blob: f78c7565aedce4b28eee70e00565bba66a8d0f74 [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/*
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530534 * FUNCTION: wlan_hdd_cfg80211_wiphy_alloc
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530535 * This function is called by hdd_wlan_startup()
536 * during initialization.
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530537 * This function is used to allocate wiphy structure.
Jeff Johnson295189b2012-06-20 16:38:30 -0700538 */
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530539struct wiphy *wlan_hdd_cfg80211_wiphy_alloc(int priv_size)
Jeff Johnson295189b2012-06-20 16:38:30 -0700540{
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 */
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530628int wlan_hdd_cfg80211_init(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 int i, j;
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530634 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
Jeff Johnsone7245742012-09-05 17:12:55 -0700635 ENTER();
636
Jeff Johnson295189b2012-06-20 16:38:30 -0700637 /* Now bind the underlying wlan device with wiphy */
638 set_wiphy_dev(wiphy, dev);
639
640 wiphy->mgmt_stypes = wlan_hdd_txrx_stypes;
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530641 if (memcmp(pHddCtx->cfg_ini->crdaDefaultCountryCode,
642 CFG_CRDA_DEFAULT_COUNTRY_CODE_DEFAULT , 2) != 0)
643 {
644 wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY;
645 }
646 else
647 {
Madan Mohan Koyyalamudi99ba3582013-05-16 12:52:48 +0530648 /* This will disable updating of NL channels from passive to
649 * active if a beacon is received on passive channel. */
650 wiphy->flags |= WIPHY_FLAG_DISABLE_BEACON_HINTS;
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530651 wiphy->flags |= WIPHY_FLAG_STRICT_REGULATORY;
652 }
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700653#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
Madan Mohan Koyyalamudi1b4afb02012-10-22 15:25:16 -0700654 wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME
655 | WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
656 | WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
Jeff Johnsone7245742012-09-05 17:12:55 -0700657 | WIPHY_FLAG_OFFCHAN_TX;
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700658#endif
Srinivas Girigowda640728a2013-03-28 12:21:54 -0700659#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_CCX) || defined(FEATURE_WLAN_LFR)
660 if (pCfg->isFastTransitionEnabled
James Zmuda77fb5ae2013-01-29 08:00:17 -0800661#ifdef FEATURE_WLAN_LFR
Srinivas Girigowda640728a2013-03-28 12:21:54 -0700662 || pCfg->isFastRoamIniFeatureEnabled
663#endif
664#ifdef FEATURE_WLAN_CCX
665 || pCfg->isCcxIniFeatureEnabled
666#endif
667 )
668 {
669 wiphy->flags |= WIPHY_FLAG_SUPPORTS_FW_ROAM;
670 }
James Zmuda77fb5ae2013-01-29 08:00:17 -0800671#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -0800672#ifdef FEATURE_WLAN_TDLS
673 wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS
674 | WIPHY_FLAG_TDLS_EXTERNAL_SETUP;
675#endif
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +0530676#ifdef FEATURE_WLAN_SCAN_PNO
677 wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
678 wiphy->max_sched_scan_ssids = MAX_SCAN_SSID;
679 wiphy->max_match_sets = SIR_PNO_MAX_SUPP_NETWORKS;
680#endif/*FEATURE_WLAN_SCAN_PNO*/
Mohit Khanna698ba2a2012-12-04 15:08:18 -0800681
Madan Mohan Koyyalamudic3a240c2012-09-28 15:34:08 -0700682 /* even with WIPHY_FLAG_CUSTOM_REGULATORY,
683 driver can still register regulatory callback and
684 it will get CRDA setting in wiphy->band[], but
685 driver need to determine what to do with both
686 regulatory settings */
687 wiphy->reg_notifier = wlan_hdd_crda_reg_notifier;
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700688
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530689 wiphy->max_scan_ssids = MAX_SCAN_SSID;
690
Madan Mohan Koyyalamudi6815b162013-07-19 17:17:46 +0530691 wiphy->max_scan_ie_len = SIR_MAC_MAX_IE_LENGTH;
Jeff Johnson295189b2012-06-20 16:38:30 -0700692
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +0530693 wiphy->max_acl_mac_addrs = MAX_ACL_MAC_ADDRESS;
694
Jeff Johnson295189b2012-06-20 16:38:30 -0700695 /* Supports STATION & AD-HOC modes right now */
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530696 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION)
Jeff Johnson295189b2012-06-20 16:38:30 -0700697 | BIT(NL80211_IFTYPE_ADHOC)
Jeff Johnson295189b2012-06-20 16:38:30 -0700698 | BIT(NL80211_IFTYPE_P2P_CLIENT)
699 | BIT(NL80211_IFTYPE_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -0700700 | BIT(NL80211_IFTYPE_AP);
701
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800702#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800703 if( pCfg->enableMCC )
704 {
705 /* Currently, supports up to two channels */
706 wlan_hdd_iface_combination.num_different_channels = 2;
707
708 if( !pCfg->allowMCCGODiffBI )
709 wlan_hdd_iface_combination.beacon_int_infra_match = true;
710
711 }
712 wiphy->iface_combinations = &wlan_hdd_iface_combination;
713 wiphy->n_iface_combinations = 1;
714#endif
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800715
Jeff Johnson295189b2012-06-20 16:38:30 -0700716 /* Before registering we need to update the ht capabilitied based
717 * on ini values*/
718 if( !pCfg->ShortGI20MhzEnable )
719 {
720 wlan_hdd_band_2_4_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_20;
721 wlan_hdd_band_5_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_20;
722 wlan_hdd_band_p2p_2_4_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_20;
723 }
724
725 if( !pCfg->ShortGI40MhzEnable )
726 {
727 wlan_hdd_band_5_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_40;
728 }
729
730 if( !pCfg->nChannelBondingMode5GHz )
731 {
732 wlan_hdd_band_5_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
733 }
734
Gopichand Nakkala1f7a64f2013-04-01 18:37:17 +0530735 wiphy->bands[IEEE80211_BAND_2GHZ] = &wlan_hdd_band_2_4_GHZ;
736 wiphy->bands[IEEE80211_BAND_5GHZ] = &wlan_hdd_band_5_GHZ;
737
738 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
739 {
740
741 if (NULL == wiphy->bands[i])
742 {
743 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy->bands[i] is NULL, i = %d",
744 __func__, i);
745 continue;
746 }
747
748 for (j = 0; j < wiphy->bands[i]->n_channels; j++)
749 {
750 struct ieee80211_supported_band *band = wiphy->bands[i];
751
752 if (IEEE80211_BAND_2GHZ == i && eCSR_BAND_5G == pCfg->nBandCapability) // 5G only
753 {
754 // Enable social channels for P2P
755 if (WLAN_HDD_IS_SOCIAL_CHANNEL(band->channels[j].center_freq))
756 band->channels[j].flags &= ~IEEE80211_CHAN_DISABLED;
757 else
758 band->channels[j].flags |= IEEE80211_CHAN_DISABLED;
759 continue;
760 }
761 else if (IEEE80211_BAND_5GHZ == i && eCSR_BAND_24 == pCfg->nBandCapability) // 2G only
762 {
763 band->channels[j].flags |= IEEE80211_CHAN_DISABLED;
764 continue;
765 }
766 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700767 }
768 /*Initialise the supported cipher suite details*/
769 wiphy->cipher_suites = hdd_cipher_suites;
770 wiphy->n_cipher_suites = ARRAY_SIZE(hdd_cipher_suites);
771
772 /*signal strength in mBm (100*dBm) */
773 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
774
775#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
Jeff Johnson295189b2012-06-20 16:38:30 -0700776 wiphy->max_remain_on_channel_duration = 1000;
777#endif
Jeff Johnson295189b2012-06-20 16:38:30 -0700778
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530779 EXIT();
780 return 0;
781}
782
783/* In this function we are registering wiphy. */
784int wlan_hdd_cfg80211_register(struct wiphy *wiphy)
785{
786 ENTER();
787 /* Register our wiphy dev with cfg80211 */
Jeff Johnson295189b2012-06-20 16:38:30 -0700788 if (0 > wiphy_register(wiphy))
789 {
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530790 /* print error */
Jeff Johnson295189b2012-06-20 16:38:30 -0700791 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy register failed", __func__);
792 return -EIO;
793 }
794
795 EXIT();
796 return 0;
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530797}
Jeff Johnson295189b2012-06-20 16:38:30 -0700798
Madan Mohan Koyyalamudic3a240c2012-09-28 15:34:08 -0700799/* In this function we will try to get default country code from crda.
800 If the gCrdaDefaultCountryCode is configured in ini file,
801 we will try to call user space crda to get the regulatory settings for
802 that country. We will timeout if we can't get it from crda.
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530803 It's called by hdd_wlan_startup() after wlan_hdd_cfg80211_init.
Madan Mohan Koyyalamudic3a240c2012-09-28 15:34:08 -0700804*/
805int wlan_hdd_get_crda_regd_entry(struct wiphy *wiphy, hdd_config_t *pCfg)
806{
807 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
Madan Mohan Koyyalamudi113ac742013-08-06 22:45:43 +0530808 int status;
809
Madan Mohan Koyyalamudic3a240c2012-09-28 15:34:08 -0700810 if (memcmp(pCfg->crdaDefaultCountryCode,
811 CFG_CRDA_DEFAULT_COUNTRY_CODE_DEFAULT , 2) != 0)
812 {
Madan Mohan Koyyalamudi113ac742013-08-06 22:45:43 +0530813 INIT_COMPLETION(pHddCtx->driver_crda_req);
Madan Mohan Koyyalamudic3a240c2012-09-28 15:34:08 -0700814 regulatory_hint(wiphy, pCfg->crdaDefaultCountryCode);
Madan Mohan Koyyalamudi113ac742013-08-06 22:45:43 +0530815 status = wait_for_completion_interruptible_timeout(
816 &pHddCtx->driver_crda_req,
817 msecs_to_jiffies(CRDA_WAIT_TIME));
818 if (!status)
819 {
820 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: timeout waiting for CRDA REQ",
821 __func__);
822 }
823
Yunsen Wange3ba1fb2013-04-05 15:04:43 -0700824 /* if the country is not found from current regulatory.bin,
825 fall back to world domain */
826 if (is_crda_regulatory_entry_valid() == VOS_FALSE)
827 crda_regulatory_entry_default(pCfg->crdaDefaultCountryCode, NUM_REG_DOMAINS-1);
Madan Mohan Koyyalamudic3a240c2012-09-28 15:34:08 -0700828 }
829 return 0;
830}
831
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530832/* In this function we are updating channel list when,
833 regulatory domain is FCC and country code is US.
834 Here In FCC standard 5GHz UNII-1 Bands are indoor only.
835 As per FCC smart phone is not a indoor device.
836 GO should not opeate on indoor channels */
837void wlan_hdd_cfg80211_update_reg_info(struct wiphy *wiphy)
838{
839 int j;
840 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
841 tANI_U8 defaultCountryCode[3] = SME_INVALID_COUNTRY_CODE;
842 //Default counrtycode from NV at the time of wiphy initialization.
843 if (eHAL_STATUS_SUCCESS != sme_GetDefaultCountryCodeFrmNv(pHddCtx->hHal,
844 &defaultCountryCode[0]))
845 {
846 hddLog(LOGE, FL("%s Failed to get default country code from NV"));
847 }
848 if ((defaultCountryCode[0]== 'U') && (defaultCountryCode[1]=='S'))
849 {
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530850 if (NULL == wiphy->bands[IEEE80211_BAND_5GHZ])
851 {
852 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy->bands[IEEE80211_BAND_5GHZ] is NULL",__func__ );
853 return;
854 }
855 for (j = 0; j < wiphy->bands[IEEE80211_BAND_5GHZ]->n_channels; j++)
856 {
857 struct ieee80211_supported_band *band = wiphy->bands[IEEE80211_BAND_5GHZ];
858 // Mark UNII -1 band channel as passive
859 if (WLAN_HDD_CHANNEL_IN_UNII_1_BAND(band->channels[j].center_freq))
860 band->channels[j].flags |= IEEE80211_CHAN_PASSIVE_SCAN;
861 }
862 }
863}
864
Jeff Johnson295189b2012-06-20 16:38:30 -0700865/* In this function we will do all post VOS start initialization.
866 In this function we will register for all frame in which supplicant
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530867 is interested.
Jeff Johnson295189b2012-06-20 16:38:30 -0700868*/
869void wlan_hdd_cfg80211_post_voss_start(hdd_adapter_t* pAdapter)
870{
Jeff Johnson295189b2012-06-20 16:38:30 -0700871 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
872 /* Register for all P2P action, public action etc frames */
873 v_U16_t type = (SIR_MAC_MGMT_FRAME << 2) | ( SIR_MAC_MGMT_ACTION << 4);
874
Jeff Johnsone7245742012-09-05 17:12:55 -0700875 ENTER();
876
Jeff Johnson295189b2012-06-20 16:38:30 -0700877 /* Right now we are registering these frame when driver is getting
878 initialized. Once we will move to 2.6.37 kernel, in which we have
879 frame register ops, we will move this code as a part of that */
880 /* GAS Initial Request */
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530881 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
Jeff Johnson295189b2012-06-20 16:38:30 -0700882 (v_U8_t*)GAS_INITIAL_REQ, GAS_INITIAL_REQ_SIZE );
883
884 /* GAS Initial Response */
885 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
886 (v_U8_t*)GAS_INITIAL_RSP, GAS_INITIAL_RSP_SIZE );
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530887
Jeff Johnson295189b2012-06-20 16:38:30 -0700888 /* GAS Comeback Request */
889 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
890 (v_U8_t*)GAS_COMEBACK_REQ, GAS_COMEBACK_REQ_SIZE );
891
892 /* GAS Comeback Response */
893 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
894 (v_U8_t*)GAS_COMEBACK_RSP, GAS_COMEBACK_RSP_SIZE );
895
896 /* P2P Public Action */
897 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530898 (v_U8_t*)P2P_PUBLIC_ACTION_FRAME,
Jeff Johnson295189b2012-06-20 16:38:30 -0700899 P2P_PUBLIC_ACTION_FRAME_SIZE );
900
901 /* P2P Action */
902 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
903 (v_U8_t*)P2P_ACTION_FRAME,
904 P2P_ACTION_FRAME_SIZE );
Chet Lanctot186b5732013-03-18 10:26:30 -0700905
Gopichand Nakkalae3d56e72013-04-21 23:33:32 +0530906 /* WNM BSS Transition Request frame */
907 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
908 (v_U8_t*)WNM_BSS_ACTION_FRAME,
909 WNM_BSS_ACTION_FRAME_SIZE );
910
Chet Lanctot186b5732013-03-18 10:26:30 -0700911#ifdef WLAN_FEATURE_11W
912 /* SA Query Response Action Frame */
913 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
914 (v_U8_t*)SA_QUERY_FRAME_RSP,
915 SA_QUERY_FRAME_RSP_SIZE );
916#endif /* WLAN_FEATURE_11W */
Jeff Johnson295189b2012-06-20 16:38:30 -0700917}
918
919void wlan_hdd_cfg80211_pre_voss_stop(hdd_adapter_t* pAdapter)
920{
Jeff Johnson295189b2012-06-20 16:38:30 -0700921 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
922 /* Register for all P2P action, public action etc frames */
923 v_U16_t type = (SIR_MAC_MGMT_FRAME << 2) | ( SIR_MAC_MGMT_ACTION << 4);
924
Jeff Johnsone7245742012-09-05 17:12:55 -0700925 ENTER();
926
Jeff Johnson295189b2012-06-20 16:38:30 -0700927 /* Right now we are registering these frame when driver is getting
928 initialized. Once we will move to 2.6.37 kernel, in which we have
929 frame register ops, we will move this code as a part of that */
930 /* GAS Initial Request */
931
932 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
933 (v_U8_t*)GAS_INITIAL_REQ, GAS_INITIAL_REQ_SIZE );
934
935 /* GAS Initial Response */
936 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
937 (v_U8_t*)GAS_INITIAL_RSP, GAS_INITIAL_RSP_SIZE );
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530938
Jeff Johnson295189b2012-06-20 16:38:30 -0700939 /* GAS Comeback Request */
940 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
941 (v_U8_t*)GAS_COMEBACK_REQ, GAS_COMEBACK_REQ_SIZE );
942
943 /* GAS Comeback Response */
944 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
945 (v_U8_t*)GAS_COMEBACK_RSP, GAS_COMEBACK_RSP_SIZE );
946
947 /* P2P Public Action */
948 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530949 (v_U8_t*)P2P_PUBLIC_ACTION_FRAME,
Jeff Johnson295189b2012-06-20 16:38:30 -0700950 P2P_PUBLIC_ACTION_FRAME_SIZE );
951
952 /* P2P Action */
953 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
954 (v_U8_t*)P2P_ACTION_FRAME,
955 P2P_ACTION_FRAME_SIZE );
Chet Lanctot186b5732013-03-18 10:26:30 -0700956
957#ifdef WLAN_FEATURE_11W
958 /* SA Query Response Action Frame */
959 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
960 (v_U8_t*)SA_QUERY_FRAME_RSP,
961 SA_QUERY_FRAME_RSP_SIZE );
962#endif /* WLAN_FEATURE_11W */
Jeff Johnson295189b2012-06-20 16:38:30 -0700963}
964
965#ifdef FEATURE_WLAN_WAPI
966void wlan_hdd_cfg80211_set_key_wapi(hdd_adapter_t* pAdapter, u8 key_index,
967 const u8 *mac_addr, u8 *key , int key_Len)
968{
969 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
970 tCsrRoamSetKey setKey;
971 v_BOOL_t isConnected = TRUE;
972 int status = 0;
973 v_U32_t roamId= 0xFF;
974 tANI_U8 *pKeyPtr = NULL;
975 int n = 0;
976
977 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
978 __func__,pAdapter->device_mode);
979
Gopichand Nakkalae7480202013-02-11 15:24:22 +0530980 vos_mem_zero(&setKey, sizeof(tCsrRoamSetKey));
Jeff Johnson295189b2012-06-20 16:38:30 -0700981 setKey.keyId = key_index; // Store Key ID
982 setKey.encType = eCSR_ENCRYPT_TYPE_WPI; // SET WAPI Encryption
983 setKey.keyDirection = eSIR_TX_RX; // Key Directionn both TX and RX
984 setKey.paeRole = 0 ; // the PAE role
985 if (!mac_addr || is_broadcast_ether_addr(mac_addr))
986 {
987 vos_set_macaddr_broadcast( (v_MACADDR_t *)setKey.peerMac );
988 }
989 else
990 {
991 isConnected = hdd_connIsConnected(pHddStaCtx);
992 vos_mem_copy(setKey.peerMac,&pHddStaCtx->conn_info.bssId,WNI_CFG_BSSID_LEN);
993 }
994 setKey.keyLength = key_Len;
995 pKeyPtr = setKey.Key;
996 memcpy( pKeyPtr, key, key_Len);
997
998 hddLog(VOS_TRACE_LEVEL_INFO,"\n%s: WAPI KEY LENGTH:0x%04x",
999 __func__, key_Len);
1000 for (n = 0 ; n < key_Len; n++)
1001 hddLog(VOS_TRACE_LEVEL_INFO, "%s WAPI KEY Data[%d]:%02x ",
1002 __func__,n,setKey.Key[n]);
1003
1004 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_SETTING_KEY;
1005 if ( isConnected )
1006 {
1007 status= sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
1008 pAdapter->sessionId, &setKey, &roamId );
1009 }
1010 if ( status != 0 )
1011 {
1012 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1013 "[%4d] sme_RoamSetKey returned ERROR status= %d",
1014 __LINE__, status );
1015 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
1016 }
1017}
1018#endif /* FEATURE_WLAN_WAPI*/
1019
1020#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301021int wlan_hdd_cfg80211_alloc_new_beacon(hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07001022 beacon_data_t **ppBeacon,
1023 struct beacon_parameters *params)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001024#else
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301025int wlan_hdd_cfg80211_alloc_new_beacon(hdd_adapter_t *pAdapter,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001026 beacon_data_t **ppBeacon,
1027 struct cfg80211_beacon_data *params,
1028 int dtim_period)
1029#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301030{
Jeff Johnson295189b2012-06-20 16:38:30 -07001031 int size;
1032 beacon_data_t *beacon = NULL;
1033 beacon_data_t *old = NULL;
1034 int head_len,tail_len;
1035
Jeff Johnsone7245742012-09-05 17:12:55 -07001036 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07001037 if (params->head && !params->head_len)
1038 return -EINVAL;
1039
1040 old = pAdapter->sessionCtx.ap.beacon;
1041
1042 if (!params->head && !old)
1043 return -EINVAL;
1044
1045 if (params->tail && !params->tail_len)
1046 return -EINVAL;
1047
1048#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,38))
1049 /* Kernel 3.0 is not updating dtim_period for set beacon */
1050 if (!params->dtim_period)
1051 return -EINVAL;
1052#endif
1053
1054 if(params->head)
1055 head_len = params->head_len;
1056 else
1057 head_len = old->head_len;
1058
1059 if(params->tail || !old)
1060 tail_len = params->tail_len;
1061 else
1062 tail_len = old->tail_len;
1063
1064 size = sizeof(beacon_data_t) + head_len + tail_len;
1065
1066 beacon = kzalloc(size, GFP_KERNEL);
1067
1068 if( beacon == NULL )
1069 return -ENOMEM;
1070
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001071#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07001072 if(params->dtim_period || !old )
1073 beacon->dtim_period = params->dtim_period;
1074 else
1075 beacon->dtim_period = old->dtim_period;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001076#else
1077 if(dtim_period || !old )
1078 beacon->dtim_period = dtim_period;
1079 else
1080 beacon->dtim_period = old->dtim_period;
1081#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301082
Jeff Johnson295189b2012-06-20 16:38:30 -07001083 beacon->head = ((u8 *) beacon) + sizeof(beacon_data_t);
1084 beacon->tail = beacon->head + head_len;
1085 beacon->head_len = head_len;
1086 beacon->tail_len = tail_len;
1087
1088 if(params->head) {
1089 memcpy (beacon->head,params->head,beacon->head_len);
1090 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301091 else {
Jeff Johnson295189b2012-06-20 16:38:30 -07001092 if(old)
1093 memcpy (beacon->head,old->head,beacon->head_len);
1094 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301095
Jeff Johnson295189b2012-06-20 16:38:30 -07001096 if(params->tail) {
1097 memcpy (beacon->tail,params->tail,beacon->tail_len);
1098 }
1099 else {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301100 if(old)
Jeff Johnson295189b2012-06-20 16:38:30 -07001101 memcpy (beacon->tail,old->tail,beacon->tail_len);
1102 }
1103
1104 *ppBeacon = beacon;
1105
1106 kfree(old);
1107
1108 return 0;
1109
1110}
Jeff Johnson295189b2012-06-20 16:38:30 -07001111
1112v_U8_t* wlan_hdd_cfg80211_get_ie_ptr(v_U8_t *pIes, int length, v_U8_t eid)
1113{
1114 int left = length;
1115 v_U8_t *ptr = pIes;
1116 v_U8_t elem_id,elem_len;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301117
Jeff Johnson295189b2012-06-20 16:38:30 -07001118 while(left >= 2)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301119 {
Jeff Johnson295189b2012-06-20 16:38:30 -07001120 elem_id = ptr[0];
1121 elem_len = ptr[1];
1122 left -= 2;
1123 if(elem_len > left)
1124 {
1125 hddLog(VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi8bdd3112012-09-24 13:55:14 -07001126 FL("****Invalid IEs eid = %d elem_len=%d left=%d*****"),
Jeff Johnson295189b2012-06-20 16:38:30 -07001127 eid,elem_len,left);
1128 return NULL;
1129 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301130 if (elem_id == eid)
Jeff Johnson295189b2012-06-20 16:38:30 -07001131 {
1132 return ptr;
1133 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301134
Jeff Johnson295189b2012-06-20 16:38:30 -07001135 left -= elem_len;
1136 ptr += (elem_len + 2);
1137 }
1138 return NULL;
1139}
1140
Jeff Johnson295189b2012-06-20 16:38:30 -07001141/* Check if rate is 11g rate or not */
1142static int wlan_hdd_rate_is_11g(u8 rate)
1143{
Sanjay Devnani28322e22013-06-21 16:13:40 -07001144 static const u8 gRateArray[8] = {12, 18, 24, 36, 48, 72, 96, 108}; /* actual rate * 2 */
Jeff Johnson295189b2012-06-20 16:38:30 -07001145 u8 i;
1146 for (i = 0; i < 8; i++)
1147 {
1148 if(rate == gRateArray[i])
1149 return TRUE;
1150 }
1151 return FALSE;
1152}
1153
1154/* Check for 11g rate and set proper 11g only mode */
1155static void wlan_hdd_check_11gmode(u8 *pIe, u8* require_ht,
1156 u8* pCheckRatesfor11g, eSapPhyMode* pSapHw_mode)
1157{
1158 u8 i, num_rates = pIe[0];
1159
1160 pIe += 1;
1161 for ( i = 0; i < num_rates; i++)
1162 {
1163 if( *pCheckRatesfor11g && (TRUE == wlan_hdd_rate_is_11g(pIe[i] & RATE_MASK)))
1164 {
1165 /* If rate set have 11g rate than change the mode to 11G */
1166 *pSapHw_mode = eSAP_DOT11_MODE_11g;
1167 if (pIe[i] & BASIC_RATE_MASK)
1168 {
1169 /* If we have 11g rate as basic rate, it means mode
1170 is 11g only mode.
1171 */
1172 *pSapHw_mode = eSAP_DOT11_MODE_11g_ONLY;
1173 *pCheckRatesfor11g = FALSE;
1174 }
1175 }
1176 else if((BASIC_RATE_MASK | WLAN_BSS_MEMBERSHIP_SELECTOR_HT_PHY) == pIe[i])
1177 {
1178 *require_ht = TRUE;
1179 }
1180 }
1181 return;
1182}
1183
1184static void wlan_hdd_set_sapHwmode(hdd_adapter_t *pHostapdAdapter)
1185{
1186 tsap_Config_t *pConfig = &pHostapdAdapter->sessionCtx.ap.sapConfig;
1187 beacon_data_t *pBeacon = pHostapdAdapter->sessionCtx.ap.beacon;
1188 struct ieee80211_mgmt *pMgmt_frame = (struct ieee80211_mgmt*)pBeacon->head;
1189 u8 checkRatesfor11g = TRUE;
1190 u8 require_ht = FALSE;
1191 u8 *pIe=NULL;
1192
1193 pConfig->SapHw_mode= eSAP_DOT11_MODE_11b;
1194
1195 pIe = wlan_hdd_cfg80211_get_ie_ptr(&pMgmt_frame->u.beacon.variable[0],
1196 pBeacon->head_len, WLAN_EID_SUPP_RATES);
1197 if (pIe != NULL)
1198 {
1199 pIe += 1;
1200 wlan_hdd_check_11gmode(pIe, &require_ht, &checkRatesfor11g,
1201 &pConfig->SapHw_mode);
1202 }
1203
1204 pIe = wlan_hdd_cfg80211_get_ie_ptr(pBeacon->tail, pBeacon->tail_len,
1205 WLAN_EID_EXT_SUPP_RATES);
1206 if (pIe != NULL)
1207 {
1208
1209 pIe += 1;
1210 wlan_hdd_check_11gmode(pIe, &require_ht, &checkRatesfor11g,
1211 &pConfig->SapHw_mode);
1212 }
1213
1214 if( pConfig->channel > 14 )
1215 {
1216 pConfig->SapHw_mode= eSAP_DOT11_MODE_11a;
1217 }
1218
1219 pIe = wlan_hdd_cfg80211_get_ie_ptr(pBeacon->tail, pBeacon->tail_len,
1220 WLAN_EID_HT_CAPABILITY);
1221
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301222 if(pIe)
Jeff Johnson295189b2012-06-20 16:38:30 -07001223 {
1224 pConfig->SapHw_mode= eSAP_DOT11_MODE_11n;
1225 if(require_ht)
1226 pConfig->SapHw_mode= eSAP_DOT11_MODE_11n_ONLY;
1227 }
1228}
1229
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301230static int wlan_hdd_add_ie(hdd_adapter_t* pHostapdAdapter, v_U8_t *genie,
1231 v_U8_t *total_ielen, v_U8_t *oui, v_U8_t oui_size)
1232{
1233 v_U8_t ielen = 0;
1234 v_U8_t *pIe = NULL;
1235 beacon_data_t *pBeacon = pHostapdAdapter->sessionCtx.ap.beacon;
1236
1237 pIe = wlan_hdd_get_vendor_oui_ie_ptr(oui, oui_size,
1238 pBeacon->tail, pBeacon->tail_len);
1239
1240 if (pIe)
1241 {
1242 ielen = pIe[1] + 2;
1243 if ((*total_ielen + ielen) <= MAX_GENIE_LEN)
1244 {
1245 vos_mem_copy(&genie[*total_ielen], pIe, ielen);
1246 }
1247 else
1248 {
1249 hddLog( VOS_TRACE_LEVEL_ERROR, "**Ie Length is too big***");
1250 return -EINVAL;
1251 }
1252 *total_ielen += ielen;
1253 }
1254 return 0;
1255}
1256
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001257#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07001258static int wlan_hdd_cfg80211_update_apies(hdd_adapter_t* pHostapdAdapter,
1259 struct beacon_parameters *params)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001260#else
1261static int wlan_hdd_cfg80211_update_apies(hdd_adapter_t* pHostapdAdapter,
1262 struct cfg80211_beacon_data *params)
1263#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07001264{
1265 v_U8_t *genie;
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301266 v_U8_t total_ielen = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07001267 v_U8_t addIE[1] = {0};
Jeff Johnsone7245742012-09-05 17:12:55 -07001268 int ret = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07001269
1270 genie = vos_mem_malloc(MAX_GENIE_LEN);
1271
1272 if(genie == NULL) {
1273
1274 return -ENOMEM;
1275 }
1276
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301277 if (0 != wlan_hdd_add_ie(pHostapdAdapter, genie,
1278 &total_ielen, WPS_OUI_TYPE, WPS_OUI_TYPE_SIZE))
Jeff Johnson295189b2012-06-20 16:38:30 -07001279 {
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301280 ret = -EINVAL;
1281 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001282 }
1283
1284#ifdef WLAN_FEATURE_WFD
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301285 if (0 != wlan_hdd_add_ie(pHostapdAdapter, genie,
1286 &total_ielen, WFD_OUI_TYPE, WFD_OUI_TYPE_SIZE))
1287 {
1288 ret = -EINVAL;
1289 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001290 }
1291#endif
1292
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301293 if (0 != wlan_hdd_add_ie(pHostapdAdapter, genie,
1294 &total_ielen, P2P_OUI_TYPE, P2P_OUI_TYPE_SIZE))
Jeff Johnson295189b2012-06-20 16:38:30 -07001295 {
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301296 ret = -EINVAL;
1297 goto done;
1298 }
1299
1300 if (WLAN_HDD_SOFTAP == pHostapdAdapter->device_mode)
1301 {
1302 if (0 != wlan_hdd_add_ie(pHostapdAdapter, genie,
1303 &total_ielen, SS_OUI_TYPE, SS_OUI_TYPE_SIZE))
Jeff Johnson295189b2012-06-20 16:38:30 -07001304 {
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301305 ret = -EINVAL;
1306 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001307 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001308 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001309
1310 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1311 WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA, genie, total_ielen, NULL,
1312 eANI_BOOLEAN_FALSE)==eHAL_STATUS_FAILURE)
1313 {
1314 hddLog(LOGE,
1315 "Could not pass on WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001316 ret = -EINVAL;
1317 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001318 }
1319
1320 if (ccmCfgSetInt((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1321 WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG, 1,NULL,
1322 test_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags) ?
1323 eANI_BOOLEAN_TRUE : eANI_BOOLEAN_FALSE)
1324 ==eHAL_STATUS_FAILURE)
1325 {
1326 hddLog(LOGE,
1327 "Could not pass on WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001328 ret = -EINVAL;
1329 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001330 }
1331
1332 // Added for ProResp IE
1333 if ( (params->proberesp_ies != NULL) && (params->proberesp_ies_len != 0) )
1334 {
1335 u16 rem_probe_resp_ie_len = params->proberesp_ies_len;
1336 u8 probe_rsp_ie_len[3] = {0};
1337 u8 counter = 0;
1338 /* Check Probe Resp Length if it is greater then 255 then Store
1339 Probe Resp IEs into WNI_CFG_PROBE_RSP_ADDNIE_DATA1 &
1340 WNI_CFG_PROBE_RSP_ADDNIE_DATA2 CFG Variable As We are not able
1341 Store More then 255 bytes into One Variable.
1342 */
1343 while ((rem_probe_resp_ie_len > 0) && (counter < 3))
1344 {
1345 if (rem_probe_resp_ie_len > MAX_CFG_STRING_LEN)
1346 {
1347 probe_rsp_ie_len[counter++] = MAX_CFG_STRING_LEN;
1348 rem_probe_resp_ie_len -= MAX_CFG_STRING_LEN;
1349 }
1350 else
1351 {
1352 probe_rsp_ie_len[counter++] = rem_probe_resp_ie_len;
1353 rem_probe_resp_ie_len = 0;
1354 }
1355 }
1356
1357 rem_probe_resp_ie_len = 0;
1358
1359 if (probe_rsp_ie_len[0] > 0)
1360 {
1361 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1362 WNI_CFG_PROBE_RSP_ADDNIE_DATA1,
1363 (tANI_U8*)&params->proberesp_ies[rem_probe_resp_ie_len],
1364 probe_rsp_ie_len[0], NULL,
1365 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
1366 {
1367 hddLog(LOGE,
1368 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA1 to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001369 ret = -EINVAL;
1370 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001371 }
1372 rem_probe_resp_ie_len += probe_rsp_ie_len[0];
1373 }
1374
1375 if (probe_rsp_ie_len[1] > 0)
1376 {
1377 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1378 WNI_CFG_PROBE_RSP_ADDNIE_DATA2,
1379 (tANI_U8*)&params->proberesp_ies[rem_probe_resp_ie_len],
1380 probe_rsp_ie_len[1], NULL,
1381 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
1382 {
1383 hddLog(LOGE,
1384 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA2 to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001385 ret = -EINVAL;
1386 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001387 }
1388 rem_probe_resp_ie_len += probe_rsp_ie_len[1];
1389 }
1390
1391 if (probe_rsp_ie_len[2] > 0)
1392 {
1393 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1394 WNI_CFG_PROBE_RSP_ADDNIE_DATA3,
1395 (tANI_U8*)&params->proberesp_ies[rem_probe_resp_ie_len],
1396 probe_rsp_ie_len[2], NULL,
1397 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
1398 {
1399 hddLog(LOGE,
1400 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA3 to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001401 ret = -EINVAL;
1402 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001403 }
1404 rem_probe_resp_ie_len += probe_rsp_ie_len[2];
1405 }
1406
1407 if (probe_rsp_ie_len[1] == 0 )
1408 {
1409 if ( eHAL_STATUS_FAILURE == ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1410 WNI_CFG_PROBE_RSP_ADDNIE_DATA2, (tANI_U8*)addIE, 0, NULL,
1411 eANI_BOOLEAN_FALSE) )
1412 {
1413 hddLog(LOGE,
1414 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA2 to CCM\n");
1415 }
1416 }
1417
1418 if (probe_rsp_ie_len[2] == 0 )
1419 {
1420 if ( eHAL_STATUS_FAILURE == ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1421 WNI_CFG_PROBE_RSP_ADDNIE_DATA3, (tANI_U8*)addIE, 0, NULL,
1422 eANI_BOOLEAN_FALSE) )
1423 {
1424 hddLog(LOGE,
1425 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA3 to CCM\n");
1426 }
1427 }
1428
1429 if (ccmCfgSetInt((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1430 WNI_CFG_PROBE_RSP_ADDNIE_FLAG, 1,NULL,
1431 test_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags) ?
1432 eANI_BOOLEAN_TRUE : eANI_BOOLEAN_FALSE)
1433 == eHAL_STATUS_FAILURE)
1434 {
1435 hddLog(LOGE,
1436 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_FLAG to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001437 ret = -EINVAL;
1438 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001439 }
1440 }
1441 else
1442 {
1443 // Reset WNI_CFG_PROBE_RSP Flags
1444 wlan_hdd_reset_prob_rspies(pHostapdAdapter);
1445
1446 hddLog(VOS_TRACE_LEVEL_INFO,
1447 "%s: No Probe Response IE received in set beacon",
1448 __func__);
1449 }
1450
1451 // Added for AssocResp IE
1452 if ( (params->assocresp_ies != NULL) && (params->assocresp_ies_len != 0) )
1453 {
1454 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1455 WNI_CFG_ASSOC_RSP_ADDNIE_DATA, (tANI_U8*)params->assocresp_ies,
1456 params->assocresp_ies_len, NULL,
1457 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
1458 {
1459 hddLog(LOGE,
1460 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_DATA to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001461 ret = -EINVAL;
1462 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001463 }
1464
1465 if (ccmCfgSetInt((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1466 WNI_CFG_ASSOC_RSP_ADDNIE_FLAG, 1, NULL,
1467 test_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags) ?
1468 eANI_BOOLEAN_TRUE : eANI_BOOLEAN_FALSE)
1469 == eHAL_STATUS_FAILURE)
1470 {
1471 hddLog(LOGE,
1472 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_FLAG to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001473 ret = -EINVAL;
1474 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001475 }
1476 }
1477 else
1478 {
1479 hddLog(VOS_TRACE_LEVEL_INFO,
1480 "%s: No Assoc Response IE received in set beacon",
1481 __func__);
1482
1483 if ( eHAL_STATUS_FAILURE == ccmCfgSetInt((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1484 WNI_CFG_ASSOC_RSP_ADDNIE_FLAG, 0, NULL,
1485 eANI_BOOLEAN_FALSE) )
1486 {
1487 hddLog(LOGE,
1488 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_FLAG to CCM\n");
1489 }
1490 }
1491
Jeff Johnsone7245742012-09-05 17:12:55 -07001492done:
Jeff Johnson295189b2012-06-20 16:38:30 -07001493 vos_mem_free(genie);
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301494 return ret;
Jeff Johnson295189b2012-06-20 16:38:30 -07001495}
Jeff Johnson295189b2012-06-20 16:38:30 -07001496
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301497/*
Jeff Johnson295189b2012-06-20 16:38:30 -07001498 * FUNCTION: wlan_hdd_validate_operation_channel
1499 * called by wlan_hdd_cfg80211_start_bss() and
1500 * wlan_hdd_cfg80211_set_channel()
1501 * This function validates whether given channel is part of valid
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301502 * channel list.
1503 */
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07001504VOS_STATUS wlan_hdd_validate_operation_channel(hdd_adapter_t *pAdapter,int channel)
Jeff Johnson295189b2012-06-20 16:38:30 -07001505{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301506
Jeff Johnson295189b2012-06-20 16:38:30 -07001507 v_U32_t num_ch = 0;
1508 u8 valid_ch[WNI_CFG_VALID_CHANNEL_LIST_LEN];
1509 u32 indx = 0;
1510 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301511 v_U8_t fValidChannel = FALSE, count = 0;
1512 hdd_config_t *hdd_pConfig_ini= (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301513
Jeff Johnson295189b2012-06-20 16:38:30 -07001514 num_ch = WNI_CFG_VALID_CHANNEL_LIST_LEN;
1515
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301516 if ( hdd_pConfig_ini->sapAllowAllChannel)
Jeff Johnson295189b2012-06-20 16:38:30 -07001517 {
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301518 /* Validate the channel */
1519 for (count = RF_CHAN_1 ; count <= RF_CHAN_165 ; count++)
Jeff Johnson295189b2012-06-20 16:38:30 -07001520 {
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301521 if ( channel == rfChannels[count].channelNum )
1522 {
1523 fValidChannel = TRUE;
1524 break;
1525 }
1526 }
1527 if (fValidChannel != TRUE)
1528 {
1529 hddLog(VOS_TRACE_LEVEL_ERROR,
1530 "%s: Invalid Channel [%d]", __func__, channel);
1531 return VOS_STATUS_E_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07001532 }
1533 }
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301534 else
Jeff Johnson295189b2012-06-20 16:38:30 -07001535 {
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301536 if (0 != ccmCfgGetStr(hHal, WNI_CFG_VALID_CHANNEL_LIST,
1537 valid_ch, &num_ch))
1538 {
1539 hddLog(VOS_TRACE_LEVEL_ERROR,
1540 "%s: failed to get valid channel list", __func__);
1541 return VOS_STATUS_E_FAILURE;
1542 }
1543 for (indx = 0; indx < num_ch; indx++)
1544 {
1545 if (channel == valid_ch[indx])
1546 {
1547 break;
1548 }
1549 }
1550
1551 if (indx >= num_ch)
1552 {
1553 hddLog(VOS_TRACE_LEVEL_ERROR,
1554 "%s: Invalid Channel [%d]", __func__, channel);
1555 return VOS_STATUS_E_FAILURE;
1556 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001557 }
1558 return VOS_STATUS_SUCCESS;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301559
Jeff Johnson295189b2012-06-20 16:38:30 -07001560}
1561
Viral Modi3a32cc52013-02-08 11:14:52 -08001562/**
1563 * FUNCTION: wlan_hdd_cfg80211_set_channel
1564 * This function is used to set the channel number
1565 */
1566static int wlan_hdd_cfg80211_set_channel( struct wiphy *wiphy, struct net_device *dev,
1567 struct ieee80211_channel *chan,
1568 enum nl80211_channel_type channel_type
1569 )
1570{
1571 v_U32_t num_ch = 0;
Jeff Johnson4416a782013-03-25 14:17:50 -07001572 int channel = 0;
Viral Modi3a32cc52013-02-08 11:14:52 -08001573 hdd_adapter_t *pAdapter = NULL;
1574 int freq = chan->center_freq; /* freq is in MHZ */
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05301575 hdd_context_t *pHddCtx;
1576 int status;
Viral Modi3a32cc52013-02-08 11:14:52 -08001577
1578 ENTER();
1579
1580 if( NULL == dev )
1581 {
1582 hddLog(VOS_TRACE_LEVEL_ERROR,
1583 "%s: Called with dev = NULL.\n", __func__);
1584 return -ENODEV;
1585 }
1586 pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
1587
1588 hddLog(VOS_TRACE_LEVEL_INFO,
1589 "%s: device_mode = %d freq = %d \n",__func__,
1590 pAdapter->device_mode, chan->center_freq);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05301591
1592 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
1593 status = wlan_hdd_validate_context(pHddCtx);
1594
1595 if (0 != status)
Viral Modi3a32cc52013-02-08 11:14:52 -08001596 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05301597 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1598 "%s: HDD context is not valid", __func__);
1599 return status;
Viral Modi3a32cc52013-02-08 11:14:52 -08001600 }
1601
1602 /*
1603 * Do freq to chan conversion
1604 * TODO: for 11a
1605 */
1606
1607 channel = ieee80211_frequency_to_channel(freq);
1608
1609 /* Check freq range */
1610 if ((WNI_CFG_CURRENT_CHANNEL_STAMIN > channel) ||
1611 (WNI_CFG_CURRENT_CHANNEL_STAMAX < channel))
1612 {
1613 hddLog(VOS_TRACE_LEVEL_ERROR,
1614 "%s: Channel [%d] is outside valid range from %d to %d\n",
1615 __func__, channel, WNI_CFG_CURRENT_CHANNEL_STAMIN,
1616 WNI_CFG_CURRENT_CHANNEL_STAMAX);
1617 return -EINVAL;
1618 }
1619
1620 num_ch = WNI_CFG_VALID_CHANNEL_LIST_LEN;
1621
Gopichand Nakkala6ab19562013-03-07 13:59:42 +05301622 if ((WLAN_HDD_SOFTAP != pAdapter->device_mode) &&
1623 (WLAN_HDD_P2P_GO != pAdapter->device_mode))
Viral Modi3a32cc52013-02-08 11:14:52 -08001624 {
1625 if(VOS_STATUS_SUCCESS != wlan_hdd_validate_operation_channel(pAdapter,channel))
1626 {
1627 hddLog(VOS_TRACE_LEVEL_ERROR,
1628 "%s: Invalid Channel [%d] \n", __func__, channel);
1629 return -EINVAL;
1630 }
1631 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
1632 "%s: set channel to [%d] for device mode =%d",
1633 __func__, channel,pAdapter->device_mode);
1634 }
1635 if( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Viral Modi3a32cc52013-02-08 11:14:52 -08001636 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Viral Modi3a32cc52013-02-08 11:14:52 -08001637 )
1638 {
1639 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
1640 tCsrRoamProfile * pRoamProfile = &pWextState->roamProfile;
1641 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
1642
1643 if (eConnectionState_IbssConnected == pHddStaCtx->conn_info.connState)
1644 {
1645 /* Link is up then return cant set channel*/
1646 hddLog( VOS_TRACE_LEVEL_ERROR,
1647 "%s: IBSS Associated, can't set the channel\n", __func__);
1648 return -EINVAL;
1649 }
1650
1651 num_ch = pRoamProfile->ChannelInfo.numOfChannels = 1;
1652 pHddStaCtx->conn_info.operationChannel = channel;
1653 pRoamProfile->ChannelInfo.ChannelList =
1654 &pHddStaCtx->conn_info.operationChannel;
1655 }
1656 else if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Viral Modi3a32cc52013-02-08 11:14:52 -08001657 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Viral Modi3a32cc52013-02-08 11:14:52 -08001658 )
1659 {
Gopichand Nakkalac8fa7b62013-03-11 13:56:41 +05301660 if (WLAN_HDD_P2P_GO == pAdapter->device_mode)
1661 {
1662 if(VOS_STATUS_SUCCESS !=
1663 wlan_hdd_validate_operation_channel(pAdapter,channel))
1664 {
1665 hddLog(VOS_TRACE_LEVEL_ERROR,
1666 "%s: Invalid Channel [%d] \n", __func__, channel);
1667 return -EINVAL;
1668 }
1669 (WLAN_HDD_GET_AP_CTX_PTR(pAdapter))->sapConfig.channel = channel;
1670 }
1671 else if ( WLAN_HDD_SOFTAP == pAdapter->device_mode )
Viral Modi3a32cc52013-02-08 11:14:52 -08001672 {
1673 hdd_config_t *cfg_param = (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini;
1674
1675 /* If auto channel selection is configured as enable/ 1 then ignore
1676 channel set by supplicant
1677 */
1678 if ( cfg_param->apAutoChannelSelection )
1679 {
Gopichand Nakkalac8fa7b62013-03-11 13:56:41 +05301680 (WLAN_HDD_GET_AP_CTX_PTR(pAdapter))->sapConfig.channel =
1681 AUTO_CHANNEL_SELECT;
Viral Modi3a32cc52013-02-08 11:14:52 -08001682 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
1683 "%s: set channel to auto channel (0) for device mode =%d",
1684 __func__, pAdapter->device_mode);
1685 }
Gopichand Nakkalac8fa7b62013-03-11 13:56:41 +05301686 else
1687 {
1688 if(VOS_STATUS_SUCCESS !=
1689 wlan_hdd_validate_operation_channel(pAdapter,channel))
1690 {
1691 hddLog(VOS_TRACE_LEVEL_ERROR,
1692 "%s: Invalid Channel [%d] \n", __func__, channel);
1693 return -EINVAL;
1694 }
1695 (WLAN_HDD_GET_AP_CTX_PTR(pAdapter))->sapConfig.channel = channel;
1696 }
Viral Modi3a32cc52013-02-08 11:14:52 -08001697 }
1698 }
1699 else
1700 {
1701 hddLog(VOS_TRACE_LEVEL_FATAL,
1702 "%s: Invalid device mode failed to set valid channel", __func__);
1703 return -EINVAL;
1704 }
1705 EXIT();
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05301706 return status;
Viral Modi3a32cc52013-02-08 11:14:52 -08001707}
1708
Jeff Johnson295189b2012-06-20 16:38:30 -07001709#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
1710static int wlan_hdd_cfg80211_start_bss(hdd_adapter_t *pHostapdAdapter,
1711 struct beacon_parameters *params)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001712#else
1713static int wlan_hdd_cfg80211_start_bss(hdd_adapter_t *pHostapdAdapter,
1714 struct cfg80211_beacon_data *params,
1715 const u8 *ssid, size_t ssid_len,
1716 enum nl80211_hidden_ssid hidden_ssid)
1717#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07001718{
1719 tsap_Config_t *pConfig;
1720 beacon_data_t *pBeacon = NULL;
1721 struct ieee80211_mgmt *pMgmt_frame;
1722 v_U8_t *pIe=NULL;
1723 v_U16_t capab_info;
1724 eCsrAuthType RSNAuthType;
1725 eCsrEncryptionType RSNEncryptType;
1726 eCsrEncryptionType mcRSNEncryptType;
1727 int status = VOS_STATUS_SUCCESS;
1728 tpWLAN_SAPEventCB pSapEventCallback;
1729 hdd_hostapd_state_t *pHostapdState;
1730 v_U8_t wpaRsnIEdata[(SIR_MAC_MAX_IE_LENGTH * 2)+4]; //Max ie length 255 * 2(WPA+RSN) + 2 bytes (vendor specific ID) * 2
1731 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pHostapdAdapter))->pvosContext;
Madan Mohan Koyylamudia16d0202013-02-01 11:05:57 +05301732 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pHostapdAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001733 struct qc_mac_acl_entry *acl_entry = NULL;
1734 v_SINT_t i;
Madan Mohan Koyyalamudi543172b2012-12-05 16:40:18 -08001735 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pHostapdAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001736
1737 ENTER();
1738
1739 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pHostapdAdapter);
1740
1741 pConfig = &pHostapdAdapter->sessionCtx.ap.sapConfig;
1742
1743 pBeacon = pHostapdAdapter->sessionCtx.ap.beacon;
1744
1745 pMgmt_frame = (struct ieee80211_mgmt*)pBeacon->head;
1746
1747 pConfig->beacon_int = pMgmt_frame->u.beacon.beacon_int;
1748
1749 //channel is already set in the set_channel Call back
1750 //pConfig->channel = pCommitConfig->channel;
1751
1752 /*Protection parameter to enable or disable*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301753 pConfig->protEnabled =
Jeff Johnson295189b2012-06-20 16:38:30 -07001754 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apProtEnabled;
1755
1756 pConfig->dtim_period = pBeacon->dtim_period;
1757
1758 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,"****pConfig->dtim_period=%d***\n",
1759 pConfig->dtim_period);
1760
1761
Madan Mohan Koyyalamudie0ca11f2012-11-27 15:57:52 -08001762 if (pHostapdAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson32d95a32012-09-10 13:15:23 -07001763 {
1764 pIe = wlan_hdd_cfg80211_get_ie_ptr(pBeacon->tail, pBeacon->tail_len,
Jeff Johnson295189b2012-06-20 16:38:30 -07001765 WLAN_EID_COUNTRY);
Jeff Johnson32d95a32012-09-10 13:15:23 -07001766 if(pIe)
Jeff Johnson295189b2012-06-20 16:38:30 -07001767 {
Jeff Johnson32d95a32012-09-10 13:15:23 -07001768 tANI_BOOLEAN restartNeeded;
Jeff Johnson32d95a32012-09-10 13:15:23 -07001769 pConfig->ieee80211d = 1;
1770 vos_mem_copy(pConfig->countryCode, &pIe[2], 3);
1771 sme_setRegInfo(hHal, pConfig->countryCode);
1772 sme_ResetCountryCodeInformation(hHal, &restartNeeded);
Jeff Johnson295189b2012-06-20 16:38:30 -07001773 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07001774 else
1775 {
1776 pConfig->ieee80211d = 0;
1777 }
Madan Mohan Koyylamudia16d0202013-02-01 11:05:57 +05301778 /*
1779 * If auto channel is configured i.e. channel is 0,
1780 * so skip channel validation.
1781 */
1782 if( AUTO_CHANNEL_SELECT != pConfig->channel )
1783 {
1784 if(VOS_STATUS_SUCCESS != wlan_hdd_validate_operation_channel(pHostapdAdapter,pConfig->channel))
1785 {
1786 hddLog(VOS_TRACE_LEVEL_ERROR,
1787 "%s: Invalid Channel [%d] \n", __func__, pConfig->channel);
1788 return -EINVAL;
1789 }
1790 }
1791 else
1792 {
1793 if(1 != pHddCtx->is_dynamic_channel_range_set)
1794 {
1795 hdd_config_t *hdd_pConfig= (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini;
1796 WLANSAP_SetChannelRange(hHal, hdd_pConfig->apStartChannelNum,
1797 hdd_pConfig->apEndChannelNum,hdd_pConfig->apOperatingBand);
1798 }
1799 pHddCtx->is_dynamic_channel_range_set = 0;
1800 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001801 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07001802 else
Jeff Johnson295189b2012-06-20 16:38:30 -07001803 {
1804 pConfig->ieee80211d = 0;
1805 }
1806 pConfig->authType = eSAP_AUTO_SWITCH;
1807
1808 capab_info = pMgmt_frame->u.beacon.capab_info;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301809
1810 pConfig->privacy = (pMgmt_frame->u.beacon.capab_info &
Jeff Johnson295189b2012-06-20 16:38:30 -07001811 WLAN_CAPABILITY_PRIVACY) ? VOS_TRUE : VOS_FALSE;
1812
1813 (WLAN_HDD_GET_AP_CTX_PTR(pHostapdAdapter))->uPrivacy = pConfig->privacy;
1814
1815 /*Set wps station to configured*/
1816 pIe = wlan_hdd_get_wps_ie_ptr(pBeacon->tail, pBeacon->tail_len);
1817
1818 if(pIe)
1819 {
1820 if(pIe[1] < (2 + WPS_OUI_TYPE_SIZE))
1821 {
1822 hddLog( VOS_TRACE_LEVEL_ERROR, "**Wps Ie Length is too small***\n");
1823 return -EINVAL;
1824 }
1825 else if(memcmp(&pIe[2], WPS_OUI_TYPE, WPS_OUI_TYPE_SIZE) == 0)
1826 {
Madan Mohan Koyyalamudi8bdd3112012-09-24 13:55:14 -07001827 hddLog( VOS_TRACE_LEVEL_INFO, "** WPS IE(len %d) ***", (pIe[1]+2));
Jeff Johnson295189b2012-06-20 16:38:30 -07001828 /* Check 15 bit of WPS IE as it contain information for wps state
1829 * WPS state
1830 */
1831 if(SAP_WPS_ENABLED_UNCONFIGURED == pIe[15])
1832 {
1833 pConfig->wps_state = SAP_WPS_ENABLED_UNCONFIGURED;
1834 } else if(SAP_WPS_ENABLED_CONFIGURED == pIe[15])
1835 {
1836 pConfig->wps_state = SAP_WPS_ENABLED_CONFIGURED;
1837 }
1838 }
1839 }
1840 else
1841 {
1842 pConfig->wps_state = SAP_WPS_DISABLED;
1843 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301844 pConfig->fwdWPSPBCProbeReq = 1; // Forward WPS PBC probe request frame up
Jeff Johnson295189b2012-06-20 16:38:30 -07001845
1846 pConfig->RSNWPAReqIELength = 0;
1847 pConfig->pRSNWPAReqIE = NULL;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301848 pIe = wlan_hdd_cfg80211_get_ie_ptr(pBeacon->tail, pBeacon->tail_len,
Jeff Johnson295189b2012-06-20 16:38:30 -07001849 WLAN_EID_RSN);
1850 if(pIe && pIe[1])
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301851 {
Jeff Johnson295189b2012-06-20 16:38:30 -07001852 pConfig->RSNWPAReqIELength = pIe[1] + 2;
1853 memcpy(&wpaRsnIEdata[0], pIe, pConfig->RSNWPAReqIELength);
1854 pConfig->pRSNWPAReqIE = &wpaRsnIEdata[0];
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301855 /* The actual processing may eventually be more extensive than
1856 * this. Right now, just consume any PMKIDs that are sent in
Jeff Johnson295189b2012-06-20 16:38:30 -07001857 * by the app.
1858 * */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301859 status = hdd_softap_unpackIE(
Jeff Johnson295189b2012-06-20 16:38:30 -07001860 vos_get_context( VOS_MODULE_ID_SME, pVosContext),
1861 &RSNEncryptType,
1862 &mcRSNEncryptType,
1863 &RSNAuthType,
1864 pConfig->pRSNWPAReqIE[1]+2,
1865 pConfig->pRSNWPAReqIE );
1866
1867 if( VOS_STATUS_SUCCESS == status )
1868 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301869 /* Now copy over all the security attributes you have
1870 * parsed out
Jeff Johnson295189b2012-06-20 16:38:30 -07001871 * */
1872 pConfig->RSNEncryptType = RSNEncryptType; // Use the cipher type in the RSN IE
1873 pConfig->mcRSNEncryptType = mcRSNEncryptType;
1874 (WLAN_HDD_GET_AP_CTX_PTR(pHostapdAdapter))->ucEncryptType
1875 = RSNEncryptType;
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +05301876 hddLog( LOG1, FL("CSR AuthType = %d, "
Jeff Johnson295189b2012-06-20 16:38:30 -07001877 "EncryptionType = %d mcEncryptionType = %d\n"),
1878 RSNAuthType, RSNEncryptType, mcRSNEncryptType);
1879 }
1880 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301881
Jeff Johnson295189b2012-06-20 16:38:30 -07001882 pIe = wlan_hdd_get_vendor_oui_ie_ptr(WPA_OUI_TYPE, WPA_OUI_TYPE_SIZE,
1883 pBeacon->tail, pBeacon->tail_len);
1884
1885 if(pIe && pIe[1] && (pIe[0] == DOT11F_EID_WPA))
1886 {
1887 if (pConfig->pRSNWPAReqIE)
1888 {
1889 /*Mixed mode WPA/WPA2*/
1890 memcpy((&wpaRsnIEdata[0] + pConfig->RSNWPAReqIELength), pIe, pIe[1] + 2);
1891 pConfig->RSNWPAReqIELength += pIe[1] + 2;
1892 }
1893 else
1894 {
1895 pConfig->RSNWPAReqIELength = pIe[1] + 2;
1896 memcpy(&wpaRsnIEdata[0], pIe, pConfig->RSNWPAReqIELength);
1897 pConfig->pRSNWPAReqIE = &wpaRsnIEdata[0];
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301898 status = hdd_softap_unpackIE(
Jeff Johnson295189b2012-06-20 16:38:30 -07001899 vos_get_context( VOS_MODULE_ID_SME, pVosContext),
1900 &RSNEncryptType,
1901 &mcRSNEncryptType,
1902 &RSNAuthType,
1903 pConfig->pRSNWPAReqIE[1]+2,
1904 pConfig->pRSNWPAReqIE );
1905
1906 if( VOS_STATUS_SUCCESS == status )
1907 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301908 /* Now copy over all the security attributes you have
1909 * parsed out
Jeff Johnson295189b2012-06-20 16:38:30 -07001910 * */
1911 pConfig->RSNEncryptType = RSNEncryptType; // Use the cipher type in the RSN IE
1912 pConfig->mcRSNEncryptType = mcRSNEncryptType;
1913 (WLAN_HDD_GET_AP_CTX_PTR(pHostapdAdapter))->ucEncryptType
1914 = RSNEncryptType;
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +05301915 hddLog( LOG1, FL("CSR AuthType = %d, "
Jeff Johnson295189b2012-06-20 16:38:30 -07001916 "EncryptionType = %d mcEncryptionType = %d\n"),
1917 RSNAuthType, RSNEncryptType, mcRSNEncryptType);
1918 }
1919 }
1920 }
1921
Jeff Johnson4416a782013-03-25 14:17:50 -07001922 if (pConfig->RSNWPAReqIELength > sizeof wpaRsnIEdata) {
1923 hddLog( VOS_TRACE_LEVEL_ERROR, "**RSNWPAReqIELength is too large***");
1924 return -EINVAL;
1925 }
1926
Jeff Johnson295189b2012-06-20 16:38:30 -07001927 pConfig->SSIDinfo.ssidHidden = VOS_FALSE;
1928
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001929#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07001930 if (params->ssid != NULL)
1931 {
1932 memcpy(pConfig->SSIDinfo.ssid.ssId, params->ssid, params->ssid_len);
1933 pConfig->SSIDinfo.ssid.length = params->ssid_len;
1934 if (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE)
1935 pConfig->SSIDinfo.ssidHidden = VOS_TRUE;
1936 }
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001937#else
1938 if (ssid != NULL)
1939 {
1940 memcpy(pConfig->SSIDinfo.ssid.ssId, ssid, ssid_len);
1941 pConfig->SSIDinfo.ssid.length = ssid_len;
1942 if (hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE)
1943 pConfig->SSIDinfo.ssidHidden = VOS_TRUE;
1944 }
1945#endif
1946
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301947 vos_mem_copy(pConfig->self_macaddr.bytes,
Jeff Johnson295189b2012-06-20 16:38:30 -07001948 pHostapdAdapter->macAddressCurrent.bytes, sizeof(v_MACADDR_t));
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301949
Jeff Johnson295189b2012-06-20 16:38:30 -07001950 /* default value */
1951 pConfig->SapMacaddr_acl = eSAP_ACCEPT_UNLESS_DENIED;
1952 pConfig->num_accept_mac = 0;
1953 pConfig->num_deny_mac = 0;
1954
1955 pIe = wlan_hdd_get_vendor_oui_ie_ptr(BLACKLIST_OUI_TYPE, WPA_OUI_TYPE_SIZE,
1956 pBeacon->tail, pBeacon->tail_len);
1957
1958 /* pIe for black list is following form:
1959 type : 1 byte
1960 length : 1 byte
1961 OUI : 4 bytes
1962 acl type : 1 byte
1963 no of mac addr in black list: 1 byte
1964 list of mac_acl_entries: variable, 6 bytes per mac address + sizeof(int) for vlan id
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301965 */
1966 if ((pIe != NULL) && (pIe[1] != 0))
Jeff Johnson295189b2012-06-20 16:38:30 -07001967 {
1968 pConfig->SapMacaddr_acl = pIe[6];
1969 pConfig->num_deny_mac = pIe[7];
1970 hddLog(VOS_TRACE_LEVEL_INFO,"acl type = %d no deny mac = %d\n",
1971 pIe[6], pIe[7]);
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05301972 if (pConfig->num_deny_mac > MAX_ACL_MAC_ADDRESS)
1973 pConfig->num_deny_mac = MAX_ACL_MAC_ADDRESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001974 acl_entry = (struct qc_mac_acl_entry *)(pIe + 8);
1975 for (i = 0; i < pConfig->num_deny_mac; i++)
1976 {
1977 vos_mem_copy(&pConfig->deny_mac[i], acl_entry->addr, sizeof(qcmacaddr));
1978 acl_entry++;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301979 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001980 }
1981 pIe = wlan_hdd_get_vendor_oui_ie_ptr(WHITELIST_OUI_TYPE, WPA_OUI_TYPE_SIZE,
1982 pBeacon->tail, pBeacon->tail_len);
1983
1984 /* pIe for white list is following form:
1985 type : 1 byte
1986 length : 1 byte
1987 OUI : 4 bytes
1988 acl type : 1 byte
1989 no of mac addr in white list: 1 byte
1990 list of mac_acl_entries: variable, 6 bytes per mac address + sizeof(int) for vlan id
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301991 */
1992 if ((pIe != NULL) && (pIe[1] != 0))
Jeff Johnson295189b2012-06-20 16:38:30 -07001993 {
1994 pConfig->SapMacaddr_acl = pIe[6];
1995 pConfig->num_accept_mac = pIe[7];
1996 hddLog(VOS_TRACE_LEVEL_INFO,"acl type = %d no accept mac = %d\n",
1997 pIe[6], pIe[7]);
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05301998 if (pConfig->num_accept_mac > MAX_ACL_MAC_ADDRESS)
1999 pConfig->num_accept_mac = MAX_ACL_MAC_ADDRESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07002000 acl_entry = (struct qc_mac_acl_entry *)(pIe + 8);
2001 for (i = 0; i < pConfig->num_accept_mac; i++)
2002 {
2003 vos_mem_copy(&pConfig->accept_mac[i], acl_entry->addr, sizeof(qcmacaddr));
2004 acl_entry++;
2005 }
2006 }
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05302007
Jeff Johnson295189b2012-06-20 16:38:30 -07002008 wlan_hdd_set_sapHwmode(pHostapdAdapter);
2009
Jeff Johnsone7245742012-09-05 17:12:55 -07002010#ifdef WLAN_FEATURE_11AC
Ravi Kumar Vaishnavbbaebbe2013-01-15 17:09:48 -08002011 /* Overwrite the hostapd setting for HW mode only for 11ac.
2012 * This is valid only if mode is set to 11n in hostapd and either AUTO or 11ac in .ini .
2013 * Otherwise, leave whatever is set in hostapd (a OR b OR g OR n mode) */
2014 if( ((pConfig->SapHw_mode == eSAP_DOT11_MODE_11n) ||
2015 (pConfig->SapHw_mode == eSAP_DOT11_MODE_11n_ONLY)) &&
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302016 (((WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->dot11Mode == eHDD_DOT11_MODE_AUTO) ||
Ravi Kumar Vaishnavbbaebbe2013-01-15 17:09:48 -08002017 ((WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->dot11Mode == eHDD_DOT11_MODE_11ac) ||
2018 ((WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY)) )
Jeff Johnsone7245742012-09-05 17:12:55 -07002019 {
2020 pConfig->SapHw_mode = eSAP_DOT11_MODE_11ac;
Ravi Joshi83bfaa12013-05-28 22:12:08 -07002021
2022 /* Disable VHT support in 2.4 GHz band */
2023 if (pConfig->channel <= 14 &&
2024 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->enableVhtFor24GHzBand == FALSE)
2025 {
2026 pConfig->SapHw_mode = eSAP_DOT11_MODE_11n;
2027 }
Jeff Johnsone7245742012-09-05 17:12:55 -07002028 }
2029#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302030
Ravi Joshiaeb7d9e2013-05-02 12:28:14 -07002031 if ( AUTO_CHANNEL_SELECT != pConfig->channel )
2032 {
2033 sme_SelectCBMode(hHal,
2034 sapConvertSapPhyModeToCsrPhyMode(pConfig->SapHw_mode),
2035 pConfig->channel);
2036 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002037 // ht_capab is not what the name conveys,this is used for protection bitmap
2038 pConfig->ht_capab =
2039 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apProtection;
2040
2041 if ( 0 != wlan_hdd_cfg80211_update_apies(pHostapdAdapter, params) )
2042 {
2043 hddLog(LOGE, FL("SAP Not able to set AP IEs"));
2044 return -EINVAL;
2045 }
2046
2047 //Uapsd Enabled Bit
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302048 pConfig->UapsdEnable =
Jeff Johnson295189b2012-06-20 16:38:30 -07002049 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apUapsdEnabled;
2050 //Enable OBSS protection
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302051 pConfig->obssProtEnabled =
2052 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apOBSSProtEnabled;
Jeff Johnson295189b2012-06-20 16:38:30 -07002053
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302054 hddLog(LOGW, FL("SOftAP macaddress : "MAC_ADDRESS_STR"\n"),
Jeff Johnson295189b2012-06-20 16:38:30 -07002055 MAC_ADDR_ARRAY(pHostapdAdapter->macAddressCurrent.bytes));
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302056 hddLog(LOGW,FL("ssid =%s\n"), pConfig->SSIDinfo.ssid.ssId);
Jeff Johnson295189b2012-06-20 16:38:30 -07002057 hddLog(LOGW,FL("beaconint=%d, channel=%d\n"), (int)pConfig->beacon_int,
2058 (int)pConfig->channel);
2059 hddLog(LOGW,FL("hw_mode=%x\n"), pConfig->SapHw_mode);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302060 hddLog(LOGW,FL("privacy=%d, authType=%d\n"), pConfig->privacy,
2061 pConfig->authType);
Jeff Johnson295189b2012-06-20 16:38:30 -07002062 hddLog(LOGW,FL("RSN/WPALen=%d, \n"),(int)pConfig->RSNWPAReqIELength);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302063 hddLog(LOGW,FL("Uapsd = %d\n"),pConfig->UapsdEnable);
Jeff Johnson295189b2012-06-20 16:38:30 -07002064 hddLog(LOGW,FL("ProtEnabled = %d, OBSSProtEnabled = %d\n"),
2065 pConfig->protEnabled, pConfig->obssProtEnabled);
2066
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302067 if(test_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags))
Jeff Johnson295189b2012-06-20 16:38:30 -07002068 {
2069 //Bss already started. just return.
2070 //TODO Probably it should update some beacon params.
2071 hddLog( LOGE, "Bss Already started...Ignore the request");
2072 EXIT();
2073 return 0;
2074 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302075
Jeff Johnson295189b2012-06-20 16:38:30 -07002076 pConfig->persona = pHostapdAdapter->device_mode;
2077
2078 pSapEventCallback = hdd_hostapd_SAPEventCB;
2079 if(WLANSAP_StartBss(pVosContext, pSapEventCallback, pConfig,
2080 (v_PVOID_t)pHostapdAdapter->dev) != VOS_STATUS_SUCCESS)
2081 {
2082 hddLog(LOGE,FL("SAP Start Bss fail\n"));
2083 return -EINVAL;
2084 }
2085
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302086 hddLog(LOG1,
Jeff Johnson295189b2012-06-20 16:38:30 -07002087 FL("Waiting for Scan to complete(auto mode) and BSS to start"));
2088
2089 status = vos_wait_single_event(&pHostapdState->vosEvent, 10000);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302090
Jeff Johnson295189b2012-06-20 16:38:30 -07002091 if (!VOS_IS_STATUS_SUCCESS(status))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302092 {
2093 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07002094 ("ERROR: HDD vos wait for single_event failed!!\n"));
2095 VOS_ASSERT(0);
2096 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302097
Jeff Johnson295189b2012-06-20 16:38:30 -07002098 //Succesfully started Bss update the state bit.
2099 set_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags);
2100
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07002101#ifdef WLAN_FEATURE_P2P_DEBUG
2102 if (pHostapdAdapter->device_mode == WLAN_HDD_P2P_GO)
2103 {
2104 if(globalP2PConnectionStatus == P2P_GO_NEG_COMPLETED)
2105 {
2106 globalP2PConnectionStatus = P2P_GO_COMPLETED_STATE;
2107 hddLog(LOGE,"[P2P State] From Go nego completed to "
Jeff Johnson1250df42012-12-10 14:31:52 -08002108 "Non-autonomous Group started");
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07002109 }
2110 else if(globalP2PConnectionStatus == P2P_NOT_ACTIVE)
2111 {
2112 globalP2PConnectionStatus = P2P_GO_COMPLETED_STATE;
2113 hddLog(LOGE,"[P2P State] From Inactive to "
Jeff Johnson1250df42012-12-10 14:31:52 -08002114 "Autonomous Group started");
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07002115 }
2116 }
2117#endif
2118
Jeff Johnson295189b2012-06-20 16:38:30 -07002119 pHostapdState->bCommit = TRUE;
2120 EXIT();
2121
2122 return 0;
2123}
2124
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002125#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302126static int wlan_hdd_cfg80211_add_beacon(struct wiphy *wiphy,
2127 struct net_device *dev,
Jeff Johnson295189b2012-06-20 16:38:30 -07002128 struct beacon_parameters *params)
2129{
2130 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302131 hdd_context_t *pHddCtx;
2132 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07002133
2134 ENTER();
2135
2136 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "device mode=%d\n",pAdapter->device_mode);
2137
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302138 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2139 status = wlan_hdd_validate_context(pHddCtx);
2140
2141 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002142 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302143 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2144 "%s: HDD context is not valid", __func__);
2145 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002146 }
2147
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302148 if ( (pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002149 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -07002150 )
2151 {
2152 beacon_data_t *old,*new;
2153
2154 old = pAdapter->sessionCtx.ap.beacon;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302155
Jeff Johnson295189b2012-06-20 16:38:30 -07002156 if (old)
2157 return -EALREADY;
2158
2159 status = wlan_hdd_cfg80211_alloc_new_beacon(pAdapter,&new,params);
2160
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302161 if(status != VOS_STATUS_SUCCESS)
Jeff Johnson295189b2012-06-20 16:38:30 -07002162 {
2163 hddLog(VOS_TRACE_LEVEL_FATAL,
2164 "%s:Error!!! Allocating the new beacon\n",__func__);
2165 return -EINVAL;
2166 }
2167
2168 pAdapter->sessionCtx.ap.beacon = new;
2169
2170 status = wlan_hdd_cfg80211_start_bss(pAdapter, params);
2171 }
2172
2173 EXIT();
2174 return status;
2175}
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302176
2177static int wlan_hdd_cfg80211_set_beacon(struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07002178 struct net_device *dev,
2179 struct beacon_parameters *params)
2180{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302181 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302182 hdd_context_t *pHddCtx;
2183 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07002184
2185 ENTER();
2186
2187 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
2188 __func__,pAdapter->device_mode);
2189
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302190 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2191 status = wlan_hdd_validate_context(pHddCtx);
2192
2193 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002194 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302195 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2196 "%s: HDD context is not valid", __func__);
2197 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002198 }
2199
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302200 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002201 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302202 )
Jeff Johnson295189b2012-06-20 16:38:30 -07002203 {
2204 beacon_data_t *old,*new;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302205
Jeff Johnson295189b2012-06-20 16:38:30 -07002206 old = pAdapter->sessionCtx.ap.beacon;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302207
Jeff Johnson295189b2012-06-20 16:38:30 -07002208 if (!old)
2209 return -ENOENT;
2210
2211 status = wlan_hdd_cfg80211_alloc_new_beacon(pAdapter,&new,params);
2212
2213 if(status != VOS_STATUS_SUCCESS) {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302214 hddLog(VOS_TRACE_LEVEL_FATAL,
Jeff Johnson295189b2012-06-20 16:38:30 -07002215 "%s: Error!!! Allocating the new beacon\n",__func__);
2216 return -EINVAL;
2217 }
2218
2219 pAdapter->sessionCtx.ap.beacon = new;
2220
2221 status = wlan_hdd_cfg80211_start_bss(pAdapter, params);
2222 }
2223
2224 EXIT();
2225 return status;
2226}
2227
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002228#endif //(LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
2229
2230#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07002231static int wlan_hdd_cfg80211_del_beacon(struct wiphy *wiphy,
2232 struct net_device *dev)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002233#else
2234static int wlan_hdd_cfg80211_stop_ap (struct wiphy *wiphy,
2235 struct net_device *dev)
2236#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002237{
2238 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsone7245742012-09-05 17:12:55 -07002239 hdd_context_t *pHddCtx = NULL;
2240 hdd_scaninfo_t *pScanInfo = NULL;
2241 hdd_adapter_t *staAdapter = NULL;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302242 VOS_STATUS status;
Jeff Johnson295189b2012-06-20 16:38:30 -07002243
2244 ENTER();
2245
2246 if (NULL == pAdapter)
2247 {
2248 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002249 "%s: HDD adapter context is Null", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002250 return -ENODEV;
2251 }
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002252
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302253 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2254 status = wlan_hdd_validate_context(pHddCtx);
2255
2256 if (0 != status)
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002257 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302258 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2259 "%s: HDD context is not valid", __func__);
2260 return status;
Jeff Johnson4416a782013-03-25 14:17:50 -07002261 }
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002262
2263 staAdapter = hdd_get_adapter(pAdapter->pHddCtx, WLAN_HDD_INFRA_STATION);
2264 if (NULL == staAdapter)
2265 {
2266 staAdapter = hdd_get_adapter(pAdapter->pHddCtx, WLAN_HDD_P2P_CLIENT);
2267 if (NULL == staAdapter)
2268 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302269 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002270 "%s: HDD adapter context is Null", __func__);
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002271 return -ENODEV;
2272 }
2273 }
2274
2275 pScanInfo = &pHddCtx->scan_info;
2276
Jeff Johnson295189b2012-06-20 16:38:30 -07002277 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
2278 __func__,pAdapter->device_mode);
2279
Jeff Johnsone7245742012-09-05 17:12:55 -07002280 if ((pScanInfo != NULL) && pScanInfo->mScanPending)
2281 {
Madan Mohan Koyyalamudif4e81002012-11-13 10:46:38 -08002282 INIT_COMPLETION(pScanInfo->abortscan_event_var);
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05302283 hdd_abort_mac_scan(staAdapter->pHddCtx, pAdapter->sessionId);
Jeff Johnsone7245742012-09-05 17:12:55 -07002284 status = wait_for_completion_interruptible_timeout(
Madan Mohan Koyyalamudif4e81002012-11-13 10:46:38 -08002285 &pScanInfo->abortscan_event_var,
Jeff Johnsone7245742012-09-05 17:12:55 -07002286 msecs_to_jiffies(WLAN_WAIT_TIME_ABORTSCAN));
2287 if (!status)
2288 {
2289 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Jeff Johnson902c9832012-12-10 14:28:09 -08002290 "%s: Timeout occurred while waiting for abortscan" ,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002291 __func__);
Jeff Johnsone7245742012-09-05 17:12:55 -07002292 VOS_ASSERT(pScanInfo->mScanPending);
2293 return 0;
2294 }
2295 }
2296
Jeff Johnson295189b2012-06-20 16:38:30 -07002297 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002298 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -07002299 )
2300 {
2301 beacon_data_t *old;
2302
2303 old = pAdapter->sessionCtx.ap.beacon;
2304
2305 if (!old)
2306 return -ENOENT;
2307
Jeff Johnson295189b2012-06-20 16:38:30 -07002308 hdd_cleanup_actionframe(pHddCtx, pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07002309
2310 mutex_lock(&pHddCtx->sap_lock);
2311 if(test_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags))
2312 {
Jeff Johnson4416a782013-03-25 14:17:50 -07002313 if ( VOS_STATUS_SUCCESS == (status = WLANSAP_StopBss(pHddCtx->pvosContext) ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07002314 {
2315 hdd_hostapd_state_t *pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
2316
2317 status = vos_wait_single_event(&pHostapdState->vosEvent, 10000);
2318
2319 if (!VOS_IS_STATUS_SUCCESS(status))
2320 {
2321 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2322 ("ERROR: HDD vos wait for single_event failed!!\n"));
2323 VOS_ASSERT(0);
2324 }
2325 }
2326 clear_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags);
2327 }
2328 mutex_unlock(&pHddCtx->sap_lock);
2329
2330 if(status != VOS_STATUS_SUCCESS)
2331 {
2332 hddLog(VOS_TRACE_LEVEL_FATAL,
2333 "%s:Error!!! Stopping the BSS\n",__func__);
2334 return -EINVAL;
2335 }
2336
Jeff Johnson4416a782013-03-25 14:17:50 -07002337 if (ccmCfgSetInt(pHddCtx->hHal,
Jeff Johnson295189b2012-06-20 16:38:30 -07002338 WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG, 0,NULL, eANI_BOOLEAN_FALSE)
2339 ==eHAL_STATUS_FAILURE)
2340 {
2341 hddLog(LOGE,
2342 "Could not pass on WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG to CCM\n");
2343 }
2344
Jeff Johnson4416a782013-03-25 14:17:50 -07002345 if ( eHAL_STATUS_FAILURE == ccmCfgSetInt(pHddCtx->hHal,
Jeff Johnson295189b2012-06-20 16:38:30 -07002346 WNI_CFG_ASSOC_RSP_ADDNIE_FLAG, 0, NULL,
2347 eANI_BOOLEAN_FALSE) )
2348 {
2349 hddLog(LOGE,
2350 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_FLAG to CCM\n");
2351 }
2352
2353 // Reset WNI_CFG_PROBE_RSP Flags
2354 wlan_hdd_reset_prob_rspies(pAdapter);
2355
2356 pAdapter->sessionCtx.ap.beacon = NULL;
2357 kfree(old);
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07002358#ifdef WLAN_FEATURE_P2P_DEBUG
2359 if((pAdapter->device_mode == WLAN_HDD_P2P_GO) &&
2360 (globalP2PConnectionStatus == P2P_GO_COMPLETED_STATE))
2361 {
2362 hddLog(LOGE,"[P2P State] From GO completed to Inactive state "
2363 "GO got removed");
2364 globalP2PConnectionStatus = P2P_NOT_ACTIVE;
2365 }
2366#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002367 }
2368 EXIT();
2369 return status;
2370}
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002371
2372#if (LINUX_VERSION_CODE > KERNEL_VERSION(3,3,0))
2373
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302374static int wlan_hdd_cfg80211_start_ap(struct wiphy *wiphy,
2375 struct net_device *dev,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002376 struct cfg80211_ap_settings *params)
2377{
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302378 hdd_adapter_t *pAdapter;
2379 hdd_context_t *pHddCtx;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302380 int status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002381
2382 ENTER();
2383
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302384 if (NULL == dev)
Madan Mohan Koyyalamudib2c36892012-10-18 20:52:38 -07002385 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302386 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302387 "%s: Device is Null", __func__);
2388 return -ENODEV;
2389 }
2390
2391 pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
2392 if (NULL == pAdapter)
2393 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302394 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302395 "%s: HDD adapter is Null", __func__);
2396 return -ENODEV;
2397 }
2398
2399 if (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic)
2400 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302401 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302402 "%s: HDD adapter magic is invalid", __func__);
2403 return -ENODEV;
2404 }
2405
2406 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302407 status = wlan_hdd_validate_context(pHddCtx);
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302408
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302409 if (0 != status)
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302410 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302411 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2412 "%s: HDD context is not valid", __func__);
2413 return status;
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302414 }
2415
2416 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: device mode = %d",
2417 __func__, pAdapter->device_mode);
2418
2419 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002420 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002421 )
2422 {
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302423 beacon_data_t *old, *new;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002424
2425 old = pAdapter->sessionCtx.ap.beacon;
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302426
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002427 if (old)
2428 return -EALREADY;
2429
2430 status = wlan_hdd_cfg80211_alloc_new_beacon(pAdapter, &new, &params->beacon, params->dtim_period);
2431
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302432 if (status != 0)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002433 {
2434 hddLog(VOS_TRACE_LEVEL_FATAL,
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302435 "%s:Error!!! Allocating the new beacon", __func__);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002436 return -EINVAL;
2437 }
2438 pAdapter->sessionCtx.ap.beacon = new;
Viral Modi3a32cc52013-02-08 11:14:52 -08002439#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
Yue Maf49ba872013-08-19 12:04:25 -07002440 wlan_hdd_cfg80211_set_channel(wiphy, dev,
2441#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0))
2442 params->channel, params->channel_type);
2443#else
2444 params->chandef.chan, cfg80211_get_chandef_type(&(params->chandef)));
2445#endif
Viral Modi3a32cc52013-02-08 11:14:52 -08002446#endif
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002447 status = wlan_hdd_cfg80211_start_bss(pAdapter, &params->beacon, params->ssid,
2448 params->ssid_len, params->hidden_ssid);
Gopichand Nakkala8c0386c2013-07-09 23:31:37 +05302449 if (0 == status)
2450 {
2451 hdd_start_p2p_go_connection_in_progress_timer(pAdapter);
2452 }
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002453 }
2454
2455 EXIT();
2456 return status;
2457}
2458
2459
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302460static int wlan_hdd_cfg80211_change_beacon(struct wiphy *wiphy,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002461 struct net_device *dev,
2462 struct cfg80211_beacon_data *params)
2463{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302464 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302465 hdd_context_t *pHddCtx;
2466 int status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002467
2468 ENTER();
2469
2470 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
2471 __func__, pAdapter->device_mode);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302472
2473 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2474 status = wlan_hdd_validate_context(pHddCtx);
2475
2476 if (0 != status)
Madan Mohan Koyyalamudib2c36892012-10-18 20:52:38 -07002477 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302478 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2479 "%s: HDD context is not valid", __func__);
2480 return status;
Madan Mohan Koyyalamudib2c36892012-10-18 20:52:38 -07002481 }
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002482
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302483 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002484 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302485 )
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002486 {
2487 beacon_data_t *old,*new;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302488
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002489 old = pAdapter->sessionCtx.ap.beacon;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302490
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002491 if (!old)
2492 return -ENOENT;
2493
2494 status = wlan_hdd_cfg80211_alloc_new_beacon(pAdapter, &new, params, 0);
2495
2496 if(status != VOS_STATUS_SUCCESS) {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302497 hddLog(VOS_TRACE_LEVEL_FATAL,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002498 "%s: Error!!! Allocating the new beacon\n",__func__);
2499 return -EINVAL;
2500 }
2501
2502 pAdapter->sessionCtx.ap.beacon = new;
2503
2504 status = wlan_hdd_cfg80211_start_bss(pAdapter, params, NULL, 0, 0);
2505 }
2506
2507 EXIT();
2508 return status;
2509}
2510
2511#endif //(LINUX_VERSION_CODE > KERNEL_VERSION(3,3,0))
2512
Jeff Johnson295189b2012-06-20 16:38:30 -07002513
2514static int wlan_hdd_cfg80211_change_bss (struct wiphy *wiphy,
2515 struct net_device *dev,
2516 struct bss_parameters *params)
2517{
2518 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
2519
2520 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302521
Jeff Johnson295189b2012-06-20 16:38:30 -07002522 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
2523 __func__,pAdapter->device_mode);
2524
2525 if((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002526 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302527 )
Jeff Johnson295189b2012-06-20 16:38:30 -07002528 {
2529 /* ap_isolate == -1 means that in change bss, upper layer doesn't
2530 * want to update this parameter */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302531 if (-1 != params->ap_isolate)
Jeff Johnson295189b2012-06-20 16:38:30 -07002532 {
2533 pAdapter->sessionCtx.ap.apDisableIntraBssFwd = !!params->ap_isolate;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302534 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002535 }
2536
2537 EXIT();
2538 return 0;
2539}
2540
2541/*
2542 * FUNCTION: wlan_hdd_cfg80211_change_iface
2543 * This function is used to set the interface type (INFRASTRUCTURE/ADHOC)
2544 */
2545int wlan_hdd_cfg80211_change_iface( struct wiphy *wiphy,
2546 struct net_device *ndev,
2547 enum nl80211_iftype type,
2548 u32 *flags,
2549 struct vif_params *params
2550 )
2551{
2552 struct wireless_dev *wdev;
2553 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
2554 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
Mohit Khanna0f232092012-09-11 14:46:08 -07002555 hdd_adapter_t *pP2pAdapter = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07002556 tCsrRoamProfile *pRoamProfile = NULL;
2557 eCsrRoamBssType LastBSSType;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302558 hdd_config_t *pConfig = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07002559 eMib_dot11DesiredBssType connectedBssType;
2560 VOS_STATUS status;
2561
2562 ENTER();
2563
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302564 status = wlan_hdd_validate_context(pHddCtx);
2565
2566 if (0 != status)
Jeff Johnson295189b2012-06-20 16:38:30 -07002567 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302568 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2569 "%s: HDD context is not valid", __func__);
2570 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07002571 }
2572
2573 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
2574 __func__, pAdapter->device_mode);
2575
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302576 pConfig = pHddCtx->cfg_ini;
Jeff Johnson295189b2012-06-20 16:38:30 -07002577 wdev = ndev->ieee80211_ptr;
2578
2579#ifdef WLAN_BTAMP_FEATURE
2580 if((NL80211_IFTYPE_P2P_CLIENT == type)||
2581 (NL80211_IFTYPE_ADHOC == type)||
2582 (NL80211_IFTYPE_AP == type)||
2583 (NL80211_IFTYPE_P2P_GO == type))
2584 {
2585 pHddCtx->isAmpAllowed = VOS_FALSE;
2586 // stop AMP traffic
2587 status = WLANBAP_StopAmp();
2588 if(VOS_STATUS_SUCCESS != status )
2589 {
2590 pHddCtx->isAmpAllowed = VOS_TRUE;
2591 hddLog(VOS_TRACE_LEVEL_FATAL,
2592 "%s: Failed to stop AMP", __func__);
2593 return -EINVAL;
2594 }
2595 }
2596#endif //WLAN_BTAMP_FEATURE
2597 /* Reset the current device mode bit mask*/
2598 wlan_hdd_clear_concurrency_mode(pHddCtx, pAdapter->device_mode);
2599
2600 if( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Jeff Johnson295189b2012-06-20 16:38:30 -07002601 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Jeff Johnsone7245742012-09-05 17:12:55 -07002602 || (pAdapter->device_mode == WLAN_HDD_P2P_DEVICE)
Jeff Johnson295189b2012-06-20 16:38:30 -07002603 )
2604 {
2605 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
2606 pRoamProfile = &pWextState->roamProfile;
2607 LastBSSType = pRoamProfile->BSSType;
2608
2609 switch (type)
2610 {
2611 case NL80211_IFTYPE_STATION:
Jeff Johnson295189b2012-06-20 16:38:30 -07002612 case NL80211_IFTYPE_P2P_CLIENT:
Jeff Johnson295189b2012-06-20 16:38:30 -07002613 hddLog(VOS_TRACE_LEVEL_INFO,
2614 "%s: setting interface Type to INFRASTRUCTURE", __func__);
2615 pRoamProfile->BSSType = eCSR_BSS_TYPE_INFRASTRUCTURE;
Jeff Johnsone7245742012-09-05 17:12:55 -07002616#ifdef WLAN_FEATURE_11AC
2617 if(pConfig->dot11Mode == eHDD_DOT11_MODE_AUTO)
2618 {
2619 pConfig->dot11Mode = eHDD_DOT11_MODE_11ac;
2620 }
2621#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302622 pRoamProfile->phyMode =
Jeff Johnsone7245742012-09-05 17:12:55 -07002623 hdd_cfg_xlate_to_csr_phy_mode(pConfig->dot11Mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07002624 wdev->iftype = type;
Gopichand Nakkalaf527dc62012-12-31 16:35:10 -08002625 //Check for sub-string p2p to confirm its a p2p interface
2626 if (NULL != strstr(ndev->name,"p2p"))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302627 {
Gopichand Nakkala864d3552012-12-31 16:08:51 -08002628 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
2629 WLAN_HDD_P2P_DEVICE : WLAN_HDD_P2P_CLIENT;
2630 }
2631 else
2632 {
2633 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
Jeff Johnson295189b2012-06-20 16:38:30 -07002634 WLAN_HDD_INFRA_STATION: WLAN_HDD_P2P_CLIENT;
Gopichand Nakkala864d3552012-12-31 16:08:51 -08002635 }
Madan Mohan Koyyalamudi81746922013-07-17 14:38:51 +05302636#ifdef FEATURE_WLAN_TDLS
2637 /* The open adapter for the p2p shall skip initializations in
2638 * tdls_init if the device mode is WLAN_HDD_P2P_DEVICE, for
2639 * TDLS is supported only on WLAN_HDD_P2P_CLIENT. Hence invoke
2640 * tdls_init when the change_iface sets the device mode to
2641 * WLAN_HDD_P2P_CLIENT.
2642 */
2643
2644 if ( pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
2645 {
2646 if (0 != wlan_hdd_tdls_init (pAdapter))
2647 {
2648 return -EINVAL;
2649 }
2650 }
2651#endif
2652
Jeff Johnson295189b2012-06-20 16:38:30 -07002653 break;
2654 case NL80211_IFTYPE_ADHOC:
2655 hddLog(VOS_TRACE_LEVEL_INFO,
2656 "%s: setting interface Type to ADHOC", __func__);
2657 pRoamProfile->BSSType = eCSR_BSS_TYPE_START_IBSS;
2658 pRoamProfile->phyMode =
2659 hdd_cfg_xlate_to_csr_phy_mode(pConfig->dot11Mode);
Shailender Karmuchia734f332013-04-19 14:02:48 -07002660 pAdapter->device_mode = WLAN_HDD_IBSS;
Jeff Johnson295189b2012-06-20 16:38:30 -07002661 wdev->iftype = type;
2662 break;
2663
2664 case NL80211_IFTYPE_AP:
Jeff Johnson295189b2012-06-20 16:38:30 -07002665 case NL80211_IFTYPE_P2P_GO:
Jeff Johnson295189b2012-06-20 16:38:30 -07002666 {
2667 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
2668 "%s: setting interface Type to %s", __func__,
2669 (type == NL80211_IFTYPE_AP) ? "SoftAP" : "P2pGo");
2670
Gopichand Nakkalaf527dc62012-12-31 16:35:10 -08002671 //Cancel any remain on channel for GO mode
2672 if (NL80211_IFTYPE_P2P_GO == type)
2673 {
2674 wlan_hdd_cancel_existing_remain_on_channel(pAdapter);
2675 }
Mohit Khanna0f232092012-09-11 14:46:08 -07002676 if (NL80211_IFTYPE_AP == type)
2677 {
2678 /* As Loading WLAN Driver one interface being created for p2p device
2679 * address. This will take one HW STA and the max number of clients
2680 * that can connect to softAP will be reduced by one. so while changing
2681 * the interface type to NL80211_IFTYPE_AP (SoftAP) remove p2p0
2682 * interface as it is not required in SoftAP mode.
2683 */
2684
2685 // Get P2P Adapter
2686 pP2pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_P2P_DEVICE);
2687
2688 if (pP2pAdapter)
2689 {
2690 hdd_stop_adapter(pHddCtx, pP2pAdapter);
2691 hdd_deinit_adapter(pHddCtx, pP2pAdapter);
2692 hdd_close_adapter(pHddCtx, pP2pAdapter, VOS_TRUE);
2693 }
2694 }
2695
Jeff Johnson295189b2012-06-20 16:38:30 -07002696 //De-init the adapter.
2697 hdd_stop_adapter( pHddCtx, pAdapter );
2698 hdd_deinit_adapter( pHddCtx, pAdapter );
2699 memset(&pAdapter->sessionCtx, 0, sizeof(pAdapter->sessionCtx));
Jeff Johnson295189b2012-06-20 16:38:30 -07002700 pAdapter->device_mode = (type == NL80211_IFTYPE_AP) ?
2701 WLAN_HDD_SOFTAP : WLAN_HDD_P2P_GO;
Jeff Johnson32d95a32012-09-10 13:15:23 -07002702
2703 //Disable BMPS and IMPS if enabled
2704 //before starting Go
2705 if(WLAN_HDD_P2P_GO == pAdapter->device_mode)
2706 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302707 if(VOS_STATUS_E_FAILURE ==
Jeff Johnson32d95a32012-09-10 13:15:23 -07002708 hdd_disable_bmps_imps(pHddCtx, WLAN_HDD_P2P_GO))
2709 {
2710 //Fail to Exit BMPS
2711 VOS_ASSERT(0);
2712 }
2713 }
2714
Madan Mohan Koyyalamudi3ff2a0b2012-10-15 14:33:46 -07002715 if ((WLAN_HDD_SOFTAP == pAdapter->device_mode) &&
2716 (pConfig->apRandomBssidEnabled))
2717 {
2718 /* To meet Android requirements create a randomized
2719 MAC address of the form 02:1A:11:Fx:xx:xx */
2720 get_random_bytes(&ndev->dev_addr[3], 3);
2721 ndev->dev_addr[0] = 0x02;
2722 ndev->dev_addr[1] = 0x1A;
2723 ndev->dev_addr[2] = 0x11;
2724 ndev->dev_addr[3] |= 0xF0;
2725 memcpy(pAdapter->macAddressCurrent.bytes, ndev->dev_addr,
2726 VOS_MAC_ADDR_SIZE);
2727 pr_info("wlan: Generated HotSpot BSSID "
2728 "%02x:%02x:%02x:%02x:%02x:%02x\n",
2729 ndev->dev_addr[0],
2730 ndev->dev_addr[1],
2731 ndev->dev_addr[2],
2732 ndev->dev_addr[3],
2733 ndev->dev_addr[4],
2734 ndev->dev_addr[5]);
2735 }
2736
Jeff Johnson295189b2012-06-20 16:38:30 -07002737 hdd_set_ap_ops( pAdapter->dev );
2738
2739 status = hdd_init_ap_mode(pAdapter);
2740 if(status != VOS_STATUS_SUCCESS)
2741 {
2742 hddLog(VOS_TRACE_LEVEL_FATAL,
2743 "%s: Error initializing the ap mode", __func__);
2744 return -EINVAL;
2745 }
2746 hdd_set_conparam(1);
2747
Jeff Johnson295189b2012-06-20 16:38:30 -07002748 /*interface type changed update in wiphy structure*/
2749 if(wdev)
2750 {
2751 wdev->iftype = type;
2752 pHddCtx->change_iface = type;
2753 }
2754 else
2755 {
2756 hddLog(VOS_TRACE_LEVEL_ERROR,
2757 "%s: ERROR !!!! Wireless dev is NULL", __func__);
2758 return -EINVAL;
2759 }
2760 goto done;
2761 }
2762
2763 default:
2764 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported interface Type",
2765 __func__);
2766 return -EOPNOTSUPP;
2767 }
2768 }
2769 else if ( (pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002770 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -07002771 )
2772 {
2773 switch(type)
2774 {
2775 case NL80211_IFTYPE_STATION:
Jeff Johnson295189b2012-06-20 16:38:30 -07002776 case NL80211_IFTYPE_P2P_CLIENT:
Jeff Johnson295189b2012-06-20 16:38:30 -07002777 case NL80211_IFTYPE_ADHOC:
Jeff Johnson32d95a32012-09-10 13:15:23 -07002778 hdd_stop_adapter( pHddCtx, pAdapter );
2779 hdd_deinit_adapter( pHddCtx, pAdapter );
Jeff Johnson295189b2012-06-20 16:38:30 -07002780 wdev->iftype = type;
Gopichand Nakkalaf527dc62012-12-31 16:35:10 -08002781 //Check for sub-string p2p to confirm its a p2p interface
2782 if (NULL != strstr(ndev->name,"p2p"))
Gopichand Nakkala864d3552012-12-31 16:08:51 -08002783 {
2784 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
2785 WLAN_HDD_P2P_DEVICE : WLAN_HDD_P2P_CLIENT;
2786 }
2787 else
2788 {
2789 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
Jeff Johnson295189b2012-06-20 16:38:30 -07002790 WLAN_HDD_INFRA_STATION: WLAN_HDD_P2P_CLIENT;
Gopichand Nakkala864d3552012-12-31 16:08:51 -08002791 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002792 hdd_set_conparam(0);
2793 pHddCtx->change_iface = type;
Jeff Johnson295189b2012-06-20 16:38:30 -07002794 memset(&pAdapter->sessionCtx, 0, sizeof(pAdapter->sessionCtx));
2795 hdd_set_station_ops( pAdapter->dev );
2796 status = hdd_init_station_mode( pAdapter );
2797 if( VOS_STATUS_SUCCESS != status )
2798 return -EOPNOTSUPP;
Jeff Johnsone7245742012-09-05 17:12:55 -07002799 /* In case of JB, for P2P-GO, only change interface will be called,
2800 * This is the right place to enable back bmps_imps()
2801 */
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05302802 if (pHddCtx->hdd_wlan_suspended)
2803 {
2804 hdd_set_pwrparams(pHddCtx);
2805 }
Jeff Johnsone7245742012-09-05 17:12:55 -07002806 hdd_enable_bmps_imps(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07002807 goto done;
2808 case NL80211_IFTYPE_AP:
Jeff Johnson295189b2012-06-20 16:38:30 -07002809 case NL80211_IFTYPE_P2P_GO:
Jeff Johnson295189b2012-06-20 16:38:30 -07002810 wdev->iftype = type;
Jeff Johnson295189b2012-06-20 16:38:30 -07002811 pAdapter->device_mode = (type == NL80211_IFTYPE_AP) ?
2812 WLAN_HDD_SOFTAP : WLAN_HDD_P2P_GO;
Jeff Johnson295189b2012-06-20 16:38:30 -07002813 goto done;
2814 default:
2815 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported interface Type",
2816 __func__);
2817 return -EOPNOTSUPP;
2818
2819 }
2820
2821 }
2822 else
2823 {
2824 return -EOPNOTSUPP;
2825 }
2826
2827
2828 if(pRoamProfile)
2829 {
2830 if ( LastBSSType != pRoamProfile->BSSType )
2831 {
2832 /*interface type changed update in wiphy structure*/
2833 wdev->iftype = type;
2834
2835 /*the BSS mode changed, We need to issue disconnect
2836 if connected or in IBSS disconnect state*/
2837 if ( hdd_connGetConnectedBssType(
2838 WLAN_HDD_GET_STATION_CTX_PTR(pAdapter), &connectedBssType ) ||
2839 ( eCSR_BSS_TYPE_START_IBSS == LastBSSType ) )
2840 {
2841 /*need to issue a disconnect to CSR.*/
2842 INIT_COMPLETION(pAdapter->disconnect_comp_var);
2843 if( eHAL_STATUS_SUCCESS ==
2844 sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
2845 pAdapter->sessionId,
2846 eCSR_DISCONNECT_REASON_UNSPECIFIED ) )
2847 {
2848 wait_for_completion_interruptible_timeout(
2849 &pAdapter->disconnect_comp_var,
2850 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
2851 }
2852 }
2853 }
2854 }
2855
2856done:
2857 /*set bitmask based on updated value*/
2858 wlan_hdd_set_concurrency_mode(pHddCtx, pAdapter->device_mode);
Leo Chang6fe1f922013-06-07 19:21:24 -07002859
2860 /* Only STA mode support TM now
2861 * all other mode, TM feature should be disabled */
2862 if ( (pHddCtx->cfg_ini->thermalMitigationEnable) &&
2863 (~VOS_STA & pHddCtx->concurrency_mode) )
2864 {
2865 hddDevTmLevelChangedHandler(pHddCtx->parent_dev, 0);
2866 }
2867
Jeff Johnson295189b2012-06-20 16:38:30 -07002868#ifdef WLAN_BTAMP_FEATURE
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302869 if((NL80211_IFTYPE_STATION == type) && (pHddCtx->concurrency_mode <= 1) &&
Jeff Johnson295189b2012-06-20 16:38:30 -07002870 (pHddCtx->no_of_sessions[WLAN_HDD_INFRA_STATION] <=1))
2871 {
2872 //we are ok to do AMP
2873 pHddCtx->isAmpAllowed = VOS_TRUE;
2874 }
2875#endif //WLAN_BTAMP_FEATURE
2876 EXIT();
2877 return 0;
2878}
2879
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002880#ifdef FEATURE_WLAN_TDLS
2881static int wlan_hdd_tdls_add_station(struct wiphy *wiphy,
2882 struct net_device *dev, u8 *mac, bool update, tCsrStaParams *StaParams)
2883{
2884 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
2885 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
2886 VOS_STATUS status;
Hoonki Lee5305c3a2013-04-29 23:28:59 -07002887 hddTdlsPeer_t *pTdlsPeer;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002888
2889 ENTER();
2890
Gopichand Nakkala838be5d2013-04-10 22:41:51 +05302891 if (NULL == pHddCtx || NULL == pHddCtx->cfg_ini)
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002892 {
2893 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2894 "Invalid arguments");
2895 return -EINVAL;
2896 }
Hoonki Lee27511902013-03-14 18:19:06 -07002897
2898 if ((eTDLS_SUPPORT_NOT_ENABLED == pHddCtx->tdls_mode) ||
2899 (eTDLS_SUPPORT_DISABLED == pHddCtx->tdls_mode))
2900 {
2901 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
2902 "%s: TDLS mode is disabled OR not enabled in FW."
2903 MAC_ADDRESS_STR " Request declined.",
2904 __func__, MAC_ADDR_ARRAY(mac));
2905 return -ENOTSUPP;
2906 }
2907
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002908 if (pHddCtx->isLogpInProgress)
2909 {
2910 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2911 "%s:LOGP in Progress. Ignore!!!", __func__);
Gopichand Nakkala05922802013-03-14 12:23:19 -07002912 wlan_hdd_tdls_set_link_status(pAdapter, mac, eTDLS_LINK_IDLE);
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002913 return -EBUSY;
2914 }
2915
Hoonki Lee5305c3a2013-04-29 23:28:59 -07002916 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, mac);
2917
2918 if ( NULL == pTdlsPeer ) {
2919 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
2920 "%s: " MAC_ADDRESS_STR " (update %d) not exist. return invalid",
2921 __func__, MAC_ADDR_ARRAY(mac), update);
2922 return -EINVAL;
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002923 }
Hoonki Lee5305c3a2013-04-29 23:28:59 -07002924
2925 /* in add station, we accept existing valid staId if there is */
2926 if ((0 == update) &&
2927 ((pTdlsPeer->link_status >= eTDLS_LINK_CONNECTING) ||
2928 (TDLS_STA_INDEX_VALID(pTdlsPeer->staId))))
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07002929 {
Hoonki Lee5305c3a2013-04-29 23:28:59 -07002930 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07002931 "%s: " MAC_ADDRESS_STR
Hoonki Lee5305c3a2013-04-29 23:28:59 -07002932 " link_status %d. staId %d. add station ignored.",
2933 __func__, MAC_ADDR_ARRAY(mac), pTdlsPeer->link_status, pTdlsPeer->staId);
2934 return 0;
2935 }
2936 /* in change station, we accept only when staId is valid */
2937 if ((1 == update) &&
2938 ((pTdlsPeer->link_status > eTDLS_LINK_CONNECTING) ||
2939 (!TDLS_STA_INDEX_VALID(pTdlsPeer->staId))))
2940 {
2941 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
2942 "%s: " MAC_ADDRESS_STR
2943 " link status %d. staId %d. change station %s.",
2944 __func__, MAC_ADDR_ARRAY(mac), pTdlsPeer->link_status, pTdlsPeer->staId,
2945 (TDLS_STA_INDEX_VALID(pTdlsPeer->staId)) ? "ignored" : "declined");
2946 return (TDLS_STA_INDEX_VALID(pTdlsPeer->staId)) ? 0 : -EPERM;
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07002947 }
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002948
2949 /* when others are on-going, we want to change link_status to idle */
Hoonki Leefb8df672013-04-10 18:20:34 -07002950 if (NULL != wlan_hdd_tdls_is_progress(pHddCtx, mac, TRUE, TRUE))
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002951 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07002952 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2953 "%s: " MAC_ADDRESS_STR
2954 " TDLS setup is ongoing. Request declined.",
2955 __func__, MAC_ADDR_ARRAY(mac));
Gopichand Nakkala05922802013-03-14 12:23:19 -07002956 goto error;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002957 }
2958
2959 /* first to check if we reached to maximum supported TDLS peer.
2960 TODO: for now, return -EPERM looks working fine,
2961 but need to check if any other errno fit into this category.*/
2962 if (HDD_MAX_NUM_TDLS_STA <= wlan_hdd_tdlsConnectedPeers(pAdapter))
2963 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07002964 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2965 "%s: " MAC_ADDRESS_STR
2966 " TDLS Max peer already connected. Request declined.",
2967 __func__, MAC_ADDR_ARRAY(mac));
Gopichand Nakkala05922802013-03-14 12:23:19 -07002968 goto error;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002969 }
2970 else
2971 {
2972 hddTdlsPeer_t *pTdlsPeer;
2973 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, mac);
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07002974 if (pTdlsPeer && TDLS_IS_CONNECTED(pTdlsPeer))
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002975 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07002976 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2977 "%s: " MAC_ADDRESS_STR " already connected. Request declined.",
2978 __func__, MAC_ADDR_ARRAY(mac));
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002979 return -EPERM;
2980 }
2981 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07002982 if (0 == update)
2983 wlan_hdd_tdls_set_link_status(pAdapter, mac, eTDLS_LINK_CONNECTING);
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002984
Jeff Johnsond75fe012013-04-06 10:53:06 -07002985 /* debug code */
Gopichand Nakkala838be5d2013-04-10 22:41:51 +05302986 if (NULL != StaParams)
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07002987 {
2988 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
2989 "%s: TDLS Peer Parameters.", __func__);
Hoonki Lee66b75f32013-04-16 18:30:07 -07002990 if(StaParams->htcap_present)
2991 {
2992 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
2993 "ht_capa->cap_info: %0x", StaParams->HTCap.capInfo);
2994 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
2995 "ht_capa->extended_capabilities: %0x",
2996 StaParams->HTCap.extendedHtCapInfo);
2997 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07002998 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
2999 "params->capability: %0x",StaParams->capability);
3000 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3001 "params->ext_capab_len: %0x",StaParams->extn_capability);
Hoonki Lee66b75f32013-04-16 18:30:07 -07003002 if(StaParams->vhtcap_present)
3003 {
3004 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3005 "rxMcsMap %x rxHighest %x txMcsMap %x txHighest %x",
3006 StaParams->VHTCap.suppMcs.rxMcsMap, StaParams->VHTCap.suppMcs.rxHighest,
3007 StaParams->VHTCap.suppMcs.txMcsMap, StaParams->VHTCap.suppMcs.txHighest);
3008 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003009 {
3010 int i = 0;
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003011 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "Supported rates:");
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003012 for (i = 0; i < sizeof(StaParams->supported_rates); i++)
3013 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3014 "[%d]: %x ", i, StaParams->supported_rates[i]);
3015 }
Jeff Johnsond75fe012013-04-06 10:53:06 -07003016 } /* end debug code */
Gopichand Nakkala838be5d2013-04-10 22:41:51 +05303017 else if ((1 == update) && (NULL == StaParams))
3018 {
3019 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3020 "%s : update is true, but staParams is NULL. Error!", __func__);
3021 return -EPERM;
3022 }
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003023
3024 INIT_COMPLETION(pAdapter->tdls_add_station_comp);
3025
3026 if (!update)
3027 {
3028 status = sme_AddTdlsPeerSta(WLAN_HDD_GET_HAL_CTX(pAdapter),
3029 pAdapter->sessionId, mac);
3030 }
3031 else
3032 {
3033 status = sme_ChangeTdlsPeerSta(WLAN_HDD_GET_HAL_CTX(pAdapter),
3034 pAdapter->sessionId, mac, StaParams);
3035 }
3036
3037 status = wait_for_completion_interruptible_timeout(&pAdapter->tdls_add_station_comp,
3038 msecs_to_jiffies(WAIT_TIME_TDLS_ADD_STA));
3039
3040 if (!status)
3041 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07003042 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003043 "%s: timeout waiting for tdls add station indication",
3044 __func__);
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07003045 return -EPERM;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003046 }
3047 if ( eHAL_STATUS_SUCCESS != pAdapter->tdlsAddStaStatus)
3048 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07003049 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003050 "%s: Add Station is unsucessful", __func__);
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07003051 return -EPERM;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003052 }
3053
3054 return 0;
Gopichand Nakkala05922802013-03-14 12:23:19 -07003055
3056error:
3057 wlan_hdd_tdls_set_link_status(pAdapter, mac, eTDLS_LINK_IDLE);
3058 return -EPERM;
3059
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003060}
3061#endif
3062
Jeff Johnson295189b2012-06-20 16:38:30 -07003063static int wlan_hdd_change_station(struct wiphy *wiphy,
3064 struct net_device *dev,
3065 u8 *mac,
3066 struct station_parameters *params)
3067{
3068 VOS_STATUS status = VOS_STATUS_SUCCESS;
3069 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Gopichand Nakkala29149562013-05-10 21:43:41 +05303070 hdd_context_t *pHddCtx;
3071 hdd_station_ctx_t *pHddStaCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07003072 v_MACADDR_t STAMacAddress;
Gopichand Nakkalab0856222013-03-12 22:39:05 -07003073#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003074 tCsrStaParams StaParams = {0};
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003075 tANI_U8 isBufSta = 0;
Gopichand Nakkalab0856222013-03-12 22:39:05 -07003076#endif
Jeff Johnsone7245742012-09-05 17:12:55 -07003077 ENTER();
3078
Gopichand Nakkala29149562013-05-10 21:43:41 +05303079 if ((NULL == pAdapter))
3080 {
3081 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
3082 "invalid adapter ");
3083 return -EINVAL;
3084 }
3085
3086 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
3087 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3088
3089 if ((NULL == pHddCtx) || (NULL == pHddStaCtx))
3090 {
3091 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
3092 "invalid HDD state or HDD station context");
3093 return -EINVAL;
3094 }
3095
3096 if (pHddCtx->isLogpInProgress)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003097 {
3098 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3099 "%s:LOGP in Progress. Ignore!!!", __func__);
3100 return -EAGAIN;
3101 }
3102
Jeff Johnson295189b2012-06-20 16:38:30 -07003103 vos_mem_copy(STAMacAddress.bytes, mac, sizeof(v_MACADDR_t));
3104
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003105 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
3106 || (pAdapter->device_mode == WLAN_HDD_P2P_GO))
Jeff Johnson295189b2012-06-20 16:38:30 -07003107 {
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003108 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED))
Jeff Johnson295189b2012-06-20 16:38:30 -07003109 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303110 status = hdd_softap_change_STA_state( pAdapter, &STAMacAddress,
Jeff Johnson295189b2012-06-20 16:38:30 -07003111 WLANTL_STA_AUTHENTICATED);
3112
Gopichand Nakkala29149562013-05-10 21:43:41 +05303113 if (status != VOS_STATUS_SUCCESS)
3114 {
3115 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3116 "%s: Not able to change TL state to AUTHENTICATED", __func__);
3117 return -EINVAL;
3118 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003119 }
3120 }
Hoonki Leea6d49be2013-04-05 09:43:25 -07003121 else if ((pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
3122 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)) {
Gopichand Nakkala29149562013-05-10 21:43:41 +05303123#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003124 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
3125 StaParams.capability = params->capability;
3126 StaParams.uapsd_queues = params->uapsd_queues;
3127 StaParams.max_sp = params->max_sp;
3128
3129 if (0 != params->ext_capab_len)
3130 vos_mem_copy(StaParams.extn_capability, params->ext_capab,
3131 sizeof(StaParams.extn_capability));
3132
3133 if (NULL != params->ht_capa)
Hoonki Lee66b75f32013-04-16 18:30:07 -07003134 {
3135 StaParams.htcap_present = 1;
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003136 vos_mem_copy(&StaParams.HTCap, params->ht_capa, sizeof(tSirHTCap));
Hoonki Lee66b75f32013-04-16 18:30:07 -07003137 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003138
3139 StaParams.supported_rates_len = params->supported_rates_len;
3140
3141 /* Note : The Maximum sizeof supported_rates sent by the Supplicant is 32.
3142 * The supported_rates array , for all the structures propogating till Add Sta
3143 * to the firmware has to be modified , if the supplicant (ieee80211) is
3144 * modified to send more rates.
3145 */
3146
3147 /* To avoid Data Currption , set to max length to SIR_MAC_MAX_SUPP_RATES
3148 */
3149 if (StaParams.supported_rates_len > SIR_MAC_MAX_SUPP_RATES)
3150 StaParams.supported_rates_len = SIR_MAC_MAX_SUPP_RATES;
3151
3152 if (0 != StaParams.supported_rates_len) {
3153 int i = 0;
3154 vos_mem_copy(StaParams.supported_rates, params->supported_rates,
3155 StaParams.supported_rates_len);
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003156 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003157 "Supported Rates with Length %d", StaParams.supported_rates_len);
3158 for (i=0; i < StaParams.supported_rates_len; i++)
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003159 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003160 "[%d]: %0x", i, StaParams.supported_rates[i]);
3161 }
3162
3163 if (NULL != params->vht_capa)
Hoonki Lee66b75f32013-04-16 18:30:07 -07003164 {
3165 StaParams.vhtcap_present = 1;
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003166 vos_mem_copy(&StaParams.VHTCap, params->vht_capa, sizeof(tSirVHTCap));
Hoonki Lee66b75f32013-04-16 18:30:07 -07003167 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003168
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003169 if (0 != params->ext_capab_len ) {
3170 /*Define A Macro : TODO Sunil*/
3171 if ((1<<4) & StaParams.extn_capability[3]) {
3172 isBufSta = 1;
3173 }
3174 }
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05303175 status = wlan_hdd_tdls_set_peer_caps( pAdapter, mac, params->uapsd_queues,
3176 params->max_sp, isBufSta);
3177 if (VOS_STATUS_SUCCESS != status) {
3178 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3179 "%s: wlan_hdd_tdls_set_peer_caps failed!", __func__);
3180 return -EINVAL;
3181 }
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003182 status = wlan_hdd_tdls_add_station(wiphy, dev, mac, 1, &StaParams);
3183
3184 if (VOS_STATUS_SUCCESS != status) {
3185 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3186 "%s: sme_ChangeTdlsPeerSta failed!", __func__);
3187 return -EINVAL;
3188 }
3189 }
Gopichand Nakkalab0856222013-03-12 22:39:05 -07003190#endif
Gopichand Nakkala6239acd2013-06-14 14:48:00 +05303191 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003192 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07003193 return status;
3194}
3195
3196/*
Jeff Johnson295189b2012-06-20 16:38:30 -07003197 * FUNCTION: wlan_hdd_cfg80211_add_key
3198 * This function is used to initialize the key information
3199 */
3200#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003201static int wlan_hdd_cfg80211_add_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003202 struct net_device *ndev,
3203 u8 key_index, bool pairwise,
3204 const u8 *mac_addr,
3205 struct key_params *params
3206 )
3207#else
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003208static int wlan_hdd_cfg80211_add_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003209 struct net_device *ndev,
3210 u8 key_index, const u8 *mac_addr,
3211 struct key_params *params
3212 )
3213#endif
3214{
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003215 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Jeff Johnson295189b2012-06-20 16:38:30 -07003216 tCsrRoamSetKey setKey;
3217 u8 groupmacaddr[WNI_CFG_BSSID_LEN] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303218 int status;
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003219 v_U32_t roamId= 0xFF;
3220 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
Jeff Johnson295189b2012-06-20 16:38:30 -07003221 hdd_hostapd_state_t *pHostapdState;
3222 VOS_STATUS vos_status;
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003223 eHalStatus halStatus;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303224 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07003225
3226 ENTER();
3227
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303228 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
3229 status = wlan_hdd_validate_context(pHddCtx);
3230
3231 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003232 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303233 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3234 "%s: HDD context is not valid", __func__);
3235 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003236 }
3237
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003238 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
3239 __func__, pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07003240
3241 if (CSR_MAX_NUM_KEY <= key_index)
3242 {
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003243 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key index %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07003244 key_index);
3245
3246 return -EINVAL;
3247 }
3248
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003249 if (CSR_MAX_KEY_LEN < params->key_len)
3250 {
3251 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key length %d", __func__,
3252 params->key_len);
3253
3254 return -EINVAL;
3255 }
3256
3257 hddLog(VOS_TRACE_LEVEL_INFO,
3258 "%s: called with key index = %d & key length %d",
3259 __func__, key_index, params->key_len);
Jeff Johnson295189b2012-06-20 16:38:30 -07003260
3261 /*extract key idx, key len and key*/
3262 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
3263 setKey.keyId = key_index;
3264 setKey.keyLength = params->key_len;
3265 vos_mem_copy(&setKey.Key[0],params->key, params->key_len);
3266
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003267 switch (params->cipher)
Jeff Johnson295189b2012-06-20 16:38:30 -07003268 {
3269 case WLAN_CIPHER_SUITE_WEP40:
3270 setKey.encType = eCSR_ENCRYPT_TYPE_WEP40_STATICKEY;
3271 break;
3272
3273 case WLAN_CIPHER_SUITE_WEP104:
3274 setKey.encType = eCSR_ENCRYPT_TYPE_WEP104_STATICKEY;
3275 break;
3276
3277 case WLAN_CIPHER_SUITE_TKIP:
3278 {
3279 u8 *pKey = &setKey.Key[0];
3280 setKey.encType = eCSR_ENCRYPT_TYPE_TKIP;
3281
3282 vos_mem_zero(pKey, CSR_MAX_KEY_LEN);
3283
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003284 /*Supplicant sends the 32bytes key in this order
Jeff Johnson295189b2012-06-20 16:38:30 -07003285
3286 |--------------|----------|----------|
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003287 | Tk1 |TX-MIC | RX Mic |
Jeff Johnson295189b2012-06-20 16:38:30 -07003288 |--------------|----------|----------|
3289 <---16bytes---><--8bytes--><--8bytes-->
3290
3291 */
3292 /*Sme expects the 32 bytes key to be in the below order
3293
3294 |--------------|----------|----------|
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003295 | Tk1 |RX-MIC | TX Mic |
Jeff Johnson295189b2012-06-20 16:38:30 -07003296 |--------------|----------|----------|
3297 <---16bytes---><--8bytes--><--8bytes-->
3298 */
3299 /* Copy the Temporal Key 1 (TK1) */
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003300 vos_mem_copy(pKey, params->key, 16);
Jeff Johnson295189b2012-06-20 16:38:30 -07003301
3302 /*Copy the rx mic first*/
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003303 vos_mem_copy(&pKey[16], &params->key[24], 8);
Jeff Johnson295189b2012-06-20 16:38:30 -07003304
3305 /*Copy the tx mic */
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003306 vos_mem_copy(&pKey[24], &params->key[16], 8);
Jeff Johnson295189b2012-06-20 16:38:30 -07003307
3308
3309 break;
3310 }
3311
3312 case WLAN_CIPHER_SUITE_CCMP:
3313 setKey.encType = eCSR_ENCRYPT_TYPE_AES;
3314 break;
3315
3316#ifdef FEATURE_WLAN_WAPI
3317 case WLAN_CIPHER_SUITE_SMS4:
3318 {
3319 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
3320 wlan_hdd_cfg80211_set_key_wapi(pAdapter, key_index, mac_addr,
3321 params->key, params->key_len);
3322 return 0;
3323 }
3324#endif
Chet Lanctot186b5732013-03-18 10:26:30 -07003325
Jeff Johnson295189b2012-06-20 16:38:30 -07003326#ifdef FEATURE_WLAN_CCX
3327 case WLAN_CIPHER_SUITE_KRK:
3328 setKey.encType = eCSR_ENCRYPT_TYPE_KRK;
3329 break;
3330#endif
Chet Lanctot186b5732013-03-18 10:26:30 -07003331
3332#ifdef WLAN_FEATURE_11W
3333 case WLAN_CIPHER_SUITE_AES_CMAC:
3334 setKey.encType = eCSR_ENCRYPT_TYPE_AES_CMAC;
Chet Lanctot3b5158a2013-03-31 16:45:21 -07003335 break;
Chet Lanctot186b5732013-03-18 10:26:30 -07003336#endif
3337
Jeff Johnson295189b2012-06-20 16:38:30 -07003338 default:
3339 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: unsupported cipher type %lu",
3340 __func__, params->cipher);
3341 return -EOPNOTSUPP;
3342 }
3343
3344 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: encryption type %d",
3345 __func__, setKey.encType);
3346
Shailender Karmuchi642e9812013-05-30 14:34:49 -07003347 if (
Jeff Johnson295189b2012-06-20 16:38:30 -07003348#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
3349 (!pairwise)
3350#else
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003351 (!mac_addr || is_broadcast_ether_addr(mac_addr))
Jeff Johnson295189b2012-06-20 16:38:30 -07003352#endif
Shailender Karmuchi642e9812013-05-30 14:34:49 -07003353 )
3354 {
3355 /* set group key*/
3356 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3357 "%s- %d: setting Broadcast key",
3358 __func__, __LINE__);
3359 setKey.keyDirection = eSIR_RX_ONLY;
3360 vos_mem_copy(setKey.peerMac,groupmacaddr,WNI_CFG_BSSID_LEN);
3361 }
3362 else
3363 {
3364 /* set pairwise key*/
3365 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3366 "%s- %d: setting pairwise key",
3367 __func__, __LINE__);
3368 setKey.keyDirection = eSIR_TX_RX;
3369 vos_mem_copy(setKey.peerMac, mac_addr,WNI_CFG_BSSID_LEN);
3370 }
3371 if ((WLAN_HDD_IBSS == pAdapter->device_mode) && !pairwise)
3372 {
3373 setKey.keyDirection = eSIR_TX_RX;
3374 /*Set the group key*/
3375 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
3376 pAdapter->sessionId, &setKey, &roamId );
Jeff Johnson295189b2012-06-20 16:38:30 -07003377
Shailender Karmuchi642e9812013-05-30 14:34:49 -07003378 if ( 0 != status )
3379 {
3380 hddLog(VOS_TRACE_LEVEL_ERROR,
3381 "%s: sme_RoamSetKey failed, returned %d", __func__, status);
3382 return -EINVAL;
3383 }
3384 /*Save the keys here and call sme_RoamSetKey for setting
3385 the PTK after peer joins the IBSS network*/
3386 vos_mem_copy(&pAdapter->sessionCtx.station.ibss_enc_key,
3387 &setKey, sizeof(tCsrRoamSetKey));
3388 return status;
3389 }
Gopichand Nakkala29149562013-05-10 21:43:41 +05303390 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP) ||
3391 (pAdapter->device_mode == WLAN_HDD_P2P_GO))
3392 {
Jeff Johnson295189b2012-06-20 16:38:30 -07003393 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003394 if( pHostapdState->bssState == BSS_START )
3395 {
Jeff Johnson295189b2012-06-20 16:38:30 -07003396 status = WLANSAP_SetKeySta( pVosContext, &setKey);
3397
3398 if ( status != eHAL_STATUS_SUCCESS )
3399 {
3400 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3401 "[%4d] WLANSAP_SetKeySta returned ERROR status= %d",
3402 __LINE__, status );
3403 }
3404 }
3405
3406 /* Saving WEP keys */
3407 else if( eCSR_ENCRYPT_TYPE_WEP40_STATICKEY == setKey.encType ||
3408 eCSR_ENCRYPT_TYPE_WEP104_STATICKEY == setKey.encType )
3409 {
3410 //Save the wep key in ap context. Issue setkey after the BSS is started.
3411 hdd_ap_ctx_t *pAPCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
3412 vos_mem_copy(&pAPCtx->wepKey[key_index], &setKey, sizeof(tCsrRoamSetKey));
3413 }
3414 else
3415 {
3416 //Save the key in ap context. Issue setkey after the BSS is started.
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003417 hdd_ap_ctx_t *pAPCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07003418 vos_mem_copy(&pAPCtx->groupKey, &setKey, sizeof(tCsrRoamSetKey));
3419 }
3420 }
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003421 else if ( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION) ||
3422 (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003423 {
3424 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
3425 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3426
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303427#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
3428 if (!pairwise)
3429#else
3430 if (!mac_addr || is_broadcast_ether_addr(mac_addr))
3431#endif
3432 {
3433 /* set group key*/
3434 if (pHddStaCtx->roam_info.deferKeyComplete)
3435 {
3436 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3437 "%s- %d: Perform Set key Complete",
3438 __func__, __LINE__);
3439 hdd_PerformRoamSetKeyComplete(pAdapter);
3440 }
3441 }
3442
Jeff Johnson295189b2012-06-20 16:38:30 -07003443 pWextState->roamProfile.Keys.KeyLength[key_index] = (u8)params->key_len;
3444
Venkata Prathyusha Kuntupalliee2ce712013-01-17 14:09:24 -08003445 pWextState->roamProfile.Keys.defaultIndex = key_index;
3446
3447
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003448 vos_mem_copy(&pWextState->roamProfile.Keys.KeyMaterial[key_index][0],
Jeff Johnson295189b2012-06-20 16:38:30 -07003449 params->key, params->key_len);
3450
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303451
Jeff Johnson295189b2012-06-20 16:38:30 -07003452 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_SETTING_KEY;
3453
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303454 hddLog(VOS_TRACE_LEVEL_INFO_MED,
Jeff Johnson295189b2012-06-20 16:38:30 -07003455 "%s: set key for peerMac %2x:%2x:%2x:%2x:%2x:%2x, direction %d",
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303456 __func__, setKey.peerMac[0], setKey.peerMac[1],
3457 setKey.peerMac[2], setKey.peerMac[3],
3458 setKey.peerMac[4], setKey.peerMac[5],
Jeff Johnson295189b2012-06-20 16:38:30 -07003459 setKey.keyDirection);
3460
3461 vos_status = wlan_hdd_check_ula_done(pAdapter);
3462
3463 if ( vos_status != VOS_STATUS_SUCCESS )
3464 {
3465 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3466 "[%4d] wlan_hdd_check_ula_done returned ERROR status= %d",
3467 __LINE__, vos_status );
3468
3469 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3470
3471 return -EINVAL;
3472
3473 }
3474
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003475#ifdef WLAN_FEATURE_VOWIFI_11R
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303476 /* The supplicant may attempt to set the PTK once pre-authentication
3477 is done. Save the key in the UMAC and include it in the ADD BSS
3478 request */
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003479 halStatus = sme_FTUpdateKey( WLAN_HDD_GET_HAL_CTX(pAdapter), &setKey);
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303480 if ( halStatus == eHAL_STATUS_FT_PREAUTH_KEY_SUCCESS )
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003481 {
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303482 hddLog(VOS_TRACE_LEVEL_INFO_MED,
3483 "%s: Update PreAuth Key success", __func__);
3484 return 0;
3485 }
3486 else if ( halStatus == eHAL_STATUS_FT_PREAUTH_KEY_FAILED )
3487 {
3488 hddLog(VOS_TRACE_LEVEL_ERROR,
3489 "%s: Update PreAuth Key failed", __func__);
Gopichand Nakkalad7d13652013-02-15 01:48:00 +05303490 return -EINVAL;
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003491 }
3492#endif /* WLAN_FEATURE_VOWIFI_11R */
Jeff Johnson295189b2012-06-20 16:38:30 -07003493
3494 /* issue set key request to SME*/
3495 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
3496 pAdapter->sessionId, &setKey, &roamId );
3497
3498 if ( 0 != status )
3499 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303500 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07003501 "%s: sme_RoamSetKey failed, returned %d", __func__, status);
3502 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3503 return -EINVAL;
3504 }
3505
3506
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303507 /* in case of IBSS as there was no information available about WEP keys during
3508 * IBSS join, group key intialized with NULL key, so re-initialize group key
Jeff Johnson295189b2012-06-20 16:38:30 -07003509 * with correct value*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303510 if ( (eCSR_BSS_TYPE_START_IBSS == pWextState->roamProfile.BSSType) &&
3511 !( ( IW_AUTH_KEY_MGMT_802_1X
3512 == (pWextState->authKeyMgmt & IW_AUTH_KEY_MGMT_802_1X))
Jeff Johnson295189b2012-06-20 16:38:30 -07003513 && (eCSR_AUTH_TYPE_OPEN_SYSTEM == pHddStaCtx->conn_info.authType)
3514 )
3515 &&
3516 ( (WLAN_CIPHER_SUITE_WEP40 == params->cipher)
3517 || (WLAN_CIPHER_SUITE_WEP104 == params->cipher)
3518 )
3519 )
3520 {
3521 setKey.keyDirection = eSIR_RX_ONLY;
3522 vos_mem_copy(setKey.peerMac,groupmacaddr,WNI_CFG_BSSID_LEN);
3523
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303524 hddLog(VOS_TRACE_LEVEL_INFO_MED,
Jeff Johnson295189b2012-06-20 16:38:30 -07003525 "%s: set key peerMac %2x:%2x:%2x:%2x:%2x:%2x, direction %d",
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303526 __func__, setKey.peerMac[0], setKey.peerMac[1],
3527 setKey.peerMac[2], setKey.peerMac[3],
3528 setKey.peerMac[4], setKey.peerMac[5],
Jeff Johnson295189b2012-06-20 16:38:30 -07003529 setKey.keyDirection);
3530
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303531 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07003532 pAdapter->sessionId, &setKey, &roamId );
3533
3534 if ( 0 != status )
3535 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303536 hddLog(VOS_TRACE_LEVEL_ERROR,
3537 "%s: sme_RoamSetKey failed for group key (IBSS), returned %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07003538 __func__, status);
3539 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3540 return -EINVAL;
3541 }
3542 }
3543 }
3544
3545 return 0;
3546}
3547
3548/*
3549 * FUNCTION: wlan_hdd_cfg80211_get_key
3550 * This function is used to get the key information
3551 */
3552#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303553static int wlan_hdd_cfg80211_get_key(
3554 struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003555 struct net_device *ndev,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303556 u8 key_index, bool pairwise,
Jeff Johnson295189b2012-06-20 16:38:30 -07003557 const u8 *mac_addr, void *cookie,
3558 void (*callback)(void *cookie, struct key_params*)
3559 )
3560#else
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303561static int wlan_hdd_cfg80211_get_key(
3562 struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003563 struct net_device *ndev,
3564 u8 key_index, const u8 *mac_addr, void *cookie,
3565 void (*callback)(void *cookie, struct key_params*)
3566 )
3567#endif
3568{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303569 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Jeff Johnson295189b2012-06-20 16:38:30 -07003570 hdd_wext_state_t *pWextState= WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
3571 tCsrRoamProfile *pRoamProfile = &(pWextState->roamProfile);
3572 struct key_params params;
3573
3574 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303575
Jeff Johnson295189b2012-06-20 16:38:30 -07003576 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
3577 __func__,pAdapter->device_mode);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303578
Jeff Johnson295189b2012-06-20 16:38:30 -07003579 memset(&params, 0, sizeof(params));
3580
3581 if (CSR_MAX_NUM_KEY <= key_index)
3582 {
3583 return -EINVAL;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303584 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003585
3586 switch(pRoamProfile->EncryptionType.encryptionType[0])
3587 {
3588 case eCSR_ENCRYPT_TYPE_NONE:
3589 params.cipher = IW_AUTH_CIPHER_NONE;
3590 break;
3591
3592 case eCSR_ENCRYPT_TYPE_WEP40_STATICKEY:
3593 case eCSR_ENCRYPT_TYPE_WEP40:
3594 params.cipher = WLAN_CIPHER_SUITE_WEP40;
3595 break;
3596
3597 case eCSR_ENCRYPT_TYPE_WEP104_STATICKEY:
3598 case eCSR_ENCRYPT_TYPE_WEP104:
3599 params.cipher = WLAN_CIPHER_SUITE_WEP104;
3600 break;
3601
3602 case eCSR_ENCRYPT_TYPE_TKIP:
3603 params.cipher = WLAN_CIPHER_SUITE_TKIP;
3604 break;
3605
3606 case eCSR_ENCRYPT_TYPE_AES:
3607 params.cipher = WLAN_CIPHER_SUITE_AES_CMAC;
3608 break;
3609
3610 default:
3611 params.cipher = IW_AUTH_CIPHER_NONE;
3612 break;
3613 }
3614
3615 params.key_len = pRoamProfile->Keys.KeyLength[key_index];
3616 params.seq_len = 0;
3617 params.seq = NULL;
3618 params.key = &pRoamProfile->Keys.KeyMaterial[key_index][0];
3619 callback(cookie, &params);
3620 return 0;
3621}
3622
3623/*
3624 * FUNCTION: wlan_hdd_cfg80211_del_key
3625 * This function is used to delete the key information
3626 */
3627#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303628static int wlan_hdd_cfg80211_del_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003629 struct net_device *ndev,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303630 u8 key_index,
3631 bool pairwise,
Jeff Johnson295189b2012-06-20 16:38:30 -07003632 const u8 *mac_addr
3633 )
3634#else
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303635static int wlan_hdd_cfg80211_del_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003636 struct net_device *ndev,
3637 u8 key_index,
3638 const u8 *mac_addr
3639 )
3640#endif
3641{
3642 int status = 0;
3643
3644 //This code needs to be revisited. There is sme_removeKey API, we should
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303645 //plan to use that. After the change to use correct index in setkey,
Jeff Johnson295189b2012-06-20 16:38:30 -07003646 //it is observed that this is invalidating peer
3647 //key index whenever re-key is done. This is affecting data link.
3648 //It should be ok to ignore del_key.
3649#if 0
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303650 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
3651 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
Jeff Johnson295189b2012-06-20 16:38:30 -07003652 u8 groupmacaddr[WNI_CFG_BSSID_LEN] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
3653 tCsrRoamSetKey setKey;
3654 v_U32_t roamId= 0xFF;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303655
Jeff Johnson295189b2012-06-20 16:38:30 -07003656 ENTER();
3657
3658 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: device_mode = %d\n",
3659 __func__,pAdapter->device_mode);
3660
3661 if (CSR_MAX_NUM_KEY <= key_index)
3662 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303663 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key index %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07003664 key_index);
3665
3666 return -EINVAL;
3667 }
3668
3669 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
3670 setKey.keyId = key_index;
3671
3672 if (mac_addr)
3673 vos_mem_copy(setKey.peerMac, mac_addr,WNI_CFG_BSSID_LEN);
3674 else
3675 vos_mem_copy(setKey.peerMac, groupmacaddr, WNI_CFG_BSSID_LEN);
3676
3677 setKey.encType = eCSR_ENCRYPT_TYPE_NONE;
3678
3679 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07003680 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303681 )
3682 {
3683
3684 hdd_hostapd_state_t *pHostapdState =
Jeff Johnson295189b2012-06-20 16:38:30 -07003685 WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
3686 if( pHostapdState->bssState == BSS_START)
3687 {
3688 status = WLANSAP_SetKeySta( pVosContext, &setKey);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303689
Jeff Johnson295189b2012-06-20 16:38:30 -07003690 if ( status != eHAL_STATUS_SUCCESS )
3691 {
3692 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3693 "[%4d] WLANSAP_SetKeySta returned ERROR status= %d",
3694 __LINE__, status );
3695 }
3696 }
3697 }
3698 else if ( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303699 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Jeff Johnson295189b2012-06-20 16:38:30 -07003700 )
3701 {
3702 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3703
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303704 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_SETTING_KEY;
3705
3706 hddLog(VOS_TRACE_LEVEL_INFO_MED,
Jeff Johnson295189b2012-06-20 16:38:30 -07003707 "%s: delete key for peerMac %2x:%2x:%2x:%2x:%2x:%2x",
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303708 __func__, setKey.peerMac[0], setKey.peerMac[1],
3709 setKey.peerMac[2], setKey.peerMac[3],
Jeff Johnson295189b2012-06-20 16:38:30 -07003710 setKey.peerMac[4], setKey.peerMac[5]);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303711 if(pAdapter->sessionCtx.station.conn_info.connState ==
3712 eConnectionState_Associated)
Jeff Johnson295189b2012-06-20 16:38:30 -07003713 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303714 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07003715 pAdapter->sessionId, &setKey, &roamId );
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303716
Jeff Johnson295189b2012-06-20 16:38:30 -07003717 if ( 0 != status )
3718 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303719 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07003720 "%s: sme_RoamSetKey failure, returned %d",
3721 __func__, status);
3722 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3723 return -EINVAL;
3724 }
3725 }
3726 }
3727#endif
Jeff Johnsone7245742012-09-05 17:12:55 -07003728 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07003729 return status;
3730}
3731
3732/*
3733 * FUNCTION: wlan_hdd_cfg80211_set_default_key
3734 * This function is used to set the default tx key index
3735 */
3736#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
3737static int wlan_hdd_cfg80211_set_default_key( struct wiphy *wiphy,
3738 struct net_device *ndev,
3739 u8 key_index,
3740 bool unicast, bool multicast)
3741#else
3742static int wlan_hdd_cfg80211_set_default_key( struct wiphy *wiphy,
3743 struct net_device *ndev,
3744 u8 key_index)
3745#endif
3746{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303747 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303748 int status;
Gopichand Nakkala29149562013-05-10 21:43:41 +05303749 hdd_wext_state_t *pWextState;
3750 hdd_station_ctx_t *pHddStaCtx;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303751 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07003752
3753 ENTER();
3754
Gopichand Nakkala29149562013-05-10 21:43:41 +05303755 if ((NULL == pAdapter))
3756 {
3757 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
3758 "invalid adapter");
3759 return -EINVAL;
3760 }
3761
3762 pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
3763 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3764
3765 if ((NULL == pWextState) || (NULL == pHddStaCtx))
3766 {
3767 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
3768 "invalid Wext state or HDD context");
3769 return -EINVAL;
3770 }
3771
Jeff Johnson295189b2012-06-20 16:38:30 -07003772 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d key_index = %d \n",
3773 __func__,pAdapter->device_mode, key_index);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303774
Jeff Johnson295189b2012-06-20 16:38:30 -07003775 if (CSR_MAX_NUM_KEY <= key_index)
3776 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303777 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key index %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07003778 key_index);
3779
3780 return -EINVAL;
3781 }
3782
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303783 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
3784 status = wlan_hdd_validate_context(pHddCtx);
3785
3786 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003787 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303788 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3789 "%s: HDD context is not valid", __func__);
3790 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003791 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303792
Jeff Johnson295189b2012-06-20 16:38:30 -07003793 if ((pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Jeff Johnson295189b2012-06-20 16:38:30 -07003794 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303795 )
Jeff Johnson295189b2012-06-20 16:38:30 -07003796 {
Gopichand Nakkala29149562013-05-10 21:43:41 +05303797 if ( (eCSR_ENCRYPT_TYPE_TKIP !=
Jeff Johnson295189b2012-06-20 16:38:30 -07003798 pWextState->roamProfile.EncryptionType.encryptionType[0]) &&
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303799 (eCSR_ENCRYPT_TYPE_AES !=
Jeff Johnson295189b2012-06-20 16:38:30 -07003800 pWextState->roamProfile.EncryptionType.encryptionType[0])
3801 )
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303802 {
3803 /* if default key index is not same as previous one,
Jeff Johnson295189b2012-06-20 16:38:30 -07003804 * then update the default key index */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303805
Jeff Johnson295189b2012-06-20 16:38:30 -07003806 tCsrRoamSetKey setKey;
3807 v_U32_t roamId= 0xFF;
3808 tCsrKeys *Keys = &pWextState->roamProfile.Keys;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303809
3810 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: default tx key index %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07003811 __func__, key_index);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303812
Jeff Johnson295189b2012-06-20 16:38:30 -07003813 Keys->defaultIndex = (u8)key_index;
3814 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
3815 setKey.keyId = key_index;
3816 setKey.keyLength = Keys->KeyLength[key_index];
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303817
3818 vos_mem_copy(&setKey.Key[0],
3819 &Keys->KeyMaterial[key_index][0],
Jeff Johnson295189b2012-06-20 16:38:30 -07003820 Keys->KeyLength[key_index]);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303821
Gopichand Nakkala29149562013-05-10 21:43:41 +05303822 setKey.keyDirection = eSIR_TX_RX;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303823
3824 vos_mem_copy(setKey.peerMac,
Jeff Johnson295189b2012-06-20 16:38:30 -07003825 &pHddStaCtx->conn_info.bssId[0],
3826 WNI_CFG_BSSID_LEN);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303827
Gopichand Nakkala29149562013-05-10 21:43:41 +05303828 if (Keys->KeyLength[key_index] == CSR_WEP40_KEY_LEN &&
3829 pWextState->roamProfile.EncryptionType.encryptionType[0] ==
3830 eCSR_ENCRYPT_TYPE_WEP104)
3831 {
3832 /*In the case of dynamic wep supplicant hardcodes DWEP type to eCSR_ENCRYPT_TYPE_WEP104
3833 even though ap is configured for WEP-40 encryption. In this canse the key length
3834 is 5 but the encryption type is 104 hence checking the key langht(5) and encryption
3835 type(104) and switching encryption type to 40*/
3836 pWextState->roamProfile.EncryptionType.encryptionType[0] =
3837 eCSR_ENCRYPT_TYPE_WEP40;
3838 pWextState->roamProfile.mcEncryptionType.encryptionType[0] =
3839 eCSR_ENCRYPT_TYPE_WEP40;
3840 }
3841
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303842 setKey.encType =
Jeff Johnson295189b2012-06-20 16:38:30 -07003843 pWextState->roamProfile.EncryptionType.encryptionType[0];
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303844
Jeff Johnson295189b2012-06-20 16:38:30 -07003845 /* issue set key request */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303846 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07003847 pAdapter->sessionId, &setKey, &roamId );
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303848
Jeff Johnson295189b2012-06-20 16:38:30 -07003849 if ( 0 != status )
3850 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303851 hddLog(VOS_TRACE_LEVEL_ERROR,
3852 "%s: sme_RoamSetKey failed, returned %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07003853 status);
3854 return -EINVAL;
3855 }
3856 }
3857 }
3858
3859 /* In SoftAp mode setting key direction for default mode */
3860 else if ( WLAN_HDD_SOFTAP == pAdapter->device_mode )
3861 {
3862 if ( (eCSR_ENCRYPT_TYPE_TKIP !=
3863 pWextState->roamProfile.EncryptionType.encryptionType[0]) &&
3864 (eCSR_ENCRYPT_TYPE_AES !=
3865 pWextState->roamProfile.EncryptionType.encryptionType[0])
3866 )
3867 {
3868 /* Saving key direction for default key index to TX default */
3869 hdd_ap_ctx_t *pAPCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
3870 pAPCtx->wepKey[key_index].keyDirection = eSIR_TX_DEFAULT;
3871 }
3872 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303873
Jeff Johnson295189b2012-06-20 16:38:30 -07003874 return status;
3875}
3876
Jeff Johnson295189b2012-06-20 16:38:30 -07003877/*
3878 * FUNCTION: wlan_hdd_cfg80211_inform_bss
3879 * This function is used to inform the BSS details to nl80211 interface.
3880 */
3881static struct cfg80211_bss* wlan_hdd_cfg80211_inform_bss(
3882 hdd_adapter_t *pAdapter, tCsrRoamConnectedProfile *roamProfile)
3883{
3884 struct net_device *dev = pAdapter->dev;
3885 struct wireless_dev *wdev = dev->ieee80211_ptr;
3886 struct wiphy *wiphy = wdev->wiphy;
3887 tSirBssDescription *pBssDesc = roamProfile->pBssDesc;
3888 int chan_no;
3889 int ie_length;
3890 const char *ie;
3891 unsigned int freq;
3892 struct ieee80211_channel *chan;
3893 int rssi = 0;
3894 struct cfg80211_bss *bss = NULL;
3895
3896 ENTER();
3897
3898 if( NULL == pBssDesc )
3899 {
3900 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: pBssDesc is NULL\n", __func__);
3901 return bss;
3902 }
3903
3904 chan_no = pBssDesc->channelId;
3905 ie_length = GET_IE_LEN_IN_BSS_DESC( pBssDesc->length );
3906 ie = ((ie_length != 0) ? (const char *)&pBssDesc->ieFields: NULL);
3907
3908 if( NULL == ie )
3909 {
3910 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: IE of BSS descriptor is NULL\n", __func__);
3911 return bss;
3912 }
3913
3914#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,38))
3915 if (chan_no <= ARRAY_SIZE(hdd_channels_2_4_GHZ))
3916 {
3917 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_2GHZ);
3918 }
3919 else
3920 {
3921 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_5GHZ);
3922 }
3923#else
3924 freq = ieee80211_channel_to_frequency(chan_no);
3925#endif
3926
3927 chan = __ieee80211_get_channel(wiphy, freq);
3928
3929 bss = cfg80211_get_bss(wiphy, chan, pBssDesc->bssId,
3930 &roamProfile->SSID.ssId[0], roamProfile->SSID.length,
3931 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
3932 if (bss == NULL)
3933 {
3934 rssi = (VOS_MIN ((pBssDesc->rssi + pBssDesc->sinr), 0))*100;
3935
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303936 return (cfg80211_inform_bss(wiphy, chan, pBssDesc->bssId,
3937 le64_to_cpu(*(__le64 *)pBssDesc->timeStamp),
Jeff Johnson295189b2012-06-20 16:38:30 -07003938 pBssDesc->capabilityInfo,
3939 pBssDesc->beaconInterval, ie, ie_length,
3940 rssi, GFP_KERNEL ));
3941}
3942 else
3943 {
3944 return bss;
3945 }
3946}
3947
3948
3949
3950/*
3951 * FUNCTION: wlan_hdd_cfg80211_inform_bss_frame
3952 * This function is used to inform the BSS details to nl80211 interface.
3953 */
3954struct cfg80211_bss*
3955wlan_hdd_cfg80211_inform_bss_frame( hdd_adapter_t *pAdapter,
3956 tSirBssDescription *bss_desc
3957 )
3958{
3959 /*
3960 cfg80211_inform_bss() is not updating ie field of bss entry, if entry
3961 already exists in bss data base of cfg80211 for that particular BSS ID.
3962 Using cfg80211_inform_bss_frame to update the bss entry instead of
3963 cfg80211_inform_bss, But this call expects mgmt packet as input. As of
3964 now there is no possibility to get the mgmt(probe response) frame from PE,
3965 converting bss_desc to ieee80211_mgmt(probe response) and passing to
3966 cfg80211_inform_bss_frame.
3967 */
3968 struct net_device *dev = pAdapter->dev;
3969 struct wireless_dev *wdev = dev->ieee80211_ptr;
3970 struct wiphy *wiphy = wdev->wiphy;
3971 int chan_no = bss_desc->channelId;
Madan Mohan Koyyalamudi86f629e2012-11-09 16:27:29 -08003972#ifdef WLAN_ENABLE_AGEIE_ON_SCAN_RESULTS
3973 qcom_ie_age *qie_age = NULL;
3974 int ie_length = GET_IE_LEN_IN_BSS_DESC( bss_desc->length ) + sizeof(qcom_ie_age);
3975#else
Jeff Johnson295189b2012-06-20 16:38:30 -07003976 int ie_length = GET_IE_LEN_IN_BSS_DESC( bss_desc->length );
Madan Mohan Koyyalamudi86f629e2012-11-09 16:27:29 -08003977#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07003978 const char *ie =
3979 ((ie_length != 0) ? (const char *)&bss_desc->ieFields: NULL);
3980 unsigned int freq;
3981 struct ieee80211_channel *chan;
3982 struct ieee80211_mgmt *mgmt =
3983 kzalloc((sizeof (struct ieee80211_mgmt) + ie_length), GFP_KERNEL);
3984 struct cfg80211_bss *bss_status = NULL;
3985 size_t frame_len = sizeof (struct ieee80211_mgmt) + ie_length;
3986 int rssi = 0;
Jeff Johnsone7245742012-09-05 17:12:55 -07003987#ifdef WLAN_OPEN_SOURCE
3988 struct timespec ts;
3989#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07003990
3991 ENTER();
3992
Madan Mohan Koyyalamudi2e5c9142012-11-02 13:17:48 -07003993 if (!mgmt)
3994 return NULL;
3995
Jeff Johnson295189b2012-06-20 16:38:30 -07003996 memcpy(mgmt->bssid, bss_desc->bssId, ETH_ALEN);
Jeff Johnsone7245742012-09-05 17:12:55 -07003997
3998#ifdef WLAN_OPEN_SOURCE
3999 /* Android does not want the timestamp from the frame.
4000 Instead it wants a monotonic increasing value */
4001 get_monotonic_boottime(&ts);
4002 mgmt->u.probe_resp.timestamp =
4003 ((u64)ts.tv_sec * 1000000) + (ts.tv_nsec / 1000);
4004#else
4005 /* keep old behavior for non-open source (for now) */
Jeff Johnson295189b2012-06-20 16:38:30 -07004006 memcpy(&mgmt->u.probe_resp.timestamp, bss_desc->timeStamp,
4007 sizeof (bss_desc->timeStamp));
Jeff Johnsone7245742012-09-05 17:12:55 -07004008
4009#endif
4010
Jeff Johnson295189b2012-06-20 16:38:30 -07004011 mgmt->u.probe_resp.beacon_int = bss_desc->beaconInterval;
4012 mgmt->u.probe_resp.capab_info = bss_desc->capabilityInfo;
Madan Mohan Koyyalamudi86f629e2012-11-09 16:27:29 -08004013
4014#ifdef WLAN_ENABLE_AGEIE_ON_SCAN_RESULTS
4015 /* GPS Requirement: need age ie per entry. Using vendor specific. */
4016 /* Assuming this is the last IE, copy at the end */
4017 ie_length -=sizeof(qcom_ie_age);
4018 qie_age = (qcom_ie_age *)(mgmt->u.probe_resp.variable + ie_length);
4019 qie_age->element_id = QCOM_VENDOR_IE_ID;
4020 qie_age->len = QCOM_VENDOR_IE_AGE_LEN;
4021 qie_age->oui_1 = QCOM_OUI1;
4022 qie_age->oui_2 = QCOM_OUI2;
4023 qie_age->oui_3 = QCOM_OUI3;
4024 qie_age->type = QCOM_VENDOR_IE_AGE_TYPE;
4025 qie_age->age = vos_timer_get_system_ticks() - bss_desc->nReceivedTime;
4026#endif
4027
Jeff Johnson295189b2012-06-20 16:38:30 -07004028 memcpy(mgmt->u.probe_resp.variable, ie, ie_length);
Gopichand Nakkalad908ec82013-05-16 19:32:19 +05304029 if (bss_desc->fProbeRsp)
4030 {
4031 mgmt->frame_control |=
4032 (u16)(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_RESP);
4033 }
4034 else
4035 {
4036 mgmt->frame_control |=
4037 (u16)(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_BEACON);
4038 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004039
4040#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,38))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304041 if (chan_no <= ARRAY_SIZE(hdd_channels_2_4_GHZ) &&
Jeff Johnson295189b2012-06-20 16:38:30 -07004042 (wiphy->bands[IEEE80211_BAND_2GHZ] != NULL))
4043 {
4044 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_2GHZ);
4045 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304046 else if ((chan_no > ARRAY_SIZE(hdd_channels_2_4_GHZ)) &&
Jeff Johnson295189b2012-06-20 16:38:30 -07004047 (wiphy->bands[IEEE80211_BAND_5GHZ] != NULL))
4048
4049 {
4050 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_5GHZ);
4051 }
4052 else
4053 {
4054 kfree(mgmt);
4055 return NULL;
4056 }
4057#else
4058 freq = ieee80211_channel_to_frequency(chan_no);
4059#endif
4060 chan = __ieee80211_get_channel(wiphy, freq);
Leela V Kiran Kumar Reddy90032de2013-01-24 18:33:30 -08004061 /*when the band is changed on the fly using the GUI, three things are done
4062 * 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)
4063 * as part of the scan abort, message willbe queued to PE and we proceed with flushing and changinh the band.
4064 * pe will stop the scanning further and report back the results what ever it had till now by calling the call back function.
4065 * if the time between update band and scandone call back is sufficent enough the band change reflects in SME, SME validates the channels
4066 * and discards the channels correponding to previous band and calls back with zero bss results.
4067 * 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
4068 * all the channels correponding to previous band.this is due to race condition.but those channels are invalid to the new band and so
4069 * this function __ieee80211_get_channel will return NULL.Each time we report scan result with this pointer null warning kernel trace is printed.
4070 * if the scan results contain large number of APs continuosly kernel warning trace is printed and it will lead to apps watch dog bark.
4071 * So drop the bss and continue to next bss.
4072 */
4073 if(chan == NULL)
4074 {
4075 hddLog(VOS_TRACE_LEVEL_INFO, "%s chan pointer is NULL", __func__);
Chilam Ngc4244af2013-04-01 15:37:32 -07004076 kfree(mgmt);
Leela V Kiran Kumar Reddy90032de2013-01-24 18:33:30 -08004077 return NULL;
4078 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004079 /*To keep the rssi icon of the connected AP in the scan window
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304080 *and the rssi icon of the wireless networks in sync
Jeff Johnson295189b2012-06-20 16:38:30 -07004081 * */
4082 if (( eConnectionState_Associated ==
4083 pAdapter->sessionCtx.station.conn_info.connState ) &&
4084 ( VOS_TRUE == vos_mem_compare(bss_desc->bssId,
4085 pAdapter->sessionCtx.station.conn_info.bssId,
4086 WNI_CFG_BSSID_LEN)))
4087 {
4088 /* supplicant takes the signal strength in terms of mBm(100*dBm) */
4089 rssi = (pAdapter->rssi * 100);
4090 }
4091 else
4092 {
4093 rssi = (VOS_MIN ((bss_desc->rssi + bss_desc->sinr), 0))*100;
4094 }
4095
4096 bss_status = cfg80211_inform_bss_frame(wiphy, chan, mgmt,
4097 frame_len, rssi, GFP_KERNEL);
4098 kfree(mgmt);
4099 return bss_status;
4100}
4101
4102/*
4103 * FUNCTION: wlan_hdd_cfg80211_update_bss_db
4104 * This function is used to update the BSS data base of CFG8011
4105 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304106struct cfg80211_bss* wlan_hdd_cfg80211_update_bss_db( hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07004107 tCsrRoamInfo *pRoamInfo
4108 )
4109{
4110 tCsrRoamConnectedProfile roamProfile;
4111 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
4112 struct cfg80211_bss *bss = NULL;
4113
4114 ENTER();
4115
4116 memset(&roamProfile, 0, sizeof(tCsrRoamConnectedProfile));
4117 sme_RoamGetConnectProfile(hHal, pAdapter->sessionId, &roamProfile);
4118
4119 if (NULL != roamProfile.pBssDesc)
4120 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304121 bss = wlan_hdd_cfg80211_inform_bss(pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07004122 &roamProfile);
4123
4124 if (NULL == bss)
4125 {
4126 hddLog(VOS_TRACE_LEVEL_INFO, "%s: cfg80211_inform_bss return NULL",
4127 __func__);
4128 }
4129
4130 sme_RoamFreeConnectProfile(hHal, &roamProfile);
4131 }
4132 else
4133 {
4134 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: roamProfile.pBssDesc is NULL",
4135 __func__);
4136 }
4137 return bss;
4138}
4139
4140/*
4141 * FUNCTION: wlan_hdd_cfg80211_update_bss
4142 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304143static int wlan_hdd_cfg80211_update_bss( struct wiphy *wiphy,
4144 hdd_adapter_t *pAdapter
Jeff Johnson295189b2012-06-20 16:38:30 -07004145 )
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304146{
Jeff Johnson295189b2012-06-20 16:38:30 -07004147 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
4148 tCsrScanResultInfo *pScanResult;
4149 eHalStatus status = 0;
4150 tScanResultHandle pResult;
4151 struct cfg80211_bss *bss_status = NULL;
4152
4153 ENTER();
4154
4155 if ((WLAN_HDD_GET_CTX(pAdapter))->isLogpInProgress)
4156 {
4157 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL, "%s:LOGP in Progress. Ignore!!!",__func__);
4158 return -EAGAIN;
4159 }
4160
4161 /*
4162 * start getting scan results and populate cgf80211 BSS database
4163 */
4164 status = sme_ScanGetResult(hHal, pAdapter->sessionId, NULL, &pResult);
4165
4166 /* no scan results */
4167 if (NULL == pResult)
4168 {
4169 hddLog(VOS_TRACE_LEVEL_INFO, "%s: No scan result\n", __func__);
4170 return status;
4171 }
4172
4173 pScanResult = sme_ScanResultGetFirst(hHal, pResult);
4174
4175 while (pScanResult)
4176 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304177 /*
4178 * cfg80211_inform_bss() is not updating ie field of bss entry, if
4179 * entry already exists in bss data base of cfg80211 for that
4180 * particular BSS ID. Using cfg80211_inform_bss_frame to update the
4181 * bss entry instead of cfg80211_inform_bss, But this call expects
4182 * mgmt packet as input. As of now there is no possibility to get
4183 * the mgmt(probe response) frame from PE, converting bss_desc to
Jeff Johnson295189b2012-06-20 16:38:30 -07004184 * ieee80211_mgmt(probe response) and passing to c
4185 * fg80211_inform_bss_frame.
4186 * */
4187
4188 bss_status = wlan_hdd_cfg80211_inform_bss_frame(pAdapter,
4189 &pScanResult->BssDescriptor);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304190
Jeff Johnson295189b2012-06-20 16:38:30 -07004191
4192 if (NULL == bss_status)
4193 {
4194 hddLog(VOS_TRACE_LEVEL_INFO,
4195 "%s: NULL returned by cfg80211_inform_bss\n", __func__);
4196 }
4197 else
4198 {
Yue Maf49ba872013-08-19 12:04:25 -07004199 cfg80211_put_bss(
4200#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,9,0))
4201 wiphy,
4202#endif
4203 bss_status);
Jeff Johnson295189b2012-06-20 16:38:30 -07004204 }
4205
4206 pScanResult = sme_ScanResultGetNext(hHal, pResult);
4207 }
4208
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304209 sme_ScanResultPurge(hHal, pResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07004210
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304211 return 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07004212}
4213
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004214void
4215hddPrintMacAddr(tCsrBssid macAddr, tANI_U8 logLevel)
4216{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304217 VOS_TRACE(VOS_MODULE_ID_HDD, logLevel,
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07004218 "%02X:%02X:%02X:%02X:%02X:%02X\n",
4219 macAddr[0], macAddr[1], macAddr[2], macAddr[3], macAddr[4],
4220 macAddr[5]);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004221} /****** end hddPrintMacAddr() ******/
4222
4223void
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07004224hddPrintPmkId(tANI_U8 *pmkId, tANI_U8 logLevel)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004225{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304226 VOS_TRACE(VOS_MODULE_ID_HDD, logLevel,
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07004227 "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
4228 pmkId[0], pmkId[1], pmkId[2], pmkId[3], pmkId[4],
4229 pmkId[5], pmkId[6], pmkId[7], pmkId[8], pmkId[9], pmkId[10],
4230 pmkId[11], pmkId[12], pmkId[13], pmkId[14], pmkId[15]);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004231} /****** end hddPrintPmkId() ******/
4232
4233//hddPrintMacAddr(tCsrBssid macAddr, tANI_U8 logLevel);
4234//hddPrintMacAddr(macAddr, VOS_TRACE_LEVEL_FATAL);
4235
4236//void sirDumpBuf(tpAniSirGlobal pMac, tANI_U8 modId, tANI_U32 level, tANI_U8 *buf, tANI_U32 size);
4237//sirDumpBuf(pMac, VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL, pmkid, 16);
4238
4239#define dump_bssid(bssid) \
4240 { \
Jeff Johnsone7245742012-09-05 17:12:55 -07004241 hddLog(VOS_TRACE_LEVEL_INFO, "BSSID (MAC) address:\t"); \
4242 hddPrintMacAddr(bssid, VOS_TRACE_LEVEL_INFO);\
4243 hddLog(VOS_TRACE_LEVEL_INFO, "\n"); \
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004244 }
4245
4246#define dump_pmkid(pMac, pmkid) \
4247 { \
Jeff Johnsone7245742012-09-05 17:12:55 -07004248 hddLog(VOS_TRACE_LEVEL_INFO, "PMKSA-ID:\t"); \
4249 hddPrintPmkId(pmkid, VOS_TRACE_LEVEL_INFO);\
4250 hddLog(VOS_TRACE_LEVEL_INFO, "\n"); \
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004251 }
4252
Madan Mohan Koyyalamudi1b4afb02012-10-22 15:25:16 -07004253#if defined(FEATURE_WLAN_LFR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004254/*
4255 * FUNCTION: wlan_hdd_cfg80211_pmksa_candidate_notify
4256 * This function is used to notify the supplicant of a new PMKSA candidate.
4257 */
4258int wlan_hdd_cfg80211_pmksa_candidate_notify(
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304259 hdd_adapter_t *pAdapter, tCsrRoamInfo *pRoamInfo,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004260 int index, bool preauth )
4261{
Jeff Johnsone7245742012-09-05 17:12:55 -07004262#ifdef FEATURE_WLAN_OKC
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004263 struct net_device *dev = pAdapter->dev;
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004264 hdd_context_t *pHddCtx = (hdd_context_t*)pAdapter->pHddCtx;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004265
4266 ENTER();
Jeff Johnsone7245742012-09-05 17:12:55 -07004267 hddLog(VOS_TRACE_LEVEL_INFO, "%s is going to notify supplicant of:", __func__);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004268
4269 if( NULL == pRoamInfo )
4270 {
4271 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: pRoamInfo is NULL\n", __func__);
4272 return -EINVAL;
4273 }
4274
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004275 if (eANI_BOOLEAN_TRUE == hdd_is_okc_mode_enabled(pHddCtx))
4276 {
4277 dump_bssid(pRoamInfo->bssid);
4278 cfg80211_pmksa_candidate_notify(dev, index,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004279 pRoamInfo->bssid, preauth, GFP_KERNEL);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004280 }
Jeff Johnsone7245742012-09-05 17:12:55 -07004281#endif /* FEATURE_WLAN_OKC */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304282 return 0;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004283}
4284#endif //FEATURE_WLAN_LFR
4285
Jeff Johnson295189b2012-06-20 16:38:30 -07004286/*
4287 * FUNCTION: hdd_cfg80211_scan_done_callback
4288 * scanning callback function, called after finishing scan
4289 *
4290 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304291static eHalStatus hdd_cfg80211_scan_done_callback(tHalHandle halHandle,
Jeff Johnson295189b2012-06-20 16:38:30 -07004292 void *pContext, tANI_U32 scanId, eCsrScanStatus status)
4293{
4294 struct net_device *dev = (struct net_device *) pContext;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304295 //struct wireless_dev *wdev = dev->ieee80211_ptr;
Jeff Johnson295189b2012-06-20 16:38:30 -07004296 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004297 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
4298 hdd_scaninfo_t *pScanInfo = &pHddCtx->scan_info;
Jeff Johnson295189b2012-06-20 16:38:30 -07004299 struct cfg80211_scan_request *req = NULL;
4300 int ret = 0;
4301
4302 ENTER();
4303
4304 hddLog(VOS_TRACE_LEVEL_INFO,
4305 "%s called with halHandle = %p, pContext = %p,"
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304306 "scanID = %d, returned status = %d\n",
Jeff Johnson295189b2012-06-20 16:38:30 -07004307 __func__, halHandle, pContext, (int) scanId, (int) status);
4308
4309 //Block on scan req completion variable. Can't wait forever though.
4310 ret = wait_for_completion_interruptible_timeout(
4311 &pScanInfo->scan_req_completion_event,
4312 msecs_to_jiffies(WLAN_WAIT_TIME_SCAN_REQ));
4313 if (!ret)
4314 {
4315 VOS_ASSERT(pScanInfo->mScanPending);
Jeff Johnsone7245742012-09-05 17:12:55 -07004316 goto allow_suspend;
Jeff Johnson295189b2012-06-20 16:38:30 -07004317 }
4318
4319 if(pScanInfo->mScanPending != VOS_TRUE)
4320 {
4321 VOS_ASSERT(pScanInfo->mScanPending);
Jeff Johnsone7245742012-09-05 17:12:55 -07004322 goto allow_suspend;
Jeff Johnson295189b2012-06-20 16:38:30 -07004323 }
4324
4325 /* Check the scanId */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304326 if (pScanInfo->scanId != scanId)
Jeff Johnson295189b2012-06-20 16:38:30 -07004327 {
4328 hddLog(VOS_TRACE_LEVEL_INFO,
4329 "%s called with mismatched scanId pScanInfo->scanId = %d "
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304330 "scanId = %d \n", __func__, (int) pScanInfo->scanId,
Jeff Johnson295189b2012-06-20 16:38:30 -07004331 (int) scanId);
4332 }
4333
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304334 ret = wlan_hdd_cfg80211_update_bss((WLAN_HDD_GET_CTX(pAdapter))->wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07004335 pAdapter);
4336
4337 if (0 > ret)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304338 hddLog(VOS_TRACE_LEVEL_INFO, "%s: NO SCAN result", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07004339
4340
4341 /* If any client wait scan result through WEXT
4342 * send scan done event to client */
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004343 if (pHddCtx->scan_info.waitScanResult)
Jeff Johnson295189b2012-06-20 16:38:30 -07004344 {
4345 /* The other scan request waiting for current scan finish
4346 * Send event to notify current scan finished */
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004347 if(WEXT_SCAN_PENDING_DELAY == pHddCtx->scan_info.scan_pending_option)
Jeff Johnson295189b2012-06-20 16:38:30 -07004348 {
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004349 vos_event_set(&pHddCtx->scan_info.scan_finished_event);
Jeff Johnson295189b2012-06-20 16:38:30 -07004350 }
4351 /* Send notify to WEXT client */
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004352 else if(WEXT_SCAN_PENDING_PIGGYBACK == pHddCtx->scan_info.scan_pending_option)
Jeff Johnson295189b2012-06-20 16:38:30 -07004353 {
4354 struct net_device *dev = pAdapter->dev;
4355 union iwreq_data wrqu;
4356 int we_event;
4357 char *msg;
4358
4359 memset(&wrqu, '\0', sizeof(wrqu));
4360 we_event = SIOCGIWSCAN;
4361 msg = NULL;
4362 wireless_send_event(dev, we_event, &wrqu, msg);
4363 }
4364 }
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004365 pHddCtx->scan_info.waitScanResult = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004366
4367 /* Get the Scan Req */
4368 req = pAdapter->request;
4369
4370 if (!req)
4371 {
4372 hddLog(VOS_TRACE_LEVEL_ERROR, "request is became NULL\n");
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07004373 pScanInfo->mScanPending = VOS_FALSE;
Jeff Johnsone7245742012-09-05 17:12:55 -07004374 goto allow_suspend;
Jeff Johnson295189b2012-06-20 16:38:30 -07004375 }
4376
4377 /*
4378 * setting up 0, just in case.
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304379 */
Jeff Johnson295189b2012-06-20 16:38:30 -07004380 req->n_ssids = 0;
4381 req->n_channels = 0;
4382 req->ie = 0;
4383
Jeff Johnson295189b2012-06-20 16:38:30 -07004384 pAdapter->request = NULL;
Jeff Johnsone7245742012-09-05 17:12:55 -07004385 /* Scan is no longer pending */
4386 pScanInfo->mScanPending = VOS_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004387
Madan Mohan Koyyalamudib764bf82012-10-11 16:38:51 -07004388 /*
4389 * cfg80211_scan_done informing NL80211 about completion
4390 * of scanning
4391 */
4392 cfg80211_scan_done(req, false);
Madan Mohan Koyyalamudif4e81002012-11-13 10:46:38 -08004393 complete(&pScanInfo->abortscan_event_var);
Jeff Johnson295189b2012-06-20 16:38:30 -07004394
Jeff Johnsone7245742012-09-05 17:12:55 -07004395allow_suspend:
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07004396 /* release the wake lock at the end of the scan*/
4397 hdd_allow_suspend();
Jeff Johnsone7245742012-09-05 17:12:55 -07004398
Madan Mohan Koyyalamudi10d83a92012-09-28 15:47:05 -07004399 /* Acquire wakelock to handle the case where APP's tries to suspend
4400 * immediatly after the driver gets connect request(i.e after scan)
4401 * from supplicant, this result in app's is suspending and not able
4402 * to process the connect request to AP */
Amar Singhal6144c002013-05-03 16:11:42 -07004403 hdd_allow_suspend_timeout(1000);
Madan Mohan Koyyalamudi10d83a92012-09-28 15:47:05 -07004404
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07004405#ifdef FEATURE_WLAN_TDLS
4406 wlan_hdd_tdls_scan_done_callback(pAdapter);
4407#endif
4408
Jeff Johnson295189b2012-06-20 16:38:30 -07004409 EXIT();
4410 return 0;
4411}
4412
4413/*
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004414 * FUNCTION: hdd_isScanAllowed
4415 * Go through each adapter and check if scan allowed
4416 *
4417 */
4418v_BOOL_t hdd_isScanAllowed( hdd_context_t *pHddCtx )
4419{
4420 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
4421 hdd_station_ctx_t *pHddStaCtx = NULL;
4422 hdd_adapter_t *pAdapter = NULL;
4423 VOS_STATUS status = 0;
4424 v_U8_t staId = 0;
4425 v_U8_t *staMac = NULL;
4426
Gopichand Nakkala8c0386c2013-07-09 23:31:37 +05304427 if (VOS_TIMER_STATE_RUNNING ==
4428 vos_timer_getCurrentState(&pHddCtx->hdd_p2p_go_conn_is_in_progress))
4429 {
4430 hddLog(VOS_TRACE_LEVEL_INFO,
4431 "%s: Connection is in progress, Do not allow the scan", __func__);
4432 return VOS_FALSE;
4433 }
4434
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004435 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
4436
4437 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
4438 {
4439 pAdapter = pAdapterNode->pAdapter;
4440
4441 if( pAdapter )
4442 {
4443 hddLog(VOS_TRACE_LEVEL_INFO,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304444 "%s: Adapter with device mode %d exists",
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004445 __func__, pAdapter->device_mode);
4446 if ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
4447 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) ||
4448 (WLAN_HDD_P2P_DEVICE == pAdapter->device_mode))
4449 {
4450 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
4451 if ((eConnectionState_Associated == pHddStaCtx->conn_info.connState) &&
4452 (VOS_FALSE == pHddStaCtx->conn_info.uIsAuthenticated))
4453 {
4454 staMac = (v_U8_t *) &(pAdapter->macAddressCurrent.bytes[0]);
4455 hddLog(VOS_TRACE_LEVEL_ERROR,
4456 "%s: client %02x:%02x:%02x:%02x:%02x:%02x is in the "
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304457 "middle of WPS/EAPOL exchange.", __func__,
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004458 staMac[0], staMac[1], staMac[2],
4459 staMac[3], staMac[4], staMac[5]);
4460 return VOS_FALSE;
4461 }
4462 }
4463 else if ((WLAN_HDD_SOFTAP == pAdapter->device_mode) ||
4464 (WLAN_HDD_P2P_GO == pAdapter->device_mode))
4465 {
4466 for (staId = 0; staId < WLAN_MAX_STA_COUNT; staId++)
4467 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304468 if ((pAdapter->aStaInfo[staId].isUsed) &&
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004469 (WLANTL_STA_CONNECTED == pAdapter->aStaInfo[staId].tlSTAState))
4470 {
4471 staMac = (v_U8_t *) &(pAdapter->aStaInfo[staId].macAddrSTA.bytes[0]);
4472
4473 hddLog(VOS_TRACE_LEVEL_ERROR,
4474 "%s: client %02x:%02x:%02x:%02x:%02x:%02x of SoftAP/P2P-GO is in the "
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304475 "middle of WPS/EAPOL exchange.", __func__,
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004476 staMac[0], staMac[1], staMac[2],
4477 staMac[3], staMac[4], staMac[5]);
4478 return VOS_FALSE;
4479 }
4480 }
4481 }
4482 }
4483 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
4484 pAdapterNode = pNext;
4485 }
4486 hddLog(VOS_TRACE_LEVEL_INFO,
4487 "%s: Scan allowed", __func__);
4488 return VOS_TRUE;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304489}
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004490
4491/*
Jeff Johnson295189b2012-06-20 16:38:30 -07004492 * FUNCTION: wlan_hdd_cfg80211_scan
4493 * this scan respond to scan trigger and update cfg80211 scan database
4494 * later, scan dump command can be used to recieve scan results
4495 */
Jeff Johnson3bbe4bf2013-01-18 17:05:29 -08004496int wlan_hdd_cfg80211_scan( struct wiphy *wiphy,
4497#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
4498 struct net_device *dev,
4499#endif
4500 struct cfg80211_scan_request *request)
4501{
4502#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
4503 struct net_device *dev = request->wdev->netdev;
4504#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304505 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Jeff Johnson295189b2012-06-20 16:38:30 -07004506 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
4507 hdd_wext_state_t *pwextBuf = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05304508 hdd_config_t *cfg_param = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004509 tCsrScanRequest scanRequest;
4510 tANI_U8 *channelList = NULL, i;
4511 v_U32_t scanId = 0;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05304512 int status;
4513 hdd_scaninfo_t *pScanInfo = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004514 v_U8_t* pP2pIe = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004515
4516 ENTER();
4517
4518 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
4519 __func__,pAdapter->device_mode);
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004520
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05304521 status = wlan_hdd_validate_context(pHddCtx);
4522
4523 if (0 != status)
4524 {
4525 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4526 "%s: HDD context is not valid", __func__);
4527 return status;
4528 }
4529
4530 cfg_param = pHddCtx->cfg_ini;
4531 pScanInfo = &pHddCtx->scan_info;
4532
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004533 if ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) &&
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004534 (eConnectionState_Connecting ==
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004535 (WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))->conn_info.connState))
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004536 {
4537 hddLog(VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08004538 "%s: %p(%d) Connection in progress: Scan request denied (EBUSY)", __func__, \
4539 WLAN_HDD_GET_STATION_CTX_PTR(pAdapter), pAdapter->sessionId);
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004540 return -EBUSY;
4541 }
4542
Jeff Johnson295189b2012-06-20 16:38:30 -07004543#ifdef WLAN_BTAMP_FEATURE
4544 //Scan not supported when AMP traffic is on.
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004545 if (VOS_TRUE == WLANBAP_AmpSessionOn())
Jeff Johnson295189b2012-06-20 16:38:30 -07004546 {
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004547 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07004548 "%s: No scanning when AMP is on", __func__);
4549 return -EOPNOTSUPP;
4550 }
4551#endif
4552 //Scan on any other interface is not supported.
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004553 if (pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07004554 {
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004555 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07004556 "%s: Not scanning on device_mode = %d",
4557 __func__, pAdapter->device_mode);
4558 return -EOPNOTSUPP;
4559 }
4560
4561 if (TRUE == pScanInfo->mScanPending)
4562 {
4563 hddLog(VOS_TRACE_LEVEL_INFO, "%s: mScanPending is TRUE", __func__);
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004564 return -EBUSY;
Jeff Johnson295189b2012-06-20 16:38:30 -07004565 }
4566
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304567 //Don't Allow Scan and return busy if Remain On
Jeff Johnson32d95a32012-09-10 13:15:23 -07004568 //Channel and action frame is pending
4569 //Otherwise Cancel Remain On Channel and allow Scan
4570 //If no action frame pending
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004571 if (0 != wlan_hdd_check_remain_on_channel(pAdapter))
Jeff Johnson32d95a32012-09-10 13:15:23 -07004572 {
4573 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Remain On Channel Pending", __func__);
4574 return -EBUSY;
4575 }
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004576#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07004577 /* if tdls disagree scan right now, return immediately.
4578 tdls will schedule the scan when scan is allowed. (return SUCCESS)
4579 or will reject the scan if any TDLS is in progress. (return -EBUSY)
4580 */
4581 status = wlan_hdd_tdls_scan_callback (pAdapter,
4582 wiphy,
4583#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
4584 dev,
Gopichand Nakkalac3c42b92013-03-20 19:42:34 -07004585#endif
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07004586 request);
4587 if(status <= 0)
4588 {
4589 hddLog(VOS_TRACE_LEVEL_INFO, "%s: TDLS Pending %d", __func__, status);
4590 return status;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004591 }
4592#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -07004593
Jeff Johnson295189b2012-06-20 16:38:30 -07004594 if (mutex_lock_interruptible(&pHddCtx->tmInfo.tmOperationLock))
4595 {
4596 VOS_TRACE(VOS_MODULE_ID_HDD,VOS_TRACE_LEVEL_ERROR,
Jeff Johnson1250df42012-12-10 14:31:52 -08004597 "%s: Acquire lock fail", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07004598 return -EAGAIN;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304599 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004600 if (TRUE == pHddCtx->tmInfo.tmAction.enterImps)
4601 {
4602 hddLog(VOS_TRACE_LEVEL_WARN,
4603 "%s: MAX TM Level Scan not allowed", __func__);
4604 mutex_unlock(&pHddCtx->tmInfo.tmOperationLock);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304605 return -EBUSY;
Jeff Johnson295189b2012-06-20 16:38:30 -07004606 }
4607 mutex_unlock(&pHddCtx->tmInfo.tmOperationLock);
4608
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004609 /* Check if scan is allowed at this point of time.
4610 */
4611 if (!hdd_isScanAllowed(pHddCtx))
4612 {
4613 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Scan not allowed", __func__);
4614 return -EBUSY;
4615 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304616
Jeff Johnson295189b2012-06-20 16:38:30 -07004617 vos_mem_zero( &scanRequest, sizeof(scanRequest));
4618
4619 if (NULL != request)
4620 {
4621 hddLog(VOS_TRACE_LEVEL_INFO, "scan request for ssid = %d",
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304622 (int)request->n_ssids);
Jeff Johnson295189b2012-06-20 16:38:30 -07004623
4624 /* Even though supplicant doesn't provide any SSIDs, n_ssids is set to 1.
4625 * Becasue of this, driver is assuming that this is not wildcard scan and so
4626 * is not aging out the scan results.
4627 */
Jeff Johnson32d95a32012-09-10 13:15:23 -07004628 if (request->ssids && '\0' == request->ssids->ssid[0])
Jeff Johnson295189b2012-06-20 16:38:30 -07004629 {
4630 request->n_ssids = 0;
4631 }
4632
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07004633 if ((request->ssids) && (0 < request->n_ssids))
Jeff Johnson295189b2012-06-20 16:38:30 -07004634 {
4635 tCsrSSIDInfo *SsidInfo;
4636 int j;
4637 scanRequest.SSIDs.numOfSSIDs = request->n_ssids;
4638 /* Allocate num_ssid tCsrSSIDInfo structure */
4639 SsidInfo = scanRequest.SSIDs.SSIDList =
4640 ( tCsrSSIDInfo *)vos_mem_malloc(
4641 request->n_ssids*sizeof(tCsrSSIDInfo));
4642
4643 if(NULL == scanRequest.SSIDs.SSIDList)
4644 {
4645 hddLog(VOS_TRACE_LEVEL_ERROR,
4646 "memory alloc failed SSIDInfo buffer");
4647 return -ENOMEM;
4648 }
4649
4650 /* copy all the ssid's and their length */
4651 for(j = 0; j < request->n_ssids; j++, SsidInfo++)
4652 {
4653 /* get the ssid length */
4654 SsidInfo->SSID.length = request->ssids[j].ssid_len;
4655 vos_mem_copy(SsidInfo->SSID.ssId, &request->ssids[j].ssid[0],
4656 SsidInfo->SSID.length);
4657 SsidInfo->SSID.ssId[SsidInfo->SSID.length] = '\0';
4658 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "SSID number %d: %s",
4659 j, SsidInfo->SSID.ssId);
4660 }
4661 /* set the scan type to active */
4662 scanRequest.scanType = eSIR_ACTIVE_SCAN;
4663 }
4664 else if(WLAN_HDD_P2P_GO == pAdapter->device_mode)
4665 {
4666 /* set the scan type to active */
4667 scanRequest.scanType = eSIR_ACTIVE_SCAN;
4668 }
4669 else
4670 {
4671 /*Set the scan type to default type, in this case it is ACTIVE*/
4672 scanRequest.scanType = pScanInfo->scan_mode;
4673 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304674 scanRequest.minChnTime = cfg_param->nActiveMinChnTime;
Jeff Johnson295189b2012-06-20 16:38:30 -07004675 scanRequest.maxChnTime = cfg_param->nActiveMaxChnTime;
4676 }
4677 else
4678 {
4679 /* set the scan type to active */
4680 scanRequest.scanType = eSIR_ACTIVE_SCAN;
4681 vos_mem_set( scanRequest.bssid, sizeof( tCsrBssid ), 0xff );
4682
4683 /* set min and max channel time to zero */
4684 scanRequest.minChnTime = 0;
4685 scanRequest.maxChnTime = 0;
4686 }
4687
4688 /* set BSSType to default type */
4689 scanRequest.BSSType = eCSR_BSS_TYPE_ANY;
4690
4691 /*TODO: scan the requested channels only*/
4692
4693 /*Right now scanning all the channels */
4694 if( request )
4695 {
4696 if( request->n_channels )
4697 {
4698 channelList = vos_mem_malloc( request->n_channels );
4699 if( NULL == channelList )
4700 {
4701 status = -ENOMEM;
4702 goto free_mem;
4703 }
4704
4705 for( i = 0 ; i < request->n_channels ; i++ )
4706 channelList[i] = request->channels[i]->hw_value;
4707 }
4708
4709 scanRequest.ChannelInfo.numOfChannels = request->n_channels;
4710 scanRequest.ChannelInfo.ChannelList = channelList;
4711
4712 /* set requestType to full scan */
4713 scanRequest.requestType = eCSR_SCAN_REQUEST_FULL_SCAN;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304714
4715 /* Flush the scan results(only p2p beacons) for STA scan and P2P
Madan Mohan Koyyalamudi8d50f312012-11-27 15:48:57 -08004716 * search (Flush on both full scan and social scan but not on single
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304717 * channel scan).P2P search happens on 3 social channels (1, 6, 11)
Madan Mohan Koyyalamudi8d50f312012-11-27 15:48:57 -08004718 */
4719
4720 /* Supplicant does single channel scan after 8-way handshake
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304721 * and in that case driver shoudnt flush scan results. If
4722 * driver flushes the scan results here and unfortunately if
4723 * the AP doesnt respond to our probe req then association
Madan Mohan Koyyalamudi8d50f312012-11-27 15:48:57 -08004724 * fails which is not desired
4725 */
4726
4727 if( request->n_channels != WLAN_HDD_P2P_SINGLE_CHANNEL_SCAN )
4728 {
4729 sme_ScanFlushP2PResult( WLAN_HDD_GET_HAL_CTX(pAdapter),
4730 pAdapter->sessionId );
4731 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004732
4733 if( request->ie_len )
4734 {
4735 /* save this for future association (join requires this) */
4736 memset( &pScanInfo->scanAddIE, 0, sizeof(pScanInfo->scanAddIE) );
4737 memcpy( pScanInfo->scanAddIE.addIEdata, request->ie, request->ie_len);
4738 pScanInfo->scanAddIE.length = request->ie_len;
4739
4740 if((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
Jeff Johnsone7245742012-09-05 17:12:55 -07004741 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) ||
4742 (WLAN_HDD_P2P_DEVICE == pAdapter->device_mode)
Jeff Johnson295189b2012-06-20 16:38:30 -07004743 )
4744 {
4745 pwextBuf->roamProfile.pAddIEScan = pScanInfo->scanAddIE.addIEdata;
4746 pwextBuf->roamProfile.nAddIEScanLength = pScanInfo->scanAddIE.length;
4747 }
4748
4749 scanRequest.uIEFieldLen = pScanInfo->scanAddIE.length;
4750 scanRequest.pIEField = pScanInfo->scanAddIE.addIEdata;
4751
Jeff Johnson295189b2012-06-20 16:38:30 -07004752 pP2pIe = wlan_hdd_get_p2p_ie_ptr((v_U8_t*)request->ie,
4753 request->ie_len);
4754 if (pP2pIe != NULL)
4755 {
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07004756#ifdef WLAN_FEATURE_P2P_DEBUG
4757 if (((globalP2PConnectionStatus == P2P_GO_NEG_COMPLETED) ||
4758 (globalP2PConnectionStatus == P2P_GO_NEG_PROCESS)) &&
4759 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
4760 {
4761 globalP2PConnectionStatus = P2P_CLIENT_CONNECTING_STATE_1;
4762 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P State] Changing state from "
4763 "Go nego completed to Connection is started");
4764 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P]P2P Scanning is started "
4765 "for 8way Handshake");
4766 }
4767 else if((globalP2PConnectionStatus == P2P_CLIENT_DISCONNECTED_STATE) &&
4768 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
4769 {
4770 globalP2PConnectionStatus = P2P_CLIENT_CONNECTING_STATE_2;
4771 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P State] Changing state from "
4772 "Disconnected state to Connection is started");
4773 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P]P2P Scanning is started "
4774 "for 4way Handshake");
4775 }
4776#endif
4777
Jeff Johnsone7245742012-09-05 17:12:55 -07004778 /* no_cck will be set during p2p find to disable 11b rates */
4779 if(TRUE == request->no_cck)
Jeff Johnson295189b2012-06-20 16:38:30 -07004780 {
Jeff Johnson295189b2012-06-20 16:38:30 -07004781 hddLog(VOS_TRACE_LEVEL_INFO,
4782 "%s: This is a P2P Search", __func__);
4783 scanRequest.p2pSearch = 1;
Jeff Johnsone7245742012-09-05 17:12:55 -07004784
Jeff Johnsone7245742012-09-05 17:12:55 -07004785 if( request->n_channels == WLAN_HDD_P2P_SOCIAL_CHANNELS )
4786 {
Madan Mohan Koyyalamudi1b1d9e82012-10-21 11:38:33 -07004787 /* set requestType to P2P Discovery */
4788 scanRequest.requestType = eCSR_SCAN_P2P_DISCOVERY;
Jeff Johnsone7245742012-09-05 17:12:55 -07004789 }
4790
4791 /*
4792 Skip Dfs Channel in case of P2P Search
4793 if it is set in ini file
4794 */
4795 if(cfg_param->skipDfsChnlInP2pSearch)
4796 {
4797 scanRequest.skipDfsChnlInP2pSearch = 1;
4798 }
4799 else
4800 {
4801 scanRequest.skipDfsChnlInP2pSearch = 0;
4802 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004803
Jeff Johnson295189b2012-06-20 16:38:30 -07004804 }
4805 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004806 }
4807 }
4808
4809 INIT_COMPLETION(pScanInfo->scan_req_completion_event);
4810
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07004811 /* acquire the wakelock to avoid the apps suspend during the scan. To
4812 * address the following issues.
4813 * 1) Disconnected scenario: we are not allowing the suspend as WLAN is not in
4814 * BMPS/IMPS this result in android trying to suspend aggressively and backing off
4815 * for long time, this result in apps running at full power for long time.
4816 * 2) Connected scenario: If we allow the suspend during the scan, RIVA will
4817 * be stuck in full power because of resume BMPS
4818 */
4819 hdd_prevent_suspend();
Jeff Johnsone7245742012-09-05 17:12:55 -07004820
4821 status = sme_ScanRequest( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07004822 pAdapter->sessionId, &scanRequest, &scanId,
4823 &hdd_cfg80211_scan_done_callback, dev );
Jeff Johnsone7245742012-09-05 17:12:55 -07004824
Jeff Johnson295189b2012-06-20 16:38:30 -07004825 if (eHAL_STATUS_SUCCESS != status)
4826 {
4827 hddLog(VOS_TRACE_LEVEL_ERROR,
4828 "%s: sme_ScanRequest returned error %d", __func__, status);
4829 complete(&pScanInfo->scan_req_completion_event);
Madan Mohan Koyyalamudi3b230fe2012-10-18 14:46:32 -07004830 if(eHAL_STATUS_RESOURCES == status)
4831 {
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07004832 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 -07004833 status = -EBUSY;
4834 } else {
4835 status = -EIO;
4836 }
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07004837 hdd_allow_suspend();
Jeff Johnson295189b2012-06-20 16:38:30 -07004838 goto free_mem;
4839 }
4840
4841 pScanInfo->mScanPending = TRUE;
4842 pAdapter->request = request;
4843 pScanInfo->scanId = scanId;
4844
4845 complete(&pScanInfo->scan_req_completion_event);
4846
4847free_mem:
4848 if( scanRequest.SSIDs.SSIDList )
4849 {
4850 vos_mem_free(scanRequest.SSIDs.SSIDList);
4851 }
4852
4853 if( channelList )
4854 vos_mem_free( channelList );
4855
4856 EXIT();
4857
4858 return status;
4859}
4860
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07004861
4862void hdd_select_cbmode( hdd_adapter_t *pAdapter,v_U8_t operationChannel)
4863{
4864 v_U8_t iniDot11Mode =
4865 (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini->dot11Mode;
4866 eHddDot11Mode hddDot11Mode = iniDot11Mode;
4867
4868 switch ( iniDot11Mode )
4869 {
4870 case eHDD_DOT11_MODE_AUTO:
4871 case eHDD_DOT11_MODE_11ac:
4872 case eHDD_DOT11_MODE_11ac_ONLY:
4873#ifdef WLAN_FEATURE_11AC
4874 hddDot11Mode = eHDD_DOT11_MODE_11ac;
4875#else
4876 hddDot11Mode = eHDD_DOT11_MODE_11n;
4877#endif
4878 break;
4879 case eHDD_DOT11_MODE_11n:
4880 case eHDD_DOT11_MODE_11n_ONLY:
4881 hddDot11Mode = eHDD_DOT11_MODE_11n;
4882 break;
4883 default:
4884 hddDot11Mode = iniDot11Mode;
4885 break;
4886 }
4887 /* This call decides required channel bonding mode */
4888 sme_SelectCBMode((WLAN_HDD_GET_CTX(pAdapter)->hHal),
4889 hdd_cfg_xlate_to_csr_phy_mode(hddDot11Mode),
4890 operationChannel);
4891}
4892
Jeff Johnson295189b2012-06-20 16:38:30 -07004893/*
4894 * FUNCTION: wlan_hdd_cfg80211_connect_start
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304895 * This function is used to start the association process
Jeff Johnson295189b2012-06-20 16:38:30 -07004896 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304897int wlan_hdd_cfg80211_connect_start( hdd_adapter_t *pAdapter,
Jeff Johnson32d95a32012-09-10 13:15:23 -07004898 const u8 *ssid, size_t ssid_len, const u8 *bssid, u8 operatingChannel)
Jeff Johnson295189b2012-06-20 16:38:30 -07004899{
4900 int status = 0;
4901 hdd_wext_state_t *pWextState;
4902 v_U32_t roamId;
4903 tCsrRoamProfile *pRoamProfile;
4904 eMib_dot11DesiredBssType connectedBssType;
4905 eCsrAuthType RSNAuthType;
4906
4907 ENTER();
4908
4909 pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304910
Jeff Johnson295189b2012-06-20 16:38:30 -07004911 if (SIR_MAC_MAX_SSID_LENGTH < ssid_len)
4912 {
4913 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: wrong SSID len", __func__);
4914 return -EINVAL;
4915 }
4916
4917 pRoamProfile = &pWextState->roamProfile;
4918
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304919 if (pRoamProfile)
Jeff Johnson295189b2012-06-20 16:38:30 -07004920 {
Jeff Johnsone7245742012-09-05 17:12:55 -07004921 int ret = 0;
4922 hdd_station_ctx_t *pHddStaCtx;
4923 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
4924 hdd_connGetConnectedBssType(pHddStaCtx,&connectedBssType );
4925
4926 if((eMib_dot11DesiredBssType_independent == connectedBssType) ||
4927 (eConnectionState_Associated == pHddStaCtx->conn_info.connState) ||
4928 (eConnectionState_IbssConnected == pHddStaCtx->conn_info.connState))
Jeff Johnson295189b2012-06-20 16:38:30 -07004929 {
4930 /* Issue disconnect to CSR */
4931 INIT_COMPLETION(pAdapter->disconnect_comp_var);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304932 if( eHAL_STATUS_SUCCESS ==
Jeff Johnson295189b2012-06-20 16:38:30 -07004933 sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
4934 pAdapter->sessionId,
4935 eCSR_DISCONNECT_REASON_UNSPECIFIED ) )
4936 {
Jeff Johnsone7245742012-09-05 17:12:55 -07004937 ret = wait_for_completion_interruptible_timeout(
4938 &pAdapter->disconnect_comp_var,
4939 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
4940 if (0 == ret)
4941 {
4942 VOS_ASSERT(0);
4943 }
4944 }
4945 }
4946 else if(eConnectionState_Disconnecting == pHddStaCtx->conn_info.connState)
4947 {
4948 ret = wait_for_completion_interruptible_timeout(
4949 &pAdapter->disconnect_comp_var,
4950 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
4951 if (0 == ret)
4952 {
4953 VOS_ASSERT(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004954 }
4955 }
4956
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304957 if (HDD_WMM_USER_MODE_NO_QOS ==
Jeff Johnson295189b2012-06-20 16:38:30 -07004958 (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini->WmmMode)
4959 {
4960 /*QoS not enabled in cfg file*/
4961 pRoamProfile->uapsd_mask = 0;
4962 }
4963 else
4964 {
4965 /*QoS enabled, update uapsd mask from cfg file*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304966 pRoamProfile->uapsd_mask =
Jeff Johnson295189b2012-06-20 16:38:30 -07004967 (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini->UapsdMask;
4968 }
4969
4970 pRoamProfile->SSIDs.numOfSSIDs = 1;
4971 pRoamProfile->SSIDs.SSIDList->SSID.length = ssid_len;
4972 vos_mem_zero(pRoamProfile->SSIDs.SSIDList->SSID.ssId,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304973 sizeof(pRoamProfile->SSIDs.SSIDList->SSID.ssId));
Jeff Johnson295189b2012-06-20 16:38:30 -07004974 vos_mem_copy((void *)(pRoamProfile->SSIDs.SSIDList->SSID.ssId),
4975 ssid, ssid_len);
4976
4977 if (bssid)
4978 {
4979 pRoamProfile->BSSIDs.numOfBSSIDs = 1;
4980 vos_mem_copy((void *)(pRoamProfile->BSSIDs.bssid), bssid,
4981 WNI_CFG_BSSID_LEN);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304982 /* Save BSSID in seperate variable as well, as RoamProfile
4983 BSSID is getting zeroed out in the association process. And in
Jeff Johnson295189b2012-06-20 16:38:30 -07004984 case of join failure we should send valid BSSID to supplicant
4985 */
4986 vos_mem_copy((void *)(pWextState->req_bssId), bssid,
4987 WNI_CFG_BSSID_LEN);
4988 }
Dhanashri Atre51981c62013-06-13 11:47:57 -07004989 else
4990 {
4991 vos_mem_zero((void *)(pRoamProfile->BSSIDs.bssid),WNI_CFG_BSSID_LEN);
4992 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004993
4994 if ((IW_AUTH_WPA_VERSION_WPA == pWextState->wpaVersion) ||
4995 (IW_AUTH_WPA_VERSION_WPA2 == pWextState->wpaVersion))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304996 {
Jeff Johnson295189b2012-06-20 16:38:30 -07004997 /*set gen ie*/
4998 hdd_SetGENIEToCsr(pAdapter, &RSNAuthType);
4999 /*set auth*/
5000 hdd_set_csr_auth_type(pAdapter, RSNAuthType);
5001 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005002#ifdef FEATURE_WLAN_WAPI
5003 if (pAdapter->wapi_info.nWapiMode)
5004 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005005 hddLog(LOG1, "%s: Setting WAPI AUTH Type and Encryption Mode values", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005006 switch (pAdapter->wapi_info.wapiAuthMode)
5007 {
5008 case WAPI_AUTH_MODE_PSK:
5009 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005010 hddLog(LOG1, "%s: WAPI AUTH TYPE: PSK: %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07005011 pAdapter->wapi_info.wapiAuthMode);
5012 pRoamProfile->AuthType.authType[0] = eCSR_AUTH_TYPE_WAPI_WAI_PSK;
5013 break;
5014 }
5015 case WAPI_AUTH_MODE_CERT:
5016 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005017 hddLog(LOG1, "%s: WAPI AUTH TYPE: CERT: %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07005018 pAdapter->wapi_info.wapiAuthMode);
5019 pRoamProfile->AuthType.authType[0] = eCSR_AUTH_TYPE_WAPI_WAI_CERTIFICATE;
5020 break;
5021 }
5022 } // End of switch
5023 if ( pAdapter->wapi_info.wapiAuthMode == WAPI_AUTH_MODE_PSK ||
5024 pAdapter->wapi_info.wapiAuthMode == WAPI_AUTH_MODE_CERT)
5025 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005026 hddLog(LOG1, "%s: WAPI PAIRWISE/GROUP ENCRYPTION: WPI", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005027 pRoamProfile->AuthType.numEntries = 1;
5028 pRoamProfile->EncryptionType.numEntries = 1;
5029 pRoamProfile->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_WPI;
5030 pRoamProfile->mcEncryptionType.numEntries = 1;
5031 pRoamProfile->mcEncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_WPI;
5032 }
5033 }
5034#endif /* FEATURE_WLAN_WAPI */
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05305035#ifdef WLAN_FEATURE_GTK_OFFLOAD
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05305036 /* Initializing gtkOffloadReqParams */
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05305037 if ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
5038 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
5039 {
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05305040 memset(&pHddStaCtx->gtkOffloadReqParams, 0,
5041 sizeof (tSirGtkOffloadParams));
5042 pHddStaCtx->gtkOffloadReqParams.ulFlags = GTK_OFFLOAD_DISABLE;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05305043 }
5044#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005045 pRoamProfile->csrPersona = pAdapter->device_mode;
5046
Jeff Johnson32d95a32012-09-10 13:15:23 -07005047 if( operatingChannel )
5048 {
5049 pRoamProfile->ChannelInfo.ChannelList = &operatingChannel;
5050 pRoamProfile->ChannelInfo.numOfChannels = 1;
5051 }
Chet Lanctot186b5732013-03-18 10:26:30 -07005052 else
5053 {
5054 pRoamProfile->ChannelInfo.ChannelList = NULL;
5055 pRoamProfile->ChannelInfo.numOfChannels = 0;
5056 }
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07005057 if ( (WLAN_HDD_IBSS == pAdapter->device_mode) && operatingChannel)
5058 {
5059 hdd_select_cbmode(pAdapter,operatingChannel);
5060 }
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08005061 /* change conn_state to connecting before sme_RoamConnect(), because sme_RoamConnect()
5062 * has a direct path to call hdd_smeRoamCallback(), which will change the conn_state
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305063 * If direct path, conn_state will be accordingly changed to NotConnected or Associated
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08005064 * by either hdd_AssociationCompletionHandler() or hdd_DisConnectHandler() in sme_RoamCallback()
Madan Mohan Koyyalamudidf86c422012-12-04 17:03:44 -08005065 * if sme_RomConnect is to be queued, Connecting state will remain until it is completed.
5066 */
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +05305067 if (WLAN_HDD_INFRA_STATION == pAdapter->device_mode ||
5068 WLAN_HDD_P2P_CLIENT == pAdapter->device_mode)
Madan Mohan Koyyalamudidf86c422012-12-04 17:03:44 -08005069 hdd_connSetConnectionState(WLAN_HDD_GET_STATION_CTX_PTR(pAdapter),
5070 eConnectionState_Connecting);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305071
5072 status = sme_RoamConnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07005073 pAdapter->sessionId, pRoamProfile, &roamId);
5074
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +05305075 if ((eHAL_STATUS_SUCCESS != status) &&
5076 (WLAN_HDD_INFRA_STATION == pAdapter->device_mode ||
5077 WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
Madan Mohan Koyyalamudid5acbf52012-11-28 01:45:08 +05305078
5079 {
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08005080 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: sme_RoamConnect (session %d) failed with "
5081 "status %d. -> NotConnected", __func__, pAdapter->sessionId, status);
5082 /* change back to NotAssociated */
Madan Mohan Koyyalamudid5acbf52012-11-28 01:45:08 +05305083 hdd_connSetConnectionState(WLAN_HDD_GET_STATION_CTX_PTR(pAdapter),
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08005084 eConnectionState_NotConnected);
Madan Mohan Koyyalamudid5acbf52012-11-28 01:45:08 +05305085 }
Madan Mohan Koyyalamudidf86c422012-12-04 17:03:44 -08005086
5087 pRoamProfile->ChannelInfo.ChannelList = NULL;
5088 pRoamProfile->ChannelInfo.numOfChannels = 0;
5089
Jeff Johnson295189b2012-06-20 16:38:30 -07005090 }
5091 else
5092 {
5093 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: No valid Roam profile", __func__);
5094 return -EINVAL;
5095 }
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08005096 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07005097 return status;
5098}
5099
5100/*
5101 * FUNCTION: wlan_hdd_set_cfg80211_auth_type
5102 * This function is used to set the authentication type (OPEN/SHARED).
5103 *
5104 */
5105static int wlan_hdd_cfg80211_set_auth_type(hdd_adapter_t *pAdapter,
5106 enum nl80211_auth_type auth_type)
5107{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305108 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07005109 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
5110
5111 ENTER();
5112
5113 /*set authentication type*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305114 switch (auth_type)
Jeff Johnson295189b2012-06-20 16:38:30 -07005115 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005116 case NL80211_AUTHTYPE_AUTOMATIC:
Gopichand Nakkala29149562013-05-10 21:43:41 +05305117 hddLog(VOS_TRACE_LEVEL_INFO,
5118 "%s: set authentication type to AUTOSWITCH", __func__);
5119 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_AUTOSWITCH;
5120 break;
5121
5122 case NL80211_AUTHTYPE_OPEN_SYSTEM:
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07005123#ifdef WLAN_FEATURE_VOWIFI_11R
5124 case NL80211_AUTHTYPE_FT:
5125#endif /* WLAN_FEATURE_VOWIFI_11R */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305126 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07005127 "%s: set authentication type to OPEN", __func__);
5128 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
5129 break;
5130
5131 case NL80211_AUTHTYPE_SHARED_KEY:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305132 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07005133 "%s: set authentication type to SHARED", __func__);
5134 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_SHARED_KEY;
5135 break;
5136#ifdef FEATURE_WLAN_CCX
5137 case NL80211_AUTHTYPE_NETWORK_EAP:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305138 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07005139 "%s: set authentication type to CCKM WPA", __func__);
5140 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_CCKM_WPA;//eCSR_AUTH_TYPE_CCKM_RSN needs to be handled as well if required.
5141 break;
5142#endif
5143
5144
5145 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305146 hddLog(VOS_TRACE_LEVEL_ERROR,
5147 "%s: Unsupported authentication type %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07005148 auth_type);
5149 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_UNKNOWN;
5150 return -EINVAL;
5151 }
5152
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305153 pWextState->roamProfile.AuthType.authType[0] =
Jeff Johnson295189b2012-06-20 16:38:30 -07005154 pHddStaCtx->conn_info.authType;
5155 return 0;
5156}
5157
5158/*
5159 * FUNCTION: wlan_hdd_set_akm_suite
5160 * This function is used to set the key mgmt type(PSK/8021x).
5161 *
5162 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305163static int wlan_hdd_set_akm_suite( hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07005164 u32 key_mgmt
5165 )
5166{
5167 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
5168 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305169
Jeff Johnson295189b2012-06-20 16:38:30 -07005170 /*set key mgmt type*/
5171 switch(key_mgmt)
5172 {
5173 case WLAN_AKM_SUITE_PSK:
Gopichand Nakkala356fb102013-03-06 12:34:04 +05305174#ifdef WLAN_FEATURE_VOWIFI_11R
5175 case WLAN_AKM_SUITE_FT_PSK:
5176#endif
5177 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting key mgmt type to PSK",
Jeff Johnson295189b2012-06-20 16:38:30 -07005178 __func__);
5179 pWextState->authKeyMgmt |= IW_AUTH_KEY_MGMT_PSK;
5180 break;
5181
5182 case WLAN_AKM_SUITE_8021X:
Gopichand Nakkala356fb102013-03-06 12:34:04 +05305183#ifdef WLAN_FEATURE_VOWIFI_11R
5184 case WLAN_AKM_SUITE_FT_8021X:
5185#endif
5186 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting key mgmt type to 8021x",
Jeff Johnson295189b2012-06-20 16:38:30 -07005187 __func__);
5188 pWextState->authKeyMgmt |= IW_AUTH_KEY_MGMT_802_1X;
5189 break;
5190#ifdef FEATURE_WLAN_CCX
5191#define WLAN_AKM_SUITE_CCKM 0x00409600 /* Should be in ieee802_11_defs.h */
5192#define IW_AUTH_KEY_MGMT_CCKM 8 /* Should be in linux/wireless.h */
5193 case WLAN_AKM_SUITE_CCKM:
5194 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting key mgmt type to CCKM",
5195 __func__);
5196 pWextState->authKeyMgmt |= IW_AUTH_KEY_MGMT_CCKM;
5197 break;
5198#endif
5199
5200 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305201 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported key mgmt type %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005202 __func__, key_mgmt);
5203 return -EINVAL;
5204
5205 }
5206 return 0;
5207}
5208
5209/*
5210 * FUNCTION: wlan_hdd_cfg80211_set_cipher
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305211 * This function is used to set the encryption type
Jeff Johnson295189b2012-06-20 16:38:30 -07005212 * (NONE/WEP40/WEP104/TKIP/CCMP).
5213 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305214static int wlan_hdd_cfg80211_set_cipher( hdd_adapter_t *pAdapter,
5215 u32 cipher,
Jeff Johnson295189b2012-06-20 16:38:30 -07005216 bool ucast
5217 )
5218{
5219 eCsrEncryptionType encryptionType = eCSR_ENCRYPT_TYPE_NONE;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305220 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07005221 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
5222
5223 ENTER();
5224
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305225 if (!cipher)
Jeff Johnson295189b2012-06-20 16:38:30 -07005226 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305227 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: received cipher %d - considering none",
Jeff Johnson295189b2012-06-20 16:38:30 -07005228 __func__, cipher);
5229 encryptionType = eCSR_ENCRYPT_TYPE_NONE;
5230 }
5231 else
5232 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305233
Jeff Johnson295189b2012-06-20 16:38:30 -07005234 /*set encryption method*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305235 switch (cipher)
Jeff Johnson295189b2012-06-20 16:38:30 -07005236 {
5237 case IW_AUTH_CIPHER_NONE:
5238 encryptionType = eCSR_ENCRYPT_TYPE_NONE;
5239 break;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305240
Jeff Johnson295189b2012-06-20 16:38:30 -07005241 case WLAN_CIPHER_SUITE_WEP40:
Gopichand Nakkala29149562013-05-10 21:43:41 +05305242 encryptionType = eCSR_ENCRYPT_TYPE_WEP40;
Jeff Johnson295189b2012-06-20 16:38:30 -07005243 break;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305244
Jeff Johnson295189b2012-06-20 16:38:30 -07005245 case WLAN_CIPHER_SUITE_WEP104:
Gopichand Nakkala29149562013-05-10 21:43:41 +05305246 encryptionType = eCSR_ENCRYPT_TYPE_WEP104;
Jeff Johnson295189b2012-06-20 16:38:30 -07005247 break;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305248
Jeff Johnson295189b2012-06-20 16:38:30 -07005249 case WLAN_CIPHER_SUITE_TKIP:
5250 encryptionType = eCSR_ENCRYPT_TYPE_TKIP;
5251 break;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305252
Jeff Johnson295189b2012-06-20 16:38:30 -07005253 case WLAN_CIPHER_SUITE_CCMP:
5254 encryptionType = eCSR_ENCRYPT_TYPE_AES;
5255 break;
5256#ifdef FEATURE_WLAN_WAPI
5257 case WLAN_CIPHER_SUITE_SMS4:
5258 encryptionType = eCSR_ENCRYPT_TYPE_WPI;
5259 break;
5260#endif
5261
5262#ifdef FEATURE_WLAN_CCX
5263 case WLAN_CIPHER_SUITE_KRK:
5264 encryptionType = eCSR_ENCRYPT_TYPE_KRK;
5265 break;
5266#endif
5267 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305268 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported cipher type %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005269 __func__, cipher);
5270 return -EOPNOTSUPP;
5271 }
5272 }
5273
5274 if (ucast)
5275 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305276 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting unicast cipher type to %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005277 __func__, encryptionType);
5278 pHddStaCtx->conn_info.ucEncryptionType = encryptionType;
5279 pWextState->roamProfile.EncryptionType.numEntries = 1;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305280 pWextState->roamProfile.EncryptionType.encryptionType[0] =
Jeff Johnson295189b2012-06-20 16:38:30 -07005281 encryptionType;
5282 }
5283 else
5284 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305285 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting mcast cipher type to %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005286 __func__, encryptionType);
5287 pHddStaCtx->conn_info.mcEncryptionType = encryptionType;
5288 pWextState->roamProfile.mcEncryptionType.numEntries = 1;
5289 pWextState->roamProfile.mcEncryptionType.encryptionType[0] = encryptionType;
5290 }
5291
5292 return 0;
5293}
5294
5295
5296/*
5297 * FUNCTION: wlan_hdd_cfg80211_set_ie
5298 * This function is used to parse WPA/RSN IE's.
5299 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305300int wlan_hdd_cfg80211_set_ie( hdd_adapter_t *pAdapter,
5301 u8 *ie,
Jeff Johnson295189b2012-06-20 16:38:30 -07005302 size_t ie_len
5303 )
5304{
5305 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
5306 u8 *genie = ie;
5307 v_U16_t remLen = ie_len;
5308#ifdef FEATURE_WLAN_WAPI
5309 v_U32_t akmsuite[MAX_NUM_AKM_SUITES];
5310 u16 *tmp;
5311 v_U16_t akmsuiteCount;
5312 int *akmlist;
5313#endif
5314 ENTER();
5315
5316 /* clear previous assocAddIE */
5317 pWextState->assocAddIE.length = 0;
5318 pWextState->roamProfile.bWPSAssociation = VOS_FALSE;
5319
5320 while (remLen >= 2)
5321 {
5322 v_U16_t eLen = 0;
5323 v_U8_t elementId;
5324 elementId = *genie++;
5325 eLen = *genie++;
5326 remLen -= 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305327
5328 hddLog(VOS_TRACE_LEVEL_INFO, "%s: IE[0x%X], LEN[%d]\n",
Jeff Johnson295189b2012-06-20 16:38:30 -07005329 __func__, elementId, eLen);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305330
5331 switch ( elementId )
Jeff Johnson295189b2012-06-20 16:38:30 -07005332 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305333 case DOT11F_EID_WPA:
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005334 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 -07005335 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305336 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005337 "%s: Invalid WPA IE", __func__);
5338 return -EINVAL;
5339 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305340 else if (0 == memcmp(&genie[0], "\x00\x50\xf2\x04", 4))
Jeff Johnson295189b2012-06-20 16:38:30 -07005341 {
5342 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305343 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set WPS IE(len %d)",
Jeff Johnson295189b2012-06-20 16:38:30 -07005344 __func__, eLen + 2);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305345
Jeff Johnson295189b2012-06-20 16:38:30 -07005346 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5347 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005348 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE. "
5349 "Need bigger buffer space");
Jeff Johnson295189b2012-06-20 16:38:30 -07005350 VOS_ASSERT(0);
5351 return -ENOMEM;
5352 }
5353 // WSC IE is saved to Additional IE ; it should be accumulated to handle WPS IE + P2P IE
5354 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5355 pWextState->assocAddIE.length += eLen + 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305356
Jeff Johnson295189b2012-06-20 16:38:30 -07005357 pWextState->roamProfile.bWPSAssociation = VOS_TRUE;
5358 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5359 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5360 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305361 else if (0 == memcmp(&genie[0], "\x00\x50\xf2", 3))
5362 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005363 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set WPA IE (len %d)",__func__, eLen + 2);
5364 memset( pWextState->WPARSNIE, 0, MAX_WPA_RSN_IE_LEN );
5365 memcpy( pWextState->WPARSNIE, genie - 2, (eLen + 2) /*ie_len*/);
5366 pWextState->roamProfile.pWPAReqIE = pWextState->WPARSNIE;
5367 pWextState->roamProfile.nWPAReqIELength = eLen + 2;//ie_len;
5368 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305369 else if ( (0 == memcmp(&genie[0], P2P_OUI_TYPE,
5370 P2P_OUI_TYPE_SIZE))
Jeff Johnson295189b2012-06-20 16:38:30 -07005371 /*Consider P2P IE, only for P2P Client */
5372 && (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) )
5373 {
5374 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305375 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set P2P IE(len %d)",
Jeff Johnson295189b2012-06-20 16:38:30 -07005376 __func__, eLen + 2);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305377
Jeff Johnson295189b2012-06-20 16:38:30 -07005378 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5379 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005380 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
5381 "Need bigger buffer space");
Jeff Johnson295189b2012-06-20 16:38:30 -07005382 VOS_ASSERT(0);
5383 return -ENOMEM;
5384 }
5385 // P2P IE is saved to Additional IE ; it should be accumulated to handle WPS IE + P2P IE
5386 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5387 pWextState->assocAddIE.length += eLen + 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305388
Jeff Johnson295189b2012-06-20 16:38:30 -07005389 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5390 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5391 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005392#ifdef WLAN_FEATURE_WFD
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305393 else if ( (0 == memcmp(&genie[0], WFD_OUI_TYPE,
5394 WFD_OUI_TYPE_SIZE))
Jeff Johnson295189b2012-06-20 16:38:30 -07005395 /*Consider WFD IE, only for P2P Client */
5396 && (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) )
5397 {
5398 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305399 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set WFD IE(len %d)",
Jeff Johnson295189b2012-06-20 16:38:30 -07005400 __func__, eLen + 2);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305401
Jeff Johnson295189b2012-06-20 16:38:30 -07005402 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5403 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005404 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
5405 "Need bigger buffer space");
Jeff Johnson295189b2012-06-20 16:38:30 -07005406 VOS_ASSERT(0);
5407 return -ENOMEM;
5408 }
5409 // WFD IE is saved to Additional IE ; it should be accumulated to handle
5410 // WPS IE + P2P IE + WFD IE
5411 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5412 pWextState->assocAddIE.length += eLen + 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305413
Jeff Johnson295189b2012-06-20 16:38:30 -07005414 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5415 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5416 }
5417#endif
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005418 /* Appending HS 2.0 Indication Element in Assiciation Request */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305419 else if ( (0 == memcmp(&genie[0], HS20_OUI_TYPE,
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005420 HS20_OUI_TYPE_SIZE)) )
5421 {
5422 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305423 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set HS20 IE(len %d)",
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005424 __func__, eLen + 2);
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005425
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005426 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5427 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005428 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
5429 "Need bigger buffer space");
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005430 VOS_ASSERT(0);
5431 return -ENOMEM;
5432 }
5433 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5434 pWextState->assocAddIE.length += eLen + 2;
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005435
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005436 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5437 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5438 }
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005439
Jeff Johnson295189b2012-06-20 16:38:30 -07005440 break;
5441 case DOT11F_EID_RSN:
5442 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set RSN IE(len %d)",__func__, eLen + 2);
5443 memset( pWextState->WPARSNIE, 0, MAX_WPA_RSN_IE_LEN );
5444 memcpy( pWextState->WPARSNIE, genie - 2, (eLen + 2)/*ie_len*/);
5445 pWextState->roamProfile.pRSNReqIE = pWextState->WPARSNIE;
5446 pWextState->roamProfile.nRSNReqIELength = eLen + 2; //ie_len;
5447 break;
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005448 /* Appending Extended Capabilities with Interworking bit set in Assoc Req */
5449 case DOT11F_EID_EXTCAP:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305450 {
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005451 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305452 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set Extended CAPS IE(len %d)",
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005453 __func__, eLen + 2);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305454
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005455 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5456 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005457 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
5458 "Need bigger buffer space");
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005459 VOS_ASSERT(0);
5460 return -ENOMEM;
5461 }
5462 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5463 pWextState->assocAddIE.length += eLen + 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305464
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005465 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5466 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5467 break;
5468 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005469#ifdef FEATURE_WLAN_WAPI
5470 case WLAN_EID_WAPI:
5471 pAdapter->wapi_info.nWapiMode = 1; //Setting WAPI Mode to ON=1
5472 hddLog(VOS_TRACE_LEVEL_INFO,"WAPI MODE IS %lu \n",
5473 pAdapter->wapi_info.nWapiMode);
5474 tmp = (u16 *)ie;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305475 tmp = tmp + 2; // Skip element Id and Len, Version
Jeff Johnson295189b2012-06-20 16:38:30 -07005476 akmsuiteCount = WPA_GET_LE16(tmp);
5477 tmp = tmp + 1;
5478 akmlist = (int *)(tmp);
5479 if(akmsuiteCount <= MAX_NUM_AKM_SUITES)
5480 {
5481 memcpy(akmsuite, akmlist, (4*akmsuiteCount));
5482 }
5483 else
5484 {
5485 hddLog(VOS_TRACE_LEVEL_FATAL, "Invalid akmSuite count\n");
5486 VOS_ASSERT(0);
5487 return -EINVAL;
5488 }
5489
5490 if (WAPI_PSK_AKM_SUITE == akmsuite[0])
5491 {
5492 hddLog(VOS_TRACE_LEVEL_INFO, "%s: WAPI AUTH MODE SET TO PSK",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005493 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005494 pAdapter->wapi_info.wapiAuthMode = WAPI_AUTH_MODE_PSK;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305495 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005496 if (WAPI_CERT_AKM_SUITE == akmsuite[0])
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305497 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005498 hddLog(VOS_TRACE_LEVEL_INFO, "%s: WAPI AUTH MODE SET TO CERTIFICATE",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005499 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005500 pAdapter->wapi_info.wapiAuthMode = WAPI_AUTH_MODE_CERT;
5501 }
5502 break;
5503#endif
5504 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305505 hddLog (VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005506 "%s Set UNKNOWN IE %X", __func__, elementId);
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005507 /* when Unknown IE is received we should break and continue
5508 * to the next IE in the buffer instead we were returning
5509 * so changing this to break */
5510 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07005511 }
5512 genie += eLen;
5513 remLen -= eLen;
5514 }
5515 EXIT();
5516 return 0;
5517}
5518
5519/*
Gopichand Nakkala18f0c262013-05-07 23:25:08 +05305520 * FUNCTION: hdd_isWPAIEPresent
5521 * Parse the received IE to find the WPA IE
5522 *
5523 */
5524static bool hdd_isWPAIEPresent(u8 *ie, u8 ie_len)
5525{
5526 v_U8_t eLen = 0;
5527 v_U16_t remLen = ie_len;
5528 v_U8_t elementId = 0;
5529
5530 while (remLen >= 2)
5531 {
5532 elementId = *ie++;
5533 eLen = *ie++;
5534 remLen -= 2;
5535 if (eLen > remLen)
5536 {
5537 hddLog(VOS_TRACE_LEVEL_ERROR,
5538 "%s: IE length is wrong %d", __func__, eLen);
5539 return FALSE;
5540 }
5541 if ((elementId == DOT11F_EID_WPA) && (remLen > 5))
5542 {
5543 /* OUI - 0x00 0X50 0XF2
5544 WPA Information Element - 0x01
5545 WPA version - 0x01*/
5546 if (0 == memcmp(&ie[0], "\x00\x50\xf2\x01\x01", 5))
5547 return TRUE;
5548 }
5549 ie += eLen;
5550 remLen -= eLen;
5551 }
5552 return FALSE;
5553}
5554
5555/*
Jeff Johnson295189b2012-06-20 16:38:30 -07005556 * FUNCTION: wlan_hdd_cfg80211_set_privacy
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305557 * This function is used to initialize the security
Jeff Johnson295189b2012-06-20 16:38:30 -07005558 * parameters during connect operation.
5559 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305560int wlan_hdd_cfg80211_set_privacy( hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07005561 struct cfg80211_connect_params *req
5562 )
5563{
5564 int status = 0;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305565 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07005566 ENTER();
5567
5568 /*set wpa version*/
5569 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_DISABLED;
5570
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305571 if (req->crypto.wpa_versions)
Jeff Johnson295189b2012-06-20 16:38:30 -07005572 {
Gopichand Nakkala781ded42013-06-28 12:10:45 +05305573 if (NL80211_WPA_VERSION_1 == req->crypto.wpa_versions)
Jeff Johnson295189b2012-06-20 16:38:30 -07005574 {
5575 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA;
5576 }
5577 else if (NL80211_WPA_VERSION_2 == req->crypto.wpa_versions)
5578 {
5579 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA2;
5580 }
5581 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305582
5583 hddLog(VOS_TRACE_LEVEL_INFO, "%s: set wpa version to %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07005584 pWextState->wpaVersion);
5585
5586 /*set authentication type*/
5587 status = wlan_hdd_cfg80211_set_auth_type(pAdapter, req->auth_type);
5588
5589 if (0 > status)
5590 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305591 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005592 "%s: failed to set authentication type ", __func__);
5593 return status;
5594 }
5595
5596 /*set key mgmt type*/
5597 if (req->crypto.n_akm_suites)
5598 {
5599 status = wlan_hdd_set_akm_suite(pAdapter, req->crypto.akm_suites[0]);
5600 if (0 > status)
5601 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305602 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set akm suite",
Jeff Johnson295189b2012-06-20 16:38:30 -07005603 __func__);
5604 return status;
5605 }
5606 }
5607
5608 /*set pairwise cipher type*/
5609 if (req->crypto.n_ciphers_pairwise)
5610 {
5611 status = wlan_hdd_cfg80211_set_cipher(pAdapter,
5612 req->crypto.ciphers_pairwise[0], true);
5613 if (0 > status)
5614 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305615 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005616 "%s: failed to set unicast cipher type", __func__);
5617 return status;
5618 }
5619 }
5620 else
5621 {
5622 /*Reset previous cipher suite to none*/
5623 status = wlan_hdd_cfg80211_set_cipher(pAdapter, 0, true);
5624 if (0 > status)
5625 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305626 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005627 "%s: failed to set unicast cipher type", __func__);
5628 return status;
5629 }
5630 }
5631
5632 /*set group cipher type*/
5633 status = wlan_hdd_cfg80211_set_cipher(pAdapter, req->crypto.cipher_group,
5634 false);
5635
5636 if (0 > status)
5637 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305638 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set mcast cipher type",
Jeff Johnson295189b2012-06-20 16:38:30 -07005639 __func__);
5640 return status;
5641 }
5642
Chet Lanctot186b5732013-03-18 10:26:30 -07005643#ifdef WLAN_FEATURE_11W
5644 pWextState->roamProfile.MFPEnabled = (req->mfp == NL80211_MFP_REQUIRED);
5645#endif
5646
Jeff Johnson295189b2012-06-20 16:38:30 -07005647 /*parse WPA/RSN IE, and set the correspoing fileds in Roam profile*/
5648 if (req->ie_len)
5649 {
5650 status = wlan_hdd_cfg80211_set_ie(pAdapter, req->ie, req->ie_len);
5651 if ( 0 > status)
5652 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305653 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to parse the WPA/RSN IE",
Jeff Johnson295189b2012-06-20 16:38:30 -07005654 __func__);
5655 return status;
5656 }
5657 }
5658
5659 /*incase of WEP set default key information*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305660 if (req->key && req->key_len)
Jeff Johnson295189b2012-06-20 16:38:30 -07005661 {
5662 if ( (WLAN_CIPHER_SUITE_WEP40 == req->crypto.ciphers_pairwise[0])
5663 || (WLAN_CIPHER_SUITE_WEP104 == req->crypto.ciphers_pairwise[0])
5664 )
5665 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305666 if ( IW_AUTH_KEY_MGMT_802_1X
Jeff Johnson295189b2012-06-20 16:38:30 -07005667 == (pWextState->authKeyMgmt & IW_AUTH_KEY_MGMT_802_1X ))
5668 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305669 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Dynamic WEP not supported",
Jeff Johnson295189b2012-06-20 16:38:30 -07005670 __func__);
5671 return -EOPNOTSUPP;
5672 }
5673 else
5674 {
5675 u8 key_len = req->key_len;
5676 u8 key_idx = req->key_idx;
5677
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305678 if ((eCSR_SECURITY_WEP_KEYSIZE_MAX_BYTES >= key_len)
Jeff Johnson295189b2012-06-20 16:38:30 -07005679 && (CSR_MAX_NUM_KEY > key_idx)
5680 )
5681 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305682 hddLog(VOS_TRACE_LEVEL_INFO,
5683 "%s: setting default wep key, key_idx = %hu key_len %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07005684 __func__, key_idx, key_len);
5685 vos_mem_copy(
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305686 &pWextState->roamProfile.Keys.KeyMaterial[key_idx][0],
Jeff Johnson295189b2012-06-20 16:38:30 -07005687 req->key, key_len);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305688 pWextState->roamProfile.Keys.KeyLength[key_idx] =
Jeff Johnson295189b2012-06-20 16:38:30 -07005689 (u8)key_len;
5690 pWextState->roamProfile.Keys.defaultIndex = (u8)key_idx;
5691 }
5692 }
5693 }
5694 }
5695
5696 return status;
5697}
5698
5699/*
5700 * FUNCTION: wlan_hdd_cfg80211_set_privacy
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305701 * This function is used to initialize the security
Jeff Johnson295189b2012-06-20 16:38:30 -07005702 * parameters during connect operation.
5703 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305704static int wlan_hdd_cfg80211_connect( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07005705 struct net_device *ndev,
5706 struct cfg80211_connect_params *req
5707 )
5708{
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305709 int status;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305710 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Jeff Johnson295189b2012-06-20 16:38:30 -07005711 VOS_STATUS exitbmpsStatus = VOS_STATUS_E_INVAL;
5712 hdd_context_t *pHddCtx = NULL;
5713
5714 ENTER();
5715
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305716 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07005717 "%s: device_mode = %d\n",__func__,pAdapter->device_mode);
5718
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305719 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
5720 status = wlan_hdd_validate_context(pHddCtx);
5721
5722 if (0 != status)
Jeff Johnson295189b2012-06-20 16:38:30 -07005723 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305724 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5725 "%s: HDD context is not valid", __func__);
5726 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07005727 }
5728
5729#ifdef WLAN_BTAMP_FEATURE
5730 //Infra connect not supported when AMP traffic is on.
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305731 if( VOS_TRUE == WLANBAP_AmpSessionOn() )
Jeff Johnson295189b2012-06-20 16:38:30 -07005732 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305733 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005734 "%s: No connection when AMP is on", __func__);
Madan Mohan Koyyalamudicae253a2012-11-06 19:10:35 -08005735 return -ECONNREFUSED;
Jeff Johnson295189b2012-06-20 16:38:30 -07005736 }
5737#endif
5738 /*initialise security parameters*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305739 status = wlan_hdd_cfg80211_set_privacy(pAdapter, req);
Jeff Johnson295189b2012-06-20 16:38:30 -07005740
5741 if ( 0 > status)
5742 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305743 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set security params",
Jeff Johnson295189b2012-06-20 16:38:30 -07005744 __func__);
5745 return status;
5746 }
5747
5748 //If Device Mode is Station Concurrent Sessions Exit BMps
Jeff Johnsona8a1a482012-12-12 16:49:33 -08005749 //P2P Mode will be taken care in Open/close adapter
Jeff Johnson295189b2012-06-20 16:38:30 -07005750 if((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) &&
5751 (vos_concurrent_sessions_running()))
5752 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305753 exitbmpsStatus = hdd_disable_bmps_imps(pHddCtx, WLAN_HDD_INFRA_STATION);
Jeff Johnson295189b2012-06-20 16:38:30 -07005754 }
5755
Mohit Khanna765234a2012-09-11 15:08:35 -07005756 if ( req->channel )
5757 {
5758 status = wlan_hdd_cfg80211_connect_start(pAdapter, req->ssid,
5759 req->ssid_len, req->bssid,
5760 req->channel->hw_value);
5761 }
5762 else
5763 {
5764 status = wlan_hdd_cfg80211_connect_start(pAdapter, req->ssid,
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305765 req->ssid_len, req->bssid, 0);
Mohit Khanna765234a2012-09-11 15:08:35 -07005766 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005767
5768 if (0 > status)
5769 {
5770 //ReEnable BMPS if disabled
5771 if((VOS_STATUS_SUCCESS == exitbmpsStatus) &&
5772 (NULL != pHddCtx))
5773 {
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05305774 if (pHddCtx->hdd_wlan_suspended)
5775 {
5776 hdd_set_pwrparams(pHddCtx);
5777 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005778 //ReEnable Bmps and Imps back
5779 hdd_enable_bmps_imps(pHddCtx);
5780 }
5781
5782 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: connect failed", __func__);
5783 return status;
5784 }
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305785 pHddCtx->isAmpAllowed = VOS_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005786 EXIT();
5787 return status;
5788}
5789
5790
5791/*
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05305792 * FUNCTION: wlan_hdd_disconnect
5793 * This function is used to issue a disconnect request to SME
5794 */
5795int wlan_hdd_disconnect( hdd_adapter_t *pAdapter, u16 reason )
5796{
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305797 int status;
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05305798 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305799 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
5800
5801 status = wlan_hdd_validate_context(pHddCtx);
5802
5803 if (0 != status)
5804 {
5805 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5806 "%s: HDD context is not valid", __func__);
5807 return status;
5808 }
5809
5810 pHddCtx->isAmpAllowed = VOS_TRUE;
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05305811 pHddStaCtx->conn_info.connState = eConnectionState_NotConnected;
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05305812 INIT_COMPLETION(pAdapter->disconnect_comp_var);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305813
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05305814 /*issue disconnect*/
5815 status = sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
5816 pAdapter->sessionId, reason);
5817
5818 if ( 0 != status )
5819 {
5820 hddLog(VOS_TRACE_LEVEL_ERROR,
5821 "%s csrRoamDisconnect failure, returned %d \n",
5822 __func__, (int)status );
5823 return -EINVAL;
5824 }
5825 wait_for_completion_interruptible_timeout(
5826 &pAdapter->disconnect_comp_var,
5827 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
5828 /*stop tx queues*/
5829 netif_tx_disable(pAdapter->dev);
5830 netif_carrier_off(pAdapter->dev);
5831 return status;
5832}
5833
5834
5835/*
Jeff Johnson295189b2012-06-20 16:38:30 -07005836 * FUNCTION: wlan_hdd_cfg80211_disconnect
5837 * This function is used to issue a disconnect request to SME
5838 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305839static int wlan_hdd_cfg80211_disconnect( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07005840 struct net_device *dev,
5841 u16 reason
5842 )
5843{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305844 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
5845 tCsrRoamProfile *pRoamProfile =
Jeff Johnson295189b2012-06-20 16:38:30 -07005846 &(WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter))->roamProfile;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305847 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07005848 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkala4327a152013-03-04 23:22:42 -08005849 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05305850#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08005851 tANI_U8 staIdx;
5852#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305853
Jeff Johnson295189b2012-06-20 16:38:30 -07005854 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305855
5856 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
Jeff Johnson295189b2012-06-20 16:38:30 -07005857 __func__,pAdapter->device_mode);
5858
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305859 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Disconnect called with reason code %d",
5860 __func__, reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07005861
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305862 status = wlan_hdd_validate_context(pHddCtx);
5863
5864 if (0 != status)
Jeff Johnson295189b2012-06-20 16:38:30 -07005865 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305866 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5867 "%s: HDD context is not valid", __func__);
5868 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07005869 }
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305870
Jeff Johnson295189b2012-06-20 16:38:30 -07005871 if (NULL != pRoamProfile)
5872 {
5873 /*issue disconnect request to SME, if station is in connected state*/
5874 if (pHddStaCtx->conn_info.connState == eConnectionState_Associated)
5875 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305876 eCsrRoamDisconnectReason reasonCode =
Jeff Johnson295189b2012-06-20 16:38:30 -07005877 eCSR_DISCONNECT_REASON_UNSPECIFIED;
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05305878 hdd_scaninfo_t *pScanInfo;
Jeff Johnson295189b2012-06-20 16:38:30 -07005879 switch(reason)
5880 {
5881 case WLAN_REASON_MIC_FAILURE:
5882 reasonCode = eCSR_DISCONNECT_REASON_MIC_ERROR;
5883 break;
5884
5885 case WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY:
5886 case WLAN_REASON_DISASSOC_AP_BUSY:
5887 case WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA:
5888 reasonCode = eCSR_DISCONNECT_REASON_DISASSOC;
5889 break;
5890
5891 case WLAN_REASON_PREV_AUTH_NOT_VALID:
5892 case WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA:
5893 reasonCode = eCSR_DISCONNECT_REASON_DEAUTH;
5894 break;
5895
5896 case WLAN_REASON_DEAUTH_LEAVING:
5897 default:
5898 reasonCode = eCSR_DISCONNECT_REASON_UNSPECIFIED;
5899 break;
5900 }
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05305901 pHddStaCtx->conn_info.connState = eConnectionState_NotConnected;
5902 pScanInfo = &pHddCtx->scan_info;
5903 if (pScanInfo->mScanPending)
5904 {
5905 hddLog(VOS_TRACE_LEVEL_INFO, "Disconnect is in progress, "
5906 "Aborting Scan");
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05305907 hdd_abort_mac_scan(pHddCtx, pAdapter->sessionId);
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05305908 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005909
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08005910#ifdef FEATURE_WLAN_TDLS
5911 /* First clean up the tdls peers if any */
Gopichand Nakkala4327a152013-03-04 23:22:42 -08005912 for (staIdx = 0 ; staIdx < HDD_MAX_NUM_TDLS_STA; staIdx++)
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08005913 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08005914 if ((pHddCtx->tdlsConnInfo[staIdx].sessionId == pAdapter->sessionId) &&
5915 (pHddCtx->tdlsConnInfo[staIdx].staId))
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08005916 {
Hoonki Lee11f7dda2013-02-14 16:55:44 -08005917 uint8 *mac;
Gopichand Nakkala4327a152013-03-04 23:22:42 -08005918 mac = pHddCtx->tdlsConnInfo[staIdx].peerMac.bytes;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08005919 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07005920 "%s: call sme_DeleteTdlsPeerSta staId %d sessionId %d " MAC_ADDRESS_STR,
Gopichand Nakkala4327a152013-03-04 23:22:42 -08005921 __func__, pHddCtx->tdlsConnInfo[staIdx].staId, pAdapter->sessionId,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07005922 MAC_ADDR_ARRAY(mac));
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08005923 sme_DeleteTdlsPeerSta(WLAN_HDD_GET_HAL_CTX(pAdapter),
Gopichand Nakkala4327a152013-03-04 23:22:42 -08005924 pAdapter->sessionId,
5925 mac);
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08005926 }
5927 }
5928#endif
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05305929 status = wlan_hdd_disconnect(pAdapter, reasonCode);
5930 if ( 0 != status )
Jeff Johnson295189b2012-06-20 16:38:30 -07005931 {
5932 hddLog(VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05305933 "%s wlan_hdd_disconnect failure, returned %d \n",
Jeff Johnson295189b2012-06-20 16:38:30 -07005934 __func__, (int)status );
5935 return -EINVAL;
5936 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005937 }
5938 }
5939 else
5940 {
5941 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: No valid roam profile", __func__);
5942 }
5943
5944 return status;
5945}
5946
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05305947
Jeff Johnson295189b2012-06-20 16:38:30 -07005948/*
5949 * FUNCTION: wlan_hdd_cfg80211_set_privacy_ibss
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305950 * This function is used to initialize the security
Jeff Johnson295189b2012-06-20 16:38:30 -07005951 * settings in IBSS mode.
5952 */
5953static int wlan_hdd_cfg80211_set_privacy_ibss(
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305954 hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07005955 struct cfg80211_ibss_params *params
5956 )
5957{
5958 int status = 0;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305959 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07005960 eCsrEncryptionType encryptionType = eCSR_ENCRYPT_TYPE_NONE;
5961 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305962
Jeff Johnson295189b2012-06-20 16:38:30 -07005963 ENTER();
5964
5965 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_DISABLED;
5966
5967 if (params->ie_len && ( NULL != params->ie) )
5968 {
Shailender Karmuchi67edd312013-06-18 16:30:48 -07005969 if (wlan_hdd_cfg80211_get_ie_ptr (params->ie,
5970 params->ie_len, WLAN_EID_RSN ))
Jeff Johnson295189b2012-06-20 16:38:30 -07005971 {
5972 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA2;
5973 encryptionType = eCSR_ENCRYPT_TYPE_AES;
5974 }
Shailender Karmuchi67edd312013-06-18 16:30:48 -07005975 else if ( hdd_isWPAIEPresent (params->ie, params->ie_len ))
Jeff Johnson295189b2012-06-20 16:38:30 -07005976 {
Shailender Karmuchi642e9812013-05-30 14:34:49 -07005977 tDot11fIEWPA dot11WPAIE;
5978 tHalHandle halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
Shailender Karmuchi67edd312013-06-18 16:30:48 -07005979 u8 *ie;
Shailender Karmuchi642e9812013-05-30 14:34:49 -07005980
Shailender Karmuchi67edd312013-06-18 16:30:48 -07005981 ie = wlan_hdd_cfg80211_get_ie_ptr (params->ie,
5982 params->ie_len, DOT11F_EID_WPA);
5983 if ( NULL != ie )
5984 {
5985 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA;
5986 // Unpack the WPA IE
5987 //Skip past the EID byte and length byte - and four byte WiFi OUI
5988 dot11fUnpackIeWPA((tpAniSirGlobal) halHandle,
5989 &ie[2+4],
5990 ie[1] - 4,
5991 &dot11WPAIE);
5992 /*Extract the multicast cipher, the encType for unicast
5993 cipher for wpa-none is none*/
5994 encryptionType =
5995 hdd_TranslateWPAToCsrEncryptionType(dot11WPAIE.multicast_cipher);
5996 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005997 }
Shailender Karmuchi67edd312013-06-18 16:30:48 -07005998
Jeff Johnson295189b2012-06-20 16:38:30 -07005999 status = wlan_hdd_cfg80211_set_ie(pAdapter, params->ie, params->ie_len);
6000
6001 if (0 > status)
6002 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306003 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to parse WPA/RSN IE",
Jeff Johnson295189b2012-06-20 16:38:30 -07006004 __func__);
6005 return status;
6006 }
6007 }
6008
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306009 pWextState->roamProfile.AuthType.authType[0] =
6010 pHddStaCtx->conn_info.authType =
Jeff Johnson295189b2012-06-20 16:38:30 -07006011 eCSR_AUTH_TYPE_OPEN_SYSTEM;
6012
6013 if (params->privacy)
6014 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306015 /* Security enabled IBSS, At this time there is no information available
6016 * about the security paramters, so initialise the encryption type to
Jeff Johnson295189b2012-06-20 16:38:30 -07006017 * eCSR_ENCRYPT_TYPE_WEP40_STATICKEY.
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306018 * The correct security parameters will be updated later in
Jeff Johnson295189b2012-06-20 16:38:30 -07006019 * wlan_hdd_cfg80211_add_key */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306020 /* Hal expects encryption type to be set inorder
Jeff Johnson295189b2012-06-20 16:38:30 -07006021 *enable privacy bit in beacons */
6022
6023 encryptionType = eCSR_ENCRYPT_TYPE_WEP40_STATICKEY;
6024 }
Shailender Karmuchi642e9812013-05-30 14:34:49 -07006025 VOS_TRACE (VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
6026 "encryptionType=%d", encryptionType);
Jeff Johnson295189b2012-06-20 16:38:30 -07006027 pHddStaCtx->conn_info.ucEncryptionType = encryptionType;
6028 pWextState->roamProfile.EncryptionType.numEntries = 1;
6029 pWextState->roamProfile.EncryptionType.encryptionType[0] = encryptionType;
Jeff Johnson295189b2012-06-20 16:38:30 -07006030 return status;
6031}
6032
6033/*
6034 * FUNCTION: wlan_hdd_cfg80211_join_ibss
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306035 * This function is used to create/join an IBSS
Jeff Johnson295189b2012-06-20 16:38:30 -07006036 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306037static int wlan_hdd_cfg80211_join_ibss( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07006038 struct net_device *dev,
6039 struct cfg80211_ibss_params *params
6040 )
6041{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306042 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Jeff Johnson295189b2012-06-20 16:38:30 -07006043 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
6044 tCsrRoamProfile *pRoamProfile;
6045 int status;
6046 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306047 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07006048
6049 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306050
6051 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07006052 "%s: device_mode = %d\n",__func__,pAdapter->device_mode);
6053
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306054 status = wlan_hdd_validate_context(pHddCtx);
6055
6056 if (0 != status)
Jeff Johnson295189b2012-06-20 16:38:30 -07006057 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306058 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6059 "%s: HDD context is not valid", __func__);
6060 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006061 }
6062
6063 if (NULL == pWextState)
6064 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306065 hddLog (VOS_TRACE_LEVEL_ERROR, "%s ERROR: Data Storage Corruption\n",
Jeff Johnson295189b2012-06-20 16:38:30 -07006066 __func__);
6067 return -EIO;
6068 }
6069
6070 pRoamProfile = &pWextState->roamProfile;
6071
6072 if ( eCSR_BSS_TYPE_START_IBSS != pRoamProfile->BSSType )
6073 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306074 hddLog (VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07006075 "%s Interface type is not set to IBSS \n", __func__);
6076 return -EINVAL;
6077 }
6078
6079 /* Set Channel */
Yue Maf49ba872013-08-19 12:04:25 -07006080 if (NULL !=
6081#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0))
6082 params->chandef.chan)
6083#else
6084 params->channel)
6085#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006086 {
6087 u8 channelNum;
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006088 v_U32_t numChans = WNI_CFG_VALID_CHANNEL_LIST_LEN;
6089 v_U8_t validChan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
6090 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
6091 int indx;
Jeff Johnson295189b2012-06-20 16:38:30 -07006092
6093 /* Get channel number */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306094 channelNum =
Yue Maf49ba872013-08-19 12:04:25 -07006095 ieee80211_frequency_to_channel(
6096#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0))
6097 params->chandef.chan->center_freq);
6098#else
6099 params->channel->center_freq);
6100#endif
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006101
6102 if (0 != ccmCfgGetStr(hHal, WNI_CFG_VALID_CHANNEL_LIST,
6103 validChan, &numChans))
Jeff Johnson295189b2012-06-20 16:38:30 -07006104 {
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006105 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: No valid channel list",
6106 __func__);
6107 return -EOPNOTSUPP;
Jeff Johnson295189b2012-06-20 16:38:30 -07006108 }
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006109
6110 for (indx = 0; indx < numChans; indx++)
Jeff Johnson295189b2012-06-20 16:38:30 -07006111 {
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006112 if (channelNum == validChan[indx])
6113 {
6114 break;
6115 }
6116 }
6117 if (indx >= numChans)
6118 {
6119 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Not valid Channel %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07006120 __func__, channelNum);
6121 return -EINVAL;
6122 }
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006123 /* Set the Operational Channel */
6124 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: set channel %d", __func__,
6125 channelNum);
6126 pRoamProfile->ChannelInfo.numOfChannels = 1;
6127 pHddStaCtx->conn_info.operationChannel = channelNum;
6128 pRoamProfile->ChannelInfo.ChannelList =
6129 &pHddStaCtx->conn_info.operationChannel;
Jeff Johnson295189b2012-06-20 16:38:30 -07006130 }
6131
6132 /* Initialize security parameters */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306133 status = wlan_hdd_cfg80211_set_privacy_ibss(pAdapter, params);
Jeff Johnson295189b2012-06-20 16:38:30 -07006134 if (status < 0)
6135 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306136 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set security parameters",
Jeff Johnson295189b2012-06-20 16:38:30 -07006137 __func__);
6138 return status;
6139 }
6140
6141 /* Issue connect start */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306142 status = wlan_hdd_cfg80211_connect_start(pAdapter, params->ssid,
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006143 params->ssid_len, params->bssid,
6144 pHddStaCtx->conn_info.operationChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07006145
6146 if (0 > status)
6147 {
6148 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: connect failed", __func__);
6149 return status;
6150 }
6151
6152 return 0;
6153}
6154
6155/*
6156 * FUNCTION: wlan_hdd_cfg80211_leave_ibss
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306157 * This function is used to leave an IBSS
Jeff Johnson295189b2012-06-20 16:38:30 -07006158 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306159static int wlan_hdd_cfg80211_leave_ibss( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07006160 struct net_device *dev
6161 )
6162{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306163 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Jeff Johnson295189b2012-06-20 16:38:30 -07006164 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
6165 tCsrRoamProfile *pRoamProfile;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306166 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
6167 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006168
6169 ENTER();
6170
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306171 status = wlan_hdd_validate_context(pHddCtx);
6172
6173 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006174 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306175 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6176 "%s: HDD context is not valid", __func__);
6177 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006178 }
6179
Jeff Johnson295189b2012-06-20 16:38:30 -07006180 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",__func__,pAdapter->device_mode);
6181 if (NULL == pWextState)
6182 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306183 hddLog (VOS_TRACE_LEVEL_ERROR, "%s ERROR: Data Storage Corruption\n",
Jeff Johnson295189b2012-06-20 16:38:30 -07006184 __func__);
6185 return -EIO;
6186 }
6187
6188 pRoamProfile = &pWextState->roamProfile;
6189
6190 /* Issue disconnect only if interface type is set to IBSS */
6191 if (eCSR_BSS_TYPE_START_IBSS != pRoamProfile->BSSType)
6192 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306193 hddLog (VOS_TRACE_LEVEL_ERROR, "%s: BSS Type is not set to IBSS",
Jeff Johnson295189b2012-06-20 16:38:30 -07006194 __func__);
6195 return -EINVAL;
6196 }
6197
6198 /* Issue Disconnect request */
6199 INIT_COMPLETION(pAdapter->disconnect_comp_var);
6200 sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter), pAdapter->sessionId,
6201 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
6202
6203 return 0;
6204}
6205
6206/*
6207 * FUNCTION: wlan_hdd_cfg80211_set_wiphy_params
6208 * This function is used to set the phy parameters
6209 * (RTS Threshold/FRAG Threshold/Retry Count etc ...)
6210 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306211static int wlan_hdd_cfg80211_set_wiphy_params(struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07006212 u32 changed)
6213{
6214 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
6215 tHalHandle hHal = pHddCtx->hHal;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306216 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006217
6218 ENTER();
6219
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306220 status = wlan_hdd_validate_context(pHddCtx);
6221
6222 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006223 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306224 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6225 "%s: HDD context is not valid", __func__);
6226 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006227 }
6228
Jeff Johnson295189b2012-06-20 16:38:30 -07006229 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
6230 {
6231 u16 rts_threshold = (wiphy->rts_threshold == -1) ?
6232 WNI_CFG_RTS_THRESHOLD_STAMAX :
6233 wiphy->rts_threshold;
6234
6235 if ((WNI_CFG_RTS_THRESHOLD_STAMIN > rts_threshold) ||
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306236 (WNI_CFG_RTS_THRESHOLD_STAMAX < rts_threshold))
Jeff Johnson295189b2012-06-20 16:38:30 -07006237 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306238 hddLog(VOS_TRACE_LEVEL_ERROR,
6239 "%s: Invalid RTS Threshold value %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006240 __func__, rts_threshold);
6241 return -EINVAL;
6242 }
6243
6244 if (0 != ccmCfgSetInt(hHal, WNI_CFG_RTS_THRESHOLD,
6245 rts_threshold, ccmCfgSetCallback,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306246 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07006247 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306248 hddLog(VOS_TRACE_LEVEL_ERROR,
6249 "%s: ccmCfgSetInt failed for rts_threshold value %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006250 __func__, rts_threshold);
6251 return -EIO;
6252 }
6253
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306254 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set rts threshold %hu", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07006255 rts_threshold);
6256 }
6257
6258 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
6259 {
6260 u16 frag_threshold = (wiphy->frag_threshold == -1) ?
6261 WNI_CFG_FRAGMENTATION_THRESHOLD_STAMAX :
6262 wiphy->frag_threshold;
6263
6264 if ((WNI_CFG_FRAGMENTATION_THRESHOLD_STAMIN > frag_threshold)||
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306265 (WNI_CFG_FRAGMENTATION_THRESHOLD_STAMAX < frag_threshold) )
Jeff Johnson295189b2012-06-20 16:38:30 -07006266 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306267 hddLog(VOS_TRACE_LEVEL_ERROR,
6268 "%s: Invalid frag_threshold value %hu", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07006269 frag_threshold);
6270 return -EINVAL;
6271 }
6272
6273 if (0 != ccmCfgSetInt(hHal, WNI_CFG_FRAGMENTATION_THRESHOLD,
6274 frag_threshold, ccmCfgSetCallback,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306275 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07006276 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306277 hddLog(VOS_TRACE_LEVEL_ERROR,
6278 "%s: ccmCfgSetInt failed for frag_threshold value %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006279 __func__, frag_threshold);
6280 return -EIO;
6281 }
6282
6283 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set frag threshold %hu", __func__,
6284 frag_threshold);
6285 }
6286
6287 if ((changed & WIPHY_PARAM_RETRY_SHORT)
6288 || (changed & WIPHY_PARAM_RETRY_LONG))
6289 {
6290 u8 retry_value = (changed & WIPHY_PARAM_RETRY_SHORT) ?
6291 wiphy->retry_short :
6292 wiphy->retry_long;
6293
6294 if ((WNI_CFG_LONG_RETRY_LIMIT_STAMIN > retry_value) ||
6295 (WNI_CFG_LONG_RETRY_LIMIT_STAMAX < retry_value))
6296 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306297 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006298 __func__, retry_value);
6299 return -EINVAL;
6300 }
6301
6302 if (changed & WIPHY_PARAM_RETRY_SHORT)
6303 {
6304 if (0 != ccmCfgSetInt(hHal, WNI_CFG_LONG_RETRY_LIMIT,
6305 retry_value, ccmCfgSetCallback,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306306 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07006307 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306308 hddLog(VOS_TRACE_LEVEL_ERROR,
6309 "%s: ccmCfgSetInt failed for long retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006310 __func__, retry_value);
6311 return -EIO;
6312 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306313 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set long retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006314 __func__, retry_value);
6315 }
6316 else if (changed & WIPHY_PARAM_RETRY_SHORT)
6317 {
6318 if (0 != ccmCfgSetInt(hHal, WNI_CFG_SHORT_RETRY_LIMIT,
6319 retry_value, ccmCfgSetCallback,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306320 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07006321 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306322 hddLog(VOS_TRACE_LEVEL_ERROR,
6323 "%s: ccmCfgSetInt failed for short retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006324 __func__, retry_value);
6325 return -EIO;
6326 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306327 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set short retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006328 __func__, retry_value);
6329 }
6330 }
6331
6332 return 0;
6333}
6334
6335/*
6336 * FUNCTION: wlan_hdd_cfg80211_set_txpower
6337 * This function is used to set the txpower
6338 */
6339static int wlan_hdd_cfg80211_set_txpower(struct wiphy *wiphy,
Yue Maf49ba872013-08-19 12:04:25 -07006340#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0)
6341 struct wireless_dev *wdev,
6342#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006343#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,35)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306344 enum tx_power_setting type,
Jeff Johnson295189b2012-06-20 16:38:30 -07006345#else
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306346 enum nl80211_tx_power_setting type,
Jeff Johnson295189b2012-06-20 16:38:30 -07006347#endif
6348 int dbm)
6349{
6350 hdd_context_t *pHddCtx = (hdd_context_t*) wiphy_priv(wiphy);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306351 tHalHandle hHal = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07006352 tSirMacAddr bssid = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
6353 tSirMacAddr selfMac = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306354 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006355
6356 ENTER();
6357
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306358 status = wlan_hdd_validate_context(pHddCtx);
6359
6360 if (0 != status)
6361 {
6362 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6363 "%s: HDD context is not valid", __func__);
6364 return status;
6365 }
6366
6367 hHal = pHddCtx->hHal;
6368
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306369 if (0 != ccmCfgSetInt(hHal, WNI_CFG_CURRENT_TX_POWER_LEVEL,
6370 dbm, ccmCfgSetCallback,
6371 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07006372 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306373 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07006374 "%s: ccmCfgSetInt failed for tx power %hu", __func__, dbm);
6375 return -EIO;
6376 }
6377
6378 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set tx power level %d dbm", __func__,
6379 dbm);
6380
6381 switch(type)
6382 {
6383 case NL80211_TX_POWER_AUTOMATIC: /*automatically determine transmit power*/
6384 /* Fall through */
6385 case NL80211_TX_POWER_LIMITED: /*limit TX power by the mBm parameter*/
6386 if( sme_SetMaxTxPower(hHal, bssid, selfMac, dbm) != eHAL_STATUS_SUCCESS )
6387 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306388 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Setting maximum tx power failed",
6389 __func__);
6390 return -EIO;
Jeff Johnson295189b2012-06-20 16:38:30 -07006391 }
6392 break;
6393 case NL80211_TX_POWER_FIXED: /*fix TX power to the mBm parameter*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306394 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: NL80211_TX_POWER_FIXED not supported",
Jeff Johnson295189b2012-06-20 16:38:30 -07006395 __func__);
6396 return -EOPNOTSUPP;
6397 break;
6398 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306399 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid power setting type %d",
6400 __func__, type);
Jeff Johnson295189b2012-06-20 16:38:30 -07006401 return -EIO;
6402 }
6403
6404 return 0;
6405}
6406
6407/*
6408 * FUNCTION: wlan_hdd_cfg80211_get_txpower
6409 * This function is used to read the txpower
6410 */
Yue Maf49ba872013-08-19 12:04:25 -07006411static int wlan_hdd_cfg80211_get_txpower(struct wiphy *wiphy,
6412#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0)
6413 struct wireless_dev *wdev,
6414#endif
6415 int *dbm)
Jeff Johnson295189b2012-06-20 16:38:30 -07006416{
6417
6418 hdd_adapter_t *pAdapter;
6419 hdd_context_t *pHddCtx = (hdd_context_t*) wiphy_priv(wiphy);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306420 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006421
Jeff Johnsone7245742012-09-05 17:12:55 -07006422 ENTER();
6423
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306424 status = wlan_hdd_validate_context(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07006425
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306426 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006427 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306428 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6429 "%s: HDD context is not valid", __func__);
6430 *dbm = 0;
6431 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006432 }
6433
Jeff Johnson295189b2012-06-20 16:38:30 -07006434 pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_INFRA_STATION);
6435 if (NULL == pAdapter)
6436 {
6437 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Not in station context " ,__func__);
6438 return -ENOENT;
6439 }
6440
6441 wlan_hdd_get_classAstats(pAdapter);
6442 *dbm = pAdapter->hdd_stats.ClassA_stat.max_pwr;
6443
Jeff Johnsone7245742012-09-05 17:12:55 -07006444 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07006445 return 0;
6446}
6447
6448static int wlan_hdd_cfg80211_get_station(struct wiphy *wiphy, struct net_device *dev,
6449 u8* mac, struct station_info *sinfo)
6450{
6451 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
6452 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
6453 int ssidlen = pHddStaCtx->conn_info.SSID.SSID.length;
6454 tANI_U8 rate_flags;
6455
6456 hdd_context_t *pHddCtx = (hdd_context_t*) wiphy_priv(wiphy);
6457 hdd_config_t *pCfg = pHddCtx->cfg_ini;
Jeff Johnson295189b2012-06-20 16:38:30 -07006458
6459 tANI_U8 OperationalRates[CSR_DOT11_SUPPORTED_RATES_MAX];
6460 tANI_U32 ORLeng = CSR_DOT11_SUPPORTED_RATES_MAX;
6461 tANI_U8 ExtendedRates[CSR_DOT11_EXTENDED_SUPPORTED_RATES_MAX];
6462 tANI_U32 ERLeng = CSR_DOT11_EXTENDED_SUPPORTED_RATES_MAX;
6463 tANI_U8 MCSRates[SIZE_OF_BASIC_MCS_SET];
6464 tANI_U32 MCSLeng = SIZE_OF_BASIC_MCS_SET;
6465 tANI_U16 maxRate = 0;
6466 tANI_U16 myRate;
6467 tANI_U16 currentRate = 0;
6468 tANI_U8 maxSpeedMCS = 0;
6469 tANI_U8 maxMCSIdx = 0;
6470 tANI_U8 rateFlag = 1;
6471 tANI_U8 i, j, rssidx;
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07006472 tANI_U16 temp;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306473 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006474
Leo Chang6f8870f2013-03-26 18:11:36 -07006475#ifdef WLAN_FEATURE_11AC
6476 tANI_U32 vht_mcs_map;
6477 eDataRate11ACMaxMcs vhtMaxMcs;
6478#endif /* WLAN_FEATURE_11AC */
6479
Jeff Johnsone7245742012-09-05 17:12:55 -07006480 ENTER();
6481
Jeff Johnson295189b2012-06-20 16:38:30 -07006482 if ((eConnectionState_Associated != pHddStaCtx->conn_info.connState) ||
6483 (0 == ssidlen))
6484 {
6485 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Not associated or"
6486 " Invalid ssidlen, %d", __func__, ssidlen);
6487 /*To keep GUI happy*/
6488 return 0;
6489 }
6490
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306491 status = wlan_hdd_validate_context(pHddCtx);
6492
6493 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006494 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306495 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6496 "%s: HDD context is not valid", __func__);
6497 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006498 }
6499
Jeff Johnson295189b2012-06-20 16:38:30 -07006500 wlan_hdd_get_rssi(pAdapter, &sinfo->signal);
6501 sinfo->filled |= STATION_INFO_SIGNAL;
6502
Madan Mohan Koyyalamudi4d4d2812012-09-24 14:08:29 -07006503 wlan_hdd_get_station_stats(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07006504 rate_flags = pAdapter->hdd_stats.ClassA_stat.tx_rate_flags;
6505
6506 //convert to the UI units of 100kbps
6507 myRate = pAdapter->hdd_stats.ClassA_stat.tx_rate * 5;
6508
6509#ifdef LINKSPEED_DEBUG_ENABLED
Leo Chang6f8870f2013-03-26 18:11:36 -07006510 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 -07006511 sinfo->signal,
6512 pCfg->reportMaxLinkSpeed,
6513 myRate,
6514 (int) pCfg->linkSpeedRssiHigh,
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07006515 (int) pCfg->linkSpeedRssiMid,
6516 (int) pCfg->linkSpeedRssiLow,
Leo Chang6f8870f2013-03-26 18:11:36 -07006517 (int) rate_flags,
6518 (int) pAdapter->hdd_stats.ClassA_stat.mcs_index);
Jeff Johnson295189b2012-06-20 16:38:30 -07006519#endif //LINKSPEED_DEBUG_ENABLED
6520
6521 if (eHDD_LINK_SPEED_REPORT_ACTUAL != pCfg->reportMaxLinkSpeed)
6522 {
6523 // we do not want to necessarily report the current speed
6524 if (eHDD_LINK_SPEED_REPORT_MAX == pCfg->reportMaxLinkSpeed)
6525 {
6526 // report the max possible speed
6527 rssidx = 0;
6528 }
6529 else if (eHDD_LINK_SPEED_REPORT_MAX_SCALED == pCfg->reportMaxLinkSpeed)
6530 {
6531 // report the max possible speed with RSSI scaling
6532 if (sinfo->signal >= pCfg->linkSpeedRssiHigh)
6533 {
6534 // report the max possible speed
6535 rssidx = 0;
6536 }
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07006537 else if (sinfo->signal >= pCfg->linkSpeedRssiMid)
Jeff Johnson295189b2012-06-20 16:38:30 -07006538 {
6539 // report middle speed
6540 rssidx = 1;
6541 }
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07006542 else if (sinfo->signal >= pCfg->linkSpeedRssiLow)
6543 {
6544 // report middle speed
6545 rssidx = 2;
6546 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006547 else
6548 {
6549 // report actual speed
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07006550 rssidx = 3;
Jeff Johnson295189b2012-06-20 16:38:30 -07006551 }
6552 }
6553 else
6554 {
6555 // unknown, treat as eHDD_LINK_SPEED_REPORT_MAX
6556 hddLog(VOS_TRACE_LEVEL_ERROR,
6557 "%s: Invalid value for reportMaxLinkSpeed: %u",
6558 __func__, pCfg->reportMaxLinkSpeed);
6559 rssidx = 0;
6560 }
6561
6562 maxRate = 0;
6563
6564 /* Get Basic Rate Set */
Gopichand Nakkala05ab1322013-02-15 11:28:38 +05306565 if (0 != ccmCfgGetStr(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_OPERATIONAL_RATE_SET,
6566 OperationalRates, &ORLeng))
6567 {
6568 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: ccm api returned failure", __func__);
6569 /*To keep GUI happy*/
6570 return 0;
6571 }
6572
Jeff Johnson295189b2012-06-20 16:38:30 -07006573 for (i = 0; i < ORLeng; i++)
6574 {
Jeff Johnsone7245742012-09-05 17:12:55 -07006575 for (j = 0; j < (sizeof(supported_data_rate) / sizeof(supported_data_rate[0])); j ++)
Jeff Johnson295189b2012-06-20 16:38:30 -07006576 {
6577 /* Validate Rate Set */
6578 if (supported_data_rate[j].beacon_rate_index == (OperationalRates[i] & 0x7F))
6579 {
6580 currentRate = supported_data_rate[j].supported_rate[rssidx];
6581 break;
6582 }
6583 }
6584 /* Update MAX rate */
6585 maxRate = (currentRate > maxRate)?currentRate:maxRate;
6586 }
6587
6588 /* Get Extended Rate Set */
Gopichand Nakkala05ab1322013-02-15 11:28:38 +05306589 if (0 != ccmCfgGetStr(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_EXTENDED_OPERATIONAL_RATE_SET,
6590 ExtendedRates, &ERLeng))
6591 {
6592 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: ccm api returned failure", __func__);
6593 /*To keep GUI happy*/
6594 return 0;
6595 }
6596
Jeff Johnson295189b2012-06-20 16:38:30 -07006597 for (i = 0; i < ERLeng; i++)
6598 {
Jeff Johnsone7245742012-09-05 17:12:55 -07006599 for (j = 0; j < (sizeof(supported_data_rate) / sizeof(supported_data_rate[0])); j ++)
Jeff Johnson295189b2012-06-20 16:38:30 -07006600 {
6601 if (supported_data_rate[j].beacon_rate_index == (ExtendedRates[i] & 0x7F))
6602 {
6603 currentRate = supported_data_rate[j].supported_rate[rssidx];
6604 break;
6605 }
6606 }
6607 /* Update MAX rate */
6608 maxRate = (currentRate > maxRate)?currentRate:maxRate;
6609 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006610 /* Get MCS Rate Set -- but only if we are connected at MCS
6611 rates or if we are always reporting max speed or if we have
6612 good rssi */
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07006613 if ((0 == rssidx) && !(rate_flags & eHAL_TX_RATE_LEGACY))
Jeff Johnson295189b2012-06-20 16:38:30 -07006614 {
Gopichand Nakkala05ab1322013-02-15 11:28:38 +05306615 if (0 != ccmCfgGetStr(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_CURRENT_MCS_SET,
6616 MCSRates, &MCSLeng))
6617 {
6618 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: ccm api returned failure", __func__);
6619 /*To keep GUI happy*/
6620 return 0;
6621 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006622 rateFlag = 0;
Leo Chang6f8870f2013-03-26 18:11:36 -07006623#ifdef WLAN_FEATURE_11AC
6624 /* VHT80 rate has seperate rate table */
Gopichand Nakkala4c705372013-04-24 13:20:33 +05306625 if (rate_flags & (eHAL_TX_RATE_VHT20|eHAL_TX_RATE_VHT40|eHAL_TX_RATE_VHT80))
Jeff Johnson295189b2012-06-20 16:38:30 -07006626 {
Leo Chang6f8870f2013-03-26 18:11:36 -07006627 ccmCfgGetInt(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_VHT_TX_MCS_MAP, &vht_mcs_map);
Gopichand Nakkala4c705372013-04-24 13:20:33 +05306628 vhtMaxMcs = (eDataRate11ACMaxMcs)(vht_mcs_map & DATA_RATE_11AC_MCS_MASK );
Leo Chang6f8870f2013-03-26 18:11:36 -07006629 if (rate_flags & eHAL_TX_RATE_SGI)
Jeff Johnson295189b2012-06-20 16:38:30 -07006630 {
Leo Chang6f8870f2013-03-26 18:11:36 -07006631 rateFlag |= 1;
Jeff Johnson295189b2012-06-20 16:38:30 -07006632 }
Leo Chang6f8870f2013-03-26 18:11:36 -07006633 if (DATA_RATE_11AC_MAX_MCS_7 == vhtMaxMcs)
Jeff Johnson295189b2012-06-20 16:38:30 -07006634 {
Leo Chang6f8870f2013-03-26 18:11:36 -07006635 maxMCSIdx = 7;
6636 }
6637 else if (DATA_RATE_11AC_MAX_MCS_8 == vhtMaxMcs)
6638 {
6639 maxMCSIdx = 8;
6640 }
6641 else if (DATA_RATE_11AC_MAX_MCS_9 == vhtMaxMcs)
6642 {
Gopichand Nakkala4c705372013-04-24 13:20:33 +05306643 //VHT20 is supporting 0~8
6644 if (rate_flags & eHAL_TX_RATE_VHT20)
6645 maxMCSIdx = 8;
6646 else
6647 maxMCSIdx = 9;
Leo Chang6f8870f2013-03-26 18:11:36 -07006648 }
Gopichand Nakkala4c705372013-04-24 13:20:33 +05306649
6650 if (rate_flags & eHAL_TX_RATE_VHT80)
6651 {
6652 currentRate = supported_vht_mcs_rate[pAdapter->hdd_stats.ClassA_stat.mcs_index].supported_VHT80_rate[rateFlag];
6653 maxRate = supported_vht_mcs_rate[maxMCSIdx].supported_VHT80_rate[rateFlag];
6654 }
6655 else if (rate_flags & eHAL_TX_RATE_VHT40)
6656 {
6657 currentRate = supported_vht_mcs_rate[pAdapter->hdd_stats.ClassA_stat.mcs_index].supported_VHT40_rate[rateFlag];
6658 maxRate = supported_vht_mcs_rate[maxMCSIdx].supported_VHT40_rate[rateFlag];
6659 }
6660 else if (rate_flags & eHAL_TX_RATE_VHT20)
6661 {
6662 currentRate = supported_vht_mcs_rate[pAdapter->hdd_stats.ClassA_stat.mcs_index].supported_VHT20_rate[rateFlag];
6663 maxRate = supported_vht_mcs_rate[maxMCSIdx].supported_VHT20_rate[rateFlag];
6664 }
6665
Leo Chang6f8870f2013-03-26 18:11:36 -07006666 maxSpeedMCS = 1;
6667 if (currentRate > maxRate)
6668 {
6669 maxRate = currentRate;
6670 }
Gopichand Nakkala4c705372013-04-24 13:20:33 +05306671
Leo Chang6f8870f2013-03-26 18:11:36 -07006672 }
6673 else
6674#endif /* WLAN_FEATURE_11AC */
6675 {
6676 if (rate_flags & eHAL_TX_RATE_HT40)
6677 {
6678 rateFlag |= 1;
6679 }
6680 if (rate_flags & eHAL_TX_RATE_SGI)
6681 {
6682 rateFlag |= 2;
6683 }
6684
6685 for (i = 0; i < MCSLeng; i++)
6686 {
6687 temp = sizeof(supported_mcs_rate) / sizeof(supported_mcs_rate[0]);
6688 for (j = 0; j < temp; j++)
6689 {
6690 if (supported_mcs_rate[j].beacon_rate_index == MCSRates[i])
6691 {
6692 currentRate = supported_mcs_rate[j].supported_rate[rateFlag];
6693 break;
6694 }
6695 }
6696 if ((j < temp) && (currentRate > maxRate))
6697 {
6698 maxRate = currentRate;
6699 maxSpeedMCS = 1;
6700 maxMCSIdx = supported_mcs_rate[j].beacon_rate_index;
6701 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006702 }
6703 }
6704 }
6705
Gopichand Nakkala4c705372013-04-24 13:20:33 +05306706 else if (!(rate_flags & eHAL_TX_RATE_LEGACY))
6707 {
6708 maxRate = myRate;
6709 maxSpeedMCS = 1;
6710 maxMCSIdx = pAdapter->hdd_stats.ClassA_stat.mcs_index;
6711 }
6712
Jeff Johnson295189b2012-06-20 16:38:30 -07006713 // make sure we report a value at least as big as our current rate
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07006714 if (((maxRate < myRate) && (0 == rssidx)) ||
6715 (0 == maxRate))
Jeff Johnson295189b2012-06-20 16:38:30 -07006716 {
6717 maxRate = myRate;
6718 if (rate_flags & eHAL_TX_RATE_LEGACY)
6719 {
6720 maxSpeedMCS = 0;
6721 }
6722 else
6723 {
6724 maxSpeedMCS = 1;
6725 maxMCSIdx = pAdapter->hdd_stats.ClassA_stat.mcs_index;
6726 }
6727 }
6728
Gopichand Nakkala4c705372013-04-24 13:20:33 +05306729 if (rate_flags & eHAL_TX_RATE_LEGACY)
Jeff Johnson295189b2012-06-20 16:38:30 -07006730 {
6731 sinfo->txrate.legacy = maxRate;
6732#ifdef LINKSPEED_DEBUG_ENABLED
6733 pr_info("Reporting legacy rate %d\n", sinfo->txrate.legacy);
6734#endif //LINKSPEED_DEBUG_ENABLED
6735 }
6736 else
6737 {
6738 sinfo->txrate.mcs = maxMCSIdx;
Leo Chang6f8870f2013-03-26 18:11:36 -07006739#ifdef WLAN_FEATURE_11AC
6740 sinfo->txrate.nss = 1;
6741 if (rate_flags & eHAL_TX_RATE_VHT80)
6742 {
6743 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
Gopichand Nakkala4c705372013-04-24 13:20:33 +05306744 sinfo->txrate.flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
Leo Chang6f8870f2013-03-26 18:11:36 -07006745 }
Gopichand Nakkala4c705372013-04-24 13:20:33 +05306746 else if (rate_flags & eHAL_TX_RATE_VHT40)
Leo Chang6f8870f2013-03-26 18:11:36 -07006747 {
Gopichand Nakkala4c705372013-04-24 13:20:33 +05306748 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
6749 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
6750 }
6751 else if (rate_flags & eHAL_TX_RATE_VHT20)
6752 {
6753 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
6754 }
6755#endif /* WLAN_FEATURE_11AC */
6756 if (rate_flags & (eHAL_TX_RATE_HT20 | eHAL_TX_RATE_HT40))
6757 {
6758 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
6759 if (rate_flags & eHAL_TX_RATE_HT40)
6760 {
6761 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
6762 }
Leo Chang6f8870f2013-03-26 18:11:36 -07006763 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006764 if (rate_flags & eHAL_TX_RATE_SGI)
6765 {
6766 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
6767 }
Gopichand Nakkala4c705372013-04-24 13:20:33 +05306768
Jeff Johnson295189b2012-06-20 16:38:30 -07006769#ifdef LINKSPEED_DEBUG_ENABLED
6770 pr_info("Reporting MCS rate %d flags %x\n",
6771 sinfo->txrate.mcs,
6772 sinfo->txrate.flags );
6773#endif //LINKSPEED_DEBUG_ENABLED
6774 }
6775 }
6776 else
6777 {
6778 // report current rate instead of max rate
6779
6780 if (rate_flags & eHAL_TX_RATE_LEGACY)
6781 {
6782 //provide to the UI in units of 100kbps
6783 sinfo->txrate.legacy = myRate;
6784#ifdef LINKSPEED_DEBUG_ENABLED
6785 pr_info("Reporting actual legacy rate %d\n", sinfo->txrate.legacy);
6786#endif //LINKSPEED_DEBUG_ENABLED
6787 }
6788 else
6789 {
6790 //must be MCS
6791 sinfo->txrate.mcs = pAdapter->hdd_stats.ClassA_stat.mcs_index;
Leo Chang6f8870f2013-03-26 18:11:36 -07006792#ifdef WLAN_FEATURE_11AC
6793 sinfo->txrate.nss = 1;
6794 if (rate_flags & eHAL_TX_RATE_VHT80)
6795 {
6796 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
6797 }
6798 else
6799#endif /* WLAN_FEATURE_11AC */
6800 {
6801 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
6802 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006803 if (rate_flags & eHAL_TX_RATE_SGI)
6804 {
6805 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
6806 }
6807 if (rate_flags & eHAL_TX_RATE_HT40)
6808 {
6809 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
6810 }
Leo Chang6f8870f2013-03-26 18:11:36 -07006811#ifdef WLAN_FEATURE_11AC
6812 else if (rate_flags & eHAL_TX_RATE_VHT80)
6813 {
6814 sinfo->txrate.flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
6815 }
6816#endif /* WLAN_FEATURE_11AC */
Jeff Johnson295189b2012-06-20 16:38:30 -07006817#ifdef LINKSPEED_DEBUG_ENABLED
6818 pr_info("Reporting actual MCS rate %d flags %x\n",
6819 sinfo->txrate.mcs,
6820 sinfo->txrate.flags );
6821#endif //LINKSPEED_DEBUG_ENABLED
6822 }
6823 }
6824 sinfo->filled |= STATION_INFO_TX_BITRATE;
6825
Madan Mohan Koyyalamudi4d4d2812012-09-24 14:08:29 -07006826 sinfo->tx_packets =
6827 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[0] +
6828 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[1] +
6829 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[2] +
6830 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[3];
6831
6832 sinfo->tx_retries =
6833 pAdapter->hdd_stats.summary_stat.retry_cnt[0] +
6834 pAdapter->hdd_stats.summary_stat.retry_cnt[1] +
6835 pAdapter->hdd_stats.summary_stat.retry_cnt[2] +
6836 pAdapter->hdd_stats.summary_stat.retry_cnt[3];
6837
6838 sinfo->tx_failed =
6839 pAdapter->hdd_stats.summary_stat.fail_cnt[0] +
6840 pAdapter->hdd_stats.summary_stat.fail_cnt[1] +
6841 pAdapter->hdd_stats.summary_stat.fail_cnt[2] +
6842 pAdapter->hdd_stats.summary_stat.fail_cnt[3];
6843
6844 sinfo->filled |=
6845 STATION_INFO_TX_PACKETS |
6846 STATION_INFO_TX_RETRIES |
6847 STATION_INFO_TX_FAILED;
6848
6849 EXIT();
6850 return 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07006851}
6852
6853static int wlan_hdd_cfg80211_set_power_mgmt(struct wiphy *wiphy,
Sameer Thalappilc9f26e92013-06-07 10:11:06 -07006854 struct net_device *dev, bool mode, int timeout)
Jeff Johnson295189b2012-06-20 16:38:30 -07006855{
6856 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05306857 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07006858 VOS_STATUS vos_status;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306859 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006860
Jeff Johnsone7245742012-09-05 17:12:55 -07006861 ENTER();
6862
Jeff Johnson295189b2012-06-20 16:38:30 -07006863 if (NULL == pAdapter)
6864 {
6865 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Adapter is NULL\n", __func__);
6866 return -ENODEV;
6867 }
6868
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05306869 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306870 status = wlan_hdd_validate_context(pHddCtx);
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05306871
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306872 if (0 != status)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306873 {
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;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306877 }
6878
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05306879 if ((DRIVER_POWER_MODE_AUTO == !mode) &&
6880 (TRUE == pHddCtx->hdd_wlan_suspended) &&
6881 (pHddCtx->cfg_ini->fhostArpOffload) &&
6882 (eConnectionState_Associated ==
6883 (WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))->conn_info.connState))
6884 {
Gopichand Nakkalab03e8082013-05-30 18:09:25 +05306885 vos_status = hdd_conf_arp_offload(pAdapter, TRUE);
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05306886 if (!VOS_IS_STATUS_SUCCESS(vos_status))
6887 {
6888 hddLog(VOS_TRACE_LEVEL_INFO,
6889 "%s:Failed to enable ARPOFFLOAD Feature %d\n",
6890 __func__, vos_status);
6891 }
6892 }
6893
Jeff Johnson295189b2012-06-20 16:38:30 -07006894 /**The get power cmd from the supplicant gets updated by the nl only
6895 *on successful execution of the function call
6896 *we are oppositely mapped w.r.t mode in the driver
6897 **/
6898 vos_status = wlan_hdd_enter_bmps(pAdapter, !mode);
6899
Jeff Johnsone7245742012-09-05 17:12:55 -07006900 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07006901 if (VOS_STATUS_E_FAILURE == vos_status)
6902 {
6903 return -EINVAL;
6904 }
6905 return 0;
6906}
6907
6908
6909#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
6910static int wlan_hdd_set_default_mgmt_key(struct wiphy *wiphy,
6911 struct net_device *netdev,
6912 u8 key_index)
6913{
Jeff Johnsone7245742012-09-05 17:12:55 -07006914 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07006915 return 0;
6916}
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306917#endif //LINUX_VERSION_CODE
Jeff Johnson295189b2012-06-20 16:38:30 -07006918
6919#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
6920static int wlan_hdd_set_txq_params(struct wiphy *wiphy,
6921 struct net_device *dev,
6922 struct ieee80211_txq_params *params)
6923{
Jeff Johnsone7245742012-09-05 17:12:55 -07006924 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07006925 return 0;
6926}
6927#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
6928static int wlan_hdd_set_txq_params(struct wiphy *wiphy,
6929 struct ieee80211_txq_params *params)
6930{
Jeff Johnsone7245742012-09-05 17:12:55 -07006931 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07006932 return 0;
6933}
6934#endif //LINUX_VERSION_CODE
6935
6936static int wlan_hdd_cfg80211_del_station(struct wiphy *wiphy,
6937 struct net_device *dev, u8 *mac)
6938{
6939 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306940 hdd_context_t *pHddCtx;
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08006941 VOS_STATUS vos_status;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306942 int status;
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08006943 v_U8_t staId;
Jeff Johnson295189b2012-06-20 16:38:30 -07006944
Jeff Johnsone7245742012-09-05 17:12:55 -07006945 ENTER();
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306946 if ( NULL == pAdapter )
Jeff Johnson295189b2012-06-20 16:38:30 -07006947 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306948 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Adapter" ,__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07006949 return -EINVAL;
6950 }
6951
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306952 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
6953 status = wlan_hdd_validate_context(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07006954
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306955 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006956 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306957 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6958 "%s: HDD context is not valid", __func__);
6959 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006960 }
6961
Jeff Johnson295189b2012-06-20 16:38:30 -07006962 if ( (WLAN_HDD_SOFTAP == pAdapter->device_mode)
Jeff Johnson295189b2012-06-20 16:38:30 -07006963 || (WLAN_HDD_P2P_GO == pAdapter->device_mode)
Jeff Johnson295189b2012-06-20 16:38:30 -07006964 )
6965 {
6966 if( NULL == mac )
6967 {
6968 v_U16_t i;
6969 for(i = 0; i < WLAN_MAX_STA_COUNT; i++)
6970 {
Rajesh Chauhan18488fc2013-08-22 10:15:03 -07006971 if ((pAdapter->aStaInfo[i].isUsed) &&
6972 (!pAdapter->aStaInfo[i].isDeauthInProgress))
Jeff Johnson295189b2012-06-20 16:38:30 -07006973 {
6974 u8 *macAddr = pAdapter->aStaInfo[i].macAddrSTA.bytes;
6975 hddLog(VOS_TRACE_LEVEL_INFO,
6976 "%s: Delete STA with MAC::"
6977 "%02x:%02x:%02x:%02x:%02x:%02x",
6978 __func__,
6979 macAddr[0], macAddr[1], macAddr[2],
6980 macAddr[3], macAddr[4], macAddr[5]);
Rajesh Chauhan18488fc2013-08-22 10:15:03 -07006981 vos_status = hdd_softap_sta_deauth(pAdapter, macAddr);
6982 if (VOS_IS_STATUS_SUCCESS(vos_status))
6983 pAdapter->aStaInfo[i].isDeauthInProgress = TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006984 }
6985 }
6986 }
6987 else
6988 {
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08006989
6990 vos_status = hdd_softap_GetStaId(pAdapter,(v_MACADDR_t *)mac, &staId);
6991 if (!VOS_IS_STATUS_SUCCESS(vos_status))
6992 {
6993 hddLog(VOS_TRACE_LEVEL_INFO,
6994 "%s: Skip this DEL STA as this is not used::"
6995 "%02x:%02x:%02x:%02x:%02x:%02x",
6996 __func__,
6997 mac[0], mac[1], mac[2],
6998 mac[3], mac[4], mac[5]);
6999 return -ENOENT;
7000 }
7001
7002 if( pAdapter->aStaInfo[staId].isDeauthInProgress == TRUE)
7003 {
7004 hddLog(VOS_TRACE_LEVEL_INFO,
7005 "%s: Skip this DEL STA as deauth is in progress::"
7006 "%02x:%02x:%02x:%02x:%02x:%02x",
7007 __func__,
7008 mac[0], mac[1], mac[2],
7009 mac[3], mac[4], mac[5]);
7010 return -ENOENT;
7011 }
7012
7013 pAdapter->aStaInfo[staId].isDeauthInProgress = TRUE;
7014
Jeff Johnson295189b2012-06-20 16:38:30 -07007015 hddLog(VOS_TRACE_LEVEL_INFO,
7016 "%s: Delete STA with MAC::"
7017 "%02x:%02x:%02x:%02x:%02x:%02x",
7018 __func__,
7019 mac[0], mac[1], mac[2],
7020 mac[3], mac[4], mac[5]);
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007021
7022 vos_status = hdd_softap_sta_deauth(pAdapter, mac);
7023 if (!VOS_IS_STATUS_SUCCESS(vos_status))
7024 {
7025 pAdapter->aStaInfo[staId].isDeauthInProgress = FALSE;
7026 hddLog(VOS_TRACE_LEVEL_INFO,
7027 "%s: STA removal failed for ::"
7028 "%02x:%02x:%02x:%02x:%02x:%02x",
7029 __func__,
7030 mac[0], mac[1], mac[2],
7031 mac[3], mac[4], mac[5]);
7032 return -ENOENT;
7033 }
7034
Jeff Johnson295189b2012-06-20 16:38:30 -07007035 }
7036 }
7037
7038 EXIT();
7039
7040 return 0;
7041}
7042
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007043static int wlan_hdd_cfg80211_add_station(struct wiphy *wiphy,
7044 struct net_device *dev, u8 *mac, struct station_parameters *params)
7045{
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007046 int status = -EPERM;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007047#ifdef FEATURE_WLAN_TDLS
7048 u32 mask, set;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007049 ENTER();
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007050 mask = params->sta_flags_mask;
7051
7052 set = params->sta_flags_set;
7053
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007054#ifdef WLAN_FEATURE_TDLS_DEBUG
7055 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7056 "%s: mask 0x%x set 0x%x " MAC_ADDRESS_STR,
7057 __func__, mask, set, MAC_ADDR_ARRAY(mac));
7058#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007059
7060 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
7061 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
Gopichand Nakkala681989c2013-03-06 22:27:48 -08007062 status = wlan_hdd_tdls_add_station(wiphy, dev, mac, 0, NULL);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007063 }
7064 }
7065#endif
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007066 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007067}
7068
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007069
7070#ifdef FEATURE_WLAN_LFR
7071static int wlan_hdd_cfg80211_set_pmksa(struct wiphy *wiphy, struct net_device *dev,
Jeff Johnsond13512a2012-07-17 11:42:19 -07007072 struct cfg80211_pmksa *pmksa)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007073{
7074#define MAX_PMKSAIDS_IN_CACHE 8
7075 static tPmkidCacheInfo PMKIDCache[MAX_PMKSAIDS_IN_CACHE]; // HDD Local cache
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307076 static tANI_U32 i; // HDD Local Cache index
7077 tANI_U32 j=0;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007078 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7079 tHalHandle halHandle;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307080 eHalStatus result;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307081 int status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007082 tANI_U8 BSSIDMatched = 0;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307083 hdd_context_t *pHddCtx;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307084
Jeff Johnsone7245742012-09-05 17:12:55 -07007085 ENTER();
7086
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307087 // Validate pAdapter
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307088 if ( NULL == pAdapter )
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007089 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307090 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Adapter" ,__func__);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007091 return -EINVAL;
7092 }
7093
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307094 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7095 status = wlan_hdd_validate_context(pHddCtx);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007096
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307097 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007098 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307099 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7100 "%s: HDD context is not valid", __func__);
7101 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007102 }
7103
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307104 // Retrieve halHandle
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007105 halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
7106
7107 for (j = 0; j < i; j++)
7108 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307109 if(vos_mem_compare(PMKIDCache[j].BSSID,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007110 pmksa->bssid, WNI_CFG_BSSID_LEN))
7111 {
7112 /* BSSID matched previous entry. Overwrite it. */
7113 BSSIDMatched = 1;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307114 vos_mem_copy(PMKIDCache[j].BSSID,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007115 pmksa->bssid, WNI_CFG_BSSID_LEN);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307116 vos_mem_copy(PMKIDCache[j].PMKID,
7117 pmksa->pmkid,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007118 CSR_RSN_PMKID_SIZE);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307119 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Reusing cache entry %d.",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007120 __func__, j );
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007121 dump_bssid(pmksa->bssid);
7122 dump_pmkid(halHandle, pmksa->pmkid);
7123 break;
7124 }
7125 }
7126
Madan Mohan Koyyalamudic4b317d2012-10-18 19:43:08 -07007127 /* Check we compared all entries,if then take the first slot now */
7128 if(j == MAX_PMKSAIDS_IN_CACHE) i=0;
7129
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007130 if (!BSSIDMatched)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307131 {
7132 // Now, we DON'T have a BSSID match, so take a new entry in the cache.
7133 vos_mem_copy(PMKIDCache[i].BSSID,
7134 pmksa->bssid, ETHER_ADDR_LEN);
7135 vos_mem_copy(PMKIDCache[i].PMKID,
7136 pmksa->pmkid,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007137 CSR_RSN_PMKID_SIZE);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307138 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Adding a new cache entry %d.",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007139 __func__, i );
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007140 dump_bssid(pmksa->bssid);
7141 dump_pmkid(halHandle, pmksa->pmkid);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307142 // Increment the HDD Local Cache index
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007143 // The "i=0" doesn't work for the call to sme_RoamSetPMKIDCache() - LFR FIXME
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307144 if (i<=(MAX_PMKSAIDS_IN_CACHE-1)) i++; else i=0;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007145 }
7146
7147
7148 // Calling csrRoamSetPMKIDCache to configure the PMKIDs into the cache
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307149 //hddLog(LOG1, FL("%s: Calling csrRoamSetPMKIDCache with %d cache entries."),
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007150 // __func__, i );
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307151 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Calling csrRoamSetPMKIDCache with %d cache entries.",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007152 __func__, i );
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007153 // Finally set the PMKSA ID Cache in CSR
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307154 result = sme_RoamSetPMKIDCache(halHandle,pAdapter->sessionId,
7155 PMKIDCache,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007156 i );
7157 return 0;
7158}
7159
7160
7161static int wlan_hdd_cfg80211_del_pmksa(struct wiphy *wiphy, struct net_device *dev,
Jeff Johnsond13512a2012-07-17 11:42:19 -07007162 struct cfg80211_pmksa *pmksa)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007163{
Jeff Johnsone7245742012-09-05 17:12:55 -07007164 ENTER();
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007165 // TODO: Implement this later.
7166 return 0;
7167}
7168
7169static int wlan_hdd_cfg80211_flush_pmksa(struct wiphy *wiphy, struct net_device *dev)
7170{
Jeff Johnsone7245742012-09-05 17:12:55 -07007171 ENTER();
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007172 // TODO: Implement this later.
7173 return 0;
7174}
7175#endif
7176
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07007177#if defined(WLAN_FEATURE_VOWIFI_11R) && defined(KERNEL_SUPPORT_11R_CFG80211)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307178static int wlan_hdd_cfg80211_update_ft_ies(struct wiphy *wiphy,
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07007179 struct net_device *dev, struct cfg80211_update_ft_ies_params *ftie)
7180{
7181 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7182 hdd_station_ctx_t *pHddStaCtx;
7183
7184 if (NULL == pAdapter)
7185 {
7186 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Adapter is NULL\n", __func__);
7187 return -ENODEV;
7188 }
7189
7190 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
7191
7192 // Added for debug on reception of Re-assoc Req.
7193 if (eConnectionState_Associated != pHddStaCtx->conn_info.connState)
7194 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307195 hddLog(LOGE, FL("Called with Ie of length = %d when not associated\n"),
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07007196 ftie->ie_len);
7197 hddLog(LOGE, FL("Should be Re-assoc Req IEs\n"));
7198 }
7199
7200#ifdef WLAN_FEATURE_VOWIFI_11R_DEBUG
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307201 hddLog(LOGE, FL("%s called with Ie of length = %d\n"), __func__,
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07007202 ftie->ie_len);
7203#endif
7204
7205 // Pass the received FT IEs to SME
Gopichand Nakkala356fb102013-03-06 12:34:04 +05307206 sme_SetFTIEs( WLAN_HDD_GET_HAL_CTX(pAdapter), pAdapter->sessionId,
7207 (const u8 *)ftie->ie,
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07007208 ftie->ie_len);
7209 return 0;
7210}
7211#endif
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007212
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307213#ifdef FEATURE_WLAN_SCAN_PNO
7214
7215void hdd_cfg80211_sched_scan_done_callback(void *callbackContext,
7216 tSirPrefNetworkFoundInd *pPrefNetworkFoundInd)
7217{
7218 int ret;
7219 hdd_adapter_t* pAdapter = (hdd_adapter_t*)callbackContext;
7220 hdd_context_t *pHddCtx;
7221
7222 if (NULL == pAdapter)
7223 {
7224 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
7225 "%s: HDD adapter is Null", __func__);
7226 return ;
7227 }
7228
7229 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7230 if (NULL == pHddCtx)
7231 {
7232 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7233 "%s: HDD context is Null!!!", __func__);
7234 return ;
7235 }
7236
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05307237 spin_lock(&pHddCtx->schedScan_lock);
7238 if (TRUE == pHddCtx->isWiphySuspended)
7239 {
7240 pHddCtx->isSchedScanUpdatePending = TRUE;
7241 spin_unlock(&pHddCtx->schedScan_lock);
7242 hddLog(VOS_TRACE_LEVEL_INFO,
7243 "%s: Update cfg80211 scan database after it resume", __func__);
7244 return ;
7245 }
7246 spin_unlock(&pHddCtx->schedScan_lock);
7247
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307248 ret = wlan_hdd_cfg80211_update_bss(pHddCtx->wiphy, pAdapter);
7249
7250 if (0 > ret)
7251 hddLog(VOS_TRACE_LEVEL_INFO, "%s: NO SCAN result", __func__);
7252
7253 cfg80211_sched_scan_results(pHddCtx->wiphy);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05307254 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
7255 "%s: cfg80211 scan result database updated", __func__);
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307256}
7257
7258/*
7259 * FUNCTION: wlan_hdd_cfg80211_sched_scan_start
7260 * NL interface to enable PNO
7261 */
7262static int wlan_hdd_cfg80211_sched_scan_start(struct wiphy *wiphy,
7263 struct net_device *dev, struct cfg80211_sched_scan_request *request)
7264{
7265 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7266 tpSirPNOScanReq pPnoRequest = NULL;
7267 hdd_context_t *pHddCtx;
7268 tHalHandle hHal;
7269 v_U32_t i, indx, num_ch;
7270 u8 valid_ch[WNI_CFG_VALID_CHANNEL_LIST_LEN];
7271 u8 channels_allowed[WNI_CFG_VALID_CHANNEL_LIST_LEN];
7272 v_U32_t num_channels_allowed = WNI_CFG_VALID_CHANNEL_LIST_LEN;
7273 eHalStatus status = eHAL_STATUS_FAILURE;
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307274 int ret = 0;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307275
7276 if (NULL == pAdapter)
7277 {
7278 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
7279 "%s: HDD adapter is Null", __func__);
7280 return -ENODEV;
7281 }
7282
7283 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05307284 ret = wlan_hdd_validate_context(pHddCtx);
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307285
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05307286 if (0 != ret)
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307287 {
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05307288 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7289 "%s: HDD context is not valid", __func__);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307290 return -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307291 }
7292
7293 hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
7294 if (NULL == hHal)
7295 {
7296 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7297 "%s: HAL context is Null!!!", __func__);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05307298 return -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307299 }
7300
7301 pPnoRequest = (tpSirPNOScanReq) vos_mem_malloc(sizeof (tSirPNOScanReq));
7302 if (NULL == pPnoRequest)
7303 {
7304 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
7305 "%s: vos_mem_malloc failed", __func__);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307306 return -ENOMEM;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307307 }
7308
7309 pPnoRequest->enable = 1; /*Enable PNO */
7310 pPnoRequest->ucNetworksCount = request->n_match_sets;
7311
7312 if (( !pPnoRequest->ucNetworksCount ) ||
7313 ( pPnoRequest->ucNetworksCount > SIR_PNO_MAX_SUPP_NETWORKS ))
7314 {
7315 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7316 "Network input is not correct");
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307317 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307318 goto error;
7319 }
7320
7321 if ( SIR_PNO_MAX_NETW_CHANNELS_EX < request->n_channels )
7322 {
7323 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7324 "Incorrect number of channels");
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307325 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307326 goto error;
7327 }
7328
7329 /* Framework provides one set of channels(all)
7330 * common for all saved profile */
7331 if (0 != ccmCfgGetStr(hHal, WNI_CFG_VALID_CHANNEL_LIST,
7332 channels_allowed, &num_channels_allowed))
7333 {
7334 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7335 "%s: failed to get valid channel list", __func__);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307336 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307337 goto error;
7338 }
7339 /* Checking each channel against allowed channel list */
7340 num_ch = 0;
7341 for (i = 0; i < request->n_channels; i++)
7342 {
7343 for (indx = 0; indx < num_channels_allowed; indx++)
7344 {
7345 if (request->channels[i]->hw_value == channels_allowed[indx])
7346 {
7347 valid_ch[num_ch++] = request->channels[i]->hw_value;
7348 break ;
7349 }
7350 }
7351 }
7352
7353 /* Filling per profile params */
7354 for (i = 0; i < pPnoRequest->ucNetworksCount; i++)
7355 {
7356 pPnoRequest->aNetworks[i].ssId.length =
7357 request->match_sets[i].ssid.ssid_len;
7358
7359 if (( 0 == pPnoRequest->aNetworks[i].ssId.length ) ||
7360 ( pPnoRequest->aNetworks[i].ssId.length > 32 ) )
7361 {
7362 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7363 "SSID Len %d is not correct for network %d",
7364 pPnoRequest->aNetworks[i].ssId.length, i);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307365 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307366 goto error;
7367 }
7368
7369 memcpy(pPnoRequest->aNetworks[i].ssId.ssId,
7370 request->match_sets[i].ssid.ssid,
7371 request->match_sets[i].ssid.ssid_len);
7372 pPnoRequest->aNetworks[i].authentication = 0; /*eAUTH_TYPE_ANY*/
7373 pPnoRequest->aNetworks[i].encryption = 0; /*eED_ANY*/
7374 pPnoRequest->aNetworks[i].bcastNetwType = 0; /*eBCAST_UNKNOWN*/
7375
7376 /*Copying list of valid channel into request */
7377 memcpy(pPnoRequest->aNetworks[i].aChannels, valid_ch, num_ch);
7378 pPnoRequest->aNetworks[i].ucChannelCount = num_ch;
7379
7380 pPnoRequest->aNetworks[i].rssiThreshold = 0; //Default value
7381 }
7382
7383 /* framework provides interval in ms */
7384 pPnoRequest->scanTimers.ucScanTimersCount = 1;
7385 pPnoRequest->scanTimers.aTimerValues[0].uTimerValue =
7386 (request->interval)/1000;
7387 pPnoRequest->scanTimers.aTimerValues[0].uTimerRepeat = 0;
7388 pPnoRequest->modePNO = SIR_PNO_MODE_ON_SUSPEND;
7389
7390 status = sme_SetPreferredNetworkList(WLAN_HDD_GET_HAL_CTX(pAdapter),
7391 pPnoRequest, pAdapter->sessionId,
7392 hdd_cfg80211_sched_scan_done_callback, pAdapter);
7393 if (eHAL_STATUS_SUCCESS != status)
7394 {
7395 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7396 "Failed to enable PNO");
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307397 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307398 goto error;
7399 }
7400
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05307401 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
7402 "PNO scanRequest offloaded");
7403
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307404error:
7405 vos_mem_free(pPnoRequest);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307406 return ret;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307407}
7408
7409/*
7410 * FUNCTION: wlan_hdd_cfg80211_sched_scan_stop
7411 * NL interface to disable PNO
7412 */
7413static int wlan_hdd_cfg80211_sched_scan_stop(struct wiphy *wiphy,
7414 struct net_device *dev)
7415{
7416 eHalStatus status = eHAL_STATUS_FAILURE;
7417 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7418 hdd_context_t *pHddCtx;
7419 tHalHandle hHal;
7420 tpSirPNOScanReq pPnoRequest = NULL;
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307421 int ret = 0;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307422
7423 ENTER();
7424
7425 if (NULL == pAdapter)
7426 {
7427 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
7428 "%s: HDD adapter is Null", __func__);
7429 return -ENODEV;
7430 }
7431
7432 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307433
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307434 if (NULL == pHddCtx)
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307435 {
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05307436 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307437 "%s: HDD context is Null", __func__);
7438 return -ENODEV;
7439 }
7440
7441 /* The return 0 is intentional when isLogpInProgress and
7442 * isLoadUnloadInProgress. We did observe a crash due to a return of
7443 * failure in sched_scan_stop , especially for a case where the unload
7444 * of the happens at the same time. The function __cfg80211_stop_sched_scan
7445 * was clearing rdev->sched_scan_req only when the sched_scan_stop returns
7446 * success. If it returns a failure , then its next invocation due to the
7447 * clean up of the second interface will have the dev pointer corresponding
7448 * to the first one leading to a crash.
7449 */
7450 if (pHddCtx->isLogpInProgress)
7451 {
7452 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7453 "%s: LOGP in Progress. Ignore!!!", __func__);
7454 return ret;
7455 }
7456
7457 if (pHddCtx->isLoadUnloadInProgress)
7458 {
7459 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7460 "%s: Unloading/Loading in Progress. Ignore!!!", __func__);
7461 return ret;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307462 }
7463
7464 hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
7465 if (NULL == hHal)
7466 {
7467 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7468 "%s: HAL context is Null!!!", __func__);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05307469 return -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307470 }
7471
7472 pPnoRequest = (tpSirPNOScanReq) vos_mem_malloc(sizeof (tSirPNOScanReq));
7473 if (NULL == pPnoRequest)
7474 {
7475 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
7476 "%s: vos_mem_malloc failed", __func__);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307477 return -ENOMEM;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307478 }
7479
7480 memset(pPnoRequest, 0, sizeof (tSirPNOScanReq));
7481 pPnoRequest->enable = 0; /* Disable PNO */
7482 pPnoRequest->ucNetworksCount = 0;
7483
7484 status = sme_SetPreferredNetworkList(hHal, pPnoRequest,
7485 pAdapter->sessionId,
7486 NULL, pAdapter);
7487 if (eHAL_STATUS_SUCCESS != status)
7488 {
7489 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7490 "Failed to disabled PNO");
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307491 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307492 }
7493
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05307494 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
7495 "%s: PNO scan disabled", __func__);
7496
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307497 vos_mem_free(pPnoRequest);
7498
7499 EXIT();
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307500 return ret;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307501}
7502
7503#endif /*FEATURE_WLAN_SCAN_PNO*/
7504
7505
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007506#ifdef FEATURE_WLAN_TDLS
7507static int wlan_hdd_cfg80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
7508 u8 *peer, u8 action_code, u8 dialog_token,
7509 u16 status_code, const u8 *buf, size_t len)
7510{
7511
7512 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7513 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007514 u8 peerMac[6];
7515 VOS_STATUS status;
Gopichand Nakkala05922802013-03-14 12:23:19 -07007516 int max_sta_failed = 0;
Hoonki Leea34dd892013-02-05 22:56:02 -08007517 int responder;
Hoonki Leed37cbb32013-04-20 00:31:14 -07007518 long rc;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007519
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007520 if (NULL == pHddCtx || NULL == pHddCtx->cfg_ini)
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007521 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307522 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007523 "Invalid arguments");
7524 return -EINVAL;
7525 }
7526
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08007527 if (pHddCtx->isLogpInProgress)
7528 {
7529 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7530 "%s:LOGP in Progress. Ignore!!!", __func__);
Gopichand Nakkala05922802013-03-14 12:23:19 -07007531 wlan_hdd_tdls_set_link_status(pAdapter, peer, eTDLS_LINK_IDLE);
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08007532 return -EBUSY;
7533 }
7534
Hoonki Lee27511902013-03-14 18:19:06 -07007535 if (eTDLS_SUPPORT_NOT_ENABLED == pHddCtx->tdls_mode)
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007536 {
Hoonki Lee27511902013-03-14 18:19:06 -07007537 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
7538 "%s: TDLS mode is disabled OR not enabled in FW."
7539 MAC_ADDRESS_STR " action %d declined.",
7540 __func__, MAC_ADDR_ARRAY(peer), action_code);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007541 return -ENOTSUPP;
7542 }
Lee Hoonkic1262f22013-01-24 21:59:00 -08007543
Hoonki Lee27511902013-03-14 18:19:06 -07007544 /* other than teardown frame, other mgmt frames are not sent if disabled */
7545 if (SIR_MAC_TDLS_TEARDOWN != action_code)
7546 {
7547 /* if tdls_mode is disabled to respond to peer's request */
7548 if (eTDLS_SUPPORT_DISABLED == pHddCtx->tdls_mode)
7549 {
7550 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
7551 "%s: " MAC_ADDRESS_STR
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07007552 " TDLS mode is disabled. action %d declined.",
7553 __func__, MAC_ADDR_ARRAY(peer), action_code);
Hoonki Lee27511902013-03-14 18:19:06 -07007554
7555 return -ENOTSUPP;
7556 }
7557 }
7558
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007559 if (WLAN_IS_TDLS_SETUP_ACTION(action_code))
7560 {
Hoonki Leefb8df672013-04-10 18:20:34 -07007561 if (NULL != wlan_hdd_tdls_is_progress(pHddCtx, peer, TRUE, TRUE))
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007562 {
7563 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007564 "%s: " MAC_ADDRESS_STR
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07007565 " TDLS setup is ongoing. action %d declined.",
7566 __func__, MAC_ADDR_ARRAY(peer), action_code);
7567 return -EPERM;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007568 }
7569 }
7570
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007571 if (SIR_MAC_TDLS_SETUP_REQ == action_code ||
7572 SIR_MAC_TDLS_SETUP_RSP == action_code )
Lee Hoonkic1262f22013-01-24 21:59:00 -08007573 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08007574 if (HDD_MAX_NUM_TDLS_STA <= wlan_hdd_tdlsConnectedPeers(pAdapter))
Lee Hoonkic1262f22013-01-24 21:59:00 -08007575 {
7576 /* supplicant still sends tdls_mgmt(SETUP_REQ) even after
7577 we return error code at 'add_station()'. Hence we have this
7578 check again in addtion to add_station().
7579 Anyway, there is no hard to double-check. */
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007580 if (SIR_MAC_TDLS_SETUP_REQ == action_code)
Lee Hoonkic1262f22013-01-24 21:59:00 -08007581 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007582 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7583 "%s: " MAC_ADDRESS_STR
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07007584 " TDLS Max peer already connected. action %d declined.",
7585 __func__, MAC_ADDR_ARRAY(peer), action_code);
Gopichand Nakkala05922802013-03-14 12:23:19 -07007586 goto error;
Lee Hoonkic1262f22013-01-24 21:59:00 -08007587 }
7588 else
7589 {
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007590 /* maximum reached. tweak to send error code to peer and return
7591 error code to supplicant */
Lee Hoonkic1262f22013-01-24 21:59:00 -08007592 status_code = eSIR_MAC_UNSPEC_FAILURE_STATUS;
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007593 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7594 "%s: " MAC_ADDRESS_STR
7595 " TDLS Max peer already connected send response status %d",
7596 __func__, MAC_ADDR_ARRAY(peer), status_code);
Gopichand Nakkala05922802013-03-14 12:23:19 -07007597 max_sta_failed = -EPERM;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007598 /* fall through to send setup resp with failure status
7599 code */
Lee Hoonkic1262f22013-01-24 21:59:00 -08007600 }
7601 }
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007602 else
7603 {
7604 hddTdlsPeer_t *pTdlsPeer;
Gopichand Nakkala4327a152013-03-04 23:22:42 -08007605 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peer);
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07007606 if (pTdlsPeer && TDLS_IS_CONNECTED(pTdlsPeer))
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007607 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007608 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07007609 "%s:" MAC_ADDRESS_STR " already connected. action %d declined.",
7610 __func__, MAC_ADDR_ARRAY(peer), action_code);
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007611 return -EPERM;
7612 }
7613 }
Lee Hoonkic1262f22013-01-24 21:59:00 -08007614 }
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007615 vos_mem_copy(peerMac, peer, 6);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007616
Hoonki Lee1090c6a2013-01-16 17:40:54 -08007617#ifdef WLAN_FEATURE_TDLS_DEBUG
7618 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007619 "%s: " MAC_ADDRESS_STR " action %d, dialog_token %d status %d, len = %d",
7620 "tdls_mgmt", MAC_ADDR_ARRAY(peer),
7621 action_code, dialog_token, status_code, len);
Hoonki Lee1090c6a2013-01-16 17:40:54 -08007622#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007623
Hoonki Leea34dd892013-02-05 22:56:02 -08007624 /*Except teardown responder will not be used so just make 0*/
7625 responder = 0;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007626 if (SIR_MAC_TDLS_TEARDOWN == action_code)
Hoonki Leea34dd892013-02-05 22:56:02 -08007627 {
Gopichand Nakkala97a65fd2013-04-16 16:59:38 -07007628
7629 hddTdlsPeer_t *pTdlsPeer;
7630 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peerMac);
7631
7632 if(pTdlsPeer && TDLS_IS_CONNECTED(pTdlsPeer))
7633 responder = pTdlsPeer->is_responder;
7634 else
Hoonki Leea34dd892013-02-05 22:56:02 -08007635 {
Gopichand Nakkala97a65fd2013-04-16 16:59:38 -07007636 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7637 "%s: " MAC_ADDRESS_STR " peer doesn't exist or not connected %d dialog_token %d status %d, len = %d",
7638 __func__, MAC_ADDR_ARRAY(peer), (NULL == pTdlsPeer) ? -1 : pTdlsPeer->link_status,
7639 dialog_token, status_code, len);
7640 return -EPERM;
Hoonki Leea34dd892013-02-05 22:56:02 -08007641 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007642 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007643
Gopichand Nakkala2f1ff152013-07-01 11:27:43 +05307644 /* For explicit trigger of DIS_REQ come out of BMPS for
7645 successfully receiving DIS_RSP from peer. */
Hoonki Lee14621352013-04-16 17:51:19 -07007646 if ((SIR_MAC_TDLS_SETUP_RSP == action_code) ||
Gopichand Nakkala2f1ff152013-07-01 11:27:43 +05307647 (SIR_MAC_TDLS_DIS_RSP == action_code) ||
7648 (SIR_MAC_TDLS_DIS_REQ == action_code))
Hoonki Lee14621352013-04-16 17:51:19 -07007649 {
7650 if (TRUE == sme_IsPmcBmps(WLAN_HDD_GET_HAL_CTX(pAdapter)))
7651 {
7652 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
Gopichand Nakkala2f1ff152013-07-01 11:27:43 +05307653 "%s: Sending frame action_code %u.Disable BMPS", __func__, action_code);
Hoonki Lee14621352013-04-16 17:51:19 -07007654 hdd_disable_bmps_imps(pHddCtx, WLAN_HDD_INFRA_STATION);
7655 }
Gopichand Nakkala2f1ff152013-07-01 11:27:43 +05307656 if (SIR_MAC_TDLS_DIS_REQ != action_code)
7657 wlan_hdd_tdls_set_cap(pAdapter, peerMac, eTDLS_CAP_SUPPORTED);
Hoonki Lee14621352013-04-16 17:51:19 -07007658 }
7659
Hoonki Lee5305c3a2013-04-29 23:28:59 -07007660 /* make sure doesn't call send_mgmt() while it is pending */
7661 if (TDLS_CTX_MAGIC == pAdapter->mgmtTxCompletionStatus)
7662 {
7663 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7664 "%s: " MAC_ADDRESS_STR " action %d couldn't sent, as one is pending. return EBUSY\n",
7665 __func__, MAC_ADDR_ARRAY(peer), action_code);
7666 return -EBUSY;
7667 }
7668
7669 pAdapter->mgmtTxCompletionStatus = TDLS_CTX_MAGIC;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007670 INIT_COMPLETION(pAdapter->tdls_mgmt_comp);
7671
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007672 status = sme_SendTdlsMgmtFrame(WLAN_HDD_GET_HAL_CTX(pAdapter), pAdapter->sessionId,
Hoonki Leea34dd892013-02-05 22:56:02 -08007673 peerMac, action_code, dialog_token, status_code, (tANI_U8 *)buf, len, responder);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007674
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007675 if (VOS_STATUS_SUCCESS != status)
7676 {
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007677 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7678 "%s: sme_SendTdlsMgmtFrame failed!", __func__);
Hoonki Lee5305c3a2013-04-29 23:28:59 -07007679 pAdapter->mgmtTxCompletionStatus = FALSE;
Hoonki Lee14621352013-04-16 17:51:19 -07007680 wlan_hdd_tdls_check_bmps(pAdapter);
7681 goto error;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007682 }
7683
Hoonki Leed37cbb32013-04-20 00:31:14 -07007684 rc = wait_for_completion_interruptible_timeout(&pAdapter->tdls_mgmt_comp,
7685 msecs_to_jiffies(WAIT_TIME_TDLS_MGMT));
7686
7687 if ((rc <= 0) || (TRUE != pAdapter->mgmtTxCompletionStatus))
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007688 {
Hoonki Leed37cbb32013-04-20 00:31:14 -07007689 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7690 "%s: Mgmt Tx Completion failed status %ld TxCompletion %lu",
7691 __func__, rc, pAdapter->mgmtTxCompletionStatus);
Hoonki Lee5305c3a2013-04-29 23:28:59 -07007692 pAdapter->mgmtTxCompletionStatus = FALSE;
Hoonki Leed37cbb32013-04-20 00:31:14 -07007693 wlan_hdd_tdls_check_bmps(pAdapter);
7694 goto error;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007695 }
7696
Gopichand Nakkala05922802013-03-14 12:23:19 -07007697 if (max_sta_failed)
Hoonki Lee14621352013-04-16 17:51:19 -07007698 {
7699 wlan_hdd_tdls_check_bmps(pAdapter);
Gopichand Nakkala05922802013-03-14 12:23:19 -07007700 return max_sta_failed;
Hoonki Lee14621352013-04-16 17:51:19 -07007701 }
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007702
Hoonki Leea34dd892013-02-05 22:56:02 -08007703 if (SIR_MAC_TDLS_SETUP_RSP == action_code)
7704 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08007705 wlan_hdd_tdls_set_responder(pAdapter, peerMac, TRUE);
Hoonki Leea34dd892013-02-05 22:56:02 -08007706 }
7707 else if (SIR_MAC_TDLS_SETUP_CNF == action_code)
7708 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08007709 wlan_hdd_tdls_set_responder(pAdapter, peerMac, FALSE);
Hoonki Leea34dd892013-02-05 22:56:02 -08007710 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007711
7712 return 0;
Gopichand Nakkala05922802013-03-14 12:23:19 -07007713error:
7714 /* max_sta_failed ; we didn't set to CONNECTING for this case,
7715 because we already know that this transaction will be failed,
7716 but we weren't sure if supplicant call DISABLE_LINK or not. So,
7717 to be safe, do not change the state mahine.
7718 */
7719 if(max_sta_failed == 0 &&
7720 (WLAN_IS_TDLS_SETUP_ACTION(action_code)))
7721 wlan_hdd_tdls_set_link_status(pAdapter, peerMac, eTDLS_LINK_IDLE);
7722 return -EPERM;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007723}
7724
7725static int wlan_hdd_cfg80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
7726 u8 *peer, enum nl80211_tdls_operation oper)
7727{
7728 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7729 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307730 int status;
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05307731#ifdef FEATURE_WLAN_TDLS_OXYGEN_DISAPPEAR_AP
7732 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05307733 tANI_U8 staIdx;
7734#endif
Hoonki Lee1090c6a2013-01-16 17:40:54 -08007735#ifdef WLAN_FEATURE_TDLS_DEBUG
7736 const char *tdls_oper_str[]= {
7737 "NL80211_TDLS_DISCOVERY_REQ",
7738 "NL80211_TDLS_SETUP",
7739 "NL80211_TDLS_TEARDOWN",
7740 "NL80211_TDLS_ENABLE_LINK",
7741 "NL80211_TDLS_DISABLE_LINK",
Gopichand Nakkala29d00192013-06-20 19:03:52 +05307742 "NL80211_TDLS_UNKNOWN_OPER"};
Hoonki Lee1090c6a2013-01-16 17:40:54 -08007743#endif
Hoonki Lee5305c3a2013-04-29 23:28:59 -07007744 hddTdlsPeer_t *pTdlsPeer;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007745
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307746 if ( NULL == peer )
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007747 {
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007748 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Chilam Ngc4244af2013-04-01 15:37:32 -07007749 "%s: Invalid arguments", __func__);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007750 return -EINVAL;
7751 }
Hoonki Lee1090c6a2013-01-16 17:40:54 -08007752
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307753 status = wlan_hdd_validate_context(pHddCtx);
7754
7755 if (0 != status)
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08007756 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307757 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7758 "%s: HDD context is not valid", __func__);
7759 return status;
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08007760 }
7761
Hoonki Lee5305c3a2013-04-29 23:28:59 -07007762 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peer);
7763
7764 if ( NULL == pTdlsPeer ) {
7765 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: " MAC_ADDRESS_STR " (oper %d) not exsting. ignored",
7766 __func__, MAC_ADDR_ARRAY(peer), (int)oper);
7767 return -EINVAL;
7768 }
7769
Hoonki Lee1090c6a2013-01-16 17:40:54 -08007770#ifdef WLAN_FEATURE_TDLS_DEBUG
7771 if((int)oper > 4)
7772 oper = 5;
7773
7774 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Hoonki Lee5305c3a2013-04-29 23:28:59 -07007775 "%s: " MAC_ADDRESS_STR " link_status %d (%s) ", "tdls_oper",
7776 MAC_ADDR_ARRAY(peer), pTdlsPeer->link_status,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007777 tdls_oper_str[(int)oper]);
Hoonki Lee1090c6a2013-01-16 17:40:54 -08007778#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007779
7780 if( FALSE == pHddCtx->cfg_ini->fEnableTDLSSupport ||
Hoonki Lee1090c6a2013-01-16 17:40:54 -08007781 FALSE == sme_IsFeatureSupportedByFW(TDLS))
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007782 {
Hoonki Lee1090c6a2013-01-16 17:40:54 -08007783 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Chilam Ngc4244af2013-04-01 15:37:32 -07007784 "TDLS Disabled in INI OR not enabled in FW. "
7785 "Cannot process TDLS commands");
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007786 return -ENOTSUPP;
7787 }
7788
7789 switch (oper) {
7790 case NL80211_TDLS_ENABLE_LINK:
7791 {
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007792 VOS_STATUS status;
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05307793 tCsrTdlsLinkEstablishParams tdlsLinkEstablishParams;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007794
Gopichand Nakkala2f4a2822013-04-17 11:22:01 -07007795 if (!TDLS_STA_INDEX_VALID(pTdlsPeer->staId))
7796 {
7797 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Staion Index %u "
7798 MAC_ADDRESS_STR " failed",
7799 __func__, pTdlsPeer->staId, MAC_ADDR_ARRAY(peer));
7800 return -EINVAL;
7801 }
7802
Hoonki Lee5305c3a2013-04-29 23:28:59 -07007803 if (eTDLS_LINK_CONNECTED != pTdlsPeer->link_status)
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007804 {
Gopichand Nakkala24be5312013-07-02 16:47:12 +05307805 long ret;
7806
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05307807 if (0 != wlan_hdd_tdls_get_link_establish_params(pAdapter, peer,&tdlsLinkEstablishParams)) {
7808 return -EINVAL;
7809 }
7810 INIT_COMPLETION(pAdapter->tdls_link_establish_req_comp);
7811
7812 sme_SendTdlsLinkEstablishParams(WLAN_HDD_GET_HAL_CTX(pAdapter),
7813 pAdapter->sessionId, peer, &tdlsLinkEstablishParams);
7814 /* Send TDLS peer UAPSD capabilities to the firmware and
7815 * register with the TL on after the response for this operation
7816 * is received .
7817 */
Gopichand Nakkala24be5312013-07-02 16:47:12 +05307818 ret = wait_for_completion_interruptible_timeout(&pAdapter->tdls_link_establish_req_comp,
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05307819 msecs_to_jiffies(WAIT_TIME_TDLS_LINK_ESTABLISH_REQ));
Gopichand Nakkala24be5312013-07-02 16:47:12 +05307820 if (ret <= 0)
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05307821 {
7822 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7823 "%s: Link Establish Request Faled Status %ld",
Gopichand Nakkala24be5312013-07-02 16:47:12 +05307824 __func__, ret);
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05307825 return -EINVAL;
7826 }
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07007827 wlan_hdd_tdls_set_peer_link_status(pTdlsPeer, eTDLS_LINK_CONNECTED);
Gopichand Nakkala471708b2013-06-04 20:03:01 +05307828 /* Mark TDLS client Authenticated .*/
7829 status = WLANTL_ChangeSTAState( pHddCtx->pvosContext,
7830 pTdlsPeer->staId,
7831 WLANTL_STA_AUTHENTICATED);
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07007832 if (VOS_STATUS_SUCCESS == status)
7833 {
Hoonki Lee14621352013-04-16 17:51:19 -07007834 if (pTdlsPeer->is_responder == 0)
7835 {
7836 v_U8_t staId = (v_U8_t)pTdlsPeer->staId;
7837
7838 wlan_hdd_tdls_timer_restart(pAdapter,
7839 &pTdlsPeer->initiatorWaitTimeoutTimer,
7840 WAIT_TIME_TDLS_INITIATOR);
7841 /* suspend initiator TX until it receives direct packet from the
7842 reponder or WAIT_TIME_TDLS_INITIATOR timer expires */
7843 WLANTL_SuspendDataTx( (WLAN_HDD_GET_CTX(pAdapter))->pvosContext,
7844 &staId, NULL);
7845 }
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07007846 wlan_hdd_tdls_increment_peer_count(pAdapter);
7847 }
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007848 wlan_hdd_tdls_check_bmps(pAdapter);
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05307849
7850 /* Update TL about the UAPSD masks , to route the packets to firmware */
Gopichand Nakkala574f6d12013-06-27 19:38:43 +05307851 if ((TRUE == pHddCtx->cfg_ini->fEnableTDLSBufferSta)
7852 || pHddCtx->cfg_ini->fTDLSUapsdMask )
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05307853 {
Gopichand Nakkala574f6d12013-06-27 19:38:43 +05307854 int ac;
7855 uint8 ucAc[4] = { WLANTL_AC_VO,
7856 WLANTL_AC_VI,
7857 WLANTL_AC_BK,
7858 WLANTL_AC_BE };
7859 uint8 tlTid[4] = { 7, 5, 2, 3 } ;
7860 for(ac=0; ac < 4; ac++)
7861 {
7862 status = WLANTL_EnableUAPSDForAC( (WLAN_HDD_GET_CTX(pAdapter))->pvosContext,
7863 pTdlsPeer->staId, ucAc[ac],
7864 tlTid[ac], tlTid[ac], 0, 0,
7865 WLANTL_BI_DIR );
7866 }
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05307867 }
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007868 }
7869
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007870 }
7871 break;
7872 case NL80211_TDLS_DISABLE_LINK:
Lee Hoonkic1262f22013-01-24 21:59:00 -08007873 {
Hoonki Lee5305c3a2013-04-29 23:28:59 -07007874 if(TDLS_STA_INDEX_VALID(pTdlsPeer->staId))
Lee Hoonkic1262f22013-01-24 21:59:00 -08007875 {
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07007876 long status;
7877
7878 INIT_COMPLETION(pAdapter->tdls_del_station_comp);
7879
Lee Hoonkic1262f22013-01-24 21:59:00 -08007880 sme_DeleteTdlsPeerSta( WLAN_HDD_GET_HAL_CTX(pAdapter),
7881 pAdapter->sessionId, peer );
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07007882
7883 status = wait_for_completion_interruptible_timeout(&pAdapter->tdls_del_station_comp,
7884 msecs_to_jiffies(WAIT_TIME_TDLS_DEL_STA));
7885 if (status <= 0)
7886 {
Hoonki Lee5305c3a2013-04-29 23:28:59 -07007887 wlan_hdd_tdls_set_peer_link_status(pTdlsPeer, eTDLS_LINK_IDLE);
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07007888 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7889 "%s: Del station failed status %ld",
7890 __func__, status);
7891 return -EPERM;
7892 }
Hoonki Lee5305c3a2013-04-29 23:28:59 -07007893 wlan_hdd_tdls_set_peer_link_status(pTdlsPeer, eTDLS_LINK_IDLE);
Lee Hoonkic1262f22013-01-24 21:59:00 -08007894 }
7895 else
7896 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007897 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7898 "%s: TDLS Peer Station doesn't exist.", __func__);
Lee Hoonkic1262f22013-01-24 21:59:00 -08007899 }
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05307900#ifdef FEATURE_WLAN_TDLS_OXYGEN_DISAPPEAR_AP
7901 if (pHddTdlsCtx->defer_link_lost_indication)
7902 {
7903 if (( TRUE == pHddCtx->cfg_ini->fEnableTDLSOxygenSupport ) &&
7904 (wlan_hdd_tdlsConnectedPeers(pAdapter) == 0))
7905 {
7906 status = wlan_hdd_disconnect(pAdapter, eCSR_DISCONNECT_REASON_UNSPECIFIED);
7907 if ( 0 != status)
7908 {
7909 hddLog(VOS_TRACE_LEVEL_ERROR,
7910 "%s wlan_hdd_disconnect failure, returned %d \n",
7911 __func__, (int)status );
7912 return -EINVAL;
7913 }
7914 }
7915 }
7916#endif
Lee Hoonkic1262f22013-01-24 21:59:00 -08007917 }
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007918 break;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007919 case NL80211_TDLS_TEARDOWN:
7920 case NL80211_TDLS_SETUP:
7921 case NL80211_TDLS_DISCOVERY_REQ:
7922 /* We don't support in-driver setup/teardown/discovery */
7923 return -ENOTSUPP;
7924 default:
7925 return -ENOTSUPP;
7926 }
7927 return 0;
7928}
Chilam NG571c65a2013-01-19 12:27:36 +05307929
7930int wlan_hdd_cfg80211_send_tdls_discover_req(struct wiphy *wiphy,
7931 struct net_device *dev, u8 *peer)
7932{
7933 hddLog(VOS_TRACE_LEVEL_INFO, "tdls send discover req: %x %x %x %x %x %x",
7934 peer[0], peer[1], peer[2], peer[3], peer[4], peer[5]);
7935
7936 return wlan_hdd_cfg80211_tdls_mgmt(wiphy, dev, peer,
7937 WLAN_TDLS_DISCOVERY_REQUEST, 1, 0, NULL, 0);
7938}
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007939#endif
7940
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05307941#ifdef WLAN_FEATURE_GTK_OFFLOAD
7942/*
7943 * FUNCTION: wlan_hdd_cfg80211_update_replayCounterCallback
7944 * Callback rountine called upon receiving response for
7945 * get offload info
7946 */
7947void wlan_hdd_cfg80211_update_replayCounterCallback(void *callbackContext,
7948 tpSirGtkOffloadGetInfoRspParams pGtkOffloadGetInfoRsp)
7949{
7950
7951 hdd_adapter_t *pAdapter = (hdd_adapter_t *)callbackContext;
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05307952 tANI_U8 tempReplayCounter[8];
7953 hdd_station_ctx_t *pHddStaCtx;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05307954
7955 ENTER();
7956
7957 if (NULL == pAdapter)
7958 {
7959 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
7960 "%s: HDD adapter is Null", __func__);
7961 return ;
7962 }
7963
7964 if (NULL == pGtkOffloadGetInfoRsp)
7965 {
7966 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7967 "%s: pGtkOffloadGetInfoRsp is Null", __func__);
7968 return ;
7969 }
7970
7971 if (VOS_STATUS_SUCCESS != pGtkOffloadGetInfoRsp->ulStatus)
7972 {
7973 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7974 "%s: wlan Failed to get replay counter value",
7975 __func__);
7976 return ;
7977 }
7978
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05307979 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
7980 /* Update replay counter */
7981 pHddStaCtx->gtkOffloadReqParams.ullKeyReplayCounter =
7982 pGtkOffloadGetInfoRsp->ullKeyReplayCounter;
7983
7984 {
7985 /* changing from little to big endian since supplicant
7986 * works on big endian format
7987 */
7988 int i;
7989 tANI_U8 *p = (tANI_U8 *)&pGtkOffloadGetInfoRsp->ullKeyReplayCounter;
7990
7991 for (i = 0; i < 8; i++)
7992 {
7993 tempReplayCounter[7-i] = (tANI_U8)p[i];
7994 }
7995 }
7996
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05307997 /* Update replay counter to NL */
7998 cfg80211_gtk_rekey_notify(pAdapter->dev, pGtkOffloadGetInfoRsp->bssId,
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05307999 tempReplayCounter, GFP_KERNEL);
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308000}
8001
8002/*
8003 * FUNCTION: wlan_hdd_cfg80211_set_rekey_data
8004 * This function is used to offload GTK rekeying job to the firmware.
8005 */
8006int wlan_hdd_cfg80211_set_rekey_data(struct wiphy *wiphy, struct net_device *dev,
8007 struct cfg80211_gtk_rekey_data *data)
8008{
8009 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8010 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
8011 hdd_station_ctx_t *pHddStaCtx;
8012 tHalHandle hHal;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308013 int result;
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308014 tSirGtkOffloadParams hddGtkOffloadReqParams;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308015 eHalStatus status = eHAL_STATUS_FAILURE;
8016
8017 ENTER();
8018
8019 if (NULL == pAdapter)
8020 {
8021 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8022 "%s: HDD adapter is Null", __func__);
8023 return -ENODEV;
8024 }
8025
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308026 result = wlan_hdd_validate_context(pHddCtx);
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308027
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308028 if (0 != result)
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308029 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308030 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8031 "%s: HDD context is not valid", __func__);
8032 return result;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308033 }
8034
8035 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
8036 hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
8037 if (NULL == hHal)
8038 {
8039 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8040 "%s: HAL context is Null!!!", __func__);
8041 return -EAGAIN;
8042 }
8043
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308044 pHddStaCtx->gtkOffloadReqParams.ulFlags = GTK_OFFLOAD_ENABLE;
8045 memcpy(pHddStaCtx->gtkOffloadReqParams.aKCK, data->kck, NL80211_KCK_LEN);
8046 memcpy(pHddStaCtx->gtkOffloadReqParams.aKEK, data->kek, NL80211_KEK_LEN);
8047 memcpy(pHddStaCtx->gtkOffloadReqParams.bssId, &pHddStaCtx->conn_info.bssId,
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308048 WNI_CFG_BSSID_LEN);
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308049 {
8050 /* changing from big to little endian since driver
8051 * works on little endian format
8052 */
8053 tANI_U8 *p =
8054 (tANI_U8 *)&pHddStaCtx->gtkOffloadReqParams.ullKeyReplayCounter;
8055 int i;
8056
8057 for (i = 0; i < 8; i++)
8058 {
8059 p[7-i] = data->replay_ctr[i];
8060 }
8061 }
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308062
8063 if (TRUE == pHddCtx->hdd_wlan_suspended)
8064 {
8065 /* if wlan is suspended, enable GTK offload directly from here */
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308066 memcpy(&hddGtkOffloadReqParams, &pHddStaCtx->gtkOffloadReqParams,
8067 sizeof (tSirGtkOffloadParams));
8068 status = sme_SetGTKOffload(hHal, &hddGtkOffloadReqParams,
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308069 pAdapter->sessionId);
8070
8071 if (eHAL_STATUS_SUCCESS != status)
8072 {
8073 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8074 "%s: sme_SetGTKOffload failed, returned %d",
8075 __func__, status);
8076 return status;
8077 }
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308078 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8079 "%s: sme_SetGTKOffload successfull", __func__);
8080 }
8081 else
8082 {
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308083 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8084 "%s: wlan not suspended GTKOffload request is stored",
8085 __func__);
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308086 }
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308087
8088 return eHAL_STATUS_SUCCESS;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308089}
8090#endif /*WLAN_FEATURE_GTK_OFFLOAD*/
8091
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05308092/*
8093 * FUNCTION: wlan_hdd_cfg80211_set_mac_acl
8094 * This function is used to set access control policy
8095 */
8096static int wlan_hdd_cfg80211_set_mac_acl(struct wiphy *wiphy,
8097 struct net_device *dev, const struct cfg80211_acl_data *params)
8098{
8099 int i;
8100 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8101 hdd_hostapd_state_t *pHostapdState;
8102 tsap_Config_t *pConfig;
8103 v_CONTEXT_t pVosContext = NULL;
8104 hdd_context_t *pHddCtx;
8105 int status;
8106
8107 ENTER();
8108
8109 if (NULL == pAdapter)
8110 {
8111 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8112 "%s: HDD adapter is Null", __func__);
8113 return -ENODEV;
8114 }
8115
8116 if (NULL == params)
8117 {
8118 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8119 "%s: params is Null", __func__);
8120 return -EINVAL;
8121 }
8122
8123 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
8124 status = wlan_hdd_validate_context(pHddCtx);
8125
8126 if (0 != status)
8127 {
8128 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8129 "%s: HDD context is not valid", __func__);
8130 return status;
8131 }
8132
8133 pVosContext = pHddCtx->pvosContext;
8134 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
8135
8136 if (NULL == pHostapdState)
8137 {
8138 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8139 "%s: pHostapdState is Null", __func__);
8140 return -EINVAL;
8141 }
8142
8143 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,"acl policy: = %d"
8144 "no acl entries = %d", params->acl_policy, params->n_acl_entries);
8145
8146 if (WLAN_HDD_SOFTAP == pAdapter->device_mode)
8147 {
8148 pConfig = &pAdapter->sessionCtx.ap.sapConfig;
8149
8150 /* default value */
8151 pConfig->num_accept_mac = 0;
8152 pConfig->num_deny_mac = 0;
8153
8154 /**
8155 * access control policy
8156 * @NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED: Deny stations which are
8157 * listed in hostapd.deny file.
8158 * @NL80211_ACL_POLICY_DENY_UNLESS_LISTED: Allow stations which are
8159 * listed in hostapd.accept file.
8160 */
8161 if (NL80211_ACL_POLICY_DENY_UNLESS_LISTED == params->acl_policy)
8162 {
8163 pConfig->SapMacaddr_acl = eSAP_DENY_UNLESS_ACCEPTED;
8164 }
8165 else if (NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED == params->acl_policy)
8166 {
8167 pConfig->SapMacaddr_acl = eSAP_ACCEPT_UNLESS_DENIED;
8168 }
8169 else
8170 {
8171 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8172 "%s:Acl Policy : %d is not supported",
8173 __func__, params->acl_policy);
8174 return -ENOTSUPP;
8175 }
8176
8177 if (eSAP_DENY_UNLESS_ACCEPTED == pConfig->SapMacaddr_acl)
8178 {
8179 pConfig->num_accept_mac = params->n_acl_entries;
8180 for (i = 0; i < params->n_acl_entries; i++)
8181 {
8182 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8183 "** Add ACL MAC entry %i in WhiletList :"
8184 MAC_ADDRESS_STR, i,
8185 MAC_ADDR_ARRAY(params->mac_addrs[i].addr));
8186
8187 vos_mem_copy(&pConfig->accept_mac[i], params->mac_addrs[i].addr,
8188 sizeof(qcmacaddr));
8189 }
8190 }
8191 else if (eSAP_ACCEPT_UNLESS_DENIED == pConfig->SapMacaddr_acl)
8192 {
8193 pConfig->num_deny_mac = params->n_acl_entries;
8194 for (i = 0; i < params->n_acl_entries; i++)
8195 {
8196 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8197 "** Add ACL MAC entry %i in BlackList :"
8198 MAC_ADDRESS_STR, i,
8199 MAC_ADDR_ARRAY(params->mac_addrs[i].addr));
8200
8201 vos_mem_copy(&pConfig->deny_mac[i], params->mac_addrs[i].addr,
8202 sizeof(qcmacaddr));
8203 }
8204 }
8205
8206 if (VOS_STATUS_SUCCESS != WLANSAP_SetMacACL(pVosContext, pConfig))
8207 {
8208 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8209 "%s: SAP Set Mac Acl fail", __func__);
8210 return -EINVAL;
8211 }
8212 }
8213 else
8214 {
8215 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8216 "%s: Invalid device_mode = %d",
8217 __func__, pAdapter->device_mode);
8218 return -EINVAL;
8219 }
8220
8221 return 0;
8222}
8223
Leo Chang9056f462013-08-01 19:21:11 -07008224#ifdef WLAN_NL80211_TESTMODE
8225#ifdef FEATURE_WLAN_LPHB
8226static void wlan_hdd_cfg80211_lphb_wait_timeout_ind_handler
8227(
8228 void *pAdapter,
8229 void *indCont
8230)
8231{
8232 tSirLPHBTimeoutInd *lphbTimeoutInd;
8233 struct sk_buff *skb;
8234
8235 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8236 "LPHB wait timeout indication arrived");
8237
8238 if (NULL == indCont)
8239 {
8240 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8241 "LPHB timeout, invalid argument");
8242 return;
8243 }
8244
8245 lphbTimeoutInd = (tSirLPHBTimeoutInd *)indCont;
8246 skb = cfg80211_testmode_alloc_event_skb(
8247 ((hdd_adapter_t *)pAdapter)->wdev.wiphy,
8248 sizeof(tSirLPHBTimeoutInd),
8249 GFP_ATOMIC);
8250 if (!skb)
8251 {
8252 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8253 "LPHB timeout, NL buffer alloc fail");
8254 return;
8255 }
8256
8257 NLA_PUT_U32(skb, WLAN_HDD_TM_ATTR_CMD, WLAN_HDD_TM_CMD_WLAN_HB);
8258 NLA_PUT_U32(skb, WLAN_HDD_TM_ATTR_TYPE, lphbTimeoutInd->protocolType);
8259 NLA_PUT(skb, WLAN_HDD_TM_ATTR_DATA,
8260 sizeof(tSirLPHBTimeoutInd), lphbTimeoutInd);
8261 cfg80211_testmode_event(skb, GFP_ATOMIC);
8262 return;
8263
8264nla_put_failure:
8265 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8266 "NLA Put fail");
8267 kfree_skb(skb);
8268
8269 return;
8270}
8271#endif /* FEATURE_WLAN_LPHB */
8272
8273static int wlan_hdd_cfg80211_testmode(struct wiphy *wiphy, void *data, int len)
8274{
8275 struct nlattr *tb[WLAN_HDD_TM_ATTR_MAX + 1];
8276 int err = 0;
8277#ifdef FEATURE_WLAN_LPHB
8278 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
8279#endif /* FEATURE_WLAN_LPHB */
8280
8281 err = nla_parse(tb, WLAN_HDD_TM_ATTR_MAX, data, len, wlan_hdd_tm_policy);
8282 if (err)
8283 {
8284 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8285 "%s Testmode INV ATTR", __func__);
8286 return err;
8287 }
8288
8289 if (!tb[WLAN_HDD_TM_ATTR_CMD])
8290 {
8291 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8292 "%s Testmode INV CMD", __func__);
8293 return -EINVAL;
8294 }
8295
8296 switch (nla_get_u32(tb[WLAN_HDD_TM_ATTR_CMD]))
8297 {
8298#ifdef FEATURE_WLAN_LPHB
8299 /* Low Power Heartbeat configuration request */
8300 case WLAN_HDD_TM_CMD_WLAN_HB:
8301 {
8302 int buf_len;
8303 void *buf;
8304 tSirLPHBReq *hb_params = NULL;
8305
8306 if (!tb[WLAN_HDD_TM_ATTR_DATA])
8307 {
8308 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8309 "%s Testmode INV DATA", __func__);
8310 return -EINVAL;
8311 }
8312
8313 buf = nla_data(tb[WLAN_HDD_TM_ATTR_DATA]);
8314 buf_len = nla_len(tb[WLAN_HDD_TM_ATTR_DATA]);
8315 hb_params = (tSirLPHBReq *)vos_mem_malloc(sizeof(tSirLPHBReq));
8316 if (NULL == hb_params)
8317 {
8318 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8319 "%s Request Buffer Alloc Fail", __func__);
8320 return -EINVAL;
8321 }
8322
8323 vos_mem_copy(hb_params, buf, buf_len);
8324
8325 /* LPHB enable and disable request will send to FW
8326 * when host suspend and resume
8327 * host suspend -> enable LPHB
8328 * host resume -> disable LPHB
8329 * if host is not suspend, cache into HDD context
8330 * and when host goes to suspend, send request to FW */
8331 if ((LPHB_SET_EN_PARAMS_INDID == hb_params->cmd) &&
8332 (!pHddCtx->hdd_wlan_suspended))
8333 {
8334 /* Feature enable command cache into HDD context,
8335 * if WLAN is not suspend
8336 * When WLAN goes into suspend, send enable command to FW */
8337 pHddCtx->lphbEnableReq.enable =
8338 hb_params->params.lphbEnableReq.enable;
8339 pHddCtx->lphbEnableReq.item =
8340 hb_params->params.lphbEnableReq.item;
8341 pHddCtx->lphbEnableReq.session =
8342 hb_params->params.lphbEnableReq.session;
8343 vos_mem_free(hb_params);
8344 }
8345 else
8346 {
8347 eHalStatus smeStatus;
8348
8349 /* If WLAN is suspend state, send enable command immediately */
8350 smeStatus = sme_LPHBConfigReq((tHalHandle)(pHddCtx->hHal),
8351 hb_params,
8352 wlan_hdd_cfg80211_lphb_wait_timeout_ind_handler);
8353 if (eHAL_STATUS_SUCCESS != smeStatus)
8354 {
8355 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8356 "LPHB Config Fail, disable");
8357 pHddCtx->lphbEnableReq.enable = 0;
8358 vos_mem_free(hb_params);
8359 }
8360 }
8361 return 0;
8362 }
8363#endif /* FEATURE_WLAN_LPHB */
8364 default:
8365 return -EOPNOTSUPP;
8366 }
8367
8368 return err;
8369}
8370#endif /* CONFIG_NL80211_TESTMODE */
8371
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05308372static int wlan_hdd_cfg80211_dump_survey(struct wiphy *wiphy,
8373 struct net_device *dev,
8374 int idx, struct survey_info *survey)
8375{
8376 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8377 hdd_context_t *pHddCtx;
Mihir Sheted9072e02013-08-21 17:02:29 +05308378 hdd_station_ctx_t *pHddStaCtx;
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05308379 tHalHandle halHandle;
Mihir Sheted9072e02013-08-21 17:02:29 +05308380 v_U32_t channel = 0, freq = 0; /* Initialization Required */
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05308381 v_S7_t snr,rssi;
8382 int status, i, j, filled = 0;
8383
8384 ENTER();
8385
8386
8387 if (NULL == pAdapter)
8388 {
8389 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8390 "%s: HDD adapter is Null", __func__);
8391 return -ENODEV;
8392 }
8393
8394 if (NULL == wiphy)
8395 {
8396 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8397 "%s: wiphy is Null", __func__);
8398 return -ENODEV;
8399 }
8400
8401 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
8402 status = wlan_hdd_validate_context(pHddCtx);
8403
8404 if (0 != status)
8405 {
8406 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8407 "%s: HDD context is not valid", __func__);
8408 return status;
8409 }
8410
Mihir Sheted9072e02013-08-21 17:02:29 +05308411 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
8412
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05308413 if (0 == pHddCtx->cfg_ini->fEnableSNRMonitoring ||
Mihir Sheted9072e02013-08-21 17:02:29 +05308414 0 != pAdapter->survey_idx ||
8415 eConnectionState_Associated != pHddStaCtx->conn_info.connState)
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05308416 {
8417 /* The survey dump ops when implemented completely is expected to
8418 * return a survey of all channels and the ops is called by the
8419 * kernel with incremental values of the argument 'idx' till it
8420 * returns -ENONET. But we can only support the survey for the
8421 * operating channel for now. survey_idx is used to track
8422 * that the ops is called only once and then return -ENONET for
8423 * the next iteration
8424 */
8425 pAdapter->survey_idx = 0;
8426 return -ENONET;
8427 }
8428
8429 halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
8430
8431 wlan_hdd_get_snr(pAdapter, &snr);
8432 wlan_hdd_get_rssi(pAdapter, &rssi);
8433
8434 sme_GetOperationChannel(halHandle, &channel, pAdapter->sessionId);
8435 hdd_wlan_get_freq(channel, &freq);
8436
8437
8438 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
8439 {
8440 if (NULL == wiphy->bands[i])
8441 {
8442 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
8443 "%s: wiphy->bands[i] is NULL, i = %d", __func__, i);
8444 continue;
8445 }
8446
8447 for (j = 0; j < wiphy->bands[i]->n_channels; j++)
8448 {
8449 struct ieee80211_supported_band *band = wiphy->bands[i];
8450
8451 if (band->channels[j].center_freq == (v_U16_t)freq)
8452 {
8453 survey->channel = &band->channels[j];
8454 /* The Rx BDs contain SNR values in dB for the received frames
8455 * while the supplicant expects noise. So we calculate and
8456 * return the value of noise (dBm)
8457 * SNR (dB) = RSSI (dBm) - NOISE (dBm)
8458 */
8459 survey->noise = rssi - snr;
8460 survey->filled = SURVEY_INFO_NOISE_DBM;
8461 filled = 1;
8462 }
8463 }
8464 }
8465
8466 if (filled)
8467 pAdapter->survey_idx = 1;
8468 else
8469 {
8470 pAdapter->survey_idx = 0;
8471 return -ENONET;
8472 }
8473
8474 return 0;
8475}
8476
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308477/*
8478 * FUNCTION: wlan_hdd_cfg80211_resume_wlan
8479 * this is called when cfg80211 driver resume
8480 * driver updates latest sched_scan scan result(if any) to cfg80211 database
8481 */
8482int wlan_hdd_cfg80211_resume_wlan(struct wiphy *wiphy)
8483{
8484 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
8485 hdd_adapter_t *pAdapter;
8486 hdd_adapter_list_node_t *pAdapterNode, *pNext;
8487 VOS_STATUS status = VOS_STATUS_SUCCESS;
8488
8489 ENTER();
8490
8491 if ( NULL == pHddCtx )
8492 {
8493 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8494 "%s: HddCtx validation failed", __func__);
8495 return 0;
8496 }
8497
8498 if (pHddCtx->isLogpInProgress)
8499 {
8500 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8501 "%s: LOGP in Progress. Ignore!!!", __func__);
8502 return 0;
8503 }
8504
8505 if (pHddCtx->isLoadUnloadInProgress)
8506 {
8507 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8508 "%s: Unloading/Loading in Progress. Ignore!!!", __func__);
8509 return 0;
8510 }
8511
8512 spin_lock(&pHddCtx->schedScan_lock);
8513 pHddCtx->isWiphySuspended = FALSE;
8514 if (TRUE != pHddCtx->isSchedScanUpdatePending)
8515 {
8516 spin_unlock(&pHddCtx->schedScan_lock);
8517 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8518 "%s: Return resume is not due to PNO indication", __func__);
8519 return 0;
8520 }
8521 // Reset flag to avoid updatating cfg80211 data old results again
8522 pHddCtx->isSchedScanUpdatePending = FALSE;
8523 spin_unlock(&pHddCtx->schedScan_lock);
8524
8525 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
8526
8527 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
8528 {
8529 pAdapter = pAdapterNode->pAdapter;
8530 if ( (NULL != pAdapter) &&
8531 (WLAN_HDD_INFRA_STATION == pAdapter->device_mode) )
8532 {
8533 if (0 != wlan_hdd_cfg80211_update_bss(pHddCtx->wiphy, pAdapter))
8534 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
8535 "%s: NO SCAN result", __func__);
8536 else
8537 cfg80211_sched_scan_results(pHddCtx->wiphy);
8538
8539 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8540 "%s : cfg80211 scan result database updated", __func__);
8541
8542 return 0;
8543
8544 }
8545 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
8546 pAdapterNode = pNext;
8547 }
8548
8549 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8550 "%s: Failed to find Adapter", __func__);
8551 return 0;
8552}
8553
8554/*
8555 * FUNCTION: wlan_hdd_cfg80211_suspend_wlan
8556 * this is called when cfg80211 driver suspends
8557 */
8558int wlan_hdd_cfg80211_suspend_wlan(struct wiphy *wiphy,
8559 struct cfg80211_wowlan *wow)
8560{
8561 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
8562
8563 ENTER();
8564 if (NULL == pHddCtx)
8565 {
8566 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8567 "%s: HddCtx validation failed", __func__);
8568 return 0;
8569 }
8570
8571 pHddCtx->isWiphySuspended = TRUE;
8572
8573 EXIT();
8574
8575 return 0;
8576}
8577
Jeff Johnson295189b2012-06-20 16:38:30 -07008578/* cfg80211_ops */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05308579static struct cfg80211_ops wlan_hdd_cfg80211_ops =
Jeff Johnson295189b2012-06-20 16:38:30 -07008580{
8581 .add_virtual_intf = wlan_hdd_add_virtual_intf,
8582 .del_virtual_intf = wlan_hdd_del_virtual_intf,
8583 .change_virtual_intf = wlan_hdd_cfg80211_change_iface,
8584 .change_station = wlan_hdd_change_station,
8585#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
8586 .add_beacon = wlan_hdd_cfg80211_add_beacon,
8587 .del_beacon = wlan_hdd_cfg80211_del_beacon,
8588 .set_beacon = wlan_hdd_cfg80211_set_beacon,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008589#else
8590 .start_ap = wlan_hdd_cfg80211_start_ap,
8591 .change_beacon = wlan_hdd_cfg80211_change_beacon,
8592 .stop_ap = wlan_hdd_cfg80211_stop_ap,
Jeff Johnson295189b2012-06-20 16:38:30 -07008593#endif
8594 .change_bss = wlan_hdd_cfg80211_change_bss,
8595 .add_key = wlan_hdd_cfg80211_add_key,
8596 .get_key = wlan_hdd_cfg80211_get_key,
8597 .del_key = wlan_hdd_cfg80211_del_key,
8598 .set_default_key = wlan_hdd_cfg80211_set_default_key,
Jeff Johnson3bbe4bf2013-01-18 17:05:29 -08008599#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07008600 .set_channel = wlan_hdd_cfg80211_set_channel,
Jeff Johnson3bbe4bf2013-01-18 17:05:29 -08008601#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07008602 .scan = wlan_hdd_cfg80211_scan,
8603 .connect = wlan_hdd_cfg80211_connect,
8604 .disconnect = wlan_hdd_cfg80211_disconnect,
8605 .join_ibss = wlan_hdd_cfg80211_join_ibss,
8606 .leave_ibss = wlan_hdd_cfg80211_leave_ibss,
8607 .set_wiphy_params = wlan_hdd_cfg80211_set_wiphy_params,
8608 .set_tx_power = wlan_hdd_cfg80211_set_txpower,
8609 .get_tx_power = wlan_hdd_cfg80211_get_txpower,
Jeff Johnson295189b2012-06-20 16:38:30 -07008610 .remain_on_channel = wlan_hdd_cfg80211_remain_on_channel,
8611 .cancel_remain_on_channel = wlan_hdd_cfg80211_cancel_remain_on_channel,
8612 .mgmt_tx = wlan_hdd_action,
8613#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
8614 .mgmt_tx_cancel_wait = wlan_hdd_cfg80211_mgmt_tx_cancel_wait,
8615 .set_default_mgmt_key = wlan_hdd_set_default_mgmt_key,
8616 .set_txq_params = wlan_hdd_set_txq_params,
8617#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07008618 .get_station = wlan_hdd_cfg80211_get_station,
8619 .set_power_mgmt = wlan_hdd_cfg80211_set_power_mgmt,
8620 .del_station = wlan_hdd_cfg80211_del_station,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008621 .add_station = wlan_hdd_cfg80211_add_station,
8622#ifdef FEATURE_WLAN_LFR
8623 .set_pmksa = wlan_hdd_cfg80211_set_pmksa,
8624 .del_pmksa = wlan_hdd_cfg80211_del_pmksa,
8625 .flush_pmksa = wlan_hdd_cfg80211_flush_pmksa,
8626#endif
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07008627#if defined(WLAN_FEATURE_VOWIFI_11R) && defined(KERNEL_SUPPORT_11R_CFG80211)
8628 .update_ft_ies = wlan_hdd_cfg80211_update_ft_ies,
8629#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008630#ifdef FEATURE_WLAN_TDLS
8631 .tdls_mgmt = wlan_hdd_cfg80211_tdls_mgmt,
8632 .tdls_oper = wlan_hdd_cfg80211_tdls_oper,
8633#endif
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308634#ifdef WLAN_FEATURE_GTK_OFFLOAD
8635 .set_rekey_data = wlan_hdd_cfg80211_set_rekey_data,
8636#endif /* WLAN_FEATURE_GTK_OFFLOAD */
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308637#ifdef FEATURE_WLAN_SCAN_PNO
8638 .sched_scan_start = wlan_hdd_cfg80211_sched_scan_start,
8639 .sched_scan_stop = wlan_hdd_cfg80211_sched_scan_stop,
8640#endif /*FEATURE_WLAN_SCAN_PNO */
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308641 .resume = wlan_hdd_cfg80211_resume_wlan,
8642 .suspend = wlan_hdd_cfg80211_suspend_wlan,
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05308643 .set_mac_acl = wlan_hdd_cfg80211_set_mac_acl,
Leo Chang9056f462013-08-01 19:21:11 -07008644#ifdef WLAN_NL80211_TESTMODE
8645 .testmode_cmd = wlan_hdd_cfg80211_testmode,
8646#endif
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05308647 .dump_survey = wlan_hdd_cfg80211_dump_survey,
Jeff Johnson295189b2012-06-20 16:38:30 -07008648};
8649