blob: 9c05427033077372bd2a5d2fafda53d15509c84d [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"
Mohit Khanna698ba2a2012-12-04 15:08:18 -080087#endif
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +053088#include "wlan_nv.h"
Leo Chang6fe1f922013-06-07 19:21:24 -070089#include "wlan_hdd_dev_pwr.h"
Jeff Johnson295189b2012-06-20 16:38:30 -070090
91#define g_mode_rates_size (12)
92#define a_mode_rates_size (8)
93#define FREQ_BASE_80211G (2407)
94#define FREQ_BAND_DIFF_80211G (5)
Jeff Johnson04dd8a82012-06-29 20:41:40 -070095#define MAX_SCAN_SSID 9
Jeff Johnson295189b2012-06-20 16:38:30 -070096#define GET_IE_LEN_IN_BSS_DESC(lenInBss) ( lenInBss + sizeof(lenInBss) - \
97 ((int) OFFSET_OF( tSirBssDescription, ieFields)))
98
99#define HDD2GHZCHAN(freq, chan, flag) { \
100 .band = IEEE80211_BAND_2GHZ, \
101 .center_freq = (freq), \
102 .hw_value = (chan),\
103 .flags = (flag), \
104 .max_antenna_gain = 0 ,\
105 .max_power = 30, \
106}
107
108#define HDD5GHZCHAN(freq, chan, flag) { \
109 .band = IEEE80211_BAND_5GHZ, \
110 .center_freq = (freq), \
111 .hw_value = (chan),\
112 .flags = (flag), \
113 .max_antenna_gain = 0 ,\
114 .max_power = 30, \
115}
116
117#define HDD_G_MODE_RATETAB(rate, rate_id, flag)\
118{\
119 .bitrate = rate, \
120 .hw_value = rate_id, \
121 .flags = flag, \
122}
123
Lee Hoonkic1262f22013-01-24 21:59:00 -0800124#ifndef WLAN_FEATURE_TDLS_DEBUG
125#define TDLS_LOG_LEVEL VOS_TRACE_LEVEL_INFO
126#else
127#define TDLS_LOG_LEVEL VOS_TRACE_LEVEL_ERROR
128#endif
129
Gopichand Nakkala356fb102013-03-06 12:34:04 +0530130#ifdef WLAN_FEATURE_VOWIFI_11R
131#define WLAN_AKM_SUITE_FT_8021X 0x000FAC03
132#define WLAN_AKM_SUITE_FT_PSK 0x000FAC04
133#endif
134
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530135static const u32 hdd_cipher_suites[] =
Jeff Johnson295189b2012-06-20 16:38:30 -0700136{
137 WLAN_CIPHER_SUITE_WEP40,
138 WLAN_CIPHER_SUITE_WEP104,
139 WLAN_CIPHER_SUITE_TKIP,
140#ifdef FEATURE_WLAN_CCX
141#define WLAN_CIPHER_SUITE_KRK 0x004096ff /* use for KRK */
142 WLAN_CIPHER_SUITE_KRK,
143 WLAN_CIPHER_SUITE_CCMP,
144#else
145 WLAN_CIPHER_SUITE_CCMP,
146#endif
147#ifdef FEATURE_WLAN_WAPI
148 WLAN_CIPHER_SUITE_SMS4,
149#endif
Chet Lanctot186b5732013-03-18 10:26:30 -0700150#ifdef WLAN_FEATURE_11W
151 WLAN_CIPHER_SUITE_AES_CMAC,
152#endif
Jeff Johnson295189b2012-06-20 16:38:30 -0700153};
154
155static inline int is_broadcast_ether_addr(const u8 *addr)
156{
157 return ((addr[0] == 0xff) && (addr[1] == 0xff) && (addr[2] == 0xff) &&
158 (addr[3] == 0xff) && (addr[4] == 0xff) && (addr[5] == 0xff));
159}
160
161static struct ieee80211_channel hdd_channels_2_4_GHZ[] =
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530162{
Jeff Johnson295189b2012-06-20 16:38:30 -0700163 HDD2GHZCHAN(2412, 1, 0) ,
164 HDD2GHZCHAN(2417, 2, 0) ,
165 HDD2GHZCHAN(2422, 3, 0) ,
166 HDD2GHZCHAN(2427, 4, 0) ,
167 HDD2GHZCHAN(2432, 5, 0) ,
168 HDD2GHZCHAN(2437, 6, 0) ,
169 HDD2GHZCHAN(2442, 7, 0) ,
170 HDD2GHZCHAN(2447, 8, 0) ,
171 HDD2GHZCHAN(2452, 9, 0) ,
172 HDD2GHZCHAN(2457, 10, 0) ,
173 HDD2GHZCHAN(2462, 11, 0) ,
174 HDD2GHZCHAN(2467, 12, 0) ,
175 HDD2GHZCHAN(2472, 13, 0) ,
176 HDD2GHZCHAN(2484, 14, 0) ,
177};
178
Jeff Johnson295189b2012-06-20 16:38:30 -0700179static struct ieee80211_channel hdd_social_channels_2_4_GHZ[] =
180{
181 HDD2GHZCHAN(2412, 1, 0) ,
182 HDD2GHZCHAN(2437, 6, 0) ,
183 HDD2GHZCHAN(2462, 11, 0) ,
184};
Jeff Johnson295189b2012-06-20 16:38:30 -0700185
186static struct ieee80211_channel hdd_channels_5_GHZ[] =
187{
Madan Mohan Koyyalamudic3a240c2012-09-28 15:34:08 -0700188 HDD5GHZCHAN(4920, 240, 0) ,
189 HDD5GHZCHAN(4940, 244, 0) ,
190 HDD5GHZCHAN(4960, 248, 0) ,
191 HDD5GHZCHAN(4980, 252, 0) ,
192 HDD5GHZCHAN(5040, 208, 0) ,
193 HDD5GHZCHAN(5060, 212, 0) ,
194 HDD5GHZCHAN(5080, 216, 0) ,
Jeff Johnson295189b2012-06-20 16:38:30 -0700195 HDD5GHZCHAN(5180, 36, 0) ,
196 HDD5GHZCHAN(5200, 40, 0) ,
197 HDD5GHZCHAN(5220, 44, 0) ,
198 HDD5GHZCHAN(5240, 48, 0) ,
199 HDD5GHZCHAN(5260, 52, 0) ,
200 HDD5GHZCHAN(5280, 56, 0) ,
201 HDD5GHZCHAN(5300, 60, 0) ,
202 HDD5GHZCHAN(5320, 64, 0) ,
203 HDD5GHZCHAN(5500,100, 0) ,
204 HDD5GHZCHAN(5520,104, 0) ,
205 HDD5GHZCHAN(5540,108, 0) ,
206 HDD5GHZCHAN(5560,112, 0) ,
207 HDD5GHZCHAN(5580,116, 0) ,
208 HDD5GHZCHAN(5600,120, 0) ,
209 HDD5GHZCHAN(5620,124, 0) ,
210 HDD5GHZCHAN(5640,128, 0) ,
211 HDD5GHZCHAN(5660,132, 0) ,
212 HDD5GHZCHAN(5680,136, 0) ,
213 HDD5GHZCHAN(5700,140, 0) ,
214 HDD5GHZCHAN(5745,149, 0) ,
215 HDD5GHZCHAN(5765,153, 0) ,
216 HDD5GHZCHAN(5785,157, 0) ,
217 HDD5GHZCHAN(5805,161, 0) ,
218 HDD5GHZCHAN(5825,165, 0) ,
219};
220
221static struct ieee80211_rate g_mode_rates[] =
222{
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530223 HDD_G_MODE_RATETAB(10, 0x1, 0),
224 HDD_G_MODE_RATETAB(20, 0x2, 0),
225 HDD_G_MODE_RATETAB(55, 0x4, 0),
226 HDD_G_MODE_RATETAB(110, 0x8, 0),
227 HDD_G_MODE_RATETAB(60, 0x10, 0),
228 HDD_G_MODE_RATETAB(90, 0x20, 0),
229 HDD_G_MODE_RATETAB(120, 0x40, 0),
230 HDD_G_MODE_RATETAB(180, 0x80, 0),
231 HDD_G_MODE_RATETAB(240, 0x100, 0),
232 HDD_G_MODE_RATETAB(360, 0x200, 0),
233 HDD_G_MODE_RATETAB(480, 0x400, 0),
Jeff Johnson295189b2012-06-20 16:38:30 -0700234 HDD_G_MODE_RATETAB(540, 0x800, 0),
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530235};
Jeff Johnson295189b2012-06-20 16:38:30 -0700236
237static struct ieee80211_rate a_mode_rates[] =
238{
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530239 HDD_G_MODE_RATETAB(60, 0x10, 0),
240 HDD_G_MODE_RATETAB(90, 0x20, 0),
241 HDD_G_MODE_RATETAB(120, 0x40, 0),
242 HDD_G_MODE_RATETAB(180, 0x80, 0),
243 HDD_G_MODE_RATETAB(240, 0x100, 0),
244 HDD_G_MODE_RATETAB(360, 0x200, 0),
245 HDD_G_MODE_RATETAB(480, 0x400, 0),
Jeff Johnson295189b2012-06-20 16:38:30 -0700246 HDD_G_MODE_RATETAB(540, 0x800, 0),
247};
248
249static struct ieee80211_supported_band wlan_hdd_band_2_4_GHZ =
250{
251 .channels = hdd_channels_2_4_GHZ,
252 .n_channels = ARRAY_SIZE(hdd_channels_2_4_GHZ),
253 .band = IEEE80211_BAND_2GHZ,
254 .bitrates = g_mode_rates,
255 .n_bitrates = g_mode_rates_size,
256 .ht_cap.ht_supported = 1,
257 .ht_cap.cap = IEEE80211_HT_CAP_SGI_20
258 | IEEE80211_HT_CAP_GRN_FLD
259 | IEEE80211_HT_CAP_DSSSCCK40
260 | IEEE80211_HT_CAP_LSIG_TXOP_PROT,
261 .ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
262 .ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_16,
263 .ht_cap.mcs.rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
264 .ht_cap.mcs.rx_highest = cpu_to_le16( 72 ),
265 .ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED,
266};
267
Jeff Johnson295189b2012-06-20 16:38:30 -0700268static struct ieee80211_supported_band wlan_hdd_band_p2p_2_4_GHZ =
269{
270 .channels = hdd_social_channels_2_4_GHZ,
271 .n_channels = ARRAY_SIZE(hdd_social_channels_2_4_GHZ),
272 .band = IEEE80211_BAND_2GHZ,
273 .bitrates = g_mode_rates,
274 .n_bitrates = g_mode_rates_size,
275 .ht_cap.ht_supported = 1,
276 .ht_cap.cap = IEEE80211_HT_CAP_SGI_20
277 | IEEE80211_HT_CAP_GRN_FLD
278 | IEEE80211_HT_CAP_DSSSCCK40
279 | IEEE80211_HT_CAP_LSIG_TXOP_PROT,
280 .ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
281 .ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_16,
282 .ht_cap.mcs.rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
283 .ht_cap.mcs.rx_highest = cpu_to_le16( 72 ),
284 .ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED,
285};
Jeff Johnson295189b2012-06-20 16:38:30 -0700286
287static struct ieee80211_supported_band wlan_hdd_band_5_GHZ =
288{
289 .channels = hdd_channels_5_GHZ,
290 .n_channels = ARRAY_SIZE(hdd_channels_5_GHZ),
291 .band = IEEE80211_BAND_5GHZ,
292 .bitrates = a_mode_rates,
293 .n_bitrates = a_mode_rates_size,
294 .ht_cap.ht_supported = 1,
295 .ht_cap.cap = IEEE80211_HT_CAP_SGI_20
296 | IEEE80211_HT_CAP_GRN_FLD
297 | IEEE80211_HT_CAP_DSSSCCK40
298 | IEEE80211_HT_CAP_LSIG_TXOP_PROT
299 | IEEE80211_HT_CAP_SGI_40
300 | IEEE80211_HT_CAP_SUP_WIDTH_20_40,
301 .ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
302 .ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_16,
303 .ht_cap.mcs.rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
304 .ht_cap.mcs.rx_highest = cpu_to_le16( 72 ),
305 .ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED,
306};
307
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530308/* This structure contain information what kind of frame are expected in
Jeff Johnson295189b2012-06-20 16:38:30 -0700309 TX/RX direction for each kind of interface */
310static const struct ieee80211_txrx_stypes
311wlan_hdd_txrx_stypes[NUM_NL80211_IFTYPES] = {
312 [NL80211_IFTYPE_STATION] = {
313 .tx = 0xffff,
314 .rx = BIT(SIR_MAC_MGMT_ACTION) |
315 BIT(SIR_MAC_MGMT_PROBE_REQ),
316 },
317 [NL80211_IFTYPE_AP] = {
318 .tx = 0xffff,
319 .rx = BIT(SIR_MAC_MGMT_ASSOC_REQ) |
320 BIT(SIR_MAC_MGMT_REASSOC_REQ) |
321 BIT(SIR_MAC_MGMT_PROBE_REQ) |
322 BIT(SIR_MAC_MGMT_DISASSOC) |
323 BIT(SIR_MAC_MGMT_AUTH) |
324 BIT(SIR_MAC_MGMT_DEAUTH) |
325 BIT(SIR_MAC_MGMT_ACTION),
326 },
Jeff Johnsonbc006202013-04-29 14:05:30 -0700327 [NL80211_IFTYPE_ADHOC] = {
328 .tx = 0xffff,
329 .rx = BIT(SIR_MAC_MGMT_ASSOC_REQ) |
330 BIT(SIR_MAC_MGMT_REASSOC_REQ) |
331 BIT(SIR_MAC_MGMT_PROBE_REQ) |
332 BIT(SIR_MAC_MGMT_DISASSOC) |
333 BIT(SIR_MAC_MGMT_AUTH) |
334 BIT(SIR_MAC_MGMT_DEAUTH) |
335 BIT(SIR_MAC_MGMT_ACTION),
336 },
Jeff Johnson295189b2012-06-20 16:38:30 -0700337 [NL80211_IFTYPE_P2P_CLIENT] = {
338 .tx = 0xffff,
339 .rx = BIT(SIR_MAC_MGMT_ACTION) |
340 BIT(SIR_MAC_MGMT_PROBE_REQ),
341 },
342 [NL80211_IFTYPE_P2P_GO] = {
343 /* This is also same as for SoftAP */
344 .tx = 0xffff,
345 .rx = BIT(SIR_MAC_MGMT_ASSOC_REQ) |
346 BIT(SIR_MAC_MGMT_REASSOC_REQ) |
347 BIT(SIR_MAC_MGMT_PROBE_REQ) |
348 BIT(SIR_MAC_MGMT_DISASSOC) |
349 BIT(SIR_MAC_MGMT_AUTH) |
350 BIT(SIR_MAC_MGMT_DEAUTH) |
351 BIT(SIR_MAC_MGMT_ACTION),
352 },
Jeff Johnson295189b2012-06-20 16:38:30 -0700353};
354
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800355#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800356static const struct ieee80211_iface_limit
357wlan_hdd_iface_limit[] = {
358 {
Sunil Ravia72c3992013-01-31 06:12:22 -0800359 /* max = 3 ; Our driver create two interfaces during driver init
360 * wlan0 and p2p0 interfaces. p2p0 is considered as station
361 * interface until a group is formed. In JB architecture, once the
362 * group is formed, interface type of p2p0 is changed to P2P GO or
363 * Client.
364 * When supplicant remove the group, it first issue a set interface
365 * cmd to change the mode back to Station. In JB this works fine as
366 * we advertize two station type interface during driver init.
367 * Some vendors create separate interface for P2P GO/Client,
368 * after group formation(Third one). But while group remove
369 * supplicant first tries to change the mode(3rd interface) to STATION
370 * But as we advertized only two sta type interfaces nl80211 was
371 * returning error for the third one which was leading to failure in
372 * delete interface. Ideally while removing the group, supplicant
373 * should not try to change the 3rd interface mode to Station type.
374 * Till we get a fix in wpa_supplicant, we advertize max STA
375 * interface type to 3
376 */
377 .max = 3,
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800378 .types = BIT(NL80211_IFTYPE_STATION),
379 },
380 {
381 .max = 1,
Jeff Johnsonbc006202013-04-29 14:05:30 -0700382 .types = BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_AP),
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800383 },
384 {
385 .max = 1,
386 .types = BIT(NL80211_IFTYPE_P2P_GO) |
387 BIT(NL80211_IFTYPE_P2P_CLIENT),
388 },
389};
390
391/* By default, only single channel concurrency is allowed */
392static struct ieee80211_iface_combination
393wlan_hdd_iface_combination = {
394 .limits = wlan_hdd_iface_limit,
395 .num_different_channels = 1,
Sunil Ravia72c3992013-01-31 06:12:22 -0800396 /*
397 * max = WLAN_MAX_INTERFACES ; JellyBean architecture creates wlan0
398 * and p2p0 interfaces during driver init
399 * Some vendors create separate interface for P2P operations.
400 * wlan0: STA interface
401 * p2p0: P2P Device interface, action frames goes
402 * through this interface.
403 * p2p-xx: P2P interface, After GO negotiation this interface is
404 * created for p2p operations(GO/CLIENT interface).
405 */
406 .max_interfaces = WLAN_MAX_INTERFACES,
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800407 .n_limits = ARRAY_SIZE(wlan_hdd_iface_limit),
408 .beacon_int_infra_match = false,
409};
410#endif
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800411
Jeff Johnson295189b2012-06-20 16:38:30 -0700412static struct cfg80211_ops wlan_hdd_cfg80211_ops;
413
414/* Data rate 100KBPS based on IE Index */
415struct index_data_rate_type
416{
417 v_U8_t beacon_rate_index;
418 v_U16_t supported_rate[4];
419};
420
421/* 11B, 11G Rate table include Basic rate and Extended rate
422 The IDX field is the rate index
423 The HI field is the rate when RSSI is strong or being ignored
424 (in this case we report actual rate)
425 The MID field is the rate when RSSI is moderate
426 (in this case we cap 11b rates at 5.5 and 11g rates at 24)
427 The LO field is the rate when RSSI is low
428 (in this case we don't report rates, actual current rate used)
429 */
430static const struct
431{
432 v_U8_t beacon_rate_index;
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -0700433 v_U16_t supported_rate[4];
Jeff Johnson295189b2012-06-20 16:38:30 -0700434} supported_data_rate[] =
435{
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -0700436/* IDX HI HM LM LO (RSSI-based index */
437 {2, { 10, 10, 10, 0}},
438 {4, { 20, 20, 10, 0}},
439 {11, { 55, 20, 10, 0}},
440 {12, { 60, 55, 20, 0}},
441 {18, { 90, 55, 20, 0}},
442 {22, {110, 55, 20, 0}},
443 {24, {120, 90, 60, 0}},
444 {36, {180, 120, 60, 0}},
445 {44, {220, 180, 60, 0}},
446 {48, {240, 180, 90, 0}},
447 {66, {330, 180, 90, 0}},
448 {72, {360, 240, 90, 0}},
449 {96, {480, 240, 120, 0}},
450 {108, {540, 240, 120, 0}}
Jeff Johnson295189b2012-06-20 16:38:30 -0700451};
452
453/* MCS Based rate table */
454static struct index_data_rate_type supported_mcs_rate[] =
455{
456/* MCS L20 L40 S20 S40 */
457 {0, {65, 135, 72, 150}},
458 {1, {130, 270, 144, 300}},
459 {2, {195, 405, 217, 450}},
460 {3, {260, 540, 289, 600}},
461 {4, {390, 810, 433, 900}},
462 {5, {520, 1080, 578, 1200}},
463 {6, {585, 1215, 650, 1350}},
464 {7, {650, 1350, 722, 1500}}
465};
466
Leo Chang6f8870f2013-03-26 18:11:36 -0700467#ifdef WLAN_FEATURE_11AC
468
Gopichand Nakkala4c705372013-04-24 13:20:33 +0530469#define DATA_RATE_11AC_MCS_MASK 0x03
Leo Chang6f8870f2013-03-26 18:11:36 -0700470
471struct index_vht_data_rate_type
472{
473 v_U8_t beacon_rate_index;
Gopichand Nakkala4c705372013-04-24 13:20:33 +0530474 v_U16_t supported_VHT80_rate[2];
475 v_U16_t supported_VHT40_rate[2];
476 v_U16_t supported_VHT20_rate[2];
Leo Chang6f8870f2013-03-26 18:11:36 -0700477};
478
479typedef enum
480{
481 DATA_RATE_11AC_MAX_MCS_7,
482 DATA_RATE_11AC_MAX_MCS_8,
483 DATA_RATE_11AC_MAX_MCS_9,
484 DATA_RATE_11AC_MAX_MCS_NA
485} eDataRate11ACMaxMcs;
486
487/* MCS Based VHT rate table */
488static struct index_vht_data_rate_type supported_vht_mcs_rate[] =
489{
Gopichand Nakkala4c705372013-04-24 13:20:33 +0530490/* MCS L80 S80 L40 S40 L20 S40*/
491 {0, {293, 325}, {135, 150}, {65, 72}},
492 {1, {585, 650}, {270, 300}, {130, 144}},
493 {2, {878, 975}, {405, 450}, {195, 217}},
494 {3, {1170, 1300}, {540, 600}, {260, 289}},
495 {4, {1755, 1950}, {810, 900}, {390, 433}},
496 {5, {2340, 2600}, {1080, 1200}, {520, 578}},
497 {6, {2633, 2925}, {1215, 1350}, {585, 650}},
498 {7, {2925, 3250}, {1350, 1500}, {650, 722}},
499 {8, {3510, 3900}, {1620, 1800}, {780, 867}},
500 {9, {3900, 4333}, {1800, 2000}, {780, 867}}
Leo Chang6f8870f2013-03-26 18:11:36 -0700501};
502#endif /* WLAN_FEATURE_11AC */
503
Jeff Johnson295189b2012-06-20 16:38:30 -0700504extern struct net_device_ops net_ops_struct;
505
Leo Chang9056f462013-08-01 19:21:11 -0700506#ifdef WLAN_NL80211_TESTMODE
507enum wlan_hdd_tm_attr
508{
509 WLAN_HDD_TM_ATTR_INVALID = 0,
510 WLAN_HDD_TM_ATTR_CMD = 1,
511 WLAN_HDD_TM_ATTR_DATA = 2,
512 WLAN_HDD_TM_ATTR_TYPE = 3,
513 /* keep last */
514 WLAN_HDD_TM_ATTR_AFTER_LAST,
515 WLAN_HDD_TM_ATTR_MAX = WLAN_HDD_TM_ATTR_AFTER_LAST - 1,
516};
517
518enum wlan_hdd_tm_cmd
519{
520 WLAN_HDD_TM_CMD_WLAN_HB = 1,
521};
522
523#define WLAN_HDD_TM_DATA_MAX_LEN 5000
524
525static const struct nla_policy wlan_hdd_tm_policy[WLAN_HDD_TM_ATTR_MAX + 1] =
526{
527 [WLAN_HDD_TM_ATTR_CMD] = { .type = NLA_U32 },
528 [WLAN_HDD_TM_ATTR_DATA] = { .type = NLA_BINARY,
529 .len = WLAN_HDD_TM_DATA_MAX_LEN },
530};
531#endif /* WLAN_NL80211_TESTMODE */
532
Jeff Johnson295189b2012-06-20 16:38:30 -0700533/*
534 * FUNCTION: wlan_hdd_cfg80211_init
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530535 * This function is called by hdd_wlan_startup()
536 * during initialization.
Jeff Johnson295189b2012-06-20 16:38:30 -0700537 * This function is used to initialize and register wiphy structure.
538 */
539struct wiphy *wlan_hdd_cfg80211_init(int priv_size)
540{
541 struct wiphy *wiphy;
542 ENTER();
543
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530544 /*
545 * Create wiphy device
Jeff Johnson295189b2012-06-20 16:38:30 -0700546 */
547 wiphy = wiphy_new(&wlan_hdd_cfg80211_ops, priv_size);
548
549 if (!wiphy)
550 {
551 /* Print error and jump into err label and free the memory */
552 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: wiphy init failed", __func__);
553 return NULL;
554 }
555
556 return wiphy;
557}
558
559/*
560 * FUNCTION: wlan_hdd_cfg80211_update_band
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530561 * This function is called from the supplicant through a
Jeff Johnson295189b2012-06-20 16:38:30 -0700562 * private ioctl to change the band value
563 */
564int wlan_hdd_cfg80211_update_band(struct wiphy *wiphy, eCsrBand eBand)
565{
Gopichand Nakkala1f7a64f2013-04-01 18:37:17 +0530566 int i, j;
567 eNVChannelEnabledType channelEnabledState;
568
Jeff Johnsone7245742012-09-05 17:12:55 -0700569 ENTER();
Gopichand Nakkala1f7a64f2013-04-01 18:37:17 +0530570 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Jeff Johnson295189b2012-06-20 16:38:30 -0700571 {
Gopichand Nakkala1f7a64f2013-04-01 18:37:17 +0530572
573 if (NULL == wiphy->bands[i])
574 {
575 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy->bands[i] is NULL, i = %d",
576 __func__, i);
577 continue;
578 }
579
580 for (j = 0; j < wiphy->bands[i]->n_channels; j++)
581 {
582 struct ieee80211_supported_band *band = wiphy->bands[i];
583
584 channelEnabledState = vos_nv_getChannelEnabledState(
585 band->channels[j].hw_value);
586
587 if (IEEE80211_BAND_2GHZ == i && eCSR_BAND_5G == eBand) // 5G only
588 {
589 // Enable Social channels for P2P
590 if (WLAN_HDD_IS_SOCIAL_CHANNEL(band->channels[j].center_freq) &&
591 NV_CHANNEL_ENABLE == channelEnabledState)
592 band->channels[j].flags &= ~IEEE80211_CHAN_DISABLED;
593 else
594 band->channels[j].flags |= IEEE80211_CHAN_DISABLED;
595 continue;
596 }
597 else if (IEEE80211_BAND_5GHZ == i && eCSR_BAND_24 == eBand) // 2G only
598 {
599 band->channels[j].flags |= IEEE80211_CHAN_DISABLED;
600 continue;
601 }
602
603 if (NV_CHANNEL_DISABLE == channelEnabledState ||
604 NV_CHANNEL_INVALID == channelEnabledState)
605 {
606 band->channels[j].flags |= IEEE80211_CHAN_DISABLED;
607 }
608 else if (NV_CHANNEL_DFS == channelEnabledState)
609 {
610 band->channels[j].flags &= ~IEEE80211_CHAN_DISABLED;
611 band->channels[j].flags |= IEEE80211_CHAN_RADAR;
612 }
613 else
614 {
615 band->channels[j].flags &= ~(IEEE80211_CHAN_DISABLED
616 |IEEE80211_CHAN_RADAR);
617 }
618 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700619 }
620 return 0;
621}
622/*
623 * FUNCTION: wlan_hdd_cfg80211_init
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530624 * This function is called by hdd_wlan_startup()
625 * during initialization.
Jeff Johnson295189b2012-06-20 16:38:30 -0700626 * This function is used to initialize and register wiphy structure.
627 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530628int wlan_hdd_cfg80211_register(struct device *dev,
Jeff Johnson295189b2012-06-20 16:38:30 -0700629 struct wiphy *wiphy,
630 hdd_config_t *pCfg
631 )
632{
Gopichand Nakkala1f7a64f2013-04-01 18:37:17 +0530633
634 int i, j;
635
Jeff Johnsone7245742012-09-05 17:12:55 -0700636 ENTER();
637
Jeff Johnson295189b2012-06-20 16:38:30 -0700638 /* Now bind the underlying wlan device with wiphy */
639 set_wiphy_dev(wiphy, dev);
640
641 wiphy->mgmt_stypes = wlan_hdd_txrx_stypes;
642
Madan Mohan Koyyalamudi1b4afb02012-10-22 15:25:16 -0700643 wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY;
Jeff Johnson295189b2012-06-20 16:38:30 -0700644
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700645#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
Madan Mohan Koyyalamudi1b4afb02012-10-22 15:25:16 -0700646 wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME
647 | WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
648 | WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
Jeff Johnsone7245742012-09-05 17:12:55 -0700649 | WIPHY_FLAG_OFFCHAN_TX;
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700650#endif
Srinivas Girigowda640728a2013-03-28 12:21:54 -0700651#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_CCX) || defined(FEATURE_WLAN_LFR)
652 if (pCfg->isFastTransitionEnabled
James Zmuda77fb5ae2013-01-29 08:00:17 -0800653#ifdef FEATURE_WLAN_LFR
Srinivas Girigowda640728a2013-03-28 12:21:54 -0700654 || pCfg->isFastRoamIniFeatureEnabled
655#endif
656#ifdef FEATURE_WLAN_CCX
657 || pCfg->isCcxIniFeatureEnabled
658#endif
659 )
660 {
661 wiphy->flags |= WIPHY_FLAG_SUPPORTS_FW_ROAM;
662 }
James Zmuda77fb5ae2013-01-29 08:00:17 -0800663#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -0800664#ifdef FEATURE_WLAN_TDLS
665 wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS
666 | WIPHY_FLAG_TDLS_EXTERNAL_SETUP;
667#endif
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +0530668#ifdef FEATURE_WLAN_SCAN_PNO
669 wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
670 wiphy->max_sched_scan_ssids = MAX_SCAN_SSID;
671 wiphy->max_match_sets = SIR_PNO_MAX_SUPP_NETWORKS;
672#endif/*FEATURE_WLAN_SCAN_PNO*/
Mohit Khanna698ba2a2012-12-04 15:08:18 -0800673
Madan Mohan Koyyalamudic3a240c2012-09-28 15:34:08 -0700674 /* even with WIPHY_FLAG_CUSTOM_REGULATORY,
675 driver can still register regulatory callback and
676 it will get CRDA setting in wiphy->band[], but
677 driver need to determine what to do with both
678 regulatory settings */
679 wiphy->reg_notifier = wlan_hdd_crda_reg_notifier;
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700680
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530681 wiphy->max_scan_ssids = MAX_SCAN_SSID;
682
Madan Mohan Koyyalamudi6815b162013-07-19 17:17:46 +0530683 wiphy->max_scan_ie_len = SIR_MAC_MAX_IE_LENGTH;
Jeff Johnson295189b2012-06-20 16:38:30 -0700684
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +0530685 wiphy->max_acl_mac_addrs = MAX_ACL_MAC_ADDRESS;
686
Jeff Johnson295189b2012-06-20 16:38:30 -0700687 /* Supports STATION & AD-HOC modes right now */
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530688 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION)
Jeff Johnson295189b2012-06-20 16:38:30 -0700689 | BIT(NL80211_IFTYPE_ADHOC)
Jeff Johnson295189b2012-06-20 16:38:30 -0700690 | BIT(NL80211_IFTYPE_P2P_CLIENT)
691 | BIT(NL80211_IFTYPE_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -0700692 | BIT(NL80211_IFTYPE_AP);
693
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800694#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800695 if( pCfg->enableMCC )
696 {
697 /* Currently, supports up to two channels */
698 wlan_hdd_iface_combination.num_different_channels = 2;
699
700 if( !pCfg->allowMCCGODiffBI )
701 wlan_hdd_iface_combination.beacon_int_infra_match = true;
702
703 }
704 wiphy->iface_combinations = &wlan_hdd_iface_combination;
705 wiphy->n_iface_combinations = 1;
706#endif
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800707
Jeff Johnson295189b2012-06-20 16:38:30 -0700708 /* Before registering we need to update the ht capabilitied based
709 * on ini values*/
710 if( !pCfg->ShortGI20MhzEnable )
711 {
712 wlan_hdd_band_2_4_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_20;
713 wlan_hdd_band_5_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_20;
714 wlan_hdd_band_p2p_2_4_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_20;
715 }
716
717 if( !pCfg->ShortGI40MhzEnable )
718 {
719 wlan_hdd_band_5_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_40;
720 }
721
722 if( !pCfg->nChannelBondingMode5GHz )
723 {
724 wlan_hdd_band_5_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
725 }
726
Gopichand Nakkala1f7a64f2013-04-01 18:37:17 +0530727 wiphy->bands[IEEE80211_BAND_2GHZ] = &wlan_hdd_band_2_4_GHZ;
728 wiphy->bands[IEEE80211_BAND_5GHZ] = &wlan_hdd_band_5_GHZ;
729
730 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
731 {
732
733 if (NULL == wiphy->bands[i])
734 {
735 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy->bands[i] is NULL, i = %d",
736 __func__, i);
737 continue;
738 }
739
740 for (j = 0; j < wiphy->bands[i]->n_channels; j++)
741 {
742 struct ieee80211_supported_band *band = wiphy->bands[i];
743
744 if (IEEE80211_BAND_2GHZ == i && eCSR_BAND_5G == pCfg->nBandCapability) // 5G only
745 {
746 // Enable social channels for P2P
747 if (WLAN_HDD_IS_SOCIAL_CHANNEL(band->channels[j].center_freq))
748 band->channels[j].flags &= ~IEEE80211_CHAN_DISABLED;
749 else
750 band->channels[j].flags |= IEEE80211_CHAN_DISABLED;
751 continue;
752 }
753 else if (IEEE80211_BAND_5GHZ == i && eCSR_BAND_24 == pCfg->nBandCapability) // 2G only
754 {
755 band->channels[j].flags |= IEEE80211_CHAN_DISABLED;
756 continue;
757 }
758 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700759 }
760 /*Initialise the supported cipher suite details*/
761 wiphy->cipher_suites = hdd_cipher_suites;
762 wiphy->n_cipher_suites = ARRAY_SIZE(hdd_cipher_suites);
763
764 /*signal strength in mBm (100*dBm) */
765 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
766
767#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
Jeff Johnson295189b2012-06-20 16:38:30 -0700768 wiphy->max_remain_on_channel_duration = 1000;
769#endif
Jeff Johnson295189b2012-06-20 16:38:30 -0700770
771 /* Register our wiphy dev with cfg80211 */
772 if (0 > wiphy_register(wiphy))
773 {
774 /* print eror */
775 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy register failed", __func__);
776 return -EIO;
777 }
778
779 EXIT();
780 return 0;
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530781}
Jeff Johnson295189b2012-06-20 16:38:30 -0700782
Madan Mohan Koyyalamudic3a240c2012-09-28 15:34:08 -0700783/* In this function we will try to get default country code from crda.
784 If the gCrdaDefaultCountryCode is configured in ini file,
785 we will try to call user space crda to get the regulatory settings for
786 that country. We will timeout if we can't get it from crda.
787 It's called by hdd_wlan_startup() after wlan_hdd_cfg80211_register.
788*/
789int wlan_hdd_get_crda_regd_entry(struct wiphy *wiphy, hdd_config_t *pCfg)
790{
791 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
792 if (memcmp(pCfg->crdaDefaultCountryCode,
793 CFG_CRDA_DEFAULT_COUNTRY_CODE_DEFAULT , 2) != 0)
794 {
795 init_completion(&pHddCtx->driver_crda_req);
796 regulatory_hint(wiphy, pCfg->crdaDefaultCountryCode);
797 wait_for_completion_interruptible_timeout(&pHddCtx->driver_crda_req,
798 CRDA_WAIT_TIME);
Yunsen Wange3ba1fb2013-04-05 15:04:43 -0700799 /* if the country is not found from current regulatory.bin,
800 fall back to world domain */
801 if (is_crda_regulatory_entry_valid() == VOS_FALSE)
802 crda_regulatory_entry_default(pCfg->crdaDefaultCountryCode, NUM_REG_DOMAINS-1);
Madan Mohan Koyyalamudic3a240c2012-09-28 15:34:08 -0700803 }
804 return 0;
805}
806
Jeff Johnson295189b2012-06-20 16:38:30 -0700807/* In this function we will do all post VOS start initialization.
808 In this function we will register for all frame in which supplicant
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530809 is interested.
Jeff Johnson295189b2012-06-20 16:38:30 -0700810*/
811void wlan_hdd_cfg80211_post_voss_start(hdd_adapter_t* pAdapter)
812{
Jeff Johnson295189b2012-06-20 16:38:30 -0700813 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
814 /* Register for all P2P action, public action etc frames */
815 v_U16_t type = (SIR_MAC_MGMT_FRAME << 2) | ( SIR_MAC_MGMT_ACTION << 4);
816
Jeff Johnsone7245742012-09-05 17:12:55 -0700817 ENTER();
818
Jeff Johnson295189b2012-06-20 16:38:30 -0700819 /* Right now we are registering these frame when driver is getting
820 initialized. Once we will move to 2.6.37 kernel, in which we have
821 frame register ops, we will move this code as a part of that */
822 /* GAS Initial Request */
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530823 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
Jeff Johnson295189b2012-06-20 16:38:30 -0700824 (v_U8_t*)GAS_INITIAL_REQ, GAS_INITIAL_REQ_SIZE );
825
826 /* GAS Initial Response */
827 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
828 (v_U8_t*)GAS_INITIAL_RSP, GAS_INITIAL_RSP_SIZE );
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530829
Jeff Johnson295189b2012-06-20 16:38:30 -0700830 /* GAS Comeback Request */
831 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
832 (v_U8_t*)GAS_COMEBACK_REQ, GAS_COMEBACK_REQ_SIZE );
833
834 /* GAS Comeback Response */
835 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
836 (v_U8_t*)GAS_COMEBACK_RSP, GAS_COMEBACK_RSP_SIZE );
837
838 /* P2P Public Action */
839 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530840 (v_U8_t*)P2P_PUBLIC_ACTION_FRAME,
Jeff Johnson295189b2012-06-20 16:38:30 -0700841 P2P_PUBLIC_ACTION_FRAME_SIZE );
842
843 /* P2P Action */
844 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
845 (v_U8_t*)P2P_ACTION_FRAME,
846 P2P_ACTION_FRAME_SIZE );
Chet Lanctot186b5732013-03-18 10:26:30 -0700847
Gopichand Nakkalae3d56e72013-04-21 23:33:32 +0530848 /* WNM BSS Transition Request frame */
849 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
850 (v_U8_t*)WNM_BSS_ACTION_FRAME,
851 WNM_BSS_ACTION_FRAME_SIZE );
852
Chet Lanctot186b5732013-03-18 10:26:30 -0700853#ifdef WLAN_FEATURE_11W
854 /* SA Query Response Action Frame */
855 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
856 (v_U8_t*)SA_QUERY_FRAME_RSP,
857 SA_QUERY_FRAME_RSP_SIZE );
858#endif /* WLAN_FEATURE_11W */
Jeff Johnson295189b2012-06-20 16:38:30 -0700859}
860
861void wlan_hdd_cfg80211_pre_voss_stop(hdd_adapter_t* pAdapter)
862{
Jeff Johnson295189b2012-06-20 16:38:30 -0700863 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
864 /* Register for all P2P action, public action etc frames */
865 v_U16_t type = (SIR_MAC_MGMT_FRAME << 2) | ( SIR_MAC_MGMT_ACTION << 4);
866
Jeff Johnsone7245742012-09-05 17:12:55 -0700867 ENTER();
868
Jeff Johnson295189b2012-06-20 16:38:30 -0700869 /* Right now we are registering these frame when driver is getting
870 initialized. Once we will move to 2.6.37 kernel, in which we have
871 frame register ops, we will move this code as a part of that */
872 /* GAS Initial Request */
873
874 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
875 (v_U8_t*)GAS_INITIAL_REQ, GAS_INITIAL_REQ_SIZE );
876
877 /* GAS Initial Response */
878 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
879 (v_U8_t*)GAS_INITIAL_RSP, GAS_INITIAL_RSP_SIZE );
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530880
Jeff Johnson295189b2012-06-20 16:38:30 -0700881 /* GAS Comeback Request */
882 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
883 (v_U8_t*)GAS_COMEBACK_REQ, GAS_COMEBACK_REQ_SIZE );
884
885 /* GAS Comeback Response */
886 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
887 (v_U8_t*)GAS_COMEBACK_RSP, GAS_COMEBACK_RSP_SIZE );
888
889 /* P2P Public Action */
890 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530891 (v_U8_t*)P2P_PUBLIC_ACTION_FRAME,
Jeff Johnson295189b2012-06-20 16:38:30 -0700892 P2P_PUBLIC_ACTION_FRAME_SIZE );
893
894 /* P2P Action */
895 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
896 (v_U8_t*)P2P_ACTION_FRAME,
897 P2P_ACTION_FRAME_SIZE );
Chet Lanctot186b5732013-03-18 10:26:30 -0700898
899#ifdef WLAN_FEATURE_11W
900 /* SA Query Response Action Frame */
901 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
902 (v_U8_t*)SA_QUERY_FRAME_RSP,
903 SA_QUERY_FRAME_RSP_SIZE );
904#endif /* WLAN_FEATURE_11W */
Jeff Johnson295189b2012-06-20 16:38:30 -0700905}
906
907#ifdef FEATURE_WLAN_WAPI
908void wlan_hdd_cfg80211_set_key_wapi(hdd_adapter_t* pAdapter, u8 key_index,
909 const u8 *mac_addr, u8 *key , int key_Len)
910{
911 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
912 tCsrRoamSetKey setKey;
913 v_BOOL_t isConnected = TRUE;
914 int status = 0;
915 v_U32_t roamId= 0xFF;
916 tANI_U8 *pKeyPtr = NULL;
917 int n = 0;
918
919 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
920 __func__,pAdapter->device_mode);
921
Gopichand Nakkalae7480202013-02-11 15:24:22 +0530922 vos_mem_zero(&setKey, sizeof(tCsrRoamSetKey));
Jeff Johnson295189b2012-06-20 16:38:30 -0700923 setKey.keyId = key_index; // Store Key ID
924 setKey.encType = eCSR_ENCRYPT_TYPE_WPI; // SET WAPI Encryption
925 setKey.keyDirection = eSIR_TX_RX; // Key Directionn both TX and RX
926 setKey.paeRole = 0 ; // the PAE role
927 if (!mac_addr || is_broadcast_ether_addr(mac_addr))
928 {
929 vos_set_macaddr_broadcast( (v_MACADDR_t *)setKey.peerMac );
930 }
931 else
932 {
933 isConnected = hdd_connIsConnected(pHddStaCtx);
934 vos_mem_copy(setKey.peerMac,&pHddStaCtx->conn_info.bssId,WNI_CFG_BSSID_LEN);
935 }
936 setKey.keyLength = key_Len;
937 pKeyPtr = setKey.Key;
938 memcpy( pKeyPtr, key, key_Len);
939
940 hddLog(VOS_TRACE_LEVEL_INFO,"\n%s: WAPI KEY LENGTH:0x%04x",
941 __func__, key_Len);
942 for (n = 0 ; n < key_Len; n++)
943 hddLog(VOS_TRACE_LEVEL_INFO, "%s WAPI KEY Data[%d]:%02x ",
944 __func__,n,setKey.Key[n]);
945
946 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_SETTING_KEY;
947 if ( isConnected )
948 {
949 status= sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
950 pAdapter->sessionId, &setKey, &roamId );
951 }
952 if ( status != 0 )
953 {
954 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
955 "[%4d] sme_RoamSetKey returned ERROR status= %d",
956 __LINE__, status );
957 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
958 }
959}
960#endif /* FEATURE_WLAN_WAPI*/
961
962#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530963int wlan_hdd_cfg80211_alloc_new_beacon(hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -0700964 beacon_data_t **ppBeacon,
965 struct beacon_parameters *params)
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700966#else
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530967int wlan_hdd_cfg80211_alloc_new_beacon(hdd_adapter_t *pAdapter,
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700968 beacon_data_t **ppBeacon,
969 struct cfg80211_beacon_data *params,
970 int dtim_period)
971#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530972{
Jeff Johnson295189b2012-06-20 16:38:30 -0700973 int size;
974 beacon_data_t *beacon = NULL;
975 beacon_data_t *old = NULL;
976 int head_len,tail_len;
977
Jeff Johnsone7245742012-09-05 17:12:55 -0700978 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -0700979 if (params->head && !params->head_len)
980 return -EINVAL;
981
982 old = pAdapter->sessionCtx.ap.beacon;
983
984 if (!params->head && !old)
985 return -EINVAL;
986
987 if (params->tail && !params->tail_len)
988 return -EINVAL;
989
990#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,38))
991 /* Kernel 3.0 is not updating dtim_period for set beacon */
992 if (!params->dtim_period)
993 return -EINVAL;
994#endif
995
996 if(params->head)
997 head_len = params->head_len;
998 else
999 head_len = old->head_len;
1000
1001 if(params->tail || !old)
1002 tail_len = params->tail_len;
1003 else
1004 tail_len = old->tail_len;
1005
1006 size = sizeof(beacon_data_t) + head_len + tail_len;
1007
1008 beacon = kzalloc(size, GFP_KERNEL);
1009
1010 if( beacon == NULL )
1011 return -ENOMEM;
1012
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001013#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07001014 if(params->dtim_period || !old )
1015 beacon->dtim_period = params->dtim_period;
1016 else
1017 beacon->dtim_period = old->dtim_period;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001018#else
1019 if(dtim_period || !old )
1020 beacon->dtim_period = dtim_period;
1021 else
1022 beacon->dtim_period = old->dtim_period;
1023#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301024
Jeff Johnson295189b2012-06-20 16:38:30 -07001025 beacon->head = ((u8 *) beacon) + sizeof(beacon_data_t);
1026 beacon->tail = beacon->head + head_len;
1027 beacon->head_len = head_len;
1028 beacon->tail_len = tail_len;
1029
1030 if(params->head) {
1031 memcpy (beacon->head,params->head,beacon->head_len);
1032 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301033 else {
Jeff Johnson295189b2012-06-20 16:38:30 -07001034 if(old)
1035 memcpy (beacon->head,old->head,beacon->head_len);
1036 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301037
Jeff Johnson295189b2012-06-20 16:38:30 -07001038 if(params->tail) {
1039 memcpy (beacon->tail,params->tail,beacon->tail_len);
1040 }
1041 else {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301042 if(old)
Jeff Johnson295189b2012-06-20 16:38:30 -07001043 memcpy (beacon->tail,old->tail,beacon->tail_len);
1044 }
1045
1046 *ppBeacon = beacon;
1047
1048 kfree(old);
1049
1050 return 0;
1051
1052}
Jeff Johnson295189b2012-06-20 16:38:30 -07001053
1054v_U8_t* wlan_hdd_cfg80211_get_ie_ptr(v_U8_t *pIes, int length, v_U8_t eid)
1055{
1056 int left = length;
1057 v_U8_t *ptr = pIes;
1058 v_U8_t elem_id,elem_len;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301059
Jeff Johnson295189b2012-06-20 16:38:30 -07001060 while(left >= 2)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301061 {
Jeff Johnson295189b2012-06-20 16:38:30 -07001062 elem_id = ptr[0];
1063 elem_len = ptr[1];
1064 left -= 2;
1065 if(elem_len > left)
1066 {
1067 hddLog(VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi8bdd3112012-09-24 13:55:14 -07001068 FL("****Invalid IEs eid = %d elem_len=%d left=%d*****"),
Jeff Johnson295189b2012-06-20 16:38:30 -07001069 eid,elem_len,left);
1070 return NULL;
1071 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301072 if (elem_id == eid)
Jeff Johnson295189b2012-06-20 16:38:30 -07001073 {
1074 return ptr;
1075 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301076
Jeff Johnson295189b2012-06-20 16:38:30 -07001077 left -= elem_len;
1078 ptr += (elem_len + 2);
1079 }
1080 return NULL;
1081}
1082
Jeff Johnson295189b2012-06-20 16:38:30 -07001083/* Check if rate is 11g rate or not */
1084static int wlan_hdd_rate_is_11g(u8 rate)
1085{
Sanjay Devnani28322e22013-06-21 16:13:40 -07001086 static const u8 gRateArray[8] = {12, 18, 24, 36, 48, 72, 96, 108}; /* actual rate * 2 */
Jeff Johnson295189b2012-06-20 16:38:30 -07001087 u8 i;
1088 for (i = 0; i < 8; i++)
1089 {
1090 if(rate == gRateArray[i])
1091 return TRUE;
1092 }
1093 return FALSE;
1094}
1095
1096/* Check for 11g rate and set proper 11g only mode */
1097static void wlan_hdd_check_11gmode(u8 *pIe, u8* require_ht,
1098 u8* pCheckRatesfor11g, eSapPhyMode* pSapHw_mode)
1099{
1100 u8 i, num_rates = pIe[0];
1101
1102 pIe += 1;
1103 for ( i = 0; i < num_rates; i++)
1104 {
1105 if( *pCheckRatesfor11g && (TRUE == wlan_hdd_rate_is_11g(pIe[i] & RATE_MASK)))
1106 {
1107 /* If rate set have 11g rate than change the mode to 11G */
1108 *pSapHw_mode = eSAP_DOT11_MODE_11g;
1109 if (pIe[i] & BASIC_RATE_MASK)
1110 {
1111 /* If we have 11g rate as basic rate, it means mode
1112 is 11g only mode.
1113 */
1114 *pSapHw_mode = eSAP_DOT11_MODE_11g_ONLY;
1115 *pCheckRatesfor11g = FALSE;
1116 }
1117 }
1118 else if((BASIC_RATE_MASK | WLAN_BSS_MEMBERSHIP_SELECTOR_HT_PHY) == pIe[i])
1119 {
1120 *require_ht = TRUE;
1121 }
1122 }
1123 return;
1124}
1125
1126static void wlan_hdd_set_sapHwmode(hdd_adapter_t *pHostapdAdapter)
1127{
1128 tsap_Config_t *pConfig = &pHostapdAdapter->sessionCtx.ap.sapConfig;
1129 beacon_data_t *pBeacon = pHostapdAdapter->sessionCtx.ap.beacon;
1130 struct ieee80211_mgmt *pMgmt_frame = (struct ieee80211_mgmt*)pBeacon->head;
1131 u8 checkRatesfor11g = TRUE;
1132 u8 require_ht = FALSE;
1133 u8 *pIe=NULL;
1134
1135 pConfig->SapHw_mode= eSAP_DOT11_MODE_11b;
1136
1137 pIe = wlan_hdd_cfg80211_get_ie_ptr(&pMgmt_frame->u.beacon.variable[0],
1138 pBeacon->head_len, WLAN_EID_SUPP_RATES);
1139 if (pIe != NULL)
1140 {
1141 pIe += 1;
1142 wlan_hdd_check_11gmode(pIe, &require_ht, &checkRatesfor11g,
1143 &pConfig->SapHw_mode);
1144 }
1145
1146 pIe = wlan_hdd_cfg80211_get_ie_ptr(pBeacon->tail, pBeacon->tail_len,
1147 WLAN_EID_EXT_SUPP_RATES);
1148 if (pIe != NULL)
1149 {
1150
1151 pIe += 1;
1152 wlan_hdd_check_11gmode(pIe, &require_ht, &checkRatesfor11g,
1153 &pConfig->SapHw_mode);
1154 }
1155
1156 if( pConfig->channel > 14 )
1157 {
1158 pConfig->SapHw_mode= eSAP_DOT11_MODE_11a;
1159 }
1160
1161 pIe = wlan_hdd_cfg80211_get_ie_ptr(pBeacon->tail, pBeacon->tail_len,
1162 WLAN_EID_HT_CAPABILITY);
1163
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301164 if(pIe)
Jeff Johnson295189b2012-06-20 16:38:30 -07001165 {
1166 pConfig->SapHw_mode= eSAP_DOT11_MODE_11n;
1167 if(require_ht)
1168 pConfig->SapHw_mode= eSAP_DOT11_MODE_11n_ONLY;
1169 }
1170}
1171
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301172static int wlan_hdd_add_ie(hdd_adapter_t* pHostapdAdapter, v_U8_t *genie,
1173 v_U8_t *total_ielen, v_U8_t *oui, v_U8_t oui_size)
1174{
1175 v_U8_t ielen = 0;
1176 v_U8_t *pIe = NULL;
1177 beacon_data_t *pBeacon = pHostapdAdapter->sessionCtx.ap.beacon;
1178
1179 pIe = wlan_hdd_get_vendor_oui_ie_ptr(oui, oui_size,
1180 pBeacon->tail, pBeacon->tail_len);
1181
1182 if (pIe)
1183 {
1184 ielen = pIe[1] + 2;
1185 if ((*total_ielen + ielen) <= MAX_GENIE_LEN)
1186 {
1187 vos_mem_copy(&genie[*total_ielen], pIe, ielen);
1188 }
1189 else
1190 {
1191 hddLog( VOS_TRACE_LEVEL_ERROR, "**Ie Length is too big***");
1192 return -EINVAL;
1193 }
1194 *total_ielen += ielen;
1195 }
1196 return 0;
1197}
1198
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001199#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07001200static int wlan_hdd_cfg80211_update_apies(hdd_adapter_t* pHostapdAdapter,
1201 struct beacon_parameters *params)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001202#else
1203static int wlan_hdd_cfg80211_update_apies(hdd_adapter_t* pHostapdAdapter,
1204 struct cfg80211_beacon_data *params)
1205#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07001206{
1207 v_U8_t *genie;
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301208 v_U8_t total_ielen = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07001209 v_U8_t addIE[1] = {0};
Jeff Johnsone7245742012-09-05 17:12:55 -07001210 int ret = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07001211
1212 genie = vos_mem_malloc(MAX_GENIE_LEN);
1213
1214 if(genie == NULL) {
1215
1216 return -ENOMEM;
1217 }
1218
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301219 if (0 != wlan_hdd_add_ie(pHostapdAdapter, genie,
1220 &total_ielen, WPS_OUI_TYPE, WPS_OUI_TYPE_SIZE))
Jeff Johnson295189b2012-06-20 16:38:30 -07001221 {
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301222 ret = -EINVAL;
1223 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001224 }
1225
1226#ifdef WLAN_FEATURE_WFD
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301227 if (0 != wlan_hdd_add_ie(pHostapdAdapter, genie,
1228 &total_ielen, WFD_OUI_TYPE, WFD_OUI_TYPE_SIZE))
1229 {
1230 ret = -EINVAL;
1231 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001232 }
1233#endif
1234
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301235 if (0 != wlan_hdd_add_ie(pHostapdAdapter, genie,
1236 &total_ielen, P2P_OUI_TYPE, P2P_OUI_TYPE_SIZE))
Jeff Johnson295189b2012-06-20 16:38:30 -07001237 {
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301238 ret = -EINVAL;
1239 goto done;
1240 }
1241
1242 if (WLAN_HDD_SOFTAP == pHostapdAdapter->device_mode)
1243 {
1244 if (0 != wlan_hdd_add_ie(pHostapdAdapter, genie,
1245 &total_ielen, SS_OUI_TYPE, SS_OUI_TYPE_SIZE))
Jeff Johnson295189b2012-06-20 16:38:30 -07001246 {
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301247 ret = -EINVAL;
1248 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001249 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001250 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001251
1252 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1253 WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA, genie, total_ielen, NULL,
1254 eANI_BOOLEAN_FALSE)==eHAL_STATUS_FAILURE)
1255 {
1256 hddLog(LOGE,
1257 "Could not pass on WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001258 ret = -EINVAL;
1259 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001260 }
1261
1262 if (ccmCfgSetInt((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1263 WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG, 1,NULL,
1264 test_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags) ?
1265 eANI_BOOLEAN_TRUE : eANI_BOOLEAN_FALSE)
1266 ==eHAL_STATUS_FAILURE)
1267 {
1268 hddLog(LOGE,
1269 "Could not pass on WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001270 ret = -EINVAL;
1271 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001272 }
1273
1274 // Added for ProResp IE
1275 if ( (params->proberesp_ies != NULL) && (params->proberesp_ies_len != 0) )
1276 {
1277 u16 rem_probe_resp_ie_len = params->proberesp_ies_len;
1278 u8 probe_rsp_ie_len[3] = {0};
1279 u8 counter = 0;
1280 /* Check Probe Resp Length if it is greater then 255 then Store
1281 Probe Resp IEs into WNI_CFG_PROBE_RSP_ADDNIE_DATA1 &
1282 WNI_CFG_PROBE_RSP_ADDNIE_DATA2 CFG Variable As We are not able
1283 Store More then 255 bytes into One Variable.
1284 */
1285 while ((rem_probe_resp_ie_len > 0) && (counter < 3))
1286 {
1287 if (rem_probe_resp_ie_len > MAX_CFG_STRING_LEN)
1288 {
1289 probe_rsp_ie_len[counter++] = MAX_CFG_STRING_LEN;
1290 rem_probe_resp_ie_len -= MAX_CFG_STRING_LEN;
1291 }
1292 else
1293 {
1294 probe_rsp_ie_len[counter++] = rem_probe_resp_ie_len;
1295 rem_probe_resp_ie_len = 0;
1296 }
1297 }
1298
1299 rem_probe_resp_ie_len = 0;
1300
1301 if (probe_rsp_ie_len[0] > 0)
1302 {
1303 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1304 WNI_CFG_PROBE_RSP_ADDNIE_DATA1,
1305 (tANI_U8*)&params->proberesp_ies[rem_probe_resp_ie_len],
1306 probe_rsp_ie_len[0], NULL,
1307 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
1308 {
1309 hddLog(LOGE,
1310 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA1 to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001311 ret = -EINVAL;
1312 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001313 }
1314 rem_probe_resp_ie_len += probe_rsp_ie_len[0];
1315 }
1316
1317 if (probe_rsp_ie_len[1] > 0)
1318 {
1319 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1320 WNI_CFG_PROBE_RSP_ADDNIE_DATA2,
1321 (tANI_U8*)&params->proberesp_ies[rem_probe_resp_ie_len],
1322 probe_rsp_ie_len[1], NULL,
1323 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
1324 {
1325 hddLog(LOGE,
1326 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA2 to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001327 ret = -EINVAL;
1328 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001329 }
1330 rem_probe_resp_ie_len += probe_rsp_ie_len[1];
1331 }
1332
1333 if (probe_rsp_ie_len[2] > 0)
1334 {
1335 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1336 WNI_CFG_PROBE_RSP_ADDNIE_DATA3,
1337 (tANI_U8*)&params->proberesp_ies[rem_probe_resp_ie_len],
1338 probe_rsp_ie_len[2], NULL,
1339 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
1340 {
1341 hddLog(LOGE,
1342 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA3 to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001343 ret = -EINVAL;
1344 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001345 }
1346 rem_probe_resp_ie_len += probe_rsp_ie_len[2];
1347 }
1348
1349 if (probe_rsp_ie_len[1] == 0 )
1350 {
1351 if ( eHAL_STATUS_FAILURE == ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1352 WNI_CFG_PROBE_RSP_ADDNIE_DATA2, (tANI_U8*)addIE, 0, NULL,
1353 eANI_BOOLEAN_FALSE) )
1354 {
1355 hddLog(LOGE,
1356 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA2 to CCM\n");
1357 }
1358 }
1359
1360 if (probe_rsp_ie_len[2] == 0 )
1361 {
1362 if ( eHAL_STATUS_FAILURE == ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1363 WNI_CFG_PROBE_RSP_ADDNIE_DATA3, (tANI_U8*)addIE, 0, NULL,
1364 eANI_BOOLEAN_FALSE) )
1365 {
1366 hddLog(LOGE,
1367 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA3 to CCM\n");
1368 }
1369 }
1370
1371 if (ccmCfgSetInt((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1372 WNI_CFG_PROBE_RSP_ADDNIE_FLAG, 1,NULL,
1373 test_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags) ?
1374 eANI_BOOLEAN_TRUE : eANI_BOOLEAN_FALSE)
1375 == eHAL_STATUS_FAILURE)
1376 {
1377 hddLog(LOGE,
1378 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_FLAG to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001379 ret = -EINVAL;
1380 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001381 }
1382 }
1383 else
1384 {
1385 // Reset WNI_CFG_PROBE_RSP Flags
1386 wlan_hdd_reset_prob_rspies(pHostapdAdapter);
1387
1388 hddLog(VOS_TRACE_LEVEL_INFO,
1389 "%s: No Probe Response IE received in set beacon",
1390 __func__);
1391 }
1392
1393 // Added for AssocResp IE
1394 if ( (params->assocresp_ies != NULL) && (params->assocresp_ies_len != 0) )
1395 {
1396 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1397 WNI_CFG_ASSOC_RSP_ADDNIE_DATA, (tANI_U8*)params->assocresp_ies,
1398 params->assocresp_ies_len, NULL,
1399 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
1400 {
1401 hddLog(LOGE,
1402 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_DATA to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001403 ret = -EINVAL;
1404 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001405 }
1406
1407 if (ccmCfgSetInt((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1408 WNI_CFG_ASSOC_RSP_ADDNIE_FLAG, 1, NULL,
1409 test_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags) ?
1410 eANI_BOOLEAN_TRUE : eANI_BOOLEAN_FALSE)
1411 == eHAL_STATUS_FAILURE)
1412 {
1413 hddLog(LOGE,
1414 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_FLAG to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001415 ret = -EINVAL;
1416 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001417 }
1418 }
1419 else
1420 {
1421 hddLog(VOS_TRACE_LEVEL_INFO,
1422 "%s: No Assoc Response IE received in set beacon",
1423 __func__);
1424
1425 if ( eHAL_STATUS_FAILURE == ccmCfgSetInt((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1426 WNI_CFG_ASSOC_RSP_ADDNIE_FLAG, 0, NULL,
1427 eANI_BOOLEAN_FALSE) )
1428 {
1429 hddLog(LOGE,
1430 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_FLAG to CCM\n");
1431 }
1432 }
1433
Jeff Johnsone7245742012-09-05 17:12:55 -07001434done:
Jeff Johnson295189b2012-06-20 16:38:30 -07001435 vos_mem_free(genie);
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301436 return ret;
Jeff Johnson295189b2012-06-20 16:38:30 -07001437}
Jeff Johnson295189b2012-06-20 16:38:30 -07001438
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301439/*
Jeff Johnson295189b2012-06-20 16:38:30 -07001440 * FUNCTION: wlan_hdd_validate_operation_channel
1441 * called by wlan_hdd_cfg80211_start_bss() and
1442 * wlan_hdd_cfg80211_set_channel()
1443 * This function validates whether given channel is part of valid
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301444 * channel list.
1445 */
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07001446VOS_STATUS wlan_hdd_validate_operation_channel(hdd_adapter_t *pAdapter,int channel)
Jeff Johnson295189b2012-06-20 16:38:30 -07001447{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301448
Jeff Johnson295189b2012-06-20 16:38:30 -07001449 v_U32_t num_ch = 0;
1450 u8 valid_ch[WNI_CFG_VALID_CHANNEL_LIST_LEN];
1451 u32 indx = 0;
1452 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301453 v_U8_t fValidChannel = FALSE, count = 0;
1454 hdd_config_t *hdd_pConfig_ini= (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301455
Jeff Johnson295189b2012-06-20 16:38:30 -07001456 num_ch = WNI_CFG_VALID_CHANNEL_LIST_LEN;
1457
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301458 if ( hdd_pConfig_ini->sapAllowAllChannel)
Jeff Johnson295189b2012-06-20 16:38:30 -07001459 {
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301460 /* Validate the channel */
1461 for (count = RF_CHAN_1 ; count <= RF_CHAN_165 ; count++)
Jeff Johnson295189b2012-06-20 16:38:30 -07001462 {
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301463 if ( channel == rfChannels[count].channelNum )
1464 {
1465 fValidChannel = TRUE;
1466 break;
1467 }
1468 }
1469 if (fValidChannel != TRUE)
1470 {
1471 hddLog(VOS_TRACE_LEVEL_ERROR,
1472 "%s: Invalid Channel [%d]", __func__, channel);
1473 return VOS_STATUS_E_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07001474 }
1475 }
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301476 else
Jeff Johnson295189b2012-06-20 16:38:30 -07001477 {
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301478 if (0 != ccmCfgGetStr(hHal, WNI_CFG_VALID_CHANNEL_LIST,
1479 valid_ch, &num_ch))
1480 {
1481 hddLog(VOS_TRACE_LEVEL_ERROR,
1482 "%s: failed to get valid channel list", __func__);
1483 return VOS_STATUS_E_FAILURE;
1484 }
1485 for (indx = 0; indx < num_ch; indx++)
1486 {
1487 if (channel == valid_ch[indx])
1488 {
1489 break;
1490 }
1491 }
1492
1493 if (indx >= num_ch)
1494 {
1495 hddLog(VOS_TRACE_LEVEL_ERROR,
1496 "%s: Invalid Channel [%d]", __func__, channel);
1497 return VOS_STATUS_E_FAILURE;
1498 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001499 }
1500 return VOS_STATUS_SUCCESS;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301501
Jeff Johnson295189b2012-06-20 16:38:30 -07001502}
1503
Viral Modi3a32cc52013-02-08 11:14:52 -08001504/**
1505 * FUNCTION: wlan_hdd_cfg80211_set_channel
1506 * This function is used to set the channel number
1507 */
1508static int wlan_hdd_cfg80211_set_channel( struct wiphy *wiphy, struct net_device *dev,
1509 struct ieee80211_channel *chan,
1510 enum nl80211_channel_type channel_type
1511 )
1512{
1513 v_U32_t num_ch = 0;
Jeff Johnson4416a782013-03-25 14:17:50 -07001514 int channel = 0;
Viral Modi3a32cc52013-02-08 11:14:52 -08001515 hdd_adapter_t *pAdapter = NULL;
1516 int freq = chan->center_freq; /* freq is in MHZ */
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05301517 hdd_context_t *pHddCtx;
1518 int status;
Viral Modi3a32cc52013-02-08 11:14:52 -08001519
1520 ENTER();
1521
1522 if( NULL == dev )
1523 {
1524 hddLog(VOS_TRACE_LEVEL_ERROR,
1525 "%s: Called with dev = NULL.\n", __func__);
1526 return -ENODEV;
1527 }
1528 pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
1529
1530 hddLog(VOS_TRACE_LEVEL_INFO,
1531 "%s: device_mode = %d freq = %d \n",__func__,
1532 pAdapter->device_mode, chan->center_freq);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05301533
1534 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
1535 status = wlan_hdd_validate_context(pHddCtx);
1536
1537 if (0 != status)
Viral Modi3a32cc52013-02-08 11:14:52 -08001538 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05301539 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1540 "%s: HDD context is not valid", __func__);
1541 return status;
Viral Modi3a32cc52013-02-08 11:14:52 -08001542 }
1543
1544 /*
1545 * Do freq to chan conversion
1546 * TODO: for 11a
1547 */
1548
1549 channel = ieee80211_frequency_to_channel(freq);
1550
1551 /* Check freq range */
1552 if ((WNI_CFG_CURRENT_CHANNEL_STAMIN > channel) ||
1553 (WNI_CFG_CURRENT_CHANNEL_STAMAX < channel))
1554 {
1555 hddLog(VOS_TRACE_LEVEL_ERROR,
1556 "%s: Channel [%d] is outside valid range from %d to %d\n",
1557 __func__, channel, WNI_CFG_CURRENT_CHANNEL_STAMIN,
1558 WNI_CFG_CURRENT_CHANNEL_STAMAX);
1559 return -EINVAL;
1560 }
1561
1562 num_ch = WNI_CFG_VALID_CHANNEL_LIST_LEN;
1563
Gopichand Nakkala6ab19562013-03-07 13:59:42 +05301564 if ((WLAN_HDD_SOFTAP != pAdapter->device_mode) &&
1565 (WLAN_HDD_P2P_GO != pAdapter->device_mode))
Viral Modi3a32cc52013-02-08 11:14:52 -08001566 {
1567 if(VOS_STATUS_SUCCESS != wlan_hdd_validate_operation_channel(pAdapter,channel))
1568 {
1569 hddLog(VOS_TRACE_LEVEL_ERROR,
1570 "%s: Invalid Channel [%d] \n", __func__, channel);
1571 return -EINVAL;
1572 }
1573 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
1574 "%s: set channel to [%d] for device mode =%d",
1575 __func__, channel,pAdapter->device_mode);
1576 }
1577 if( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Viral Modi3a32cc52013-02-08 11:14:52 -08001578 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Viral Modi3a32cc52013-02-08 11:14:52 -08001579 )
1580 {
1581 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
1582 tCsrRoamProfile * pRoamProfile = &pWextState->roamProfile;
1583 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
1584
1585 if (eConnectionState_IbssConnected == pHddStaCtx->conn_info.connState)
1586 {
1587 /* Link is up then return cant set channel*/
1588 hddLog( VOS_TRACE_LEVEL_ERROR,
1589 "%s: IBSS Associated, can't set the channel\n", __func__);
1590 return -EINVAL;
1591 }
1592
1593 num_ch = pRoamProfile->ChannelInfo.numOfChannels = 1;
1594 pHddStaCtx->conn_info.operationChannel = channel;
1595 pRoamProfile->ChannelInfo.ChannelList =
1596 &pHddStaCtx->conn_info.operationChannel;
1597 }
1598 else if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Viral Modi3a32cc52013-02-08 11:14:52 -08001599 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Viral Modi3a32cc52013-02-08 11:14:52 -08001600 )
1601 {
Gopichand Nakkalac8fa7b62013-03-11 13:56:41 +05301602 if (WLAN_HDD_P2P_GO == pAdapter->device_mode)
1603 {
1604 if(VOS_STATUS_SUCCESS !=
1605 wlan_hdd_validate_operation_channel(pAdapter,channel))
1606 {
1607 hddLog(VOS_TRACE_LEVEL_ERROR,
1608 "%s: Invalid Channel [%d] \n", __func__, channel);
1609 return -EINVAL;
1610 }
1611 (WLAN_HDD_GET_AP_CTX_PTR(pAdapter))->sapConfig.channel = channel;
1612 }
1613 else if ( WLAN_HDD_SOFTAP == pAdapter->device_mode )
Viral Modi3a32cc52013-02-08 11:14:52 -08001614 {
1615 hdd_config_t *cfg_param = (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini;
1616
1617 /* If auto channel selection is configured as enable/ 1 then ignore
1618 channel set by supplicant
1619 */
1620 if ( cfg_param->apAutoChannelSelection )
1621 {
Gopichand Nakkalac8fa7b62013-03-11 13:56:41 +05301622 (WLAN_HDD_GET_AP_CTX_PTR(pAdapter))->sapConfig.channel =
1623 AUTO_CHANNEL_SELECT;
Viral Modi3a32cc52013-02-08 11:14:52 -08001624 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
1625 "%s: set channel to auto channel (0) for device mode =%d",
1626 __func__, pAdapter->device_mode);
1627 }
Gopichand Nakkalac8fa7b62013-03-11 13:56:41 +05301628 else
1629 {
1630 if(VOS_STATUS_SUCCESS !=
1631 wlan_hdd_validate_operation_channel(pAdapter,channel))
1632 {
1633 hddLog(VOS_TRACE_LEVEL_ERROR,
1634 "%s: Invalid Channel [%d] \n", __func__, channel);
1635 return -EINVAL;
1636 }
1637 (WLAN_HDD_GET_AP_CTX_PTR(pAdapter))->sapConfig.channel = channel;
1638 }
Viral Modi3a32cc52013-02-08 11:14:52 -08001639 }
1640 }
1641 else
1642 {
1643 hddLog(VOS_TRACE_LEVEL_FATAL,
1644 "%s: Invalid device mode failed to set valid channel", __func__);
1645 return -EINVAL;
1646 }
1647 EXIT();
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05301648 return status;
Viral Modi3a32cc52013-02-08 11:14:52 -08001649}
1650
Jeff Johnson295189b2012-06-20 16:38:30 -07001651#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
1652static int wlan_hdd_cfg80211_start_bss(hdd_adapter_t *pHostapdAdapter,
1653 struct beacon_parameters *params)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001654#else
1655static int wlan_hdd_cfg80211_start_bss(hdd_adapter_t *pHostapdAdapter,
1656 struct cfg80211_beacon_data *params,
1657 const u8 *ssid, size_t ssid_len,
1658 enum nl80211_hidden_ssid hidden_ssid)
1659#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07001660{
1661 tsap_Config_t *pConfig;
1662 beacon_data_t *pBeacon = NULL;
1663 struct ieee80211_mgmt *pMgmt_frame;
1664 v_U8_t *pIe=NULL;
1665 v_U16_t capab_info;
1666 eCsrAuthType RSNAuthType;
1667 eCsrEncryptionType RSNEncryptType;
1668 eCsrEncryptionType mcRSNEncryptType;
1669 int status = VOS_STATUS_SUCCESS;
1670 tpWLAN_SAPEventCB pSapEventCallback;
1671 hdd_hostapd_state_t *pHostapdState;
1672 v_U8_t wpaRsnIEdata[(SIR_MAC_MAX_IE_LENGTH * 2)+4]; //Max ie length 255 * 2(WPA+RSN) + 2 bytes (vendor specific ID) * 2
1673 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pHostapdAdapter))->pvosContext;
Madan Mohan Koyylamudia16d0202013-02-01 11:05:57 +05301674 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pHostapdAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001675 struct qc_mac_acl_entry *acl_entry = NULL;
1676 v_SINT_t i;
Madan Mohan Koyyalamudi543172b2012-12-05 16:40:18 -08001677 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pHostapdAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001678
1679 ENTER();
1680
1681 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pHostapdAdapter);
1682
1683 pConfig = &pHostapdAdapter->sessionCtx.ap.sapConfig;
1684
1685 pBeacon = pHostapdAdapter->sessionCtx.ap.beacon;
1686
1687 pMgmt_frame = (struct ieee80211_mgmt*)pBeacon->head;
1688
1689 pConfig->beacon_int = pMgmt_frame->u.beacon.beacon_int;
1690
1691 //channel is already set in the set_channel Call back
1692 //pConfig->channel = pCommitConfig->channel;
1693
1694 /*Protection parameter to enable or disable*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301695 pConfig->protEnabled =
Jeff Johnson295189b2012-06-20 16:38:30 -07001696 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apProtEnabled;
1697
1698 pConfig->dtim_period = pBeacon->dtim_period;
1699
1700 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,"****pConfig->dtim_period=%d***\n",
1701 pConfig->dtim_period);
1702
1703
Madan Mohan Koyyalamudie0ca11f2012-11-27 15:57:52 -08001704 if (pHostapdAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson32d95a32012-09-10 13:15:23 -07001705 {
1706 pIe = wlan_hdd_cfg80211_get_ie_ptr(pBeacon->tail, pBeacon->tail_len,
Jeff Johnson295189b2012-06-20 16:38:30 -07001707 WLAN_EID_COUNTRY);
Jeff Johnson32d95a32012-09-10 13:15:23 -07001708 if(pIe)
Jeff Johnson295189b2012-06-20 16:38:30 -07001709 {
Jeff Johnson32d95a32012-09-10 13:15:23 -07001710 tANI_BOOLEAN restartNeeded;
Jeff Johnson32d95a32012-09-10 13:15:23 -07001711 pConfig->ieee80211d = 1;
1712 vos_mem_copy(pConfig->countryCode, &pIe[2], 3);
1713 sme_setRegInfo(hHal, pConfig->countryCode);
1714 sme_ResetCountryCodeInformation(hHal, &restartNeeded);
Jeff Johnson295189b2012-06-20 16:38:30 -07001715 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07001716 else
1717 {
1718 pConfig->ieee80211d = 0;
1719 }
Madan Mohan Koyylamudia16d0202013-02-01 11:05:57 +05301720 /*
1721 * If auto channel is configured i.e. channel is 0,
1722 * so skip channel validation.
1723 */
1724 if( AUTO_CHANNEL_SELECT != pConfig->channel )
1725 {
1726 if(VOS_STATUS_SUCCESS != wlan_hdd_validate_operation_channel(pHostapdAdapter,pConfig->channel))
1727 {
1728 hddLog(VOS_TRACE_LEVEL_ERROR,
1729 "%s: Invalid Channel [%d] \n", __func__, pConfig->channel);
1730 return -EINVAL;
1731 }
1732 }
1733 else
1734 {
1735 if(1 != pHddCtx->is_dynamic_channel_range_set)
1736 {
1737 hdd_config_t *hdd_pConfig= (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini;
1738 WLANSAP_SetChannelRange(hHal, hdd_pConfig->apStartChannelNum,
1739 hdd_pConfig->apEndChannelNum,hdd_pConfig->apOperatingBand);
1740 }
1741 pHddCtx->is_dynamic_channel_range_set = 0;
1742 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001743 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07001744 else
Jeff Johnson295189b2012-06-20 16:38:30 -07001745 {
1746 pConfig->ieee80211d = 0;
1747 }
1748 pConfig->authType = eSAP_AUTO_SWITCH;
1749
1750 capab_info = pMgmt_frame->u.beacon.capab_info;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301751
1752 pConfig->privacy = (pMgmt_frame->u.beacon.capab_info &
Jeff Johnson295189b2012-06-20 16:38:30 -07001753 WLAN_CAPABILITY_PRIVACY) ? VOS_TRUE : VOS_FALSE;
1754
1755 (WLAN_HDD_GET_AP_CTX_PTR(pHostapdAdapter))->uPrivacy = pConfig->privacy;
1756
1757 /*Set wps station to configured*/
1758 pIe = wlan_hdd_get_wps_ie_ptr(pBeacon->tail, pBeacon->tail_len);
1759
1760 if(pIe)
1761 {
1762 if(pIe[1] < (2 + WPS_OUI_TYPE_SIZE))
1763 {
1764 hddLog( VOS_TRACE_LEVEL_ERROR, "**Wps Ie Length is too small***\n");
1765 return -EINVAL;
1766 }
1767 else if(memcmp(&pIe[2], WPS_OUI_TYPE, WPS_OUI_TYPE_SIZE) == 0)
1768 {
Madan Mohan Koyyalamudi8bdd3112012-09-24 13:55:14 -07001769 hddLog( VOS_TRACE_LEVEL_INFO, "** WPS IE(len %d) ***", (pIe[1]+2));
Jeff Johnson295189b2012-06-20 16:38:30 -07001770 /* Check 15 bit of WPS IE as it contain information for wps state
1771 * WPS state
1772 */
1773 if(SAP_WPS_ENABLED_UNCONFIGURED == pIe[15])
1774 {
1775 pConfig->wps_state = SAP_WPS_ENABLED_UNCONFIGURED;
1776 } else if(SAP_WPS_ENABLED_CONFIGURED == pIe[15])
1777 {
1778 pConfig->wps_state = SAP_WPS_ENABLED_CONFIGURED;
1779 }
1780 }
1781 }
1782 else
1783 {
1784 pConfig->wps_state = SAP_WPS_DISABLED;
1785 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301786 pConfig->fwdWPSPBCProbeReq = 1; // Forward WPS PBC probe request frame up
Jeff Johnson295189b2012-06-20 16:38:30 -07001787
1788 pConfig->RSNWPAReqIELength = 0;
1789 pConfig->pRSNWPAReqIE = NULL;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301790 pIe = wlan_hdd_cfg80211_get_ie_ptr(pBeacon->tail, pBeacon->tail_len,
Jeff Johnson295189b2012-06-20 16:38:30 -07001791 WLAN_EID_RSN);
1792 if(pIe && pIe[1])
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301793 {
Jeff Johnson295189b2012-06-20 16:38:30 -07001794 pConfig->RSNWPAReqIELength = pIe[1] + 2;
1795 memcpy(&wpaRsnIEdata[0], pIe, pConfig->RSNWPAReqIELength);
1796 pConfig->pRSNWPAReqIE = &wpaRsnIEdata[0];
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301797 /* The actual processing may eventually be more extensive than
1798 * this. Right now, just consume any PMKIDs that are sent in
Jeff Johnson295189b2012-06-20 16:38:30 -07001799 * by the app.
1800 * */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301801 status = hdd_softap_unpackIE(
Jeff Johnson295189b2012-06-20 16:38:30 -07001802 vos_get_context( VOS_MODULE_ID_SME, pVosContext),
1803 &RSNEncryptType,
1804 &mcRSNEncryptType,
1805 &RSNAuthType,
1806 pConfig->pRSNWPAReqIE[1]+2,
1807 pConfig->pRSNWPAReqIE );
1808
1809 if( VOS_STATUS_SUCCESS == status )
1810 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301811 /* Now copy over all the security attributes you have
1812 * parsed out
Jeff Johnson295189b2012-06-20 16:38:30 -07001813 * */
1814 pConfig->RSNEncryptType = RSNEncryptType; // Use the cipher type in the RSN IE
1815 pConfig->mcRSNEncryptType = mcRSNEncryptType;
1816 (WLAN_HDD_GET_AP_CTX_PTR(pHostapdAdapter))->ucEncryptType
1817 = RSNEncryptType;
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +05301818 hddLog( LOG1, FL("CSR AuthType = %d, "
Jeff Johnson295189b2012-06-20 16:38:30 -07001819 "EncryptionType = %d mcEncryptionType = %d\n"),
1820 RSNAuthType, RSNEncryptType, mcRSNEncryptType);
1821 }
1822 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301823
Jeff Johnson295189b2012-06-20 16:38:30 -07001824 pIe = wlan_hdd_get_vendor_oui_ie_ptr(WPA_OUI_TYPE, WPA_OUI_TYPE_SIZE,
1825 pBeacon->tail, pBeacon->tail_len);
1826
1827 if(pIe && pIe[1] && (pIe[0] == DOT11F_EID_WPA))
1828 {
1829 if (pConfig->pRSNWPAReqIE)
1830 {
1831 /*Mixed mode WPA/WPA2*/
1832 memcpy((&wpaRsnIEdata[0] + pConfig->RSNWPAReqIELength), pIe, pIe[1] + 2);
1833 pConfig->RSNWPAReqIELength += pIe[1] + 2;
1834 }
1835 else
1836 {
1837 pConfig->RSNWPAReqIELength = pIe[1] + 2;
1838 memcpy(&wpaRsnIEdata[0], pIe, pConfig->RSNWPAReqIELength);
1839 pConfig->pRSNWPAReqIE = &wpaRsnIEdata[0];
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301840 status = hdd_softap_unpackIE(
Jeff Johnson295189b2012-06-20 16:38:30 -07001841 vos_get_context( VOS_MODULE_ID_SME, pVosContext),
1842 &RSNEncryptType,
1843 &mcRSNEncryptType,
1844 &RSNAuthType,
1845 pConfig->pRSNWPAReqIE[1]+2,
1846 pConfig->pRSNWPAReqIE );
1847
1848 if( VOS_STATUS_SUCCESS == status )
1849 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301850 /* Now copy over all the security attributes you have
1851 * parsed out
Jeff Johnson295189b2012-06-20 16:38:30 -07001852 * */
1853 pConfig->RSNEncryptType = RSNEncryptType; // Use the cipher type in the RSN IE
1854 pConfig->mcRSNEncryptType = mcRSNEncryptType;
1855 (WLAN_HDD_GET_AP_CTX_PTR(pHostapdAdapter))->ucEncryptType
1856 = RSNEncryptType;
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +05301857 hddLog( LOG1, FL("CSR AuthType = %d, "
Jeff Johnson295189b2012-06-20 16:38:30 -07001858 "EncryptionType = %d mcEncryptionType = %d\n"),
1859 RSNAuthType, RSNEncryptType, mcRSNEncryptType);
1860 }
1861 }
1862 }
1863
Jeff Johnson4416a782013-03-25 14:17:50 -07001864 if (pConfig->RSNWPAReqIELength > sizeof wpaRsnIEdata) {
1865 hddLog( VOS_TRACE_LEVEL_ERROR, "**RSNWPAReqIELength is too large***");
1866 return -EINVAL;
1867 }
1868
Jeff Johnson295189b2012-06-20 16:38:30 -07001869 pConfig->SSIDinfo.ssidHidden = VOS_FALSE;
1870
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001871#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07001872 if (params->ssid != NULL)
1873 {
1874 memcpy(pConfig->SSIDinfo.ssid.ssId, params->ssid, params->ssid_len);
1875 pConfig->SSIDinfo.ssid.length = params->ssid_len;
1876 if (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE)
1877 pConfig->SSIDinfo.ssidHidden = VOS_TRUE;
1878 }
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001879#else
1880 if (ssid != NULL)
1881 {
1882 memcpy(pConfig->SSIDinfo.ssid.ssId, ssid, ssid_len);
1883 pConfig->SSIDinfo.ssid.length = ssid_len;
1884 if (hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE)
1885 pConfig->SSIDinfo.ssidHidden = VOS_TRUE;
1886 }
1887#endif
1888
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301889 vos_mem_copy(pConfig->self_macaddr.bytes,
Jeff Johnson295189b2012-06-20 16:38:30 -07001890 pHostapdAdapter->macAddressCurrent.bytes, sizeof(v_MACADDR_t));
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301891
Jeff Johnson295189b2012-06-20 16:38:30 -07001892 /* default value */
1893 pConfig->SapMacaddr_acl = eSAP_ACCEPT_UNLESS_DENIED;
1894 pConfig->num_accept_mac = 0;
1895 pConfig->num_deny_mac = 0;
1896
1897 pIe = wlan_hdd_get_vendor_oui_ie_ptr(BLACKLIST_OUI_TYPE, WPA_OUI_TYPE_SIZE,
1898 pBeacon->tail, pBeacon->tail_len);
1899
1900 /* pIe for black list is following form:
1901 type : 1 byte
1902 length : 1 byte
1903 OUI : 4 bytes
1904 acl type : 1 byte
1905 no of mac addr in black list: 1 byte
1906 list of mac_acl_entries: variable, 6 bytes per mac address + sizeof(int) for vlan id
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301907 */
1908 if ((pIe != NULL) && (pIe[1] != 0))
Jeff Johnson295189b2012-06-20 16:38:30 -07001909 {
1910 pConfig->SapMacaddr_acl = pIe[6];
1911 pConfig->num_deny_mac = pIe[7];
1912 hddLog(VOS_TRACE_LEVEL_INFO,"acl type = %d no deny mac = %d\n",
1913 pIe[6], pIe[7]);
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05301914 if (pConfig->num_deny_mac > MAX_ACL_MAC_ADDRESS)
1915 pConfig->num_deny_mac = MAX_ACL_MAC_ADDRESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001916 acl_entry = (struct qc_mac_acl_entry *)(pIe + 8);
1917 for (i = 0; i < pConfig->num_deny_mac; i++)
1918 {
1919 vos_mem_copy(&pConfig->deny_mac[i], acl_entry->addr, sizeof(qcmacaddr));
1920 acl_entry++;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301921 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001922 }
1923 pIe = wlan_hdd_get_vendor_oui_ie_ptr(WHITELIST_OUI_TYPE, WPA_OUI_TYPE_SIZE,
1924 pBeacon->tail, pBeacon->tail_len);
1925
1926 /* pIe for white list is following form:
1927 type : 1 byte
1928 length : 1 byte
1929 OUI : 4 bytes
1930 acl type : 1 byte
1931 no of mac addr in white list: 1 byte
1932 list of mac_acl_entries: variable, 6 bytes per mac address + sizeof(int) for vlan id
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301933 */
1934 if ((pIe != NULL) && (pIe[1] != 0))
Jeff Johnson295189b2012-06-20 16:38:30 -07001935 {
1936 pConfig->SapMacaddr_acl = pIe[6];
1937 pConfig->num_accept_mac = pIe[7];
1938 hddLog(VOS_TRACE_LEVEL_INFO,"acl type = %d no accept mac = %d\n",
1939 pIe[6], pIe[7]);
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05301940 if (pConfig->num_accept_mac > MAX_ACL_MAC_ADDRESS)
1941 pConfig->num_accept_mac = MAX_ACL_MAC_ADDRESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001942 acl_entry = (struct qc_mac_acl_entry *)(pIe + 8);
1943 for (i = 0; i < pConfig->num_accept_mac; i++)
1944 {
1945 vos_mem_copy(&pConfig->accept_mac[i], acl_entry->addr, sizeof(qcmacaddr));
1946 acl_entry++;
1947 }
1948 }
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05301949
Jeff Johnson295189b2012-06-20 16:38:30 -07001950 wlan_hdd_set_sapHwmode(pHostapdAdapter);
1951
Jeff Johnsone7245742012-09-05 17:12:55 -07001952#ifdef WLAN_FEATURE_11AC
Ravi Kumar Vaishnavbbaebbe2013-01-15 17:09:48 -08001953 /* Overwrite the hostapd setting for HW mode only for 11ac.
1954 * This is valid only if mode is set to 11n in hostapd and either AUTO or 11ac in .ini .
1955 * Otherwise, leave whatever is set in hostapd (a OR b OR g OR n mode) */
1956 if( ((pConfig->SapHw_mode == eSAP_DOT11_MODE_11n) ||
1957 (pConfig->SapHw_mode == eSAP_DOT11_MODE_11n_ONLY)) &&
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301958 (((WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->dot11Mode == eHDD_DOT11_MODE_AUTO) ||
Ravi Kumar Vaishnavbbaebbe2013-01-15 17:09:48 -08001959 ((WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->dot11Mode == eHDD_DOT11_MODE_11ac) ||
1960 ((WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY)) )
Jeff Johnsone7245742012-09-05 17:12:55 -07001961 {
1962 pConfig->SapHw_mode = eSAP_DOT11_MODE_11ac;
Ravi Joshi83bfaa12013-05-28 22:12:08 -07001963
1964 /* Disable VHT support in 2.4 GHz band */
1965 if (pConfig->channel <= 14 &&
1966 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->enableVhtFor24GHzBand == FALSE)
1967 {
1968 pConfig->SapHw_mode = eSAP_DOT11_MODE_11n;
1969 }
Jeff Johnsone7245742012-09-05 17:12:55 -07001970 }
1971#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301972
Ravi Joshiaeb7d9e2013-05-02 12:28:14 -07001973 if ( AUTO_CHANNEL_SELECT != pConfig->channel )
1974 {
1975 sme_SelectCBMode(hHal,
1976 sapConvertSapPhyModeToCsrPhyMode(pConfig->SapHw_mode),
1977 pConfig->channel);
1978 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001979 // ht_capab is not what the name conveys,this is used for protection bitmap
1980 pConfig->ht_capab =
1981 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apProtection;
1982
1983 if ( 0 != wlan_hdd_cfg80211_update_apies(pHostapdAdapter, params) )
1984 {
1985 hddLog(LOGE, FL("SAP Not able to set AP IEs"));
1986 return -EINVAL;
1987 }
1988
1989 //Uapsd Enabled Bit
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301990 pConfig->UapsdEnable =
Jeff Johnson295189b2012-06-20 16:38:30 -07001991 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apUapsdEnabled;
1992 //Enable OBSS protection
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301993 pConfig->obssProtEnabled =
1994 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apOBSSProtEnabled;
Jeff Johnson295189b2012-06-20 16:38:30 -07001995
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301996 hddLog(LOGW, FL("SOftAP macaddress : "MAC_ADDRESS_STR"\n"),
Jeff Johnson295189b2012-06-20 16:38:30 -07001997 MAC_ADDR_ARRAY(pHostapdAdapter->macAddressCurrent.bytes));
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301998 hddLog(LOGW,FL("ssid =%s\n"), pConfig->SSIDinfo.ssid.ssId);
Jeff Johnson295189b2012-06-20 16:38:30 -07001999 hddLog(LOGW,FL("beaconint=%d, channel=%d\n"), (int)pConfig->beacon_int,
2000 (int)pConfig->channel);
2001 hddLog(LOGW,FL("hw_mode=%x\n"), pConfig->SapHw_mode);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302002 hddLog(LOGW,FL("privacy=%d, authType=%d\n"), pConfig->privacy,
2003 pConfig->authType);
Jeff Johnson295189b2012-06-20 16:38:30 -07002004 hddLog(LOGW,FL("RSN/WPALen=%d, \n"),(int)pConfig->RSNWPAReqIELength);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302005 hddLog(LOGW,FL("Uapsd = %d\n"),pConfig->UapsdEnable);
Jeff Johnson295189b2012-06-20 16:38:30 -07002006 hddLog(LOGW,FL("ProtEnabled = %d, OBSSProtEnabled = %d\n"),
2007 pConfig->protEnabled, pConfig->obssProtEnabled);
2008
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302009 if(test_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags))
Jeff Johnson295189b2012-06-20 16:38:30 -07002010 {
2011 //Bss already started. just return.
2012 //TODO Probably it should update some beacon params.
2013 hddLog( LOGE, "Bss Already started...Ignore the request");
2014 EXIT();
2015 return 0;
2016 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302017
Jeff Johnson295189b2012-06-20 16:38:30 -07002018 pConfig->persona = pHostapdAdapter->device_mode;
2019
2020 pSapEventCallback = hdd_hostapd_SAPEventCB;
2021 if(WLANSAP_StartBss(pVosContext, pSapEventCallback, pConfig,
2022 (v_PVOID_t)pHostapdAdapter->dev) != VOS_STATUS_SUCCESS)
2023 {
2024 hddLog(LOGE,FL("SAP Start Bss fail\n"));
2025 return -EINVAL;
2026 }
2027
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302028 hddLog(LOG1,
Jeff Johnson295189b2012-06-20 16:38:30 -07002029 FL("Waiting for Scan to complete(auto mode) and BSS to start"));
2030
2031 status = vos_wait_single_event(&pHostapdState->vosEvent, 10000);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302032
Jeff Johnson295189b2012-06-20 16:38:30 -07002033 if (!VOS_IS_STATUS_SUCCESS(status))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302034 {
2035 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07002036 ("ERROR: HDD vos wait for single_event failed!!\n"));
2037 VOS_ASSERT(0);
2038 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302039
Jeff Johnson295189b2012-06-20 16:38:30 -07002040 //Succesfully started Bss update the state bit.
2041 set_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags);
2042
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07002043#ifdef WLAN_FEATURE_P2P_DEBUG
2044 if (pHostapdAdapter->device_mode == WLAN_HDD_P2P_GO)
2045 {
2046 if(globalP2PConnectionStatus == P2P_GO_NEG_COMPLETED)
2047 {
2048 globalP2PConnectionStatus = P2P_GO_COMPLETED_STATE;
2049 hddLog(LOGE,"[P2P State] From Go nego completed to "
Jeff Johnson1250df42012-12-10 14:31:52 -08002050 "Non-autonomous Group started");
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07002051 }
2052 else if(globalP2PConnectionStatus == P2P_NOT_ACTIVE)
2053 {
2054 globalP2PConnectionStatus = P2P_GO_COMPLETED_STATE;
2055 hddLog(LOGE,"[P2P State] From Inactive to "
Jeff Johnson1250df42012-12-10 14:31:52 -08002056 "Autonomous Group started");
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07002057 }
2058 }
2059#endif
2060
Jeff Johnson295189b2012-06-20 16:38:30 -07002061 pHostapdState->bCommit = TRUE;
2062 EXIT();
2063
2064 return 0;
2065}
2066
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002067#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302068static int wlan_hdd_cfg80211_add_beacon(struct wiphy *wiphy,
2069 struct net_device *dev,
Jeff Johnson295189b2012-06-20 16:38:30 -07002070 struct beacon_parameters *params)
2071{
2072 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302073 hdd_context_t *pHddCtx;
2074 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07002075
2076 ENTER();
2077
2078 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "device mode=%d\n",pAdapter->device_mode);
2079
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302080 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2081 status = wlan_hdd_validate_context(pHddCtx);
2082
2083 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002084 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302085 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2086 "%s: HDD context is not valid", __func__);
2087 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002088 }
2089
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302090 if ( (pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002091 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -07002092 )
2093 {
2094 beacon_data_t *old,*new;
2095
2096 old = pAdapter->sessionCtx.ap.beacon;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302097
Jeff Johnson295189b2012-06-20 16:38:30 -07002098 if (old)
2099 return -EALREADY;
2100
2101 status = wlan_hdd_cfg80211_alloc_new_beacon(pAdapter,&new,params);
2102
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302103 if(status != VOS_STATUS_SUCCESS)
Jeff Johnson295189b2012-06-20 16:38:30 -07002104 {
2105 hddLog(VOS_TRACE_LEVEL_FATAL,
2106 "%s:Error!!! Allocating the new beacon\n",__func__);
2107 return -EINVAL;
2108 }
2109
2110 pAdapter->sessionCtx.ap.beacon = new;
2111
2112 status = wlan_hdd_cfg80211_start_bss(pAdapter, params);
2113 }
2114
2115 EXIT();
2116 return status;
2117}
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302118
2119static int wlan_hdd_cfg80211_set_beacon(struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07002120 struct net_device *dev,
2121 struct beacon_parameters *params)
2122{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302123 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302124 hdd_context_t *pHddCtx;
2125 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07002126
2127 ENTER();
2128
2129 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
2130 __func__,pAdapter->device_mode);
2131
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302132 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2133 status = wlan_hdd_validate_context(pHddCtx);
2134
2135 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002136 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302137 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2138 "%s: HDD context is not valid", __func__);
2139 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002140 }
2141
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302142 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002143 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302144 )
Jeff Johnson295189b2012-06-20 16:38:30 -07002145 {
2146 beacon_data_t *old,*new;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302147
Jeff Johnson295189b2012-06-20 16:38:30 -07002148 old = pAdapter->sessionCtx.ap.beacon;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302149
Jeff Johnson295189b2012-06-20 16:38:30 -07002150 if (!old)
2151 return -ENOENT;
2152
2153 status = wlan_hdd_cfg80211_alloc_new_beacon(pAdapter,&new,params);
2154
2155 if(status != VOS_STATUS_SUCCESS) {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302156 hddLog(VOS_TRACE_LEVEL_FATAL,
Jeff Johnson295189b2012-06-20 16:38:30 -07002157 "%s: Error!!! Allocating the new beacon\n",__func__);
2158 return -EINVAL;
2159 }
2160
2161 pAdapter->sessionCtx.ap.beacon = new;
2162
2163 status = wlan_hdd_cfg80211_start_bss(pAdapter, params);
2164 }
2165
2166 EXIT();
2167 return status;
2168}
2169
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002170#endif //(LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
2171
2172#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07002173static int wlan_hdd_cfg80211_del_beacon(struct wiphy *wiphy,
2174 struct net_device *dev)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002175#else
2176static int wlan_hdd_cfg80211_stop_ap (struct wiphy *wiphy,
2177 struct net_device *dev)
2178#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002179{
2180 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsone7245742012-09-05 17:12:55 -07002181 hdd_context_t *pHddCtx = NULL;
2182 hdd_scaninfo_t *pScanInfo = NULL;
2183 hdd_adapter_t *staAdapter = NULL;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302184 VOS_STATUS status;
Jeff Johnson295189b2012-06-20 16:38:30 -07002185
2186 ENTER();
2187
2188 if (NULL == pAdapter)
2189 {
2190 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002191 "%s: HDD adapter context is Null", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002192 return -ENODEV;
2193 }
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002194
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302195 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2196 status = wlan_hdd_validate_context(pHddCtx);
2197
2198 if (0 != status)
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002199 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302200 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2201 "%s: HDD context is not valid", __func__);
2202 return status;
Jeff Johnson4416a782013-03-25 14:17:50 -07002203 }
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002204
2205 staAdapter = hdd_get_adapter(pAdapter->pHddCtx, WLAN_HDD_INFRA_STATION);
2206 if (NULL == staAdapter)
2207 {
2208 staAdapter = hdd_get_adapter(pAdapter->pHddCtx, WLAN_HDD_P2P_CLIENT);
2209 if (NULL == staAdapter)
2210 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302211 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002212 "%s: HDD adapter context is Null", __func__);
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002213 return -ENODEV;
2214 }
2215 }
2216
2217 pScanInfo = &pHddCtx->scan_info;
2218
Jeff Johnson295189b2012-06-20 16:38:30 -07002219 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
2220 __func__,pAdapter->device_mode);
2221
Jeff Johnsone7245742012-09-05 17:12:55 -07002222 if ((pScanInfo != NULL) && pScanInfo->mScanPending)
2223 {
Madan Mohan Koyyalamudif4e81002012-11-13 10:46:38 -08002224 INIT_COMPLETION(pScanInfo->abortscan_event_var);
Jeff Johnsone7245742012-09-05 17:12:55 -07002225 hdd_abort_mac_scan(staAdapter->pHddCtx);
2226 status = wait_for_completion_interruptible_timeout(
Madan Mohan Koyyalamudif4e81002012-11-13 10:46:38 -08002227 &pScanInfo->abortscan_event_var,
Jeff Johnsone7245742012-09-05 17:12:55 -07002228 msecs_to_jiffies(WLAN_WAIT_TIME_ABORTSCAN));
2229 if (!status)
2230 {
2231 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Jeff Johnson902c9832012-12-10 14:28:09 -08002232 "%s: Timeout occurred while waiting for abortscan" ,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002233 __func__);
Jeff Johnsone7245742012-09-05 17:12:55 -07002234 VOS_ASSERT(pScanInfo->mScanPending);
2235 return 0;
2236 }
2237 }
2238
Jeff Johnson295189b2012-06-20 16:38:30 -07002239 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002240 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -07002241 )
2242 {
2243 beacon_data_t *old;
2244
2245 old = pAdapter->sessionCtx.ap.beacon;
2246
2247 if (!old)
2248 return -ENOENT;
2249
Jeff Johnson295189b2012-06-20 16:38:30 -07002250 hdd_cleanup_actionframe(pHddCtx, pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07002251
2252 mutex_lock(&pHddCtx->sap_lock);
2253 if(test_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags))
2254 {
Jeff Johnson4416a782013-03-25 14:17:50 -07002255 if ( VOS_STATUS_SUCCESS == (status = WLANSAP_StopBss(pHddCtx->pvosContext) ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07002256 {
2257 hdd_hostapd_state_t *pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
2258
2259 status = vos_wait_single_event(&pHostapdState->vosEvent, 10000);
2260
2261 if (!VOS_IS_STATUS_SUCCESS(status))
2262 {
2263 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2264 ("ERROR: HDD vos wait for single_event failed!!\n"));
2265 VOS_ASSERT(0);
2266 }
2267 }
2268 clear_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags);
2269 }
2270 mutex_unlock(&pHddCtx->sap_lock);
2271
2272 if(status != VOS_STATUS_SUCCESS)
2273 {
2274 hddLog(VOS_TRACE_LEVEL_FATAL,
2275 "%s:Error!!! Stopping the BSS\n",__func__);
2276 return -EINVAL;
2277 }
2278
Jeff Johnson4416a782013-03-25 14:17:50 -07002279 if (ccmCfgSetInt(pHddCtx->hHal,
Jeff Johnson295189b2012-06-20 16:38:30 -07002280 WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG, 0,NULL, eANI_BOOLEAN_FALSE)
2281 ==eHAL_STATUS_FAILURE)
2282 {
2283 hddLog(LOGE,
2284 "Could not pass on WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG to CCM\n");
2285 }
2286
Jeff Johnson4416a782013-03-25 14:17:50 -07002287 if ( eHAL_STATUS_FAILURE == ccmCfgSetInt(pHddCtx->hHal,
Jeff Johnson295189b2012-06-20 16:38:30 -07002288 WNI_CFG_ASSOC_RSP_ADDNIE_FLAG, 0, NULL,
2289 eANI_BOOLEAN_FALSE) )
2290 {
2291 hddLog(LOGE,
2292 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_FLAG to CCM\n");
2293 }
2294
2295 // Reset WNI_CFG_PROBE_RSP Flags
2296 wlan_hdd_reset_prob_rspies(pAdapter);
2297
2298 pAdapter->sessionCtx.ap.beacon = NULL;
2299 kfree(old);
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07002300#ifdef WLAN_FEATURE_P2P_DEBUG
2301 if((pAdapter->device_mode == WLAN_HDD_P2P_GO) &&
2302 (globalP2PConnectionStatus == P2P_GO_COMPLETED_STATE))
2303 {
2304 hddLog(LOGE,"[P2P State] From GO completed to Inactive state "
2305 "GO got removed");
2306 globalP2PConnectionStatus = P2P_NOT_ACTIVE;
2307 }
2308#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002309 }
2310 EXIT();
2311 return status;
2312}
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002313
2314#if (LINUX_VERSION_CODE > KERNEL_VERSION(3,3,0))
2315
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302316static int wlan_hdd_cfg80211_start_ap(struct wiphy *wiphy,
2317 struct net_device *dev,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002318 struct cfg80211_ap_settings *params)
2319{
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302320 hdd_adapter_t *pAdapter;
2321 hdd_context_t *pHddCtx;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302322 int status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002323
2324 ENTER();
2325
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302326 if (NULL == dev)
Madan Mohan Koyyalamudib2c36892012-10-18 20:52:38 -07002327 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302328 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302329 "%s: Device is Null", __func__);
2330 return -ENODEV;
2331 }
2332
2333 pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
2334 if (NULL == pAdapter)
2335 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302336 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302337 "%s: HDD adapter is Null", __func__);
2338 return -ENODEV;
2339 }
2340
2341 if (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic)
2342 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302343 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302344 "%s: HDD adapter magic is invalid", __func__);
2345 return -ENODEV;
2346 }
2347
2348 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302349 status = wlan_hdd_validate_context(pHddCtx);
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302350
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302351 if (0 != status)
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302352 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302353 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2354 "%s: HDD context is not valid", __func__);
2355 return status;
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302356 }
2357
2358 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: device mode = %d",
2359 __func__, pAdapter->device_mode);
2360
2361 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002362 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002363 )
2364 {
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302365 beacon_data_t *old, *new;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002366
2367 old = pAdapter->sessionCtx.ap.beacon;
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302368
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002369 if (old)
2370 return -EALREADY;
2371
2372 status = wlan_hdd_cfg80211_alloc_new_beacon(pAdapter, &new, &params->beacon, params->dtim_period);
2373
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302374 if (status != 0)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002375 {
2376 hddLog(VOS_TRACE_LEVEL_FATAL,
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302377 "%s:Error!!! Allocating the new beacon", __func__);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002378 return -EINVAL;
2379 }
2380 pAdapter->sessionCtx.ap.beacon = new;
Viral Modi3a32cc52013-02-08 11:14:52 -08002381#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
2382 wlan_hdd_cfg80211_set_channel(wiphy, dev, params->channel, params->channel_type);
2383#endif
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002384 status = wlan_hdd_cfg80211_start_bss(pAdapter, &params->beacon, params->ssid,
2385 params->ssid_len, params->hidden_ssid);
Gopichand Nakkala8c0386c2013-07-09 23:31:37 +05302386 if (0 == status)
2387 {
2388 hdd_start_p2p_go_connection_in_progress_timer(pAdapter);
2389 }
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002390 }
2391
2392 EXIT();
2393 return status;
2394}
2395
2396
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302397static int wlan_hdd_cfg80211_change_beacon(struct wiphy *wiphy,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002398 struct net_device *dev,
2399 struct cfg80211_beacon_data *params)
2400{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302401 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302402 hdd_context_t *pHddCtx;
2403 int status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002404
2405 ENTER();
2406
2407 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
2408 __func__, pAdapter->device_mode);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302409
2410 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2411 status = wlan_hdd_validate_context(pHddCtx);
2412
2413 if (0 != status)
Madan Mohan Koyyalamudib2c36892012-10-18 20:52:38 -07002414 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302415 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2416 "%s: HDD context is not valid", __func__);
2417 return status;
Madan Mohan Koyyalamudib2c36892012-10-18 20:52:38 -07002418 }
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002419
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302420 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002421 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302422 )
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002423 {
2424 beacon_data_t *old,*new;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302425
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002426 old = pAdapter->sessionCtx.ap.beacon;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302427
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002428 if (!old)
2429 return -ENOENT;
2430
2431 status = wlan_hdd_cfg80211_alloc_new_beacon(pAdapter, &new, params, 0);
2432
2433 if(status != VOS_STATUS_SUCCESS) {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302434 hddLog(VOS_TRACE_LEVEL_FATAL,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002435 "%s: Error!!! Allocating the new beacon\n",__func__);
2436 return -EINVAL;
2437 }
2438
2439 pAdapter->sessionCtx.ap.beacon = new;
2440
2441 status = wlan_hdd_cfg80211_start_bss(pAdapter, params, NULL, 0, 0);
2442 }
2443
2444 EXIT();
2445 return status;
2446}
2447
2448#endif //(LINUX_VERSION_CODE > KERNEL_VERSION(3,3,0))
2449
Jeff Johnson295189b2012-06-20 16:38:30 -07002450
2451static int wlan_hdd_cfg80211_change_bss (struct wiphy *wiphy,
2452 struct net_device *dev,
2453 struct bss_parameters *params)
2454{
2455 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
2456
2457 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302458
Jeff Johnson295189b2012-06-20 16:38:30 -07002459 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
2460 __func__,pAdapter->device_mode);
2461
2462 if((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002463 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302464 )
Jeff Johnson295189b2012-06-20 16:38:30 -07002465 {
2466 /* ap_isolate == -1 means that in change bss, upper layer doesn't
2467 * want to update this parameter */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302468 if (-1 != params->ap_isolate)
Jeff Johnson295189b2012-06-20 16:38:30 -07002469 {
2470 pAdapter->sessionCtx.ap.apDisableIntraBssFwd = !!params->ap_isolate;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302471 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002472 }
2473
2474 EXIT();
2475 return 0;
2476}
2477
2478/*
2479 * FUNCTION: wlan_hdd_cfg80211_change_iface
2480 * This function is used to set the interface type (INFRASTRUCTURE/ADHOC)
2481 */
2482int wlan_hdd_cfg80211_change_iface( struct wiphy *wiphy,
2483 struct net_device *ndev,
2484 enum nl80211_iftype type,
2485 u32 *flags,
2486 struct vif_params *params
2487 )
2488{
2489 struct wireless_dev *wdev;
2490 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
2491 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
Mohit Khanna0f232092012-09-11 14:46:08 -07002492 hdd_adapter_t *pP2pAdapter = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07002493 tCsrRoamProfile *pRoamProfile = NULL;
2494 eCsrRoamBssType LastBSSType;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302495 hdd_config_t *pConfig = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07002496 eMib_dot11DesiredBssType connectedBssType;
2497 VOS_STATUS status;
2498
2499 ENTER();
2500
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302501 status = wlan_hdd_validate_context(pHddCtx);
2502
2503 if (0 != status)
Jeff Johnson295189b2012-06-20 16:38:30 -07002504 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302505 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2506 "%s: HDD context is not valid", __func__);
2507 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07002508 }
2509
2510 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
2511 __func__, pAdapter->device_mode);
2512
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302513 pConfig = pHddCtx->cfg_ini;
Jeff Johnson295189b2012-06-20 16:38:30 -07002514 wdev = ndev->ieee80211_ptr;
2515
2516#ifdef WLAN_BTAMP_FEATURE
2517 if((NL80211_IFTYPE_P2P_CLIENT == type)||
2518 (NL80211_IFTYPE_ADHOC == type)||
2519 (NL80211_IFTYPE_AP == type)||
2520 (NL80211_IFTYPE_P2P_GO == type))
2521 {
2522 pHddCtx->isAmpAllowed = VOS_FALSE;
2523 // stop AMP traffic
2524 status = WLANBAP_StopAmp();
2525 if(VOS_STATUS_SUCCESS != status )
2526 {
2527 pHddCtx->isAmpAllowed = VOS_TRUE;
2528 hddLog(VOS_TRACE_LEVEL_FATAL,
2529 "%s: Failed to stop AMP", __func__);
2530 return -EINVAL;
2531 }
2532 }
2533#endif //WLAN_BTAMP_FEATURE
2534 /* Reset the current device mode bit mask*/
2535 wlan_hdd_clear_concurrency_mode(pHddCtx, pAdapter->device_mode);
2536
2537 if( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Jeff Johnson295189b2012-06-20 16:38:30 -07002538 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Jeff Johnsone7245742012-09-05 17:12:55 -07002539 || (pAdapter->device_mode == WLAN_HDD_P2P_DEVICE)
Jeff Johnson295189b2012-06-20 16:38:30 -07002540 )
2541 {
2542 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
2543 pRoamProfile = &pWextState->roamProfile;
2544 LastBSSType = pRoamProfile->BSSType;
2545
2546 switch (type)
2547 {
2548 case NL80211_IFTYPE_STATION:
Jeff Johnson295189b2012-06-20 16:38:30 -07002549 case NL80211_IFTYPE_P2P_CLIENT:
Jeff Johnson295189b2012-06-20 16:38:30 -07002550 hddLog(VOS_TRACE_LEVEL_INFO,
2551 "%s: setting interface Type to INFRASTRUCTURE", __func__);
2552 pRoamProfile->BSSType = eCSR_BSS_TYPE_INFRASTRUCTURE;
Jeff Johnsone7245742012-09-05 17:12:55 -07002553#ifdef WLAN_FEATURE_11AC
2554 if(pConfig->dot11Mode == eHDD_DOT11_MODE_AUTO)
2555 {
2556 pConfig->dot11Mode = eHDD_DOT11_MODE_11ac;
2557 }
2558#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302559 pRoamProfile->phyMode =
Jeff Johnsone7245742012-09-05 17:12:55 -07002560 hdd_cfg_xlate_to_csr_phy_mode(pConfig->dot11Mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07002561 wdev->iftype = type;
Gopichand Nakkalaf527dc62012-12-31 16:35:10 -08002562 //Check for sub-string p2p to confirm its a p2p interface
2563 if (NULL != strstr(ndev->name,"p2p"))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302564 {
Gopichand Nakkala864d3552012-12-31 16:08:51 -08002565 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
2566 WLAN_HDD_P2P_DEVICE : WLAN_HDD_P2P_CLIENT;
2567 }
2568 else
2569 {
2570 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
Jeff Johnson295189b2012-06-20 16:38:30 -07002571 WLAN_HDD_INFRA_STATION: WLAN_HDD_P2P_CLIENT;
Gopichand Nakkala864d3552012-12-31 16:08:51 -08002572 }
Madan Mohan Koyyalamudi81746922013-07-17 14:38:51 +05302573#ifdef FEATURE_WLAN_TDLS
2574 /* The open adapter for the p2p shall skip initializations in
2575 * tdls_init if the device mode is WLAN_HDD_P2P_DEVICE, for
2576 * TDLS is supported only on WLAN_HDD_P2P_CLIENT. Hence invoke
2577 * tdls_init when the change_iface sets the device mode to
2578 * WLAN_HDD_P2P_CLIENT.
2579 */
2580
2581 if ( pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
2582 {
2583 if (0 != wlan_hdd_tdls_init (pAdapter))
2584 {
2585 return -EINVAL;
2586 }
2587 }
2588#endif
2589
Jeff Johnson295189b2012-06-20 16:38:30 -07002590 break;
2591 case NL80211_IFTYPE_ADHOC:
2592 hddLog(VOS_TRACE_LEVEL_INFO,
2593 "%s: setting interface Type to ADHOC", __func__);
2594 pRoamProfile->BSSType = eCSR_BSS_TYPE_START_IBSS;
2595 pRoamProfile->phyMode =
2596 hdd_cfg_xlate_to_csr_phy_mode(pConfig->dot11Mode);
Shailender Karmuchia734f332013-04-19 14:02:48 -07002597 pAdapter->device_mode = WLAN_HDD_IBSS;
Jeff Johnson295189b2012-06-20 16:38:30 -07002598 wdev->iftype = type;
2599 break;
2600
2601 case NL80211_IFTYPE_AP:
Jeff Johnson295189b2012-06-20 16:38:30 -07002602 case NL80211_IFTYPE_P2P_GO:
Jeff Johnson295189b2012-06-20 16:38:30 -07002603 {
2604 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
2605 "%s: setting interface Type to %s", __func__,
2606 (type == NL80211_IFTYPE_AP) ? "SoftAP" : "P2pGo");
2607
Gopichand Nakkalaf527dc62012-12-31 16:35:10 -08002608 //Cancel any remain on channel for GO mode
2609 if (NL80211_IFTYPE_P2P_GO == type)
2610 {
2611 wlan_hdd_cancel_existing_remain_on_channel(pAdapter);
2612 }
Mohit Khanna0f232092012-09-11 14:46:08 -07002613 if (NL80211_IFTYPE_AP == type)
2614 {
2615 /* As Loading WLAN Driver one interface being created for p2p device
2616 * address. This will take one HW STA and the max number of clients
2617 * that can connect to softAP will be reduced by one. so while changing
2618 * the interface type to NL80211_IFTYPE_AP (SoftAP) remove p2p0
2619 * interface as it is not required in SoftAP mode.
2620 */
2621
2622 // Get P2P Adapter
2623 pP2pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_P2P_DEVICE);
2624
2625 if (pP2pAdapter)
2626 {
2627 hdd_stop_adapter(pHddCtx, pP2pAdapter);
2628 hdd_deinit_adapter(pHddCtx, pP2pAdapter);
2629 hdd_close_adapter(pHddCtx, pP2pAdapter, VOS_TRUE);
2630 }
2631 }
2632
Jeff Johnson295189b2012-06-20 16:38:30 -07002633 //De-init the adapter.
2634 hdd_stop_adapter( pHddCtx, pAdapter );
2635 hdd_deinit_adapter( pHddCtx, pAdapter );
2636 memset(&pAdapter->sessionCtx, 0, sizeof(pAdapter->sessionCtx));
Jeff Johnson295189b2012-06-20 16:38:30 -07002637 pAdapter->device_mode = (type == NL80211_IFTYPE_AP) ?
2638 WLAN_HDD_SOFTAP : WLAN_HDD_P2P_GO;
Jeff Johnson32d95a32012-09-10 13:15:23 -07002639
2640 //Disable BMPS and IMPS if enabled
2641 //before starting Go
2642 if(WLAN_HDD_P2P_GO == pAdapter->device_mode)
2643 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302644 if(VOS_STATUS_E_FAILURE ==
Jeff Johnson32d95a32012-09-10 13:15:23 -07002645 hdd_disable_bmps_imps(pHddCtx, WLAN_HDD_P2P_GO))
2646 {
2647 //Fail to Exit BMPS
2648 VOS_ASSERT(0);
2649 }
2650 }
2651
Madan Mohan Koyyalamudi3ff2a0b2012-10-15 14:33:46 -07002652 if ((WLAN_HDD_SOFTAP == pAdapter->device_mode) &&
2653 (pConfig->apRandomBssidEnabled))
2654 {
2655 /* To meet Android requirements create a randomized
2656 MAC address of the form 02:1A:11:Fx:xx:xx */
2657 get_random_bytes(&ndev->dev_addr[3], 3);
2658 ndev->dev_addr[0] = 0x02;
2659 ndev->dev_addr[1] = 0x1A;
2660 ndev->dev_addr[2] = 0x11;
2661 ndev->dev_addr[3] |= 0xF0;
2662 memcpy(pAdapter->macAddressCurrent.bytes, ndev->dev_addr,
2663 VOS_MAC_ADDR_SIZE);
2664 pr_info("wlan: Generated HotSpot BSSID "
2665 "%02x:%02x:%02x:%02x:%02x:%02x\n",
2666 ndev->dev_addr[0],
2667 ndev->dev_addr[1],
2668 ndev->dev_addr[2],
2669 ndev->dev_addr[3],
2670 ndev->dev_addr[4],
2671 ndev->dev_addr[5]);
2672 }
2673
Jeff Johnson295189b2012-06-20 16:38:30 -07002674 hdd_set_ap_ops( pAdapter->dev );
2675
2676 status = hdd_init_ap_mode(pAdapter);
2677 if(status != VOS_STATUS_SUCCESS)
2678 {
2679 hddLog(VOS_TRACE_LEVEL_FATAL,
2680 "%s: Error initializing the ap mode", __func__);
2681 return -EINVAL;
2682 }
2683 hdd_set_conparam(1);
2684
Jeff Johnson295189b2012-06-20 16:38:30 -07002685 /*interface type changed update in wiphy structure*/
2686 if(wdev)
2687 {
2688 wdev->iftype = type;
2689 pHddCtx->change_iface = type;
2690 }
2691 else
2692 {
2693 hddLog(VOS_TRACE_LEVEL_ERROR,
2694 "%s: ERROR !!!! Wireless dev is NULL", __func__);
2695 return -EINVAL;
2696 }
2697 goto done;
2698 }
2699
2700 default:
2701 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported interface Type",
2702 __func__);
2703 return -EOPNOTSUPP;
2704 }
2705 }
2706 else if ( (pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002707 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -07002708 )
2709 {
2710 switch(type)
2711 {
2712 case NL80211_IFTYPE_STATION:
Jeff Johnson295189b2012-06-20 16:38:30 -07002713 case NL80211_IFTYPE_P2P_CLIENT:
Jeff Johnson295189b2012-06-20 16:38:30 -07002714 case NL80211_IFTYPE_ADHOC:
Jeff Johnson32d95a32012-09-10 13:15:23 -07002715 hdd_stop_adapter( pHddCtx, pAdapter );
2716 hdd_deinit_adapter( pHddCtx, pAdapter );
Jeff Johnson295189b2012-06-20 16:38:30 -07002717 wdev->iftype = type;
Gopichand Nakkalaf527dc62012-12-31 16:35:10 -08002718 //Check for sub-string p2p to confirm its a p2p interface
2719 if (NULL != strstr(ndev->name,"p2p"))
Gopichand Nakkala864d3552012-12-31 16:08:51 -08002720 {
2721 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
2722 WLAN_HDD_P2P_DEVICE : WLAN_HDD_P2P_CLIENT;
2723 }
2724 else
2725 {
2726 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
Jeff Johnson295189b2012-06-20 16:38:30 -07002727 WLAN_HDD_INFRA_STATION: WLAN_HDD_P2P_CLIENT;
Gopichand Nakkala864d3552012-12-31 16:08:51 -08002728 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002729 hdd_set_conparam(0);
2730 pHddCtx->change_iface = type;
Jeff Johnson295189b2012-06-20 16:38:30 -07002731 memset(&pAdapter->sessionCtx, 0, sizeof(pAdapter->sessionCtx));
2732 hdd_set_station_ops( pAdapter->dev );
2733 status = hdd_init_station_mode( pAdapter );
2734 if( VOS_STATUS_SUCCESS != status )
2735 return -EOPNOTSUPP;
Jeff Johnsone7245742012-09-05 17:12:55 -07002736 /* In case of JB, for P2P-GO, only change interface will be called,
2737 * This is the right place to enable back bmps_imps()
2738 */
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05302739 if (pHddCtx->hdd_wlan_suspended)
2740 {
2741 hdd_set_pwrparams(pHddCtx);
2742 }
Jeff Johnsone7245742012-09-05 17:12:55 -07002743 hdd_enable_bmps_imps(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07002744 goto done;
2745 case NL80211_IFTYPE_AP:
Jeff Johnson295189b2012-06-20 16:38:30 -07002746 case NL80211_IFTYPE_P2P_GO:
Jeff Johnson295189b2012-06-20 16:38:30 -07002747 wdev->iftype = type;
Jeff Johnson295189b2012-06-20 16:38:30 -07002748 pAdapter->device_mode = (type == NL80211_IFTYPE_AP) ?
2749 WLAN_HDD_SOFTAP : WLAN_HDD_P2P_GO;
Jeff Johnson295189b2012-06-20 16:38:30 -07002750 goto done;
2751 default:
2752 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported interface Type",
2753 __func__);
2754 return -EOPNOTSUPP;
2755
2756 }
2757
2758 }
2759 else
2760 {
2761 return -EOPNOTSUPP;
2762 }
2763
2764
2765 if(pRoamProfile)
2766 {
2767 if ( LastBSSType != pRoamProfile->BSSType )
2768 {
2769 /*interface type changed update in wiphy structure*/
2770 wdev->iftype = type;
2771
2772 /*the BSS mode changed, We need to issue disconnect
2773 if connected or in IBSS disconnect state*/
2774 if ( hdd_connGetConnectedBssType(
2775 WLAN_HDD_GET_STATION_CTX_PTR(pAdapter), &connectedBssType ) ||
2776 ( eCSR_BSS_TYPE_START_IBSS == LastBSSType ) )
2777 {
2778 /*need to issue a disconnect to CSR.*/
2779 INIT_COMPLETION(pAdapter->disconnect_comp_var);
2780 if( eHAL_STATUS_SUCCESS ==
2781 sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
2782 pAdapter->sessionId,
2783 eCSR_DISCONNECT_REASON_UNSPECIFIED ) )
2784 {
2785 wait_for_completion_interruptible_timeout(
2786 &pAdapter->disconnect_comp_var,
2787 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
2788 }
2789 }
2790 }
2791 }
2792
2793done:
2794 /*set bitmask based on updated value*/
2795 wlan_hdd_set_concurrency_mode(pHddCtx, pAdapter->device_mode);
Leo Chang6fe1f922013-06-07 19:21:24 -07002796
2797 /* Only STA mode support TM now
2798 * all other mode, TM feature should be disabled */
2799 if ( (pHddCtx->cfg_ini->thermalMitigationEnable) &&
2800 (~VOS_STA & pHddCtx->concurrency_mode) )
2801 {
2802 hddDevTmLevelChangedHandler(pHddCtx->parent_dev, 0);
2803 }
2804
Jeff Johnson295189b2012-06-20 16:38:30 -07002805#ifdef WLAN_BTAMP_FEATURE
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302806 if((NL80211_IFTYPE_STATION == type) && (pHddCtx->concurrency_mode <= 1) &&
Jeff Johnson295189b2012-06-20 16:38:30 -07002807 (pHddCtx->no_of_sessions[WLAN_HDD_INFRA_STATION] <=1))
2808 {
2809 //we are ok to do AMP
2810 pHddCtx->isAmpAllowed = VOS_TRUE;
2811 }
2812#endif //WLAN_BTAMP_FEATURE
2813 EXIT();
2814 return 0;
2815}
2816
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002817#ifdef FEATURE_WLAN_TDLS
2818static int wlan_hdd_tdls_add_station(struct wiphy *wiphy,
2819 struct net_device *dev, u8 *mac, bool update, tCsrStaParams *StaParams)
2820{
2821 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
2822 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
2823 VOS_STATUS status;
Hoonki Lee5305c3a2013-04-29 23:28:59 -07002824 hddTdlsPeer_t *pTdlsPeer;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002825
2826 ENTER();
2827
Gopichand Nakkala838be5d2013-04-10 22:41:51 +05302828 if (NULL == pHddCtx || NULL == pHddCtx->cfg_ini)
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002829 {
2830 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2831 "Invalid arguments");
2832 return -EINVAL;
2833 }
Hoonki Lee27511902013-03-14 18:19:06 -07002834
2835 if ((eTDLS_SUPPORT_NOT_ENABLED == pHddCtx->tdls_mode) ||
2836 (eTDLS_SUPPORT_DISABLED == pHddCtx->tdls_mode))
2837 {
2838 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
2839 "%s: TDLS mode is disabled OR not enabled in FW."
2840 MAC_ADDRESS_STR " Request declined.",
2841 __func__, MAC_ADDR_ARRAY(mac));
2842 return -ENOTSUPP;
2843 }
2844
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002845 if (pHddCtx->isLogpInProgress)
2846 {
2847 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2848 "%s:LOGP in Progress. Ignore!!!", __func__);
Gopichand Nakkala05922802013-03-14 12:23:19 -07002849 wlan_hdd_tdls_set_link_status(pAdapter, mac, eTDLS_LINK_IDLE);
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002850 return -EBUSY;
2851 }
2852
Hoonki Lee5305c3a2013-04-29 23:28:59 -07002853 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, mac);
2854
2855 if ( NULL == pTdlsPeer ) {
2856 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
2857 "%s: " MAC_ADDRESS_STR " (update %d) not exist. return invalid",
2858 __func__, MAC_ADDR_ARRAY(mac), update);
2859 return -EINVAL;
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002860 }
Hoonki Lee5305c3a2013-04-29 23:28:59 -07002861
2862 /* in add station, we accept existing valid staId if there is */
2863 if ((0 == update) &&
2864 ((pTdlsPeer->link_status >= eTDLS_LINK_CONNECTING) ||
2865 (TDLS_STA_INDEX_VALID(pTdlsPeer->staId))))
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07002866 {
Hoonki Lee5305c3a2013-04-29 23:28:59 -07002867 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07002868 "%s: " MAC_ADDRESS_STR
Hoonki Lee5305c3a2013-04-29 23:28:59 -07002869 " link_status %d. staId %d. add station ignored.",
2870 __func__, MAC_ADDR_ARRAY(mac), pTdlsPeer->link_status, pTdlsPeer->staId);
2871 return 0;
2872 }
2873 /* in change station, we accept only when staId is valid */
2874 if ((1 == update) &&
2875 ((pTdlsPeer->link_status > eTDLS_LINK_CONNECTING) ||
2876 (!TDLS_STA_INDEX_VALID(pTdlsPeer->staId))))
2877 {
2878 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
2879 "%s: " MAC_ADDRESS_STR
2880 " link status %d. staId %d. change station %s.",
2881 __func__, MAC_ADDR_ARRAY(mac), pTdlsPeer->link_status, pTdlsPeer->staId,
2882 (TDLS_STA_INDEX_VALID(pTdlsPeer->staId)) ? "ignored" : "declined");
2883 return (TDLS_STA_INDEX_VALID(pTdlsPeer->staId)) ? 0 : -EPERM;
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07002884 }
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002885
2886 /* when others are on-going, we want to change link_status to idle */
Hoonki Leefb8df672013-04-10 18:20:34 -07002887 if (NULL != wlan_hdd_tdls_is_progress(pHddCtx, mac, TRUE, TRUE))
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002888 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07002889 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2890 "%s: " MAC_ADDRESS_STR
2891 " TDLS setup is ongoing. Request declined.",
2892 __func__, MAC_ADDR_ARRAY(mac));
Gopichand Nakkala05922802013-03-14 12:23:19 -07002893 goto error;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002894 }
2895
2896 /* first to check if we reached to maximum supported TDLS peer.
2897 TODO: for now, return -EPERM looks working fine,
2898 but need to check if any other errno fit into this category.*/
2899 if (HDD_MAX_NUM_TDLS_STA <= wlan_hdd_tdlsConnectedPeers(pAdapter))
2900 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07002901 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2902 "%s: " MAC_ADDRESS_STR
2903 " TDLS Max peer already connected. Request declined.",
2904 __func__, MAC_ADDR_ARRAY(mac));
Gopichand Nakkala05922802013-03-14 12:23:19 -07002905 goto error;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002906 }
2907 else
2908 {
2909 hddTdlsPeer_t *pTdlsPeer;
2910 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, mac);
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07002911 if (pTdlsPeer && TDLS_IS_CONNECTED(pTdlsPeer))
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002912 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07002913 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2914 "%s: " MAC_ADDRESS_STR " already connected. Request declined.",
2915 __func__, MAC_ADDR_ARRAY(mac));
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002916 return -EPERM;
2917 }
2918 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07002919 if (0 == update)
2920 wlan_hdd_tdls_set_link_status(pAdapter, mac, eTDLS_LINK_CONNECTING);
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002921
Jeff Johnsond75fe012013-04-06 10:53:06 -07002922 /* debug code */
Gopichand Nakkala838be5d2013-04-10 22:41:51 +05302923 if (NULL != StaParams)
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07002924 {
2925 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
2926 "%s: TDLS Peer Parameters.", __func__);
Hoonki Lee66b75f32013-04-16 18:30:07 -07002927 if(StaParams->htcap_present)
2928 {
2929 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
2930 "ht_capa->cap_info: %0x", StaParams->HTCap.capInfo);
2931 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
2932 "ht_capa->extended_capabilities: %0x",
2933 StaParams->HTCap.extendedHtCapInfo);
2934 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07002935 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
2936 "params->capability: %0x",StaParams->capability);
2937 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
2938 "params->ext_capab_len: %0x",StaParams->extn_capability);
Hoonki Lee66b75f32013-04-16 18:30:07 -07002939 if(StaParams->vhtcap_present)
2940 {
2941 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
2942 "rxMcsMap %x rxHighest %x txMcsMap %x txHighest %x",
2943 StaParams->VHTCap.suppMcs.rxMcsMap, StaParams->VHTCap.suppMcs.rxHighest,
2944 StaParams->VHTCap.suppMcs.txMcsMap, StaParams->VHTCap.suppMcs.txHighest);
2945 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07002946 {
2947 int i = 0;
Hoonki Lee5305c3a2013-04-29 23:28:59 -07002948 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "Supported rates:");
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07002949 for (i = 0; i < sizeof(StaParams->supported_rates); i++)
2950 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
2951 "[%d]: %x ", i, StaParams->supported_rates[i]);
2952 }
Jeff Johnsond75fe012013-04-06 10:53:06 -07002953 } /* end debug code */
Gopichand Nakkala838be5d2013-04-10 22:41:51 +05302954 else if ((1 == update) && (NULL == StaParams))
2955 {
2956 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2957 "%s : update is true, but staParams is NULL. Error!", __func__);
2958 return -EPERM;
2959 }
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002960
2961 INIT_COMPLETION(pAdapter->tdls_add_station_comp);
2962
2963 if (!update)
2964 {
2965 status = sme_AddTdlsPeerSta(WLAN_HDD_GET_HAL_CTX(pAdapter),
2966 pAdapter->sessionId, mac);
2967 }
2968 else
2969 {
2970 status = sme_ChangeTdlsPeerSta(WLAN_HDD_GET_HAL_CTX(pAdapter),
2971 pAdapter->sessionId, mac, StaParams);
2972 }
2973
2974 status = wait_for_completion_interruptible_timeout(&pAdapter->tdls_add_station_comp,
2975 msecs_to_jiffies(WAIT_TIME_TDLS_ADD_STA));
2976
2977 if (!status)
2978 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07002979 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002980 "%s: timeout waiting for tdls add station indication",
2981 __func__);
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002982 return -EPERM;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002983 }
2984 if ( eHAL_STATUS_SUCCESS != pAdapter->tdlsAddStaStatus)
2985 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07002986 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002987 "%s: Add Station is unsucessful", __func__);
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002988 return -EPERM;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002989 }
2990
2991 return 0;
Gopichand Nakkala05922802013-03-14 12:23:19 -07002992
2993error:
2994 wlan_hdd_tdls_set_link_status(pAdapter, mac, eTDLS_LINK_IDLE);
2995 return -EPERM;
2996
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002997}
2998#endif
2999
Jeff Johnson295189b2012-06-20 16:38:30 -07003000static int wlan_hdd_change_station(struct wiphy *wiphy,
3001 struct net_device *dev,
3002 u8 *mac,
3003 struct station_parameters *params)
3004{
3005 VOS_STATUS status = VOS_STATUS_SUCCESS;
3006 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Gopichand Nakkala29149562013-05-10 21:43:41 +05303007 hdd_context_t *pHddCtx;
3008 hdd_station_ctx_t *pHddStaCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07003009 v_MACADDR_t STAMacAddress;
Gopichand Nakkalab0856222013-03-12 22:39:05 -07003010#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003011 tCsrStaParams StaParams = {0};
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003012 tANI_U8 isBufSta = 0;
Gopichand Nakkalab0856222013-03-12 22:39:05 -07003013#endif
Jeff Johnsone7245742012-09-05 17:12:55 -07003014 ENTER();
3015
Gopichand Nakkala29149562013-05-10 21:43:41 +05303016 if ((NULL == pAdapter))
3017 {
3018 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
3019 "invalid adapter ");
3020 return -EINVAL;
3021 }
3022
3023 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
3024 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3025
3026 if ((NULL == pHddCtx) || (NULL == pHddStaCtx))
3027 {
3028 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
3029 "invalid HDD state or HDD station context");
3030 return -EINVAL;
3031 }
3032
3033 if (pHddCtx->isLogpInProgress)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003034 {
3035 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3036 "%s:LOGP in Progress. Ignore!!!", __func__);
3037 return -EAGAIN;
3038 }
3039
Jeff Johnson295189b2012-06-20 16:38:30 -07003040 vos_mem_copy(STAMacAddress.bytes, mac, sizeof(v_MACADDR_t));
3041
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003042 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
3043 || (pAdapter->device_mode == WLAN_HDD_P2P_GO))
Jeff Johnson295189b2012-06-20 16:38:30 -07003044 {
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003045 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED))
Jeff Johnson295189b2012-06-20 16:38:30 -07003046 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303047 status = hdd_softap_change_STA_state( pAdapter, &STAMacAddress,
Jeff Johnson295189b2012-06-20 16:38:30 -07003048 WLANTL_STA_AUTHENTICATED);
3049
Gopichand Nakkala29149562013-05-10 21:43:41 +05303050 if (status != VOS_STATUS_SUCCESS)
3051 {
3052 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3053 "%s: Not able to change TL state to AUTHENTICATED", __func__);
3054 return -EINVAL;
3055 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003056 }
3057 }
Hoonki Leea6d49be2013-04-05 09:43:25 -07003058 else if ((pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
3059 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)) {
Gopichand Nakkala29149562013-05-10 21:43:41 +05303060#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003061 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
3062 StaParams.capability = params->capability;
3063 StaParams.uapsd_queues = params->uapsd_queues;
3064 StaParams.max_sp = params->max_sp;
3065
3066 if (0 != params->ext_capab_len)
3067 vos_mem_copy(StaParams.extn_capability, params->ext_capab,
3068 sizeof(StaParams.extn_capability));
3069
3070 if (NULL != params->ht_capa)
Hoonki Lee66b75f32013-04-16 18:30:07 -07003071 {
3072 StaParams.htcap_present = 1;
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003073 vos_mem_copy(&StaParams.HTCap, params->ht_capa, sizeof(tSirHTCap));
Hoonki Lee66b75f32013-04-16 18:30:07 -07003074 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003075
3076 StaParams.supported_rates_len = params->supported_rates_len;
3077
3078 /* Note : The Maximum sizeof supported_rates sent by the Supplicant is 32.
3079 * The supported_rates array , for all the structures propogating till Add Sta
3080 * to the firmware has to be modified , if the supplicant (ieee80211) is
3081 * modified to send more rates.
3082 */
3083
3084 /* To avoid Data Currption , set to max length to SIR_MAC_MAX_SUPP_RATES
3085 */
3086 if (StaParams.supported_rates_len > SIR_MAC_MAX_SUPP_RATES)
3087 StaParams.supported_rates_len = SIR_MAC_MAX_SUPP_RATES;
3088
3089 if (0 != StaParams.supported_rates_len) {
3090 int i = 0;
3091 vos_mem_copy(StaParams.supported_rates, params->supported_rates,
3092 StaParams.supported_rates_len);
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003093 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003094 "Supported Rates with Length %d", StaParams.supported_rates_len);
3095 for (i=0; i < StaParams.supported_rates_len; i++)
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003096 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003097 "[%d]: %0x", i, StaParams.supported_rates[i]);
3098 }
3099
3100 if (NULL != params->vht_capa)
Hoonki Lee66b75f32013-04-16 18:30:07 -07003101 {
3102 StaParams.vhtcap_present = 1;
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003103 vos_mem_copy(&StaParams.VHTCap, params->vht_capa, sizeof(tSirVHTCap));
Hoonki Lee66b75f32013-04-16 18:30:07 -07003104 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003105
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003106 if (0 != params->ext_capab_len ) {
3107 /*Define A Macro : TODO Sunil*/
3108 if ((1<<4) & StaParams.extn_capability[3]) {
3109 isBufSta = 1;
3110 }
3111 }
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05303112 status = wlan_hdd_tdls_set_peer_caps( pAdapter, mac, params->uapsd_queues,
3113 params->max_sp, isBufSta);
3114 if (VOS_STATUS_SUCCESS != status) {
3115 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3116 "%s: wlan_hdd_tdls_set_peer_caps failed!", __func__);
3117 return -EINVAL;
3118 }
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003119 status = wlan_hdd_tdls_add_station(wiphy, dev, mac, 1, &StaParams);
3120
3121 if (VOS_STATUS_SUCCESS != status) {
3122 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3123 "%s: sme_ChangeTdlsPeerSta failed!", __func__);
3124 return -EINVAL;
3125 }
3126 }
Gopichand Nakkalab0856222013-03-12 22:39:05 -07003127#endif
Gopichand Nakkala6239acd2013-06-14 14:48:00 +05303128 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003129 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07003130 return status;
3131}
3132
3133/*
Jeff Johnson295189b2012-06-20 16:38:30 -07003134 * FUNCTION: wlan_hdd_cfg80211_add_key
3135 * This function is used to initialize the key information
3136 */
3137#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003138static int wlan_hdd_cfg80211_add_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003139 struct net_device *ndev,
3140 u8 key_index, bool pairwise,
3141 const u8 *mac_addr,
3142 struct key_params *params
3143 )
3144#else
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003145static int wlan_hdd_cfg80211_add_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003146 struct net_device *ndev,
3147 u8 key_index, const u8 *mac_addr,
3148 struct key_params *params
3149 )
3150#endif
3151{
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003152 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Jeff Johnson295189b2012-06-20 16:38:30 -07003153 tCsrRoamSetKey setKey;
3154 u8 groupmacaddr[WNI_CFG_BSSID_LEN] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303155 int status;
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003156 v_U32_t roamId= 0xFF;
3157 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
Jeff Johnson295189b2012-06-20 16:38:30 -07003158 hdd_hostapd_state_t *pHostapdState;
3159 VOS_STATUS vos_status;
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003160 eHalStatus halStatus;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303161 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07003162
3163 ENTER();
3164
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303165 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
3166 status = wlan_hdd_validate_context(pHddCtx);
3167
3168 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003169 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303170 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3171 "%s: HDD context is not valid", __func__);
3172 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003173 }
3174
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003175 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
3176 __func__, pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07003177
3178 if (CSR_MAX_NUM_KEY <= key_index)
3179 {
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003180 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key index %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07003181 key_index);
3182
3183 return -EINVAL;
3184 }
3185
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003186 if (CSR_MAX_KEY_LEN < params->key_len)
3187 {
3188 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key length %d", __func__,
3189 params->key_len);
3190
3191 return -EINVAL;
3192 }
3193
3194 hddLog(VOS_TRACE_LEVEL_INFO,
3195 "%s: called with key index = %d & key length %d",
3196 __func__, key_index, params->key_len);
Jeff Johnson295189b2012-06-20 16:38:30 -07003197
3198 /*extract key idx, key len and key*/
3199 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
3200 setKey.keyId = key_index;
3201 setKey.keyLength = params->key_len;
3202 vos_mem_copy(&setKey.Key[0],params->key, params->key_len);
3203
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003204 switch (params->cipher)
Jeff Johnson295189b2012-06-20 16:38:30 -07003205 {
3206 case WLAN_CIPHER_SUITE_WEP40:
3207 setKey.encType = eCSR_ENCRYPT_TYPE_WEP40_STATICKEY;
3208 break;
3209
3210 case WLAN_CIPHER_SUITE_WEP104:
3211 setKey.encType = eCSR_ENCRYPT_TYPE_WEP104_STATICKEY;
3212 break;
3213
3214 case WLAN_CIPHER_SUITE_TKIP:
3215 {
3216 u8 *pKey = &setKey.Key[0];
3217 setKey.encType = eCSR_ENCRYPT_TYPE_TKIP;
3218
3219 vos_mem_zero(pKey, CSR_MAX_KEY_LEN);
3220
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003221 /*Supplicant sends the 32bytes key in this order
Jeff Johnson295189b2012-06-20 16:38:30 -07003222
3223 |--------------|----------|----------|
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003224 | Tk1 |TX-MIC | RX Mic |
Jeff Johnson295189b2012-06-20 16:38:30 -07003225 |--------------|----------|----------|
3226 <---16bytes---><--8bytes--><--8bytes-->
3227
3228 */
3229 /*Sme expects the 32 bytes key to be in the below order
3230
3231 |--------------|----------|----------|
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003232 | Tk1 |RX-MIC | TX Mic |
Jeff Johnson295189b2012-06-20 16:38:30 -07003233 |--------------|----------|----------|
3234 <---16bytes---><--8bytes--><--8bytes-->
3235 */
3236 /* Copy the Temporal Key 1 (TK1) */
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003237 vos_mem_copy(pKey, params->key, 16);
Jeff Johnson295189b2012-06-20 16:38:30 -07003238
3239 /*Copy the rx mic first*/
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003240 vos_mem_copy(&pKey[16], &params->key[24], 8);
Jeff Johnson295189b2012-06-20 16:38:30 -07003241
3242 /*Copy the tx mic */
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003243 vos_mem_copy(&pKey[24], &params->key[16], 8);
Jeff Johnson295189b2012-06-20 16:38:30 -07003244
3245
3246 break;
3247 }
3248
3249 case WLAN_CIPHER_SUITE_CCMP:
3250 setKey.encType = eCSR_ENCRYPT_TYPE_AES;
3251 break;
3252
3253#ifdef FEATURE_WLAN_WAPI
3254 case WLAN_CIPHER_SUITE_SMS4:
3255 {
3256 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
3257 wlan_hdd_cfg80211_set_key_wapi(pAdapter, key_index, mac_addr,
3258 params->key, params->key_len);
3259 return 0;
3260 }
3261#endif
Chet Lanctot186b5732013-03-18 10:26:30 -07003262
Jeff Johnson295189b2012-06-20 16:38:30 -07003263#ifdef FEATURE_WLAN_CCX
3264 case WLAN_CIPHER_SUITE_KRK:
3265 setKey.encType = eCSR_ENCRYPT_TYPE_KRK;
3266 break;
3267#endif
Chet Lanctot186b5732013-03-18 10:26:30 -07003268
3269#ifdef WLAN_FEATURE_11W
3270 case WLAN_CIPHER_SUITE_AES_CMAC:
3271 setKey.encType = eCSR_ENCRYPT_TYPE_AES_CMAC;
Chet Lanctot3b5158a2013-03-31 16:45:21 -07003272 break;
Chet Lanctot186b5732013-03-18 10:26:30 -07003273#endif
3274
Jeff Johnson295189b2012-06-20 16:38:30 -07003275 default:
3276 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: unsupported cipher type %lu",
3277 __func__, params->cipher);
3278 return -EOPNOTSUPP;
3279 }
3280
3281 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: encryption type %d",
3282 __func__, setKey.encType);
3283
Shailender Karmuchi642e9812013-05-30 14:34:49 -07003284 if (
Jeff Johnson295189b2012-06-20 16:38:30 -07003285#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
3286 (!pairwise)
3287#else
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003288 (!mac_addr || is_broadcast_ether_addr(mac_addr))
Jeff Johnson295189b2012-06-20 16:38:30 -07003289#endif
Shailender Karmuchi642e9812013-05-30 14:34:49 -07003290 )
3291 {
3292 /* set group key*/
3293 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3294 "%s- %d: setting Broadcast key",
3295 __func__, __LINE__);
3296 setKey.keyDirection = eSIR_RX_ONLY;
3297 vos_mem_copy(setKey.peerMac,groupmacaddr,WNI_CFG_BSSID_LEN);
3298 }
3299 else
3300 {
3301 /* set pairwise key*/
3302 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3303 "%s- %d: setting pairwise key",
3304 __func__, __LINE__);
3305 setKey.keyDirection = eSIR_TX_RX;
3306 vos_mem_copy(setKey.peerMac, mac_addr,WNI_CFG_BSSID_LEN);
3307 }
3308 if ((WLAN_HDD_IBSS == pAdapter->device_mode) && !pairwise)
3309 {
3310 setKey.keyDirection = eSIR_TX_RX;
3311 /*Set the group key*/
3312 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
3313 pAdapter->sessionId, &setKey, &roamId );
Jeff Johnson295189b2012-06-20 16:38:30 -07003314
Shailender Karmuchi642e9812013-05-30 14:34:49 -07003315 if ( 0 != status )
3316 {
3317 hddLog(VOS_TRACE_LEVEL_ERROR,
3318 "%s: sme_RoamSetKey failed, returned %d", __func__, status);
3319 return -EINVAL;
3320 }
3321 /*Save the keys here and call sme_RoamSetKey for setting
3322 the PTK after peer joins the IBSS network*/
3323 vos_mem_copy(&pAdapter->sessionCtx.station.ibss_enc_key,
3324 &setKey, sizeof(tCsrRoamSetKey));
3325 return status;
3326 }
Gopichand Nakkala29149562013-05-10 21:43:41 +05303327 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP) ||
3328 (pAdapter->device_mode == WLAN_HDD_P2P_GO))
3329 {
Jeff Johnson295189b2012-06-20 16:38:30 -07003330 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003331 if( pHostapdState->bssState == BSS_START )
3332 {
Jeff Johnson295189b2012-06-20 16:38:30 -07003333 status = WLANSAP_SetKeySta( pVosContext, &setKey);
3334
3335 if ( status != eHAL_STATUS_SUCCESS )
3336 {
3337 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3338 "[%4d] WLANSAP_SetKeySta returned ERROR status= %d",
3339 __LINE__, status );
3340 }
3341 }
3342
3343 /* Saving WEP keys */
3344 else if( eCSR_ENCRYPT_TYPE_WEP40_STATICKEY == setKey.encType ||
3345 eCSR_ENCRYPT_TYPE_WEP104_STATICKEY == setKey.encType )
3346 {
3347 //Save the wep key in ap context. Issue setkey after the BSS is started.
3348 hdd_ap_ctx_t *pAPCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
3349 vos_mem_copy(&pAPCtx->wepKey[key_index], &setKey, sizeof(tCsrRoamSetKey));
3350 }
3351 else
3352 {
3353 //Save the key in ap context. Issue setkey after the BSS is started.
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003354 hdd_ap_ctx_t *pAPCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07003355 vos_mem_copy(&pAPCtx->groupKey, &setKey, sizeof(tCsrRoamSetKey));
3356 }
3357 }
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003358 else if ( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION) ||
3359 (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003360 {
3361 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
3362 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3363
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303364#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
3365 if (!pairwise)
3366#else
3367 if (!mac_addr || is_broadcast_ether_addr(mac_addr))
3368#endif
3369 {
3370 /* set group key*/
3371 if (pHddStaCtx->roam_info.deferKeyComplete)
3372 {
3373 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3374 "%s- %d: Perform Set key Complete",
3375 __func__, __LINE__);
3376 hdd_PerformRoamSetKeyComplete(pAdapter);
3377 }
3378 }
3379
Jeff Johnson295189b2012-06-20 16:38:30 -07003380 pWextState->roamProfile.Keys.KeyLength[key_index] = (u8)params->key_len;
3381
Venkata Prathyusha Kuntupalliee2ce712013-01-17 14:09:24 -08003382 pWextState->roamProfile.Keys.defaultIndex = key_index;
3383
3384
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003385 vos_mem_copy(&pWextState->roamProfile.Keys.KeyMaterial[key_index][0],
Jeff Johnson295189b2012-06-20 16:38:30 -07003386 params->key, params->key_len);
3387
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303388
Jeff Johnson295189b2012-06-20 16:38:30 -07003389 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_SETTING_KEY;
3390
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303391 hddLog(VOS_TRACE_LEVEL_INFO_MED,
Jeff Johnson295189b2012-06-20 16:38:30 -07003392 "%s: set key for peerMac %2x:%2x:%2x:%2x:%2x:%2x, direction %d",
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303393 __func__, setKey.peerMac[0], setKey.peerMac[1],
3394 setKey.peerMac[2], setKey.peerMac[3],
3395 setKey.peerMac[4], setKey.peerMac[5],
Jeff Johnson295189b2012-06-20 16:38:30 -07003396 setKey.keyDirection);
3397
3398 vos_status = wlan_hdd_check_ula_done(pAdapter);
3399
3400 if ( vos_status != VOS_STATUS_SUCCESS )
3401 {
3402 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3403 "[%4d] wlan_hdd_check_ula_done returned ERROR status= %d",
3404 __LINE__, vos_status );
3405
3406 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3407
3408 return -EINVAL;
3409
3410 }
3411
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003412#ifdef WLAN_FEATURE_VOWIFI_11R
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303413 /* The supplicant may attempt to set the PTK once pre-authentication
3414 is done. Save the key in the UMAC and include it in the ADD BSS
3415 request */
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003416 halStatus = sme_FTUpdateKey( WLAN_HDD_GET_HAL_CTX(pAdapter), &setKey);
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303417 if ( halStatus == eHAL_STATUS_FT_PREAUTH_KEY_SUCCESS )
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003418 {
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303419 hddLog(VOS_TRACE_LEVEL_INFO_MED,
3420 "%s: Update PreAuth Key success", __func__);
3421 return 0;
3422 }
3423 else if ( halStatus == eHAL_STATUS_FT_PREAUTH_KEY_FAILED )
3424 {
3425 hddLog(VOS_TRACE_LEVEL_ERROR,
3426 "%s: Update PreAuth Key failed", __func__);
Gopichand Nakkalad7d13652013-02-15 01:48:00 +05303427 return -EINVAL;
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003428 }
3429#endif /* WLAN_FEATURE_VOWIFI_11R */
Jeff Johnson295189b2012-06-20 16:38:30 -07003430
3431 /* issue set key request to SME*/
3432 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
3433 pAdapter->sessionId, &setKey, &roamId );
3434
3435 if ( 0 != status )
3436 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303437 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07003438 "%s: sme_RoamSetKey failed, returned %d", __func__, status);
3439 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3440 return -EINVAL;
3441 }
3442
3443
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303444 /* in case of IBSS as there was no information available about WEP keys during
3445 * IBSS join, group key intialized with NULL key, so re-initialize group key
Jeff Johnson295189b2012-06-20 16:38:30 -07003446 * with correct value*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303447 if ( (eCSR_BSS_TYPE_START_IBSS == pWextState->roamProfile.BSSType) &&
3448 !( ( IW_AUTH_KEY_MGMT_802_1X
3449 == (pWextState->authKeyMgmt & IW_AUTH_KEY_MGMT_802_1X))
Jeff Johnson295189b2012-06-20 16:38:30 -07003450 && (eCSR_AUTH_TYPE_OPEN_SYSTEM == pHddStaCtx->conn_info.authType)
3451 )
3452 &&
3453 ( (WLAN_CIPHER_SUITE_WEP40 == params->cipher)
3454 || (WLAN_CIPHER_SUITE_WEP104 == params->cipher)
3455 )
3456 )
3457 {
3458 setKey.keyDirection = eSIR_RX_ONLY;
3459 vos_mem_copy(setKey.peerMac,groupmacaddr,WNI_CFG_BSSID_LEN);
3460
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303461 hddLog(VOS_TRACE_LEVEL_INFO_MED,
Jeff Johnson295189b2012-06-20 16:38:30 -07003462 "%s: set key peerMac %2x:%2x:%2x:%2x:%2x:%2x, direction %d",
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303463 __func__, setKey.peerMac[0], setKey.peerMac[1],
3464 setKey.peerMac[2], setKey.peerMac[3],
3465 setKey.peerMac[4], setKey.peerMac[5],
Jeff Johnson295189b2012-06-20 16:38:30 -07003466 setKey.keyDirection);
3467
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303468 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07003469 pAdapter->sessionId, &setKey, &roamId );
3470
3471 if ( 0 != status )
3472 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303473 hddLog(VOS_TRACE_LEVEL_ERROR,
3474 "%s: sme_RoamSetKey failed for group key (IBSS), returned %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07003475 __func__, status);
3476 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3477 return -EINVAL;
3478 }
3479 }
3480 }
3481
3482 return 0;
3483}
3484
3485/*
3486 * FUNCTION: wlan_hdd_cfg80211_get_key
3487 * This function is used to get the key information
3488 */
3489#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303490static int wlan_hdd_cfg80211_get_key(
3491 struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003492 struct net_device *ndev,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303493 u8 key_index, bool pairwise,
Jeff Johnson295189b2012-06-20 16:38:30 -07003494 const u8 *mac_addr, void *cookie,
3495 void (*callback)(void *cookie, struct key_params*)
3496 )
3497#else
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303498static int wlan_hdd_cfg80211_get_key(
3499 struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003500 struct net_device *ndev,
3501 u8 key_index, const u8 *mac_addr, void *cookie,
3502 void (*callback)(void *cookie, struct key_params*)
3503 )
3504#endif
3505{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303506 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Jeff Johnson295189b2012-06-20 16:38:30 -07003507 hdd_wext_state_t *pWextState= WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
3508 tCsrRoamProfile *pRoamProfile = &(pWextState->roamProfile);
3509 struct key_params params;
3510
3511 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303512
Jeff Johnson295189b2012-06-20 16:38:30 -07003513 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
3514 __func__,pAdapter->device_mode);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303515
Jeff Johnson295189b2012-06-20 16:38:30 -07003516 memset(&params, 0, sizeof(params));
3517
3518 if (CSR_MAX_NUM_KEY <= key_index)
3519 {
3520 return -EINVAL;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303521 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003522
3523 switch(pRoamProfile->EncryptionType.encryptionType[0])
3524 {
3525 case eCSR_ENCRYPT_TYPE_NONE:
3526 params.cipher = IW_AUTH_CIPHER_NONE;
3527 break;
3528
3529 case eCSR_ENCRYPT_TYPE_WEP40_STATICKEY:
3530 case eCSR_ENCRYPT_TYPE_WEP40:
3531 params.cipher = WLAN_CIPHER_SUITE_WEP40;
3532 break;
3533
3534 case eCSR_ENCRYPT_TYPE_WEP104_STATICKEY:
3535 case eCSR_ENCRYPT_TYPE_WEP104:
3536 params.cipher = WLAN_CIPHER_SUITE_WEP104;
3537 break;
3538
3539 case eCSR_ENCRYPT_TYPE_TKIP:
3540 params.cipher = WLAN_CIPHER_SUITE_TKIP;
3541 break;
3542
3543 case eCSR_ENCRYPT_TYPE_AES:
3544 params.cipher = WLAN_CIPHER_SUITE_AES_CMAC;
3545 break;
3546
3547 default:
3548 params.cipher = IW_AUTH_CIPHER_NONE;
3549 break;
3550 }
3551
3552 params.key_len = pRoamProfile->Keys.KeyLength[key_index];
3553 params.seq_len = 0;
3554 params.seq = NULL;
3555 params.key = &pRoamProfile->Keys.KeyMaterial[key_index][0];
3556 callback(cookie, &params);
3557 return 0;
3558}
3559
3560/*
3561 * FUNCTION: wlan_hdd_cfg80211_del_key
3562 * This function is used to delete the key information
3563 */
3564#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303565static int wlan_hdd_cfg80211_del_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003566 struct net_device *ndev,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303567 u8 key_index,
3568 bool pairwise,
Jeff Johnson295189b2012-06-20 16:38:30 -07003569 const u8 *mac_addr
3570 )
3571#else
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303572static int wlan_hdd_cfg80211_del_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003573 struct net_device *ndev,
3574 u8 key_index,
3575 const u8 *mac_addr
3576 )
3577#endif
3578{
3579 int status = 0;
3580
3581 //This code needs to be revisited. There is sme_removeKey API, we should
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303582 //plan to use that. After the change to use correct index in setkey,
Jeff Johnson295189b2012-06-20 16:38:30 -07003583 //it is observed that this is invalidating peer
3584 //key index whenever re-key is done. This is affecting data link.
3585 //It should be ok to ignore del_key.
3586#if 0
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303587 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
3588 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
Jeff Johnson295189b2012-06-20 16:38:30 -07003589 u8 groupmacaddr[WNI_CFG_BSSID_LEN] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
3590 tCsrRoamSetKey setKey;
3591 v_U32_t roamId= 0xFF;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303592
Jeff Johnson295189b2012-06-20 16:38:30 -07003593 ENTER();
3594
3595 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: device_mode = %d\n",
3596 __func__,pAdapter->device_mode);
3597
3598 if (CSR_MAX_NUM_KEY <= key_index)
3599 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303600 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key index %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07003601 key_index);
3602
3603 return -EINVAL;
3604 }
3605
3606 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
3607 setKey.keyId = key_index;
3608
3609 if (mac_addr)
3610 vos_mem_copy(setKey.peerMac, mac_addr,WNI_CFG_BSSID_LEN);
3611 else
3612 vos_mem_copy(setKey.peerMac, groupmacaddr, WNI_CFG_BSSID_LEN);
3613
3614 setKey.encType = eCSR_ENCRYPT_TYPE_NONE;
3615
3616 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07003617 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303618 )
3619 {
3620
3621 hdd_hostapd_state_t *pHostapdState =
Jeff Johnson295189b2012-06-20 16:38:30 -07003622 WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
3623 if( pHostapdState->bssState == BSS_START)
3624 {
3625 status = WLANSAP_SetKeySta( pVosContext, &setKey);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303626
Jeff Johnson295189b2012-06-20 16:38:30 -07003627 if ( status != eHAL_STATUS_SUCCESS )
3628 {
3629 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3630 "[%4d] WLANSAP_SetKeySta returned ERROR status= %d",
3631 __LINE__, status );
3632 }
3633 }
3634 }
3635 else if ( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303636 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Jeff Johnson295189b2012-06-20 16:38:30 -07003637 )
3638 {
3639 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3640
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303641 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_SETTING_KEY;
3642
3643 hddLog(VOS_TRACE_LEVEL_INFO_MED,
Jeff Johnson295189b2012-06-20 16:38:30 -07003644 "%s: delete key for peerMac %2x:%2x:%2x:%2x:%2x:%2x",
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303645 __func__, setKey.peerMac[0], setKey.peerMac[1],
3646 setKey.peerMac[2], setKey.peerMac[3],
Jeff Johnson295189b2012-06-20 16:38:30 -07003647 setKey.peerMac[4], setKey.peerMac[5]);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303648 if(pAdapter->sessionCtx.station.conn_info.connState ==
3649 eConnectionState_Associated)
Jeff Johnson295189b2012-06-20 16:38:30 -07003650 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303651 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07003652 pAdapter->sessionId, &setKey, &roamId );
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303653
Jeff Johnson295189b2012-06-20 16:38:30 -07003654 if ( 0 != status )
3655 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303656 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07003657 "%s: sme_RoamSetKey failure, returned %d",
3658 __func__, status);
3659 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3660 return -EINVAL;
3661 }
3662 }
3663 }
3664#endif
Jeff Johnsone7245742012-09-05 17:12:55 -07003665 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07003666 return status;
3667}
3668
3669/*
3670 * FUNCTION: wlan_hdd_cfg80211_set_default_key
3671 * This function is used to set the default tx key index
3672 */
3673#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
3674static int wlan_hdd_cfg80211_set_default_key( struct wiphy *wiphy,
3675 struct net_device *ndev,
3676 u8 key_index,
3677 bool unicast, bool multicast)
3678#else
3679static int wlan_hdd_cfg80211_set_default_key( struct wiphy *wiphy,
3680 struct net_device *ndev,
3681 u8 key_index)
3682#endif
3683{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303684 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303685 int status;
Gopichand Nakkala29149562013-05-10 21:43:41 +05303686 hdd_wext_state_t *pWextState;
3687 hdd_station_ctx_t *pHddStaCtx;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303688 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07003689
3690 ENTER();
3691
Gopichand Nakkala29149562013-05-10 21:43:41 +05303692 if ((NULL == pAdapter))
3693 {
3694 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
3695 "invalid adapter");
3696 return -EINVAL;
3697 }
3698
3699 pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
3700 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3701
3702 if ((NULL == pWextState) || (NULL == pHddStaCtx))
3703 {
3704 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
3705 "invalid Wext state or HDD context");
3706 return -EINVAL;
3707 }
3708
Jeff Johnson295189b2012-06-20 16:38:30 -07003709 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d key_index = %d \n",
3710 __func__,pAdapter->device_mode, key_index);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303711
Jeff Johnson295189b2012-06-20 16:38:30 -07003712 if (CSR_MAX_NUM_KEY <= key_index)
3713 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303714 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key index %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07003715 key_index);
3716
3717 return -EINVAL;
3718 }
3719
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303720 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
3721 status = wlan_hdd_validate_context(pHddCtx);
3722
3723 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003724 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303725 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3726 "%s: HDD context is not valid", __func__);
3727 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003728 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303729
Jeff Johnson295189b2012-06-20 16:38:30 -07003730 if ((pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Jeff Johnson295189b2012-06-20 16:38:30 -07003731 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303732 )
Jeff Johnson295189b2012-06-20 16:38:30 -07003733 {
Gopichand Nakkala29149562013-05-10 21:43:41 +05303734 if ( (eCSR_ENCRYPT_TYPE_TKIP !=
Jeff Johnson295189b2012-06-20 16:38:30 -07003735 pWextState->roamProfile.EncryptionType.encryptionType[0]) &&
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303736 (eCSR_ENCRYPT_TYPE_AES !=
Jeff Johnson295189b2012-06-20 16:38:30 -07003737 pWextState->roamProfile.EncryptionType.encryptionType[0])
3738 )
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303739 {
3740 /* if default key index is not same as previous one,
Jeff Johnson295189b2012-06-20 16:38:30 -07003741 * then update the default key index */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303742
Jeff Johnson295189b2012-06-20 16:38:30 -07003743 tCsrRoamSetKey setKey;
3744 v_U32_t roamId= 0xFF;
3745 tCsrKeys *Keys = &pWextState->roamProfile.Keys;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303746
3747 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: default tx key index %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07003748 __func__, key_index);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303749
Jeff Johnson295189b2012-06-20 16:38:30 -07003750 Keys->defaultIndex = (u8)key_index;
3751 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
3752 setKey.keyId = key_index;
3753 setKey.keyLength = Keys->KeyLength[key_index];
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303754
3755 vos_mem_copy(&setKey.Key[0],
3756 &Keys->KeyMaterial[key_index][0],
Jeff Johnson295189b2012-06-20 16:38:30 -07003757 Keys->KeyLength[key_index]);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303758
Gopichand Nakkala29149562013-05-10 21:43:41 +05303759 setKey.keyDirection = eSIR_TX_RX;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303760
3761 vos_mem_copy(setKey.peerMac,
Jeff Johnson295189b2012-06-20 16:38:30 -07003762 &pHddStaCtx->conn_info.bssId[0],
3763 WNI_CFG_BSSID_LEN);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303764
Gopichand Nakkala29149562013-05-10 21:43:41 +05303765 if (Keys->KeyLength[key_index] == CSR_WEP40_KEY_LEN &&
3766 pWextState->roamProfile.EncryptionType.encryptionType[0] ==
3767 eCSR_ENCRYPT_TYPE_WEP104)
3768 {
3769 /*In the case of dynamic wep supplicant hardcodes DWEP type to eCSR_ENCRYPT_TYPE_WEP104
3770 even though ap is configured for WEP-40 encryption. In this canse the key length
3771 is 5 but the encryption type is 104 hence checking the key langht(5) and encryption
3772 type(104) and switching encryption type to 40*/
3773 pWextState->roamProfile.EncryptionType.encryptionType[0] =
3774 eCSR_ENCRYPT_TYPE_WEP40;
3775 pWextState->roamProfile.mcEncryptionType.encryptionType[0] =
3776 eCSR_ENCRYPT_TYPE_WEP40;
3777 }
3778
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303779 setKey.encType =
Jeff Johnson295189b2012-06-20 16:38:30 -07003780 pWextState->roamProfile.EncryptionType.encryptionType[0];
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303781
Jeff Johnson295189b2012-06-20 16:38:30 -07003782 /* issue set key request */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303783 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07003784 pAdapter->sessionId, &setKey, &roamId );
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303785
Jeff Johnson295189b2012-06-20 16:38:30 -07003786 if ( 0 != status )
3787 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303788 hddLog(VOS_TRACE_LEVEL_ERROR,
3789 "%s: sme_RoamSetKey failed, returned %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07003790 status);
3791 return -EINVAL;
3792 }
3793 }
3794 }
3795
3796 /* In SoftAp mode setting key direction for default mode */
3797 else if ( WLAN_HDD_SOFTAP == pAdapter->device_mode )
3798 {
3799 if ( (eCSR_ENCRYPT_TYPE_TKIP !=
3800 pWextState->roamProfile.EncryptionType.encryptionType[0]) &&
3801 (eCSR_ENCRYPT_TYPE_AES !=
3802 pWextState->roamProfile.EncryptionType.encryptionType[0])
3803 )
3804 {
3805 /* Saving key direction for default key index to TX default */
3806 hdd_ap_ctx_t *pAPCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
3807 pAPCtx->wepKey[key_index].keyDirection = eSIR_TX_DEFAULT;
3808 }
3809 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303810
Jeff Johnson295189b2012-06-20 16:38:30 -07003811 return status;
3812}
3813
Jeff Johnson295189b2012-06-20 16:38:30 -07003814/*
3815 * FUNCTION: wlan_hdd_cfg80211_inform_bss
3816 * This function is used to inform the BSS details to nl80211 interface.
3817 */
3818static struct cfg80211_bss* wlan_hdd_cfg80211_inform_bss(
3819 hdd_adapter_t *pAdapter, tCsrRoamConnectedProfile *roamProfile)
3820{
3821 struct net_device *dev = pAdapter->dev;
3822 struct wireless_dev *wdev = dev->ieee80211_ptr;
3823 struct wiphy *wiphy = wdev->wiphy;
3824 tSirBssDescription *pBssDesc = roamProfile->pBssDesc;
3825 int chan_no;
3826 int ie_length;
3827 const char *ie;
3828 unsigned int freq;
3829 struct ieee80211_channel *chan;
3830 int rssi = 0;
3831 struct cfg80211_bss *bss = NULL;
3832
3833 ENTER();
3834
3835 if( NULL == pBssDesc )
3836 {
3837 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: pBssDesc is NULL\n", __func__);
3838 return bss;
3839 }
3840
3841 chan_no = pBssDesc->channelId;
3842 ie_length = GET_IE_LEN_IN_BSS_DESC( pBssDesc->length );
3843 ie = ((ie_length != 0) ? (const char *)&pBssDesc->ieFields: NULL);
3844
3845 if( NULL == ie )
3846 {
3847 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: IE of BSS descriptor is NULL\n", __func__);
3848 return bss;
3849 }
3850
3851#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,38))
3852 if (chan_no <= ARRAY_SIZE(hdd_channels_2_4_GHZ))
3853 {
3854 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_2GHZ);
3855 }
3856 else
3857 {
3858 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_5GHZ);
3859 }
3860#else
3861 freq = ieee80211_channel_to_frequency(chan_no);
3862#endif
3863
3864 chan = __ieee80211_get_channel(wiphy, freq);
3865
3866 bss = cfg80211_get_bss(wiphy, chan, pBssDesc->bssId,
3867 &roamProfile->SSID.ssId[0], roamProfile->SSID.length,
3868 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
3869 if (bss == NULL)
3870 {
3871 rssi = (VOS_MIN ((pBssDesc->rssi + pBssDesc->sinr), 0))*100;
3872
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303873 return (cfg80211_inform_bss(wiphy, chan, pBssDesc->bssId,
3874 le64_to_cpu(*(__le64 *)pBssDesc->timeStamp),
Jeff Johnson295189b2012-06-20 16:38:30 -07003875 pBssDesc->capabilityInfo,
3876 pBssDesc->beaconInterval, ie, ie_length,
3877 rssi, GFP_KERNEL ));
3878}
3879 else
3880 {
3881 return bss;
3882 }
3883}
3884
3885
3886
3887/*
3888 * FUNCTION: wlan_hdd_cfg80211_inform_bss_frame
3889 * This function is used to inform the BSS details to nl80211 interface.
3890 */
3891struct cfg80211_bss*
3892wlan_hdd_cfg80211_inform_bss_frame( hdd_adapter_t *pAdapter,
3893 tSirBssDescription *bss_desc
3894 )
3895{
3896 /*
3897 cfg80211_inform_bss() is not updating ie field of bss entry, if entry
3898 already exists in bss data base of cfg80211 for that particular BSS ID.
3899 Using cfg80211_inform_bss_frame to update the bss entry instead of
3900 cfg80211_inform_bss, But this call expects mgmt packet as input. As of
3901 now there is no possibility to get the mgmt(probe response) frame from PE,
3902 converting bss_desc to ieee80211_mgmt(probe response) and passing to
3903 cfg80211_inform_bss_frame.
3904 */
3905 struct net_device *dev = pAdapter->dev;
3906 struct wireless_dev *wdev = dev->ieee80211_ptr;
3907 struct wiphy *wiphy = wdev->wiphy;
3908 int chan_no = bss_desc->channelId;
Madan Mohan Koyyalamudi86f629e2012-11-09 16:27:29 -08003909#ifdef WLAN_ENABLE_AGEIE_ON_SCAN_RESULTS
3910 qcom_ie_age *qie_age = NULL;
3911 int ie_length = GET_IE_LEN_IN_BSS_DESC( bss_desc->length ) + sizeof(qcom_ie_age);
3912#else
Jeff Johnson295189b2012-06-20 16:38:30 -07003913 int ie_length = GET_IE_LEN_IN_BSS_DESC( bss_desc->length );
Madan Mohan Koyyalamudi86f629e2012-11-09 16:27:29 -08003914#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07003915 const char *ie =
3916 ((ie_length != 0) ? (const char *)&bss_desc->ieFields: NULL);
3917 unsigned int freq;
3918 struct ieee80211_channel *chan;
3919 struct ieee80211_mgmt *mgmt =
3920 kzalloc((sizeof (struct ieee80211_mgmt) + ie_length), GFP_KERNEL);
3921 struct cfg80211_bss *bss_status = NULL;
3922 size_t frame_len = sizeof (struct ieee80211_mgmt) + ie_length;
3923 int rssi = 0;
Jeff Johnsone7245742012-09-05 17:12:55 -07003924#ifdef WLAN_OPEN_SOURCE
3925 struct timespec ts;
3926#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07003927
3928 ENTER();
3929
Madan Mohan Koyyalamudi2e5c9142012-11-02 13:17:48 -07003930 if (!mgmt)
3931 return NULL;
3932
Jeff Johnson295189b2012-06-20 16:38:30 -07003933 memcpy(mgmt->bssid, bss_desc->bssId, ETH_ALEN);
Jeff Johnsone7245742012-09-05 17:12:55 -07003934
3935#ifdef WLAN_OPEN_SOURCE
3936 /* Android does not want the timestamp from the frame.
3937 Instead it wants a monotonic increasing value */
3938 get_monotonic_boottime(&ts);
3939 mgmt->u.probe_resp.timestamp =
3940 ((u64)ts.tv_sec * 1000000) + (ts.tv_nsec / 1000);
3941#else
3942 /* keep old behavior for non-open source (for now) */
Jeff Johnson295189b2012-06-20 16:38:30 -07003943 memcpy(&mgmt->u.probe_resp.timestamp, bss_desc->timeStamp,
3944 sizeof (bss_desc->timeStamp));
Jeff Johnsone7245742012-09-05 17:12:55 -07003945
3946#endif
3947
Jeff Johnson295189b2012-06-20 16:38:30 -07003948 mgmt->u.probe_resp.beacon_int = bss_desc->beaconInterval;
3949 mgmt->u.probe_resp.capab_info = bss_desc->capabilityInfo;
Madan Mohan Koyyalamudi86f629e2012-11-09 16:27:29 -08003950
3951#ifdef WLAN_ENABLE_AGEIE_ON_SCAN_RESULTS
3952 /* GPS Requirement: need age ie per entry. Using vendor specific. */
3953 /* Assuming this is the last IE, copy at the end */
3954 ie_length -=sizeof(qcom_ie_age);
3955 qie_age = (qcom_ie_age *)(mgmt->u.probe_resp.variable + ie_length);
3956 qie_age->element_id = QCOM_VENDOR_IE_ID;
3957 qie_age->len = QCOM_VENDOR_IE_AGE_LEN;
3958 qie_age->oui_1 = QCOM_OUI1;
3959 qie_age->oui_2 = QCOM_OUI2;
3960 qie_age->oui_3 = QCOM_OUI3;
3961 qie_age->type = QCOM_VENDOR_IE_AGE_TYPE;
3962 qie_age->age = vos_timer_get_system_ticks() - bss_desc->nReceivedTime;
3963#endif
3964
Jeff Johnson295189b2012-06-20 16:38:30 -07003965 memcpy(mgmt->u.probe_resp.variable, ie, ie_length);
Gopichand Nakkalad908ec82013-05-16 19:32:19 +05303966 if (bss_desc->fProbeRsp)
3967 {
3968 mgmt->frame_control |=
3969 (u16)(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_RESP);
3970 }
3971 else
3972 {
3973 mgmt->frame_control |=
3974 (u16)(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_BEACON);
3975 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003976
3977#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,38))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303978 if (chan_no <= ARRAY_SIZE(hdd_channels_2_4_GHZ) &&
Jeff Johnson295189b2012-06-20 16:38:30 -07003979 (wiphy->bands[IEEE80211_BAND_2GHZ] != NULL))
3980 {
3981 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_2GHZ);
3982 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303983 else if ((chan_no > ARRAY_SIZE(hdd_channels_2_4_GHZ)) &&
Jeff Johnson295189b2012-06-20 16:38:30 -07003984 (wiphy->bands[IEEE80211_BAND_5GHZ] != NULL))
3985
3986 {
3987 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_5GHZ);
3988 }
3989 else
3990 {
3991 kfree(mgmt);
3992 return NULL;
3993 }
3994#else
3995 freq = ieee80211_channel_to_frequency(chan_no);
3996#endif
3997 chan = __ieee80211_get_channel(wiphy, freq);
Leela V Kiran Kumar Reddy90032de2013-01-24 18:33:30 -08003998 /*when the band is changed on the fly using the GUI, three things are done
3999 * 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)
4000 * as part of the scan abort, message willbe queued to PE and we proceed with flushing and changinh the band.
4001 * pe will stop the scanning further and report back the results what ever it had till now by calling the call back function.
4002 * if the time between update band and scandone call back is sufficent enough the band change reflects in SME, SME validates the channels
4003 * and discards the channels correponding to previous band and calls back with zero bss results.
4004 * 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
4005 * all the channels correponding to previous band.this is due to race condition.but those channels are invalid to the new band and so
4006 * this function __ieee80211_get_channel will return NULL.Each time we report scan result with this pointer null warning kernel trace is printed.
4007 * if the scan results contain large number of APs continuosly kernel warning trace is printed and it will lead to apps watch dog bark.
4008 * So drop the bss and continue to next bss.
4009 */
4010 if(chan == NULL)
4011 {
4012 hddLog(VOS_TRACE_LEVEL_INFO, "%s chan pointer is NULL", __func__);
Chilam Ngc4244af2013-04-01 15:37:32 -07004013 kfree(mgmt);
Leela V Kiran Kumar Reddy90032de2013-01-24 18:33:30 -08004014 return NULL;
4015 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004016 /*To keep the rssi icon of the connected AP in the scan window
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304017 *and the rssi icon of the wireless networks in sync
Jeff Johnson295189b2012-06-20 16:38:30 -07004018 * */
4019 if (( eConnectionState_Associated ==
4020 pAdapter->sessionCtx.station.conn_info.connState ) &&
4021 ( VOS_TRUE == vos_mem_compare(bss_desc->bssId,
4022 pAdapter->sessionCtx.station.conn_info.bssId,
4023 WNI_CFG_BSSID_LEN)))
4024 {
4025 /* supplicant takes the signal strength in terms of mBm(100*dBm) */
4026 rssi = (pAdapter->rssi * 100);
4027 }
4028 else
4029 {
4030 rssi = (VOS_MIN ((bss_desc->rssi + bss_desc->sinr), 0))*100;
4031 }
4032
4033 bss_status = cfg80211_inform_bss_frame(wiphy, chan, mgmt,
4034 frame_len, rssi, GFP_KERNEL);
4035 kfree(mgmt);
4036 return bss_status;
4037}
4038
4039/*
4040 * FUNCTION: wlan_hdd_cfg80211_update_bss_db
4041 * This function is used to update the BSS data base of CFG8011
4042 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304043struct cfg80211_bss* wlan_hdd_cfg80211_update_bss_db( hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07004044 tCsrRoamInfo *pRoamInfo
4045 )
4046{
4047 tCsrRoamConnectedProfile roamProfile;
4048 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
4049 struct cfg80211_bss *bss = NULL;
4050
4051 ENTER();
4052
4053 memset(&roamProfile, 0, sizeof(tCsrRoamConnectedProfile));
4054 sme_RoamGetConnectProfile(hHal, pAdapter->sessionId, &roamProfile);
4055
4056 if (NULL != roamProfile.pBssDesc)
4057 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304058 bss = wlan_hdd_cfg80211_inform_bss(pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07004059 &roamProfile);
4060
4061 if (NULL == bss)
4062 {
4063 hddLog(VOS_TRACE_LEVEL_INFO, "%s: cfg80211_inform_bss return NULL",
4064 __func__);
4065 }
4066
4067 sme_RoamFreeConnectProfile(hHal, &roamProfile);
4068 }
4069 else
4070 {
4071 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: roamProfile.pBssDesc is NULL",
4072 __func__);
4073 }
4074 return bss;
4075}
4076
4077/*
4078 * FUNCTION: wlan_hdd_cfg80211_update_bss
4079 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304080static int wlan_hdd_cfg80211_update_bss( struct wiphy *wiphy,
4081 hdd_adapter_t *pAdapter
Jeff Johnson295189b2012-06-20 16:38:30 -07004082 )
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304083{
Jeff Johnson295189b2012-06-20 16:38:30 -07004084 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
4085 tCsrScanResultInfo *pScanResult;
4086 eHalStatus status = 0;
4087 tScanResultHandle pResult;
4088 struct cfg80211_bss *bss_status = NULL;
4089
4090 ENTER();
4091
4092 if ((WLAN_HDD_GET_CTX(pAdapter))->isLogpInProgress)
4093 {
4094 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL, "%s:LOGP in Progress. Ignore!!!",__func__);
4095 return -EAGAIN;
4096 }
4097
4098 /*
4099 * start getting scan results and populate cgf80211 BSS database
4100 */
4101 status = sme_ScanGetResult(hHal, pAdapter->sessionId, NULL, &pResult);
4102
4103 /* no scan results */
4104 if (NULL == pResult)
4105 {
4106 hddLog(VOS_TRACE_LEVEL_INFO, "%s: No scan result\n", __func__);
4107 return status;
4108 }
4109
4110 pScanResult = sme_ScanResultGetFirst(hHal, pResult);
4111
4112 while (pScanResult)
4113 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304114 /*
4115 * cfg80211_inform_bss() is not updating ie field of bss entry, if
4116 * entry already exists in bss data base of cfg80211 for that
4117 * particular BSS ID. Using cfg80211_inform_bss_frame to update the
4118 * bss entry instead of cfg80211_inform_bss, But this call expects
4119 * mgmt packet as input. As of now there is no possibility to get
4120 * the mgmt(probe response) frame from PE, converting bss_desc to
Jeff Johnson295189b2012-06-20 16:38:30 -07004121 * ieee80211_mgmt(probe response) and passing to c
4122 * fg80211_inform_bss_frame.
4123 * */
4124
4125 bss_status = wlan_hdd_cfg80211_inform_bss_frame(pAdapter,
4126 &pScanResult->BssDescriptor);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304127
Jeff Johnson295189b2012-06-20 16:38:30 -07004128
4129 if (NULL == bss_status)
4130 {
4131 hddLog(VOS_TRACE_LEVEL_INFO,
4132 "%s: NULL returned by cfg80211_inform_bss\n", __func__);
4133 }
4134 else
4135 {
4136 cfg80211_put_bss(bss_status);
4137 }
4138
4139 pScanResult = sme_ScanResultGetNext(hHal, pResult);
4140 }
4141
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304142 sme_ScanResultPurge(hHal, pResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07004143
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304144 return 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07004145}
4146
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004147void
4148hddPrintMacAddr(tCsrBssid macAddr, tANI_U8 logLevel)
4149{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304150 VOS_TRACE(VOS_MODULE_ID_HDD, logLevel,
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07004151 "%02X:%02X:%02X:%02X:%02X:%02X\n",
4152 macAddr[0], macAddr[1], macAddr[2], macAddr[3], macAddr[4],
4153 macAddr[5]);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004154} /****** end hddPrintMacAddr() ******/
4155
4156void
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07004157hddPrintPmkId(tANI_U8 *pmkId, tANI_U8 logLevel)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004158{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304159 VOS_TRACE(VOS_MODULE_ID_HDD, logLevel,
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07004160 "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
4161 pmkId[0], pmkId[1], pmkId[2], pmkId[3], pmkId[4],
4162 pmkId[5], pmkId[6], pmkId[7], pmkId[8], pmkId[9], pmkId[10],
4163 pmkId[11], pmkId[12], pmkId[13], pmkId[14], pmkId[15]);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004164} /****** end hddPrintPmkId() ******/
4165
4166//hddPrintMacAddr(tCsrBssid macAddr, tANI_U8 logLevel);
4167//hddPrintMacAddr(macAddr, VOS_TRACE_LEVEL_FATAL);
4168
4169//void sirDumpBuf(tpAniSirGlobal pMac, tANI_U8 modId, tANI_U32 level, tANI_U8 *buf, tANI_U32 size);
4170//sirDumpBuf(pMac, VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL, pmkid, 16);
4171
4172#define dump_bssid(bssid) \
4173 { \
Jeff Johnsone7245742012-09-05 17:12:55 -07004174 hddLog(VOS_TRACE_LEVEL_INFO, "BSSID (MAC) address:\t"); \
4175 hddPrintMacAddr(bssid, VOS_TRACE_LEVEL_INFO);\
4176 hddLog(VOS_TRACE_LEVEL_INFO, "\n"); \
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004177 }
4178
4179#define dump_pmkid(pMac, pmkid) \
4180 { \
Jeff Johnsone7245742012-09-05 17:12:55 -07004181 hddLog(VOS_TRACE_LEVEL_INFO, "PMKSA-ID:\t"); \
4182 hddPrintPmkId(pmkid, VOS_TRACE_LEVEL_INFO);\
4183 hddLog(VOS_TRACE_LEVEL_INFO, "\n"); \
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004184 }
4185
Madan Mohan Koyyalamudi1b4afb02012-10-22 15:25:16 -07004186#if defined(FEATURE_WLAN_LFR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004187/*
4188 * FUNCTION: wlan_hdd_cfg80211_pmksa_candidate_notify
4189 * This function is used to notify the supplicant of a new PMKSA candidate.
4190 */
4191int wlan_hdd_cfg80211_pmksa_candidate_notify(
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304192 hdd_adapter_t *pAdapter, tCsrRoamInfo *pRoamInfo,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004193 int index, bool preauth )
4194{
Jeff Johnsone7245742012-09-05 17:12:55 -07004195#ifdef FEATURE_WLAN_OKC
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004196 struct net_device *dev = pAdapter->dev;
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004197 hdd_context_t *pHddCtx = (hdd_context_t*)pAdapter->pHddCtx;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004198
4199 ENTER();
Jeff Johnsone7245742012-09-05 17:12:55 -07004200 hddLog(VOS_TRACE_LEVEL_INFO, "%s is going to notify supplicant of:", __func__);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004201
4202 if( NULL == pRoamInfo )
4203 {
4204 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: pRoamInfo is NULL\n", __func__);
4205 return -EINVAL;
4206 }
4207
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004208 if (eANI_BOOLEAN_TRUE == hdd_is_okc_mode_enabled(pHddCtx))
4209 {
4210 dump_bssid(pRoamInfo->bssid);
4211 cfg80211_pmksa_candidate_notify(dev, index,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004212 pRoamInfo->bssid, preauth, GFP_KERNEL);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004213 }
Jeff Johnsone7245742012-09-05 17:12:55 -07004214#endif /* FEATURE_WLAN_OKC */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304215 return 0;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004216}
4217#endif //FEATURE_WLAN_LFR
4218
Jeff Johnson295189b2012-06-20 16:38:30 -07004219/*
4220 * FUNCTION: hdd_cfg80211_scan_done_callback
4221 * scanning callback function, called after finishing scan
4222 *
4223 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304224static eHalStatus hdd_cfg80211_scan_done_callback(tHalHandle halHandle,
Jeff Johnson295189b2012-06-20 16:38:30 -07004225 void *pContext, tANI_U32 scanId, eCsrScanStatus status)
4226{
4227 struct net_device *dev = (struct net_device *) pContext;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304228 //struct wireless_dev *wdev = dev->ieee80211_ptr;
Jeff Johnson295189b2012-06-20 16:38:30 -07004229 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004230 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
4231 hdd_scaninfo_t *pScanInfo = &pHddCtx->scan_info;
Jeff Johnson295189b2012-06-20 16:38:30 -07004232 struct cfg80211_scan_request *req = NULL;
4233 int ret = 0;
4234
4235 ENTER();
4236
4237 hddLog(VOS_TRACE_LEVEL_INFO,
4238 "%s called with halHandle = %p, pContext = %p,"
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304239 "scanID = %d, returned status = %d\n",
Jeff Johnson295189b2012-06-20 16:38:30 -07004240 __func__, halHandle, pContext, (int) scanId, (int) status);
4241
4242 //Block on scan req completion variable. Can't wait forever though.
4243 ret = wait_for_completion_interruptible_timeout(
4244 &pScanInfo->scan_req_completion_event,
4245 msecs_to_jiffies(WLAN_WAIT_TIME_SCAN_REQ));
4246 if (!ret)
4247 {
4248 VOS_ASSERT(pScanInfo->mScanPending);
Jeff Johnsone7245742012-09-05 17:12:55 -07004249 goto allow_suspend;
Jeff Johnson295189b2012-06-20 16:38:30 -07004250 }
4251
4252 if(pScanInfo->mScanPending != VOS_TRUE)
4253 {
4254 VOS_ASSERT(pScanInfo->mScanPending);
Jeff Johnsone7245742012-09-05 17:12:55 -07004255 goto allow_suspend;
Jeff Johnson295189b2012-06-20 16:38:30 -07004256 }
4257
4258 /* Check the scanId */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304259 if (pScanInfo->scanId != scanId)
Jeff Johnson295189b2012-06-20 16:38:30 -07004260 {
4261 hddLog(VOS_TRACE_LEVEL_INFO,
4262 "%s called with mismatched scanId pScanInfo->scanId = %d "
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304263 "scanId = %d \n", __func__, (int) pScanInfo->scanId,
Jeff Johnson295189b2012-06-20 16:38:30 -07004264 (int) scanId);
4265 }
4266
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304267 ret = wlan_hdd_cfg80211_update_bss((WLAN_HDD_GET_CTX(pAdapter))->wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07004268 pAdapter);
4269
4270 if (0 > ret)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304271 hddLog(VOS_TRACE_LEVEL_INFO, "%s: NO SCAN result", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07004272
4273
4274 /* If any client wait scan result through WEXT
4275 * send scan done event to client */
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004276 if (pHddCtx->scan_info.waitScanResult)
Jeff Johnson295189b2012-06-20 16:38:30 -07004277 {
4278 /* The other scan request waiting for current scan finish
4279 * Send event to notify current scan finished */
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004280 if(WEXT_SCAN_PENDING_DELAY == pHddCtx->scan_info.scan_pending_option)
Jeff Johnson295189b2012-06-20 16:38:30 -07004281 {
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004282 vos_event_set(&pHddCtx->scan_info.scan_finished_event);
Jeff Johnson295189b2012-06-20 16:38:30 -07004283 }
4284 /* Send notify to WEXT client */
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004285 else if(WEXT_SCAN_PENDING_PIGGYBACK == pHddCtx->scan_info.scan_pending_option)
Jeff Johnson295189b2012-06-20 16:38:30 -07004286 {
4287 struct net_device *dev = pAdapter->dev;
4288 union iwreq_data wrqu;
4289 int we_event;
4290 char *msg;
4291
4292 memset(&wrqu, '\0', sizeof(wrqu));
4293 we_event = SIOCGIWSCAN;
4294 msg = NULL;
4295 wireless_send_event(dev, we_event, &wrqu, msg);
4296 }
4297 }
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004298 pHddCtx->scan_info.waitScanResult = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004299
4300 /* Get the Scan Req */
4301 req = pAdapter->request;
4302
4303 if (!req)
4304 {
4305 hddLog(VOS_TRACE_LEVEL_ERROR, "request is became NULL\n");
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07004306 pScanInfo->mScanPending = VOS_FALSE;
Jeff Johnsone7245742012-09-05 17:12:55 -07004307 goto allow_suspend;
Jeff Johnson295189b2012-06-20 16:38:30 -07004308 }
4309
4310 /*
4311 * setting up 0, just in case.
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304312 */
Jeff Johnson295189b2012-06-20 16:38:30 -07004313 req->n_ssids = 0;
4314 req->n_channels = 0;
4315 req->ie = 0;
4316
Jeff Johnson295189b2012-06-20 16:38:30 -07004317 pAdapter->request = NULL;
Jeff Johnsone7245742012-09-05 17:12:55 -07004318 /* Scan is no longer pending */
4319 pScanInfo->mScanPending = VOS_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004320
Madan Mohan Koyyalamudib764bf82012-10-11 16:38:51 -07004321 /*
4322 * cfg80211_scan_done informing NL80211 about completion
4323 * of scanning
4324 */
4325 cfg80211_scan_done(req, false);
Madan Mohan Koyyalamudif4e81002012-11-13 10:46:38 -08004326 complete(&pScanInfo->abortscan_event_var);
Jeff Johnson295189b2012-06-20 16:38:30 -07004327
Jeff Johnsone7245742012-09-05 17:12:55 -07004328allow_suspend:
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07004329 /* release the wake lock at the end of the scan*/
4330 hdd_allow_suspend();
Jeff Johnsone7245742012-09-05 17:12:55 -07004331
Madan Mohan Koyyalamudi10d83a92012-09-28 15:47:05 -07004332 /* Acquire wakelock to handle the case where APP's tries to suspend
4333 * immediatly after the driver gets connect request(i.e after scan)
4334 * from supplicant, this result in app's is suspending and not able
4335 * to process the connect request to AP */
Amar Singhal6144c002013-05-03 16:11:42 -07004336 hdd_allow_suspend_timeout(1000);
Madan Mohan Koyyalamudi10d83a92012-09-28 15:47:05 -07004337
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07004338#ifdef FEATURE_WLAN_TDLS
4339 wlan_hdd_tdls_scan_done_callback(pAdapter);
4340#endif
4341
Jeff Johnson295189b2012-06-20 16:38:30 -07004342 EXIT();
4343 return 0;
4344}
4345
4346/*
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004347 * FUNCTION: hdd_isScanAllowed
4348 * Go through each adapter and check if scan allowed
4349 *
4350 */
4351v_BOOL_t hdd_isScanAllowed( hdd_context_t *pHddCtx )
4352{
4353 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
4354 hdd_station_ctx_t *pHddStaCtx = NULL;
4355 hdd_adapter_t *pAdapter = NULL;
4356 VOS_STATUS status = 0;
4357 v_U8_t staId = 0;
4358 v_U8_t *staMac = NULL;
4359
Gopichand Nakkala8c0386c2013-07-09 23:31:37 +05304360 if (VOS_TIMER_STATE_RUNNING ==
4361 vos_timer_getCurrentState(&pHddCtx->hdd_p2p_go_conn_is_in_progress))
4362 {
4363 hddLog(VOS_TRACE_LEVEL_INFO,
4364 "%s: Connection is in progress, Do not allow the scan", __func__);
4365 return VOS_FALSE;
4366 }
4367
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004368 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
4369
4370 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
4371 {
4372 pAdapter = pAdapterNode->pAdapter;
4373
4374 if( pAdapter )
4375 {
4376 hddLog(VOS_TRACE_LEVEL_INFO,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304377 "%s: Adapter with device mode %d exists",
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004378 __func__, pAdapter->device_mode);
4379 if ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
4380 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) ||
4381 (WLAN_HDD_P2P_DEVICE == pAdapter->device_mode))
4382 {
4383 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
4384 if ((eConnectionState_Associated == pHddStaCtx->conn_info.connState) &&
4385 (VOS_FALSE == pHddStaCtx->conn_info.uIsAuthenticated))
4386 {
4387 staMac = (v_U8_t *) &(pAdapter->macAddressCurrent.bytes[0]);
4388 hddLog(VOS_TRACE_LEVEL_ERROR,
4389 "%s: client %02x:%02x:%02x:%02x:%02x:%02x is in the "
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304390 "middle of WPS/EAPOL exchange.", __func__,
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004391 staMac[0], staMac[1], staMac[2],
4392 staMac[3], staMac[4], staMac[5]);
4393 return VOS_FALSE;
4394 }
4395 }
4396 else if ((WLAN_HDD_SOFTAP == pAdapter->device_mode) ||
4397 (WLAN_HDD_P2P_GO == pAdapter->device_mode))
4398 {
4399 for (staId = 0; staId < WLAN_MAX_STA_COUNT; staId++)
4400 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304401 if ((pAdapter->aStaInfo[staId].isUsed) &&
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004402 (WLANTL_STA_CONNECTED == pAdapter->aStaInfo[staId].tlSTAState))
4403 {
4404 staMac = (v_U8_t *) &(pAdapter->aStaInfo[staId].macAddrSTA.bytes[0]);
4405
4406 hddLog(VOS_TRACE_LEVEL_ERROR,
4407 "%s: client %02x:%02x:%02x:%02x:%02x:%02x of SoftAP/P2P-GO is in the "
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304408 "middle of WPS/EAPOL exchange.", __func__,
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004409 staMac[0], staMac[1], staMac[2],
4410 staMac[3], staMac[4], staMac[5]);
4411 return VOS_FALSE;
4412 }
4413 }
4414 }
4415 }
4416 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
4417 pAdapterNode = pNext;
4418 }
4419 hddLog(VOS_TRACE_LEVEL_INFO,
4420 "%s: Scan allowed", __func__);
4421 return VOS_TRUE;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304422}
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004423
4424/*
Jeff Johnson295189b2012-06-20 16:38:30 -07004425 * FUNCTION: wlan_hdd_cfg80211_scan
4426 * this scan respond to scan trigger and update cfg80211 scan database
4427 * later, scan dump command can be used to recieve scan results
4428 */
Jeff Johnson3bbe4bf2013-01-18 17:05:29 -08004429int wlan_hdd_cfg80211_scan( struct wiphy *wiphy,
4430#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
4431 struct net_device *dev,
4432#endif
4433 struct cfg80211_scan_request *request)
4434{
4435#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
4436 struct net_device *dev = request->wdev->netdev;
4437#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304438 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Jeff Johnson295189b2012-06-20 16:38:30 -07004439 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
4440 hdd_wext_state_t *pwextBuf = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05304441 hdd_config_t *cfg_param = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004442 tCsrScanRequest scanRequest;
4443 tANI_U8 *channelList = NULL, i;
4444 v_U32_t scanId = 0;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05304445 int status;
4446 hdd_scaninfo_t *pScanInfo = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004447 v_U8_t* pP2pIe = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004448
4449 ENTER();
4450
4451 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
4452 __func__,pAdapter->device_mode);
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004453
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05304454 status = wlan_hdd_validate_context(pHddCtx);
4455
4456 if (0 != status)
4457 {
4458 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4459 "%s: HDD context is not valid", __func__);
4460 return status;
4461 }
4462
4463 cfg_param = pHddCtx->cfg_ini;
4464 pScanInfo = &pHddCtx->scan_info;
4465
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004466 if ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) &&
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004467 (eConnectionState_Connecting ==
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004468 (WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))->conn_info.connState))
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004469 {
4470 hddLog(VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08004471 "%s: %p(%d) Connection in progress: Scan request denied (EBUSY)", __func__, \
4472 WLAN_HDD_GET_STATION_CTX_PTR(pAdapter), pAdapter->sessionId);
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004473 return -EBUSY;
4474 }
4475
Jeff Johnson295189b2012-06-20 16:38:30 -07004476#ifdef WLAN_BTAMP_FEATURE
4477 //Scan not supported when AMP traffic is on.
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004478 if (VOS_TRUE == WLANBAP_AmpSessionOn())
Jeff Johnson295189b2012-06-20 16:38:30 -07004479 {
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004480 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07004481 "%s: No scanning when AMP is on", __func__);
4482 return -EOPNOTSUPP;
4483 }
4484#endif
4485 //Scan on any other interface is not supported.
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004486 if (pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07004487 {
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004488 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07004489 "%s: Not scanning on device_mode = %d",
4490 __func__, pAdapter->device_mode);
4491 return -EOPNOTSUPP;
4492 }
4493
4494 if (TRUE == pScanInfo->mScanPending)
4495 {
4496 hddLog(VOS_TRACE_LEVEL_INFO, "%s: mScanPending is TRUE", __func__);
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004497 return -EBUSY;
Jeff Johnson295189b2012-06-20 16:38:30 -07004498 }
4499
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304500 //Don't Allow Scan and return busy if Remain On
Jeff Johnson32d95a32012-09-10 13:15:23 -07004501 //Channel and action frame is pending
4502 //Otherwise Cancel Remain On Channel and allow Scan
4503 //If no action frame pending
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004504 if (0 != wlan_hdd_check_remain_on_channel(pAdapter))
Jeff Johnson32d95a32012-09-10 13:15:23 -07004505 {
4506 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Remain On Channel Pending", __func__);
4507 return -EBUSY;
4508 }
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004509#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07004510 /* if tdls disagree scan right now, return immediately.
4511 tdls will schedule the scan when scan is allowed. (return SUCCESS)
4512 or will reject the scan if any TDLS is in progress. (return -EBUSY)
4513 */
4514 status = wlan_hdd_tdls_scan_callback (pAdapter,
4515 wiphy,
4516#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
4517 dev,
Gopichand Nakkalac3c42b92013-03-20 19:42:34 -07004518#endif
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07004519 request);
4520 if(status <= 0)
4521 {
4522 hddLog(VOS_TRACE_LEVEL_INFO, "%s: TDLS Pending %d", __func__, status);
4523 return status;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004524 }
4525#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -07004526
Jeff Johnson295189b2012-06-20 16:38:30 -07004527 if (mutex_lock_interruptible(&pHddCtx->tmInfo.tmOperationLock))
4528 {
4529 VOS_TRACE(VOS_MODULE_ID_HDD,VOS_TRACE_LEVEL_ERROR,
Jeff Johnson1250df42012-12-10 14:31:52 -08004530 "%s: Acquire lock fail", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07004531 return -EAGAIN;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304532 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004533 if (TRUE == pHddCtx->tmInfo.tmAction.enterImps)
4534 {
4535 hddLog(VOS_TRACE_LEVEL_WARN,
4536 "%s: MAX TM Level Scan not allowed", __func__);
4537 mutex_unlock(&pHddCtx->tmInfo.tmOperationLock);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304538 return -EBUSY;
Jeff Johnson295189b2012-06-20 16:38:30 -07004539 }
4540 mutex_unlock(&pHddCtx->tmInfo.tmOperationLock);
4541
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004542 /* Check if scan is allowed at this point of time.
4543 */
4544 if (!hdd_isScanAllowed(pHddCtx))
4545 {
4546 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Scan not allowed", __func__);
4547 return -EBUSY;
4548 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304549
Jeff Johnson295189b2012-06-20 16:38:30 -07004550 vos_mem_zero( &scanRequest, sizeof(scanRequest));
4551
4552 if (NULL != request)
4553 {
4554 hddLog(VOS_TRACE_LEVEL_INFO, "scan request for ssid = %d",
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304555 (int)request->n_ssids);
Jeff Johnson295189b2012-06-20 16:38:30 -07004556
4557 /* Even though supplicant doesn't provide any SSIDs, n_ssids is set to 1.
4558 * Becasue of this, driver is assuming that this is not wildcard scan and so
4559 * is not aging out the scan results.
4560 */
Jeff Johnson32d95a32012-09-10 13:15:23 -07004561 if (request->ssids && '\0' == request->ssids->ssid[0])
Jeff Johnson295189b2012-06-20 16:38:30 -07004562 {
4563 request->n_ssids = 0;
4564 }
4565
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07004566 if ((request->ssids) && (0 < request->n_ssids))
Jeff Johnson295189b2012-06-20 16:38:30 -07004567 {
4568 tCsrSSIDInfo *SsidInfo;
4569 int j;
4570 scanRequest.SSIDs.numOfSSIDs = request->n_ssids;
4571 /* Allocate num_ssid tCsrSSIDInfo structure */
4572 SsidInfo = scanRequest.SSIDs.SSIDList =
4573 ( tCsrSSIDInfo *)vos_mem_malloc(
4574 request->n_ssids*sizeof(tCsrSSIDInfo));
4575
4576 if(NULL == scanRequest.SSIDs.SSIDList)
4577 {
4578 hddLog(VOS_TRACE_LEVEL_ERROR,
4579 "memory alloc failed SSIDInfo buffer");
4580 return -ENOMEM;
4581 }
4582
4583 /* copy all the ssid's and their length */
4584 for(j = 0; j < request->n_ssids; j++, SsidInfo++)
4585 {
4586 /* get the ssid length */
4587 SsidInfo->SSID.length = request->ssids[j].ssid_len;
4588 vos_mem_copy(SsidInfo->SSID.ssId, &request->ssids[j].ssid[0],
4589 SsidInfo->SSID.length);
4590 SsidInfo->SSID.ssId[SsidInfo->SSID.length] = '\0';
4591 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "SSID number %d: %s",
4592 j, SsidInfo->SSID.ssId);
4593 }
4594 /* set the scan type to active */
4595 scanRequest.scanType = eSIR_ACTIVE_SCAN;
4596 }
4597 else if(WLAN_HDD_P2P_GO == pAdapter->device_mode)
4598 {
4599 /* set the scan type to active */
4600 scanRequest.scanType = eSIR_ACTIVE_SCAN;
4601 }
4602 else
4603 {
4604 /*Set the scan type to default type, in this case it is ACTIVE*/
4605 scanRequest.scanType = pScanInfo->scan_mode;
4606 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304607 scanRequest.minChnTime = cfg_param->nActiveMinChnTime;
Jeff Johnson295189b2012-06-20 16:38:30 -07004608 scanRequest.maxChnTime = cfg_param->nActiveMaxChnTime;
4609 }
4610 else
4611 {
4612 /* set the scan type to active */
4613 scanRequest.scanType = eSIR_ACTIVE_SCAN;
4614 vos_mem_set( scanRequest.bssid, sizeof( tCsrBssid ), 0xff );
4615
4616 /* set min and max channel time to zero */
4617 scanRequest.minChnTime = 0;
4618 scanRequest.maxChnTime = 0;
4619 }
4620
4621 /* set BSSType to default type */
4622 scanRequest.BSSType = eCSR_BSS_TYPE_ANY;
4623
4624 /*TODO: scan the requested channels only*/
4625
4626 /*Right now scanning all the channels */
4627 if( request )
4628 {
4629 if( request->n_channels )
4630 {
4631 channelList = vos_mem_malloc( request->n_channels );
4632 if( NULL == channelList )
4633 {
4634 status = -ENOMEM;
4635 goto free_mem;
4636 }
4637
4638 for( i = 0 ; i < request->n_channels ; i++ )
4639 channelList[i] = request->channels[i]->hw_value;
4640 }
4641
4642 scanRequest.ChannelInfo.numOfChannels = request->n_channels;
4643 scanRequest.ChannelInfo.ChannelList = channelList;
4644
4645 /* set requestType to full scan */
4646 scanRequest.requestType = eCSR_SCAN_REQUEST_FULL_SCAN;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304647
4648 /* Flush the scan results(only p2p beacons) for STA scan and P2P
Madan Mohan Koyyalamudi8d50f312012-11-27 15:48:57 -08004649 * search (Flush on both full scan and social scan but not on single
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304650 * channel scan).P2P search happens on 3 social channels (1, 6, 11)
Madan Mohan Koyyalamudi8d50f312012-11-27 15:48:57 -08004651 */
4652
4653 /* Supplicant does single channel scan after 8-way handshake
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304654 * and in that case driver shoudnt flush scan results. If
4655 * driver flushes the scan results here and unfortunately if
4656 * the AP doesnt respond to our probe req then association
Madan Mohan Koyyalamudi8d50f312012-11-27 15:48:57 -08004657 * fails which is not desired
4658 */
4659
4660 if( request->n_channels != WLAN_HDD_P2P_SINGLE_CHANNEL_SCAN )
4661 {
4662 sme_ScanFlushP2PResult( WLAN_HDD_GET_HAL_CTX(pAdapter),
4663 pAdapter->sessionId );
4664 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004665
4666 if( request->ie_len )
4667 {
4668 /* save this for future association (join requires this) */
4669 memset( &pScanInfo->scanAddIE, 0, sizeof(pScanInfo->scanAddIE) );
4670 memcpy( pScanInfo->scanAddIE.addIEdata, request->ie, request->ie_len);
4671 pScanInfo->scanAddIE.length = request->ie_len;
4672
4673 if((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
Jeff Johnsone7245742012-09-05 17:12:55 -07004674 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) ||
4675 (WLAN_HDD_P2P_DEVICE == pAdapter->device_mode)
Jeff Johnson295189b2012-06-20 16:38:30 -07004676 )
4677 {
4678 pwextBuf->roamProfile.pAddIEScan = pScanInfo->scanAddIE.addIEdata;
4679 pwextBuf->roamProfile.nAddIEScanLength = pScanInfo->scanAddIE.length;
4680 }
4681
4682 scanRequest.uIEFieldLen = pScanInfo->scanAddIE.length;
4683 scanRequest.pIEField = pScanInfo->scanAddIE.addIEdata;
4684
Jeff Johnson295189b2012-06-20 16:38:30 -07004685 pP2pIe = wlan_hdd_get_p2p_ie_ptr((v_U8_t*)request->ie,
4686 request->ie_len);
4687 if (pP2pIe != NULL)
4688 {
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07004689#ifdef WLAN_FEATURE_P2P_DEBUG
4690 if (((globalP2PConnectionStatus == P2P_GO_NEG_COMPLETED) ||
4691 (globalP2PConnectionStatus == P2P_GO_NEG_PROCESS)) &&
4692 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
4693 {
4694 globalP2PConnectionStatus = P2P_CLIENT_CONNECTING_STATE_1;
4695 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P State] Changing state from "
4696 "Go nego completed to Connection is started");
4697 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P]P2P Scanning is started "
4698 "for 8way Handshake");
4699 }
4700 else if((globalP2PConnectionStatus == P2P_CLIENT_DISCONNECTED_STATE) &&
4701 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
4702 {
4703 globalP2PConnectionStatus = P2P_CLIENT_CONNECTING_STATE_2;
4704 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P State] Changing state from "
4705 "Disconnected state to Connection is started");
4706 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P]P2P Scanning is started "
4707 "for 4way Handshake");
4708 }
4709#endif
4710
Jeff Johnsone7245742012-09-05 17:12:55 -07004711 /* no_cck will be set during p2p find to disable 11b rates */
4712 if(TRUE == request->no_cck)
Jeff Johnson295189b2012-06-20 16:38:30 -07004713 {
Jeff Johnson295189b2012-06-20 16:38:30 -07004714 hddLog(VOS_TRACE_LEVEL_INFO,
4715 "%s: This is a P2P Search", __func__);
4716 scanRequest.p2pSearch = 1;
Jeff Johnsone7245742012-09-05 17:12:55 -07004717
Jeff Johnsone7245742012-09-05 17:12:55 -07004718 if( request->n_channels == WLAN_HDD_P2P_SOCIAL_CHANNELS )
4719 {
Madan Mohan Koyyalamudi1b1d9e82012-10-21 11:38:33 -07004720 /* set requestType to P2P Discovery */
4721 scanRequest.requestType = eCSR_SCAN_P2P_DISCOVERY;
Jeff Johnsone7245742012-09-05 17:12:55 -07004722 }
4723
4724 /*
4725 Skip Dfs Channel in case of P2P Search
4726 if it is set in ini file
4727 */
4728 if(cfg_param->skipDfsChnlInP2pSearch)
4729 {
4730 scanRequest.skipDfsChnlInP2pSearch = 1;
4731 }
4732 else
4733 {
4734 scanRequest.skipDfsChnlInP2pSearch = 0;
4735 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004736
Jeff Johnson295189b2012-06-20 16:38:30 -07004737 }
4738 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004739 }
4740 }
4741
4742 INIT_COMPLETION(pScanInfo->scan_req_completion_event);
4743
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07004744 /* acquire the wakelock to avoid the apps suspend during the scan. To
4745 * address the following issues.
4746 * 1) Disconnected scenario: we are not allowing the suspend as WLAN is not in
4747 * BMPS/IMPS this result in android trying to suspend aggressively and backing off
4748 * for long time, this result in apps running at full power for long time.
4749 * 2) Connected scenario: If we allow the suspend during the scan, RIVA will
4750 * be stuck in full power because of resume BMPS
4751 */
4752 hdd_prevent_suspend();
Jeff Johnsone7245742012-09-05 17:12:55 -07004753
4754 status = sme_ScanRequest( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07004755 pAdapter->sessionId, &scanRequest, &scanId,
4756 &hdd_cfg80211_scan_done_callback, dev );
Jeff Johnsone7245742012-09-05 17:12:55 -07004757
Jeff Johnson295189b2012-06-20 16:38:30 -07004758 if (eHAL_STATUS_SUCCESS != status)
4759 {
4760 hddLog(VOS_TRACE_LEVEL_ERROR,
4761 "%s: sme_ScanRequest returned error %d", __func__, status);
4762 complete(&pScanInfo->scan_req_completion_event);
Madan Mohan Koyyalamudi3b230fe2012-10-18 14:46:32 -07004763 if(eHAL_STATUS_RESOURCES == status)
4764 {
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07004765 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 -07004766 status = -EBUSY;
4767 } else {
4768 status = -EIO;
4769 }
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07004770 hdd_allow_suspend();
Jeff Johnson295189b2012-06-20 16:38:30 -07004771 goto free_mem;
4772 }
4773
4774 pScanInfo->mScanPending = TRUE;
4775 pAdapter->request = request;
4776 pScanInfo->scanId = scanId;
4777
4778 complete(&pScanInfo->scan_req_completion_event);
4779
4780free_mem:
4781 if( scanRequest.SSIDs.SSIDList )
4782 {
4783 vos_mem_free(scanRequest.SSIDs.SSIDList);
4784 }
4785
4786 if( channelList )
4787 vos_mem_free( channelList );
4788
4789 EXIT();
4790
4791 return status;
4792}
4793
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07004794
4795void hdd_select_cbmode( hdd_adapter_t *pAdapter,v_U8_t operationChannel)
4796{
4797 v_U8_t iniDot11Mode =
4798 (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini->dot11Mode;
4799 eHddDot11Mode hddDot11Mode = iniDot11Mode;
4800
4801 switch ( iniDot11Mode )
4802 {
4803 case eHDD_DOT11_MODE_AUTO:
4804 case eHDD_DOT11_MODE_11ac:
4805 case eHDD_DOT11_MODE_11ac_ONLY:
4806#ifdef WLAN_FEATURE_11AC
4807 hddDot11Mode = eHDD_DOT11_MODE_11ac;
4808#else
4809 hddDot11Mode = eHDD_DOT11_MODE_11n;
4810#endif
4811 break;
4812 case eHDD_DOT11_MODE_11n:
4813 case eHDD_DOT11_MODE_11n_ONLY:
4814 hddDot11Mode = eHDD_DOT11_MODE_11n;
4815 break;
4816 default:
4817 hddDot11Mode = iniDot11Mode;
4818 break;
4819 }
4820 /* This call decides required channel bonding mode */
4821 sme_SelectCBMode((WLAN_HDD_GET_CTX(pAdapter)->hHal),
4822 hdd_cfg_xlate_to_csr_phy_mode(hddDot11Mode),
4823 operationChannel);
4824}
4825
Jeff Johnson295189b2012-06-20 16:38:30 -07004826/*
4827 * FUNCTION: wlan_hdd_cfg80211_connect_start
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304828 * This function is used to start the association process
Jeff Johnson295189b2012-06-20 16:38:30 -07004829 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304830int wlan_hdd_cfg80211_connect_start( hdd_adapter_t *pAdapter,
Jeff Johnson32d95a32012-09-10 13:15:23 -07004831 const u8 *ssid, size_t ssid_len, const u8 *bssid, u8 operatingChannel)
Jeff Johnson295189b2012-06-20 16:38:30 -07004832{
4833 int status = 0;
4834 hdd_wext_state_t *pWextState;
4835 v_U32_t roamId;
4836 tCsrRoamProfile *pRoamProfile;
4837 eMib_dot11DesiredBssType connectedBssType;
4838 eCsrAuthType RSNAuthType;
4839
4840 ENTER();
4841
4842 pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304843
Jeff Johnson295189b2012-06-20 16:38:30 -07004844 if (SIR_MAC_MAX_SSID_LENGTH < ssid_len)
4845 {
4846 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: wrong SSID len", __func__);
4847 return -EINVAL;
4848 }
4849
4850 pRoamProfile = &pWextState->roamProfile;
4851
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304852 if (pRoamProfile)
Jeff Johnson295189b2012-06-20 16:38:30 -07004853 {
Jeff Johnsone7245742012-09-05 17:12:55 -07004854 int ret = 0;
4855 hdd_station_ctx_t *pHddStaCtx;
4856 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
4857 hdd_connGetConnectedBssType(pHddStaCtx,&connectedBssType );
4858
4859 if((eMib_dot11DesiredBssType_independent == connectedBssType) ||
4860 (eConnectionState_Associated == pHddStaCtx->conn_info.connState) ||
4861 (eConnectionState_IbssConnected == pHddStaCtx->conn_info.connState))
Jeff Johnson295189b2012-06-20 16:38:30 -07004862 {
4863 /* Issue disconnect to CSR */
4864 INIT_COMPLETION(pAdapter->disconnect_comp_var);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304865 if( eHAL_STATUS_SUCCESS ==
Jeff Johnson295189b2012-06-20 16:38:30 -07004866 sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
4867 pAdapter->sessionId,
4868 eCSR_DISCONNECT_REASON_UNSPECIFIED ) )
4869 {
Jeff Johnsone7245742012-09-05 17:12:55 -07004870 ret = wait_for_completion_interruptible_timeout(
4871 &pAdapter->disconnect_comp_var,
4872 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
4873 if (0 == ret)
4874 {
4875 VOS_ASSERT(0);
4876 }
4877 }
4878 }
4879 else if(eConnectionState_Disconnecting == pHddStaCtx->conn_info.connState)
4880 {
4881 ret = wait_for_completion_interruptible_timeout(
4882 &pAdapter->disconnect_comp_var,
4883 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
4884 if (0 == ret)
4885 {
4886 VOS_ASSERT(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004887 }
4888 }
4889
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304890 if (HDD_WMM_USER_MODE_NO_QOS ==
Jeff Johnson295189b2012-06-20 16:38:30 -07004891 (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini->WmmMode)
4892 {
4893 /*QoS not enabled in cfg file*/
4894 pRoamProfile->uapsd_mask = 0;
4895 }
4896 else
4897 {
4898 /*QoS enabled, update uapsd mask from cfg file*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304899 pRoamProfile->uapsd_mask =
Jeff Johnson295189b2012-06-20 16:38:30 -07004900 (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini->UapsdMask;
4901 }
4902
4903 pRoamProfile->SSIDs.numOfSSIDs = 1;
4904 pRoamProfile->SSIDs.SSIDList->SSID.length = ssid_len;
4905 vos_mem_zero(pRoamProfile->SSIDs.SSIDList->SSID.ssId,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304906 sizeof(pRoamProfile->SSIDs.SSIDList->SSID.ssId));
Jeff Johnson295189b2012-06-20 16:38:30 -07004907 vos_mem_copy((void *)(pRoamProfile->SSIDs.SSIDList->SSID.ssId),
4908 ssid, ssid_len);
4909
4910 if (bssid)
4911 {
4912 pRoamProfile->BSSIDs.numOfBSSIDs = 1;
4913 vos_mem_copy((void *)(pRoamProfile->BSSIDs.bssid), bssid,
4914 WNI_CFG_BSSID_LEN);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304915 /* Save BSSID in seperate variable as well, as RoamProfile
4916 BSSID is getting zeroed out in the association process. And in
Jeff Johnson295189b2012-06-20 16:38:30 -07004917 case of join failure we should send valid BSSID to supplicant
4918 */
4919 vos_mem_copy((void *)(pWextState->req_bssId), bssid,
4920 WNI_CFG_BSSID_LEN);
4921 }
Dhanashri Atre51981c62013-06-13 11:47:57 -07004922 else
4923 {
4924 vos_mem_zero((void *)(pRoamProfile->BSSIDs.bssid),WNI_CFG_BSSID_LEN);
4925 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004926
4927 if ((IW_AUTH_WPA_VERSION_WPA == pWextState->wpaVersion) ||
4928 (IW_AUTH_WPA_VERSION_WPA2 == pWextState->wpaVersion))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304929 {
Jeff Johnson295189b2012-06-20 16:38:30 -07004930 /*set gen ie*/
4931 hdd_SetGENIEToCsr(pAdapter, &RSNAuthType);
4932 /*set auth*/
4933 hdd_set_csr_auth_type(pAdapter, RSNAuthType);
4934 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004935#ifdef FEATURE_WLAN_WAPI
4936 if (pAdapter->wapi_info.nWapiMode)
4937 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07004938 hddLog(LOG1, "%s: Setting WAPI AUTH Type and Encryption Mode values", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07004939 switch (pAdapter->wapi_info.wapiAuthMode)
4940 {
4941 case WAPI_AUTH_MODE_PSK:
4942 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07004943 hddLog(LOG1, "%s: WAPI AUTH TYPE: PSK: %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07004944 pAdapter->wapi_info.wapiAuthMode);
4945 pRoamProfile->AuthType.authType[0] = eCSR_AUTH_TYPE_WAPI_WAI_PSK;
4946 break;
4947 }
4948 case WAPI_AUTH_MODE_CERT:
4949 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07004950 hddLog(LOG1, "%s: WAPI AUTH TYPE: CERT: %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07004951 pAdapter->wapi_info.wapiAuthMode);
4952 pRoamProfile->AuthType.authType[0] = eCSR_AUTH_TYPE_WAPI_WAI_CERTIFICATE;
4953 break;
4954 }
4955 } // End of switch
4956 if ( pAdapter->wapi_info.wapiAuthMode == WAPI_AUTH_MODE_PSK ||
4957 pAdapter->wapi_info.wapiAuthMode == WAPI_AUTH_MODE_CERT)
4958 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07004959 hddLog(LOG1, "%s: WAPI PAIRWISE/GROUP ENCRYPTION: WPI", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07004960 pRoamProfile->AuthType.numEntries = 1;
4961 pRoamProfile->EncryptionType.numEntries = 1;
4962 pRoamProfile->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_WPI;
4963 pRoamProfile->mcEncryptionType.numEntries = 1;
4964 pRoamProfile->mcEncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_WPI;
4965 }
4966 }
4967#endif /* FEATURE_WLAN_WAPI */
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05304968#ifdef WLAN_FEATURE_GTK_OFFLOAD
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05304969 /* Initializing gtkOffloadReqParams */
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05304970 if ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
4971 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
4972 {
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05304973 memset(&pHddStaCtx->gtkOffloadReqParams, 0,
4974 sizeof (tSirGtkOffloadParams));
4975 pHddStaCtx->gtkOffloadReqParams.ulFlags = GTK_OFFLOAD_DISABLE;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05304976 }
4977#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004978 pRoamProfile->csrPersona = pAdapter->device_mode;
4979
Jeff Johnson32d95a32012-09-10 13:15:23 -07004980 if( operatingChannel )
4981 {
4982 pRoamProfile->ChannelInfo.ChannelList = &operatingChannel;
4983 pRoamProfile->ChannelInfo.numOfChannels = 1;
4984 }
Chet Lanctot186b5732013-03-18 10:26:30 -07004985 else
4986 {
4987 pRoamProfile->ChannelInfo.ChannelList = NULL;
4988 pRoamProfile->ChannelInfo.numOfChannels = 0;
4989 }
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07004990 if ( (WLAN_HDD_IBSS == pAdapter->device_mode) && operatingChannel)
4991 {
4992 hdd_select_cbmode(pAdapter,operatingChannel);
4993 }
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08004994 /* change conn_state to connecting before sme_RoamConnect(), because sme_RoamConnect()
4995 * has a direct path to call hdd_smeRoamCallback(), which will change the conn_state
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304996 * If direct path, conn_state will be accordingly changed to NotConnected or Associated
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08004997 * by either hdd_AssociationCompletionHandler() or hdd_DisConnectHandler() in sme_RoamCallback()
Madan Mohan Koyyalamudidf86c422012-12-04 17:03:44 -08004998 * if sme_RomConnect is to be queued, Connecting state will remain until it is completed.
4999 */
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +05305000 if (WLAN_HDD_INFRA_STATION == pAdapter->device_mode ||
5001 WLAN_HDD_P2P_CLIENT == pAdapter->device_mode)
Madan Mohan Koyyalamudidf86c422012-12-04 17:03:44 -08005002 hdd_connSetConnectionState(WLAN_HDD_GET_STATION_CTX_PTR(pAdapter),
5003 eConnectionState_Connecting);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305004
5005 status = sme_RoamConnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07005006 pAdapter->sessionId, pRoamProfile, &roamId);
5007
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +05305008 if ((eHAL_STATUS_SUCCESS != status) &&
5009 (WLAN_HDD_INFRA_STATION == pAdapter->device_mode ||
5010 WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
Madan Mohan Koyyalamudid5acbf52012-11-28 01:45:08 +05305011
5012 {
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08005013 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: sme_RoamConnect (session %d) failed with "
5014 "status %d. -> NotConnected", __func__, pAdapter->sessionId, status);
5015 /* change back to NotAssociated */
Madan Mohan Koyyalamudid5acbf52012-11-28 01:45:08 +05305016 hdd_connSetConnectionState(WLAN_HDD_GET_STATION_CTX_PTR(pAdapter),
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08005017 eConnectionState_NotConnected);
Madan Mohan Koyyalamudid5acbf52012-11-28 01:45:08 +05305018 }
Madan Mohan Koyyalamudidf86c422012-12-04 17:03:44 -08005019
5020 pRoamProfile->ChannelInfo.ChannelList = NULL;
5021 pRoamProfile->ChannelInfo.numOfChannels = 0;
5022
Jeff Johnson295189b2012-06-20 16:38:30 -07005023 }
5024 else
5025 {
5026 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: No valid Roam profile", __func__);
5027 return -EINVAL;
5028 }
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08005029 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07005030 return status;
5031}
5032
5033/*
5034 * FUNCTION: wlan_hdd_set_cfg80211_auth_type
5035 * This function is used to set the authentication type (OPEN/SHARED).
5036 *
5037 */
5038static int wlan_hdd_cfg80211_set_auth_type(hdd_adapter_t *pAdapter,
5039 enum nl80211_auth_type auth_type)
5040{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305041 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07005042 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
5043
5044 ENTER();
5045
5046 /*set authentication type*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305047 switch (auth_type)
Jeff Johnson295189b2012-06-20 16:38:30 -07005048 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005049 case NL80211_AUTHTYPE_AUTOMATIC:
Gopichand Nakkala29149562013-05-10 21:43:41 +05305050 hddLog(VOS_TRACE_LEVEL_INFO,
5051 "%s: set authentication type to AUTOSWITCH", __func__);
5052 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_AUTOSWITCH;
5053 break;
5054
5055 case NL80211_AUTHTYPE_OPEN_SYSTEM:
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07005056#ifdef WLAN_FEATURE_VOWIFI_11R
5057 case NL80211_AUTHTYPE_FT:
5058#endif /* WLAN_FEATURE_VOWIFI_11R */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305059 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07005060 "%s: set authentication type to OPEN", __func__);
5061 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
5062 break;
5063
5064 case NL80211_AUTHTYPE_SHARED_KEY:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305065 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07005066 "%s: set authentication type to SHARED", __func__);
5067 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_SHARED_KEY;
5068 break;
5069#ifdef FEATURE_WLAN_CCX
5070 case NL80211_AUTHTYPE_NETWORK_EAP:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305071 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07005072 "%s: set authentication type to CCKM WPA", __func__);
5073 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_CCKM_WPA;//eCSR_AUTH_TYPE_CCKM_RSN needs to be handled as well if required.
5074 break;
5075#endif
5076
5077
5078 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305079 hddLog(VOS_TRACE_LEVEL_ERROR,
5080 "%s: Unsupported authentication type %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07005081 auth_type);
5082 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_UNKNOWN;
5083 return -EINVAL;
5084 }
5085
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305086 pWextState->roamProfile.AuthType.authType[0] =
Jeff Johnson295189b2012-06-20 16:38:30 -07005087 pHddStaCtx->conn_info.authType;
5088 return 0;
5089}
5090
5091/*
5092 * FUNCTION: wlan_hdd_set_akm_suite
5093 * This function is used to set the key mgmt type(PSK/8021x).
5094 *
5095 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305096static int wlan_hdd_set_akm_suite( hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07005097 u32 key_mgmt
5098 )
5099{
5100 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
5101 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305102
Jeff Johnson295189b2012-06-20 16:38:30 -07005103 /*set key mgmt type*/
5104 switch(key_mgmt)
5105 {
5106 case WLAN_AKM_SUITE_PSK:
Gopichand Nakkala356fb102013-03-06 12:34:04 +05305107#ifdef WLAN_FEATURE_VOWIFI_11R
5108 case WLAN_AKM_SUITE_FT_PSK:
5109#endif
5110 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting key mgmt type to PSK",
Jeff Johnson295189b2012-06-20 16:38:30 -07005111 __func__);
5112 pWextState->authKeyMgmt |= IW_AUTH_KEY_MGMT_PSK;
5113 break;
5114
5115 case WLAN_AKM_SUITE_8021X:
Gopichand Nakkala356fb102013-03-06 12:34:04 +05305116#ifdef WLAN_FEATURE_VOWIFI_11R
5117 case WLAN_AKM_SUITE_FT_8021X:
5118#endif
5119 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting key mgmt type to 8021x",
Jeff Johnson295189b2012-06-20 16:38:30 -07005120 __func__);
5121 pWextState->authKeyMgmt |= IW_AUTH_KEY_MGMT_802_1X;
5122 break;
5123#ifdef FEATURE_WLAN_CCX
5124#define WLAN_AKM_SUITE_CCKM 0x00409600 /* Should be in ieee802_11_defs.h */
5125#define IW_AUTH_KEY_MGMT_CCKM 8 /* Should be in linux/wireless.h */
5126 case WLAN_AKM_SUITE_CCKM:
5127 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting key mgmt type to CCKM",
5128 __func__);
5129 pWextState->authKeyMgmt |= IW_AUTH_KEY_MGMT_CCKM;
5130 break;
5131#endif
5132
5133 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305134 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported key mgmt type %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005135 __func__, key_mgmt);
5136 return -EINVAL;
5137
5138 }
5139 return 0;
5140}
5141
5142/*
5143 * FUNCTION: wlan_hdd_cfg80211_set_cipher
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305144 * This function is used to set the encryption type
Jeff Johnson295189b2012-06-20 16:38:30 -07005145 * (NONE/WEP40/WEP104/TKIP/CCMP).
5146 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305147static int wlan_hdd_cfg80211_set_cipher( hdd_adapter_t *pAdapter,
5148 u32 cipher,
Jeff Johnson295189b2012-06-20 16:38:30 -07005149 bool ucast
5150 )
5151{
5152 eCsrEncryptionType encryptionType = eCSR_ENCRYPT_TYPE_NONE;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305153 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07005154 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
5155
5156 ENTER();
5157
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305158 if (!cipher)
Jeff Johnson295189b2012-06-20 16:38:30 -07005159 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305160 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: received cipher %d - considering none",
Jeff Johnson295189b2012-06-20 16:38:30 -07005161 __func__, cipher);
5162 encryptionType = eCSR_ENCRYPT_TYPE_NONE;
5163 }
5164 else
5165 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305166
Jeff Johnson295189b2012-06-20 16:38:30 -07005167 /*set encryption method*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305168 switch (cipher)
Jeff Johnson295189b2012-06-20 16:38:30 -07005169 {
5170 case IW_AUTH_CIPHER_NONE:
5171 encryptionType = eCSR_ENCRYPT_TYPE_NONE;
5172 break;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305173
Jeff Johnson295189b2012-06-20 16:38:30 -07005174 case WLAN_CIPHER_SUITE_WEP40:
Gopichand Nakkala29149562013-05-10 21:43:41 +05305175 encryptionType = eCSR_ENCRYPT_TYPE_WEP40;
Jeff Johnson295189b2012-06-20 16:38:30 -07005176 break;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305177
Jeff Johnson295189b2012-06-20 16:38:30 -07005178 case WLAN_CIPHER_SUITE_WEP104:
Gopichand Nakkala29149562013-05-10 21:43:41 +05305179 encryptionType = eCSR_ENCRYPT_TYPE_WEP104;
Jeff Johnson295189b2012-06-20 16:38:30 -07005180 break;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305181
Jeff Johnson295189b2012-06-20 16:38:30 -07005182 case WLAN_CIPHER_SUITE_TKIP:
5183 encryptionType = eCSR_ENCRYPT_TYPE_TKIP;
5184 break;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305185
Jeff Johnson295189b2012-06-20 16:38:30 -07005186 case WLAN_CIPHER_SUITE_CCMP:
5187 encryptionType = eCSR_ENCRYPT_TYPE_AES;
5188 break;
5189#ifdef FEATURE_WLAN_WAPI
5190 case WLAN_CIPHER_SUITE_SMS4:
5191 encryptionType = eCSR_ENCRYPT_TYPE_WPI;
5192 break;
5193#endif
5194
5195#ifdef FEATURE_WLAN_CCX
5196 case WLAN_CIPHER_SUITE_KRK:
5197 encryptionType = eCSR_ENCRYPT_TYPE_KRK;
5198 break;
5199#endif
5200 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305201 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported cipher type %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005202 __func__, cipher);
5203 return -EOPNOTSUPP;
5204 }
5205 }
5206
5207 if (ucast)
5208 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305209 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting unicast cipher type to %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005210 __func__, encryptionType);
5211 pHddStaCtx->conn_info.ucEncryptionType = encryptionType;
5212 pWextState->roamProfile.EncryptionType.numEntries = 1;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305213 pWextState->roamProfile.EncryptionType.encryptionType[0] =
Jeff Johnson295189b2012-06-20 16:38:30 -07005214 encryptionType;
5215 }
5216 else
5217 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305218 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting mcast cipher type to %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005219 __func__, encryptionType);
5220 pHddStaCtx->conn_info.mcEncryptionType = encryptionType;
5221 pWextState->roamProfile.mcEncryptionType.numEntries = 1;
5222 pWextState->roamProfile.mcEncryptionType.encryptionType[0] = encryptionType;
5223 }
5224
5225 return 0;
5226}
5227
5228
5229/*
5230 * FUNCTION: wlan_hdd_cfg80211_set_ie
5231 * This function is used to parse WPA/RSN IE's.
5232 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305233int wlan_hdd_cfg80211_set_ie( hdd_adapter_t *pAdapter,
5234 u8 *ie,
Jeff Johnson295189b2012-06-20 16:38:30 -07005235 size_t ie_len
5236 )
5237{
5238 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
5239 u8 *genie = ie;
5240 v_U16_t remLen = ie_len;
5241#ifdef FEATURE_WLAN_WAPI
5242 v_U32_t akmsuite[MAX_NUM_AKM_SUITES];
5243 u16 *tmp;
5244 v_U16_t akmsuiteCount;
5245 int *akmlist;
5246#endif
5247 ENTER();
5248
5249 /* clear previous assocAddIE */
5250 pWextState->assocAddIE.length = 0;
5251 pWextState->roamProfile.bWPSAssociation = VOS_FALSE;
5252
5253 while (remLen >= 2)
5254 {
5255 v_U16_t eLen = 0;
5256 v_U8_t elementId;
5257 elementId = *genie++;
5258 eLen = *genie++;
5259 remLen -= 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305260
5261 hddLog(VOS_TRACE_LEVEL_INFO, "%s: IE[0x%X], LEN[%d]\n",
Jeff Johnson295189b2012-06-20 16:38:30 -07005262 __func__, elementId, eLen);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305263
5264 switch ( elementId )
Jeff Johnson295189b2012-06-20 16:38:30 -07005265 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305266 case DOT11F_EID_WPA:
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005267 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 -07005268 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305269 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005270 "%s: Invalid WPA IE", __func__);
5271 return -EINVAL;
5272 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305273 else if (0 == memcmp(&genie[0], "\x00\x50\xf2\x04", 4))
Jeff Johnson295189b2012-06-20 16:38:30 -07005274 {
5275 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305276 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set WPS IE(len %d)",
Jeff Johnson295189b2012-06-20 16:38:30 -07005277 __func__, eLen + 2);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305278
Jeff Johnson295189b2012-06-20 16:38:30 -07005279 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5280 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005281 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE. "
5282 "Need bigger buffer space");
Jeff Johnson295189b2012-06-20 16:38:30 -07005283 VOS_ASSERT(0);
5284 return -ENOMEM;
5285 }
5286 // WSC IE is saved to Additional IE ; it should be accumulated to handle WPS IE + P2P IE
5287 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5288 pWextState->assocAddIE.length += eLen + 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305289
Jeff Johnson295189b2012-06-20 16:38:30 -07005290 pWextState->roamProfile.bWPSAssociation = VOS_TRUE;
5291 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5292 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5293 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305294 else if (0 == memcmp(&genie[0], "\x00\x50\xf2", 3))
5295 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005296 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set WPA IE (len %d)",__func__, eLen + 2);
5297 memset( pWextState->WPARSNIE, 0, MAX_WPA_RSN_IE_LEN );
5298 memcpy( pWextState->WPARSNIE, genie - 2, (eLen + 2) /*ie_len*/);
5299 pWextState->roamProfile.pWPAReqIE = pWextState->WPARSNIE;
5300 pWextState->roamProfile.nWPAReqIELength = eLen + 2;//ie_len;
5301 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305302 else if ( (0 == memcmp(&genie[0], P2P_OUI_TYPE,
5303 P2P_OUI_TYPE_SIZE))
Jeff Johnson295189b2012-06-20 16:38:30 -07005304 /*Consider P2P IE, only for P2P Client */
5305 && (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) )
5306 {
5307 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305308 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set P2P IE(len %d)",
Jeff Johnson295189b2012-06-20 16:38:30 -07005309 __func__, eLen + 2);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305310
Jeff Johnson295189b2012-06-20 16:38:30 -07005311 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5312 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005313 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
5314 "Need bigger buffer space");
Jeff Johnson295189b2012-06-20 16:38:30 -07005315 VOS_ASSERT(0);
5316 return -ENOMEM;
5317 }
5318 // P2P IE is saved to Additional IE ; it should be accumulated to handle WPS IE + P2P IE
5319 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5320 pWextState->assocAddIE.length += eLen + 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305321
Jeff Johnson295189b2012-06-20 16:38:30 -07005322 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5323 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5324 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005325#ifdef WLAN_FEATURE_WFD
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305326 else if ( (0 == memcmp(&genie[0], WFD_OUI_TYPE,
5327 WFD_OUI_TYPE_SIZE))
Jeff Johnson295189b2012-06-20 16:38:30 -07005328 /*Consider WFD IE, only for P2P Client */
5329 && (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) )
5330 {
5331 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305332 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set WFD IE(len %d)",
Jeff Johnson295189b2012-06-20 16:38:30 -07005333 __func__, eLen + 2);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305334
Jeff Johnson295189b2012-06-20 16:38:30 -07005335 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5336 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005337 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
5338 "Need bigger buffer space");
Jeff Johnson295189b2012-06-20 16:38:30 -07005339 VOS_ASSERT(0);
5340 return -ENOMEM;
5341 }
5342 // WFD IE is saved to Additional IE ; it should be accumulated to handle
5343 // WPS IE + P2P IE + WFD IE
5344 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5345 pWextState->assocAddIE.length += eLen + 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305346
Jeff Johnson295189b2012-06-20 16:38:30 -07005347 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5348 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5349 }
5350#endif
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005351 /* Appending HS 2.0 Indication Element in Assiciation Request */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305352 else if ( (0 == memcmp(&genie[0], HS20_OUI_TYPE,
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005353 HS20_OUI_TYPE_SIZE)) )
5354 {
5355 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305356 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set HS20 IE(len %d)",
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005357 __func__, eLen + 2);
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005358
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005359 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5360 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005361 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
5362 "Need bigger buffer space");
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005363 VOS_ASSERT(0);
5364 return -ENOMEM;
5365 }
5366 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5367 pWextState->assocAddIE.length += eLen + 2;
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005368
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005369 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5370 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5371 }
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005372
Jeff Johnson295189b2012-06-20 16:38:30 -07005373 break;
5374 case DOT11F_EID_RSN:
5375 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set RSN IE(len %d)",__func__, eLen + 2);
5376 memset( pWextState->WPARSNIE, 0, MAX_WPA_RSN_IE_LEN );
5377 memcpy( pWextState->WPARSNIE, genie - 2, (eLen + 2)/*ie_len*/);
5378 pWextState->roamProfile.pRSNReqIE = pWextState->WPARSNIE;
5379 pWextState->roamProfile.nRSNReqIELength = eLen + 2; //ie_len;
5380 break;
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005381 /* Appending Extended Capabilities with Interworking bit set in Assoc Req */
5382 case DOT11F_EID_EXTCAP:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305383 {
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005384 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305385 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set Extended CAPS IE(len %d)",
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005386 __func__, eLen + 2);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305387
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005388 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5389 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005390 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
5391 "Need bigger buffer space");
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005392 VOS_ASSERT(0);
5393 return -ENOMEM;
5394 }
5395 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5396 pWextState->assocAddIE.length += eLen + 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305397
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005398 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5399 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5400 break;
5401 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005402#ifdef FEATURE_WLAN_WAPI
5403 case WLAN_EID_WAPI:
5404 pAdapter->wapi_info.nWapiMode = 1; //Setting WAPI Mode to ON=1
5405 hddLog(VOS_TRACE_LEVEL_INFO,"WAPI MODE IS %lu \n",
5406 pAdapter->wapi_info.nWapiMode);
5407 tmp = (u16 *)ie;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305408 tmp = tmp + 2; // Skip element Id and Len, Version
Jeff Johnson295189b2012-06-20 16:38:30 -07005409 akmsuiteCount = WPA_GET_LE16(tmp);
5410 tmp = tmp + 1;
5411 akmlist = (int *)(tmp);
5412 if(akmsuiteCount <= MAX_NUM_AKM_SUITES)
5413 {
5414 memcpy(akmsuite, akmlist, (4*akmsuiteCount));
5415 }
5416 else
5417 {
5418 hddLog(VOS_TRACE_LEVEL_FATAL, "Invalid akmSuite count\n");
5419 VOS_ASSERT(0);
5420 return -EINVAL;
5421 }
5422
5423 if (WAPI_PSK_AKM_SUITE == akmsuite[0])
5424 {
5425 hddLog(VOS_TRACE_LEVEL_INFO, "%s: WAPI AUTH MODE SET TO PSK",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005426 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005427 pAdapter->wapi_info.wapiAuthMode = WAPI_AUTH_MODE_PSK;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305428 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005429 if (WAPI_CERT_AKM_SUITE == akmsuite[0])
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305430 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005431 hddLog(VOS_TRACE_LEVEL_INFO, "%s: WAPI AUTH MODE SET TO CERTIFICATE",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005432 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005433 pAdapter->wapi_info.wapiAuthMode = WAPI_AUTH_MODE_CERT;
5434 }
5435 break;
5436#endif
5437 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305438 hddLog (VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005439 "%s Set UNKNOWN IE %X", __func__, elementId);
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005440 /* when Unknown IE is received we should break and continue
5441 * to the next IE in the buffer instead we were returning
5442 * so changing this to break */
5443 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07005444 }
5445 genie += eLen;
5446 remLen -= eLen;
5447 }
5448 EXIT();
5449 return 0;
5450}
5451
5452/*
Gopichand Nakkala18f0c262013-05-07 23:25:08 +05305453 * FUNCTION: hdd_isWPAIEPresent
5454 * Parse the received IE to find the WPA IE
5455 *
5456 */
5457static bool hdd_isWPAIEPresent(u8 *ie, u8 ie_len)
5458{
5459 v_U8_t eLen = 0;
5460 v_U16_t remLen = ie_len;
5461 v_U8_t elementId = 0;
5462
5463 while (remLen >= 2)
5464 {
5465 elementId = *ie++;
5466 eLen = *ie++;
5467 remLen -= 2;
5468 if (eLen > remLen)
5469 {
5470 hddLog(VOS_TRACE_LEVEL_ERROR,
5471 "%s: IE length is wrong %d", __func__, eLen);
5472 return FALSE;
5473 }
5474 if ((elementId == DOT11F_EID_WPA) && (remLen > 5))
5475 {
5476 /* OUI - 0x00 0X50 0XF2
5477 WPA Information Element - 0x01
5478 WPA version - 0x01*/
5479 if (0 == memcmp(&ie[0], "\x00\x50\xf2\x01\x01", 5))
5480 return TRUE;
5481 }
5482 ie += eLen;
5483 remLen -= eLen;
5484 }
5485 return FALSE;
5486}
5487
5488/*
Jeff Johnson295189b2012-06-20 16:38:30 -07005489 * FUNCTION: wlan_hdd_cfg80211_set_privacy
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305490 * This function is used to initialize the security
Jeff Johnson295189b2012-06-20 16:38:30 -07005491 * parameters during connect operation.
5492 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305493int wlan_hdd_cfg80211_set_privacy( hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07005494 struct cfg80211_connect_params *req
5495 )
5496{
5497 int status = 0;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305498 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07005499 ENTER();
5500
5501 /*set wpa version*/
5502 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_DISABLED;
5503
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305504 if (req->crypto.wpa_versions)
Jeff Johnson295189b2012-06-20 16:38:30 -07005505 {
Gopichand Nakkala781ded42013-06-28 12:10:45 +05305506 if (NL80211_WPA_VERSION_1 == req->crypto.wpa_versions)
Jeff Johnson295189b2012-06-20 16:38:30 -07005507 {
5508 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA;
5509 }
5510 else if (NL80211_WPA_VERSION_2 == req->crypto.wpa_versions)
5511 {
5512 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA2;
5513 }
5514 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305515
5516 hddLog(VOS_TRACE_LEVEL_INFO, "%s: set wpa version to %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07005517 pWextState->wpaVersion);
5518
5519 /*set authentication type*/
5520 status = wlan_hdd_cfg80211_set_auth_type(pAdapter, req->auth_type);
5521
5522 if (0 > status)
5523 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305524 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005525 "%s: failed to set authentication type ", __func__);
5526 return status;
5527 }
5528
5529 /*set key mgmt type*/
5530 if (req->crypto.n_akm_suites)
5531 {
5532 status = wlan_hdd_set_akm_suite(pAdapter, req->crypto.akm_suites[0]);
5533 if (0 > status)
5534 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305535 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set akm suite",
Jeff Johnson295189b2012-06-20 16:38:30 -07005536 __func__);
5537 return status;
5538 }
5539 }
5540
5541 /*set pairwise cipher type*/
5542 if (req->crypto.n_ciphers_pairwise)
5543 {
5544 status = wlan_hdd_cfg80211_set_cipher(pAdapter,
5545 req->crypto.ciphers_pairwise[0], true);
5546 if (0 > status)
5547 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305548 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005549 "%s: failed to set unicast cipher type", __func__);
5550 return status;
5551 }
5552 }
5553 else
5554 {
5555 /*Reset previous cipher suite to none*/
5556 status = wlan_hdd_cfg80211_set_cipher(pAdapter, 0, true);
5557 if (0 > status)
5558 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305559 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005560 "%s: failed to set unicast cipher type", __func__);
5561 return status;
5562 }
5563 }
5564
5565 /*set group cipher type*/
5566 status = wlan_hdd_cfg80211_set_cipher(pAdapter, req->crypto.cipher_group,
5567 false);
5568
5569 if (0 > status)
5570 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305571 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set mcast cipher type",
Jeff Johnson295189b2012-06-20 16:38:30 -07005572 __func__);
5573 return status;
5574 }
5575
Chet Lanctot186b5732013-03-18 10:26:30 -07005576#ifdef WLAN_FEATURE_11W
5577 pWextState->roamProfile.MFPEnabled = (req->mfp == NL80211_MFP_REQUIRED);
5578#endif
5579
Jeff Johnson295189b2012-06-20 16:38:30 -07005580 /*parse WPA/RSN IE, and set the correspoing fileds in Roam profile*/
5581 if (req->ie_len)
5582 {
5583 status = wlan_hdd_cfg80211_set_ie(pAdapter, req->ie, req->ie_len);
5584 if ( 0 > status)
5585 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305586 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to parse the WPA/RSN IE",
Jeff Johnson295189b2012-06-20 16:38:30 -07005587 __func__);
5588 return status;
5589 }
5590 }
5591
5592 /*incase of WEP set default key information*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305593 if (req->key && req->key_len)
Jeff Johnson295189b2012-06-20 16:38:30 -07005594 {
5595 if ( (WLAN_CIPHER_SUITE_WEP40 == req->crypto.ciphers_pairwise[0])
5596 || (WLAN_CIPHER_SUITE_WEP104 == req->crypto.ciphers_pairwise[0])
5597 )
5598 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305599 if ( IW_AUTH_KEY_MGMT_802_1X
Jeff Johnson295189b2012-06-20 16:38:30 -07005600 == (pWextState->authKeyMgmt & IW_AUTH_KEY_MGMT_802_1X ))
5601 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305602 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Dynamic WEP not supported",
Jeff Johnson295189b2012-06-20 16:38:30 -07005603 __func__);
5604 return -EOPNOTSUPP;
5605 }
5606 else
5607 {
5608 u8 key_len = req->key_len;
5609 u8 key_idx = req->key_idx;
5610
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305611 if ((eCSR_SECURITY_WEP_KEYSIZE_MAX_BYTES >= key_len)
Jeff Johnson295189b2012-06-20 16:38:30 -07005612 && (CSR_MAX_NUM_KEY > key_idx)
5613 )
5614 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305615 hddLog(VOS_TRACE_LEVEL_INFO,
5616 "%s: setting default wep key, key_idx = %hu key_len %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07005617 __func__, key_idx, key_len);
5618 vos_mem_copy(
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305619 &pWextState->roamProfile.Keys.KeyMaterial[key_idx][0],
Jeff Johnson295189b2012-06-20 16:38:30 -07005620 req->key, key_len);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305621 pWextState->roamProfile.Keys.KeyLength[key_idx] =
Jeff Johnson295189b2012-06-20 16:38:30 -07005622 (u8)key_len;
5623 pWextState->roamProfile.Keys.defaultIndex = (u8)key_idx;
5624 }
5625 }
5626 }
5627 }
5628
5629 return status;
5630}
5631
5632/*
5633 * FUNCTION: wlan_hdd_cfg80211_set_privacy
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305634 * This function is used to initialize the security
Jeff Johnson295189b2012-06-20 16:38:30 -07005635 * parameters during connect operation.
5636 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305637static int wlan_hdd_cfg80211_connect( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07005638 struct net_device *ndev,
5639 struct cfg80211_connect_params *req
5640 )
5641{
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305642 int status;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305643 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Jeff Johnson295189b2012-06-20 16:38:30 -07005644 VOS_STATUS exitbmpsStatus = VOS_STATUS_E_INVAL;
5645 hdd_context_t *pHddCtx = NULL;
5646
5647 ENTER();
5648
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305649 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07005650 "%s: device_mode = %d\n",__func__,pAdapter->device_mode);
5651
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305652 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
5653 status = wlan_hdd_validate_context(pHddCtx);
5654
5655 if (0 != status)
Jeff Johnson295189b2012-06-20 16:38:30 -07005656 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305657 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5658 "%s: HDD context is not valid", __func__);
5659 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07005660 }
5661
5662#ifdef WLAN_BTAMP_FEATURE
5663 //Infra connect not supported when AMP traffic is on.
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305664 if( VOS_TRUE == WLANBAP_AmpSessionOn() )
Jeff Johnson295189b2012-06-20 16:38:30 -07005665 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305666 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005667 "%s: No connection when AMP is on", __func__);
Madan Mohan Koyyalamudicae253a2012-11-06 19:10:35 -08005668 return -ECONNREFUSED;
Jeff Johnson295189b2012-06-20 16:38:30 -07005669 }
5670#endif
5671 /*initialise security parameters*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305672 status = wlan_hdd_cfg80211_set_privacy(pAdapter, req);
Jeff Johnson295189b2012-06-20 16:38:30 -07005673
5674 if ( 0 > status)
5675 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305676 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set security params",
Jeff Johnson295189b2012-06-20 16:38:30 -07005677 __func__);
5678 return status;
5679 }
5680
5681 //If Device Mode is Station Concurrent Sessions Exit BMps
Jeff Johnsona8a1a482012-12-12 16:49:33 -08005682 //P2P Mode will be taken care in Open/close adapter
Jeff Johnson295189b2012-06-20 16:38:30 -07005683 if((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) &&
5684 (vos_concurrent_sessions_running()))
5685 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305686 exitbmpsStatus = hdd_disable_bmps_imps(pHddCtx, WLAN_HDD_INFRA_STATION);
Jeff Johnson295189b2012-06-20 16:38:30 -07005687 }
5688
Mohit Khanna765234a2012-09-11 15:08:35 -07005689 if ( req->channel )
5690 {
5691 status = wlan_hdd_cfg80211_connect_start(pAdapter, req->ssid,
5692 req->ssid_len, req->bssid,
5693 req->channel->hw_value);
5694 }
5695 else
5696 {
5697 status = wlan_hdd_cfg80211_connect_start(pAdapter, req->ssid,
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305698 req->ssid_len, req->bssid, 0);
Mohit Khanna765234a2012-09-11 15:08:35 -07005699 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005700
5701 if (0 > status)
5702 {
5703 //ReEnable BMPS if disabled
5704 if((VOS_STATUS_SUCCESS == exitbmpsStatus) &&
5705 (NULL != pHddCtx))
5706 {
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05305707 if (pHddCtx->hdd_wlan_suspended)
5708 {
5709 hdd_set_pwrparams(pHddCtx);
5710 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005711 //ReEnable Bmps and Imps back
5712 hdd_enable_bmps_imps(pHddCtx);
5713 }
5714
5715 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: connect failed", __func__);
5716 return status;
5717 }
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305718 pHddCtx->isAmpAllowed = VOS_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005719 EXIT();
5720 return status;
5721}
5722
5723
5724/*
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05305725 * FUNCTION: wlan_hdd_disconnect
5726 * This function is used to issue a disconnect request to SME
5727 */
5728int wlan_hdd_disconnect( hdd_adapter_t *pAdapter, u16 reason )
5729{
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305730 int status;
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05305731 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305732 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
5733
5734 status = wlan_hdd_validate_context(pHddCtx);
5735
5736 if (0 != status)
5737 {
5738 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5739 "%s: HDD context is not valid", __func__);
5740 return status;
5741 }
5742
5743 pHddCtx->isAmpAllowed = VOS_TRUE;
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05305744 pHddStaCtx->conn_info.connState = eConnectionState_NotConnected;
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05305745 INIT_COMPLETION(pAdapter->disconnect_comp_var);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305746
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05305747 /*issue disconnect*/
5748 status = sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
5749 pAdapter->sessionId, reason);
5750
5751 if ( 0 != status )
5752 {
5753 hddLog(VOS_TRACE_LEVEL_ERROR,
5754 "%s csrRoamDisconnect failure, returned %d \n",
5755 __func__, (int)status );
5756 return -EINVAL;
5757 }
5758 wait_for_completion_interruptible_timeout(
5759 &pAdapter->disconnect_comp_var,
5760 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
5761 /*stop tx queues*/
5762 netif_tx_disable(pAdapter->dev);
5763 netif_carrier_off(pAdapter->dev);
5764 return status;
5765}
5766
5767
5768/*
Jeff Johnson295189b2012-06-20 16:38:30 -07005769 * FUNCTION: wlan_hdd_cfg80211_disconnect
5770 * This function is used to issue a disconnect request to SME
5771 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305772static int wlan_hdd_cfg80211_disconnect( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07005773 struct net_device *dev,
5774 u16 reason
5775 )
5776{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305777 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
5778 tCsrRoamProfile *pRoamProfile =
Jeff Johnson295189b2012-06-20 16:38:30 -07005779 &(WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter))->roamProfile;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305780 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07005781 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkala4327a152013-03-04 23:22:42 -08005782 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05305783#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08005784 tANI_U8 staIdx;
5785#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305786
Jeff Johnson295189b2012-06-20 16:38:30 -07005787 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305788
5789 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
Jeff Johnson295189b2012-06-20 16:38:30 -07005790 __func__,pAdapter->device_mode);
5791
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305792 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Disconnect called with reason code %d",
5793 __func__, reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07005794
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305795 status = wlan_hdd_validate_context(pHddCtx);
5796
5797 if (0 != status)
Jeff Johnson295189b2012-06-20 16:38:30 -07005798 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305799 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5800 "%s: HDD context is not valid", __func__);
5801 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07005802 }
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305803
Jeff Johnson295189b2012-06-20 16:38:30 -07005804 if (NULL != pRoamProfile)
5805 {
5806 /*issue disconnect request to SME, if station is in connected state*/
5807 if (pHddStaCtx->conn_info.connState == eConnectionState_Associated)
5808 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305809 eCsrRoamDisconnectReason reasonCode =
Jeff Johnson295189b2012-06-20 16:38:30 -07005810 eCSR_DISCONNECT_REASON_UNSPECIFIED;
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05305811 hdd_scaninfo_t *pScanInfo;
Jeff Johnson295189b2012-06-20 16:38:30 -07005812 switch(reason)
5813 {
5814 case WLAN_REASON_MIC_FAILURE:
5815 reasonCode = eCSR_DISCONNECT_REASON_MIC_ERROR;
5816 break;
5817
5818 case WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY:
5819 case WLAN_REASON_DISASSOC_AP_BUSY:
5820 case WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA:
5821 reasonCode = eCSR_DISCONNECT_REASON_DISASSOC;
5822 break;
5823
5824 case WLAN_REASON_PREV_AUTH_NOT_VALID:
5825 case WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA:
5826 reasonCode = eCSR_DISCONNECT_REASON_DEAUTH;
5827 break;
5828
5829 case WLAN_REASON_DEAUTH_LEAVING:
5830 default:
5831 reasonCode = eCSR_DISCONNECT_REASON_UNSPECIFIED;
5832 break;
5833 }
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05305834 pHddStaCtx->conn_info.connState = eConnectionState_NotConnected;
5835 pScanInfo = &pHddCtx->scan_info;
5836 if (pScanInfo->mScanPending)
5837 {
5838 hddLog(VOS_TRACE_LEVEL_INFO, "Disconnect is in progress, "
5839 "Aborting Scan");
5840 hdd_abort_mac_scan(pHddCtx);
5841 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005842
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08005843#ifdef FEATURE_WLAN_TDLS
5844 /* First clean up the tdls peers if any */
Gopichand Nakkala4327a152013-03-04 23:22:42 -08005845 for (staIdx = 0 ; staIdx < HDD_MAX_NUM_TDLS_STA; staIdx++)
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08005846 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08005847 if ((pHddCtx->tdlsConnInfo[staIdx].sessionId == pAdapter->sessionId) &&
5848 (pHddCtx->tdlsConnInfo[staIdx].staId))
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08005849 {
Hoonki Lee11f7dda2013-02-14 16:55:44 -08005850 uint8 *mac;
Gopichand Nakkala4327a152013-03-04 23:22:42 -08005851 mac = pHddCtx->tdlsConnInfo[staIdx].peerMac.bytes;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08005852 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07005853 "%s: call sme_DeleteTdlsPeerSta staId %d sessionId %d " MAC_ADDRESS_STR,
Gopichand Nakkala4327a152013-03-04 23:22:42 -08005854 __func__, pHddCtx->tdlsConnInfo[staIdx].staId, pAdapter->sessionId,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07005855 MAC_ADDR_ARRAY(mac));
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08005856 sme_DeleteTdlsPeerSta(WLAN_HDD_GET_HAL_CTX(pAdapter),
Gopichand Nakkala4327a152013-03-04 23:22:42 -08005857 pAdapter->sessionId,
5858 mac);
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08005859 }
5860 }
5861#endif
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05305862 status = wlan_hdd_disconnect(pAdapter, reasonCode);
5863 if ( 0 != status )
Jeff Johnson295189b2012-06-20 16:38:30 -07005864 {
5865 hddLog(VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05305866 "%s wlan_hdd_disconnect failure, returned %d \n",
Jeff Johnson295189b2012-06-20 16:38:30 -07005867 __func__, (int)status );
5868 return -EINVAL;
5869 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005870 }
5871 }
5872 else
5873 {
5874 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: No valid roam profile", __func__);
5875 }
5876
5877 return status;
5878}
5879
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05305880
Jeff Johnson295189b2012-06-20 16:38:30 -07005881/*
5882 * FUNCTION: wlan_hdd_cfg80211_set_privacy_ibss
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305883 * This function is used to initialize the security
Jeff Johnson295189b2012-06-20 16:38:30 -07005884 * settings in IBSS mode.
5885 */
5886static int wlan_hdd_cfg80211_set_privacy_ibss(
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305887 hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07005888 struct cfg80211_ibss_params *params
5889 )
5890{
5891 int status = 0;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305892 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07005893 eCsrEncryptionType encryptionType = eCSR_ENCRYPT_TYPE_NONE;
5894 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305895
Jeff Johnson295189b2012-06-20 16:38:30 -07005896 ENTER();
5897
5898 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_DISABLED;
5899
5900 if (params->ie_len && ( NULL != params->ie) )
5901 {
Shailender Karmuchi67edd312013-06-18 16:30:48 -07005902 if (wlan_hdd_cfg80211_get_ie_ptr (params->ie,
5903 params->ie_len, WLAN_EID_RSN ))
Jeff Johnson295189b2012-06-20 16:38:30 -07005904 {
5905 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA2;
5906 encryptionType = eCSR_ENCRYPT_TYPE_AES;
5907 }
Shailender Karmuchi67edd312013-06-18 16:30:48 -07005908 else if ( hdd_isWPAIEPresent (params->ie, params->ie_len ))
Jeff Johnson295189b2012-06-20 16:38:30 -07005909 {
Shailender Karmuchi642e9812013-05-30 14:34:49 -07005910 tDot11fIEWPA dot11WPAIE;
5911 tHalHandle halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
Shailender Karmuchi67edd312013-06-18 16:30:48 -07005912 u8 *ie;
Shailender Karmuchi642e9812013-05-30 14:34:49 -07005913
Shailender Karmuchi67edd312013-06-18 16:30:48 -07005914 ie = wlan_hdd_cfg80211_get_ie_ptr (params->ie,
5915 params->ie_len, DOT11F_EID_WPA);
5916 if ( NULL != ie )
5917 {
5918 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA;
5919 // Unpack the WPA IE
5920 //Skip past the EID byte and length byte - and four byte WiFi OUI
5921 dot11fUnpackIeWPA((tpAniSirGlobal) halHandle,
5922 &ie[2+4],
5923 ie[1] - 4,
5924 &dot11WPAIE);
5925 /*Extract the multicast cipher, the encType for unicast
5926 cipher for wpa-none is none*/
5927 encryptionType =
5928 hdd_TranslateWPAToCsrEncryptionType(dot11WPAIE.multicast_cipher);
5929 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005930 }
Shailender Karmuchi67edd312013-06-18 16:30:48 -07005931
Jeff Johnson295189b2012-06-20 16:38:30 -07005932 status = wlan_hdd_cfg80211_set_ie(pAdapter, params->ie, params->ie_len);
5933
5934 if (0 > status)
5935 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305936 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to parse WPA/RSN IE",
Jeff Johnson295189b2012-06-20 16:38:30 -07005937 __func__);
5938 return status;
5939 }
5940 }
5941
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305942 pWextState->roamProfile.AuthType.authType[0] =
5943 pHddStaCtx->conn_info.authType =
Jeff Johnson295189b2012-06-20 16:38:30 -07005944 eCSR_AUTH_TYPE_OPEN_SYSTEM;
5945
5946 if (params->privacy)
5947 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305948 /* Security enabled IBSS, At this time there is no information available
5949 * about the security paramters, so initialise the encryption type to
Jeff Johnson295189b2012-06-20 16:38:30 -07005950 * eCSR_ENCRYPT_TYPE_WEP40_STATICKEY.
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305951 * The correct security parameters will be updated later in
Jeff Johnson295189b2012-06-20 16:38:30 -07005952 * wlan_hdd_cfg80211_add_key */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305953 /* Hal expects encryption type to be set inorder
Jeff Johnson295189b2012-06-20 16:38:30 -07005954 *enable privacy bit in beacons */
5955
5956 encryptionType = eCSR_ENCRYPT_TYPE_WEP40_STATICKEY;
5957 }
Shailender Karmuchi642e9812013-05-30 14:34:49 -07005958 VOS_TRACE (VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
5959 "encryptionType=%d", encryptionType);
Jeff Johnson295189b2012-06-20 16:38:30 -07005960 pHddStaCtx->conn_info.ucEncryptionType = encryptionType;
5961 pWextState->roamProfile.EncryptionType.numEntries = 1;
5962 pWextState->roamProfile.EncryptionType.encryptionType[0] = encryptionType;
Jeff Johnson295189b2012-06-20 16:38:30 -07005963 return status;
5964}
5965
5966/*
5967 * FUNCTION: wlan_hdd_cfg80211_join_ibss
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305968 * This function is used to create/join an IBSS
Jeff Johnson295189b2012-06-20 16:38:30 -07005969 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305970static int wlan_hdd_cfg80211_join_ibss( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07005971 struct net_device *dev,
5972 struct cfg80211_ibss_params *params
5973 )
5974{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305975 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Jeff Johnson295189b2012-06-20 16:38:30 -07005976 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
5977 tCsrRoamProfile *pRoamProfile;
5978 int status;
5979 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305980 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07005981
5982 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305983
5984 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07005985 "%s: device_mode = %d\n",__func__,pAdapter->device_mode);
5986
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 }
5995
5996 if (NULL == pWextState)
5997 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305998 hddLog (VOS_TRACE_LEVEL_ERROR, "%s ERROR: Data Storage Corruption\n",
Jeff Johnson295189b2012-06-20 16:38:30 -07005999 __func__);
6000 return -EIO;
6001 }
6002
6003 pRoamProfile = &pWextState->roamProfile;
6004
6005 if ( eCSR_BSS_TYPE_START_IBSS != pRoamProfile->BSSType )
6006 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306007 hddLog (VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07006008 "%s Interface type is not set to IBSS \n", __func__);
6009 return -EINVAL;
6010 }
6011
6012 /* Set Channel */
6013 if (NULL != params->channel)
6014 {
6015 u8 channelNum;
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006016 v_U32_t numChans = WNI_CFG_VALID_CHANNEL_LIST_LEN;
6017 v_U8_t validChan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
6018 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
6019 int indx;
Jeff Johnson295189b2012-06-20 16:38:30 -07006020
6021 /* Get channel number */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306022 channelNum =
Jeff Johnson295189b2012-06-20 16:38:30 -07006023 ieee80211_frequency_to_channel(params->channel->center_freq);
6024
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006025
6026 if (0 != ccmCfgGetStr(hHal, WNI_CFG_VALID_CHANNEL_LIST,
6027 validChan, &numChans))
Jeff Johnson295189b2012-06-20 16:38:30 -07006028 {
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006029 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: No valid channel list",
6030 __func__);
6031 return -EOPNOTSUPP;
Jeff Johnson295189b2012-06-20 16:38:30 -07006032 }
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006033
6034 for (indx = 0; indx < numChans; indx++)
Jeff Johnson295189b2012-06-20 16:38:30 -07006035 {
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006036 if (channelNum == validChan[indx])
6037 {
6038 break;
6039 }
6040 }
6041 if (indx >= numChans)
6042 {
6043 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Not valid Channel %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07006044 __func__, channelNum);
6045 return -EINVAL;
6046 }
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006047 /* Set the Operational Channel */
6048 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: set channel %d", __func__,
6049 channelNum);
6050 pRoamProfile->ChannelInfo.numOfChannels = 1;
6051 pHddStaCtx->conn_info.operationChannel = channelNum;
6052 pRoamProfile->ChannelInfo.ChannelList =
6053 &pHddStaCtx->conn_info.operationChannel;
Jeff Johnson295189b2012-06-20 16:38:30 -07006054 }
6055
6056 /* Initialize security parameters */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306057 status = wlan_hdd_cfg80211_set_privacy_ibss(pAdapter, params);
Jeff Johnson295189b2012-06-20 16:38:30 -07006058 if (status < 0)
6059 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306060 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set security parameters",
Jeff Johnson295189b2012-06-20 16:38:30 -07006061 __func__);
6062 return status;
6063 }
6064
6065 /* Issue connect start */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306066 status = wlan_hdd_cfg80211_connect_start(pAdapter, params->ssid,
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006067 params->ssid_len, params->bssid,
6068 pHddStaCtx->conn_info.operationChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07006069
6070 if (0 > status)
6071 {
6072 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: connect failed", __func__);
6073 return status;
6074 }
6075
6076 return 0;
6077}
6078
6079/*
6080 * FUNCTION: wlan_hdd_cfg80211_leave_ibss
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306081 * This function is used to leave an IBSS
Jeff Johnson295189b2012-06-20 16:38:30 -07006082 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306083static int wlan_hdd_cfg80211_leave_ibss( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07006084 struct net_device *dev
6085 )
6086{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306087 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Jeff Johnson295189b2012-06-20 16:38:30 -07006088 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
6089 tCsrRoamProfile *pRoamProfile;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306090 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
6091 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006092
6093 ENTER();
6094
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306095 status = wlan_hdd_validate_context(pHddCtx);
6096
6097 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006098 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306099 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6100 "%s: HDD context is not valid", __func__);
6101 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006102 }
6103
Jeff Johnson295189b2012-06-20 16:38:30 -07006104 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",__func__,pAdapter->device_mode);
6105 if (NULL == pWextState)
6106 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306107 hddLog (VOS_TRACE_LEVEL_ERROR, "%s ERROR: Data Storage Corruption\n",
Jeff Johnson295189b2012-06-20 16:38:30 -07006108 __func__);
6109 return -EIO;
6110 }
6111
6112 pRoamProfile = &pWextState->roamProfile;
6113
6114 /* Issue disconnect only if interface type is set to IBSS */
6115 if (eCSR_BSS_TYPE_START_IBSS != pRoamProfile->BSSType)
6116 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306117 hddLog (VOS_TRACE_LEVEL_ERROR, "%s: BSS Type is not set to IBSS",
Jeff Johnson295189b2012-06-20 16:38:30 -07006118 __func__);
6119 return -EINVAL;
6120 }
6121
6122 /* Issue Disconnect request */
6123 INIT_COMPLETION(pAdapter->disconnect_comp_var);
6124 sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter), pAdapter->sessionId,
6125 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
6126
6127 return 0;
6128}
6129
6130/*
6131 * FUNCTION: wlan_hdd_cfg80211_set_wiphy_params
6132 * This function is used to set the phy parameters
6133 * (RTS Threshold/FRAG Threshold/Retry Count etc ...)
6134 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306135static int wlan_hdd_cfg80211_set_wiphy_params(struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07006136 u32 changed)
6137{
6138 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
6139 tHalHandle hHal = pHddCtx->hHal;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306140 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006141
6142 ENTER();
6143
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306144 status = wlan_hdd_validate_context(pHddCtx);
6145
6146 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006147 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306148 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6149 "%s: HDD context is not valid", __func__);
6150 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006151 }
6152
Jeff Johnson295189b2012-06-20 16:38:30 -07006153 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
6154 {
6155 u16 rts_threshold = (wiphy->rts_threshold == -1) ?
6156 WNI_CFG_RTS_THRESHOLD_STAMAX :
6157 wiphy->rts_threshold;
6158
6159 if ((WNI_CFG_RTS_THRESHOLD_STAMIN > rts_threshold) ||
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306160 (WNI_CFG_RTS_THRESHOLD_STAMAX < rts_threshold))
Jeff Johnson295189b2012-06-20 16:38:30 -07006161 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306162 hddLog(VOS_TRACE_LEVEL_ERROR,
6163 "%s: Invalid RTS Threshold value %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006164 __func__, rts_threshold);
6165 return -EINVAL;
6166 }
6167
6168 if (0 != ccmCfgSetInt(hHal, WNI_CFG_RTS_THRESHOLD,
6169 rts_threshold, ccmCfgSetCallback,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306170 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07006171 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306172 hddLog(VOS_TRACE_LEVEL_ERROR,
6173 "%s: ccmCfgSetInt failed for rts_threshold value %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006174 __func__, rts_threshold);
6175 return -EIO;
6176 }
6177
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306178 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set rts threshold %hu", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07006179 rts_threshold);
6180 }
6181
6182 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
6183 {
6184 u16 frag_threshold = (wiphy->frag_threshold == -1) ?
6185 WNI_CFG_FRAGMENTATION_THRESHOLD_STAMAX :
6186 wiphy->frag_threshold;
6187
6188 if ((WNI_CFG_FRAGMENTATION_THRESHOLD_STAMIN > frag_threshold)||
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306189 (WNI_CFG_FRAGMENTATION_THRESHOLD_STAMAX < frag_threshold) )
Jeff Johnson295189b2012-06-20 16:38:30 -07006190 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306191 hddLog(VOS_TRACE_LEVEL_ERROR,
6192 "%s: Invalid frag_threshold value %hu", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07006193 frag_threshold);
6194 return -EINVAL;
6195 }
6196
6197 if (0 != ccmCfgSetInt(hHal, WNI_CFG_FRAGMENTATION_THRESHOLD,
6198 frag_threshold, ccmCfgSetCallback,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306199 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07006200 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306201 hddLog(VOS_TRACE_LEVEL_ERROR,
6202 "%s: ccmCfgSetInt failed for frag_threshold value %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006203 __func__, frag_threshold);
6204 return -EIO;
6205 }
6206
6207 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set frag threshold %hu", __func__,
6208 frag_threshold);
6209 }
6210
6211 if ((changed & WIPHY_PARAM_RETRY_SHORT)
6212 || (changed & WIPHY_PARAM_RETRY_LONG))
6213 {
6214 u8 retry_value = (changed & WIPHY_PARAM_RETRY_SHORT) ?
6215 wiphy->retry_short :
6216 wiphy->retry_long;
6217
6218 if ((WNI_CFG_LONG_RETRY_LIMIT_STAMIN > retry_value) ||
6219 (WNI_CFG_LONG_RETRY_LIMIT_STAMAX < retry_value))
6220 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306221 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006222 __func__, retry_value);
6223 return -EINVAL;
6224 }
6225
6226 if (changed & WIPHY_PARAM_RETRY_SHORT)
6227 {
6228 if (0 != ccmCfgSetInt(hHal, WNI_CFG_LONG_RETRY_LIMIT,
6229 retry_value, ccmCfgSetCallback,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306230 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07006231 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306232 hddLog(VOS_TRACE_LEVEL_ERROR,
6233 "%s: ccmCfgSetInt failed for long retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006234 __func__, retry_value);
6235 return -EIO;
6236 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306237 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set long retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006238 __func__, retry_value);
6239 }
6240 else if (changed & WIPHY_PARAM_RETRY_SHORT)
6241 {
6242 if (0 != ccmCfgSetInt(hHal, WNI_CFG_SHORT_RETRY_LIMIT,
6243 retry_value, ccmCfgSetCallback,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306244 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07006245 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306246 hddLog(VOS_TRACE_LEVEL_ERROR,
6247 "%s: ccmCfgSetInt failed for short retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006248 __func__, retry_value);
6249 return -EIO;
6250 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306251 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set short retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006252 __func__, retry_value);
6253 }
6254 }
6255
6256 return 0;
6257}
6258
6259/*
6260 * FUNCTION: wlan_hdd_cfg80211_set_txpower
6261 * This function is used to set the txpower
6262 */
6263static int wlan_hdd_cfg80211_set_txpower(struct wiphy *wiphy,
6264#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,35)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306265 enum tx_power_setting type,
Jeff Johnson295189b2012-06-20 16:38:30 -07006266#else
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306267 enum nl80211_tx_power_setting type,
Jeff Johnson295189b2012-06-20 16:38:30 -07006268#endif
6269 int dbm)
6270{
6271 hdd_context_t *pHddCtx = (hdd_context_t*) wiphy_priv(wiphy);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306272 tHalHandle hHal = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07006273 tSirMacAddr bssid = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
6274 tSirMacAddr selfMac = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306275 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006276
6277 ENTER();
6278
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306279 status = wlan_hdd_validate_context(pHddCtx);
6280
6281 if (0 != status)
6282 {
6283 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6284 "%s: HDD context is not valid", __func__);
6285 return status;
6286 }
6287
6288 hHal = pHddCtx->hHal;
6289
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306290 if (0 != ccmCfgSetInt(hHal, WNI_CFG_CURRENT_TX_POWER_LEVEL,
6291 dbm, ccmCfgSetCallback,
6292 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07006293 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306294 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07006295 "%s: ccmCfgSetInt failed for tx power %hu", __func__, dbm);
6296 return -EIO;
6297 }
6298
6299 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set tx power level %d dbm", __func__,
6300 dbm);
6301
6302 switch(type)
6303 {
6304 case NL80211_TX_POWER_AUTOMATIC: /*automatically determine transmit power*/
6305 /* Fall through */
6306 case NL80211_TX_POWER_LIMITED: /*limit TX power by the mBm parameter*/
6307 if( sme_SetMaxTxPower(hHal, bssid, selfMac, dbm) != eHAL_STATUS_SUCCESS )
6308 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306309 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Setting maximum tx power failed",
6310 __func__);
6311 return -EIO;
Jeff Johnson295189b2012-06-20 16:38:30 -07006312 }
6313 break;
6314 case NL80211_TX_POWER_FIXED: /*fix TX power to the mBm parameter*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306315 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: NL80211_TX_POWER_FIXED not supported",
Jeff Johnson295189b2012-06-20 16:38:30 -07006316 __func__);
6317 return -EOPNOTSUPP;
6318 break;
6319 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306320 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid power setting type %d",
6321 __func__, type);
Jeff Johnson295189b2012-06-20 16:38:30 -07006322 return -EIO;
6323 }
6324
6325 return 0;
6326}
6327
6328/*
6329 * FUNCTION: wlan_hdd_cfg80211_get_txpower
6330 * This function is used to read the txpower
6331 */
6332static int wlan_hdd_cfg80211_get_txpower(struct wiphy *wiphy, int *dbm)
6333{
6334
6335 hdd_adapter_t *pAdapter;
6336 hdd_context_t *pHddCtx = (hdd_context_t*) wiphy_priv(wiphy);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306337 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006338
Jeff Johnsone7245742012-09-05 17:12:55 -07006339 ENTER();
6340
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306341 status = wlan_hdd_validate_context(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07006342
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306343 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006344 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306345 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6346 "%s: HDD context is not valid", __func__);
6347 *dbm = 0;
6348 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006349 }
6350
Jeff Johnson295189b2012-06-20 16:38:30 -07006351 pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_INFRA_STATION);
6352 if (NULL == pAdapter)
6353 {
6354 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Not in station context " ,__func__);
6355 return -ENOENT;
6356 }
6357
6358 wlan_hdd_get_classAstats(pAdapter);
6359 *dbm = pAdapter->hdd_stats.ClassA_stat.max_pwr;
6360
Jeff Johnsone7245742012-09-05 17:12:55 -07006361 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07006362 return 0;
6363}
6364
6365static int wlan_hdd_cfg80211_get_station(struct wiphy *wiphy, struct net_device *dev,
6366 u8* mac, struct station_info *sinfo)
6367{
6368 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
6369 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
6370 int ssidlen = pHddStaCtx->conn_info.SSID.SSID.length;
6371 tANI_U8 rate_flags;
6372
6373 hdd_context_t *pHddCtx = (hdd_context_t*) wiphy_priv(wiphy);
6374 hdd_config_t *pCfg = pHddCtx->cfg_ini;
Jeff Johnson295189b2012-06-20 16:38:30 -07006375
6376 tANI_U8 OperationalRates[CSR_DOT11_SUPPORTED_RATES_MAX];
6377 tANI_U32 ORLeng = CSR_DOT11_SUPPORTED_RATES_MAX;
6378 tANI_U8 ExtendedRates[CSR_DOT11_EXTENDED_SUPPORTED_RATES_MAX];
6379 tANI_U32 ERLeng = CSR_DOT11_EXTENDED_SUPPORTED_RATES_MAX;
6380 tANI_U8 MCSRates[SIZE_OF_BASIC_MCS_SET];
6381 tANI_U32 MCSLeng = SIZE_OF_BASIC_MCS_SET;
6382 tANI_U16 maxRate = 0;
6383 tANI_U16 myRate;
6384 tANI_U16 currentRate = 0;
6385 tANI_U8 maxSpeedMCS = 0;
6386 tANI_U8 maxMCSIdx = 0;
6387 tANI_U8 rateFlag = 1;
6388 tANI_U8 i, j, rssidx;
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07006389 tANI_U16 temp;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306390 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006391
Leo Chang6f8870f2013-03-26 18:11:36 -07006392#ifdef WLAN_FEATURE_11AC
6393 tANI_U32 vht_mcs_map;
6394 eDataRate11ACMaxMcs vhtMaxMcs;
6395#endif /* WLAN_FEATURE_11AC */
6396
Jeff Johnsone7245742012-09-05 17:12:55 -07006397 ENTER();
6398
Jeff Johnson295189b2012-06-20 16:38:30 -07006399 if ((eConnectionState_Associated != pHddStaCtx->conn_info.connState) ||
6400 (0 == ssidlen))
6401 {
6402 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Not associated or"
6403 " Invalid ssidlen, %d", __func__, ssidlen);
6404 /*To keep GUI happy*/
6405 return 0;
6406 }
6407
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306408 status = wlan_hdd_validate_context(pHddCtx);
6409
6410 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006411 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306412 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6413 "%s: HDD context is not valid", __func__);
6414 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006415 }
6416
Jeff Johnson295189b2012-06-20 16:38:30 -07006417 wlan_hdd_get_rssi(pAdapter, &sinfo->signal);
6418 sinfo->filled |= STATION_INFO_SIGNAL;
6419
Madan Mohan Koyyalamudi4d4d2812012-09-24 14:08:29 -07006420 wlan_hdd_get_station_stats(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07006421 rate_flags = pAdapter->hdd_stats.ClassA_stat.tx_rate_flags;
6422
6423 //convert to the UI units of 100kbps
6424 myRate = pAdapter->hdd_stats.ClassA_stat.tx_rate * 5;
6425
6426#ifdef LINKSPEED_DEBUG_ENABLED
Leo Chang6f8870f2013-03-26 18:11:36 -07006427 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 -07006428 sinfo->signal,
6429 pCfg->reportMaxLinkSpeed,
6430 myRate,
6431 (int) pCfg->linkSpeedRssiHigh,
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07006432 (int) pCfg->linkSpeedRssiMid,
6433 (int) pCfg->linkSpeedRssiLow,
Leo Chang6f8870f2013-03-26 18:11:36 -07006434 (int) rate_flags,
6435 (int) pAdapter->hdd_stats.ClassA_stat.mcs_index);
Jeff Johnson295189b2012-06-20 16:38:30 -07006436#endif //LINKSPEED_DEBUG_ENABLED
6437
6438 if (eHDD_LINK_SPEED_REPORT_ACTUAL != pCfg->reportMaxLinkSpeed)
6439 {
6440 // we do not want to necessarily report the current speed
6441 if (eHDD_LINK_SPEED_REPORT_MAX == pCfg->reportMaxLinkSpeed)
6442 {
6443 // report the max possible speed
6444 rssidx = 0;
6445 }
6446 else if (eHDD_LINK_SPEED_REPORT_MAX_SCALED == pCfg->reportMaxLinkSpeed)
6447 {
6448 // report the max possible speed with RSSI scaling
6449 if (sinfo->signal >= pCfg->linkSpeedRssiHigh)
6450 {
6451 // report the max possible speed
6452 rssidx = 0;
6453 }
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07006454 else if (sinfo->signal >= pCfg->linkSpeedRssiMid)
Jeff Johnson295189b2012-06-20 16:38:30 -07006455 {
6456 // report middle speed
6457 rssidx = 1;
6458 }
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07006459 else if (sinfo->signal >= pCfg->linkSpeedRssiLow)
6460 {
6461 // report middle speed
6462 rssidx = 2;
6463 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006464 else
6465 {
6466 // report actual speed
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07006467 rssidx = 3;
Jeff Johnson295189b2012-06-20 16:38:30 -07006468 }
6469 }
6470 else
6471 {
6472 // unknown, treat as eHDD_LINK_SPEED_REPORT_MAX
6473 hddLog(VOS_TRACE_LEVEL_ERROR,
6474 "%s: Invalid value for reportMaxLinkSpeed: %u",
6475 __func__, pCfg->reportMaxLinkSpeed);
6476 rssidx = 0;
6477 }
6478
6479 maxRate = 0;
6480
6481 /* Get Basic Rate Set */
Gopichand Nakkala05ab1322013-02-15 11:28:38 +05306482 if (0 != ccmCfgGetStr(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_OPERATIONAL_RATE_SET,
6483 OperationalRates, &ORLeng))
6484 {
6485 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: ccm api returned failure", __func__);
6486 /*To keep GUI happy*/
6487 return 0;
6488 }
6489
Jeff Johnson295189b2012-06-20 16:38:30 -07006490 for (i = 0; i < ORLeng; i++)
6491 {
Jeff Johnsone7245742012-09-05 17:12:55 -07006492 for (j = 0; j < (sizeof(supported_data_rate) / sizeof(supported_data_rate[0])); j ++)
Jeff Johnson295189b2012-06-20 16:38:30 -07006493 {
6494 /* Validate Rate Set */
6495 if (supported_data_rate[j].beacon_rate_index == (OperationalRates[i] & 0x7F))
6496 {
6497 currentRate = supported_data_rate[j].supported_rate[rssidx];
6498 break;
6499 }
6500 }
6501 /* Update MAX rate */
6502 maxRate = (currentRate > maxRate)?currentRate:maxRate;
6503 }
6504
6505 /* Get Extended Rate Set */
Gopichand Nakkala05ab1322013-02-15 11:28:38 +05306506 if (0 != ccmCfgGetStr(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_EXTENDED_OPERATIONAL_RATE_SET,
6507 ExtendedRates, &ERLeng))
6508 {
6509 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: ccm api returned failure", __func__);
6510 /*To keep GUI happy*/
6511 return 0;
6512 }
6513
Jeff Johnson295189b2012-06-20 16:38:30 -07006514 for (i = 0; i < ERLeng; i++)
6515 {
Jeff Johnsone7245742012-09-05 17:12:55 -07006516 for (j = 0; j < (sizeof(supported_data_rate) / sizeof(supported_data_rate[0])); j ++)
Jeff Johnson295189b2012-06-20 16:38:30 -07006517 {
6518 if (supported_data_rate[j].beacon_rate_index == (ExtendedRates[i] & 0x7F))
6519 {
6520 currentRate = supported_data_rate[j].supported_rate[rssidx];
6521 break;
6522 }
6523 }
6524 /* Update MAX rate */
6525 maxRate = (currentRate > maxRate)?currentRate:maxRate;
6526 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006527 /* Get MCS Rate Set -- but only if we are connected at MCS
6528 rates or if we are always reporting max speed or if we have
6529 good rssi */
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07006530 if ((0 == rssidx) && !(rate_flags & eHAL_TX_RATE_LEGACY))
Jeff Johnson295189b2012-06-20 16:38:30 -07006531 {
Gopichand Nakkala05ab1322013-02-15 11:28:38 +05306532 if (0 != ccmCfgGetStr(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_CURRENT_MCS_SET,
6533 MCSRates, &MCSLeng))
6534 {
6535 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: ccm api returned failure", __func__);
6536 /*To keep GUI happy*/
6537 return 0;
6538 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006539 rateFlag = 0;
Leo Chang6f8870f2013-03-26 18:11:36 -07006540#ifdef WLAN_FEATURE_11AC
6541 /* VHT80 rate has seperate rate table */
Gopichand Nakkala4c705372013-04-24 13:20:33 +05306542 if (rate_flags & (eHAL_TX_RATE_VHT20|eHAL_TX_RATE_VHT40|eHAL_TX_RATE_VHT80))
Jeff Johnson295189b2012-06-20 16:38:30 -07006543 {
Leo Chang6f8870f2013-03-26 18:11:36 -07006544 ccmCfgGetInt(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_VHT_TX_MCS_MAP, &vht_mcs_map);
Gopichand Nakkala4c705372013-04-24 13:20:33 +05306545 vhtMaxMcs = (eDataRate11ACMaxMcs)(vht_mcs_map & DATA_RATE_11AC_MCS_MASK );
Leo Chang6f8870f2013-03-26 18:11:36 -07006546 if (rate_flags & eHAL_TX_RATE_SGI)
Jeff Johnson295189b2012-06-20 16:38:30 -07006547 {
Leo Chang6f8870f2013-03-26 18:11:36 -07006548 rateFlag |= 1;
Jeff Johnson295189b2012-06-20 16:38:30 -07006549 }
Leo Chang6f8870f2013-03-26 18:11:36 -07006550 if (DATA_RATE_11AC_MAX_MCS_7 == vhtMaxMcs)
Jeff Johnson295189b2012-06-20 16:38:30 -07006551 {
Leo Chang6f8870f2013-03-26 18:11:36 -07006552 maxMCSIdx = 7;
6553 }
6554 else if (DATA_RATE_11AC_MAX_MCS_8 == vhtMaxMcs)
6555 {
6556 maxMCSIdx = 8;
6557 }
6558 else if (DATA_RATE_11AC_MAX_MCS_9 == vhtMaxMcs)
6559 {
Gopichand Nakkala4c705372013-04-24 13:20:33 +05306560 //VHT20 is supporting 0~8
6561 if (rate_flags & eHAL_TX_RATE_VHT20)
6562 maxMCSIdx = 8;
6563 else
6564 maxMCSIdx = 9;
Leo Chang6f8870f2013-03-26 18:11:36 -07006565 }
Gopichand Nakkala4c705372013-04-24 13:20:33 +05306566
6567 if (rate_flags & eHAL_TX_RATE_VHT80)
6568 {
6569 currentRate = supported_vht_mcs_rate[pAdapter->hdd_stats.ClassA_stat.mcs_index].supported_VHT80_rate[rateFlag];
6570 maxRate = supported_vht_mcs_rate[maxMCSIdx].supported_VHT80_rate[rateFlag];
6571 }
6572 else if (rate_flags & eHAL_TX_RATE_VHT40)
6573 {
6574 currentRate = supported_vht_mcs_rate[pAdapter->hdd_stats.ClassA_stat.mcs_index].supported_VHT40_rate[rateFlag];
6575 maxRate = supported_vht_mcs_rate[maxMCSIdx].supported_VHT40_rate[rateFlag];
6576 }
6577 else if (rate_flags & eHAL_TX_RATE_VHT20)
6578 {
6579 currentRate = supported_vht_mcs_rate[pAdapter->hdd_stats.ClassA_stat.mcs_index].supported_VHT20_rate[rateFlag];
6580 maxRate = supported_vht_mcs_rate[maxMCSIdx].supported_VHT20_rate[rateFlag];
6581 }
6582
Leo Chang6f8870f2013-03-26 18:11:36 -07006583 maxSpeedMCS = 1;
6584 if (currentRate > maxRate)
6585 {
6586 maxRate = currentRate;
6587 }
Gopichand Nakkala4c705372013-04-24 13:20:33 +05306588
Leo Chang6f8870f2013-03-26 18:11:36 -07006589 }
6590 else
6591#endif /* WLAN_FEATURE_11AC */
6592 {
6593 if (rate_flags & eHAL_TX_RATE_HT40)
6594 {
6595 rateFlag |= 1;
6596 }
6597 if (rate_flags & eHAL_TX_RATE_SGI)
6598 {
6599 rateFlag |= 2;
6600 }
6601
6602 for (i = 0; i < MCSLeng; i++)
6603 {
6604 temp = sizeof(supported_mcs_rate) / sizeof(supported_mcs_rate[0]);
6605 for (j = 0; j < temp; j++)
6606 {
6607 if (supported_mcs_rate[j].beacon_rate_index == MCSRates[i])
6608 {
6609 currentRate = supported_mcs_rate[j].supported_rate[rateFlag];
6610 break;
6611 }
6612 }
6613 if ((j < temp) && (currentRate > maxRate))
6614 {
6615 maxRate = currentRate;
6616 maxSpeedMCS = 1;
6617 maxMCSIdx = supported_mcs_rate[j].beacon_rate_index;
6618 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006619 }
6620 }
6621 }
6622
Gopichand Nakkala4c705372013-04-24 13:20:33 +05306623 else if (!(rate_flags & eHAL_TX_RATE_LEGACY))
6624 {
6625 maxRate = myRate;
6626 maxSpeedMCS = 1;
6627 maxMCSIdx = pAdapter->hdd_stats.ClassA_stat.mcs_index;
6628 }
6629
Jeff Johnson295189b2012-06-20 16:38:30 -07006630 // make sure we report a value at least as big as our current rate
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07006631 if (((maxRate < myRate) && (0 == rssidx)) ||
6632 (0 == maxRate))
Jeff Johnson295189b2012-06-20 16:38:30 -07006633 {
6634 maxRate = myRate;
6635 if (rate_flags & eHAL_TX_RATE_LEGACY)
6636 {
6637 maxSpeedMCS = 0;
6638 }
6639 else
6640 {
6641 maxSpeedMCS = 1;
6642 maxMCSIdx = pAdapter->hdd_stats.ClassA_stat.mcs_index;
6643 }
6644 }
6645
Gopichand Nakkala4c705372013-04-24 13:20:33 +05306646 if (rate_flags & eHAL_TX_RATE_LEGACY)
Jeff Johnson295189b2012-06-20 16:38:30 -07006647 {
6648 sinfo->txrate.legacy = maxRate;
6649#ifdef LINKSPEED_DEBUG_ENABLED
6650 pr_info("Reporting legacy rate %d\n", sinfo->txrate.legacy);
6651#endif //LINKSPEED_DEBUG_ENABLED
6652 }
6653 else
6654 {
6655 sinfo->txrate.mcs = maxMCSIdx;
Leo Chang6f8870f2013-03-26 18:11:36 -07006656#ifdef WLAN_FEATURE_11AC
6657 sinfo->txrate.nss = 1;
6658 if (rate_flags & eHAL_TX_RATE_VHT80)
6659 {
6660 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
Gopichand Nakkala4c705372013-04-24 13:20:33 +05306661 sinfo->txrate.flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
Leo Chang6f8870f2013-03-26 18:11:36 -07006662 }
Gopichand Nakkala4c705372013-04-24 13:20:33 +05306663 else if (rate_flags & eHAL_TX_RATE_VHT40)
Leo Chang6f8870f2013-03-26 18:11:36 -07006664 {
Gopichand Nakkala4c705372013-04-24 13:20:33 +05306665 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
6666 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
6667 }
6668 else if (rate_flags & eHAL_TX_RATE_VHT20)
6669 {
6670 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
6671 }
6672#endif /* WLAN_FEATURE_11AC */
6673 if (rate_flags & (eHAL_TX_RATE_HT20 | eHAL_TX_RATE_HT40))
6674 {
6675 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
6676 if (rate_flags & eHAL_TX_RATE_HT40)
6677 {
6678 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
6679 }
Leo Chang6f8870f2013-03-26 18:11:36 -07006680 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006681 if (rate_flags & eHAL_TX_RATE_SGI)
6682 {
6683 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
6684 }
Gopichand Nakkala4c705372013-04-24 13:20:33 +05306685
Jeff Johnson295189b2012-06-20 16:38:30 -07006686#ifdef LINKSPEED_DEBUG_ENABLED
6687 pr_info("Reporting MCS rate %d flags %x\n",
6688 sinfo->txrate.mcs,
6689 sinfo->txrate.flags );
6690#endif //LINKSPEED_DEBUG_ENABLED
6691 }
6692 }
6693 else
6694 {
6695 // report current rate instead of max rate
6696
6697 if (rate_flags & eHAL_TX_RATE_LEGACY)
6698 {
6699 //provide to the UI in units of 100kbps
6700 sinfo->txrate.legacy = myRate;
6701#ifdef LINKSPEED_DEBUG_ENABLED
6702 pr_info("Reporting actual legacy rate %d\n", sinfo->txrate.legacy);
6703#endif //LINKSPEED_DEBUG_ENABLED
6704 }
6705 else
6706 {
6707 //must be MCS
6708 sinfo->txrate.mcs = pAdapter->hdd_stats.ClassA_stat.mcs_index;
Leo Chang6f8870f2013-03-26 18:11:36 -07006709#ifdef WLAN_FEATURE_11AC
6710 sinfo->txrate.nss = 1;
6711 if (rate_flags & eHAL_TX_RATE_VHT80)
6712 {
6713 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
6714 }
6715 else
6716#endif /* WLAN_FEATURE_11AC */
6717 {
6718 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
6719 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006720 if (rate_flags & eHAL_TX_RATE_SGI)
6721 {
6722 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
6723 }
6724 if (rate_flags & eHAL_TX_RATE_HT40)
6725 {
6726 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
6727 }
Leo Chang6f8870f2013-03-26 18:11:36 -07006728#ifdef WLAN_FEATURE_11AC
6729 else if (rate_flags & eHAL_TX_RATE_VHT80)
6730 {
6731 sinfo->txrate.flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
6732 }
6733#endif /* WLAN_FEATURE_11AC */
Jeff Johnson295189b2012-06-20 16:38:30 -07006734#ifdef LINKSPEED_DEBUG_ENABLED
6735 pr_info("Reporting actual MCS rate %d flags %x\n",
6736 sinfo->txrate.mcs,
6737 sinfo->txrate.flags );
6738#endif //LINKSPEED_DEBUG_ENABLED
6739 }
6740 }
6741 sinfo->filled |= STATION_INFO_TX_BITRATE;
6742
Madan Mohan Koyyalamudi4d4d2812012-09-24 14:08:29 -07006743 sinfo->tx_packets =
6744 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[0] +
6745 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[1] +
6746 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[2] +
6747 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[3];
6748
6749 sinfo->tx_retries =
6750 pAdapter->hdd_stats.summary_stat.retry_cnt[0] +
6751 pAdapter->hdd_stats.summary_stat.retry_cnt[1] +
6752 pAdapter->hdd_stats.summary_stat.retry_cnt[2] +
6753 pAdapter->hdd_stats.summary_stat.retry_cnt[3];
6754
6755 sinfo->tx_failed =
6756 pAdapter->hdd_stats.summary_stat.fail_cnt[0] +
6757 pAdapter->hdd_stats.summary_stat.fail_cnt[1] +
6758 pAdapter->hdd_stats.summary_stat.fail_cnt[2] +
6759 pAdapter->hdd_stats.summary_stat.fail_cnt[3];
6760
6761 sinfo->filled |=
6762 STATION_INFO_TX_PACKETS |
6763 STATION_INFO_TX_RETRIES |
6764 STATION_INFO_TX_FAILED;
6765
6766 EXIT();
6767 return 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07006768}
6769
6770static int wlan_hdd_cfg80211_set_power_mgmt(struct wiphy *wiphy,
Sameer Thalappilc9f26e92013-06-07 10:11:06 -07006771 struct net_device *dev, bool mode, int timeout)
Jeff Johnson295189b2012-06-20 16:38:30 -07006772{
6773 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05306774 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07006775 VOS_STATUS vos_status;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306776 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006777
Jeff Johnsone7245742012-09-05 17:12:55 -07006778 ENTER();
6779
Jeff Johnson295189b2012-06-20 16:38:30 -07006780 if (NULL == pAdapter)
6781 {
6782 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Adapter is NULL\n", __func__);
6783 return -ENODEV;
6784 }
6785
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05306786 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306787 status = wlan_hdd_validate_context(pHddCtx);
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05306788
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306789 if (0 != status)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306790 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306791 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6792 "%s: HDD context is not valid", __func__);
6793 return status;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306794 }
6795
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05306796 if ((DRIVER_POWER_MODE_AUTO == !mode) &&
6797 (TRUE == pHddCtx->hdd_wlan_suspended) &&
6798 (pHddCtx->cfg_ini->fhostArpOffload) &&
6799 (eConnectionState_Associated ==
6800 (WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))->conn_info.connState))
6801 {
Gopichand Nakkalab03e8082013-05-30 18:09:25 +05306802 vos_status = hdd_conf_arp_offload(pAdapter, TRUE);
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05306803 if (!VOS_IS_STATUS_SUCCESS(vos_status))
6804 {
6805 hddLog(VOS_TRACE_LEVEL_INFO,
6806 "%s:Failed to enable ARPOFFLOAD Feature %d\n",
6807 __func__, vos_status);
6808 }
6809 }
6810
Jeff Johnson295189b2012-06-20 16:38:30 -07006811 /**The get power cmd from the supplicant gets updated by the nl only
6812 *on successful execution of the function call
6813 *we are oppositely mapped w.r.t mode in the driver
6814 **/
6815 vos_status = wlan_hdd_enter_bmps(pAdapter, !mode);
6816
Jeff Johnsone7245742012-09-05 17:12:55 -07006817 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07006818 if (VOS_STATUS_E_FAILURE == vos_status)
6819 {
6820 return -EINVAL;
6821 }
6822 return 0;
6823}
6824
6825
6826#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
6827static int wlan_hdd_set_default_mgmt_key(struct wiphy *wiphy,
6828 struct net_device *netdev,
6829 u8 key_index)
6830{
Jeff Johnsone7245742012-09-05 17:12:55 -07006831 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07006832 return 0;
6833}
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306834#endif //LINUX_VERSION_CODE
Jeff Johnson295189b2012-06-20 16:38:30 -07006835
6836#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
6837static int wlan_hdd_set_txq_params(struct wiphy *wiphy,
6838 struct net_device *dev,
6839 struct ieee80211_txq_params *params)
6840{
Jeff Johnsone7245742012-09-05 17:12:55 -07006841 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07006842 return 0;
6843}
6844#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
6845static int wlan_hdd_set_txq_params(struct wiphy *wiphy,
6846 struct ieee80211_txq_params *params)
6847{
Jeff Johnsone7245742012-09-05 17:12:55 -07006848 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07006849 return 0;
6850}
6851#endif //LINUX_VERSION_CODE
6852
6853static int wlan_hdd_cfg80211_del_station(struct wiphy *wiphy,
6854 struct net_device *dev, u8 *mac)
6855{
6856 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306857 hdd_context_t *pHddCtx;
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08006858 VOS_STATUS vos_status;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306859 int status;
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08006860 v_U8_t staId;
Jeff Johnson295189b2012-06-20 16:38:30 -07006861
Jeff Johnsone7245742012-09-05 17:12:55 -07006862 ENTER();
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306863 if ( NULL == pAdapter )
Jeff Johnson295189b2012-06-20 16:38:30 -07006864 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306865 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Adapter" ,__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07006866 return -EINVAL;
6867 }
6868
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306869 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
6870 status = wlan_hdd_validate_context(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07006871
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306872 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006873 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306874 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6875 "%s: HDD context is not valid", __func__);
6876 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006877 }
6878
Jeff Johnson295189b2012-06-20 16:38:30 -07006879 if ( (WLAN_HDD_SOFTAP == pAdapter->device_mode)
Jeff Johnson295189b2012-06-20 16:38:30 -07006880 || (WLAN_HDD_P2P_GO == pAdapter->device_mode)
Jeff Johnson295189b2012-06-20 16:38:30 -07006881 )
6882 {
6883 if( NULL == mac )
6884 {
6885 v_U16_t i;
6886 for(i = 0; i < WLAN_MAX_STA_COUNT; i++)
6887 {
6888 if(pAdapter->aStaInfo[i].isUsed)
6889 {
6890 u8 *macAddr = pAdapter->aStaInfo[i].macAddrSTA.bytes;
6891 hddLog(VOS_TRACE_LEVEL_INFO,
6892 "%s: Delete STA with MAC::"
6893 "%02x:%02x:%02x:%02x:%02x:%02x",
6894 __func__,
6895 macAddr[0], macAddr[1], macAddr[2],
6896 macAddr[3], macAddr[4], macAddr[5]);
6897 hdd_softap_sta_deauth(pAdapter, macAddr);
6898 }
6899 }
6900 }
6901 else
6902 {
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08006903
6904 vos_status = hdd_softap_GetStaId(pAdapter,(v_MACADDR_t *)mac, &staId);
6905 if (!VOS_IS_STATUS_SUCCESS(vos_status))
6906 {
6907 hddLog(VOS_TRACE_LEVEL_INFO,
6908 "%s: Skip this DEL STA as this is not used::"
6909 "%02x:%02x:%02x:%02x:%02x:%02x",
6910 __func__,
6911 mac[0], mac[1], mac[2],
6912 mac[3], mac[4], mac[5]);
6913 return -ENOENT;
6914 }
6915
6916 if( pAdapter->aStaInfo[staId].isDeauthInProgress == TRUE)
6917 {
6918 hddLog(VOS_TRACE_LEVEL_INFO,
6919 "%s: Skip this DEL STA as deauth is in progress::"
6920 "%02x:%02x:%02x:%02x:%02x:%02x",
6921 __func__,
6922 mac[0], mac[1], mac[2],
6923 mac[3], mac[4], mac[5]);
6924 return -ENOENT;
6925 }
6926
6927 pAdapter->aStaInfo[staId].isDeauthInProgress = TRUE;
6928
Jeff Johnson295189b2012-06-20 16:38:30 -07006929 hddLog(VOS_TRACE_LEVEL_INFO,
6930 "%s: Delete STA with MAC::"
6931 "%02x:%02x:%02x:%02x:%02x:%02x",
6932 __func__,
6933 mac[0], mac[1], mac[2],
6934 mac[3], mac[4], mac[5]);
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08006935
6936 vos_status = hdd_softap_sta_deauth(pAdapter, mac);
6937 if (!VOS_IS_STATUS_SUCCESS(vos_status))
6938 {
6939 pAdapter->aStaInfo[staId].isDeauthInProgress = FALSE;
6940 hddLog(VOS_TRACE_LEVEL_INFO,
6941 "%s: STA removal failed for ::"
6942 "%02x:%02x:%02x:%02x:%02x:%02x",
6943 __func__,
6944 mac[0], mac[1], mac[2],
6945 mac[3], mac[4], mac[5]);
6946 return -ENOENT;
6947 }
6948
Jeff Johnson295189b2012-06-20 16:38:30 -07006949 }
6950 }
6951
6952 EXIT();
6953
6954 return 0;
6955}
6956
Hoonki Lee11f7dda2013-02-14 16:55:44 -08006957static int wlan_hdd_cfg80211_add_station(struct wiphy *wiphy,
6958 struct net_device *dev, u8 *mac, struct station_parameters *params)
6959{
Gopichand Nakkalab977a972013-02-18 19:15:09 -08006960 int status = -EPERM;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08006961#ifdef FEATURE_WLAN_TDLS
6962 u32 mask, set;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08006963 ENTER();
Mohit Khanna698ba2a2012-12-04 15:08:18 -08006964 mask = params->sta_flags_mask;
6965
6966 set = params->sta_flags_set;
6967
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07006968#ifdef WLAN_FEATURE_TDLS_DEBUG
6969 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6970 "%s: mask 0x%x set 0x%x " MAC_ADDRESS_STR,
6971 __func__, mask, set, MAC_ADDR_ARRAY(mac));
6972#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -08006973
6974 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
6975 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
Gopichand Nakkala681989c2013-03-06 22:27:48 -08006976 status = wlan_hdd_tdls_add_station(wiphy, dev, mac, 0, NULL);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08006977 }
6978 }
6979#endif
Gopichand Nakkalab977a972013-02-18 19:15:09 -08006980 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006981}
6982
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006983
6984#ifdef FEATURE_WLAN_LFR
6985static int wlan_hdd_cfg80211_set_pmksa(struct wiphy *wiphy, struct net_device *dev,
Jeff Johnsond13512a2012-07-17 11:42:19 -07006986 struct cfg80211_pmksa *pmksa)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006987{
6988#define MAX_PMKSAIDS_IN_CACHE 8
6989 static tPmkidCacheInfo PMKIDCache[MAX_PMKSAIDS_IN_CACHE]; // HDD Local cache
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306990 static tANI_U32 i; // HDD Local Cache index
6991 tANI_U32 j=0;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006992 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
6993 tHalHandle halHandle;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306994 eHalStatus result;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306995 int status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006996 tANI_U8 BSSIDMatched = 0;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306997 hdd_context_t *pHddCtx;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306998
Jeff Johnsone7245742012-09-05 17:12:55 -07006999 ENTER();
7000
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307001 // Validate pAdapter
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307002 if ( NULL == pAdapter )
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007003 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307004 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Adapter" ,__func__);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007005 return -EINVAL;
7006 }
7007
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307008 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7009 status = wlan_hdd_validate_context(pHddCtx);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007010
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307011 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007012 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307013 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7014 "%s: HDD context is not valid", __func__);
7015 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007016 }
7017
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307018 // Retrieve halHandle
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007019 halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
7020
7021 for (j = 0; j < i; j++)
7022 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307023 if(vos_mem_compare(PMKIDCache[j].BSSID,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007024 pmksa->bssid, WNI_CFG_BSSID_LEN))
7025 {
7026 /* BSSID matched previous entry. Overwrite it. */
7027 BSSIDMatched = 1;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307028 vos_mem_copy(PMKIDCache[j].BSSID,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007029 pmksa->bssid, WNI_CFG_BSSID_LEN);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307030 vos_mem_copy(PMKIDCache[j].PMKID,
7031 pmksa->pmkid,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007032 CSR_RSN_PMKID_SIZE);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307033 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Reusing cache entry %d.",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007034 __func__, j );
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007035 dump_bssid(pmksa->bssid);
7036 dump_pmkid(halHandle, pmksa->pmkid);
7037 break;
7038 }
7039 }
7040
Madan Mohan Koyyalamudic4b317d2012-10-18 19:43:08 -07007041 /* Check we compared all entries,if then take the first slot now */
7042 if(j == MAX_PMKSAIDS_IN_CACHE) i=0;
7043
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007044 if (!BSSIDMatched)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307045 {
7046 // Now, we DON'T have a BSSID match, so take a new entry in the cache.
7047 vos_mem_copy(PMKIDCache[i].BSSID,
7048 pmksa->bssid, ETHER_ADDR_LEN);
7049 vos_mem_copy(PMKIDCache[i].PMKID,
7050 pmksa->pmkid,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007051 CSR_RSN_PMKID_SIZE);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307052 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Adding a new cache entry %d.",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007053 __func__, i );
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007054 dump_bssid(pmksa->bssid);
7055 dump_pmkid(halHandle, pmksa->pmkid);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307056 // Increment the HDD Local Cache index
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007057 // The "i=0" doesn't work for the call to sme_RoamSetPMKIDCache() - LFR FIXME
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307058 if (i<=(MAX_PMKSAIDS_IN_CACHE-1)) i++; else i=0;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007059 }
7060
7061
7062 // Calling csrRoamSetPMKIDCache to configure the PMKIDs into the cache
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307063 //hddLog(LOG1, FL("%s: Calling csrRoamSetPMKIDCache with %d cache entries."),
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007064 // __func__, i );
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307065 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Calling csrRoamSetPMKIDCache with %d cache entries.",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007066 __func__, i );
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007067 // Finally set the PMKSA ID Cache in CSR
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307068 result = sme_RoamSetPMKIDCache(halHandle,pAdapter->sessionId,
7069 PMKIDCache,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007070 i );
7071 return 0;
7072}
7073
7074
7075static int wlan_hdd_cfg80211_del_pmksa(struct wiphy *wiphy, struct net_device *dev,
Jeff Johnsond13512a2012-07-17 11:42:19 -07007076 struct cfg80211_pmksa *pmksa)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007077{
Jeff Johnsone7245742012-09-05 17:12:55 -07007078 ENTER();
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007079 // TODO: Implement this later.
7080 return 0;
7081}
7082
7083static int wlan_hdd_cfg80211_flush_pmksa(struct wiphy *wiphy, struct net_device *dev)
7084{
Jeff Johnsone7245742012-09-05 17:12:55 -07007085 ENTER();
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007086 // TODO: Implement this later.
7087 return 0;
7088}
7089#endif
7090
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07007091#if defined(WLAN_FEATURE_VOWIFI_11R) && defined(KERNEL_SUPPORT_11R_CFG80211)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307092static int wlan_hdd_cfg80211_update_ft_ies(struct wiphy *wiphy,
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07007093 struct net_device *dev, struct cfg80211_update_ft_ies_params *ftie)
7094{
7095 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7096 hdd_station_ctx_t *pHddStaCtx;
7097
7098 if (NULL == pAdapter)
7099 {
7100 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Adapter is NULL\n", __func__);
7101 return -ENODEV;
7102 }
7103
7104 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
7105
7106 // Added for debug on reception of Re-assoc Req.
7107 if (eConnectionState_Associated != pHddStaCtx->conn_info.connState)
7108 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307109 hddLog(LOGE, FL("Called with Ie of length = %d when not associated\n"),
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07007110 ftie->ie_len);
7111 hddLog(LOGE, FL("Should be Re-assoc Req IEs\n"));
7112 }
7113
7114#ifdef WLAN_FEATURE_VOWIFI_11R_DEBUG
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307115 hddLog(LOGE, FL("%s called with Ie of length = %d\n"), __func__,
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07007116 ftie->ie_len);
7117#endif
7118
7119 // Pass the received FT IEs to SME
Gopichand Nakkala356fb102013-03-06 12:34:04 +05307120 sme_SetFTIEs( WLAN_HDD_GET_HAL_CTX(pAdapter), pAdapter->sessionId,
7121 (const u8 *)ftie->ie,
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07007122 ftie->ie_len);
7123 return 0;
7124}
7125#endif
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007126
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307127#ifdef FEATURE_WLAN_SCAN_PNO
7128
7129void hdd_cfg80211_sched_scan_done_callback(void *callbackContext,
7130 tSirPrefNetworkFoundInd *pPrefNetworkFoundInd)
7131{
7132 int ret;
7133 hdd_adapter_t* pAdapter = (hdd_adapter_t*)callbackContext;
7134 hdd_context_t *pHddCtx;
7135
7136 if (NULL == pAdapter)
7137 {
7138 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
7139 "%s: HDD adapter is Null", __func__);
7140 return ;
7141 }
7142
7143 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7144 if (NULL == pHddCtx)
7145 {
7146 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7147 "%s: HDD context is Null!!!", __func__);
7148 return ;
7149 }
7150
7151 ret = wlan_hdd_cfg80211_update_bss(pHddCtx->wiphy, pAdapter);
7152
7153 if (0 > ret)
7154 hddLog(VOS_TRACE_LEVEL_INFO, "%s: NO SCAN result", __func__);
7155
7156 cfg80211_sched_scan_results(pHddCtx->wiphy);
7157}
7158
7159/*
7160 * FUNCTION: wlan_hdd_cfg80211_sched_scan_start
7161 * NL interface to enable PNO
7162 */
7163static int wlan_hdd_cfg80211_sched_scan_start(struct wiphy *wiphy,
7164 struct net_device *dev, struct cfg80211_sched_scan_request *request)
7165{
7166 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7167 tpSirPNOScanReq pPnoRequest = NULL;
7168 hdd_context_t *pHddCtx;
7169 tHalHandle hHal;
7170 v_U32_t i, indx, num_ch;
7171 u8 valid_ch[WNI_CFG_VALID_CHANNEL_LIST_LEN];
7172 u8 channels_allowed[WNI_CFG_VALID_CHANNEL_LIST_LEN];
7173 v_U32_t num_channels_allowed = WNI_CFG_VALID_CHANNEL_LIST_LEN;
7174 eHalStatus status = eHAL_STATUS_FAILURE;
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05307175 int result;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307176
7177 if (NULL == pAdapter)
7178 {
7179 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
7180 "%s: HDD adapter is Null", __func__);
7181 return -ENODEV;
7182 }
7183
7184 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05307185 result = wlan_hdd_validate_context(pHddCtx);
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307186
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05307187 if (0 != result)
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307188 {
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05307189 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7190 "%s: HDD context is not valid", __func__);
7191 return result;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307192 }
7193
7194 hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
7195 if (NULL == hHal)
7196 {
7197 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7198 "%s: HAL context is Null!!!", __func__);
7199 return -EAGAIN;
7200 }
7201
7202 pPnoRequest = (tpSirPNOScanReq) vos_mem_malloc(sizeof (tSirPNOScanReq));
7203 if (NULL == pPnoRequest)
7204 {
7205 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
7206 "%s: vos_mem_malloc failed", __func__);
7207 return -ENODEV;
7208 }
7209
7210 pPnoRequest->enable = 1; /*Enable PNO */
7211 pPnoRequest->ucNetworksCount = request->n_match_sets;
7212
7213 if (( !pPnoRequest->ucNetworksCount ) ||
7214 ( pPnoRequest->ucNetworksCount > SIR_PNO_MAX_SUPP_NETWORKS ))
7215 {
7216 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7217 "Network input is not correct");
7218 goto error;
7219 }
7220
7221 if ( SIR_PNO_MAX_NETW_CHANNELS_EX < request->n_channels )
7222 {
7223 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7224 "Incorrect number of channels");
7225 goto error;
7226 }
7227
7228 /* Framework provides one set of channels(all)
7229 * common for all saved profile */
7230 if (0 != ccmCfgGetStr(hHal, WNI_CFG_VALID_CHANNEL_LIST,
7231 channels_allowed, &num_channels_allowed))
7232 {
7233 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7234 "%s: failed to get valid channel list", __func__);
7235 goto error;
7236 }
7237 /* Checking each channel against allowed channel list */
7238 num_ch = 0;
7239 for (i = 0; i < request->n_channels; i++)
7240 {
7241 for (indx = 0; indx < num_channels_allowed; indx++)
7242 {
7243 if (request->channels[i]->hw_value == channels_allowed[indx])
7244 {
7245 valid_ch[num_ch++] = request->channels[i]->hw_value;
7246 break ;
7247 }
7248 }
7249 }
7250
7251 /* Filling per profile params */
7252 for (i = 0; i < pPnoRequest->ucNetworksCount; i++)
7253 {
7254 pPnoRequest->aNetworks[i].ssId.length =
7255 request->match_sets[i].ssid.ssid_len;
7256
7257 if (( 0 == pPnoRequest->aNetworks[i].ssId.length ) ||
7258 ( pPnoRequest->aNetworks[i].ssId.length > 32 ) )
7259 {
7260 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7261 "SSID Len %d is not correct for network %d",
7262 pPnoRequest->aNetworks[i].ssId.length, i);
7263 goto error;
7264 }
7265
7266 memcpy(pPnoRequest->aNetworks[i].ssId.ssId,
7267 request->match_sets[i].ssid.ssid,
7268 request->match_sets[i].ssid.ssid_len);
7269 pPnoRequest->aNetworks[i].authentication = 0; /*eAUTH_TYPE_ANY*/
7270 pPnoRequest->aNetworks[i].encryption = 0; /*eED_ANY*/
7271 pPnoRequest->aNetworks[i].bcastNetwType = 0; /*eBCAST_UNKNOWN*/
7272
7273 /*Copying list of valid channel into request */
7274 memcpy(pPnoRequest->aNetworks[i].aChannels, valid_ch, num_ch);
7275 pPnoRequest->aNetworks[i].ucChannelCount = num_ch;
7276
7277 pPnoRequest->aNetworks[i].rssiThreshold = 0; //Default value
7278 }
7279
7280 /* framework provides interval in ms */
7281 pPnoRequest->scanTimers.ucScanTimersCount = 1;
7282 pPnoRequest->scanTimers.aTimerValues[0].uTimerValue =
7283 (request->interval)/1000;
7284 pPnoRequest->scanTimers.aTimerValues[0].uTimerRepeat = 0;
7285 pPnoRequest->modePNO = SIR_PNO_MODE_ON_SUSPEND;
7286
7287 status = sme_SetPreferredNetworkList(WLAN_HDD_GET_HAL_CTX(pAdapter),
7288 pPnoRequest, pAdapter->sessionId,
7289 hdd_cfg80211_sched_scan_done_callback, pAdapter);
7290 if (eHAL_STATUS_SUCCESS != status)
7291 {
7292 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7293 "Failed to enable PNO");
7294 goto error;
7295 }
7296
7297error:
7298 vos_mem_free(pPnoRequest);
7299 return status;
7300}
7301
7302/*
7303 * FUNCTION: wlan_hdd_cfg80211_sched_scan_stop
7304 * NL interface to disable PNO
7305 */
7306static int wlan_hdd_cfg80211_sched_scan_stop(struct wiphy *wiphy,
7307 struct net_device *dev)
7308{
7309 eHalStatus status = eHAL_STATUS_FAILURE;
7310 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7311 hdd_context_t *pHddCtx;
7312 tHalHandle hHal;
7313 tpSirPNOScanReq pPnoRequest = NULL;
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05307314 int result;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307315
7316 ENTER();
7317
7318 if (NULL == pAdapter)
7319 {
7320 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
7321 "%s: HDD adapter is Null", __func__);
7322 return -ENODEV;
7323 }
7324
7325 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05307326 result = wlan_hdd_validate_context(pHddCtx);
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307327
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05307328 if (0 != result)
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307329 {
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05307330 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7331 "%s: HDD context is not valid", __func__);
7332 return result;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307333 }
7334
7335 hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
7336 if (NULL == hHal)
7337 {
7338 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7339 "%s: HAL context is Null!!!", __func__);
7340 return -EAGAIN;
7341 }
7342
7343 pPnoRequest = (tpSirPNOScanReq) vos_mem_malloc(sizeof (tSirPNOScanReq));
7344 if (NULL == pPnoRequest)
7345 {
7346 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
7347 "%s: vos_mem_malloc failed", __func__);
7348 return -ENODEV;
7349 }
7350
7351 memset(pPnoRequest, 0, sizeof (tSirPNOScanReq));
7352 pPnoRequest->enable = 0; /* Disable PNO */
7353 pPnoRequest->ucNetworksCount = 0;
7354
7355 status = sme_SetPreferredNetworkList(hHal, pPnoRequest,
7356 pAdapter->sessionId,
7357 NULL, pAdapter);
7358 if (eHAL_STATUS_SUCCESS != status)
7359 {
7360 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7361 "Failed to disabled PNO");
7362 }
7363
7364 vos_mem_free(pPnoRequest);
7365
7366 EXIT();
7367 return status;
7368}
7369
7370#endif /*FEATURE_WLAN_SCAN_PNO*/
7371
7372
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007373#ifdef FEATURE_WLAN_TDLS
7374static int wlan_hdd_cfg80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
7375 u8 *peer, u8 action_code, u8 dialog_token,
7376 u16 status_code, const u8 *buf, size_t len)
7377{
7378
7379 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7380 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007381 u8 peerMac[6];
7382 VOS_STATUS status;
Gopichand Nakkala05922802013-03-14 12:23:19 -07007383 int max_sta_failed = 0;
Hoonki Leea34dd892013-02-05 22:56:02 -08007384 int responder;
Hoonki Leed37cbb32013-04-20 00:31:14 -07007385 long rc;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007386
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007387 if (NULL == pHddCtx || NULL == pHddCtx->cfg_ini)
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007388 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307389 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007390 "Invalid arguments");
7391 return -EINVAL;
7392 }
7393
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08007394 if (pHddCtx->isLogpInProgress)
7395 {
7396 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7397 "%s:LOGP in Progress. Ignore!!!", __func__);
Gopichand Nakkala05922802013-03-14 12:23:19 -07007398 wlan_hdd_tdls_set_link_status(pAdapter, peer, eTDLS_LINK_IDLE);
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08007399 return -EBUSY;
7400 }
7401
Hoonki Lee27511902013-03-14 18:19:06 -07007402 if (eTDLS_SUPPORT_NOT_ENABLED == pHddCtx->tdls_mode)
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007403 {
Hoonki Lee27511902013-03-14 18:19:06 -07007404 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
7405 "%s: TDLS mode is disabled OR not enabled in FW."
7406 MAC_ADDRESS_STR " action %d declined.",
7407 __func__, MAC_ADDR_ARRAY(peer), action_code);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007408 return -ENOTSUPP;
7409 }
Lee Hoonkic1262f22013-01-24 21:59:00 -08007410
Hoonki Lee27511902013-03-14 18:19:06 -07007411 /* other than teardown frame, other mgmt frames are not sent if disabled */
7412 if (SIR_MAC_TDLS_TEARDOWN != action_code)
7413 {
7414 /* if tdls_mode is disabled to respond to peer's request */
7415 if (eTDLS_SUPPORT_DISABLED == pHddCtx->tdls_mode)
7416 {
7417 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
7418 "%s: " MAC_ADDRESS_STR
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07007419 " TDLS mode is disabled. action %d declined.",
7420 __func__, MAC_ADDR_ARRAY(peer), action_code);
Hoonki Lee27511902013-03-14 18:19:06 -07007421
7422 return -ENOTSUPP;
7423 }
7424 }
7425
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007426 if (WLAN_IS_TDLS_SETUP_ACTION(action_code))
7427 {
Hoonki Leefb8df672013-04-10 18:20:34 -07007428 if (NULL != wlan_hdd_tdls_is_progress(pHddCtx, peer, TRUE, TRUE))
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007429 {
7430 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007431 "%s: " MAC_ADDRESS_STR
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07007432 " TDLS setup is ongoing. action %d declined.",
7433 __func__, MAC_ADDR_ARRAY(peer), action_code);
7434 return -EPERM;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007435 }
7436 }
7437
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007438 if (SIR_MAC_TDLS_SETUP_REQ == action_code ||
7439 SIR_MAC_TDLS_SETUP_RSP == action_code )
Lee Hoonkic1262f22013-01-24 21:59:00 -08007440 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08007441 if (HDD_MAX_NUM_TDLS_STA <= wlan_hdd_tdlsConnectedPeers(pAdapter))
Lee Hoonkic1262f22013-01-24 21:59:00 -08007442 {
7443 /* supplicant still sends tdls_mgmt(SETUP_REQ) even after
7444 we return error code at 'add_station()'. Hence we have this
7445 check again in addtion to add_station().
7446 Anyway, there is no hard to double-check. */
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007447 if (SIR_MAC_TDLS_SETUP_REQ == action_code)
Lee Hoonkic1262f22013-01-24 21:59:00 -08007448 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007449 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7450 "%s: " MAC_ADDRESS_STR
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07007451 " TDLS Max peer already connected. action %d declined.",
7452 __func__, MAC_ADDR_ARRAY(peer), action_code);
Gopichand Nakkala05922802013-03-14 12:23:19 -07007453 goto error;
Lee Hoonkic1262f22013-01-24 21:59:00 -08007454 }
7455 else
7456 {
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007457 /* maximum reached. tweak to send error code to peer and return
7458 error code to supplicant */
Lee Hoonkic1262f22013-01-24 21:59:00 -08007459 status_code = eSIR_MAC_UNSPEC_FAILURE_STATUS;
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007460 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7461 "%s: " MAC_ADDRESS_STR
7462 " TDLS Max peer already connected send response status %d",
7463 __func__, MAC_ADDR_ARRAY(peer), status_code);
Gopichand Nakkala05922802013-03-14 12:23:19 -07007464 max_sta_failed = -EPERM;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007465 /* fall through to send setup resp with failure status
7466 code */
Lee Hoonkic1262f22013-01-24 21:59:00 -08007467 }
7468 }
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007469 else
7470 {
7471 hddTdlsPeer_t *pTdlsPeer;
Gopichand Nakkala4327a152013-03-04 23:22:42 -08007472 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peer);
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07007473 if (pTdlsPeer && TDLS_IS_CONNECTED(pTdlsPeer))
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007474 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007475 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07007476 "%s:" MAC_ADDRESS_STR " already connected. action %d declined.",
7477 __func__, MAC_ADDR_ARRAY(peer), action_code);
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007478 return -EPERM;
7479 }
7480 }
Lee Hoonkic1262f22013-01-24 21:59:00 -08007481 }
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007482 vos_mem_copy(peerMac, peer, 6);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007483
Hoonki Lee1090c6a2013-01-16 17:40:54 -08007484#ifdef WLAN_FEATURE_TDLS_DEBUG
7485 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007486 "%s: " MAC_ADDRESS_STR " action %d, dialog_token %d status %d, len = %d",
7487 "tdls_mgmt", MAC_ADDR_ARRAY(peer),
7488 action_code, dialog_token, status_code, len);
Hoonki Lee1090c6a2013-01-16 17:40:54 -08007489#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007490
Hoonki Leea34dd892013-02-05 22:56:02 -08007491 /*Except teardown responder will not be used so just make 0*/
7492 responder = 0;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007493 if (SIR_MAC_TDLS_TEARDOWN == action_code)
Hoonki Leea34dd892013-02-05 22:56:02 -08007494 {
Gopichand Nakkala97a65fd2013-04-16 16:59:38 -07007495
7496 hddTdlsPeer_t *pTdlsPeer;
7497 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peerMac);
7498
7499 if(pTdlsPeer && TDLS_IS_CONNECTED(pTdlsPeer))
7500 responder = pTdlsPeer->is_responder;
7501 else
Hoonki Leea34dd892013-02-05 22:56:02 -08007502 {
Gopichand Nakkala97a65fd2013-04-16 16:59:38 -07007503 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7504 "%s: " MAC_ADDRESS_STR " peer doesn't exist or not connected %d dialog_token %d status %d, len = %d",
7505 __func__, MAC_ADDR_ARRAY(peer), (NULL == pTdlsPeer) ? -1 : pTdlsPeer->link_status,
7506 dialog_token, status_code, len);
7507 return -EPERM;
Hoonki Leea34dd892013-02-05 22:56:02 -08007508 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007509 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007510
Gopichand Nakkala2f1ff152013-07-01 11:27:43 +05307511 /* For explicit trigger of DIS_REQ come out of BMPS for
7512 successfully receiving DIS_RSP from peer. */
Hoonki Lee14621352013-04-16 17:51:19 -07007513 if ((SIR_MAC_TDLS_SETUP_RSP == action_code) ||
Gopichand Nakkala2f1ff152013-07-01 11:27:43 +05307514 (SIR_MAC_TDLS_DIS_RSP == action_code) ||
7515 (SIR_MAC_TDLS_DIS_REQ == action_code))
Hoonki Lee14621352013-04-16 17:51:19 -07007516 {
7517 if (TRUE == sme_IsPmcBmps(WLAN_HDD_GET_HAL_CTX(pAdapter)))
7518 {
7519 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
Gopichand Nakkala2f1ff152013-07-01 11:27:43 +05307520 "%s: Sending frame action_code %u.Disable BMPS", __func__, action_code);
Hoonki Lee14621352013-04-16 17:51:19 -07007521 hdd_disable_bmps_imps(pHddCtx, WLAN_HDD_INFRA_STATION);
7522 }
Gopichand Nakkala2f1ff152013-07-01 11:27:43 +05307523 if (SIR_MAC_TDLS_DIS_REQ != action_code)
7524 wlan_hdd_tdls_set_cap(pAdapter, peerMac, eTDLS_CAP_SUPPORTED);
Hoonki Lee14621352013-04-16 17:51:19 -07007525 }
7526
Hoonki Lee5305c3a2013-04-29 23:28:59 -07007527 /* make sure doesn't call send_mgmt() while it is pending */
7528 if (TDLS_CTX_MAGIC == pAdapter->mgmtTxCompletionStatus)
7529 {
7530 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7531 "%s: " MAC_ADDRESS_STR " action %d couldn't sent, as one is pending. return EBUSY\n",
7532 __func__, MAC_ADDR_ARRAY(peer), action_code);
7533 return -EBUSY;
7534 }
7535
7536 pAdapter->mgmtTxCompletionStatus = TDLS_CTX_MAGIC;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007537 INIT_COMPLETION(pAdapter->tdls_mgmt_comp);
7538
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007539 status = sme_SendTdlsMgmtFrame(WLAN_HDD_GET_HAL_CTX(pAdapter), pAdapter->sessionId,
Hoonki Leea34dd892013-02-05 22:56:02 -08007540 peerMac, action_code, dialog_token, status_code, (tANI_U8 *)buf, len, responder);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007541
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007542 if (VOS_STATUS_SUCCESS != status)
7543 {
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007544 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7545 "%s: sme_SendTdlsMgmtFrame failed!", __func__);
Hoonki Lee5305c3a2013-04-29 23:28:59 -07007546 pAdapter->mgmtTxCompletionStatus = FALSE;
Hoonki Lee14621352013-04-16 17:51:19 -07007547 wlan_hdd_tdls_check_bmps(pAdapter);
7548 goto error;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007549 }
7550
Hoonki Leed37cbb32013-04-20 00:31:14 -07007551 rc = wait_for_completion_interruptible_timeout(&pAdapter->tdls_mgmt_comp,
7552 msecs_to_jiffies(WAIT_TIME_TDLS_MGMT));
7553
7554 if ((rc <= 0) || (TRUE != pAdapter->mgmtTxCompletionStatus))
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007555 {
Hoonki Leed37cbb32013-04-20 00:31:14 -07007556 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7557 "%s: Mgmt Tx Completion failed status %ld TxCompletion %lu",
7558 __func__, rc, pAdapter->mgmtTxCompletionStatus);
Hoonki Lee5305c3a2013-04-29 23:28:59 -07007559 pAdapter->mgmtTxCompletionStatus = FALSE;
Hoonki Leed37cbb32013-04-20 00:31:14 -07007560 wlan_hdd_tdls_check_bmps(pAdapter);
7561 goto error;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007562 }
7563
Gopichand Nakkala05922802013-03-14 12:23:19 -07007564 if (max_sta_failed)
Hoonki Lee14621352013-04-16 17:51:19 -07007565 {
7566 wlan_hdd_tdls_check_bmps(pAdapter);
Gopichand Nakkala05922802013-03-14 12:23:19 -07007567 return max_sta_failed;
Hoonki Lee14621352013-04-16 17:51:19 -07007568 }
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007569
Hoonki Leea34dd892013-02-05 22:56:02 -08007570 if (SIR_MAC_TDLS_SETUP_RSP == action_code)
7571 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08007572 wlan_hdd_tdls_set_responder(pAdapter, peerMac, TRUE);
Hoonki Leea34dd892013-02-05 22:56:02 -08007573 }
7574 else if (SIR_MAC_TDLS_SETUP_CNF == action_code)
7575 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08007576 wlan_hdd_tdls_set_responder(pAdapter, peerMac, FALSE);
Hoonki Leea34dd892013-02-05 22:56:02 -08007577 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007578
7579 return 0;
Gopichand Nakkala05922802013-03-14 12:23:19 -07007580error:
7581 /* max_sta_failed ; we didn't set to CONNECTING for this case,
7582 because we already know that this transaction will be failed,
7583 but we weren't sure if supplicant call DISABLE_LINK or not. So,
7584 to be safe, do not change the state mahine.
7585 */
7586 if(max_sta_failed == 0 &&
7587 (WLAN_IS_TDLS_SETUP_ACTION(action_code)))
7588 wlan_hdd_tdls_set_link_status(pAdapter, peerMac, eTDLS_LINK_IDLE);
7589 return -EPERM;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007590}
7591
7592static int wlan_hdd_cfg80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
7593 u8 *peer, enum nl80211_tdls_operation oper)
7594{
7595 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7596 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307597 int status;
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05307598#ifdef FEATURE_WLAN_TDLS_OXYGEN_DISAPPEAR_AP
7599 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05307600 tANI_U8 staIdx;
7601#endif
Hoonki Lee1090c6a2013-01-16 17:40:54 -08007602#ifdef WLAN_FEATURE_TDLS_DEBUG
7603 const char *tdls_oper_str[]= {
7604 "NL80211_TDLS_DISCOVERY_REQ",
7605 "NL80211_TDLS_SETUP",
7606 "NL80211_TDLS_TEARDOWN",
7607 "NL80211_TDLS_ENABLE_LINK",
7608 "NL80211_TDLS_DISABLE_LINK",
Gopichand Nakkala29d00192013-06-20 19:03:52 +05307609 "NL80211_TDLS_UNKNOWN_OPER"};
Hoonki Lee1090c6a2013-01-16 17:40:54 -08007610#endif
Hoonki Lee5305c3a2013-04-29 23:28:59 -07007611 hddTdlsPeer_t *pTdlsPeer;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007612
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307613 if ( NULL == peer )
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007614 {
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007615 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Chilam Ngc4244af2013-04-01 15:37:32 -07007616 "%s: Invalid arguments", __func__);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007617 return -EINVAL;
7618 }
Hoonki Lee1090c6a2013-01-16 17:40:54 -08007619
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307620 status = wlan_hdd_validate_context(pHddCtx);
7621
7622 if (0 != status)
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08007623 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307624 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7625 "%s: HDD context is not valid", __func__);
7626 return status;
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08007627 }
7628
Hoonki Lee5305c3a2013-04-29 23:28:59 -07007629 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peer);
7630
7631 if ( NULL == pTdlsPeer ) {
7632 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: " MAC_ADDRESS_STR " (oper %d) not exsting. ignored",
7633 __func__, MAC_ADDR_ARRAY(peer), (int)oper);
7634 return -EINVAL;
7635 }
7636
Hoonki Lee1090c6a2013-01-16 17:40:54 -08007637#ifdef WLAN_FEATURE_TDLS_DEBUG
7638 if((int)oper > 4)
7639 oper = 5;
7640
7641 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Hoonki Lee5305c3a2013-04-29 23:28:59 -07007642 "%s: " MAC_ADDRESS_STR " link_status %d (%s) ", "tdls_oper",
7643 MAC_ADDR_ARRAY(peer), pTdlsPeer->link_status,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007644 tdls_oper_str[(int)oper]);
Hoonki Lee1090c6a2013-01-16 17:40:54 -08007645#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007646
7647 if( FALSE == pHddCtx->cfg_ini->fEnableTDLSSupport ||
Hoonki Lee1090c6a2013-01-16 17:40:54 -08007648 FALSE == sme_IsFeatureSupportedByFW(TDLS))
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007649 {
Hoonki Lee1090c6a2013-01-16 17:40:54 -08007650 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Chilam Ngc4244af2013-04-01 15:37:32 -07007651 "TDLS Disabled in INI OR not enabled in FW. "
7652 "Cannot process TDLS commands");
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007653 return -ENOTSUPP;
7654 }
7655
7656 switch (oper) {
7657 case NL80211_TDLS_ENABLE_LINK:
7658 {
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007659 VOS_STATUS status;
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05307660 tCsrTdlsLinkEstablishParams tdlsLinkEstablishParams;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007661
Gopichand Nakkala2f4a2822013-04-17 11:22:01 -07007662 if (!TDLS_STA_INDEX_VALID(pTdlsPeer->staId))
7663 {
7664 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Staion Index %u "
7665 MAC_ADDRESS_STR " failed",
7666 __func__, pTdlsPeer->staId, MAC_ADDR_ARRAY(peer));
7667 return -EINVAL;
7668 }
7669
Hoonki Lee5305c3a2013-04-29 23:28:59 -07007670 if (eTDLS_LINK_CONNECTED != pTdlsPeer->link_status)
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007671 {
Gopichand Nakkala24be5312013-07-02 16:47:12 +05307672 long ret;
7673
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05307674 if (0 != wlan_hdd_tdls_get_link_establish_params(pAdapter, peer,&tdlsLinkEstablishParams)) {
7675 return -EINVAL;
7676 }
7677 INIT_COMPLETION(pAdapter->tdls_link_establish_req_comp);
7678
7679 sme_SendTdlsLinkEstablishParams(WLAN_HDD_GET_HAL_CTX(pAdapter),
7680 pAdapter->sessionId, peer, &tdlsLinkEstablishParams);
7681 /* Send TDLS peer UAPSD capabilities to the firmware and
7682 * register with the TL on after the response for this operation
7683 * is received .
7684 */
Gopichand Nakkala24be5312013-07-02 16:47:12 +05307685 ret = wait_for_completion_interruptible_timeout(&pAdapter->tdls_link_establish_req_comp,
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05307686 msecs_to_jiffies(WAIT_TIME_TDLS_LINK_ESTABLISH_REQ));
Gopichand Nakkala24be5312013-07-02 16:47:12 +05307687 if (ret <= 0)
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05307688 {
7689 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7690 "%s: Link Establish Request Faled Status %ld",
Gopichand Nakkala24be5312013-07-02 16:47:12 +05307691 __func__, ret);
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05307692 return -EINVAL;
7693 }
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07007694 wlan_hdd_tdls_set_peer_link_status(pTdlsPeer, eTDLS_LINK_CONNECTED);
Gopichand Nakkala471708b2013-06-04 20:03:01 +05307695 /* Mark TDLS client Authenticated .*/
7696 status = WLANTL_ChangeSTAState( pHddCtx->pvosContext,
7697 pTdlsPeer->staId,
7698 WLANTL_STA_AUTHENTICATED);
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07007699 if (VOS_STATUS_SUCCESS == status)
7700 {
Hoonki Lee14621352013-04-16 17:51:19 -07007701 if (pTdlsPeer->is_responder == 0)
7702 {
7703 v_U8_t staId = (v_U8_t)pTdlsPeer->staId;
7704
7705 wlan_hdd_tdls_timer_restart(pAdapter,
7706 &pTdlsPeer->initiatorWaitTimeoutTimer,
7707 WAIT_TIME_TDLS_INITIATOR);
7708 /* suspend initiator TX until it receives direct packet from the
7709 reponder or WAIT_TIME_TDLS_INITIATOR timer expires */
7710 WLANTL_SuspendDataTx( (WLAN_HDD_GET_CTX(pAdapter))->pvosContext,
7711 &staId, NULL);
7712 }
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07007713 wlan_hdd_tdls_increment_peer_count(pAdapter);
7714 }
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007715 wlan_hdd_tdls_check_bmps(pAdapter);
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05307716
7717 /* Update TL about the UAPSD masks , to route the packets to firmware */
Gopichand Nakkala574f6d12013-06-27 19:38:43 +05307718 if ((TRUE == pHddCtx->cfg_ini->fEnableTDLSBufferSta)
7719 || pHddCtx->cfg_ini->fTDLSUapsdMask )
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05307720 {
Gopichand Nakkala574f6d12013-06-27 19:38:43 +05307721 int ac;
7722 uint8 ucAc[4] = { WLANTL_AC_VO,
7723 WLANTL_AC_VI,
7724 WLANTL_AC_BK,
7725 WLANTL_AC_BE };
7726 uint8 tlTid[4] = { 7, 5, 2, 3 } ;
7727 for(ac=0; ac < 4; ac++)
7728 {
7729 status = WLANTL_EnableUAPSDForAC( (WLAN_HDD_GET_CTX(pAdapter))->pvosContext,
7730 pTdlsPeer->staId, ucAc[ac],
7731 tlTid[ac], tlTid[ac], 0, 0,
7732 WLANTL_BI_DIR );
7733 }
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05307734 }
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007735 }
7736
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007737 }
7738 break;
7739 case NL80211_TDLS_DISABLE_LINK:
Lee Hoonkic1262f22013-01-24 21:59:00 -08007740 {
Hoonki Lee5305c3a2013-04-29 23:28:59 -07007741 if(TDLS_STA_INDEX_VALID(pTdlsPeer->staId))
Lee Hoonkic1262f22013-01-24 21:59:00 -08007742 {
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07007743 long status;
7744
7745 INIT_COMPLETION(pAdapter->tdls_del_station_comp);
7746
Lee Hoonkic1262f22013-01-24 21:59:00 -08007747 sme_DeleteTdlsPeerSta( WLAN_HDD_GET_HAL_CTX(pAdapter),
7748 pAdapter->sessionId, peer );
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07007749
7750 status = wait_for_completion_interruptible_timeout(&pAdapter->tdls_del_station_comp,
7751 msecs_to_jiffies(WAIT_TIME_TDLS_DEL_STA));
7752 if (status <= 0)
7753 {
Hoonki Lee5305c3a2013-04-29 23:28:59 -07007754 wlan_hdd_tdls_set_peer_link_status(pTdlsPeer, eTDLS_LINK_IDLE);
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07007755 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7756 "%s: Del station failed status %ld",
7757 __func__, status);
7758 return -EPERM;
7759 }
Hoonki Lee5305c3a2013-04-29 23:28:59 -07007760 wlan_hdd_tdls_set_peer_link_status(pTdlsPeer, eTDLS_LINK_IDLE);
Lee Hoonkic1262f22013-01-24 21:59:00 -08007761 }
7762 else
7763 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007764 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7765 "%s: TDLS Peer Station doesn't exist.", __func__);
Lee Hoonkic1262f22013-01-24 21:59:00 -08007766 }
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05307767#ifdef FEATURE_WLAN_TDLS_OXYGEN_DISAPPEAR_AP
7768 if (pHddTdlsCtx->defer_link_lost_indication)
7769 {
7770 if (( TRUE == pHddCtx->cfg_ini->fEnableTDLSOxygenSupport ) &&
7771 (wlan_hdd_tdlsConnectedPeers(pAdapter) == 0))
7772 {
7773 status = wlan_hdd_disconnect(pAdapter, eCSR_DISCONNECT_REASON_UNSPECIFIED);
7774 if ( 0 != status)
7775 {
7776 hddLog(VOS_TRACE_LEVEL_ERROR,
7777 "%s wlan_hdd_disconnect failure, returned %d \n",
7778 __func__, (int)status );
7779 return -EINVAL;
7780 }
7781 }
7782 }
7783#endif
Lee Hoonkic1262f22013-01-24 21:59:00 -08007784 }
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007785 break;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007786 case NL80211_TDLS_TEARDOWN:
7787 case NL80211_TDLS_SETUP:
7788 case NL80211_TDLS_DISCOVERY_REQ:
7789 /* We don't support in-driver setup/teardown/discovery */
7790 return -ENOTSUPP;
7791 default:
7792 return -ENOTSUPP;
7793 }
7794 return 0;
7795}
Chilam NG571c65a2013-01-19 12:27:36 +05307796
7797int wlan_hdd_cfg80211_send_tdls_discover_req(struct wiphy *wiphy,
7798 struct net_device *dev, u8 *peer)
7799{
7800 hddLog(VOS_TRACE_LEVEL_INFO, "tdls send discover req: %x %x %x %x %x %x",
7801 peer[0], peer[1], peer[2], peer[3], peer[4], peer[5]);
7802
7803 return wlan_hdd_cfg80211_tdls_mgmt(wiphy, dev, peer,
7804 WLAN_TDLS_DISCOVERY_REQUEST, 1, 0, NULL, 0);
7805}
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007806#endif
7807
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05307808#ifdef WLAN_FEATURE_GTK_OFFLOAD
7809/*
7810 * FUNCTION: wlan_hdd_cfg80211_update_replayCounterCallback
7811 * Callback rountine called upon receiving response for
7812 * get offload info
7813 */
7814void wlan_hdd_cfg80211_update_replayCounterCallback(void *callbackContext,
7815 tpSirGtkOffloadGetInfoRspParams pGtkOffloadGetInfoRsp)
7816{
7817
7818 hdd_adapter_t *pAdapter = (hdd_adapter_t *)callbackContext;
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05307819 tANI_U8 tempReplayCounter[8];
7820 hdd_station_ctx_t *pHddStaCtx;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05307821
7822 ENTER();
7823
7824 if (NULL == pAdapter)
7825 {
7826 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
7827 "%s: HDD adapter is Null", __func__);
7828 return ;
7829 }
7830
7831 if (NULL == pGtkOffloadGetInfoRsp)
7832 {
7833 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7834 "%s: pGtkOffloadGetInfoRsp is Null", __func__);
7835 return ;
7836 }
7837
7838 if (VOS_STATUS_SUCCESS != pGtkOffloadGetInfoRsp->ulStatus)
7839 {
7840 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7841 "%s: wlan Failed to get replay counter value",
7842 __func__);
7843 return ;
7844 }
7845
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05307846 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
7847 /* Update replay counter */
7848 pHddStaCtx->gtkOffloadReqParams.ullKeyReplayCounter =
7849 pGtkOffloadGetInfoRsp->ullKeyReplayCounter;
7850
7851 {
7852 /* changing from little to big endian since supplicant
7853 * works on big endian format
7854 */
7855 int i;
7856 tANI_U8 *p = (tANI_U8 *)&pGtkOffloadGetInfoRsp->ullKeyReplayCounter;
7857
7858 for (i = 0; i < 8; i++)
7859 {
7860 tempReplayCounter[7-i] = (tANI_U8)p[i];
7861 }
7862 }
7863
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05307864 /* Update replay counter to NL */
7865 cfg80211_gtk_rekey_notify(pAdapter->dev, pGtkOffloadGetInfoRsp->bssId,
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05307866 tempReplayCounter, GFP_KERNEL);
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05307867}
7868
7869/*
7870 * FUNCTION: wlan_hdd_cfg80211_set_rekey_data
7871 * This function is used to offload GTK rekeying job to the firmware.
7872 */
7873int wlan_hdd_cfg80211_set_rekey_data(struct wiphy *wiphy, struct net_device *dev,
7874 struct cfg80211_gtk_rekey_data *data)
7875{
7876 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7877 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
7878 hdd_station_ctx_t *pHddStaCtx;
7879 tHalHandle hHal;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307880 int result;
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05307881 tSirGtkOffloadParams hddGtkOffloadReqParams;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05307882 eHalStatus status = eHAL_STATUS_FAILURE;
7883
7884 ENTER();
7885
7886 if (NULL == pAdapter)
7887 {
7888 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
7889 "%s: HDD adapter is Null", __func__);
7890 return -ENODEV;
7891 }
7892
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307893 result = wlan_hdd_validate_context(pHddCtx);
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05307894
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307895 if (0 != result)
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05307896 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307897 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7898 "%s: HDD context is not valid", __func__);
7899 return result;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05307900 }
7901
7902 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
7903 hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
7904 if (NULL == hHal)
7905 {
7906 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7907 "%s: HAL context is Null!!!", __func__);
7908 return -EAGAIN;
7909 }
7910
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05307911 pHddStaCtx->gtkOffloadReqParams.ulFlags = GTK_OFFLOAD_ENABLE;
7912 memcpy(pHddStaCtx->gtkOffloadReqParams.aKCK, data->kck, NL80211_KCK_LEN);
7913 memcpy(pHddStaCtx->gtkOffloadReqParams.aKEK, data->kek, NL80211_KEK_LEN);
7914 memcpy(pHddStaCtx->gtkOffloadReqParams.bssId, &pHddStaCtx->conn_info.bssId,
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05307915 WNI_CFG_BSSID_LEN);
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05307916 {
7917 /* changing from big to little endian since driver
7918 * works on little endian format
7919 */
7920 tANI_U8 *p =
7921 (tANI_U8 *)&pHddStaCtx->gtkOffloadReqParams.ullKeyReplayCounter;
7922 int i;
7923
7924 for (i = 0; i < 8; i++)
7925 {
7926 p[7-i] = data->replay_ctr[i];
7927 }
7928 }
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05307929
7930 if (TRUE == pHddCtx->hdd_wlan_suspended)
7931 {
7932 /* if wlan is suspended, enable GTK offload directly from here */
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05307933 memcpy(&hddGtkOffloadReqParams, &pHddStaCtx->gtkOffloadReqParams,
7934 sizeof (tSirGtkOffloadParams));
7935 status = sme_SetGTKOffload(hHal, &hddGtkOffloadReqParams,
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05307936 pAdapter->sessionId);
7937
7938 if (eHAL_STATUS_SUCCESS != status)
7939 {
7940 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7941 "%s: sme_SetGTKOffload failed, returned %d",
7942 __func__, status);
7943 return status;
7944 }
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05307945 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
7946 "%s: sme_SetGTKOffload successfull", __func__);
7947 }
7948 else
7949 {
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05307950 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
7951 "%s: wlan not suspended GTKOffload request is stored",
7952 __func__);
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05307953 }
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05307954
7955 return eHAL_STATUS_SUCCESS;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05307956}
7957#endif /*WLAN_FEATURE_GTK_OFFLOAD*/
7958
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05307959/*
7960 * FUNCTION: wlan_hdd_cfg80211_set_mac_acl
7961 * This function is used to set access control policy
7962 */
7963static int wlan_hdd_cfg80211_set_mac_acl(struct wiphy *wiphy,
7964 struct net_device *dev, const struct cfg80211_acl_data *params)
7965{
7966 int i;
7967 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7968 hdd_hostapd_state_t *pHostapdState;
7969 tsap_Config_t *pConfig;
7970 v_CONTEXT_t pVosContext = NULL;
7971 hdd_context_t *pHddCtx;
7972 int status;
7973
7974 ENTER();
7975
7976 if (NULL == pAdapter)
7977 {
7978 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
7979 "%s: HDD adapter is Null", __func__);
7980 return -ENODEV;
7981 }
7982
7983 if (NULL == params)
7984 {
7985 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
7986 "%s: params is Null", __func__);
7987 return -EINVAL;
7988 }
7989
7990 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7991 status = wlan_hdd_validate_context(pHddCtx);
7992
7993 if (0 != status)
7994 {
7995 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7996 "%s: HDD context is not valid", __func__);
7997 return status;
7998 }
7999
8000 pVosContext = pHddCtx->pvosContext;
8001 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
8002
8003 if (NULL == pHostapdState)
8004 {
8005 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8006 "%s: pHostapdState is Null", __func__);
8007 return -EINVAL;
8008 }
8009
8010 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,"acl policy: = %d"
8011 "no acl entries = %d", params->acl_policy, params->n_acl_entries);
8012
8013 if (WLAN_HDD_SOFTAP == pAdapter->device_mode)
8014 {
8015 pConfig = &pAdapter->sessionCtx.ap.sapConfig;
8016
8017 /* default value */
8018 pConfig->num_accept_mac = 0;
8019 pConfig->num_deny_mac = 0;
8020
8021 /**
8022 * access control policy
8023 * @NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED: Deny stations which are
8024 * listed in hostapd.deny file.
8025 * @NL80211_ACL_POLICY_DENY_UNLESS_LISTED: Allow stations which are
8026 * listed in hostapd.accept file.
8027 */
8028 if (NL80211_ACL_POLICY_DENY_UNLESS_LISTED == params->acl_policy)
8029 {
8030 pConfig->SapMacaddr_acl = eSAP_DENY_UNLESS_ACCEPTED;
8031 }
8032 else if (NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED == params->acl_policy)
8033 {
8034 pConfig->SapMacaddr_acl = eSAP_ACCEPT_UNLESS_DENIED;
8035 }
8036 else
8037 {
8038 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8039 "%s:Acl Policy : %d is not supported",
8040 __func__, params->acl_policy);
8041 return -ENOTSUPP;
8042 }
8043
8044 if (eSAP_DENY_UNLESS_ACCEPTED == pConfig->SapMacaddr_acl)
8045 {
8046 pConfig->num_accept_mac = params->n_acl_entries;
8047 for (i = 0; i < params->n_acl_entries; i++)
8048 {
8049 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8050 "** Add ACL MAC entry %i in WhiletList :"
8051 MAC_ADDRESS_STR, i,
8052 MAC_ADDR_ARRAY(params->mac_addrs[i].addr));
8053
8054 vos_mem_copy(&pConfig->accept_mac[i], params->mac_addrs[i].addr,
8055 sizeof(qcmacaddr));
8056 }
8057 }
8058 else if (eSAP_ACCEPT_UNLESS_DENIED == pConfig->SapMacaddr_acl)
8059 {
8060 pConfig->num_deny_mac = params->n_acl_entries;
8061 for (i = 0; i < params->n_acl_entries; i++)
8062 {
8063 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8064 "** Add ACL MAC entry %i in BlackList :"
8065 MAC_ADDRESS_STR, i,
8066 MAC_ADDR_ARRAY(params->mac_addrs[i].addr));
8067
8068 vos_mem_copy(&pConfig->deny_mac[i], params->mac_addrs[i].addr,
8069 sizeof(qcmacaddr));
8070 }
8071 }
8072
8073 if (VOS_STATUS_SUCCESS != WLANSAP_SetMacACL(pVosContext, pConfig))
8074 {
8075 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8076 "%s: SAP Set Mac Acl fail", __func__);
8077 return -EINVAL;
8078 }
8079 }
8080 else
8081 {
8082 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8083 "%s: Invalid device_mode = %d",
8084 __func__, pAdapter->device_mode);
8085 return -EINVAL;
8086 }
8087
8088 return 0;
8089}
8090
Leo Chang9056f462013-08-01 19:21:11 -07008091#ifdef WLAN_NL80211_TESTMODE
8092#ifdef FEATURE_WLAN_LPHB
8093static void wlan_hdd_cfg80211_lphb_wait_timeout_ind_handler
8094(
8095 void *pAdapter,
8096 void *indCont
8097)
8098{
8099 tSirLPHBTimeoutInd *lphbTimeoutInd;
8100 struct sk_buff *skb;
8101
8102 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8103 "LPHB wait timeout indication arrived");
8104
8105 if (NULL == indCont)
8106 {
8107 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8108 "LPHB timeout, invalid argument");
8109 return;
8110 }
8111
8112 lphbTimeoutInd = (tSirLPHBTimeoutInd *)indCont;
8113 skb = cfg80211_testmode_alloc_event_skb(
8114 ((hdd_adapter_t *)pAdapter)->wdev.wiphy,
8115 sizeof(tSirLPHBTimeoutInd),
8116 GFP_ATOMIC);
8117 if (!skb)
8118 {
8119 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8120 "LPHB timeout, NL buffer alloc fail");
8121 return;
8122 }
8123
8124 NLA_PUT_U32(skb, WLAN_HDD_TM_ATTR_CMD, WLAN_HDD_TM_CMD_WLAN_HB);
8125 NLA_PUT_U32(skb, WLAN_HDD_TM_ATTR_TYPE, lphbTimeoutInd->protocolType);
8126 NLA_PUT(skb, WLAN_HDD_TM_ATTR_DATA,
8127 sizeof(tSirLPHBTimeoutInd), lphbTimeoutInd);
8128 cfg80211_testmode_event(skb, GFP_ATOMIC);
8129 return;
8130
8131nla_put_failure:
8132 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8133 "NLA Put fail");
8134 kfree_skb(skb);
8135
8136 return;
8137}
8138#endif /* FEATURE_WLAN_LPHB */
8139
8140static int wlan_hdd_cfg80211_testmode(struct wiphy *wiphy, void *data, int len)
8141{
8142 struct nlattr *tb[WLAN_HDD_TM_ATTR_MAX + 1];
8143 int err = 0;
8144#ifdef FEATURE_WLAN_LPHB
8145 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
8146#endif /* FEATURE_WLAN_LPHB */
8147
8148 err = nla_parse(tb, WLAN_HDD_TM_ATTR_MAX, data, len, wlan_hdd_tm_policy);
8149 if (err)
8150 {
8151 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8152 "%s Testmode INV ATTR", __func__);
8153 return err;
8154 }
8155
8156 if (!tb[WLAN_HDD_TM_ATTR_CMD])
8157 {
8158 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8159 "%s Testmode INV CMD", __func__);
8160 return -EINVAL;
8161 }
8162
8163 switch (nla_get_u32(tb[WLAN_HDD_TM_ATTR_CMD]))
8164 {
8165#ifdef FEATURE_WLAN_LPHB
8166 /* Low Power Heartbeat configuration request */
8167 case WLAN_HDD_TM_CMD_WLAN_HB:
8168 {
8169 int buf_len;
8170 void *buf;
8171 tSirLPHBReq *hb_params = NULL;
8172
8173 if (!tb[WLAN_HDD_TM_ATTR_DATA])
8174 {
8175 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8176 "%s Testmode INV DATA", __func__);
8177 return -EINVAL;
8178 }
8179
8180 buf = nla_data(tb[WLAN_HDD_TM_ATTR_DATA]);
8181 buf_len = nla_len(tb[WLAN_HDD_TM_ATTR_DATA]);
8182 hb_params = (tSirLPHBReq *)vos_mem_malloc(sizeof(tSirLPHBReq));
8183 if (NULL == hb_params)
8184 {
8185 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8186 "%s Request Buffer Alloc Fail", __func__);
8187 return -EINVAL;
8188 }
8189
8190 vos_mem_copy(hb_params, buf, buf_len);
8191
8192 /* LPHB enable and disable request will send to FW
8193 * when host suspend and resume
8194 * host suspend -> enable LPHB
8195 * host resume -> disable LPHB
8196 * if host is not suspend, cache into HDD context
8197 * and when host goes to suspend, send request to FW */
8198 if ((LPHB_SET_EN_PARAMS_INDID == hb_params->cmd) &&
8199 (!pHddCtx->hdd_wlan_suspended))
8200 {
8201 /* Feature enable command cache into HDD context,
8202 * if WLAN is not suspend
8203 * When WLAN goes into suspend, send enable command to FW */
8204 pHddCtx->lphbEnableReq.enable =
8205 hb_params->params.lphbEnableReq.enable;
8206 pHddCtx->lphbEnableReq.item =
8207 hb_params->params.lphbEnableReq.item;
8208 pHddCtx->lphbEnableReq.session =
8209 hb_params->params.lphbEnableReq.session;
8210 vos_mem_free(hb_params);
8211 }
8212 else
8213 {
8214 eHalStatus smeStatus;
8215
8216 /* If WLAN is suspend state, send enable command immediately */
8217 smeStatus = sme_LPHBConfigReq((tHalHandle)(pHddCtx->hHal),
8218 hb_params,
8219 wlan_hdd_cfg80211_lphb_wait_timeout_ind_handler);
8220 if (eHAL_STATUS_SUCCESS != smeStatus)
8221 {
8222 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8223 "LPHB Config Fail, disable");
8224 pHddCtx->lphbEnableReq.enable = 0;
8225 vos_mem_free(hb_params);
8226 }
8227 }
8228 return 0;
8229 }
8230#endif /* FEATURE_WLAN_LPHB */
8231 default:
8232 return -EOPNOTSUPP;
8233 }
8234
8235 return err;
8236}
8237#endif /* CONFIG_NL80211_TESTMODE */
8238
Jeff Johnson295189b2012-06-20 16:38:30 -07008239/* cfg80211_ops */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05308240static struct cfg80211_ops wlan_hdd_cfg80211_ops =
Jeff Johnson295189b2012-06-20 16:38:30 -07008241{
8242 .add_virtual_intf = wlan_hdd_add_virtual_intf,
8243 .del_virtual_intf = wlan_hdd_del_virtual_intf,
8244 .change_virtual_intf = wlan_hdd_cfg80211_change_iface,
8245 .change_station = wlan_hdd_change_station,
8246#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
8247 .add_beacon = wlan_hdd_cfg80211_add_beacon,
8248 .del_beacon = wlan_hdd_cfg80211_del_beacon,
8249 .set_beacon = wlan_hdd_cfg80211_set_beacon,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008250#else
8251 .start_ap = wlan_hdd_cfg80211_start_ap,
8252 .change_beacon = wlan_hdd_cfg80211_change_beacon,
8253 .stop_ap = wlan_hdd_cfg80211_stop_ap,
Jeff Johnson295189b2012-06-20 16:38:30 -07008254#endif
8255 .change_bss = wlan_hdd_cfg80211_change_bss,
8256 .add_key = wlan_hdd_cfg80211_add_key,
8257 .get_key = wlan_hdd_cfg80211_get_key,
8258 .del_key = wlan_hdd_cfg80211_del_key,
8259 .set_default_key = wlan_hdd_cfg80211_set_default_key,
Jeff Johnson3bbe4bf2013-01-18 17:05:29 -08008260#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07008261 .set_channel = wlan_hdd_cfg80211_set_channel,
Jeff Johnson3bbe4bf2013-01-18 17:05:29 -08008262#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07008263 .scan = wlan_hdd_cfg80211_scan,
8264 .connect = wlan_hdd_cfg80211_connect,
8265 .disconnect = wlan_hdd_cfg80211_disconnect,
8266 .join_ibss = wlan_hdd_cfg80211_join_ibss,
8267 .leave_ibss = wlan_hdd_cfg80211_leave_ibss,
8268 .set_wiphy_params = wlan_hdd_cfg80211_set_wiphy_params,
8269 .set_tx_power = wlan_hdd_cfg80211_set_txpower,
8270 .get_tx_power = wlan_hdd_cfg80211_get_txpower,
Jeff Johnson295189b2012-06-20 16:38:30 -07008271 .remain_on_channel = wlan_hdd_cfg80211_remain_on_channel,
8272 .cancel_remain_on_channel = wlan_hdd_cfg80211_cancel_remain_on_channel,
8273 .mgmt_tx = wlan_hdd_action,
8274#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
8275 .mgmt_tx_cancel_wait = wlan_hdd_cfg80211_mgmt_tx_cancel_wait,
8276 .set_default_mgmt_key = wlan_hdd_set_default_mgmt_key,
8277 .set_txq_params = wlan_hdd_set_txq_params,
8278#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07008279 .get_station = wlan_hdd_cfg80211_get_station,
8280 .set_power_mgmt = wlan_hdd_cfg80211_set_power_mgmt,
8281 .del_station = wlan_hdd_cfg80211_del_station,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008282 .add_station = wlan_hdd_cfg80211_add_station,
8283#ifdef FEATURE_WLAN_LFR
8284 .set_pmksa = wlan_hdd_cfg80211_set_pmksa,
8285 .del_pmksa = wlan_hdd_cfg80211_del_pmksa,
8286 .flush_pmksa = wlan_hdd_cfg80211_flush_pmksa,
8287#endif
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07008288#if defined(WLAN_FEATURE_VOWIFI_11R) && defined(KERNEL_SUPPORT_11R_CFG80211)
8289 .update_ft_ies = wlan_hdd_cfg80211_update_ft_ies,
8290#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008291#ifdef FEATURE_WLAN_TDLS
8292 .tdls_mgmt = wlan_hdd_cfg80211_tdls_mgmt,
8293 .tdls_oper = wlan_hdd_cfg80211_tdls_oper,
8294#endif
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308295#ifdef WLAN_FEATURE_GTK_OFFLOAD
8296 .set_rekey_data = wlan_hdd_cfg80211_set_rekey_data,
8297#endif /* WLAN_FEATURE_GTK_OFFLOAD */
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308298#ifdef FEATURE_WLAN_SCAN_PNO
8299 .sched_scan_start = wlan_hdd_cfg80211_sched_scan_start,
8300 .sched_scan_stop = wlan_hdd_cfg80211_sched_scan_stop,
8301#endif /*FEATURE_WLAN_SCAN_PNO */
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05308302 .set_mac_acl = wlan_hdd_cfg80211_set_mac_acl,
Leo Chang9056f462013-08-01 19:21:11 -07008303#ifdef WLAN_NL80211_TESTMODE
8304 .testmode_cmd = wlan_hdd_cfg80211_testmode,
8305#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07008306};
8307