blob: cc77ec8522d49c29467b4f73de5dd7f8efa350e2 [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302 * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
3 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20*/
Jeff Johnson295189b2012-06-20 16:38:30 -070021
22/**========================================================================
23
24 \file wlan_hdd_cfg80211.c
25
26 \brief WLAN Host Device Driver implementation
27
Gopichand Nakkala747461f2013-04-24 19:24:45 +053028 Copyright 2008 (c) Qualcomm Technologies, Inc. All Rights Reserved.
Jeff Johnson295189b2012-06-20 16:38:30 -070029
Gopichand Nakkala747461f2013-04-24 19:24:45 +053030 Qualcomm Technologies Confidential and Proprietary.
Jeff Johnson295189b2012-06-20 16:38:30 -070031
32 ========================================================================*/
33
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -070034/**=========================================================================
Jeff Johnson295189b2012-06-20 16:38:30 -070035
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -070036 EDIT HISTORY FOR FILE
Jeff Johnson295189b2012-06-20 16:38:30 -070037
38
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -070039 This section contains comments describing changes made to the module.
40 Notice that changes are listed in reverse chronological order.
Jeff Johnson295189b2012-06-20 16:38:30 -070041
42
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -070043 $Header:$ $DateTime: $ $Author: $
Jeff Johnson295189b2012-06-20 16:38:30 -070044
45
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -070046 when who what, where, why
Jeff Johnson295189b2012-06-20 16:38:30 -070047 -------- --- --------------------------------------------------------
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -070048 21/12/09 Ashwani Created module.
Jeff Johnson295189b2012-06-20 16:38:30 -070049
50 07/06/10 Kumar Deepak Implemented cfg80211 callbacks for ANDROID
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -070051 Ganesh K
Jeff Johnson295189b2012-06-20 16:38:30 -070052 ==========================================================================*/
53
Jeff Johnson295189b2012-06-20 16:38:30 -070054
55#include <linux/version.h>
56#include <linux/module.h>
57#include <linux/kernel.h>
58#include <linux/init.h>
59#include <linux/wireless.h>
60#include <wlan_hdd_includes.h>
61#include <net/arp.h>
62#include <net/cfg80211.h>
63#include <linux/wireless.h>
64#include <wlan_hdd_wowl.h>
65#include <aniGlobal.h>
66#include "ccmApi.h"
67#include "sirParams.h"
68#include "dot11f.h"
69#include "wlan_hdd_assoc.h"
70#include "wlan_hdd_wext.h"
71#include "sme_Api.h"
72#include "wlan_hdd_p2p.h"
73#include "wlan_hdd_cfg80211.h"
74#include "wlan_hdd_hostapd.h"
75#include "sapInternal.h"
76#include "wlan_hdd_softap_tx_rx.h"
77#include "wlan_hdd_main.h"
Madan Mohan Koyyalamudid5acbf52012-11-28 01:45:08 +053078#include "wlan_hdd_assoc.h"
Gopichand Nakkala20c4c042013-04-19 22:08:55 +053079#include "wlan_hdd_power.h"
Jeff Johnson295189b2012-06-20 16:38:30 -070080#ifdef WLAN_BTAMP_FEATURE
81#include "bap_hdd_misc.h"
82#endif
83#include <qc_sap_ioctl.h>
Mohit Khanna698ba2a2012-12-04 15:08:18 -080084#ifdef FEATURE_WLAN_TDLS
85#include "wlan_hdd_tdls.h"
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +053086#include "wlan_hdd_wmm.h"
Madan Mohan Koyyalamudice419872013-09-13 19:36:52 +053087#include "wlan_qct_wda.h"
Mohit Khanna698ba2a2012-12-04 15:08:18 -080088#endif
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +053089#include "wlan_nv.h"
Leo Chang6fe1f922013-06-07 19:21:24 -070090#include "wlan_hdd_dev_pwr.h"
Jeff Johnson295189b2012-06-20 16:38:30 -070091
92#define g_mode_rates_size (12)
93#define a_mode_rates_size (8)
94#define FREQ_BASE_80211G (2407)
95#define FREQ_BAND_DIFF_80211G (5)
Jeff Johnson04dd8a82012-06-29 20:41:40 -070096#define MAX_SCAN_SSID 9
Jeff Johnson295189b2012-06-20 16:38:30 -070097#define GET_IE_LEN_IN_BSS_DESC(lenInBss) ( lenInBss + sizeof(lenInBss) - \
98 ((int) OFFSET_OF( tSirBssDescription, ieFields)))
99
100#define HDD2GHZCHAN(freq, chan, flag) { \
101 .band = IEEE80211_BAND_2GHZ, \
102 .center_freq = (freq), \
103 .hw_value = (chan),\
104 .flags = (flag), \
105 .max_antenna_gain = 0 ,\
106 .max_power = 30, \
107}
108
109#define HDD5GHZCHAN(freq, chan, flag) { \
110 .band = IEEE80211_BAND_5GHZ, \
111 .center_freq = (freq), \
112 .hw_value = (chan),\
113 .flags = (flag), \
114 .max_antenna_gain = 0 ,\
115 .max_power = 30, \
116}
117
118#define HDD_G_MODE_RATETAB(rate, rate_id, flag)\
119{\
120 .bitrate = rate, \
121 .hw_value = rate_id, \
122 .flags = flag, \
123}
124
Lee Hoonkic1262f22013-01-24 21:59:00 -0800125#ifndef WLAN_FEATURE_TDLS_DEBUG
126#define TDLS_LOG_LEVEL VOS_TRACE_LEVEL_INFO
127#else
128#define TDLS_LOG_LEVEL VOS_TRACE_LEVEL_ERROR
129#endif
130
Gopichand Nakkala356fb102013-03-06 12:34:04 +0530131#ifdef WLAN_FEATURE_VOWIFI_11R
132#define WLAN_AKM_SUITE_FT_8021X 0x000FAC03
133#define WLAN_AKM_SUITE_FT_PSK 0x000FAC04
134#endif
135
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530136static const u32 hdd_cipher_suites[] =
Jeff Johnson295189b2012-06-20 16:38:30 -0700137{
138 WLAN_CIPHER_SUITE_WEP40,
139 WLAN_CIPHER_SUITE_WEP104,
140 WLAN_CIPHER_SUITE_TKIP,
141#ifdef FEATURE_WLAN_CCX
142#define WLAN_CIPHER_SUITE_KRK 0x004096ff /* use for KRK */
143 WLAN_CIPHER_SUITE_KRK,
144 WLAN_CIPHER_SUITE_CCMP,
145#else
146 WLAN_CIPHER_SUITE_CCMP,
147#endif
148#ifdef FEATURE_WLAN_WAPI
149 WLAN_CIPHER_SUITE_SMS4,
150#endif
Chet Lanctot186b5732013-03-18 10:26:30 -0700151#ifdef WLAN_FEATURE_11W
152 WLAN_CIPHER_SUITE_AES_CMAC,
153#endif
Jeff Johnson295189b2012-06-20 16:38:30 -0700154};
155
156static inline int is_broadcast_ether_addr(const u8 *addr)
157{
158 return ((addr[0] == 0xff) && (addr[1] == 0xff) && (addr[2] == 0xff) &&
159 (addr[3] == 0xff) && (addr[4] == 0xff) && (addr[5] == 0xff));
160}
161
162static struct ieee80211_channel hdd_channels_2_4_GHZ[] =
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530163{
Jeff Johnson295189b2012-06-20 16:38:30 -0700164 HDD2GHZCHAN(2412, 1, 0) ,
165 HDD2GHZCHAN(2417, 2, 0) ,
166 HDD2GHZCHAN(2422, 3, 0) ,
167 HDD2GHZCHAN(2427, 4, 0) ,
168 HDD2GHZCHAN(2432, 5, 0) ,
169 HDD2GHZCHAN(2437, 6, 0) ,
170 HDD2GHZCHAN(2442, 7, 0) ,
171 HDD2GHZCHAN(2447, 8, 0) ,
172 HDD2GHZCHAN(2452, 9, 0) ,
173 HDD2GHZCHAN(2457, 10, 0) ,
174 HDD2GHZCHAN(2462, 11, 0) ,
175 HDD2GHZCHAN(2467, 12, 0) ,
176 HDD2GHZCHAN(2472, 13, 0) ,
177 HDD2GHZCHAN(2484, 14, 0) ,
178};
179
Jeff Johnson295189b2012-06-20 16:38:30 -0700180static struct ieee80211_channel hdd_social_channels_2_4_GHZ[] =
181{
182 HDD2GHZCHAN(2412, 1, 0) ,
183 HDD2GHZCHAN(2437, 6, 0) ,
184 HDD2GHZCHAN(2462, 11, 0) ,
185};
Jeff Johnson295189b2012-06-20 16:38:30 -0700186
187static struct ieee80211_channel hdd_channels_5_GHZ[] =
188{
Madan Mohan Koyyalamudic3a240c2012-09-28 15:34:08 -0700189 HDD5GHZCHAN(4920, 240, 0) ,
190 HDD5GHZCHAN(4940, 244, 0) ,
191 HDD5GHZCHAN(4960, 248, 0) ,
192 HDD5GHZCHAN(4980, 252, 0) ,
193 HDD5GHZCHAN(5040, 208, 0) ,
194 HDD5GHZCHAN(5060, 212, 0) ,
195 HDD5GHZCHAN(5080, 216, 0) ,
Jeff Johnson295189b2012-06-20 16:38:30 -0700196 HDD5GHZCHAN(5180, 36, 0) ,
197 HDD5GHZCHAN(5200, 40, 0) ,
198 HDD5GHZCHAN(5220, 44, 0) ,
199 HDD5GHZCHAN(5240, 48, 0) ,
200 HDD5GHZCHAN(5260, 52, 0) ,
201 HDD5GHZCHAN(5280, 56, 0) ,
202 HDD5GHZCHAN(5300, 60, 0) ,
203 HDD5GHZCHAN(5320, 64, 0) ,
204 HDD5GHZCHAN(5500,100, 0) ,
205 HDD5GHZCHAN(5520,104, 0) ,
206 HDD5GHZCHAN(5540,108, 0) ,
207 HDD5GHZCHAN(5560,112, 0) ,
208 HDD5GHZCHAN(5580,116, 0) ,
209 HDD5GHZCHAN(5600,120, 0) ,
210 HDD5GHZCHAN(5620,124, 0) ,
211 HDD5GHZCHAN(5640,128, 0) ,
212 HDD5GHZCHAN(5660,132, 0) ,
213 HDD5GHZCHAN(5680,136, 0) ,
214 HDD5GHZCHAN(5700,140, 0) ,
215 HDD5GHZCHAN(5745,149, 0) ,
216 HDD5GHZCHAN(5765,153, 0) ,
217 HDD5GHZCHAN(5785,157, 0) ,
218 HDD5GHZCHAN(5805,161, 0) ,
219 HDD5GHZCHAN(5825,165, 0) ,
220};
221
222static struct ieee80211_rate g_mode_rates[] =
223{
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530224 HDD_G_MODE_RATETAB(10, 0x1, 0),
225 HDD_G_MODE_RATETAB(20, 0x2, 0),
226 HDD_G_MODE_RATETAB(55, 0x4, 0),
227 HDD_G_MODE_RATETAB(110, 0x8, 0),
228 HDD_G_MODE_RATETAB(60, 0x10, 0),
229 HDD_G_MODE_RATETAB(90, 0x20, 0),
230 HDD_G_MODE_RATETAB(120, 0x40, 0),
231 HDD_G_MODE_RATETAB(180, 0x80, 0),
232 HDD_G_MODE_RATETAB(240, 0x100, 0),
233 HDD_G_MODE_RATETAB(360, 0x200, 0),
234 HDD_G_MODE_RATETAB(480, 0x400, 0),
Jeff Johnson295189b2012-06-20 16:38:30 -0700235 HDD_G_MODE_RATETAB(540, 0x800, 0),
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530236};
Jeff Johnson295189b2012-06-20 16:38:30 -0700237
238static struct ieee80211_rate a_mode_rates[] =
239{
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530240 HDD_G_MODE_RATETAB(60, 0x10, 0),
241 HDD_G_MODE_RATETAB(90, 0x20, 0),
242 HDD_G_MODE_RATETAB(120, 0x40, 0),
243 HDD_G_MODE_RATETAB(180, 0x80, 0),
244 HDD_G_MODE_RATETAB(240, 0x100, 0),
245 HDD_G_MODE_RATETAB(360, 0x200, 0),
246 HDD_G_MODE_RATETAB(480, 0x400, 0),
Jeff Johnson295189b2012-06-20 16:38:30 -0700247 HDD_G_MODE_RATETAB(540, 0x800, 0),
248};
249
250static struct ieee80211_supported_band wlan_hdd_band_2_4_GHZ =
251{
252 .channels = hdd_channels_2_4_GHZ,
253 .n_channels = ARRAY_SIZE(hdd_channels_2_4_GHZ),
254 .band = IEEE80211_BAND_2GHZ,
255 .bitrates = g_mode_rates,
256 .n_bitrates = g_mode_rates_size,
257 .ht_cap.ht_supported = 1,
258 .ht_cap.cap = IEEE80211_HT_CAP_SGI_20
259 | IEEE80211_HT_CAP_GRN_FLD
260 | IEEE80211_HT_CAP_DSSSCCK40
261 | IEEE80211_HT_CAP_LSIG_TXOP_PROT,
262 .ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
263 .ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_16,
264 .ht_cap.mcs.rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
265 .ht_cap.mcs.rx_highest = cpu_to_le16( 72 ),
266 .ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED,
267};
268
Jeff Johnson295189b2012-06-20 16:38:30 -0700269static struct ieee80211_supported_band wlan_hdd_band_p2p_2_4_GHZ =
270{
271 .channels = hdd_social_channels_2_4_GHZ,
272 .n_channels = ARRAY_SIZE(hdd_social_channels_2_4_GHZ),
273 .band = IEEE80211_BAND_2GHZ,
274 .bitrates = g_mode_rates,
275 .n_bitrates = g_mode_rates_size,
276 .ht_cap.ht_supported = 1,
277 .ht_cap.cap = IEEE80211_HT_CAP_SGI_20
278 | IEEE80211_HT_CAP_GRN_FLD
279 | IEEE80211_HT_CAP_DSSSCCK40
280 | IEEE80211_HT_CAP_LSIG_TXOP_PROT,
281 .ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
282 .ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_16,
283 .ht_cap.mcs.rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
284 .ht_cap.mcs.rx_highest = cpu_to_le16( 72 ),
285 .ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED,
286};
Jeff Johnson295189b2012-06-20 16:38:30 -0700287
288static struct ieee80211_supported_band wlan_hdd_band_5_GHZ =
289{
290 .channels = hdd_channels_5_GHZ,
291 .n_channels = ARRAY_SIZE(hdd_channels_5_GHZ),
292 .band = IEEE80211_BAND_5GHZ,
293 .bitrates = a_mode_rates,
294 .n_bitrates = a_mode_rates_size,
295 .ht_cap.ht_supported = 1,
296 .ht_cap.cap = IEEE80211_HT_CAP_SGI_20
297 | IEEE80211_HT_CAP_GRN_FLD
298 | IEEE80211_HT_CAP_DSSSCCK40
299 | IEEE80211_HT_CAP_LSIG_TXOP_PROT
300 | IEEE80211_HT_CAP_SGI_40
301 | IEEE80211_HT_CAP_SUP_WIDTH_20_40,
302 .ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
303 .ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_16,
304 .ht_cap.mcs.rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
305 .ht_cap.mcs.rx_highest = cpu_to_le16( 72 ),
306 .ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED,
307};
308
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530309/* This structure contain information what kind of frame are expected in
Jeff Johnson295189b2012-06-20 16:38:30 -0700310 TX/RX direction for each kind of interface */
311static const struct ieee80211_txrx_stypes
312wlan_hdd_txrx_stypes[NUM_NL80211_IFTYPES] = {
313 [NL80211_IFTYPE_STATION] = {
314 .tx = 0xffff,
315 .rx = BIT(SIR_MAC_MGMT_ACTION) |
316 BIT(SIR_MAC_MGMT_PROBE_REQ),
317 },
318 [NL80211_IFTYPE_AP] = {
319 .tx = 0xffff,
320 .rx = BIT(SIR_MAC_MGMT_ASSOC_REQ) |
321 BIT(SIR_MAC_MGMT_REASSOC_REQ) |
322 BIT(SIR_MAC_MGMT_PROBE_REQ) |
323 BIT(SIR_MAC_MGMT_DISASSOC) |
324 BIT(SIR_MAC_MGMT_AUTH) |
325 BIT(SIR_MAC_MGMT_DEAUTH) |
326 BIT(SIR_MAC_MGMT_ACTION),
327 },
Jeff Johnsonbc006202013-04-29 14:05:30 -0700328 [NL80211_IFTYPE_ADHOC] = {
329 .tx = 0xffff,
330 .rx = BIT(SIR_MAC_MGMT_ASSOC_REQ) |
331 BIT(SIR_MAC_MGMT_REASSOC_REQ) |
332 BIT(SIR_MAC_MGMT_PROBE_REQ) |
333 BIT(SIR_MAC_MGMT_DISASSOC) |
334 BIT(SIR_MAC_MGMT_AUTH) |
335 BIT(SIR_MAC_MGMT_DEAUTH) |
336 BIT(SIR_MAC_MGMT_ACTION),
337 },
Jeff Johnson295189b2012-06-20 16:38:30 -0700338 [NL80211_IFTYPE_P2P_CLIENT] = {
339 .tx = 0xffff,
340 .rx = BIT(SIR_MAC_MGMT_ACTION) |
341 BIT(SIR_MAC_MGMT_PROBE_REQ),
342 },
343 [NL80211_IFTYPE_P2P_GO] = {
344 /* This is also same as for SoftAP */
345 .tx = 0xffff,
346 .rx = BIT(SIR_MAC_MGMT_ASSOC_REQ) |
347 BIT(SIR_MAC_MGMT_REASSOC_REQ) |
348 BIT(SIR_MAC_MGMT_PROBE_REQ) |
349 BIT(SIR_MAC_MGMT_DISASSOC) |
350 BIT(SIR_MAC_MGMT_AUTH) |
351 BIT(SIR_MAC_MGMT_DEAUTH) |
352 BIT(SIR_MAC_MGMT_ACTION),
353 },
Jeff Johnson295189b2012-06-20 16:38:30 -0700354};
355
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800356#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800357static const struct ieee80211_iface_limit
358wlan_hdd_iface_limit[] = {
359 {
Sunil Ravia72c3992013-01-31 06:12:22 -0800360 /* max = 3 ; Our driver create two interfaces during driver init
361 * wlan0 and p2p0 interfaces. p2p0 is considered as station
362 * interface until a group is formed. In JB architecture, once the
363 * group is formed, interface type of p2p0 is changed to P2P GO or
364 * Client.
365 * When supplicant remove the group, it first issue a set interface
366 * cmd to change the mode back to Station. In JB this works fine as
367 * we advertize two station type interface during driver init.
368 * Some vendors create separate interface for P2P GO/Client,
369 * after group formation(Third one). But while group remove
370 * supplicant first tries to change the mode(3rd interface) to STATION
371 * But as we advertized only two sta type interfaces nl80211 was
372 * returning error for the third one which was leading to failure in
373 * delete interface. Ideally while removing the group, supplicant
374 * should not try to change the 3rd interface mode to Station type.
375 * Till we get a fix in wpa_supplicant, we advertize max STA
376 * interface type to 3
377 */
378 .max = 3,
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800379 .types = BIT(NL80211_IFTYPE_STATION),
380 },
381 {
382 .max = 1,
Jeff Johnsonbc006202013-04-29 14:05:30 -0700383 .types = BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_AP),
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800384 },
385 {
386 .max = 1,
387 .types = BIT(NL80211_IFTYPE_P2P_GO) |
388 BIT(NL80211_IFTYPE_P2P_CLIENT),
389 },
390};
391
392/* By default, only single channel concurrency is allowed */
393static struct ieee80211_iface_combination
394wlan_hdd_iface_combination = {
395 .limits = wlan_hdd_iface_limit,
396 .num_different_channels = 1,
Sunil Ravia72c3992013-01-31 06:12:22 -0800397 /*
398 * max = WLAN_MAX_INTERFACES ; JellyBean architecture creates wlan0
399 * and p2p0 interfaces during driver init
400 * Some vendors create separate interface for P2P operations.
401 * wlan0: STA interface
402 * p2p0: P2P Device interface, action frames goes
403 * through this interface.
404 * p2p-xx: P2P interface, After GO negotiation this interface is
405 * created for p2p operations(GO/CLIENT interface).
406 */
407 .max_interfaces = WLAN_MAX_INTERFACES,
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800408 .n_limits = ARRAY_SIZE(wlan_hdd_iface_limit),
409 .beacon_int_infra_match = false,
410};
411#endif
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800412
Jeff Johnson295189b2012-06-20 16:38:30 -0700413static struct cfg80211_ops wlan_hdd_cfg80211_ops;
414
415/* Data rate 100KBPS based on IE Index */
416struct index_data_rate_type
417{
418 v_U8_t beacon_rate_index;
419 v_U16_t supported_rate[4];
420};
421
422/* 11B, 11G Rate table include Basic rate and Extended rate
423 The IDX field is the rate index
424 The HI field is the rate when RSSI is strong or being ignored
425 (in this case we report actual rate)
426 The MID field is the rate when RSSI is moderate
427 (in this case we cap 11b rates at 5.5 and 11g rates at 24)
428 The LO field is the rate when RSSI is low
429 (in this case we don't report rates, actual current rate used)
430 */
431static const struct
432{
433 v_U8_t beacon_rate_index;
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -0700434 v_U16_t supported_rate[4];
Jeff Johnson295189b2012-06-20 16:38:30 -0700435} supported_data_rate[] =
436{
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -0700437/* IDX HI HM LM LO (RSSI-based index */
438 {2, { 10, 10, 10, 0}},
439 {4, { 20, 20, 10, 0}},
440 {11, { 55, 20, 10, 0}},
441 {12, { 60, 55, 20, 0}},
442 {18, { 90, 55, 20, 0}},
443 {22, {110, 55, 20, 0}},
444 {24, {120, 90, 60, 0}},
445 {36, {180, 120, 60, 0}},
446 {44, {220, 180, 60, 0}},
447 {48, {240, 180, 90, 0}},
448 {66, {330, 180, 90, 0}},
449 {72, {360, 240, 90, 0}},
450 {96, {480, 240, 120, 0}},
451 {108, {540, 240, 120, 0}}
Jeff Johnson295189b2012-06-20 16:38:30 -0700452};
453
454/* MCS Based rate table */
455static struct index_data_rate_type supported_mcs_rate[] =
456{
457/* MCS L20 L40 S20 S40 */
458 {0, {65, 135, 72, 150}},
459 {1, {130, 270, 144, 300}},
460 {2, {195, 405, 217, 450}},
461 {3, {260, 540, 289, 600}},
462 {4, {390, 810, 433, 900}},
463 {5, {520, 1080, 578, 1200}},
464 {6, {585, 1215, 650, 1350}},
465 {7, {650, 1350, 722, 1500}}
466};
467
Leo Chang6f8870f2013-03-26 18:11:36 -0700468#ifdef WLAN_FEATURE_11AC
469
Gopichand Nakkala4c705372013-04-24 13:20:33 +0530470#define DATA_RATE_11AC_MCS_MASK 0x03
Leo Chang6f8870f2013-03-26 18:11:36 -0700471
472struct index_vht_data_rate_type
473{
474 v_U8_t beacon_rate_index;
Gopichand Nakkala4c705372013-04-24 13:20:33 +0530475 v_U16_t supported_VHT80_rate[2];
476 v_U16_t supported_VHT40_rate[2];
477 v_U16_t supported_VHT20_rate[2];
Leo Chang6f8870f2013-03-26 18:11:36 -0700478};
479
480typedef enum
481{
482 DATA_RATE_11AC_MAX_MCS_7,
483 DATA_RATE_11AC_MAX_MCS_8,
484 DATA_RATE_11AC_MAX_MCS_9,
485 DATA_RATE_11AC_MAX_MCS_NA
486} eDataRate11ACMaxMcs;
487
488/* MCS Based VHT rate table */
489static struct index_vht_data_rate_type supported_vht_mcs_rate[] =
490{
Gopichand Nakkala4c705372013-04-24 13:20:33 +0530491/* MCS L80 S80 L40 S40 L20 S40*/
492 {0, {293, 325}, {135, 150}, {65, 72}},
493 {1, {585, 650}, {270, 300}, {130, 144}},
494 {2, {878, 975}, {405, 450}, {195, 217}},
495 {3, {1170, 1300}, {540, 600}, {260, 289}},
496 {4, {1755, 1950}, {810, 900}, {390, 433}},
497 {5, {2340, 2600}, {1080, 1200}, {520, 578}},
498 {6, {2633, 2925}, {1215, 1350}, {585, 650}},
499 {7, {2925, 3250}, {1350, 1500}, {650, 722}},
500 {8, {3510, 3900}, {1620, 1800}, {780, 867}},
501 {9, {3900, 4333}, {1800, 2000}, {780, 867}}
Leo Chang6f8870f2013-03-26 18:11:36 -0700502};
503#endif /* WLAN_FEATURE_11AC */
504
Jeff Johnson295189b2012-06-20 16:38:30 -0700505extern struct net_device_ops net_ops_struct;
506
Leo Chang9056f462013-08-01 19:21:11 -0700507#ifdef WLAN_NL80211_TESTMODE
508enum wlan_hdd_tm_attr
509{
510 WLAN_HDD_TM_ATTR_INVALID = 0,
511 WLAN_HDD_TM_ATTR_CMD = 1,
512 WLAN_HDD_TM_ATTR_DATA = 2,
513 WLAN_HDD_TM_ATTR_TYPE = 3,
514 /* keep last */
515 WLAN_HDD_TM_ATTR_AFTER_LAST,
516 WLAN_HDD_TM_ATTR_MAX = WLAN_HDD_TM_ATTR_AFTER_LAST - 1,
517};
518
519enum wlan_hdd_tm_cmd
520{
521 WLAN_HDD_TM_CMD_WLAN_HB = 1,
522};
523
524#define WLAN_HDD_TM_DATA_MAX_LEN 5000
525
526static const struct nla_policy wlan_hdd_tm_policy[WLAN_HDD_TM_ATTR_MAX + 1] =
527{
528 [WLAN_HDD_TM_ATTR_CMD] = { .type = NLA_U32 },
529 [WLAN_HDD_TM_ATTR_DATA] = { .type = NLA_BINARY,
530 .len = WLAN_HDD_TM_DATA_MAX_LEN },
531};
532#endif /* WLAN_NL80211_TESTMODE */
533
Jeff Johnson295189b2012-06-20 16:38:30 -0700534/*
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530535 * FUNCTION: wlan_hdd_cfg80211_wiphy_alloc
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530536 * This function is called by hdd_wlan_startup()
537 * during initialization.
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530538 * This function is used to allocate wiphy structure.
Jeff Johnson295189b2012-06-20 16:38:30 -0700539 */
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530540struct wiphy *wlan_hdd_cfg80211_wiphy_alloc(int priv_size)
Jeff Johnson295189b2012-06-20 16:38:30 -0700541{
542 struct wiphy *wiphy;
543 ENTER();
544
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530545 /*
546 * Create wiphy device
Jeff Johnson295189b2012-06-20 16:38:30 -0700547 */
548 wiphy = wiphy_new(&wlan_hdd_cfg80211_ops, priv_size);
549
550 if (!wiphy)
551 {
552 /* Print error and jump into err label and free the memory */
553 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: wiphy init failed", __func__);
554 return NULL;
555 }
556
557 return wiphy;
558}
559
560/*
561 * FUNCTION: wlan_hdd_cfg80211_update_band
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530562 * This function is called from the supplicant through a
Jeff Johnson295189b2012-06-20 16:38:30 -0700563 * private ioctl to change the band value
564 */
565int wlan_hdd_cfg80211_update_band(struct wiphy *wiphy, eCsrBand eBand)
566{
Gopichand Nakkala1f7a64f2013-04-01 18:37:17 +0530567 int i, j;
568 eNVChannelEnabledType channelEnabledState;
569
Jeff Johnsone7245742012-09-05 17:12:55 -0700570 ENTER();
Gopichand Nakkala1f7a64f2013-04-01 18:37:17 +0530571 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Jeff Johnson295189b2012-06-20 16:38:30 -0700572 {
Gopichand Nakkala1f7a64f2013-04-01 18:37:17 +0530573
574 if (NULL == wiphy->bands[i])
575 {
576 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy->bands[i] is NULL, i = %d",
577 __func__, i);
578 continue;
579 }
580
581 for (j = 0; j < wiphy->bands[i]->n_channels; j++)
582 {
583 struct ieee80211_supported_band *band = wiphy->bands[i];
584
585 channelEnabledState = vos_nv_getChannelEnabledState(
586 band->channels[j].hw_value);
587
588 if (IEEE80211_BAND_2GHZ == i && eCSR_BAND_5G == eBand) // 5G only
589 {
590 // Enable Social channels for P2P
591 if (WLAN_HDD_IS_SOCIAL_CHANNEL(band->channels[j].center_freq) &&
592 NV_CHANNEL_ENABLE == channelEnabledState)
593 band->channels[j].flags &= ~IEEE80211_CHAN_DISABLED;
594 else
595 band->channels[j].flags |= IEEE80211_CHAN_DISABLED;
596 continue;
597 }
598 else if (IEEE80211_BAND_5GHZ == i && eCSR_BAND_24 == eBand) // 2G only
599 {
600 band->channels[j].flags |= IEEE80211_CHAN_DISABLED;
601 continue;
602 }
603
604 if (NV_CHANNEL_DISABLE == channelEnabledState ||
605 NV_CHANNEL_INVALID == channelEnabledState)
606 {
607 band->channels[j].flags |= IEEE80211_CHAN_DISABLED;
608 }
609 else if (NV_CHANNEL_DFS == channelEnabledState)
610 {
611 band->channels[j].flags &= ~IEEE80211_CHAN_DISABLED;
612 band->channels[j].flags |= IEEE80211_CHAN_RADAR;
613 }
614 else
615 {
616 band->channels[j].flags &= ~(IEEE80211_CHAN_DISABLED
617 |IEEE80211_CHAN_RADAR);
618 }
619 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700620 }
621 return 0;
622}
623/*
624 * FUNCTION: wlan_hdd_cfg80211_init
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530625 * This function is called by hdd_wlan_startup()
626 * during initialization.
Jeff Johnson295189b2012-06-20 16:38:30 -0700627 * This function is used to initialize and register wiphy structure.
628 */
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530629int wlan_hdd_cfg80211_init(struct device *dev,
Jeff Johnson295189b2012-06-20 16:38:30 -0700630 struct wiphy *wiphy,
631 hdd_config_t *pCfg
632 )
633{
Gopichand Nakkala1f7a64f2013-04-01 18:37:17 +0530634 int i, j;
Jeff Johnsone7245742012-09-05 17:12:55 -0700635 ENTER();
636
Jeff Johnson295189b2012-06-20 16:38:30 -0700637 /* Now bind the underlying wlan device with wiphy */
638 set_wiphy_dev(wiphy, dev);
639
640 wiphy->mgmt_stypes = wlan_hdd_txrx_stypes;
Amar Singhalfddc28c2013-09-05 13:03:40 -0700641
642 /* This will disable updating of NL channels from passive to
643 * active if a beacon is received on passive channel. */
644 wiphy->flags |= WIPHY_FLAG_DISABLE_BEACON_HINTS;
645 wiphy->flags |= WIPHY_FLAG_STRICT_REGULATORY;
646
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700647#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
Madan Mohan Koyyalamudi1b4afb02012-10-22 15:25:16 -0700648 wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME
649 | WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
650 | WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
Jeff Johnsone7245742012-09-05 17:12:55 -0700651 | WIPHY_FLAG_OFFCHAN_TX;
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700652#endif
Srinivas Girigowda640728a2013-03-28 12:21:54 -0700653#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_CCX) || defined(FEATURE_WLAN_LFR)
654 if (pCfg->isFastTransitionEnabled
James Zmuda77fb5ae2013-01-29 08:00:17 -0800655#ifdef FEATURE_WLAN_LFR
Srinivas Girigowda640728a2013-03-28 12:21:54 -0700656 || pCfg->isFastRoamIniFeatureEnabled
657#endif
658#ifdef FEATURE_WLAN_CCX
659 || pCfg->isCcxIniFeatureEnabled
660#endif
661 )
662 {
663 wiphy->flags |= WIPHY_FLAG_SUPPORTS_FW_ROAM;
664 }
James Zmuda77fb5ae2013-01-29 08:00:17 -0800665#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -0800666#ifdef FEATURE_WLAN_TDLS
667 wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS
668 | WIPHY_FLAG_TDLS_EXTERNAL_SETUP;
669#endif
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +0530670#ifdef FEATURE_WLAN_SCAN_PNO
671 wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
Madan Mohan Koyyalamudi75de0102013-09-17 14:56:29 +0530672 wiphy->max_sched_scan_ssids = SIR_PNO_MAX_SUPP_NETWORKS;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +0530673 wiphy->max_match_sets = SIR_PNO_MAX_SUPP_NETWORKS;
674#endif/*FEATURE_WLAN_SCAN_PNO*/
Mohit Khanna698ba2a2012-12-04 15:08:18 -0800675
Amar Singhalfddc28c2013-09-05 13:03:40 -0700676#ifdef CONFIG_ENABLE_LINUX_REG
Madan Mohan Koyyalamudic3a240c2012-09-28 15:34:08 -0700677 /* even with WIPHY_FLAG_CUSTOM_REGULATORY,
678 driver can still register regulatory callback and
Amar Singhalfddc28c2013-09-05 13:03:40 -0700679 it will get regulatory settings in wiphy->band[], but
Madan Mohan Koyyalamudic3a240c2012-09-28 15:34:08 -0700680 driver need to determine what to do with both
681 regulatory settings */
Amar Singhalfddc28c2013-09-05 13:03:40 -0700682
683 wiphy->reg_notifier = wlan_hdd_linux_reg_notifier;
684#endif
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700685
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530686 wiphy->max_scan_ssids = MAX_SCAN_SSID;
687
Madan Mohan Koyyalamudi6815b162013-07-19 17:17:46 +0530688 wiphy->max_scan_ie_len = SIR_MAC_MAX_IE_LENGTH;
Jeff Johnson295189b2012-06-20 16:38:30 -0700689
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +0530690 wiphy->max_acl_mac_addrs = MAX_ACL_MAC_ADDRESS;
691
Jeff Johnson295189b2012-06-20 16:38:30 -0700692 /* Supports STATION & AD-HOC modes right now */
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530693 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION)
Jeff Johnson295189b2012-06-20 16:38:30 -0700694 | BIT(NL80211_IFTYPE_ADHOC)
Jeff Johnson295189b2012-06-20 16:38:30 -0700695 | BIT(NL80211_IFTYPE_P2P_CLIENT)
696 | BIT(NL80211_IFTYPE_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -0700697 | BIT(NL80211_IFTYPE_AP);
698
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800699#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800700 if( pCfg->enableMCC )
701 {
702 /* Currently, supports up to two channels */
703 wlan_hdd_iface_combination.num_different_channels = 2;
704
705 if( !pCfg->allowMCCGODiffBI )
706 wlan_hdd_iface_combination.beacon_int_infra_match = true;
707
708 }
709 wiphy->iface_combinations = &wlan_hdd_iface_combination;
710 wiphy->n_iface_combinations = 1;
711#endif
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800712
Jeff Johnson295189b2012-06-20 16:38:30 -0700713 /* Before registering we need to update the ht capabilitied based
714 * on ini values*/
715 if( !pCfg->ShortGI20MhzEnable )
716 {
717 wlan_hdd_band_2_4_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_20;
718 wlan_hdd_band_5_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_20;
719 wlan_hdd_band_p2p_2_4_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_20;
720 }
721
722 if( !pCfg->ShortGI40MhzEnable )
723 {
724 wlan_hdd_band_5_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_40;
725 }
726
727 if( !pCfg->nChannelBondingMode5GHz )
728 {
729 wlan_hdd_band_5_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
730 }
731
Gopichand Nakkala1f7a64f2013-04-01 18:37:17 +0530732 wiphy->bands[IEEE80211_BAND_2GHZ] = &wlan_hdd_band_2_4_GHZ;
733 wiphy->bands[IEEE80211_BAND_5GHZ] = &wlan_hdd_band_5_GHZ;
734
735 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
736 {
737
738 if (NULL == wiphy->bands[i])
739 {
740 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy->bands[i] is NULL, i = %d",
741 __func__, i);
742 continue;
743 }
744
745 for (j = 0; j < wiphy->bands[i]->n_channels; j++)
746 {
747 struct ieee80211_supported_band *band = wiphy->bands[i];
748
749 if (IEEE80211_BAND_2GHZ == i && eCSR_BAND_5G == pCfg->nBandCapability) // 5G only
750 {
751 // Enable social channels for P2P
752 if (WLAN_HDD_IS_SOCIAL_CHANNEL(band->channels[j].center_freq))
753 band->channels[j].flags &= ~IEEE80211_CHAN_DISABLED;
754 else
755 band->channels[j].flags |= IEEE80211_CHAN_DISABLED;
756 continue;
757 }
758 else if (IEEE80211_BAND_5GHZ == i && eCSR_BAND_24 == pCfg->nBandCapability) // 2G only
759 {
760 band->channels[j].flags |= IEEE80211_CHAN_DISABLED;
761 continue;
762 }
763 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700764 }
765 /*Initialise the supported cipher suite details*/
766 wiphy->cipher_suites = hdd_cipher_suites;
767 wiphy->n_cipher_suites = ARRAY_SIZE(hdd_cipher_suites);
768
769 /*signal strength in mBm (100*dBm) */
770 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
771
772#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
Jeff Johnson295189b2012-06-20 16:38:30 -0700773 wiphy->max_remain_on_channel_duration = 1000;
774#endif
Jeff Johnson295189b2012-06-20 16:38:30 -0700775
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530776 EXIT();
777 return 0;
778}
779
780/* In this function we are registering wiphy. */
781int wlan_hdd_cfg80211_register(struct wiphy *wiphy)
782{
783 ENTER();
784 /* Register our wiphy dev with cfg80211 */
Jeff Johnson295189b2012-06-20 16:38:30 -0700785 if (0 > wiphy_register(wiphy))
786 {
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530787 /* print error */
Jeff Johnson295189b2012-06-20 16:38:30 -0700788 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy register failed", __func__);
789 return -EIO;
790 }
791
792 EXIT();
793 return 0;
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530794}
Jeff Johnson295189b2012-06-20 16:38:30 -0700795
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530796/* In this function we are updating channel list when,
797 regulatory domain is FCC and country code is US.
798 Here In FCC standard 5GHz UNII-1 Bands are indoor only.
799 As per FCC smart phone is not a indoor device.
800 GO should not opeate on indoor channels */
801void wlan_hdd_cfg80211_update_reg_info(struct wiphy *wiphy)
802{
803 int j;
804 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
805 tANI_U8 defaultCountryCode[3] = SME_INVALID_COUNTRY_CODE;
806 //Default counrtycode from NV at the time of wiphy initialization.
807 if (eHAL_STATUS_SUCCESS != sme_GetDefaultCountryCodeFrmNv(pHddCtx->hHal,
808 &defaultCountryCode[0]))
809 {
810 hddLog(LOGE, FL("%s Failed to get default country code from NV"));
811 }
812 if ((defaultCountryCode[0]== 'U') && (defaultCountryCode[1]=='S'))
813 {
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +0530814 if (NULL == wiphy->bands[IEEE80211_BAND_5GHZ])
815 {
816 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy->bands[IEEE80211_BAND_5GHZ] is NULL",__func__ );
817 return;
818 }
819 for (j = 0; j < wiphy->bands[IEEE80211_BAND_5GHZ]->n_channels; j++)
820 {
821 struct ieee80211_supported_band *band = wiphy->bands[IEEE80211_BAND_5GHZ];
822 // Mark UNII -1 band channel as passive
823 if (WLAN_HDD_CHANNEL_IN_UNII_1_BAND(band->channels[j].center_freq))
824 band->channels[j].flags |= IEEE80211_CHAN_PASSIVE_SCAN;
825 }
826 }
827}
828
Jeff Johnson295189b2012-06-20 16:38:30 -0700829/* In this function we will do all post VOS start initialization.
830 In this function we will register for all frame in which supplicant
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530831 is interested.
Jeff Johnson295189b2012-06-20 16:38:30 -0700832*/
833void wlan_hdd_cfg80211_post_voss_start(hdd_adapter_t* pAdapter)
834{
Jeff Johnson295189b2012-06-20 16:38:30 -0700835 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
836 /* Register for all P2P action, public action etc frames */
837 v_U16_t type = (SIR_MAC_MGMT_FRAME << 2) | ( SIR_MAC_MGMT_ACTION << 4);
838
Jeff Johnsone7245742012-09-05 17:12:55 -0700839 ENTER();
840
Jeff Johnson295189b2012-06-20 16:38:30 -0700841 /* Right now we are registering these frame when driver is getting
842 initialized. Once we will move to 2.6.37 kernel, in which we have
843 frame register ops, we will move this code as a part of that */
844 /* GAS Initial Request */
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530845 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
Jeff Johnson295189b2012-06-20 16:38:30 -0700846 (v_U8_t*)GAS_INITIAL_REQ, GAS_INITIAL_REQ_SIZE );
847
848 /* GAS Initial Response */
849 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
850 (v_U8_t*)GAS_INITIAL_RSP, GAS_INITIAL_RSP_SIZE );
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530851
Jeff Johnson295189b2012-06-20 16:38:30 -0700852 /* GAS Comeback Request */
853 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
854 (v_U8_t*)GAS_COMEBACK_REQ, GAS_COMEBACK_REQ_SIZE );
855
856 /* GAS Comeback Response */
857 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
858 (v_U8_t*)GAS_COMEBACK_RSP, GAS_COMEBACK_RSP_SIZE );
859
860 /* P2P Public Action */
861 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530862 (v_U8_t*)P2P_PUBLIC_ACTION_FRAME,
Jeff Johnson295189b2012-06-20 16:38:30 -0700863 P2P_PUBLIC_ACTION_FRAME_SIZE );
864
865 /* P2P Action */
866 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
867 (v_U8_t*)P2P_ACTION_FRAME,
868 P2P_ACTION_FRAME_SIZE );
Chet Lanctot186b5732013-03-18 10:26:30 -0700869
Gopichand Nakkalae3d56e72013-04-21 23:33:32 +0530870 /* WNM BSS Transition Request frame */
871 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
872 (v_U8_t*)WNM_BSS_ACTION_FRAME,
873 WNM_BSS_ACTION_FRAME_SIZE );
874
Chet Lanctot186b5732013-03-18 10:26:30 -0700875#ifdef WLAN_FEATURE_11W
876 /* SA Query Response Action Frame */
877 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
878 (v_U8_t*)SA_QUERY_FRAME_RSP,
879 SA_QUERY_FRAME_RSP_SIZE );
880#endif /* WLAN_FEATURE_11W */
Jeff Johnson295189b2012-06-20 16:38:30 -0700881}
882
883void wlan_hdd_cfg80211_pre_voss_stop(hdd_adapter_t* pAdapter)
884{
Jeff Johnson295189b2012-06-20 16:38:30 -0700885 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
886 /* Register for all P2P action, public action etc frames */
887 v_U16_t type = (SIR_MAC_MGMT_FRAME << 2) | ( SIR_MAC_MGMT_ACTION << 4);
888
Jeff Johnsone7245742012-09-05 17:12:55 -0700889 ENTER();
890
Jeff Johnson295189b2012-06-20 16:38:30 -0700891 /* Right now we are registering these frame when driver is getting
892 initialized. Once we will move to 2.6.37 kernel, in which we have
893 frame register ops, we will move this code as a part of that */
894 /* GAS Initial Request */
895
896 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
897 (v_U8_t*)GAS_INITIAL_REQ, GAS_INITIAL_REQ_SIZE );
898
899 /* GAS Initial Response */
900 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
901 (v_U8_t*)GAS_INITIAL_RSP, GAS_INITIAL_RSP_SIZE );
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530902
Jeff Johnson295189b2012-06-20 16:38:30 -0700903 /* GAS Comeback Request */
904 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
905 (v_U8_t*)GAS_COMEBACK_REQ, GAS_COMEBACK_REQ_SIZE );
906
907 /* GAS Comeback Response */
908 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
909 (v_U8_t*)GAS_COMEBACK_RSP, GAS_COMEBACK_RSP_SIZE );
910
911 /* P2P Public Action */
912 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530913 (v_U8_t*)P2P_PUBLIC_ACTION_FRAME,
Jeff Johnson295189b2012-06-20 16:38:30 -0700914 P2P_PUBLIC_ACTION_FRAME_SIZE );
915
916 /* P2P Action */
917 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
918 (v_U8_t*)P2P_ACTION_FRAME,
919 P2P_ACTION_FRAME_SIZE );
Chet Lanctot186b5732013-03-18 10:26:30 -0700920
921#ifdef WLAN_FEATURE_11W
922 /* SA Query Response Action Frame */
923 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
924 (v_U8_t*)SA_QUERY_FRAME_RSP,
925 SA_QUERY_FRAME_RSP_SIZE );
926#endif /* WLAN_FEATURE_11W */
Jeff Johnson295189b2012-06-20 16:38:30 -0700927}
928
929#ifdef FEATURE_WLAN_WAPI
930void wlan_hdd_cfg80211_set_key_wapi(hdd_adapter_t* pAdapter, u8 key_index,
931 const u8 *mac_addr, u8 *key , int key_Len)
932{
933 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
934 tCsrRoamSetKey setKey;
935 v_BOOL_t isConnected = TRUE;
936 int status = 0;
937 v_U32_t roamId= 0xFF;
938 tANI_U8 *pKeyPtr = NULL;
939 int n = 0;
940
941 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
942 __func__,pAdapter->device_mode);
943
Gopichand Nakkalae7480202013-02-11 15:24:22 +0530944 vos_mem_zero(&setKey, sizeof(tCsrRoamSetKey));
Jeff Johnson295189b2012-06-20 16:38:30 -0700945 setKey.keyId = key_index; // Store Key ID
946 setKey.encType = eCSR_ENCRYPT_TYPE_WPI; // SET WAPI Encryption
947 setKey.keyDirection = eSIR_TX_RX; // Key Directionn both TX and RX
948 setKey.paeRole = 0 ; // the PAE role
949 if (!mac_addr || is_broadcast_ether_addr(mac_addr))
950 {
951 vos_set_macaddr_broadcast( (v_MACADDR_t *)setKey.peerMac );
952 }
953 else
954 {
955 isConnected = hdd_connIsConnected(pHddStaCtx);
956 vos_mem_copy(setKey.peerMac,&pHddStaCtx->conn_info.bssId,WNI_CFG_BSSID_LEN);
957 }
958 setKey.keyLength = key_Len;
959 pKeyPtr = setKey.Key;
960 memcpy( pKeyPtr, key, key_Len);
961
962 hddLog(VOS_TRACE_LEVEL_INFO,"\n%s: WAPI KEY LENGTH:0x%04x",
963 __func__, key_Len);
964 for (n = 0 ; n < key_Len; n++)
965 hddLog(VOS_TRACE_LEVEL_INFO, "%s WAPI KEY Data[%d]:%02x ",
966 __func__,n,setKey.Key[n]);
967
968 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_SETTING_KEY;
969 if ( isConnected )
970 {
971 status= sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
972 pAdapter->sessionId, &setKey, &roamId );
973 }
974 if ( status != 0 )
975 {
976 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
977 "[%4d] sme_RoamSetKey returned ERROR status= %d",
978 __LINE__, status );
979 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
980 }
981}
982#endif /* FEATURE_WLAN_WAPI*/
983
984#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530985int wlan_hdd_cfg80211_alloc_new_beacon(hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -0700986 beacon_data_t **ppBeacon,
987 struct beacon_parameters *params)
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700988#else
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530989int wlan_hdd_cfg80211_alloc_new_beacon(hdd_adapter_t *pAdapter,
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700990 beacon_data_t **ppBeacon,
991 struct cfg80211_beacon_data *params,
992 int dtim_period)
993#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +0530994{
Jeff Johnson295189b2012-06-20 16:38:30 -0700995 int size;
996 beacon_data_t *beacon = NULL;
997 beacon_data_t *old = NULL;
998 int head_len,tail_len;
999
Jeff Johnsone7245742012-09-05 17:12:55 -07001000 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07001001 if (params->head && !params->head_len)
1002 return -EINVAL;
1003
1004 old = pAdapter->sessionCtx.ap.beacon;
1005
1006 if (!params->head && !old)
1007 return -EINVAL;
1008
1009 if (params->tail && !params->tail_len)
1010 return -EINVAL;
1011
1012#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,38))
1013 /* Kernel 3.0 is not updating dtim_period for set beacon */
1014 if (!params->dtim_period)
1015 return -EINVAL;
1016#endif
1017
1018 if(params->head)
1019 head_len = params->head_len;
1020 else
1021 head_len = old->head_len;
1022
1023 if(params->tail || !old)
1024 tail_len = params->tail_len;
1025 else
1026 tail_len = old->tail_len;
1027
1028 size = sizeof(beacon_data_t) + head_len + tail_len;
1029
1030 beacon = kzalloc(size, GFP_KERNEL);
1031
1032 if( beacon == NULL )
1033 return -ENOMEM;
1034
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001035#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07001036 if(params->dtim_period || !old )
1037 beacon->dtim_period = params->dtim_period;
1038 else
1039 beacon->dtim_period = old->dtim_period;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001040#else
1041 if(dtim_period || !old )
1042 beacon->dtim_period = dtim_period;
1043 else
1044 beacon->dtim_period = old->dtim_period;
1045#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301046
Jeff Johnson295189b2012-06-20 16:38:30 -07001047 beacon->head = ((u8 *) beacon) + sizeof(beacon_data_t);
1048 beacon->tail = beacon->head + head_len;
1049 beacon->head_len = head_len;
1050 beacon->tail_len = tail_len;
1051
1052 if(params->head) {
1053 memcpy (beacon->head,params->head,beacon->head_len);
1054 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301055 else {
Jeff Johnson295189b2012-06-20 16:38:30 -07001056 if(old)
1057 memcpy (beacon->head,old->head,beacon->head_len);
1058 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301059
Jeff Johnson295189b2012-06-20 16:38:30 -07001060 if(params->tail) {
1061 memcpy (beacon->tail,params->tail,beacon->tail_len);
1062 }
1063 else {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301064 if(old)
Jeff Johnson295189b2012-06-20 16:38:30 -07001065 memcpy (beacon->tail,old->tail,beacon->tail_len);
1066 }
1067
1068 *ppBeacon = beacon;
1069
1070 kfree(old);
1071
1072 return 0;
1073
1074}
Jeff Johnson295189b2012-06-20 16:38:30 -07001075
1076v_U8_t* wlan_hdd_cfg80211_get_ie_ptr(v_U8_t *pIes, int length, v_U8_t eid)
1077{
1078 int left = length;
1079 v_U8_t *ptr = pIes;
1080 v_U8_t elem_id,elem_len;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301081
Jeff Johnson295189b2012-06-20 16:38:30 -07001082 while(left >= 2)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301083 {
Jeff Johnson295189b2012-06-20 16:38:30 -07001084 elem_id = ptr[0];
1085 elem_len = ptr[1];
1086 left -= 2;
1087 if(elem_len > left)
1088 {
1089 hddLog(VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi8bdd3112012-09-24 13:55:14 -07001090 FL("****Invalid IEs eid = %d elem_len=%d left=%d*****"),
Jeff Johnson295189b2012-06-20 16:38:30 -07001091 eid,elem_len,left);
1092 return NULL;
1093 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301094 if (elem_id == eid)
Jeff Johnson295189b2012-06-20 16:38:30 -07001095 {
1096 return ptr;
1097 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301098
Jeff Johnson295189b2012-06-20 16:38:30 -07001099 left -= elem_len;
1100 ptr += (elem_len + 2);
1101 }
1102 return NULL;
1103}
1104
Jeff Johnson295189b2012-06-20 16:38:30 -07001105/* Check if rate is 11g rate or not */
1106static int wlan_hdd_rate_is_11g(u8 rate)
1107{
Sanjay Devnani28322e22013-06-21 16:13:40 -07001108 static const u8 gRateArray[8] = {12, 18, 24, 36, 48, 72, 96, 108}; /* actual rate * 2 */
Jeff Johnson295189b2012-06-20 16:38:30 -07001109 u8 i;
1110 for (i = 0; i < 8; i++)
1111 {
1112 if(rate == gRateArray[i])
1113 return TRUE;
1114 }
1115 return FALSE;
1116}
1117
1118/* Check for 11g rate and set proper 11g only mode */
1119static void wlan_hdd_check_11gmode(u8 *pIe, u8* require_ht,
1120 u8* pCheckRatesfor11g, eSapPhyMode* pSapHw_mode)
1121{
1122 u8 i, num_rates = pIe[0];
1123
1124 pIe += 1;
1125 for ( i = 0; i < num_rates; i++)
1126 {
1127 if( *pCheckRatesfor11g && (TRUE == wlan_hdd_rate_is_11g(pIe[i] & RATE_MASK)))
1128 {
1129 /* If rate set have 11g rate than change the mode to 11G */
1130 *pSapHw_mode = eSAP_DOT11_MODE_11g;
1131 if (pIe[i] & BASIC_RATE_MASK)
1132 {
1133 /* If we have 11g rate as basic rate, it means mode
1134 is 11g only mode.
1135 */
1136 *pSapHw_mode = eSAP_DOT11_MODE_11g_ONLY;
1137 *pCheckRatesfor11g = FALSE;
1138 }
1139 }
1140 else if((BASIC_RATE_MASK | WLAN_BSS_MEMBERSHIP_SELECTOR_HT_PHY) == pIe[i])
1141 {
1142 *require_ht = TRUE;
1143 }
1144 }
1145 return;
1146}
1147
1148static void wlan_hdd_set_sapHwmode(hdd_adapter_t *pHostapdAdapter)
1149{
1150 tsap_Config_t *pConfig = &pHostapdAdapter->sessionCtx.ap.sapConfig;
1151 beacon_data_t *pBeacon = pHostapdAdapter->sessionCtx.ap.beacon;
1152 struct ieee80211_mgmt *pMgmt_frame = (struct ieee80211_mgmt*)pBeacon->head;
1153 u8 checkRatesfor11g = TRUE;
1154 u8 require_ht = FALSE;
1155 u8 *pIe=NULL;
1156
1157 pConfig->SapHw_mode= eSAP_DOT11_MODE_11b;
1158
1159 pIe = wlan_hdd_cfg80211_get_ie_ptr(&pMgmt_frame->u.beacon.variable[0],
1160 pBeacon->head_len, WLAN_EID_SUPP_RATES);
1161 if (pIe != NULL)
1162 {
1163 pIe += 1;
1164 wlan_hdd_check_11gmode(pIe, &require_ht, &checkRatesfor11g,
1165 &pConfig->SapHw_mode);
1166 }
1167
1168 pIe = wlan_hdd_cfg80211_get_ie_ptr(pBeacon->tail, pBeacon->tail_len,
1169 WLAN_EID_EXT_SUPP_RATES);
1170 if (pIe != NULL)
1171 {
1172
1173 pIe += 1;
1174 wlan_hdd_check_11gmode(pIe, &require_ht, &checkRatesfor11g,
1175 &pConfig->SapHw_mode);
1176 }
1177
1178 if( pConfig->channel > 14 )
1179 {
1180 pConfig->SapHw_mode= eSAP_DOT11_MODE_11a;
1181 }
1182
1183 pIe = wlan_hdd_cfg80211_get_ie_ptr(pBeacon->tail, pBeacon->tail_len,
1184 WLAN_EID_HT_CAPABILITY);
1185
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301186 if(pIe)
Jeff Johnson295189b2012-06-20 16:38:30 -07001187 {
1188 pConfig->SapHw_mode= eSAP_DOT11_MODE_11n;
1189 if(require_ht)
1190 pConfig->SapHw_mode= eSAP_DOT11_MODE_11n_ONLY;
1191 }
1192}
1193
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301194static int wlan_hdd_add_ie(hdd_adapter_t* pHostapdAdapter, v_U8_t *genie,
1195 v_U8_t *total_ielen, v_U8_t *oui, v_U8_t oui_size)
1196{
Arif Hussaine7f3ea52013-09-12 21:56:36 -07001197 v_U16_t ielen = 0;
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301198 v_U8_t *pIe = NULL;
1199 beacon_data_t *pBeacon = pHostapdAdapter->sessionCtx.ap.beacon;
1200
1201 pIe = wlan_hdd_get_vendor_oui_ie_ptr(oui, oui_size,
1202 pBeacon->tail, pBeacon->tail_len);
1203
1204 if (pIe)
1205 {
1206 ielen = pIe[1] + 2;
1207 if ((*total_ielen + ielen) <= MAX_GENIE_LEN)
1208 {
1209 vos_mem_copy(&genie[*total_ielen], pIe, ielen);
1210 }
1211 else
1212 {
1213 hddLog( VOS_TRACE_LEVEL_ERROR, "**Ie Length is too big***");
1214 return -EINVAL;
1215 }
1216 *total_ielen += ielen;
1217 }
1218 return 0;
1219}
1220
Arif Hussaine7f3ea52013-09-12 21:56:36 -07001221static void wlan_hdd_add_hostapd_conf_vsie(hdd_adapter_t* pHostapdAdapter,
1222 v_U8_t *genie, v_U8_t *total_ielen)
1223{
1224 beacon_data_t *pBeacon = pHostapdAdapter->sessionCtx.ap.beacon;
1225 int left = pBeacon->tail_len;
1226 v_U8_t *ptr = pBeacon->tail;
1227 v_U8_t elem_id, elem_len;
1228 v_U16_t ielen = 0;
1229
1230 if ( NULL == ptr || 0 == left )
1231 return;
1232
1233 while (left >= 2)
1234 {
1235 elem_id = ptr[0];
1236 elem_len = ptr[1];
1237 left -= 2;
1238 if (elem_len > left)
1239 {
1240 hddLog( VOS_TRACE_LEVEL_ERROR,
1241 "****Invalid IEs eid = %d elem_len=%d left=%d*****",
1242 elem_id, elem_len, left);
1243 return;
1244 }
1245 if (IE_EID_VENDOR == elem_id)
1246 {
1247 /* skipping the VSIE's which we don't want to include or
1248 * it will be included by existing code
1249 */
1250 if ((memcmp( &ptr[2], WPS_OUI_TYPE, WPS_OUI_TYPE_SIZE) != 0 ) &&
1251#ifdef WLAN_FEATURE_WFD
1252 (memcmp( &ptr[2], WFD_OUI_TYPE, WFD_OUI_TYPE_SIZE) != 0) &&
1253#endif
1254 (memcmp( &ptr[2], WHITELIST_OUI_TYPE, WPA_OUI_TYPE_SIZE) != 0) &&
1255 (memcmp( &ptr[2], BLACKLIST_OUI_TYPE, WPA_OUI_TYPE_SIZE) != 0) &&
1256 (memcmp( &ptr[2], "\x00\x50\xf2\x02", WPA_OUI_TYPE_SIZE) != 0) &&
1257 (memcmp( &ptr[2], WPA_OUI_TYPE, WPA_OUI_TYPE_SIZE) != 0) &&
1258 (memcmp( &ptr[2], P2P_OUI_TYPE, P2P_OUI_TYPE_SIZE) != 0))
1259 {
1260 ielen = ptr[1] + 2;
1261 if ((*total_ielen + ielen) <= MAX_GENIE_LEN)
1262 {
1263 vos_mem_copy(&genie[*total_ielen], ptr, ielen);
1264 *total_ielen += ielen;
1265 }
1266 else
1267 {
1268 hddLog( VOS_TRACE_LEVEL_ERROR,
1269 "IE Length is too big "
1270 "IEs eid=%d elem_len=%d total_ie_lent=%d",
1271 elem_id, elem_len, *total_ielen);
1272 }
1273 }
1274 }
1275
1276 left -= elem_len;
1277 ptr += (elem_len + 2);
1278 }
1279 return;
1280}
1281
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001282#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07001283static int wlan_hdd_cfg80211_update_apies(hdd_adapter_t* pHostapdAdapter,
1284 struct beacon_parameters *params)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001285#else
1286static int wlan_hdd_cfg80211_update_apies(hdd_adapter_t* pHostapdAdapter,
1287 struct cfg80211_beacon_data *params)
1288#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07001289{
1290 v_U8_t *genie;
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301291 v_U8_t total_ielen = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07001292 v_U8_t addIE[1] = {0};
Jeff Johnsone7245742012-09-05 17:12:55 -07001293 int ret = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07001294
1295 genie = vos_mem_malloc(MAX_GENIE_LEN);
1296
1297 if(genie == NULL) {
1298
1299 return -ENOMEM;
1300 }
1301
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301302 if (0 != wlan_hdd_add_ie(pHostapdAdapter, genie,
1303 &total_ielen, WPS_OUI_TYPE, WPS_OUI_TYPE_SIZE))
Jeff Johnson295189b2012-06-20 16:38:30 -07001304 {
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301305 ret = -EINVAL;
1306 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001307 }
1308
1309#ifdef WLAN_FEATURE_WFD
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301310 if (0 != wlan_hdd_add_ie(pHostapdAdapter, genie,
1311 &total_ielen, WFD_OUI_TYPE, WFD_OUI_TYPE_SIZE))
1312 {
1313 ret = -EINVAL;
1314 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001315 }
1316#endif
1317
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301318 if (0 != wlan_hdd_add_ie(pHostapdAdapter, genie,
1319 &total_ielen, P2P_OUI_TYPE, P2P_OUI_TYPE_SIZE))
Jeff Johnson295189b2012-06-20 16:38:30 -07001320 {
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301321 ret = -EINVAL;
1322 goto done;
1323 }
1324
1325 if (WLAN_HDD_SOFTAP == pHostapdAdapter->device_mode)
1326 {
Arif Hussaine7f3ea52013-09-12 21:56:36 -07001327 wlan_hdd_add_hostapd_conf_vsie(pHostapdAdapter, genie, &total_ielen);
Jeff Johnson295189b2012-06-20 16:38:30 -07001328 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001329
1330 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1331 WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA, genie, total_ielen, NULL,
1332 eANI_BOOLEAN_FALSE)==eHAL_STATUS_FAILURE)
1333 {
1334 hddLog(LOGE,
1335 "Could not pass on WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001336 ret = -EINVAL;
1337 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001338 }
1339
1340 if (ccmCfgSetInt((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1341 WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG, 1,NULL,
1342 test_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags) ?
1343 eANI_BOOLEAN_TRUE : eANI_BOOLEAN_FALSE)
1344 ==eHAL_STATUS_FAILURE)
1345 {
1346 hddLog(LOGE,
1347 "Could not pass on WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001348 ret = -EINVAL;
1349 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001350 }
1351
1352 // Added for ProResp IE
1353 if ( (params->proberesp_ies != NULL) && (params->proberesp_ies_len != 0) )
1354 {
1355 u16 rem_probe_resp_ie_len = params->proberesp_ies_len;
1356 u8 probe_rsp_ie_len[3] = {0};
1357 u8 counter = 0;
1358 /* Check Probe Resp Length if it is greater then 255 then Store
1359 Probe Resp IEs into WNI_CFG_PROBE_RSP_ADDNIE_DATA1 &
1360 WNI_CFG_PROBE_RSP_ADDNIE_DATA2 CFG Variable As We are not able
1361 Store More then 255 bytes into One Variable.
1362 */
1363 while ((rem_probe_resp_ie_len > 0) && (counter < 3))
1364 {
1365 if (rem_probe_resp_ie_len > MAX_CFG_STRING_LEN)
1366 {
1367 probe_rsp_ie_len[counter++] = MAX_CFG_STRING_LEN;
1368 rem_probe_resp_ie_len -= MAX_CFG_STRING_LEN;
1369 }
1370 else
1371 {
1372 probe_rsp_ie_len[counter++] = rem_probe_resp_ie_len;
1373 rem_probe_resp_ie_len = 0;
1374 }
1375 }
1376
1377 rem_probe_resp_ie_len = 0;
1378
1379 if (probe_rsp_ie_len[0] > 0)
1380 {
1381 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1382 WNI_CFG_PROBE_RSP_ADDNIE_DATA1,
1383 (tANI_U8*)&params->proberesp_ies[rem_probe_resp_ie_len],
1384 probe_rsp_ie_len[0], NULL,
1385 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
1386 {
1387 hddLog(LOGE,
1388 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA1 to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001389 ret = -EINVAL;
1390 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001391 }
1392 rem_probe_resp_ie_len += probe_rsp_ie_len[0];
1393 }
1394
1395 if (probe_rsp_ie_len[1] > 0)
1396 {
1397 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1398 WNI_CFG_PROBE_RSP_ADDNIE_DATA2,
1399 (tANI_U8*)&params->proberesp_ies[rem_probe_resp_ie_len],
1400 probe_rsp_ie_len[1], NULL,
1401 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
1402 {
1403 hddLog(LOGE,
1404 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA2 to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001405 ret = -EINVAL;
1406 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001407 }
1408 rem_probe_resp_ie_len += probe_rsp_ie_len[1];
1409 }
1410
1411 if (probe_rsp_ie_len[2] > 0)
1412 {
1413 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1414 WNI_CFG_PROBE_RSP_ADDNIE_DATA3,
1415 (tANI_U8*)&params->proberesp_ies[rem_probe_resp_ie_len],
1416 probe_rsp_ie_len[2], NULL,
1417 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
1418 {
1419 hddLog(LOGE,
1420 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA3 to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001421 ret = -EINVAL;
1422 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001423 }
1424 rem_probe_resp_ie_len += probe_rsp_ie_len[2];
1425 }
1426
1427 if (probe_rsp_ie_len[1] == 0 )
1428 {
1429 if ( eHAL_STATUS_FAILURE == ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1430 WNI_CFG_PROBE_RSP_ADDNIE_DATA2, (tANI_U8*)addIE, 0, NULL,
1431 eANI_BOOLEAN_FALSE) )
1432 {
1433 hddLog(LOGE,
1434 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA2 to CCM\n");
1435 }
1436 }
1437
1438 if (probe_rsp_ie_len[2] == 0 )
1439 {
1440 if ( eHAL_STATUS_FAILURE == ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1441 WNI_CFG_PROBE_RSP_ADDNIE_DATA3, (tANI_U8*)addIE, 0, NULL,
1442 eANI_BOOLEAN_FALSE) )
1443 {
1444 hddLog(LOGE,
1445 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA3 to CCM\n");
1446 }
1447 }
1448
1449 if (ccmCfgSetInt((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1450 WNI_CFG_PROBE_RSP_ADDNIE_FLAG, 1,NULL,
1451 test_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags) ?
1452 eANI_BOOLEAN_TRUE : eANI_BOOLEAN_FALSE)
1453 == eHAL_STATUS_FAILURE)
1454 {
1455 hddLog(LOGE,
1456 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_FLAG to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001457 ret = -EINVAL;
1458 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001459 }
1460 }
1461 else
1462 {
1463 // Reset WNI_CFG_PROBE_RSP Flags
1464 wlan_hdd_reset_prob_rspies(pHostapdAdapter);
1465
1466 hddLog(VOS_TRACE_LEVEL_INFO,
1467 "%s: No Probe Response IE received in set beacon",
1468 __func__);
1469 }
1470
1471 // Added for AssocResp IE
1472 if ( (params->assocresp_ies != NULL) && (params->assocresp_ies_len != 0) )
1473 {
1474 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1475 WNI_CFG_ASSOC_RSP_ADDNIE_DATA, (tANI_U8*)params->assocresp_ies,
1476 params->assocresp_ies_len, NULL,
1477 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
1478 {
1479 hddLog(LOGE,
1480 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_DATA to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001481 ret = -EINVAL;
1482 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001483 }
1484
1485 if (ccmCfgSetInt((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1486 WNI_CFG_ASSOC_RSP_ADDNIE_FLAG, 1, NULL,
1487 test_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags) ?
1488 eANI_BOOLEAN_TRUE : eANI_BOOLEAN_FALSE)
1489 == eHAL_STATUS_FAILURE)
1490 {
1491 hddLog(LOGE,
1492 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_FLAG to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001493 ret = -EINVAL;
1494 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001495 }
1496 }
1497 else
1498 {
1499 hddLog(VOS_TRACE_LEVEL_INFO,
1500 "%s: No Assoc Response IE received in set beacon",
1501 __func__);
1502
1503 if ( eHAL_STATUS_FAILURE == ccmCfgSetInt((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1504 WNI_CFG_ASSOC_RSP_ADDNIE_FLAG, 0, NULL,
1505 eANI_BOOLEAN_FALSE) )
1506 {
1507 hddLog(LOGE,
1508 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_FLAG to CCM\n");
1509 }
1510 }
1511
Jeff Johnsone7245742012-09-05 17:12:55 -07001512done:
Jeff Johnson295189b2012-06-20 16:38:30 -07001513 vos_mem_free(genie);
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301514 return ret;
Jeff Johnson295189b2012-06-20 16:38:30 -07001515}
Jeff Johnson295189b2012-06-20 16:38:30 -07001516
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301517/*
Jeff Johnson295189b2012-06-20 16:38:30 -07001518 * FUNCTION: wlan_hdd_validate_operation_channel
1519 * called by wlan_hdd_cfg80211_start_bss() and
1520 * wlan_hdd_cfg80211_set_channel()
1521 * This function validates whether given channel is part of valid
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301522 * channel list.
1523 */
Varun Reddy Yeturu920df212013-05-22 08:07:23 -07001524VOS_STATUS wlan_hdd_validate_operation_channel(hdd_adapter_t *pAdapter,int channel)
Jeff Johnson295189b2012-06-20 16:38:30 -07001525{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301526
Jeff Johnson295189b2012-06-20 16:38:30 -07001527 v_U32_t num_ch = 0;
1528 u8 valid_ch[WNI_CFG_VALID_CHANNEL_LIST_LEN];
1529 u32 indx = 0;
1530 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301531 v_U8_t fValidChannel = FALSE, count = 0;
1532 hdd_config_t *hdd_pConfig_ini= (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301533
Jeff Johnson295189b2012-06-20 16:38:30 -07001534 num_ch = WNI_CFG_VALID_CHANNEL_LIST_LEN;
1535
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301536 if ( hdd_pConfig_ini->sapAllowAllChannel)
Jeff Johnson295189b2012-06-20 16:38:30 -07001537 {
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301538 /* Validate the channel */
1539 for (count = RF_CHAN_1 ; count <= RF_CHAN_165 ; count++)
Jeff Johnson295189b2012-06-20 16:38:30 -07001540 {
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301541 if ( channel == rfChannels[count].channelNum )
1542 {
1543 fValidChannel = TRUE;
1544 break;
1545 }
1546 }
1547 if (fValidChannel != TRUE)
1548 {
1549 hddLog(VOS_TRACE_LEVEL_ERROR,
1550 "%s: Invalid Channel [%d]", __func__, channel);
1551 return VOS_STATUS_E_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07001552 }
1553 }
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301554 else
Jeff Johnson295189b2012-06-20 16:38:30 -07001555 {
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301556 if (0 != ccmCfgGetStr(hHal, WNI_CFG_VALID_CHANNEL_LIST,
1557 valid_ch, &num_ch))
1558 {
1559 hddLog(VOS_TRACE_LEVEL_ERROR,
1560 "%s: failed to get valid channel list", __func__);
1561 return VOS_STATUS_E_FAILURE;
1562 }
1563 for (indx = 0; indx < num_ch; indx++)
1564 {
1565 if (channel == valid_ch[indx])
1566 {
1567 break;
1568 }
1569 }
1570
1571 if (indx >= num_ch)
1572 {
1573 hddLog(VOS_TRACE_LEVEL_ERROR,
1574 "%s: Invalid Channel [%d]", __func__, channel);
1575 return VOS_STATUS_E_FAILURE;
1576 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001577 }
1578 return VOS_STATUS_SUCCESS;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301579
Jeff Johnson295189b2012-06-20 16:38:30 -07001580}
1581
Viral Modi3a32cc52013-02-08 11:14:52 -08001582/**
1583 * FUNCTION: wlan_hdd_cfg80211_set_channel
1584 * This function is used to set the channel number
1585 */
1586static int wlan_hdd_cfg80211_set_channel( struct wiphy *wiphy, struct net_device *dev,
1587 struct ieee80211_channel *chan,
1588 enum nl80211_channel_type channel_type
1589 )
1590{
1591 v_U32_t num_ch = 0;
Jeff Johnson4416a782013-03-25 14:17:50 -07001592 int channel = 0;
Viral Modi3a32cc52013-02-08 11:14:52 -08001593 hdd_adapter_t *pAdapter = NULL;
1594 int freq = chan->center_freq; /* freq is in MHZ */
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05301595 hdd_context_t *pHddCtx;
1596 int status;
Viral Modi3a32cc52013-02-08 11:14:52 -08001597
1598 ENTER();
1599
1600 if( NULL == dev )
1601 {
1602 hddLog(VOS_TRACE_LEVEL_ERROR,
1603 "%s: Called with dev = NULL.\n", __func__);
1604 return -ENODEV;
1605 }
1606 pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
1607
1608 hddLog(VOS_TRACE_LEVEL_INFO,
1609 "%s: device_mode = %d freq = %d \n",__func__,
1610 pAdapter->device_mode, chan->center_freq);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05301611
1612 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
1613 status = wlan_hdd_validate_context(pHddCtx);
1614
1615 if (0 != status)
Viral Modi3a32cc52013-02-08 11:14:52 -08001616 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05301617 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1618 "%s: HDD context is not valid", __func__);
1619 return status;
Viral Modi3a32cc52013-02-08 11:14:52 -08001620 }
1621
1622 /*
1623 * Do freq to chan conversion
1624 * TODO: for 11a
1625 */
1626
1627 channel = ieee80211_frequency_to_channel(freq);
1628
1629 /* Check freq range */
1630 if ((WNI_CFG_CURRENT_CHANNEL_STAMIN > channel) ||
1631 (WNI_CFG_CURRENT_CHANNEL_STAMAX < channel))
1632 {
1633 hddLog(VOS_TRACE_LEVEL_ERROR,
1634 "%s: Channel [%d] is outside valid range from %d to %d\n",
1635 __func__, channel, WNI_CFG_CURRENT_CHANNEL_STAMIN,
1636 WNI_CFG_CURRENT_CHANNEL_STAMAX);
1637 return -EINVAL;
1638 }
1639
1640 num_ch = WNI_CFG_VALID_CHANNEL_LIST_LEN;
1641
Gopichand Nakkala6ab19562013-03-07 13:59:42 +05301642 if ((WLAN_HDD_SOFTAP != pAdapter->device_mode) &&
1643 (WLAN_HDD_P2P_GO != pAdapter->device_mode))
Viral Modi3a32cc52013-02-08 11:14:52 -08001644 {
1645 if(VOS_STATUS_SUCCESS != wlan_hdd_validate_operation_channel(pAdapter,channel))
1646 {
1647 hddLog(VOS_TRACE_LEVEL_ERROR,
1648 "%s: Invalid Channel [%d] \n", __func__, channel);
1649 return -EINVAL;
1650 }
1651 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
1652 "%s: set channel to [%d] for device mode =%d",
1653 __func__, channel,pAdapter->device_mode);
1654 }
1655 if( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Viral Modi3a32cc52013-02-08 11:14:52 -08001656 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Viral Modi3a32cc52013-02-08 11:14:52 -08001657 )
1658 {
1659 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
1660 tCsrRoamProfile * pRoamProfile = &pWextState->roamProfile;
1661 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
1662
1663 if (eConnectionState_IbssConnected == pHddStaCtx->conn_info.connState)
1664 {
1665 /* Link is up then return cant set channel*/
1666 hddLog( VOS_TRACE_LEVEL_ERROR,
1667 "%s: IBSS Associated, can't set the channel\n", __func__);
1668 return -EINVAL;
1669 }
1670
1671 num_ch = pRoamProfile->ChannelInfo.numOfChannels = 1;
1672 pHddStaCtx->conn_info.operationChannel = channel;
1673 pRoamProfile->ChannelInfo.ChannelList =
1674 &pHddStaCtx->conn_info.operationChannel;
1675 }
1676 else if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Viral Modi3a32cc52013-02-08 11:14:52 -08001677 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Viral Modi3a32cc52013-02-08 11:14:52 -08001678 )
1679 {
Gopichand Nakkalac8fa7b62013-03-11 13:56:41 +05301680 if (WLAN_HDD_P2P_GO == pAdapter->device_mode)
1681 {
1682 if(VOS_STATUS_SUCCESS !=
1683 wlan_hdd_validate_operation_channel(pAdapter,channel))
1684 {
1685 hddLog(VOS_TRACE_LEVEL_ERROR,
1686 "%s: Invalid Channel [%d] \n", __func__, channel);
1687 return -EINVAL;
1688 }
1689 (WLAN_HDD_GET_AP_CTX_PTR(pAdapter))->sapConfig.channel = channel;
1690 }
1691 else if ( WLAN_HDD_SOFTAP == pAdapter->device_mode )
Viral Modi3a32cc52013-02-08 11:14:52 -08001692 {
1693 hdd_config_t *cfg_param = (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini;
1694
1695 /* If auto channel selection is configured as enable/ 1 then ignore
1696 channel set by supplicant
1697 */
1698 if ( cfg_param->apAutoChannelSelection )
1699 {
Gopichand Nakkalac8fa7b62013-03-11 13:56:41 +05301700 (WLAN_HDD_GET_AP_CTX_PTR(pAdapter))->sapConfig.channel =
1701 AUTO_CHANNEL_SELECT;
Viral Modi3a32cc52013-02-08 11:14:52 -08001702 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
1703 "%s: set channel to auto channel (0) for device mode =%d",
1704 __func__, pAdapter->device_mode);
1705 }
Gopichand Nakkalac8fa7b62013-03-11 13:56:41 +05301706 else
1707 {
1708 if(VOS_STATUS_SUCCESS !=
1709 wlan_hdd_validate_operation_channel(pAdapter,channel))
1710 {
1711 hddLog(VOS_TRACE_LEVEL_ERROR,
1712 "%s: Invalid Channel [%d] \n", __func__, channel);
1713 return -EINVAL;
1714 }
1715 (WLAN_HDD_GET_AP_CTX_PTR(pAdapter))->sapConfig.channel = channel;
1716 }
Viral Modi3a32cc52013-02-08 11:14:52 -08001717 }
1718 }
1719 else
1720 {
1721 hddLog(VOS_TRACE_LEVEL_FATAL,
1722 "%s: Invalid device mode failed to set valid channel", __func__);
1723 return -EINVAL;
1724 }
1725 EXIT();
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05301726 return status;
Viral Modi3a32cc52013-02-08 11:14:52 -08001727}
1728
Jeff Johnson295189b2012-06-20 16:38:30 -07001729#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
1730static int wlan_hdd_cfg80211_start_bss(hdd_adapter_t *pHostapdAdapter,
1731 struct beacon_parameters *params)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001732#else
1733static int wlan_hdd_cfg80211_start_bss(hdd_adapter_t *pHostapdAdapter,
1734 struct cfg80211_beacon_data *params,
1735 const u8 *ssid, size_t ssid_len,
1736 enum nl80211_hidden_ssid hidden_ssid)
1737#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07001738{
1739 tsap_Config_t *pConfig;
1740 beacon_data_t *pBeacon = NULL;
1741 struct ieee80211_mgmt *pMgmt_frame;
1742 v_U8_t *pIe=NULL;
1743 v_U16_t capab_info;
1744 eCsrAuthType RSNAuthType;
1745 eCsrEncryptionType RSNEncryptType;
1746 eCsrEncryptionType mcRSNEncryptType;
1747 int status = VOS_STATUS_SUCCESS;
1748 tpWLAN_SAPEventCB pSapEventCallback;
1749 hdd_hostapd_state_t *pHostapdState;
1750 v_U8_t wpaRsnIEdata[(SIR_MAC_MAX_IE_LENGTH * 2)+4]; //Max ie length 255 * 2(WPA+RSN) + 2 bytes (vendor specific ID) * 2
1751 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pHostapdAdapter))->pvosContext;
Madan Mohan Koyylamudia16d0202013-02-01 11:05:57 +05301752 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pHostapdAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001753 struct qc_mac_acl_entry *acl_entry = NULL;
1754 v_SINT_t i;
Madan Mohan Koyyalamudi543172b2012-12-05 16:40:18 -08001755 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pHostapdAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001756
1757 ENTER();
1758
1759 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pHostapdAdapter);
1760
1761 pConfig = &pHostapdAdapter->sessionCtx.ap.sapConfig;
1762
1763 pBeacon = pHostapdAdapter->sessionCtx.ap.beacon;
1764
1765 pMgmt_frame = (struct ieee80211_mgmt*)pBeacon->head;
1766
1767 pConfig->beacon_int = pMgmt_frame->u.beacon.beacon_int;
1768
1769 //channel is already set in the set_channel Call back
1770 //pConfig->channel = pCommitConfig->channel;
1771
1772 /*Protection parameter to enable or disable*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301773 pConfig->protEnabled =
Jeff Johnson295189b2012-06-20 16:38:30 -07001774 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apProtEnabled;
1775
1776 pConfig->dtim_period = pBeacon->dtim_period;
1777
1778 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,"****pConfig->dtim_period=%d***\n",
1779 pConfig->dtim_period);
1780
1781
Madan Mohan Koyyalamudie0ca11f2012-11-27 15:57:52 -08001782 if (pHostapdAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson32d95a32012-09-10 13:15:23 -07001783 {
1784 pIe = wlan_hdd_cfg80211_get_ie_ptr(pBeacon->tail, pBeacon->tail_len,
Jeff Johnson295189b2012-06-20 16:38:30 -07001785 WLAN_EID_COUNTRY);
Jeff Johnson32d95a32012-09-10 13:15:23 -07001786 if(pIe)
Jeff Johnson295189b2012-06-20 16:38:30 -07001787 {
Jeff Johnson32d95a32012-09-10 13:15:23 -07001788 tANI_BOOLEAN restartNeeded;
Jeff Johnson32d95a32012-09-10 13:15:23 -07001789 pConfig->ieee80211d = 1;
1790 vos_mem_copy(pConfig->countryCode, &pIe[2], 3);
1791 sme_setRegInfo(hHal, pConfig->countryCode);
1792 sme_ResetCountryCodeInformation(hHal, &restartNeeded);
Jeff Johnson295189b2012-06-20 16:38:30 -07001793 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07001794 else
1795 {
1796 pConfig->ieee80211d = 0;
1797 }
Madan Mohan Koyylamudia16d0202013-02-01 11:05:57 +05301798 /*
1799 * If auto channel is configured i.e. channel is 0,
1800 * so skip channel validation.
1801 */
1802 if( AUTO_CHANNEL_SELECT != pConfig->channel )
1803 {
1804 if(VOS_STATUS_SUCCESS != wlan_hdd_validate_operation_channel(pHostapdAdapter,pConfig->channel))
1805 {
1806 hddLog(VOS_TRACE_LEVEL_ERROR,
1807 "%s: Invalid Channel [%d] \n", __func__, pConfig->channel);
1808 return -EINVAL;
1809 }
1810 }
1811 else
1812 {
1813 if(1 != pHddCtx->is_dynamic_channel_range_set)
1814 {
1815 hdd_config_t *hdd_pConfig= (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini;
1816 WLANSAP_SetChannelRange(hHal, hdd_pConfig->apStartChannelNum,
1817 hdd_pConfig->apEndChannelNum,hdd_pConfig->apOperatingBand);
1818 }
1819 pHddCtx->is_dynamic_channel_range_set = 0;
1820 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001821 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07001822 else
Jeff Johnson295189b2012-06-20 16:38:30 -07001823 {
1824 pConfig->ieee80211d = 0;
1825 }
1826 pConfig->authType = eSAP_AUTO_SWITCH;
1827
1828 capab_info = pMgmt_frame->u.beacon.capab_info;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301829
1830 pConfig->privacy = (pMgmt_frame->u.beacon.capab_info &
Jeff Johnson295189b2012-06-20 16:38:30 -07001831 WLAN_CAPABILITY_PRIVACY) ? VOS_TRUE : VOS_FALSE;
1832
1833 (WLAN_HDD_GET_AP_CTX_PTR(pHostapdAdapter))->uPrivacy = pConfig->privacy;
1834
1835 /*Set wps station to configured*/
1836 pIe = wlan_hdd_get_wps_ie_ptr(pBeacon->tail, pBeacon->tail_len);
1837
1838 if(pIe)
1839 {
1840 if(pIe[1] < (2 + WPS_OUI_TYPE_SIZE))
1841 {
1842 hddLog( VOS_TRACE_LEVEL_ERROR, "**Wps Ie Length is too small***\n");
1843 return -EINVAL;
1844 }
1845 else if(memcmp(&pIe[2], WPS_OUI_TYPE, WPS_OUI_TYPE_SIZE) == 0)
1846 {
Madan Mohan Koyyalamudi8bdd3112012-09-24 13:55:14 -07001847 hddLog( VOS_TRACE_LEVEL_INFO, "** WPS IE(len %d) ***", (pIe[1]+2));
Jeff Johnson295189b2012-06-20 16:38:30 -07001848 /* Check 15 bit of WPS IE as it contain information for wps state
1849 * WPS state
1850 */
1851 if(SAP_WPS_ENABLED_UNCONFIGURED == pIe[15])
1852 {
1853 pConfig->wps_state = SAP_WPS_ENABLED_UNCONFIGURED;
1854 } else if(SAP_WPS_ENABLED_CONFIGURED == pIe[15])
1855 {
1856 pConfig->wps_state = SAP_WPS_ENABLED_CONFIGURED;
1857 }
1858 }
1859 }
1860 else
1861 {
1862 pConfig->wps_state = SAP_WPS_DISABLED;
1863 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301864 pConfig->fwdWPSPBCProbeReq = 1; // Forward WPS PBC probe request frame up
Jeff Johnson295189b2012-06-20 16:38:30 -07001865
1866 pConfig->RSNWPAReqIELength = 0;
1867 pConfig->pRSNWPAReqIE = NULL;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301868 pIe = wlan_hdd_cfg80211_get_ie_ptr(pBeacon->tail, pBeacon->tail_len,
Jeff Johnson295189b2012-06-20 16:38:30 -07001869 WLAN_EID_RSN);
1870 if(pIe && pIe[1])
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301871 {
Jeff Johnson295189b2012-06-20 16:38:30 -07001872 pConfig->RSNWPAReqIELength = pIe[1] + 2;
1873 memcpy(&wpaRsnIEdata[0], pIe, pConfig->RSNWPAReqIELength);
1874 pConfig->pRSNWPAReqIE = &wpaRsnIEdata[0];
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301875 /* The actual processing may eventually be more extensive than
1876 * this. Right now, just consume any PMKIDs that are sent in
Jeff Johnson295189b2012-06-20 16:38:30 -07001877 * by the app.
1878 * */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301879 status = hdd_softap_unpackIE(
Jeff Johnson295189b2012-06-20 16:38:30 -07001880 vos_get_context( VOS_MODULE_ID_SME, pVosContext),
1881 &RSNEncryptType,
1882 &mcRSNEncryptType,
1883 &RSNAuthType,
1884 pConfig->pRSNWPAReqIE[1]+2,
1885 pConfig->pRSNWPAReqIE );
1886
1887 if( VOS_STATUS_SUCCESS == status )
1888 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301889 /* Now copy over all the security attributes you have
1890 * parsed out
Jeff Johnson295189b2012-06-20 16:38:30 -07001891 * */
1892 pConfig->RSNEncryptType = RSNEncryptType; // Use the cipher type in the RSN IE
1893 pConfig->mcRSNEncryptType = mcRSNEncryptType;
1894 (WLAN_HDD_GET_AP_CTX_PTR(pHostapdAdapter))->ucEncryptType
1895 = RSNEncryptType;
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +05301896 hddLog( LOG1, FL("CSR AuthType = %d, "
Jeff Johnson295189b2012-06-20 16:38:30 -07001897 "EncryptionType = %d mcEncryptionType = %d\n"),
1898 RSNAuthType, RSNEncryptType, mcRSNEncryptType);
1899 }
1900 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301901
Jeff Johnson295189b2012-06-20 16:38:30 -07001902 pIe = wlan_hdd_get_vendor_oui_ie_ptr(WPA_OUI_TYPE, WPA_OUI_TYPE_SIZE,
1903 pBeacon->tail, pBeacon->tail_len);
1904
1905 if(pIe && pIe[1] && (pIe[0] == DOT11F_EID_WPA))
1906 {
1907 if (pConfig->pRSNWPAReqIE)
1908 {
1909 /*Mixed mode WPA/WPA2*/
1910 memcpy((&wpaRsnIEdata[0] + pConfig->RSNWPAReqIELength), pIe, pIe[1] + 2);
1911 pConfig->RSNWPAReqIELength += pIe[1] + 2;
1912 }
1913 else
1914 {
1915 pConfig->RSNWPAReqIELength = pIe[1] + 2;
1916 memcpy(&wpaRsnIEdata[0], pIe, pConfig->RSNWPAReqIELength);
1917 pConfig->pRSNWPAReqIE = &wpaRsnIEdata[0];
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301918 status = hdd_softap_unpackIE(
Jeff Johnson295189b2012-06-20 16:38:30 -07001919 vos_get_context( VOS_MODULE_ID_SME, pVosContext),
1920 &RSNEncryptType,
1921 &mcRSNEncryptType,
1922 &RSNAuthType,
1923 pConfig->pRSNWPAReqIE[1]+2,
1924 pConfig->pRSNWPAReqIE );
1925
1926 if( VOS_STATUS_SUCCESS == status )
1927 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301928 /* Now copy over all the security attributes you have
1929 * parsed out
Jeff Johnson295189b2012-06-20 16:38:30 -07001930 * */
1931 pConfig->RSNEncryptType = RSNEncryptType; // Use the cipher type in the RSN IE
1932 pConfig->mcRSNEncryptType = mcRSNEncryptType;
1933 (WLAN_HDD_GET_AP_CTX_PTR(pHostapdAdapter))->ucEncryptType
1934 = RSNEncryptType;
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +05301935 hddLog( LOG1, FL("CSR AuthType = %d, "
Jeff Johnson295189b2012-06-20 16:38:30 -07001936 "EncryptionType = %d mcEncryptionType = %d\n"),
1937 RSNAuthType, RSNEncryptType, mcRSNEncryptType);
1938 }
1939 }
1940 }
1941
Jeff Johnson4416a782013-03-25 14:17:50 -07001942 if (pConfig->RSNWPAReqIELength > sizeof wpaRsnIEdata) {
1943 hddLog( VOS_TRACE_LEVEL_ERROR, "**RSNWPAReqIELength is too large***");
1944 return -EINVAL;
1945 }
1946
Jeff Johnson295189b2012-06-20 16:38:30 -07001947 pConfig->SSIDinfo.ssidHidden = VOS_FALSE;
1948
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001949#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07001950 if (params->ssid != NULL)
1951 {
1952 memcpy(pConfig->SSIDinfo.ssid.ssId, params->ssid, params->ssid_len);
1953 pConfig->SSIDinfo.ssid.length = params->ssid_len;
1954 if (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE)
1955 pConfig->SSIDinfo.ssidHidden = VOS_TRUE;
1956 }
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001957#else
1958 if (ssid != NULL)
1959 {
1960 memcpy(pConfig->SSIDinfo.ssid.ssId, ssid, ssid_len);
1961 pConfig->SSIDinfo.ssid.length = ssid_len;
1962 if (hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE)
1963 pConfig->SSIDinfo.ssidHidden = VOS_TRUE;
1964 }
1965#endif
1966
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301967 vos_mem_copy(pConfig->self_macaddr.bytes,
Jeff Johnson295189b2012-06-20 16:38:30 -07001968 pHostapdAdapter->macAddressCurrent.bytes, sizeof(v_MACADDR_t));
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301969
Jeff Johnson295189b2012-06-20 16:38:30 -07001970 /* default value */
1971 pConfig->SapMacaddr_acl = eSAP_ACCEPT_UNLESS_DENIED;
1972 pConfig->num_accept_mac = 0;
1973 pConfig->num_deny_mac = 0;
1974
1975 pIe = wlan_hdd_get_vendor_oui_ie_ptr(BLACKLIST_OUI_TYPE, WPA_OUI_TYPE_SIZE,
1976 pBeacon->tail, pBeacon->tail_len);
1977
1978 /* pIe for black list is following form:
1979 type : 1 byte
1980 length : 1 byte
1981 OUI : 4 bytes
1982 acl type : 1 byte
1983 no of mac addr in black list: 1 byte
1984 list of mac_acl_entries: variable, 6 bytes per mac address + sizeof(int) for vlan id
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301985 */
1986 if ((pIe != NULL) && (pIe[1] != 0))
Jeff Johnson295189b2012-06-20 16:38:30 -07001987 {
1988 pConfig->SapMacaddr_acl = pIe[6];
1989 pConfig->num_deny_mac = pIe[7];
1990 hddLog(VOS_TRACE_LEVEL_INFO,"acl type = %d no deny mac = %d\n",
1991 pIe[6], pIe[7]);
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05301992 if (pConfig->num_deny_mac > MAX_ACL_MAC_ADDRESS)
1993 pConfig->num_deny_mac = MAX_ACL_MAC_ADDRESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001994 acl_entry = (struct qc_mac_acl_entry *)(pIe + 8);
1995 for (i = 0; i < pConfig->num_deny_mac; i++)
1996 {
1997 vos_mem_copy(&pConfig->deny_mac[i], acl_entry->addr, sizeof(qcmacaddr));
1998 acl_entry++;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05301999 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002000 }
2001 pIe = wlan_hdd_get_vendor_oui_ie_ptr(WHITELIST_OUI_TYPE, WPA_OUI_TYPE_SIZE,
2002 pBeacon->tail, pBeacon->tail_len);
2003
2004 /* pIe for white list is following form:
2005 type : 1 byte
2006 length : 1 byte
2007 OUI : 4 bytes
2008 acl type : 1 byte
2009 no of mac addr in white list: 1 byte
2010 list of mac_acl_entries: variable, 6 bytes per mac address + sizeof(int) for vlan id
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302011 */
2012 if ((pIe != NULL) && (pIe[1] != 0))
Jeff Johnson295189b2012-06-20 16:38:30 -07002013 {
2014 pConfig->SapMacaddr_acl = pIe[6];
2015 pConfig->num_accept_mac = pIe[7];
2016 hddLog(VOS_TRACE_LEVEL_INFO,"acl type = %d no accept mac = %d\n",
2017 pIe[6], pIe[7]);
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05302018 if (pConfig->num_accept_mac > MAX_ACL_MAC_ADDRESS)
2019 pConfig->num_accept_mac = MAX_ACL_MAC_ADDRESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07002020 acl_entry = (struct qc_mac_acl_entry *)(pIe + 8);
2021 for (i = 0; i < pConfig->num_accept_mac; i++)
2022 {
2023 vos_mem_copy(&pConfig->accept_mac[i], acl_entry->addr, sizeof(qcmacaddr));
2024 acl_entry++;
2025 }
2026 }
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05302027
Jeff Johnson295189b2012-06-20 16:38:30 -07002028 wlan_hdd_set_sapHwmode(pHostapdAdapter);
2029
Jeff Johnsone7245742012-09-05 17:12:55 -07002030#ifdef WLAN_FEATURE_11AC
Ravi Kumar Vaishnavbbaebbe2013-01-15 17:09:48 -08002031 /* Overwrite the hostapd setting for HW mode only for 11ac.
2032 * This is valid only if mode is set to 11n in hostapd and either AUTO or 11ac in .ini .
2033 * Otherwise, leave whatever is set in hostapd (a OR b OR g OR n mode) */
2034 if( ((pConfig->SapHw_mode == eSAP_DOT11_MODE_11n) ||
2035 (pConfig->SapHw_mode == eSAP_DOT11_MODE_11n_ONLY)) &&
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302036 (((WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->dot11Mode == eHDD_DOT11_MODE_AUTO) ||
Ravi Kumar Vaishnavbbaebbe2013-01-15 17:09:48 -08002037 ((WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->dot11Mode == eHDD_DOT11_MODE_11ac) ||
2038 ((WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY)) )
Jeff Johnsone7245742012-09-05 17:12:55 -07002039 {
2040 pConfig->SapHw_mode = eSAP_DOT11_MODE_11ac;
Ravi Joshi83bfaa12013-05-28 22:12:08 -07002041
2042 /* Disable VHT support in 2.4 GHz band */
2043 if (pConfig->channel <= 14 &&
2044 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->enableVhtFor24GHzBand == FALSE)
2045 {
2046 pConfig->SapHw_mode = eSAP_DOT11_MODE_11n;
2047 }
Jeff Johnsone7245742012-09-05 17:12:55 -07002048 }
2049#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302050
Ravi Joshiaeb7d9e2013-05-02 12:28:14 -07002051 if ( AUTO_CHANNEL_SELECT != pConfig->channel )
2052 {
2053 sme_SelectCBMode(hHal,
2054 sapConvertSapPhyModeToCsrPhyMode(pConfig->SapHw_mode),
2055 pConfig->channel);
2056 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002057 // ht_capab is not what the name conveys,this is used for protection bitmap
2058 pConfig->ht_capab =
2059 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apProtection;
2060
2061 if ( 0 != wlan_hdd_cfg80211_update_apies(pHostapdAdapter, params) )
2062 {
2063 hddLog(LOGE, FL("SAP Not able to set AP IEs"));
2064 return -EINVAL;
2065 }
2066
2067 //Uapsd Enabled Bit
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302068 pConfig->UapsdEnable =
Jeff Johnson295189b2012-06-20 16:38:30 -07002069 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apUapsdEnabled;
2070 //Enable OBSS protection
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302071 pConfig->obssProtEnabled =
2072 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apOBSSProtEnabled;
Jeff Johnson295189b2012-06-20 16:38:30 -07002073
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302074 hddLog(LOGW, FL("SOftAP macaddress : "MAC_ADDRESS_STR"\n"),
Jeff Johnson295189b2012-06-20 16:38:30 -07002075 MAC_ADDR_ARRAY(pHostapdAdapter->macAddressCurrent.bytes));
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302076 hddLog(LOGW,FL("ssid =%s\n"), pConfig->SSIDinfo.ssid.ssId);
Jeff Johnson295189b2012-06-20 16:38:30 -07002077 hddLog(LOGW,FL("beaconint=%d, channel=%d\n"), (int)pConfig->beacon_int,
2078 (int)pConfig->channel);
2079 hddLog(LOGW,FL("hw_mode=%x\n"), pConfig->SapHw_mode);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302080 hddLog(LOGW,FL("privacy=%d, authType=%d\n"), pConfig->privacy,
2081 pConfig->authType);
Jeff Johnson295189b2012-06-20 16:38:30 -07002082 hddLog(LOGW,FL("RSN/WPALen=%d, \n"),(int)pConfig->RSNWPAReqIELength);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302083 hddLog(LOGW,FL("Uapsd = %d\n"),pConfig->UapsdEnable);
Jeff Johnson295189b2012-06-20 16:38:30 -07002084 hddLog(LOGW,FL("ProtEnabled = %d, OBSSProtEnabled = %d\n"),
2085 pConfig->protEnabled, pConfig->obssProtEnabled);
2086
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302087 if(test_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags))
Jeff Johnson295189b2012-06-20 16:38:30 -07002088 {
2089 //Bss already started. just return.
2090 //TODO Probably it should update some beacon params.
2091 hddLog( LOGE, "Bss Already started...Ignore the request");
2092 EXIT();
2093 return 0;
2094 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302095
Jeff Johnson295189b2012-06-20 16:38:30 -07002096 pConfig->persona = pHostapdAdapter->device_mode;
2097
2098 pSapEventCallback = hdd_hostapd_SAPEventCB;
2099 if(WLANSAP_StartBss(pVosContext, pSapEventCallback, pConfig,
2100 (v_PVOID_t)pHostapdAdapter->dev) != VOS_STATUS_SUCCESS)
2101 {
2102 hddLog(LOGE,FL("SAP Start Bss fail\n"));
2103 return -EINVAL;
2104 }
2105
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302106 hddLog(LOG1,
Jeff Johnson295189b2012-06-20 16:38:30 -07002107 FL("Waiting for Scan to complete(auto mode) and BSS to start"));
2108
2109 status = vos_wait_single_event(&pHostapdState->vosEvent, 10000);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302110
Jeff Johnson295189b2012-06-20 16:38:30 -07002111 if (!VOS_IS_STATUS_SUCCESS(status))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302112 {
2113 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07002114 ("ERROR: HDD vos wait for single_event failed!!\n"));
2115 VOS_ASSERT(0);
2116 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302117
Jeff Johnson295189b2012-06-20 16:38:30 -07002118 //Succesfully started Bss update the state bit.
2119 set_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags);
2120
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07002121#ifdef WLAN_FEATURE_P2P_DEBUG
2122 if (pHostapdAdapter->device_mode == WLAN_HDD_P2P_GO)
2123 {
2124 if(globalP2PConnectionStatus == P2P_GO_NEG_COMPLETED)
2125 {
2126 globalP2PConnectionStatus = P2P_GO_COMPLETED_STATE;
2127 hddLog(LOGE,"[P2P State] From Go nego completed to "
Jeff Johnson1250df42012-12-10 14:31:52 -08002128 "Non-autonomous Group started");
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07002129 }
2130 else if(globalP2PConnectionStatus == P2P_NOT_ACTIVE)
2131 {
2132 globalP2PConnectionStatus = P2P_GO_COMPLETED_STATE;
2133 hddLog(LOGE,"[P2P State] From Inactive to "
Jeff Johnson1250df42012-12-10 14:31:52 -08002134 "Autonomous Group started");
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07002135 }
2136 }
2137#endif
2138
Jeff Johnson295189b2012-06-20 16:38:30 -07002139 pHostapdState->bCommit = TRUE;
2140 EXIT();
2141
2142 return 0;
2143}
2144
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002145#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302146static int wlan_hdd_cfg80211_add_beacon(struct wiphy *wiphy,
2147 struct net_device *dev,
Jeff Johnson295189b2012-06-20 16:38:30 -07002148 struct beacon_parameters *params)
2149{
2150 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302151 hdd_context_t *pHddCtx;
2152 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07002153
2154 ENTER();
2155
2156 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "device mode=%d\n",pAdapter->device_mode);
2157
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302158 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2159 status = wlan_hdd_validate_context(pHddCtx);
2160
2161 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002162 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302163 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2164 "%s: HDD context is not valid", __func__);
2165 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002166 }
2167
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302168 if ( (pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002169 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -07002170 )
2171 {
2172 beacon_data_t *old,*new;
2173
2174 old = pAdapter->sessionCtx.ap.beacon;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302175
Jeff Johnson295189b2012-06-20 16:38:30 -07002176 if (old)
2177 return -EALREADY;
2178
2179 status = wlan_hdd_cfg80211_alloc_new_beacon(pAdapter,&new,params);
2180
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302181 if(status != VOS_STATUS_SUCCESS)
Jeff Johnson295189b2012-06-20 16:38:30 -07002182 {
2183 hddLog(VOS_TRACE_LEVEL_FATAL,
2184 "%s:Error!!! Allocating the new beacon\n",__func__);
2185 return -EINVAL;
2186 }
2187
2188 pAdapter->sessionCtx.ap.beacon = new;
2189
2190 status = wlan_hdd_cfg80211_start_bss(pAdapter, params);
2191 }
2192
2193 EXIT();
2194 return status;
2195}
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302196
2197static int wlan_hdd_cfg80211_set_beacon(struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07002198 struct net_device *dev,
2199 struct beacon_parameters *params)
2200{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302201 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302202 hdd_context_t *pHddCtx;
2203 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07002204
2205 ENTER();
2206
2207 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
2208 __func__,pAdapter->device_mode);
2209
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302210 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2211 status = wlan_hdd_validate_context(pHddCtx);
2212
2213 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002214 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302215 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2216 "%s: HDD context is not valid", __func__);
2217 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002218 }
2219
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302220 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002221 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302222 )
Jeff Johnson295189b2012-06-20 16:38:30 -07002223 {
2224 beacon_data_t *old,*new;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302225
Jeff Johnson295189b2012-06-20 16:38:30 -07002226 old = pAdapter->sessionCtx.ap.beacon;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302227
Jeff Johnson295189b2012-06-20 16:38:30 -07002228 if (!old)
2229 return -ENOENT;
2230
2231 status = wlan_hdd_cfg80211_alloc_new_beacon(pAdapter,&new,params);
2232
2233 if(status != VOS_STATUS_SUCCESS) {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302234 hddLog(VOS_TRACE_LEVEL_FATAL,
Jeff Johnson295189b2012-06-20 16:38:30 -07002235 "%s: Error!!! Allocating the new beacon\n",__func__);
2236 return -EINVAL;
2237 }
2238
2239 pAdapter->sessionCtx.ap.beacon = new;
2240
2241 status = wlan_hdd_cfg80211_start_bss(pAdapter, params);
2242 }
2243
2244 EXIT();
2245 return status;
2246}
2247
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002248#endif //(LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
2249
2250#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07002251static int wlan_hdd_cfg80211_del_beacon(struct wiphy *wiphy,
2252 struct net_device *dev)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002253#else
2254static int wlan_hdd_cfg80211_stop_ap (struct wiphy *wiphy,
2255 struct net_device *dev)
2256#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002257{
2258 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsone7245742012-09-05 17:12:55 -07002259 hdd_context_t *pHddCtx = NULL;
2260 hdd_scaninfo_t *pScanInfo = NULL;
2261 hdd_adapter_t *staAdapter = NULL;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302262 VOS_STATUS status;
Jeff Johnson295189b2012-06-20 16:38:30 -07002263
2264 ENTER();
2265
2266 if (NULL == pAdapter)
2267 {
2268 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002269 "%s: HDD adapter context is Null", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002270 return -ENODEV;
2271 }
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002272
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302273 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2274 status = wlan_hdd_validate_context(pHddCtx);
2275
2276 if (0 != status)
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002277 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302278 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2279 "%s: HDD context is not valid", __func__);
2280 return status;
Jeff Johnson4416a782013-03-25 14:17:50 -07002281 }
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002282
2283 staAdapter = hdd_get_adapter(pAdapter->pHddCtx, WLAN_HDD_INFRA_STATION);
2284 if (NULL == staAdapter)
2285 {
2286 staAdapter = hdd_get_adapter(pAdapter->pHddCtx, WLAN_HDD_P2P_CLIENT);
2287 if (NULL == staAdapter)
2288 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302289 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002290 "%s: HDD adapter context is Null", __func__);
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002291 return -ENODEV;
2292 }
2293 }
2294
2295 pScanInfo = &pHddCtx->scan_info;
2296
Jeff Johnson295189b2012-06-20 16:38:30 -07002297 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
2298 __func__,pAdapter->device_mode);
2299
Jeff Johnsone7245742012-09-05 17:12:55 -07002300 if ((pScanInfo != NULL) && pScanInfo->mScanPending)
2301 {
Madan Mohan Koyyalamudif4e81002012-11-13 10:46:38 -08002302 INIT_COMPLETION(pScanInfo->abortscan_event_var);
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05302303 hdd_abort_mac_scan(staAdapter->pHddCtx, pAdapter->sessionId);
Jeff Johnsone7245742012-09-05 17:12:55 -07002304 status = wait_for_completion_interruptible_timeout(
Madan Mohan Koyyalamudif4e81002012-11-13 10:46:38 -08002305 &pScanInfo->abortscan_event_var,
Jeff Johnsone7245742012-09-05 17:12:55 -07002306 msecs_to_jiffies(WLAN_WAIT_TIME_ABORTSCAN));
2307 if (!status)
2308 {
2309 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Jeff Johnson902c9832012-12-10 14:28:09 -08002310 "%s: Timeout occurred while waiting for abortscan" ,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002311 __func__);
Jeff Johnsone7245742012-09-05 17:12:55 -07002312 VOS_ASSERT(pScanInfo->mScanPending);
2313 return 0;
2314 }
2315 }
2316
Jeff Johnson295189b2012-06-20 16:38:30 -07002317 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002318 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -07002319 )
2320 {
2321 beacon_data_t *old;
2322
2323 old = pAdapter->sessionCtx.ap.beacon;
2324
2325 if (!old)
2326 return -ENOENT;
2327
Jeff Johnson295189b2012-06-20 16:38:30 -07002328 hdd_cleanup_actionframe(pHddCtx, pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07002329
2330 mutex_lock(&pHddCtx->sap_lock);
2331 if(test_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags))
2332 {
Jeff Johnson4416a782013-03-25 14:17:50 -07002333 if ( VOS_STATUS_SUCCESS == (status = WLANSAP_StopBss(pHddCtx->pvosContext) ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07002334 {
2335 hdd_hostapd_state_t *pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
2336
2337 status = vos_wait_single_event(&pHostapdState->vosEvent, 10000);
2338
2339 if (!VOS_IS_STATUS_SUCCESS(status))
2340 {
2341 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2342 ("ERROR: HDD vos wait for single_event failed!!\n"));
2343 VOS_ASSERT(0);
2344 }
2345 }
2346 clear_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags);
2347 }
2348 mutex_unlock(&pHddCtx->sap_lock);
2349
2350 if(status != VOS_STATUS_SUCCESS)
2351 {
2352 hddLog(VOS_TRACE_LEVEL_FATAL,
2353 "%s:Error!!! Stopping the BSS\n",__func__);
2354 return -EINVAL;
2355 }
2356
Jeff Johnson4416a782013-03-25 14:17:50 -07002357 if (ccmCfgSetInt(pHddCtx->hHal,
Jeff Johnson295189b2012-06-20 16:38:30 -07002358 WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG, 0,NULL, eANI_BOOLEAN_FALSE)
2359 ==eHAL_STATUS_FAILURE)
2360 {
2361 hddLog(LOGE,
2362 "Could not pass on WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG to CCM\n");
2363 }
2364
Jeff Johnson4416a782013-03-25 14:17:50 -07002365 if ( eHAL_STATUS_FAILURE == ccmCfgSetInt(pHddCtx->hHal,
Jeff Johnson295189b2012-06-20 16:38:30 -07002366 WNI_CFG_ASSOC_RSP_ADDNIE_FLAG, 0, NULL,
2367 eANI_BOOLEAN_FALSE) )
2368 {
2369 hddLog(LOGE,
2370 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_FLAG to CCM\n");
2371 }
2372
2373 // Reset WNI_CFG_PROBE_RSP Flags
2374 wlan_hdd_reset_prob_rspies(pAdapter);
2375
2376 pAdapter->sessionCtx.ap.beacon = NULL;
2377 kfree(old);
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07002378#ifdef WLAN_FEATURE_P2P_DEBUG
2379 if((pAdapter->device_mode == WLAN_HDD_P2P_GO) &&
2380 (globalP2PConnectionStatus == P2P_GO_COMPLETED_STATE))
2381 {
2382 hddLog(LOGE,"[P2P State] From GO completed to Inactive state "
2383 "GO got removed");
2384 globalP2PConnectionStatus = P2P_NOT_ACTIVE;
2385 }
2386#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002387 }
2388 EXIT();
2389 return status;
2390}
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002391
2392#if (LINUX_VERSION_CODE > KERNEL_VERSION(3,3,0))
2393
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302394static int wlan_hdd_cfg80211_start_ap(struct wiphy *wiphy,
2395 struct net_device *dev,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002396 struct cfg80211_ap_settings *params)
2397{
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302398 hdd_adapter_t *pAdapter;
2399 hdd_context_t *pHddCtx;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302400 int status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002401
2402 ENTER();
2403
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302404 if (NULL == dev)
Madan Mohan Koyyalamudib2c36892012-10-18 20:52:38 -07002405 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302406 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302407 "%s: Device is Null", __func__);
2408 return -ENODEV;
2409 }
2410
2411 pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
2412 if (NULL == pAdapter)
2413 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302414 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302415 "%s: HDD adapter is Null", __func__);
2416 return -ENODEV;
2417 }
2418
2419 if (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic)
2420 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302421 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302422 "%s: HDD adapter magic is invalid", __func__);
2423 return -ENODEV;
2424 }
2425
2426 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302427 status = wlan_hdd_validate_context(pHddCtx);
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302428
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302429 if (0 != status)
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302430 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302431 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2432 "%s: HDD context is not valid", __func__);
2433 return status;
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302434 }
2435
2436 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: device mode = %d",
2437 __func__, pAdapter->device_mode);
2438
2439 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002440 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002441 )
2442 {
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302443 beacon_data_t *old, *new;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002444
2445 old = pAdapter->sessionCtx.ap.beacon;
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302446
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002447 if (old)
2448 return -EALREADY;
2449
2450 status = wlan_hdd_cfg80211_alloc_new_beacon(pAdapter, &new, &params->beacon, params->dtim_period);
2451
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302452 if (status != 0)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002453 {
2454 hddLog(VOS_TRACE_LEVEL_FATAL,
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302455 "%s:Error!!! Allocating the new beacon", __func__);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002456 return -EINVAL;
2457 }
2458 pAdapter->sessionCtx.ap.beacon = new;
Viral Modi3a32cc52013-02-08 11:14:52 -08002459#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
Yue Maf49ba872013-08-19 12:04:25 -07002460 wlan_hdd_cfg80211_set_channel(wiphy, dev,
2461#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0))
2462 params->channel, params->channel_type);
2463#else
2464 params->chandef.chan, cfg80211_get_chandef_type(&(params->chandef)));
2465#endif
Viral Modi3a32cc52013-02-08 11:14:52 -08002466#endif
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002467 status = wlan_hdd_cfg80211_start_bss(pAdapter, &params->beacon, params->ssid,
2468 params->ssid_len, params->hidden_ssid);
2469 }
2470
2471 EXIT();
2472 return status;
2473}
2474
2475
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302476static int wlan_hdd_cfg80211_change_beacon(struct wiphy *wiphy,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002477 struct net_device *dev,
2478 struct cfg80211_beacon_data *params)
2479{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302480 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302481 hdd_context_t *pHddCtx;
2482 int status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002483
2484 ENTER();
2485
2486 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
2487 __func__, pAdapter->device_mode);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302488
2489 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2490 status = wlan_hdd_validate_context(pHddCtx);
2491
2492 if (0 != status)
Madan Mohan Koyyalamudib2c36892012-10-18 20:52:38 -07002493 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302494 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2495 "%s: HDD context is not valid", __func__);
2496 return status;
Madan Mohan Koyyalamudib2c36892012-10-18 20:52:38 -07002497 }
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002498
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302499 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002500 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302501 )
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002502 {
2503 beacon_data_t *old,*new;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302504
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002505 old = pAdapter->sessionCtx.ap.beacon;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302506
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002507 if (!old)
2508 return -ENOENT;
2509
2510 status = wlan_hdd_cfg80211_alloc_new_beacon(pAdapter, &new, params, 0);
2511
2512 if(status != VOS_STATUS_SUCCESS) {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302513 hddLog(VOS_TRACE_LEVEL_FATAL,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002514 "%s: Error!!! Allocating the new beacon\n",__func__);
2515 return -EINVAL;
2516 }
2517
2518 pAdapter->sessionCtx.ap.beacon = new;
2519
2520 status = wlan_hdd_cfg80211_start_bss(pAdapter, params, NULL, 0, 0);
2521 }
2522
2523 EXIT();
2524 return status;
2525}
2526
2527#endif //(LINUX_VERSION_CODE > KERNEL_VERSION(3,3,0))
2528
Jeff Johnson295189b2012-06-20 16:38:30 -07002529
2530static int wlan_hdd_cfg80211_change_bss (struct wiphy *wiphy,
2531 struct net_device *dev,
2532 struct bss_parameters *params)
2533{
2534 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
2535
2536 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302537
Jeff Johnson295189b2012-06-20 16:38:30 -07002538 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
2539 __func__,pAdapter->device_mode);
2540
2541 if((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002542 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302543 )
Jeff Johnson295189b2012-06-20 16:38:30 -07002544 {
2545 /* ap_isolate == -1 means that in change bss, upper layer doesn't
2546 * want to update this parameter */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302547 if (-1 != params->ap_isolate)
Jeff Johnson295189b2012-06-20 16:38:30 -07002548 {
2549 pAdapter->sessionCtx.ap.apDisableIntraBssFwd = !!params->ap_isolate;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302550 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002551 }
2552
2553 EXIT();
2554 return 0;
2555}
2556
2557/*
2558 * FUNCTION: wlan_hdd_cfg80211_change_iface
2559 * This function is used to set the interface type (INFRASTRUCTURE/ADHOC)
2560 */
2561int wlan_hdd_cfg80211_change_iface( struct wiphy *wiphy,
2562 struct net_device *ndev,
2563 enum nl80211_iftype type,
2564 u32 *flags,
2565 struct vif_params *params
2566 )
2567{
2568 struct wireless_dev *wdev;
2569 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
2570 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
Mohit Khanna0f232092012-09-11 14:46:08 -07002571 hdd_adapter_t *pP2pAdapter = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07002572 tCsrRoamProfile *pRoamProfile = NULL;
2573 eCsrRoamBssType LastBSSType;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302574 hdd_config_t *pConfig = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07002575 eMib_dot11DesiredBssType connectedBssType;
2576 VOS_STATUS status;
2577
2578 ENTER();
2579
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302580 status = wlan_hdd_validate_context(pHddCtx);
2581
2582 if (0 != status)
Jeff Johnson295189b2012-06-20 16:38:30 -07002583 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302584 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2585 "%s: HDD context is not valid", __func__);
2586 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07002587 }
2588
2589 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
2590 __func__, pAdapter->device_mode);
2591
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05302592 pConfig = pHddCtx->cfg_ini;
Jeff Johnson295189b2012-06-20 16:38:30 -07002593 wdev = ndev->ieee80211_ptr;
2594
2595#ifdef WLAN_BTAMP_FEATURE
2596 if((NL80211_IFTYPE_P2P_CLIENT == type)||
2597 (NL80211_IFTYPE_ADHOC == type)||
2598 (NL80211_IFTYPE_AP == type)||
2599 (NL80211_IFTYPE_P2P_GO == type))
2600 {
2601 pHddCtx->isAmpAllowed = VOS_FALSE;
2602 // stop AMP traffic
2603 status = WLANBAP_StopAmp();
2604 if(VOS_STATUS_SUCCESS != status )
2605 {
2606 pHddCtx->isAmpAllowed = VOS_TRUE;
2607 hddLog(VOS_TRACE_LEVEL_FATAL,
2608 "%s: Failed to stop AMP", __func__);
2609 return -EINVAL;
2610 }
2611 }
2612#endif //WLAN_BTAMP_FEATURE
2613 /* Reset the current device mode bit mask*/
2614 wlan_hdd_clear_concurrency_mode(pHddCtx, pAdapter->device_mode);
2615
2616 if( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Jeff Johnson295189b2012-06-20 16:38:30 -07002617 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Jeff Johnsone7245742012-09-05 17:12:55 -07002618 || (pAdapter->device_mode == WLAN_HDD_P2P_DEVICE)
Jeff Johnson295189b2012-06-20 16:38:30 -07002619 )
2620 {
2621 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
2622 pRoamProfile = &pWextState->roamProfile;
2623 LastBSSType = pRoamProfile->BSSType;
2624
2625 switch (type)
2626 {
2627 case NL80211_IFTYPE_STATION:
Jeff Johnson295189b2012-06-20 16:38:30 -07002628 case NL80211_IFTYPE_P2P_CLIENT:
Jeff Johnson295189b2012-06-20 16:38:30 -07002629 hddLog(VOS_TRACE_LEVEL_INFO,
2630 "%s: setting interface Type to INFRASTRUCTURE", __func__);
2631 pRoamProfile->BSSType = eCSR_BSS_TYPE_INFRASTRUCTURE;
Jeff Johnsone7245742012-09-05 17:12:55 -07002632#ifdef WLAN_FEATURE_11AC
2633 if(pConfig->dot11Mode == eHDD_DOT11_MODE_AUTO)
2634 {
2635 pConfig->dot11Mode = eHDD_DOT11_MODE_11ac;
2636 }
2637#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302638 pRoamProfile->phyMode =
Jeff Johnsone7245742012-09-05 17:12:55 -07002639 hdd_cfg_xlate_to_csr_phy_mode(pConfig->dot11Mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07002640 wdev->iftype = type;
Gopichand Nakkalaf527dc62012-12-31 16:35:10 -08002641 //Check for sub-string p2p to confirm its a p2p interface
2642 if (NULL != strstr(ndev->name,"p2p"))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302643 {
Gopichand Nakkala864d3552012-12-31 16:08:51 -08002644 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
2645 WLAN_HDD_P2P_DEVICE : WLAN_HDD_P2P_CLIENT;
2646 }
2647 else
2648 {
2649 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
Jeff Johnson295189b2012-06-20 16:38:30 -07002650 WLAN_HDD_INFRA_STATION: WLAN_HDD_P2P_CLIENT;
Gopichand Nakkala864d3552012-12-31 16:08:51 -08002651 }
Madan Mohan Koyyalamudi81746922013-07-17 14:38:51 +05302652#ifdef FEATURE_WLAN_TDLS
2653 /* The open adapter for the p2p shall skip initializations in
2654 * tdls_init if the device mode is WLAN_HDD_P2P_DEVICE, for
2655 * TDLS is supported only on WLAN_HDD_P2P_CLIENT. Hence invoke
2656 * tdls_init when the change_iface sets the device mode to
2657 * WLAN_HDD_P2P_CLIENT.
2658 */
2659
2660 if ( pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
2661 {
2662 if (0 != wlan_hdd_tdls_init (pAdapter))
2663 {
2664 return -EINVAL;
2665 }
2666 }
2667#endif
2668
Jeff Johnson295189b2012-06-20 16:38:30 -07002669 break;
2670 case NL80211_IFTYPE_ADHOC:
2671 hddLog(VOS_TRACE_LEVEL_INFO,
2672 "%s: setting interface Type to ADHOC", __func__);
2673 pRoamProfile->BSSType = eCSR_BSS_TYPE_START_IBSS;
2674 pRoamProfile->phyMode =
2675 hdd_cfg_xlate_to_csr_phy_mode(pConfig->dot11Mode);
Shailender Karmuchia734f332013-04-19 14:02:48 -07002676 pAdapter->device_mode = WLAN_HDD_IBSS;
Jeff Johnson295189b2012-06-20 16:38:30 -07002677 wdev->iftype = type;
2678 break;
2679
2680 case NL80211_IFTYPE_AP:
Jeff Johnson295189b2012-06-20 16:38:30 -07002681 case NL80211_IFTYPE_P2P_GO:
Jeff Johnson295189b2012-06-20 16:38:30 -07002682 {
2683 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
2684 "%s: setting interface Type to %s", __func__,
2685 (type == NL80211_IFTYPE_AP) ? "SoftAP" : "P2pGo");
2686
Gopichand Nakkalaf527dc62012-12-31 16:35:10 -08002687 //Cancel any remain on channel for GO mode
2688 if (NL80211_IFTYPE_P2P_GO == type)
2689 {
2690 wlan_hdd_cancel_existing_remain_on_channel(pAdapter);
2691 }
Mohit Khanna0f232092012-09-11 14:46:08 -07002692 if (NL80211_IFTYPE_AP == type)
2693 {
2694 /* As Loading WLAN Driver one interface being created for p2p device
2695 * address. This will take one HW STA and the max number of clients
2696 * that can connect to softAP will be reduced by one. so while changing
2697 * the interface type to NL80211_IFTYPE_AP (SoftAP) remove p2p0
2698 * interface as it is not required in SoftAP mode.
2699 */
2700
2701 // Get P2P Adapter
2702 pP2pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_P2P_DEVICE);
2703
2704 if (pP2pAdapter)
2705 {
2706 hdd_stop_adapter(pHddCtx, pP2pAdapter);
2707 hdd_deinit_adapter(pHddCtx, pP2pAdapter);
2708 hdd_close_adapter(pHddCtx, pP2pAdapter, VOS_TRUE);
2709 }
2710 }
2711
Jeff Johnson295189b2012-06-20 16:38:30 -07002712 //De-init the adapter.
2713 hdd_stop_adapter( pHddCtx, pAdapter );
2714 hdd_deinit_adapter( pHddCtx, pAdapter );
2715 memset(&pAdapter->sessionCtx, 0, sizeof(pAdapter->sessionCtx));
Jeff Johnson295189b2012-06-20 16:38:30 -07002716 pAdapter->device_mode = (type == NL80211_IFTYPE_AP) ?
2717 WLAN_HDD_SOFTAP : WLAN_HDD_P2P_GO;
Jeff Johnson32d95a32012-09-10 13:15:23 -07002718
2719 //Disable BMPS and IMPS if enabled
2720 //before starting Go
2721 if(WLAN_HDD_P2P_GO == pAdapter->device_mode)
2722 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302723 if(VOS_STATUS_E_FAILURE ==
Jeff Johnson32d95a32012-09-10 13:15:23 -07002724 hdd_disable_bmps_imps(pHddCtx, WLAN_HDD_P2P_GO))
2725 {
2726 //Fail to Exit BMPS
2727 VOS_ASSERT(0);
2728 }
2729 }
2730
Madan Mohan Koyyalamudi3ff2a0b2012-10-15 14:33:46 -07002731 if ((WLAN_HDD_SOFTAP == pAdapter->device_mode) &&
2732 (pConfig->apRandomBssidEnabled))
2733 {
2734 /* To meet Android requirements create a randomized
2735 MAC address of the form 02:1A:11:Fx:xx:xx */
2736 get_random_bytes(&ndev->dev_addr[3], 3);
2737 ndev->dev_addr[0] = 0x02;
2738 ndev->dev_addr[1] = 0x1A;
2739 ndev->dev_addr[2] = 0x11;
2740 ndev->dev_addr[3] |= 0xF0;
2741 memcpy(pAdapter->macAddressCurrent.bytes, ndev->dev_addr,
2742 VOS_MAC_ADDR_SIZE);
2743 pr_info("wlan: Generated HotSpot BSSID "
2744 "%02x:%02x:%02x:%02x:%02x:%02x\n",
2745 ndev->dev_addr[0],
2746 ndev->dev_addr[1],
2747 ndev->dev_addr[2],
2748 ndev->dev_addr[3],
2749 ndev->dev_addr[4],
2750 ndev->dev_addr[5]);
2751 }
2752
Jeff Johnson295189b2012-06-20 16:38:30 -07002753 hdd_set_ap_ops( pAdapter->dev );
2754
2755 status = hdd_init_ap_mode(pAdapter);
2756 if(status != VOS_STATUS_SUCCESS)
2757 {
2758 hddLog(VOS_TRACE_LEVEL_FATAL,
2759 "%s: Error initializing the ap mode", __func__);
2760 return -EINVAL;
2761 }
2762 hdd_set_conparam(1);
2763
Jeff Johnson295189b2012-06-20 16:38:30 -07002764 /*interface type changed update in wiphy structure*/
2765 if(wdev)
2766 {
2767 wdev->iftype = type;
2768 pHddCtx->change_iface = type;
2769 }
2770 else
2771 {
2772 hddLog(VOS_TRACE_LEVEL_ERROR,
2773 "%s: ERROR !!!! Wireless dev is NULL", __func__);
2774 return -EINVAL;
2775 }
2776 goto done;
2777 }
2778
2779 default:
2780 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported interface Type",
2781 __func__);
2782 return -EOPNOTSUPP;
2783 }
2784 }
2785 else if ( (pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002786 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -07002787 )
2788 {
2789 switch(type)
2790 {
2791 case NL80211_IFTYPE_STATION:
Jeff Johnson295189b2012-06-20 16:38:30 -07002792 case NL80211_IFTYPE_P2P_CLIENT:
Jeff Johnson295189b2012-06-20 16:38:30 -07002793 case NL80211_IFTYPE_ADHOC:
Jeff Johnson32d95a32012-09-10 13:15:23 -07002794 hdd_stop_adapter( pHddCtx, pAdapter );
2795 hdd_deinit_adapter( pHddCtx, pAdapter );
Jeff Johnson295189b2012-06-20 16:38:30 -07002796 wdev->iftype = type;
Gopichand Nakkalaf527dc62012-12-31 16:35:10 -08002797 //Check for sub-string p2p to confirm its a p2p interface
2798 if (NULL != strstr(ndev->name,"p2p"))
Gopichand Nakkala864d3552012-12-31 16:08:51 -08002799 {
2800 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
2801 WLAN_HDD_P2P_DEVICE : WLAN_HDD_P2P_CLIENT;
2802 }
2803 else
2804 {
2805 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
Jeff Johnson295189b2012-06-20 16:38:30 -07002806 WLAN_HDD_INFRA_STATION: WLAN_HDD_P2P_CLIENT;
Gopichand Nakkala864d3552012-12-31 16:08:51 -08002807 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002808 hdd_set_conparam(0);
2809 pHddCtx->change_iface = type;
Jeff Johnson295189b2012-06-20 16:38:30 -07002810 memset(&pAdapter->sessionCtx, 0, sizeof(pAdapter->sessionCtx));
2811 hdd_set_station_ops( pAdapter->dev );
2812 status = hdd_init_station_mode( pAdapter );
2813 if( VOS_STATUS_SUCCESS != status )
2814 return -EOPNOTSUPP;
Jeff Johnsone7245742012-09-05 17:12:55 -07002815 /* In case of JB, for P2P-GO, only change interface will be called,
2816 * This is the right place to enable back bmps_imps()
2817 */
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05302818 if (pHddCtx->hdd_wlan_suspended)
2819 {
2820 hdd_set_pwrparams(pHddCtx);
2821 }
Jeff Johnsone7245742012-09-05 17:12:55 -07002822 hdd_enable_bmps_imps(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07002823 goto done;
2824 case NL80211_IFTYPE_AP:
Jeff Johnson295189b2012-06-20 16:38:30 -07002825 case NL80211_IFTYPE_P2P_GO:
Jeff Johnson295189b2012-06-20 16:38:30 -07002826 wdev->iftype = type;
Jeff Johnson295189b2012-06-20 16:38:30 -07002827 pAdapter->device_mode = (type == NL80211_IFTYPE_AP) ?
2828 WLAN_HDD_SOFTAP : WLAN_HDD_P2P_GO;
Jeff Johnson295189b2012-06-20 16:38:30 -07002829 goto done;
2830 default:
2831 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported interface Type",
2832 __func__);
2833 return -EOPNOTSUPP;
2834
2835 }
2836
2837 }
2838 else
2839 {
2840 return -EOPNOTSUPP;
2841 }
2842
2843
2844 if(pRoamProfile)
2845 {
2846 if ( LastBSSType != pRoamProfile->BSSType )
2847 {
2848 /*interface type changed update in wiphy structure*/
2849 wdev->iftype = type;
2850
2851 /*the BSS mode changed, We need to issue disconnect
2852 if connected or in IBSS disconnect state*/
2853 if ( hdd_connGetConnectedBssType(
2854 WLAN_HDD_GET_STATION_CTX_PTR(pAdapter), &connectedBssType ) ||
2855 ( eCSR_BSS_TYPE_START_IBSS == LastBSSType ) )
2856 {
2857 /*need to issue a disconnect to CSR.*/
2858 INIT_COMPLETION(pAdapter->disconnect_comp_var);
2859 if( eHAL_STATUS_SUCCESS ==
2860 sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
2861 pAdapter->sessionId,
2862 eCSR_DISCONNECT_REASON_UNSPECIFIED ) )
2863 {
2864 wait_for_completion_interruptible_timeout(
2865 &pAdapter->disconnect_comp_var,
2866 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
2867 }
2868 }
2869 }
2870 }
2871
2872done:
2873 /*set bitmask based on updated value*/
2874 wlan_hdd_set_concurrency_mode(pHddCtx, pAdapter->device_mode);
Leo Chang6fe1f922013-06-07 19:21:24 -07002875
2876 /* Only STA mode support TM now
2877 * all other mode, TM feature should be disabled */
2878 if ( (pHddCtx->cfg_ini->thermalMitigationEnable) &&
2879 (~VOS_STA & pHddCtx->concurrency_mode) )
2880 {
2881 hddDevTmLevelChangedHandler(pHddCtx->parent_dev, 0);
2882 }
2883
Jeff Johnson295189b2012-06-20 16:38:30 -07002884#ifdef WLAN_BTAMP_FEATURE
Gopichand Nakkala747461f2013-04-24 19:24:45 +05302885 if((NL80211_IFTYPE_STATION == type) && (pHddCtx->concurrency_mode <= 1) &&
Jeff Johnson295189b2012-06-20 16:38:30 -07002886 (pHddCtx->no_of_sessions[WLAN_HDD_INFRA_STATION] <=1))
2887 {
2888 //we are ok to do AMP
2889 pHddCtx->isAmpAllowed = VOS_TRUE;
2890 }
2891#endif //WLAN_BTAMP_FEATURE
2892 EXIT();
2893 return 0;
2894}
2895
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002896#ifdef FEATURE_WLAN_TDLS
2897static int wlan_hdd_tdls_add_station(struct wiphy *wiphy,
2898 struct net_device *dev, u8 *mac, bool update, tCsrStaParams *StaParams)
2899{
2900 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
2901 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
2902 VOS_STATUS status;
Hoonki Lee5305c3a2013-04-29 23:28:59 -07002903 hddTdlsPeer_t *pTdlsPeer;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002904
2905 ENTER();
2906
Gopichand Nakkala838be5d2013-04-10 22:41:51 +05302907 if (NULL == pHddCtx || NULL == pHddCtx->cfg_ini)
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002908 {
2909 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2910 "Invalid arguments");
2911 return -EINVAL;
2912 }
Hoonki Lee27511902013-03-14 18:19:06 -07002913
2914 if ((eTDLS_SUPPORT_NOT_ENABLED == pHddCtx->tdls_mode) ||
2915 (eTDLS_SUPPORT_DISABLED == pHddCtx->tdls_mode))
2916 {
2917 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
2918 "%s: TDLS mode is disabled OR not enabled in FW."
2919 MAC_ADDRESS_STR " Request declined.",
2920 __func__, MAC_ADDR_ARRAY(mac));
2921 return -ENOTSUPP;
2922 }
2923
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002924 if (pHddCtx->isLogpInProgress)
2925 {
2926 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2927 "%s:LOGP in Progress. Ignore!!!", __func__);
Gopichand Nakkala05922802013-03-14 12:23:19 -07002928 wlan_hdd_tdls_set_link_status(pAdapter, mac, eTDLS_LINK_IDLE);
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002929 return -EBUSY;
2930 }
2931
Hoonki Lee5305c3a2013-04-29 23:28:59 -07002932 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, mac);
2933
2934 if ( NULL == pTdlsPeer ) {
2935 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
2936 "%s: " MAC_ADDRESS_STR " (update %d) not exist. return invalid",
2937 __func__, MAC_ADDR_ARRAY(mac), update);
2938 return -EINVAL;
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002939 }
Hoonki Lee5305c3a2013-04-29 23:28:59 -07002940
2941 /* in add station, we accept existing valid staId if there is */
2942 if ((0 == update) &&
2943 ((pTdlsPeer->link_status >= eTDLS_LINK_CONNECTING) ||
2944 (TDLS_STA_INDEX_VALID(pTdlsPeer->staId))))
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07002945 {
Hoonki Lee5305c3a2013-04-29 23:28:59 -07002946 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07002947 "%s: " MAC_ADDRESS_STR
Hoonki Lee5305c3a2013-04-29 23:28:59 -07002948 " link_status %d. staId %d. add station ignored.",
2949 __func__, MAC_ADDR_ARRAY(mac), pTdlsPeer->link_status, pTdlsPeer->staId);
2950 return 0;
2951 }
2952 /* in change station, we accept only when staId is valid */
2953 if ((1 == update) &&
2954 ((pTdlsPeer->link_status > eTDLS_LINK_CONNECTING) ||
2955 (!TDLS_STA_INDEX_VALID(pTdlsPeer->staId))))
2956 {
2957 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
2958 "%s: " MAC_ADDRESS_STR
2959 " link status %d. staId %d. change station %s.",
2960 __func__, MAC_ADDR_ARRAY(mac), pTdlsPeer->link_status, pTdlsPeer->staId,
2961 (TDLS_STA_INDEX_VALID(pTdlsPeer->staId)) ? "ignored" : "declined");
2962 return (TDLS_STA_INDEX_VALID(pTdlsPeer->staId)) ? 0 : -EPERM;
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07002963 }
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002964
2965 /* when others are on-going, we want to change link_status to idle */
Hoonki Leefb8df672013-04-10 18:20:34 -07002966 if (NULL != wlan_hdd_tdls_is_progress(pHddCtx, mac, TRUE, TRUE))
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002967 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07002968 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2969 "%s: " MAC_ADDRESS_STR
2970 " TDLS setup is ongoing. Request declined.",
2971 __func__, MAC_ADDR_ARRAY(mac));
Gopichand Nakkala05922802013-03-14 12:23:19 -07002972 goto error;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002973 }
2974
2975 /* first to check if we reached to maximum supported TDLS peer.
2976 TODO: for now, return -EPERM looks working fine,
2977 but need to check if any other errno fit into this category.*/
2978 if (HDD_MAX_NUM_TDLS_STA <= wlan_hdd_tdlsConnectedPeers(pAdapter))
2979 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07002980 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2981 "%s: " MAC_ADDRESS_STR
2982 " TDLS Max peer already connected. Request declined.",
2983 __func__, MAC_ADDR_ARRAY(mac));
Gopichand Nakkala05922802013-03-14 12:23:19 -07002984 goto error;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002985 }
2986 else
2987 {
2988 hddTdlsPeer_t *pTdlsPeer;
2989 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, mac);
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07002990 if (pTdlsPeer && TDLS_IS_CONNECTED(pTdlsPeer))
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002991 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07002992 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2993 "%s: " MAC_ADDRESS_STR " already connected. Request declined.",
2994 __func__, MAC_ADDR_ARRAY(mac));
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002995 return -EPERM;
2996 }
2997 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07002998 if (0 == update)
2999 wlan_hdd_tdls_set_link_status(pAdapter, mac, eTDLS_LINK_CONNECTING);
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003000
Jeff Johnsond75fe012013-04-06 10:53:06 -07003001 /* debug code */
Gopichand Nakkala838be5d2013-04-10 22:41:51 +05303002 if (NULL != StaParams)
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003003 {
3004 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3005 "%s: TDLS Peer Parameters.", __func__);
Hoonki Lee66b75f32013-04-16 18:30:07 -07003006 if(StaParams->htcap_present)
3007 {
3008 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3009 "ht_capa->cap_info: %0x", StaParams->HTCap.capInfo);
3010 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3011 "ht_capa->extended_capabilities: %0x",
3012 StaParams->HTCap.extendedHtCapInfo);
3013 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003014 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3015 "params->capability: %0x",StaParams->capability);
3016 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3017 "params->ext_capab_len: %0x",StaParams->extn_capability);
Hoonki Lee66b75f32013-04-16 18:30:07 -07003018 if(StaParams->vhtcap_present)
3019 {
3020 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3021 "rxMcsMap %x rxHighest %x txMcsMap %x txHighest %x",
3022 StaParams->VHTCap.suppMcs.rxMcsMap, StaParams->VHTCap.suppMcs.rxHighest,
3023 StaParams->VHTCap.suppMcs.txMcsMap, StaParams->VHTCap.suppMcs.txHighest);
3024 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003025 {
3026 int i = 0;
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003027 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "Supported rates:");
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003028 for (i = 0; i < sizeof(StaParams->supported_rates); i++)
3029 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3030 "[%d]: %x ", i, StaParams->supported_rates[i]);
3031 }
Jeff Johnsond75fe012013-04-06 10:53:06 -07003032 } /* end debug code */
Gopichand Nakkala838be5d2013-04-10 22:41:51 +05303033 else if ((1 == update) && (NULL == StaParams))
3034 {
3035 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3036 "%s : update is true, but staParams is NULL. Error!", __func__);
3037 return -EPERM;
3038 }
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003039
3040 INIT_COMPLETION(pAdapter->tdls_add_station_comp);
3041
3042 if (!update)
3043 {
3044 status = sme_AddTdlsPeerSta(WLAN_HDD_GET_HAL_CTX(pAdapter),
3045 pAdapter->sessionId, mac);
3046 }
3047 else
3048 {
3049 status = sme_ChangeTdlsPeerSta(WLAN_HDD_GET_HAL_CTX(pAdapter),
3050 pAdapter->sessionId, mac, StaParams);
3051 }
3052
3053 status = wait_for_completion_interruptible_timeout(&pAdapter->tdls_add_station_comp,
3054 msecs_to_jiffies(WAIT_TIME_TDLS_ADD_STA));
3055
3056 if (!status)
3057 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07003058 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003059 "%s: timeout waiting for tdls add station indication",
3060 __func__);
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07003061 return -EPERM;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003062 }
3063 if ( eHAL_STATUS_SUCCESS != pAdapter->tdlsAddStaStatus)
3064 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07003065 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003066 "%s: Add Station is unsucessful", __func__);
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07003067 return -EPERM;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003068 }
3069
3070 return 0;
Gopichand Nakkala05922802013-03-14 12:23:19 -07003071
3072error:
3073 wlan_hdd_tdls_set_link_status(pAdapter, mac, eTDLS_LINK_IDLE);
3074 return -EPERM;
3075
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003076}
3077#endif
3078
Jeff Johnson295189b2012-06-20 16:38:30 -07003079static int wlan_hdd_change_station(struct wiphy *wiphy,
3080 struct net_device *dev,
3081 u8 *mac,
3082 struct station_parameters *params)
3083{
3084 VOS_STATUS status = VOS_STATUS_SUCCESS;
3085 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Gopichand Nakkala29149562013-05-10 21:43:41 +05303086 hdd_context_t *pHddCtx;
3087 hdd_station_ctx_t *pHddStaCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07003088 v_MACADDR_t STAMacAddress;
Gopichand Nakkalab0856222013-03-12 22:39:05 -07003089#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003090 tCsrStaParams StaParams = {0};
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003091 tANI_U8 isBufSta = 0;
Gopichand Nakkalab0856222013-03-12 22:39:05 -07003092#endif
Jeff Johnsone7245742012-09-05 17:12:55 -07003093 ENTER();
3094
Gopichand Nakkala29149562013-05-10 21:43:41 +05303095 if ((NULL == pAdapter))
3096 {
3097 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
3098 "invalid adapter ");
3099 return -EINVAL;
3100 }
3101
3102 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
3103 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3104
3105 if ((NULL == pHddCtx) || (NULL == pHddStaCtx))
3106 {
3107 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
3108 "invalid HDD state or HDD station context");
3109 return -EINVAL;
3110 }
3111
3112 if (pHddCtx->isLogpInProgress)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003113 {
3114 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3115 "%s:LOGP in Progress. Ignore!!!", __func__);
3116 return -EAGAIN;
3117 }
3118
Jeff Johnson295189b2012-06-20 16:38:30 -07003119 vos_mem_copy(STAMacAddress.bytes, mac, sizeof(v_MACADDR_t));
3120
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003121 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
3122 || (pAdapter->device_mode == WLAN_HDD_P2P_GO))
Jeff Johnson295189b2012-06-20 16:38:30 -07003123 {
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003124 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED))
Jeff Johnson295189b2012-06-20 16:38:30 -07003125 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303126 status = hdd_softap_change_STA_state( pAdapter, &STAMacAddress,
Jeff Johnson295189b2012-06-20 16:38:30 -07003127 WLANTL_STA_AUTHENTICATED);
3128
Gopichand Nakkala29149562013-05-10 21:43:41 +05303129 if (status != VOS_STATUS_SUCCESS)
3130 {
3131 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3132 "%s: Not able to change TL state to AUTHENTICATED", __func__);
3133 return -EINVAL;
3134 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003135 }
3136 }
Hoonki Leea6d49be2013-04-05 09:43:25 -07003137 else if ((pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
3138 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)) {
Gopichand Nakkala29149562013-05-10 21:43:41 +05303139#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003140 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
3141 StaParams.capability = params->capability;
3142 StaParams.uapsd_queues = params->uapsd_queues;
3143 StaParams.max_sp = params->max_sp;
3144
3145 if (0 != params->ext_capab_len)
3146 vos_mem_copy(StaParams.extn_capability, params->ext_capab,
3147 sizeof(StaParams.extn_capability));
3148
3149 if (NULL != params->ht_capa)
Hoonki Lee66b75f32013-04-16 18:30:07 -07003150 {
3151 StaParams.htcap_present = 1;
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003152 vos_mem_copy(&StaParams.HTCap, params->ht_capa, sizeof(tSirHTCap));
Hoonki Lee66b75f32013-04-16 18:30:07 -07003153 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003154
3155 StaParams.supported_rates_len = params->supported_rates_len;
3156
3157 /* Note : The Maximum sizeof supported_rates sent by the Supplicant is 32.
3158 * The supported_rates array , for all the structures propogating till Add Sta
3159 * to the firmware has to be modified , if the supplicant (ieee80211) is
3160 * modified to send more rates.
3161 */
3162
3163 /* To avoid Data Currption , set to max length to SIR_MAC_MAX_SUPP_RATES
3164 */
3165 if (StaParams.supported_rates_len > SIR_MAC_MAX_SUPP_RATES)
3166 StaParams.supported_rates_len = SIR_MAC_MAX_SUPP_RATES;
3167
3168 if (0 != StaParams.supported_rates_len) {
3169 int i = 0;
3170 vos_mem_copy(StaParams.supported_rates, params->supported_rates,
3171 StaParams.supported_rates_len);
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003172 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003173 "Supported Rates with Length %d", StaParams.supported_rates_len);
3174 for (i=0; i < StaParams.supported_rates_len; i++)
Hoonki Lee5305c3a2013-04-29 23:28:59 -07003175 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003176 "[%d]: %0x", i, StaParams.supported_rates[i]);
3177 }
3178
3179 if (NULL != params->vht_capa)
Hoonki Lee66b75f32013-04-16 18:30:07 -07003180 {
3181 StaParams.vhtcap_present = 1;
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003182 vos_mem_copy(&StaParams.VHTCap, params->vht_capa, sizeof(tSirVHTCap));
Hoonki Lee66b75f32013-04-16 18:30:07 -07003183 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003184
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003185 if (0 != params->ext_capab_len ) {
3186 /*Define A Macro : TODO Sunil*/
3187 if ((1<<4) & StaParams.extn_capability[3]) {
3188 isBufSta = 1;
3189 }
3190 }
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05303191 status = wlan_hdd_tdls_set_peer_caps( pAdapter, mac, params->uapsd_queues,
3192 params->max_sp, isBufSta);
3193 if (VOS_STATUS_SUCCESS != status) {
3194 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3195 "%s: wlan_hdd_tdls_set_peer_caps failed!", __func__);
3196 return -EINVAL;
3197 }
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003198 status = wlan_hdd_tdls_add_station(wiphy, dev, mac, 1, &StaParams);
3199
3200 if (VOS_STATUS_SUCCESS != status) {
3201 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3202 "%s: sme_ChangeTdlsPeerSta failed!", __func__);
3203 return -EINVAL;
3204 }
3205 }
Gopichand Nakkalab0856222013-03-12 22:39:05 -07003206#endif
Gopichand Nakkala6239acd2013-06-14 14:48:00 +05303207 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003208 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07003209 return status;
3210}
3211
3212/*
Jeff Johnson295189b2012-06-20 16:38:30 -07003213 * FUNCTION: wlan_hdd_cfg80211_add_key
3214 * This function is used to initialize the key information
3215 */
3216#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003217static int wlan_hdd_cfg80211_add_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003218 struct net_device *ndev,
3219 u8 key_index, bool pairwise,
3220 const u8 *mac_addr,
3221 struct key_params *params
3222 )
3223#else
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003224static int wlan_hdd_cfg80211_add_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003225 struct net_device *ndev,
3226 u8 key_index, const u8 *mac_addr,
3227 struct key_params *params
3228 )
3229#endif
3230{
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003231 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Jeff Johnson295189b2012-06-20 16:38:30 -07003232 tCsrRoamSetKey setKey;
3233 u8 groupmacaddr[WNI_CFG_BSSID_LEN] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303234 int status;
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003235 v_U32_t roamId= 0xFF;
3236 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
Jeff Johnson295189b2012-06-20 16:38:30 -07003237 hdd_hostapd_state_t *pHostapdState;
3238 VOS_STATUS vos_status;
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003239 eHalStatus halStatus;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303240 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07003241
3242 ENTER();
3243
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303244 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
3245 status = wlan_hdd_validate_context(pHddCtx);
3246
3247 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003248 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303249 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3250 "%s: HDD context is not valid", __func__);
3251 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003252 }
3253
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003254 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
3255 __func__, pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07003256
3257 if (CSR_MAX_NUM_KEY <= key_index)
3258 {
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003259 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key index %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07003260 key_index);
3261
3262 return -EINVAL;
3263 }
3264
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003265 if (CSR_MAX_KEY_LEN < params->key_len)
3266 {
3267 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key length %d", __func__,
3268 params->key_len);
3269
3270 return -EINVAL;
3271 }
3272
3273 hddLog(VOS_TRACE_LEVEL_INFO,
3274 "%s: called with key index = %d & key length %d",
3275 __func__, key_index, params->key_len);
Jeff Johnson295189b2012-06-20 16:38:30 -07003276
3277 /*extract key idx, key len and key*/
3278 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
3279 setKey.keyId = key_index;
3280 setKey.keyLength = params->key_len;
3281 vos_mem_copy(&setKey.Key[0],params->key, params->key_len);
3282
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003283 switch (params->cipher)
Jeff Johnson295189b2012-06-20 16:38:30 -07003284 {
3285 case WLAN_CIPHER_SUITE_WEP40:
3286 setKey.encType = eCSR_ENCRYPT_TYPE_WEP40_STATICKEY;
3287 break;
3288
3289 case WLAN_CIPHER_SUITE_WEP104:
3290 setKey.encType = eCSR_ENCRYPT_TYPE_WEP104_STATICKEY;
3291 break;
3292
3293 case WLAN_CIPHER_SUITE_TKIP:
3294 {
3295 u8 *pKey = &setKey.Key[0];
3296 setKey.encType = eCSR_ENCRYPT_TYPE_TKIP;
3297
3298 vos_mem_zero(pKey, CSR_MAX_KEY_LEN);
3299
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003300 /*Supplicant sends the 32bytes key in this order
Jeff Johnson295189b2012-06-20 16:38:30 -07003301
3302 |--------------|----------|----------|
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003303 | Tk1 |TX-MIC | RX Mic |
Jeff Johnson295189b2012-06-20 16:38:30 -07003304 |--------------|----------|----------|
3305 <---16bytes---><--8bytes--><--8bytes-->
3306
3307 */
3308 /*Sme expects the 32 bytes key to be in the below order
3309
3310 |--------------|----------|----------|
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003311 | Tk1 |RX-MIC | TX Mic |
Jeff Johnson295189b2012-06-20 16:38:30 -07003312 |--------------|----------|----------|
3313 <---16bytes---><--8bytes--><--8bytes-->
3314 */
3315 /* Copy the Temporal Key 1 (TK1) */
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003316 vos_mem_copy(pKey, params->key, 16);
Jeff Johnson295189b2012-06-20 16:38:30 -07003317
3318 /*Copy the rx mic first*/
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003319 vos_mem_copy(&pKey[16], &params->key[24], 8);
Jeff Johnson295189b2012-06-20 16:38:30 -07003320
3321 /*Copy the tx mic */
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003322 vos_mem_copy(&pKey[24], &params->key[16], 8);
Jeff Johnson295189b2012-06-20 16:38:30 -07003323
3324
3325 break;
3326 }
3327
3328 case WLAN_CIPHER_SUITE_CCMP:
3329 setKey.encType = eCSR_ENCRYPT_TYPE_AES;
3330 break;
3331
3332#ifdef FEATURE_WLAN_WAPI
3333 case WLAN_CIPHER_SUITE_SMS4:
3334 {
3335 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
3336 wlan_hdd_cfg80211_set_key_wapi(pAdapter, key_index, mac_addr,
3337 params->key, params->key_len);
3338 return 0;
3339 }
3340#endif
Chet Lanctot186b5732013-03-18 10:26:30 -07003341
Jeff Johnson295189b2012-06-20 16:38:30 -07003342#ifdef FEATURE_WLAN_CCX
3343 case WLAN_CIPHER_SUITE_KRK:
3344 setKey.encType = eCSR_ENCRYPT_TYPE_KRK;
3345 break;
3346#endif
Chet Lanctot186b5732013-03-18 10:26:30 -07003347
3348#ifdef WLAN_FEATURE_11W
3349 case WLAN_CIPHER_SUITE_AES_CMAC:
3350 setKey.encType = eCSR_ENCRYPT_TYPE_AES_CMAC;
Chet Lanctot3b5158a2013-03-31 16:45:21 -07003351 break;
Chet Lanctot186b5732013-03-18 10:26:30 -07003352#endif
3353
Jeff Johnson295189b2012-06-20 16:38:30 -07003354 default:
3355 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: unsupported cipher type %lu",
3356 __func__, params->cipher);
3357 return -EOPNOTSUPP;
3358 }
3359
3360 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: encryption type %d",
3361 __func__, setKey.encType);
3362
Shailender Karmuchi642e9812013-05-30 14:34:49 -07003363 if (
Jeff Johnson295189b2012-06-20 16:38:30 -07003364#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
3365 (!pairwise)
3366#else
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003367 (!mac_addr || is_broadcast_ether_addr(mac_addr))
Jeff Johnson295189b2012-06-20 16:38:30 -07003368#endif
Shailender Karmuchi642e9812013-05-30 14:34:49 -07003369 )
3370 {
3371 /* set group key*/
3372 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3373 "%s- %d: setting Broadcast key",
3374 __func__, __LINE__);
3375 setKey.keyDirection = eSIR_RX_ONLY;
3376 vos_mem_copy(setKey.peerMac,groupmacaddr,WNI_CFG_BSSID_LEN);
3377 }
3378 else
3379 {
3380 /* set pairwise key*/
3381 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3382 "%s- %d: setting pairwise key",
3383 __func__, __LINE__);
3384 setKey.keyDirection = eSIR_TX_RX;
3385 vos_mem_copy(setKey.peerMac, mac_addr,WNI_CFG_BSSID_LEN);
3386 }
3387 if ((WLAN_HDD_IBSS == pAdapter->device_mode) && !pairwise)
3388 {
3389 setKey.keyDirection = eSIR_TX_RX;
3390 /*Set the group key*/
3391 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
3392 pAdapter->sessionId, &setKey, &roamId );
Jeff Johnson295189b2012-06-20 16:38:30 -07003393
Shailender Karmuchi642e9812013-05-30 14:34:49 -07003394 if ( 0 != status )
3395 {
3396 hddLog(VOS_TRACE_LEVEL_ERROR,
3397 "%s: sme_RoamSetKey failed, returned %d", __func__, status);
3398 return -EINVAL;
3399 }
3400 /*Save the keys here and call sme_RoamSetKey for setting
3401 the PTK after peer joins the IBSS network*/
3402 vos_mem_copy(&pAdapter->sessionCtx.station.ibss_enc_key,
3403 &setKey, sizeof(tCsrRoamSetKey));
3404 return status;
3405 }
Gopichand Nakkala29149562013-05-10 21:43:41 +05303406 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP) ||
3407 (pAdapter->device_mode == WLAN_HDD_P2P_GO))
3408 {
Jeff Johnson295189b2012-06-20 16:38:30 -07003409 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003410 if( pHostapdState->bssState == BSS_START )
3411 {
Jeff Johnson295189b2012-06-20 16:38:30 -07003412 status = WLANSAP_SetKeySta( pVosContext, &setKey);
3413
3414 if ( status != eHAL_STATUS_SUCCESS )
3415 {
3416 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3417 "[%4d] WLANSAP_SetKeySta returned ERROR status= %d",
3418 __LINE__, status );
3419 }
3420 }
3421
3422 /* Saving WEP keys */
3423 else if( eCSR_ENCRYPT_TYPE_WEP40_STATICKEY == setKey.encType ||
3424 eCSR_ENCRYPT_TYPE_WEP104_STATICKEY == setKey.encType )
3425 {
3426 //Save the wep key in ap context. Issue setkey after the BSS is started.
3427 hdd_ap_ctx_t *pAPCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
3428 vos_mem_copy(&pAPCtx->wepKey[key_index], &setKey, sizeof(tCsrRoamSetKey));
3429 }
3430 else
3431 {
3432 //Save the key in ap context. Issue setkey after the BSS is started.
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003433 hdd_ap_ctx_t *pAPCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07003434 vos_mem_copy(&pAPCtx->groupKey, &setKey, sizeof(tCsrRoamSetKey));
3435 }
3436 }
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003437 else if ( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION) ||
3438 (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003439 {
3440 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
3441 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3442
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303443#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
3444 if (!pairwise)
3445#else
3446 if (!mac_addr || is_broadcast_ether_addr(mac_addr))
3447#endif
3448 {
3449 /* set group key*/
3450 if (pHddStaCtx->roam_info.deferKeyComplete)
3451 {
3452 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3453 "%s- %d: Perform Set key Complete",
3454 __func__, __LINE__);
3455 hdd_PerformRoamSetKeyComplete(pAdapter);
3456 }
3457 }
3458
Jeff Johnson295189b2012-06-20 16:38:30 -07003459 pWextState->roamProfile.Keys.KeyLength[key_index] = (u8)params->key_len;
3460
Venkata Prathyusha Kuntupalliee2ce712013-01-17 14:09:24 -08003461 pWextState->roamProfile.Keys.defaultIndex = key_index;
3462
3463
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003464 vos_mem_copy(&pWextState->roamProfile.Keys.KeyMaterial[key_index][0],
Jeff Johnson295189b2012-06-20 16:38:30 -07003465 params->key, params->key_len);
3466
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303467
Jeff Johnson295189b2012-06-20 16:38:30 -07003468 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_SETTING_KEY;
3469
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303470 hddLog(VOS_TRACE_LEVEL_INFO_MED,
Jeff Johnson295189b2012-06-20 16:38:30 -07003471 "%s: set key for peerMac %2x:%2x:%2x:%2x:%2x:%2x, direction %d",
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303472 __func__, setKey.peerMac[0], setKey.peerMac[1],
3473 setKey.peerMac[2], setKey.peerMac[3],
3474 setKey.peerMac[4], setKey.peerMac[5],
Jeff Johnson295189b2012-06-20 16:38:30 -07003475 setKey.keyDirection);
3476
3477 vos_status = wlan_hdd_check_ula_done(pAdapter);
3478
3479 if ( vos_status != VOS_STATUS_SUCCESS )
3480 {
3481 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3482 "[%4d] wlan_hdd_check_ula_done returned ERROR status= %d",
3483 __LINE__, vos_status );
3484
3485 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3486
3487 return -EINVAL;
3488
3489 }
3490
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003491#ifdef WLAN_FEATURE_VOWIFI_11R
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303492 /* The supplicant may attempt to set the PTK once pre-authentication
3493 is done. Save the key in the UMAC and include it in the ADD BSS
3494 request */
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003495 halStatus = sme_FTUpdateKey( WLAN_HDD_GET_HAL_CTX(pAdapter), &setKey);
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303496 if ( halStatus == eHAL_STATUS_FT_PREAUTH_KEY_SUCCESS )
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003497 {
Gopichand Nakkala3d295922013-05-07 16:19:14 +05303498 hddLog(VOS_TRACE_LEVEL_INFO_MED,
3499 "%s: Update PreAuth Key success", __func__);
3500 return 0;
3501 }
3502 else if ( halStatus == eHAL_STATUS_FT_PREAUTH_KEY_FAILED )
3503 {
3504 hddLog(VOS_TRACE_LEVEL_ERROR,
3505 "%s: Update PreAuth Key failed", __func__);
Gopichand Nakkalad7d13652013-02-15 01:48:00 +05303506 return -EINVAL;
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003507 }
3508#endif /* WLAN_FEATURE_VOWIFI_11R */
Jeff Johnson295189b2012-06-20 16:38:30 -07003509
3510 /* issue set key request to SME*/
3511 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
3512 pAdapter->sessionId, &setKey, &roamId );
3513
3514 if ( 0 != status )
3515 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303516 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07003517 "%s: sme_RoamSetKey failed, returned %d", __func__, status);
3518 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3519 return -EINVAL;
3520 }
3521
3522
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303523 /* in case of IBSS as there was no information available about WEP keys during
3524 * IBSS join, group key intialized with NULL key, so re-initialize group key
Jeff Johnson295189b2012-06-20 16:38:30 -07003525 * with correct value*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303526 if ( (eCSR_BSS_TYPE_START_IBSS == pWextState->roamProfile.BSSType) &&
3527 !( ( IW_AUTH_KEY_MGMT_802_1X
3528 == (pWextState->authKeyMgmt & IW_AUTH_KEY_MGMT_802_1X))
Jeff Johnson295189b2012-06-20 16:38:30 -07003529 && (eCSR_AUTH_TYPE_OPEN_SYSTEM == pHddStaCtx->conn_info.authType)
3530 )
3531 &&
3532 ( (WLAN_CIPHER_SUITE_WEP40 == params->cipher)
3533 || (WLAN_CIPHER_SUITE_WEP104 == params->cipher)
3534 )
3535 )
3536 {
3537 setKey.keyDirection = eSIR_RX_ONLY;
3538 vos_mem_copy(setKey.peerMac,groupmacaddr,WNI_CFG_BSSID_LEN);
3539
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303540 hddLog(VOS_TRACE_LEVEL_INFO_MED,
Jeff Johnson295189b2012-06-20 16:38:30 -07003541 "%s: set key peerMac %2x:%2x:%2x:%2x:%2x:%2x, direction %d",
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303542 __func__, setKey.peerMac[0], setKey.peerMac[1],
3543 setKey.peerMac[2], setKey.peerMac[3],
3544 setKey.peerMac[4], setKey.peerMac[5],
Jeff Johnson295189b2012-06-20 16:38:30 -07003545 setKey.keyDirection);
3546
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303547 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07003548 pAdapter->sessionId, &setKey, &roamId );
3549
3550 if ( 0 != status )
3551 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303552 hddLog(VOS_TRACE_LEVEL_ERROR,
3553 "%s: sme_RoamSetKey failed for group key (IBSS), returned %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07003554 __func__, status);
3555 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3556 return -EINVAL;
3557 }
3558 }
3559 }
3560
3561 return 0;
3562}
3563
3564/*
3565 * FUNCTION: wlan_hdd_cfg80211_get_key
3566 * This function is used to get the key information
3567 */
3568#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303569static int wlan_hdd_cfg80211_get_key(
3570 struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003571 struct net_device *ndev,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303572 u8 key_index, bool pairwise,
Jeff Johnson295189b2012-06-20 16:38:30 -07003573 const u8 *mac_addr, void *cookie,
3574 void (*callback)(void *cookie, struct key_params*)
3575 )
3576#else
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303577static int wlan_hdd_cfg80211_get_key(
3578 struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003579 struct net_device *ndev,
3580 u8 key_index, const u8 *mac_addr, void *cookie,
3581 void (*callback)(void *cookie, struct key_params*)
3582 )
3583#endif
3584{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303585 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Jeff Johnson295189b2012-06-20 16:38:30 -07003586 hdd_wext_state_t *pWextState= WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
3587 tCsrRoamProfile *pRoamProfile = &(pWextState->roamProfile);
3588 struct key_params params;
3589
3590 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303591
Jeff Johnson295189b2012-06-20 16:38:30 -07003592 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
3593 __func__,pAdapter->device_mode);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303594
Jeff Johnson295189b2012-06-20 16:38:30 -07003595 memset(&params, 0, sizeof(params));
3596
3597 if (CSR_MAX_NUM_KEY <= key_index)
3598 {
3599 return -EINVAL;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303600 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003601
3602 switch(pRoamProfile->EncryptionType.encryptionType[0])
3603 {
3604 case eCSR_ENCRYPT_TYPE_NONE:
3605 params.cipher = IW_AUTH_CIPHER_NONE;
3606 break;
3607
3608 case eCSR_ENCRYPT_TYPE_WEP40_STATICKEY:
3609 case eCSR_ENCRYPT_TYPE_WEP40:
3610 params.cipher = WLAN_CIPHER_SUITE_WEP40;
3611 break;
3612
3613 case eCSR_ENCRYPT_TYPE_WEP104_STATICKEY:
3614 case eCSR_ENCRYPT_TYPE_WEP104:
3615 params.cipher = WLAN_CIPHER_SUITE_WEP104;
3616 break;
3617
3618 case eCSR_ENCRYPT_TYPE_TKIP:
3619 params.cipher = WLAN_CIPHER_SUITE_TKIP;
3620 break;
3621
3622 case eCSR_ENCRYPT_TYPE_AES:
3623 params.cipher = WLAN_CIPHER_SUITE_AES_CMAC;
3624 break;
3625
3626 default:
3627 params.cipher = IW_AUTH_CIPHER_NONE;
3628 break;
3629 }
3630
3631 params.key_len = pRoamProfile->Keys.KeyLength[key_index];
3632 params.seq_len = 0;
3633 params.seq = NULL;
3634 params.key = &pRoamProfile->Keys.KeyMaterial[key_index][0];
3635 callback(cookie, &params);
3636 return 0;
3637}
3638
3639/*
3640 * FUNCTION: wlan_hdd_cfg80211_del_key
3641 * This function is used to delete the key information
3642 */
3643#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303644static int wlan_hdd_cfg80211_del_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003645 struct net_device *ndev,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303646 u8 key_index,
3647 bool pairwise,
Jeff Johnson295189b2012-06-20 16:38:30 -07003648 const u8 *mac_addr
3649 )
3650#else
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303651static int wlan_hdd_cfg80211_del_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003652 struct net_device *ndev,
3653 u8 key_index,
3654 const u8 *mac_addr
3655 )
3656#endif
3657{
3658 int status = 0;
3659
3660 //This code needs to be revisited. There is sme_removeKey API, we should
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303661 //plan to use that. After the change to use correct index in setkey,
Jeff Johnson295189b2012-06-20 16:38:30 -07003662 //it is observed that this is invalidating peer
3663 //key index whenever re-key is done. This is affecting data link.
3664 //It should be ok to ignore del_key.
3665#if 0
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303666 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
3667 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
Jeff Johnson295189b2012-06-20 16:38:30 -07003668 u8 groupmacaddr[WNI_CFG_BSSID_LEN] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
3669 tCsrRoamSetKey setKey;
3670 v_U32_t roamId= 0xFF;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303671
Jeff Johnson295189b2012-06-20 16:38:30 -07003672 ENTER();
3673
3674 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: device_mode = %d\n",
3675 __func__,pAdapter->device_mode);
3676
3677 if (CSR_MAX_NUM_KEY <= key_index)
3678 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303679 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key index %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07003680 key_index);
3681
3682 return -EINVAL;
3683 }
3684
3685 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
3686 setKey.keyId = key_index;
3687
3688 if (mac_addr)
3689 vos_mem_copy(setKey.peerMac, mac_addr,WNI_CFG_BSSID_LEN);
3690 else
3691 vos_mem_copy(setKey.peerMac, groupmacaddr, WNI_CFG_BSSID_LEN);
3692
3693 setKey.encType = eCSR_ENCRYPT_TYPE_NONE;
3694
3695 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07003696 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303697 )
3698 {
3699
3700 hdd_hostapd_state_t *pHostapdState =
Jeff Johnson295189b2012-06-20 16:38:30 -07003701 WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
3702 if( pHostapdState->bssState == BSS_START)
3703 {
3704 status = WLANSAP_SetKeySta( pVosContext, &setKey);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303705
Jeff Johnson295189b2012-06-20 16:38:30 -07003706 if ( status != eHAL_STATUS_SUCCESS )
3707 {
3708 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3709 "[%4d] WLANSAP_SetKeySta returned ERROR status= %d",
3710 __LINE__, status );
3711 }
3712 }
3713 }
3714 else if ( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303715 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Jeff Johnson295189b2012-06-20 16:38:30 -07003716 )
3717 {
3718 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3719
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303720 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_SETTING_KEY;
3721
3722 hddLog(VOS_TRACE_LEVEL_INFO_MED,
Jeff Johnson295189b2012-06-20 16:38:30 -07003723 "%s: delete key for peerMac %2x:%2x:%2x:%2x:%2x:%2x",
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303724 __func__, setKey.peerMac[0], setKey.peerMac[1],
3725 setKey.peerMac[2], setKey.peerMac[3],
Jeff Johnson295189b2012-06-20 16:38:30 -07003726 setKey.peerMac[4], setKey.peerMac[5]);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303727 if(pAdapter->sessionCtx.station.conn_info.connState ==
3728 eConnectionState_Associated)
Jeff Johnson295189b2012-06-20 16:38:30 -07003729 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303730 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07003731 pAdapter->sessionId, &setKey, &roamId );
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303732
Jeff Johnson295189b2012-06-20 16:38:30 -07003733 if ( 0 != status )
3734 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303735 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07003736 "%s: sme_RoamSetKey failure, returned %d",
3737 __func__, status);
3738 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3739 return -EINVAL;
3740 }
3741 }
3742 }
3743#endif
Jeff Johnsone7245742012-09-05 17:12:55 -07003744 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07003745 return status;
3746}
3747
3748/*
3749 * FUNCTION: wlan_hdd_cfg80211_set_default_key
3750 * This function is used to set the default tx key index
3751 */
3752#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
3753static int wlan_hdd_cfg80211_set_default_key( struct wiphy *wiphy,
3754 struct net_device *ndev,
3755 u8 key_index,
3756 bool unicast, bool multicast)
3757#else
3758static int wlan_hdd_cfg80211_set_default_key( struct wiphy *wiphy,
3759 struct net_device *ndev,
3760 u8 key_index)
3761#endif
3762{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303763 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303764 int status;
Gopichand Nakkala29149562013-05-10 21:43:41 +05303765 hdd_wext_state_t *pWextState;
3766 hdd_station_ctx_t *pHddStaCtx;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303767 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07003768
3769 ENTER();
3770
Gopichand Nakkala29149562013-05-10 21:43:41 +05303771 if ((NULL == pAdapter))
3772 {
3773 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
3774 "invalid adapter");
3775 return -EINVAL;
3776 }
3777
3778 pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
3779 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3780
3781 if ((NULL == pWextState) || (NULL == pHddStaCtx))
3782 {
3783 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
3784 "invalid Wext state or HDD context");
3785 return -EINVAL;
3786 }
3787
Jeff Johnson295189b2012-06-20 16:38:30 -07003788 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d key_index = %d \n",
3789 __func__,pAdapter->device_mode, key_index);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303790
Jeff Johnson295189b2012-06-20 16:38:30 -07003791 if (CSR_MAX_NUM_KEY <= key_index)
3792 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303793 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key index %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07003794 key_index);
3795
3796 return -EINVAL;
3797 }
3798
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303799 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
3800 status = wlan_hdd_validate_context(pHddCtx);
3801
3802 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003803 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05303804 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3805 "%s: HDD context is not valid", __func__);
3806 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003807 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303808
Jeff Johnson295189b2012-06-20 16:38:30 -07003809 if ((pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Jeff Johnson295189b2012-06-20 16:38:30 -07003810 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303811 )
Jeff Johnson295189b2012-06-20 16:38:30 -07003812 {
Gopichand Nakkala29149562013-05-10 21:43:41 +05303813 if ( (eCSR_ENCRYPT_TYPE_TKIP !=
Jeff Johnson295189b2012-06-20 16:38:30 -07003814 pWextState->roamProfile.EncryptionType.encryptionType[0]) &&
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303815 (eCSR_ENCRYPT_TYPE_AES !=
Jeff Johnson295189b2012-06-20 16:38:30 -07003816 pWextState->roamProfile.EncryptionType.encryptionType[0])
3817 )
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303818 {
3819 /* if default key index is not same as previous one,
Jeff Johnson295189b2012-06-20 16:38:30 -07003820 * then update the default key index */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303821
Jeff Johnson295189b2012-06-20 16:38:30 -07003822 tCsrRoamSetKey setKey;
3823 v_U32_t roamId= 0xFF;
3824 tCsrKeys *Keys = &pWextState->roamProfile.Keys;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303825
3826 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: default tx key index %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07003827 __func__, key_index);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303828
Jeff Johnson295189b2012-06-20 16:38:30 -07003829 Keys->defaultIndex = (u8)key_index;
3830 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
3831 setKey.keyId = key_index;
3832 setKey.keyLength = Keys->KeyLength[key_index];
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303833
3834 vos_mem_copy(&setKey.Key[0],
3835 &Keys->KeyMaterial[key_index][0],
Jeff Johnson295189b2012-06-20 16:38:30 -07003836 Keys->KeyLength[key_index]);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303837
Gopichand Nakkala29149562013-05-10 21:43:41 +05303838 setKey.keyDirection = eSIR_TX_RX;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303839
3840 vos_mem_copy(setKey.peerMac,
Jeff Johnson295189b2012-06-20 16:38:30 -07003841 &pHddStaCtx->conn_info.bssId[0],
3842 WNI_CFG_BSSID_LEN);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303843
Gopichand Nakkala29149562013-05-10 21:43:41 +05303844 if (Keys->KeyLength[key_index] == CSR_WEP40_KEY_LEN &&
3845 pWextState->roamProfile.EncryptionType.encryptionType[0] ==
3846 eCSR_ENCRYPT_TYPE_WEP104)
3847 {
3848 /*In the case of dynamic wep supplicant hardcodes DWEP type to eCSR_ENCRYPT_TYPE_WEP104
3849 even though ap is configured for WEP-40 encryption. In this canse the key length
3850 is 5 but the encryption type is 104 hence checking the key langht(5) and encryption
3851 type(104) and switching encryption type to 40*/
3852 pWextState->roamProfile.EncryptionType.encryptionType[0] =
3853 eCSR_ENCRYPT_TYPE_WEP40;
3854 pWextState->roamProfile.mcEncryptionType.encryptionType[0] =
3855 eCSR_ENCRYPT_TYPE_WEP40;
3856 }
3857
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303858 setKey.encType =
Jeff Johnson295189b2012-06-20 16:38:30 -07003859 pWextState->roamProfile.EncryptionType.encryptionType[0];
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303860
Jeff Johnson295189b2012-06-20 16:38:30 -07003861 /* issue set key request */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303862 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07003863 pAdapter->sessionId, &setKey, &roamId );
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303864
Jeff Johnson295189b2012-06-20 16:38:30 -07003865 if ( 0 != status )
3866 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303867 hddLog(VOS_TRACE_LEVEL_ERROR,
3868 "%s: sme_RoamSetKey failed, returned %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07003869 status);
3870 return -EINVAL;
3871 }
3872 }
3873 }
3874
3875 /* In SoftAp mode setting key direction for default mode */
3876 else if ( WLAN_HDD_SOFTAP == pAdapter->device_mode )
3877 {
3878 if ( (eCSR_ENCRYPT_TYPE_TKIP !=
3879 pWextState->roamProfile.EncryptionType.encryptionType[0]) &&
3880 (eCSR_ENCRYPT_TYPE_AES !=
3881 pWextState->roamProfile.EncryptionType.encryptionType[0])
3882 )
3883 {
3884 /* Saving key direction for default key index to TX default */
3885 hdd_ap_ctx_t *pAPCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
3886 pAPCtx->wepKey[key_index].keyDirection = eSIR_TX_DEFAULT;
3887 }
3888 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303889
Jeff Johnson295189b2012-06-20 16:38:30 -07003890 return status;
3891}
3892
Jeff Johnson295189b2012-06-20 16:38:30 -07003893/*
3894 * FUNCTION: wlan_hdd_cfg80211_inform_bss
3895 * This function is used to inform the BSS details to nl80211 interface.
3896 */
3897static struct cfg80211_bss* wlan_hdd_cfg80211_inform_bss(
3898 hdd_adapter_t *pAdapter, tCsrRoamConnectedProfile *roamProfile)
3899{
3900 struct net_device *dev = pAdapter->dev;
3901 struct wireless_dev *wdev = dev->ieee80211_ptr;
3902 struct wiphy *wiphy = wdev->wiphy;
3903 tSirBssDescription *pBssDesc = roamProfile->pBssDesc;
3904 int chan_no;
3905 int ie_length;
3906 const char *ie;
3907 unsigned int freq;
3908 struct ieee80211_channel *chan;
3909 int rssi = 0;
3910 struct cfg80211_bss *bss = NULL;
3911
3912 ENTER();
3913
3914 if( NULL == pBssDesc )
3915 {
3916 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: pBssDesc is NULL\n", __func__);
3917 return bss;
3918 }
3919
3920 chan_no = pBssDesc->channelId;
3921 ie_length = GET_IE_LEN_IN_BSS_DESC( pBssDesc->length );
3922 ie = ((ie_length != 0) ? (const char *)&pBssDesc->ieFields: NULL);
3923
3924 if( NULL == ie )
3925 {
3926 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: IE of BSS descriptor is NULL\n", __func__);
3927 return bss;
3928 }
3929
3930#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,38))
3931 if (chan_no <= ARRAY_SIZE(hdd_channels_2_4_GHZ))
3932 {
3933 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_2GHZ);
3934 }
3935 else
3936 {
3937 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_5GHZ);
3938 }
3939#else
3940 freq = ieee80211_channel_to_frequency(chan_no);
3941#endif
3942
3943 chan = __ieee80211_get_channel(wiphy, freq);
3944
3945 bss = cfg80211_get_bss(wiphy, chan, pBssDesc->bssId,
3946 &roamProfile->SSID.ssId[0], roamProfile->SSID.length,
3947 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
3948 if (bss == NULL)
3949 {
3950 rssi = (VOS_MIN ((pBssDesc->rssi + pBssDesc->sinr), 0))*100;
3951
Gopichand Nakkala747461f2013-04-24 19:24:45 +05303952 return (cfg80211_inform_bss(wiphy, chan, pBssDesc->bssId,
3953 le64_to_cpu(*(__le64 *)pBssDesc->timeStamp),
Jeff Johnson295189b2012-06-20 16:38:30 -07003954 pBssDesc->capabilityInfo,
3955 pBssDesc->beaconInterval, ie, ie_length,
3956 rssi, GFP_KERNEL ));
3957}
3958 else
3959 {
3960 return bss;
3961 }
3962}
3963
3964
3965
3966/*
3967 * FUNCTION: wlan_hdd_cfg80211_inform_bss_frame
3968 * This function is used to inform the BSS details to nl80211 interface.
3969 */
3970struct cfg80211_bss*
3971wlan_hdd_cfg80211_inform_bss_frame( hdd_adapter_t *pAdapter,
3972 tSirBssDescription *bss_desc
3973 )
3974{
3975 /*
3976 cfg80211_inform_bss() is not updating ie field of bss entry, if entry
3977 already exists in bss data base of cfg80211 for that particular BSS ID.
3978 Using cfg80211_inform_bss_frame to update the bss entry instead of
3979 cfg80211_inform_bss, But this call expects mgmt packet as input. As of
3980 now there is no possibility to get the mgmt(probe response) frame from PE,
3981 converting bss_desc to ieee80211_mgmt(probe response) and passing to
3982 cfg80211_inform_bss_frame.
3983 */
3984 struct net_device *dev = pAdapter->dev;
3985 struct wireless_dev *wdev = dev->ieee80211_ptr;
3986 struct wiphy *wiphy = wdev->wiphy;
3987 int chan_no = bss_desc->channelId;
Madan Mohan Koyyalamudi86f629e2012-11-09 16:27:29 -08003988#ifdef WLAN_ENABLE_AGEIE_ON_SCAN_RESULTS
3989 qcom_ie_age *qie_age = NULL;
3990 int ie_length = GET_IE_LEN_IN_BSS_DESC( bss_desc->length ) + sizeof(qcom_ie_age);
3991#else
Jeff Johnson295189b2012-06-20 16:38:30 -07003992 int ie_length = GET_IE_LEN_IN_BSS_DESC( bss_desc->length );
Madan Mohan Koyyalamudi86f629e2012-11-09 16:27:29 -08003993#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07003994 const char *ie =
3995 ((ie_length != 0) ? (const char *)&bss_desc->ieFields: NULL);
3996 unsigned int freq;
3997 struct ieee80211_channel *chan;
3998 struct ieee80211_mgmt *mgmt =
3999 kzalloc((sizeof (struct ieee80211_mgmt) + ie_length), GFP_KERNEL);
4000 struct cfg80211_bss *bss_status = NULL;
4001 size_t frame_len = sizeof (struct ieee80211_mgmt) + ie_length;
4002 int rssi = 0;
Jeff Johnsone7245742012-09-05 17:12:55 -07004003#ifdef WLAN_OPEN_SOURCE
4004 struct timespec ts;
4005#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004006
4007 ENTER();
4008
Madan Mohan Koyyalamudi2e5c9142012-11-02 13:17:48 -07004009 if (!mgmt)
4010 return NULL;
4011
Jeff Johnson295189b2012-06-20 16:38:30 -07004012 memcpy(mgmt->bssid, bss_desc->bssId, ETH_ALEN);
Jeff Johnsone7245742012-09-05 17:12:55 -07004013
4014#ifdef WLAN_OPEN_SOURCE
4015 /* Android does not want the timestamp from the frame.
4016 Instead it wants a monotonic increasing value */
4017 get_monotonic_boottime(&ts);
4018 mgmt->u.probe_resp.timestamp =
4019 ((u64)ts.tv_sec * 1000000) + (ts.tv_nsec / 1000);
4020#else
4021 /* keep old behavior for non-open source (for now) */
Jeff Johnson295189b2012-06-20 16:38:30 -07004022 memcpy(&mgmt->u.probe_resp.timestamp, bss_desc->timeStamp,
4023 sizeof (bss_desc->timeStamp));
Jeff Johnsone7245742012-09-05 17:12:55 -07004024
4025#endif
4026
Jeff Johnson295189b2012-06-20 16:38:30 -07004027 mgmt->u.probe_resp.beacon_int = bss_desc->beaconInterval;
4028 mgmt->u.probe_resp.capab_info = bss_desc->capabilityInfo;
Madan Mohan Koyyalamudi86f629e2012-11-09 16:27:29 -08004029
4030#ifdef WLAN_ENABLE_AGEIE_ON_SCAN_RESULTS
4031 /* GPS Requirement: need age ie per entry. Using vendor specific. */
4032 /* Assuming this is the last IE, copy at the end */
4033 ie_length -=sizeof(qcom_ie_age);
4034 qie_age = (qcom_ie_age *)(mgmt->u.probe_resp.variable + ie_length);
4035 qie_age->element_id = QCOM_VENDOR_IE_ID;
4036 qie_age->len = QCOM_VENDOR_IE_AGE_LEN;
4037 qie_age->oui_1 = QCOM_OUI1;
4038 qie_age->oui_2 = QCOM_OUI2;
4039 qie_age->oui_3 = QCOM_OUI3;
4040 qie_age->type = QCOM_VENDOR_IE_AGE_TYPE;
4041 qie_age->age = vos_timer_get_system_ticks() - bss_desc->nReceivedTime;
4042#endif
4043
Jeff Johnson295189b2012-06-20 16:38:30 -07004044 memcpy(mgmt->u.probe_resp.variable, ie, ie_length);
Gopichand Nakkalad908ec82013-05-16 19:32:19 +05304045 if (bss_desc->fProbeRsp)
4046 {
4047 mgmt->frame_control |=
4048 (u16)(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_RESP);
4049 }
4050 else
4051 {
4052 mgmt->frame_control |=
4053 (u16)(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_BEACON);
4054 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004055
4056#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,38))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304057 if (chan_no <= ARRAY_SIZE(hdd_channels_2_4_GHZ) &&
Jeff Johnson295189b2012-06-20 16:38:30 -07004058 (wiphy->bands[IEEE80211_BAND_2GHZ] != NULL))
4059 {
4060 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_2GHZ);
4061 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304062 else if ((chan_no > ARRAY_SIZE(hdd_channels_2_4_GHZ)) &&
Jeff Johnson295189b2012-06-20 16:38:30 -07004063 (wiphy->bands[IEEE80211_BAND_5GHZ] != NULL))
4064
4065 {
4066 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_5GHZ);
4067 }
4068 else
4069 {
4070 kfree(mgmt);
4071 return NULL;
4072 }
4073#else
4074 freq = ieee80211_channel_to_frequency(chan_no);
4075#endif
4076 chan = __ieee80211_get_channel(wiphy, freq);
Leela V Kiran Kumar Reddy90032de2013-01-24 18:33:30 -08004077 /*when the band is changed on the fly using the GUI, three things are done
4078 * 1. scan abort 2.flush scan results from cache 3.update the band with the new band user specified(refer to the hdd_setBand_helper function)
4079 * as part of the scan abort, message willbe queued to PE and we proceed with flushing and changinh the band.
4080 * pe will stop the scanning further and report back the results what ever it had till now by calling the call back function.
4081 * if the time between update band and scandone call back is sufficent enough the band change reflects in SME, SME validates the channels
4082 * and discards the channels correponding to previous band and calls back with zero bss results.
4083 * but if the time between band update and scan done callback is very small then band change will not reflect in SME and SME reports to HDD
4084 * all the channels correponding to previous band.this is due to race condition.but those channels are invalid to the new band and so
4085 * this function __ieee80211_get_channel will return NULL.Each time we report scan result with this pointer null warning kernel trace is printed.
4086 * if the scan results contain large number of APs continuosly kernel warning trace is printed and it will lead to apps watch dog bark.
4087 * So drop the bss and continue to next bss.
4088 */
4089 if(chan == NULL)
4090 {
4091 hddLog(VOS_TRACE_LEVEL_INFO, "%s chan pointer is NULL", __func__);
Chilam Ngc4244af2013-04-01 15:37:32 -07004092 kfree(mgmt);
Leela V Kiran Kumar Reddy90032de2013-01-24 18:33:30 -08004093 return NULL;
4094 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004095 /*To keep the rssi icon of the connected AP in the scan window
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304096 *and the rssi icon of the wireless networks in sync
Jeff Johnson295189b2012-06-20 16:38:30 -07004097 * */
4098 if (( eConnectionState_Associated ==
4099 pAdapter->sessionCtx.station.conn_info.connState ) &&
4100 ( VOS_TRUE == vos_mem_compare(bss_desc->bssId,
4101 pAdapter->sessionCtx.station.conn_info.bssId,
4102 WNI_CFG_BSSID_LEN)))
4103 {
4104 /* supplicant takes the signal strength in terms of mBm(100*dBm) */
4105 rssi = (pAdapter->rssi * 100);
4106 }
4107 else
4108 {
4109 rssi = (VOS_MIN ((bss_desc->rssi + bss_desc->sinr), 0))*100;
4110 }
4111
4112 bss_status = cfg80211_inform_bss_frame(wiphy, chan, mgmt,
4113 frame_len, rssi, GFP_KERNEL);
4114 kfree(mgmt);
4115 return bss_status;
4116}
4117
4118/*
4119 * FUNCTION: wlan_hdd_cfg80211_update_bss_db
4120 * This function is used to update the BSS data base of CFG8011
4121 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304122struct cfg80211_bss* wlan_hdd_cfg80211_update_bss_db( hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07004123 tCsrRoamInfo *pRoamInfo
4124 )
4125{
4126 tCsrRoamConnectedProfile roamProfile;
4127 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
4128 struct cfg80211_bss *bss = NULL;
4129
4130 ENTER();
4131
4132 memset(&roamProfile, 0, sizeof(tCsrRoamConnectedProfile));
4133 sme_RoamGetConnectProfile(hHal, pAdapter->sessionId, &roamProfile);
4134
4135 if (NULL != roamProfile.pBssDesc)
4136 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304137 bss = wlan_hdd_cfg80211_inform_bss(pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07004138 &roamProfile);
4139
4140 if (NULL == bss)
4141 {
4142 hddLog(VOS_TRACE_LEVEL_INFO, "%s: cfg80211_inform_bss return NULL",
4143 __func__);
4144 }
4145
4146 sme_RoamFreeConnectProfile(hHal, &roamProfile);
4147 }
4148 else
4149 {
4150 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: roamProfile.pBssDesc is NULL",
4151 __func__);
4152 }
4153 return bss;
4154}
4155
4156/*
4157 * FUNCTION: wlan_hdd_cfg80211_update_bss
4158 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304159static int wlan_hdd_cfg80211_update_bss( struct wiphy *wiphy,
4160 hdd_adapter_t *pAdapter
Jeff Johnson295189b2012-06-20 16:38:30 -07004161 )
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304162{
Jeff Johnson295189b2012-06-20 16:38:30 -07004163 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
4164 tCsrScanResultInfo *pScanResult;
4165 eHalStatus status = 0;
4166 tScanResultHandle pResult;
4167 struct cfg80211_bss *bss_status = NULL;
4168
4169 ENTER();
4170
4171 if ((WLAN_HDD_GET_CTX(pAdapter))->isLogpInProgress)
4172 {
4173 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL, "%s:LOGP in Progress. Ignore!!!",__func__);
4174 return -EAGAIN;
4175 }
4176
4177 /*
4178 * start getting scan results and populate cgf80211 BSS database
4179 */
4180 status = sme_ScanGetResult(hHal, pAdapter->sessionId, NULL, &pResult);
4181
4182 /* no scan results */
4183 if (NULL == pResult)
4184 {
4185 hddLog(VOS_TRACE_LEVEL_INFO, "%s: No scan result\n", __func__);
4186 return status;
4187 }
4188
4189 pScanResult = sme_ScanResultGetFirst(hHal, pResult);
4190
4191 while (pScanResult)
4192 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304193 /*
4194 * cfg80211_inform_bss() is not updating ie field of bss entry, if
4195 * entry already exists in bss data base of cfg80211 for that
4196 * particular BSS ID. Using cfg80211_inform_bss_frame to update the
4197 * bss entry instead of cfg80211_inform_bss, But this call expects
4198 * mgmt packet as input. As of now there is no possibility to get
4199 * the mgmt(probe response) frame from PE, converting bss_desc to
Jeff Johnson295189b2012-06-20 16:38:30 -07004200 * ieee80211_mgmt(probe response) and passing to c
4201 * fg80211_inform_bss_frame.
4202 * */
4203
4204 bss_status = wlan_hdd_cfg80211_inform_bss_frame(pAdapter,
4205 &pScanResult->BssDescriptor);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304206
Jeff Johnson295189b2012-06-20 16:38:30 -07004207
4208 if (NULL == bss_status)
4209 {
4210 hddLog(VOS_TRACE_LEVEL_INFO,
4211 "%s: NULL returned by cfg80211_inform_bss\n", __func__);
4212 }
4213 else
4214 {
Yue Maf49ba872013-08-19 12:04:25 -07004215 cfg80211_put_bss(
4216#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,9,0))
4217 wiphy,
4218#endif
4219 bss_status);
Jeff Johnson295189b2012-06-20 16:38:30 -07004220 }
4221
4222 pScanResult = sme_ScanResultGetNext(hHal, pResult);
4223 }
4224
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304225 sme_ScanResultPurge(hHal, pResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07004226
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304227 return 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07004228}
4229
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004230void
4231hddPrintMacAddr(tCsrBssid macAddr, tANI_U8 logLevel)
4232{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304233 VOS_TRACE(VOS_MODULE_ID_HDD, logLevel,
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07004234 "%02X:%02X:%02X:%02X:%02X:%02X\n",
4235 macAddr[0], macAddr[1], macAddr[2], macAddr[3], macAddr[4],
4236 macAddr[5]);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004237} /****** end hddPrintMacAddr() ******/
4238
4239void
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07004240hddPrintPmkId(tANI_U8 *pmkId, tANI_U8 logLevel)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004241{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304242 VOS_TRACE(VOS_MODULE_ID_HDD, logLevel,
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07004243 "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
4244 pmkId[0], pmkId[1], pmkId[2], pmkId[3], pmkId[4],
4245 pmkId[5], pmkId[6], pmkId[7], pmkId[8], pmkId[9], pmkId[10],
4246 pmkId[11], pmkId[12], pmkId[13], pmkId[14], pmkId[15]);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004247} /****** end hddPrintPmkId() ******/
4248
4249//hddPrintMacAddr(tCsrBssid macAddr, tANI_U8 logLevel);
4250//hddPrintMacAddr(macAddr, VOS_TRACE_LEVEL_FATAL);
4251
4252//void sirDumpBuf(tpAniSirGlobal pMac, tANI_U8 modId, tANI_U32 level, tANI_U8 *buf, tANI_U32 size);
4253//sirDumpBuf(pMac, VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL, pmkid, 16);
4254
4255#define dump_bssid(bssid) \
4256 { \
Jeff Johnsone7245742012-09-05 17:12:55 -07004257 hddLog(VOS_TRACE_LEVEL_INFO, "BSSID (MAC) address:\t"); \
4258 hddPrintMacAddr(bssid, VOS_TRACE_LEVEL_INFO);\
4259 hddLog(VOS_TRACE_LEVEL_INFO, "\n"); \
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004260 }
4261
4262#define dump_pmkid(pMac, pmkid) \
4263 { \
Jeff Johnsone7245742012-09-05 17:12:55 -07004264 hddLog(VOS_TRACE_LEVEL_INFO, "PMKSA-ID:\t"); \
4265 hddPrintPmkId(pmkid, VOS_TRACE_LEVEL_INFO);\
4266 hddLog(VOS_TRACE_LEVEL_INFO, "\n"); \
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004267 }
4268
Madan Mohan Koyyalamudi1b4afb02012-10-22 15:25:16 -07004269#if defined(FEATURE_WLAN_LFR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004270/*
4271 * FUNCTION: wlan_hdd_cfg80211_pmksa_candidate_notify
4272 * This function is used to notify the supplicant of a new PMKSA candidate.
4273 */
4274int wlan_hdd_cfg80211_pmksa_candidate_notify(
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304275 hdd_adapter_t *pAdapter, tCsrRoamInfo *pRoamInfo,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004276 int index, bool preauth )
4277{
Jeff Johnsone7245742012-09-05 17:12:55 -07004278#ifdef FEATURE_WLAN_OKC
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004279 struct net_device *dev = pAdapter->dev;
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004280 hdd_context_t *pHddCtx = (hdd_context_t*)pAdapter->pHddCtx;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004281
4282 ENTER();
Jeff Johnsone7245742012-09-05 17:12:55 -07004283 hddLog(VOS_TRACE_LEVEL_INFO, "%s is going to notify supplicant of:", __func__);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004284
4285 if( NULL == pRoamInfo )
4286 {
4287 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: pRoamInfo is NULL\n", __func__);
4288 return -EINVAL;
4289 }
4290
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004291 if (eANI_BOOLEAN_TRUE == hdd_is_okc_mode_enabled(pHddCtx))
4292 {
4293 dump_bssid(pRoamInfo->bssid);
4294 cfg80211_pmksa_candidate_notify(dev, index,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004295 pRoamInfo->bssid, preauth, GFP_KERNEL);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004296 }
Jeff Johnsone7245742012-09-05 17:12:55 -07004297#endif /* FEATURE_WLAN_OKC */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304298 return 0;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004299}
4300#endif //FEATURE_WLAN_LFR
4301
Jeff Johnson295189b2012-06-20 16:38:30 -07004302/*
4303 * FUNCTION: hdd_cfg80211_scan_done_callback
4304 * scanning callback function, called after finishing scan
4305 *
4306 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304307static eHalStatus hdd_cfg80211_scan_done_callback(tHalHandle halHandle,
Jeff Johnson295189b2012-06-20 16:38:30 -07004308 void *pContext, tANI_U32 scanId, eCsrScanStatus status)
4309{
4310 struct net_device *dev = (struct net_device *) pContext;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304311 //struct wireless_dev *wdev = dev->ieee80211_ptr;
Jeff Johnson295189b2012-06-20 16:38:30 -07004312 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004313 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
4314 hdd_scaninfo_t *pScanInfo = &pHddCtx->scan_info;
Jeff Johnson295189b2012-06-20 16:38:30 -07004315 struct cfg80211_scan_request *req = NULL;
4316 int ret = 0;
4317
4318 ENTER();
4319
4320 hddLog(VOS_TRACE_LEVEL_INFO,
4321 "%s called with halHandle = %p, pContext = %p,"
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304322 "scanID = %d, returned status = %d\n",
Jeff Johnson295189b2012-06-20 16:38:30 -07004323 __func__, halHandle, pContext, (int) scanId, (int) status);
4324
4325 //Block on scan req completion variable. Can't wait forever though.
4326 ret = wait_for_completion_interruptible_timeout(
4327 &pScanInfo->scan_req_completion_event,
4328 msecs_to_jiffies(WLAN_WAIT_TIME_SCAN_REQ));
4329 if (!ret)
4330 {
4331 VOS_ASSERT(pScanInfo->mScanPending);
Jeff Johnsone7245742012-09-05 17:12:55 -07004332 goto allow_suspend;
Jeff Johnson295189b2012-06-20 16:38:30 -07004333 }
4334
4335 if(pScanInfo->mScanPending != VOS_TRUE)
4336 {
4337 VOS_ASSERT(pScanInfo->mScanPending);
Jeff Johnsone7245742012-09-05 17:12:55 -07004338 goto allow_suspend;
Jeff Johnson295189b2012-06-20 16:38:30 -07004339 }
4340
4341 /* Check the scanId */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304342 if (pScanInfo->scanId != scanId)
Jeff Johnson295189b2012-06-20 16:38:30 -07004343 {
4344 hddLog(VOS_TRACE_LEVEL_INFO,
4345 "%s called with mismatched scanId pScanInfo->scanId = %d "
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304346 "scanId = %d \n", __func__, (int) pScanInfo->scanId,
Jeff Johnson295189b2012-06-20 16:38:30 -07004347 (int) scanId);
4348 }
4349
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304350 ret = wlan_hdd_cfg80211_update_bss((WLAN_HDD_GET_CTX(pAdapter))->wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07004351 pAdapter);
4352
4353 if (0 > ret)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304354 hddLog(VOS_TRACE_LEVEL_INFO, "%s: NO SCAN result", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07004355
4356
4357 /* If any client wait scan result through WEXT
4358 * send scan done event to client */
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004359 if (pHddCtx->scan_info.waitScanResult)
Jeff Johnson295189b2012-06-20 16:38:30 -07004360 {
4361 /* The other scan request waiting for current scan finish
4362 * Send event to notify current scan finished */
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004363 if(WEXT_SCAN_PENDING_DELAY == pHddCtx->scan_info.scan_pending_option)
Jeff Johnson295189b2012-06-20 16:38:30 -07004364 {
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004365 vos_event_set(&pHddCtx->scan_info.scan_finished_event);
Jeff Johnson295189b2012-06-20 16:38:30 -07004366 }
4367 /* Send notify to WEXT client */
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004368 else if(WEXT_SCAN_PENDING_PIGGYBACK == pHddCtx->scan_info.scan_pending_option)
Jeff Johnson295189b2012-06-20 16:38:30 -07004369 {
4370 struct net_device *dev = pAdapter->dev;
4371 union iwreq_data wrqu;
4372 int we_event;
4373 char *msg;
4374
4375 memset(&wrqu, '\0', sizeof(wrqu));
4376 we_event = SIOCGIWSCAN;
4377 msg = NULL;
4378 wireless_send_event(dev, we_event, &wrqu, msg);
4379 }
4380 }
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004381 pHddCtx->scan_info.waitScanResult = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004382
4383 /* Get the Scan Req */
4384 req = pAdapter->request;
4385
4386 if (!req)
4387 {
4388 hddLog(VOS_TRACE_LEVEL_ERROR, "request is became NULL\n");
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07004389 pScanInfo->mScanPending = VOS_FALSE;
Jeff Johnsone7245742012-09-05 17:12:55 -07004390 goto allow_suspend;
Jeff Johnson295189b2012-06-20 16:38:30 -07004391 }
4392
4393 /*
4394 * setting up 0, just in case.
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304395 */
Jeff Johnson295189b2012-06-20 16:38:30 -07004396 req->n_ssids = 0;
4397 req->n_channels = 0;
4398 req->ie = 0;
4399
Jeff Johnson295189b2012-06-20 16:38:30 -07004400 pAdapter->request = NULL;
Jeff Johnsone7245742012-09-05 17:12:55 -07004401 /* Scan is no longer pending */
4402 pScanInfo->mScanPending = VOS_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004403
Madan Mohan Koyyalamudib764bf82012-10-11 16:38:51 -07004404 /*
4405 * cfg80211_scan_done informing NL80211 about completion
4406 * of scanning
4407 */
4408 cfg80211_scan_done(req, false);
Madan Mohan Koyyalamudif4e81002012-11-13 10:46:38 -08004409 complete(&pScanInfo->abortscan_event_var);
Jeff Johnson295189b2012-06-20 16:38:30 -07004410
Jeff Johnsone7245742012-09-05 17:12:55 -07004411allow_suspend:
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07004412 /* release the wake lock at the end of the scan*/
4413 hdd_allow_suspend();
Jeff Johnsone7245742012-09-05 17:12:55 -07004414
Madan Mohan Koyyalamudi10d83a92012-09-28 15:47:05 -07004415 /* Acquire wakelock to handle the case where APP's tries to suspend
4416 * immediatly after the driver gets connect request(i.e after scan)
4417 * from supplicant, this result in app's is suspending and not able
4418 * to process the connect request to AP */
Amar Singhal6144c002013-05-03 16:11:42 -07004419 hdd_allow_suspend_timeout(1000);
Madan Mohan Koyyalamudi10d83a92012-09-28 15:47:05 -07004420
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07004421#ifdef FEATURE_WLAN_TDLS
4422 wlan_hdd_tdls_scan_done_callback(pAdapter);
4423#endif
4424
Jeff Johnson295189b2012-06-20 16:38:30 -07004425 EXIT();
4426 return 0;
4427}
4428
4429/*
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004430 * FUNCTION: hdd_isScanAllowed
4431 * Go through each adapter and check if scan allowed
4432 *
4433 */
4434v_BOOL_t hdd_isScanAllowed( hdd_context_t *pHddCtx )
4435{
4436 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
4437 hdd_station_ctx_t *pHddStaCtx = NULL;
4438 hdd_adapter_t *pAdapter = NULL;
4439 VOS_STATUS status = 0;
4440 v_U8_t staId = 0;
4441 v_U8_t *staMac = NULL;
4442
4443 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
4444
4445 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
4446 {
4447 pAdapter = pAdapterNode->pAdapter;
4448
4449 if( pAdapter )
4450 {
4451 hddLog(VOS_TRACE_LEVEL_INFO,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304452 "%s: Adapter with device mode %d exists",
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004453 __func__, pAdapter->device_mode);
4454 if ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
4455 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) ||
4456 (WLAN_HDD_P2P_DEVICE == pAdapter->device_mode))
4457 {
4458 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
4459 if ((eConnectionState_Associated == pHddStaCtx->conn_info.connState) &&
4460 (VOS_FALSE == pHddStaCtx->conn_info.uIsAuthenticated))
4461 {
4462 staMac = (v_U8_t *) &(pAdapter->macAddressCurrent.bytes[0]);
4463 hddLog(VOS_TRACE_LEVEL_ERROR,
4464 "%s: client %02x:%02x:%02x:%02x:%02x:%02x is in the "
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304465 "middle of WPS/EAPOL exchange.", __func__,
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004466 staMac[0], staMac[1], staMac[2],
4467 staMac[3], staMac[4], staMac[5]);
4468 return VOS_FALSE;
4469 }
4470 }
4471 else if ((WLAN_HDD_SOFTAP == pAdapter->device_mode) ||
4472 (WLAN_HDD_P2P_GO == pAdapter->device_mode))
4473 {
4474 for (staId = 0; staId < WLAN_MAX_STA_COUNT; staId++)
4475 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304476 if ((pAdapter->aStaInfo[staId].isUsed) &&
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004477 (WLANTL_STA_CONNECTED == pAdapter->aStaInfo[staId].tlSTAState))
4478 {
4479 staMac = (v_U8_t *) &(pAdapter->aStaInfo[staId].macAddrSTA.bytes[0]);
4480
4481 hddLog(VOS_TRACE_LEVEL_ERROR,
4482 "%s: client %02x:%02x:%02x:%02x:%02x:%02x of SoftAP/P2P-GO is in the "
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304483 "middle of WPS/EAPOL exchange.", __func__,
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004484 staMac[0], staMac[1], staMac[2],
4485 staMac[3], staMac[4], staMac[5]);
4486 return VOS_FALSE;
4487 }
4488 }
4489 }
4490 }
4491 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
4492 pAdapterNode = pNext;
4493 }
4494 hddLog(VOS_TRACE_LEVEL_INFO,
4495 "%s: Scan allowed", __func__);
4496 return VOS_TRUE;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304497}
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004498
4499/*
Jeff Johnson295189b2012-06-20 16:38:30 -07004500 * FUNCTION: wlan_hdd_cfg80211_scan
4501 * this scan respond to scan trigger and update cfg80211 scan database
4502 * later, scan dump command can be used to recieve scan results
4503 */
Jeff Johnson3bbe4bf2013-01-18 17:05:29 -08004504int wlan_hdd_cfg80211_scan( struct wiphy *wiphy,
4505#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
4506 struct net_device *dev,
4507#endif
4508 struct cfg80211_scan_request *request)
4509{
4510#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
4511 struct net_device *dev = request->wdev->netdev;
4512#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304513 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Jeff Johnson295189b2012-06-20 16:38:30 -07004514 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
4515 hdd_wext_state_t *pwextBuf = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05304516 hdd_config_t *cfg_param = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004517 tCsrScanRequest scanRequest;
4518 tANI_U8 *channelList = NULL, i;
4519 v_U32_t scanId = 0;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05304520 int status;
4521 hdd_scaninfo_t *pScanInfo = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004522 v_U8_t* pP2pIe = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004523
4524 ENTER();
4525
4526 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
4527 __func__,pAdapter->device_mode);
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004528
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05304529 status = wlan_hdd_validate_context(pHddCtx);
4530
4531 if (0 != status)
4532 {
4533 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
4534 "%s: HDD context is not valid", __func__);
4535 return status;
4536 }
4537
4538 cfg_param = pHddCtx->cfg_ini;
4539 pScanInfo = &pHddCtx->scan_info;
4540
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004541 if ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) &&
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004542 (eConnectionState_Connecting ==
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004543 (WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))->conn_info.connState))
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004544 {
4545 hddLog(VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08004546 "%s: %p(%d) Connection in progress: Scan request denied (EBUSY)", __func__, \
4547 WLAN_HDD_GET_STATION_CTX_PTR(pAdapter), pAdapter->sessionId);
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004548 return -EBUSY;
4549 }
4550
Jeff Johnson295189b2012-06-20 16:38:30 -07004551#ifdef WLAN_BTAMP_FEATURE
4552 //Scan not supported when AMP traffic is on.
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004553 if (VOS_TRUE == WLANBAP_AmpSessionOn())
Jeff Johnson295189b2012-06-20 16:38:30 -07004554 {
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004555 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07004556 "%s: No scanning when AMP is on", __func__);
4557 return -EOPNOTSUPP;
4558 }
4559#endif
4560 //Scan on any other interface is not supported.
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004561 if (pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07004562 {
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004563 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07004564 "%s: Not scanning on device_mode = %d",
4565 __func__, pAdapter->device_mode);
4566 return -EOPNOTSUPP;
4567 }
4568
4569 if (TRUE == pScanInfo->mScanPending)
4570 {
4571 hddLog(VOS_TRACE_LEVEL_INFO, "%s: mScanPending is TRUE", __func__);
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004572 return -EBUSY;
Jeff Johnson295189b2012-06-20 16:38:30 -07004573 }
4574
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304575 //Don't Allow Scan and return busy if Remain On
Jeff Johnson32d95a32012-09-10 13:15:23 -07004576 //Channel and action frame is pending
4577 //Otherwise Cancel Remain On Channel and allow Scan
4578 //If no action frame pending
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004579 if (0 != wlan_hdd_check_remain_on_channel(pAdapter))
Jeff Johnson32d95a32012-09-10 13:15:23 -07004580 {
4581 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Remain On Channel Pending", __func__);
4582 return -EBUSY;
4583 }
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004584#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07004585 /* if tdls disagree scan right now, return immediately.
4586 tdls will schedule the scan when scan is allowed. (return SUCCESS)
4587 or will reject the scan if any TDLS is in progress. (return -EBUSY)
4588 */
4589 status = wlan_hdd_tdls_scan_callback (pAdapter,
4590 wiphy,
4591#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
4592 dev,
Gopichand Nakkalac3c42b92013-03-20 19:42:34 -07004593#endif
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07004594 request);
4595 if(status <= 0)
4596 {
4597 hddLog(VOS_TRACE_LEVEL_INFO, "%s: TDLS Pending %d", __func__, status);
4598 return status;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004599 }
4600#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -07004601
Jeff Johnson295189b2012-06-20 16:38:30 -07004602 if (mutex_lock_interruptible(&pHddCtx->tmInfo.tmOperationLock))
4603 {
4604 VOS_TRACE(VOS_MODULE_ID_HDD,VOS_TRACE_LEVEL_ERROR,
Jeff Johnson1250df42012-12-10 14:31:52 -08004605 "%s: Acquire lock fail", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07004606 return -EAGAIN;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304607 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004608 if (TRUE == pHddCtx->tmInfo.tmAction.enterImps)
4609 {
4610 hddLog(VOS_TRACE_LEVEL_WARN,
4611 "%s: MAX TM Level Scan not allowed", __func__);
4612 mutex_unlock(&pHddCtx->tmInfo.tmOperationLock);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304613 return -EBUSY;
Jeff Johnson295189b2012-06-20 16:38:30 -07004614 }
4615 mutex_unlock(&pHddCtx->tmInfo.tmOperationLock);
4616
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004617 /* Check if scan is allowed at this point of time.
4618 */
4619 if (!hdd_isScanAllowed(pHddCtx))
4620 {
4621 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Scan not allowed", __func__);
4622 return -EBUSY;
4623 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304624
Jeff Johnson295189b2012-06-20 16:38:30 -07004625 vos_mem_zero( &scanRequest, sizeof(scanRequest));
4626
4627 if (NULL != request)
4628 {
4629 hddLog(VOS_TRACE_LEVEL_INFO, "scan request for ssid = %d",
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304630 (int)request->n_ssids);
Jeff Johnson295189b2012-06-20 16:38:30 -07004631
4632 /* Even though supplicant doesn't provide any SSIDs, n_ssids is set to 1.
4633 * Becasue of this, driver is assuming that this is not wildcard scan and so
4634 * is not aging out the scan results.
4635 */
Jeff Johnson32d95a32012-09-10 13:15:23 -07004636 if (request->ssids && '\0' == request->ssids->ssid[0])
Jeff Johnson295189b2012-06-20 16:38:30 -07004637 {
4638 request->n_ssids = 0;
4639 }
4640
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07004641 if ((request->ssids) && (0 < request->n_ssids))
Jeff Johnson295189b2012-06-20 16:38:30 -07004642 {
4643 tCsrSSIDInfo *SsidInfo;
4644 int j;
4645 scanRequest.SSIDs.numOfSSIDs = request->n_ssids;
4646 /* Allocate num_ssid tCsrSSIDInfo structure */
4647 SsidInfo = scanRequest.SSIDs.SSIDList =
4648 ( tCsrSSIDInfo *)vos_mem_malloc(
4649 request->n_ssids*sizeof(tCsrSSIDInfo));
4650
4651 if(NULL == scanRequest.SSIDs.SSIDList)
4652 {
4653 hddLog(VOS_TRACE_LEVEL_ERROR,
4654 "memory alloc failed SSIDInfo buffer");
4655 return -ENOMEM;
4656 }
4657
4658 /* copy all the ssid's and their length */
4659 for(j = 0; j < request->n_ssids; j++, SsidInfo++)
4660 {
4661 /* get the ssid length */
4662 SsidInfo->SSID.length = request->ssids[j].ssid_len;
4663 vos_mem_copy(SsidInfo->SSID.ssId, &request->ssids[j].ssid[0],
4664 SsidInfo->SSID.length);
4665 SsidInfo->SSID.ssId[SsidInfo->SSID.length] = '\0';
4666 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "SSID number %d: %s",
4667 j, SsidInfo->SSID.ssId);
4668 }
4669 /* set the scan type to active */
4670 scanRequest.scanType = eSIR_ACTIVE_SCAN;
4671 }
4672 else if(WLAN_HDD_P2P_GO == pAdapter->device_mode)
4673 {
4674 /* set the scan type to active */
4675 scanRequest.scanType = eSIR_ACTIVE_SCAN;
4676 }
4677 else
4678 {
4679 /*Set the scan type to default type, in this case it is ACTIVE*/
4680 scanRequest.scanType = pScanInfo->scan_mode;
4681 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304682 scanRequest.minChnTime = cfg_param->nActiveMinChnTime;
Jeff Johnson295189b2012-06-20 16:38:30 -07004683 scanRequest.maxChnTime = cfg_param->nActiveMaxChnTime;
4684 }
4685 else
4686 {
4687 /* set the scan type to active */
4688 scanRequest.scanType = eSIR_ACTIVE_SCAN;
4689 vos_mem_set( scanRequest.bssid, sizeof( tCsrBssid ), 0xff );
4690
4691 /* set min and max channel time to zero */
4692 scanRequest.minChnTime = 0;
4693 scanRequest.maxChnTime = 0;
4694 }
4695
4696 /* set BSSType to default type */
4697 scanRequest.BSSType = eCSR_BSS_TYPE_ANY;
4698
4699 /*TODO: scan the requested channels only*/
4700
4701 /*Right now scanning all the channels */
4702 if( request )
4703 {
4704 if( request->n_channels )
4705 {
4706 channelList = vos_mem_malloc( request->n_channels );
4707 if( NULL == channelList )
4708 {
4709 status = -ENOMEM;
4710 goto free_mem;
4711 }
4712
4713 for( i = 0 ; i < request->n_channels ; i++ )
4714 channelList[i] = request->channels[i]->hw_value;
4715 }
4716
4717 scanRequest.ChannelInfo.numOfChannels = request->n_channels;
4718 scanRequest.ChannelInfo.ChannelList = channelList;
4719
4720 /* set requestType to full scan */
4721 scanRequest.requestType = eCSR_SCAN_REQUEST_FULL_SCAN;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304722
4723 /* Flush the scan results(only p2p beacons) for STA scan and P2P
Madan Mohan Koyyalamudi8d50f312012-11-27 15:48:57 -08004724 * search (Flush on both full scan and social scan but not on single
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304725 * channel scan).P2P search happens on 3 social channels (1, 6, 11)
Madan Mohan Koyyalamudi8d50f312012-11-27 15:48:57 -08004726 */
4727
4728 /* Supplicant does single channel scan after 8-way handshake
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304729 * and in that case driver shoudnt flush scan results. If
4730 * driver flushes the scan results here and unfortunately if
4731 * the AP doesnt respond to our probe req then association
Madan Mohan Koyyalamudi8d50f312012-11-27 15:48:57 -08004732 * fails which is not desired
4733 */
4734
4735 if( request->n_channels != WLAN_HDD_P2P_SINGLE_CHANNEL_SCAN )
4736 {
4737 sme_ScanFlushP2PResult( WLAN_HDD_GET_HAL_CTX(pAdapter),
4738 pAdapter->sessionId );
4739 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004740
4741 if( request->ie_len )
4742 {
4743 /* save this for future association (join requires this) */
4744 memset( &pScanInfo->scanAddIE, 0, sizeof(pScanInfo->scanAddIE) );
4745 memcpy( pScanInfo->scanAddIE.addIEdata, request->ie, request->ie_len);
4746 pScanInfo->scanAddIE.length = request->ie_len;
4747
4748 if((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
Jeff Johnsone7245742012-09-05 17:12:55 -07004749 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) ||
4750 (WLAN_HDD_P2P_DEVICE == pAdapter->device_mode)
Jeff Johnson295189b2012-06-20 16:38:30 -07004751 )
4752 {
4753 pwextBuf->roamProfile.pAddIEScan = pScanInfo->scanAddIE.addIEdata;
4754 pwextBuf->roamProfile.nAddIEScanLength = pScanInfo->scanAddIE.length;
4755 }
4756
4757 scanRequest.uIEFieldLen = pScanInfo->scanAddIE.length;
4758 scanRequest.pIEField = pScanInfo->scanAddIE.addIEdata;
4759
Jeff Johnson295189b2012-06-20 16:38:30 -07004760 pP2pIe = wlan_hdd_get_p2p_ie_ptr((v_U8_t*)request->ie,
4761 request->ie_len);
4762 if (pP2pIe != NULL)
4763 {
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07004764#ifdef WLAN_FEATURE_P2P_DEBUG
4765 if (((globalP2PConnectionStatus == P2P_GO_NEG_COMPLETED) ||
4766 (globalP2PConnectionStatus == P2P_GO_NEG_PROCESS)) &&
4767 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
4768 {
4769 globalP2PConnectionStatus = P2P_CLIENT_CONNECTING_STATE_1;
4770 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P State] Changing state from "
4771 "Go nego completed to Connection is started");
4772 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P]P2P Scanning is started "
4773 "for 8way Handshake");
4774 }
4775 else if((globalP2PConnectionStatus == P2P_CLIENT_DISCONNECTED_STATE) &&
4776 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
4777 {
4778 globalP2PConnectionStatus = P2P_CLIENT_CONNECTING_STATE_2;
4779 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P State] Changing state from "
4780 "Disconnected state to Connection is started");
4781 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P]P2P Scanning is started "
4782 "for 4way Handshake");
4783 }
4784#endif
4785
Jeff Johnsone7245742012-09-05 17:12:55 -07004786 /* no_cck will be set during p2p find to disable 11b rates */
4787 if(TRUE == request->no_cck)
Jeff Johnson295189b2012-06-20 16:38:30 -07004788 {
Jeff Johnson295189b2012-06-20 16:38:30 -07004789 hddLog(VOS_TRACE_LEVEL_INFO,
4790 "%s: This is a P2P Search", __func__);
4791 scanRequest.p2pSearch = 1;
Jeff Johnsone7245742012-09-05 17:12:55 -07004792
Jeff Johnsone7245742012-09-05 17:12:55 -07004793 if( request->n_channels == WLAN_HDD_P2P_SOCIAL_CHANNELS )
4794 {
Madan Mohan Koyyalamudi1b1d9e82012-10-21 11:38:33 -07004795 /* set requestType to P2P Discovery */
4796 scanRequest.requestType = eCSR_SCAN_P2P_DISCOVERY;
Jeff Johnsone7245742012-09-05 17:12:55 -07004797 }
4798
4799 /*
4800 Skip Dfs Channel in case of P2P Search
4801 if it is set in ini file
4802 */
4803 if(cfg_param->skipDfsChnlInP2pSearch)
4804 {
4805 scanRequest.skipDfsChnlInP2pSearch = 1;
4806 }
4807 else
4808 {
4809 scanRequest.skipDfsChnlInP2pSearch = 0;
4810 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004811
Jeff Johnson295189b2012-06-20 16:38:30 -07004812 }
4813 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004814 }
4815 }
4816
4817 INIT_COMPLETION(pScanInfo->scan_req_completion_event);
4818
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07004819 /* acquire the wakelock to avoid the apps suspend during the scan. To
4820 * address the following issues.
4821 * 1) Disconnected scenario: we are not allowing the suspend as WLAN is not in
4822 * BMPS/IMPS this result in android trying to suspend aggressively and backing off
4823 * for long time, this result in apps running at full power for long time.
4824 * 2) Connected scenario: If we allow the suspend during the scan, RIVA will
4825 * be stuck in full power because of resume BMPS
4826 */
4827 hdd_prevent_suspend();
Jeff Johnsone7245742012-09-05 17:12:55 -07004828
4829 status = sme_ScanRequest( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07004830 pAdapter->sessionId, &scanRequest, &scanId,
4831 &hdd_cfg80211_scan_done_callback, dev );
Jeff Johnsone7245742012-09-05 17:12:55 -07004832
Jeff Johnson295189b2012-06-20 16:38:30 -07004833 if (eHAL_STATUS_SUCCESS != status)
4834 {
4835 hddLog(VOS_TRACE_LEVEL_ERROR,
4836 "%s: sme_ScanRequest returned error %d", __func__, status);
4837 complete(&pScanInfo->scan_req_completion_event);
Madan Mohan Koyyalamudi3b230fe2012-10-18 14:46:32 -07004838 if(eHAL_STATUS_RESOURCES == status)
4839 {
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07004840 hddLog(VOS_TRACE_LEVEL_INFO, "%s: HO is in progress.So defer the scan by informing busy",__func__);
Madan Mohan Koyyalamudi3b230fe2012-10-18 14:46:32 -07004841 status = -EBUSY;
4842 } else {
4843 status = -EIO;
4844 }
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07004845 hdd_allow_suspend();
Jeff Johnson295189b2012-06-20 16:38:30 -07004846 goto free_mem;
4847 }
4848
4849 pScanInfo->mScanPending = TRUE;
4850 pAdapter->request = request;
4851 pScanInfo->scanId = scanId;
4852
4853 complete(&pScanInfo->scan_req_completion_event);
4854
4855free_mem:
4856 if( scanRequest.SSIDs.SSIDList )
4857 {
4858 vos_mem_free(scanRequest.SSIDs.SSIDList);
4859 }
4860
4861 if( channelList )
4862 vos_mem_free( channelList );
4863
4864 EXIT();
4865
4866 return status;
4867}
4868
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07004869
4870void hdd_select_cbmode( hdd_adapter_t *pAdapter,v_U8_t operationChannel)
4871{
4872 v_U8_t iniDot11Mode =
4873 (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini->dot11Mode;
4874 eHddDot11Mode hddDot11Mode = iniDot11Mode;
4875
4876 switch ( iniDot11Mode )
4877 {
4878 case eHDD_DOT11_MODE_AUTO:
4879 case eHDD_DOT11_MODE_11ac:
4880 case eHDD_DOT11_MODE_11ac_ONLY:
4881#ifdef WLAN_FEATURE_11AC
4882 hddDot11Mode = eHDD_DOT11_MODE_11ac;
4883#else
4884 hddDot11Mode = eHDD_DOT11_MODE_11n;
4885#endif
4886 break;
4887 case eHDD_DOT11_MODE_11n:
4888 case eHDD_DOT11_MODE_11n_ONLY:
4889 hddDot11Mode = eHDD_DOT11_MODE_11n;
4890 break;
4891 default:
4892 hddDot11Mode = iniDot11Mode;
4893 break;
4894 }
4895 /* This call decides required channel bonding mode */
4896 sme_SelectCBMode((WLAN_HDD_GET_CTX(pAdapter)->hHal),
4897 hdd_cfg_xlate_to_csr_phy_mode(hddDot11Mode),
4898 operationChannel);
4899}
4900
Jeff Johnson295189b2012-06-20 16:38:30 -07004901/*
4902 * FUNCTION: wlan_hdd_cfg80211_connect_start
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304903 * This function is used to start the association process
Jeff Johnson295189b2012-06-20 16:38:30 -07004904 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304905int wlan_hdd_cfg80211_connect_start( hdd_adapter_t *pAdapter,
Jeff Johnson32d95a32012-09-10 13:15:23 -07004906 const u8 *ssid, size_t ssid_len, const u8 *bssid, u8 operatingChannel)
Jeff Johnson295189b2012-06-20 16:38:30 -07004907{
4908 int status = 0;
4909 hdd_wext_state_t *pWextState;
4910 v_U32_t roamId;
4911 tCsrRoamProfile *pRoamProfile;
4912 eMib_dot11DesiredBssType connectedBssType;
4913 eCsrAuthType RSNAuthType;
4914
4915 ENTER();
4916
4917 pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304918
Jeff Johnson295189b2012-06-20 16:38:30 -07004919 if (SIR_MAC_MAX_SSID_LENGTH < ssid_len)
4920 {
4921 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: wrong SSID len", __func__);
4922 return -EINVAL;
4923 }
4924
4925 pRoamProfile = &pWextState->roamProfile;
4926
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304927 if (pRoamProfile)
Jeff Johnson295189b2012-06-20 16:38:30 -07004928 {
Jeff Johnsone7245742012-09-05 17:12:55 -07004929 int ret = 0;
4930 hdd_station_ctx_t *pHddStaCtx;
4931 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
4932 hdd_connGetConnectedBssType(pHddStaCtx,&connectedBssType );
4933
4934 if((eMib_dot11DesiredBssType_independent == connectedBssType) ||
4935 (eConnectionState_Associated == pHddStaCtx->conn_info.connState) ||
4936 (eConnectionState_IbssConnected == pHddStaCtx->conn_info.connState))
Jeff Johnson295189b2012-06-20 16:38:30 -07004937 {
4938 /* Issue disconnect to CSR */
4939 INIT_COMPLETION(pAdapter->disconnect_comp_var);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304940 if( eHAL_STATUS_SUCCESS ==
Jeff Johnson295189b2012-06-20 16:38:30 -07004941 sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
4942 pAdapter->sessionId,
4943 eCSR_DISCONNECT_REASON_UNSPECIFIED ) )
4944 {
Jeff Johnsone7245742012-09-05 17:12:55 -07004945 ret = wait_for_completion_interruptible_timeout(
4946 &pAdapter->disconnect_comp_var,
4947 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
4948 if (0 == ret)
4949 {
4950 VOS_ASSERT(0);
4951 }
4952 }
4953 }
4954 else if(eConnectionState_Disconnecting == pHddStaCtx->conn_info.connState)
4955 {
4956 ret = wait_for_completion_interruptible_timeout(
4957 &pAdapter->disconnect_comp_var,
4958 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
4959 if (0 == ret)
4960 {
4961 VOS_ASSERT(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004962 }
4963 }
4964
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304965 if (HDD_WMM_USER_MODE_NO_QOS ==
Jeff Johnson295189b2012-06-20 16:38:30 -07004966 (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini->WmmMode)
4967 {
4968 /*QoS not enabled in cfg file*/
4969 pRoamProfile->uapsd_mask = 0;
4970 }
4971 else
4972 {
4973 /*QoS enabled, update uapsd mask from cfg file*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304974 pRoamProfile->uapsd_mask =
Jeff Johnson295189b2012-06-20 16:38:30 -07004975 (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini->UapsdMask;
4976 }
4977
4978 pRoamProfile->SSIDs.numOfSSIDs = 1;
4979 pRoamProfile->SSIDs.SSIDList->SSID.length = ssid_len;
4980 vos_mem_zero(pRoamProfile->SSIDs.SSIDList->SSID.ssId,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304981 sizeof(pRoamProfile->SSIDs.SSIDList->SSID.ssId));
Jeff Johnson295189b2012-06-20 16:38:30 -07004982 vos_mem_copy((void *)(pRoamProfile->SSIDs.SSIDList->SSID.ssId),
4983 ssid, ssid_len);
4984
4985 if (bssid)
4986 {
4987 pRoamProfile->BSSIDs.numOfBSSIDs = 1;
4988 vos_mem_copy((void *)(pRoamProfile->BSSIDs.bssid), bssid,
4989 WNI_CFG_BSSID_LEN);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05304990 /* Save BSSID in seperate variable as well, as RoamProfile
4991 BSSID is getting zeroed out in the association process. And in
Jeff Johnson295189b2012-06-20 16:38:30 -07004992 case of join failure we should send valid BSSID to supplicant
4993 */
4994 vos_mem_copy((void *)(pWextState->req_bssId), bssid,
4995 WNI_CFG_BSSID_LEN);
4996 }
Dhanashri Atre51981c62013-06-13 11:47:57 -07004997 else
4998 {
4999 vos_mem_zero((void *)(pRoamProfile->BSSIDs.bssid),WNI_CFG_BSSID_LEN);
5000 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005001
5002 if ((IW_AUTH_WPA_VERSION_WPA == pWextState->wpaVersion) ||
5003 (IW_AUTH_WPA_VERSION_WPA2 == pWextState->wpaVersion))
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305004 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005005 /*set gen ie*/
5006 hdd_SetGENIEToCsr(pAdapter, &RSNAuthType);
5007 /*set auth*/
5008 hdd_set_csr_auth_type(pAdapter, RSNAuthType);
5009 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005010#ifdef FEATURE_WLAN_WAPI
5011 if (pAdapter->wapi_info.nWapiMode)
5012 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005013 hddLog(LOG1, "%s: Setting WAPI AUTH Type and Encryption Mode values", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005014 switch (pAdapter->wapi_info.wapiAuthMode)
5015 {
5016 case WAPI_AUTH_MODE_PSK:
5017 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005018 hddLog(LOG1, "%s: WAPI AUTH TYPE: PSK: %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07005019 pAdapter->wapi_info.wapiAuthMode);
5020 pRoamProfile->AuthType.authType[0] = eCSR_AUTH_TYPE_WAPI_WAI_PSK;
5021 break;
5022 }
5023 case WAPI_AUTH_MODE_CERT:
5024 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005025 hddLog(LOG1, "%s: WAPI AUTH TYPE: CERT: %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07005026 pAdapter->wapi_info.wapiAuthMode);
5027 pRoamProfile->AuthType.authType[0] = eCSR_AUTH_TYPE_WAPI_WAI_CERTIFICATE;
5028 break;
5029 }
5030 } // End of switch
5031 if ( pAdapter->wapi_info.wapiAuthMode == WAPI_AUTH_MODE_PSK ||
5032 pAdapter->wapi_info.wapiAuthMode == WAPI_AUTH_MODE_CERT)
5033 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005034 hddLog(LOG1, "%s: WAPI PAIRWISE/GROUP ENCRYPTION: WPI", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005035 pRoamProfile->AuthType.numEntries = 1;
5036 pRoamProfile->EncryptionType.numEntries = 1;
5037 pRoamProfile->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_WPI;
5038 pRoamProfile->mcEncryptionType.numEntries = 1;
5039 pRoamProfile->mcEncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_WPI;
5040 }
5041 }
5042#endif /* FEATURE_WLAN_WAPI */
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05305043#ifdef WLAN_FEATURE_GTK_OFFLOAD
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05305044 /* Initializing gtkOffloadReqParams */
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05305045 if ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
5046 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
5047 {
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05305048 memset(&pHddStaCtx->gtkOffloadReqParams, 0,
5049 sizeof (tSirGtkOffloadParams));
5050 pHddStaCtx->gtkOffloadReqParams.ulFlags = GTK_OFFLOAD_DISABLE;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05305051 }
5052#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005053 pRoamProfile->csrPersona = pAdapter->device_mode;
5054
Jeff Johnson32d95a32012-09-10 13:15:23 -07005055 if( operatingChannel )
5056 {
5057 pRoamProfile->ChannelInfo.ChannelList = &operatingChannel;
5058 pRoamProfile->ChannelInfo.numOfChannels = 1;
5059 }
Chet Lanctot186b5732013-03-18 10:26:30 -07005060 else
5061 {
5062 pRoamProfile->ChannelInfo.ChannelList = NULL;
5063 pRoamProfile->ChannelInfo.numOfChannels = 0;
5064 }
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07005065 if ( (WLAN_HDD_IBSS == pAdapter->device_mode) && operatingChannel)
5066 {
5067 hdd_select_cbmode(pAdapter,operatingChannel);
5068 }
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08005069 /* change conn_state to connecting before sme_RoamConnect(), because sme_RoamConnect()
5070 * has a direct path to call hdd_smeRoamCallback(), which will change the conn_state
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305071 * If direct path, conn_state will be accordingly changed to NotConnected or Associated
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08005072 * by either hdd_AssociationCompletionHandler() or hdd_DisConnectHandler() in sme_RoamCallback()
Madan Mohan Koyyalamudidf86c422012-12-04 17:03:44 -08005073 * if sme_RomConnect is to be queued, Connecting state will remain until it is completed.
5074 */
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +05305075 if (WLAN_HDD_INFRA_STATION == pAdapter->device_mode ||
5076 WLAN_HDD_P2P_CLIENT == pAdapter->device_mode)
Madan Mohan Koyyalamudidf86c422012-12-04 17:03:44 -08005077 hdd_connSetConnectionState(WLAN_HDD_GET_STATION_CTX_PTR(pAdapter),
5078 eConnectionState_Connecting);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305079
5080 status = sme_RoamConnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07005081 pAdapter->sessionId, pRoamProfile, &roamId);
5082
Gopichand Nakkalaa3c8fb62013-06-21 15:36:42 +05305083 if ((eHAL_STATUS_SUCCESS != status) &&
5084 (WLAN_HDD_INFRA_STATION == pAdapter->device_mode ||
5085 WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
Madan Mohan Koyyalamudid5acbf52012-11-28 01:45:08 +05305086
5087 {
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08005088 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: sme_RoamConnect (session %d) failed with "
5089 "status %d. -> NotConnected", __func__, pAdapter->sessionId, status);
5090 /* change back to NotAssociated */
Madan Mohan Koyyalamudid5acbf52012-11-28 01:45:08 +05305091 hdd_connSetConnectionState(WLAN_HDD_GET_STATION_CTX_PTR(pAdapter),
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08005092 eConnectionState_NotConnected);
Madan Mohan Koyyalamudid5acbf52012-11-28 01:45:08 +05305093 }
Madan Mohan Koyyalamudidf86c422012-12-04 17:03:44 -08005094
5095 pRoamProfile->ChannelInfo.ChannelList = NULL;
5096 pRoamProfile->ChannelInfo.numOfChannels = 0;
5097
Jeff Johnson295189b2012-06-20 16:38:30 -07005098 }
5099 else
5100 {
5101 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: No valid Roam profile", __func__);
5102 return -EINVAL;
5103 }
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08005104 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07005105 return status;
5106}
5107
5108/*
5109 * FUNCTION: wlan_hdd_set_cfg80211_auth_type
5110 * This function is used to set the authentication type (OPEN/SHARED).
5111 *
5112 */
5113static int wlan_hdd_cfg80211_set_auth_type(hdd_adapter_t *pAdapter,
5114 enum nl80211_auth_type auth_type)
5115{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305116 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07005117 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
5118
5119 ENTER();
5120
5121 /*set authentication type*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305122 switch (auth_type)
Jeff Johnson295189b2012-06-20 16:38:30 -07005123 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005124 case NL80211_AUTHTYPE_AUTOMATIC:
Gopichand Nakkala29149562013-05-10 21:43:41 +05305125 hddLog(VOS_TRACE_LEVEL_INFO,
5126 "%s: set authentication type to AUTOSWITCH", __func__);
5127 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_AUTOSWITCH;
5128 break;
5129
5130 case NL80211_AUTHTYPE_OPEN_SYSTEM:
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07005131#ifdef WLAN_FEATURE_VOWIFI_11R
5132 case NL80211_AUTHTYPE_FT:
5133#endif /* WLAN_FEATURE_VOWIFI_11R */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305134 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07005135 "%s: set authentication type to OPEN", __func__);
5136 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
5137 break;
5138
5139 case NL80211_AUTHTYPE_SHARED_KEY:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305140 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07005141 "%s: set authentication type to SHARED", __func__);
5142 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_SHARED_KEY;
5143 break;
5144#ifdef FEATURE_WLAN_CCX
5145 case NL80211_AUTHTYPE_NETWORK_EAP:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305146 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07005147 "%s: set authentication type to CCKM WPA", __func__);
5148 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_CCKM_WPA;//eCSR_AUTH_TYPE_CCKM_RSN needs to be handled as well if required.
5149 break;
5150#endif
5151
5152
5153 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305154 hddLog(VOS_TRACE_LEVEL_ERROR,
5155 "%s: Unsupported authentication type %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07005156 auth_type);
5157 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_UNKNOWN;
5158 return -EINVAL;
5159 }
5160
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305161 pWextState->roamProfile.AuthType.authType[0] =
Jeff Johnson295189b2012-06-20 16:38:30 -07005162 pHddStaCtx->conn_info.authType;
5163 return 0;
5164}
5165
5166/*
5167 * FUNCTION: wlan_hdd_set_akm_suite
5168 * This function is used to set the key mgmt type(PSK/8021x).
5169 *
5170 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305171static int wlan_hdd_set_akm_suite( hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07005172 u32 key_mgmt
5173 )
5174{
5175 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
5176 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305177
Jeff Johnson295189b2012-06-20 16:38:30 -07005178 /*set key mgmt type*/
5179 switch(key_mgmt)
5180 {
5181 case WLAN_AKM_SUITE_PSK:
Gopichand Nakkala356fb102013-03-06 12:34:04 +05305182#ifdef WLAN_FEATURE_VOWIFI_11R
5183 case WLAN_AKM_SUITE_FT_PSK:
5184#endif
5185 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting key mgmt type to PSK",
Jeff Johnson295189b2012-06-20 16:38:30 -07005186 __func__);
5187 pWextState->authKeyMgmt |= IW_AUTH_KEY_MGMT_PSK;
5188 break;
5189
5190 case WLAN_AKM_SUITE_8021X:
Gopichand Nakkala356fb102013-03-06 12:34:04 +05305191#ifdef WLAN_FEATURE_VOWIFI_11R
5192 case WLAN_AKM_SUITE_FT_8021X:
5193#endif
5194 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting key mgmt type to 8021x",
Jeff Johnson295189b2012-06-20 16:38:30 -07005195 __func__);
5196 pWextState->authKeyMgmt |= IW_AUTH_KEY_MGMT_802_1X;
5197 break;
5198#ifdef FEATURE_WLAN_CCX
5199#define WLAN_AKM_SUITE_CCKM 0x00409600 /* Should be in ieee802_11_defs.h */
5200#define IW_AUTH_KEY_MGMT_CCKM 8 /* Should be in linux/wireless.h */
5201 case WLAN_AKM_SUITE_CCKM:
5202 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting key mgmt type to CCKM",
5203 __func__);
5204 pWextState->authKeyMgmt |= IW_AUTH_KEY_MGMT_CCKM;
5205 break;
5206#endif
5207
5208 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305209 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported key mgmt type %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005210 __func__, key_mgmt);
5211 return -EINVAL;
5212
5213 }
5214 return 0;
5215}
5216
5217/*
5218 * FUNCTION: wlan_hdd_cfg80211_set_cipher
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305219 * This function is used to set the encryption type
Jeff Johnson295189b2012-06-20 16:38:30 -07005220 * (NONE/WEP40/WEP104/TKIP/CCMP).
5221 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305222static int wlan_hdd_cfg80211_set_cipher( hdd_adapter_t *pAdapter,
5223 u32 cipher,
Jeff Johnson295189b2012-06-20 16:38:30 -07005224 bool ucast
5225 )
5226{
5227 eCsrEncryptionType encryptionType = eCSR_ENCRYPT_TYPE_NONE;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305228 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07005229 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
5230
5231 ENTER();
5232
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305233 if (!cipher)
Jeff Johnson295189b2012-06-20 16:38:30 -07005234 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305235 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: received cipher %d - considering none",
Jeff Johnson295189b2012-06-20 16:38:30 -07005236 __func__, cipher);
5237 encryptionType = eCSR_ENCRYPT_TYPE_NONE;
5238 }
5239 else
5240 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305241
Jeff Johnson295189b2012-06-20 16:38:30 -07005242 /*set encryption method*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305243 switch (cipher)
Jeff Johnson295189b2012-06-20 16:38:30 -07005244 {
5245 case IW_AUTH_CIPHER_NONE:
5246 encryptionType = eCSR_ENCRYPT_TYPE_NONE;
5247 break;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305248
Jeff Johnson295189b2012-06-20 16:38:30 -07005249 case WLAN_CIPHER_SUITE_WEP40:
Gopichand Nakkala29149562013-05-10 21:43:41 +05305250 encryptionType = eCSR_ENCRYPT_TYPE_WEP40;
Jeff Johnson295189b2012-06-20 16:38:30 -07005251 break;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305252
Jeff Johnson295189b2012-06-20 16:38:30 -07005253 case WLAN_CIPHER_SUITE_WEP104:
Gopichand Nakkala29149562013-05-10 21:43:41 +05305254 encryptionType = eCSR_ENCRYPT_TYPE_WEP104;
Jeff Johnson295189b2012-06-20 16:38:30 -07005255 break;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305256
Jeff Johnson295189b2012-06-20 16:38:30 -07005257 case WLAN_CIPHER_SUITE_TKIP:
5258 encryptionType = eCSR_ENCRYPT_TYPE_TKIP;
5259 break;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305260
Jeff Johnson295189b2012-06-20 16:38:30 -07005261 case WLAN_CIPHER_SUITE_CCMP:
5262 encryptionType = eCSR_ENCRYPT_TYPE_AES;
5263 break;
5264#ifdef FEATURE_WLAN_WAPI
5265 case WLAN_CIPHER_SUITE_SMS4:
5266 encryptionType = eCSR_ENCRYPT_TYPE_WPI;
5267 break;
5268#endif
5269
5270#ifdef FEATURE_WLAN_CCX
5271 case WLAN_CIPHER_SUITE_KRK:
5272 encryptionType = eCSR_ENCRYPT_TYPE_KRK;
5273 break;
5274#endif
5275 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305276 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported cipher type %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005277 __func__, cipher);
5278 return -EOPNOTSUPP;
5279 }
5280 }
5281
5282 if (ucast)
5283 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305284 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting unicast cipher type to %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005285 __func__, encryptionType);
5286 pHddStaCtx->conn_info.ucEncryptionType = encryptionType;
5287 pWextState->roamProfile.EncryptionType.numEntries = 1;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305288 pWextState->roamProfile.EncryptionType.encryptionType[0] =
Jeff Johnson295189b2012-06-20 16:38:30 -07005289 encryptionType;
5290 }
5291 else
5292 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305293 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting mcast cipher type to %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005294 __func__, encryptionType);
5295 pHddStaCtx->conn_info.mcEncryptionType = encryptionType;
5296 pWextState->roamProfile.mcEncryptionType.numEntries = 1;
5297 pWextState->roamProfile.mcEncryptionType.encryptionType[0] = encryptionType;
5298 }
5299
5300 return 0;
5301}
5302
5303
5304/*
5305 * FUNCTION: wlan_hdd_cfg80211_set_ie
5306 * This function is used to parse WPA/RSN IE's.
5307 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305308int wlan_hdd_cfg80211_set_ie( hdd_adapter_t *pAdapter,
5309 u8 *ie,
Jeff Johnson295189b2012-06-20 16:38:30 -07005310 size_t ie_len
5311 )
5312{
5313 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
5314 u8 *genie = ie;
5315 v_U16_t remLen = ie_len;
5316#ifdef FEATURE_WLAN_WAPI
5317 v_U32_t akmsuite[MAX_NUM_AKM_SUITES];
5318 u16 *tmp;
5319 v_U16_t akmsuiteCount;
5320 int *akmlist;
5321#endif
5322 ENTER();
5323
5324 /* clear previous assocAddIE */
5325 pWextState->assocAddIE.length = 0;
5326 pWextState->roamProfile.bWPSAssociation = VOS_FALSE;
5327
5328 while (remLen >= 2)
5329 {
5330 v_U16_t eLen = 0;
5331 v_U8_t elementId;
5332 elementId = *genie++;
5333 eLen = *genie++;
5334 remLen -= 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305335
5336 hddLog(VOS_TRACE_LEVEL_INFO, "%s: IE[0x%X], LEN[%d]\n",
Jeff Johnson295189b2012-06-20 16:38:30 -07005337 __func__, elementId, eLen);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305338
5339 switch ( elementId )
Jeff Johnson295189b2012-06-20 16:38:30 -07005340 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305341 case DOT11F_EID_WPA:
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005342 if (4 > eLen) /* should have at least OUI which is 4 bytes so extra 2 bytes not needed */
Jeff Johnson295189b2012-06-20 16:38:30 -07005343 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305344 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005345 "%s: Invalid WPA IE", __func__);
5346 return -EINVAL;
5347 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305348 else if (0 == memcmp(&genie[0], "\x00\x50\xf2\x04", 4))
Jeff Johnson295189b2012-06-20 16:38:30 -07005349 {
5350 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305351 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set WPS IE(len %d)",
Jeff Johnson295189b2012-06-20 16:38:30 -07005352 __func__, eLen + 2);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305353
Jeff Johnson295189b2012-06-20 16:38:30 -07005354 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5355 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005356 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE. "
5357 "Need bigger buffer space");
Jeff Johnson295189b2012-06-20 16:38:30 -07005358 VOS_ASSERT(0);
5359 return -ENOMEM;
5360 }
5361 // WSC IE is saved to Additional IE ; it should be accumulated to handle WPS IE + P2P IE
5362 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5363 pWextState->assocAddIE.length += eLen + 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305364
Jeff Johnson295189b2012-06-20 16:38:30 -07005365 pWextState->roamProfile.bWPSAssociation = VOS_TRUE;
5366 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5367 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5368 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305369 else if (0 == memcmp(&genie[0], "\x00\x50\xf2", 3))
5370 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005371 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set WPA IE (len %d)",__func__, eLen + 2);
5372 memset( pWextState->WPARSNIE, 0, MAX_WPA_RSN_IE_LEN );
5373 memcpy( pWextState->WPARSNIE, genie - 2, (eLen + 2) /*ie_len*/);
5374 pWextState->roamProfile.pWPAReqIE = pWextState->WPARSNIE;
5375 pWextState->roamProfile.nWPAReqIELength = eLen + 2;//ie_len;
5376 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305377 else if ( (0 == memcmp(&genie[0], P2P_OUI_TYPE,
5378 P2P_OUI_TYPE_SIZE))
Jeff Johnson295189b2012-06-20 16:38:30 -07005379 /*Consider P2P IE, only for P2P Client */
5380 && (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) )
5381 {
5382 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305383 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set P2P IE(len %d)",
Jeff Johnson295189b2012-06-20 16:38:30 -07005384 __func__, eLen + 2);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305385
Jeff Johnson295189b2012-06-20 16:38:30 -07005386 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5387 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005388 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
5389 "Need bigger buffer space");
Jeff Johnson295189b2012-06-20 16:38:30 -07005390 VOS_ASSERT(0);
5391 return -ENOMEM;
5392 }
5393 // P2P IE is saved to Additional IE ; it should be accumulated to handle WPS IE + P2P IE
5394 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5395 pWextState->assocAddIE.length += eLen + 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305396
Jeff Johnson295189b2012-06-20 16:38:30 -07005397 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5398 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5399 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005400#ifdef WLAN_FEATURE_WFD
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305401 else if ( (0 == memcmp(&genie[0], WFD_OUI_TYPE,
5402 WFD_OUI_TYPE_SIZE))
Jeff Johnson295189b2012-06-20 16:38:30 -07005403 /*Consider WFD IE, only for P2P Client */
5404 && (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) )
5405 {
5406 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305407 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set WFD IE(len %d)",
Jeff Johnson295189b2012-06-20 16:38:30 -07005408 __func__, eLen + 2);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305409
Jeff Johnson295189b2012-06-20 16:38:30 -07005410 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5411 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005412 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
5413 "Need bigger buffer space");
Jeff Johnson295189b2012-06-20 16:38:30 -07005414 VOS_ASSERT(0);
5415 return -ENOMEM;
5416 }
5417 // WFD IE is saved to Additional IE ; it should be accumulated to handle
5418 // WPS IE + P2P IE + WFD IE
5419 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5420 pWextState->assocAddIE.length += eLen + 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305421
Jeff Johnson295189b2012-06-20 16:38:30 -07005422 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5423 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5424 }
5425#endif
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005426 /* Appending HS 2.0 Indication Element in Assiciation Request */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305427 else if ( (0 == memcmp(&genie[0], HS20_OUI_TYPE,
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005428 HS20_OUI_TYPE_SIZE)) )
5429 {
5430 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305431 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set HS20 IE(len %d)",
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005432 __func__, eLen + 2);
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005433
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005434 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5435 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005436 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
5437 "Need bigger buffer space");
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005438 VOS_ASSERT(0);
5439 return -ENOMEM;
5440 }
5441 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5442 pWextState->assocAddIE.length += eLen + 2;
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005443
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005444 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5445 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5446 }
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005447
Jeff Johnson295189b2012-06-20 16:38:30 -07005448 break;
5449 case DOT11F_EID_RSN:
5450 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set RSN IE(len %d)",__func__, eLen + 2);
5451 memset( pWextState->WPARSNIE, 0, MAX_WPA_RSN_IE_LEN );
5452 memcpy( pWextState->WPARSNIE, genie - 2, (eLen + 2)/*ie_len*/);
5453 pWextState->roamProfile.pRSNReqIE = pWextState->WPARSNIE;
5454 pWextState->roamProfile.nRSNReqIELength = eLen + 2; //ie_len;
5455 break;
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005456 /* Appending Extended Capabilities with Interworking bit set in Assoc Req */
5457 case DOT11F_EID_EXTCAP:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305458 {
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005459 v_U16_t curAddIELen = pWextState->assocAddIE.length;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305460 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set Extended CAPS IE(len %d)",
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005461 __func__, eLen + 2);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305462
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005463 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5464 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005465 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
5466 "Need bigger buffer space");
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005467 VOS_ASSERT(0);
5468 return -ENOMEM;
5469 }
5470 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5471 pWextState->assocAddIE.length += eLen + 2;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305472
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005473 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5474 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5475 break;
5476 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005477#ifdef FEATURE_WLAN_WAPI
5478 case WLAN_EID_WAPI:
5479 pAdapter->wapi_info.nWapiMode = 1; //Setting WAPI Mode to ON=1
5480 hddLog(VOS_TRACE_LEVEL_INFO,"WAPI MODE IS %lu \n",
5481 pAdapter->wapi_info.nWapiMode);
5482 tmp = (u16 *)ie;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305483 tmp = tmp + 2; // Skip element Id and Len, Version
Jeff Johnson295189b2012-06-20 16:38:30 -07005484 akmsuiteCount = WPA_GET_LE16(tmp);
5485 tmp = tmp + 1;
5486 akmlist = (int *)(tmp);
5487 if(akmsuiteCount <= MAX_NUM_AKM_SUITES)
5488 {
5489 memcpy(akmsuite, akmlist, (4*akmsuiteCount));
5490 }
5491 else
5492 {
5493 hddLog(VOS_TRACE_LEVEL_FATAL, "Invalid akmSuite count\n");
5494 VOS_ASSERT(0);
5495 return -EINVAL;
5496 }
5497
5498 if (WAPI_PSK_AKM_SUITE == akmsuite[0])
5499 {
5500 hddLog(VOS_TRACE_LEVEL_INFO, "%s: WAPI AUTH MODE SET TO PSK",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005501 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005502 pAdapter->wapi_info.wapiAuthMode = WAPI_AUTH_MODE_PSK;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305503 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005504 if (WAPI_CERT_AKM_SUITE == akmsuite[0])
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305505 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005506 hddLog(VOS_TRACE_LEVEL_INFO, "%s: WAPI AUTH MODE SET TO CERTIFICATE",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005507 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005508 pAdapter->wapi_info.wapiAuthMode = WAPI_AUTH_MODE_CERT;
5509 }
5510 break;
5511#endif
5512 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305513 hddLog (VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005514 "%s Set UNKNOWN IE %X", __func__, elementId);
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005515 /* when Unknown IE is received we should break and continue
5516 * to the next IE in the buffer instead we were returning
5517 * so changing this to break */
5518 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07005519 }
5520 genie += eLen;
5521 remLen -= eLen;
5522 }
5523 EXIT();
5524 return 0;
5525}
5526
5527/*
Gopichand Nakkala18f0c262013-05-07 23:25:08 +05305528 * FUNCTION: hdd_isWPAIEPresent
5529 * Parse the received IE to find the WPA IE
5530 *
5531 */
5532static bool hdd_isWPAIEPresent(u8 *ie, u8 ie_len)
5533{
5534 v_U8_t eLen = 0;
5535 v_U16_t remLen = ie_len;
5536 v_U8_t elementId = 0;
5537
5538 while (remLen >= 2)
5539 {
5540 elementId = *ie++;
5541 eLen = *ie++;
5542 remLen -= 2;
5543 if (eLen > remLen)
5544 {
5545 hddLog(VOS_TRACE_LEVEL_ERROR,
5546 "%s: IE length is wrong %d", __func__, eLen);
5547 return FALSE;
5548 }
5549 if ((elementId == DOT11F_EID_WPA) && (remLen > 5))
5550 {
5551 /* OUI - 0x00 0X50 0XF2
5552 WPA Information Element - 0x01
5553 WPA version - 0x01*/
5554 if (0 == memcmp(&ie[0], "\x00\x50\xf2\x01\x01", 5))
5555 return TRUE;
5556 }
5557 ie += eLen;
5558 remLen -= eLen;
5559 }
5560 return FALSE;
5561}
5562
5563/*
Jeff Johnson295189b2012-06-20 16:38:30 -07005564 * FUNCTION: wlan_hdd_cfg80211_set_privacy
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305565 * This function is used to initialize the security
Jeff Johnson295189b2012-06-20 16:38:30 -07005566 * parameters during connect operation.
5567 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305568int wlan_hdd_cfg80211_set_privacy( hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07005569 struct cfg80211_connect_params *req
5570 )
5571{
5572 int status = 0;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305573 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07005574 ENTER();
5575
5576 /*set wpa version*/
5577 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_DISABLED;
5578
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305579 if (req->crypto.wpa_versions)
Jeff Johnson295189b2012-06-20 16:38:30 -07005580 {
Gopichand Nakkala781ded42013-06-28 12:10:45 +05305581 if (NL80211_WPA_VERSION_1 == req->crypto.wpa_versions)
Jeff Johnson295189b2012-06-20 16:38:30 -07005582 {
5583 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA;
5584 }
5585 else if (NL80211_WPA_VERSION_2 == req->crypto.wpa_versions)
5586 {
5587 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA2;
5588 }
5589 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305590
5591 hddLog(VOS_TRACE_LEVEL_INFO, "%s: set wpa version to %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07005592 pWextState->wpaVersion);
5593
5594 /*set authentication type*/
5595 status = wlan_hdd_cfg80211_set_auth_type(pAdapter, req->auth_type);
5596
5597 if (0 > status)
5598 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305599 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005600 "%s: failed to set authentication type ", __func__);
5601 return status;
5602 }
5603
5604 /*set key mgmt type*/
5605 if (req->crypto.n_akm_suites)
5606 {
5607 status = wlan_hdd_set_akm_suite(pAdapter, req->crypto.akm_suites[0]);
5608 if (0 > status)
5609 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305610 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set akm suite",
Jeff Johnson295189b2012-06-20 16:38:30 -07005611 __func__);
5612 return status;
5613 }
5614 }
5615
5616 /*set pairwise cipher type*/
5617 if (req->crypto.n_ciphers_pairwise)
5618 {
5619 status = wlan_hdd_cfg80211_set_cipher(pAdapter,
5620 req->crypto.ciphers_pairwise[0], true);
5621 if (0 > status)
5622 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305623 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005624 "%s: failed to set unicast cipher type", __func__);
5625 return status;
5626 }
5627 }
5628 else
5629 {
5630 /*Reset previous cipher suite to none*/
5631 status = wlan_hdd_cfg80211_set_cipher(pAdapter, 0, true);
5632 if (0 > status)
5633 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305634 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005635 "%s: failed to set unicast cipher type", __func__);
5636 return status;
5637 }
5638 }
5639
5640 /*set group cipher type*/
5641 status = wlan_hdd_cfg80211_set_cipher(pAdapter, req->crypto.cipher_group,
5642 false);
5643
5644 if (0 > status)
5645 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305646 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set mcast cipher type",
Jeff Johnson295189b2012-06-20 16:38:30 -07005647 __func__);
5648 return status;
5649 }
5650
Chet Lanctot186b5732013-03-18 10:26:30 -07005651#ifdef WLAN_FEATURE_11W
5652 pWextState->roamProfile.MFPEnabled = (req->mfp == NL80211_MFP_REQUIRED);
5653#endif
5654
Jeff Johnson295189b2012-06-20 16:38:30 -07005655 /*parse WPA/RSN IE, and set the correspoing fileds in Roam profile*/
5656 if (req->ie_len)
5657 {
5658 status = wlan_hdd_cfg80211_set_ie(pAdapter, req->ie, req->ie_len);
5659 if ( 0 > status)
5660 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305661 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to parse the WPA/RSN IE",
Jeff Johnson295189b2012-06-20 16:38:30 -07005662 __func__);
5663 return status;
5664 }
5665 }
5666
5667 /*incase of WEP set default key information*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305668 if (req->key && req->key_len)
Jeff Johnson295189b2012-06-20 16:38:30 -07005669 {
5670 if ( (WLAN_CIPHER_SUITE_WEP40 == req->crypto.ciphers_pairwise[0])
5671 || (WLAN_CIPHER_SUITE_WEP104 == req->crypto.ciphers_pairwise[0])
5672 )
5673 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305674 if ( IW_AUTH_KEY_MGMT_802_1X
Jeff Johnson295189b2012-06-20 16:38:30 -07005675 == (pWextState->authKeyMgmt & IW_AUTH_KEY_MGMT_802_1X ))
5676 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305677 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Dynamic WEP not supported",
Jeff Johnson295189b2012-06-20 16:38:30 -07005678 __func__);
5679 return -EOPNOTSUPP;
5680 }
5681 else
5682 {
5683 u8 key_len = req->key_len;
5684 u8 key_idx = req->key_idx;
5685
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305686 if ((eCSR_SECURITY_WEP_KEYSIZE_MAX_BYTES >= key_len)
Jeff Johnson295189b2012-06-20 16:38:30 -07005687 && (CSR_MAX_NUM_KEY > key_idx)
5688 )
5689 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305690 hddLog(VOS_TRACE_LEVEL_INFO,
5691 "%s: setting default wep key, key_idx = %hu key_len %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07005692 __func__, key_idx, key_len);
5693 vos_mem_copy(
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305694 &pWextState->roamProfile.Keys.KeyMaterial[key_idx][0],
Jeff Johnson295189b2012-06-20 16:38:30 -07005695 req->key, key_len);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305696 pWextState->roamProfile.Keys.KeyLength[key_idx] =
Jeff Johnson295189b2012-06-20 16:38:30 -07005697 (u8)key_len;
5698 pWextState->roamProfile.Keys.defaultIndex = (u8)key_idx;
5699 }
5700 }
5701 }
5702 }
5703
5704 return status;
5705}
5706
5707/*
5708 * FUNCTION: wlan_hdd_cfg80211_set_privacy
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305709 * This function is used to initialize the security
Jeff Johnson295189b2012-06-20 16:38:30 -07005710 * parameters during connect operation.
5711 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305712static int wlan_hdd_cfg80211_connect( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07005713 struct net_device *ndev,
5714 struct cfg80211_connect_params *req
5715 )
5716{
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305717 int status;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305718 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Jeff Johnson295189b2012-06-20 16:38:30 -07005719 VOS_STATUS exitbmpsStatus = VOS_STATUS_E_INVAL;
5720 hdd_context_t *pHddCtx = NULL;
5721
5722 ENTER();
5723
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305724 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07005725 "%s: device_mode = %d\n",__func__,pAdapter->device_mode);
5726
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305727 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
5728 status = wlan_hdd_validate_context(pHddCtx);
5729
5730 if (0 != status)
Jeff Johnson295189b2012-06-20 16:38:30 -07005731 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305732 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5733 "%s: HDD context is not valid", __func__);
5734 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07005735 }
5736
5737#ifdef WLAN_BTAMP_FEATURE
5738 //Infra connect not supported when AMP traffic is on.
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305739 if( VOS_TRUE == WLANBAP_AmpSessionOn() )
Jeff Johnson295189b2012-06-20 16:38:30 -07005740 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305741 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07005742 "%s: No connection when AMP is on", __func__);
Madan Mohan Koyyalamudicae253a2012-11-06 19:10:35 -08005743 return -ECONNREFUSED;
Jeff Johnson295189b2012-06-20 16:38:30 -07005744 }
5745#endif
5746 /*initialise security parameters*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305747 status = wlan_hdd_cfg80211_set_privacy(pAdapter, req);
Jeff Johnson295189b2012-06-20 16:38:30 -07005748
5749 if ( 0 > status)
5750 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305751 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set security params",
Jeff Johnson295189b2012-06-20 16:38:30 -07005752 __func__);
5753 return status;
5754 }
5755
5756 //If Device Mode is Station Concurrent Sessions Exit BMps
Jeff Johnsona8a1a482012-12-12 16:49:33 -08005757 //P2P Mode will be taken care in Open/close adapter
Jeff Johnson295189b2012-06-20 16:38:30 -07005758 if((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) &&
5759 (vos_concurrent_sessions_running()))
5760 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305761 exitbmpsStatus = hdd_disable_bmps_imps(pHddCtx, WLAN_HDD_INFRA_STATION);
Jeff Johnson295189b2012-06-20 16:38:30 -07005762 }
5763
Mohit Khanna765234a2012-09-11 15:08:35 -07005764 if ( req->channel )
5765 {
5766 status = wlan_hdd_cfg80211_connect_start(pAdapter, req->ssid,
5767 req->ssid_len, req->bssid,
5768 req->channel->hw_value);
5769 }
5770 else
5771 {
5772 status = wlan_hdd_cfg80211_connect_start(pAdapter, req->ssid,
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305773 req->ssid_len, req->bssid, 0);
Mohit Khanna765234a2012-09-11 15:08:35 -07005774 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005775
5776 if (0 > status)
5777 {
5778 //ReEnable BMPS if disabled
5779 if((VOS_STATUS_SUCCESS == exitbmpsStatus) &&
5780 (NULL != pHddCtx))
5781 {
Gopichand Nakkalaa2fe5b02013-06-06 16:32:28 +05305782 if (pHddCtx->hdd_wlan_suspended)
5783 {
5784 hdd_set_pwrparams(pHddCtx);
5785 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005786 //ReEnable Bmps and Imps back
5787 hdd_enable_bmps_imps(pHddCtx);
5788 }
5789
5790 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: connect failed", __func__);
5791 return status;
5792 }
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305793 pHddCtx->isAmpAllowed = VOS_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005794 EXIT();
5795 return status;
5796}
5797
5798
5799/*
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05305800 * FUNCTION: wlan_hdd_disconnect
5801 * This function is used to issue a disconnect request to SME
5802 */
5803int wlan_hdd_disconnect( hdd_adapter_t *pAdapter, u16 reason )
5804{
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305805 int status;
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05305806 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305807 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
5808
5809 status = wlan_hdd_validate_context(pHddCtx);
5810
5811 if (0 != status)
5812 {
5813 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5814 "%s: HDD context is not valid", __func__);
5815 return status;
5816 }
5817
5818 pHddCtx->isAmpAllowed = VOS_TRUE;
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05305819 pHddStaCtx->conn_info.connState = eConnectionState_NotConnected;
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05305820 INIT_COMPLETION(pAdapter->disconnect_comp_var);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305821
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05305822 /*issue disconnect*/
5823 status = sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
5824 pAdapter->sessionId, reason);
5825
5826 if ( 0 != status )
5827 {
5828 hddLog(VOS_TRACE_LEVEL_ERROR,
5829 "%s csrRoamDisconnect failure, returned %d \n",
5830 __func__, (int)status );
5831 return -EINVAL;
5832 }
5833 wait_for_completion_interruptible_timeout(
5834 &pAdapter->disconnect_comp_var,
5835 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
5836 /*stop tx queues*/
5837 netif_tx_disable(pAdapter->dev);
5838 netif_carrier_off(pAdapter->dev);
5839 return status;
5840}
5841
5842
5843/*
Jeff Johnson295189b2012-06-20 16:38:30 -07005844 * FUNCTION: wlan_hdd_cfg80211_disconnect
5845 * This function is used to issue a disconnect request to SME
5846 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305847static int wlan_hdd_cfg80211_disconnect( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07005848 struct net_device *dev,
5849 u16 reason
5850 )
5851{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305852 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
5853 tCsrRoamProfile *pRoamProfile =
Jeff Johnson295189b2012-06-20 16:38:30 -07005854 &(WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter))->roamProfile;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305855 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07005856 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkala4327a152013-03-04 23:22:42 -08005857 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05305858#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08005859 tANI_U8 staIdx;
5860#endif
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305861
Jeff Johnson295189b2012-06-20 16:38:30 -07005862 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305863
5864 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
Jeff Johnson295189b2012-06-20 16:38:30 -07005865 __func__,pAdapter->device_mode);
5866
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305867 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Disconnect called with reason code %d",
5868 __func__, reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07005869
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305870 status = wlan_hdd_validate_context(pHddCtx);
5871
5872 if (0 != status)
Jeff Johnson295189b2012-06-20 16:38:30 -07005873 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305874 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5875 "%s: HDD context is not valid", __func__);
5876 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07005877 }
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05305878
Jeff Johnson295189b2012-06-20 16:38:30 -07005879 if (NULL != pRoamProfile)
5880 {
5881 /*issue disconnect request to SME, if station is in connected state*/
5882 if (pHddStaCtx->conn_info.connState == eConnectionState_Associated)
5883 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305884 eCsrRoamDisconnectReason reasonCode =
Jeff Johnson295189b2012-06-20 16:38:30 -07005885 eCSR_DISCONNECT_REASON_UNSPECIFIED;
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05305886 hdd_scaninfo_t *pScanInfo;
Jeff Johnson295189b2012-06-20 16:38:30 -07005887 switch(reason)
5888 {
5889 case WLAN_REASON_MIC_FAILURE:
5890 reasonCode = eCSR_DISCONNECT_REASON_MIC_ERROR;
5891 break;
5892
5893 case WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY:
5894 case WLAN_REASON_DISASSOC_AP_BUSY:
5895 case WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA:
5896 reasonCode = eCSR_DISCONNECT_REASON_DISASSOC;
5897 break;
5898
5899 case WLAN_REASON_PREV_AUTH_NOT_VALID:
5900 case WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA:
5901 reasonCode = eCSR_DISCONNECT_REASON_DEAUTH;
5902 break;
5903
5904 case WLAN_REASON_DEAUTH_LEAVING:
5905 default:
5906 reasonCode = eCSR_DISCONNECT_REASON_UNSPECIFIED;
5907 break;
5908 }
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05305909 pHddStaCtx->conn_info.connState = eConnectionState_NotConnected;
5910 pScanInfo = &pHddCtx->scan_info;
5911 if (pScanInfo->mScanPending)
5912 {
5913 hddLog(VOS_TRACE_LEVEL_INFO, "Disconnect is in progress, "
5914 "Aborting Scan");
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05305915 hdd_abort_mac_scan(pHddCtx, pAdapter->sessionId);
Gopichand Nakkalaaa353782013-05-17 20:36:22 +05305916 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005917
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08005918#ifdef FEATURE_WLAN_TDLS
5919 /* First clean up the tdls peers if any */
Gopichand Nakkala4327a152013-03-04 23:22:42 -08005920 for (staIdx = 0 ; staIdx < HDD_MAX_NUM_TDLS_STA; staIdx++)
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08005921 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08005922 if ((pHddCtx->tdlsConnInfo[staIdx].sessionId == pAdapter->sessionId) &&
5923 (pHddCtx->tdlsConnInfo[staIdx].staId))
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08005924 {
Hoonki Lee11f7dda2013-02-14 16:55:44 -08005925 uint8 *mac;
Gopichand Nakkala4327a152013-03-04 23:22:42 -08005926 mac = pHddCtx->tdlsConnInfo[staIdx].peerMac.bytes;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08005927 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07005928 "%s: call sme_DeleteTdlsPeerSta staId %d sessionId %d " MAC_ADDRESS_STR,
Gopichand Nakkala4327a152013-03-04 23:22:42 -08005929 __func__, pHddCtx->tdlsConnInfo[staIdx].staId, pAdapter->sessionId,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07005930 MAC_ADDR_ARRAY(mac));
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08005931 sme_DeleteTdlsPeerSta(WLAN_HDD_GET_HAL_CTX(pAdapter),
Gopichand Nakkala4327a152013-03-04 23:22:42 -08005932 pAdapter->sessionId,
5933 mac);
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08005934 }
5935 }
5936#endif
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05305937 status = wlan_hdd_disconnect(pAdapter, reasonCode);
5938 if ( 0 != status )
Jeff Johnson295189b2012-06-20 16:38:30 -07005939 {
5940 hddLog(VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05305941 "%s wlan_hdd_disconnect failure, returned %d \n",
Jeff Johnson295189b2012-06-20 16:38:30 -07005942 __func__, (int)status );
5943 return -EINVAL;
5944 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005945 }
5946 }
5947 else
5948 {
5949 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: No valid roam profile", __func__);
5950 }
5951
5952 return status;
5953}
5954
Gopichand Nakkala78a6c812013-05-13 16:39:49 +05305955
Jeff Johnson295189b2012-06-20 16:38:30 -07005956/*
5957 * FUNCTION: wlan_hdd_cfg80211_set_privacy_ibss
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305958 * This function is used to initialize the security
Jeff Johnson295189b2012-06-20 16:38:30 -07005959 * settings in IBSS mode.
5960 */
5961static int wlan_hdd_cfg80211_set_privacy_ibss(
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305962 hdd_adapter_t *pAdapter,
Jeff Johnson295189b2012-06-20 16:38:30 -07005963 struct cfg80211_ibss_params *params
5964 )
5965{
5966 int status = 0;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305967 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07005968 eCsrEncryptionType encryptionType = eCSR_ENCRYPT_TYPE_NONE;
5969 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05305970
Jeff Johnson295189b2012-06-20 16:38:30 -07005971 ENTER();
5972
5973 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_DISABLED;
5974
5975 if (params->ie_len && ( NULL != params->ie) )
5976 {
Shailender Karmuchi67edd312013-06-18 16:30:48 -07005977 if (wlan_hdd_cfg80211_get_ie_ptr (params->ie,
5978 params->ie_len, WLAN_EID_RSN ))
Jeff Johnson295189b2012-06-20 16:38:30 -07005979 {
5980 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA2;
5981 encryptionType = eCSR_ENCRYPT_TYPE_AES;
5982 }
Shailender Karmuchi67edd312013-06-18 16:30:48 -07005983 else if ( hdd_isWPAIEPresent (params->ie, params->ie_len ))
Jeff Johnson295189b2012-06-20 16:38:30 -07005984 {
Shailender Karmuchi642e9812013-05-30 14:34:49 -07005985 tDot11fIEWPA dot11WPAIE;
5986 tHalHandle halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
Shailender Karmuchi67edd312013-06-18 16:30:48 -07005987 u8 *ie;
Shailender Karmuchi642e9812013-05-30 14:34:49 -07005988
Shailender Karmuchi67edd312013-06-18 16:30:48 -07005989 ie = wlan_hdd_cfg80211_get_ie_ptr (params->ie,
5990 params->ie_len, DOT11F_EID_WPA);
5991 if ( NULL != ie )
5992 {
5993 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA;
5994 // Unpack the WPA IE
5995 //Skip past the EID byte and length byte - and four byte WiFi OUI
5996 dot11fUnpackIeWPA((tpAniSirGlobal) halHandle,
5997 &ie[2+4],
5998 ie[1] - 4,
5999 &dot11WPAIE);
6000 /*Extract the multicast cipher, the encType for unicast
6001 cipher for wpa-none is none*/
6002 encryptionType =
6003 hdd_TranslateWPAToCsrEncryptionType(dot11WPAIE.multicast_cipher);
6004 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006005 }
Shailender Karmuchi67edd312013-06-18 16:30:48 -07006006
Jeff Johnson295189b2012-06-20 16:38:30 -07006007 status = wlan_hdd_cfg80211_set_ie(pAdapter, params->ie, params->ie_len);
6008
6009 if (0 > status)
6010 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306011 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to parse WPA/RSN IE",
Jeff Johnson295189b2012-06-20 16:38:30 -07006012 __func__);
6013 return status;
6014 }
6015 }
6016
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306017 pWextState->roamProfile.AuthType.authType[0] =
6018 pHddStaCtx->conn_info.authType =
Jeff Johnson295189b2012-06-20 16:38:30 -07006019 eCSR_AUTH_TYPE_OPEN_SYSTEM;
6020
6021 if (params->privacy)
6022 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306023 /* Security enabled IBSS, At this time there is no information available
6024 * about the security paramters, so initialise the encryption type to
Jeff Johnson295189b2012-06-20 16:38:30 -07006025 * eCSR_ENCRYPT_TYPE_WEP40_STATICKEY.
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306026 * The correct security parameters will be updated later in
Jeff Johnson295189b2012-06-20 16:38:30 -07006027 * wlan_hdd_cfg80211_add_key */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306028 /* Hal expects encryption type to be set inorder
Jeff Johnson295189b2012-06-20 16:38:30 -07006029 *enable privacy bit in beacons */
6030
6031 encryptionType = eCSR_ENCRYPT_TYPE_WEP40_STATICKEY;
6032 }
Shailender Karmuchi642e9812013-05-30 14:34:49 -07006033 VOS_TRACE (VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
6034 "encryptionType=%d", encryptionType);
Jeff Johnson295189b2012-06-20 16:38:30 -07006035 pHddStaCtx->conn_info.ucEncryptionType = encryptionType;
6036 pWextState->roamProfile.EncryptionType.numEntries = 1;
6037 pWextState->roamProfile.EncryptionType.encryptionType[0] = encryptionType;
Jeff Johnson295189b2012-06-20 16:38:30 -07006038 return status;
6039}
6040
6041/*
6042 * FUNCTION: wlan_hdd_cfg80211_join_ibss
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306043 * This function is used to create/join an IBSS
Jeff Johnson295189b2012-06-20 16:38:30 -07006044 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306045static int wlan_hdd_cfg80211_join_ibss( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07006046 struct net_device *dev,
6047 struct cfg80211_ibss_params *params
6048 )
6049{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306050 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Jeff Johnson295189b2012-06-20 16:38:30 -07006051 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
6052 tCsrRoamProfile *pRoamProfile;
6053 int status;
6054 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306055 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07006056
6057 ENTER();
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306058
6059 hddLog(VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07006060 "%s: device_mode = %d\n",__func__,pAdapter->device_mode);
6061
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306062 status = wlan_hdd_validate_context(pHddCtx);
6063
6064 if (0 != status)
Jeff Johnson295189b2012-06-20 16:38:30 -07006065 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306066 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6067 "%s: HDD context is not valid", __func__);
6068 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006069 }
6070
6071 if (NULL == pWextState)
6072 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306073 hddLog (VOS_TRACE_LEVEL_ERROR, "%s ERROR: Data Storage Corruption\n",
Jeff Johnson295189b2012-06-20 16:38:30 -07006074 __func__);
6075 return -EIO;
6076 }
6077
6078 pRoamProfile = &pWextState->roamProfile;
6079
6080 if ( eCSR_BSS_TYPE_START_IBSS != pRoamProfile->BSSType )
6081 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306082 hddLog (VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07006083 "%s Interface type is not set to IBSS \n", __func__);
6084 return -EINVAL;
6085 }
6086
6087 /* Set Channel */
Yue Maf49ba872013-08-19 12:04:25 -07006088 if (NULL !=
6089#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0))
6090 params->chandef.chan)
6091#else
6092 params->channel)
6093#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006094 {
6095 u8 channelNum;
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006096 v_U32_t numChans = WNI_CFG_VALID_CHANNEL_LIST_LEN;
6097 v_U8_t validChan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
6098 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
6099 int indx;
Jeff Johnson295189b2012-06-20 16:38:30 -07006100
6101 /* Get channel number */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306102 channelNum =
Yue Maf49ba872013-08-19 12:04:25 -07006103 ieee80211_frequency_to_channel(
6104#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0))
6105 params->chandef.chan->center_freq);
6106#else
6107 params->channel->center_freq);
6108#endif
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006109
6110 if (0 != ccmCfgGetStr(hHal, WNI_CFG_VALID_CHANNEL_LIST,
6111 validChan, &numChans))
Jeff Johnson295189b2012-06-20 16:38:30 -07006112 {
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006113 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: No valid channel list",
6114 __func__);
6115 return -EOPNOTSUPP;
Jeff Johnson295189b2012-06-20 16:38:30 -07006116 }
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006117
6118 for (indx = 0; indx < numChans; indx++)
Jeff Johnson295189b2012-06-20 16:38:30 -07006119 {
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006120 if (channelNum == validChan[indx])
6121 {
6122 break;
6123 }
6124 }
6125 if (indx >= numChans)
6126 {
6127 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Not valid Channel %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07006128 __func__, channelNum);
6129 return -EINVAL;
6130 }
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006131 /* Set the Operational Channel */
6132 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: set channel %d", __func__,
6133 channelNum);
6134 pRoamProfile->ChannelInfo.numOfChannels = 1;
6135 pHddStaCtx->conn_info.operationChannel = channelNum;
6136 pRoamProfile->ChannelInfo.ChannelList =
6137 &pHddStaCtx->conn_info.operationChannel;
Jeff Johnson295189b2012-06-20 16:38:30 -07006138 }
6139
6140 /* Initialize security parameters */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306141 status = wlan_hdd_cfg80211_set_privacy_ibss(pAdapter, params);
Jeff Johnson295189b2012-06-20 16:38:30 -07006142 if (status < 0)
6143 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306144 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set security parameters",
Jeff Johnson295189b2012-06-20 16:38:30 -07006145 __func__);
6146 return status;
6147 }
6148
6149 /* Issue connect start */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306150 status = wlan_hdd_cfg80211_connect_start(pAdapter, params->ssid,
Shailender Karmuchi15cd0672013-05-15 19:50:04 -07006151 params->ssid_len, params->bssid,
6152 pHddStaCtx->conn_info.operationChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07006153
6154 if (0 > status)
6155 {
6156 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: connect failed", __func__);
6157 return status;
6158 }
6159
6160 return 0;
6161}
6162
6163/*
6164 * FUNCTION: wlan_hdd_cfg80211_leave_ibss
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306165 * This function is used to leave an IBSS
Jeff Johnson295189b2012-06-20 16:38:30 -07006166 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306167static int wlan_hdd_cfg80211_leave_ibss( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07006168 struct net_device *dev
6169 )
6170{
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306171 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Jeff Johnson295189b2012-06-20 16:38:30 -07006172 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
6173 tCsrRoamProfile *pRoamProfile;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306174 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
6175 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006176
6177 ENTER();
6178
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306179 status = wlan_hdd_validate_context(pHddCtx);
6180
6181 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006182 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306183 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6184 "%s: HDD context is not valid", __func__);
6185 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006186 }
6187
Jeff Johnson295189b2012-06-20 16:38:30 -07006188 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",__func__,pAdapter->device_mode);
6189 if (NULL == pWextState)
6190 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306191 hddLog (VOS_TRACE_LEVEL_ERROR, "%s ERROR: Data Storage Corruption\n",
Jeff Johnson295189b2012-06-20 16:38:30 -07006192 __func__);
6193 return -EIO;
6194 }
6195
6196 pRoamProfile = &pWextState->roamProfile;
6197
6198 /* Issue disconnect only if interface type is set to IBSS */
6199 if (eCSR_BSS_TYPE_START_IBSS != pRoamProfile->BSSType)
6200 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306201 hddLog (VOS_TRACE_LEVEL_ERROR, "%s: BSS Type is not set to IBSS",
Jeff Johnson295189b2012-06-20 16:38:30 -07006202 __func__);
6203 return -EINVAL;
6204 }
6205
6206 /* Issue Disconnect request */
6207 INIT_COMPLETION(pAdapter->disconnect_comp_var);
6208 sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter), pAdapter->sessionId,
6209 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
6210
6211 return 0;
6212}
6213
6214/*
6215 * FUNCTION: wlan_hdd_cfg80211_set_wiphy_params
6216 * This function is used to set the phy parameters
6217 * (RTS Threshold/FRAG Threshold/Retry Count etc ...)
6218 */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306219static int wlan_hdd_cfg80211_set_wiphy_params(struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07006220 u32 changed)
6221{
6222 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
6223 tHalHandle hHal = pHddCtx->hHal;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306224 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006225
6226 ENTER();
6227
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306228 status = wlan_hdd_validate_context(pHddCtx);
6229
6230 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006231 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306232 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6233 "%s: HDD context is not valid", __func__);
6234 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006235 }
6236
Jeff Johnson295189b2012-06-20 16:38:30 -07006237 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
6238 {
6239 u16 rts_threshold = (wiphy->rts_threshold == -1) ?
6240 WNI_CFG_RTS_THRESHOLD_STAMAX :
6241 wiphy->rts_threshold;
6242
6243 if ((WNI_CFG_RTS_THRESHOLD_STAMIN > rts_threshold) ||
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306244 (WNI_CFG_RTS_THRESHOLD_STAMAX < rts_threshold))
Jeff Johnson295189b2012-06-20 16:38:30 -07006245 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306246 hddLog(VOS_TRACE_LEVEL_ERROR,
6247 "%s: Invalid RTS Threshold value %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006248 __func__, rts_threshold);
6249 return -EINVAL;
6250 }
6251
6252 if (0 != ccmCfgSetInt(hHal, WNI_CFG_RTS_THRESHOLD,
6253 rts_threshold, ccmCfgSetCallback,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306254 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07006255 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306256 hddLog(VOS_TRACE_LEVEL_ERROR,
6257 "%s: ccmCfgSetInt failed for rts_threshold value %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006258 __func__, rts_threshold);
6259 return -EIO;
6260 }
6261
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306262 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set rts threshold %hu", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07006263 rts_threshold);
6264 }
6265
6266 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
6267 {
6268 u16 frag_threshold = (wiphy->frag_threshold == -1) ?
6269 WNI_CFG_FRAGMENTATION_THRESHOLD_STAMAX :
6270 wiphy->frag_threshold;
6271
6272 if ((WNI_CFG_FRAGMENTATION_THRESHOLD_STAMIN > frag_threshold)||
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306273 (WNI_CFG_FRAGMENTATION_THRESHOLD_STAMAX < frag_threshold) )
Jeff Johnson295189b2012-06-20 16:38:30 -07006274 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306275 hddLog(VOS_TRACE_LEVEL_ERROR,
6276 "%s: Invalid frag_threshold value %hu", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07006277 frag_threshold);
6278 return -EINVAL;
6279 }
6280
6281 if (0 != ccmCfgSetInt(hHal, WNI_CFG_FRAGMENTATION_THRESHOLD,
6282 frag_threshold, ccmCfgSetCallback,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306283 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07006284 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306285 hddLog(VOS_TRACE_LEVEL_ERROR,
6286 "%s: ccmCfgSetInt failed for frag_threshold value %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006287 __func__, frag_threshold);
6288 return -EIO;
6289 }
6290
6291 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set frag threshold %hu", __func__,
6292 frag_threshold);
6293 }
6294
6295 if ((changed & WIPHY_PARAM_RETRY_SHORT)
6296 || (changed & WIPHY_PARAM_RETRY_LONG))
6297 {
6298 u8 retry_value = (changed & WIPHY_PARAM_RETRY_SHORT) ?
6299 wiphy->retry_short :
6300 wiphy->retry_long;
6301
6302 if ((WNI_CFG_LONG_RETRY_LIMIT_STAMIN > retry_value) ||
6303 (WNI_CFG_LONG_RETRY_LIMIT_STAMAX < retry_value))
6304 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306305 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006306 __func__, retry_value);
6307 return -EINVAL;
6308 }
6309
6310 if (changed & WIPHY_PARAM_RETRY_SHORT)
6311 {
6312 if (0 != ccmCfgSetInt(hHal, WNI_CFG_LONG_RETRY_LIMIT,
6313 retry_value, ccmCfgSetCallback,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306314 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07006315 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306316 hddLog(VOS_TRACE_LEVEL_ERROR,
6317 "%s: ccmCfgSetInt failed for long retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006318 __func__, retry_value);
6319 return -EIO;
6320 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306321 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set long retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006322 __func__, retry_value);
6323 }
6324 else if (changed & WIPHY_PARAM_RETRY_SHORT)
6325 {
6326 if (0 != ccmCfgSetInt(hHal, WNI_CFG_SHORT_RETRY_LIMIT,
6327 retry_value, ccmCfgSetCallback,
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306328 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07006329 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306330 hddLog(VOS_TRACE_LEVEL_ERROR,
6331 "%s: ccmCfgSetInt failed for short retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006332 __func__, retry_value);
6333 return -EIO;
6334 }
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306335 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set short retry count %hu",
Jeff Johnson295189b2012-06-20 16:38:30 -07006336 __func__, retry_value);
6337 }
6338 }
6339
6340 return 0;
6341}
6342
6343/*
6344 * FUNCTION: wlan_hdd_cfg80211_set_txpower
6345 * This function is used to set the txpower
6346 */
6347static int wlan_hdd_cfg80211_set_txpower(struct wiphy *wiphy,
Yue Maf49ba872013-08-19 12:04:25 -07006348#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0)
6349 struct wireless_dev *wdev,
6350#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006351#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,35)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306352 enum tx_power_setting type,
Jeff Johnson295189b2012-06-20 16:38:30 -07006353#else
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306354 enum nl80211_tx_power_setting type,
Jeff Johnson295189b2012-06-20 16:38:30 -07006355#endif
6356 int dbm)
6357{
6358 hdd_context_t *pHddCtx = (hdd_context_t*) wiphy_priv(wiphy);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306359 tHalHandle hHal = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07006360 tSirMacAddr bssid = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
6361 tSirMacAddr selfMac = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306362 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006363
6364 ENTER();
6365
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306366 status = wlan_hdd_validate_context(pHddCtx);
6367
6368 if (0 != status)
6369 {
6370 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6371 "%s: HDD context is not valid", __func__);
6372 return status;
6373 }
6374
6375 hHal = pHddCtx->hHal;
6376
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306377 if (0 != ccmCfgSetInt(hHal, WNI_CFG_CURRENT_TX_POWER_LEVEL,
6378 dbm, ccmCfgSetCallback,
6379 eANI_BOOLEAN_TRUE))
Jeff Johnson295189b2012-06-20 16:38:30 -07006380 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306381 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07006382 "%s: ccmCfgSetInt failed for tx power %hu", __func__, dbm);
6383 return -EIO;
6384 }
6385
6386 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set tx power level %d dbm", __func__,
6387 dbm);
6388
6389 switch(type)
6390 {
6391 case NL80211_TX_POWER_AUTOMATIC: /*automatically determine transmit power*/
6392 /* Fall through */
6393 case NL80211_TX_POWER_LIMITED: /*limit TX power by the mBm parameter*/
6394 if( sme_SetMaxTxPower(hHal, bssid, selfMac, dbm) != eHAL_STATUS_SUCCESS )
6395 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306396 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Setting maximum tx power failed",
6397 __func__);
6398 return -EIO;
Jeff Johnson295189b2012-06-20 16:38:30 -07006399 }
6400 break;
6401 case NL80211_TX_POWER_FIXED: /*fix TX power to the mBm parameter*/
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306402 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: NL80211_TX_POWER_FIXED not supported",
Jeff Johnson295189b2012-06-20 16:38:30 -07006403 __func__);
6404 return -EOPNOTSUPP;
6405 break;
6406 default:
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306407 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid power setting type %d",
6408 __func__, type);
Jeff Johnson295189b2012-06-20 16:38:30 -07006409 return -EIO;
6410 }
6411
6412 return 0;
6413}
6414
6415/*
6416 * FUNCTION: wlan_hdd_cfg80211_get_txpower
6417 * This function is used to read the txpower
6418 */
Yue Maf49ba872013-08-19 12:04:25 -07006419static int wlan_hdd_cfg80211_get_txpower(struct wiphy *wiphy,
6420#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0)
6421 struct wireless_dev *wdev,
6422#endif
6423 int *dbm)
Jeff Johnson295189b2012-06-20 16:38:30 -07006424{
6425
6426 hdd_adapter_t *pAdapter;
6427 hdd_context_t *pHddCtx = (hdd_context_t*) wiphy_priv(wiphy);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306428 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006429
Jeff Johnsone7245742012-09-05 17:12:55 -07006430 ENTER();
6431
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306432 status = wlan_hdd_validate_context(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07006433
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306434 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006435 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306436 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6437 "%s: HDD context is not valid", __func__);
6438 *dbm = 0;
6439 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006440 }
6441
Jeff Johnson295189b2012-06-20 16:38:30 -07006442 pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_INFRA_STATION);
6443 if (NULL == pAdapter)
6444 {
6445 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Not in station context " ,__func__);
6446 return -ENOENT;
6447 }
6448
6449 wlan_hdd_get_classAstats(pAdapter);
6450 *dbm = pAdapter->hdd_stats.ClassA_stat.max_pwr;
6451
Jeff Johnsone7245742012-09-05 17:12:55 -07006452 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07006453 return 0;
6454}
6455
6456static int wlan_hdd_cfg80211_get_station(struct wiphy *wiphy, struct net_device *dev,
6457 u8* mac, struct station_info *sinfo)
6458{
6459 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
6460 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
6461 int ssidlen = pHddStaCtx->conn_info.SSID.SSID.length;
6462 tANI_U8 rate_flags;
6463
6464 hdd_context_t *pHddCtx = (hdd_context_t*) wiphy_priv(wiphy);
6465 hdd_config_t *pCfg = pHddCtx->cfg_ini;
Jeff Johnson295189b2012-06-20 16:38:30 -07006466
6467 tANI_U8 OperationalRates[CSR_DOT11_SUPPORTED_RATES_MAX];
6468 tANI_U32 ORLeng = CSR_DOT11_SUPPORTED_RATES_MAX;
6469 tANI_U8 ExtendedRates[CSR_DOT11_EXTENDED_SUPPORTED_RATES_MAX];
6470 tANI_U32 ERLeng = CSR_DOT11_EXTENDED_SUPPORTED_RATES_MAX;
6471 tANI_U8 MCSRates[SIZE_OF_BASIC_MCS_SET];
6472 tANI_U32 MCSLeng = SIZE_OF_BASIC_MCS_SET;
6473 tANI_U16 maxRate = 0;
6474 tANI_U16 myRate;
6475 tANI_U16 currentRate = 0;
6476 tANI_U8 maxSpeedMCS = 0;
6477 tANI_U8 maxMCSIdx = 0;
6478 tANI_U8 rateFlag = 1;
6479 tANI_U8 i, j, rssidx;
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07006480 tANI_U16 temp;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306481 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006482
Leo Chang6f8870f2013-03-26 18:11:36 -07006483#ifdef WLAN_FEATURE_11AC
6484 tANI_U32 vht_mcs_map;
6485 eDataRate11ACMaxMcs vhtMaxMcs;
6486#endif /* WLAN_FEATURE_11AC */
6487
Jeff Johnsone7245742012-09-05 17:12:55 -07006488 ENTER();
6489
Jeff Johnson295189b2012-06-20 16:38:30 -07006490 if ((eConnectionState_Associated != pHddStaCtx->conn_info.connState) ||
6491 (0 == ssidlen))
6492 {
6493 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Not associated or"
6494 " Invalid ssidlen, %d", __func__, ssidlen);
6495 /*To keep GUI happy*/
6496 return 0;
6497 }
6498
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306499 status = wlan_hdd_validate_context(pHddCtx);
6500
6501 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006502 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306503 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6504 "%s: HDD context is not valid", __func__);
6505 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006506 }
6507
Jeff Johnson295189b2012-06-20 16:38:30 -07006508 wlan_hdd_get_rssi(pAdapter, &sinfo->signal);
6509 sinfo->filled |= STATION_INFO_SIGNAL;
6510
Madan Mohan Koyyalamudi4d4d2812012-09-24 14:08:29 -07006511 wlan_hdd_get_station_stats(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07006512 rate_flags = pAdapter->hdd_stats.ClassA_stat.tx_rate_flags;
6513
6514 //convert to the UI units of 100kbps
6515 myRate = pAdapter->hdd_stats.ClassA_stat.tx_rate * 5;
6516
6517#ifdef LINKSPEED_DEBUG_ENABLED
Leo Chang6f8870f2013-03-26 18:11:36 -07006518 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 -07006519 sinfo->signal,
6520 pCfg->reportMaxLinkSpeed,
6521 myRate,
6522 (int) pCfg->linkSpeedRssiHigh,
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07006523 (int) pCfg->linkSpeedRssiMid,
6524 (int) pCfg->linkSpeedRssiLow,
Leo Chang6f8870f2013-03-26 18:11:36 -07006525 (int) rate_flags,
6526 (int) pAdapter->hdd_stats.ClassA_stat.mcs_index);
Jeff Johnson295189b2012-06-20 16:38:30 -07006527#endif //LINKSPEED_DEBUG_ENABLED
6528
6529 if (eHDD_LINK_SPEED_REPORT_ACTUAL != pCfg->reportMaxLinkSpeed)
6530 {
6531 // we do not want to necessarily report the current speed
6532 if (eHDD_LINK_SPEED_REPORT_MAX == pCfg->reportMaxLinkSpeed)
6533 {
6534 // report the max possible speed
6535 rssidx = 0;
6536 }
6537 else if (eHDD_LINK_SPEED_REPORT_MAX_SCALED == pCfg->reportMaxLinkSpeed)
6538 {
6539 // report the max possible speed with RSSI scaling
6540 if (sinfo->signal >= pCfg->linkSpeedRssiHigh)
6541 {
6542 // report the max possible speed
6543 rssidx = 0;
6544 }
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07006545 else if (sinfo->signal >= pCfg->linkSpeedRssiMid)
Jeff Johnson295189b2012-06-20 16:38:30 -07006546 {
6547 // report middle speed
6548 rssidx = 1;
6549 }
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07006550 else if (sinfo->signal >= pCfg->linkSpeedRssiLow)
6551 {
6552 // report middle speed
6553 rssidx = 2;
6554 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006555 else
6556 {
6557 // report actual speed
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07006558 rssidx = 3;
Jeff Johnson295189b2012-06-20 16:38:30 -07006559 }
6560 }
6561 else
6562 {
6563 // unknown, treat as eHDD_LINK_SPEED_REPORT_MAX
6564 hddLog(VOS_TRACE_LEVEL_ERROR,
6565 "%s: Invalid value for reportMaxLinkSpeed: %u",
6566 __func__, pCfg->reportMaxLinkSpeed);
6567 rssidx = 0;
6568 }
6569
6570 maxRate = 0;
6571
6572 /* Get Basic Rate Set */
Gopichand Nakkala05ab1322013-02-15 11:28:38 +05306573 if (0 != ccmCfgGetStr(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_OPERATIONAL_RATE_SET,
6574 OperationalRates, &ORLeng))
6575 {
6576 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: ccm api returned failure", __func__);
6577 /*To keep GUI happy*/
6578 return 0;
6579 }
6580
Jeff Johnson295189b2012-06-20 16:38:30 -07006581 for (i = 0; i < ORLeng; i++)
6582 {
Jeff Johnsone7245742012-09-05 17:12:55 -07006583 for (j = 0; j < (sizeof(supported_data_rate) / sizeof(supported_data_rate[0])); j ++)
Jeff Johnson295189b2012-06-20 16:38:30 -07006584 {
6585 /* Validate Rate Set */
6586 if (supported_data_rate[j].beacon_rate_index == (OperationalRates[i] & 0x7F))
6587 {
6588 currentRate = supported_data_rate[j].supported_rate[rssidx];
6589 break;
6590 }
6591 }
6592 /* Update MAX rate */
6593 maxRate = (currentRate > maxRate)?currentRate:maxRate;
6594 }
6595
6596 /* Get Extended Rate Set */
Gopichand Nakkala05ab1322013-02-15 11:28:38 +05306597 if (0 != ccmCfgGetStr(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_EXTENDED_OPERATIONAL_RATE_SET,
6598 ExtendedRates, &ERLeng))
6599 {
6600 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: ccm api returned failure", __func__);
6601 /*To keep GUI happy*/
6602 return 0;
6603 }
6604
Jeff Johnson295189b2012-06-20 16:38:30 -07006605 for (i = 0; i < ERLeng; i++)
6606 {
Jeff Johnsone7245742012-09-05 17:12:55 -07006607 for (j = 0; j < (sizeof(supported_data_rate) / sizeof(supported_data_rate[0])); j ++)
Jeff Johnson295189b2012-06-20 16:38:30 -07006608 {
6609 if (supported_data_rate[j].beacon_rate_index == (ExtendedRates[i] & 0x7F))
6610 {
6611 currentRate = supported_data_rate[j].supported_rate[rssidx];
6612 break;
6613 }
6614 }
6615 /* Update MAX rate */
6616 maxRate = (currentRate > maxRate)?currentRate:maxRate;
6617 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006618 /* Get MCS Rate Set -- but only if we are connected at MCS
6619 rates or if we are always reporting max speed or if we have
6620 good rssi */
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07006621 if ((0 == rssidx) && !(rate_flags & eHAL_TX_RATE_LEGACY))
Jeff Johnson295189b2012-06-20 16:38:30 -07006622 {
Gopichand Nakkala05ab1322013-02-15 11:28:38 +05306623 if (0 != ccmCfgGetStr(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_CURRENT_MCS_SET,
6624 MCSRates, &MCSLeng))
6625 {
6626 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: ccm api returned failure", __func__);
6627 /*To keep GUI happy*/
6628 return 0;
6629 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006630 rateFlag = 0;
Leo Chang6f8870f2013-03-26 18:11:36 -07006631#ifdef WLAN_FEATURE_11AC
6632 /* VHT80 rate has seperate rate table */
Gopichand Nakkala4c705372013-04-24 13:20:33 +05306633 if (rate_flags & (eHAL_TX_RATE_VHT20|eHAL_TX_RATE_VHT40|eHAL_TX_RATE_VHT80))
Jeff Johnson295189b2012-06-20 16:38:30 -07006634 {
Leo Chang6f8870f2013-03-26 18:11:36 -07006635 ccmCfgGetInt(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_VHT_TX_MCS_MAP, &vht_mcs_map);
Gopichand Nakkala4c705372013-04-24 13:20:33 +05306636 vhtMaxMcs = (eDataRate11ACMaxMcs)(vht_mcs_map & DATA_RATE_11AC_MCS_MASK );
Leo Chang6f8870f2013-03-26 18:11:36 -07006637 if (rate_flags & eHAL_TX_RATE_SGI)
Jeff Johnson295189b2012-06-20 16:38:30 -07006638 {
Leo Chang6f8870f2013-03-26 18:11:36 -07006639 rateFlag |= 1;
Jeff Johnson295189b2012-06-20 16:38:30 -07006640 }
Leo Chang6f8870f2013-03-26 18:11:36 -07006641 if (DATA_RATE_11AC_MAX_MCS_7 == vhtMaxMcs)
Jeff Johnson295189b2012-06-20 16:38:30 -07006642 {
Leo Chang6f8870f2013-03-26 18:11:36 -07006643 maxMCSIdx = 7;
6644 }
6645 else if (DATA_RATE_11AC_MAX_MCS_8 == vhtMaxMcs)
6646 {
6647 maxMCSIdx = 8;
6648 }
6649 else if (DATA_RATE_11AC_MAX_MCS_9 == vhtMaxMcs)
6650 {
Gopichand Nakkala4c705372013-04-24 13:20:33 +05306651 //VHT20 is supporting 0~8
6652 if (rate_flags & eHAL_TX_RATE_VHT20)
6653 maxMCSIdx = 8;
6654 else
6655 maxMCSIdx = 9;
Leo Chang6f8870f2013-03-26 18:11:36 -07006656 }
Gopichand Nakkala4c705372013-04-24 13:20:33 +05306657
6658 if (rate_flags & eHAL_TX_RATE_VHT80)
6659 {
6660 currentRate = supported_vht_mcs_rate[pAdapter->hdd_stats.ClassA_stat.mcs_index].supported_VHT80_rate[rateFlag];
6661 maxRate = supported_vht_mcs_rate[maxMCSIdx].supported_VHT80_rate[rateFlag];
6662 }
6663 else if (rate_flags & eHAL_TX_RATE_VHT40)
6664 {
6665 currentRate = supported_vht_mcs_rate[pAdapter->hdd_stats.ClassA_stat.mcs_index].supported_VHT40_rate[rateFlag];
6666 maxRate = supported_vht_mcs_rate[maxMCSIdx].supported_VHT40_rate[rateFlag];
6667 }
6668 else if (rate_flags & eHAL_TX_RATE_VHT20)
6669 {
6670 currentRate = supported_vht_mcs_rate[pAdapter->hdd_stats.ClassA_stat.mcs_index].supported_VHT20_rate[rateFlag];
6671 maxRate = supported_vht_mcs_rate[maxMCSIdx].supported_VHT20_rate[rateFlag];
6672 }
6673
Leo Chang6f8870f2013-03-26 18:11:36 -07006674 maxSpeedMCS = 1;
6675 if (currentRate > maxRate)
6676 {
6677 maxRate = currentRate;
6678 }
Gopichand Nakkala4c705372013-04-24 13:20:33 +05306679
Leo Chang6f8870f2013-03-26 18:11:36 -07006680 }
6681 else
6682#endif /* WLAN_FEATURE_11AC */
6683 {
6684 if (rate_flags & eHAL_TX_RATE_HT40)
6685 {
6686 rateFlag |= 1;
6687 }
6688 if (rate_flags & eHAL_TX_RATE_SGI)
6689 {
6690 rateFlag |= 2;
6691 }
6692
6693 for (i = 0; i < MCSLeng; i++)
6694 {
6695 temp = sizeof(supported_mcs_rate) / sizeof(supported_mcs_rate[0]);
6696 for (j = 0; j < temp; j++)
6697 {
6698 if (supported_mcs_rate[j].beacon_rate_index == MCSRates[i])
6699 {
6700 currentRate = supported_mcs_rate[j].supported_rate[rateFlag];
6701 break;
6702 }
6703 }
6704 if ((j < temp) && (currentRate > maxRate))
6705 {
6706 maxRate = currentRate;
6707 maxSpeedMCS = 1;
6708 maxMCSIdx = supported_mcs_rate[j].beacon_rate_index;
6709 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006710 }
6711 }
6712 }
6713
Gopichand Nakkala4c705372013-04-24 13:20:33 +05306714 else if (!(rate_flags & eHAL_TX_RATE_LEGACY))
6715 {
6716 maxRate = myRate;
6717 maxSpeedMCS = 1;
6718 maxMCSIdx = pAdapter->hdd_stats.ClassA_stat.mcs_index;
6719 }
6720
Jeff Johnson295189b2012-06-20 16:38:30 -07006721 // make sure we report a value at least as big as our current rate
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07006722 if (((maxRate < myRate) && (0 == rssidx)) ||
6723 (0 == maxRate))
Jeff Johnson295189b2012-06-20 16:38:30 -07006724 {
6725 maxRate = myRate;
6726 if (rate_flags & eHAL_TX_RATE_LEGACY)
6727 {
6728 maxSpeedMCS = 0;
6729 }
6730 else
6731 {
6732 maxSpeedMCS = 1;
6733 maxMCSIdx = pAdapter->hdd_stats.ClassA_stat.mcs_index;
6734 }
6735 }
6736
Gopichand Nakkala4c705372013-04-24 13:20:33 +05306737 if (rate_flags & eHAL_TX_RATE_LEGACY)
Jeff Johnson295189b2012-06-20 16:38:30 -07006738 {
6739 sinfo->txrate.legacy = maxRate;
6740#ifdef LINKSPEED_DEBUG_ENABLED
6741 pr_info("Reporting legacy rate %d\n", sinfo->txrate.legacy);
6742#endif //LINKSPEED_DEBUG_ENABLED
6743 }
6744 else
6745 {
6746 sinfo->txrate.mcs = maxMCSIdx;
Leo Chang6f8870f2013-03-26 18:11:36 -07006747#ifdef WLAN_FEATURE_11AC
6748 sinfo->txrate.nss = 1;
6749 if (rate_flags & eHAL_TX_RATE_VHT80)
6750 {
6751 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
Gopichand Nakkala4c705372013-04-24 13:20:33 +05306752 sinfo->txrate.flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
Leo Chang6f8870f2013-03-26 18:11:36 -07006753 }
Gopichand Nakkala4c705372013-04-24 13:20:33 +05306754 else if (rate_flags & eHAL_TX_RATE_VHT40)
Leo Chang6f8870f2013-03-26 18:11:36 -07006755 {
Gopichand Nakkala4c705372013-04-24 13:20:33 +05306756 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
6757 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
6758 }
6759 else if (rate_flags & eHAL_TX_RATE_VHT20)
6760 {
6761 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
6762 }
6763#endif /* WLAN_FEATURE_11AC */
6764 if (rate_flags & (eHAL_TX_RATE_HT20 | eHAL_TX_RATE_HT40))
6765 {
6766 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
6767 if (rate_flags & eHAL_TX_RATE_HT40)
6768 {
6769 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
6770 }
Leo Chang6f8870f2013-03-26 18:11:36 -07006771 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006772 if (rate_flags & eHAL_TX_RATE_SGI)
6773 {
6774 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
6775 }
Gopichand Nakkala4c705372013-04-24 13:20:33 +05306776
Jeff Johnson295189b2012-06-20 16:38:30 -07006777#ifdef LINKSPEED_DEBUG_ENABLED
6778 pr_info("Reporting MCS rate %d flags %x\n",
6779 sinfo->txrate.mcs,
6780 sinfo->txrate.flags );
6781#endif //LINKSPEED_DEBUG_ENABLED
6782 }
6783 }
6784 else
6785 {
6786 // report current rate instead of max rate
6787
6788 if (rate_flags & eHAL_TX_RATE_LEGACY)
6789 {
6790 //provide to the UI in units of 100kbps
6791 sinfo->txrate.legacy = myRate;
6792#ifdef LINKSPEED_DEBUG_ENABLED
6793 pr_info("Reporting actual legacy rate %d\n", sinfo->txrate.legacy);
6794#endif //LINKSPEED_DEBUG_ENABLED
6795 }
6796 else
6797 {
6798 //must be MCS
6799 sinfo->txrate.mcs = pAdapter->hdd_stats.ClassA_stat.mcs_index;
Leo Chang6f8870f2013-03-26 18:11:36 -07006800#ifdef WLAN_FEATURE_11AC
6801 sinfo->txrate.nss = 1;
6802 if (rate_flags & eHAL_TX_RATE_VHT80)
6803 {
6804 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
6805 }
6806 else
6807#endif /* WLAN_FEATURE_11AC */
6808 {
6809 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
6810 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006811 if (rate_flags & eHAL_TX_RATE_SGI)
6812 {
6813 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
6814 }
6815 if (rate_flags & eHAL_TX_RATE_HT40)
6816 {
6817 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
6818 }
Leo Chang6f8870f2013-03-26 18:11:36 -07006819#ifdef WLAN_FEATURE_11AC
6820 else if (rate_flags & eHAL_TX_RATE_VHT80)
6821 {
6822 sinfo->txrate.flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
6823 }
6824#endif /* WLAN_FEATURE_11AC */
Jeff Johnson295189b2012-06-20 16:38:30 -07006825#ifdef LINKSPEED_DEBUG_ENABLED
6826 pr_info("Reporting actual MCS rate %d flags %x\n",
6827 sinfo->txrate.mcs,
6828 sinfo->txrate.flags );
6829#endif //LINKSPEED_DEBUG_ENABLED
6830 }
6831 }
6832 sinfo->filled |= STATION_INFO_TX_BITRATE;
6833
Madan Mohan Koyyalamudi4d4d2812012-09-24 14:08:29 -07006834 sinfo->tx_packets =
6835 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[0] +
6836 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[1] +
6837 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[2] +
6838 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[3];
6839
6840 sinfo->tx_retries =
6841 pAdapter->hdd_stats.summary_stat.retry_cnt[0] +
6842 pAdapter->hdd_stats.summary_stat.retry_cnt[1] +
6843 pAdapter->hdd_stats.summary_stat.retry_cnt[2] +
6844 pAdapter->hdd_stats.summary_stat.retry_cnt[3];
6845
6846 sinfo->tx_failed =
6847 pAdapter->hdd_stats.summary_stat.fail_cnt[0] +
6848 pAdapter->hdd_stats.summary_stat.fail_cnt[1] +
6849 pAdapter->hdd_stats.summary_stat.fail_cnt[2] +
6850 pAdapter->hdd_stats.summary_stat.fail_cnt[3];
6851
6852 sinfo->filled |=
6853 STATION_INFO_TX_PACKETS |
6854 STATION_INFO_TX_RETRIES |
6855 STATION_INFO_TX_FAILED;
6856
6857 EXIT();
6858 return 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07006859}
6860
6861static int wlan_hdd_cfg80211_set_power_mgmt(struct wiphy *wiphy,
Sameer Thalappilc9f26e92013-06-07 10:11:06 -07006862 struct net_device *dev, bool mode, int timeout)
Jeff Johnson295189b2012-06-20 16:38:30 -07006863{
6864 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05306865 hdd_context_t *pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -07006866 VOS_STATUS vos_status;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306867 int status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006868
Jeff Johnsone7245742012-09-05 17:12:55 -07006869 ENTER();
6870
Jeff Johnson295189b2012-06-20 16:38:30 -07006871 if (NULL == pAdapter)
6872 {
6873 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Adapter is NULL\n", __func__);
6874 return -ENODEV;
6875 }
6876
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05306877 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306878 status = wlan_hdd_validate_context(pHddCtx);
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05306879
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306880 if (0 != status)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306881 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306882 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6883 "%s: HDD context is not valid", __func__);
6884 return status;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306885 }
6886
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05306887 if ((DRIVER_POWER_MODE_AUTO == !mode) &&
6888 (TRUE == pHddCtx->hdd_wlan_suspended) &&
6889 (pHddCtx->cfg_ini->fhostArpOffload) &&
6890 (eConnectionState_Associated ==
6891 (WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))->conn_info.connState))
6892 {
Gopichand Nakkalab03e8082013-05-30 18:09:25 +05306893 vos_status = hdd_conf_arp_offload(pAdapter, TRUE);
Gopichand Nakkala20c4c042013-04-19 22:08:55 +05306894 if (!VOS_IS_STATUS_SUCCESS(vos_status))
6895 {
6896 hddLog(VOS_TRACE_LEVEL_INFO,
6897 "%s:Failed to enable ARPOFFLOAD Feature %d\n",
6898 __func__, vos_status);
6899 }
6900 }
6901
Jeff Johnson295189b2012-06-20 16:38:30 -07006902 /**The get power cmd from the supplicant gets updated by the nl only
6903 *on successful execution of the function call
6904 *we are oppositely mapped w.r.t mode in the driver
6905 **/
6906 vos_status = wlan_hdd_enter_bmps(pAdapter, !mode);
6907
Jeff Johnsone7245742012-09-05 17:12:55 -07006908 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07006909 if (VOS_STATUS_E_FAILURE == vos_status)
6910 {
6911 return -EINVAL;
6912 }
6913 return 0;
6914}
6915
6916
6917#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
6918static int wlan_hdd_set_default_mgmt_key(struct wiphy *wiphy,
6919 struct net_device *netdev,
6920 u8 key_index)
6921{
Jeff Johnsone7245742012-09-05 17:12:55 -07006922 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07006923 return 0;
6924}
Gopichand Nakkala747461f2013-04-24 19:24:45 +05306925#endif //LINUX_VERSION_CODE
Jeff Johnson295189b2012-06-20 16:38:30 -07006926
6927#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
6928static int wlan_hdd_set_txq_params(struct wiphy *wiphy,
6929 struct net_device *dev,
6930 struct ieee80211_txq_params *params)
6931{
Jeff Johnsone7245742012-09-05 17:12:55 -07006932 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07006933 return 0;
6934}
6935#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
6936static int wlan_hdd_set_txq_params(struct wiphy *wiphy,
6937 struct ieee80211_txq_params *params)
6938{
Jeff Johnsone7245742012-09-05 17:12:55 -07006939 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07006940 return 0;
6941}
6942#endif //LINUX_VERSION_CODE
6943
6944static int wlan_hdd_cfg80211_del_station(struct wiphy *wiphy,
6945 struct net_device *dev, u8 *mac)
6946{
6947 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306948 hdd_context_t *pHddCtx;
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08006949 VOS_STATUS vos_status;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306950 int status;
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08006951 v_U8_t staId;
Jeff Johnson295189b2012-06-20 16:38:30 -07006952
Jeff Johnsone7245742012-09-05 17:12:55 -07006953 ENTER();
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306954 if ( NULL == pAdapter )
Jeff Johnson295189b2012-06-20 16:38:30 -07006955 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306956 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Adapter" ,__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07006957 return -EINVAL;
6958 }
6959
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306960 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
6961 status = wlan_hdd_validate_context(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07006962
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306963 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006964 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05306965 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6966 "%s: HDD context is not valid", __func__);
6967 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006968 }
6969
Jeff Johnson295189b2012-06-20 16:38:30 -07006970 if ( (WLAN_HDD_SOFTAP == pAdapter->device_mode)
Jeff Johnson295189b2012-06-20 16:38:30 -07006971 || (WLAN_HDD_P2P_GO == pAdapter->device_mode)
Jeff Johnson295189b2012-06-20 16:38:30 -07006972 )
6973 {
6974 if( NULL == mac )
6975 {
6976 v_U16_t i;
6977 for(i = 0; i < WLAN_MAX_STA_COUNT; i++)
6978 {
Rajesh Chauhan18488fc2013-08-22 10:15:03 -07006979 if ((pAdapter->aStaInfo[i].isUsed) &&
6980 (!pAdapter->aStaInfo[i].isDeauthInProgress))
Jeff Johnson295189b2012-06-20 16:38:30 -07006981 {
6982 u8 *macAddr = pAdapter->aStaInfo[i].macAddrSTA.bytes;
6983 hddLog(VOS_TRACE_LEVEL_INFO,
6984 "%s: Delete STA with MAC::"
6985 "%02x:%02x:%02x:%02x:%02x:%02x",
6986 __func__,
6987 macAddr[0], macAddr[1], macAddr[2],
6988 macAddr[3], macAddr[4], macAddr[5]);
Rajesh Chauhan18488fc2013-08-22 10:15:03 -07006989 vos_status = hdd_softap_sta_deauth(pAdapter, macAddr);
6990 if (VOS_IS_STATUS_SUCCESS(vos_status))
6991 pAdapter->aStaInfo[i].isDeauthInProgress = TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006992 }
6993 }
6994 }
6995 else
6996 {
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08006997
6998 vos_status = hdd_softap_GetStaId(pAdapter,(v_MACADDR_t *)mac, &staId);
6999 if (!VOS_IS_STATUS_SUCCESS(vos_status))
7000 {
7001 hddLog(VOS_TRACE_LEVEL_INFO,
7002 "%s: Skip this DEL STA as this is not used::"
7003 "%02x:%02x:%02x:%02x:%02x:%02x",
7004 __func__,
7005 mac[0], mac[1], mac[2],
7006 mac[3], mac[4], mac[5]);
7007 return -ENOENT;
7008 }
7009
7010 if( pAdapter->aStaInfo[staId].isDeauthInProgress == TRUE)
7011 {
7012 hddLog(VOS_TRACE_LEVEL_INFO,
7013 "%s: Skip this DEL STA as deauth is in progress::"
7014 "%02x:%02x:%02x:%02x:%02x:%02x",
7015 __func__,
7016 mac[0], mac[1], mac[2],
7017 mac[3], mac[4], mac[5]);
7018 return -ENOENT;
7019 }
7020
7021 pAdapter->aStaInfo[staId].isDeauthInProgress = TRUE;
7022
Jeff Johnson295189b2012-06-20 16:38:30 -07007023 hddLog(VOS_TRACE_LEVEL_INFO,
7024 "%s: Delete STA with MAC::"
7025 "%02x:%02x:%02x:%02x:%02x:%02x",
7026 __func__,
7027 mac[0], mac[1], mac[2],
7028 mac[3], mac[4], mac[5]);
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08007029
7030 vos_status = hdd_softap_sta_deauth(pAdapter, mac);
7031 if (!VOS_IS_STATUS_SUCCESS(vos_status))
7032 {
7033 pAdapter->aStaInfo[staId].isDeauthInProgress = FALSE;
7034 hddLog(VOS_TRACE_LEVEL_INFO,
7035 "%s: STA removal failed for ::"
7036 "%02x:%02x:%02x:%02x:%02x:%02x",
7037 __func__,
7038 mac[0], mac[1], mac[2],
7039 mac[3], mac[4], mac[5]);
7040 return -ENOENT;
7041 }
7042
Jeff Johnson295189b2012-06-20 16:38:30 -07007043 }
7044 }
7045
7046 EXIT();
7047
7048 return 0;
7049}
7050
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007051static int wlan_hdd_cfg80211_add_station(struct wiphy *wiphy,
7052 struct net_device *dev, u8 *mac, struct station_parameters *params)
7053{
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007054 int status = -EPERM;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007055#ifdef FEATURE_WLAN_TDLS
7056 u32 mask, set;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007057 ENTER();
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007058 mask = params->sta_flags_mask;
7059
7060 set = params->sta_flags_set;
7061
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007062#ifdef WLAN_FEATURE_TDLS_DEBUG
7063 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7064 "%s: mask 0x%x set 0x%x " MAC_ADDRESS_STR,
7065 __func__, mask, set, MAC_ADDR_ARRAY(mac));
7066#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007067
7068 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
7069 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
Gopichand Nakkala681989c2013-03-06 22:27:48 -08007070 status = wlan_hdd_tdls_add_station(wiphy, dev, mac, 0, NULL);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007071 }
7072 }
7073#endif
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007074 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007075}
7076
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007077
7078#ifdef FEATURE_WLAN_LFR
7079static int wlan_hdd_cfg80211_set_pmksa(struct wiphy *wiphy, struct net_device *dev,
Jeff Johnsond13512a2012-07-17 11:42:19 -07007080 struct cfg80211_pmksa *pmksa)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007081{
7082#define MAX_PMKSAIDS_IN_CACHE 8
7083 static tPmkidCacheInfo PMKIDCache[MAX_PMKSAIDS_IN_CACHE]; // HDD Local cache
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307084 static tANI_U32 i; // HDD Local Cache index
7085 tANI_U32 j=0;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007086 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7087 tHalHandle halHandle;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307088 eHalStatus result;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307089 int status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007090 tANI_U8 BSSIDMatched = 0;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307091 hdd_context_t *pHddCtx;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307092
Jeff Johnsone7245742012-09-05 17:12:55 -07007093 ENTER();
7094
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307095 // Validate pAdapter
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307096 if ( NULL == pAdapter )
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007097 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307098 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Adapter" ,__func__);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007099 return -EINVAL;
7100 }
7101
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307102 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7103 status = wlan_hdd_validate_context(pHddCtx);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007104
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307105 if (0 != status)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007106 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307107 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7108 "%s: HDD context is not valid", __func__);
7109 return status;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007110 }
7111
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307112 // Retrieve halHandle
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007113 halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
7114
7115 for (j = 0; j < i; j++)
7116 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307117 if(vos_mem_compare(PMKIDCache[j].BSSID,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007118 pmksa->bssid, WNI_CFG_BSSID_LEN))
7119 {
7120 /* BSSID matched previous entry. Overwrite it. */
7121 BSSIDMatched = 1;
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307122 vos_mem_copy(PMKIDCache[j].BSSID,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007123 pmksa->bssid, WNI_CFG_BSSID_LEN);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307124 vos_mem_copy(PMKIDCache[j].PMKID,
7125 pmksa->pmkid,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007126 CSR_RSN_PMKID_SIZE);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307127 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Reusing cache entry %d.",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007128 __func__, j );
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007129 dump_bssid(pmksa->bssid);
7130 dump_pmkid(halHandle, pmksa->pmkid);
7131 break;
7132 }
7133 }
7134
Madan Mohan Koyyalamudic4b317d2012-10-18 19:43:08 -07007135 /* Check we compared all entries,if then take the first slot now */
7136 if(j == MAX_PMKSAIDS_IN_CACHE) i=0;
7137
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007138 if (!BSSIDMatched)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307139 {
7140 // Now, we DON'T have a BSSID match, so take a new entry in the cache.
7141 vos_mem_copy(PMKIDCache[i].BSSID,
7142 pmksa->bssid, ETHER_ADDR_LEN);
7143 vos_mem_copy(PMKIDCache[i].PMKID,
7144 pmksa->pmkid,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007145 CSR_RSN_PMKID_SIZE);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307146 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Adding a new cache entry %d.",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007147 __func__, i );
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007148 dump_bssid(pmksa->bssid);
7149 dump_pmkid(halHandle, pmksa->pmkid);
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307150 // Increment the HDD Local Cache index
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007151 // The "i=0" doesn't work for the call to sme_RoamSetPMKIDCache() - LFR FIXME
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307152 if (i<=(MAX_PMKSAIDS_IN_CACHE-1)) i++; else i=0;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007153 }
7154
7155
7156 // Calling csrRoamSetPMKIDCache to configure the PMKIDs into the cache
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307157 //hddLog(LOG1, FL("%s: Calling csrRoamSetPMKIDCache with %d cache entries."),
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007158 // __func__, i );
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307159 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Calling csrRoamSetPMKIDCache with %d cache entries.",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007160 __func__, i );
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007161 // Finally set the PMKSA ID Cache in CSR
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307162 result = sme_RoamSetPMKIDCache(halHandle,pAdapter->sessionId,
7163 PMKIDCache,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007164 i );
7165 return 0;
7166}
7167
7168
7169static int wlan_hdd_cfg80211_del_pmksa(struct wiphy *wiphy, struct net_device *dev,
Jeff Johnsond13512a2012-07-17 11:42:19 -07007170 struct cfg80211_pmksa *pmksa)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007171{
Jeff Johnsone7245742012-09-05 17:12:55 -07007172 ENTER();
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007173 // TODO: Implement this later.
7174 return 0;
7175}
7176
7177static int wlan_hdd_cfg80211_flush_pmksa(struct wiphy *wiphy, struct net_device *dev)
7178{
Jeff Johnsone7245742012-09-05 17:12:55 -07007179 ENTER();
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007180 // TODO: Implement this later.
7181 return 0;
7182}
7183#endif
7184
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07007185#if defined(WLAN_FEATURE_VOWIFI_11R) && defined(KERNEL_SUPPORT_11R_CFG80211)
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307186static int wlan_hdd_cfg80211_update_ft_ies(struct wiphy *wiphy,
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07007187 struct net_device *dev, struct cfg80211_update_ft_ies_params *ftie)
7188{
7189 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7190 hdd_station_ctx_t *pHddStaCtx;
7191
7192 if (NULL == pAdapter)
7193 {
7194 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Adapter is NULL\n", __func__);
7195 return -ENODEV;
7196 }
7197
7198 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
7199
7200 // Added for debug on reception of Re-assoc Req.
7201 if (eConnectionState_Associated != pHddStaCtx->conn_info.connState)
7202 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307203 hddLog(LOGE, FL("Called with Ie of length = %d when not associated\n"),
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07007204 ftie->ie_len);
7205 hddLog(LOGE, FL("Should be Re-assoc Req IEs\n"));
7206 }
7207
7208#ifdef WLAN_FEATURE_VOWIFI_11R_DEBUG
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307209 hddLog(LOGE, FL("%s called with Ie of length = %d\n"), __func__,
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07007210 ftie->ie_len);
7211#endif
7212
7213 // Pass the received FT IEs to SME
Gopichand Nakkala356fb102013-03-06 12:34:04 +05307214 sme_SetFTIEs( WLAN_HDD_GET_HAL_CTX(pAdapter), pAdapter->sessionId,
7215 (const u8 *)ftie->ie,
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07007216 ftie->ie_len);
7217 return 0;
7218}
7219#endif
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007220
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307221#ifdef FEATURE_WLAN_SCAN_PNO
7222
7223void hdd_cfg80211_sched_scan_done_callback(void *callbackContext,
7224 tSirPrefNetworkFoundInd *pPrefNetworkFoundInd)
7225{
7226 int ret;
7227 hdd_adapter_t* pAdapter = (hdd_adapter_t*)callbackContext;
7228 hdd_context_t *pHddCtx;
7229
7230 if (NULL == pAdapter)
7231 {
7232 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
7233 "%s: HDD adapter is Null", __func__);
7234 return ;
7235 }
7236
7237 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
7238 if (NULL == pHddCtx)
7239 {
7240 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7241 "%s: HDD context is Null!!!", __func__);
7242 return ;
7243 }
7244
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05307245 spin_lock(&pHddCtx->schedScan_lock);
7246 if (TRUE == pHddCtx->isWiphySuspended)
7247 {
7248 pHddCtx->isSchedScanUpdatePending = TRUE;
7249 spin_unlock(&pHddCtx->schedScan_lock);
7250 hddLog(VOS_TRACE_LEVEL_INFO,
7251 "%s: Update cfg80211 scan database after it resume", __func__);
7252 return ;
7253 }
7254 spin_unlock(&pHddCtx->schedScan_lock);
7255
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307256 ret = wlan_hdd_cfg80211_update_bss(pHddCtx->wiphy, pAdapter);
7257
7258 if (0 > ret)
7259 hddLog(VOS_TRACE_LEVEL_INFO, "%s: NO SCAN result", __func__);
7260
7261 cfg80211_sched_scan_results(pHddCtx->wiphy);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05307262 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
7263 "%s: cfg80211 scan result database updated", __func__);
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307264}
7265
7266/*
7267 * FUNCTION: wlan_hdd_cfg80211_sched_scan_start
7268 * NL interface to enable PNO
7269 */
7270static int wlan_hdd_cfg80211_sched_scan_start(struct wiphy *wiphy,
7271 struct net_device *dev, struct cfg80211_sched_scan_request *request)
7272{
7273 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7274 tpSirPNOScanReq pPnoRequest = NULL;
7275 hdd_context_t *pHddCtx;
7276 tHalHandle hHal;
Madan Mohan Koyyalamudi1d16f462013-08-27 16:25:34 +05307277 v_U32_t i, indx, num_ch, tempInterval;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307278 u8 valid_ch[WNI_CFG_VALID_CHANNEL_LIST_LEN];
7279 u8 channels_allowed[WNI_CFG_VALID_CHANNEL_LIST_LEN];
7280 v_U32_t num_channels_allowed = WNI_CFG_VALID_CHANNEL_LIST_LEN;
7281 eHalStatus status = eHAL_STATUS_FAILURE;
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307282 int ret = 0;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307283
7284 if (NULL == pAdapter)
7285 {
7286 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
7287 "%s: HDD adapter is Null", __func__);
7288 return -ENODEV;
7289 }
7290
7291 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05307292 ret = wlan_hdd_validate_context(pHddCtx);
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307293
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05307294 if (0 != ret)
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307295 {
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05307296 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7297 "%s: HDD context is not valid", __func__);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307298 return -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307299 }
7300
7301 hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
7302 if (NULL == hHal)
7303 {
7304 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7305 "%s: HAL context is Null!!!", __func__);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05307306 return -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307307 }
7308
7309 pPnoRequest = (tpSirPNOScanReq) vos_mem_malloc(sizeof (tSirPNOScanReq));
7310 if (NULL == pPnoRequest)
7311 {
7312 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
7313 "%s: vos_mem_malloc failed", __func__);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307314 return -ENOMEM;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307315 }
7316
7317 pPnoRequest->enable = 1; /*Enable PNO */
7318 pPnoRequest->ucNetworksCount = request->n_match_sets;
7319
7320 if (( !pPnoRequest->ucNetworksCount ) ||
7321 ( pPnoRequest->ucNetworksCount > SIR_PNO_MAX_SUPP_NETWORKS ))
7322 {
7323 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7324 "Network input is not correct");
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307325 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307326 goto error;
7327 }
7328
7329 if ( SIR_PNO_MAX_NETW_CHANNELS_EX < request->n_channels )
7330 {
7331 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7332 "Incorrect number of channels");
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307333 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307334 goto error;
7335 }
7336
7337 /* Framework provides one set of channels(all)
7338 * common for all saved profile */
7339 if (0 != ccmCfgGetStr(hHal, WNI_CFG_VALID_CHANNEL_LIST,
7340 channels_allowed, &num_channels_allowed))
7341 {
7342 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7343 "%s: failed to get valid channel list", __func__);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307344 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307345 goto error;
7346 }
7347 /* Checking each channel against allowed channel list */
7348 num_ch = 0;
7349 for (i = 0; i < request->n_channels; i++)
7350 {
7351 for (indx = 0; indx < num_channels_allowed; indx++)
7352 {
7353 if (request->channels[i]->hw_value == channels_allowed[indx])
7354 {
7355 valid_ch[num_ch++] = request->channels[i]->hw_value;
7356 break ;
7357 }
7358 }
7359 }
7360
7361 /* Filling per profile params */
7362 for (i = 0; i < pPnoRequest->ucNetworksCount; i++)
7363 {
7364 pPnoRequest->aNetworks[i].ssId.length =
7365 request->match_sets[i].ssid.ssid_len;
7366
7367 if (( 0 == pPnoRequest->aNetworks[i].ssId.length ) ||
7368 ( pPnoRequest->aNetworks[i].ssId.length > 32 ) )
7369 {
7370 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7371 "SSID Len %d is not correct for network %d",
7372 pPnoRequest->aNetworks[i].ssId.length, i);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307373 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307374 goto error;
7375 }
7376
7377 memcpy(pPnoRequest->aNetworks[i].ssId.ssId,
7378 request->match_sets[i].ssid.ssid,
7379 request->match_sets[i].ssid.ssid_len);
7380 pPnoRequest->aNetworks[i].authentication = 0; /*eAUTH_TYPE_ANY*/
7381 pPnoRequest->aNetworks[i].encryption = 0; /*eED_ANY*/
7382 pPnoRequest->aNetworks[i].bcastNetwType = 0; /*eBCAST_UNKNOWN*/
7383
7384 /*Copying list of valid channel into request */
7385 memcpy(pPnoRequest->aNetworks[i].aChannels, valid_ch, num_ch);
7386 pPnoRequest->aNetworks[i].ucChannelCount = num_ch;
7387
7388 pPnoRequest->aNetworks[i].rssiThreshold = 0; //Default value
7389 }
7390
Madan Mohan Koyyalamudi1d16f462013-08-27 16:25:34 +05307391 /* Driver gets only one time interval which is hardcoded in
7392 * supplicant for 10000ms. Taking power consumption into account 6 timers
7393 * will be used, Timervalue is increased exponentially i.e 10,20,40,
7394 * 80,160,320 secs. And number of scan cycle for each timer
7395 * is configurable through INI param gPNOScanTimerRepeatValue.
7396 * If it is set to 0 only one timer will be used and PNO scan cycle
7397 * will be repeated after each interval specified by supplicant
7398 * till PNO is disabled.
7399 */
7400 if (0 == pHddCtx->cfg_ini->configPNOScanTimerRepeatValue)
7401 pPnoRequest->scanTimers.ucScanTimersCount = HDD_PNO_SCAN_TIMERS_SET_ONE;
7402 else
7403 pPnoRequest->scanTimers.ucScanTimersCount =
7404 HDD_PNO_SCAN_TIMERS_SET_MULTIPLE;
7405
7406 tempInterval = (request->interval)/1000;
7407 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
7408 "Base scan interval = %d PNOScanTimerRepeatValue = %d",
7409 tempInterval, pHddCtx->cfg_ini->configPNOScanTimerRepeatValue);
7410 for ( i = 0; i < pPnoRequest->scanTimers.ucScanTimersCount; i++)
7411 {
7412 pPnoRequest->scanTimers.aTimerValues[i].uTimerRepeat =
7413 pHddCtx->cfg_ini->configPNOScanTimerRepeatValue;
7414 pPnoRequest->scanTimers.aTimerValues[i].uTimerValue = tempInterval;
7415 tempInterval *= 2;
7416 }
7417 //Repeat last timer until pno disabled.
7418 pPnoRequest->scanTimers.aTimerValues[i-1].uTimerRepeat = 0;
7419
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307420 pPnoRequest->modePNO = SIR_PNO_MODE_ON_SUSPEND;
7421
7422 status = sme_SetPreferredNetworkList(WLAN_HDD_GET_HAL_CTX(pAdapter),
7423 pPnoRequest, pAdapter->sessionId,
7424 hdd_cfg80211_sched_scan_done_callback, pAdapter);
7425 if (eHAL_STATUS_SUCCESS != status)
7426 {
7427 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7428 "Failed to enable PNO");
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307429 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307430 goto error;
7431 }
7432
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05307433 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
7434 "PNO scanRequest offloaded");
7435
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307436error:
7437 vos_mem_free(pPnoRequest);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307438 return ret;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307439}
7440
7441/*
7442 * FUNCTION: wlan_hdd_cfg80211_sched_scan_stop
7443 * NL interface to disable PNO
7444 */
7445static int wlan_hdd_cfg80211_sched_scan_stop(struct wiphy *wiphy,
7446 struct net_device *dev)
7447{
7448 eHalStatus status = eHAL_STATUS_FAILURE;
7449 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7450 hdd_context_t *pHddCtx;
7451 tHalHandle hHal;
7452 tpSirPNOScanReq pPnoRequest = NULL;
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307453 int ret = 0;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307454
7455 ENTER();
7456
7457 if (NULL == pAdapter)
7458 {
7459 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
7460 "%s: HDD adapter is Null", __func__);
7461 return -ENODEV;
7462 }
7463
7464 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307465
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307466 if (NULL == pHddCtx)
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307467 {
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05307468 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307469 "%s: HDD context is Null", __func__);
7470 return -ENODEV;
7471 }
7472
7473 /* The return 0 is intentional when isLogpInProgress and
7474 * isLoadUnloadInProgress. We did observe a crash due to a return of
7475 * failure in sched_scan_stop , especially for a case where the unload
7476 * of the happens at the same time. The function __cfg80211_stop_sched_scan
7477 * was clearing rdev->sched_scan_req only when the sched_scan_stop returns
7478 * success. If it returns a failure , then its next invocation due to the
7479 * clean up of the second interface will have the dev pointer corresponding
7480 * to the first one leading to a crash.
7481 */
7482 if (pHddCtx->isLogpInProgress)
7483 {
7484 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7485 "%s: LOGP in Progress. Ignore!!!", __func__);
7486 return ret;
7487 }
7488
7489 if (pHddCtx->isLoadUnloadInProgress)
7490 {
7491 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7492 "%s: Unloading/Loading in Progress. Ignore!!!", __func__);
7493 return ret;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307494 }
7495
7496 hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
7497 if (NULL == hHal)
7498 {
7499 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7500 "%s: HAL context is Null!!!", __func__);
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05307501 return -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307502 }
7503
7504 pPnoRequest = (tpSirPNOScanReq) vos_mem_malloc(sizeof (tSirPNOScanReq));
7505 if (NULL == pPnoRequest)
7506 {
7507 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
7508 "%s: vos_mem_malloc failed", __func__);
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307509 return -ENOMEM;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307510 }
7511
7512 memset(pPnoRequest, 0, sizeof (tSirPNOScanReq));
7513 pPnoRequest->enable = 0; /* Disable PNO */
7514 pPnoRequest->ucNetworksCount = 0;
7515
7516 status = sme_SetPreferredNetworkList(hHal, pPnoRequest,
7517 pAdapter->sessionId,
7518 NULL, pAdapter);
7519 if (eHAL_STATUS_SUCCESS != status)
7520 {
7521 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7522 "Failed to disabled PNO");
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307523 ret = -EINVAL;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307524 }
7525
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05307526 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
7527 "%s: PNO scan disabled", __func__);
7528
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307529 vos_mem_free(pPnoRequest);
7530
7531 EXIT();
Kamath Vinayakba5313f2013-08-22 15:52:39 +05307532 return ret;
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05307533}
7534
7535#endif /*FEATURE_WLAN_SCAN_PNO*/
7536
7537
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007538#ifdef FEATURE_WLAN_TDLS
7539static int wlan_hdd_cfg80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
7540 u8 *peer, u8 action_code, u8 dialog_token,
7541 u16 status_code, const u8 *buf, size_t len)
7542{
7543
7544 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7545 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007546 u8 peerMac[6];
7547 VOS_STATUS status;
Gopichand Nakkala05922802013-03-14 12:23:19 -07007548 int max_sta_failed = 0;
Hoonki Leea34dd892013-02-05 22:56:02 -08007549 int responder;
Hoonki Leed37cbb32013-04-20 00:31:14 -07007550 long rc;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007551
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007552 if (NULL == pHddCtx || NULL == pHddCtx->cfg_ini)
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007553 {
Gopichand Nakkala747461f2013-04-24 19:24:45 +05307554 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007555 "Invalid arguments");
7556 return -EINVAL;
7557 }
7558
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08007559 if (pHddCtx->isLogpInProgress)
7560 {
7561 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7562 "%s:LOGP in Progress. Ignore!!!", __func__);
Gopichand Nakkala05922802013-03-14 12:23:19 -07007563 wlan_hdd_tdls_set_link_status(pAdapter, peer, eTDLS_LINK_IDLE);
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08007564 return -EBUSY;
7565 }
7566
Hoonki Lee27511902013-03-14 18:19:06 -07007567 if (eTDLS_SUPPORT_NOT_ENABLED == pHddCtx->tdls_mode)
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007568 {
Hoonki Lee27511902013-03-14 18:19:06 -07007569 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
7570 "%s: TDLS mode is disabled OR not enabled in FW."
7571 MAC_ADDRESS_STR " action %d declined.",
7572 __func__, MAC_ADDR_ARRAY(peer), action_code);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007573 return -ENOTSUPP;
7574 }
Lee Hoonkic1262f22013-01-24 21:59:00 -08007575
Hoonki Lee27511902013-03-14 18:19:06 -07007576 /* other than teardown frame, other mgmt frames are not sent if disabled */
7577 if (SIR_MAC_TDLS_TEARDOWN != action_code)
7578 {
7579 /* if tdls_mode is disabled to respond to peer's request */
7580 if (eTDLS_SUPPORT_DISABLED == pHddCtx->tdls_mode)
7581 {
7582 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
7583 "%s: " MAC_ADDRESS_STR
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07007584 " TDLS mode is disabled. action %d declined.",
7585 __func__, MAC_ADDR_ARRAY(peer), action_code);
Hoonki Lee27511902013-03-14 18:19:06 -07007586
7587 return -ENOTSUPP;
7588 }
7589 }
7590
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007591 if (WLAN_IS_TDLS_SETUP_ACTION(action_code))
7592 {
Hoonki Leefb8df672013-04-10 18:20:34 -07007593 if (NULL != wlan_hdd_tdls_is_progress(pHddCtx, peer, TRUE, TRUE))
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007594 {
7595 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007596 "%s: " MAC_ADDRESS_STR
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07007597 " TDLS setup is ongoing. action %d declined.",
7598 __func__, MAC_ADDR_ARRAY(peer), action_code);
7599 return -EPERM;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007600 }
7601 }
7602
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007603 if (SIR_MAC_TDLS_SETUP_REQ == action_code ||
7604 SIR_MAC_TDLS_SETUP_RSP == action_code )
Lee Hoonkic1262f22013-01-24 21:59:00 -08007605 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08007606 if (HDD_MAX_NUM_TDLS_STA <= wlan_hdd_tdlsConnectedPeers(pAdapter))
Lee Hoonkic1262f22013-01-24 21:59:00 -08007607 {
7608 /* supplicant still sends tdls_mgmt(SETUP_REQ) even after
7609 we return error code at 'add_station()'. Hence we have this
7610 check again in addtion to add_station().
7611 Anyway, there is no hard to double-check. */
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007612 if (SIR_MAC_TDLS_SETUP_REQ == action_code)
Lee Hoonkic1262f22013-01-24 21:59:00 -08007613 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007614 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7615 "%s: " MAC_ADDRESS_STR
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07007616 " TDLS Max peer already connected. action %d declined.",
7617 __func__, MAC_ADDR_ARRAY(peer), action_code);
Gopichand Nakkala05922802013-03-14 12:23:19 -07007618 goto error;
Lee Hoonkic1262f22013-01-24 21:59:00 -08007619 }
7620 else
7621 {
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007622 /* maximum reached. tweak to send error code to peer and return
7623 error code to supplicant */
Lee Hoonkic1262f22013-01-24 21:59:00 -08007624 status_code = eSIR_MAC_UNSPEC_FAILURE_STATUS;
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007625 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7626 "%s: " MAC_ADDRESS_STR
7627 " TDLS Max peer already connected send response status %d",
7628 __func__, MAC_ADDR_ARRAY(peer), status_code);
Gopichand Nakkala05922802013-03-14 12:23:19 -07007629 max_sta_failed = -EPERM;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007630 /* fall through to send setup resp with failure status
7631 code */
Lee Hoonkic1262f22013-01-24 21:59:00 -08007632 }
7633 }
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007634 else
7635 {
7636 hddTdlsPeer_t *pTdlsPeer;
Gopichand Nakkala4327a152013-03-04 23:22:42 -08007637 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peer);
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07007638 if (pTdlsPeer && TDLS_IS_CONNECTED(pTdlsPeer))
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007639 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007640 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07007641 "%s:" MAC_ADDRESS_STR " already connected. action %d declined.",
7642 __func__, MAC_ADDR_ARRAY(peer), action_code);
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007643 return -EPERM;
7644 }
7645 }
Lee Hoonkic1262f22013-01-24 21:59:00 -08007646 }
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007647 vos_mem_copy(peerMac, peer, 6);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007648
Hoonki Lee1090c6a2013-01-16 17:40:54 -08007649#ifdef WLAN_FEATURE_TDLS_DEBUG
7650 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007651 "%s: " MAC_ADDRESS_STR " action %d, dialog_token %d status %d, len = %d",
7652 "tdls_mgmt", MAC_ADDR_ARRAY(peer),
7653 action_code, dialog_token, status_code, len);
Hoonki Lee1090c6a2013-01-16 17:40:54 -08007654#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007655
Hoonki Leea34dd892013-02-05 22:56:02 -08007656 /*Except teardown responder will not be used so just make 0*/
7657 responder = 0;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007658 if (SIR_MAC_TDLS_TEARDOWN == action_code)
Hoonki Leea34dd892013-02-05 22:56:02 -08007659 {
Gopichand Nakkala97a65fd2013-04-16 16:59:38 -07007660
7661 hddTdlsPeer_t *pTdlsPeer;
7662 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peerMac);
7663
7664 if(pTdlsPeer && TDLS_IS_CONNECTED(pTdlsPeer))
7665 responder = pTdlsPeer->is_responder;
7666 else
Hoonki Leea34dd892013-02-05 22:56:02 -08007667 {
Gopichand Nakkala97a65fd2013-04-16 16:59:38 -07007668 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7669 "%s: " MAC_ADDRESS_STR " peer doesn't exist or not connected %d dialog_token %d status %d, len = %d",
7670 __func__, MAC_ADDR_ARRAY(peer), (NULL == pTdlsPeer) ? -1 : pTdlsPeer->link_status,
7671 dialog_token, status_code, len);
7672 return -EPERM;
Hoonki Leea34dd892013-02-05 22:56:02 -08007673 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007674 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007675
Gopichand Nakkala2f1ff152013-07-01 11:27:43 +05307676 /* For explicit trigger of DIS_REQ come out of BMPS for
7677 successfully receiving DIS_RSP from peer. */
Hoonki Lee14621352013-04-16 17:51:19 -07007678 if ((SIR_MAC_TDLS_SETUP_RSP == action_code) ||
Gopichand Nakkala2f1ff152013-07-01 11:27:43 +05307679 (SIR_MAC_TDLS_DIS_RSP == action_code) ||
7680 (SIR_MAC_TDLS_DIS_REQ == action_code))
Hoonki Lee14621352013-04-16 17:51:19 -07007681 {
7682 if (TRUE == sme_IsPmcBmps(WLAN_HDD_GET_HAL_CTX(pAdapter)))
7683 {
7684 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
Gopichand Nakkala2f1ff152013-07-01 11:27:43 +05307685 "%s: Sending frame action_code %u.Disable BMPS", __func__, action_code);
Hoonki Lee14621352013-04-16 17:51:19 -07007686 hdd_disable_bmps_imps(pHddCtx, WLAN_HDD_INFRA_STATION);
7687 }
Gopichand Nakkala2f1ff152013-07-01 11:27:43 +05307688 if (SIR_MAC_TDLS_DIS_REQ != action_code)
7689 wlan_hdd_tdls_set_cap(pAdapter, peerMac, eTDLS_CAP_SUPPORTED);
Hoonki Lee14621352013-04-16 17:51:19 -07007690 }
7691
Hoonki Lee5305c3a2013-04-29 23:28:59 -07007692 /* make sure doesn't call send_mgmt() while it is pending */
7693 if (TDLS_CTX_MAGIC == pAdapter->mgmtTxCompletionStatus)
7694 {
7695 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7696 "%s: " MAC_ADDRESS_STR " action %d couldn't sent, as one is pending. return EBUSY\n",
7697 __func__, MAC_ADDR_ARRAY(peer), action_code);
7698 return -EBUSY;
7699 }
7700
7701 pAdapter->mgmtTxCompletionStatus = TDLS_CTX_MAGIC;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007702 INIT_COMPLETION(pAdapter->tdls_mgmt_comp);
7703
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007704 status = sme_SendTdlsMgmtFrame(WLAN_HDD_GET_HAL_CTX(pAdapter), pAdapter->sessionId,
Hoonki Leea34dd892013-02-05 22:56:02 -08007705 peerMac, action_code, dialog_token, status_code, (tANI_U8 *)buf, len, responder);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007706
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007707 if (VOS_STATUS_SUCCESS != status)
7708 {
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007709 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7710 "%s: sme_SendTdlsMgmtFrame failed!", __func__);
Hoonki Lee5305c3a2013-04-29 23:28:59 -07007711 pAdapter->mgmtTxCompletionStatus = FALSE;
Hoonki Lee14621352013-04-16 17:51:19 -07007712 wlan_hdd_tdls_check_bmps(pAdapter);
7713 goto error;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007714 }
7715
Hoonki Leed37cbb32013-04-20 00:31:14 -07007716 rc = wait_for_completion_interruptible_timeout(&pAdapter->tdls_mgmt_comp,
7717 msecs_to_jiffies(WAIT_TIME_TDLS_MGMT));
7718
7719 if ((rc <= 0) || (TRUE != pAdapter->mgmtTxCompletionStatus))
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007720 {
Hoonki Leed37cbb32013-04-20 00:31:14 -07007721 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7722 "%s: Mgmt Tx Completion failed status %ld TxCompletion %lu",
7723 __func__, rc, pAdapter->mgmtTxCompletionStatus);
Hoonki Lee5305c3a2013-04-29 23:28:59 -07007724 pAdapter->mgmtTxCompletionStatus = FALSE;
Hoonki Leed37cbb32013-04-20 00:31:14 -07007725 wlan_hdd_tdls_check_bmps(pAdapter);
7726 goto error;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007727 }
7728
Gopichand Nakkala05922802013-03-14 12:23:19 -07007729 if (max_sta_failed)
Hoonki Lee14621352013-04-16 17:51:19 -07007730 {
7731 wlan_hdd_tdls_check_bmps(pAdapter);
Gopichand Nakkala05922802013-03-14 12:23:19 -07007732 return max_sta_failed;
Hoonki Lee14621352013-04-16 17:51:19 -07007733 }
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007734
Hoonki Leea34dd892013-02-05 22:56:02 -08007735 if (SIR_MAC_TDLS_SETUP_RSP == action_code)
7736 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08007737 wlan_hdd_tdls_set_responder(pAdapter, peerMac, TRUE);
Hoonki Leea34dd892013-02-05 22:56:02 -08007738 }
7739 else if (SIR_MAC_TDLS_SETUP_CNF == action_code)
7740 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08007741 wlan_hdd_tdls_set_responder(pAdapter, peerMac, FALSE);
Hoonki Leea34dd892013-02-05 22:56:02 -08007742 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007743
7744 return 0;
Gopichand Nakkala05922802013-03-14 12:23:19 -07007745error:
7746 /* max_sta_failed ; we didn't set to CONNECTING for this case,
7747 because we already know that this transaction will be failed,
7748 but we weren't sure if supplicant call DISABLE_LINK or not. So,
7749 to be safe, do not change the state mahine.
7750 */
7751 if(max_sta_failed == 0 &&
7752 (WLAN_IS_TDLS_SETUP_ACTION(action_code)))
7753 wlan_hdd_tdls_set_link_status(pAdapter, peerMac, eTDLS_LINK_IDLE);
7754 return -EPERM;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007755}
7756
7757static int wlan_hdd_cfg80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
7758 u8 *peer, enum nl80211_tdls_operation oper)
7759{
7760 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7761 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307762 int status;
Hoonki Lee1090c6a2013-01-16 17:40:54 -08007763#ifdef WLAN_FEATURE_TDLS_DEBUG
7764 const char *tdls_oper_str[]= {
7765 "NL80211_TDLS_DISCOVERY_REQ",
7766 "NL80211_TDLS_SETUP",
7767 "NL80211_TDLS_TEARDOWN",
7768 "NL80211_TDLS_ENABLE_LINK",
7769 "NL80211_TDLS_DISABLE_LINK",
Gopichand Nakkala29d00192013-06-20 19:03:52 +05307770 "NL80211_TDLS_UNKNOWN_OPER"};
Hoonki Lee1090c6a2013-01-16 17:40:54 -08007771#endif
Hoonki Lee5305c3a2013-04-29 23:28:59 -07007772 hddTdlsPeer_t *pTdlsPeer;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007773
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307774 if ( NULL == peer )
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007775 {
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007776 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Chilam Ngc4244af2013-04-01 15:37:32 -07007777 "%s: Invalid arguments", __func__);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007778 return -EINVAL;
7779 }
Hoonki Lee1090c6a2013-01-16 17:40:54 -08007780
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307781 status = wlan_hdd_validate_context(pHddCtx);
7782
7783 if (0 != status)
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08007784 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05307785 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7786 "%s: HDD context is not valid", __func__);
7787 return status;
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08007788 }
7789
Hoonki Lee5305c3a2013-04-29 23:28:59 -07007790 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peer);
7791
7792 if ( NULL == pTdlsPeer ) {
7793 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: " MAC_ADDRESS_STR " (oper %d) not exsting. ignored",
7794 __func__, MAC_ADDR_ARRAY(peer), (int)oper);
7795 return -EINVAL;
7796 }
7797
Hoonki Lee1090c6a2013-01-16 17:40:54 -08007798#ifdef WLAN_FEATURE_TDLS_DEBUG
7799 if((int)oper > 4)
7800 oper = 5;
7801
7802 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Hoonki Lee5305c3a2013-04-29 23:28:59 -07007803 "%s: " MAC_ADDRESS_STR " link_status %d (%s) ", "tdls_oper",
7804 MAC_ADDR_ARRAY(peer), pTdlsPeer->link_status,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007805 tdls_oper_str[(int)oper]);
Hoonki Lee1090c6a2013-01-16 17:40:54 -08007806#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007807
7808 if( FALSE == pHddCtx->cfg_ini->fEnableTDLSSupport ||
Hoonki Lee1090c6a2013-01-16 17:40:54 -08007809 FALSE == sme_IsFeatureSupportedByFW(TDLS))
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007810 {
Hoonki Lee1090c6a2013-01-16 17:40:54 -08007811 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Chilam Ngc4244af2013-04-01 15:37:32 -07007812 "TDLS Disabled in INI OR not enabled in FW. "
7813 "Cannot process TDLS commands");
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007814 return -ENOTSUPP;
7815 }
7816
7817 switch (oper) {
7818 case NL80211_TDLS_ENABLE_LINK:
7819 {
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007820 VOS_STATUS status;
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05307821 tCsrTdlsLinkEstablishParams tdlsLinkEstablishParams;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007822
Gopichand Nakkala2f4a2822013-04-17 11:22:01 -07007823 if (!TDLS_STA_INDEX_VALID(pTdlsPeer->staId))
7824 {
7825 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Staion Index %u "
7826 MAC_ADDRESS_STR " failed",
7827 __func__, pTdlsPeer->staId, MAC_ADDR_ARRAY(peer));
7828 return -EINVAL;
7829 }
7830
Hoonki Lee5305c3a2013-04-29 23:28:59 -07007831 if (eTDLS_LINK_CONNECTED != pTdlsPeer->link_status)
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007832 {
Gopichand Nakkala24be5312013-07-02 16:47:12 +05307833 long ret;
Madan Mohan Koyyalamudice419872013-09-13 19:36:52 +05307834 if (IS_ADVANCE_TDLS_ENABLE) {
Gopichand Nakkala24be5312013-07-02 16:47:12 +05307835
Madan Mohan Koyyalamudice419872013-09-13 19:36:52 +05307836 if (0 != wlan_hdd_tdls_get_link_establish_params(
7837 pAdapter, peer,&tdlsLinkEstablishParams)) {
7838 return -EINVAL;
7839 }
7840 INIT_COMPLETION(pAdapter->tdls_link_establish_req_comp);
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05307841
Madan Mohan Koyyalamudice419872013-09-13 19:36:52 +05307842 sme_SendTdlsLinkEstablishParams(WLAN_HDD_GET_HAL_CTX(pAdapter),
7843 pAdapter->sessionId, peer, &tdlsLinkEstablishParams);
7844 /* Send TDLS peer UAPSD capabilities to the firmware and
7845 * register with the TL on after the response for this operation
7846 * is received .
7847 */
7848 ret = wait_for_completion_interruptible_timeout(
7849 &pAdapter->tdls_link_establish_req_comp,
7850 msecs_to_jiffies(WAIT_TIME_TDLS_LINK_ESTABLISH_REQ));
7851 if (ret <= 0)
7852 {
7853 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7854 "%s: Link Establish Request Faled Status %ld",
7855 __func__, ret);
7856 return -EINVAL;
7857 }
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05307858 }
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07007859 wlan_hdd_tdls_set_peer_link_status(pTdlsPeer, eTDLS_LINK_CONNECTED);
Gopichand Nakkala471708b2013-06-04 20:03:01 +05307860 /* Mark TDLS client Authenticated .*/
7861 status = WLANTL_ChangeSTAState( pHddCtx->pvosContext,
7862 pTdlsPeer->staId,
7863 WLANTL_STA_AUTHENTICATED);
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07007864 if (VOS_STATUS_SUCCESS == status)
7865 {
Hoonki Lee14621352013-04-16 17:51:19 -07007866 if (pTdlsPeer->is_responder == 0)
7867 {
7868 v_U8_t staId = (v_U8_t)pTdlsPeer->staId;
7869
7870 wlan_hdd_tdls_timer_restart(pAdapter,
7871 &pTdlsPeer->initiatorWaitTimeoutTimer,
7872 WAIT_TIME_TDLS_INITIATOR);
7873 /* suspend initiator TX until it receives direct packet from the
7874 reponder or WAIT_TIME_TDLS_INITIATOR timer expires */
7875 WLANTL_SuspendDataTx( (WLAN_HDD_GET_CTX(pAdapter))->pvosContext,
7876 &staId, NULL);
7877 }
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07007878 wlan_hdd_tdls_increment_peer_count(pAdapter);
7879 }
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007880 wlan_hdd_tdls_check_bmps(pAdapter);
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05307881
7882 /* Update TL about the UAPSD masks , to route the packets to firmware */
Gopichand Nakkala574f6d12013-06-27 19:38:43 +05307883 if ((TRUE == pHddCtx->cfg_ini->fEnableTDLSBufferSta)
7884 || pHddCtx->cfg_ini->fTDLSUapsdMask )
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05307885 {
Gopichand Nakkala574f6d12013-06-27 19:38:43 +05307886 int ac;
7887 uint8 ucAc[4] = { WLANTL_AC_VO,
7888 WLANTL_AC_VI,
7889 WLANTL_AC_BK,
7890 WLANTL_AC_BE };
7891 uint8 tlTid[4] = { 7, 5, 2, 3 } ;
7892 for(ac=0; ac < 4; ac++)
7893 {
7894 status = WLANTL_EnableUAPSDForAC( (WLAN_HDD_GET_CTX(pAdapter))->pvosContext,
7895 pTdlsPeer->staId, ucAc[ac],
7896 tlTid[ac], tlTid[ac], 0, 0,
7897 WLANTL_BI_DIR );
7898 }
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05307899 }
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007900 }
7901
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007902 }
7903 break;
7904 case NL80211_TDLS_DISABLE_LINK:
Lee Hoonkic1262f22013-01-24 21:59:00 -08007905 {
Hoonki Lee5305c3a2013-04-29 23:28:59 -07007906 if(TDLS_STA_INDEX_VALID(pTdlsPeer->staId))
Lee Hoonkic1262f22013-01-24 21:59:00 -08007907 {
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07007908 long status;
7909
7910 INIT_COMPLETION(pAdapter->tdls_del_station_comp);
7911
Lee Hoonkic1262f22013-01-24 21:59:00 -08007912 sme_DeleteTdlsPeerSta( WLAN_HDD_GET_HAL_CTX(pAdapter),
7913 pAdapter->sessionId, peer );
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07007914
7915 status = wait_for_completion_interruptible_timeout(&pAdapter->tdls_del_station_comp,
7916 msecs_to_jiffies(WAIT_TIME_TDLS_DEL_STA));
7917 if (status <= 0)
7918 {
Hoonki Lee5305c3a2013-04-29 23:28:59 -07007919 wlan_hdd_tdls_set_peer_link_status(pTdlsPeer, eTDLS_LINK_IDLE);
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07007920 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7921 "%s: Del station failed status %ld",
7922 __func__, status);
7923 return -EPERM;
7924 }
Hoonki Lee5305c3a2013-04-29 23:28:59 -07007925 wlan_hdd_tdls_set_peer_link_status(pTdlsPeer, eTDLS_LINK_IDLE);
Lee Hoonkic1262f22013-01-24 21:59:00 -08007926 }
7927 else
7928 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007929 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7930 "%s: TDLS Peer Station doesn't exist.", __func__);
Lee Hoonkic1262f22013-01-24 21:59:00 -08007931 }
Lee Hoonkic1262f22013-01-24 21:59:00 -08007932 }
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007933 break;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007934 case NL80211_TDLS_TEARDOWN:
7935 case NL80211_TDLS_SETUP:
7936 case NL80211_TDLS_DISCOVERY_REQ:
7937 /* We don't support in-driver setup/teardown/discovery */
7938 return -ENOTSUPP;
7939 default:
7940 return -ENOTSUPP;
7941 }
7942 return 0;
7943}
Chilam NG571c65a2013-01-19 12:27:36 +05307944
7945int wlan_hdd_cfg80211_send_tdls_discover_req(struct wiphy *wiphy,
7946 struct net_device *dev, u8 *peer)
7947{
7948 hddLog(VOS_TRACE_LEVEL_INFO, "tdls send discover req: %x %x %x %x %x %x",
7949 peer[0], peer[1], peer[2], peer[3], peer[4], peer[5]);
7950
7951 return wlan_hdd_cfg80211_tdls_mgmt(wiphy, dev, peer,
7952 WLAN_TDLS_DISCOVERY_REQUEST, 1, 0, NULL, 0);
7953}
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007954#endif
7955
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05307956#ifdef WLAN_FEATURE_GTK_OFFLOAD
7957/*
7958 * FUNCTION: wlan_hdd_cfg80211_update_replayCounterCallback
7959 * Callback rountine called upon receiving response for
7960 * get offload info
7961 */
7962void wlan_hdd_cfg80211_update_replayCounterCallback(void *callbackContext,
7963 tpSirGtkOffloadGetInfoRspParams pGtkOffloadGetInfoRsp)
7964{
7965
7966 hdd_adapter_t *pAdapter = (hdd_adapter_t *)callbackContext;
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05307967 tANI_U8 tempReplayCounter[8];
7968 hdd_station_ctx_t *pHddStaCtx;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05307969
7970 ENTER();
7971
7972 if (NULL == pAdapter)
7973 {
7974 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
7975 "%s: HDD adapter is Null", __func__);
7976 return ;
7977 }
7978
7979 if (NULL == pGtkOffloadGetInfoRsp)
7980 {
7981 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7982 "%s: pGtkOffloadGetInfoRsp is Null", __func__);
7983 return ;
7984 }
7985
7986 if (VOS_STATUS_SUCCESS != pGtkOffloadGetInfoRsp->ulStatus)
7987 {
7988 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7989 "%s: wlan Failed to get replay counter value",
7990 __func__);
7991 return ;
7992 }
7993
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05307994 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
7995 /* Update replay counter */
7996 pHddStaCtx->gtkOffloadReqParams.ullKeyReplayCounter =
7997 pGtkOffloadGetInfoRsp->ullKeyReplayCounter;
7998
7999 {
8000 /* changing from little to big endian since supplicant
8001 * works on big endian format
8002 */
8003 int i;
8004 tANI_U8 *p = (tANI_U8 *)&pGtkOffloadGetInfoRsp->ullKeyReplayCounter;
8005
8006 for (i = 0; i < 8; i++)
8007 {
8008 tempReplayCounter[7-i] = (tANI_U8)p[i];
8009 }
8010 }
8011
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308012 /* Update replay counter to NL */
8013 cfg80211_gtk_rekey_notify(pAdapter->dev, pGtkOffloadGetInfoRsp->bssId,
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308014 tempReplayCounter, GFP_KERNEL);
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308015}
8016
8017/*
8018 * FUNCTION: wlan_hdd_cfg80211_set_rekey_data
8019 * This function is used to offload GTK rekeying job to the firmware.
8020 */
8021int wlan_hdd_cfg80211_set_rekey_data(struct wiphy *wiphy, struct net_device *dev,
8022 struct cfg80211_gtk_rekey_data *data)
8023{
8024 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8025 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
8026 hdd_station_ctx_t *pHddStaCtx;
8027 tHalHandle hHal;
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308028 int result;
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308029 tSirGtkOffloadParams hddGtkOffloadReqParams;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308030 eHalStatus status = eHAL_STATUS_FAILURE;
8031
8032 ENTER();
8033
8034 if (NULL == pAdapter)
8035 {
8036 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8037 "%s: HDD adapter is Null", __func__);
8038 return -ENODEV;
8039 }
8040
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308041 result = wlan_hdd_validate_context(pHddCtx);
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308042
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308043 if (0 != result)
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308044 {
Gopichand Nakkalaf502e2b2013-05-24 18:34:25 +05308045 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8046 "%s: HDD context is not valid", __func__);
8047 return result;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308048 }
8049
8050 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
8051 hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
8052 if (NULL == hHal)
8053 {
8054 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8055 "%s: HAL context is Null!!!", __func__);
8056 return -EAGAIN;
8057 }
8058
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308059 pHddStaCtx->gtkOffloadReqParams.ulFlags = GTK_OFFLOAD_ENABLE;
8060 memcpy(pHddStaCtx->gtkOffloadReqParams.aKCK, data->kck, NL80211_KCK_LEN);
8061 memcpy(pHddStaCtx->gtkOffloadReqParams.aKEK, data->kek, NL80211_KEK_LEN);
8062 memcpy(pHddStaCtx->gtkOffloadReqParams.bssId, &pHddStaCtx->conn_info.bssId,
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308063 WNI_CFG_BSSID_LEN);
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308064 {
8065 /* changing from big to little endian since driver
8066 * works on little endian format
8067 */
8068 tANI_U8 *p =
8069 (tANI_U8 *)&pHddStaCtx->gtkOffloadReqParams.ullKeyReplayCounter;
8070 int i;
8071
8072 for (i = 0; i < 8; i++)
8073 {
8074 p[7-i] = data->replay_ctr[i];
8075 }
8076 }
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308077
8078 if (TRUE == pHddCtx->hdd_wlan_suspended)
8079 {
8080 /* if wlan is suspended, enable GTK offload directly from here */
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308081 memcpy(&hddGtkOffloadReqParams, &pHddStaCtx->gtkOffloadReqParams,
8082 sizeof (tSirGtkOffloadParams));
8083 status = sme_SetGTKOffload(hHal, &hddGtkOffloadReqParams,
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308084 pAdapter->sessionId);
8085
8086 if (eHAL_STATUS_SUCCESS != status)
8087 {
8088 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8089 "%s: sme_SetGTKOffload failed, returned %d",
8090 __func__, status);
8091 return status;
8092 }
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308093 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8094 "%s: sme_SetGTKOffload successfull", __func__);
8095 }
8096 else
8097 {
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308098 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8099 "%s: wlan not suspended GTKOffload request is stored",
8100 __func__);
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308101 }
Gopichand Nakkalad36ee622013-05-07 14:13:27 +05308102
8103 return eHAL_STATUS_SUCCESS;
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308104}
8105#endif /*WLAN_FEATURE_GTK_OFFLOAD*/
8106
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05308107/*
8108 * FUNCTION: wlan_hdd_cfg80211_set_mac_acl
8109 * This function is used to set access control policy
8110 */
8111static int wlan_hdd_cfg80211_set_mac_acl(struct wiphy *wiphy,
8112 struct net_device *dev, const struct cfg80211_acl_data *params)
8113{
8114 int i;
8115 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8116 hdd_hostapd_state_t *pHostapdState;
8117 tsap_Config_t *pConfig;
8118 v_CONTEXT_t pVosContext = NULL;
8119 hdd_context_t *pHddCtx;
8120 int status;
8121
8122 ENTER();
8123
8124 if (NULL == pAdapter)
8125 {
8126 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8127 "%s: HDD adapter is Null", __func__);
8128 return -ENODEV;
8129 }
8130
8131 if (NULL == params)
8132 {
8133 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8134 "%s: params is Null", __func__);
8135 return -EINVAL;
8136 }
8137
8138 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
8139 status = wlan_hdd_validate_context(pHddCtx);
8140
8141 if (0 != status)
8142 {
8143 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8144 "%s: HDD context is not valid", __func__);
8145 return status;
8146 }
8147
8148 pVosContext = pHddCtx->pvosContext;
8149 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
8150
8151 if (NULL == pHostapdState)
8152 {
8153 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8154 "%s: pHostapdState is Null", __func__);
8155 return -EINVAL;
8156 }
8157
8158 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,"acl policy: = %d"
8159 "no acl entries = %d", params->acl_policy, params->n_acl_entries);
8160
8161 if (WLAN_HDD_SOFTAP == pAdapter->device_mode)
8162 {
8163 pConfig = &pAdapter->sessionCtx.ap.sapConfig;
8164
8165 /* default value */
8166 pConfig->num_accept_mac = 0;
8167 pConfig->num_deny_mac = 0;
8168
8169 /**
8170 * access control policy
8171 * @NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED: Deny stations which are
8172 * listed in hostapd.deny file.
8173 * @NL80211_ACL_POLICY_DENY_UNLESS_LISTED: Allow stations which are
8174 * listed in hostapd.accept file.
8175 */
8176 if (NL80211_ACL_POLICY_DENY_UNLESS_LISTED == params->acl_policy)
8177 {
8178 pConfig->SapMacaddr_acl = eSAP_DENY_UNLESS_ACCEPTED;
8179 }
8180 else if (NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED == params->acl_policy)
8181 {
8182 pConfig->SapMacaddr_acl = eSAP_ACCEPT_UNLESS_DENIED;
8183 }
8184 else
8185 {
8186 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8187 "%s:Acl Policy : %d is not supported",
8188 __func__, params->acl_policy);
8189 return -ENOTSUPP;
8190 }
8191
8192 if (eSAP_DENY_UNLESS_ACCEPTED == pConfig->SapMacaddr_acl)
8193 {
8194 pConfig->num_accept_mac = params->n_acl_entries;
8195 for (i = 0; i < params->n_acl_entries; i++)
8196 {
8197 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8198 "** Add ACL MAC entry %i in WhiletList :"
8199 MAC_ADDRESS_STR, i,
8200 MAC_ADDR_ARRAY(params->mac_addrs[i].addr));
8201
8202 vos_mem_copy(&pConfig->accept_mac[i], params->mac_addrs[i].addr,
8203 sizeof(qcmacaddr));
8204 }
8205 }
8206 else if (eSAP_ACCEPT_UNLESS_DENIED == pConfig->SapMacaddr_acl)
8207 {
8208 pConfig->num_deny_mac = params->n_acl_entries;
8209 for (i = 0; i < params->n_acl_entries; i++)
8210 {
8211 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8212 "** Add ACL MAC entry %i in BlackList :"
8213 MAC_ADDRESS_STR, i,
8214 MAC_ADDR_ARRAY(params->mac_addrs[i].addr));
8215
8216 vos_mem_copy(&pConfig->deny_mac[i], params->mac_addrs[i].addr,
8217 sizeof(qcmacaddr));
8218 }
8219 }
8220
8221 if (VOS_STATUS_SUCCESS != WLANSAP_SetMacACL(pVosContext, pConfig))
8222 {
8223 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8224 "%s: SAP Set Mac Acl fail", __func__);
8225 return -EINVAL;
8226 }
8227 }
8228 else
8229 {
8230 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8231 "%s: Invalid device_mode = %d",
8232 __func__, pAdapter->device_mode);
8233 return -EINVAL;
8234 }
8235
8236 return 0;
8237}
8238
Leo Chang9056f462013-08-01 19:21:11 -07008239#ifdef WLAN_NL80211_TESTMODE
8240#ifdef FEATURE_WLAN_LPHB
8241static void wlan_hdd_cfg80211_lphb_wait_timeout_ind_handler
8242(
8243 void *pAdapter,
8244 void *indCont
8245)
8246{
8247 tSirLPHBTimeoutInd *lphbTimeoutInd;
8248 struct sk_buff *skb;
8249
8250 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8251 "LPHB wait timeout indication arrived");
8252
8253 if (NULL == indCont)
8254 {
8255 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8256 "LPHB timeout, invalid argument");
8257 return;
8258 }
8259
8260 lphbTimeoutInd = (tSirLPHBTimeoutInd *)indCont;
8261 skb = cfg80211_testmode_alloc_event_skb(
8262 ((hdd_adapter_t *)pAdapter)->wdev.wiphy,
8263 sizeof(tSirLPHBTimeoutInd),
8264 GFP_ATOMIC);
8265 if (!skb)
8266 {
8267 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8268 "LPHB timeout, NL buffer alloc fail");
8269 return;
8270 }
8271
8272 NLA_PUT_U32(skb, WLAN_HDD_TM_ATTR_CMD, WLAN_HDD_TM_CMD_WLAN_HB);
8273 NLA_PUT_U32(skb, WLAN_HDD_TM_ATTR_TYPE, lphbTimeoutInd->protocolType);
8274 NLA_PUT(skb, WLAN_HDD_TM_ATTR_DATA,
8275 sizeof(tSirLPHBTimeoutInd), lphbTimeoutInd);
8276 cfg80211_testmode_event(skb, GFP_ATOMIC);
8277 return;
8278
8279nla_put_failure:
8280 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8281 "NLA Put fail");
8282 kfree_skb(skb);
8283
8284 return;
8285}
8286#endif /* FEATURE_WLAN_LPHB */
8287
8288static int wlan_hdd_cfg80211_testmode(struct wiphy *wiphy, void *data, int len)
8289{
8290 struct nlattr *tb[WLAN_HDD_TM_ATTR_MAX + 1];
8291 int err = 0;
8292#ifdef FEATURE_WLAN_LPHB
8293 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
8294#endif /* FEATURE_WLAN_LPHB */
8295
8296 err = nla_parse(tb, WLAN_HDD_TM_ATTR_MAX, data, len, wlan_hdd_tm_policy);
8297 if (err)
8298 {
8299 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8300 "%s Testmode INV ATTR", __func__);
8301 return err;
8302 }
8303
8304 if (!tb[WLAN_HDD_TM_ATTR_CMD])
8305 {
8306 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8307 "%s Testmode INV CMD", __func__);
8308 return -EINVAL;
8309 }
8310
8311 switch (nla_get_u32(tb[WLAN_HDD_TM_ATTR_CMD]))
8312 {
8313#ifdef FEATURE_WLAN_LPHB
8314 /* Low Power Heartbeat configuration request */
8315 case WLAN_HDD_TM_CMD_WLAN_HB:
8316 {
8317 int buf_len;
8318 void *buf;
8319 tSirLPHBReq *hb_params = NULL;
8320
8321 if (!tb[WLAN_HDD_TM_ATTR_DATA])
8322 {
8323 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8324 "%s Testmode INV DATA", __func__);
8325 return -EINVAL;
8326 }
8327
8328 buf = nla_data(tb[WLAN_HDD_TM_ATTR_DATA]);
8329 buf_len = nla_len(tb[WLAN_HDD_TM_ATTR_DATA]);
8330 hb_params = (tSirLPHBReq *)vos_mem_malloc(sizeof(tSirLPHBReq));
8331 if (NULL == hb_params)
8332 {
8333 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8334 "%s Request Buffer Alloc Fail", __func__);
8335 return -EINVAL;
8336 }
8337
8338 vos_mem_copy(hb_params, buf, buf_len);
8339
8340 /* LPHB enable and disable request will send to FW
8341 * when host suspend and resume
8342 * host suspend -> enable LPHB
8343 * host resume -> disable LPHB
8344 * if host is not suspend, cache into HDD context
8345 * and when host goes to suspend, send request to FW */
8346 if ((LPHB_SET_EN_PARAMS_INDID == hb_params->cmd) &&
8347 (!pHddCtx->hdd_wlan_suspended))
8348 {
8349 /* Feature enable command cache into HDD context,
8350 * if WLAN is not suspend
8351 * When WLAN goes into suspend, send enable command to FW */
8352 pHddCtx->lphbEnableReq.enable =
8353 hb_params->params.lphbEnableReq.enable;
8354 pHddCtx->lphbEnableReq.item =
8355 hb_params->params.lphbEnableReq.item;
8356 pHddCtx->lphbEnableReq.session =
8357 hb_params->params.lphbEnableReq.session;
8358 vos_mem_free(hb_params);
8359 }
8360 else
8361 {
8362 eHalStatus smeStatus;
8363
8364 /* If WLAN is suspend state, send enable command immediately */
8365 smeStatus = sme_LPHBConfigReq((tHalHandle)(pHddCtx->hHal),
8366 hb_params,
8367 wlan_hdd_cfg80211_lphb_wait_timeout_ind_handler);
8368 if (eHAL_STATUS_SUCCESS != smeStatus)
8369 {
8370 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8371 "LPHB Config Fail, disable");
8372 pHddCtx->lphbEnableReq.enable = 0;
8373 vos_mem_free(hb_params);
8374 }
8375 }
8376 return 0;
8377 }
8378#endif /* FEATURE_WLAN_LPHB */
8379 default:
8380 return -EOPNOTSUPP;
8381 }
8382
8383 return err;
8384}
8385#endif /* CONFIG_NL80211_TESTMODE */
8386
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05308387static int wlan_hdd_cfg80211_dump_survey(struct wiphy *wiphy,
8388 struct net_device *dev,
8389 int idx, struct survey_info *survey)
8390{
8391 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
8392 hdd_context_t *pHddCtx;
Mihir Sheted9072e02013-08-21 17:02:29 +05308393 hdd_station_ctx_t *pHddStaCtx;
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05308394 tHalHandle halHandle;
Mihir Sheted9072e02013-08-21 17:02:29 +05308395 v_U32_t channel = 0, freq = 0; /* Initialization Required */
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05308396 v_S7_t snr,rssi;
8397 int status, i, j, filled = 0;
8398
8399 ENTER();
8400
8401
8402 if (NULL == pAdapter)
8403 {
8404 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8405 "%s: HDD adapter is Null", __func__);
8406 return -ENODEV;
8407 }
8408
8409 if (NULL == wiphy)
8410 {
8411 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8412 "%s: wiphy is Null", __func__);
8413 return -ENODEV;
8414 }
8415
8416 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
8417 status = wlan_hdd_validate_context(pHddCtx);
8418
8419 if (0 != status)
8420 {
8421 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8422 "%s: HDD context is not valid", __func__);
8423 return status;
8424 }
8425
Mihir Sheted9072e02013-08-21 17:02:29 +05308426 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
8427
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05308428 if (0 == pHddCtx->cfg_ini->fEnableSNRMonitoring ||
Mihir Sheted9072e02013-08-21 17:02:29 +05308429 0 != pAdapter->survey_idx ||
8430 eConnectionState_Associated != pHddStaCtx->conn_info.connState)
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05308431 {
8432 /* The survey dump ops when implemented completely is expected to
8433 * return a survey of all channels and the ops is called by the
8434 * kernel with incremental values of the argument 'idx' till it
8435 * returns -ENONET. But we can only support the survey for the
8436 * operating channel for now. survey_idx is used to track
8437 * that the ops is called only once and then return -ENONET for
8438 * the next iteration
8439 */
8440 pAdapter->survey_idx = 0;
8441 return -ENONET;
8442 }
8443
8444 halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
8445
8446 wlan_hdd_get_snr(pAdapter, &snr);
8447 wlan_hdd_get_rssi(pAdapter, &rssi);
8448
8449 sme_GetOperationChannel(halHandle, &channel, pAdapter->sessionId);
8450 hdd_wlan_get_freq(channel, &freq);
8451
8452
8453 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
8454 {
8455 if (NULL == wiphy->bands[i])
8456 {
8457 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
8458 "%s: wiphy->bands[i] is NULL, i = %d", __func__, i);
8459 continue;
8460 }
8461
8462 for (j = 0; j < wiphy->bands[i]->n_channels; j++)
8463 {
8464 struct ieee80211_supported_band *band = wiphy->bands[i];
8465
8466 if (band->channels[j].center_freq == (v_U16_t)freq)
8467 {
8468 survey->channel = &band->channels[j];
8469 /* The Rx BDs contain SNR values in dB for the received frames
8470 * while the supplicant expects noise. So we calculate and
8471 * return the value of noise (dBm)
8472 * SNR (dB) = RSSI (dBm) - NOISE (dBm)
8473 */
8474 survey->noise = rssi - snr;
8475 survey->filled = SURVEY_INFO_NOISE_DBM;
8476 filled = 1;
8477 }
8478 }
8479 }
8480
8481 if (filled)
8482 pAdapter->survey_idx = 1;
8483 else
8484 {
8485 pAdapter->survey_idx = 0;
8486 return -ENONET;
8487 }
8488
8489 return 0;
8490}
8491
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308492/*
8493 * FUNCTION: wlan_hdd_cfg80211_resume_wlan
8494 * this is called when cfg80211 driver resume
8495 * driver updates latest sched_scan scan result(if any) to cfg80211 database
8496 */
8497int wlan_hdd_cfg80211_resume_wlan(struct wiphy *wiphy)
8498{
8499 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
8500 hdd_adapter_t *pAdapter;
8501 hdd_adapter_list_node_t *pAdapterNode, *pNext;
8502 VOS_STATUS status = VOS_STATUS_SUCCESS;
8503
8504 ENTER();
8505
8506 if ( NULL == pHddCtx )
8507 {
8508 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8509 "%s: HddCtx validation failed", __func__);
8510 return 0;
8511 }
8512
8513 if (pHddCtx->isLogpInProgress)
8514 {
8515 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8516 "%s: LOGP in Progress. Ignore!!!", __func__);
8517 return 0;
8518 }
8519
8520 if (pHddCtx->isLoadUnloadInProgress)
8521 {
8522 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
8523 "%s: Unloading/Loading in Progress. Ignore!!!", __func__);
8524 return 0;
8525 }
8526
8527 spin_lock(&pHddCtx->schedScan_lock);
8528 pHddCtx->isWiphySuspended = FALSE;
8529 if (TRUE != pHddCtx->isSchedScanUpdatePending)
8530 {
8531 spin_unlock(&pHddCtx->schedScan_lock);
8532 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8533 "%s: Return resume is not due to PNO indication", __func__);
8534 return 0;
8535 }
8536 // Reset flag to avoid updatating cfg80211 data old results again
8537 pHddCtx->isSchedScanUpdatePending = FALSE;
8538 spin_unlock(&pHddCtx->schedScan_lock);
8539
8540 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
8541
8542 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
8543 {
8544 pAdapter = pAdapterNode->pAdapter;
8545 if ( (NULL != pAdapter) &&
8546 (WLAN_HDD_INFRA_STATION == pAdapter->device_mode) )
8547 {
8548 if (0 != wlan_hdd_cfg80211_update_bss(pHddCtx->wiphy, pAdapter))
8549 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
8550 "%s: NO SCAN result", __func__);
8551 else
8552 cfg80211_sched_scan_results(pHddCtx->wiphy);
8553
8554 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8555 "%s : cfg80211 scan result database updated", __func__);
8556
8557 return 0;
8558
8559 }
8560 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
8561 pAdapterNode = pNext;
8562 }
8563
8564 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
8565 "%s: Failed to find Adapter", __func__);
8566 return 0;
8567}
8568
8569/*
8570 * FUNCTION: wlan_hdd_cfg80211_suspend_wlan
8571 * this is called when cfg80211 driver suspends
8572 */
8573int wlan_hdd_cfg80211_suspend_wlan(struct wiphy *wiphy,
8574 struct cfg80211_wowlan *wow)
8575{
8576 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
8577
8578 ENTER();
8579 if (NULL == pHddCtx)
8580 {
8581 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
8582 "%s: HddCtx validation failed", __func__);
8583 return 0;
8584 }
8585
8586 pHddCtx->isWiphySuspended = TRUE;
8587
8588 EXIT();
8589
8590 return 0;
8591}
8592
Jeff Johnson295189b2012-06-20 16:38:30 -07008593/* cfg80211_ops */
Gopichand Nakkala747461f2013-04-24 19:24:45 +05308594static struct cfg80211_ops wlan_hdd_cfg80211_ops =
Jeff Johnson295189b2012-06-20 16:38:30 -07008595{
8596 .add_virtual_intf = wlan_hdd_add_virtual_intf,
8597 .del_virtual_intf = wlan_hdd_del_virtual_intf,
8598 .change_virtual_intf = wlan_hdd_cfg80211_change_iface,
8599 .change_station = wlan_hdd_change_station,
8600#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
8601 .add_beacon = wlan_hdd_cfg80211_add_beacon,
8602 .del_beacon = wlan_hdd_cfg80211_del_beacon,
8603 .set_beacon = wlan_hdd_cfg80211_set_beacon,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008604#else
8605 .start_ap = wlan_hdd_cfg80211_start_ap,
8606 .change_beacon = wlan_hdd_cfg80211_change_beacon,
8607 .stop_ap = wlan_hdd_cfg80211_stop_ap,
Jeff Johnson295189b2012-06-20 16:38:30 -07008608#endif
8609 .change_bss = wlan_hdd_cfg80211_change_bss,
8610 .add_key = wlan_hdd_cfg80211_add_key,
8611 .get_key = wlan_hdd_cfg80211_get_key,
8612 .del_key = wlan_hdd_cfg80211_del_key,
8613 .set_default_key = wlan_hdd_cfg80211_set_default_key,
Jeff Johnson3bbe4bf2013-01-18 17:05:29 -08008614#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07008615 .set_channel = wlan_hdd_cfg80211_set_channel,
Jeff Johnson3bbe4bf2013-01-18 17:05:29 -08008616#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07008617 .scan = wlan_hdd_cfg80211_scan,
8618 .connect = wlan_hdd_cfg80211_connect,
8619 .disconnect = wlan_hdd_cfg80211_disconnect,
8620 .join_ibss = wlan_hdd_cfg80211_join_ibss,
8621 .leave_ibss = wlan_hdd_cfg80211_leave_ibss,
8622 .set_wiphy_params = wlan_hdd_cfg80211_set_wiphy_params,
8623 .set_tx_power = wlan_hdd_cfg80211_set_txpower,
8624 .get_tx_power = wlan_hdd_cfg80211_get_txpower,
Jeff Johnson295189b2012-06-20 16:38:30 -07008625 .remain_on_channel = wlan_hdd_cfg80211_remain_on_channel,
8626 .cancel_remain_on_channel = wlan_hdd_cfg80211_cancel_remain_on_channel,
8627 .mgmt_tx = wlan_hdd_action,
8628#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
8629 .mgmt_tx_cancel_wait = wlan_hdd_cfg80211_mgmt_tx_cancel_wait,
8630 .set_default_mgmt_key = wlan_hdd_set_default_mgmt_key,
8631 .set_txq_params = wlan_hdd_set_txq_params,
8632#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07008633 .get_station = wlan_hdd_cfg80211_get_station,
8634 .set_power_mgmt = wlan_hdd_cfg80211_set_power_mgmt,
8635 .del_station = wlan_hdd_cfg80211_del_station,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07008636 .add_station = wlan_hdd_cfg80211_add_station,
8637#ifdef FEATURE_WLAN_LFR
8638 .set_pmksa = wlan_hdd_cfg80211_set_pmksa,
8639 .del_pmksa = wlan_hdd_cfg80211_del_pmksa,
8640 .flush_pmksa = wlan_hdd_cfg80211_flush_pmksa,
8641#endif
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07008642#if defined(WLAN_FEATURE_VOWIFI_11R) && defined(KERNEL_SUPPORT_11R_CFG80211)
8643 .update_ft_ies = wlan_hdd_cfg80211_update_ft_ies,
8644#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -08008645#ifdef FEATURE_WLAN_TDLS
8646 .tdls_mgmt = wlan_hdd_cfg80211_tdls_mgmt,
8647 .tdls_oper = wlan_hdd_cfg80211_tdls_oper,
8648#endif
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05308649#ifdef WLAN_FEATURE_GTK_OFFLOAD
8650 .set_rekey_data = wlan_hdd_cfg80211_set_rekey_data,
8651#endif /* WLAN_FEATURE_GTK_OFFLOAD */
Gopichand Nakkala8e93fde2013-05-10 17:40:12 +05308652#ifdef FEATURE_WLAN_SCAN_PNO
8653 .sched_scan_start = wlan_hdd_cfg80211_sched_scan_start,
8654 .sched_scan_stop = wlan_hdd_cfg80211_sched_scan_stop,
8655#endif /*FEATURE_WLAN_SCAN_PNO */
Kamath Vinayak4000c9a2013-08-23 14:24:27 +05308656 .resume = wlan_hdd_cfg80211_resume_wlan,
8657 .suspend = wlan_hdd_cfg80211_suspend_wlan,
Gopichand Nakkalac005b7c2013-05-14 16:04:14 +05308658 .set_mac_acl = wlan_hdd_cfg80211_set_mac_acl,
Leo Chang9056f462013-08-01 19:21:11 -07008659#ifdef WLAN_NL80211_TESTMODE
8660 .testmode_cmd = wlan_hdd_cfg80211_testmode,
8661#endif
Madan Mohan Koyyalamudid9383fd2013-08-13 09:27:30 +05308662 .dump_survey = wlan_hdd_cfg80211_dump_survey,
Jeff Johnson295189b2012-06-20 16:38:30 -07008663};
8664