blob: 729033e4a58acb706651c5a6c3c55fb12a5392da [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302 * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
3 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20*/
Jeff Johnson295189b2012-06-20 16:38:30 -070021
22/**========================================================================
23
24 \file wlan_hdd_cfg80211.c
25
26 \brief WLAN Host Device Driver implementation
27
Gopichand Nakkala747461f2013-04-24 19:24:45 +053028 Copyright 2008 (c) Qualcomm Technologies, Inc. All Rights Reserved.
Jeff Johnson295189b2012-06-20 16:38:30 -070029
Gopichand Nakkala747461f2013-04-24 19:24:45 +053030 Qualcomm Technologies Confidential and Proprietary.
Jeff Johnson295189b2012-06-20 16:38:30 -070031
32 ========================================================================*/
33
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -070034/**=========================================================================
Jeff Johnson295189b2012-06-20 16:38:30 -070035
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -070036 EDIT HISTORY FOR FILE
Jeff Johnson295189b2012-06-20 16:38:30 -070037
38
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -070039 This section contains comments describing changes made to the module.
40 Notice that changes are listed in reverse chronological order.
Jeff Johnson295189b2012-06-20 16:38:30 -070041
42
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -070043 $Header:$ $DateTime: $ $Author: $
Jeff Johnson295189b2012-06-20 16:38:30 -070044
45
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -070046 when who what, where, why
Jeff Johnson295189b2012-06-20 16:38:30 -070047 -------- --- --------------------------------------------------------
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -070048 21/12/09 Ashwani Created module.
Jeff Johnson295189b2012-06-20 16:38:30 -070049
50 07/06/10 Kumar Deepak Implemented cfg80211 callbacks for ANDROID
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -070051 Ganesh K
Jeff Johnson295189b2012-06-20 16:38:30 -070052 ==========================================================================*/
53
Jeff Johnson295189b2012-06-20 16:38:30 -070054
55#include <linux/version.h>
56#include <linux/module.h>
57#include <linux/kernel.h>
58#include <linux/init.h>
59#include <linux/wireless.h>
60#include <wlan_hdd_includes.h>
61#include <net/arp.h>
62#include <net/cfg80211.h>
63#include <linux/wireless.h>
64#include <wlan_hdd_wowl.h>
65#include <aniGlobal.h>
66#include "ccmApi.h"
67#include "sirParams.h"
68#include "dot11f.h"
69#include "wlan_hdd_assoc.h"
70#include "wlan_hdd_wext.h"
71#include "sme_Api.h"
72#include "wlan_hdd_p2p.h"
73#include "wlan_hdd_cfg80211.h"
74#include "wlan_hdd_hostapd.h"
75#include "sapInternal.h"
76#include "wlan_hdd_softap_tx_rx.h"
77#include "wlan_hdd_main.h"
Madan Mohan Koyyalamudid5acbf52012-11-28 01:45:08 +053078#include "wlan_hdd_assoc.h"
Gopichand Nakkala20c4c042013-04-19 22:08:55 +053079#include "wlan_hdd_power.h"
Jeff Johnson295189b2012-06-20 16:38:30 -070080#ifdef WLAN_BTAMP_FEATURE
81#include "bap_hdd_misc.h"
82#endif
83#include <qc_sap_ioctl.h>
Mohit Khanna698ba2a2012-12-04 15:08:18 -080084#ifdef FEATURE_WLAN_TDLS
85#include "wlan_hdd_tdls.h"
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +053086#include "wlan_hdd_wmm.h"
Madan Mohan Koyyalamudice419872013-09-13 19:36:52 +053087#include "wlan_qct_wda.h"
Mohit Khanna698ba2a2012-12-04 15:08:18 -080088#endif
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +053089#include "wlan_nv.h"
Leo Chang6fe1f922013-06-07 19:21:24 -070090#include "wlan_hdd_dev_pwr.h"
Jeff Johnson295189b2012-06-20 16:38:30 -070091
92#define g_mode_rates_size (12)
93#define a_mode_rates_size (8)
94#define FREQ_BASE_80211G (2407)
95#define FREQ_BAND_DIFF_80211G (5)
Jeff Johnson04dd8a82012-06-29 20:41:40 -070096#define MAX_SCAN_SSID 9
Jeff Johnson295189b2012-06-20 16:38:30 -070097#define GET_IE_LEN_IN_BSS_DESC(lenInBss) ( lenInBss + sizeof(lenInBss) - \
98 ((int) OFFSET_OF( tSirBssDescription, ieFields)))
99
100#define HDD2GHZCHAN(freq, chan, flag) { \
101 .band = IEEE80211_BAND_2GHZ, \
102 .center_freq = (freq), \
103 .hw_value = (chan),\
104 .flags = (flag), \
105 .max_antenna_gain = 0 ,\
106 .max_power = 30, \
107}
108
109#define HDD5GHZCHAN(freq, chan, flag) { \
110 .band = IEEE80211_BAND_5GHZ, \
111 .center_freq = (freq), \
112 .hw_value = (chan),\
113 .flags = (flag), \
114 .max_antenna_gain = 0 ,\
115 .max_power = 30, \
116}
117
118#define HDD_G_MODE_RATETAB(rate, rate_id, flag)\
119{\
120 .bitrate = rate, \
121 .hw_value = rate_id, \
122 .flags = flag, \
123}
124
Lee Hoonkic1262f22013-01-24 21:59:00 -0800125#ifndef WLAN_FEATURE_TDLS_DEBUG
126#define TDLS_LOG_LEVEL VOS_TRACE_LEVEL_INFO
127#else
128#define TDLS_LOG_LEVEL VOS_TRACE_LEVEL_ERROR
129#endif
130
Gopichand Nakkala356fb102013-03-06 12:34:04 +0530131#ifdef WLAN_FEATURE_VOWIFI_11R
132#define WLAN_AKM_SUITE_FT_8021X 0x000FAC03
133#define WLAN_AKM_SUITE_FT_PSK 0x000FAC04
134#endif
135
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530136static const u32 hdd_cipher_suites[] =
Jeff Johnson295189b2012-06-20 16:38:30 -0700137{
138 WLAN_CIPHER_SUITE_WEP40,
139 WLAN_CIPHER_SUITE_WEP104,
140 WLAN_CIPHER_SUITE_TKIP,
141#ifdef FEATURE_WLAN_CCX
142#define WLAN_CIPHER_SUITE_KRK 0x004096ff /* use for KRK */
143 WLAN_CIPHER_SUITE_KRK,
144 WLAN_CIPHER_SUITE_CCMP,
145#else
146 WLAN_CIPHER_SUITE_CCMP,
147#endif
148#ifdef FEATURE_WLAN_WAPI
149 WLAN_CIPHER_SUITE_SMS4,
150#endif
Chet Lanctot186b5732013-03-18 10:26:30 -0700151#ifdef WLAN_FEATURE_11W
152 WLAN_CIPHER_SUITE_AES_CMAC,
153#endif
Jeff Johnson295189b2012-06-20 16:38:30 -0700154};
155
156static inline int is_broadcast_ether_addr(const u8 *addr)
157{
158 return ((addr[0] == 0xff) && (addr[1] == 0xff) && (addr[2] == 0xff) &&
159 (addr[3] == 0xff) && (addr[4] == 0xff) && (addr[5] == 0xff));
160}
161
162static struct ieee80211_channel hdd_channels_2_4_GHZ[] =
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530163{
Jeff Johnson295189b2012-06-20 16:38:30 -0700164 HDD2GHZCHAN(2412, 1, 0) ,
165 HDD2GHZCHAN(2417, 2, 0) ,
166 HDD2GHZCHAN(2422, 3, 0) ,
167 HDD2GHZCHAN(2427, 4, 0) ,
168 HDD2GHZCHAN(2432, 5, 0) ,
169 HDD2GHZCHAN(2437, 6, 0) ,
170 HDD2GHZCHAN(2442, 7, 0) ,
171 HDD2GHZCHAN(2447, 8, 0) ,
172 HDD2GHZCHAN(2452, 9, 0) ,
173 HDD2GHZCHAN(2457, 10, 0) ,
174 HDD2GHZCHAN(2462, 11, 0) ,
175 HDD2GHZCHAN(2467, 12, 0) ,
176 HDD2GHZCHAN(2472, 13, 0) ,
177 HDD2GHZCHAN(2484, 14, 0) ,
178};
179
Jeff Johnson295189b2012-06-20 16:38:30 -0700180static struct ieee80211_channel hdd_social_channels_2_4_GHZ[] =
181{
182 HDD2GHZCHAN(2412, 1, 0) ,
183 HDD2GHZCHAN(2437, 6, 0) ,
184 HDD2GHZCHAN(2462, 11, 0) ,
185};
Jeff Johnson295189b2012-06-20 16:38:30 -0700186
187static struct ieee80211_channel hdd_channels_5_GHZ[] =
188{
Madan Mohan Koyyalamudic3a240c2012-09-28 15:34:08 -0700189 HDD5GHZCHAN(4920, 240, 0) ,
190 HDD5GHZCHAN(4940, 244, 0) ,
191 HDD5GHZCHAN(4960, 248, 0) ,
192 HDD5GHZCHAN(4980, 252, 0) ,
193 HDD5GHZCHAN(5040, 208, 0) ,
194 HDD5GHZCHAN(5060, 212, 0) ,
195 HDD5GHZCHAN(5080, 216, 0) ,
Jeff Johnson295189b2012-06-20 16:38:30 -0700196 HDD5GHZCHAN(5180, 36, 0) ,
197 HDD5GHZCHAN(5200, 40, 0) ,
198 HDD5GHZCHAN(5220, 44, 0) ,
199 HDD5GHZCHAN(5240, 48, 0) ,
200 HDD5GHZCHAN(5260, 52, 0) ,
201 HDD5GHZCHAN(5280, 56, 0) ,
202 HDD5GHZCHAN(5300, 60, 0) ,
203 HDD5GHZCHAN(5320, 64, 0) ,
204 HDD5GHZCHAN(5500,100, 0) ,
205 HDD5GHZCHAN(5520,104, 0) ,
206 HDD5GHZCHAN(5540,108, 0) ,
207 HDD5GHZCHAN(5560,112, 0) ,
208 HDD5GHZCHAN(5580,116, 0) ,
209 HDD5GHZCHAN(5600,120, 0) ,
210 HDD5GHZCHAN(5620,124, 0) ,
211 HDD5GHZCHAN(5640,128, 0) ,
212 HDD5GHZCHAN(5660,132, 0) ,
213 HDD5GHZCHAN(5680,136, 0) ,
214 HDD5GHZCHAN(5700,140, 0) ,
215 HDD5GHZCHAN(5745,149, 0) ,
216 HDD5GHZCHAN(5765,153, 0) ,
217 HDD5GHZCHAN(5785,157, 0) ,
218 HDD5GHZCHAN(5805,161, 0) ,
219 HDD5GHZCHAN(5825,165, 0) ,
220};
221
222static struct ieee80211_rate g_mode_rates[] =
223{
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530224 HDD_G_MODE_RATETAB(10, 0x1, 0),
225 HDD_G_MODE_RATETAB(20, 0x2, 0),
226 HDD_G_MODE_RATETAB(55, 0x4, 0),
227 HDD_G_MODE_RATETAB(110, 0x8, 0),
228 HDD_G_MODE_RATETAB(60, 0x10, 0),
229 HDD_G_MODE_RATETAB(90, 0x20, 0),
230 HDD_G_MODE_RATETAB(120, 0x40, 0),
231 HDD_G_MODE_RATETAB(180, 0x80, 0),
232 HDD_G_MODE_RATETAB(240, 0x100, 0),
233 HDD_G_MODE_RATETAB(360, 0x200, 0),
234 HDD_G_MODE_RATETAB(480, 0x400, 0),
Jeff Johnson295189b2012-06-20 16:38:30 -0700235 HDD_G_MODE_RATETAB(540, 0x800, 0),
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530236};
Jeff Johnson295189b2012-06-20 16:38:30 -0700237
238static struct ieee80211_rate a_mode_rates[] =
239{
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530240 HDD_G_MODE_RATETAB(60, 0x10, 0),
241 HDD_G_MODE_RATETAB(90, 0x20, 0),
242 HDD_G_MODE_RATETAB(120, 0x40, 0),
243 HDD_G_MODE_RATETAB(180, 0x80, 0),
244 HDD_G_MODE_RATETAB(240, 0x100, 0),
245 HDD_G_MODE_RATETAB(360, 0x200, 0),
246 HDD_G_MODE_RATETAB(480, 0x400, 0),
Jeff Johnson295189b2012-06-20 16:38:30 -0700247 HDD_G_MODE_RATETAB(540, 0x800, 0),
248};
249
250static struct ieee80211_supported_band wlan_hdd_band_2_4_GHZ =
251{
252 .channels = hdd_channels_2_4_GHZ,
253 .n_channels = ARRAY_SIZE(hdd_channels_2_4_GHZ),
254 .band = IEEE80211_BAND_2GHZ,
255 .bitrates = g_mode_rates,
256 .n_bitrates = g_mode_rates_size,
257 .ht_cap.ht_supported = 1,
258 .ht_cap.cap = IEEE80211_HT_CAP_SGI_20
259 | IEEE80211_HT_CAP_GRN_FLD
260 | IEEE80211_HT_CAP_DSSSCCK40
261 | IEEE80211_HT_CAP_LSIG_TXOP_PROT,
262 .ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
263 .ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_16,
264 .ht_cap.mcs.rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
265 .ht_cap.mcs.rx_highest = cpu_to_le16( 72 ),
266 .ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED,
267};
268
Jeff Johnson295189b2012-06-20 16:38:30 -0700269static struct ieee80211_supported_band wlan_hdd_band_p2p_2_4_GHZ =
270{
271 .channels = hdd_social_channels_2_4_GHZ,
272 .n_channels = ARRAY_SIZE(hdd_social_channels_2_4_GHZ),
273 .band = IEEE80211_BAND_2GHZ,
274 .bitrates = g_mode_rates,
275 .n_bitrates = g_mode_rates_size,
276 .ht_cap.ht_supported = 1,
277 .ht_cap.cap = IEEE80211_HT_CAP_SGI_20
278 | IEEE80211_HT_CAP_GRN_FLD
279 | IEEE80211_HT_CAP_DSSSCCK40
280 | IEEE80211_HT_CAP_LSIG_TXOP_PROT,
281 .ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
282 .ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_16,
283 .ht_cap.mcs.rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
284 .ht_cap.mcs.rx_highest = cpu_to_le16( 72 ),
285 .ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED,
286};
Jeff Johnson295189b2012-06-20 16:38:30 -0700287
288static struct ieee80211_supported_band wlan_hdd_band_5_GHZ =
289{
290 .channels = hdd_channels_5_GHZ,
291 .n_channels = ARRAY_SIZE(hdd_channels_5_GHZ),
292 .band = IEEE80211_BAND_5GHZ,
293 .bitrates = a_mode_rates,
294 .n_bitrates = a_mode_rates_size,
295 .ht_cap.ht_supported = 1,
296 .ht_cap.cap = IEEE80211_HT_CAP_SGI_20
297 | IEEE80211_HT_CAP_GRN_FLD
298 | IEEE80211_HT_CAP_DSSSCCK40
299 | IEEE80211_HT_CAP_LSIG_TXOP_PROT
300 | IEEE80211_HT_CAP_SGI_40
301 | IEEE80211_HT_CAP_SUP_WIDTH_20_40,
302 .ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
303 .ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_16,
304 .ht_cap.mcs.rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
305 .ht_cap.mcs.rx_highest = cpu_to_le16( 72 ),
306 .ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED,
307};
308
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530309/* This structure contain information what kind of frame are expected in
Jeff Johnson295189b2012-06-20 16:38:30 -0700310 TX/RX direction for each kind of interface */
311static const struct ieee80211_txrx_stypes
312wlan_hdd_txrx_stypes[NUM_NL80211_IFTYPES] = {
313 [NL80211_IFTYPE_STATION] = {
314 .tx = 0xffff,
315 .rx = BIT(SIR_MAC_MGMT_ACTION) |
316 BIT(SIR_MAC_MGMT_PROBE_REQ),
317 },
318 [NL80211_IFTYPE_AP] = {
319 .tx = 0xffff,
320 .rx = BIT(SIR_MAC_MGMT_ASSOC_REQ) |
321 BIT(SIR_MAC_MGMT_REASSOC_REQ) |
322 BIT(SIR_MAC_MGMT_PROBE_REQ) |
323 BIT(SIR_MAC_MGMT_DISASSOC) |
324 BIT(SIR_MAC_MGMT_AUTH) |
325 BIT(SIR_MAC_MGMT_DEAUTH) |
326 BIT(SIR_MAC_MGMT_ACTION),
327 },
Jeff Johnsonbc006202013-04-29 14:05:30 -0700328 [NL80211_IFTYPE_ADHOC] = {
329 .tx = 0xffff,
330 .rx = BIT(SIR_MAC_MGMT_ASSOC_REQ) |
331 BIT(SIR_MAC_MGMT_REASSOC_REQ) |
332 BIT(SIR_MAC_MGMT_PROBE_REQ) |
333 BIT(SIR_MAC_MGMT_DISASSOC) |
334 BIT(SIR_MAC_MGMT_AUTH) |
335 BIT(SIR_MAC_MGMT_DEAUTH) |
336 BIT(SIR_MAC_MGMT_ACTION),
337 },
Jeff Johnson295189b2012-06-20 16:38:30 -0700338 [NL80211_IFTYPE_P2P_CLIENT] = {
339 .tx = 0xffff,
340 .rx = BIT(SIR_MAC_MGMT_ACTION) |
341 BIT(SIR_MAC_MGMT_PROBE_REQ),
342 },
343 [NL80211_IFTYPE_P2P_GO] = {
344 /* This is also same as for SoftAP */
345 .tx = 0xffff,
346 .rx = BIT(SIR_MAC_MGMT_ASSOC_REQ) |
347 BIT(SIR_MAC_MGMT_REASSOC_REQ) |
348 BIT(SIR_MAC_MGMT_PROBE_REQ) |
349 BIT(SIR_MAC_MGMT_DISASSOC) |
350 BIT(SIR_MAC_MGMT_AUTH) |
351 BIT(SIR_MAC_MGMT_DEAUTH) |
352 BIT(SIR_MAC_MGMT_ACTION),
353 },
Jeff Johnson295189b2012-06-20 16:38:30 -0700354};
355
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800356#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800357static const struct ieee80211_iface_limit
358wlan_hdd_iface_limit[] = {
359 {
Sunil Ravia72c3992013-01-31 06:12:22 -0800360 /* max = 3 ; Our driver create two interfaces during driver init
361 * wlan0 and p2p0 interfaces. p2p0 is considered as station
362 * interface until a group is formed. In JB architecture, once the
363 * group is formed, interface type of p2p0 is changed to P2P GO or
364 * Client.
365 * When supplicant remove the group, it first issue a set interface
366 * cmd to change the mode back to Station. In JB this works fine as
367 * we advertize two station type interface during driver init.
368 * Some vendors create separate interface for P2P GO/Client,
369 * after group formation(Third one). But while group remove
370 * supplicant first tries to change the mode(3rd interface) to STATION
371 * But as we advertized only two sta type interfaces nl80211 was
372 * returning error for the third one which was leading to failure in
373 * delete interface. Ideally while removing the group, supplicant
374 * should not try to change the 3rd interface mode to Station type.
375 * Till we get a fix in wpa_supplicant, we advertize max STA
376 * interface type to 3
377 */
378 .max = 3,
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800379 .types = BIT(NL80211_IFTYPE_STATION),
380 },
381 {
382 .max = 1,
Jeff Johnsonbc006202013-04-29 14:05:30 -0700383 .types = BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_AP),
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800384 },
385 {
386 .max = 1,
387 .types = BIT(NL80211_IFTYPE_P2P_GO) |
388 BIT(NL80211_IFTYPE_P2P_CLIENT),
389 },
390};
391
392/* By default, only single channel concurrency is allowed */
393static struct ieee80211_iface_combination
394wlan_hdd_iface_combination = {
395 .limits = wlan_hdd_iface_limit,
396 .num_different_channels = 1,
Sunil Ravia72c3992013-01-31 06:12:22 -0800397 /*
398 * max = WLAN_MAX_INTERFACES ; JellyBean architecture creates wlan0
399 * and p2p0 interfaces during driver init
400 * Some vendors create separate interface for P2P operations.
401 * wlan0: STA interface
402 * p2p0: P2P Device interface, action frames goes
403 * through this interface.
404 * p2p-xx: P2P interface, After GO negotiation this interface is
405 * created for p2p operations(GO/CLIENT interface).
406 */
407 .max_interfaces = WLAN_MAX_INTERFACES,
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800408 .n_limits = ARRAY_SIZE(wlan_hdd_iface_limit),
409 .beacon_int_infra_match = false,
410};
411#endif
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800412
Jeff Johnson295189b2012-06-20 16:38:30 -0700413static struct cfg80211_ops wlan_hdd_cfg80211_ops;
414
415/* Data rate 100KBPS based on IE Index */
416struct index_data_rate_type
417{
418 v_U8_t beacon_rate_index;
419 v_U16_t supported_rate[4];
420};
421
422/* 11B, 11G Rate table include Basic rate and Extended rate
423 The IDX field is the rate index
424 The HI field is the rate when RSSI is strong or being ignored
425 (in this case we report actual rate)
426 The MID field is the rate when RSSI is moderate
427 (in this case we cap 11b rates at 5.5 and 11g rates at 24)
428 The LO field is the rate when RSSI is low
429 (in this case we don't report rates, actual current rate used)
430 */
431static const struct
432{
433 v_U8_t beacon_rate_index;
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -0700434 v_U16_t supported_rate[4];
Jeff Johnson295189b2012-06-20 16:38:30 -0700435} supported_data_rate[] =
436{
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -0700437/* IDX HI HM LM LO (RSSI-based index */
438 {2, { 10, 10, 10, 0}},
439 {4, { 20, 20, 10, 0}},
440 {11, { 55, 20, 10, 0}},
441 {12, { 60, 55, 20, 0}},
442 {18, { 90, 55, 20, 0}},
443 {22, {110, 55, 20, 0}},
444 {24, {120, 90, 60, 0}},
445 {36, {180, 120, 60, 0}},
446 {44, {220, 180, 60, 0}},
447 {48, {240, 180, 90, 0}},
448 {66, {330, 180, 90, 0}},
449 {72, {360, 240, 90, 0}},
450 {96, {480, 240, 120, 0}},
451 {108, {540, 240, 120, 0}}
Jeff Johnson295189b2012-06-20 16:38:30 -0700452};
453
454/* MCS Based rate table */
455static struct index_data_rate_type supported_mcs_rate[] =
456{
457/* MCS L20 L40 S20 S40 */
458 {0, {65, 135, 72, 150}},
459 {1, {130, 270, 144, 300}},
460 {2, {195, 405, 217, 450}},
461 {3, {260, 540, 289, 600}},
462 {4, {390, 810, 433, 900}},
463 {5, {520, 1080, 578, 1200}},
464 {6, {585, 1215, 650, 1350}},
465 {7, {650, 1350, 722, 1500}}
466};
467
Leo Chang6f8870f2013-03-26 18:11:36 -0700468#ifdef WLAN_FEATURE_11AC
469
Gopichand Nakkala4c705372013-04-24 13:20:33 +0530470#define DATA_RATE_11AC_MCS_MASK 0x03
Leo Chang6f8870f2013-03-26 18:11:36 -0700471
472struct index_vht_data_rate_type
473{
474 v_U8_t beacon_rate_index;
Gopichand Nakkala4c705372013-04-24 13:20:33 +0530475 v_U16_t supported_VHT80_rate[2];
476 v_U16_t supported_VHT40_rate[2];
477 v_U16_t supported_VHT20_rate[2];
Leo Chang6f8870f2013-03-26 18:11:36 -0700478};
479
480typedef enum
481{
482 DATA_RATE_11AC_MAX_MCS_7,
483 DATA_RATE_11AC_MAX_MCS_8,
484 DATA_RATE_11AC_MAX_MCS_9,
485 DATA_RATE_11AC_MAX_MCS_NA
486} eDataRate11ACMaxMcs;
487
488/* MCS Based VHT rate table */
489static struct index_vht_data_rate_type supported_vht_mcs_rate[] =
490{
Gopichand Nakkala4c705372013-04-24 13:20:33 +0530491/* MCS L80 S80 L40 S40 L20 S40*/
492 {0, {293, 325}, {135, 150}, {65, 72}},
493 {1, {585, 650}, {270, 300}, {130, 144}},
494 {2, {878, 975}, {405, 450}, {195, 217}},
495 {3, {1170, 1300}, {540, 600}, {260, 289}},
496 {4, {1755, 1950}, {810, 900}, {390, 433}},
497 {5, {2340, 2600}, {1080, 1200}, {520, 578}},
498 {6, {2633, 2925}, {1215, 1350}, {585, 650}},
499 {7, {2925, 3250}, {1350, 1500}, {650, 722}},
500 {8, {3510, 3900}, {1620, 1800}, {780, 867}},
501 {9, {3900, 4333}, {1800, 2000}, {780, 867}}
Leo Chang6f8870f2013-03-26 18:11:36 -0700502};
503#endif /* WLAN_FEATURE_11AC */
504
Jeff Johnson295189b2012-06-20 16:38:30 -0700505extern struct net_device_ops net_ops_struct;
506
Leo Chang9056f462013-08-01 19:21:11 -0700507#ifdef WLAN_NL80211_TESTMODE
508enum wlan_hdd_tm_attr
509{
510 WLAN_HDD_TM_ATTR_INVALID = 0,
511 WLAN_HDD_TM_ATTR_CMD = 1,
512 WLAN_HDD_TM_ATTR_DATA = 2,
513 WLAN_HDD_TM_ATTR_TYPE = 3,
514 /* keep last */
515 WLAN_HDD_TM_ATTR_AFTER_LAST,
516 WLAN_HDD_TM_ATTR_MAX = WLAN_HDD_TM_ATTR_AFTER_LAST - 1,
517};
518
519enum wlan_hdd_tm_cmd
520{
521 WLAN_HDD_TM_CMD_WLAN_HB = 1,
522};
523
524#define WLAN_HDD_TM_DATA_MAX_LEN 5000
525
526static const struct nla_policy wlan_hdd_tm_policy[WLAN_HDD_TM_ATTR_MAX + 1] =
527{
528 [WLAN_HDD_TM_ATTR_CMD] = { .type = NLA_U32 },
529 [WLAN_HDD_TM_ATTR_DATA] = { .type = NLA_BINARY,
530 .len = WLAN_HDD_TM_DATA_MAX_LEN },
531};
532#endif /* WLAN_NL80211_TESTMODE */
533
Jeff Johnson295189b2012-06-20 16:38:30 -0700534/*
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530535 * FUNCTION: wlan_hdd_cfg80211_wiphy_alloc
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530536 * This function is called by hdd_wlan_startup()
537 * during initialization.
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530538 * This function is used to allocate wiphy structure.
Jeff Johnson295189b2012-06-20 16:38:30 -0700539 */
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530540struct wiphy *wlan_hdd_cfg80211_wiphy_alloc(int priv_size)
Jeff Johnson295189b2012-06-20 16:38:30 -0700541{
542 struct wiphy *wiphy;
543 ENTER();
544
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530545 /*
546 * Create wiphy device
Jeff Johnson295189b2012-06-20 16:38:30 -0700547 */
548 wiphy = wiphy_new(&wlan_hdd_cfg80211_ops, priv_size);
549
550 if (!wiphy)
551 {
552 /* Print error and jump into err label and free the memory */
553 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: wiphy init failed", __func__);
554 return NULL;
555 }
556
557 return wiphy;
558}
559
560/*
561 * FUNCTION: wlan_hdd_cfg80211_update_band
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530562 * This function is called from the supplicant through a
Jeff Johnson295189b2012-06-20 16:38:30 -0700563 * private ioctl to change the band value
564 */
565int wlan_hdd_cfg80211_update_band(struct wiphy *wiphy, eCsrBand eBand)
566{
Gopichand Nakkala1f7a64f2013-04-01 18:37:17 +0530567 int i, j;
568 eNVChannelEnabledType channelEnabledState;
569
Jeff Johnsone7245742012-09-05 17:12:55 -0700570 ENTER();
Gopichand Nakkala1f7a64f2013-04-01 18:37:17 +0530571 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Jeff Johnson295189b2012-06-20 16:38:30 -0700572 {
Gopichand Nakkala1f7a64f2013-04-01 18:37:17 +0530573
574 if (NULL == wiphy->bands[i])
575 {
576 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy->bands[i] is NULL, i = %d",
577 __func__, i);
578 continue;
579 }
580
581 for (j = 0; j < wiphy->bands[i]->n_channels; j++)
582 {
583 struct ieee80211_supported_band *band = wiphy->bands[i];
584
585 channelEnabledState = vos_nv_getChannelEnabledState(
586 band->channels[j].hw_value);
587
588 if (IEEE80211_BAND_2GHZ == i && eCSR_BAND_5G == eBand) // 5G only
589 {
590 // Enable Social channels for P2P
591 if (WLAN_HDD_IS_SOCIAL_CHANNEL(band->channels[j].center_freq) &&
592 NV_CHANNEL_ENABLE == channelEnabledState)
593 band->channels[j].flags &= ~IEEE80211_CHAN_DISABLED;
594 else
595 band->channels[j].flags |= IEEE80211_CHAN_DISABLED;
596 continue;
597 }
598 else if (IEEE80211_BAND_5GHZ == i && eCSR_BAND_24 == eBand) // 2G only
599 {
600 band->channels[j].flags |= IEEE80211_CHAN_DISABLED;
601 continue;
602 }
603
604 if (NV_CHANNEL_DISABLE == channelEnabledState ||
605 NV_CHANNEL_INVALID == channelEnabledState)
606 {
607 band->channels[j].flags |= IEEE80211_CHAN_DISABLED;
608 }
609 else if (NV_CHANNEL_DFS == channelEnabledState)
610 {
611 band->channels[j].flags &= ~IEEE80211_CHAN_DISABLED;
612 band->channels[j].flags |= IEEE80211_CHAN_RADAR;
613 }
614 else
615 {
616 band->channels[j].flags &= ~(IEEE80211_CHAN_DISABLED
617 |IEEE80211_CHAN_RADAR);
618 }
619 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700620 }
621 return 0;
622}
623/*
624 * FUNCTION: wlan_hdd_cfg80211_init
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530625 * This function is called by hdd_wlan_startup()
626 * during initialization.
Jeff Johnson295189b2012-06-20 16:38:30 -0700627 * This function is used to initialize and register wiphy structure.
628 */
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530629int wlan_hdd_cfg80211_init(struct device *dev,
Jeff Johnson295189b2012-06-20 16:38:30 -0700630 struct wiphy *wiphy,
631 hdd_config_t *pCfg
632 )
633{
Gopichand Nakkala1f7a64f2013-04-01 18:37:17 +0530634 int i, j;
Jeff Johnsone7245742012-09-05 17:12:55 -0700635 ENTER();
636
Jeff Johnson295189b2012-06-20 16:38:30 -0700637 /* Now bind the underlying wlan device with wiphy */
638 set_wiphy_dev(wiphy, dev);
639
640 wiphy->mgmt_stypes = wlan_hdd_txrx_stypes;
Amar Singhalfddc28c2013-09-05 13:03:40 -0700641
Amar Singhala49cbc52013-10-08 18:37:44 -0700642 wiphy->flags |= WIPHY_FLAG_STRICT_REGULATORY;
643
644
Amar Singhalfddc28c2013-09-05 13:03:40 -0700645 /* This will disable updating of NL channels from passive to
646 * active if a beacon is received on passive channel. */
647 wiphy->flags |= WIPHY_FLAG_DISABLE_BEACON_HINTS;
Amar Singhalf0073192013-09-20 12:34:56 -0700648
Amar Singhalfddc28c2013-09-05 13:03:40 -0700649
Amar Singhala49cbc52013-10-08 18:37:44 -0700650
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700651#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
Madan Mohan Koyyalamudi1b4afb02012-10-22 15:25:16 -0700652 wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME
653 | WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
654 | WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
Jeff Johnsone7245742012-09-05 17:12:55 -0700655 | WIPHY_FLAG_OFFCHAN_TX;
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700656#endif
Amar Singhala49cbc52013-10-08 18:37:44 -0700657
Srinivas Girigowda640728a2013-03-28 12:21:54 -0700658#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_CCX) || defined(FEATURE_WLAN_LFR)
659 if (pCfg->isFastTransitionEnabled
James Zmuda77fb5ae2013-01-29 08:00:17 -0800660#ifdef FEATURE_WLAN_LFR
Srinivas Girigowda640728a2013-03-28 12:21:54 -0700661 || pCfg->isFastRoamIniFeatureEnabled
662#endif
663#ifdef FEATURE_WLAN_CCX
664 || pCfg->isCcxIniFeatureEnabled
665#endif
666 )
667 {
668 wiphy->flags |= WIPHY_FLAG_SUPPORTS_FW_ROAM;
669 }
James Zmuda77fb5ae2013-01-29 08:00:17 -0800670#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -0800671#ifdef FEATURE_WLAN_TDLS
672 wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS
673 | WIPHY_FLAG_TDLS_EXTERNAL_SETUP;
674#endif
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +0530675#ifdef FEATURE_WLAN_SCAN_PNO
676 wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
Madan Mohan Koyyalamudi75de0102013-09-17 14:56:29 +0530677 wiphy->max_sched_scan_ssids = SIR_PNO_MAX_SUPP_NETWORKS;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +0530678 wiphy->max_match_sets = SIR_PNO_MAX_SUPP_NETWORKS;
Madan Mohan Koyyalamudia7765d52013-09-18 16:49:56 +0530679 wiphy->max_sched_scan_ie_len = SIR_MAC_MAX_IE_LENGTH;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +0530680#endif/*FEATURE_WLAN_SCAN_PNO*/
Mohit Khanna698ba2a2012-12-04 15:08:18 -0800681
Amar Singhalfddc28c2013-09-05 13:03:40 -0700682#ifdef CONFIG_ENABLE_LINUX_REG
Madan Mohan Koyyalamudic3a240c2012-09-28 15:34:08 -0700683 /* even with WIPHY_FLAG_CUSTOM_REGULATORY,
684 driver can still register regulatory callback and
Amar Singhalfddc28c2013-09-05 13:03:40 -0700685 it will get regulatory settings in wiphy->band[], but
Madan Mohan Koyyalamudic3a240c2012-09-28 15:34:08 -0700686 driver need to determine what to do with both
687 regulatory settings */
Amar Singhalfddc28c2013-09-05 13:03:40 -0700688
689 wiphy->reg_notifier = wlan_hdd_linux_reg_notifier;
Amar Singhala49cbc52013-10-08 18:37:44 -0700690#else
691 wiphy->reg_notifier = wlan_hdd_crda_reg_notifier;
Amar Singhalfddc28c2013-09-05 13:03:40 -0700692#endif
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700693
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530694 wiphy->max_scan_ssids = MAX_SCAN_SSID;
695
Madan Mohan Koyyalamudi6815b162013-07-19 17:17:46 +0530696 wiphy->max_scan_ie_len = SIR_MAC_MAX_IE_LENGTH;
Jeff Johnson295189b2012-06-20 16:38:30 -0700697
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +0530698 wiphy->max_acl_mac_addrs = MAX_ACL_MAC_ADDRESS;
699
Jeff Johnson295189b2012-06-20 16:38:30 -0700700 /* Supports STATION & AD-HOC modes right now */
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530701 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION)
Jeff Johnson295189b2012-06-20 16:38:30 -0700702 | BIT(NL80211_IFTYPE_ADHOC)
Jeff Johnson295189b2012-06-20 16:38:30 -0700703 | BIT(NL80211_IFTYPE_P2P_CLIENT)
704 | BIT(NL80211_IFTYPE_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -0700705 | BIT(NL80211_IFTYPE_AP);
706
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800707#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800708 if( pCfg->enableMCC )
709 {
710 /* Currently, supports up to two channels */
711 wlan_hdd_iface_combination.num_different_channels = 2;
712
713 if( !pCfg->allowMCCGODiffBI )
714 wlan_hdd_iface_combination.beacon_int_infra_match = true;
715
716 }
717 wiphy->iface_combinations = &wlan_hdd_iface_combination;
718 wiphy->n_iface_combinations = 1;
719#endif
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800720
Jeff Johnson295189b2012-06-20 16:38:30 -0700721 /* Before registering we need to update the ht capabilitied based
722 * on ini values*/
723 if( !pCfg->ShortGI20MhzEnable )
724 {
725 wlan_hdd_band_2_4_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_20;
726 wlan_hdd_band_5_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_20;
727 wlan_hdd_band_p2p_2_4_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_20;
728 }
729
730 if( !pCfg->ShortGI40MhzEnable )
731 {
732 wlan_hdd_band_5_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_40;
733 }
734
735 if( !pCfg->nChannelBondingMode5GHz )
736 {
737 wlan_hdd_band_5_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
738 }
739
Gopichand Nakkala1f7a64f2013-04-01 18:37:17 +0530740 wiphy->bands[IEEE80211_BAND_2GHZ] = &wlan_hdd_band_2_4_GHZ;
741 wiphy->bands[IEEE80211_BAND_5GHZ] = &wlan_hdd_band_5_GHZ;
742
743 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
744 {
745
746 if (NULL == wiphy->bands[i])
747 {
748 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy->bands[i] is NULL, i = %d",
749 __func__, i);
750 continue;
751 }
752
753 for (j = 0; j < wiphy->bands[i]->n_channels; j++)
754 {
755 struct ieee80211_supported_band *band = wiphy->bands[i];
756
757 if (IEEE80211_BAND_2GHZ == i && eCSR_BAND_5G == pCfg->nBandCapability) // 5G only
758 {
759 // Enable social channels for P2P
760 if (WLAN_HDD_IS_SOCIAL_CHANNEL(band->channels[j].center_freq))
761 band->channels[j].flags &= ~IEEE80211_CHAN_DISABLED;
762 else
763 band->channels[j].flags |= IEEE80211_CHAN_DISABLED;
764 continue;
765 }
766 else if (IEEE80211_BAND_5GHZ == i && eCSR_BAND_24 == pCfg->nBandCapability) // 2G only
767 {
768 band->channels[j].flags |= IEEE80211_CHAN_DISABLED;
769 continue;
770 }
771 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700772 }
773 /*Initialise the supported cipher suite details*/
774 wiphy->cipher_suites = hdd_cipher_suites;
775 wiphy->n_cipher_suites = ARRAY_SIZE(hdd_cipher_suites);
776
777 /*signal strength in mBm (100*dBm) */
778 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
779
780#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
Jeff Johnson295189b2012-06-20 16:38:30 -0700781 wiphy->max_remain_on_channel_duration = 1000;
782#endif
Jeff Johnson295189b2012-06-20 16:38:30 -0700783
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530784 EXIT();
785 return 0;
786}
787
788/* In this function we are registering wiphy. */
789int wlan_hdd_cfg80211_register(struct wiphy *wiphy)
790{
791 ENTER();
792 /* Register our wiphy dev with cfg80211 */
Jeff Johnson295189b2012-06-20 16:38:30 -0700793 if (0 > wiphy_register(wiphy))
794 {
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530795 /* print error */
Jeff Johnson295189b2012-06-20 16:38:30 -0700796 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy register failed", __func__);
797 return -EIO;
798 }
799
800 EXIT();
801 return 0;
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530802}
Jeff Johnson295189b2012-06-20 16:38:30 -0700803
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530804/* In this function we are updating channel list when,
805 regulatory domain is FCC and country code is US.
806 Here In FCC standard 5GHz UNII-1 Bands are indoor only.
807 As per FCC smart phone is not a indoor device.
808 GO should not opeate on indoor channels */
809void wlan_hdd_cfg80211_update_reg_info(struct wiphy *wiphy)
810{
811 int j;
812 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
813 tANI_U8 defaultCountryCode[3] = SME_INVALID_COUNTRY_CODE;
814 //Default counrtycode from NV at the time of wiphy initialization.
815 if (eHAL_STATUS_SUCCESS != sme_GetDefaultCountryCodeFrmNv(pHddCtx->hHal,
816 &defaultCountryCode[0]))
817 {
818 hddLog(LOGE, FL("%s Failed to get default country code from NV"));
819 }
820 if ((defaultCountryCode[0]== 'U') && (defaultCountryCode[1]=='S'))
821 {
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530822 if (NULL == wiphy->bands[IEEE80211_BAND_5GHZ])
823 {
824 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy->bands[IEEE80211_BAND_5GHZ] is NULL",__func__ );
825 return;
826 }
827 for (j = 0; j < wiphy->bands[IEEE80211_BAND_5GHZ]->n_channels; j++)
828 {
829 struct ieee80211_supported_band *band = wiphy->bands[IEEE80211_BAND_5GHZ];
830 // Mark UNII -1 band channel as passive
831 if (WLAN_HDD_CHANNEL_IN_UNII_1_BAND(band->channels[j].center_freq))
832 band->channels[j].flags |= IEEE80211_CHAN_PASSIVE_SCAN;
833 }
834 }
835}
836
Jeff Johnson295189b2012-06-20 16:38:30 -0700837/* In this function we will do all post VOS start initialization.
838 In this function we will register for all frame in which supplicant
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530839 is interested.
Jeff Johnson295189b2012-06-20 16:38:30 -0700840*/
841void wlan_hdd_cfg80211_post_voss_start(hdd_adapter_t* pAdapter)
842{
Jeff Johnson295189b2012-06-20 16:38:30 -0700843 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
844 /* Register for all P2P action, public action etc frames */
845 v_U16_t type = (SIR_MAC_MGMT_FRAME << 2) | ( SIR_MAC_MGMT_ACTION << 4);
846
Jeff Johnsone7245742012-09-05 17:12:55 -0700847 ENTER();
848
Jeff Johnson295189b2012-06-20 16:38:30 -0700849 /* Right now we are registering these frame when driver is getting
850 initialized. Once we will move to 2.6.37 kernel, in which we have
851 frame register ops, we will move this code as a part of that */
852 /* GAS Initial Request */
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530853 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
Jeff Johnson295189b2012-06-20 16:38:30 -0700854 (v_U8_t*)GAS_INITIAL_REQ, GAS_INITIAL_REQ_SIZE );
855
856 /* GAS Initial Response */
857 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
858 (v_U8_t*)GAS_INITIAL_RSP, GAS_INITIAL_RSP_SIZE );
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530859
Jeff Johnson295189b2012-06-20 16:38:30 -0700860 /* GAS Comeback Request */
861 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
862 (v_U8_t*)GAS_COMEBACK_REQ, GAS_COMEBACK_REQ_SIZE );
863
864 /* GAS Comeback Response */
865 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
866 (v_U8_t*)GAS_COMEBACK_RSP, GAS_COMEBACK_RSP_SIZE );
867
868 /* P2P Public Action */
869 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530870 (v_U8_t*)P2P_PUBLIC_ACTION_FRAME,
Jeff Johnson295189b2012-06-20 16:38:30 -0700871 P2P_PUBLIC_ACTION_FRAME_SIZE );
872
873 /* P2P Action */
874 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
875 (v_U8_t*)P2P_ACTION_FRAME,
876 P2P_ACTION_FRAME_SIZE );
Chet Lanctot186b5732013-03-18 10:26:30 -0700877
Gopichand Nakkalae3d56e72013-04-21 23:33:32 +0530878 /* WNM BSS Transition Request frame */
879 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
880 (v_U8_t*)WNM_BSS_ACTION_FRAME,
881 WNM_BSS_ACTION_FRAME_SIZE );
882
Chet Lanctot186b5732013-03-18 10:26:30 -0700883#ifdef WLAN_FEATURE_11W
884 /* SA Query Response Action Frame */
885 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
886 (v_U8_t*)SA_QUERY_FRAME_RSP,
887 SA_QUERY_FRAME_RSP_SIZE );
888#endif /* WLAN_FEATURE_11W */
Jeff Johnson295189b2012-06-20 16:38:30 -0700889}
890
891void wlan_hdd_cfg80211_pre_voss_stop(hdd_adapter_t* pAdapter)
892{
Jeff Johnson295189b2012-06-20 16:38:30 -0700893 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
894 /* Register for all P2P action, public action etc frames */
895 v_U16_t type = (SIR_MAC_MGMT_FRAME << 2) | ( SIR_MAC_MGMT_ACTION << 4);
896
Jeff Johnsone7245742012-09-05 17:12:55 -0700897 ENTER();
898
Jeff Johnson295189b2012-06-20 16:38:30 -0700899 /* Right now we are registering these frame when driver is getting
900 initialized. Once we will move to 2.6.37 kernel, in which we have
901 frame register ops, we will move this code as a part of that */
902 /* GAS Initial Request */
903
904 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
905 (v_U8_t*)GAS_INITIAL_REQ, GAS_INITIAL_REQ_SIZE );
906
907 /* GAS Initial Response */
908 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
909 (v_U8_t*)GAS_INITIAL_RSP, GAS_INITIAL_RSP_SIZE );
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530910
Jeff Johnson295189b2012-06-20 16:38:30 -0700911 /* GAS Comeback Request */
912 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
913 (v_U8_t*)GAS_COMEBACK_REQ, GAS_COMEBACK_REQ_SIZE );
914
915 /* GAS Comeback Response */
916 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
917 (v_U8_t*)GAS_COMEBACK_RSP, GAS_COMEBACK_RSP_SIZE );
918
919 /* P2P Public Action */
920 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530921 (v_U8_t*)P2P_PUBLIC_ACTION_FRAME,
Jeff Johnson295189b2012-06-20 16:38:30 -0700922 P2P_PUBLIC_ACTION_FRAME_SIZE );
923
924 /* P2P Action */
925 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
926 (v_U8_t*)P2P_ACTION_FRAME,
927 P2P_ACTION_FRAME_SIZE );
Chet Lanctot186b5732013-03-18 10:26:30 -0700928
929#ifdef WLAN_FEATURE_11W
930 /* SA Query Response Action Frame */
931 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
932 (v_U8_t*)SA_QUERY_FRAME_RSP,
933 SA_QUERY_FRAME_RSP_SIZE );
934#endif /* WLAN_FEATURE_11W */
Jeff Johnson295189b2012-06-20 16:38:30 -0700935}
936
937#ifdef FEATURE_WLAN_WAPI
938void wlan_hdd_cfg80211_set_key_wapi(hdd_adapter_t* pAdapter, u8 key_index,
939 const u8 *mac_addr, u8 *key , int key_Len)
940{
941 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
942 tCsrRoamSetKey setKey;
943 v_BOOL_t isConnected = TRUE;
944 int status = 0;
945 v_U32_t roamId= 0xFF;
946 tANI_U8 *pKeyPtr = NULL;
947 int n = 0;
948
949 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
950 __func__,pAdapter->device_mode);
951
Gopichand Nakkalae7480202013-02-11 15:24:22 +0530952 vos_mem_zero(&setKey, sizeof(tCsrRoamSetKey));
Jeff Johnson295189b2012-06-20 16:38:30 -0700953 setKey.keyId = key_index; // Store Key ID
954 setKey.encType = eCSR_ENCRYPT_TYPE_WPI; // SET WAPI Encryption
955 setKey.keyDirection = eSIR_TX_RX; // Key Directionn both TX and RX
956 setKey.paeRole = 0 ; // the PAE role
957 if (!mac_addr || is_broadcast_ether_addr(mac_addr))
958 {
959 vos_set_macaddr_broadcast( (v_MACADDR_t *)setKey.peerMac );
960 }
961 else
962 {
963 isConnected = hdd_connIsConnected(pHddStaCtx);
964 vos_mem_copy(setKey.peerMac,&pHddStaCtx->conn_info.bssId,WNI_CFG_BSSID_LEN);
965 }
966 setKey.keyLength = key_Len;
967 pKeyPtr = setKey.Key;
968 memcpy( pKeyPtr, key, key_Len);
969
970 hddLog(VOS_TRACE_LEVEL_INFO,"\n%s: WAPI KEY LENGTH:0x%04x",
971 __func__, key_Len);
972 for (n = 0 ; n < key_Len; n++)
973 hddLog(VOS_TRACE_LEVEL_INFO, "%s WAPI KEY Data[%d]:%02x ",
974 __func__,n,setKey.Key[n]);
975
976 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_SETTING_KEY;
977 if ( isConnected )
978 {
979 status= sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
980 pAdapter->sessionId, &setKey, &roamId );
981 }
982 if ( status != 0 )
983 {
984 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
985 "[%4d] sme_RoamSetKey returned ERROR status= %d",
986 __LINE__, status );
987 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
988 }
989}
990#endif /* FEATURE_WLAN_WAPI*/
991
992#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530993int wlan_hdd_cfg80211_alloc_new_beacon(hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -0700994 beacon_data_t **ppBeacon,
995 struct beacon_parameters *params)
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700996#else
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530997int wlan_hdd_cfg80211_alloc_new_beacon(hdd_adapter_t *pAdapter,
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700998 beacon_data_t **ppBeacon,
999 struct cfg80211_beacon_data *params,
1000 int dtim_period)
1001#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301002{
Jeff Johnson295189b2012-06-20 16:38:30 -07001003 int size;
1004 beacon_data_t *beacon = NULL;
1005 beacon_data_t *old = NULL;
1006 int head_len,tail_len;
1007
Jeff Johnsone7245742012-09-05 17:12:55 -07001008 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07001009 if (params->head && !params->head_len)
1010 return -EINVAL;
1011
1012 old = pAdapter->sessionCtx.ap.beacon;
1013
1014 if (!params->head && !old)
1015 return -EINVAL;
1016
1017 if (params->tail && !params->tail_len)
1018 return -EINVAL;
1019
1020#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,38))
1021 /* Kernel 3.0 is not updating dtim_period for set beacon */
1022 if (!params->dtim_period)
1023 return -EINVAL;
1024#endif
1025
1026 if(params->head)
1027 head_len = params->head_len;
1028 else
1029 head_len = old->head_len;
1030
1031 if(params->tail || !old)
1032 tail_len = params->tail_len;
1033 else
1034 tail_len = old->tail_len;
1035
1036 size = sizeof(beacon_data_t) + head_len + tail_len;
1037
1038 beacon = kzalloc(size, GFP_KERNEL);
1039
1040 if( beacon == NULL )
1041 return -ENOMEM;
1042
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001043#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07001044 if(params->dtim_period || !old )
1045 beacon->dtim_period = params->dtim_period;
1046 else
1047 beacon->dtim_period = old->dtim_period;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001048#else
1049 if(dtim_period || !old )
1050 beacon->dtim_period = dtim_period;
1051 else
1052 beacon->dtim_period = old->dtim_period;
1053#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301054
Jeff Johnson295189b2012-06-20 16:38:30 -07001055 beacon->head = ((u8 *) beacon) + sizeof(beacon_data_t);
1056 beacon->tail = beacon->head + head_len;
1057 beacon->head_len = head_len;
1058 beacon->tail_len = tail_len;
1059
1060 if(params->head) {
1061 memcpy (beacon->head,params->head,beacon->head_len);
1062 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301063 else {
Jeff Johnson295189b2012-06-20 16:38:30 -07001064 if(old)
1065 memcpy (beacon->head,old->head,beacon->head_len);
1066 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301067
Jeff Johnson295189b2012-06-20 16:38:30 -07001068 if(params->tail) {
1069 memcpy (beacon->tail,params->tail,beacon->tail_len);
1070 }
1071 else {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301072 if(old)
Jeff Johnson295189b2012-06-20 16:38:30 -07001073 memcpy (beacon->tail,old->tail,beacon->tail_len);
1074 }
1075
1076 *ppBeacon = beacon;
1077
1078 kfree(old);
1079
1080 return 0;
1081
1082}
Jeff Johnson295189b2012-06-20 16:38:30 -07001083
1084v_U8_t* wlan_hdd_cfg80211_get_ie_ptr(v_U8_t *pIes, int length, v_U8_t eid)
1085{
1086 int left = length;
1087 v_U8_t *ptr = pIes;
1088 v_U8_t elem_id,elem_len;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301089
Jeff Johnson295189b2012-06-20 16:38:30 -07001090 while(left >= 2)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301091 {
Jeff Johnson295189b2012-06-20 16:38:30 -07001092 elem_id = ptr[0];
1093 elem_len = ptr[1];
1094 left -= 2;
1095 if(elem_len > left)
1096 {
1097 hddLog(VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi8bdd3112012-09-24 13:55:14 -07001098 FL("****Invalid IEs eid = %d elem_len=%d left=%d*****"),
Jeff Johnson295189b2012-06-20 16:38:30 -07001099 eid,elem_len,left);
1100 return NULL;
1101 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301102 if (elem_id == eid)
Jeff Johnson295189b2012-06-20 16:38:30 -07001103 {
1104 return ptr;
1105 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301106
Jeff Johnson295189b2012-06-20 16:38:30 -07001107 left -= elem_len;
1108 ptr += (elem_len + 2);
1109 }
1110 return NULL;
1111}
1112
Jeff Johnson295189b2012-06-20 16:38:30 -07001113/* Check if rate is 11g rate or not */
1114static int wlan_hdd_rate_is_11g(u8 rate)
1115{
Sanjay Devnani28322e22013-06-21 16:13:40 -07001116 static const u8 gRateArray[8] = {12, 18, 24, 36, 48, 72, 96, 108}; /* actual rate * 2 */
Jeff Johnson295189b2012-06-20 16:38:30 -07001117 u8 i;
1118 for (i = 0; i < 8; i++)
1119 {
1120 if(rate == gRateArray[i])
1121 return TRUE;
1122 }
1123 return FALSE;
1124}
1125
1126/* Check for 11g rate and set proper 11g only mode */
1127static void wlan_hdd_check_11gmode(u8 *pIe, u8* require_ht,
1128 u8* pCheckRatesfor11g, eSapPhyMode* pSapHw_mode)
1129{
1130 u8 i, num_rates = pIe[0];
1131
1132 pIe += 1;
1133 for ( i = 0; i < num_rates; i++)
1134 {
1135 if( *pCheckRatesfor11g && (TRUE == wlan_hdd_rate_is_11g(pIe[i] & RATE_MASK)))
1136 {
1137 /* If rate set have 11g rate than change the mode to 11G */
1138 *pSapHw_mode = eSAP_DOT11_MODE_11g;
1139 if (pIe[i] & BASIC_RATE_MASK)
1140 {
1141 /* If we have 11g rate as basic rate, it means mode
1142 is 11g only mode.
1143 */
1144 *pSapHw_mode = eSAP_DOT11_MODE_11g_ONLY;
1145 *pCheckRatesfor11g = FALSE;
1146 }
1147 }
1148 else if((BASIC_RATE_MASK | WLAN_BSS_MEMBERSHIP_SELECTOR_HT_PHY) == pIe[i])
1149 {
1150 *require_ht = TRUE;
1151 }
1152 }
1153 return;
1154}
1155
1156static void wlan_hdd_set_sapHwmode(hdd_adapter_t *pHostapdAdapter)
1157{
1158 tsap_Config_t *pConfig = &pHostapdAdapter->sessionCtx.ap.sapConfig;
1159 beacon_data_t *pBeacon = pHostapdAdapter->sessionCtx.ap.beacon;
1160 struct ieee80211_mgmt *pMgmt_frame = (struct ieee80211_mgmt*)pBeacon->head;
1161 u8 checkRatesfor11g = TRUE;
1162 u8 require_ht = FALSE;
1163 u8 *pIe=NULL;
1164
1165 pConfig->SapHw_mode= eSAP_DOT11_MODE_11b;
1166
1167 pIe = wlan_hdd_cfg80211_get_ie_ptr(&pMgmt_frame->u.beacon.variable[0],
1168 pBeacon->head_len, WLAN_EID_SUPP_RATES);
1169 if (pIe != NULL)
1170 {
1171 pIe += 1;
1172 wlan_hdd_check_11gmode(pIe, &require_ht, &checkRatesfor11g,
1173 &pConfig->SapHw_mode);
1174 }
1175
1176 pIe = wlan_hdd_cfg80211_get_ie_ptr(pBeacon->tail, pBeacon->tail_len,
1177 WLAN_EID_EXT_SUPP_RATES);
1178 if (pIe != NULL)
1179 {
1180
1181 pIe += 1;
1182 wlan_hdd_check_11gmode(pIe, &require_ht, &checkRatesfor11g,
1183 &pConfig->SapHw_mode);
1184 }
1185
1186 if( pConfig->channel > 14 )
1187 {
1188 pConfig->SapHw_mode= eSAP_DOT11_MODE_11a;
1189 }
1190
1191 pIe = wlan_hdd_cfg80211_get_ie_ptr(pBeacon->tail, pBeacon->tail_len,
1192 WLAN_EID_HT_CAPABILITY);
1193
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301194 if(pIe)
Jeff Johnson295189b2012-06-20 16:38:30 -07001195 {
1196 pConfig->SapHw_mode= eSAP_DOT11_MODE_11n;
1197 if(require_ht)
1198 pConfig->SapHw_mode= eSAP_DOT11_MODE_11n_ONLY;
1199 }
1200}
1201
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301202static int wlan_hdd_add_ie(hdd_adapter_t* pHostapdAdapter, v_U8_t *genie,
1203 v_U8_t *total_ielen, v_U8_t *oui, v_U8_t oui_size)
1204{
Arif Hussaine7f3ea52013-09-12 21:56:36 -07001205 v_U16_t ielen = 0;
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301206 v_U8_t *pIe = NULL;
1207 beacon_data_t *pBeacon = pHostapdAdapter->sessionCtx.ap.beacon;
1208
1209 pIe = wlan_hdd_get_vendor_oui_ie_ptr(oui, oui_size,
1210 pBeacon->tail, pBeacon->tail_len);
1211
1212 if (pIe)
1213 {
1214 ielen = pIe[1] + 2;
1215 if ((*total_ielen + ielen) <= MAX_GENIE_LEN)
1216 {
1217 vos_mem_copy(&genie[*total_ielen], pIe, ielen);
1218 }
1219 else
1220 {
1221 hddLog( VOS_TRACE_LEVEL_ERROR, "**Ie Length is too big***");
1222 return -EINVAL;
1223 }
1224 *total_ielen += ielen;
1225 }
1226 return 0;
1227}
1228
Arif Hussaine7f3ea52013-09-12 21:56:36 -07001229static void wlan_hdd_add_hostapd_conf_vsie(hdd_adapter_t* pHostapdAdapter,
1230 v_U8_t *genie, v_U8_t *total_ielen)
1231{
1232 beacon_data_t *pBeacon = pHostapdAdapter->sessionCtx.ap.beacon;
1233 int left = pBeacon->tail_len;
1234 v_U8_t *ptr = pBeacon->tail;
1235 v_U8_t elem_id, elem_len;
1236 v_U16_t ielen = 0;
1237
1238 if ( NULL == ptr || 0 == left )
1239 return;
1240
1241 while (left >= 2)
1242 {
1243 elem_id = ptr[0];
1244 elem_len = ptr[1];
1245 left -= 2;
1246 if (elem_len > left)
1247 {
1248 hddLog( VOS_TRACE_LEVEL_ERROR,
1249 "****Invalid IEs eid = %d elem_len=%d left=%d*****",
1250 elem_id, elem_len, left);
1251 return;
1252 }
1253 if (IE_EID_VENDOR == elem_id)
1254 {
1255 /* skipping the VSIE's which we don't want to include or
1256 * it will be included by existing code
1257 */
1258 if ((memcmp( &ptr[2], WPS_OUI_TYPE, WPS_OUI_TYPE_SIZE) != 0 ) &&
1259#ifdef WLAN_FEATURE_WFD
1260 (memcmp( &ptr[2], WFD_OUI_TYPE, WFD_OUI_TYPE_SIZE) != 0) &&
1261#endif
1262 (memcmp( &ptr[2], WHITELIST_OUI_TYPE, WPA_OUI_TYPE_SIZE) != 0) &&
1263 (memcmp( &ptr[2], BLACKLIST_OUI_TYPE, WPA_OUI_TYPE_SIZE) != 0) &&
1264 (memcmp( &ptr[2], "\x00\x50\xf2\x02", WPA_OUI_TYPE_SIZE) != 0) &&
1265 (memcmp( &ptr[2], WPA_OUI_TYPE, WPA_OUI_TYPE_SIZE) != 0) &&
1266 (memcmp( &ptr[2], P2P_OUI_TYPE, P2P_OUI_TYPE_SIZE) != 0))
1267 {
1268 ielen = ptr[1] + 2;
1269 if ((*total_ielen + ielen) <= MAX_GENIE_LEN)
1270 {
1271 vos_mem_copy(&genie[*total_ielen], ptr, ielen);
1272 *total_ielen += ielen;
1273 }
1274 else
1275 {
1276 hddLog( VOS_TRACE_LEVEL_ERROR,
1277 "IE Length is too big "
1278 "IEs eid=%d elem_len=%d total_ie_lent=%d",
1279 elem_id, elem_len, *total_ielen);
1280 }
1281 }
1282 }
1283
1284 left -= elem_len;
1285 ptr += (elem_len + 2);
1286 }
1287 return;
1288}
1289
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001290#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07001291static int wlan_hdd_cfg80211_update_apies(hdd_adapter_t* pHostapdAdapter,
1292 struct beacon_parameters *params)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001293#else
1294static int wlan_hdd_cfg80211_update_apies(hdd_adapter_t* pHostapdAdapter,
1295 struct cfg80211_beacon_data *params)
1296#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07001297{
1298 v_U8_t *genie;
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301299 v_U8_t total_ielen = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07001300 v_U8_t addIE[1] = {0};
Jeff Johnsone7245742012-09-05 17:12:55 -07001301 int ret = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07001302
1303 genie = vos_mem_malloc(MAX_GENIE_LEN);
1304
1305 if(genie == NULL) {
1306
1307 return -ENOMEM;
1308 }
1309
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301310 if (0 != wlan_hdd_add_ie(pHostapdAdapter, genie,
1311 &total_ielen, WPS_OUI_TYPE, WPS_OUI_TYPE_SIZE))
Jeff Johnson295189b2012-06-20 16:38:30 -07001312 {
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301313 ret = -EINVAL;
1314 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001315 }
1316
1317#ifdef WLAN_FEATURE_WFD
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301318 if (0 != wlan_hdd_add_ie(pHostapdAdapter, genie,
1319 &total_ielen, WFD_OUI_TYPE, WFD_OUI_TYPE_SIZE))
1320 {
1321 ret = -EINVAL;
1322 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001323 }
1324#endif
1325
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301326 if (0 != wlan_hdd_add_ie(pHostapdAdapter, genie,
1327 &total_ielen, P2P_OUI_TYPE, P2P_OUI_TYPE_SIZE))
Jeff Johnson295189b2012-06-20 16:38:30 -07001328 {
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301329 ret = -EINVAL;
1330 goto done;
1331 }
1332
1333 if (WLAN_HDD_SOFTAP == pHostapdAdapter->device_mode)
1334 {
Arif Hussaine7f3ea52013-09-12 21:56:36 -07001335 wlan_hdd_add_hostapd_conf_vsie(pHostapdAdapter, genie, &total_ielen);
Jeff Johnson295189b2012-06-20 16:38:30 -07001336 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001337
1338 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1339 WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA, genie, total_ielen, NULL,
1340 eANI_BOOLEAN_FALSE)==eHAL_STATUS_FAILURE)
1341 {
1342 hddLog(LOGE,
1343 "Could not pass on WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001344 ret = -EINVAL;
1345 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001346 }
1347
1348 if (ccmCfgSetInt((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1349 WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG, 1,NULL,
1350 test_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags) ?
1351 eANI_BOOLEAN_TRUE : eANI_BOOLEAN_FALSE)
1352 ==eHAL_STATUS_FAILURE)
1353 {
1354 hddLog(LOGE,
1355 "Could not pass on WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001356 ret = -EINVAL;
1357 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001358 }
1359
1360 // Added for ProResp IE
1361 if ( (params->proberesp_ies != NULL) && (params->proberesp_ies_len != 0) )
1362 {
1363 u16 rem_probe_resp_ie_len = params->proberesp_ies_len;
1364 u8 probe_rsp_ie_len[3] = {0};
1365 u8 counter = 0;
1366 /* Check Probe Resp Length if it is greater then 255 then Store
1367 Probe Resp IEs into WNI_CFG_PROBE_RSP_ADDNIE_DATA1 &
1368 WNI_CFG_PROBE_RSP_ADDNIE_DATA2 CFG Variable As We are not able
1369 Store More then 255 bytes into One Variable.
1370 */
1371 while ((rem_probe_resp_ie_len > 0) && (counter < 3))
1372 {
1373 if (rem_probe_resp_ie_len > MAX_CFG_STRING_LEN)
1374 {
1375 probe_rsp_ie_len[counter++] = MAX_CFG_STRING_LEN;
1376 rem_probe_resp_ie_len -= MAX_CFG_STRING_LEN;
1377 }
1378 else
1379 {
1380 probe_rsp_ie_len[counter++] = rem_probe_resp_ie_len;
1381 rem_probe_resp_ie_len = 0;
1382 }
1383 }
1384
1385 rem_probe_resp_ie_len = 0;
1386
1387 if (probe_rsp_ie_len[0] > 0)
1388 {
1389 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1390 WNI_CFG_PROBE_RSP_ADDNIE_DATA1,
1391 (tANI_U8*)&params->proberesp_ies[rem_probe_resp_ie_len],
1392 probe_rsp_ie_len[0], NULL,
1393 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
1394 {
1395 hddLog(LOGE,
1396 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA1 to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001397 ret = -EINVAL;
1398 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001399 }
1400 rem_probe_resp_ie_len += probe_rsp_ie_len[0];
1401 }
1402
1403 if (probe_rsp_ie_len[1] > 0)
1404 {
1405 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1406 WNI_CFG_PROBE_RSP_ADDNIE_DATA2,
1407 (tANI_U8*)&params->proberesp_ies[rem_probe_resp_ie_len],
1408 probe_rsp_ie_len[1], NULL,
1409 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
1410 {
1411 hddLog(LOGE,
1412 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA2 to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001413 ret = -EINVAL;
1414 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001415 }
1416 rem_probe_resp_ie_len += probe_rsp_ie_len[1];
1417 }
1418
1419 if (probe_rsp_ie_len[2] > 0)
1420 {
1421 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1422 WNI_CFG_PROBE_RSP_ADDNIE_DATA3,
1423 (tANI_U8*)&params->proberesp_ies[rem_probe_resp_ie_len],
1424 probe_rsp_ie_len[2], NULL,
1425 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
1426 {
1427 hddLog(LOGE,
1428 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA3 to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001429 ret = -EINVAL;
1430 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001431 }
1432 rem_probe_resp_ie_len += probe_rsp_ie_len[2];
1433 }
1434
1435 if (probe_rsp_ie_len[1] == 0 )
1436 {
1437 if ( eHAL_STATUS_FAILURE == ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1438 WNI_CFG_PROBE_RSP_ADDNIE_DATA2, (tANI_U8*)addIE, 0, NULL,
1439 eANI_BOOLEAN_FALSE) )
1440 {
1441 hddLog(LOGE,
1442 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA2 to CCM\n");
1443 }
1444 }
1445
1446 if (probe_rsp_ie_len[2] == 0 )
1447 {
1448 if ( eHAL_STATUS_FAILURE == ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1449 WNI_CFG_PROBE_RSP_ADDNIE_DATA3, (tANI_U8*)addIE, 0, NULL,
1450 eANI_BOOLEAN_FALSE) )
1451 {
1452 hddLog(LOGE,
1453 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA3 to CCM\n");
1454 }
1455 }
1456
1457 if (ccmCfgSetInt((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1458 WNI_CFG_PROBE_RSP_ADDNIE_FLAG, 1,NULL,
1459 test_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags) ?
1460 eANI_BOOLEAN_TRUE : eANI_BOOLEAN_FALSE)
1461 == eHAL_STATUS_FAILURE)
1462 {
1463 hddLog(LOGE,
1464 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_FLAG to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001465 ret = -EINVAL;
1466 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001467 }
1468 }
1469 else
1470 {
1471 // Reset WNI_CFG_PROBE_RSP Flags
1472 wlan_hdd_reset_prob_rspies(pHostapdAdapter);
1473
1474 hddLog(VOS_TRACE_LEVEL_INFO,
1475 "%s: No Probe Response IE received in set beacon",
1476 __func__);
1477 }
1478
1479 // Added for AssocResp IE
1480 if ( (params->assocresp_ies != NULL) && (params->assocresp_ies_len != 0) )
1481 {
1482 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1483 WNI_CFG_ASSOC_RSP_ADDNIE_DATA, (tANI_U8*)params->assocresp_ies,
1484 params->assocresp_ies_len, NULL,
1485 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
1486 {
1487 hddLog(LOGE,
1488 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_DATA to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001489 ret = -EINVAL;
1490 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001491 }
1492
1493 if (ccmCfgSetInt((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1494 WNI_CFG_ASSOC_RSP_ADDNIE_FLAG, 1, NULL,
1495 test_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags) ?
1496 eANI_BOOLEAN_TRUE : eANI_BOOLEAN_FALSE)
1497 == eHAL_STATUS_FAILURE)
1498 {
1499 hddLog(LOGE,
1500 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_FLAG to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001501 ret = -EINVAL;
1502 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001503 }
1504 }
1505 else
1506 {
1507 hddLog(VOS_TRACE_LEVEL_INFO,
1508 "%s: No Assoc Response IE received in set beacon",
1509 __func__);
1510
1511 if ( eHAL_STATUS_FAILURE == ccmCfgSetInt((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1512 WNI_CFG_ASSOC_RSP_ADDNIE_FLAG, 0, NULL,
1513 eANI_BOOLEAN_FALSE) )
1514 {
1515 hddLog(LOGE,
1516 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_FLAG to CCM\n");
1517 }
1518 }
1519
Jeff Johnsone7245742012-09-05 17:12:55 -07001520done:
Jeff Johnson295189b2012-06-20 16:38:30 -07001521 vos_mem_free(genie);
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301522 return ret;
Jeff Johnson295189b2012-06-20 16:38:30 -07001523}
Jeff Johnson295189b2012-06-20 16:38:30 -07001524
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301525/*
Jeff Johnson295189b2012-06-20 16:38:30 -07001526 * FUNCTION: wlan_hdd_validate_operation_channel
1527 * called by wlan_hdd_cfg80211_start_bss() and
1528 * wlan_hdd_cfg80211_set_channel()
1529 * This function validates whether given channel is part of valid
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301530 * channel list.
1531 */
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07001532VOS_STATUS wlan_hdd_validate_operation_channel(hdd_adapter_t *pAdapter,int channel)
Jeff Johnson295189b2012-06-20 16:38:30 -07001533{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301534
Jeff Johnson295189b2012-06-20 16:38:30 -07001535 v_U32_t num_ch = 0;
1536 u8 valid_ch[WNI_CFG_VALID_CHANNEL_LIST_LEN];
1537 u32 indx = 0;
1538 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301539 v_U8_t fValidChannel = FALSE, count = 0;
1540 hdd_config_t *hdd_pConfig_ini= (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301541
Jeff Johnson295189b2012-06-20 16:38:30 -07001542 num_ch = WNI_CFG_VALID_CHANNEL_LIST_LEN;
1543
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301544 if ( hdd_pConfig_ini->sapAllowAllChannel)
Jeff Johnson295189b2012-06-20 16:38:30 -07001545 {
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301546 /* Validate the channel */
1547 for (count = RF_CHAN_1 ; count <= RF_CHAN_165 ; count++)
Jeff Johnson295189b2012-06-20 16:38:30 -07001548 {
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301549 if ( channel == rfChannels[count].channelNum )
1550 {
1551 fValidChannel = TRUE;
1552 break;
1553 }
1554 }
1555 if (fValidChannel != TRUE)
1556 {
1557 hddLog(VOS_TRACE_LEVEL_ERROR,
1558 "%s: Invalid Channel [%d]", __func__, channel);
1559 return VOS_STATUS_E_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07001560 }
1561 }
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301562 else
Jeff Johnson295189b2012-06-20 16:38:30 -07001563 {
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301564 if (0 != ccmCfgGetStr(hHal, WNI_CFG_VALID_CHANNEL_LIST,
1565 valid_ch, &num_ch))
1566 {
1567 hddLog(VOS_TRACE_LEVEL_ERROR,
1568 "%s: failed to get valid channel list", __func__);
1569 return VOS_STATUS_E_FAILURE;
1570 }
1571 for (indx = 0; indx < num_ch; indx++)
1572 {
1573 if (channel == valid_ch[indx])
1574 {
1575 break;
1576 }
1577 }
1578
1579 if (indx >= num_ch)
1580 {
1581 hddLog(VOS_TRACE_LEVEL_ERROR,
1582 "%s: Invalid Channel [%d]", __func__, channel);
1583 return VOS_STATUS_E_FAILURE;
1584 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001585 }
1586 return VOS_STATUS_SUCCESS;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301587
Jeff Johnson295189b2012-06-20 16:38:30 -07001588}
1589
Viral Modi3a32cc52013-02-08 11:14:52 -08001590/**
1591 * FUNCTION: wlan_hdd_cfg80211_set_channel
1592 * This function is used to set the channel number
1593 */
1594static int wlan_hdd_cfg80211_set_channel( struct wiphy *wiphy, struct net_device *dev,
1595 struct ieee80211_channel *chan,
1596 enum nl80211_channel_type channel_type
1597 )
1598{
1599 v_U32_t num_ch = 0;
Jeff Johnson4416a782013-03-25 14:17:50 -07001600 int channel = 0;
Viral Modi3a32cc52013-02-08 11:14:52 -08001601 hdd_adapter_t *pAdapter = NULL;
1602 int freq = chan->center_freq; /* freq is in MHZ */
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05301603 hdd_context_t *pHddCtx;
1604 int status;
Viral Modi3a32cc52013-02-08 11:14:52 -08001605
1606 ENTER();
1607
1608 if( NULL == dev )
1609 {
1610 hddLog(VOS_TRACE_LEVEL_ERROR,
1611 "%s: Called with dev = NULL.\n", __func__);
1612 return -ENODEV;
1613 }
1614 pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
1615
1616 hddLog(VOS_TRACE_LEVEL_INFO,
1617 "%s: device_mode = %d freq = %d \n",__func__,
1618 pAdapter->device_mode, chan->center_freq);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05301619
1620 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
1621 status = wlan_hdd_validate_context(pHddCtx);
1622
1623 if (0 != status)
Viral Modi3a32cc52013-02-08 11:14:52 -08001624 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05301625 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1626 "%s: HDD context is not valid", __func__);
1627 return status;
Viral Modi3a32cc52013-02-08 11:14:52 -08001628 }
1629
1630 /*
1631 * Do freq to chan conversion
1632 * TODO: for 11a
1633 */
1634
1635 channel = ieee80211_frequency_to_channel(freq);
1636
1637 /* Check freq range */
1638 if ((WNI_CFG_CURRENT_CHANNEL_STAMIN > channel) ||
1639 (WNI_CFG_CURRENT_CHANNEL_STAMAX < channel))
1640 {
1641 hddLog(VOS_TRACE_LEVEL_ERROR,
1642 "%s: Channel [%d] is outside valid range from %d to %d\n",
1643 __func__, channel, WNI_CFG_CURRENT_CHANNEL_STAMIN,
1644 WNI_CFG_CURRENT_CHANNEL_STAMAX);
1645 return -EINVAL;
1646 }
1647
1648 num_ch = WNI_CFG_VALID_CHANNEL_LIST_LEN;
1649
Gopichand Nakkala6ab19562013-03-07 13:59:42 +05301650 if ((WLAN_HDD_SOFTAP != pAdapter->device_mode) &&
1651 (WLAN_HDD_P2P_GO != pAdapter->device_mode))
Viral Modi3a32cc52013-02-08 11:14:52 -08001652 {
1653 if(VOS_STATUS_SUCCESS != wlan_hdd_validate_operation_channel(pAdapter,channel))
1654 {
1655 hddLog(VOS_TRACE_LEVEL_ERROR,
1656 "%s: Invalid Channel [%d] \n", __func__, channel);
1657 return -EINVAL;
1658 }
1659 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
1660 "%s: set channel to [%d] for device mode =%d",
1661 __func__, channel,pAdapter->device_mode);
1662 }
1663 if( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Viral Modi3a32cc52013-02-08 11:14:52 -08001664 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Viral Modi3a32cc52013-02-08 11:14:52 -08001665 )
1666 {
1667 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
1668 tCsrRoamProfile * pRoamProfile = &pWextState->roamProfile;
1669 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
1670
1671 if (eConnectionState_IbssConnected == pHddStaCtx->conn_info.connState)
1672 {
1673 /* Link is up then return cant set channel*/
1674 hddLog( VOS_TRACE_LEVEL_ERROR,
1675 "%s: IBSS Associated, can't set the channel\n", __func__);
1676 return -EINVAL;
1677 }
1678
1679 num_ch = pRoamProfile->ChannelInfo.numOfChannels = 1;
1680 pHddStaCtx->conn_info.operationChannel = channel;
1681 pRoamProfile->ChannelInfo.ChannelList =
1682 &pHddStaCtx->conn_info.operationChannel;
1683 }
1684 else if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Viral Modi3a32cc52013-02-08 11:14:52 -08001685 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Viral Modi3a32cc52013-02-08 11:14:52 -08001686 )
1687 {
Gopichand Nakkalac8fa7b62013-03-11 13:56:41 +05301688 if (WLAN_HDD_P2P_GO == pAdapter->device_mode)
1689 {
1690 if(VOS_STATUS_SUCCESS !=
1691 wlan_hdd_validate_operation_channel(pAdapter,channel))
1692 {
1693 hddLog(VOS_TRACE_LEVEL_ERROR,
1694 "%s: Invalid Channel [%d] \n", __func__, channel);
1695 return -EINVAL;
1696 }
1697 (WLAN_HDD_GET_AP_CTX_PTR(pAdapter))->sapConfig.channel = channel;
1698 }
1699 else if ( WLAN_HDD_SOFTAP == pAdapter->device_mode )
Viral Modi3a32cc52013-02-08 11:14:52 -08001700 {
1701 hdd_config_t *cfg_param = (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini;
1702
1703 /* If auto channel selection is configured as enable/ 1 then ignore
1704 channel set by supplicant
1705 */
1706 if ( cfg_param->apAutoChannelSelection )
1707 {
Gopichand Nakkalac8fa7b62013-03-11 13:56:41 +05301708 (WLAN_HDD_GET_AP_CTX_PTR(pAdapter))->sapConfig.channel =
1709 AUTO_CHANNEL_SELECT;
Viral Modi3a32cc52013-02-08 11:14:52 -08001710 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
1711 "%s: set channel to auto channel (0) for device mode =%d",
1712 __func__, pAdapter->device_mode);
1713 }
Gopichand Nakkalac8fa7b62013-03-11 13:56:41 +05301714 else
1715 {
1716 if(VOS_STATUS_SUCCESS !=
1717 wlan_hdd_validate_operation_channel(pAdapter,channel))
1718 {
1719 hddLog(VOS_TRACE_LEVEL_ERROR,
1720 "%s: Invalid Channel [%d] \n", __func__, channel);
1721 return -EINVAL;
1722 }
1723 (WLAN_HDD_GET_AP_CTX_PTR(pAdapter))->sapConfig.channel = channel;
1724 }
Viral Modi3a32cc52013-02-08 11:14:52 -08001725 }
1726 }
1727 else
1728 {
1729 hddLog(VOS_TRACE_LEVEL_FATAL,
1730 "%s: Invalid device mode failed to set valid channel", __func__);
1731 return -EINVAL;
1732 }
1733 EXIT();
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05301734 return status;
Viral Modi3a32cc52013-02-08 11:14:52 -08001735}
1736
Jeff Johnson295189b2012-06-20 16:38:30 -07001737#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
1738static int wlan_hdd_cfg80211_start_bss(hdd_adapter_t *pHostapdAdapter,
1739 struct beacon_parameters *params)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001740#else
1741static int wlan_hdd_cfg80211_start_bss(hdd_adapter_t *pHostapdAdapter,
1742 struct cfg80211_beacon_data *params,
1743 const u8 *ssid, size_t ssid_len,
1744 enum nl80211_hidden_ssid hidden_ssid)
1745#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07001746{
1747 tsap_Config_t *pConfig;
1748 beacon_data_t *pBeacon = NULL;
1749 struct ieee80211_mgmt *pMgmt_frame;
1750 v_U8_t *pIe=NULL;
1751 v_U16_t capab_info;
1752 eCsrAuthType RSNAuthType;
1753 eCsrEncryptionType RSNEncryptType;
1754 eCsrEncryptionType mcRSNEncryptType;
1755 int status = VOS_STATUS_SUCCESS;
1756 tpWLAN_SAPEventCB pSapEventCallback;
1757 hdd_hostapd_state_t *pHostapdState;
1758 v_U8_t wpaRsnIEdata[(SIR_MAC_MAX_IE_LENGTH * 2)+4]; //Max ie length 255 * 2(WPA+RSN) + 2 bytes (vendor specific ID) * 2
1759 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pHostapdAdapter))->pvosContext;
Madan Mohan Koyylamudia16d0202013-02-01 11:05:57 +05301760 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pHostapdAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001761 struct qc_mac_acl_entry *acl_entry = NULL;
1762 v_SINT_t i;
Madan Mohan Koyyalamudi543172b2012-12-05 16:40:18 -08001763 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pHostapdAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001764
1765 ENTER();
1766
1767 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pHostapdAdapter);
1768
1769 pConfig = &pHostapdAdapter->sessionCtx.ap.sapConfig;
1770
1771 pBeacon = pHostapdAdapter->sessionCtx.ap.beacon;
1772
1773 pMgmt_frame = (struct ieee80211_mgmt*)pBeacon->head;
1774
1775 pConfig->beacon_int = pMgmt_frame->u.beacon.beacon_int;
1776
1777 //channel is already set in the set_channel Call back
1778 //pConfig->channel = pCommitConfig->channel;
1779
1780 /*Protection parameter to enable or disable*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301781 pConfig->protEnabled =
Jeff Johnson295189b2012-06-20 16:38:30 -07001782 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apProtEnabled;
1783
1784 pConfig->dtim_period = pBeacon->dtim_period;
1785
1786 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,"****pConfig->dtim_period=%d***\n",
1787 pConfig->dtim_period);
1788
1789
Madan Mohan Koyyalamudie0ca11f2012-11-27 15:57:52 -08001790 if (pHostapdAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson32d95a32012-09-10 13:15:23 -07001791 {
1792 pIe = wlan_hdd_cfg80211_get_ie_ptr(pBeacon->tail, pBeacon->tail_len,
Jeff Johnson295189b2012-06-20 16:38:30 -07001793 WLAN_EID_COUNTRY);
Jeff Johnson32d95a32012-09-10 13:15:23 -07001794 if(pIe)
Jeff Johnson295189b2012-06-20 16:38:30 -07001795 {
Jeff Johnson32d95a32012-09-10 13:15:23 -07001796 tANI_BOOLEAN restartNeeded;
Jeff Johnson32d95a32012-09-10 13:15:23 -07001797 pConfig->ieee80211d = 1;
1798 vos_mem_copy(pConfig->countryCode, &pIe[2], 3);
1799 sme_setRegInfo(hHal, pConfig->countryCode);
1800 sme_ResetCountryCodeInformation(hHal, &restartNeeded);
Jeff Johnson295189b2012-06-20 16:38:30 -07001801 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07001802 else
1803 {
1804 pConfig->ieee80211d = 0;
1805 }
Madan Mohan Koyylamudia16d0202013-02-01 11:05:57 +05301806 /*
1807 * If auto channel is configured i.e. channel is 0,
1808 * so skip channel validation.
1809 */
1810 if( AUTO_CHANNEL_SELECT != pConfig->channel )
1811 {
1812 if(VOS_STATUS_SUCCESS != wlan_hdd_validate_operation_channel(pHostapdAdapter,pConfig->channel))
1813 {
1814 hddLog(VOS_TRACE_LEVEL_ERROR,
1815 "%s: Invalid Channel [%d] \n", __func__, pConfig->channel);
1816 return -EINVAL;
1817 }
1818 }
1819 else
1820 {
1821 if(1 != pHddCtx->is_dynamic_channel_range_set)
1822 {
1823 hdd_config_t *hdd_pConfig= (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini;
1824 WLANSAP_SetChannelRange(hHal, hdd_pConfig->apStartChannelNum,
1825 hdd_pConfig->apEndChannelNum,hdd_pConfig->apOperatingBand);
1826 }
1827 pHddCtx->is_dynamic_channel_range_set = 0;
1828 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001829 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07001830 else
Jeff Johnson295189b2012-06-20 16:38:30 -07001831 {
1832 pConfig->ieee80211d = 0;
1833 }
1834 pConfig->authType = eSAP_AUTO_SWITCH;
1835
1836 capab_info = pMgmt_frame->u.beacon.capab_info;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301837
1838 pConfig->privacy = (pMgmt_frame->u.beacon.capab_info &
Jeff Johnson295189b2012-06-20 16:38:30 -07001839 WLAN_CAPABILITY_PRIVACY) ? VOS_TRUE : VOS_FALSE;
1840
1841 (WLAN_HDD_GET_AP_CTX_PTR(pHostapdAdapter))->uPrivacy = pConfig->privacy;
1842
1843 /*Set wps station to configured*/
1844 pIe = wlan_hdd_get_wps_ie_ptr(pBeacon->tail, pBeacon->tail_len);
1845
1846 if(pIe)
1847 {
1848 if(pIe[1] < (2 + WPS_OUI_TYPE_SIZE))
1849 {
1850 hddLog( VOS_TRACE_LEVEL_ERROR, "**Wps Ie Length is too small***\n");
1851 return -EINVAL;
1852 }
1853 else if(memcmp(&pIe[2], WPS_OUI_TYPE, WPS_OUI_TYPE_SIZE) == 0)
1854 {
Madan Mohan Koyyalamudi8bdd3112012-09-24 13:55:14 -07001855 hddLog( VOS_TRACE_LEVEL_INFO, "** WPS IE(len %d) ***", (pIe[1]+2));
Jeff Johnson295189b2012-06-20 16:38:30 -07001856 /* Check 15 bit of WPS IE as it contain information for wps state
1857 * WPS state
1858 */
1859 if(SAP_WPS_ENABLED_UNCONFIGURED == pIe[15])
1860 {
1861 pConfig->wps_state = SAP_WPS_ENABLED_UNCONFIGURED;
1862 } else if(SAP_WPS_ENABLED_CONFIGURED == pIe[15])
1863 {
1864 pConfig->wps_state = SAP_WPS_ENABLED_CONFIGURED;
1865 }
1866 }
1867 }
1868 else
1869 {
1870 pConfig->wps_state = SAP_WPS_DISABLED;
1871 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301872 pConfig->fwdWPSPBCProbeReq = 1; // Forward WPS PBC probe request frame up
Jeff Johnson295189b2012-06-20 16:38:30 -07001873
1874 pConfig->RSNWPAReqIELength = 0;
1875 pConfig->pRSNWPAReqIE = NULL;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301876 pIe = wlan_hdd_cfg80211_get_ie_ptr(pBeacon->tail, pBeacon->tail_len,
Jeff Johnson295189b2012-06-20 16:38:30 -07001877 WLAN_EID_RSN);
1878 if(pIe && pIe[1])
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301879 {
Jeff Johnson295189b2012-06-20 16:38:30 -07001880 pConfig->RSNWPAReqIELength = pIe[1] + 2;
1881 memcpy(&wpaRsnIEdata[0], pIe, pConfig->RSNWPAReqIELength);
1882 pConfig->pRSNWPAReqIE = &wpaRsnIEdata[0];
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301883 /* The actual processing may eventually be more extensive than
1884 * this. Right now, just consume any PMKIDs that are sent in
Jeff Johnson295189b2012-06-20 16:38:30 -07001885 * by the app.
1886 * */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301887 status = hdd_softap_unpackIE(
Jeff Johnson295189b2012-06-20 16:38:30 -07001888 vos_get_context( VOS_MODULE_ID_SME, pVosContext),
1889 &RSNEncryptType,
1890 &mcRSNEncryptType,
1891 &RSNAuthType,
1892 pConfig->pRSNWPAReqIE[1]+2,
1893 pConfig->pRSNWPAReqIE );
1894
1895 if( VOS_STATUS_SUCCESS == status )
1896 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301897 /* Now copy over all the security attributes you have
1898 * parsed out
Jeff Johnson295189b2012-06-20 16:38:30 -07001899 * */
1900 pConfig->RSNEncryptType = RSNEncryptType; // Use the cipher type in the RSN IE
1901 pConfig->mcRSNEncryptType = mcRSNEncryptType;
1902 (WLAN_HDD_GET_AP_CTX_PTR(pHostapdAdapter))->ucEncryptType
1903 = RSNEncryptType;
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +05301904 hddLog( LOG1, FL("CSR AuthType = %d, "
Jeff Johnson295189b2012-06-20 16:38:30 -07001905 "EncryptionType = %d mcEncryptionType = %d\n"),
1906 RSNAuthType, RSNEncryptType, mcRSNEncryptType);
1907 }
1908 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301909
Jeff Johnson295189b2012-06-20 16:38:30 -07001910 pIe = wlan_hdd_get_vendor_oui_ie_ptr(WPA_OUI_TYPE, WPA_OUI_TYPE_SIZE,
1911 pBeacon->tail, pBeacon->tail_len);
1912
1913 if(pIe && pIe[1] && (pIe[0] == DOT11F_EID_WPA))
1914 {
1915 if (pConfig->pRSNWPAReqIE)
1916 {
1917 /*Mixed mode WPA/WPA2*/
1918 memcpy((&wpaRsnIEdata[0] + pConfig->RSNWPAReqIELength), pIe, pIe[1] + 2);
1919 pConfig->RSNWPAReqIELength += pIe[1] + 2;
1920 }
1921 else
1922 {
1923 pConfig->RSNWPAReqIELength = pIe[1] + 2;
1924 memcpy(&wpaRsnIEdata[0], pIe, pConfig->RSNWPAReqIELength);
1925 pConfig->pRSNWPAReqIE = &wpaRsnIEdata[0];
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301926 status = hdd_softap_unpackIE(
Jeff Johnson295189b2012-06-20 16:38:30 -07001927 vos_get_context( VOS_MODULE_ID_SME, pVosContext),
1928 &RSNEncryptType,
1929 &mcRSNEncryptType,
1930 &RSNAuthType,
1931 pConfig->pRSNWPAReqIE[1]+2,
1932 pConfig->pRSNWPAReqIE );
1933
1934 if( VOS_STATUS_SUCCESS == status )
1935 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301936 /* Now copy over all the security attributes you have
1937 * parsed out
Jeff Johnson295189b2012-06-20 16:38:30 -07001938 * */
1939 pConfig->RSNEncryptType = RSNEncryptType; // Use the cipher type in the RSN IE
1940 pConfig->mcRSNEncryptType = mcRSNEncryptType;
1941 (WLAN_HDD_GET_AP_CTX_PTR(pHostapdAdapter))->ucEncryptType
1942 = RSNEncryptType;
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +05301943 hddLog( LOG1, FL("CSR AuthType = %d, "
Jeff Johnson295189b2012-06-20 16:38:30 -07001944 "EncryptionType = %d mcEncryptionType = %d\n"),
1945 RSNAuthType, RSNEncryptType, mcRSNEncryptType);
1946 }
1947 }
1948 }
1949
Jeff Johnson4416a782013-03-25 14:17:50 -07001950 if (pConfig->RSNWPAReqIELength > sizeof wpaRsnIEdata) {
1951 hddLog( VOS_TRACE_LEVEL_ERROR, "**RSNWPAReqIELength is too large***");
1952 return -EINVAL;
1953 }
1954
Jeff Johnson295189b2012-06-20 16:38:30 -07001955 pConfig->SSIDinfo.ssidHidden = VOS_FALSE;
1956
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001957#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07001958 if (params->ssid != NULL)
1959 {
1960 memcpy(pConfig->SSIDinfo.ssid.ssId, params->ssid, params->ssid_len);
1961 pConfig->SSIDinfo.ssid.length = params->ssid_len;
1962 if (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE)
1963 pConfig->SSIDinfo.ssidHidden = VOS_TRUE;
1964 }
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001965#else
1966 if (ssid != NULL)
1967 {
1968 memcpy(pConfig->SSIDinfo.ssid.ssId, ssid, ssid_len);
1969 pConfig->SSIDinfo.ssid.length = ssid_len;
1970 if (hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE)
1971 pConfig->SSIDinfo.ssidHidden = VOS_TRUE;
1972 }
1973#endif
1974
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301975 vos_mem_copy(pConfig->self_macaddr.bytes,
Jeff Johnson295189b2012-06-20 16:38:30 -07001976 pHostapdAdapter->macAddressCurrent.bytes, sizeof(v_MACADDR_t));
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301977
Jeff Johnson295189b2012-06-20 16:38:30 -07001978 /* default value */
1979 pConfig->SapMacaddr_acl = eSAP_ACCEPT_UNLESS_DENIED;
1980 pConfig->num_accept_mac = 0;
1981 pConfig->num_deny_mac = 0;
1982
1983 pIe = wlan_hdd_get_vendor_oui_ie_ptr(BLACKLIST_OUI_TYPE, WPA_OUI_TYPE_SIZE,
1984 pBeacon->tail, pBeacon->tail_len);
1985
1986 /* pIe for black list is following form:
1987 type : 1 byte
1988 length : 1 byte
1989 OUI : 4 bytes
1990 acl type : 1 byte
1991 no of mac addr in black list: 1 byte
1992 list of mac_acl_entries: variable, 6 bytes per mac address + sizeof(int) for vlan id
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301993 */
1994 if ((pIe != NULL) && (pIe[1] != 0))
Jeff Johnson295189b2012-06-20 16:38:30 -07001995 {
1996 pConfig->SapMacaddr_acl = pIe[6];
1997 pConfig->num_deny_mac = pIe[7];
1998 hddLog(VOS_TRACE_LEVEL_INFO,"acl type = %d no deny mac = %d\n",
1999 pIe[6], pIe[7]);
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05302000 if (pConfig->num_deny_mac > MAX_ACL_MAC_ADDRESS)
2001 pConfig->num_deny_mac = MAX_ACL_MAC_ADDRESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07002002 acl_entry = (struct qc_mac_acl_entry *)(pIe + 8);
2003 for (i = 0; i < pConfig->num_deny_mac; i++)
2004 {
2005 vos_mem_copy(&pConfig->deny_mac[i], acl_entry->addr, sizeof(qcmacaddr));
2006 acl_entry++;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302007 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002008 }
2009 pIe = wlan_hdd_get_vendor_oui_ie_ptr(WHITELIST_OUI_TYPE, WPA_OUI_TYPE_SIZE,
2010 pBeacon->tail, pBeacon->tail_len);
2011
2012 /* pIe for white list is following form:
2013 type : 1 byte
2014 length : 1 byte
2015 OUI : 4 bytes
2016 acl type : 1 byte
2017 no of mac addr in white list: 1 byte
2018 list of mac_acl_entries: variable, 6 bytes per mac address + sizeof(int) for vlan id
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302019 */
2020 if ((pIe != NULL) && (pIe[1] != 0))
Jeff Johnson295189b2012-06-20 16:38:30 -07002021 {
2022 pConfig->SapMacaddr_acl = pIe[6];
2023 pConfig->num_accept_mac = pIe[7];
2024 hddLog(VOS_TRACE_LEVEL_INFO,"acl type = %d no accept mac = %d\n",
2025 pIe[6], pIe[7]);
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05302026 if (pConfig->num_accept_mac > MAX_ACL_MAC_ADDRESS)
2027 pConfig->num_accept_mac = MAX_ACL_MAC_ADDRESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07002028 acl_entry = (struct qc_mac_acl_entry *)(pIe + 8);
2029 for (i = 0; i < pConfig->num_accept_mac; i++)
2030 {
2031 vos_mem_copy(&pConfig->accept_mac[i], acl_entry->addr, sizeof(qcmacaddr));
2032 acl_entry++;
2033 }
2034 }
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05302035
Jeff Johnson295189b2012-06-20 16:38:30 -07002036 wlan_hdd_set_sapHwmode(pHostapdAdapter);
2037
Jeff Johnsone7245742012-09-05 17:12:55 -07002038#ifdef WLAN_FEATURE_11AC
Ravi Kumar Vaishnavbbaebbe2013-01-15 17:09:48 -08002039 /* Overwrite the hostapd setting for HW mode only for 11ac.
2040 * This is valid only if mode is set to 11n in hostapd and either AUTO or 11ac in .ini .
2041 * Otherwise, leave whatever is set in hostapd (a OR b OR g OR n mode) */
2042 if( ((pConfig->SapHw_mode == eSAP_DOT11_MODE_11n) ||
2043 (pConfig->SapHw_mode == eSAP_DOT11_MODE_11n_ONLY)) &&
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302044 (((WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->dot11Mode == eHDD_DOT11_MODE_AUTO) ||
Ravi Kumar Vaishnavbbaebbe2013-01-15 17:09:48 -08002045 ((WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->dot11Mode == eHDD_DOT11_MODE_11ac) ||
2046 ((WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY)) )
Jeff Johnsone7245742012-09-05 17:12:55 -07002047 {
2048 pConfig->SapHw_mode = eSAP_DOT11_MODE_11ac;
Ravi Joshi83bfaa12013-05-28 22:12:08 -07002049
2050 /* Disable VHT support in 2.4 GHz band */
2051 if (pConfig->channel <= 14 &&
2052 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->enableVhtFor24GHzBand == FALSE)
2053 {
2054 pConfig->SapHw_mode = eSAP_DOT11_MODE_11n;
2055 }
Jeff Johnsone7245742012-09-05 17:12:55 -07002056 }
2057#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302058
Ravi Joshiaeb7d9e2013-05-02 12:28:14 -07002059 if ( AUTO_CHANNEL_SELECT != pConfig->channel )
2060 {
2061 sme_SelectCBMode(hHal,
2062 sapConvertSapPhyModeToCsrPhyMode(pConfig->SapHw_mode),
2063 pConfig->channel);
2064 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002065 // ht_capab is not what the name conveys,this is used for protection bitmap
2066 pConfig->ht_capab =
2067 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apProtection;
2068
2069 if ( 0 != wlan_hdd_cfg80211_update_apies(pHostapdAdapter, params) )
2070 {
2071 hddLog(LOGE, FL("SAP Not able to set AP IEs"));
2072 return -EINVAL;
2073 }
2074
2075 //Uapsd Enabled Bit
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302076 pConfig->UapsdEnable =
Jeff Johnson295189b2012-06-20 16:38:30 -07002077 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apUapsdEnabled;
2078 //Enable OBSS protection
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302079 pConfig->obssProtEnabled =
2080 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apOBSSProtEnabled;
Jeff Johnson295189b2012-06-20 16:38:30 -07002081
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302082 hddLog(LOGW, FL("SOftAP macaddress : "MAC_ADDRESS_STR"\n"),
Jeff Johnson295189b2012-06-20 16:38:30 -07002083 MAC_ADDR_ARRAY(pHostapdAdapter->macAddressCurrent.bytes));
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302084 hddLog(LOGW,FL("ssid =%s\n"), pConfig->SSIDinfo.ssid.ssId);
Jeff Johnson295189b2012-06-20 16:38:30 -07002085 hddLog(LOGW,FL("beaconint=%d, channel=%d\n"), (int)pConfig->beacon_int,
2086 (int)pConfig->channel);
2087 hddLog(LOGW,FL("hw_mode=%x\n"), pConfig->SapHw_mode);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302088 hddLog(LOGW,FL("privacy=%d, authType=%d\n"), pConfig->privacy,
2089 pConfig->authType);
Jeff Johnson295189b2012-06-20 16:38:30 -07002090 hddLog(LOGW,FL("RSN/WPALen=%d, \n"),(int)pConfig->RSNWPAReqIELength);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302091 hddLog(LOGW,FL("Uapsd = %d\n"),pConfig->UapsdEnable);
Jeff Johnson295189b2012-06-20 16:38:30 -07002092 hddLog(LOGW,FL("ProtEnabled = %d, OBSSProtEnabled = %d\n"),
2093 pConfig->protEnabled, pConfig->obssProtEnabled);
2094
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302095 if(test_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags))
Jeff Johnson295189b2012-06-20 16:38:30 -07002096 {
2097 //Bss already started. just return.
2098 //TODO Probably it should update some beacon params.
2099 hddLog( LOGE, "Bss Already started...Ignore the request");
2100 EXIT();
2101 return 0;
2102 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302103
Jeff Johnson295189b2012-06-20 16:38:30 -07002104 pConfig->persona = pHostapdAdapter->device_mode;
2105
2106 pSapEventCallback = hdd_hostapd_SAPEventCB;
2107 if(WLANSAP_StartBss(pVosContext, pSapEventCallback, pConfig,
2108 (v_PVOID_t)pHostapdAdapter->dev) != VOS_STATUS_SUCCESS)
2109 {
2110 hddLog(LOGE,FL("SAP Start Bss fail\n"));
2111 return -EINVAL;
2112 }
2113
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302114 hddLog(LOG1,
Jeff Johnson295189b2012-06-20 16:38:30 -07002115 FL("Waiting for Scan to complete(auto mode) and BSS to start"));
2116
2117 status = vos_wait_single_event(&pHostapdState->vosEvent, 10000);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302118
Jeff Johnson295189b2012-06-20 16:38:30 -07002119 if (!VOS_IS_STATUS_SUCCESS(status))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302120 {
2121 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07002122 ("ERROR: HDD vos wait for single_event failed!!\n"));
Tushnim Bhattacharyyaad37df12013-10-02 12:01:33 -07002123 smeGetCommandQStatus(hHal);
Jeff Johnson295189b2012-06-20 16:38:30 -07002124 VOS_ASSERT(0);
2125 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302126
Jeff Johnson295189b2012-06-20 16:38:30 -07002127 //Succesfully started Bss update the state bit.
2128 set_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags);
2129
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07002130#ifdef WLAN_FEATURE_P2P_DEBUG
2131 if (pHostapdAdapter->device_mode == WLAN_HDD_P2P_GO)
2132 {
2133 if(globalP2PConnectionStatus == P2P_GO_NEG_COMPLETED)
2134 {
2135 globalP2PConnectionStatus = P2P_GO_COMPLETED_STATE;
2136 hddLog(LOGE,"[P2P State] From Go nego completed to "
Jeff Johnson1250df42012-12-10 14:31:52 -08002137 "Non-autonomous Group started");
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07002138 }
2139 else if(globalP2PConnectionStatus == P2P_NOT_ACTIVE)
2140 {
2141 globalP2PConnectionStatus = P2P_GO_COMPLETED_STATE;
2142 hddLog(LOGE,"[P2P State] From Inactive to "
Jeff Johnson1250df42012-12-10 14:31:52 -08002143 "Autonomous Group started");
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07002144 }
2145 }
2146#endif
2147
Jeff Johnson295189b2012-06-20 16:38:30 -07002148 pHostapdState->bCommit = TRUE;
2149 EXIT();
2150
2151 return 0;
2152}
2153
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002154#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302155static int wlan_hdd_cfg80211_add_beacon(struct wiphy *wiphy,
2156 struct net_device *dev,
Jeff Johnson295189b2012-06-20 16:38:30 -07002157 struct beacon_parameters *params)
2158{
2159 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302160 hdd_context_t *pHddCtx;
2161 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07002162
2163 ENTER();
2164
2165 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "device mode=%d\n",pAdapter->device_mode);
2166
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302167 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2168 status = wlan_hdd_validate_context(pHddCtx);
2169
2170 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002171 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302172 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2173 "%s: HDD context is not valid", __func__);
2174 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002175 }
2176
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302177 if ( (pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002178 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -07002179 )
2180 {
2181 beacon_data_t *old,*new;
2182
2183 old = pAdapter->sessionCtx.ap.beacon;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302184
Jeff Johnson295189b2012-06-20 16:38:30 -07002185 if (old)
2186 return -EALREADY;
2187
2188 status = wlan_hdd_cfg80211_alloc_new_beacon(pAdapter,&new,params);
2189
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302190 if(status != VOS_STATUS_SUCCESS)
Jeff Johnson295189b2012-06-20 16:38:30 -07002191 {
2192 hddLog(VOS_TRACE_LEVEL_FATAL,
2193 "%s:Error!!! Allocating the new beacon\n",__func__);
2194 return -EINVAL;
2195 }
2196
2197 pAdapter->sessionCtx.ap.beacon = new;
2198
2199 status = wlan_hdd_cfg80211_start_bss(pAdapter, params);
2200 }
2201
2202 EXIT();
2203 return status;
2204}
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302205
2206static int wlan_hdd_cfg80211_set_beacon(struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07002207 struct net_device *dev,
2208 struct beacon_parameters *params)
2209{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302210 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302211 hdd_context_t *pHddCtx;
2212 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07002213
2214 ENTER();
2215
2216 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
2217 __func__,pAdapter->device_mode);
2218
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302219 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2220 status = wlan_hdd_validate_context(pHddCtx);
2221
2222 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002223 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302224 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2225 "%s: HDD context is not valid", __func__);
2226 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002227 }
2228
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302229 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002230 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302231 )
Jeff Johnson295189b2012-06-20 16:38:30 -07002232 {
2233 beacon_data_t *old,*new;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302234
Jeff Johnson295189b2012-06-20 16:38:30 -07002235 old = pAdapter->sessionCtx.ap.beacon;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302236
Jeff Johnson295189b2012-06-20 16:38:30 -07002237 if (!old)
2238 return -ENOENT;
2239
2240 status = wlan_hdd_cfg80211_alloc_new_beacon(pAdapter,&new,params);
2241
2242 if(status != VOS_STATUS_SUCCESS) {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302243 hddLog(VOS_TRACE_LEVEL_FATAL,
Jeff Johnson295189b2012-06-20 16:38:30 -07002244 "%s: Error!!! Allocating the new beacon\n",__func__);
2245 return -EINVAL;
2246 }
2247
2248 pAdapter->sessionCtx.ap.beacon = new;
2249
2250 status = wlan_hdd_cfg80211_start_bss(pAdapter, params);
2251 }
2252
2253 EXIT();
2254 return status;
2255}
2256
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002257#endif //(LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
2258
2259#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07002260static int wlan_hdd_cfg80211_del_beacon(struct wiphy *wiphy,
2261 struct net_device *dev)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002262#else
2263static int wlan_hdd_cfg80211_stop_ap (struct wiphy *wiphy,
2264 struct net_device *dev)
2265#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002266{
2267 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsone7245742012-09-05 17:12:55 -07002268 hdd_context_t *pHddCtx = NULL;
2269 hdd_scaninfo_t *pScanInfo = NULL;
2270 hdd_adapter_t *staAdapter = NULL;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302271 VOS_STATUS status;
Jeff Johnson295189b2012-06-20 16:38:30 -07002272
2273 ENTER();
2274
2275 if (NULL == pAdapter)
2276 {
2277 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002278 "%s: HDD adapter context is Null", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002279 return -ENODEV;
2280 }
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002281
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302282 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2283 status = wlan_hdd_validate_context(pHddCtx);
2284
2285 if (0 != status)
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002286 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302287 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2288 "%s: HDD context is not valid", __func__);
2289 return status;
Jeff Johnson4416a782013-03-25 14:17:50 -07002290 }
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002291
2292 staAdapter = hdd_get_adapter(pAdapter->pHddCtx, WLAN_HDD_INFRA_STATION);
2293 if (NULL == staAdapter)
2294 {
2295 staAdapter = hdd_get_adapter(pAdapter->pHddCtx, WLAN_HDD_P2P_CLIENT);
2296 if (NULL == staAdapter)
2297 {
Rajesh Chauhan52d885b2013-11-01 10:54:25 -07002298 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
2299 "%s: HDD adapter context for STA/P2P-CLI is Null",
2300 __func__);
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002301 }
2302 }
2303
2304 pScanInfo = &pHddCtx->scan_info;
2305
Jeff Johnson295189b2012-06-20 16:38:30 -07002306 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
2307 __func__,pAdapter->device_mode);
2308
Rajesh Chauhan52d885b2013-11-01 10:54:25 -07002309 if ((pScanInfo != NULL) && pScanInfo->mScanPending && staAdapter)
Jeff Johnsone7245742012-09-05 17:12:55 -07002310 {
Madan Mohan Koyyalamudif4e81002012-11-13 10:46:38 -08002311 INIT_COMPLETION(pScanInfo->abortscan_event_var);
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05302312 hdd_abort_mac_scan(staAdapter->pHddCtx, pAdapter->sessionId);
Jeff Johnsone7245742012-09-05 17:12:55 -07002313 status = wait_for_completion_interruptible_timeout(
Madan Mohan Koyyalamudif4e81002012-11-13 10:46:38 -08002314 &pScanInfo->abortscan_event_var,
Jeff Johnsone7245742012-09-05 17:12:55 -07002315 msecs_to_jiffies(WLAN_WAIT_TIME_ABORTSCAN));
2316 if (!status)
2317 {
Rajesh Chauhan52d885b2013-11-01 10:54:25 -07002318 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Jeff Johnson902c9832012-12-10 14:28:09 -08002319 "%s: Timeout occurred while waiting for abortscan" ,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002320 __func__);
Jeff Johnsone7245742012-09-05 17:12:55 -07002321 VOS_ASSERT(pScanInfo->mScanPending);
Jeff Johnsone7245742012-09-05 17:12:55 -07002322 }
2323 }
2324
Jeff Johnson295189b2012-06-20 16:38:30 -07002325 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002326 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -07002327 )
2328 {
2329 beacon_data_t *old;
2330
2331 old = pAdapter->sessionCtx.ap.beacon;
2332
2333 if (!old)
2334 return -ENOENT;
2335
Jeff Johnson295189b2012-06-20 16:38:30 -07002336 hdd_cleanup_actionframe(pHddCtx, pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07002337
2338 mutex_lock(&pHddCtx->sap_lock);
2339 if(test_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags))
2340 {
Jeff Johnson4416a782013-03-25 14:17:50 -07002341 if ( VOS_STATUS_SUCCESS == (status = WLANSAP_StopBss(pHddCtx->pvosContext) ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07002342 {
2343 hdd_hostapd_state_t *pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
2344
2345 status = vos_wait_single_event(&pHostapdState->vosEvent, 10000);
2346
2347 if (!VOS_IS_STATUS_SUCCESS(status))
2348 {
2349 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2350 ("ERROR: HDD vos wait for single_event failed!!\n"));
2351 VOS_ASSERT(0);
2352 }
2353 }
2354 clear_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags);
2355 }
2356 mutex_unlock(&pHddCtx->sap_lock);
2357
2358 if(status != VOS_STATUS_SUCCESS)
2359 {
2360 hddLog(VOS_TRACE_LEVEL_FATAL,
2361 "%s:Error!!! Stopping the BSS\n",__func__);
2362 return -EINVAL;
2363 }
2364
Jeff Johnson4416a782013-03-25 14:17:50 -07002365 if (ccmCfgSetInt(pHddCtx->hHal,
Jeff Johnson295189b2012-06-20 16:38:30 -07002366 WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG, 0,NULL, eANI_BOOLEAN_FALSE)
2367 ==eHAL_STATUS_FAILURE)
2368 {
2369 hddLog(LOGE,
2370 "Could not pass on WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG to CCM\n");
2371 }
2372
Jeff Johnson4416a782013-03-25 14:17:50 -07002373 if ( eHAL_STATUS_FAILURE == ccmCfgSetInt(pHddCtx->hHal,
Jeff Johnson295189b2012-06-20 16:38:30 -07002374 WNI_CFG_ASSOC_RSP_ADDNIE_FLAG, 0, NULL,
2375 eANI_BOOLEAN_FALSE) )
2376 {
2377 hddLog(LOGE,
2378 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_FLAG to CCM\n");
2379 }
2380
2381 // Reset WNI_CFG_PROBE_RSP Flags
2382 wlan_hdd_reset_prob_rspies(pAdapter);
2383
2384 pAdapter->sessionCtx.ap.beacon = NULL;
2385 kfree(old);
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07002386#ifdef WLAN_FEATURE_P2P_DEBUG
2387 if((pAdapter->device_mode == WLAN_HDD_P2P_GO) &&
2388 (globalP2PConnectionStatus == P2P_GO_COMPLETED_STATE))
2389 {
2390 hddLog(LOGE,"[P2P State] From GO completed to Inactive state "
2391 "GO got removed");
2392 globalP2PConnectionStatus = P2P_NOT_ACTIVE;
2393 }
2394#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002395 }
2396 EXIT();
2397 return status;
2398}
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002399
2400#if (LINUX_VERSION_CODE > KERNEL_VERSION(3,3,0))
2401
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302402static int wlan_hdd_cfg80211_start_ap(struct wiphy *wiphy,
2403 struct net_device *dev,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002404 struct cfg80211_ap_settings *params)
2405{
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302406 hdd_adapter_t *pAdapter;
2407 hdd_context_t *pHddCtx;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302408 int status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002409
2410 ENTER();
2411
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302412 if (NULL == dev)
Madan Mohan Koyyalamudib2c36892012-10-18 20:52:38 -07002413 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302414 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302415 "%s: Device is Null", __func__);
2416 return -ENODEV;
2417 }
2418
2419 pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
2420 if (NULL == pAdapter)
2421 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302422 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302423 "%s: HDD adapter is Null", __func__);
2424 return -ENODEV;
2425 }
2426
2427 if (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic)
2428 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302429 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302430 "%s: HDD adapter magic is invalid", __func__);
2431 return -ENODEV;
2432 }
2433
2434 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302435 status = wlan_hdd_validate_context(pHddCtx);
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302436
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302437 if (0 != status)
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302438 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302439 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2440 "%s: HDD context is not valid", __func__);
2441 return status;
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302442 }
2443
2444 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: device mode = %d",
2445 __func__, pAdapter->device_mode);
2446
2447 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002448 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002449 )
2450 {
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302451 beacon_data_t *old, *new;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002452
2453 old = pAdapter->sessionCtx.ap.beacon;
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302454
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002455 if (old)
2456 return -EALREADY;
2457
2458 status = wlan_hdd_cfg80211_alloc_new_beacon(pAdapter, &new, &params->beacon, params->dtim_period);
2459
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302460 if (status != 0)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002461 {
2462 hddLog(VOS_TRACE_LEVEL_FATAL,
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302463 "%s:Error!!! Allocating the new beacon", __func__);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002464 return -EINVAL;
2465 }
2466 pAdapter->sessionCtx.ap.beacon = new;
Viral Modi3a32cc52013-02-08 11:14:52 -08002467#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
Yue Maf49ba872013-08-19 12:04:25 -07002468 wlan_hdd_cfg80211_set_channel(wiphy, dev,
2469#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0))
2470 params->channel, params->channel_type);
2471#else
2472 params->chandef.chan, cfg80211_get_chandef_type(&(params->chandef)));
2473#endif
Viral Modi3a32cc52013-02-08 11:14:52 -08002474#endif
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002475 status = wlan_hdd_cfg80211_start_bss(pAdapter, &params->beacon, params->ssid,
2476 params->ssid_len, params->hidden_ssid);
2477 }
2478
2479 EXIT();
2480 return status;
2481}
2482
2483
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302484static int wlan_hdd_cfg80211_change_beacon(struct wiphy *wiphy,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002485 struct net_device *dev,
2486 struct cfg80211_beacon_data *params)
2487{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302488 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302489 hdd_context_t *pHddCtx;
2490 int status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002491
2492 ENTER();
2493
2494 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
2495 __func__, pAdapter->device_mode);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302496
2497 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2498 status = wlan_hdd_validate_context(pHddCtx);
2499
2500 if (0 != status)
Madan Mohan Koyyalamudib2c36892012-10-18 20:52:38 -07002501 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302502 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2503 "%s: HDD context is not valid", __func__);
2504 return status;
Madan Mohan Koyyalamudib2c36892012-10-18 20:52:38 -07002505 }
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002506
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302507 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002508 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302509 )
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002510 {
2511 beacon_data_t *old,*new;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302512
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002513 old = pAdapter->sessionCtx.ap.beacon;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302514
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002515 if (!old)
2516 return -ENOENT;
2517
2518 status = wlan_hdd_cfg80211_alloc_new_beacon(pAdapter, &new, params, 0);
2519
2520 if(status != VOS_STATUS_SUCCESS) {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302521 hddLog(VOS_TRACE_LEVEL_FATAL,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002522 "%s: Error!!! Allocating the new beacon\n",__func__);
2523 return -EINVAL;
2524 }
2525
2526 pAdapter->sessionCtx.ap.beacon = new;
2527
2528 status = wlan_hdd_cfg80211_start_bss(pAdapter, params, NULL, 0, 0);
2529 }
2530
2531 EXIT();
2532 return status;
2533}
2534
2535#endif //(LINUX_VERSION_CODE > KERNEL_VERSION(3,3,0))
2536
Jeff Johnson295189b2012-06-20 16:38:30 -07002537
2538static int wlan_hdd_cfg80211_change_bss (struct wiphy *wiphy,
2539 struct net_device *dev,
2540 struct bss_parameters *params)
2541{
2542 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
2543
2544 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302545
Jeff Johnson295189b2012-06-20 16:38:30 -07002546 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
2547 __func__,pAdapter->device_mode);
2548
2549 if((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002550 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302551 )
Jeff Johnson295189b2012-06-20 16:38:30 -07002552 {
2553 /* ap_isolate == -1 means that in change bss, upper layer doesn't
2554 * want to update this parameter */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302555 if (-1 != params->ap_isolate)
Jeff Johnson295189b2012-06-20 16:38:30 -07002556 {
2557 pAdapter->sessionCtx.ap.apDisableIntraBssFwd = !!params->ap_isolate;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302558 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002559 }
2560
2561 EXIT();
2562 return 0;
2563}
2564
Kiet Lam10841362013-11-01 11:36:50 +05302565/* FUNCTION: wlan_hdd_change_country_code_cd
2566* to wait for contry code completion
2567*/
2568void* wlan_hdd_change_country_code_cb(void *pAdapter)
2569{
2570 hdd_adapter_t *call_back_pAdapter = pAdapter;
2571 complete(&call_back_pAdapter->change_country_code);
2572 return NULL;
2573}
2574
Jeff Johnson295189b2012-06-20 16:38:30 -07002575/*
2576 * FUNCTION: wlan_hdd_cfg80211_change_iface
2577 * This function is used to set the interface type (INFRASTRUCTURE/ADHOC)
2578 */
2579int wlan_hdd_cfg80211_change_iface( struct wiphy *wiphy,
2580 struct net_device *ndev,
2581 enum nl80211_iftype type,
2582 u32 *flags,
2583 struct vif_params *params
2584 )
2585{
2586 struct wireless_dev *wdev;
2587 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
2588 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
Mohit Khanna0f232092012-09-11 14:46:08 -07002589 hdd_adapter_t *pP2pAdapter = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07002590 tCsrRoamProfile *pRoamProfile = NULL;
2591 eCsrRoamBssType LastBSSType;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302592 hdd_config_t *pConfig = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07002593 eMib_dot11DesiredBssType connectedBssType;
2594 VOS_STATUS status;
2595
2596 ENTER();
2597
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302598 status = wlan_hdd_validate_context(pHddCtx);
2599
2600 if (0 != status)
Jeff Johnson295189b2012-06-20 16:38:30 -07002601 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302602 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2603 "%s: HDD context is not valid", __func__);
2604 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07002605 }
2606
2607 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
2608 __func__, pAdapter->device_mode);
2609
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302610 pConfig = pHddCtx->cfg_ini;
Jeff Johnson295189b2012-06-20 16:38:30 -07002611 wdev = ndev->ieee80211_ptr;
2612
2613#ifdef WLAN_BTAMP_FEATURE
2614 if((NL80211_IFTYPE_P2P_CLIENT == type)||
2615 (NL80211_IFTYPE_ADHOC == type)||
2616 (NL80211_IFTYPE_AP == type)||
2617 (NL80211_IFTYPE_P2P_GO == type))
2618 {
2619 pHddCtx->isAmpAllowed = VOS_FALSE;
2620 // stop AMP traffic
2621 status = WLANBAP_StopAmp();
2622 if(VOS_STATUS_SUCCESS != status )
2623 {
2624 pHddCtx->isAmpAllowed = VOS_TRUE;
2625 hddLog(VOS_TRACE_LEVEL_FATAL,
2626 "%s: Failed to stop AMP", __func__);
2627 return -EINVAL;
2628 }
2629 }
2630#endif //WLAN_BTAMP_FEATURE
2631 /* Reset the current device mode bit mask*/
2632 wlan_hdd_clear_concurrency_mode(pHddCtx, pAdapter->device_mode);
2633
2634 if( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Jeff Johnson295189b2012-06-20 16:38:30 -07002635 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Jeff Johnsone7245742012-09-05 17:12:55 -07002636 || (pAdapter->device_mode == WLAN_HDD_P2P_DEVICE)
Jeff Johnson295189b2012-06-20 16:38:30 -07002637 )
2638 {
2639 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
2640 pRoamProfile = &pWextState->roamProfile;
2641 LastBSSType = pRoamProfile->BSSType;
2642
2643 switch (type)
2644 {
2645 case NL80211_IFTYPE_STATION:
Jeff Johnson295189b2012-06-20 16:38:30 -07002646 case NL80211_IFTYPE_P2P_CLIENT:
Jeff Johnson295189b2012-06-20 16:38:30 -07002647 hddLog(VOS_TRACE_LEVEL_INFO,
2648 "%s: setting interface Type to INFRASTRUCTURE", __func__);
2649 pRoamProfile->BSSType = eCSR_BSS_TYPE_INFRASTRUCTURE;
Jeff Johnsone7245742012-09-05 17:12:55 -07002650#ifdef WLAN_FEATURE_11AC
2651 if(pConfig->dot11Mode == eHDD_DOT11_MODE_AUTO)
2652 {
2653 pConfig->dot11Mode = eHDD_DOT11_MODE_11ac;
2654 }
2655#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302656 pRoamProfile->phyMode =
Jeff Johnsone7245742012-09-05 17:12:55 -07002657 hdd_cfg_xlate_to_csr_phy_mode(pConfig->dot11Mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07002658 wdev->iftype = type;
Gopichand Nakkalaf527dc62012-12-31 16:35:10 -08002659 //Check for sub-string p2p to confirm its a p2p interface
2660 if (NULL != strstr(ndev->name,"p2p"))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302661 {
Gopichand Nakkala864d3552012-12-31 16:08:51 -08002662 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
2663 WLAN_HDD_P2P_DEVICE : WLAN_HDD_P2P_CLIENT;
2664 }
2665 else
2666 {
2667 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
Jeff Johnson295189b2012-06-20 16:38:30 -07002668 WLAN_HDD_INFRA_STATION: WLAN_HDD_P2P_CLIENT;
Gopichand Nakkala864d3552012-12-31 16:08:51 -08002669 }
Madan Mohan Koyyalamudi81746922013-07-17 14:38:51 +05302670#ifdef FEATURE_WLAN_TDLS
2671 /* The open adapter for the p2p shall skip initializations in
2672 * tdls_init if the device mode is WLAN_HDD_P2P_DEVICE, for
2673 * TDLS is supported only on WLAN_HDD_P2P_CLIENT. Hence invoke
2674 * tdls_init when the change_iface sets the device mode to
2675 * WLAN_HDD_P2P_CLIENT.
2676 */
2677
2678 if ( pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
2679 {
2680 if (0 != wlan_hdd_tdls_init (pAdapter))
2681 {
2682 return -EINVAL;
2683 }
2684 }
2685#endif
2686
Jeff Johnson295189b2012-06-20 16:38:30 -07002687 break;
2688 case NL80211_IFTYPE_ADHOC:
2689 hddLog(VOS_TRACE_LEVEL_INFO,
2690 "%s: setting interface Type to ADHOC", __func__);
2691 pRoamProfile->BSSType = eCSR_BSS_TYPE_START_IBSS;
2692 pRoamProfile->phyMode =
2693 hdd_cfg_xlate_to_csr_phy_mode(pConfig->dot11Mode);
Shailender Karmuchia734f332013-04-19 14:02:48 -07002694 pAdapter->device_mode = WLAN_HDD_IBSS;
Jeff Johnson295189b2012-06-20 16:38:30 -07002695 wdev->iftype = type;
2696 break;
2697
2698 case NL80211_IFTYPE_AP:
Jeff Johnson295189b2012-06-20 16:38:30 -07002699 case NL80211_IFTYPE_P2P_GO:
Jeff Johnson295189b2012-06-20 16:38:30 -07002700 {
2701 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
2702 "%s: setting interface Type to %s", __func__,
2703 (type == NL80211_IFTYPE_AP) ? "SoftAP" : "P2pGo");
2704
Gopichand Nakkalaf527dc62012-12-31 16:35:10 -08002705 //Cancel any remain on channel for GO mode
2706 if (NL80211_IFTYPE_P2P_GO == type)
2707 {
2708 wlan_hdd_cancel_existing_remain_on_channel(pAdapter);
2709 }
Mohit Khanna0f232092012-09-11 14:46:08 -07002710 if (NL80211_IFTYPE_AP == type)
2711 {
2712 /* As Loading WLAN Driver one interface being created for p2p device
2713 * address. This will take one HW STA and the max number of clients
2714 * that can connect to softAP will be reduced by one. so while changing
2715 * the interface type to NL80211_IFTYPE_AP (SoftAP) remove p2p0
2716 * interface as it is not required in SoftAP mode.
2717 */
2718
2719 // Get P2P Adapter
2720 pP2pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_P2P_DEVICE);
2721
2722 if (pP2pAdapter)
2723 {
2724 hdd_stop_adapter(pHddCtx, pP2pAdapter);
2725 hdd_deinit_adapter(pHddCtx, pP2pAdapter);
2726 hdd_close_adapter(pHddCtx, pP2pAdapter, VOS_TRUE);
2727 }
2728 }
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302729#ifdef FEATURE_WLAN_TDLS
Mohit Khanna0f232092012-09-11 14:46:08 -07002730
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302731 /* A Mutex Lock is introduced while changing the mode to
2732 * protect the concurrent access for the Adapters by TDLS
2733 * module.
2734 */
2735 if (mutex_lock_interruptible(&pHddCtx->tdls_lock))
2736 {
2737 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2738 "%s: unable to lock list", __func__);
2739 return -EINVAL;
2740 }
2741#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002742 //De-init the adapter.
2743 hdd_stop_adapter( pHddCtx, pAdapter );
2744 hdd_deinit_adapter( pHddCtx, pAdapter );
2745 memset(&pAdapter->sessionCtx, 0, sizeof(pAdapter->sessionCtx));
Jeff Johnson295189b2012-06-20 16:38:30 -07002746 pAdapter->device_mode = (type == NL80211_IFTYPE_AP) ?
2747 WLAN_HDD_SOFTAP : WLAN_HDD_P2P_GO;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302748#ifdef FEATURE_WLAN_TDLS
2749 mutex_unlock(&pHddCtx->tdls_lock);
2750#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -07002751
2752 //Disable BMPS and IMPS if enabled
2753 //before starting Go
2754 if(WLAN_HDD_P2P_GO == pAdapter->device_mode)
2755 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302756 if(VOS_STATUS_E_FAILURE ==
Jeff Johnson32d95a32012-09-10 13:15:23 -07002757 hdd_disable_bmps_imps(pHddCtx, WLAN_HDD_P2P_GO))
2758 {
2759 //Fail to Exit BMPS
2760 VOS_ASSERT(0);
2761 }
2762 }
2763
Madan Mohan Koyyalamudi3ff2a0b2012-10-15 14:33:46 -07002764 if ((WLAN_HDD_SOFTAP == pAdapter->device_mode) &&
2765 (pConfig->apRandomBssidEnabled))
2766 {
2767 /* To meet Android requirements create a randomized
2768 MAC address of the form 02:1A:11:Fx:xx:xx */
2769 get_random_bytes(&ndev->dev_addr[3], 3);
2770 ndev->dev_addr[0] = 0x02;
2771 ndev->dev_addr[1] = 0x1A;
2772 ndev->dev_addr[2] = 0x11;
2773 ndev->dev_addr[3] |= 0xF0;
2774 memcpy(pAdapter->macAddressCurrent.bytes, ndev->dev_addr,
2775 VOS_MAC_ADDR_SIZE);
2776 pr_info("wlan: Generated HotSpot BSSID "
2777 "%02x:%02x:%02x:%02x:%02x:%02x\n",
2778 ndev->dev_addr[0],
2779 ndev->dev_addr[1],
2780 ndev->dev_addr[2],
2781 ndev->dev_addr[3],
2782 ndev->dev_addr[4],
2783 ndev->dev_addr[5]);
2784 }
2785
Jeff Johnson295189b2012-06-20 16:38:30 -07002786 hdd_set_ap_ops( pAdapter->dev );
2787
Kiet Lam10841362013-11-01 11:36:50 +05302788 /* This is for only SAP mode where users can
2789 * control country through ini.
2790 * P2P GO follows station country code
2791 * acquired during the STA scanning. */
2792 if((NL80211_IFTYPE_AP == type) &&
2793 (memcmp(pConfig->apCntryCode, CFG_AP_COUNTRY_CODE_DEFAULT, 3) != 0))
2794 {
2795 int status = 0;
2796 VOS_TRACE(VOS_MODULE_ID_HDD,VOS_TRACE_LEVEL_INFO,
2797 "%s: setting country code from INI ", __func__);
2798 init_completion(&pAdapter->change_country_code);
2799 status = (int)sme_ChangeCountryCode(pHddCtx->hHal,
2800 (void *)(tSmeChangeCountryCallback)
2801 wlan_hdd_change_country_code_cb,
2802 pConfig->apCntryCode, pAdapter,
2803 pHddCtx->pvosContext,
2804 VOS_FALSE);
2805 if (eHAL_STATUS_SUCCESS == status)
2806 {
2807 /* Wait for completion */
2808 status = wait_for_completion_interruptible_timeout(
2809 &pAdapter->change_country_code,
2810 msecs_to_jiffies(WLAN_WAIT_TIME_COUNTRY));
2811 if (status <= 0)
2812 {
2813 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2814 "%s: SME Timed out while setting country code ",
2815 __func__);
2816 }
2817 }
2818 else
2819 {
2820 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2821 "%s: SME Change Country code failed \n",__func__);
2822 return -EINVAL;
2823 }
2824 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002825 status = hdd_init_ap_mode(pAdapter);
2826 if(status != VOS_STATUS_SUCCESS)
2827 {
2828 hddLog(VOS_TRACE_LEVEL_FATAL,
2829 "%s: Error initializing the ap mode", __func__);
2830 return -EINVAL;
2831 }
2832 hdd_set_conparam(1);
2833
Jeff Johnson295189b2012-06-20 16:38:30 -07002834 /*interface type changed update in wiphy structure*/
2835 if(wdev)
2836 {
2837 wdev->iftype = type;
2838 pHddCtx->change_iface = type;
2839 }
2840 else
2841 {
2842 hddLog(VOS_TRACE_LEVEL_ERROR,
2843 "%s: ERROR !!!! Wireless dev is NULL", __func__);
2844 return -EINVAL;
2845 }
2846 goto done;
2847 }
2848
2849 default:
2850 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported interface Type",
2851 __func__);
2852 return -EOPNOTSUPP;
2853 }
2854 }
2855 else if ( (pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002856 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -07002857 )
2858 {
2859 switch(type)
2860 {
2861 case NL80211_IFTYPE_STATION:
Jeff Johnson295189b2012-06-20 16:38:30 -07002862 case NL80211_IFTYPE_P2P_CLIENT:
Jeff Johnson295189b2012-06-20 16:38:30 -07002863 case NL80211_IFTYPE_ADHOC:
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302864#ifdef FEATURE_WLAN_TDLS
2865
2866 /* A Mutex Lock is introduced while changing the mode to
2867 * protect the concurrent access for the Adapters by TDLS
2868 * module.
2869 */
2870 if (mutex_lock_interruptible(&pHddCtx->tdls_lock))
2871 {
2872 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2873 "%s: unable to lock list", __func__);
2874 return -EINVAL;
2875 }
2876#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -07002877 hdd_stop_adapter( pHddCtx, pAdapter );
2878 hdd_deinit_adapter( pHddCtx, pAdapter );
Jeff Johnson295189b2012-06-20 16:38:30 -07002879 wdev->iftype = type;
Gopichand Nakkalaf527dc62012-12-31 16:35:10 -08002880 //Check for sub-string p2p to confirm its a p2p interface
2881 if (NULL != strstr(ndev->name,"p2p"))
Gopichand Nakkala864d3552012-12-31 16:08:51 -08002882 {
2883 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
2884 WLAN_HDD_P2P_DEVICE : WLAN_HDD_P2P_CLIENT;
2885 }
2886 else
2887 {
2888 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
Jeff Johnson295189b2012-06-20 16:38:30 -07002889 WLAN_HDD_INFRA_STATION: WLAN_HDD_P2P_CLIENT;
Gopichand Nakkala864d3552012-12-31 16:08:51 -08002890 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002891 hdd_set_conparam(0);
2892 pHddCtx->change_iface = type;
Jeff Johnson295189b2012-06-20 16:38:30 -07002893 memset(&pAdapter->sessionCtx, 0, sizeof(pAdapter->sessionCtx));
2894 hdd_set_station_ops( pAdapter->dev );
2895 status = hdd_init_station_mode( pAdapter );
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302896#ifdef FEATURE_WLAN_TDLS
2897 mutex_unlock(&pHddCtx->tdls_lock);
2898#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002899 if( VOS_STATUS_SUCCESS != status )
2900 return -EOPNOTSUPP;
Jeff Johnsone7245742012-09-05 17:12:55 -07002901 /* In case of JB, for P2P-GO, only change interface will be called,
2902 * This is the right place to enable back bmps_imps()
2903 */
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05302904 if (pHddCtx->hdd_wlan_suspended)
2905 {
2906 hdd_set_pwrparams(pHddCtx);
2907 }
Jeff Johnsone7245742012-09-05 17:12:55 -07002908 hdd_enable_bmps_imps(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07002909 goto done;
2910 case NL80211_IFTYPE_AP:
Jeff Johnson295189b2012-06-20 16:38:30 -07002911 case NL80211_IFTYPE_P2P_GO:
Jeff Johnson295189b2012-06-20 16:38:30 -07002912 wdev->iftype = type;
Jeff Johnson295189b2012-06-20 16:38:30 -07002913 pAdapter->device_mode = (type == NL80211_IFTYPE_AP) ?
2914 WLAN_HDD_SOFTAP : WLAN_HDD_P2P_GO;
Jeff Johnson295189b2012-06-20 16:38:30 -07002915 goto done;
2916 default:
2917 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported interface Type",
2918 __func__);
2919 return -EOPNOTSUPP;
2920
2921 }
2922
2923 }
2924 else
2925 {
2926 return -EOPNOTSUPP;
2927 }
2928
2929
2930 if(pRoamProfile)
2931 {
2932 if ( LastBSSType != pRoamProfile->BSSType )
2933 {
2934 /*interface type changed update in wiphy structure*/
2935 wdev->iftype = type;
2936
2937 /*the BSS mode changed, We need to issue disconnect
2938 if connected or in IBSS disconnect state*/
2939 if ( hdd_connGetConnectedBssType(
2940 WLAN_HDD_GET_STATION_CTX_PTR(pAdapter), &connectedBssType ) ||
2941 ( eCSR_BSS_TYPE_START_IBSS == LastBSSType ) )
2942 {
2943 /*need to issue a disconnect to CSR.*/
2944 INIT_COMPLETION(pAdapter->disconnect_comp_var);
2945 if( eHAL_STATUS_SUCCESS ==
2946 sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
2947 pAdapter->sessionId,
2948 eCSR_DISCONNECT_REASON_UNSPECIFIED ) )
2949 {
2950 wait_for_completion_interruptible_timeout(
2951 &pAdapter->disconnect_comp_var,
2952 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
2953 }
2954 }
2955 }
2956 }
2957
2958done:
2959 /*set bitmask based on updated value*/
2960 wlan_hdd_set_concurrency_mode(pHddCtx, pAdapter->device_mode);
Leo Chang6fe1f922013-06-07 19:21:24 -07002961
2962 /* Only STA mode support TM now
2963 * all other mode, TM feature should be disabled */
2964 if ( (pHddCtx->cfg_ini->thermalMitigationEnable) &&
2965 (~VOS_STA & pHddCtx->concurrency_mode) )
2966 {
2967 hddDevTmLevelChangedHandler(pHddCtx->parent_dev, 0);
2968 }
2969
Jeff Johnson295189b2012-06-20 16:38:30 -07002970#ifdef WLAN_BTAMP_FEATURE
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302971 if((NL80211_IFTYPE_STATION == type) && (pHddCtx->concurrency_mode <= 1) &&
Jeff Johnson295189b2012-06-20 16:38:30 -07002972 (pHddCtx->no_of_sessions[WLAN_HDD_INFRA_STATION] <=1))
2973 {
2974 //we are ok to do AMP
2975 pHddCtx->isAmpAllowed = VOS_TRUE;
2976 }
2977#endif //WLAN_BTAMP_FEATURE
2978 EXIT();
2979 return 0;
2980}
2981
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002982#ifdef FEATURE_WLAN_TDLS
2983static int wlan_hdd_tdls_add_station(struct wiphy *wiphy,
2984 struct net_device *dev, u8 *mac, bool update, tCsrStaParams *StaParams)
2985{
2986 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
2987 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
2988 VOS_STATUS status;
Hoonki Lee5305c3a2013-04-29 23:28:59 -07002989 hddTdlsPeer_t *pTdlsPeer;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002990
2991 ENTER();
2992
Gopichand Nakkala838be5d2013-04-10 22:41:51 +05302993 if (NULL == pHddCtx || NULL == pHddCtx->cfg_ini)
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002994 {
2995 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2996 "Invalid arguments");
2997 return -EINVAL;
2998 }
Hoonki Lee27511902013-03-14 18:19:06 -07002999
3000 if ((eTDLS_SUPPORT_NOT_ENABLED == pHddCtx->tdls_mode) ||
3001 (eTDLS_SUPPORT_DISABLED == pHddCtx->tdls_mode))
3002 {
3003 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3004 "%s: TDLS mode is disabled OR not enabled in FW."
3005 MAC_ADDRESS_STR " Request declined.",
3006 __func__, MAC_ADDR_ARRAY(mac));
3007 return -ENOTSUPP;
3008 }
3009
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003010 if (pHddCtx->isLogpInProgress)
3011 {
3012 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3013 "%s:LOGP in Progress. Ignore!!!", __func__);
Gopichand Nakkala05922802013-03-14 12:23:19 -07003014 wlan_hdd_tdls_set_link_status(pAdapter, mac, eTDLS_LINK_IDLE);
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003015 return -EBUSY;
3016 }
3017
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05303018 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, mac, TRUE);
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003019
3020 if ( NULL == pTdlsPeer ) {
3021 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3022 "%s: " MAC_ADDRESS_STR " (update %d) not exist. return invalid",
3023 __func__, MAC_ADDR_ARRAY(mac), update);
3024 return -EINVAL;
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07003025 }
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003026
3027 /* in add station, we accept existing valid staId if there is */
3028 if ((0 == update) &&
3029 ((pTdlsPeer->link_status >= eTDLS_LINK_CONNECTING) ||
3030 (TDLS_STA_INDEX_VALID(pTdlsPeer->staId))))
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003031 {
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003032 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003033 "%s: " MAC_ADDRESS_STR
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003034 " link_status %d. staId %d. add station ignored.",
3035 __func__, MAC_ADDR_ARRAY(mac), pTdlsPeer->link_status, pTdlsPeer->staId);
3036 return 0;
3037 }
3038 /* in change station, we accept only when staId is valid */
3039 if ((1 == update) &&
3040 ((pTdlsPeer->link_status > eTDLS_LINK_CONNECTING) ||
3041 (!TDLS_STA_INDEX_VALID(pTdlsPeer->staId))))
3042 {
3043 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3044 "%s: " MAC_ADDRESS_STR
3045 " link status %d. staId %d. change station %s.",
3046 __func__, MAC_ADDR_ARRAY(mac), pTdlsPeer->link_status, pTdlsPeer->staId,
3047 (TDLS_STA_INDEX_VALID(pTdlsPeer->staId)) ? "ignored" : "declined");
3048 return (TDLS_STA_INDEX_VALID(pTdlsPeer->staId)) ? 0 : -EPERM;
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003049 }
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07003050
3051 /* when others are on-going, we want to change link_status to idle */
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05303052 if (NULL != wlan_hdd_tdls_is_progress(pHddCtx, mac, TRUE))
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003053 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07003054 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3055 "%s: " MAC_ADDRESS_STR
3056 " TDLS setup is ongoing. Request declined.",
3057 __func__, MAC_ADDR_ARRAY(mac));
Gopichand Nakkala05922802013-03-14 12:23:19 -07003058 goto error;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003059 }
3060
3061 /* first to check if we reached to maximum supported TDLS peer.
3062 TODO: for now, return -EPERM looks working fine,
3063 but need to check if any other errno fit into this category.*/
3064 if (HDD_MAX_NUM_TDLS_STA <= wlan_hdd_tdlsConnectedPeers(pAdapter))
3065 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07003066 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3067 "%s: " MAC_ADDRESS_STR
3068 " TDLS Max peer already connected. Request declined.",
3069 __func__, MAC_ADDR_ARRAY(mac));
Gopichand Nakkala05922802013-03-14 12:23:19 -07003070 goto error;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003071 }
3072 else
3073 {
3074 hddTdlsPeer_t *pTdlsPeer;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05303075 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, mac, TRUE);
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003076 if (pTdlsPeer && TDLS_IS_CONNECTED(pTdlsPeer))
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003077 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07003078 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3079 "%s: " MAC_ADDRESS_STR " already connected. Request declined.",
3080 __func__, MAC_ADDR_ARRAY(mac));
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003081 return -EPERM;
3082 }
3083 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003084 if (0 == update)
3085 wlan_hdd_tdls_set_link_status(pAdapter, mac, eTDLS_LINK_CONNECTING);
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003086
Jeff Johnsond75fe012013-04-06 10:53:06 -07003087 /* debug code */
Gopichand Nakkala838be5d2013-04-10 22:41:51 +05303088 if (NULL != StaParams)
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003089 {
3090 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3091 "%s: TDLS Peer Parameters.", __func__);
Hoonki Lee66b75f32013-04-16 18:30:07 -07003092 if(StaParams->htcap_present)
3093 {
3094 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3095 "ht_capa->cap_info: %0x", StaParams->HTCap.capInfo);
3096 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3097 "ht_capa->extended_capabilities: %0x",
3098 StaParams->HTCap.extendedHtCapInfo);
3099 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003100 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3101 "params->capability: %0x",StaParams->capability);
3102 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3103 "params->ext_capab_len: %0x",StaParams->extn_capability);
Hoonki Lee66b75f32013-04-16 18:30:07 -07003104 if(StaParams->vhtcap_present)
3105 {
3106 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3107 "rxMcsMap %x rxHighest %x txMcsMap %x txHighest %x",
3108 StaParams->VHTCap.suppMcs.rxMcsMap, StaParams->VHTCap.suppMcs.rxHighest,
3109 StaParams->VHTCap.suppMcs.txMcsMap, StaParams->VHTCap.suppMcs.txHighest);
3110 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003111 {
3112 int i = 0;
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003113 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "Supported rates:");
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003114 for (i = 0; i < sizeof(StaParams->supported_rates); i++)
3115 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3116 "[%d]: %x ", i, StaParams->supported_rates[i]);
3117 }
Jeff Johnsond75fe012013-04-06 10:53:06 -07003118 } /* end debug code */
Gopichand Nakkala838be5d2013-04-10 22:41:51 +05303119 else if ((1 == update) && (NULL == StaParams))
3120 {
3121 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3122 "%s : update is true, but staParams is NULL. Error!", __func__);
3123 return -EPERM;
3124 }
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003125
3126 INIT_COMPLETION(pAdapter->tdls_add_station_comp);
3127
3128 if (!update)
3129 {
3130 status = sme_AddTdlsPeerSta(WLAN_HDD_GET_HAL_CTX(pAdapter),
3131 pAdapter->sessionId, mac);
3132 }
3133 else
3134 {
3135 status = sme_ChangeTdlsPeerSta(WLAN_HDD_GET_HAL_CTX(pAdapter),
3136 pAdapter->sessionId, mac, StaParams);
3137 }
3138
3139 status = wait_for_completion_interruptible_timeout(&pAdapter->tdls_add_station_comp,
3140 msecs_to_jiffies(WAIT_TIME_TDLS_ADD_STA));
3141
3142 if (!status)
3143 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07003144 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003145 "%s: timeout waiting for tdls add station indication",
3146 __func__);
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07003147 return -EPERM;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003148 }
3149 if ( eHAL_STATUS_SUCCESS != pAdapter->tdlsAddStaStatus)
3150 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07003151 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003152 "%s: Add Station is unsucessful", __func__);
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07003153 return -EPERM;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003154 }
3155
3156 return 0;
Gopichand Nakkala05922802013-03-14 12:23:19 -07003157
3158error:
3159 wlan_hdd_tdls_set_link_status(pAdapter, mac, eTDLS_LINK_IDLE);
3160 return -EPERM;
3161
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003162}
3163#endif
3164
Jeff Johnson295189b2012-06-20 16:38:30 -07003165static int wlan_hdd_change_station(struct wiphy *wiphy,
3166 struct net_device *dev,
3167 u8 *mac,
3168 struct station_parameters *params)
3169{
3170 VOS_STATUS status = VOS_STATUS_SUCCESS;
3171 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Gopichand Nakkala29149562013-05-10 21:43:41 +05303172 hdd_context_t *pHddCtx;
3173 hdd_station_ctx_t *pHddStaCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07003174 v_MACADDR_t STAMacAddress;
Gopichand Nakkalab0856222013-03-12 22:39:05 -07003175#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003176 tCsrStaParams StaParams = {0};
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003177 tANI_U8 isBufSta = 0;
Gopichand Nakkalab0856222013-03-12 22:39:05 -07003178#endif
Jeff Johnsone7245742012-09-05 17:12:55 -07003179 ENTER();
3180
Gopichand Nakkala29149562013-05-10 21:43:41 +05303181 if ((NULL == pAdapter))
3182 {
3183 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
3184 "invalid adapter ");
3185 return -EINVAL;
3186 }
3187
3188 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
3189 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3190
3191 if ((NULL == pHddCtx) || (NULL == pHddStaCtx))
3192 {
3193 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
3194 "invalid HDD state or HDD station context");
3195 return -EINVAL;
3196 }
3197
3198 if (pHddCtx->isLogpInProgress)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003199 {
3200 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3201 "%s:LOGP in Progress. Ignore!!!", __func__);
3202 return -EAGAIN;
3203 }
3204
Jeff Johnson295189b2012-06-20 16:38:30 -07003205 vos_mem_copy(STAMacAddress.bytes, mac, sizeof(v_MACADDR_t));
3206
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003207 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
3208 || (pAdapter->device_mode == WLAN_HDD_P2P_GO))
Jeff Johnson295189b2012-06-20 16:38:30 -07003209 {
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003210 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED))
Jeff Johnson295189b2012-06-20 16:38:30 -07003211 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303212 status = hdd_softap_change_STA_state( pAdapter, &STAMacAddress,
Jeff Johnson295189b2012-06-20 16:38:30 -07003213 WLANTL_STA_AUTHENTICATED);
3214
Gopichand Nakkala29149562013-05-10 21:43:41 +05303215 if (status != VOS_STATUS_SUCCESS)
3216 {
3217 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3218 "%s: Not able to change TL state to AUTHENTICATED", __func__);
3219 return -EINVAL;
3220 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003221 }
3222 }
Hoonki Leea6d49be2013-04-05 09:43:25 -07003223 else if ((pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
3224 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)) {
Gopichand Nakkala29149562013-05-10 21:43:41 +05303225#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003226 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
3227 StaParams.capability = params->capability;
3228 StaParams.uapsd_queues = params->uapsd_queues;
3229 StaParams.max_sp = params->max_sp;
3230
3231 if (0 != params->ext_capab_len)
3232 vos_mem_copy(StaParams.extn_capability, params->ext_capab,
3233 sizeof(StaParams.extn_capability));
3234
3235 if (NULL != params->ht_capa)
Hoonki Lee66b75f32013-04-16 18:30:07 -07003236 {
3237 StaParams.htcap_present = 1;
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003238 vos_mem_copy(&StaParams.HTCap, params->ht_capa, sizeof(tSirHTCap));
Hoonki Lee66b75f32013-04-16 18:30:07 -07003239 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003240
3241 StaParams.supported_rates_len = params->supported_rates_len;
3242
3243 /* Note : The Maximum sizeof supported_rates sent by the Supplicant is 32.
3244 * The supported_rates array , for all the structures propogating till Add Sta
3245 * to the firmware has to be modified , if the supplicant (ieee80211) is
3246 * modified to send more rates.
3247 */
3248
3249 /* To avoid Data Currption , set to max length to SIR_MAC_MAX_SUPP_RATES
3250 */
3251 if (StaParams.supported_rates_len > SIR_MAC_MAX_SUPP_RATES)
3252 StaParams.supported_rates_len = SIR_MAC_MAX_SUPP_RATES;
3253
3254 if (0 != StaParams.supported_rates_len) {
3255 int i = 0;
3256 vos_mem_copy(StaParams.supported_rates, params->supported_rates,
3257 StaParams.supported_rates_len);
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003258 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003259 "Supported Rates with Length %d", StaParams.supported_rates_len);
3260 for (i=0; i < StaParams.supported_rates_len; i++)
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003261 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003262 "[%d]: %0x", i, StaParams.supported_rates[i]);
3263 }
3264
3265 if (NULL != params->vht_capa)
Hoonki Lee66b75f32013-04-16 18:30:07 -07003266 {
3267 StaParams.vhtcap_present = 1;
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003268 vos_mem_copy(&StaParams.VHTCap, params->vht_capa, sizeof(tSirVHTCap));
Hoonki Lee66b75f32013-04-16 18:30:07 -07003269 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003270
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003271 if (0 != params->ext_capab_len ) {
3272 /*Define A Macro : TODO Sunil*/
3273 if ((1<<4) & StaParams.extn_capability[3]) {
3274 isBufSta = 1;
3275 }
3276 }
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05303277 status = wlan_hdd_tdls_set_peer_caps( pAdapter, mac, params->uapsd_queues,
3278 params->max_sp, isBufSta);
3279 if (VOS_STATUS_SUCCESS != status) {
3280 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3281 "%s: wlan_hdd_tdls_set_peer_caps failed!", __func__);
3282 return -EINVAL;
3283 }
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003284 status = wlan_hdd_tdls_add_station(wiphy, dev, mac, 1, &StaParams);
3285
3286 if (VOS_STATUS_SUCCESS != status) {
3287 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3288 "%s: sme_ChangeTdlsPeerSta failed!", __func__);
3289 return -EINVAL;
3290 }
3291 }
Gopichand Nakkalab0856222013-03-12 22:39:05 -07003292#endif
Gopichand Nakkala6239acd2013-06-14 14:48:00 +05303293 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003294 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07003295 return status;
3296}
3297
3298/*
Jeff Johnson295189b2012-06-20 16:38:30 -07003299 * FUNCTION: wlan_hdd_cfg80211_add_key
3300 * This function is used to initialize the key information
3301 */
3302#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003303static int wlan_hdd_cfg80211_add_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003304 struct net_device *ndev,
3305 u8 key_index, bool pairwise,
3306 const u8 *mac_addr,
3307 struct key_params *params
3308 )
3309#else
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003310static int wlan_hdd_cfg80211_add_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003311 struct net_device *ndev,
3312 u8 key_index, const u8 *mac_addr,
3313 struct key_params *params
3314 )
3315#endif
3316{
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003317 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Jeff Johnson295189b2012-06-20 16:38:30 -07003318 tCsrRoamSetKey setKey;
3319 u8 groupmacaddr[WNI_CFG_BSSID_LEN] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303320 int status;
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003321 v_U32_t roamId= 0xFF;
3322 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
Jeff Johnson295189b2012-06-20 16:38:30 -07003323 hdd_hostapd_state_t *pHostapdState;
3324 VOS_STATUS vos_status;
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003325 eHalStatus halStatus;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303326 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07003327
3328 ENTER();
3329
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303330 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
3331 status = wlan_hdd_validate_context(pHddCtx);
3332
3333 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003334 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303335 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3336 "%s: HDD context is not valid", __func__);
3337 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003338 }
3339
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003340 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
3341 __func__, pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07003342
3343 if (CSR_MAX_NUM_KEY <= key_index)
3344 {
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003345 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key index %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07003346 key_index);
3347
3348 return -EINVAL;
3349 }
3350
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003351 if (CSR_MAX_KEY_LEN < params->key_len)
3352 {
3353 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key length %d", __func__,
3354 params->key_len);
3355
3356 return -EINVAL;
3357 }
3358
3359 hddLog(VOS_TRACE_LEVEL_INFO,
3360 "%s: called with key index = %d & key length %d",
3361 __func__, key_index, params->key_len);
Jeff Johnson295189b2012-06-20 16:38:30 -07003362
3363 /*extract key idx, key len and key*/
3364 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
3365 setKey.keyId = key_index;
3366 setKey.keyLength = params->key_len;
3367 vos_mem_copy(&setKey.Key[0],params->key, params->key_len);
3368
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003369 switch (params->cipher)
Jeff Johnson295189b2012-06-20 16:38:30 -07003370 {
3371 case WLAN_CIPHER_SUITE_WEP40:
3372 setKey.encType = eCSR_ENCRYPT_TYPE_WEP40_STATICKEY;
3373 break;
3374
3375 case WLAN_CIPHER_SUITE_WEP104:
3376 setKey.encType = eCSR_ENCRYPT_TYPE_WEP104_STATICKEY;
3377 break;
3378
3379 case WLAN_CIPHER_SUITE_TKIP:
3380 {
3381 u8 *pKey = &setKey.Key[0];
3382 setKey.encType = eCSR_ENCRYPT_TYPE_TKIP;
3383
3384 vos_mem_zero(pKey, CSR_MAX_KEY_LEN);
3385
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003386 /*Supplicant sends the 32bytes key in this order
Jeff Johnson295189b2012-06-20 16:38:30 -07003387
3388 |--------------|----------|----------|
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003389 | Tk1 |TX-MIC | RX Mic |
Jeff Johnson295189b2012-06-20 16:38:30 -07003390 |--------------|----------|----------|
3391 <---16bytes---><--8bytes--><--8bytes-->
3392
3393 */
3394 /*Sme expects the 32 bytes key to be in the below order
3395
3396 |--------------|----------|----------|
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003397 | Tk1 |RX-MIC | TX Mic |
Jeff Johnson295189b2012-06-20 16:38:30 -07003398 |--------------|----------|----------|
3399 <---16bytes---><--8bytes--><--8bytes-->
3400 */
3401 /* Copy the Temporal Key 1 (TK1) */
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003402 vos_mem_copy(pKey, params->key, 16);
Jeff Johnson295189b2012-06-20 16:38:30 -07003403
3404 /*Copy the rx mic first*/
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003405 vos_mem_copy(&pKey[16], &params->key[24], 8);
Jeff Johnson295189b2012-06-20 16:38:30 -07003406
3407 /*Copy the tx mic */
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003408 vos_mem_copy(&pKey[24], &params->key[16], 8);
Jeff Johnson295189b2012-06-20 16:38:30 -07003409
3410
3411 break;
3412 }
3413
3414 case WLAN_CIPHER_SUITE_CCMP:
3415 setKey.encType = eCSR_ENCRYPT_TYPE_AES;
3416 break;
3417
3418#ifdef FEATURE_WLAN_WAPI
3419 case WLAN_CIPHER_SUITE_SMS4:
3420 {
3421 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
3422 wlan_hdd_cfg80211_set_key_wapi(pAdapter, key_index, mac_addr,
3423 params->key, params->key_len);
3424 return 0;
3425 }
3426#endif
Chet Lanctot186b5732013-03-18 10:26:30 -07003427
Jeff Johnson295189b2012-06-20 16:38:30 -07003428#ifdef FEATURE_WLAN_CCX
3429 case WLAN_CIPHER_SUITE_KRK:
3430 setKey.encType = eCSR_ENCRYPT_TYPE_KRK;
3431 break;
3432#endif
Chet Lanctot186b5732013-03-18 10:26:30 -07003433
3434#ifdef WLAN_FEATURE_11W
3435 case WLAN_CIPHER_SUITE_AES_CMAC:
3436 setKey.encType = eCSR_ENCRYPT_TYPE_AES_CMAC;
Chet Lanctot3b5158a2013-03-31 16:45:21 -07003437 break;
Chet Lanctot186b5732013-03-18 10:26:30 -07003438#endif
3439
Jeff Johnson295189b2012-06-20 16:38:30 -07003440 default:
3441 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: unsupported cipher type %lu",
3442 __func__, params->cipher);
3443 return -EOPNOTSUPP;
3444 }
3445
3446 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: encryption type %d",
3447 __func__, setKey.encType);
3448
Shailender Karmuchi642e9812013-05-30 14:34:49 -07003449 if (
Jeff Johnson295189b2012-06-20 16:38:30 -07003450#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
3451 (!pairwise)
3452#else
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003453 (!mac_addr || is_broadcast_ether_addr(mac_addr))
Jeff Johnson295189b2012-06-20 16:38:30 -07003454#endif
Shailender Karmuchi642e9812013-05-30 14:34:49 -07003455 )
3456 {
3457 /* set group key*/
3458 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3459 "%s- %d: setting Broadcast key",
3460 __func__, __LINE__);
3461 setKey.keyDirection = eSIR_RX_ONLY;
3462 vos_mem_copy(setKey.peerMac,groupmacaddr,WNI_CFG_BSSID_LEN);
3463 }
3464 else
3465 {
3466 /* set pairwise key*/
3467 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3468 "%s- %d: setting pairwise key",
3469 __func__, __LINE__);
3470 setKey.keyDirection = eSIR_TX_RX;
3471 vos_mem_copy(setKey.peerMac, mac_addr,WNI_CFG_BSSID_LEN);
3472 }
3473 if ((WLAN_HDD_IBSS == pAdapter->device_mode) && !pairwise)
3474 {
3475 setKey.keyDirection = eSIR_TX_RX;
3476 /*Set the group key*/
3477 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
3478 pAdapter->sessionId, &setKey, &roamId );
Jeff Johnson295189b2012-06-20 16:38:30 -07003479
Shailender Karmuchi642e9812013-05-30 14:34:49 -07003480 if ( 0 != status )
3481 {
3482 hddLog(VOS_TRACE_LEVEL_ERROR,
3483 "%s: sme_RoamSetKey failed, returned %d", __func__, status);
3484 return -EINVAL;
3485 }
3486 /*Save the keys here and call sme_RoamSetKey for setting
3487 the PTK after peer joins the IBSS network*/
3488 vos_mem_copy(&pAdapter->sessionCtx.station.ibss_enc_key,
3489 &setKey, sizeof(tCsrRoamSetKey));
3490 return status;
3491 }
Gopichand Nakkala29149562013-05-10 21:43:41 +05303492 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP) ||
3493 (pAdapter->device_mode == WLAN_HDD_P2P_GO))
3494 {
Jeff Johnson295189b2012-06-20 16:38:30 -07003495 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003496 if( pHostapdState->bssState == BSS_START )
3497 {
Jeff Johnson295189b2012-06-20 16:38:30 -07003498 status = WLANSAP_SetKeySta( pVosContext, &setKey);
3499
3500 if ( status != eHAL_STATUS_SUCCESS )
3501 {
3502 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3503 "[%4d] WLANSAP_SetKeySta returned ERROR status= %d",
3504 __LINE__, status );
3505 }
3506 }
3507
3508 /* Saving WEP keys */
3509 else if( eCSR_ENCRYPT_TYPE_WEP40_STATICKEY == setKey.encType ||
3510 eCSR_ENCRYPT_TYPE_WEP104_STATICKEY == setKey.encType )
3511 {
3512 //Save the wep key in ap context. Issue setkey after the BSS is started.
3513 hdd_ap_ctx_t *pAPCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
3514 vos_mem_copy(&pAPCtx->wepKey[key_index], &setKey, sizeof(tCsrRoamSetKey));
3515 }
3516 else
3517 {
3518 //Save the key in ap context. Issue setkey after the BSS is started.
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003519 hdd_ap_ctx_t *pAPCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07003520 vos_mem_copy(&pAPCtx->groupKey, &setKey, sizeof(tCsrRoamSetKey));
3521 }
3522 }
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003523 else if ( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION) ||
3524 (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003525 {
3526 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
3527 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3528
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303529#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
3530 if (!pairwise)
3531#else
3532 if (!mac_addr || is_broadcast_ether_addr(mac_addr))
3533#endif
3534 {
3535 /* set group key*/
3536 if (pHddStaCtx->roam_info.deferKeyComplete)
3537 {
3538 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3539 "%s- %d: Perform Set key Complete",
3540 __func__, __LINE__);
3541 hdd_PerformRoamSetKeyComplete(pAdapter);
3542 }
3543 }
3544
Jeff Johnson295189b2012-06-20 16:38:30 -07003545 pWextState->roamProfile.Keys.KeyLength[key_index] = (u8)params->key_len;
3546
Venkata Prathyusha Kuntupalliee2ce712013-01-17 14:09:24 -08003547 pWextState->roamProfile.Keys.defaultIndex = key_index;
3548
3549
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003550 vos_mem_copy(&pWextState->roamProfile.Keys.KeyMaterial[key_index][0],
Jeff Johnson295189b2012-06-20 16:38:30 -07003551 params->key, params->key_len);
3552
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303553
Jeff Johnson295189b2012-06-20 16:38:30 -07003554 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_SETTING_KEY;
3555
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303556 hddLog(VOS_TRACE_LEVEL_INFO_MED,
Jeff Johnson295189b2012-06-20 16:38:30 -07003557 "%s: set key for peerMac %2x:%2x:%2x:%2x:%2x:%2x, direction %d",
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303558 __func__, setKey.peerMac[0], setKey.peerMac[1],
3559 setKey.peerMac[2], setKey.peerMac[3],
3560 setKey.peerMac[4], setKey.peerMac[5],
Jeff Johnson295189b2012-06-20 16:38:30 -07003561 setKey.keyDirection);
3562
3563 vos_status = wlan_hdd_check_ula_done(pAdapter);
3564
3565 if ( vos_status != VOS_STATUS_SUCCESS )
3566 {
3567 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3568 "[%4d] wlan_hdd_check_ula_done returned ERROR status= %d",
3569 __LINE__, vos_status );
3570
3571 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3572
3573 return -EINVAL;
3574
3575 }
3576
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003577#ifdef WLAN_FEATURE_VOWIFI_11R
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303578 /* The supplicant may attempt to set the PTK once pre-authentication
3579 is done. Save the key in the UMAC and include it in the ADD BSS
3580 request */
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003581 halStatus = sme_FTUpdateKey( WLAN_HDD_GET_HAL_CTX(pAdapter), &setKey);
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303582 if ( halStatus == eHAL_STATUS_FT_PREAUTH_KEY_SUCCESS )
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003583 {
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303584 hddLog(VOS_TRACE_LEVEL_INFO_MED,
3585 "%s: Update PreAuth Key success", __func__);
3586 return 0;
3587 }
3588 else if ( halStatus == eHAL_STATUS_FT_PREAUTH_KEY_FAILED )
3589 {
3590 hddLog(VOS_TRACE_LEVEL_ERROR,
3591 "%s: Update PreAuth Key failed", __func__);
Gopichand Nakkalad7d13652013-02-15 01:48:00 +05303592 return -EINVAL;
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003593 }
3594#endif /* WLAN_FEATURE_VOWIFI_11R */
Jeff Johnson295189b2012-06-20 16:38:30 -07003595
3596 /* issue set key request to SME*/
3597 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
3598 pAdapter->sessionId, &setKey, &roamId );
3599
3600 if ( 0 != status )
3601 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303602 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07003603 "%s: sme_RoamSetKey failed, returned %d", __func__, status);
3604 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3605 return -EINVAL;
3606 }
3607
3608
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303609 /* in case of IBSS as there was no information available about WEP keys during
3610 * IBSS join, group key intialized with NULL key, so re-initialize group key
Jeff Johnson295189b2012-06-20 16:38:30 -07003611 * with correct value*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303612 if ( (eCSR_BSS_TYPE_START_IBSS == pWextState->roamProfile.BSSType) &&
3613 !( ( IW_AUTH_KEY_MGMT_802_1X
3614 == (pWextState->authKeyMgmt & IW_AUTH_KEY_MGMT_802_1X))
Jeff Johnson295189b2012-06-20 16:38:30 -07003615 && (eCSR_AUTH_TYPE_OPEN_SYSTEM == pHddStaCtx->conn_info.authType)
3616 )
3617 &&
3618 ( (WLAN_CIPHER_SUITE_WEP40 == params->cipher)
3619 || (WLAN_CIPHER_SUITE_WEP104 == params->cipher)
3620 )
3621 )
3622 {
3623 setKey.keyDirection = eSIR_RX_ONLY;
3624 vos_mem_copy(setKey.peerMac,groupmacaddr,WNI_CFG_BSSID_LEN);
3625
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303626 hddLog(VOS_TRACE_LEVEL_INFO_MED,
Jeff Johnson295189b2012-06-20 16:38:30 -07003627 "%s: set key peerMac %2x:%2x:%2x:%2x:%2x:%2x, direction %d",
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303628 __func__, setKey.peerMac[0], setKey.peerMac[1],
3629 setKey.peerMac[2], setKey.peerMac[3],
3630 setKey.peerMac[4], setKey.peerMac[5],
Jeff Johnson295189b2012-06-20 16:38:30 -07003631 setKey.keyDirection);
3632
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303633 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07003634 pAdapter->sessionId, &setKey, &roamId );
3635
3636 if ( 0 != status )
3637 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303638 hddLog(VOS_TRACE_LEVEL_ERROR,
3639 "%s: sme_RoamSetKey failed for group key (IBSS), returned %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07003640 __func__, status);
3641 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3642 return -EINVAL;
3643 }
3644 }
3645 }
3646
3647 return 0;
3648}
3649
3650/*
3651 * FUNCTION: wlan_hdd_cfg80211_get_key
3652 * This function is used to get the key information
3653 */
3654#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303655static int wlan_hdd_cfg80211_get_key(
3656 struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003657 struct net_device *ndev,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303658 u8 key_index, bool pairwise,
Jeff Johnson295189b2012-06-20 16:38:30 -07003659 const u8 *mac_addr, void *cookie,
3660 void (*callback)(void *cookie, struct key_params*)
3661 )
3662#else
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303663static int wlan_hdd_cfg80211_get_key(
3664 struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003665 struct net_device *ndev,
3666 u8 key_index, const u8 *mac_addr, void *cookie,
3667 void (*callback)(void *cookie, struct key_params*)
3668 )
3669#endif
3670{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303671 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Jeff Johnson295189b2012-06-20 16:38:30 -07003672 hdd_wext_state_t *pWextState= WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
3673 tCsrRoamProfile *pRoamProfile = &(pWextState->roamProfile);
3674 struct key_params params;
3675
3676 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303677
Jeff Johnson295189b2012-06-20 16:38:30 -07003678 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
3679 __func__,pAdapter->device_mode);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303680
Jeff Johnson295189b2012-06-20 16:38:30 -07003681 memset(&params, 0, sizeof(params));
3682
3683 if (CSR_MAX_NUM_KEY <= key_index)
3684 {
3685 return -EINVAL;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303686 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003687
3688 switch(pRoamProfile->EncryptionType.encryptionType[0])
3689 {
3690 case eCSR_ENCRYPT_TYPE_NONE:
3691 params.cipher = IW_AUTH_CIPHER_NONE;
3692 break;
3693
3694 case eCSR_ENCRYPT_TYPE_WEP40_STATICKEY:
3695 case eCSR_ENCRYPT_TYPE_WEP40:
3696 params.cipher = WLAN_CIPHER_SUITE_WEP40;
3697 break;
3698
3699 case eCSR_ENCRYPT_TYPE_WEP104_STATICKEY:
3700 case eCSR_ENCRYPT_TYPE_WEP104:
3701 params.cipher = WLAN_CIPHER_SUITE_WEP104;
3702 break;
3703
3704 case eCSR_ENCRYPT_TYPE_TKIP:
3705 params.cipher = WLAN_CIPHER_SUITE_TKIP;
3706 break;
3707
3708 case eCSR_ENCRYPT_TYPE_AES:
3709 params.cipher = WLAN_CIPHER_SUITE_AES_CMAC;
3710 break;
3711
3712 default:
3713 params.cipher = IW_AUTH_CIPHER_NONE;
3714 break;
3715 }
3716
3717 params.key_len = pRoamProfile->Keys.KeyLength[key_index];
3718 params.seq_len = 0;
3719 params.seq = NULL;
3720 params.key = &pRoamProfile->Keys.KeyMaterial[key_index][0];
3721 callback(cookie, &params);
3722 return 0;
3723}
3724
3725/*
3726 * FUNCTION: wlan_hdd_cfg80211_del_key
3727 * This function is used to delete the key information
3728 */
3729#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303730static int wlan_hdd_cfg80211_del_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003731 struct net_device *ndev,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303732 u8 key_index,
3733 bool pairwise,
Jeff Johnson295189b2012-06-20 16:38:30 -07003734 const u8 *mac_addr
3735 )
3736#else
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303737static int wlan_hdd_cfg80211_del_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003738 struct net_device *ndev,
3739 u8 key_index,
3740 const u8 *mac_addr
3741 )
3742#endif
3743{
3744 int status = 0;
3745
3746 //This code needs to be revisited. There is sme_removeKey API, we should
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303747 //plan to use that. After the change to use correct index in setkey,
Jeff Johnson295189b2012-06-20 16:38:30 -07003748 //it is observed that this is invalidating peer
3749 //key index whenever re-key is done. This is affecting data link.
3750 //It should be ok to ignore del_key.
3751#if 0
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303752 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
3753 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
Jeff Johnson295189b2012-06-20 16:38:30 -07003754 u8 groupmacaddr[WNI_CFG_BSSID_LEN] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
3755 tCsrRoamSetKey setKey;
3756 v_U32_t roamId= 0xFF;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303757
Jeff Johnson295189b2012-06-20 16:38:30 -07003758 ENTER();
3759
3760 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: device_mode = %d\n",
3761 __func__,pAdapter->device_mode);
3762
3763 if (CSR_MAX_NUM_KEY <= key_index)
3764 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303765 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key index %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07003766 key_index);
3767
3768 return -EINVAL;
3769 }
3770
3771 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
3772 setKey.keyId = key_index;
3773
3774 if (mac_addr)
3775 vos_mem_copy(setKey.peerMac, mac_addr,WNI_CFG_BSSID_LEN);
3776 else
3777 vos_mem_copy(setKey.peerMac, groupmacaddr, WNI_CFG_BSSID_LEN);
3778
3779 setKey.encType = eCSR_ENCRYPT_TYPE_NONE;
3780
3781 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07003782 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303783 )
3784 {
3785
3786 hdd_hostapd_state_t *pHostapdState =
Jeff Johnson295189b2012-06-20 16:38:30 -07003787 WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
3788 if( pHostapdState->bssState == BSS_START)
3789 {
3790 status = WLANSAP_SetKeySta( pVosContext, &setKey);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303791
Jeff Johnson295189b2012-06-20 16:38:30 -07003792 if ( status != eHAL_STATUS_SUCCESS )
3793 {
3794 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3795 "[%4d] WLANSAP_SetKeySta returned ERROR status= %d",
3796 __LINE__, status );
3797 }
3798 }
3799 }
3800 else if ( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303801 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Jeff Johnson295189b2012-06-20 16:38:30 -07003802 )
3803 {
3804 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3805
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303806 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_SETTING_KEY;
3807
3808 hddLog(VOS_TRACE_LEVEL_INFO_MED,
Jeff Johnson295189b2012-06-20 16:38:30 -07003809 "%s: delete key for peerMac %2x:%2x:%2x:%2x:%2x:%2x",
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303810 __func__, setKey.peerMac[0], setKey.peerMac[1],
3811 setKey.peerMac[2], setKey.peerMac[3],
Jeff Johnson295189b2012-06-20 16:38:30 -07003812 setKey.peerMac[4], setKey.peerMac[5]);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303813 if(pAdapter->sessionCtx.station.conn_info.connState ==
3814 eConnectionState_Associated)
Jeff Johnson295189b2012-06-20 16:38:30 -07003815 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303816 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07003817 pAdapter->sessionId, &setKey, &roamId );
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303818
Jeff Johnson295189b2012-06-20 16:38:30 -07003819 if ( 0 != status )
3820 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303821 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07003822 "%s: sme_RoamSetKey failure, returned %d",
3823 __func__, status);
3824 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3825 return -EINVAL;
3826 }
3827 }
3828 }
3829#endif
Jeff Johnsone7245742012-09-05 17:12:55 -07003830 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07003831 return status;
3832}
3833
3834/*
3835 * FUNCTION: wlan_hdd_cfg80211_set_default_key
3836 * This function is used to set the default tx key index
3837 */
3838#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
3839static int wlan_hdd_cfg80211_set_default_key( struct wiphy *wiphy,
3840 struct net_device *ndev,
3841 u8 key_index,
3842 bool unicast, bool multicast)
3843#else
3844static int wlan_hdd_cfg80211_set_default_key( struct wiphy *wiphy,
3845 struct net_device *ndev,
3846 u8 key_index)
3847#endif
3848{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303849 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303850 int status;
Gopichand Nakkala29149562013-05-10 21:43:41 +05303851 hdd_wext_state_t *pWextState;
3852 hdd_station_ctx_t *pHddStaCtx;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303853 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07003854
3855 ENTER();
3856
Gopichand Nakkala29149562013-05-10 21:43:41 +05303857 if ((NULL == pAdapter))
3858 {
3859 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
3860 "invalid adapter");
3861 return -EINVAL;
3862 }
3863
3864 pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
3865 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3866
3867 if ((NULL == pWextState) || (NULL == pHddStaCtx))
3868 {
3869 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
3870 "invalid Wext state or HDD context");
3871 return -EINVAL;
3872 }
3873
Jeff Johnson295189b2012-06-20 16:38:30 -07003874 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d key_index = %d \n",
3875 __func__,pAdapter->device_mode, key_index);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303876
Jeff Johnson295189b2012-06-20 16:38:30 -07003877 if (CSR_MAX_NUM_KEY <= key_index)
3878 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303879 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key index %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07003880 key_index);
3881
3882 return -EINVAL;
3883 }
3884
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303885 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
3886 status = wlan_hdd_validate_context(pHddCtx);
3887
3888 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003889 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303890 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3891 "%s: HDD context is not valid", __func__);
3892 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003893 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303894
Jeff Johnson295189b2012-06-20 16:38:30 -07003895 if ((pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Jeff Johnson295189b2012-06-20 16:38:30 -07003896 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303897 )
Jeff Johnson295189b2012-06-20 16:38:30 -07003898 {
Gopichand Nakkala29149562013-05-10 21:43:41 +05303899 if ( (eCSR_ENCRYPT_TYPE_TKIP !=
Arif Hussain6943f522013-11-04 20:10:10 -08003900 pHddStaCtx->conn_info.ucEncryptionType) &&
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303901 (eCSR_ENCRYPT_TYPE_AES !=
Arif Hussain6943f522013-11-04 20:10:10 -08003902 pHddStaCtx->conn_info.ucEncryptionType)
Jeff Johnson295189b2012-06-20 16:38:30 -07003903 )
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303904 {
3905 /* if default key index is not same as previous one,
Jeff Johnson295189b2012-06-20 16:38:30 -07003906 * then update the default key index */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303907
Jeff Johnson295189b2012-06-20 16:38:30 -07003908 tCsrRoamSetKey setKey;
3909 v_U32_t roamId= 0xFF;
3910 tCsrKeys *Keys = &pWextState->roamProfile.Keys;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303911
3912 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: default tx key index %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07003913 __func__, key_index);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303914
Jeff Johnson295189b2012-06-20 16:38:30 -07003915 Keys->defaultIndex = (u8)key_index;
3916 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
3917 setKey.keyId = key_index;
3918 setKey.keyLength = Keys->KeyLength[key_index];
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303919
3920 vos_mem_copy(&setKey.Key[0],
3921 &Keys->KeyMaterial[key_index][0],
Jeff Johnson295189b2012-06-20 16:38:30 -07003922 Keys->KeyLength[key_index]);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303923
Gopichand Nakkala29149562013-05-10 21:43:41 +05303924 setKey.keyDirection = eSIR_TX_RX;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303925
3926 vos_mem_copy(setKey.peerMac,
Jeff Johnson295189b2012-06-20 16:38:30 -07003927 &pHddStaCtx->conn_info.bssId[0],
3928 WNI_CFG_BSSID_LEN);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303929
Gopichand Nakkala29149562013-05-10 21:43:41 +05303930 if (Keys->KeyLength[key_index] == CSR_WEP40_KEY_LEN &&
3931 pWextState->roamProfile.EncryptionType.encryptionType[0] ==
3932 eCSR_ENCRYPT_TYPE_WEP104)
3933 {
3934 /*In the case of dynamic wep supplicant hardcodes DWEP type to eCSR_ENCRYPT_TYPE_WEP104
3935 even though ap is configured for WEP-40 encryption. In this canse the key length
3936 is 5 but the encryption type is 104 hence checking the key langht(5) and encryption
3937 type(104) and switching encryption type to 40*/
3938 pWextState->roamProfile.EncryptionType.encryptionType[0] =
3939 eCSR_ENCRYPT_TYPE_WEP40;
3940 pWextState->roamProfile.mcEncryptionType.encryptionType[0] =
3941 eCSR_ENCRYPT_TYPE_WEP40;
3942 }
3943
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303944 setKey.encType =
Jeff Johnson295189b2012-06-20 16:38:30 -07003945 pWextState->roamProfile.EncryptionType.encryptionType[0];
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303946
Jeff Johnson295189b2012-06-20 16:38:30 -07003947 /* issue set key request */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303948 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07003949 pAdapter->sessionId, &setKey, &roamId );
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303950
Jeff Johnson295189b2012-06-20 16:38:30 -07003951 if ( 0 != status )
3952 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303953 hddLog(VOS_TRACE_LEVEL_ERROR,
3954 "%s: sme_RoamSetKey failed, returned %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07003955 status);
3956 return -EINVAL;
3957 }
3958 }
3959 }
3960
3961 /* In SoftAp mode setting key direction for default mode */
3962 else if ( WLAN_HDD_SOFTAP == pAdapter->device_mode )
3963 {
3964 if ( (eCSR_ENCRYPT_TYPE_TKIP !=
3965 pWextState->roamProfile.EncryptionType.encryptionType[0]) &&
3966 (eCSR_ENCRYPT_TYPE_AES !=
3967 pWextState->roamProfile.EncryptionType.encryptionType[0])
3968 )
3969 {
3970 /* Saving key direction for default key index to TX default */
3971 hdd_ap_ctx_t *pAPCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
3972 pAPCtx->wepKey[key_index].keyDirection = eSIR_TX_DEFAULT;
3973 }
3974 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303975
Jeff Johnson295189b2012-06-20 16:38:30 -07003976 return status;
3977}
3978
Jeff Johnson295189b2012-06-20 16:38:30 -07003979/*
3980 * FUNCTION: wlan_hdd_cfg80211_inform_bss
3981 * This function is used to inform the BSS details to nl80211 interface.
3982 */
3983static struct cfg80211_bss* wlan_hdd_cfg80211_inform_bss(
3984 hdd_adapter_t *pAdapter, tCsrRoamConnectedProfile *roamProfile)
3985{
3986 struct net_device *dev = pAdapter->dev;
3987 struct wireless_dev *wdev = dev->ieee80211_ptr;
3988 struct wiphy *wiphy = wdev->wiphy;
3989 tSirBssDescription *pBssDesc = roamProfile->pBssDesc;
3990 int chan_no;
3991 int ie_length;
3992 const char *ie;
3993 unsigned int freq;
3994 struct ieee80211_channel *chan;
3995 int rssi = 0;
3996 struct cfg80211_bss *bss = NULL;
3997
3998 ENTER();
3999
4000 if( NULL == pBssDesc )
4001 {
4002 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: pBssDesc is NULL\n", __func__);
4003 return bss;
4004 }
4005
4006 chan_no = pBssDesc->channelId;
4007 ie_length = GET_IE_LEN_IN_BSS_DESC( pBssDesc->length );
4008 ie = ((ie_length != 0) ? (const char *)&pBssDesc->ieFields: NULL);
4009
4010 if( NULL == ie )
4011 {
4012 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: IE of BSS descriptor is NULL\n", __func__);
4013 return bss;
4014 }
4015
4016#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,38))
4017 if (chan_no <= ARRAY_SIZE(hdd_channels_2_4_GHZ))
4018 {
4019 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_2GHZ);
4020 }
4021 else
4022 {
4023 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_5GHZ);
4024 }
4025#else
4026 freq = ieee80211_channel_to_frequency(chan_no);
4027#endif
4028
4029 chan = __ieee80211_get_channel(wiphy, freq);
4030
4031 bss = cfg80211_get_bss(wiphy, chan, pBssDesc->bssId,
4032 &roamProfile->SSID.ssId[0], roamProfile->SSID.length,
4033 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
4034 if (bss == NULL)
4035 {
4036 rssi = (VOS_MIN ((pBssDesc->rssi + pBssDesc->sinr), 0))*100;
4037
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304038 return (cfg80211_inform_bss(wiphy, chan, pBssDesc->bssId,
4039 le64_to_cpu(*(__le64 *)pBssDesc->timeStamp),
Jeff Johnson295189b2012-06-20 16:38:30 -07004040 pBssDesc->capabilityInfo,
4041 pBssDesc->beaconInterval, ie, ie_length,
4042 rssi, GFP_KERNEL ));
4043}
4044 else
4045 {
4046 return bss;
4047 }
4048}
4049
4050
4051
4052/*
4053 * FUNCTION: wlan_hdd_cfg80211_inform_bss_frame
4054 * This function is used to inform the BSS details to nl80211 interface.
4055 */
4056struct cfg80211_bss*
4057wlan_hdd_cfg80211_inform_bss_frame( hdd_adapter_t *pAdapter,
4058 tSirBssDescription *bss_desc
4059 )
4060{
4061 /*
4062 cfg80211_inform_bss() is not updating ie field of bss entry, if entry
4063 already exists in bss data base of cfg80211 for that particular BSS ID.
4064 Using cfg80211_inform_bss_frame to update the bss entry instead of
4065 cfg80211_inform_bss, But this call expects mgmt packet as input. As of
4066 now there is no possibility to get the mgmt(probe response) frame from PE,
4067 converting bss_desc to ieee80211_mgmt(probe response) and passing to
4068 cfg80211_inform_bss_frame.
4069 */
4070 struct net_device *dev = pAdapter->dev;
4071 struct wireless_dev *wdev = dev->ieee80211_ptr;
4072 struct wiphy *wiphy = wdev->wiphy;
4073 int chan_no = bss_desc->channelId;
Madan Mohan Koyyalamudi86f629e2012-11-09 16:27:29 -08004074#ifdef WLAN_ENABLE_AGEIE_ON_SCAN_RESULTS
4075 qcom_ie_age *qie_age = NULL;
4076 int ie_length = GET_IE_LEN_IN_BSS_DESC( bss_desc->length ) + sizeof(qcom_ie_age);
4077#else
Jeff Johnson295189b2012-06-20 16:38:30 -07004078 int ie_length = GET_IE_LEN_IN_BSS_DESC( bss_desc->length );
Madan Mohan Koyyalamudi86f629e2012-11-09 16:27:29 -08004079#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004080 const char *ie =
4081 ((ie_length != 0) ? (const char *)&bss_desc->ieFields: NULL);
4082 unsigned int freq;
4083 struct ieee80211_channel *chan;
4084 struct ieee80211_mgmt *mgmt =
4085 kzalloc((sizeof (struct ieee80211_mgmt) + ie_length), GFP_KERNEL);
4086 struct cfg80211_bss *bss_status = NULL;
4087 size_t frame_len = sizeof (struct ieee80211_mgmt) + ie_length;
4088 int rssi = 0;
Wilson Yangf80a0542013-10-07 13:02:37 -07004089 hdd_context_t *pHddCtx;
4090 int status;
Jeff Johnsone7245742012-09-05 17:12:55 -07004091#ifdef WLAN_OPEN_SOURCE
4092 struct timespec ts;
4093#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004094
4095 ENTER();
4096
Wilson Yangf80a0542013-10-07 13:02:37 -07004097 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
4098 status = wlan_hdd_validate_context(pHddCtx);
4099
4100 /*bss_update is not allowed during wlan driver loading or unloading*/
4101 if (pHddCtx->isLoadUnloadInProgress)
4102 {
4103 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4104 "%s:Loading_unloading in Progress. Ignore!!!",__func__);
4105 return NULL;
4106 }
4107
4108
4109 if (0 != status)
4110 {
4111 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4112 "%s: HDD context is not valid", __func__);
Madan Mohan Koyyalamudi2e5c9142012-11-02 13:17:48 -07004113 return NULL;
Wilson Yangf80a0542013-10-07 13:02:37 -07004114 }
4115
4116
4117 if (!mgmt)
4118 {
4119 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4120 "%s: memory allocation failed ", __func__);
4121 return NULL;
4122 }
Madan Mohan Koyyalamudi2e5c9142012-11-02 13:17:48 -07004123
Jeff Johnson295189b2012-06-20 16:38:30 -07004124 memcpy(mgmt->bssid, bss_desc->bssId, ETH_ALEN);
Jeff Johnsone7245742012-09-05 17:12:55 -07004125
4126#ifdef WLAN_OPEN_SOURCE
4127 /* Android does not want the timestamp from the frame.
4128 Instead it wants a monotonic increasing value */
4129 get_monotonic_boottime(&ts);
4130 mgmt->u.probe_resp.timestamp =
4131 ((u64)ts.tv_sec * 1000000) + (ts.tv_nsec / 1000);
4132#else
4133 /* keep old behavior for non-open source (for now) */
Jeff Johnson295189b2012-06-20 16:38:30 -07004134 memcpy(&mgmt->u.probe_resp.timestamp, bss_desc->timeStamp,
4135 sizeof (bss_desc->timeStamp));
Jeff Johnsone7245742012-09-05 17:12:55 -07004136
4137#endif
4138
Jeff Johnson295189b2012-06-20 16:38:30 -07004139 mgmt->u.probe_resp.beacon_int = bss_desc->beaconInterval;
4140 mgmt->u.probe_resp.capab_info = bss_desc->capabilityInfo;
Madan Mohan Koyyalamudi86f629e2012-11-09 16:27:29 -08004141
4142#ifdef WLAN_ENABLE_AGEIE_ON_SCAN_RESULTS
4143 /* GPS Requirement: need age ie per entry. Using vendor specific. */
4144 /* Assuming this is the last IE, copy at the end */
4145 ie_length -=sizeof(qcom_ie_age);
4146 qie_age = (qcom_ie_age *)(mgmt->u.probe_resp.variable + ie_length);
4147 qie_age->element_id = QCOM_VENDOR_IE_ID;
4148 qie_age->len = QCOM_VENDOR_IE_AGE_LEN;
4149 qie_age->oui_1 = QCOM_OUI1;
4150 qie_age->oui_2 = QCOM_OUI2;
4151 qie_age->oui_3 = QCOM_OUI3;
4152 qie_age->type = QCOM_VENDOR_IE_AGE_TYPE;
4153 qie_age->age = vos_timer_get_system_ticks() - bss_desc->nReceivedTime;
4154#endif
4155
Jeff Johnson295189b2012-06-20 16:38:30 -07004156 memcpy(mgmt->u.probe_resp.variable, ie, ie_length);
Gopichand Nakkalad908ec82013-05-16 19:32:19 +05304157 if (bss_desc->fProbeRsp)
4158 {
4159 mgmt->frame_control |=
4160 (u16)(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_RESP);
4161 }
4162 else
4163 {
4164 mgmt->frame_control |=
4165 (u16)(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_BEACON);
4166 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004167
4168#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,38))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304169 if (chan_no <= ARRAY_SIZE(hdd_channels_2_4_GHZ) &&
Jeff Johnson295189b2012-06-20 16:38:30 -07004170 (wiphy->bands[IEEE80211_BAND_2GHZ] != NULL))
4171 {
4172 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_2GHZ);
4173 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304174 else if ((chan_no > ARRAY_SIZE(hdd_channels_2_4_GHZ)) &&
Jeff Johnson295189b2012-06-20 16:38:30 -07004175 (wiphy->bands[IEEE80211_BAND_5GHZ] != NULL))
4176
4177 {
4178 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_5GHZ);
4179 }
4180 else
4181 {
4182 kfree(mgmt);
4183 return NULL;
4184 }
4185#else
4186 freq = ieee80211_channel_to_frequency(chan_no);
4187#endif
4188 chan = __ieee80211_get_channel(wiphy, freq);
Leela V Kiran Kumar Reddy90032de2013-01-24 18:33:30 -08004189 /*when the band is changed on the fly using the GUI, three things are done
4190 * 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)
4191 * as part of the scan abort, message willbe queued to PE and we proceed with flushing and changinh the band.
4192 * pe will stop the scanning further and report back the results what ever it had till now by calling the call back function.
4193 * if the time between update band and scandone call back is sufficent enough the band change reflects in SME, SME validates the channels
4194 * and discards the channels correponding to previous band and calls back with zero bss results.
4195 * 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
4196 * all the channels correponding to previous band.this is due to race condition.but those channels are invalid to the new band and so
4197 * this function __ieee80211_get_channel will return NULL.Each time we report scan result with this pointer null warning kernel trace is printed.
4198 * if the scan results contain large number of APs continuosly kernel warning trace is printed and it will lead to apps watch dog bark.
4199 * So drop the bss and continue to next bss.
4200 */
4201 if(chan == NULL)
4202 {
4203 hddLog(VOS_TRACE_LEVEL_INFO, "%s chan pointer is NULL", __func__);
Chilam Ngc4244af2013-04-01 15:37:32 -07004204 kfree(mgmt);
Leela V Kiran Kumar Reddy90032de2013-01-24 18:33:30 -08004205 return NULL;
4206 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004207 /*To keep the rssi icon of the connected AP in the scan window
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304208 *and the rssi icon of the wireless networks in sync
Jeff Johnson295189b2012-06-20 16:38:30 -07004209 * */
4210 if (( eConnectionState_Associated ==
4211 pAdapter->sessionCtx.station.conn_info.connState ) &&
4212 ( VOS_TRUE == vos_mem_compare(bss_desc->bssId,
4213 pAdapter->sessionCtx.station.conn_info.bssId,
4214 WNI_CFG_BSSID_LEN)))
4215 {
4216 /* supplicant takes the signal strength in terms of mBm(100*dBm) */
4217 rssi = (pAdapter->rssi * 100);
4218 }
4219 else
4220 {
4221 rssi = (VOS_MIN ((bss_desc->rssi + bss_desc->sinr), 0))*100;
4222 }
4223
4224 bss_status = cfg80211_inform_bss_frame(wiphy, chan, mgmt,
4225 frame_len, rssi, GFP_KERNEL);
4226 kfree(mgmt);
4227 return bss_status;
4228}
4229
4230/*
4231 * FUNCTION: wlan_hdd_cfg80211_update_bss_db
4232 * This function is used to update the BSS data base of CFG8011
4233 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304234struct cfg80211_bss* wlan_hdd_cfg80211_update_bss_db( hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07004235 tCsrRoamInfo *pRoamInfo
4236 )
4237{
4238 tCsrRoamConnectedProfile roamProfile;
4239 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
4240 struct cfg80211_bss *bss = NULL;
4241
4242 ENTER();
4243
4244 memset(&roamProfile, 0, sizeof(tCsrRoamConnectedProfile));
4245 sme_RoamGetConnectProfile(hHal, pAdapter->sessionId, &roamProfile);
4246
4247 if (NULL != roamProfile.pBssDesc)
4248 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304249 bss = wlan_hdd_cfg80211_inform_bss(pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07004250 &roamProfile);
4251
4252 if (NULL == bss)
4253 {
4254 hddLog(VOS_TRACE_LEVEL_INFO, "%s: cfg80211_inform_bss return NULL",
4255 __func__);
4256 }
4257
4258 sme_RoamFreeConnectProfile(hHal, &roamProfile);
4259 }
4260 else
4261 {
4262 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: roamProfile.pBssDesc is NULL",
4263 __func__);
4264 }
4265 return bss;
4266}
4267
4268/*
4269 * FUNCTION: wlan_hdd_cfg80211_update_bss
4270 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304271static int wlan_hdd_cfg80211_update_bss( struct wiphy *wiphy,
4272 hdd_adapter_t *pAdapter
Jeff Johnson295189b2012-06-20 16:38:30 -07004273 )
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304274{
Jeff Johnson295189b2012-06-20 16:38:30 -07004275 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
4276 tCsrScanResultInfo *pScanResult;
4277 eHalStatus status = 0;
4278 tScanResultHandle pResult;
4279 struct cfg80211_bss *bss_status = NULL;
Wilson Yangf80a0542013-10-07 13:02:37 -07004280 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07004281
4282 ENTER();
4283
Wilson Yangf80a0542013-10-07 13:02:37 -07004284 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
4285
4286 if (pHddCtx->isLogpInProgress)
Jeff Johnson295189b2012-06-20 16:38:30 -07004287 {
Wilson Yangf80a0542013-10-07 13:02:37 -07004288 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
4289 "%s:LOGP in Progress. Ignore!!!",__func__);
4290 return -EAGAIN;
Jeff Johnson295189b2012-06-20 16:38:30 -07004291 }
4292
Wilson Yangf80a0542013-10-07 13:02:37 -07004293
4294 /*bss_update is not allowed during wlan driver loading or unloading*/
4295 if (pHddCtx->isLoadUnloadInProgress)
4296 {
4297 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4298 "%s:Loading_unloading in Progress. Ignore!!!",__func__);
4299 return VOS_STATUS_E_PERM;
4300 }
4301
4302
Jeff Johnson295189b2012-06-20 16:38:30 -07004303 /*
4304 * start getting scan results and populate cgf80211 BSS database
4305 */
4306 status = sme_ScanGetResult(hHal, pAdapter->sessionId, NULL, &pResult);
4307
4308 /* no scan results */
4309 if (NULL == pResult)
4310 {
4311 hddLog(VOS_TRACE_LEVEL_INFO, "%s: No scan result\n", __func__);
4312 return status;
4313 }
4314
4315 pScanResult = sme_ScanResultGetFirst(hHal, pResult);
4316
4317 while (pScanResult)
4318 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304319 /*
4320 * cfg80211_inform_bss() is not updating ie field of bss entry, if
4321 * entry already exists in bss data base of cfg80211 for that
4322 * particular BSS ID. Using cfg80211_inform_bss_frame to update the
4323 * bss entry instead of cfg80211_inform_bss, But this call expects
4324 * mgmt packet as input. As of now there is no possibility to get
4325 * the mgmt(probe response) frame from PE, converting bss_desc to
Jeff Johnson295189b2012-06-20 16:38:30 -07004326 * ieee80211_mgmt(probe response) and passing to c
4327 * fg80211_inform_bss_frame.
4328 * */
4329
4330 bss_status = wlan_hdd_cfg80211_inform_bss_frame(pAdapter,
4331 &pScanResult->BssDescriptor);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304332
Jeff Johnson295189b2012-06-20 16:38:30 -07004333
4334 if (NULL == bss_status)
4335 {
4336 hddLog(VOS_TRACE_LEVEL_INFO,
4337 "%s: NULL returned by cfg80211_inform_bss\n", __func__);
4338 }
4339 else
4340 {
Yue Maf49ba872013-08-19 12:04:25 -07004341 cfg80211_put_bss(
4342#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,9,0))
4343 wiphy,
4344#endif
4345 bss_status);
Jeff Johnson295189b2012-06-20 16:38:30 -07004346 }
4347
4348 pScanResult = sme_ScanResultGetNext(hHal, pResult);
4349 }
4350
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304351 sme_ScanResultPurge(hHal, pResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07004352
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304353 return 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07004354}
4355
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004356void
4357hddPrintMacAddr(tCsrBssid macAddr, tANI_U8 logLevel)
4358{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304359 VOS_TRACE(VOS_MODULE_ID_HDD, logLevel,
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07004360 "%02X:%02X:%02X:%02X:%02X:%02X\n",
4361 macAddr[0], macAddr[1], macAddr[2], macAddr[3], macAddr[4],
4362 macAddr[5]);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004363} /****** end hddPrintMacAddr() ******/
4364
4365void
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07004366hddPrintPmkId(tANI_U8 *pmkId, tANI_U8 logLevel)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004367{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304368 VOS_TRACE(VOS_MODULE_ID_HDD, logLevel,
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07004369 "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
4370 pmkId[0], pmkId[1], pmkId[2], pmkId[3], pmkId[4],
4371 pmkId[5], pmkId[6], pmkId[7], pmkId[8], pmkId[9], pmkId[10],
4372 pmkId[11], pmkId[12], pmkId[13], pmkId[14], pmkId[15]);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004373} /****** end hddPrintPmkId() ******/
4374
4375//hddPrintMacAddr(tCsrBssid macAddr, tANI_U8 logLevel);
4376//hddPrintMacAddr(macAddr, VOS_TRACE_LEVEL_FATAL);
4377
4378//void sirDumpBuf(tpAniSirGlobal pMac, tANI_U8 modId, tANI_U32 level, tANI_U8 *buf, tANI_U32 size);
4379//sirDumpBuf(pMac, VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL, pmkid, 16);
4380
4381#define dump_bssid(bssid) \
4382 { \
Jeff Johnsone7245742012-09-05 17:12:55 -07004383 hddLog(VOS_TRACE_LEVEL_INFO, "BSSID (MAC) address:\t"); \
4384 hddPrintMacAddr(bssid, VOS_TRACE_LEVEL_INFO);\
4385 hddLog(VOS_TRACE_LEVEL_INFO, "\n"); \
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004386 }
4387
4388#define dump_pmkid(pMac, pmkid) \
4389 { \
Jeff Johnsone7245742012-09-05 17:12:55 -07004390 hddLog(VOS_TRACE_LEVEL_INFO, "PMKSA-ID:\t"); \
4391 hddPrintPmkId(pmkid, VOS_TRACE_LEVEL_INFO);\
4392 hddLog(VOS_TRACE_LEVEL_INFO, "\n"); \
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004393 }
4394
Madan Mohan Koyyalamudi1b4afb02012-10-22 15:25:16 -07004395#if defined(FEATURE_WLAN_LFR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004396/*
4397 * FUNCTION: wlan_hdd_cfg80211_pmksa_candidate_notify
4398 * This function is used to notify the supplicant of a new PMKSA candidate.
4399 */
4400int wlan_hdd_cfg80211_pmksa_candidate_notify(
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304401 hdd_adapter_t *pAdapter, tCsrRoamInfo *pRoamInfo,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004402 int index, bool preauth )
4403{
Jeff Johnsone7245742012-09-05 17:12:55 -07004404#ifdef FEATURE_WLAN_OKC
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004405 struct net_device *dev = pAdapter->dev;
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004406 hdd_context_t *pHddCtx = (hdd_context_t*)pAdapter->pHddCtx;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004407
4408 ENTER();
Jeff Johnsone7245742012-09-05 17:12:55 -07004409 hddLog(VOS_TRACE_LEVEL_INFO, "%s is going to notify supplicant of:", __func__);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004410
4411 if( NULL == pRoamInfo )
4412 {
4413 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: pRoamInfo is NULL\n", __func__);
4414 return -EINVAL;
4415 }
4416
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004417 if (eANI_BOOLEAN_TRUE == hdd_is_okc_mode_enabled(pHddCtx))
4418 {
4419 dump_bssid(pRoamInfo->bssid);
4420 cfg80211_pmksa_candidate_notify(dev, index,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004421 pRoamInfo->bssid, preauth, GFP_KERNEL);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004422 }
Jeff Johnsone7245742012-09-05 17:12:55 -07004423#endif /* FEATURE_WLAN_OKC */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304424 return 0;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004425}
4426#endif //FEATURE_WLAN_LFR
4427
Yue Maef608272013-04-08 23:09:17 -07004428#ifdef FEATURE_WLAN_LFR_METRICS
4429/*
4430 * FUNCTION: wlan_hdd_cfg80211_roam_metrics_preauth
4431 * 802.11r/LFR metrics reporting function to report preauth initiation
4432 *
4433 */
4434#define MAX_LFR_METRICS_EVENT_LENGTH 100
4435VOS_STATUS wlan_hdd_cfg80211_roam_metrics_preauth(hdd_adapter_t *pAdapter,
4436 tCsrRoamInfo *pRoamInfo)
4437{
4438 unsigned char metrics_notification[MAX_LFR_METRICS_EVENT_LENGTH + 1];
4439 union iwreq_data wrqu;
4440
4441 ENTER();
4442
4443 if (NULL == pAdapter)
4444 {
4445 hddLog(LOGE, "%s: pAdapter is NULL!", __func__);
4446 return VOS_STATUS_E_FAILURE;
4447 }
4448
4449 /* create the event */
4450 memset(&wrqu, 0, sizeof(wrqu));
4451 memset(metrics_notification, 0, sizeof(metrics_notification));
4452
4453 wrqu.data.pointer = metrics_notification;
4454 wrqu.data.length = scnprintf(metrics_notification,
4455 sizeof(metrics_notification), "QCOM: LFR_PREAUTH_INIT "
4456 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(pRoamInfo->bssid));
4457
4458 wireless_send_event(pAdapter->dev, IWEVCUSTOM, &wrqu, metrics_notification);
4459
4460 EXIT();
4461
4462 return VOS_STATUS_SUCCESS;
4463}
4464
4465/*
4466 * FUNCTION: wlan_hdd_cfg80211_roam_metrics_preauth_status
4467 * 802.11r/LFR metrics reporting function to report preauth completion
4468 * or failure
4469 */
4470VOS_STATUS wlan_hdd_cfg80211_roam_metrics_preauth_status(
4471 hdd_adapter_t *pAdapter, tCsrRoamInfo *pRoamInfo, bool preauth_status)
4472{
4473 unsigned char metrics_notification[MAX_LFR_METRICS_EVENT_LENGTH + 1];
4474 union iwreq_data wrqu;
4475
4476 ENTER();
4477
4478 if (NULL == pAdapter)
4479 {
4480 hddLog(LOGE, "%s: pAdapter is NULL!", __func__);
4481 return VOS_STATUS_E_FAILURE;
4482 }
4483
4484 /* create the event */
4485 memset(&wrqu, 0, sizeof(wrqu));
4486 memset(metrics_notification, 0, sizeof(metrics_notification));
4487
4488 scnprintf(metrics_notification, sizeof(metrics_notification),
4489 "QCOM: LFR_PREAUTH_STATUS "MAC_ADDRESS_STR,
4490 MAC_ADDR_ARRAY(pRoamInfo->bssid));
4491
4492 if (1 == preauth_status)
4493 strncat(metrics_notification, " TRUE", 5);
4494 else
4495 strncat(metrics_notification, " FALSE", 6);
4496
4497 wrqu.data.pointer = metrics_notification;
4498 wrqu.data.length = strlen(metrics_notification);
4499
4500 wireless_send_event(pAdapter->dev, IWEVCUSTOM, &wrqu, metrics_notification);
4501
4502 EXIT();
4503
4504 return VOS_STATUS_SUCCESS;
4505}
4506
4507/*
4508 * FUNCTION: wlan_hdd_cfg80211_roam_metrics_handover
4509 * 802.11r/LFR metrics reporting function to report handover initiation
4510 *
4511 */
4512VOS_STATUS wlan_hdd_cfg80211_roam_metrics_handover(hdd_adapter_t * pAdapter,
4513 tCsrRoamInfo *pRoamInfo)
4514{
4515 unsigned char metrics_notification[MAX_LFR_METRICS_EVENT_LENGTH + 1];
4516 union iwreq_data wrqu;
4517
4518 ENTER();
4519
4520 if (NULL == pAdapter)
4521 {
4522 hddLog(LOGE, "%s: pAdapter is NULL!", __func__);
4523 return VOS_STATUS_E_FAILURE;
4524 }
4525
4526 /* create the event */
4527 memset(&wrqu, 0, sizeof(wrqu));
4528 memset(metrics_notification, 0, sizeof(metrics_notification));
4529
4530 wrqu.data.pointer = metrics_notification;
4531 wrqu.data.length = scnprintf(metrics_notification,
4532 sizeof(metrics_notification), "QCOM: LFR_PREAUTH_HANDOVER "
4533 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(pRoamInfo->bssid));
4534
4535 wireless_send_event(pAdapter->dev, IWEVCUSTOM, &wrqu, metrics_notification);
4536
4537 EXIT();
4538
4539 return VOS_STATUS_SUCCESS;
4540}
4541#endif
4542
Jeff Johnson295189b2012-06-20 16:38:30 -07004543/*
4544 * FUNCTION: hdd_cfg80211_scan_done_callback
4545 * scanning callback function, called after finishing scan
4546 *
4547 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304548static eHalStatus hdd_cfg80211_scan_done_callback(tHalHandle halHandle,
Jeff Johnson295189b2012-06-20 16:38:30 -07004549 void *pContext, tANI_U32 scanId, eCsrScanStatus status)
4550{
4551 struct net_device *dev = (struct net_device *) pContext;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304552 //struct wireless_dev *wdev = dev->ieee80211_ptr;
Jeff Johnson295189b2012-06-20 16:38:30 -07004553 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004554 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
4555 hdd_scaninfo_t *pScanInfo = &pHddCtx->scan_info;
Jeff Johnson295189b2012-06-20 16:38:30 -07004556 struct cfg80211_scan_request *req = NULL;
4557 int ret = 0;
4558
4559 ENTER();
4560
4561 hddLog(VOS_TRACE_LEVEL_INFO,
4562 "%s called with halHandle = %p, pContext = %p,"
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304563 "scanID = %d, returned status = %d\n",
Jeff Johnson295189b2012-06-20 16:38:30 -07004564 __func__, halHandle, pContext, (int) scanId, (int) status);
4565
4566 //Block on scan req completion variable. Can't wait forever though.
4567 ret = wait_for_completion_interruptible_timeout(
4568 &pScanInfo->scan_req_completion_event,
4569 msecs_to_jiffies(WLAN_WAIT_TIME_SCAN_REQ));
4570 if (!ret)
4571 {
4572 VOS_ASSERT(pScanInfo->mScanPending);
Jeff Johnsone7245742012-09-05 17:12:55 -07004573 goto allow_suspend;
Jeff Johnson295189b2012-06-20 16:38:30 -07004574 }
4575
Yue Maef608272013-04-08 23:09:17 -07004576 if (pScanInfo->mScanPending != VOS_TRUE)
Jeff Johnson295189b2012-06-20 16:38:30 -07004577 {
4578 VOS_ASSERT(pScanInfo->mScanPending);
Jeff Johnsone7245742012-09-05 17:12:55 -07004579 goto allow_suspend;
Jeff Johnson295189b2012-06-20 16:38:30 -07004580 }
4581
4582 /* Check the scanId */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304583 if (pScanInfo->scanId != scanId)
Jeff Johnson295189b2012-06-20 16:38:30 -07004584 {
4585 hddLog(VOS_TRACE_LEVEL_INFO,
4586 "%s called with mismatched scanId pScanInfo->scanId = %d "
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304587 "scanId = %d \n", __func__, (int) pScanInfo->scanId,
Jeff Johnson295189b2012-06-20 16:38:30 -07004588 (int) scanId);
4589 }
4590
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304591 ret = wlan_hdd_cfg80211_update_bss((WLAN_HDD_GET_CTX(pAdapter))->wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07004592 pAdapter);
4593
4594 if (0 > ret)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304595 hddLog(VOS_TRACE_LEVEL_INFO, "%s: NO SCAN result", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07004596
4597
4598 /* If any client wait scan result through WEXT
4599 * send scan done event to client */
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004600 if (pHddCtx->scan_info.waitScanResult)
Jeff Johnson295189b2012-06-20 16:38:30 -07004601 {
4602 /* The other scan request waiting for current scan finish
4603 * Send event to notify current scan finished */
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004604 if(WEXT_SCAN_PENDING_DELAY == pHddCtx->scan_info.scan_pending_option)
Jeff Johnson295189b2012-06-20 16:38:30 -07004605 {
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004606 vos_event_set(&pHddCtx->scan_info.scan_finished_event);
Jeff Johnson295189b2012-06-20 16:38:30 -07004607 }
4608 /* Send notify to WEXT client */
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004609 else if(WEXT_SCAN_PENDING_PIGGYBACK == pHddCtx->scan_info.scan_pending_option)
Jeff Johnson295189b2012-06-20 16:38:30 -07004610 {
4611 struct net_device *dev = pAdapter->dev;
4612 union iwreq_data wrqu;
4613 int we_event;
4614 char *msg;
4615
4616 memset(&wrqu, '\0', sizeof(wrqu));
4617 we_event = SIOCGIWSCAN;
4618 msg = NULL;
4619 wireless_send_event(dev, we_event, &wrqu, msg);
4620 }
4621 }
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004622 pHddCtx->scan_info.waitScanResult = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004623
4624 /* Get the Scan Req */
4625 req = pAdapter->request;
4626
4627 if (!req)
4628 {
4629 hddLog(VOS_TRACE_LEVEL_ERROR, "request is became NULL\n");
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07004630 pScanInfo->mScanPending = VOS_FALSE;
Jeff Johnsone7245742012-09-05 17:12:55 -07004631 goto allow_suspend;
Jeff Johnson295189b2012-06-20 16:38:30 -07004632 }
4633
4634 /*
4635 * setting up 0, just in case.
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304636 */
Jeff Johnson295189b2012-06-20 16:38:30 -07004637 req->n_ssids = 0;
4638 req->n_channels = 0;
4639 req->ie = 0;
4640
Jeff Johnson295189b2012-06-20 16:38:30 -07004641 pAdapter->request = NULL;
Jeff Johnsone7245742012-09-05 17:12:55 -07004642 /* Scan is no longer pending */
4643 pScanInfo->mScanPending = VOS_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004644
Madan Mohan Koyyalamudib764bf82012-10-11 16:38:51 -07004645 /*
4646 * cfg80211_scan_done informing NL80211 about completion
4647 * of scanning
4648 */
4649 cfg80211_scan_done(req, false);
Madan Mohan Koyyalamudif4e81002012-11-13 10:46:38 -08004650 complete(&pScanInfo->abortscan_event_var);
Jeff Johnson295189b2012-06-20 16:38:30 -07004651
Jeff Johnsone7245742012-09-05 17:12:55 -07004652allow_suspend:
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07004653 /* release the wake lock at the end of the scan*/
4654 hdd_allow_suspend();
Jeff Johnsone7245742012-09-05 17:12:55 -07004655
Madan Mohan Koyyalamudi10d83a92012-09-28 15:47:05 -07004656 /* Acquire wakelock to handle the case where APP's tries to suspend
4657 * immediatly after the driver gets connect request(i.e after scan)
4658 * from supplicant, this result in app's is suspending and not able
4659 * to process the connect request to AP */
Amar Singhal6144c002013-05-03 16:11:42 -07004660 hdd_allow_suspend_timeout(1000);
Madan Mohan Koyyalamudi10d83a92012-09-28 15:47:05 -07004661
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07004662#ifdef FEATURE_WLAN_TDLS
4663 wlan_hdd_tdls_scan_done_callback(pAdapter);
4664#endif
4665
Jeff Johnson295189b2012-06-20 16:38:30 -07004666 EXIT();
4667 return 0;
4668}
4669
4670/*
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004671 * FUNCTION: hdd_isScanAllowed
4672 * Go through each adapter and check if scan allowed
4673 *
4674 */
4675v_BOOL_t hdd_isScanAllowed( hdd_context_t *pHddCtx )
4676{
4677 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
4678 hdd_station_ctx_t *pHddStaCtx = NULL;
4679 hdd_adapter_t *pAdapter = NULL;
4680 VOS_STATUS status = 0;
4681 v_U8_t staId = 0;
4682 v_U8_t *staMac = NULL;
4683
4684 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
4685
4686 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
4687 {
4688 pAdapter = pAdapterNode->pAdapter;
4689
4690 if( pAdapter )
4691 {
4692 hddLog(VOS_TRACE_LEVEL_INFO,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304693 "%s: Adapter with device mode %d exists",
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004694 __func__, pAdapter->device_mode);
4695 if ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
4696 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) ||
4697 (WLAN_HDD_P2P_DEVICE == pAdapter->device_mode))
4698 {
4699 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
4700 if ((eConnectionState_Associated == pHddStaCtx->conn_info.connState) &&
4701 (VOS_FALSE == pHddStaCtx->conn_info.uIsAuthenticated))
4702 {
4703 staMac = (v_U8_t *) &(pAdapter->macAddressCurrent.bytes[0]);
4704 hddLog(VOS_TRACE_LEVEL_ERROR,
4705 "%s: client %02x:%02x:%02x:%02x:%02x:%02x is in the "
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304706 "middle of WPS/EAPOL exchange.", __func__,
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004707 staMac[0], staMac[1], staMac[2],
4708 staMac[3], staMac[4], staMac[5]);
4709 return VOS_FALSE;
4710 }
4711 }
4712 else if ((WLAN_HDD_SOFTAP == pAdapter->device_mode) ||
4713 (WLAN_HDD_P2P_GO == pAdapter->device_mode))
4714 {
4715 for (staId = 0; staId < WLAN_MAX_STA_COUNT; staId++)
4716 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304717 if ((pAdapter->aStaInfo[staId].isUsed) &&
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004718 (WLANTL_STA_CONNECTED == pAdapter->aStaInfo[staId].tlSTAState))
4719 {
4720 staMac = (v_U8_t *) &(pAdapter->aStaInfo[staId].macAddrSTA.bytes[0]);
4721
4722 hddLog(VOS_TRACE_LEVEL_ERROR,
4723 "%s: client %02x:%02x:%02x:%02x:%02x:%02x of SoftAP/P2P-GO is in the "
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304724 "middle of WPS/EAPOL exchange.", __func__,
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004725 staMac[0], staMac[1], staMac[2],
4726 staMac[3], staMac[4], staMac[5]);
4727 return VOS_FALSE;
4728 }
4729 }
4730 }
4731 }
4732 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
4733 pAdapterNode = pNext;
4734 }
4735 hddLog(VOS_TRACE_LEVEL_INFO,
4736 "%s: Scan allowed", __func__);
4737 return VOS_TRUE;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304738}
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004739
4740/*
Jeff Johnson295189b2012-06-20 16:38:30 -07004741 * FUNCTION: wlan_hdd_cfg80211_scan
4742 * this scan respond to scan trigger and update cfg80211 scan database
4743 * later, scan dump command can be used to recieve scan results
4744 */
Jeff Johnson3bbe4bf2013-01-18 17:05:29 -08004745int wlan_hdd_cfg80211_scan( struct wiphy *wiphy,
4746#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
4747 struct net_device *dev,
4748#endif
4749 struct cfg80211_scan_request *request)
4750{
4751#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
4752 struct net_device *dev = request->wdev->netdev;
4753#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304754 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Jeff Johnson295189b2012-06-20 16:38:30 -07004755 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
4756 hdd_wext_state_t *pwextBuf = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05304757 hdd_config_t *cfg_param = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004758 tCsrScanRequest scanRequest;
4759 tANI_U8 *channelList = NULL, i;
4760 v_U32_t scanId = 0;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05304761 int status;
4762 hdd_scaninfo_t *pScanInfo = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004763 v_U8_t* pP2pIe = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004764
4765 ENTER();
4766
4767 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
4768 __func__,pAdapter->device_mode);
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004769
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05304770 status = wlan_hdd_validate_context(pHddCtx);
4771
4772 if (0 != status)
4773 {
4774 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4775 "%s: HDD context is not valid", __func__);
4776 return status;
4777 }
4778
4779 cfg_param = pHddCtx->cfg_ini;
4780 pScanInfo = &pHddCtx->scan_info;
4781
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004782 if ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) &&
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004783 (eConnectionState_Connecting ==
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004784 (WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))->conn_info.connState))
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004785 {
4786 hddLog(VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08004787 "%s: %p(%d) Connection in progress: Scan request denied (EBUSY)", __func__, \
4788 WLAN_HDD_GET_STATION_CTX_PTR(pAdapter), pAdapter->sessionId);
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004789 return -EBUSY;
4790 }
4791
Jeff Johnson295189b2012-06-20 16:38:30 -07004792#ifdef WLAN_BTAMP_FEATURE
4793 //Scan not supported when AMP traffic is on.
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004794 if (VOS_TRUE == WLANBAP_AmpSessionOn())
Jeff Johnson295189b2012-06-20 16:38:30 -07004795 {
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004796 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07004797 "%s: No scanning when AMP is on", __func__);
4798 return -EOPNOTSUPP;
4799 }
4800#endif
4801 //Scan on any other interface is not supported.
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004802 if (pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07004803 {
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004804 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07004805 "%s: Not scanning on device_mode = %d",
4806 __func__, pAdapter->device_mode);
4807 return -EOPNOTSUPP;
4808 }
4809
4810 if (TRUE == pScanInfo->mScanPending)
4811 {
4812 hddLog(VOS_TRACE_LEVEL_INFO, "%s: mScanPending is TRUE", __func__);
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004813 return -EBUSY;
Jeff Johnson295189b2012-06-20 16:38:30 -07004814 }
4815
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304816 //Don't Allow Scan and return busy if Remain On
Jeff Johnson32d95a32012-09-10 13:15:23 -07004817 //Channel and action frame is pending
4818 //Otherwise Cancel Remain On Channel and allow Scan
4819 //If no action frame pending
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004820 if (0 != wlan_hdd_check_remain_on_channel(pAdapter))
Jeff Johnson32d95a32012-09-10 13:15:23 -07004821 {
4822 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Remain On Channel Pending", __func__);
4823 return -EBUSY;
4824 }
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004825#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07004826 /* if tdls disagree scan right now, return immediately.
4827 tdls will schedule the scan when scan is allowed. (return SUCCESS)
4828 or will reject the scan if any TDLS is in progress. (return -EBUSY)
4829 */
4830 status = wlan_hdd_tdls_scan_callback (pAdapter,
4831 wiphy,
4832#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
4833 dev,
Gopichand Nakkalac3c42b92013-03-20 19:42:34 -07004834#endif
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07004835 request);
4836 if(status <= 0)
4837 {
4838 hddLog(VOS_TRACE_LEVEL_INFO, "%s: TDLS Pending %d", __func__, status);
4839 return status;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004840 }
4841#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -07004842
Jeff Johnson295189b2012-06-20 16:38:30 -07004843 if (mutex_lock_interruptible(&pHddCtx->tmInfo.tmOperationLock))
4844 {
4845 VOS_TRACE(VOS_MODULE_ID_HDD,VOS_TRACE_LEVEL_ERROR,
Jeff Johnson1250df42012-12-10 14:31:52 -08004846 "%s: Acquire lock fail", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07004847 return -EAGAIN;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304848 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004849 if (TRUE == pHddCtx->tmInfo.tmAction.enterImps)
4850 {
4851 hddLog(VOS_TRACE_LEVEL_WARN,
4852 "%s: MAX TM Level Scan not allowed", __func__);
4853 mutex_unlock(&pHddCtx->tmInfo.tmOperationLock);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304854 return -EBUSY;
Jeff Johnson295189b2012-06-20 16:38:30 -07004855 }
4856 mutex_unlock(&pHddCtx->tmInfo.tmOperationLock);
4857
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004858 /* Check if scan is allowed at this point of time.
4859 */
4860 if (!hdd_isScanAllowed(pHddCtx))
4861 {
4862 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Scan not allowed", __func__);
4863 return -EBUSY;
4864 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304865
Jeff Johnson295189b2012-06-20 16:38:30 -07004866 vos_mem_zero( &scanRequest, sizeof(scanRequest));
4867
4868 if (NULL != request)
4869 {
4870 hddLog(VOS_TRACE_LEVEL_INFO, "scan request for ssid = %d",
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304871 (int)request->n_ssids);
Jeff Johnson295189b2012-06-20 16:38:30 -07004872
4873 /* Even though supplicant doesn't provide any SSIDs, n_ssids is set to 1.
4874 * Becasue of this, driver is assuming that this is not wildcard scan and so
4875 * is not aging out the scan results.
4876 */
Jeff Johnson32d95a32012-09-10 13:15:23 -07004877 if (request->ssids && '\0' == request->ssids->ssid[0])
Jeff Johnson295189b2012-06-20 16:38:30 -07004878 {
4879 request->n_ssids = 0;
4880 }
4881
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07004882 if ((request->ssids) && (0 < request->n_ssids))
Jeff Johnson295189b2012-06-20 16:38:30 -07004883 {
4884 tCsrSSIDInfo *SsidInfo;
4885 int j;
4886 scanRequest.SSIDs.numOfSSIDs = request->n_ssids;
4887 /* Allocate num_ssid tCsrSSIDInfo structure */
4888 SsidInfo = scanRequest.SSIDs.SSIDList =
4889 ( tCsrSSIDInfo *)vos_mem_malloc(
4890 request->n_ssids*sizeof(tCsrSSIDInfo));
4891
4892 if(NULL == scanRequest.SSIDs.SSIDList)
4893 {
4894 hddLog(VOS_TRACE_LEVEL_ERROR,
4895 "memory alloc failed SSIDInfo buffer");
4896 return -ENOMEM;
4897 }
4898
4899 /* copy all the ssid's and their length */
4900 for(j = 0; j < request->n_ssids; j++, SsidInfo++)
4901 {
4902 /* get the ssid length */
4903 SsidInfo->SSID.length = request->ssids[j].ssid_len;
4904 vos_mem_copy(SsidInfo->SSID.ssId, &request->ssids[j].ssid[0],
4905 SsidInfo->SSID.length);
4906 SsidInfo->SSID.ssId[SsidInfo->SSID.length] = '\0';
4907 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "SSID number %d: %s",
4908 j, SsidInfo->SSID.ssId);
4909 }
4910 /* set the scan type to active */
4911 scanRequest.scanType = eSIR_ACTIVE_SCAN;
4912 }
4913 else if(WLAN_HDD_P2P_GO == pAdapter->device_mode)
4914 {
4915 /* set the scan type to active */
4916 scanRequest.scanType = eSIR_ACTIVE_SCAN;
4917 }
4918 else
4919 {
4920 /*Set the scan type to default type, in this case it is ACTIVE*/
4921 scanRequest.scanType = pScanInfo->scan_mode;
4922 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304923 scanRequest.minChnTime = cfg_param->nActiveMinChnTime;
Jeff Johnson295189b2012-06-20 16:38:30 -07004924 scanRequest.maxChnTime = cfg_param->nActiveMaxChnTime;
4925 }
4926 else
4927 {
4928 /* set the scan type to active */
4929 scanRequest.scanType = eSIR_ACTIVE_SCAN;
4930 vos_mem_set( scanRequest.bssid, sizeof( tCsrBssid ), 0xff );
4931
4932 /* set min and max channel time to zero */
4933 scanRequest.minChnTime = 0;
4934 scanRequest.maxChnTime = 0;
4935 }
4936
4937 /* set BSSType to default type */
4938 scanRequest.BSSType = eCSR_BSS_TYPE_ANY;
4939
4940 /*TODO: scan the requested channels only*/
4941
4942 /*Right now scanning all the channels */
4943 if( request )
4944 {
4945 if( request->n_channels )
4946 {
4947 channelList = vos_mem_malloc( request->n_channels );
4948 if( NULL == channelList )
4949 {
4950 status = -ENOMEM;
4951 goto free_mem;
4952 }
4953
4954 for( i = 0 ; i < request->n_channels ; i++ )
4955 channelList[i] = request->channels[i]->hw_value;
4956 }
4957
4958 scanRequest.ChannelInfo.numOfChannels = request->n_channels;
4959 scanRequest.ChannelInfo.ChannelList = channelList;
4960
4961 /* set requestType to full scan */
4962 scanRequest.requestType = eCSR_SCAN_REQUEST_FULL_SCAN;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304963
4964 /* Flush the scan results(only p2p beacons) for STA scan and P2P
Madan Mohan Koyyalamudi8d50f312012-11-27 15:48:57 -08004965 * search (Flush on both full scan and social scan but not on single
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304966 * channel scan).P2P search happens on 3 social channels (1, 6, 11)
Madan Mohan Koyyalamudi8d50f312012-11-27 15:48:57 -08004967 */
4968
4969 /* Supplicant does single channel scan after 8-way handshake
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304970 * and in that case driver shoudnt flush scan results. If
4971 * driver flushes the scan results here and unfortunately if
4972 * the AP doesnt respond to our probe req then association
Madan Mohan Koyyalamudi8d50f312012-11-27 15:48:57 -08004973 * fails which is not desired
4974 */
4975
4976 if( request->n_channels != WLAN_HDD_P2P_SINGLE_CHANNEL_SCAN )
4977 {
4978 sme_ScanFlushP2PResult( WLAN_HDD_GET_HAL_CTX(pAdapter),
4979 pAdapter->sessionId );
4980 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004981
4982 if( request->ie_len )
4983 {
4984 /* save this for future association (join requires this) */
4985 memset( &pScanInfo->scanAddIE, 0, sizeof(pScanInfo->scanAddIE) );
4986 memcpy( pScanInfo->scanAddIE.addIEdata, request->ie, request->ie_len);
4987 pScanInfo->scanAddIE.length = request->ie_len;
4988
4989 if((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
Jeff Johnsone7245742012-09-05 17:12:55 -07004990 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) ||
4991 (WLAN_HDD_P2P_DEVICE == pAdapter->device_mode)
Jeff Johnson295189b2012-06-20 16:38:30 -07004992 )
4993 {
4994 pwextBuf->roamProfile.pAddIEScan = pScanInfo->scanAddIE.addIEdata;
4995 pwextBuf->roamProfile.nAddIEScanLength = pScanInfo->scanAddIE.length;
4996 }
4997
4998 scanRequest.uIEFieldLen = pScanInfo->scanAddIE.length;
4999 scanRequest.pIEField = pScanInfo->scanAddIE.addIEdata;
5000
Jeff Johnson295189b2012-06-20 16:38:30 -07005001 pP2pIe = wlan_hdd_get_p2p_ie_ptr((v_U8_t*)request->ie,
5002 request->ie_len);
5003 if (pP2pIe != NULL)
5004 {
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07005005#ifdef WLAN_FEATURE_P2P_DEBUG
5006 if (((globalP2PConnectionStatus == P2P_GO_NEG_COMPLETED) ||
5007 (globalP2PConnectionStatus == P2P_GO_NEG_PROCESS)) &&
5008 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
5009 {
5010 globalP2PConnectionStatus = P2P_CLIENT_CONNECTING_STATE_1;
5011 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P State] Changing state from "
5012 "Go nego completed to Connection is started");
5013 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P]P2P Scanning is started "
5014 "for 8way Handshake");
5015 }
5016 else if((globalP2PConnectionStatus == P2P_CLIENT_DISCONNECTED_STATE) &&
5017 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
5018 {
5019 globalP2PConnectionStatus = P2P_CLIENT_CONNECTING_STATE_2;
5020 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P State] Changing state from "
5021 "Disconnected state to Connection is started");
5022 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P]P2P Scanning is started "
5023 "for 4way Handshake");
5024 }
5025#endif
5026
Jeff Johnsone7245742012-09-05 17:12:55 -07005027 /* no_cck will be set during p2p find to disable 11b rates */
5028 if(TRUE == request->no_cck)
Jeff Johnson295189b2012-06-20 16:38:30 -07005029 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005030 hddLog(VOS_TRACE_LEVEL_INFO,
5031 "%s: This is a P2P Search", __func__);
5032 scanRequest.p2pSearch = 1;
Jeff Johnsone7245742012-09-05 17:12:55 -07005033
Jeff Johnsone7245742012-09-05 17:12:55 -07005034 if( request->n_channels == WLAN_HDD_P2P_SOCIAL_CHANNELS )
5035 {
Madan Mohan Koyyalamudi1b1d9e82012-10-21 11:38:33 -07005036 /* set requestType to P2P Discovery */
5037 scanRequest.requestType = eCSR_SCAN_P2P_DISCOVERY;
Jeff Johnsone7245742012-09-05 17:12:55 -07005038 }
5039
5040 /*
5041 Skip Dfs Channel in case of P2P Search
5042 if it is set in ini file
5043 */
5044 if(cfg_param->skipDfsChnlInP2pSearch)
5045 {
5046 scanRequest.skipDfsChnlInP2pSearch = 1;
5047 }
5048 else
5049 {
5050 scanRequest.skipDfsChnlInP2pSearch = 0;
5051 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005052
Jeff Johnson295189b2012-06-20 16:38:30 -07005053 }
5054 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005055 }
5056 }
5057
5058 INIT_COMPLETION(pScanInfo->scan_req_completion_event);
5059
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07005060 /* acquire the wakelock to avoid the apps suspend during the scan. To
5061 * address the following issues.
5062 * 1) Disconnected scenario: we are not allowing the suspend as WLAN is not in
5063 * BMPS/IMPS this result in android trying to suspend aggressively and backing off
5064 * for long time, this result in apps running at full power for long time.
5065 * 2) Connected scenario: If we allow the suspend during the scan, RIVA will
5066 * be stuck in full power because of resume BMPS
5067 */
5068 hdd_prevent_suspend();
Jeff Johnsone7245742012-09-05 17:12:55 -07005069
5070 status = sme_ScanRequest( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07005071 pAdapter->sessionId, &scanRequest, &scanId,
5072 &hdd_cfg80211_scan_done_callback, dev );
Jeff Johnsone7245742012-09-05 17:12:55 -07005073
Jeff Johnson295189b2012-06-20 16:38:30 -07005074 if (eHAL_STATUS_SUCCESS != status)
5075 {
5076 hddLog(VOS_TRACE_LEVEL_ERROR,
5077 "%s: sme_ScanRequest returned error %d", __func__, status);
5078 complete(&pScanInfo->scan_req_completion_event);
Madan Mohan Koyyalamudi3b230fe2012-10-18 14:46:32 -07005079 if(eHAL_STATUS_RESOURCES == status)
5080 {
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07005081 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 -07005082 status = -EBUSY;
5083 } else {
5084 status = -EIO;
5085 }
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07005086 hdd_allow_suspend();
Jeff Johnson295189b2012-06-20 16:38:30 -07005087 goto free_mem;
5088 }
5089
5090 pScanInfo->mScanPending = TRUE;
5091 pAdapter->request = request;
5092 pScanInfo->scanId = scanId;
5093
5094 complete(&pScanInfo->scan_req_completion_event);
5095
5096free_mem:
5097 if( scanRequest.SSIDs.SSIDList )
5098 {
5099 vos_mem_free(scanRequest.SSIDs.SSIDList);
5100 }
5101
5102 if( channelList )
5103 vos_mem_free( channelList );
5104
5105 EXIT();
5106
5107 return status;
5108}
5109
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07005110
5111void hdd_select_cbmode( hdd_adapter_t *pAdapter,v_U8_t operationChannel)
5112{
5113 v_U8_t iniDot11Mode =
5114 (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini->dot11Mode;
5115 eHddDot11Mode hddDot11Mode = iniDot11Mode;
5116
5117 switch ( iniDot11Mode )
5118 {
5119 case eHDD_DOT11_MODE_AUTO:
5120 case eHDD_DOT11_MODE_11ac:
5121 case eHDD_DOT11_MODE_11ac_ONLY:
5122#ifdef WLAN_FEATURE_11AC
5123 hddDot11Mode = eHDD_DOT11_MODE_11ac;
5124#else
5125 hddDot11Mode = eHDD_DOT11_MODE_11n;
5126#endif
5127 break;
5128 case eHDD_DOT11_MODE_11n:
5129 case eHDD_DOT11_MODE_11n_ONLY:
5130 hddDot11Mode = eHDD_DOT11_MODE_11n;
5131 break;
5132 default:
5133 hddDot11Mode = iniDot11Mode;
5134 break;
5135 }
5136 /* This call decides required channel bonding mode */
5137 sme_SelectCBMode((WLAN_HDD_GET_CTX(pAdapter)->hHal),
5138 hdd_cfg_xlate_to_csr_phy_mode(hddDot11Mode),
5139 operationChannel);
5140}
5141
Jeff Johnson295189b2012-06-20 16:38:30 -07005142/*
5143 * FUNCTION: wlan_hdd_cfg80211_connect_start
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305144 * This function is used to start the association process
Jeff Johnson295189b2012-06-20 16:38:30 -07005145 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305146int wlan_hdd_cfg80211_connect_start( hdd_adapter_t *pAdapter,
Jeff Johnson32d95a32012-09-10 13:15:23 -07005147 const u8 *ssid, size_t ssid_len, const u8 *bssid, u8 operatingChannel)
Jeff Johnson295189b2012-06-20 16:38:30 -07005148{
5149 int status = 0;
5150 hdd_wext_state_t *pWextState;
5151 v_U32_t roamId;
5152 tCsrRoamProfile *pRoamProfile;
5153 eMib_dot11DesiredBssType connectedBssType;
5154 eCsrAuthType RSNAuthType;
5155
5156 ENTER();
5157
5158 pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305159
Jeff Johnson295189b2012-06-20 16:38:30 -07005160 if (SIR_MAC_MAX_SSID_LENGTH < ssid_len)
5161 {
5162 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: wrong SSID len", __func__);
5163 return -EINVAL;
5164 }
5165
5166 pRoamProfile = &pWextState->roamProfile;
5167
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305168 if (pRoamProfile)
Jeff Johnson295189b2012-06-20 16:38:30 -07005169 {
Jeff Johnsone7245742012-09-05 17:12:55 -07005170 int ret = 0;
5171 hdd_station_ctx_t *pHddStaCtx;
5172 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
5173 hdd_connGetConnectedBssType(pHddStaCtx,&connectedBssType );
5174
5175 if((eMib_dot11DesiredBssType_independent == connectedBssType) ||
5176 (eConnectionState_Associated == pHddStaCtx->conn_info.connState) ||
5177 (eConnectionState_IbssConnected == pHddStaCtx->conn_info.connState))
Jeff Johnson295189b2012-06-20 16:38:30 -07005178 {
5179 /* Issue disconnect to CSR */
5180 INIT_COMPLETION(pAdapter->disconnect_comp_var);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305181 if( eHAL_STATUS_SUCCESS ==
Jeff Johnson295189b2012-06-20 16:38:30 -07005182 sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
5183 pAdapter->sessionId,
5184 eCSR_DISCONNECT_REASON_UNSPECIFIED ) )
5185 {
Jeff Johnsone7245742012-09-05 17:12:55 -07005186 ret = wait_for_completion_interruptible_timeout(
5187 &pAdapter->disconnect_comp_var,
5188 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
5189 if (0 == ret)
5190 {
5191 VOS_ASSERT(0);
5192 }
5193 }
5194 }
5195 else if(eConnectionState_Disconnecting == pHddStaCtx->conn_info.connState)
5196 {
5197 ret = wait_for_completion_interruptible_timeout(
5198 &pAdapter->disconnect_comp_var,
5199 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
5200 if (0 == ret)
5201 {
5202 VOS_ASSERT(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005203 }
5204 }
5205
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305206 if (HDD_WMM_USER_MODE_NO_QOS ==
Jeff Johnson295189b2012-06-20 16:38:30 -07005207 (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini->WmmMode)
5208 {
5209 /*QoS not enabled in cfg file*/
5210 pRoamProfile->uapsd_mask = 0;
5211 }
5212 else
5213 {
5214 /*QoS enabled, update uapsd mask from cfg file*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305215 pRoamProfile->uapsd_mask =
Jeff Johnson295189b2012-06-20 16:38:30 -07005216 (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini->UapsdMask;
5217 }
5218
5219 pRoamProfile->SSIDs.numOfSSIDs = 1;
5220 pRoamProfile->SSIDs.SSIDList->SSID.length = ssid_len;
5221 vos_mem_zero(pRoamProfile->SSIDs.SSIDList->SSID.ssId,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305222 sizeof(pRoamProfile->SSIDs.SSIDList->SSID.ssId));
Jeff Johnson295189b2012-06-20 16:38:30 -07005223 vos_mem_copy((void *)(pRoamProfile->SSIDs.SSIDList->SSID.ssId),
5224 ssid, ssid_len);
5225
5226 if (bssid)
5227 {
5228 pRoamProfile->BSSIDs.numOfBSSIDs = 1;
5229 vos_mem_copy((void *)(pRoamProfile->BSSIDs.bssid), bssid,
5230 WNI_CFG_BSSID_LEN);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305231 /* Save BSSID in seperate variable as well, as RoamProfile
5232 BSSID is getting zeroed out in the association process. And in
Jeff Johnson295189b2012-06-20 16:38:30 -07005233 case of join failure we should send valid BSSID to supplicant
5234 */
5235 vos_mem_copy((void *)(pWextState->req_bssId), bssid,
5236 WNI_CFG_BSSID_LEN);
5237 }
Dhanashri Atre51981c62013-06-13 11:47:57 -07005238 else
5239 {
5240 vos_mem_zero((void *)(pRoamProfile->BSSIDs.bssid),WNI_CFG_BSSID_LEN);
5241 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005242
5243 if ((IW_AUTH_WPA_VERSION_WPA == pWextState->wpaVersion) ||
5244 (IW_AUTH_WPA_VERSION_WPA2 == pWextState->wpaVersion))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305245 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005246 /*set gen ie*/
5247 hdd_SetGENIEToCsr(pAdapter, &RSNAuthType);
5248 /*set auth*/
5249 hdd_set_csr_auth_type(pAdapter, RSNAuthType);
5250 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005251#ifdef FEATURE_WLAN_WAPI
5252 if (pAdapter->wapi_info.nWapiMode)
5253 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005254 hddLog(LOG1, "%s: Setting WAPI AUTH Type and Encryption Mode values", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005255 switch (pAdapter->wapi_info.wapiAuthMode)
5256 {
5257 case WAPI_AUTH_MODE_PSK:
5258 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005259 hddLog(LOG1, "%s: WAPI AUTH TYPE: PSK: %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07005260 pAdapter->wapi_info.wapiAuthMode);
5261 pRoamProfile->AuthType.authType[0] = eCSR_AUTH_TYPE_WAPI_WAI_PSK;
5262 break;
5263 }
5264 case WAPI_AUTH_MODE_CERT:
5265 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005266 hddLog(LOG1, "%s: WAPI AUTH TYPE: CERT: %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07005267 pAdapter->wapi_info.wapiAuthMode);
5268 pRoamProfile->AuthType.authType[0] = eCSR_AUTH_TYPE_WAPI_WAI_CERTIFICATE;
5269 break;
5270 }
5271 } // End of switch
5272 if ( pAdapter->wapi_info.wapiAuthMode == WAPI_AUTH_MODE_PSK ||
5273 pAdapter->wapi_info.wapiAuthMode == WAPI_AUTH_MODE_CERT)
5274 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005275 hddLog(LOG1, "%s: WAPI PAIRWISE/GROUP ENCRYPTION: WPI", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005276 pRoamProfile->AuthType.numEntries = 1;
5277 pRoamProfile->EncryptionType.numEntries = 1;
5278 pRoamProfile->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_WPI;
5279 pRoamProfile->mcEncryptionType.numEntries = 1;
5280 pRoamProfile->mcEncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_WPI;
5281 }
5282 }
5283#endif /* FEATURE_WLAN_WAPI */
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05305284#ifdef WLAN_FEATURE_GTK_OFFLOAD
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05305285 /* Initializing gtkOffloadReqParams */
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05305286 if ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
5287 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
5288 {
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05305289 memset(&pHddStaCtx->gtkOffloadReqParams, 0,
5290 sizeof (tSirGtkOffloadParams));
5291 pHddStaCtx->gtkOffloadReqParams.ulFlags = GTK_OFFLOAD_DISABLE;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05305292 }
5293#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005294 pRoamProfile->csrPersona = pAdapter->device_mode;
5295
Jeff Johnson32d95a32012-09-10 13:15:23 -07005296 if( operatingChannel )
5297 {
5298 pRoamProfile->ChannelInfo.ChannelList = &operatingChannel;
5299 pRoamProfile->ChannelInfo.numOfChannels = 1;
5300 }
Chet Lanctot186b5732013-03-18 10:26:30 -07005301 else
5302 {
5303 pRoamProfile->ChannelInfo.ChannelList = NULL;
5304 pRoamProfile->ChannelInfo.numOfChannels = 0;
5305 }
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07005306 if ( (WLAN_HDD_IBSS == pAdapter->device_mode) && operatingChannel)
5307 {
5308 hdd_select_cbmode(pAdapter,operatingChannel);
5309 }
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08005310 /* change conn_state to connecting before sme_RoamConnect(), because sme_RoamConnect()
5311 * has a direct path to call hdd_smeRoamCallback(), which will change the conn_state
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305312 * If direct path, conn_state will be accordingly changed to NotConnected or Associated
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08005313 * by either hdd_AssociationCompletionHandler() or hdd_DisConnectHandler() in sme_RoamCallback()
Madan Mohan Koyyalamudidf86c422012-12-04 17:03:44 -08005314 * if sme_RomConnect is to be queued, Connecting state will remain until it is completed.
5315 */
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +05305316 if (WLAN_HDD_INFRA_STATION == pAdapter->device_mode ||
5317 WLAN_HDD_P2P_CLIENT == pAdapter->device_mode)
Madan Mohan Koyyalamudidf86c422012-12-04 17:03:44 -08005318 hdd_connSetConnectionState(WLAN_HDD_GET_STATION_CTX_PTR(pAdapter),
5319 eConnectionState_Connecting);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305320
5321 status = sme_RoamConnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07005322 pAdapter->sessionId, pRoamProfile, &roamId);
5323
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +05305324 if ((eHAL_STATUS_SUCCESS != status) &&
5325 (WLAN_HDD_INFRA_STATION == pAdapter->device_mode ||
5326 WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
Madan Mohan Koyyalamudid5acbf52012-11-28 01:45:08 +05305327
5328 {
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08005329 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: sme_RoamConnect (session %d) failed with "
5330 "status %d. -> NotConnected", __func__, pAdapter->sessionId, status);
5331 /* change back to NotAssociated */
Madan Mohan Koyyalamudid5acbf52012-11-28 01:45:08 +05305332 hdd_connSetConnectionState(WLAN_HDD_GET_STATION_CTX_PTR(pAdapter),
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08005333 eConnectionState_NotConnected);
Madan Mohan Koyyalamudid5acbf52012-11-28 01:45:08 +05305334 }
Madan Mohan Koyyalamudidf86c422012-12-04 17:03:44 -08005335
5336 pRoamProfile->ChannelInfo.ChannelList = NULL;
5337 pRoamProfile->ChannelInfo.numOfChannels = 0;
5338
Jeff Johnson295189b2012-06-20 16:38:30 -07005339 }
5340 else
5341 {
5342 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: No valid Roam profile", __func__);
5343 return -EINVAL;
5344 }
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08005345 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07005346 return status;
5347}
5348
5349/*
5350 * FUNCTION: wlan_hdd_set_cfg80211_auth_type
5351 * This function is used to set the authentication type (OPEN/SHARED).
5352 *
5353 */
5354static int wlan_hdd_cfg80211_set_auth_type(hdd_adapter_t *pAdapter,
5355 enum nl80211_auth_type auth_type)
5356{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305357 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07005358 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
5359
5360 ENTER();
5361
5362 /*set authentication type*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305363 switch (auth_type)
Jeff Johnson295189b2012-06-20 16:38:30 -07005364 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005365 case NL80211_AUTHTYPE_AUTOMATIC:
Gopichand Nakkala29149562013-05-10 21:43:41 +05305366 hddLog(VOS_TRACE_LEVEL_INFO,
5367 "%s: set authentication type to AUTOSWITCH", __func__);
5368 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_AUTOSWITCH;
5369 break;
5370
5371 case NL80211_AUTHTYPE_OPEN_SYSTEM:
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07005372#ifdef WLAN_FEATURE_VOWIFI_11R
5373 case NL80211_AUTHTYPE_FT:
5374#endif /* WLAN_FEATURE_VOWIFI_11R */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305375 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07005376 "%s: set authentication type to OPEN", __func__);
5377 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
5378 break;
5379
5380 case NL80211_AUTHTYPE_SHARED_KEY:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305381 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07005382 "%s: set authentication type to SHARED", __func__);
5383 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_SHARED_KEY;
5384 break;
5385#ifdef FEATURE_WLAN_CCX
5386 case NL80211_AUTHTYPE_NETWORK_EAP:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305387 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07005388 "%s: set authentication type to CCKM WPA", __func__);
5389 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_CCKM_WPA;//eCSR_AUTH_TYPE_CCKM_RSN needs to be handled as well if required.
5390 break;
5391#endif
5392
5393
5394 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305395 hddLog(VOS_TRACE_LEVEL_ERROR,
5396 "%s: Unsupported authentication type %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07005397 auth_type);
5398 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_UNKNOWN;
5399 return -EINVAL;
5400 }
5401
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305402 pWextState->roamProfile.AuthType.authType[0] =
Jeff Johnson295189b2012-06-20 16:38:30 -07005403 pHddStaCtx->conn_info.authType;
5404 return 0;
5405}
5406
5407/*
5408 * FUNCTION: wlan_hdd_set_akm_suite
5409 * This function is used to set the key mgmt type(PSK/8021x).
5410 *
5411 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305412static int wlan_hdd_set_akm_suite( hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07005413 u32 key_mgmt
5414 )
5415{
5416 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
5417 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305418
Jeff Johnson295189b2012-06-20 16:38:30 -07005419 /*set key mgmt type*/
5420 switch(key_mgmt)
5421 {
5422 case WLAN_AKM_SUITE_PSK:
Gopichand Nakkala356fb102013-03-06 12:34:04 +05305423#ifdef WLAN_FEATURE_VOWIFI_11R
5424 case WLAN_AKM_SUITE_FT_PSK:
5425#endif
5426 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting key mgmt type to PSK",
Jeff Johnson295189b2012-06-20 16:38:30 -07005427 __func__);
5428 pWextState->authKeyMgmt |= IW_AUTH_KEY_MGMT_PSK;
5429 break;
5430
5431 case WLAN_AKM_SUITE_8021X:
Gopichand Nakkala356fb102013-03-06 12:34:04 +05305432#ifdef WLAN_FEATURE_VOWIFI_11R
5433 case WLAN_AKM_SUITE_FT_8021X:
5434#endif
5435 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting key mgmt type to 8021x",
Jeff Johnson295189b2012-06-20 16:38:30 -07005436 __func__);
5437 pWextState->authKeyMgmt |= IW_AUTH_KEY_MGMT_802_1X;
5438 break;
5439#ifdef FEATURE_WLAN_CCX
5440#define WLAN_AKM_SUITE_CCKM 0x00409600 /* Should be in ieee802_11_defs.h */
5441#define IW_AUTH_KEY_MGMT_CCKM 8 /* Should be in linux/wireless.h */
5442 case WLAN_AKM_SUITE_CCKM:
5443 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting key mgmt type to CCKM",
5444 __func__);
5445 pWextState->authKeyMgmt |= IW_AUTH_KEY_MGMT_CCKM;
5446 break;
5447#endif
5448
5449 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305450 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported key mgmt type %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005451 __func__, key_mgmt);
5452 return -EINVAL;
5453
5454 }
5455 return 0;
5456}
5457
5458/*
5459 * FUNCTION: wlan_hdd_cfg80211_set_cipher
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305460 * This function is used to set the encryption type
Jeff Johnson295189b2012-06-20 16:38:30 -07005461 * (NONE/WEP40/WEP104/TKIP/CCMP).
5462 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305463static int wlan_hdd_cfg80211_set_cipher( hdd_adapter_t *pAdapter,
5464 u32 cipher,
Jeff Johnson295189b2012-06-20 16:38:30 -07005465 bool ucast
5466 )
5467{
5468 eCsrEncryptionType encryptionType = eCSR_ENCRYPT_TYPE_NONE;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305469 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07005470 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
5471
5472 ENTER();
5473
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305474 if (!cipher)
Jeff Johnson295189b2012-06-20 16:38:30 -07005475 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305476 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: received cipher %d - considering none",
Jeff Johnson295189b2012-06-20 16:38:30 -07005477 __func__, cipher);
5478 encryptionType = eCSR_ENCRYPT_TYPE_NONE;
5479 }
5480 else
5481 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305482
Jeff Johnson295189b2012-06-20 16:38:30 -07005483 /*set encryption method*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305484 switch (cipher)
Jeff Johnson295189b2012-06-20 16:38:30 -07005485 {
5486 case IW_AUTH_CIPHER_NONE:
5487 encryptionType = eCSR_ENCRYPT_TYPE_NONE;
5488 break;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305489
Jeff Johnson295189b2012-06-20 16:38:30 -07005490 case WLAN_CIPHER_SUITE_WEP40:
Gopichand Nakkala29149562013-05-10 21:43:41 +05305491 encryptionType = eCSR_ENCRYPT_TYPE_WEP40;
Jeff Johnson295189b2012-06-20 16:38:30 -07005492 break;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305493
Jeff Johnson295189b2012-06-20 16:38:30 -07005494 case WLAN_CIPHER_SUITE_WEP104:
Gopichand Nakkala29149562013-05-10 21:43:41 +05305495 encryptionType = eCSR_ENCRYPT_TYPE_WEP104;
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_TKIP:
5499 encryptionType = eCSR_ENCRYPT_TYPE_TKIP;
5500 break;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305501
Jeff Johnson295189b2012-06-20 16:38:30 -07005502 case WLAN_CIPHER_SUITE_CCMP:
5503 encryptionType = eCSR_ENCRYPT_TYPE_AES;
5504 break;
5505#ifdef FEATURE_WLAN_WAPI
5506 case WLAN_CIPHER_SUITE_SMS4:
5507 encryptionType = eCSR_ENCRYPT_TYPE_WPI;
5508 break;
5509#endif
5510
5511#ifdef FEATURE_WLAN_CCX
5512 case WLAN_CIPHER_SUITE_KRK:
5513 encryptionType = eCSR_ENCRYPT_TYPE_KRK;
5514 break;
5515#endif
5516 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305517 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported cipher type %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005518 __func__, cipher);
5519 return -EOPNOTSUPP;
5520 }
5521 }
5522
5523 if (ucast)
5524 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305525 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting unicast cipher type to %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005526 __func__, encryptionType);
5527 pHddStaCtx->conn_info.ucEncryptionType = encryptionType;
5528 pWextState->roamProfile.EncryptionType.numEntries = 1;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305529 pWextState->roamProfile.EncryptionType.encryptionType[0] =
Jeff Johnson295189b2012-06-20 16:38:30 -07005530 encryptionType;
5531 }
5532 else
5533 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305534 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting mcast cipher type to %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005535 __func__, encryptionType);
5536 pHddStaCtx->conn_info.mcEncryptionType = encryptionType;
5537 pWextState->roamProfile.mcEncryptionType.numEntries = 1;
5538 pWextState->roamProfile.mcEncryptionType.encryptionType[0] = encryptionType;
5539 }
5540
5541 return 0;
5542}
5543
5544
5545/*
5546 * FUNCTION: wlan_hdd_cfg80211_set_ie
5547 * This function is used to parse WPA/RSN IE's.
5548 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305549int wlan_hdd_cfg80211_set_ie( hdd_adapter_t *pAdapter,
5550 u8 *ie,
Jeff Johnson295189b2012-06-20 16:38:30 -07005551 size_t ie_len
5552 )
5553{
5554 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
5555 u8 *genie = ie;
5556 v_U16_t remLen = ie_len;
5557#ifdef FEATURE_WLAN_WAPI
5558 v_U32_t akmsuite[MAX_NUM_AKM_SUITES];
5559 u16 *tmp;
5560 v_U16_t akmsuiteCount;
5561 int *akmlist;
5562#endif
5563 ENTER();
5564
5565 /* clear previous assocAddIE */
5566 pWextState->assocAddIE.length = 0;
5567 pWextState->roamProfile.bWPSAssociation = VOS_FALSE;
5568
5569 while (remLen >= 2)
5570 {
5571 v_U16_t eLen = 0;
5572 v_U8_t elementId;
5573 elementId = *genie++;
5574 eLen = *genie++;
5575 remLen -= 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305576
5577 hddLog(VOS_TRACE_LEVEL_INFO, "%s: IE[0x%X], LEN[%d]\n",
Jeff Johnson295189b2012-06-20 16:38:30 -07005578 __func__, elementId, eLen);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305579
5580 switch ( elementId )
Jeff Johnson295189b2012-06-20 16:38:30 -07005581 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305582 case DOT11F_EID_WPA:
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005583 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 -07005584 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305585 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005586 "%s: Invalid WPA IE", __func__);
5587 return -EINVAL;
5588 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305589 else if (0 == memcmp(&genie[0], "\x00\x50\xf2\x04", 4))
Jeff Johnson295189b2012-06-20 16:38:30 -07005590 {
5591 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305592 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set WPS IE(len %d)",
Jeff Johnson295189b2012-06-20 16:38:30 -07005593 __func__, eLen + 2);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305594
Jeff Johnson295189b2012-06-20 16:38:30 -07005595 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5596 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005597 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE. "
5598 "Need bigger buffer space");
Jeff Johnson295189b2012-06-20 16:38:30 -07005599 VOS_ASSERT(0);
5600 return -ENOMEM;
5601 }
5602 // WSC IE is saved to Additional IE ; it should be accumulated to handle WPS IE + P2P IE
5603 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5604 pWextState->assocAddIE.length += eLen + 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305605
Jeff Johnson295189b2012-06-20 16:38:30 -07005606 pWextState->roamProfile.bWPSAssociation = VOS_TRUE;
5607 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5608 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5609 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305610 else if (0 == memcmp(&genie[0], "\x00\x50\xf2", 3))
5611 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005612 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set WPA IE (len %d)",__func__, eLen + 2);
5613 memset( pWextState->WPARSNIE, 0, MAX_WPA_RSN_IE_LEN );
5614 memcpy( pWextState->WPARSNIE, genie - 2, (eLen + 2) /*ie_len*/);
5615 pWextState->roamProfile.pWPAReqIE = pWextState->WPARSNIE;
5616 pWextState->roamProfile.nWPAReqIELength = eLen + 2;//ie_len;
5617 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305618 else if ( (0 == memcmp(&genie[0], P2P_OUI_TYPE,
5619 P2P_OUI_TYPE_SIZE))
Jeff Johnson295189b2012-06-20 16:38:30 -07005620 /*Consider P2P IE, only for P2P Client */
5621 && (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) )
5622 {
5623 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305624 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set P2P IE(len %d)",
Jeff Johnson295189b2012-06-20 16:38:30 -07005625 __func__, eLen + 2);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305626
Jeff Johnson295189b2012-06-20 16:38:30 -07005627 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5628 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005629 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
5630 "Need bigger buffer space");
Jeff Johnson295189b2012-06-20 16:38:30 -07005631 VOS_ASSERT(0);
5632 return -ENOMEM;
5633 }
5634 // P2P IE is saved to Additional IE ; it should be accumulated to handle WPS IE + P2P IE
5635 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5636 pWextState->assocAddIE.length += eLen + 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305637
Jeff Johnson295189b2012-06-20 16:38:30 -07005638 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5639 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5640 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005641#ifdef WLAN_FEATURE_WFD
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305642 else if ( (0 == memcmp(&genie[0], WFD_OUI_TYPE,
5643 WFD_OUI_TYPE_SIZE))
Jeff Johnson295189b2012-06-20 16:38:30 -07005644 /*Consider WFD IE, only for P2P Client */
5645 && (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) )
5646 {
5647 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305648 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set WFD IE(len %d)",
Jeff Johnson295189b2012-06-20 16:38:30 -07005649 __func__, eLen + 2);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305650
Jeff Johnson295189b2012-06-20 16:38:30 -07005651 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5652 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005653 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
5654 "Need bigger buffer space");
Jeff Johnson295189b2012-06-20 16:38:30 -07005655 VOS_ASSERT(0);
5656 return -ENOMEM;
5657 }
5658 // WFD IE is saved to Additional IE ; it should be accumulated to handle
5659 // WPS IE + P2P IE + WFD IE
5660 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5661 pWextState->assocAddIE.length += eLen + 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305662
Jeff Johnson295189b2012-06-20 16:38:30 -07005663 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5664 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5665 }
5666#endif
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005667 /* Appending HS 2.0 Indication Element in Assiciation Request */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305668 else if ( (0 == memcmp(&genie[0], HS20_OUI_TYPE,
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005669 HS20_OUI_TYPE_SIZE)) )
5670 {
5671 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305672 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set HS20 IE(len %d)",
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005673 __func__, eLen + 2);
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005674
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005675 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5676 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005677 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
5678 "Need bigger buffer space");
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005679 VOS_ASSERT(0);
5680 return -ENOMEM;
5681 }
5682 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5683 pWextState->assocAddIE.length += eLen + 2;
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005684
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005685 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5686 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5687 }
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005688
Praveen Kumar Sirisilla7d68b7b2013-09-22 14:01:42 -07005689 if (WLAN_HDD_IBSS == pAdapter->device_mode) {
5690
5691 /* populating as ADDIE in beacon frames */
5692 if (ccmCfgSetStr(WLAN_HDD_GET_HAL_CTX(pAdapter),
5693 WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA, genie - 2, eLen + 2,
5694 NULL, eANI_BOOLEAN_FALSE)== eHAL_STATUS_SUCCESS)
5695 {
5696 if (ccmCfgSetInt(WLAN_HDD_GET_HAL_CTX(pAdapter),
5697 WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG, 1,NULL,
5698 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
5699 {
5700 hddLog(LOGE,
5701 "Coldn't pass "
5702 "WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG to CCM");
5703 }
5704 }/* ccmCfgSetStr(,WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA, , )*/
5705 else
5706 hddLog(LOGE,
5707 "Could not pass on "
5708 "WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA to CCM");
5709
5710 /* IBSS mode doesn't contain params->proberesp_ies still
5711 beaconIE's need to be populated in probe response frames */
5712 if ( (NULL != (genie - 2)) && (0 != eLen + 2) )
5713 {
5714 u16 rem_probe_resp_ie_len = eLen + 2;
5715 u8 probe_rsp_ie_len[3] = {0};
5716 u8 counter = 0;
5717
5718 /* Check Probe Resp Length if it is greater then 255 then
5719 Store Probe Rsp IEs into WNI_CFG_PROBE_RSP_ADDNIE_DATA1
5720 & WNI_CFG_PROBE_RSP_ADDNIE_DATA2 CFG Variable As We are
5721 not able Store More then 255 bytes into One Variable */
5722
5723 while ((rem_probe_resp_ie_len > 0) && (counter < 3))
5724 {
5725 if (rem_probe_resp_ie_len > MAX_CFG_STRING_LEN)
5726 {
5727 probe_rsp_ie_len[counter++] = MAX_CFG_STRING_LEN;
5728 rem_probe_resp_ie_len -= MAX_CFG_STRING_LEN;
5729 }
5730 else
5731 {
5732 probe_rsp_ie_len[counter++] = rem_probe_resp_ie_len;
5733 rem_probe_resp_ie_len = 0;
5734 }
5735 }
5736
5737 rem_probe_resp_ie_len = 0;
5738
5739 if (probe_rsp_ie_len[0] > 0)
5740 {
5741 if (ccmCfgSetStr(WLAN_HDD_GET_HAL_CTX(pAdapter),
5742 WNI_CFG_PROBE_RSP_ADDNIE_DATA1,
5743 (tANI_U8*)(genie - 2),
5744 probe_rsp_ie_len[0], NULL,
5745 eANI_BOOLEAN_FALSE)
5746 == eHAL_STATUS_FAILURE)
5747 {
5748 hddLog(LOGE,
5749 "Could not pass"
5750 "on WNI_CFG_PROBE_RSP_ADDNIE_DATA1 to CCM");
5751 }
5752 rem_probe_resp_ie_len += probe_rsp_ie_len[0];
5753 }
5754
5755 if (probe_rsp_ie_len[1] > 0)
5756 {
5757 if (ccmCfgSetStr(WLAN_HDD_GET_HAL_CTX(pAdapter),
5758 WNI_CFG_PROBE_RSP_ADDNIE_DATA2,
5759 (tANI_U8*)(genie - (2 + rem_probe_resp_ie_len)),
5760 probe_rsp_ie_len[1], NULL,
5761 eANI_BOOLEAN_FALSE)
5762 == eHAL_STATUS_FAILURE)
5763 {
5764 hddLog(LOGE,
5765 "Could not pass"
5766 "on WNI_CFG_PROBE_RSP_ADDNIE_DATA2 to CCM");
5767 }
5768 rem_probe_resp_ie_len += probe_rsp_ie_len[1];
5769 }
5770
5771 if (probe_rsp_ie_len[2] > 0)
5772 {
5773 if (ccmCfgSetStr(WLAN_HDD_GET_HAL_CTX(pAdapter),
5774 WNI_CFG_PROBE_RSP_ADDNIE_DATA3,
5775 (tANI_U8*)(genie - (2 + rem_probe_resp_ie_len)),
5776 probe_rsp_ie_len[2], NULL,
5777 eANI_BOOLEAN_FALSE)
5778 == eHAL_STATUS_FAILURE)
5779 {
5780 hddLog(LOGE,
5781 "Could not pass"
5782 "on WNI_CFG_PROBE_RSP_ADDNIE_DATA3 to CCM");
5783 }
5784 rem_probe_resp_ie_len += probe_rsp_ie_len[2];
5785 }
5786
5787 if (ccmCfgSetInt(WLAN_HDD_GET_HAL_CTX(pAdapter),
5788 WNI_CFG_PROBE_RSP_ADDNIE_FLAG, 1,NULL,
5789 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
5790 {
5791 hddLog(LOGE,
5792 "Could not pass"
5793 "on WNI_CFG_PROBE_RSP_ADDNIE_FLAG to CCM");
5794 }
5795 }
5796 else
5797 {
5798 // Reset WNI_CFG_PROBE_RSP Flags
5799 wlan_hdd_reset_prob_rspies(pAdapter);
5800
5801 hddLog(VOS_TRACE_LEVEL_INFO,
5802 "%s: No Probe Response IE received in set beacon",
5803 __func__);
5804 }
5805 } /* end of if (WLAN_HDD_IBSS == pAdapter->device_mode) */
Jeff Johnson295189b2012-06-20 16:38:30 -07005806 break;
5807 case DOT11F_EID_RSN:
5808 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set RSN IE(len %d)",__func__, eLen + 2);
5809 memset( pWextState->WPARSNIE, 0, MAX_WPA_RSN_IE_LEN );
5810 memcpy( pWextState->WPARSNIE, genie - 2, (eLen + 2)/*ie_len*/);
5811 pWextState->roamProfile.pRSNReqIE = pWextState->WPARSNIE;
5812 pWextState->roamProfile.nRSNReqIELength = eLen + 2; //ie_len;
5813 break;
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005814 /* Appending Extended Capabilities with Interworking bit set in Assoc Req */
5815 case DOT11F_EID_EXTCAP:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305816 {
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005817 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305818 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set Extended CAPS IE(len %d)",
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005819 __func__, eLen + 2);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305820
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005821 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5822 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005823 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
5824 "Need bigger buffer space");
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005825 VOS_ASSERT(0);
5826 return -ENOMEM;
5827 }
5828 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5829 pWextState->assocAddIE.length += eLen + 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305830
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005831 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5832 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5833 break;
5834 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005835#ifdef FEATURE_WLAN_WAPI
5836 case WLAN_EID_WAPI:
5837 pAdapter->wapi_info.nWapiMode = 1; //Setting WAPI Mode to ON=1
5838 hddLog(VOS_TRACE_LEVEL_INFO,"WAPI MODE IS %lu \n",
5839 pAdapter->wapi_info.nWapiMode);
5840 tmp = (u16 *)ie;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305841 tmp = tmp + 2; // Skip element Id and Len, Version
Jeff Johnson295189b2012-06-20 16:38:30 -07005842 akmsuiteCount = WPA_GET_LE16(tmp);
5843 tmp = tmp + 1;
5844 akmlist = (int *)(tmp);
5845 if(akmsuiteCount <= MAX_NUM_AKM_SUITES)
5846 {
5847 memcpy(akmsuite, akmlist, (4*akmsuiteCount));
5848 }
5849 else
5850 {
5851 hddLog(VOS_TRACE_LEVEL_FATAL, "Invalid akmSuite count\n");
5852 VOS_ASSERT(0);
5853 return -EINVAL;
5854 }
5855
5856 if (WAPI_PSK_AKM_SUITE == akmsuite[0])
5857 {
5858 hddLog(VOS_TRACE_LEVEL_INFO, "%s: WAPI AUTH MODE SET TO PSK",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005859 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005860 pAdapter->wapi_info.wapiAuthMode = WAPI_AUTH_MODE_PSK;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305861 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005862 if (WAPI_CERT_AKM_SUITE == akmsuite[0])
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305863 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005864 hddLog(VOS_TRACE_LEVEL_INFO, "%s: WAPI AUTH MODE SET TO CERTIFICATE",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005865 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005866 pAdapter->wapi_info.wapiAuthMode = WAPI_AUTH_MODE_CERT;
5867 }
5868 break;
5869#endif
5870 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305871 hddLog (VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005872 "%s Set UNKNOWN IE %X", __func__, elementId);
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005873 /* when Unknown IE is received we should break and continue
5874 * to the next IE in the buffer instead we were returning
5875 * so changing this to break */
5876 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07005877 }
5878 genie += eLen;
5879 remLen -= eLen;
5880 }
5881 EXIT();
5882 return 0;
5883}
5884
5885/*
Gopichand Nakkala18f0c262013-05-07 23:25:08 +05305886 * FUNCTION: hdd_isWPAIEPresent
5887 * Parse the received IE to find the WPA IE
5888 *
5889 */
5890static bool hdd_isWPAIEPresent(u8 *ie, u8 ie_len)
5891{
5892 v_U8_t eLen = 0;
5893 v_U16_t remLen = ie_len;
5894 v_U8_t elementId = 0;
5895
5896 while (remLen >= 2)
5897 {
5898 elementId = *ie++;
5899 eLen = *ie++;
5900 remLen -= 2;
5901 if (eLen > remLen)
5902 {
5903 hddLog(VOS_TRACE_LEVEL_ERROR,
5904 "%s: IE length is wrong %d", __func__, eLen);
5905 return FALSE;
5906 }
5907 if ((elementId == DOT11F_EID_WPA) && (remLen > 5))
5908 {
5909 /* OUI - 0x00 0X50 0XF2
5910 WPA Information Element - 0x01
5911 WPA version - 0x01*/
5912 if (0 == memcmp(&ie[0], "\x00\x50\xf2\x01\x01", 5))
5913 return TRUE;
5914 }
5915 ie += eLen;
5916 remLen -= eLen;
5917 }
5918 return FALSE;
5919}
5920
5921/*
Jeff Johnson295189b2012-06-20 16:38:30 -07005922 * FUNCTION: wlan_hdd_cfg80211_set_privacy
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305923 * This function is used to initialize the security
Jeff Johnson295189b2012-06-20 16:38:30 -07005924 * parameters during connect operation.
5925 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305926int wlan_hdd_cfg80211_set_privacy( hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07005927 struct cfg80211_connect_params *req
5928 )
5929{
5930 int status = 0;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305931 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07005932 ENTER();
5933
5934 /*set wpa version*/
5935 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_DISABLED;
5936
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305937 if (req->crypto.wpa_versions)
Jeff Johnson295189b2012-06-20 16:38:30 -07005938 {
Gopichand Nakkala781ded42013-06-28 12:10:45 +05305939 if (NL80211_WPA_VERSION_1 == req->crypto.wpa_versions)
Jeff Johnson295189b2012-06-20 16:38:30 -07005940 {
5941 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA;
5942 }
5943 else if (NL80211_WPA_VERSION_2 == req->crypto.wpa_versions)
5944 {
5945 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA2;
5946 }
5947 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305948
5949 hddLog(VOS_TRACE_LEVEL_INFO, "%s: set wpa version to %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07005950 pWextState->wpaVersion);
5951
5952 /*set authentication type*/
5953 status = wlan_hdd_cfg80211_set_auth_type(pAdapter, req->auth_type);
5954
5955 if (0 > status)
5956 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305957 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005958 "%s: failed to set authentication type ", __func__);
5959 return status;
5960 }
5961
5962 /*set key mgmt type*/
5963 if (req->crypto.n_akm_suites)
5964 {
5965 status = wlan_hdd_set_akm_suite(pAdapter, req->crypto.akm_suites[0]);
5966 if (0 > status)
5967 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305968 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set akm suite",
Jeff Johnson295189b2012-06-20 16:38:30 -07005969 __func__);
5970 return status;
5971 }
5972 }
5973
5974 /*set pairwise cipher type*/
5975 if (req->crypto.n_ciphers_pairwise)
5976 {
5977 status = wlan_hdd_cfg80211_set_cipher(pAdapter,
5978 req->crypto.ciphers_pairwise[0], true);
5979 if (0 > status)
5980 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305981 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005982 "%s: failed to set unicast cipher type", __func__);
5983 return status;
5984 }
5985 }
5986 else
5987 {
5988 /*Reset previous cipher suite to none*/
5989 status = wlan_hdd_cfg80211_set_cipher(pAdapter, 0, true);
5990 if (0 > status)
5991 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305992 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005993 "%s: failed to set unicast cipher type", __func__);
5994 return status;
5995 }
5996 }
5997
5998 /*set group cipher type*/
5999 status = wlan_hdd_cfg80211_set_cipher(pAdapter, req->crypto.cipher_group,
6000 false);
6001
6002 if (0 > status)
6003 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306004 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set mcast cipher type",
Jeff Johnson295189b2012-06-20 16:38:30 -07006005 __func__);
6006 return status;
6007 }
6008
Chet Lanctot186b5732013-03-18 10:26:30 -07006009#ifdef WLAN_FEATURE_11W
6010 pWextState->roamProfile.MFPEnabled = (req->mfp == NL80211_MFP_REQUIRED);
6011#endif
6012
Jeff Johnson295189b2012-06-20 16:38:30 -07006013 /*parse WPA/RSN IE, and set the correspoing fileds in Roam profile*/
6014 if (req->ie_len)
6015 {
6016 status = wlan_hdd_cfg80211_set_ie(pAdapter, req->ie, req->ie_len);
6017 if ( 0 > status)
6018 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306019 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to parse the WPA/RSN IE",
Jeff Johnson295189b2012-06-20 16:38:30 -07006020 __func__);
6021 return status;
6022 }
6023 }
6024
6025 /*incase of WEP set default key information*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306026 if (req->key && req->key_len)
Jeff Johnson295189b2012-06-20 16:38:30 -07006027 {
6028 if ( (WLAN_CIPHER_SUITE_WEP40 == req->crypto.ciphers_pairwise[0])
6029 || (WLAN_CIPHER_SUITE_WEP104 == req->crypto.ciphers_pairwise[0])
6030 )
6031 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306032 if ( IW_AUTH_KEY_MGMT_802_1X
Jeff Johnson295189b2012-06-20 16:38:30 -07006033 == (pWextState->authKeyMgmt & IW_AUTH_KEY_MGMT_802_1X ))
6034 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306035 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Dynamic WEP not supported",
Jeff Johnson295189b2012-06-20 16:38:30 -07006036 __func__);
6037 return -EOPNOTSUPP;
6038 }
6039 else
6040 {
6041 u8 key_len = req->key_len;
6042 u8 key_idx = req->key_idx;
6043
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306044 if ((eCSR_SECURITY_WEP_KEYSIZE_MAX_BYTES >= key_len)
Jeff Johnson295189b2012-06-20 16:38:30 -07006045 && (CSR_MAX_NUM_KEY > key_idx)
6046 )
6047 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306048 hddLog(VOS_TRACE_LEVEL_INFO,
6049 "%s: setting default wep key, key_idx = %hu key_len %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006050 __func__, key_idx, key_len);
6051 vos_mem_copy(
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306052 &pWextState->roamProfile.Keys.KeyMaterial[key_idx][0],
Jeff Johnson295189b2012-06-20 16:38:30 -07006053 req->key, key_len);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306054 pWextState->roamProfile.Keys.KeyLength[key_idx] =
Jeff Johnson295189b2012-06-20 16:38:30 -07006055 (u8)key_len;
6056 pWextState->roamProfile.Keys.defaultIndex = (u8)key_idx;
6057 }
6058 }
6059 }
6060 }
6061
6062 return status;
6063}
6064
6065/*
6066 * FUNCTION: wlan_hdd_cfg80211_set_privacy
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306067 * This function is used to initialize the security
Jeff Johnson295189b2012-06-20 16:38:30 -07006068 * parameters during connect operation.
6069 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306070static int wlan_hdd_cfg80211_connect( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07006071 struct net_device *ndev,
6072 struct cfg80211_connect_params *req
6073 )
6074{
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306075 int status;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306076 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Jeff Johnson295189b2012-06-20 16:38:30 -07006077 VOS_STATUS exitbmpsStatus = VOS_STATUS_E_INVAL;
6078 hdd_context_t *pHddCtx = NULL;
6079
6080 ENTER();
6081
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306082 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07006083 "%s: device_mode = %d\n",__func__,pAdapter->device_mode);
6084
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306085 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
6086 status = wlan_hdd_validate_context(pHddCtx);
6087
6088 if (0 != status)
Jeff Johnson295189b2012-06-20 16:38:30 -07006089 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306090 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6091 "%s: HDD context is not valid", __func__);
6092 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006093 }
6094
6095#ifdef WLAN_BTAMP_FEATURE
6096 //Infra connect not supported when AMP traffic is on.
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306097 if( VOS_TRUE == WLANBAP_AmpSessionOn() )
Jeff Johnson295189b2012-06-20 16:38:30 -07006098 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306099 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07006100 "%s: No connection when AMP is on", __func__);
Madan Mohan Koyyalamudicae253a2012-11-06 19:10:35 -08006101 return -ECONNREFUSED;
Jeff Johnson295189b2012-06-20 16:38:30 -07006102 }
6103#endif
6104 /*initialise security parameters*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306105 status = wlan_hdd_cfg80211_set_privacy(pAdapter, req);
Jeff Johnson295189b2012-06-20 16:38:30 -07006106
6107 if ( 0 > status)
6108 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306109 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set security params",
Jeff Johnson295189b2012-06-20 16:38:30 -07006110 __func__);
6111 return status;
6112 }
6113
6114 //If Device Mode is Station Concurrent Sessions Exit BMps
Jeff Johnsona8a1a482012-12-12 16:49:33 -08006115 //P2P Mode will be taken care in Open/close adapter
Jeff Johnson295189b2012-06-20 16:38:30 -07006116 if((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) &&
6117 (vos_concurrent_sessions_running()))
6118 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306119 exitbmpsStatus = hdd_disable_bmps_imps(pHddCtx, WLAN_HDD_INFRA_STATION);
Jeff Johnson295189b2012-06-20 16:38:30 -07006120 }
6121
Mohit Khanna765234a2012-09-11 15:08:35 -07006122 if ( req->channel )
6123 {
6124 status = wlan_hdd_cfg80211_connect_start(pAdapter, req->ssid,
6125 req->ssid_len, req->bssid,
6126 req->channel->hw_value);
6127 }
6128 else
6129 {
6130 status = wlan_hdd_cfg80211_connect_start(pAdapter, req->ssid,
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306131 req->ssid_len, req->bssid, 0);
Mohit Khanna765234a2012-09-11 15:08:35 -07006132 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006133
6134 if (0 > status)
6135 {
6136 //ReEnable BMPS if disabled
6137 if((VOS_STATUS_SUCCESS == exitbmpsStatus) &&
6138 (NULL != pHddCtx))
6139 {
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05306140 if (pHddCtx->hdd_wlan_suspended)
6141 {
6142 hdd_set_pwrparams(pHddCtx);
6143 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006144 //ReEnable Bmps and Imps back
6145 hdd_enable_bmps_imps(pHddCtx);
6146 }
6147
6148 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: connect failed", __func__);
6149 return status;
6150 }
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306151 pHddCtx->isAmpAllowed = VOS_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006152 EXIT();
6153 return status;
6154}
6155
6156
6157/*
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306158 * FUNCTION: wlan_hdd_disconnect
6159 * This function is used to issue a disconnect request to SME
6160 */
6161int wlan_hdd_disconnect( hdd_adapter_t *pAdapter, u16 reason )
6162{
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306163 int status;
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306164 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306165 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
6166
6167 status = wlan_hdd_validate_context(pHddCtx);
6168
6169 if (0 != status)
6170 {
6171 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6172 "%s: HDD context is not valid", __func__);
6173 return status;
6174 }
6175
6176 pHddCtx->isAmpAllowed = VOS_TRUE;
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306177 pHddStaCtx->conn_info.connState = eConnectionState_NotConnected;
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306178 INIT_COMPLETION(pAdapter->disconnect_comp_var);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306179
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306180 /*issue disconnect*/
6181 status = sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
6182 pAdapter->sessionId, reason);
6183
6184 if ( 0 != status )
6185 {
6186 hddLog(VOS_TRACE_LEVEL_ERROR,
6187 "%s csrRoamDisconnect failure, returned %d \n",
6188 __func__, (int)status );
6189 return -EINVAL;
6190 }
6191 wait_for_completion_interruptible_timeout(
6192 &pAdapter->disconnect_comp_var,
6193 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
6194 /*stop tx queues*/
6195 netif_tx_disable(pAdapter->dev);
6196 netif_carrier_off(pAdapter->dev);
6197 return status;
6198}
6199
6200
6201/*
Jeff Johnson295189b2012-06-20 16:38:30 -07006202 * FUNCTION: wlan_hdd_cfg80211_disconnect
6203 * This function is used to issue a disconnect request to SME
6204 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306205static int wlan_hdd_cfg80211_disconnect( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07006206 struct net_device *dev,
6207 u16 reason
6208 )
6209{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306210 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
6211 tCsrRoamProfile *pRoamProfile =
Jeff Johnson295189b2012-06-20 16:38:30 -07006212 &(WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter))->roamProfile;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306213 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006214 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006215 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05306216#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006217 tANI_U8 staIdx;
6218#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306219
Jeff Johnson295189b2012-06-20 16:38:30 -07006220 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306221
6222 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
Jeff Johnson295189b2012-06-20 16:38:30 -07006223 __func__,pAdapter->device_mode);
6224
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306225 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Disconnect called with reason code %d",
6226 __func__, reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07006227
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306228 status = wlan_hdd_validate_context(pHddCtx);
6229
6230 if (0 != status)
Jeff Johnson295189b2012-06-20 16:38:30 -07006231 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306232 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6233 "%s: HDD context is not valid", __func__);
6234 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006235 }
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306236
Jeff Johnson295189b2012-06-20 16:38:30 -07006237 if (NULL != pRoamProfile)
6238 {
6239 /*issue disconnect request to SME, if station is in connected state*/
6240 if (pHddStaCtx->conn_info.connState == eConnectionState_Associated)
6241 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306242 eCsrRoamDisconnectReason reasonCode =
Jeff Johnson295189b2012-06-20 16:38:30 -07006243 eCSR_DISCONNECT_REASON_UNSPECIFIED;
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05306244 hdd_scaninfo_t *pScanInfo;
Jeff Johnson295189b2012-06-20 16:38:30 -07006245 switch(reason)
6246 {
6247 case WLAN_REASON_MIC_FAILURE:
6248 reasonCode = eCSR_DISCONNECT_REASON_MIC_ERROR;
6249 break;
6250
6251 case WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY:
6252 case WLAN_REASON_DISASSOC_AP_BUSY:
6253 case WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA:
6254 reasonCode = eCSR_DISCONNECT_REASON_DISASSOC;
6255 break;
6256
6257 case WLAN_REASON_PREV_AUTH_NOT_VALID:
6258 case WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA:
6259 reasonCode = eCSR_DISCONNECT_REASON_DEAUTH;
6260 break;
6261
6262 case WLAN_REASON_DEAUTH_LEAVING:
6263 default:
6264 reasonCode = eCSR_DISCONNECT_REASON_UNSPECIFIED;
6265 break;
6266 }
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05306267 pHddStaCtx->conn_info.connState = eConnectionState_NotConnected;
6268 pScanInfo = &pHddCtx->scan_info;
6269 if (pScanInfo->mScanPending)
6270 {
6271 hddLog(VOS_TRACE_LEVEL_INFO, "Disconnect is in progress, "
6272 "Aborting Scan");
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05306273 hdd_abort_mac_scan(pHddCtx, pAdapter->sessionId);
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05306274 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006275
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006276#ifdef FEATURE_WLAN_TDLS
6277 /* First clean up the tdls peers if any */
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006278 for (staIdx = 0 ; staIdx < HDD_MAX_NUM_TDLS_STA; staIdx++)
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006279 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006280 if ((pHddCtx->tdlsConnInfo[staIdx].sessionId == pAdapter->sessionId) &&
6281 (pHddCtx->tdlsConnInfo[staIdx].staId))
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006282 {
Hoonki Lee11f7dda2013-02-14 16:55:44 -08006283 uint8 *mac;
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006284 mac = pHddCtx->tdlsConnInfo[staIdx].peerMac.bytes;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08006285 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07006286 "%s: call sme_DeleteTdlsPeerSta staId %d sessionId %d " MAC_ADDRESS_STR,
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006287 __func__, pHddCtx->tdlsConnInfo[staIdx].staId, pAdapter->sessionId,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07006288 MAC_ADDR_ARRAY(mac));
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006289 sme_DeleteTdlsPeerSta(WLAN_HDD_GET_HAL_CTX(pAdapter),
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006290 pAdapter->sessionId,
6291 mac);
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006292 }
6293 }
6294#endif
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306295 status = wlan_hdd_disconnect(pAdapter, reasonCode);
6296 if ( 0 != status )
Jeff Johnson295189b2012-06-20 16:38:30 -07006297 {
6298 hddLog(VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306299 "%s wlan_hdd_disconnect failure, returned %d \n",
Jeff Johnson295189b2012-06-20 16:38:30 -07006300 __func__, (int)status );
6301 return -EINVAL;
6302 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006303 }
6304 }
6305 else
6306 {
6307 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: No valid roam profile", __func__);
6308 }
6309
6310 return status;
6311}
6312
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306313
Jeff Johnson295189b2012-06-20 16:38:30 -07006314/*
6315 * FUNCTION: wlan_hdd_cfg80211_set_privacy_ibss
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306316 * This function is used to initialize the security
Jeff Johnson295189b2012-06-20 16:38:30 -07006317 * settings in IBSS mode.
6318 */
6319static int wlan_hdd_cfg80211_set_privacy_ibss(
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306320 hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07006321 struct cfg80211_ibss_params *params
6322 )
6323{
6324 int status = 0;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306325 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07006326 eCsrEncryptionType encryptionType = eCSR_ENCRYPT_TYPE_NONE;
6327 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306328
Jeff Johnson295189b2012-06-20 16:38:30 -07006329 ENTER();
6330
6331 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_DISABLED;
6332
6333 if (params->ie_len && ( NULL != params->ie) )
6334 {
Shailender Karmuchi67edd312013-06-18 16:30:48 -07006335 if (wlan_hdd_cfg80211_get_ie_ptr (params->ie,
6336 params->ie_len, WLAN_EID_RSN ))
Jeff Johnson295189b2012-06-20 16:38:30 -07006337 {
6338 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA2;
6339 encryptionType = eCSR_ENCRYPT_TYPE_AES;
6340 }
Shailender Karmuchi67edd312013-06-18 16:30:48 -07006341 else if ( hdd_isWPAIEPresent (params->ie, params->ie_len ))
Jeff Johnson295189b2012-06-20 16:38:30 -07006342 {
Shailender Karmuchi642e9812013-05-30 14:34:49 -07006343 tDot11fIEWPA dot11WPAIE;
6344 tHalHandle halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
Shailender Karmuchi67edd312013-06-18 16:30:48 -07006345 u8 *ie;
Shailender Karmuchi642e9812013-05-30 14:34:49 -07006346
Wilson Yang00256342013-10-10 23:13:38 -07006347 memset(&dot11WPAIE, 0, sizeof(dot11WPAIE));
Shailender Karmuchi67edd312013-06-18 16:30:48 -07006348 ie = wlan_hdd_cfg80211_get_ie_ptr (params->ie,
6349 params->ie_len, DOT11F_EID_WPA);
6350 if ( NULL != ie )
6351 {
6352 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA;
6353 // Unpack the WPA IE
6354 //Skip past the EID byte and length byte - and four byte WiFi OUI
6355 dot11fUnpackIeWPA((tpAniSirGlobal) halHandle,
6356 &ie[2+4],
6357 ie[1] - 4,
6358 &dot11WPAIE);
6359 /*Extract the multicast cipher, the encType for unicast
6360 cipher for wpa-none is none*/
6361 encryptionType =
6362 hdd_TranslateWPAToCsrEncryptionType(dot11WPAIE.multicast_cipher);
6363 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006364 }
Shailender Karmuchi67edd312013-06-18 16:30:48 -07006365
Jeff Johnson295189b2012-06-20 16:38:30 -07006366 status = wlan_hdd_cfg80211_set_ie(pAdapter, params->ie, params->ie_len);
6367
6368 if (0 > status)
6369 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306370 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to parse WPA/RSN IE",
Jeff Johnson295189b2012-06-20 16:38:30 -07006371 __func__);
6372 return status;
6373 }
6374 }
6375
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306376 pWextState->roamProfile.AuthType.authType[0] =
6377 pHddStaCtx->conn_info.authType =
Jeff Johnson295189b2012-06-20 16:38:30 -07006378 eCSR_AUTH_TYPE_OPEN_SYSTEM;
6379
6380 if (params->privacy)
6381 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306382 /* Security enabled IBSS, At this time there is no information available
6383 * about the security paramters, so initialise the encryption type to
Jeff Johnson295189b2012-06-20 16:38:30 -07006384 * eCSR_ENCRYPT_TYPE_WEP40_STATICKEY.
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306385 * The correct security parameters will be updated later in
Jeff Johnson295189b2012-06-20 16:38:30 -07006386 * wlan_hdd_cfg80211_add_key */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306387 /* Hal expects encryption type to be set inorder
Jeff Johnson295189b2012-06-20 16:38:30 -07006388 *enable privacy bit in beacons */
6389
6390 encryptionType = eCSR_ENCRYPT_TYPE_WEP40_STATICKEY;
6391 }
Shailender Karmuchi642e9812013-05-30 14:34:49 -07006392 VOS_TRACE (VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
6393 "encryptionType=%d", encryptionType);
Jeff Johnson295189b2012-06-20 16:38:30 -07006394 pHddStaCtx->conn_info.ucEncryptionType = encryptionType;
6395 pWextState->roamProfile.EncryptionType.numEntries = 1;
6396 pWextState->roamProfile.EncryptionType.encryptionType[0] = encryptionType;
Jeff Johnson295189b2012-06-20 16:38:30 -07006397 return status;
6398}
6399
6400/*
6401 * FUNCTION: wlan_hdd_cfg80211_join_ibss
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306402 * This function is used to create/join an IBSS
Jeff Johnson295189b2012-06-20 16:38:30 -07006403 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306404static int wlan_hdd_cfg80211_join_ibss( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07006405 struct net_device *dev,
6406 struct cfg80211_ibss_params *params
6407 )
6408{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306409 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Jeff Johnson295189b2012-06-20 16:38:30 -07006410 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
6411 tCsrRoamProfile *pRoamProfile;
6412 int status;
6413 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306414 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07006415
6416 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306417
6418 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07006419 "%s: device_mode = %d\n",__func__,pAdapter->device_mode);
6420
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306421 status = wlan_hdd_validate_context(pHddCtx);
6422
6423 if (0 != status)
Jeff Johnson295189b2012-06-20 16:38:30 -07006424 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306425 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6426 "%s: HDD context is not valid", __func__);
6427 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006428 }
6429
6430 if (NULL == pWextState)
6431 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306432 hddLog (VOS_TRACE_LEVEL_ERROR, "%s ERROR: Data Storage Corruption\n",
Jeff Johnson295189b2012-06-20 16:38:30 -07006433 __func__);
6434 return -EIO;
6435 }
6436
6437 pRoamProfile = &pWextState->roamProfile;
6438
6439 if ( eCSR_BSS_TYPE_START_IBSS != pRoamProfile->BSSType )
6440 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306441 hddLog (VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07006442 "%s Interface type is not set to IBSS \n", __func__);
6443 return -EINVAL;
6444 }
6445
6446 /* Set Channel */
Yue Maf49ba872013-08-19 12:04:25 -07006447 if (NULL !=
6448#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0))
6449 params->chandef.chan)
6450#else
6451 params->channel)
6452#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006453 {
6454 u8 channelNum;
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006455 v_U32_t numChans = WNI_CFG_VALID_CHANNEL_LIST_LEN;
6456 v_U8_t validChan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
6457 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
6458 int indx;
Jeff Johnson295189b2012-06-20 16:38:30 -07006459
6460 /* Get channel number */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306461 channelNum =
Yue Maf49ba872013-08-19 12:04:25 -07006462 ieee80211_frequency_to_channel(
6463#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0))
6464 params->chandef.chan->center_freq);
6465#else
6466 params->channel->center_freq);
6467#endif
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006468
6469 if (0 != ccmCfgGetStr(hHal, WNI_CFG_VALID_CHANNEL_LIST,
6470 validChan, &numChans))
Jeff Johnson295189b2012-06-20 16:38:30 -07006471 {
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006472 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: No valid channel list",
6473 __func__);
6474 return -EOPNOTSUPP;
Jeff Johnson295189b2012-06-20 16:38:30 -07006475 }
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006476
6477 for (indx = 0; indx < numChans; indx++)
Jeff Johnson295189b2012-06-20 16:38:30 -07006478 {
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006479 if (channelNum == validChan[indx])
6480 {
6481 break;
6482 }
6483 }
6484 if (indx >= numChans)
6485 {
6486 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Not valid Channel %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07006487 __func__, channelNum);
6488 return -EINVAL;
6489 }
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006490 /* Set the Operational Channel */
6491 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: set channel %d", __func__,
6492 channelNum);
6493 pRoamProfile->ChannelInfo.numOfChannels = 1;
6494 pHddStaCtx->conn_info.operationChannel = channelNum;
6495 pRoamProfile->ChannelInfo.ChannelList =
6496 &pHddStaCtx->conn_info.operationChannel;
Jeff Johnson295189b2012-06-20 16:38:30 -07006497 }
6498
6499 /* Initialize security parameters */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306500 status = wlan_hdd_cfg80211_set_privacy_ibss(pAdapter, params);
Jeff Johnson295189b2012-06-20 16:38:30 -07006501 if (status < 0)
6502 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306503 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set security parameters",
Jeff Johnson295189b2012-06-20 16:38:30 -07006504 __func__);
6505 return status;
6506 }
6507
6508 /* Issue connect start */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306509 status = wlan_hdd_cfg80211_connect_start(pAdapter, params->ssid,
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006510 params->ssid_len, params->bssid,
6511 pHddStaCtx->conn_info.operationChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07006512
6513 if (0 > status)
6514 {
6515 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: connect failed", __func__);
6516 return status;
6517 }
6518
6519 return 0;
6520}
6521
6522/*
6523 * FUNCTION: wlan_hdd_cfg80211_leave_ibss
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306524 * This function is used to leave an IBSS
Jeff Johnson295189b2012-06-20 16:38:30 -07006525 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306526static int wlan_hdd_cfg80211_leave_ibss( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07006527 struct net_device *dev
6528 )
6529{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306530 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Jeff Johnson295189b2012-06-20 16:38:30 -07006531 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
6532 tCsrRoamProfile *pRoamProfile;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306533 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
6534 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006535
6536 ENTER();
6537
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306538 status = wlan_hdd_validate_context(pHddCtx);
6539
6540 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006541 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306542 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6543 "%s: HDD context is not valid", __func__);
6544 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006545 }
6546
Jeff Johnson295189b2012-06-20 16:38:30 -07006547 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",__func__,pAdapter->device_mode);
6548 if (NULL == pWextState)
6549 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306550 hddLog (VOS_TRACE_LEVEL_ERROR, "%s ERROR: Data Storage Corruption\n",
Jeff Johnson295189b2012-06-20 16:38:30 -07006551 __func__);
6552 return -EIO;
6553 }
6554
6555 pRoamProfile = &pWextState->roamProfile;
6556
6557 /* Issue disconnect only if interface type is set to IBSS */
6558 if (eCSR_BSS_TYPE_START_IBSS != pRoamProfile->BSSType)
6559 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306560 hddLog (VOS_TRACE_LEVEL_ERROR, "%s: BSS Type is not set to IBSS",
Jeff Johnson295189b2012-06-20 16:38:30 -07006561 __func__);
6562 return -EINVAL;
6563 }
6564
6565 /* Issue Disconnect request */
6566 INIT_COMPLETION(pAdapter->disconnect_comp_var);
6567 sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter), pAdapter->sessionId,
6568 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
6569
6570 return 0;
6571}
6572
6573/*
6574 * FUNCTION: wlan_hdd_cfg80211_set_wiphy_params
6575 * This function is used to set the phy parameters
6576 * (RTS Threshold/FRAG Threshold/Retry Count etc ...)
6577 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306578static int wlan_hdd_cfg80211_set_wiphy_params(struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07006579 u32 changed)
6580{
6581 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
6582 tHalHandle hHal = pHddCtx->hHal;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306583 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006584
6585 ENTER();
6586
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306587 status = wlan_hdd_validate_context(pHddCtx);
6588
6589 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006590 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306591 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6592 "%s: HDD context is not valid", __func__);
6593 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006594 }
6595
Jeff Johnson295189b2012-06-20 16:38:30 -07006596 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
6597 {
6598 u16 rts_threshold = (wiphy->rts_threshold == -1) ?
6599 WNI_CFG_RTS_THRESHOLD_STAMAX :
6600 wiphy->rts_threshold;
6601
6602 if ((WNI_CFG_RTS_THRESHOLD_STAMIN > rts_threshold) ||
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306603 (WNI_CFG_RTS_THRESHOLD_STAMAX < rts_threshold))
Jeff Johnson295189b2012-06-20 16:38:30 -07006604 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306605 hddLog(VOS_TRACE_LEVEL_ERROR,
6606 "%s: Invalid RTS Threshold value %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006607 __func__, rts_threshold);
6608 return -EINVAL;
6609 }
6610
6611 if (0 != ccmCfgSetInt(hHal, WNI_CFG_RTS_THRESHOLD,
6612 rts_threshold, ccmCfgSetCallback,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306613 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07006614 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306615 hddLog(VOS_TRACE_LEVEL_ERROR,
6616 "%s: ccmCfgSetInt failed for rts_threshold value %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006617 __func__, rts_threshold);
6618 return -EIO;
6619 }
6620
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306621 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set rts threshold %hu", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07006622 rts_threshold);
6623 }
6624
6625 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
6626 {
6627 u16 frag_threshold = (wiphy->frag_threshold == -1) ?
6628 WNI_CFG_FRAGMENTATION_THRESHOLD_STAMAX :
6629 wiphy->frag_threshold;
6630
6631 if ((WNI_CFG_FRAGMENTATION_THRESHOLD_STAMIN > frag_threshold)||
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306632 (WNI_CFG_FRAGMENTATION_THRESHOLD_STAMAX < frag_threshold) )
Jeff Johnson295189b2012-06-20 16:38:30 -07006633 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306634 hddLog(VOS_TRACE_LEVEL_ERROR,
6635 "%s: Invalid frag_threshold value %hu", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07006636 frag_threshold);
6637 return -EINVAL;
6638 }
6639
6640 if (0 != ccmCfgSetInt(hHal, WNI_CFG_FRAGMENTATION_THRESHOLD,
6641 frag_threshold, ccmCfgSetCallback,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306642 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07006643 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306644 hddLog(VOS_TRACE_LEVEL_ERROR,
6645 "%s: ccmCfgSetInt failed for frag_threshold value %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006646 __func__, frag_threshold);
6647 return -EIO;
6648 }
6649
6650 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set frag threshold %hu", __func__,
6651 frag_threshold);
6652 }
6653
6654 if ((changed & WIPHY_PARAM_RETRY_SHORT)
6655 || (changed & WIPHY_PARAM_RETRY_LONG))
6656 {
6657 u8 retry_value = (changed & WIPHY_PARAM_RETRY_SHORT) ?
6658 wiphy->retry_short :
6659 wiphy->retry_long;
6660
6661 if ((WNI_CFG_LONG_RETRY_LIMIT_STAMIN > retry_value) ||
6662 (WNI_CFG_LONG_RETRY_LIMIT_STAMAX < retry_value))
6663 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306664 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006665 __func__, retry_value);
6666 return -EINVAL;
6667 }
6668
6669 if (changed & WIPHY_PARAM_RETRY_SHORT)
6670 {
6671 if (0 != ccmCfgSetInt(hHal, WNI_CFG_LONG_RETRY_LIMIT,
6672 retry_value, ccmCfgSetCallback,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306673 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07006674 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306675 hddLog(VOS_TRACE_LEVEL_ERROR,
6676 "%s: ccmCfgSetInt failed for long retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006677 __func__, retry_value);
6678 return -EIO;
6679 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306680 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set long retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006681 __func__, retry_value);
6682 }
6683 else if (changed & WIPHY_PARAM_RETRY_SHORT)
6684 {
6685 if (0 != ccmCfgSetInt(hHal, WNI_CFG_SHORT_RETRY_LIMIT,
6686 retry_value, ccmCfgSetCallback,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306687 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07006688 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306689 hddLog(VOS_TRACE_LEVEL_ERROR,
6690 "%s: ccmCfgSetInt failed for short retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006691 __func__, retry_value);
6692 return -EIO;
6693 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306694 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set short retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006695 __func__, retry_value);
6696 }
6697 }
6698
6699 return 0;
6700}
6701
6702/*
6703 * FUNCTION: wlan_hdd_cfg80211_set_txpower
6704 * This function is used to set the txpower
6705 */
6706static int wlan_hdd_cfg80211_set_txpower(struct wiphy *wiphy,
Yue Maf49ba872013-08-19 12:04:25 -07006707#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0)
6708 struct wireless_dev *wdev,
6709#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006710#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,35)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306711 enum tx_power_setting type,
Jeff Johnson295189b2012-06-20 16:38:30 -07006712#else
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306713 enum nl80211_tx_power_setting type,
Jeff Johnson295189b2012-06-20 16:38:30 -07006714#endif
6715 int dbm)
6716{
6717 hdd_context_t *pHddCtx = (hdd_context_t*) wiphy_priv(wiphy);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306718 tHalHandle hHal = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07006719 tSirMacAddr bssid = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
6720 tSirMacAddr selfMac = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306721 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006722
6723 ENTER();
6724
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306725 status = wlan_hdd_validate_context(pHddCtx);
6726
6727 if (0 != status)
6728 {
6729 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6730 "%s: HDD context is not valid", __func__);
6731 return status;
6732 }
6733
6734 hHal = pHddCtx->hHal;
6735
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306736 if (0 != ccmCfgSetInt(hHal, WNI_CFG_CURRENT_TX_POWER_LEVEL,
6737 dbm, ccmCfgSetCallback,
6738 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07006739 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306740 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07006741 "%s: ccmCfgSetInt failed for tx power %hu", __func__, dbm);
6742 return -EIO;
6743 }
6744
6745 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set tx power level %d dbm", __func__,
6746 dbm);
6747
6748 switch(type)
6749 {
6750 case NL80211_TX_POWER_AUTOMATIC: /*automatically determine transmit power*/
6751 /* Fall through */
6752 case NL80211_TX_POWER_LIMITED: /*limit TX power by the mBm parameter*/
6753 if( sme_SetMaxTxPower(hHal, bssid, selfMac, dbm) != eHAL_STATUS_SUCCESS )
6754 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306755 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Setting maximum tx power failed",
6756 __func__);
6757 return -EIO;
Jeff Johnson295189b2012-06-20 16:38:30 -07006758 }
6759 break;
6760 case NL80211_TX_POWER_FIXED: /*fix TX power to the mBm parameter*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306761 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: NL80211_TX_POWER_FIXED not supported",
Jeff Johnson295189b2012-06-20 16:38:30 -07006762 __func__);
6763 return -EOPNOTSUPP;
6764 break;
6765 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306766 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid power setting type %d",
6767 __func__, type);
Jeff Johnson295189b2012-06-20 16:38:30 -07006768 return -EIO;
6769 }
6770
6771 return 0;
6772}
6773
6774/*
6775 * FUNCTION: wlan_hdd_cfg80211_get_txpower
6776 * This function is used to read the txpower
6777 */
Yue Maf49ba872013-08-19 12:04:25 -07006778static int wlan_hdd_cfg80211_get_txpower(struct wiphy *wiphy,
6779#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0)
6780 struct wireless_dev *wdev,
6781#endif
6782 int *dbm)
Jeff Johnson295189b2012-06-20 16:38:30 -07006783{
6784
6785 hdd_adapter_t *pAdapter;
6786 hdd_context_t *pHddCtx = (hdd_context_t*) wiphy_priv(wiphy);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306787 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006788
Jeff Johnsone7245742012-09-05 17:12:55 -07006789 ENTER();
6790
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306791 status = wlan_hdd_validate_context(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07006792
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306793 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006794 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306795 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6796 "%s: HDD context is not valid", __func__);
6797 *dbm = 0;
6798 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006799 }
6800
Jeff Johnson295189b2012-06-20 16:38:30 -07006801 pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_INFRA_STATION);
6802 if (NULL == pAdapter)
6803 {
6804 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Not in station context " ,__func__);
6805 return -ENOENT;
6806 }
6807
6808 wlan_hdd_get_classAstats(pAdapter);
6809 *dbm = pAdapter->hdd_stats.ClassA_stat.max_pwr;
6810
Jeff Johnsone7245742012-09-05 17:12:55 -07006811 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07006812 return 0;
6813}
6814
6815static int wlan_hdd_cfg80211_get_station(struct wiphy *wiphy, struct net_device *dev,
6816 u8* mac, struct station_info *sinfo)
6817{
6818 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
6819 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
6820 int ssidlen = pHddStaCtx->conn_info.SSID.SSID.length;
6821 tANI_U8 rate_flags;
6822
6823 hdd_context_t *pHddCtx = (hdd_context_t*) wiphy_priv(wiphy);
6824 hdd_config_t *pCfg = pHddCtx->cfg_ini;
Jeff Johnson295189b2012-06-20 16:38:30 -07006825
6826 tANI_U8 OperationalRates[CSR_DOT11_SUPPORTED_RATES_MAX];
6827 tANI_U32 ORLeng = CSR_DOT11_SUPPORTED_RATES_MAX;
6828 tANI_U8 ExtendedRates[CSR_DOT11_EXTENDED_SUPPORTED_RATES_MAX];
6829 tANI_U32 ERLeng = CSR_DOT11_EXTENDED_SUPPORTED_RATES_MAX;
6830 tANI_U8 MCSRates[SIZE_OF_BASIC_MCS_SET];
6831 tANI_U32 MCSLeng = SIZE_OF_BASIC_MCS_SET;
6832 tANI_U16 maxRate = 0;
6833 tANI_U16 myRate;
6834 tANI_U16 currentRate = 0;
6835 tANI_U8 maxSpeedMCS = 0;
6836 tANI_U8 maxMCSIdx = 0;
6837 tANI_U8 rateFlag = 1;
6838 tANI_U8 i, j, rssidx;
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07006839 tANI_U16 temp;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306840 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006841
Leo Chang6f8870f2013-03-26 18:11:36 -07006842#ifdef WLAN_FEATURE_11AC
6843 tANI_U32 vht_mcs_map;
6844 eDataRate11ACMaxMcs vhtMaxMcs;
6845#endif /* WLAN_FEATURE_11AC */
6846
Jeff Johnsone7245742012-09-05 17:12:55 -07006847 ENTER();
6848
Jeff Johnson295189b2012-06-20 16:38:30 -07006849 if ((eConnectionState_Associated != pHddStaCtx->conn_info.connState) ||
6850 (0 == ssidlen))
6851 {
6852 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Not associated or"
6853 " Invalid ssidlen, %d", __func__, ssidlen);
6854 /*To keep GUI happy*/
6855 return 0;
6856 }
6857
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306858 status = wlan_hdd_validate_context(pHddCtx);
6859
6860 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006861 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306862 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6863 "%s: HDD context is not valid", __func__);
6864 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006865 }
6866
Jeff Johnson295189b2012-06-20 16:38:30 -07006867 wlan_hdd_get_rssi(pAdapter, &sinfo->signal);
6868 sinfo->filled |= STATION_INFO_SIGNAL;
6869
Madan Mohan Koyyalamudi4d4d2812012-09-24 14:08:29 -07006870 wlan_hdd_get_station_stats(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07006871 rate_flags = pAdapter->hdd_stats.ClassA_stat.tx_rate_flags;
6872
6873 //convert to the UI units of 100kbps
6874 myRate = pAdapter->hdd_stats.ClassA_stat.tx_rate * 5;
6875
6876#ifdef LINKSPEED_DEBUG_ENABLED
Leo Chang6f8870f2013-03-26 18:11:36 -07006877 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 -07006878 sinfo->signal,
6879 pCfg->reportMaxLinkSpeed,
6880 myRate,
6881 (int) pCfg->linkSpeedRssiHigh,
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07006882 (int) pCfg->linkSpeedRssiMid,
6883 (int) pCfg->linkSpeedRssiLow,
Leo Chang6f8870f2013-03-26 18:11:36 -07006884 (int) rate_flags,
6885 (int) pAdapter->hdd_stats.ClassA_stat.mcs_index);
Jeff Johnson295189b2012-06-20 16:38:30 -07006886#endif //LINKSPEED_DEBUG_ENABLED
6887
6888 if (eHDD_LINK_SPEED_REPORT_ACTUAL != pCfg->reportMaxLinkSpeed)
6889 {
6890 // we do not want to necessarily report the current speed
6891 if (eHDD_LINK_SPEED_REPORT_MAX == pCfg->reportMaxLinkSpeed)
6892 {
6893 // report the max possible speed
6894 rssidx = 0;
6895 }
6896 else if (eHDD_LINK_SPEED_REPORT_MAX_SCALED == pCfg->reportMaxLinkSpeed)
6897 {
6898 // report the max possible speed with RSSI scaling
6899 if (sinfo->signal >= pCfg->linkSpeedRssiHigh)
6900 {
6901 // report the max possible speed
6902 rssidx = 0;
6903 }
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07006904 else if (sinfo->signal >= pCfg->linkSpeedRssiMid)
Jeff Johnson295189b2012-06-20 16:38:30 -07006905 {
6906 // report middle speed
6907 rssidx = 1;
6908 }
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07006909 else if (sinfo->signal >= pCfg->linkSpeedRssiLow)
6910 {
6911 // report middle speed
6912 rssidx = 2;
6913 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006914 else
6915 {
6916 // report actual speed
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07006917 rssidx = 3;
Jeff Johnson295189b2012-06-20 16:38:30 -07006918 }
6919 }
6920 else
6921 {
6922 // unknown, treat as eHDD_LINK_SPEED_REPORT_MAX
6923 hddLog(VOS_TRACE_LEVEL_ERROR,
6924 "%s: Invalid value for reportMaxLinkSpeed: %u",
6925 __func__, pCfg->reportMaxLinkSpeed);
6926 rssidx = 0;
6927 }
6928
6929 maxRate = 0;
6930
6931 /* Get Basic Rate Set */
Gopichand Nakkala05ab1322013-02-15 11:28:38 +05306932 if (0 != ccmCfgGetStr(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_OPERATIONAL_RATE_SET,
6933 OperationalRates, &ORLeng))
6934 {
6935 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: ccm api returned failure", __func__);
6936 /*To keep GUI happy*/
6937 return 0;
6938 }
6939
Jeff Johnson295189b2012-06-20 16:38:30 -07006940 for (i = 0; i < ORLeng; i++)
6941 {
Jeff Johnsone7245742012-09-05 17:12:55 -07006942 for (j = 0; j < (sizeof(supported_data_rate) / sizeof(supported_data_rate[0])); j ++)
Jeff Johnson295189b2012-06-20 16:38:30 -07006943 {
6944 /* Validate Rate Set */
6945 if (supported_data_rate[j].beacon_rate_index == (OperationalRates[i] & 0x7F))
6946 {
6947 currentRate = supported_data_rate[j].supported_rate[rssidx];
6948 break;
6949 }
6950 }
6951 /* Update MAX rate */
6952 maxRate = (currentRate > maxRate)?currentRate:maxRate;
6953 }
6954
6955 /* Get Extended Rate Set */
Gopichand Nakkala05ab1322013-02-15 11:28:38 +05306956 if (0 != ccmCfgGetStr(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_EXTENDED_OPERATIONAL_RATE_SET,
6957 ExtendedRates, &ERLeng))
6958 {
6959 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: ccm api returned failure", __func__);
6960 /*To keep GUI happy*/
6961 return 0;
6962 }
6963
Jeff Johnson295189b2012-06-20 16:38:30 -07006964 for (i = 0; i < ERLeng; i++)
6965 {
Jeff Johnsone7245742012-09-05 17:12:55 -07006966 for (j = 0; j < (sizeof(supported_data_rate) / sizeof(supported_data_rate[0])); j ++)
Jeff Johnson295189b2012-06-20 16:38:30 -07006967 {
6968 if (supported_data_rate[j].beacon_rate_index == (ExtendedRates[i] & 0x7F))
6969 {
6970 currentRate = supported_data_rate[j].supported_rate[rssidx];
6971 break;
6972 }
6973 }
6974 /* Update MAX rate */
6975 maxRate = (currentRate > maxRate)?currentRate:maxRate;
6976 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006977 /* Get MCS Rate Set -- but only if we are connected at MCS
6978 rates or if we are always reporting max speed or if we have
6979 good rssi */
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07006980 if ((0 == rssidx) && !(rate_flags & eHAL_TX_RATE_LEGACY))
Jeff Johnson295189b2012-06-20 16:38:30 -07006981 {
Gopichand Nakkala05ab1322013-02-15 11:28:38 +05306982 if (0 != ccmCfgGetStr(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_CURRENT_MCS_SET,
6983 MCSRates, &MCSLeng))
6984 {
6985 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: ccm api returned failure", __func__);
6986 /*To keep GUI happy*/
6987 return 0;
6988 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006989 rateFlag = 0;
Leo Chang6f8870f2013-03-26 18:11:36 -07006990#ifdef WLAN_FEATURE_11AC
6991 /* VHT80 rate has seperate rate table */
Gopichand Nakkala4c705372013-04-24 13:20:33 +05306992 if (rate_flags & (eHAL_TX_RATE_VHT20|eHAL_TX_RATE_VHT40|eHAL_TX_RATE_VHT80))
Jeff Johnson295189b2012-06-20 16:38:30 -07006993 {
Leo Chang6f8870f2013-03-26 18:11:36 -07006994 ccmCfgGetInt(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_VHT_TX_MCS_MAP, &vht_mcs_map);
Gopichand Nakkala4c705372013-04-24 13:20:33 +05306995 vhtMaxMcs = (eDataRate11ACMaxMcs)(vht_mcs_map & DATA_RATE_11AC_MCS_MASK );
Leo Chang6f8870f2013-03-26 18:11:36 -07006996 if (rate_flags & eHAL_TX_RATE_SGI)
Jeff Johnson295189b2012-06-20 16:38:30 -07006997 {
Leo Chang6f8870f2013-03-26 18:11:36 -07006998 rateFlag |= 1;
Jeff Johnson295189b2012-06-20 16:38:30 -07006999 }
Leo Chang6f8870f2013-03-26 18:11:36 -07007000 if (DATA_RATE_11AC_MAX_MCS_7 == vhtMaxMcs)
Jeff Johnson295189b2012-06-20 16:38:30 -07007001 {
Leo Chang6f8870f2013-03-26 18:11:36 -07007002 maxMCSIdx = 7;
7003 }
7004 else if (DATA_RATE_11AC_MAX_MCS_8 == vhtMaxMcs)
7005 {
7006 maxMCSIdx = 8;
7007 }
7008 else if (DATA_RATE_11AC_MAX_MCS_9 == vhtMaxMcs)
7009 {
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307010 //VHT20 is supporting 0~8
7011 if (rate_flags & eHAL_TX_RATE_VHT20)
7012 maxMCSIdx = 8;
7013 else
7014 maxMCSIdx = 9;
Leo Chang6f8870f2013-03-26 18:11:36 -07007015 }
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307016
7017 if (rate_flags & eHAL_TX_RATE_VHT80)
7018 {
7019 currentRate = supported_vht_mcs_rate[pAdapter->hdd_stats.ClassA_stat.mcs_index].supported_VHT80_rate[rateFlag];
7020 maxRate = supported_vht_mcs_rate[maxMCSIdx].supported_VHT80_rate[rateFlag];
7021 }
7022 else if (rate_flags & eHAL_TX_RATE_VHT40)
7023 {
7024 currentRate = supported_vht_mcs_rate[pAdapter->hdd_stats.ClassA_stat.mcs_index].supported_VHT40_rate[rateFlag];
7025 maxRate = supported_vht_mcs_rate[maxMCSIdx].supported_VHT40_rate[rateFlag];
7026 }
7027 else if (rate_flags & eHAL_TX_RATE_VHT20)
7028 {
7029 currentRate = supported_vht_mcs_rate[pAdapter->hdd_stats.ClassA_stat.mcs_index].supported_VHT20_rate[rateFlag];
7030 maxRate = supported_vht_mcs_rate[maxMCSIdx].supported_VHT20_rate[rateFlag];
7031 }
7032
Leo Chang6f8870f2013-03-26 18:11:36 -07007033 maxSpeedMCS = 1;
7034 if (currentRate > maxRate)
7035 {
7036 maxRate = currentRate;
7037 }
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307038
Leo Chang6f8870f2013-03-26 18:11:36 -07007039 }
7040 else
7041#endif /* WLAN_FEATURE_11AC */
7042 {
7043 if (rate_flags & eHAL_TX_RATE_HT40)
7044 {
7045 rateFlag |= 1;
7046 }
7047 if (rate_flags & eHAL_TX_RATE_SGI)
7048 {
7049 rateFlag |= 2;
7050 }
7051
7052 for (i = 0; i < MCSLeng; i++)
7053 {
7054 temp = sizeof(supported_mcs_rate) / sizeof(supported_mcs_rate[0]);
7055 for (j = 0; j < temp; j++)
7056 {
7057 if (supported_mcs_rate[j].beacon_rate_index == MCSRates[i])
7058 {
7059 currentRate = supported_mcs_rate[j].supported_rate[rateFlag];
7060 break;
7061 }
7062 }
7063 if ((j < temp) && (currentRate > maxRate))
7064 {
7065 maxRate = currentRate;
7066 maxSpeedMCS = 1;
7067 maxMCSIdx = supported_mcs_rate[j].beacon_rate_index;
7068 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007069 }
7070 }
7071 }
7072
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307073 else if (!(rate_flags & eHAL_TX_RATE_LEGACY))
7074 {
7075 maxRate = myRate;
7076 maxSpeedMCS = 1;
7077 maxMCSIdx = pAdapter->hdd_stats.ClassA_stat.mcs_index;
7078 }
7079
Jeff Johnson295189b2012-06-20 16:38:30 -07007080 // make sure we report a value at least as big as our current rate
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07007081 if (((maxRate < myRate) && (0 == rssidx)) ||
7082 (0 == maxRate))
Jeff Johnson295189b2012-06-20 16:38:30 -07007083 {
7084 maxRate = myRate;
7085 if (rate_flags & eHAL_TX_RATE_LEGACY)
7086 {
7087 maxSpeedMCS = 0;
7088 }
7089 else
7090 {
7091 maxSpeedMCS = 1;
7092 maxMCSIdx = pAdapter->hdd_stats.ClassA_stat.mcs_index;
7093 }
7094 }
7095
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307096 if (rate_flags & eHAL_TX_RATE_LEGACY)
Jeff Johnson295189b2012-06-20 16:38:30 -07007097 {
7098 sinfo->txrate.legacy = maxRate;
7099#ifdef LINKSPEED_DEBUG_ENABLED
7100 pr_info("Reporting legacy rate %d\n", sinfo->txrate.legacy);
7101#endif //LINKSPEED_DEBUG_ENABLED
7102 }
7103 else
7104 {
7105 sinfo->txrate.mcs = maxMCSIdx;
Leo Chang6f8870f2013-03-26 18:11:36 -07007106#ifdef WLAN_FEATURE_11AC
7107 sinfo->txrate.nss = 1;
7108 if (rate_flags & eHAL_TX_RATE_VHT80)
7109 {
7110 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307111 sinfo->txrate.flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
Leo Chang6f8870f2013-03-26 18:11:36 -07007112 }
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307113 else if (rate_flags & eHAL_TX_RATE_VHT40)
Leo Chang6f8870f2013-03-26 18:11:36 -07007114 {
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307115 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
7116 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
7117 }
7118 else if (rate_flags & eHAL_TX_RATE_VHT20)
7119 {
7120 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
7121 }
7122#endif /* WLAN_FEATURE_11AC */
7123 if (rate_flags & (eHAL_TX_RATE_HT20 | eHAL_TX_RATE_HT40))
7124 {
7125 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
7126 if (rate_flags & eHAL_TX_RATE_HT40)
7127 {
7128 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
7129 }
Leo Chang6f8870f2013-03-26 18:11:36 -07007130 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007131 if (rate_flags & eHAL_TX_RATE_SGI)
7132 {
7133 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
7134 }
Gopichand Nakkala4c705372013-04-24 13:20:33 +05307135
Jeff Johnson295189b2012-06-20 16:38:30 -07007136#ifdef LINKSPEED_DEBUG_ENABLED
7137 pr_info("Reporting MCS rate %d flags %x\n",
7138 sinfo->txrate.mcs,
7139 sinfo->txrate.flags );
7140#endif //LINKSPEED_DEBUG_ENABLED
7141 }
7142 }
7143 else
7144 {
7145 // report current rate instead of max rate
7146
7147 if (rate_flags & eHAL_TX_RATE_LEGACY)
7148 {
7149 //provide to the UI in units of 100kbps
7150 sinfo->txrate.legacy = myRate;
7151#ifdef LINKSPEED_DEBUG_ENABLED
7152 pr_info("Reporting actual legacy rate %d\n", sinfo->txrate.legacy);
7153#endif //LINKSPEED_DEBUG_ENABLED
7154 }
7155 else
7156 {
7157 //must be MCS
7158 sinfo->txrate.mcs = pAdapter->hdd_stats.ClassA_stat.mcs_index;
Leo Chang6f8870f2013-03-26 18:11:36 -07007159#ifdef WLAN_FEATURE_11AC
7160 sinfo->txrate.nss = 1;
7161 if (rate_flags & eHAL_TX_RATE_VHT80)
7162 {
7163 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
7164 }
7165 else
7166#endif /* WLAN_FEATURE_11AC */
7167 {
7168 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
7169 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007170 if (rate_flags & eHAL_TX_RATE_SGI)
7171 {
7172 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
7173 }
7174 if (rate_flags & eHAL_TX_RATE_HT40)
7175 {
7176 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
7177 }
Leo Chang6f8870f2013-03-26 18:11:36 -07007178#ifdef WLAN_FEATURE_11AC
7179 else if (rate_flags & eHAL_TX_RATE_VHT80)
7180 {
7181 sinfo->txrate.flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
7182 }
7183#endif /* WLAN_FEATURE_11AC */
Jeff Johnson295189b2012-06-20 16:38:30 -07007184#ifdef LINKSPEED_DEBUG_ENABLED
7185 pr_info("Reporting actual MCS rate %d flags %x\n",
7186 sinfo->txrate.mcs,
7187 sinfo->txrate.flags );
7188#endif //LINKSPEED_DEBUG_ENABLED
7189 }
7190 }
7191 sinfo->filled |= STATION_INFO_TX_BITRATE;
7192
Madan Mohan Koyyalamudi4d4d2812012-09-24 14:08:29 -07007193 sinfo->tx_packets =
7194 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[0] +
7195 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[1] +
7196 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[2] +
7197 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[3];
7198
7199 sinfo->tx_retries =
7200 pAdapter->hdd_stats.summary_stat.retry_cnt[0] +
7201 pAdapter->hdd_stats.summary_stat.retry_cnt[1] +
7202 pAdapter->hdd_stats.summary_stat.retry_cnt[2] +
7203 pAdapter->hdd_stats.summary_stat.retry_cnt[3];
7204
7205 sinfo->tx_failed =
7206 pAdapter->hdd_stats.summary_stat.fail_cnt[0] +
7207 pAdapter->hdd_stats.summary_stat.fail_cnt[1] +
7208 pAdapter->hdd_stats.summary_stat.fail_cnt[2] +
7209 pAdapter->hdd_stats.summary_stat.fail_cnt[3];
7210
7211 sinfo->filled |=
7212 STATION_INFO_TX_PACKETS |
7213 STATION_INFO_TX_RETRIES |
7214 STATION_INFO_TX_FAILED;
7215
7216 EXIT();
7217 return 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07007218}
7219
7220static int wlan_hdd_cfg80211_set_power_mgmt(struct wiphy *wiphy,
Sameer Thalappilc9f26e92013-06-07 10:11:06 -07007221 struct net_device *dev, bool mode, int timeout)
Jeff Johnson295189b2012-06-20 16:38:30 -07007222{
7223 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05307224 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07007225 VOS_STATUS vos_status;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307226 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007227
Jeff Johnsone7245742012-09-05 17:12:55 -07007228 ENTER();
7229
Jeff Johnson295189b2012-06-20 16:38:30 -07007230 if (NULL == pAdapter)
7231 {
7232 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Adapter is NULL\n", __func__);
7233 return -ENODEV;
7234 }
7235
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05307236 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307237 status = wlan_hdd_validate_context(pHddCtx);
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05307238
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307239 if (0 != status)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307240 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307241 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7242 "%s: HDD context is not valid", __func__);
7243 return status;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307244 }
7245
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05307246 if ((DRIVER_POWER_MODE_AUTO == !mode) &&
7247 (TRUE == pHddCtx->hdd_wlan_suspended) &&
7248 (pHddCtx->cfg_ini->fhostArpOffload) &&
7249 (eConnectionState_Associated ==
7250 (WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))->conn_info.connState))
7251 {
Amar Singhald53568e2013-09-26 11:03:45 -07007252
7253 hddLog(VOS_TRACE_LEVEL_INFO,
7254 "offload: in cfg80211_set_power_mgmt, calling arp offload");
Gopichand Nakkalab03e8082013-05-30 18:09:25 +05307255 vos_status = hdd_conf_arp_offload(pAdapter, TRUE);
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05307256 if (!VOS_IS_STATUS_SUCCESS(vos_status))
7257 {
7258 hddLog(VOS_TRACE_LEVEL_INFO,
7259 "%s:Failed to enable ARPOFFLOAD Feature %d\n",
7260 __func__, vos_status);
7261 }
7262 }
7263
Jeff Johnson295189b2012-06-20 16:38:30 -07007264 /**The get power cmd from the supplicant gets updated by the nl only
7265 *on successful execution of the function call
7266 *we are oppositely mapped w.r.t mode in the driver
7267 **/
7268 vos_status = wlan_hdd_enter_bmps(pAdapter, !mode);
7269
Jeff Johnsone7245742012-09-05 17:12:55 -07007270 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07007271 if (VOS_STATUS_E_FAILURE == vos_status)
7272 {
7273 return -EINVAL;
7274 }
7275 return 0;
7276}
7277
7278
7279#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
7280static int wlan_hdd_set_default_mgmt_key(struct wiphy *wiphy,
7281 struct net_device *netdev,
7282 u8 key_index)
7283{
Jeff Johnsone7245742012-09-05 17:12:55 -07007284 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07007285 return 0;
7286}
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307287#endif //LINUX_VERSION_CODE
Jeff Johnson295189b2012-06-20 16:38:30 -07007288
7289#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
7290static int wlan_hdd_set_txq_params(struct wiphy *wiphy,
7291 struct net_device *dev,
7292 struct ieee80211_txq_params *params)
7293{
Jeff Johnsone7245742012-09-05 17:12:55 -07007294 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07007295 return 0;
7296}
7297#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
7298static int wlan_hdd_set_txq_params(struct wiphy *wiphy,
7299 struct ieee80211_txq_params *params)
7300{
Jeff Johnsone7245742012-09-05 17:12:55 -07007301 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07007302 return 0;
7303}
7304#endif //LINUX_VERSION_CODE
7305
7306static int wlan_hdd_cfg80211_del_station(struct wiphy *wiphy,
7307 struct net_device *dev, u8 *mac)
7308{
7309 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307310 hdd_context_t *pHddCtx;
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007311 VOS_STATUS vos_status;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307312 int status;
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007313 v_U8_t staId;
Jeff Johnson295189b2012-06-20 16:38:30 -07007314
Jeff Johnsone7245742012-09-05 17:12:55 -07007315 ENTER();
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307316 if ( NULL == pAdapter )
Jeff Johnson295189b2012-06-20 16:38:30 -07007317 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307318 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Adapter" ,__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07007319 return -EINVAL;
7320 }
7321
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307322 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7323 status = wlan_hdd_validate_context(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07007324
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307325 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007326 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307327 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7328 "%s: HDD context is not valid", __func__);
7329 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007330 }
7331
Jeff Johnson295189b2012-06-20 16:38:30 -07007332 if ( (WLAN_HDD_SOFTAP == pAdapter->device_mode)
Jeff Johnson295189b2012-06-20 16:38:30 -07007333 || (WLAN_HDD_P2P_GO == pAdapter->device_mode)
Jeff Johnson295189b2012-06-20 16:38:30 -07007334 )
7335 {
7336 if( NULL == mac )
7337 {
7338 v_U16_t i;
7339 for(i = 0; i < WLAN_MAX_STA_COUNT; i++)
7340 {
Rajesh Chauhan18488fc2013-08-22 10:15:03 -07007341 if ((pAdapter->aStaInfo[i].isUsed) &&
7342 (!pAdapter->aStaInfo[i].isDeauthInProgress))
Jeff Johnson295189b2012-06-20 16:38:30 -07007343 {
7344 u8 *macAddr = pAdapter->aStaInfo[i].macAddrSTA.bytes;
7345 hddLog(VOS_TRACE_LEVEL_INFO,
7346 "%s: Delete STA with MAC::"
7347 "%02x:%02x:%02x:%02x:%02x:%02x",
7348 __func__,
7349 macAddr[0], macAddr[1], macAddr[2],
7350 macAddr[3], macAddr[4], macAddr[5]);
Rajesh Chauhan18488fc2013-08-22 10:15:03 -07007351 vos_status = hdd_softap_sta_deauth(pAdapter, macAddr);
7352 if (VOS_IS_STATUS_SUCCESS(vos_status))
7353 pAdapter->aStaInfo[i].isDeauthInProgress = TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07007354 }
7355 }
7356 }
7357 else
7358 {
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007359
7360 vos_status = hdd_softap_GetStaId(pAdapter,(v_MACADDR_t *)mac, &staId);
7361 if (!VOS_IS_STATUS_SUCCESS(vos_status))
7362 {
7363 hddLog(VOS_TRACE_LEVEL_INFO,
7364 "%s: Skip this DEL STA as this is not used::"
7365 "%02x:%02x:%02x:%02x:%02x:%02x",
7366 __func__,
7367 mac[0], mac[1], mac[2],
7368 mac[3], mac[4], mac[5]);
7369 return -ENOENT;
7370 }
7371
7372 if( pAdapter->aStaInfo[staId].isDeauthInProgress == TRUE)
7373 {
7374 hddLog(VOS_TRACE_LEVEL_INFO,
7375 "%s: Skip this DEL STA as deauth is in progress::"
7376 "%02x:%02x:%02x:%02x:%02x:%02x",
7377 __func__,
7378 mac[0], mac[1], mac[2],
7379 mac[3], mac[4], mac[5]);
7380 return -ENOENT;
7381 }
7382
7383 pAdapter->aStaInfo[staId].isDeauthInProgress = TRUE;
7384
Jeff Johnson295189b2012-06-20 16:38:30 -07007385 hddLog(VOS_TRACE_LEVEL_INFO,
7386 "%s: Delete STA with MAC::"
7387 "%02x:%02x:%02x:%02x:%02x:%02x",
7388 __func__,
7389 mac[0], mac[1], mac[2],
7390 mac[3], mac[4], mac[5]);
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007391
7392 vos_status = hdd_softap_sta_deauth(pAdapter, mac);
7393 if (!VOS_IS_STATUS_SUCCESS(vos_status))
7394 {
7395 pAdapter->aStaInfo[staId].isDeauthInProgress = FALSE;
7396 hddLog(VOS_TRACE_LEVEL_INFO,
7397 "%s: STA removal failed for ::"
7398 "%02x:%02x:%02x:%02x:%02x:%02x",
7399 __func__,
7400 mac[0], mac[1], mac[2],
7401 mac[3], mac[4], mac[5]);
7402 return -ENOENT;
7403 }
7404
Jeff Johnson295189b2012-06-20 16:38:30 -07007405 }
7406 }
7407
7408 EXIT();
7409
7410 return 0;
7411}
7412
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007413static int wlan_hdd_cfg80211_add_station(struct wiphy *wiphy,
7414 struct net_device *dev, u8 *mac, struct station_parameters *params)
7415{
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007416 int status = -EPERM;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007417#ifdef FEATURE_WLAN_TDLS
7418 u32 mask, set;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007419 ENTER();
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007420 mask = params->sta_flags_mask;
7421
7422 set = params->sta_flags_set;
7423
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007424#ifdef WLAN_FEATURE_TDLS_DEBUG
7425 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7426 "%s: mask 0x%x set 0x%x " MAC_ADDRESS_STR,
7427 __func__, mask, set, MAC_ADDR_ARRAY(mac));
7428#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007429
7430 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
7431 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
Gopichand Nakkala681989c2013-03-06 22:27:48 -08007432 status = wlan_hdd_tdls_add_station(wiphy, dev, mac, 0, NULL);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007433 }
7434 }
7435#endif
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007436 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007437}
7438
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007439
7440#ifdef FEATURE_WLAN_LFR
Wilson Yang6507c4e2013-10-01 20:11:19 -07007441#define MAX_PMKSAIDS_IN_CACHE 8
7442
7443static tPmkidCacheInfo PMKIDCache[MAX_PMKSAIDS_IN_CACHE]; // HDD local cache
7444static tANI_U32 PMKIDCacheIndex; // HDD local Cache index
7445
7446
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007447static int wlan_hdd_cfg80211_set_pmksa(struct wiphy *wiphy, struct net_device *dev,
Jeff Johnsond13512a2012-07-17 11:42:19 -07007448 struct cfg80211_pmksa *pmksa)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007449{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307450 tANI_U32 j=0;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007451 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7452 tHalHandle halHandle;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307453 eHalStatus result;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307454 int status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007455 tANI_U8 BSSIDMatched = 0;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307456 hdd_context_t *pHddCtx;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307457
Jeff Johnsone7245742012-09-05 17:12:55 -07007458 ENTER();
7459
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307460 // Validate pAdapter
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307461 if ( NULL == pAdapter )
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007462 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307463 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Adapter" ,__func__);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007464 return -EINVAL;
7465 }
7466
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307467 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7468 status = wlan_hdd_validate_context(pHddCtx);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007469
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307470 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007471 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307472 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7473 "%s: HDD context is not valid", __func__);
7474 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007475 }
7476
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307477 // Retrieve halHandle
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007478 halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
7479
Wilson Yang6507c4e2013-10-01 20:11:19 -07007480 for (j = 0; j < PMKIDCacheIndex; j++)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007481 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307482 if(vos_mem_compare(PMKIDCache[j].BSSID,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007483 pmksa->bssid, WNI_CFG_BSSID_LEN))
7484 {
7485 /* BSSID matched previous entry. Overwrite it. */
7486 BSSIDMatched = 1;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307487 vos_mem_copy(PMKIDCache[j].BSSID,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007488 pmksa->bssid, WNI_CFG_BSSID_LEN);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307489 vos_mem_copy(PMKIDCache[j].PMKID,
7490 pmksa->pmkid,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007491 CSR_RSN_PMKID_SIZE);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307492 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Reusing cache entry %d.",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007493 __func__, j );
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007494 dump_bssid(pmksa->bssid);
7495 dump_pmkid(halHandle, pmksa->pmkid);
7496 break;
7497 }
7498 }
7499
Madan Mohan Koyyalamudic4b317d2012-10-18 19:43:08 -07007500 /* Check we compared all entries,if then take the first slot now */
Wilson Yang6507c4e2013-10-01 20:11:19 -07007501 if(j == MAX_PMKSAIDS_IN_CACHE) PMKIDCacheIndex=0;
Madan Mohan Koyyalamudic4b317d2012-10-18 19:43:08 -07007502
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007503 if (!BSSIDMatched)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307504 {
7505 // Now, we DON'T have a BSSID match, so take a new entry in the cache.
Wilson Yang6507c4e2013-10-01 20:11:19 -07007506 vos_mem_copy(PMKIDCache[PMKIDCacheIndex].BSSID,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307507 pmksa->bssid, ETHER_ADDR_LEN);
Wilson Yang6507c4e2013-10-01 20:11:19 -07007508 vos_mem_copy(PMKIDCache[PMKIDCacheIndex].PMKID,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307509 pmksa->pmkid,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007510 CSR_RSN_PMKID_SIZE);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307511 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Adding a new cache entry %d.",
Wilson Yang6507c4e2013-10-01 20:11:19 -07007512 __func__, PMKIDCacheIndex );
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007513 dump_bssid(pmksa->bssid);
7514 dump_pmkid(halHandle, pmksa->pmkid);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307515 // Increment the HDD Local Cache index
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007516 // The "i=0" doesn't work for the call to sme_RoamSetPMKIDCache() - LFR FIXME
Wilson Yang6507c4e2013-10-01 20:11:19 -07007517 if (PMKIDCacheIndex <= (MAX_PMKSAIDS_IN_CACHE-1)) PMKIDCacheIndex++; else PMKIDCacheIndex = 0;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007518 }
7519
7520
7521 // Calling csrRoamSetPMKIDCache to configure the PMKIDs into the cache
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307522 //hddLog(LOG1, FL("%s: Calling csrRoamSetPMKIDCache with %d cache entries."),
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007523 // __func__, i );
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307524 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Calling csrRoamSetPMKIDCache with %d cache entries.",
Wilson Yang6507c4e2013-10-01 20:11:19 -07007525 __func__, PMKIDCacheIndex );
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007526 // Finally set the PMKSA ID Cache in CSR
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307527 result = sme_RoamSetPMKIDCache(halHandle,pAdapter->sessionId,
7528 PMKIDCache,
Wilson Yang6507c4e2013-10-01 20:11:19 -07007529 PMKIDCacheIndex);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007530 return 0;
7531}
7532
7533
Wilson Yang6507c4e2013-10-01 20:11:19 -07007534
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007535static int wlan_hdd_cfg80211_del_pmksa(struct wiphy *wiphy, struct net_device *dev,
Wilson Yang6507c4e2013-10-01 20:11:19 -07007536 struct cfg80211_pmksa *pmksa)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007537{
Wilson Yang6507c4e2013-10-01 20:11:19 -07007538 tANI_U32 j=0;
7539 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7540 tHalHandle halHandle;
7541 int status;
7542 tANI_U8 BSSIDMatched = 0;
7543 tANI_U8 *pBSSId;
7544 hdd_context_t *pHddCtx;
7545 int result = 0;
7546
7547 hddLog(VOS_TRACE_LEVEL_DEBUG, "%s: deleting PMKSA with PMKSA_ID %d .",
7548 __func__,pmksa->pmkid);
7549
7550 /* Validate pAdapter */
7551 if (NULL == pAdapter)
7552 {
7553 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Adapter" ,__func__);
7554 return -EINVAL;
7555 }
7556
7557 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7558 status = wlan_hdd_validate_context(pHddCtx);
7559
7560 if (0 != status)
7561 {
7562 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7563 "%s: HDD context is not valid", __func__);
7564 return status;
7565 }
7566
7567 /*Retrieve halHandle*/
7568 halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
7569
7570 /*in case index is 0,no entry to delete*/
7571 if (0 == PMKIDCacheIndex)
7572 {
7573 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid entry to delete" ,
7574 __func__);
7575 return -EINVAL;
7576 }
7577
7578 /*find the matching PMKSA entry from j=0 to (index-1),
7579 * and delete the matched one
7580 */
7581 for (j = 0; j<PMKIDCacheIndex; j++)
7582 {
7583 if (vos_mem_compare(PMKIDCache[j].BSSID,
7584 pmksa->bssid,
7585 WNI_CFG_BSSID_LEN))
7586 {
7587 /* BSSID matched entry */
7588 BSSIDMatched = 1;
7589
7590 if (j<PMKIDCacheIndex-1)
7591 {
7592 /*replace the matching entry with the last entry in HDD local cache*/
7593 vos_mem_copy(PMKIDCache[j].BSSID,
7594 PMKIDCache[PMKIDCacheIndex-1].BSSID,
7595 WNI_CFG_BSSID_LEN);
7596 vos_mem_copy(PMKIDCache[j].PMKID,
7597 PMKIDCache[PMKIDCacheIndex-1].PMKID,
7598 CSR_RSN_PMKID_SIZE);
7599 }
7600
7601 /*clear the last entry in HDD cache ---[index-1]*/
7602 pBSSId =(tANI_U8 *)(PMKIDCache[PMKIDCacheIndex-1].BSSID);
7603 vos_mem_zero(PMKIDCache[PMKIDCacheIndex-1].BSSID, WNI_CFG_BSSID_LEN);
7604 vos_mem_zero(PMKIDCache[PMKIDCacheIndex-1].PMKID, CSR_RSN_PMKID_SIZE);
7605
7606 /*reduce the PMKID array index*/
7607 PMKIDCacheIndex--;
7608
7609 /*delete the last PMKID cache in CSR*/
7610 result = sme_RoamDelPMKIDfromCache(halHandle, pAdapter->sessionId, pBSSId);
7611 if (0 != result)
7612 {
7613 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: cannot delete PMKSA %d CONTENT.",
7614 __func__,PMKIDCacheIndex);
7615 }
7616
7617 dump_bssid(pmksa->bssid);
7618 dump_pmkid(halHandle,pmksa->pmkid);
7619
7620 break;
7621 }
7622 }
7623
7624 /* we compare all entries,but cannot find matching entry */
7625 if (j == MAX_PMKSAIDS_IN_CACHE && !BSSIDMatched)
7626 {
7627 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: No such PMKSA entry existed %d.",
7628 __func__,pmksa->bssid);
7629 dump_bssid(pmksa->bssid);
7630 dump_pmkid(halHandle, pmksa->pmkid);
7631 return -EINVAL;
7632 }
7633 return result;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007634}
7635
Wilson Yang6507c4e2013-10-01 20:11:19 -07007636
7637
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007638static int wlan_hdd_cfg80211_flush_pmksa(struct wiphy *wiphy, struct net_device *dev)
7639{
Wilson Yang6507c4e2013-10-01 20:11:19 -07007640 tANI_U32 j=0;
7641 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7642 tHalHandle halHandle;
7643 hdd_context_t *pHddCtx;
7644 tANI_U8 *pBSSId;
7645 int status;
7646 int result;
7647
7648 hddLog(VOS_TRACE_LEVEL_DEBUG, "%s: flushing PMKSA ",__func__);
7649
7650 /* Validate pAdapter */
7651 if (NULL == pAdapter)
7652 {
7653 hddLog(VOS_TRACE_LEVEL_ERROR,
7654 "%s: Invalid Adapter" ,__func__);
7655 return -EINVAL;
7656 }
7657
7658 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7659 status = wlan_hdd_validate_context(pHddCtx);
7660
7661 if (0 != status)
7662 {
7663 hddLog(VOS_TRACE_LEVEL_ERROR,
7664 "%s: HDD context is not valid", __func__);
7665 return status;
7666 }
7667
7668 /*Retrieve halHandle*/
7669 halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
7670
7671 /*in case index is 0,no entry to delete*/
7672 if (0 == PMKIDCacheIndex)
7673 {
7674 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid entry to delete" ,
7675 __func__);
7676 return -EINVAL;
7677 }
7678
7679 /*delete all the PMKSA one by one */
7680 for (j = 0; j<PMKIDCacheIndex; j++)
7681 {
7682 /*clear the entry in HDD cache 0--index-1 */
7683 pBSSId =(tANI_U8 *)(PMKIDCache[j].BSSID);
7684 vos_mem_zero(PMKIDCache[j].BSSID, WNI_CFG_BSSID_LEN);
7685 vos_mem_zero(PMKIDCache[j].PMKID, CSR_RSN_PMKID_SIZE);
7686
7687 /*delete the PMKID in CSR*/
7688 result = sme_RoamDelPMKIDfromCache(halHandle, pAdapter->sessionId, pBSSId);
7689
7690 if (0!= result)
7691 {
7692 hddLog(VOS_TRACE_LEVEL_ERROR ,"%s cannot flush PMKIDCache %d.",
7693 __func__,j);
7694 }
7695 }
7696
7697 PMKIDCacheIndex = 0;
7698 return result;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007699}
7700#endif
7701
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07007702#if defined(WLAN_FEATURE_VOWIFI_11R) && defined(KERNEL_SUPPORT_11R_CFG80211)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307703static int wlan_hdd_cfg80211_update_ft_ies(struct wiphy *wiphy,
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07007704 struct net_device *dev, struct cfg80211_update_ft_ies_params *ftie)
7705{
7706 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7707 hdd_station_ctx_t *pHddStaCtx;
7708
7709 if (NULL == pAdapter)
7710 {
7711 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Adapter is NULL\n", __func__);
7712 return -ENODEV;
7713 }
7714
7715 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
7716
7717 // Added for debug on reception of Re-assoc Req.
7718 if (eConnectionState_Associated != pHddStaCtx->conn_info.connState)
7719 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307720 hddLog(LOGE, FL("Called with Ie of length = %d when not associated\n"),
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07007721 ftie->ie_len);
7722 hddLog(LOGE, FL("Should be Re-assoc Req IEs\n"));
7723 }
7724
7725#ifdef WLAN_FEATURE_VOWIFI_11R_DEBUG
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307726 hddLog(LOGE, FL("%s called with Ie of length = %d\n"), __func__,
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07007727 ftie->ie_len);
7728#endif
7729
7730 // Pass the received FT IEs to SME
Gopichand Nakkala356fb102013-03-06 12:34:04 +05307731 sme_SetFTIEs( WLAN_HDD_GET_HAL_CTX(pAdapter), pAdapter->sessionId,
7732 (const u8 *)ftie->ie,
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07007733 ftie->ie_len);
7734 return 0;
7735}
7736#endif
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007737
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307738#ifdef FEATURE_WLAN_SCAN_PNO
7739
7740void hdd_cfg80211_sched_scan_done_callback(void *callbackContext,
7741 tSirPrefNetworkFoundInd *pPrefNetworkFoundInd)
7742{
7743 int ret;
7744 hdd_adapter_t* pAdapter = (hdd_adapter_t*)callbackContext;
7745 hdd_context_t *pHddCtx;
7746
7747 if (NULL == pAdapter)
7748 {
7749 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
7750 "%s: HDD adapter is Null", __func__);
7751 return ;
7752 }
7753
7754 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7755 if (NULL == pHddCtx)
7756 {
7757 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7758 "%s: HDD context is Null!!!", __func__);
7759 return ;
7760 }
7761
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05307762 spin_lock(&pHddCtx->schedScan_lock);
7763 if (TRUE == pHddCtx->isWiphySuspended)
7764 {
7765 pHddCtx->isSchedScanUpdatePending = TRUE;
7766 spin_unlock(&pHddCtx->schedScan_lock);
7767 hddLog(VOS_TRACE_LEVEL_INFO,
7768 "%s: Update cfg80211 scan database after it resume", __func__);
7769 return ;
7770 }
7771 spin_unlock(&pHddCtx->schedScan_lock);
7772
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307773 ret = wlan_hdd_cfg80211_update_bss(pHddCtx->wiphy, pAdapter);
7774
7775 if (0 > ret)
7776 hddLog(VOS_TRACE_LEVEL_INFO, "%s: NO SCAN result", __func__);
7777
7778 cfg80211_sched_scan_results(pHddCtx->wiphy);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05307779 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
7780 "%s: cfg80211 scan result database updated", __func__);
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307781}
7782
7783/*
7784 * FUNCTION: wlan_hdd_cfg80211_sched_scan_start
7785 * NL interface to enable PNO
7786 */
7787static int wlan_hdd_cfg80211_sched_scan_start(struct wiphy *wiphy,
7788 struct net_device *dev, struct cfg80211_sched_scan_request *request)
7789{
7790 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7791 tpSirPNOScanReq pPnoRequest = NULL;
7792 hdd_context_t *pHddCtx;
7793 tHalHandle hHal;
Madan Mohan Koyyalamudi1d16f462013-08-27 16:25:34 +05307794 v_U32_t i, indx, num_ch, tempInterval;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307795 u8 valid_ch[WNI_CFG_VALID_CHANNEL_LIST_LEN];
7796 u8 channels_allowed[WNI_CFG_VALID_CHANNEL_LIST_LEN];
7797 v_U32_t num_channels_allowed = WNI_CFG_VALID_CHANNEL_LIST_LEN;
7798 eHalStatus status = eHAL_STATUS_FAILURE;
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307799 int ret = 0;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307800
7801 if (NULL == pAdapter)
7802 {
7803 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
7804 "%s: HDD adapter is Null", __func__);
7805 return -ENODEV;
7806 }
7807
7808 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05307809 ret = wlan_hdd_validate_context(pHddCtx);
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307810
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05307811 if (0 != ret)
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307812 {
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05307813 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7814 "%s: HDD context is not valid", __func__);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307815 return -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307816 }
7817
7818 hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
7819 if (NULL == hHal)
7820 {
7821 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7822 "%s: HAL context is Null!!!", __func__);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05307823 return -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307824 }
7825
7826 pPnoRequest = (tpSirPNOScanReq) vos_mem_malloc(sizeof (tSirPNOScanReq));
7827 if (NULL == pPnoRequest)
7828 {
7829 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
7830 "%s: vos_mem_malloc failed", __func__);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307831 return -ENOMEM;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307832 }
7833
Madan Mohan Koyyalamudic3f04352013-09-26 19:21:48 +05307834 memset(pPnoRequest, 0, sizeof (tSirPNOScanReq));
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307835 pPnoRequest->enable = 1; /*Enable PNO */
7836 pPnoRequest->ucNetworksCount = request->n_match_sets;
7837
7838 if (( !pPnoRequest->ucNetworksCount ) ||
7839 ( pPnoRequest->ucNetworksCount > SIR_PNO_MAX_SUPP_NETWORKS ))
7840 {
7841 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7842 "Network input is not correct");
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307843 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307844 goto error;
7845 }
7846
7847 if ( SIR_PNO_MAX_NETW_CHANNELS_EX < request->n_channels )
7848 {
7849 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7850 "Incorrect number of channels");
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307851 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307852 goto error;
7853 }
7854
7855 /* Framework provides one set of channels(all)
7856 * common for all saved profile */
7857 if (0 != ccmCfgGetStr(hHal, WNI_CFG_VALID_CHANNEL_LIST,
7858 channels_allowed, &num_channels_allowed))
7859 {
7860 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7861 "%s: failed to get valid channel list", __func__);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307862 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307863 goto error;
7864 }
7865 /* Checking each channel against allowed channel list */
7866 num_ch = 0;
7867 for (i = 0; i < request->n_channels; i++)
7868 {
7869 for (indx = 0; indx < num_channels_allowed; indx++)
7870 {
7871 if (request->channels[i]->hw_value == channels_allowed[indx])
7872 {
7873 valid_ch[num_ch++] = request->channels[i]->hw_value;
7874 break ;
7875 }
7876 }
7877 }
7878
7879 /* Filling per profile params */
7880 for (i = 0; i < pPnoRequest->ucNetworksCount; i++)
7881 {
7882 pPnoRequest->aNetworks[i].ssId.length =
7883 request->match_sets[i].ssid.ssid_len;
7884
7885 if (( 0 == pPnoRequest->aNetworks[i].ssId.length ) ||
7886 ( pPnoRequest->aNetworks[i].ssId.length > 32 ) )
7887 {
7888 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7889 "SSID Len %d is not correct for network %d",
7890 pPnoRequest->aNetworks[i].ssId.length, i);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307891 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307892 goto error;
7893 }
7894
7895 memcpy(pPnoRequest->aNetworks[i].ssId.ssId,
7896 request->match_sets[i].ssid.ssid,
7897 request->match_sets[i].ssid.ssid_len);
7898 pPnoRequest->aNetworks[i].authentication = 0; /*eAUTH_TYPE_ANY*/
7899 pPnoRequest->aNetworks[i].encryption = 0; /*eED_ANY*/
7900 pPnoRequest->aNetworks[i].bcastNetwType = 0; /*eBCAST_UNKNOWN*/
7901
7902 /*Copying list of valid channel into request */
7903 memcpy(pPnoRequest->aNetworks[i].aChannels, valid_ch, num_ch);
7904 pPnoRequest->aNetworks[i].ucChannelCount = num_ch;
7905
7906 pPnoRequest->aNetworks[i].rssiThreshold = 0; //Default value
7907 }
7908
Madan Mohan Koyyalamudia7765d52013-09-18 16:49:56 +05307909 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
7910 "request->ie_len = %d", request->ie_len);
7911 if ((0 < request->ie_len) && (NULL != request->ie))
7912 {
7913 pPnoRequest->us24GProbeTemplateLen = request->ie_len;
7914 memcpy(&pPnoRequest->p24GProbeTemplate, request->ie,
7915 pPnoRequest->us24GProbeTemplateLen);
7916
7917 pPnoRequest->us5GProbeTemplateLen = request->ie_len;
7918 memcpy(&pPnoRequest->p5GProbeTemplate, request->ie,
7919 pPnoRequest->us5GProbeTemplateLen);
7920 }
7921
Madan Mohan Koyyalamudi1d16f462013-08-27 16:25:34 +05307922 /* Driver gets only one time interval which is hardcoded in
7923 * supplicant for 10000ms. Taking power consumption into account 6 timers
7924 * will be used, Timervalue is increased exponentially i.e 10,20,40,
7925 * 80,160,320 secs. And number of scan cycle for each timer
7926 * is configurable through INI param gPNOScanTimerRepeatValue.
7927 * If it is set to 0 only one timer will be used and PNO scan cycle
7928 * will be repeated after each interval specified by supplicant
7929 * till PNO is disabled.
7930 */
7931 if (0 == pHddCtx->cfg_ini->configPNOScanTimerRepeatValue)
7932 pPnoRequest->scanTimers.ucScanTimersCount = HDD_PNO_SCAN_TIMERS_SET_ONE;
7933 else
7934 pPnoRequest->scanTimers.ucScanTimersCount =
7935 HDD_PNO_SCAN_TIMERS_SET_MULTIPLE;
7936
7937 tempInterval = (request->interval)/1000;
7938 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
7939 "Base scan interval = %d PNOScanTimerRepeatValue = %d",
7940 tempInterval, pHddCtx->cfg_ini->configPNOScanTimerRepeatValue);
7941 for ( i = 0; i < pPnoRequest->scanTimers.ucScanTimersCount; i++)
7942 {
7943 pPnoRequest->scanTimers.aTimerValues[i].uTimerRepeat =
7944 pHddCtx->cfg_ini->configPNOScanTimerRepeatValue;
7945 pPnoRequest->scanTimers.aTimerValues[i].uTimerValue = tempInterval;
7946 tempInterval *= 2;
7947 }
7948 //Repeat last timer until pno disabled.
7949 pPnoRequest->scanTimers.aTimerValues[i-1].uTimerRepeat = 0;
7950
Madan Mohan Koyyalamudid206c7b2013-09-26 22:54:51 +05307951 pPnoRequest->modePNO = SIR_PNO_MODE_IMMEDIATE;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307952
7953 status = sme_SetPreferredNetworkList(WLAN_HDD_GET_HAL_CTX(pAdapter),
7954 pPnoRequest, pAdapter->sessionId,
7955 hdd_cfg80211_sched_scan_done_callback, pAdapter);
7956 if (eHAL_STATUS_SUCCESS != status)
7957 {
7958 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7959 "Failed to enable PNO");
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307960 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307961 goto error;
7962 }
7963
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05307964 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
7965 "PNO scanRequest offloaded");
7966
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307967error:
7968 vos_mem_free(pPnoRequest);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307969 return ret;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307970}
7971
7972/*
7973 * FUNCTION: wlan_hdd_cfg80211_sched_scan_stop
7974 * NL interface to disable PNO
7975 */
7976static int wlan_hdd_cfg80211_sched_scan_stop(struct wiphy *wiphy,
7977 struct net_device *dev)
7978{
7979 eHalStatus status = eHAL_STATUS_FAILURE;
7980 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7981 hdd_context_t *pHddCtx;
7982 tHalHandle hHal;
7983 tpSirPNOScanReq pPnoRequest = NULL;
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307984 int ret = 0;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307985
7986 ENTER();
7987
7988 if (NULL == pAdapter)
7989 {
7990 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
7991 "%s: HDD adapter is Null", __func__);
7992 return -ENODEV;
7993 }
7994
7995 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307996
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307997 if (NULL == pHddCtx)
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307998 {
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05307999 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308000 "%s: HDD context is Null", __func__);
8001 return -ENODEV;
8002 }
8003
8004 /* The return 0 is intentional when isLogpInProgress and
8005 * isLoadUnloadInProgress. We did observe a crash due to a return of
8006 * failure in sched_scan_stop , especially for a case where the unload
8007 * of the happens at the same time. The function __cfg80211_stop_sched_scan
8008 * was clearing rdev->sched_scan_req only when the sched_scan_stop returns
8009 * success. If it returns a failure , then its next invocation due to the
8010 * clean up of the second interface will have the dev pointer corresponding
8011 * to the first one leading to a crash.
8012 */
8013 if (pHddCtx->isLogpInProgress)
8014 {
8015 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8016 "%s: LOGP in Progress. Ignore!!!", __func__);
8017 return ret;
8018 }
8019
8020 if (pHddCtx->isLoadUnloadInProgress)
8021 {
8022 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8023 "%s: Unloading/Loading in Progress. Ignore!!!", __func__);
8024 return ret;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308025 }
8026
8027 hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
8028 if (NULL == hHal)
8029 {
8030 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8031 "%s: HAL context is Null!!!", __func__);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308032 return -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308033 }
8034
8035 pPnoRequest = (tpSirPNOScanReq) vos_mem_malloc(sizeof (tSirPNOScanReq));
8036 if (NULL == pPnoRequest)
8037 {
8038 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8039 "%s: vos_mem_malloc failed", __func__);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308040 return -ENOMEM;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308041 }
8042
8043 memset(pPnoRequest, 0, sizeof (tSirPNOScanReq));
8044 pPnoRequest->enable = 0; /* Disable PNO */
8045 pPnoRequest->ucNetworksCount = 0;
8046
8047 status = sme_SetPreferredNetworkList(hHal, pPnoRequest,
8048 pAdapter->sessionId,
8049 NULL, pAdapter);
8050 if (eHAL_STATUS_SUCCESS != status)
8051 {
8052 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8053 "Failed to disabled PNO");
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308054 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308055 }
8056
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308057 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8058 "%s: PNO scan disabled", __func__);
8059
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308060 vos_mem_free(pPnoRequest);
8061
8062 EXIT();
Kamath Vinayakba5313f2013-08-22 15:52:39 +05308063 return ret;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308064}
8065
8066#endif /*FEATURE_WLAN_SCAN_PNO*/
8067
8068
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008069#ifdef FEATURE_WLAN_TDLS
8070static int wlan_hdd_cfg80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
8071 u8 *peer, u8 action_code, u8 dialog_token,
8072 u16 status_code, const u8 *buf, size_t len)
8073{
8074
8075 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8076 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008077 u8 peerMac[6];
8078 VOS_STATUS status;
Gopichand Nakkala05922802013-03-14 12:23:19 -07008079 int max_sta_failed = 0;
Hoonki Leea34dd892013-02-05 22:56:02 -08008080 int responder;
Hoonki Leed37cbb32013-04-20 00:31:14 -07008081 long rc;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008082
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008083 if (NULL == pHddCtx || NULL == pHddCtx->cfg_ini)
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008084 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05308085 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008086 "Invalid arguments");
8087 return -EINVAL;
8088 }
8089
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08008090 if (pHddCtx->isLogpInProgress)
8091 {
8092 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8093 "%s:LOGP in Progress. Ignore!!!", __func__);
Gopichand Nakkala05922802013-03-14 12:23:19 -07008094 wlan_hdd_tdls_set_link_status(pAdapter, peer, eTDLS_LINK_IDLE);
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08008095 return -EBUSY;
8096 }
8097
Hoonki Lee27511902013-03-14 18:19:06 -07008098 if (eTDLS_SUPPORT_NOT_ENABLED == pHddCtx->tdls_mode)
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008099 {
Hoonki Lee27511902013-03-14 18:19:06 -07008100 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
8101 "%s: TDLS mode is disabled OR not enabled in FW."
8102 MAC_ADDRESS_STR " action %d declined.",
8103 __func__, MAC_ADDR_ARRAY(peer), action_code);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008104 return -ENOTSUPP;
8105 }
Lee Hoonkic1262f22013-01-24 21:59:00 -08008106
Hoonki Lee27511902013-03-14 18:19:06 -07008107 /* other than teardown frame, other mgmt frames are not sent if disabled */
8108 if (SIR_MAC_TDLS_TEARDOWN != action_code)
8109 {
8110 /* if tdls_mode is disabled to respond to peer's request */
8111 if (eTDLS_SUPPORT_DISABLED == pHddCtx->tdls_mode)
8112 {
8113 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
8114 "%s: " MAC_ADDRESS_STR
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07008115 " TDLS mode is disabled. action %d declined.",
8116 __func__, MAC_ADDR_ARRAY(peer), action_code);
Hoonki Lee27511902013-03-14 18:19:06 -07008117
8118 return -ENOTSUPP;
8119 }
8120 }
8121
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008122 if (WLAN_IS_TDLS_SETUP_ACTION(action_code))
8123 {
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05308124 if (NULL != wlan_hdd_tdls_is_progress(pHddCtx, peer, TRUE))
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008125 {
8126 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008127 "%s: " MAC_ADDRESS_STR
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07008128 " TDLS setup is ongoing. action %d declined.",
8129 __func__, MAC_ADDR_ARRAY(peer), action_code);
8130 return -EPERM;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008131 }
8132 }
8133
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008134 if (SIR_MAC_TDLS_SETUP_REQ == action_code ||
8135 SIR_MAC_TDLS_SETUP_RSP == action_code )
Lee Hoonkic1262f22013-01-24 21:59:00 -08008136 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08008137 if (HDD_MAX_NUM_TDLS_STA <= wlan_hdd_tdlsConnectedPeers(pAdapter))
Lee Hoonkic1262f22013-01-24 21:59:00 -08008138 {
8139 /* supplicant still sends tdls_mgmt(SETUP_REQ) even after
8140 we return error code at 'add_station()'. Hence we have this
8141 check again in addtion to add_station().
8142 Anyway, there is no hard to double-check. */
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008143 if (SIR_MAC_TDLS_SETUP_REQ == action_code)
Lee Hoonkic1262f22013-01-24 21:59:00 -08008144 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008145 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8146 "%s: " MAC_ADDRESS_STR
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07008147 " TDLS Max peer already connected. action %d declined.",
8148 __func__, MAC_ADDR_ARRAY(peer), action_code);
Gopichand Nakkala05922802013-03-14 12:23:19 -07008149 goto error;
Lee Hoonkic1262f22013-01-24 21:59:00 -08008150 }
8151 else
8152 {
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008153 /* maximum reached. tweak to send error code to peer and return
8154 error code to supplicant */
Lee Hoonkic1262f22013-01-24 21:59:00 -08008155 status_code = eSIR_MAC_UNSPEC_FAILURE_STATUS;
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008156 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8157 "%s: " MAC_ADDRESS_STR
8158 " TDLS Max peer already connected send response status %d",
8159 __func__, MAC_ADDR_ARRAY(peer), status_code);
Gopichand Nakkala05922802013-03-14 12:23:19 -07008160 max_sta_failed = -EPERM;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008161 /* fall through to send setup resp with failure status
8162 code */
Lee Hoonkic1262f22013-01-24 21:59:00 -08008163 }
8164 }
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008165 else
8166 {
8167 hddTdlsPeer_t *pTdlsPeer;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05308168 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peer, TRUE);
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07008169 if (pTdlsPeer && TDLS_IS_CONNECTED(pTdlsPeer))
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008170 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008171 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07008172 "%s:" MAC_ADDRESS_STR " already connected. action %d declined.",
8173 __func__, MAC_ADDR_ARRAY(peer), action_code);
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008174 return -EPERM;
8175 }
8176 }
Lee Hoonkic1262f22013-01-24 21:59:00 -08008177 }
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008178 vos_mem_copy(peerMac, peer, 6);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008179
Hoonki Lee1090c6a2013-01-16 17:40:54 -08008180#ifdef WLAN_FEATURE_TDLS_DEBUG
8181 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008182 "%s: " MAC_ADDRESS_STR " action %d, dialog_token %d status %d, len = %d",
8183 "tdls_mgmt", MAC_ADDR_ARRAY(peer),
8184 action_code, dialog_token, status_code, len);
Hoonki Lee1090c6a2013-01-16 17:40:54 -08008185#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008186
Hoonki Leea34dd892013-02-05 22:56:02 -08008187 /*Except teardown responder will not be used so just make 0*/
8188 responder = 0;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08008189 if (SIR_MAC_TDLS_TEARDOWN == action_code)
Hoonki Leea34dd892013-02-05 22:56:02 -08008190 {
Gopichand Nakkala97a65fd2013-04-16 16:59:38 -07008191
8192 hddTdlsPeer_t *pTdlsPeer;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05308193 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peerMac, TRUE);
Gopichand Nakkala97a65fd2013-04-16 16:59:38 -07008194
8195 if(pTdlsPeer && TDLS_IS_CONNECTED(pTdlsPeer))
8196 responder = pTdlsPeer->is_responder;
8197 else
Hoonki Leea34dd892013-02-05 22:56:02 -08008198 {
Gopichand Nakkala97a65fd2013-04-16 16:59:38 -07008199 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8200 "%s: " MAC_ADDRESS_STR " peer doesn't exist or not connected %d dialog_token %d status %d, len = %d",
8201 __func__, MAC_ADDR_ARRAY(peer), (NULL == pTdlsPeer) ? -1 : pTdlsPeer->link_status,
8202 dialog_token, status_code, len);
8203 return -EPERM;
Hoonki Leea34dd892013-02-05 22:56:02 -08008204 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008205 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008206
Gopichand Nakkala2f1ff152013-07-01 11:27:43 +05308207 /* For explicit trigger of DIS_REQ come out of BMPS for
8208 successfully receiving DIS_RSP from peer. */
Hoonki Lee14621352013-04-16 17:51:19 -07008209 if ((SIR_MAC_TDLS_SETUP_RSP == action_code) ||
Gopichand Nakkala2f1ff152013-07-01 11:27:43 +05308210 (SIR_MAC_TDLS_DIS_RSP == action_code) ||
8211 (SIR_MAC_TDLS_DIS_REQ == action_code))
Hoonki Lee14621352013-04-16 17:51:19 -07008212 {
8213 if (TRUE == sme_IsPmcBmps(WLAN_HDD_GET_HAL_CTX(pAdapter)))
8214 {
8215 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
Gopichand Nakkala2f1ff152013-07-01 11:27:43 +05308216 "%s: Sending frame action_code %u.Disable BMPS", __func__, action_code);
Hoonki Lee14621352013-04-16 17:51:19 -07008217 hdd_disable_bmps_imps(pHddCtx, WLAN_HDD_INFRA_STATION);
8218 }
Gopichand Nakkala2f1ff152013-07-01 11:27:43 +05308219 if (SIR_MAC_TDLS_DIS_REQ != action_code)
8220 wlan_hdd_tdls_set_cap(pAdapter, peerMac, eTDLS_CAP_SUPPORTED);
Hoonki Lee14621352013-04-16 17:51:19 -07008221 }
8222
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008223 /* make sure doesn't call send_mgmt() while it is pending */
8224 if (TDLS_CTX_MAGIC == pAdapter->mgmtTxCompletionStatus)
8225 {
8226 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8227 "%s: " MAC_ADDRESS_STR " action %d couldn't sent, as one is pending. return EBUSY\n",
8228 __func__, MAC_ADDR_ARRAY(peer), action_code);
8229 return -EBUSY;
8230 }
8231
8232 pAdapter->mgmtTxCompletionStatus = TDLS_CTX_MAGIC;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008233 INIT_COMPLETION(pAdapter->tdls_mgmt_comp);
8234
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008235 status = sme_SendTdlsMgmtFrame(WLAN_HDD_GET_HAL_CTX(pAdapter), pAdapter->sessionId,
Hoonki Leea34dd892013-02-05 22:56:02 -08008236 peerMac, action_code, dialog_token, status_code, (tANI_U8 *)buf, len, responder);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008237
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008238 if (VOS_STATUS_SUCCESS != status)
8239 {
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008240 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8241 "%s: sme_SendTdlsMgmtFrame failed!", __func__);
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008242 pAdapter->mgmtTxCompletionStatus = FALSE;
Hoonki Lee14621352013-04-16 17:51:19 -07008243 wlan_hdd_tdls_check_bmps(pAdapter);
8244 goto error;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008245 }
8246
Hoonki Leed37cbb32013-04-20 00:31:14 -07008247 rc = wait_for_completion_interruptible_timeout(&pAdapter->tdls_mgmt_comp,
8248 msecs_to_jiffies(WAIT_TIME_TDLS_MGMT));
8249
8250 if ((rc <= 0) || (TRUE != pAdapter->mgmtTxCompletionStatus))
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008251 {
Hoonki Leed37cbb32013-04-20 00:31:14 -07008252 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8253 "%s: Mgmt Tx Completion failed status %ld TxCompletion %lu",
8254 __func__, rc, pAdapter->mgmtTxCompletionStatus);
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008255 pAdapter->mgmtTxCompletionStatus = FALSE;
Hoonki Leed37cbb32013-04-20 00:31:14 -07008256 wlan_hdd_tdls_check_bmps(pAdapter);
8257 goto error;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008258 }
8259
Gopichand Nakkala05922802013-03-14 12:23:19 -07008260 if (max_sta_failed)
Hoonki Lee14621352013-04-16 17:51:19 -07008261 {
8262 wlan_hdd_tdls_check_bmps(pAdapter);
Gopichand Nakkala05922802013-03-14 12:23:19 -07008263 return max_sta_failed;
Hoonki Lee14621352013-04-16 17:51:19 -07008264 }
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008265
Hoonki Leea34dd892013-02-05 22:56:02 -08008266 if (SIR_MAC_TDLS_SETUP_RSP == action_code)
8267 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08008268 wlan_hdd_tdls_set_responder(pAdapter, peerMac, TRUE);
Hoonki Leea34dd892013-02-05 22:56:02 -08008269 }
8270 else if (SIR_MAC_TDLS_SETUP_CNF == action_code)
8271 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08008272 wlan_hdd_tdls_set_responder(pAdapter, peerMac, FALSE);
Hoonki Leea34dd892013-02-05 22:56:02 -08008273 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008274
8275 return 0;
Gopichand Nakkala05922802013-03-14 12:23:19 -07008276error:
8277 /* max_sta_failed ; we didn't set to CONNECTING for this case,
8278 because we already know that this transaction will be failed,
8279 but we weren't sure if supplicant call DISABLE_LINK or not. So,
8280 to be safe, do not change the state mahine.
8281 */
8282 if(max_sta_failed == 0 &&
8283 (WLAN_IS_TDLS_SETUP_ACTION(action_code)))
8284 wlan_hdd_tdls_set_link_status(pAdapter, peerMac, eTDLS_LINK_IDLE);
8285 return -EPERM;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008286}
8287
8288static int wlan_hdd_cfg80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
8289 u8 *peer, enum nl80211_tdls_operation oper)
8290{
8291 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8292 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308293 int status;
Hoonki Lee1090c6a2013-01-16 17:40:54 -08008294#ifdef WLAN_FEATURE_TDLS_DEBUG
8295 const char *tdls_oper_str[]= {
8296 "NL80211_TDLS_DISCOVERY_REQ",
8297 "NL80211_TDLS_SETUP",
8298 "NL80211_TDLS_TEARDOWN",
8299 "NL80211_TDLS_ENABLE_LINK",
8300 "NL80211_TDLS_DISABLE_LINK",
Gopichand Nakkala29d00192013-06-20 19:03:52 +05308301 "NL80211_TDLS_UNKNOWN_OPER"};
Hoonki Lee1090c6a2013-01-16 17:40:54 -08008302#endif
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008303 hddTdlsPeer_t *pTdlsPeer;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008304
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308305 if ( NULL == peer )
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008306 {
Gopichand Nakkalab977a972013-02-18 19:15:09 -08008307 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Chilam Ngc4244af2013-04-01 15:37:32 -07008308 "%s: Invalid arguments", __func__);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008309 return -EINVAL;
8310 }
Hoonki Lee1090c6a2013-01-16 17:40:54 -08008311
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308312 status = wlan_hdd_validate_context(pHddCtx);
8313
8314 if (0 != status)
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08008315 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308316 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8317 "%s: HDD context is not valid", __func__);
8318 return status;
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08008319 }
8320
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05308321 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peer, TRUE);
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008322
8323 if ( NULL == pTdlsPeer ) {
8324 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: " MAC_ADDRESS_STR " (oper %d) not exsting. ignored",
8325 __func__, MAC_ADDR_ARRAY(peer), (int)oper);
8326 return -EINVAL;
8327 }
8328
Hoonki Lee1090c6a2013-01-16 17:40:54 -08008329#ifdef WLAN_FEATURE_TDLS_DEBUG
8330 if((int)oper > 4)
8331 oper = 5;
8332
8333 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008334 "%s: " MAC_ADDRESS_STR " link_status %d (%s) ", "tdls_oper",
8335 MAC_ADDR_ARRAY(peer), pTdlsPeer->link_status,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008336 tdls_oper_str[(int)oper]);
Hoonki Lee1090c6a2013-01-16 17:40:54 -08008337#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008338
8339 if( FALSE == pHddCtx->cfg_ini->fEnableTDLSSupport ||
Hoonki Lee1090c6a2013-01-16 17:40:54 -08008340 FALSE == sme_IsFeatureSupportedByFW(TDLS))
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008341 {
Hoonki Lee1090c6a2013-01-16 17:40:54 -08008342 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Chilam Ngc4244af2013-04-01 15:37:32 -07008343 "TDLS Disabled in INI OR not enabled in FW. "
8344 "Cannot process TDLS commands");
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008345 return -ENOTSUPP;
8346 }
8347
8348 switch (oper) {
8349 case NL80211_TDLS_ENABLE_LINK:
8350 {
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008351 VOS_STATUS status;
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05308352 tCsrTdlsLinkEstablishParams tdlsLinkEstablishParams;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008353
Gopichand Nakkala2f4a2822013-04-17 11:22:01 -07008354 if (!TDLS_STA_INDEX_VALID(pTdlsPeer->staId))
8355 {
8356 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Staion Index %u "
8357 MAC_ADDRESS_STR " failed",
8358 __func__, pTdlsPeer->staId, MAC_ADDR_ARRAY(peer));
8359 return -EINVAL;
8360 }
8361
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008362 if (eTDLS_LINK_CONNECTED != pTdlsPeer->link_status)
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008363 {
Gopichand Nakkala24be5312013-07-02 16:47:12 +05308364 long ret;
Madan Mohan Koyyalamudice419872013-09-13 19:36:52 +05308365 if (IS_ADVANCE_TDLS_ENABLE) {
Gopichand Nakkala24be5312013-07-02 16:47:12 +05308366
Madan Mohan Koyyalamudice419872013-09-13 19:36:52 +05308367 if (0 != wlan_hdd_tdls_get_link_establish_params(
8368 pAdapter, peer,&tdlsLinkEstablishParams)) {
8369 return -EINVAL;
8370 }
8371 INIT_COMPLETION(pAdapter->tdls_link_establish_req_comp);
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05308372
Madan Mohan Koyyalamudice419872013-09-13 19:36:52 +05308373 sme_SendTdlsLinkEstablishParams(WLAN_HDD_GET_HAL_CTX(pAdapter),
8374 pAdapter->sessionId, peer, &tdlsLinkEstablishParams);
8375 /* Send TDLS peer UAPSD capabilities to the firmware and
8376 * register with the TL on after the response for this operation
8377 * is received .
8378 */
8379 ret = wait_for_completion_interruptible_timeout(
8380 &pAdapter->tdls_link_establish_req_comp,
8381 msecs_to_jiffies(WAIT_TIME_TDLS_LINK_ESTABLISH_REQ));
8382 if (ret <= 0)
8383 {
8384 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8385 "%s: Link Establish Request Faled Status %ld",
8386 __func__, ret);
8387 return -EINVAL;
8388 }
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05308389 }
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07008390 wlan_hdd_tdls_set_peer_link_status(pTdlsPeer, eTDLS_LINK_CONNECTED);
Gopichand Nakkala471708b2013-06-04 20:03:01 +05308391 /* Mark TDLS client Authenticated .*/
8392 status = WLANTL_ChangeSTAState( pHddCtx->pvosContext,
8393 pTdlsPeer->staId,
8394 WLANTL_STA_AUTHENTICATED);
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07008395 if (VOS_STATUS_SUCCESS == status)
8396 {
Hoonki Lee14621352013-04-16 17:51:19 -07008397 if (pTdlsPeer->is_responder == 0)
8398 {
8399 v_U8_t staId = (v_U8_t)pTdlsPeer->staId;
8400
8401 wlan_hdd_tdls_timer_restart(pAdapter,
8402 &pTdlsPeer->initiatorWaitTimeoutTimer,
8403 WAIT_TIME_TDLS_INITIATOR);
8404 /* suspend initiator TX until it receives direct packet from the
8405 reponder or WAIT_TIME_TDLS_INITIATOR timer expires */
8406 WLANTL_SuspendDataTx( (WLAN_HDD_GET_CTX(pAdapter))->pvosContext,
8407 &staId, NULL);
8408 }
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07008409 wlan_hdd_tdls_increment_peer_count(pAdapter);
8410 }
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008411 wlan_hdd_tdls_check_bmps(pAdapter);
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05308412
8413 /* Update TL about the UAPSD masks , to route the packets to firmware */
Gopichand Nakkala574f6d12013-06-27 19:38:43 +05308414 if ((TRUE == pHddCtx->cfg_ini->fEnableTDLSBufferSta)
8415 || pHddCtx->cfg_ini->fTDLSUapsdMask )
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05308416 {
Gopichand Nakkala574f6d12013-06-27 19:38:43 +05308417 int ac;
8418 uint8 ucAc[4] = { WLANTL_AC_VO,
8419 WLANTL_AC_VI,
8420 WLANTL_AC_BK,
8421 WLANTL_AC_BE };
8422 uint8 tlTid[4] = { 7, 5, 2, 3 } ;
8423 for(ac=0; ac < 4; ac++)
8424 {
8425 status = WLANTL_EnableUAPSDForAC( (WLAN_HDD_GET_CTX(pAdapter))->pvosContext,
8426 pTdlsPeer->staId, ucAc[ac],
8427 tlTid[ac], tlTid[ac], 0, 0,
8428 WLANTL_BI_DIR );
8429 }
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05308430 }
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008431 }
8432
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008433 }
8434 break;
8435 case NL80211_TDLS_DISABLE_LINK:
Lee Hoonkic1262f22013-01-24 21:59:00 -08008436 {
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008437 if(TDLS_STA_INDEX_VALID(pTdlsPeer->staId))
Lee Hoonkic1262f22013-01-24 21:59:00 -08008438 {
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07008439 long status;
8440
8441 INIT_COMPLETION(pAdapter->tdls_del_station_comp);
8442
Lee Hoonkic1262f22013-01-24 21:59:00 -08008443 sme_DeleteTdlsPeerSta( WLAN_HDD_GET_HAL_CTX(pAdapter),
8444 pAdapter->sessionId, peer );
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07008445
8446 status = wait_for_completion_interruptible_timeout(&pAdapter->tdls_del_station_comp,
8447 msecs_to_jiffies(WAIT_TIME_TDLS_DEL_STA));
8448 if (status <= 0)
8449 {
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008450 wlan_hdd_tdls_set_peer_link_status(pTdlsPeer, eTDLS_LINK_IDLE);
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07008451 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8452 "%s: Del station failed status %ld",
8453 __func__, status);
8454 return -EPERM;
8455 }
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008456 wlan_hdd_tdls_set_peer_link_status(pTdlsPeer, eTDLS_LINK_IDLE);
Lee Hoonkic1262f22013-01-24 21:59:00 -08008457 }
8458 else
8459 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008460 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8461 "%s: TDLS Peer Station doesn't exist.", __func__);
Lee Hoonkic1262f22013-01-24 21:59:00 -08008462 }
Lee Hoonkic1262f22013-01-24 21:59:00 -08008463 }
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008464 break;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008465 case NL80211_TDLS_TEARDOWN:
8466 case NL80211_TDLS_SETUP:
8467 case NL80211_TDLS_DISCOVERY_REQ:
8468 /* We don't support in-driver setup/teardown/discovery */
8469 return -ENOTSUPP;
8470 default:
8471 return -ENOTSUPP;
8472 }
8473 return 0;
8474}
Chilam NG571c65a2013-01-19 12:27:36 +05308475
8476int wlan_hdd_cfg80211_send_tdls_discover_req(struct wiphy *wiphy,
8477 struct net_device *dev, u8 *peer)
8478{
8479 hddLog(VOS_TRACE_LEVEL_INFO, "tdls send discover req: %x %x %x %x %x %x",
8480 peer[0], peer[1], peer[2], peer[3], peer[4], peer[5]);
8481
8482 return wlan_hdd_cfg80211_tdls_mgmt(wiphy, dev, peer,
8483 WLAN_TDLS_DISCOVERY_REQUEST, 1, 0, NULL, 0);
8484}
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008485#endif
8486
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308487#ifdef WLAN_FEATURE_GTK_OFFLOAD
8488/*
8489 * FUNCTION: wlan_hdd_cfg80211_update_replayCounterCallback
8490 * Callback rountine called upon receiving response for
8491 * get offload info
8492 */
8493void wlan_hdd_cfg80211_update_replayCounterCallback(void *callbackContext,
8494 tpSirGtkOffloadGetInfoRspParams pGtkOffloadGetInfoRsp)
8495{
8496
8497 hdd_adapter_t *pAdapter = (hdd_adapter_t *)callbackContext;
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308498 tANI_U8 tempReplayCounter[8];
8499 hdd_station_ctx_t *pHddStaCtx;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308500
8501 ENTER();
8502
8503 if (NULL == pAdapter)
8504 {
8505 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8506 "%s: HDD adapter is Null", __func__);
8507 return ;
8508 }
8509
8510 if (NULL == pGtkOffloadGetInfoRsp)
8511 {
8512 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8513 "%s: pGtkOffloadGetInfoRsp is Null", __func__);
8514 return ;
8515 }
8516
8517 if (VOS_STATUS_SUCCESS != pGtkOffloadGetInfoRsp->ulStatus)
8518 {
8519 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8520 "%s: wlan Failed to get replay counter value",
8521 __func__);
8522 return ;
8523 }
8524
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308525 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
8526 /* Update replay counter */
8527 pHddStaCtx->gtkOffloadReqParams.ullKeyReplayCounter =
8528 pGtkOffloadGetInfoRsp->ullKeyReplayCounter;
8529
8530 {
8531 /* changing from little to big endian since supplicant
8532 * works on big endian format
8533 */
8534 int i;
8535 tANI_U8 *p = (tANI_U8 *)&pGtkOffloadGetInfoRsp->ullKeyReplayCounter;
8536
8537 for (i = 0; i < 8; i++)
8538 {
8539 tempReplayCounter[7-i] = (tANI_U8)p[i];
8540 }
8541 }
8542
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308543 /* Update replay counter to NL */
8544 cfg80211_gtk_rekey_notify(pAdapter->dev, pGtkOffloadGetInfoRsp->bssId,
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308545 tempReplayCounter, GFP_KERNEL);
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308546}
8547
8548/*
8549 * FUNCTION: wlan_hdd_cfg80211_set_rekey_data
8550 * This function is used to offload GTK rekeying job to the firmware.
8551 */
8552int wlan_hdd_cfg80211_set_rekey_data(struct wiphy *wiphy, struct net_device *dev,
8553 struct cfg80211_gtk_rekey_data *data)
8554{
8555 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8556 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
8557 hdd_station_ctx_t *pHddStaCtx;
8558 tHalHandle hHal;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308559 int result;
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308560 tSirGtkOffloadParams hddGtkOffloadReqParams;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308561 eHalStatus status = eHAL_STATUS_FAILURE;
8562
8563 ENTER();
8564
8565 if (NULL == pAdapter)
8566 {
8567 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8568 "%s: HDD adapter is Null", __func__);
8569 return -ENODEV;
8570 }
8571
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308572 result = wlan_hdd_validate_context(pHddCtx);
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308573
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308574 if (0 != result)
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308575 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308576 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8577 "%s: HDD context is not valid", __func__);
8578 return result;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308579 }
8580
8581 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
8582 hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
8583 if (NULL == hHal)
8584 {
8585 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8586 "%s: HAL context is Null!!!", __func__);
8587 return -EAGAIN;
8588 }
8589
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308590 pHddStaCtx->gtkOffloadReqParams.ulFlags = GTK_OFFLOAD_ENABLE;
8591 memcpy(pHddStaCtx->gtkOffloadReqParams.aKCK, data->kck, NL80211_KCK_LEN);
8592 memcpy(pHddStaCtx->gtkOffloadReqParams.aKEK, data->kek, NL80211_KEK_LEN);
8593 memcpy(pHddStaCtx->gtkOffloadReqParams.bssId, &pHddStaCtx->conn_info.bssId,
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308594 WNI_CFG_BSSID_LEN);
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308595 {
8596 /* changing from big to little endian since driver
8597 * works on little endian format
8598 */
8599 tANI_U8 *p =
8600 (tANI_U8 *)&pHddStaCtx->gtkOffloadReqParams.ullKeyReplayCounter;
8601 int i;
8602
8603 for (i = 0; i < 8; i++)
8604 {
8605 p[7-i] = data->replay_ctr[i];
8606 }
8607 }
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308608
8609 if (TRUE == pHddCtx->hdd_wlan_suspended)
8610 {
8611 /* if wlan is suspended, enable GTK offload directly from here */
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308612 memcpy(&hddGtkOffloadReqParams, &pHddStaCtx->gtkOffloadReqParams,
8613 sizeof (tSirGtkOffloadParams));
8614 status = sme_SetGTKOffload(hHal, &hddGtkOffloadReqParams,
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308615 pAdapter->sessionId);
8616
8617 if (eHAL_STATUS_SUCCESS != status)
8618 {
8619 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8620 "%s: sme_SetGTKOffload failed, returned %d",
8621 __func__, status);
8622 return status;
8623 }
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308624 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8625 "%s: sme_SetGTKOffload successfull", __func__);
8626 }
8627 else
8628 {
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308629 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8630 "%s: wlan not suspended GTKOffload request is stored",
8631 __func__);
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308632 }
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308633
8634 return eHAL_STATUS_SUCCESS;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308635}
8636#endif /*WLAN_FEATURE_GTK_OFFLOAD*/
8637
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05308638/*
8639 * FUNCTION: wlan_hdd_cfg80211_set_mac_acl
8640 * This function is used to set access control policy
8641 */
8642static int wlan_hdd_cfg80211_set_mac_acl(struct wiphy *wiphy,
8643 struct net_device *dev, const struct cfg80211_acl_data *params)
8644{
8645 int i;
8646 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8647 hdd_hostapd_state_t *pHostapdState;
8648 tsap_Config_t *pConfig;
8649 v_CONTEXT_t pVosContext = NULL;
8650 hdd_context_t *pHddCtx;
8651 int status;
8652
8653 ENTER();
8654
8655 if (NULL == pAdapter)
8656 {
8657 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8658 "%s: HDD adapter is Null", __func__);
8659 return -ENODEV;
8660 }
8661
8662 if (NULL == params)
8663 {
8664 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8665 "%s: params is Null", __func__);
8666 return -EINVAL;
8667 }
8668
8669 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
8670 status = wlan_hdd_validate_context(pHddCtx);
8671
8672 if (0 != status)
8673 {
8674 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8675 "%s: HDD context is not valid", __func__);
8676 return status;
8677 }
8678
8679 pVosContext = pHddCtx->pvosContext;
8680 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
8681
8682 if (NULL == pHostapdState)
8683 {
8684 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8685 "%s: pHostapdState is Null", __func__);
8686 return -EINVAL;
8687 }
8688
8689 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,"acl policy: = %d"
8690 "no acl entries = %d", params->acl_policy, params->n_acl_entries);
8691
8692 if (WLAN_HDD_SOFTAP == pAdapter->device_mode)
8693 {
8694 pConfig = &pAdapter->sessionCtx.ap.sapConfig;
8695
8696 /* default value */
8697 pConfig->num_accept_mac = 0;
8698 pConfig->num_deny_mac = 0;
8699
8700 /**
8701 * access control policy
8702 * @NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED: Deny stations which are
8703 * listed in hostapd.deny file.
8704 * @NL80211_ACL_POLICY_DENY_UNLESS_LISTED: Allow stations which are
8705 * listed in hostapd.accept file.
8706 */
8707 if (NL80211_ACL_POLICY_DENY_UNLESS_LISTED == params->acl_policy)
8708 {
8709 pConfig->SapMacaddr_acl = eSAP_DENY_UNLESS_ACCEPTED;
8710 }
8711 else if (NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED == params->acl_policy)
8712 {
8713 pConfig->SapMacaddr_acl = eSAP_ACCEPT_UNLESS_DENIED;
8714 }
8715 else
8716 {
8717 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8718 "%s:Acl Policy : %d is not supported",
8719 __func__, params->acl_policy);
8720 return -ENOTSUPP;
8721 }
8722
8723 if (eSAP_DENY_UNLESS_ACCEPTED == pConfig->SapMacaddr_acl)
8724 {
8725 pConfig->num_accept_mac = params->n_acl_entries;
8726 for (i = 0; i < params->n_acl_entries; i++)
8727 {
8728 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8729 "** Add ACL MAC entry %i in WhiletList :"
8730 MAC_ADDRESS_STR, i,
8731 MAC_ADDR_ARRAY(params->mac_addrs[i].addr));
8732
8733 vos_mem_copy(&pConfig->accept_mac[i], params->mac_addrs[i].addr,
8734 sizeof(qcmacaddr));
8735 }
8736 }
8737 else if (eSAP_ACCEPT_UNLESS_DENIED == pConfig->SapMacaddr_acl)
8738 {
8739 pConfig->num_deny_mac = params->n_acl_entries;
8740 for (i = 0; i < params->n_acl_entries; i++)
8741 {
8742 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8743 "** Add ACL MAC entry %i in BlackList :"
8744 MAC_ADDRESS_STR, i,
8745 MAC_ADDR_ARRAY(params->mac_addrs[i].addr));
8746
8747 vos_mem_copy(&pConfig->deny_mac[i], params->mac_addrs[i].addr,
8748 sizeof(qcmacaddr));
8749 }
8750 }
8751
8752 if (VOS_STATUS_SUCCESS != WLANSAP_SetMacACL(pVosContext, pConfig))
8753 {
8754 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8755 "%s: SAP Set Mac Acl fail", __func__);
8756 return -EINVAL;
8757 }
8758 }
8759 else
8760 {
8761 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8762 "%s: Invalid device_mode = %d",
8763 __func__, pAdapter->device_mode);
8764 return -EINVAL;
8765 }
8766
8767 return 0;
8768}
8769
Leo Chang9056f462013-08-01 19:21:11 -07008770#ifdef WLAN_NL80211_TESTMODE
8771#ifdef FEATURE_WLAN_LPHB
Leo Changd9df8aa2013-09-26 13:32:26 -07008772void wlan_hdd_cfg80211_lphb_ind_handler
Leo Chang9056f462013-08-01 19:21:11 -07008773(
8774 void *pAdapter,
8775 void *indCont
8776)
8777{
Leo Changd9df8aa2013-09-26 13:32:26 -07008778 tSirLPHBInd *lphbInd;
8779 struct sk_buff *skb;
Leo Chang9056f462013-08-01 19:21:11 -07008780
8781 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Leo Changd9df8aa2013-09-26 13:32:26 -07008782 "LPHB indication arrived");
Leo Chang9056f462013-08-01 19:21:11 -07008783
8784 if (NULL == indCont)
8785 {
8786 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Leo Changd9df8aa2013-09-26 13:32:26 -07008787 "LPHB IND, invalid argument");
Leo Chang9056f462013-08-01 19:21:11 -07008788 return;
8789 }
8790
Leo Changd9df8aa2013-09-26 13:32:26 -07008791 lphbInd = (tSirLPHBInd *)indCont;
Leo Chang9056f462013-08-01 19:21:11 -07008792 skb = cfg80211_testmode_alloc_event_skb(
8793 ((hdd_adapter_t *)pAdapter)->wdev.wiphy,
Leo Changd9df8aa2013-09-26 13:32:26 -07008794 sizeof(tSirLPHBInd),
Leo Chang9056f462013-08-01 19:21:11 -07008795 GFP_ATOMIC);
8796 if (!skb)
8797 {
8798 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8799 "LPHB timeout, NL buffer alloc fail");
8800 return;
8801 }
8802
Leo Changd9df8aa2013-09-26 13:32:26 -07008803 if(!nla_put_u32(skb, WLAN_HDD_TM_ATTR_CMD, WLAN_HDD_TM_CMD_WLAN_HB))
8804 {
8805 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8806 "WLAN_HDD_TM_ATTR_CMD put fail");
8807 goto nla_put_failure;
8808 }
8809 if(!nla_put_u32(skb, WLAN_HDD_TM_ATTR_TYPE, lphbInd->protocolType))
8810 {
8811 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8812 "WLAN_HDD_TM_ATTR_TYPE put fail");
8813 goto nla_put_failure;
8814 }
8815 if(!nla_put(skb, WLAN_HDD_TM_ATTR_DATA,
8816 sizeof(tSirLPHBInd), lphbInd))
8817 {
8818 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8819 "WLAN_HDD_TM_ATTR_DATA put fail");
8820 goto nla_put_failure;
8821 }
Leo Chang9056f462013-08-01 19:21:11 -07008822 cfg80211_testmode_event(skb, GFP_ATOMIC);
8823 return;
8824
8825nla_put_failure:
8826 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8827 "NLA Put fail");
8828 kfree_skb(skb);
8829
8830 return;
8831}
8832#endif /* FEATURE_WLAN_LPHB */
8833
8834static int wlan_hdd_cfg80211_testmode(struct wiphy *wiphy, void *data, int len)
8835{
8836 struct nlattr *tb[WLAN_HDD_TM_ATTR_MAX + 1];
8837 int err = 0;
8838#ifdef FEATURE_WLAN_LPHB
8839 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
Leo Changd9df8aa2013-09-26 13:32:26 -07008840 eHalStatus smeStatus;
Leo Chang9056f462013-08-01 19:21:11 -07008841#endif /* FEATURE_WLAN_LPHB */
8842
8843 err = nla_parse(tb, WLAN_HDD_TM_ATTR_MAX, data, len, wlan_hdd_tm_policy);
8844 if (err)
8845 {
8846 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8847 "%s Testmode INV ATTR", __func__);
8848 return err;
8849 }
8850
8851 if (!tb[WLAN_HDD_TM_ATTR_CMD])
8852 {
8853 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8854 "%s Testmode INV CMD", __func__);
8855 return -EINVAL;
8856 }
8857
8858 switch (nla_get_u32(tb[WLAN_HDD_TM_ATTR_CMD]))
8859 {
8860#ifdef FEATURE_WLAN_LPHB
8861 /* Low Power Heartbeat configuration request */
8862 case WLAN_HDD_TM_CMD_WLAN_HB:
8863 {
8864 int buf_len;
8865 void *buf;
8866 tSirLPHBReq *hb_params = NULL;
8867
8868 if (!tb[WLAN_HDD_TM_ATTR_DATA])
8869 {
8870 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8871 "%s Testmode INV DATA", __func__);
8872 return -EINVAL;
8873 }
8874
8875 buf = nla_data(tb[WLAN_HDD_TM_ATTR_DATA]);
8876 buf_len = nla_len(tb[WLAN_HDD_TM_ATTR_DATA]);
8877 hb_params = (tSirLPHBReq *)vos_mem_malloc(sizeof(tSirLPHBReq));
8878 if (NULL == hb_params)
8879 {
8880 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8881 "%s Request Buffer Alloc Fail", __func__);
8882 return -EINVAL;
8883 }
8884
8885 vos_mem_copy(hb_params, buf, buf_len);
Leo Changd9df8aa2013-09-26 13:32:26 -07008886 smeStatus = sme_LPHBConfigReq((tHalHandle)(pHddCtx->hHal),
8887 hb_params,
8888 wlan_hdd_cfg80211_lphb_ind_handler);
8889 if (eHAL_STATUS_SUCCESS != smeStatus)
Leo Chang9056f462013-08-01 19:21:11 -07008890 {
Leo Changd9df8aa2013-09-26 13:32:26 -07008891 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8892 "LPHB Config Fail, disable");
Leo Chang9056f462013-08-01 19:21:11 -07008893 vos_mem_free(hb_params);
8894 }
Leo Chang9056f462013-08-01 19:21:11 -07008895 return 0;
8896 }
8897#endif /* FEATURE_WLAN_LPHB */
8898 default:
8899 return -EOPNOTSUPP;
8900 }
8901
8902 return err;
8903}
8904#endif /* CONFIG_NL80211_TESTMODE */
8905
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05308906static int wlan_hdd_cfg80211_dump_survey(struct wiphy *wiphy,
8907 struct net_device *dev,
8908 int idx, struct survey_info *survey)
8909{
8910 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8911 hdd_context_t *pHddCtx;
Mihir Sheted9072e02013-08-21 17:02:29 +05308912 hdd_station_ctx_t *pHddStaCtx;
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05308913 tHalHandle halHandle;
Mihir Sheted9072e02013-08-21 17:02:29 +05308914 v_U32_t channel = 0, freq = 0; /* Initialization Required */
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05308915 v_S7_t snr,rssi;
8916 int status, i, j, filled = 0;
8917
8918 ENTER();
8919
8920
8921 if (NULL == pAdapter)
8922 {
8923 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8924 "%s: HDD adapter is Null", __func__);
8925 return -ENODEV;
8926 }
8927
8928 if (NULL == wiphy)
8929 {
8930 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8931 "%s: wiphy is Null", __func__);
8932 return -ENODEV;
8933 }
8934
8935 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
8936 status = wlan_hdd_validate_context(pHddCtx);
8937
8938 if (0 != status)
8939 {
8940 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8941 "%s: HDD context is not valid", __func__);
8942 return status;
8943 }
8944
Mihir Sheted9072e02013-08-21 17:02:29 +05308945 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
8946
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05308947 if (0 == pHddCtx->cfg_ini->fEnableSNRMonitoring ||
Mihir Sheted9072e02013-08-21 17:02:29 +05308948 0 != pAdapter->survey_idx ||
8949 eConnectionState_Associated != pHddStaCtx->conn_info.connState)
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05308950 {
8951 /* The survey dump ops when implemented completely is expected to
8952 * return a survey of all channels and the ops is called by the
8953 * kernel with incremental values of the argument 'idx' till it
8954 * returns -ENONET. But we can only support the survey for the
8955 * operating channel for now. survey_idx is used to track
8956 * that the ops is called only once and then return -ENONET for
8957 * the next iteration
8958 */
8959 pAdapter->survey_idx = 0;
8960 return -ENONET;
8961 }
8962
8963 halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
8964
8965 wlan_hdd_get_snr(pAdapter, &snr);
8966 wlan_hdd_get_rssi(pAdapter, &rssi);
8967
8968 sme_GetOperationChannel(halHandle, &channel, pAdapter->sessionId);
8969 hdd_wlan_get_freq(channel, &freq);
8970
8971
8972 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
8973 {
8974 if (NULL == wiphy->bands[i])
8975 {
8976 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
8977 "%s: wiphy->bands[i] is NULL, i = %d", __func__, i);
8978 continue;
8979 }
8980
8981 for (j = 0; j < wiphy->bands[i]->n_channels; j++)
8982 {
8983 struct ieee80211_supported_band *band = wiphy->bands[i];
8984
8985 if (band->channels[j].center_freq == (v_U16_t)freq)
8986 {
8987 survey->channel = &band->channels[j];
8988 /* The Rx BDs contain SNR values in dB for the received frames
8989 * while the supplicant expects noise. So we calculate and
8990 * return the value of noise (dBm)
8991 * SNR (dB) = RSSI (dBm) - NOISE (dBm)
8992 */
8993 survey->noise = rssi - snr;
8994 survey->filled = SURVEY_INFO_NOISE_DBM;
8995 filled = 1;
8996 }
8997 }
8998 }
8999
9000 if (filled)
9001 pAdapter->survey_idx = 1;
9002 else
9003 {
9004 pAdapter->survey_idx = 0;
9005 return -ENONET;
9006 }
9007
9008 return 0;
9009}
9010
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05309011/*
9012 * FUNCTION: wlan_hdd_cfg80211_resume_wlan
9013 * this is called when cfg80211 driver resume
9014 * driver updates latest sched_scan scan result(if any) to cfg80211 database
9015 */
9016int wlan_hdd_cfg80211_resume_wlan(struct wiphy *wiphy)
9017{
9018 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
9019 hdd_adapter_t *pAdapter;
9020 hdd_adapter_list_node_t *pAdapterNode, *pNext;
9021 VOS_STATUS status = VOS_STATUS_SUCCESS;
9022
9023 ENTER();
9024
9025 if ( NULL == pHddCtx )
9026 {
9027 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
9028 "%s: HddCtx validation failed", __func__);
9029 return 0;
9030 }
9031
9032 if (pHddCtx->isLogpInProgress)
9033 {
9034 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9035 "%s: LOGP in Progress. Ignore!!!", __func__);
9036 return 0;
9037 }
9038
9039 if (pHddCtx->isLoadUnloadInProgress)
9040 {
9041 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
9042 "%s: Unloading/Loading in Progress. Ignore!!!", __func__);
9043 return 0;
9044 }
9045
9046 spin_lock(&pHddCtx->schedScan_lock);
9047 pHddCtx->isWiphySuspended = FALSE;
9048 if (TRUE != pHddCtx->isSchedScanUpdatePending)
9049 {
9050 spin_unlock(&pHddCtx->schedScan_lock);
9051 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9052 "%s: Return resume is not due to PNO indication", __func__);
9053 return 0;
9054 }
9055 // Reset flag to avoid updatating cfg80211 data old results again
9056 pHddCtx->isSchedScanUpdatePending = FALSE;
9057 spin_unlock(&pHddCtx->schedScan_lock);
9058
9059 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
9060
9061 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
9062 {
9063 pAdapter = pAdapterNode->pAdapter;
9064 if ( (NULL != pAdapter) &&
9065 (WLAN_HDD_INFRA_STATION == pAdapter->device_mode) )
9066 {
9067 if (0 != wlan_hdd_cfg80211_update_bss(pHddCtx->wiphy, pAdapter))
9068 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
9069 "%s: NO SCAN result", __func__);
9070 else
9071 cfg80211_sched_scan_results(pHddCtx->wiphy);
9072
9073 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9074 "%s : cfg80211 scan result database updated", __func__);
9075
9076 return 0;
9077
9078 }
9079 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
9080 pAdapterNode = pNext;
9081 }
9082
9083 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
9084 "%s: Failed to find Adapter", __func__);
9085 return 0;
9086}
9087
9088/*
9089 * FUNCTION: wlan_hdd_cfg80211_suspend_wlan
9090 * this is called when cfg80211 driver suspends
9091 */
9092int wlan_hdd_cfg80211_suspend_wlan(struct wiphy *wiphy,
9093 struct cfg80211_wowlan *wow)
9094{
9095 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
9096
9097 ENTER();
9098 if (NULL == pHddCtx)
9099 {
9100 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
9101 "%s: HddCtx validation failed", __func__);
9102 return 0;
9103 }
9104
9105 pHddCtx->isWiphySuspended = TRUE;
9106
9107 EXIT();
9108
9109 return 0;
9110}
9111
Jeff Johnson295189b2012-06-20 16:38:30 -07009112/* cfg80211_ops */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05309113static struct cfg80211_ops wlan_hdd_cfg80211_ops =
Jeff Johnson295189b2012-06-20 16:38:30 -07009114{
9115 .add_virtual_intf = wlan_hdd_add_virtual_intf,
9116 .del_virtual_intf = wlan_hdd_del_virtual_intf,
9117 .change_virtual_intf = wlan_hdd_cfg80211_change_iface,
9118 .change_station = wlan_hdd_change_station,
9119#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
9120 .add_beacon = wlan_hdd_cfg80211_add_beacon,
9121 .del_beacon = wlan_hdd_cfg80211_del_beacon,
9122 .set_beacon = wlan_hdd_cfg80211_set_beacon,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07009123#else
9124 .start_ap = wlan_hdd_cfg80211_start_ap,
9125 .change_beacon = wlan_hdd_cfg80211_change_beacon,
9126 .stop_ap = wlan_hdd_cfg80211_stop_ap,
Jeff Johnson295189b2012-06-20 16:38:30 -07009127#endif
9128 .change_bss = wlan_hdd_cfg80211_change_bss,
9129 .add_key = wlan_hdd_cfg80211_add_key,
9130 .get_key = wlan_hdd_cfg80211_get_key,
9131 .del_key = wlan_hdd_cfg80211_del_key,
9132 .set_default_key = wlan_hdd_cfg80211_set_default_key,
Jeff Johnson3bbe4bf2013-01-18 17:05:29 -08009133#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07009134 .set_channel = wlan_hdd_cfg80211_set_channel,
Jeff Johnson3bbe4bf2013-01-18 17:05:29 -08009135#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07009136 .scan = wlan_hdd_cfg80211_scan,
9137 .connect = wlan_hdd_cfg80211_connect,
9138 .disconnect = wlan_hdd_cfg80211_disconnect,
9139 .join_ibss = wlan_hdd_cfg80211_join_ibss,
9140 .leave_ibss = wlan_hdd_cfg80211_leave_ibss,
9141 .set_wiphy_params = wlan_hdd_cfg80211_set_wiphy_params,
9142 .set_tx_power = wlan_hdd_cfg80211_set_txpower,
9143 .get_tx_power = wlan_hdd_cfg80211_get_txpower,
Jeff Johnson295189b2012-06-20 16:38:30 -07009144 .remain_on_channel = wlan_hdd_cfg80211_remain_on_channel,
9145 .cancel_remain_on_channel = wlan_hdd_cfg80211_cancel_remain_on_channel,
9146 .mgmt_tx = wlan_hdd_action,
9147#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
9148 .mgmt_tx_cancel_wait = wlan_hdd_cfg80211_mgmt_tx_cancel_wait,
9149 .set_default_mgmt_key = wlan_hdd_set_default_mgmt_key,
9150 .set_txq_params = wlan_hdd_set_txq_params,
9151#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07009152 .get_station = wlan_hdd_cfg80211_get_station,
9153 .set_power_mgmt = wlan_hdd_cfg80211_set_power_mgmt,
9154 .del_station = wlan_hdd_cfg80211_del_station,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07009155 .add_station = wlan_hdd_cfg80211_add_station,
9156#ifdef FEATURE_WLAN_LFR
9157 .set_pmksa = wlan_hdd_cfg80211_set_pmksa,
9158 .del_pmksa = wlan_hdd_cfg80211_del_pmksa,
9159 .flush_pmksa = wlan_hdd_cfg80211_flush_pmksa,
9160#endif
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07009161#if defined(WLAN_FEATURE_VOWIFI_11R) && defined(KERNEL_SUPPORT_11R_CFG80211)
9162 .update_ft_ies = wlan_hdd_cfg80211_update_ft_ies,
9163#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -08009164#ifdef FEATURE_WLAN_TDLS
9165 .tdls_mgmt = wlan_hdd_cfg80211_tdls_mgmt,
9166 .tdls_oper = wlan_hdd_cfg80211_tdls_oper,
9167#endif
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05309168#ifdef WLAN_FEATURE_GTK_OFFLOAD
9169 .set_rekey_data = wlan_hdd_cfg80211_set_rekey_data,
9170#endif /* WLAN_FEATURE_GTK_OFFLOAD */
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05309171#ifdef FEATURE_WLAN_SCAN_PNO
9172 .sched_scan_start = wlan_hdd_cfg80211_sched_scan_start,
9173 .sched_scan_stop = wlan_hdd_cfg80211_sched_scan_stop,
9174#endif /*FEATURE_WLAN_SCAN_PNO */
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05309175 .resume = wlan_hdd_cfg80211_resume_wlan,
9176 .suspend = wlan_hdd_cfg80211_suspend_wlan,
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05309177 .set_mac_acl = wlan_hdd_cfg80211_set_mac_acl,
Leo Chang9056f462013-08-01 19:21:11 -07009178#ifdef WLAN_NL80211_TESTMODE
9179 .testmode_cmd = wlan_hdd_cfg80211_testmode,
9180#endif
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05309181 .dump_survey = wlan_hdd_cfg80211_dump_survey,
Jeff Johnson295189b2012-06-20 16:38:30 -07009182};
9183