blob: 6c93f731e2d5f1ea60746ccb1aeb836b098ff0d3 [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
642 /* This will disable updating of NL channels from passive to
643 * active if a beacon is received on passive channel. */
644 wiphy->flags |= WIPHY_FLAG_DISABLE_BEACON_HINTS;
Amar Singhalf0073192013-09-20 12:34:56 -0700645
Amar Singhalfddc28c2013-09-05 13:03:40 -0700646
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700647#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
Madan Mohan Koyyalamudi1b4afb02012-10-22 15:25:16 -0700648 wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME
649 | WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
650 | WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
Jeff Johnsone7245742012-09-05 17:12:55 -0700651 | WIPHY_FLAG_OFFCHAN_TX;
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700652#endif
Srinivas Girigowda640728a2013-03-28 12:21:54 -0700653#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_CCX) || defined(FEATURE_WLAN_LFR)
654 if (pCfg->isFastTransitionEnabled
James Zmuda77fb5ae2013-01-29 08:00:17 -0800655#ifdef FEATURE_WLAN_LFR
Srinivas Girigowda640728a2013-03-28 12:21:54 -0700656 || pCfg->isFastRoamIniFeatureEnabled
657#endif
658#ifdef FEATURE_WLAN_CCX
659 || pCfg->isCcxIniFeatureEnabled
660#endif
661 )
662 {
663 wiphy->flags |= WIPHY_FLAG_SUPPORTS_FW_ROAM;
664 }
James Zmuda77fb5ae2013-01-29 08:00:17 -0800665#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -0800666#ifdef FEATURE_WLAN_TDLS
667 wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS
668 | WIPHY_FLAG_TDLS_EXTERNAL_SETUP;
669#endif
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +0530670#ifdef FEATURE_WLAN_SCAN_PNO
671 wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
Madan Mohan Koyyalamudi75de0102013-09-17 14:56:29 +0530672 wiphy->max_sched_scan_ssids = SIR_PNO_MAX_SUPP_NETWORKS;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +0530673 wiphy->max_match_sets = SIR_PNO_MAX_SUPP_NETWORKS;
674#endif/*FEATURE_WLAN_SCAN_PNO*/
Mohit Khanna698ba2a2012-12-04 15:08:18 -0800675
Amar Singhalfddc28c2013-09-05 13:03:40 -0700676#ifdef CONFIG_ENABLE_LINUX_REG
Madan Mohan Koyyalamudic3a240c2012-09-28 15:34:08 -0700677 /* even with WIPHY_FLAG_CUSTOM_REGULATORY,
678 driver can still register regulatory callback and
Amar Singhalfddc28c2013-09-05 13:03:40 -0700679 it will get regulatory settings in wiphy->band[], but
Madan Mohan Koyyalamudic3a240c2012-09-28 15:34:08 -0700680 driver need to determine what to do with both
681 regulatory settings */
Amar Singhalfddc28c2013-09-05 13:03:40 -0700682
683 wiphy->reg_notifier = wlan_hdd_linux_reg_notifier;
684#endif
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700685
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530686 wiphy->max_scan_ssids = MAX_SCAN_SSID;
687
Madan Mohan Koyyalamudi6815b162013-07-19 17:17:46 +0530688 wiphy->max_scan_ie_len = SIR_MAC_MAX_IE_LENGTH;
Jeff Johnson295189b2012-06-20 16:38:30 -0700689
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +0530690 wiphy->max_acl_mac_addrs = MAX_ACL_MAC_ADDRESS;
691
Jeff Johnson295189b2012-06-20 16:38:30 -0700692 /* Supports STATION & AD-HOC modes right now */
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530693 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION)
Jeff Johnson295189b2012-06-20 16:38:30 -0700694 | BIT(NL80211_IFTYPE_ADHOC)
Jeff Johnson295189b2012-06-20 16:38:30 -0700695 | BIT(NL80211_IFTYPE_P2P_CLIENT)
696 | BIT(NL80211_IFTYPE_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -0700697 | BIT(NL80211_IFTYPE_AP);
698
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800699#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800700 if( pCfg->enableMCC )
701 {
702 /* Currently, supports up to two channels */
703 wlan_hdd_iface_combination.num_different_channels = 2;
704
705 if( !pCfg->allowMCCGODiffBI )
706 wlan_hdd_iface_combination.beacon_int_infra_match = true;
707
708 }
709 wiphy->iface_combinations = &wlan_hdd_iface_combination;
710 wiphy->n_iface_combinations = 1;
711#endif
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800712
Jeff Johnson295189b2012-06-20 16:38:30 -0700713 /* Before registering we need to update the ht capabilitied based
714 * on ini values*/
715 if( !pCfg->ShortGI20MhzEnable )
716 {
717 wlan_hdd_band_2_4_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_20;
718 wlan_hdd_band_5_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_20;
719 wlan_hdd_band_p2p_2_4_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_20;
720 }
721
722 if( !pCfg->ShortGI40MhzEnable )
723 {
724 wlan_hdd_band_5_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_40;
725 }
726
727 if( !pCfg->nChannelBondingMode5GHz )
728 {
729 wlan_hdd_band_5_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
730 }
731
Gopichand Nakkala1f7a64f2013-04-01 18:37:17 +0530732 wiphy->bands[IEEE80211_BAND_2GHZ] = &wlan_hdd_band_2_4_GHZ;
733 wiphy->bands[IEEE80211_BAND_5GHZ] = &wlan_hdd_band_5_GHZ;
734
735 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
736 {
737
738 if (NULL == wiphy->bands[i])
739 {
740 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy->bands[i] is NULL, i = %d",
741 __func__, i);
742 continue;
743 }
744
745 for (j = 0; j < wiphy->bands[i]->n_channels; j++)
746 {
747 struct ieee80211_supported_band *band = wiphy->bands[i];
748
749 if (IEEE80211_BAND_2GHZ == i && eCSR_BAND_5G == pCfg->nBandCapability) // 5G only
750 {
751 // Enable social channels for P2P
752 if (WLAN_HDD_IS_SOCIAL_CHANNEL(band->channels[j].center_freq))
753 band->channels[j].flags &= ~IEEE80211_CHAN_DISABLED;
754 else
755 band->channels[j].flags |= IEEE80211_CHAN_DISABLED;
756 continue;
757 }
758 else if (IEEE80211_BAND_5GHZ == i && eCSR_BAND_24 == pCfg->nBandCapability) // 2G only
759 {
760 band->channels[j].flags |= IEEE80211_CHAN_DISABLED;
761 continue;
762 }
763 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700764 }
765 /*Initialise the supported cipher suite details*/
766 wiphy->cipher_suites = hdd_cipher_suites;
767 wiphy->n_cipher_suites = ARRAY_SIZE(hdd_cipher_suites);
768
769 /*signal strength in mBm (100*dBm) */
770 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
771
772#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
Jeff Johnson295189b2012-06-20 16:38:30 -0700773 wiphy->max_remain_on_channel_duration = 1000;
774#endif
Jeff Johnson295189b2012-06-20 16:38:30 -0700775
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530776 EXIT();
777 return 0;
778}
779
780/* In this function we are registering wiphy. */
781int wlan_hdd_cfg80211_register(struct wiphy *wiphy)
782{
783 ENTER();
784 /* Register our wiphy dev with cfg80211 */
Jeff Johnson295189b2012-06-20 16:38:30 -0700785 if (0 > wiphy_register(wiphy))
786 {
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530787 /* print error */
Jeff Johnson295189b2012-06-20 16:38:30 -0700788 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy register failed", __func__);
789 return -EIO;
790 }
791
792 EXIT();
793 return 0;
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530794}
Jeff Johnson295189b2012-06-20 16:38:30 -0700795
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530796/* In this function we are updating channel list when,
797 regulatory domain is FCC and country code is US.
798 Here In FCC standard 5GHz UNII-1 Bands are indoor only.
799 As per FCC smart phone is not a indoor device.
800 GO should not opeate on indoor channels */
801void wlan_hdd_cfg80211_update_reg_info(struct wiphy *wiphy)
802{
803 int j;
804 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
805 tANI_U8 defaultCountryCode[3] = SME_INVALID_COUNTRY_CODE;
806 //Default counrtycode from NV at the time of wiphy initialization.
807 if (eHAL_STATUS_SUCCESS != sme_GetDefaultCountryCodeFrmNv(pHddCtx->hHal,
808 &defaultCountryCode[0]))
809 {
810 hddLog(LOGE, FL("%s Failed to get default country code from NV"));
811 }
812 if ((defaultCountryCode[0]== 'U') && (defaultCountryCode[1]=='S'))
813 {
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530814 if (NULL == wiphy->bands[IEEE80211_BAND_5GHZ])
815 {
816 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy->bands[IEEE80211_BAND_5GHZ] is NULL",__func__ );
817 return;
818 }
819 for (j = 0; j < wiphy->bands[IEEE80211_BAND_5GHZ]->n_channels; j++)
820 {
821 struct ieee80211_supported_band *band = wiphy->bands[IEEE80211_BAND_5GHZ];
822 // Mark UNII -1 band channel as passive
823 if (WLAN_HDD_CHANNEL_IN_UNII_1_BAND(band->channels[j].center_freq))
824 band->channels[j].flags |= IEEE80211_CHAN_PASSIVE_SCAN;
825 }
826 }
827}
828
Jeff Johnson295189b2012-06-20 16:38:30 -0700829/* In this function we will do all post VOS start initialization.
830 In this function we will register for all frame in which supplicant
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530831 is interested.
Jeff Johnson295189b2012-06-20 16:38:30 -0700832*/
833void wlan_hdd_cfg80211_post_voss_start(hdd_adapter_t* pAdapter)
834{
Jeff Johnson295189b2012-06-20 16:38:30 -0700835 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
836 /* Register for all P2P action, public action etc frames */
837 v_U16_t type = (SIR_MAC_MGMT_FRAME << 2) | ( SIR_MAC_MGMT_ACTION << 4);
838
Jeff Johnsone7245742012-09-05 17:12:55 -0700839 ENTER();
840
Jeff Johnson295189b2012-06-20 16:38:30 -0700841 /* Right now we are registering these frame when driver is getting
842 initialized. Once we will move to 2.6.37 kernel, in which we have
843 frame register ops, we will move this code as a part of that */
844 /* GAS Initial Request */
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530845 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
Jeff Johnson295189b2012-06-20 16:38:30 -0700846 (v_U8_t*)GAS_INITIAL_REQ, GAS_INITIAL_REQ_SIZE );
847
848 /* GAS Initial Response */
849 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
850 (v_U8_t*)GAS_INITIAL_RSP, GAS_INITIAL_RSP_SIZE );
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530851
Jeff Johnson295189b2012-06-20 16:38:30 -0700852 /* GAS Comeback Request */
853 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
854 (v_U8_t*)GAS_COMEBACK_REQ, GAS_COMEBACK_REQ_SIZE );
855
856 /* GAS Comeback Response */
857 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
858 (v_U8_t*)GAS_COMEBACK_RSP, GAS_COMEBACK_RSP_SIZE );
859
860 /* P2P Public Action */
861 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530862 (v_U8_t*)P2P_PUBLIC_ACTION_FRAME,
Jeff Johnson295189b2012-06-20 16:38:30 -0700863 P2P_PUBLIC_ACTION_FRAME_SIZE );
864
865 /* P2P Action */
866 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
867 (v_U8_t*)P2P_ACTION_FRAME,
868 P2P_ACTION_FRAME_SIZE );
Chet Lanctot186b5732013-03-18 10:26:30 -0700869
Gopichand Nakkalae3d56e72013-04-21 23:33:32 +0530870 /* WNM BSS Transition Request frame */
871 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
872 (v_U8_t*)WNM_BSS_ACTION_FRAME,
873 WNM_BSS_ACTION_FRAME_SIZE );
874
Chet Lanctot186b5732013-03-18 10:26:30 -0700875#ifdef WLAN_FEATURE_11W
876 /* SA Query Response Action Frame */
877 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
878 (v_U8_t*)SA_QUERY_FRAME_RSP,
879 SA_QUERY_FRAME_RSP_SIZE );
880#endif /* WLAN_FEATURE_11W */
Jeff Johnson295189b2012-06-20 16:38:30 -0700881}
882
883void wlan_hdd_cfg80211_pre_voss_stop(hdd_adapter_t* pAdapter)
884{
Jeff Johnson295189b2012-06-20 16:38:30 -0700885 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
886 /* Register for all P2P action, public action etc frames */
887 v_U16_t type = (SIR_MAC_MGMT_FRAME << 2) | ( SIR_MAC_MGMT_ACTION << 4);
888
Jeff Johnsone7245742012-09-05 17:12:55 -0700889 ENTER();
890
Jeff Johnson295189b2012-06-20 16:38:30 -0700891 /* Right now we are registering these frame when driver is getting
892 initialized. Once we will move to 2.6.37 kernel, in which we have
893 frame register ops, we will move this code as a part of that */
894 /* GAS Initial Request */
895
896 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
897 (v_U8_t*)GAS_INITIAL_REQ, GAS_INITIAL_REQ_SIZE );
898
899 /* GAS Initial Response */
900 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
901 (v_U8_t*)GAS_INITIAL_RSP, GAS_INITIAL_RSP_SIZE );
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530902
Jeff Johnson295189b2012-06-20 16:38:30 -0700903 /* GAS Comeback Request */
904 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
905 (v_U8_t*)GAS_COMEBACK_REQ, GAS_COMEBACK_REQ_SIZE );
906
907 /* GAS Comeback Response */
908 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
909 (v_U8_t*)GAS_COMEBACK_RSP, GAS_COMEBACK_RSP_SIZE );
910
911 /* P2P Public Action */
912 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530913 (v_U8_t*)P2P_PUBLIC_ACTION_FRAME,
Jeff Johnson295189b2012-06-20 16:38:30 -0700914 P2P_PUBLIC_ACTION_FRAME_SIZE );
915
916 /* P2P Action */
917 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
918 (v_U8_t*)P2P_ACTION_FRAME,
919 P2P_ACTION_FRAME_SIZE );
Chet Lanctot186b5732013-03-18 10:26:30 -0700920
921#ifdef WLAN_FEATURE_11W
922 /* SA Query Response Action Frame */
923 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
924 (v_U8_t*)SA_QUERY_FRAME_RSP,
925 SA_QUERY_FRAME_RSP_SIZE );
926#endif /* WLAN_FEATURE_11W */
Jeff Johnson295189b2012-06-20 16:38:30 -0700927}
928
929#ifdef FEATURE_WLAN_WAPI
930void wlan_hdd_cfg80211_set_key_wapi(hdd_adapter_t* pAdapter, u8 key_index,
931 const u8 *mac_addr, u8 *key , int key_Len)
932{
933 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
934 tCsrRoamSetKey setKey;
935 v_BOOL_t isConnected = TRUE;
936 int status = 0;
937 v_U32_t roamId= 0xFF;
938 tANI_U8 *pKeyPtr = NULL;
939 int n = 0;
940
941 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
942 __func__,pAdapter->device_mode);
943
Gopichand Nakkalae7480202013-02-11 15:24:22 +0530944 vos_mem_zero(&setKey, sizeof(tCsrRoamSetKey));
Jeff Johnson295189b2012-06-20 16:38:30 -0700945 setKey.keyId = key_index; // Store Key ID
946 setKey.encType = eCSR_ENCRYPT_TYPE_WPI; // SET WAPI Encryption
947 setKey.keyDirection = eSIR_TX_RX; // Key Directionn both TX and RX
948 setKey.paeRole = 0 ; // the PAE role
949 if (!mac_addr || is_broadcast_ether_addr(mac_addr))
950 {
951 vos_set_macaddr_broadcast( (v_MACADDR_t *)setKey.peerMac );
952 }
953 else
954 {
955 isConnected = hdd_connIsConnected(pHddStaCtx);
956 vos_mem_copy(setKey.peerMac,&pHddStaCtx->conn_info.bssId,WNI_CFG_BSSID_LEN);
957 }
958 setKey.keyLength = key_Len;
959 pKeyPtr = setKey.Key;
960 memcpy( pKeyPtr, key, key_Len);
961
962 hddLog(VOS_TRACE_LEVEL_INFO,"\n%s: WAPI KEY LENGTH:0x%04x",
963 __func__, key_Len);
964 for (n = 0 ; n < key_Len; n++)
965 hddLog(VOS_TRACE_LEVEL_INFO, "%s WAPI KEY Data[%d]:%02x ",
966 __func__,n,setKey.Key[n]);
967
968 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_SETTING_KEY;
969 if ( isConnected )
970 {
971 status= sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
972 pAdapter->sessionId, &setKey, &roamId );
973 }
974 if ( status != 0 )
975 {
976 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
977 "[%4d] sme_RoamSetKey returned ERROR status= %d",
978 __LINE__, status );
979 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
980 }
981}
982#endif /* FEATURE_WLAN_WAPI*/
983
984#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530985int wlan_hdd_cfg80211_alloc_new_beacon(hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -0700986 beacon_data_t **ppBeacon,
987 struct beacon_parameters *params)
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700988#else
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530989int wlan_hdd_cfg80211_alloc_new_beacon(hdd_adapter_t *pAdapter,
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700990 beacon_data_t **ppBeacon,
991 struct cfg80211_beacon_data *params,
992 int dtim_period)
993#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530994{
Jeff Johnson295189b2012-06-20 16:38:30 -0700995 int size;
996 beacon_data_t *beacon = NULL;
997 beacon_data_t *old = NULL;
998 int head_len,tail_len;
999
Jeff Johnsone7245742012-09-05 17:12:55 -07001000 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07001001 if (params->head && !params->head_len)
1002 return -EINVAL;
1003
1004 old = pAdapter->sessionCtx.ap.beacon;
1005
1006 if (!params->head && !old)
1007 return -EINVAL;
1008
1009 if (params->tail && !params->tail_len)
1010 return -EINVAL;
1011
1012#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,38))
1013 /* Kernel 3.0 is not updating dtim_period for set beacon */
1014 if (!params->dtim_period)
1015 return -EINVAL;
1016#endif
1017
1018 if(params->head)
1019 head_len = params->head_len;
1020 else
1021 head_len = old->head_len;
1022
1023 if(params->tail || !old)
1024 tail_len = params->tail_len;
1025 else
1026 tail_len = old->tail_len;
1027
1028 size = sizeof(beacon_data_t) + head_len + tail_len;
1029
1030 beacon = kzalloc(size, GFP_KERNEL);
1031
1032 if( beacon == NULL )
1033 return -ENOMEM;
1034
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001035#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07001036 if(params->dtim_period || !old )
1037 beacon->dtim_period = params->dtim_period;
1038 else
1039 beacon->dtim_period = old->dtim_period;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001040#else
1041 if(dtim_period || !old )
1042 beacon->dtim_period = dtim_period;
1043 else
1044 beacon->dtim_period = old->dtim_period;
1045#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301046
Jeff Johnson295189b2012-06-20 16:38:30 -07001047 beacon->head = ((u8 *) beacon) + sizeof(beacon_data_t);
1048 beacon->tail = beacon->head + head_len;
1049 beacon->head_len = head_len;
1050 beacon->tail_len = tail_len;
1051
1052 if(params->head) {
1053 memcpy (beacon->head,params->head,beacon->head_len);
1054 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301055 else {
Jeff Johnson295189b2012-06-20 16:38:30 -07001056 if(old)
1057 memcpy (beacon->head,old->head,beacon->head_len);
1058 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301059
Jeff Johnson295189b2012-06-20 16:38:30 -07001060 if(params->tail) {
1061 memcpy (beacon->tail,params->tail,beacon->tail_len);
1062 }
1063 else {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301064 if(old)
Jeff Johnson295189b2012-06-20 16:38:30 -07001065 memcpy (beacon->tail,old->tail,beacon->tail_len);
1066 }
1067
1068 *ppBeacon = beacon;
1069
1070 kfree(old);
1071
1072 return 0;
1073
1074}
Jeff Johnson295189b2012-06-20 16:38:30 -07001075
1076v_U8_t* wlan_hdd_cfg80211_get_ie_ptr(v_U8_t *pIes, int length, v_U8_t eid)
1077{
1078 int left = length;
1079 v_U8_t *ptr = pIes;
1080 v_U8_t elem_id,elem_len;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301081
Jeff Johnson295189b2012-06-20 16:38:30 -07001082 while(left >= 2)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301083 {
Jeff Johnson295189b2012-06-20 16:38:30 -07001084 elem_id = ptr[0];
1085 elem_len = ptr[1];
1086 left -= 2;
1087 if(elem_len > left)
1088 {
1089 hddLog(VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi8bdd3112012-09-24 13:55:14 -07001090 FL("****Invalid IEs eid = %d elem_len=%d left=%d*****"),
Jeff Johnson295189b2012-06-20 16:38:30 -07001091 eid,elem_len,left);
1092 return NULL;
1093 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301094 if (elem_id == eid)
Jeff Johnson295189b2012-06-20 16:38:30 -07001095 {
1096 return ptr;
1097 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301098
Jeff Johnson295189b2012-06-20 16:38:30 -07001099 left -= elem_len;
1100 ptr += (elem_len + 2);
1101 }
1102 return NULL;
1103}
1104
Jeff Johnson295189b2012-06-20 16:38:30 -07001105/* Check if rate is 11g rate or not */
1106static int wlan_hdd_rate_is_11g(u8 rate)
1107{
Sanjay Devnani28322e22013-06-21 16:13:40 -07001108 static const u8 gRateArray[8] = {12, 18, 24, 36, 48, 72, 96, 108}; /* actual rate * 2 */
Jeff Johnson295189b2012-06-20 16:38:30 -07001109 u8 i;
1110 for (i = 0; i < 8; i++)
1111 {
1112 if(rate == gRateArray[i])
1113 return TRUE;
1114 }
1115 return FALSE;
1116}
1117
1118/* Check for 11g rate and set proper 11g only mode */
1119static void wlan_hdd_check_11gmode(u8 *pIe, u8* require_ht,
1120 u8* pCheckRatesfor11g, eSapPhyMode* pSapHw_mode)
1121{
1122 u8 i, num_rates = pIe[0];
1123
1124 pIe += 1;
1125 for ( i = 0; i < num_rates; i++)
1126 {
1127 if( *pCheckRatesfor11g && (TRUE == wlan_hdd_rate_is_11g(pIe[i] & RATE_MASK)))
1128 {
1129 /* If rate set have 11g rate than change the mode to 11G */
1130 *pSapHw_mode = eSAP_DOT11_MODE_11g;
1131 if (pIe[i] & BASIC_RATE_MASK)
1132 {
1133 /* If we have 11g rate as basic rate, it means mode
1134 is 11g only mode.
1135 */
1136 *pSapHw_mode = eSAP_DOT11_MODE_11g_ONLY;
1137 *pCheckRatesfor11g = FALSE;
1138 }
1139 }
1140 else if((BASIC_RATE_MASK | WLAN_BSS_MEMBERSHIP_SELECTOR_HT_PHY) == pIe[i])
1141 {
1142 *require_ht = TRUE;
1143 }
1144 }
1145 return;
1146}
1147
1148static void wlan_hdd_set_sapHwmode(hdd_adapter_t *pHostapdAdapter)
1149{
1150 tsap_Config_t *pConfig = &pHostapdAdapter->sessionCtx.ap.sapConfig;
1151 beacon_data_t *pBeacon = pHostapdAdapter->sessionCtx.ap.beacon;
1152 struct ieee80211_mgmt *pMgmt_frame = (struct ieee80211_mgmt*)pBeacon->head;
1153 u8 checkRatesfor11g = TRUE;
1154 u8 require_ht = FALSE;
1155 u8 *pIe=NULL;
1156
1157 pConfig->SapHw_mode= eSAP_DOT11_MODE_11b;
1158
1159 pIe = wlan_hdd_cfg80211_get_ie_ptr(&pMgmt_frame->u.beacon.variable[0],
1160 pBeacon->head_len, WLAN_EID_SUPP_RATES);
1161 if (pIe != NULL)
1162 {
1163 pIe += 1;
1164 wlan_hdd_check_11gmode(pIe, &require_ht, &checkRatesfor11g,
1165 &pConfig->SapHw_mode);
1166 }
1167
1168 pIe = wlan_hdd_cfg80211_get_ie_ptr(pBeacon->tail, pBeacon->tail_len,
1169 WLAN_EID_EXT_SUPP_RATES);
1170 if (pIe != NULL)
1171 {
1172
1173 pIe += 1;
1174 wlan_hdd_check_11gmode(pIe, &require_ht, &checkRatesfor11g,
1175 &pConfig->SapHw_mode);
1176 }
1177
1178 if( pConfig->channel > 14 )
1179 {
1180 pConfig->SapHw_mode= eSAP_DOT11_MODE_11a;
1181 }
1182
1183 pIe = wlan_hdd_cfg80211_get_ie_ptr(pBeacon->tail, pBeacon->tail_len,
1184 WLAN_EID_HT_CAPABILITY);
1185
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301186 if(pIe)
Jeff Johnson295189b2012-06-20 16:38:30 -07001187 {
1188 pConfig->SapHw_mode= eSAP_DOT11_MODE_11n;
1189 if(require_ht)
1190 pConfig->SapHw_mode= eSAP_DOT11_MODE_11n_ONLY;
1191 }
1192}
1193
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301194static int wlan_hdd_add_ie(hdd_adapter_t* pHostapdAdapter, v_U8_t *genie,
1195 v_U8_t *total_ielen, v_U8_t *oui, v_U8_t oui_size)
1196{
Arif Hussaine7f3ea52013-09-12 21:56:36 -07001197 v_U16_t ielen = 0;
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301198 v_U8_t *pIe = NULL;
1199 beacon_data_t *pBeacon = pHostapdAdapter->sessionCtx.ap.beacon;
1200
1201 pIe = wlan_hdd_get_vendor_oui_ie_ptr(oui, oui_size,
1202 pBeacon->tail, pBeacon->tail_len);
1203
1204 if (pIe)
1205 {
1206 ielen = pIe[1] + 2;
1207 if ((*total_ielen + ielen) <= MAX_GENIE_LEN)
1208 {
1209 vos_mem_copy(&genie[*total_ielen], pIe, ielen);
1210 }
1211 else
1212 {
1213 hddLog( VOS_TRACE_LEVEL_ERROR, "**Ie Length is too big***");
1214 return -EINVAL;
1215 }
1216 *total_ielen += ielen;
1217 }
1218 return 0;
1219}
1220
Arif Hussaine7f3ea52013-09-12 21:56:36 -07001221static void wlan_hdd_add_hostapd_conf_vsie(hdd_adapter_t* pHostapdAdapter,
1222 v_U8_t *genie, v_U8_t *total_ielen)
1223{
1224 beacon_data_t *pBeacon = pHostapdAdapter->sessionCtx.ap.beacon;
1225 int left = pBeacon->tail_len;
1226 v_U8_t *ptr = pBeacon->tail;
1227 v_U8_t elem_id, elem_len;
1228 v_U16_t ielen = 0;
1229
1230 if ( NULL == ptr || 0 == left )
1231 return;
1232
1233 while (left >= 2)
1234 {
1235 elem_id = ptr[0];
1236 elem_len = ptr[1];
1237 left -= 2;
1238 if (elem_len > left)
1239 {
1240 hddLog( VOS_TRACE_LEVEL_ERROR,
1241 "****Invalid IEs eid = %d elem_len=%d left=%d*****",
1242 elem_id, elem_len, left);
1243 return;
1244 }
1245 if (IE_EID_VENDOR == elem_id)
1246 {
1247 /* skipping the VSIE's which we don't want to include or
1248 * it will be included by existing code
1249 */
1250 if ((memcmp( &ptr[2], WPS_OUI_TYPE, WPS_OUI_TYPE_SIZE) != 0 ) &&
1251#ifdef WLAN_FEATURE_WFD
1252 (memcmp( &ptr[2], WFD_OUI_TYPE, WFD_OUI_TYPE_SIZE) != 0) &&
1253#endif
1254 (memcmp( &ptr[2], WHITELIST_OUI_TYPE, WPA_OUI_TYPE_SIZE) != 0) &&
1255 (memcmp( &ptr[2], BLACKLIST_OUI_TYPE, WPA_OUI_TYPE_SIZE) != 0) &&
1256 (memcmp( &ptr[2], "\x00\x50\xf2\x02", WPA_OUI_TYPE_SIZE) != 0) &&
1257 (memcmp( &ptr[2], WPA_OUI_TYPE, WPA_OUI_TYPE_SIZE) != 0) &&
1258 (memcmp( &ptr[2], P2P_OUI_TYPE, P2P_OUI_TYPE_SIZE) != 0))
1259 {
1260 ielen = ptr[1] + 2;
1261 if ((*total_ielen + ielen) <= MAX_GENIE_LEN)
1262 {
1263 vos_mem_copy(&genie[*total_ielen], ptr, ielen);
1264 *total_ielen += ielen;
1265 }
1266 else
1267 {
1268 hddLog( VOS_TRACE_LEVEL_ERROR,
1269 "IE Length is too big "
1270 "IEs eid=%d elem_len=%d total_ie_lent=%d",
1271 elem_id, elem_len, *total_ielen);
1272 }
1273 }
1274 }
1275
1276 left -= elem_len;
1277 ptr += (elem_len + 2);
1278 }
1279 return;
1280}
1281
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001282#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07001283static int wlan_hdd_cfg80211_update_apies(hdd_adapter_t* pHostapdAdapter,
1284 struct beacon_parameters *params)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001285#else
1286static int wlan_hdd_cfg80211_update_apies(hdd_adapter_t* pHostapdAdapter,
1287 struct cfg80211_beacon_data *params)
1288#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07001289{
1290 v_U8_t *genie;
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301291 v_U8_t total_ielen = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07001292 v_U8_t addIE[1] = {0};
Jeff Johnsone7245742012-09-05 17:12:55 -07001293 int ret = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07001294
1295 genie = vos_mem_malloc(MAX_GENIE_LEN);
1296
1297 if(genie == NULL) {
1298
1299 return -ENOMEM;
1300 }
1301
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301302 if (0 != wlan_hdd_add_ie(pHostapdAdapter, genie,
1303 &total_ielen, WPS_OUI_TYPE, WPS_OUI_TYPE_SIZE))
Jeff Johnson295189b2012-06-20 16:38:30 -07001304 {
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301305 ret = -EINVAL;
1306 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001307 }
1308
1309#ifdef WLAN_FEATURE_WFD
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301310 if (0 != wlan_hdd_add_ie(pHostapdAdapter, genie,
1311 &total_ielen, WFD_OUI_TYPE, WFD_OUI_TYPE_SIZE))
1312 {
1313 ret = -EINVAL;
1314 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001315 }
1316#endif
1317
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301318 if (0 != wlan_hdd_add_ie(pHostapdAdapter, genie,
1319 &total_ielen, P2P_OUI_TYPE, P2P_OUI_TYPE_SIZE))
Jeff Johnson295189b2012-06-20 16:38:30 -07001320 {
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301321 ret = -EINVAL;
1322 goto done;
1323 }
1324
1325 if (WLAN_HDD_SOFTAP == pHostapdAdapter->device_mode)
1326 {
Arif Hussaine7f3ea52013-09-12 21:56:36 -07001327 wlan_hdd_add_hostapd_conf_vsie(pHostapdAdapter, genie, &total_ielen);
Jeff Johnson295189b2012-06-20 16:38:30 -07001328 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001329
1330 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1331 WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA, genie, total_ielen, NULL,
1332 eANI_BOOLEAN_FALSE)==eHAL_STATUS_FAILURE)
1333 {
1334 hddLog(LOGE,
1335 "Could not pass on WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001336 ret = -EINVAL;
1337 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001338 }
1339
1340 if (ccmCfgSetInt((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1341 WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG, 1,NULL,
1342 test_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags) ?
1343 eANI_BOOLEAN_TRUE : eANI_BOOLEAN_FALSE)
1344 ==eHAL_STATUS_FAILURE)
1345 {
1346 hddLog(LOGE,
1347 "Could not pass on WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001348 ret = -EINVAL;
1349 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001350 }
1351
1352 // Added for ProResp IE
1353 if ( (params->proberesp_ies != NULL) && (params->proberesp_ies_len != 0) )
1354 {
1355 u16 rem_probe_resp_ie_len = params->proberesp_ies_len;
1356 u8 probe_rsp_ie_len[3] = {0};
1357 u8 counter = 0;
1358 /* Check Probe Resp Length if it is greater then 255 then Store
1359 Probe Resp IEs into WNI_CFG_PROBE_RSP_ADDNIE_DATA1 &
1360 WNI_CFG_PROBE_RSP_ADDNIE_DATA2 CFG Variable As We are not able
1361 Store More then 255 bytes into One Variable.
1362 */
1363 while ((rem_probe_resp_ie_len > 0) && (counter < 3))
1364 {
1365 if (rem_probe_resp_ie_len > MAX_CFG_STRING_LEN)
1366 {
1367 probe_rsp_ie_len[counter++] = MAX_CFG_STRING_LEN;
1368 rem_probe_resp_ie_len -= MAX_CFG_STRING_LEN;
1369 }
1370 else
1371 {
1372 probe_rsp_ie_len[counter++] = rem_probe_resp_ie_len;
1373 rem_probe_resp_ie_len = 0;
1374 }
1375 }
1376
1377 rem_probe_resp_ie_len = 0;
1378
1379 if (probe_rsp_ie_len[0] > 0)
1380 {
1381 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1382 WNI_CFG_PROBE_RSP_ADDNIE_DATA1,
1383 (tANI_U8*)&params->proberesp_ies[rem_probe_resp_ie_len],
1384 probe_rsp_ie_len[0], NULL,
1385 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
1386 {
1387 hddLog(LOGE,
1388 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA1 to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001389 ret = -EINVAL;
1390 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001391 }
1392 rem_probe_resp_ie_len += probe_rsp_ie_len[0];
1393 }
1394
1395 if (probe_rsp_ie_len[1] > 0)
1396 {
1397 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1398 WNI_CFG_PROBE_RSP_ADDNIE_DATA2,
1399 (tANI_U8*)&params->proberesp_ies[rem_probe_resp_ie_len],
1400 probe_rsp_ie_len[1], NULL,
1401 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
1402 {
1403 hddLog(LOGE,
1404 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA2 to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001405 ret = -EINVAL;
1406 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001407 }
1408 rem_probe_resp_ie_len += probe_rsp_ie_len[1];
1409 }
1410
1411 if (probe_rsp_ie_len[2] > 0)
1412 {
1413 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1414 WNI_CFG_PROBE_RSP_ADDNIE_DATA3,
1415 (tANI_U8*)&params->proberesp_ies[rem_probe_resp_ie_len],
1416 probe_rsp_ie_len[2], NULL,
1417 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
1418 {
1419 hddLog(LOGE,
1420 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA3 to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001421 ret = -EINVAL;
1422 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001423 }
1424 rem_probe_resp_ie_len += probe_rsp_ie_len[2];
1425 }
1426
1427 if (probe_rsp_ie_len[1] == 0 )
1428 {
1429 if ( eHAL_STATUS_FAILURE == ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1430 WNI_CFG_PROBE_RSP_ADDNIE_DATA2, (tANI_U8*)addIE, 0, NULL,
1431 eANI_BOOLEAN_FALSE) )
1432 {
1433 hddLog(LOGE,
1434 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA2 to CCM\n");
1435 }
1436 }
1437
1438 if (probe_rsp_ie_len[2] == 0 )
1439 {
1440 if ( eHAL_STATUS_FAILURE == ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1441 WNI_CFG_PROBE_RSP_ADDNIE_DATA3, (tANI_U8*)addIE, 0, NULL,
1442 eANI_BOOLEAN_FALSE) )
1443 {
1444 hddLog(LOGE,
1445 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA3 to CCM\n");
1446 }
1447 }
1448
1449 if (ccmCfgSetInt((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1450 WNI_CFG_PROBE_RSP_ADDNIE_FLAG, 1,NULL,
1451 test_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags) ?
1452 eANI_BOOLEAN_TRUE : eANI_BOOLEAN_FALSE)
1453 == eHAL_STATUS_FAILURE)
1454 {
1455 hddLog(LOGE,
1456 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_FLAG to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001457 ret = -EINVAL;
1458 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001459 }
1460 }
1461 else
1462 {
1463 // Reset WNI_CFG_PROBE_RSP Flags
1464 wlan_hdd_reset_prob_rspies(pHostapdAdapter);
1465
1466 hddLog(VOS_TRACE_LEVEL_INFO,
1467 "%s: No Probe Response IE received in set beacon",
1468 __func__);
1469 }
1470
1471 // Added for AssocResp IE
1472 if ( (params->assocresp_ies != NULL) && (params->assocresp_ies_len != 0) )
1473 {
1474 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1475 WNI_CFG_ASSOC_RSP_ADDNIE_DATA, (tANI_U8*)params->assocresp_ies,
1476 params->assocresp_ies_len, NULL,
1477 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
1478 {
1479 hddLog(LOGE,
1480 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_DATA to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001481 ret = -EINVAL;
1482 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001483 }
1484
1485 if (ccmCfgSetInt((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1486 WNI_CFG_ASSOC_RSP_ADDNIE_FLAG, 1, NULL,
1487 test_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags) ?
1488 eANI_BOOLEAN_TRUE : eANI_BOOLEAN_FALSE)
1489 == eHAL_STATUS_FAILURE)
1490 {
1491 hddLog(LOGE,
1492 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_FLAG to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001493 ret = -EINVAL;
1494 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001495 }
1496 }
1497 else
1498 {
1499 hddLog(VOS_TRACE_LEVEL_INFO,
1500 "%s: No Assoc Response IE received in set beacon",
1501 __func__);
1502
1503 if ( eHAL_STATUS_FAILURE == ccmCfgSetInt((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1504 WNI_CFG_ASSOC_RSP_ADDNIE_FLAG, 0, NULL,
1505 eANI_BOOLEAN_FALSE) )
1506 {
1507 hddLog(LOGE,
1508 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_FLAG to CCM\n");
1509 }
1510 }
1511
Jeff Johnsone7245742012-09-05 17:12:55 -07001512done:
Jeff Johnson295189b2012-06-20 16:38:30 -07001513 vos_mem_free(genie);
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301514 return ret;
Jeff Johnson295189b2012-06-20 16:38:30 -07001515}
Jeff Johnson295189b2012-06-20 16:38:30 -07001516
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301517/*
Jeff Johnson295189b2012-06-20 16:38:30 -07001518 * FUNCTION: wlan_hdd_validate_operation_channel
1519 * called by wlan_hdd_cfg80211_start_bss() and
1520 * wlan_hdd_cfg80211_set_channel()
1521 * This function validates whether given channel is part of valid
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301522 * channel list.
1523 */
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07001524VOS_STATUS wlan_hdd_validate_operation_channel(hdd_adapter_t *pAdapter,int channel)
Jeff Johnson295189b2012-06-20 16:38:30 -07001525{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301526
Jeff Johnson295189b2012-06-20 16:38:30 -07001527 v_U32_t num_ch = 0;
1528 u8 valid_ch[WNI_CFG_VALID_CHANNEL_LIST_LEN];
1529 u32 indx = 0;
1530 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301531 v_U8_t fValidChannel = FALSE, count = 0;
1532 hdd_config_t *hdd_pConfig_ini= (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301533
Jeff Johnson295189b2012-06-20 16:38:30 -07001534 num_ch = WNI_CFG_VALID_CHANNEL_LIST_LEN;
1535
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301536 if ( hdd_pConfig_ini->sapAllowAllChannel)
Jeff Johnson295189b2012-06-20 16:38:30 -07001537 {
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301538 /* Validate the channel */
1539 for (count = RF_CHAN_1 ; count <= RF_CHAN_165 ; count++)
Jeff Johnson295189b2012-06-20 16:38:30 -07001540 {
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301541 if ( channel == rfChannels[count].channelNum )
1542 {
1543 fValidChannel = TRUE;
1544 break;
1545 }
1546 }
1547 if (fValidChannel != TRUE)
1548 {
1549 hddLog(VOS_TRACE_LEVEL_ERROR,
1550 "%s: Invalid Channel [%d]", __func__, channel);
1551 return VOS_STATUS_E_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07001552 }
1553 }
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301554 else
Jeff Johnson295189b2012-06-20 16:38:30 -07001555 {
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301556 if (0 != ccmCfgGetStr(hHal, WNI_CFG_VALID_CHANNEL_LIST,
1557 valid_ch, &num_ch))
1558 {
1559 hddLog(VOS_TRACE_LEVEL_ERROR,
1560 "%s: failed to get valid channel list", __func__);
1561 return VOS_STATUS_E_FAILURE;
1562 }
1563 for (indx = 0; indx < num_ch; indx++)
1564 {
1565 if (channel == valid_ch[indx])
1566 {
1567 break;
1568 }
1569 }
1570
1571 if (indx >= num_ch)
1572 {
1573 hddLog(VOS_TRACE_LEVEL_ERROR,
1574 "%s: Invalid Channel [%d]", __func__, channel);
1575 return VOS_STATUS_E_FAILURE;
1576 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001577 }
1578 return VOS_STATUS_SUCCESS;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301579
Jeff Johnson295189b2012-06-20 16:38:30 -07001580}
1581
Viral Modi3a32cc52013-02-08 11:14:52 -08001582/**
1583 * FUNCTION: wlan_hdd_cfg80211_set_channel
1584 * This function is used to set the channel number
1585 */
1586static int wlan_hdd_cfg80211_set_channel( struct wiphy *wiphy, struct net_device *dev,
1587 struct ieee80211_channel *chan,
1588 enum nl80211_channel_type channel_type
1589 )
1590{
1591 v_U32_t num_ch = 0;
Jeff Johnson4416a782013-03-25 14:17:50 -07001592 int channel = 0;
Viral Modi3a32cc52013-02-08 11:14:52 -08001593 hdd_adapter_t *pAdapter = NULL;
1594 int freq = chan->center_freq; /* freq is in MHZ */
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05301595 hdd_context_t *pHddCtx;
1596 int status;
Viral Modi3a32cc52013-02-08 11:14:52 -08001597
1598 ENTER();
1599
1600 if( NULL == dev )
1601 {
1602 hddLog(VOS_TRACE_LEVEL_ERROR,
1603 "%s: Called with dev = NULL.\n", __func__);
1604 return -ENODEV;
1605 }
1606 pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
1607
1608 hddLog(VOS_TRACE_LEVEL_INFO,
1609 "%s: device_mode = %d freq = %d \n",__func__,
1610 pAdapter->device_mode, chan->center_freq);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05301611
1612 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
1613 status = wlan_hdd_validate_context(pHddCtx);
1614
1615 if (0 != status)
Viral Modi3a32cc52013-02-08 11:14:52 -08001616 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05301617 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1618 "%s: HDD context is not valid", __func__);
1619 return status;
Viral Modi3a32cc52013-02-08 11:14:52 -08001620 }
1621
1622 /*
1623 * Do freq to chan conversion
1624 * TODO: for 11a
1625 */
1626
1627 channel = ieee80211_frequency_to_channel(freq);
1628
1629 /* Check freq range */
1630 if ((WNI_CFG_CURRENT_CHANNEL_STAMIN > channel) ||
1631 (WNI_CFG_CURRENT_CHANNEL_STAMAX < channel))
1632 {
1633 hddLog(VOS_TRACE_LEVEL_ERROR,
1634 "%s: Channel [%d] is outside valid range from %d to %d\n",
1635 __func__, channel, WNI_CFG_CURRENT_CHANNEL_STAMIN,
1636 WNI_CFG_CURRENT_CHANNEL_STAMAX);
1637 return -EINVAL;
1638 }
1639
1640 num_ch = WNI_CFG_VALID_CHANNEL_LIST_LEN;
1641
Gopichand Nakkala6ab19562013-03-07 13:59:42 +05301642 if ((WLAN_HDD_SOFTAP != pAdapter->device_mode) &&
1643 (WLAN_HDD_P2P_GO != pAdapter->device_mode))
Viral Modi3a32cc52013-02-08 11:14:52 -08001644 {
1645 if(VOS_STATUS_SUCCESS != wlan_hdd_validate_operation_channel(pAdapter,channel))
1646 {
1647 hddLog(VOS_TRACE_LEVEL_ERROR,
1648 "%s: Invalid Channel [%d] \n", __func__, channel);
1649 return -EINVAL;
1650 }
1651 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
1652 "%s: set channel to [%d] for device mode =%d",
1653 __func__, channel,pAdapter->device_mode);
1654 }
1655 if( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Viral Modi3a32cc52013-02-08 11:14:52 -08001656 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Viral Modi3a32cc52013-02-08 11:14:52 -08001657 )
1658 {
1659 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
1660 tCsrRoamProfile * pRoamProfile = &pWextState->roamProfile;
1661 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
1662
1663 if (eConnectionState_IbssConnected == pHddStaCtx->conn_info.connState)
1664 {
1665 /* Link is up then return cant set channel*/
1666 hddLog( VOS_TRACE_LEVEL_ERROR,
1667 "%s: IBSS Associated, can't set the channel\n", __func__);
1668 return -EINVAL;
1669 }
1670
1671 num_ch = pRoamProfile->ChannelInfo.numOfChannels = 1;
1672 pHddStaCtx->conn_info.operationChannel = channel;
1673 pRoamProfile->ChannelInfo.ChannelList =
1674 &pHddStaCtx->conn_info.operationChannel;
1675 }
1676 else if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Viral Modi3a32cc52013-02-08 11:14:52 -08001677 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Viral Modi3a32cc52013-02-08 11:14:52 -08001678 )
1679 {
Gopichand Nakkalac8fa7b62013-03-11 13:56:41 +05301680 if (WLAN_HDD_P2P_GO == pAdapter->device_mode)
1681 {
1682 if(VOS_STATUS_SUCCESS !=
1683 wlan_hdd_validate_operation_channel(pAdapter,channel))
1684 {
1685 hddLog(VOS_TRACE_LEVEL_ERROR,
1686 "%s: Invalid Channel [%d] \n", __func__, channel);
1687 return -EINVAL;
1688 }
1689 (WLAN_HDD_GET_AP_CTX_PTR(pAdapter))->sapConfig.channel = channel;
1690 }
1691 else if ( WLAN_HDD_SOFTAP == pAdapter->device_mode )
Viral Modi3a32cc52013-02-08 11:14:52 -08001692 {
1693 hdd_config_t *cfg_param = (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini;
1694
1695 /* If auto channel selection is configured as enable/ 1 then ignore
1696 channel set by supplicant
1697 */
1698 if ( cfg_param->apAutoChannelSelection )
1699 {
Gopichand Nakkalac8fa7b62013-03-11 13:56:41 +05301700 (WLAN_HDD_GET_AP_CTX_PTR(pAdapter))->sapConfig.channel =
1701 AUTO_CHANNEL_SELECT;
Viral Modi3a32cc52013-02-08 11:14:52 -08001702 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
1703 "%s: set channel to auto channel (0) for device mode =%d",
1704 __func__, pAdapter->device_mode);
1705 }
Gopichand Nakkalac8fa7b62013-03-11 13:56:41 +05301706 else
1707 {
1708 if(VOS_STATUS_SUCCESS !=
1709 wlan_hdd_validate_operation_channel(pAdapter,channel))
1710 {
1711 hddLog(VOS_TRACE_LEVEL_ERROR,
1712 "%s: Invalid Channel [%d] \n", __func__, channel);
1713 return -EINVAL;
1714 }
1715 (WLAN_HDD_GET_AP_CTX_PTR(pAdapter))->sapConfig.channel = channel;
1716 }
Viral Modi3a32cc52013-02-08 11:14:52 -08001717 }
1718 }
1719 else
1720 {
1721 hddLog(VOS_TRACE_LEVEL_FATAL,
1722 "%s: Invalid device mode failed to set valid channel", __func__);
1723 return -EINVAL;
1724 }
1725 EXIT();
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05301726 return status;
Viral Modi3a32cc52013-02-08 11:14:52 -08001727}
1728
Jeff Johnson295189b2012-06-20 16:38:30 -07001729#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
1730static int wlan_hdd_cfg80211_start_bss(hdd_adapter_t *pHostapdAdapter,
1731 struct beacon_parameters *params)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001732#else
1733static int wlan_hdd_cfg80211_start_bss(hdd_adapter_t *pHostapdAdapter,
1734 struct cfg80211_beacon_data *params,
1735 const u8 *ssid, size_t ssid_len,
1736 enum nl80211_hidden_ssid hidden_ssid)
1737#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07001738{
1739 tsap_Config_t *pConfig;
1740 beacon_data_t *pBeacon = NULL;
1741 struct ieee80211_mgmt *pMgmt_frame;
1742 v_U8_t *pIe=NULL;
1743 v_U16_t capab_info;
1744 eCsrAuthType RSNAuthType;
1745 eCsrEncryptionType RSNEncryptType;
1746 eCsrEncryptionType mcRSNEncryptType;
1747 int status = VOS_STATUS_SUCCESS;
1748 tpWLAN_SAPEventCB pSapEventCallback;
1749 hdd_hostapd_state_t *pHostapdState;
1750 v_U8_t wpaRsnIEdata[(SIR_MAC_MAX_IE_LENGTH * 2)+4]; //Max ie length 255 * 2(WPA+RSN) + 2 bytes (vendor specific ID) * 2
1751 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pHostapdAdapter))->pvosContext;
Madan Mohan Koyylamudia16d0202013-02-01 11:05:57 +05301752 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pHostapdAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001753 struct qc_mac_acl_entry *acl_entry = NULL;
1754 v_SINT_t i;
Madan Mohan Koyyalamudi543172b2012-12-05 16:40:18 -08001755 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pHostapdAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001756
1757 ENTER();
1758
1759 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pHostapdAdapter);
1760
1761 pConfig = &pHostapdAdapter->sessionCtx.ap.sapConfig;
1762
1763 pBeacon = pHostapdAdapter->sessionCtx.ap.beacon;
1764
1765 pMgmt_frame = (struct ieee80211_mgmt*)pBeacon->head;
1766
1767 pConfig->beacon_int = pMgmt_frame->u.beacon.beacon_int;
1768
1769 //channel is already set in the set_channel Call back
1770 //pConfig->channel = pCommitConfig->channel;
1771
1772 /*Protection parameter to enable or disable*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301773 pConfig->protEnabled =
Jeff Johnson295189b2012-06-20 16:38:30 -07001774 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apProtEnabled;
1775
1776 pConfig->dtim_period = pBeacon->dtim_period;
1777
1778 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,"****pConfig->dtim_period=%d***\n",
1779 pConfig->dtim_period);
1780
1781
Madan Mohan Koyyalamudie0ca11f2012-11-27 15:57:52 -08001782 if (pHostapdAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson32d95a32012-09-10 13:15:23 -07001783 {
1784 pIe = wlan_hdd_cfg80211_get_ie_ptr(pBeacon->tail, pBeacon->tail_len,
Jeff Johnson295189b2012-06-20 16:38:30 -07001785 WLAN_EID_COUNTRY);
Jeff Johnson32d95a32012-09-10 13:15:23 -07001786 if(pIe)
Jeff Johnson295189b2012-06-20 16:38:30 -07001787 {
Jeff Johnson32d95a32012-09-10 13:15:23 -07001788 tANI_BOOLEAN restartNeeded;
Jeff Johnson32d95a32012-09-10 13:15:23 -07001789 pConfig->ieee80211d = 1;
1790 vos_mem_copy(pConfig->countryCode, &pIe[2], 3);
1791 sme_setRegInfo(hHal, pConfig->countryCode);
1792 sme_ResetCountryCodeInformation(hHal, &restartNeeded);
Jeff Johnson295189b2012-06-20 16:38:30 -07001793 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07001794 else
1795 {
1796 pConfig->ieee80211d = 0;
1797 }
Madan Mohan Koyylamudia16d0202013-02-01 11:05:57 +05301798 /*
1799 * If auto channel is configured i.e. channel is 0,
1800 * so skip channel validation.
1801 */
1802 if( AUTO_CHANNEL_SELECT != pConfig->channel )
1803 {
1804 if(VOS_STATUS_SUCCESS != wlan_hdd_validate_operation_channel(pHostapdAdapter,pConfig->channel))
1805 {
1806 hddLog(VOS_TRACE_LEVEL_ERROR,
1807 "%s: Invalid Channel [%d] \n", __func__, pConfig->channel);
1808 return -EINVAL;
1809 }
1810 }
1811 else
1812 {
1813 if(1 != pHddCtx->is_dynamic_channel_range_set)
1814 {
1815 hdd_config_t *hdd_pConfig= (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini;
1816 WLANSAP_SetChannelRange(hHal, hdd_pConfig->apStartChannelNum,
1817 hdd_pConfig->apEndChannelNum,hdd_pConfig->apOperatingBand);
1818 }
1819 pHddCtx->is_dynamic_channel_range_set = 0;
1820 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001821 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07001822 else
Jeff Johnson295189b2012-06-20 16:38:30 -07001823 {
1824 pConfig->ieee80211d = 0;
1825 }
1826 pConfig->authType = eSAP_AUTO_SWITCH;
1827
1828 capab_info = pMgmt_frame->u.beacon.capab_info;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301829
1830 pConfig->privacy = (pMgmt_frame->u.beacon.capab_info &
Jeff Johnson295189b2012-06-20 16:38:30 -07001831 WLAN_CAPABILITY_PRIVACY) ? VOS_TRUE : VOS_FALSE;
1832
1833 (WLAN_HDD_GET_AP_CTX_PTR(pHostapdAdapter))->uPrivacy = pConfig->privacy;
1834
1835 /*Set wps station to configured*/
1836 pIe = wlan_hdd_get_wps_ie_ptr(pBeacon->tail, pBeacon->tail_len);
1837
1838 if(pIe)
1839 {
1840 if(pIe[1] < (2 + WPS_OUI_TYPE_SIZE))
1841 {
1842 hddLog( VOS_TRACE_LEVEL_ERROR, "**Wps Ie Length is too small***\n");
1843 return -EINVAL;
1844 }
1845 else if(memcmp(&pIe[2], WPS_OUI_TYPE, WPS_OUI_TYPE_SIZE) == 0)
1846 {
Madan Mohan Koyyalamudi8bdd3112012-09-24 13:55:14 -07001847 hddLog( VOS_TRACE_LEVEL_INFO, "** WPS IE(len %d) ***", (pIe[1]+2));
Jeff Johnson295189b2012-06-20 16:38:30 -07001848 /* Check 15 bit of WPS IE as it contain information for wps state
1849 * WPS state
1850 */
1851 if(SAP_WPS_ENABLED_UNCONFIGURED == pIe[15])
1852 {
1853 pConfig->wps_state = SAP_WPS_ENABLED_UNCONFIGURED;
1854 } else if(SAP_WPS_ENABLED_CONFIGURED == pIe[15])
1855 {
1856 pConfig->wps_state = SAP_WPS_ENABLED_CONFIGURED;
1857 }
1858 }
1859 }
1860 else
1861 {
1862 pConfig->wps_state = SAP_WPS_DISABLED;
1863 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301864 pConfig->fwdWPSPBCProbeReq = 1; // Forward WPS PBC probe request frame up
Jeff Johnson295189b2012-06-20 16:38:30 -07001865
1866 pConfig->RSNWPAReqIELength = 0;
1867 pConfig->pRSNWPAReqIE = NULL;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301868 pIe = wlan_hdd_cfg80211_get_ie_ptr(pBeacon->tail, pBeacon->tail_len,
Jeff Johnson295189b2012-06-20 16:38:30 -07001869 WLAN_EID_RSN);
1870 if(pIe && pIe[1])
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301871 {
Jeff Johnson295189b2012-06-20 16:38:30 -07001872 pConfig->RSNWPAReqIELength = pIe[1] + 2;
1873 memcpy(&wpaRsnIEdata[0], pIe, pConfig->RSNWPAReqIELength);
1874 pConfig->pRSNWPAReqIE = &wpaRsnIEdata[0];
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301875 /* The actual processing may eventually be more extensive than
1876 * this. Right now, just consume any PMKIDs that are sent in
Jeff Johnson295189b2012-06-20 16:38:30 -07001877 * by the app.
1878 * */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301879 status = hdd_softap_unpackIE(
Jeff Johnson295189b2012-06-20 16:38:30 -07001880 vos_get_context( VOS_MODULE_ID_SME, pVosContext),
1881 &RSNEncryptType,
1882 &mcRSNEncryptType,
1883 &RSNAuthType,
1884 pConfig->pRSNWPAReqIE[1]+2,
1885 pConfig->pRSNWPAReqIE );
1886
1887 if( VOS_STATUS_SUCCESS == status )
1888 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301889 /* Now copy over all the security attributes you have
1890 * parsed out
Jeff Johnson295189b2012-06-20 16:38:30 -07001891 * */
1892 pConfig->RSNEncryptType = RSNEncryptType; // Use the cipher type in the RSN IE
1893 pConfig->mcRSNEncryptType = mcRSNEncryptType;
1894 (WLAN_HDD_GET_AP_CTX_PTR(pHostapdAdapter))->ucEncryptType
1895 = RSNEncryptType;
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +05301896 hddLog( LOG1, FL("CSR AuthType = %d, "
Jeff Johnson295189b2012-06-20 16:38:30 -07001897 "EncryptionType = %d mcEncryptionType = %d\n"),
1898 RSNAuthType, RSNEncryptType, mcRSNEncryptType);
1899 }
1900 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301901
Jeff Johnson295189b2012-06-20 16:38:30 -07001902 pIe = wlan_hdd_get_vendor_oui_ie_ptr(WPA_OUI_TYPE, WPA_OUI_TYPE_SIZE,
1903 pBeacon->tail, pBeacon->tail_len);
1904
1905 if(pIe && pIe[1] && (pIe[0] == DOT11F_EID_WPA))
1906 {
1907 if (pConfig->pRSNWPAReqIE)
1908 {
1909 /*Mixed mode WPA/WPA2*/
1910 memcpy((&wpaRsnIEdata[0] + pConfig->RSNWPAReqIELength), pIe, pIe[1] + 2);
1911 pConfig->RSNWPAReqIELength += pIe[1] + 2;
1912 }
1913 else
1914 {
1915 pConfig->RSNWPAReqIELength = pIe[1] + 2;
1916 memcpy(&wpaRsnIEdata[0], pIe, pConfig->RSNWPAReqIELength);
1917 pConfig->pRSNWPAReqIE = &wpaRsnIEdata[0];
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301918 status = hdd_softap_unpackIE(
Jeff Johnson295189b2012-06-20 16:38:30 -07001919 vos_get_context( VOS_MODULE_ID_SME, pVosContext),
1920 &RSNEncryptType,
1921 &mcRSNEncryptType,
1922 &RSNAuthType,
1923 pConfig->pRSNWPAReqIE[1]+2,
1924 pConfig->pRSNWPAReqIE );
1925
1926 if( VOS_STATUS_SUCCESS == status )
1927 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301928 /* Now copy over all the security attributes you have
1929 * parsed out
Jeff Johnson295189b2012-06-20 16:38:30 -07001930 * */
1931 pConfig->RSNEncryptType = RSNEncryptType; // Use the cipher type in the RSN IE
1932 pConfig->mcRSNEncryptType = mcRSNEncryptType;
1933 (WLAN_HDD_GET_AP_CTX_PTR(pHostapdAdapter))->ucEncryptType
1934 = RSNEncryptType;
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +05301935 hddLog( LOG1, FL("CSR AuthType = %d, "
Jeff Johnson295189b2012-06-20 16:38:30 -07001936 "EncryptionType = %d mcEncryptionType = %d\n"),
1937 RSNAuthType, RSNEncryptType, mcRSNEncryptType);
1938 }
1939 }
1940 }
1941
Jeff Johnson4416a782013-03-25 14:17:50 -07001942 if (pConfig->RSNWPAReqIELength > sizeof wpaRsnIEdata) {
1943 hddLog( VOS_TRACE_LEVEL_ERROR, "**RSNWPAReqIELength is too large***");
1944 return -EINVAL;
1945 }
1946
Jeff Johnson295189b2012-06-20 16:38:30 -07001947 pConfig->SSIDinfo.ssidHidden = VOS_FALSE;
1948
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001949#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07001950 if (params->ssid != NULL)
1951 {
1952 memcpy(pConfig->SSIDinfo.ssid.ssId, params->ssid, params->ssid_len);
1953 pConfig->SSIDinfo.ssid.length = params->ssid_len;
1954 if (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE)
1955 pConfig->SSIDinfo.ssidHidden = VOS_TRUE;
1956 }
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001957#else
1958 if (ssid != NULL)
1959 {
1960 memcpy(pConfig->SSIDinfo.ssid.ssId, ssid, ssid_len);
1961 pConfig->SSIDinfo.ssid.length = ssid_len;
1962 if (hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE)
1963 pConfig->SSIDinfo.ssidHidden = VOS_TRUE;
1964 }
1965#endif
1966
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301967 vos_mem_copy(pConfig->self_macaddr.bytes,
Jeff Johnson295189b2012-06-20 16:38:30 -07001968 pHostapdAdapter->macAddressCurrent.bytes, sizeof(v_MACADDR_t));
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301969
Jeff Johnson295189b2012-06-20 16:38:30 -07001970 /* default value */
1971 pConfig->SapMacaddr_acl = eSAP_ACCEPT_UNLESS_DENIED;
1972 pConfig->num_accept_mac = 0;
1973 pConfig->num_deny_mac = 0;
1974
1975 pIe = wlan_hdd_get_vendor_oui_ie_ptr(BLACKLIST_OUI_TYPE, WPA_OUI_TYPE_SIZE,
1976 pBeacon->tail, pBeacon->tail_len);
1977
1978 /* pIe for black list is following form:
1979 type : 1 byte
1980 length : 1 byte
1981 OUI : 4 bytes
1982 acl type : 1 byte
1983 no of mac addr in black list: 1 byte
1984 list of mac_acl_entries: variable, 6 bytes per mac address + sizeof(int) for vlan id
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301985 */
1986 if ((pIe != NULL) && (pIe[1] != 0))
Jeff Johnson295189b2012-06-20 16:38:30 -07001987 {
1988 pConfig->SapMacaddr_acl = pIe[6];
1989 pConfig->num_deny_mac = pIe[7];
1990 hddLog(VOS_TRACE_LEVEL_INFO,"acl type = %d no deny mac = %d\n",
1991 pIe[6], pIe[7]);
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05301992 if (pConfig->num_deny_mac > MAX_ACL_MAC_ADDRESS)
1993 pConfig->num_deny_mac = MAX_ACL_MAC_ADDRESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001994 acl_entry = (struct qc_mac_acl_entry *)(pIe + 8);
1995 for (i = 0; i < pConfig->num_deny_mac; i++)
1996 {
1997 vos_mem_copy(&pConfig->deny_mac[i], acl_entry->addr, sizeof(qcmacaddr));
1998 acl_entry++;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301999 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002000 }
2001 pIe = wlan_hdd_get_vendor_oui_ie_ptr(WHITELIST_OUI_TYPE, WPA_OUI_TYPE_SIZE,
2002 pBeacon->tail, pBeacon->tail_len);
2003
2004 /* pIe for white list is following form:
2005 type : 1 byte
2006 length : 1 byte
2007 OUI : 4 bytes
2008 acl type : 1 byte
2009 no of mac addr in white list: 1 byte
2010 list of mac_acl_entries: variable, 6 bytes per mac address + sizeof(int) for vlan id
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302011 */
2012 if ((pIe != NULL) && (pIe[1] != 0))
Jeff Johnson295189b2012-06-20 16:38:30 -07002013 {
2014 pConfig->SapMacaddr_acl = pIe[6];
2015 pConfig->num_accept_mac = pIe[7];
2016 hddLog(VOS_TRACE_LEVEL_INFO,"acl type = %d no accept mac = %d\n",
2017 pIe[6], pIe[7]);
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05302018 if (pConfig->num_accept_mac > MAX_ACL_MAC_ADDRESS)
2019 pConfig->num_accept_mac = MAX_ACL_MAC_ADDRESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07002020 acl_entry = (struct qc_mac_acl_entry *)(pIe + 8);
2021 for (i = 0; i < pConfig->num_accept_mac; i++)
2022 {
2023 vos_mem_copy(&pConfig->accept_mac[i], acl_entry->addr, sizeof(qcmacaddr));
2024 acl_entry++;
2025 }
2026 }
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05302027
Jeff Johnson295189b2012-06-20 16:38:30 -07002028 wlan_hdd_set_sapHwmode(pHostapdAdapter);
2029
Jeff Johnsone7245742012-09-05 17:12:55 -07002030#ifdef WLAN_FEATURE_11AC
Ravi Kumar Vaishnavbbaebbe2013-01-15 17:09:48 -08002031 /* Overwrite the hostapd setting for HW mode only for 11ac.
2032 * This is valid only if mode is set to 11n in hostapd and either AUTO or 11ac in .ini .
2033 * Otherwise, leave whatever is set in hostapd (a OR b OR g OR n mode) */
2034 if( ((pConfig->SapHw_mode == eSAP_DOT11_MODE_11n) ||
2035 (pConfig->SapHw_mode == eSAP_DOT11_MODE_11n_ONLY)) &&
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302036 (((WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->dot11Mode == eHDD_DOT11_MODE_AUTO) ||
Ravi Kumar Vaishnavbbaebbe2013-01-15 17:09:48 -08002037 ((WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->dot11Mode == eHDD_DOT11_MODE_11ac) ||
2038 ((WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY)) )
Jeff Johnsone7245742012-09-05 17:12:55 -07002039 {
2040 pConfig->SapHw_mode = eSAP_DOT11_MODE_11ac;
Ravi Joshi83bfaa12013-05-28 22:12:08 -07002041
2042 /* Disable VHT support in 2.4 GHz band */
2043 if (pConfig->channel <= 14 &&
2044 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->enableVhtFor24GHzBand == FALSE)
2045 {
2046 pConfig->SapHw_mode = eSAP_DOT11_MODE_11n;
2047 }
Jeff Johnsone7245742012-09-05 17:12:55 -07002048 }
2049#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302050
Ravi Joshiaeb7d9e2013-05-02 12:28:14 -07002051 if ( AUTO_CHANNEL_SELECT != pConfig->channel )
2052 {
2053 sme_SelectCBMode(hHal,
2054 sapConvertSapPhyModeToCsrPhyMode(pConfig->SapHw_mode),
2055 pConfig->channel);
2056 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002057 // ht_capab is not what the name conveys,this is used for protection bitmap
2058 pConfig->ht_capab =
2059 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apProtection;
2060
2061 if ( 0 != wlan_hdd_cfg80211_update_apies(pHostapdAdapter, params) )
2062 {
2063 hddLog(LOGE, FL("SAP Not able to set AP IEs"));
2064 return -EINVAL;
2065 }
2066
2067 //Uapsd Enabled Bit
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302068 pConfig->UapsdEnable =
Jeff Johnson295189b2012-06-20 16:38:30 -07002069 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apUapsdEnabled;
2070 //Enable OBSS protection
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302071 pConfig->obssProtEnabled =
2072 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apOBSSProtEnabled;
Jeff Johnson295189b2012-06-20 16:38:30 -07002073
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302074 hddLog(LOGW, FL("SOftAP macaddress : "MAC_ADDRESS_STR"\n"),
Jeff Johnson295189b2012-06-20 16:38:30 -07002075 MAC_ADDR_ARRAY(pHostapdAdapter->macAddressCurrent.bytes));
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302076 hddLog(LOGW,FL("ssid =%s\n"), pConfig->SSIDinfo.ssid.ssId);
Jeff Johnson295189b2012-06-20 16:38:30 -07002077 hddLog(LOGW,FL("beaconint=%d, channel=%d\n"), (int)pConfig->beacon_int,
2078 (int)pConfig->channel);
2079 hddLog(LOGW,FL("hw_mode=%x\n"), pConfig->SapHw_mode);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302080 hddLog(LOGW,FL("privacy=%d, authType=%d\n"), pConfig->privacy,
2081 pConfig->authType);
Jeff Johnson295189b2012-06-20 16:38:30 -07002082 hddLog(LOGW,FL("RSN/WPALen=%d, \n"),(int)pConfig->RSNWPAReqIELength);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302083 hddLog(LOGW,FL("Uapsd = %d\n"),pConfig->UapsdEnable);
Jeff Johnson295189b2012-06-20 16:38:30 -07002084 hddLog(LOGW,FL("ProtEnabled = %d, OBSSProtEnabled = %d\n"),
2085 pConfig->protEnabled, pConfig->obssProtEnabled);
2086
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302087 if(test_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags))
Jeff Johnson295189b2012-06-20 16:38:30 -07002088 {
2089 //Bss already started. just return.
2090 //TODO Probably it should update some beacon params.
2091 hddLog( LOGE, "Bss Already started...Ignore the request");
2092 EXIT();
2093 return 0;
2094 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302095
Jeff Johnson295189b2012-06-20 16:38:30 -07002096 pConfig->persona = pHostapdAdapter->device_mode;
2097
2098 pSapEventCallback = hdd_hostapd_SAPEventCB;
2099 if(WLANSAP_StartBss(pVosContext, pSapEventCallback, pConfig,
2100 (v_PVOID_t)pHostapdAdapter->dev) != VOS_STATUS_SUCCESS)
2101 {
2102 hddLog(LOGE,FL("SAP Start Bss fail\n"));
2103 return -EINVAL;
2104 }
2105
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302106 hddLog(LOG1,
Jeff Johnson295189b2012-06-20 16:38:30 -07002107 FL("Waiting for Scan to complete(auto mode) and BSS to start"));
2108
2109 status = vos_wait_single_event(&pHostapdState->vosEvent, 10000);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302110
Jeff Johnson295189b2012-06-20 16:38:30 -07002111 if (!VOS_IS_STATUS_SUCCESS(status))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302112 {
2113 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07002114 ("ERROR: HDD vos wait for single_event failed!!\n"));
2115 VOS_ASSERT(0);
2116 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302117
Jeff Johnson295189b2012-06-20 16:38:30 -07002118 //Succesfully started Bss update the state bit.
2119 set_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags);
2120
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07002121#ifdef WLAN_FEATURE_P2P_DEBUG
2122 if (pHostapdAdapter->device_mode == WLAN_HDD_P2P_GO)
2123 {
2124 if(globalP2PConnectionStatus == P2P_GO_NEG_COMPLETED)
2125 {
2126 globalP2PConnectionStatus = P2P_GO_COMPLETED_STATE;
2127 hddLog(LOGE,"[P2P State] From Go nego completed to "
Jeff Johnson1250df42012-12-10 14:31:52 -08002128 "Non-autonomous Group started");
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07002129 }
2130 else if(globalP2PConnectionStatus == P2P_NOT_ACTIVE)
2131 {
2132 globalP2PConnectionStatus = P2P_GO_COMPLETED_STATE;
2133 hddLog(LOGE,"[P2P State] From Inactive to "
Jeff Johnson1250df42012-12-10 14:31:52 -08002134 "Autonomous Group started");
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07002135 }
2136 }
2137#endif
2138
Jeff Johnson295189b2012-06-20 16:38:30 -07002139 pHostapdState->bCommit = TRUE;
2140 EXIT();
2141
2142 return 0;
2143}
2144
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002145#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302146static int wlan_hdd_cfg80211_add_beacon(struct wiphy *wiphy,
2147 struct net_device *dev,
Jeff Johnson295189b2012-06-20 16:38:30 -07002148 struct beacon_parameters *params)
2149{
2150 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302151 hdd_context_t *pHddCtx;
2152 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07002153
2154 ENTER();
2155
2156 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "device mode=%d\n",pAdapter->device_mode);
2157
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302158 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2159 status = wlan_hdd_validate_context(pHddCtx);
2160
2161 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002162 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302163 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2164 "%s: HDD context is not valid", __func__);
2165 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002166 }
2167
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302168 if ( (pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002169 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -07002170 )
2171 {
2172 beacon_data_t *old,*new;
2173
2174 old = pAdapter->sessionCtx.ap.beacon;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302175
Jeff Johnson295189b2012-06-20 16:38:30 -07002176 if (old)
2177 return -EALREADY;
2178
2179 status = wlan_hdd_cfg80211_alloc_new_beacon(pAdapter,&new,params);
2180
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302181 if(status != VOS_STATUS_SUCCESS)
Jeff Johnson295189b2012-06-20 16:38:30 -07002182 {
2183 hddLog(VOS_TRACE_LEVEL_FATAL,
2184 "%s:Error!!! Allocating the new beacon\n",__func__);
2185 return -EINVAL;
2186 }
2187
2188 pAdapter->sessionCtx.ap.beacon = new;
2189
2190 status = wlan_hdd_cfg80211_start_bss(pAdapter, params);
2191 }
2192
2193 EXIT();
2194 return status;
2195}
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302196
2197static int wlan_hdd_cfg80211_set_beacon(struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07002198 struct net_device *dev,
2199 struct beacon_parameters *params)
2200{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302201 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302202 hdd_context_t *pHddCtx;
2203 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07002204
2205 ENTER();
2206
2207 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
2208 __func__,pAdapter->device_mode);
2209
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302210 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2211 status = wlan_hdd_validate_context(pHddCtx);
2212
2213 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002214 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302215 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2216 "%s: HDD context is not valid", __func__);
2217 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002218 }
2219
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302220 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002221 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302222 )
Jeff Johnson295189b2012-06-20 16:38:30 -07002223 {
2224 beacon_data_t *old,*new;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302225
Jeff Johnson295189b2012-06-20 16:38:30 -07002226 old = pAdapter->sessionCtx.ap.beacon;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302227
Jeff Johnson295189b2012-06-20 16:38:30 -07002228 if (!old)
2229 return -ENOENT;
2230
2231 status = wlan_hdd_cfg80211_alloc_new_beacon(pAdapter,&new,params);
2232
2233 if(status != VOS_STATUS_SUCCESS) {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302234 hddLog(VOS_TRACE_LEVEL_FATAL,
Jeff Johnson295189b2012-06-20 16:38:30 -07002235 "%s: Error!!! Allocating the new beacon\n",__func__);
2236 return -EINVAL;
2237 }
2238
2239 pAdapter->sessionCtx.ap.beacon = new;
2240
2241 status = wlan_hdd_cfg80211_start_bss(pAdapter, params);
2242 }
2243
2244 EXIT();
2245 return status;
2246}
2247
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002248#endif //(LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
2249
2250#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07002251static int wlan_hdd_cfg80211_del_beacon(struct wiphy *wiphy,
2252 struct net_device *dev)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002253#else
2254static int wlan_hdd_cfg80211_stop_ap (struct wiphy *wiphy,
2255 struct net_device *dev)
2256#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002257{
2258 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsone7245742012-09-05 17:12:55 -07002259 hdd_context_t *pHddCtx = NULL;
2260 hdd_scaninfo_t *pScanInfo = NULL;
2261 hdd_adapter_t *staAdapter = NULL;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302262 VOS_STATUS status;
Jeff Johnson295189b2012-06-20 16:38:30 -07002263
2264 ENTER();
2265
2266 if (NULL == pAdapter)
2267 {
2268 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002269 "%s: HDD adapter context is Null", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002270 return -ENODEV;
2271 }
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002272
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302273 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2274 status = wlan_hdd_validate_context(pHddCtx);
2275
2276 if (0 != status)
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002277 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302278 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2279 "%s: HDD context is not valid", __func__);
2280 return status;
Jeff Johnson4416a782013-03-25 14:17:50 -07002281 }
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002282
2283 staAdapter = hdd_get_adapter(pAdapter->pHddCtx, WLAN_HDD_INFRA_STATION);
2284 if (NULL == staAdapter)
2285 {
2286 staAdapter = hdd_get_adapter(pAdapter->pHddCtx, WLAN_HDD_P2P_CLIENT);
2287 if (NULL == staAdapter)
2288 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302289 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002290 "%s: HDD adapter context is Null", __func__);
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002291 return -ENODEV;
2292 }
2293 }
2294
2295 pScanInfo = &pHddCtx->scan_info;
2296
Jeff Johnson295189b2012-06-20 16:38:30 -07002297 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
2298 __func__,pAdapter->device_mode);
2299
Jeff Johnsone7245742012-09-05 17:12:55 -07002300 if ((pScanInfo != NULL) && pScanInfo->mScanPending)
2301 {
Madan Mohan Koyyalamudif4e81002012-11-13 10:46:38 -08002302 INIT_COMPLETION(pScanInfo->abortscan_event_var);
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05302303 hdd_abort_mac_scan(staAdapter->pHddCtx, pAdapter->sessionId);
Jeff Johnsone7245742012-09-05 17:12:55 -07002304 status = wait_for_completion_interruptible_timeout(
Madan Mohan Koyyalamudif4e81002012-11-13 10:46:38 -08002305 &pScanInfo->abortscan_event_var,
Jeff Johnsone7245742012-09-05 17:12:55 -07002306 msecs_to_jiffies(WLAN_WAIT_TIME_ABORTSCAN));
2307 if (!status)
2308 {
2309 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Jeff Johnson902c9832012-12-10 14:28:09 -08002310 "%s: Timeout occurred while waiting for abortscan" ,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002311 __func__);
Jeff Johnsone7245742012-09-05 17:12:55 -07002312 VOS_ASSERT(pScanInfo->mScanPending);
2313 return 0;
2314 }
2315 }
2316
Jeff Johnson295189b2012-06-20 16:38:30 -07002317 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002318 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -07002319 )
2320 {
2321 beacon_data_t *old;
2322
2323 old = pAdapter->sessionCtx.ap.beacon;
2324
2325 if (!old)
2326 return -ENOENT;
2327
Jeff Johnson295189b2012-06-20 16:38:30 -07002328 hdd_cleanup_actionframe(pHddCtx, pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07002329
2330 mutex_lock(&pHddCtx->sap_lock);
2331 if(test_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags))
2332 {
Jeff Johnson4416a782013-03-25 14:17:50 -07002333 if ( VOS_STATUS_SUCCESS == (status = WLANSAP_StopBss(pHddCtx->pvosContext) ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07002334 {
2335 hdd_hostapd_state_t *pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
2336
2337 status = vos_wait_single_event(&pHostapdState->vosEvent, 10000);
2338
2339 if (!VOS_IS_STATUS_SUCCESS(status))
2340 {
2341 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2342 ("ERROR: HDD vos wait for single_event failed!!\n"));
2343 VOS_ASSERT(0);
2344 }
2345 }
2346 clear_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags);
2347 }
2348 mutex_unlock(&pHddCtx->sap_lock);
2349
2350 if(status != VOS_STATUS_SUCCESS)
2351 {
2352 hddLog(VOS_TRACE_LEVEL_FATAL,
2353 "%s:Error!!! Stopping the BSS\n",__func__);
2354 return -EINVAL;
2355 }
2356
Jeff Johnson4416a782013-03-25 14:17:50 -07002357 if (ccmCfgSetInt(pHddCtx->hHal,
Jeff Johnson295189b2012-06-20 16:38:30 -07002358 WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG, 0,NULL, eANI_BOOLEAN_FALSE)
2359 ==eHAL_STATUS_FAILURE)
2360 {
2361 hddLog(LOGE,
2362 "Could not pass on WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG to CCM\n");
2363 }
2364
Jeff Johnson4416a782013-03-25 14:17:50 -07002365 if ( eHAL_STATUS_FAILURE == ccmCfgSetInt(pHddCtx->hHal,
Jeff Johnson295189b2012-06-20 16:38:30 -07002366 WNI_CFG_ASSOC_RSP_ADDNIE_FLAG, 0, NULL,
2367 eANI_BOOLEAN_FALSE) )
2368 {
2369 hddLog(LOGE,
2370 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_FLAG to CCM\n");
2371 }
2372
2373 // Reset WNI_CFG_PROBE_RSP Flags
2374 wlan_hdd_reset_prob_rspies(pAdapter);
2375
2376 pAdapter->sessionCtx.ap.beacon = NULL;
2377 kfree(old);
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07002378#ifdef WLAN_FEATURE_P2P_DEBUG
2379 if((pAdapter->device_mode == WLAN_HDD_P2P_GO) &&
2380 (globalP2PConnectionStatus == P2P_GO_COMPLETED_STATE))
2381 {
2382 hddLog(LOGE,"[P2P State] From GO completed to Inactive state "
2383 "GO got removed");
2384 globalP2PConnectionStatus = P2P_NOT_ACTIVE;
2385 }
2386#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002387 }
2388 EXIT();
2389 return status;
2390}
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002391
2392#if (LINUX_VERSION_CODE > KERNEL_VERSION(3,3,0))
2393
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302394static int wlan_hdd_cfg80211_start_ap(struct wiphy *wiphy,
2395 struct net_device *dev,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002396 struct cfg80211_ap_settings *params)
2397{
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302398 hdd_adapter_t *pAdapter;
2399 hdd_context_t *pHddCtx;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302400 int status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002401
2402 ENTER();
2403
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302404 if (NULL == dev)
Madan Mohan Koyyalamudib2c36892012-10-18 20:52:38 -07002405 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302406 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302407 "%s: Device is Null", __func__);
2408 return -ENODEV;
2409 }
2410
2411 pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
2412 if (NULL == pAdapter)
2413 {
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: HDD adapter is Null", __func__);
2416 return -ENODEV;
2417 }
2418
2419 if (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic)
2420 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302421 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302422 "%s: HDD adapter magic is invalid", __func__);
2423 return -ENODEV;
2424 }
2425
2426 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302427 status = wlan_hdd_validate_context(pHddCtx);
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302428
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302429 if (0 != status)
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302430 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302431 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2432 "%s: HDD context is not valid", __func__);
2433 return status;
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302434 }
2435
2436 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: device mode = %d",
2437 __func__, pAdapter->device_mode);
2438
2439 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002440 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002441 )
2442 {
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302443 beacon_data_t *old, *new;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002444
2445 old = pAdapter->sessionCtx.ap.beacon;
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302446
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002447 if (old)
2448 return -EALREADY;
2449
2450 status = wlan_hdd_cfg80211_alloc_new_beacon(pAdapter, &new, &params->beacon, params->dtim_period);
2451
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302452 if (status != 0)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002453 {
2454 hddLog(VOS_TRACE_LEVEL_FATAL,
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302455 "%s:Error!!! Allocating the new beacon", __func__);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002456 return -EINVAL;
2457 }
2458 pAdapter->sessionCtx.ap.beacon = new;
Viral Modi3a32cc52013-02-08 11:14:52 -08002459#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
Yue Maf49ba872013-08-19 12:04:25 -07002460 wlan_hdd_cfg80211_set_channel(wiphy, dev,
2461#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0))
2462 params->channel, params->channel_type);
2463#else
2464 params->chandef.chan, cfg80211_get_chandef_type(&(params->chandef)));
2465#endif
Viral Modi3a32cc52013-02-08 11:14:52 -08002466#endif
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002467 status = wlan_hdd_cfg80211_start_bss(pAdapter, &params->beacon, params->ssid,
2468 params->ssid_len, params->hidden_ssid);
2469 }
2470
2471 EXIT();
2472 return status;
2473}
2474
2475
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302476static int wlan_hdd_cfg80211_change_beacon(struct wiphy *wiphy,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002477 struct net_device *dev,
2478 struct cfg80211_beacon_data *params)
2479{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302480 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302481 hdd_context_t *pHddCtx;
2482 int status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002483
2484 ENTER();
2485
2486 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
2487 __func__, pAdapter->device_mode);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302488
2489 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2490 status = wlan_hdd_validate_context(pHddCtx);
2491
2492 if (0 != status)
Madan Mohan Koyyalamudib2c36892012-10-18 20:52:38 -07002493 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302494 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2495 "%s: HDD context is not valid", __func__);
2496 return status;
Madan Mohan Koyyalamudib2c36892012-10-18 20:52:38 -07002497 }
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002498
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302499 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002500 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302501 )
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002502 {
2503 beacon_data_t *old,*new;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302504
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002505 old = pAdapter->sessionCtx.ap.beacon;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302506
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002507 if (!old)
2508 return -ENOENT;
2509
2510 status = wlan_hdd_cfg80211_alloc_new_beacon(pAdapter, &new, params, 0);
2511
2512 if(status != VOS_STATUS_SUCCESS) {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302513 hddLog(VOS_TRACE_LEVEL_FATAL,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002514 "%s: Error!!! Allocating the new beacon\n",__func__);
2515 return -EINVAL;
2516 }
2517
2518 pAdapter->sessionCtx.ap.beacon = new;
2519
2520 status = wlan_hdd_cfg80211_start_bss(pAdapter, params, NULL, 0, 0);
2521 }
2522
2523 EXIT();
2524 return status;
2525}
2526
2527#endif //(LINUX_VERSION_CODE > KERNEL_VERSION(3,3,0))
2528
Jeff Johnson295189b2012-06-20 16:38:30 -07002529
2530static int wlan_hdd_cfg80211_change_bss (struct wiphy *wiphy,
2531 struct net_device *dev,
2532 struct bss_parameters *params)
2533{
2534 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
2535
2536 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302537
Jeff Johnson295189b2012-06-20 16:38:30 -07002538 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
2539 __func__,pAdapter->device_mode);
2540
2541 if((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002542 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302543 )
Jeff Johnson295189b2012-06-20 16:38:30 -07002544 {
2545 /* ap_isolate == -1 means that in change bss, upper layer doesn't
2546 * want to update this parameter */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302547 if (-1 != params->ap_isolate)
Jeff Johnson295189b2012-06-20 16:38:30 -07002548 {
2549 pAdapter->sessionCtx.ap.apDisableIntraBssFwd = !!params->ap_isolate;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302550 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002551 }
2552
2553 EXIT();
2554 return 0;
2555}
2556
2557/*
2558 * FUNCTION: wlan_hdd_cfg80211_change_iface
2559 * This function is used to set the interface type (INFRASTRUCTURE/ADHOC)
2560 */
2561int wlan_hdd_cfg80211_change_iface( struct wiphy *wiphy,
2562 struct net_device *ndev,
2563 enum nl80211_iftype type,
2564 u32 *flags,
2565 struct vif_params *params
2566 )
2567{
2568 struct wireless_dev *wdev;
2569 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
2570 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
Mohit Khanna0f232092012-09-11 14:46:08 -07002571 hdd_adapter_t *pP2pAdapter = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07002572 tCsrRoamProfile *pRoamProfile = NULL;
2573 eCsrRoamBssType LastBSSType;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302574 hdd_config_t *pConfig = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07002575 eMib_dot11DesiredBssType connectedBssType;
2576 VOS_STATUS status;
2577
2578 ENTER();
2579
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302580 status = wlan_hdd_validate_context(pHddCtx);
2581
2582 if (0 != status)
Jeff Johnson295189b2012-06-20 16:38:30 -07002583 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302584 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2585 "%s: HDD context is not valid", __func__);
2586 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07002587 }
2588
2589 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
2590 __func__, pAdapter->device_mode);
2591
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302592 pConfig = pHddCtx->cfg_ini;
Jeff Johnson295189b2012-06-20 16:38:30 -07002593 wdev = ndev->ieee80211_ptr;
2594
2595#ifdef WLAN_BTAMP_FEATURE
2596 if((NL80211_IFTYPE_P2P_CLIENT == type)||
2597 (NL80211_IFTYPE_ADHOC == type)||
2598 (NL80211_IFTYPE_AP == type)||
2599 (NL80211_IFTYPE_P2P_GO == type))
2600 {
2601 pHddCtx->isAmpAllowed = VOS_FALSE;
2602 // stop AMP traffic
2603 status = WLANBAP_StopAmp();
2604 if(VOS_STATUS_SUCCESS != status )
2605 {
2606 pHddCtx->isAmpAllowed = VOS_TRUE;
2607 hddLog(VOS_TRACE_LEVEL_FATAL,
2608 "%s: Failed to stop AMP", __func__);
2609 return -EINVAL;
2610 }
2611 }
2612#endif //WLAN_BTAMP_FEATURE
2613 /* Reset the current device mode bit mask*/
2614 wlan_hdd_clear_concurrency_mode(pHddCtx, pAdapter->device_mode);
2615
2616 if( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Jeff Johnson295189b2012-06-20 16:38:30 -07002617 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Jeff Johnsone7245742012-09-05 17:12:55 -07002618 || (pAdapter->device_mode == WLAN_HDD_P2P_DEVICE)
Jeff Johnson295189b2012-06-20 16:38:30 -07002619 )
2620 {
2621 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
2622 pRoamProfile = &pWextState->roamProfile;
2623 LastBSSType = pRoamProfile->BSSType;
2624
2625 switch (type)
2626 {
2627 case NL80211_IFTYPE_STATION:
Jeff Johnson295189b2012-06-20 16:38:30 -07002628 case NL80211_IFTYPE_P2P_CLIENT:
Jeff Johnson295189b2012-06-20 16:38:30 -07002629 hddLog(VOS_TRACE_LEVEL_INFO,
2630 "%s: setting interface Type to INFRASTRUCTURE", __func__);
2631 pRoamProfile->BSSType = eCSR_BSS_TYPE_INFRASTRUCTURE;
Jeff Johnsone7245742012-09-05 17:12:55 -07002632#ifdef WLAN_FEATURE_11AC
2633 if(pConfig->dot11Mode == eHDD_DOT11_MODE_AUTO)
2634 {
2635 pConfig->dot11Mode = eHDD_DOT11_MODE_11ac;
2636 }
2637#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302638 pRoamProfile->phyMode =
Jeff Johnsone7245742012-09-05 17:12:55 -07002639 hdd_cfg_xlate_to_csr_phy_mode(pConfig->dot11Mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07002640 wdev->iftype = type;
Gopichand Nakkalaf527dc62012-12-31 16:35:10 -08002641 //Check for sub-string p2p to confirm its a p2p interface
2642 if (NULL != strstr(ndev->name,"p2p"))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302643 {
Gopichand Nakkala864d3552012-12-31 16:08:51 -08002644 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
2645 WLAN_HDD_P2P_DEVICE : WLAN_HDD_P2P_CLIENT;
2646 }
2647 else
2648 {
2649 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
Jeff Johnson295189b2012-06-20 16:38:30 -07002650 WLAN_HDD_INFRA_STATION: WLAN_HDD_P2P_CLIENT;
Gopichand Nakkala864d3552012-12-31 16:08:51 -08002651 }
Madan Mohan Koyyalamudi81746922013-07-17 14:38:51 +05302652#ifdef FEATURE_WLAN_TDLS
2653 /* The open adapter for the p2p shall skip initializations in
2654 * tdls_init if the device mode is WLAN_HDD_P2P_DEVICE, for
2655 * TDLS is supported only on WLAN_HDD_P2P_CLIENT. Hence invoke
2656 * tdls_init when the change_iface sets the device mode to
2657 * WLAN_HDD_P2P_CLIENT.
2658 */
2659
2660 if ( pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
2661 {
2662 if (0 != wlan_hdd_tdls_init (pAdapter))
2663 {
2664 return -EINVAL;
2665 }
2666 }
2667#endif
2668
Jeff Johnson295189b2012-06-20 16:38:30 -07002669 break;
2670 case NL80211_IFTYPE_ADHOC:
2671 hddLog(VOS_TRACE_LEVEL_INFO,
2672 "%s: setting interface Type to ADHOC", __func__);
2673 pRoamProfile->BSSType = eCSR_BSS_TYPE_START_IBSS;
2674 pRoamProfile->phyMode =
2675 hdd_cfg_xlate_to_csr_phy_mode(pConfig->dot11Mode);
Shailender Karmuchia734f332013-04-19 14:02:48 -07002676 pAdapter->device_mode = WLAN_HDD_IBSS;
Jeff Johnson295189b2012-06-20 16:38:30 -07002677 wdev->iftype = type;
2678 break;
2679
2680 case NL80211_IFTYPE_AP:
Jeff Johnson295189b2012-06-20 16:38:30 -07002681 case NL80211_IFTYPE_P2P_GO:
Jeff Johnson295189b2012-06-20 16:38:30 -07002682 {
2683 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
2684 "%s: setting interface Type to %s", __func__,
2685 (type == NL80211_IFTYPE_AP) ? "SoftAP" : "P2pGo");
2686
Gopichand Nakkalaf527dc62012-12-31 16:35:10 -08002687 //Cancel any remain on channel for GO mode
2688 if (NL80211_IFTYPE_P2P_GO == type)
2689 {
2690 wlan_hdd_cancel_existing_remain_on_channel(pAdapter);
2691 }
Mohit Khanna0f232092012-09-11 14:46:08 -07002692 if (NL80211_IFTYPE_AP == type)
2693 {
2694 /* As Loading WLAN Driver one interface being created for p2p device
2695 * address. This will take one HW STA and the max number of clients
2696 * that can connect to softAP will be reduced by one. so while changing
2697 * the interface type to NL80211_IFTYPE_AP (SoftAP) remove p2p0
2698 * interface as it is not required in SoftAP mode.
2699 */
2700
2701 // Get P2P Adapter
2702 pP2pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_P2P_DEVICE);
2703
2704 if (pP2pAdapter)
2705 {
2706 hdd_stop_adapter(pHddCtx, pP2pAdapter);
2707 hdd_deinit_adapter(pHddCtx, pP2pAdapter);
2708 hdd_close_adapter(pHddCtx, pP2pAdapter, VOS_TRUE);
2709 }
2710 }
2711
Jeff Johnson295189b2012-06-20 16:38:30 -07002712 //De-init the adapter.
2713 hdd_stop_adapter( pHddCtx, pAdapter );
2714 hdd_deinit_adapter( pHddCtx, pAdapter );
2715 memset(&pAdapter->sessionCtx, 0, sizeof(pAdapter->sessionCtx));
Jeff Johnson295189b2012-06-20 16:38:30 -07002716 pAdapter->device_mode = (type == NL80211_IFTYPE_AP) ?
2717 WLAN_HDD_SOFTAP : WLAN_HDD_P2P_GO;
Jeff Johnson32d95a32012-09-10 13:15:23 -07002718
2719 //Disable BMPS and IMPS if enabled
2720 //before starting Go
2721 if(WLAN_HDD_P2P_GO == pAdapter->device_mode)
2722 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302723 if(VOS_STATUS_E_FAILURE ==
Jeff Johnson32d95a32012-09-10 13:15:23 -07002724 hdd_disable_bmps_imps(pHddCtx, WLAN_HDD_P2P_GO))
2725 {
2726 //Fail to Exit BMPS
2727 VOS_ASSERT(0);
2728 }
2729 }
2730
Madan Mohan Koyyalamudi3ff2a0b2012-10-15 14:33:46 -07002731 if ((WLAN_HDD_SOFTAP == pAdapter->device_mode) &&
2732 (pConfig->apRandomBssidEnabled))
2733 {
2734 /* To meet Android requirements create a randomized
2735 MAC address of the form 02:1A:11:Fx:xx:xx */
2736 get_random_bytes(&ndev->dev_addr[3], 3);
2737 ndev->dev_addr[0] = 0x02;
2738 ndev->dev_addr[1] = 0x1A;
2739 ndev->dev_addr[2] = 0x11;
2740 ndev->dev_addr[3] |= 0xF0;
2741 memcpy(pAdapter->macAddressCurrent.bytes, ndev->dev_addr,
2742 VOS_MAC_ADDR_SIZE);
2743 pr_info("wlan: Generated HotSpot BSSID "
2744 "%02x:%02x:%02x:%02x:%02x:%02x\n",
2745 ndev->dev_addr[0],
2746 ndev->dev_addr[1],
2747 ndev->dev_addr[2],
2748 ndev->dev_addr[3],
2749 ndev->dev_addr[4],
2750 ndev->dev_addr[5]);
2751 }
2752
Jeff Johnson295189b2012-06-20 16:38:30 -07002753 hdd_set_ap_ops( pAdapter->dev );
2754
2755 status = hdd_init_ap_mode(pAdapter);
2756 if(status != VOS_STATUS_SUCCESS)
2757 {
2758 hddLog(VOS_TRACE_LEVEL_FATAL,
2759 "%s: Error initializing the ap mode", __func__);
2760 return -EINVAL;
2761 }
2762 hdd_set_conparam(1);
2763
Jeff Johnson295189b2012-06-20 16:38:30 -07002764 /*interface type changed update in wiphy structure*/
2765 if(wdev)
2766 {
2767 wdev->iftype = type;
2768 pHddCtx->change_iface = type;
2769 }
2770 else
2771 {
2772 hddLog(VOS_TRACE_LEVEL_ERROR,
2773 "%s: ERROR !!!! Wireless dev is NULL", __func__);
2774 return -EINVAL;
2775 }
2776 goto done;
2777 }
2778
2779 default:
2780 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported interface Type",
2781 __func__);
2782 return -EOPNOTSUPP;
2783 }
2784 }
2785 else if ( (pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002786 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -07002787 )
2788 {
2789 switch(type)
2790 {
2791 case NL80211_IFTYPE_STATION:
Jeff Johnson295189b2012-06-20 16:38:30 -07002792 case NL80211_IFTYPE_P2P_CLIENT:
Jeff Johnson295189b2012-06-20 16:38:30 -07002793 case NL80211_IFTYPE_ADHOC:
Jeff Johnson32d95a32012-09-10 13:15:23 -07002794 hdd_stop_adapter( pHddCtx, pAdapter );
2795 hdd_deinit_adapter( pHddCtx, pAdapter );
Jeff Johnson295189b2012-06-20 16:38:30 -07002796 wdev->iftype = type;
Gopichand Nakkalaf527dc62012-12-31 16:35:10 -08002797 //Check for sub-string p2p to confirm its a p2p interface
2798 if (NULL != strstr(ndev->name,"p2p"))
Gopichand Nakkala864d3552012-12-31 16:08:51 -08002799 {
2800 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
2801 WLAN_HDD_P2P_DEVICE : WLAN_HDD_P2P_CLIENT;
2802 }
2803 else
2804 {
2805 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
Jeff Johnson295189b2012-06-20 16:38:30 -07002806 WLAN_HDD_INFRA_STATION: WLAN_HDD_P2P_CLIENT;
Gopichand Nakkala864d3552012-12-31 16:08:51 -08002807 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002808 hdd_set_conparam(0);
2809 pHddCtx->change_iface = type;
Jeff Johnson295189b2012-06-20 16:38:30 -07002810 memset(&pAdapter->sessionCtx, 0, sizeof(pAdapter->sessionCtx));
2811 hdd_set_station_ops( pAdapter->dev );
2812 status = hdd_init_station_mode( pAdapter );
2813 if( VOS_STATUS_SUCCESS != status )
2814 return -EOPNOTSUPP;
Jeff Johnsone7245742012-09-05 17:12:55 -07002815 /* In case of JB, for P2P-GO, only change interface will be called,
2816 * This is the right place to enable back bmps_imps()
2817 */
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05302818 if (pHddCtx->hdd_wlan_suspended)
2819 {
2820 hdd_set_pwrparams(pHddCtx);
2821 }
Jeff Johnsone7245742012-09-05 17:12:55 -07002822 hdd_enable_bmps_imps(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07002823 goto done;
2824 case NL80211_IFTYPE_AP:
Jeff Johnson295189b2012-06-20 16:38:30 -07002825 case NL80211_IFTYPE_P2P_GO:
Jeff Johnson295189b2012-06-20 16:38:30 -07002826 wdev->iftype = type;
Jeff Johnson295189b2012-06-20 16:38:30 -07002827 pAdapter->device_mode = (type == NL80211_IFTYPE_AP) ?
2828 WLAN_HDD_SOFTAP : WLAN_HDD_P2P_GO;
Jeff Johnson295189b2012-06-20 16:38:30 -07002829 goto done;
2830 default:
2831 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported interface Type",
2832 __func__);
2833 return -EOPNOTSUPP;
2834
2835 }
2836
2837 }
2838 else
2839 {
2840 return -EOPNOTSUPP;
2841 }
2842
2843
2844 if(pRoamProfile)
2845 {
2846 if ( LastBSSType != pRoamProfile->BSSType )
2847 {
2848 /*interface type changed update in wiphy structure*/
2849 wdev->iftype = type;
2850
2851 /*the BSS mode changed, We need to issue disconnect
2852 if connected or in IBSS disconnect state*/
2853 if ( hdd_connGetConnectedBssType(
2854 WLAN_HDD_GET_STATION_CTX_PTR(pAdapter), &connectedBssType ) ||
2855 ( eCSR_BSS_TYPE_START_IBSS == LastBSSType ) )
2856 {
2857 /*need to issue a disconnect to CSR.*/
2858 INIT_COMPLETION(pAdapter->disconnect_comp_var);
2859 if( eHAL_STATUS_SUCCESS ==
2860 sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
2861 pAdapter->sessionId,
2862 eCSR_DISCONNECT_REASON_UNSPECIFIED ) )
2863 {
2864 wait_for_completion_interruptible_timeout(
2865 &pAdapter->disconnect_comp_var,
2866 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
2867 }
2868 }
2869 }
2870 }
2871
2872done:
2873 /*set bitmask based on updated value*/
2874 wlan_hdd_set_concurrency_mode(pHddCtx, pAdapter->device_mode);
Leo Chang6fe1f922013-06-07 19:21:24 -07002875
2876 /* Only STA mode support TM now
2877 * all other mode, TM feature should be disabled */
2878 if ( (pHddCtx->cfg_ini->thermalMitigationEnable) &&
2879 (~VOS_STA & pHddCtx->concurrency_mode) )
2880 {
2881 hddDevTmLevelChangedHandler(pHddCtx->parent_dev, 0);
2882 }
2883
Jeff Johnson295189b2012-06-20 16:38:30 -07002884#ifdef WLAN_BTAMP_FEATURE
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302885 if((NL80211_IFTYPE_STATION == type) && (pHddCtx->concurrency_mode <= 1) &&
Jeff Johnson295189b2012-06-20 16:38:30 -07002886 (pHddCtx->no_of_sessions[WLAN_HDD_INFRA_STATION] <=1))
2887 {
2888 //we are ok to do AMP
2889 pHddCtx->isAmpAllowed = VOS_TRUE;
2890 }
2891#endif //WLAN_BTAMP_FEATURE
2892 EXIT();
2893 return 0;
2894}
2895
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002896#ifdef FEATURE_WLAN_TDLS
2897static int wlan_hdd_tdls_add_station(struct wiphy *wiphy,
2898 struct net_device *dev, u8 *mac, bool update, tCsrStaParams *StaParams)
2899{
2900 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
2901 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
2902 VOS_STATUS status;
Hoonki Lee5305c3a2013-04-29 23:28:59 -07002903 hddTdlsPeer_t *pTdlsPeer;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002904
2905 ENTER();
2906
Gopichand Nakkala838be5d2013-04-10 22:41:51 +05302907 if (NULL == pHddCtx || NULL == pHddCtx->cfg_ini)
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002908 {
2909 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2910 "Invalid arguments");
2911 return -EINVAL;
2912 }
Hoonki Lee27511902013-03-14 18:19:06 -07002913
2914 if ((eTDLS_SUPPORT_NOT_ENABLED == pHddCtx->tdls_mode) ||
2915 (eTDLS_SUPPORT_DISABLED == pHddCtx->tdls_mode))
2916 {
2917 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
2918 "%s: TDLS mode is disabled OR not enabled in FW."
2919 MAC_ADDRESS_STR " Request declined.",
2920 __func__, MAC_ADDR_ARRAY(mac));
2921 return -ENOTSUPP;
2922 }
2923
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002924 if (pHddCtx->isLogpInProgress)
2925 {
2926 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2927 "%s:LOGP in Progress. Ignore!!!", __func__);
Gopichand Nakkala05922802013-03-14 12:23:19 -07002928 wlan_hdd_tdls_set_link_status(pAdapter, mac, eTDLS_LINK_IDLE);
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002929 return -EBUSY;
2930 }
2931
Hoonki Lee5305c3a2013-04-29 23:28:59 -07002932 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, mac);
2933
2934 if ( NULL == pTdlsPeer ) {
2935 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
2936 "%s: " MAC_ADDRESS_STR " (update %d) not exist. return invalid",
2937 __func__, MAC_ADDR_ARRAY(mac), update);
2938 return -EINVAL;
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002939 }
Hoonki Lee5305c3a2013-04-29 23:28:59 -07002940
2941 /* in add station, we accept existing valid staId if there is */
2942 if ((0 == update) &&
2943 ((pTdlsPeer->link_status >= eTDLS_LINK_CONNECTING) ||
2944 (TDLS_STA_INDEX_VALID(pTdlsPeer->staId))))
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07002945 {
Hoonki Lee5305c3a2013-04-29 23:28:59 -07002946 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07002947 "%s: " MAC_ADDRESS_STR
Hoonki Lee5305c3a2013-04-29 23:28:59 -07002948 " link_status %d. staId %d. add station ignored.",
2949 __func__, MAC_ADDR_ARRAY(mac), pTdlsPeer->link_status, pTdlsPeer->staId);
2950 return 0;
2951 }
2952 /* in change station, we accept only when staId is valid */
2953 if ((1 == update) &&
2954 ((pTdlsPeer->link_status > eTDLS_LINK_CONNECTING) ||
2955 (!TDLS_STA_INDEX_VALID(pTdlsPeer->staId))))
2956 {
2957 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
2958 "%s: " MAC_ADDRESS_STR
2959 " link status %d. staId %d. change station %s.",
2960 __func__, MAC_ADDR_ARRAY(mac), pTdlsPeer->link_status, pTdlsPeer->staId,
2961 (TDLS_STA_INDEX_VALID(pTdlsPeer->staId)) ? "ignored" : "declined");
2962 return (TDLS_STA_INDEX_VALID(pTdlsPeer->staId)) ? 0 : -EPERM;
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07002963 }
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002964
2965 /* when others are on-going, we want to change link_status to idle */
Hoonki Leefb8df672013-04-10 18:20:34 -07002966 if (NULL != wlan_hdd_tdls_is_progress(pHddCtx, mac, TRUE, TRUE))
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002967 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07002968 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2969 "%s: " MAC_ADDRESS_STR
2970 " TDLS setup is ongoing. Request declined.",
2971 __func__, MAC_ADDR_ARRAY(mac));
Gopichand Nakkala05922802013-03-14 12:23:19 -07002972 goto error;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002973 }
2974
2975 /* first to check if we reached to maximum supported TDLS peer.
2976 TODO: for now, return -EPERM looks working fine,
2977 but need to check if any other errno fit into this category.*/
2978 if (HDD_MAX_NUM_TDLS_STA <= wlan_hdd_tdlsConnectedPeers(pAdapter))
2979 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07002980 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2981 "%s: " MAC_ADDRESS_STR
2982 " TDLS Max peer already connected. Request declined.",
2983 __func__, MAC_ADDR_ARRAY(mac));
Gopichand Nakkala05922802013-03-14 12:23:19 -07002984 goto error;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002985 }
2986 else
2987 {
2988 hddTdlsPeer_t *pTdlsPeer;
2989 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, mac);
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07002990 if (pTdlsPeer && TDLS_IS_CONNECTED(pTdlsPeer))
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002991 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07002992 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2993 "%s: " MAC_ADDRESS_STR " already connected. Request declined.",
2994 __func__, MAC_ADDR_ARRAY(mac));
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002995 return -EPERM;
2996 }
2997 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07002998 if (0 == update)
2999 wlan_hdd_tdls_set_link_status(pAdapter, mac, eTDLS_LINK_CONNECTING);
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003000
Jeff Johnsond75fe012013-04-06 10:53:06 -07003001 /* debug code */
Gopichand Nakkala838be5d2013-04-10 22:41:51 +05303002 if (NULL != StaParams)
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003003 {
3004 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3005 "%s: TDLS Peer Parameters.", __func__);
Hoonki Lee66b75f32013-04-16 18:30:07 -07003006 if(StaParams->htcap_present)
3007 {
3008 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3009 "ht_capa->cap_info: %0x", StaParams->HTCap.capInfo);
3010 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3011 "ht_capa->extended_capabilities: %0x",
3012 StaParams->HTCap.extendedHtCapInfo);
3013 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003014 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3015 "params->capability: %0x",StaParams->capability);
3016 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3017 "params->ext_capab_len: %0x",StaParams->extn_capability);
Hoonki Lee66b75f32013-04-16 18:30:07 -07003018 if(StaParams->vhtcap_present)
3019 {
3020 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3021 "rxMcsMap %x rxHighest %x txMcsMap %x txHighest %x",
3022 StaParams->VHTCap.suppMcs.rxMcsMap, StaParams->VHTCap.suppMcs.rxHighest,
3023 StaParams->VHTCap.suppMcs.txMcsMap, StaParams->VHTCap.suppMcs.txHighest);
3024 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003025 {
3026 int i = 0;
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003027 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "Supported rates:");
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003028 for (i = 0; i < sizeof(StaParams->supported_rates); i++)
3029 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3030 "[%d]: %x ", i, StaParams->supported_rates[i]);
3031 }
Jeff Johnsond75fe012013-04-06 10:53:06 -07003032 } /* end debug code */
Gopichand Nakkala838be5d2013-04-10 22:41:51 +05303033 else if ((1 == update) && (NULL == StaParams))
3034 {
3035 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3036 "%s : update is true, but staParams is NULL. Error!", __func__);
3037 return -EPERM;
3038 }
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003039
3040 INIT_COMPLETION(pAdapter->tdls_add_station_comp);
3041
3042 if (!update)
3043 {
3044 status = sme_AddTdlsPeerSta(WLAN_HDD_GET_HAL_CTX(pAdapter),
3045 pAdapter->sessionId, mac);
3046 }
3047 else
3048 {
3049 status = sme_ChangeTdlsPeerSta(WLAN_HDD_GET_HAL_CTX(pAdapter),
3050 pAdapter->sessionId, mac, StaParams);
3051 }
3052
3053 status = wait_for_completion_interruptible_timeout(&pAdapter->tdls_add_station_comp,
3054 msecs_to_jiffies(WAIT_TIME_TDLS_ADD_STA));
3055
3056 if (!status)
3057 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07003058 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003059 "%s: timeout waiting for tdls add station indication",
3060 __func__);
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07003061 return -EPERM;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003062 }
3063 if ( eHAL_STATUS_SUCCESS != pAdapter->tdlsAddStaStatus)
3064 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07003065 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003066 "%s: Add Station is unsucessful", __func__);
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07003067 return -EPERM;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003068 }
3069
3070 return 0;
Gopichand Nakkala05922802013-03-14 12:23:19 -07003071
3072error:
3073 wlan_hdd_tdls_set_link_status(pAdapter, mac, eTDLS_LINK_IDLE);
3074 return -EPERM;
3075
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003076}
3077#endif
3078
Jeff Johnson295189b2012-06-20 16:38:30 -07003079static int wlan_hdd_change_station(struct wiphy *wiphy,
3080 struct net_device *dev,
3081 u8 *mac,
3082 struct station_parameters *params)
3083{
3084 VOS_STATUS status = VOS_STATUS_SUCCESS;
3085 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Gopichand Nakkala29149562013-05-10 21:43:41 +05303086 hdd_context_t *pHddCtx;
3087 hdd_station_ctx_t *pHddStaCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07003088 v_MACADDR_t STAMacAddress;
Gopichand Nakkalab0856222013-03-12 22:39:05 -07003089#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003090 tCsrStaParams StaParams = {0};
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003091 tANI_U8 isBufSta = 0;
Gopichand Nakkalab0856222013-03-12 22:39:05 -07003092#endif
Jeff Johnsone7245742012-09-05 17:12:55 -07003093 ENTER();
3094
Gopichand Nakkala29149562013-05-10 21:43:41 +05303095 if ((NULL == pAdapter))
3096 {
3097 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
3098 "invalid adapter ");
3099 return -EINVAL;
3100 }
3101
3102 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
3103 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3104
3105 if ((NULL == pHddCtx) || (NULL == pHddStaCtx))
3106 {
3107 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
3108 "invalid HDD state or HDD station context");
3109 return -EINVAL;
3110 }
3111
3112 if (pHddCtx->isLogpInProgress)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003113 {
3114 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3115 "%s:LOGP in Progress. Ignore!!!", __func__);
3116 return -EAGAIN;
3117 }
3118
Jeff Johnson295189b2012-06-20 16:38:30 -07003119 vos_mem_copy(STAMacAddress.bytes, mac, sizeof(v_MACADDR_t));
3120
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003121 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
3122 || (pAdapter->device_mode == WLAN_HDD_P2P_GO))
Jeff Johnson295189b2012-06-20 16:38:30 -07003123 {
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003124 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED))
Jeff Johnson295189b2012-06-20 16:38:30 -07003125 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303126 status = hdd_softap_change_STA_state( pAdapter, &STAMacAddress,
Jeff Johnson295189b2012-06-20 16:38:30 -07003127 WLANTL_STA_AUTHENTICATED);
3128
Gopichand Nakkala29149562013-05-10 21:43:41 +05303129 if (status != VOS_STATUS_SUCCESS)
3130 {
3131 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3132 "%s: Not able to change TL state to AUTHENTICATED", __func__);
3133 return -EINVAL;
3134 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003135 }
3136 }
Hoonki Leea6d49be2013-04-05 09:43:25 -07003137 else if ((pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
3138 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)) {
Gopichand Nakkala29149562013-05-10 21:43:41 +05303139#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003140 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
3141 StaParams.capability = params->capability;
3142 StaParams.uapsd_queues = params->uapsd_queues;
3143 StaParams.max_sp = params->max_sp;
3144
3145 if (0 != params->ext_capab_len)
3146 vos_mem_copy(StaParams.extn_capability, params->ext_capab,
3147 sizeof(StaParams.extn_capability));
3148
3149 if (NULL != params->ht_capa)
Hoonki Lee66b75f32013-04-16 18:30:07 -07003150 {
3151 StaParams.htcap_present = 1;
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003152 vos_mem_copy(&StaParams.HTCap, params->ht_capa, sizeof(tSirHTCap));
Hoonki Lee66b75f32013-04-16 18:30:07 -07003153 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003154
3155 StaParams.supported_rates_len = params->supported_rates_len;
3156
3157 /* Note : The Maximum sizeof supported_rates sent by the Supplicant is 32.
3158 * The supported_rates array , for all the structures propogating till Add Sta
3159 * to the firmware has to be modified , if the supplicant (ieee80211) is
3160 * modified to send more rates.
3161 */
3162
3163 /* To avoid Data Currption , set to max length to SIR_MAC_MAX_SUPP_RATES
3164 */
3165 if (StaParams.supported_rates_len > SIR_MAC_MAX_SUPP_RATES)
3166 StaParams.supported_rates_len = SIR_MAC_MAX_SUPP_RATES;
3167
3168 if (0 != StaParams.supported_rates_len) {
3169 int i = 0;
3170 vos_mem_copy(StaParams.supported_rates, params->supported_rates,
3171 StaParams.supported_rates_len);
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003172 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003173 "Supported Rates with Length %d", StaParams.supported_rates_len);
3174 for (i=0; i < StaParams.supported_rates_len; i++)
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003175 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003176 "[%d]: %0x", i, StaParams.supported_rates[i]);
3177 }
3178
3179 if (NULL != params->vht_capa)
Hoonki Lee66b75f32013-04-16 18:30:07 -07003180 {
3181 StaParams.vhtcap_present = 1;
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003182 vos_mem_copy(&StaParams.VHTCap, params->vht_capa, sizeof(tSirVHTCap));
Hoonki Lee66b75f32013-04-16 18:30:07 -07003183 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003184
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003185 if (0 != params->ext_capab_len ) {
3186 /*Define A Macro : TODO Sunil*/
3187 if ((1<<4) & StaParams.extn_capability[3]) {
3188 isBufSta = 1;
3189 }
3190 }
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05303191 status = wlan_hdd_tdls_set_peer_caps( pAdapter, mac, params->uapsd_queues,
3192 params->max_sp, isBufSta);
3193 if (VOS_STATUS_SUCCESS != status) {
3194 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3195 "%s: wlan_hdd_tdls_set_peer_caps failed!", __func__);
3196 return -EINVAL;
3197 }
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003198 status = wlan_hdd_tdls_add_station(wiphy, dev, mac, 1, &StaParams);
3199
3200 if (VOS_STATUS_SUCCESS != status) {
3201 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3202 "%s: sme_ChangeTdlsPeerSta failed!", __func__);
3203 return -EINVAL;
3204 }
3205 }
Gopichand Nakkalab0856222013-03-12 22:39:05 -07003206#endif
Gopichand Nakkala6239acd2013-06-14 14:48:00 +05303207 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003208 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07003209 return status;
3210}
3211
3212/*
Jeff Johnson295189b2012-06-20 16:38:30 -07003213 * FUNCTION: wlan_hdd_cfg80211_add_key
3214 * This function is used to initialize the key information
3215 */
3216#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003217static int wlan_hdd_cfg80211_add_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003218 struct net_device *ndev,
3219 u8 key_index, bool pairwise,
3220 const u8 *mac_addr,
3221 struct key_params *params
3222 )
3223#else
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003224static int wlan_hdd_cfg80211_add_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003225 struct net_device *ndev,
3226 u8 key_index, const u8 *mac_addr,
3227 struct key_params *params
3228 )
3229#endif
3230{
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003231 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Jeff Johnson295189b2012-06-20 16:38:30 -07003232 tCsrRoamSetKey setKey;
3233 u8 groupmacaddr[WNI_CFG_BSSID_LEN] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303234 int status;
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003235 v_U32_t roamId= 0xFF;
3236 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
Jeff Johnson295189b2012-06-20 16:38:30 -07003237 hdd_hostapd_state_t *pHostapdState;
3238 VOS_STATUS vos_status;
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003239 eHalStatus halStatus;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303240 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07003241
3242 ENTER();
3243
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303244 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
3245 status = wlan_hdd_validate_context(pHddCtx);
3246
3247 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003248 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303249 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3250 "%s: HDD context is not valid", __func__);
3251 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003252 }
3253
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003254 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
3255 __func__, pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07003256
3257 if (CSR_MAX_NUM_KEY <= key_index)
3258 {
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003259 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key index %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07003260 key_index);
3261
3262 return -EINVAL;
3263 }
3264
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003265 if (CSR_MAX_KEY_LEN < params->key_len)
3266 {
3267 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key length %d", __func__,
3268 params->key_len);
3269
3270 return -EINVAL;
3271 }
3272
3273 hddLog(VOS_TRACE_LEVEL_INFO,
3274 "%s: called with key index = %d & key length %d",
3275 __func__, key_index, params->key_len);
Jeff Johnson295189b2012-06-20 16:38:30 -07003276
3277 /*extract key idx, key len and key*/
3278 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
3279 setKey.keyId = key_index;
3280 setKey.keyLength = params->key_len;
3281 vos_mem_copy(&setKey.Key[0],params->key, params->key_len);
3282
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003283 switch (params->cipher)
Jeff Johnson295189b2012-06-20 16:38:30 -07003284 {
3285 case WLAN_CIPHER_SUITE_WEP40:
3286 setKey.encType = eCSR_ENCRYPT_TYPE_WEP40_STATICKEY;
3287 break;
3288
3289 case WLAN_CIPHER_SUITE_WEP104:
3290 setKey.encType = eCSR_ENCRYPT_TYPE_WEP104_STATICKEY;
3291 break;
3292
3293 case WLAN_CIPHER_SUITE_TKIP:
3294 {
3295 u8 *pKey = &setKey.Key[0];
3296 setKey.encType = eCSR_ENCRYPT_TYPE_TKIP;
3297
3298 vos_mem_zero(pKey, CSR_MAX_KEY_LEN);
3299
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003300 /*Supplicant sends the 32bytes key in this order
Jeff Johnson295189b2012-06-20 16:38:30 -07003301
3302 |--------------|----------|----------|
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003303 | Tk1 |TX-MIC | RX Mic |
Jeff Johnson295189b2012-06-20 16:38:30 -07003304 |--------------|----------|----------|
3305 <---16bytes---><--8bytes--><--8bytes-->
3306
3307 */
3308 /*Sme expects the 32 bytes key to be in the below order
3309
3310 |--------------|----------|----------|
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003311 | Tk1 |RX-MIC | TX Mic |
Jeff Johnson295189b2012-06-20 16:38:30 -07003312 |--------------|----------|----------|
3313 <---16bytes---><--8bytes--><--8bytes-->
3314 */
3315 /* Copy the Temporal Key 1 (TK1) */
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003316 vos_mem_copy(pKey, params->key, 16);
Jeff Johnson295189b2012-06-20 16:38:30 -07003317
3318 /*Copy the rx mic first*/
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003319 vos_mem_copy(&pKey[16], &params->key[24], 8);
Jeff Johnson295189b2012-06-20 16:38:30 -07003320
3321 /*Copy the tx mic */
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003322 vos_mem_copy(&pKey[24], &params->key[16], 8);
Jeff Johnson295189b2012-06-20 16:38:30 -07003323
3324
3325 break;
3326 }
3327
3328 case WLAN_CIPHER_SUITE_CCMP:
3329 setKey.encType = eCSR_ENCRYPT_TYPE_AES;
3330 break;
3331
3332#ifdef FEATURE_WLAN_WAPI
3333 case WLAN_CIPHER_SUITE_SMS4:
3334 {
3335 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
3336 wlan_hdd_cfg80211_set_key_wapi(pAdapter, key_index, mac_addr,
3337 params->key, params->key_len);
3338 return 0;
3339 }
3340#endif
Chet Lanctot186b5732013-03-18 10:26:30 -07003341
Jeff Johnson295189b2012-06-20 16:38:30 -07003342#ifdef FEATURE_WLAN_CCX
3343 case WLAN_CIPHER_SUITE_KRK:
3344 setKey.encType = eCSR_ENCRYPT_TYPE_KRK;
3345 break;
3346#endif
Chet Lanctot186b5732013-03-18 10:26:30 -07003347
3348#ifdef WLAN_FEATURE_11W
3349 case WLAN_CIPHER_SUITE_AES_CMAC:
3350 setKey.encType = eCSR_ENCRYPT_TYPE_AES_CMAC;
Chet Lanctot3b5158a2013-03-31 16:45:21 -07003351 break;
Chet Lanctot186b5732013-03-18 10:26:30 -07003352#endif
3353
Jeff Johnson295189b2012-06-20 16:38:30 -07003354 default:
3355 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: unsupported cipher type %lu",
3356 __func__, params->cipher);
3357 return -EOPNOTSUPP;
3358 }
3359
3360 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: encryption type %d",
3361 __func__, setKey.encType);
3362
Shailender Karmuchi642e9812013-05-30 14:34:49 -07003363 if (
Jeff Johnson295189b2012-06-20 16:38:30 -07003364#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
3365 (!pairwise)
3366#else
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003367 (!mac_addr || is_broadcast_ether_addr(mac_addr))
Jeff Johnson295189b2012-06-20 16:38:30 -07003368#endif
Shailender Karmuchi642e9812013-05-30 14:34:49 -07003369 )
3370 {
3371 /* set group key*/
3372 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3373 "%s- %d: setting Broadcast key",
3374 __func__, __LINE__);
3375 setKey.keyDirection = eSIR_RX_ONLY;
3376 vos_mem_copy(setKey.peerMac,groupmacaddr,WNI_CFG_BSSID_LEN);
3377 }
3378 else
3379 {
3380 /* set pairwise key*/
3381 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3382 "%s- %d: setting pairwise key",
3383 __func__, __LINE__);
3384 setKey.keyDirection = eSIR_TX_RX;
3385 vos_mem_copy(setKey.peerMac, mac_addr,WNI_CFG_BSSID_LEN);
3386 }
3387 if ((WLAN_HDD_IBSS == pAdapter->device_mode) && !pairwise)
3388 {
3389 setKey.keyDirection = eSIR_TX_RX;
3390 /*Set the group key*/
3391 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
3392 pAdapter->sessionId, &setKey, &roamId );
Jeff Johnson295189b2012-06-20 16:38:30 -07003393
Shailender Karmuchi642e9812013-05-30 14:34:49 -07003394 if ( 0 != status )
3395 {
3396 hddLog(VOS_TRACE_LEVEL_ERROR,
3397 "%s: sme_RoamSetKey failed, returned %d", __func__, status);
3398 return -EINVAL;
3399 }
3400 /*Save the keys here and call sme_RoamSetKey for setting
3401 the PTK after peer joins the IBSS network*/
3402 vos_mem_copy(&pAdapter->sessionCtx.station.ibss_enc_key,
3403 &setKey, sizeof(tCsrRoamSetKey));
3404 return status;
3405 }
Gopichand Nakkala29149562013-05-10 21:43:41 +05303406 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP) ||
3407 (pAdapter->device_mode == WLAN_HDD_P2P_GO))
3408 {
Jeff Johnson295189b2012-06-20 16:38:30 -07003409 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003410 if( pHostapdState->bssState == BSS_START )
3411 {
Jeff Johnson295189b2012-06-20 16:38:30 -07003412 status = WLANSAP_SetKeySta( pVosContext, &setKey);
3413
3414 if ( status != eHAL_STATUS_SUCCESS )
3415 {
3416 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3417 "[%4d] WLANSAP_SetKeySta returned ERROR status= %d",
3418 __LINE__, status );
3419 }
3420 }
3421
3422 /* Saving WEP keys */
3423 else if( eCSR_ENCRYPT_TYPE_WEP40_STATICKEY == setKey.encType ||
3424 eCSR_ENCRYPT_TYPE_WEP104_STATICKEY == setKey.encType )
3425 {
3426 //Save the wep key in ap context. Issue setkey after the BSS is started.
3427 hdd_ap_ctx_t *pAPCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
3428 vos_mem_copy(&pAPCtx->wepKey[key_index], &setKey, sizeof(tCsrRoamSetKey));
3429 }
3430 else
3431 {
3432 //Save the key in ap context. Issue setkey after the BSS is started.
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003433 hdd_ap_ctx_t *pAPCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07003434 vos_mem_copy(&pAPCtx->groupKey, &setKey, sizeof(tCsrRoamSetKey));
3435 }
3436 }
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003437 else if ( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION) ||
3438 (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003439 {
3440 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
3441 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3442
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303443#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
3444 if (!pairwise)
3445#else
3446 if (!mac_addr || is_broadcast_ether_addr(mac_addr))
3447#endif
3448 {
3449 /* set group key*/
3450 if (pHddStaCtx->roam_info.deferKeyComplete)
3451 {
3452 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3453 "%s- %d: Perform Set key Complete",
3454 __func__, __LINE__);
3455 hdd_PerformRoamSetKeyComplete(pAdapter);
3456 }
3457 }
3458
Jeff Johnson295189b2012-06-20 16:38:30 -07003459 pWextState->roamProfile.Keys.KeyLength[key_index] = (u8)params->key_len;
3460
Venkata Prathyusha Kuntupalliee2ce712013-01-17 14:09:24 -08003461 pWextState->roamProfile.Keys.defaultIndex = key_index;
3462
3463
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003464 vos_mem_copy(&pWextState->roamProfile.Keys.KeyMaterial[key_index][0],
Jeff Johnson295189b2012-06-20 16:38:30 -07003465 params->key, params->key_len);
3466
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303467
Jeff Johnson295189b2012-06-20 16:38:30 -07003468 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_SETTING_KEY;
3469
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303470 hddLog(VOS_TRACE_LEVEL_INFO_MED,
Jeff Johnson295189b2012-06-20 16:38:30 -07003471 "%s: set key for peerMac %2x:%2x:%2x:%2x:%2x:%2x, direction %d",
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303472 __func__, setKey.peerMac[0], setKey.peerMac[1],
3473 setKey.peerMac[2], setKey.peerMac[3],
3474 setKey.peerMac[4], setKey.peerMac[5],
Jeff Johnson295189b2012-06-20 16:38:30 -07003475 setKey.keyDirection);
3476
3477 vos_status = wlan_hdd_check_ula_done(pAdapter);
3478
3479 if ( vos_status != VOS_STATUS_SUCCESS )
3480 {
3481 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3482 "[%4d] wlan_hdd_check_ula_done returned ERROR status= %d",
3483 __LINE__, vos_status );
3484
3485 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3486
3487 return -EINVAL;
3488
3489 }
3490
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003491#ifdef WLAN_FEATURE_VOWIFI_11R
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303492 /* The supplicant may attempt to set the PTK once pre-authentication
3493 is done. Save the key in the UMAC and include it in the ADD BSS
3494 request */
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003495 halStatus = sme_FTUpdateKey( WLAN_HDD_GET_HAL_CTX(pAdapter), &setKey);
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303496 if ( halStatus == eHAL_STATUS_FT_PREAUTH_KEY_SUCCESS )
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003497 {
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303498 hddLog(VOS_TRACE_LEVEL_INFO_MED,
3499 "%s: Update PreAuth Key success", __func__);
3500 return 0;
3501 }
3502 else if ( halStatus == eHAL_STATUS_FT_PREAUTH_KEY_FAILED )
3503 {
3504 hddLog(VOS_TRACE_LEVEL_ERROR,
3505 "%s: Update PreAuth Key failed", __func__);
Gopichand Nakkalad7d13652013-02-15 01:48:00 +05303506 return -EINVAL;
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003507 }
3508#endif /* WLAN_FEATURE_VOWIFI_11R */
Jeff Johnson295189b2012-06-20 16:38:30 -07003509
3510 /* issue set key request to SME*/
3511 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
3512 pAdapter->sessionId, &setKey, &roamId );
3513
3514 if ( 0 != status )
3515 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303516 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07003517 "%s: sme_RoamSetKey failed, returned %d", __func__, status);
3518 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3519 return -EINVAL;
3520 }
3521
3522
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303523 /* in case of IBSS as there was no information available about WEP keys during
3524 * IBSS join, group key intialized with NULL key, so re-initialize group key
Jeff Johnson295189b2012-06-20 16:38:30 -07003525 * with correct value*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303526 if ( (eCSR_BSS_TYPE_START_IBSS == pWextState->roamProfile.BSSType) &&
3527 !( ( IW_AUTH_KEY_MGMT_802_1X
3528 == (pWextState->authKeyMgmt & IW_AUTH_KEY_MGMT_802_1X))
Jeff Johnson295189b2012-06-20 16:38:30 -07003529 && (eCSR_AUTH_TYPE_OPEN_SYSTEM == pHddStaCtx->conn_info.authType)
3530 )
3531 &&
3532 ( (WLAN_CIPHER_SUITE_WEP40 == params->cipher)
3533 || (WLAN_CIPHER_SUITE_WEP104 == params->cipher)
3534 )
3535 )
3536 {
3537 setKey.keyDirection = eSIR_RX_ONLY;
3538 vos_mem_copy(setKey.peerMac,groupmacaddr,WNI_CFG_BSSID_LEN);
3539
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303540 hddLog(VOS_TRACE_LEVEL_INFO_MED,
Jeff Johnson295189b2012-06-20 16:38:30 -07003541 "%s: set key peerMac %2x:%2x:%2x:%2x:%2x:%2x, direction %d",
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303542 __func__, setKey.peerMac[0], setKey.peerMac[1],
3543 setKey.peerMac[2], setKey.peerMac[3],
3544 setKey.peerMac[4], setKey.peerMac[5],
Jeff Johnson295189b2012-06-20 16:38:30 -07003545 setKey.keyDirection);
3546
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303547 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07003548 pAdapter->sessionId, &setKey, &roamId );
3549
3550 if ( 0 != status )
3551 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303552 hddLog(VOS_TRACE_LEVEL_ERROR,
3553 "%s: sme_RoamSetKey failed for group key (IBSS), returned %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07003554 __func__, status);
3555 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3556 return -EINVAL;
3557 }
3558 }
3559 }
3560
3561 return 0;
3562}
3563
3564/*
3565 * FUNCTION: wlan_hdd_cfg80211_get_key
3566 * This function is used to get the key information
3567 */
3568#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303569static int wlan_hdd_cfg80211_get_key(
3570 struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003571 struct net_device *ndev,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303572 u8 key_index, bool pairwise,
Jeff Johnson295189b2012-06-20 16:38:30 -07003573 const u8 *mac_addr, void *cookie,
3574 void (*callback)(void *cookie, struct key_params*)
3575 )
3576#else
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303577static int wlan_hdd_cfg80211_get_key(
3578 struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003579 struct net_device *ndev,
3580 u8 key_index, const u8 *mac_addr, void *cookie,
3581 void (*callback)(void *cookie, struct key_params*)
3582 )
3583#endif
3584{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303585 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Jeff Johnson295189b2012-06-20 16:38:30 -07003586 hdd_wext_state_t *pWextState= WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
3587 tCsrRoamProfile *pRoamProfile = &(pWextState->roamProfile);
3588 struct key_params params;
3589
3590 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303591
Jeff Johnson295189b2012-06-20 16:38:30 -07003592 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
3593 __func__,pAdapter->device_mode);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303594
Jeff Johnson295189b2012-06-20 16:38:30 -07003595 memset(&params, 0, sizeof(params));
3596
3597 if (CSR_MAX_NUM_KEY <= key_index)
3598 {
3599 return -EINVAL;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303600 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003601
3602 switch(pRoamProfile->EncryptionType.encryptionType[0])
3603 {
3604 case eCSR_ENCRYPT_TYPE_NONE:
3605 params.cipher = IW_AUTH_CIPHER_NONE;
3606 break;
3607
3608 case eCSR_ENCRYPT_TYPE_WEP40_STATICKEY:
3609 case eCSR_ENCRYPT_TYPE_WEP40:
3610 params.cipher = WLAN_CIPHER_SUITE_WEP40;
3611 break;
3612
3613 case eCSR_ENCRYPT_TYPE_WEP104_STATICKEY:
3614 case eCSR_ENCRYPT_TYPE_WEP104:
3615 params.cipher = WLAN_CIPHER_SUITE_WEP104;
3616 break;
3617
3618 case eCSR_ENCRYPT_TYPE_TKIP:
3619 params.cipher = WLAN_CIPHER_SUITE_TKIP;
3620 break;
3621
3622 case eCSR_ENCRYPT_TYPE_AES:
3623 params.cipher = WLAN_CIPHER_SUITE_AES_CMAC;
3624 break;
3625
3626 default:
3627 params.cipher = IW_AUTH_CIPHER_NONE;
3628 break;
3629 }
3630
3631 params.key_len = pRoamProfile->Keys.KeyLength[key_index];
3632 params.seq_len = 0;
3633 params.seq = NULL;
3634 params.key = &pRoamProfile->Keys.KeyMaterial[key_index][0];
3635 callback(cookie, &params);
3636 return 0;
3637}
3638
3639/*
3640 * FUNCTION: wlan_hdd_cfg80211_del_key
3641 * This function is used to delete the key information
3642 */
3643#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303644static int wlan_hdd_cfg80211_del_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003645 struct net_device *ndev,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303646 u8 key_index,
3647 bool pairwise,
Jeff Johnson295189b2012-06-20 16:38:30 -07003648 const u8 *mac_addr
3649 )
3650#else
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303651static int wlan_hdd_cfg80211_del_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003652 struct net_device *ndev,
3653 u8 key_index,
3654 const u8 *mac_addr
3655 )
3656#endif
3657{
3658 int status = 0;
3659
3660 //This code needs to be revisited. There is sme_removeKey API, we should
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303661 //plan to use that. After the change to use correct index in setkey,
Jeff Johnson295189b2012-06-20 16:38:30 -07003662 //it is observed that this is invalidating peer
3663 //key index whenever re-key is done. This is affecting data link.
3664 //It should be ok to ignore del_key.
3665#if 0
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303666 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
3667 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
Jeff Johnson295189b2012-06-20 16:38:30 -07003668 u8 groupmacaddr[WNI_CFG_BSSID_LEN] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
3669 tCsrRoamSetKey setKey;
3670 v_U32_t roamId= 0xFF;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303671
Jeff Johnson295189b2012-06-20 16:38:30 -07003672 ENTER();
3673
3674 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: device_mode = %d\n",
3675 __func__,pAdapter->device_mode);
3676
3677 if (CSR_MAX_NUM_KEY <= key_index)
3678 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303679 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key index %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07003680 key_index);
3681
3682 return -EINVAL;
3683 }
3684
3685 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
3686 setKey.keyId = key_index;
3687
3688 if (mac_addr)
3689 vos_mem_copy(setKey.peerMac, mac_addr,WNI_CFG_BSSID_LEN);
3690 else
3691 vos_mem_copy(setKey.peerMac, groupmacaddr, WNI_CFG_BSSID_LEN);
3692
3693 setKey.encType = eCSR_ENCRYPT_TYPE_NONE;
3694
3695 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07003696 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303697 )
3698 {
3699
3700 hdd_hostapd_state_t *pHostapdState =
Jeff Johnson295189b2012-06-20 16:38:30 -07003701 WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
3702 if( pHostapdState->bssState == BSS_START)
3703 {
3704 status = WLANSAP_SetKeySta( pVosContext, &setKey);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303705
Jeff Johnson295189b2012-06-20 16:38:30 -07003706 if ( status != eHAL_STATUS_SUCCESS )
3707 {
3708 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3709 "[%4d] WLANSAP_SetKeySta returned ERROR status= %d",
3710 __LINE__, status );
3711 }
3712 }
3713 }
3714 else if ( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303715 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Jeff Johnson295189b2012-06-20 16:38:30 -07003716 )
3717 {
3718 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3719
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303720 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_SETTING_KEY;
3721
3722 hddLog(VOS_TRACE_LEVEL_INFO_MED,
Jeff Johnson295189b2012-06-20 16:38:30 -07003723 "%s: delete key for peerMac %2x:%2x:%2x:%2x:%2x:%2x",
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303724 __func__, setKey.peerMac[0], setKey.peerMac[1],
3725 setKey.peerMac[2], setKey.peerMac[3],
Jeff Johnson295189b2012-06-20 16:38:30 -07003726 setKey.peerMac[4], setKey.peerMac[5]);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303727 if(pAdapter->sessionCtx.station.conn_info.connState ==
3728 eConnectionState_Associated)
Jeff Johnson295189b2012-06-20 16:38:30 -07003729 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303730 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07003731 pAdapter->sessionId, &setKey, &roamId );
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303732
Jeff Johnson295189b2012-06-20 16:38:30 -07003733 if ( 0 != status )
3734 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303735 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07003736 "%s: sme_RoamSetKey failure, returned %d",
3737 __func__, status);
3738 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3739 return -EINVAL;
3740 }
3741 }
3742 }
3743#endif
Jeff Johnsone7245742012-09-05 17:12:55 -07003744 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07003745 return status;
3746}
3747
3748/*
3749 * FUNCTION: wlan_hdd_cfg80211_set_default_key
3750 * This function is used to set the default tx key index
3751 */
3752#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
3753static int wlan_hdd_cfg80211_set_default_key( struct wiphy *wiphy,
3754 struct net_device *ndev,
3755 u8 key_index,
3756 bool unicast, bool multicast)
3757#else
3758static int wlan_hdd_cfg80211_set_default_key( struct wiphy *wiphy,
3759 struct net_device *ndev,
3760 u8 key_index)
3761#endif
3762{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303763 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303764 int status;
Gopichand Nakkala29149562013-05-10 21:43:41 +05303765 hdd_wext_state_t *pWextState;
3766 hdd_station_ctx_t *pHddStaCtx;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303767 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07003768
3769 ENTER();
3770
Gopichand Nakkala29149562013-05-10 21:43:41 +05303771 if ((NULL == pAdapter))
3772 {
3773 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
3774 "invalid adapter");
3775 return -EINVAL;
3776 }
3777
3778 pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
3779 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3780
3781 if ((NULL == pWextState) || (NULL == pHddStaCtx))
3782 {
3783 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
3784 "invalid Wext state or HDD context");
3785 return -EINVAL;
3786 }
3787
Jeff Johnson295189b2012-06-20 16:38:30 -07003788 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d key_index = %d \n",
3789 __func__,pAdapter->device_mode, key_index);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303790
Jeff Johnson295189b2012-06-20 16:38:30 -07003791 if (CSR_MAX_NUM_KEY <= key_index)
3792 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303793 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key index %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07003794 key_index);
3795
3796 return -EINVAL;
3797 }
3798
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303799 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
3800 status = wlan_hdd_validate_context(pHddCtx);
3801
3802 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003803 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303804 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3805 "%s: HDD context is not valid", __func__);
3806 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003807 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303808
Jeff Johnson295189b2012-06-20 16:38:30 -07003809 if ((pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Jeff Johnson295189b2012-06-20 16:38:30 -07003810 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303811 )
Jeff Johnson295189b2012-06-20 16:38:30 -07003812 {
Gopichand Nakkala29149562013-05-10 21:43:41 +05303813 if ( (eCSR_ENCRYPT_TYPE_TKIP !=
Jeff Johnson295189b2012-06-20 16:38:30 -07003814 pWextState->roamProfile.EncryptionType.encryptionType[0]) &&
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303815 (eCSR_ENCRYPT_TYPE_AES !=
Jeff Johnson295189b2012-06-20 16:38:30 -07003816 pWextState->roamProfile.EncryptionType.encryptionType[0])
3817 )
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303818 {
3819 /* if default key index is not same as previous one,
Jeff Johnson295189b2012-06-20 16:38:30 -07003820 * then update the default key index */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303821
Jeff Johnson295189b2012-06-20 16:38:30 -07003822 tCsrRoamSetKey setKey;
3823 v_U32_t roamId= 0xFF;
3824 tCsrKeys *Keys = &pWextState->roamProfile.Keys;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303825
3826 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: default tx key index %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07003827 __func__, key_index);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303828
Jeff Johnson295189b2012-06-20 16:38:30 -07003829 Keys->defaultIndex = (u8)key_index;
3830 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
3831 setKey.keyId = key_index;
3832 setKey.keyLength = Keys->KeyLength[key_index];
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303833
3834 vos_mem_copy(&setKey.Key[0],
3835 &Keys->KeyMaterial[key_index][0],
Jeff Johnson295189b2012-06-20 16:38:30 -07003836 Keys->KeyLength[key_index]);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303837
Gopichand Nakkala29149562013-05-10 21:43:41 +05303838 setKey.keyDirection = eSIR_TX_RX;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303839
3840 vos_mem_copy(setKey.peerMac,
Jeff Johnson295189b2012-06-20 16:38:30 -07003841 &pHddStaCtx->conn_info.bssId[0],
3842 WNI_CFG_BSSID_LEN);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303843
Gopichand Nakkala29149562013-05-10 21:43:41 +05303844 if (Keys->KeyLength[key_index] == CSR_WEP40_KEY_LEN &&
3845 pWextState->roamProfile.EncryptionType.encryptionType[0] ==
3846 eCSR_ENCRYPT_TYPE_WEP104)
3847 {
3848 /*In the case of dynamic wep supplicant hardcodes DWEP type to eCSR_ENCRYPT_TYPE_WEP104
3849 even though ap is configured for WEP-40 encryption. In this canse the key length
3850 is 5 but the encryption type is 104 hence checking the key langht(5) and encryption
3851 type(104) and switching encryption type to 40*/
3852 pWextState->roamProfile.EncryptionType.encryptionType[0] =
3853 eCSR_ENCRYPT_TYPE_WEP40;
3854 pWextState->roamProfile.mcEncryptionType.encryptionType[0] =
3855 eCSR_ENCRYPT_TYPE_WEP40;
3856 }
3857
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303858 setKey.encType =
Jeff Johnson295189b2012-06-20 16:38:30 -07003859 pWextState->roamProfile.EncryptionType.encryptionType[0];
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303860
Jeff Johnson295189b2012-06-20 16:38:30 -07003861 /* issue set key request */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303862 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07003863 pAdapter->sessionId, &setKey, &roamId );
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303864
Jeff Johnson295189b2012-06-20 16:38:30 -07003865 if ( 0 != status )
3866 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303867 hddLog(VOS_TRACE_LEVEL_ERROR,
3868 "%s: sme_RoamSetKey failed, returned %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07003869 status);
3870 return -EINVAL;
3871 }
3872 }
3873 }
3874
3875 /* In SoftAp mode setting key direction for default mode */
3876 else if ( WLAN_HDD_SOFTAP == pAdapter->device_mode )
3877 {
3878 if ( (eCSR_ENCRYPT_TYPE_TKIP !=
3879 pWextState->roamProfile.EncryptionType.encryptionType[0]) &&
3880 (eCSR_ENCRYPT_TYPE_AES !=
3881 pWextState->roamProfile.EncryptionType.encryptionType[0])
3882 )
3883 {
3884 /* Saving key direction for default key index to TX default */
3885 hdd_ap_ctx_t *pAPCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
3886 pAPCtx->wepKey[key_index].keyDirection = eSIR_TX_DEFAULT;
3887 }
3888 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303889
Jeff Johnson295189b2012-06-20 16:38:30 -07003890 return status;
3891}
3892
Jeff Johnson295189b2012-06-20 16:38:30 -07003893/*
3894 * FUNCTION: wlan_hdd_cfg80211_inform_bss
3895 * This function is used to inform the BSS details to nl80211 interface.
3896 */
3897static struct cfg80211_bss* wlan_hdd_cfg80211_inform_bss(
3898 hdd_adapter_t *pAdapter, tCsrRoamConnectedProfile *roamProfile)
3899{
3900 struct net_device *dev = pAdapter->dev;
3901 struct wireless_dev *wdev = dev->ieee80211_ptr;
3902 struct wiphy *wiphy = wdev->wiphy;
3903 tSirBssDescription *pBssDesc = roamProfile->pBssDesc;
3904 int chan_no;
3905 int ie_length;
3906 const char *ie;
3907 unsigned int freq;
3908 struct ieee80211_channel *chan;
3909 int rssi = 0;
3910 struct cfg80211_bss *bss = NULL;
3911
3912 ENTER();
3913
3914 if( NULL == pBssDesc )
3915 {
3916 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: pBssDesc is NULL\n", __func__);
3917 return bss;
3918 }
3919
3920 chan_no = pBssDesc->channelId;
3921 ie_length = GET_IE_LEN_IN_BSS_DESC( pBssDesc->length );
3922 ie = ((ie_length != 0) ? (const char *)&pBssDesc->ieFields: NULL);
3923
3924 if( NULL == ie )
3925 {
3926 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: IE of BSS descriptor is NULL\n", __func__);
3927 return bss;
3928 }
3929
3930#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,38))
3931 if (chan_no <= ARRAY_SIZE(hdd_channels_2_4_GHZ))
3932 {
3933 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_2GHZ);
3934 }
3935 else
3936 {
3937 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_5GHZ);
3938 }
3939#else
3940 freq = ieee80211_channel_to_frequency(chan_no);
3941#endif
3942
3943 chan = __ieee80211_get_channel(wiphy, freq);
3944
3945 bss = cfg80211_get_bss(wiphy, chan, pBssDesc->bssId,
3946 &roamProfile->SSID.ssId[0], roamProfile->SSID.length,
3947 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
3948 if (bss == NULL)
3949 {
3950 rssi = (VOS_MIN ((pBssDesc->rssi + pBssDesc->sinr), 0))*100;
3951
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303952 return (cfg80211_inform_bss(wiphy, chan, pBssDesc->bssId,
3953 le64_to_cpu(*(__le64 *)pBssDesc->timeStamp),
Jeff Johnson295189b2012-06-20 16:38:30 -07003954 pBssDesc->capabilityInfo,
3955 pBssDesc->beaconInterval, ie, ie_length,
3956 rssi, GFP_KERNEL ));
3957}
3958 else
3959 {
3960 return bss;
3961 }
3962}
3963
3964
3965
3966/*
3967 * FUNCTION: wlan_hdd_cfg80211_inform_bss_frame
3968 * This function is used to inform the BSS details to nl80211 interface.
3969 */
3970struct cfg80211_bss*
3971wlan_hdd_cfg80211_inform_bss_frame( hdd_adapter_t *pAdapter,
3972 tSirBssDescription *bss_desc
3973 )
3974{
3975 /*
3976 cfg80211_inform_bss() is not updating ie field of bss entry, if entry
3977 already exists in bss data base of cfg80211 for that particular BSS ID.
3978 Using cfg80211_inform_bss_frame to update the bss entry instead of
3979 cfg80211_inform_bss, But this call expects mgmt packet as input. As of
3980 now there is no possibility to get the mgmt(probe response) frame from PE,
3981 converting bss_desc to ieee80211_mgmt(probe response) and passing to
3982 cfg80211_inform_bss_frame.
3983 */
3984 struct net_device *dev = pAdapter->dev;
3985 struct wireless_dev *wdev = dev->ieee80211_ptr;
3986 struct wiphy *wiphy = wdev->wiphy;
3987 int chan_no = bss_desc->channelId;
Madan Mohan Koyyalamudi86f629e2012-11-09 16:27:29 -08003988#ifdef WLAN_ENABLE_AGEIE_ON_SCAN_RESULTS
3989 qcom_ie_age *qie_age = NULL;
3990 int ie_length = GET_IE_LEN_IN_BSS_DESC( bss_desc->length ) + sizeof(qcom_ie_age);
3991#else
Jeff Johnson295189b2012-06-20 16:38:30 -07003992 int ie_length = GET_IE_LEN_IN_BSS_DESC( bss_desc->length );
Madan Mohan Koyyalamudi86f629e2012-11-09 16:27:29 -08003993#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07003994 const char *ie =
3995 ((ie_length != 0) ? (const char *)&bss_desc->ieFields: NULL);
3996 unsigned int freq;
3997 struct ieee80211_channel *chan;
3998 struct ieee80211_mgmt *mgmt =
3999 kzalloc((sizeof (struct ieee80211_mgmt) + ie_length), GFP_KERNEL);
4000 struct cfg80211_bss *bss_status = NULL;
4001 size_t frame_len = sizeof (struct ieee80211_mgmt) + ie_length;
4002 int rssi = 0;
Jeff Johnsone7245742012-09-05 17:12:55 -07004003#ifdef WLAN_OPEN_SOURCE
4004 struct timespec ts;
4005#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004006
4007 ENTER();
4008
Madan Mohan Koyyalamudi2e5c9142012-11-02 13:17:48 -07004009 if (!mgmt)
4010 return NULL;
4011
Jeff Johnson295189b2012-06-20 16:38:30 -07004012 memcpy(mgmt->bssid, bss_desc->bssId, ETH_ALEN);
Jeff Johnsone7245742012-09-05 17:12:55 -07004013
4014#ifdef WLAN_OPEN_SOURCE
4015 /* Android does not want the timestamp from the frame.
4016 Instead it wants a monotonic increasing value */
4017 get_monotonic_boottime(&ts);
4018 mgmt->u.probe_resp.timestamp =
4019 ((u64)ts.tv_sec * 1000000) + (ts.tv_nsec / 1000);
4020#else
4021 /* keep old behavior for non-open source (for now) */
Jeff Johnson295189b2012-06-20 16:38:30 -07004022 memcpy(&mgmt->u.probe_resp.timestamp, bss_desc->timeStamp,
4023 sizeof (bss_desc->timeStamp));
Jeff Johnsone7245742012-09-05 17:12:55 -07004024
4025#endif
4026
Jeff Johnson295189b2012-06-20 16:38:30 -07004027 mgmt->u.probe_resp.beacon_int = bss_desc->beaconInterval;
4028 mgmt->u.probe_resp.capab_info = bss_desc->capabilityInfo;
Madan Mohan Koyyalamudi86f629e2012-11-09 16:27:29 -08004029
4030#ifdef WLAN_ENABLE_AGEIE_ON_SCAN_RESULTS
4031 /* GPS Requirement: need age ie per entry. Using vendor specific. */
4032 /* Assuming this is the last IE, copy at the end */
4033 ie_length -=sizeof(qcom_ie_age);
4034 qie_age = (qcom_ie_age *)(mgmt->u.probe_resp.variable + ie_length);
4035 qie_age->element_id = QCOM_VENDOR_IE_ID;
4036 qie_age->len = QCOM_VENDOR_IE_AGE_LEN;
4037 qie_age->oui_1 = QCOM_OUI1;
4038 qie_age->oui_2 = QCOM_OUI2;
4039 qie_age->oui_3 = QCOM_OUI3;
4040 qie_age->type = QCOM_VENDOR_IE_AGE_TYPE;
4041 qie_age->age = vos_timer_get_system_ticks() - bss_desc->nReceivedTime;
4042#endif
4043
Jeff Johnson295189b2012-06-20 16:38:30 -07004044 memcpy(mgmt->u.probe_resp.variable, ie, ie_length);
Gopichand Nakkalad908ec82013-05-16 19:32:19 +05304045 if (bss_desc->fProbeRsp)
4046 {
4047 mgmt->frame_control |=
4048 (u16)(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_RESP);
4049 }
4050 else
4051 {
4052 mgmt->frame_control |=
4053 (u16)(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_BEACON);
4054 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004055
4056#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,38))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304057 if (chan_no <= ARRAY_SIZE(hdd_channels_2_4_GHZ) &&
Jeff Johnson295189b2012-06-20 16:38:30 -07004058 (wiphy->bands[IEEE80211_BAND_2GHZ] != NULL))
4059 {
4060 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_2GHZ);
4061 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304062 else if ((chan_no > ARRAY_SIZE(hdd_channels_2_4_GHZ)) &&
Jeff Johnson295189b2012-06-20 16:38:30 -07004063 (wiphy->bands[IEEE80211_BAND_5GHZ] != NULL))
4064
4065 {
4066 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_5GHZ);
4067 }
4068 else
4069 {
4070 kfree(mgmt);
4071 return NULL;
4072 }
4073#else
4074 freq = ieee80211_channel_to_frequency(chan_no);
4075#endif
4076 chan = __ieee80211_get_channel(wiphy, freq);
Leela V Kiran Kumar Reddy90032de2013-01-24 18:33:30 -08004077 /*when the band is changed on the fly using the GUI, three things are done
4078 * 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)
4079 * as part of the scan abort, message willbe queued to PE and we proceed with flushing and changinh the band.
4080 * pe will stop the scanning further and report back the results what ever it had till now by calling the call back function.
4081 * if the time between update band and scandone call back is sufficent enough the band change reflects in SME, SME validates the channels
4082 * and discards the channels correponding to previous band and calls back with zero bss results.
4083 * 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
4084 * all the channels correponding to previous band.this is due to race condition.but those channels are invalid to the new band and so
4085 * this function __ieee80211_get_channel will return NULL.Each time we report scan result with this pointer null warning kernel trace is printed.
4086 * if the scan results contain large number of APs continuosly kernel warning trace is printed and it will lead to apps watch dog bark.
4087 * So drop the bss and continue to next bss.
4088 */
4089 if(chan == NULL)
4090 {
4091 hddLog(VOS_TRACE_LEVEL_INFO, "%s chan pointer is NULL", __func__);
Chilam Ngc4244af2013-04-01 15:37:32 -07004092 kfree(mgmt);
Leela V Kiran Kumar Reddy90032de2013-01-24 18:33:30 -08004093 return NULL;
4094 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004095 /*To keep the rssi icon of the connected AP in the scan window
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304096 *and the rssi icon of the wireless networks in sync
Jeff Johnson295189b2012-06-20 16:38:30 -07004097 * */
4098 if (( eConnectionState_Associated ==
4099 pAdapter->sessionCtx.station.conn_info.connState ) &&
4100 ( VOS_TRUE == vos_mem_compare(bss_desc->bssId,
4101 pAdapter->sessionCtx.station.conn_info.bssId,
4102 WNI_CFG_BSSID_LEN)))
4103 {
4104 /* supplicant takes the signal strength in terms of mBm(100*dBm) */
4105 rssi = (pAdapter->rssi * 100);
4106 }
4107 else
4108 {
4109 rssi = (VOS_MIN ((bss_desc->rssi + bss_desc->sinr), 0))*100;
4110 }
4111
4112 bss_status = cfg80211_inform_bss_frame(wiphy, chan, mgmt,
4113 frame_len, rssi, GFP_KERNEL);
4114 kfree(mgmt);
4115 return bss_status;
4116}
4117
4118/*
4119 * FUNCTION: wlan_hdd_cfg80211_update_bss_db
4120 * This function is used to update the BSS data base of CFG8011
4121 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304122struct cfg80211_bss* wlan_hdd_cfg80211_update_bss_db( hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07004123 tCsrRoamInfo *pRoamInfo
4124 )
4125{
4126 tCsrRoamConnectedProfile roamProfile;
4127 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
4128 struct cfg80211_bss *bss = NULL;
4129
4130 ENTER();
4131
4132 memset(&roamProfile, 0, sizeof(tCsrRoamConnectedProfile));
4133 sme_RoamGetConnectProfile(hHal, pAdapter->sessionId, &roamProfile);
4134
4135 if (NULL != roamProfile.pBssDesc)
4136 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304137 bss = wlan_hdd_cfg80211_inform_bss(pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07004138 &roamProfile);
4139
4140 if (NULL == bss)
4141 {
4142 hddLog(VOS_TRACE_LEVEL_INFO, "%s: cfg80211_inform_bss return NULL",
4143 __func__);
4144 }
4145
4146 sme_RoamFreeConnectProfile(hHal, &roamProfile);
4147 }
4148 else
4149 {
4150 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: roamProfile.pBssDesc is NULL",
4151 __func__);
4152 }
4153 return bss;
4154}
4155
4156/*
4157 * FUNCTION: wlan_hdd_cfg80211_update_bss
4158 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304159static int wlan_hdd_cfg80211_update_bss( struct wiphy *wiphy,
4160 hdd_adapter_t *pAdapter
Jeff Johnson295189b2012-06-20 16:38:30 -07004161 )
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304162{
Jeff Johnson295189b2012-06-20 16:38:30 -07004163 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
4164 tCsrScanResultInfo *pScanResult;
4165 eHalStatus status = 0;
4166 tScanResultHandle pResult;
4167 struct cfg80211_bss *bss_status = NULL;
4168
4169 ENTER();
4170
4171 if ((WLAN_HDD_GET_CTX(pAdapter))->isLogpInProgress)
4172 {
4173 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL, "%s:LOGP in Progress. Ignore!!!",__func__);
4174 return -EAGAIN;
4175 }
4176
4177 /*
4178 * start getting scan results and populate cgf80211 BSS database
4179 */
4180 status = sme_ScanGetResult(hHal, pAdapter->sessionId, NULL, &pResult);
4181
4182 /* no scan results */
4183 if (NULL == pResult)
4184 {
4185 hddLog(VOS_TRACE_LEVEL_INFO, "%s: No scan result\n", __func__);
4186 return status;
4187 }
4188
4189 pScanResult = sme_ScanResultGetFirst(hHal, pResult);
4190
4191 while (pScanResult)
4192 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304193 /*
4194 * cfg80211_inform_bss() is not updating ie field of bss entry, if
4195 * entry already exists in bss data base of cfg80211 for that
4196 * particular BSS ID. Using cfg80211_inform_bss_frame to update the
4197 * bss entry instead of cfg80211_inform_bss, But this call expects
4198 * mgmt packet as input. As of now there is no possibility to get
4199 * the mgmt(probe response) frame from PE, converting bss_desc to
Jeff Johnson295189b2012-06-20 16:38:30 -07004200 * ieee80211_mgmt(probe response) and passing to c
4201 * fg80211_inform_bss_frame.
4202 * */
4203
4204 bss_status = wlan_hdd_cfg80211_inform_bss_frame(pAdapter,
4205 &pScanResult->BssDescriptor);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304206
Jeff Johnson295189b2012-06-20 16:38:30 -07004207
4208 if (NULL == bss_status)
4209 {
4210 hddLog(VOS_TRACE_LEVEL_INFO,
4211 "%s: NULL returned by cfg80211_inform_bss\n", __func__);
4212 }
4213 else
4214 {
Yue Maf49ba872013-08-19 12:04:25 -07004215 cfg80211_put_bss(
4216#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,9,0))
4217 wiphy,
4218#endif
4219 bss_status);
Jeff Johnson295189b2012-06-20 16:38:30 -07004220 }
4221
4222 pScanResult = sme_ScanResultGetNext(hHal, pResult);
4223 }
4224
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304225 sme_ScanResultPurge(hHal, pResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07004226
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304227 return 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07004228}
4229
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004230void
4231hddPrintMacAddr(tCsrBssid macAddr, tANI_U8 logLevel)
4232{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304233 VOS_TRACE(VOS_MODULE_ID_HDD, logLevel,
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07004234 "%02X:%02X:%02X:%02X:%02X:%02X\n",
4235 macAddr[0], macAddr[1], macAddr[2], macAddr[3], macAddr[4],
4236 macAddr[5]);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004237} /****** end hddPrintMacAddr() ******/
4238
4239void
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07004240hddPrintPmkId(tANI_U8 *pmkId, tANI_U8 logLevel)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004241{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304242 VOS_TRACE(VOS_MODULE_ID_HDD, logLevel,
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07004243 "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
4244 pmkId[0], pmkId[1], pmkId[2], pmkId[3], pmkId[4],
4245 pmkId[5], pmkId[6], pmkId[7], pmkId[8], pmkId[9], pmkId[10],
4246 pmkId[11], pmkId[12], pmkId[13], pmkId[14], pmkId[15]);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004247} /****** end hddPrintPmkId() ******/
4248
4249//hddPrintMacAddr(tCsrBssid macAddr, tANI_U8 logLevel);
4250//hddPrintMacAddr(macAddr, VOS_TRACE_LEVEL_FATAL);
4251
4252//void sirDumpBuf(tpAniSirGlobal pMac, tANI_U8 modId, tANI_U32 level, tANI_U8 *buf, tANI_U32 size);
4253//sirDumpBuf(pMac, VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL, pmkid, 16);
4254
4255#define dump_bssid(bssid) \
4256 { \
Jeff Johnsone7245742012-09-05 17:12:55 -07004257 hddLog(VOS_TRACE_LEVEL_INFO, "BSSID (MAC) address:\t"); \
4258 hddPrintMacAddr(bssid, VOS_TRACE_LEVEL_INFO);\
4259 hddLog(VOS_TRACE_LEVEL_INFO, "\n"); \
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004260 }
4261
4262#define dump_pmkid(pMac, pmkid) \
4263 { \
Jeff Johnsone7245742012-09-05 17:12:55 -07004264 hddLog(VOS_TRACE_LEVEL_INFO, "PMKSA-ID:\t"); \
4265 hddPrintPmkId(pmkid, VOS_TRACE_LEVEL_INFO);\
4266 hddLog(VOS_TRACE_LEVEL_INFO, "\n"); \
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004267 }
4268
Madan Mohan Koyyalamudi1b4afb02012-10-22 15:25:16 -07004269#if defined(FEATURE_WLAN_LFR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004270/*
4271 * FUNCTION: wlan_hdd_cfg80211_pmksa_candidate_notify
4272 * This function is used to notify the supplicant of a new PMKSA candidate.
4273 */
4274int wlan_hdd_cfg80211_pmksa_candidate_notify(
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304275 hdd_adapter_t *pAdapter, tCsrRoamInfo *pRoamInfo,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004276 int index, bool preauth )
4277{
Jeff Johnsone7245742012-09-05 17:12:55 -07004278#ifdef FEATURE_WLAN_OKC
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004279 struct net_device *dev = pAdapter->dev;
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004280 hdd_context_t *pHddCtx = (hdd_context_t*)pAdapter->pHddCtx;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004281
4282 ENTER();
Jeff Johnsone7245742012-09-05 17:12:55 -07004283 hddLog(VOS_TRACE_LEVEL_INFO, "%s is going to notify supplicant of:", __func__);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004284
4285 if( NULL == pRoamInfo )
4286 {
4287 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: pRoamInfo is NULL\n", __func__);
4288 return -EINVAL;
4289 }
4290
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004291 if (eANI_BOOLEAN_TRUE == hdd_is_okc_mode_enabled(pHddCtx))
4292 {
4293 dump_bssid(pRoamInfo->bssid);
4294 cfg80211_pmksa_candidate_notify(dev, index,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004295 pRoamInfo->bssid, preauth, GFP_KERNEL);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004296 }
Jeff Johnsone7245742012-09-05 17:12:55 -07004297#endif /* FEATURE_WLAN_OKC */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304298 return 0;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004299}
4300#endif //FEATURE_WLAN_LFR
4301
Jeff Johnson295189b2012-06-20 16:38:30 -07004302/*
4303 * FUNCTION: hdd_cfg80211_scan_done_callback
4304 * scanning callback function, called after finishing scan
4305 *
4306 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304307static eHalStatus hdd_cfg80211_scan_done_callback(tHalHandle halHandle,
Jeff Johnson295189b2012-06-20 16:38:30 -07004308 void *pContext, tANI_U32 scanId, eCsrScanStatus status)
4309{
4310 struct net_device *dev = (struct net_device *) pContext;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304311 //struct wireless_dev *wdev = dev->ieee80211_ptr;
Jeff Johnson295189b2012-06-20 16:38:30 -07004312 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004313 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
4314 hdd_scaninfo_t *pScanInfo = &pHddCtx->scan_info;
Jeff Johnson295189b2012-06-20 16:38:30 -07004315 struct cfg80211_scan_request *req = NULL;
4316 int ret = 0;
4317
4318 ENTER();
4319
4320 hddLog(VOS_TRACE_LEVEL_INFO,
4321 "%s called with halHandle = %p, pContext = %p,"
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304322 "scanID = %d, returned status = %d\n",
Jeff Johnson295189b2012-06-20 16:38:30 -07004323 __func__, halHandle, pContext, (int) scanId, (int) status);
4324
4325 //Block on scan req completion variable. Can't wait forever though.
4326 ret = wait_for_completion_interruptible_timeout(
4327 &pScanInfo->scan_req_completion_event,
4328 msecs_to_jiffies(WLAN_WAIT_TIME_SCAN_REQ));
4329 if (!ret)
4330 {
4331 VOS_ASSERT(pScanInfo->mScanPending);
Jeff Johnsone7245742012-09-05 17:12:55 -07004332 goto allow_suspend;
Jeff Johnson295189b2012-06-20 16:38:30 -07004333 }
4334
4335 if(pScanInfo->mScanPending != VOS_TRUE)
4336 {
4337 VOS_ASSERT(pScanInfo->mScanPending);
Jeff Johnsone7245742012-09-05 17:12:55 -07004338 goto allow_suspend;
Jeff Johnson295189b2012-06-20 16:38:30 -07004339 }
4340
4341 /* Check the scanId */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304342 if (pScanInfo->scanId != scanId)
Jeff Johnson295189b2012-06-20 16:38:30 -07004343 {
4344 hddLog(VOS_TRACE_LEVEL_INFO,
4345 "%s called with mismatched scanId pScanInfo->scanId = %d "
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304346 "scanId = %d \n", __func__, (int) pScanInfo->scanId,
Jeff Johnson295189b2012-06-20 16:38:30 -07004347 (int) scanId);
4348 }
4349
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304350 ret = wlan_hdd_cfg80211_update_bss((WLAN_HDD_GET_CTX(pAdapter))->wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07004351 pAdapter);
4352
4353 if (0 > ret)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304354 hddLog(VOS_TRACE_LEVEL_INFO, "%s: NO SCAN result", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07004355
4356
4357 /* If any client wait scan result through WEXT
4358 * send scan done event to client */
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004359 if (pHddCtx->scan_info.waitScanResult)
Jeff Johnson295189b2012-06-20 16:38:30 -07004360 {
4361 /* The other scan request waiting for current scan finish
4362 * Send event to notify current scan finished */
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004363 if(WEXT_SCAN_PENDING_DELAY == pHddCtx->scan_info.scan_pending_option)
Jeff Johnson295189b2012-06-20 16:38:30 -07004364 {
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004365 vos_event_set(&pHddCtx->scan_info.scan_finished_event);
Jeff Johnson295189b2012-06-20 16:38:30 -07004366 }
4367 /* Send notify to WEXT client */
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004368 else if(WEXT_SCAN_PENDING_PIGGYBACK == pHddCtx->scan_info.scan_pending_option)
Jeff Johnson295189b2012-06-20 16:38:30 -07004369 {
4370 struct net_device *dev = pAdapter->dev;
4371 union iwreq_data wrqu;
4372 int we_event;
4373 char *msg;
4374
4375 memset(&wrqu, '\0', sizeof(wrqu));
4376 we_event = SIOCGIWSCAN;
4377 msg = NULL;
4378 wireless_send_event(dev, we_event, &wrqu, msg);
4379 }
4380 }
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004381 pHddCtx->scan_info.waitScanResult = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004382
4383 /* Get the Scan Req */
4384 req = pAdapter->request;
4385
4386 if (!req)
4387 {
4388 hddLog(VOS_TRACE_LEVEL_ERROR, "request is became NULL\n");
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07004389 pScanInfo->mScanPending = VOS_FALSE;
Jeff Johnsone7245742012-09-05 17:12:55 -07004390 goto allow_suspend;
Jeff Johnson295189b2012-06-20 16:38:30 -07004391 }
4392
4393 /*
4394 * setting up 0, just in case.
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304395 */
Jeff Johnson295189b2012-06-20 16:38:30 -07004396 req->n_ssids = 0;
4397 req->n_channels = 0;
4398 req->ie = 0;
4399
Jeff Johnson295189b2012-06-20 16:38:30 -07004400 pAdapter->request = NULL;
Jeff Johnsone7245742012-09-05 17:12:55 -07004401 /* Scan is no longer pending */
4402 pScanInfo->mScanPending = VOS_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004403
Madan Mohan Koyyalamudib764bf82012-10-11 16:38:51 -07004404 /*
4405 * cfg80211_scan_done informing NL80211 about completion
4406 * of scanning
4407 */
4408 cfg80211_scan_done(req, false);
Madan Mohan Koyyalamudif4e81002012-11-13 10:46:38 -08004409 complete(&pScanInfo->abortscan_event_var);
Jeff Johnson295189b2012-06-20 16:38:30 -07004410
Jeff Johnsone7245742012-09-05 17:12:55 -07004411allow_suspend:
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07004412 /* release the wake lock at the end of the scan*/
4413 hdd_allow_suspend();
Jeff Johnsone7245742012-09-05 17:12:55 -07004414
Madan Mohan Koyyalamudi10d83a92012-09-28 15:47:05 -07004415 /* Acquire wakelock to handle the case where APP's tries to suspend
4416 * immediatly after the driver gets connect request(i.e after scan)
4417 * from supplicant, this result in app's is suspending and not able
4418 * to process the connect request to AP */
Amar Singhal6144c002013-05-03 16:11:42 -07004419 hdd_allow_suspend_timeout(1000);
Madan Mohan Koyyalamudi10d83a92012-09-28 15:47:05 -07004420
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07004421#ifdef FEATURE_WLAN_TDLS
4422 wlan_hdd_tdls_scan_done_callback(pAdapter);
4423#endif
4424
Jeff Johnson295189b2012-06-20 16:38:30 -07004425 EXIT();
4426 return 0;
4427}
4428
4429/*
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004430 * FUNCTION: hdd_isScanAllowed
4431 * Go through each adapter and check if scan allowed
4432 *
4433 */
4434v_BOOL_t hdd_isScanAllowed( hdd_context_t *pHddCtx )
4435{
4436 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
4437 hdd_station_ctx_t *pHddStaCtx = NULL;
4438 hdd_adapter_t *pAdapter = NULL;
4439 VOS_STATUS status = 0;
4440 v_U8_t staId = 0;
4441 v_U8_t *staMac = NULL;
4442
4443 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
4444
4445 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
4446 {
4447 pAdapter = pAdapterNode->pAdapter;
4448
4449 if( pAdapter )
4450 {
4451 hddLog(VOS_TRACE_LEVEL_INFO,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304452 "%s: Adapter with device mode %d exists",
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004453 __func__, pAdapter->device_mode);
4454 if ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
4455 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) ||
4456 (WLAN_HDD_P2P_DEVICE == pAdapter->device_mode))
4457 {
4458 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
4459 if ((eConnectionState_Associated == pHddStaCtx->conn_info.connState) &&
4460 (VOS_FALSE == pHddStaCtx->conn_info.uIsAuthenticated))
4461 {
4462 staMac = (v_U8_t *) &(pAdapter->macAddressCurrent.bytes[0]);
4463 hddLog(VOS_TRACE_LEVEL_ERROR,
4464 "%s: client %02x:%02x:%02x:%02x:%02x:%02x is in the "
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304465 "middle of WPS/EAPOL exchange.", __func__,
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004466 staMac[0], staMac[1], staMac[2],
4467 staMac[3], staMac[4], staMac[5]);
4468 return VOS_FALSE;
4469 }
4470 }
4471 else if ((WLAN_HDD_SOFTAP == pAdapter->device_mode) ||
4472 (WLAN_HDD_P2P_GO == pAdapter->device_mode))
4473 {
4474 for (staId = 0; staId < WLAN_MAX_STA_COUNT; staId++)
4475 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304476 if ((pAdapter->aStaInfo[staId].isUsed) &&
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004477 (WLANTL_STA_CONNECTED == pAdapter->aStaInfo[staId].tlSTAState))
4478 {
4479 staMac = (v_U8_t *) &(pAdapter->aStaInfo[staId].macAddrSTA.bytes[0]);
4480
4481 hddLog(VOS_TRACE_LEVEL_ERROR,
4482 "%s: client %02x:%02x:%02x:%02x:%02x:%02x of SoftAP/P2P-GO is in the "
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304483 "middle of WPS/EAPOL exchange.", __func__,
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004484 staMac[0], staMac[1], staMac[2],
4485 staMac[3], staMac[4], staMac[5]);
4486 return VOS_FALSE;
4487 }
4488 }
4489 }
4490 }
4491 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
4492 pAdapterNode = pNext;
4493 }
4494 hddLog(VOS_TRACE_LEVEL_INFO,
4495 "%s: Scan allowed", __func__);
4496 return VOS_TRUE;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304497}
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004498
4499/*
Jeff Johnson295189b2012-06-20 16:38:30 -07004500 * FUNCTION: wlan_hdd_cfg80211_scan
4501 * this scan respond to scan trigger and update cfg80211 scan database
4502 * later, scan dump command can be used to recieve scan results
4503 */
Jeff Johnson3bbe4bf2013-01-18 17:05:29 -08004504int wlan_hdd_cfg80211_scan( struct wiphy *wiphy,
4505#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
4506 struct net_device *dev,
4507#endif
4508 struct cfg80211_scan_request *request)
4509{
4510#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
4511 struct net_device *dev = request->wdev->netdev;
4512#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304513 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Jeff Johnson295189b2012-06-20 16:38:30 -07004514 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
4515 hdd_wext_state_t *pwextBuf = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05304516 hdd_config_t *cfg_param = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004517 tCsrScanRequest scanRequest;
4518 tANI_U8 *channelList = NULL, i;
4519 v_U32_t scanId = 0;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05304520 int status;
4521 hdd_scaninfo_t *pScanInfo = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004522 v_U8_t* pP2pIe = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004523
4524 ENTER();
4525
4526 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
4527 __func__,pAdapter->device_mode);
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004528
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05304529 status = wlan_hdd_validate_context(pHddCtx);
4530
4531 if (0 != status)
4532 {
4533 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4534 "%s: HDD context is not valid", __func__);
4535 return status;
4536 }
4537
4538 cfg_param = pHddCtx->cfg_ini;
4539 pScanInfo = &pHddCtx->scan_info;
4540
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004541 if ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) &&
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004542 (eConnectionState_Connecting ==
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004543 (WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))->conn_info.connState))
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004544 {
4545 hddLog(VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08004546 "%s: %p(%d) Connection in progress: Scan request denied (EBUSY)", __func__, \
4547 WLAN_HDD_GET_STATION_CTX_PTR(pAdapter), pAdapter->sessionId);
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004548 return -EBUSY;
4549 }
4550
Jeff Johnson295189b2012-06-20 16:38:30 -07004551#ifdef WLAN_BTAMP_FEATURE
4552 //Scan not supported when AMP traffic is on.
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004553 if (VOS_TRUE == WLANBAP_AmpSessionOn())
Jeff Johnson295189b2012-06-20 16:38:30 -07004554 {
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004555 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07004556 "%s: No scanning when AMP is on", __func__);
4557 return -EOPNOTSUPP;
4558 }
4559#endif
4560 //Scan on any other interface is not supported.
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004561 if (pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07004562 {
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004563 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07004564 "%s: Not scanning on device_mode = %d",
4565 __func__, pAdapter->device_mode);
4566 return -EOPNOTSUPP;
4567 }
4568
4569 if (TRUE == pScanInfo->mScanPending)
4570 {
4571 hddLog(VOS_TRACE_LEVEL_INFO, "%s: mScanPending is TRUE", __func__);
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004572 return -EBUSY;
Jeff Johnson295189b2012-06-20 16:38:30 -07004573 }
4574
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304575 //Don't Allow Scan and return busy if Remain On
Jeff Johnson32d95a32012-09-10 13:15:23 -07004576 //Channel and action frame is pending
4577 //Otherwise Cancel Remain On Channel and allow Scan
4578 //If no action frame pending
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004579 if (0 != wlan_hdd_check_remain_on_channel(pAdapter))
Jeff Johnson32d95a32012-09-10 13:15:23 -07004580 {
4581 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Remain On Channel Pending", __func__);
4582 return -EBUSY;
4583 }
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004584#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07004585 /* if tdls disagree scan right now, return immediately.
4586 tdls will schedule the scan when scan is allowed. (return SUCCESS)
4587 or will reject the scan if any TDLS is in progress. (return -EBUSY)
4588 */
4589 status = wlan_hdd_tdls_scan_callback (pAdapter,
4590 wiphy,
4591#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
4592 dev,
Gopichand Nakkalac3c42b92013-03-20 19:42:34 -07004593#endif
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07004594 request);
4595 if(status <= 0)
4596 {
4597 hddLog(VOS_TRACE_LEVEL_INFO, "%s: TDLS Pending %d", __func__, status);
4598 return status;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004599 }
4600#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -07004601
Jeff Johnson295189b2012-06-20 16:38:30 -07004602 if (mutex_lock_interruptible(&pHddCtx->tmInfo.tmOperationLock))
4603 {
4604 VOS_TRACE(VOS_MODULE_ID_HDD,VOS_TRACE_LEVEL_ERROR,
Jeff Johnson1250df42012-12-10 14:31:52 -08004605 "%s: Acquire lock fail", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07004606 return -EAGAIN;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304607 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004608 if (TRUE == pHddCtx->tmInfo.tmAction.enterImps)
4609 {
4610 hddLog(VOS_TRACE_LEVEL_WARN,
4611 "%s: MAX TM Level Scan not allowed", __func__);
4612 mutex_unlock(&pHddCtx->tmInfo.tmOperationLock);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304613 return -EBUSY;
Jeff Johnson295189b2012-06-20 16:38:30 -07004614 }
4615 mutex_unlock(&pHddCtx->tmInfo.tmOperationLock);
4616
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004617 /* Check if scan is allowed at this point of time.
4618 */
4619 if (!hdd_isScanAllowed(pHddCtx))
4620 {
4621 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Scan not allowed", __func__);
4622 return -EBUSY;
4623 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304624
Jeff Johnson295189b2012-06-20 16:38:30 -07004625 vos_mem_zero( &scanRequest, sizeof(scanRequest));
4626
4627 if (NULL != request)
4628 {
4629 hddLog(VOS_TRACE_LEVEL_INFO, "scan request for ssid = %d",
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304630 (int)request->n_ssids);
Jeff Johnson295189b2012-06-20 16:38:30 -07004631
4632 /* Even though supplicant doesn't provide any SSIDs, n_ssids is set to 1.
4633 * Becasue of this, driver is assuming that this is not wildcard scan and so
4634 * is not aging out the scan results.
4635 */
Jeff Johnson32d95a32012-09-10 13:15:23 -07004636 if (request->ssids && '\0' == request->ssids->ssid[0])
Jeff Johnson295189b2012-06-20 16:38:30 -07004637 {
4638 request->n_ssids = 0;
4639 }
4640
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07004641 if ((request->ssids) && (0 < request->n_ssids))
Jeff Johnson295189b2012-06-20 16:38:30 -07004642 {
4643 tCsrSSIDInfo *SsidInfo;
4644 int j;
4645 scanRequest.SSIDs.numOfSSIDs = request->n_ssids;
4646 /* Allocate num_ssid tCsrSSIDInfo structure */
4647 SsidInfo = scanRequest.SSIDs.SSIDList =
4648 ( tCsrSSIDInfo *)vos_mem_malloc(
4649 request->n_ssids*sizeof(tCsrSSIDInfo));
4650
4651 if(NULL == scanRequest.SSIDs.SSIDList)
4652 {
4653 hddLog(VOS_TRACE_LEVEL_ERROR,
4654 "memory alloc failed SSIDInfo buffer");
4655 return -ENOMEM;
4656 }
4657
4658 /* copy all the ssid's and their length */
4659 for(j = 0; j < request->n_ssids; j++, SsidInfo++)
4660 {
4661 /* get the ssid length */
4662 SsidInfo->SSID.length = request->ssids[j].ssid_len;
4663 vos_mem_copy(SsidInfo->SSID.ssId, &request->ssids[j].ssid[0],
4664 SsidInfo->SSID.length);
4665 SsidInfo->SSID.ssId[SsidInfo->SSID.length] = '\0';
4666 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "SSID number %d: %s",
4667 j, SsidInfo->SSID.ssId);
4668 }
4669 /* set the scan type to active */
4670 scanRequest.scanType = eSIR_ACTIVE_SCAN;
4671 }
4672 else if(WLAN_HDD_P2P_GO == pAdapter->device_mode)
4673 {
4674 /* set the scan type to active */
4675 scanRequest.scanType = eSIR_ACTIVE_SCAN;
4676 }
4677 else
4678 {
4679 /*Set the scan type to default type, in this case it is ACTIVE*/
4680 scanRequest.scanType = pScanInfo->scan_mode;
4681 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304682 scanRequest.minChnTime = cfg_param->nActiveMinChnTime;
Jeff Johnson295189b2012-06-20 16:38:30 -07004683 scanRequest.maxChnTime = cfg_param->nActiveMaxChnTime;
4684 }
4685 else
4686 {
4687 /* set the scan type to active */
4688 scanRequest.scanType = eSIR_ACTIVE_SCAN;
4689 vos_mem_set( scanRequest.bssid, sizeof( tCsrBssid ), 0xff );
4690
4691 /* set min and max channel time to zero */
4692 scanRequest.minChnTime = 0;
4693 scanRequest.maxChnTime = 0;
4694 }
4695
4696 /* set BSSType to default type */
4697 scanRequest.BSSType = eCSR_BSS_TYPE_ANY;
4698
4699 /*TODO: scan the requested channels only*/
4700
4701 /*Right now scanning all the channels */
4702 if( request )
4703 {
4704 if( request->n_channels )
4705 {
4706 channelList = vos_mem_malloc( request->n_channels );
4707 if( NULL == channelList )
4708 {
4709 status = -ENOMEM;
4710 goto free_mem;
4711 }
4712
4713 for( i = 0 ; i < request->n_channels ; i++ )
4714 channelList[i] = request->channels[i]->hw_value;
4715 }
4716
4717 scanRequest.ChannelInfo.numOfChannels = request->n_channels;
4718 scanRequest.ChannelInfo.ChannelList = channelList;
4719
4720 /* set requestType to full scan */
4721 scanRequest.requestType = eCSR_SCAN_REQUEST_FULL_SCAN;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304722
4723 /* Flush the scan results(only p2p beacons) for STA scan and P2P
Madan Mohan Koyyalamudi8d50f312012-11-27 15:48:57 -08004724 * search (Flush on both full scan and social scan but not on single
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304725 * channel scan).P2P search happens on 3 social channels (1, 6, 11)
Madan Mohan Koyyalamudi8d50f312012-11-27 15:48:57 -08004726 */
4727
4728 /* Supplicant does single channel scan after 8-way handshake
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304729 * and in that case driver shoudnt flush scan results. If
4730 * driver flushes the scan results here and unfortunately if
4731 * the AP doesnt respond to our probe req then association
Madan Mohan Koyyalamudi8d50f312012-11-27 15:48:57 -08004732 * fails which is not desired
4733 */
4734
4735 if( request->n_channels != WLAN_HDD_P2P_SINGLE_CHANNEL_SCAN )
4736 {
4737 sme_ScanFlushP2PResult( WLAN_HDD_GET_HAL_CTX(pAdapter),
4738 pAdapter->sessionId );
4739 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004740
4741 if( request->ie_len )
4742 {
4743 /* save this for future association (join requires this) */
4744 memset( &pScanInfo->scanAddIE, 0, sizeof(pScanInfo->scanAddIE) );
4745 memcpy( pScanInfo->scanAddIE.addIEdata, request->ie, request->ie_len);
4746 pScanInfo->scanAddIE.length = request->ie_len;
4747
4748 if((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
Jeff Johnsone7245742012-09-05 17:12:55 -07004749 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) ||
4750 (WLAN_HDD_P2P_DEVICE == pAdapter->device_mode)
Jeff Johnson295189b2012-06-20 16:38:30 -07004751 )
4752 {
4753 pwextBuf->roamProfile.pAddIEScan = pScanInfo->scanAddIE.addIEdata;
4754 pwextBuf->roamProfile.nAddIEScanLength = pScanInfo->scanAddIE.length;
4755 }
4756
4757 scanRequest.uIEFieldLen = pScanInfo->scanAddIE.length;
4758 scanRequest.pIEField = pScanInfo->scanAddIE.addIEdata;
4759
Jeff Johnson295189b2012-06-20 16:38:30 -07004760 pP2pIe = wlan_hdd_get_p2p_ie_ptr((v_U8_t*)request->ie,
4761 request->ie_len);
4762 if (pP2pIe != NULL)
4763 {
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07004764#ifdef WLAN_FEATURE_P2P_DEBUG
4765 if (((globalP2PConnectionStatus == P2P_GO_NEG_COMPLETED) ||
4766 (globalP2PConnectionStatus == P2P_GO_NEG_PROCESS)) &&
4767 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
4768 {
4769 globalP2PConnectionStatus = P2P_CLIENT_CONNECTING_STATE_1;
4770 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P State] Changing state from "
4771 "Go nego completed to Connection is started");
4772 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P]P2P Scanning is started "
4773 "for 8way Handshake");
4774 }
4775 else if((globalP2PConnectionStatus == P2P_CLIENT_DISCONNECTED_STATE) &&
4776 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
4777 {
4778 globalP2PConnectionStatus = P2P_CLIENT_CONNECTING_STATE_2;
4779 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P State] Changing state from "
4780 "Disconnected state to Connection is started");
4781 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P]P2P Scanning is started "
4782 "for 4way Handshake");
4783 }
4784#endif
4785
Jeff Johnsone7245742012-09-05 17:12:55 -07004786 /* no_cck will be set during p2p find to disable 11b rates */
4787 if(TRUE == request->no_cck)
Jeff Johnson295189b2012-06-20 16:38:30 -07004788 {
Jeff Johnson295189b2012-06-20 16:38:30 -07004789 hddLog(VOS_TRACE_LEVEL_INFO,
4790 "%s: This is a P2P Search", __func__);
4791 scanRequest.p2pSearch = 1;
Jeff Johnsone7245742012-09-05 17:12:55 -07004792
Jeff Johnsone7245742012-09-05 17:12:55 -07004793 if( request->n_channels == WLAN_HDD_P2P_SOCIAL_CHANNELS )
4794 {
Madan Mohan Koyyalamudi1b1d9e82012-10-21 11:38:33 -07004795 /* set requestType to P2P Discovery */
4796 scanRequest.requestType = eCSR_SCAN_P2P_DISCOVERY;
Jeff Johnsone7245742012-09-05 17:12:55 -07004797 }
4798
4799 /*
4800 Skip Dfs Channel in case of P2P Search
4801 if it is set in ini file
4802 */
4803 if(cfg_param->skipDfsChnlInP2pSearch)
4804 {
4805 scanRequest.skipDfsChnlInP2pSearch = 1;
4806 }
4807 else
4808 {
4809 scanRequest.skipDfsChnlInP2pSearch = 0;
4810 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004811
Jeff Johnson295189b2012-06-20 16:38:30 -07004812 }
4813 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004814 }
4815 }
4816
4817 INIT_COMPLETION(pScanInfo->scan_req_completion_event);
4818
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07004819 /* acquire the wakelock to avoid the apps suspend during the scan. To
4820 * address the following issues.
4821 * 1) Disconnected scenario: we are not allowing the suspend as WLAN is not in
4822 * BMPS/IMPS this result in android trying to suspend aggressively and backing off
4823 * for long time, this result in apps running at full power for long time.
4824 * 2) Connected scenario: If we allow the suspend during the scan, RIVA will
4825 * be stuck in full power because of resume BMPS
4826 */
4827 hdd_prevent_suspend();
Jeff Johnsone7245742012-09-05 17:12:55 -07004828
4829 status = sme_ScanRequest( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07004830 pAdapter->sessionId, &scanRequest, &scanId,
4831 &hdd_cfg80211_scan_done_callback, dev );
Jeff Johnsone7245742012-09-05 17:12:55 -07004832
Jeff Johnson295189b2012-06-20 16:38:30 -07004833 if (eHAL_STATUS_SUCCESS != status)
4834 {
4835 hddLog(VOS_TRACE_LEVEL_ERROR,
4836 "%s: sme_ScanRequest returned error %d", __func__, status);
4837 complete(&pScanInfo->scan_req_completion_event);
Madan Mohan Koyyalamudi3b230fe2012-10-18 14:46:32 -07004838 if(eHAL_STATUS_RESOURCES == status)
4839 {
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07004840 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 -07004841 status = -EBUSY;
4842 } else {
4843 status = -EIO;
4844 }
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07004845 hdd_allow_suspend();
Jeff Johnson295189b2012-06-20 16:38:30 -07004846 goto free_mem;
4847 }
4848
4849 pScanInfo->mScanPending = TRUE;
4850 pAdapter->request = request;
4851 pScanInfo->scanId = scanId;
4852
4853 complete(&pScanInfo->scan_req_completion_event);
4854
4855free_mem:
4856 if( scanRequest.SSIDs.SSIDList )
4857 {
4858 vos_mem_free(scanRequest.SSIDs.SSIDList);
4859 }
4860
4861 if( channelList )
4862 vos_mem_free( channelList );
4863
4864 EXIT();
4865
4866 return status;
4867}
4868
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07004869
4870void hdd_select_cbmode( hdd_adapter_t *pAdapter,v_U8_t operationChannel)
4871{
4872 v_U8_t iniDot11Mode =
4873 (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini->dot11Mode;
4874 eHddDot11Mode hddDot11Mode = iniDot11Mode;
4875
4876 switch ( iniDot11Mode )
4877 {
4878 case eHDD_DOT11_MODE_AUTO:
4879 case eHDD_DOT11_MODE_11ac:
4880 case eHDD_DOT11_MODE_11ac_ONLY:
4881#ifdef WLAN_FEATURE_11AC
4882 hddDot11Mode = eHDD_DOT11_MODE_11ac;
4883#else
4884 hddDot11Mode = eHDD_DOT11_MODE_11n;
4885#endif
4886 break;
4887 case eHDD_DOT11_MODE_11n:
4888 case eHDD_DOT11_MODE_11n_ONLY:
4889 hddDot11Mode = eHDD_DOT11_MODE_11n;
4890 break;
4891 default:
4892 hddDot11Mode = iniDot11Mode;
4893 break;
4894 }
4895 /* This call decides required channel bonding mode */
4896 sme_SelectCBMode((WLAN_HDD_GET_CTX(pAdapter)->hHal),
4897 hdd_cfg_xlate_to_csr_phy_mode(hddDot11Mode),
4898 operationChannel);
4899}
4900
Jeff Johnson295189b2012-06-20 16:38:30 -07004901/*
4902 * FUNCTION: wlan_hdd_cfg80211_connect_start
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304903 * This function is used to start the association process
Jeff Johnson295189b2012-06-20 16:38:30 -07004904 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304905int wlan_hdd_cfg80211_connect_start( hdd_adapter_t *pAdapter,
Jeff Johnson32d95a32012-09-10 13:15:23 -07004906 const u8 *ssid, size_t ssid_len, const u8 *bssid, u8 operatingChannel)
Jeff Johnson295189b2012-06-20 16:38:30 -07004907{
4908 int status = 0;
4909 hdd_wext_state_t *pWextState;
4910 v_U32_t roamId;
4911 tCsrRoamProfile *pRoamProfile;
4912 eMib_dot11DesiredBssType connectedBssType;
4913 eCsrAuthType RSNAuthType;
4914
4915 ENTER();
4916
4917 pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304918
Jeff Johnson295189b2012-06-20 16:38:30 -07004919 if (SIR_MAC_MAX_SSID_LENGTH < ssid_len)
4920 {
4921 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: wrong SSID len", __func__);
4922 return -EINVAL;
4923 }
4924
4925 pRoamProfile = &pWextState->roamProfile;
4926
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304927 if (pRoamProfile)
Jeff Johnson295189b2012-06-20 16:38:30 -07004928 {
Jeff Johnsone7245742012-09-05 17:12:55 -07004929 int ret = 0;
4930 hdd_station_ctx_t *pHddStaCtx;
4931 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
4932 hdd_connGetConnectedBssType(pHddStaCtx,&connectedBssType );
4933
4934 if((eMib_dot11DesiredBssType_independent == connectedBssType) ||
4935 (eConnectionState_Associated == pHddStaCtx->conn_info.connState) ||
4936 (eConnectionState_IbssConnected == pHddStaCtx->conn_info.connState))
Jeff Johnson295189b2012-06-20 16:38:30 -07004937 {
4938 /* Issue disconnect to CSR */
4939 INIT_COMPLETION(pAdapter->disconnect_comp_var);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304940 if( eHAL_STATUS_SUCCESS ==
Jeff Johnson295189b2012-06-20 16:38:30 -07004941 sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
4942 pAdapter->sessionId,
4943 eCSR_DISCONNECT_REASON_UNSPECIFIED ) )
4944 {
Jeff Johnsone7245742012-09-05 17:12:55 -07004945 ret = wait_for_completion_interruptible_timeout(
4946 &pAdapter->disconnect_comp_var,
4947 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
4948 if (0 == ret)
4949 {
4950 VOS_ASSERT(0);
4951 }
4952 }
4953 }
4954 else if(eConnectionState_Disconnecting == pHddStaCtx->conn_info.connState)
4955 {
4956 ret = wait_for_completion_interruptible_timeout(
4957 &pAdapter->disconnect_comp_var,
4958 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
4959 if (0 == ret)
4960 {
4961 VOS_ASSERT(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004962 }
4963 }
4964
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304965 if (HDD_WMM_USER_MODE_NO_QOS ==
Jeff Johnson295189b2012-06-20 16:38:30 -07004966 (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini->WmmMode)
4967 {
4968 /*QoS not enabled in cfg file*/
4969 pRoamProfile->uapsd_mask = 0;
4970 }
4971 else
4972 {
4973 /*QoS enabled, update uapsd mask from cfg file*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304974 pRoamProfile->uapsd_mask =
Jeff Johnson295189b2012-06-20 16:38:30 -07004975 (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini->UapsdMask;
4976 }
4977
4978 pRoamProfile->SSIDs.numOfSSIDs = 1;
4979 pRoamProfile->SSIDs.SSIDList->SSID.length = ssid_len;
4980 vos_mem_zero(pRoamProfile->SSIDs.SSIDList->SSID.ssId,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304981 sizeof(pRoamProfile->SSIDs.SSIDList->SSID.ssId));
Jeff Johnson295189b2012-06-20 16:38:30 -07004982 vos_mem_copy((void *)(pRoamProfile->SSIDs.SSIDList->SSID.ssId),
4983 ssid, ssid_len);
4984
4985 if (bssid)
4986 {
4987 pRoamProfile->BSSIDs.numOfBSSIDs = 1;
4988 vos_mem_copy((void *)(pRoamProfile->BSSIDs.bssid), bssid,
4989 WNI_CFG_BSSID_LEN);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304990 /* Save BSSID in seperate variable as well, as RoamProfile
4991 BSSID is getting zeroed out in the association process. And in
Jeff Johnson295189b2012-06-20 16:38:30 -07004992 case of join failure we should send valid BSSID to supplicant
4993 */
4994 vos_mem_copy((void *)(pWextState->req_bssId), bssid,
4995 WNI_CFG_BSSID_LEN);
4996 }
Dhanashri Atre51981c62013-06-13 11:47:57 -07004997 else
4998 {
4999 vos_mem_zero((void *)(pRoamProfile->BSSIDs.bssid),WNI_CFG_BSSID_LEN);
5000 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005001
5002 if ((IW_AUTH_WPA_VERSION_WPA == pWextState->wpaVersion) ||
5003 (IW_AUTH_WPA_VERSION_WPA2 == pWextState->wpaVersion))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305004 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005005 /*set gen ie*/
5006 hdd_SetGENIEToCsr(pAdapter, &RSNAuthType);
5007 /*set auth*/
5008 hdd_set_csr_auth_type(pAdapter, RSNAuthType);
5009 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005010#ifdef FEATURE_WLAN_WAPI
5011 if (pAdapter->wapi_info.nWapiMode)
5012 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005013 hddLog(LOG1, "%s: Setting WAPI AUTH Type and Encryption Mode values", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005014 switch (pAdapter->wapi_info.wapiAuthMode)
5015 {
5016 case WAPI_AUTH_MODE_PSK:
5017 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005018 hddLog(LOG1, "%s: WAPI AUTH TYPE: PSK: %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07005019 pAdapter->wapi_info.wapiAuthMode);
5020 pRoamProfile->AuthType.authType[0] = eCSR_AUTH_TYPE_WAPI_WAI_PSK;
5021 break;
5022 }
5023 case WAPI_AUTH_MODE_CERT:
5024 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005025 hddLog(LOG1, "%s: WAPI AUTH TYPE: CERT: %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07005026 pAdapter->wapi_info.wapiAuthMode);
5027 pRoamProfile->AuthType.authType[0] = eCSR_AUTH_TYPE_WAPI_WAI_CERTIFICATE;
5028 break;
5029 }
5030 } // End of switch
5031 if ( pAdapter->wapi_info.wapiAuthMode == WAPI_AUTH_MODE_PSK ||
5032 pAdapter->wapi_info.wapiAuthMode == WAPI_AUTH_MODE_CERT)
5033 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005034 hddLog(LOG1, "%s: WAPI PAIRWISE/GROUP ENCRYPTION: WPI", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005035 pRoamProfile->AuthType.numEntries = 1;
5036 pRoamProfile->EncryptionType.numEntries = 1;
5037 pRoamProfile->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_WPI;
5038 pRoamProfile->mcEncryptionType.numEntries = 1;
5039 pRoamProfile->mcEncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_WPI;
5040 }
5041 }
5042#endif /* FEATURE_WLAN_WAPI */
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05305043#ifdef WLAN_FEATURE_GTK_OFFLOAD
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05305044 /* Initializing gtkOffloadReqParams */
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05305045 if ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
5046 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
5047 {
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05305048 memset(&pHddStaCtx->gtkOffloadReqParams, 0,
5049 sizeof (tSirGtkOffloadParams));
5050 pHddStaCtx->gtkOffloadReqParams.ulFlags = GTK_OFFLOAD_DISABLE;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05305051 }
5052#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005053 pRoamProfile->csrPersona = pAdapter->device_mode;
5054
Jeff Johnson32d95a32012-09-10 13:15:23 -07005055 if( operatingChannel )
5056 {
5057 pRoamProfile->ChannelInfo.ChannelList = &operatingChannel;
5058 pRoamProfile->ChannelInfo.numOfChannels = 1;
5059 }
Chet Lanctot186b5732013-03-18 10:26:30 -07005060 else
5061 {
5062 pRoamProfile->ChannelInfo.ChannelList = NULL;
5063 pRoamProfile->ChannelInfo.numOfChannels = 0;
5064 }
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07005065 if ( (WLAN_HDD_IBSS == pAdapter->device_mode) && operatingChannel)
5066 {
5067 hdd_select_cbmode(pAdapter,operatingChannel);
5068 }
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08005069 /* change conn_state to connecting before sme_RoamConnect(), because sme_RoamConnect()
5070 * has a direct path to call hdd_smeRoamCallback(), which will change the conn_state
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305071 * If direct path, conn_state will be accordingly changed to NotConnected or Associated
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08005072 * by either hdd_AssociationCompletionHandler() or hdd_DisConnectHandler() in sme_RoamCallback()
Madan Mohan Koyyalamudidf86c422012-12-04 17:03:44 -08005073 * if sme_RomConnect is to be queued, Connecting state will remain until it is completed.
5074 */
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +05305075 if (WLAN_HDD_INFRA_STATION == pAdapter->device_mode ||
5076 WLAN_HDD_P2P_CLIENT == pAdapter->device_mode)
Madan Mohan Koyyalamudidf86c422012-12-04 17:03:44 -08005077 hdd_connSetConnectionState(WLAN_HDD_GET_STATION_CTX_PTR(pAdapter),
5078 eConnectionState_Connecting);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305079
5080 status = sme_RoamConnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07005081 pAdapter->sessionId, pRoamProfile, &roamId);
5082
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +05305083 if ((eHAL_STATUS_SUCCESS != status) &&
5084 (WLAN_HDD_INFRA_STATION == pAdapter->device_mode ||
5085 WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
Madan Mohan Koyyalamudid5acbf52012-11-28 01:45:08 +05305086
5087 {
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08005088 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: sme_RoamConnect (session %d) failed with "
5089 "status %d. -> NotConnected", __func__, pAdapter->sessionId, status);
5090 /* change back to NotAssociated */
Madan Mohan Koyyalamudid5acbf52012-11-28 01:45:08 +05305091 hdd_connSetConnectionState(WLAN_HDD_GET_STATION_CTX_PTR(pAdapter),
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08005092 eConnectionState_NotConnected);
Madan Mohan Koyyalamudid5acbf52012-11-28 01:45:08 +05305093 }
Madan Mohan Koyyalamudidf86c422012-12-04 17:03:44 -08005094
5095 pRoamProfile->ChannelInfo.ChannelList = NULL;
5096 pRoamProfile->ChannelInfo.numOfChannels = 0;
5097
Jeff Johnson295189b2012-06-20 16:38:30 -07005098 }
5099 else
5100 {
5101 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: No valid Roam profile", __func__);
5102 return -EINVAL;
5103 }
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08005104 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07005105 return status;
5106}
5107
5108/*
5109 * FUNCTION: wlan_hdd_set_cfg80211_auth_type
5110 * This function is used to set the authentication type (OPEN/SHARED).
5111 *
5112 */
5113static int wlan_hdd_cfg80211_set_auth_type(hdd_adapter_t *pAdapter,
5114 enum nl80211_auth_type auth_type)
5115{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305116 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07005117 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
5118
5119 ENTER();
5120
5121 /*set authentication type*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305122 switch (auth_type)
Jeff Johnson295189b2012-06-20 16:38:30 -07005123 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005124 case NL80211_AUTHTYPE_AUTOMATIC:
Gopichand Nakkala29149562013-05-10 21:43:41 +05305125 hddLog(VOS_TRACE_LEVEL_INFO,
5126 "%s: set authentication type to AUTOSWITCH", __func__);
5127 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_AUTOSWITCH;
5128 break;
5129
5130 case NL80211_AUTHTYPE_OPEN_SYSTEM:
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07005131#ifdef WLAN_FEATURE_VOWIFI_11R
5132 case NL80211_AUTHTYPE_FT:
5133#endif /* WLAN_FEATURE_VOWIFI_11R */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305134 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07005135 "%s: set authentication type to OPEN", __func__);
5136 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
5137 break;
5138
5139 case NL80211_AUTHTYPE_SHARED_KEY:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305140 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07005141 "%s: set authentication type to SHARED", __func__);
5142 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_SHARED_KEY;
5143 break;
5144#ifdef FEATURE_WLAN_CCX
5145 case NL80211_AUTHTYPE_NETWORK_EAP:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305146 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07005147 "%s: set authentication type to CCKM WPA", __func__);
5148 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_CCKM_WPA;//eCSR_AUTH_TYPE_CCKM_RSN needs to be handled as well if required.
5149 break;
5150#endif
5151
5152
5153 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305154 hddLog(VOS_TRACE_LEVEL_ERROR,
5155 "%s: Unsupported authentication type %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07005156 auth_type);
5157 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_UNKNOWN;
5158 return -EINVAL;
5159 }
5160
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305161 pWextState->roamProfile.AuthType.authType[0] =
Jeff Johnson295189b2012-06-20 16:38:30 -07005162 pHddStaCtx->conn_info.authType;
5163 return 0;
5164}
5165
5166/*
5167 * FUNCTION: wlan_hdd_set_akm_suite
5168 * This function is used to set the key mgmt type(PSK/8021x).
5169 *
5170 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305171static int wlan_hdd_set_akm_suite( hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07005172 u32 key_mgmt
5173 )
5174{
5175 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
5176 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305177
Jeff Johnson295189b2012-06-20 16:38:30 -07005178 /*set key mgmt type*/
5179 switch(key_mgmt)
5180 {
5181 case WLAN_AKM_SUITE_PSK:
Gopichand Nakkala356fb102013-03-06 12:34:04 +05305182#ifdef WLAN_FEATURE_VOWIFI_11R
5183 case WLAN_AKM_SUITE_FT_PSK:
5184#endif
5185 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting key mgmt type to PSK",
Jeff Johnson295189b2012-06-20 16:38:30 -07005186 __func__);
5187 pWextState->authKeyMgmt |= IW_AUTH_KEY_MGMT_PSK;
5188 break;
5189
5190 case WLAN_AKM_SUITE_8021X:
Gopichand Nakkala356fb102013-03-06 12:34:04 +05305191#ifdef WLAN_FEATURE_VOWIFI_11R
5192 case WLAN_AKM_SUITE_FT_8021X:
5193#endif
5194 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting key mgmt type to 8021x",
Jeff Johnson295189b2012-06-20 16:38:30 -07005195 __func__);
5196 pWextState->authKeyMgmt |= IW_AUTH_KEY_MGMT_802_1X;
5197 break;
5198#ifdef FEATURE_WLAN_CCX
5199#define WLAN_AKM_SUITE_CCKM 0x00409600 /* Should be in ieee802_11_defs.h */
5200#define IW_AUTH_KEY_MGMT_CCKM 8 /* Should be in linux/wireless.h */
5201 case WLAN_AKM_SUITE_CCKM:
5202 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting key mgmt type to CCKM",
5203 __func__);
5204 pWextState->authKeyMgmt |= IW_AUTH_KEY_MGMT_CCKM;
5205 break;
5206#endif
5207
5208 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305209 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported key mgmt type %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005210 __func__, key_mgmt);
5211 return -EINVAL;
5212
5213 }
5214 return 0;
5215}
5216
5217/*
5218 * FUNCTION: wlan_hdd_cfg80211_set_cipher
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305219 * This function is used to set the encryption type
Jeff Johnson295189b2012-06-20 16:38:30 -07005220 * (NONE/WEP40/WEP104/TKIP/CCMP).
5221 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305222static int wlan_hdd_cfg80211_set_cipher( hdd_adapter_t *pAdapter,
5223 u32 cipher,
Jeff Johnson295189b2012-06-20 16:38:30 -07005224 bool ucast
5225 )
5226{
5227 eCsrEncryptionType encryptionType = eCSR_ENCRYPT_TYPE_NONE;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305228 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07005229 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
5230
5231 ENTER();
5232
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305233 if (!cipher)
Jeff Johnson295189b2012-06-20 16:38:30 -07005234 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305235 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: received cipher %d - considering none",
Jeff Johnson295189b2012-06-20 16:38:30 -07005236 __func__, cipher);
5237 encryptionType = eCSR_ENCRYPT_TYPE_NONE;
5238 }
5239 else
5240 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305241
Jeff Johnson295189b2012-06-20 16:38:30 -07005242 /*set encryption method*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305243 switch (cipher)
Jeff Johnson295189b2012-06-20 16:38:30 -07005244 {
5245 case IW_AUTH_CIPHER_NONE:
5246 encryptionType = eCSR_ENCRYPT_TYPE_NONE;
5247 break;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305248
Jeff Johnson295189b2012-06-20 16:38:30 -07005249 case WLAN_CIPHER_SUITE_WEP40:
Gopichand Nakkala29149562013-05-10 21:43:41 +05305250 encryptionType = eCSR_ENCRYPT_TYPE_WEP40;
Jeff Johnson295189b2012-06-20 16:38:30 -07005251 break;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305252
Jeff Johnson295189b2012-06-20 16:38:30 -07005253 case WLAN_CIPHER_SUITE_WEP104:
Gopichand Nakkala29149562013-05-10 21:43:41 +05305254 encryptionType = eCSR_ENCRYPT_TYPE_WEP104;
Jeff Johnson295189b2012-06-20 16:38:30 -07005255 break;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305256
Jeff Johnson295189b2012-06-20 16:38:30 -07005257 case WLAN_CIPHER_SUITE_TKIP:
5258 encryptionType = eCSR_ENCRYPT_TYPE_TKIP;
5259 break;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305260
Jeff Johnson295189b2012-06-20 16:38:30 -07005261 case WLAN_CIPHER_SUITE_CCMP:
5262 encryptionType = eCSR_ENCRYPT_TYPE_AES;
5263 break;
5264#ifdef FEATURE_WLAN_WAPI
5265 case WLAN_CIPHER_SUITE_SMS4:
5266 encryptionType = eCSR_ENCRYPT_TYPE_WPI;
5267 break;
5268#endif
5269
5270#ifdef FEATURE_WLAN_CCX
5271 case WLAN_CIPHER_SUITE_KRK:
5272 encryptionType = eCSR_ENCRYPT_TYPE_KRK;
5273 break;
5274#endif
5275 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305276 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported cipher type %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005277 __func__, cipher);
5278 return -EOPNOTSUPP;
5279 }
5280 }
5281
5282 if (ucast)
5283 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305284 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting unicast cipher type to %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005285 __func__, encryptionType);
5286 pHddStaCtx->conn_info.ucEncryptionType = encryptionType;
5287 pWextState->roamProfile.EncryptionType.numEntries = 1;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305288 pWextState->roamProfile.EncryptionType.encryptionType[0] =
Jeff Johnson295189b2012-06-20 16:38:30 -07005289 encryptionType;
5290 }
5291 else
5292 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305293 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting mcast cipher type to %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005294 __func__, encryptionType);
5295 pHddStaCtx->conn_info.mcEncryptionType = encryptionType;
5296 pWextState->roamProfile.mcEncryptionType.numEntries = 1;
5297 pWextState->roamProfile.mcEncryptionType.encryptionType[0] = encryptionType;
5298 }
5299
5300 return 0;
5301}
5302
5303
5304/*
5305 * FUNCTION: wlan_hdd_cfg80211_set_ie
5306 * This function is used to parse WPA/RSN IE's.
5307 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305308int wlan_hdd_cfg80211_set_ie( hdd_adapter_t *pAdapter,
5309 u8 *ie,
Jeff Johnson295189b2012-06-20 16:38:30 -07005310 size_t ie_len
5311 )
5312{
5313 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
5314 u8 *genie = ie;
5315 v_U16_t remLen = ie_len;
5316#ifdef FEATURE_WLAN_WAPI
5317 v_U32_t akmsuite[MAX_NUM_AKM_SUITES];
5318 u16 *tmp;
5319 v_U16_t akmsuiteCount;
5320 int *akmlist;
5321#endif
5322 ENTER();
5323
5324 /* clear previous assocAddIE */
5325 pWextState->assocAddIE.length = 0;
5326 pWextState->roamProfile.bWPSAssociation = VOS_FALSE;
5327
5328 while (remLen >= 2)
5329 {
5330 v_U16_t eLen = 0;
5331 v_U8_t elementId;
5332 elementId = *genie++;
5333 eLen = *genie++;
5334 remLen -= 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305335
5336 hddLog(VOS_TRACE_LEVEL_INFO, "%s: IE[0x%X], LEN[%d]\n",
Jeff Johnson295189b2012-06-20 16:38:30 -07005337 __func__, elementId, eLen);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305338
5339 switch ( elementId )
Jeff Johnson295189b2012-06-20 16:38:30 -07005340 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305341 case DOT11F_EID_WPA:
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005342 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 -07005343 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305344 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005345 "%s: Invalid WPA IE", __func__);
5346 return -EINVAL;
5347 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305348 else if (0 == memcmp(&genie[0], "\x00\x50\xf2\x04", 4))
Jeff Johnson295189b2012-06-20 16:38:30 -07005349 {
5350 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305351 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set WPS IE(len %d)",
Jeff Johnson295189b2012-06-20 16:38:30 -07005352 __func__, eLen + 2);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305353
Jeff Johnson295189b2012-06-20 16:38:30 -07005354 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5355 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005356 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE. "
5357 "Need bigger buffer space");
Jeff Johnson295189b2012-06-20 16:38:30 -07005358 VOS_ASSERT(0);
5359 return -ENOMEM;
5360 }
5361 // WSC IE is saved to Additional IE ; it should be accumulated to handle WPS IE + P2P IE
5362 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5363 pWextState->assocAddIE.length += eLen + 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305364
Jeff Johnson295189b2012-06-20 16:38:30 -07005365 pWextState->roamProfile.bWPSAssociation = VOS_TRUE;
5366 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5367 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5368 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305369 else if (0 == memcmp(&genie[0], "\x00\x50\xf2", 3))
5370 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005371 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set WPA IE (len %d)",__func__, eLen + 2);
5372 memset( pWextState->WPARSNIE, 0, MAX_WPA_RSN_IE_LEN );
5373 memcpy( pWextState->WPARSNIE, genie - 2, (eLen + 2) /*ie_len*/);
5374 pWextState->roamProfile.pWPAReqIE = pWextState->WPARSNIE;
5375 pWextState->roamProfile.nWPAReqIELength = eLen + 2;//ie_len;
5376 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305377 else if ( (0 == memcmp(&genie[0], P2P_OUI_TYPE,
5378 P2P_OUI_TYPE_SIZE))
Jeff Johnson295189b2012-06-20 16:38:30 -07005379 /*Consider P2P IE, only for P2P Client */
5380 && (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) )
5381 {
5382 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305383 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set P2P IE(len %d)",
Jeff Johnson295189b2012-06-20 16:38:30 -07005384 __func__, eLen + 2);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305385
Jeff Johnson295189b2012-06-20 16:38:30 -07005386 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5387 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005388 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
5389 "Need bigger buffer space");
Jeff Johnson295189b2012-06-20 16:38:30 -07005390 VOS_ASSERT(0);
5391 return -ENOMEM;
5392 }
5393 // P2P IE is saved to Additional IE ; it should be accumulated to handle WPS IE + P2P IE
5394 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5395 pWextState->assocAddIE.length += eLen + 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305396
Jeff Johnson295189b2012-06-20 16:38:30 -07005397 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5398 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5399 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005400#ifdef WLAN_FEATURE_WFD
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305401 else if ( (0 == memcmp(&genie[0], WFD_OUI_TYPE,
5402 WFD_OUI_TYPE_SIZE))
Jeff Johnson295189b2012-06-20 16:38:30 -07005403 /*Consider WFD IE, only for P2P Client */
5404 && (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) )
5405 {
5406 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305407 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set WFD IE(len %d)",
Jeff Johnson295189b2012-06-20 16:38:30 -07005408 __func__, eLen + 2);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305409
Jeff Johnson295189b2012-06-20 16:38:30 -07005410 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5411 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005412 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
5413 "Need bigger buffer space");
Jeff Johnson295189b2012-06-20 16:38:30 -07005414 VOS_ASSERT(0);
5415 return -ENOMEM;
5416 }
5417 // WFD IE is saved to Additional IE ; it should be accumulated to handle
5418 // WPS IE + P2P IE + WFD IE
5419 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5420 pWextState->assocAddIE.length += eLen + 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305421
Jeff Johnson295189b2012-06-20 16:38:30 -07005422 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5423 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5424 }
5425#endif
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005426 /* Appending HS 2.0 Indication Element in Assiciation Request */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305427 else if ( (0 == memcmp(&genie[0], HS20_OUI_TYPE,
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005428 HS20_OUI_TYPE_SIZE)) )
5429 {
5430 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305431 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set HS20 IE(len %d)",
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005432 __func__, eLen + 2);
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005433
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005434 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5435 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005436 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
5437 "Need bigger buffer space");
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005438 VOS_ASSERT(0);
5439 return -ENOMEM;
5440 }
5441 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5442 pWextState->assocAddIE.length += eLen + 2;
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005443
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005444 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5445 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5446 }
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005447
Praveen Kumar Sirisilla7d68b7b2013-09-22 14:01:42 -07005448 if (WLAN_HDD_IBSS == pAdapter->device_mode) {
5449
5450 /* populating as ADDIE in beacon frames */
5451 if (ccmCfgSetStr(WLAN_HDD_GET_HAL_CTX(pAdapter),
5452 WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA, genie - 2, eLen + 2,
5453 NULL, eANI_BOOLEAN_FALSE)== eHAL_STATUS_SUCCESS)
5454 {
5455 if (ccmCfgSetInt(WLAN_HDD_GET_HAL_CTX(pAdapter),
5456 WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG, 1,NULL,
5457 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
5458 {
5459 hddLog(LOGE,
5460 "Coldn't pass "
5461 "WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG to CCM");
5462 }
5463 }/* ccmCfgSetStr(,WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA, , )*/
5464 else
5465 hddLog(LOGE,
5466 "Could not pass on "
5467 "WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA to CCM");
5468
5469 /* IBSS mode doesn't contain params->proberesp_ies still
5470 beaconIE's need to be populated in probe response frames */
5471 if ( (NULL != (genie - 2)) && (0 != eLen + 2) )
5472 {
5473 u16 rem_probe_resp_ie_len = eLen + 2;
5474 u8 probe_rsp_ie_len[3] = {0};
5475 u8 counter = 0;
5476
5477 /* Check Probe Resp Length if it is greater then 255 then
5478 Store Probe Rsp IEs into WNI_CFG_PROBE_RSP_ADDNIE_DATA1
5479 & WNI_CFG_PROBE_RSP_ADDNIE_DATA2 CFG Variable As We are
5480 not able Store More then 255 bytes into One Variable */
5481
5482 while ((rem_probe_resp_ie_len > 0) && (counter < 3))
5483 {
5484 if (rem_probe_resp_ie_len > MAX_CFG_STRING_LEN)
5485 {
5486 probe_rsp_ie_len[counter++] = MAX_CFG_STRING_LEN;
5487 rem_probe_resp_ie_len -= MAX_CFG_STRING_LEN;
5488 }
5489 else
5490 {
5491 probe_rsp_ie_len[counter++] = rem_probe_resp_ie_len;
5492 rem_probe_resp_ie_len = 0;
5493 }
5494 }
5495
5496 rem_probe_resp_ie_len = 0;
5497
5498 if (probe_rsp_ie_len[0] > 0)
5499 {
5500 if (ccmCfgSetStr(WLAN_HDD_GET_HAL_CTX(pAdapter),
5501 WNI_CFG_PROBE_RSP_ADDNIE_DATA1,
5502 (tANI_U8*)(genie - 2),
5503 probe_rsp_ie_len[0], NULL,
5504 eANI_BOOLEAN_FALSE)
5505 == eHAL_STATUS_FAILURE)
5506 {
5507 hddLog(LOGE,
5508 "Could not pass"
5509 "on WNI_CFG_PROBE_RSP_ADDNIE_DATA1 to CCM");
5510 }
5511 rem_probe_resp_ie_len += probe_rsp_ie_len[0];
5512 }
5513
5514 if (probe_rsp_ie_len[1] > 0)
5515 {
5516 if (ccmCfgSetStr(WLAN_HDD_GET_HAL_CTX(pAdapter),
5517 WNI_CFG_PROBE_RSP_ADDNIE_DATA2,
5518 (tANI_U8*)(genie - (2 + rem_probe_resp_ie_len)),
5519 probe_rsp_ie_len[1], NULL,
5520 eANI_BOOLEAN_FALSE)
5521 == eHAL_STATUS_FAILURE)
5522 {
5523 hddLog(LOGE,
5524 "Could not pass"
5525 "on WNI_CFG_PROBE_RSP_ADDNIE_DATA2 to CCM");
5526 }
5527 rem_probe_resp_ie_len += probe_rsp_ie_len[1];
5528 }
5529
5530 if (probe_rsp_ie_len[2] > 0)
5531 {
5532 if (ccmCfgSetStr(WLAN_HDD_GET_HAL_CTX(pAdapter),
5533 WNI_CFG_PROBE_RSP_ADDNIE_DATA3,
5534 (tANI_U8*)(genie - (2 + rem_probe_resp_ie_len)),
5535 probe_rsp_ie_len[2], NULL,
5536 eANI_BOOLEAN_FALSE)
5537 == eHAL_STATUS_FAILURE)
5538 {
5539 hddLog(LOGE,
5540 "Could not pass"
5541 "on WNI_CFG_PROBE_RSP_ADDNIE_DATA3 to CCM");
5542 }
5543 rem_probe_resp_ie_len += probe_rsp_ie_len[2];
5544 }
5545
5546 if (ccmCfgSetInt(WLAN_HDD_GET_HAL_CTX(pAdapter),
5547 WNI_CFG_PROBE_RSP_ADDNIE_FLAG, 1,NULL,
5548 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
5549 {
5550 hddLog(LOGE,
5551 "Could not pass"
5552 "on WNI_CFG_PROBE_RSP_ADDNIE_FLAG to CCM");
5553 }
5554 }
5555 else
5556 {
5557 // Reset WNI_CFG_PROBE_RSP Flags
5558 wlan_hdd_reset_prob_rspies(pAdapter);
5559
5560 hddLog(VOS_TRACE_LEVEL_INFO,
5561 "%s: No Probe Response IE received in set beacon",
5562 __func__);
5563 }
5564 } /* end of if (WLAN_HDD_IBSS == pAdapter->device_mode) */
Jeff Johnson295189b2012-06-20 16:38:30 -07005565 break;
5566 case DOT11F_EID_RSN:
5567 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set RSN IE(len %d)",__func__, eLen + 2);
5568 memset( pWextState->WPARSNIE, 0, MAX_WPA_RSN_IE_LEN );
5569 memcpy( pWextState->WPARSNIE, genie - 2, (eLen + 2)/*ie_len*/);
5570 pWextState->roamProfile.pRSNReqIE = pWextState->WPARSNIE;
5571 pWextState->roamProfile.nRSNReqIELength = eLen + 2; //ie_len;
5572 break;
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005573 /* Appending Extended Capabilities with Interworking bit set in Assoc Req */
5574 case DOT11F_EID_EXTCAP:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305575 {
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005576 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305577 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set Extended CAPS IE(len %d)",
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005578 __func__, eLen + 2);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305579
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005580 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5581 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005582 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
5583 "Need bigger buffer space");
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005584 VOS_ASSERT(0);
5585 return -ENOMEM;
5586 }
5587 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5588 pWextState->assocAddIE.length += eLen + 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305589
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005590 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5591 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5592 break;
5593 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005594#ifdef FEATURE_WLAN_WAPI
5595 case WLAN_EID_WAPI:
5596 pAdapter->wapi_info.nWapiMode = 1; //Setting WAPI Mode to ON=1
5597 hddLog(VOS_TRACE_LEVEL_INFO,"WAPI MODE IS %lu \n",
5598 pAdapter->wapi_info.nWapiMode);
5599 tmp = (u16 *)ie;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305600 tmp = tmp + 2; // Skip element Id and Len, Version
Jeff Johnson295189b2012-06-20 16:38:30 -07005601 akmsuiteCount = WPA_GET_LE16(tmp);
5602 tmp = tmp + 1;
5603 akmlist = (int *)(tmp);
5604 if(akmsuiteCount <= MAX_NUM_AKM_SUITES)
5605 {
5606 memcpy(akmsuite, akmlist, (4*akmsuiteCount));
5607 }
5608 else
5609 {
5610 hddLog(VOS_TRACE_LEVEL_FATAL, "Invalid akmSuite count\n");
5611 VOS_ASSERT(0);
5612 return -EINVAL;
5613 }
5614
5615 if (WAPI_PSK_AKM_SUITE == akmsuite[0])
5616 {
5617 hddLog(VOS_TRACE_LEVEL_INFO, "%s: WAPI AUTH MODE SET TO PSK",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005618 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005619 pAdapter->wapi_info.wapiAuthMode = WAPI_AUTH_MODE_PSK;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305620 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005621 if (WAPI_CERT_AKM_SUITE == akmsuite[0])
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305622 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005623 hddLog(VOS_TRACE_LEVEL_INFO, "%s: WAPI AUTH MODE SET TO CERTIFICATE",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005624 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005625 pAdapter->wapi_info.wapiAuthMode = WAPI_AUTH_MODE_CERT;
5626 }
5627 break;
5628#endif
5629 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305630 hddLog (VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005631 "%s Set UNKNOWN IE %X", __func__, elementId);
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005632 /* when Unknown IE is received we should break and continue
5633 * to the next IE in the buffer instead we were returning
5634 * so changing this to break */
5635 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07005636 }
5637 genie += eLen;
5638 remLen -= eLen;
5639 }
5640 EXIT();
5641 return 0;
5642}
5643
5644/*
Gopichand Nakkala18f0c262013-05-07 23:25:08 +05305645 * FUNCTION: hdd_isWPAIEPresent
5646 * Parse the received IE to find the WPA IE
5647 *
5648 */
5649static bool hdd_isWPAIEPresent(u8 *ie, u8 ie_len)
5650{
5651 v_U8_t eLen = 0;
5652 v_U16_t remLen = ie_len;
5653 v_U8_t elementId = 0;
5654
5655 while (remLen >= 2)
5656 {
5657 elementId = *ie++;
5658 eLen = *ie++;
5659 remLen -= 2;
5660 if (eLen > remLen)
5661 {
5662 hddLog(VOS_TRACE_LEVEL_ERROR,
5663 "%s: IE length is wrong %d", __func__, eLen);
5664 return FALSE;
5665 }
5666 if ((elementId == DOT11F_EID_WPA) && (remLen > 5))
5667 {
5668 /* OUI - 0x00 0X50 0XF2
5669 WPA Information Element - 0x01
5670 WPA version - 0x01*/
5671 if (0 == memcmp(&ie[0], "\x00\x50\xf2\x01\x01", 5))
5672 return TRUE;
5673 }
5674 ie += eLen;
5675 remLen -= eLen;
5676 }
5677 return FALSE;
5678}
5679
5680/*
Jeff Johnson295189b2012-06-20 16:38:30 -07005681 * FUNCTION: wlan_hdd_cfg80211_set_privacy
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305682 * This function is used to initialize the security
Jeff Johnson295189b2012-06-20 16:38:30 -07005683 * parameters during connect operation.
5684 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305685int wlan_hdd_cfg80211_set_privacy( hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07005686 struct cfg80211_connect_params *req
5687 )
5688{
5689 int status = 0;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305690 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07005691 ENTER();
5692
5693 /*set wpa version*/
5694 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_DISABLED;
5695
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305696 if (req->crypto.wpa_versions)
Jeff Johnson295189b2012-06-20 16:38:30 -07005697 {
Gopichand Nakkala781ded42013-06-28 12:10:45 +05305698 if (NL80211_WPA_VERSION_1 == req->crypto.wpa_versions)
Jeff Johnson295189b2012-06-20 16:38:30 -07005699 {
5700 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA;
5701 }
5702 else if (NL80211_WPA_VERSION_2 == req->crypto.wpa_versions)
5703 {
5704 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA2;
5705 }
5706 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305707
5708 hddLog(VOS_TRACE_LEVEL_INFO, "%s: set wpa version to %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07005709 pWextState->wpaVersion);
5710
5711 /*set authentication type*/
5712 status = wlan_hdd_cfg80211_set_auth_type(pAdapter, req->auth_type);
5713
5714 if (0 > status)
5715 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305716 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005717 "%s: failed to set authentication type ", __func__);
5718 return status;
5719 }
5720
5721 /*set key mgmt type*/
5722 if (req->crypto.n_akm_suites)
5723 {
5724 status = wlan_hdd_set_akm_suite(pAdapter, req->crypto.akm_suites[0]);
5725 if (0 > status)
5726 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305727 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set akm suite",
Jeff Johnson295189b2012-06-20 16:38:30 -07005728 __func__);
5729 return status;
5730 }
5731 }
5732
5733 /*set pairwise cipher type*/
5734 if (req->crypto.n_ciphers_pairwise)
5735 {
5736 status = wlan_hdd_cfg80211_set_cipher(pAdapter,
5737 req->crypto.ciphers_pairwise[0], true);
5738 if (0 > status)
5739 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305740 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005741 "%s: failed to set unicast cipher type", __func__);
5742 return status;
5743 }
5744 }
5745 else
5746 {
5747 /*Reset previous cipher suite to none*/
5748 status = wlan_hdd_cfg80211_set_cipher(pAdapter, 0, true);
5749 if (0 > status)
5750 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305751 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005752 "%s: failed to set unicast cipher type", __func__);
5753 return status;
5754 }
5755 }
5756
5757 /*set group cipher type*/
5758 status = wlan_hdd_cfg80211_set_cipher(pAdapter, req->crypto.cipher_group,
5759 false);
5760
5761 if (0 > status)
5762 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305763 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set mcast cipher type",
Jeff Johnson295189b2012-06-20 16:38:30 -07005764 __func__);
5765 return status;
5766 }
5767
Chet Lanctot186b5732013-03-18 10:26:30 -07005768#ifdef WLAN_FEATURE_11W
5769 pWextState->roamProfile.MFPEnabled = (req->mfp == NL80211_MFP_REQUIRED);
5770#endif
5771
Jeff Johnson295189b2012-06-20 16:38:30 -07005772 /*parse WPA/RSN IE, and set the correspoing fileds in Roam profile*/
5773 if (req->ie_len)
5774 {
5775 status = wlan_hdd_cfg80211_set_ie(pAdapter, req->ie, req->ie_len);
5776 if ( 0 > status)
5777 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305778 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to parse the WPA/RSN IE",
Jeff Johnson295189b2012-06-20 16:38:30 -07005779 __func__);
5780 return status;
5781 }
5782 }
5783
5784 /*incase of WEP set default key information*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305785 if (req->key && req->key_len)
Jeff Johnson295189b2012-06-20 16:38:30 -07005786 {
5787 if ( (WLAN_CIPHER_SUITE_WEP40 == req->crypto.ciphers_pairwise[0])
5788 || (WLAN_CIPHER_SUITE_WEP104 == req->crypto.ciphers_pairwise[0])
5789 )
5790 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305791 if ( IW_AUTH_KEY_MGMT_802_1X
Jeff Johnson295189b2012-06-20 16:38:30 -07005792 == (pWextState->authKeyMgmt & IW_AUTH_KEY_MGMT_802_1X ))
5793 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305794 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Dynamic WEP not supported",
Jeff Johnson295189b2012-06-20 16:38:30 -07005795 __func__);
5796 return -EOPNOTSUPP;
5797 }
5798 else
5799 {
5800 u8 key_len = req->key_len;
5801 u8 key_idx = req->key_idx;
5802
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305803 if ((eCSR_SECURITY_WEP_KEYSIZE_MAX_BYTES >= key_len)
Jeff Johnson295189b2012-06-20 16:38:30 -07005804 && (CSR_MAX_NUM_KEY > key_idx)
5805 )
5806 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305807 hddLog(VOS_TRACE_LEVEL_INFO,
5808 "%s: setting default wep key, key_idx = %hu key_len %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07005809 __func__, key_idx, key_len);
5810 vos_mem_copy(
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305811 &pWextState->roamProfile.Keys.KeyMaterial[key_idx][0],
Jeff Johnson295189b2012-06-20 16:38:30 -07005812 req->key, key_len);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305813 pWextState->roamProfile.Keys.KeyLength[key_idx] =
Jeff Johnson295189b2012-06-20 16:38:30 -07005814 (u8)key_len;
5815 pWextState->roamProfile.Keys.defaultIndex = (u8)key_idx;
5816 }
5817 }
5818 }
5819 }
5820
5821 return status;
5822}
5823
5824/*
5825 * FUNCTION: wlan_hdd_cfg80211_set_privacy
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305826 * This function is used to initialize the security
Jeff Johnson295189b2012-06-20 16:38:30 -07005827 * parameters during connect operation.
5828 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305829static int wlan_hdd_cfg80211_connect( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07005830 struct net_device *ndev,
5831 struct cfg80211_connect_params *req
5832 )
5833{
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305834 int status;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305835 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Jeff Johnson295189b2012-06-20 16:38:30 -07005836 VOS_STATUS exitbmpsStatus = VOS_STATUS_E_INVAL;
5837 hdd_context_t *pHddCtx = NULL;
5838
5839 ENTER();
5840
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305841 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07005842 "%s: device_mode = %d\n",__func__,pAdapter->device_mode);
5843
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305844 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
5845 status = wlan_hdd_validate_context(pHddCtx);
5846
5847 if (0 != status)
Jeff Johnson295189b2012-06-20 16:38:30 -07005848 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305849 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5850 "%s: HDD context is not valid", __func__);
5851 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07005852 }
5853
5854#ifdef WLAN_BTAMP_FEATURE
5855 //Infra connect not supported when AMP traffic is on.
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305856 if( VOS_TRUE == WLANBAP_AmpSessionOn() )
Jeff Johnson295189b2012-06-20 16:38:30 -07005857 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305858 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005859 "%s: No connection when AMP is on", __func__);
Madan Mohan Koyyalamudicae253a2012-11-06 19:10:35 -08005860 return -ECONNREFUSED;
Jeff Johnson295189b2012-06-20 16:38:30 -07005861 }
5862#endif
5863 /*initialise security parameters*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305864 status = wlan_hdd_cfg80211_set_privacy(pAdapter, req);
Jeff Johnson295189b2012-06-20 16:38:30 -07005865
5866 if ( 0 > status)
5867 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305868 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set security params",
Jeff Johnson295189b2012-06-20 16:38:30 -07005869 __func__);
5870 return status;
5871 }
5872
5873 //If Device Mode is Station Concurrent Sessions Exit BMps
Jeff Johnsona8a1a482012-12-12 16:49:33 -08005874 //P2P Mode will be taken care in Open/close adapter
Jeff Johnson295189b2012-06-20 16:38:30 -07005875 if((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) &&
5876 (vos_concurrent_sessions_running()))
5877 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305878 exitbmpsStatus = hdd_disable_bmps_imps(pHddCtx, WLAN_HDD_INFRA_STATION);
Jeff Johnson295189b2012-06-20 16:38:30 -07005879 }
5880
Mohit Khanna765234a2012-09-11 15:08:35 -07005881 if ( req->channel )
5882 {
5883 status = wlan_hdd_cfg80211_connect_start(pAdapter, req->ssid,
5884 req->ssid_len, req->bssid,
5885 req->channel->hw_value);
5886 }
5887 else
5888 {
5889 status = wlan_hdd_cfg80211_connect_start(pAdapter, req->ssid,
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305890 req->ssid_len, req->bssid, 0);
Mohit Khanna765234a2012-09-11 15:08:35 -07005891 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005892
5893 if (0 > status)
5894 {
5895 //ReEnable BMPS if disabled
5896 if((VOS_STATUS_SUCCESS == exitbmpsStatus) &&
5897 (NULL != pHddCtx))
5898 {
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05305899 if (pHddCtx->hdd_wlan_suspended)
5900 {
5901 hdd_set_pwrparams(pHddCtx);
5902 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005903 //ReEnable Bmps and Imps back
5904 hdd_enable_bmps_imps(pHddCtx);
5905 }
5906
5907 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: connect failed", __func__);
5908 return status;
5909 }
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305910 pHddCtx->isAmpAllowed = VOS_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005911 EXIT();
5912 return status;
5913}
5914
5915
5916/*
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05305917 * FUNCTION: wlan_hdd_disconnect
5918 * This function is used to issue a disconnect request to SME
5919 */
5920int wlan_hdd_disconnect( hdd_adapter_t *pAdapter, u16 reason )
5921{
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305922 int status;
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05305923 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305924 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
5925
5926 status = wlan_hdd_validate_context(pHddCtx);
5927
5928 if (0 != status)
5929 {
5930 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5931 "%s: HDD context is not valid", __func__);
5932 return status;
5933 }
5934
5935 pHddCtx->isAmpAllowed = VOS_TRUE;
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05305936 pHddStaCtx->conn_info.connState = eConnectionState_NotConnected;
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05305937 INIT_COMPLETION(pAdapter->disconnect_comp_var);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305938
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05305939 /*issue disconnect*/
5940 status = sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
5941 pAdapter->sessionId, reason);
5942
5943 if ( 0 != status )
5944 {
5945 hddLog(VOS_TRACE_LEVEL_ERROR,
5946 "%s csrRoamDisconnect failure, returned %d \n",
5947 __func__, (int)status );
5948 return -EINVAL;
5949 }
5950 wait_for_completion_interruptible_timeout(
5951 &pAdapter->disconnect_comp_var,
5952 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
5953 /*stop tx queues*/
5954 netif_tx_disable(pAdapter->dev);
5955 netif_carrier_off(pAdapter->dev);
5956 return status;
5957}
5958
5959
5960/*
Jeff Johnson295189b2012-06-20 16:38:30 -07005961 * FUNCTION: wlan_hdd_cfg80211_disconnect
5962 * This function is used to issue a disconnect request to SME
5963 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305964static int wlan_hdd_cfg80211_disconnect( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07005965 struct net_device *dev,
5966 u16 reason
5967 )
5968{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305969 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
5970 tCsrRoamProfile *pRoamProfile =
Jeff Johnson295189b2012-06-20 16:38:30 -07005971 &(WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter))->roamProfile;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305972 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07005973 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkala4327a152013-03-04 23:22:42 -08005974 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05305975#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08005976 tANI_U8 staIdx;
5977#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305978
Jeff Johnson295189b2012-06-20 16:38:30 -07005979 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305980
5981 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
Jeff Johnson295189b2012-06-20 16:38:30 -07005982 __func__,pAdapter->device_mode);
5983
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305984 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Disconnect called with reason code %d",
5985 __func__, reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07005986
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305987 status = wlan_hdd_validate_context(pHddCtx);
5988
5989 if (0 != status)
Jeff Johnson295189b2012-06-20 16:38:30 -07005990 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305991 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5992 "%s: HDD context is not valid", __func__);
5993 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07005994 }
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305995
Jeff Johnson295189b2012-06-20 16:38:30 -07005996 if (NULL != pRoamProfile)
5997 {
5998 /*issue disconnect request to SME, if station is in connected state*/
5999 if (pHddStaCtx->conn_info.connState == eConnectionState_Associated)
6000 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306001 eCsrRoamDisconnectReason reasonCode =
Jeff Johnson295189b2012-06-20 16:38:30 -07006002 eCSR_DISCONNECT_REASON_UNSPECIFIED;
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05306003 hdd_scaninfo_t *pScanInfo;
Jeff Johnson295189b2012-06-20 16:38:30 -07006004 switch(reason)
6005 {
6006 case WLAN_REASON_MIC_FAILURE:
6007 reasonCode = eCSR_DISCONNECT_REASON_MIC_ERROR;
6008 break;
6009
6010 case WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY:
6011 case WLAN_REASON_DISASSOC_AP_BUSY:
6012 case WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA:
6013 reasonCode = eCSR_DISCONNECT_REASON_DISASSOC;
6014 break;
6015
6016 case WLAN_REASON_PREV_AUTH_NOT_VALID:
6017 case WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA:
6018 reasonCode = eCSR_DISCONNECT_REASON_DEAUTH;
6019 break;
6020
6021 case WLAN_REASON_DEAUTH_LEAVING:
6022 default:
6023 reasonCode = eCSR_DISCONNECT_REASON_UNSPECIFIED;
6024 break;
6025 }
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05306026 pHddStaCtx->conn_info.connState = eConnectionState_NotConnected;
6027 pScanInfo = &pHddCtx->scan_info;
6028 if (pScanInfo->mScanPending)
6029 {
6030 hddLog(VOS_TRACE_LEVEL_INFO, "Disconnect is in progress, "
6031 "Aborting Scan");
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05306032 hdd_abort_mac_scan(pHddCtx, pAdapter->sessionId);
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05306033 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006034
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006035#ifdef FEATURE_WLAN_TDLS
6036 /* First clean up the tdls peers if any */
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006037 for (staIdx = 0 ; staIdx < HDD_MAX_NUM_TDLS_STA; staIdx++)
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006038 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006039 if ((pHddCtx->tdlsConnInfo[staIdx].sessionId == pAdapter->sessionId) &&
6040 (pHddCtx->tdlsConnInfo[staIdx].staId))
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006041 {
Hoonki Lee11f7dda2013-02-14 16:55:44 -08006042 uint8 *mac;
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006043 mac = pHddCtx->tdlsConnInfo[staIdx].peerMac.bytes;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08006044 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07006045 "%s: call sme_DeleteTdlsPeerSta staId %d sessionId %d " MAC_ADDRESS_STR,
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006046 __func__, pHddCtx->tdlsConnInfo[staIdx].staId, pAdapter->sessionId,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07006047 MAC_ADDR_ARRAY(mac));
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006048 sme_DeleteTdlsPeerSta(WLAN_HDD_GET_HAL_CTX(pAdapter),
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006049 pAdapter->sessionId,
6050 mac);
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08006051 }
6052 }
6053#endif
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306054 status = wlan_hdd_disconnect(pAdapter, reasonCode);
6055 if ( 0 != status )
Jeff Johnson295189b2012-06-20 16:38:30 -07006056 {
6057 hddLog(VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306058 "%s wlan_hdd_disconnect failure, returned %d \n",
Jeff Johnson295189b2012-06-20 16:38:30 -07006059 __func__, (int)status );
6060 return -EINVAL;
6061 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006062 }
6063 }
6064 else
6065 {
6066 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: No valid roam profile", __func__);
6067 }
6068
6069 return status;
6070}
6071
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05306072
Jeff Johnson295189b2012-06-20 16:38:30 -07006073/*
6074 * FUNCTION: wlan_hdd_cfg80211_set_privacy_ibss
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306075 * This function is used to initialize the security
Jeff Johnson295189b2012-06-20 16:38:30 -07006076 * settings in IBSS mode.
6077 */
6078static int wlan_hdd_cfg80211_set_privacy_ibss(
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306079 hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07006080 struct cfg80211_ibss_params *params
6081 )
6082{
6083 int status = 0;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306084 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07006085 eCsrEncryptionType encryptionType = eCSR_ENCRYPT_TYPE_NONE;
6086 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306087
Jeff Johnson295189b2012-06-20 16:38:30 -07006088 ENTER();
6089
6090 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_DISABLED;
6091
6092 if (params->ie_len && ( NULL != params->ie) )
6093 {
Shailender Karmuchi67edd312013-06-18 16:30:48 -07006094 if (wlan_hdd_cfg80211_get_ie_ptr (params->ie,
6095 params->ie_len, WLAN_EID_RSN ))
Jeff Johnson295189b2012-06-20 16:38:30 -07006096 {
6097 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA2;
6098 encryptionType = eCSR_ENCRYPT_TYPE_AES;
6099 }
Shailender Karmuchi67edd312013-06-18 16:30:48 -07006100 else if ( hdd_isWPAIEPresent (params->ie, params->ie_len ))
Jeff Johnson295189b2012-06-20 16:38:30 -07006101 {
Shailender Karmuchi642e9812013-05-30 14:34:49 -07006102 tDot11fIEWPA dot11WPAIE;
6103 tHalHandle halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
Shailender Karmuchi67edd312013-06-18 16:30:48 -07006104 u8 *ie;
Shailender Karmuchi642e9812013-05-30 14:34:49 -07006105
Shailender Karmuchi67edd312013-06-18 16:30:48 -07006106 ie = wlan_hdd_cfg80211_get_ie_ptr (params->ie,
6107 params->ie_len, DOT11F_EID_WPA);
6108 if ( NULL != ie )
6109 {
6110 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA;
6111 // Unpack the WPA IE
6112 //Skip past the EID byte and length byte - and four byte WiFi OUI
6113 dot11fUnpackIeWPA((tpAniSirGlobal) halHandle,
6114 &ie[2+4],
6115 ie[1] - 4,
6116 &dot11WPAIE);
6117 /*Extract the multicast cipher, the encType for unicast
6118 cipher for wpa-none is none*/
6119 encryptionType =
6120 hdd_TranslateWPAToCsrEncryptionType(dot11WPAIE.multicast_cipher);
6121 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006122 }
Shailender Karmuchi67edd312013-06-18 16:30:48 -07006123
Jeff Johnson295189b2012-06-20 16:38:30 -07006124 status = wlan_hdd_cfg80211_set_ie(pAdapter, params->ie, params->ie_len);
6125
6126 if (0 > status)
6127 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306128 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to parse WPA/RSN IE",
Jeff Johnson295189b2012-06-20 16:38:30 -07006129 __func__);
6130 return status;
6131 }
6132 }
6133
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306134 pWextState->roamProfile.AuthType.authType[0] =
6135 pHddStaCtx->conn_info.authType =
Jeff Johnson295189b2012-06-20 16:38:30 -07006136 eCSR_AUTH_TYPE_OPEN_SYSTEM;
6137
6138 if (params->privacy)
6139 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306140 /* Security enabled IBSS, At this time there is no information available
6141 * about the security paramters, so initialise the encryption type to
Jeff Johnson295189b2012-06-20 16:38:30 -07006142 * eCSR_ENCRYPT_TYPE_WEP40_STATICKEY.
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306143 * The correct security parameters will be updated later in
Jeff Johnson295189b2012-06-20 16:38:30 -07006144 * wlan_hdd_cfg80211_add_key */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306145 /* Hal expects encryption type to be set inorder
Jeff Johnson295189b2012-06-20 16:38:30 -07006146 *enable privacy bit in beacons */
6147
6148 encryptionType = eCSR_ENCRYPT_TYPE_WEP40_STATICKEY;
6149 }
Shailender Karmuchi642e9812013-05-30 14:34:49 -07006150 VOS_TRACE (VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
6151 "encryptionType=%d", encryptionType);
Jeff Johnson295189b2012-06-20 16:38:30 -07006152 pHddStaCtx->conn_info.ucEncryptionType = encryptionType;
6153 pWextState->roamProfile.EncryptionType.numEntries = 1;
6154 pWextState->roamProfile.EncryptionType.encryptionType[0] = encryptionType;
Jeff Johnson295189b2012-06-20 16:38:30 -07006155 return status;
6156}
6157
6158/*
6159 * FUNCTION: wlan_hdd_cfg80211_join_ibss
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306160 * This function is used to create/join an IBSS
Jeff Johnson295189b2012-06-20 16:38:30 -07006161 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306162static int wlan_hdd_cfg80211_join_ibss( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07006163 struct net_device *dev,
6164 struct cfg80211_ibss_params *params
6165 )
6166{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306167 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Jeff Johnson295189b2012-06-20 16:38:30 -07006168 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
6169 tCsrRoamProfile *pRoamProfile;
6170 int status;
6171 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306172 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07006173
6174 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306175
6176 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07006177 "%s: device_mode = %d\n",__func__,pAdapter->device_mode);
6178
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306179 status = wlan_hdd_validate_context(pHddCtx);
6180
6181 if (0 != status)
Jeff Johnson295189b2012-06-20 16:38:30 -07006182 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306183 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6184 "%s: HDD context is not valid", __func__);
6185 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006186 }
6187
6188 if (NULL == pWextState)
6189 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306190 hddLog (VOS_TRACE_LEVEL_ERROR, "%s ERROR: Data Storage Corruption\n",
Jeff Johnson295189b2012-06-20 16:38:30 -07006191 __func__);
6192 return -EIO;
6193 }
6194
6195 pRoamProfile = &pWextState->roamProfile;
6196
6197 if ( eCSR_BSS_TYPE_START_IBSS != pRoamProfile->BSSType )
6198 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306199 hddLog (VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07006200 "%s Interface type is not set to IBSS \n", __func__);
6201 return -EINVAL;
6202 }
6203
6204 /* Set Channel */
Yue Maf49ba872013-08-19 12:04:25 -07006205 if (NULL !=
6206#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0))
6207 params->chandef.chan)
6208#else
6209 params->channel)
6210#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006211 {
6212 u8 channelNum;
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006213 v_U32_t numChans = WNI_CFG_VALID_CHANNEL_LIST_LEN;
6214 v_U8_t validChan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
6215 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
6216 int indx;
Jeff Johnson295189b2012-06-20 16:38:30 -07006217
6218 /* Get channel number */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306219 channelNum =
Yue Maf49ba872013-08-19 12:04:25 -07006220 ieee80211_frequency_to_channel(
6221#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0))
6222 params->chandef.chan->center_freq);
6223#else
6224 params->channel->center_freq);
6225#endif
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006226
6227 if (0 != ccmCfgGetStr(hHal, WNI_CFG_VALID_CHANNEL_LIST,
6228 validChan, &numChans))
Jeff Johnson295189b2012-06-20 16:38:30 -07006229 {
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006230 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: No valid channel list",
6231 __func__);
6232 return -EOPNOTSUPP;
Jeff Johnson295189b2012-06-20 16:38:30 -07006233 }
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006234
6235 for (indx = 0; indx < numChans; indx++)
Jeff Johnson295189b2012-06-20 16:38:30 -07006236 {
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006237 if (channelNum == validChan[indx])
6238 {
6239 break;
6240 }
6241 }
6242 if (indx >= numChans)
6243 {
6244 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Not valid Channel %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07006245 __func__, channelNum);
6246 return -EINVAL;
6247 }
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006248 /* Set the Operational Channel */
6249 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: set channel %d", __func__,
6250 channelNum);
6251 pRoamProfile->ChannelInfo.numOfChannels = 1;
6252 pHddStaCtx->conn_info.operationChannel = channelNum;
6253 pRoamProfile->ChannelInfo.ChannelList =
6254 &pHddStaCtx->conn_info.operationChannel;
Jeff Johnson295189b2012-06-20 16:38:30 -07006255 }
6256
6257 /* Initialize security parameters */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306258 status = wlan_hdd_cfg80211_set_privacy_ibss(pAdapter, params);
Jeff Johnson295189b2012-06-20 16:38:30 -07006259 if (status < 0)
6260 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306261 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set security parameters",
Jeff Johnson295189b2012-06-20 16:38:30 -07006262 __func__);
6263 return status;
6264 }
6265
6266 /* Issue connect start */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306267 status = wlan_hdd_cfg80211_connect_start(pAdapter, params->ssid,
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006268 params->ssid_len, params->bssid,
6269 pHddStaCtx->conn_info.operationChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07006270
6271 if (0 > status)
6272 {
6273 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: connect failed", __func__);
6274 return status;
6275 }
6276
6277 return 0;
6278}
6279
6280/*
6281 * FUNCTION: wlan_hdd_cfg80211_leave_ibss
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306282 * This function is used to leave an IBSS
Jeff Johnson295189b2012-06-20 16:38:30 -07006283 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306284static int wlan_hdd_cfg80211_leave_ibss( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07006285 struct net_device *dev
6286 )
6287{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306288 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Jeff Johnson295189b2012-06-20 16:38:30 -07006289 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
6290 tCsrRoamProfile *pRoamProfile;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306291 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
6292 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006293
6294 ENTER();
6295
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306296 status = wlan_hdd_validate_context(pHddCtx);
6297
6298 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006299 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306300 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6301 "%s: HDD context is not valid", __func__);
6302 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006303 }
6304
Jeff Johnson295189b2012-06-20 16:38:30 -07006305 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",__func__,pAdapter->device_mode);
6306 if (NULL == pWextState)
6307 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306308 hddLog (VOS_TRACE_LEVEL_ERROR, "%s ERROR: Data Storage Corruption\n",
Jeff Johnson295189b2012-06-20 16:38:30 -07006309 __func__);
6310 return -EIO;
6311 }
6312
6313 pRoamProfile = &pWextState->roamProfile;
6314
6315 /* Issue disconnect only if interface type is set to IBSS */
6316 if (eCSR_BSS_TYPE_START_IBSS != pRoamProfile->BSSType)
6317 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306318 hddLog (VOS_TRACE_LEVEL_ERROR, "%s: BSS Type is not set to IBSS",
Jeff Johnson295189b2012-06-20 16:38:30 -07006319 __func__);
6320 return -EINVAL;
6321 }
6322
6323 /* Issue Disconnect request */
6324 INIT_COMPLETION(pAdapter->disconnect_comp_var);
6325 sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter), pAdapter->sessionId,
6326 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
6327
6328 return 0;
6329}
6330
6331/*
6332 * FUNCTION: wlan_hdd_cfg80211_set_wiphy_params
6333 * This function is used to set the phy parameters
6334 * (RTS Threshold/FRAG Threshold/Retry Count etc ...)
6335 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306336static int wlan_hdd_cfg80211_set_wiphy_params(struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07006337 u32 changed)
6338{
6339 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
6340 tHalHandle hHal = pHddCtx->hHal;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306341 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006342
6343 ENTER();
6344
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306345 status = wlan_hdd_validate_context(pHddCtx);
6346
6347 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006348 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306349 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6350 "%s: HDD context is not valid", __func__);
6351 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006352 }
6353
Jeff Johnson295189b2012-06-20 16:38:30 -07006354 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
6355 {
6356 u16 rts_threshold = (wiphy->rts_threshold == -1) ?
6357 WNI_CFG_RTS_THRESHOLD_STAMAX :
6358 wiphy->rts_threshold;
6359
6360 if ((WNI_CFG_RTS_THRESHOLD_STAMIN > rts_threshold) ||
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306361 (WNI_CFG_RTS_THRESHOLD_STAMAX < rts_threshold))
Jeff Johnson295189b2012-06-20 16:38:30 -07006362 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306363 hddLog(VOS_TRACE_LEVEL_ERROR,
6364 "%s: Invalid RTS Threshold value %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006365 __func__, rts_threshold);
6366 return -EINVAL;
6367 }
6368
6369 if (0 != ccmCfgSetInt(hHal, WNI_CFG_RTS_THRESHOLD,
6370 rts_threshold, ccmCfgSetCallback,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306371 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07006372 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306373 hddLog(VOS_TRACE_LEVEL_ERROR,
6374 "%s: ccmCfgSetInt failed for rts_threshold value %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006375 __func__, rts_threshold);
6376 return -EIO;
6377 }
6378
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306379 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set rts threshold %hu", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07006380 rts_threshold);
6381 }
6382
6383 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
6384 {
6385 u16 frag_threshold = (wiphy->frag_threshold == -1) ?
6386 WNI_CFG_FRAGMENTATION_THRESHOLD_STAMAX :
6387 wiphy->frag_threshold;
6388
6389 if ((WNI_CFG_FRAGMENTATION_THRESHOLD_STAMIN > frag_threshold)||
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306390 (WNI_CFG_FRAGMENTATION_THRESHOLD_STAMAX < frag_threshold) )
Jeff Johnson295189b2012-06-20 16:38:30 -07006391 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306392 hddLog(VOS_TRACE_LEVEL_ERROR,
6393 "%s: Invalid frag_threshold value %hu", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07006394 frag_threshold);
6395 return -EINVAL;
6396 }
6397
6398 if (0 != ccmCfgSetInt(hHal, WNI_CFG_FRAGMENTATION_THRESHOLD,
6399 frag_threshold, ccmCfgSetCallback,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306400 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07006401 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306402 hddLog(VOS_TRACE_LEVEL_ERROR,
6403 "%s: ccmCfgSetInt failed for frag_threshold value %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006404 __func__, frag_threshold);
6405 return -EIO;
6406 }
6407
6408 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set frag threshold %hu", __func__,
6409 frag_threshold);
6410 }
6411
6412 if ((changed & WIPHY_PARAM_RETRY_SHORT)
6413 || (changed & WIPHY_PARAM_RETRY_LONG))
6414 {
6415 u8 retry_value = (changed & WIPHY_PARAM_RETRY_SHORT) ?
6416 wiphy->retry_short :
6417 wiphy->retry_long;
6418
6419 if ((WNI_CFG_LONG_RETRY_LIMIT_STAMIN > retry_value) ||
6420 (WNI_CFG_LONG_RETRY_LIMIT_STAMAX < retry_value))
6421 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306422 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006423 __func__, retry_value);
6424 return -EINVAL;
6425 }
6426
6427 if (changed & WIPHY_PARAM_RETRY_SHORT)
6428 {
6429 if (0 != ccmCfgSetInt(hHal, WNI_CFG_LONG_RETRY_LIMIT,
6430 retry_value, ccmCfgSetCallback,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306431 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07006432 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306433 hddLog(VOS_TRACE_LEVEL_ERROR,
6434 "%s: ccmCfgSetInt failed for long retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006435 __func__, retry_value);
6436 return -EIO;
6437 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306438 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set long retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006439 __func__, retry_value);
6440 }
6441 else if (changed & WIPHY_PARAM_RETRY_SHORT)
6442 {
6443 if (0 != ccmCfgSetInt(hHal, WNI_CFG_SHORT_RETRY_LIMIT,
6444 retry_value, ccmCfgSetCallback,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306445 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07006446 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306447 hddLog(VOS_TRACE_LEVEL_ERROR,
6448 "%s: ccmCfgSetInt failed for short retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006449 __func__, retry_value);
6450 return -EIO;
6451 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306452 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set short retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006453 __func__, retry_value);
6454 }
6455 }
6456
6457 return 0;
6458}
6459
6460/*
6461 * FUNCTION: wlan_hdd_cfg80211_set_txpower
6462 * This function is used to set the txpower
6463 */
6464static int wlan_hdd_cfg80211_set_txpower(struct wiphy *wiphy,
Yue Maf49ba872013-08-19 12:04:25 -07006465#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0)
6466 struct wireless_dev *wdev,
6467#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006468#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,35)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306469 enum tx_power_setting type,
Jeff Johnson295189b2012-06-20 16:38:30 -07006470#else
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306471 enum nl80211_tx_power_setting type,
Jeff Johnson295189b2012-06-20 16:38:30 -07006472#endif
6473 int dbm)
6474{
6475 hdd_context_t *pHddCtx = (hdd_context_t*) wiphy_priv(wiphy);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306476 tHalHandle hHal = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07006477 tSirMacAddr bssid = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
6478 tSirMacAddr selfMac = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306479 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006480
6481 ENTER();
6482
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306483 status = wlan_hdd_validate_context(pHddCtx);
6484
6485 if (0 != status)
6486 {
6487 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6488 "%s: HDD context is not valid", __func__);
6489 return status;
6490 }
6491
6492 hHal = pHddCtx->hHal;
6493
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306494 if (0 != ccmCfgSetInt(hHal, WNI_CFG_CURRENT_TX_POWER_LEVEL,
6495 dbm, ccmCfgSetCallback,
6496 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07006497 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306498 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07006499 "%s: ccmCfgSetInt failed for tx power %hu", __func__, dbm);
6500 return -EIO;
6501 }
6502
6503 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set tx power level %d dbm", __func__,
6504 dbm);
6505
6506 switch(type)
6507 {
6508 case NL80211_TX_POWER_AUTOMATIC: /*automatically determine transmit power*/
6509 /* Fall through */
6510 case NL80211_TX_POWER_LIMITED: /*limit TX power by the mBm parameter*/
6511 if( sme_SetMaxTxPower(hHal, bssid, selfMac, dbm) != eHAL_STATUS_SUCCESS )
6512 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306513 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Setting maximum tx power failed",
6514 __func__);
6515 return -EIO;
Jeff Johnson295189b2012-06-20 16:38:30 -07006516 }
6517 break;
6518 case NL80211_TX_POWER_FIXED: /*fix TX power to the mBm parameter*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306519 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: NL80211_TX_POWER_FIXED not supported",
Jeff Johnson295189b2012-06-20 16:38:30 -07006520 __func__);
6521 return -EOPNOTSUPP;
6522 break;
6523 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306524 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid power setting type %d",
6525 __func__, type);
Jeff Johnson295189b2012-06-20 16:38:30 -07006526 return -EIO;
6527 }
6528
6529 return 0;
6530}
6531
6532/*
6533 * FUNCTION: wlan_hdd_cfg80211_get_txpower
6534 * This function is used to read the txpower
6535 */
Yue Maf49ba872013-08-19 12:04:25 -07006536static int wlan_hdd_cfg80211_get_txpower(struct wiphy *wiphy,
6537#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0)
6538 struct wireless_dev *wdev,
6539#endif
6540 int *dbm)
Jeff Johnson295189b2012-06-20 16:38:30 -07006541{
6542
6543 hdd_adapter_t *pAdapter;
6544 hdd_context_t *pHddCtx = (hdd_context_t*) wiphy_priv(wiphy);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306545 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006546
Jeff Johnsone7245742012-09-05 17:12:55 -07006547 ENTER();
6548
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306549 status = wlan_hdd_validate_context(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07006550
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306551 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006552 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306553 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6554 "%s: HDD context is not valid", __func__);
6555 *dbm = 0;
6556 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006557 }
6558
Jeff Johnson295189b2012-06-20 16:38:30 -07006559 pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_INFRA_STATION);
6560 if (NULL == pAdapter)
6561 {
6562 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Not in station context " ,__func__);
6563 return -ENOENT;
6564 }
6565
6566 wlan_hdd_get_classAstats(pAdapter);
6567 *dbm = pAdapter->hdd_stats.ClassA_stat.max_pwr;
6568
Jeff Johnsone7245742012-09-05 17:12:55 -07006569 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07006570 return 0;
6571}
6572
6573static int wlan_hdd_cfg80211_get_station(struct wiphy *wiphy, struct net_device *dev,
6574 u8* mac, struct station_info *sinfo)
6575{
6576 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
6577 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
6578 int ssidlen = pHddStaCtx->conn_info.SSID.SSID.length;
6579 tANI_U8 rate_flags;
6580
6581 hdd_context_t *pHddCtx = (hdd_context_t*) wiphy_priv(wiphy);
6582 hdd_config_t *pCfg = pHddCtx->cfg_ini;
Jeff Johnson295189b2012-06-20 16:38:30 -07006583
6584 tANI_U8 OperationalRates[CSR_DOT11_SUPPORTED_RATES_MAX];
6585 tANI_U32 ORLeng = CSR_DOT11_SUPPORTED_RATES_MAX;
6586 tANI_U8 ExtendedRates[CSR_DOT11_EXTENDED_SUPPORTED_RATES_MAX];
6587 tANI_U32 ERLeng = CSR_DOT11_EXTENDED_SUPPORTED_RATES_MAX;
6588 tANI_U8 MCSRates[SIZE_OF_BASIC_MCS_SET];
6589 tANI_U32 MCSLeng = SIZE_OF_BASIC_MCS_SET;
6590 tANI_U16 maxRate = 0;
6591 tANI_U16 myRate;
6592 tANI_U16 currentRate = 0;
6593 tANI_U8 maxSpeedMCS = 0;
6594 tANI_U8 maxMCSIdx = 0;
6595 tANI_U8 rateFlag = 1;
6596 tANI_U8 i, j, rssidx;
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07006597 tANI_U16 temp;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306598 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006599
Leo Chang6f8870f2013-03-26 18:11:36 -07006600#ifdef WLAN_FEATURE_11AC
6601 tANI_U32 vht_mcs_map;
6602 eDataRate11ACMaxMcs vhtMaxMcs;
6603#endif /* WLAN_FEATURE_11AC */
6604
Jeff Johnsone7245742012-09-05 17:12:55 -07006605 ENTER();
6606
Jeff Johnson295189b2012-06-20 16:38:30 -07006607 if ((eConnectionState_Associated != pHddStaCtx->conn_info.connState) ||
6608 (0 == ssidlen))
6609 {
6610 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Not associated or"
6611 " Invalid ssidlen, %d", __func__, ssidlen);
6612 /*To keep GUI happy*/
6613 return 0;
6614 }
6615
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306616 status = wlan_hdd_validate_context(pHddCtx);
6617
6618 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006619 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306620 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6621 "%s: HDD context is not valid", __func__);
6622 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006623 }
6624
Jeff Johnson295189b2012-06-20 16:38:30 -07006625 wlan_hdd_get_rssi(pAdapter, &sinfo->signal);
6626 sinfo->filled |= STATION_INFO_SIGNAL;
6627
Madan Mohan Koyyalamudi4d4d2812012-09-24 14:08:29 -07006628 wlan_hdd_get_station_stats(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07006629 rate_flags = pAdapter->hdd_stats.ClassA_stat.tx_rate_flags;
6630
6631 //convert to the UI units of 100kbps
6632 myRate = pAdapter->hdd_stats.ClassA_stat.tx_rate * 5;
6633
6634#ifdef LINKSPEED_DEBUG_ENABLED
Leo Chang6f8870f2013-03-26 18:11:36 -07006635 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 -07006636 sinfo->signal,
6637 pCfg->reportMaxLinkSpeed,
6638 myRate,
6639 (int) pCfg->linkSpeedRssiHigh,
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07006640 (int) pCfg->linkSpeedRssiMid,
6641 (int) pCfg->linkSpeedRssiLow,
Leo Chang6f8870f2013-03-26 18:11:36 -07006642 (int) rate_flags,
6643 (int) pAdapter->hdd_stats.ClassA_stat.mcs_index);
Jeff Johnson295189b2012-06-20 16:38:30 -07006644#endif //LINKSPEED_DEBUG_ENABLED
6645
6646 if (eHDD_LINK_SPEED_REPORT_ACTUAL != pCfg->reportMaxLinkSpeed)
6647 {
6648 // we do not want to necessarily report the current speed
6649 if (eHDD_LINK_SPEED_REPORT_MAX == pCfg->reportMaxLinkSpeed)
6650 {
6651 // report the max possible speed
6652 rssidx = 0;
6653 }
6654 else if (eHDD_LINK_SPEED_REPORT_MAX_SCALED == pCfg->reportMaxLinkSpeed)
6655 {
6656 // report the max possible speed with RSSI scaling
6657 if (sinfo->signal >= pCfg->linkSpeedRssiHigh)
6658 {
6659 // report the max possible speed
6660 rssidx = 0;
6661 }
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07006662 else if (sinfo->signal >= pCfg->linkSpeedRssiMid)
Jeff Johnson295189b2012-06-20 16:38:30 -07006663 {
6664 // report middle speed
6665 rssidx = 1;
6666 }
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07006667 else if (sinfo->signal >= pCfg->linkSpeedRssiLow)
6668 {
6669 // report middle speed
6670 rssidx = 2;
6671 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006672 else
6673 {
6674 // report actual speed
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07006675 rssidx = 3;
Jeff Johnson295189b2012-06-20 16:38:30 -07006676 }
6677 }
6678 else
6679 {
6680 // unknown, treat as eHDD_LINK_SPEED_REPORT_MAX
6681 hddLog(VOS_TRACE_LEVEL_ERROR,
6682 "%s: Invalid value for reportMaxLinkSpeed: %u",
6683 __func__, pCfg->reportMaxLinkSpeed);
6684 rssidx = 0;
6685 }
6686
6687 maxRate = 0;
6688
6689 /* Get Basic Rate Set */
Gopichand Nakkala05ab1322013-02-15 11:28:38 +05306690 if (0 != ccmCfgGetStr(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_OPERATIONAL_RATE_SET,
6691 OperationalRates, &ORLeng))
6692 {
6693 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: ccm api returned failure", __func__);
6694 /*To keep GUI happy*/
6695 return 0;
6696 }
6697
Jeff Johnson295189b2012-06-20 16:38:30 -07006698 for (i = 0; i < ORLeng; i++)
6699 {
Jeff Johnsone7245742012-09-05 17:12:55 -07006700 for (j = 0; j < (sizeof(supported_data_rate) / sizeof(supported_data_rate[0])); j ++)
Jeff Johnson295189b2012-06-20 16:38:30 -07006701 {
6702 /* Validate Rate Set */
6703 if (supported_data_rate[j].beacon_rate_index == (OperationalRates[i] & 0x7F))
6704 {
6705 currentRate = supported_data_rate[j].supported_rate[rssidx];
6706 break;
6707 }
6708 }
6709 /* Update MAX rate */
6710 maxRate = (currentRate > maxRate)?currentRate:maxRate;
6711 }
6712
6713 /* Get Extended Rate Set */
Gopichand Nakkala05ab1322013-02-15 11:28:38 +05306714 if (0 != ccmCfgGetStr(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_EXTENDED_OPERATIONAL_RATE_SET,
6715 ExtendedRates, &ERLeng))
6716 {
6717 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: ccm api returned failure", __func__);
6718 /*To keep GUI happy*/
6719 return 0;
6720 }
6721
Jeff Johnson295189b2012-06-20 16:38:30 -07006722 for (i = 0; i < ERLeng; i++)
6723 {
Jeff Johnsone7245742012-09-05 17:12:55 -07006724 for (j = 0; j < (sizeof(supported_data_rate) / sizeof(supported_data_rate[0])); j ++)
Jeff Johnson295189b2012-06-20 16:38:30 -07006725 {
6726 if (supported_data_rate[j].beacon_rate_index == (ExtendedRates[i] & 0x7F))
6727 {
6728 currentRate = supported_data_rate[j].supported_rate[rssidx];
6729 break;
6730 }
6731 }
6732 /* Update MAX rate */
6733 maxRate = (currentRate > maxRate)?currentRate:maxRate;
6734 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006735 /* Get MCS Rate Set -- but only if we are connected at MCS
6736 rates or if we are always reporting max speed or if we have
6737 good rssi */
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07006738 if ((0 == rssidx) && !(rate_flags & eHAL_TX_RATE_LEGACY))
Jeff Johnson295189b2012-06-20 16:38:30 -07006739 {
Gopichand Nakkala05ab1322013-02-15 11:28:38 +05306740 if (0 != ccmCfgGetStr(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_CURRENT_MCS_SET,
6741 MCSRates, &MCSLeng))
6742 {
6743 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: ccm api returned failure", __func__);
6744 /*To keep GUI happy*/
6745 return 0;
6746 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006747 rateFlag = 0;
Leo Chang6f8870f2013-03-26 18:11:36 -07006748#ifdef WLAN_FEATURE_11AC
6749 /* VHT80 rate has seperate rate table */
Gopichand Nakkala4c705372013-04-24 13:20:33 +05306750 if (rate_flags & (eHAL_TX_RATE_VHT20|eHAL_TX_RATE_VHT40|eHAL_TX_RATE_VHT80))
Jeff Johnson295189b2012-06-20 16:38:30 -07006751 {
Leo Chang6f8870f2013-03-26 18:11:36 -07006752 ccmCfgGetInt(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_VHT_TX_MCS_MAP, &vht_mcs_map);
Gopichand Nakkala4c705372013-04-24 13:20:33 +05306753 vhtMaxMcs = (eDataRate11ACMaxMcs)(vht_mcs_map & DATA_RATE_11AC_MCS_MASK );
Leo Chang6f8870f2013-03-26 18:11:36 -07006754 if (rate_flags & eHAL_TX_RATE_SGI)
Jeff Johnson295189b2012-06-20 16:38:30 -07006755 {
Leo Chang6f8870f2013-03-26 18:11:36 -07006756 rateFlag |= 1;
Jeff Johnson295189b2012-06-20 16:38:30 -07006757 }
Leo Chang6f8870f2013-03-26 18:11:36 -07006758 if (DATA_RATE_11AC_MAX_MCS_7 == vhtMaxMcs)
Jeff Johnson295189b2012-06-20 16:38:30 -07006759 {
Leo Chang6f8870f2013-03-26 18:11:36 -07006760 maxMCSIdx = 7;
6761 }
6762 else if (DATA_RATE_11AC_MAX_MCS_8 == vhtMaxMcs)
6763 {
6764 maxMCSIdx = 8;
6765 }
6766 else if (DATA_RATE_11AC_MAX_MCS_9 == vhtMaxMcs)
6767 {
Gopichand Nakkala4c705372013-04-24 13:20:33 +05306768 //VHT20 is supporting 0~8
6769 if (rate_flags & eHAL_TX_RATE_VHT20)
6770 maxMCSIdx = 8;
6771 else
6772 maxMCSIdx = 9;
Leo Chang6f8870f2013-03-26 18:11:36 -07006773 }
Gopichand Nakkala4c705372013-04-24 13:20:33 +05306774
6775 if (rate_flags & eHAL_TX_RATE_VHT80)
6776 {
6777 currentRate = supported_vht_mcs_rate[pAdapter->hdd_stats.ClassA_stat.mcs_index].supported_VHT80_rate[rateFlag];
6778 maxRate = supported_vht_mcs_rate[maxMCSIdx].supported_VHT80_rate[rateFlag];
6779 }
6780 else if (rate_flags & eHAL_TX_RATE_VHT40)
6781 {
6782 currentRate = supported_vht_mcs_rate[pAdapter->hdd_stats.ClassA_stat.mcs_index].supported_VHT40_rate[rateFlag];
6783 maxRate = supported_vht_mcs_rate[maxMCSIdx].supported_VHT40_rate[rateFlag];
6784 }
6785 else if (rate_flags & eHAL_TX_RATE_VHT20)
6786 {
6787 currentRate = supported_vht_mcs_rate[pAdapter->hdd_stats.ClassA_stat.mcs_index].supported_VHT20_rate[rateFlag];
6788 maxRate = supported_vht_mcs_rate[maxMCSIdx].supported_VHT20_rate[rateFlag];
6789 }
6790
Leo Chang6f8870f2013-03-26 18:11:36 -07006791 maxSpeedMCS = 1;
6792 if (currentRate > maxRate)
6793 {
6794 maxRate = currentRate;
6795 }
Gopichand Nakkala4c705372013-04-24 13:20:33 +05306796
Leo Chang6f8870f2013-03-26 18:11:36 -07006797 }
6798 else
6799#endif /* WLAN_FEATURE_11AC */
6800 {
6801 if (rate_flags & eHAL_TX_RATE_HT40)
6802 {
6803 rateFlag |= 1;
6804 }
6805 if (rate_flags & eHAL_TX_RATE_SGI)
6806 {
6807 rateFlag |= 2;
6808 }
6809
6810 for (i = 0; i < MCSLeng; i++)
6811 {
6812 temp = sizeof(supported_mcs_rate) / sizeof(supported_mcs_rate[0]);
6813 for (j = 0; j < temp; j++)
6814 {
6815 if (supported_mcs_rate[j].beacon_rate_index == MCSRates[i])
6816 {
6817 currentRate = supported_mcs_rate[j].supported_rate[rateFlag];
6818 break;
6819 }
6820 }
6821 if ((j < temp) && (currentRate > maxRate))
6822 {
6823 maxRate = currentRate;
6824 maxSpeedMCS = 1;
6825 maxMCSIdx = supported_mcs_rate[j].beacon_rate_index;
6826 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006827 }
6828 }
6829 }
6830
Gopichand Nakkala4c705372013-04-24 13:20:33 +05306831 else if (!(rate_flags & eHAL_TX_RATE_LEGACY))
6832 {
6833 maxRate = myRate;
6834 maxSpeedMCS = 1;
6835 maxMCSIdx = pAdapter->hdd_stats.ClassA_stat.mcs_index;
6836 }
6837
Jeff Johnson295189b2012-06-20 16:38:30 -07006838 // make sure we report a value at least as big as our current rate
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07006839 if (((maxRate < myRate) && (0 == rssidx)) ||
6840 (0 == maxRate))
Jeff Johnson295189b2012-06-20 16:38:30 -07006841 {
6842 maxRate = myRate;
6843 if (rate_flags & eHAL_TX_RATE_LEGACY)
6844 {
6845 maxSpeedMCS = 0;
6846 }
6847 else
6848 {
6849 maxSpeedMCS = 1;
6850 maxMCSIdx = pAdapter->hdd_stats.ClassA_stat.mcs_index;
6851 }
6852 }
6853
Gopichand Nakkala4c705372013-04-24 13:20:33 +05306854 if (rate_flags & eHAL_TX_RATE_LEGACY)
Jeff Johnson295189b2012-06-20 16:38:30 -07006855 {
6856 sinfo->txrate.legacy = maxRate;
6857#ifdef LINKSPEED_DEBUG_ENABLED
6858 pr_info("Reporting legacy rate %d\n", sinfo->txrate.legacy);
6859#endif //LINKSPEED_DEBUG_ENABLED
6860 }
6861 else
6862 {
6863 sinfo->txrate.mcs = maxMCSIdx;
Leo Chang6f8870f2013-03-26 18:11:36 -07006864#ifdef WLAN_FEATURE_11AC
6865 sinfo->txrate.nss = 1;
6866 if (rate_flags & eHAL_TX_RATE_VHT80)
6867 {
6868 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
Gopichand Nakkala4c705372013-04-24 13:20:33 +05306869 sinfo->txrate.flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
Leo Chang6f8870f2013-03-26 18:11:36 -07006870 }
Gopichand Nakkala4c705372013-04-24 13:20:33 +05306871 else if (rate_flags & eHAL_TX_RATE_VHT40)
Leo Chang6f8870f2013-03-26 18:11:36 -07006872 {
Gopichand Nakkala4c705372013-04-24 13:20:33 +05306873 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
6874 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
6875 }
6876 else if (rate_flags & eHAL_TX_RATE_VHT20)
6877 {
6878 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
6879 }
6880#endif /* WLAN_FEATURE_11AC */
6881 if (rate_flags & (eHAL_TX_RATE_HT20 | eHAL_TX_RATE_HT40))
6882 {
6883 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
6884 if (rate_flags & eHAL_TX_RATE_HT40)
6885 {
6886 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
6887 }
Leo Chang6f8870f2013-03-26 18:11:36 -07006888 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006889 if (rate_flags & eHAL_TX_RATE_SGI)
6890 {
6891 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
6892 }
Gopichand Nakkala4c705372013-04-24 13:20:33 +05306893
Jeff Johnson295189b2012-06-20 16:38:30 -07006894#ifdef LINKSPEED_DEBUG_ENABLED
6895 pr_info("Reporting MCS rate %d flags %x\n",
6896 sinfo->txrate.mcs,
6897 sinfo->txrate.flags );
6898#endif //LINKSPEED_DEBUG_ENABLED
6899 }
6900 }
6901 else
6902 {
6903 // report current rate instead of max rate
6904
6905 if (rate_flags & eHAL_TX_RATE_LEGACY)
6906 {
6907 //provide to the UI in units of 100kbps
6908 sinfo->txrate.legacy = myRate;
6909#ifdef LINKSPEED_DEBUG_ENABLED
6910 pr_info("Reporting actual legacy rate %d\n", sinfo->txrate.legacy);
6911#endif //LINKSPEED_DEBUG_ENABLED
6912 }
6913 else
6914 {
6915 //must be MCS
6916 sinfo->txrate.mcs = pAdapter->hdd_stats.ClassA_stat.mcs_index;
Leo Chang6f8870f2013-03-26 18:11:36 -07006917#ifdef WLAN_FEATURE_11AC
6918 sinfo->txrate.nss = 1;
6919 if (rate_flags & eHAL_TX_RATE_VHT80)
6920 {
6921 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
6922 }
6923 else
6924#endif /* WLAN_FEATURE_11AC */
6925 {
6926 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
6927 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006928 if (rate_flags & eHAL_TX_RATE_SGI)
6929 {
6930 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
6931 }
6932 if (rate_flags & eHAL_TX_RATE_HT40)
6933 {
6934 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
6935 }
Leo Chang6f8870f2013-03-26 18:11:36 -07006936#ifdef WLAN_FEATURE_11AC
6937 else if (rate_flags & eHAL_TX_RATE_VHT80)
6938 {
6939 sinfo->txrate.flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
6940 }
6941#endif /* WLAN_FEATURE_11AC */
Jeff Johnson295189b2012-06-20 16:38:30 -07006942#ifdef LINKSPEED_DEBUG_ENABLED
6943 pr_info("Reporting actual MCS rate %d flags %x\n",
6944 sinfo->txrate.mcs,
6945 sinfo->txrate.flags );
6946#endif //LINKSPEED_DEBUG_ENABLED
6947 }
6948 }
6949 sinfo->filled |= STATION_INFO_TX_BITRATE;
6950
Madan Mohan Koyyalamudi4d4d2812012-09-24 14:08:29 -07006951 sinfo->tx_packets =
6952 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[0] +
6953 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[1] +
6954 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[2] +
6955 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[3];
6956
6957 sinfo->tx_retries =
6958 pAdapter->hdd_stats.summary_stat.retry_cnt[0] +
6959 pAdapter->hdd_stats.summary_stat.retry_cnt[1] +
6960 pAdapter->hdd_stats.summary_stat.retry_cnt[2] +
6961 pAdapter->hdd_stats.summary_stat.retry_cnt[3];
6962
6963 sinfo->tx_failed =
6964 pAdapter->hdd_stats.summary_stat.fail_cnt[0] +
6965 pAdapter->hdd_stats.summary_stat.fail_cnt[1] +
6966 pAdapter->hdd_stats.summary_stat.fail_cnt[2] +
6967 pAdapter->hdd_stats.summary_stat.fail_cnt[3];
6968
6969 sinfo->filled |=
6970 STATION_INFO_TX_PACKETS |
6971 STATION_INFO_TX_RETRIES |
6972 STATION_INFO_TX_FAILED;
6973
6974 EXIT();
6975 return 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07006976}
6977
6978static int wlan_hdd_cfg80211_set_power_mgmt(struct wiphy *wiphy,
Sameer Thalappilc9f26e92013-06-07 10:11:06 -07006979 struct net_device *dev, bool mode, int timeout)
Jeff Johnson295189b2012-06-20 16:38:30 -07006980{
6981 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05306982 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07006983 VOS_STATUS vos_status;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306984 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006985
Jeff Johnsone7245742012-09-05 17:12:55 -07006986 ENTER();
6987
Jeff Johnson295189b2012-06-20 16:38:30 -07006988 if (NULL == pAdapter)
6989 {
6990 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Adapter is NULL\n", __func__);
6991 return -ENODEV;
6992 }
6993
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05306994 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306995 status = wlan_hdd_validate_context(pHddCtx);
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05306996
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306997 if (0 != status)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306998 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306999 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7000 "%s: HDD context is not valid", __func__);
7001 return status;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307002 }
7003
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05307004 if ((DRIVER_POWER_MODE_AUTO == !mode) &&
7005 (TRUE == pHddCtx->hdd_wlan_suspended) &&
7006 (pHddCtx->cfg_ini->fhostArpOffload) &&
7007 (eConnectionState_Associated ==
7008 (WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))->conn_info.connState))
7009 {
Gopichand Nakkalab03e8082013-05-30 18:09:25 +05307010 vos_status = hdd_conf_arp_offload(pAdapter, TRUE);
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05307011 if (!VOS_IS_STATUS_SUCCESS(vos_status))
7012 {
7013 hddLog(VOS_TRACE_LEVEL_INFO,
7014 "%s:Failed to enable ARPOFFLOAD Feature %d\n",
7015 __func__, vos_status);
7016 }
7017 }
7018
Jeff Johnson295189b2012-06-20 16:38:30 -07007019 /**The get power cmd from the supplicant gets updated by the nl only
7020 *on successful execution of the function call
7021 *we are oppositely mapped w.r.t mode in the driver
7022 **/
7023 vos_status = wlan_hdd_enter_bmps(pAdapter, !mode);
7024
Jeff Johnsone7245742012-09-05 17:12:55 -07007025 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07007026 if (VOS_STATUS_E_FAILURE == vos_status)
7027 {
7028 return -EINVAL;
7029 }
7030 return 0;
7031}
7032
7033
7034#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
7035static int wlan_hdd_set_default_mgmt_key(struct wiphy *wiphy,
7036 struct net_device *netdev,
7037 u8 key_index)
7038{
Jeff Johnsone7245742012-09-05 17:12:55 -07007039 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07007040 return 0;
7041}
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307042#endif //LINUX_VERSION_CODE
Jeff Johnson295189b2012-06-20 16:38:30 -07007043
7044#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
7045static int wlan_hdd_set_txq_params(struct wiphy *wiphy,
7046 struct net_device *dev,
7047 struct ieee80211_txq_params *params)
7048{
Jeff Johnsone7245742012-09-05 17:12:55 -07007049 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07007050 return 0;
7051}
7052#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
7053static int wlan_hdd_set_txq_params(struct wiphy *wiphy,
7054 struct ieee80211_txq_params *params)
7055{
Jeff Johnsone7245742012-09-05 17:12:55 -07007056 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07007057 return 0;
7058}
7059#endif //LINUX_VERSION_CODE
7060
7061static int wlan_hdd_cfg80211_del_station(struct wiphy *wiphy,
7062 struct net_device *dev, u8 *mac)
7063{
7064 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307065 hdd_context_t *pHddCtx;
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007066 VOS_STATUS vos_status;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307067 int status;
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007068 v_U8_t staId;
Jeff Johnson295189b2012-06-20 16:38:30 -07007069
Jeff Johnsone7245742012-09-05 17:12:55 -07007070 ENTER();
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307071 if ( NULL == pAdapter )
Jeff Johnson295189b2012-06-20 16:38:30 -07007072 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307073 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Adapter" ,__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07007074 return -EINVAL;
7075 }
7076
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307077 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7078 status = wlan_hdd_validate_context(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07007079
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307080 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007081 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307082 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7083 "%s: HDD context is not valid", __func__);
7084 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007085 }
7086
Jeff Johnson295189b2012-06-20 16:38:30 -07007087 if ( (WLAN_HDD_SOFTAP == pAdapter->device_mode)
Jeff Johnson295189b2012-06-20 16:38:30 -07007088 || (WLAN_HDD_P2P_GO == pAdapter->device_mode)
Jeff Johnson295189b2012-06-20 16:38:30 -07007089 )
7090 {
7091 if( NULL == mac )
7092 {
7093 v_U16_t i;
7094 for(i = 0; i < WLAN_MAX_STA_COUNT; i++)
7095 {
Rajesh Chauhan18488fc2013-08-22 10:15:03 -07007096 if ((pAdapter->aStaInfo[i].isUsed) &&
7097 (!pAdapter->aStaInfo[i].isDeauthInProgress))
Jeff Johnson295189b2012-06-20 16:38:30 -07007098 {
7099 u8 *macAddr = pAdapter->aStaInfo[i].macAddrSTA.bytes;
7100 hddLog(VOS_TRACE_LEVEL_INFO,
7101 "%s: Delete STA with MAC::"
7102 "%02x:%02x:%02x:%02x:%02x:%02x",
7103 __func__,
7104 macAddr[0], macAddr[1], macAddr[2],
7105 macAddr[3], macAddr[4], macAddr[5]);
Rajesh Chauhan18488fc2013-08-22 10:15:03 -07007106 vos_status = hdd_softap_sta_deauth(pAdapter, macAddr);
7107 if (VOS_IS_STATUS_SUCCESS(vos_status))
7108 pAdapter->aStaInfo[i].isDeauthInProgress = TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07007109 }
7110 }
7111 }
7112 else
7113 {
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007114
7115 vos_status = hdd_softap_GetStaId(pAdapter,(v_MACADDR_t *)mac, &staId);
7116 if (!VOS_IS_STATUS_SUCCESS(vos_status))
7117 {
7118 hddLog(VOS_TRACE_LEVEL_INFO,
7119 "%s: Skip this DEL STA as this is not used::"
7120 "%02x:%02x:%02x:%02x:%02x:%02x",
7121 __func__,
7122 mac[0], mac[1], mac[2],
7123 mac[3], mac[4], mac[5]);
7124 return -ENOENT;
7125 }
7126
7127 if( pAdapter->aStaInfo[staId].isDeauthInProgress == TRUE)
7128 {
7129 hddLog(VOS_TRACE_LEVEL_INFO,
7130 "%s: Skip this DEL STA as deauth is in progress::"
7131 "%02x:%02x:%02x:%02x:%02x:%02x",
7132 __func__,
7133 mac[0], mac[1], mac[2],
7134 mac[3], mac[4], mac[5]);
7135 return -ENOENT;
7136 }
7137
7138 pAdapter->aStaInfo[staId].isDeauthInProgress = TRUE;
7139
Jeff Johnson295189b2012-06-20 16:38:30 -07007140 hddLog(VOS_TRACE_LEVEL_INFO,
7141 "%s: Delete STA with MAC::"
7142 "%02x:%02x:%02x:%02x:%02x:%02x",
7143 __func__,
7144 mac[0], mac[1], mac[2],
7145 mac[3], mac[4], mac[5]);
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007146
7147 vos_status = hdd_softap_sta_deauth(pAdapter, mac);
7148 if (!VOS_IS_STATUS_SUCCESS(vos_status))
7149 {
7150 pAdapter->aStaInfo[staId].isDeauthInProgress = FALSE;
7151 hddLog(VOS_TRACE_LEVEL_INFO,
7152 "%s: STA removal failed for ::"
7153 "%02x:%02x:%02x:%02x:%02x:%02x",
7154 __func__,
7155 mac[0], mac[1], mac[2],
7156 mac[3], mac[4], mac[5]);
7157 return -ENOENT;
7158 }
7159
Jeff Johnson295189b2012-06-20 16:38:30 -07007160 }
7161 }
7162
7163 EXIT();
7164
7165 return 0;
7166}
7167
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007168static int wlan_hdd_cfg80211_add_station(struct wiphy *wiphy,
7169 struct net_device *dev, u8 *mac, struct station_parameters *params)
7170{
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007171 int status = -EPERM;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007172#ifdef FEATURE_WLAN_TDLS
7173 u32 mask, set;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007174 ENTER();
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007175 mask = params->sta_flags_mask;
7176
7177 set = params->sta_flags_set;
7178
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007179#ifdef WLAN_FEATURE_TDLS_DEBUG
7180 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7181 "%s: mask 0x%x set 0x%x " MAC_ADDRESS_STR,
7182 __func__, mask, set, MAC_ADDR_ARRAY(mac));
7183#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007184
7185 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
7186 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
Gopichand Nakkala681989c2013-03-06 22:27:48 -08007187 status = wlan_hdd_tdls_add_station(wiphy, dev, mac, 0, NULL);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007188 }
7189 }
7190#endif
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007191 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007192}
7193
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007194
7195#ifdef FEATURE_WLAN_LFR
7196static int wlan_hdd_cfg80211_set_pmksa(struct wiphy *wiphy, struct net_device *dev,
Jeff Johnsond13512a2012-07-17 11:42:19 -07007197 struct cfg80211_pmksa *pmksa)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007198{
7199#define MAX_PMKSAIDS_IN_CACHE 8
7200 static tPmkidCacheInfo PMKIDCache[MAX_PMKSAIDS_IN_CACHE]; // HDD Local cache
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307201 static tANI_U32 i; // HDD Local Cache index
7202 tANI_U32 j=0;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007203 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7204 tHalHandle halHandle;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307205 eHalStatus result;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307206 int status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007207 tANI_U8 BSSIDMatched = 0;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307208 hdd_context_t *pHddCtx;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307209
Jeff Johnsone7245742012-09-05 17:12:55 -07007210 ENTER();
7211
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307212 // Validate pAdapter
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307213 if ( NULL == pAdapter )
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007214 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307215 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Adapter" ,__func__);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007216 return -EINVAL;
7217 }
7218
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307219 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7220 status = wlan_hdd_validate_context(pHddCtx);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007221
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307222 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007223 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307224 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7225 "%s: HDD context is not valid", __func__);
7226 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007227 }
7228
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307229 // Retrieve halHandle
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007230 halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
7231
7232 for (j = 0; j < i; j++)
7233 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307234 if(vos_mem_compare(PMKIDCache[j].BSSID,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007235 pmksa->bssid, WNI_CFG_BSSID_LEN))
7236 {
7237 /* BSSID matched previous entry. Overwrite it. */
7238 BSSIDMatched = 1;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307239 vos_mem_copy(PMKIDCache[j].BSSID,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007240 pmksa->bssid, WNI_CFG_BSSID_LEN);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307241 vos_mem_copy(PMKIDCache[j].PMKID,
7242 pmksa->pmkid,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007243 CSR_RSN_PMKID_SIZE);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307244 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Reusing cache entry %d.",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007245 __func__, j );
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007246 dump_bssid(pmksa->bssid);
7247 dump_pmkid(halHandle, pmksa->pmkid);
7248 break;
7249 }
7250 }
7251
Madan Mohan Koyyalamudic4b317d2012-10-18 19:43:08 -07007252 /* Check we compared all entries,if then take the first slot now */
7253 if(j == MAX_PMKSAIDS_IN_CACHE) i=0;
7254
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007255 if (!BSSIDMatched)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307256 {
7257 // Now, we DON'T have a BSSID match, so take a new entry in the cache.
7258 vos_mem_copy(PMKIDCache[i].BSSID,
7259 pmksa->bssid, ETHER_ADDR_LEN);
7260 vos_mem_copy(PMKIDCache[i].PMKID,
7261 pmksa->pmkid,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007262 CSR_RSN_PMKID_SIZE);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307263 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Adding a new cache entry %d.",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007264 __func__, i );
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007265 dump_bssid(pmksa->bssid);
7266 dump_pmkid(halHandle, pmksa->pmkid);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307267 // Increment the HDD Local Cache index
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007268 // The "i=0" doesn't work for the call to sme_RoamSetPMKIDCache() - LFR FIXME
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307269 if (i<=(MAX_PMKSAIDS_IN_CACHE-1)) i++; else i=0;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007270 }
7271
7272
7273 // Calling csrRoamSetPMKIDCache to configure the PMKIDs into the cache
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307274 //hddLog(LOG1, FL("%s: Calling csrRoamSetPMKIDCache with %d cache entries."),
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007275 // __func__, i );
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307276 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Calling csrRoamSetPMKIDCache with %d cache entries.",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007277 __func__, i );
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007278 // Finally set the PMKSA ID Cache in CSR
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307279 result = sme_RoamSetPMKIDCache(halHandle,pAdapter->sessionId,
7280 PMKIDCache,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007281 i );
7282 return 0;
7283}
7284
7285
7286static int wlan_hdd_cfg80211_del_pmksa(struct wiphy *wiphy, struct net_device *dev,
Jeff Johnsond13512a2012-07-17 11:42:19 -07007287 struct cfg80211_pmksa *pmksa)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007288{
Jeff Johnsone7245742012-09-05 17:12:55 -07007289 ENTER();
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007290 // TODO: Implement this later.
7291 return 0;
7292}
7293
7294static int wlan_hdd_cfg80211_flush_pmksa(struct wiphy *wiphy, struct net_device *dev)
7295{
Jeff Johnsone7245742012-09-05 17:12:55 -07007296 ENTER();
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007297 // TODO: Implement this later.
7298 return 0;
7299}
7300#endif
7301
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07007302#if defined(WLAN_FEATURE_VOWIFI_11R) && defined(KERNEL_SUPPORT_11R_CFG80211)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307303static int wlan_hdd_cfg80211_update_ft_ies(struct wiphy *wiphy,
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07007304 struct net_device *dev, struct cfg80211_update_ft_ies_params *ftie)
7305{
7306 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7307 hdd_station_ctx_t *pHddStaCtx;
7308
7309 if (NULL == pAdapter)
7310 {
7311 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Adapter is NULL\n", __func__);
7312 return -ENODEV;
7313 }
7314
7315 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
7316
7317 // Added for debug on reception of Re-assoc Req.
7318 if (eConnectionState_Associated != pHddStaCtx->conn_info.connState)
7319 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307320 hddLog(LOGE, FL("Called with Ie of length = %d when not associated\n"),
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07007321 ftie->ie_len);
7322 hddLog(LOGE, FL("Should be Re-assoc Req IEs\n"));
7323 }
7324
7325#ifdef WLAN_FEATURE_VOWIFI_11R_DEBUG
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307326 hddLog(LOGE, FL("%s called with Ie of length = %d\n"), __func__,
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07007327 ftie->ie_len);
7328#endif
7329
7330 // Pass the received FT IEs to SME
Gopichand Nakkala356fb102013-03-06 12:34:04 +05307331 sme_SetFTIEs( WLAN_HDD_GET_HAL_CTX(pAdapter), pAdapter->sessionId,
7332 (const u8 *)ftie->ie,
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07007333 ftie->ie_len);
7334 return 0;
7335}
7336#endif
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007337
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307338#ifdef FEATURE_WLAN_SCAN_PNO
7339
7340void hdd_cfg80211_sched_scan_done_callback(void *callbackContext,
7341 tSirPrefNetworkFoundInd *pPrefNetworkFoundInd)
7342{
7343 int ret;
7344 hdd_adapter_t* pAdapter = (hdd_adapter_t*)callbackContext;
7345 hdd_context_t *pHddCtx;
7346
7347 if (NULL == pAdapter)
7348 {
7349 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
7350 "%s: HDD adapter is Null", __func__);
7351 return ;
7352 }
7353
7354 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7355 if (NULL == pHddCtx)
7356 {
7357 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7358 "%s: HDD context is Null!!!", __func__);
7359 return ;
7360 }
7361
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05307362 spin_lock(&pHddCtx->schedScan_lock);
7363 if (TRUE == pHddCtx->isWiphySuspended)
7364 {
7365 pHddCtx->isSchedScanUpdatePending = TRUE;
7366 spin_unlock(&pHddCtx->schedScan_lock);
7367 hddLog(VOS_TRACE_LEVEL_INFO,
7368 "%s: Update cfg80211 scan database after it resume", __func__);
7369 return ;
7370 }
7371 spin_unlock(&pHddCtx->schedScan_lock);
7372
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307373 ret = wlan_hdd_cfg80211_update_bss(pHddCtx->wiphy, pAdapter);
7374
7375 if (0 > ret)
7376 hddLog(VOS_TRACE_LEVEL_INFO, "%s: NO SCAN result", __func__);
7377
7378 cfg80211_sched_scan_results(pHddCtx->wiphy);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05307379 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
7380 "%s: cfg80211 scan result database updated", __func__);
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307381}
7382
7383/*
7384 * FUNCTION: wlan_hdd_cfg80211_sched_scan_start
7385 * NL interface to enable PNO
7386 */
7387static int wlan_hdd_cfg80211_sched_scan_start(struct wiphy *wiphy,
7388 struct net_device *dev, struct cfg80211_sched_scan_request *request)
7389{
7390 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7391 tpSirPNOScanReq pPnoRequest = NULL;
7392 hdd_context_t *pHddCtx;
7393 tHalHandle hHal;
Madan Mohan Koyyalamudi1d16f462013-08-27 16:25:34 +05307394 v_U32_t i, indx, num_ch, tempInterval;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307395 u8 valid_ch[WNI_CFG_VALID_CHANNEL_LIST_LEN];
7396 u8 channels_allowed[WNI_CFG_VALID_CHANNEL_LIST_LEN];
7397 v_U32_t num_channels_allowed = WNI_CFG_VALID_CHANNEL_LIST_LEN;
7398 eHalStatus status = eHAL_STATUS_FAILURE;
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307399 int ret = 0;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307400
7401 if (NULL == pAdapter)
7402 {
7403 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
7404 "%s: HDD adapter is Null", __func__);
7405 return -ENODEV;
7406 }
7407
7408 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05307409 ret = wlan_hdd_validate_context(pHddCtx);
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307410
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05307411 if (0 != ret)
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307412 {
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05307413 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7414 "%s: HDD context is not valid", __func__);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307415 return -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307416 }
7417
7418 hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
7419 if (NULL == hHal)
7420 {
7421 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7422 "%s: HAL context is Null!!!", __func__);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05307423 return -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307424 }
7425
7426 pPnoRequest = (tpSirPNOScanReq) vos_mem_malloc(sizeof (tSirPNOScanReq));
7427 if (NULL == pPnoRequest)
7428 {
7429 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
7430 "%s: vos_mem_malloc failed", __func__);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307431 return -ENOMEM;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307432 }
7433
7434 pPnoRequest->enable = 1; /*Enable PNO */
7435 pPnoRequest->ucNetworksCount = request->n_match_sets;
7436
7437 if (( !pPnoRequest->ucNetworksCount ) ||
7438 ( pPnoRequest->ucNetworksCount > SIR_PNO_MAX_SUPP_NETWORKS ))
7439 {
7440 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7441 "Network input is not correct");
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307442 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307443 goto error;
7444 }
7445
7446 if ( SIR_PNO_MAX_NETW_CHANNELS_EX < request->n_channels )
7447 {
7448 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7449 "Incorrect number of channels");
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307450 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307451 goto error;
7452 }
7453
7454 /* Framework provides one set of channels(all)
7455 * common for all saved profile */
7456 if (0 != ccmCfgGetStr(hHal, WNI_CFG_VALID_CHANNEL_LIST,
7457 channels_allowed, &num_channels_allowed))
7458 {
7459 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7460 "%s: failed to get valid channel list", __func__);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307461 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307462 goto error;
7463 }
7464 /* Checking each channel against allowed channel list */
7465 num_ch = 0;
7466 for (i = 0; i < request->n_channels; i++)
7467 {
7468 for (indx = 0; indx < num_channels_allowed; indx++)
7469 {
7470 if (request->channels[i]->hw_value == channels_allowed[indx])
7471 {
7472 valid_ch[num_ch++] = request->channels[i]->hw_value;
7473 break ;
7474 }
7475 }
7476 }
7477
7478 /* Filling per profile params */
7479 for (i = 0; i < pPnoRequest->ucNetworksCount; i++)
7480 {
7481 pPnoRequest->aNetworks[i].ssId.length =
7482 request->match_sets[i].ssid.ssid_len;
7483
7484 if (( 0 == pPnoRequest->aNetworks[i].ssId.length ) ||
7485 ( pPnoRequest->aNetworks[i].ssId.length > 32 ) )
7486 {
7487 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7488 "SSID Len %d is not correct for network %d",
7489 pPnoRequest->aNetworks[i].ssId.length, i);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307490 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307491 goto error;
7492 }
7493
7494 memcpy(pPnoRequest->aNetworks[i].ssId.ssId,
7495 request->match_sets[i].ssid.ssid,
7496 request->match_sets[i].ssid.ssid_len);
7497 pPnoRequest->aNetworks[i].authentication = 0; /*eAUTH_TYPE_ANY*/
7498 pPnoRequest->aNetworks[i].encryption = 0; /*eED_ANY*/
7499 pPnoRequest->aNetworks[i].bcastNetwType = 0; /*eBCAST_UNKNOWN*/
7500
7501 /*Copying list of valid channel into request */
7502 memcpy(pPnoRequest->aNetworks[i].aChannels, valid_ch, num_ch);
7503 pPnoRequest->aNetworks[i].ucChannelCount = num_ch;
7504
7505 pPnoRequest->aNetworks[i].rssiThreshold = 0; //Default value
7506 }
7507
Madan Mohan Koyyalamudi1d16f462013-08-27 16:25:34 +05307508 /* Driver gets only one time interval which is hardcoded in
7509 * supplicant for 10000ms. Taking power consumption into account 6 timers
7510 * will be used, Timervalue is increased exponentially i.e 10,20,40,
7511 * 80,160,320 secs. And number of scan cycle for each timer
7512 * is configurable through INI param gPNOScanTimerRepeatValue.
7513 * If it is set to 0 only one timer will be used and PNO scan cycle
7514 * will be repeated after each interval specified by supplicant
7515 * till PNO is disabled.
7516 */
7517 if (0 == pHddCtx->cfg_ini->configPNOScanTimerRepeatValue)
7518 pPnoRequest->scanTimers.ucScanTimersCount = HDD_PNO_SCAN_TIMERS_SET_ONE;
7519 else
7520 pPnoRequest->scanTimers.ucScanTimersCount =
7521 HDD_PNO_SCAN_TIMERS_SET_MULTIPLE;
7522
7523 tempInterval = (request->interval)/1000;
7524 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
7525 "Base scan interval = %d PNOScanTimerRepeatValue = %d",
7526 tempInterval, pHddCtx->cfg_ini->configPNOScanTimerRepeatValue);
7527 for ( i = 0; i < pPnoRequest->scanTimers.ucScanTimersCount; i++)
7528 {
7529 pPnoRequest->scanTimers.aTimerValues[i].uTimerRepeat =
7530 pHddCtx->cfg_ini->configPNOScanTimerRepeatValue;
7531 pPnoRequest->scanTimers.aTimerValues[i].uTimerValue = tempInterval;
7532 tempInterval *= 2;
7533 }
7534 //Repeat last timer until pno disabled.
7535 pPnoRequest->scanTimers.aTimerValues[i-1].uTimerRepeat = 0;
7536
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307537 pPnoRequest->modePNO = SIR_PNO_MODE_ON_SUSPEND;
7538
7539 status = sme_SetPreferredNetworkList(WLAN_HDD_GET_HAL_CTX(pAdapter),
7540 pPnoRequest, pAdapter->sessionId,
7541 hdd_cfg80211_sched_scan_done_callback, pAdapter);
7542 if (eHAL_STATUS_SUCCESS != status)
7543 {
7544 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7545 "Failed to enable PNO");
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307546 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307547 goto error;
7548 }
7549
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05307550 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
7551 "PNO scanRequest offloaded");
7552
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307553error:
7554 vos_mem_free(pPnoRequest);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307555 return ret;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307556}
7557
7558/*
7559 * FUNCTION: wlan_hdd_cfg80211_sched_scan_stop
7560 * NL interface to disable PNO
7561 */
7562static int wlan_hdd_cfg80211_sched_scan_stop(struct wiphy *wiphy,
7563 struct net_device *dev)
7564{
7565 eHalStatus status = eHAL_STATUS_FAILURE;
7566 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7567 hdd_context_t *pHddCtx;
7568 tHalHandle hHal;
7569 tpSirPNOScanReq pPnoRequest = NULL;
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307570 int ret = 0;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307571
7572 ENTER();
7573
7574 if (NULL == pAdapter)
7575 {
7576 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
7577 "%s: HDD adapter is Null", __func__);
7578 return -ENODEV;
7579 }
7580
7581 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307582
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307583 if (NULL == pHddCtx)
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307584 {
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05307585 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307586 "%s: HDD context is Null", __func__);
7587 return -ENODEV;
7588 }
7589
7590 /* The return 0 is intentional when isLogpInProgress and
7591 * isLoadUnloadInProgress. We did observe a crash due to a return of
7592 * failure in sched_scan_stop , especially for a case where the unload
7593 * of the happens at the same time. The function __cfg80211_stop_sched_scan
7594 * was clearing rdev->sched_scan_req only when the sched_scan_stop returns
7595 * success. If it returns a failure , then its next invocation due to the
7596 * clean up of the second interface will have the dev pointer corresponding
7597 * to the first one leading to a crash.
7598 */
7599 if (pHddCtx->isLogpInProgress)
7600 {
7601 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7602 "%s: LOGP in Progress. Ignore!!!", __func__);
7603 return ret;
7604 }
7605
7606 if (pHddCtx->isLoadUnloadInProgress)
7607 {
7608 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7609 "%s: Unloading/Loading in Progress. Ignore!!!", __func__);
7610 return ret;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307611 }
7612
7613 hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
7614 if (NULL == hHal)
7615 {
7616 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7617 "%s: HAL context is Null!!!", __func__);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05307618 return -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307619 }
7620
7621 pPnoRequest = (tpSirPNOScanReq) vos_mem_malloc(sizeof (tSirPNOScanReq));
7622 if (NULL == pPnoRequest)
7623 {
7624 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
7625 "%s: vos_mem_malloc failed", __func__);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307626 return -ENOMEM;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307627 }
7628
7629 memset(pPnoRequest, 0, sizeof (tSirPNOScanReq));
7630 pPnoRequest->enable = 0; /* Disable PNO */
7631 pPnoRequest->ucNetworksCount = 0;
7632
7633 status = sme_SetPreferredNetworkList(hHal, pPnoRequest,
7634 pAdapter->sessionId,
7635 NULL, pAdapter);
7636 if (eHAL_STATUS_SUCCESS != status)
7637 {
7638 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7639 "Failed to disabled PNO");
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307640 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307641 }
7642
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05307643 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
7644 "%s: PNO scan disabled", __func__);
7645
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307646 vos_mem_free(pPnoRequest);
7647
7648 EXIT();
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307649 return ret;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307650}
7651
7652#endif /*FEATURE_WLAN_SCAN_PNO*/
7653
7654
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007655#ifdef FEATURE_WLAN_TDLS
7656static int wlan_hdd_cfg80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
7657 u8 *peer, u8 action_code, u8 dialog_token,
7658 u16 status_code, const u8 *buf, size_t len)
7659{
7660
7661 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7662 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007663 u8 peerMac[6];
7664 VOS_STATUS status;
Gopichand Nakkala05922802013-03-14 12:23:19 -07007665 int max_sta_failed = 0;
Hoonki Leea34dd892013-02-05 22:56:02 -08007666 int responder;
Hoonki Leed37cbb32013-04-20 00:31:14 -07007667 long rc;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007668
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007669 if (NULL == pHddCtx || NULL == pHddCtx->cfg_ini)
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007670 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307671 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007672 "Invalid arguments");
7673 return -EINVAL;
7674 }
7675
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08007676 if (pHddCtx->isLogpInProgress)
7677 {
7678 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7679 "%s:LOGP in Progress. Ignore!!!", __func__);
Gopichand Nakkala05922802013-03-14 12:23:19 -07007680 wlan_hdd_tdls_set_link_status(pAdapter, peer, eTDLS_LINK_IDLE);
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08007681 return -EBUSY;
7682 }
7683
Hoonki Lee27511902013-03-14 18:19:06 -07007684 if (eTDLS_SUPPORT_NOT_ENABLED == pHddCtx->tdls_mode)
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007685 {
Hoonki Lee27511902013-03-14 18:19:06 -07007686 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
7687 "%s: TDLS mode is disabled OR not enabled in FW."
7688 MAC_ADDRESS_STR " action %d declined.",
7689 __func__, MAC_ADDR_ARRAY(peer), action_code);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007690 return -ENOTSUPP;
7691 }
Lee Hoonkic1262f22013-01-24 21:59:00 -08007692
Hoonki Lee27511902013-03-14 18:19:06 -07007693 /* other than teardown frame, other mgmt frames are not sent if disabled */
7694 if (SIR_MAC_TDLS_TEARDOWN != action_code)
7695 {
7696 /* if tdls_mode is disabled to respond to peer's request */
7697 if (eTDLS_SUPPORT_DISABLED == pHddCtx->tdls_mode)
7698 {
7699 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
7700 "%s: " MAC_ADDRESS_STR
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07007701 " TDLS mode is disabled. action %d declined.",
7702 __func__, MAC_ADDR_ARRAY(peer), action_code);
Hoonki Lee27511902013-03-14 18:19:06 -07007703
7704 return -ENOTSUPP;
7705 }
7706 }
7707
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007708 if (WLAN_IS_TDLS_SETUP_ACTION(action_code))
7709 {
Hoonki Leefb8df672013-04-10 18:20:34 -07007710 if (NULL != wlan_hdd_tdls_is_progress(pHddCtx, peer, TRUE, TRUE))
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007711 {
7712 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007713 "%s: " MAC_ADDRESS_STR
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07007714 " TDLS setup is ongoing. action %d declined.",
7715 __func__, MAC_ADDR_ARRAY(peer), action_code);
7716 return -EPERM;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007717 }
7718 }
7719
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007720 if (SIR_MAC_TDLS_SETUP_REQ == action_code ||
7721 SIR_MAC_TDLS_SETUP_RSP == action_code )
Lee Hoonkic1262f22013-01-24 21:59:00 -08007722 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08007723 if (HDD_MAX_NUM_TDLS_STA <= wlan_hdd_tdlsConnectedPeers(pAdapter))
Lee Hoonkic1262f22013-01-24 21:59:00 -08007724 {
7725 /* supplicant still sends tdls_mgmt(SETUP_REQ) even after
7726 we return error code at 'add_station()'. Hence we have this
7727 check again in addtion to add_station().
7728 Anyway, there is no hard to double-check. */
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007729 if (SIR_MAC_TDLS_SETUP_REQ == action_code)
Lee Hoonkic1262f22013-01-24 21:59:00 -08007730 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007731 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7732 "%s: " MAC_ADDRESS_STR
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07007733 " TDLS Max peer already connected. action %d declined.",
7734 __func__, MAC_ADDR_ARRAY(peer), action_code);
Gopichand Nakkala05922802013-03-14 12:23:19 -07007735 goto error;
Lee Hoonkic1262f22013-01-24 21:59:00 -08007736 }
7737 else
7738 {
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007739 /* maximum reached. tweak to send error code to peer and return
7740 error code to supplicant */
Lee Hoonkic1262f22013-01-24 21:59:00 -08007741 status_code = eSIR_MAC_UNSPEC_FAILURE_STATUS;
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007742 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7743 "%s: " MAC_ADDRESS_STR
7744 " TDLS Max peer already connected send response status %d",
7745 __func__, MAC_ADDR_ARRAY(peer), status_code);
Gopichand Nakkala05922802013-03-14 12:23:19 -07007746 max_sta_failed = -EPERM;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007747 /* fall through to send setup resp with failure status
7748 code */
Lee Hoonkic1262f22013-01-24 21:59:00 -08007749 }
7750 }
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007751 else
7752 {
7753 hddTdlsPeer_t *pTdlsPeer;
Gopichand Nakkala4327a152013-03-04 23:22:42 -08007754 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peer);
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07007755 if (pTdlsPeer && TDLS_IS_CONNECTED(pTdlsPeer))
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007756 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007757 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07007758 "%s:" MAC_ADDRESS_STR " already connected. action %d declined.",
7759 __func__, MAC_ADDR_ARRAY(peer), action_code);
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007760 return -EPERM;
7761 }
7762 }
Lee Hoonkic1262f22013-01-24 21:59:00 -08007763 }
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007764 vos_mem_copy(peerMac, peer, 6);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007765
Hoonki Lee1090c6a2013-01-16 17:40:54 -08007766#ifdef WLAN_FEATURE_TDLS_DEBUG
7767 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007768 "%s: " MAC_ADDRESS_STR " action %d, dialog_token %d status %d, len = %d",
7769 "tdls_mgmt", MAC_ADDR_ARRAY(peer),
7770 action_code, dialog_token, status_code, len);
Hoonki Lee1090c6a2013-01-16 17:40:54 -08007771#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007772
Hoonki Leea34dd892013-02-05 22:56:02 -08007773 /*Except teardown responder will not be used so just make 0*/
7774 responder = 0;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007775 if (SIR_MAC_TDLS_TEARDOWN == action_code)
Hoonki Leea34dd892013-02-05 22:56:02 -08007776 {
Gopichand Nakkala97a65fd2013-04-16 16:59:38 -07007777
7778 hddTdlsPeer_t *pTdlsPeer;
7779 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peerMac);
7780
7781 if(pTdlsPeer && TDLS_IS_CONNECTED(pTdlsPeer))
7782 responder = pTdlsPeer->is_responder;
7783 else
Hoonki Leea34dd892013-02-05 22:56:02 -08007784 {
Gopichand Nakkala97a65fd2013-04-16 16:59:38 -07007785 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7786 "%s: " MAC_ADDRESS_STR " peer doesn't exist or not connected %d dialog_token %d status %d, len = %d",
7787 __func__, MAC_ADDR_ARRAY(peer), (NULL == pTdlsPeer) ? -1 : pTdlsPeer->link_status,
7788 dialog_token, status_code, len);
7789 return -EPERM;
Hoonki Leea34dd892013-02-05 22:56:02 -08007790 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007791 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007792
Gopichand Nakkala2f1ff152013-07-01 11:27:43 +05307793 /* For explicit trigger of DIS_REQ come out of BMPS for
7794 successfully receiving DIS_RSP from peer. */
Hoonki Lee14621352013-04-16 17:51:19 -07007795 if ((SIR_MAC_TDLS_SETUP_RSP == action_code) ||
Gopichand Nakkala2f1ff152013-07-01 11:27:43 +05307796 (SIR_MAC_TDLS_DIS_RSP == action_code) ||
7797 (SIR_MAC_TDLS_DIS_REQ == action_code))
Hoonki Lee14621352013-04-16 17:51:19 -07007798 {
7799 if (TRUE == sme_IsPmcBmps(WLAN_HDD_GET_HAL_CTX(pAdapter)))
7800 {
7801 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
Gopichand Nakkala2f1ff152013-07-01 11:27:43 +05307802 "%s: Sending frame action_code %u.Disable BMPS", __func__, action_code);
Hoonki Lee14621352013-04-16 17:51:19 -07007803 hdd_disable_bmps_imps(pHddCtx, WLAN_HDD_INFRA_STATION);
7804 }
Gopichand Nakkala2f1ff152013-07-01 11:27:43 +05307805 if (SIR_MAC_TDLS_DIS_REQ != action_code)
7806 wlan_hdd_tdls_set_cap(pAdapter, peerMac, eTDLS_CAP_SUPPORTED);
Hoonki Lee14621352013-04-16 17:51:19 -07007807 }
7808
Hoonki Lee5305c3a2013-04-29 23:28:59 -07007809 /* make sure doesn't call send_mgmt() while it is pending */
7810 if (TDLS_CTX_MAGIC == pAdapter->mgmtTxCompletionStatus)
7811 {
7812 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7813 "%s: " MAC_ADDRESS_STR " action %d couldn't sent, as one is pending. return EBUSY\n",
7814 __func__, MAC_ADDR_ARRAY(peer), action_code);
7815 return -EBUSY;
7816 }
7817
7818 pAdapter->mgmtTxCompletionStatus = TDLS_CTX_MAGIC;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007819 INIT_COMPLETION(pAdapter->tdls_mgmt_comp);
7820
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007821 status = sme_SendTdlsMgmtFrame(WLAN_HDD_GET_HAL_CTX(pAdapter), pAdapter->sessionId,
Hoonki Leea34dd892013-02-05 22:56:02 -08007822 peerMac, action_code, dialog_token, status_code, (tANI_U8 *)buf, len, responder);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007823
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007824 if (VOS_STATUS_SUCCESS != status)
7825 {
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007826 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7827 "%s: sme_SendTdlsMgmtFrame failed!", __func__);
Hoonki Lee5305c3a2013-04-29 23:28:59 -07007828 pAdapter->mgmtTxCompletionStatus = FALSE;
Hoonki Lee14621352013-04-16 17:51:19 -07007829 wlan_hdd_tdls_check_bmps(pAdapter);
7830 goto error;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007831 }
7832
Hoonki Leed37cbb32013-04-20 00:31:14 -07007833 rc = wait_for_completion_interruptible_timeout(&pAdapter->tdls_mgmt_comp,
7834 msecs_to_jiffies(WAIT_TIME_TDLS_MGMT));
7835
7836 if ((rc <= 0) || (TRUE != pAdapter->mgmtTxCompletionStatus))
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007837 {
Hoonki Leed37cbb32013-04-20 00:31:14 -07007838 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7839 "%s: Mgmt Tx Completion failed status %ld TxCompletion %lu",
7840 __func__, rc, pAdapter->mgmtTxCompletionStatus);
Hoonki Lee5305c3a2013-04-29 23:28:59 -07007841 pAdapter->mgmtTxCompletionStatus = FALSE;
Hoonki Leed37cbb32013-04-20 00:31:14 -07007842 wlan_hdd_tdls_check_bmps(pAdapter);
7843 goto error;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007844 }
7845
Gopichand Nakkala05922802013-03-14 12:23:19 -07007846 if (max_sta_failed)
Hoonki Lee14621352013-04-16 17:51:19 -07007847 {
7848 wlan_hdd_tdls_check_bmps(pAdapter);
Gopichand Nakkala05922802013-03-14 12:23:19 -07007849 return max_sta_failed;
Hoonki Lee14621352013-04-16 17:51:19 -07007850 }
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007851
Hoonki Leea34dd892013-02-05 22:56:02 -08007852 if (SIR_MAC_TDLS_SETUP_RSP == action_code)
7853 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08007854 wlan_hdd_tdls_set_responder(pAdapter, peerMac, TRUE);
Hoonki Leea34dd892013-02-05 22:56:02 -08007855 }
7856 else if (SIR_MAC_TDLS_SETUP_CNF == action_code)
7857 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08007858 wlan_hdd_tdls_set_responder(pAdapter, peerMac, FALSE);
Hoonki Leea34dd892013-02-05 22:56:02 -08007859 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007860
7861 return 0;
Gopichand Nakkala05922802013-03-14 12:23:19 -07007862error:
7863 /* max_sta_failed ; we didn't set to CONNECTING for this case,
7864 because we already know that this transaction will be failed,
7865 but we weren't sure if supplicant call DISABLE_LINK or not. So,
7866 to be safe, do not change the state mahine.
7867 */
7868 if(max_sta_failed == 0 &&
7869 (WLAN_IS_TDLS_SETUP_ACTION(action_code)))
7870 wlan_hdd_tdls_set_link_status(pAdapter, peerMac, eTDLS_LINK_IDLE);
7871 return -EPERM;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007872}
7873
7874static int wlan_hdd_cfg80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
7875 u8 *peer, enum nl80211_tdls_operation oper)
7876{
7877 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7878 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307879 int status;
Hoonki Lee1090c6a2013-01-16 17:40:54 -08007880#ifdef WLAN_FEATURE_TDLS_DEBUG
7881 const char *tdls_oper_str[]= {
7882 "NL80211_TDLS_DISCOVERY_REQ",
7883 "NL80211_TDLS_SETUP",
7884 "NL80211_TDLS_TEARDOWN",
7885 "NL80211_TDLS_ENABLE_LINK",
7886 "NL80211_TDLS_DISABLE_LINK",
Gopichand Nakkala29d00192013-06-20 19:03:52 +05307887 "NL80211_TDLS_UNKNOWN_OPER"};
Hoonki Lee1090c6a2013-01-16 17:40:54 -08007888#endif
Hoonki Lee5305c3a2013-04-29 23:28:59 -07007889 hddTdlsPeer_t *pTdlsPeer;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007890
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307891 if ( NULL == peer )
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007892 {
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007893 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Chilam Ngc4244af2013-04-01 15:37:32 -07007894 "%s: Invalid arguments", __func__);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007895 return -EINVAL;
7896 }
Hoonki Lee1090c6a2013-01-16 17:40:54 -08007897
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307898 status = wlan_hdd_validate_context(pHddCtx);
7899
7900 if (0 != status)
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08007901 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307902 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7903 "%s: HDD context is not valid", __func__);
7904 return status;
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08007905 }
7906
Hoonki Lee5305c3a2013-04-29 23:28:59 -07007907 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peer);
7908
7909 if ( NULL == pTdlsPeer ) {
7910 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: " MAC_ADDRESS_STR " (oper %d) not exsting. ignored",
7911 __func__, MAC_ADDR_ARRAY(peer), (int)oper);
7912 return -EINVAL;
7913 }
7914
Hoonki Lee1090c6a2013-01-16 17:40:54 -08007915#ifdef WLAN_FEATURE_TDLS_DEBUG
7916 if((int)oper > 4)
7917 oper = 5;
7918
7919 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Hoonki Lee5305c3a2013-04-29 23:28:59 -07007920 "%s: " MAC_ADDRESS_STR " link_status %d (%s) ", "tdls_oper",
7921 MAC_ADDR_ARRAY(peer), pTdlsPeer->link_status,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007922 tdls_oper_str[(int)oper]);
Hoonki Lee1090c6a2013-01-16 17:40:54 -08007923#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007924
7925 if( FALSE == pHddCtx->cfg_ini->fEnableTDLSSupport ||
Hoonki Lee1090c6a2013-01-16 17:40:54 -08007926 FALSE == sme_IsFeatureSupportedByFW(TDLS))
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007927 {
Hoonki Lee1090c6a2013-01-16 17:40:54 -08007928 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Chilam Ngc4244af2013-04-01 15:37:32 -07007929 "TDLS Disabled in INI OR not enabled in FW. "
7930 "Cannot process TDLS commands");
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007931 return -ENOTSUPP;
7932 }
7933
7934 switch (oper) {
7935 case NL80211_TDLS_ENABLE_LINK:
7936 {
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007937 VOS_STATUS status;
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05307938 tCsrTdlsLinkEstablishParams tdlsLinkEstablishParams;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007939
Gopichand Nakkala2f4a2822013-04-17 11:22:01 -07007940 if (!TDLS_STA_INDEX_VALID(pTdlsPeer->staId))
7941 {
7942 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Staion Index %u "
7943 MAC_ADDRESS_STR " failed",
7944 __func__, pTdlsPeer->staId, MAC_ADDR_ARRAY(peer));
7945 return -EINVAL;
7946 }
7947
Hoonki Lee5305c3a2013-04-29 23:28:59 -07007948 if (eTDLS_LINK_CONNECTED != pTdlsPeer->link_status)
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007949 {
Gopichand Nakkala24be5312013-07-02 16:47:12 +05307950 long ret;
Madan Mohan Koyyalamudice419872013-09-13 19:36:52 +05307951 if (IS_ADVANCE_TDLS_ENABLE) {
Gopichand Nakkala24be5312013-07-02 16:47:12 +05307952
Madan Mohan Koyyalamudice419872013-09-13 19:36:52 +05307953 if (0 != wlan_hdd_tdls_get_link_establish_params(
7954 pAdapter, peer,&tdlsLinkEstablishParams)) {
7955 return -EINVAL;
7956 }
7957 INIT_COMPLETION(pAdapter->tdls_link_establish_req_comp);
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05307958
Madan Mohan Koyyalamudice419872013-09-13 19:36:52 +05307959 sme_SendTdlsLinkEstablishParams(WLAN_HDD_GET_HAL_CTX(pAdapter),
7960 pAdapter->sessionId, peer, &tdlsLinkEstablishParams);
7961 /* Send TDLS peer UAPSD capabilities to the firmware and
7962 * register with the TL on after the response for this operation
7963 * is received .
7964 */
7965 ret = wait_for_completion_interruptible_timeout(
7966 &pAdapter->tdls_link_establish_req_comp,
7967 msecs_to_jiffies(WAIT_TIME_TDLS_LINK_ESTABLISH_REQ));
7968 if (ret <= 0)
7969 {
7970 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7971 "%s: Link Establish Request Faled Status %ld",
7972 __func__, ret);
7973 return -EINVAL;
7974 }
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05307975 }
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07007976 wlan_hdd_tdls_set_peer_link_status(pTdlsPeer, eTDLS_LINK_CONNECTED);
Gopichand Nakkala471708b2013-06-04 20:03:01 +05307977 /* Mark TDLS client Authenticated .*/
7978 status = WLANTL_ChangeSTAState( pHddCtx->pvosContext,
7979 pTdlsPeer->staId,
7980 WLANTL_STA_AUTHENTICATED);
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07007981 if (VOS_STATUS_SUCCESS == status)
7982 {
Hoonki Lee14621352013-04-16 17:51:19 -07007983 if (pTdlsPeer->is_responder == 0)
7984 {
7985 v_U8_t staId = (v_U8_t)pTdlsPeer->staId;
7986
7987 wlan_hdd_tdls_timer_restart(pAdapter,
7988 &pTdlsPeer->initiatorWaitTimeoutTimer,
7989 WAIT_TIME_TDLS_INITIATOR);
7990 /* suspend initiator TX until it receives direct packet from the
7991 reponder or WAIT_TIME_TDLS_INITIATOR timer expires */
7992 WLANTL_SuspendDataTx( (WLAN_HDD_GET_CTX(pAdapter))->pvosContext,
7993 &staId, NULL);
7994 }
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07007995 wlan_hdd_tdls_increment_peer_count(pAdapter);
7996 }
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007997 wlan_hdd_tdls_check_bmps(pAdapter);
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05307998
7999 /* Update TL about the UAPSD masks , to route the packets to firmware */
Gopichand Nakkala574f6d12013-06-27 19:38:43 +05308000 if ((TRUE == pHddCtx->cfg_ini->fEnableTDLSBufferSta)
8001 || pHddCtx->cfg_ini->fTDLSUapsdMask )
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05308002 {
Gopichand Nakkala574f6d12013-06-27 19:38:43 +05308003 int ac;
8004 uint8 ucAc[4] = { WLANTL_AC_VO,
8005 WLANTL_AC_VI,
8006 WLANTL_AC_BK,
8007 WLANTL_AC_BE };
8008 uint8 tlTid[4] = { 7, 5, 2, 3 } ;
8009 for(ac=0; ac < 4; ac++)
8010 {
8011 status = WLANTL_EnableUAPSDForAC( (WLAN_HDD_GET_CTX(pAdapter))->pvosContext,
8012 pTdlsPeer->staId, ucAc[ac],
8013 tlTid[ac], tlTid[ac], 0, 0,
8014 WLANTL_BI_DIR );
8015 }
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05308016 }
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008017 }
8018
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008019 }
8020 break;
8021 case NL80211_TDLS_DISABLE_LINK:
Lee Hoonkic1262f22013-01-24 21:59:00 -08008022 {
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008023 if(TDLS_STA_INDEX_VALID(pTdlsPeer->staId))
Lee Hoonkic1262f22013-01-24 21:59:00 -08008024 {
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07008025 long status;
8026
8027 INIT_COMPLETION(pAdapter->tdls_del_station_comp);
8028
Lee Hoonkic1262f22013-01-24 21:59:00 -08008029 sme_DeleteTdlsPeerSta( WLAN_HDD_GET_HAL_CTX(pAdapter),
8030 pAdapter->sessionId, peer );
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07008031
8032 status = wait_for_completion_interruptible_timeout(&pAdapter->tdls_del_station_comp,
8033 msecs_to_jiffies(WAIT_TIME_TDLS_DEL_STA));
8034 if (status <= 0)
8035 {
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008036 wlan_hdd_tdls_set_peer_link_status(pTdlsPeer, eTDLS_LINK_IDLE);
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07008037 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8038 "%s: Del station failed status %ld",
8039 __func__, status);
8040 return -EPERM;
8041 }
Hoonki Lee5305c3a2013-04-29 23:28:59 -07008042 wlan_hdd_tdls_set_peer_link_status(pTdlsPeer, eTDLS_LINK_IDLE);
Lee Hoonkic1262f22013-01-24 21:59:00 -08008043 }
8044 else
8045 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008046 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8047 "%s: TDLS Peer Station doesn't exist.", __func__);
Lee Hoonkic1262f22013-01-24 21:59:00 -08008048 }
Lee Hoonkic1262f22013-01-24 21:59:00 -08008049 }
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07008050 break;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008051 case NL80211_TDLS_TEARDOWN:
8052 case NL80211_TDLS_SETUP:
8053 case NL80211_TDLS_DISCOVERY_REQ:
8054 /* We don't support in-driver setup/teardown/discovery */
8055 return -ENOTSUPP;
8056 default:
8057 return -ENOTSUPP;
8058 }
8059 return 0;
8060}
Chilam NG571c65a2013-01-19 12:27:36 +05308061
8062int wlan_hdd_cfg80211_send_tdls_discover_req(struct wiphy *wiphy,
8063 struct net_device *dev, u8 *peer)
8064{
8065 hddLog(VOS_TRACE_LEVEL_INFO, "tdls send discover req: %x %x %x %x %x %x",
8066 peer[0], peer[1], peer[2], peer[3], peer[4], peer[5]);
8067
8068 return wlan_hdd_cfg80211_tdls_mgmt(wiphy, dev, peer,
8069 WLAN_TDLS_DISCOVERY_REQUEST, 1, 0, NULL, 0);
8070}
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008071#endif
8072
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308073#ifdef WLAN_FEATURE_GTK_OFFLOAD
8074/*
8075 * FUNCTION: wlan_hdd_cfg80211_update_replayCounterCallback
8076 * Callback rountine called upon receiving response for
8077 * get offload info
8078 */
8079void wlan_hdd_cfg80211_update_replayCounterCallback(void *callbackContext,
8080 tpSirGtkOffloadGetInfoRspParams pGtkOffloadGetInfoRsp)
8081{
8082
8083 hdd_adapter_t *pAdapter = (hdd_adapter_t *)callbackContext;
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308084 tANI_U8 tempReplayCounter[8];
8085 hdd_station_ctx_t *pHddStaCtx;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308086
8087 ENTER();
8088
8089 if (NULL == pAdapter)
8090 {
8091 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8092 "%s: HDD adapter is Null", __func__);
8093 return ;
8094 }
8095
8096 if (NULL == pGtkOffloadGetInfoRsp)
8097 {
8098 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8099 "%s: pGtkOffloadGetInfoRsp is Null", __func__);
8100 return ;
8101 }
8102
8103 if (VOS_STATUS_SUCCESS != pGtkOffloadGetInfoRsp->ulStatus)
8104 {
8105 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8106 "%s: wlan Failed to get replay counter value",
8107 __func__);
8108 return ;
8109 }
8110
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308111 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
8112 /* Update replay counter */
8113 pHddStaCtx->gtkOffloadReqParams.ullKeyReplayCounter =
8114 pGtkOffloadGetInfoRsp->ullKeyReplayCounter;
8115
8116 {
8117 /* changing from little to big endian since supplicant
8118 * works on big endian format
8119 */
8120 int i;
8121 tANI_U8 *p = (tANI_U8 *)&pGtkOffloadGetInfoRsp->ullKeyReplayCounter;
8122
8123 for (i = 0; i < 8; i++)
8124 {
8125 tempReplayCounter[7-i] = (tANI_U8)p[i];
8126 }
8127 }
8128
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308129 /* Update replay counter to NL */
8130 cfg80211_gtk_rekey_notify(pAdapter->dev, pGtkOffloadGetInfoRsp->bssId,
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308131 tempReplayCounter, GFP_KERNEL);
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308132}
8133
8134/*
8135 * FUNCTION: wlan_hdd_cfg80211_set_rekey_data
8136 * This function is used to offload GTK rekeying job to the firmware.
8137 */
8138int wlan_hdd_cfg80211_set_rekey_data(struct wiphy *wiphy, struct net_device *dev,
8139 struct cfg80211_gtk_rekey_data *data)
8140{
8141 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8142 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
8143 hdd_station_ctx_t *pHddStaCtx;
8144 tHalHandle hHal;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308145 int result;
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308146 tSirGtkOffloadParams hddGtkOffloadReqParams;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308147 eHalStatus status = eHAL_STATUS_FAILURE;
8148
8149 ENTER();
8150
8151 if (NULL == pAdapter)
8152 {
8153 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8154 "%s: HDD adapter is Null", __func__);
8155 return -ENODEV;
8156 }
8157
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308158 result = wlan_hdd_validate_context(pHddCtx);
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308159
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308160 if (0 != result)
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308161 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308162 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8163 "%s: HDD context is not valid", __func__);
8164 return result;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308165 }
8166
8167 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
8168 hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
8169 if (NULL == hHal)
8170 {
8171 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8172 "%s: HAL context is Null!!!", __func__);
8173 return -EAGAIN;
8174 }
8175
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308176 pHddStaCtx->gtkOffloadReqParams.ulFlags = GTK_OFFLOAD_ENABLE;
8177 memcpy(pHddStaCtx->gtkOffloadReqParams.aKCK, data->kck, NL80211_KCK_LEN);
8178 memcpy(pHddStaCtx->gtkOffloadReqParams.aKEK, data->kek, NL80211_KEK_LEN);
8179 memcpy(pHddStaCtx->gtkOffloadReqParams.bssId, &pHddStaCtx->conn_info.bssId,
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308180 WNI_CFG_BSSID_LEN);
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308181 {
8182 /* changing from big to little endian since driver
8183 * works on little endian format
8184 */
8185 tANI_U8 *p =
8186 (tANI_U8 *)&pHddStaCtx->gtkOffloadReqParams.ullKeyReplayCounter;
8187 int i;
8188
8189 for (i = 0; i < 8; i++)
8190 {
8191 p[7-i] = data->replay_ctr[i];
8192 }
8193 }
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308194
8195 if (TRUE == pHddCtx->hdd_wlan_suspended)
8196 {
8197 /* if wlan is suspended, enable GTK offload directly from here */
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308198 memcpy(&hddGtkOffloadReqParams, &pHddStaCtx->gtkOffloadReqParams,
8199 sizeof (tSirGtkOffloadParams));
8200 status = sme_SetGTKOffload(hHal, &hddGtkOffloadReqParams,
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308201 pAdapter->sessionId);
8202
8203 if (eHAL_STATUS_SUCCESS != status)
8204 {
8205 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8206 "%s: sme_SetGTKOffload failed, returned %d",
8207 __func__, status);
8208 return status;
8209 }
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308210 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8211 "%s: sme_SetGTKOffload successfull", __func__);
8212 }
8213 else
8214 {
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308215 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8216 "%s: wlan not suspended GTKOffload request is stored",
8217 __func__);
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308218 }
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308219
8220 return eHAL_STATUS_SUCCESS;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308221}
8222#endif /*WLAN_FEATURE_GTK_OFFLOAD*/
8223
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05308224/*
8225 * FUNCTION: wlan_hdd_cfg80211_set_mac_acl
8226 * This function is used to set access control policy
8227 */
8228static int wlan_hdd_cfg80211_set_mac_acl(struct wiphy *wiphy,
8229 struct net_device *dev, const struct cfg80211_acl_data *params)
8230{
8231 int i;
8232 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8233 hdd_hostapd_state_t *pHostapdState;
8234 tsap_Config_t *pConfig;
8235 v_CONTEXT_t pVosContext = NULL;
8236 hdd_context_t *pHddCtx;
8237 int status;
8238
8239 ENTER();
8240
8241 if (NULL == pAdapter)
8242 {
8243 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8244 "%s: HDD adapter is Null", __func__);
8245 return -ENODEV;
8246 }
8247
8248 if (NULL == params)
8249 {
8250 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8251 "%s: params is Null", __func__);
8252 return -EINVAL;
8253 }
8254
8255 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
8256 status = wlan_hdd_validate_context(pHddCtx);
8257
8258 if (0 != status)
8259 {
8260 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8261 "%s: HDD context is not valid", __func__);
8262 return status;
8263 }
8264
8265 pVosContext = pHddCtx->pvosContext;
8266 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
8267
8268 if (NULL == pHostapdState)
8269 {
8270 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8271 "%s: pHostapdState is Null", __func__);
8272 return -EINVAL;
8273 }
8274
8275 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,"acl policy: = %d"
8276 "no acl entries = %d", params->acl_policy, params->n_acl_entries);
8277
8278 if (WLAN_HDD_SOFTAP == pAdapter->device_mode)
8279 {
8280 pConfig = &pAdapter->sessionCtx.ap.sapConfig;
8281
8282 /* default value */
8283 pConfig->num_accept_mac = 0;
8284 pConfig->num_deny_mac = 0;
8285
8286 /**
8287 * access control policy
8288 * @NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED: Deny stations which are
8289 * listed in hostapd.deny file.
8290 * @NL80211_ACL_POLICY_DENY_UNLESS_LISTED: Allow stations which are
8291 * listed in hostapd.accept file.
8292 */
8293 if (NL80211_ACL_POLICY_DENY_UNLESS_LISTED == params->acl_policy)
8294 {
8295 pConfig->SapMacaddr_acl = eSAP_DENY_UNLESS_ACCEPTED;
8296 }
8297 else if (NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED == params->acl_policy)
8298 {
8299 pConfig->SapMacaddr_acl = eSAP_ACCEPT_UNLESS_DENIED;
8300 }
8301 else
8302 {
8303 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8304 "%s:Acl Policy : %d is not supported",
8305 __func__, params->acl_policy);
8306 return -ENOTSUPP;
8307 }
8308
8309 if (eSAP_DENY_UNLESS_ACCEPTED == pConfig->SapMacaddr_acl)
8310 {
8311 pConfig->num_accept_mac = params->n_acl_entries;
8312 for (i = 0; i < params->n_acl_entries; i++)
8313 {
8314 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8315 "** Add ACL MAC entry %i in WhiletList :"
8316 MAC_ADDRESS_STR, i,
8317 MAC_ADDR_ARRAY(params->mac_addrs[i].addr));
8318
8319 vos_mem_copy(&pConfig->accept_mac[i], params->mac_addrs[i].addr,
8320 sizeof(qcmacaddr));
8321 }
8322 }
8323 else if (eSAP_ACCEPT_UNLESS_DENIED == pConfig->SapMacaddr_acl)
8324 {
8325 pConfig->num_deny_mac = params->n_acl_entries;
8326 for (i = 0; i < params->n_acl_entries; i++)
8327 {
8328 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8329 "** Add ACL MAC entry %i in BlackList :"
8330 MAC_ADDRESS_STR, i,
8331 MAC_ADDR_ARRAY(params->mac_addrs[i].addr));
8332
8333 vos_mem_copy(&pConfig->deny_mac[i], params->mac_addrs[i].addr,
8334 sizeof(qcmacaddr));
8335 }
8336 }
8337
8338 if (VOS_STATUS_SUCCESS != WLANSAP_SetMacACL(pVosContext, pConfig))
8339 {
8340 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8341 "%s: SAP Set Mac Acl fail", __func__);
8342 return -EINVAL;
8343 }
8344 }
8345 else
8346 {
8347 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8348 "%s: Invalid device_mode = %d",
8349 __func__, pAdapter->device_mode);
8350 return -EINVAL;
8351 }
8352
8353 return 0;
8354}
8355
Leo Chang9056f462013-08-01 19:21:11 -07008356#ifdef WLAN_NL80211_TESTMODE
8357#ifdef FEATURE_WLAN_LPHB
8358static void wlan_hdd_cfg80211_lphb_wait_timeout_ind_handler
8359(
8360 void *pAdapter,
8361 void *indCont
8362)
8363{
8364 tSirLPHBTimeoutInd *lphbTimeoutInd;
8365 struct sk_buff *skb;
8366
8367 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8368 "LPHB wait timeout indication arrived");
8369
8370 if (NULL == indCont)
8371 {
8372 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8373 "LPHB timeout, invalid argument");
8374 return;
8375 }
8376
8377 lphbTimeoutInd = (tSirLPHBTimeoutInd *)indCont;
8378 skb = cfg80211_testmode_alloc_event_skb(
8379 ((hdd_adapter_t *)pAdapter)->wdev.wiphy,
8380 sizeof(tSirLPHBTimeoutInd),
8381 GFP_ATOMIC);
8382 if (!skb)
8383 {
8384 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8385 "LPHB timeout, NL buffer alloc fail");
8386 return;
8387 }
8388
8389 NLA_PUT_U32(skb, WLAN_HDD_TM_ATTR_CMD, WLAN_HDD_TM_CMD_WLAN_HB);
8390 NLA_PUT_U32(skb, WLAN_HDD_TM_ATTR_TYPE, lphbTimeoutInd->protocolType);
8391 NLA_PUT(skb, WLAN_HDD_TM_ATTR_DATA,
8392 sizeof(tSirLPHBTimeoutInd), lphbTimeoutInd);
8393 cfg80211_testmode_event(skb, GFP_ATOMIC);
8394 return;
8395
8396nla_put_failure:
8397 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8398 "NLA Put fail");
8399 kfree_skb(skb);
8400
8401 return;
8402}
8403#endif /* FEATURE_WLAN_LPHB */
8404
8405static int wlan_hdd_cfg80211_testmode(struct wiphy *wiphy, void *data, int len)
8406{
8407 struct nlattr *tb[WLAN_HDD_TM_ATTR_MAX + 1];
8408 int err = 0;
8409#ifdef FEATURE_WLAN_LPHB
8410 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
8411#endif /* FEATURE_WLAN_LPHB */
8412
8413 err = nla_parse(tb, WLAN_HDD_TM_ATTR_MAX, data, len, wlan_hdd_tm_policy);
8414 if (err)
8415 {
8416 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8417 "%s Testmode INV ATTR", __func__);
8418 return err;
8419 }
8420
8421 if (!tb[WLAN_HDD_TM_ATTR_CMD])
8422 {
8423 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8424 "%s Testmode INV CMD", __func__);
8425 return -EINVAL;
8426 }
8427
8428 switch (nla_get_u32(tb[WLAN_HDD_TM_ATTR_CMD]))
8429 {
8430#ifdef FEATURE_WLAN_LPHB
8431 /* Low Power Heartbeat configuration request */
8432 case WLAN_HDD_TM_CMD_WLAN_HB:
8433 {
8434 int buf_len;
8435 void *buf;
8436 tSirLPHBReq *hb_params = NULL;
8437
8438 if (!tb[WLAN_HDD_TM_ATTR_DATA])
8439 {
8440 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8441 "%s Testmode INV DATA", __func__);
8442 return -EINVAL;
8443 }
8444
8445 buf = nla_data(tb[WLAN_HDD_TM_ATTR_DATA]);
8446 buf_len = nla_len(tb[WLAN_HDD_TM_ATTR_DATA]);
8447 hb_params = (tSirLPHBReq *)vos_mem_malloc(sizeof(tSirLPHBReq));
8448 if (NULL == hb_params)
8449 {
8450 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8451 "%s Request Buffer Alloc Fail", __func__);
8452 return -EINVAL;
8453 }
8454
8455 vos_mem_copy(hb_params, buf, buf_len);
8456
8457 /* LPHB enable and disable request will send to FW
8458 * when host suspend and resume
8459 * host suspend -> enable LPHB
8460 * host resume -> disable LPHB
8461 * if host is not suspend, cache into HDD context
8462 * and when host goes to suspend, send request to FW */
8463 if ((LPHB_SET_EN_PARAMS_INDID == hb_params->cmd) &&
8464 (!pHddCtx->hdd_wlan_suspended))
8465 {
8466 /* Feature enable command cache into HDD context,
8467 * if WLAN is not suspend
8468 * When WLAN goes into suspend, send enable command to FW */
8469 pHddCtx->lphbEnableReq.enable =
8470 hb_params->params.lphbEnableReq.enable;
8471 pHddCtx->lphbEnableReq.item =
8472 hb_params->params.lphbEnableReq.item;
8473 pHddCtx->lphbEnableReq.session =
8474 hb_params->params.lphbEnableReq.session;
8475 vos_mem_free(hb_params);
8476 }
8477 else
8478 {
8479 eHalStatus smeStatus;
8480
8481 /* If WLAN is suspend state, send enable command immediately */
8482 smeStatus = sme_LPHBConfigReq((tHalHandle)(pHddCtx->hHal),
8483 hb_params,
8484 wlan_hdd_cfg80211_lphb_wait_timeout_ind_handler);
8485 if (eHAL_STATUS_SUCCESS != smeStatus)
8486 {
8487 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8488 "LPHB Config Fail, disable");
8489 pHddCtx->lphbEnableReq.enable = 0;
8490 vos_mem_free(hb_params);
8491 }
8492 }
8493 return 0;
8494 }
8495#endif /* FEATURE_WLAN_LPHB */
8496 default:
8497 return -EOPNOTSUPP;
8498 }
8499
8500 return err;
8501}
8502#endif /* CONFIG_NL80211_TESTMODE */
8503
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05308504static int wlan_hdd_cfg80211_dump_survey(struct wiphy *wiphy,
8505 struct net_device *dev,
8506 int idx, struct survey_info *survey)
8507{
8508 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8509 hdd_context_t *pHddCtx;
Mihir Sheted9072e02013-08-21 17:02:29 +05308510 hdd_station_ctx_t *pHddStaCtx;
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05308511 tHalHandle halHandle;
Mihir Sheted9072e02013-08-21 17:02:29 +05308512 v_U32_t channel = 0, freq = 0; /* Initialization Required */
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05308513 v_S7_t snr,rssi;
8514 int status, i, j, filled = 0;
8515
8516 ENTER();
8517
8518
8519 if (NULL == pAdapter)
8520 {
8521 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8522 "%s: HDD adapter is Null", __func__);
8523 return -ENODEV;
8524 }
8525
8526 if (NULL == wiphy)
8527 {
8528 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8529 "%s: wiphy is Null", __func__);
8530 return -ENODEV;
8531 }
8532
8533 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
8534 status = wlan_hdd_validate_context(pHddCtx);
8535
8536 if (0 != status)
8537 {
8538 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8539 "%s: HDD context is not valid", __func__);
8540 return status;
8541 }
8542
Mihir Sheted9072e02013-08-21 17:02:29 +05308543 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
8544
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05308545 if (0 == pHddCtx->cfg_ini->fEnableSNRMonitoring ||
Mihir Sheted9072e02013-08-21 17:02:29 +05308546 0 != pAdapter->survey_idx ||
8547 eConnectionState_Associated != pHddStaCtx->conn_info.connState)
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05308548 {
8549 /* The survey dump ops when implemented completely is expected to
8550 * return a survey of all channels and the ops is called by the
8551 * kernel with incremental values of the argument 'idx' till it
8552 * returns -ENONET. But we can only support the survey for the
8553 * operating channel for now. survey_idx is used to track
8554 * that the ops is called only once and then return -ENONET for
8555 * the next iteration
8556 */
8557 pAdapter->survey_idx = 0;
8558 return -ENONET;
8559 }
8560
8561 halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
8562
8563 wlan_hdd_get_snr(pAdapter, &snr);
8564 wlan_hdd_get_rssi(pAdapter, &rssi);
8565
8566 sme_GetOperationChannel(halHandle, &channel, pAdapter->sessionId);
8567 hdd_wlan_get_freq(channel, &freq);
8568
8569
8570 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
8571 {
8572 if (NULL == wiphy->bands[i])
8573 {
8574 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
8575 "%s: wiphy->bands[i] is NULL, i = %d", __func__, i);
8576 continue;
8577 }
8578
8579 for (j = 0; j < wiphy->bands[i]->n_channels; j++)
8580 {
8581 struct ieee80211_supported_band *band = wiphy->bands[i];
8582
8583 if (band->channels[j].center_freq == (v_U16_t)freq)
8584 {
8585 survey->channel = &band->channels[j];
8586 /* The Rx BDs contain SNR values in dB for the received frames
8587 * while the supplicant expects noise. So we calculate and
8588 * return the value of noise (dBm)
8589 * SNR (dB) = RSSI (dBm) - NOISE (dBm)
8590 */
8591 survey->noise = rssi - snr;
8592 survey->filled = SURVEY_INFO_NOISE_DBM;
8593 filled = 1;
8594 }
8595 }
8596 }
8597
8598 if (filled)
8599 pAdapter->survey_idx = 1;
8600 else
8601 {
8602 pAdapter->survey_idx = 0;
8603 return -ENONET;
8604 }
8605
8606 return 0;
8607}
8608
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308609/*
8610 * FUNCTION: wlan_hdd_cfg80211_resume_wlan
8611 * this is called when cfg80211 driver resume
8612 * driver updates latest sched_scan scan result(if any) to cfg80211 database
8613 */
8614int wlan_hdd_cfg80211_resume_wlan(struct wiphy *wiphy)
8615{
8616 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
8617 hdd_adapter_t *pAdapter;
8618 hdd_adapter_list_node_t *pAdapterNode, *pNext;
8619 VOS_STATUS status = VOS_STATUS_SUCCESS;
8620
8621 ENTER();
8622
8623 if ( NULL == pHddCtx )
8624 {
8625 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8626 "%s: HddCtx validation failed", __func__);
8627 return 0;
8628 }
8629
8630 if (pHddCtx->isLogpInProgress)
8631 {
8632 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8633 "%s: LOGP in Progress. Ignore!!!", __func__);
8634 return 0;
8635 }
8636
8637 if (pHddCtx->isLoadUnloadInProgress)
8638 {
8639 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8640 "%s: Unloading/Loading in Progress. Ignore!!!", __func__);
8641 return 0;
8642 }
8643
8644 spin_lock(&pHddCtx->schedScan_lock);
8645 pHddCtx->isWiphySuspended = FALSE;
8646 if (TRUE != pHddCtx->isSchedScanUpdatePending)
8647 {
8648 spin_unlock(&pHddCtx->schedScan_lock);
8649 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8650 "%s: Return resume is not due to PNO indication", __func__);
8651 return 0;
8652 }
8653 // Reset flag to avoid updatating cfg80211 data old results again
8654 pHddCtx->isSchedScanUpdatePending = FALSE;
8655 spin_unlock(&pHddCtx->schedScan_lock);
8656
8657 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
8658
8659 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
8660 {
8661 pAdapter = pAdapterNode->pAdapter;
8662 if ( (NULL != pAdapter) &&
8663 (WLAN_HDD_INFRA_STATION == pAdapter->device_mode) )
8664 {
8665 if (0 != wlan_hdd_cfg80211_update_bss(pHddCtx->wiphy, pAdapter))
8666 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
8667 "%s: NO SCAN result", __func__);
8668 else
8669 cfg80211_sched_scan_results(pHddCtx->wiphy);
8670
8671 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8672 "%s : cfg80211 scan result database updated", __func__);
8673
8674 return 0;
8675
8676 }
8677 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
8678 pAdapterNode = pNext;
8679 }
8680
8681 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8682 "%s: Failed to find Adapter", __func__);
8683 return 0;
8684}
8685
8686/*
8687 * FUNCTION: wlan_hdd_cfg80211_suspend_wlan
8688 * this is called when cfg80211 driver suspends
8689 */
8690int wlan_hdd_cfg80211_suspend_wlan(struct wiphy *wiphy,
8691 struct cfg80211_wowlan *wow)
8692{
8693 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
8694
8695 ENTER();
8696 if (NULL == pHddCtx)
8697 {
8698 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8699 "%s: HddCtx validation failed", __func__);
8700 return 0;
8701 }
8702
8703 pHddCtx->isWiphySuspended = TRUE;
8704
8705 EXIT();
8706
8707 return 0;
8708}
8709
Jeff Johnson295189b2012-06-20 16:38:30 -07008710/* cfg80211_ops */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05308711static struct cfg80211_ops wlan_hdd_cfg80211_ops =
Jeff Johnson295189b2012-06-20 16:38:30 -07008712{
8713 .add_virtual_intf = wlan_hdd_add_virtual_intf,
8714 .del_virtual_intf = wlan_hdd_del_virtual_intf,
8715 .change_virtual_intf = wlan_hdd_cfg80211_change_iface,
8716 .change_station = wlan_hdd_change_station,
8717#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
8718 .add_beacon = wlan_hdd_cfg80211_add_beacon,
8719 .del_beacon = wlan_hdd_cfg80211_del_beacon,
8720 .set_beacon = wlan_hdd_cfg80211_set_beacon,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008721#else
8722 .start_ap = wlan_hdd_cfg80211_start_ap,
8723 .change_beacon = wlan_hdd_cfg80211_change_beacon,
8724 .stop_ap = wlan_hdd_cfg80211_stop_ap,
Jeff Johnson295189b2012-06-20 16:38:30 -07008725#endif
8726 .change_bss = wlan_hdd_cfg80211_change_bss,
8727 .add_key = wlan_hdd_cfg80211_add_key,
8728 .get_key = wlan_hdd_cfg80211_get_key,
8729 .del_key = wlan_hdd_cfg80211_del_key,
8730 .set_default_key = wlan_hdd_cfg80211_set_default_key,
Jeff Johnson3bbe4bf2013-01-18 17:05:29 -08008731#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07008732 .set_channel = wlan_hdd_cfg80211_set_channel,
Jeff Johnson3bbe4bf2013-01-18 17:05:29 -08008733#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07008734 .scan = wlan_hdd_cfg80211_scan,
8735 .connect = wlan_hdd_cfg80211_connect,
8736 .disconnect = wlan_hdd_cfg80211_disconnect,
8737 .join_ibss = wlan_hdd_cfg80211_join_ibss,
8738 .leave_ibss = wlan_hdd_cfg80211_leave_ibss,
8739 .set_wiphy_params = wlan_hdd_cfg80211_set_wiphy_params,
8740 .set_tx_power = wlan_hdd_cfg80211_set_txpower,
8741 .get_tx_power = wlan_hdd_cfg80211_get_txpower,
Jeff Johnson295189b2012-06-20 16:38:30 -07008742 .remain_on_channel = wlan_hdd_cfg80211_remain_on_channel,
8743 .cancel_remain_on_channel = wlan_hdd_cfg80211_cancel_remain_on_channel,
8744 .mgmt_tx = wlan_hdd_action,
8745#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
8746 .mgmt_tx_cancel_wait = wlan_hdd_cfg80211_mgmt_tx_cancel_wait,
8747 .set_default_mgmt_key = wlan_hdd_set_default_mgmt_key,
8748 .set_txq_params = wlan_hdd_set_txq_params,
8749#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07008750 .get_station = wlan_hdd_cfg80211_get_station,
8751 .set_power_mgmt = wlan_hdd_cfg80211_set_power_mgmt,
8752 .del_station = wlan_hdd_cfg80211_del_station,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008753 .add_station = wlan_hdd_cfg80211_add_station,
8754#ifdef FEATURE_WLAN_LFR
8755 .set_pmksa = wlan_hdd_cfg80211_set_pmksa,
8756 .del_pmksa = wlan_hdd_cfg80211_del_pmksa,
8757 .flush_pmksa = wlan_hdd_cfg80211_flush_pmksa,
8758#endif
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07008759#if defined(WLAN_FEATURE_VOWIFI_11R) && defined(KERNEL_SUPPORT_11R_CFG80211)
8760 .update_ft_ies = wlan_hdd_cfg80211_update_ft_ies,
8761#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008762#ifdef FEATURE_WLAN_TDLS
8763 .tdls_mgmt = wlan_hdd_cfg80211_tdls_mgmt,
8764 .tdls_oper = wlan_hdd_cfg80211_tdls_oper,
8765#endif
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308766#ifdef WLAN_FEATURE_GTK_OFFLOAD
8767 .set_rekey_data = wlan_hdd_cfg80211_set_rekey_data,
8768#endif /* WLAN_FEATURE_GTK_OFFLOAD */
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308769#ifdef FEATURE_WLAN_SCAN_PNO
8770 .sched_scan_start = wlan_hdd_cfg80211_sched_scan_start,
8771 .sched_scan_stop = wlan_hdd_cfg80211_sched_scan_stop,
8772#endif /*FEATURE_WLAN_SCAN_PNO */
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308773 .resume = wlan_hdd_cfg80211_resume_wlan,
8774 .suspend = wlan_hdd_cfg80211_suspend_wlan,
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05308775 .set_mac_acl = wlan_hdd_cfg80211_set_mac_acl,
Leo Chang9056f462013-08-01 19:21:11 -07008776#ifdef WLAN_NL80211_TESTMODE
8777 .testmode_cmd = wlan_hdd_cfg80211_testmode,
8778#endif
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05308779 .dump_survey = wlan_hdd_cfg80211_dump_survey,
Jeff Johnson295189b2012-06-20 16:38:30 -07008780};
8781