blob: f1be3ff369c31e8dbc95c1292946a966261bfd36 [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
Kiet Lam6c583332013-10-14 05:37:09 +0530642#ifndef CONFIG_ENABLE_LINUX_REG
Amar Singhal0a402232013-10-11 20:57:16 -0700643 /* the flag for the other case would be initialzed in
644 vos_init_wiphy_from_nv_bin */
Amar Singhal0a402232013-10-11 20:57:16 -0700645 wiphy->flags |= WIPHY_FLAG_STRICT_REGULATORY;
Kiet Lam6c583332013-10-14 05:37:09 +0530646#endif
Amar Singhala49cbc52013-10-08 18:37:44 -0700647
Amar Singhalfddc28c2013-09-05 13:03:40 -0700648 /* This will disable updating of NL channels from passive to
649 * active if a beacon is received on passive channel. */
650 wiphy->flags |= WIPHY_FLAG_DISABLE_BEACON_HINTS;
Amar Singhalf0073192013-09-20 12:34:56 -0700651
Amar Singhalfddc28c2013-09-05 13:03:40 -0700652
Amar Singhala49cbc52013-10-08 18:37:44 -0700653
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700654#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
Madan Mohan Koyyalamudi1b4afb02012-10-22 15:25:16 -0700655 wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME
656 | WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
657 | WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
Jeff Johnsone7245742012-09-05 17:12:55 -0700658 | WIPHY_FLAG_OFFCHAN_TX;
Kiet Lam6c583332013-10-14 05:37:09 +0530659 wiphy->country_ie_pref = NL80211_COUNTRY_IE_IGNORE_CORE;
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700660#endif
Amar Singhala49cbc52013-10-08 18:37:44 -0700661
Srinivas Girigowda640728a2013-03-28 12:21:54 -0700662#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_CCX) || defined(FEATURE_WLAN_LFR)
663 if (pCfg->isFastTransitionEnabled
James Zmuda77fb5ae2013-01-29 08:00:17 -0800664#ifdef FEATURE_WLAN_LFR
Srinivas Girigowda640728a2013-03-28 12:21:54 -0700665 || pCfg->isFastRoamIniFeatureEnabled
666#endif
667#ifdef FEATURE_WLAN_CCX
668 || pCfg->isCcxIniFeatureEnabled
669#endif
670 )
671 {
672 wiphy->flags |= WIPHY_FLAG_SUPPORTS_FW_ROAM;
673 }
James Zmuda77fb5ae2013-01-29 08:00:17 -0800674#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -0800675#ifdef FEATURE_WLAN_TDLS
676 wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS
677 | WIPHY_FLAG_TDLS_EXTERNAL_SETUP;
678#endif
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +0530679#ifdef FEATURE_WLAN_SCAN_PNO
680 wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
Madan Mohan Koyyalamudi75de0102013-09-17 14:56:29 +0530681 wiphy->max_sched_scan_ssids = SIR_PNO_MAX_SUPP_NETWORKS;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +0530682 wiphy->max_match_sets = SIR_PNO_MAX_SUPP_NETWORKS;
Madan Mohan Koyyalamudia7765d52013-09-18 16:49:56 +0530683 wiphy->max_sched_scan_ie_len = SIR_MAC_MAX_IE_LENGTH;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +0530684#endif/*FEATURE_WLAN_SCAN_PNO*/
Mohit Khanna698ba2a2012-12-04 15:08:18 -0800685
Amar Singhalfddc28c2013-09-05 13:03:40 -0700686#ifdef CONFIG_ENABLE_LINUX_REG
Madan Mohan Koyyalamudic3a240c2012-09-28 15:34:08 -0700687 /* even with WIPHY_FLAG_CUSTOM_REGULATORY,
688 driver can still register regulatory callback and
Amar Singhalfddc28c2013-09-05 13:03:40 -0700689 it will get regulatory settings in wiphy->band[], but
Madan Mohan Koyyalamudic3a240c2012-09-28 15:34:08 -0700690 driver need to determine what to do with both
691 regulatory settings */
Amar Singhalfddc28c2013-09-05 13:03:40 -0700692
693 wiphy->reg_notifier = wlan_hdd_linux_reg_notifier;
Amar Singhala49cbc52013-10-08 18:37:44 -0700694#else
695 wiphy->reg_notifier = wlan_hdd_crda_reg_notifier;
Amar Singhalfddc28c2013-09-05 13:03:40 -0700696#endif
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700697
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530698 wiphy->max_scan_ssids = MAX_SCAN_SSID;
699
Madan Mohan Koyyalamudi6815b162013-07-19 17:17:46 +0530700 wiphy->max_scan_ie_len = SIR_MAC_MAX_IE_LENGTH;
Jeff Johnson295189b2012-06-20 16:38:30 -0700701
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +0530702 wiphy->max_acl_mac_addrs = MAX_ACL_MAC_ADDRESS;
703
Jeff Johnson295189b2012-06-20 16:38:30 -0700704 /* Supports STATION & AD-HOC modes right now */
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530705 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION)
Jeff Johnson295189b2012-06-20 16:38:30 -0700706 | BIT(NL80211_IFTYPE_ADHOC)
Jeff Johnson295189b2012-06-20 16:38:30 -0700707 | BIT(NL80211_IFTYPE_P2P_CLIENT)
708 | BIT(NL80211_IFTYPE_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -0700709 | BIT(NL80211_IFTYPE_AP);
710
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800711#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800712 if( pCfg->enableMCC )
713 {
714 /* Currently, supports up to two channels */
715 wlan_hdd_iface_combination.num_different_channels = 2;
716
717 if( !pCfg->allowMCCGODiffBI )
718 wlan_hdd_iface_combination.beacon_int_infra_match = true;
719
720 }
721 wiphy->iface_combinations = &wlan_hdd_iface_combination;
722 wiphy->n_iface_combinations = 1;
723#endif
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800724
Jeff Johnson295189b2012-06-20 16:38:30 -0700725 /* Before registering we need to update the ht capabilitied based
726 * on ini values*/
727 if( !pCfg->ShortGI20MhzEnable )
728 {
729 wlan_hdd_band_2_4_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_20;
730 wlan_hdd_band_5_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_20;
731 wlan_hdd_band_p2p_2_4_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_20;
732 }
733
734 if( !pCfg->ShortGI40MhzEnable )
735 {
736 wlan_hdd_band_5_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_40;
737 }
738
739 if( !pCfg->nChannelBondingMode5GHz )
740 {
741 wlan_hdd_band_5_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
742 }
743
Gopichand Nakkala1f7a64f2013-04-01 18:37:17 +0530744 wiphy->bands[IEEE80211_BAND_2GHZ] = &wlan_hdd_band_2_4_GHZ;
745 wiphy->bands[IEEE80211_BAND_5GHZ] = &wlan_hdd_band_5_GHZ;
746
747 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
748 {
749
750 if (NULL == wiphy->bands[i])
751 {
752 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy->bands[i] is NULL, i = %d",
753 __func__, i);
754 continue;
755 }
756
757 for (j = 0; j < wiphy->bands[i]->n_channels; j++)
758 {
759 struct ieee80211_supported_band *band = wiphy->bands[i];
760
761 if (IEEE80211_BAND_2GHZ == i && eCSR_BAND_5G == pCfg->nBandCapability) // 5G only
762 {
763 // Enable social channels for P2P
764 if (WLAN_HDD_IS_SOCIAL_CHANNEL(band->channels[j].center_freq))
765 band->channels[j].flags &= ~IEEE80211_CHAN_DISABLED;
766 else
767 band->channels[j].flags |= IEEE80211_CHAN_DISABLED;
768 continue;
769 }
770 else if (IEEE80211_BAND_5GHZ == i && eCSR_BAND_24 == pCfg->nBandCapability) // 2G only
771 {
772 band->channels[j].flags |= IEEE80211_CHAN_DISABLED;
773 continue;
774 }
775 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700776 }
777 /*Initialise the supported cipher suite details*/
778 wiphy->cipher_suites = hdd_cipher_suites;
779 wiphy->n_cipher_suites = ARRAY_SIZE(hdd_cipher_suites);
780
781 /*signal strength in mBm (100*dBm) */
782 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
783
784#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
Jeff Johnson295189b2012-06-20 16:38:30 -0700785 wiphy->max_remain_on_channel_duration = 1000;
786#endif
Jeff Johnson295189b2012-06-20 16:38:30 -0700787
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530788 EXIT();
789 return 0;
790}
791
792/* In this function we are registering wiphy. */
793int wlan_hdd_cfg80211_register(struct wiphy *wiphy)
794{
795 ENTER();
796 /* Register our wiphy dev with cfg80211 */
Jeff Johnson295189b2012-06-20 16:38:30 -0700797 if (0 > wiphy_register(wiphy))
798 {
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530799 /* print error */
Jeff Johnson295189b2012-06-20 16:38:30 -0700800 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy register failed", __func__);
801 return -EIO;
802 }
803
804 EXIT();
805 return 0;
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530806}
Jeff Johnson295189b2012-06-20 16:38:30 -0700807
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530808/* In this function we are updating channel list when,
809 regulatory domain is FCC and country code is US.
810 Here In FCC standard 5GHz UNII-1 Bands are indoor only.
811 As per FCC smart phone is not a indoor device.
812 GO should not opeate on indoor channels */
813void wlan_hdd_cfg80211_update_reg_info(struct wiphy *wiphy)
814{
815 int j;
816 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
817 tANI_U8 defaultCountryCode[3] = SME_INVALID_COUNTRY_CODE;
818 //Default counrtycode from NV at the time of wiphy initialization.
819 if (eHAL_STATUS_SUCCESS != sme_GetDefaultCountryCodeFrmNv(pHddCtx->hHal,
820 &defaultCountryCode[0]))
821 {
Jeff Johnson0299d0a2013-10-30 12:37:43 -0700822 hddLog(LOGE, FL("Failed to get default country code from NV"));
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530823 }
824 if ((defaultCountryCode[0]== 'U') && (defaultCountryCode[1]=='S'))
825 {
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530826 if (NULL == wiphy->bands[IEEE80211_BAND_5GHZ])
827 {
828 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy->bands[IEEE80211_BAND_5GHZ] is NULL",__func__ );
829 return;
830 }
831 for (j = 0; j < wiphy->bands[IEEE80211_BAND_5GHZ]->n_channels; j++)
832 {
833 struct ieee80211_supported_band *band = wiphy->bands[IEEE80211_BAND_5GHZ];
834 // Mark UNII -1 band channel as passive
835 if (WLAN_HDD_CHANNEL_IN_UNII_1_BAND(band->channels[j].center_freq))
836 band->channels[j].flags |= IEEE80211_CHAN_PASSIVE_SCAN;
837 }
838 }
839}
840
Jeff Johnson295189b2012-06-20 16:38:30 -0700841/* In this function we will do all post VOS start initialization.
842 In this function we will register for all frame in which supplicant
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530843 is interested.
Jeff Johnson295189b2012-06-20 16:38:30 -0700844*/
845void wlan_hdd_cfg80211_post_voss_start(hdd_adapter_t* pAdapter)
846{
Jeff Johnson295189b2012-06-20 16:38:30 -0700847 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
848 /* Register for all P2P action, public action etc frames */
849 v_U16_t type = (SIR_MAC_MGMT_FRAME << 2) | ( SIR_MAC_MGMT_ACTION << 4);
850
Jeff Johnsone7245742012-09-05 17:12:55 -0700851 ENTER();
852
Jeff Johnson295189b2012-06-20 16:38:30 -0700853 /* Right now we are registering these frame when driver is getting
854 initialized. Once we will move to 2.6.37 kernel, in which we have
855 frame register ops, we will move this code as a part of that */
856 /* GAS Initial Request */
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530857 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
Jeff Johnson295189b2012-06-20 16:38:30 -0700858 (v_U8_t*)GAS_INITIAL_REQ, GAS_INITIAL_REQ_SIZE );
859
860 /* GAS Initial Response */
861 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
862 (v_U8_t*)GAS_INITIAL_RSP, GAS_INITIAL_RSP_SIZE );
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530863
Jeff Johnson295189b2012-06-20 16:38:30 -0700864 /* GAS Comeback Request */
865 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
866 (v_U8_t*)GAS_COMEBACK_REQ, GAS_COMEBACK_REQ_SIZE );
867
868 /* GAS Comeback Response */
869 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
870 (v_U8_t*)GAS_COMEBACK_RSP, GAS_COMEBACK_RSP_SIZE );
871
872 /* P2P Public Action */
873 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530874 (v_U8_t*)P2P_PUBLIC_ACTION_FRAME,
Jeff Johnson295189b2012-06-20 16:38:30 -0700875 P2P_PUBLIC_ACTION_FRAME_SIZE );
876
877 /* P2P Action */
878 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
879 (v_U8_t*)P2P_ACTION_FRAME,
880 P2P_ACTION_FRAME_SIZE );
Chet Lanctot186b5732013-03-18 10:26:30 -0700881
Gopichand Nakkalae3d56e72013-04-21 23:33:32 +0530882 /* WNM BSS Transition Request frame */
883 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
884 (v_U8_t*)WNM_BSS_ACTION_FRAME,
885 WNM_BSS_ACTION_FRAME_SIZE );
886
Chet Lanctot186b5732013-03-18 10:26:30 -0700887#ifdef WLAN_FEATURE_11W
888 /* SA Query Response Action Frame */
889 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
890 (v_U8_t*)SA_QUERY_FRAME_RSP,
891 SA_QUERY_FRAME_RSP_SIZE );
892#endif /* WLAN_FEATURE_11W */
Jeff Johnson295189b2012-06-20 16:38:30 -0700893}
894
895void wlan_hdd_cfg80211_pre_voss_stop(hdd_adapter_t* pAdapter)
896{
Jeff Johnson295189b2012-06-20 16:38:30 -0700897 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
898 /* Register for all P2P action, public action etc frames */
899 v_U16_t type = (SIR_MAC_MGMT_FRAME << 2) | ( SIR_MAC_MGMT_ACTION << 4);
900
Jeff Johnsone7245742012-09-05 17:12:55 -0700901 ENTER();
902
Jeff Johnson295189b2012-06-20 16:38:30 -0700903 /* Right now we are registering these frame when driver is getting
904 initialized. Once we will move to 2.6.37 kernel, in which we have
905 frame register ops, we will move this code as a part of that */
906 /* GAS Initial Request */
907
908 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
909 (v_U8_t*)GAS_INITIAL_REQ, GAS_INITIAL_REQ_SIZE );
910
911 /* GAS Initial Response */
912 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
913 (v_U8_t*)GAS_INITIAL_RSP, GAS_INITIAL_RSP_SIZE );
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530914
Jeff Johnson295189b2012-06-20 16:38:30 -0700915 /* GAS Comeback Request */
916 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
917 (v_U8_t*)GAS_COMEBACK_REQ, GAS_COMEBACK_REQ_SIZE );
918
919 /* GAS Comeback Response */
920 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
921 (v_U8_t*)GAS_COMEBACK_RSP, GAS_COMEBACK_RSP_SIZE );
922
923 /* P2P Public Action */
924 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530925 (v_U8_t*)P2P_PUBLIC_ACTION_FRAME,
Jeff Johnson295189b2012-06-20 16:38:30 -0700926 P2P_PUBLIC_ACTION_FRAME_SIZE );
927
928 /* P2P Action */
929 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
930 (v_U8_t*)P2P_ACTION_FRAME,
931 P2P_ACTION_FRAME_SIZE );
Chet Lanctot186b5732013-03-18 10:26:30 -0700932
933#ifdef WLAN_FEATURE_11W
934 /* SA Query Response Action Frame */
935 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
936 (v_U8_t*)SA_QUERY_FRAME_RSP,
937 SA_QUERY_FRAME_RSP_SIZE );
938#endif /* WLAN_FEATURE_11W */
Jeff Johnson295189b2012-06-20 16:38:30 -0700939}
940
941#ifdef FEATURE_WLAN_WAPI
942void wlan_hdd_cfg80211_set_key_wapi(hdd_adapter_t* pAdapter, u8 key_index,
943 const u8 *mac_addr, u8 *key , int key_Len)
944{
945 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
946 tCsrRoamSetKey setKey;
947 v_BOOL_t isConnected = TRUE;
948 int status = 0;
949 v_U32_t roamId= 0xFF;
950 tANI_U8 *pKeyPtr = NULL;
951 int n = 0;
952
953 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
954 __func__,pAdapter->device_mode);
955
Gopichand Nakkalae7480202013-02-11 15:24:22 +0530956 vos_mem_zero(&setKey, sizeof(tCsrRoamSetKey));
Jeff Johnson295189b2012-06-20 16:38:30 -0700957 setKey.keyId = key_index; // Store Key ID
958 setKey.encType = eCSR_ENCRYPT_TYPE_WPI; // SET WAPI Encryption
959 setKey.keyDirection = eSIR_TX_RX; // Key Directionn both TX and RX
960 setKey.paeRole = 0 ; // the PAE role
961 if (!mac_addr || is_broadcast_ether_addr(mac_addr))
962 {
963 vos_set_macaddr_broadcast( (v_MACADDR_t *)setKey.peerMac );
964 }
965 else
966 {
967 isConnected = hdd_connIsConnected(pHddStaCtx);
968 vos_mem_copy(setKey.peerMac,&pHddStaCtx->conn_info.bssId,WNI_CFG_BSSID_LEN);
969 }
970 setKey.keyLength = key_Len;
971 pKeyPtr = setKey.Key;
972 memcpy( pKeyPtr, key, key_Len);
973
974 hddLog(VOS_TRACE_LEVEL_INFO,"\n%s: WAPI KEY LENGTH:0x%04x",
975 __func__, key_Len);
976 for (n = 0 ; n < key_Len; n++)
977 hddLog(VOS_TRACE_LEVEL_INFO, "%s WAPI KEY Data[%d]:%02x ",
978 __func__,n,setKey.Key[n]);
979
980 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_SETTING_KEY;
981 if ( isConnected )
982 {
983 status= sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
984 pAdapter->sessionId, &setKey, &roamId );
985 }
986 if ( status != 0 )
987 {
988 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
989 "[%4d] sme_RoamSetKey returned ERROR status= %d",
990 __LINE__, status );
991 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
992 }
993}
994#endif /* FEATURE_WLAN_WAPI*/
995
996#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530997int wlan_hdd_cfg80211_alloc_new_beacon(hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -0700998 beacon_data_t **ppBeacon,
999 struct beacon_parameters *params)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001000#else
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301001int wlan_hdd_cfg80211_alloc_new_beacon(hdd_adapter_t *pAdapter,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001002 beacon_data_t **ppBeacon,
1003 struct cfg80211_beacon_data *params,
1004 int dtim_period)
1005#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301006{
Jeff Johnson295189b2012-06-20 16:38:30 -07001007 int size;
1008 beacon_data_t *beacon = NULL;
1009 beacon_data_t *old = NULL;
1010 int head_len,tail_len;
1011
Jeff Johnsone7245742012-09-05 17:12:55 -07001012 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07001013 if (params->head && !params->head_len)
1014 return -EINVAL;
1015
1016 old = pAdapter->sessionCtx.ap.beacon;
1017
1018 if (!params->head && !old)
1019 return -EINVAL;
1020
1021 if (params->tail && !params->tail_len)
1022 return -EINVAL;
1023
1024#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,38))
1025 /* Kernel 3.0 is not updating dtim_period for set beacon */
1026 if (!params->dtim_period)
1027 return -EINVAL;
1028#endif
1029
1030 if(params->head)
1031 head_len = params->head_len;
1032 else
1033 head_len = old->head_len;
1034
1035 if(params->tail || !old)
1036 tail_len = params->tail_len;
1037 else
1038 tail_len = old->tail_len;
1039
1040 size = sizeof(beacon_data_t) + head_len + tail_len;
1041
1042 beacon = kzalloc(size, GFP_KERNEL);
1043
1044 if( beacon == NULL )
1045 return -ENOMEM;
1046
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001047#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07001048 if(params->dtim_period || !old )
1049 beacon->dtim_period = params->dtim_period;
1050 else
1051 beacon->dtim_period = old->dtim_period;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001052#else
1053 if(dtim_period || !old )
1054 beacon->dtim_period = dtim_period;
1055 else
1056 beacon->dtim_period = old->dtim_period;
1057#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301058
Jeff Johnson295189b2012-06-20 16:38:30 -07001059 beacon->head = ((u8 *) beacon) + sizeof(beacon_data_t);
1060 beacon->tail = beacon->head + head_len;
1061 beacon->head_len = head_len;
1062 beacon->tail_len = tail_len;
1063
1064 if(params->head) {
1065 memcpy (beacon->head,params->head,beacon->head_len);
1066 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301067 else {
Jeff Johnson295189b2012-06-20 16:38:30 -07001068 if(old)
1069 memcpy (beacon->head,old->head,beacon->head_len);
1070 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301071
Jeff Johnson295189b2012-06-20 16:38:30 -07001072 if(params->tail) {
1073 memcpy (beacon->tail,params->tail,beacon->tail_len);
1074 }
1075 else {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301076 if(old)
Jeff Johnson295189b2012-06-20 16:38:30 -07001077 memcpy (beacon->tail,old->tail,beacon->tail_len);
1078 }
1079
1080 *ppBeacon = beacon;
1081
1082 kfree(old);
1083
1084 return 0;
1085
1086}
Jeff Johnson295189b2012-06-20 16:38:30 -07001087
1088v_U8_t* wlan_hdd_cfg80211_get_ie_ptr(v_U8_t *pIes, int length, v_U8_t eid)
1089{
1090 int left = length;
1091 v_U8_t *ptr = pIes;
1092 v_U8_t elem_id,elem_len;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301093
Jeff Johnson295189b2012-06-20 16:38:30 -07001094 while(left >= 2)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301095 {
Jeff Johnson295189b2012-06-20 16:38:30 -07001096 elem_id = ptr[0];
1097 elem_len = ptr[1];
1098 left -= 2;
1099 if(elem_len > left)
1100 {
1101 hddLog(VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi8bdd3112012-09-24 13:55:14 -07001102 FL("****Invalid IEs eid = %d elem_len=%d left=%d*****"),
Jeff Johnson295189b2012-06-20 16:38:30 -07001103 eid,elem_len,left);
1104 return NULL;
1105 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301106 if (elem_id == eid)
Jeff Johnson295189b2012-06-20 16:38:30 -07001107 {
1108 return ptr;
1109 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301110
Jeff Johnson295189b2012-06-20 16:38:30 -07001111 left -= elem_len;
1112 ptr += (elem_len + 2);
1113 }
1114 return NULL;
1115}
1116
Jeff Johnson295189b2012-06-20 16:38:30 -07001117/* Check if rate is 11g rate or not */
1118static int wlan_hdd_rate_is_11g(u8 rate)
1119{
Sanjay Devnani28322e22013-06-21 16:13:40 -07001120 static const u8 gRateArray[8] = {12, 18, 24, 36, 48, 72, 96, 108}; /* actual rate * 2 */
Jeff Johnson295189b2012-06-20 16:38:30 -07001121 u8 i;
1122 for (i = 0; i < 8; i++)
1123 {
1124 if(rate == gRateArray[i])
1125 return TRUE;
1126 }
1127 return FALSE;
1128}
1129
1130/* Check for 11g rate and set proper 11g only mode */
1131static void wlan_hdd_check_11gmode(u8 *pIe, u8* require_ht,
1132 u8* pCheckRatesfor11g, eSapPhyMode* pSapHw_mode)
1133{
1134 u8 i, num_rates = pIe[0];
1135
1136 pIe += 1;
1137 for ( i = 0; i < num_rates; i++)
1138 {
1139 if( *pCheckRatesfor11g && (TRUE == wlan_hdd_rate_is_11g(pIe[i] & RATE_MASK)))
1140 {
1141 /* If rate set have 11g rate than change the mode to 11G */
1142 *pSapHw_mode = eSAP_DOT11_MODE_11g;
1143 if (pIe[i] & BASIC_RATE_MASK)
1144 {
1145 /* If we have 11g rate as basic rate, it means mode
1146 is 11g only mode.
1147 */
1148 *pSapHw_mode = eSAP_DOT11_MODE_11g_ONLY;
1149 *pCheckRatesfor11g = FALSE;
1150 }
1151 }
1152 else if((BASIC_RATE_MASK | WLAN_BSS_MEMBERSHIP_SELECTOR_HT_PHY) == pIe[i])
1153 {
1154 *require_ht = TRUE;
1155 }
1156 }
1157 return;
1158}
1159
1160static void wlan_hdd_set_sapHwmode(hdd_adapter_t *pHostapdAdapter)
1161{
1162 tsap_Config_t *pConfig = &pHostapdAdapter->sessionCtx.ap.sapConfig;
1163 beacon_data_t *pBeacon = pHostapdAdapter->sessionCtx.ap.beacon;
1164 struct ieee80211_mgmt *pMgmt_frame = (struct ieee80211_mgmt*)pBeacon->head;
1165 u8 checkRatesfor11g = TRUE;
1166 u8 require_ht = FALSE;
1167 u8 *pIe=NULL;
1168
1169 pConfig->SapHw_mode= eSAP_DOT11_MODE_11b;
1170
1171 pIe = wlan_hdd_cfg80211_get_ie_ptr(&pMgmt_frame->u.beacon.variable[0],
1172 pBeacon->head_len, WLAN_EID_SUPP_RATES);
1173 if (pIe != NULL)
1174 {
1175 pIe += 1;
1176 wlan_hdd_check_11gmode(pIe, &require_ht, &checkRatesfor11g,
1177 &pConfig->SapHw_mode);
1178 }
1179
1180 pIe = wlan_hdd_cfg80211_get_ie_ptr(pBeacon->tail, pBeacon->tail_len,
1181 WLAN_EID_EXT_SUPP_RATES);
1182 if (pIe != NULL)
1183 {
1184
1185 pIe += 1;
1186 wlan_hdd_check_11gmode(pIe, &require_ht, &checkRatesfor11g,
1187 &pConfig->SapHw_mode);
1188 }
1189
1190 if( pConfig->channel > 14 )
1191 {
1192 pConfig->SapHw_mode= eSAP_DOT11_MODE_11a;
1193 }
1194
1195 pIe = wlan_hdd_cfg80211_get_ie_ptr(pBeacon->tail, pBeacon->tail_len,
1196 WLAN_EID_HT_CAPABILITY);
1197
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301198 if(pIe)
Jeff Johnson295189b2012-06-20 16:38:30 -07001199 {
1200 pConfig->SapHw_mode= eSAP_DOT11_MODE_11n;
1201 if(require_ht)
1202 pConfig->SapHw_mode= eSAP_DOT11_MODE_11n_ONLY;
1203 }
1204}
1205
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301206static int wlan_hdd_add_ie(hdd_adapter_t* pHostapdAdapter, v_U8_t *genie,
1207 v_U8_t *total_ielen, v_U8_t *oui, v_U8_t oui_size)
1208{
Arif Hussaine7f3ea52013-09-12 21:56:36 -07001209 v_U16_t ielen = 0;
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301210 v_U8_t *pIe = NULL;
1211 beacon_data_t *pBeacon = pHostapdAdapter->sessionCtx.ap.beacon;
1212
1213 pIe = wlan_hdd_get_vendor_oui_ie_ptr(oui, oui_size,
1214 pBeacon->tail, pBeacon->tail_len);
1215
1216 if (pIe)
1217 {
1218 ielen = pIe[1] + 2;
1219 if ((*total_ielen + ielen) <= MAX_GENIE_LEN)
1220 {
1221 vos_mem_copy(&genie[*total_ielen], pIe, ielen);
1222 }
1223 else
1224 {
1225 hddLog( VOS_TRACE_LEVEL_ERROR, "**Ie Length is too big***");
1226 return -EINVAL;
1227 }
1228 *total_ielen += ielen;
1229 }
1230 return 0;
1231}
1232
Arif Hussaine7f3ea52013-09-12 21:56:36 -07001233static void wlan_hdd_add_hostapd_conf_vsie(hdd_adapter_t* pHostapdAdapter,
1234 v_U8_t *genie, v_U8_t *total_ielen)
1235{
1236 beacon_data_t *pBeacon = pHostapdAdapter->sessionCtx.ap.beacon;
1237 int left = pBeacon->tail_len;
1238 v_U8_t *ptr = pBeacon->tail;
1239 v_U8_t elem_id, elem_len;
1240 v_U16_t ielen = 0;
1241
1242 if ( NULL == ptr || 0 == left )
1243 return;
1244
1245 while (left >= 2)
1246 {
1247 elem_id = ptr[0];
1248 elem_len = ptr[1];
1249 left -= 2;
1250 if (elem_len > left)
1251 {
1252 hddLog( VOS_TRACE_LEVEL_ERROR,
1253 "****Invalid IEs eid = %d elem_len=%d left=%d*****",
1254 elem_id, elem_len, left);
1255 return;
1256 }
1257 if (IE_EID_VENDOR == elem_id)
1258 {
1259 /* skipping the VSIE's which we don't want to include or
1260 * it will be included by existing code
1261 */
1262 if ((memcmp( &ptr[2], WPS_OUI_TYPE, WPS_OUI_TYPE_SIZE) != 0 ) &&
1263#ifdef WLAN_FEATURE_WFD
1264 (memcmp( &ptr[2], WFD_OUI_TYPE, WFD_OUI_TYPE_SIZE) != 0) &&
1265#endif
1266 (memcmp( &ptr[2], WHITELIST_OUI_TYPE, WPA_OUI_TYPE_SIZE) != 0) &&
1267 (memcmp( &ptr[2], BLACKLIST_OUI_TYPE, WPA_OUI_TYPE_SIZE) != 0) &&
1268 (memcmp( &ptr[2], "\x00\x50\xf2\x02", WPA_OUI_TYPE_SIZE) != 0) &&
1269 (memcmp( &ptr[2], WPA_OUI_TYPE, WPA_OUI_TYPE_SIZE) != 0) &&
1270 (memcmp( &ptr[2], P2P_OUI_TYPE, P2P_OUI_TYPE_SIZE) != 0))
1271 {
1272 ielen = ptr[1] + 2;
1273 if ((*total_ielen + ielen) <= MAX_GENIE_LEN)
1274 {
1275 vos_mem_copy(&genie[*total_ielen], ptr, ielen);
1276 *total_ielen += ielen;
1277 }
1278 else
1279 {
1280 hddLog( VOS_TRACE_LEVEL_ERROR,
1281 "IE Length is too big "
1282 "IEs eid=%d elem_len=%d total_ie_lent=%d",
1283 elem_id, elem_len, *total_ielen);
1284 }
1285 }
1286 }
1287
1288 left -= elem_len;
1289 ptr += (elem_len + 2);
1290 }
1291 return;
1292}
1293
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001294#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07001295static int wlan_hdd_cfg80211_update_apies(hdd_adapter_t* pHostapdAdapter,
1296 struct beacon_parameters *params)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001297#else
1298static int wlan_hdd_cfg80211_update_apies(hdd_adapter_t* pHostapdAdapter,
1299 struct cfg80211_beacon_data *params)
1300#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07001301{
1302 v_U8_t *genie;
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301303 v_U8_t total_ielen = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07001304 v_U8_t addIE[1] = {0};
Jeff Johnsone7245742012-09-05 17:12:55 -07001305 int ret = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07001306
1307 genie = vos_mem_malloc(MAX_GENIE_LEN);
1308
1309 if(genie == NULL) {
1310
1311 return -ENOMEM;
1312 }
1313
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301314 if (0 != wlan_hdd_add_ie(pHostapdAdapter, genie,
1315 &total_ielen, WPS_OUI_TYPE, WPS_OUI_TYPE_SIZE))
Jeff Johnson295189b2012-06-20 16:38:30 -07001316 {
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301317 ret = -EINVAL;
1318 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001319 }
1320
1321#ifdef WLAN_FEATURE_WFD
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301322 if (0 != wlan_hdd_add_ie(pHostapdAdapter, genie,
1323 &total_ielen, WFD_OUI_TYPE, WFD_OUI_TYPE_SIZE))
1324 {
1325 ret = -EINVAL;
1326 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001327 }
1328#endif
1329
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301330 if (0 != wlan_hdd_add_ie(pHostapdAdapter, genie,
1331 &total_ielen, P2P_OUI_TYPE, P2P_OUI_TYPE_SIZE))
Jeff Johnson295189b2012-06-20 16:38:30 -07001332 {
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301333 ret = -EINVAL;
1334 goto done;
1335 }
1336
1337 if (WLAN_HDD_SOFTAP == pHostapdAdapter->device_mode)
1338 {
Arif Hussaine7f3ea52013-09-12 21:56:36 -07001339 wlan_hdd_add_hostapd_conf_vsie(pHostapdAdapter, genie, &total_ielen);
Jeff Johnson295189b2012-06-20 16:38:30 -07001340 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001341
1342 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1343 WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA, genie, total_ielen, NULL,
1344 eANI_BOOLEAN_FALSE)==eHAL_STATUS_FAILURE)
1345 {
1346 hddLog(LOGE,
1347 "Could not pass on WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001348 ret = -EINVAL;
1349 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001350 }
1351
1352 if (ccmCfgSetInt((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1353 WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG, 1,NULL,
1354 test_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags) ?
1355 eANI_BOOLEAN_TRUE : eANI_BOOLEAN_FALSE)
1356 ==eHAL_STATUS_FAILURE)
1357 {
1358 hddLog(LOGE,
1359 "Could not pass on WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001360 ret = -EINVAL;
1361 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001362 }
1363
1364 // Added for ProResp IE
1365 if ( (params->proberesp_ies != NULL) && (params->proberesp_ies_len != 0) )
1366 {
1367 u16 rem_probe_resp_ie_len = params->proberesp_ies_len;
1368 u8 probe_rsp_ie_len[3] = {0};
1369 u8 counter = 0;
1370 /* Check Probe Resp Length if it is greater then 255 then Store
1371 Probe Resp IEs into WNI_CFG_PROBE_RSP_ADDNIE_DATA1 &
1372 WNI_CFG_PROBE_RSP_ADDNIE_DATA2 CFG Variable As We are not able
1373 Store More then 255 bytes into One Variable.
1374 */
1375 while ((rem_probe_resp_ie_len > 0) && (counter < 3))
1376 {
1377 if (rem_probe_resp_ie_len > MAX_CFG_STRING_LEN)
1378 {
1379 probe_rsp_ie_len[counter++] = MAX_CFG_STRING_LEN;
1380 rem_probe_resp_ie_len -= MAX_CFG_STRING_LEN;
1381 }
1382 else
1383 {
1384 probe_rsp_ie_len[counter++] = rem_probe_resp_ie_len;
1385 rem_probe_resp_ie_len = 0;
1386 }
1387 }
1388
1389 rem_probe_resp_ie_len = 0;
1390
1391 if (probe_rsp_ie_len[0] > 0)
1392 {
1393 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1394 WNI_CFG_PROBE_RSP_ADDNIE_DATA1,
1395 (tANI_U8*)&params->proberesp_ies[rem_probe_resp_ie_len],
1396 probe_rsp_ie_len[0], NULL,
1397 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
1398 {
1399 hddLog(LOGE,
1400 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA1 to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001401 ret = -EINVAL;
1402 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001403 }
1404 rem_probe_resp_ie_len += probe_rsp_ie_len[0];
1405 }
1406
1407 if (probe_rsp_ie_len[1] > 0)
1408 {
1409 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1410 WNI_CFG_PROBE_RSP_ADDNIE_DATA2,
1411 (tANI_U8*)&params->proberesp_ies[rem_probe_resp_ie_len],
1412 probe_rsp_ie_len[1], NULL,
1413 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
1414 {
1415 hddLog(LOGE,
1416 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA2 to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001417 ret = -EINVAL;
1418 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001419 }
1420 rem_probe_resp_ie_len += probe_rsp_ie_len[1];
1421 }
1422
1423 if (probe_rsp_ie_len[2] > 0)
1424 {
1425 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1426 WNI_CFG_PROBE_RSP_ADDNIE_DATA3,
1427 (tANI_U8*)&params->proberesp_ies[rem_probe_resp_ie_len],
1428 probe_rsp_ie_len[2], NULL,
1429 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
1430 {
1431 hddLog(LOGE,
1432 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA3 to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001433 ret = -EINVAL;
1434 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001435 }
1436 rem_probe_resp_ie_len += probe_rsp_ie_len[2];
1437 }
1438
1439 if (probe_rsp_ie_len[1] == 0 )
1440 {
1441 if ( eHAL_STATUS_FAILURE == ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1442 WNI_CFG_PROBE_RSP_ADDNIE_DATA2, (tANI_U8*)addIE, 0, NULL,
1443 eANI_BOOLEAN_FALSE) )
1444 {
1445 hddLog(LOGE,
1446 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA2 to CCM\n");
1447 }
1448 }
1449
1450 if (probe_rsp_ie_len[2] == 0 )
1451 {
1452 if ( eHAL_STATUS_FAILURE == ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1453 WNI_CFG_PROBE_RSP_ADDNIE_DATA3, (tANI_U8*)addIE, 0, NULL,
1454 eANI_BOOLEAN_FALSE) )
1455 {
1456 hddLog(LOGE,
1457 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA3 to CCM\n");
1458 }
1459 }
1460
1461 if (ccmCfgSetInt((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1462 WNI_CFG_PROBE_RSP_ADDNIE_FLAG, 1,NULL,
1463 test_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags) ?
1464 eANI_BOOLEAN_TRUE : eANI_BOOLEAN_FALSE)
1465 == eHAL_STATUS_FAILURE)
1466 {
1467 hddLog(LOGE,
1468 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_FLAG to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001469 ret = -EINVAL;
1470 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001471 }
1472 }
1473 else
1474 {
1475 // Reset WNI_CFG_PROBE_RSP Flags
1476 wlan_hdd_reset_prob_rspies(pHostapdAdapter);
1477
1478 hddLog(VOS_TRACE_LEVEL_INFO,
1479 "%s: No Probe Response IE received in set beacon",
1480 __func__);
1481 }
1482
1483 // Added for AssocResp IE
1484 if ( (params->assocresp_ies != NULL) && (params->assocresp_ies_len != 0) )
1485 {
1486 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1487 WNI_CFG_ASSOC_RSP_ADDNIE_DATA, (tANI_U8*)params->assocresp_ies,
1488 params->assocresp_ies_len, NULL,
1489 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
1490 {
1491 hddLog(LOGE,
1492 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_DATA to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001493 ret = -EINVAL;
1494 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001495 }
1496
1497 if (ccmCfgSetInt((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1498 WNI_CFG_ASSOC_RSP_ADDNIE_FLAG, 1, NULL,
1499 test_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags) ?
1500 eANI_BOOLEAN_TRUE : eANI_BOOLEAN_FALSE)
1501 == eHAL_STATUS_FAILURE)
1502 {
1503 hddLog(LOGE,
1504 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_FLAG to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001505 ret = -EINVAL;
1506 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001507 }
1508 }
1509 else
1510 {
1511 hddLog(VOS_TRACE_LEVEL_INFO,
1512 "%s: No Assoc Response IE received in set beacon",
1513 __func__);
1514
1515 if ( eHAL_STATUS_FAILURE == ccmCfgSetInt((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1516 WNI_CFG_ASSOC_RSP_ADDNIE_FLAG, 0, NULL,
1517 eANI_BOOLEAN_FALSE) )
1518 {
1519 hddLog(LOGE,
1520 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_FLAG to CCM\n");
1521 }
1522 }
1523
Jeff Johnsone7245742012-09-05 17:12:55 -07001524done:
Jeff Johnson295189b2012-06-20 16:38:30 -07001525 vos_mem_free(genie);
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301526 return ret;
Jeff Johnson295189b2012-06-20 16:38:30 -07001527}
Jeff Johnson295189b2012-06-20 16:38:30 -07001528
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301529/*
Jeff Johnson295189b2012-06-20 16:38:30 -07001530 * FUNCTION: wlan_hdd_validate_operation_channel
1531 * called by wlan_hdd_cfg80211_start_bss() and
1532 * wlan_hdd_cfg80211_set_channel()
1533 * This function validates whether given channel is part of valid
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301534 * channel list.
1535 */
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07001536VOS_STATUS wlan_hdd_validate_operation_channel(hdd_adapter_t *pAdapter,int channel)
Jeff Johnson295189b2012-06-20 16:38:30 -07001537{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301538
Jeff Johnson295189b2012-06-20 16:38:30 -07001539 v_U32_t num_ch = 0;
1540 u8 valid_ch[WNI_CFG_VALID_CHANNEL_LIST_LEN];
1541 u32 indx = 0;
1542 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301543 v_U8_t fValidChannel = FALSE, count = 0;
1544 hdd_config_t *hdd_pConfig_ini= (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301545
Jeff Johnson295189b2012-06-20 16:38:30 -07001546 num_ch = WNI_CFG_VALID_CHANNEL_LIST_LEN;
1547
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301548 if ( hdd_pConfig_ini->sapAllowAllChannel)
Jeff Johnson295189b2012-06-20 16:38:30 -07001549 {
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301550 /* Validate the channel */
1551 for (count = RF_CHAN_1 ; count <= RF_CHAN_165 ; count++)
Jeff Johnson295189b2012-06-20 16:38:30 -07001552 {
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301553 if ( channel == rfChannels[count].channelNum )
1554 {
1555 fValidChannel = TRUE;
1556 break;
1557 }
1558 }
1559 if (fValidChannel != TRUE)
1560 {
1561 hddLog(VOS_TRACE_LEVEL_ERROR,
1562 "%s: Invalid Channel [%d]", __func__, channel);
1563 return VOS_STATUS_E_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07001564 }
1565 }
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301566 else
Jeff Johnson295189b2012-06-20 16:38:30 -07001567 {
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301568 if (0 != ccmCfgGetStr(hHal, WNI_CFG_VALID_CHANNEL_LIST,
1569 valid_ch, &num_ch))
1570 {
1571 hddLog(VOS_TRACE_LEVEL_ERROR,
1572 "%s: failed to get valid channel list", __func__);
1573 return VOS_STATUS_E_FAILURE;
1574 }
1575 for (indx = 0; indx < num_ch; indx++)
1576 {
1577 if (channel == valid_ch[indx])
1578 {
1579 break;
1580 }
1581 }
1582
1583 if (indx >= num_ch)
1584 {
1585 hddLog(VOS_TRACE_LEVEL_ERROR,
1586 "%s: Invalid Channel [%d]", __func__, channel);
1587 return VOS_STATUS_E_FAILURE;
1588 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001589 }
1590 return VOS_STATUS_SUCCESS;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301591
Jeff Johnson295189b2012-06-20 16:38:30 -07001592}
1593
Viral Modi3a32cc52013-02-08 11:14:52 -08001594/**
1595 * FUNCTION: wlan_hdd_cfg80211_set_channel
1596 * This function is used to set the channel number
1597 */
1598static int wlan_hdd_cfg80211_set_channel( struct wiphy *wiphy, struct net_device *dev,
1599 struct ieee80211_channel *chan,
1600 enum nl80211_channel_type channel_type
1601 )
1602{
1603 v_U32_t num_ch = 0;
Jeff Johnson4416a782013-03-25 14:17:50 -07001604 int channel = 0;
Viral Modi3a32cc52013-02-08 11:14:52 -08001605 hdd_adapter_t *pAdapter = NULL;
1606 int freq = chan->center_freq; /* freq is in MHZ */
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05301607 hdd_context_t *pHddCtx;
1608 int status;
Viral Modi3a32cc52013-02-08 11:14:52 -08001609
1610 ENTER();
1611
1612 if( NULL == dev )
1613 {
1614 hddLog(VOS_TRACE_LEVEL_ERROR,
1615 "%s: Called with dev = NULL.\n", __func__);
1616 return -ENODEV;
1617 }
1618 pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
1619
1620 hddLog(VOS_TRACE_LEVEL_INFO,
1621 "%s: device_mode = %d freq = %d \n",__func__,
1622 pAdapter->device_mode, chan->center_freq);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05301623
1624 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
1625 status = wlan_hdd_validate_context(pHddCtx);
1626
1627 if (0 != status)
Viral Modi3a32cc52013-02-08 11:14:52 -08001628 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05301629 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1630 "%s: HDD context is not valid", __func__);
1631 return status;
Viral Modi3a32cc52013-02-08 11:14:52 -08001632 }
1633
1634 /*
1635 * Do freq to chan conversion
1636 * TODO: for 11a
1637 */
1638
1639 channel = ieee80211_frequency_to_channel(freq);
1640
1641 /* Check freq range */
1642 if ((WNI_CFG_CURRENT_CHANNEL_STAMIN > channel) ||
1643 (WNI_CFG_CURRENT_CHANNEL_STAMAX < channel))
1644 {
1645 hddLog(VOS_TRACE_LEVEL_ERROR,
1646 "%s: Channel [%d] is outside valid range from %d to %d\n",
1647 __func__, channel, WNI_CFG_CURRENT_CHANNEL_STAMIN,
1648 WNI_CFG_CURRENT_CHANNEL_STAMAX);
1649 return -EINVAL;
1650 }
1651
1652 num_ch = WNI_CFG_VALID_CHANNEL_LIST_LEN;
1653
Gopichand Nakkala6ab19562013-03-07 13:59:42 +05301654 if ((WLAN_HDD_SOFTAP != pAdapter->device_mode) &&
1655 (WLAN_HDD_P2P_GO != pAdapter->device_mode))
Viral Modi3a32cc52013-02-08 11:14:52 -08001656 {
1657 if(VOS_STATUS_SUCCESS != wlan_hdd_validate_operation_channel(pAdapter,channel))
1658 {
1659 hddLog(VOS_TRACE_LEVEL_ERROR,
1660 "%s: Invalid Channel [%d] \n", __func__, channel);
1661 return -EINVAL;
1662 }
1663 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
1664 "%s: set channel to [%d] for device mode =%d",
1665 __func__, channel,pAdapter->device_mode);
1666 }
1667 if( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Viral Modi3a32cc52013-02-08 11:14:52 -08001668 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Viral Modi3a32cc52013-02-08 11:14:52 -08001669 )
1670 {
1671 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
1672 tCsrRoamProfile * pRoamProfile = &pWextState->roamProfile;
1673 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
1674
1675 if (eConnectionState_IbssConnected == pHddStaCtx->conn_info.connState)
1676 {
1677 /* Link is up then return cant set channel*/
1678 hddLog( VOS_TRACE_LEVEL_ERROR,
1679 "%s: IBSS Associated, can't set the channel\n", __func__);
1680 return -EINVAL;
1681 }
1682
1683 num_ch = pRoamProfile->ChannelInfo.numOfChannels = 1;
1684 pHddStaCtx->conn_info.operationChannel = channel;
1685 pRoamProfile->ChannelInfo.ChannelList =
1686 &pHddStaCtx->conn_info.operationChannel;
1687 }
1688 else if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Viral Modi3a32cc52013-02-08 11:14:52 -08001689 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Viral Modi3a32cc52013-02-08 11:14:52 -08001690 )
1691 {
Gopichand Nakkalac8fa7b62013-03-11 13:56:41 +05301692 if (WLAN_HDD_P2P_GO == pAdapter->device_mode)
1693 {
1694 if(VOS_STATUS_SUCCESS !=
1695 wlan_hdd_validate_operation_channel(pAdapter,channel))
1696 {
1697 hddLog(VOS_TRACE_LEVEL_ERROR,
1698 "%s: Invalid Channel [%d] \n", __func__, channel);
1699 return -EINVAL;
1700 }
1701 (WLAN_HDD_GET_AP_CTX_PTR(pAdapter))->sapConfig.channel = channel;
1702 }
1703 else if ( WLAN_HDD_SOFTAP == pAdapter->device_mode )
Viral Modi3a32cc52013-02-08 11:14:52 -08001704 {
1705 hdd_config_t *cfg_param = (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini;
1706
1707 /* If auto channel selection is configured as enable/ 1 then ignore
1708 channel set by supplicant
1709 */
1710 if ( cfg_param->apAutoChannelSelection )
1711 {
Gopichand Nakkalac8fa7b62013-03-11 13:56:41 +05301712 (WLAN_HDD_GET_AP_CTX_PTR(pAdapter))->sapConfig.channel =
1713 AUTO_CHANNEL_SELECT;
Viral Modi3a32cc52013-02-08 11:14:52 -08001714 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
1715 "%s: set channel to auto channel (0) for device mode =%d",
1716 __func__, pAdapter->device_mode);
1717 }
Gopichand Nakkalac8fa7b62013-03-11 13:56:41 +05301718 else
1719 {
1720 if(VOS_STATUS_SUCCESS !=
1721 wlan_hdd_validate_operation_channel(pAdapter,channel))
1722 {
1723 hddLog(VOS_TRACE_LEVEL_ERROR,
1724 "%s: Invalid Channel [%d] \n", __func__, channel);
1725 return -EINVAL;
1726 }
1727 (WLAN_HDD_GET_AP_CTX_PTR(pAdapter))->sapConfig.channel = channel;
1728 }
Viral Modi3a32cc52013-02-08 11:14:52 -08001729 }
1730 }
1731 else
1732 {
1733 hddLog(VOS_TRACE_LEVEL_FATAL,
1734 "%s: Invalid device mode failed to set valid channel", __func__);
1735 return -EINVAL;
1736 }
1737 EXIT();
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05301738 return status;
Viral Modi3a32cc52013-02-08 11:14:52 -08001739}
1740
Jeff Johnson295189b2012-06-20 16:38:30 -07001741#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
1742static int wlan_hdd_cfg80211_start_bss(hdd_adapter_t *pHostapdAdapter,
1743 struct beacon_parameters *params)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001744#else
1745static int wlan_hdd_cfg80211_start_bss(hdd_adapter_t *pHostapdAdapter,
1746 struct cfg80211_beacon_data *params,
1747 const u8 *ssid, size_t ssid_len,
1748 enum nl80211_hidden_ssid hidden_ssid)
1749#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07001750{
1751 tsap_Config_t *pConfig;
1752 beacon_data_t *pBeacon = NULL;
1753 struct ieee80211_mgmt *pMgmt_frame;
1754 v_U8_t *pIe=NULL;
1755 v_U16_t capab_info;
1756 eCsrAuthType RSNAuthType;
1757 eCsrEncryptionType RSNEncryptType;
1758 eCsrEncryptionType mcRSNEncryptType;
1759 int status = VOS_STATUS_SUCCESS;
1760 tpWLAN_SAPEventCB pSapEventCallback;
1761 hdd_hostapd_state_t *pHostapdState;
1762 v_U8_t wpaRsnIEdata[(SIR_MAC_MAX_IE_LENGTH * 2)+4]; //Max ie length 255 * 2(WPA+RSN) + 2 bytes (vendor specific ID) * 2
1763 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pHostapdAdapter))->pvosContext;
Madan Mohan Koyylamudia16d0202013-02-01 11:05:57 +05301764 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pHostapdAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001765 struct qc_mac_acl_entry *acl_entry = NULL;
1766 v_SINT_t i;
Madan Mohan Koyyalamudi543172b2012-12-05 16:40:18 -08001767 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pHostapdAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001768
1769 ENTER();
1770
1771 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pHostapdAdapter);
1772
1773 pConfig = &pHostapdAdapter->sessionCtx.ap.sapConfig;
1774
1775 pBeacon = pHostapdAdapter->sessionCtx.ap.beacon;
1776
1777 pMgmt_frame = (struct ieee80211_mgmt*)pBeacon->head;
1778
1779 pConfig->beacon_int = pMgmt_frame->u.beacon.beacon_int;
1780
1781 //channel is already set in the set_channel Call back
1782 //pConfig->channel = pCommitConfig->channel;
1783
1784 /*Protection parameter to enable or disable*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301785 pConfig->protEnabled =
Jeff Johnson295189b2012-06-20 16:38:30 -07001786 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apProtEnabled;
1787
1788 pConfig->dtim_period = pBeacon->dtim_period;
1789
1790 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,"****pConfig->dtim_period=%d***\n",
1791 pConfig->dtim_period);
1792
1793
Madan Mohan Koyyalamudie0ca11f2012-11-27 15:57:52 -08001794 if (pHostapdAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson32d95a32012-09-10 13:15:23 -07001795 {
1796 pIe = wlan_hdd_cfg80211_get_ie_ptr(pBeacon->tail, pBeacon->tail_len,
Jeff Johnson295189b2012-06-20 16:38:30 -07001797 WLAN_EID_COUNTRY);
Jeff Johnson32d95a32012-09-10 13:15:23 -07001798 if(pIe)
Jeff Johnson295189b2012-06-20 16:38:30 -07001799 {
Jeff Johnson32d95a32012-09-10 13:15:23 -07001800 tANI_BOOLEAN restartNeeded;
Jeff Johnson32d95a32012-09-10 13:15:23 -07001801 pConfig->ieee80211d = 1;
1802 vos_mem_copy(pConfig->countryCode, &pIe[2], 3);
1803 sme_setRegInfo(hHal, pConfig->countryCode);
1804 sme_ResetCountryCodeInformation(hHal, &restartNeeded);
Jeff Johnson295189b2012-06-20 16:38:30 -07001805 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07001806 else
1807 {
1808 pConfig->ieee80211d = 0;
1809 }
Madan Mohan Koyylamudia16d0202013-02-01 11:05:57 +05301810 /*
1811 * If auto channel is configured i.e. channel is 0,
1812 * so skip channel validation.
1813 */
1814 if( AUTO_CHANNEL_SELECT != pConfig->channel )
1815 {
1816 if(VOS_STATUS_SUCCESS != wlan_hdd_validate_operation_channel(pHostapdAdapter,pConfig->channel))
1817 {
1818 hddLog(VOS_TRACE_LEVEL_ERROR,
1819 "%s: Invalid Channel [%d] \n", __func__, pConfig->channel);
1820 return -EINVAL;
1821 }
1822 }
1823 else
1824 {
1825 if(1 != pHddCtx->is_dynamic_channel_range_set)
1826 {
1827 hdd_config_t *hdd_pConfig= (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini;
1828 WLANSAP_SetChannelRange(hHal, hdd_pConfig->apStartChannelNum,
1829 hdd_pConfig->apEndChannelNum,hdd_pConfig->apOperatingBand);
1830 }
1831 pHddCtx->is_dynamic_channel_range_set = 0;
1832 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001833 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07001834 else
Jeff Johnson295189b2012-06-20 16:38:30 -07001835 {
1836 pConfig->ieee80211d = 0;
1837 }
1838 pConfig->authType = eSAP_AUTO_SWITCH;
1839
1840 capab_info = pMgmt_frame->u.beacon.capab_info;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301841
1842 pConfig->privacy = (pMgmt_frame->u.beacon.capab_info &
Jeff Johnson295189b2012-06-20 16:38:30 -07001843 WLAN_CAPABILITY_PRIVACY) ? VOS_TRUE : VOS_FALSE;
1844
1845 (WLAN_HDD_GET_AP_CTX_PTR(pHostapdAdapter))->uPrivacy = pConfig->privacy;
1846
1847 /*Set wps station to configured*/
1848 pIe = wlan_hdd_get_wps_ie_ptr(pBeacon->tail, pBeacon->tail_len);
1849
1850 if(pIe)
1851 {
1852 if(pIe[1] < (2 + WPS_OUI_TYPE_SIZE))
1853 {
1854 hddLog( VOS_TRACE_LEVEL_ERROR, "**Wps Ie Length is too small***\n");
1855 return -EINVAL;
1856 }
1857 else if(memcmp(&pIe[2], WPS_OUI_TYPE, WPS_OUI_TYPE_SIZE) == 0)
1858 {
Madan Mohan Koyyalamudi8bdd3112012-09-24 13:55:14 -07001859 hddLog( VOS_TRACE_LEVEL_INFO, "** WPS IE(len %d) ***", (pIe[1]+2));
Jeff Johnson295189b2012-06-20 16:38:30 -07001860 /* Check 15 bit of WPS IE as it contain information for wps state
1861 * WPS state
1862 */
1863 if(SAP_WPS_ENABLED_UNCONFIGURED == pIe[15])
1864 {
1865 pConfig->wps_state = SAP_WPS_ENABLED_UNCONFIGURED;
1866 } else if(SAP_WPS_ENABLED_CONFIGURED == pIe[15])
1867 {
1868 pConfig->wps_state = SAP_WPS_ENABLED_CONFIGURED;
1869 }
1870 }
1871 }
1872 else
1873 {
1874 pConfig->wps_state = SAP_WPS_DISABLED;
1875 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301876 pConfig->fwdWPSPBCProbeReq = 1; // Forward WPS PBC probe request frame up
Jeff Johnson295189b2012-06-20 16:38:30 -07001877
1878 pConfig->RSNWPAReqIELength = 0;
1879 pConfig->pRSNWPAReqIE = NULL;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301880 pIe = wlan_hdd_cfg80211_get_ie_ptr(pBeacon->tail, pBeacon->tail_len,
Jeff Johnson295189b2012-06-20 16:38:30 -07001881 WLAN_EID_RSN);
1882 if(pIe && pIe[1])
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301883 {
Jeff Johnson295189b2012-06-20 16:38:30 -07001884 pConfig->RSNWPAReqIELength = pIe[1] + 2;
1885 memcpy(&wpaRsnIEdata[0], pIe, pConfig->RSNWPAReqIELength);
1886 pConfig->pRSNWPAReqIE = &wpaRsnIEdata[0];
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301887 /* The actual processing may eventually be more extensive than
1888 * this. Right now, just consume any PMKIDs that are sent in
Jeff Johnson295189b2012-06-20 16:38:30 -07001889 * by the app.
1890 * */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301891 status = hdd_softap_unpackIE(
Jeff Johnson295189b2012-06-20 16:38:30 -07001892 vos_get_context( VOS_MODULE_ID_SME, pVosContext),
1893 &RSNEncryptType,
1894 &mcRSNEncryptType,
1895 &RSNAuthType,
1896 pConfig->pRSNWPAReqIE[1]+2,
1897 pConfig->pRSNWPAReqIE );
1898
1899 if( VOS_STATUS_SUCCESS == status )
1900 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301901 /* Now copy over all the security attributes you have
1902 * parsed out
Jeff Johnson295189b2012-06-20 16:38:30 -07001903 * */
1904 pConfig->RSNEncryptType = RSNEncryptType; // Use the cipher type in the RSN IE
1905 pConfig->mcRSNEncryptType = mcRSNEncryptType;
1906 (WLAN_HDD_GET_AP_CTX_PTR(pHostapdAdapter))->ucEncryptType
1907 = RSNEncryptType;
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +05301908 hddLog( LOG1, FL("CSR AuthType = %d, "
Jeff Johnson295189b2012-06-20 16:38:30 -07001909 "EncryptionType = %d mcEncryptionType = %d\n"),
1910 RSNAuthType, RSNEncryptType, mcRSNEncryptType);
1911 }
1912 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301913
Jeff Johnson295189b2012-06-20 16:38:30 -07001914 pIe = wlan_hdd_get_vendor_oui_ie_ptr(WPA_OUI_TYPE, WPA_OUI_TYPE_SIZE,
1915 pBeacon->tail, pBeacon->tail_len);
1916
1917 if(pIe && pIe[1] && (pIe[0] == DOT11F_EID_WPA))
1918 {
1919 if (pConfig->pRSNWPAReqIE)
1920 {
1921 /*Mixed mode WPA/WPA2*/
1922 memcpy((&wpaRsnIEdata[0] + pConfig->RSNWPAReqIELength), pIe, pIe[1] + 2);
1923 pConfig->RSNWPAReqIELength += pIe[1] + 2;
1924 }
1925 else
1926 {
1927 pConfig->RSNWPAReqIELength = pIe[1] + 2;
1928 memcpy(&wpaRsnIEdata[0], pIe, pConfig->RSNWPAReqIELength);
1929 pConfig->pRSNWPAReqIE = &wpaRsnIEdata[0];
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301930 status = hdd_softap_unpackIE(
Jeff Johnson295189b2012-06-20 16:38:30 -07001931 vos_get_context( VOS_MODULE_ID_SME, pVosContext),
1932 &RSNEncryptType,
1933 &mcRSNEncryptType,
1934 &RSNAuthType,
1935 pConfig->pRSNWPAReqIE[1]+2,
1936 pConfig->pRSNWPAReqIE );
1937
1938 if( VOS_STATUS_SUCCESS == status )
1939 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301940 /* Now copy over all the security attributes you have
1941 * parsed out
Jeff Johnson295189b2012-06-20 16:38:30 -07001942 * */
1943 pConfig->RSNEncryptType = RSNEncryptType; // Use the cipher type in the RSN IE
1944 pConfig->mcRSNEncryptType = mcRSNEncryptType;
1945 (WLAN_HDD_GET_AP_CTX_PTR(pHostapdAdapter))->ucEncryptType
1946 = RSNEncryptType;
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +05301947 hddLog( LOG1, FL("CSR AuthType = %d, "
Jeff Johnson295189b2012-06-20 16:38:30 -07001948 "EncryptionType = %d mcEncryptionType = %d\n"),
1949 RSNAuthType, RSNEncryptType, mcRSNEncryptType);
1950 }
1951 }
1952 }
1953
Jeff Johnson4416a782013-03-25 14:17:50 -07001954 if (pConfig->RSNWPAReqIELength > sizeof wpaRsnIEdata) {
1955 hddLog( VOS_TRACE_LEVEL_ERROR, "**RSNWPAReqIELength is too large***");
1956 return -EINVAL;
1957 }
1958
Jeff Johnson295189b2012-06-20 16:38:30 -07001959 pConfig->SSIDinfo.ssidHidden = VOS_FALSE;
1960
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001961#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07001962 if (params->ssid != NULL)
1963 {
1964 memcpy(pConfig->SSIDinfo.ssid.ssId, params->ssid, params->ssid_len);
1965 pConfig->SSIDinfo.ssid.length = params->ssid_len;
1966 if (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE)
1967 pConfig->SSIDinfo.ssidHidden = VOS_TRUE;
1968 }
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001969#else
1970 if (ssid != NULL)
1971 {
1972 memcpy(pConfig->SSIDinfo.ssid.ssId, ssid, ssid_len);
1973 pConfig->SSIDinfo.ssid.length = ssid_len;
1974 if (hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE)
1975 pConfig->SSIDinfo.ssidHidden = VOS_TRUE;
1976 }
1977#endif
1978
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301979 vos_mem_copy(pConfig->self_macaddr.bytes,
Jeff Johnson295189b2012-06-20 16:38:30 -07001980 pHostapdAdapter->macAddressCurrent.bytes, sizeof(v_MACADDR_t));
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301981
Jeff Johnson295189b2012-06-20 16:38:30 -07001982 /* default value */
1983 pConfig->SapMacaddr_acl = eSAP_ACCEPT_UNLESS_DENIED;
1984 pConfig->num_accept_mac = 0;
1985 pConfig->num_deny_mac = 0;
1986
1987 pIe = wlan_hdd_get_vendor_oui_ie_ptr(BLACKLIST_OUI_TYPE, WPA_OUI_TYPE_SIZE,
1988 pBeacon->tail, pBeacon->tail_len);
1989
1990 /* pIe for black list is following form:
1991 type : 1 byte
1992 length : 1 byte
1993 OUI : 4 bytes
1994 acl type : 1 byte
1995 no of mac addr in black list: 1 byte
1996 list of mac_acl_entries: variable, 6 bytes per mac address + sizeof(int) for vlan id
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301997 */
1998 if ((pIe != NULL) && (pIe[1] != 0))
Jeff Johnson295189b2012-06-20 16:38:30 -07001999 {
2000 pConfig->SapMacaddr_acl = pIe[6];
2001 pConfig->num_deny_mac = pIe[7];
2002 hddLog(VOS_TRACE_LEVEL_INFO,"acl type = %d no deny mac = %d\n",
2003 pIe[6], pIe[7]);
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05302004 if (pConfig->num_deny_mac > MAX_ACL_MAC_ADDRESS)
2005 pConfig->num_deny_mac = MAX_ACL_MAC_ADDRESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07002006 acl_entry = (struct qc_mac_acl_entry *)(pIe + 8);
2007 for (i = 0; i < pConfig->num_deny_mac; i++)
2008 {
2009 vos_mem_copy(&pConfig->deny_mac[i], acl_entry->addr, sizeof(qcmacaddr));
2010 acl_entry++;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302011 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002012 }
2013 pIe = wlan_hdd_get_vendor_oui_ie_ptr(WHITELIST_OUI_TYPE, WPA_OUI_TYPE_SIZE,
2014 pBeacon->tail, pBeacon->tail_len);
2015
2016 /* pIe for white list is following form:
2017 type : 1 byte
2018 length : 1 byte
2019 OUI : 4 bytes
2020 acl type : 1 byte
2021 no of mac addr in white list: 1 byte
2022 list of mac_acl_entries: variable, 6 bytes per mac address + sizeof(int) for vlan id
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302023 */
2024 if ((pIe != NULL) && (pIe[1] != 0))
Jeff Johnson295189b2012-06-20 16:38:30 -07002025 {
2026 pConfig->SapMacaddr_acl = pIe[6];
2027 pConfig->num_accept_mac = pIe[7];
2028 hddLog(VOS_TRACE_LEVEL_INFO,"acl type = %d no accept mac = %d\n",
2029 pIe[6], pIe[7]);
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05302030 if (pConfig->num_accept_mac > MAX_ACL_MAC_ADDRESS)
2031 pConfig->num_accept_mac = MAX_ACL_MAC_ADDRESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07002032 acl_entry = (struct qc_mac_acl_entry *)(pIe + 8);
2033 for (i = 0; i < pConfig->num_accept_mac; i++)
2034 {
2035 vos_mem_copy(&pConfig->accept_mac[i], acl_entry->addr, sizeof(qcmacaddr));
2036 acl_entry++;
2037 }
2038 }
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05302039
Jeff Johnson295189b2012-06-20 16:38:30 -07002040 wlan_hdd_set_sapHwmode(pHostapdAdapter);
2041
Jeff Johnsone7245742012-09-05 17:12:55 -07002042#ifdef WLAN_FEATURE_11AC
Ravi Kumar Vaishnavbbaebbe2013-01-15 17:09:48 -08002043 /* Overwrite the hostapd setting for HW mode only for 11ac.
2044 * This is valid only if mode is set to 11n in hostapd and either AUTO or 11ac in .ini .
2045 * Otherwise, leave whatever is set in hostapd (a OR b OR g OR n mode) */
2046 if( ((pConfig->SapHw_mode == eSAP_DOT11_MODE_11n) ||
2047 (pConfig->SapHw_mode == eSAP_DOT11_MODE_11n_ONLY)) &&
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302048 (((WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->dot11Mode == eHDD_DOT11_MODE_AUTO) ||
Ravi Kumar Vaishnavbbaebbe2013-01-15 17:09:48 -08002049 ((WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->dot11Mode == eHDD_DOT11_MODE_11ac) ||
2050 ((WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY)) )
Jeff Johnsone7245742012-09-05 17:12:55 -07002051 {
2052 pConfig->SapHw_mode = eSAP_DOT11_MODE_11ac;
Ravi Joshi83bfaa12013-05-28 22:12:08 -07002053
2054 /* Disable VHT support in 2.4 GHz band */
2055 if (pConfig->channel <= 14 &&
2056 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->enableVhtFor24GHzBand == FALSE)
2057 {
2058 pConfig->SapHw_mode = eSAP_DOT11_MODE_11n;
2059 }
Jeff Johnsone7245742012-09-05 17:12:55 -07002060 }
2061#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302062
Ravi Joshiaeb7d9e2013-05-02 12:28:14 -07002063 if ( AUTO_CHANNEL_SELECT != pConfig->channel )
2064 {
2065 sme_SelectCBMode(hHal,
2066 sapConvertSapPhyModeToCsrPhyMode(pConfig->SapHw_mode),
2067 pConfig->channel);
2068 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002069 // ht_capab is not what the name conveys,this is used for protection bitmap
2070 pConfig->ht_capab =
2071 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apProtection;
2072
2073 if ( 0 != wlan_hdd_cfg80211_update_apies(pHostapdAdapter, params) )
2074 {
2075 hddLog(LOGE, FL("SAP Not able to set AP IEs"));
2076 return -EINVAL;
2077 }
2078
2079 //Uapsd Enabled Bit
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302080 pConfig->UapsdEnable =
Jeff Johnson295189b2012-06-20 16:38:30 -07002081 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apUapsdEnabled;
2082 //Enable OBSS protection
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302083 pConfig->obssProtEnabled =
2084 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apOBSSProtEnabled;
Jeff Johnson295189b2012-06-20 16:38:30 -07002085
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302086 hddLog(LOGW, FL("SOftAP macaddress : "MAC_ADDRESS_STR"\n"),
Jeff Johnson295189b2012-06-20 16:38:30 -07002087 MAC_ADDR_ARRAY(pHostapdAdapter->macAddressCurrent.bytes));
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302088 hddLog(LOGW,FL("ssid =%s\n"), pConfig->SSIDinfo.ssid.ssId);
Jeff Johnson295189b2012-06-20 16:38:30 -07002089 hddLog(LOGW,FL("beaconint=%d, channel=%d\n"), (int)pConfig->beacon_int,
2090 (int)pConfig->channel);
2091 hddLog(LOGW,FL("hw_mode=%x\n"), pConfig->SapHw_mode);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302092 hddLog(LOGW,FL("privacy=%d, authType=%d\n"), pConfig->privacy,
2093 pConfig->authType);
Jeff Johnson295189b2012-06-20 16:38:30 -07002094 hddLog(LOGW,FL("RSN/WPALen=%d, \n"),(int)pConfig->RSNWPAReqIELength);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302095 hddLog(LOGW,FL("Uapsd = %d\n"),pConfig->UapsdEnable);
Jeff Johnson295189b2012-06-20 16:38:30 -07002096 hddLog(LOGW,FL("ProtEnabled = %d, OBSSProtEnabled = %d\n"),
2097 pConfig->protEnabled, pConfig->obssProtEnabled);
2098
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302099 if(test_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags))
Jeff Johnson295189b2012-06-20 16:38:30 -07002100 {
2101 //Bss already started. just return.
2102 //TODO Probably it should update some beacon params.
2103 hddLog( LOGE, "Bss Already started...Ignore the request");
2104 EXIT();
2105 return 0;
2106 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302107
Jeff Johnson295189b2012-06-20 16:38:30 -07002108 pConfig->persona = pHostapdAdapter->device_mode;
2109
2110 pSapEventCallback = hdd_hostapd_SAPEventCB;
2111 if(WLANSAP_StartBss(pVosContext, pSapEventCallback, pConfig,
2112 (v_PVOID_t)pHostapdAdapter->dev) != VOS_STATUS_SUCCESS)
2113 {
2114 hddLog(LOGE,FL("SAP Start Bss fail\n"));
2115 return -EINVAL;
2116 }
2117
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302118 hddLog(LOG1,
Jeff Johnson295189b2012-06-20 16:38:30 -07002119 FL("Waiting for Scan to complete(auto mode) and BSS to start"));
2120
2121 status = vos_wait_single_event(&pHostapdState->vosEvent, 10000);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302122
Jeff Johnson295189b2012-06-20 16:38:30 -07002123 if (!VOS_IS_STATUS_SUCCESS(status))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302124 {
2125 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07002126 ("ERROR: HDD vos wait for single_event failed!!\n"));
Tushnim Bhattacharyyaad37df12013-10-02 12:01:33 -07002127 smeGetCommandQStatus(hHal);
Jeff Johnson295189b2012-06-20 16:38:30 -07002128 VOS_ASSERT(0);
2129 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302130
Jeff Johnson295189b2012-06-20 16:38:30 -07002131 //Succesfully started Bss update the state bit.
2132 set_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags);
2133
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07002134#ifdef WLAN_FEATURE_P2P_DEBUG
2135 if (pHostapdAdapter->device_mode == WLAN_HDD_P2P_GO)
2136 {
2137 if(globalP2PConnectionStatus == P2P_GO_NEG_COMPLETED)
2138 {
2139 globalP2PConnectionStatus = P2P_GO_COMPLETED_STATE;
2140 hddLog(LOGE,"[P2P State] From Go nego completed to "
Jeff Johnson1250df42012-12-10 14:31:52 -08002141 "Non-autonomous Group started");
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07002142 }
2143 else if(globalP2PConnectionStatus == P2P_NOT_ACTIVE)
2144 {
2145 globalP2PConnectionStatus = P2P_GO_COMPLETED_STATE;
2146 hddLog(LOGE,"[P2P State] From Inactive to "
Jeff Johnson1250df42012-12-10 14:31:52 -08002147 "Autonomous Group started");
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07002148 }
2149 }
2150#endif
2151
Jeff Johnson295189b2012-06-20 16:38:30 -07002152 pHostapdState->bCommit = TRUE;
2153 EXIT();
2154
2155 return 0;
2156}
2157
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002158#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302159static int wlan_hdd_cfg80211_add_beacon(struct wiphy *wiphy,
2160 struct net_device *dev,
Jeff Johnson295189b2012-06-20 16:38:30 -07002161 struct beacon_parameters *params)
2162{
2163 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302164 hdd_context_t *pHddCtx;
2165 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07002166
2167 ENTER();
2168
2169 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "device mode=%d\n",pAdapter->device_mode);
2170
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302171 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2172 status = wlan_hdd_validate_context(pHddCtx);
2173
2174 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002175 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302176 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2177 "%s: HDD context is not valid", __func__);
2178 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002179 }
2180
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302181 if ( (pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002182 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -07002183 )
2184 {
2185 beacon_data_t *old,*new;
2186
2187 old = pAdapter->sessionCtx.ap.beacon;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302188
Jeff Johnson295189b2012-06-20 16:38:30 -07002189 if (old)
2190 return -EALREADY;
2191
2192 status = wlan_hdd_cfg80211_alloc_new_beacon(pAdapter,&new,params);
2193
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302194 if(status != VOS_STATUS_SUCCESS)
Jeff Johnson295189b2012-06-20 16:38:30 -07002195 {
2196 hddLog(VOS_TRACE_LEVEL_FATAL,
2197 "%s:Error!!! Allocating the new beacon\n",__func__);
2198 return -EINVAL;
2199 }
2200
2201 pAdapter->sessionCtx.ap.beacon = new;
2202
2203 status = wlan_hdd_cfg80211_start_bss(pAdapter, params);
2204 }
2205
2206 EXIT();
2207 return status;
2208}
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302209
2210static int wlan_hdd_cfg80211_set_beacon(struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07002211 struct net_device *dev,
2212 struct beacon_parameters *params)
2213{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302214 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302215 hdd_context_t *pHddCtx;
2216 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07002217
2218 ENTER();
2219
2220 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
2221 __func__,pAdapter->device_mode);
2222
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302223 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2224 status = wlan_hdd_validate_context(pHddCtx);
2225
2226 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002227 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302228 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2229 "%s: HDD context is not valid", __func__);
2230 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002231 }
2232
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302233 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002234 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302235 )
Jeff Johnson295189b2012-06-20 16:38:30 -07002236 {
2237 beacon_data_t *old,*new;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302238
Jeff Johnson295189b2012-06-20 16:38:30 -07002239 old = pAdapter->sessionCtx.ap.beacon;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302240
Jeff Johnson295189b2012-06-20 16:38:30 -07002241 if (!old)
2242 return -ENOENT;
2243
2244 status = wlan_hdd_cfg80211_alloc_new_beacon(pAdapter,&new,params);
2245
2246 if(status != VOS_STATUS_SUCCESS) {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302247 hddLog(VOS_TRACE_LEVEL_FATAL,
Jeff Johnson295189b2012-06-20 16:38:30 -07002248 "%s: Error!!! Allocating the new beacon\n",__func__);
2249 return -EINVAL;
2250 }
2251
2252 pAdapter->sessionCtx.ap.beacon = new;
2253
2254 status = wlan_hdd_cfg80211_start_bss(pAdapter, params);
2255 }
2256
2257 EXIT();
2258 return status;
2259}
2260
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002261#endif //(LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
2262
2263#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07002264static int wlan_hdd_cfg80211_del_beacon(struct wiphy *wiphy,
2265 struct net_device *dev)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002266#else
2267static int wlan_hdd_cfg80211_stop_ap (struct wiphy *wiphy,
2268 struct net_device *dev)
2269#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002270{
2271 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsone7245742012-09-05 17:12:55 -07002272 hdd_context_t *pHddCtx = NULL;
2273 hdd_scaninfo_t *pScanInfo = NULL;
2274 hdd_adapter_t *staAdapter = NULL;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302275 VOS_STATUS status;
Jeff Johnson295189b2012-06-20 16:38:30 -07002276
2277 ENTER();
2278
2279 if (NULL == pAdapter)
2280 {
2281 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002282 "%s: HDD adapter context is Null", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002283 return -ENODEV;
2284 }
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002285
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302286 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2287 status = wlan_hdd_validate_context(pHddCtx);
2288
2289 if (0 != status)
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002290 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302291 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2292 "%s: HDD context is not valid", __func__);
2293 return status;
Jeff Johnson4416a782013-03-25 14:17:50 -07002294 }
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002295
2296 staAdapter = hdd_get_adapter(pAdapter->pHddCtx, WLAN_HDD_INFRA_STATION);
2297 if (NULL == staAdapter)
2298 {
2299 staAdapter = hdd_get_adapter(pAdapter->pHddCtx, WLAN_HDD_P2P_CLIENT);
2300 if (NULL == staAdapter)
2301 {
Rajesh Chauhan52d885b2013-11-01 10:54:25 -07002302 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
2303 "%s: HDD adapter context for STA/P2P-CLI is Null",
2304 __func__);
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002305 }
2306 }
2307
2308 pScanInfo = &pHddCtx->scan_info;
2309
Jeff Johnson295189b2012-06-20 16:38:30 -07002310 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
2311 __func__,pAdapter->device_mode);
2312
Rajesh Chauhan52d885b2013-11-01 10:54:25 -07002313 if ((pScanInfo != NULL) && pScanInfo->mScanPending && staAdapter)
Jeff Johnsone7245742012-09-05 17:12:55 -07002314 {
Madan Mohan Koyyalamudif4e81002012-11-13 10:46:38 -08002315 INIT_COMPLETION(pScanInfo->abortscan_event_var);
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05302316 hdd_abort_mac_scan(staAdapter->pHddCtx, pAdapter->sessionId);
Jeff Johnsone7245742012-09-05 17:12:55 -07002317 status = wait_for_completion_interruptible_timeout(
Madan Mohan Koyyalamudif4e81002012-11-13 10:46:38 -08002318 &pScanInfo->abortscan_event_var,
Jeff Johnsone7245742012-09-05 17:12:55 -07002319 msecs_to_jiffies(WLAN_WAIT_TIME_ABORTSCAN));
2320 if (!status)
2321 {
Rajesh Chauhan52d885b2013-11-01 10:54:25 -07002322 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Jeff Johnson902c9832012-12-10 14:28:09 -08002323 "%s: Timeout occurred while waiting for abortscan" ,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002324 __func__);
Jeff Johnsone7245742012-09-05 17:12:55 -07002325 VOS_ASSERT(pScanInfo->mScanPending);
Jeff Johnsone7245742012-09-05 17:12:55 -07002326 }
2327 }
2328
Jeff Johnson295189b2012-06-20 16:38:30 -07002329 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002330 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -07002331 )
2332 {
2333 beacon_data_t *old;
2334
2335 old = pAdapter->sessionCtx.ap.beacon;
2336
2337 if (!old)
2338 return -ENOENT;
2339
Jeff Johnson295189b2012-06-20 16:38:30 -07002340 hdd_cleanup_actionframe(pHddCtx, pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07002341
2342 mutex_lock(&pHddCtx->sap_lock);
2343 if(test_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags))
2344 {
Jeff Johnson4416a782013-03-25 14:17:50 -07002345 if ( VOS_STATUS_SUCCESS == (status = WLANSAP_StopBss(pHddCtx->pvosContext) ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07002346 {
2347 hdd_hostapd_state_t *pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
2348
2349 status = vos_wait_single_event(&pHostapdState->vosEvent, 10000);
2350
2351 if (!VOS_IS_STATUS_SUCCESS(status))
2352 {
2353 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2354 ("ERROR: HDD vos wait for single_event failed!!\n"));
2355 VOS_ASSERT(0);
2356 }
2357 }
2358 clear_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags);
2359 }
2360 mutex_unlock(&pHddCtx->sap_lock);
2361
2362 if(status != VOS_STATUS_SUCCESS)
2363 {
2364 hddLog(VOS_TRACE_LEVEL_FATAL,
2365 "%s:Error!!! Stopping the BSS\n",__func__);
2366 return -EINVAL;
2367 }
2368
Jeff Johnson4416a782013-03-25 14:17:50 -07002369 if (ccmCfgSetInt(pHddCtx->hHal,
Jeff Johnson295189b2012-06-20 16:38:30 -07002370 WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG, 0,NULL, eANI_BOOLEAN_FALSE)
2371 ==eHAL_STATUS_FAILURE)
2372 {
2373 hddLog(LOGE,
2374 "Could not pass on WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG to CCM\n");
2375 }
2376
Jeff Johnson4416a782013-03-25 14:17:50 -07002377 if ( eHAL_STATUS_FAILURE == ccmCfgSetInt(pHddCtx->hHal,
Jeff Johnson295189b2012-06-20 16:38:30 -07002378 WNI_CFG_ASSOC_RSP_ADDNIE_FLAG, 0, NULL,
2379 eANI_BOOLEAN_FALSE) )
2380 {
2381 hddLog(LOGE,
2382 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_FLAG to CCM\n");
2383 }
2384
2385 // Reset WNI_CFG_PROBE_RSP Flags
2386 wlan_hdd_reset_prob_rspies(pAdapter);
2387
2388 pAdapter->sessionCtx.ap.beacon = NULL;
2389 kfree(old);
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07002390#ifdef WLAN_FEATURE_P2P_DEBUG
2391 if((pAdapter->device_mode == WLAN_HDD_P2P_GO) &&
2392 (globalP2PConnectionStatus == P2P_GO_COMPLETED_STATE))
2393 {
2394 hddLog(LOGE,"[P2P State] From GO completed to Inactive state "
2395 "GO got removed");
2396 globalP2PConnectionStatus = P2P_NOT_ACTIVE;
2397 }
2398#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002399 }
2400 EXIT();
2401 return status;
2402}
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002403
2404#if (LINUX_VERSION_CODE > KERNEL_VERSION(3,3,0))
2405
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302406static int wlan_hdd_cfg80211_start_ap(struct wiphy *wiphy,
2407 struct net_device *dev,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002408 struct cfg80211_ap_settings *params)
2409{
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302410 hdd_adapter_t *pAdapter;
2411 hdd_context_t *pHddCtx;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302412 int status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002413
2414 ENTER();
2415
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302416 if (NULL == dev)
Madan Mohan Koyyalamudib2c36892012-10-18 20:52:38 -07002417 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302418 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302419 "%s: Device is Null", __func__);
2420 return -ENODEV;
2421 }
2422
2423 pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
2424 if (NULL == pAdapter)
2425 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302426 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302427 "%s: HDD adapter is Null", __func__);
2428 return -ENODEV;
2429 }
2430
2431 if (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic)
2432 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302433 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302434 "%s: HDD adapter magic is invalid", __func__);
2435 return -ENODEV;
2436 }
2437
2438 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302439 status = wlan_hdd_validate_context(pHddCtx);
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302440
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302441 if (0 != status)
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302442 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302443 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2444 "%s: HDD context is not valid", __func__);
2445 return status;
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302446 }
2447
2448 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: device mode = %d",
2449 __func__, pAdapter->device_mode);
2450
2451 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002452 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002453 )
2454 {
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302455 beacon_data_t *old, *new;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002456
2457 old = pAdapter->sessionCtx.ap.beacon;
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302458
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002459 if (old)
2460 return -EALREADY;
2461
2462 status = wlan_hdd_cfg80211_alloc_new_beacon(pAdapter, &new, &params->beacon, params->dtim_period);
2463
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302464 if (status != 0)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002465 {
2466 hddLog(VOS_TRACE_LEVEL_FATAL,
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302467 "%s:Error!!! Allocating the new beacon", __func__);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002468 return -EINVAL;
2469 }
2470 pAdapter->sessionCtx.ap.beacon = new;
Viral Modi3a32cc52013-02-08 11:14:52 -08002471#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
Yue Maf49ba872013-08-19 12:04:25 -07002472 wlan_hdd_cfg80211_set_channel(wiphy, dev,
2473#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0))
2474 params->channel, params->channel_type);
2475#else
2476 params->chandef.chan, cfg80211_get_chandef_type(&(params->chandef)));
2477#endif
Viral Modi3a32cc52013-02-08 11:14:52 -08002478#endif
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002479 status = wlan_hdd_cfg80211_start_bss(pAdapter, &params->beacon, params->ssid,
2480 params->ssid_len, params->hidden_ssid);
2481 }
2482
2483 EXIT();
2484 return status;
2485}
2486
2487
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302488static int wlan_hdd_cfg80211_change_beacon(struct wiphy *wiphy,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002489 struct net_device *dev,
2490 struct cfg80211_beacon_data *params)
2491{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302492 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302493 hdd_context_t *pHddCtx;
2494 int status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002495
2496 ENTER();
2497
2498 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
2499 __func__, pAdapter->device_mode);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302500
2501 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2502 status = wlan_hdd_validate_context(pHddCtx);
2503
2504 if (0 != status)
Madan Mohan Koyyalamudib2c36892012-10-18 20:52:38 -07002505 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302506 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2507 "%s: HDD context is not valid", __func__);
2508 return status;
Madan Mohan Koyyalamudib2c36892012-10-18 20:52:38 -07002509 }
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002510
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302511 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002512 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302513 )
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002514 {
2515 beacon_data_t *old,*new;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302516
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002517 old = pAdapter->sessionCtx.ap.beacon;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302518
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002519 if (!old)
2520 return -ENOENT;
2521
2522 status = wlan_hdd_cfg80211_alloc_new_beacon(pAdapter, &new, params, 0);
2523
2524 if(status != VOS_STATUS_SUCCESS) {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302525 hddLog(VOS_TRACE_LEVEL_FATAL,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002526 "%s: Error!!! Allocating the new beacon\n",__func__);
2527 return -EINVAL;
2528 }
2529
2530 pAdapter->sessionCtx.ap.beacon = new;
2531
2532 status = wlan_hdd_cfg80211_start_bss(pAdapter, params, NULL, 0, 0);
2533 }
2534
2535 EXIT();
2536 return status;
2537}
2538
2539#endif //(LINUX_VERSION_CODE > KERNEL_VERSION(3,3,0))
2540
Jeff Johnson295189b2012-06-20 16:38:30 -07002541
2542static int wlan_hdd_cfg80211_change_bss (struct wiphy *wiphy,
2543 struct net_device *dev,
2544 struct bss_parameters *params)
2545{
2546 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
2547
2548 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302549
Jeff Johnson295189b2012-06-20 16:38:30 -07002550 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
2551 __func__,pAdapter->device_mode);
2552
2553 if((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002554 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302555 )
Jeff Johnson295189b2012-06-20 16:38:30 -07002556 {
2557 /* ap_isolate == -1 means that in change bss, upper layer doesn't
2558 * want to update this parameter */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302559 if (-1 != params->ap_isolate)
Jeff Johnson295189b2012-06-20 16:38:30 -07002560 {
2561 pAdapter->sessionCtx.ap.apDisableIntraBssFwd = !!params->ap_isolate;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302562 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002563 }
2564
2565 EXIT();
2566 return 0;
2567}
2568
Kiet Lam10841362013-11-01 11:36:50 +05302569/* FUNCTION: wlan_hdd_change_country_code_cd
2570* to wait for contry code completion
2571*/
2572void* wlan_hdd_change_country_code_cb(void *pAdapter)
2573{
2574 hdd_adapter_t *call_back_pAdapter = pAdapter;
2575 complete(&call_back_pAdapter->change_country_code);
2576 return NULL;
2577}
2578
Jeff Johnson295189b2012-06-20 16:38:30 -07002579/*
2580 * FUNCTION: wlan_hdd_cfg80211_change_iface
2581 * This function is used to set the interface type (INFRASTRUCTURE/ADHOC)
2582 */
2583int wlan_hdd_cfg80211_change_iface( struct wiphy *wiphy,
2584 struct net_device *ndev,
2585 enum nl80211_iftype type,
2586 u32 *flags,
2587 struct vif_params *params
2588 )
2589{
2590 struct wireless_dev *wdev;
2591 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
2592 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
Mohit Khanna0f232092012-09-11 14:46:08 -07002593 hdd_adapter_t *pP2pAdapter = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07002594 tCsrRoamProfile *pRoamProfile = NULL;
2595 eCsrRoamBssType LastBSSType;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302596 hdd_config_t *pConfig = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07002597 eMib_dot11DesiredBssType connectedBssType;
2598 VOS_STATUS status;
2599
2600 ENTER();
2601
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302602 status = wlan_hdd_validate_context(pHddCtx);
2603
2604 if (0 != status)
Jeff Johnson295189b2012-06-20 16:38:30 -07002605 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302606 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2607 "%s: HDD context is not valid", __func__);
2608 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07002609 }
2610
2611 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
2612 __func__, pAdapter->device_mode);
2613
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302614 pConfig = pHddCtx->cfg_ini;
Jeff Johnson295189b2012-06-20 16:38:30 -07002615 wdev = ndev->ieee80211_ptr;
2616
2617#ifdef WLAN_BTAMP_FEATURE
2618 if((NL80211_IFTYPE_P2P_CLIENT == type)||
2619 (NL80211_IFTYPE_ADHOC == type)||
2620 (NL80211_IFTYPE_AP == type)||
2621 (NL80211_IFTYPE_P2P_GO == type))
2622 {
2623 pHddCtx->isAmpAllowed = VOS_FALSE;
2624 // stop AMP traffic
2625 status = WLANBAP_StopAmp();
2626 if(VOS_STATUS_SUCCESS != status )
2627 {
2628 pHddCtx->isAmpAllowed = VOS_TRUE;
2629 hddLog(VOS_TRACE_LEVEL_FATAL,
2630 "%s: Failed to stop AMP", __func__);
2631 return -EINVAL;
2632 }
2633 }
2634#endif //WLAN_BTAMP_FEATURE
2635 /* Reset the current device mode bit mask*/
2636 wlan_hdd_clear_concurrency_mode(pHddCtx, pAdapter->device_mode);
2637
2638 if( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Jeff Johnson295189b2012-06-20 16:38:30 -07002639 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Jeff Johnsone7245742012-09-05 17:12:55 -07002640 || (pAdapter->device_mode == WLAN_HDD_P2P_DEVICE)
Jeff Johnson295189b2012-06-20 16:38:30 -07002641 )
2642 {
2643 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
2644 pRoamProfile = &pWextState->roamProfile;
2645 LastBSSType = pRoamProfile->BSSType;
2646
2647 switch (type)
2648 {
2649 case NL80211_IFTYPE_STATION:
Jeff Johnson295189b2012-06-20 16:38:30 -07002650 case NL80211_IFTYPE_P2P_CLIENT:
Jeff Johnson295189b2012-06-20 16:38:30 -07002651 hddLog(VOS_TRACE_LEVEL_INFO,
2652 "%s: setting interface Type to INFRASTRUCTURE", __func__);
2653 pRoamProfile->BSSType = eCSR_BSS_TYPE_INFRASTRUCTURE;
Jeff Johnsone7245742012-09-05 17:12:55 -07002654#ifdef WLAN_FEATURE_11AC
2655 if(pConfig->dot11Mode == eHDD_DOT11_MODE_AUTO)
2656 {
2657 pConfig->dot11Mode = eHDD_DOT11_MODE_11ac;
2658 }
2659#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302660 pRoamProfile->phyMode =
Jeff Johnsone7245742012-09-05 17:12:55 -07002661 hdd_cfg_xlate_to_csr_phy_mode(pConfig->dot11Mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07002662 wdev->iftype = type;
Gopichand Nakkalaf527dc62012-12-31 16:35:10 -08002663 //Check for sub-string p2p to confirm its a p2p interface
2664 if (NULL != strstr(ndev->name,"p2p"))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302665 {
Gopichand Nakkala864d3552012-12-31 16:08:51 -08002666 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
2667 WLAN_HDD_P2P_DEVICE : WLAN_HDD_P2P_CLIENT;
2668 }
2669 else
2670 {
2671 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
Jeff Johnson295189b2012-06-20 16:38:30 -07002672 WLAN_HDD_INFRA_STATION: WLAN_HDD_P2P_CLIENT;
Gopichand Nakkala864d3552012-12-31 16:08:51 -08002673 }
Madan Mohan Koyyalamudi81746922013-07-17 14:38:51 +05302674#ifdef FEATURE_WLAN_TDLS
2675 /* The open adapter for the p2p shall skip initializations in
2676 * tdls_init if the device mode is WLAN_HDD_P2P_DEVICE, for
2677 * TDLS is supported only on WLAN_HDD_P2P_CLIENT. Hence invoke
2678 * tdls_init when the change_iface sets the device mode to
2679 * WLAN_HDD_P2P_CLIENT.
2680 */
2681
2682 if ( pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
2683 {
2684 if (0 != wlan_hdd_tdls_init (pAdapter))
2685 {
2686 return -EINVAL;
2687 }
2688 }
2689#endif
2690
Jeff Johnson295189b2012-06-20 16:38:30 -07002691 break;
2692 case NL80211_IFTYPE_ADHOC:
2693 hddLog(VOS_TRACE_LEVEL_INFO,
2694 "%s: setting interface Type to ADHOC", __func__);
2695 pRoamProfile->BSSType = eCSR_BSS_TYPE_START_IBSS;
2696 pRoamProfile->phyMode =
2697 hdd_cfg_xlate_to_csr_phy_mode(pConfig->dot11Mode);
Shailender Karmuchia734f332013-04-19 14:02:48 -07002698 pAdapter->device_mode = WLAN_HDD_IBSS;
Jeff Johnson295189b2012-06-20 16:38:30 -07002699 wdev->iftype = type;
2700 break;
2701
2702 case NL80211_IFTYPE_AP:
Jeff Johnson295189b2012-06-20 16:38:30 -07002703 case NL80211_IFTYPE_P2P_GO:
Jeff Johnson295189b2012-06-20 16:38:30 -07002704 {
2705 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
2706 "%s: setting interface Type to %s", __func__,
2707 (type == NL80211_IFTYPE_AP) ? "SoftAP" : "P2pGo");
2708
Gopichand Nakkalaf527dc62012-12-31 16:35:10 -08002709 //Cancel any remain on channel for GO mode
2710 if (NL80211_IFTYPE_P2P_GO == type)
2711 {
2712 wlan_hdd_cancel_existing_remain_on_channel(pAdapter);
2713 }
Mohit Khanna0f232092012-09-11 14:46:08 -07002714 if (NL80211_IFTYPE_AP == type)
2715 {
2716 /* As Loading WLAN Driver one interface being created for p2p device
2717 * address. This will take one HW STA and the max number of clients
2718 * that can connect to softAP will be reduced by one. so while changing
2719 * the interface type to NL80211_IFTYPE_AP (SoftAP) remove p2p0
2720 * interface as it is not required in SoftAP mode.
2721 */
2722
2723 // Get P2P Adapter
2724 pP2pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_P2P_DEVICE);
2725
2726 if (pP2pAdapter)
2727 {
2728 hdd_stop_adapter(pHddCtx, pP2pAdapter);
2729 hdd_deinit_adapter(pHddCtx, pP2pAdapter);
2730 hdd_close_adapter(pHddCtx, pP2pAdapter, VOS_TRUE);
2731 }
2732 }
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302733#ifdef FEATURE_WLAN_TDLS
Mohit Khanna0f232092012-09-11 14:46:08 -07002734
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302735 /* A Mutex Lock is introduced while changing the mode to
2736 * protect the concurrent access for the Adapters by TDLS
2737 * module.
2738 */
2739 if (mutex_lock_interruptible(&pHddCtx->tdls_lock))
2740 {
2741 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2742 "%s: unable to lock list", __func__);
2743 return -EINVAL;
2744 }
2745#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002746 //De-init the adapter.
2747 hdd_stop_adapter( pHddCtx, pAdapter );
2748 hdd_deinit_adapter( pHddCtx, pAdapter );
2749 memset(&pAdapter->sessionCtx, 0, sizeof(pAdapter->sessionCtx));
Jeff Johnson295189b2012-06-20 16:38:30 -07002750 pAdapter->device_mode = (type == NL80211_IFTYPE_AP) ?
2751 WLAN_HDD_SOFTAP : WLAN_HDD_P2P_GO;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302752#ifdef FEATURE_WLAN_TDLS
2753 mutex_unlock(&pHddCtx->tdls_lock);
2754#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -07002755
2756 //Disable BMPS and IMPS if enabled
2757 //before starting Go
2758 if(WLAN_HDD_P2P_GO == pAdapter->device_mode)
2759 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302760 if(VOS_STATUS_E_FAILURE ==
Jeff Johnson32d95a32012-09-10 13:15:23 -07002761 hdd_disable_bmps_imps(pHddCtx, WLAN_HDD_P2P_GO))
2762 {
2763 //Fail to Exit BMPS
2764 VOS_ASSERT(0);
2765 }
2766 }
2767
Madan Mohan Koyyalamudi3ff2a0b2012-10-15 14:33:46 -07002768 if ((WLAN_HDD_SOFTAP == pAdapter->device_mode) &&
2769 (pConfig->apRandomBssidEnabled))
2770 {
2771 /* To meet Android requirements create a randomized
2772 MAC address of the form 02:1A:11:Fx:xx:xx */
2773 get_random_bytes(&ndev->dev_addr[3], 3);
2774 ndev->dev_addr[0] = 0x02;
2775 ndev->dev_addr[1] = 0x1A;
2776 ndev->dev_addr[2] = 0x11;
2777 ndev->dev_addr[3] |= 0xF0;
2778 memcpy(pAdapter->macAddressCurrent.bytes, ndev->dev_addr,
2779 VOS_MAC_ADDR_SIZE);
2780 pr_info("wlan: Generated HotSpot BSSID "
2781 "%02x:%02x:%02x:%02x:%02x:%02x\n",
2782 ndev->dev_addr[0],
2783 ndev->dev_addr[1],
2784 ndev->dev_addr[2],
2785 ndev->dev_addr[3],
2786 ndev->dev_addr[4],
2787 ndev->dev_addr[5]);
2788 }
2789
Jeff Johnson295189b2012-06-20 16:38:30 -07002790 hdd_set_ap_ops( pAdapter->dev );
2791
Kiet Lam10841362013-11-01 11:36:50 +05302792 /* This is for only SAP mode where users can
2793 * control country through ini.
2794 * P2P GO follows station country code
2795 * acquired during the STA scanning. */
2796 if((NL80211_IFTYPE_AP == type) &&
2797 (memcmp(pConfig->apCntryCode, CFG_AP_COUNTRY_CODE_DEFAULT, 3) != 0))
2798 {
2799 int status = 0;
2800 VOS_TRACE(VOS_MODULE_ID_HDD,VOS_TRACE_LEVEL_INFO,
2801 "%s: setting country code from INI ", __func__);
2802 init_completion(&pAdapter->change_country_code);
2803 status = (int)sme_ChangeCountryCode(pHddCtx->hHal,
2804 (void *)(tSmeChangeCountryCallback)
2805 wlan_hdd_change_country_code_cb,
2806 pConfig->apCntryCode, pAdapter,
2807 pHddCtx->pvosContext,
2808 VOS_FALSE);
2809 if (eHAL_STATUS_SUCCESS == status)
2810 {
2811 /* Wait for completion */
2812 status = wait_for_completion_interruptible_timeout(
2813 &pAdapter->change_country_code,
2814 msecs_to_jiffies(WLAN_WAIT_TIME_COUNTRY));
2815 if (status <= 0)
2816 {
2817 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2818 "%s: SME Timed out while setting country code ",
2819 __func__);
2820 }
2821 }
2822 else
2823 {
2824 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2825 "%s: SME Change Country code failed \n",__func__);
2826 return -EINVAL;
2827 }
2828 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002829 status = hdd_init_ap_mode(pAdapter);
2830 if(status != VOS_STATUS_SUCCESS)
2831 {
2832 hddLog(VOS_TRACE_LEVEL_FATAL,
2833 "%s: Error initializing the ap mode", __func__);
2834 return -EINVAL;
2835 }
2836 hdd_set_conparam(1);
2837
Jeff Johnson295189b2012-06-20 16:38:30 -07002838 /*interface type changed update in wiphy structure*/
2839 if(wdev)
2840 {
2841 wdev->iftype = type;
2842 pHddCtx->change_iface = type;
2843 }
2844 else
2845 {
2846 hddLog(VOS_TRACE_LEVEL_ERROR,
2847 "%s: ERROR !!!! Wireless dev is NULL", __func__);
2848 return -EINVAL;
2849 }
2850 goto done;
2851 }
2852
2853 default:
2854 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported interface Type",
2855 __func__);
2856 return -EOPNOTSUPP;
2857 }
2858 }
2859 else if ( (pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002860 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -07002861 )
2862 {
2863 switch(type)
2864 {
2865 case NL80211_IFTYPE_STATION:
Jeff Johnson295189b2012-06-20 16:38:30 -07002866 case NL80211_IFTYPE_P2P_CLIENT:
Jeff Johnson295189b2012-06-20 16:38:30 -07002867 case NL80211_IFTYPE_ADHOC:
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302868#ifdef FEATURE_WLAN_TDLS
2869
2870 /* A Mutex Lock is introduced while changing the mode to
2871 * protect the concurrent access for the Adapters by TDLS
2872 * module.
2873 */
2874 if (mutex_lock_interruptible(&pHddCtx->tdls_lock))
2875 {
2876 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2877 "%s: unable to lock list", __func__);
2878 return -EINVAL;
2879 }
2880#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -07002881 hdd_stop_adapter( pHddCtx, pAdapter );
2882 hdd_deinit_adapter( pHddCtx, pAdapter );
Jeff Johnson295189b2012-06-20 16:38:30 -07002883 wdev->iftype = type;
Gopichand Nakkalaf527dc62012-12-31 16:35:10 -08002884 //Check for sub-string p2p to confirm its a p2p interface
2885 if (NULL != strstr(ndev->name,"p2p"))
Gopichand Nakkala864d3552012-12-31 16:08:51 -08002886 {
2887 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
2888 WLAN_HDD_P2P_DEVICE : WLAN_HDD_P2P_CLIENT;
2889 }
2890 else
2891 {
2892 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
Jeff Johnson295189b2012-06-20 16:38:30 -07002893 WLAN_HDD_INFRA_STATION: WLAN_HDD_P2P_CLIENT;
Gopichand Nakkala864d3552012-12-31 16:08:51 -08002894 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002895 hdd_set_conparam(0);
2896 pHddCtx->change_iface = type;
Jeff Johnson295189b2012-06-20 16:38:30 -07002897 memset(&pAdapter->sessionCtx, 0, sizeof(pAdapter->sessionCtx));
2898 hdd_set_station_ops( pAdapter->dev );
2899 status = hdd_init_station_mode( pAdapter );
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302900#ifdef FEATURE_WLAN_TDLS
2901 mutex_unlock(&pHddCtx->tdls_lock);
2902#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002903 if( VOS_STATUS_SUCCESS != status )
2904 return -EOPNOTSUPP;
Jeff Johnsone7245742012-09-05 17:12:55 -07002905 /* In case of JB, for P2P-GO, only change interface will be called,
2906 * This is the right place to enable back bmps_imps()
2907 */
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05302908 if (pHddCtx->hdd_wlan_suspended)
2909 {
2910 hdd_set_pwrparams(pHddCtx);
2911 }
Jeff Johnsone7245742012-09-05 17:12:55 -07002912 hdd_enable_bmps_imps(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07002913 goto done;
2914 case NL80211_IFTYPE_AP:
Jeff Johnson295189b2012-06-20 16:38:30 -07002915 case NL80211_IFTYPE_P2P_GO:
Jeff Johnson295189b2012-06-20 16:38:30 -07002916 wdev->iftype = type;
Jeff Johnson295189b2012-06-20 16:38:30 -07002917 pAdapter->device_mode = (type == NL80211_IFTYPE_AP) ?
2918 WLAN_HDD_SOFTAP : WLAN_HDD_P2P_GO;
Jeff Johnson295189b2012-06-20 16:38:30 -07002919 goto done;
2920 default:
2921 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported interface Type",
2922 __func__);
2923 return -EOPNOTSUPP;
2924
2925 }
2926
2927 }
2928 else
2929 {
2930 return -EOPNOTSUPP;
2931 }
2932
2933
2934 if(pRoamProfile)
2935 {
2936 if ( LastBSSType != pRoamProfile->BSSType )
2937 {
2938 /*interface type changed update in wiphy structure*/
2939 wdev->iftype = type;
2940
2941 /*the BSS mode changed, We need to issue disconnect
2942 if connected or in IBSS disconnect state*/
2943 if ( hdd_connGetConnectedBssType(
2944 WLAN_HDD_GET_STATION_CTX_PTR(pAdapter), &connectedBssType ) ||
2945 ( eCSR_BSS_TYPE_START_IBSS == LastBSSType ) )
2946 {
2947 /*need to issue a disconnect to CSR.*/
2948 INIT_COMPLETION(pAdapter->disconnect_comp_var);
2949 if( eHAL_STATUS_SUCCESS ==
2950 sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
2951 pAdapter->sessionId,
2952 eCSR_DISCONNECT_REASON_UNSPECIFIED ) )
2953 {
2954 wait_for_completion_interruptible_timeout(
2955 &pAdapter->disconnect_comp_var,
2956 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
2957 }
2958 }
2959 }
2960 }
2961
2962done:
2963 /*set bitmask based on updated value*/
2964 wlan_hdd_set_concurrency_mode(pHddCtx, pAdapter->device_mode);
Leo Chang6fe1f922013-06-07 19:21:24 -07002965
2966 /* Only STA mode support TM now
2967 * all other mode, TM feature should be disabled */
2968 if ( (pHddCtx->cfg_ini->thermalMitigationEnable) &&
2969 (~VOS_STA & pHddCtx->concurrency_mode) )
2970 {
2971 hddDevTmLevelChangedHandler(pHddCtx->parent_dev, 0);
2972 }
2973
Jeff Johnson295189b2012-06-20 16:38:30 -07002974#ifdef WLAN_BTAMP_FEATURE
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302975 if((NL80211_IFTYPE_STATION == type) && (pHddCtx->concurrency_mode <= 1) &&
Jeff Johnson295189b2012-06-20 16:38:30 -07002976 (pHddCtx->no_of_sessions[WLAN_HDD_INFRA_STATION] <=1))
2977 {
2978 //we are ok to do AMP
2979 pHddCtx->isAmpAllowed = VOS_TRUE;
2980 }
2981#endif //WLAN_BTAMP_FEATURE
2982 EXIT();
2983 return 0;
2984}
2985
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002986#ifdef FEATURE_WLAN_TDLS
2987static int wlan_hdd_tdls_add_station(struct wiphy *wiphy,
2988 struct net_device *dev, u8 *mac, bool update, tCsrStaParams *StaParams)
2989{
2990 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
2991 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
2992 VOS_STATUS status;
Hoonki Lee5305c3a2013-04-29 23:28:59 -07002993 hddTdlsPeer_t *pTdlsPeer;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002994
2995 ENTER();
2996
Gopichand Nakkala838be5d2013-04-10 22:41:51 +05302997 if (NULL == pHddCtx || NULL == pHddCtx->cfg_ini)
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002998 {
2999 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3000 "Invalid arguments");
3001 return -EINVAL;
3002 }
Hoonki Lee27511902013-03-14 18:19:06 -07003003
3004 if ((eTDLS_SUPPORT_NOT_ENABLED == pHddCtx->tdls_mode) ||
3005 (eTDLS_SUPPORT_DISABLED == pHddCtx->tdls_mode))
3006 {
3007 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3008 "%s: TDLS mode is disabled OR not enabled in FW."
3009 MAC_ADDRESS_STR " Request declined.",
3010 __func__, MAC_ADDR_ARRAY(mac));
3011 return -ENOTSUPP;
3012 }
3013
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003014 if (pHddCtx->isLogpInProgress)
3015 {
3016 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3017 "%s:LOGP in Progress. Ignore!!!", __func__);
Gopichand Nakkala05922802013-03-14 12:23:19 -07003018 wlan_hdd_tdls_set_link_status(pAdapter, mac, eTDLS_LINK_IDLE);
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003019 return -EBUSY;
3020 }
3021
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05303022 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, mac, TRUE);
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003023
3024 if ( NULL == pTdlsPeer ) {
3025 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3026 "%s: " MAC_ADDRESS_STR " (update %d) not exist. return invalid",
3027 __func__, MAC_ADDR_ARRAY(mac), update);
3028 return -EINVAL;
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07003029 }
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003030
3031 /* in add station, we accept existing valid staId if there is */
3032 if ((0 == update) &&
3033 ((pTdlsPeer->link_status >= eTDLS_LINK_CONNECTING) ||
3034 (TDLS_STA_INDEX_VALID(pTdlsPeer->staId))))
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003035 {
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003036 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003037 "%s: " MAC_ADDRESS_STR
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003038 " link_status %d. staId %d. add station ignored.",
3039 __func__, MAC_ADDR_ARRAY(mac), pTdlsPeer->link_status, pTdlsPeer->staId);
3040 return 0;
3041 }
3042 /* in change station, we accept only when staId is valid */
3043 if ((1 == update) &&
3044 ((pTdlsPeer->link_status > eTDLS_LINK_CONNECTING) ||
3045 (!TDLS_STA_INDEX_VALID(pTdlsPeer->staId))))
3046 {
3047 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3048 "%s: " MAC_ADDRESS_STR
3049 " link status %d. staId %d. change station %s.",
3050 __func__, MAC_ADDR_ARRAY(mac), pTdlsPeer->link_status, pTdlsPeer->staId,
3051 (TDLS_STA_INDEX_VALID(pTdlsPeer->staId)) ? "ignored" : "declined");
3052 return (TDLS_STA_INDEX_VALID(pTdlsPeer->staId)) ? 0 : -EPERM;
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003053 }
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07003054
3055 /* when others are on-going, we want to change link_status to idle */
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05303056 if (NULL != wlan_hdd_tdls_is_progress(pHddCtx, mac, TRUE))
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003057 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07003058 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3059 "%s: " MAC_ADDRESS_STR
3060 " TDLS setup is ongoing. Request declined.",
3061 __func__, MAC_ADDR_ARRAY(mac));
Gopichand Nakkala05922802013-03-14 12:23:19 -07003062 goto error;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003063 }
3064
3065 /* first to check if we reached to maximum supported TDLS peer.
3066 TODO: for now, return -EPERM looks working fine,
3067 but need to check if any other errno fit into this category.*/
3068 if (HDD_MAX_NUM_TDLS_STA <= wlan_hdd_tdlsConnectedPeers(pAdapter))
3069 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07003070 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3071 "%s: " MAC_ADDRESS_STR
3072 " TDLS Max peer already connected. Request declined.",
3073 __func__, MAC_ADDR_ARRAY(mac));
Gopichand Nakkala05922802013-03-14 12:23:19 -07003074 goto error;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003075 }
3076 else
3077 {
3078 hddTdlsPeer_t *pTdlsPeer;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05303079 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, mac, TRUE);
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003080 if (pTdlsPeer && TDLS_IS_CONNECTED(pTdlsPeer))
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003081 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07003082 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3083 "%s: " MAC_ADDRESS_STR " already connected. Request declined.",
3084 __func__, MAC_ADDR_ARRAY(mac));
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003085 return -EPERM;
3086 }
3087 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003088 if (0 == update)
3089 wlan_hdd_tdls_set_link_status(pAdapter, mac, eTDLS_LINK_CONNECTING);
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003090
Jeff Johnsond75fe012013-04-06 10:53:06 -07003091 /* debug code */
Gopichand Nakkala838be5d2013-04-10 22:41:51 +05303092 if (NULL != StaParams)
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003093 {
3094 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3095 "%s: TDLS Peer Parameters.", __func__);
Hoonki Lee66b75f32013-04-16 18:30:07 -07003096 if(StaParams->htcap_present)
3097 {
3098 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3099 "ht_capa->cap_info: %0x", StaParams->HTCap.capInfo);
3100 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3101 "ht_capa->extended_capabilities: %0x",
3102 StaParams->HTCap.extendedHtCapInfo);
3103 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003104 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3105 "params->capability: %0x",StaParams->capability);
3106 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
Jeff Johnson0299d0a2013-10-30 12:37:43 -07003107 "params->ext_capab_len: %0x",StaParams->extn_capability[0]);
Hoonki Lee66b75f32013-04-16 18:30:07 -07003108 if(StaParams->vhtcap_present)
3109 {
3110 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3111 "rxMcsMap %x rxHighest %x txMcsMap %x txHighest %x",
3112 StaParams->VHTCap.suppMcs.rxMcsMap, StaParams->VHTCap.suppMcs.rxHighest,
3113 StaParams->VHTCap.suppMcs.txMcsMap, StaParams->VHTCap.suppMcs.txHighest);
3114 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003115 {
3116 int i = 0;
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003117 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "Supported rates:");
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003118 for (i = 0; i < sizeof(StaParams->supported_rates); i++)
3119 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3120 "[%d]: %x ", i, StaParams->supported_rates[i]);
3121 }
Jeff Johnsond75fe012013-04-06 10:53:06 -07003122 } /* end debug code */
Gopichand Nakkala838be5d2013-04-10 22:41:51 +05303123 else if ((1 == update) && (NULL == StaParams))
3124 {
3125 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3126 "%s : update is true, but staParams is NULL. Error!", __func__);
3127 return -EPERM;
3128 }
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003129
3130 INIT_COMPLETION(pAdapter->tdls_add_station_comp);
3131
3132 if (!update)
3133 {
3134 status = sme_AddTdlsPeerSta(WLAN_HDD_GET_HAL_CTX(pAdapter),
3135 pAdapter->sessionId, mac);
3136 }
3137 else
3138 {
3139 status = sme_ChangeTdlsPeerSta(WLAN_HDD_GET_HAL_CTX(pAdapter),
3140 pAdapter->sessionId, mac, StaParams);
3141 }
3142
3143 status = wait_for_completion_interruptible_timeout(&pAdapter->tdls_add_station_comp,
3144 msecs_to_jiffies(WAIT_TIME_TDLS_ADD_STA));
3145
3146 if (!status)
3147 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07003148 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003149 "%s: timeout waiting for tdls add station indication",
3150 __func__);
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07003151 return -EPERM;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003152 }
3153 if ( eHAL_STATUS_SUCCESS != pAdapter->tdlsAddStaStatus)
3154 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07003155 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003156 "%s: Add Station is unsucessful", __func__);
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07003157 return -EPERM;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003158 }
3159
3160 return 0;
Gopichand Nakkala05922802013-03-14 12:23:19 -07003161
3162error:
3163 wlan_hdd_tdls_set_link_status(pAdapter, mac, eTDLS_LINK_IDLE);
3164 return -EPERM;
3165
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003166}
3167#endif
3168
Jeff Johnson295189b2012-06-20 16:38:30 -07003169static int wlan_hdd_change_station(struct wiphy *wiphy,
3170 struct net_device *dev,
3171 u8 *mac,
3172 struct station_parameters *params)
3173{
3174 VOS_STATUS status = VOS_STATUS_SUCCESS;
3175 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Gopichand Nakkala29149562013-05-10 21:43:41 +05303176 hdd_context_t *pHddCtx;
3177 hdd_station_ctx_t *pHddStaCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07003178 v_MACADDR_t STAMacAddress;
Gopichand Nakkalab0856222013-03-12 22:39:05 -07003179#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003180 tCsrStaParams StaParams = {0};
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003181 tANI_U8 isBufSta = 0;
Gopichand Nakkalab0856222013-03-12 22:39:05 -07003182#endif
Jeff Johnsone7245742012-09-05 17:12:55 -07003183 ENTER();
3184
Gopichand Nakkala29149562013-05-10 21:43:41 +05303185 if ((NULL == pAdapter))
3186 {
3187 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
3188 "invalid adapter ");
3189 return -EINVAL;
3190 }
3191
3192 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
3193 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3194
3195 if ((NULL == pHddCtx) || (NULL == pHddStaCtx))
3196 {
3197 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
3198 "invalid HDD state or HDD station context");
3199 return -EINVAL;
3200 }
3201
3202 if (pHddCtx->isLogpInProgress)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003203 {
3204 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3205 "%s:LOGP in Progress. Ignore!!!", __func__);
3206 return -EAGAIN;
3207 }
3208
Jeff Johnson295189b2012-06-20 16:38:30 -07003209 vos_mem_copy(STAMacAddress.bytes, mac, sizeof(v_MACADDR_t));
3210
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003211 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
3212 || (pAdapter->device_mode == WLAN_HDD_P2P_GO))
Jeff Johnson295189b2012-06-20 16:38:30 -07003213 {
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003214 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED))
Jeff Johnson295189b2012-06-20 16:38:30 -07003215 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303216 status = hdd_softap_change_STA_state( pAdapter, &STAMacAddress,
Jeff Johnson295189b2012-06-20 16:38:30 -07003217 WLANTL_STA_AUTHENTICATED);
3218
Gopichand Nakkala29149562013-05-10 21:43:41 +05303219 if (status != VOS_STATUS_SUCCESS)
3220 {
3221 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3222 "%s: Not able to change TL state to AUTHENTICATED", __func__);
3223 return -EINVAL;
3224 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003225 }
3226 }
Hoonki Leea6d49be2013-04-05 09:43:25 -07003227 else if ((pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
3228 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)) {
Gopichand Nakkala29149562013-05-10 21:43:41 +05303229#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003230 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
3231 StaParams.capability = params->capability;
3232 StaParams.uapsd_queues = params->uapsd_queues;
3233 StaParams.max_sp = params->max_sp;
3234
3235 if (0 != params->ext_capab_len)
3236 vos_mem_copy(StaParams.extn_capability, params->ext_capab,
3237 sizeof(StaParams.extn_capability));
3238
3239 if (NULL != params->ht_capa)
Hoonki Lee66b75f32013-04-16 18:30:07 -07003240 {
3241 StaParams.htcap_present = 1;
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003242 vos_mem_copy(&StaParams.HTCap, params->ht_capa, sizeof(tSirHTCap));
Hoonki Lee66b75f32013-04-16 18:30:07 -07003243 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003244
3245 StaParams.supported_rates_len = params->supported_rates_len;
3246
3247 /* Note : The Maximum sizeof supported_rates sent by the Supplicant is 32.
3248 * The supported_rates array , for all the structures propogating till Add Sta
3249 * to the firmware has to be modified , if the supplicant (ieee80211) is
3250 * modified to send more rates.
3251 */
3252
3253 /* To avoid Data Currption , set to max length to SIR_MAC_MAX_SUPP_RATES
3254 */
3255 if (StaParams.supported_rates_len > SIR_MAC_MAX_SUPP_RATES)
3256 StaParams.supported_rates_len = SIR_MAC_MAX_SUPP_RATES;
3257
3258 if (0 != StaParams.supported_rates_len) {
3259 int i = 0;
3260 vos_mem_copy(StaParams.supported_rates, params->supported_rates,
3261 StaParams.supported_rates_len);
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 "Supported Rates with Length %d", StaParams.supported_rates_len);
3264 for (i=0; i < StaParams.supported_rates_len; i++)
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003265 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003266 "[%d]: %0x", i, StaParams.supported_rates[i]);
3267 }
3268
3269 if (NULL != params->vht_capa)
Hoonki Lee66b75f32013-04-16 18:30:07 -07003270 {
3271 StaParams.vhtcap_present = 1;
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003272 vos_mem_copy(&StaParams.VHTCap, params->vht_capa, sizeof(tSirVHTCap));
Hoonki Lee66b75f32013-04-16 18:30:07 -07003273 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003274
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003275 if (0 != params->ext_capab_len ) {
3276 /*Define A Macro : TODO Sunil*/
3277 if ((1<<4) & StaParams.extn_capability[3]) {
3278 isBufSta = 1;
3279 }
3280 }
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05303281 status = wlan_hdd_tdls_set_peer_caps( pAdapter, mac, params->uapsd_queues,
3282 params->max_sp, isBufSta);
3283 if (VOS_STATUS_SUCCESS != status) {
3284 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3285 "%s: wlan_hdd_tdls_set_peer_caps failed!", __func__);
3286 return -EINVAL;
3287 }
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003288 status = wlan_hdd_tdls_add_station(wiphy, dev, mac, 1, &StaParams);
3289
3290 if (VOS_STATUS_SUCCESS != status) {
3291 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3292 "%s: sme_ChangeTdlsPeerSta failed!", __func__);
3293 return -EINVAL;
3294 }
3295 }
Gopichand Nakkalab0856222013-03-12 22:39:05 -07003296#endif
Gopichand Nakkala6239acd2013-06-14 14:48:00 +05303297 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003298 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07003299 return status;
3300}
3301
3302/*
Jeff Johnson295189b2012-06-20 16:38:30 -07003303 * FUNCTION: wlan_hdd_cfg80211_add_key
3304 * This function is used to initialize the key information
3305 */
3306#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003307static int wlan_hdd_cfg80211_add_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003308 struct net_device *ndev,
3309 u8 key_index, bool pairwise,
3310 const u8 *mac_addr,
3311 struct key_params *params
3312 )
3313#else
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003314static int wlan_hdd_cfg80211_add_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003315 struct net_device *ndev,
3316 u8 key_index, const u8 *mac_addr,
3317 struct key_params *params
3318 )
3319#endif
3320{
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003321 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Jeff Johnson295189b2012-06-20 16:38:30 -07003322 tCsrRoamSetKey setKey;
3323 u8 groupmacaddr[WNI_CFG_BSSID_LEN] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303324 int status;
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003325 v_U32_t roamId= 0xFF;
3326 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
Jeff Johnson295189b2012-06-20 16:38:30 -07003327 hdd_hostapd_state_t *pHostapdState;
3328 VOS_STATUS vos_status;
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003329 eHalStatus halStatus;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303330 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07003331
3332 ENTER();
3333
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303334 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
3335 status = wlan_hdd_validate_context(pHddCtx);
3336
3337 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003338 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303339 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3340 "%s: HDD context is not valid", __func__);
3341 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003342 }
3343
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003344 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
3345 __func__, pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07003346
3347 if (CSR_MAX_NUM_KEY <= key_index)
3348 {
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003349 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key index %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07003350 key_index);
3351
3352 return -EINVAL;
3353 }
3354
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003355 if (CSR_MAX_KEY_LEN < params->key_len)
3356 {
3357 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key length %d", __func__,
3358 params->key_len);
3359
3360 return -EINVAL;
3361 }
3362
3363 hddLog(VOS_TRACE_LEVEL_INFO,
3364 "%s: called with key index = %d & key length %d",
3365 __func__, key_index, params->key_len);
Jeff Johnson295189b2012-06-20 16:38:30 -07003366
3367 /*extract key idx, key len and key*/
3368 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
3369 setKey.keyId = key_index;
3370 setKey.keyLength = params->key_len;
3371 vos_mem_copy(&setKey.Key[0],params->key, params->key_len);
3372
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003373 switch (params->cipher)
Jeff Johnson295189b2012-06-20 16:38:30 -07003374 {
3375 case WLAN_CIPHER_SUITE_WEP40:
3376 setKey.encType = eCSR_ENCRYPT_TYPE_WEP40_STATICKEY;
3377 break;
3378
3379 case WLAN_CIPHER_SUITE_WEP104:
3380 setKey.encType = eCSR_ENCRYPT_TYPE_WEP104_STATICKEY;
3381 break;
3382
3383 case WLAN_CIPHER_SUITE_TKIP:
3384 {
3385 u8 *pKey = &setKey.Key[0];
3386 setKey.encType = eCSR_ENCRYPT_TYPE_TKIP;
3387
3388 vos_mem_zero(pKey, CSR_MAX_KEY_LEN);
3389
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003390 /*Supplicant sends the 32bytes key in this order
Jeff Johnson295189b2012-06-20 16:38:30 -07003391
3392 |--------------|----------|----------|
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003393 | Tk1 |TX-MIC | RX Mic |
Jeff Johnson295189b2012-06-20 16:38:30 -07003394 |--------------|----------|----------|
3395 <---16bytes---><--8bytes--><--8bytes-->
3396
3397 */
3398 /*Sme expects the 32 bytes key to be in the below order
3399
3400 |--------------|----------|----------|
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003401 | Tk1 |RX-MIC | TX Mic |
Jeff Johnson295189b2012-06-20 16:38:30 -07003402 |--------------|----------|----------|
3403 <---16bytes---><--8bytes--><--8bytes-->
3404 */
3405 /* Copy the Temporal Key 1 (TK1) */
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003406 vos_mem_copy(pKey, params->key, 16);
Jeff Johnson295189b2012-06-20 16:38:30 -07003407
3408 /*Copy the rx mic first*/
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003409 vos_mem_copy(&pKey[16], &params->key[24], 8);
Jeff Johnson295189b2012-06-20 16:38:30 -07003410
3411 /*Copy the tx mic */
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003412 vos_mem_copy(&pKey[24], &params->key[16], 8);
Jeff Johnson295189b2012-06-20 16:38:30 -07003413
3414
3415 break;
3416 }
3417
3418 case WLAN_CIPHER_SUITE_CCMP:
3419 setKey.encType = eCSR_ENCRYPT_TYPE_AES;
3420 break;
3421
3422#ifdef FEATURE_WLAN_WAPI
3423 case WLAN_CIPHER_SUITE_SMS4:
3424 {
3425 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
3426 wlan_hdd_cfg80211_set_key_wapi(pAdapter, key_index, mac_addr,
3427 params->key, params->key_len);
3428 return 0;
3429 }
3430#endif
Chet Lanctot186b5732013-03-18 10:26:30 -07003431
Jeff Johnson295189b2012-06-20 16:38:30 -07003432#ifdef FEATURE_WLAN_CCX
3433 case WLAN_CIPHER_SUITE_KRK:
3434 setKey.encType = eCSR_ENCRYPT_TYPE_KRK;
3435 break;
3436#endif
Chet Lanctot186b5732013-03-18 10:26:30 -07003437
3438#ifdef WLAN_FEATURE_11W
3439 case WLAN_CIPHER_SUITE_AES_CMAC:
3440 setKey.encType = eCSR_ENCRYPT_TYPE_AES_CMAC;
Chet Lanctot3b5158a2013-03-31 16:45:21 -07003441 break;
Chet Lanctot186b5732013-03-18 10:26:30 -07003442#endif
3443
Jeff Johnson295189b2012-06-20 16:38:30 -07003444 default:
Jeff Johnson0299d0a2013-10-30 12:37:43 -07003445 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: unsupported cipher type %u",
Jeff Johnson295189b2012-06-20 16:38:30 -07003446 __func__, params->cipher);
3447 return -EOPNOTSUPP;
3448 }
3449
3450 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: encryption type %d",
3451 __func__, setKey.encType);
3452
Shailender Karmuchi642e9812013-05-30 14:34:49 -07003453 if (
Jeff Johnson295189b2012-06-20 16:38:30 -07003454#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
3455 (!pairwise)
3456#else
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003457 (!mac_addr || is_broadcast_ether_addr(mac_addr))
Jeff Johnson295189b2012-06-20 16:38:30 -07003458#endif
Shailender Karmuchi642e9812013-05-30 14:34:49 -07003459 )
3460 {
3461 /* set group key*/
3462 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3463 "%s- %d: setting Broadcast key",
3464 __func__, __LINE__);
3465 setKey.keyDirection = eSIR_RX_ONLY;
3466 vos_mem_copy(setKey.peerMac,groupmacaddr,WNI_CFG_BSSID_LEN);
3467 }
3468 else
3469 {
3470 /* set pairwise key*/
3471 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3472 "%s- %d: setting pairwise key",
3473 __func__, __LINE__);
3474 setKey.keyDirection = eSIR_TX_RX;
3475 vos_mem_copy(setKey.peerMac, mac_addr,WNI_CFG_BSSID_LEN);
3476 }
3477 if ((WLAN_HDD_IBSS == pAdapter->device_mode) && !pairwise)
3478 {
3479 setKey.keyDirection = eSIR_TX_RX;
3480 /*Set the group key*/
3481 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
3482 pAdapter->sessionId, &setKey, &roamId );
Jeff Johnson295189b2012-06-20 16:38:30 -07003483
Shailender Karmuchi642e9812013-05-30 14:34:49 -07003484 if ( 0 != status )
3485 {
3486 hddLog(VOS_TRACE_LEVEL_ERROR,
3487 "%s: sme_RoamSetKey failed, returned %d", __func__, status);
3488 return -EINVAL;
3489 }
3490 /*Save the keys here and call sme_RoamSetKey for setting
3491 the PTK after peer joins the IBSS network*/
3492 vos_mem_copy(&pAdapter->sessionCtx.station.ibss_enc_key,
3493 &setKey, sizeof(tCsrRoamSetKey));
3494 return status;
3495 }
Gopichand Nakkala29149562013-05-10 21:43:41 +05303496 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP) ||
3497 (pAdapter->device_mode == WLAN_HDD_P2P_GO))
3498 {
Jeff Johnson295189b2012-06-20 16:38:30 -07003499 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003500 if( pHostapdState->bssState == BSS_START )
3501 {
Jeff Johnson295189b2012-06-20 16:38:30 -07003502 status = WLANSAP_SetKeySta( pVosContext, &setKey);
3503
3504 if ( status != eHAL_STATUS_SUCCESS )
3505 {
3506 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3507 "[%4d] WLANSAP_SetKeySta returned ERROR status= %d",
3508 __LINE__, status );
3509 }
3510 }
3511
3512 /* Saving WEP keys */
3513 else if( eCSR_ENCRYPT_TYPE_WEP40_STATICKEY == setKey.encType ||
3514 eCSR_ENCRYPT_TYPE_WEP104_STATICKEY == setKey.encType )
3515 {
3516 //Save the wep key in ap context. Issue setkey after the BSS is started.
3517 hdd_ap_ctx_t *pAPCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
3518 vos_mem_copy(&pAPCtx->wepKey[key_index], &setKey, sizeof(tCsrRoamSetKey));
3519 }
3520 else
3521 {
3522 //Save the key in ap context. Issue setkey after the BSS is started.
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003523 hdd_ap_ctx_t *pAPCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07003524 vos_mem_copy(&pAPCtx->groupKey, &setKey, sizeof(tCsrRoamSetKey));
3525 }
3526 }
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003527 else if ( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION) ||
3528 (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003529 {
3530 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
3531 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3532
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303533#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
3534 if (!pairwise)
3535#else
3536 if (!mac_addr || is_broadcast_ether_addr(mac_addr))
3537#endif
3538 {
3539 /* set group key*/
3540 if (pHddStaCtx->roam_info.deferKeyComplete)
3541 {
3542 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3543 "%s- %d: Perform Set key Complete",
3544 __func__, __LINE__);
3545 hdd_PerformRoamSetKeyComplete(pAdapter);
3546 }
3547 }
3548
Jeff Johnson295189b2012-06-20 16:38:30 -07003549 pWextState->roamProfile.Keys.KeyLength[key_index] = (u8)params->key_len;
3550
Venkata Prathyusha Kuntupalliee2ce712013-01-17 14:09:24 -08003551 pWextState->roamProfile.Keys.defaultIndex = key_index;
3552
3553
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003554 vos_mem_copy(&pWextState->roamProfile.Keys.KeyMaterial[key_index][0],
Jeff Johnson295189b2012-06-20 16:38:30 -07003555 params->key, params->key_len);
3556
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303557
Jeff Johnson295189b2012-06-20 16:38:30 -07003558 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_SETTING_KEY;
3559
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303560 hddLog(VOS_TRACE_LEVEL_INFO_MED,
Jeff Johnson295189b2012-06-20 16:38:30 -07003561 "%s: set key for peerMac %2x:%2x:%2x:%2x:%2x:%2x, direction %d",
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303562 __func__, setKey.peerMac[0], setKey.peerMac[1],
3563 setKey.peerMac[2], setKey.peerMac[3],
3564 setKey.peerMac[4], setKey.peerMac[5],
Jeff Johnson295189b2012-06-20 16:38:30 -07003565 setKey.keyDirection);
3566
3567 vos_status = wlan_hdd_check_ula_done(pAdapter);
3568
3569 if ( vos_status != VOS_STATUS_SUCCESS )
3570 {
3571 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3572 "[%4d] wlan_hdd_check_ula_done returned ERROR status= %d",
3573 __LINE__, vos_status );
3574
3575 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3576
3577 return -EINVAL;
3578
3579 }
3580
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003581#ifdef WLAN_FEATURE_VOWIFI_11R
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303582 /* The supplicant may attempt to set the PTK once pre-authentication
3583 is done. Save the key in the UMAC and include it in the ADD BSS
3584 request */
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003585 halStatus = sme_FTUpdateKey( WLAN_HDD_GET_HAL_CTX(pAdapter), &setKey);
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303586 if ( halStatus == eHAL_STATUS_FT_PREAUTH_KEY_SUCCESS )
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003587 {
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303588 hddLog(VOS_TRACE_LEVEL_INFO_MED,
3589 "%s: Update PreAuth Key success", __func__);
3590 return 0;
3591 }
3592 else if ( halStatus == eHAL_STATUS_FT_PREAUTH_KEY_FAILED )
3593 {
3594 hddLog(VOS_TRACE_LEVEL_ERROR,
3595 "%s: Update PreAuth Key failed", __func__);
Gopichand Nakkalad7d13652013-02-15 01:48:00 +05303596 return -EINVAL;
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003597 }
3598#endif /* WLAN_FEATURE_VOWIFI_11R */
Jeff Johnson295189b2012-06-20 16:38:30 -07003599
3600 /* issue set key request to SME*/
3601 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
3602 pAdapter->sessionId, &setKey, &roamId );
3603
3604 if ( 0 != status )
3605 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303606 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07003607 "%s: sme_RoamSetKey failed, returned %d", __func__, status);
3608 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3609 return -EINVAL;
3610 }
3611
3612
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303613 /* in case of IBSS as there was no information available about WEP keys during
3614 * IBSS join, group key intialized with NULL key, so re-initialize group key
Jeff Johnson295189b2012-06-20 16:38:30 -07003615 * with correct value*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303616 if ( (eCSR_BSS_TYPE_START_IBSS == pWextState->roamProfile.BSSType) &&
3617 !( ( IW_AUTH_KEY_MGMT_802_1X
3618 == (pWextState->authKeyMgmt & IW_AUTH_KEY_MGMT_802_1X))
Jeff Johnson295189b2012-06-20 16:38:30 -07003619 && (eCSR_AUTH_TYPE_OPEN_SYSTEM == pHddStaCtx->conn_info.authType)
3620 )
3621 &&
3622 ( (WLAN_CIPHER_SUITE_WEP40 == params->cipher)
3623 || (WLAN_CIPHER_SUITE_WEP104 == params->cipher)
3624 )
3625 )
3626 {
3627 setKey.keyDirection = eSIR_RX_ONLY;
3628 vos_mem_copy(setKey.peerMac,groupmacaddr,WNI_CFG_BSSID_LEN);
3629
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303630 hddLog(VOS_TRACE_LEVEL_INFO_MED,
Jeff Johnson295189b2012-06-20 16:38:30 -07003631 "%s: set key peerMac %2x:%2x:%2x:%2x:%2x:%2x, direction %d",
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303632 __func__, setKey.peerMac[0], setKey.peerMac[1],
3633 setKey.peerMac[2], setKey.peerMac[3],
3634 setKey.peerMac[4], setKey.peerMac[5],
Jeff Johnson295189b2012-06-20 16:38:30 -07003635 setKey.keyDirection);
3636
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303637 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07003638 pAdapter->sessionId, &setKey, &roamId );
3639
3640 if ( 0 != status )
3641 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303642 hddLog(VOS_TRACE_LEVEL_ERROR,
3643 "%s: sme_RoamSetKey failed for group key (IBSS), returned %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07003644 __func__, status);
3645 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3646 return -EINVAL;
3647 }
3648 }
3649 }
3650
3651 return 0;
3652}
3653
3654/*
3655 * FUNCTION: wlan_hdd_cfg80211_get_key
3656 * This function is used to get the key information
3657 */
3658#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303659static int wlan_hdd_cfg80211_get_key(
3660 struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003661 struct net_device *ndev,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303662 u8 key_index, bool pairwise,
Jeff Johnson295189b2012-06-20 16:38:30 -07003663 const u8 *mac_addr, void *cookie,
3664 void (*callback)(void *cookie, struct key_params*)
3665 )
3666#else
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303667static int wlan_hdd_cfg80211_get_key(
3668 struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003669 struct net_device *ndev,
3670 u8 key_index, const u8 *mac_addr, void *cookie,
3671 void (*callback)(void *cookie, struct key_params*)
3672 )
3673#endif
3674{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303675 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Jeff Johnson295189b2012-06-20 16:38:30 -07003676 hdd_wext_state_t *pWextState= WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
3677 tCsrRoamProfile *pRoamProfile = &(pWextState->roamProfile);
3678 struct key_params params;
3679
3680 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303681
Jeff Johnson295189b2012-06-20 16:38:30 -07003682 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
3683 __func__,pAdapter->device_mode);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303684
Jeff Johnson295189b2012-06-20 16:38:30 -07003685 memset(&params, 0, sizeof(params));
3686
3687 if (CSR_MAX_NUM_KEY <= key_index)
3688 {
3689 return -EINVAL;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303690 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003691
3692 switch(pRoamProfile->EncryptionType.encryptionType[0])
3693 {
3694 case eCSR_ENCRYPT_TYPE_NONE:
3695 params.cipher = IW_AUTH_CIPHER_NONE;
3696 break;
3697
3698 case eCSR_ENCRYPT_TYPE_WEP40_STATICKEY:
3699 case eCSR_ENCRYPT_TYPE_WEP40:
3700 params.cipher = WLAN_CIPHER_SUITE_WEP40;
3701 break;
3702
3703 case eCSR_ENCRYPT_TYPE_WEP104_STATICKEY:
3704 case eCSR_ENCRYPT_TYPE_WEP104:
3705 params.cipher = WLAN_CIPHER_SUITE_WEP104;
3706 break;
3707
3708 case eCSR_ENCRYPT_TYPE_TKIP:
3709 params.cipher = WLAN_CIPHER_SUITE_TKIP;
3710 break;
3711
3712 case eCSR_ENCRYPT_TYPE_AES:
3713 params.cipher = WLAN_CIPHER_SUITE_AES_CMAC;
3714 break;
3715
3716 default:
3717 params.cipher = IW_AUTH_CIPHER_NONE;
3718 break;
3719 }
3720
3721 params.key_len = pRoamProfile->Keys.KeyLength[key_index];
3722 params.seq_len = 0;
3723 params.seq = NULL;
3724 params.key = &pRoamProfile->Keys.KeyMaterial[key_index][0];
3725 callback(cookie, &params);
3726 return 0;
3727}
3728
3729/*
3730 * FUNCTION: wlan_hdd_cfg80211_del_key
3731 * This function is used to delete the key information
3732 */
3733#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303734static int wlan_hdd_cfg80211_del_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003735 struct net_device *ndev,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303736 u8 key_index,
3737 bool pairwise,
Jeff Johnson295189b2012-06-20 16:38:30 -07003738 const u8 *mac_addr
3739 )
3740#else
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303741static int wlan_hdd_cfg80211_del_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003742 struct net_device *ndev,
3743 u8 key_index,
3744 const u8 *mac_addr
3745 )
3746#endif
3747{
3748 int status = 0;
3749
3750 //This code needs to be revisited. There is sme_removeKey API, we should
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303751 //plan to use that. After the change to use correct index in setkey,
Jeff Johnson295189b2012-06-20 16:38:30 -07003752 //it is observed that this is invalidating peer
3753 //key index whenever re-key is done. This is affecting data link.
3754 //It should be ok to ignore del_key.
3755#if 0
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303756 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
3757 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
Jeff Johnson295189b2012-06-20 16:38:30 -07003758 u8 groupmacaddr[WNI_CFG_BSSID_LEN] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
3759 tCsrRoamSetKey setKey;
3760 v_U32_t roamId= 0xFF;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303761
Jeff Johnson295189b2012-06-20 16:38:30 -07003762 ENTER();
3763
3764 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: device_mode = %d\n",
3765 __func__,pAdapter->device_mode);
3766
3767 if (CSR_MAX_NUM_KEY <= key_index)
3768 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303769 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key index %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07003770 key_index);
3771
3772 return -EINVAL;
3773 }
3774
3775 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
3776 setKey.keyId = key_index;
3777
3778 if (mac_addr)
3779 vos_mem_copy(setKey.peerMac, mac_addr,WNI_CFG_BSSID_LEN);
3780 else
3781 vos_mem_copy(setKey.peerMac, groupmacaddr, WNI_CFG_BSSID_LEN);
3782
3783 setKey.encType = eCSR_ENCRYPT_TYPE_NONE;
3784
3785 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07003786 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303787 )
3788 {
3789
3790 hdd_hostapd_state_t *pHostapdState =
Jeff Johnson295189b2012-06-20 16:38:30 -07003791 WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
3792 if( pHostapdState->bssState == BSS_START)
3793 {
3794 status = WLANSAP_SetKeySta( pVosContext, &setKey);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303795
Jeff Johnson295189b2012-06-20 16:38:30 -07003796 if ( status != eHAL_STATUS_SUCCESS )
3797 {
3798 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3799 "[%4d] WLANSAP_SetKeySta returned ERROR status= %d",
3800 __LINE__, status );
3801 }
3802 }
3803 }
3804 else if ( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303805 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Jeff Johnson295189b2012-06-20 16:38:30 -07003806 )
3807 {
3808 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3809
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303810 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_SETTING_KEY;
3811
3812 hddLog(VOS_TRACE_LEVEL_INFO_MED,
Jeff Johnson295189b2012-06-20 16:38:30 -07003813 "%s: delete key for peerMac %2x:%2x:%2x:%2x:%2x:%2x",
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303814 __func__, setKey.peerMac[0], setKey.peerMac[1],
3815 setKey.peerMac[2], setKey.peerMac[3],
Jeff Johnson295189b2012-06-20 16:38:30 -07003816 setKey.peerMac[4], setKey.peerMac[5]);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303817 if(pAdapter->sessionCtx.station.conn_info.connState ==
3818 eConnectionState_Associated)
Jeff Johnson295189b2012-06-20 16:38:30 -07003819 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303820 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07003821 pAdapter->sessionId, &setKey, &roamId );
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303822
Jeff Johnson295189b2012-06-20 16:38:30 -07003823 if ( 0 != status )
3824 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303825 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07003826 "%s: sme_RoamSetKey failure, returned %d",
3827 __func__, status);
3828 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3829 return -EINVAL;
3830 }
3831 }
3832 }
3833#endif
Jeff Johnsone7245742012-09-05 17:12:55 -07003834 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07003835 return status;
3836}
3837
3838/*
3839 * FUNCTION: wlan_hdd_cfg80211_set_default_key
3840 * This function is used to set the default tx key index
3841 */
3842#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
3843static int wlan_hdd_cfg80211_set_default_key( struct wiphy *wiphy,
3844 struct net_device *ndev,
3845 u8 key_index,
3846 bool unicast, bool multicast)
3847#else
3848static int wlan_hdd_cfg80211_set_default_key( struct wiphy *wiphy,
3849 struct net_device *ndev,
3850 u8 key_index)
3851#endif
3852{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303853 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303854 int status;
Gopichand Nakkala29149562013-05-10 21:43:41 +05303855 hdd_wext_state_t *pWextState;
3856 hdd_station_ctx_t *pHddStaCtx;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303857 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07003858
3859 ENTER();
3860
Gopichand Nakkala29149562013-05-10 21:43:41 +05303861 if ((NULL == pAdapter))
3862 {
3863 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
3864 "invalid adapter");
3865 return -EINVAL;
3866 }
3867
3868 pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
3869 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3870
3871 if ((NULL == pWextState) || (NULL == pHddStaCtx))
3872 {
3873 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
3874 "invalid Wext state or HDD context");
3875 return -EINVAL;
3876 }
3877
Jeff Johnson295189b2012-06-20 16:38:30 -07003878 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d key_index = %d \n",
3879 __func__,pAdapter->device_mode, key_index);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303880
Jeff Johnson295189b2012-06-20 16:38:30 -07003881 if (CSR_MAX_NUM_KEY <= key_index)
3882 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303883 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key index %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07003884 key_index);
3885
3886 return -EINVAL;
3887 }
3888
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303889 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
3890 status = wlan_hdd_validate_context(pHddCtx);
3891
3892 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003893 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303894 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3895 "%s: HDD context is not valid", __func__);
3896 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003897 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303898
Jeff Johnson295189b2012-06-20 16:38:30 -07003899 if ((pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Jeff Johnson295189b2012-06-20 16:38:30 -07003900 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303901 )
Jeff Johnson295189b2012-06-20 16:38:30 -07003902 {
Gopichand Nakkala29149562013-05-10 21:43:41 +05303903 if ( (eCSR_ENCRYPT_TYPE_TKIP !=
Arif Hussain6943f522013-11-04 20:10:10 -08003904 pHddStaCtx->conn_info.ucEncryptionType) &&
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303905 (eCSR_ENCRYPT_TYPE_AES !=
Arif Hussain6943f522013-11-04 20:10:10 -08003906 pHddStaCtx->conn_info.ucEncryptionType)
Jeff Johnson295189b2012-06-20 16:38:30 -07003907 )
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303908 {
3909 /* if default key index is not same as previous one,
Jeff Johnson295189b2012-06-20 16:38:30 -07003910 * then update the default key index */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303911
Jeff Johnson295189b2012-06-20 16:38:30 -07003912 tCsrRoamSetKey setKey;
3913 v_U32_t roamId= 0xFF;
3914 tCsrKeys *Keys = &pWextState->roamProfile.Keys;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303915
3916 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: default tx key index %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07003917 __func__, key_index);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303918
Jeff Johnson295189b2012-06-20 16:38:30 -07003919 Keys->defaultIndex = (u8)key_index;
3920 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
3921 setKey.keyId = key_index;
3922 setKey.keyLength = Keys->KeyLength[key_index];
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303923
3924 vos_mem_copy(&setKey.Key[0],
3925 &Keys->KeyMaterial[key_index][0],
Jeff Johnson295189b2012-06-20 16:38:30 -07003926 Keys->KeyLength[key_index]);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303927
Gopichand Nakkala29149562013-05-10 21:43:41 +05303928 setKey.keyDirection = eSIR_TX_RX;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303929
3930 vos_mem_copy(setKey.peerMac,
Jeff Johnson295189b2012-06-20 16:38:30 -07003931 &pHddStaCtx->conn_info.bssId[0],
3932 WNI_CFG_BSSID_LEN);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303933
Gopichand Nakkala29149562013-05-10 21:43:41 +05303934 if (Keys->KeyLength[key_index] == CSR_WEP40_KEY_LEN &&
3935 pWextState->roamProfile.EncryptionType.encryptionType[0] ==
3936 eCSR_ENCRYPT_TYPE_WEP104)
3937 {
3938 /*In the case of dynamic wep supplicant hardcodes DWEP type to eCSR_ENCRYPT_TYPE_WEP104
3939 even though ap is configured for WEP-40 encryption. In this canse the key length
3940 is 5 but the encryption type is 104 hence checking the key langht(5) and encryption
3941 type(104) and switching encryption type to 40*/
3942 pWextState->roamProfile.EncryptionType.encryptionType[0] =
3943 eCSR_ENCRYPT_TYPE_WEP40;
3944 pWextState->roamProfile.mcEncryptionType.encryptionType[0] =
3945 eCSR_ENCRYPT_TYPE_WEP40;
3946 }
3947
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303948 setKey.encType =
Jeff Johnson295189b2012-06-20 16:38:30 -07003949 pWextState->roamProfile.EncryptionType.encryptionType[0];
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303950
Jeff Johnson295189b2012-06-20 16:38:30 -07003951 /* issue set key request */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303952 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07003953 pAdapter->sessionId, &setKey, &roamId );
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303954
Jeff Johnson295189b2012-06-20 16:38:30 -07003955 if ( 0 != status )
3956 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303957 hddLog(VOS_TRACE_LEVEL_ERROR,
3958 "%s: sme_RoamSetKey failed, returned %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07003959 status);
3960 return -EINVAL;
3961 }
3962 }
3963 }
3964
3965 /* In SoftAp mode setting key direction for default mode */
3966 else if ( WLAN_HDD_SOFTAP == pAdapter->device_mode )
3967 {
3968 if ( (eCSR_ENCRYPT_TYPE_TKIP !=
3969 pWextState->roamProfile.EncryptionType.encryptionType[0]) &&
3970 (eCSR_ENCRYPT_TYPE_AES !=
3971 pWextState->roamProfile.EncryptionType.encryptionType[0])
3972 )
3973 {
3974 /* Saving key direction for default key index to TX default */
3975 hdd_ap_ctx_t *pAPCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
3976 pAPCtx->wepKey[key_index].keyDirection = eSIR_TX_DEFAULT;
3977 }
3978 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303979
Jeff Johnson295189b2012-06-20 16:38:30 -07003980 return status;
3981}
3982
Jeff Johnson295189b2012-06-20 16:38:30 -07003983/*
3984 * FUNCTION: wlan_hdd_cfg80211_inform_bss
3985 * This function is used to inform the BSS details to nl80211 interface.
3986 */
3987static struct cfg80211_bss* wlan_hdd_cfg80211_inform_bss(
3988 hdd_adapter_t *pAdapter, tCsrRoamConnectedProfile *roamProfile)
3989{
3990 struct net_device *dev = pAdapter->dev;
3991 struct wireless_dev *wdev = dev->ieee80211_ptr;
3992 struct wiphy *wiphy = wdev->wiphy;
3993 tSirBssDescription *pBssDesc = roamProfile->pBssDesc;
3994 int chan_no;
3995 int ie_length;
3996 const char *ie;
3997 unsigned int freq;
3998 struct ieee80211_channel *chan;
3999 int rssi = 0;
4000 struct cfg80211_bss *bss = NULL;
4001
4002 ENTER();
4003
4004 if( NULL == pBssDesc )
4005 {
4006 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: pBssDesc is NULL\n", __func__);
4007 return bss;
4008 }
4009
4010 chan_no = pBssDesc->channelId;
4011 ie_length = GET_IE_LEN_IN_BSS_DESC( pBssDesc->length );
4012 ie = ((ie_length != 0) ? (const char *)&pBssDesc->ieFields: NULL);
4013
4014 if( NULL == ie )
4015 {
4016 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: IE of BSS descriptor is NULL\n", __func__);
4017 return bss;
4018 }
4019
4020#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,38))
4021 if (chan_no <= ARRAY_SIZE(hdd_channels_2_4_GHZ))
4022 {
4023 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_2GHZ);
4024 }
4025 else
4026 {
4027 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_5GHZ);
4028 }
4029#else
4030 freq = ieee80211_channel_to_frequency(chan_no);
4031#endif
4032
4033 chan = __ieee80211_get_channel(wiphy, freq);
4034
4035 bss = cfg80211_get_bss(wiphy, chan, pBssDesc->bssId,
4036 &roamProfile->SSID.ssId[0], roamProfile->SSID.length,
4037 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
4038 if (bss == NULL)
4039 {
4040 rssi = (VOS_MIN ((pBssDesc->rssi + pBssDesc->sinr), 0))*100;
4041
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304042 return (cfg80211_inform_bss(wiphy, chan, pBssDesc->bssId,
4043 le64_to_cpu(*(__le64 *)pBssDesc->timeStamp),
Jeff Johnson295189b2012-06-20 16:38:30 -07004044 pBssDesc->capabilityInfo,
4045 pBssDesc->beaconInterval, ie, ie_length,
4046 rssi, GFP_KERNEL ));
4047}
4048 else
4049 {
4050 return bss;
4051 }
4052}
4053
4054
4055
4056/*
4057 * FUNCTION: wlan_hdd_cfg80211_inform_bss_frame
4058 * This function is used to inform the BSS details to nl80211 interface.
4059 */
4060struct cfg80211_bss*
4061wlan_hdd_cfg80211_inform_bss_frame( hdd_adapter_t *pAdapter,
4062 tSirBssDescription *bss_desc
4063 )
4064{
4065 /*
4066 cfg80211_inform_bss() is not updating ie field of bss entry, if entry
4067 already exists in bss data base of cfg80211 for that particular BSS ID.
4068 Using cfg80211_inform_bss_frame to update the bss entry instead of
4069 cfg80211_inform_bss, But this call expects mgmt packet as input. As of
4070 now there is no possibility to get the mgmt(probe response) frame from PE,
4071 converting bss_desc to ieee80211_mgmt(probe response) and passing to
4072 cfg80211_inform_bss_frame.
4073 */
4074 struct net_device *dev = pAdapter->dev;
4075 struct wireless_dev *wdev = dev->ieee80211_ptr;
4076 struct wiphy *wiphy = wdev->wiphy;
4077 int chan_no = bss_desc->channelId;
Madan Mohan Koyyalamudi86f629e2012-11-09 16:27:29 -08004078#ifdef WLAN_ENABLE_AGEIE_ON_SCAN_RESULTS
4079 qcom_ie_age *qie_age = NULL;
4080 int ie_length = GET_IE_LEN_IN_BSS_DESC( bss_desc->length ) + sizeof(qcom_ie_age);
4081#else
Jeff Johnson295189b2012-06-20 16:38:30 -07004082 int ie_length = GET_IE_LEN_IN_BSS_DESC( bss_desc->length );
Madan Mohan Koyyalamudi86f629e2012-11-09 16:27:29 -08004083#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004084 const char *ie =
4085 ((ie_length != 0) ? (const char *)&bss_desc->ieFields: NULL);
4086 unsigned int freq;
4087 struct ieee80211_channel *chan;
4088 struct ieee80211_mgmt *mgmt =
4089 kzalloc((sizeof (struct ieee80211_mgmt) + ie_length), GFP_KERNEL);
4090 struct cfg80211_bss *bss_status = NULL;
4091 size_t frame_len = sizeof (struct ieee80211_mgmt) + ie_length;
4092 int rssi = 0;
Wilson Yangf80a0542013-10-07 13:02:37 -07004093 hdd_context_t *pHddCtx;
4094 int status;
Jeff Johnsone7245742012-09-05 17:12:55 -07004095#ifdef WLAN_OPEN_SOURCE
4096 struct timespec ts;
4097#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004098
4099 ENTER();
4100
Wilson Yangf80a0542013-10-07 13:02:37 -07004101 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
4102 status = wlan_hdd_validate_context(pHddCtx);
4103
4104 /*bss_update is not allowed during wlan driver loading or unloading*/
4105 if (pHddCtx->isLoadUnloadInProgress)
4106 {
4107 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4108 "%s:Loading_unloading in Progress. Ignore!!!",__func__);
4109 return NULL;
4110 }
4111
4112
4113 if (0 != status)
4114 {
4115 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4116 "%s: HDD context is not valid", __func__);
Madan Mohan Koyyalamudi2e5c9142012-11-02 13:17:48 -07004117 return NULL;
Wilson Yangf80a0542013-10-07 13:02:37 -07004118 }
4119
4120
4121 if (!mgmt)
4122 {
4123 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4124 "%s: memory allocation failed ", __func__);
4125 return NULL;
4126 }
Madan Mohan Koyyalamudi2e5c9142012-11-02 13:17:48 -07004127
Jeff Johnson295189b2012-06-20 16:38:30 -07004128 memcpy(mgmt->bssid, bss_desc->bssId, ETH_ALEN);
Jeff Johnsone7245742012-09-05 17:12:55 -07004129
4130#ifdef WLAN_OPEN_SOURCE
4131 /* Android does not want the timestamp from the frame.
4132 Instead it wants a monotonic increasing value */
4133 get_monotonic_boottime(&ts);
4134 mgmt->u.probe_resp.timestamp =
4135 ((u64)ts.tv_sec * 1000000) + (ts.tv_nsec / 1000);
4136#else
4137 /* keep old behavior for non-open source (for now) */
Jeff Johnson295189b2012-06-20 16:38:30 -07004138 memcpy(&mgmt->u.probe_resp.timestamp, bss_desc->timeStamp,
4139 sizeof (bss_desc->timeStamp));
Jeff Johnsone7245742012-09-05 17:12:55 -07004140
4141#endif
4142
Jeff Johnson295189b2012-06-20 16:38:30 -07004143 mgmt->u.probe_resp.beacon_int = bss_desc->beaconInterval;
4144 mgmt->u.probe_resp.capab_info = bss_desc->capabilityInfo;
Madan Mohan Koyyalamudi86f629e2012-11-09 16:27:29 -08004145
4146#ifdef WLAN_ENABLE_AGEIE_ON_SCAN_RESULTS
4147 /* GPS Requirement: need age ie per entry. Using vendor specific. */
4148 /* Assuming this is the last IE, copy at the end */
4149 ie_length -=sizeof(qcom_ie_age);
4150 qie_age = (qcom_ie_age *)(mgmt->u.probe_resp.variable + ie_length);
4151 qie_age->element_id = QCOM_VENDOR_IE_ID;
4152 qie_age->len = QCOM_VENDOR_IE_AGE_LEN;
4153 qie_age->oui_1 = QCOM_OUI1;
4154 qie_age->oui_2 = QCOM_OUI2;
4155 qie_age->oui_3 = QCOM_OUI3;
4156 qie_age->type = QCOM_VENDOR_IE_AGE_TYPE;
4157 qie_age->age = vos_timer_get_system_ticks() - bss_desc->nReceivedTime;
4158#endif
4159
Jeff Johnson295189b2012-06-20 16:38:30 -07004160 memcpy(mgmt->u.probe_resp.variable, ie, ie_length);
Gopichand Nakkalad908ec82013-05-16 19:32:19 +05304161 if (bss_desc->fProbeRsp)
4162 {
4163 mgmt->frame_control |=
4164 (u16)(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_RESP);
4165 }
4166 else
4167 {
4168 mgmt->frame_control |=
4169 (u16)(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_BEACON);
4170 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004171
4172#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,38))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304173 if (chan_no <= ARRAY_SIZE(hdd_channels_2_4_GHZ) &&
Jeff Johnson295189b2012-06-20 16:38:30 -07004174 (wiphy->bands[IEEE80211_BAND_2GHZ] != NULL))
4175 {
4176 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_2GHZ);
4177 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304178 else if ((chan_no > ARRAY_SIZE(hdd_channels_2_4_GHZ)) &&
Jeff Johnson295189b2012-06-20 16:38:30 -07004179 (wiphy->bands[IEEE80211_BAND_5GHZ] != NULL))
4180
4181 {
4182 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_5GHZ);
4183 }
4184 else
4185 {
4186 kfree(mgmt);
4187 return NULL;
4188 }
4189#else
4190 freq = ieee80211_channel_to_frequency(chan_no);
4191#endif
4192 chan = __ieee80211_get_channel(wiphy, freq);
Leela V Kiran Kumar Reddy90032de2013-01-24 18:33:30 -08004193 /*when the band is changed on the fly using the GUI, three things are done
4194 * 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)
4195 * as part of the scan abort, message willbe queued to PE and we proceed with flushing and changinh the band.
4196 * pe will stop the scanning further and report back the results what ever it had till now by calling the call back function.
4197 * if the time between update band and scandone call back is sufficent enough the band change reflects in SME, SME validates the channels
4198 * and discards the channels correponding to previous band and calls back with zero bss results.
4199 * 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
4200 * all the channels correponding to previous band.this is due to race condition.but those channels are invalid to the new band and so
4201 * this function __ieee80211_get_channel will return NULL.Each time we report scan result with this pointer null warning kernel trace is printed.
4202 * if the scan results contain large number of APs continuosly kernel warning trace is printed and it will lead to apps watch dog bark.
4203 * So drop the bss and continue to next bss.
4204 */
4205 if(chan == NULL)
4206 {
4207 hddLog(VOS_TRACE_LEVEL_INFO, "%s chan pointer is NULL", __func__);
Chilam Ngc4244af2013-04-01 15:37:32 -07004208 kfree(mgmt);
Leela V Kiran Kumar Reddy90032de2013-01-24 18:33:30 -08004209 return NULL;
4210 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004211 /*To keep the rssi icon of the connected AP in the scan window
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304212 *and the rssi icon of the wireless networks in sync
Jeff Johnson295189b2012-06-20 16:38:30 -07004213 * */
4214 if (( eConnectionState_Associated ==
4215 pAdapter->sessionCtx.station.conn_info.connState ) &&
4216 ( VOS_TRUE == vos_mem_compare(bss_desc->bssId,
4217 pAdapter->sessionCtx.station.conn_info.bssId,
4218 WNI_CFG_BSSID_LEN)))
4219 {
4220 /* supplicant takes the signal strength in terms of mBm(100*dBm) */
4221 rssi = (pAdapter->rssi * 100);
4222 }
4223 else
4224 {
4225 rssi = (VOS_MIN ((bss_desc->rssi + bss_desc->sinr), 0))*100;
4226 }
4227
4228 bss_status = cfg80211_inform_bss_frame(wiphy, chan, mgmt,
4229 frame_len, rssi, GFP_KERNEL);
4230 kfree(mgmt);
4231 return bss_status;
4232}
4233
4234/*
4235 * FUNCTION: wlan_hdd_cfg80211_update_bss_db
4236 * This function is used to update the BSS data base of CFG8011
4237 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304238struct cfg80211_bss* wlan_hdd_cfg80211_update_bss_db( hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07004239 tCsrRoamInfo *pRoamInfo
4240 )
4241{
4242 tCsrRoamConnectedProfile roamProfile;
4243 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
4244 struct cfg80211_bss *bss = NULL;
4245
4246 ENTER();
4247
4248 memset(&roamProfile, 0, sizeof(tCsrRoamConnectedProfile));
4249 sme_RoamGetConnectProfile(hHal, pAdapter->sessionId, &roamProfile);
4250
4251 if (NULL != roamProfile.pBssDesc)
4252 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304253 bss = wlan_hdd_cfg80211_inform_bss(pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07004254 &roamProfile);
4255
4256 if (NULL == bss)
4257 {
4258 hddLog(VOS_TRACE_LEVEL_INFO, "%s: cfg80211_inform_bss return NULL",
4259 __func__);
4260 }
4261
4262 sme_RoamFreeConnectProfile(hHal, &roamProfile);
4263 }
4264 else
4265 {
4266 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: roamProfile.pBssDesc is NULL",
4267 __func__);
4268 }
4269 return bss;
4270}
4271
4272/*
4273 * FUNCTION: wlan_hdd_cfg80211_update_bss
4274 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304275static int wlan_hdd_cfg80211_update_bss( struct wiphy *wiphy,
4276 hdd_adapter_t *pAdapter
Jeff Johnson295189b2012-06-20 16:38:30 -07004277 )
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304278{
Jeff Johnson295189b2012-06-20 16:38:30 -07004279 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
4280 tCsrScanResultInfo *pScanResult;
4281 eHalStatus status = 0;
4282 tScanResultHandle pResult;
4283 struct cfg80211_bss *bss_status = NULL;
Wilson Yangf80a0542013-10-07 13:02:37 -07004284 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07004285
4286 ENTER();
4287
Wilson Yangf80a0542013-10-07 13:02:37 -07004288 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
4289
4290 if (pHddCtx->isLogpInProgress)
Jeff Johnson295189b2012-06-20 16:38:30 -07004291 {
Wilson Yangf80a0542013-10-07 13:02:37 -07004292 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
4293 "%s:LOGP in Progress. Ignore!!!",__func__);
4294 return -EAGAIN;
Jeff Johnson295189b2012-06-20 16:38:30 -07004295 }
4296
Wilson Yangf80a0542013-10-07 13:02:37 -07004297
4298 /*bss_update is not allowed during wlan driver loading or unloading*/
4299 if (pHddCtx->isLoadUnloadInProgress)
4300 {
4301 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4302 "%s:Loading_unloading in Progress. Ignore!!!",__func__);
4303 return VOS_STATUS_E_PERM;
4304 }
4305
4306
Jeff Johnson295189b2012-06-20 16:38:30 -07004307 /*
4308 * start getting scan results and populate cgf80211 BSS database
4309 */
4310 status = sme_ScanGetResult(hHal, pAdapter->sessionId, NULL, &pResult);
4311
4312 /* no scan results */
4313 if (NULL == pResult)
4314 {
4315 hddLog(VOS_TRACE_LEVEL_INFO, "%s: No scan result\n", __func__);
4316 return status;
4317 }
4318
4319 pScanResult = sme_ScanResultGetFirst(hHal, pResult);
4320
4321 while (pScanResult)
4322 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304323 /*
4324 * cfg80211_inform_bss() is not updating ie field of bss entry, if
4325 * entry already exists in bss data base of cfg80211 for that
4326 * particular BSS ID. Using cfg80211_inform_bss_frame to update the
4327 * bss entry instead of cfg80211_inform_bss, But this call expects
4328 * mgmt packet as input. As of now there is no possibility to get
4329 * the mgmt(probe response) frame from PE, converting bss_desc to
Jeff Johnson295189b2012-06-20 16:38:30 -07004330 * ieee80211_mgmt(probe response) and passing to c
4331 * fg80211_inform_bss_frame.
4332 * */
4333
4334 bss_status = wlan_hdd_cfg80211_inform_bss_frame(pAdapter,
4335 &pScanResult->BssDescriptor);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304336
Jeff Johnson295189b2012-06-20 16:38:30 -07004337
4338 if (NULL == bss_status)
4339 {
4340 hddLog(VOS_TRACE_LEVEL_INFO,
4341 "%s: NULL returned by cfg80211_inform_bss\n", __func__);
4342 }
4343 else
4344 {
Yue Maf49ba872013-08-19 12:04:25 -07004345 cfg80211_put_bss(
4346#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,9,0))
4347 wiphy,
4348#endif
4349 bss_status);
Jeff Johnson295189b2012-06-20 16:38:30 -07004350 }
4351
4352 pScanResult = sme_ScanResultGetNext(hHal, pResult);
4353 }
4354
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304355 sme_ScanResultPurge(hHal, pResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07004356
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304357 return 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07004358}
4359
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004360void
4361hddPrintMacAddr(tCsrBssid macAddr, tANI_U8 logLevel)
4362{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304363 VOS_TRACE(VOS_MODULE_ID_HDD, logLevel,
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07004364 "%02X:%02X:%02X:%02X:%02X:%02X\n",
4365 macAddr[0], macAddr[1], macAddr[2], macAddr[3], macAddr[4],
4366 macAddr[5]);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004367} /****** end hddPrintMacAddr() ******/
4368
4369void
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07004370hddPrintPmkId(tANI_U8 *pmkId, tANI_U8 logLevel)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004371{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304372 VOS_TRACE(VOS_MODULE_ID_HDD, logLevel,
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07004373 "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
4374 pmkId[0], pmkId[1], pmkId[2], pmkId[3], pmkId[4],
4375 pmkId[5], pmkId[6], pmkId[7], pmkId[8], pmkId[9], pmkId[10],
4376 pmkId[11], pmkId[12], pmkId[13], pmkId[14], pmkId[15]);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004377} /****** end hddPrintPmkId() ******/
4378
4379//hddPrintMacAddr(tCsrBssid macAddr, tANI_U8 logLevel);
4380//hddPrintMacAddr(macAddr, VOS_TRACE_LEVEL_FATAL);
4381
4382//void sirDumpBuf(tpAniSirGlobal pMac, tANI_U8 modId, tANI_U32 level, tANI_U8 *buf, tANI_U32 size);
4383//sirDumpBuf(pMac, VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL, pmkid, 16);
4384
4385#define dump_bssid(bssid) \
4386 { \
Jeff Johnsone7245742012-09-05 17:12:55 -07004387 hddLog(VOS_TRACE_LEVEL_INFO, "BSSID (MAC) address:\t"); \
4388 hddPrintMacAddr(bssid, VOS_TRACE_LEVEL_INFO);\
4389 hddLog(VOS_TRACE_LEVEL_INFO, "\n"); \
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004390 }
4391
4392#define dump_pmkid(pMac, pmkid) \
4393 { \
Jeff Johnsone7245742012-09-05 17:12:55 -07004394 hddLog(VOS_TRACE_LEVEL_INFO, "PMKSA-ID:\t"); \
4395 hddPrintPmkId(pmkid, VOS_TRACE_LEVEL_INFO);\
4396 hddLog(VOS_TRACE_LEVEL_INFO, "\n"); \
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004397 }
4398
Madan Mohan Koyyalamudi1b4afb02012-10-22 15:25:16 -07004399#if defined(FEATURE_WLAN_LFR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004400/*
4401 * FUNCTION: wlan_hdd_cfg80211_pmksa_candidate_notify
4402 * This function is used to notify the supplicant of a new PMKSA candidate.
4403 */
4404int wlan_hdd_cfg80211_pmksa_candidate_notify(
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304405 hdd_adapter_t *pAdapter, tCsrRoamInfo *pRoamInfo,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004406 int index, bool preauth )
4407{
Jeff Johnsone7245742012-09-05 17:12:55 -07004408#ifdef FEATURE_WLAN_OKC
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004409 struct net_device *dev = pAdapter->dev;
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004410 hdd_context_t *pHddCtx = (hdd_context_t*)pAdapter->pHddCtx;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004411
4412 ENTER();
Jeff Johnsone7245742012-09-05 17:12:55 -07004413 hddLog(VOS_TRACE_LEVEL_INFO, "%s is going to notify supplicant of:", __func__);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004414
4415 if( NULL == pRoamInfo )
4416 {
4417 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: pRoamInfo is NULL\n", __func__);
4418 return -EINVAL;
4419 }
4420
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004421 if (eANI_BOOLEAN_TRUE == hdd_is_okc_mode_enabled(pHddCtx))
4422 {
4423 dump_bssid(pRoamInfo->bssid);
4424 cfg80211_pmksa_candidate_notify(dev, index,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004425 pRoamInfo->bssid, preauth, GFP_KERNEL);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004426 }
Jeff Johnsone7245742012-09-05 17:12:55 -07004427#endif /* FEATURE_WLAN_OKC */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304428 return 0;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004429}
4430#endif //FEATURE_WLAN_LFR
4431
Yue Maef608272013-04-08 23:09:17 -07004432#ifdef FEATURE_WLAN_LFR_METRICS
4433/*
4434 * FUNCTION: wlan_hdd_cfg80211_roam_metrics_preauth
4435 * 802.11r/LFR metrics reporting function to report preauth initiation
4436 *
4437 */
4438#define MAX_LFR_METRICS_EVENT_LENGTH 100
4439VOS_STATUS wlan_hdd_cfg80211_roam_metrics_preauth(hdd_adapter_t *pAdapter,
4440 tCsrRoamInfo *pRoamInfo)
4441{
4442 unsigned char metrics_notification[MAX_LFR_METRICS_EVENT_LENGTH + 1];
4443 union iwreq_data wrqu;
4444
4445 ENTER();
4446
4447 if (NULL == pAdapter)
4448 {
4449 hddLog(LOGE, "%s: pAdapter is NULL!", __func__);
4450 return VOS_STATUS_E_FAILURE;
4451 }
4452
4453 /* create the event */
4454 memset(&wrqu, 0, sizeof(wrqu));
4455 memset(metrics_notification, 0, sizeof(metrics_notification));
4456
4457 wrqu.data.pointer = metrics_notification;
4458 wrqu.data.length = scnprintf(metrics_notification,
4459 sizeof(metrics_notification), "QCOM: LFR_PREAUTH_INIT "
4460 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(pRoamInfo->bssid));
4461
4462 wireless_send_event(pAdapter->dev, IWEVCUSTOM, &wrqu, metrics_notification);
4463
4464 EXIT();
4465
4466 return VOS_STATUS_SUCCESS;
4467}
4468
4469/*
4470 * FUNCTION: wlan_hdd_cfg80211_roam_metrics_preauth_status
4471 * 802.11r/LFR metrics reporting function to report preauth completion
4472 * or failure
4473 */
4474VOS_STATUS wlan_hdd_cfg80211_roam_metrics_preauth_status(
4475 hdd_adapter_t *pAdapter, tCsrRoamInfo *pRoamInfo, bool preauth_status)
4476{
4477 unsigned char metrics_notification[MAX_LFR_METRICS_EVENT_LENGTH + 1];
4478 union iwreq_data wrqu;
4479
4480 ENTER();
4481
4482 if (NULL == pAdapter)
4483 {
4484 hddLog(LOGE, "%s: pAdapter is NULL!", __func__);
4485 return VOS_STATUS_E_FAILURE;
4486 }
4487
4488 /* create the event */
4489 memset(&wrqu, 0, sizeof(wrqu));
4490 memset(metrics_notification, 0, sizeof(metrics_notification));
4491
4492 scnprintf(metrics_notification, sizeof(metrics_notification),
4493 "QCOM: LFR_PREAUTH_STATUS "MAC_ADDRESS_STR,
4494 MAC_ADDR_ARRAY(pRoamInfo->bssid));
4495
4496 if (1 == preauth_status)
4497 strncat(metrics_notification, " TRUE", 5);
4498 else
4499 strncat(metrics_notification, " FALSE", 6);
4500
4501 wrqu.data.pointer = metrics_notification;
4502 wrqu.data.length = strlen(metrics_notification);
4503
4504 wireless_send_event(pAdapter->dev, IWEVCUSTOM, &wrqu, metrics_notification);
4505
4506 EXIT();
4507
4508 return VOS_STATUS_SUCCESS;
4509}
4510
4511/*
4512 * FUNCTION: wlan_hdd_cfg80211_roam_metrics_handover
4513 * 802.11r/LFR metrics reporting function to report handover initiation
4514 *
4515 */
4516VOS_STATUS wlan_hdd_cfg80211_roam_metrics_handover(hdd_adapter_t * pAdapter,
4517 tCsrRoamInfo *pRoamInfo)
4518{
4519 unsigned char metrics_notification[MAX_LFR_METRICS_EVENT_LENGTH + 1];
4520 union iwreq_data wrqu;
4521
4522 ENTER();
4523
4524 if (NULL == pAdapter)
4525 {
4526 hddLog(LOGE, "%s: pAdapter is NULL!", __func__);
4527 return VOS_STATUS_E_FAILURE;
4528 }
4529
4530 /* create the event */
4531 memset(&wrqu, 0, sizeof(wrqu));
4532 memset(metrics_notification, 0, sizeof(metrics_notification));
4533
4534 wrqu.data.pointer = metrics_notification;
4535 wrqu.data.length = scnprintf(metrics_notification,
4536 sizeof(metrics_notification), "QCOM: LFR_PREAUTH_HANDOVER "
4537 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(pRoamInfo->bssid));
4538
4539 wireless_send_event(pAdapter->dev, IWEVCUSTOM, &wrqu, metrics_notification);
4540
4541 EXIT();
4542
4543 return VOS_STATUS_SUCCESS;
4544}
4545#endif
4546
Jeff Johnson295189b2012-06-20 16:38:30 -07004547/*
4548 * FUNCTION: hdd_cfg80211_scan_done_callback
4549 * scanning callback function, called after finishing scan
4550 *
4551 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304552static eHalStatus hdd_cfg80211_scan_done_callback(tHalHandle halHandle,
Jeff Johnson295189b2012-06-20 16:38:30 -07004553 void *pContext, tANI_U32 scanId, eCsrScanStatus status)
4554{
4555 struct net_device *dev = (struct net_device *) pContext;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304556 //struct wireless_dev *wdev = dev->ieee80211_ptr;
Jeff Johnson295189b2012-06-20 16:38:30 -07004557 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004558 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
4559 hdd_scaninfo_t *pScanInfo = &pHddCtx->scan_info;
Jeff Johnson295189b2012-06-20 16:38:30 -07004560 struct cfg80211_scan_request *req = NULL;
4561 int ret = 0;
4562
4563 ENTER();
4564
4565 hddLog(VOS_TRACE_LEVEL_INFO,
4566 "%s called with halHandle = %p, pContext = %p,"
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304567 "scanID = %d, returned status = %d\n",
Jeff Johnson295189b2012-06-20 16:38:30 -07004568 __func__, halHandle, pContext, (int) scanId, (int) status);
4569
4570 //Block on scan req completion variable. Can't wait forever though.
4571 ret = wait_for_completion_interruptible_timeout(
4572 &pScanInfo->scan_req_completion_event,
4573 msecs_to_jiffies(WLAN_WAIT_TIME_SCAN_REQ));
4574 if (!ret)
4575 {
4576 VOS_ASSERT(pScanInfo->mScanPending);
Jeff Johnsone7245742012-09-05 17:12:55 -07004577 goto allow_suspend;
Jeff Johnson295189b2012-06-20 16:38:30 -07004578 }
4579
Yue Maef608272013-04-08 23:09:17 -07004580 if (pScanInfo->mScanPending != VOS_TRUE)
Jeff Johnson295189b2012-06-20 16:38:30 -07004581 {
4582 VOS_ASSERT(pScanInfo->mScanPending);
Jeff Johnsone7245742012-09-05 17:12:55 -07004583 goto allow_suspend;
Jeff Johnson295189b2012-06-20 16:38:30 -07004584 }
4585
4586 /* Check the scanId */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304587 if (pScanInfo->scanId != scanId)
Jeff Johnson295189b2012-06-20 16:38:30 -07004588 {
4589 hddLog(VOS_TRACE_LEVEL_INFO,
4590 "%s called with mismatched scanId pScanInfo->scanId = %d "
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304591 "scanId = %d \n", __func__, (int) pScanInfo->scanId,
Jeff Johnson295189b2012-06-20 16:38:30 -07004592 (int) scanId);
4593 }
4594
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304595 ret = wlan_hdd_cfg80211_update_bss((WLAN_HDD_GET_CTX(pAdapter))->wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07004596 pAdapter);
4597
4598 if (0 > ret)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304599 hddLog(VOS_TRACE_LEVEL_INFO, "%s: NO SCAN result", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07004600
4601
4602 /* If any client wait scan result through WEXT
4603 * send scan done event to client */
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004604 if (pHddCtx->scan_info.waitScanResult)
Jeff Johnson295189b2012-06-20 16:38:30 -07004605 {
4606 /* The other scan request waiting for current scan finish
4607 * Send event to notify current scan finished */
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004608 if(WEXT_SCAN_PENDING_DELAY == pHddCtx->scan_info.scan_pending_option)
Jeff Johnson295189b2012-06-20 16:38:30 -07004609 {
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004610 vos_event_set(&pHddCtx->scan_info.scan_finished_event);
Jeff Johnson295189b2012-06-20 16:38:30 -07004611 }
4612 /* Send notify to WEXT client */
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004613 else if(WEXT_SCAN_PENDING_PIGGYBACK == pHddCtx->scan_info.scan_pending_option)
Jeff Johnson295189b2012-06-20 16:38:30 -07004614 {
4615 struct net_device *dev = pAdapter->dev;
4616 union iwreq_data wrqu;
4617 int we_event;
4618 char *msg;
4619
4620 memset(&wrqu, '\0', sizeof(wrqu));
4621 we_event = SIOCGIWSCAN;
4622 msg = NULL;
4623 wireless_send_event(dev, we_event, &wrqu, msg);
4624 }
4625 }
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004626 pHddCtx->scan_info.waitScanResult = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004627
4628 /* Get the Scan Req */
4629 req = pAdapter->request;
4630
4631 if (!req)
4632 {
4633 hddLog(VOS_TRACE_LEVEL_ERROR, "request is became NULL\n");
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07004634 pScanInfo->mScanPending = VOS_FALSE;
Jeff Johnsone7245742012-09-05 17:12:55 -07004635 goto allow_suspend;
Jeff Johnson295189b2012-06-20 16:38:30 -07004636 }
4637
4638 /*
4639 * setting up 0, just in case.
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304640 */
Jeff Johnson295189b2012-06-20 16:38:30 -07004641 req->n_ssids = 0;
4642 req->n_channels = 0;
4643 req->ie = 0;
4644
Jeff Johnson295189b2012-06-20 16:38:30 -07004645 pAdapter->request = NULL;
Jeff Johnsone7245742012-09-05 17:12:55 -07004646 /* Scan is no longer pending */
4647 pScanInfo->mScanPending = VOS_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004648
Madan Mohan Koyyalamudib764bf82012-10-11 16:38:51 -07004649 /*
4650 * cfg80211_scan_done informing NL80211 about completion
4651 * of scanning
4652 */
4653 cfg80211_scan_done(req, false);
Madan Mohan Koyyalamudif4e81002012-11-13 10:46:38 -08004654 complete(&pScanInfo->abortscan_event_var);
Jeff Johnson295189b2012-06-20 16:38:30 -07004655
Jeff Johnsone7245742012-09-05 17:12:55 -07004656allow_suspend:
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07004657 /* release the wake lock at the end of the scan*/
4658 hdd_allow_suspend();
Jeff Johnsone7245742012-09-05 17:12:55 -07004659
Madan Mohan Koyyalamudi10d83a92012-09-28 15:47:05 -07004660 /* Acquire wakelock to handle the case where APP's tries to suspend
4661 * immediatly after the driver gets connect request(i.e after scan)
4662 * from supplicant, this result in app's is suspending and not able
4663 * to process the connect request to AP */
Amar Singhal6144c002013-05-03 16:11:42 -07004664 hdd_allow_suspend_timeout(1000);
Madan Mohan Koyyalamudi10d83a92012-09-28 15:47:05 -07004665
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07004666#ifdef FEATURE_WLAN_TDLS
4667 wlan_hdd_tdls_scan_done_callback(pAdapter);
4668#endif
4669
Jeff Johnson295189b2012-06-20 16:38:30 -07004670 EXIT();
4671 return 0;
4672}
4673
4674/*
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004675 * FUNCTION: hdd_isScanAllowed
4676 * Go through each adapter and check if scan allowed
4677 *
4678 */
4679v_BOOL_t hdd_isScanAllowed( hdd_context_t *pHddCtx )
4680{
4681 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
4682 hdd_station_ctx_t *pHddStaCtx = NULL;
4683 hdd_adapter_t *pAdapter = NULL;
4684 VOS_STATUS status = 0;
4685 v_U8_t staId = 0;
4686 v_U8_t *staMac = NULL;
4687
4688 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
4689
4690 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
4691 {
4692 pAdapter = pAdapterNode->pAdapter;
4693
4694 if( pAdapter )
4695 {
4696 hddLog(VOS_TRACE_LEVEL_INFO,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304697 "%s: Adapter with device mode %d exists",
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004698 __func__, pAdapter->device_mode);
4699 if ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
4700 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) ||
4701 (WLAN_HDD_P2P_DEVICE == pAdapter->device_mode))
4702 {
4703 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
4704 if ((eConnectionState_Associated == pHddStaCtx->conn_info.connState) &&
4705 (VOS_FALSE == pHddStaCtx->conn_info.uIsAuthenticated))
4706 {
4707 staMac = (v_U8_t *) &(pAdapter->macAddressCurrent.bytes[0]);
4708 hddLog(VOS_TRACE_LEVEL_ERROR,
4709 "%s: client %02x:%02x:%02x:%02x:%02x:%02x is in the "
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304710 "middle of WPS/EAPOL exchange.", __func__,
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004711 staMac[0], staMac[1], staMac[2],
4712 staMac[3], staMac[4], staMac[5]);
4713 return VOS_FALSE;
4714 }
4715 }
4716 else if ((WLAN_HDD_SOFTAP == pAdapter->device_mode) ||
4717 (WLAN_HDD_P2P_GO == pAdapter->device_mode))
4718 {
4719 for (staId = 0; staId < WLAN_MAX_STA_COUNT; staId++)
4720 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304721 if ((pAdapter->aStaInfo[staId].isUsed) &&
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004722 (WLANTL_STA_CONNECTED == pAdapter->aStaInfo[staId].tlSTAState))
4723 {
4724 staMac = (v_U8_t *) &(pAdapter->aStaInfo[staId].macAddrSTA.bytes[0]);
4725
4726 hddLog(VOS_TRACE_LEVEL_ERROR,
4727 "%s: client %02x:%02x:%02x:%02x:%02x:%02x of SoftAP/P2P-GO is in the "
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304728 "middle of WPS/EAPOL exchange.", __func__,
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004729 staMac[0], staMac[1], staMac[2],
4730 staMac[3], staMac[4], staMac[5]);
4731 return VOS_FALSE;
4732 }
4733 }
4734 }
4735 }
4736 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
4737 pAdapterNode = pNext;
4738 }
4739 hddLog(VOS_TRACE_LEVEL_INFO,
4740 "%s: Scan allowed", __func__);
4741 return VOS_TRUE;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304742}
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004743
4744/*
Jeff Johnson295189b2012-06-20 16:38:30 -07004745 * FUNCTION: wlan_hdd_cfg80211_scan
4746 * this scan respond to scan trigger and update cfg80211 scan database
4747 * later, scan dump command can be used to recieve scan results
4748 */
Jeff Johnson3bbe4bf2013-01-18 17:05:29 -08004749int wlan_hdd_cfg80211_scan( struct wiphy *wiphy,
4750#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
4751 struct net_device *dev,
4752#endif
4753 struct cfg80211_scan_request *request)
4754{
4755#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
4756 struct net_device *dev = request->wdev->netdev;
4757#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304758 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Jeff Johnson295189b2012-06-20 16:38:30 -07004759 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
4760 hdd_wext_state_t *pwextBuf = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05304761 hdd_config_t *cfg_param = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004762 tCsrScanRequest scanRequest;
4763 tANI_U8 *channelList = NULL, i;
4764 v_U32_t scanId = 0;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05304765 int status;
4766 hdd_scaninfo_t *pScanInfo = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004767 v_U8_t* pP2pIe = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004768
4769 ENTER();
4770
4771 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
4772 __func__,pAdapter->device_mode);
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004773
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05304774 status = wlan_hdd_validate_context(pHddCtx);
4775
4776 if (0 != status)
4777 {
4778 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4779 "%s: HDD context is not valid", __func__);
4780 return status;
4781 }
4782
4783 cfg_param = pHddCtx->cfg_ini;
4784 pScanInfo = &pHddCtx->scan_info;
4785
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004786 if ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) &&
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004787 (eConnectionState_Connecting ==
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004788 (WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))->conn_info.connState))
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004789 {
4790 hddLog(VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08004791 "%s: %p(%d) Connection in progress: Scan request denied (EBUSY)", __func__, \
4792 WLAN_HDD_GET_STATION_CTX_PTR(pAdapter), pAdapter->sessionId);
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004793 return -EBUSY;
4794 }
4795
Jeff Johnson295189b2012-06-20 16:38:30 -07004796#ifdef WLAN_BTAMP_FEATURE
4797 //Scan not supported when AMP traffic is on.
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004798 if (VOS_TRUE == WLANBAP_AmpSessionOn())
Jeff Johnson295189b2012-06-20 16:38:30 -07004799 {
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004800 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07004801 "%s: No scanning when AMP is on", __func__);
4802 return -EOPNOTSUPP;
4803 }
4804#endif
4805 //Scan on any other interface is not supported.
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004806 if (pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07004807 {
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004808 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07004809 "%s: Not scanning on device_mode = %d",
4810 __func__, pAdapter->device_mode);
4811 return -EOPNOTSUPP;
4812 }
4813
4814 if (TRUE == pScanInfo->mScanPending)
4815 {
4816 hddLog(VOS_TRACE_LEVEL_INFO, "%s: mScanPending is TRUE", __func__);
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004817 return -EBUSY;
Jeff Johnson295189b2012-06-20 16:38:30 -07004818 }
4819
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304820 //Don't Allow Scan and return busy if Remain On
Jeff Johnson32d95a32012-09-10 13:15:23 -07004821 //Channel and action frame is pending
4822 //Otherwise Cancel Remain On Channel and allow Scan
4823 //If no action frame pending
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004824 if (0 != wlan_hdd_check_remain_on_channel(pAdapter))
Jeff Johnson32d95a32012-09-10 13:15:23 -07004825 {
4826 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Remain On Channel Pending", __func__);
4827 return -EBUSY;
4828 }
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004829#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07004830 /* if tdls disagree scan right now, return immediately.
4831 tdls will schedule the scan when scan is allowed. (return SUCCESS)
4832 or will reject the scan if any TDLS is in progress. (return -EBUSY)
4833 */
4834 status = wlan_hdd_tdls_scan_callback (pAdapter,
4835 wiphy,
4836#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
4837 dev,
Gopichand Nakkalac3c42b92013-03-20 19:42:34 -07004838#endif
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07004839 request);
4840 if(status <= 0)
4841 {
4842 hddLog(VOS_TRACE_LEVEL_INFO, "%s: TDLS Pending %d", __func__, status);
4843 return status;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004844 }
4845#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -07004846
Jeff Johnson295189b2012-06-20 16:38:30 -07004847 if (mutex_lock_interruptible(&pHddCtx->tmInfo.tmOperationLock))
4848 {
4849 VOS_TRACE(VOS_MODULE_ID_HDD,VOS_TRACE_LEVEL_ERROR,
Jeff Johnson1250df42012-12-10 14:31:52 -08004850 "%s: Acquire lock fail", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07004851 return -EAGAIN;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304852 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004853 if (TRUE == pHddCtx->tmInfo.tmAction.enterImps)
4854 {
4855 hddLog(VOS_TRACE_LEVEL_WARN,
4856 "%s: MAX TM Level Scan not allowed", __func__);
4857 mutex_unlock(&pHddCtx->tmInfo.tmOperationLock);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304858 return -EBUSY;
Jeff Johnson295189b2012-06-20 16:38:30 -07004859 }
4860 mutex_unlock(&pHddCtx->tmInfo.tmOperationLock);
4861
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004862 /* Check if scan is allowed at this point of time.
4863 */
4864 if (!hdd_isScanAllowed(pHddCtx))
4865 {
4866 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Scan not allowed", __func__);
4867 return -EBUSY;
4868 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304869
Jeff Johnson295189b2012-06-20 16:38:30 -07004870 vos_mem_zero( &scanRequest, sizeof(scanRequest));
4871
4872 if (NULL != request)
4873 {
4874 hddLog(VOS_TRACE_LEVEL_INFO, "scan request for ssid = %d",
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304875 (int)request->n_ssids);
Jeff Johnson295189b2012-06-20 16:38:30 -07004876
4877 /* Even though supplicant doesn't provide any SSIDs, n_ssids is set to 1.
4878 * Becasue of this, driver is assuming that this is not wildcard scan and so
4879 * is not aging out the scan results.
4880 */
Jeff Johnson32d95a32012-09-10 13:15:23 -07004881 if (request->ssids && '\0' == request->ssids->ssid[0])
Jeff Johnson295189b2012-06-20 16:38:30 -07004882 {
4883 request->n_ssids = 0;
4884 }
4885
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07004886 if ((request->ssids) && (0 < request->n_ssids))
Jeff Johnson295189b2012-06-20 16:38:30 -07004887 {
4888 tCsrSSIDInfo *SsidInfo;
4889 int j;
4890 scanRequest.SSIDs.numOfSSIDs = request->n_ssids;
4891 /* Allocate num_ssid tCsrSSIDInfo structure */
4892 SsidInfo = scanRequest.SSIDs.SSIDList =
4893 ( tCsrSSIDInfo *)vos_mem_malloc(
4894 request->n_ssids*sizeof(tCsrSSIDInfo));
4895
4896 if(NULL == scanRequest.SSIDs.SSIDList)
4897 {
4898 hddLog(VOS_TRACE_LEVEL_ERROR,
4899 "memory alloc failed SSIDInfo buffer");
4900 return -ENOMEM;
4901 }
4902
4903 /* copy all the ssid's and their length */
4904 for(j = 0; j < request->n_ssids; j++, SsidInfo++)
4905 {
4906 /* get the ssid length */
4907 SsidInfo->SSID.length = request->ssids[j].ssid_len;
4908 vos_mem_copy(SsidInfo->SSID.ssId, &request->ssids[j].ssid[0],
4909 SsidInfo->SSID.length);
4910 SsidInfo->SSID.ssId[SsidInfo->SSID.length] = '\0';
4911 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "SSID number %d: %s",
4912 j, SsidInfo->SSID.ssId);
4913 }
4914 /* set the scan type to active */
4915 scanRequest.scanType = eSIR_ACTIVE_SCAN;
4916 }
4917 else if(WLAN_HDD_P2P_GO == pAdapter->device_mode)
4918 {
4919 /* set the scan type to active */
4920 scanRequest.scanType = eSIR_ACTIVE_SCAN;
4921 }
4922 else
4923 {
4924 /*Set the scan type to default type, in this case it is ACTIVE*/
4925 scanRequest.scanType = pScanInfo->scan_mode;
4926 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304927 scanRequest.minChnTime = cfg_param->nActiveMinChnTime;
Jeff Johnson295189b2012-06-20 16:38:30 -07004928 scanRequest.maxChnTime = cfg_param->nActiveMaxChnTime;
4929 }
4930 else
4931 {
4932 /* set the scan type to active */
4933 scanRequest.scanType = eSIR_ACTIVE_SCAN;
4934 vos_mem_set( scanRequest.bssid, sizeof( tCsrBssid ), 0xff );
4935
4936 /* set min and max channel time to zero */
4937 scanRequest.minChnTime = 0;
4938 scanRequest.maxChnTime = 0;
4939 }
4940
4941 /* set BSSType to default type */
4942 scanRequest.BSSType = eCSR_BSS_TYPE_ANY;
4943
4944 /*TODO: scan the requested channels only*/
4945
4946 /*Right now scanning all the channels */
4947 if( request )
4948 {
4949 if( request->n_channels )
4950 {
4951 channelList = vos_mem_malloc( request->n_channels );
4952 if( NULL == channelList )
4953 {
4954 status = -ENOMEM;
4955 goto free_mem;
4956 }
4957
4958 for( i = 0 ; i < request->n_channels ; i++ )
4959 channelList[i] = request->channels[i]->hw_value;
4960 }
4961
4962 scanRequest.ChannelInfo.numOfChannels = request->n_channels;
4963 scanRequest.ChannelInfo.ChannelList = channelList;
4964
4965 /* set requestType to full scan */
4966 scanRequest.requestType = eCSR_SCAN_REQUEST_FULL_SCAN;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304967
4968 /* Flush the scan results(only p2p beacons) for STA scan and P2P
Madan Mohan Koyyalamudi8d50f312012-11-27 15:48:57 -08004969 * search (Flush on both full scan and social scan but not on single
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304970 * channel scan).P2P search happens on 3 social channels (1, 6, 11)
Madan Mohan Koyyalamudi8d50f312012-11-27 15:48:57 -08004971 */
4972
4973 /* Supplicant does single channel scan after 8-way handshake
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304974 * and in that case driver shoudnt flush scan results. If
4975 * driver flushes the scan results here and unfortunately if
4976 * the AP doesnt respond to our probe req then association
Madan Mohan Koyyalamudi8d50f312012-11-27 15:48:57 -08004977 * fails which is not desired
4978 */
4979
4980 if( request->n_channels != WLAN_HDD_P2P_SINGLE_CHANNEL_SCAN )
4981 {
4982 sme_ScanFlushP2PResult( WLAN_HDD_GET_HAL_CTX(pAdapter),
4983 pAdapter->sessionId );
4984 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004985
4986 if( request->ie_len )
4987 {
4988 /* save this for future association (join requires this) */
4989 memset( &pScanInfo->scanAddIE, 0, sizeof(pScanInfo->scanAddIE) );
4990 memcpy( pScanInfo->scanAddIE.addIEdata, request->ie, request->ie_len);
4991 pScanInfo->scanAddIE.length = request->ie_len;
4992
4993 if((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
Jeff Johnsone7245742012-09-05 17:12:55 -07004994 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) ||
4995 (WLAN_HDD_P2P_DEVICE == pAdapter->device_mode)
Jeff Johnson295189b2012-06-20 16:38:30 -07004996 )
4997 {
4998 pwextBuf->roamProfile.pAddIEScan = pScanInfo->scanAddIE.addIEdata;
4999 pwextBuf->roamProfile.nAddIEScanLength = pScanInfo->scanAddIE.length;
5000 }
5001
5002 scanRequest.uIEFieldLen = pScanInfo->scanAddIE.length;
5003 scanRequest.pIEField = pScanInfo->scanAddIE.addIEdata;
5004
Jeff Johnson295189b2012-06-20 16:38:30 -07005005 pP2pIe = wlan_hdd_get_p2p_ie_ptr((v_U8_t*)request->ie,
5006 request->ie_len);
5007 if (pP2pIe != NULL)
5008 {
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07005009#ifdef WLAN_FEATURE_P2P_DEBUG
5010 if (((globalP2PConnectionStatus == P2P_GO_NEG_COMPLETED) ||
5011 (globalP2PConnectionStatus == P2P_GO_NEG_PROCESS)) &&
5012 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
5013 {
5014 globalP2PConnectionStatus = P2P_CLIENT_CONNECTING_STATE_1;
5015 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P State] Changing state from "
5016 "Go nego completed to Connection is started");
5017 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P]P2P Scanning is started "
5018 "for 8way Handshake");
5019 }
5020 else if((globalP2PConnectionStatus == P2P_CLIENT_DISCONNECTED_STATE) &&
5021 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
5022 {
5023 globalP2PConnectionStatus = P2P_CLIENT_CONNECTING_STATE_2;
5024 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P State] Changing state from "
5025 "Disconnected state to Connection is started");
5026 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P]P2P Scanning is started "
5027 "for 4way Handshake");
5028 }
5029#endif
5030
Jeff Johnsone7245742012-09-05 17:12:55 -07005031 /* no_cck will be set during p2p find to disable 11b rates */
5032 if(TRUE == request->no_cck)
Jeff Johnson295189b2012-06-20 16:38:30 -07005033 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005034 hddLog(VOS_TRACE_LEVEL_INFO,
5035 "%s: This is a P2P Search", __func__);
5036 scanRequest.p2pSearch = 1;
Jeff Johnsone7245742012-09-05 17:12:55 -07005037
Jeff Johnsone7245742012-09-05 17:12:55 -07005038 if( request->n_channels == WLAN_HDD_P2P_SOCIAL_CHANNELS )
5039 {
Madan Mohan Koyyalamudi1b1d9e82012-10-21 11:38:33 -07005040 /* set requestType to P2P Discovery */
5041 scanRequest.requestType = eCSR_SCAN_P2P_DISCOVERY;
Jeff Johnsone7245742012-09-05 17:12:55 -07005042 }
5043
5044 /*
5045 Skip Dfs Channel in case of P2P Search
5046 if it is set in ini file
5047 */
5048 if(cfg_param->skipDfsChnlInP2pSearch)
5049 {
5050 scanRequest.skipDfsChnlInP2pSearch = 1;
5051 }
5052 else
5053 {
5054 scanRequest.skipDfsChnlInP2pSearch = 0;
5055 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005056
Jeff Johnson295189b2012-06-20 16:38:30 -07005057 }
5058 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005059 }
5060 }
5061
5062 INIT_COMPLETION(pScanInfo->scan_req_completion_event);
5063
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07005064 /* acquire the wakelock to avoid the apps suspend during the scan. To
5065 * address the following issues.
5066 * 1) Disconnected scenario: we are not allowing the suspend as WLAN is not in
5067 * BMPS/IMPS this result in android trying to suspend aggressively and backing off
5068 * for long time, this result in apps running at full power for long time.
5069 * 2) Connected scenario: If we allow the suspend during the scan, RIVA will
5070 * be stuck in full power because of resume BMPS
5071 */
5072 hdd_prevent_suspend();
Jeff Johnsone7245742012-09-05 17:12:55 -07005073
5074 status = sme_ScanRequest( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07005075 pAdapter->sessionId, &scanRequest, &scanId,
5076 &hdd_cfg80211_scan_done_callback, dev );
Jeff Johnsone7245742012-09-05 17:12:55 -07005077
Jeff Johnson295189b2012-06-20 16:38:30 -07005078 if (eHAL_STATUS_SUCCESS != status)
5079 {
5080 hddLog(VOS_TRACE_LEVEL_ERROR,
5081 "%s: sme_ScanRequest returned error %d", __func__, status);
5082 complete(&pScanInfo->scan_req_completion_event);
Madan Mohan Koyyalamudi3b230fe2012-10-18 14:46:32 -07005083 if(eHAL_STATUS_RESOURCES == status)
5084 {
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07005085 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 -07005086 status = -EBUSY;
5087 } else {
5088 status = -EIO;
5089 }
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07005090 hdd_allow_suspend();
Jeff Johnson295189b2012-06-20 16:38:30 -07005091 goto free_mem;
5092 }
5093
5094 pScanInfo->mScanPending = TRUE;
5095 pAdapter->request = request;
5096 pScanInfo->scanId = scanId;
5097
5098 complete(&pScanInfo->scan_req_completion_event);
5099
5100free_mem:
5101 if( scanRequest.SSIDs.SSIDList )
5102 {
5103 vos_mem_free(scanRequest.SSIDs.SSIDList);
5104 }
5105
5106 if( channelList )
5107 vos_mem_free( channelList );
5108
5109 EXIT();
5110
5111 return status;
5112}
5113
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07005114
5115void hdd_select_cbmode( hdd_adapter_t *pAdapter,v_U8_t operationChannel)
5116{
5117 v_U8_t iniDot11Mode =
5118 (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini->dot11Mode;
5119 eHddDot11Mode hddDot11Mode = iniDot11Mode;
5120
5121 switch ( iniDot11Mode )
5122 {
5123 case eHDD_DOT11_MODE_AUTO:
5124 case eHDD_DOT11_MODE_11ac:
5125 case eHDD_DOT11_MODE_11ac_ONLY:
5126#ifdef WLAN_FEATURE_11AC
5127 hddDot11Mode = eHDD_DOT11_MODE_11ac;
5128#else
5129 hddDot11Mode = eHDD_DOT11_MODE_11n;
5130#endif
5131 break;
5132 case eHDD_DOT11_MODE_11n:
5133 case eHDD_DOT11_MODE_11n_ONLY:
5134 hddDot11Mode = eHDD_DOT11_MODE_11n;
5135 break;
5136 default:
5137 hddDot11Mode = iniDot11Mode;
5138 break;
5139 }
5140 /* This call decides required channel bonding mode */
5141 sme_SelectCBMode((WLAN_HDD_GET_CTX(pAdapter)->hHal),
5142 hdd_cfg_xlate_to_csr_phy_mode(hddDot11Mode),
5143 operationChannel);
5144}
5145
Jeff Johnson295189b2012-06-20 16:38:30 -07005146/*
5147 * FUNCTION: wlan_hdd_cfg80211_connect_start
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305148 * This function is used to start the association process
Jeff Johnson295189b2012-06-20 16:38:30 -07005149 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305150int wlan_hdd_cfg80211_connect_start( hdd_adapter_t *pAdapter,
Jeff Johnson32d95a32012-09-10 13:15:23 -07005151 const u8 *ssid, size_t ssid_len, const u8 *bssid, u8 operatingChannel)
Jeff Johnson295189b2012-06-20 16:38:30 -07005152{
5153 int status = 0;
5154 hdd_wext_state_t *pWextState;
5155 v_U32_t roamId;
5156 tCsrRoamProfile *pRoamProfile;
5157 eMib_dot11DesiredBssType connectedBssType;
5158 eCsrAuthType RSNAuthType;
5159
5160 ENTER();
5161
5162 pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305163
Jeff Johnson295189b2012-06-20 16:38:30 -07005164 if (SIR_MAC_MAX_SSID_LENGTH < ssid_len)
5165 {
5166 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: wrong SSID len", __func__);
5167 return -EINVAL;
5168 }
5169
5170 pRoamProfile = &pWextState->roamProfile;
5171
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305172 if (pRoamProfile)
Jeff Johnson295189b2012-06-20 16:38:30 -07005173 {
Jeff Johnsone7245742012-09-05 17:12:55 -07005174 int ret = 0;
5175 hdd_station_ctx_t *pHddStaCtx;
5176 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
5177 hdd_connGetConnectedBssType(pHddStaCtx,&connectedBssType );
5178
5179 if((eMib_dot11DesiredBssType_independent == connectedBssType) ||
5180 (eConnectionState_Associated == pHddStaCtx->conn_info.connState) ||
5181 (eConnectionState_IbssConnected == pHddStaCtx->conn_info.connState))
Jeff Johnson295189b2012-06-20 16:38:30 -07005182 {
5183 /* Issue disconnect to CSR */
5184 INIT_COMPLETION(pAdapter->disconnect_comp_var);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305185 if( eHAL_STATUS_SUCCESS ==
Jeff Johnson295189b2012-06-20 16:38:30 -07005186 sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
5187 pAdapter->sessionId,
5188 eCSR_DISCONNECT_REASON_UNSPECIFIED ) )
5189 {
Jeff Johnsone7245742012-09-05 17:12:55 -07005190 ret = wait_for_completion_interruptible_timeout(
5191 &pAdapter->disconnect_comp_var,
5192 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
5193 if (0 == ret)
5194 {
5195 VOS_ASSERT(0);
5196 }
5197 }
5198 }
5199 else if(eConnectionState_Disconnecting == pHddStaCtx->conn_info.connState)
5200 {
5201 ret = wait_for_completion_interruptible_timeout(
5202 &pAdapter->disconnect_comp_var,
5203 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
5204 if (0 == ret)
5205 {
5206 VOS_ASSERT(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005207 }
5208 }
5209
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305210 if (HDD_WMM_USER_MODE_NO_QOS ==
Jeff Johnson295189b2012-06-20 16:38:30 -07005211 (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini->WmmMode)
5212 {
5213 /*QoS not enabled in cfg file*/
5214 pRoamProfile->uapsd_mask = 0;
5215 }
5216 else
5217 {
5218 /*QoS enabled, update uapsd mask from cfg file*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305219 pRoamProfile->uapsd_mask =
Jeff Johnson295189b2012-06-20 16:38:30 -07005220 (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini->UapsdMask;
5221 }
5222
5223 pRoamProfile->SSIDs.numOfSSIDs = 1;
5224 pRoamProfile->SSIDs.SSIDList->SSID.length = ssid_len;
5225 vos_mem_zero(pRoamProfile->SSIDs.SSIDList->SSID.ssId,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305226 sizeof(pRoamProfile->SSIDs.SSIDList->SSID.ssId));
Jeff Johnson295189b2012-06-20 16:38:30 -07005227 vos_mem_copy((void *)(pRoamProfile->SSIDs.SSIDList->SSID.ssId),
5228 ssid, ssid_len);
5229
5230 if (bssid)
5231 {
5232 pRoamProfile->BSSIDs.numOfBSSIDs = 1;
5233 vos_mem_copy((void *)(pRoamProfile->BSSIDs.bssid), bssid,
5234 WNI_CFG_BSSID_LEN);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305235 /* Save BSSID in seperate variable as well, as RoamProfile
5236 BSSID is getting zeroed out in the association process. And in
Jeff Johnson295189b2012-06-20 16:38:30 -07005237 case of join failure we should send valid BSSID to supplicant
5238 */
5239 vos_mem_copy((void *)(pWextState->req_bssId), bssid,
5240 WNI_CFG_BSSID_LEN);
5241 }
Dhanashri Atre51981c62013-06-13 11:47:57 -07005242 else
5243 {
5244 vos_mem_zero((void *)(pRoamProfile->BSSIDs.bssid),WNI_CFG_BSSID_LEN);
5245 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005246
5247 if ((IW_AUTH_WPA_VERSION_WPA == pWextState->wpaVersion) ||
5248 (IW_AUTH_WPA_VERSION_WPA2 == pWextState->wpaVersion))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305249 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005250 /*set gen ie*/
5251 hdd_SetGENIEToCsr(pAdapter, &RSNAuthType);
5252 /*set auth*/
5253 hdd_set_csr_auth_type(pAdapter, RSNAuthType);
5254 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005255#ifdef FEATURE_WLAN_WAPI
5256 if (pAdapter->wapi_info.nWapiMode)
5257 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005258 hddLog(LOG1, "%s: Setting WAPI AUTH Type and Encryption Mode values", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005259 switch (pAdapter->wapi_info.wapiAuthMode)
5260 {
5261 case WAPI_AUTH_MODE_PSK:
5262 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005263 hddLog(LOG1, "%s: WAPI AUTH TYPE: PSK: %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07005264 pAdapter->wapi_info.wapiAuthMode);
5265 pRoamProfile->AuthType.authType[0] = eCSR_AUTH_TYPE_WAPI_WAI_PSK;
5266 break;
5267 }
5268 case WAPI_AUTH_MODE_CERT:
5269 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005270 hddLog(LOG1, "%s: WAPI AUTH TYPE: CERT: %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07005271 pAdapter->wapi_info.wapiAuthMode);
5272 pRoamProfile->AuthType.authType[0] = eCSR_AUTH_TYPE_WAPI_WAI_CERTIFICATE;
5273 break;
5274 }
5275 } // End of switch
5276 if ( pAdapter->wapi_info.wapiAuthMode == WAPI_AUTH_MODE_PSK ||
5277 pAdapter->wapi_info.wapiAuthMode == WAPI_AUTH_MODE_CERT)
5278 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005279 hddLog(LOG1, "%s: WAPI PAIRWISE/GROUP ENCRYPTION: WPI", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005280 pRoamProfile->AuthType.numEntries = 1;
5281 pRoamProfile->EncryptionType.numEntries = 1;
5282 pRoamProfile->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_WPI;
5283 pRoamProfile->mcEncryptionType.numEntries = 1;
5284 pRoamProfile->mcEncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_WPI;
5285 }
5286 }
5287#endif /* FEATURE_WLAN_WAPI */
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05305288#ifdef WLAN_FEATURE_GTK_OFFLOAD
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05305289 /* Initializing gtkOffloadReqParams */
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05305290 if ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
5291 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
5292 {
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05305293 memset(&pHddStaCtx->gtkOffloadReqParams, 0,
5294 sizeof (tSirGtkOffloadParams));
5295 pHddStaCtx->gtkOffloadReqParams.ulFlags = GTK_OFFLOAD_DISABLE;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05305296 }
5297#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005298 pRoamProfile->csrPersona = pAdapter->device_mode;
5299
Jeff Johnson32d95a32012-09-10 13:15:23 -07005300 if( operatingChannel )
5301 {
5302 pRoamProfile->ChannelInfo.ChannelList = &operatingChannel;
5303 pRoamProfile->ChannelInfo.numOfChannels = 1;
5304 }
Chet Lanctot186b5732013-03-18 10:26:30 -07005305 else
5306 {
5307 pRoamProfile->ChannelInfo.ChannelList = NULL;
5308 pRoamProfile->ChannelInfo.numOfChannels = 0;
5309 }
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07005310 if ( (WLAN_HDD_IBSS == pAdapter->device_mode) && operatingChannel)
5311 {
5312 hdd_select_cbmode(pAdapter,operatingChannel);
5313 }
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08005314 /* change conn_state to connecting before sme_RoamConnect(), because sme_RoamConnect()
5315 * has a direct path to call hdd_smeRoamCallback(), which will change the conn_state
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305316 * If direct path, conn_state will be accordingly changed to NotConnected or Associated
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08005317 * by either hdd_AssociationCompletionHandler() or hdd_DisConnectHandler() in sme_RoamCallback()
Madan Mohan Koyyalamudidf86c422012-12-04 17:03:44 -08005318 * if sme_RomConnect is to be queued, Connecting state will remain until it is completed.
5319 */
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +05305320 if (WLAN_HDD_INFRA_STATION == pAdapter->device_mode ||
5321 WLAN_HDD_P2P_CLIENT == pAdapter->device_mode)
Madan Mohan Koyyalamudidf86c422012-12-04 17:03:44 -08005322 hdd_connSetConnectionState(WLAN_HDD_GET_STATION_CTX_PTR(pAdapter),
5323 eConnectionState_Connecting);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305324
5325 status = sme_RoamConnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07005326 pAdapter->sessionId, pRoamProfile, &roamId);
5327
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +05305328 if ((eHAL_STATUS_SUCCESS != status) &&
5329 (WLAN_HDD_INFRA_STATION == pAdapter->device_mode ||
5330 WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
Madan Mohan Koyyalamudid5acbf52012-11-28 01:45:08 +05305331
5332 {
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08005333 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: sme_RoamConnect (session %d) failed with "
5334 "status %d. -> NotConnected", __func__, pAdapter->sessionId, status);
5335 /* change back to NotAssociated */
Madan Mohan Koyyalamudid5acbf52012-11-28 01:45:08 +05305336 hdd_connSetConnectionState(WLAN_HDD_GET_STATION_CTX_PTR(pAdapter),
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08005337 eConnectionState_NotConnected);
Madan Mohan Koyyalamudid5acbf52012-11-28 01:45:08 +05305338 }
Madan Mohan Koyyalamudidf86c422012-12-04 17:03:44 -08005339
5340 pRoamProfile->ChannelInfo.ChannelList = NULL;
5341 pRoamProfile->ChannelInfo.numOfChannels = 0;
5342
Jeff Johnson295189b2012-06-20 16:38:30 -07005343 }
5344 else
5345 {
5346 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: No valid Roam profile", __func__);
5347 return -EINVAL;
5348 }
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08005349 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07005350 return status;
5351}
5352
5353/*
5354 * FUNCTION: wlan_hdd_set_cfg80211_auth_type
5355 * This function is used to set the authentication type (OPEN/SHARED).
5356 *
5357 */
5358static int wlan_hdd_cfg80211_set_auth_type(hdd_adapter_t *pAdapter,
5359 enum nl80211_auth_type auth_type)
5360{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305361 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07005362 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
5363
5364 ENTER();
5365
5366 /*set authentication type*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305367 switch (auth_type)
Jeff Johnson295189b2012-06-20 16:38:30 -07005368 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005369 case NL80211_AUTHTYPE_AUTOMATIC:
Gopichand Nakkala29149562013-05-10 21:43:41 +05305370 hddLog(VOS_TRACE_LEVEL_INFO,
5371 "%s: set authentication type to AUTOSWITCH", __func__);
5372 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_AUTOSWITCH;
5373 break;
5374
5375 case NL80211_AUTHTYPE_OPEN_SYSTEM:
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07005376#ifdef WLAN_FEATURE_VOWIFI_11R
5377 case NL80211_AUTHTYPE_FT:
5378#endif /* WLAN_FEATURE_VOWIFI_11R */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305379 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07005380 "%s: set authentication type to OPEN", __func__);
5381 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
5382 break;
5383
5384 case NL80211_AUTHTYPE_SHARED_KEY:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305385 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07005386 "%s: set authentication type to SHARED", __func__);
5387 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_SHARED_KEY;
5388 break;
5389#ifdef FEATURE_WLAN_CCX
5390 case NL80211_AUTHTYPE_NETWORK_EAP:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305391 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07005392 "%s: set authentication type to CCKM WPA", __func__);
5393 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_CCKM_WPA;//eCSR_AUTH_TYPE_CCKM_RSN needs to be handled as well if required.
5394 break;
5395#endif
5396
5397
5398 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305399 hddLog(VOS_TRACE_LEVEL_ERROR,
5400 "%s: Unsupported authentication type %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07005401 auth_type);
5402 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_UNKNOWN;
5403 return -EINVAL;
5404 }
5405
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305406 pWextState->roamProfile.AuthType.authType[0] =
Jeff Johnson295189b2012-06-20 16:38:30 -07005407 pHddStaCtx->conn_info.authType;
5408 return 0;
5409}
5410
5411/*
5412 * FUNCTION: wlan_hdd_set_akm_suite
5413 * This function is used to set the key mgmt type(PSK/8021x).
5414 *
5415 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305416static int wlan_hdd_set_akm_suite( hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07005417 u32 key_mgmt
5418 )
5419{
5420 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
5421 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305422
Jeff Johnson295189b2012-06-20 16:38:30 -07005423 /*set key mgmt type*/
5424 switch(key_mgmt)
5425 {
5426 case WLAN_AKM_SUITE_PSK:
Gopichand Nakkala356fb102013-03-06 12:34:04 +05305427#ifdef WLAN_FEATURE_VOWIFI_11R
5428 case WLAN_AKM_SUITE_FT_PSK:
5429#endif
5430 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting key mgmt type to PSK",
Jeff Johnson295189b2012-06-20 16:38:30 -07005431 __func__);
5432 pWextState->authKeyMgmt |= IW_AUTH_KEY_MGMT_PSK;
5433 break;
5434
5435 case WLAN_AKM_SUITE_8021X:
Gopichand Nakkala356fb102013-03-06 12:34:04 +05305436#ifdef WLAN_FEATURE_VOWIFI_11R
5437 case WLAN_AKM_SUITE_FT_8021X:
5438#endif
5439 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting key mgmt type to 8021x",
Jeff Johnson295189b2012-06-20 16:38:30 -07005440 __func__);
5441 pWextState->authKeyMgmt |= IW_AUTH_KEY_MGMT_802_1X;
5442 break;
5443#ifdef FEATURE_WLAN_CCX
5444#define WLAN_AKM_SUITE_CCKM 0x00409600 /* Should be in ieee802_11_defs.h */
5445#define IW_AUTH_KEY_MGMT_CCKM 8 /* Should be in linux/wireless.h */
5446 case WLAN_AKM_SUITE_CCKM:
5447 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting key mgmt type to CCKM",
5448 __func__);
5449 pWextState->authKeyMgmt |= IW_AUTH_KEY_MGMT_CCKM;
5450 break;
5451#endif
5452
5453 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305454 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported key mgmt type %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005455 __func__, key_mgmt);
5456 return -EINVAL;
5457
5458 }
5459 return 0;
5460}
5461
5462/*
5463 * FUNCTION: wlan_hdd_cfg80211_set_cipher
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305464 * This function is used to set the encryption type
Jeff Johnson295189b2012-06-20 16:38:30 -07005465 * (NONE/WEP40/WEP104/TKIP/CCMP).
5466 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305467static int wlan_hdd_cfg80211_set_cipher( hdd_adapter_t *pAdapter,
5468 u32 cipher,
Jeff Johnson295189b2012-06-20 16:38:30 -07005469 bool ucast
5470 )
5471{
5472 eCsrEncryptionType encryptionType = eCSR_ENCRYPT_TYPE_NONE;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305473 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07005474 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
5475
5476 ENTER();
5477
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305478 if (!cipher)
Jeff Johnson295189b2012-06-20 16:38:30 -07005479 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305480 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: received cipher %d - considering none",
Jeff Johnson295189b2012-06-20 16:38:30 -07005481 __func__, cipher);
5482 encryptionType = eCSR_ENCRYPT_TYPE_NONE;
5483 }
5484 else
5485 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305486
Jeff Johnson295189b2012-06-20 16:38:30 -07005487 /*set encryption method*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305488 switch (cipher)
Jeff Johnson295189b2012-06-20 16:38:30 -07005489 {
5490 case IW_AUTH_CIPHER_NONE:
5491 encryptionType = eCSR_ENCRYPT_TYPE_NONE;
5492 break;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305493
Jeff Johnson295189b2012-06-20 16:38:30 -07005494 case WLAN_CIPHER_SUITE_WEP40:
Gopichand Nakkala29149562013-05-10 21:43:41 +05305495 encryptionType = eCSR_ENCRYPT_TYPE_WEP40;
Jeff Johnson295189b2012-06-20 16:38:30 -07005496 break;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305497
Jeff Johnson295189b2012-06-20 16:38:30 -07005498 case WLAN_CIPHER_SUITE_WEP104:
Gopichand Nakkala29149562013-05-10 21:43:41 +05305499 encryptionType = eCSR_ENCRYPT_TYPE_WEP104;
Jeff Johnson295189b2012-06-20 16:38:30 -07005500 break;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305501
Jeff Johnson295189b2012-06-20 16:38:30 -07005502 case WLAN_CIPHER_SUITE_TKIP:
5503 encryptionType = eCSR_ENCRYPT_TYPE_TKIP;
5504 break;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305505
Jeff Johnson295189b2012-06-20 16:38:30 -07005506 case WLAN_CIPHER_SUITE_CCMP:
5507 encryptionType = eCSR_ENCRYPT_TYPE_AES;
5508 break;
5509#ifdef FEATURE_WLAN_WAPI
5510 case WLAN_CIPHER_SUITE_SMS4:
5511 encryptionType = eCSR_ENCRYPT_TYPE_WPI;
5512 break;
5513#endif
5514
5515#ifdef FEATURE_WLAN_CCX
5516 case WLAN_CIPHER_SUITE_KRK:
5517 encryptionType = eCSR_ENCRYPT_TYPE_KRK;
5518 break;
5519#endif
5520 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305521 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported cipher type %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005522 __func__, cipher);
5523 return -EOPNOTSUPP;
5524 }
5525 }
5526
5527 if (ucast)
5528 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305529 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting unicast cipher type to %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005530 __func__, encryptionType);
5531 pHddStaCtx->conn_info.ucEncryptionType = encryptionType;
5532 pWextState->roamProfile.EncryptionType.numEntries = 1;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305533 pWextState->roamProfile.EncryptionType.encryptionType[0] =
Jeff Johnson295189b2012-06-20 16:38:30 -07005534 encryptionType;
5535 }
5536 else
5537 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305538 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting mcast cipher type to %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005539 __func__, encryptionType);
5540 pHddStaCtx->conn_info.mcEncryptionType = encryptionType;
5541 pWextState->roamProfile.mcEncryptionType.numEntries = 1;
5542 pWextState->roamProfile.mcEncryptionType.encryptionType[0] = encryptionType;
5543 }
5544
5545 return 0;
5546}
5547
5548
5549/*
5550 * FUNCTION: wlan_hdd_cfg80211_set_ie
5551 * This function is used to parse WPA/RSN IE's.
5552 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305553int wlan_hdd_cfg80211_set_ie( hdd_adapter_t *pAdapter,
5554 u8 *ie,
Jeff Johnson295189b2012-06-20 16:38:30 -07005555 size_t ie_len
5556 )
5557{
5558 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
5559 u8 *genie = ie;
5560 v_U16_t remLen = ie_len;
5561#ifdef FEATURE_WLAN_WAPI
5562 v_U32_t akmsuite[MAX_NUM_AKM_SUITES];
5563 u16 *tmp;
5564 v_U16_t akmsuiteCount;
5565 int *akmlist;
5566#endif
5567 ENTER();
5568
5569 /* clear previous assocAddIE */
5570 pWextState->assocAddIE.length = 0;
5571 pWextState->roamProfile.bWPSAssociation = VOS_FALSE;
5572
5573 while (remLen >= 2)
5574 {
5575 v_U16_t eLen = 0;
5576 v_U8_t elementId;
5577 elementId = *genie++;
5578 eLen = *genie++;
5579 remLen -= 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305580
5581 hddLog(VOS_TRACE_LEVEL_INFO, "%s: IE[0x%X], LEN[%d]\n",
Jeff Johnson295189b2012-06-20 16:38:30 -07005582 __func__, elementId, eLen);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305583
5584 switch ( elementId )
Jeff Johnson295189b2012-06-20 16:38:30 -07005585 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305586 case DOT11F_EID_WPA:
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005587 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 -07005588 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305589 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005590 "%s: Invalid WPA IE", __func__);
5591 return -EINVAL;
5592 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305593 else if (0 == memcmp(&genie[0], "\x00\x50\xf2\x04", 4))
Jeff Johnson295189b2012-06-20 16:38:30 -07005594 {
5595 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305596 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set WPS IE(len %d)",
Jeff Johnson295189b2012-06-20 16:38:30 -07005597 __func__, eLen + 2);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305598
Jeff Johnson295189b2012-06-20 16:38:30 -07005599 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5600 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005601 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE. "
5602 "Need bigger buffer space");
Jeff Johnson295189b2012-06-20 16:38:30 -07005603 VOS_ASSERT(0);
5604 return -ENOMEM;
5605 }
5606 // WSC IE is saved to Additional IE ; it should be accumulated to handle WPS IE + P2P IE
5607 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5608 pWextState->assocAddIE.length += eLen + 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305609
Jeff Johnson295189b2012-06-20 16:38:30 -07005610 pWextState->roamProfile.bWPSAssociation = VOS_TRUE;
5611 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5612 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5613 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305614 else if (0 == memcmp(&genie[0], "\x00\x50\xf2", 3))
5615 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005616 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set WPA IE (len %d)",__func__, eLen + 2);
5617 memset( pWextState->WPARSNIE, 0, MAX_WPA_RSN_IE_LEN );
5618 memcpy( pWextState->WPARSNIE, genie - 2, (eLen + 2) /*ie_len*/);
5619 pWextState->roamProfile.pWPAReqIE = pWextState->WPARSNIE;
5620 pWextState->roamProfile.nWPAReqIELength = eLen + 2;//ie_len;
5621 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305622 else if ( (0 == memcmp(&genie[0], P2P_OUI_TYPE,
5623 P2P_OUI_TYPE_SIZE))
Jeff Johnson295189b2012-06-20 16:38:30 -07005624 /*Consider P2P IE, only for P2P Client */
5625 && (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) )
5626 {
5627 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305628 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set P2P IE(len %d)",
Jeff Johnson295189b2012-06-20 16:38:30 -07005629 __func__, eLen + 2);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305630
Jeff Johnson295189b2012-06-20 16:38:30 -07005631 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5632 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005633 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
5634 "Need bigger buffer space");
Jeff Johnson295189b2012-06-20 16:38:30 -07005635 VOS_ASSERT(0);
5636 return -ENOMEM;
5637 }
5638 // P2P IE is saved to Additional IE ; it should be accumulated to handle WPS IE + P2P IE
5639 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5640 pWextState->assocAddIE.length += eLen + 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305641
Jeff Johnson295189b2012-06-20 16:38:30 -07005642 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5643 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5644 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005645#ifdef WLAN_FEATURE_WFD
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305646 else if ( (0 == memcmp(&genie[0], WFD_OUI_TYPE,
5647 WFD_OUI_TYPE_SIZE))
Jeff Johnson295189b2012-06-20 16:38:30 -07005648 /*Consider WFD IE, only for P2P Client */
5649 && (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) )
5650 {
5651 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305652 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set WFD IE(len %d)",
Jeff Johnson295189b2012-06-20 16:38:30 -07005653 __func__, eLen + 2);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305654
Jeff Johnson295189b2012-06-20 16:38:30 -07005655 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5656 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005657 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
5658 "Need bigger buffer space");
Jeff Johnson295189b2012-06-20 16:38:30 -07005659 VOS_ASSERT(0);
5660 return -ENOMEM;
5661 }
5662 // WFD IE is saved to Additional IE ; it should be accumulated to handle
5663 // WPS IE + P2P IE + WFD IE
5664 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5665 pWextState->assocAddIE.length += eLen + 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305666
Jeff Johnson295189b2012-06-20 16:38:30 -07005667 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5668 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5669 }
5670#endif
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005671 /* Appending HS 2.0 Indication Element in Assiciation Request */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305672 else if ( (0 == memcmp(&genie[0], HS20_OUI_TYPE,
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005673 HS20_OUI_TYPE_SIZE)) )
5674 {
5675 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305676 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set HS20 IE(len %d)",
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005677 __func__, eLen + 2);
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005678
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005679 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5680 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005681 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
5682 "Need bigger buffer space");
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005683 VOS_ASSERT(0);
5684 return -ENOMEM;
5685 }
5686 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5687 pWextState->assocAddIE.length += eLen + 2;
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005688
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005689 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5690 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5691 }
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005692
Praveen Kumar Sirisilla7d68b7b2013-09-22 14:01:42 -07005693 if (WLAN_HDD_IBSS == pAdapter->device_mode) {
5694
5695 /* populating as ADDIE in beacon frames */
5696 if (ccmCfgSetStr(WLAN_HDD_GET_HAL_CTX(pAdapter),
5697 WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA, genie - 2, eLen + 2,
5698 NULL, eANI_BOOLEAN_FALSE)== eHAL_STATUS_SUCCESS)
5699 {
5700 if (ccmCfgSetInt(WLAN_HDD_GET_HAL_CTX(pAdapter),
5701 WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG, 1,NULL,
5702 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
5703 {
5704 hddLog(LOGE,
5705 "Coldn't pass "
5706 "WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG to CCM");
5707 }
5708 }/* ccmCfgSetStr(,WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA, , )*/
5709 else
5710 hddLog(LOGE,
5711 "Could not pass on "
5712 "WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA to CCM");
5713
5714 /* IBSS mode doesn't contain params->proberesp_ies still
5715 beaconIE's need to be populated in probe response frames */
5716 if ( (NULL != (genie - 2)) && (0 != eLen + 2) )
5717 {
5718 u16 rem_probe_resp_ie_len = eLen + 2;
5719 u8 probe_rsp_ie_len[3] = {0};
5720 u8 counter = 0;
5721
5722 /* Check Probe Resp Length if it is greater then 255 then
5723 Store Probe Rsp IEs into WNI_CFG_PROBE_RSP_ADDNIE_DATA1
5724 & WNI_CFG_PROBE_RSP_ADDNIE_DATA2 CFG Variable As We are
5725 not able Store More then 255 bytes into One Variable */
5726
5727 while ((rem_probe_resp_ie_len > 0) && (counter < 3))
5728 {
5729 if (rem_probe_resp_ie_len > MAX_CFG_STRING_LEN)
5730 {
5731 probe_rsp_ie_len[counter++] = MAX_CFG_STRING_LEN;
5732 rem_probe_resp_ie_len -= MAX_CFG_STRING_LEN;
5733 }
5734 else
5735 {
5736 probe_rsp_ie_len[counter++] = rem_probe_resp_ie_len;
5737 rem_probe_resp_ie_len = 0;
5738 }
5739 }
5740
5741 rem_probe_resp_ie_len = 0;
5742
5743 if (probe_rsp_ie_len[0] > 0)
5744 {
5745 if (ccmCfgSetStr(WLAN_HDD_GET_HAL_CTX(pAdapter),
5746 WNI_CFG_PROBE_RSP_ADDNIE_DATA1,
5747 (tANI_U8*)(genie - 2),
5748 probe_rsp_ie_len[0], NULL,
5749 eANI_BOOLEAN_FALSE)
5750 == eHAL_STATUS_FAILURE)
5751 {
5752 hddLog(LOGE,
5753 "Could not pass"
5754 "on WNI_CFG_PROBE_RSP_ADDNIE_DATA1 to CCM");
5755 }
5756 rem_probe_resp_ie_len += probe_rsp_ie_len[0];
5757 }
5758
5759 if (probe_rsp_ie_len[1] > 0)
5760 {
5761 if (ccmCfgSetStr(WLAN_HDD_GET_HAL_CTX(pAdapter),
5762 WNI_CFG_PROBE_RSP_ADDNIE_DATA2,
5763 (tANI_U8*)(genie - (2 + rem_probe_resp_ie_len)),
5764 probe_rsp_ie_len[1], NULL,
5765 eANI_BOOLEAN_FALSE)
5766 == eHAL_STATUS_FAILURE)
5767 {
5768 hddLog(LOGE,
5769 "Could not pass"
5770 "on WNI_CFG_PROBE_RSP_ADDNIE_DATA2 to CCM");
5771 }
5772 rem_probe_resp_ie_len += probe_rsp_ie_len[1];
5773 }
5774
5775 if (probe_rsp_ie_len[2] > 0)
5776 {
5777 if (ccmCfgSetStr(WLAN_HDD_GET_HAL_CTX(pAdapter),
5778 WNI_CFG_PROBE_RSP_ADDNIE_DATA3,
5779 (tANI_U8*)(genie - (2 + rem_probe_resp_ie_len)),
5780 probe_rsp_ie_len[2], NULL,
5781 eANI_BOOLEAN_FALSE)
5782 == eHAL_STATUS_FAILURE)
5783 {
5784 hddLog(LOGE,
5785 "Could not pass"
5786 "on WNI_CFG_PROBE_RSP_ADDNIE_DATA3 to CCM");
5787 }
5788 rem_probe_resp_ie_len += probe_rsp_ie_len[2];
5789 }
5790
5791 if (ccmCfgSetInt(WLAN_HDD_GET_HAL_CTX(pAdapter),
5792 WNI_CFG_PROBE_RSP_ADDNIE_FLAG, 1,NULL,
5793 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
5794 {
5795 hddLog(LOGE,
5796 "Could not pass"
5797 "on WNI_CFG_PROBE_RSP_ADDNIE_FLAG to CCM");
5798 }
5799 }
5800 else
5801 {
5802 // Reset WNI_CFG_PROBE_RSP Flags
5803 wlan_hdd_reset_prob_rspies(pAdapter);
5804
5805 hddLog(VOS_TRACE_LEVEL_INFO,
5806 "%s: No Probe Response IE received in set beacon",
5807 __func__);
5808 }
5809 } /* end of if (WLAN_HDD_IBSS == pAdapter->device_mode) */
Jeff Johnson295189b2012-06-20 16:38:30 -07005810 break;
5811 case DOT11F_EID_RSN:
5812 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set RSN IE(len %d)",__func__, eLen + 2);
5813 memset( pWextState->WPARSNIE, 0, MAX_WPA_RSN_IE_LEN );
5814 memcpy( pWextState->WPARSNIE, genie - 2, (eLen + 2)/*ie_len*/);
5815 pWextState->roamProfile.pRSNReqIE = pWextState->WPARSNIE;
5816 pWextState->roamProfile.nRSNReqIELength = eLen + 2; //ie_len;
5817 break;
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005818 /* Appending Extended Capabilities with Interworking bit set in Assoc Req */
5819 case DOT11F_EID_EXTCAP:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305820 {
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005821 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305822 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set Extended CAPS IE(len %d)",
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005823 __func__, eLen + 2);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305824
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005825 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5826 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005827 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
5828 "Need bigger buffer space");
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005829 VOS_ASSERT(0);
5830 return -ENOMEM;
5831 }
5832 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5833 pWextState->assocAddIE.length += eLen + 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305834
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005835 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5836 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5837 break;
5838 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005839#ifdef FEATURE_WLAN_WAPI
5840 case WLAN_EID_WAPI:
5841 pAdapter->wapi_info.nWapiMode = 1; //Setting WAPI Mode to ON=1
Jeff Johnson0299d0a2013-10-30 12:37:43 -07005842 hddLog(VOS_TRACE_LEVEL_INFO, "WAPI MODE IS %u",
Jeff Johnson295189b2012-06-20 16:38:30 -07005843 pAdapter->wapi_info.nWapiMode);
5844 tmp = (u16 *)ie;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305845 tmp = tmp + 2; // Skip element Id and Len, Version
Jeff Johnson295189b2012-06-20 16:38:30 -07005846 akmsuiteCount = WPA_GET_LE16(tmp);
5847 tmp = tmp + 1;
5848 akmlist = (int *)(tmp);
5849 if(akmsuiteCount <= MAX_NUM_AKM_SUITES)
5850 {
5851 memcpy(akmsuite, akmlist, (4*akmsuiteCount));
5852 }
5853 else
5854 {
5855 hddLog(VOS_TRACE_LEVEL_FATAL, "Invalid akmSuite count\n");
5856 VOS_ASSERT(0);
5857 return -EINVAL;
5858 }
5859
5860 if (WAPI_PSK_AKM_SUITE == akmsuite[0])
5861 {
5862 hddLog(VOS_TRACE_LEVEL_INFO, "%s: WAPI AUTH MODE SET TO PSK",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005863 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005864 pAdapter->wapi_info.wapiAuthMode = WAPI_AUTH_MODE_PSK;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305865 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005866 if (WAPI_CERT_AKM_SUITE == akmsuite[0])
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305867 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005868 hddLog(VOS_TRACE_LEVEL_INFO, "%s: WAPI AUTH MODE SET TO CERTIFICATE",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005869 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005870 pAdapter->wapi_info.wapiAuthMode = WAPI_AUTH_MODE_CERT;
5871 }
5872 break;
5873#endif
5874 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305875 hddLog (VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005876 "%s Set UNKNOWN IE %X", __func__, elementId);
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005877 /* when Unknown IE is received we should break and continue
5878 * to the next IE in the buffer instead we were returning
5879 * so changing this to break */
5880 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07005881 }
5882 genie += eLen;
5883 remLen -= eLen;
5884 }
5885 EXIT();
5886 return 0;
5887}
5888
5889/*
Gopichand Nakkala18f0c262013-05-07 23:25:08 +05305890 * FUNCTION: hdd_isWPAIEPresent
5891 * Parse the received IE to find the WPA IE
5892 *
5893 */
5894static bool hdd_isWPAIEPresent(u8 *ie, u8 ie_len)
5895{
5896 v_U8_t eLen = 0;
5897 v_U16_t remLen = ie_len;
5898 v_U8_t elementId = 0;
5899
5900 while (remLen >= 2)
5901 {
5902 elementId = *ie++;
5903 eLen = *ie++;
5904 remLen -= 2;
5905 if (eLen > remLen)
5906 {
5907 hddLog(VOS_TRACE_LEVEL_ERROR,
5908 "%s: IE length is wrong %d", __func__, eLen);
5909 return FALSE;
5910 }
5911 if ((elementId == DOT11F_EID_WPA) && (remLen > 5))
5912 {
5913 /* OUI - 0x00 0X50 0XF2
5914 WPA Information Element - 0x01
5915 WPA version - 0x01*/
5916 if (0 == memcmp(&ie[0], "\x00\x50\xf2\x01\x01", 5))
5917 return TRUE;
5918 }
5919 ie += eLen;
5920 remLen -= eLen;
5921 }
5922 return FALSE;
5923}
5924
5925/*
Jeff Johnson295189b2012-06-20 16:38:30 -07005926 * FUNCTION: wlan_hdd_cfg80211_set_privacy
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305927 * This function is used to initialize the security
Jeff Johnson295189b2012-06-20 16:38:30 -07005928 * parameters during connect operation.
5929 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305930int wlan_hdd_cfg80211_set_privacy( hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07005931 struct cfg80211_connect_params *req
5932 )
5933{
5934 int status = 0;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305935 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07005936 ENTER();
5937
5938 /*set wpa version*/
5939 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_DISABLED;
5940
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305941 if (req->crypto.wpa_versions)
Jeff Johnson295189b2012-06-20 16:38:30 -07005942 {
Gopichand Nakkala781ded42013-06-28 12:10:45 +05305943 if (NL80211_WPA_VERSION_1 == req->crypto.wpa_versions)
Jeff Johnson295189b2012-06-20 16:38:30 -07005944 {
5945 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA;
5946 }
5947 else if (NL80211_WPA_VERSION_2 == req->crypto.wpa_versions)
5948 {
5949 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA2;
5950 }
5951 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305952
5953 hddLog(VOS_TRACE_LEVEL_INFO, "%s: set wpa version to %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07005954 pWextState->wpaVersion);
5955
5956 /*set authentication type*/
5957 status = wlan_hdd_cfg80211_set_auth_type(pAdapter, req->auth_type);
5958
5959 if (0 > status)
5960 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305961 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005962 "%s: failed to set authentication type ", __func__);
5963 return status;
5964 }
5965
5966 /*set key mgmt type*/
5967 if (req->crypto.n_akm_suites)
5968 {
5969 status = wlan_hdd_set_akm_suite(pAdapter, req->crypto.akm_suites[0]);
5970 if (0 > status)
5971 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305972 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set akm suite",
Jeff Johnson295189b2012-06-20 16:38:30 -07005973 __func__);
5974 return status;
5975 }
5976 }
5977
5978 /*set pairwise cipher type*/
5979 if (req->crypto.n_ciphers_pairwise)
5980 {
5981 status = wlan_hdd_cfg80211_set_cipher(pAdapter,
5982 req->crypto.ciphers_pairwise[0], true);
5983 if (0 > status)
5984 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305985 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005986 "%s: failed to set unicast cipher type", __func__);
5987 return status;
5988 }
5989 }
5990 else
5991 {
5992 /*Reset previous cipher suite to none*/
5993 status = wlan_hdd_cfg80211_set_cipher(pAdapter, 0, true);
5994 if (0 > status)
5995 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305996 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005997 "%s: failed to set unicast cipher type", __func__);
5998 return status;
5999 }
6000 }
6001
6002 /*set group cipher type*/
6003 status = wlan_hdd_cfg80211_set_cipher(pAdapter, req->crypto.cipher_group,
6004 false);
6005
6006 if (0 > status)
6007 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306008 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set mcast cipher type",
Jeff Johnson295189b2012-06-20 16:38:30 -07006009 __func__);
6010 return status;
6011 }
6012
Chet Lanctot186b5732013-03-18 10:26:30 -07006013#ifdef WLAN_FEATURE_11W
6014 pWextState->roamProfile.MFPEnabled = (req->mfp == NL80211_MFP_REQUIRED);
6015#endif
6016
Jeff Johnson295189b2012-06-20 16:38:30 -07006017 /*parse WPA/RSN IE, and set the correspoing fileds in Roam profile*/
6018 if (req->ie_len)
6019 {
6020 status = wlan_hdd_cfg80211_set_ie(pAdapter, req->ie, req->ie_len);
6021 if ( 0 > status)
6022 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306023 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to parse the WPA/RSN IE",
Jeff Johnson295189b2012-06-20 16:38:30 -07006024 __func__);
6025 return status;
6026 }
6027 }
6028
6029 /*incase of WEP set default key information*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306030 if (req->key && req->key_len)
Jeff Johnson295189b2012-06-20 16:38:30 -07006031 {
6032 if ( (WLAN_CIPHER_SUITE_WEP40 == req->crypto.ciphers_pairwise[0])
6033 || (WLAN_CIPHER_SUITE_WEP104 == req->crypto.ciphers_pairwise[0])
6034 )
6035 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306036 if ( IW_AUTH_KEY_MGMT_802_1X
Jeff Johnson295189b2012-06-20 16:38:30 -07006037 == (pWextState->authKeyMgmt & IW_AUTH_KEY_MGMT_802_1X ))
6038 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306039 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Dynamic WEP not supported",
Jeff Johnson295189b2012-06-20 16:38:30 -07006040 __func__);
6041 return -EOPNOTSUPP;
6042 }
6043 else
6044 {
6045 u8 key_len = req->key_len;
6046 u8 key_idx = req->key_idx;
6047
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306048 if ((eCSR_SECURITY_WEP_KEYSIZE_MAX_BYTES >= key_len)
Jeff Johnson295189b2012-06-20 16:38:30 -07006049 && (CSR_MAX_NUM_KEY > key_idx)
6050 )
6051 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306052 hddLog(VOS_TRACE_LEVEL_INFO,
6053 "%s: setting default wep key, key_idx = %hu key_len %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006054 __func__, key_idx, key_len);
6055 vos_mem_copy(
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306056 &pWextState->roamProfile.Keys.KeyMaterial[key_idx][0],
Jeff Johnson295189b2012-06-20 16:38:30 -07006057 req->key, key_len);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306058 pWextState->roamProfile.Keys.KeyLength[key_idx] =
Jeff Johnson295189b2012-06-20 16:38:30 -07006059 (u8)key_len;
6060 pWextState->roamProfile.Keys.defaultIndex = (u8)key_idx;
6061 }
6062 }
6063 }
6064 }
6065
6066 return status;
6067}
6068
6069/*
6070 * FUNCTION: wlan_hdd_cfg80211_set_privacy
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306071 * This function is used to initialize the security
Jeff Johnson295189b2012-06-20 16:38:30 -07006072 * parameters during connect operation.
6073 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306074static int wlan_hdd_cfg80211_connect( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07006075 struct net_device *ndev,
6076 struct cfg80211_connect_params *req
6077 )
6078{
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306079 int status;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306080 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Jeff Johnson295189b2012-06-20 16:38:30 -07006081 VOS_STATUS exitbmpsStatus = VOS_STATUS_E_INVAL;
6082 hdd_context_t *pHddCtx = NULL;
6083
6084 ENTER();
6085
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306086 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07006087 "%s: device_mode = %d\n",__func__,pAdapter->device_mode);
6088
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306089 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
6090 status = wlan_hdd_validate_context(pHddCtx);
6091
6092 if (0 != status)
Jeff Johnson295189b2012-06-20 16:38:30 -07006093 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306094 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6095 "%s: HDD context is not valid", __func__);
6096 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006097 }
6098
6099#ifdef WLAN_BTAMP_FEATURE
6100 //Infra connect not supported when AMP traffic is on.
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306101 if( VOS_TRUE == WLANBAP_AmpSessionOn() )
Jeff Johnson295189b2012-06-20 16:38:30 -07006102 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306103 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07006104 "%s: No connection when AMP is on", __func__);
Madan Mohan Koyyalamudicae253a2012-11-06 19:10:35 -08006105 return -ECONNREFUSED;
Jeff Johnson295189b2012-06-20 16:38:30 -07006106 }
6107#endif
6108 /*initialise security parameters*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306109 status = wlan_hdd_cfg80211_set_privacy(pAdapter, req);
Jeff Johnson295189b2012-06-20 16:38:30 -07006110
6111 if ( 0 > status)
6112 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306113 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set security params",
Jeff Johnson295189b2012-06-20 16:38:30 -07006114 __func__);
6115 return status;
6116 }
6117
6118 //If Device Mode is Station Concurrent Sessions Exit BMps
Jeff Johnsona8a1a482012-12-12 16:49:33 -08006119 //P2P Mode will be taken care in Open/close adapter
Jeff Johnson295189b2012-06-20 16:38:30 -07006120 if((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) &&
6121 (vos_concurrent_sessions_running()))
6122 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306123 exitbmpsStatus = hdd_disable_bmps_imps(pHddCtx, WLAN_HDD_INFRA_STATION);
Jeff Johnson295189b2012-06-20 16:38:30 -07006124 }
6125
Mohit Khanna765234a2012-09-11 15:08:35 -07006126 if ( req->channel )
6127 {
6128 status = wlan_hdd_cfg80211_connect_start(pAdapter, req->ssid,
6129 req->ssid_len, req->bssid,
6130 req->channel->hw_value);
6131 }
6132 else
6133 {
6134 status = wlan_hdd_cfg80211_connect_start(pAdapter, req->ssid,
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306135 req->ssid_len, req->bssid, 0);
Mohit Khanna765234a2012-09-11 15:08:35 -07006136 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006137
6138 if (0 > status)
6139 {
6140 //ReEnable BMPS if disabled
6141 if((VOS_STATUS_SUCCESS == exitbmpsStatus) &&
6142 (NULL != pHddCtx))
6143 {
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05306144 if (pHddCtx->hdd_wlan_suspended)
6145 {
6146 hdd_set_pwrparams(pHddCtx);
6147 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006148 //ReEnable Bmps and Imps back
6149 hdd_enable_bmps_imps(pHddCtx);
6150 }
6151
6152 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: connect failed", __func__);
6153 return status;
6154 }
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306155 pHddCtx->isAmpAllowed = VOS_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006156 EXIT();
6157 return status;
6158}
6159
6160
6161/*
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306162 * FUNCTION: wlan_hdd_disconnect
6163 * This function is used to issue a disconnect request to SME
6164 */
6165int wlan_hdd_disconnect( hdd_adapter_t *pAdapter, u16 reason )
6166{
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306167 int status;
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306168 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306169 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
6170
6171 status = wlan_hdd_validate_context(pHddCtx);
6172
6173 if (0 != status)
6174 {
6175 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6176 "%s: HDD context is not valid", __func__);
6177 return status;
6178 }
6179
6180 pHddCtx->isAmpAllowed = VOS_TRUE;
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306181 pHddStaCtx->conn_info.connState = eConnectionState_NotConnected;
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306182 INIT_COMPLETION(pAdapter->disconnect_comp_var);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306183
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306184 /*issue disconnect*/
6185 status = sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
6186 pAdapter->sessionId, reason);
6187
6188 if ( 0 != status )
6189 {
6190 hddLog(VOS_TRACE_LEVEL_ERROR,
6191 "%s csrRoamDisconnect failure, returned %d \n",
6192 __func__, (int)status );
6193 return -EINVAL;
6194 }
6195 wait_for_completion_interruptible_timeout(
6196 &pAdapter->disconnect_comp_var,
6197 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
6198 /*stop tx queues*/
6199 netif_tx_disable(pAdapter->dev);
6200 netif_carrier_off(pAdapter->dev);
6201 return status;
6202}
6203
6204
6205/*
Jeff Johnson295189b2012-06-20 16:38:30 -07006206 * FUNCTION: wlan_hdd_cfg80211_disconnect
6207 * This function is used to issue a disconnect request to SME
6208 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306209static int wlan_hdd_cfg80211_disconnect( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07006210 struct net_device *dev,
6211 u16 reason
6212 )
6213{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306214 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
6215 tCsrRoamProfile *pRoamProfile =
Jeff Johnson295189b2012-06-20 16:38:30 -07006216 &(WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter))->roamProfile;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306217 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006218 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006219 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05306220#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006221 tANI_U8 staIdx;
6222#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306223
Jeff Johnson295189b2012-06-20 16:38:30 -07006224 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306225
6226 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
Jeff Johnson295189b2012-06-20 16:38:30 -07006227 __func__,pAdapter->device_mode);
6228
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306229 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Disconnect called with reason code %d",
6230 __func__, reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07006231
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306232 status = wlan_hdd_validate_context(pHddCtx);
6233
6234 if (0 != status)
Jeff Johnson295189b2012-06-20 16:38:30 -07006235 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306236 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6237 "%s: HDD context is not valid", __func__);
6238 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006239 }
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306240
Jeff Johnson295189b2012-06-20 16:38:30 -07006241 if (NULL != pRoamProfile)
6242 {
6243 /*issue disconnect request to SME, if station is in connected state*/
6244 if (pHddStaCtx->conn_info.connState == eConnectionState_Associated)
6245 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306246 eCsrRoamDisconnectReason reasonCode =
Jeff Johnson295189b2012-06-20 16:38:30 -07006247 eCSR_DISCONNECT_REASON_UNSPECIFIED;
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05306248 hdd_scaninfo_t *pScanInfo;
Jeff Johnson295189b2012-06-20 16:38:30 -07006249 switch(reason)
6250 {
6251 case WLAN_REASON_MIC_FAILURE:
6252 reasonCode = eCSR_DISCONNECT_REASON_MIC_ERROR;
6253 break;
6254
6255 case WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY:
6256 case WLAN_REASON_DISASSOC_AP_BUSY:
6257 case WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA:
6258 reasonCode = eCSR_DISCONNECT_REASON_DISASSOC;
6259 break;
6260
6261 case WLAN_REASON_PREV_AUTH_NOT_VALID:
6262 case WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA:
6263 reasonCode = eCSR_DISCONNECT_REASON_DEAUTH;
6264 break;
6265
6266 case WLAN_REASON_DEAUTH_LEAVING:
6267 default:
6268 reasonCode = eCSR_DISCONNECT_REASON_UNSPECIFIED;
6269 break;
6270 }
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05306271 pHddStaCtx->conn_info.connState = eConnectionState_NotConnected;
6272 pScanInfo = &pHddCtx->scan_info;
6273 if (pScanInfo->mScanPending)
6274 {
6275 hddLog(VOS_TRACE_LEVEL_INFO, "Disconnect is in progress, "
6276 "Aborting Scan");
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05306277 hdd_abort_mac_scan(pHddCtx, pAdapter->sessionId);
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05306278 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006279
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006280#ifdef FEATURE_WLAN_TDLS
6281 /* First clean up the tdls peers if any */
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006282 for (staIdx = 0 ; staIdx < HDD_MAX_NUM_TDLS_STA; staIdx++)
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006283 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006284 if ((pHddCtx->tdlsConnInfo[staIdx].sessionId == pAdapter->sessionId) &&
6285 (pHddCtx->tdlsConnInfo[staIdx].staId))
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006286 {
Hoonki Lee11f7dda2013-02-14 16:55:44 -08006287 uint8 *mac;
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006288 mac = pHddCtx->tdlsConnInfo[staIdx].peerMac.bytes;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08006289 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07006290 "%s: call sme_DeleteTdlsPeerSta staId %d sessionId %d " MAC_ADDRESS_STR,
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006291 __func__, pHddCtx->tdlsConnInfo[staIdx].staId, pAdapter->sessionId,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07006292 MAC_ADDR_ARRAY(mac));
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006293 sme_DeleteTdlsPeerSta(WLAN_HDD_GET_HAL_CTX(pAdapter),
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006294 pAdapter->sessionId,
6295 mac);
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006296 }
6297 }
6298#endif
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306299 status = wlan_hdd_disconnect(pAdapter, reasonCode);
6300 if ( 0 != status )
Jeff Johnson295189b2012-06-20 16:38:30 -07006301 {
6302 hddLog(VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306303 "%s wlan_hdd_disconnect failure, returned %d \n",
Jeff Johnson295189b2012-06-20 16:38:30 -07006304 __func__, (int)status );
6305 return -EINVAL;
6306 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006307 }
6308 }
6309 else
6310 {
6311 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: No valid roam profile", __func__);
6312 }
6313
6314 return status;
6315}
6316
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306317
Jeff Johnson295189b2012-06-20 16:38:30 -07006318/*
6319 * FUNCTION: wlan_hdd_cfg80211_set_privacy_ibss
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306320 * This function is used to initialize the security
Jeff Johnson295189b2012-06-20 16:38:30 -07006321 * settings in IBSS mode.
6322 */
6323static int wlan_hdd_cfg80211_set_privacy_ibss(
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306324 hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07006325 struct cfg80211_ibss_params *params
6326 )
6327{
6328 int status = 0;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306329 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07006330 eCsrEncryptionType encryptionType = eCSR_ENCRYPT_TYPE_NONE;
6331 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306332
Jeff Johnson295189b2012-06-20 16:38:30 -07006333 ENTER();
6334
6335 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_DISABLED;
6336
6337 if (params->ie_len && ( NULL != params->ie) )
6338 {
Shailender Karmuchi67edd312013-06-18 16:30:48 -07006339 if (wlan_hdd_cfg80211_get_ie_ptr (params->ie,
6340 params->ie_len, WLAN_EID_RSN ))
Jeff Johnson295189b2012-06-20 16:38:30 -07006341 {
6342 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA2;
6343 encryptionType = eCSR_ENCRYPT_TYPE_AES;
6344 }
Shailender Karmuchi67edd312013-06-18 16:30:48 -07006345 else if ( hdd_isWPAIEPresent (params->ie, params->ie_len ))
Jeff Johnson295189b2012-06-20 16:38:30 -07006346 {
Shailender Karmuchi642e9812013-05-30 14:34:49 -07006347 tDot11fIEWPA dot11WPAIE;
6348 tHalHandle halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
Shailender Karmuchi67edd312013-06-18 16:30:48 -07006349 u8 *ie;
Shailender Karmuchi642e9812013-05-30 14:34:49 -07006350
Wilson Yang00256342013-10-10 23:13:38 -07006351 memset(&dot11WPAIE, 0, sizeof(dot11WPAIE));
Shailender Karmuchi67edd312013-06-18 16:30:48 -07006352 ie = wlan_hdd_cfg80211_get_ie_ptr (params->ie,
6353 params->ie_len, DOT11F_EID_WPA);
6354 if ( NULL != ie )
6355 {
6356 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA;
6357 // Unpack the WPA IE
6358 //Skip past the EID byte and length byte - and four byte WiFi OUI
6359 dot11fUnpackIeWPA((tpAniSirGlobal) halHandle,
6360 &ie[2+4],
6361 ie[1] - 4,
6362 &dot11WPAIE);
6363 /*Extract the multicast cipher, the encType for unicast
6364 cipher for wpa-none is none*/
6365 encryptionType =
6366 hdd_TranslateWPAToCsrEncryptionType(dot11WPAIE.multicast_cipher);
6367 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006368 }
Shailender Karmuchi67edd312013-06-18 16:30:48 -07006369
Jeff Johnson295189b2012-06-20 16:38:30 -07006370 status = wlan_hdd_cfg80211_set_ie(pAdapter, params->ie, params->ie_len);
6371
6372 if (0 > status)
6373 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306374 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to parse WPA/RSN IE",
Jeff Johnson295189b2012-06-20 16:38:30 -07006375 __func__);
6376 return status;
6377 }
6378 }
6379
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306380 pWextState->roamProfile.AuthType.authType[0] =
6381 pHddStaCtx->conn_info.authType =
Jeff Johnson295189b2012-06-20 16:38:30 -07006382 eCSR_AUTH_TYPE_OPEN_SYSTEM;
6383
6384 if (params->privacy)
6385 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306386 /* Security enabled IBSS, At this time there is no information available
6387 * about the security paramters, so initialise the encryption type to
Jeff Johnson295189b2012-06-20 16:38:30 -07006388 * eCSR_ENCRYPT_TYPE_WEP40_STATICKEY.
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306389 * The correct security parameters will be updated later in
Jeff Johnson295189b2012-06-20 16:38:30 -07006390 * wlan_hdd_cfg80211_add_key */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306391 /* Hal expects encryption type to be set inorder
Jeff Johnson295189b2012-06-20 16:38:30 -07006392 *enable privacy bit in beacons */
6393
6394 encryptionType = eCSR_ENCRYPT_TYPE_WEP40_STATICKEY;
6395 }
Shailender Karmuchi642e9812013-05-30 14:34:49 -07006396 VOS_TRACE (VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
6397 "encryptionType=%d", encryptionType);
Jeff Johnson295189b2012-06-20 16:38:30 -07006398 pHddStaCtx->conn_info.ucEncryptionType = encryptionType;
6399 pWextState->roamProfile.EncryptionType.numEntries = 1;
6400 pWextState->roamProfile.EncryptionType.encryptionType[0] = encryptionType;
Jeff Johnson295189b2012-06-20 16:38:30 -07006401 return status;
6402}
6403
6404/*
6405 * FUNCTION: wlan_hdd_cfg80211_join_ibss
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306406 * This function is used to create/join an IBSS
Jeff Johnson295189b2012-06-20 16:38:30 -07006407 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306408static int wlan_hdd_cfg80211_join_ibss( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07006409 struct net_device *dev,
6410 struct cfg80211_ibss_params *params
6411 )
6412{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306413 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Jeff Johnson295189b2012-06-20 16:38:30 -07006414 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
6415 tCsrRoamProfile *pRoamProfile;
6416 int status;
6417 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306418 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07006419
6420 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306421
6422 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07006423 "%s: device_mode = %d\n",__func__,pAdapter->device_mode);
6424
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306425 status = wlan_hdd_validate_context(pHddCtx);
6426
6427 if (0 != status)
Jeff Johnson295189b2012-06-20 16:38:30 -07006428 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306429 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6430 "%s: HDD context is not valid", __func__);
6431 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006432 }
6433
6434 if (NULL == pWextState)
6435 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306436 hddLog (VOS_TRACE_LEVEL_ERROR, "%s ERROR: Data Storage Corruption\n",
Jeff Johnson295189b2012-06-20 16:38:30 -07006437 __func__);
6438 return -EIO;
6439 }
6440
6441 pRoamProfile = &pWextState->roamProfile;
6442
6443 if ( eCSR_BSS_TYPE_START_IBSS != pRoamProfile->BSSType )
6444 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306445 hddLog (VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07006446 "%s Interface type is not set to IBSS \n", __func__);
6447 return -EINVAL;
6448 }
6449
6450 /* Set Channel */
Yue Maf49ba872013-08-19 12:04:25 -07006451 if (NULL !=
6452#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0))
6453 params->chandef.chan)
6454#else
6455 params->channel)
6456#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006457 {
6458 u8 channelNum;
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006459 v_U32_t numChans = WNI_CFG_VALID_CHANNEL_LIST_LEN;
6460 v_U8_t validChan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
6461 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
6462 int indx;
Jeff Johnson295189b2012-06-20 16:38:30 -07006463
6464 /* Get channel number */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306465 channelNum =
Yue Maf49ba872013-08-19 12:04:25 -07006466 ieee80211_frequency_to_channel(
6467#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0))
6468 params->chandef.chan->center_freq);
6469#else
6470 params->channel->center_freq);
6471#endif
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006472
6473 if (0 != ccmCfgGetStr(hHal, WNI_CFG_VALID_CHANNEL_LIST,
6474 validChan, &numChans))
Jeff Johnson295189b2012-06-20 16:38:30 -07006475 {
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006476 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: No valid channel list",
6477 __func__);
6478 return -EOPNOTSUPP;
Jeff Johnson295189b2012-06-20 16:38:30 -07006479 }
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006480
6481 for (indx = 0; indx < numChans; indx++)
Jeff Johnson295189b2012-06-20 16:38:30 -07006482 {
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006483 if (channelNum == validChan[indx])
6484 {
6485 break;
6486 }
6487 }
6488 if (indx >= numChans)
6489 {
6490 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Not valid Channel %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07006491 __func__, channelNum);
6492 return -EINVAL;
6493 }
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006494 /* Set the Operational Channel */
6495 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: set channel %d", __func__,
6496 channelNum);
6497 pRoamProfile->ChannelInfo.numOfChannels = 1;
6498 pHddStaCtx->conn_info.operationChannel = channelNum;
6499 pRoamProfile->ChannelInfo.ChannelList =
6500 &pHddStaCtx->conn_info.operationChannel;
Jeff Johnson295189b2012-06-20 16:38:30 -07006501 }
6502
6503 /* Initialize security parameters */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306504 status = wlan_hdd_cfg80211_set_privacy_ibss(pAdapter, params);
Jeff Johnson295189b2012-06-20 16:38:30 -07006505 if (status < 0)
6506 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306507 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set security parameters",
Jeff Johnson295189b2012-06-20 16:38:30 -07006508 __func__);
6509 return status;
6510 }
6511
6512 /* Issue connect start */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306513 status = wlan_hdd_cfg80211_connect_start(pAdapter, params->ssid,
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006514 params->ssid_len, params->bssid,
6515 pHddStaCtx->conn_info.operationChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07006516
6517 if (0 > status)
6518 {
6519 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: connect failed", __func__);
6520 return status;
6521 }
6522
6523 return 0;
6524}
6525
6526/*
6527 * FUNCTION: wlan_hdd_cfg80211_leave_ibss
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306528 * This function is used to leave an IBSS
Jeff Johnson295189b2012-06-20 16:38:30 -07006529 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306530static int wlan_hdd_cfg80211_leave_ibss( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07006531 struct net_device *dev
6532 )
6533{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306534 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Jeff Johnson295189b2012-06-20 16:38:30 -07006535 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
6536 tCsrRoamProfile *pRoamProfile;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306537 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
6538 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006539
6540 ENTER();
6541
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306542 status = wlan_hdd_validate_context(pHddCtx);
6543
6544 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006545 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306546 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6547 "%s: HDD context is not valid", __func__);
6548 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006549 }
6550
Jeff Johnson295189b2012-06-20 16:38:30 -07006551 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",__func__,pAdapter->device_mode);
6552 if (NULL == pWextState)
6553 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306554 hddLog (VOS_TRACE_LEVEL_ERROR, "%s ERROR: Data Storage Corruption\n",
Jeff Johnson295189b2012-06-20 16:38:30 -07006555 __func__);
6556 return -EIO;
6557 }
6558
6559 pRoamProfile = &pWextState->roamProfile;
6560
6561 /* Issue disconnect only if interface type is set to IBSS */
6562 if (eCSR_BSS_TYPE_START_IBSS != pRoamProfile->BSSType)
6563 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306564 hddLog (VOS_TRACE_LEVEL_ERROR, "%s: BSS Type is not set to IBSS",
Jeff Johnson295189b2012-06-20 16:38:30 -07006565 __func__);
6566 return -EINVAL;
6567 }
6568
6569 /* Issue Disconnect request */
6570 INIT_COMPLETION(pAdapter->disconnect_comp_var);
6571 sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter), pAdapter->sessionId,
6572 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
6573
6574 return 0;
6575}
6576
6577/*
6578 * FUNCTION: wlan_hdd_cfg80211_set_wiphy_params
6579 * This function is used to set the phy parameters
6580 * (RTS Threshold/FRAG Threshold/Retry Count etc ...)
6581 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306582static int wlan_hdd_cfg80211_set_wiphy_params(struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07006583 u32 changed)
6584{
6585 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
6586 tHalHandle hHal = pHddCtx->hHal;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306587 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006588
6589 ENTER();
6590
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306591 status = wlan_hdd_validate_context(pHddCtx);
6592
6593 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006594 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306595 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6596 "%s: HDD context is not valid", __func__);
6597 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006598 }
6599
Jeff Johnson295189b2012-06-20 16:38:30 -07006600 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
6601 {
6602 u16 rts_threshold = (wiphy->rts_threshold == -1) ?
6603 WNI_CFG_RTS_THRESHOLD_STAMAX :
6604 wiphy->rts_threshold;
6605
6606 if ((WNI_CFG_RTS_THRESHOLD_STAMIN > rts_threshold) ||
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306607 (WNI_CFG_RTS_THRESHOLD_STAMAX < rts_threshold))
Jeff Johnson295189b2012-06-20 16:38:30 -07006608 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306609 hddLog(VOS_TRACE_LEVEL_ERROR,
6610 "%s: Invalid RTS Threshold value %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006611 __func__, rts_threshold);
6612 return -EINVAL;
6613 }
6614
6615 if (0 != ccmCfgSetInt(hHal, WNI_CFG_RTS_THRESHOLD,
6616 rts_threshold, ccmCfgSetCallback,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306617 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07006618 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306619 hddLog(VOS_TRACE_LEVEL_ERROR,
6620 "%s: ccmCfgSetInt failed for rts_threshold value %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006621 __func__, rts_threshold);
6622 return -EIO;
6623 }
6624
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306625 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set rts threshold %hu", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07006626 rts_threshold);
6627 }
6628
6629 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
6630 {
6631 u16 frag_threshold = (wiphy->frag_threshold == -1) ?
6632 WNI_CFG_FRAGMENTATION_THRESHOLD_STAMAX :
6633 wiphy->frag_threshold;
6634
6635 if ((WNI_CFG_FRAGMENTATION_THRESHOLD_STAMIN > frag_threshold)||
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306636 (WNI_CFG_FRAGMENTATION_THRESHOLD_STAMAX < frag_threshold) )
Jeff Johnson295189b2012-06-20 16:38:30 -07006637 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306638 hddLog(VOS_TRACE_LEVEL_ERROR,
6639 "%s: Invalid frag_threshold value %hu", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07006640 frag_threshold);
6641 return -EINVAL;
6642 }
6643
6644 if (0 != ccmCfgSetInt(hHal, WNI_CFG_FRAGMENTATION_THRESHOLD,
6645 frag_threshold, ccmCfgSetCallback,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306646 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07006647 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306648 hddLog(VOS_TRACE_LEVEL_ERROR,
6649 "%s: ccmCfgSetInt failed for frag_threshold value %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006650 __func__, frag_threshold);
6651 return -EIO;
6652 }
6653
6654 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set frag threshold %hu", __func__,
6655 frag_threshold);
6656 }
6657
6658 if ((changed & WIPHY_PARAM_RETRY_SHORT)
6659 || (changed & WIPHY_PARAM_RETRY_LONG))
6660 {
6661 u8 retry_value = (changed & WIPHY_PARAM_RETRY_SHORT) ?
6662 wiphy->retry_short :
6663 wiphy->retry_long;
6664
6665 if ((WNI_CFG_LONG_RETRY_LIMIT_STAMIN > retry_value) ||
6666 (WNI_CFG_LONG_RETRY_LIMIT_STAMAX < retry_value))
6667 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306668 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006669 __func__, retry_value);
6670 return -EINVAL;
6671 }
6672
6673 if (changed & WIPHY_PARAM_RETRY_SHORT)
6674 {
6675 if (0 != ccmCfgSetInt(hHal, WNI_CFG_LONG_RETRY_LIMIT,
6676 retry_value, ccmCfgSetCallback,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306677 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07006678 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306679 hddLog(VOS_TRACE_LEVEL_ERROR,
6680 "%s: ccmCfgSetInt failed for long retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006681 __func__, retry_value);
6682 return -EIO;
6683 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306684 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set long retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006685 __func__, retry_value);
6686 }
6687 else if (changed & WIPHY_PARAM_RETRY_SHORT)
6688 {
6689 if (0 != ccmCfgSetInt(hHal, WNI_CFG_SHORT_RETRY_LIMIT,
6690 retry_value, ccmCfgSetCallback,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306691 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07006692 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306693 hddLog(VOS_TRACE_LEVEL_ERROR,
6694 "%s: ccmCfgSetInt failed for short retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006695 __func__, retry_value);
6696 return -EIO;
6697 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306698 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set short retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006699 __func__, retry_value);
6700 }
6701 }
6702
6703 return 0;
6704}
6705
6706/*
6707 * FUNCTION: wlan_hdd_cfg80211_set_txpower
6708 * This function is used to set the txpower
6709 */
6710static int wlan_hdd_cfg80211_set_txpower(struct wiphy *wiphy,
Yue Maf49ba872013-08-19 12:04:25 -07006711#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0)
6712 struct wireless_dev *wdev,
6713#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006714#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,35)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306715 enum tx_power_setting type,
Jeff Johnson295189b2012-06-20 16:38:30 -07006716#else
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306717 enum nl80211_tx_power_setting type,
Jeff Johnson295189b2012-06-20 16:38:30 -07006718#endif
6719 int dbm)
6720{
6721 hdd_context_t *pHddCtx = (hdd_context_t*) wiphy_priv(wiphy);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306722 tHalHandle hHal = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07006723 tSirMacAddr bssid = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
6724 tSirMacAddr selfMac = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306725 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006726
6727 ENTER();
6728
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306729 status = wlan_hdd_validate_context(pHddCtx);
6730
6731 if (0 != status)
6732 {
6733 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6734 "%s: HDD context is not valid", __func__);
6735 return status;
6736 }
6737
6738 hHal = pHddCtx->hHal;
6739
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306740 if (0 != ccmCfgSetInt(hHal, WNI_CFG_CURRENT_TX_POWER_LEVEL,
6741 dbm, ccmCfgSetCallback,
6742 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07006743 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306744 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07006745 "%s: ccmCfgSetInt failed for tx power %hu", __func__, dbm);
6746 return -EIO;
6747 }
6748
6749 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set tx power level %d dbm", __func__,
6750 dbm);
6751
6752 switch(type)
6753 {
6754 case NL80211_TX_POWER_AUTOMATIC: /*automatically determine transmit power*/
6755 /* Fall through */
6756 case NL80211_TX_POWER_LIMITED: /*limit TX power by the mBm parameter*/
6757 if( sme_SetMaxTxPower(hHal, bssid, selfMac, dbm) != eHAL_STATUS_SUCCESS )
6758 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306759 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Setting maximum tx power failed",
6760 __func__);
6761 return -EIO;
Jeff Johnson295189b2012-06-20 16:38:30 -07006762 }
6763 break;
6764 case NL80211_TX_POWER_FIXED: /*fix TX power to the mBm parameter*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306765 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: NL80211_TX_POWER_FIXED not supported",
Jeff Johnson295189b2012-06-20 16:38:30 -07006766 __func__);
6767 return -EOPNOTSUPP;
6768 break;
6769 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306770 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid power setting type %d",
6771 __func__, type);
Jeff Johnson295189b2012-06-20 16:38:30 -07006772 return -EIO;
6773 }
6774
6775 return 0;
6776}
6777
6778/*
6779 * FUNCTION: wlan_hdd_cfg80211_get_txpower
6780 * This function is used to read the txpower
6781 */
Yue Maf49ba872013-08-19 12:04:25 -07006782static int wlan_hdd_cfg80211_get_txpower(struct wiphy *wiphy,
6783#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0)
6784 struct wireless_dev *wdev,
6785#endif
6786 int *dbm)
Jeff Johnson295189b2012-06-20 16:38:30 -07006787{
6788
6789 hdd_adapter_t *pAdapter;
6790 hdd_context_t *pHddCtx = (hdd_context_t*) wiphy_priv(wiphy);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306791 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006792
Jeff Johnsone7245742012-09-05 17:12:55 -07006793 ENTER();
6794
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306795 status = wlan_hdd_validate_context(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07006796
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306797 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006798 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306799 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6800 "%s: HDD context is not valid", __func__);
6801 *dbm = 0;
6802 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006803 }
6804
Jeff Johnson295189b2012-06-20 16:38:30 -07006805 pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_INFRA_STATION);
6806 if (NULL == pAdapter)
6807 {
6808 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Not in station context " ,__func__);
6809 return -ENOENT;
6810 }
6811
6812 wlan_hdd_get_classAstats(pAdapter);
6813 *dbm = pAdapter->hdd_stats.ClassA_stat.max_pwr;
6814
Jeff Johnsone7245742012-09-05 17:12:55 -07006815 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07006816 return 0;
6817}
6818
6819static int wlan_hdd_cfg80211_get_station(struct wiphy *wiphy, struct net_device *dev,
6820 u8* mac, struct station_info *sinfo)
6821{
6822 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
6823 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
6824 int ssidlen = pHddStaCtx->conn_info.SSID.SSID.length;
6825 tANI_U8 rate_flags;
6826
6827 hdd_context_t *pHddCtx = (hdd_context_t*) wiphy_priv(wiphy);
6828 hdd_config_t *pCfg = pHddCtx->cfg_ini;
Jeff Johnson295189b2012-06-20 16:38:30 -07006829
6830 tANI_U8 OperationalRates[CSR_DOT11_SUPPORTED_RATES_MAX];
6831 tANI_U32 ORLeng = CSR_DOT11_SUPPORTED_RATES_MAX;
6832 tANI_U8 ExtendedRates[CSR_DOT11_EXTENDED_SUPPORTED_RATES_MAX];
6833 tANI_U32 ERLeng = CSR_DOT11_EXTENDED_SUPPORTED_RATES_MAX;
6834 tANI_U8 MCSRates[SIZE_OF_BASIC_MCS_SET];
6835 tANI_U32 MCSLeng = SIZE_OF_BASIC_MCS_SET;
6836 tANI_U16 maxRate = 0;
6837 tANI_U16 myRate;
6838 tANI_U16 currentRate = 0;
6839 tANI_U8 maxSpeedMCS = 0;
6840 tANI_U8 maxMCSIdx = 0;
6841 tANI_U8 rateFlag = 1;
6842 tANI_U8 i, j, rssidx;
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07006843 tANI_U16 temp;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306844 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006845
Leo Chang6f8870f2013-03-26 18:11:36 -07006846#ifdef WLAN_FEATURE_11AC
6847 tANI_U32 vht_mcs_map;
6848 eDataRate11ACMaxMcs vhtMaxMcs;
6849#endif /* WLAN_FEATURE_11AC */
6850
Jeff Johnsone7245742012-09-05 17:12:55 -07006851 ENTER();
6852
Jeff Johnson295189b2012-06-20 16:38:30 -07006853 if ((eConnectionState_Associated != pHddStaCtx->conn_info.connState) ||
6854 (0 == ssidlen))
6855 {
6856 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Not associated or"
6857 " Invalid ssidlen, %d", __func__, ssidlen);
6858 /*To keep GUI happy*/
6859 return 0;
6860 }
6861
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306862 status = wlan_hdd_validate_context(pHddCtx);
6863
6864 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006865 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306866 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6867 "%s: HDD context is not valid", __func__);
6868 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006869 }
6870
Madan Mohan Koyyalamudi4d4d2812012-09-24 14:08:29 -07006871 wlan_hdd_get_station_stats(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07006872 rate_flags = pAdapter->hdd_stats.ClassA_stat.tx_rate_flags;
6873
Kiet Lam3b17fc82013-09-27 05:24:08 +05306874 wlan_hdd_get_rssi(pAdapter, &sinfo->signal);
6875 sinfo->filled |= STATION_INFO_SIGNAL;
6876
Jeff Johnson295189b2012-06-20 16:38:30 -07006877 //convert to the UI units of 100kbps
6878 myRate = pAdapter->hdd_stats.ClassA_stat.tx_rate * 5;
6879
6880#ifdef LINKSPEED_DEBUG_ENABLED
Leo Chang6f8870f2013-03-26 18:11:36 -07006881 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 -07006882 sinfo->signal,
6883 pCfg->reportMaxLinkSpeed,
6884 myRate,
6885 (int) pCfg->linkSpeedRssiHigh,
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07006886 (int) pCfg->linkSpeedRssiMid,
6887 (int) pCfg->linkSpeedRssiLow,
Leo Chang6f8870f2013-03-26 18:11:36 -07006888 (int) rate_flags,
6889 (int) pAdapter->hdd_stats.ClassA_stat.mcs_index);
Jeff Johnson295189b2012-06-20 16:38:30 -07006890#endif //LINKSPEED_DEBUG_ENABLED
6891
6892 if (eHDD_LINK_SPEED_REPORT_ACTUAL != pCfg->reportMaxLinkSpeed)
6893 {
6894 // we do not want to necessarily report the current speed
6895 if (eHDD_LINK_SPEED_REPORT_MAX == pCfg->reportMaxLinkSpeed)
6896 {
6897 // report the max possible speed
6898 rssidx = 0;
6899 }
6900 else if (eHDD_LINK_SPEED_REPORT_MAX_SCALED == pCfg->reportMaxLinkSpeed)
6901 {
6902 // report the max possible speed with RSSI scaling
6903 if (sinfo->signal >= pCfg->linkSpeedRssiHigh)
6904 {
6905 // report the max possible speed
6906 rssidx = 0;
6907 }
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07006908 else if (sinfo->signal >= pCfg->linkSpeedRssiMid)
Jeff Johnson295189b2012-06-20 16:38:30 -07006909 {
6910 // report middle speed
6911 rssidx = 1;
6912 }
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07006913 else if (sinfo->signal >= pCfg->linkSpeedRssiLow)
6914 {
6915 // report middle speed
6916 rssidx = 2;
6917 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006918 else
6919 {
6920 // report actual speed
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07006921 rssidx = 3;
Jeff Johnson295189b2012-06-20 16:38:30 -07006922 }
6923 }
6924 else
6925 {
6926 // unknown, treat as eHDD_LINK_SPEED_REPORT_MAX
6927 hddLog(VOS_TRACE_LEVEL_ERROR,
6928 "%s: Invalid value for reportMaxLinkSpeed: %u",
6929 __func__, pCfg->reportMaxLinkSpeed);
6930 rssidx = 0;
6931 }
6932
6933 maxRate = 0;
6934
6935 /* Get Basic Rate Set */
Gopichand Nakkala05ab1322013-02-15 11:28:38 +05306936 if (0 != ccmCfgGetStr(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_OPERATIONAL_RATE_SET,
6937 OperationalRates, &ORLeng))
6938 {
6939 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: ccm api returned failure", __func__);
6940 /*To keep GUI happy*/
6941 return 0;
6942 }
6943
Jeff Johnson295189b2012-06-20 16:38:30 -07006944 for (i = 0; i < ORLeng; i++)
6945 {
Jeff Johnsone7245742012-09-05 17:12:55 -07006946 for (j = 0; j < (sizeof(supported_data_rate) / sizeof(supported_data_rate[0])); j ++)
Jeff Johnson295189b2012-06-20 16:38:30 -07006947 {
6948 /* Validate Rate Set */
6949 if (supported_data_rate[j].beacon_rate_index == (OperationalRates[i] & 0x7F))
6950 {
6951 currentRate = supported_data_rate[j].supported_rate[rssidx];
6952 break;
6953 }
6954 }
6955 /* Update MAX rate */
6956 maxRate = (currentRate > maxRate)?currentRate:maxRate;
6957 }
6958
6959 /* Get Extended Rate Set */
Gopichand Nakkala05ab1322013-02-15 11:28:38 +05306960 if (0 != ccmCfgGetStr(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_EXTENDED_OPERATIONAL_RATE_SET,
6961 ExtendedRates, &ERLeng))
6962 {
6963 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: ccm api returned failure", __func__);
6964 /*To keep GUI happy*/
6965 return 0;
6966 }
6967
Jeff Johnson295189b2012-06-20 16:38:30 -07006968 for (i = 0; i < ERLeng; i++)
6969 {
Jeff Johnsone7245742012-09-05 17:12:55 -07006970 for (j = 0; j < (sizeof(supported_data_rate) / sizeof(supported_data_rate[0])); j ++)
Jeff Johnson295189b2012-06-20 16:38:30 -07006971 {
6972 if (supported_data_rate[j].beacon_rate_index == (ExtendedRates[i] & 0x7F))
6973 {
6974 currentRate = supported_data_rate[j].supported_rate[rssidx];
6975 break;
6976 }
6977 }
6978 /* Update MAX rate */
6979 maxRate = (currentRate > maxRate)?currentRate:maxRate;
6980 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006981 /* Get MCS Rate Set -- but only if we are connected at MCS
6982 rates or if we are always reporting max speed or if we have
6983 good rssi */
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07006984 if ((0 == rssidx) && !(rate_flags & eHAL_TX_RATE_LEGACY))
Jeff Johnson295189b2012-06-20 16:38:30 -07006985 {
Gopichand Nakkala05ab1322013-02-15 11:28:38 +05306986 if (0 != ccmCfgGetStr(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_CURRENT_MCS_SET,
6987 MCSRates, &MCSLeng))
6988 {
6989 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: ccm api returned failure", __func__);
6990 /*To keep GUI happy*/
6991 return 0;
6992 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006993 rateFlag = 0;
Leo Chang6f8870f2013-03-26 18:11:36 -07006994#ifdef WLAN_FEATURE_11AC
6995 /* VHT80 rate has seperate rate table */
Gopichand Nakkala4c705372013-04-24 13:20:33 +05306996 if (rate_flags & (eHAL_TX_RATE_VHT20|eHAL_TX_RATE_VHT40|eHAL_TX_RATE_VHT80))
Jeff Johnson295189b2012-06-20 16:38:30 -07006997 {
Leo Chang6f8870f2013-03-26 18:11:36 -07006998 ccmCfgGetInt(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_VHT_TX_MCS_MAP, &vht_mcs_map);
Gopichand Nakkala4c705372013-04-24 13:20:33 +05306999 vhtMaxMcs = (eDataRate11ACMaxMcs)(vht_mcs_map & DATA_RATE_11AC_MCS_MASK );
Leo Chang6f8870f2013-03-26 18:11:36 -07007000 if (rate_flags & eHAL_TX_RATE_SGI)
Jeff Johnson295189b2012-06-20 16:38:30 -07007001 {
Leo Chang6f8870f2013-03-26 18:11:36 -07007002 rateFlag |= 1;
Jeff Johnson295189b2012-06-20 16:38:30 -07007003 }
Leo Chang6f8870f2013-03-26 18:11:36 -07007004 if (DATA_RATE_11AC_MAX_MCS_7 == vhtMaxMcs)
Jeff Johnson295189b2012-06-20 16:38:30 -07007005 {
Leo Chang6f8870f2013-03-26 18:11:36 -07007006 maxMCSIdx = 7;
7007 }
7008 else if (DATA_RATE_11AC_MAX_MCS_8 == vhtMaxMcs)
7009 {
7010 maxMCSIdx = 8;
7011 }
7012 else if (DATA_RATE_11AC_MAX_MCS_9 == vhtMaxMcs)
7013 {
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307014 //VHT20 is supporting 0~8
7015 if (rate_flags & eHAL_TX_RATE_VHT20)
7016 maxMCSIdx = 8;
7017 else
7018 maxMCSIdx = 9;
Leo Chang6f8870f2013-03-26 18:11:36 -07007019 }
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307020
7021 if (rate_flags & eHAL_TX_RATE_VHT80)
7022 {
7023 currentRate = supported_vht_mcs_rate[pAdapter->hdd_stats.ClassA_stat.mcs_index].supported_VHT80_rate[rateFlag];
7024 maxRate = supported_vht_mcs_rate[maxMCSIdx].supported_VHT80_rate[rateFlag];
7025 }
7026 else if (rate_flags & eHAL_TX_RATE_VHT40)
7027 {
7028 currentRate = supported_vht_mcs_rate[pAdapter->hdd_stats.ClassA_stat.mcs_index].supported_VHT40_rate[rateFlag];
7029 maxRate = supported_vht_mcs_rate[maxMCSIdx].supported_VHT40_rate[rateFlag];
7030 }
7031 else if (rate_flags & eHAL_TX_RATE_VHT20)
7032 {
7033 currentRate = supported_vht_mcs_rate[pAdapter->hdd_stats.ClassA_stat.mcs_index].supported_VHT20_rate[rateFlag];
7034 maxRate = supported_vht_mcs_rate[maxMCSIdx].supported_VHT20_rate[rateFlag];
7035 }
7036
Leo Chang6f8870f2013-03-26 18:11:36 -07007037 maxSpeedMCS = 1;
7038 if (currentRate > maxRate)
7039 {
7040 maxRate = currentRate;
7041 }
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307042
Leo Chang6f8870f2013-03-26 18:11:36 -07007043 }
7044 else
7045#endif /* WLAN_FEATURE_11AC */
7046 {
7047 if (rate_flags & eHAL_TX_RATE_HT40)
7048 {
7049 rateFlag |= 1;
7050 }
7051 if (rate_flags & eHAL_TX_RATE_SGI)
7052 {
7053 rateFlag |= 2;
7054 }
7055
7056 for (i = 0; i < MCSLeng; i++)
7057 {
7058 temp = sizeof(supported_mcs_rate) / sizeof(supported_mcs_rate[0]);
7059 for (j = 0; j < temp; j++)
7060 {
7061 if (supported_mcs_rate[j].beacon_rate_index == MCSRates[i])
7062 {
7063 currentRate = supported_mcs_rate[j].supported_rate[rateFlag];
7064 break;
7065 }
7066 }
7067 if ((j < temp) && (currentRate > maxRate))
7068 {
7069 maxRate = currentRate;
7070 maxSpeedMCS = 1;
7071 maxMCSIdx = supported_mcs_rate[j].beacon_rate_index;
7072 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007073 }
7074 }
7075 }
7076
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307077 else if (!(rate_flags & eHAL_TX_RATE_LEGACY))
7078 {
7079 maxRate = myRate;
7080 maxSpeedMCS = 1;
7081 maxMCSIdx = pAdapter->hdd_stats.ClassA_stat.mcs_index;
7082 }
7083
Jeff Johnson295189b2012-06-20 16:38:30 -07007084 // make sure we report a value at least as big as our current rate
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07007085 if (((maxRate < myRate) && (0 == rssidx)) ||
7086 (0 == maxRate))
Jeff Johnson295189b2012-06-20 16:38:30 -07007087 {
7088 maxRate = myRate;
7089 if (rate_flags & eHAL_TX_RATE_LEGACY)
7090 {
7091 maxSpeedMCS = 0;
7092 }
7093 else
7094 {
7095 maxSpeedMCS = 1;
7096 maxMCSIdx = pAdapter->hdd_stats.ClassA_stat.mcs_index;
7097 }
7098 }
7099
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307100 if (rate_flags & eHAL_TX_RATE_LEGACY)
Jeff Johnson295189b2012-06-20 16:38:30 -07007101 {
7102 sinfo->txrate.legacy = maxRate;
7103#ifdef LINKSPEED_DEBUG_ENABLED
7104 pr_info("Reporting legacy rate %d\n", sinfo->txrate.legacy);
7105#endif //LINKSPEED_DEBUG_ENABLED
7106 }
7107 else
7108 {
7109 sinfo->txrate.mcs = maxMCSIdx;
Leo Chang6f8870f2013-03-26 18:11:36 -07007110#ifdef WLAN_FEATURE_11AC
7111 sinfo->txrate.nss = 1;
7112 if (rate_flags & eHAL_TX_RATE_VHT80)
7113 {
7114 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307115 sinfo->txrate.flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
Leo Chang6f8870f2013-03-26 18:11:36 -07007116 }
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307117 else if (rate_flags & eHAL_TX_RATE_VHT40)
Leo Chang6f8870f2013-03-26 18:11:36 -07007118 {
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307119 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
7120 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
7121 }
7122 else if (rate_flags & eHAL_TX_RATE_VHT20)
7123 {
7124 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
7125 }
7126#endif /* WLAN_FEATURE_11AC */
7127 if (rate_flags & (eHAL_TX_RATE_HT20 | eHAL_TX_RATE_HT40))
7128 {
7129 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
7130 if (rate_flags & eHAL_TX_RATE_HT40)
7131 {
7132 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
7133 }
Leo Chang6f8870f2013-03-26 18:11:36 -07007134 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007135 if (rate_flags & eHAL_TX_RATE_SGI)
7136 {
7137 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
7138 }
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307139
Jeff Johnson295189b2012-06-20 16:38:30 -07007140#ifdef LINKSPEED_DEBUG_ENABLED
7141 pr_info("Reporting MCS rate %d flags %x\n",
7142 sinfo->txrate.mcs,
7143 sinfo->txrate.flags );
7144#endif //LINKSPEED_DEBUG_ENABLED
7145 }
7146 }
7147 else
7148 {
7149 // report current rate instead of max rate
7150
7151 if (rate_flags & eHAL_TX_RATE_LEGACY)
7152 {
7153 //provide to the UI in units of 100kbps
7154 sinfo->txrate.legacy = myRate;
7155#ifdef LINKSPEED_DEBUG_ENABLED
7156 pr_info("Reporting actual legacy rate %d\n", sinfo->txrate.legacy);
7157#endif //LINKSPEED_DEBUG_ENABLED
7158 }
7159 else
7160 {
7161 //must be MCS
7162 sinfo->txrate.mcs = pAdapter->hdd_stats.ClassA_stat.mcs_index;
Leo Chang6f8870f2013-03-26 18:11:36 -07007163#ifdef WLAN_FEATURE_11AC
7164 sinfo->txrate.nss = 1;
7165 if (rate_flags & eHAL_TX_RATE_VHT80)
7166 {
7167 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
7168 }
7169 else
7170#endif /* WLAN_FEATURE_11AC */
7171 {
7172 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
7173 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007174 if (rate_flags & eHAL_TX_RATE_SGI)
7175 {
7176 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
7177 }
7178 if (rate_flags & eHAL_TX_RATE_HT40)
7179 {
7180 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
7181 }
Leo Chang6f8870f2013-03-26 18:11:36 -07007182#ifdef WLAN_FEATURE_11AC
7183 else if (rate_flags & eHAL_TX_RATE_VHT80)
7184 {
7185 sinfo->txrate.flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
7186 }
7187#endif /* WLAN_FEATURE_11AC */
Jeff Johnson295189b2012-06-20 16:38:30 -07007188#ifdef LINKSPEED_DEBUG_ENABLED
7189 pr_info("Reporting actual MCS rate %d flags %x\n",
7190 sinfo->txrate.mcs,
7191 sinfo->txrate.flags );
7192#endif //LINKSPEED_DEBUG_ENABLED
7193 }
7194 }
7195 sinfo->filled |= STATION_INFO_TX_BITRATE;
7196
Madan Mohan Koyyalamudi4d4d2812012-09-24 14:08:29 -07007197 sinfo->tx_packets =
7198 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[0] +
7199 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[1] +
7200 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[2] +
7201 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[3];
7202
7203 sinfo->tx_retries =
7204 pAdapter->hdd_stats.summary_stat.retry_cnt[0] +
7205 pAdapter->hdd_stats.summary_stat.retry_cnt[1] +
7206 pAdapter->hdd_stats.summary_stat.retry_cnt[2] +
7207 pAdapter->hdd_stats.summary_stat.retry_cnt[3];
7208
7209 sinfo->tx_failed =
7210 pAdapter->hdd_stats.summary_stat.fail_cnt[0] +
7211 pAdapter->hdd_stats.summary_stat.fail_cnt[1] +
7212 pAdapter->hdd_stats.summary_stat.fail_cnt[2] +
7213 pAdapter->hdd_stats.summary_stat.fail_cnt[3];
7214
7215 sinfo->filled |=
7216 STATION_INFO_TX_PACKETS |
7217 STATION_INFO_TX_RETRIES |
7218 STATION_INFO_TX_FAILED;
7219
7220 EXIT();
7221 return 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07007222}
7223
7224static int wlan_hdd_cfg80211_set_power_mgmt(struct wiphy *wiphy,
Sameer Thalappilc9f26e92013-06-07 10:11:06 -07007225 struct net_device *dev, bool mode, int timeout)
Jeff Johnson295189b2012-06-20 16:38:30 -07007226{
7227 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05307228 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07007229 VOS_STATUS vos_status;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307230 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007231
Jeff Johnsone7245742012-09-05 17:12:55 -07007232 ENTER();
7233
Jeff Johnson295189b2012-06-20 16:38:30 -07007234 if (NULL == pAdapter)
7235 {
7236 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Adapter is NULL\n", __func__);
7237 return -ENODEV;
7238 }
7239
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05307240 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307241 status = wlan_hdd_validate_context(pHddCtx);
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05307242
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307243 if (0 != status)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307244 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307245 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7246 "%s: HDD context is not valid", __func__);
7247 return status;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307248 }
7249
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05307250 if ((DRIVER_POWER_MODE_AUTO == !mode) &&
7251 (TRUE == pHddCtx->hdd_wlan_suspended) &&
7252 (pHddCtx->cfg_ini->fhostArpOffload) &&
7253 (eConnectionState_Associated ==
7254 (WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))->conn_info.connState))
7255 {
Amar Singhald53568e2013-09-26 11:03:45 -07007256
7257 hddLog(VOS_TRACE_LEVEL_INFO,
7258 "offload: in cfg80211_set_power_mgmt, calling arp offload");
Gopichand Nakkalab03e8082013-05-30 18:09:25 +05307259 vos_status = hdd_conf_arp_offload(pAdapter, TRUE);
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05307260 if (!VOS_IS_STATUS_SUCCESS(vos_status))
7261 {
7262 hddLog(VOS_TRACE_LEVEL_INFO,
7263 "%s:Failed to enable ARPOFFLOAD Feature %d\n",
7264 __func__, vos_status);
7265 }
7266 }
7267
Jeff Johnson295189b2012-06-20 16:38:30 -07007268 /**The get power cmd from the supplicant gets updated by the nl only
7269 *on successful execution of the function call
7270 *we are oppositely mapped w.r.t mode in the driver
7271 **/
7272 vos_status = wlan_hdd_enter_bmps(pAdapter, !mode);
7273
Jeff Johnsone7245742012-09-05 17:12:55 -07007274 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07007275 if (VOS_STATUS_E_FAILURE == vos_status)
7276 {
7277 return -EINVAL;
7278 }
7279 return 0;
7280}
7281
7282
7283#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
7284static int wlan_hdd_set_default_mgmt_key(struct wiphy *wiphy,
7285 struct net_device *netdev,
7286 u8 key_index)
7287{
Jeff Johnsone7245742012-09-05 17:12:55 -07007288 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07007289 return 0;
7290}
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307291#endif //LINUX_VERSION_CODE
Jeff Johnson295189b2012-06-20 16:38:30 -07007292
7293#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
7294static int wlan_hdd_set_txq_params(struct wiphy *wiphy,
7295 struct net_device *dev,
7296 struct ieee80211_txq_params *params)
7297{
Jeff Johnsone7245742012-09-05 17:12:55 -07007298 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07007299 return 0;
7300}
7301#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
7302static int wlan_hdd_set_txq_params(struct wiphy *wiphy,
7303 struct ieee80211_txq_params *params)
7304{
Jeff Johnsone7245742012-09-05 17:12:55 -07007305 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07007306 return 0;
7307}
7308#endif //LINUX_VERSION_CODE
7309
7310static int wlan_hdd_cfg80211_del_station(struct wiphy *wiphy,
7311 struct net_device *dev, u8 *mac)
7312{
7313 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307314 hdd_context_t *pHddCtx;
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007315 VOS_STATUS vos_status;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307316 int status;
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007317 v_U8_t staId;
Jeff Johnson295189b2012-06-20 16:38:30 -07007318
Jeff Johnsone7245742012-09-05 17:12:55 -07007319 ENTER();
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307320 if ( NULL == pAdapter )
Jeff Johnson295189b2012-06-20 16:38:30 -07007321 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307322 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Adapter" ,__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07007323 return -EINVAL;
7324 }
7325
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307326 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7327 status = wlan_hdd_validate_context(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07007328
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307329 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007330 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307331 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7332 "%s: HDD context is not valid", __func__);
7333 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007334 }
7335
Jeff Johnson295189b2012-06-20 16:38:30 -07007336 if ( (WLAN_HDD_SOFTAP == pAdapter->device_mode)
Jeff Johnson295189b2012-06-20 16:38:30 -07007337 || (WLAN_HDD_P2P_GO == pAdapter->device_mode)
Jeff Johnson295189b2012-06-20 16:38:30 -07007338 )
7339 {
7340 if( NULL == mac )
7341 {
7342 v_U16_t i;
7343 for(i = 0; i < WLAN_MAX_STA_COUNT; i++)
7344 {
Rajesh Chauhan18488fc2013-08-22 10:15:03 -07007345 if ((pAdapter->aStaInfo[i].isUsed) &&
7346 (!pAdapter->aStaInfo[i].isDeauthInProgress))
Jeff Johnson295189b2012-06-20 16:38:30 -07007347 {
7348 u8 *macAddr = pAdapter->aStaInfo[i].macAddrSTA.bytes;
7349 hddLog(VOS_TRACE_LEVEL_INFO,
7350 "%s: Delete STA with MAC::"
7351 "%02x:%02x:%02x:%02x:%02x:%02x",
7352 __func__,
7353 macAddr[0], macAddr[1], macAddr[2],
7354 macAddr[3], macAddr[4], macAddr[5]);
Rajesh Chauhan18488fc2013-08-22 10:15:03 -07007355 vos_status = hdd_softap_sta_deauth(pAdapter, macAddr);
7356 if (VOS_IS_STATUS_SUCCESS(vos_status))
7357 pAdapter->aStaInfo[i].isDeauthInProgress = TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07007358 }
7359 }
7360 }
7361 else
7362 {
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007363
7364 vos_status = hdd_softap_GetStaId(pAdapter,(v_MACADDR_t *)mac, &staId);
7365 if (!VOS_IS_STATUS_SUCCESS(vos_status))
7366 {
7367 hddLog(VOS_TRACE_LEVEL_INFO,
7368 "%s: Skip this DEL STA as this is not used::"
7369 "%02x:%02x:%02x:%02x:%02x:%02x",
7370 __func__,
7371 mac[0], mac[1], mac[2],
7372 mac[3], mac[4], mac[5]);
7373 return -ENOENT;
7374 }
7375
7376 if( pAdapter->aStaInfo[staId].isDeauthInProgress == TRUE)
7377 {
7378 hddLog(VOS_TRACE_LEVEL_INFO,
7379 "%s: Skip this DEL STA as deauth is in progress::"
7380 "%02x:%02x:%02x:%02x:%02x:%02x",
7381 __func__,
7382 mac[0], mac[1], mac[2],
7383 mac[3], mac[4], mac[5]);
7384 return -ENOENT;
7385 }
7386
7387 pAdapter->aStaInfo[staId].isDeauthInProgress = TRUE;
7388
Jeff Johnson295189b2012-06-20 16:38:30 -07007389 hddLog(VOS_TRACE_LEVEL_INFO,
7390 "%s: Delete STA with MAC::"
7391 "%02x:%02x:%02x:%02x:%02x:%02x",
7392 __func__,
7393 mac[0], mac[1], mac[2],
7394 mac[3], mac[4], mac[5]);
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007395
7396 vos_status = hdd_softap_sta_deauth(pAdapter, mac);
7397 if (!VOS_IS_STATUS_SUCCESS(vos_status))
7398 {
7399 pAdapter->aStaInfo[staId].isDeauthInProgress = FALSE;
7400 hddLog(VOS_TRACE_LEVEL_INFO,
7401 "%s: STA removal failed for ::"
7402 "%02x:%02x:%02x:%02x:%02x:%02x",
7403 __func__,
7404 mac[0], mac[1], mac[2],
7405 mac[3], mac[4], mac[5]);
7406 return -ENOENT;
7407 }
7408
Jeff Johnson295189b2012-06-20 16:38:30 -07007409 }
7410 }
7411
7412 EXIT();
7413
7414 return 0;
7415}
7416
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007417static int wlan_hdd_cfg80211_add_station(struct wiphy *wiphy,
7418 struct net_device *dev, u8 *mac, struct station_parameters *params)
7419{
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007420 int status = -EPERM;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007421#ifdef FEATURE_WLAN_TDLS
7422 u32 mask, set;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007423 ENTER();
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007424 mask = params->sta_flags_mask;
7425
7426 set = params->sta_flags_set;
7427
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007428#ifdef WLAN_FEATURE_TDLS_DEBUG
7429 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7430 "%s: mask 0x%x set 0x%x " MAC_ADDRESS_STR,
7431 __func__, mask, set, MAC_ADDR_ARRAY(mac));
7432#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007433
7434 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
7435 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
Gopichand Nakkala681989c2013-03-06 22:27:48 -08007436 status = wlan_hdd_tdls_add_station(wiphy, dev, mac, 0, NULL);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007437 }
7438 }
7439#endif
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007440 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007441}
7442
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007443
7444#ifdef FEATURE_WLAN_LFR
Wilson Yang6507c4e2013-10-01 20:11:19 -07007445#define MAX_PMKSAIDS_IN_CACHE 8
7446
7447static tPmkidCacheInfo PMKIDCache[MAX_PMKSAIDS_IN_CACHE]; // HDD local cache
7448static tANI_U32 PMKIDCacheIndex; // HDD local Cache index
7449
7450
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007451static int wlan_hdd_cfg80211_set_pmksa(struct wiphy *wiphy, struct net_device *dev,
Jeff Johnsond13512a2012-07-17 11:42:19 -07007452 struct cfg80211_pmksa *pmksa)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007453{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307454 tANI_U32 j=0;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007455 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7456 tHalHandle halHandle;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307457 eHalStatus result;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307458 int status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007459 tANI_U8 BSSIDMatched = 0;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307460 hdd_context_t *pHddCtx;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307461
Jeff Johnson0299d0a2013-10-30 12:37:43 -07007462 hddLog(VOS_TRACE_LEVEL_DEBUG, "%s: set PMKSA for " MAC_ADDRESS_STR,
7463 __func__, MAC_ADDR_ARRAY(pmksa->bssid));
Jeff Johnsone7245742012-09-05 17:12:55 -07007464
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307465 // Validate pAdapter
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307466 if ( NULL == pAdapter )
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007467 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307468 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Adapter" ,__func__);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007469 return -EINVAL;
7470 }
7471
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307472 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7473 status = wlan_hdd_validate_context(pHddCtx);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007474
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307475 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007476 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307477 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7478 "%s: HDD context is not valid", __func__);
7479 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007480 }
7481
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307482 // Retrieve halHandle
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007483 halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
7484
Wilson Yang6507c4e2013-10-01 20:11:19 -07007485 for (j = 0; j < PMKIDCacheIndex; j++)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007486 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307487 if(vos_mem_compare(PMKIDCache[j].BSSID,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007488 pmksa->bssid, WNI_CFG_BSSID_LEN))
7489 {
7490 /* BSSID matched previous entry. Overwrite it. */
7491 BSSIDMatched = 1;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307492 vos_mem_copy(PMKIDCache[j].BSSID,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007493 pmksa->bssid, WNI_CFG_BSSID_LEN);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307494 vos_mem_copy(PMKIDCache[j].PMKID,
7495 pmksa->pmkid,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007496 CSR_RSN_PMKID_SIZE);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307497 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Reusing cache entry %d.",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007498 __func__, j );
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007499 dump_bssid(pmksa->bssid);
7500 dump_pmkid(halHandle, pmksa->pmkid);
7501 break;
7502 }
7503 }
7504
Madan Mohan Koyyalamudic4b317d2012-10-18 19:43:08 -07007505 /* Check we compared all entries,if then take the first slot now */
Wilson Yang6507c4e2013-10-01 20:11:19 -07007506 if(j == MAX_PMKSAIDS_IN_CACHE) PMKIDCacheIndex=0;
Madan Mohan Koyyalamudic4b317d2012-10-18 19:43:08 -07007507
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007508 if (!BSSIDMatched)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307509 {
7510 // Now, we DON'T have a BSSID match, so take a new entry in the cache.
Wilson Yang6507c4e2013-10-01 20:11:19 -07007511 vos_mem_copy(PMKIDCache[PMKIDCacheIndex].BSSID,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307512 pmksa->bssid, ETHER_ADDR_LEN);
Wilson Yang6507c4e2013-10-01 20:11:19 -07007513 vos_mem_copy(PMKIDCache[PMKIDCacheIndex].PMKID,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307514 pmksa->pmkid,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007515 CSR_RSN_PMKID_SIZE);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307516 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Adding a new cache entry %d.",
Wilson Yang6507c4e2013-10-01 20:11:19 -07007517 __func__, PMKIDCacheIndex );
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007518 dump_bssid(pmksa->bssid);
7519 dump_pmkid(halHandle, pmksa->pmkid);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307520 // Increment the HDD Local Cache index
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007521 // The "i=0" doesn't work for the call to sme_RoamSetPMKIDCache() - LFR FIXME
Wilson Yang6507c4e2013-10-01 20:11:19 -07007522 if (PMKIDCacheIndex <= (MAX_PMKSAIDS_IN_CACHE-1)) PMKIDCacheIndex++; else PMKIDCacheIndex = 0;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007523 }
7524
7525
7526 // Calling csrRoamSetPMKIDCache to configure the PMKIDs into the cache
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307527 //hddLog(LOG1, FL("%s: Calling csrRoamSetPMKIDCache with %d cache entries."),
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007528 // __func__, i );
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307529 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Calling csrRoamSetPMKIDCache with %d cache entries.",
Wilson Yang6507c4e2013-10-01 20:11:19 -07007530 __func__, PMKIDCacheIndex );
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007531 // Finally set the PMKSA ID Cache in CSR
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307532 result = sme_RoamSetPMKIDCache(halHandle,pAdapter->sessionId,
7533 PMKIDCache,
Wilson Yang6507c4e2013-10-01 20:11:19 -07007534 PMKIDCacheIndex);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007535 return 0;
7536}
7537
7538
Wilson Yang6507c4e2013-10-01 20:11:19 -07007539
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007540static int wlan_hdd_cfg80211_del_pmksa(struct wiphy *wiphy, struct net_device *dev,
Wilson Yang6507c4e2013-10-01 20:11:19 -07007541 struct cfg80211_pmksa *pmksa)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007542{
Wilson Yang6507c4e2013-10-01 20:11:19 -07007543 tANI_U32 j=0;
7544 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7545 tHalHandle halHandle;
7546 int status;
7547 tANI_U8 BSSIDMatched = 0;
Wilson Yang6507c4e2013-10-01 20:11:19 -07007548 hdd_context_t *pHddCtx;
7549 int result = 0;
7550
Jeff Johnson0299d0a2013-10-30 12:37:43 -07007551 hddLog(VOS_TRACE_LEVEL_DEBUG, "%s: deleting PMKSA for " MAC_ADDRESS_STR,
7552 __func__, MAC_ADDR_ARRAY(pmksa->bssid));
Wilson Yang6507c4e2013-10-01 20:11:19 -07007553
7554 /* Validate pAdapter */
7555 if (NULL == pAdapter)
7556 {
7557 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Adapter" ,__func__);
7558 return -EINVAL;
7559 }
7560
7561 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7562 status = wlan_hdd_validate_context(pHddCtx);
7563
7564 if (0 != status)
7565 {
7566 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7567 "%s: HDD context is not valid", __func__);
7568 return status;
7569 }
7570
7571 /*Retrieve halHandle*/
7572 halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
7573
7574 /*in case index is 0,no entry to delete*/
7575 if (0 == PMKIDCacheIndex)
7576 {
7577 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid entry to delete" ,
7578 __func__);
7579 return -EINVAL;
7580 }
7581
7582 /*find the matching PMKSA entry from j=0 to (index-1),
7583 * and delete the matched one
7584 */
7585 for (j = 0; j<PMKIDCacheIndex; j++)
7586 {
7587 if (vos_mem_compare(PMKIDCache[j].BSSID,
7588 pmksa->bssid,
7589 WNI_CFG_BSSID_LEN))
7590 {
7591 /* BSSID matched entry */
7592 BSSIDMatched = 1;
7593
7594 if (j<PMKIDCacheIndex-1)
7595 {
7596 /*replace the matching entry with the last entry in HDD local cache*/
7597 vos_mem_copy(PMKIDCache[j].BSSID,
7598 PMKIDCache[PMKIDCacheIndex-1].BSSID,
7599 WNI_CFG_BSSID_LEN);
7600 vos_mem_copy(PMKIDCache[j].PMKID,
7601 PMKIDCache[PMKIDCacheIndex-1].PMKID,
7602 CSR_RSN_PMKID_SIZE);
7603 }
7604
7605 /*clear the last entry in HDD cache ---[index-1]*/
Wilson Yang6507c4e2013-10-01 20:11:19 -07007606 vos_mem_zero(PMKIDCache[PMKIDCacheIndex-1].BSSID, WNI_CFG_BSSID_LEN);
7607 vos_mem_zero(PMKIDCache[PMKIDCacheIndex-1].PMKID, CSR_RSN_PMKID_SIZE);
7608
7609 /*reduce the PMKID array index*/
7610 PMKIDCacheIndex--;
7611
7612 /*delete the last PMKID cache in CSR*/
Kiet Lam8d21d5b2013-10-31 17:18:29 +05307613 result = sme_RoamDelPMKIDfromCache(halHandle, pAdapter->sessionId, pmksa->bssid);
Wilson Yang6507c4e2013-10-01 20:11:19 -07007614 if (0 != result)
7615 {
7616 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: cannot delete PMKSA %d CONTENT.",
7617 __func__,PMKIDCacheIndex);
7618 }
7619
7620 dump_bssid(pmksa->bssid);
7621 dump_pmkid(halHandle,pmksa->pmkid);
7622
7623 break;
7624 }
7625 }
7626
7627 /* we compare all entries,but cannot find matching entry */
7628 if (j == MAX_PMKSAIDS_IN_CACHE && !BSSIDMatched)
7629 {
Jeff Johnson0299d0a2013-10-30 12:37:43 -07007630 hddLog(VOS_TRACE_LEVEL_FATAL,
7631 "%s: No such PMKSA entry existed " MAC_ADDRESS_STR,
7632 __func__, MAC_ADDR_ARRAY(pmksa->bssid));
Wilson Yang6507c4e2013-10-01 20:11:19 -07007633 dump_bssid(pmksa->bssid);
7634 dump_pmkid(halHandle, pmksa->pmkid);
7635 return -EINVAL;
7636 }
7637 return result;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007638}
7639
Wilson Yang6507c4e2013-10-01 20:11:19 -07007640
7641
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007642static int wlan_hdd_cfg80211_flush_pmksa(struct wiphy *wiphy, struct net_device *dev)
7643{
Wilson Yang6507c4e2013-10-01 20:11:19 -07007644 tANI_U32 j=0;
7645 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7646 tHalHandle halHandle;
7647 hdd_context_t *pHddCtx;
7648 tANI_U8 *pBSSId;
7649 int status;
7650 int result;
7651
7652 hddLog(VOS_TRACE_LEVEL_DEBUG, "%s: flushing PMKSA ",__func__);
7653
7654 /* Validate pAdapter */
7655 if (NULL == pAdapter)
7656 {
7657 hddLog(VOS_TRACE_LEVEL_ERROR,
7658 "%s: Invalid Adapter" ,__func__);
7659 return -EINVAL;
7660 }
7661
7662 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7663 status = wlan_hdd_validate_context(pHddCtx);
7664
7665 if (0 != status)
7666 {
7667 hddLog(VOS_TRACE_LEVEL_ERROR,
7668 "%s: HDD context is not valid", __func__);
7669 return status;
7670 }
7671
7672 /*Retrieve halHandle*/
7673 halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
7674
7675 /*in case index is 0,no entry to delete*/
7676 if (0 == PMKIDCacheIndex)
7677 {
7678 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid entry to delete" ,
7679 __func__);
7680 return -EINVAL;
7681 }
7682
7683 /*delete all the PMKSA one by one */
7684 for (j = 0; j<PMKIDCacheIndex; j++)
7685 {
Wilson Yang6507c4e2013-10-01 20:11:19 -07007686 pBSSId =(tANI_U8 *)(PMKIDCache[j].BSSID);
Wilson Yang6507c4e2013-10-01 20:11:19 -07007687
7688 /*delete the PMKID in CSR*/
7689 result = sme_RoamDelPMKIDfromCache(halHandle, pAdapter->sessionId, pBSSId);
7690
7691 if (0!= result)
7692 {
7693 hddLog(VOS_TRACE_LEVEL_ERROR ,"%s cannot flush PMKIDCache %d.",
7694 __func__,j);
7695 }
Kiet Lam8d21d5b2013-10-31 17:18:29 +05307696 /*clear the entry in HDD cache 0--index-1 */
7697 vos_mem_zero(PMKIDCache[j].BSSID, WNI_CFG_BSSID_LEN);
7698 vos_mem_zero(PMKIDCache[j].PMKID, CSR_RSN_PMKID_SIZE);
Wilson Yang6507c4e2013-10-01 20:11:19 -07007699 }
7700
7701 PMKIDCacheIndex = 0;
7702 return result;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007703}
7704#endif
7705
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07007706#if defined(WLAN_FEATURE_VOWIFI_11R) && defined(KERNEL_SUPPORT_11R_CFG80211)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307707static int wlan_hdd_cfg80211_update_ft_ies(struct wiphy *wiphy,
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07007708 struct net_device *dev, struct cfg80211_update_ft_ies_params *ftie)
7709{
7710 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7711 hdd_station_ctx_t *pHddStaCtx;
7712
7713 if (NULL == pAdapter)
7714 {
7715 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Adapter is NULL\n", __func__);
7716 return -ENODEV;
7717 }
7718
7719 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
7720
7721 // Added for debug on reception of Re-assoc Req.
7722 if (eConnectionState_Associated != pHddStaCtx->conn_info.connState)
7723 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307724 hddLog(LOGE, FL("Called with Ie of length = %d when not associated\n"),
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07007725 ftie->ie_len);
7726 hddLog(LOGE, FL("Should be Re-assoc Req IEs\n"));
7727 }
7728
7729#ifdef WLAN_FEATURE_VOWIFI_11R_DEBUG
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307730 hddLog(LOGE, FL("%s called with Ie of length = %d\n"), __func__,
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07007731 ftie->ie_len);
7732#endif
7733
7734 // Pass the received FT IEs to SME
Gopichand Nakkala356fb102013-03-06 12:34:04 +05307735 sme_SetFTIEs( WLAN_HDD_GET_HAL_CTX(pAdapter), pAdapter->sessionId,
7736 (const u8 *)ftie->ie,
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07007737 ftie->ie_len);
7738 return 0;
7739}
7740#endif
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007741
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307742#ifdef FEATURE_WLAN_SCAN_PNO
7743
7744void hdd_cfg80211_sched_scan_done_callback(void *callbackContext,
7745 tSirPrefNetworkFoundInd *pPrefNetworkFoundInd)
7746{
7747 int ret;
7748 hdd_adapter_t* pAdapter = (hdd_adapter_t*)callbackContext;
7749 hdd_context_t *pHddCtx;
7750
7751 if (NULL == pAdapter)
7752 {
7753 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
7754 "%s: HDD adapter is Null", __func__);
7755 return ;
7756 }
7757
7758 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7759 if (NULL == pHddCtx)
7760 {
7761 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7762 "%s: HDD context is Null!!!", __func__);
7763 return ;
7764 }
7765
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05307766 spin_lock(&pHddCtx->schedScan_lock);
7767 if (TRUE == pHddCtx->isWiphySuspended)
7768 {
7769 pHddCtx->isSchedScanUpdatePending = TRUE;
7770 spin_unlock(&pHddCtx->schedScan_lock);
7771 hddLog(VOS_TRACE_LEVEL_INFO,
7772 "%s: Update cfg80211 scan database after it resume", __func__);
7773 return ;
7774 }
7775 spin_unlock(&pHddCtx->schedScan_lock);
7776
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307777 ret = wlan_hdd_cfg80211_update_bss(pHddCtx->wiphy, pAdapter);
7778
7779 if (0 > ret)
7780 hddLog(VOS_TRACE_LEVEL_INFO, "%s: NO SCAN result", __func__);
7781
7782 cfg80211_sched_scan_results(pHddCtx->wiphy);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05307783 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
7784 "%s: cfg80211 scan result database updated", __func__);
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307785}
7786
7787/*
7788 * FUNCTION: wlan_hdd_cfg80211_sched_scan_start
7789 * NL interface to enable PNO
7790 */
7791static int wlan_hdd_cfg80211_sched_scan_start(struct wiphy *wiphy,
7792 struct net_device *dev, struct cfg80211_sched_scan_request *request)
7793{
7794 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7795 tpSirPNOScanReq pPnoRequest = NULL;
7796 hdd_context_t *pHddCtx;
7797 tHalHandle hHal;
Madan Mohan Koyyalamudi1d16f462013-08-27 16:25:34 +05307798 v_U32_t i, indx, num_ch, tempInterval;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307799 u8 valid_ch[WNI_CFG_VALID_CHANNEL_LIST_LEN];
7800 u8 channels_allowed[WNI_CFG_VALID_CHANNEL_LIST_LEN];
7801 v_U32_t num_channels_allowed = WNI_CFG_VALID_CHANNEL_LIST_LEN;
7802 eHalStatus status = eHAL_STATUS_FAILURE;
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307803 int ret = 0;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307804
7805 if (NULL == pAdapter)
7806 {
7807 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
7808 "%s: HDD adapter is Null", __func__);
7809 return -ENODEV;
7810 }
7811
7812 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05307813 ret = wlan_hdd_validate_context(pHddCtx);
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307814
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05307815 if (0 != ret)
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307816 {
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05307817 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7818 "%s: HDD context is not valid", __func__);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307819 return -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307820 }
7821
7822 hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
7823 if (NULL == hHal)
7824 {
7825 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7826 "%s: HAL context is Null!!!", __func__);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05307827 return -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307828 }
7829
7830 pPnoRequest = (tpSirPNOScanReq) vos_mem_malloc(sizeof (tSirPNOScanReq));
7831 if (NULL == pPnoRequest)
7832 {
7833 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
7834 "%s: vos_mem_malloc failed", __func__);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307835 return -ENOMEM;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307836 }
7837
Madan Mohan Koyyalamudic3f04352013-09-26 19:21:48 +05307838 memset(pPnoRequest, 0, sizeof (tSirPNOScanReq));
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307839 pPnoRequest->enable = 1; /*Enable PNO */
7840 pPnoRequest->ucNetworksCount = request->n_match_sets;
7841
7842 if (( !pPnoRequest->ucNetworksCount ) ||
7843 ( pPnoRequest->ucNetworksCount > SIR_PNO_MAX_SUPP_NETWORKS ))
7844 {
7845 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7846 "Network input is not correct");
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307847 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307848 goto error;
7849 }
7850
7851 if ( SIR_PNO_MAX_NETW_CHANNELS_EX < request->n_channels )
7852 {
7853 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7854 "Incorrect number of channels");
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307855 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307856 goto error;
7857 }
7858
7859 /* Framework provides one set of channels(all)
7860 * common for all saved profile */
7861 if (0 != ccmCfgGetStr(hHal, WNI_CFG_VALID_CHANNEL_LIST,
7862 channels_allowed, &num_channels_allowed))
7863 {
7864 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7865 "%s: failed to get valid channel list", __func__);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307866 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307867 goto error;
7868 }
7869 /* Checking each channel against allowed channel list */
7870 num_ch = 0;
7871 for (i = 0; i < request->n_channels; i++)
7872 {
7873 for (indx = 0; indx < num_channels_allowed; indx++)
7874 {
7875 if (request->channels[i]->hw_value == channels_allowed[indx])
7876 {
7877 valid_ch[num_ch++] = request->channels[i]->hw_value;
7878 break ;
7879 }
7880 }
7881 }
7882
7883 /* Filling per profile params */
7884 for (i = 0; i < pPnoRequest->ucNetworksCount; i++)
7885 {
7886 pPnoRequest->aNetworks[i].ssId.length =
7887 request->match_sets[i].ssid.ssid_len;
7888
7889 if (( 0 == pPnoRequest->aNetworks[i].ssId.length ) ||
7890 ( pPnoRequest->aNetworks[i].ssId.length > 32 ) )
7891 {
7892 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7893 "SSID Len %d is not correct for network %d",
7894 pPnoRequest->aNetworks[i].ssId.length, i);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307895 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307896 goto error;
7897 }
7898
7899 memcpy(pPnoRequest->aNetworks[i].ssId.ssId,
7900 request->match_sets[i].ssid.ssid,
7901 request->match_sets[i].ssid.ssid_len);
7902 pPnoRequest->aNetworks[i].authentication = 0; /*eAUTH_TYPE_ANY*/
7903 pPnoRequest->aNetworks[i].encryption = 0; /*eED_ANY*/
7904 pPnoRequest->aNetworks[i].bcastNetwType = 0; /*eBCAST_UNKNOWN*/
7905
7906 /*Copying list of valid channel into request */
7907 memcpy(pPnoRequest->aNetworks[i].aChannels, valid_ch, num_ch);
7908 pPnoRequest->aNetworks[i].ucChannelCount = num_ch;
7909
7910 pPnoRequest->aNetworks[i].rssiThreshold = 0; //Default value
7911 }
7912
Madan Mohan Koyyalamudia7765d52013-09-18 16:49:56 +05307913 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
7914 "request->ie_len = %d", request->ie_len);
7915 if ((0 < request->ie_len) && (NULL != request->ie))
7916 {
7917 pPnoRequest->us24GProbeTemplateLen = request->ie_len;
7918 memcpy(&pPnoRequest->p24GProbeTemplate, request->ie,
7919 pPnoRequest->us24GProbeTemplateLen);
7920
7921 pPnoRequest->us5GProbeTemplateLen = request->ie_len;
7922 memcpy(&pPnoRequest->p5GProbeTemplate, request->ie,
7923 pPnoRequest->us5GProbeTemplateLen);
7924 }
7925
Madan Mohan Koyyalamudi1d16f462013-08-27 16:25:34 +05307926 /* Driver gets only one time interval which is hardcoded in
7927 * supplicant for 10000ms. Taking power consumption into account 6 timers
7928 * will be used, Timervalue is increased exponentially i.e 10,20,40,
7929 * 80,160,320 secs. And number of scan cycle for each timer
7930 * is configurable through INI param gPNOScanTimerRepeatValue.
7931 * If it is set to 0 only one timer will be used and PNO scan cycle
7932 * will be repeated after each interval specified by supplicant
7933 * till PNO is disabled.
7934 */
7935 if (0 == pHddCtx->cfg_ini->configPNOScanTimerRepeatValue)
7936 pPnoRequest->scanTimers.ucScanTimersCount = HDD_PNO_SCAN_TIMERS_SET_ONE;
7937 else
7938 pPnoRequest->scanTimers.ucScanTimersCount =
7939 HDD_PNO_SCAN_TIMERS_SET_MULTIPLE;
7940
7941 tempInterval = (request->interval)/1000;
7942 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
7943 "Base scan interval = %d PNOScanTimerRepeatValue = %d",
7944 tempInterval, pHddCtx->cfg_ini->configPNOScanTimerRepeatValue);
7945 for ( i = 0; i < pPnoRequest->scanTimers.ucScanTimersCount; i++)
7946 {
7947 pPnoRequest->scanTimers.aTimerValues[i].uTimerRepeat =
7948 pHddCtx->cfg_ini->configPNOScanTimerRepeatValue;
7949 pPnoRequest->scanTimers.aTimerValues[i].uTimerValue = tempInterval;
7950 tempInterval *= 2;
7951 }
7952 //Repeat last timer until pno disabled.
7953 pPnoRequest->scanTimers.aTimerValues[i-1].uTimerRepeat = 0;
7954
Madan Mohan Koyyalamudid206c7b2013-09-26 22:54:51 +05307955 pPnoRequest->modePNO = SIR_PNO_MODE_IMMEDIATE;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307956
7957 status = sme_SetPreferredNetworkList(WLAN_HDD_GET_HAL_CTX(pAdapter),
7958 pPnoRequest, pAdapter->sessionId,
7959 hdd_cfg80211_sched_scan_done_callback, pAdapter);
7960 if (eHAL_STATUS_SUCCESS != status)
7961 {
7962 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7963 "Failed to enable PNO");
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307964 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307965 goto error;
7966 }
7967
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05307968 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
7969 "PNO scanRequest offloaded");
7970
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307971error:
7972 vos_mem_free(pPnoRequest);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307973 return ret;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307974}
7975
7976/*
7977 * FUNCTION: wlan_hdd_cfg80211_sched_scan_stop
7978 * NL interface to disable PNO
7979 */
7980static int wlan_hdd_cfg80211_sched_scan_stop(struct wiphy *wiphy,
7981 struct net_device *dev)
7982{
7983 eHalStatus status = eHAL_STATUS_FAILURE;
7984 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7985 hdd_context_t *pHddCtx;
7986 tHalHandle hHal;
7987 tpSirPNOScanReq pPnoRequest = NULL;
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307988 int ret = 0;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307989
7990 ENTER();
7991
7992 if (NULL == pAdapter)
7993 {
7994 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
7995 "%s: HDD adapter is Null", __func__);
7996 return -ENODEV;
7997 }
7998
7999 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308000
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308001 if (NULL == pHddCtx)
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308002 {
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05308003 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308004 "%s: HDD context is Null", __func__);
8005 return -ENODEV;
8006 }
8007
8008 /* The return 0 is intentional when isLogpInProgress and
8009 * isLoadUnloadInProgress. We did observe a crash due to a return of
8010 * failure in sched_scan_stop , especially for a case where the unload
8011 * of the happens at the same time. The function __cfg80211_stop_sched_scan
8012 * was clearing rdev->sched_scan_req only when the sched_scan_stop returns
8013 * success. If it returns a failure , then its next invocation due to the
8014 * clean up of the second interface will have the dev pointer corresponding
8015 * to the first one leading to a crash.
8016 */
8017 if (pHddCtx->isLogpInProgress)
8018 {
8019 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8020 "%s: LOGP in Progress. Ignore!!!", __func__);
8021 return ret;
8022 }
8023
8024 if (pHddCtx->isLoadUnloadInProgress)
8025 {
8026 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8027 "%s: Unloading/Loading in Progress. Ignore!!!", __func__);
8028 return ret;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308029 }
8030
8031 hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
8032 if (NULL == hHal)
8033 {
8034 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8035 "%s: HAL context is Null!!!", __func__);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308036 return -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308037 }
8038
8039 pPnoRequest = (tpSirPNOScanReq) vos_mem_malloc(sizeof (tSirPNOScanReq));
8040 if (NULL == pPnoRequest)
8041 {
8042 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8043 "%s: vos_mem_malloc failed", __func__);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308044 return -ENOMEM;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308045 }
8046
8047 memset(pPnoRequest, 0, sizeof (tSirPNOScanReq));
8048 pPnoRequest->enable = 0; /* Disable PNO */
8049 pPnoRequest->ucNetworksCount = 0;
8050
8051 status = sme_SetPreferredNetworkList(hHal, pPnoRequest,
8052 pAdapter->sessionId,
8053 NULL, pAdapter);
8054 if (eHAL_STATUS_SUCCESS != status)
8055 {
8056 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8057 "Failed to disabled PNO");
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308058 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308059 }
8060
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308061 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8062 "%s: PNO scan disabled", __func__);
8063
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308064 vos_mem_free(pPnoRequest);
8065
8066 EXIT();
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308067 return ret;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308068}
8069
8070#endif /*FEATURE_WLAN_SCAN_PNO*/
8071
8072
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008073#ifdef FEATURE_WLAN_TDLS
8074static int wlan_hdd_cfg80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
8075 u8 *peer, u8 action_code, u8 dialog_token,
8076 u16 status_code, const u8 *buf, size_t len)
8077{
8078
8079 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8080 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008081 u8 peerMac[6];
8082 VOS_STATUS status;
Gopichand Nakkala05922802013-03-14 12:23:19 -07008083 int max_sta_failed = 0;
Hoonki Leea34dd892013-02-05 22:56:02 -08008084 int responder;
Hoonki Leed37cbb32013-04-20 00:31:14 -07008085 long rc;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008086
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008087 if (NULL == pHddCtx || NULL == pHddCtx->cfg_ini)
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008088 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05308089 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008090 "Invalid arguments");
8091 return -EINVAL;
8092 }
8093
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08008094 if (pHddCtx->isLogpInProgress)
8095 {
8096 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8097 "%s:LOGP in Progress. Ignore!!!", __func__);
Gopichand Nakkala05922802013-03-14 12:23:19 -07008098 wlan_hdd_tdls_set_link_status(pAdapter, peer, eTDLS_LINK_IDLE);
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08008099 return -EBUSY;
8100 }
8101
Hoonki Lee27511902013-03-14 18:19:06 -07008102 if (eTDLS_SUPPORT_NOT_ENABLED == pHddCtx->tdls_mode)
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008103 {
Hoonki Lee27511902013-03-14 18:19:06 -07008104 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
8105 "%s: TDLS mode is disabled OR not enabled in FW."
8106 MAC_ADDRESS_STR " action %d declined.",
8107 __func__, MAC_ADDR_ARRAY(peer), action_code);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008108 return -ENOTSUPP;
8109 }
Lee Hoonkic1262f22013-01-24 21:59:00 -08008110
Hoonki Lee27511902013-03-14 18:19:06 -07008111 /* other than teardown frame, other mgmt frames are not sent if disabled */
8112 if (SIR_MAC_TDLS_TEARDOWN != action_code)
8113 {
8114 /* if tdls_mode is disabled to respond to peer's request */
8115 if (eTDLS_SUPPORT_DISABLED == pHddCtx->tdls_mode)
8116 {
8117 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
8118 "%s: " MAC_ADDRESS_STR
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07008119 " TDLS mode is disabled. action %d declined.",
8120 __func__, MAC_ADDR_ARRAY(peer), action_code);
Hoonki Lee27511902013-03-14 18:19:06 -07008121
8122 return -ENOTSUPP;
8123 }
8124 }
8125
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008126 if (WLAN_IS_TDLS_SETUP_ACTION(action_code))
8127 {
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05308128 if (NULL != wlan_hdd_tdls_is_progress(pHddCtx, peer, TRUE))
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008129 {
8130 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008131 "%s: " MAC_ADDRESS_STR
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07008132 " TDLS setup is ongoing. action %d declined.",
8133 __func__, MAC_ADDR_ARRAY(peer), action_code);
8134 return -EPERM;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008135 }
8136 }
8137
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008138 if (SIR_MAC_TDLS_SETUP_REQ == action_code ||
8139 SIR_MAC_TDLS_SETUP_RSP == action_code )
Lee Hoonkic1262f22013-01-24 21:59:00 -08008140 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08008141 if (HDD_MAX_NUM_TDLS_STA <= wlan_hdd_tdlsConnectedPeers(pAdapter))
Lee Hoonkic1262f22013-01-24 21:59:00 -08008142 {
8143 /* supplicant still sends tdls_mgmt(SETUP_REQ) even after
8144 we return error code at 'add_station()'. Hence we have this
8145 check again in addtion to add_station().
8146 Anyway, there is no hard to double-check. */
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008147 if (SIR_MAC_TDLS_SETUP_REQ == action_code)
Lee Hoonkic1262f22013-01-24 21:59:00 -08008148 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008149 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8150 "%s: " MAC_ADDRESS_STR
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07008151 " TDLS Max peer already connected. action %d declined.",
8152 __func__, MAC_ADDR_ARRAY(peer), action_code);
Gopichand Nakkala05922802013-03-14 12:23:19 -07008153 goto error;
Lee Hoonkic1262f22013-01-24 21:59:00 -08008154 }
8155 else
8156 {
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008157 /* maximum reached. tweak to send error code to peer and return
8158 error code to supplicant */
Lee Hoonkic1262f22013-01-24 21:59:00 -08008159 status_code = eSIR_MAC_UNSPEC_FAILURE_STATUS;
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008160 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8161 "%s: " MAC_ADDRESS_STR
8162 " TDLS Max peer already connected send response status %d",
8163 __func__, MAC_ADDR_ARRAY(peer), status_code);
Gopichand Nakkala05922802013-03-14 12:23:19 -07008164 max_sta_failed = -EPERM;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008165 /* fall through to send setup resp with failure status
8166 code */
Lee Hoonkic1262f22013-01-24 21:59:00 -08008167 }
8168 }
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008169 else
8170 {
8171 hddTdlsPeer_t *pTdlsPeer;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05308172 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peer, TRUE);
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07008173 if (pTdlsPeer && TDLS_IS_CONNECTED(pTdlsPeer))
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008174 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008175 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07008176 "%s:" MAC_ADDRESS_STR " already connected. action %d declined.",
8177 __func__, MAC_ADDR_ARRAY(peer), action_code);
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008178 return -EPERM;
8179 }
8180 }
Lee Hoonkic1262f22013-01-24 21:59:00 -08008181 }
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008182 vos_mem_copy(peerMac, peer, 6);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008183
Hoonki Lee1090c6a2013-01-16 17:40:54 -08008184#ifdef WLAN_FEATURE_TDLS_DEBUG
8185 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008186 "%s: " MAC_ADDRESS_STR " action %d, dialog_token %d status %d, len = %d",
8187 "tdls_mgmt", MAC_ADDR_ARRAY(peer),
8188 action_code, dialog_token, status_code, len);
Hoonki Lee1090c6a2013-01-16 17:40:54 -08008189#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008190
Hoonki Leea34dd892013-02-05 22:56:02 -08008191 /*Except teardown responder will not be used so just make 0*/
8192 responder = 0;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008193 if (SIR_MAC_TDLS_TEARDOWN == action_code)
Hoonki Leea34dd892013-02-05 22:56:02 -08008194 {
Gopichand Nakkala97a65fd2013-04-16 16:59:38 -07008195
8196 hddTdlsPeer_t *pTdlsPeer;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05308197 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peerMac, TRUE);
Gopichand Nakkala97a65fd2013-04-16 16:59:38 -07008198
8199 if(pTdlsPeer && TDLS_IS_CONNECTED(pTdlsPeer))
8200 responder = pTdlsPeer->is_responder;
8201 else
Hoonki Leea34dd892013-02-05 22:56:02 -08008202 {
Gopichand Nakkala97a65fd2013-04-16 16:59:38 -07008203 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8204 "%s: " MAC_ADDRESS_STR " peer doesn't exist or not connected %d dialog_token %d status %d, len = %d",
8205 __func__, MAC_ADDR_ARRAY(peer), (NULL == pTdlsPeer) ? -1 : pTdlsPeer->link_status,
8206 dialog_token, status_code, len);
8207 return -EPERM;
Hoonki Leea34dd892013-02-05 22:56:02 -08008208 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008209 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008210
Gopichand Nakkala2f1ff152013-07-01 11:27:43 +05308211 /* For explicit trigger of DIS_REQ come out of BMPS for
8212 successfully receiving DIS_RSP from peer. */
Hoonki Lee14621352013-04-16 17:51:19 -07008213 if ((SIR_MAC_TDLS_SETUP_RSP == action_code) ||
Gopichand Nakkala2f1ff152013-07-01 11:27:43 +05308214 (SIR_MAC_TDLS_DIS_RSP == action_code) ||
8215 (SIR_MAC_TDLS_DIS_REQ == action_code))
Hoonki Lee14621352013-04-16 17:51:19 -07008216 {
8217 if (TRUE == sme_IsPmcBmps(WLAN_HDD_GET_HAL_CTX(pAdapter)))
8218 {
8219 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
Gopichand Nakkala2f1ff152013-07-01 11:27:43 +05308220 "%s: Sending frame action_code %u.Disable BMPS", __func__, action_code);
Hoonki Lee14621352013-04-16 17:51:19 -07008221 hdd_disable_bmps_imps(pHddCtx, WLAN_HDD_INFRA_STATION);
8222 }
Gopichand Nakkala2f1ff152013-07-01 11:27:43 +05308223 if (SIR_MAC_TDLS_DIS_REQ != action_code)
8224 wlan_hdd_tdls_set_cap(pAdapter, peerMac, eTDLS_CAP_SUPPORTED);
Hoonki Lee14621352013-04-16 17:51:19 -07008225 }
8226
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008227 /* make sure doesn't call send_mgmt() while it is pending */
8228 if (TDLS_CTX_MAGIC == pAdapter->mgmtTxCompletionStatus)
8229 {
8230 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8231 "%s: " MAC_ADDRESS_STR " action %d couldn't sent, as one is pending. return EBUSY\n",
8232 __func__, MAC_ADDR_ARRAY(peer), action_code);
8233 return -EBUSY;
8234 }
8235
8236 pAdapter->mgmtTxCompletionStatus = TDLS_CTX_MAGIC;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008237 INIT_COMPLETION(pAdapter->tdls_mgmt_comp);
8238
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008239 status = sme_SendTdlsMgmtFrame(WLAN_HDD_GET_HAL_CTX(pAdapter), pAdapter->sessionId,
Hoonki Leea34dd892013-02-05 22:56:02 -08008240 peerMac, action_code, dialog_token, status_code, (tANI_U8 *)buf, len, responder);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008241
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008242 if (VOS_STATUS_SUCCESS != status)
8243 {
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008244 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8245 "%s: sme_SendTdlsMgmtFrame failed!", __func__);
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008246 pAdapter->mgmtTxCompletionStatus = FALSE;
Hoonki Lee14621352013-04-16 17:51:19 -07008247 wlan_hdd_tdls_check_bmps(pAdapter);
8248 goto error;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008249 }
8250
Hoonki Leed37cbb32013-04-20 00:31:14 -07008251 rc = wait_for_completion_interruptible_timeout(&pAdapter->tdls_mgmt_comp,
8252 msecs_to_jiffies(WAIT_TIME_TDLS_MGMT));
8253
8254 if ((rc <= 0) || (TRUE != pAdapter->mgmtTxCompletionStatus))
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008255 {
Hoonki Leed37cbb32013-04-20 00:31:14 -07008256 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Jeff Johnson0299d0a2013-10-30 12:37:43 -07008257 "%s: Mgmt Tx Completion failed status %ld TxCompletion %u",
Hoonki Leed37cbb32013-04-20 00:31:14 -07008258 __func__, rc, pAdapter->mgmtTxCompletionStatus);
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008259 pAdapter->mgmtTxCompletionStatus = FALSE;
Hoonki Leed37cbb32013-04-20 00:31:14 -07008260 wlan_hdd_tdls_check_bmps(pAdapter);
8261 goto error;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008262 }
8263
Gopichand Nakkala05922802013-03-14 12:23:19 -07008264 if (max_sta_failed)
Hoonki Lee14621352013-04-16 17:51:19 -07008265 {
8266 wlan_hdd_tdls_check_bmps(pAdapter);
Gopichand Nakkala05922802013-03-14 12:23:19 -07008267 return max_sta_failed;
Hoonki Lee14621352013-04-16 17:51:19 -07008268 }
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008269
Hoonki Leea34dd892013-02-05 22:56:02 -08008270 if (SIR_MAC_TDLS_SETUP_RSP == action_code)
8271 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08008272 wlan_hdd_tdls_set_responder(pAdapter, peerMac, TRUE);
Hoonki Leea34dd892013-02-05 22:56:02 -08008273 }
8274 else if (SIR_MAC_TDLS_SETUP_CNF == action_code)
8275 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08008276 wlan_hdd_tdls_set_responder(pAdapter, peerMac, FALSE);
Hoonki Leea34dd892013-02-05 22:56:02 -08008277 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008278
8279 return 0;
Gopichand Nakkala05922802013-03-14 12:23:19 -07008280error:
8281 /* max_sta_failed ; we didn't set to CONNECTING for this case,
8282 because we already know that this transaction will be failed,
8283 but we weren't sure if supplicant call DISABLE_LINK or not. So,
8284 to be safe, do not change the state mahine.
8285 */
8286 if(max_sta_failed == 0 &&
8287 (WLAN_IS_TDLS_SETUP_ACTION(action_code)))
8288 wlan_hdd_tdls_set_link_status(pAdapter, peerMac, eTDLS_LINK_IDLE);
8289 return -EPERM;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008290}
8291
8292static int wlan_hdd_cfg80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
8293 u8 *peer, enum nl80211_tdls_operation oper)
8294{
8295 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8296 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308297 int status;
Hoonki Lee1090c6a2013-01-16 17:40:54 -08008298#ifdef WLAN_FEATURE_TDLS_DEBUG
8299 const char *tdls_oper_str[]= {
8300 "NL80211_TDLS_DISCOVERY_REQ",
8301 "NL80211_TDLS_SETUP",
8302 "NL80211_TDLS_TEARDOWN",
8303 "NL80211_TDLS_ENABLE_LINK",
8304 "NL80211_TDLS_DISABLE_LINK",
Gopichand Nakkala29d00192013-06-20 19:03:52 +05308305 "NL80211_TDLS_UNKNOWN_OPER"};
Hoonki Lee1090c6a2013-01-16 17:40:54 -08008306#endif
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008307 hddTdlsPeer_t *pTdlsPeer;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008308
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308309 if ( NULL == peer )
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008310 {
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008311 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Chilam Ngc4244af2013-04-01 15:37:32 -07008312 "%s: Invalid arguments", __func__);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008313 return -EINVAL;
8314 }
Hoonki Lee1090c6a2013-01-16 17:40:54 -08008315
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308316 status = wlan_hdd_validate_context(pHddCtx);
8317
8318 if (0 != status)
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08008319 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308320 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8321 "%s: HDD context is not valid", __func__);
8322 return status;
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08008323 }
8324
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05308325 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peer, TRUE);
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008326
8327 if ( NULL == pTdlsPeer ) {
8328 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: " MAC_ADDRESS_STR " (oper %d) not exsting. ignored",
8329 __func__, MAC_ADDR_ARRAY(peer), (int)oper);
8330 return -EINVAL;
8331 }
8332
Hoonki Lee1090c6a2013-01-16 17:40:54 -08008333#ifdef WLAN_FEATURE_TDLS_DEBUG
8334 if((int)oper > 4)
8335 oper = 5;
8336
8337 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008338 "%s: " MAC_ADDRESS_STR " link_status %d (%s) ", "tdls_oper",
8339 MAC_ADDR_ARRAY(peer), pTdlsPeer->link_status,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008340 tdls_oper_str[(int)oper]);
Hoonki Lee1090c6a2013-01-16 17:40:54 -08008341#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008342
8343 if( FALSE == pHddCtx->cfg_ini->fEnableTDLSSupport ||
Hoonki Lee1090c6a2013-01-16 17:40:54 -08008344 FALSE == sme_IsFeatureSupportedByFW(TDLS))
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008345 {
Hoonki Lee1090c6a2013-01-16 17:40:54 -08008346 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Chilam Ngc4244af2013-04-01 15:37:32 -07008347 "TDLS Disabled in INI OR not enabled in FW. "
8348 "Cannot process TDLS commands");
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008349 return -ENOTSUPP;
8350 }
8351
8352 switch (oper) {
8353 case NL80211_TDLS_ENABLE_LINK:
8354 {
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008355 VOS_STATUS status;
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05308356 tCsrTdlsLinkEstablishParams tdlsLinkEstablishParams;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008357
Gopichand Nakkala2f4a2822013-04-17 11:22:01 -07008358 if (!TDLS_STA_INDEX_VALID(pTdlsPeer->staId))
8359 {
8360 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Staion Index %u "
8361 MAC_ADDRESS_STR " failed",
8362 __func__, pTdlsPeer->staId, MAC_ADDR_ARRAY(peer));
8363 return -EINVAL;
8364 }
8365
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008366 if (eTDLS_LINK_CONNECTED != pTdlsPeer->link_status)
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008367 {
Gopichand Nakkala24be5312013-07-02 16:47:12 +05308368 long ret;
Madan Mohan Koyyalamudice419872013-09-13 19:36:52 +05308369 if (IS_ADVANCE_TDLS_ENABLE) {
Gopichand Nakkala24be5312013-07-02 16:47:12 +05308370
Madan Mohan Koyyalamudice419872013-09-13 19:36:52 +05308371 if (0 != wlan_hdd_tdls_get_link_establish_params(
8372 pAdapter, peer,&tdlsLinkEstablishParams)) {
8373 return -EINVAL;
8374 }
8375 INIT_COMPLETION(pAdapter->tdls_link_establish_req_comp);
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05308376
Madan Mohan Koyyalamudice419872013-09-13 19:36:52 +05308377 sme_SendTdlsLinkEstablishParams(WLAN_HDD_GET_HAL_CTX(pAdapter),
8378 pAdapter->sessionId, peer, &tdlsLinkEstablishParams);
8379 /* Send TDLS peer UAPSD capabilities to the firmware and
8380 * register with the TL on after the response for this operation
8381 * is received .
8382 */
8383 ret = wait_for_completion_interruptible_timeout(
8384 &pAdapter->tdls_link_establish_req_comp,
8385 msecs_to_jiffies(WAIT_TIME_TDLS_LINK_ESTABLISH_REQ));
8386 if (ret <= 0)
8387 {
8388 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8389 "%s: Link Establish Request Faled Status %ld",
8390 __func__, ret);
8391 return -EINVAL;
8392 }
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05308393 }
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07008394 wlan_hdd_tdls_set_peer_link_status(pTdlsPeer, eTDLS_LINK_CONNECTED);
Gopichand Nakkala471708b2013-06-04 20:03:01 +05308395 /* Mark TDLS client Authenticated .*/
8396 status = WLANTL_ChangeSTAState( pHddCtx->pvosContext,
8397 pTdlsPeer->staId,
8398 WLANTL_STA_AUTHENTICATED);
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07008399 if (VOS_STATUS_SUCCESS == status)
8400 {
Hoonki Lee14621352013-04-16 17:51:19 -07008401 if (pTdlsPeer->is_responder == 0)
8402 {
8403 v_U8_t staId = (v_U8_t)pTdlsPeer->staId;
8404
8405 wlan_hdd_tdls_timer_restart(pAdapter,
8406 &pTdlsPeer->initiatorWaitTimeoutTimer,
8407 WAIT_TIME_TDLS_INITIATOR);
8408 /* suspend initiator TX until it receives direct packet from the
8409 reponder or WAIT_TIME_TDLS_INITIATOR timer expires */
8410 WLANTL_SuspendDataTx( (WLAN_HDD_GET_CTX(pAdapter))->pvosContext,
8411 &staId, NULL);
8412 }
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07008413 wlan_hdd_tdls_increment_peer_count(pAdapter);
8414 }
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008415 wlan_hdd_tdls_check_bmps(pAdapter);
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05308416
8417 /* Update TL about the UAPSD masks , to route the packets to firmware */
Gopichand Nakkala574f6d12013-06-27 19:38:43 +05308418 if ((TRUE == pHddCtx->cfg_ini->fEnableTDLSBufferSta)
8419 || pHddCtx->cfg_ini->fTDLSUapsdMask )
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05308420 {
Gopichand Nakkala574f6d12013-06-27 19:38:43 +05308421 int ac;
8422 uint8 ucAc[4] = { WLANTL_AC_VO,
8423 WLANTL_AC_VI,
8424 WLANTL_AC_BK,
8425 WLANTL_AC_BE };
8426 uint8 tlTid[4] = { 7, 5, 2, 3 } ;
8427 for(ac=0; ac < 4; ac++)
8428 {
8429 status = WLANTL_EnableUAPSDForAC( (WLAN_HDD_GET_CTX(pAdapter))->pvosContext,
8430 pTdlsPeer->staId, ucAc[ac],
8431 tlTid[ac], tlTid[ac], 0, 0,
8432 WLANTL_BI_DIR );
8433 }
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05308434 }
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008435 }
8436
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008437 }
8438 break;
8439 case NL80211_TDLS_DISABLE_LINK:
Lee Hoonkic1262f22013-01-24 21:59:00 -08008440 {
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008441 if(TDLS_STA_INDEX_VALID(pTdlsPeer->staId))
Lee Hoonkic1262f22013-01-24 21:59:00 -08008442 {
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07008443 long status;
8444
8445 INIT_COMPLETION(pAdapter->tdls_del_station_comp);
8446
Lee Hoonkic1262f22013-01-24 21:59:00 -08008447 sme_DeleteTdlsPeerSta( WLAN_HDD_GET_HAL_CTX(pAdapter),
8448 pAdapter->sessionId, peer );
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07008449
8450 status = wait_for_completion_interruptible_timeout(&pAdapter->tdls_del_station_comp,
8451 msecs_to_jiffies(WAIT_TIME_TDLS_DEL_STA));
8452 if (status <= 0)
8453 {
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008454 wlan_hdd_tdls_set_peer_link_status(pTdlsPeer, eTDLS_LINK_IDLE);
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07008455 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8456 "%s: Del station failed status %ld",
8457 __func__, status);
8458 return -EPERM;
8459 }
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008460 wlan_hdd_tdls_set_peer_link_status(pTdlsPeer, eTDLS_LINK_IDLE);
Lee Hoonkic1262f22013-01-24 21:59:00 -08008461 }
8462 else
8463 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008464 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8465 "%s: TDLS Peer Station doesn't exist.", __func__);
Lee Hoonkic1262f22013-01-24 21:59:00 -08008466 }
Lee Hoonkic1262f22013-01-24 21:59:00 -08008467 }
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008468 break;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008469 case NL80211_TDLS_TEARDOWN:
8470 case NL80211_TDLS_SETUP:
8471 case NL80211_TDLS_DISCOVERY_REQ:
8472 /* We don't support in-driver setup/teardown/discovery */
8473 return -ENOTSUPP;
8474 default:
8475 return -ENOTSUPP;
8476 }
8477 return 0;
8478}
Chilam NG571c65a2013-01-19 12:27:36 +05308479
8480int wlan_hdd_cfg80211_send_tdls_discover_req(struct wiphy *wiphy,
8481 struct net_device *dev, u8 *peer)
8482{
8483 hddLog(VOS_TRACE_LEVEL_INFO, "tdls send discover req: %x %x %x %x %x %x",
8484 peer[0], peer[1], peer[2], peer[3], peer[4], peer[5]);
8485
8486 return wlan_hdd_cfg80211_tdls_mgmt(wiphy, dev, peer,
8487 WLAN_TDLS_DISCOVERY_REQUEST, 1, 0, NULL, 0);
8488}
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008489#endif
8490
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308491#ifdef WLAN_FEATURE_GTK_OFFLOAD
8492/*
8493 * FUNCTION: wlan_hdd_cfg80211_update_replayCounterCallback
8494 * Callback rountine called upon receiving response for
8495 * get offload info
8496 */
8497void wlan_hdd_cfg80211_update_replayCounterCallback(void *callbackContext,
8498 tpSirGtkOffloadGetInfoRspParams pGtkOffloadGetInfoRsp)
8499{
8500
8501 hdd_adapter_t *pAdapter = (hdd_adapter_t *)callbackContext;
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308502 tANI_U8 tempReplayCounter[8];
8503 hdd_station_ctx_t *pHddStaCtx;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308504
8505 ENTER();
8506
8507 if (NULL == pAdapter)
8508 {
8509 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8510 "%s: HDD adapter is Null", __func__);
8511 return ;
8512 }
8513
8514 if (NULL == pGtkOffloadGetInfoRsp)
8515 {
8516 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8517 "%s: pGtkOffloadGetInfoRsp is Null", __func__);
8518 return ;
8519 }
8520
8521 if (VOS_STATUS_SUCCESS != pGtkOffloadGetInfoRsp->ulStatus)
8522 {
8523 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8524 "%s: wlan Failed to get replay counter value",
8525 __func__);
8526 return ;
8527 }
8528
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308529 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
8530 /* Update replay counter */
8531 pHddStaCtx->gtkOffloadReqParams.ullKeyReplayCounter =
8532 pGtkOffloadGetInfoRsp->ullKeyReplayCounter;
8533
8534 {
8535 /* changing from little to big endian since supplicant
8536 * works on big endian format
8537 */
8538 int i;
8539 tANI_U8 *p = (tANI_U8 *)&pGtkOffloadGetInfoRsp->ullKeyReplayCounter;
8540
8541 for (i = 0; i < 8; i++)
8542 {
8543 tempReplayCounter[7-i] = (tANI_U8)p[i];
8544 }
8545 }
8546
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308547 /* Update replay counter to NL */
8548 cfg80211_gtk_rekey_notify(pAdapter->dev, pGtkOffloadGetInfoRsp->bssId,
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308549 tempReplayCounter, GFP_KERNEL);
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308550}
8551
8552/*
8553 * FUNCTION: wlan_hdd_cfg80211_set_rekey_data
8554 * This function is used to offload GTK rekeying job to the firmware.
8555 */
8556int wlan_hdd_cfg80211_set_rekey_data(struct wiphy *wiphy, struct net_device *dev,
8557 struct cfg80211_gtk_rekey_data *data)
8558{
8559 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8560 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
8561 hdd_station_ctx_t *pHddStaCtx;
8562 tHalHandle hHal;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308563 int result;
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308564 tSirGtkOffloadParams hddGtkOffloadReqParams;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308565 eHalStatus status = eHAL_STATUS_FAILURE;
8566
8567 ENTER();
8568
8569 if (NULL == pAdapter)
8570 {
8571 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8572 "%s: HDD adapter is Null", __func__);
8573 return -ENODEV;
8574 }
8575
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308576 result = wlan_hdd_validate_context(pHddCtx);
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308577
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308578 if (0 != result)
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308579 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308580 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8581 "%s: HDD context is not valid", __func__);
8582 return result;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308583 }
8584
8585 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
8586 hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
8587 if (NULL == hHal)
8588 {
8589 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8590 "%s: HAL context is Null!!!", __func__);
8591 return -EAGAIN;
8592 }
8593
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308594 pHddStaCtx->gtkOffloadReqParams.ulFlags = GTK_OFFLOAD_ENABLE;
8595 memcpy(pHddStaCtx->gtkOffloadReqParams.aKCK, data->kck, NL80211_KCK_LEN);
8596 memcpy(pHddStaCtx->gtkOffloadReqParams.aKEK, data->kek, NL80211_KEK_LEN);
8597 memcpy(pHddStaCtx->gtkOffloadReqParams.bssId, &pHddStaCtx->conn_info.bssId,
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308598 WNI_CFG_BSSID_LEN);
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308599 {
8600 /* changing from big to little endian since driver
8601 * works on little endian format
8602 */
8603 tANI_U8 *p =
8604 (tANI_U8 *)&pHddStaCtx->gtkOffloadReqParams.ullKeyReplayCounter;
8605 int i;
8606
8607 for (i = 0; i < 8; i++)
8608 {
8609 p[7-i] = data->replay_ctr[i];
8610 }
8611 }
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308612
8613 if (TRUE == pHddCtx->hdd_wlan_suspended)
8614 {
8615 /* if wlan is suspended, enable GTK offload directly from here */
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308616 memcpy(&hddGtkOffloadReqParams, &pHddStaCtx->gtkOffloadReqParams,
8617 sizeof (tSirGtkOffloadParams));
8618 status = sme_SetGTKOffload(hHal, &hddGtkOffloadReqParams,
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308619 pAdapter->sessionId);
8620
8621 if (eHAL_STATUS_SUCCESS != status)
8622 {
8623 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8624 "%s: sme_SetGTKOffload failed, returned %d",
8625 __func__, status);
8626 return status;
8627 }
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308628 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8629 "%s: sme_SetGTKOffload successfull", __func__);
8630 }
8631 else
8632 {
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308633 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8634 "%s: wlan not suspended GTKOffload request is stored",
8635 __func__);
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308636 }
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308637
8638 return eHAL_STATUS_SUCCESS;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308639}
8640#endif /*WLAN_FEATURE_GTK_OFFLOAD*/
8641
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05308642/*
8643 * FUNCTION: wlan_hdd_cfg80211_set_mac_acl
8644 * This function is used to set access control policy
8645 */
8646static int wlan_hdd_cfg80211_set_mac_acl(struct wiphy *wiphy,
8647 struct net_device *dev, const struct cfg80211_acl_data *params)
8648{
8649 int i;
8650 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8651 hdd_hostapd_state_t *pHostapdState;
8652 tsap_Config_t *pConfig;
8653 v_CONTEXT_t pVosContext = NULL;
8654 hdd_context_t *pHddCtx;
8655 int status;
8656
8657 ENTER();
8658
8659 if (NULL == pAdapter)
8660 {
8661 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8662 "%s: HDD adapter is Null", __func__);
8663 return -ENODEV;
8664 }
8665
8666 if (NULL == params)
8667 {
8668 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8669 "%s: params is Null", __func__);
8670 return -EINVAL;
8671 }
8672
8673 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
8674 status = wlan_hdd_validate_context(pHddCtx);
8675
8676 if (0 != status)
8677 {
8678 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8679 "%s: HDD context is not valid", __func__);
8680 return status;
8681 }
8682
8683 pVosContext = pHddCtx->pvosContext;
8684 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
8685
8686 if (NULL == pHostapdState)
8687 {
8688 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8689 "%s: pHostapdState is Null", __func__);
8690 return -EINVAL;
8691 }
8692
8693 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,"acl policy: = %d"
8694 "no acl entries = %d", params->acl_policy, params->n_acl_entries);
8695
8696 if (WLAN_HDD_SOFTAP == pAdapter->device_mode)
8697 {
8698 pConfig = &pAdapter->sessionCtx.ap.sapConfig;
8699
8700 /* default value */
8701 pConfig->num_accept_mac = 0;
8702 pConfig->num_deny_mac = 0;
8703
8704 /**
8705 * access control policy
8706 * @NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED: Deny stations which are
8707 * listed in hostapd.deny file.
8708 * @NL80211_ACL_POLICY_DENY_UNLESS_LISTED: Allow stations which are
8709 * listed in hostapd.accept file.
8710 */
8711 if (NL80211_ACL_POLICY_DENY_UNLESS_LISTED == params->acl_policy)
8712 {
8713 pConfig->SapMacaddr_acl = eSAP_DENY_UNLESS_ACCEPTED;
8714 }
8715 else if (NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED == params->acl_policy)
8716 {
8717 pConfig->SapMacaddr_acl = eSAP_ACCEPT_UNLESS_DENIED;
8718 }
8719 else
8720 {
8721 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8722 "%s:Acl Policy : %d is not supported",
8723 __func__, params->acl_policy);
8724 return -ENOTSUPP;
8725 }
8726
8727 if (eSAP_DENY_UNLESS_ACCEPTED == pConfig->SapMacaddr_acl)
8728 {
8729 pConfig->num_accept_mac = params->n_acl_entries;
8730 for (i = 0; i < params->n_acl_entries; i++)
8731 {
8732 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8733 "** Add ACL MAC entry %i in WhiletList :"
8734 MAC_ADDRESS_STR, i,
8735 MAC_ADDR_ARRAY(params->mac_addrs[i].addr));
8736
8737 vos_mem_copy(&pConfig->accept_mac[i], params->mac_addrs[i].addr,
8738 sizeof(qcmacaddr));
8739 }
8740 }
8741 else if (eSAP_ACCEPT_UNLESS_DENIED == pConfig->SapMacaddr_acl)
8742 {
8743 pConfig->num_deny_mac = params->n_acl_entries;
8744 for (i = 0; i < params->n_acl_entries; i++)
8745 {
8746 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8747 "** Add ACL MAC entry %i in BlackList :"
8748 MAC_ADDRESS_STR, i,
8749 MAC_ADDR_ARRAY(params->mac_addrs[i].addr));
8750
8751 vos_mem_copy(&pConfig->deny_mac[i], params->mac_addrs[i].addr,
8752 sizeof(qcmacaddr));
8753 }
8754 }
8755
8756 if (VOS_STATUS_SUCCESS != WLANSAP_SetMacACL(pVosContext, pConfig))
8757 {
8758 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8759 "%s: SAP Set Mac Acl fail", __func__);
8760 return -EINVAL;
8761 }
8762 }
8763 else
8764 {
8765 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8766 "%s: Invalid device_mode = %d",
8767 __func__, pAdapter->device_mode);
8768 return -EINVAL;
8769 }
8770
8771 return 0;
8772}
8773
Leo Chang9056f462013-08-01 19:21:11 -07008774#ifdef WLAN_NL80211_TESTMODE
8775#ifdef FEATURE_WLAN_LPHB
Leo Changd9df8aa2013-09-26 13:32:26 -07008776void wlan_hdd_cfg80211_lphb_ind_handler
Leo Chang9056f462013-08-01 19:21:11 -07008777(
8778 void *pAdapter,
8779 void *indCont
8780)
8781{
Leo Changd9df8aa2013-09-26 13:32:26 -07008782 tSirLPHBInd *lphbInd;
8783 struct sk_buff *skb;
Leo Chang9056f462013-08-01 19:21:11 -07008784
8785 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Leo Changd9df8aa2013-09-26 13:32:26 -07008786 "LPHB indication arrived");
Leo Chang9056f462013-08-01 19:21:11 -07008787
8788 if (NULL == indCont)
8789 {
8790 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Leo Changd9df8aa2013-09-26 13:32:26 -07008791 "LPHB IND, invalid argument");
Leo Chang9056f462013-08-01 19:21:11 -07008792 return;
8793 }
8794
Leo Changd9df8aa2013-09-26 13:32:26 -07008795 lphbInd = (tSirLPHBInd *)indCont;
Leo Chang9056f462013-08-01 19:21:11 -07008796 skb = cfg80211_testmode_alloc_event_skb(
8797 ((hdd_adapter_t *)pAdapter)->wdev.wiphy,
Leo Changd9df8aa2013-09-26 13:32:26 -07008798 sizeof(tSirLPHBInd),
Leo Chang9056f462013-08-01 19:21:11 -07008799 GFP_ATOMIC);
8800 if (!skb)
8801 {
8802 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8803 "LPHB timeout, NL buffer alloc fail");
8804 return;
8805 }
8806
Leo Changac3ba772013-10-07 09:47:04 -07008807 if(nla_put_u32(skb, WLAN_HDD_TM_ATTR_CMD, WLAN_HDD_TM_CMD_WLAN_HB))
Leo Changd9df8aa2013-09-26 13:32:26 -07008808 {
8809 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8810 "WLAN_HDD_TM_ATTR_CMD put fail");
8811 goto nla_put_failure;
8812 }
Leo Changac3ba772013-10-07 09:47:04 -07008813 if(nla_put_u32(skb, WLAN_HDD_TM_ATTR_TYPE, lphbInd->protocolType))
Leo Changd9df8aa2013-09-26 13:32:26 -07008814 {
8815 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8816 "WLAN_HDD_TM_ATTR_TYPE put fail");
8817 goto nla_put_failure;
8818 }
Leo Changac3ba772013-10-07 09:47:04 -07008819 if(nla_put(skb, WLAN_HDD_TM_ATTR_DATA,
Leo Changd9df8aa2013-09-26 13:32:26 -07008820 sizeof(tSirLPHBInd), lphbInd))
8821 {
8822 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8823 "WLAN_HDD_TM_ATTR_DATA put fail");
8824 goto nla_put_failure;
8825 }
Leo Chang9056f462013-08-01 19:21:11 -07008826 cfg80211_testmode_event(skb, GFP_ATOMIC);
8827 return;
8828
8829nla_put_failure:
8830 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8831 "NLA Put fail");
8832 kfree_skb(skb);
8833
8834 return;
8835}
8836#endif /* FEATURE_WLAN_LPHB */
8837
8838static int wlan_hdd_cfg80211_testmode(struct wiphy *wiphy, void *data, int len)
8839{
8840 struct nlattr *tb[WLAN_HDD_TM_ATTR_MAX + 1];
8841 int err = 0;
8842#ifdef FEATURE_WLAN_LPHB
8843 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
Leo Changd9df8aa2013-09-26 13:32:26 -07008844 eHalStatus smeStatus;
Leo Chang9056f462013-08-01 19:21:11 -07008845#endif /* FEATURE_WLAN_LPHB */
8846
8847 err = nla_parse(tb, WLAN_HDD_TM_ATTR_MAX, data, len, wlan_hdd_tm_policy);
8848 if (err)
8849 {
8850 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8851 "%s Testmode INV ATTR", __func__);
8852 return err;
8853 }
8854
8855 if (!tb[WLAN_HDD_TM_ATTR_CMD])
8856 {
8857 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8858 "%s Testmode INV CMD", __func__);
8859 return -EINVAL;
8860 }
8861
8862 switch (nla_get_u32(tb[WLAN_HDD_TM_ATTR_CMD]))
8863 {
8864#ifdef FEATURE_WLAN_LPHB
8865 /* Low Power Heartbeat configuration request */
8866 case WLAN_HDD_TM_CMD_WLAN_HB:
8867 {
8868 int buf_len;
8869 void *buf;
8870 tSirLPHBReq *hb_params = NULL;
8871
8872 if (!tb[WLAN_HDD_TM_ATTR_DATA])
8873 {
8874 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8875 "%s Testmode INV DATA", __func__);
8876 return -EINVAL;
8877 }
8878
8879 buf = nla_data(tb[WLAN_HDD_TM_ATTR_DATA]);
8880 buf_len = nla_len(tb[WLAN_HDD_TM_ATTR_DATA]);
8881 hb_params = (tSirLPHBReq *)vos_mem_malloc(sizeof(tSirLPHBReq));
8882 if (NULL == hb_params)
8883 {
8884 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8885 "%s Request Buffer Alloc Fail", __func__);
8886 return -EINVAL;
8887 }
8888
8889 vos_mem_copy(hb_params, buf, buf_len);
Leo Changd9df8aa2013-09-26 13:32:26 -07008890 smeStatus = sme_LPHBConfigReq((tHalHandle)(pHddCtx->hHal),
8891 hb_params,
8892 wlan_hdd_cfg80211_lphb_ind_handler);
8893 if (eHAL_STATUS_SUCCESS != smeStatus)
Leo Chang9056f462013-08-01 19:21:11 -07008894 {
Leo Changd9df8aa2013-09-26 13:32:26 -07008895 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8896 "LPHB Config Fail, disable");
Leo Chang9056f462013-08-01 19:21:11 -07008897 vos_mem_free(hb_params);
8898 }
Leo Chang9056f462013-08-01 19:21:11 -07008899 return 0;
8900 }
8901#endif /* FEATURE_WLAN_LPHB */
8902 default:
8903 return -EOPNOTSUPP;
8904 }
8905
8906 return err;
8907}
8908#endif /* CONFIG_NL80211_TESTMODE */
8909
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05308910static int wlan_hdd_cfg80211_dump_survey(struct wiphy *wiphy,
8911 struct net_device *dev,
8912 int idx, struct survey_info *survey)
8913{
8914 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8915 hdd_context_t *pHddCtx;
Mihir Sheted9072e02013-08-21 17:02:29 +05308916 hdd_station_ctx_t *pHddStaCtx;
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05308917 tHalHandle halHandle;
Mihir Sheted9072e02013-08-21 17:02:29 +05308918 v_U32_t channel = 0, freq = 0; /* Initialization Required */
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05308919 v_S7_t snr,rssi;
8920 int status, i, j, filled = 0;
8921
8922 ENTER();
8923
8924
8925 if (NULL == pAdapter)
8926 {
8927 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8928 "%s: HDD adapter is Null", __func__);
8929 return -ENODEV;
8930 }
8931
8932 if (NULL == wiphy)
8933 {
8934 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8935 "%s: wiphy is Null", __func__);
8936 return -ENODEV;
8937 }
8938
8939 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
8940 status = wlan_hdd_validate_context(pHddCtx);
8941
8942 if (0 != status)
8943 {
8944 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8945 "%s: HDD context is not valid", __func__);
8946 return status;
8947 }
8948
Mihir Sheted9072e02013-08-21 17:02:29 +05308949 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
8950
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05308951 if (0 == pHddCtx->cfg_ini->fEnableSNRMonitoring ||
Mihir Sheted9072e02013-08-21 17:02:29 +05308952 0 != pAdapter->survey_idx ||
8953 eConnectionState_Associated != pHddStaCtx->conn_info.connState)
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05308954 {
8955 /* The survey dump ops when implemented completely is expected to
8956 * return a survey of all channels and the ops is called by the
8957 * kernel with incremental values of the argument 'idx' till it
8958 * returns -ENONET. But we can only support the survey for the
8959 * operating channel for now. survey_idx is used to track
8960 * that the ops is called only once and then return -ENONET for
8961 * the next iteration
8962 */
8963 pAdapter->survey_idx = 0;
8964 return -ENONET;
8965 }
8966
8967 halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
8968
8969 wlan_hdd_get_snr(pAdapter, &snr);
8970 wlan_hdd_get_rssi(pAdapter, &rssi);
8971
8972 sme_GetOperationChannel(halHandle, &channel, pAdapter->sessionId);
8973 hdd_wlan_get_freq(channel, &freq);
8974
8975
8976 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
8977 {
8978 if (NULL == wiphy->bands[i])
8979 {
8980 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
8981 "%s: wiphy->bands[i] is NULL, i = %d", __func__, i);
8982 continue;
8983 }
8984
8985 for (j = 0; j < wiphy->bands[i]->n_channels; j++)
8986 {
8987 struct ieee80211_supported_band *band = wiphy->bands[i];
8988
8989 if (band->channels[j].center_freq == (v_U16_t)freq)
8990 {
8991 survey->channel = &band->channels[j];
8992 /* The Rx BDs contain SNR values in dB for the received frames
8993 * while the supplicant expects noise. So we calculate and
8994 * return the value of noise (dBm)
8995 * SNR (dB) = RSSI (dBm) - NOISE (dBm)
8996 */
8997 survey->noise = rssi - snr;
8998 survey->filled = SURVEY_INFO_NOISE_DBM;
8999 filled = 1;
9000 }
9001 }
9002 }
9003
9004 if (filled)
9005 pAdapter->survey_idx = 1;
9006 else
9007 {
9008 pAdapter->survey_idx = 0;
9009 return -ENONET;
9010 }
9011
9012 return 0;
9013}
9014
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05309015/*
9016 * FUNCTION: wlan_hdd_cfg80211_resume_wlan
9017 * this is called when cfg80211 driver resume
9018 * driver updates latest sched_scan scan result(if any) to cfg80211 database
9019 */
9020int wlan_hdd_cfg80211_resume_wlan(struct wiphy *wiphy)
9021{
9022 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
9023 hdd_adapter_t *pAdapter;
9024 hdd_adapter_list_node_t *pAdapterNode, *pNext;
9025 VOS_STATUS status = VOS_STATUS_SUCCESS;
9026
9027 ENTER();
9028
9029 if ( NULL == pHddCtx )
9030 {
9031 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
9032 "%s: HddCtx validation failed", __func__);
9033 return 0;
9034 }
9035
9036 if (pHddCtx->isLogpInProgress)
9037 {
9038 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9039 "%s: LOGP in Progress. Ignore!!!", __func__);
9040 return 0;
9041 }
9042
9043 if (pHddCtx->isLoadUnloadInProgress)
9044 {
9045 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9046 "%s: Unloading/Loading in Progress. Ignore!!!", __func__);
9047 return 0;
9048 }
9049
9050 spin_lock(&pHddCtx->schedScan_lock);
9051 pHddCtx->isWiphySuspended = FALSE;
9052 if (TRUE != pHddCtx->isSchedScanUpdatePending)
9053 {
9054 spin_unlock(&pHddCtx->schedScan_lock);
9055 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9056 "%s: Return resume is not due to PNO indication", __func__);
9057 return 0;
9058 }
9059 // Reset flag to avoid updatating cfg80211 data old results again
9060 pHddCtx->isSchedScanUpdatePending = FALSE;
9061 spin_unlock(&pHddCtx->schedScan_lock);
9062
9063 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
9064
9065 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
9066 {
9067 pAdapter = pAdapterNode->pAdapter;
9068 if ( (NULL != pAdapter) &&
9069 (WLAN_HDD_INFRA_STATION == pAdapter->device_mode) )
9070 {
9071 if (0 != wlan_hdd_cfg80211_update_bss(pHddCtx->wiphy, pAdapter))
9072 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
9073 "%s: NO SCAN result", __func__);
9074 else
9075 cfg80211_sched_scan_results(pHddCtx->wiphy);
9076
9077 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9078 "%s : cfg80211 scan result database updated", __func__);
9079
9080 return 0;
9081
9082 }
9083 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
9084 pAdapterNode = pNext;
9085 }
9086
9087 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9088 "%s: Failed to find Adapter", __func__);
9089 return 0;
9090}
9091
9092/*
9093 * FUNCTION: wlan_hdd_cfg80211_suspend_wlan
9094 * this is called when cfg80211 driver suspends
9095 */
9096int wlan_hdd_cfg80211_suspend_wlan(struct wiphy *wiphy,
9097 struct cfg80211_wowlan *wow)
9098{
9099 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
9100
9101 ENTER();
9102 if (NULL == pHddCtx)
9103 {
9104 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
9105 "%s: HddCtx validation failed", __func__);
9106 return 0;
9107 }
9108
9109 pHddCtx->isWiphySuspended = TRUE;
9110
9111 EXIT();
9112
9113 return 0;
9114}
9115
Jeff Johnson295189b2012-06-20 16:38:30 -07009116/* cfg80211_ops */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05309117static struct cfg80211_ops wlan_hdd_cfg80211_ops =
Jeff Johnson295189b2012-06-20 16:38:30 -07009118{
9119 .add_virtual_intf = wlan_hdd_add_virtual_intf,
9120 .del_virtual_intf = wlan_hdd_del_virtual_intf,
9121 .change_virtual_intf = wlan_hdd_cfg80211_change_iface,
9122 .change_station = wlan_hdd_change_station,
9123#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
9124 .add_beacon = wlan_hdd_cfg80211_add_beacon,
9125 .del_beacon = wlan_hdd_cfg80211_del_beacon,
9126 .set_beacon = wlan_hdd_cfg80211_set_beacon,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07009127#else
9128 .start_ap = wlan_hdd_cfg80211_start_ap,
9129 .change_beacon = wlan_hdd_cfg80211_change_beacon,
9130 .stop_ap = wlan_hdd_cfg80211_stop_ap,
Jeff Johnson295189b2012-06-20 16:38:30 -07009131#endif
9132 .change_bss = wlan_hdd_cfg80211_change_bss,
9133 .add_key = wlan_hdd_cfg80211_add_key,
9134 .get_key = wlan_hdd_cfg80211_get_key,
9135 .del_key = wlan_hdd_cfg80211_del_key,
9136 .set_default_key = wlan_hdd_cfg80211_set_default_key,
Jeff Johnson3bbe4bf2013-01-18 17:05:29 -08009137#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07009138 .set_channel = wlan_hdd_cfg80211_set_channel,
Jeff Johnson3bbe4bf2013-01-18 17:05:29 -08009139#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07009140 .scan = wlan_hdd_cfg80211_scan,
9141 .connect = wlan_hdd_cfg80211_connect,
9142 .disconnect = wlan_hdd_cfg80211_disconnect,
9143 .join_ibss = wlan_hdd_cfg80211_join_ibss,
9144 .leave_ibss = wlan_hdd_cfg80211_leave_ibss,
9145 .set_wiphy_params = wlan_hdd_cfg80211_set_wiphy_params,
9146 .set_tx_power = wlan_hdd_cfg80211_set_txpower,
9147 .get_tx_power = wlan_hdd_cfg80211_get_txpower,
Jeff Johnson295189b2012-06-20 16:38:30 -07009148 .remain_on_channel = wlan_hdd_cfg80211_remain_on_channel,
9149 .cancel_remain_on_channel = wlan_hdd_cfg80211_cancel_remain_on_channel,
9150 .mgmt_tx = wlan_hdd_action,
9151#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
9152 .mgmt_tx_cancel_wait = wlan_hdd_cfg80211_mgmt_tx_cancel_wait,
9153 .set_default_mgmt_key = wlan_hdd_set_default_mgmt_key,
9154 .set_txq_params = wlan_hdd_set_txq_params,
9155#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07009156 .get_station = wlan_hdd_cfg80211_get_station,
9157 .set_power_mgmt = wlan_hdd_cfg80211_set_power_mgmt,
9158 .del_station = wlan_hdd_cfg80211_del_station,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07009159 .add_station = wlan_hdd_cfg80211_add_station,
9160#ifdef FEATURE_WLAN_LFR
9161 .set_pmksa = wlan_hdd_cfg80211_set_pmksa,
9162 .del_pmksa = wlan_hdd_cfg80211_del_pmksa,
9163 .flush_pmksa = wlan_hdd_cfg80211_flush_pmksa,
9164#endif
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07009165#if defined(WLAN_FEATURE_VOWIFI_11R) && defined(KERNEL_SUPPORT_11R_CFG80211)
9166 .update_ft_ies = wlan_hdd_cfg80211_update_ft_ies,
9167#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -08009168#ifdef FEATURE_WLAN_TDLS
9169 .tdls_mgmt = wlan_hdd_cfg80211_tdls_mgmt,
9170 .tdls_oper = wlan_hdd_cfg80211_tdls_oper,
9171#endif
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309172#ifdef WLAN_FEATURE_GTK_OFFLOAD
9173 .set_rekey_data = wlan_hdd_cfg80211_set_rekey_data,
9174#endif /* WLAN_FEATURE_GTK_OFFLOAD */
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05309175#ifdef FEATURE_WLAN_SCAN_PNO
9176 .sched_scan_start = wlan_hdd_cfg80211_sched_scan_start,
9177 .sched_scan_stop = wlan_hdd_cfg80211_sched_scan_stop,
9178#endif /*FEATURE_WLAN_SCAN_PNO */
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05309179 .resume = wlan_hdd_cfg80211_resume_wlan,
9180 .suspend = wlan_hdd_cfg80211_suspend_wlan,
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05309181 .set_mac_acl = wlan_hdd_cfg80211_set_mac_acl,
Leo Chang9056f462013-08-01 19:21:11 -07009182#ifdef WLAN_NL80211_TESTMODE
9183 .testmode_cmd = wlan_hdd_cfg80211_testmode,
9184#endif
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05309185 .dump_survey = wlan_hdd_cfg80211_dump_survey,
Jeff Johnson295189b2012-06-20 16:38:30 -07009186};
9187