blob: c3c815f7a7fa721c3455ba68c5b2575e826fd3ea [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302 * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
3 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20*/
Jeff Johnson295189b2012-06-20 16:38:30 -070021
22/**========================================================================
23
24 \file wlan_hdd_cfg80211.c
25
26 \brief WLAN Host Device Driver implementation
27
Gopichand Nakkala747461f2013-04-24 19:24:45 +053028 Copyright 2008 (c) Qualcomm Technologies, Inc. All Rights Reserved.
Jeff Johnson295189b2012-06-20 16:38:30 -070029
Gopichand Nakkala747461f2013-04-24 19:24:45 +053030 Qualcomm Technologies Confidential and Proprietary.
Jeff Johnson295189b2012-06-20 16:38:30 -070031
32 ========================================================================*/
33
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -070034/**=========================================================================
Jeff Johnson295189b2012-06-20 16:38:30 -070035
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -070036 EDIT HISTORY FOR FILE
Jeff Johnson295189b2012-06-20 16:38:30 -070037
38
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -070039 This section contains comments describing changes made to the module.
40 Notice that changes are listed in reverse chronological order.
Jeff Johnson295189b2012-06-20 16:38:30 -070041
42
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -070043 $Header:$ $DateTime: $ $Author: $
Jeff Johnson295189b2012-06-20 16:38:30 -070044
45
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -070046 when who what, where, why
Jeff Johnson295189b2012-06-20 16:38:30 -070047 -------- --- --------------------------------------------------------
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -070048 21/12/09 Ashwani Created module.
Jeff Johnson295189b2012-06-20 16:38:30 -070049
50 07/06/10 Kumar Deepak Implemented cfg80211 callbacks for ANDROID
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -070051 Ganesh K
Jeff Johnson295189b2012-06-20 16:38:30 -070052 ==========================================================================*/
53
Jeff Johnson295189b2012-06-20 16:38:30 -070054
55#include <linux/version.h>
56#include <linux/module.h>
57#include <linux/kernel.h>
58#include <linux/init.h>
59#include <linux/wireless.h>
60#include <wlan_hdd_includes.h>
61#include <net/arp.h>
62#include <net/cfg80211.h>
63#include <linux/wireless.h>
64#include <wlan_hdd_wowl.h>
65#include <aniGlobal.h>
66#include "ccmApi.h"
67#include "sirParams.h"
68#include "dot11f.h"
69#include "wlan_hdd_assoc.h"
70#include "wlan_hdd_wext.h"
71#include "sme_Api.h"
72#include "wlan_hdd_p2p.h"
73#include "wlan_hdd_cfg80211.h"
74#include "wlan_hdd_hostapd.h"
75#include "sapInternal.h"
76#include "wlan_hdd_softap_tx_rx.h"
77#include "wlan_hdd_main.h"
Madan Mohan Koyyalamudid5acbf52012-11-28 01:45:08 +053078#include "wlan_hdd_assoc.h"
Gopichand Nakkala20c4c042013-04-19 22:08:55 +053079#include "wlan_hdd_power.h"
Jeff Johnson295189b2012-06-20 16:38:30 -070080#ifdef WLAN_BTAMP_FEATURE
81#include "bap_hdd_misc.h"
82#endif
83#include <qc_sap_ioctl.h>
Mohit Khanna698ba2a2012-12-04 15:08:18 -080084#ifdef FEATURE_WLAN_TDLS
85#include "wlan_hdd_tdls.h"
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +053086#include "wlan_hdd_wmm.h"
Madan Mohan Koyyalamudice419872013-09-13 19:36:52 +053087#include "wlan_qct_wda.h"
Mohit Khanna698ba2a2012-12-04 15:08:18 -080088#endif
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +053089#include "wlan_nv.h"
Leo Chang6fe1f922013-06-07 19:21:24 -070090#include "wlan_hdd_dev_pwr.h"
Jeff Johnson295189b2012-06-20 16:38:30 -070091
92#define g_mode_rates_size (12)
93#define a_mode_rates_size (8)
94#define FREQ_BASE_80211G (2407)
95#define FREQ_BAND_DIFF_80211G (5)
Jeff Johnson04dd8a82012-06-29 20:41:40 -070096#define MAX_SCAN_SSID 9
Jeff Johnson295189b2012-06-20 16:38:30 -070097#define GET_IE_LEN_IN_BSS_DESC(lenInBss) ( lenInBss + sizeof(lenInBss) - \
98 ((int) OFFSET_OF( tSirBssDescription, ieFields)))
99
100#define HDD2GHZCHAN(freq, chan, flag) { \
101 .band = IEEE80211_BAND_2GHZ, \
102 .center_freq = (freq), \
103 .hw_value = (chan),\
104 .flags = (flag), \
105 .max_antenna_gain = 0 ,\
106 .max_power = 30, \
107}
108
109#define HDD5GHZCHAN(freq, chan, flag) { \
110 .band = IEEE80211_BAND_5GHZ, \
111 .center_freq = (freq), \
112 .hw_value = (chan),\
113 .flags = (flag), \
114 .max_antenna_gain = 0 ,\
115 .max_power = 30, \
116}
117
118#define HDD_G_MODE_RATETAB(rate, rate_id, flag)\
119{\
120 .bitrate = rate, \
121 .hw_value = rate_id, \
122 .flags = flag, \
123}
124
Lee Hoonkic1262f22013-01-24 21:59:00 -0800125#ifndef WLAN_FEATURE_TDLS_DEBUG
126#define TDLS_LOG_LEVEL VOS_TRACE_LEVEL_INFO
127#else
128#define TDLS_LOG_LEVEL VOS_TRACE_LEVEL_ERROR
129#endif
130
Gopichand Nakkala356fb102013-03-06 12:34:04 +0530131#ifdef WLAN_FEATURE_VOWIFI_11R
132#define WLAN_AKM_SUITE_FT_8021X 0x000FAC03
133#define WLAN_AKM_SUITE_FT_PSK 0x000FAC04
134#endif
135
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530136static const u32 hdd_cipher_suites[] =
Jeff Johnson295189b2012-06-20 16:38:30 -0700137{
138 WLAN_CIPHER_SUITE_WEP40,
139 WLAN_CIPHER_SUITE_WEP104,
140 WLAN_CIPHER_SUITE_TKIP,
141#ifdef FEATURE_WLAN_CCX
142#define WLAN_CIPHER_SUITE_KRK 0x004096ff /* use for KRK */
143 WLAN_CIPHER_SUITE_KRK,
144 WLAN_CIPHER_SUITE_CCMP,
145#else
146 WLAN_CIPHER_SUITE_CCMP,
147#endif
148#ifdef FEATURE_WLAN_WAPI
149 WLAN_CIPHER_SUITE_SMS4,
150#endif
Chet Lanctot186b5732013-03-18 10:26:30 -0700151#ifdef WLAN_FEATURE_11W
152 WLAN_CIPHER_SUITE_AES_CMAC,
153#endif
Jeff Johnson295189b2012-06-20 16:38:30 -0700154};
155
156static inline int is_broadcast_ether_addr(const u8 *addr)
157{
158 return ((addr[0] == 0xff) && (addr[1] == 0xff) && (addr[2] == 0xff) &&
159 (addr[3] == 0xff) && (addr[4] == 0xff) && (addr[5] == 0xff));
160}
161
162static struct ieee80211_channel hdd_channels_2_4_GHZ[] =
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530163{
Jeff Johnson295189b2012-06-20 16:38:30 -0700164 HDD2GHZCHAN(2412, 1, 0) ,
165 HDD2GHZCHAN(2417, 2, 0) ,
166 HDD2GHZCHAN(2422, 3, 0) ,
167 HDD2GHZCHAN(2427, 4, 0) ,
168 HDD2GHZCHAN(2432, 5, 0) ,
169 HDD2GHZCHAN(2437, 6, 0) ,
170 HDD2GHZCHAN(2442, 7, 0) ,
171 HDD2GHZCHAN(2447, 8, 0) ,
172 HDD2GHZCHAN(2452, 9, 0) ,
173 HDD2GHZCHAN(2457, 10, 0) ,
174 HDD2GHZCHAN(2462, 11, 0) ,
175 HDD2GHZCHAN(2467, 12, 0) ,
176 HDD2GHZCHAN(2472, 13, 0) ,
177 HDD2GHZCHAN(2484, 14, 0) ,
178};
179
Jeff Johnson295189b2012-06-20 16:38:30 -0700180static struct ieee80211_channel hdd_social_channels_2_4_GHZ[] =
181{
182 HDD2GHZCHAN(2412, 1, 0) ,
183 HDD2GHZCHAN(2437, 6, 0) ,
184 HDD2GHZCHAN(2462, 11, 0) ,
185};
Jeff Johnson295189b2012-06-20 16:38:30 -0700186
187static struct ieee80211_channel hdd_channels_5_GHZ[] =
188{
Madan Mohan Koyyalamudic3a240c2012-09-28 15:34:08 -0700189 HDD5GHZCHAN(4920, 240, 0) ,
190 HDD5GHZCHAN(4940, 244, 0) ,
191 HDD5GHZCHAN(4960, 248, 0) ,
192 HDD5GHZCHAN(4980, 252, 0) ,
193 HDD5GHZCHAN(5040, 208, 0) ,
194 HDD5GHZCHAN(5060, 212, 0) ,
195 HDD5GHZCHAN(5080, 216, 0) ,
Jeff Johnson295189b2012-06-20 16:38:30 -0700196 HDD5GHZCHAN(5180, 36, 0) ,
197 HDD5GHZCHAN(5200, 40, 0) ,
198 HDD5GHZCHAN(5220, 44, 0) ,
199 HDD5GHZCHAN(5240, 48, 0) ,
200 HDD5GHZCHAN(5260, 52, 0) ,
201 HDD5GHZCHAN(5280, 56, 0) ,
202 HDD5GHZCHAN(5300, 60, 0) ,
203 HDD5GHZCHAN(5320, 64, 0) ,
204 HDD5GHZCHAN(5500,100, 0) ,
205 HDD5GHZCHAN(5520,104, 0) ,
206 HDD5GHZCHAN(5540,108, 0) ,
207 HDD5GHZCHAN(5560,112, 0) ,
208 HDD5GHZCHAN(5580,116, 0) ,
209 HDD5GHZCHAN(5600,120, 0) ,
210 HDD5GHZCHAN(5620,124, 0) ,
211 HDD5GHZCHAN(5640,128, 0) ,
212 HDD5GHZCHAN(5660,132, 0) ,
213 HDD5GHZCHAN(5680,136, 0) ,
214 HDD5GHZCHAN(5700,140, 0) ,
215 HDD5GHZCHAN(5745,149, 0) ,
216 HDD5GHZCHAN(5765,153, 0) ,
217 HDD5GHZCHAN(5785,157, 0) ,
218 HDD5GHZCHAN(5805,161, 0) ,
219 HDD5GHZCHAN(5825,165, 0) ,
220};
221
222static struct ieee80211_rate g_mode_rates[] =
223{
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530224 HDD_G_MODE_RATETAB(10, 0x1, 0),
225 HDD_G_MODE_RATETAB(20, 0x2, 0),
226 HDD_G_MODE_RATETAB(55, 0x4, 0),
227 HDD_G_MODE_RATETAB(110, 0x8, 0),
228 HDD_G_MODE_RATETAB(60, 0x10, 0),
229 HDD_G_MODE_RATETAB(90, 0x20, 0),
230 HDD_G_MODE_RATETAB(120, 0x40, 0),
231 HDD_G_MODE_RATETAB(180, 0x80, 0),
232 HDD_G_MODE_RATETAB(240, 0x100, 0),
233 HDD_G_MODE_RATETAB(360, 0x200, 0),
234 HDD_G_MODE_RATETAB(480, 0x400, 0),
Jeff Johnson295189b2012-06-20 16:38:30 -0700235 HDD_G_MODE_RATETAB(540, 0x800, 0),
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530236};
Jeff Johnson295189b2012-06-20 16:38:30 -0700237
238static struct ieee80211_rate a_mode_rates[] =
239{
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530240 HDD_G_MODE_RATETAB(60, 0x10, 0),
241 HDD_G_MODE_RATETAB(90, 0x20, 0),
242 HDD_G_MODE_RATETAB(120, 0x40, 0),
243 HDD_G_MODE_RATETAB(180, 0x80, 0),
244 HDD_G_MODE_RATETAB(240, 0x100, 0),
245 HDD_G_MODE_RATETAB(360, 0x200, 0),
246 HDD_G_MODE_RATETAB(480, 0x400, 0),
Jeff Johnson295189b2012-06-20 16:38:30 -0700247 HDD_G_MODE_RATETAB(540, 0x800, 0),
248};
249
250static struct ieee80211_supported_band wlan_hdd_band_2_4_GHZ =
251{
252 .channels = hdd_channels_2_4_GHZ,
253 .n_channels = ARRAY_SIZE(hdd_channels_2_4_GHZ),
254 .band = IEEE80211_BAND_2GHZ,
255 .bitrates = g_mode_rates,
256 .n_bitrates = g_mode_rates_size,
257 .ht_cap.ht_supported = 1,
258 .ht_cap.cap = IEEE80211_HT_CAP_SGI_20
259 | IEEE80211_HT_CAP_GRN_FLD
260 | IEEE80211_HT_CAP_DSSSCCK40
261 | IEEE80211_HT_CAP_LSIG_TXOP_PROT,
262 .ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
263 .ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_16,
264 .ht_cap.mcs.rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
265 .ht_cap.mcs.rx_highest = cpu_to_le16( 72 ),
266 .ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED,
267};
268
Jeff Johnson295189b2012-06-20 16:38:30 -0700269static struct ieee80211_supported_band wlan_hdd_band_p2p_2_4_GHZ =
270{
271 .channels = hdd_social_channels_2_4_GHZ,
272 .n_channels = ARRAY_SIZE(hdd_social_channels_2_4_GHZ),
273 .band = IEEE80211_BAND_2GHZ,
274 .bitrates = g_mode_rates,
275 .n_bitrates = g_mode_rates_size,
276 .ht_cap.ht_supported = 1,
277 .ht_cap.cap = IEEE80211_HT_CAP_SGI_20
278 | IEEE80211_HT_CAP_GRN_FLD
279 | IEEE80211_HT_CAP_DSSSCCK40
280 | IEEE80211_HT_CAP_LSIG_TXOP_PROT,
281 .ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
282 .ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_16,
283 .ht_cap.mcs.rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
284 .ht_cap.mcs.rx_highest = cpu_to_le16( 72 ),
285 .ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED,
286};
Jeff Johnson295189b2012-06-20 16:38:30 -0700287
288static struct ieee80211_supported_band wlan_hdd_band_5_GHZ =
289{
290 .channels = hdd_channels_5_GHZ,
291 .n_channels = ARRAY_SIZE(hdd_channels_5_GHZ),
292 .band = IEEE80211_BAND_5GHZ,
293 .bitrates = a_mode_rates,
294 .n_bitrates = a_mode_rates_size,
295 .ht_cap.ht_supported = 1,
296 .ht_cap.cap = IEEE80211_HT_CAP_SGI_20
297 | IEEE80211_HT_CAP_GRN_FLD
298 | IEEE80211_HT_CAP_DSSSCCK40
299 | IEEE80211_HT_CAP_LSIG_TXOP_PROT
300 | IEEE80211_HT_CAP_SGI_40
301 | IEEE80211_HT_CAP_SUP_WIDTH_20_40,
302 .ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
303 .ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_16,
304 .ht_cap.mcs.rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
305 .ht_cap.mcs.rx_highest = cpu_to_le16( 72 ),
306 .ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED,
307};
308
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530309/* This structure contain information what kind of frame are expected in
Jeff Johnson295189b2012-06-20 16:38:30 -0700310 TX/RX direction for each kind of interface */
311static const struct ieee80211_txrx_stypes
312wlan_hdd_txrx_stypes[NUM_NL80211_IFTYPES] = {
313 [NL80211_IFTYPE_STATION] = {
314 .tx = 0xffff,
315 .rx = BIT(SIR_MAC_MGMT_ACTION) |
316 BIT(SIR_MAC_MGMT_PROBE_REQ),
317 },
318 [NL80211_IFTYPE_AP] = {
319 .tx = 0xffff,
320 .rx = BIT(SIR_MAC_MGMT_ASSOC_REQ) |
321 BIT(SIR_MAC_MGMT_REASSOC_REQ) |
322 BIT(SIR_MAC_MGMT_PROBE_REQ) |
323 BIT(SIR_MAC_MGMT_DISASSOC) |
324 BIT(SIR_MAC_MGMT_AUTH) |
325 BIT(SIR_MAC_MGMT_DEAUTH) |
326 BIT(SIR_MAC_MGMT_ACTION),
327 },
Jeff Johnsonbc006202013-04-29 14:05:30 -0700328 [NL80211_IFTYPE_ADHOC] = {
329 .tx = 0xffff,
330 .rx = BIT(SIR_MAC_MGMT_ASSOC_REQ) |
331 BIT(SIR_MAC_MGMT_REASSOC_REQ) |
332 BIT(SIR_MAC_MGMT_PROBE_REQ) |
333 BIT(SIR_MAC_MGMT_DISASSOC) |
334 BIT(SIR_MAC_MGMT_AUTH) |
335 BIT(SIR_MAC_MGMT_DEAUTH) |
336 BIT(SIR_MAC_MGMT_ACTION),
337 },
Jeff Johnson295189b2012-06-20 16:38:30 -0700338 [NL80211_IFTYPE_P2P_CLIENT] = {
339 .tx = 0xffff,
340 .rx = BIT(SIR_MAC_MGMT_ACTION) |
341 BIT(SIR_MAC_MGMT_PROBE_REQ),
342 },
343 [NL80211_IFTYPE_P2P_GO] = {
344 /* This is also same as for SoftAP */
345 .tx = 0xffff,
346 .rx = BIT(SIR_MAC_MGMT_ASSOC_REQ) |
347 BIT(SIR_MAC_MGMT_REASSOC_REQ) |
348 BIT(SIR_MAC_MGMT_PROBE_REQ) |
349 BIT(SIR_MAC_MGMT_DISASSOC) |
350 BIT(SIR_MAC_MGMT_AUTH) |
351 BIT(SIR_MAC_MGMT_DEAUTH) |
352 BIT(SIR_MAC_MGMT_ACTION),
353 },
Jeff Johnson295189b2012-06-20 16:38:30 -0700354};
355
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800356#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800357static const struct ieee80211_iface_limit
358wlan_hdd_iface_limit[] = {
359 {
Sunil Ravia72c3992013-01-31 06:12:22 -0800360 /* max = 3 ; Our driver create two interfaces during driver init
361 * wlan0 and p2p0 interfaces. p2p0 is considered as station
362 * interface until a group is formed. In JB architecture, once the
363 * group is formed, interface type of p2p0 is changed to P2P GO or
364 * Client.
365 * When supplicant remove the group, it first issue a set interface
366 * cmd to change the mode back to Station. In JB this works fine as
367 * we advertize two station type interface during driver init.
368 * Some vendors create separate interface for P2P GO/Client,
369 * after group formation(Third one). But while group remove
370 * supplicant first tries to change the mode(3rd interface) to STATION
371 * But as we advertized only two sta type interfaces nl80211 was
372 * returning error for the third one which was leading to failure in
373 * delete interface. Ideally while removing the group, supplicant
374 * should not try to change the 3rd interface mode to Station type.
375 * Till we get a fix in wpa_supplicant, we advertize max STA
376 * interface type to 3
377 */
378 .max = 3,
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800379 .types = BIT(NL80211_IFTYPE_STATION),
380 },
381 {
382 .max = 1,
Jeff Johnsonbc006202013-04-29 14:05:30 -0700383 .types = BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_AP),
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800384 },
385 {
386 .max = 1,
387 .types = BIT(NL80211_IFTYPE_P2P_GO) |
388 BIT(NL80211_IFTYPE_P2P_CLIENT),
389 },
390};
391
392/* By default, only single channel concurrency is allowed */
393static struct ieee80211_iface_combination
394wlan_hdd_iface_combination = {
395 .limits = wlan_hdd_iface_limit,
396 .num_different_channels = 1,
Sunil Ravia72c3992013-01-31 06:12:22 -0800397 /*
398 * max = WLAN_MAX_INTERFACES ; JellyBean architecture creates wlan0
399 * and p2p0 interfaces during driver init
400 * Some vendors create separate interface for P2P operations.
401 * wlan0: STA interface
402 * p2p0: P2P Device interface, action frames goes
403 * through this interface.
404 * p2p-xx: P2P interface, After GO negotiation this interface is
405 * created for p2p operations(GO/CLIENT interface).
406 */
407 .max_interfaces = WLAN_MAX_INTERFACES,
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800408 .n_limits = ARRAY_SIZE(wlan_hdd_iface_limit),
409 .beacon_int_infra_match = false,
410};
411#endif
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800412
Jeff Johnson295189b2012-06-20 16:38:30 -0700413static struct cfg80211_ops wlan_hdd_cfg80211_ops;
414
415/* Data rate 100KBPS based on IE Index */
416struct index_data_rate_type
417{
418 v_U8_t beacon_rate_index;
419 v_U16_t supported_rate[4];
420};
421
422/* 11B, 11G Rate table include Basic rate and Extended rate
423 The IDX field is the rate index
424 The HI field is the rate when RSSI is strong or being ignored
425 (in this case we report actual rate)
426 The MID field is the rate when RSSI is moderate
427 (in this case we cap 11b rates at 5.5 and 11g rates at 24)
428 The LO field is the rate when RSSI is low
429 (in this case we don't report rates, actual current rate used)
430 */
431static const struct
432{
433 v_U8_t beacon_rate_index;
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -0700434 v_U16_t supported_rate[4];
Jeff Johnson295189b2012-06-20 16:38:30 -0700435} supported_data_rate[] =
436{
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -0700437/* IDX HI HM LM LO (RSSI-based index */
438 {2, { 10, 10, 10, 0}},
439 {4, { 20, 20, 10, 0}},
440 {11, { 55, 20, 10, 0}},
441 {12, { 60, 55, 20, 0}},
442 {18, { 90, 55, 20, 0}},
443 {22, {110, 55, 20, 0}},
444 {24, {120, 90, 60, 0}},
445 {36, {180, 120, 60, 0}},
446 {44, {220, 180, 60, 0}},
447 {48, {240, 180, 90, 0}},
448 {66, {330, 180, 90, 0}},
449 {72, {360, 240, 90, 0}},
450 {96, {480, 240, 120, 0}},
451 {108, {540, 240, 120, 0}}
Jeff Johnson295189b2012-06-20 16:38:30 -0700452};
453
454/* MCS Based rate table */
455static struct index_data_rate_type supported_mcs_rate[] =
456{
457/* MCS L20 L40 S20 S40 */
458 {0, {65, 135, 72, 150}},
459 {1, {130, 270, 144, 300}},
460 {2, {195, 405, 217, 450}},
461 {3, {260, 540, 289, 600}},
462 {4, {390, 810, 433, 900}},
463 {5, {520, 1080, 578, 1200}},
464 {6, {585, 1215, 650, 1350}},
465 {7, {650, 1350, 722, 1500}}
466};
467
Leo Chang6f8870f2013-03-26 18:11:36 -0700468#ifdef WLAN_FEATURE_11AC
469
Gopichand Nakkala4c705372013-04-24 13:20:33 +0530470#define DATA_RATE_11AC_MCS_MASK 0x03
Leo Chang6f8870f2013-03-26 18:11:36 -0700471
472struct index_vht_data_rate_type
473{
474 v_U8_t beacon_rate_index;
Gopichand Nakkala4c705372013-04-24 13:20:33 +0530475 v_U16_t supported_VHT80_rate[2];
476 v_U16_t supported_VHT40_rate[2];
477 v_U16_t supported_VHT20_rate[2];
Leo Chang6f8870f2013-03-26 18:11:36 -0700478};
479
480typedef enum
481{
482 DATA_RATE_11AC_MAX_MCS_7,
483 DATA_RATE_11AC_MAX_MCS_8,
484 DATA_RATE_11AC_MAX_MCS_9,
485 DATA_RATE_11AC_MAX_MCS_NA
486} eDataRate11ACMaxMcs;
487
488/* MCS Based VHT rate table */
489static struct index_vht_data_rate_type supported_vht_mcs_rate[] =
490{
Gopichand Nakkala4c705372013-04-24 13:20:33 +0530491/* MCS L80 S80 L40 S40 L20 S40*/
492 {0, {293, 325}, {135, 150}, {65, 72}},
493 {1, {585, 650}, {270, 300}, {130, 144}},
494 {2, {878, 975}, {405, 450}, {195, 217}},
495 {3, {1170, 1300}, {540, 600}, {260, 289}},
496 {4, {1755, 1950}, {810, 900}, {390, 433}},
497 {5, {2340, 2600}, {1080, 1200}, {520, 578}},
498 {6, {2633, 2925}, {1215, 1350}, {585, 650}},
499 {7, {2925, 3250}, {1350, 1500}, {650, 722}},
500 {8, {3510, 3900}, {1620, 1800}, {780, 867}},
501 {9, {3900, 4333}, {1800, 2000}, {780, 867}}
Leo Chang6f8870f2013-03-26 18:11:36 -0700502};
503#endif /* WLAN_FEATURE_11AC */
504
Jeff Johnson295189b2012-06-20 16:38:30 -0700505extern struct net_device_ops net_ops_struct;
506
Leo Chang9056f462013-08-01 19:21:11 -0700507#ifdef WLAN_NL80211_TESTMODE
508enum wlan_hdd_tm_attr
509{
510 WLAN_HDD_TM_ATTR_INVALID = 0,
511 WLAN_HDD_TM_ATTR_CMD = 1,
512 WLAN_HDD_TM_ATTR_DATA = 2,
513 WLAN_HDD_TM_ATTR_TYPE = 3,
514 /* keep last */
515 WLAN_HDD_TM_ATTR_AFTER_LAST,
516 WLAN_HDD_TM_ATTR_MAX = WLAN_HDD_TM_ATTR_AFTER_LAST - 1,
517};
518
519enum wlan_hdd_tm_cmd
520{
521 WLAN_HDD_TM_CMD_WLAN_HB = 1,
522};
523
524#define WLAN_HDD_TM_DATA_MAX_LEN 5000
525
526static const struct nla_policy wlan_hdd_tm_policy[WLAN_HDD_TM_ATTR_MAX + 1] =
527{
528 [WLAN_HDD_TM_ATTR_CMD] = { .type = NLA_U32 },
529 [WLAN_HDD_TM_ATTR_DATA] = { .type = NLA_BINARY,
530 .len = WLAN_HDD_TM_DATA_MAX_LEN },
531};
532#endif /* WLAN_NL80211_TESTMODE */
533
Jeff Johnson295189b2012-06-20 16:38:30 -0700534/*
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530535 * FUNCTION: wlan_hdd_cfg80211_wiphy_alloc
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530536 * This function is called by hdd_wlan_startup()
537 * during initialization.
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530538 * This function is used to allocate wiphy structure.
Jeff Johnson295189b2012-06-20 16:38:30 -0700539 */
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530540struct wiphy *wlan_hdd_cfg80211_wiphy_alloc(int priv_size)
Jeff Johnson295189b2012-06-20 16:38:30 -0700541{
542 struct wiphy *wiphy;
543 ENTER();
544
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530545 /*
546 * Create wiphy device
Jeff Johnson295189b2012-06-20 16:38:30 -0700547 */
548 wiphy = wiphy_new(&wlan_hdd_cfg80211_ops, priv_size);
549
550 if (!wiphy)
551 {
552 /* Print error and jump into err label and free the memory */
553 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: wiphy init failed", __func__);
554 return NULL;
555 }
556
557 return wiphy;
558}
559
560/*
561 * FUNCTION: wlan_hdd_cfg80211_update_band
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530562 * This function is called from the supplicant through a
Jeff Johnson295189b2012-06-20 16:38:30 -0700563 * private ioctl to change the band value
564 */
565int wlan_hdd_cfg80211_update_band(struct wiphy *wiphy, eCsrBand eBand)
566{
Gopichand Nakkala1f7a64f2013-04-01 18:37:17 +0530567 int i, j;
568 eNVChannelEnabledType channelEnabledState;
569
Jeff Johnsone7245742012-09-05 17:12:55 -0700570 ENTER();
Gopichand Nakkala1f7a64f2013-04-01 18:37:17 +0530571 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Jeff Johnson295189b2012-06-20 16:38:30 -0700572 {
Gopichand Nakkala1f7a64f2013-04-01 18:37:17 +0530573
574 if (NULL == wiphy->bands[i])
575 {
576 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy->bands[i] is NULL, i = %d",
577 __func__, i);
578 continue;
579 }
580
581 for (j = 0; j < wiphy->bands[i]->n_channels; j++)
582 {
583 struct ieee80211_supported_band *band = wiphy->bands[i];
584
585 channelEnabledState = vos_nv_getChannelEnabledState(
586 band->channels[j].hw_value);
587
588 if (IEEE80211_BAND_2GHZ == i && eCSR_BAND_5G == eBand) // 5G only
589 {
590 // Enable Social channels for P2P
591 if (WLAN_HDD_IS_SOCIAL_CHANNEL(band->channels[j].center_freq) &&
592 NV_CHANNEL_ENABLE == channelEnabledState)
593 band->channels[j].flags &= ~IEEE80211_CHAN_DISABLED;
594 else
595 band->channels[j].flags |= IEEE80211_CHAN_DISABLED;
596 continue;
597 }
598 else if (IEEE80211_BAND_5GHZ == i && eCSR_BAND_24 == eBand) // 2G only
599 {
600 band->channels[j].flags |= IEEE80211_CHAN_DISABLED;
601 continue;
602 }
603
604 if (NV_CHANNEL_DISABLE == channelEnabledState ||
605 NV_CHANNEL_INVALID == channelEnabledState)
606 {
607 band->channels[j].flags |= IEEE80211_CHAN_DISABLED;
608 }
609 else if (NV_CHANNEL_DFS == channelEnabledState)
610 {
611 band->channels[j].flags &= ~IEEE80211_CHAN_DISABLED;
612 band->channels[j].flags |= IEEE80211_CHAN_RADAR;
613 }
614 else
615 {
616 band->channels[j].flags &= ~(IEEE80211_CHAN_DISABLED
617 |IEEE80211_CHAN_RADAR);
618 }
619 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700620 }
621 return 0;
622}
623/*
624 * FUNCTION: wlan_hdd_cfg80211_init
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530625 * This function is called by hdd_wlan_startup()
626 * during initialization.
Jeff Johnson295189b2012-06-20 16:38:30 -0700627 * This function is used to initialize and register wiphy structure.
628 */
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530629int wlan_hdd_cfg80211_init(struct device *dev,
Jeff Johnson295189b2012-06-20 16:38:30 -0700630 struct wiphy *wiphy,
631 hdd_config_t *pCfg
632 )
633{
Gopichand Nakkala1f7a64f2013-04-01 18:37:17 +0530634 int i, j;
Jeff Johnsone7245742012-09-05 17:12:55 -0700635 ENTER();
636
Jeff Johnson295189b2012-06-20 16:38:30 -0700637 /* Now bind the underlying wlan device with wiphy */
638 set_wiphy_dev(wiphy, dev);
639
640 wiphy->mgmt_stypes = wlan_hdd_txrx_stypes;
Amar Singhalfddc28c2013-09-05 13:03:40 -0700641
Amar Singhala49cbc52013-10-08 18:37:44 -0700642 wiphy->flags |= WIPHY_FLAG_STRICT_REGULATORY;
643
644
Amar Singhalfddc28c2013-09-05 13:03:40 -0700645 /* This will disable updating of NL channels from passive to
646 * active if a beacon is received on passive channel. */
647 wiphy->flags |= WIPHY_FLAG_DISABLE_BEACON_HINTS;
Amar Singhalf0073192013-09-20 12:34:56 -0700648
Amar Singhalfddc28c2013-09-05 13:03:40 -0700649
Amar Singhala49cbc52013-10-08 18:37:44 -0700650
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700651#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
Madan Mohan Koyyalamudi1b4afb02012-10-22 15:25:16 -0700652 wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME
653 | WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
654 | WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
Jeff Johnsone7245742012-09-05 17:12:55 -0700655 | WIPHY_FLAG_OFFCHAN_TX;
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700656#endif
Amar Singhala49cbc52013-10-08 18:37:44 -0700657
Srinivas Girigowda640728a2013-03-28 12:21:54 -0700658#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_CCX) || defined(FEATURE_WLAN_LFR)
659 if (pCfg->isFastTransitionEnabled
James Zmuda77fb5ae2013-01-29 08:00:17 -0800660#ifdef FEATURE_WLAN_LFR
Srinivas Girigowda640728a2013-03-28 12:21:54 -0700661 || pCfg->isFastRoamIniFeatureEnabled
662#endif
663#ifdef FEATURE_WLAN_CCX
664 || pCfg->isCcxIniFeatureEnabled
665#endif
666 )
667 {
668 wiphy->flags |= WIPHY_FLAG_SUPPORTS_FW_ROAM;
669 }
James Zmuda77fb5ae2013-01-29 08:00:17 -0800670#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -0800671#ifdef FEATURE_WLAN_TDLS
672 wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS
673 | WIPHY_FLAG_TDLS_EXTERNAL_SETUP;
674#endif
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +0530675#ifdef FEATURE_WLAN_SCAN_PNO
676 wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
Madan Mohan Koyyalamudi75de0102013-09-17 14:56:29 +0530677 wiphy->max_sched_scan_ssids = SIR_PNO_MAX_SUPP_NETWORKS;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +0530678 wiphy->max_match_sets = SIR_PNO_MAX_SUPP_NETWORKS;
Madan Mohan Koyyalamudia7765d52013-09-18 16:49:56 +0530679 wiphy->max_sched_scan_ie_len = SIR_MAC_MAX_IE_LENGTH;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +0530680#endif/*FEATURE_WLAN_SCAN_PNO*/
Mohit Khanna698ba2a2012-12-04 15:08:18 -0800681
Amar Singhalfddc28c2013-09-05 13:03:40 -0700682#ifdef CONFIG_ENABLE_LINUX_REG
Madan Mohan Koyyalamudic3a240c2012-09-28 15:34:08 -0700683 /* even with WIPHY_FLAG_CUSTOM_REGULATORY,
684 driver can still register regulatory callback and
Amar Singhalfddc28c2013-09-05 13:03:40 -0700685 it will get regulatory settings in wiphy->band[], but
Madan Mohan Koyyalamudic3a240c2012-09-28 15:34:08 -0700686 driver need to determine what to do with both
687 regulatory settings */
Amar Singhalfddc28c2013-09-05 13:03:40 -0700688
689 wiphy->reg_notifier = wlan_hdd_linux_reg_notifier;
Amar Singhala49cbc52013-10-08 18:37:44 -0700690#else
691 wiphy->reg_notifier = wlan_hdd_crda_reg_notifier;
Amar Singhalfddc28c2013-09-05 13:03:40 -0700692#endif
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700693
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530694 wiphy->max_scan_ssids = MAX_SCAN_SSID;
695
Madan Mohan Koyyalamudi6815b162013-07-19 17:17:46 +0530696 wiphy->max_scan_ie_len = SIR_MAC_MAX_IE_LENGTH;
Jeff Johnson295189b2012-06-20 16:38:30 -0700697
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +0530698 wiphy->max_acl_mac_addrs = MAX_ACL_MAC_ADDRESS;
699
Jeff Johnson295189b2012-06-20 16:38:30 -0700700 /* Supports STATION & AD-HOC modes right now */
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530701 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION)
Jeff Johnson295189b2012-06-20 16:38:30 -0700702 | BIT(NL80211_IFTYPE_ADHOC)
Jeff Johnson295189b2012-06-20 16:38:30 -0700703 | BIT(NL80211_IFTYPE_P2P_CLIENT)
704 | BIT(NL80211_IFTYPE_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -0700705 | BIT(NL80211_IFTYPE_AP);
706
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800707#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800708 if( pCfg->enableMCC )
709 {
710 /* Currently, supports up to two channels */
711 wlan_hdd_iface_combination.num_different_channels = 2;
712
713 if( !pCfg->allowMCCGODiffBI )
714 wlan_hdd_iface_combination.beacon_int_infra_match = true;
715
716 }
717 wiphy->iface_combinations = &wlan_hdd_iface_combination;
718 wiphy->n_iface_combinations = 1;
719#endif
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800720
Jeff Johnson295189b2012-06-20 16:38:30 -0700721 /* Before registering we need to update the ht capabilitied based
722 * on ini values*/
723 if( !pCfg->ShortGI20MhzEnable )
724 {
725 wlan_hdd_band_2_4_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_20;
726 wlan_hdd_band_5_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_20;
727 wlan_hdd_band_p2p_2_4_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_20;
728 }
729
730 if( !pCfg->ShortGI40MhzEnable )
731 {
732 wlan_hdd_band_5_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_40;
733 }
734
735 if( !pCfg->nChannelBondingMode5GHz )
736 {
737 wlan_hdd_band_5_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
738 }
739
Gopichand Nakkala1f7a64f2013-04-01 18:37:17 +0530740 wiphy->bands[IEEE80211_BAND_2GHZ] = &wlan_hdd_band_2_4_GHZ;
741 wiphy->bands[IEEE80211_BAND_5GHZ] = &wlan_hdd_band_5_GHZ;
742
743 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
744 {
745
746 if (NULL == wiphy->bands[i])
747 {
748 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy->bands[i] is NULL, i = %d",
749 __func__, i);
750 continue;
751 }
752
753 for (j = 0; j < wiphy->bands[i]->n_channels; j++)
754 {
755 struct ieee80211_supported_band *band = wiphy->bands[i];
756
757 if (IEEE80211_BAND_2GHZ == i && eCSR_BAND_5G == pCfg->nBandCapability) // 5G only
758 {
759 // Enable social channels for P2P
760 if (WLAN_HDD_IS_SOCIAL_CHANNEL(band->channels[j].center_freq))
761 band->channels[j].flags &= ~IEEE80211_CHAN_DISABLED;
762 else
763 band->channels[j].flags |= IEEE80211_CHAN_DISABLED;
764 continue;
765 }
766 else if (IEEE80211_BAND_5GHZ == i && eCSR_BAND_24 == pCfg->nBandCapability) // 2G only
767 {
768 band->channels[j].flags |= IEEE80211_CHAN_DISABLED;
769 continue;
770 }
771 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700772 }
773 /*Initialise the supported cipher suite details*/
774 wiphy->cipher_suites = hdd_cipher_suites;
775 wiphy->n_cipher_suites = ARRAY_SIZE(hdd_cipher_suites);
776
777 /*signal strength in mBm (100*dBm) */
778 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
779
780#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
Jeff Johnson295189b2012-06-20 16:38:30 -0700781 wiphy->max_remain_on_channel_duration = 1000;
782#endif
Jeff Johnson295189b2012-06-20 16:38:30 -0700783
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530784 EXIT();
785 return 0;
786}
787
788/* In this function we are registering wiphy. */
789int wlan_hdd_cfg80211_register(struct wiphy *wiphy)
790{
791 ENTER();
792 /* Register our wiphy dev with cfg80211 */
Jeff Johnson295189b2012-06-20 16:38:30 -0700793 if (0 > wiphy_register(wiphy))
794 {
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530795 /* print error */
Jeff Johnson295189b2012-06-20 16:38:30 -0700796 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy register failed", __func__);
797 return -EIO;
798 }
799
800 EXIT();
801 return 0;
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530802}
Jeff Johnson295189b2012-06-20 16:38:30 -0700803
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530804/* In this function we are updating channel list when,
805 regulatory domain is FCC and country code is US.
806 Here In FCC standard 5GHz UNII-1 Bands are indoor only.
807 As per FCC smart phone is not a indoor device.
808 GO should not opeate on indoor channels */
809void wlan_hdd_cfg80211_update_reg_info(struct wiphy *wiphy)
810{
811 int j;
812 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
813 tANI_U8 defaultCountryCode[3] = SME_INVALID_COUNTRY_CODE;
814 //Default counrtycode from NV at the time of wiphy initialization.
815 if (eHAL_STATUS_SUCCESS != sme_GetDefaultCountryCodeFrmNv(pHddCtx->hHal,
816 &defaultCountryCode[0]))
817 {
818 hddLog(LOGE, FL("%s Failed to get default country code from NV"));
819 }
820 if ((defaultCountryCode[0]== 'U') && (defaultCountryCode[1]=='S'))
821 {
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530822 if (NULL == wiphy->bands[IEEE80211_BAND_5GHZ])
823 {
824 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy->bands[IEEE80211_BAND_5GHZ] is NULL",__func__ );
825 return;
826 }
827 for (j = 0; j < wiphy->bands[IEEE80211_BAND_5GHZ]->n_channels; j++)
828 {
829 struct ieee80211_supported_band *band = wiphy->bands[IEEE80211_BAND_5GHZ];
830 // Mark UNII -1 band channel as passive
831 if (WLAN_HDD_CHANNEL_IN_UNII_1_BAND(band->channels[j].center_freq))
832 band->channels[j].flags |= IEEE80211_CHAN_PASSIVE_SCAN;
833 }
834 }
835}
836
Jeff Johnson295189b2012-06-20 16:38:30 -0700837/* In this function we will do all post VOS start initialization.
838 In this function we will register for all frame in which supplicant
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530839 is interested.
Jeff Johnson295189b2012-06-20 16:38:30 -0700840*/
841void wlan_hdd_cfg80211_post_voss_start(hdd_adapter_t* pAdapter)
842{
Jeff Johnson295189b2012-06-20 16:38:30 -0700843 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
844 /* Register for all P2P action, public action etc frames */
845 v_U16_t type = (SIR_MAC_MGMT_FRAME << 2) | ( SIR_MAC_MGMT_ACTION << 4);
846
Jeff Johnsone7245742012-09-05 17:12:55 -0700847 ENTER();
848
Jeff Johnson295189b2012-06-20 16:38:30 -0700849 /* Right now we are registering these frame when driver is getting
850 initialized. Once we will move to 2.6.37 kernel, in which we have
851 frame register ops, we will move this code as a part of that */
852 /* GAS Initial Request */
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530853 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
Jeff Johnson295189b2012-06-20 16:38:30 -0700854 (v_U8_t*)GAS_INITIAL_REQ, GAS_INITIAL_REQ_SIZE );
855
856 /* GAS Initial Response */
857 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
858 (v_U8_t*)GAS_INITIAL_RSP, GAS_INITIAL_RSP_SIZE );
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530859
Jeff Johnson295189b2012-06-20 16:38:30 -0700860 /* GAS Comeback Request */
861 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
862 (v_U8_t*)GAS_COMEBACK_REQ, GAS_COMEBACK_REQ_SIZE );
863
864 /* GAS Comeback Response */
865 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
866 (v_U8_t*)GAS_COMEBACK_RSP, GAS_COMEBACK_RSP_SIZE );
867
868 /* P2P Public Action */
869 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530870 (v_U8_t*)P2P_PUBLIC_ACTION_FRAME,
Jeff Johnson295189b2012-06-20 16:38:30 -0700871 P2P_PUBLIC_ACTION_FRAME_SIZE );
872
873 /* P2P Action */
874 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
875 (v_U8_t*)P2P_ACTION_FRAME,
876 P2P_ACTION_FRAME_SIZE );
Chet Lanctot186b5732013-03-18 10:26:30 -0700877
Gopichand Nakkalae3d56e72013-04-21 23:33:32 +0530878 /* WNM BSS Transition Request frame */
879 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
880 (v_U8_t*)WNM_BSS_ACTION_FRAME,
881 WNM_BSS_ACTION_FRAME_SIZE );
882
Chet Lanctot186b5732013-03-18 10:26:30 -0700883#ifdef WLAN_FEATURE_11W
884 /* SA Query Response Action Frame */
885 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
886 (v_U8_t*)SA_QUERY_FRAME_RSP,
887 SA_QUERY_FRAME_RSP_SIZE );
888#endif /* WLAN_FEATURE_11W */
Jeff Johnson295189b2012-06-20 16:38:30 -0700889}
890
891void wlan_hdd_cfg80211_pre_voss_stop(hdd_adapter_t* pAdapter)
892{
Jeff Johnson295189b2012-06-20 16:38:30 -0700893 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
894 /* Register for all P2P action, public action etc frames */
895 v_U16_t type = (SIR_MAC_MGMT_FRAME << 2) | ( SIR_MAC_MGMT_ACTION << 4);
896
Jeff Johnsone7245742012-09-05 17:12:55 -0700897 ENTER();
898
Jeff Johnson295189b2012-06-20 16:38:30 -0700899 /* Right now we are registering these frame when driver is getting
900 initialized. Once we will move to 2.6.37 kernel, in which we have
901 frame register ops, we will move this code as a part of that */
902 /* GAS Initial Request */
903
904 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
905 (v_U8_t*)GAS_INITIAL_REQ, GAS_INITIAL_REQ_SIZE );
906
907 /* GAS Initial Response */
908 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
909 (v_U8_t*)GAS_INITIAL_RSP, GAS_INITIAL_RSP_SIZE );
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530910
Jeff Johnson295189b2012-06-20 16:38:30 -0700911 /* GAS Comeback Request */
912 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
913 (v_U8_t*)GAS_COMEBACK_REQ, GAS_COMEBACK_REQ_SIZE );
914
915 /* GAS Comeback Response */
916 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
917 (v_U8_t*)GAS_COMEBACK_RSP, GAS_COMEBACK_RSP_SIZE );
918
919 /* P2P Public Action */
920 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530921 (v_U8_t*)P2P_PUBLIC_ACTION_FRAME,
Jeff Johnson295189b2012-06-20 16:38:30 -0700922 P2P_PUBLIC_ACTION_FRAME_SIZE );
923
924 /* P2P Action */
925 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
926 (v_U8_t*)P2P_ACTION_FRAME,
927 P2P_ACTION_FRAME_SIZE );
Chet Lanctot186b5732013-03-18 10:26:30 -0700928
929#ifdef WLAN_FEATURE_11W
930 /* SA Query Response Action Frame */
931 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
932 (v_U8_t*)SA_QUERY_FRAME_RSP,
933 SA_QUERY_FRAME_RSP_SIZE );
934#endif /* WLAN_FEATURE_11W */
Jeff Johnson295189b2012-06-20 16:38:30 -0700935}
936
937#ifdef FEATURE_WLAN_WAPI
938void wlan_hdd_cfg80211_set_key_wapi(hdd_adapter_t* pAdapter, u8 key_index,
939 const u8 *mac_addr, u8 *key , int key_Len)
940{
941 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
942 tCsrRoamSetKey setKey;
943 v_BOOL_t isConnected = TRUE;
944 int status = 0;
945 v_U32_t roamId= 0xFF;
946 tANI_U8 *pKeyPtr = NULL;
947 int n = 0;
948
949 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
950 __func__,pAdapter->device_mode);
951
Gopichand Nakkalae7480202013-02-11 15:24:22 +0530952 vos_mem_zero(&setKey, sizeof(tCsrRoamSetKey));
Jeff Johnson295189b2012-06-20 16:38:30 -0700953 setKey.keyId = key_index; // Store Key ID
954 setKey.encType = eCSR_ENCRYPT_TYPE_WPI; // SET WAPI Encryption
955 setKey.keyDirection = eSIR_TX_RX; // Key Directionn both TX and RX
956 setKey.paeRole = 0 ; // the PAE role
957 if (!mac_addr || is_broadcast_ether_addr(mac_addr))
958 {
959 vos_set_macaddr_broadcast( (v_MACADDR_t *)setKey.peerMac );
960 }
961 else
962 {
963 isConnected = hdd_connIsConnected(pHddStaCtx);
964 vos_mem_copy(setKey.peerMac,&pHddStaCtx->conn_info.bssId,WNI_CFG_BSSID_LEN);
965 }
966 setKey.keyLength = key_Len;
967 pKeyPtr = setKey.Key;
968 memcpy( pKeyPtr, key, key_Len);
969
970 hddLog(VOS_TRACE_LEVEL_INFO,"\n%s: WAPI KEY LENGTH:0x%04x",
971 __func__, key_Len);
972 for (n = 0 ; n < key_Len; n++)
973 hddLog(VOS_TRACE_LEVEL_INFO, "%s WAPI KEY Data[%d]:%02x ",
974 __func__,n,setKey.Key[n]);
975
976 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_SETTING_KEY;
977 if ( isConnected )
978 {
979 status= sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
980 pAdapter->sessionId, &setKey, &roamId );
981 }
982 if ( status != 0 )
983 {
984 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
985 "[%4d] sme_RoamSetKey returned ERROR status= %d",
986 __LINE__, status );
987 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
988 }
989}
990#endif /* FEATURE_WLAN_WAPI*/
991
992#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530993int wlan_hdd_cfg80211_alloc_new_beacon(hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -0700994 beacon_data_t **ppBeacon,
995 struct beacon_parameters *params)
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700996#else
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530997int wlan_hdd_cfg80211_alloc_new_beacon(hdd_adapter_t *pAdapter,
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700998 beacon_data_t **ppBeacon,
999 struct cfg80211_beacon_data *params,
1000 int dtim_period)
1001#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301002{
Jeff Johnson295189b2012-06-20 16:38:30 -07001003 int size;
1004 beacon_data_t *beacon = NULL;
1005 beacon_data_t *old = NULL;
1006 int head_len,tail_len;
1007
Jeff Johnsone7245742012-09-05 17:12:55 -07001008 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07001009 if (params->head && !params->head_len)
1010 return -EINVAL;
1011
1012 old = pAdapter->sessionCtx.ap.beacon;
1013
1014 if (!params->head && !old)
1015 return -EINVAL;
1016
1017 if (params->tail && !params->tail_len)
1018 return -EINVAL;
1019
1020#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,38))
1021 /* Kernel 3.0 is not updating dtim_period for set beacon */
1022 if (!params->dtim_period)
1023 return -EINVAL;
1024#endif
1025
1026 if(params->head)
1027 head_len = params->head_len;
1028 else
1029 head_len = old->head_len;
1030
1031 if(params->tail || !old)
1032 tail_len = params->tail_len;
1033 else
1034 tail_len = old->tail_len;
1035
1036 size = sizeof(beacon_data_t) + head_len + tail_len;
1037
1038 beacon = kzalloc(size, GFP_KERNEL);
1039
1040 if( beacon == NULL )
1041 return -ENOMEM;
1042
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001043#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07001044 if(params->dtim_period || !old )
1045 beacon->dtim_period = params->dtim_period;
1046 else
1047 beacon->dtim_period = old->dtim_period;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001048#else
1049 if(dtim_period || !old )
1050 beacon->dtim_period = dtim_period;
1051 else
1052 beacon->dtim_period = old->dtim_period;
1053#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301054
Jeff Johnson295189b2012-06-20 16:38:30 -07001055 beacon->head = ((u8 *) beacon) + sizeof(beacon_data_t);
1056 beacon->tail = beacon->head + head_len;
1057 beacon->head_len = head_len;
1058 beacon->tail_len = tail_len;
1059
1060 if(params->head) {
1061 memcpy (beacon->head,params->head,beacon->head_len);
1062 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301063 else {
Jeff Johnson295189b2012-06-20 16:38:30 -07001064 if(old)
1065 memcpy (beacon->head,old->head,beacon->head_len);
1066 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301067
Jeff Johnson295189b2012-06-20 16:38:30 -07001068 if(params->tail) {
1069 memcpy (beacon->tail,params->tail,beacon->tail_len);
1070 }
1071 else {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301072 if(old)
Jeff Johnson295189b2012-06-20 16:38:30 -07001073 memcpy (beacon->tail,old->tail,beacon->tail_len);
1074 }
1075
1076 *ppBeacon = beacon;
1077
1078 kfree(old);
1079
1080 return 0;
1081
1082}
Jeff Johnson295189b2012-06-20 16:38:30 -07001083
1084v_U8_t* wlan_hdd_cfg80211_get_ie_ptr(v_U8_t *pIes, int length, v_U8_t eid)
1085{
1086 int left = length;
1087 v_U8_t *ptr = pIes;
1088 v_U8_t elem_id,elem_len;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301089
Jeff Johnson295189b2012-06-20 16:38:30 -07001090 while(left >= 2)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301091 {
Jeff Johnson295189b2012-06-20 16:38:30 -07001092 elem_id = ptr[0];
1093 elem_len = ptr[1];
1094 left -= 2;
1095 if(elem_len > left)
1096 {
1097 hddLog(VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi8bdd3112012-09-24 13:55:14 -07001098 FL("****Invalid IEs eid = %d elem_len=%d left=%d*****"),
Jeff Johnson295189b2012-06-20 16:38:30 -07001099 eid,elem_len,left);
1100 return NULL;
1101 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301102 if (elem_id == eid)
Jeff Johnson295189b2012-06-20 16:38:30 -07001103 {
1104 return ptr;
1105 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301106
Jeff Johnson295189b2012-06-20 16:38:30 -07001107 left -= elem_len;
1108 ptr += (elem_len + 2);
1109 }
1110 return NULL;
1111}
1112
Jeff Johnson295189b2012-06-20 16:38:30 -07001113/* Check if rate is 11g rate or not */
1114static int wlan_hdd_rate_is_11g(u8 rate)
1115{
Sanjay Devnani28322e22013-06-21 16:13:40 -07001116 static const u8 gRateArray[8] = {12, 18, 24, 36, 48, 72, 96, 108}; /* actual rate * 2 */
Jeff Johnson295189b2012-06-20 16:38:30 -07001117 u8 i;
1118 for (i = 0; i < 8; i++)
1119 {
1120 if(rate == gRateArray[i])
1121 return TRUE;
1122 }
1123 return FALSE;
1124}
1125
1126/* Check for 11g rate and set proper 11g only mode */
1127static void wlan_hdd_check_11gmode(u8 *pIe, u8* require_ht,
1128 u8* pCheckRatesfor11g, eSapPhyMode* pSapHw_mode)
1129{
1130 u8 i, num_rates = pIe[0];
1131
1132 pIe += 1;
1133 for ( i = 0; i < num_rates; i++)
1134 {
1135 if( *pCheckRatesfor11g && (TRUE == wlan_hdd_rate_is_11g(pIe[i] & RATE_MASK)))
1136 {
1137 /* If rate set have 11g rate than change the mode to 11G */
1138 *pSapHw_mode = eSAP_DOT11_MODE_11g;
1139 if (pIe[i] & BASIC_RATE_MASK)
1140 {
1141 /* If we have 11g rate as basic rate, it means mode
1142 is 11g only mode.
1143 */
1144 *pSapHw_mode = eSAP_DOT11_MODE_11g_ONLY;
1145 *pCheckRatesfor11g = FALSE;
1146 }
1147 }
1148 else if((BASIC_RATE_MASK | WLAN_BSS_MEMBERSHIP_SELECTOR_HT_PHY) == pIe[i])
1149 {
1150 *require_ht = TRUE;
1151 }
1152 }
1153 return;
1154}
1155
1156static void wlan_hdd_set_sapHwmode(hdd_adapter_t *pHostapdAdapter)
1157{
1158 tsap_Config_t *pConfig = &pHostapdAdapter->sessionCtx.ap.sapConfig;
1159 beacon_data_t *pBeacon = pHostapdAdapter->sessionCtx.ap.beacon;
1160 struct ieee80211_mgmt *pMgmt_frame = (struct ieee80211_mgmt*)pBeacon->head;
1161 u8 checkRatesfor11g = TRUE;
1162 u8 require_ht = FALSE;
1163 u8 *pIe=NULL;
1164
1165 pConfig->SapHw_mode= eSAP_DOT11_MODE_11b;
1166
1167 pIe = wlan_hdd_cfg80211_get_ie_ptr(&pMgmt_frame->u.beacon.variable[0],
1168 pBeacon->head_len, WLAN_EID_SUPP_RATES);
1169 if (pIe != NULL)
1170 {
1171 pIe += 1;
1172 wlan_hdd_check_11gmode(pIe, &require_ht, &checkRatesfor11g,
1173 &pConfig->SapHw_mode);
1174 }
1175
1176 pIe = wlan_hdd_cfg80211_get_ie_ptr(pBeacon->tail, pBeacon->tail_len,
1177 WLAN_EID_EXT_SUPP_RATES);
1178 if (pIe != NULL)
1179 {
1180
1181 pIe += 1;
1182 wlan_hdd_check_11gmode(pIe, &require_ht, &checkRatesfor11g,
1183 &pConfig->SapHw_mode);
1184 }
1185
1186 if( pConfig->channel > 14 )
1187 {
1188 pConfig->SapHw_mode= eSAP_DOT11_MODE_11a;
1189 }
1190
1191 pIe = wlan_hdd_cfg80211_get_ie_ptr(pBeacon->tail, pBeacon->tail_len,
1192 WLAN_EID_HT_CAPABILITY);
1193
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301194 if(pIe)
Jeff Johnson295189b2012-06-20 16:38:30 -07001195 {
1196 pConfig->SapHw_mode= eSAP_DOT11_MODE_11n;
1197 if(require_ht)
1198 pConfig->SapHw_mode= eSAP_DOT11_MODE_11n_ONLY;
1199 }
1200}
1201
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301202static int wlan_hdd_add_ie(hdd_adapter_t* pHostapdAdapter, v_U8_t *genie,
1203 v_U8_t *total_ielen, v_U8_t *oui, v_U8_t oui_size)
1204{
Arif Hussaine7f3ea52013-09-12 21:56:36 -07001205 v_U16_t ielen = 0;
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301206 v_U8_t *pIe = NULL;
1207 beacon_data_t *pBeacon = pHostapdAdapter->sessionCtx.ap.beacon;
1208
1209 pIe = wlan_hdd_get_vendor_oui_ie_ptr(oui, oui_size,
1210 pBeacon->tail, pBeacon->tail_len);
1211
1212 if (pIe)
1213 {
1214 ielen = pIe[1] + 2;
1215 if ((*total_ielen + ielen) <= MAX_GENIE_LEN)
1216 {
1217 vos_mem_copy(&genie[*total_ielen], pIe, ielen);
1218 }
1219 else
1220 {
1221 hddLog( VOS_TRACE_LEVEL_ERROR, "**Ie Length is too big***");
1222 return -EINVAL;
1223 }
1224 *total_ielen += ielen;
1225 }
1226 return 0;
1227}
1228
Arif Hussaine7f3ea52013-09-12 21:56:36 -07001229static void wlan_hdd_add_hostapd_conf_vsie(hdd_adapter_t* pHostapdAdapter,
1230 v_U8_t *genie, v_U8_t *total_ielen)
1231{
1232 beacon_data_t *pBeacon = pHostapdAdapter->sessionCtx.ap.beacon;
1233 int left = pBeacon->tail_len;
1234 v_U8_t *ptr = pBeacon->tail;
1235 v_U8_t elem_id, elem_len;
1236 v_U16_t ielen = 0;
1237
1238 if ( NULL == ptr || 0 == left )
1239 return;
1240
1241 while (left >= 2)
1242 {
1243 elem_id = ptr[0];
1244 elem_len = ptr[1];
1245 left -= 2;
1246 if (elem_len > left)
1247 {
1248 hddLog( VOS_TRACE_LEVEL_ERROR,
1249 "****Invalid IEs eid = %d elem_len=%d left=%d*****",
1250 elem_id, elem_len, left);
1251 return;
1252 }
1253 if (IE_EID_VENDOR == elem_id)
1254 {
1255 /* skipping the VSIE's which we don't want to include or
1256 * it will be included by existing code
1257 */
1258 if ((memcmp( &ptr[2], WPS_OUI_TYPE, WPS_OUI_TYPE_SIZE) != 0 ) &&
1259#ifdef WLAN_FEATURE_WFD
1260 (memcmp( &ptr[2], WFD_OUI_TYPE, WFD_OUI_TYPE_SIZE) != 0) &&
1261#endif
1262 (memcmp( &ptr[2], WHITELIST_OUI_TYPE, WPA_OUI_TYPE_SIZE) != 0) &&
1263 (memcmp( &ptr[2], BLACKLIST_OUI_TYPE, WPA_OUI_TYPE_SIZE) != 0) &&
1264 (memcmp( &ptr[2], "\x00\x50\xf2\x02", WPA_OUI_TYPE_SIZE) != 0) &&
1265 (memcmp( &ptr[2], WPA_OUI_TYPE, WPA_OUI_TYPE_SIZE) != 0) &&
1266 (memcmp( &ptr[2], P2P_OUI_TYPE, P2P_OUI_TYPE_SIZE) != 0))
1267 {
1268 ielen = ptr[1] + 2;
1269 if ((*total_ielen + ielen) <= MAX_GENIE_LEN)
1270 {
1271 vos_mem_copy(&genie[*total_ielen], ptr, ielen);
1272 *total_ielen += ielen;
1273 }
1274 else
1275 {
1276 hddLog( VOS_TRACE_LEVEL_ERROR,
1277 "IE Length is too big "
1278 "IEs eid=%d elem_len=%d total_ie_lent=%d",
1279 elem_id, elem_len, *total_ielen);
1280 }
1281 }
1282 }
1283
1284 left -= elem_len;
1285 ptr += (elem_len + 2);
1286 }
1287 return;
1288}
1289
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001290#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07001291static int wlan_hdd_cfg80211_update_apies(hdd_adapter_t* pHostapdAdapter,
1292 struct beacon_parameters *params)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001293#else
1294static int wlan_hdd_cfg80211_update_apies(hdd_adapter_t* pHostapdAdapter,
1295 struct cfg80211_beacon_data *params)
1296#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07001297{
1298 v_U8_t *genie;
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301299 v_U8_t total_ielen = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07001300 v_U8_t addIE[1] = {0};
Jeff Johnsone7245742012-09-05 17:12:55 -07001301 int ret = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07001302
1303 genie = vos_mem_malloc(MAX_GENIE_LEN);
1304
1305 if(genie == NULL) {
1306
1307 return -ENOMEM;
1308 }
1309
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301310 if (0 != wlan_hdd_add_ie(pHostapdAdapter, genie,
1311 &total_ielen, WPS_OUI_TYPE, WPS_OUI_TYPE_SIZE))
Jeff Johnson295189b2012-06-20 16:38:30 -07001312 {
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301313 ret = -EINVAL;
1314 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001315 }
1316
1317#ifdef WLAN_FEATURE_WFD
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301318 if (0 != wlan_hdd_add_ie(pHostapdAdapter, genie,
1319 &total_ielen, WFD_OUI_TYPE, WFD_OUI_TYPE_SIZE))
1320 {
1321 ret = -EINVAL;
1322 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001323 }
1324#endif
1325
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301326 if (0 != wlan_hdd_add_ie(pHostapdAdapter, genie,
1327 &total_ielen, P2P_OUI_TYPE, P2P_OUI_TYPE_SIZE))
Jeff Johnson295189b2012-06-20 16:38:30 -07001328 {
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301329 ret = -EINVAL;
1330 goto done;
1331 }
1332
1333 if (WLAN_HDD_SOFTAP == pHostapdAdapter->device_mode)
1334 {
Arif Hussaine7f3ea52013-09-12 21:56:36 -07001335 wlan_hdd_add_hostapd_conf_vsie(pHostapdAdapter, genie, &total_ielen);
Jeff Johnson295189b2012-06-20 16:38:30 -07001336 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001337
1338 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1339 WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA, genie, total_ielen, NULL,
1340 eANI_BOOLEAN_FALSE)==eHAL_STATUS_FAILURE)
1341 {
1342 hddLog(LOGE,
1343 "Could not pass on WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001344 ret = -EINVAL;
1345 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001346 }
1347
1348 if (ccmCfgSetInt((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1349 WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG, 1,NULL,
1350 test_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags) ?
1351 eANI_BOOLEAN_TRUE : eANI_BOOLEAN_FALSE)
1352 ==eHAL_STATUS_FAILURE)
1353 {
1354 hddLog(LOGE,
1355 "Could not pass on WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001356 ret = -EINVAL;
1357 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001358 }
1359
1360 // Added for ProResp IE
1361 if ( (params->proberesp_ies != NULL) && (params->proberesp_ies_len != 0) )
1362 {
1363 u16 rem_probe_resp_ie_len = params->proberesp_ies_len;
1364 u8 probe_rsp_ie_len[3] = {0};
1365 u8 counter = 0;
1366 /* Check Probe Resp Length if it is greater then 255 then Store
1367 Probe Resp IEs into WNI_CFG_PROBE_RSP_ADDNIE_DATA1 &
1368 WNI_CFG_PROBE_RSP_ADDNIE_DATA2 CFG Variable As We are not able
1369 Store More then 255 bytes into One Variable.
1370 */
1371 while ((rem_probe_resp_ie_len > 0) && (counter < 3))
1372 {
1373 if (rem_probe_resp_ie_len > MAX_CFG_STRING_LEN)
1374 {
1375 probe_rsp_ie_len[counter++] = MAX_CFG_STRING_LEN;
1376 rem_probe_resp_ie_len -= MAX_CFG_STRING_LEN;
1377 }
1378 else
1379 {
1380 probe_rsp_ie_len[counter++] = rem_probe_resp_ie_len;
1381 rem_probe_resp_ie_len = 0;
1382 }
1383 }
1384
1385 rem_probe_resp_ie_len = 0;
1386
1387 if (probe_rsp_ie_len[0] > 0)
1388 {
1389 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1390 WNI_CFG_PROBE_RSP_ADDNIE_DATA1,
1391 (tANI_U8*)&params->proberesp_ies[rem_probe_resp_ie_len],
1392 probe_rsp_ie_len[0], NULL,
1393 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
1394 {
1395 hddLog(LOGE,
1396 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA1 to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001397 ret = -EINVAL;
1398 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001399 }
1400 rem_probe_resp_ie_len += probe_rsp_ie_len[0];
1401 }
1402
1403 if (probe_rsp_ie_len[1] > 0)
1404 {
1405 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1406 WNI_CFG_PROBE_RSP_ADDNIE_DATA2,
1407 (tANI_U8*)&params->proberesp_ies[rem_probe_resp_ie_len],
1408 probe_rsp_ie_len[1], NULL,
1409 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
1410 {
1411 hddLog(LOGE,
1412 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA2 to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001413 ret = -EINVAL;
1414 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001415 }
1416 rem_probe_resp_ie_len += probe_rsp_ie_len[1];
1417 }
1418
1419 if (probe_rsp_ie_len[2] > 0)
1420 {
1421 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1422 WNI_CFG_PROBE_RSP_ADDNIE_DATA3,
1423 (tANI_U8*)&params->proberesp_ies[rem_probe_resp_ie_len],
1424 probe_rsp_ie_len[2], NULL,
1425 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
1426 {
1427 hddLog(LOGE,
1428 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA3 to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001429 ret = -EINVAL;
1430 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001431 }
1432 rem_probe_resp_ie_len += probe_rsp_ie_len[2];
1433 }
1434
1435 if (probe_rsp_ie_len[1] == 0 )
1436 {
1437 if ( eHAL_STATUS_FAILURE == ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1438 WNI_CFG_PROBE_RSP_ADDNIE_DATA2, (tANI_U8*)addIE, 0, NULL,
1439 eANI_BOOLEAN_FALSE) )
1440 {
1441 hddLog(LOGE,
1442 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA2 to CCM\n");
1443 }
1444 }
1445
1446 if (probe_rsp_ie_len[2] == 0 )
1447 {
1448 if ( eHAL_STATUS_FAILURE == ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1449 WNI_CFG_PROBE_RSP_ADDNIE_DATA3, (tANI_U8*)addIE, 0, NULL,
1450 eANI_BOOLEAN_FALSE) )
1451 {
1452 hddLog(LOGE,
1453 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA3 to CCM\n");
1454 }
1455 }
1456
1457 if (ccmCfgSetInt((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1458 WNI_CFG_PROBE_RSP_ADDNIE_FLAG, 1,NULL,
1459 test_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags) ?
1460 eANI_BOOLEAN_TRUE : eANI_BOOLEAN_FALSE)
1461 == eHAL_STATUS_FAILURE)
1462 {
1463 hddLog(LOGE,
1464 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_FLAG to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001465 ret = -EINVAL;
1466 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001467 }
1468 }
1469 else
1470 {
1471 // Reset WNI_CFG_PROBE_RSP Flags
1472 wlan_hdd_reset_prob_rspies(pHostapdAdapter);
1473
1474 hddLog(VOS_TRACE_LEVEL_INFO,
1475 "%s: No Probe Response IE received in set beacon",
1476 __func__);
1477 }
1478
1479 // Added for AssocResp IE
1480 if ( (params->assocresp_ies != NULL) && (params->assocresp_ies_len != 0) )
1481 {
1482 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1483 WNI_CFG_ASSOC_RSP_ADDNIE_DATA, (tANI_U8*)params->assocresp_ies,
1484 params->assocresp_ies_len, NULL,
1485 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
1486 {
1487 hddLog(LOGE,
1488 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_DATA to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001489 ret = -EINVAL;
1490 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001491 }
1492
1493 if (ccmCfgSetInt((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1494 WNI_CFG_ASSOC_RSP_ADDNIE_FLAG, 1, NULL,
1495 test_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags) ?
1496 eANI_BOOLEAN_TRUE : eANI_BOOLEAN_FALSE)
1497 == eHAL_STATUS_FAILURE)
1498 {
1499 hddLog(LOGE,
1500 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_FLAG to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001501 ret = -EINVAL;
1502 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001503 }
1504 }
1505 else
1506 {
1507 hddLog(VOS_TRACE_LEVEL_INFO,
1508 "%s: No Assoc Response IE received in set beacon",
1509 __func__);
1510
1511 if ( eHAL_STATUS_FAILURE == ccmCfgSetInt((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1512 WNI_CFG_ASSOC_RSP_ADDNIE_FLAG, 0, NULL,
1513 eANI_BOOLEAN_FALSE) )
1514 {
1515 hddLog(LOGE,
1516 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_FLAG to CCM\n");
1517 }
1518 }
1519
Jeff Johnsone7245742012-09-05 17:12:55 -07001520done:
Jeff Johnson295189b2012-06-20 16:38:30 -07001521 vos_mem_free(genie);
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301522 return ret;
Jeff Johnson295189b2012-06-20 16:38:30 -07001523}
Jeff Johnson295189b2012-06-20 16:38:30 -07001524
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301525/*
Jeff Johnson295189b2012-06-20 16:38:30 -07001526 * FUNCTION: wlan_hdd_validate_operation_channel
1527 * called by wlan_hdd_cfg80211_start_bss() and
1528 * wlan_hdd_cfg80211_set_channel()
1529 * This function validates whether given channel is part of valid
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301530 * channel list.
1531 */
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07001532VOS_STATUS wlan_hdd_validate_operation_channel(hdd_adapter_t *pAdapter,int channel)
Jeff Johnson295189b2012-06-20 16:38:30 -07001533{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301534
Jeff Johnson295189b2012-06-20 16:38:30 -07001535 v_U32_t num_ch = 0;
1536 u8 valid_ch[WNI_CFG_VALID_CHANNEL_LIST_LEN];
1537 u32 indx = 0;
1538 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301539 v_U8_t fValidChannel = FALSE, count = 0;
1540 hdd_config_t *hdd_pConfig_ini= (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301541
Jeff Johnson295189b2012-06-20 16:38:30 -07001542 num_ch = WNI_CFG_VALID_CHANNEL_LIST_LEN;
1543
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301544 if ( hdd_pConfig_ini->sapAllowAllChannel)
Jeff Johnson295189b2012-06-20 16:38:30 -07001545 {
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301546 /* Validate the channel */
1547 for (count = RF_CHAN_1 ; count <= RF_CHAN_165 ; count++)
Jeff Johnson295189b2012-06-20 16:38:30 -07001548 {
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301549 if ( channel == rfChannels[count].channelNum )
1550 {
1551 fValidChannel = TRUE;
1552 break;
1553 }
1554 }
1555 if (fValidChannel != TRUE)
1556 {
1557 hddLog(VOS_TRACE_LEVEL_ERROR,
1558 "%s: Invalid Channel [%d]", __func__, channel);
1559 return VOS_STATUS_E_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07001560 }
1561 }
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301562 else
Jeff Johnson295189b2012-06-20 16:38:30 -07001563 {
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301564 if (0 != ccmCfgGetStr(hHal, WNI_CFG_VALID_CHANNEL_LIST,
1565 valid_ch, &num_ch))
1566 {
1567 hddLog(VOS_TRACE_LEVEL_ERROR,
1568 "%s: failed to get valid channel list", __func__);
1569 return VOS_STATUS_E_FAILURE;
1570 }
1571 for (indx = 0; indx < num_ch; indx++)
1572 {
1573 if (channel == valid_ch[indx])
1574 {
1575 break;
1576 }
1577 }
1578
1579 if (indx >= num_ch)
1580 {
1581 hddLog(VOS_TRACE_LEVEL_ERROR,
1582 "%s: Invalid Channel [%d]", __func__, channel);
1583 return VOS_STATUS_E_FAILURE;
1584 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001585 }
1586 return VOS_STATUS_SUCCESS;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301587
Jeff Johnson295189b2012-06-20 16:38:30 -07001588}
1589
Viral Modi3a32cc52013-02-08 11:14:52 -08001590/**
1591 * FUNCTION: wlan_hdd_cfg80211_set_channel
1592 * This function is used to set the channel number
1593 */
1594static int wlan_hdd_cfg80211_set_channel( struct wiphy *wiphy, struct net_device *dev,
1595 struct ieee80211_channel *chan,
1596 enum nl80211_channel_type channel_type
1597 )
1598{
1599 v_U32_t num_ch = 0;
Jeff Johnson4416a782013-03-25 14:17:50 -07001600 int channel = 0;
Viral Modi3a32cc52013-02-08 11:14:52 -08001601 hdd_adapter_t *pAdapter = NULL;
1602 int freq = chan->center_freq; /* freq is in MHZ */
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05301603 hdd_context_t *pHddCtx;
1604 int status;
Viral Modi3a32cc52013-02-08 11:14:52 -08001605
1606 ENTER();
1607
1608 if( NULL == dev )
1609 {
1610 hddLog(VOS_TRACE_LEVEL_ERROR,
1611 "%s: Called with dev = NULL.\n", __func__);
1612 return -ENODEV;
1613 }
1614 pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
1615
1616 hddLog(VOS_TRACE_LEVEL_INFO,
1617 "%s: device_mode = %d freq = %d \n",__func__,
1618 pAdapter->device_mode, chan->center_freq);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05301619
1620 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
1621 status = wlan_hdd_validate_context(pHddCtx);
1622
1623 if (0 != status)
Viral Modi3a32cc52013-02-08 11:14:52 -08001624 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05301625 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1626 "%s: HDD context is not valid", __func__);
1627 return status;
Viral Modi3a32cc52013-02-08 11:14:52 -08001628 }
1629
1630 /*
1631 * Do freq to chan conversion
1632 * TODO: for 11a
1633 */
1634
1635 channel = ieee80211_frequency_to_channel(freq);
1636
1637 /* Check freq range */
1638 if ((WNI_CFG_CURRENT_CHANNEL_STAMIN > channel) ||
1639 (WNI_CFG_CURRENT_CHANNEL_STAMAX < channel))
1640 {
1641 hddLog(VOS_TRACE_LEVEL_ERROR,
1642 "%s: Channel [%d] is outside valid range from %d to %d\n",
1643 __func__, channel, WNI_CFG_CURRENT_CHANNEL_STAMIN,
1644 WNI_CFG_CURRENT_CHANNEL_STAMAX);
1645 return -EINVAL;
1646 }
1647
1648 num_ch = WNI_CFG_VALID_CHANNEL_LIST_LEN;
1649
Gopichand Nakkala6ab19562013-03-07 13:59:42 +05301650 if ((WLAN_HDD_SOFTAP != pAdapter->device_mode) &&
1651 (WLAN_HDD_P2P_GO != pAdapter->device_mode))
Viral Modi3a32cc52013-02-08 11:14:52 -08001652 {
1653 if(VOS_STATUS_SUCCESS != wlan_hdd_validate_operation_channel(pAdapter,channel))
1654 {
1655 hddLog(VOS_TRACE_LEVEL_ERROR,
1656 "%s: Invalid Channel [%d] \n", __func__, channel);
1657 return -EINVAL;
1658 }
1659 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
1660 "%s: set channel to [%d] for device mode =%d",
1661 __func__, channel,pAdapter->device_mode);
1662 }
1663 if( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Viral Modi3a32cc52013-02-08 11:14:52 -08001664 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Viral Modi3a32cc52013-02-08 11:14:52 -08001665 )
1666 {
1667 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
1668 tCsrRoamProfile * pRoamProfile = &pWextState->roamProfile;
1669 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
1670
1671 if (eConnectionState_IbssConnected == pHddStaCtx->conn_info.connState)
1672 {
1673 /* Link is up then return cant set channel*/
1674 hddLog( VOS_TRACE_LEVEL_ERROR,
1675 "%s: IBSS Associated, can't set the channel\n", __func__);
1676 return -EINVAL;
1677 }
1678
1679 num_ch = pRoamProfile->ChannelInfo.numOfChannels = 1;
1680 pHddStaCtx->conn_info.operationChannel = channel;
1681 pRoamProfile->ChannelInfo.ChannelList =
1682 &pHddStaCtx->conn_info.operationChannel;
1683 }
1684 else if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Viral Modi3a32cc52013-02-08 11:14:52 -08001685 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Viral Modi3a32cc52013-02-08 11:14:52 -08001686 )
1687 {
Gopichand Nakkalac8fa7b62013-03-11 13:56:41 +05301688 if (WLAN_HDD_P2P_GO == pAdapter->device_mode)
1689 {
1690 if(VOS_STATUS_SUCCESS !=
1691 wlan_hdd_validate_operation_channel(pAdapter,channel))
1692 {
1693 hddLog(VOS_TRACE_LEVEL_ERROR,
1694 "%s: Invalid Channel [%d] \n", __func__, channel);
1695 return -EINVAL;
1696 }
1697 (WLAN_HDD_GET_AP_CTX_PTR(pAdapter))->sapConfig.channel = channel;
1698 }
1699 else if ( WLAN_HDD_SOFTAP == pAdapter->device_mode )
Viral Modi3a32cc52013-02-08 11:14:52 -08001700 {
1701 hdd_config_t *cfg_param = (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini;
1702
1703 /* If auto channel selection is configured as enable/ 1 then ignore
1704 channel set by supplicant
1705 */
1706 if ( cfg_param->apAutoChannelSelection )
1707 {
Gopichand Nakkalac8fa7b62013-03-11 13:56:41 +05301708 (WLAN_HDD_GET_AP_CTX_PTR(pAdapter))->sapConfig.channel =
1709 AUTO_CHANNEL_SELECT;
Viral Modi3a32cc52013-02-08 11:14:52 -08001710 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
1711 "%s: set channel to auto channel (0) for device mode =%d",
1712 __func__, pAdapter->device_mode);
1713 }
Gopichand Nakkalac8fa7b62013-03-11 13:56:41 +05301714 else
1715 {
1716 if(VOS_STATUS_SUCCESS !=
1717 wlan_hdd_validate_operation_channel(pAdapter,channel))
1718 {
1719 hddLog(VOS_TRACE_LEVEL_ERROR,
1720 "%s: Invalid Channel [%d] \n", __func__, channel);
1721 return -EINVAL;
1722 }
1723 (WLAN_HDD_GET_AP_CTX_PTR(pAdapter))->sapConfig.channel = channel;
1724 }
Viral Modi3a32cc52013-02-08 11:14:52 -08001725 }
1726 }
1727 else
1728 {
1729 hddLog(VOS_TRACE_LEVEL_FATAL,
1730 "%s: Invalid device mode failed to set valid channel", __func__);
1731 return -EINVAL;
1732 }
1733 EXIT();
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05301734 return status;
Viral Modi3a32cc52013-02-08 11:14:52 -08001735}
1736
Jeff Johnson295189b2012-06-20 16:38:30 -07001737#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
1738static int wlan_hdd_cfg80211_start_bss(hdd_adapter_t *pHostapdAdapter,
1739 struct beacon_parameters *params)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001740#else
1741static int wlan_hdd_cfg80211_start_bss(hdd_adapter_t *pHostapdAdapter,
1742 struct cfg80211_beacon_data *params,
1743 const u8 *ssid, size_t ssid_len,
1744 enum nl80211_hidden_ssid hidden_ssid)
1745#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07001746{
1747 tsap_Config_t *pConfig;
1748 beacon_data_t *pBeacon = NULL;
1749 struct ieee80211_mgmt *pMgmt_frame;
1750 v_U8_t *pIe=NULL;
1751 v_U16_t capab_info;
1752 eCsrAuthType RSNAuthType;
1753 eCsrEncryptionType RSNEncryptType;
1754 eCsrEncryptionType mcRSNEncryptType;
1755 int status = VOS_STATUS_SUCCESS;
1756 tpWLAN_SAPEventCB pSapEventCallback;
1757 hdd_hostapd_state_t *pHostapdState;
1758 v_U8_t wpaRsnIEdata[(SIR_MAC_MAX_IE_LENGTH * 2)+4]; //Max ie length 255 * 2(WPA+RSN) + 2 bytes (vendor specific ID) * 2
1759 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pHostapdAdapter))->pvosContext;
Madan Mohan Koyylamudia16d0202013-02-01 11:05:57 +05301760 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pHostapdAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001761 struct qc_mac_acl_entry *acl_entry = NULL;
1762 v_SINT_t i;
Madan Mohan Koyyalamudi543172b2012-12-05 16:40:18 -08001763 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pHostapdAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001764
1765 ENTER();
1766
1767 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pHostapdAdapter);
1768
1769 pConfig = &pHostapdAdapter->sessionCtx.ap.sapConfig;
1770
1771 pBeacon = pHostapdAdapter->sessionCtx.ap.beacon;
1772
1773 pMgmt_frame = (struct ieee80211_mgmt*)pBeacon->head;
1774
1775 pConfig->beacon_int = pMgmt_frame->u.beacon.beacon_int;
1776
1777 //channel is already set in the set_channel Call back
1778 //pConfig->channel = pCommitConfig->channel;
1779
1780 /*Protection parameter to enable or disable*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301781 pConfig->protEnabled =
Jeff Johnson295189b2012-06-20 16:38:30 -07001782 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apProtEnabled;
1783
1784 pConfig->dtim_period = pBeacon->dtim_period;
1785
1786 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,"****pConfig->dtim_period=%d***\n",
1787 pConfig->dtim_period);
1788
1789
Madan Mohan Koyyalamudie0ca11f2012-11-27 15:57:52 -08001790 if (pHostapdAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson32d95a32012-09-10 13:15:23 -07001791 {
1792 pIe = wlan_hdd_cfg80211_get_ie_ptr(pBeacon->tail, pBeacon->tail_len,
Jeff Johnson295189b2012-06-20 16:38:30 -07001793 WLAN_EID_COUNTRY);
Jeff Johnson32d95a32012-09-10 13:15:23 -07001794 if(pIe)
Jeff Johnson295189b2012-06-20 16:38:30 -07001795 {
Jeff Johnson32d95a32012-09-10 13:15:23 -07001796 tANI_BOOLEAN restartNeeded;
Jeff Johnson32d95a32012-09-10 13:15:23 -07001797 pConfig->ieee80211d = 1;
1798 vos_mem_copy(pConfig->countryCode, &pIe[2], 3);
1799 sme_setRegInfo(hHal, pConfig->countryCode);
1800 sme_ResetCountryCodeInformation(hHal, &restartNeeded);
Jeff Johnson295189b2012-06-20 16:38:30 -07001801 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07001802 else
1803 {
1804 pConfig->ieee80211d = 0;
1805 }
Madan Mohan Koyylamudia16d0202013-02-01 11:05:57 +05301806 /*
1807 * If auto channel is configured i.e. channel is 0,
1808 * so skip channel validation.
1809 */
1810 if( AUTO_CHANNEL_SELECT != pConfig->channel )
1811 {
1812 if(VOS_STATUS_SUCCESS != wlan_hdd_validate_operation_channel(pHostapdAdapter,pConfig->channel))
1813 {
1814 hddLog(VOS_TRACE_LEVEL_ERROR,
1815 "%s: Invalid Channel [%d] \n", __func__, pConfig->channel);
1816 return -EINVAL;
1817 }
1818 }
1819 else
1820 {
1821 if(1 != pHddCtx->is_dynamic_channel_range_set)
1822 {
1823 hdd_config_t *hdd_pConfig= (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini;
1824 WLANSAP_SetChannelRange(hHal, hdd_pConfig->apStartChannelNum,
1825 hdd_pConfig->apEndChannelNum,hdd_pConfig->apOperatingBand);
1826 }
1827 pHddCtx->is_dynamic_channel_range_set = 0;
1828 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001829 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07001830 else
Jeff Johnson295189b2012-06-20 16:38:30 -07001831 {
1832 pConfig->ieee80211d = 0;
1833 }
1834 pConfig->authType = eSAP_AUTO_SWITCH;
1835
1836 capab_info = pMgmt_frame->u.beacon.capab_info;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301837
1838 pConfig->privacy = (pMgmt_frame->u.beacon.capab_info &
Jeff Johnson295189b2012-06-20 16:38:30 -07001839 WLAN_CAPABILITY_PRIVACY) ? VOS_TRUE : VOS_FALSE;
1840
1841 (WLAN_HDD_GET_AP_CTX_PTR(pHostapdAdapter))->uPrivacy = pConfig->privacy;
1842
1843 /*Set wps station to configured*/
1844 pIe = wlan_hdd_get_wps_ie_ptr(pBeacon->tail, pBeacon->tail_len);
1845
1846 if(pIe)
1847 {
1848 if(pIe[1] < (2 + WPS_OUI_TYPE_SIZE))
1849 {
1850 hddLog( VOS_TRACE_LEVEL_ERROR, "**Wps Ie Length is too small***\n");
1851 return -EINVAL;
1852 }
1853 else if(memcmp(&pIe[2], WPS_OUI_TYPE, WPS_OUI_TYPE_SIZE) == 0)
1854 {
Madan Mohan Koyyalamudi8bdd3112012-09-24 13:55:14 -07001855 hddLog( VOS_TRACE_LEVEL_INFO, "** WPS IE(len %d) ***", (pIe[1]+2));
Jeff Johnson295189b2012-06-20 16:38:30 -07001856 /* Check 15 bit of WPS IE as it contain information for wps state
1857 * WPS state
1858 */
1859 if(SAP_WPS_ENABLED_UNCONFIGURED == pIe[15])
1860 {
1861 pConfig->wps_state = SAP_WPS_ENABLED_UNCONFIGURED;
1862 } else if(SAP_WPS_ENABLED_CONFIGURED == pIe[15])
1863 {
1864 pConfig->wps_state = SAP_WPS_ENABLED_CONFIGURED;
1865 }
1866 }
1867 }
1868 else
1869 {
1870 pConfig->wps_state = SAP_WPS_DISABLED;
1871 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301872 pConfig->fwdWPSPBCProbeReq = 1; // Forward WPS PBC probe request frame up
Jeff Johnson295189b2012-06-20 16:38:30 -07001873
1874 pConfig->RSNWPAReqIELength = 0;
1875 pConfig->pRSNWPAReqIE = NULL;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301876 pIe = wlan_hdd_cfg80211_get_ie_ptr(pBeacon->tail, pBeacon->tail_len,
Jeff Johnson295189b2012-06-20 16:38:30 -07001877 WLAN_EID_RSN);
1878 if(pIe && pIe[1])
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301879 {
Jeff Johnson295189b2012-06-20 16:38:30 -07001880 pConfig->RSNWPAReqIELength = pIe[1] + 2;
1881 memcpy(&wpaRsnIEdata[0], pIe, pConfig->RSNWPAReqIELength);
1882 pConfig->pRSNWPAReqIE = &wpaRsnIEdata[0];
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301883 /* The actual processing may eventually be more extensive than
1884 * this. Right now, just consume any PMKIDs that are sent in
Jeff Johnson295189b2012-06-20 16:38:30 -07001885 * by the app.
1886 * */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301887 status = hdd_softap_unpackIE(
Jeff Johnson295189b2012-06-20 16:38:30 -07001888 vos_get_context( VOS_MODULE_ID_SME, pVosContext),
1889 &RSNEncryptType,
1890 &mcRSNEncryptType,
1891 &RSNAuthType,
1892 pConfig->pRSNWPAReqIE[1]+2,
1893 pConfig->pRSNWPAReqIE );
1894
1895 if( VOS_STATUS_SUCCESS == status )
1896 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301897 /* Now copy over all the security attributes you have
1898 * parsed out
Jeff Johnson295189b2012-06-20 16:38:30 -07001899 * */
1900 pConfig->RSNEncryptType = RSNEncryptType; // Use the cipher type in the RSN IE
1901 pConfig->mcRSNEncryptType = mcRSNEncryptType;
1902 (WLAN_HDD_GET_AP_CTX_PTR(pHostapdAdapter))->ucEncryptType
1903 = RSNEncryptType;
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +05301904 hddLog( LOG1, FL("CSR AuthType = %d, "
Jeff Johnson295189b2012-06-20 16:38:30 -07001905 "EncryptionType = %d mcEncryptionType = %d\n"),
1906 RSNAuthType, RSNEncryptType, mcRSNEncryptType);
1907 }
1908 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301909
Jeff Johnson295189b2012-06-20 16:38:30 -07001910 pIe = wlan_hdd_get_vendor_oui_ie_ptr(WPA_OUI_TYPE, WPA_OUI_TYPE_SIZE,
1911 pBeacon->tail, pBeacon->tail_len);
1912
1913 if(pIe && pIe[1] && (pIe[0] == DOT11F_EID_WPA))
1914 {
1915 if (pConfig->pRSNWPAReqIE)
1916 {
1917 /*Mixed mode WPA/WPA2*/
1918 memcpy((&wpaRsnIEdata[0] + pConfig->RSNWPAReqIELength), pIe, pIe[1] + 2);
1919 pConfig->RSNWPAReqIELength += pIe[1] + 2;
1920 }
1921 else
1922 {
1923 pConfig->RSNWPAReqIELength = pIe[1] + 2;
1924 memcpy(&wpaRsnIEdata[0], pIe, pConfig->RSNWPAReqIELength);
1925 pConfig->pRSNWPAReqIE = &wpaRsnIEdata[0];
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301926 status = hdd_softap_unpackIE(
Jeff Johnson295189b2012-06-20 16:38:30 -07001927 vos_get_context( VOS_MODULE_ID_SME, pVosContext),
1928 &RSNEncryptType,
1929 &mcRSNEncryptType,
1930 &RSNAuthType,
1931 pConfig->pRSNWPAReqIE[1]+2,
1932 pConfig->pRSNWPAReqIE );
1933
1934 if( VOS_STATUS_SUCCESS == status )
1935 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301936 /* Now copy over all the security attributes you have
1937 * parsed out
Jeff Johnson295189b2012-06-20 16:38:30 -07001938 * */
1939 pConfig->RSNEncryptType = RSNEncryptType; // Use the cipher type in the RSN IE
1940 pConfig->mcRSNEncryptType = mcRSNEncryptType;
1941 (WLAN_HDD_GET_AP_CTX_PTR(pHostapdAdapter))->ucEncryptType
1942 = RSNEncryptType;
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +05301943 hddLog( LOG1, FL("CSR AuthType = %d, "
Jeff Johnson295189b2012-06-20 16:38:30 -07001944 "EncryptionType = %d mcEncryptionType = %d\n"),
1945 RSNAuthType, RSNEncryptType, mcRSNEncryptType);
1946 }
1947 }
1948 }
1949
Jeff Johnson4416a782013-03-25 14:17:50 -07001950 if (pConfig->RSNWPAReqIELength > sizeof wpaRsnIEdata) {
1951 hddLog( VOS_TRACE_LEVEL_ERROR, "**RSNWPAReqIELength is too large***");
1952 return -EINVAL;
1953 }
1954
Jeff Johnson295189b2012-06-20 16:38:30 -07001955 pConfig->SSIDinfo.ssidHidden = VOS_FALSE;
1956
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001957#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07001958 if (params->ssid != NULL)
1959 {
1960 memcpy(pConfig->SSIDinfo.ssid.ssId, params->ssid, params->ssid_len);
1961 pConfig->SSIDinfo.ssid.length = params->ssid_len;
1962 if (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE)
1963 pConfig->SSIDinfo.ssidHidden = VOS_TRUE;
1964 }
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001965#else
1966 if (ssid != NULL)
1967 {
1968 memcpy(pConfig->SSIDinfo.ssid.ssId, ssid, ssid_len);
1969 pConfig->SSIDinfo.ssid.length = ssid_len;
1970 if (hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE)
1971 pConfig->SSIDinfo.ssidHidden = VOS_TRUE;
1972 }
1973#endif
1974
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301975 vos_mem_copy(pConfig->self_macaddr.bytes,
Jeff Johnson295189b2012-06-20 16:38:30 -07001976 pHostapdAdapter->macAddressCurrent.bytes, sizeof(v_MACADDR_t));
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301977
Jeff Johnson295189b2012-06-20 16:38:30 -07001978 /* default value */
1979 pConfig->SapMacaddr_acl = eSAP_ACCEPT_UNLESS_DENIED;
1980 pConfig->num_accept_mac = 0;
1981 pConfig->num_deny_mac = 0;
1982
1983 pIe = wlan_hdd_get_vendor_oui_ie_ptr(BLACKLIST_OUI_TYPE, WPA_OUI_TYPE_SIZE,
1984 pBeacon->tail, pBeacon->tail_len);
1985
1986 /* pIe for black list is following form:
1987 type : 1 byte
1988 length : 1 byte
1989 OUI : 4 bytes
1990 acl type : 1 byte
1991 no of mac addr in black list: 1 byte
1992 list of mac_acl_entries: variable, 6 bytes per mac address + sizeof(int) for vlan id
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301993 */
1994 if ((pIe != NULL) && (pIe[1] != 0))
Jeff Johnson295189b2012-06-20 16:38:30 -07001995 {
1996 pConfig->SapMacaddr_acl = pIe[6];
1997 pConfig->num_deny_mac = pIe[7];
1998 hddLog(VOS_TRACE_LEVEL_INFO,"acl type = %d no deny mac = %d\n",
1999 pIe[6], pIe[7]);
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05302000 if (pConfig->num_deny_mac > MAX_ACL_MAC_ADDRESS)
2001 pConfig->num_deny_mac = MAX_ACL_MAC_ADDRESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07002002 acl_entry = (struct qc_mac_acl_entry *)(pIe + 8);
2003 for (i = 0; i < pConfig->num_deny_mac; i++)
2004 {
2005 vos_mem_copy(&pConfig->deny_mac[i], acl_entry->addr, sizeof(qcmacaddr));
2006 acl_entry++;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302007 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002008 }
2009 pIe = wlan_hdd_get_vendor_oui_ie_ptr(WHITELIST_OUI_TYPE, WPA_OUI_TYPE_SIZE,
2010 pBeacon->tail, pBeacon->tail_len);
2011
2012 /* pIe for white list is following form:
2013 type : 1 byte
2014 length : 1 byte
2015 OUI : 4 bytes
2016 acl type : 1 byte
2017 no of mac addr in white list: 1 byte
2018 list of mac_acl_entries: variable, 6 bytes per mac address + sizeof(int) for vlan id
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302019 */
2020 if ((pIe != NULL) && (pIe[1] != 0))
Jeff Johnson295189b2012-06-20 16:38:30 -07002021 {
2022 pConfig->SapMacaddr_acl = pIe[6];
2023 pConfig->num_accept_mac = pIe[7];
2024 hddLog(VOS_TRACE_LEVEL_INFO,"acl type = %d no accept mac = %d\n",
2025 pIe[6], pIe[7]);
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05302026 if (pConfig->num_accept_mac > MAX_ACL_MAC_ADDRESS)
2027 pConfig->num_accept_mac = MAX_ACL_MAC_ADDRESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07002028 acl_entry = (struct qc_mac_acl_entry *)(pIe + 8);
2029 for (i = 0; i < pConfig->num_accept_mac; i++)
2030 {
2031 vos_mem_copy(&pConfig->accept_mac[i], acl_entry->addr, sizeof(qcmacaddr));
2032 acl_entry++;
2033 }
2034 }
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05302035
Jeff Johnson295189b2012-06-20 16:38:30 -07002036 wlan_hdd_set_sapHwmode(pHostapdAdapter);
2037
Jeff Johnsone7245742012-09-05 17:12:55 -07002038#ifdef WLAN_FEATURE_11AC
Ravi Kumar Vaishnavbbaebbe2013-01-15 17:09:48 -08002039 /* Overwrite the hostapd setting for HW mode only for 11ac.
2040 * This is valid only if mode is set to 11n in hostapd and either AUTO or 11ac in .ini .
2041 * Otherwise, leave whatever is set in hostapd (a OR b OR g OR n mode) */
2042 if( ((pConfig->SapHw_mode == eSAP_DOT11_MODE_11n) ||
2043 (pConfig->SapHw_mode == eSAP_DOT11_MODE_11n_ONLY)) &&
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302044 (((WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->dot11Mode == eHDD_DOT11_MODE_AUTO) ||
Ravi Kumar Vaishnavbbaebbe2013-01-15 17:09:48 -08002045 ((WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->dot11Mode == eHDD_DOT11_MODE_11ac) ||
2046 ((WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY)) )
Jeff Johnsone7245742012-09-05 17:12:55 -07002047 {
2048 pConfig->SapHw_mode = eSAP_DOT11_MODE_11ac;
Ravi Joshi83bfaa12013-05-28 22:12:08 -07002049
2050 /* Disable VHT support in 2.4 GHz band */
2051 if (pConfig->channel <= 14 &&
2052 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->enableVhtFor24GHzBand == FALSE)
2053 {
2054 pConfig->SapHw_mode = eSAP_DOT11_MODE_11n;
2055 }
Jeff Johnsone7245742012-09-05 17:12:55 -07002056 }
2057#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302058
Ravi Joshiaeb7d9e2013-05-02 12:28:14 -07002059 if ( AUTO_CHANNEL_SELECT != pConfig->channel )
2060 {
2061 sme_SelectCBMode(hHal,
2062 sapConvertSapPhyModeToCsrPhyMode(pConfig->SapHw_mode),
2063 pConfig->channel);
2064 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002065 // ht_capab is not what the name conveys,this is used for protection bitmap
2066 pConfig->ht_capab =
2067 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apProtection;
2068
2069 if ( 0 != wlan_hdd_cfg80211_update_apies(pHostapdAdapter, params) )
2070 {
2071 hddLog(LOGE, FL("SAP Not able to set AP IEs"));
2072 return -EINVAL;
2073 }
2074
2075 //Uapsd Enabled Bit
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302076 pConfig->UapsdEnable =
Jeff Johnson295189b2012-06-20 16:38:30 -07002077 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apUapsdEnabled;
2078 //Enable OBSS protection
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302079 pConfig->obssProtEnabled =
2080 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apOBSSProtEnabled;
Jeff Johnson295189b2012-06-20 16:38:30 -07002081
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302082 hddLog(LOGW, FL("SOftAP macaddress : "MAC_ADDRESS_STR"\n"),
Jeff Johnson295189b2012-06-20 16:38:30 -07002083 MAC_ADDR_ARRAY(pHostapdAdapter->macAddressCurrent.bytes));
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302084 hddLog(LOGW,FL("ssid =%s\n"), pConfig->SSIDinfo.ssid.ssId);
Jeff Johnson295189b2012-06-20 16:38:30 -07002085 hddLog(LOGW,FL("beaconint=%d, channel=%d\n"), (int)pConfig->beacon_int,
2086 (int)pConfig->channel);
2087 hddLog(LOGW,FL("hw_mode=%x\n"), pConfig->SapHw_mode);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302088 hddLog(LOGW,FL("privacy=%d, authType=%d\n"), pConfig->privacy,
2089 pConfig->authType);
Jeff Johnson295189b2012-06-20 16:38:30 -07002090 hddLog(LOGW,FL("RSN/WPALen=%d, \n"),(int)pConfig->RSNWPAReqIELength);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302091 hddLog(LOGW,FL("Uapsd = %d\n"),pConfig->UapsdEnable);
Jeff Johnson295189b2012-06-20 16:38:30 -07002092 hddLog(LOGW,FL("ProtEnabled = %d, OBSSProtEnabled = %d\n"),
2093 pConfig->protEnabled, pConfig->obssProtEnabled);
2094
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302095 if(test_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags))
Jeff Johnson295189b2012-06-20 16:38:30 -07002096 {
2097 //Bss already started. just return.
2098 //TODO Probably it should update some beacon params.
2099 hddLog( LOGE, "Bss Already started...Ignore the request");
2100 EXIT();
2101 return 0;
2102 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302103
Jeff Johnson295189b2012-06-20 16:38:30 -07002104 pConfig->persona = pHostapdAdapter->device_mode;
2105
2106 pSapEventCallback = hdd_hostapd_SAPEventCB;
2107 if(WLANSAP_StartBss(pVosContext, pSapEventCallback, pConfig,
2108 (v_PVOID_t)pHostapdAdapter->dev) != VOS_STATUS_SUCCESS)
2109 {
2110 hddLog(LOGE,FL("SAP Start Bss fail\n"));
2111 return -EINVAL;
2112 }
2113
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302114 hddLog(LOG1,
Jeff Johnson295189b2012-06-20 16:38:30 -07002115 FL("Waiting for Scan to complete(auto mode) and BSS to start"));
2116
2117 status = vos_wait_single_event(&pHostapdState->vosEvent, 10000);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302118
Jeff Johnson295189b2012-06-20 16:38:30 -07002119 if (!VOS_IS_STATUS_SUCCESS(status))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302120 {
2121 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07002122 ("ERROR: HDD vos wait for single_event failed!!\n"));
Tushnim Bhattacharyyaad37df12013-10-02 12:01:33 -07002123 smeGetCommandQStatus(hHal);
Jeff Johnson295189b2012-06-20 16:38:30 -07002124 VOS_ASSERT(0);
2125 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302126
Jeff Johnson295189b2012-06-20 16:38:30 -07002127 //Succesfully started Bss update the state bit.
2128 set_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags);
2129
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07002130#ifdef WLAN_FEATURE_P2P_DEBUG
2131 if (pHostapdAdapter->device_mode == WLAN_HDD_P2P_GO)
2132 {
2133 if(globalP2PConnectionStatus == P2P_GO_NEG_COMPLETED)
2134 {
2135 globalP2PConnectionStatus = P2P_GO_COMPLETED_STATE;
2136 hddLog(LOGE,"[P2P State] From Go nego completed to "
Jeff Johnson1250df42012-12-10 14:31:52 -08002137 "Non-autonomous Group started");
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07002138 }
2139 else if(globalP2PConnectionStatus == P2P_NOT_ACTIVE)
2140 {
2141 globalP2PConnectionStatus = P2P_GO_COMPLETED_STATE;
2142 hddLog(LOGE,"[P2P State] From Inactive to "
Jeff Johnson1250df42012-12-10 14:31:52 -08002143 "Autonomous Group started");
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07002144 }
2145 }
2146#endif
2147
Jeff Johnson295189b2012-06-20 16:38:30 -07002148 pHostapdState->bCommit = TRUE;
2149 EXIT();
2150
2151 return 0;
2152}
2153
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002154#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302155static int wlan_hdd_cfg80211_add_beacon(struct wiphy *wiphy,
2156 struct net_device *dev,
Jeff Johnson295189b2012-06-20 16:38:30 -07002157 struct beacon_parameters *params)
2158{
2159 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302160 hdd_context_t *pHddCtx;
2161 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07002162
2163 ENTER();
2164
2165 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "device mode=%d\n",pAdapter->device_mode);
2166
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302167 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2168 status = wlan_hdd_validate_context(pHddCtx);
2169
2170 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002171 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302172 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2173 "%s: HDD context is not valid", __func__);
2174 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002175 }
2176
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302177 if ( (pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002178 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -07002179 )
2180 {
2181 beacon_data_t *old,*new;
2182
2183 old = pAdapter->sessionCtx.ap.beacon;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302184
Jeff Johnson295189b2012-06-20 16:38:30 -07002185 if (old)
2186 return -EALREADY;
2187
2188 status = wlan_hdd_cfg80211_alloc_new_beacon(pAdapter,&new,params);
2189
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302190 if(status != VOS_STATUS_SUCCESS)
Jeff Johnson295189b2012-06-20 16:38:30 -07002191 {
2192 hddLog(VOS_TRACE_LEVEL_FATAL,
2193 "%s:Error!!! Allocating the new beacon\n",__func__);
2194 return -EINVAL;
2195 }
2196
2197 pAdapter->sessionCtx.ap.beacon = new;
2198
2199 status = wlan_hdd_cfg80211_start_bss(pAdapter, params);
2200 }
2201
2202 EXIT();
2203 return status;
2204}
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302205
2206static int wlan_hdd_cfg80211_set_beacon(struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07002207 struct net_device *dev,
2208 struct beacon_parameters *params)
2209{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302210 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302211 hdd_context_t *pHddCtx;
2212 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07002213
2214 ENTER();
2215
2216 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
2217 __func__,pAdapter->device_mode);
2218
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302219 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2220 status = wlan_hdd_validate_context(pHddCtx);
2221
2222 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002223 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302224 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2225 "%s: HDD context is not valid", __func__);
2226 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002227 }
2228
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302229 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002230 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302231 )
Jeff Johnson295189b2012-06-20 16:38:30 -07002232 {
2233 beacon_data_t *old,*new;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302234
Jeff Johnson295189b2012-06-20 16:38:30 -07002235 old = pAdapter->sessionCtx.ap.beacon;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302236
Jeff Johnson295189b2012-06-20 16:38:30 -07002237 if (!old)
2238 return -ENOENT;
2239
2240 status = wlan_hdd_cfg80211_alloc_new_beacon(pAdapter,&new,params);
2241
2242 if(status != VOS_STATUS_SUCCESS) {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302243 hddLog(VOS_TRACE_LEVEL_FATAL,
Jeff Johnson295189b2012-06-20 16:38:30 -07002244 "%s: Error!!! Allocating the new beacon\n",__func__);
2245 return -EINVAL;
2246 }
2247
2248 pAdapter->sessionCtx.ap.beacon = new;
2249
2250 status = wlan_hdd_cfg80211_start_bss(pAdapter, params);
2251 }
2252
2253 EXIT();
2254 return status;
2255}
2256
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002257#endif //(LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
2258
2259#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07002260static int wlan_hdd_cfg80211_del_beacon(struct wiphy *wiphy,
2261 struct net_device *dev)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002262#else
2263static int wlan_hdd_cfg80211_stop_ap (struct wiphy *wiphy,
2264 struct net_device *dev)
2265#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002266{
2267 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsone7245742012-09-05 17:12:55 -07002268 hdd_context_t *pHddCtx = NULL;
2269 hdd_scaninfo_t *pScanInfo = NULL;
2270 hdd_adapter_t *staAdapter = NULL;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302271 VOS_STATUS status;
Jeff Johnson295189b2012-06-20 16:38:30 -07002272
2273 ENTER();
2274
2275 if (NULL == pAdapter)
2276 {
2277 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002278 "%s: HDD adapter context is Null", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002279 return -ENODEV;
2280 }
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002281
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302282 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2283 status = wlan_hdd_validate_context(pHddCtx);
2284
2285 if (0 != status)
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002286 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302287 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2288 "%s: HDD context is not valid", __func__);
2289 return status;
Jeff Johnson4416a782013-03-25 14:17:50 -07002290 }
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002291
2292 staAdapter = hdd_get_adapter(pAdapter->pHddCtx, WLAN_HDD_INFRA_STATION);
2293 if (NULL == staAdapter)
2294 {
2295 staAdapter = hdd_get_adapter(pAdapter->pHddCtx, WLAN_HDD_P2P_CLIENT);
2296 if (NULL == staAdapter)
2297 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302298 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002299 "%s: HDD adapter context is Null", __func__);
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002300 return -ENODEV;
2301 }
2302 }
2303
2304 pScanInfo = &pHddCtx->scan_info;
2305
Jeff Johnson295189b2012-06-20 16:38:30 -07002306 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
2307 __func__,pAdapter->device_mode);
2308
Jeff Johnsone7245742012-09-05 17:12:55 -07002309 if ((pScanInfo != NULL) && pScanInfo->mScanPending)
2310 {
Madan Mohan Koyyalamudif4e81002012-11-13 10:46:38 -08002311 INIT_COMPLETION(pScanInfo->abortscan_event_var);
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05302312 hdd_abort_mac_scan(staAdapter->pHddCtx, pAdapter->sessionId);
Jeff Johnsone7245742012-09-05 17:12:55 -07002313 status = wait_for_completion_interruptible_timeout(
Madan Mohan Koyyalamudif4e81002012-11-13 10:46:38 -08002314 &pScanInfo->abortscan_event_var,
Jeff Johnsone7245742012-09-05 17:12:55 -07002315 msecs_to_jiffies(WLAN_WAIT_TIME_ABORTSCAN));
2316 if (!status)
2317 {
2318 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Jeff Johnson902c9832012-12-10 14:28:09 -08002319 "%s: Timeout occurred while waiting for abortscan" ,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002320 __func__);
Jeff Johnsone7245742012-09-05 17:12:55 -07002321 VOS_ASSERT(pScanInfo->mScanPending);
2322 return 0;
2323 }
2324 }
2325
Jeff Johnson295189b2012-06-20 16:38:30 -07002326 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002327 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -07002328 )
2329 {
2330 beacon_data_t *old;
2331
2332 old = pAdapter->sessionCtx.ap.beacon;
2333
2334 if (!old)
2335 return -ENOENT;
2336
Jeff Johnson295189b2012-06-20 16:38:30 -07002337 hdd_cleanup_actionframe(pHddCtx, pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07002338
2339 mutex_lock(&pHddCtx->sap_lock);
2340 if(test_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags))
2341 {
Jeff Johnson4416a782013-03-25 14:17:50 -07002342 if ( VOS_STATUS_SUCCESS == (status = WLANSAP_StopBss(pHddCtx->pvosContext) ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07002343 {
2344 hdd_hostapd_state_t *pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
2345
2346 status = vos_wait_single_event(&pHostapdState->vosEvent, 10000);
2347
2348 if (!VOS_IS_STATUS_SUCCESS(status))
2349 {
2350 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2351 ("ERROR: HDD vos wait for single_event failed!!\n"));
2352 VOS_ASSERT(0);
2353 }
2354 }
2355 clear_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags);
2356 }
2357 mutex_unlock(&pHddCtx->sap_lock);
2358
2359 if(status != VOS_STATUS_SUCCESS)
2360 {
2361 hddLog(VOS_TRACE_LEVEL_FATAL,
2362 "%s:Error!!! Stopping the BSS\n",__func__);
2363 return -EINVAL;
2364 }
2365
Jeff Johnson4416a782013-03-25 14:17:50 -07002366 if (ccmCfgSetInt(pHddCtx->hHal,
Jeff Johnson295189b2012-06-20 16:38:30 -07002367 WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG, 0,NULL, eANI_BOOLEAN_FALSE)
2368 ==eHAL_STATUS_FAILURE)
2369 {
2370 hddLog(LOGE,
2371 "Could not pass on WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG to CCM\n");
2372 }
2373
Jeff Johnson4416a782013-03-25 14:17:50 -07002374 if ( eHAL_STATUS_FAILURE == ccmCfgSetInt(pHddCtx->hHal,
Jeff Johnson295189b2012-06-20 16:38:30 -07002375 WNI_CFG_ASSOC_RSP_ADDNIE_FLAG, 0, NULL,
2376 eANI_BOOLEAN_FALSE) )
2377 {
2378 hddLog(LOGE,
2379 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_FLAG to CCM\n");
2380 }
2381
2382 // Reset WNI_CFG_PROBE_RSP Flags
2383 wlan_hdd_reset_prob_rspies(pAdapter);
2384
2385 pAdapter->sessionCtx.ap.beacon = NULL;
2386 kfree(old);
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07002387#ifdef WLAN_FEATURE_P2P_DEBUG
2388 if((pAdapter->device_mode == WLAN_HDD_P2P_GO) &&
2389 (globalP2PConnectionStatus == P2P_GO_COMPLETED_STATE))
2390 {
2391 hddLog(LOGE,"[P2P State] From GO completed to Inactive state "
2392 "GO got removed");
2393 globalP2PConnectionStatus = P2P_NOT_ACTIVE;
2394 }
2395#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002396 }
2397 EXIT();
2398 return status;
2399}
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002400
2401#if (LINUX_VERSION_CODE > KERNEL_VERSION(3,3,0))
2402
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302403static int wlan_hdd_cfg80211_start_ap(struct wiphy *wiphy,
2404 struct net_device *dev,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002405 struct cfg80211_ap_settings *params)
2406{
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302407 hdd_adapter_t *pAdapter;
2408 hdd_context_t *pHddCtx;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302409 int status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002410
2411 ENTER();
2412
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302413 if (NULL == dev)
Madan Mohan Koyyalamudib2c36892012-10-18 20:52:38 -07002414 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302415 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302416 "%s: Device is Null", __func__);
2417 return -ENODEV;
2418 }
2419
2420 pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
2421 if (NULL == pAdapter)
2422 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302423 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302424 "%s: HDD adapter is Null", __func__);
2425 return -ENODEV;
2426 }
2427
2428 if (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic)
2429 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302430 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302431 "%s: HDD adapter magic is invalid", __func__);
2432 return -ENODEV;
2433 }
2434
2435 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302436 status = wlan_hdd_validate_context(pHddCtx);
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302437
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302438 if (0 != status)
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302439 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302440 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2441 "%s: HDD context is not valid", __func__);
2442 return status;
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302443 }
2444
2445 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: device mode = %d",
2446 __func__, pAdapter->device_mode);
2447
2448 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002449 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002450 )
2451 {
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302452 beacon_data_t *old, *new;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002453
2454 old = pAdapter->sessionCtx.ap.beacon;
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302455
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002456 if (old)
2457 return -EALREADY;
2458
2459 status = wlan_hdd_cfg80211_alloc_new_beacon(pAdapter, &new, &params->beacon, params->dtim_period);
2460
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302461 if (status != 0)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002462 {
2463 hddLog(VOS_TRACE_LEVEL_FATAL,
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302464 "%s:Error!!! Allocating the new beacon", __func__);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002465 return -EINVAL;
2466 }
2467 pAdapter->sessionCtx.ap.beacon = new;
Viral Modi3a32cc52013-02-08 11:14:52 -08002468#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
Yue Maf49ba872013-08-19 12:04:25 -07002469 wlan_hdd_cfg80211_set_channel(wiphy, dev,
2470#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0))
2471 params->channel, params->channel_type);
2472#else
2473 params->chandef.chan, cfg80211_get_chandef_type(&(params->chandef)));
2474#endif
Viral Modi3a32cc52013-02-08 11:14:52 -08002475#endif
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002476 status = wlan_hdd_cfg80211_start_bss(pAdapter, &params->beacon, params->ssid,
2477 params->ssid_len, params->hidden_ssid);
2478 }
2479
2480 EXIT();
2481 return status;
2482}
2483
2484
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302485static int wlan_hdd_cfg80211_change_beacon(struct wiphy *wiphy,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002486 struct net_device *dev,
2487 struct cfg80211_beacon_data *params)
2488{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302489 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302490 hdd_context_t *pHddCtx;
2491 int status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002492
2493 ENTER();
2494
2495 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
2496 __func__, pAdapter->device_mode);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302497
2498 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2499 status = wlan_hdd_validate_context(pHddCtx);
2500
2501 if (0 != status)
Madan Mohan Koyyalamudib2c36892012-10-18 20:52:38 -07002502 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302503 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2504 "%s: HDD context is not valid", __func__);
2505 return status;
Madan Mohan Koyyalamudib2c36892012-10-18 20:52:38 -07002506 }
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002507
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302508 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002509 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302510 )
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002511 {
2512 beacon_data_t *old,*new;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302513
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002514 old = pAdapter->sessionCtx.ap.beacon;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302515
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002516 if (!old)
2517 return -ENOENT;
2518
2519 status = wlan_hdd_cfg80211_alloc_new_beacon(pAdapter, &new, params, 0);
2520
2521 if(status != VOS_STATUS_SUCCESS) {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302522 hddLog(VOS_TRACE_LEVEL_FATAL,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002523 "%s: Error!!! Allocating the new beacon\n",__func__);
2524 return -EINVAL;
2525 }
2526
2527 pAdapter->sessionCtx.ap.beacon = new;
2528
2529 status = wlan_hdd_cfg80211_start_bss(pAdapter, params, NULL, 0, 0);
2530 }
2531
2532 EXIT();
2533 return status;
2534}
2535
2536#endif //(LINUX_VERSION_CODE > KERNEL_VERSION(3,3,0))
2537
Jeff Johnson295189b2012-06-20 16:38:30 -07002538
2539static int wlan_hdd_cfg80211_change_bss (struct wiphy *wiphy,
2540 struct net_device *dev,
2541 struct bss_parameters *params)
2542{
2543 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
2544
2545 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302546
Jeff Johnson295189b2012-06-20 16:38:30 -07002547 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
2548 __func__,pAdapter->device_mode);
2549
2550 if((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002551 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302552 )
Jeff Johnson295189b2012-06-20 16:38:30 -07002553 {
2554 /* ap_isolate == -1 means that in change bss, upper layer doesn't
2555 * want to update this parameter */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302556 if (-1 != params->ap_isolate)
Jeff Johnson295189b2012-06-20 16:38:30 -07002557 {
2558 pAdapter->sessionCtx.ap.apDisableIntraBssFwd = !!params->ap_isolate;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302559 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002560 }
2561
2562 EXIT();
2563 return 0;
2564}
2565
Kiet Lam10841362013-11-01 11:36:50 +05302566/* FUNCTION: wlan_hdd_change_country_code_cd
2567* to wait for contry code completion
2568*/
2569void* wlan_hdd_change_country_code_cb(void *pAdapter)
2570{
2571 hdd_adapter_t *call_back_pAdapter = pAdapter;
2572 complete(&call_back_pAdapter->change_country_code);
2573 return NULL;
2574}
2575
Jeff Johnson295189b2012-06-20 16:38:30 -07002576/*
2577 * FUNCTION: wlan_hdd_cfg80211_change_iface
2578 * This function is used to set the interface type (INFRASTRUCTURE/ADHOC)
2579 */
2580int wlan_hdd_cfg80211_change_iface( struct wiphy *wiphy,
2581 struct net_device *ndev,
2582 enum nl80211_iftype type,
2583 u32 *flags,
2584 struct vif_params *params
2585 )
2586{
2587 struct wireless_dev *wdev;
2588 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
2589 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
Mohit Khanna0f232092012-09-11 14:46:08 -07002590 hdd_adapter_t *pP2pAdapter = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07002591 tCsrRoamProfile *pRoamProfile = NULL;
2592 eCsrRoamBssType LastBSSType;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302593 hdd_config_t *pConfig = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07002594 eMib_dot11DesiredBssType connectedBssType;
2595 VOS_STATUS status;
2596
2597 ENTER();
2598
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302599 status = wlan_hdd_validate_context(pHddCtx);
2600
2601 if (0 != status)
Jeff Johnson295189b2012-06-20 16:38:30 -07002602 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302603 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2604 "%s: HDD context is not valid", __func__);
2605 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07002606 }
2607
2608 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
2609 __func__, pAdapter->device_mode);
2610
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302611 pConfig = pHddCtx->cfg_ini;
Jeff Johnson295189b2012-06-20 16:38:30 -07002612 wdev = ndev->ieee80211_ptr;
2613
2614#ifdef WLAN_BTAMP_FEATURE
2615 if((NL80211_IFTYPE_P2P_CLIENT == type)||
2616 (NL80211_IFTYPE_ADHOC == type)||
2617 (NL80211_IFTYPE_AP == type)||
2618 (NL80211_IFTYPE_P2P_GO == type))
2619 {
2620 pHddCtx->isAmpAllowed = VOS_FALSE;
2621 // stop AMP traffic
2622 status = WLANBAP_StopAmp();
2623 if(VOS_STATUS_SUCCESS != status )
2624 {
2625 pHddCtx->isAmpAllowed = VOS_TRUE;
2626 hddLog(VOS_TRACE_LEVEL_FATAL,
2627 "%s: Failed to stop AMP", __func__);
2628 return -EINVAL;
2629 }
2630 }
2631#endif //WLAN_BTAMP_FEATURE
2632 /* Reset the current device mode bit mask*/
2633 wlan_hdd_clear_concurrency_mode(pHddCtx, pAdapter->device_mode);
2634
2635 if( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Jeff Johnson295189b2012-06-20 16:38:30 -07002636 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Jeff Johnsone7245742012-09-05 17:12:55 -07002637 || (pAdapter->device_mode == WLAN_HDD_P2P_DEVICE)
Jeff Johnson295189b2012-06-20 16:38:30 -07002638 )
2639 {
2640 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
2641 pRoamProfile = &pWextState->roamProfile;
2642 LastBSSType = pRoamProfile->BSSType;
2643
2644 switch (type)
2645 {
2646 case NL80211_IFTYPE_STATION:
Jeff Johnson295189b2012-06-20 16:38:30 -07002647 case NL80211_IFTYPE_P2P_CLIENT:
Jeff Johnson295189b2012-06-20 16:38:30 -07002648 hddLog(VOS_TRACE_LEVEL_INFO,
2649 "%s: setting interface Type to INFRASTRUCTURE", __func__);
2650 pRoamProfile->BSSType = eCSR_BSS_TYPE_INFRASTRUCTURE;
Jeff Johnsone7245742012-09-05 17:12:55 -07002651#ifdef WLAN_FEATURE_11AC
2652 if(pConfig->dot11Mode == eHDD_DOT11_MODE_AUTO)
2653 {
2654 pConfig->dot11Mode = eHDD_DOT11_MODE_11ac;
2655 }
2656#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302657 pRoamProfile->phyMode =
Jeff Johnsone7245742012-09-05 17:12:55 -07002658 hdd_cfg_xlate_to_csr_phy_mode(pConfig->dot11Mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07002659 wdev->iftype = type;
Gopichand Nakkalaf527dc62012-12-31 16:35:10 -08002660 //Check for sub-string p2p to confirm its a p2p interface
2661 if (NULL != strstr(ndev->name,"p2p"))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302662 {
Gopichand Nakkala864d3552012-12-31 16:08:51 -08002663 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
2664 WLAN_HDD_P2P_DEVICE : WLAN_HDD_P2P_CLIENT;
2665 }
2666 else
2667 {
2668 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
Jeff Johnson295189b2012-06-20 16:38:30 -07002669 WLAN_HDD_INFRA_STATION: WLAN_HDD_P2P_CLIENT;
Gopichand Nakkala864d3552012-12-31 16:08:51 -08002670 }
Madan Mohan Koyyalamudi81746922013-07-17 14:38:51 +05302671#ifdef FEATURE_WLAN_TDLS
2672 /* The open adapter for the p2p shall skip initializations in
2673 * tdls_init if the device mode is WLAN_HDD_P2P_DEVICE, for
2674 * TDLS is supported only on WLAN_HDD_P2P_CLIENT. Hence invoke
2675 * tdls_init when the change_iface sets the device mode to
2676 * WLAN_HDD_P2P_CLIENT.
2677 */
2678
2679 if ( pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
2680 {
2681 if (0 != wlan_hdd_tdls_init (pAdapter))
2682 {
2683 return -EINVAL;
2684 }
2685 }
2686#endif
2687
Jeff Johnson295189b2012-06-20 16:38:30 -07002688 break;
2689 case NL80211_IFTYPE_ADHOC:
2690 hddLog(VOS_TRACE_LEVEL_INFO,
2691 "%s: setting interface Type to ADHOC", __func__);
2692 pRoamProfile->BSSType = eCSR_BSS_TYPE_START_IBSS;
2693 pRoamProfile->phyMode =
2694 hdd_cfg_xlate_to_csr_phy_mode(pConfig->dot11Mode);
Shailender Karmuchia734f332013-04-19 14:02:48 -07002695 pAdapter->device_mode = WLAN_HDD_IBSS;
Jeff Johnson295189b2012-06-20 16:38:30 -07002696 wdev->iftype = type;
2697 break;
2698
2699 case NL80211_IFTYPE_AP:
Jeff Johnson295189b2012-06-20 16:38:30 -07002700 case NL80211_IFTYPE_P2P_GO:
Jeff Johnson295189b2012-06-20 16:38:30 -07002701 {
2702 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
2703 "%s: setting interface Type to %s", __func__,
2704 (type == NL80211_IFTYPE_AP) ? "SoftAP" : "P2pGo");
2705
Gopichand Nakkalaf527dc62012-12-31 16:35:10 -08002706 //Cancel any remain on channel for GO mode
2707 if (NL80211_IFTYPE_P2P_GO == type)
2708 {
2709 wlan_hdd_cancel_existing_remain_on_channel(pAdapter);
2710 }
Mohit Khanna0f232092012-09-11 14:46:08 -07002711 if (NL80211_IFTYPE_AP == type)
2712 {
2713 /* As Loading WLAN Driver one interface being created for p2p device
2714 * address. This will take one HW STA and the max number of clients
2715 * that can connect to softAP will be reduced by one. so while changing
2716 * the interface type to NL80211_IFTYPE_AP (SoftAP) remove p2p0
2717 * interface as it is not required in SoftAP mode.
2718 */
2719
2720 // Get P2P Adapter
2721 pP2pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_P2P_DEVICE);
2722
2723 if (pP2pAdapter)
2724 {
2725 hdd_stop_adapter(pHddCtx, pP2pAdapter);
2726 hdd_deinit_adapter(pHddCtx, pP2pAdapter);
2727 hdd_close_adapter(pHddCtx, pP2pAdapter, VOS_TRUE);
2728 }
2729 }
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302730#ifdef FEATURE_WLAN_TDLS
Mohit Khanna0f232092012-09-11 14:46:08 -07002731
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302732 /* A Mutex Lock is introduced while changing the mode to
2733 * protect the concurrent access for the Adapters by TDLS
2734 * module.
2735 */
2736 if (mutex_lock_interruptible(&pHddCtx->tdls_lock))
2737 {
2738 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2739 "%s: unable to lock list", __func__);
2740 return -EINVAL;
2741 }
2742#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002743 //De-init the adapter.
2744 hdd_stop_adapter( pHddCtx, pAdapter );
2745 hdd_deinit_adapter( pHddCtx, pAdapter );
2746 memset(&pAdapter->sessionCtx, 0, sizeof(pAdapter->sessionCtx));
Jeff Johnson295189b2012-06-20 16:38:30 -07002747 pAdapter->device_mode = (type == NL80211_IFTYPE_AP) ?
2748 WLAN_HDD_SOFTAP : WLAN_HDD_P2P_GO;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302749#ifdef FEATURE_WLAN_TDLS
2750 mutex_unlock(&pHddCtx->tdls_lock);
2751#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -07002752
2753 //Disable BMPS and IMPS if enabled
2754 //before starting Go
2755 if(WLAN_HDD_P2P_GO == pAdapter->device_mode)
2756 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302757 if(VOS_STATUS_E_FAILURE ==
Jeff Johnson32d95a32012-09-10 13:15:23 -07002758 hdd_disable_bmps_imps(pHddCtx, WLAN_HDD_P2P_GO))
2759 {
2760 //Fail to Exit BMPS
2761 VOS_ASSERT(0);
2762 }
2763 }
2764
Madan Mohan Koyyalamudi3ff2a0b2012-10-15 14:33:46 -07002765 if ((WLAN_HDD_SOFTAP == pAdapter->device_mode) &&
2766 (pConfig->apRandomBssidEnabled))
2767 {
2768 /* To meet Android requirements create a randomized
2769 MAC address of the form 02:1A:11:Fx:xx:xx */
2770 get_random_bytes(&ndev->dev_addr[3], 3);
2771 ndev->dev_addr[0] = 0x02;
2772 ndev->dev_addr[1] = 0x1A;
2773 ndev->dev_addr[2] = 0x11;
2774 ndev->dev_addr[3] |= 0xF0;
2775 memcpy(pAdapter->macAddressCurrent.bytes, ndev->dev_addr,
2776 VOS_MAC_ADDR_SIZE);
2777 pr_info("wlan: Generated HotSpot BSSID "
2778 "%02x:%02x:%02x:%02x:%02x:%02x\n",
2779 ndev->dev_addr[0],
2780 ndev->dev_addr[1],
2781 ndev->dev_addr[2],
2782 ndev->dev_addr[3],
2783 ndev->dev_addr[4],
2784 ndev->dev_addr[5]);
2785 }
2786
Jeff Johnson295189b2012-06-20 16:38:30 -07002787 hdd_set_ap_ops( pAdapter->dev );
2788
Kiet Lam10841362013-11-01 11:36:50 +05302789 /* This is for only SAP mode where users can
2790 * control country through ini.
2791 * P2P GO follows station country code
2792 * acquired during the STA scanning. */
2793 if((NL80211_IFTYPE_AP == type) &&
2794 (memcmp(pConfig->apCntryCode, CFG_AP_COUNTRY_CODE_DEFAULT, 3) != 0))
2795 {
2796 int status = 0;
2797 VOS_TRACE(VOS_MODULE_ID_HDD,VOS_TRACE_LEVEL_INFO,
2798 "%s: setting country code from INI ", __func__);
2799 init_completion(&pAdapter->change_country_code);
2800 status = (int)sme_ChangeCountryCode(pHddCtx->hHal,
2801 (void *)(tSmeChangeCountryCallback)
2802 wlan_hdd_change_country_code_cb,
2803 pConfig->apCntryCode, pAdapter,
2804 pHddCtx->pvosContext,
2805 VOS_FALSE);
2806 if (eHAL_STATUS_SUCCESS == status)
2807 {
2808 /* Wait for completion */
2809 status = wait_for_completion_interruptible_timeout(
2810 &pAdapter->change_country_code,
2811 msecs_to_jiffies(WLAN_WAIT_TIME_COUNTRY));
2812 if (status <= 0)
2813 {
2814 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2815 "%s: SME Timed out while setting country code ",
2816 __func__);
2817 }
2818 }
2819 else
2820 {
2821 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2822 "%s: SME Change Country code failed \n",__func__);
2823 return -EINVAL;
2824 }
2825 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002826 status = hdd_init_ap_mode(pAdapter);
2827 if(status != VOS_STATUS_SUCCESS)
2828 {
2829 hddLog(VOS_TRACE_LEVEL_FATAL,
2830 "%s: Error initializing the ap mode", __func__);
2831 return -EINVAL;
2832 }
2833 hdd_set_conparam(1);
2834
Jeff Johnson295189b2012-06-20 16:38:30 -07002835 /*interface type changed update in wiphy structure*/
2836 if(wdev)
2837 {
2838 wdev->iftype = type;
2839 pHddCtx->change_iface = type;
2840 }
2841 else
2842 {
2843 hddLog(VOS_TRACE_LEVEL_ERROR,
2844 "%s: ERROR !!!! Wireless dev is NULL", __func__);
2845 return -EINVAL;
2846 }
2847 goto done;
2848 }
2849
2850 default:
2851 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported interface Type",
2852 __func__);
2853 return -EOPNOTSUPP;
2854 }
2855 }
2856 else if ( (pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002857 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -07002858 )
2859 {
2860 switch(type)
2861 {
2862 case NL80211_IFTYPE_STATION:
Jeff Johnson295189b2012-06-20 16:38:30 -07002863 case NL80211_IFTYPE_P2P_CLIENT:
Jeff Johnson295189b2012-06-20 16:38:30 -07002864 case NL80211_IFTYPE_ADHOC:
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302865#ifdef FEATURE_WLAN_TDLS
2866
2867 /* A Mutex Lock is introduced while changing the mode to
2868 * protect the concurrent access for the Adapters by TDLS
2869 * module.
2870 */
2871 if (mutex_lock_interruptible(&pHddCtx->tdls_lock))
2872 {
2873 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2874 "%s: unable to lock list", __func__);
2875 return -EINVAL;
2876 }
2877#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -07002878 hdd_stop_adapter( pHddCtx, pAdapter );
2879 hdd_deinit_adapter( pHddCtx, pAdapter );
Jeff Johnson295189b2012-06-20 16:38:30 -07002880 wdev->iftype = type;
Gopichand Nakkalaf527dc62012-12-31 16:35:10 -08002881 //Check for sub-string p2p to confirm its a p2p interface
2882 if (NULL != strstr(ndev->name,"p2p"))
Gopichand Nakkala864d3552012-12-31 16:08:51 -08002883 {
2884 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
2885 WLAN_HDD_P2P_DEVICE : WLAN_HDD_P2P_CLIENT;
2886 }
2887 else
2888 {
2889 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
Jeff Johnson295189b2012-06-20 16:38:30 -07002890 WLAN_HDD_INFRA_STATION: WLAN_HDD_P2P_CLIENT;
Gopichand Nakkala864d3552012-12-31 16:08:51 -08002891 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002892 hdd_set_conparam(0);
2893 pHddCtx->change_iface = type;
Jeff Johnson295189b2012-06-20 16:38:30 -07002894 memset(&pAdapter->sessionCtx, 0, sizeof(pAdapter->sessionCtx));
2895 hdd_set_station_ops( pAdapter->dev );
2896 status = hdd_init_station_mode( pAdapter );
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302897#ifdef FEATURE_WLAN_TDLS
2898 mutex_unlock(&pHddCtx->tdls_lock);
2899#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002900 if( VOS_STATUS_SUCCESS != status )
2901 return -EOPNOTSUPP;
Jeff Johnsone7245742012-09-05 17:12:55 -07002902 /* In case of JB, for P2P-GO, only change interface will be called,
2903 * This is the right place to enable back bmps_imps()
2904 */
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05302905 if (pHddCtx->hdd_wlan_suspended)
2906 {
2907 hdd_set_pwrparams(pHddCtx);
2908 }
Jeff Johnsone7245742012-09-05 17:12:55 -07002909 hdd_enable_bmps_imps(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07002910 goto done;
2911 case NL80211_IFTYPE_AP:
Jeff Johnson295189b2012-06-20 16:38:30 -07002912 case NL80211_IFTYPE_P2P_GO:
Jeff Johnson295189b2012-06-20 16:38:30 -07002913 wdev->iftype = type;
Jeff Johnson295189b2012-06-20 16:38:30 -07002914 pAdapter->device_mode = (type == NL80211_IFTYPE_AP) ?
2915 WLAN_HDD_SOFTAP : WLAN_HDD_P2P_GO;
Jeff Johnson295189b2012-06-20 16:38:30 -07002916 goto done;
2917 default:
2918 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported interface Type",
2919 __func__);
2920 return -EOPNOTSUPP;
2921
2922 }
2923
2924 }
2925 else
2926 {
2927 return -EOPNOTSUPP;
2928 }
2929
2930
2931 if(pRoamProfile)
2932 {
2933 if ( LastBSSType != pRoamProfile->BSSType )
2934 {
2935 /*interface type changed update in wiphy structure*/
2936 wdev->iftype = type;
2937
2938 /*the BSS mode changed, We need to issue disconnect
2939 if connected or in IBSS disconnect state*/
2940 if ( hdd_connGetConnectedBssType(
2941 WLAN_HDD_GET_STATION_CTX_PTR(pAdapter), &connectedBssType ) ||
2942 ( eCSR_BSS_TYPE_START_IBSS == LastBSSType ) )
2943 {
2944 /*need to issue a disconnect to CSR.*/
2945 INIT_COMPLETION(pAdapter->disconnect_comp_var);
2946 if( eHAL_STATUS_SUCCESS ==
2947 sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
2948 pAdapter->sessionId,
2949 eCSR_DISCONNECT_REASON_UNSPECIFIED ) )
2950 {
2951 wait_for_completion_interruptible_timeout(
2952 &pAdapter->disconnect_comp_var,
2953 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
2954 }
2955 }
2956 }
2957 }
2958
2959done:
2960 /*set bitmask based on updated value*/
2961 wlan_hdd_set_concurrency_mode(pHddCtx, pAdapter->device_mode);
Leo Chang6fe1f922013-06-07 19:21:24 -07002962
2963 /* Only STA mode support TM now
2964 * all other mode, TM feature should be disabled */
2965 if ( (pHddCtx->cfg_ini->thermalMitigationEnable) &&
2966 (~VOS_STA & pHddCtx->concurrency_mode) )
2967 {
2968 hddDevTmLevelChangedHandler(pHddCtx->parent_dev, 0);
2969 }
2970
Jeff Johnson295189b2012-06-20 16:38:30 -07002971#ifdef WLAN_BTAMP_FEATURE
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302972 if((NL80211_IFTYPE_STATION == type) && (pHddCtx->concurrency_mode <= 1) &&
Jeff Johnson295189b2012-06-20 16:38:30 -07002973 (pHddCtx->no_of_sessions[WLAN_HDD_INFRA_STATION] <=1))
2974 {
2975 //we are ok to do AMP
2976 pHddCtx->isAmpAllowed = VOS_TRUE;
2977 }
2978#endif //WLAN_BTAMP_FEATURE
2979 EXIT();
2980 return 0;
2981}
2982
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002983#ifdef FEATURE_WLAN_TDLS
2984static int wlan_hdd_tdls_add_station(struct wiphy *wiphy,
2985 struct net_device *dev, u8 *mac, bool update, tCsrStaParams *StaParams)
2986{
2987 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
2988 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
2989 VOS_STATUS status;
Hoonki Lee5305c3a2013-04-29 23:28:59 -07002990 hddTdlsPeer_t *pTdlsPeer;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002991
2992 ENTER();
2993
Gopichand Nakkala838be5d2013-04-10 22:41:51 +05302994 if (NULL == pHddCtx || NULL == pHddCtx->cfg_ini)
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002995 {
2996 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2997 "Invalid arguments");
2998 return -EINVAL;
2999 }
Hoonki Lee27511902013-03-14 18:19:06 -07003000
3001 if ((eTDLS_SUPPORT_NOT_ENABLED == pHddCtx->tdls_mode) ||
3002 (eTDLS_SUPPORT_DISABLED == pHddCtx->tdls_mode))
3003 {
3004 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3005 "%s: TDLS mode is disabled OR not enabled in FW."
3006 MAC_ADDRESS_STR " Request declined.",
3007 __func__, MAC_ADDR_ARRAY(mac));
3008 return -ENOTSUPP;
3009 }
3010
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003011 if (pHddCtx->isLogpInProgress)
3012 {
3013 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3014 "%s:LOGP in Progress. Ignore!!!", __func__);
Gopichand Nakkala05922802013-03-14 12:23:19 -07003015 wlan_hdd_tdls_set_link_status(pAdapter, mac, eTDLS_LINK_IDLE);
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003016 return -EBUSY;
3017 }
3018
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05303019 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, mac, TRUE);
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003020
3021 if ( NULL == pTdlsPeer ) {
3022 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3023 "%s: " MAC_ADDRESS_STR " (update %d) not exist. return invalid",
3024 __func__, MAC_ADDR_ARRAY(mac), update);
3025 return -EINVAL;
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07003026 }
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003027
3028 /* in add station, we accept existing valid staId if there is */
3029 if ((0 == update) &&
3030 ((pTdlsPeer->link_status >= eTDLS_LINK_CONNECTING) ||
3031 (TDLS_STA_INDEX_VALID(pTdlsPeer->staId))))
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003032 {
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003033 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003034 "%s: " MAC_ADDRESS_STR
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003035 " link_status %d. staId %d. add station ignored.",
3036 __func__, MAC_ADDR_ARRAY(mac), pTdlsPeer->link_status, pTdlsPeer->staId);
3037 return 0;
3038 }
3039 /* in change station, we accept only when staId is valid */
3040 if ((1 == update) &&
3041 ((pTdlsPeer->link_status > eTDLS_LINK_CONNECTING) ||
3042 (!TDLS_STA_INDEX_VALID(pTdlsPeer->staId))))
3043 {
3044 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3045 "%s: " MAC_ADDRESS_STR
3046 " link status %d. staId %d. change station %s.",
3047 __func__, MAC_ADDR_ARRAY(mac), pTdlsPeer->link_status, pTdlsPeer->staId,
3048 (TDLS_STA_INDEX_VALID(pTdlsPeer->staId)) ? "ignored" : "declined");
3049 return (TDLS_STA_INDEX_VALID(pTdlsPeer->staId)) ? 0 : -EPERM;
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003050 }
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07003051
3052 /* when others are on-going, we want to change link_status to idle */
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05303053 if (NULL != wlan_hdd_tdls_is_progress(pHddCtx, mac, TRUE))
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003054 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07003055 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3056 "%s: " MAC_ADDRESS_STR
3057 " TDLS setup is ongoing. Request declined.",
3058 __func__, MAC_ADDR_ARRAY(mac));
Gopichand Nakkala05922802013-03-14 12:23:19 -07003059 goto error;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003060 }
3061
3062 /* first to check if we reached to maximum supported TDLS peer.
3063 TODO: for now, return -EPERM looks working fine,
3064 but need to check if any other errno fit into this category.*/
3065 if (HDD_MAX_NUM_TDLS_STA <= wlan_hdd_tdlsConnectedPeers(pAdapter))
3066 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07003067 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3068 "%s: " MAC_ADDRESS_STR
3069 " TDLS Max peer already connected. Request declined.",
3070 __func__, MAC_ADDR_ARRAY(mac));
Gopichand Nakkala05922802013-03-14 12:23:19 -07003071 goto error;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003072 }
3073 else
3074 {
3075 hddTdlsPeer_t *pTdlsPeer;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05303076 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, mac, TRUE);
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003077 if (pTdlsPeer && TDLS_IS_CONNECTED(pTdlsPeer))
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003078 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07003079 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3080 "%s: " MAC_ADDRESS_STR " already connected. Request declined.",
3081 __func__, MAC_ADDR_ARRAY(mac));
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003082 return -EPERM;
3083 }
3084 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003085 if (0 == update)
3086 wlan_hdd_tdls_set_link_status(pAdapter, mac, eTDLS_LINK_CONNECTING);
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003087
Jeff Johnsond75fe012013-04-06 10:53:06 -07003088 /* debug code */
Gopichand Nakkala838be5d2013-04-10 22:41:51 +05303089 if (NULL != StaParams)
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003090 {
3091 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3092 "%s: TDLS Peer Parameters.", __func__);
Hoonki Lee66b75f32013-04-16 18:30:07 -07003093 if(StaParams->htcap_present)
3094 {
3095 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3096 "ht_capa->cap_info: %0x", StaParams->HTCap.capInfo);
3097 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3098 "ht_capa->extended_capabilities: %0x",
3099 StaParams->HTCap.extendedHtCapInfo);
3100 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003101 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3102 "params->capability: %0x",StaParams->capability);
3103 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3104 "params->ext_capab_len: %0x",StaParams->extn_capability);
Hoonki Lee66b75f32013-04-16 18:30:07 -07003105 if(StaParams->vhtcap_present)
3106 {
3107 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3108 "rxMcsMap %x rxHighest %x txMcsMap %x txHighest %x",
3109 StaParams->VHTCap.suppMcs.rxMcsMap, StaParams->VHTCap.suppMcs.rxHighest,
3110 StaParams->VHTCap.suppMcs.txMcsMap, StaParams->VHTCap.suppMcs.txHighest);
3111 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003112 {
3113 int i = 0;
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003114 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "Supported rates:");
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003115 for (i = 0; i < sizeof(StaParams->supported_rates); i++)
3116 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3117 "[%d]: %x ", i, StaParams->supported_rates[i]);
3118 }
Jeff Johnsond75fe012013-04-06 10:53:06 -07003119 } /* end debug code */
Gopichand Nakkala838be5d2013-04-10 22:41:51 +05303120 else if ((1 == update) && (NULL == StaParams))
3121 {
3122 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3123 "%s : update is true, but staParams is NULL. Error!", __func__);
3124 return -EPERM;
3125 }
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003126
3127 INIT_COMPLETION(pAdapter->tdls_add_station_comp);
3128
3129 if (!update)
3130 {
3131 status = sme_AddTdlsPeerSta(WLAN_HDD_GET_HAL_CTX(pAdapter),
3132 pAdapter->sessionId, mac);
3133 }
3134 else
3135 {
3136 status = sme_ChangeTdlsPeerSta(WLAN_HDD_GET_HAL_CTX(pAdapter),
3137 pAdapter->sessionId, mac, StaParams);
3138 }
3139
3140 status = wait_for_completion_interruptible_timeout(&pAdapter->tdls_add_station_comp,
3141 msecs_to_jiffies(WAIT_TIME_TDLS_ADD_STA));
3142
3143 if (!status)
3144 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07003145 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003146 "%s: timeout waiting for tdls add station indication",
3147 __func__);
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07003148 return -EPERM;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003149 }
3150 if ( eHAL_STATUS_SUCCESS != pAdapter->tdlsAddStaStatus)
3151 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07003152 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003153 "%s: Add Station is unsucessful", __func__);
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07003154 return -EPERM;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003155 }
3156
3157 return 0;
Gopichand Nakkala05922802013-03-14 12:23:19 -07003158
3159error:
3160 wlan_hdd_tdls_set_link_status(pAdapter, mac, eTDLS_LINK_IDLE);
3161 return -EPERM;
3162
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003163}
3164#endif
3165
Jeff Johnson295189b2012-06-20 16:38:30 -07003166static int wlan_hdd_change_station(struct wiphy *wiphy,
3167 struct net_device *dev,
3168 u8 *mac,
3169 struct station_parameters *params)
3170{
3171 VOS_STATUS status = VOS_STATUS_SUCCESS;
3172 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Gopichand Nakkala29149562013-05-10 21:43:41 +05303173 hdd_context_t *pHddCtx;
3174 hdd_station_ctx_t *pHddStaCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07003175 v_MACADDR_t STAMacAddress;
Gopichand Nakkalab0856222013-03-12 22:39:05 -07003176#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003177 tCsrStaParams StaParams = {0};
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003178 tANI_U8 isBufSta = 0;
Gopichand Nakkalab0856222013-03-12 22:39:05 -07003179#endif
Jeff Johnsone7245742012-09-05 17:12:55 -07003180 ENTER();
3181
Gopichand Nakkala29149562013-05-10 21:43:41 +05303182 if ((NULL == pAdapter))
3183 {
3184 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
3185 "invalid adapter ");
3186 return -EINVAL;
3187 }
3188
3189 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
3190 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3191
3192 if ((NULL == pHddCtx) || (NULL == pHddStaCtx))
3193 {
3194 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
3195 "invalid HDD state or HDD station context");
3196 return -EINVAL;
3197 }
3198
3199 if (pHddCtx->isLogpInProgress)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003200 {
3201 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3202 "%s:LOGP in Progress. Ignore!!!", __func__);
3203 return -EAGAIN;
3204 }
3205
Jeff Johnson295189b2012-06-20 16:38:30 -07003206 vos_mem_copy(STAMacAddress.bytes, mac, sizeof(v_MACADDR_t));
3207
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003208 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
3209 || (pAdapter->device_mode == WLAN_HDD_P2P_GO))
Jeff Johnson295189b2012-06-20 16:38:30 -07003210 {
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003211 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED))
Jeff Johnson295189b2012-06-20 16:38:30 -07003212 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303213 status = hdd_softap_change_STA_state( pAdapter, &STAMacAddress,
Jeff Johnson295189b2012-06-20 16:38:30 -07003214 WLANTL_STA_AUTHENTICATED);
3215
Gopichand Nakkala29149562013-05-10 21:43:41 +05303216 if (status != VOS_STATUS_SUCCESS)
3217 {
3218 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3219 "%s: Not able to change TL state to AUTHENTICATED", __func__);
3220 return -EINVAL;
3221 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003222 }
3223 }
Hoonki Leea6d49be2013-04-05 09:43:25 -07003224 else if ((pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
3225 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)) {
Gopichand Nakkala29149562013-05-10 21:43:41 +05303226#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003227 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
3228 StaParams.capability = params->capability;
3229 StaParams.uapsd_queues = params->uapsd_queues;
3230 StaParams.max_sp = params->max_sp;
3231
3232 if (0 != params->ext_capab_len)
3233 vos_mem_copy(StaParams.extn_capability, params->ext_capab,
3234 sizeof(StaParams.extn_capability));
3235
3236 if (NULL != params->ht_capa)
Hoonki Lee66b75f32013-04-16 18:30:07 -07003237 {
3238 StaParams.htcap_present = 1;
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003239 vos_mem_copy(&StaParams.HTCap, params->ht_capa, sizeof(tSirHTCap));
Hoonki Lee66b75f32013-04-16 18:30:07 -07003240 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003241
3242 StaParams.supported_rates_len = params->supported_rates_len;
3243
3244 /* Note : The Maximum sizeof supported_rates sent by the Supplicant is 32.
3245 * The supported_rates array , for all the structures propogating till Add Sta
3246 * to the firmware has to be modified , if the supplicant (ieee80211) is
3247 * modified to send more rates.
3248 */
3249
3250 /* To avoid Data Currption , set to max length to SIR_MAC_MAX_SUPP_RATES
3251 */
3252 if (StaParams.supported_rates_len > SIR_MAC_MAX_SUPP_RATES)
3253 StaParams.supported_rates_len = SIR_MAC_MAX_SUPP_RATES;
3254
3255 if (0 != StaParams.supported_rates_len) {
3256 int i = 0;
3257 vos_mem_copy(StaParams.supported_rates, params->supported_rates,
3258 StaParams.supported_rates_len);
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003259 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003260 "Supported Rates with Length %d", StaParams.supported_rates_len);
3261 for (i=0; i < StaParams.supported_rates_len; i++)
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003262 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003263 "[%d]: %0x", i, StaParams.supported_rates[i]);
3264 }
3265
3266 if (NULL != params->vht_capa)
Hoonki Lee66b75f32013-04-16 18:30:07 -07003267 {
3268 StaParams.vhtcap_present = 1;
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003269 vos_mem_copy(&StaParams.VHTCap, params->vht_capa, sizeof(tSirVHTCap));
Hoonki Lee66b75f32013-04-16 18:30:07 -07003270 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003271
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003272 if (0 != params->ext_capab_len ) {
3273 /*Define A Macro : TODO Sunil*/
3274 if ((1<<4) & StaParams.extn_capability[3]) {
3275 isBufSta = 1;
3276 }
3277 }
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05303278 status = wlan_hdd_tdls_set_peer_caps( pAdapter, mac, params->uapsd_queues,
3279 params->max_sp, isBufSta);
3280 if (VOS_STATUS_SUCCESS != status) {
3281 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3282 "%s: wlan_hdd_tdls_set_peer_caps failed!", __func__);
3283 return -EINVAL;
3284 }
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003285 status = wlan_hdd_tdls_add_station(wiphy, dev, mac, 1, &StaParams);
3286
3287 if (VOS_STATUS_SUCCESS != status) {
3288 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3289 "%s: sme_ChangeTdlsPeerSta failed!", __func__);
3290 return -EINVAL;
3291 }
3292 }
Gopichand Nakkalab0856222013-03-12 22:39:05 -07003293#endif
Gopichand Nakkala6239acd2013-06-14 14:48:00 +05303294 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003295 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07003296 return status;
3297}
3298
3299/*
Jeff Johnson295189b2012-06-20 16:38:30 -07003300 * FUNCTION: wlan_hdd_cfg80211_add_key
3301 * This function is used to initialize the key information
3302 */
3303#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003304static int wlan_hdd_cfg80211_add_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003305 struct net_device *ndev,
3306 u8 key_index, bool pairwise,
3307 const u8 *mac_addr,
3308 struct key_params *params
3309 )
3310#else
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003311static int wlan_hdd_cfg80211_add_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003312 struct net_device *ndev,
3313 u8 key_index, const u8 *mac_addr,
3314 struct key_params *params
3315 )
3316#endif
3317{
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003318 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Jeff Johnson295189b2012-06-20 16:38:30 -07003319 tCsrRoamSetKey setKey;
3320 u8 groupmacaddr[WNI_CFG_BSSID_LEN] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303321 int status;
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003322 v_U32_t roamId= 0xFF;
3323 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
Jeff Johnson295189b2012-06-20 16:38:30 -07003324 hdd_hostapd_state_t *pHostapdState;
3325 VOS_STATUS vos_status;
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003326 eHalStatus halStatus;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303327 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07003328
3329 ENTER();
3330
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303331 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
3332 status = wlan_hdd_validate_context(pHddCtx);
3333
3334 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003335 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303336 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3337 "%s: HDD context is not valid", __func__);
3338 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003339 }
3340
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003341 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
3342 __func__, pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07003343
3344 if (CSR_MAX_NUM_KEY <= key_index)
3345 {
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003346 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key index %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07003347 key_index);
3348
3349 return -EINVAL;
3350 }
3351
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003352 if (CSR_MAX_KEY_LEN < params->key_len)
3353 {
3354 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key length %d", __func__,
3355 params->key_len);
3356
3357 return -EINVAL;
3358 }
3359
3360 hddLog(VOS_TRACE_LEVEL_INFO,
3361 "%s: called with key index = %d & key length %d",
3362 __func__, key_index, params->key_len);
Jeff Johnson295189b2012-06-20 16:38:30 -07003363
3364 /*extract key idx, key len and key*/
3365 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
3366 setKey.keyId = key_index;
3367 setKey.keyLength = params->key_len;
3368 vos_mem_copy(&setKey.Key[0],params->key, params->key_len);
3369
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003370 switch (params->cipher)
Jeff Johnson295189b2012-06-20 16:38:30 -07003371 {
3372 case WLAN_CIPHER_SUITE_WEP40:
3373 setKey.encType = eCSR_ENCRYPT_TYPE_WEP40_STATICKEY;
3374 break;
3375
3376 case WLAN_CIPHER_SUITE_WEP104:
3377 setKey.encType = eCSR_ENCRYPT_TYPE_WEP104_STATICKEY;
3378 break;
3379
3380 case WLAN_CIPHER_SUITE_TKIP:
3381 {
3382 u8 *pKey = &setKey.Key[0];
3383 setKey.encType = eCSR_ENCRYPT_TYPE_TKIP;
3384
3385 vos_mem_zero(pKey, CSR_MAX_KEY_LEN);
3386
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003387 /*Supplicant sends the 32bytes key in this order
Jeff Johnson295189b2012-06-20 16:38:30 -07003388
3389 |--------------|----------|----------|
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003390 | Tk1 |TX-MIC | RX Mic |
Jeff Johnson295189b2012-06-20 16:38:30 -07003391 |--------------|----------|----------|
3392 <---16bytes---><--8bytes--><--8bytes-->
3393
3394 */
3395 /*Sme expects the 32 bytes key to be in the below order
3396
3397 |--------------|----------|----------|
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003398 | Tk1 |RX-MIC | TX Mic |
Jeff Johnson295189b2012-06-20 16:38:30 -07003399 |--------------|----------|----------|
3400 <---16bytes---><--8bytes--><--8bytes-->
3401 */
3402 /* Copy the Temporal Key 1 (TK1) */
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003403 vos_mem_copy(pKey, params->key, 16);
Jeff Johnson295189b2012-06-20 16:38:30 -07003404
3405 /*Copy the rx mic first*/
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003406 vos_mem_copy(&pKey[16], &params->key[24], 8);
Jeff Johnson295189b2012-06-20 16:38:30 -07003407
3408 /*Copy the tx mic */
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003409 vos_mem_copy(&pKey[24], &params->key[16], 8);
Jeff Johnson295189b2012-06-20 16:38:30 -07003410
3411
3412 break;
3413 }
3414
3415 case WLAN_CIPHER_SUITE_CCMP:
3416 setKey.encType = eCSR_ENCRYPT_TYPE_AES;
3417 break;
3418
3419#ifdef FEATURE_WLAN_WAPI
3420 case WLAN_CIPHER_SUITE_SMS4:
3421 {
3422 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
3423 wlan_hdd_cfg80211_set_key_wapi(pAdapter, key_index, mac_addr,
3424 params->key, params->key_len);
3425 return 0;
3426 }
3427#endif
Chet Lanctot186b5732013-03-18 10:26:30 -07003428
Jeff Johnson295189b2012-06-20 16:38:30 -07003429#ifdef FEATURE_WLAN_CCX
3430 case WLAN_CIPHER_SUITE_KRK:
3431 setKey.encType = eCSR_ENCRYPT_TYPE_KRK;
3432 break;
3433#endif
Chet Lanctot186b5732013-03-18 10:26:30 -07003434
3435#ifdef WLAN_FEATURE_11W
3436 case WLAN_CIPHER_SUITE_AES_CMAC:
3437 setKey.encType = eCSR_ENCRYPT_TYPE_AES_CMAC;
Chet Lanctot3b5158a2013-03-31 16:45:21 -07003438 break;
Chet Lanctot186b5732013-03-18 10:26:30 -07003439#endif
3440
Jeff Johnson295189b2012-06-20 16:38:30 -07003441 default:
3442 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: unsupported cipher type %lu",
3443 __func__, params->cipher);
3444 return -EOPNOTSUPP;
3445 }
3446
3447 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: encryption type %d",
3448 __func__, setKey.encType);
3449
Shailender Karmuchi642e9812013-05-30 14:34:49 -07003450 if (
Jeff Johnson295189b2012-06-20 16:38:30 -07003451#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
3452 (!pairwise)
3453#else
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003454 (!mac_addr || is_broadcast_ether_addr(mac_addr))
Jeff Johnson295189b2012-06-20 16:38:30 -07003455#endif
Shailender Karmuchi642e9812013-05-30 14:34:49 -07003456 )
3457 {
3458 /* set group key*/
3459 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3460 "%s- %d: setting Broadcast key",
3461 __func__, __LINE__);
3462 setKey.keyDirection = eSIR_RX_ONLY;
3463 vos_mem_copy(setKey.peerMac,groupmacaddr,WNI_CFG_BSSID_LEN);
3464 }
3465 else
3466 {
3467 /* set pairwise key*/
3468 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3469 "%s- %d: setting pairwise key",
3470 __func__, __LINE__);
3471 setKey.keyDirection = eSIR_TX_RX;
3472 vos_mem_copy(setKey.peerMac, mac_addr,WNI_CFG_BSSID_LEN);
3473 }
3474 if ((WLAN_HDD_IBSS == pAdapter->device_mode) && !pairwise)
3475 {
3476 setKey.keyDirection = eSIR_TX_RX;
3477 /*Set the group key*/
3478 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
3479 pAdapter->sessionId, &setKey, &roamId );
Jeff Johnson295189b2012-06-20 16:38:30 -07003480
Shailender Karmuchi642e9812013-05-30 14:34:49 -07003481 if ( 0 != status )
3482 {
3483 hddLog(VOS_TRACE_LEVEL_ERROR,
3484 "%s: sme_RoamSetKey failed, returned %d", __func__, status);
3485 return -EINVAL;
3486 }
3487 /*Save the keys here and call sme_RoamSetKey for setting
3488 the PTK after peer joins the IBSS network*/
3489 vos_mem_copy(&pAdapter->sessionCtx.station.ibss_enc_key,
3490 &setKey, sizeof(tCsrRoamSetKey));
3491 return status;
3492 }
Gopichand Nakkala29149562013-05-10 21:43:41 +05303493 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP) ||
3494 (pAdapter->device_mode == WLAN_HDD_P2P_GO))
3495 {
Jeff Johnson295189b2012-06-20 16:38:30 -07003496 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003497 if( pHostapdState->bssState == BSS_START )
3498 {
Jeff Johnson295189b2012-06-20 16:38:30 -07003499 status = WLANSAP_SetKeySta( pVosContext, &setKey);
3500
3501 if ( status != eHAL_STATUS_SUCCESS )
3502 {
3503 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3504 "[%4d] WLANSAP_SetKeySta returned ERROR status= %d",
3505 __LINE__, status );
3506 }
3507 }
3508
3509 /* Saving WEP keys */
3510 else if( eCSR_ENCRYPT_TYPE_WEP40_STATICKEY == setKey.encType ||
3511 eCSR_ENCRYPT_TYPE_WEP104_STATICKEY == setKey.encType )
3512 {
3513 //Save the wep key in ap context. Issue setkey after the BSS is started.
3514 hdd_ap_ctx_t *pAPCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
3515 vos_mem_copy(&pAPCtx->wepKey[key_index], &setKey, sizeof(tCsrRoamSetKey));
3516 }
3517 else
3518 {
3519 //Save the key in ap context. Issue setkey after the BSS is started.
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003520 hdd_ap_ctx_t *pAPCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07003521 vos_mem_copy(&pAPCtx->groupKey, &setKey, sizeof(tCsrRoamSetKey));
3522 }
3523 }
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003524 else if ( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION) ||
3525 (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003526 {
3527 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
3528 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3529
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303530#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
3531 if (!pairwise)
3532#else
3533 if (!mac_addr || is_broadcast_ether_addr(mac_addr))
3534#endif
3535 {
3536 /* set group key*/
3537 if (pHddStaCtx->roam_info.deferKeyComplete)
3538 {
3539 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3540 "%s- %d: Perform Set key Complete",
3541 __func__, __LINE__);
3542 hdd_PerformRoamSetKeyComplete(pAdapter);
3543 }
3544 }
3545
Jeff Johnson295189b2012-06-20 16:38:30 -07003546 pWextState->roamProfile.Keys.KeyLength[key_index] = (u8)params->key_len;
3547
Venkata Prathyusha Kuntupalliee2ce712013-01-17 14:09:24 -08003548 pWextState->roamProfile.Keys.defaultIndex = key_index;
3549
3550
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003551 vos_mem_copy(&pWextState->roamProfile.Keys.KeyMaterial[key_index][0],
Jeff Johnson295189b2012-06-20 16:38:30 -07003552 params->key, params->key_len);
3553
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303554
Jeff Johnson295189b2012-06-20 16:38:30 -07003555 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_SETTING_KEY;
3556
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303557 hddLog(VOS_TRACE_LEVEL_INFO_MED,
Jeff Johnson295189b2012-06-20 16:38:30 -07003558 "%s: set key for peerMac %2x:%2x:%2x:%2x:%2x:%2x, direction %d",
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303559 __func__, setKey.peerMac[0], setKey.peerMac[1],
3560 setKey.peerMac[2], setKey.peerMac[3],
3561 setKey.peerMac[4], setKey.peerMac[5],
Jeff Johnson295189b2012-06-20 16:38:30 -07003562 setKey.keyDirection);
3563
3564 vos_status = wlan_hdd_check_ula_done(pAdapter);
3565
3566 if ( vos_status != VOS_STATUS_SUCCESS )
3567 {
3568 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3569 "[%4d] wlan_hdd_check_ula_done returned ERROR status= %d",
3570 __LINE__, vos_status );
3571
3572 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3573
3574 return -EINVAL;
3575
3576 }
3577
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003578#ifdef WLAN_FEATURE_VOWIFI_11R
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303579 /* The supplicant may attempt to set the PTK once pre-authentication
3580 is done. Save the key in the UMAC and include it in the ADD BSS
3581 request */
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003582 halStatus = sme_FTUpdateKey( WLAN_HDD_GET_HAL_CTX(pAdapter), &setKey);
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303583 if ( halStatus == eHAL_STATUS_FT_PREAUTH_KEY_SUCCESS )
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003584 {
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303585 hddLog(VOS_TRACE_LEVEL_INFO_MED,
3586 "%s: Update PreAuth Key success", __func__);
3587 return 0;
3588 }
3589 else if ( halStatus == eHAL_STATUS_FT_PREAUTH_KEY_FAILED )
3590 {
3591 hddLog(VOS_TRACE_LEVEL_ERROR,
3592 "%s: Update PreAuth Key failed", __func__);
Gopichand Nakkalad7d13652013-02-15 01:48:00 +05303593 return -EINVAL;
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003594 }
3595#endif /* WLAN_FEATURE_VOWIFI_11R */
Jeff Johnson295189b2012-06-20 16:38:30 -07003596
3597 /* issue set key request to SME*/
3598 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
3599 pAdapter->sessionId, &setKey, &roamId );
3600
3601 if ( 0 != status )
3602 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303603 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07003604 "%s: sme_RoamSetKey failed, returned %d", __func__, status);
3605 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3606 return -EINVAL;
3607 }
3608
3609
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303610 /* in case of IBSS as there was no information available about WEP keys during
3611 * IBSS join, group key intialized with NULL key, so re-initialize group key
Jeff Johnson295189b2012-06-20 16:38:30 -07003612 * with correct value*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303613 if ( (eCSR_BSS_TYPE_START_IBSS == pWextState->roamProfile.BSSType) &&
3614 !( ( IW_AUTH_KEY_MGMT_802_1X
3615 == (pWextState->authKeyMgmt & IW_AUTH_KEY_MGMT_802_1X))
Jeff Johnson295189b2012-06-20 16:38:30 -07003616 && (eCSR_AUTH_TYPE_OPEN_SYSTEM == pHddStaCtx->conn_info.authType)
3617 )
3618 &&
3619 ( (WLAN_CIPHER_SUITE_WEP40 == params->cipher)
3620 || (WLAN_CIPHER_SUITE_WEP104 == params->cipher)
3621 )
3622 )
3623 {
3624 setKey.keyDirection = eSIR_RX_ONLY;
3625 vos_mem_copy(setKey.peerMac,groupmacaddr,WNI_CFG_BSSID_LEN);
3626
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303627 hddLog(VOS_TRACE_LEVEL_INFO_MED,
Jeff Johnson295189b2012-06-20 16:38:30 -07003628 "%s: set key peerMac %2x:%2x:%2x:%2x:%2x:%2x, direction %d",
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303629 __func__, setKey.peerMac[0], setKey.peerMac[1],
3630 setKey.peerMac[2], setKey.peerMac[3],
3631 setKey.peerMac[4], setKey.peerMac[5],
Jeff Johnson295189b2012-06-20 16:38:30 -07003632 setKey.keyDirection);
3633
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303634 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07003635 pAdapter->sessionId, &setKey, &roamId );
3636
3637 if ( 0 != status )
3638 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303639 hddLog(VOS_TRACE_LEVEL_ERROR,
3640 "%s: sme_RoamSetKey failed for group key (IBSS), returned %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07003641 __func__, status);
3642 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3643 return -EINVAL;
3644 }
3645 }
3646 }
3647
3648 return 0;
3649}
3650
3651/*
3652 * FUNCTION: wlan_hdd_cfg80211_get_key
3653 * This function is used to get the key information
3654 */
3655#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303656static int wlan_hdd_cfg80211_get_key(
3657 struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003658 struct net_device *ndev,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303659 u8 key_index, bool pairwise,
Jeff Johnson295189b2012-06-20 16:38:30 -07003660 const u8 *mac_addr, void *cookie,
3661 void (*callback)(void *cookie, struct key_params*)
3662 )
3663#else
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303664static int wlan_hdd_cfg80211_get_key(
3665 struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003666 struct net_device *ndev,
3667 u8 key_index, const u8 *mac_addr, void *cookie,
3668 void (*callback)(void *cookie, struct key_params*)
3669 )
3670#endif
3671{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303672 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Jeff Johnson295189b2012-06-20 16:38:30 -07003673 hdd_wext_state_t *pWextState= WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
3674 tCsrRoamProfile *pRoamProfile = &(pWextState->roamProfile);
3675 struct key_params params;
3676
3677 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303678
Jeff Johnson295189b2012-06-20 16:38:30 -07003679 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
3680 __func__,pAdapter->device_mode);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303681
Jeff Johnson295189b2012-06-20 16:38:30 -07003682 memset(&params, 0, sizeof(params));
3683
3684 if (CSR_MAX_NUM_KEY <= key_index)
3685 {
3686 return -EINVAL;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303687 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003688
3689 switch(pRoamProfile->EncryptionType.encryptionType[0])
3690 {
3691 case eCSR_ENCRYPT_TYPE_NONE:
3692 params.cipher = IW_AUTH_CIPHER_NONE;
3693 break;
3694
3695 case eCSR_ENCRYPT_TYPE_WEP40_STATICKEY:
3696 case eCSR_ENCRYPT_TYPE_WEP40:
3697 params.cipher = WLAN_CIPHER_SUITE_WEP40;
3698 break;
3699
3700 case eCSR_ENCRYPT_TYPE_WEP104_STATICKEY:
3701 case eCSR_ENCRYPT_TYPE_WEP104:
3702 params.cipher = WLAN_CIPHER_SUITE_WEP104;
3703 break;
3704
3705 case eCSR_ENCRYPT_TYPE_TKIP:
3706 params.cipher = WLAN_CIPHER_SUITE_TKIP;
3707 break;
3708
3709 case eCSR_ENCRYPT_TYPE_AES:
3710 params.cipher = WLAN_CIPHER_SUITE_AES_CMAC;
3711 break;
3712
3713 default:
3714 params.cipher = IW_AUTH_CIPHER_NONE;
3715 break;
3716 }
3717
3718 params.key_len = pRoamProfile->Keys.KeyLength[key_index];
3719 params.seq_len = 0;
3720 params.seq = NULL;
3721 params.key = &pRoamProfile->Keys.KeyMaterial[key_index][0];
3722 callback(cookie, &params);
3723 return 0;
3724}
3725
3726/*
3727 * FUNCTION: wlan_hdd_cfg80211_del_key
3728 * This function is used to delete the key information
3729 */
3730#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303731static int wlan_hdd_cfg80211_del_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003732 struct net_device *ndev,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303733 u8 key_index,
3734 bool pairwise,
Jeff Johnson295189b2012-06-20 16:38:30 -07003735 const u8 *mac_addr
3736 )
3737#else
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303738static int wlan_hdd_cfg80211_del_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003739 struct net_device *ndev,
3740 u8 key_index,
3741 const u8 *mac_addr
3742 )
3743#endif
3744{
3745 int status = 0;
3746
3747 //This code needs to be revisited. There is sme_removeKey API, we should
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303748 //plan to use that. After the change to use correct index in setkey,
Jeff Johnson295189b2012-06-20 16:38:30 -07003749 //it is observed that this is invalidating peer
3750 //key index whenever re-key is done. This is affecting data link.
3751 //It should be ok to ignore del_key.
3752#if 0
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303753 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
3754 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
Jeff Johnson295189b2012-06-20 16:38:30 -07003755 u8 groupmacaddr[WNI_CFG_BSSID_LEN] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
3756 tCsrRoamSetKey setKey;
3757 v_U32_t roamId= 0xFF;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303758
Jeff Johnson295189b2012-06-20 16:38:30 -07003759 ENTER();
3760
3761 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: device_mode = %d\n",
3762 __func__,pAdapter->device_mode);
3763
3764 if (CSR_MAX_NUM_KEY <= key_index)
3765 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303766 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key index %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07003767 key_index);
3768
3769 return -EINVAL;
3770 }
3771
3772 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
3773 setKey.keyId = key_index;
3774
3775 if (mac_addr)
3776 vos_mem_copy(setKey.peerMac, mac_addr,WNI_CFG_BSSID_LEN);
3777 else
3778 vos_mem_copy(setKey.peerMac, groupmacaddr, WNI_CFG_BSSID_LEN);
3779
3780 setKey.encType = eCSR_ENCRYPT_TYPE_NONE;
3781
3782 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07003783 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303784 )
3785 {
3786
3787 hdd_hostapd_state_t *pHostapdState =
Jeff Johnson295189b2012-06-20 16:38:30 -07003788 WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
3789 if( pHostapdState->bssState == BSS_START)
3790 {
3791 status = WLANSAP_SetKeySta( pVosContext, &setKey);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303792
Jeff Johnson295189b2012-06-20 16:38:30 -07003793 if ( status != eHAL_STATUS_SUCCESS )
3794 {
3795 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3796 "[%4d] WLANSAP_SetKeySta returned ERROR status= %d",
3797 __LINE__, status );
3798 }
3799 }
3800 }
3801 else if ( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303802 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Jeff Johnson295189b2012-06-20 16:38:30 -07003803 )
3804 {
3805 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3806
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303807 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_SETTING_KEY;
3808
3809 hddLog(VOS_TRACE_LEVEL_INFO_MED,
Jeff Johnson295189b2012-06-20 16:38:30 -07003810 "%s: delete key for peerMac %2x:%2x:%2x:%2x:%2x:%2x",
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303811 __func__, setKey.peerMac[0], setKey.peerMac[1],
3812 setKey.peerMac[2], setKey.peerMac[3],
Jeff Johnson295189b2012-06-20 16:38:30 -07003813 setKey.peerMac[4], setKey.peerMac[5]);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303814 if(pAdapter->sessionCtx.station.conn_info.connState ==
3815 eConnectionState_Associated)
Jeff Johnson295189b2012-06-20 16:38:30 -07003816 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303817 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07003818 pAdapter->sessionId, &setKey, &roamId );
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303819
Jeff Johnson295189b2012-06-20 16:38:30 -07003820 if ( 0 != status )
3821 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303822 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07003823 "%s: sme_RoamSetKey failure, returned %d",
3824 __func__, status);
3825 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3826 return -EINVAL;
3827 }
3828 }
3829 }
3830#endif
Jeff Johnsone7245742012-09-05 17:12:55 -07003831 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07003832 return status;
3833}
3834
3835/*
3836 * FUNCTION: wlan_hdd_cfg80211_set_default_key
3837 * This function is used to set the default tx key index
3838 */
3839#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
3840static int wlan_hdd_cfg80211_set_default_key( struct wiphy *wiphy,
3841 struct net_device *ndev,
3842 u8 key_index,
3843 bool unicast, bool multicast)
3844#else
3845static int wlan_hdd_cfg80211_set_default_key( struct wiphy *wiphy,
3846 struct net_device *ndev,
3847 u8 key_index)
3848#endif
3849{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303850 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303851 int status;
Gopichand Nakkala29149562013-05-10 21:43:41 +05303852 hdd_wext_state_t *pWextState;
3853 hdd_station_ctx_t *pHddStaCtx;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303854 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07003855
3856 ENTER();
3857
Gopichand Nakkala29149562013-05-10 21:43:41 +05303858 if ((NULL == pAdapter))
3859 {
3860 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
3861 "invalid adapter");
3862 return -EINVAL;
3863 }
3864
3865 pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
3866 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3867
3868 if ((NULL == pWextState) || (NULL == pHddStaCtx))
3869 {
3870 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
3871 "invalid Wext state or HDD context");
3872 return -EINVAL;
3873 }
3874
Jeff Johnson295189b2012-06-20 16:38:30 -07003875 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d key_index = %d \n",
3876 __func__,pAdapter->device_mode, key_index);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303877
Jeff Johnson295189b2012-06-20 16:38:30 -07003878 if (CSR_MAX_NUM_KEY <= key_index)
3879 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303880 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key index %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07003881 key_index);
3882
3883 return -EINVAL;
3884 }
3885
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303886 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
3887 status = wlan_hdd_validate_context(pHddCtx);
3888
3889 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003890 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303891 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3892 "%s: HDD context is not valid", __func__);
3893 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003894 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303895
Jeff Johnson295189b2012-06-20 16:38:30 -07003896 if ((pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Jeff Johnson295189b2012-06-20 16:38:30 -07003897 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303898 )
Jeff Johnson295189b2012-06-20 16:38:30 -07003899 {
Gopichand Nakkala29149562013-05-10 21:43:41 +05303900 if ( (eCSR_ENCRYPT_TYPE_TKIP !=
Jeff Johnson295189b2012-06-20 16:38:30 -07003901 pWextState->roamProfile.EncryptionType.encryptionType[0]) &&
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303902 (eCSR_ENCRYPT_TYPE_AES !=
Jeff Johnson295189b2012-06-20 16:38:30 -07003903 pWextState->roamProfile.EncryptionType.encryptionType[0])
3904 )
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303905 {
3906 /* if default key index is not same as previous one,
Jeff Johnson295189b2012-06-20 16:38:30 -07003907 * then update the default key index */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303908
Jeff Johnson295189b2012-06-20 16:38:30 -07003909 tCsrRoamSetKey setKey;
3910 v_U32_t roamId= 0xFF;
3911 tCsrKeys *Keys = &pWextState->roamProfile.Keys;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303912
3913 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: default tx key index %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07003914 __func__, key_index);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303915
Jeff Johnson295189b2012-06-20 16:38:30 -07003916 Keys->defaultIndex = (u8)key_index;
3917 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
3918 setKey.keyId = key_index;
3919 setKey.keyLength = Keys->KeyLength[key_index];
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303920
3921 vos_mem_copy(&setKey.Key[0],
3922 &Keys->KeyMaterial[key_index][0],
Jeff Johnson295189b2012-06-20 16:38:30 -07003923 Keys->KeyLength[key_index]);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303924
Gopichand Nakkala29149562013-05-10 21:43:41 +05303925 setKey.keyDirection = eSIR_TX_RX;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303926
3927 vos_mem_copy(setKey.peerMac,
Jeff Johnson295189b2012-06-20 16:38:30 -07003928 &pHddStaCtx->conn_info.bssId[0],
3929 WNI_CFG_BSSID_LEN);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303930
Gopichand Nakkala29149562013-05-10 21:43:41 +05303931 if (Keys->KeyLength[key_index] == CSR_WEP40_KEY_LEN &&
3932 pWextState->roamProfile.EncryptionType.encryptionType[0] ==
3933 eCSR_ENCRYPT_TYPE_WEP104)
3934 {
3935 /*In the case of dynamic wep supplicant hardcodes DWEP type to eCSR_ENCRYPT_TYPE_WEP104
3936 even though ap is configured for WEP-40 encryption. In this canse the key length
3937 is 5 but the encryption type is 104 hence checking the key langht(5) and encryption
3938 type(104) and switching encryption type to 40*/
3939 pWextState->roamProfile.EncryptionType.encryptionType[0] =
3940 eCSR_ENCRYPT_TYPE_WEP40;
3941 pWextState->roamProfile.mcEncryptionType.encryptionType[0] =
3942 eCSR_ENCRYPT_TYPE_WEP40;
3943 }
3944
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303945 setKey.encType =
Jeff Johnson295189b2012-06-20 16:38:30 -07003946 pWextState->roamProfile.EncryptionType.encryptionType[0];
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303947
Jeff Johnson295189b2012-06-20 16:38:30 -07003948 /* issue set key request */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303949 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07003950 pAdapter->sessionId, &setKey, &roamId );
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303951
Jeff Johnson295189b2012-06-20 16:38:30 -07003952 if ( 0 != status )
3953 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303954 hddLog(VOS_TRACE_LEVEL_ERROR,
3955 "%s: sme_RoamSetKey failed, returned %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07003956 status);
3957 return -EINVAL;
3958 }
3959 }
3960 }
3961
3962 /* In SoftAp mode setting key direction for default mode */
3963 else if ( WLAN_HDD_SOFTAP == pAdapter->device_mode )
3964 {
3965 if ( (eCSR_ENCRYPT_TYPE_TKIP !=
3966 pWextState->roamProfile.EncryptionType.encryptionType[0]) &&
3967 (eCSR_ENCRYPT_TYPE_AES !=
3968 pWextState->roamProfile.EncryptionType.encryptionType[0])
3969 )
3970 {
3971 /* Saving key direction for default key index to TX default */
3972 hdd_ap_ctx_t *pAPCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
3973 pAPCtx->wepKey[key_index].keyDirection = eSIR_TX_DEFAULT;
3974 }
3975 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303976
Jeff Johnson295189b2012-06-20 16:38:30 -07003977 return status;
3978}
3979
Jeff Johnson295189b2012-06-20 16:38:30 -07003980/*
3981 * FUNCTION: wlan_hdd_cfg80211_inform_bss
3982 * This function is used to inform the BSS details to nl80211 interface.
3983 */
3984static struct cfg80211_bss* wlan_hdd_cfg80211_inform_bss(
3985 hdd_adapter_t *pAdapter, tCsrRoamConnectedProfile *roamProfile)
3986{
3987 struct net_device *dev = pAdapter->dev;
3988 struct wireless_dev *wdev = dev->ieee80211_ptr;
3989 struct wiphy *wiphy = wdev->wiphy;
3990 tSirBssDescription *pBssDesc = roamProfile->pBssDesc;
3991 int chan_no;
3992 int ie_length;
3993 const char *ie;
3994 unsigned int freq;
3995 struct ieee80211_channel *chan;
3996 int rssi = 0;
3997 struct cfg80211_bss *bss = NULL;
3998
3999 ENTER();
4000
4001 if( NULL == pBssDesc )
4002 {
4003 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: pBssDesc is NULL\n", __func__);
4004 return bss;
4005 }
4006
4007 chan_no = pBssDesc->channelId;
4008 ie_length = GET_IE_LEN_IN_BSS_DESC( pBssDesc->length );
4009 ie = ((ie_length != 0) ? (const char *)&pBssDesc->ieFields: NULL);
4010
4011 if( NULL == ie )
4012 {
4013 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: IE of BSS descriptor is NULL\n", __func__);
4014 return bss;
4015 }
4016
4017#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,38))
4018 if (chan_no <= ARRAY_SIZE(hdd_channels_2_4_GHZ))
4019 {
4020 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_2GHZ);
4021 }
4022 else
4023 {
4024 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_5GHZ);
4025 }
4026#else
4027 freq = ieee80211_channel_to_frequency(chan_no);
4028#endif
4029
4030 chan = __ieee80211_get_channel(wiphy, freq);
4031
4032 bss = cfg80211_get_bss(wiphy, chan, pBssDesc->bssId,
4033 &roamProfile->SSID.ssId[0], roamProfile->SSID.length,
4034 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
4035 if (bss == NULL)
4036 {
4037 rssi = (VOS_MIN ((pBssDesc->rssi + pBssDesc->sinr), 0))*100;
4038
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304039 return (cfg80211_inform_bss(wiphy, chan, pBssDesc->bssId,
4040 le64_to_cpu(*(__le64 *)pBssDesc->timeStamp),
Jeff Johnson295189b2012-06-20 16:38:30 -07004041 pBssDesc->capabilityInfo,
4042 pBssDesc->beaconInterval, ie, ie_length,
4043 rssi, GFP_KERNEL ));
4044}
4045 else
4046 {
4047 return bss;
4048 }
4049}
4050
4051
4052
4053/*
4054 * FUNCTION: wlan_hdd_cfg80211_inform_bss_frame
4055 * This function is used to inform the BSS details to nl80211 interface.
4056 */
4057struct cfg80211_bss*
4058wlan_hdd_cfg80211_inform_bss_frame( hdd_adapter_t *pAdapter,
4059 tSirBssDescription *bss_desc
4060 )
4061{
4062 /*
4063 cfg80211_inform_bss() is not updating ie field of bss entry, if entry
4064 already exists in bss data base of cfg80211 for that particular BSS ID.
4065 Using cfg80211_inform_bss_frame to update the bss entry instead of
4066 cfg80211_inform_bss, But this call expects mgmt packet as input. As of
4067 now there is no possibility to get the mgmt(probe response) frame from PE,
4068 converting bss_desc to ieee80211_mgmt(probe response) and passing to
4069 cfg80211_inform_bss_frame.
4070 */
4071 struct net_device *dev = pAdapter->dev;
4072 struct wireless_dev *wdev = dev->ieee80211_ptr;
4073 struct wiphy *wiphy = wdev->wiphy;
4074 int chan_no = bss_desc->channelId;
Madan Mohan Koyyalamudi86f629e2012-11-09 16:27:29 -08004075#ifdef WLAN_ENABLE_AGEIE_ON_SCAN_RESULTS
4076 qcom_ie_age *qie_age = NULL;
4077 int ie_length = GET_IE_LEN_IN_BSS_DESC( bss_desc->length ) + sizeof(qcom_ie_age);
4078#else
Jeff Johnson295189b2012-06-20 16:38:30 -07004079 int ie_length = GET_IE_LEN_IN_BSS_DESC( bss_desc->length );
Madan Mohan Koyyalamudi86f629e2012-11-09 16:27:29 -08004080#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004081 const char *ie =
4082 ((ie_length != 0) ? (const char *)&bss_desc->ieFields: NULL);
4083 unsigned int freq;
4084 struct ieee80211_channel *chan;
4085 struct ieee80211_mgmt *mgmt =
4086 kzalloc((sizeof (struct ieee80211_mgmt) + ie_length), GFP_KERNEL);
4087 struct cfg80211_bss *bss_status = NULL;
4088 size_t frame_len = sizeof (struct ieee80211_mgmt) + ie_length;
4089 int rssi = 0;
Jeff Johnsone7245742012-09-05 17:12:55 -07004090#ifdef WLAN_OPEN_SOURCE
4091 struct timespec ts;
4092#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004093
4094 ENTER();
4095
Madan Mohan Koyyalamudi2e5c9142012-11-02 13:17:48 -07004096 if (!mgmt)
4097 return NULL;
4098
Jeff Johnson295189b2012-06-20 16:38:30 -07004099 memcpy(mgmt->bssid, bss_desc->bssId, ETH_ALEN);
Jeff Johnsone7245742012-09-05 17:12:55 -07004100
4101#ifdef WLAN_OPEN_SOURCE
4102 /* Android does not want the timestamp from the frame.
4103 Instead it wants a monotonic increasing value */
4104 get_monotonic_boottime(&ts);
4105 mgmt->u.probe_resp.timestamp =
4106 ((u64)ts.tv_sec * 1000000) + (ts.tv_nsec / 1000);
4107#else
4108 /* keep old behavior for non-open source (for now) */
Jeff Johnson295189b2012-06-20 16:38:30 -07004109 memcpy(&mgmt->u.probe_resp.timestamp, bss_desc->timeStamp,
4110 sizeof (bss_desc->timeStamp));
Jeff Johnsone7245742012-09-05 17:12:55 -07004111
4112#endif
4113
Jeff Johnson295189b2012-06-20 16:38:30 -07004114 mgmt->u.probe_resp.beacon_int = bss_desc->beaconInterval;
4115 mgmt->u.probe_resp.capab_info = bss_desc->capabilityInfo;
Madan Mohan Koyyalamudi86f629e2012-11-09 16:27:29 -08004116
4117#ifdef WLAN_ENABLE_AGEIE_ON_SCAN_RESULTS
4118 /* GPS Requirement: need age ie per entry. Using vendor specific. */
4119 /* Assuming this is the last IE, copy at the end */
4120 ie_length -=sizeof(qcom_ie_age);
4121 qie_age = (qcom_ie_age *)(mgmt->u.probe_resp.variable + ie_length);
4122 qie_age->element_id = QCOM_VENDOR_IE_ID;
4123 qie_age->len = QCOM_VENDOR_IE_AGE_LEN;
4124 qie_age->oui_1 = QCOM_OUI1;
4125 qie_age->oui_2 = QCOM_OUI2;
4126 qie_age->oui_3 = QCOM_OUI3;
4127 qie_age->type = QCOM_VENDOR_IE_AGE_TYPE;
4128 qie_age->age = vos_timer_get_system_ticks() - bss_desc->nReceivedTime;
4129#endif
4130
Jeff Johnson295189b2012-06-20 16:38:30 -07004131 memcpy(mgmt->u.probe_resp.variable, ie, ie_length);
Gopichand Nakkalad908ec82013-05-16 19:32:19 +05304132 if (bss_desc->fProbeRsp)
4133 {
4134 mgmt->frame_control |=
4135 (u16)(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_RESP);
4136 }
4137 else
4138 {
4139 mgmt->frame_control |=
4140 (u16)(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_BEACON);
4141 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004142
4143#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,38))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304144 if (chan_no <= ARRAY_SIZE(hdd_channels_2_4_GHZ) &&
Jeff Johnson295189b2012-06-20 16:38:30 -07004145 (wiphy->bands[IEEE80211_BAND_2GHZ] != NULL))
4146 {
4147 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_2GHZ);
4148 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304149 else if ((chan_no > ARRAY_SIZE(hdd_channels_2_4_GHZ)) &&
Jeff Johnson295189b2012-06-20 16:38:30 -07004150 (wiphy->bands[IEEE80211_BAND_5GHZ] != NULL))
4151
4152 {
4153 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_5GHZ);
4154 }
4155 else
4156 {
4157 kfree(mgmt);
4158 return NULL;
4159 }
4160#else
4161 freq = ieee80211_channel_to_frequency(chan_no);
4162#endif
4163 chan = __ieee80211_get_channel(wiphy, freq);
Leela V Kiran Kumar Reddy90032de2013-01-24 18:33:30 -08004164 /*when the band is changed on the fly using the GUI, three things are done
4165 * 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)
4166 * as part of the scan abort, message willbe queued to PE and we proceed with flushing and changinh the band.
4167 * pe will stop the scanning further and report back the results what ever it had till now by calling the call back function.
4168 * if the time between update band and scandone call back is sufficent enough the band change reflects in SME, SME validates the channels
4169 * and discards the channels correponding to previous band and calls back with zero bss results.
4170 * 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
4171 * all the channels correponding to previous band.this is due to race condition.but those channels are invalid to the new band and so
4172 * this function __ieee80211_get_channel will return NULL.Each time we report scan result with this pointer null warning kernel trace is printed.
4173 * if the scan results contain large number of APs continuosly kernel warning trace is printed and it will lead to apps watch dog bark.
4174 * So drop the bss and continue to next bss.
4175 */
4176 if(chan == NULL)
4177 {
4178 hddLog(VOS_TRACE_LEVEL_INFO, "%s chan pointer is NULL", __func__);
Chilam Ngc4244af2013-04-01 15:37:32 -07004179 kfree(mgmt);
Leela V Kiran Kumar Reddy90032de2013-01-24 18:33:30 -08004180 return NULL;
4181 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004182 /*To keep the rssi icon of the connected AP in the scan window
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304183 *and the rssi icon of the wireless networks in sync
Jeff Johnson295189b2012-06-20 16:38:30 -07004184 * */
4185 if (( eConnectionState_Associated ==
4186 pAdapter->sessionCtx.station.conn_info.connState ) &&
4187 ( VOS_TRUE == vos_mem_compare(bss_desc->bssId,
4188 pAdapter->sessionCtx.station.conn_info.bssId,
4189 WNI_CFG_BSSID_LEN)))
4190 {
4191 /* supplicant takes the signal strength in terms of mBm(100*dBm) */
4192 rssi = (pAdapter->rssi * 100);
4193 }
4194 else
4195 {
4196 rssi = (VOS_MIN ((bss_desc->rssi + bss_desc->sinr), 0))*100;
4197 }
4198
4199 bss_status = cfg80211_inform_bss_frame(wiphy, chan, mgmt,
4200 frame_len, rssi, GFP_KERNEL);
4201 kfree(mgmt);
4202 return bss_status;
4203}
4204
4205/*
4206 * FUNCTION: wlan_hdd_cfg80211_update_bss_db
4207 * This function is used to update the BSS data base of CFG8011
4208 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304209struct cfg80211_bss* wlan_hdd_cfg80211_update_bss_db( hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07004210 tCsrRoamInfo *pRoamInfo
4211 )
4212{
4213 tCsrRoamConnectedProfile roamProfile;
4214 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
4215 struct cfg80211_bss *bss = NULL;
4216
4217 ENTER();
4218
4219 memset(&roamProfile, 0, sizeof(tCsrRoamConnectedProfile));
4220 sme_RoamGetConnectProfile(hHal, pAdapter->sessionId, &roamProfile);
4221
4222 if (NULL != roamProfile.pBssDesc)
4223 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304224 bss = wlan_hdd_cfg80211_inform_bss(pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07004225 &roamProfile);
4226
4227 if (NULL == bss)
4228 {
4229 hddLog(VOS_TRACE_LEVEL_INFO, "%s: cfg80211_inform_bss return NULL",
4230 __func__);
4231 }
4232
4233 sme_RoamFreeConnectProfile(hHal, &roamProfile);
4234 }
4235 else
4236 {
4237 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: roamProfile.pBssDesc is NULL",
4238 __func__);
4239 }
4240 return bss;
4241}
4242
4243/*
4244 * FUNCTION: wlan_hdd_cfg80211_update_bss
4245 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304246static int wlan_hdd_cfg80211_update_bss( struct wiphy *wiphy,
4247 hdd_adapter_t *pAdapter
Jeff Johnson295189b2012-06-20 16:38:30 -07004248 )
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304249{
Jeff Johnson295189b2012-06-20 16:38:30 -07004250 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
4251 tCsrScanResultInfo *pScanResult;
4252 eHalStatus status = 0;
4253 tScanResultHandle pResult;
4254 struct cfg80211_bss *bss_status = NULL;
4255
4256 ENTER();
4257
4258 if ((WLAN_HDD_GET_CTX(pAdapter))->isLogpInProgress)
4259 {
4260 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL, "%s:LOGP in Progress. Ignore!!!",__func__);
4261 return -EAGAIN;
4262 }
4263
4264 /*
4265 * start getting scan results and populate cgf80211 BSS database
4266 */
4267 status = sme_ScanGetResult(hHal, pAdapter->sessionId, NULL, &pResult);
4268
4269 /* no scan results */
4270 if (NULL == pResult)
4271 {
4272 hddLog(VOS_TRACE_LEVEL_INFO, "%s: No scan result\n", __func__);
4273 return status;
4274 }
4275
4276 pScanResult = sme_ScanResultGetFirst(hHal, pResult);
4277
4278 while (pScanResult)
4279 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304280 /*
4281 * cfg80211_inform_bss() is not updating ie field of bss entry, if
4282 * entry already exists in bss data base of cfg80211 for that
4283 * particular BSS ID. Using cfg80211_inform_bss_frame to update the
4284 * bss entry instead of cfg80211_inform_bss, But this call expects
4285 * mgmt packet as input. As of now there is no possibility to get
4286 * the mgmt(probe response) frame from PE, converting bss_desc to
Jeff Johnson295189b2012-06-20 16:38:30 -07004287 * ieee80211_mgmt(probe response) and passing to c
4288 * fg80211_inform_bss_frame.
4289 * */
4290
4291 bss_status = wlan_hdd_cfg80211_inform_bss_frame(pAdapter,
4292 &pScanResult->BssDescriptor);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304293
Jeff Johnson295189b2012-06-20 16:38:30 -07004294
4295 if (NULL == bss_status)
4296 {
4297 hddLog(VOS_TRACE_LEVEL_INFO,
4298 "%s: NULL returned by cfg80211_inform_bss\n", __func__);
4299 }
4300 else
4301 {
Yue Maf49ba872013-08-19 12:04:25 -07004302 cfg80211_put_bss(
4303#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,9,0))
4304 wiphy,
4305#endif
4306 bss_status);
Jeff Johnson295189b2012-06-20 16:38:30 -07004307 }
4308
4309 pScanResult = sme_ScanResultGetNext(hHal, pResult);
4310 }
4311
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304312 sme_ScanResultPurge(hHal, pResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07004313
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304314 return 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07004315}
4316
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004317void
4318hddPrintMacAddr(tCsrBssid macAddr, tANI_U8 logLevel)
4319{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304320 VOS_TRACE(VOS_MODULE_ID_HDD, logLevel,
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07004321 "%02X:%02X:%02X:%02X:%02X:%02X\n",
4322 macAddr[0], macAddr[1], macAddr[2], macAddr[3], macAddr[4],
4323 macAddr[5]);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004324} /****** end hddPrintMacAddr() ******/
4325
4326void
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07004327hddPrintPmkId(tANI_U8 *pmkId, tANI_U8 logLevel)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004328{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304329 VOS_TRACE(VOS_MODULE_ID_HDD, logLevel,
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07004330 "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
4331 pmkId[0], pmkId[1], pmkId[2], pmkId[3], pmkId[4],
4332 pmkId[5], pmkId[6], pmkId[7], pmkId[8], pmkId[9], pmkId[10],
4333 pmkId[11], pmkId[12], pmkId[13], pmkId[14], pmkId[15]);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004334} /****** end hddPrintPmkId() ******/
4335
4336//hddPrintMacAddr(tCsrBssid macAddr, tANI_U8 logLevel);
4337//hddPrintMacAddr(macAddr, VOS_TRACE_LEVEL_FATAL);
4338
4339//void sirDumpBuf(tpAniSirGlobal pMac, tANI_U8 modId, tANI_U32 level, tANI_U8 *buf, tANI_U32 size);
4340//sirDumpBuf(pMac, VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL, pmkid, 16);
4341
4342#define dump_bssid(bssid) \
4343 { \
Jeff Johnsone7245742012-09-05 17:12:55 -07004344 hddLog(VOS_TRACE_LEVEL_INFO, "BSSID (MAC) address:\t"); \
4345 hddPrintMacAddr(bssid, VOS_TRACE_LEVEL_INFO);\
4346 hddLog(VOS_TRACE_LEVEL_INFO, "\n"); \
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004347 }
4348
4349#define dump_pmkid(pMac, pmkid) \
4350 { \
Jeff Johnsone7245742012-09-05 17:12:55 -07004351 hddLog(VOS_TRACE_LEVEL_INFO, "PMKSA-ID:\t"); \
4352 hddPrintPmkId(pmkid, VOS_TRACE_LEVEL_INFO);\
4353 hddLog(VOS_TRACE_LEVEL_INFO, "\n"); \
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004354 }
4355
Madan Mohan Koyyalamudi1b4afb02012-10-22 15:25:16 -07004356#if defined(FEATURE_WLAN_LFR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004357/*
4358 * FUNCTION: wlan_hdd_cfg80211_pmksa_candidate_notify
4359 * This function is used to notify the supplicant of a new PMKSA candidate.
4360 */
4361int wlan_hdd_cfg80211_pmksa_candidate_notify(
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304362 hdd_adapter_t *pAdapter, tCsrRoamInfo *pRoamInfo,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004363 int index, bool preauth )
4364{
Jeff Johnsone7245742012-09-05 17:12:55 -07004365#ifdef FEATURE_WLAN_OKC
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004366 struct net_device *dev = pAdapter->dev;
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004367 hdd_context_t *pHddCtx = (hdd_context_t*)pAdapter->pHddCtx;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004368
4369 ENTER();
Jeff Johnsone7245742012-09-05 17:12:55 -07004370 hddLog(VOS_TRACE_LEVEL_INFO, "%s is going to notify supplicant of:", __func__);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004371
4372 if( NULL == pRoamInfo )
4373 {
4374 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: pRoamInfo is NULL\n", __func__);
4375 return -EINVAL;
4376 }
4377
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004378 if (eANI_BOOLEAN_TRUE == hdd_is_okc_mode_enabled(pHddCtx))
4379 {
4380 dump_bssid(pRoamInfo->bssid);
4381 cfg80211_pmksa_candidate_notify(dev, index,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004382 pRoamInfo->bssid, preauth, GFP_KERNEL);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004383 }
Jeff Johnsone7245742012-09-05 17:12:55 -07004384#endif /* FEATURE_WLAN_OKC */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304385 return 0;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004386}
4387#endif //FEATURE_WLAN_LFR
4388
Yue Maef608272013-04-08 23:09:17 -07004389#ifdef FEATURE_WLAN_LFR_METRICS
4390/*
4391 * FUNCTION: wlan_hdd_cfg80211_roam_metrics_preauth
4392 * 802.11r/LFR metrics reporting function to report preauth initiation
4393 *
4394 */
4395#define MAX_LFR_METRICS_EVENT_LENGTH 100
4396VOS_STATUS wlan_hdd_cfg80211_roam_metrics_preauth(hdd_adapter_t *pAdapter,
4397 tCsrRoamInfo *pRoamInfo)
4398{
4399 unsigned char metrics_notification[MAX_LFR_METRICS_EVENT_LENGTH + 1];
4400 union iwreq_data wrqu;
4401
4402 ENTER();
4403
4404 if (NULL == pAdapter)
4405 {
4406 hddLog(LOGE, "%s: pAdapter is NULL!", __func__);
4407 return VOS_STATUS_E_FAILURE;
4408 }
4409
4410 /* create the event */
4411 memset(&wrqu, 0, sizeof(wrqu));
4412 memset(metrics_notification, 0, sizeof(metrics_notification));
4413
4414 wrqu.data.pointer = metrics_notification;
4415 wrqu.data.length = scnprintf(metrics_notification,
4416 sizeof(metrics_notification), "QCOM: LFR_PREAUTH_INIT "
4417 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(pRoamInfo->bssid));
4418
4419 wireless_send_event(pAdapter->dev, IWEVCUSTOM, &wrqu, metrics_notification);
4420
4421 EXIT();
4422
4423 return VOS_STATUS_SUCCESS;
4424}
4425
4426/*
4427 * FUNCTION: wlan_hdd_cfg80211_roam_metrics_preauth_status
4428 * 802.11r/LFR metrics reporting function to report preauth completion
4429 * or failure
4430 */
4431VOS_STATUS wlan_hdd_cfg80211_roam_metrics_preauth_status(
4432 hdd_adapter_t *pAdapter, tCsrRoamInfo *pRoamInfo, bool preauth_status)
4433{
4434 unsigned char metrics_notification[MAX_LFR_METRICS_EVENT_LENGTH + 1];
4435 union iwreq_data wrqu;
4436
4437 ENTER();
4438
4439 if (NULL == pAdapter)
4440 {
4441 hddLog(LOGE, "%s: pAdapter is NULL!", __func__);
4442 return VOS_STATUS_E_FAILURE;
4443 }
4444
4445 /* create the event */
4446 memset(&wrqu, 0, sizeof(wrqu));
4447 memset(metrics_notification, 0, sizeof(metrics_notification));
4448
4449 scnprintf(metrics_notification, sizeof(metrics_notification),
4450 "QCOM: LFR_PREAUTH_STATUS "MAC_ADDRESS_STR,
4451 MAC_ADDR_ARRAY(pRoamInfo->bssid));
4452
4453 if (1 == preauth_status)
4454 strncat(metrics_notification, " TRUE", 5);
4455 else
4456 strncat(metrics_notification, " FALSE", 6);
4457
4458 wrqu.data.pointer = metrics_notification;
4459 wrqu.data.length = strlen(metrics_notification);
4460
4461 wireless_send_event(pAdapter->dev, IWEVCUSTOM, &wrqu, metrics_notification);
4462
4463 EXIT();
4464
4465 return VOS_STATUS_SUCCESS;
4466}
4467
4468/*
4469 * FUNCTION: wlan_hdd_cfg80211_roam_metrics_handover
4470 * 802.11r/LFR metrics reporting function to report handover initiation
4471 *
4472 */
4473VOS_STATUS wlan_hdd_cfg80211_roam_metrics_handover(hdd_adapter_t * pAdapter,
4474 tCsrRoamInfo *pRoamInfo)
4475{
4476 unsigned char metrics_notification[MAX_LFR_METRICS_EVENT_LENGTH + 1];
4477 union iwreq_data wrqu;
4478
4479 ENTER();
4480
4481 if (NULL == pAdapter)
4482 {
4483 hddLog(LOGE, "%s: pAdapter is NULL!", __func__);
4484 return VOS_STATUS_E_FAILURE;
4485 }
4486
4487 /* create the event */
4488 memset(&wrqu, 0, sizeof(wrqu));
4489 memset(metrics_notification, 0, sizeof(metrics_notification));
4490
4491 wrqu.data.pointer = metrics_notification;
4492 wrqu.data.length = scnprintf(metrics_notification,
4493 sizeof(metrics_notification), "QCOM: LFR_PREAUTH_HANDOVER "
4494 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(pRoamInfo->bssid));
4495
4496 wireless_send_event(pAdapter->dev, IWEVCUSTOM, &wrqu, metrics_notification);
4497
4498 EXIT();
4499
4500 return VOS_STATUS_SUCCESS;
4501}
4502#endif
4503
Jeff Johnson295189b2012-06-20 16:38:30 -07004504/*
4505 * FUNCTION: hdd_cfg80211_scan_done_callback
4506 * scanning callback function, called after finishing scan
4507 *
4508 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304509static eHalStatus hdd_cfg80211_scan_done_callback(tHalHandle halHandle,
Jeff Johnson295189b2012-06-20 16:38:30 -07004510 void *pContext, tANI_U32 scanId, eCsrScanStatus status)
4511{
4512 struct net_device *dev = (struct net_device *) pContext;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304513 //struct wireless_dev *wdev = dev->ieee80211_ptr;
Jeff Johnson295189b2012-06-20 16:38:30 -07004514 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004515 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
4516 hdd_scaninfo_t *pScanInfo = &pHddCtx->scan_info;
Jeff Johnson295189b2012-06-20 16:38:30 -07004517 struct cfg80211_scan_request *req = NULL;
4518 int ret = 0;
4519
4520 ENTER();
4521
4522 hddLog(VOS_TRACE_LEVEL_INFO,
4523 "%s called with halHandle = %p, pContext = %p,"
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304524 "scanID = %d, returned status = %d\n",
Jeff Johnson295189b2012-06-20 16:38:30 -07004525 __func__, halHandle, pContext, (int) scanId, (int) status);
4526
4527 //Block on scan req completion variable. Can't wait forever though.
4528 ret = wait_for_completion_interruptible_timeout(
4529 &pScanInfo->scan_req_completion_event,
4530 msecs_to_jiffies(WLAN_WAIT_TIME_SCAN_REQ));
4531 if (!ret)
4532 {
4533 VOS_ASSERT(pScanInfo->mScanPending);
Jeff Johnsone7245742012-09-05 17:12:55 -07004534 goto allow_suspend;
Jeff Johnson295189b2012-06-20 16:38:30 -07004535 }
4536
Yue Maef608272013-04-08 23:09:17 -07004537 if (pScanInfo->mScanPending != VOS_TRUE)
Jeff Johnson295189b2012-06-20 16:38:30 -07004538 {
4539 VOS_ASSERT(pScanInfo->mScanPending);
Jeff Johnsone7245742012-09-05 17:12:55 -07004540 goto allow_suspend;
Jeff Johnson295189b2012-06-20 16:38:30 -07004541 }
4542
4543 /* Check the scanId */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304544 if (pScanInfo->scanId != scanId)
Jeff Johnson295189b2012-06-20 16:38:30 -07004545 {
4546 hddLog(VOS_TRACE_LEVEL_INFO,
4547 "%s called with mismatched scanId pScanInfo->scanId = %d "
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304548 "scanId = %d \n", __func__, (int) pScanInfo->scanId,
Jeff Johnson295189b2012-06-20 16:38:30 -07004549 (int) scanId);
4550 }
4551
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304552 ret = wlan_hdd_cfg80211_update_bss((WLAN_HDD_GET_CTX(pAdapter))->wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07004553 pAdapter);
4554
4555 if (0 > ret)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304556 hddLog(VOS_TRACE_LEVEL_INFO, "%s: NO SCAN result", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07004557
4558
4559 /* If any client wait scan result through WEXT
4560 * send scan done event to client */
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004561 if (pHddCtx->scan_info.waitScanResult)
Jeff Johnson295189b2012-06-20 16:38:30 -07004562 {
4563 /* The other scan request waiting for current scan finish
4564 * Send event to notify current scan finished */
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004565 if(WEXT_SCAN_PENDING_DELAY == pHddCtx->scan_info.scan_pending_option)
Jeff Johnson295189b2012-06-20 16:38:30 -07004566 {
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004567 vos_event_set(&pHddCtx->scan_info.scan_finished_event);
Jeff Johnson295189b2012-06-20 16:38:30 -07004568 }
4569 /* Send notify to WEXT client */
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004570 else if(WEXT_SCAN_PENDING_PIGGYBACK == pHddCtx->scan_info.scan_pending_option)
Jeff Johnson295189b2012-06-20 16:38:30 -07004571 {
4572 struct net_device *dev = pAdapter->dev;
4573 union iwreq_data wrqu;
4574 int we_event;
4575 char *msg;
4576
4577 memset(&wrqu, '\0', sizeof(wrqu));
4578 we_event = SIOCGIWSCAN;
4579 msg = NULL;
4580 wireless_send_event(dev, we_event, &wrqu, msg);
4581 }
4582 }
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004583 pHddCtx->scan_info.waitScanResult = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004584
4585 /* Get the Scan Req */
4586 req = pAdapter->request;
4587
4588 if (!req)
4589 {
4590 hddLog(VOS_TRACE_LEVEL_ERROR, "request is became NULL\n");
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07004591 pScanInfo->mScanPending = VOS_FALSE;
Jeff Johnsone7245742012-09-05 17:12:55 -07004592 goto allow_suspend;
Jeff Johnson295189b2012-06-20 16:38:30 -07004593 }
4594
4595 /*
4596 * setting up 0, just in case.
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304597 */
Jeff Johnson295189b2012-06-20 16:38:30 -07004598 req->n_ssids = 0;
4599 req->n_channels = 0;
4600 req->ie = 0;
4601
Jeff Johnson295189b2012-06-20 16:38:30 -07004602 pAdapter->request = NULL;
Jeff Johnsone7245742012-09-05 17:12:55 -07004603 /* Scan is no longer pending */
4604 pScanInfo->mScanPending = VOS_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004605
Madan Mohan Koyyalamudib764bf82012-10-11 16:38:51 -07004606 /*
4607 * cfg80211_scan_done informing NL80211 about completion
4608 * of scanning
4609 */
4610 cfg80211_scan_done(req, false);
Madan Mohan Koyyalamudif4e81002012-11-13 10:46:38 -08004611 complete(&pScanInfo->abortscan_event_var);
Jeff Johnson295189b2012-06-20 16:38:30 -07004612
Jeff Johnsone7245742012-09-05 17:12:55 -07004613allow_suspend:
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07004614 /* release the wake lock at the end of the scan*/
4615 hdd_allow_suspend();
Jeff Johnsone7245742012-09-05 17:12:55 -07004616
Madan Mohan Koyyalamudi10d83a92012-09-28 15:47:05 -07004617 /* Acquire wakelock to handle the case where APP's tries to suspend
4618 * immediatly after the driver gets connect request(i.e after scan)
4619 * from supplicant, this result in app's is suspending and not able
4620 * to process the connect request to AP */
Amar Singhal6144c002013-05-03 16:11:42 -07004621 hdd_allow_suspend_timeout(1000);
Madan Mohan Koyyalamudi10d83a92012-09-28 15:47:05 -07004622
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07004623#ifdef FEATURE_WLAN_TDLS
4624 wlan_hdd_tdls_scan_done_callback(pAdapter);
4625#endif
4626
Jeff Johnson295189b2012-06-20 16:38:30 -07004627 EXIT();
4628 return 0;
4629}
4630
4631/*
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004632 * FUNCTION: hdd_isScanAllowed
4633 * Go through each adapter and check if scan allowed
4634 *
4635 */
4636v_BOOL_t hdd_isScanAllowed( hdd_context_t *pHddCtx )
4637{
4638 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
4639 hdd_station_ctx_t *pHddStaCtx = NULL;
4640 hdd_adapter_t *pAdapter = NULL;
4641 VOS_STATUS status = 0;
4642 v_U8_t staId = 0;
4643 v_U8_t *staMac = NULL;
4644
4645 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
4646
4647 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
4648 {
4649 pAdapter = pAdapterNode->pAdapter;
4650
4651 if( pAdapter )
4652 {
4653 hddLog(VOS_TRACE_LEVEL_INFO,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304654 "%s: Adapter with device mode %d exists",
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004655 __func__, pAdapter->device_mode);
4656 if ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
4657 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) ||
4658 (WLAN_HDD_P2P_DEVICE == pAdapter->device_mode))
4659 {
4660 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
4661 if ((eConnectionState_Associated == pHddStaCtx->conn_info.connState) &&
4662 (VOS_FALSE == pHddStaCtx->conn_info.uIsAuthenticated))
4663 {
4664 staMac = (v_U8_t *) &(pAdapter->macAddressCurrent.bytes[0]);
4665 hddLog(VOS_TRACE_LEVEL_ERROR,
4666 "%s: client %02x:%02x:%02x:%02x:%02x:%02x is in the "
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304667 "middle of WPS/EAPOL exchange.", __func__,
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004668 staMac[0], staMac[1], staMac[2],
4669 staMac[3], staMac[4], staMac[5]);
4670 return VOS_FALSE;
4671 }
4672 }
4673 else if ((WLAN_HDD_SOFTAP == pAdapter->device_mode) ||
4674 (WLAN_HDD_P2P_GO == pAdapter->device_mode))
4675 {
4676 for (staId = 0; staId < WLAN_MAX_STA_COUNT; staId++)
4677 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304678 if ((pAdapter->aStaInfo[staId].isUsed) &&
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004679 (WLANTL_STA_CONNECTED == pAdapter->aStaInfo[staId].tlSTAState))
4680 {
4681 staMac = (v_U8_t *) &(pAdapter->aStaInfo[staId].macAddrSTA.bytes[0]);
4682
4683 hddLog(VOS_TRACE_LEVEL_ERROR,
4684 "%s: client %02x:%02x:%02x:%02x:%02x:%02x of SoftAP/P2P-GO is in the "
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304685 "middle of WPS/EAPOL exchange.", __func__,
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004686 staMac[0], staMac[1], staMac[2],
4687 staMac[3], staMac[4], staMac[5]);
4688 return VOS_FALSE;
4689 }
4690 }
4691 }
4692 }
4693 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
4694 pAdapterNode = pNext;
4695 }
4696 hddLog(VOS_TRACE_LEVEL_INFO,
4697 "%s: Scan allowed", __func__);
4698 return VOS_TRUE;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304699}
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004700
4701/*
Jeff Johnson295189b2012-06-20 16:38:30 -07004702 * FUNCTION: wlan_hdd_cfg80211_scan
4703 * this scan respond to scan trigger and update cfg80211 scan database
4704 * later, scan dump command can be used to recieve scan results
4705 */
Jeff Johnson3bbe4bf2013-01-18 17:05:29 -08004706int wlan_hdd_cfg80211_scan( struct wiphy *wiphy,
4707#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
4708 struct net_device *dev,
4709#endif
4710 struct cfg80211_scan_request *request)
4711{
4712#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
4713 struct net_device *dev = request->wdev->netdev;
4714#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304715 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Jeff Johnson295189b2012-06-20 16:38:30 -07004716 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
4717 hdd_wext_state_t *pwextBuf = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05304718 hdd_config_t *cfg_param = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004719 tCsrScanRequest scanRequest;
4720 tANI_U8 *channelList = NULL, i;
4721 v_U32_t scanId = 0;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05304722 int status;
4723 hdd_scaninfo_t *pScanInfo = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004724 v_U8_t* pP2pIe = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004725
4726 ENTER();
4727
4728 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
4729 __func__,pAdapter->device_mode);
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004730
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05304731 status = wlan_hdd_validate_context(pHddCtx);
4732
4733 if (0 != status)
4734 {
4735 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4736 "%s: HDD context is not valid", __func__);
4737 return status;
4738 }
4739
4740 cfg_param = pHddCtx->cfg_ini;
4741 pScanInfo = &pHddCtx->scan_info;
4742
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004743 if ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) &&
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004744 (eConnectionState_Connecting ==
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004745 (WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))->conn_info.connState))
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004746 {
4747 hddLog(VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08004748 "%s: %p(%d) Connection in progress: Scan request denied (EBUSY)", __func__, \
4749 WLAN_HDD_GET_STATION_CTX_PTR(pAdapter), pAdapter->sessionId);
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004750 return -EBUSY;
4751 }
4752
Jeff Johnson295189b2012-06-20 16:38:30 -07004753#ifdef WLAN_BTAMP_FEATURE
4754 //Scan not supported when AMP traffic is on.
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004755 if (VOS_TRUE == WLANBAP_AmpSessionOn())
Jeff Johnson295189b2012-06-20 16:38:30 -07004756 {
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004757 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07004758 "%s: No scanning when AMP is on", __func__);
4759 return -EOPNOTSUPP;
4760 }
4761#endif
4762 //Scan on any other interface is not supported.
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004763 if (pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07004764 {
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004765 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07004766 "%s: Not scanning on device_mode = %d",
4767 __func__, pAdapter->device_mode);
4768 return -EOPNOTSUPP;
4769 }
4770
4771 if (TRUE == pScanInfo->mScanPending)
4772 {
4773 hddLog(VOS_TRACE_LEVEL_INFO, "%s: mScanPending is TRUE", __func__);
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004774 return -EBUSY;
Jeff Johnson295189b2012-06-20 16:38:30 -07004775 }
4776
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304777 //Don't Allow Scan and return busy if Remain On
Jeff Johnson32d95a32012-09-10 13:15:23 -07004778 //Channel and action frame is pending
4779 //Otherwise Cancel Remain On Channel and allow Scan
4780 //If no action frame pending
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004781 if (0 != wlan_hdd_check_remain_on_channel(pAdapter))
Jeff Johnson32d95a32012-09-10 13:15:23 -07004782 {
4783 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Remain On Channel Pending", __func__);
4784 return -EBUSY;
4785 }
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004786#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07004787 /* if tdls disagree scan right now, return immediately.
4788 tdls will schedule the scan when scan is allowed. (return SUCCESS)
4789 or will reject the scan if any TDLS is in progress. (return -EBUSY)
4790 */
4791 status = wlan_hdd_tdls_scan_callback (pAdapter,
4792 wiphy,
4793#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
4794 dev,
Gopichand Nakkalac3c42b92013-03-20 19:42:34 -07004795#endif
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07004796 request);
4797 if(status <= 0)
4798 {
4799 hddLog(VOS_TRACE_LEVEL_INFO, "%s: TDLS Pending %d", __func__, status);
4800 return status;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004801 }
4802#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -07004803
Jeff Johnson295189b2012-06-20 16:38:30 -07004804 if (mutex_lock_interruptible(&pHddCtx->tmInfo.tmOperationLock))
4805 {
4806 VOS_TRACE(VOS_MODULE_ID_HDD,VOS_TRACE_LEVEL_ERROR,
Jeff Johnson1250df42012-12-10 14:31:52 -08004807 "%s: Acquire lock fail", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07004808 return -EAGAIN;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304809 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004810 if (TRUE == pHddCtx->tmInfo.tmAction.enterImps)
4811 {
4812 hddLog(VOS_TRACE_LEVEL_WARN,
4813 "%s: MAX TM Level Scan not allowed", __func__);
4814 mutex_unlock(&pHddCtx->tmInfo.tmOperationLock);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304815 return -EBUSY;
Jeff Johnson295189b2012-06-20 16:38:30 -07004816 }
4817 mutex_unlock(&pHddCtx->tmInfo.tmOperationLock);
4818
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004819 /* Check if scan is allowed at this point of time.
4820 */
4821 if (!hdd_isScanAllowed(pHddCtx))
4822 {
4823 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Scan not allowed", __func__);
4824 return -EBUSY;
4825 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304826
Jeff Johnson295189b2012-06-20 16:38:30 -07004827 vos_mem_zero( &scanRequest, sizeof(scanRequest));
4828
4829 if (NULL != request)
4830 {
4831 hddLog(VOS_TRACE_LEVEL_INFO, "scan request for ssid = %d",
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304832 (int)request->n_ssids);
Jeff Johnson295189b2012-06-20 16:38:30 -07004833
4834 /* Even though supplicant doesn't provide any SSIDs, n_ssids is set to 1.
4835 * Becasue of this, driver is assuming that this is not wildcard scan and so
4836 * is not aging out the scan results.
4837 */
Jeff Johnson32d95a32012-09-10 13:15:23 -07004838 if (request->ssids && '\0' == request->ssids->ssid[0])
Jeff Johnson295189b2012-06-20 16:38:30 -07004839 {
4840 request->n_ssids = 0;
4841 }
4842
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07004843 if ((request->ssids) && (0 < request->n_ssids))
Jeff Johnson295189b2012-06-20 16:38:30 -07004844 {
4845 tCsrSSIDInfo *SsidInfo;
4846 int j;
4847 scanRequest.SSIDs.numOfSSIDs = request->n_ssids;
4848 /* Allocate num_ssid tCsrSSIDInfo structure */
4849 SsidInfo = scanRequest.SSIDs.SSIDList =
4850 ( tCsrSSIDInfo *)vos_mem_malloc(
4851 request->n_ssids*sizeof(tCsrSSIDInfo));
4852
4853 if(NULL == scanRequest.SSIDs.SSIDList)
4854 {
4855 hddLog(VOS_TRACE_LEVEL_ERROR,
4856 "memory alloc failed SSIDInfo buffer");
4857 return -ENOMEM;
4858 }
4859
4860 /* copy all the ssid's and their length */
4861 for(j = 0; j < request->n_ssids; j++, SsidInfo++)
4862 {
4863 /* get the ssid length */
4864 SsidInfo->SSID.length = request->ssids[j].ssid_len;
4865 vos_mem_copy(SsidInfo->SSID.ssId, &request->ssids[j].ssid[0],
4866 SsidInfo->SSID.length);
4867 SsidInfo->SSID.ssId[SsidInfo->SSID.length] = '\0';
4868 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "SSID number %d: %s",
4869 j, SsidInfo->SSID.ssId);
4870 }
4871 /* set the scan type to active */
4872 scanRequest.scanType = eSIR_ACTIVE_SCAN;
4873 }
4874 else if(WLAN_HDD_P2P_GO == pAdapter->device_mode)
4875 {
4876 /* set the scan type to active */
4877 scanRequest.scanType = eSIR_ACTIVE_SCAN;
4878 }
4879 else
4880 {
4881 /*Set the scan type to default type, in this case it is ACTIVE*/
4882 scanRequest.scanType = pScanInfo->scan_mode;
4883 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304884 scanRequest.minChnTime = cfg_param->nActiveMinChnTime;
Jeff Johnson295189b2012-06-20 16:38:30 -07004885 scanRequest.maxChnTime = cfg_param->nActiveMaxChnTime;
4886 }
4887 else
4888 {
4889 /* set the scan type to active */
4890 scanRequest.scanType = eSIR_ACTIVE_SCAN;
4891 vos_mem_set( scanRequest.bssid, sizeof( tCsrBssid ), 0xff );
4892
4893 /* set min and max channel time to zero */
4894 scanRequest.minChnTime = 0;
4895 scanRequest.maxChnTime = 0;
4896 }
4897
4898 /* set BSSType to default type */
4899 scanRequest.BSSType = eCSR_BSS_TYPE_ANY;
4900
4901 /*TODO: scan the requested channels only*/
4902
4903 /*Right now scanning all the channels */
4904 if( request )
4905 {
4906 if( request->n_channels )
4907 {
4908 channelList = vos_mem_malloc( request->n_channels );
4909 if( NULL == channelList )
4910 {
4911 status = -ENOMEM;
4912 goto free_mem;
4913 }
4914
4915 for( i = 0 ; i < request->n_channels ; i++ )
4916 channelList[i] = request->channels[i]->hw_value;
4917 }
4918
4919 scanRequest.ChannelInfo.numOfChannels = request->n_channels;
4920 scanRequest.ChannelInfo.ChannelList = channelList;
4921
4922 /* set requestType to full scan */
4923 scanRequest.requestType = eCSR_SCAN_REQUEST_FULL_SCAN;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304924
4925 /* Flush the scan results(only p2p beacons) for STA scan and P2P
Madan Mohan Koyyalamudi8d50f312012-11-27 15:48:57 -08004926 * search (Flush on both full scan and social scan but not on single
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304927 * channel scan).P2P search happens on 3 social channels (1, 6, 11)
Madan Mohan Koyyalamudi8d50f312012-11-27 15:48:57 -08004928 */
4929
4930 /* Supplicant does single channel scan after 8-way handshake
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304931 * and in that case driver shoudnt flush scan results. If
4932 * driver flushes the scan results here and unfortunately if
4933 * the AP doesnt respond to our probe req then association
Madan Mohan Koyyalamudi8d50f312012-11-27 15:48:57 -08004934 * fails which is not desired
4935 */
4936
4937 if( request->n_channels != WLAN_HDD_P2P_SINGLE_CHANNEL_SCAN )
4938 {
4939 sme_ScanFlushP2PResult( WLAN_HDD_GET_HAL_CTX(pAdapter),
4940 pAdapter->sessionId );
4941 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004942
4943 if( request->ie_len )
4944 {
4945 /* save this for future association (join requires this) */
4946 memset( &pScanInfo->scanAddIE, 0, sizeof(pScanInfo->scanAddIE) );
4947 memcpy( pScanInfo->scanAddIE.addIEdata, request->ie, request->ie_len);
4948 pScanInfo->scanAddIE.length = request->ie_len;
4949
4950 if((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
Jeff Johnsone7245742012-09-05 17:12:55 -07004951 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) ||
4952 (WLAN_HDD_P2P_DEVICE == pAdapter->device_mode)
Jeff Johnson295189b2012-06-20 16:38:30 -07004953 )
4954 {
4955 pwextBuf->roamProfile.pAddIEScan = pScanInfo->scanAddIE.addIEdata;
4956 pwextBuf->roamProfile.nAddIEScanLength = pScanInfo->scanAddIE.length;
4957 }
4958
4959 scanRequest.uIEFieldLen = pScanInfo->scanAddIE.length;
4960 scanRequest.pIEField = pScanInfo->scanAddIE.addIEdata;
4961
Jeff Johnson295189b2012-06-20 16:38:30 -07004962 pP2pIe = wlan_hdd_get_p2p_ie_ptr((v_U8_t*)request->ie,
4963 request->ie_len);
4964 if (pP2pIe != NULL)
4965 {
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07004966#ifdef WLAN_FEATURE_P2P_DEBUG
4967 if (((globalP2PConnectionStatus == P2P_GO_NEG_COMPLETED) ||
4968 (globalP2PConnectionStatus == P2P_GO_NEG_PROCESS)) &&
4969 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
4970 {
4971 globalP2PConnectionStatus = P2P_CLIENT_CONNECTING_STATE_1;
4972 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P State] Changing state from "
4973 "Go nego completed to Connection is started");
4974 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P]P2P Scanning is started "
4975 "for 8way Handshake");
4976 }
4977 else if((globalP2PConnectionStatus == P2P_CLIENT_DISCONNECTED_STATE) &&
4978 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
4979 {
4980 globalP2PConnectionStatus = P2P_CLIENT_CONNECTING_STATE_2;
4981 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P State] Changing state from "
4982 "Disconnected state to Connection is started");
4983 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P]P2P Scanning is started "
4984 "for 4way Handshake");
4985 }
4986#endif
4987
Jeff Johnsone7245742012-09-05 17:12:55 -07004988 /* no_cck will be set during p2p find to disable 11b rates */
4989 if(TRUE == request->no_cck)
Jeff Johnson295189b2012-06-20 16:38:30 -07004990 {
Jeff Johnson295189b2012-06-20 16:38:30 -07004991 hddLog(VOS_TRACE_LEVEL_INFO,
4992 "%s: This is a P2P Search", __func__);
4993 scanRequest.p2pSearch = 1;
Jeff Johnsone7245742012-09-05 17:12:55 -07004994
Jeff Johnsone7245742012-09-05 17:12:55 -07004995 if( request->n_channels == WLAN_HDD_P2P_SOCIAL_CHANNELS )
4996 {
Madan Mohan Koyyalamudi1b1d9e82012-10-21 11:38:33 -07004997 /* set requestType to P2P Discovery */
4998 scanRequest.requestType = eCSR_SCAN_P2P_DISCOVERY;
Jeff Johnsone7245742012-09-05 17:12:55 -07004999 }
5000
5001 /*
5002 Skip Dfs Channel in case of P2P Search
5003 if it is set in ini file
5004 */
5005 if(cfg_param->skipDfsChnlInP2pSearch)
5006 {
5007 scanRequest.skipDfsChnlInP2pSearch = 1;
5008 }
5009 else
5010 {
5011 scanRequest.skipDfsChnlInP2pSearch = 0;
5012 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005013
Jeff Johnson295189b2012-06-20 16:38:30 -07005014 }
5015 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005016 }
5017 }
5018
5019 INIT_COMPLETION(pScanInfo->scan_req_completion_event);
5020
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07005021 /* acquire the wakelock to avoid the apps suspend during the scan. To
5022 * address the following issues.
5023 * 1) Disconnected scenario: we are not allowing the suspend as WLAN is not in
5024 * BMPS/IMPS this result in android trying to suspend aggressively and backing off
5025 * for long time, this result in apps running at full power for long time.
5026 * 2) Connected scenario: If we allow the suspend during the scan, RIVA will
5027 * be stuck in full power because of resume BMPS
5028 */
5029 hdd_prevent_suspend();
Jeff Johnsone7245742012-09-05 17:12:55 -07005030
5031 status = sme_ScanRequest( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07005032 pAdapter->sessionId, &scanRequest, &scanId,
5033 &hdd_cfg80211_scan_done_callback, dev );
Jeff Johnsone7245742012-09-05 17:12:55 -07005034
Jeff Johnson295189b2012-06-20 16:38:30 -07005035 if (eHAL_STATUS_SUCCESS != status)
5036 {
5037 hddLog(VOS_TRACE_LEVEL_ERROR,
5038 "%s: sme_ScanRequest returned error %d", __func__, status);
5039 complete(&pScanInfo->scan_req_completion_event);
Madan Mohan Koyyalamudi3b230fe2012-10-18 14:46:32 -07005040 if(eHAL_STATUS_RESOURCES == status)
5041 {
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07005042 hddLog(VOS_TRACE_LEVEL_INFO, "%s: HO is in progress.So defer the scan by informing busy",__func__);
Madan Mohan Koyyalamudi3b230fe2012-10-18 14:46:32 -07005043 status = -EBUSY;
5044 } else {
5045 status = -EIO;
5046 }
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07005047 hdd_allow_suspend();
Jeff Johnson295189b2012-06-20 16:38:30 -07005048 goto free_mem;
5049 }
5050
5051 pScanInfo->mScanPending = TRUE;
5052 pAdapter->request = request;
5053 pScanInfo->scanId = scanId;
5054
5055 complete(&pScanInfo->scan_req_completion_event);
5056
5057free_mem:
5058 if( scanRequest.SSIDs.SSIDList )
5059 {
5060 vos_mem_free(scanRequest.SSIDs.SSIDList);
5061 }
5062
5063 if( channelList )
5064 vos_mem_free( channelList );
5065
5066 EXIT();
5067
5068 return status;
5069}
5070
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07005071
5072void hdd_select_cbmode( hdd_adapter_t *pAdapter,v_U8_t operationChannel)
5073{
5074 v_U8_t iniDot11Mode =
5075 (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini->dot11Mode;
5076 eHddDot11Mode hddDot11Mode = iniDot11Mode;
5077
5078 switch ( iniDot11Mode )
5079 {
5080 case eHDD_DOT11_MODE_AUTO:
5081 case eHDD_DOT11_MODE_11ac:
5082 case eHDD_DOT11_MODE_11ac_ONLY:
5083#ifdef WLAN_FEATURE_11AC
5084 hddDot11Mode = eHDD_DOT11_MODE_11ac;
5085#else
5086 hddDot11Mode = eHDD_DOT11_MODE_11n;
5087#endif
5088 break;
5089 case eHDD_DOT11_MODE_11n:
5090 case eHDD_DOT11_MODE_11n_ONLY:
5091 hddDot11Mode = eHDD_DOT11_MODE_11n;
5092 break;
5093 default:
5094 hddDot11Mode = iniDot11Mode;
5095 break;
5096 }
5097 /* This call decides required channel bonding mode */
5098 sme_SelectCBMode((WLAN_HDD_GET_CTX(pAdapter)->hHal),
5099 hdd_cfg_xlate_to_csr_phy_mode(hddDot11Mode),
5100 operationChannel);
5101}
5102
Jeff Johnson295189b2012-06-20 16:38:30 -07005103/*
5104 * FUNCTION: wlan_hdd_cfg80211_connect_start
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305105 * This function is used to start the association process
Jeff Johnson295189b2012-06-20 16:38:30 -07005106 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305107int wlan_hdd_cfg80211_connect_start( hdd_adapter_t *pAdapter,
Jeff Johnson32d95a32012-09-10 13:15:23 -07005108 const u8 *ssid, size_t ssid_len, const u8 *bssid, u8 operatingChannel)
Jeff Johnson295189b2012-06-20 16:38:30 -07005109{
5110 int status = 0;
5111 hdd_wext_state_t *pWextState;
5112 v_U32_t roamId;
5113 tCsrRoamProfile *pRoamProfile;
5114 eMib_dot11DesiredBssType connectedBssType;
5115 eCsrAuthType RSNAuthType;
5116
5117 ENTER();
5118
5119 pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305120
Jeff Johnson295189b2012-06-20 16:38:30 -07005121 if (SIR_MAC_MAX_SSID_LENGTH < ssid_len)
5122 {
5123 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: wrong SSID len", __func__);
5124 return -EINVAL;
5125 }
5126
5127 pRoamProfile = &pWextState->roamProfile;
5128
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305129 if (pRoamProfile)
Jeff Johnson295189b2012-06-20 16:38:30 -07005130 {
Jeff Johnsone7245742012-09-05 17:12:55 -07005131 int ret = 0;
5132 hdd_station_ctx_t *pHddStaCtx;
5133 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
5134 hdd_connGetConnectedBssType(pHddStaCtx,&connectedBssType );
5135
5136 if((eMib_dot11DesiredBssType_independent == connectedBssType) ||
5137 (eConnectionState_Associated == pHddStaCtx->conn_info.connState) ||
5138 (eConnectionState_IbssConnected == pHddStaCtx->conn_info.connState))
Jeff Johnson295189b2012-06-20 16:38:30 -07005139 {
5140 /* Issue disconnect to CSR */
5141 INIT_COMPLETION(pAdapter->disconnect_comp_var);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305142 if( eHAL_STATUS_SUCCESS ==
Jeff Johnson295189b2012-06-20 16:38:30 -07005143 sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
5144 pAdapter->sessionId,
5145 eCSR_DISCONNECT_REASON_UNSPECIFIED ) )
5146 {
Jeff Johnsone7245742012-09-05 17:12:55 -07005147 ret = wait_for_completion_interruptible_timeout(
5148 &pAdapter->disconnect_comp_var,
5149 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
5150 if (0 == ret)
5151 {
5152 VOS_ASSERT(0);
5153 }
5154 }
5155 }
5156 else if(eConnectionState_Disconnecting == pHddStaCtx->conn_info.connState)
5157 {
5158 ret = wait_for_completion_interruptible_timeout(
5159 &pAdapter->disconnect_comp_var,
5160 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
5161 if (0 == ret)
5162 {
5163 VOS_ASSERT(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005164 }
5165 }
5166
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305167 if (HDD_WMM_USER_MODE_NO_QOS ==
Jeff Johnson295189b2012-06-20 16:38:30 -07005168 (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini->WmmMode)
5169 {
5170 /*QoS not enabled in cfg file*/
5171 pRoamProfile->uapsd_mask = 0;
5172 }
5173 else
5174 {
5175 /*QoS enabled, update uapsd mask from cfg file*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305176 pRoamProfile->uapsd_mask =
Jeff Johnson295189b2012-06-20 16:38:30 -07005177 (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini->UapsdMask;
5178 }
5179
5180 pRoamProfile->SSIDs.numOfSSIDs = 1;
5181 pRoamProfile->SSIDs.SSIDList->SSID.length = ssid_len;
5182 vos_mem_zero(pRoamProfile->SSIDs.SSIDList->SSID.ssId,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305183 sizeof(pRoamProfile->SSIDs.SSIDList->SSID.ssId));
Jeff Johnson295189b2012-06-20 16:38:30 -07005184 vos_mem_copy((void *)(pRoamProfile->SSIDs.SSIDList->SSID.ssId),
5185 ssid, ssid_len);
5186
5187 if (bssid)
5188 {
5189 pRoamProfile->BSSIDs.numOfBSSIDs = 1;
5190 vos_mem_copy((void *)(pRoamProfile->BSSIDs.bssid), bssid,
5191 WNI_CFG_BSSID_LEN);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305192 /* Save BSSID in seperate variable as well, as RoamProfile
5193 BSSID is getting zeroed out in the association process. And in
Jeff Johnson295189b2012-06-20 16:38:30 -07005194 case of join failure we should send valid BSSID to supplicant
5195 */
5196 vos_mem_copy((void *)(pWextState->req_bssId), bssid,
5197 WNI_CFG_BSSID_LEN);
5198 }
Dhanashri Atre51981c62013-06-13 11:47:57 -07005199 else
5200 {
5201 vos_mem_zero((void *)(pRoamProfile->BSSIDs.bssid),WNI_CFG_BSSID_LEN);
5202 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005203
5204 if ((IW_AUTH_WPA_VERSION_WPA == pWextState->wpaVersion) ||
5205 (IW_AUTH_WPA_VERSION_WPA2 == pWextState->wpaVersion))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305206 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005207 /*set gen ie*/
5208 hdd_SetGENIEToCsr(pAdapter, &RSNAuthType);
5209 /*set auth*/
5210 hdd_set_csr_auth_type(pAdapter, RSNAuthType);
5211 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005212#ifdef FEATURE_WLAN_WAPI
5213 if (pAdapter->wapi_info.nWapiMode)
5214 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005215 hddLog(LOG1, "%s: Setting WAPI AUTH Type and Encryption Mode values", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005216 switch (pAdapter->wapi_info.wapiAuthMode)
5217 {
5218 case WAPI_AUTH_MODE_PSK:
5219 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005220 hddLog(LOG1, "%s: WAPI AUTH TYPE: PSK: %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07005221 pAdapter->wapi_info.wapiAuthMode);
5222 pRoamProfile->AuthType.authType[0] = eCSR_AUTH_TYPE_WAPI_WAI_PSK;
5223 break;
5224 }
5225 case WAPI_AUTH_MODE_CERT:
5226 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005227 hddLog(LOG1, "%s: WAPI AUTH TYPE: CERT: %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07005228 pAdapter->wapi_info.wapiAuthMode);
5229 pRoamProfile->AuthType.authType[0] = eCSR_AUTH_TYPE_WAPI_WAI_CERTIFICATE;
5230 break;
5231 }
5232 } // End of switch
5233 if ( pAdapter->wapi_info.wapiAuthMode == WAPI_AUTH_MODE_PSK ||
5234 pAdapter->wapi_info.wapiAuthMode == WAPI_AUTH_MODE_CERT)
5235 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005236 hddLog(LOG1, "%s: WAPI PAIRWISE/GROUP ENCRYPTION: WPI", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005237 pRoamProfile->AuthType.numEntries = 1;
5238 pRoamProfile->EncryptionType.numEntries = 1;
5239 pRoamProfile->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_WPI;
5240 pRoamProfile->mcEncryptionType.numEntries = 1;
5241 pRoamProfile->mcEncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_WPI;
5242 }
5243 }
5244#endif /* FEATURE_WLAN_WAPI */
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05305245#ifdef WLAN_FEATURE_GTK_OFFLOAD
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05305246 /* Initializing gtkOffloadReqParams */
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05305247 if ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
5248 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
5249 {
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05305250 memset(&pHddStaCtx->gtkOffloadReqParams, 0,
5251 sizeof (tSirGtkOffloadParams));
5252 pHddStaCtx->gtkOffloadReqParams.ulFlags = GTK_OFFLOAD_DISABLE;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05305253 }
5254#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005255 pRoamProfile->csrPersona = pAdapter->device_mode;
5256
Jeff Johnson32d95a32012-09-10 13:15:23 -07005257 if( operatingChannel )
5258 {
5259 pRoamProfile->ChannelInfo.ChannelList = &operatingChannel;
5260 pRoamProfile->ChannelInfo.numOfChannels = 1;
5261 }
Chet Lanctot186b5732013-03-18 10:26:30 -07005262 else
5263 {
5264 pRoamProfile->ChannelInfo.ChannelList = NULL;
5265 pRoamProfile->ChannelInfo.numOfChannels = 0;
5266 }
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07005267 if ( (WLAN_HDD_IBSS == pAdapter->device_mode) && operatingChannel)
5268 {
5269 hdd_select_cbmode(pAdapter,operatingChannel);
5270 }
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08005271 /* change conn_state to connecting before sme_RoamConnect(), because sme_RoamConnect()
5272 * has a direct path to call hdd_smeRoamCallback(), which will change the conn_state
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305273 * If direct path, conn_state will be accordingly changed to NotConnected or Associated
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08005274 * by either hdd_AssociationCompletionHandler() or hdd_DisConnectHandler() in sme_RoamCallback()
Madan Mohan Koyyalamudidf86c422012-12-04 17:03:44 -08005275 * if sme_RomConnect is to be queued, Connecting state will remain until it is completed.
5276 */
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +05305277 if (WLAN_HDD_INFRA_STATION == pAdapter->device_mode ||
5278 WLAN_HDD_P2P_CLIENT == pAdapter->device_mode)
Madan Mohan Koyyalamudidf86c422012-12-04 17:03:44 -08005279 hdd_connSetConnectionState(WLAN_HDD_GET_STATION_CTX_PTR(pAdapter),
5280 eConnectionState_Connecting);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305281
5282 status = sme_RoamConnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07005283 pAdapter->sessionId, pRoamProfile, &roamId);
5284
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +05305285 if ((eHAL_STATUS_SUCCESS != status) &&
5286 (WLAN_HDD_INFRA_STATION == pAdapter->device_mode ||
5287 WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
Madan Mohan Koyyalamudid5acbf52012-11-28 01:45:08 +05305288
5289 {
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08005290 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: sme_RoamConnect (session %d) failed with "
5291 "status %d. -> NotConnected", __func__, pAdapter->sessionId, status);
5292 /* change back to NotAssociated */
Madan Mohan Koyyalamudid5acbf52012-11-28 01:45:08 +05305293 hdd_connSetConnectionState(WLAN_HDD_GET_STATION_CTX_PTR(pAdapter),
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08005294 eConnectionState_NotConnected);
Madan Mohan Koyyalamudid5acbf52012-11-28 01:45:08 +05305295 }
Madan Mohan Koyyalamudidf86c422012-12-04 17:03:44 -08005296
5297 pRoamProfile->ChannelInfo.ChannelList = NULL;
5298 pRoamProfile->ChannelInfo.numOfChannels = 0;
5299
Jeff Johnson295189b2012-06-20 16:38:30 -07005300 }
5301 else
5302 {
5303 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: No valid Roam profile", __func__);
5304 return -EINVAL;
5305 }
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08005306 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07005307 return status;
5308}
5309
5310/*
5311 * FUNCTION: wlan_hdd_set_cfg80211_auth_type
5312 * This function is used to set the authentication type (OPEN/SHARED).
5313 *
5314 */
5315static int wlan_hdd_cfg80211_set_auth_type(hdd_adapter_t *pAdapter,
5316 enum nl80211_auth_type auth_type)
5317{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305318 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07005319 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
5320
5321 ENTER();
5322
5323 /*set authentication type*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305324 switch (auth_type)
Jeff Johnson295189b2012-06-20 16:38:30 -07005325 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005326 case NL80211_AUTHTYPE_AUTOMATIC:
Gopichand Nakkala29149562013-05-10 21:43:41 +05305327 hddLog(VOS_TRACE_LEVEL_INFO,
5328 "%s: set authentication type to AUTOSWITCH", __func__);
5329 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_AUTOSWITCH;
5330 break;
5331
5332 case NL80211_AUTHTYPE_OPEN_SYSTEM:
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07005333#ifdef WLAN_FEATURE_VOWIFI_11R
5334 case NL80211_AUTHTYPE_FT:
5335#endif /* WLAN_FEATURE_VOWIFI_11R */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305336 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07005337 "%s: set authentication type to OPEN", __func__);
5338 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
5339 break;
5340
5341 case NL80211_AUTHTYPE_SHARED_KEY:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305342 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07005343 "%s: set authentication type to SHARED", __func__);
5344 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_SHARED_KEY;
5345 break;
5346#ifdef FEATURE_WLAN_CCX
5347 case NL80211_AUTHTYPE_NETWORK_EAP:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305348 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07005349 "%s: set authentication type to CCKM WPA", __func__);
5350 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_CCKM_WPA;//eCSR_AUTH_TYPE_CCKM_RSN needs to be handled as well if required.
5351 break;
5352#endif
5353
5354
5355 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305356 hddLog(VOS_TRACE_LEVEL_ERROR,
5357 "%s: Unsupported authentication type %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07005358 auth_type);
5359 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_UNKNOWN;
5360 return -EINVAL;
5361 }
5362
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305363 pWextState->roamProfile.AuthType.authType[0] =
Jeff Johnson295189b2012-06-20 16:38:30 -07005364 pHddStaCtx->conn_info.authType;
5365 return 0;
5366}
5367
5368/*
5369 * FUNCTION: wlan_hdd_set_akm_suite
5370 * This function is used to set the key mgmt type(PSK/8021x).
5371 *
5372 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305373static int wlan_hdd_set_akm_suite( hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07005374 u32 key_mgmt
5375 )
5376{
5377 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
5378 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305379
Jeff Johnson295189b2012-06-20 16:38:30 -07005380 /*set key mgmt type*/
5381 switch(key_mgmt)
5382 {
5383 case WLAN_AKM_SUITE_PSK:
Gopichand Nakkala356fb102013-03-06 12:34:04 +05305384#ifdef WLAN_FEATURE_VOWIFI_11R
5385 case WLAN_AKM_SUITE_FT_PSK:
5386#endif
5387 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting key mgmt type to PSK",
Jeff Johnson295189b2012-06-20 16:38:30 -07005388 __func__);
5389 pWextState->authKeyMgmt |= IW_AUTH_KEY_MGMT_PSK;
5390 break;
5391
5392 case WLAN_AKM_SUITE_8021X:
Gopichand Nakkala356fb102013-03-06 12:34:04 +05305393#ifdef WLAN_FEATURE_VOWIFI_11R
5394 case WLAN_AKM_SUITE_FT_8021X:
5395#endif
5396 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting key mgmt type to 8021x",
Jeff Johnson295189b2012-06-20 16:38:30 -07005397 __func__);
5398 pWextState->authKeyMgmt |= IW_AUTH_KEY_MGMT_802_1X;
5399 break;
5400#ifdef FEATURE_WLAN_CCX
5401#define WLAN_AKM_SUITE_CCKM 0x00409600 /* Should be in ieee802_11_defs.h */
5402#define IW_AUTH_KEY_MGMT_CCKM 8 /* Should be in linux/wireless.h */
5403 case WLAN_AKM_SUITE_CCKM:
5404 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting key mgmt type to CCKM",
5405 __func__);
5406 pWextState->authKeyMgmt |= IW_AUTH_KEY_MGMT_CCKM;
5407 break;
5408#endif
5409
5410 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305411 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported key mgmt type %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005412 __func__, key_mgmt);
5413 return -EINVAL;
5414
5415 }
5416 return 0;
5417}
5418
5419/*
5420 * FUNCTION: wlan_hdd_cfg80211_set_cipher
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305421 * This function is used to set the encryption type
Jeff Johnson295189b2012-06-20 16:38:30 -07005422 * (NONE/WEP40/WEP104/TKIP/CCMP).
5423 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305424static int wlan_hdd_cfg80211_set_cipher( hdd_adapter_t *pAdapter,
5425 u32 cipher,
Jeff Johnson295189b2012-06-20 16:38:30 -07005426 bool ucast
5427 )
5428{
5429 eCsrEncryptionType encryptionType = eCSR_ENCRYPT_TYPE_NONE;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305430 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07005431 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
5432
5433 ENTER();
5434
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305435 if (!cipher)
Jeff Johnson295189b2012-06-20 16:38:30 -07005436 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305437 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: received cipher %d - considering none",
Jeff Johnson295189b2012-06-20 16:38:30 -07005438 __func__, cipher);
5439 encryptionType = eCSR_ENCRYPT_TYPE_NONE;
5440 }
5441 else
5442 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305443
Jeff Johnson295189b2012-06-20 16:38:30 -07005444 /*set encryption method*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305445 switch (cipher)
Jeff Johnson295189b2012-06-20 16:38:30 -07005446 {
5447 case IW_AUTH_CIPHER_NONE:
5448 encryptionType = eCSR_ENCRYPT_TYPE_NONE;
5449 break;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305450
Jeff Johnson295189b2012-06-20 16:38:30 -07005451 case WLAN_CIPHER_SUITE_WEP40:
Gopichand Nakkala29149562013-05-10 21:43:41 +05305452 encryptionType = eCSR_ENCRYPT_TYPE_WEP40;
Jeff Johnson295189b2012-06-20 16:38:30 -07005453 break;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305454
Jeff Johnson295189b2012-06-20 16:38:30 -07005455 case WLAN_CIPHER_SUITE_WEP104:
Gopichand Nakkala29149562013-05-10 21:43:41 +05305456 encryptionType = eCSR_ENCRYPT_TYPE_WEP104;
Jeff Johnson295189b2012-06-20 16:38:30 -07005457 break;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305458
Jeff Johnson295189b2012-06-20 16:38:30 -07005459 case WLAN_CIPHER_SUITE_TKIP:
5460 encryptionType = eCSR_ENCRYPT_TYPE_TKIP;
5461 break;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305462
Jeff Johnson295189b2012-06-20 16:38:30 -07005463 case WLAN_CIPHER_SUITE_CCMP:
5464 encryptionType = eCSR_ENCRYPT_TYPE_AES;
5465 break;
5466#ifdef FEATURE_WLAN_WAPI
5467 case WLAN_CIPHER_SUITE_SMS4:
5468 encryptionType = eCSR_ENCRYPT_TYPE_WPI;
5469 break;
5470#endif
5471
5472#ifdef FEATURE_WLAN_CCX
5473 case WLAN_CIPHER_SUITE_KRK:
5474 encryptionType = eCSR_ENCRYPT_TYPE_KRK;
5475 break;
5476#endif
5477 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305478 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported cipher type %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005479 __func__, cipher);
5480 return -EOPNOTSUPP;
5481 }
5482 }
5483
5484 if (ucast)
5485 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305486 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting unicast cipher type to %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005487 __func__, encryptionType);
5488 pHddStaCtx->conn_info.ucEncryptionType = encryptionType;
5489 pWextState->roamProfile.EncryptionType.numEntries = 1;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305490 pWextState->roamProfile.EncryptionType.encryptionType[0] =
Jeff Johnson295189b2012-06-20 16:38:30 -07005491 encryptionType;
5492 }
5493 else
5494 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305495 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting mcast cipher type to %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005496 __func__, encryptionType);
5497 pHddStaCtx->conn_info.mcEncryptionType = encryptionType;
5498 pWextState->roamProfile.mcEncryptionType.numEntries = 1;
5499 pWextState->roamProfile.mcEncryptionType.encryptionType[0] = encryptionType;
5500 }
5501
5502 return 0;
5503}
5504
5505
5506/*
5507 * FUNCTION: wlan_hdd_cfg80211_set_ie
5508 * This function is used to parse WPA/RSN IE's.
5509 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305510int wlan_hdd_cfg80211_set_ie( hdd_adapter_t *pAdapter,
5511 u8 *ie,
Jeff Johnson295189b2012-06-20 16:38:30 -07005512 size_t ie_len
5513 )
5514{
5515 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
5516 u8 *genie = ie;
5517 v_U16_t remLen = ie_len;
5518#ifdef FEATURE_WLAN_WAPI
5519 v_U32_t akmsuite[MAX_NUM_AKM_SUITES];
5520 u16 *tmp;
5521 v_U16_t akmsuiteCount;
5522 int *akmlist;
5523#endif
5524 ENTER();
5525
5526 /* clear previous assocAddIE */
5527 pWextState->assocAddIE.length = 0;
5528 pWextState->roamProfile.bWPSAssociation = VOS_FALSE;
5529
5530 while (remLen >= 2)
5531 {
5532 v_U16_t eLen = 0;
5533 v_U8_t elementId;
5534 elementId = *genie++;
5535 eLen = *genie++;
5536 remLen -= 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305537
5538 hddLog(VOS_TRACE_LEVEL_INFO, "%s: IE[0x%X], LEN[%d]\n",
Jeff Johnson295189b2012-06-20 16:38:30 -07005539 __func__, elementId, eLen);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305540
5541 switch ( elementId )
Jeff Johnson295189b2012-06-20 16:38:30 -07005542 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305543 case DOT11F_EID_WPA:
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005544 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 -07005545 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305546 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005547 "%s: Invalid WPA IE", __func__);
5548 return -EINVAL;
5549 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305550 else if (0 == memcmp(&genie[0], "\x00\x50\xf2\x04", 4))
Jeff Johnson295189b2012-06-20 16:38:30 -07005551 {
5552 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305553 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set WPS IE(len %d)",
Jeff Johnson295189b2012-06-20 16:38:30 -07005554 __func__, eLen + 2);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305555
Jeff Johnson295189b2012-06-20 16:38:30 -07005556 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5557 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005558 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE. "
5559 "Need bigger buffer space");
Jeff Johnson295189b2012-06-20 16:38:30 -07005560 VOS_ASSERT(0);
5561 return -ENOMEM;
5562 }
5563 // WSC IE is saved to Additional IE ; it should be accumulated to handle WPS IE + P2P IE
5564 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5565 pWextState->assocAddIE.length += eLen + 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305566
Jeff Johnson295189b2012-06-20 16:38:30 -07005567 pWextState->roamProfile.bWPSAssociation = VOS_TRUE;
5568 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5569 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5570 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305571 else if (0 == memcmp(&genie[0], "\x00\x50\xf2", 3))
5572 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005573 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set WPA IE (len %d)",__func__, eLen + 2);
5574 memset( pWextState->WPARSNIE, 0, MAX_WPA_RSN_IE_LEN );
5575 memcpy( pWextState->WPARSNIE, genie - 2, (eLen + 2) /*ie_len*/);
5576 pWextState->roamProfile.pWPAReqIE = pWextState->WPARSNIE;
5577 pWextState->roamProfile.nWPAReqIELength = eLen + 2;//ie_len;
5578 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305579 else if ( (0 == memcmp(&genie[0], P2P_OUI_TYPE,
5580 P2P_OUI_TYPE_SIZE))
Jeff Johnson295189b2012-06-20 16:38:30 -07005581 /*Consider P2P IE, only for P2P Client */
5582 && (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) )
5583 {
5584 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305585 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set P2P IE(len %d)",
Jeff Johnson295189b2012-06-20 16:38:30 -07005586 __func__, eLen + 2);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305587
Jeff Johnson295189b2012-06-20 16:38:30 -07005588 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5589 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005590 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
5591 "Need bigger buffer space");
Jeff Johnson295189b2012-06-20 16:38:30 -07005592 VOS_ASSERT(0);
5593 return -ENOMEM;
5594 }
5595 // P2P IE is saved to Additional IE ; it should be accumulated to handle WPS IE + P2P IE
5596 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5597 pWextState->assocAddIE.length += eLen + 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305598
Jeff Johnson295189b2012-06-20 16:38:30 -07005599 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5600 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5601 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005602#ifdef WLAN_FEATURE_WFD
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305603 else if ( (0 == memcmp(&genie[0], WFD_OUI_TYPE,
5604 WFD_OUI_TYPE_SIZE))
Jeff Johnson295189b2012-06-20 16:38:30 -07005605 /*Consider WFD IE, only for P2P Client */
5606 && (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) )
5607 {
5608 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305609 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set WFD IE(len %d)",
Jeff Johnson295189b2012-06-20 16:38:30 -07005610 __func__, eLen + 2);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305611
Jeff Johnson295189b2012-06-20 16:38:30 -07005612 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5613 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005614 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
5615 "Need bigger buffer space");
Jeff Johnson295189b2012-06-20 16:38:30 -07005616 VOS_ASSERT(0);
5617 return -ENOMEM;
5618 }
5619 // WFD IE is saved to Additional IE ; it should be accumulated to handle
5620 // WPS IE + P2P IE + WFD IE
5621 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5622 pWextState->assocAddIE.length += eLen + 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305623
Jeff Johnson295189b2012-06-20 16:38:30 -07005624 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5625 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5626 }
5627#endif
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005628 /* Appending HS 2.0 Indication Element in Assiciation Request */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305629 else if ( (0 == memcmp(&genie[0], HS20_OUI_TYPE,
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005630 HS20_OUI_TYPE_SIZE)) )
5631 {
5632 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305633 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set HS20 IE(len %d)",
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005634 __func__, eLen + 2);
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005635
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005636 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5637 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005638 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
5639 "Need bigger buffer space");
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005640 VOS_ASSERT(0);
5641 return -ENOMEM;
5642 }
5643 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5644 pWextState->assocAddIE.length += eLen + 2;
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005645
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005646 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5647 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5648 }
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005649
Praveen Kumar Sirisilla7d68b7b2013-09-22 14:01:42 -07005650 if (WLAN_HDD_IBSS == pAdapter->device_mode) {
5651
5652 /* populating as ADDIE in beacon frames */
5653 if (ccmCfgSetStr(WLAN_HDD_GET_HAL_CTX(pAdapter),
5654 WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA, genie - 2, eLen + 2,
5655 NULL, eANI_BOOLEAN_FALSE)== eHAL_STATUS_SUCCESS)
5656 {
5657 if (ccmCfgSetInt(WLAN_HDD_GET_HAL_CTX(pAdapter),
5658 WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG, 1,NULL,
5659 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
5660 {
5661 hddLog(LOGE,
5662 "Coldn't pass "
5663 "WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG to CCM");
5664 }
5665 }/* ccmCfgSetStr(,WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA, , )*/
5666 else
5667 hddLog(LOGE,
5668 "Could not pass on "
5669 "WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA to CCM");
5670
5671 /* IBSS mode doesn't contain params->proberesp_ies still
5672 beaconIE's need to be populated in probe response frames */
5673 if ( (NULL != (genie - 2)) && (0 != eLen + 2) )
5674 {
5675 u16 rem_probe_resp_ie_len = eLen + 2;
5676 u8 probe_rsp_ie_len[3] = {0};
5677 u8 counter = 0;
5678
5679 /* Check Probe Resp Length if it is greater then 255 then
5680 Store Probe Rsp IEs into WNI_CFG_PROBE_RSP_ADDNIE_DATA1
5681 & WNI_CFG_PROBE_RSP_ADDNIE_DATA2 CFG Variable As We are
5682 not able Store More then 255 bytes into One Variable */
5683
5684 while ((rem_probe_resp_ie_len > 0) && (counter < 3))
5685 {
5686 if (rem_probe_resp_ie_len > MAX_CFG_STRING_LEN)
5687 {
5688 probe_rsp_ie_len[counter++] = MAX_CFG_STRING_LEN;
5689 rem_probe_resp_ie_len -= MAX_CFG_STRING_LEN;
5690 }
5691 else
5692 {
5693 probe_rsp_ie_len[counter++] = rem_probe_resp_ie_len;
5694 rem_probe_resp_ie_len = 0;
5695 }
5696 }
5697
5698 rem_probe_resp_ie_len = 0;
5699
5700 if (probe_rsp_ie_len[0] > 0)
5701 {
5702 if (ccmCfgSetStr(WLAN_HDD_GET_HAL_CTX(pAdapter),
5703 WNI_CFG_PROBE_RSP_ADDNIE_DATA1,
5704 (tANI_U8*)(genie - 2),
5705 probe_rsp_ie_len[0], NULL,
5706 eANI_BOOLEAN_FALSE)
5707 == eHAL_STATUS_FAILURE)
5708 {
5709 hddLog(LOGE,
5710 "Could not pass"
5711 "on WNI_CFG_PROBE_RSP_ADDNIE_DATA1 to CCM");
5712 }
5713 rem_probe_resp_ie_len += probe_rsp_ie_len[0];
5714 }
5715
5716 if (probe_rsp_ie_len[1] > 0)
5717 {
5718 if (ccmCfgSetStr(WLAN_HDD_GET_HAL_CTX(pAdapter),
5719 WNI_CFG_PROBE_RSP_ADDNIE_DATA2,
5720 (tANI_U8*)(genie - (2 + rem_probe_resp_ie_len)),
5721 probe_rsp_ie_len[1], NULL,
5722 eANI_BOOLEAN_FALSE)
5723 == eHAL_STATUS_FAILURE)
5724 {
5725 hddLog(LOGE,
5726 "Could not pass"
5727 "on WNI_CFG_PROBE_RSP_ADDNIE_DATA2 to CCM");
5728 }
5729 rem_probe_resp_ie_len += probe_rsp_ie_len[1];
5730 }
5731
5732 if (probe_rsp_ie_len[2] > 0)
5733 {
5734 if (ccmCfgSetStr(WLAN_HDD_GET_HAL_CTX(pAdapter),
5735 WNI_CFG_PROBE_RSP_ADDNIE_DATA3,
5736 (tANI_U8*)(genie - (2 + rem_probe_resp_ie_len)),
5737 probe_rsp_ie_len[2], NULL,
5738 eANI_BOOLEAN_FALSE)
5739 == eHAL_STATUS_FAILURE)
5740 {
5741 hddLog(LOGE,
5742 "Could not pass"
5743 "on WNI_CFG_PROBE_RSP_ADDNIE_DATA3 to CCM");
5744 }
5745 rem_probe_resp_ie_len += probe_rsp_ie_len[2];
5746 }
5747
5748 if (ccmCfgSetInt(WLAN_HDD_GET_HAL_CTX(pAdapter),
5749 WNI_CFG_PROBE_RSP_ADDNIE_FLAG, 1,NULL,
5750 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
5751 {
5752 hddLog(LOGE,
5753 "Could not pass"
5754 "on WNI_CFG_PROBE_RSP_ADDNIE_FLAG to CCM");
5755 }
5756 }
5757 else
5758 {
5759 // Reset WNI_CFG_PROBE_RSP Flags
5760 wlan_hdd_reset_prob_rspies(pAdapter);
5761
5762 hddLog(VOS_TRACE_LEVEL_INFO,
5763 "%s: No Probe Response IE received in set beacon",
5764 __func__);
5765 }
5766 } /* end of if (WLAN_HDD_IBSS == pAdapter->device_mode) */
Jeff Johnson295189b2012-06-20 16:38:30 -07005767 break;
5768 case DOT11F_EID_RSN:
5769 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set RSN IE(len %d)",__func__, eLen + 2);
5770 memset( pWextState->WPARSNIE, 0, MAX_WPA_RSN_IE_LEN );
5771 memcpy( pWextState->WPARSNIE, genie - 2, (eLen + 2)/*ie_len*/);
5772 pWextState->roamProfile.pRSNReqIE = pWextState->WPARSNIE;
5773 pWextState->roamProfile.nRSNReqIELength = eLen + 2; //ie_len;
5774 break;
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005775 /* Appending Extended Capabilities with Interworking bit set in Assoc Req */
5776 case DOT11F_EID_EXTCAP:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305777 {
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005778 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305779 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set Extended CAPS IE(len %d)",
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005780 __func__, eLen + 2);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305781
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005782 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5783 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005784 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
5785 "Need bigger buffer space");
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005786 VOS_ASSERT(0);
5787 return -ENOMEM;
5788 }
5789 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5790 pWextState->assocAddIE.length += eLen + 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305791
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005792 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5793 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5794 break;
5795 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005796#ifdef FEATURE_WLAN_WAPI
5797 case WLAN_EID_WAPI:
5798 pAdapter->wapi_info.nWapiMode = 1; //Setting WAPI Mode to ON=1
5799 hddLog(VOS_TRACE_LEVEL_INFO,"WAPI MODE IS %lu \n",
5800 pAdapter->wapi_info.nWapiMode);
5801 tmp = (u16 *)ie;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305802 tmp = tmp + 2; // Skip element Id and Len, Version
Jeff Johnson295189b2012-06-20 16:38:30 -07005803 akmsuiteCount = WPA_GET_LE16(tmp);
5804 tmp = tmp + 1;
5805 akmlist = (int *)(tmp);
5806 if(akmsuiteCount <= MAX_NUM_AKM_SUITES)
5807 {
5808 memcpy(akmsuite, akmlist, (4*akmsuiteCount));
5809 }
5810 else
5811 {
5812 hddLog(VOS_TRACE_LEVEL_FATAL, "Invalid akmSuite count\n");
5813 VOS_ASSERT(0);
5814 return -EINVAL;
5815 }
5816
5817 if (WAPI_PSK_AKM_SUITE == akmsuite[0])
5818 {
5819 hddLog(VOS_TRACE_LEVEL_INFO, "%s: WAPI AUTH MODE SET TO PSK",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005820 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005821 pAdapter->wapi_info.wapiAuthMode = WAPI_AUTH_MODE_PSK;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305822 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005823 if (WAPI_CERT_AKM_SUITE == akmsuite[0])
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305824 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005825 hddLog(VOS_TRACE_LEVEL_INFO, "%s: WAPI AUTH MODE SET TO CERTIFICATE",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005826 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005827 pAdapter->wapi_info.wapiAuthMode = WAPI_AUTH_MODE_CERT;
5828 }
5829 break;
5830#endif
5831 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305832 hddLog (VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005833 "%s Set UNKNOWN IE %X", __func__, elementId);
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005834 /* when Unknown IE is received we should break and continue
5835 * to the next IE in the buffer instead we were returning
5836 * so changing this to break */
5837 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07005838 }
5839 genie += eLen;
5840 remLen -= eLen;
5841 }
5842 EXIT();
5843 return 0;
5844}
5845
5846/*
Gopichand Nakkala18f0c262013-05-07 23:25:08 +05305847 * FUNCTION: hdd_isWPAIEPresent
5848 * Parse the received IE to find the WPA IE
5849 *
5850 */
5851static bool hdd_isWPAIEPresent(u8 *ie, u8 ie_len)
5852{
5853 v_U8_t eLen = 0;
5854 v_U16_t remLen = ie_len;
5855 v_U8_t elementId = 0;
5856
5857 while (remLen >= 2)
5858 {
5859 elementId = *ie++;
5860 eLen = *ie++;
5861 remLen -= 2;
5862 if (eLen > remLen)
5863 {
5864 hddLog(VOS_TRACE_LEVEL_ERROR,
5865 "%s: IE length is wrong %d", __func__, eLen);
5866 return FALSE;
5867 }
5868 if ((elementId == DOT11F_EID_WPA) && (remLen > 5))
5869 {
5870 /* OUI - 0x00 0X50 0XF2
5871 WPA Information Element - 0x01
5872 WPA version - 0x01*/
5873 if (0 == memcmp(&ie[0], "\x00\x50\xf2\x01\x01", 5))
5874 return TRUE;
5875 }
5876 ie += eLen;
5877 remLen -= eLen;
5878 }
5879 return FALSE;
5880}
5881
5882/*
Jeff Johnson295189b2012-06-20 16:38:30 -07005883 * FUNCTION: wlan_hdd_cfg80211_set_privacy
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305884 * This function is used to initialize the security
Jeff Johnson295189b2012-06-20 16:38:30 -07005885 * parameters during connect operation.
5886 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305887int wlan_hdd_cfg80211_set_privacy( hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07005888 struct cfg80211_connect_params *req
5889 )
5890{
5891 int status = 0;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305892 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07005893 ENTER();
5894
5895 /*set wpa version*/
5896 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_DISABLED;
5897
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305898 if (req->crypto.wpa_versions)
Jeff Johnson295189b2012-06-20 16:38:30 -07005899 {
Gopichand Nakkala781ded42013-06-28 12:10:45 +05305900 if (NL80211_WPA_VERSION_1 == req->crypto.wpa_versions)
Jeff Johnson295189b2012-06-20 16:38:30 -07005901 {
5902 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA;
5903 }
5904 else if (NL80211_WPA_VERSION_2 == req->crypto.wpa_versions)
5905 {
5906 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA2;
5907 }
5908 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305909
5910 hddLog(VOS_TRACE_LEVEL_INFO, "%s: set wpa version to %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07005911 pWextState->wpaVersion);
5912
5913 /*set authentication type*/
5914 status = wlan_hdd_cfg80211_set_auth_type(pAdapter, req->auth_type);
5915
5916 if (0 > status)
5917 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305918 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005919 "%s: failed to set authentication type ", __func__);
5920 return status;
5921 }
5922
5923 /*set key mgmt type*/
5924 if (req->crypto.n_akm_suites)
5925 {
5926 status = wlan_hdd_set_akm_suite(pAdapter, req->crypto.akm_suites[0]);
5927 if (0 > status)
5928 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305929 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set akm suite",
Jeff Johnson295189b2012-06-20 16:38:30 -07005930 __func__);
5931 return status;
5932 }
5933 }
5934
5935 /*set pairwise cipher type*/
5936 if (req->crypto.n_ciphers_pairwise)
5937 {
5938 status = wlan_hdd_cfg80211_set_cipher(pAdapter,
5939 req->crypto.ciphers_pairwise[0], true);
5940 if (0 > status)
5941 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305942 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005943 "%s: failed to set unicast cipher type", __func__);
5944 return status;
5945 }
5946 }
5947 else
5948 {
5949 /*Reset previous cipher suite to none*/
5950 status = wlan_hdd_cfg80211_set_cipher(pAdapter, 0, true);
5951 if (0 > status)
5952 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305953 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005954 "%s: failed to set unicast cipher type", __func__);
5955 return status;
5956 }
5957 }
5958
5959 /*set group cipher type*/
5960 status = wlan_hdd_cfg80211_set_cipher(pAdapter, req->crypto.cipher_group,
5961 false);
5962
5963 if (0 > status)
5964 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305965 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set mcast cipher type",
Jeff Johnson295189b2012-06-20 16:38:30 -07005966 __func__);
5967 return status;
5968 }
5969
Chet Lanctot186b5732013-03-18 10:26:30 -07005970#ifdef WLAN_FEATURE_11W
5971 pWextState->roamProfile.MFPEnabled = (req->mfp == NL80211_MFP_REQUIRED);
5972#endif
5973
Jeff Johnson295189b2012-06-20 16:38:30 -07005974 /*parse WPA/RSN IE, and set the correspoing fileds in Roam profile*/
5975 if (req->ie_len)
5976 {
5977 status = wlan_hdd_cfg80211_set_ie(pAdapter, req->ie, req->ie_len);
5978 if ( 0 > status)
5979 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305980 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to parse the WPA/RSN IE",
Jeff Johnson295189b2012-06-20 16:38:30 -07005981 __func__);
5982 return status;
5983 }
5984 }
5985
5986 /*incase of WEP set default key information*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305987 if (req->key && req->key_len)
Jeff Johnson295189b2012-06-20 16:38:30 -07005988 {
5989 if ( (WLAN_CIPHER_SUITE_WEP40 == req->crypto.ciphers_pairwise[0])
5990 || (WLAN_CIPHER_SUITE_WEP104 == req->crypto.ciphers_pairwise[0])
5991 )
5992 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305993 if ( IW_AUTH_KEY_MGMT_802_1X
Jeff Johnson295189b2012-06-20 16:38:30 -07005994 == (pWextState->authKeyMgmt & IW_AUTH_KEY_MGMT_802_1X ))
5995 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305996 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Dynamic WEP not supported",
Jeff Johnson295189b2012-06-20 16:38:30 -07005997 __func__);
5998 return -EOPNOTSUPP;
5999 }
6000 else
6001 {
6002 u8 key_len = req->key_len;
6003 u8 key_idx = req->key_idx;
6004
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306005 if ((eCSR_SECURITY_WEP_KEYSIZE_MAX_BYTES >= key_len)
Jeff Johnson295189b2012-06-20 16:38:30 -07006006 && (CSR_MAX_NUM_KEY > key_idx)
6007 )
6008 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306009 hddLog(VOS_TRACE_LEVEL_INFO,
6010 "%s: setting default wep key, key_idx = %hu key_len %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006011 __func__, key_idx, key_len);
6012 vos_mem_copy(
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306013 &pWextState->roamProfile.Keys.KeyMaterial[key_idx][0],
Jeff Johnson295189b2012-06-20 16:38:30 -07006014 req->key, key_len);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306015 pWextState->roamProfile.Keys.KeyLength[key_idx] =
Jeff Johnson295189b2012-06-20 16:38:30 -07006016 (u8)key_len;
6017 pWextState->roamProfile.Keys.defaultIndex = (u8)key_idx;
6018 }
6019 }
6020 }
6021 }
6022
6023 return status;
6024}
6025
6026/*
6027 * FUNCTION: wlan_hdd_cfg80211_set_privacy
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306028 * This function is used to initialize the security
Jeff Johnson295189b2012-06-20 16:38:30 -07006029 * parameters during connect operation.
6030 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306031static int wlan_hdd_cfg80211_connect( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07006032 struct net_device *ndev,
6033 struct cfg80211_connect_params *req
6034 )
6035{
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306036 int status;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306037 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Jeff Johnson295189b2012-06-20 16:38:30 -07006038 VOS_STATUS exitbmpsStatus = VOS_STATUS_E_INVAL;
6039 hdd_context_t *pHddCtx = NULL;
6040
6041 ENTER();
6042
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306043 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07006044 "%s: device_mode = %d\n",__func__,pAdapter->device_mode);
6045
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306046 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
6047 status = wlan_hdd_validate_context(pHddCtx);
6048
6049 if (0 != status)
Jeff Johnson295189b2012-06-20 16:38:30 -07006050 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306051 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6052 "%s: HDD context is not valid", __func__);
6053 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006054 }
6055
6056#ifdef WLAN_BTAMP_FEATURE
6057 //Infra connect not supported when AMP traffic is on.
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306058 if( VOS_TRUE == WLANBAP_AmpSessionOn() )
Jeff Johnson295189b2012-06-20 16:38:30 -07006059 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306060 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07006061 "%s: No connection when AMP is on", __func__);
Madan Mohan Koyyalamudicae253a2012-11-06 19:10:35 -08006062 return -ECONNREFUSED;
Jeff Johnson295189b2012-06-20 16:38:30 -07006063 }
6064#endif
6065 /*initialise security parameters*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306066 status = wlan_hdd_cfg80211_set_privacy(pAdapter, req);
Jeff Johnson295189b2012-06-20 16:38:30 -07006067
6068 if ( 0 > status)
6069 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306070 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set security params",
Jeff Johnson295189b2012-06-20 16:38:30 -07006071 __func__);
6072 return status;
6073 }
6074
6075 //If Device Mode is Station Concurrent Sessions Exit BMps
Jeff Johnsona8a1a482012-12-12 16:49:33 -08006076 //P2P Mode will be taken care in Open/close adapter
Jeff Johnson295189b2012-06-20 16:38:30 -07006077 if((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) &&
6078 (vos_concurrent_sessions_running()))
6079 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306080 exitbmpsStatus = hdd_disable_bmps_imps(pHddCtx, WLAN_HDD_INFRA_STATION);
Jeff Johnson295189b2012-06-20 16:38:30 -07006081 }
6082
Mohit Khanna765234a2012-09-11 15:08:35 -07006083 if ( req->channel )
6084 {
6085 status = wlan_hdd_cfg80211_connect_start(pAdapter, req->ssid,
6086 req->ssid_len, req->bssid,
6087 req->channel->hw_value);
6088 }
6089 else
6090 {
6091 status = wlan_hdd_cfg80211_connect_start(pAdapter, req->ssid,
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306092 req->ssid_len, req->bssid, 0);
Mohit Khanna765234a2012-09-11 15:08:35 -07006093 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006094
6095 if (0 > status)
6096 {
6097 //ReEnable BMPS if disabled
6098 if((VOS_STATUS_SUCCESS == exitbmpsStatus) &&
6099 (NULL != pHddCtx))
6100 {
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05306101 if (pHddCtx->hdd_wlan_suspended)
6102 {
6103 hdd_set_pwrparams(pHddCtx);
6104 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006105 //ReEnable Bmps and Imps back
6106 hdd_enable_bmps_imps(pHddCtx);
6107 }
6108
6109 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: connect failed", __func__);
6110 return status;
6111 }
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306112 pHddCtx->isAmpAllowed = VOS_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006113 EXIT();
6114 return status;
6115}
6116
6117
6118/*
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306119 * FUNCTION: wlan_hdd_disconnect
6120 * This function is used to issue a disconnect request to SME
6121 */
6122int wlan_hdd_disconnect( hdd_adapter_t *pAdapter, u16 reason )
6123{
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306124 int status;
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306125 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306126 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
6127
6128 status = wlan_hdd_validate_context(pHddCtx);
6129
6130 if (0 != status)
6131 {
6132 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6133 "%s: HDD context is not valid", __func__);
6134 return status;
6135 }
6136
6137 pHddCtx->isAmpAllowed = VOS_TRUE;
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306138 pHddStaCtx->conn_info.connState = eConnectionState_NotConnected;
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306139 INIT_COMPLETION(pAdapter->disconnect_comp_var);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306140
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306141 /*issue disconnect*/
6142 status = sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
6143 pAdapter->sessionId, reason);
6144
6145 if ( 0 != status )
6146 {
6147 hddLog(VOS_TRACE_LEVEL_ERROR,
6148 "%s csrRoamDisconnect failure, returned %d \n",
6149 __func__, (int)status );
6150 return -EINVAL;
6151 }
6152 wait_for_completion_interruptible_timeout(
6153 &pAdapter->disconnect_comp_var,
6154 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
6155 /*stop tx queues*/
6156 netif_tx_disable(pAdapter->dev);
6157 netif_carrier_off(pAdapter->dev);
6158 return status;
6159}
6160
6161
6162/*
Jeff Johnson295189b2012-06-20 16:38:30 -07006163 * FUNCTION: wlan_hdd_cfg80211_disconnect
6164 * This function is used to issue a disconnect request to SME
6165 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306166static int wlan_hdd_cfg80211_disconnect( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07006167 struct net_device *dev,
6168 u16 reason
6169 )
6170{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306171 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
6172 tCsrRoamProfile *pRoamProfile =
Jeff Johnson295189b2012-06-20 16:38:30 -07006173 &(WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter))->roamProfile;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306174 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006175 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006176 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05306177#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006178 tANI_U8 staIdx;
6179#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306180
Jeff Johnson295189b2012-06-20 16:38:30 -07006181 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306182
6183 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
Jeff Johnson295189b2012-06-20 16:38:30 -07006184 __func__,pAdapter->device_mode);
6185
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306186 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Disconnect called with reason code %d",
6187 __func__, reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07006188
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306189 status = wlan_hdd_validate_context(pHddCtx);
6190
6191 if (0 != status)
Jeff Johnson295189b2012-06-20 16:38:30 -07006192 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306193 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6194 "%s: HDD context is not valid", __func__);
6195 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006196 }
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306197
Jeff Johnson295189b2012-06-20 16:38:30 -07006198 if (NULL != pRoamProfile)
6199 {
6200 /*issue disconnect request to SME, if station is in connected state*/
6201 if (pHddStaCtx->conn_info.connState == eConnectionState_Associated)
6202 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306203 eCsrRoamDisconnectReason reasonCode =
Jeff Johnson295189b2012-06-20 16:38:30 -07006204 eCSR_DISCONNECT_REASON_UNSPECIFIED;
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05306205 hdd_scaninfo_t *pScanInfo;
Jeff Johnson295189b2012-06-20 16:38:30 -07006206 switch(reason)
6207 {
6208 case WLAN_REASON_MIC_FAILURE:
6209 reasonCode = eCSR_DISCONNECT_REASON_MIC_ERROR;
6210 break;
6211
6212 case WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY:
6213 case WLAN_REASON_DISASSOC_AP_BUSY:
6214 case WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA:
6215 reasonCode = eCSR_DISCONNECT_REASON_DISASSOC;
6216 break;
6217
6218 case WLAN_REASON_PREV_AUTH_NOT_VALID:
6219 case WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA:
6220 reasonCode = eCSR_DISCONNECT_REASON_DEAUTH;
6221 break;
6222
6223 case WLAN_REASON_DEAUTH_LEAVING:
6224 default:
6225 reasonCode = eCSR_DISCONNECT_REASON_UNSPECIFIED;
6226 break;
6227 }
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05306228 pHddStaCtx->conn_info.connState = eConnectionState_NotConnected;
6229 pScanInfo = &pHddCtx->scan_info;
6230 if (pScanInfo->mScanPending)
6231 {
6232 hddLog(VOS_TRACE_LEVEL_INFO, "Disconnect is in progress, "
6233 "Aborting Scan");
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05306234 hdd_abort_mac_scan(pHddCtx, pAdapter->sessionId);
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05306235 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006236
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006237#ifdef FEATURE_WLAN_TDLS
6238 /* First clean up the tdls peers if any */
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006239 for (staIdx = 0 ; staIdx < HDD_MAX_NUM_TDLS_STA; staIdx++)
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006240 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006241 if ((pHddCtx->tdlsConnInfo[staIdx].sessionId == pAdapter->sessionId) &&
6242 (pHddCtx->tdlsConnInfo[staIdx].staId))
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006243 {
Hoonki Lee11f7dda2013-02-14 16:55:44 -08006244 uint8 *mac;
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006245 mac = pHddCtx->tdlsConnInfo[staIdx].peerMac.bytes;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08006246 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07006247 "%s: call sme_DeleteTdlsPeerSta staId %d sessionId %d " MAC_ADDRESS_STR,
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006248 __func__, pHddCtx->tdlsConnInfo[staIdx].staId, pAdapter->sessionId,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07006249 MAC_ADDR_ARRAY(mac));
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006250 sme_DeleteTdlsPeerSta(WLAN_HDD_GET_HAL_CTX(pAdapter),
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006251 pAdapter->sessionId,
6252 mac);
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006253 }
6254 }
6255#endif
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306256 status = wlan_hdd_disconnect(pAdapter, reasonCode);
6257 if ( 0 != status )
Jeff Johnson295189b2012-06-20 16:38:30 -07006258 {
6259 hddLog(VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306260 "%s wlan_hdd_disconnect failure, returned %d \n",
Jeff Johnson295189b2012-06-20 16:38:30 -07006261 __func__, (int)status );
6262 return -EINVAL;
6263 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006264 }
6265 }
6266 else
6267 {
6268 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: No valid roam profile", __func__);
6269 }
6270
6271 return status;
6272}
6273
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306274
Jeff Johnson295189b2012-06-20 16:38:30 -07006275/*
6276 * FUNCTION: wlan_hdd_cfg80211_set_privacy_ibss
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306277 * This function is used to initialize the security
Jeff Johnson295189b2012-06-20 16:38:30 -07006278 * settings in IBSS mode.
6279 */
6280static int wlan_hdd_cfg80211_set_privacy_ibss(
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306281 hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07006282 struct cfg80211_ibss_params *params
6283 )
6284{
6285 int status = 0;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306286 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07006287 eCsrEncryptionType encryptionType = eCSR_ENCRYPT_TYPE_NONE;
6288 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306289
Jeff Johnson295189b2012-06-20 16:38:30 -07006290 ENTER();
6291
6292 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_DISABLED;
6293
6294 if (params->ie_len && ( NULL != params->ie) )
6295 {
Shailender Karmuchi67edd312013-06-18 16:30:48 -07006296 if (wlan_hdd_cfg80211_get_ie_ptr (params->ie,
6297 params->ie_len, WLAN_EID_RSN ))
Jeff Johnson295189b2012-06-20 16:38:30 -07006298 {
6299 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA2;
6300 encryptionType = eCSR_ENCRYPT_TYPE_AES;
6301 }
Shailender Karmuchi67edd312013-06-18 16:30:48 -07006302 else if ( hdd_isWPAIEPresent (params->ie, params->ie_len ))
Jeff Johnson295189b2012-06-20 16:38:30 -07006303 {
Shailender Karmuchi642e9812013-05-30 14:34:49 -07006304 tDot11fIEWPA dot11WPAIE;
6305 tHalHandle halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
Shailender Karmuchi67edd312013-06-18 16:30:48 -07006306 u8 *ie;
Shailender Karmuchi642e9812013-05-30 14:34:49 -07006307
Wilson Yang00256342013-10-10 23:13:38 -07006308 memset(&dot11WPAIE, 0, sizeof(dot11WPAIE));
Shailender Karmuchi67edd312013-06-18 16:30:48 -07006309 ie = wlan_hdd_cfg80211_get_ie_ptr (params->ie,
6310 params->ie_len, DOT11F_EID_WPA);
6311 if ( NULL != ie )
6312 {
6313 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA;
6314 // Unpack the WPA IE
6315 //Skip past the EID byte and length byte - and four byte WiFi OUI
6316 dot11fUnpackIeWPA((tpAniSirGlobal) halHandle,
6317 &ie[2+4],
6318 ie[1] - 4,
6319 &dot11WPAIE);
6320 /*Extract the multicast cipher, the encType for unicast
6321 cipher for wpa-none is none*/
6322 encryptionType =
6323 hdd_TranslateWPAToCsrEncryptionType(dot11WPAIE.multicast_cipher);
6324 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006325 }
Shailender Karmuchi67edd312013-06-18 16:30:48 -07006326
Jeff Johnson295189b2012-06-20 16:38:30 -07006327 status = wlan_hdd_cfg80211_set_ie(pAdapter, params->ie, params->ie_len);
6328
6329 if (0 > status)
6330 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306331 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to parse WPA/RSN IE",
Jeff Johnson295189b2012-06-20 16:38:30 -07006332 __func__);
6333 return status;
6334 }
6335 }
6336
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306337 pWextState->roamProfile.AuthType.authType[0] =
6338 pHddStaCtx->conn_info.authType =
Jeff Johnson295189b2012-06-20 16:38:30 -07006339 eCSR_AUTH_TYPE_OPEN_SYSTEM;
6340
6341 if (params->privacy)
6342 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306343 /* Security enabled IBSS, At this time there is no information available
6344 * about the security paramters, so initialise the encryption type to
Jeff Johnson295189b2012-06-20 16:38:30 -07006345 * eCSR_ENCRYPT_TYPE_WEP40_STATICKEY.
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306346 * The correct security parameters will be updated later in
Jeff Johnson295189b2012-06-20 16:38:30 -07006347 * wlan_hdd_cfg80211_add_key */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306348 /* Hal expects encryption type to be set inorder
Jeff Johnson295189b2012-06-20 16:38:30 -07006349 *enable privacy bit in beacons */
6350
6351 encryptionType = eCSR_ENCRYPT_TYPE_WEP40_STATICKEY;
6352 }
Shailender Karmuchi642e9812013-05-30 14:34:49 -07006353 VOS_TRACE (VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
6354 "encryptionType=%d", encryptionType);
Jeff Johnson295189b2012-06-20 16:38:30 -07006355 pHddStaCtx->conn_info.ucEncryptionType = encryptionType;
6356 pWextState->roamProfile.EncryptionType.numEntries = 1;
6357 pWextState->roamProfile.EncryptionType.encryptionType[0] = encryptionType;
Jeff Johnson295189b2012-06-20 16:38:30 -07006358 return status;
6359}
6360
6361/*
6362 * FUNCTION: wlan_hdd_cfg80211_join_ibss
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306363 * This function is used to create/join an IBSS
Jeff Johnson295189b2012-06-20 16:38:30 -07006364 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306365static int wlan_hdd_cfg80211_join_ibss( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07006366 struct net_device *dev,
6367 struct cfg80211_ibss_params *params
6368 )
6369{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306370 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Jeff Johnson295189b2012-06-20 16:38:30 -07006371 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
6372 tCsrRoamProfile *pRoamProfile;
6373 int status;
6374 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306375 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07006376
6377 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306378
6379 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07006380 "%s: device_mode = %d\n",__func__,pAdapter->device_mode);
6381
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306382 status = wlan_hdd_validate_context(pHddCtx);
6383
6384 if (0 != status)
Jeff Johnson295189b2012-06-20 16:38:30 -07006385 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306386 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6387 "%s: HDD context is not valid", __func__);
6388 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006389 }
6390
6391 if (NULL == pWextState)
6392 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306393 hddLog (VOS_TRACE_LEVEL_ERROR, "%s ERROR: Data Storage Corruption\n",
Jeff Johnson295189b2012-06-20 16:38:30 -07006394 __func__);
6395 return -EIO;
6396 }
6397
6398 pRoamProfile = &pWextState->roamProfile;
6399
6400 if ( eCSR_BSS_TYPE_START_IBSS != pRoamProfile->BSSType )
6401 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306402 hddLog (VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07006403 "%s Interface type is not set to IBSS \n", __func__);
6404 return -EINVAL;
6405 }
6406
6407 /* Set Channel */
Yue Maf49ba872013-08-19 12:04:25 -07006408 if (NULL !=
6409#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0))
6410 params->chandef.chan)
6411#else
6412 params->channel)
6413#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006414 {
6415 u8 channelNum;
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006416 v_U32_t numChans = WNI_CFG_VALID_CHANNEL_LIST_LEN;
6417 v_U8_t validChan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
6418 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
6419 int indx;
Jeff Johnson295189b2012-06-20 16:38:30 -07006420
6421 /* Get channel number */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306422 channelNum =
Yue Maf49ba872013-08-19 12:04:25 -07006423 ieee80211_frequency_to_channel(
6424#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0))
6425 params->chandef.chan->center_freq);
6426#else
6427 params->channel->center_freq);
6428#endif
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006429
6430 if (0 != ccmCfgGetStr(hHal, WNI_CFG_VALID_CHANNEL_LIST,
6431 validChan, &numChans))
Jeff Johnson295189b2012-06-20 16:38:30 -07006432 {
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006433 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: No valid channel list",
6434 __func__);
6435 return -EOPNOTSUPP;
Jeff Johnson295189b2012-06-20 16:38:30 -07006436 }
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006437
6438 for (indx = 0; indx < numChans; indx++)
Jeff Johnson295189b2012-06-20 16:38:30 -07006439 {
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006440 if (channelNum == validChan[indx])
6441 {
6442 break;
6443 }
6444 }
6445 if (indx >= numChans)
6446 {
6447 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Not valid Channel %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07006448 __func__, channelNum);
6449 return -EINVAL;
6450 }
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006451 /* Set the Operational Channel */
6452 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: set channel %d", __func__,
6453 channelNum);
6454 pRoamProfile->ChannelInfo.numOfChannels = 1;
6455 pHddStaCtx->conn_info.operationChannel = channelNum;
6456 pRoamProfile->ChannelInfo.ChannelList =
6457 &pHddStaCtx->conn_info.operationChannel;
Jeff Johnson295189b2012-06-20 16:38:30 -07006458 }
6459
6460 /* Initialize security parameters */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306461 status = wlan_hdd_cfg80211_set_privacy_ibss(pAdapter, params);
Jeff Johnson295189b2012-06-20 16:38:30 -07006462 if (status < 0)
6463 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306464 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set security parameters",
Jeff Johnson295189b2012-06-20 16:38:30 -07006465 __func__);
6466 return status;
6467 }
6468
6469 /* Issue connect start */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306470 status = wlan_hdd_cfg80211_connect_start(pAdapter, params->ssid,
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006471 params->ssid_len, params->bssid,
6472 pHddStaCtx->conn_info.operationChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07006473
6474 if (0 > status)
6475 {
6476 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: connect failed", __func__);
6477 return status;
6478 }
6479
6480 return 0;
6481}
6482
6483/*
6484 * FUNCTION: wlan_hdd_cfg80211_leave_ibss
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306485 * This function is used to leave an IBSS
Jeff Johnson295189b2012-06-20 16:38:30 -07006486 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306487static int wlan_hdd_cfg80211_leave_ibss( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07006488 struct net_device *dev
6489 )
6490{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306491 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Jeff Johnson295189b2012-06-20 16:38:30 -07006492 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
6493 tCsrRoamProfile *pRoamProfile;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306494 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
6495 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006496
6497 ENTER();
6498
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306499 status = wlan_hdd_validate_context(pHddCtx);
6500
6501 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006502 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306503 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6504 "%s: HDD context is not valid", __func__);
6505 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006506 }
6507
Jeff Johnson295189b2012-06-20 16:38:30 -07006508 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",__func__,pAdapter->device_mode);
6509 if (NULL == pWextState)
6510 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306511 hddLog (VOS_TRACE_LEVEL_ERROR, "%s ERROR: Data Storage Corruption\n",
Jeff Johnson295189b2012-06-20 16:38:30 -07006512 __func__);
6513 return -EIO;
6514 }
6515
6516 pRoamProfile = &pWextState->roamProfile;
6517
6518 /* Issue disconnect only if interface type is set to IBSS */
6519 if (eCSR_BSS_TYPE_START_IBSS != pRoamProfile->BSSType)
6520 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306521 hddLog (VOS_TRACE_LEVEL_ERROR, "%s: BSS Type is not set to IBSS",
Jeff Johnson295189b2012-06-20 16:38:30 -07006522 __func__);
6523 return -EINVAL;
6524 }
6525
6526 /* Issue Disconnect request */
6527 INIT_COMPLETION(pAdapter->disconnect_comp_var);
6528 sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter), pAdapter->sessionId,
6529 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
6530
6531 return 0;
6532}
6533
6534/*
6535 * FUNCTION: wlan_hdd_cfg80211_set_wiphy_params
6536 * This function is used to set the phy parameters
6537 * (RTS Threshold/FRAG Threshold/Retry Count etc ...)
6538 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306539static int wlan_hdd_cfg80211_set_wiphy_params(struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07006540 u32 changed)
6541{
6542 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
6543 tHalHandle hHal = pHddCtx->hHal;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306544 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006545
6546 ENTER();
6547
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306548 status = wlan_hdd_validate_context(pHddCtx);
6549
6550 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006551 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306552 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6553 "%s: HDD context is not valid", __func__);
6554 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006555 }
6556
Jeff Johnson295189b2012-06-20 16:38:30 -07006557 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
6558 {
6559 u16 rts_threshold = (wiphy->rts_threshold == -1) ?
6560 WNI_CFG_RTS_THRESHOLD_STAMAX :
6561 wiphy->rts_threshold;
6562
6563 if ((WNI_CFG_RTS_THRESHOLD_STAMIN > rts_threshold) ||
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306564 (WNI_CFG_RTS_THRESHOLD_STAMAX < rts_threshold))
Jeff Johnson295189b2012-06-20 16:38:30 -07006565 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306566 hddLog(VOS_TRACE_LEVEL_ERROR,
6567 "%s: Invalid RTS Threshold value %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006568 __func__, rts_threshold);
6569 return -EINVAL;
6570 }
6571
6572 if (0 != ccmCfgSetInt(hHal, WNI_CFG_RTS_THRESHOLD,
6573 rts_threshold, ccmCfgSetCallback,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306574 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07006575 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306576 hddLog(VOS_TRACE_LEVEL_ERROR,
6577 "%s: ccmCfgSetInt failed for rts_threshold value %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006578 __func__, rts_threshold);
6579 return -EIO;
6580 }
6581
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306582 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set rts threshold %hu", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07006583 rts_threshold);
6584 }
6585
6586 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
6587 {
6588 u16 frag_threshold = (wiphy->frag_threshold == -1) ?
6589 WNI_CFG_FRAGMENTATION_THRESHOLD_STAMAX :
6590 wiphy->frag_threshold;
6591
6592 if ((WNI_CFG_FRAGMENTATION_THRESHOLD_STAMIN > frag_threshold)||
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306593 (WNI_CFG_FRAGMENTATION_THRESHOLD_STAMAX < frag_threshold) )
Jeff Johnson295189b2012-06-20 16:38:30 -07006594 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306595 hddLog(VOS_TRACE_LEVEL_ERROR,
6596 "%s: Invalid frag_threshold value %hu", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07006597 frag_threshold);
6598 return -EINVAL;
6599 }
6600
6601 if (0 != ccmCfgSetInt(hHal, WNI_CFG_FRAGMENTATION_THRESHOLD,
6602 frag_threshold, ccmCfgSetCallback,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306603 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07006604 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306605 hddLog(VOS_TRACE_LEVEL_ERROR,
6606 "%s: ccmCfgSetInt failed for frag_threshold value %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006607 __func__, frag_threshold);
6608 return -EIO;
6609 }
6610
6611 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set frag threshold %hu", __func__,
6612 frag_threshold);
6613 }
6614
6615 if ((changed & WIPHY_PARAM_RETRY_SHORT)
6616 || (changed & WIPHY_PARAM_RETRY_LONG))
6617 {
6618 u8 retry_value = (changed & WIPHY_PARAM_RETRY_SHORT) ?
6619 wiphy->retry_short :
6620 wiphy->retry_long;
6621
6622 if ((WNI_CFG_LONG_RETRY_LIMIT_STAMIN > retry_value) ||
6623 (WNI_CFG_LONG_RETRY_LIMIT_STAMAX < retry_value))
6624 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306625 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006626 __func__, retry_value);
6627 return -EINVAL;
6628 }
6629
6630 if (changed & WIPHY_PARAM_RETRY_SHORT)
6631 {
6632 if (0 != ccmCfgSetInt(hHal, WNI_CFG_LONG_RETRY_LIMIT,
6633 retry_value, ccmCfgSetCallback,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306634 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07006635 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306636 hddLog(VOS_TRACE_LEVEL_ERROR,
6637 "%s: ccmCfgSetInt failed for long retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006638 __func__, retry_value);
6639 return -EIO;
6640 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306641 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set long retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006642 __func__, retry_value);
6643 }
6644 else if (changed & WIPHY_PARAM_RETRY_SHORT)
6645 {
6646 if (0 != ccmCfgSetInt(hHal, WNI_CFG_SHORT_RETRY_LIMIT,
6647 retry_value, ccmCfgSetCallback,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306648 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07006649 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306650 hddLog(VOS_TRACE_LEVEL_ERROR,
6651 "%s: ccmCfgSetInt failed for short retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006652 __func__, retry_value);
6653 return -EIO;
6654 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306655 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set short retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006656 __func__, retry_value);
6657 }
6658 }
6659
6660 return 0;
6661}
6662
6663/*
6664 * FUNCTION: wlan_hdd_cfg80211_set_txpower
6665 * This function is used to set the txpower
6666 */
6667static int wlan_hdd_cfg80211_set_txpower(struct wiphy *wiphy,
Yue Maf49ba872013-08-19 12:04:25 -07006668#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0)
6669 struct wireless_dev *wdev,
6670#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006671#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,35)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306672 enum tx_power_setting type,
Jeff Johnson295189b2012-06-20 16:38:30 -07006673#else
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306674 enum nl80211_tx_power_setting type,
Jeff Johnson295189b2012-06-20 16:38:30 -07006675#endif
6676 int dbm)
6677{
6678 hdd_context_t *pHddCtx = (hdd_context_t*) wiphy_priv(wiphy);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306679 tHalHandle hHal = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07006680 tSirMacAddr bssid = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
6681 tSirMacAddr selfMac = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306682 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006683
6684 ENTER();
6685
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306686 status = wlan_hdd_validate_context(pHddCtx);
6687
6688 if (0 != status)
6689 {
6690 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6691 "%s: HDD context is not valid", __func__);
6692 return status;
6693 }
6694
6695 hHal = pHddCtx->hHal;
6696
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306697 if (0 != ccmCfgSetInt(hHal, WNI_CFG_CURRENT_TX_POWER_LEVEL,
6698 dbm, ccmCfgSetCallback,
6699 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07006700 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306701 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07006702 "%s: ccmCfgSetInt failed for tx power %hu", __func__, dbm);
6703 return -EIO;
6704 }
6705
6706 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set tx power level %d dbm", __func__,
6707 dbm);
6708
6709 switch(type)
6710 {
6711 case NL80211_TX_POWER_AUTOMATIC: /*automatically determine transmit power*/
6712 /* Fall through */
6713 case NL80211_TX_POWER_LIMITED: /*limit TX power by the mBm parameter*/
6714 if( sme_SetMaxTxPower(hHal, bssid, selfMac, dbm) != eHAL_STATUS_SUCCESS )
6715 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306716 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Setting maximum tx power failed",
6717 __func__);
6718 return -EIO;
Jeff Johnson295189b2012-06-20 16:38:30 -07006719 }
6720 break;
6721 case NL80211_TX_POWER_FIXED: /*fix TX power to the mBm parameter*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306722 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: NL80211_TX_POWER_FIXED not supported",
Jeff Johnson295189b2012-06-20 16:38:30 -07006723 __func__);
6724 return -EOPNOTSUPP;
6725 break;
6726 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306727 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid power setting type %d",
6728 __func__, type);
Jeff Johnson295189b2012-06-20 16:38:30 -07006729 return -EIO;
6730 }
6731
6732 return 0;
6733}
6734
6735/*
6736 * FUNCTION: wlan_hdd_cfg80211_get_txpower
6737 * This function is used to read the txpower
6738 */
Yue Maf49ba872013-08-19 12:04:25 -07006739static int wlan_hdd_cfg80211_get_txpower(struct wiphy *wiphy,
6740#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0)
6741 struct wireless_dev *wdev,
6742#endif
6743 int *dbm)
Jeff Johnson295189b2012-06-20 16:38:30 -07006744{
6745
6746 hdd_adapter_t *pAdapter;
6747 hdd_context_t *pHddCtx = (hdd_context_t*) wiphy_priv(wiphy);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306748 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006749
Jeff Johnsone7245742012-09-05 17:12:55 -07006750 ENTER();
6751
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306752 status = wlan_hdd_validate_context(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07006753
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306754 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006755 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306756 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6757 "%s: HDD context is not valid", __func__);
6758 *dbm = 0;
6759 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006760 }
6761
Jeff Johnson295189b2012-06-20 16:38:30 -07006762 pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_INFRA_STATION);
6763 if (NULL == pAdapter)
6764 {
6765 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Not in station context " ,__func__);
6766 return -ENOENT;
6767 }
6768
6769 wlan_hdd_get_classAstats(pAdapter);
6770 *dbm = pAdapter->hdd_stats.ClassA_stat.max_pwr;
6771
Jeff Johnsone7245742012-09-05 17:12:55 -07006772 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07006773 return 0;
6774}
6775
6776static int wlan_hdd_cfg80211_get_station(struct wiphy *wiphy, struct net_device *dev,
6777 u8* mac, struct station_info *sinfo)
6778{
6779 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
6780 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
6781 int ssidlen = pHddStaCtx->conn_info.SSID.SSID.length;
6782 tANI_U8 rate_flags;
6783
6784 hdd_context_t *pHddCtx = (hdd_context_t*) wiphy_priv(wiphy);
6785 hdd_config_t *pCfg = pHddCtx->cfg_ini;
Jeff Johnson295189b2012-06-20 16:38:30 -07006786
6787 tANI_U8 OperationalRates[CSR_DOT11_SUPPORTED_RATES_MAX];
6788 tANI_U32 ORLeng = CSR_DOT11_SUPPORTED_RATES_MAX;
6789 tANI_U8 ExtendedRates[CSR_DOT11_EXTENDED_SUPPORTED_RATES_MAX];
6790 tANI_U32 ERLeng = CSR_DOT11_EXTENDED_SUPPORTED_RATES_MAX;
6791 tANI_U8 MCSRates[SIZE_OF_BASIC_MCS_SET];
6792 tANI_U32 MCSLeng = SIZE_OF_BASIC_MCS_SET;
6793 tANI_U16 maxRate = 0;
6794 tANI_U16 myRate;
6795 tANI_U16 currentRate = 0;
6796 tANI_U8 maxSpeedMCS = 0;
6797 tANI_U8 maxMCSIdx = 0;
6798 tANI_U8 rateFlag = 1;
6799 tANI_U8 i, j, rssidx;
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07006800 tANI_U16 temp;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306801 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006802
Leo Chang6f8870f2013-03-26 18:11:36 -07006803#ifdef WLAN_FEATURE_11AC
6804 tANI_U32 vht_mcs_map;
6805 eDataRate11ACMaxMcs vhtMaxMcs;
6806#endif /* WLAN_FEATURE_11AC */
6807
Jeff Johnsone7245742012-09-05 17:12:55 -07006808 ENTER();
6809
Jeff Johnson295189b2012-06-20 16:38:30 -07006810 if ((eConnectionState_Associated != pHddStaCtx->conn_info.connState) ||
6811 (0 == ssidlen))
6812 {
6813 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Not associated or"
6814 " Invalid ssidlen, %d", __func__, ssidlen);
6815 /*To keep GUI happy*/
6816 return 0;
6817 }
6818
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306819 status = wlan_hdd_validate_context(pHddCtx);
6820
6821 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006822 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306823 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6824 "%s: HDD context is not valid", __func__);
6825 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006826 }
6827
Jeff Johnson295189b2012-06-20 16:38:30 -07006828 wlan_hdd_get_rssi(pAdapter, &sinfo->signal);
6829 sinfo->filled |= STATION_INFO_SIGNAL;
6830
Madan Mohan Koyyalamudi4d4d2812012-09-24 14:08:29 -07006831 wlan_hdd_get_station_stats(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07006832 rate_flags = pAdapter->hdd_stats.ClassA_stat.tx_rate_flags;
6833
6834 //convert to the UI units of 100kbps
6835 myRate = pAdapter->hdd_stats.ClassA_stat.tx_rate * 5;
6836
6837#ifdef LINKSPEED_DEBUG_ENABLED
Leo Chang6f8870f2013-03-26 18:11:36 -07006838 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 -07006839 sinfo->signal,
6840 pCfg->reportMaxLinkSpeed,
6841 myRate,
6842 (int) pCfg->linkSpeedRssiHigh,
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07006843 (int) pCfg->linkSpeedRssiMid,
6844 (int) pCfg->linkSpeedRssiLow,
Leo Chang6f8870f2013-03-26 18:11:36 -07006845 (int) rate_flags,
6846 (int) pAdapter->hdd_stats.ClassA_stat.mcs_index);
Jeff Johnson295189b2012-06-20 16:38:30 -07006847#endif //LINKSPEED_DEBUG_ENABLED
6848
6849 if (eHDD_LINK_SPEED_REPORT_ACTUAL != pCfg->reportMaxLinkSpeed)
6850 {
6851 // we do not want to necessarily report the current speed
6852 if (eHDD_LINK_SPEED_REPORT_MAX == pCfg->reportMaxLinkSpeed)
6853 {
6854 // report the max possible speed
6855 rssidx = 0;
6856 }
6857 else if (eHDD_LINK_SPEED_REPORT_MAX_SCALED == pCfg->reportMaxLinkSpeed)
6858 {
6859 // report the max possible speed with RSSI scaling
6860 if (sinfo->signal >= pCfg->linkSpeedRssiHigh)
6861 {
6862 // report the max possible speed
6863 rssidx = 0;
6864 }
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07006865 else if (sinfo->signal >= pCfg->linkSpeedRssiMid)
Jeff Johnson295189b2012-06-20 16:38:30 -07006866 {
6867 // report middle speed
6868 rssidx = 1;
6869 }
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07006870 else if (sinfo->signal >= pCfg->linkSpeedRssiLow)
6871 {
6872 // report middle speed
6873 rssidx = 2;
6874 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006875 else
6876 {
6877 // report actual speed
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07006878 rssidx = 3;
Jeff Johnson295189b2012-06-20 16:38:30 -07006879 }
6880 }
6881 else
6882 {
6883 // unknown, treat as eHDD_LINK_SPEED_REPORT_MAX
6884 hddLog(VOS_TRACE_LEVEL_ERROR,
6885 "%s: Invalid value for reportMaxLinkSpeed: %u",
6886 __func__, pCfg->reportMaxLinkSpeed);
6887 rssidx = 0;
6888 }
6889
6890 maxRate = 0;
6891
6892 /* Get Basic Rate Set */
Gopichand Nakkala05ab1322013-02-15 11:28:38 +05306893 if (0 != ccmCfgGetStr(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_OPERATIONAL_RATE_SET,
6894 OperationalRates, &ORLeng))
6895 {
6896 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: ccm api returned failure", __func__);
6897 /*To keep GUI happy*/
6898 return 0;
6899 }
6900
Jeff Johnson295189b2012-06-20 16:38:30 -07006901 for (i = 0; i < ORLeng; i++)
6902 {
Jeff Johnsone7245742012-09-05 17:12:55 -07006903 for (j = 0; j < (sizeof(supported_data_rate) / sizeof(supported_data_rate[0])); j ++)
Jeff Johnson295189b2012-06-20 16:38:30 -07006904 {
6905 /* Validate Rate Set */
6906 if (supported_data_rate[j].beacon_rate_index == (OperationalRates[i] & 0x7F))
6907 {
6908 currentRate = supported_data_rate[j].supported_rate[rssidx];
6909 break;
6910 }
6911 }
6912 /* Update MAX rate */
6913 maxRate = (currentRate > maxRate)?currentRate:maxRate;
6914 }
6915
6916 /* Get Extended Rate Set */
Gopichand Nakkala05ab1322013-02-15 11:28:38 +05306917 if (0 != ccmCfgGetStr(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_EXTENDED_OPERATIONAL_RATE_SET,
6918 ExtendedRates, &ERLeng))
6919 {
6920 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: ccm api returned failure", __func__);
6921 /*To keep GUI happy*/
6922 return 0;
6923 }
6924
Jeff Johnson295189b2012-06-20 16:38:30 -07006925 for (i = 0; i < ERLeng; i++)
6926 {
Jeff Johnsone7245742012-09-05 17:12:55 -07006927 for (j = 0; j < (sizeof(supported_data_rate) / sizeof(supported_data_rate[0])); j ++)
Jeff Johnson295189b2012-06-20 16:38:30 -07006928 {
6929 if (supported_data_rate[j].beacon_rate_index == (ExtendedRates[i] & 0x7F))
6930 {
6931 currentRate = supported_data_rate[j].supported_rate[rssidx];
6932 break;
6933 }
6934 }
6935 /* Update MAX rate */
6936 maxRate = (currentRate > maxRate)?currentRate:maxRate;
6937 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006938 /* Get MCS Rate Set -- but only if we are connected at MCS
6939 rates or if we are always reporting max speed or if we have
6940 good rssi */
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07006941 if ((0 == rssidx) && !(rate_flags & eHAL_TX_RATE_LEGACY))
Jeff Johnson295189b2012-06-20 16:38:30 -07006942 {
Gopichand Nakkala05ab1322013-02-15 11:28:38 +05306943 if (0 != ccmCfgGetStr(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_CURRENT_MCS_SET,
6944 MCSRates, &MCSLeng))
6945 {
6946 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: ccm api returned failure", __func__);
6947 /*To keep GUI happy*/
6948 return 0;
6949 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006950 rateFlag = 0;
Leo Chang6f8870f2013-03-26 18:11:36 -07006951#ifdef WLAN_FEATURE_11AC
6952 /* VHT80 rate has seperate rate table */
Gopichand Nakkala4c705372013-04-24 13:20:33 +05306953 if (rate_flags & (eHAL_TX_RATE_VHT20|eHAL_TX_RATE_VHT40|eHAL_TX_RATE_VHT80))
Jeff Johnson295189b2012-06-20 16:38:30 -07006954 {
Leo Chang6f8870f2013-03-26 18:11:36 -07006955 ccmCfgGetInt(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_VHT_TX_MCS_MAP, &vht_mcs_map);
Gopichand Nakkala4c705372013-04-24 13:20:33 +05306956 vhtMaxMcs = (eDataRate11ACMaxMcs)(vht_mcs_map & DATA_RATE_11AC_MCS_MASK );
Leo Chang6f8870f2013-03-26 18:11:36 -07006957 if (rate_flags & eHAL_TX_RATE_SGI)
Jeff Johnson295189b2012-06-20 16:38:30 -07006958 {
Leo Chang6f8870f2013-03-26 18:11:36 -07006959 rateFlag |= 1;
Jeff Johnson295189b2012-06-20 16:38:30 -07006960 }
Leo Chang6f8870f2013-03-26 18:11:36 -07006961 if (DATA_RATE_11AC_MAX_MCS_7 == vhtMaxMcs)
Jeff Johnson295189b2012-06-20 16:38:30 -07006962 {
Leo Chang6f8870f2013-03-26 18:11:36 -07006963 maxMCSIdx = 7;
6964 }
6965 else if (DATA_RATE_11AC_MAX_MCS_8 == vhtMaxMcs)
6966 {
6967 maxMCSIdx = 8;
6968 }
6969 else if (DATA_RATE_11AC_MAX_MCS_9 == vhtMaxMcs)
6970 {
Gopichand Nakkala4c705372013-04-24 13:20:33 +05306971 //VHT20 is supporting 0~8
6972 if (rate_flags & eHAL_TX_RATE_VHT20)
6973 maxMCSIdx = 8;
6974 else
6975 maxMCSIdx = 9;
Leo Chang6f8870f2013-03-26 18:11:36 -07006976 }
Gopichand Nakkala4c705372013-04-24 13:20:33 +05306977
6978 if (rate_flags & eHAL_TX_RATE_VHT80)
6979 {
6980 currentRate = supported_vht_mcs_rate[pAdapter->hdd_stats.ClassA_stat.mcs_index].supported_VHT80_rate[rateFlag];
6981 maxRate = supported_vht_mcs_rate[maxMCSIdx].supported_VHT80_rate[rateFlag];
6982 }
6983 else if (rate_flags & eHAL_TX_RATE_VHT40)
6984 {
6985 currentRate = supported_vht_mcs_rate[pAdapter->hdd_stats.ClassA_stat.mcs_index].supported_VHT40_rate[rateFlag];
6986 maxRate = supported_vht_mcs_rate[maxMCSIdx].supported_VHT40_rate[rateFlag];
6987 }
6988 else if (rate_flags & eHAL_TX_RATE_VHT20)
6989 {
6990 currentRate = supported_vht_mcs_rate[pAdapter->hdd_stats.ClassA_stat.mcs_index].supported_VHT20_rate[rateFlag];
6991 maxRate = supported_vht_mcs_rate[maxMCSIdx].supported_VHT20_rate[rateFlag];
6992 }
6993
Leo Chang6f8870f2013-03-26 18:11:36 -07006994 maxSpeedMCS = 1;
6995 if (currentRate > maxRate)
6996 {
6997 maxRate = currentRate;
6998 }
Gopichand Nakkala4c705372013-04-24 13:20:33 +05306999
Leo Chang6f8870f2013-03-26 18:11:36 -07007000 }
7001 else
7002#endif /* WLAN_FEATURE_11AC */
7003 {
7004 if (rate_flags & eHAL_TX_RATE_HT40)
7005 {
7006 rateFlag |= 1;
7007 }
7008 if (rate_flags & eHAL_TX_RATE_SGI)
7009 {
7010 rateFlag |= 2;
7011 }
7012
7013 for (i = 0; i < MCSLeng; i++)
7014 {
7015 temp = sizeof(supported_mcs_rate) / sizeof(supported_mcs_rate[0]);
7016 for (j = 0; j < temp; j++)
7017 {
7018 if (supported_mcs_rate[j].beacon_rate_index == MCSRates[i])
7019 {
7020 currentRate = supported_mcs_rate[j].supported_rate[rateFlag];
7021 break;
7022 }
7023 }
7024 if ((j < temp) && (currentRate > maxRate))
7025 {
7026 maxRate = currentRate;
7027 maxSpeedMCS = 1;
7028 maxMCSIdx = supported_mcs_rate[j].beacon_rate_index;
7029 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007030 }
7031 }
7032 }
7033
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307034 else if (!(rate_flags & eHAL_TX_RATE_LEGACY))
7035 {
7036 maxRate = myRate;
7037 maxSpeedMCS = 1;
7038 maxMCSIdx = pAdapter->hdd_stats.ClassA_stat.mcs_index;
7039 }
7040
Jeff Johnson295189b2012-06-20 16:38:30 -07007041 // make sure we report a value at least as big as our current rate
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07007042 if (((maxRate < myRate) && (0 == rssidx)) ||
7043 (0 == maxRate))
Jeff Johnson295189b2012-06-20 16:38:30 -07007044 {
7045 maxRate = myRate;
7046 if (rate_flags & eHAL_TX_RATE_LEGACY)
7047 {
7048 maxSpeedMCS = 0;
7049 }
7050 else
7051 {
7052 maxSpeedMCS = 1;
7053 maxMCSIdx = pAdapter->hdd_stats.ClassA_stat.mcs_index;
7054 }
7055 }
7056
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307057 if (rate_flags & eHAL_TX_RATE_LEGACY)
Jeff Johnson295189b2012-06-20 16:38:30 -07007058 {
7059 sinfo->txrate.legacy = maxRate;
7060#ifdef LINKSPEED_DEBUG_ENABLED
7061 pr_info("Reporting legacy rate %d\n", sinfo->txrate.legacy);
7062#endif //LINKSPEED_DEBUG_ENABLED
7063 }
7064 else
7065 {
7066 sinfo->txrate.mcs = maxMCSIdx;
Leo Chang6f8870f2013-03-26 18:11:36 -07007067#ifdef WLAN_FEATURE_11AC
7068 sinfo->txrate.nss = 1;
7069 if (rate_flags & eHAL_TX_RATE_VHT80)
7070 {
7071 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307072 sinfo->txrate.flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
Leo Chang6f8870f2013-03-26 18:11:36 -07007073 }
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307074 else if (rate_flags & eHAL_TX_RATE_VHT40)
Leo Chang6f8870f2013-03-26 18:11:36 -07007075 {
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307076 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
7077 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
7078 }
7079 else if (rate_flags & eHAL_TX_RATE_VHT20)
7080 {
7081 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
7082 }
7083#endif /* WLAN_FEATURE_11AC */
7084 if (rate_flags & (eHAL_TX_RATE_HT20 | eHAL_TX_RATE_HT40))
7085 {
7086 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
7087 if (rate_flags & eHAL_TX_RATE_HT40)
7088 {
7089 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
7090 }
Leo Chang6f8870f2013-03-26 18:11:36 -07007091 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007092 if (rate_flags & eHAL_TX_RATE_SGI)
7093 {
7094 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
7095 }
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307096
Jeff Johnson295189b2012-06-20 16:38:30 -07007097#ifdef LINKSPEED_DEBUG_ENABLED
7098 pr_info("Reporting MCS rate %d flags %x\n",
7099 sinfo->txrate.mcs,
7100 sinfo->txrate.flags );
7101#endif //LINKSPEED_DEBUG_ENABLED
7102 }
7103 }
7104 else
7105 {
7106 // report current rate instead of max rate
7107
7108 if (rate_flags & eHAL_TX_RATE_LEGACY)
7109 {
7110 //provide to the UI in units of 100kbps
7111 sinfo->txrate.legacy = myRate;
7112#ifdef LINKSPEED_DEBUG_ENABLED
7113 pr_info("Reporting actual legacy rate %d\n", sinfo->txrate.legacy);
7114#endif //LINKSPEED_DEBUG_ENABLED
7115 }
7116 else
7117 {
7118 //must be MCS
7119 sinfo->txrate.mcs = pAdapter->hdd_stats.ClassA_stat.mcs_index;
Leo Chang6f8870f2013-03-26 18:11:36 -07007120#ifdef WLAN_FEATURE_11AC
7121 sinfo->txrate.nss = 1;
7122 if (rate_flags & eHAL_TX_RATE_VHT80)
7123 {
7124 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
7125 }
7126 else
7127#endif /* WLAN_FEATURE_11AC */
7128 {
7129 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
7130 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007131 if (rate_flags & eHAL_TX_RATE_SGI)
7132 {
7133 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
7134 }
7135 if (rate_flags & eHAL_TX_RATE_HT40)
7136 {
7137 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
7138 }
Leo Chang6f8870f2013-03-26 18:11:36 -07007139#ifdef WLAN_FEATURE_11AC
7140 else if (rate_flags & eHAL_TX_RATE_VHT80)
7141 {
7142 sinfo->txrate.flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
7143 }
7144#endif /* WLAN_FEATURE_11AC */
Jeff Johnson295189b2012-06-20 16:38:30 -07007145#ifdef LINKSPEED_DEBUG_ENABLED
7146 pr_info("Reporting actual MCS rate %d flags %x\n",
7147 sinfo->txrate.mcs,
7148 sinfo->txrate.flags );
7149#endif //LINKSPEED_DEBUG_ENABLED
7150 }
7151 }
7152 sinfo->filled |= STATION_INFO_TX_BITRATE;
7153
Madan Mohan Koyyalamudi4d4d2812012-09-24 14:08:29 -07007154 sinfo->tx_packets =
7155 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[0] +
7156 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[1] +
7157 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[2] +
7158 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[3];
7159
7160 sinfo->tx_retries =
7161 pAdapter->hdd_stats.summary_stat.retry_cnt[0] +
7162 pAdapter->hdd_stats.summary_stat.retry_cnt[1] +
7163 pAdapter->hdd_stats.summary_stat.retry_cnt[2] +
7164 pAdapter->hdd_stats.summary_stat.retry_cnt[3];
7165
7166 sinfo->tx_failed =
7167 pAdapter->hdd_stats.summary_stat.fail_cnt[0] +
7168 pAdapter->hdd_stats.summary_stat.fail_cnt[1] +
7169 pAdapter->hdd_stats.summary_stat.fail_cnt[2] +
7170 pAdapter->hdd_stats.summary_stat.fail_cnt[3];
7171
7172 sinfo->filled |=
7173 STATION_INFO_TX_PACKETS |
7174 STATION_INFO_TX_RETRIES |
7175 STATION_INFO_TX_FAILED;
7176
7177 EXIT();
7178 return 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07007179}
7180
7181static int wlan_hdd_cfg80211_set_power_mgmt(struct wiphy *wiphy,
Sameer Thalappilc9f26e92013-06-07 10:11:06 -07007182 struct net_device *dev, bool mode, int timeout)
Jeff Johnson295189b2012-06-20 16:38:30 -07007183{
7184 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05307185 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07007186 VOS_STATUS vos_status;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307187 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007188
Jeff Johnsone7245742012-09-05 17:12:55 -07007189 ENTER();
7190
Jeff Johnson295189b2012-06-20 16:38:30 -07007191 if (NULL == pAdapter)
7192 {
7193 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Adapter is NULL\n", __func__);
7194 return -ENODEV;
7195 }
7196
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05307197 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307198 status = wlan_hdd_validate_context(pHddCtx);
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05307199
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307200 if (0 != status)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307201 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307202 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7203 "%s: HDD context is not valid", __func__);
7204 return status;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307205 }
7206
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05307207 if ((DRIVER_POWER_MODE_AUTO == !mode) &&
7208 (TRUE == pHddCtx->hdd_wlan_suspended) &&
7209 (pHddCtx->cfg_ini->fhostArpOffload) &&
7210 (eConnectionState_Associated ==
7211 (WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))->conn_info.connState))
7212 {
Amar Singhald53568e2013-09-26 11:03:45 -07007213
7214 hddLog(VOS_TRACE_LEVEL_INFO,
7215 "offload: in cfg80211_set_power_mgmt, calling arp offload");
Gopichand Nakkalab03e8082013-05-30 18:09:25 +05307216 vos_status = hdd_conf_arp_offload(pAdapter, TRUE);
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05307217 if (!VOS_IS_STATUS_SUCCESS(vos_status))
7218 {
7219 hddLog(VOS_TRACE_LEVEL_INFO,
7220 "%s:Failed to enable ARPOFFLOAD Feature %d\n",
7221 __func__, vos_status);
7222 }
7223 }
7224
Jeff Johnson295189b2012-06-20 16:38:30 -07007225 /**The get power cmd from the supplicant gets updated by the nl only
7226 *on successful execution of the function call
7227 *we are oppositely mapped w.r.t mode in the driver
7228 **/
7229 vos_status = wlan_hdd_enter_bmps(pAdapter, !mode);
7230
Jeff Johnsone7245742012-09-05 17:12:55 -07007231 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07007232 if (VOS_STATUS_E_FAILURE == vos_status)
7233 {
7234 return -EINVAL;
7235 }
7236 return 0;
7237}
7238
7239
7240#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
7241static int wlan_hdd_set_default_mgmt_key(struct wiphy *wiphy,
7242 struct net_device *netdev,
7243 u8 key_index)
7244{
Jeff Johnsone7245742012-09-05 17:12:55 -07007245 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07007246 return 0;
7247}
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307248#endif //LINUX_VERSION_CODE
Jeff Johnson295189b2012-06-20 16:38:30 -07007249
7250#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
7251static int wlan_hdd_set_txq_params(struct wiphy *wiphy,
7252 struct net_device *dev,
7253 struct ieee80211_txq_params *params)
7254{
Jeff Johnsone7245742012-09-05 17:12:55 -07007255 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07007256 return 0;
7257}
7258#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
7259static int wlan_hdd_set_txq_params(struct wiphy *wiphy,
7260 struct ieee80211_txq_params *params)
7261{
Jeff Johnsone7245742012-09-05 17:12:55 -07007262 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07007263 return 0;
7264}
7265#endif //LINUX_VERSION_CODE
7266
7267static int wlan_hdd_cfg80211_del_station(struct wiphy *wiphy,
7268 struct net_device *dev, u8 *mac)
7269{
7270 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307271 hdd_context_t *pHddCtx;
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007272 VOS_STATUS vos_status;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307273 int status;
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007274 v_U8_t staId;
Jeff Johnson295189b2012-06-20 16:38:30 -07007275
Jeff Johnsone7245742012-09-05 17:12:55 -07007276 ENTER();
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307277 if ( NULL == pAdapter )
Jeff Johnson295189b2012-06-20 16:38:30 -07007278 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307279 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Adapter" ,__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07007280 return -EINVAL;
7281 }
7282
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307283 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7284 status = wlan_hdd_validate_context(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07007285
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307286 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007287 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307288 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7289 "%s: HDD context is not valid", __func__);
7290 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007291 }
7292
Jeff Johnson295189b2012-06-20 16:38:30 -07007293 if ( (WLAN_HDD_SOFTAP == pAdapter->device_mode)
Jeff Johnson295189b2012-06-20 16:38:30 -07007294 || (WLAN_HDD_P2P_GO == pAdapter->device_mode)
Jeff Johnson295189b2012-06-20 16:38:30 -07007295 )
7296 {
7297 if( NULL == mac )
7298 {
7299 v_U16_t i;
7300 for(i = 0; i < WLAN_MAX_STA_COUNT; i++)
7301 {
Rajesh Chauhan18488fc2013-08-22 10:15:03 -07007302 if ((pAdapter->aStaInfo[i].isUsed) &&
7303 (!pAdapter->aStaInfo[i].isDeauthInProgress))
Jeff Johnson295189b2012-06-20 16:38:30 -07007304 {
7305 u8 *macAddr = pAdapter->aStaInfo[i].macAddrSTA.bytes;
7306 hddLog(VOS_TRACE_LEVEL_INFO,
7307 "%s: Delete STA with MAC::"
7308 "%02x:%02x:%02x:%02x:%02x:%02x",
7309 __func__,
7310 macAddr[0], macAddr[1], macAddr[2],
7311 macAddr[3], macAddr[4], macAddr[5]);
Rajesh Chauhan18488fc2013-08-22 10:15:03 -07007312 vos_status = hdd_softap_sta_deauth(pAdapter, macAddr);
7313 if (VOS_IS_STATUS_SUCCESS(vos_status))
7314 pAdapter->aStaInfo[i].isDeauthInProgress = TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07007315 }
7316 }
7317 }
7318 else
7319 {
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007320
7321 vos_status = hdd_softap_GetStaId(pAdapter,(v_MACADDR_t *)mac, &staId);
7322 if (!VOS_IS_STATUS_SUCCESS(vos_status))
7323 {
7324 hddLog(VOS_TRACE_LEVEL_INFO,
7325 "%s: Skip this DEL STA as this is not used::"
7326 "%02x:%02x:%02x:%02x:%02x:%02x",
7327 __func__,
7328 mac[0], mac[1], mac[2],
7329 mac[3], mac[4], mac[5]);
7330 return -ENOENT;
7331 }
7332
7333 if( pAdapter->aStaInfo[staId].isDeauthInProgress == TRUE)
7334 {
7335 hddLog(VOS_TRACE_LEVEL_INFO,
7336 "%s: Skip this DEL STA as deauth is in progress::"
7337 "%02x:%02x:%02x:%02x:%02x:%02x",
7338 __func__,
7339 mac[0], mac[1], mac[2],
7340 mac[3], mac[4], mac[5]);
7341 return -ENOENT;
7342 }
7343
7344 pAdapter->aStaInfo[staId].isDeauthInProgress = TRUE;
7345
Jeff Johnson295189b2012-06-20 16:38:30 -07007346 hddLog(VOS_TRACE_LEVEL_INFO,
7347 "%s: Delete STA with MAC::"
7348 "%02x:%02x:%02x:%02x:%02x:%02x",
7349 __func__,
7350 mac[0], mac[1], mac[2],
7351 mac[3], mac[4], mac[5]);
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007352
7353 vos_status = hdd_softap_sta_deauth(pAdapter, mac);
7354 if (!VOS_IS_STATUS_SUCCESS(vos_status))
7355 {
7356 pAdapter->aStaInfo[staId].isDeauthInProgress = FALSE;
7357 hddLog(VOS_TRACE_LEVEL_INFO,
7358 "%s: STA removal failed for ::"
7359 "%02x:%02x:%02x:%02x:%02x:%02x",
7360 __func__,
7361 mac[0], mac[1], mac[2],
7362 mac[3], mac[4], mac[5]);
7363 return -ENOENT;
7364 }
7365
Jeff Johnson295189b2012-06-20 16:38:30 -07007366 }
7367 }
7368
7369 EXIT();
7370
7371 return 0;
7372}
7373
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007374static int wlan_hdd_cfg80211_add_station(struct wiphy *wiphy,
7375 struct net_device *dev, u8 *mac, struct station_parameters *params)
7376{
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007377 int status = -EPERM;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007378#ifdef FEATURE_WLAN_TDLS
7379 u32 mask, set;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007380 ENTER();
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007381 mask = params->sta_flags_mask;
7382
7383 set = params->sta_flags_set;
7384
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007385#ifdef WLAN_FEATURE_TDLS_DEBUG
7386 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7387 "%s: mask 0x%x set 0x%x " MAC_ADDRESS_STR,
7388 __func__, mask, set, MAC_ADDR_ARRAY(mac));
7389#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007390
7391 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
7392 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
Gopichand Nakkala681989c2013-03-06 22:27:48 -08007393 status = wlan_hdd_tdls_add_station(wiphy, dev, mac, 0, NULL);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007394 }
7395 }
7396#endif
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007397 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007398}
7399
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007400
7401#ifdef FEATURE_WLAN_LFR
Wilson Yang6507c4e2013-10-01 20:11:19 -07007402#define MAX_PMKSAIDS_IN_CACHE 8
7403
7404static tPmkidCacheInfo PMKIDCache[MAX_PMKSAIDS_IN_CACHE]; // HDD local cache
7405static tANI_U32 PMKIDCacheIndex; // HDD local Cache index
7406
7407
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007408static int wlan_hdd_cfg80211_set_pmksa(struct wiphy *wiphy, struct net_device *dev,
Jeff Johnsond13512a2012-07-17 11:42:19 -07007409 struct cfg80211_pmksa *pmksa)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007410{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307411 tANI_U32 j=0;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007412 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7413 tHalHandle halHandle;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307414 eHalStatus result;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307415 int status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007416 tANI_U8 BSSIDMatched = 0;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307417 hdd_context_t *pHddCtx;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307418
Jeff Johnsone7245742012-09-05 17:12:55 -07007419 ENTER();
7420
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307421 // Validate pAdapter
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307422 if ( NULL == pAdapter )
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007423 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307424 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Adapter" ,__func__);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007425 return -EINVAL;
7426 }
7427
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307428 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7429 status = wlan_hdd_validate_context(pHddCtx);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007430
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307431 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007432 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307433 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7434 "%s: HDD context is not valid", __func__);
7435 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007436 }
7437
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307438 // Retrieve halHandle
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007439 halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
7440
Wilson Yang6507c4e2013-10-01 20:11:19 -07007441 for (j = 0; j < PMKIDCacheIndex; j++)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007442 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307443 if(vos_mem_compare(PMKIDCache[j].BSSID,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007444 pmksa->bssid, WNI_CFG_BSSID_LEN))
7445 {
7446 /* BSSID matched previous entry. Overwrite it. */
7447 BSSIDMatched = 1;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307448 vos_mem_copy(PMKIDCache[j].BSSID,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007449 pmksa->bssid, WNI_CFG_BSSID_LEN);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307450 vos_mem_copy(PMKIDCache[j].PMKID,
7451 pmksa->pmkid,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007452 CSR_RSN_PMKID_SIZE);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307453 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Reusing cache entry %d.",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007454 __func__, j );
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007455 dump_bssid(pmksa->bssid);
7456 dump_pmkid(halHandle, pmksa->pmkid);
7457 break;
7458 }
7459 }
7460
Madan Mohan Koyyalamudic4b317d2012-10-18 19:43:08 -07007461 /* Check we compared all entries,if then take the first slot now */
Wilson Yang6507c4e2013-10-01 20:11:19 -07007462 if(j == MAX_PMKSAIDS_IN_CACHE) PMKIDCacheIndex=0;
Madan Mohan Koyyalamudic4b317d2012-10-18 19:43:08 -07007463
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007464 if (!BSSIDMatched)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307465 {
7466 // Now, we DON'T have a BSSID match, so take a new entry in the cache.
Wilson Yang6507c4e2013-10-01 20:11:19 -07007467 vos_mem_copy(PMKIDCache[PMKIDCacheIndex].BSSID,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307468 pmksa->bssid, ETHER_ADDR_LEN);
Wilson Yang6507c4e2013-10-01 20:11:19 -07007469 vos_mem_copy(PMKIDCache[PMKIDCacheIndex].PMKID,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307470 pmksa->pmkid,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007471 CSR_RSN_PMKID_SIZE);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307472 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Adding a new cache entry %d.",
Wilson Yang6507c4e2013-10-01 20:11:19 -07007473 __func__, PMKIDCacheIndex );
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007474 dump_bssid(pmksa->bssid);
7475 dump_pmkid(halHandle, pmksa->pmkid);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307476 // Increment the HDD Local Cache index
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007477 // The "i=0" doesn't work for the call to sme_RoamSetPMKIDCache() - LFR FIXME
Wilson Yang6507c4e2013-10-01 20:11:19 -07007478 if (PMKIDCacheIndex <= (MAX_PMKSAIDS_IN_CACHE-1)) PMKIDCacheIndex++; else PMKIDCacheIndex = 0;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007479 }
7480
7481
7482 // Calling csrRoamSetPMKIDCache to configure the PMKIDs into the cache
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307483 //hddLog(LOG1, FL("%s: Calling csrRoamSetPMKIDCache with %d cache entries."),
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007484 // __func__, i );
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307485 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Calling csrRoamSetPMKIDCache with %d cache entries.",
Wilson Yang6507c4e2013-10-01 20:11:19 -07007486 __func__, PMKIDCacheIndex );
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007487 // Finally set the PMKSA ID Cache in CSR
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307488 result = sme_RoamSetPMKIDCache(halHandle,pAdapter->sessionId,
7489 PMKIDCache,
Wilson Yang6507c4e2013-10-01 20:11:19 -07007490 PMKIDCacheIndex);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007491 return 0;
7492}
7493
7494
Wilson Yang6507c4e2013-10-01 20:11:19 -07007495
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007496static int wlan_hdd_cfg80211_del_pmksa(struct wiphy *wiphy, struct net_device *dev,
Wilson Yang6507c4e2013-10-01 20:11:19 -07007497 struct cfg80211_pmksa *pmksa)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007498{
Wilson Yang6507c4e2013-10-01 20:11:19 -07007499 tANI_U32 j=0;
7500 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7501 tHalHandle halHandle;
7502 int status;
7503 tANI_U8 BSSIDMatched = 0;
7504 tANI_U8 *pBSSId;
7505 hdd_context_t *pHddCtx;
7506 int result = 0;
7507
7508 hddLog(VOS_TRACE_LEVEL_DEBUG, "%s: deleting PMKSA with PMKSA_ID %d .",
7509 __func__,pmksa->pmkid);
7510
7511 /* Validate pAdapter */
7512 if (NULL == pAdapter)
7513 {
7514 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Adapter" ,__func__);
7515 return -EINVAL;
7516 }
7517
7518 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7519 status = wlan_hdd_validate_context(pHddCtx);
7520
7521 if (0 != status)
7522 {
7523 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7524 "%s: HDD context is not valid", __func__);
7525 return status;
7526 }
7527
7528 /*Retrieve halHandle*/
7529 halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
7530
7531 /*in case index is 0,no entry to delete*/
7532 if (0 == PMKIDCacheIndex)
7533 {
7534 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid entry to delete" ,
7535 __func__);
7536 return -EINVAL;
7537 }
7538
7539 /*find the matching PMKSA entry from j=0 to (index-1),
7540 * and delete the matched one
7541 */
7542 for (j = 0; j<PMKIDCacheIndex; j++)
7543 {
7544 if (vos_mem_compare(PMKIDCache[j].BSSID,
7545 pmksa->bssid,
7546 WNI_CFG_BSSID_LEN))
7547 {
7548 /* BSSID matched entry */
7549 BSSIDMatched = 1;
7550
7551 if (j<PMKIDCacheIndex-1)
7552 {
7553 /*replace the matching entry with the last entry in HDD local cache*/
7554 vos_mem_copy(PMKIDCache[j].BSSID,
7555 PMKIDCache[PMKIDCacheIndex-1].BSSID,
7556 WNI_CFG_BSSID_LEN);
7557 vos_mem_copy(PMKIDCache[j].PMKID,
7558 PMKIDCache[PMKIDCacheIndex-1].PMKID,
7559 CSR_RSN_PMKID_SIZE);
7560 }
7561
7562 /*clear the last entry in HDD cache ---[index-1]*/
7563 pBSSId =(tANI_U8 *)(PMKIDCache[PMKIDCacheIndex-1].BSSID);
7564 vos_mem_zero(PMKIDCache[PMKIDCacheIndex-1].BSSID, WNI_CFG_BSSID_LEN);
7565 vos_mem_zero(PMKIDCache[PMKIDCacheIndex-1].PMKID, CSR_RSN_PMKID_SIZE);
7566
7567 /*reduce the PMKID array index*/
7568 PMKIDCacheIndex--;
7569
7570 /*delete the last PMKID cache in CSR*/
7571 result = sme_RoamDelPMKIDfromCache(halHandle, pAdapter->sessionId, pBSSId);
7572 if (0 != result)
7573 {
7574 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: cannot delete PMKSA %d CONTENT.",
7575 __func__,PMKIDCacheIndex);
7576 }
7577
7578 dump_bssid(pmksa->bssid);
7579 dump_pmkid(halHandle,pmksa->pmkid);
7580
7581 break;
7582 }
7583 }
7584
7585 /* we compare all entries,but cannot find matching entry */
7586 if (j == MAX_PMKSAIDS_IN_CACHE && !BSSIDMatched)
7587 {
7588 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: No such PMKSA entry existed %d.",
7589 __func__,pmksa->bssid);
7590 dump_bssid(pmksa->bssid);
7591 dump_pmkid(halHandle, pmksa->pmkid);
7592 return -EINVAL;
7593 }
7594 return result;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007595}
7596
Wilson Yang6507c4e2013-10-01 20:11:19 -07007597
7598
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007599static int wlan_hdd_cfg80211_flush_pmksa(struct wiphy *wiphy, struct net_device *dev)
7600{
Wilson Yang6507c4e2013-10-01 20:11:19 -07007601 tANI_U32 j=0;
7602 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7603 tHalHandle halHandle;
7604 hdd_context_t *pHddCtx;
7605 tANI_U8 *pBSSId;
7606 int status;
7607 int result;
7608
7609 hddLog(VOS_TRACE_LEVEL_DEBUG, "%s: flushing PMKSA ",__func__);
7610
7611 /* Validate pAdapter */
7612 if (NULL == pAdapter)
7613 {
7614 hddLog(VOS_TRACE_LEVEL_ERROR,
7615 "%s: Invalid Adapter" ,__func__);
7616 return -EINVAL;
7617 }
7618
7619 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7620 status = wlan_hdd_validate_context(pHddCtx);
7621
7622 if (0 != status)
7623 {
7624 hddLog(VOS_TRACE_LEVEL_ERROR,
7625 "%s: HDD context is not valid", __func__);
7626 return status;
7627 }
7628
7629 /*Retrieve halHandle*/
7630 halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
7631
7632 /*in case index is 0,no entry to delete*/
7633 if (0 == PMKIDCacheIndex)
7634 {
7635 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid entry to delete" ,
7636 __func__);
7637 return -EINVAL;
7638 }
7639
7640 /*delete all the PMKSA one by one */
7641 for (j = 0; j<PMKIDCacheIndex; j++)
7642 {
7643 /*clear the entry in HDD cache 0--index-1 */
7644 pBSSId =(tANI_U8 *)(PMKIDCache[j].BSSID);
7645 vos_mem_zero(PMKIDCache[j].BSSID, WNI_CFG_BSSID_LEN);
7646 vos_mem_zero(PMKIDCache[j].PMKID, CSR_RSN_PMKID_SIZE);
7647
7648 /*delete the PMKID in CSR*/
7649 result = sme_RoamDelPMKIDfromCache(halHandle, pAdapter->sessionId, pBSSId);
7650
7651 if (0!= result)
7652 {
7653 hddLog(VOS_TRACE_LEVEL_ERROR ,"%s cannot flush PMKIDCache %d.",
7654 __func__,j);
7655 }
7656 }
7657
7658 PMKIDCacheIndex = 0;
7659 return result;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007660}
7661#endif
7662
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07007663#if defined(WLAN_FEATURE_VOWIFI_11R) && defined(KERNEL_SUPPORT_11R_CFG80211)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307664static int wlan_hdd_cfg80211_update_ft_ies(struct wiphy *wiphy,
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07007665 struct net_device *dev, struct cfg80211_update_ft_ies_params *ftie)
7666{
7667 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7668 hdd_station_ctx_t *pHddStaCtx;
7669
7670 if (NULL == pAdapter)
7671 {
7672 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Adapter is NULL\n", __func__);
7673 return -ENODEV;
7674 }
7675
7676 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
7677
7678 // Added for debug on reception of Re-assoc Req.
7679 if (eConnectionState_Associated != pHddStaCtx->conn_info.connState)
7680 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307681 hddLog(LOGE, FL("Called with Ie of length = %d when not associated\n"),
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07007682 ftie->ie_len);
7683 hddLog(LOGE, FL("Should be Re-assoc Req IEs\n"));
7684 }
7685
7686#ifdef WLAN_FEATURE_VOWIFI_11R_DEBUG
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307687 hddLog(LOGE, FL("%s called with Ie of length = %d\n"), __func__,
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07007688 ftie->ie_len);
7689#endif
7690
7691 // Pass the received FT IEs to SME
Gopichand Nakkala356fb102013-03-06 12:34:04 +05307692 sme_SetFTIEs( WLAN_HDD_GET_HAL_CTX(pAdapter), pAdapter->sessionId,
7693 (const u8 *)ftie->ie,
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07007694 ftie->ie_len);
7695 return 0;
7696}
7697#endif
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007698
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307699#ifdef FEATURE_WLAN_SCAN_PNO
7700
7701void hdd_cfg80211_sched_scan_done_callback(void *callbackContext,
7702 tSirPrefNetworkFoundInd *pPrefNetworkFoundInd)
7703{
7704 int ret;
7705 hdd_adapter_t* pAdapter = (hdd_adapter_t*)callbackContext;
7706 hdd_context_t *pHddCtx;
7707
7708 if (NULL == pAdapter)
7709 {
7710 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
7711 "%s: HDD adapter is Null", __func__);
7712 return ;
7713 }
7714
7715 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7716 if (NULL == pHddCtx)
7717 {
7718 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7719 "%s: HDD context is Null!!!", __func__);
7720 return ;
7721 }
7722
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05307723 spin_lock(&pHddCtx->schedScan_lock);
7724 if (TRUE == pHddCtx->isWiphySuspended)
7725 {
7726 pHddCtx->isSchedScanUpdatePending = TRUE;
7727 spin_unlock(&pHddCtx->schedScan_lock);
7728 hddLog(VOS_TRACE_LEVEL_INFO,
7729 "%s: Update cfg80211 scan database after it resume", __func__);
7730 return ;
7731 }
7732 spin_unlock(&pHddCtx->schedScan_lock);
7733
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307734 ret = wlan_hdd_cfg80211_update_bss(pHddCtx->wiphy, pAdapter);
7735
7736 if (0 > ret)
7737 hddLog(VOS_TRACE_LEVEL_INFO, "%s: NO SCAN result", __func__);
7738
7739 cfg80211_sched_scan_results(pHddCtx->wiphy);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05307740 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
7741 "%s: cfg80211 scan result database updated", __func__);
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307742}
7743
7744/*
7745 * FUNCTION: wlan_hdd_cfg80211_sched_scan_start
7746 * NL interface to enable PNO
7747 */
7748static int wlan_hdd_cfg80211_sched_scan_start(struct wiphy *wiphy,
7749 struct net_device *dev, struct cfg80211_sched_scan_request *request)
7750{
7751 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7752 tpSirPNOScanReq pPnoRequest = NULL;
7753 hdd_context_t *pHddCtx;
7754 tHalHandle hHal;
Madan Mohan Koyyalamudi1d16f462013-08-27 16:25:34 +05307755 v_U32_t i, indx, num_ch, tempInterval;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307756 u8 valid_ch[WNI_CFG_VALID_CHANNEL_LIST_LEN];
7757 u8 channels_allowed[WNI_CFG_VALID_CHANNEL_LIST_LEN];
7758 v_U32_t num_channels_allowed = WNI_CFG_VALID_CHANNEL_LIST_LEN;
7759 eHalStatus status = eHAL_STATUS_FAILURE;
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307760 int ret = 0;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307761
7762 if (NULL == pAdapter)
7763 {
7764 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
7765 "%s: HDD adapter is Null", __func__);
7766 return -ENODEV;
7767 }
7768
7769 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05307770 ret = wlan_hdd_validate_context(pHddCtx);
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307771
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05307772 if (0 != ret)
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307773 {
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05307774 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7775 "%s: HDD context is not valid", __func__);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307776 return -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307777 }
7778
7779 hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
7780 if (NULL == hHal)
7781 {
7782 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7783 "%s: HAL context is Null!!!", __func__);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05307784 return -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307785 }
7786
7787 pPnoRequest = (tpSirPNOScanReq) vos_mem_malloc(sizeof (tSirPNOScanReq));
7788 if (NULL == pPnoRequest)
7789 {
7790 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
7791 "%s: vos_mem_malloc failed", __func__);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307792 return -ENOMEM;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307793 }
7794
Madan Mohan Koyyalamudic3f04352013-09-26 19:21:48 +05307795 memset(pPnoRequest, 0, sizeof (tSirPNOScanReq));
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307796 pPnoRequest->enable = 1; /*Enable PNO */
7797 pPnoRequest->ucNetworksCount = request->n_match_sets;
7798
7799 if (( !pPnoRequest->ucNetworksCount ) ||
7800 ( pPnoRequest->ucNetworksCount > SIR_PNO_MAX_SUPP_NETWORKS ))
7801 {
7802 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7803 "Network input is not correct");
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307804 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307805 goto error;
7806 }
7807
7808 if ( SIR_PNO_MAX_NETW_CHANNELS_EX < request->n_channels )
7809 {
7810 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7811 "Incorrect number of channels");
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307812 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307813 goto error;
7814 }
7815
7816 /* Framework provides one set of channels(all)
7817 * common for all saved profile */
7818 if (0 != ccmCfgGetStr(hHal, WNI_CFG_VALID_CHANNEL_LIST,
7819 channels_allowed, &num_channels_allowed))
7820 {
7821 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7822 "%s: failed to get valid channel list", __func__);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307823 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307824 goto error;
7825 }
7826 /* Checking each channel against allowed channel list */
7827 num_ch = 0;
7828 for (i = 0; i < request->n_channels; i++)
7829 {
7830 for (indx = 0; indx < num_channels_allowed; indx++)
7831 {
7832 if (request->channels[i]->hw_value == channels_allowed[indx])
7833 {
7834 valid_ch[num_ch++] = request->channels[i]->hw_value;
7835 break ;
7836 }
7837 }
7838 }
7839
7840 /* Filling per profile params */
7841 for (i = 0; i < pPnoRequest->ucNetworksCount; i++)
7842 {
7843 pPnoRequest->aNetworks[i].ssId.length =
7844 request->match_sets[i].ssid.ssid_len;
7845
7846 if (( 0 == pPnoRequest->aNetworks[i].ssId.length ) ||
7847 ( pPnoRequest->aNetworks[i].ssId.length > 32 ) )
7848 {
7849 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7850 "SSID Len %d is not correct for network %d",
7851 pPnoRequest->aNetworks[i].ssId.length, i);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307852 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307853 goto error;
7854 }
7855
7856 memcpy(pPnoRequest->aNetworks[i].ssId.ssId,
7857 request->match_sets[i].ssid.ssid,
7858 request->match_sets[i].ssid.ssid_len);
7859 pPnoRequest->aNetworks[i].authentication = 0; /*eAUTH_TYPE_ANY*/
7860 pPnoRequest->aNetworks[i].encryption = 0; /*eED_ANY*/
7861 pPnoRequest->aNetworks[i].bcastNetwType = 0; /*eBCAST_UNKNOWN*/
7862
7863 /*Copying list of valid channel into request */
7864 memcpy(pPnoRequest->aNetworks[i].aChannels, valid_ch, num_ch);
7865 pPnoRequest->aNetworks[i].ucChannelCount = num_ch;
7866
7867 pPnoRequest->aNetworks[i].rssiThreshold = 0; //Default value
7868 }
7869
Madan Mohan Koyyalamudia7765d52013-09-18 16:49:56 +05307870 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
7871 "request->ie_len = %d", request->ie_len);
7872 if ((0 < request->ie_len) && (NULL != request->ie))
7873 {
7874 pPnoRequest->us24GProbeTemplateLen = request->ie_len;
7875 memcpy(&pPnoRequest->p24GProbeTemplate, request->ie,
7876 pPnoRequest->us24GProbeTemplateLen);
7877
7878 pPnoRequest->us5GProbeTemplateLen = request->ie_len;
7879 memcpy(&pPnoRequest->p5GProbeTemplate, request->ie,
7880 pPnoRequest->us5GProbeTemplateLen);
7881 }
7882
Madan Mohan Koyyalamudi1d16f462013-08-27 16:25:34 +05307883 /* Driver gets only one time interval which is hardcoded in
7884 * supplicant for 10000ms. Taking power consumption into account 6 timers
7885 * will be used, Timervalue is increased exponentially i.e 10,20,40,
7886 * 80,160,320 secs. And number of scan cycle for each timer
7887 * is configurable through INI param gPNOScanTimerRepeatValue.
7888 * If it is set to 0 only one timer will be used and PNO scan cycle
7889 * will be repeated after each interval specified by supplicant
7890 * till PNO is disabled.
7891 */
7892 if (0 == pHddCtx->cfg_ini->configPNOScanTimerRepeatValue)
7893 pPnoRequest->scanTimers.ucScanTimersCount = HDD_PNO_SCAN_TIMERS_SET_ONE;
7894 else
7895 pPnoRequest->scanTimers.ucScanTimersCount =
7896 HDD_PNO_SCAN_TIMERS_SET_MULTIPLE;
7897
7898 tempInterval = (request->interval)/1000;
7899 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
7900 "Base scan interval = %d PNOScanTimerRepeatValue = %d",
7901 tempInterval, pHddCtx->cfg_ini->configPNOScanTimerRepeatValue);
7902 for ( i = 0; i < pPnoRequest->scanTimers.ucScanTimersCount; i++)
7903 {
7904 pPnoRequest->scanTimers.aTimerValues[i].uTimerRepeat =
7905 pHddCtx->cfg_ini->configPNOScanTimerRepeatValue;
7906 pPnoRequest->scanTimers.aTimerValues[i].uTimerValue = tempInterval;
7907 tempInterval *= 2;
7908 }
7909 //Repeat last timer until pno disabled.
7910 pPnoRequest->scanTimers.aTimerValues[i-1].uTimerRepeat = 0;
7911
Madan Mohan Koyyalamudid206c7b2013-09-26 22:54:51 +05307912 pPnoRequest->modePNO = SIR_PNO_MODE_IMMEDIATE;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307913
7914 status = sme_SetPreferredNetworkList(WLAN_HDD_GET_HAL_CTX(pAdapter),
7915 pPnoRequest, pAdapter->sessionId,
7916 hdd_cfg80211_sched_scan_done_callback, pAdapter);
7917 if (eHAL_STATUS_SUCCESS != status)
7918 {
7919 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7920 "Failed to enable PNO");
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307921 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307922 goto error;
7923 }
7924
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05307925 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
7926 "PNO scanRequest offloaded");
7927
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307928error:
7929 vos_mem_free(pPnoRequest);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307930 return ret;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307931}
7932
7933/*
7934 * FUNCTION: wlan_hdd_cfg80211_sched_scan_stop
7935 * NL interface to disable PNO
7936 */
7937static int wlan_hdd_cfg80211_sched_scan_stop(struct wiphy *wiphy,
7938 struct net_device *dev)
7939{
7940 eHalStatus status = eHAL_STATUS_FAILURE;
7941 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7942 hdd_context_t *pHddCtx;
7943 tHalHandle hHal;
7944 tpSirPNOScanReq pPnoRequest = NULL;
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307945 int ret = 0;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307946
7947 ENTER();
7948
7949 if (NULL == pAdapter)
7950 {
7951 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
7952 "%s: HDD adapter is Null", __func__);
7953 return -ENODEV;
7954 }
7955
7956 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307957
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307958 if (NULL == pHddCtx)
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307959 {
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05307960 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307961 "%s: HDD context is Null", __func__);
7962 return -ENODEV;
7963 }
7964
7965 /* The return 0 is intentional when isLogpInProgress and
7966 * isLoadUnloadInProgress. We did observe a crash due to a return of
7967 * failure in sched_scan_stop , especially for a case where the unload
7968 * of the happens at the same time. The function __cfg80211_stop_sched_scan
7969 * was clearing rdev->sched_scan_req only when the sched_scan_stop returns
7970 * success. If it returns a failure , then its next invocation due to the
7971 * clean up of the second interface will have the dev pointer corresponding
7972 * to the first one leading to a crash.
7973 */
7974 if (pHddCtx->isLogpInProgress)
7975 {
7976 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7977 "%s: LOGP in Progress. Ignore!!!", __func__);
7978 return ret;
7979 }
7980
7981 if (pHddCtx->isLoadUnloadInProgress)
7982 {
7983 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7984 "%s: Unloading/Loading in Progress. Ignore!!!", __func__);
7985 return ret;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307986 }
7987
7988 hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
7989 if (NULL == hHal)
7990 {
7991 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7992 "%s: HAL context is Null!!!", __func__);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05307993 return -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307994 }
7995
7996 pPnoRequest = (tpSirPNOScanReq) vos_mem_malloc(sizeof (tSirPNOScanReq));
7997 if (NULL == pPnoRequest)
7998 {
7999 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8000 "%s: vos_mem_malloc failed", __func__);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308001 return -ENOMEM;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308002 }
8003
8004 memset(pPnoRequest, 0, sizeof (tSirPNOScanReq));
8005 pPnoRequest->enable = 0; /* Disable PNO */
8006 pPnoRequest->ucNetworksCount = 0;
8007
8008 status = sme_SetPreferredNetworkList(hHal, pPnoRequest,
8009 pAdapter->sessionId,
8010 NULL, pAdapter);
8011 if (eHAL_STATUS_SUCCESS != status)
8012 {
8013 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8014 "Failed to disabled PNO");
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308015 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308016 }
8017
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308018 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8019 "%s: PNO scan disabled", __func__);
8020
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308021 vos_mem_free(pPnoRequest);
8022
8023 EXIT();
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308024 return ret;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308025}
8026
8027#endif /*FEATURE_WLAN_SCAN_PNO*/
8028
8029
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008030#ifdef FEATURE_WLAN_TDLS
8031static int wlan_hdd_cfg80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
8032 u8 *peer, u8 action_code, u8 dialog_token,
8033 u16 status_code, const u8 *buf, size_t len)
8034{
8035
8036 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8037 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008038 u8 peerMac[6];
8039 VOS_STATUS status;
Gopichand Nakkala05922802013-03-14 12:23:19 -07008040 int max_sta_failed = 0;
Hoonki Leea34dd892013-02-05 22:56:02 -08008041 int responder;
Hoonki Leed37cbb32013-04-20 00:31:14 -07008042 long rc;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008043
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008044 if (NULL == pHddCtx || NULL == pHddCtx->cfg_ini)
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008045 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05308046 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008047 "Invalid arguments");
8048 return -EINVAL;
8049 }
8050
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08008051 if (pHddCtx->isLogpInProgress)
8052 {
8053 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8054 "%s:LOGP in Progress. Ignore!!!", __func__);
Gopichand Nakkala05922802013-03-14 12:23:19 -07008055 wlan_hdd_tdls_set_link_status(pAdapter, peer, eTDLS_LINK_IDLE);
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08008056 return -EBUSY;
8057 }
8058
Hoonki Lee27511902013-03-14 18:19:06 -07008059 if (eTDLS_SUPPORT_NOT_ENABLED == pHddCtx->tdls_mode)
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008060 {
Hoonki Lee27511902013-03-14 18:19:06 -07008061 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
8062 "%s: TDLS mode is disabled OR not enabled in FW."
8063 MAC_ADDRESS_STR " action %d declined.",
8064 __func__, MAC_ADDR_ARRAY(peer), action_code);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008065 return -ENOTSUPP;
8066 }
Lee Hoonkic1262f22013-01-24 21:59:00 -08008067
Hoonki Lee27511902013-03-14 18:19:06 -07008068 /* other than teardown frame, other mgmt frames are not sent if disabled */
8069 if (SIR_MAC_TDLS_TEARDOWN != action_code)
8070 {
8071 /* if tdls_mode is disabled to respond to peer's request */
8072 if (eTDLS_SUPPORT_DISABLED == pHddCtx->tdls_mode)
8073 {
8074 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
8075 "%s: " MAC_ADDRESS_STR
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07008076 " TDLS mode is disabled. action %d declined.",
8077 __func__, MAC_ADDR_ARRAY(peer), action_code);
Hoonki Lee27511902013-03-14 18:19:06 -07008078
8079 return -ENOTSUPP;
8080 }
8081 }
8082
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008083 if (WLAN_IS_TDLS_SETUP_ACTION(action_code))
8084 {
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05308085 if (NULL != wlan_hdd_tdls_is_progress(pHddCtx, peer, TRUE))
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008086 {
8087 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008088 "%s: " MAC_ADDRESS_STR
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07008089 " TDLS setup is ongoing. action %d declined.",
8090 __func__, MAC_ADDR_ARRAY(peer), action_code);
8091 return -EPERM;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008092 }
8093 }
8094
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008095 if (SIR_MAC_TDLS_SETUP_REQ == action_code ||
8096 SIR_MAC_TDLS_SETUP_RSP == action_code )
Lee Hoonkic1262f22013-01-24 21:59:00 -08008097 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08008098 if (HDD_MAX_NUM_TDLS_STA <= wlan_hdd_tdlsConnectedPeers(pAdapter))
Lee Hoonkic1262f22013-01-24 21:59:00 -08008099 {
8100 /* supplicant still sends tdls_mgmt(SETUP_REQ) even after
8101 we return error code at 'add_station()'. Hence we have this
8102 check again in addtion to add_station().
8103 Anyway, there is no hard to double-check. */
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008104 if (SIR_MAC_TDLS_SETUP_REQ == action_code)
Lee Hoonkic1262f22013-01-24 21:59:00 -08008105 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008106 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8107 "%s: " MAC_ADDRESS_STR
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07008108 " TDLS Max peer already connected. action %d declined.",
8109 __func__, MAC_ADDR_ARRAY(peer), action_code);
Gopichand Nakkala05922802013-03-14 12:23:19 -07008110 goto error;
Lee Hoonkic1262f22013-01-24 21:59:00 -08008111 }
8112 else
8113 {
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008114 /* maximum reached. tweak to send error code to peer and return
8115 error code to supplicant */
Lee Hoonkic1262f22013-01-24 21:59:00 -08008116 status_code = eSIR_MAC_UNSPEC_FAILURE_STATUS;
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008117 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8118 "%s: " MAC_ADDRESS_STR
8119 " TDLS Max peer already connected send response status %d",
8120 __func__, MAC_ADDR_ARRAY(peer), status_code);
Gopichand Nakkala05922802013-03-14 12:23:19 -07008121 max_sta_failed = -EPERM;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008122 /* fall through to send setup resp with failure status
8123 code */
Lee Hoonkic1262f22013-01-24 21:59:00 -08008124 }
8125 }
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008126 else
8127 {
8128 hddTdlsPeer_t *pTdlsPeer;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05308129 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peer, TRUE);
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07008130 if (pTdlsPeer && TDLS_IS_CONNECTED(pTdlsPeer))
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008131 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008132 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07008133 "%s:" MAC_ADDRESS_STR " already connected. action %d declined.",
8134 __func__, MAC_ADDR_ARRAY(peer), action_code);
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008135 return -EPERM;
8136 }
8137 }
Lee Hoonkic1262f22013-01-24 21:59:00 -08008138 }
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008139 vos_mem_copy(peerMac, peer, 6);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008140
Hoonki Lee1090c6a2013-01-16 17:40:54 -08008141#ifdef WLAN_FEATURE_TDLS_DEBUG
8142 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008143 "%s: " MAC_ADDRESS_STR " action %d, dialog_token %d status %d, len = %d",
8144 "tdls_mgmt", MAC_ADDR_ARRAY(peer),
8145 action_code, dialog_token, status_code, len);
Hoonki Lee1090c6a2013-01-16 17:40:54 -08008146#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008147
Hoonki Leea34dd892013-02-05 22:56:02 -08008148 /*Except teardown responder will not be used so just make 0*/
8149 responder = 0;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008150 if (SIR_MAC_TDLS_TEARDOWN == action_code)
Hoonki Leea34dd892013-02-05 22:56:02 -08008151 {
Gopichand Nakkala97a65fd2013-04-16 16:59:38 -07008152
8153 hddTdlsPeer_t *pTdlsPeer;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05308154 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peerMac, TRUE);
Gopichand Nakkala97a65fd2013-04-16 16:59:38 -07008155
8156 if(pTdlsPeer && TDLS_IS_CONNECTED(pTdlsPeer))
8157 responder = pTdlsPeer->is_responder;
8158 else
Hoonki Leea34dd892013-02-05 22:56:02 -08008159 {
Gopichand Nakkala97a65fd2013-04-16 16:59:38 -07008160 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8161 "%s: " MAC_ADDRESS_STR " peer doesn't exist or not connected %d dialog_token %d status %d, len = %d",
8162 __func__, MAC_ADDR_ARRAY(peer), (NULL == pTdlsPeer) ? -1 : pTdlsPeer->link_status,
8163 dialog_token, status_code, len);
8164 return -EPERM;
Hoonki Leea34dd892013-02-05 22:56:02 -08008165 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008166 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008167
Gopichand Nakkala2f1ff152013-07-01 11:27:43 +05308168 /* For explicit trigger of DIS_REQ come out of BMPS for
8169 successfully receiving DIS_RSP from peer. */
Hoonki Lee14621352013-04-16 17:51:19 -07008170 if ((SIR_MAC_TDLS_SETUP_RSP == action_code) ||
Gopichand Nakkala2f1ff152013-07-01 11:27:43 +05308171 (SIR_MAC_TDLS_DIS_RSP == action_code) ||
8172 (SIR_MAC_TDLS_DIS_REQ == action_code))
Hoonki Lee14621352013-04-16 17:51:19 -07008173 {
8174 if (TRUE == sme_IsPmcBmps(WLAN_HDD_GET_HAL_CTX(pAdapter)))
8175 {
8176 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
Gopichand Nakkala2f1ff152013-07-01 11:27:43 +05308177 "%s: Sending frame action_code %u.Disable BMPS", __func__, action_code);
Hoonki Lee14621352013-04-16 17:51:19 -07008178 hdd_disable_bmps_imps(pHddCtx, WLAN_HDD_INFRA_STATION);
8179 }
Gopichand Nakkala2f1ff152013-07-01 11:27:43 +05308180 if (SIR_MAC_TDLS_DIS_REQ != action_code)
8181 wlan_hdd_tdls_set_cap(pAdapter, peerMac, eTDLS_CAP_SUPPORTED);
Hoonki Lee14621352013-04-16 17:51:19 -07008182 }
8183
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008184 /* make sure doesn't call send_mgmt() while it is pending */
8185 if (TDLS_CTX_MAGIC == pAdapter->mgmtTxCompletionStatus)
8186 {
8187 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8188 "%s: " MAC_ADDRESS_STR " action %d couldn't sent, as one is pending. return EBUSY\n",
8189 __func__, MAC_ADDR_ARRAY(peer), action_code);
8190 return -EBUSY;
8191 }
8192
8193 pAdapter->mgmtTxCompletionStatus = TDLS_CTX_MAGIC;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008194 INIT_COMPLETION(pAdapter->tdls_mgmt_comp);
8195
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008196 status = sme_SendTdlsMgmtFrame(WLAN_HDD_GET_HAL_CTX(pAdapter), pAdapter->sessionId,
Hoonki Leea34dd892013-02-05 22:56:02 -08008197 peerMac, action_code, dialog_token, status_code, (tANI_U8 *)buf, len, responder);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008198
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008199 if (VOS_STATUS_SUCCESS != status)
8200 {
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008201 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8202 "%s: sme_SendTdlsMgmtFrame failed!", __func__);
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008203 pAdapter->mgmtTxCompletionStatus = FALSE;
Hoonki Lee14621352013-04-16 17:51:19 -07008204 wlan_hdd_tdls_check_bmps(pAdapter);
8205 goto error;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008206 }
8207
Hoonki Leed37cbb32013-04-20 00:31:14 -07008208 rc = wait_for_completion_interruptible_timeout(&pAdapter->tdls_mgmt_comp,
8209 msecs_to_jiffies(WAIT_TIME_TDLS_MGMT));
8210
8211 if ((rc <= 0) || (TRUE != pAdapter->mgmtTxCompletionStatus))
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008212 {
Hoonki Leed37cbb32013-04-20 00:31:14 -07008213 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8214 "%s: Mgmt Tx Completion failed status %ld TxCompletion %lu",
8215 __func__, rc, pAdapter->mgmtTxCompletionStatus);
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008216 pAdapter->mgmtTxCompletionStatus = FALSE;
Hoonki Leed37cbb32013-04-20 00:31:14 -07008217 wlan_hdd_tdls_check_bmps(pAdapter);
8218 goto error;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008219 }
8220
Gopichand Nakkala05922802013-03-14 12:23:19 -07008221 if (max_sta_failed)
Hoonki Lee14621352013-04-16 17:51:19 -07008222 {
8223 wlan_hdd_tdls_check_bmps(pAdapter);
Gopichand Nakkala05922802013-03-14 12:23:19 -07008224 return max_sta_failed;
Hoonki Lee14621352013-04-16 17:51:19 -07008225 }
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008226
Hoonki Leea34dd892013-02-05 22:56:02 -08008227 if (SIR_MAC_TDLS_SETUP_RSP == action_code)
8228 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08008229 wlan_hdd_tdls_set_responder(pAdapter, peerMac, TRUE);
Hoonki Leea34dd892013-02-05 22:56:02 -08008230 }
8231 else if (SIR_MAC_TDLS_SETUP_CNF == action_code)
8232 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08008233 wlan_hdd_tdls_set_responder(pAdapter, peerMac, FALSE);
Hoonki Leea34dd892013-02-05 22:56:02 -08008234 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008235
8236 return 0;
Gopichand Nakkala05922802013-03-14 12:23:19 -07008237error:
8238 /* max_sta_failed ; we didn't set to CONNECTING for this case,
8239 because we already know that this transaction will be failed,
8240 but we weren't sure if supplicant call DISABLE_LINK or not. So,
8241 to be safe, do not change the state mahine.
8242 */
8243 if(max_sta_failed == 0 &&
8244 (WLAN_IS_TDLS_SETUP_ACTION(action_code)))
8245 wlan_hdd_tdls_set_link_status(pAdapter, peerMac, eTDLS_LINK_IDLE);
8246 return -EPERM;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008247}
8248
8249static int wlan_hdd_cfg80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
8250 u8 *peer, enum nl80211_tdls_operation oper)
8251{
8252 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8253 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308254 int status;
Hoonki Lee1090c6a2013-01-16 17:40:54 -08008255#ifdef WLAN_FEATURE_TDLS_DEBUG
8256 const char *tdls_oper_str[]= {
8257 "NL80211_TDLS_DISCOVERY_REQ",
8258 "NL80211_TDLS_SETUP",
8259 "NL80211_TDLS_TEARDOWN",
8260 "NL80211_TDLS_ENABLE_LINK",
8261 "NL80211_TDLS_DISABLE_LINK",
Gopichand Nakkala29d00192013-06-20 19:03:52 +05308262 "NL80211_TDLS_UNKNOWN_OPER"};
Hoonki Lee1090c6a2013-01-16 17:40:54 -08008263#endif
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008264 hddTdlsPeer_t *pTdlsPeer;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008265
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308266 if ( NULL == peer )
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008267 {
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008268 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Chilam Ngc4244af2013-04-01 15:37:32 -07008269 "%s: Invalid arguments", __func__);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008270 return -EINVAL;
8271 }
Hoonki Lee1090c6a2013-01-16 17:40:54 -08008272
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308273 status = wlan_hdd_validate_context(pHddCtx);
8274
8275 if (0 != status)
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08008276 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308277 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8278 "%s: HDD context is not valid", __func__);
8279 return status;
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08008280 }
8281
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05308282 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peer, TRUE);
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008283
8284 if ( NULL == pTdlsPeer ) {
8285 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: " MAC_ADDRESS_STR " (oper %d) not exsting. ignored",
8286 __func__, MAC_ADDR_ARRAY(peer), (int)oper);
8287 return -EINVAL;
8288 }
8289
Hoonki Lee1090c6a2013-01-16 17:40:54 -08008290#ifdef WLAN_FEATURE_TDLS_DEBUG
8291 if((int)oper > 4)
8292 oper = 5;
8293
8294 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008295 "%s: " MAC_ADDRESS_STR " link_status %d (%s) ", "tdls_oper",
8296 MAC_ADDR_ARRAY(peer), pTdlsPeer->link_status,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008297 tdls_oper_str[(int)oper]);
Hoonki Lee1090c6a2013-01-16 17:40:54 -08008298#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008299
8300 if( FALSE == pHddCtx->cfg_ini->fEnableTDLSSupport ||
Hoonki Lee1090c6a2013-01-16 17:40:54 -08008301 FALSE == sme_IsFeatureSupportedByFW(TDLS))
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008302 {
Hoonki Lee1090c6a2013-01-16 17:40:54 -08008303 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Chilam Ngc4244af2013-04-01 15:37:32 -07008304 "TDLS Disabled in INI OR not enabled in FW. "
8305 "Cannot process TDLS commands");
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008306 return -ENOTSUPP;
8307 }
8308
8309 switch (oper) {
8310 case NL80211_TDLS_ENABLE_LINK:
8311 {
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008312 VOS_STATUS status;
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05308313 tCsrTdlsLinkEstablishParams tdlsLinkEstablishParams;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008314
Gopichand Nakkala2f4a2822013-04-17 11:22:01 -07008315 if (!TDLS_STA_INDEX_VALID(pTdlsPeer->staId))
8316 {
8317 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Staion Index %u "
8318 MAC_ADDRESS_STR " failed",
8319 __func__, pTdlsPeer->staId, MAC_ADDR_ARRAY(peer));
8320 return -EINVAL;
8321 }
8322
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008323 if (eTDLS_LINK_CONNECTED != pTdlsPeer->link_status)
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008324 {
Gopichand Nakkala24be5312013-07-02 16:47:12 +05308325 long ret;
Madan Mohan Koyyalamudice419872013-09-13 19:36:52 +05308326 if (IS_ADVANCE_TDLS_ENABLE) {
Gopichand Nakkala24be5312013-07-02 16:47:12 +05308327
Madan Mohan Koyyalamudice419872013-09-13 19:36:52 +05308328 if (0 != wlan_hdd_tdls_get_link_establish_params(
8329 pAdapter, peer,&tdlsLinkEstablishParams)) {
8330 return -EINVAL;
8331 }
8332 INIT_COMPLETION(pAdapter->tdls_link_establish_req_comp);
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05308333
Madan Mohan Koyyalamudice419872013-09-13 19:36:52 +05308334 sme_SendTdlsLinkEstablishParams(WLAN_HDD_GET_HAL_CTX(pAdapter),
8335 pAdapter->sessionId, peer, &tdlsLinkEstablishParams);
8336 /* Send TDLS peer UAPSD capabilities to the firmware and
8337 * register with the TL on after the response for this operation
8338 * is received .
8339 */
8340 ret = wait_for_completion_interruptible_timeout(
8341 &pAdapter->tdls_link_establish_req_comp,
8342 msecs_to_jiffies(WAIT_TIME_TDLS_LINK_ESTABLISH_REQ));
8343 if (ret <= 0)
8344 {
8345 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8346 "%s: Link Establish Request Faled Status %ld",
8347 __func__, ret);
8348 return -EINVAL;
8349 }
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05308350 }
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07008351 wlan_hdd_tdls_set_peer_link_status(pTdlsPeer, eTDLS_LINK_CONNECTED);
Gopichand Nakkala471708b2013-06-04 20:03:01 +05308352 /* Mark TDLS client Authenticated .*/
8353 status = WLANTL_ChangeSTAState( pHddCtx->pvosContext,
8354 pTdlsPeer->staId,
8355 WLANTL_STA_AUTHENTICATED);
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07008356 if (VOS_STATUS_SUCCESS == status)
8357 {
Hoonki Lee14621352013-04-16 17:51:19 -07008358 if (pTdlsPeer->is_responder == 0)
8359 {
8360 v_U8_t staId = (v_U8_t)pTdlsPeer->staId;
8361
8362 wlan_hdd_tdls_timer_restart(pAdapter,
8363 &pTdlsPeer->initiatorWaitTimeoutTimer,
8364 WAIT_TIME_TDLS_INITIATOR);
8365 /* suspend initiator TX until it receives direct packet from the
8366 reponder or WAIT_TIME_TDLS_INITIATOR timer expires */
8367 WLANTL_SuspendDataTx( (WLAN_HDD_GET_CTX(pAdapter))->pvosContext,
8368 &staId, NULL);
8369 }
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07008370 wlan_hdd_tdls_increment_peer_count(pAdapter);
8371 }
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008372 wlan_hdd_tdls_check_bmps(pAdapter);
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05308373
8374 /* Update TL about the UAPSD masks , to route the packets to firmware */
Gopichand Nakkala574f6d12013-06-27 19:38:43 +05308375 if ((TRUE == pHddCtx->cfg_ini->fEnableTDLSBufferSta)
8376 || pHddCtx->cfg_ini->fTDLSUapsdMask )
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05308377 {
Gopichand Nakkala574f6d12013-06-27 19:38:43 +05308378 int ac;
8379 uint8 ucAc[4] = { WLANTL_AC_VO,
8380 WLANTL_AC_VI,
8381 WLANTL_AC_BK,
8382 WLANTL_AC_BE };
8383 uint8 tlTid[4] = { 7, 5, 2, 3 } ;
8384 for(ac=0; ac < 4; ac++)
8385 {
8386 status = WLANTL_EnableUAPSDForAC( (WLAN_HDD_GET_CTX(pAdapter))->pvosContext,
8387 pTdlsPeer->staId, ucAc[ac],
8388 tlTid[ac], tlTid[ac], 0, 0,
8389 WLANTL_BI_DIR );
8390 }
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05308391 }
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008392 }
8393
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008394 }
8395 break;
8396 case NL80211_TDLS_DISABLE_LINK:
Lee Hoonkic1262f22013-01-24 21:59:00 -08008397 {
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008398 if(TDLS_STA_INDEX_VALID(pTdlsPeer->staId))
Lee Hoonkic1262f22013-01-24 21:59:00 -08008399 {
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07008400 long status;
8401
8402 INIT_COMPLETION(pAdapter->tdls_del_station_comp);
8403
Lee Hoonkic1262f22013-01-24 21:59:00 -08008404 sme_DeleteTdlsPeerSta( WLAN_HDD_GET_HAL_CTX(pAdapter),
8405 pAdapter->sessionId, peer );
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07008406
8407 status = wait_for_completion_interruptible_timeout(&pAdapter->tdls_del_station_comp,
8408 msecs_to_jiffies(WAIT_TIME_TDLS_DEL_STA));
8409 if (status <= 0)
8410 {
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008411 wlan_hdd_tdls_set_peer_link_status(pTdlsPeer, eTDLS_LINK_IDLE);
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07008412 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8413 "%s: Del station failed status %ld",
8414 __func__, status);
8415 return -EPERM;
8416 }
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008417 wlan_hdd_tdls_set_peer_link_status(pTdlsPeer, eTDLS_LINK_IDLE);
Lee Hoonkic1262f22013-01-24 21:59:00 -08008418 }
8419 else
8420 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008421 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8422 "%s: TDLS Peer Station doesn't exist.", __func__);
Lee Hoonkic1262f22013-01-24 21:59:00 -08008423 }
Lee Hoonkic1262f22013-01-24 21:59:00 -08008424 }
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008425 break;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008426 case NL80211_TDLS_TEARDOWN:
8427 case NL80211_TDLS_SETUP:
8428 case NL80211_TDLS_DISCOVERY_REQ:
8429 /* We don't support in-driver setup/teardown/discovery */
8430 return -ENOTSUPP;
8431 default:
8432 return -ENOTSUPP;
8433 }
8434 return 0;
8435}
Chilam NG571c65a2013-01-19 12:27:36 +05308436
8437int wlan_hdd_cfg80211_send_tdls_discover_req(struct wiphy *wiphy,
8438 struct net_device *dev, u8 *peer)
8439{
8440 hddLog(VOS_TRACE_LEVEL_INFO, "tdls send discover req: %x %x %x %x %x %x",
8441 peer[0], peer[1], peer[2], peer[3], peer[4], peer[5]);
8442
8443 return wlan_hdd_cfg80211_tdls_mgmt(wiphy, dev, peer,
8444 WLAN_TDLS_DISCOVERY_REQUEST, 1, 0, NULL, 0);
8445}
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008446#endif
8447
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308448#ifdef WLAN_FEATURE_GTK_OFFLOAD
8449/*
8450 * FUNCTION: wlan_hdd_cfg80211_update_replayCounterCallback
8451 * Callback rountine called upon receiving response for
8452 * get offload info
8453 */
8454void wlan_hdd_cfg80211_update_replayCounterCallback(void *callbackContext,
8455 tpSirGtkOffloadGetInfoRspParams pGtkOffloadGetInfoRsp)
8456{
8457
8458 hdd_adapter_t *pAdapter = (hdd_adapter_t *)callbackContext;
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308459 tANI_U8 tempReplayCounter[8];
8460 hdd_station_ctx_t *pHddStaCtx;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308461
8462 ENTER();
8463
8464 if (NULL == pAdapter)
8465 {
8466 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8467 "%s: HDD adapter is Null", __func__);
8468 return ;
8469 }
8470
8471 if (NULL == pGtkOffloadGetInfoRsp)
8472 {
8473 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8474 "%s: pGtkOffloadGetInfoRsp is Null", __func__);
8475 return ;
8476 }
8477
8478 if (VOS_STATUS_SUCCESS != pGtkOffloadGetInfoRsp->ulStatus)
8479 {
8480 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8481 "%s: wlan Failed to get replay counter value",
8482 __func__);
8483 return ;
8484 }
8485
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308486 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
8487 /* Update replay counter */
8488 pHddStaCtx->gtkOffloadReqParams.ullKeyReplayCounter =
8489 pGtkOffloadGetInfoRsp->ullKeyReplayCounter;
8490
8491 {
8492 /* changing from little to big endian since supplicant
8493 * works on big endian format
8494 */
8495 int i;
8496 tANI_U8 *p = (tANI_U8 *)&pGtkOffloadGetInfoRsp->ullKeyReplayCounter;
8497
8498 for (i = 0; i < 8; i++)
8499 {
8500 tempReplayCounter[7-i] = (tANI_U8)p[i];
8501 }
8502 }
8503
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308504 /* Update replay counter to NL */
8505 cfg80211_gtk_rekey_notify(pAdapter->dev, pGtkOffloadGetInfoRsp->bssId,
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308506 tempReplayCounter, GFP_KERNEL);
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308507}
8508
8509/*
8510 * FUNCTION: wlan_hdd_cfg80211_set_rekey_data
8511 * This function is used to offload GTK rekeying job to the firmware.
8512 */
8513int wlan_hdd_cfg80211_set_rekey_data(struct wiphy *wiphy, struct net_device *dev,
8514 struct cfg80211_gtk_rekey_data *data)
8515{
8516 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8517 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
8518 hdd_station_ctx_t *pHddStaCtx;
8519 tHalHandle hHal;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308520 int result;
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308521 tSirGtkOffloadParams hddGtkOffloadReqParams;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308522 eHalStatus status = eHAL_STATUS_FAILURE;
8523
8524 ENTER();
8525
8526 if (NULL == pAdapter)
8527 {
8528 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8529 "%s: HDD adapter is Null", __func__);
8530 return -ENODEV;
8531 }
8532
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308533 result = wlan_hdd_validate_context(pHddCtx);
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308534
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308535 if (0 != result)
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308536 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308537 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8538 "%s: HDD context is not valid", __func__);
8539 return result;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308540 }
8541
8542 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
8543 hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
8544 if (NULL == hHal)
8545 {
8546 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8547 "%s: HAL context is Null!!!", __func__);
8548 return -EAGAIN;
8549 }
8550
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308551 pHddStaCtx->gtkOffloadReqParams.ulFlags = GTK_OFFLOAD_ENABLE;
8552 memcpy(pHddStaCtx->gtkOffloadReqParams.aKCK, data->kck, NL80211_KCK_LEN);
8553 memcpy(pHddStaCtx->gtkOffloadReqParams.aKEK, data->kek, NL80211_KEK_LEN);
8554 memcpy(pHddStaCtx->gtkOffloadReqParams.bssId, &pHddStaCtx->conn_info.bssId,
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308555 WNI_CFG_BSSID_LEN);
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308556 {
8557 /* changing from big to little endian since driver
8558 * works on little endian format
8559 */
8560 tANI_U8 *p =
8561 (tANI_U8 *)&pHddStaCtx->gtkOffloadReqParams.ullKeyReplayCounter;
8562 int i;
8563
8564 for (i = 0; i < 8; i++)
8565 {
8566 p[7-i] = data->replay_ctr[i];
8567 }
8568 }
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308569
8570 if (TRUE == pHddCtx->hdd_wlan_suspended)
8571 {
8572 /* if wlan is suspended, enable GTK offload directly from here */
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308573 memcpy(&hddGtkOffloadReqParams, &pHddStaCtx->gtkOffloadReqParams,
8574 sizeof (tSirGtkOffloadParams));
8575 status = sme_SetGTKOffload(hHal, &hddGtkOffloadReqParams,
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308576 pAdapter->sessionId);
8577
8578 if (eHAL_STATUS_SUCCESS != status)
8579 {
8580 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8581 "%s: sme_SetGTKOffload failed, returned %d",
8582 __func__, status);
8583 return status;
8584 }
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308585 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8586 "%s: sme_SetGTKOffload successfull", __func__);
8587 }
8588 else
8589 {
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308590 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8591 "%s: wlan not suspended GTKOffload request is stored",
8592 __func__);
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308593 }
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308594
8595 return eHAL_STATUS_SUCCESS;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308596}
8597#endif /*WLAN_FEATURE_GTK_OFFLOAD*/
8598
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05308599/*
8600 * FUNCTION: wlan_hdd_cfg80211_set_mac_acl
8601 * This function is used to set access control policy
8602 */
8603static int wlan_hdd_cfg80211_set_mac_acl(struct wiphy *wiphy,
8604 struct net_device *dev, const struct cfg80211_acl_data *params)
8605{
8606 int i;
8607 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8608 hdd_hostapd_state_t *pHostapdState;
8609 tsap_Config_t *pConfig;
8610 v_CONTEXT_t pVosContext = NULL;
8611 hdd_context_t *pHddCtx;
8612 int status;
8613
8614 ENTER();
8615
8616 if (NULL == pAdapter)
8617 {
8618 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8619 "%s: HDD adapter is Null", __func__);
8620 return -ENODEV;
8621 }
8622
8623 if (NULL == params)
8624 {
8625 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8626 "%s: params is Null", __func__);
8627 return -EINVAL;
8628 }
8629
8630 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
8631 status = wlan_hdd_validate_context(pHddCtx);
8632
8633 if (0 != status)
8634 {
8635 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8636 "%s: HDD context is not valid", __func__);
8637 return status;
8638 }
8639
8640 pVosContext = pHddCtx->pvosContext;
8641 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
8642
8643 if (NULL == pHostapdState)
8644 {
8645 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8646 "%s: pHostapdState is Null", __func__);
8647 return -EINVAL;
8648 }
8649
8650 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,"acl policy: = %d"
8651 "no acl entries = %d", params->acl_policy, params->n_acl_entries);
8652
8653 if (WLAN_HDD_SOFTAP == pAdapter->device_mode)
8654 {
8655 pConfig = &pAdapter->sessionCtx.ap.sapConfig;
8656
8657 /* default value */
8658 pConfig->num_accept_mac = 0;
8659 pConfig->num_deny_mac = 0;
8660
8661 /**
8662 * access control policy
8663 * @NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED: Deny stations which are
8664 * listed in hostapd.deny file.
8665 * @NL80211_ACL_POLICY_DENY_UNLESS_LISTED: Allow stations which are
8666 * listed in hostapd.accept file.
8667 */
8668 if (NL80211_ACL_POLICY_DENY_UNLESS_LISTED == params->acl_policy)
8669 {
8670 pConfig->SapMacaddr_acl = eSAP_DENY_UNLESS_ACCEPTED;
8671 }
8672 else if (NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED == params->acl_policy)
8673 {
8674 pConfig->SapMacaddr_acl = eSAP_ACCEPT_UNLESS_DENIED;
8675 }
8676 else
8677 {
8678 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8679 "%s:Acl Policy : %d is not supported",
8680 __func__, params->acl_policy);
8681 return -ENOTSUPP;
8682 }
8683
8684 if (eSAP_DENY_UNLESS_ACCEPTED == pConfig->SapMacaddr_acl)
8685 {
8686 pConfig->num_accept_mac = params->n_acl_entries;
8687 for (i = 0; i < params->n_acl_entries; i++)
8688 {
8689 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8690 "** Add ACL MAC entry %i in WhiletList :"
8691 MAC_ADDRESS_STR, i,
8692 MAC_ADDR_ARRAY(params->mac_addrs[i].addr));
8693
8694 vos_mem_copy(&pConfig->accept_mac[i], params->mac_addrs[i].addr,
8695 sizeof(qcmacaddr));
8696 }
8697 }
8698 else if (eSAP_ACCEPT_UNLESS_DENIED == pConfig->SapMacaddr_acl)
8699 {
8700 pConfig->num_deny_mac = params->n_acl_entries;
8701 for (i = 0; i < params->n_acl_entries; i++)
8702 {
8703 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8704 "** Add ACL MAC entry %i in BlackList :"
8705 MAC_ADDRESS_STR, i,
8706 MAC_ADDR_ARRAY(params->mac_addrs[i].addr));
8707
8708 vos_mem_copy(&pConfig->deny_mac[i], params->mac_addrs[i].addr,
8709 sizeof(qcmacaddr));
8710 }
8711 }
8712
8713 if (VOS_STATUS_SUCCESS != WLANSAP_SetMacACL(pVosContext, pConfig))
8714 {
8715 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8716 "%s: SAP Set Mac Acl fail", __func__);
8717 return -EINVAL;
8718 }
8719 }
8720 else
8721 {
8722 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8723 "%s: Invalid device_mode = %d",
8724 __func__, pAdapter->device_mode);
8725 return -EINVAL;
8726 }
8727
8728 return 0;
8729}
8730
Leo Chang9056f462013-08-01 19:21:11 -07008731#ifdef WLAN_NL80211_TESTMODE
8732#ifdef FEATURE_WLAN_LPHB
Leo Changd9df8aa2013-09-26 13:32:26 -07008733void wlan_hdd_cfg80211_lphb_ind_handler
Leo Chang9056f462013-08-01 19:21:11 -07008734(
8735 void *pAdapter,
8736 void *indCont
8737)
8738{
Leo Changd9df8aa2013-09-26 13:32:26 -07008739 tSirLPHBInd *lphbInd;
8740 struct sk_buff *skb;
Leo Chang9056f462013-08-01 19:21:11 -07008741
8742 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Leo Changd9df8aa2013-09-26 13:32:26 -07008743 "LPHB indication arrived");
Leo Chang9056f462013-08-01 19:21:11 -07008744
8745 if (NULL == indCont)
8746 {
8747 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Leo Changd9df8aa2013-09-26 13:32:26 -07008748 "LPHB IND, invalid argument");
Leo Chang9056f462013-08-01 19:21:11 -07008749 return;
8750 }
8751
Leo Changd9df8aa2013-09-26 13:32:26 -07008752 lphbInd = (tSirLPHBInd *)indCont;
Leo Chang9056f462013-08-01 19:21:11 -07008753 skb = cfg80211_testmode_alloc_event_skb(
8754 ((hdd_adapter_t *)pAdapter)->wdev.wiphy,
Leo Changd9df8aa2013-09-26 13:32:26 -07008755 sizeof(tSirLPHBInd),
Leo Chang9056f462013-08-01 19:21:11 -07008756 GFP_ATOMIC);
8757 if (!skb)
8758 {
8759 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8760 "LPHB timeout, NL buffer alloc fail");
8761 return;
8762 }
8763
Leo Changd9df8aa2013-09-26 13:32:26 -07008764 if(!nla_put_u32(skb, WLAN_HDD_TM_ATTR_CMD, WLAN_HDD_TM_CMD_WLAN_HB))
8765 {
8766 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8767 "WLAN_HDD_TM_ATTR_CMD put fail");
8768 goto nla_put_failure;
8769 }
8770 if(!nla_put_u32(skb, WLAN_HDD_TM_ATTR_TYPE, lphbInd->protocolType))
8771 {
8772 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8773 "WLAN_HDD_TM_ATTR_TYPE put fail");
8774 goto nla_put_failure;
8775 }
8776 if(!nla_put(skb, WLAN_HDD_TM_ATTR_DATA,
8777 sizeof(tSirLPHBInd), lphbInd))
8778 {
8779 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8780 "WLAN_HDD_TM_ATTR_DATA put fail");
8781 goto nla_put_failure;
8782 }
Leo Chang9056f462013-08-01 19:21:11 -07008783 cfg80211_testmode_event(skb, GFP_ATOMIC);
8784 return;
8785
8786nla_put_failure:
8787 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8788 "NLA Put fail");
8789 kfree_skb(skb);
8790
8791 return;
8792}
8793#endif /* FEATURE_WLAN_LPHB */
8794
8795static int wlan_hdd_cfg80211_testmode(struct wiphy *wiphy, void *data, int len)
8796{
8797 struct nlattr *tb[WLAN_HDD_TM_ATTR_MAX + 1];
8798 int err = 0;
8799#ifdef FEATURE_WLAN_LPHB
8800 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
Leo Changd9df8aa2013-09-26 13:32:26 -07008801 eHalStatus smeStatus;
Leo Chang9056f462013-08-01 19:21:11 -07008802#endif /* FEATURE_WLAN_LPHB */
8803
8804 err = nla_parse(tb, WLAN_HDD_TM_ATTR_MAX, data, len, wlan_hdd_tm_policy);
8805 if (err)
8806 {
8807 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8808 "%s Testmode INV ATTR", __func__);
8809 return err;
8810 }
8811
8812 if (!tb[WLAN_HDD_TM_ATTR_CMD])
8813 {
8814 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8815 "%s Testmode INV CMD", __func__);
8816 return -EINVAL;
8817 }
8818
8819 switch (nla_get_u32(tb[WLAN_HDD_TM_ATTR_CMD]))
8820 {
8821#ifdef FEATURE_WLAN_LPHB
8822 /* Low Power Heartbeat configuration request */
8823 case WLAN_HDD_TM_CMD_WLAN_HB:
8824 {
8825 int buf_len;
8826 void *buf;
8827 tSirLPHBReq *hb_params = NULL;
8828
8829 if (!tb[WLAN_HDD_TM_ATTR_DATA])
8830 {
8831 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8832 "%s Testmode INV DATA", __func__);
8833 return -EINVAL;
8834 }
8835
8836 buf = nla_data(tb[WLAN_HDD_TM_ATTR_DATA]);
8837 buf_len = nla_len(tb[WLAN_HDD_TM_ATTR_DATA]);
8838 hb_params = (tSirLPHBReq *)vos_mem_malloc(sizeof(tSirLPHBReq));
8839 if (NULL == hb_params)
8840 {
8841 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8842 "%s Request Buffer Alloc Fail", __func__);
8843 return -EINVAL;
8844 }
8845
8846 vos_mem_copy(hb_params, buf, buf_len);
Leo Changd9df8aa2013-09-26 13:32:26 -07008847 smeStatus = sme_LPHBConfigReq((tHalHandle)(pHddCtx->hHal),
8848 hb_params,
8849 wlan_hdd_cfg80211_lphb_ind_handler);
8850 if (eHAL_STATUS_SUCCESS != smeStatus)
Leo Chang9056f462013-08-01 19:21:11 -07008851 {
Leo Changd9df8aa2013-09-26 13:32:26 -07008852 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8853 "LPHB Config Fail, disable");
Leo Chang9056f462013-08-01 19:21:11 -07008854 vos_mem_free(hb_params);
8855 }
Leo Chang9056f462013-08-01 19:21:11 -07008856 return 0;
8857 }
8858#endif /* FEATURE_WLAN_LPHB */
8859 default:
8860 return -EOPNOTSUPP;
8861 }
8862
8863 return err;
8864}
8865#endif /* CONFIG_NL80211_TESTMODE */
8866
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05308867static int wlan_hdd_cfg80211_dump_survey(struct wiphy *wiphy,
8868 struct net_device *dev,
8869 int idx, struct survey_info *survey)
8870{
8871 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8872 hdd_context_t *pHddCtx;
Mihir Sheted9072e02013-08-21 17:02:29 +05308873 hdd_station_ctx_t *pHddStaCtx;
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05308874 tHalHandle halHandle;
Mihir Sheted9072e02013-08-21 17:02:29 +05308875 v_U32_t channel = 0, freq = 0; /* Initialization Required */
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05308876 v_S7_t snr,rssi;
8877 int status, i, j, filled = 0;
8878
8879 ENTER();
8880
8881
8882 if (NULL == pAdapter)
8883 {
8884 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8885 "%s: HDD adapter is Null", __func__);
8886 return -ENODEV;
8887 }
8888
8889 if (NULL == wiphy)
8890 {
8891 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8892 "%s: wiphy is Null", __func__);
8893 return -ENODEV;
8894 }
8895
8896 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
8897 status = wlan_hdd_validate_context(pHddCtx);
8898
8899 if (0 != status)
8900 {
8901 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8902 "%s: HDD context is not valid", __func__);
8903 return status;
8904 }
8905
Mihir Sheted9072e02013-08-21 17:02:29 +05308906 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
8907
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05308908 if (0 == pHddCtx->cfg_ini->fEnableSNRMonitoring ||
Mihir Sheted9072e02013-08-21 17:02:29 +05308909 0 != pAdapter->survey_idx ||
8910 eConnectionState_Associated != pHddStaCtx->conn_info.connState)
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05308911 {
8912 /* The survey dump ops when implemented completely is expected to
8913 * return a survey of all channels and the ops is called by the
8914 * kernel with incremental values of the argument 'idx' till it
8915 * returns -ENONET. But we can only support the survey for the
8916 * operating channel for now. survey_idx is used to track
8917 * that the ops is called only once and then return -ENONET for
8918 * the next iteration
8919 */
8920 pAdapter->survey_idx = 0;
8921 return -ENONET;
8922 }
8923
8924 halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
8925
8926 wlan_hdd_get_snr(pAdapter, &snr);
8927 wlan_hdd_get_rssi(pAdapter, &rssi);
8928
8929 sme_GetOperationChannel(halHandle, &channel, pAdapter->sessionId);
8930 hdd_wlan_get_freq(channel, &freq);
8931
8932
8933 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
8934 {
8935 if (NULL == wiphy->bands[i])
8936 {
8937 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
8938 "%s: wiphy->bands[i] is NULL, i = %d", __func__, i);
8939 continue;
8940 }
8941
8942 for (j = 0; j < wiphy->bands[i]->n_channels; j++)
8943 {
8944 struct ieee80211_supported_band *band = wiphy->bands[i];
8945
8946 if (band->channels[j].center_freq == (v_U16_t)freq)
8947 {
8948 survey->channel = &band->channels[j];
8949 /* The Rx BDs contain SNR values in dB for the received frames
8950 * while the supplicant expects noise. So we calculate and
8951 * return the value of noise (dBm)
8952 * SNR (dB) = RSSI (dBm) - NOISE (dBm)
8953 */
8954 survey->noise = rssi - snr;
8955 survey->filled = SURVEY_INFO_NOISE_DBM;
8956 filled = 1;
8957 }
8958 }
8959 }
8960
8961 if (filled)
8962 pAdapter->survey_idx = 1;
8963 else
8964 {
8965 pAdapter->survey_idx = 0;
8966 return -ENONET;
8967 }
8968
8969 return 0;
8970}
8971
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308972/*
8973 * FUNCTION: wlan_hdd_cfg80211_resume_wlan
8974 * this is called when cfg80211 driver resume
8975 * driver updates latest sched_scan scan result(if any) to cfg80211 database
8976 */
8977int wlan_hdd_cfg80211_resume_wlan(struct wiphy *wiphy)
8978{
8979 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
8980 hdd_adapter_t *pAdapter;
8981 hdd_adapter_list_node_t *pAdapterNode, *pNext;
8982 VOS_STATUS status = VOS_STATUS_SUCCESS;
8983
8984 ENTER();
8985
8986 if ( NULL == pHddCtx )
8987 {
8988 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8989 "%s: HddCtx validation failed", __func__);
8990 return 0;
8991 }
8992
8993 if (pHddCtx->isLogpInProgress)
8994 {
8995 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8996 "%s: LOGP in Progress. Ignore!!!", __func__);
8997 return 0;
8998 }
8999
9000 if (pHddCtx->isLoadUnloadInProgress)
9001 {
9002 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9003 "%s: Unloading/Loading in Progress. Ignore!!!", __func__);
9004 return 0;
9005 }
9006
9007 spin_lock(&pHddCtx->schedScan_lock);
9008 pHddCtx->isWiphySuspended = FALSE;
9009 if (TRUE != pHddCtx->isSchedScanUpdatePending)
9010 {
9011 spin_unlock(&pHddCtx->schedScan_lock);
9012 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9013 "%s: Return resume is not due to PNO indication", __func__);
9014 return 0;
9015 }
9016 // Reset flag to avoid updatating cfg80211 data old results again
9017 pHddCtx->isSchedScanUpdatePending = FALSE;
9018 spin_unlock(&pHddCtx->schedScan_lock);
9019
9020 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
9021
9022 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
9023 {
9024 pAdapter = pAdapterNode->pAdapter;
9025 if ( (NULL != pAdapter) &&
9026 (WLAN_HDD_INFRA_STATION == pAdapter->device_mode) )
9027 {
9028 if (0 != wlan_hdd_cfg80211_update_bss(pHddCtx->wiphy, pAdapter))
9029 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
9030 "%s: NO SCAN result", __func__);
9031 else
9032 cfg80211_sched_scan_results(pHddCtx->wiphy);
9033
9034 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9035 "%s : cfg80211 scan result database updated", __func__);
9036
9037 return 0;
9038
9039 }
9040 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
9041 pAdapterNode = pNext;
9042 }
9043
9044 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9045 "%s: Failed to find Adapter", __func__);
9046 return 0;
9047}
9048
9049/*
9050 * FUNCTION: wlan_hdd_cfg80211_suspend_wlan
9051 * this is called when cfg80211 driver suspends
9052 */
9053int wlan_hdd_cfg80211_suspend_wlan(struct wiphy *wiphy,
9054 struct cfg80211_wowlan *wow)
9055{
9056 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
9057
9058 ENTER();
9059 if (NULL == pHddCtx)
9060 {
9061 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
9062 "%s: HddCtx validation failed", __func__);
9063 return 0;
9064 }
9065
9066 pHddCtx->isWiphySuspended = TRUE;
9067
9068 EXIT();
9069
9070 return 0;
9071}
9072
Jeff Johnson295189b2012-06-20 16:38:30 -07009073/* cfg80211_ops */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05309074static struct cfg80211_ops wlan_hdd_cfg80211_ops =
Jeff Johnson295189b2012-06-20 16:38:30 -07009075{
9076 .add_virtual_intf = wlan_hdd_add_virtual_intf,
9077 .del_virtual_intf = wlan_hdd_del_virtual_intf,
9078 .change_virtual_intf = wlan_hdd_cfg80211_change_iface,
9079 .change_station = wlan_hdd_change_station,
9080#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
9081 .add_beacon = wlan_hdd_cfg80211_add_beacon,
9082 .del_beacon = wlan_hdd_cfg80211_del_beacon,
9083 .set_beacon = wlan_hdd_cfg80211_set_beacon,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07009084#else
9085 .start_ap = wlan_hdd_cfg80211_start_ap,
9086 .change_beacon = wlan_hdd_cfg80211_change_beacon,
9087 .stop_ap = wlan_hdd_cfg80211_stop_ap,
Jeff Johnson295189b2012-06-20 16:38:30 -07009088#endif
9089 .change_bss = wlan_hdd_cfg80211_change_bss,
9090 .add_key = wlan_hdd_cfg80211_add_key,
9091 .get_key = wlan_hdd_cfg80211_get_key,
9092 .del_key = wlan_hdd_cfg80211_del_key,
9093 .set_default_key = wlan_hdd_cfg80211_set_default_key,
Jeff Johnson3bbe4bf2013-01-18 17:05:29 -08009094#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07009095 .set_channel = wlan_hdd_cfg80211_set_channel,
Jeff Johnson3bbe4bf2013-01-18 17:05:29 -08009096#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07009097 .scan = wlan_hdd_cfg80211_scan,
9098 .connect = wlan_hdd_cfg80211_connect,
9099 .disconnect = wlan_hdd_cfg80211_disconnect,
9100 .join_ibss = wlan_hdd_cfg80211_join_ibss,
9101 .leave_ibss = wlan_hdd_cfg80211_leave_ibss,
9102 .set_wiphy_params = wlan_hdd_cfg80211_set_wiphy_params,
9103 .set_tx_power = wlan_hdd_cfg80211_set_txpower,
9104 .get_tx_power = wlan_hdd_cfg80211_get_txpower,
Jeff Johnson295189b2012-06-20 16:38:30 -07009105 .remain_on_channel = wlan_hdd_cfg80211_remain_on_channel,
9106 .cancel_remain_on_channel = wlan_hdd_cfg80211_cancel_remain_on_channel,
9107 .mgmt_tx = wlan_hdd_action,
9108#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
9109 .mgmt_tx_cancel_wait = wlan_hdd_cfg80211_mgmt_tx_cancel_wait,
9110 .set_default_mgmt_key = wlan_hdd_set_default_mgmt_key,
9111 .set_txq_params = wlan_hdd_set_txq_params,
9112#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07009113 .get_station = wlan_hdd_cfg80211_get_station,
9114 .set_power_mgmt = wlan_hdd_cfg80211_set_power_mgmt,
9115 .del_station = wlan_hdd_cfg80211_del_station,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07009116 .add_station = wlan_hdd_cfg80211_add_station,
9117#ifdef FEATURE_WLAN_LFR
9118 .set_pmksa = wlan_hdd_cfg80211_set_pmksa,
9119 .del_pmksa = wlan_hdd_cfg80211_del_pmksa,
9120 .flush_pmksa = wlan_hdd_cfg80211_flush_pmksa,
9121#endif
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07009122#if defined(WLAN_FEATURE_VOWIFI_11R) && defined(KERNEL_SUPPORT_11R_CFG80211)
9123 .update_ft_ies = wlan_hdd_cfg80211_update_ft_ies,
9124#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -08009125#ifdef FEATURE_WLAN_TDLS
9126 .tdls_mgmt = wlan_hdd_cfg80211_tdls_mgmt,
9127 .tdls_oper = wlan_hdd_cfg80211_tdls_oper,
9128#endif
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309129#ifdef WLAN_FEATURE_GTK_OFFLOAD
9130 .set_rekey_data = wlan_hdd_cfg80211_set_rekey_data,
9131#endif /* WLAN_FEATURE_GTK_OFFLOAD */
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05309132#ifdef FEATURE_WLAN_SCAN_PNO
9133 .sched_scan_start = wlan_hdd_cfg80211_sched_scan_start,
9134 .sched_scan_stop = wlan_hdd_cfg80211_sched_scan_stop,
9135#endif /*FEATURE_WLAN_SCAN_PNO */
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05309136 .resume = wlan_hdd_cfg80211_resume_wlan,
9137 .suspend = wlan_hdd_cfg80211_suspend_wlan,
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05309138 .set_mac_acl = wlan_hdd_cfg80211_set_mac_acl,
Leo Chang9056f462013-08-01 19:21:11 -07009139#ifdef WLAN_NL80211_TESTMODE
9140 .testmode_cmd = wlan_hdd_cfg80211_testmode,
9141#endif
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05309142 .dump_survey = wlan_hdd_cfg80211_dump_survey,
Jeff Johnson295189b2012-06-20 16:38:30 -07009143};
9144