blob: 62aa33bbce42b3e6b17aa8f80bd792f539c9d7a3 [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Gopichand Nakkala92f07d82013-01-08 21:16:34 -08002 * 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 */
21/*
Jeff Johnson32d95a32012-09-10 13:15:23 -070022 * Copyright (c) 2012, The Linux Foundation. All rights reserved.
Jeff Johnson295189b2012-06-20 16:38:30 -070023 *
24 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
25 *
26 *
27 * Permission to use, copy, modify, and/or distribute this software for
28 * any purpose with or without fee is hereby granted, provided that the
29 * above copyright notice and this permission notice appear in all
30 * copies.
31 *
32 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
33 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
34 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
35 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
36 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
37 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
38 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
39 * PERFORMANCE OF THIS SOFTWARE.
40 */
41
42/**========================================================================
43
44 \file wlan_hdd_cfg80211.c
45
46 \brief WLAN Host Device Driver implementation
47
48 Copyright 2008 (c) Qualcomm, Incorporated. All Rights Reserved.
49
50 Qualcomm Confidential and Proprietary.
51
52 ========================================================================*/
53
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -070054/**=========================================================================
Jeff Johnson295189b2012-06-20 16:38:30 -070055
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -070056 EDIT HISTORY FOR FILE
Jeff Johnson295189b2012-06-20 16:38:30 -070057
58
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -070059 This section contains comments describing changes made to the module.
60 Notice that changes are listed in reverse chronological order.
Jeff Johnson295189b2012-06-20 16:38:30 -070061
62
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -070063 $Header:$ $DateTime: $ $Author: $
Jeff Johnson295189b2012-06-20 16:38:30 -070064
65
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -070066 when who what, where, why
Jeff Johnson295189b2012-06-20 16:38:30 -070067 -------- --- --------------------------------------------------------
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -070068 21/12/09 Ashwani Created module.
Jeff Johnson295189b2012-06-20 16:38:30 -070069
70 07/06/10 Kumar Deepak Implemented cfg80211 callbacks for ANDROID
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -070071 Ganesh K
Jeff Johnson295189b2012-06-20 16:38:30 -070072 ==========================================================================*/
73
Jeff Johnson295189b2012-06-20 16:38:30 -070074
75#include <linux/version.h>
76#include <linux/module.h>
77#include <linux/kernel.h>
78#include <linux/init.h>
79#include <linux/wireless.h>
80#include <wlan_hdd_includes.h>
81#include <net/arp.h>
82#include <net/cfg80211.h>
83#include <linux/wireless.h>
84#include <wlan_hdd_wowl.h>
85#include <aniGlobal.h>
86#include "ccmApi.h"
87#include "sirParams.h"
88#include "dot11f.h"
89#include "wlan_hdd_assoc.h"
90#include "wlan_hdd_wext.h"
91#include "sme_Api.h"
92#include "wlan_hdd_p2p.h"
93#include "wlan_hdd_cfg80211.h"
94#include "wlan_hdd_hostapd.h"
95#include "sapInternal.h"
96#include "wlan_hdd_softap_tx_rx.h"
97#include "wlan_hdd_main.h"
Madan Mohan Koyyalamudid5acbf52012-11-28 01:45:08 +053098#include "wlan_hdd_assoc.h"
Jeff Johnson295189b2012-06-20 16:38:30 -070099#ifdef WLAN_BTAMP_FEATURE
100#include "bap_hdd_misc.h"
101#endif
102#include <qc_sap_ioctl.h>
Mohit Khanna698ba2a2012-12-04 15:08:18 -0800103#ifdef FEATURE_WLAN_TDLS
104#include "wlan_hdd_tdls.h"
105#endif
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +0530106#include "wlan_nv.h"
Jeff Johnson295189b2012-06-20 16:38:30 -0700107
108#define g_mode_rates_size (12)
109#define a_mode_rates_size (8)
110#define FREQ_BASE_80211G (2407)
111#define FREQ_BAND_DIFF_80211G (5)
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700112#define MAX_SCAN_SSID 9
Jeff Johnson295189b2012-06-20 16:38:30 -0700113#define GET_IE_LEN_IN_BSS_DESC(lenInBss) ( lenInBss + sizeof(lenInBss) - \
114 ((int) OFFSET_OF( tSirBssDescription, ieFields)))
115
116#define HDD2GHZCHAN(freq, chan, flag) { \
117 .band = IEEE80211_BAND_2GHZ, \
118 .center_freq = (freq), \
119 .hw_value = (chan),\
120 .flags = (flag), \
121 .max_antenna_gain = 0 ,\
122 .max_power = 30, \
123}
124
125#define HDD5GHZCHAN(freq, chan, flag) { \
126 .band = IEEE80211_BAND_5GHZ, \
127 .center_freq = (freq), \
128 .hw_value = (chan),\
129 .flags = (flag), \
130 .max_antenna_gain = 0 ,\
131 .max_power = 30, \
132}
133
134#define HDD_G_MODE_RATETAB(rate, rate_id, flag)\
135{\
136 .bitrate = rate, \
137 .hw_value = rate_id, \
138 .flags = flag, \
139}
140
Lee Hoonkic1262f22013-01-24 21:59:00 -0800141#ifndef WLAN_FEATURE_TDLS_DEBUG
142#define TDLS_LOG_LEVEL VOS_TRACE_LEVEL_INFO
143#else
144#define TDLS_LOG_LEVEL VOS_TRACE_LEVEL_ERROR
145#endif
146
Gopichand Nakkala356fb102013-03-06 12:34:04 +0530147#ifdef WLAN_FEATURE_VOWIFI_11R
148#define WLAN_AKM_SUITE_FT_8021X 0x000FAC03
149#define WLAN_AKM_SUITE_FT_PSK 0x000FAC04
150#endif
151
Jeff Johnson295189b2012-06-20 16:38:30 -0700152static const u32 hdd_cipher_suites[] =
153{
154 WLAN_CIPHER_SUITE_WEP40,
155 WLAN_CIPHER_SUITE_WEP104,
156 WLAN_CIPHER_SUITE_TKIP,
157#ifdef FEATURE_WLAN_CCX
158#define WLAN_CIPHER_SUITE_KRK 0x004096ff /* use for KRK */
159 WLAN_CIPHER_SUITE_KRK,
160 WLAN_CIPHER_SUITE_CCMP,
161#else
162 WLAN_CIPHER_SUITE_CCMP,
163#endif
164#ifdef FEATURE_WLAN_WAPI
165 WLAN_CIPHER_SUITE_SMS4,
166#endif
Chet Lanctot186b5732013-03-18 10:26:30 -0700167#ifdef WLAN_FEATURE_11W
168 WLAN_CIPHER_SUITE_AES_CMAC,
169#endif
Jeff Johnson295189b2012-06-20 16:38:30 -0700170};
171
172static inline int is_broadcast_ether_addr(const u8 *addr)
173{
174 return ((addr[0] == 0xff) && (addr[1] == 0xff) && (addr[2] == 0xff) &&
175 (addr[3] == 0xff) && (addr[4] == 0xff) && (addr[5] == 0xff));
176}
177
178static struct ieee80211_channel hdd_channels_2_4_GHZ[] =
179{
180 HDD2GHZCHAN(2412, 1, 0) ,
181 HDD2GHZCHAN(2417, 2, 0) ,
182 HDD2GHZCHAN(2422, 3, 0) ,
183 HDD2GHZCHAN(2427, 4, 0) ,
184 HDD2GHZCHAN(2432, 5, 0) ,
185 HDD2GHZCHAN(2437, 6, 0) ,
186 HDD2GHZCHAN(2442, 7, 0) ,
187 HDD2GHZCHAN(2447, 8, 0) ,
188 HDD2GHZCHAN(2452, 9, 0) ,
189 HDD2GHZCHAN(2457, 10, 0) ,
190 HDD2GHZCHAN(2462, 11, 0) ,
191 HDD2GHZCHAN(2467, 12, 0) ,
192 HDD2GHZCHAN(2472, 13, 0) ,
193 HDD2GHZCHAN(2484, 14, 0) ,
194};
195
Jeff Johnson295189b2012-06-20 16:38:30 -0700196static struct ieee80211_channel hdd_social_channels_2_4_GHZ[] =
197{
198 HDD2GHZCHAN(2412, 1, 0) ,
199 HDD2GHZCHAN(2437, 6, 0) ,
200 HDD2GHZCHAN(2462, 11, 0) ,
201};
Jeff Johnson295189b2012-06-20 16:38:30 -0700202
203static struct ieee80211_channel hdd_channels_5_GHZ[] =
204{
Madan Mohan Koyyalamudic3a240c2012-09-28 15:34:08 -0700205 HDD5GHZCHAN(4920, 240, 0) ,
206 HDD5GHZCHAN(4940, 244, 0) ,
207 HDD5GHZCHAN(4960, 248, 0) ,
208 HDD5GHZCHAN(4980, 252, 0) ,
209 HDD5GHZCHAN(5040, 208, 0) ,
210 HDD5GHZCHAN(5060, 212, 0) ,
211 HDD5GHZCHAN(5080, 216, 0) ,
Jeff Johnson295189b2012-06-20 16:38:30 -0700212 HDD5GHZCHAN(5180, 36, 0) ,
213 HDD5GHZCHAN(5200, 40, 0) ,
214 HDD5GHZCHAN(5220, 44, 0) ,
215 HDD5GHZCHAN(5240, 48, 0) ,
216 HDD5GHZCHAN(5260, 52, 0) ,
217 HDD5GHZCHAN(5280, 56, 0) ,
218 HDD5GHZCHAN(5300, 60, 0) ,
219 HDD5GHZCHAN(5320, 64, 0) ,
220 HDD5GHZCHAN(5500,100, 0) ,
221 HDD5GHZCHAN(5520,104, 0) ,
222 HDD5GHZCHAN(5540,108, 0) ,
223 HDD5GHZCHAN(5560,112, 0) ,
224 HDD5GHZCHAN(5580,116, 0) ,
225 HDD5GHZCHAN(5600,120, 0) ,
226 HDD5GHZCHAN(5620,124, 0) ,
227 HDD5GHZCHAN(5640,128, 0) ,
228 HDD5GHZCHAN(5660,132, 0) ,
229 HDD5GHZCHAN(5680,136, 0) ,
230 HDD5GHZCHAN(5700,140, 0) ,
231 HDD5GHZCHAN(5745,149, 0) ,
232 HDD5GHZCHAN(5765,153, 0) ,
233 HDD5GHZCHAN(5785,157, 0) ,
234 HDD5GHZCHAN(5805,161, 0) ,
235 HDD5GHZCHAN(5825,165, 0) ,
236};
237
238static struct ieee80211_rate g_mode_rates[] =
239{
240 HDD_G_MODE_RATETAB(10, 0x1, 0),
241 HDD_G_MODE_RATETAB(20, 0x2, 0),
242 HDD_G_MODE_RATETAB(55, 0x4, 0),
243 HDD_G_MODE_RATETAB(110, 0x8, 0),
244 HDD_G_MODE_RATETAB(60, 0x10, 0),
245 HDD_G_MODE_RATETAB(90, 0x20, 0),
246 HDD_G_MODE_RATETAB(120, 0x40, 0),
247 HDD_G_MODE_RATETAB(180, 0x80, 0),
248 HDD_G_MODE_RATETAB(240, 0x100, 0),
249 HDD_G_MODE_RATETAB(360, 0x200, 0),
250 HDD_G_MODE_RATETAB(480, 0x400, 0),
251 HDD_G_MODE_RATETAB(540, 0x800, 0),
252};
253
254static struct ieee80211_rate a_mode_rates[] =
255{
256 HDD_G_MODE_RATETAB(60, 0x10, 0),
257 HDD_G_MODE_RATETAB(90, 0x20, 0),
258 HDD_G_MODE_RATETAB(120, 0x40, 0),
259 HDD_G_MODE_RATETAB(180, 0x80, 0),
260 HDD_G_MODE_RATETAB(240, 0x100, 0),
261 HDD_G_MODE_RATETAB(360, 0x200, 0),
262 HDD_G_MODE_RATETAB(480, 0x400, 0),
263 HDD_G_MODE_RATETAB(540, 0x800, 0),
264};
265
266static struct ieee80211_supported_band wlan_hdd_band_2_4_GHZ =
267{
268 .channels = hdd_channels_2_4_GHZ,
269 .n_channels = ARRAY_SIZE(hdd_channels_2_4_GHZ),
270 .band = IEEE80211_BAND_2GHZ,
271 .bitrates = g_mode_rates,
272 .n_bitrates = g_mode_rates_size,
273 .ht_cap.ht_supported = 1,
274 .ht_cap.cap = IEEE80211_HT_CAP_SGI_20
275 | IEEE80211_HT_CAP_GRN_FLD
276 | IEEE80211_HT_CAP_DSSSCCK40
277 | IEEE80211_HT_CAP_LSIG_TXOP_PROT,
278 .ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
279 .ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_16,
280 .ht_cap.mcs.rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
281 .ht_cap.mcs.rx_highest = cpu_to_le16( 72 ),
282 .ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED,
283};
284
Jeff Johnson295189b2012-06-20 16:38:30 -0700285static struct ieee80211_supported_band wlan_hdd_band_p2p_2_4_GHZ =
286{
287 .channels = hdd_social_channels_2_4_GHZ,
288 .n_channels = ARRAY_SIZE(hdd_social_channels_2_4_GHZ),
289 .band = IEEE80211_BAND_2GHZ,
290 .bitrates = g_mode_rates,
291 .n_bitrates = g_mode_rates_size,
292 .ht_cap.ht_supported = 1,
293 .ht_cap.cap = IEEE80211_HT_CAP_SGI_20
294 | IEEE80211_HT_CAP_GRN_FLD
295 | IEEE80211_HT_CAP_DSSSCCK40
296 | IEEE80211_HT_CAP_LSIG_TXOP_PROT,
297 .ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
298 .ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_16,
299 .ht_cap.mcs.rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
300 .ht_cap.mcs.rx_highest = cpu_to_le16( 72 ),
301 .ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED,
302};
Jeff Johnson295189b2012-06-20 16:38:30 -0700303
304static struct ieee80211_supported_band wlan_hdd_band_5_GHZ =
305{
306 .channels = hdd_channels_5_GHZ,
307 .n_channels = ARRAY_SIZE(hdd_channels_5_GHZ),
308 .band = IEEE80211_BAND_5GHZ,
309 .bitrates = a_mode_rates,
310 .n_bitrates = a_mode_rates_size,
311 .ht_cap.ht_supported = 1,
312 .ht_cap.cap = IEEE80211_HT_CAP_SGI_20
313 | IEEE80211_HT_CAP_GRN_FLD
314 | IEEE80211_HT_CAP_DSSSCCK40
315 | IEEE80211_HT_CAP_LSIG_TXOP_PROT
316 | IEEE80211_HT_CAP_SGI_40
317 | IEEE80211_HT_CAP_SUP_WIDTH_20_40,
318 .ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
319 .ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_16,
320 .ht_cap.mcs.rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
321 .ht_cap.mcs.rx_highest = cpu_to_le16( 72 ),
322 .ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED,
323};
324
325/* This structure contain information what kind of frame are expected in
326 TX/RX direction for each kind of interface */
327static const struct ieee80211_txrx_stypes
328wlan_hdd_txrx_stypes[NUM_NL80211_IFTYPES] = {
329 [NL80211_IFTYPE_STATION] = {
330 .tx = 0xffff,
331 .rx = BIT(SIR_MAC_MGMT_ACTION) |
332 BIT(SIR_MAC_MGMT_PROBE_REQ),
333 },
334 [NL80211_IFTYPE_AP] = {
335 .tx = 0xffff,
336 .rx = BIT(SIR_MAC_MGMT_ASSOC_REQ) |
337 BIT(SIR_MAC_MGMT_REASSOC_REQ) |
338 BIT(SIR_MAC_MGMT_PROBE_REQ) |
339 BIT(SIR_MAC_MGMT_DISASSOC) |
340 BIT(SIR_MAC_MGMT_AUTH) |
341 BIT(SIR_MAC_MGMT_DEAUTH) |
342 BIT(SIR_MAC_MGMT_ACTION),
343 },
Jeff Johnson295189b2012-06-20 16:38:30 -0700344 [NL80211_IFTYPE_P2P_CLIENT] = {
345 .tx = 0xffff,
346 .rx = BIT(SIR_MAC_MGMT_ACTION) |
347 BIT(SIR_MAC_MGMT_PROBE_REQ),
348 },
349 [NL80211_IFTYPE_P2P_GO] = {
350 /* This is also same as for SoftAP */
351 .tx = 0xffff,
352 .rx = BIT(SIR_MAC_MGMT_ASSOC_REQ) |
353 BIT(SIR_MAC_MGMT_REASSOC_REQ) |
354 BIT(SIR_MAC_MGMT_PROBE_REQ) |
355 BIT(SIR_MAC_MGMT_DISASSOC) |
356 BIT(SIR_MAC_MGMT_AUTH) |
357 BIT(SIR_MAC_MGMT_DEAUTH) |
358 BIT(SIR_MAC_MGMT_ACTION),
359 },
Jeff Johnson295189b2012-06-20 16:38:30 -0700360};
361
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800362#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800363static const struct ieee80211_iface_limit
364wlan_hdd_iface_limit[] = {
365 {
Sunil Ravia72c3992013-01-31 06:12:22 -0800366 /* max = 3 ; Our driver create two interfaces during driver init
367 * wlan0 and p2p0 interfaces. p2p0 is considered as station
368 * interface until a group is formed. In JB architecture, once the
369 * group is formed, interface type of p2p0 is changed to P2P GO or
370 * Client.
371 * When supplicant remove the group, it first issue a set interface
372 * cmd to change the mode back to Station. In JB this works fine as
373 * we advertize two station type interface during driver init.
374 * Some vendors create separate interface for P2P GO/Client,
375 * after group formation(Third one). But while group remove
376 * supplicant first tries to change the mode(3rd interface) to STATION
377 * But as we advertized only two sta type interfaces nl80211 was
378 * returning error for the third one which was leading to failure in
379 * delete interface. Ideally while removing the group, supplicant
380 * should not try to change the 3rd interface mode to Station type.
381 * Till we get a fix in wpa_supplicant, we advertize max STA
382 * interface type to 3
383 */
384 .max = 3,
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800385 .types = BIT(NL80211_IFTYPE_STATION),
386 },
387 {
388 .max = 1,
389 .types = BIT(NL80211_IFTYPE_AP),
390 },
391 {
392 .max = 1,
393 .types = BIT(NL80211_IFTYPE_P2P_GO) |
394 BIT(NL80211_IFTYPE_P2P_CLIENT),
395 },
396};
397
398/* By default, only single channel concurrency is allowed */
399static struct ieee80211_iface_combination
400wlan_hdd_iface_combination = {
401 .limits = wlan_hdd_iface_limit,
402 .num_different_channels = 1,
Sunil Ravia72c3992013-01-31 06:12:22 -0800403 /*
404 * max = WLAN_MAX_INTERFACES ; JellyBean architecture creates wlan0
405 * and p2p0 interfaces during driver init
406 * Some vendors create separate interface for P2P operations.
407 * wlan0: STA interface
408 * p2p0: P2P Device interface, action frames goes
409 * through this interface.
410 * p2p-xx: P2P interface, After GO negotiation this interface is
411 * created for p2p operations(GO/CLIENT interface).
412 */
413 .max_interfaces = WLAN_MAX_INTERFACES,
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800414 .n_limits = ARRAY_SIZE(wlan_hdd_iface_limit),
415 .beacon_int_infra_match = false,
416};
417#endif
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800418
Jeff Johnson295189b2012-06-20 16:38:30 -0700419static struct cfg80211_ops wlan_hdd_cfg80211_ops;
420
421/* Data rate 100KBPS based on IE Index */
422struct index_data_rate_type
423{
424 v_U8_t beacon_rate_index;
425 v_U16_t supported_rate[4];
426};
427
428/* 11B, 11G Rate table include Basic rate and Extended rate
429 The IDX field is the rate index
430 The HI field is the rate when RSSI is strong or being ignored
431 (in this case we report actual rate)
432 The MID field is the rate when RSSI is moderate
433 (in this case we cap 11b rates at 5.5 and 11g rates at 24)
434 The LO field is the rate when RSSI is low
435 (in this case we don't report rates, actual current rate used)
436 */
437static const struct
438{
439 v_U8_t beacon_rate_index;
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -0700440 v_U16_t supported_rate[4];
Jeff Johnson295189b2012-06-20 16:38:30 -0700441} supported_data_rate[] =
442{
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -0700443/* IDX HI HM LM LO (RSSI-based index */
444 {2, { 10, 10, 10, 0}},
445 {4, { 20, 20, 10, 0}},
446 {11, { 55, 20, 10, 0}},
447 {12, { 60, 55, 20, 0}},
448 {18, { 90, 55, 20, 0}},
449 {22, {110, 55, 20, 0}},
450 {24, {120, 90, 60, 0}},
451 {36, {180, 120, 60, 0}},
452 {44, {220, 180, 60, 0}},
453 {48, {240, 180, 90, 0}},
454 {66, {330, 180, 90, 0}},
455 {72, {360, 240, 90, 0}},
456 {96, {480, 240, 120, 0}},
457 {108, {540, 240, 120, 0}}
Jeff Johnson295189b2012-06-20 16:38:30 -0700458};
459
460/* MCS Based rate table */
461static struct index_data_rate_type supported_mcs_rate[] =
462{
463/* MCS L20 L40 S20 S40 */
464 {0, {65, 135, 72, 150}},
465 {1, {130, 270, 144, 300}},
466 {2, {195, 405, 217, 450}},
467 {3, {260, 540, 289, 600}},
468 {4, {390, 810, 433, 900}},
469 {5, {520, 1080, 578, 1200}},
470 {6, {585, 1215, 650, 1350}},
471 {7, {650, 1350, 722, 1500}}
472};
473
Leo Chang6f8870f2013-03-26 18:11:36 -0700474#ifdef WLAN_FEATURE_11AC
475
476#define DATA_RATE_11AC_MCS_MASK 0x0F
477
478struct index_vht_data_rate_type
479{
480 v_U8_t beacon_rate_index;
481 v_U16_t supported_rate[2];
482};
483
484typedef enum
485{
486 DATA_RATE_11AC_MAX_MCS_7,
487 DATA_RATE_11AC_MAX_MCS_8,
488 DATA_RATE_11AC_MAX_MCS_9,
489 DATA_RATE_11AC_MAX_MCS_NA
490} eDataRate11ACMaxMcs;
491
492/* MCS Based VHT rate table */
493static struct index_vht_data_rate_type supported_vht_mcs_rate[] =
494{
495/* MCS L80 S80 */
496 {0, {293, 325}},
497 {1, {585, 650}},
498 {2, {878, 975}},
499 {3, {1170, 1300}},
500 {4, {1755, 1950}},
501 {5, {2340, 2600}},
502 {6, {2633, 2925}},
503 {7, {2925, 3250}},
504 {8, {3510, 3900}},
505 {9, {3900, 4333}}
506};
507#endif /* WLAN_FEATURE_11AC */
508
Jeff Johnson295189b2012-06-20 16:38:30 -0700509extern struct net_device_ops net_ops_struct;
510
511/*
512 * FUNCTION: wlan_hdd_cfg80211_init
513 * This function is called by hdd_wlan_startup()
514 * during initialization.
515 * This function is used to initialize and register wiphy structure.
516 */
517struct wiphy *wlan_hdd_cfg80211_init(int priv_size)
518{
519 struct wiphy *wiphy;
520 ENTER();
521
522 /*
523 * Create wiphy device
524 */
525 wiphy = wiphy_new(&wlan_hdd_cfg80211_ops, priv_size);
526
527 if (!wiphy)
528 {
529 /* Print error and jump into err label and free the memory */
530 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: wiphy init failed", __func__);
531 return NULL;
532 }
533
534 return wiphy;
535}
536
537/*
538 * FUNCTION: wlan_hdd_cfg80211_update_band
539 * This function is called from the supplicant through a
540 * private ioctl to change the band value
541 */
542int wlan_hdd_cfg80211_update_band(struct wiphy *wiphy, eCsrBand eBand)
543{
Jeff Johnsone7245742012-09-05 17:12:55 -0700544 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -0700545 switch(eBand)
546 {
547 case eCSR_BAND_24:
548 wiphy->bands[IEEE80211_BAND_2GHZ] = &wlan_hdd_band_2_4_GHZ;
549 wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
550 break;
551 case eCSR_BAND_5G:
Madan Mohan Koyyalamudi6f6390c2012-09-24 13:57:46 -0700552 wiphy->bands[IEEE80211_BAND_2GHZ] = &wlan_hdd_band_p2p_2_4_GHZ;
Jeff Johnson295189b2012-06-20 16:38:30 -0700553 wiphy->bands[IEEE80211_BAND_5GHZ] = &wlan_hdd_band_5_GHZ;
554 break;
555 case eCSR_BAND_ALL:
556 default:
557 wiphy->bands[IEEE80211_BAND_2GHZ] = &wlan_hdd_band_2_4_GHZ;
558 wiphy->bands[IEEE80211_BAND_5GHZ] = &wlan_hdd_band_5_GHZ;
559 }
560 return 0;
561}
562/*
563 * FUNCTION: wlan_hdd_cfg80211_init
564 * This function is called by hdd_wlan_startup()
565 * during initialization.
566 * This function is used to initialize and register wiphy structure.
567 */
568int wlan_hdd_cfg80211_register(struct device *dev,
569 struct wiphy *wiphy,
570 hdd_config_t *pCfg
571 )
572{
Jeff Johnsone7245742012-09-05 17:12:55 -0700573 ENTER();
574
Jeff Johnson295189b2012-06-20 16:38:30 -0700575 /* Now bind the underlying wlan device with wiphy */
576 set_wiphy_dev(wiphy, dev);
577
578 wiphy->mgmt_stypes = wlan_hdd_txrx_stypes;
579
Madan Mohan Koyyalamudi1b4afb02012-10-22 15:25:16 -0700580 wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY;
Jeff Johnson295189b2012-06-20 16:38:30 -0700581
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700582#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
Madan Mohan Koyyalamudi1b4afb02012-10-22 15:25:16 -0700583 wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME
584 | WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
585 | WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
Jeff Johnsone7245742012-09-05 17:12:55 -0700586 | WIPHY_FLAG_OFFCHAN_TX;
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700587#endif
Srinivas Girigowda640728a2013-03-28 12:21:54 -0700588#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_CCX) || defined(FEATURE_WLAN_LFR)
589 if (pCfg->isFastTransitionEnabled
James Zmuda77fb5ae2013-01-29 08:00:17 -0800590#ifdef FEATURE_WLAN_LFR
Srinivas Girigowda640728a2013-03-28 12:21:54 -0700591 || pCfg->isFastRoamIniFeatureEnabled
592#endif
593#ifdef FEATURE_WLAN_CCX
594 || pCfg->isCcxIniFeatureEnabled
595#endif
596 )
597 {
598 wiphy->flags |= WIPHY_FLAG_SUPPORTS_FW_ROAM;
599 }
James Zmuda77fb5ae2013-01-29 08:00:17 -0800600#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -0800601#ifdef FEATURE_WLAN_TDLS
602 wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS
603 | WIPHY_FLAG_TDLS_EXTERNAL_SETUP;
604#endif
605
Madan Mohan Koyyalamudic3a240c2012-09-28 15:34:08 -0700606 /* even with WIPHY_FLAG_CUSTOM_REGULATORY,
607 driver can still register regulatory callback and
608 it will get CRDA setting in wiphy->band[], but
609 driver need to determine what to do with both
610 regulatory settings */
611 wiphy->reg_notifier = wlan_hdd_crda_reg_notifier;
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700612
Jeff Johnson295189b2012-06-20 16:38:30 -0700613 wiphy->max_scan_ssids = MAX_SCAN_SSID;
614
615 wiphy->max_scan_ie_len = 200 ; //TODO: define a macro
616
617 /* Supports STATION & AD-HOC modes right now */
618 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION)
619 | BIT(NL80211_IFTYPE_ADHOC)
Jeff Johnson295189b2012-06-20 16:38:30 -0700620 | BIT(NL80211_IFTYPE_P2P_CLIENT)
621 | BIT(NL80211_IFTYPE_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -0700622 | BIT(NL80211_IFTYPE_AP);
623
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800624#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800625 if( pCfg->enableMCC )
626 {
627 /* Currently, supports up to two channels */
628 wlan_hdd_iface_combination.num_different_channels = 2;
629
630 if( !pCfg->allowMCCGODiffBI )
631 wlan_hdd_iface_combination.beacon_int_infra_match = true;
632
633 }
634 wiphy->iface_combinations = &wlan_hdd_iface_combination;
635 wiphy->n_iface_combinations = 1;
636#endif
Sudhir Sattayappa Kohalli278eee52013-01-16 17:35:13 -0800637
Jeff Johnson295189b2012-06-20 16:38:30 -0700638 /* Before registering we need to update the ht capabilitied based
639 * on ini values*/
640 if( !pCfg->ShortGI20MhzEnable )
641 {
642 wlan_hdd_band_2_4_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_20;
643 wlan_hdd_band_5_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_20;
644 wlan_hdd_band_p2p_2_4_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_20;
645 }
646
647 if( !pCfg->ShortGI40MhzEnable )
648 {
649 wlan_hdd_band_5_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_40;
650 }
651
652 if( !pCfg->nChannelBondingMode5GHz )
653 {
654 wlan_hdd_band_5_GHZ.ht_cap.cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
655 }
656
657 /*Initialize band capability*/
658 switch(pCfg->nBandCapability)
659 {
660 case eCSR_BAND_24:
661 wiphy->bands[IEEE80211_BAND_2GHZ] = &wlan_hdd_band_2_4_GHZ;
662 break;
663 case eCSR_BAND_5G:
Jeff Johnson295189b2012-06-20 16:38:30 -0700664 wiphy->bands[IEEE80211_BAND_2GHZ] = &wlan_hdd_band_p2p_2_4_GHZ;
Jeff Johnson295189b2012-06-20 16:38:30 -0700665 wiphy->bands[IEEE80211_BAND_5GHZ] = &wlan_hdd_band_5_GHZ;
666 break;
667 case eCSR_BAND_ALL:
668 default:
669 wiphy->bands[IEEE80211_BAND_2GHZ] = &wlan_hdd_band_2_4_GHZ;
670 wiphy->bands[IEEE80211_BAND_5GHZ] = &wlan_hdd_band_5_GHZ;
671 }
672 /*Initialise the supported cipher suite details*/
673 wiphy->cipher_suites = hdd_cipher_suites;
674 wiphy->n_cipher_suites = ARRAY_SIZE(hdd_cipher_suites);
675
676 /*signal strength in mBm (100*dBm) */
677 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
678
679#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
Jeff Johnson295189b2012-06-20 16:38:30 -0700680 wiphy->max_remain_on_channel_duration = 1000;
681#endif
Jeff Johnson295189b2012-06-20 16:38:30 -0700682
683 /* Register our wiphy dev with cfg80211 */
684 if (0 > wiphy_register(wiphy))
685 {
686 /* print eror */
687 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wiphy register failed", __func__);
688 return -EIO;
689 }
690
691 EXIT();
692 return 0;
693}
694
Madan Mohan Koyyalamudic3a240c2012-09-28 15:34:08 -0700695/* In this function we will try to get default country code from crda.
696 If the gCrdaDefaultCountryCode is configured in ini file,
697 we will try to call user space crda to get the regulatory settings for
698 that country. We will timeout if we can't get it from crda.
699 It's called by hdd_wlan_startup() after wlan_hdd_cfg80211_register.
700*/
701int wlan_hdd_get_crda_regd_entry(struct wiphy *wiphy, hdd_config_t *pCfg)
702{
703 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
704 if (memcmp(pCfg->crdaDefaultCountryCode,
705 CFG_CRDA_DEFAULT_COUNTRY_CODE_DEFAULT , 2) != 0)
706 {
707 init_completion(&pHddCtx->driver_crda_req);
708 regulatory_hint(wiphy, pCfg->crdaDefaultCountryCode);
709 wait_for_completion_interruptible_timeout(&pHddCtx->driver_crda_req,
710 CRDA_WAIT_TIME);
Yunsen Wange3ba1fb2013-04-05 15:04:43 -0700711 /* if the country is not found from current regulatory.bin,
712 fall back to world domain */
713 if (is_crda_regulatory_entry_valid() == VOS_FALSE)
714 crda_regulatory_entry_default(pCfg->crdaDefaultCountryCode, NUM_REG_DOMAINS-1);
Madan Mohan Koyyalamudic3a240c2012-09-28 15:34:08 -0700715 }
716 return 0;
717}
718
Jeff Johnson295189b2012-06-20 16:38:30 -0700719/* In this function we will do all post VOS start initialization.
720 In this function we will register for all frame in which supplicant
721 is interested.
722*/
723void wlan_hdd_cfg80211_post_voss_start(hdd_adapter_t* pAdapter)
724{
Jeff Johnson295189b2012-06-20 16:38:30 -0700725 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
726 /* Register for all P2P action, public action etc frames */
727 v_U16_t type = (SIR_MAC_MGMT_FRAME << 2) | ( SIR_MAC_MGMT_ACTION << 4);
728
Jeff Johnsone7245742012-09-05 17:12:55 -0700729 ENTER();
730
Jeff Johnson295189b2012-06-20 16:38:30 -0700731 /* Right now we are registering these frame when driver is getting
732 initialized. Once we will move to 2.6.37 kernel, in which we have
733 frame register ops, we will move this code as a part of that */
734 /* GAS Initial Request */
735 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
736 (v_U8_t*)GAS_INITIAL_REQ, GAS_INITIAL_REQ_SIZE );
737
738 /* GAS Initial Response */
739 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
740 (v_U8_t*)GAS_INITIAL_RSP, GAS_INITIAL_RSP_SIZE );
741
742 /* GAS Comeback Request */
743 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
744 (v_U8_t*)GAS_COMEBACK_REQ, GAS_COMEBACK_REQ_SIZE );
745
746 /* GAS Comeback Response */
747 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
748 (v_U8_t*)GAS_COMEBACK_RSP, GAS_COMEBACK_RSP_SIZE );
749
750 /* P2P Public Action */
751 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
752 (v_U8_t*)P2P_PUBLIC_ACTION_FRAME,
753 P2P_PUBLIC_ACTION_FRAME_SIZE );
754
755 /* P2P Action */
756 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
757 (v_U8_t*)P2P_ACTION_FRAME,
758 P2P_ACTION_FRAME_SIZE );
Chet Lanctot186b5732013-03-18 10:26:30 -0700759
760#ifdef WLAN_FEATURE_11W
761 /* SA Query Response Action Frame */
762 sme_RegisterMgmtFrame(hHal, pAdapter->sessionId, type,
763 (v_U8_t*)SA_QUERY_FRAME_RSP,
764 SA_QUERY_FRAME_RSP_SIZE );
765#endif /* WLAN_FEATURE_11W */
Jeff Johnson295189b2012-06-20 16:38:30 -0700766}
767
768void wlan_hdd_cfg80211_pre_voss_stop(hdd_adapter_t* pAdapter)
769{
Jeff Johnson295189b2012-06-20 16:38:30 -0700770 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
771 /* Register for all P2P action, public action etc frames */
772 v_U16_t type = (SIR_MAC_MGMT_FRAME << 2) | ( SIR_MAC_MGMT_ACTION << 4);
773
Jeff Johnsone7245742012-09-05 17:12:55 -0700774 ENTER();
775
Jeff Johnson295189b2012-06-20 16:38:30 -0700776 /* Right now we are registering these frame when driver is getting
777 initialized. Once we will move to 2.6.37 kernel, in which we have
778 frame register ops, we will move this code as a part of that */
779 /* GAS Initial Request */
780
781 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
782 (v_U8_t*)GAS_INITIAL_REQ, GAS_INITIAL_REQ_SIZE );
783
784 /* GAS Initial Response */
785 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
786 (v_U8_t*)GAS_INITIAL_RSP, GAS_INITIAL_RSP_SIZE );
787
788 /* GAS Comeback Request */
789 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
790 (v_U8_t*)GAS_COMEBACK_REQ, GAS_COMEBACK_REQ_SIZE );
791
792 /* GAS Comeback Response */
793 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
794 (v_U8_t*)GAS_COMEBACK_RSP, GAS_COMEBACK_RSP_SIZE );
795
796 /* P2P Public Action */
797 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
798 (v_U8_t*)P2P_PUBLIC_ACTION_FRAME,
799 P2P_PUBLIC_ACTION_FRAME_SIZE );
800
801 /* P2P Action */
802 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
803 (v_U8_t*)P2P_ACTION_FRAME,
804 P2P_ACTION_FRAME_SIZE );
Chet Lanctot186b5732013-03-18 10:26:30 -0700805
806#ifdef WLAN_FEATURE_11W
807 /* SA Query Response Action Frame */
808 sme_DeregisterMgmtFrame(hHal, pAdapter->sessionId, type,
809 (v_U8_t*)SA_QUERY_FRAME_RSP,
810 SA_QUERY_FRAME_RSP_SIZE );
811#endif /* WLAN_FEATURE_11W */
Jeff Johnson295189b2012-06-20 16:38:30 -0700812}
813
814#ifdef FEATURE_WLAN_WAPI
815void wlan_hdd_cfg80211_set_key_wapi(hdd_adapter_t* pAdapter, u8 key_index,
816 const u8 *mac_addr, u8 *key , int key_Len)
817{
818 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
819 tCsrRoamSetKey setKey;
820 v_BOOL_t isConnected = TRUE;
821 int status = 0;
822 v_U32_t roamId= 0xFF;
823 tANI_U8 *pKeyPtr = NULL;
824 int n = 0;
825
826 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
827 __func__,pAdapter->device_mode);
828
Gopichand Nakkalae7480202013-02-11 15:24:22 +0530829 vos_mem_zero(&setKey, sizeof(tCsrRoamSetKey));
Jeff Johnson295189b2012-06-20 16:38:30 -0700830 setKey.keyId = key_index; // Store Key ID
831 setKey.encType = eCSR_ENCRYPT_TYPE_WPI; // SET WAPI Encryption
832 setKey.keyDirection = eSIR_TX_RX; // Key Directionn both TX and RX
833 setKey.paeRole = 0 ; // the PAE role
834 if (!mac_addr || is_broadcast_ether_addr(mac_addr))
835 {
836 vos_set_macaddr_broadcast( (v_MACADDR_t *)setKey.peerMac );
837 }
838 else
839 {
840 isConnected = hdd_connIsConnected(pHddStaCtx);
841 vos_mem_copy(setKey.peerMac,&pHddStaCtx->conn_info.bssId,WNI_CFG_BSSID_LEN);
842 }
843 setKey.keyLength = key_Len;
844 pKeyPtr = setKey.Key;
845 memcpy( pKeyPtr, key, key_Len);
846
847 hddLog(VOS_TRACE_LEVEL_INFO,"\n%s: WAPI KEY LENGTH:0x%04x",
848 __func__, key_Len);
849 for (n = 0 ; n < key_Len; n++)
850 hddLog(VOS_TRACE_LEVEL_INFO, "%s WAPI KEY Data[%d]:%02x ",
851 __func__,n,setKey.Key[n]);
852
853 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_SETTING_KEY;
854 if ( isConnected )
855 {
856 status= sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
857 pAdapter->sessionId, &setKey, &roamId );
858 }
859 if ( status != 0 )
860 {
861 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
862 "[%4d] sme_RoamSetKey returned ERROR status= %d",
863 __LINE__, status );
864 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
865 }
866}
867#endif /* FEATURE_WLAN_WAPI*/
868
869#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
870int wlan_hdd_cfg80211_alloc_new_beacon(hdd_adapter_t *pAdapter,
871 beacon_data_t **ppBeacon,
872 struct beacon_parameters *params)
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700873#else
874int wlan_hdd_cfg80211_alloc_new_beacon(hdd_adapter_t *pAdapter,
875 beacon_data_t **ppBeacon,
876 struct cfg80211_beacon_data *params,
877 int dtim_period)
878#endif
Jeff Johnson295189b2012-06-20 16:38:30 -0700879{
880 int size;
881 beacon_data_t *beacon = NULL;
882 beacon_data_t *old = NULL;
883 int head_len,tail_len;
884
Jeff Johnsone7245742012-09-05 17:12:55 -0700885 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -0700886 if (params->head && !params->head_len)
887 return -EINVAL;
888
889 old = pAdapter->sessionCtx.ap.beacon;
890
891 if (!params->head && !old)
892 return -EINVAL;
893
894 if (params->tail && !params->tail_len)
895 return -EINVAL;
896
897#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,38))
898 /* Kernel 3.0 is not updating dtim_period for set beacon */
899 if (!params->dtim_period)
900 return -EINVAL;
901#endif
902
903 if(params->head)
904 head_len = params->head_len;
905 else
906 head_len = old->head_len;
907
908 if(params->tail || !old)
909 tail_len = params->tail_len;
910 else
911 tail_len = old->tail_len;
912
913 size = sizeof(beacon_data_t) + head_len + tail_len;
914
915 beacon = kzalloc(size, GFP_KERNEL);
916
917 if( beacon == NULL )
918 return -ENOMEM;
919
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700920#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Jeff Johnson295189b2012-06-20 16:38:30 -0700921 if(params->dtim_period || !old )
922 beacon->dtim_period = params->dtim_period;
923 else
924 beacon->dtim_period = old->dtim_period;
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700925#else
926 if(dtim_period || !old )
927 beacon->dtim_period = dtim_period;
928 else
929 beacon->dtim_period = old->dtim_period;
930#endif
Jeff Johnson295189b2012-06-20 16:38:30 -0700931
932 beacon->head = ((u8 *) beacon) + sizeof(beacon_data_t);
933 beacon->tail = beacon->head + head_len;
934 beacon->head_len = head_len;
935 beacon->tail_len = tail_len;
936
937 if(params->head) {
938 memcpy (beacon->head,params->head,beacon->head_len);
939 }
940 else {
941 if(old)
942 memcpy (beacon->head,old->head,beacon->head_len);
943 }
944
945 if(params->tail) {
946 memcpy (beacon->tail,params->tail,beacon->tail_len);
947 }
948 else {
949 if(old)
950 memcpy (beacon->tail,old->tail,beacon->tail_len);
951 }
952
953 *ppBeacon = beacon;
954
955 kfree(old);
956
957 return 0;
958
959}
Jeff Johnson295189b2012-06-20 16:38:30 -0700960
961v_U8_t* wlan_hdd_cfg80211_get_ie_ptr(v_U8_t *pIes, int length, v_U8_t eid)
962{
963 int left = length;
964 v_U8_t *ptr = pIes;
965 v_U8_t elem_id,elem_len;
966
967 while(left >= 2)
968 {
969 elem_id = ptr[0];
970 elem_len = ptr[1];
971 left -= 2;
972 if(elem_len > left)
973 {
974 hddLog(VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi8bdd3112012-09-24 13:55:14 -0700975 FL("****Invalid IEs eid = %d elem_len=%d left=%d*****"),
Jeff Johnson295189b2012-06-20 16:38:30 -0700976 eid,elem_len,left);
977 return NULL;
978 }
979 if (elem_id == eid)
980 {
981 return ptr;
982 }
983
984 left -= elem_len;
985 ptr += (elem_len + 2);
986 }
987 return NULL;
988}
989
Jeff Johnson295189b2012-06-20 16:38:30 -0700990/* Check if rate is 11g rate or not */
991static int wlan_hdd_rate_is_11g(u8 rate)
992{
993 u8 gRateArray[8] = {12, 18, 24, 36, 48, 72, 96, 104}; /* actual rate * 2 */
994 u8 i;
995 for (i = 0; i < 8; i++)
996 {
997 if(rate == gRateArray[i])
998 return TRUE;
999 }
1000 return FALSE;
1001}
1002
1003/* Check for 11g rate and set proper 11g only mode */
1004static void wlan_hdd_check_11gmode(u8 *pIe, u8* require_ht,
1005 u8* pCheckRatesfor11g, eSapPhyMode* pSapHw_mode)
1006{
1007 u8 i, num_rates = pIe[0];
1008
1009 pIe += 1;
1010 for ( i = 0; i < num_rates; i++)
1011 {
1012 if( *pCheckRatesfor11g && (TRUE == wlan_hdd_rate_is_11g(pIe[i] & RATE_MASK)))
1013 {
1014 /* If rate set have 11g rate than change the mode to 11G */
1015 *pSapHw_mode = eSAP_DOT11_MODE_11g;
1016 if (pIe[i] & BASIC_RATE_MASK)
1017 {
1018 /* If we have 11g rate as basic rate, it means mode
1019 is 11g only mode.
1020 */
1021 *pSapHw_mode = eSAP_DOT11_MODE_11g_ONLY;
1022 *pCheckRatesfor11g = FALSE;
1023 }
1024 }
1025 else if((BASIC_RATE_MASK | WLAN_BSS_MEMBERSHIP_SELECTOR_HT_PHY) == pIe[i])
1026 {
1027 *require_ht = TRUE;
1028 }
1029 }
1030 return;
1031}
1032
1033static void wlan_hdd_set_sapHwmode(hdd_adapter_t *pHostapdAdapter)
1034{
1035 tsap_Config_t *pConfig = &pHostapdAdapter->sessionCtx.ap.sapConfig;
1036 beacon_data_t *pBeacon = pHostapdAdapter->sessionCtx.ap.beacon;
1037 struct ieee80211_mgmt *pMgmt_frame = (struct ieee80211_mgmt*)pBeacon->head;
1038 u8 checkRatesfor11g = TRUE;
1039 u8 require_ht = FALSE;
1040 u8 *pIe=NULL;
1041
1042 pConfig->SapHw_mode= eSAP_DOT11_MODE_11b;
1043
1044 pIe = wlan_hdd_cfg80211_get_ie_ptr(&pMgmt_frame->u.beacon.variable[0],
1045 pBeacon->head_len, WLAN_EID_SUPP_RATES);
1046 if (pIe != NULL)
1047 {
1048 pIe += 1;
1049 wlan_hdd_check_11gmode(pIe, &require_ht, &checkRatesfor11g,
1050 &pConfig->SapHw_mode);
1051 }
1052
1053 pIe = wlan_hdd_cfg80211_get_ie_ptr(pBeacon->tail, pBeacon->tail_len,
1054 WLAN_EID_EXT_SUPP_RATES);
1055 if (pIe != NULL)
1056 {
1057
1058 pIe += 1;
1059 wlan_hdd_check_11gmode(pIe, &require_ht, &checkRatesfor11g,
1060 &pConfig->SapHw_mode);
1061 }
1062
1063 if( pConfig->channel > 14 )
1064 {
1065 pConfig->SapHw_mode= eSAP_DOT11_MODE_11a;
1066 }
1067
1068 pIe = wlan_hdd_cfg80211_get_ie_ptr(pBeacon->tail, pBeacon->tail_len,
1069 WLAN_EID_HT_CAPABILITY);
1070
1071 if(pIe)
1072 {
1073 pConfig->SapHw_mode= eSAP_DOT11_MODE_11n;
1074 if(require_ht)
1075 pConfig->SapHw_mode= eSAP_DOT11_MODE_11n_ONLY;
1076 }
1077}
1078
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301079static int wlan_hdd_add_ie(hdd_adapter_t* pHostapdAdapter, v_U8_t *genie,
1080 v_U8_t *total_ielen, v_U8_t *oui, v_U8_t oui_size)
1081{
1082 v_U8_t ielen = 0;
1083 v_U8_t *pIe = NULL;
1084 beacon_data_t *pBeacon = pHostapdAdapter->sessionCtx.ap.beacon;
1085
1086 pIe = wlan_hdd_get_vendor_oui_ie_ptr(oui, oui_size,
1087 pBeacon->tail, pBeacon->tail_len);
1088
1089 if (pIe)
1090 {
1091 ielen = pIe[1] + 2;
1092 if ((*total_ielen + ielen) <= MAX_GENIE_LEN)
1093 {
1094 vos_mem_copy(&genie[*total_ielen], pIe, ielen);
1095 }
1096 else
1097 {
1098 hddLog( VOS_TRACE_LEVEL_ERROR, "**Ie Length is too big***");
1099 return -EINVAL;
1100 }
1101 *total_ielen += ielen;
1102 }
1103 return 0;
1104}
1105
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001106#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07001107static int wlan_hdd_cfg80211_update_apies(hdd_adapter_t* pHostapdAdapter,
1108 struct beacon_parameters *params)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001109#else
1110static int wlan_hdd_cfg80211_update_apies(hdd_adapter_t* pHostapdAdapter,
1111 struct cfg80211_beacon_data *params)
1112#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07001113{
1114 v_U8_t *genie;
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301115 v_U8_t total_ielen = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07001116 v_U8_t addIE[1] = {0};
Jeff Johnsone7245742012-09-05 17:12:55 -07001117 int ret = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07001118
1119 genie = vos_mem_malloc(MAX_GENIE_LEN);
1120
1121 if(genie == NULL) {
1122
1123 return -ENOMEM;
1124 }
1125
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301126 if (0 != wlan_hdd_add_ie(pHostapdAdapter, genie,
1127 &total_ielen, WPS_OUI_TYPE, WPS_OUI_TYPE_SIZE))
Jeff Johnson295189b2012-06-20 16:38:30 -07001128 {
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301129 ret = -EINVAL;
1130 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001131 }
1132
1133#ifdef WLAN_FEATURE_WFD
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301134 if (0 != wlan_hdd_add_ie(pHostapdAdapter, genie,
1135 &total_ielen, WFD_OUI_TYPE, WFD_OUI_TYPE_SIZE))
1136 {
1137 ret = -EINVAL;
1138 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001139 }
1140#endif
1141
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301142 if (0 != wlan_hdd_add_ie(pHostapdAdapter, genie,
1143 &total_ielen, P2P_OUI_TYPE, P2P_OUI_TYPE_SIZE))
Jeff Johnson295189b2012-06-20 16:38:30 -07001144 {
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301145 ret = -EINVAL;
1146 goto done;
1147 }
1148
1149 if (WLAN_HDD_SOFTAP == pHostapdAdapter->device_mode)
1150 {
1151 if (0 != wlan_hdd_add_ie(pHostapdAdapter, genie,
1152 &total_ielen, SS_OUI_TYPE, SS_OUI_TYPE_SIZE))
Jeff Johnson295189b2012-06-20 16:38:30 -07001153 {
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301154 ret = -EINVAL;
1155 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001156 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001157 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001158
1159 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1160 WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA, genie, total_ielen, NULL,
1161 eANI_BOOLEAN_FALSE)==eHAL_STATUS_FAILURE)
1162 {
1163 hddLog(LOGE,
1164 "Could not pass on WNI_CFG_PROBE_RSP_BCN_ADDNIE_DATA to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001165 ret = -EINVAL;
1166 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001167 }
1168
1169 if (ccmCfgSetInt((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1170 WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG, 1,NULL,
1171 test_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags) ?
1172 eANI_BOOLEAN_TRUE : eANI_BOOLEAN_FALSE)
1173 ==eHAL_STATUS_FAILURE)
1174 {
1175 hddLog(LOGE,
1176 "Could not pass on WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001177 ret = -EINVAL;
1178 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001179 }
1180
1181 // Added for ProResp IE
1182 if ( (params->proberesp_ies != NULL) && (params->proberesp_ies_len != 0) )
1183 {
1184 u16 rem_probe_resp_ie_len = params->proberesp_ies_len;
1185 u8 probe_rsp_ie_len[3] = {0};
1186 u8 counter = 0;
1187 /* Check Probe Resp Length if it is greater then 255 then Store
1188 Probe Resp IEs into WNI_CFG_PROBE_RSP_ADDNIE_DATA1 &
1189 WNI_CFG_PROBE_RSP_ADDNIE_DATA2 CFG Variable As We are not able
1190 Store More then 255 bytes into One Variable.
1191 */
1192 while ((rem_probe_resp_ie_len > 0) && (counter < 3))
1193 {
1194 if (rem_probe_resp_ie_len > MAX_CFG_STRING_LEN)
1195 {
1196 probe_rsp_ie_len[counter++] = MAX_CFG_STRING_LEN;
1197 rem_probe_resp_ie_len -= MAX_CFG_STRING_LEN;
1198 }
1199 else
1200 {
1201 probe_rsp_ie_len[counter++] = rem_probe_resp_ie_len;
1202 rem_probe_resp_ie_len = 0;
1203 }
1204 }
1205
1206 rem_probe_resp_ie_len = 0;
1207
1208 if (probe_rsp_ie_len[0] > 0)
1209 {
1210 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1211 WNI_CFG_PROBE_RSP_ADDNIE_DATA1,
1212 (tANI_U8*)&params->proberesp_ies[rem_probe_resp_ie_len],
1213 probe_rsp_ie_len[0], NULL,
1214 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
1215 {
1216 hddLog(LOGE,
1217 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA1 to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001218 ret = -EINVAL;
1219 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001220 }
1221 rem_probe_resp_ie_len += probe_rsp_ie_len[0];
1222 }
1223
1224 if (probe_rsp_ie_len[1] > 0)
1225 {
1226 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1227 WNI_CFG_PROBE_RSP_ADDNIE_DATA2,
1228 (tANI_U8*)&params->proberesp_ies[rem_probe_resp_ie_len],
1229 probe_rsp_ie_len[1], NULL,
1230 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
1231 {
1232 hddLog(LOGE,
1233 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA2 to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001234 ret = -EINVAL;
1235 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001236 }
1237 rem_probe_resp_ie_len += probe_rsp_ie_len[1];
1238 }
1239
1240 if (probe_rsp_ie_len[2] > 0)
1241 {
1242 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1243 WNI_CFG_PROBE_RSP_ADDNIE_DATA3,
1244 (tANI_U8*)&params->proberesp_ies[rem_probe_resp_ie_len],
1245 probe_rsp_ie_len[2], NULL,
1246 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
1247 {
1248 hddLog(LOGE,
1249 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA3 to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001250 ret = -EINVAL;
1251 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001252 }
1253 rem_probe_resp_ie_len += probe_rsp_ie_len[2];
1254 }
1255
1256 if (probe_rsp_ie_len[1] == 0 )
1257 {
1258 if ( eHAL_STATUS_FAILURE == ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1259 WNI_CFG_PROBE_RSP_ADDNIE_DATA2, (tANI_U8*)addIE, 0, NULL,
1260 eANI_BOOLEAN_FALSE) )
1261 {
1262 hddLog(LOGE,
1263 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA2 to CCM\n");
1264 }
1265 }
1266
1267 if (probe_rsp_ie_len[2] == 0 )
1268 {
1269 if ( eHAL_STATUS_FAILURE == ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1270 WNI_CFG_PROBE_RSP_ADDNIE_DATA3, (tANI_U8*)addIE, 0, NULL,
1271 eANI_BOOLEAN_FALSE) )
1272 {
1273 hddLog(LOGE,
1274 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_DATA3 to CCM\n");
1275 }
1276 }
1277
1278 if (ccmCfgSetInt((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1279 WNI_CFG_PROBE_RSP_ADDNIE_FLAG, 1,NULL,
1280 test_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags) ?
1281 eANI_BOOLEAN_TRUE : eANI_BOOLEAN_FALSE)
1282 == eHAL_STATUS_FAILURE)
1283 {
1284 hddLog(LOGE,
1285 "Could not pass on WNI_CFG_PROBE_RSP_ADDNIE_FLAG to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001286 ret = -EINVAL;
1287 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001288 }
1289 }
1290 else
1291 {
1292 // Reset WNI_CFG_PROBE_RSP Flags
1293 wlan_hdd_reset_prob_rspies(pHostapdAdapter);
1294
1295 hddLog(VOS_TRACE_LEVEL_INFO,
1296 "%s: No Probe Response IE received in set beacon",
1297 __func__);
1298 }
1299
1300 // Added for AssocResp IE
1301 if ( (params->assocresp_ies != NULL) && (params->assocresp_ies_len != 0) )
1302 {
1303 if (ccmCfgSetStr((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1304 WNI_CFG_ASSOC_RSP_ADDNIE_DATA, (tANI_U8*)params->assocresp_ies,
1305 params->assocresp_ies_len, NULL,
1306 eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
1307 {
1308 hddLog(LOGE,
1309 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_DATA to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001310 ret = -EINVAL;
1311 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001312 }
1313
1314 if (ccmCfgSetInt((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1315 WNI_CFG_ASSOC_RSP_ADDNIE_FLAG, 1, NULL,
1316 test_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags) ?
1317 eANI_BOOLEAN_TRUE : eANI_BOOLEAN_FALSE)
1318 == eHAL_STATUS_FAILURE)
1319 {
1320 hddLog(LOGE,
1321 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_FLAG to CCM");
Jeff Johnsone7245742012-09-05 17:12:55 -07001322 ret = -EINVAL;
1323 goto done;
Jeff Johnson295189b2012-06-20 16:38:30 -07001324 }
1325 }
1326 else
1327 {
1328 hddLog(VOS_TRACE_LEVEL_INFO,
1329 "%s: No Assoc Response IE received in set beacon",
1330 __func__);
1331
1332 if ( eHAL_STATUS_FAILURE == ccmCfgSetInt((WLAN_HDD_GET_CTX(pHostapdAdapter))->hHal,
1333 WNI_CFG_ASSOC_RSP_ADDNIE_FLAG, 0, NULL,
1334 eANI_BOOLEAN_FALSE) )
1335 {
1336 hddLog(LOGE,
1337 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_FLAG to CCM\n");
1338 }
1339 }
1340
Jeff Johnsone7245742012-09-05 17:12:55 -07001341done:
Jeff Johnson295189b2012-06-20 16:38:30 -07001342 vos_mem_free(genie);
Gopichand Nakkala2b25f4e2013-03-21 19:14:07 +05301343 return ret;
Jeff Johnson295189b2012-06-20 16:38:30 -07001344}
Jeff Johnson295189b2012-06-20 16:38:30 -07001345
1346/*
1347 * FUNCTION: wlan_hdd_validate_operation_channel
1348 * called by wlan_hdd_cfg80211_start_bss() and
1349 * wlan_hdd_cfg80211_set_channel()
1350 * This function validates whether given channel is part of valid
1351 * channel list.
1352 */
1353static VOS_STATUS wlan_hdd_validate_operation_channel(hdd_adapter_t *pAdapter,int channel)
1354{
1355
1356 v_U32_t num_ch = 0;
1357 u8 valid_ch[WNI_CFG_VALID_CHANNEL_LIST_LEN];
1358 u32 indx = 0;
1359 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301360 v_U8_t fValidChannel = FALSE, count = 0;
1361 hdd_config_t *hdd_pConfig_ini= (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini;
Jeff Johnson295189b2012-06-20 16:38:30 -07001362
1363 num_ch = WNI_CFG_VALID_CHANNEL_LIST_LEN;
1364
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301365 if ( hdd_pConfig_ini->sapAllowAllChannel)
Jeff Johnson295189b2012-06-20 16:38:30 -07001366 {
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301367 /* Validate the channel */
1368 for (count = RF_CHAN_1 ; count <= RF_CHAN_165 ; count++)
Jeff Johnson295189b2012-06-20 16:38:30 -07001369 {
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301370 if ( channel == rfChannels[count].channelNum )
1371 {
1372 fValidChannel = TRUE;
1373 break;
1374 }
1375 }
1376 if (fValidChannel != TRUE)
1377 {
1378 hddLog(VOS_TRACE_LEVEL_ERROR,
1379 "%s: Invalid Channel [%d]", __func__, channel);
1380 return VOS_STATUS_E_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07001381 }
1382 }
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301383 else
Jeff Johnson295189b2012-06-20 16:38:30 -07001384 {
Madan Mohan Koyylamudi64267f72013-02-05 14:07:08 +05301385 if (0 != ccmCfgGetStr(hHal, WNI_CFG_VALID_CHANNEL_LIST,
1386 valid_ch, &num_ch))
1387 {
1388 hddLog(VOS_TRACE_LEVEL_ERROR,
1389 "%s: failed to get valid channel list", __func__);
1390 return VOS_STATUS_E_FAILURE;
1391 }
1392 for (indx = 0; indx < num_ch; indx++)
1393 {
1394 if (channel == valid_ch[indx])
1395 {
1396 break;
1397 }
1398 }
1399
1400 if (indx >= num_ch)
1401 {
1402 hddLog(VOS_TRACE_LEVEL_ERROR,
1403 "%s: Invalid Channel [%d]", __func__, channel);
1404 return VOS_STATUS_E_FAILURE;
1405 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001406 }
1407 return VOS_STATUS_SUCCESS;
1408
1409}
1410
Viral Modi3a32cc52013-02-08 11:14:52 -08001411/**
1412 * FUNCTION: wlan_hdd_cfg80211_set_channel
1413 * This function is used to set the channel number
1414 */
1415static int wlan_hdd_cfg80211_set_channel( struct wiphy *wiphy, struct net_device *dev,
1416 struct ieee80211_channel *chan,
1417 enum nl80211_channel_type channel_type
1418 )
1419{
1420 v_U32_t num_ch = 0;
Jeff Johnson4416a782013-03-25 14:17:50 -07001421 int channel = 0;
Viral Modi3a32cc52013-02-08 11:14:52 -08001422 hdd_adapter_t *pAdapter = NULL;
1423 int freq = chan->center_freq; /* freq is in MHZ */
1424
1425 ENTER();
1426
1427 if( NULL == dev )
1428 {
1429 hddLog(VOS_TRACE_LEVEL_ERROR,
1430 "%s: Called with dev = NULL.\n", __func__);
1431 return -ENODEV;
1432 }
1433 pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
1434
1435 hddLog(VOS_TRACE_LEVEL_INFO,
1436 "%s: device_mode = %d freq = %d \n",__func__,
1437 pAdapter->device_mode, chan->center_freq);
1438 if ((WLAN_HDD_GET_CTX(pAdapter))->isLogpInProgress)
1439 {
1440 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL, "%s:LOGP in Progress. Ignore!!!",__func__);
1441 return -EAGAIN;
1442 }
1443
1444 /*
1445 * Do freq to chan conversion
1446 * TODO: for 11a
1447 */
1448
1449 channel = ieee80211_frequency_to_channel(freq);
1450
1451 /* Check freq range */
1452 if ((WNI_CFG_CURRENT_CHANNEL_STAMIN > channel) ||
1453 (WNI_CFG_CURRENT_CHANNEL_STAMAX < channel))
1454 {
1455 hddLog(VOS_TRACE_LEVEL_ERROR,
1456 "%s: Channel [%d] is outside valid range from %d to %d\n",
1457 __func__, channel, WNI_CFG_CURRENT_CHANNEL_STAMIN,
1458 WNI_CFG_CURRENT_CHANNEL_STAMAX);
1459 return -EINVAL;
1460 }
1461
1462 num_ch = WNI_CFG_VALID_CHANNEL_LIST_LEN;
1463
Gopichand Nakkala6ab19562013-03-07 13:59:42 +05301464 if ((WLAN_HDD_SOFTAP != pAdapter->device_mode) &&
1465 (WLAN_HDD_P2P_GO != pAdapter->device_mode))
Viral Modi3a32cc52013-02-08 11:14:52 -08001466 {
1467 if(VOS_STATUS_SUCCESS != wlan_hdd_validate_operation_channel(pAdapter,channel))
1468 {
1469 hddLog(VOS_TRACE_LEVEL_ERROR,
1470 "%s: Invalid Channel [%d] \n", __func__, channel);
1471 return -EINVAL;
1472 }
1473 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
1474 "%s: set channel to [%d] for device mode =%d",
1475 __func__, channel,pAdapter->device_mode);
1476 }
1477 if( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Viral Modi3a32cc52013-02-08 11:14:52 -08001478 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Viral Modi3a32cc52013-02-08 11:14:52 -08001479 )
1480 {
1481 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
1482 tCsrRoamProfile * pRoamProfile = &pWextState->roamProfile;
1483 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
1484
1485 if (eConnectionState_IbssConnected == pHddStaCtx->conn_info.connState)
1486 {
1487 /* Link is up then return cant set channel*/
1488 hddLog( VOS_TRACE_LEVEL_ERROR,
1489 "%s: IBSS Associated, can't set the channel\n", __func__);
1490 return -EINVAL;
1491 }
1492
1493 num_ch = pRoamProfile->ChannelInfo.numOfChannels = 1;
1494 pHddStaCtx->conn_info.operationChannel = channel;
1495 pRoamProfile->ChannelInfo.ChannelList =
1496 &pHddStaCtx->conn_info.operationChannel;
1497 }
1498 else if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Viral Modi3a32cc52013-02-08 11:14:52 -08001499 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Viral Modi3a32cc52013-02-08 11:14:52 -08001500 )
1501 {
Gopichand Nakkalac8fa7b62013-03-11 13:56:41 +05301502 if (WLAN_HDD_P2P_GO == pAdapter->device_mode)
1503 {
1504 if(VOS_STATUS_SUCCESS !=
1505 wlan_hdd_validate_operation_channel(pAdapter,channel))
1506 {
1507 hddLog(VOS_TRACE_LEVEL_ERROR,
1508 "%s: Invalid Channel [%d] \n", __func__, channel);
1509 return -EINVAL;
1510 }
1511 (WLAN_HDD_GET_AP_CTX_PTR(pAdapter))->sapConfig.channel = channel;
1512 }
1513 else if ( WLAN_HDD_SOFTAP == pAdapter->device_mode )
Viral Modi3a32cc52013-02-08 11:14:52 -08001514 {
1515 hdd_config_t *cfg_param = (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini;
1516
1517 /* If auto channel selection is configured as enable/ 1 then ignore
1518 channel set by supplicant
1519 */
1520 if ( cfg_param->apAutoChannelSelection )
1521 {
Gopichand Nakkalac8fa7b62013-03-11 13:56:41 +05301522 (WLAN_HDD_GET_AP_CTX_PTR(pAdapter))->sapConfig.channel =
1523 AUTO_CHANNEL_SELECT;
Viral Modi3a32cc52013-02-08 11:14:52 -08001524 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
1525 "%s: set channel to auto channel (0) for device mode =%d",
1526 __func__, pAdapter->device_mode);
1527 }
Gopichand Nakkalac8fa7b62013-03-11 13:56:41 +05301528 else
1529 {
1530 if(VOS_STATUS_SUCCESS !=
1531 wlan_hdd_validate_operation_channel(pAdapter,channel))
1532 {
1533 hddLog(VOS_TRACE_LEVEL_ERROR,
1534 "%s: Invalid Channel [%d] \n", __func__, channel);
1535 return -EINVAL;
1536 }
1537 (WLAN_HDD_GET_AP_CTX_PTR(pAdapter))->sapConfig.channel = channel;
1538 }
Viral Modi3a32cc52013-02-08 11:14:52 -08001539 }
1540 }
1541 else
1542 {
1543 hddLog(VOS_TRACE_LEVEL_FATAL,
1544 "%s: Invalid device mode failed to set valid channel", __func__);
1545 return -EINVAL;
1546 }
1547 EXIT();
1548 return 0;
1549}
1550
Madan Mohan Koyyalamudi59381622012-11-28 01:56:47 +05301551/*
1552 * FUNCTION: wlan_hdd_select_cbmode
1553 * called by wlan_hdd_cfg80211_start_bss() and
1554 * This function selects the cbmode based on primary channel
1555 */
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001556VOS_STATUS wlan_sap_select_cbmode(void *pAdapter,eSapPhyMode SapHw_mode, v_U8_t channel)
Madan Mohan Koyyalamudi59381622012-11-28 01:56:47 +05301557{
1558 tSmeConfigParams smeConfig;
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001559 hdd_context_t *pHddCtx = ( hdd_context_t *) pAdapter;
1560 hdd_config_t *pConfigIni = ((hdd_context_t *)(pAdapter))->cfg_ini;
1561
Madan Mohan Koyyalamudi59381622012-11-28 01:56:47 +05301562 if(
1563#ifdef WLAN_FEATURE_11AC
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001564 SapHw_mode != eSAP_DOT11_MODE_11ac &&
1565 SapHw_mode != eSAP_DOT11_MODE_11ac_ONLY &&
Madan Mohan Koyyalamudi59381622012-11-28 01:56:47 +05301566#endif
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001567 SapHw_mode != eSAP_DOT11_MODE_11n &&
1568 SapHw_mode != eSAP_DOT11_MODE_11n_ONLY
Madan Mohan Koyyalamudi59381622012-11-28 01:56:47 +05301569 )
1570 {
1571 return VOS_STATUS_SUCCESS;
1572 }
1573
1574 if (!pConfigIni->nChannelBondingMode5GHz) {
1575 return VOS_STATUS_SUCCESS;
1576 }
1577
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001578 //channel = pSapConfig->channel;
Madan Mohan Koyyalamudi59381622012-11-28 01:56:47 +05301579 vos_mem_zero(&smeConfig, sizeof (tSmeConfigParams));
1580
1581 sme_GetConfigParam(pHddCtx->hHal, &smeConfig);
1582
1583#ifdef WLAN_FEATURE_11AC
1584
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001585 if ( SapHw_mode == eSAP_DOT11_MODE_11ac ||
1586 SapHw_mode == eSAP_DOT11_MODE_11ac_ONLY )
Madan Mohan Koyyalamudi59381622012-11-28 01:56:47 +05301587 {
1588 if ( channel== 36 || channel == 52 || channel == 100 ||
1589 channel == 116 || channel == 149 )
1590 {
1591 smeConfig.csrConfig.channelBondingMode5GHz =
1592 PHY_QUADRUPLE_CHANNEL_20MHZ_LOW_40MHZ_LOW - 1;
1593 }
1594 else if ( channel == 40 || channel == 56 || channel == 104 ||
1595 channel == 120 || channel == 153 )
1596 {
1597 smeConfig.csrConfig.channelBondingMode5GHz =
1598 PHY_QUADRUPLE_CHANNEL_20MHZ_HIGH_40MHZ_LOW - 1;
1599 }
1600 else if ( channel == 44 || channel == 60 || channel == 108 ||
1601 channel == 124 || channel == 157 )
1602 {
1603 smeConfig.csrConfig.channelBondingMode5GHz =
1604 PHY_QUADRUPLE_CHANNEL_20MHZ_LOW_40MHZ_HIGH -1;
1605 }
1606 else if ( channel == 48 || channel == 64 || channel == 112 ||
1607 channel == 128 || channel == 161 )
1608 {
1609 smeConfig.csrConfig.channelBondingMode5GHz =
1610 PHY_QUADRUPLE_CHANNEL_20MHZ_HIGH_40MHZ_HIGH - 1;
1611 }
Shailender Karmuchi84f11f02013-02-12 17:11:45 -08001612 else if ( channel == 165 )
1613 {
1614 smeConfig.csrConfig.channelBondingMode5GHz = 0;
1615 }
Madan Mohan Koyyalamudi59381622012-11-28 01:56:47 +05301616 }
1617#endif
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001618 if ( SapHw_mode == eSAP_DOT11_MODE_11n ||
1619 SapHw_mode == eSAP_DOT11_MODE_11n_ONLY )
Madan Mohan Koyyalamudi59381622012-11-28 01:56:47 +05301620 {
1621 if ( channel== 40 || channel == 48 || channel == 56 ||
1622 channel == 64 || channel == 104 || channel == 112 ||
1623 channel == 120 || channel == 128 || channel == 136 ||
1624 channel == 144 || channel == 153 || channel == 161 )
1625 {
1626 smeConfig.csrConfig.channelBondingMode5GHz = 1;
1627 }
1628 else if ( channel== 36 || channel == 44 || channel == 52 ||
1629 channel == 60 || channel == 100 || channel == 108 ||
1630 channel == 116 || channel == 124 || channel == 132 ||
1631 channel == 140 || channel == 149 || channel == 157 )
1632 {
1633 smeConfig.csrConfig.channelBondingMode5GHz = 2;
1634 }
Shailender Karmuchi84f11f02013-02-12 17:11:45 -08001635 else if ( channel == 165 )
1636 {
1637 smeConfig.csrConfig.channelBondingMode5GHz = 0;
1638 }
Madan Mohan Koyyalamudi59381622012-11-28 01:56:47 +05301639 }
1640 pr_info ("cbmode selected=%ld\n",smeConfig.csrConfig.channelBondingMode5GHz);
1641
1642 sme_UpdateConfig (pHddCtx->hHal,&smeConfig);
1643 return VOS_STATUS_SUCCESS;
1644}
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001645
Jeff Johnson295189b2012-06-20 16:38:30 -07001646#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
1647static int wlan_hdd_cfg80211_start_bss(hdd_adapter_t *pHostapdAdapter,
1648 struct beacon_parameters *params)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001649#else
1650static int wlan_hdd_cfg80211_start_bss(hdd_adapter_t *pHostapdAdapter,
1651 struct cfg80211_beacon_data *params,
1652 const u8 *ssid, size_t ssid_len,
1653 enum nl80211_hidden_ssid hidden_ssid)
1654#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07001655{
1656 tsap_Config_t *pConfig;
1657 beacon_data_t *pBeacon = NULL;
1658 struct ieee80211_mgmt *pMgmt_frame;
1659 v_U8_t *pIe=NULL;
1660 v_U16_t capab_info;
1661 eCsrAuthType RSNAuthType;
1662 eCsrEncryptionType RSNEncryptType;
1663 eCsrEncryptionType mcRSNEncryptType;
1664 int status = VOS_STATUS_SUCCESS;
1665 tpWLAN_SAPEventCB pSapEventCallback;
1666 hdd_hostapd_state_t *pHostapdState;
1667 v_U8_t wpaRsnIEdata[(SIR_MAC_MAX_IE_LENGTH * 2)+4]; //Max ie length 255 * 2(WPA+RSN) + 2 bytes (vendor specific ID) * 2
1668 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pHostapdAdapter))->pvosContext;
Madan Mohan Koyylamudia16d0202013-02-01 11:05:57 +05301669 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pHostapdAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001670 struct qc_mac_acl_entry *acl_entry = NULL;
1671 v_SINT_t i;
Madan Mohan Koyyalamudi543172b2012-12-05 16:40:18 -08001672 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pHostapdAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001673
1674 ENTER();
1675
1676 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pHostapdAdapter);
1677
1678 pConfig = &pHostapdAdapter->sessionCtx.ap.sapConfig;
1679
1680 pBeacon = pHostapdAdapter->sessionCtx.ap.beacon;
1681
1682 pMgmt_frame = (struct ieee80211_mgmt*)pBeacon->head;
1683
1684 pConfig->beacon_int = pMgmt_frame->u.beacon.beacon_int;
1685
1686 //channel is already set in the set_channel Call back
1687 //pConfig->channel = pCommitConfig->channel;
1688
1689 /*Protection parameter to enable or disable*/
1690 pConfig->protEnabled =
1691 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apProtEnabled;
1692
1693 pConfig->dtim_period = pBeacon->dtim_period;
1694
1695 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,"****pConfig->dtim_period=%d***\n",
1696 pConfig->dtim_period);
1697
1698
Madan Mohan Koyyalamudie0ca11f2012-11-27 15:57:52 -08001699 if (pHostapdAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson32d95a32012-09-10 13:15:23 -07001700 {
1701 pIe = wlan_hdd_cfg80211_get_ie_ptr(pBeacon->tail, pBeacon->tail_len,
Jeff Johnson295189b2012-06-20 16:38:30 -07001702 WLAN_EID_COUNTRY);
Jeff Johnson32d95a32012-09-10 13:15:23 -07001703 if(pIe)
Jeff Johnson295189b2012-06-20 16:38:30 -07001704 {
Jeff Johnson32d95a32012-09-10 13:15:23 -07001705 tANI_BOOLEAN restartNeeded;
Jeff Johnson32d95a32012-09-10 13:15:23 -07001706 pConfig->ieee80211d = 1;
1707 vos_mem_copy(pConfig->countryCode, &pIe[2], 3);
1708 sme_setRegInfo(hHal, pConfig->countryCode);
1709 sme_ResetCountryCodeInformation(hHal, &restartNeeded);
Jeff Johnson295189b2012-06-20 16:38:30 -07001710 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07001711 else
1712 {
1713 pConfig->ieee80211d = 0;
1714 }
Madan Mohan Koyylamudia16d0202013-02-01 11:05:57 +05301715 /*
1716 * If auto channel is configured i.e. channel is 0,
1717 * so skip channel validation.
1718 */
1719 if( AUTO_CHANNEL_SELECT != pConfig->channel )
1720 {
1721 if(VOS_STATUS_SUCCESS != wlan_hdd_validate_operation_channel(pHostapdAdapter,pConfig->channel))
1722 {
1723 hddLog(VOS_TRACE_LEVEL_ERROR,
1724 "%s: Invalid Channel [%d] \n", __func__, pConfig->channel);
1725 return -EINVAL;
1726 }
1727 }
1728 else
1729 {
1730 if(1 != pHddCtx->is_dynamic_channel_range_set)
1731 {
1732 hdd_config_t *hdd_pConfig= (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini;
1733 WLANSAP_SetChannelRange(hHal, hdd_pConfig->apStartChannelNum,
1734 hdd_pConfig->apEndChannelNum,hdd_pConfig->apOperatingBand);
1735 }
1736 pHddCtx->is_dynamic_channel_range_set = 0;
1737 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001738 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07001739 else
Jeff Johnson295189b2012-06-20 16:38:30 -07001740 {
1741 pConfig->ieee80211d = 0;
1742 }
1743 pConfig->authType = eSAP_AUTO_SWITCH;
1744
1745 capab_info = pMgmt_frame->u.beacon.capab_info;
1746
1747 pConfig->privacy = (pMgmt_frame->u.beacon.capab_info &
1748 WLAN_CAPABILITY_PRIVACY) ? VOS_TRUE : VOS_FALSE;
1749
1750 (WLAN_HDD_GET_AP_CTX_PTR(pHostapdAdapter))->uPrivacy = pConfig->privacy;
1751
1752 /*Set wps station to configured*/
1753 pIe = wlan_hdd_get_wps_ie_ptr(pBeacon->tail, pBeacon->tail_len);
1754
1755 if(pIe)
1756 {
1757 if(pIe[1] < (2 + WPS_OUI_TYPE_SIZE))
1758 {
1759 hddLog( VOS_TRACE_LEVEL_ERROR, "**Wps Ie Length is too small***\n");
1760 return -EINVAL;
1761 }
1762 else if(memcmp(&pIe[2], WPS_OUI_TYPE, WPS_OUI_TYPE_SIZE) == 0)
1763 {
Madan Mohan Koyyalamudi8bdd3112012-09-24 13:55:14 -07001764 hddLog( VOS_TRACE_LEVEL_INFO, "** WPS IE(len %d) ***", (pIe[1]+2));
Jeff Johnson295189b2012-06-20 16:38:30 -07001765 /* Check 15 bit of WPS IE as it contain information for wps state
1766 * WPS state
1767 */
1768 if(SAP_WPS_ENABLED_UNCONFIGURED == pIe[15])
1769 {
1770 pConfig->wps_state = SAP_WPS_ENABLED_UNCONFIGURED;
1771 } else if(SAP_WPS_ENABLED_CONFIGURED == pIe[15])
1772 {
1773 pConfig->wps_state = SAP_WPS_ENABLED_CONFIGURED;
1774 }
1775 }
1776 }
1777 else
1778 {
1779 pConfig->wps_state = SAP_WPS_DISABLED;
1780 }
1781 pConfig->fwdWPSPBCProbeReq = 1; // Forward WPS PBC probe request frame up
1782
1783 pConfig->RSNWPAReqIELength = 0;
1784 pConfig->pRSNWPAReqIE = NULL;
1785 pIe = wlan_hdd_cfg80211_get_ie_ptr(pBeacon->tail, pBeacon->tail_len,
1786 WLAN_EID_RSN);
1787 if(pIe && pIe[1])
1788 {
1789 pConfig->RSNWPAReqIELength = pIe[1] + 2;
1790 memcpy(&wpaRsnIEdata[0], pIe, pConfig->RSNWPAReqIELength);
1791 pConfig->pRSNWPAReqIE = &wpaRsnIEdata[0];
1792 /* The actual processing may eventually be more extensive than
1793 * this. Right now, just consume any PMKIDs that are sent in
1794 * by the app.
1795 * */
1796 status = hdd_softap_unpackIE(
1797 vos_get_context( VOS_MODULE_ID_SME, pVosContext),
1798 &RSNEncryptType,
1799 &mcRSNEncryptType,
1800 &RSNAuthType,
1801 pConfig->pRSNWPAReqIE[1]+2,
1802 pConfig->pRSNWPAReqIE );
1803
1804 if( VOS_STATUS_SUCCESS == status )
1805 {
1806 /* Now copy over all the security attributes you have
1807 * parsed out
1808 * */
1809 pConfig->RSNEncryptType = RSNEncryptType; // Use the cipher type in the RSN IE
1810 pConfig->mcRSNEncryptType = mcRSNEncryptType;
1811 (WLAN_HDD_GET_AP_CTX_PTR(pHostapdAdapter))->ucEncryptType
1812 = RSNEncryptType;
1813 hddLog( LOG1, FL("%s: CSR AuthType = %d, "
1814 "EncryptionType = %d mcEncryptionType = %d\n"),
1815 RSNAuthType, RSNEncryptType, mcRSNEncryptType);
1816 }
1817 }
1818
1819 pIe = wlan_hdd_get_vendor_oui_ie_ptr(WPA_OUI_TYPE, WPA_OUI_TYPE_SIZE,
1820 pBeacon->tail, pBeacon->tail_len);
1821
1822 if(pIe && pIe[1] && (pIe[0] == DOT11F_EID_WPA))
1823 {
1824 if (pConfig->pRSNWPAReqIE)
1825 {
1826 /*Mixed mode WPA/WPA2*/
1827 memcpy((&wpaRsnIEdata[0] + pConfig->RSNWPAReqIELength), pIe, pIe[1] + 2);
1828 pConfig->RSNWPAReqIELength += pIe[1] + 2;
1829 }
1830 else
1831 {
1832 pConfig->RSNWPAReqIELength = pIe[1] + 2;
1833 memcpy(&wpaRsnIEdata[0], pIe, pConfig->RSNWPAReqIELength);
1834 pConfig->pRSNWPAReqIE = &wpaRsnIEdata[0];
1835 status = hdd_softap_unpackIE(
1836 vos_get_context( VOS_MODULE_ID_SME, pVosContext),
1837 &RSNEncryptType,
1838 &mcRSNEncryptType,
1839 &RSNAuthType,
1840 pConfig->pRSNWPAReqIE[1]+2,
1841 pConfig->pRSNWPAReqIE );
1842
1843 if( VOS_STATUS_SUCCESS == status )
1844 {
1845 /* Now copy over all the security attributes you have
1846 * parsed out
1847 * */
1848 pConfig->RSNEncryptType = RSNEncryptType; // Use the cipher type in the RSN IE
1849 pConfig->mcRSNEncryptType = mcRSNEncryptType;
1850 (WLAN_HDD_GET_AP_CTX_PTR(pHostapdAdapter))->ucEncryptType
1851 = RSNEncryptType;
1852 hddLog( LOG1, FL("%s: CSR AuthType = %d, "
1853 "EncryptionType = %d mcEncryptionType = %d\n"),
1854 RSNAuthType, RSNEncryptType, mcRSNEncryptType);
1855 }
1856 }
1857 }
1858
Jeff Johnson4416a782013-03-25 14:17:50 -07001859 if (pConfig->RSNWPAReqIELength > sizeof wpaRsnIEdata) {
1860 hddLog( VOS_TRACE_LEVEL_ERROR, "**RSNWPAReqIELength is too large***");
1861 return -EINVAL;
1862 }
1863
Jeff Johnson295189b2012-06-20 16:38:30 -07001864 pConfig->SSIDinfo.ssidHidden = VOS_FALSE;
1865
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001866#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07001867 if (params->ssid != NULL)
1868 {
1869 memcpy(pConfig->SSIDinfo.ssid.ssId, params->ssid, params->ssid_len);
1870 pConfig->SSIDinfo.ssid.length = params->ssid_len;
1871 if (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE)
1872 pConfig->SSIDinfo.ssidHidden = VOS_TRUE;
1873 }
Jeff Johnson04dd8a82012-06-29 20:41:40 -07001874#else
1875 if (ssid != NULL)
1876 {
1877 memcpy(pConfig->SSIDinfo.ssid.ssId, ssid, ssid_len);
1878 pConfig->SSIDinfo.ssid.length = ssid_len;
1879 if (hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE)
1880 pConfig->SSIDinfo.ssidHidden = VOS_TRUE;
1881 }
1882#endif
1883
Jeff Johnson295189b2012-06-20 16:38:30 -07001884 vos_mem_copy(pConfig->self_macaddr.bytes,
1885 pHostapdAdapter->macAddressCurrent.bytes, sizeof(v_MACADDR_t));
1886
1887 /* default value */
1888 pConfig->SapMacaddr_acl = eSAP_ACCEPT_UNLESS_DENIED;
1889 pConfig->num_accept_mac = 0;
1890 pConfig->num_deny_mac = 0;
1891
1892 pIe = wlan_hdd_get_vendor_oui_ie_ptr(BLACKLIST_OUI_TYPE, WPA_OUI_TYPE_SIZE,
1893 pBeacon->tail, pBeacon->tail_len);
1894
1895 /* pIe for black list is following form:
1896 type : 1 byte
1897 length : 1 byte
1898 OUI : 4 bytes
1899 acl type : 1 byte
1900 no of mac addr in black list: 1 byte
1901 list of mac_acl_entries: variable, 6 bytes per mac address + sizeof(int) for vlan id
1902 */
1903 if ((pIe != NULL) && (pIe[1] != 0))
1904 {
1905 pConfig->SapMacaddr_acl = pIe[6];
1906 pConfig->num_deny_mac = pIe[7];
1907 hddLog(VOS_TRACE_LEVEL_INFO,"acl type = %d no deny mac = %d\n",
1908 pIe[6], pIe[7]);
1909 if (pConfig->num_deny_mac > MAX_MAC_ADDRESS_DENIED)
1910 pConfig->num_deny_mac = MAX_MAC_ADDRESS_DENIED;
1911 acl_entry = (struct qc_mac_acl_entry *)(pIe + 8);
1912 for (i = 0; i < pConfig->num_deny_mac; i++)
1913 {
1914 vos_mem_copy(&pConfig->deny_mac[i], acl_entry->addr, sizeof(qcmacaddr));
1915 acl_entry++;
1916 }
1917 }
1918 pIe = wlan_hdd_get_vendor_oui_ie_ptr(WHITELIST_OUI_TYPE, WPA_OUI_TYPE_SIZE,
1919 pBeacon->tail, pBeacon->tail_len);
1920
1921 /* pIe for white list is following form:
1922 type : 1 byte
1923 length : 1 byte
1924 OUI : 4 bytes
1925 acl type : 1 byte
1926 no of mac addr in white list: 1 byte
1927 list of mac_acl_entries: variable, 6 bytes per mac address + sizeof(int) for vlan id
1928 */
1929 if ((pIe != NULL) && (pIe[1] != 0))
1930 {
1931 pConfig->SapMacaddr_acl = pIe[6];
1932 pConfig->num_accept_mac = pIe[7];
1933 hddLog(VOS_TRACE_LEVEL_INFO,"acl type = %d no accept mac = %d\n",
1934 pIe[6], pIe[7]);
1935 if (pConfig->num_accept_mac > MAX_MAC_ADDRESS_ACCEPTED)
1936 pConfig->num_accept_mac = MAX_MAC_ADDRESS_ACCEPTED;
1937 acl_entry = (struct qc_mac_acl_entry *)(pIe + 8);
1938 for (i = 0; i < pConfig->num_accept_mac; i++)
1939 {
1940 vos_mem_copy(&pConfig->accept_mac[i], acl_entry->addr, sizeof(qcmacaddr));
1941 acl_entry++;
1942 }
1943 }
1944 wlan_hdd_set_sapHwmode(pHostapdAdapter);
1945
Jeff Johnsone7245742012-09-05 17:12:55 -07001946#ifdef WLAN_FEATURE_11AC
Ravi Kumar Vaishnavbbaebbe2013-01-15 17:09:48 -08001947 /* Overwrite the hostapd setting for HW mode only for 11ac.
1948 * This is valid only if mode is set to 11n in hostapd and either AUTO or 11ac in .ini .
1949 * Otherwise, leave whatever is set in hostapd (a OR b OR g OR n mode) */
1950 if( ((pConfig->SapHw_mode == eSAP_DOT11_MODE_11n) ||
1951 (pConfig->SapHw_mode == eSAP_DOT11_MODE_11n_ONLY)) &&
1952 (((WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->dot11Mode == eHDD_DOT11_MODE_AUTO) ||
1953 ((WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->dot11Mode == eHDD_DOT11_MODE_11ac) ||
1954 ((WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY)) )
Jeff Johnsone7245742012-09-05 17:12:55 -07001955 {
1956 pConfig->SapHw_mode = eSAP_DOT11_MODE_11ac;
1957 }
1958#endif
Madan Mohan Koyyalamudi59381622012-11-28 01:56:47 +05301959
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001960 if( AUTO_CHANNEL_SELECT != pConfig->channel)
1961 wlan_sap_select_cbmode((WLAN_HDD_GET_CTX(pHostapdAdapter)),pConfig->SapHw_mode,pConfig->channel);
Jeff Johnson295189b2012-06-20 16:38:30 -07001962 // ht_capab is not what the name conveys,this is used for protection bitmap
1963 pConfig->ht_capab =
1964 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apProtection;
1965
1966 if ( 0 != wlan_hdd_cfg80211_update_apies(pHostapdAdapter, params) )
1967 {
1968 hddLog(LOGE, FL("SAP Not able to set AP IEs"));
1969 return -EINVAL;
1970 }
1971
1972 //Uapsd Enabled Bit
1973 pConfig->UapsdEnable =
1974 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apUapsdEnabled;
1975 //Enable OBSS protection
1976 pConfig->obssProtEnabled =
1977 (WLAN_HDD_GET_CTX(pHostapdAdapter))->cfg_ini->apOBSSProtEnabled;
1978
1979 hddLog(LOGW, FL("SOftAP macaddress : "MAC_ADDRESS_STR"\n"),
1980 MAC_ADDR_ARRAY(pHostapdAdapter->macAddressCurrent.bytes));
1981 hddLog(LOGW,FL("ssid =%s\n"), pConfig->SSIDinfo.ssid.ssId);
1982 hddLog(LOGW,FL("beaconint=%d, channel=%d\n"), (int)pConfig->beacon_int,
1983 (int)pConfig->channel);
1984 hddLog(LOGW,FL("hw_mode=%x\n"), pConfig->SapHw_mode);
1985 hddLog(LOGW,FL("privacy=%d, authType=%d\n"), pConfig->privacy,
1986 pConfig->authType);
1987 hddLog(LOGW,FL("RSN/WPALen=%d, \n"),(int)pConfig->RSNWPAReqIELength);
1988 hddLog(LOGW,FL("Uapsd = %d\n"),pConfig->UapsdEnable);
1989 hddLog(LOGW,FL("ProtEnabled = %d, OBSSProtEnabled = %d\n"),
1990 pConfig->protEnabled, pConfig->obssProtEnabled);
1991
1992 if(test_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags))
1993 {
1994 //Bss already started. just return.
1995 //TODO Probably it should update some beacon params.
1996 hddLog( LOGE, "Bss Already started...Ignore the request");
1997 EXIT();
1998 return 0;
1999 }
2000
2001 pConfig->persona = pHostapdAdapter->device_mode;
2002
2003 pSapEventCallback = hdd_hostapd_SAPEventCB;
2004 if(WLANSAP_StartBss(pVosContext, pSapEventCallback, pConfig,
2005 (v_PVOID_t)pHostapdAdapter->dev) != VOS_STATUS_SUCCESS)
2006 {
2007 hddLog(LOGE,FL("SAP Start Bss fail\n"));
2008 return -EINVAL;
2009 }
2010
Madan Mohan Koyyalamudi8bdd3112012-09-24 13:55:14 -07002011 hddLog(LOG1,
Jeff Johnson295189b2012-06-20 16:38:30 -07002012 FL("Waiting for Scan to complete(auto mode) and BSS to start"));
2013
2014 status = vos_wait_single_event(&pHostapdState->vosEvent, 10000);
2015
2016 if (!VOS_IS_STATUS_SUCCESS(status))
2017 {
2018 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2019 ("ERROR: HDD vos wait for single_event failed!!\n"));
2020 VOS_ASSERT(0);
2021 }
2022
2023 //Succesfully started Bss update the state bit.
2024 set_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags);
2025
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07002026#ifdef WLAN_FEATURE_P2P_DEBUG
2027 if (pHostapdAdapter->device_mode == WLAN_HDD_P2P_GO)
2028 {
2029 if(globalP2PConnectionStatus == P2P_GO_NEG_COMPLETED)
2030 {
2031 globalP2PConnectionStatus = P2P_GO_COMPLETED_STATE;
2032 hddLog(LOGE,"[P2P State] From Go nego completed to "
Jeff Johnson1250df42012-12-10 14:31:52 -08002033 "Non-autonomous Group started");
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07002034 }
2035 else if(globalP2PConnectionStatus == P2P_NOT_ACTIVE)
2036 {
2037 globalP2PConnectionStatus = P2P_GO_COMPLETED_STATE;
2038 hddLog(LOGE,"[P2P State] From Inactive to "
Jeff Johnson1250df42012-12-10 14:31:52 -08002039 "Autonomous Group started");
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07002040 }
2041 }
2042#endif
2043
Jeff Johnson295189b2012-06-20 16:38:30 -07002044 pHostapdState->bCommit = TRUE;
2045 EXIT();
2046
2047 return 0;
2048}
2049
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002050#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07002051static int wlan_hdd_cfg80211_add_beacon(struct wiphy *wiphy,
2052 struct net_device *dev,
2053 struct beacon_parameters *params)
2054{
2055 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
2056 int status=VOS_STATUS_SUCCESS;
2057
2058 ENTER();
2059
2060 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "device mode=%d\n",pAdapter->device_mode);
2061
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002062 if ( (WLAN_HDD_GET_CTX(pAdapter))->isLogpInProgress )
2063 {
2064 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2065 "%s:LOGP in Progress. Ignore!!!", __func__);
2066 return -EAGAIN;
2067 }
2068
Jeff Johnson295189b2012-06-20 16:38:30 -07002069 if ( (pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002070 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -07002071 )
2072 {
2073 beacon_data_t *old,*new;
2074
2075 old = pAdapter->sessionCtx.ap.beacon;
2076
2077 if (old)
2078 return -EALREADY;
2079
2080 status = wlan_hdd_cfg80211_alloc_new_beacon(pAdapter,&new,params);
2081
2082 if(status != VOS_STATUS_SUCCESS)
2083 {
2084 hddLog(VOS_TRACE_LEVEL_FATAL,
2085 "%s:Error!!! Allocating the new beacon\n",__func__);
2086 return -EINVAL;
2087 }
2088
2089 pAdapter->sessionCtx.ap.beacon = new;
2090
2091 status = wlan_hdd_cfg80211_start_bss(pAdapter, params);
2092 }
2093
2094 EXIT();
2095 return status;
2096}
2097
2098static int wlan_hdd_cfg80211_set_beacon(struct wiphy *wiphy,
2099 struct net_device *dev,
2100 struct beacon_parameters *params)
2101{
2102 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
2103 int status=VOS_STATUS_SUCCESS;
2104
2105 ENTER();
2106
2107 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
2108 __func__,pAdapter->device_mode);
2109
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002110 if ( (WLAN_HDD_GET_CTX(pAdapter))->isLogpInProgress )
2111 {
2112 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2113 "%s:LOGP in Progress. Ignore!!!", __func__);
2114 return -EAGAIN;
2115 }
2116
Jeff Johnson295189b2012-06-20 16:38:30 -07002117 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002118 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -07002119 )
2120 {
2121 beacon_data_t *old,*new;
2122
2123 old = pAdapter->sessionCtx.ap.beacon;
2124
2125 if (!old)
2126 return -ENOENT;
2127
2128 status = wlan_hdd_cfg80211_alloc_new_beacon(pAdapter,&new,params);
2129
2130 if(status != VOS_STATUS_SUCCESS) {
2131 hddLog(VOS_TRACE_LEVEL_FATAL,
2132 "%s: Error!!! Allocating the new beacon\n",__func__);
2133 return -EINVAL;
2134 }
2135
2136 pAdapter->sessionCtx.ap.beacon = new;
2137
2138 status = wlan_hdd_cfg80211_start_bss(pAdapter, params);
2139 }
2140
2141 EXIT();
2142 return status;
2143}
2144
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002145#endif //(LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
2146
2147#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07002148static int wlan_hdd_cfg80211_del_beacon(struct wiphy *wiphy,
2149 struct net_device *dev)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002150#else
2151static int wlan_hdd_cfg80211_stop_ap (struct wiphy *wiphy,
2152 struct net_device *dev)
2153#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002154{
2155 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsone7245742012-09-05 17:12:55 -07002156 hdd_context_t *pHddCtx = NULL;
2157 hdd_scaninfo_t *pScanInfo = NULL;
2158 hdd_adapter_t *staAdapter = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07002159 VOS_STATUS status = 0;
2160
2161 ENTER();
2162
2163 if (NULL == pAdapter)
2164 {
2165 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002166 "%s: HDD adapter context is Null", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002167 return -ENODEV;
2168 }
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002169
Jeff Johnson4416a782013-03-25 14:17:50 -07002170 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002171 if (NULL == pHddCtx)
2172 {
2173 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002174 "%s: HDD context is Null", __func__);
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002175 return -ENODEV;
2176 }
Jeff Johnson4416a782013-03-25 14:17:50 -07002177 if (pHddCtx->isLogpInProgress)
2178 {
2179 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2180 "%s:LOGP in Progress. Ignore!!!", __func__);
2181 return -EAGAIN;
2182 }
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002183
2184 staAdapter = hdd_get_adapter(pAdapter->pHddCtx, WLAN_HDD_INFRA_STATION);
2185 if (NULL == staAdapter)
2186 {
2187 staAdapter = hdd_get_adapter(pAdapter->pHddCtx, WLAN_HDD_P2P_CLIENT);
2188 if (NULL == staAdapter)
2189 {
2190 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002191 "%s: HDD adapter context is Null", __func__);
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07002192 return -ENODEV;
2193 }
2194 }
2195
2196 pScanInfo = &pHddCtx->scan_info;
2197
Jeff Johnson4416a782013-03-25 14:17:50 -07002198 if (pHddCtx->isLogpInProgress)
Jeff Johnson295189b2012-06-20 16:38:30 -07002199 {
2200 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL, "%s:LOGP in Progress. Ignore!!!",__func__);
2201 return -EAGAIN;
2202 }
2203
2204 pHddCtx = (hdd_context_t*)pAdapter->pHddCtx;
2205
2206 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
2207 __func__,pAdapter->device_mode);
2208
Jeff Johnsone7245742012-09-05 17:12:55 -07002209 if ((pScanInfo != NULL) && pScanInfo->mScanPending)
2210 {
Madan Mohan Koyyalamudif4e81002012-11-13 10:46:38 -08002211 INIT_COMPLETION(pScanInfo->abortscan_event_var);
Jeff Johnsone7245742012-09-05 17:12:55 -07002212 hdd_abort_mac_scan(staAdapter->pHddCtx);
2213 status = wait_for_completion_interruptible_timeout(
Madan Mohan Koyyalamudif4e81002012-11-13 10:46:38 -08002214 &pScanInfo->abortscan_event_var,
Jeff Johnsone7245742012-09-05 17:12:55 -07002215 msecs_to_jiffies(WLAN_WAIT_TIME_ABORTSCAN));
2216 if (!status)
2217 {
2218 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
Jeff Johnson902c9832012-12-10 14:28:09 -08002219 "%s: Timeout occurred while waiting for abortscan" ,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002220 __func__);
Jeff Johnsone7245742012-09-05 17:12:55 -07002221 VOS_ASSERT(pScanInfo->mScanPending);
2222 return 0;
2223 }
2224 }
2225
Jeff Johnson295189b2012-06-20 16:38:30 -07002226 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002227 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -07002228 )
2229 {
2230 beacon_data_t *old;
2231
2232 old = pAdapter->sessionCtx.ap.beacon;
2233
2234 if (!old)
2235 return -ENOENT;
2236
Jeff Johnson295189b2012-06-20 16:38:30 -07002237 hdd_cleanup_actionframe(pHddCtx, pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07002238
2239 mutex_lock(&pHddCtx->sap_lock);
2240 if(test_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags))
2241 {
Jeff Johnson4416a782013-03-25 14:17:50 -07002242 if ( VOS_STATUS_SUCCESS == (status = WLANSAP_StopBss(pHddCtx->pvosContext) ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07002243 {
2244 hdd_hostapd_state_t *pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
2245
2246 status = vos_wait_single_event(&pHostapdState->vosEvent, 10000);
2247
2248 if (!VOS_IS_STATUS_SUCCESS(status))
2249 {
2250 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2251 ("ERROR: HDD vos wait for single_event failed!!\n"));
2252 VOS_ASSERT(0);
2253 }
2254 }
2255 clear_bit(SOFTAP_BSS_STARTED, &pAdapter->event_flags);
2256 }
2257 mutex_unlock(&pHddCtx->sap_lock);
2258
2259 if(status != VOS_STATUS_SUCCESS)
2260 {
2261 hddLog(VOS_TRACE_LEVEL_FATAL,
2262 "%s:Error!!! Stopping the BSS\n",__func__);
2263 return -EINVAL;
2264 }
2265
Jeff Johnson4416a782013-03-25 14:17:50 -07002266 if (ccmCfgSetInt(pHddCtx->hHal,
Jeff Johnson295189b2012-06-20 16:38:30 -07002267 WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG, 0,NULL, eANI_BOOLEAN_FALSE)
2268 ==eHAL_STATUS_FAILURE)
2269 {
2270 hddLog(LOGE,
2271 "Could not pass on WNI_CFG_PROBE_RSP_BCN_ADDNIE_FLAG to CCM\n");
2272 }
2273
Jeff Johnson4416a782013-03-25 14:17:50 -07002274 if ( eHAL_STATUS_FAILURE == ccmCfgSetInt(pHddCtx->hHal,
Jeff Johnson295189b2012-06-20 16:38:30 -07002275 WNI_CFG_ASSOC_RSP_ADDNIE_FLAG, 0, NULL,
2276 eANI_BOOLEAN_FALSE) )
2277 {
2278 hddLog(LOGE,
2279 "Could not pass on WNI_CFG_ASSOC_RSP_ADDNIE_FLAG to CCM\n");
2280 }
2281
2282 // Reset WNI_CFG_PROBE_RSP Flags
2283 wlan_hdd_reset_prob_rspies(pAdapter);
2284
2285 pAdapter->sessionCtx.ap.beacon = NULL;
2286 kfree(old);
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07002287#ifdef WLAN_FEATURE_P2P_DEBUG
2288 if((pAdapter->device_mode == WLAN_HDD_P2P_GO) &&
2289 (globalP2PConnectionStatus == P2P_GO_COMPLETED_STATE))
2290 {
2291 hddLog(LOGE,"[P2P State] From GO completed to Inactive state "
2292 "GO got removed");
2293 globalP2PConnectionStatus = P2P_NOT_ACTIVE;
2294 }
2295#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002296 }
2297 EXIT();
2298 return status;
2299}
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002300
2301#if (LINUX_VERSION_CODE > KERNEL_VERSION(3,3,0))
2302
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302303static int wlan_hdd_cfg80211_start_ap(struct wiphy *wiphy,
2304 struct net_device *dev,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002305 struct cfg80211_ap_settings *params)
2306{
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302307 hdd_adapter_t *pAdapter;
2308 hdd_context_t *pHddCtx;
2309 int status = 0;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002310
2311 ENTER();
2312
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302313 if (NULL == dev)
Madan Mohan Koyyalamudib2c36892012-10-18 20:52:38 -07002314 {
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302315 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
2316 "%s: Device is Null", __func__);
2317 return -ENODEV;
2318 }
2319
2320 pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
2321 if (NULL == pAdapter)
2322 {
2323 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
2324 "%s: HDD adapter is Null", __func__);
2325 return -ENODEV;
2326 }
2327
2328 if (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic)
2329 {
2330 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
2331 "%s: HDD adapter magic is invalid", __func__);
2332 return -ENODEV;
2333 }
2334
2335 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2336 if (NULL == pHddCtx)
2337 {
2338 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
2339 "%s: HDD context is Null", __func__);
2340 return -ENODEV;
2341 }
2342
2343 if (pHddCtx->isLogpInProgress)
2344 {
2345 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
2346 "%s: LOGP in Progress. Ignore!!!", __func__);
Madan Mohan Koyyalamudib2c36892012-10-18 20:52:38 -07002347 return -EAGAIN;
2348 }
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302349
2350 if (pHddCtx->isLoadUnloadInProgress)
2351 {
2352 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
2353 "%s: Unloading/Loading in Progress. Ignore!!!", __func__);
2354 return -EAGAIN;
2355 }
2356
2357 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: device mode = %d",
2358 __func__, pAdapter->device_mode);
2359
2360 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002361 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002362 )
2363 {
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302364 beacon_data_t *old, *new;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002365
2366 old = pAdapter->sessionCtx.ap.beacon;
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302367
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002368 if (old)
2369 return -EALREADY;
2370
2371 status = wlan_hdd_cfg80211_alloc_new_beacon(pAdapter, &new, &params->beacon, params->dtim_period);
2372
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302373 if (status != 0)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002374 {
2375 hddLog(VOS_TRACE_LEVEL_FATAL,
Pratik Bhalgata0c7f262012-11-22 17:40:24 +05302376 "%s:Error!!! Allocating the new beacon", __func__);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002377 return -EINVAL;
2378 }
2379 pAdapter->sessionCtx.ap.beacon = new;
Viral Modi3a32cc52013-02-08 11:14:52 -08002380#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
2381 wlan_hdd_cfg80211_set_channel(wiphy, dev, params->channel, params->channel_type);
2382#endif
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002383 status = wlan_hdd_cfg80211_start_bss(pAdapter, &params->beacon, params->ssid,
2384 params->ssid_len, params->hidden_ssid);
2385 }
2386
2387 EXIT();
2388 return status;
2389}
2390
2391
2392static int wlan_hdd_cfg80211_change_beacon(struct wiphy *wiphy,
2393 struct net_device *dev,
2394 struct cfg80211_beacon_data *params)
2395{
2396 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
2397 int status=VOS_STATUS_SUCCESS;
2398
2399 ENTER();
2400
2401 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
2402 __func__, pAdapter->device_mode);
Madan Mohan Koyyalamudib2c36892012-10-18 20:52:38 -07002403 if ((WLAN_HDD_GET_CTX(pAdapter))->isLogpInProgress)
2404 {
2405 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL, "%s:LOGP in Progress. Ignore!!!",__func__);
2406 return -EAGAIN;
2407 }
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002408
2409 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002410 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002411 )
2412 {
2413 beacon_data_t *old,*new;
2414
2415 old = pAdapter->sessionCtx.ap.beacon;
2416
2417 if (!old)
2418 return -ENOENT;
2419
2420 status = wlan_hdd_cfg80211_alloc_new_beacon(pAdapter, &new, params, 0);
2421
2422 if(status != VOS_STATUS_SUCCESS) {
2423 hddLog(VOS_TRACE_LEVEL_FATAL,
2424 "%s: Error!!! Allocating the new beacon\n",__func__);
2425 return -EINVAL;
2426 }
2427
2428 pAdapter->sessionCtx.ap.beacon = new;
2429
2430 status = wlan_hdd_cfg80211_start_bss(pAdapter, params, NULL, 0, 0);
2431 }
2432
2433 EXIT();
2434 return status;
2435}
2436
2437#endif //(LINUX_VERSION_CODE > KERNEL_VERSION(3,3,0))
2438
Jeff Johnson295189b2012-06-20 16:38:30 -07002439
2440static int wlan_hdd_cfg80211_change_bss (struct wiphy *wiphy,
2441 struct net_device *dev,
2442 struct bss_parameters *params)
2443{
2444 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
2445
2446 ENTER();
2447
2448 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
2449 __func__,pAdapter->device_mode);
2450
2451 if((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002452 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -07002453 )
2454 {
2455 /* ap_isolate == -1 means that in change bss, upper layer doesn't
2456 * want to update this parameter */
2457 if (-1 != params->ap_isolate)
2458 {
2459 pAdapter->sessionCtx.ap.apDisableIntraBssFwd = !!params->ap_isolate;
2460 }
2461 }
2462
2463 EXIT();
2464 return 0;
2465}
2466
2467/*
2468 * FUNCTION: wlan_hdd_cfg80211_change_iface
2469 * This function is used to set the interface type (INFRASTRUCTURE/ADHOC)
2470 */
2471int wlan_hdd_cfg80211_change_iface( struct wiphy *wiphy,
2472 struct net_device *ndev,
2473 enum nl80211_iftype type,
2474 u32 *flags,
2475 struct vif_params *params
2476 )
2477{
2478 struct wireless_dev *wdev;
2479 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
2480 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
Mohit Khanna0f232092012-09-11 14:46:08 -07002481 hdd_adapter_t *pP2pAdapter = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07002482 tCsrRoamProfile *pRoamProfile = NULL;
2483 eCsrRoamBssType LastBSSType;
2484 hdd_config_t *pConfig = pHddCtx->cfg_ini;
2485 eMib_dot11DesiredBssType connectedBssType;
2486 VOS_STATUS status;
2487
2488 ENTER();
2489
2490 if ((WLAN_HDD_GET_CTX(pAdapter))->isLogpInProgress)
2491 {
2492 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL, "%s:LOGP in Progress. Ignore!!!",__func__);
2493 return -EAGAIN;
2494 }
2495
2496 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
2497 __func__, pAdapter->device_mode);
2498
2499 wdev = ndev->ieee80211_ptr;
2500
2501#ifdef WLAN_BTAMP_FEATURE
2502 if((NL80211_IFTYPE_P2P_CLIENT == type)||
2503 (NL80211_IFTYPE_ADHOC == type)||
2504 (NL80211_IFTYPE_AP == type)||
2505 (NL80211_IFTYPE_P2P_GO == type))
2506 {
2507 pHddCtx->isAmpAllowed = VOS_FALSE;
2508 // stop AMP traffic
2509 status = WLANBAP_StopAmp();
2510 if(VOS_STATUS_SUCCESS != status )
2511 {
2512 pHddCtx->isAmpAllowed = VOS_TRUE;
2513 hddLog(VOS_TRACE_LEVEL_FATAL,
2514 "%s: Failed to stop AMP", __func__);
2515 return -EINVAL;
2516 }
2517 }
2518#endif //WLAN_BTAMP_FEATURE
2519 /* Reset the current device mode bit mask*/
2520 wlan_hdd_clear_concurrency_mode(pHddCtx, pAdapter->device_mode);
2521
2522 if( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Jeff Johnson295189b2012-06-20 16:38:30 -07002523 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Jeff Johnsone7245742012-09-05 17:12:55 -07002524 || (pAdapter->device_mode == WLAN_HDD_P2P_DEVICE)
Jeff Johnson295189b2012-06-20 16:38:30 -07002525 )
2526 {
2527 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
2528 pRoamProfile = &pWextState->roamProfile;
2529 LastBSSType = pRoamProfile->BSSType;
2530
2531 switch (type)
2532 {
2533 case NL80211_IFTYPE_STATION:
Jeff Johnson295189b2012-06-20 16:38:30 -07002534 case NL80211_IFTYPE_P2P_CLIENT:
Jeff Johnson295189b2012-06-20 16:38:30 -07002535 hddLog(VOS_TRACE_LEVEL_INFO,
2536 "%s: setting interface Type to INFRASTRUCTURE", __func__);
2537 pRoamProfile->BSSType = eCSR_BSS_TYPE_INFRASTRUCTURE;
Jeff Johnsone7245742012-09-05 17:12:55 -07002538#ifdef WLAN_FEATURE_11AC
2539 if(pConfig->dot11Mode == eHDD_DOT11_MODE_AUTO)
2540 {
2541 pConfig->dot11Mode = eHDD_DOT11_MODE_11ac;
2542 }
2543#endif
2544 pRoamProfile->phyMode =
2545 hdd_cfg_xlate_to_csr_phy_mode(pConfig->dot11Mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07002546 wdev->iftype = type;
Gopichand Nakkalaf527dc62012-12-31 16:35:10 -08002547 //Check for sub-string p2p to confirm its a p2p interface
2548 if (NULL != strstr(ndev->name,"p2p"))
Gopichand Nakkala864d3552012-12-31 16:08:51 -08002549 {
2550 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
2551 WLAN_HDD_P2P_DEVICE : WLAN_HDD_P2P_CLIENT;
2552 }
2553 else
2554 {
2555 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
Jeff Johnson295189b2012-06-20 16:38:30 -07002556 WLAN_HDD_INFRA_STATION: WLAN_HDD_P2P_CLIENT;
Gopichand Nakkala864d3552012-12-31 16:08:51 -08002557 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002558 break;
2559 case NL80211_IFTYPE_ADHOC:
2560 hddLog(VOS_TRACE_LEVEL_INFO,
2561 "%s: setting interface Type to ADHOC", __func__);
2562 pRoamProfile->BSSType = eCSR_BSS_TYPE_START_IBSS;
2563 pRoamProfile->phyMode =
2564 hdd_cfg_xlate_to_csr_phy_mode(pConfig->dot11Mode);
2565 wdev->iftype = type;
2566 break;
2567
2568 case NL80211_IFTYPE_AP:
Jeff Johnson295189b2012-06-20 16:38:30 -07002569 case NL80211_IFTYPE_P2P_GO:
Jeff Johnson295189b2012-06-20 16:38:30 -07002570 {
2571 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
2572 "%s: setting interface Type to %s", __func__,
2573 (type == NL80211_IFTYPE_AP) ? "SoftAP" : "P2pGo");
2574
Gopichand Nakkalaf527dc62012-12-31 16:35:10 -08002575 //Cancel any remain on channel for GO mode
2576 if (NL80211_IFTYPE_P2P_GO == type)
2577 {
2578 wlan_hdd_cancel_existing_remain_on_channel(pAdapter);
2579 }
Mohit Khanna0f232092012-09-11 14:46:08 -07002580 if (NL80211_IFTYPE_AP == type)
2581 {
2582 /* As Loading WLAN Driver one interface being created for p2p device
2583 * address. This will take one HW STA and the max number of clients
2584 * that can connect to softAP will be reduced by one. so while changing
2585 * the interface type to NL80211_IFTYPE_AP (SoftAP) remove p2p0
2586 * interface as it is not required in SoftAP mode.
2587 */
2588
2589 // Get P2P Adapter
2590 pP2pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_P2P_DEVICE);
2591
2592 if (pP2pAdapter)
2593 {
2594 hdd_stop_adapter(pHddCtx, pP2pAdapter);
2595 hdd_deinit_adapter(pHddCtx, pP2pAdapter);
2596 hdd_close_adapter(pHddCtx, pP2pAdapter, VOS_TRUE);
2597 }
2598 }
2599
Jeff Johnson295189b2012-06-20 16:38:30 -07002600 //De-init the adapter.
2601 hdd_stop_adapter( pHddCtx, pAdapter );
2602 hdd_deinit_adapter( pHddCtx, pAdapter );
2603 memset(&pAdapter->sessionCtx, 0, sizeof(pAdapter->sessionCtx));
Jeff Johnson295189b2012-06-20 16:38:30 -07002604 pAdapter->device_mode = (type == NL80211_IFTYPE_AP) ?
2605 WLAN_HDD_SOFTAP : WLAN_HDD_P2P_GO;
Jeff Johnson32d95a32012-09-10 13:15:23 -07002606
2607 //Disable BMPS and IMPS if enabled
2608 //before starting Go
2609 if(WLAN_HDD_P2P_GO == pAdapter->device_mode)
2610 {
2611 if(VOS_STATUS_E_FAILURE ==
2612 hdd_disable_bmps_imps(pHddCtx, WLAN_HDD_P2P_GO))
2613 {
2614 //Fail to Exit BMPS
2615 VOS_ASSERT(0);
2616 }
2617 }
2618
Madan Mohan Koyyalamudi3ff2a0b2012-10-15 14:33:46 -07002619 if ((WLAN_HDD_SOFTAP == pAdapter->device_mode) &&
2620 (pConfig->apRandomBssidEnabled))
2621 {
2622 /* To meet Android requirements create a randomized
2623 MAC address of the form 02:1A:11:Fx:xx:xx */
2624 get_random_bytes(&ndev->dev_addr[3], 3);
2625 ndev->dev_addr[0] = 0x02;
2626 ndev->dev_addr[1] = 0x1A;
2627 ndev->dev_addr[2] = 0x11;
2628 ndev->dev_addr[3] |= 0xF0;
2629 memcpy(pAdapter->macAddressCurrent.bytes, ndev->dev_addr,
2630 VOS_MAC_ADDR_SIZE);
2631 pr_info("wlan: Generated HotSpot BSSID "
2632 "%02x:%02x:%02x:%02x:%02x:%02x\n",
2633 ndev->dev_addr[0],
2634 ndev->dev_addr[1],
2635 ndev->dev_addr[2],
2636 ndev->dev_addr[3],
2637 ndev->dev_addr[4],
2638 ndev->dev_addr[5]);
2639 }
2640
Jeff Johnson295189b2012-06-20 16:38:30 -07002641 hdd_set_ap_ops( pAdapter->dev );
2642
2643 status = hdd_init_ap_mode(pAdapter);
2644 if(status != VOS_STATUS_SUCCESS)
2645 {
2646 hddLog(VOS_TRACE_LEVEL_FATAL,
2647 "%s: Error initializing the ap mode", __func__);
2648 return -EINVAL;
2649 }
2650 hdd_set_conparam(1);
2651
Jeff Johnson295189b2012-06-20 16:38:30 -07002652 /*interface type changed update in wiphy structure*/
2653 if(wdev)
2654 {
2655 wdev->iftype = type;
2656 pHddCtx->change_iface = type;
2657 }
2658 else
2659 {
2660 hddLog(VOS_TRACE_LEVEL_ERROR,
2661 "%s: ERROR !!!! Wireless dev is NULL", __func__);
2662 return -EINVAL;
2663 }
2664 goto done;
2665 }
2666
2667 default:
2668 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported interface Type",
2669 __func__);
2670 return -EOPNOTSUPP;
2671 }
2672 }
2673 else if ( (pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07002674 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -07002675 )
2676 {
2677 switch(type)
2678 {
2679 case NL80211_IFTYPE_STATION:
Jeff Johnson295189b2012-06-20 16:38:30 -07002680 case NL80211_IFTYPE_P2P_CLIENT:
Jeff Johnson295189b2012-06-20 16:38:30 -07002681 case NL80211_IFTYPE_ADHOC:
Jeff Johnson32d95a32012-09-10 13:15:23 -07002682 hdd_stop_adapter( pHddCtx, pAdapter );
2683 hdd_deinit_adapter( pHddCtx, pAdapter );
Jeff Johnson295189b2012-06-20 16:38:30 -07002684 wdev->iftype = type;
Gopichand Nakkalaf527dc62012-12-31 16:35:10 -08002685 //Check for sub-string p2p to confirm its a p2p interface
2686 if (NULL != strstr(ndev->name,"p2p"))
Gopichand Nakkala864d3552012-12-31 16:08:51 -08002687 {
2688 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
2689 WLAN_HDD_P2P_DEVICE : WLAN_HDD_P2P_CLIENT;
2690 }
2691 else
2692 {
2693 pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
Jeff Johnson295189b2012-06-20 16:38:30 -07002694 WLAN_HDD_INFRA_STATION: WLAN_HDD_P2P_CLIENT;
Gopichand Nakkala864d3552012-12-31 16:08:51 -08002695 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002696 hdd_set_conparam(0);
2697 pHddCtx->change_iface = type;
Jeff Johnson295189b2012-06-20 16:38:30 -07002698 memset(&pAdapter->sessionCtx, 0, sizeof(pAdapter->sessionCtx));
2699 hdd_set_station_ops( pAdapter->dev );
2700 status = hdd_init_station_mode( pAdapter );
2701 if( VOS_STATUS_SUCCESS != status )
2702 return -EOPNOTSUPP;
Jeff Johnsone7245742012-09-05 17:12:55 -07002703 /* In case of JB, for P2P-GO, only change interface will be called,
2704 * This is the right place to enable back bmps_imps()
2705 */
2706 hdd_enable_bmps_imps(pHddCtx);
Jeff Johnson295189b2012-06-20 16:38:30 -07002707 goto done;
2708 case NL80211_IFTYPE_AP:
Jeff Johnson295189b2012-06-20 16:38:30 -07002709 case NL80211_IFTYPE_P2P_GO:
Jeff Johnson295189b2012-06-20 16:38:30 -07002710 wdev->iftype = type;
Jeff Johnson295189b2012-06-20 16:38:30 -07002711 pAdapter->device_mode = (type == NL80211_IFTYPE_AP) ?
2712 WLAN_HDD_SOFTAP : WLAN_HDD_P2P_GO;
Jeff Johnson295189b2012-06-20 16:38:30 -07002713 goto done;
2714 default:
2715 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported interface Type",
2716 __func__);
2717 return -EOPNOTSUPP;
2718
2719 }
2720
2721 }
2722 else
2723 {
2724 return -EOPNOTSUPP;
2725 }
2726
2727
2728 if(pRoamProfile)
2729 {
2730 if ( LastBSSType != pRoamProfile->BSSType )
2731 {
2732 /*interface type changed update in wiphy structure*/
2733 wdev->iftype = type;
2734
2735 /*the BSS mode changed, We need to issue disconnect
2736 if connected or in IBSS disconnect state*/
2737 if ( hdd_connGetConnectedBssType(
2738 WLAN_HDD_GET_STATION_CTX_PTR(pAdapter), &connectedBssType ) ||
2739 ( eCSR_BSS_TYPE_START_IBSS == LastBSSType ) )
2740 {
2741 /*need to issue a disconnect to CSR.*/
2742 INIT_COMPLETION(pAdapter->disconnect_comp_var);
2743 if( eHAL_STATUS_SUCCESS ==
2744 sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
2745 pAdapter->sessionId,
2746 eCSR_DISCONNECT_REASON_UNSPECIFIED ) )
2747 {
2748 wait_for_completion_interruptible_timeout(
2749 &pAdapter->disconnect_comp_var,
2750 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
2751 }
2752 }
2753 }
2754 }
2755
2756done:
2757 /*set bitmask based on updated value*/
2758 wlan_hdd_set_concurrency_mode(pHddCtx, pAdapter->device_mode);
2759#ifdef WLAN_BTAMP_FEATURE
2760 if((NL80211_IFTYPE_STATION == type) && (pHddCtx->concurrency_mode <= 1) &&
2761 (pHddCtx->no_of_sessions[WLAN_HDD_INFRA_STATION] <=1))
2762 {
2763 //we are ok to do AMP
2764 pHddCtx->isAmpAllowed = VOS_TRUE;
2765 }
2766#endif //WLAN_BTAMP_FEATURE
2767 EXIT();
2768 return 0;
2769}
2770
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002771#ifdef FEATURE_WLAN_TDLS
2772static int wlan_hdd_tdls_add_station(struct wiphy *wiphy,
2773 struct net_device *dev, u8 *mac, bool update, tCsrStaParams *StaParams)
2774{
2775 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
2776 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
2777 VOS_STATUS status;
2778
2779 ENTER();
2780
Gopichand Nakkala838be5d2013-04-10 22:41:51 +05302781 if (NULL == pHddCtx || NULL == pHddCtx->cfg_ini)
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002782 {
2783 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2784 "Invalid arguments");
2785 return -EINVAL;
2786 }
Hoonki Lee27511902013-03-14 18:19:06 -07002787
2788 if ((eTDLS_SUPPORT_NOT_ENABLED == pHddCtx->tdls_mode) ||
2789 (eTDLS_SUPPORT_DISABLED == pHddCtx->tdls_mode))
2790 {
2791 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
2792 "%s: TDLS mode is disabled OR not enabled in FW."
2793 MAC_ADDRESS_STR " Request declined.",
2794 __func__, MAC_ADDR_ARRAY(mac));
2795 return -ENOTSUPP;
2796 }
2797
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002798 if (pHddCtx->isLogpInProgress)
2799 {
2800 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2801 "%s:LOGP in Progress. Ignore!!!", __func__);
Gopichand Nakkala05922802013-03-14 12:23:19 -07002802 wlan_hdd_tdls_set_link_status(pAdapter, mac, eTDLS_LINK_IDLE);
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002803 return -EBUSY;
2804 }
2805
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002806 /* when self is on-going, we dont' want to change link_status */
2807 if ((0 == update) && wlan_hdd_tdls_is_peer_progress(pAdapter, mac))
2808 {
2809 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2810 "%s: " MAC_ADDRESS_STR
2811 " TDLS setup is ongoing. Request declined.",
2812 __func__, MAC_ADDR_ARRAY(mac));
2813 return -EPERM;
2814 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07002815 /* when self is not on-ongoing, we don't want to allow change_station */
2816 if ((1 == update) && !wlan_hdd_tdls_is_peer_progress(pAdapter, mac))
2817 {
2818 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2819 "%s: " MAC_ADDRESS_STR
2820 " TDLS is not connecting. change station declined.",
2821 __func__, MAC_ADDR_ARRAY(mac));
2822 return -EPERM;
2823 }
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002824
2825 /* when others are on-going, we want to change link_status to idle */
Hoonki Leefb8df672013-04-10 18:20:34 -07002826 if (NULL != wlan_hdd_tdls_is_progress(pHddCtx, mac, TRUE, TRUE))
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002827 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07002828 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2829 "%s: " MAC_ADDRESS_STR
2830 " TDLS setup is ongoing. Request declined.",
2831 __func__, MAC_ADDR_ARRAY(mac));
Gopichand Nakkala05922802013-03-14 12:23:19 -07002832 goto error;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002833 }
2834
2835 /* first to check if we reached to maximum supported TDLS peer.
2836 TODO: for now, return -EPERM looks working fine,
2837 but need to check if any other errno fit into this category.*/
2838 if (HDD_MAX_NUM_TDLS_STA <= wlan_hdd_tdlsConnectedPeers(pAdapter))
2839 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07002840 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2841 "%s: " MAC_ADDRESS_STR
2842 " TDLS Max peer already connected. Request declined.",
2843 __func__, MAC_ADDR_ARRAY(mac));
Gopichand Nakkala05922802013-03-14 12:23:19 -07002844 goto error;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002845 }
2846 else
2847 {
2848 hddTdlsPeer_t *pTdlsPeer;
2849 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, mac);
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07002850 if (pTdlsPeer && TDLS_IS_CONNECTED(pTdlsPeer))
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002851 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07002852 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2853 "%s: " MAC_ADDRESS_STR " already connected. Request declined.",
2854 __func__, MAC_ADDR_ARRAY(mac));
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002855 return -EPERM;
2856 }
2857 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07002858 if (0 == update)
2859 wlan_hdd_tdls_set_link_status(pAdapter, mac, eTDLS_LINK_CONNECTING);
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002860
Jeff Johnsond75fe012013-04-06 10:53:06 -07002861 /* debug code */
Gopichand Nakkala838be5d2013-04-10 22:41:51 +05302862 if (NULL != StaParams)
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07002863 {
2864 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
2865 "%s: TDLS Peer Parameters.", __func__);
2866 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
2867 "ht_capa->cap_info: %0x", StaParams->HTCap.capInfo);
2868 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
2869 "ht_capa->extended_capabilities: %0x",
2870 StaParams->HTCap.extendedHtCapInfo);
2871 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
2872 "params->capability: %0x",StaParams->capability);
2873 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
2874 "params->ext_capab_len: %0x",StaParams->extn_capability);
2875 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
2876 "rxMcsMap %x rxHighest %x txMcsMap %x txHighest %x",
2877 StaParams->VHTCap.suppMcs.rxMcsMap, StaParams->VHTCap.suppMcs.rxHighest,
2878 StaParams->VHTCap.suppMcs.txMcsMap, StaParams->VHTCap.suppMcs.txHighest);
2879 {
2880 int i = 0;
2881 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL, "Supported rates:");
2882 for (i = 0; i < sizeof(StaParams->supported_rates); i++)
2883 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
2884 "[%d]: %x ", i, StaParams->supported_rates[i]);
2885 }
Jeff Johnsond75fe012013-04-06 10:53:06 -07002886 } /* end debug code */
Gopichand Nakkala838be5d2013-04-10 22:41:51 +05302887 else if ((1 == update) && (NULL == StaParams))
2888 {
2889 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2890 "%s : update is true, but staParams is NULL. Error!", __func__);
2891 return -EPERM;
2892 }
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002893
2894 INIT_COMPLETION(pAdapter->tdls_add_station_comp);
2895
2896 if (!update)
2897 {
2898 status = sme_AddTdlsPeerSta(WLAN_HDD_GET_HAL_CTX(pAdapter),
2899 pAdapter->sessionId, mac);
2900 }
2901 else
2902 {
2903 status = sme_ChangeTdlsPeerSta(WLAN_HDD_GET_HAL_CTX(pAdapter),
2904 pAdapter->sessionId, mac, StaParams);
2905 }
2906
2907 status = wait_for_completion_interruptible_timeout(&pAdapter->tdls_add_station_comp,
2908 msecs_to_jiffies(WAIT_TIME_TDLS_ADD_STA));
2909
2910 if (!status)
2911 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07002912 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002913 "%s: timeout waiting for tdls add station indication",
2914 __func__);
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002915 return -EPERM;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002916 }
2917 if ( eHAL_STATUS_SUCCESS != pAdapter->tdlsAddStaStatus)
2918 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07002919 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002920 "%s: Add Station is unsucessful", __func__);
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002921 return -EPERM;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002922 }
2923
2924 return 0;
Gopichand Nakkala05922802013-03-14 12:23:19 -07002925
2926error:
2927 wlan_hdd_tdls_set_link_status(pAdapter, mac, eTDLS_LINK_IDLE);
2928 return -EPERM;
2929
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002930}
2931#endif
2932
Jeff Johnson295189b2012-06-20 16:38:30 -07002933static int wlan_hdd_change_station(struct wiphy *wiphy,
2934 struct net_device *dev,
2935 u8 *mac,
2936 struct station_parameters *params)
2937{
2938 VOS_STATUS status = VOS_STATUS_SUCCESS;
2939 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
2940 v_MACADDR_t STAMacAddress;
Gopichand Nakkalab0856222013-03-12 22:39:05 -07002941#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002942 tCsrStaParams StaParams = {0};
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002943 tANI_U8 isBufSta = 0;
Gopichand Nakkalab0856222013-03-12 22:39:05 -07002944#endif
Jeff Johnsone7245742012-09-05 17:12:55 -07002945 ENTER();
2946
Jeff Johnson04dd8a82012-06-29 20:41:40 -07002947 if ( (WLAN_HDD_GET_CTX(pAdapter))->isLogpInProgress )
2948 {
2949 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2950 "%s:LOGP in Progress. Ignore!!!", __func__);
2951 return -EAGAIN;
2952 }
2953
Jeff Johnson295189b2012-06-20 16:38:30 -07002954 vos_mem_copy(STAMacAddress.bytes, mac, sizeof(v_MACADDR_t));
2955
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002956 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
2957 || (pAdapter->device_mode == WLAN_HDD_P2P_GO))
Jeff Johnson295189b2012-06-20 16:38:30 -07002958 {
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002959 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED))
Jeff Johnson295189b2012-06-20 16:38:30 -07002960 {
2961 status = hdd_softap_change_STA_state( pAdapter, &STAMacAddress,
2962 WLANTL_STA_AUTHENTICATED);
2963
2964 VOS_TRACE( VOS_MODULE_ID_HDD_SOFTAP, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala681989c2013-03-06 22:27:48 -08002965 "%s: Station MAC address does not matching", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002966 return -EINVAL;
2967 }
2968 }
Gopichand Nakkalab0856222013-03-12 22:39:05 -07002969#ifdef FEATURE_WLAN_TDLS
Hoonki Leea6d49be2013-04-05 09:43:25 -07002970 else if ((pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
2971 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)) {
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07002972 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
2973 StaParams.capability = params->capability;
2974 StaParams.uapsd_queues = params->uapsd_queues;
2975 StaParams.max_sp = params->max_sp;
2976
2977 if (0 != params->ext_capab_len)
2978 vos_mem_copy(StaParams.extn_capability, params->ext_capab,
2979 sizeof(StaParams.extn_capability));
2980
2981 if (NULL != params->ht_capa)
2982 vos_mem_copy(&StaParams.HTCap, params->ht_capa, sizeof(tSirHTCap));
2983
2984 StaParams.supported_rates_len = params->supported_rates_len;
2985
2986 /* Note : The Maximum sizeof supported_rates sent by the Supplicant is 32.
2987 * The supported_rates array , for all the structures propogating till Add Sta
2988 * to the firmware has to be modified , if the supplicant (ieee80211) is
2989 * modified to send more rates.
2990 */
2991
2992 /* To avoid Data Currption , set to max length to SIR_MAC_MAX_SUPP_RATES
2993 */
2994 if (StaParams.supported_rates_len > SIR_MAC_MAX_SUPP_RATES)
2995 StaParams.supported_rates_len = SIR_MAC_MAX_SUPP_RATES;
2996
2997 if (0 != StaParams.supported_rates_len) {
2998 int i = 0;
2999 vos_mem_copy(StaParams.supported_rates, params->supported_rates,
3000 StaParams.supported_rates_len);
3001 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3002 "Supported Rates with Length %d", StaParams.supported_rates_len);
3003 for (i=0; i < StaParams.supported_rates_len; i++)
3004 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
3005 "[%d]: %0x", i, StaParams.supported_rates[i]);
3006 }
3007
3008 if (NULL != params->vht_capa)
3009 vos_mem_copy(&StaParams.VHTCap, params->vht_capa, sizeof(tSirVHTCap));
3010
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003011 if (0 != params->ext_capab_len ) {
3012 /*Define A Macro : TODO Sunil*/
3013 if ((1<<4) & StaParams.extn_capability[3]) {
3014 isBufSta = 1;
3015 }
3016 }
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003017 //status = wlan_hdd_tdls_set_peer_caps( mac, params->uapsd_queues,
3018 // params->max_sp, isBufSta);
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003019 //if (VOS_STATUS_SUCCESS != status) {
3020 // VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3021 // "%s: wlan_hdd_tdls_set_peer_caps failed!", __func__);
3022 // return -EINVAL;
3023 //}
Gopichand Nakkala681989c2013-03-06 22:27:48 -08003024 status = wlan_hdd_tdls_add_station(wiphy, dev, mac, 1, &StaParams);
3025
3026 if (VOS_STATUS_SUCCESS != status) {
3027 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3028 "%s: sme_ChangeTdlsPeerSta failed!", __func__);
3029 return -EINVAL;
3030 }
3031 }
3032 }
Gopichand Nakkalab0856222013-03-12 22:39:05 -07003033#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07003034
Jeff Johnsone7245742012-09-05 17:12:55 -07003035 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07003036 return status;
3037}
3038
3039/*
3040 * FUNCTION: wlan_hdd_cfg80211_get_ibss_peer_staidx
3041 * This function is used to get peer station index in IBSS mode
3042 */
3043static u8 wlan_hdd_cfg80211_get_ibss_peer_staidx(hdd_adapter_t* pAdapter)
3044{
3045 u8 idx = 0;
3046 u8 temp[VOS_MAC_ADDR_SIZE] = {0};
3047 ENTER();
3048 memset(temp, 0, VOS_MAC_ADDR_SIZE);
3049 for ( idx = 0; idx < HDD_MAX_NUM_IBSS_STA; idx++ )
3050 {
3051 if ( (0 !=
3052 (WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))->conn_info.staId[idx])
3053 && memcmp((u8*)&(WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))->conn_info.peerMacAddress[idx],
3054 temp, VOS_MAC_ADDR_SIZE)
3055 )
3056 {
3057 return idx;
3058 }
3059 }
3060 return idx;
3061}
3062
3063
3064/*
3065 * FUNCTION: wlan_hdd_cfg80211_add_key
3066 * This function is used to initialize the key information
3067 */
3068#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003069static int wlan_hdd_cfg80211_add_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003070 struct net_device *ndev,
3071 u8 key_index, bool pairwise,
3072 const u8 *mac_addr,
3073 struct key_params *params
3074 )
3075#else
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003076static int wlan_hdd_cfg80211_add_key( struct wiphy *wiphy,
Jeff Johnson295189b2012-06-20 16:38:30 -07003077 struct net_device *ndev,
3078 u8 key_index, const u8 *mac_addr,
3079 struct key_params *params
3080 )
3081#endif
3082{
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003083 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
Jeff Johnson295189b2012-06-20 16:38:30 -07003084 tCsrRoamSetKey setKey;
3085 u8 groupmacaddr[WNI_CFG_BSSID_LEN] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
3086 int status = 0;
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003087 v_U32_t roamId= 0xFF;
3088 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
Jeff Johnson295189b2012-06-20 16:38:30 -07003089 hdd_hostapd_state_t *pHostapdState;
3090 VOS_STATUS vos_status;
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003091 eHalStatus halStatus;
Jeff Johnson295189b2012-06-20 16:38:30 -07003092
3093 ENTER();
3094
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003095 if ( (WLAN_HDD_GET_CTX(pAdapter))->isLogpInProgress )
3096 {
3097 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3098 "%s:LOGP in Progress. Ignore!!!", __func__);
3099 return -EAGAIN;
3100 }
3101
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003102 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d",
3103 __func__, pAdapter->device_mode);
Jeff Johnson295189b2012-06-20 16:38:30 -07003104
3105 if (CSR_MAX_NUM_KEY <= key_index)
3106 {
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003107 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key index %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07003108 key_index);
3109
3110 return -EINVAL;
3111 }
3112
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003113 if (CSR_MAX_KEY_LEN < params->key_len)
3114 {
3115 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key length %d", __func__,
3116 params->key_len);
3117
3118 return -EINVAL;
3119 }
3120
3121 hddLog(VOS_TRACE_LEVEL_INFO,
3122 "%s: called with key index = %d & key length %d",
3123 __func__, key_index, params->key_len);
Jeff Johnson295189b2012-06-20 16:38:30 -07003124
3125 /*extract key idx, key len and key*/
3126 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
3127 setKey.keyId = key_index;
3128 setKey.keyLength = params->key_len;
3129 vos_mem_copy(&setKey.Key[0],params->key, params->key_len);
3130
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003131 switch (params->cipher)
Jeff Johnson295189b2012-06-20 16:38:30 -07003132 {
3133 case WLAN_CIPHER_SUITE_WEP40:
3134 setKey.encType = eCSR_ENCRYPT_TYPE_WEP40_STATICKEY;
3135 break;
3136
3137 case WLAN_CIPHER_SUITE_WEP104:
3138 setKey.encType = eCSR_ENCRYPT_TYPE_WEP104_STATICKEY;
3139 break;
3140
3141 case WLAN_CIPHER_SUITE_TKIP:
3142 {
3143 u8 *pKey = &setKey.Key[0];
3144 setKey.encType = eCSR_ENCRYPT_TYPE_TKIP;
3145
3146 vos_mem_zero(pKey, CSR_MAX_KEY_LEN);
3147
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003148 /*Supplicant sends the 32bytes key in this order
Jeff Johnson295189b2012-06-20 16:38:30 -07003149
3150 |--------------|----------|----------|
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003151 | Tk1 |TX-MIC | RX Mic |
Jeff Johnson295189b2012-06-20 16:38:30 -07003152 |--------------|----------|----------|
3153 <---16bytes---><--8bytes--><--8bytes-->
3154
3155 */
3156 /*Sme expects the 32 bytes key to be in the below order
3157
3158 |--------------|----------|----------|
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003159 | Tk1 |RX-MIC | TX Mic |
Jeff Johnson295189b2012-06-20 16:38:30 -07003160 |--------------|----------|----------|
3161 <---16bytes---><--8bytes--><--8bytes-->
3162 */
3163 /* Copy the Temporal Key 1 (TK1) */
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003164 vos_mem_copy(pKey, params->key, 16);
Jeff Johnson295189b2012-06-20 16:38:30 -07003165
3166 /*Copy the rx mic first*/
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003167 vos_mem_copy(&pKey[16], &params->key[24], 8);
Jeff Johnson295189b2012-06-20 16:38:30 -07003168
3169 /*Copy the tx mic */
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003170 vos_mem_copy(&pKey[24], &params->key[16], 8);
Jeff Johnson295189b2012-06-20 16:38:30 -07003171
3172
3173 break;
3174 }
3175
3176 case WLAN_CIPHER_SUITE_CCMP:
3177 setKey.encType = eCSR_ENCRYPT_TYPE_AES;
3178 break;
3179
3180#ifdef FEATURE_WLAN_WAPI
3181 case WLAN_CIPHER_SUITE_SMS4:
3182 {
3183 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
3184 wlan_hdd_cfg80211_set_key_wapi(pAdapter, key_index, mac_addr,
3185 params->key, params->key_len);
3186 return 0;
3187 }
3188#endif
Chet Lanctot186b5732013-03-18 10:26:30 -07003189
Jeff Johnson295189b2012-06-20 16:38:30 -07003190#ifdef FEATURE_WLAN_CCX
3191 case WLAN_CIPHER_SUITE_KRK:
3192 setKey.encType = eCSR_ENCRYPT_TYPE_KRK;
3193 break;
3194#endif
Chet Lanctot186b5732013-03-18 10:26:30 -07003195
3196#ifdef WLAN_FEATURE_11W
3197 case WLAN_CIPHER_SUITE_AES_CMAC:
3198 setKey.encType = eCSR_ENCRYPT_TYPE_AES_CMAC;
Chet Lanctot3b5158a2013-03-31 16:45:21 -07003199 break;
Chet Lanctot186b5732013-03-18 10:26:30 -07003200#endif
3201
Jeff Johnson295189b2012-06-20 16:38:30 -07003202 default:
3203 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: unsupported cipher type %lu",
3204 __func__, params->cipher);
3205 return -EOPNOTSUPP;
3206 }
3207
3208 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: encryption type %d",
3209 __func__, setKey.encType);
3210
3211
3212
3213 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07003214 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -07003215 )
3216 {
3217
3218
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003219 if (
Jeff Johnson295189b2012-06-20 16:38:30 -07003220#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
3221 (!pairwise)
3222#else
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003223 (!mac_addr || is_broadcast_ether_addr(mac_addr))
Jeff Johnson295189b2012-06-20 16:38:30 -07003224#endif
3225 )
3226 {
3227 /* set group key*/
3228 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Jeff Johnson1250df42012-12-10 14:31:52 -08003229 "%s- %d: setting Broadcast key",
Jeff Johnson295189b2012-06-20 16:38:30 -07003230 __func__, __LINE__);
3231 setKey.keyDirection = eSIR_RX_ONLY;
3232 vos_mem_copy(setKey.peerMac,groupmacaddr,WNI_CFG_BSSID_LEN);
3233 }
3234 else
3235 {
3236 /* set pairwise key*/
3237 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3238 "%s- %d: setting pairwise key",
3239 __func__, __LINE__);
3240 setKey.keyDirection = eSIR_TX_RX;
3241 vos_mem_copy(setKey.peerMac, mac_addr,WNI_CFG_BSSID_LEN);
3242 }
3243
3244 pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003245 if( pHostapdState->bssState == BSS_START )
3246 {
Jeff Johnson295189b2012-06-20 16:38:30 -07003247 status = WLANSAP_SetKeySta( pVosContext, &setKey);
3248
3249 if ( status != eHAL_STATUS_SUCCESS )
3250 {
3251 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3252 "[%4d] WLANSAP_SetKeySta returned ERROR status= %d",
3253 __LINE__, status );
3254 }
3255 }
3256
3257 /* Saving WEP keys */
3258 else if( eCSR_ENCRYPT_TYPE_WEP40_STATICKEY == setKey.encType ||
3259 eCSR_ENCRYPT_TYPE_WEP104_STATICKEY == setKey.encType )
3260 {
3261 //Save the wep key in ap context. Issue setkey after the BSS is started.
3262 hdd_ap_ctx_t *pAPCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
3263 vos_mem_copy(&pAPCtx->wepKey[key_index], &setKey, sizeof(tCsrRoamSetKey));
3264 }
3265 else
3266 {
3267 //Save the key in ap context. Issue setkey after the BSS is started.
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003268 hdd_ap_ctx_t *pAPCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07003269 vos_mem_copy(&pAPCtx->groupKey, &setKey, sizeof(tCsrRoamSetKey));
3270 }
3271 }
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003272 else if ( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION) ||
3273 (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003274 {
3275 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
3276 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3277
3278 pWextState->roamProfile.Keys.KeyLength[key_index] = (u8)params->key_len;
3279
Venkata Prathyusha Kuntupalliee2ce712013-01-17 14:09:24 -08003280 pWextState->roamProfile.Keys.defaultIndex = key_index;
3281
3282
Jeff Johnsonf77ef0a2013-03-27 09:29:14 -07003283 vos_mem_copy(&pWextState->roamProfile.Keys.KeyMaterial[key_index][0],
Jeff Johnson295189b2012-06-20 16:38:30 -07003284 params->key, params->key_len);
3285
3286 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_SETTING_KEY;
3287
3288 if (!( ( IW_AUTH_KEY_MGMT_802_1X
3289 == (pWextState->authKeyMgmt & IW_AUTH_KEY_MGMT_802_1X))
3290 && (eCSR_AUTH_TYPE_OPEN_SYSTEM == pHddStaCtx->conn_info.authType)
3291 )
3292 &&
3293 ( (WLAN_CIPHER_SUITE_WEP40 == params->cipher)
3294 || (WLAN_CIPHER_SUITE_WEP104 == params->cipher)
3295 )
3296 )
3297 {
3298 /* in case of static WEP, macaddr/bssid is not coming from nl80211
3299 * interface, copy bssid for pairwise key and group macaddr for
3300 * group key initialization*/
3301
3302 tCsrRoamProfile *pRoamProfile = &pWextState->roamProfile;
3303
3304 pWextState->roamProfile.negotiatedUCEncryptionType =
3305 pHddStaCtx->conn_info.ucEncryptionType =
3306 ((WLAN_CIPHER_SUITE_WEP40 == params->cipher) ?
3307 eCSR_ENCRYPT_TYPE_WEP40_STATICKEY :
3308 eCSR_ENCRYPT_TYPE_WEP104_STATICKEY);
3309
3310
3311 hddLog(VOS_TRACE_LEVEL_INFO_MED,
3312 "%s: Negotiated encryption type %d", __func__,
3313 pWextState->roamProfile.negotiatedUCEncryptionType);
3314
3315 sme_SetCfgPrivacy((tpAniSirGlobal)WLAN_HDD_GET_HAL_CTX(pAdapter),
3316 &pWextState->roamProfile, true);
3317 setKey.keyLength = 0;
3318 setKey.keyDirection = eSIR_TX_RX;
3319
3320#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
3321 if (pairwise)
3322 {
3323#endif
3324 if (mac_addr)
3325 {
3326 vos_mem_copy(setKey.peerMac, mac_addr,WNI_CFG_BSSID_LEN);
3327 }
3328 else
3329 {
3330 /* macaddr is NULL, set the peerMac to bssId in case of BSS,
3331 * and peerMacAddress in case of IBSS*/
3332 if (eCSR_BSS_TYPE_START_IBSS == pRoamProfile->BSSType)
3333 {
3334 u8 staidx = wlan_hdd_cfg80211_get_ibss_peer_staidx(pAdapter);
3335 if (HDD_MAX_NUM_IBSS_STA != staidx)
3336 {
3337 vos_mem_copy(setKey.peerMac,
3338 &pHddStaCtx->conn_info.peerMacAddress[staidx],
3339 WNI_CFG_BSSID_LEN);
3340
3341 }
3342 else
3343 {
3344 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: No peerMac found",
3345 __func__);
3346 return -EOPNOTSUPP;
3347 }
3348 }
3349 else
3350 {
3351 vos_mem_copy(setKey.peerMac,
3352 &pHddStaCtx->conn_info.bssId[0],
3353 WNI_CFG_BSSID_LEN);
3354 }
3355 }
3356#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
3357 }
3358 else
3359 {
3360 /* set group key*/
3361 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3362 "%s- %d: setting Group key",
3363 __func__, __LINE__);
3364 setKey.keyDirection = eSIR_RX_ONLY;
3365 vos_mem_copy(setKey.peerMac, groupmacaddr, WNI_CFG_BSSID_LEN);
3366 }
3367#endif
3368 }
3369 else if (
3370#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
3371 (!pairwise)
3372#else
3373 (!mac_addr || is_broadcast_ether_addr(mac_addr))
3374#endif
3375 )
3376 {
3377 /* set group key*/
3378 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3379 "%s- %d: setting Group key",
3380 __func__, __LINE__);
3381 setKey.keyDirection = eSIR_RX_ONLY;
3382 vos_mem_copy(setKey.peerMac,groupmacaddr,WNI_CFG_BSSID_LEN);
3383 }
3384 else
3385 {
3386 /* set pairwise key*/
3387 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
3388 "%s- %d: setting pairwise key",
3389 __func__, __LINE__);
3390 setKey.keyDirection = eSIR_TX_RX;
3391 vos_mem_copy(setKey.peerMac, mac_addr,WNI_CFG_BSSID_LEN);
3392 }
3393
3394 hddLog(VOS_TRACE_LEVEL_INFO_MED,
3395 "%s: set key for peerMac %2x:%2x:%2x:%2x:%2x:%2x, direction %d",
3396 __func__, setKey.peerMac[0], setKey.peerMac[1],
3397 setKey.peerMac[2], setKey.peerMac[3],
3398 setKey.peerMac[4], setKey.peerMac[5],
3399 setKey.keyDirection);
3400
3401 vos_status = wlan_hdd_check_ula_done(pAdapter);
3402
3403 if ( vos_status != VOS_STATUS_SUCCESS )
3404 {
3405 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3406 "[%4d] wlan_hdd_check_ula_done returned ERROR status= %d",
3407 __LINE__, vos_status );
3408
3409 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3410
3411 return -EINVAL;
3412
3413 }
3414
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003415#ifdef WLAN_FEATURE_VOWIFI_11R
3416 /* The supplicant may attempt to set the PTK once pre-authentication is done.
3417 Save the key in the UMAC and include it in the ADD BSS request */
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003418 halStatus = sme_FTUpdateKey( WLAN_HDD_GET_HAL_CTX(pAdapter), &setKey);
Gopichand Nakkalad7d13652013-02-15 01:48:00 +05303419 if( halStatus == eHAL_STATUS_FT_PREAUTH_KEY_WAIT )
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003420 {
Gopichand Nakkalad7d13652013-02-15 01:48:00 +05303421 return -EINVAL;
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07003422 }
3423#endif /* WLAN_FEATURE_VOWIFI_11R */
Jeff Johnson295189b2012-06-20 16:38:30 -07003424
3425 /* issue set key request to SME*/
3426 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
3427 pAdapter->sessionId, &setKey, &roamId );
3428
3429 if ( 0 != status )
3430 {
3431 hddLog(VOS_TRACE_LEVEL_ERROR,
3432 "%s: sme_RoamSetKey failed, returned %d", __func__, status);
3433 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3434 return -EINVAL;
3435 }
3436
3437
3438 /* in case of IBSS as there was no information available about WEP keys during
3439 * IBSS join, group key intialized with NULL key, so re-initialize group key
3440 * with correct value*/
3441 if ( (eCSR_BSS_TYPE_START_IBSS == pWextState->roamProfile.BSSType) &&
3442 !( ( IW_AUTH_KEY_MGMT_802_1X
3443 == (pWextState->authKeyMgmt & IW_AUTH_KEY_MGMT_802_1X))
3444 && (eCSR_AUTH_TYPE_OPEN_SYSTEM == pHddStaCtx->conn_info.authType)
3445 )
3446 &&
3447 ( (WLAN_CIPHER_SUITE_WEP40 == params->cipher)
3448 || (WLAN_CIPHER_SUITE_WEP104 == params->cipher)
3449 )
3450 )
3451 {
3452 setKey.keyDirection = eSIR_RX_ONLY;
3453 vos_mem_copy(setKey.peerMac,groupmacaddr,WNI_CFG_BSSID_LEN);
3454
3455 hddLog(VOS_TRACE_LEVEL_INFO_MED,
3456 "%s: set key peerMac %2x:%2x:%2x:%2x:%2x:%2x, direction %d",
3457 __func__, setKey.peerMac[0], setKey.peerMac[1],
3458 setKey.peerMac[2], setKey.peerMac[3],
3459 setKey.peerMac[4], setKey.peerMac[5],
3460 setKey.keyDirection);
3461
3462 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
3463 pAdapter->sessionId, &setKey, &roamId );
3464
3465 if ( 0 != status )
3466 {
3467 hddLog(VOS_TRACE_LEVEL_ERROR,
3468 "%s: sme_RoamSetKey failed for group key (IBSS), returned %d",
3469 __func__, status);
3470 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3471 return -EINVAL;
3472 }
3473 }
3474 }
3475
3476 return 0;
3477}
3478
3479/*
3480 * FUNCTION: wlan_hdd_cfg80211_get_key
3481 * This function is used to get the key information
3482 */
3483#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
3484static int wlan_hdd_cfg80211_get_key(
3485 struct wiphy *wiphy,
3486 struct net_device *ndev,
3487 u8 key_index, bool pairwise,
3488 const u8 *mac_addr, void *cookie,
3489 void (*callback)(void *cookie, struct key_params*)
3490 )
3491#else
3492static int wlan_hdd_cfg80211_get_key(
3493 struct wiphy *wiphy,
3494 struct net_device *ndev,
3495 u8 key_index, const u8 *mac_addr, void *cookie,
3496 void (*callback)(void *cookie, struct key_params*)
3497 )
3498#endif
3499{
3500 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
3501 hdd_wext_state_t *pWextState= WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
3502 tCsrRoamProfile *pRoamProfile = &(pWextState->roamProfile);
3503 struct key_params params;
3504
3505 ENTER();
3506
3507 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
3508 __func__,pAdapter->device_mode);
3509
3510 memset(&params, 0, sizeof(params));
3511
3512 if (CSR_MAX_NUM_KEY <= key_index)
3513 {
3514 return -EINVAL;
3515 }
3516
3517 switch(pRoamProfile->EncryptionType.encryptionType[0])
3518 {
3519 case eCSR_ENCRYPT_TYPE_NONE:
3520 params.cipher = IW_AUTH_CIPHER_NONE;
3521 break;
3522
3523 case eCSR_ENCRYPT_TYPE_WEP40_STATICKEY:
3524 case eCSR_ENCRYPT_TYPE_WEP40:
3525 params.cipher = WLAN_CIPHER_SUITE_WEP40;
3526 break;
3527
3528 case eCSR_ENCRYPT_TYPE_WEP104_STATICKEY:
3529 case eCSR_ENCRYPT_TYPE_WEP104:
3530 params.cipher = WLAN_CIPHER_SUITE_WEP104;
3531 break;
3532
3533 case eCSR_ENCRYPT_TYPE_TKIP:
3534 params.cipher = WLAN_CIPHER_SUITE_TKIP;
3535 break;
3536
3537 case eCSR_ENCRYPT_TYPE_AES:
3538 params.cipher = WLAN_CIPHER_SUITE_AES_CMAC;
3539 break;
3540
3541 default:
3542 params.cipher = IW_AUTH_CIPHER_NONE;
3543 break;
3544 }
3545
3546 params.key_len = pRoamProfile->Keys.KeyLength[key_index];
3547 params.seq_len = 0;
3548 params.seq = NULL;
3549 params.key = &pRoamProfile->Keys.KeyMaterial[key_index][0];
3550 callback(cookie, &params);
3551 return 0;
3552}
3553
3554/*
3555 * FUNCTION: wlan_hdd_cfg80211_del_key
3556 * This function is used to delete the key information
3557 */
3558#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
3559static int wlan_hdd_cfg80211_del_key( struct wiphy *wiphy,
3560 struct net_device *ndev,
3561 u8 key_index,
3562 bool pairwise,
3563 const u8 *mac_addr
3564 )
3565#else
3566static int wlan_hdd_cfg80211_del_key( struct wiphy *wiphy,
3567 struct net_device *ndev,
3568 u8 key_index,
3569 const u8 *mac_addr
3570 )
3571#endif
3572{
3573 int status = 0;
3574
3575 //This code needs to be revisited. There is sme_removeKey API, we should
3576 //plan to use that. After the change to use correct index in setkey,
3577 //it is observed that this is invalidating peer
3578 //key index whenever re-key is done. This is affecting data link.
3579 //It should be ok to ignore del_key.
3580#if 0
3581 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
3582 v_CONTEXT_t pVosContext = (WLAN_HDD_GET_CTX(pAdapter))->pvosContext;
3583 u8 groupmacaddr[WNI_CFG_BSSID_LEN] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
3584 tCsrRoamSetKey setKey;
3585 v_U32_t roamId= 0xFF;
3586
3587 ENTER();
3588
3589 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: device_mode = %d\n",
3590 __func__,pAdapter->device_mode);
3591
3592 if (CSR_MAX_NUM_KEY <= key_index)
3593 {
3594 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key index %d", __func__,
3595 key_index);
3596
3597 return -EINVAL;
3598 }
3599
3600 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
3601 setKey.keyId = key_index;
3602
3603 if (mac_addr)
3604 vos_mem_copy(setKey.peerMac, mac_addr,WNI_CFG_BSSID_LEN);
3605 else
3606 vos_mem_copy(setKey.peerMac, groupmacaddr, WNI_CFG_BSSID_LEN);
3607
3608 setKey.encType = eCSR_ENCRYPT_TYPE_NONE;
3609
3610 if ((pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07003611 || (pAdapter->device_mode == WLAN_HDD_P2P_GO)
Jeff Johnson295189b2012-06-20 16:38:30 -07003612 )
3613 {
3614
3615 hdd_hostapd_state_t *pHostapdState =
3616 WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter);
3617 if( pHostapdState->bssState == BSS_START)
3618 {
3619 status = WLANSAP_SetKeySta( pVosContext, &setKey);
3620
3621 if ( status != eHAL_STATUS_SUCCESS )
3622 {
3623 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3624 "[%4d] WLANSAP_SetKeySta returned ERROR status= %d",
3625 __LINE__, status );
3626 }
3627 }
3628 }
3629 else if ( (pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Jeff Johnson295189b2012-06-20 16:38:30 -07003630 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Jeff Johnson295189b2012-06-20 16:38:30 -07003631 )
3632 {
3633 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3634
3635 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_SETTING_KEY;
3636
3637 hddLog(VOS_TRACE_LEVEL_INFO_MED,
3638 "%s: delete key for peerMac %2x:%2x:%2x:%2x:%2x:%2x",
3639 __func__, setKey.peerMac[0], setKey.peerMac[1],
3640 setKey.peerMac[2], setKey.peerMac[3],
3641 setKey.peerMac[4], setKey.peerMac[5]);
3642 if(pAdapter->sessionCtx.station.conn_info.connState ==
3643 eConnectionState_Associated)
3644 {
3645 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
3646 pAdapter->sessionId, &setKey, &roamId );
3647
3648 if ( 0 != status )
3649 {
3650 hddLog(VOS_TRACE_LEVEL_ERROR,
3651 "%s: sme_RoamSetKey failure, returned %d",
3652 __func__, status);
3653 pHddStaCtx->roam_info.roamingState = HDD_ROAM_STATE_NONE;
3654 return -EINVAL;
3655 }
3656 }
3657 }
3658#endif
Jeff Johnsone7245742012-09-05 17:12:55 -07003659 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07003660 return status;
3661}
3662
3663/*
3664 * FUNCTION: wlan_hdd_cfg80211_set_default_key
3665 * This function is used to set the default tx key index
3666 */
3667#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
3668static int wlan_hdd_cfg80211_set_default_key( struct wiphy *wiphy,
3669 struct net_device *ndev,
3670 u8 key_index,
3671 bool unicast, bool multicast)
3672#else
3673static int wlan_hdd_cfg80211_set_default_key( struct wiphy *wiphy,
3674 struct net_device *ndev,
3675 u8 key_index)
3676#endif
3677{
3678 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
3679 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
3680 int status = 0;
3681 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
3682
3683 ENTER();
3684
3685 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d key_index = %d \n",
3686 __func__,pAdapter->device_mode, key_index);
3687
3688 if (CSR_MAX_NUM_KEY <= key_index)
3689 {
3690 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid key index %d", __func__,
3691 key_index);
3692
3693 return -EINVAL;
3694 }
3695
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003696 if ( (WLAN_HDD_GET_CTX(pAdapter))->isLogpInProgress )
3697 {
3698 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3699 "%s:LOGP in Progress. Ignore!!!", __func__);
3700 return -EAGAIN;
3701 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003702
3703 if ((pAdapter->device_mode == WLAN_HDD_INFRA_STATION)
Jeff Johnson295189b2012-06-20 16:38:30 -07003704 || (pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
Jeff Johnson295189b2012-06-20 16:38:30 -07003705 )
3706 {
3707 if ( (key_index != pWextState->roamProfile.Keys.defaultIndex) &&
3708 (eCSR_ENCRYPT_TYPE_TKIP !=
3709 pWextState->roamProfile.EncryptionType.encryptionType[0]) &&
3710 (eCSR_ENCRYPT_TYPE_AES !=
3711 pWextState->roamProfile.EncryptionType.encryptionType[0])
3712 )
3713 {
3714 /* if default key index is not same as previous one,
3715 * then update the default key index */
3716
3717 tCsrRoamSetKey setKey;
3718 v_U32_t roamId= 0xFF;
3719 tCsrKeys *Keys = &pWextState->roamProfile.Keys;
3720
3721 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: default tx key index %d",
3722 __func__, key_index);
3723
3724 Keys->defaultIndex = (u8)key_index;
3725 vos_mem_zero(&setKey,sizeof(tCsrRoamSetKey));
3726 setKey.keyId = key_index;
3727 setKey.keyLength = Keys->KeyLength[key_index];
3728
3729 vos_mem_copy(&setKey.Key[0],
3730 &Keys->KeyMaterial[key_index][0],
3731 Keys->KeyLength[key_index]);
3732
3733 setKey.keyDirection = eSIR_TX_ONLY;
3734
3735 vos_mem_copy(setKey.peerMac,
3736 &pHddStaCtx->conn_info.bssId[0],
3737 WNI_CFG_BSSID_LEN);
3738
3739 setKey.encType =
3740 pWextState->roamProfile.EncryptionType.encryptionType[0];
3741
3742 /* issue set key request */
3743 status = sme_RoamSetKey( WLAN_HDD_GET_HAL_CTX(pAdapter),
3744 pAdapter->sessionId, &setKey, &roamId );
3745
3746 if ( 0 != status )
3747 {
3748 hddLog(VOS_TRACE_LEVEL_ERROR,
3749 "%s: sme_RoamSetKey failed, returned %d", __func__,
3750 status);
3751 return -EINVAL;
3752 }
3753 }
3754 }
3755
3756 /* In SoftAp mode setting key direction for default mode */
3757 else if ( WLAN_HDD_SOFTAP == pAdapter->device_mode )
3758 {
3759 if ( (eCSR_ENCRYPT_TYPE_TKIP !=
3760 pWextState->roamProfile.EncryptionType.encryptionType[0]) &&
3761 (eCSR_ENCRYPT_TYPE_AES !=
3762 pWextState->roamProfile.EncryptionType.encryptionType[0])
3763 )
3764 {
3765 /* Saving key direction for default key index to TX default */
3766 hdd_ap_ctx_t *pAPCtx = WLAN_HDD_GET_AP_CTX_PTR(pAdapter);
3767 pAPCtx->wepKey[key_index].keyDirection = eSIR_TX_DEFAULT;
3768 }
3769 }
3770
3771 return status;
3772}
3773
Jeff Johnson295189b2012-06-20 16:38:30 -07003774/*
3775 * FUNCTION: wlan_hdd_cfg80211_inform_bss
3776 * This function is used to inform the BSS details to nl80211 interface.
3777 */
3778static struct cfg80211_bss* wlan_hdd_cfg80211_inform_bss(
3779 hdd_adapter_t *pAdapter, tCsrRoamConnectedProfile *roamProfile)
3780{
3781 struct net_device *dev = pAdapter->dev;
3782 struct wireless_dev *wdev = dev->ieee80211_ptr;
3783 struct wiphy *wiphy = wdev->wiphy;
3784 tSirBssDescription *pBssDesc = roamProfile->pBssDesc;
3785 int chan_no;
3786 int ie_length;
3787 const char *ie;
3788 unsigned int freq;
3789 struct ieee80211_channel *chan;
3790 int rssi = 0;
3791 struct cfg80211_bss *bss = NULL;
3792
3793 ENTER();
3794
3795 if( NULL == pBssDesc )
3796 {
3797 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: pBssDesc is NULL\n", __func__);
3798 return bss;
3799 }
3800
3801 chan_no = pBssDesc->channelId;
3802 ie_length = GET_IE_LEN_IN_BSS_DESC( pBssDesc->length );
3803 ie = ((ie_length != 0) ? (const char *)&pBssDesc->ieFields: NULL);
3804
3805 if( NULL == ie )
3806 {
3807 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: IE of BSS descriptor is NULL\n", __func__);
3808 return bss;
3809 }
3810
3811#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,38))
3812 if (chan_no <= ARRAY_SIZE(hdd_channels_2_4_GHZ))
3813 {
3814 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_2GHZ);
3815 }
3816 else
3817 {
3818 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_5GHZ);
3819 }
3820#else
3821 freq = ieee80211_channel_to_frequency(chan_no);
3822#endif
3823
3824 chan = __ieee80211_get_channel(wiphy, freq);
3825
3826 bss = cfg80211_get_bss(wiphy, chan, pBssDesc->bssId,
3827 &roamProfile->SSID.ssId[0], roamProfile->SSID.length,
3828 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
3829 if (bss == NULL)
3830 {
3831 rssi = (VOS_MIN ((pBssDesc->rssi + pBssDesc->sinr), 0))*100;
3832
3833 return (cfg80211_inform_bss(wiphy, chan, pBssDesc->bssId,
3834 le64_to_cpu(*(__le64 *)pBssDesc->timeStamp),
3835 pBssDesc->capabilityInfo,
3836 pBssDesc->beaconInterval, ie, ie_length,
3837 rssi, GFP_KERNEL ));
3838}
3839 else
3840 {
3841 return bss;
3842 }
3843}
3844
3845
3846
3847/*
3848 * FUNCTION: wlan_hdd_cfg80211_inform_bss_frame
3849 * This function is used to inform the BSS details to nl80211 interface.
3850 */
3851struct cfg80211_bss*
3852wlan_hdd_cfg80211_inform_bss_frame( hdd_adapter_t *pAdapter,
3853 tSirBssDescription *bss_desc
3854 )
3855{
3856 /*
3857 cfg80211_inform_bss() is not updating ie field of bss entry, if entry
3858 already exists in bss data base of cfg80211 for that particular BSS ID.
3859 Using cfg80211_inform_bss_frame to update the bss entry instead of
3860 cfg80211_inform_bss, But this call expects mgmt packet as input. As of
3861 now there is no possibility to get the mgmt(probe response) frame from PE,
3862 converting bss_desc to ieee80211_mgmt(probe response) and passing to
3863 cfg80211_inform_bss_frame.
3864 */
3865 struct net_device *dev = pAdapter->dev;
3866 struct wireless_dev *wdev = dev->ieee80211_ptr;
3867 struct wiphy *wiphy = wdev->wiphy;
3868 int chan_no = bss_desc->channelId;
Madan Mohan Koyyalamudi86f629e2012-11-09 16:27:29 -08003869#ifdef WLAN_ENABLE_AGEIE_ON_SCAN_RESULTS
3870 qcom_ie_age *qie_age = NULL;
3871 int ie_length = GET_IE_LEN_IN_BSS_DESC( bss_desc->length ) + sizeof(qcom_ie_age);
3872#else
Jeff Johnson295189b2012-06-20 16:38:30 -07003873 int ie_length = GET_IE_LEN_IN_BSS_DESC( bss_desc->length );
Madan Mohan Koyyalamudi86f629e2012-11-09 16:27:29 -08003874#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07003875 const char *ie =
3876 ((ie_length != 0) ? (const char *)&bss_desc->ieFields: NULL);
3877 unsigned int freq;
3878 struct ieee80211_channel *chan;
3879 struct ieee80211_mgmt *mgmt =
3880 kzalloc((sizeof (struct ieee80211_mgmt) + ie_length), GFP_KERNEL);
3881 struct cfg80211_bss *bss_status = NULL;
3882 size_t frame_len = sizeof (struct ieee80211_mgmt) + ie_length;
3883 int rssi = 0;
Jeff Johnsone7245742012-09-05 17:12:55 -07003884#ifdef WLAN_OPEN_SOURCE
3885 struct timespec ts;
3886#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07003887
3888 ENTER();
3889
Madan Mohan Koyyalamudi2e5c9142012-11-02 13:17:48 -07003890 if (!mgmt)
3891 return NULL;
3892
Jeff Johnson295189b2012-06-20 16:38:30 -07003893 memcpy(mgmt->bssid, bss_desc->bssId, ETH_ALEN);
Jeff Johnsone7245742012-09-05 17:12:55 -07003894
3895#ifdef WLAN_OPEN_SOURCE
3896 /* Android does not want the timestamp from the frame.
3897 Instead it wants a monotonic increasing value */
3898 get_monotonic_boottime(&ts);
3899 mgmt->u.probe_resp.timestamp =
3900 ((u64)ts.tv_sec * 1000000) + (ts.tv_nsec / 1000);
3901#else
3902 /* keep old behavior for non-open source (for now) */
Jeff Johnson295189b2012-06-20 16:38:30 -07003903 memcpy(&mgmt->u.probe_resp.timestamp, bss_desc->timeStamp,
3904 sizeof (bss_desc->timeStamp));
Jeff Johnsone7245742012-09-05 17:12:55 -07003905
3906#endif
3907
Jeff Johnson295189b2012-06-20 16:38:30 -07003908 mgmt->u.probe_resp.beacon_int = bss_desc->beaconInterval;
3909 mgmt->u.probe_resp.capab_info = bss_desc->capabilityInfo;
Madan Mohan Koyyalamudi86f629e2012-11-09 16:27:29 -08003910
3911#ifdef WLAN_ENABLE_AGEIE_ON_SCAN_RESULTS
3912 /* GPS Requirement: need age ie per entry. Using vendor specific. */
3913 /* Assuming this is the last IE, copy at the end */
3914 ie_length -=sizeof(qcom_ie_age);
3915 qie_age = (qcom_ie_age *)(mgmt->u.probe_resp.variable + ie_length);
3916 qie_age->element_id = QCOM_VENDOR_IE_ID;
3917 qie_age->len = QCOM_VENDOR_IE_AGE_LEN;
3918 qie_age->oui_1 = QCOM_OUI1;
3919 qie_age->oui_2 = QCOM_OUI2;
3920 qie_age->oui_3 = QCOM_OUI3;
3921 qie_age->type = QCOM_VENDOR_IE_AGE_TYPE;
3922 qie_age->age = vos_timer_get_system_ticks() - bss_desc->nReceivedTime;
3923#endif
3924
Jeff Johnson295189b2012-06-20 16:38:30 -07003925 memcpy(mgmt->u.probe_resp.variable, ie, ie_length);
3926
3927 mgmt->frame_control |=
3928 (u16)(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_RESP);
3929
3930#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,38))
3931 if (chan_no <= ARRAY_SIZE(hdd_channels_2_4_GHZ) &&
3932 (wiphy->bands[IEEE80211_BAND_2GHZ] != NULL))
3933 {
3934 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_2GHZ);
3935 }
3936 else if ((chan_no > ARRAY_SIZE(hdd_channels_2_4_GHZ)) &&
3937 (wiphy->bands[IEEE80211_BAND_5GHZ] != NULL))
3938
3939 {
3940 freq = ieee80211_channel_to_frequency(chan_no, IEEE80211_BAND_5GHZ);
3941 }
3942 else
3943 {
3944 kfree(mgmt);
3945 return NULL;
3946 }
3947#else
3948 freq = ieee80211_channel_to_frequency(chan_no);
3949#endif
3950 chan = __ieee80211_get_channel(wiphy, freq);
Leela V Kiran Kumar Reddy90032de2013-01-24 18:33:30 -08003951 /*when the band is changed on the fly using the GUI, three things are done
3952 * 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)
3953 * as part of the scan abort, message willbe queued to PE and we proceed with flushing and changinh the band.
3954 * pe will stop the scanning further and report back the results what ever it had till now by calling the call back function.
3955 * if the time between update band and scandone call back is sufficent enough the band change reflects in SME, SME validates the channels
3956 * and discards the channels correponding to previous band and calls back with zero bss results.
3957 * 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
3958 * all the channels correponding to previous band.this is due to race condition.but those channels are invalid to the new band and so
3959 * this function __ieee80211_get_channel will return NULL.Each time we report scan result with this pointer null warning kernel trace is printed.
3960 * if the scan results contain large number of APs continuosly kernel warning trace is printed and it will lead to apps watch dog bark.
3961 * So drop the bss and continue to next bss.
3962 */
3963 if(chan == NULL)
3964 {
3965 hddLog(VOS_TRACE_LEVEL_INFO, "%s chan pointer is NULL", __func__);
Chilam Ngc4244af2013-04-01 15:37:32 -07003966 kfree(mgmt);
Leela V Kiran Kumar Reddy90032de2013-01-24 18:33:30 -08003967 return NULL;
3968 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003969 /*To keep the rssi icon of the connected AP in the scan window
3970 *and the rssi icon of the wireless networks in sync
3971 * */
3972 if (( eConnectionState_Associated ==
3973 pAdapter->sessionCtx.station.conn_info.connState ) &&
3974 ( VOS_TRUE == vos_mem_compare(bss_desc->bssId,
3975 pAdapter->sessionCtx.station.conn_info.bssId,
3976 WNI_CFG_BSSID_LEN)))
3977 {
3978 /* supplicant takes the signal strength in terms of mBm(100*dBm) */
3979 rssi = (pAdapter->rssi * 100);
3980 }
3981 else
3982 {
3983 rssi = (VOS_MIN ((bss_desc->rssi + bss_desc->sinr), 0))*100;
3984 }
3985
3986 bss_status = cfg80211_inform_bss_frame(wiphy, chan, mgmt,
3987 frame_len, rssi, GFP_KERNEL);
3988 kfree(mgmt);
3989 return bss_status;
3990}
3991
3992/*
3993 * FUNCTION: wlan_hdd_cfg80211_update_bss_db
3994 * This function is used to update the BSS data base of CFG8011
3995 */
3996struct cfg80211_bss* wlan_hdd_cfg80211_update_bss_db( hdd_adapter_t *pAdapter,
3997 tCsrRoamInfo *pRoamInfo
3998 )
3999{
4000 tCsrRoamConnectedProfile roamProfile;
4001 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
4002 struct cfg80211_bss *bss = NULL;
4003
4004 ENTER();
4005
4006 memset(&roamProfile, 0, sizeof(tCsrRoamConnectedProfile));
4007 sme_RoamGetConnectProfile(hHal, pAdapter->sessionId, &roamProfile);
4008
4009 if (NULL != roamProfile.pBssDesc)
4010 {
4011 bss = wlan_hdd_cfg80211_inform_bss(pAdapter,
4012 &roamProfile);
4013
4014 if (NULL == bss)
4015 {
4016 hddLog(VOS_TRACE_LEVEL_INFO, "%s: cfg80211_inform_bss return NULL",
4017 __func__);
4018 }
4019
4020 sme_RoamFreeConnectProfile(hHal, &roamProfile);
4021 }
4022 else
4023 {
4024 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: roamProfile.pBssDesc is NULL",
4025 __func__);
4026 }
4027 return bss;
4028}
4029
4030/*
4031 * FUNCTION: wlan_hdd_cfg80211_update_bss
4032 */
4033static int wlan_hdd_cfg80211_update_bss( struct wiphy *wiphy,
4034 hdd_adapter_t *pAdapter
4035 )
4036{
4037 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
4038 tCsrScanResultInfo *pScanResult;
4039 eHalStatus status = 0;
4040 tScanResultHandle pResult;
4041 struct cfg80211_bss *bss_status = NULL;
4042
4043 ENTER();
4044
4045 if ((WLAN_HDD_GET_CTX(pAdapter))->isLogpInProgress)
4046 {
4047 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL, "%s:LOGP in Progress. Ignore!!!",__func__);
4048 return -EAGAIN;
4049 }
4050
4051 /*
4052 * start getting scan results and populate cgf80211 BSS database
4053 */
4054 status = sme_ScanGetResult(hHal, pAdapter->sessionId, NULL, &pResult);
4055
4056 /* no scan results */
4057 if (NULL == pResult)
4058 {
4059 hddLog(VOS_TRACE_LEVEL_INFO, "%s: No scan result\n", __func__);
4060 return status;
4061 }
4062
4063 pScanResult = sme_ScanResultGetFirst(hHal, pResult);
4064
4065 while (pScanResult)
4066 {
4067 /*
4068 * cfg80211_inform_bss() is not updating ie field of bss entry, if
4069 * entry already exists in bss data base of cfg80211 for that
4070 * particular BSS ID. Using cfg80211_inform_bss_frame to update the
4071 * bss entry instead of cfg80211_inform_bss, But this call expects
4072 * mgmt packet as input. As of now there is no possibility to get
4073 * the mgmt(probe response) frame from PE, converting bss_desc to
4074 * ieee80211_mgmt(probe response) and passing to c
4075 * fg80211_inform_bss_frame.
4076 * */
4077
4078 bss_status = wlan_hdd_cfg80211_inform_bss_frame(pAdapter,
4079 &pScanResult->BssDescriptor);
4080
4081
4082 if (NULL == bss_status)
4083 {
4084 hddLog(VOS_TRACE_LEVEL_INFO,
4085 "%s: NULL returned by cfg80211_inform_bss\n", __func__);
4086 }
4087 else
4088 {
4089 cfg80211_put_bss(bss_status);
4090 }
4091
4092 pScanResult = sme_ScanResultGetNext(hHal, pResult);
4093 }
4094
4095 sme_ScanResultPurge(hHal, pResult);
4096
4097 return 0;
4098}
4099
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004100void
4101hddPrintMacAddr(tCsrBssid macAddr, tANI_U8 logLevel)
4102{
4103 VOS_TRACE(VOS_MODULE_ID_HDD, logLevel,
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07004104 "%02X:%02X:%02X:%02X:%02X:%02X\n",
4105 macAddr[0], macAddr[1], macAddr[2], macAddr[3], macAddr[4],
4106 macAddr[5]);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004107} /****** end hddPrintMacAddr() ******/
4108
4109void
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07004110hddPrintPmkId(tANI_U8 *pmkId, tANI_U8 logLevel)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004111{
4112 VOS_TRACE(VOS_MODULE_ID_HDD, logLevel,
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07004113 "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
4114 pmkId[0], pmkId[1], pmkId[2], pmkId[3], pmkId[4],
4115 pmkId[5], pmkId[6], pmkId[7], pmkId[8], pmkId[9], pmkId[10],
4116 pmkId[11], pmkId[12], pmkId[13], pmkId[14], pmkId[15]);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004117} /****** end hddPrintPmkId() ******/
4118
4119//hddPrintMacAddr(tCsrBssid macAddr, tANI_U8 logLevel);
4120//hddPrintMacAddr(macAddr, VOS_TRACE_LEVEL_FATAL);
4121
4122//void sirDumpBuf(tpAniSirGlobal pMac, tANI_U8 modId, tANI_U32 level, tANI_U8 *buf, tANI_U32 size);
4123//sirDumpBuf(pMac, VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL, pmkid, 16);
4124
4125#define dump_bssid(bssid) \
4126 { \
Jeff Johnsone7245742012-09-05 17:12:55 -07004127 hddLog(VOS_TRACE_LEVEL_INFO, "BSSID (MAC) address:\t"); \
4128 hddPrintMacAddr(bssid, VOS_TRACE_LEVEL_INFO);\
4129 hddLog(VOS_TRACE_LEVEL_INFO, "\n"); \
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004130 }
4131
4132#define dump_pmkid(pMac, pmkid) \
4133 { \
Jeff Johnsone7245742012-09-05 17:12:55 -07004134 hddLog(VOS_TRACE_LEVEL_INFO, "PMKSA-ID:\t"); \
4135 hddPrintPmkId(pmkid, VOS_TRACE_LEVEL_INFO);\
4136 hddLog(VOS_TRACE_LEVEL_INFO, "\n"); \
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004137 }
4138
Madan Mohan Koyyalamudi1b4afb02012-10-22 15:25:16 -07004139#if defined(FEATURE_WLAN_LFR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004140/*
4141 * FUNCTION: wlan_hdd_cfg80211_pmksa_candidate_notify
4142 * This function is used to notify the supplicant of a new PMKSA candidate.
4143 */
4144int wlan_hdd_cfg80211_pmksa_candidate_notify(
4145 hdd_adapter_t *pAdapter, tCsrRoamInfo *pRoamInfo,
4146 int index, bool preauth )
4147{
Jeff Johnsone7245742012-09-05 17:12:55 -07004148#ifdef FEATURE_WLAN_OKC
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004149 struct net_device *dev = pAdapter->dev;
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004150 hdd_context_t *pHddCtx = (hdd_context_t*)pAdapter->pHddCtx;
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004151
4152 ENTER();
Jeff Johnsone7245742012-09-05 17:12:55 -07004153 hddLog(VOS_TRACE_LEVEL_INFO, "%s is going to notify supplicant of:", __func__);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004154
4155 if( NULL == pRoamInfo )
4156 {
4157 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: pRoamInfo is NULL\n", __func__);
4158 return -EINVAL;
4159 }
4160
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004161 if (eANI_BOOLEAN_TRUE == hdd_is_okc_mode_enabled(pHddCtx))
4162 {
4163 dump_bssid(pRoamInfo->bssid);
4164 cfg80211_pmksa_candidate_notify(dev, index,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004165 pRoamInfo->bssid, preauth, GFP_KERNEL);
Srinivas Girigowdabbd16eb2013-03-21 12:34:46 -07004166 }
Jeff Johnsone7245742012-09-05 17:12:55 -07004167#endif /* FEATURE_WLAN_OKC */
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004168 return 0;
4169}
4170#endif //FEATURE_WLAN_LFR
4171
Jeff Johnson295189b2012-06-20 16:38:30 -07004172/*
4173 * FUNCTION: hdd_cfg80211_scan_done_callback
4174 * scanning callback function, called after finishing scan
4175 *
4176 */
4177static eHalStatus hdd_cfg80211_scan_done_callback(tHalHandle halHandle,
4178 void *pContext, tANI_U32 scanId, eCsrScanStatus status)
4179{
4180 struct net_device *dev = (struct net_device *) pContext;
4181 //struct wireless_dev *wdev = dev->ieee80211_ptr;
4182 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004183 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
4184 hdd_scaninfo_t *pScanInfo = &pHddCtx->scan_info;
Jeff Johnson295189b2012-06-20 16:38:30 -07004185 struct cfg80211_scan_request *req = NULL;
4186 int ret = 0;
4187
4188 ENTER();
4189
4190 hddLog(VOS_TRACE_LEVEL_INFO,
4191 "%s called with halHandle = %p, pContext = %p,"
4192 "scanID = %d, returned status = %d\n",
4193 __func__, halHandle, pContext, (int) scanId, (int) status);
4194
4195 //Block on scan req completion variable. Can't wait forever though.
4196 ret = wait_for_completion_interruptible_timeout(
4197 &pScanInfo->scan_req_completion_event,
4198 msecs_to_jiffies(WLAN_WAIT_TIME_SCAN_REQ));
4199 if (!ret)
4200 {
4201 VOS_ASSERT(pScanInfo->mScanPending);
Jeff Johnsone7245742012-09-05 17:12:55 -07004202 goto allow_suspend;
Jeff Johnson295189b2012-06-20 16:38:30 -07004203 }
4204
4205 if(pScanInfo->mScanPending != VOS_TRUE)
4206 {
4207 VOS_ASSERT(pScanInfo->mScanPending);
Jeff Johnsone7245742012-09-05 17:12:55 -07004208 goto allow_suspend;
Jeff Johnson295189b2012-06-20 16:38:30 -07004209 }
4210
4211 /* Check the scanId */
4212 if (pScanInfo->scanId != scanId)
4213 {
4214 hddLog(VOS_TRACE_LEVEL_INFO,
4215 "%s called with mismatched scanId pScanInfo->scanId = %d "
4216 "scanId = %d \n", __func__, (int) pScanInfo->scanId,
4217 (int) scanId);
4218 }
4219
Jeff Johnson295189b2012-06-20 16:38:30 -07004220 ret = wlan_hdd_cfg80211_update_bss((WLAN_HDD_GET_CTX(pAdapter))->wiphy,
4221 pAdapter);
4222
4223 if (0 > ret)
4224 hddLog(VOS_TRACE_LEVEL_INFO, "%s: NO SCAN result", __func__);
4225
4226
4227 /* If any client wait scan result through WEXT
4228 * send scan done event to client */
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004229 if (pHddCtx->scan_info.waitScanResult)
Jeff Johnson295189b2012-06-20 16:38:30 -07004230 {
4231 /* The other scan request waiting for current scan finish
4232 * Send event to notify current scan finished */
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004233 if(WEXT_SCAN_PENDING_DELAY == pHddCtx->scan_info.scan_pending_option)
Jeff Johnson295189b2012-06-20 16:38:30 -07004234 {
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004235 vos_event_set(&pHddCtx->scan_info.scan_finished_event);
Jeff Johnson295189b2012-06-20 16:38:30 -07004236 }
4237 /* Send notify to WEXT client */
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004238 else if(WEXT_SCAN_PENDING_PIGGYBACK == pHddCtx->scan_info.scan_pending_option)
Jeff Johnson295189b2012-06-20 16:38:30 -07004239 {
4240 struct net_device *dev = pAdapter->dev;
4241 union iwreq_data wrqu;
4242 int we_event;
4243 char *msg;
4244
4245 memset(&wrqu, '\0', sizeof(wrqu));
4246 we_event = SIOCGIWSCAN;
4247 msg = NULL;
4248 wireless_send_event(dev, we_event, &wrqu, msg);
4249 }
4250 }
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004251 pHddCtx->scan_info.waitScanResult = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004252
4253 /* Get the Scan Req */
4254 req = pAdapter->request;
4255
4256 if (!req)
4257 {
4258 hddLog(VOS_TRACE_LEVEL_ERROR, "request is became NULL\n");
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07004259 pScanInfo->mScanPending = VOS_FALSE;
Jeff Johnsone7245742012-09-05 17:12:55 -07004260 goto allow_suspend;
Jeff Johnson295189b2012-06-20 16:38:30 -07004261 }
4262
4263 /*
4264 * setting up 0, just in case.
4265 */
4266 req->n_ssids = 0;
4267 req->n_channels = 0;
4268 req->ie = 0;
4269
Jeff Johnson295189b2012-06-20 16:38:30 -07004270 pAdapter->request = NULL;
Jeff Johnsone7245742012-09-05 17:12:55 -07004271 /* Scan is no longer pending */
4272 pScanInfo->mScanPending = VOS_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004273
Madan Mohan Koyyalamudib764bf82012-10-11 16:38:51 -07004274 /*
4275 * cfg80211_scan_done informing NL80211 about completion
4276 * of scanning
4277 */
4278 cfg80211_scan_done(req, false);
Madan Mohan Koyyalamudif4e81002012-11-13 10:46:38 -08004279 complete(&pScanInfo->abortscan_event_var);
Jeff Johnson295189b2012-06-20 16:38:30 -07004280
Jeff Johnsone7245742012-09-05 17:12:55 -07004281allow_suspend:
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07004282 /* release the wake lock at the end of the scan*/
4283 hdd_allow_suspend();
Jeff Johnsone7245742012-09-05 17:12:55 -07004284
Madan Mohan Koyyalamudi10d83a92012-09-28 15:47:05 -07004285 /* Acquire wakelock to handle the case where APP's tries to suspend
4286 * immediatly after the driver gets connect request(i.e after scan)
4287 * from supplicant, this result in app's is suspending and not able
4288 * to process the connect request to AP */
4289 hdd_allow_suspend_timeout(100);
4290
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07004291#ifdef FEATURE_WLAN_TDLS
4292 wlan_hdd_tdls_scan_done_callback(pAdapter);
4293#endif
4294
Jeff Johnson295189b2012-06-20 16:38:30 -07004295 EXIT();
4296 return 0;
4297}
4298
4299/*
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004300 * FUNCTION: hdd_isScanAllowed
4301 * Go through each adapter and check if scan allowed
4302 *
4303 */
4304v_BOOL_t hdd_isScanAllowed( hdd_context_t *pHddCtx )
4305{
4306 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
4307 hdd_station_ctx_t *pHddStaCtx = NULL;
4308 hdd_adapter_t *pAdapter = NULL;
4309 VOS_STATUS status = 0;
4310 v_U8_t staId = 0;
4311 v_U8_t *staMac = NULL;
4312
4313 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
4314
4315 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
4316 {
4317 pAdapter = pAdapterNode->pAdapter;
4318
4319 if( pAdapter )
4320 {
4321 hddLog(VOS_TRACE_LEVEL_INFO,
4322 "%s: Adapter with device mode %d exists",
4323 __func__, pAdapter->device_mode);
4324 if ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
4325 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) ||
4326 (WLAN_HDD_P2P_DEVICE == pAdapter->device_mode))
4327 {
4328 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
4329 if ((eConnectionState_Associated == pHddStaCtx->conn_info.connState) &&
4330 (VOS_FALSE == pHddStaCtx->conn_info.uIsAuthenticated))
4331 {
4332 staMac = (v_U8_t *) &(pAdapter->macAddressCurrent.bytes[0]);
4333 hddLog(VOS_TRACE_LEVEL_ERROR,
4334 "%s: client %02x:%02x:%02x:%02x:%02x:%02x is in the "
4335 "middle of WPS/EAPOL exchange.", __func__,
4336 staMac[0], staMac[1], staMac[2],
4337 staMac[3], staMac[4], staMac[5]);
4338 return VOS_FALSE;
4339 }
4340 }
4341 else if ((WLAN_HDD_SOFTAP == pAdapter->device_mode) ||
4342 (WLAN_HDD_P2P_GO == pAdapter->device_mode))
4343 {
4344 for (staId = 0; staId < WLAN_MAX_STA_COUNT; staId++)
4345 {
4346 if ((pAdapter->aStaInfo[staId].isUsed) &&
4347 (WLANTL_STA_CONNECTED == pAdapter->aStaInfo[staId].tlSTAState))
4348 {
4349 staMac = (v_U8_t *) &(pAdapter->aStaInfo[staId].macAddrSTA.bytes[0]);
4350
4351 hddLog(VOS_TRACE_LEVEL_ERROR,
4352 "%s: client %02x:%02x:%02x:%02x:%02x:%02x of SoftAP/P2P-GO is in the "
4353 "middle of WPS/EAPOL exchange.", __func__,
4354 staMac[0], staMac[1], staMac[2],
4355 staMac[3], staMac[4], staMac[5]);
4356 return VOS_FALSE;
4357 }
4358 }
4359 }
4360 }
4361 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
4362 pAdapterNode = pNext;
4363 }
4364 hddLog(VOS_TRACE_LEVEL_INFO,
4365 "%s: Scan allowed", __func__);
4366 return VOS_TRUE;
4367}
4368
4369/*
Jeff Johnson295189b2012-06-20 16:38:30 -07004370 * FUNCTION: wlan_hdd_cfg80211_scan
4371 * this scan respond to scan trigger and update cfg80211 scan database
4372 * later, scan dump command can be used to recieve scan results
4373 */
Jeff Johnson3bbe4bf2013-01-18 17:05:29 -08004374int wlan_hdd_cfg80211_scan( struct wiphy *wiphy,
4375#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
4376 struct net_device *dev,
4377#endif
4378 struct cfg80211_scan_request *request)
4379{
4380#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
4381 struct net_device *dev = request->wdev->netdev;
4382#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004383 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
4384 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
4385 hdd_wext_state_t *pwextBuf = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
4386 hdd_config_t *cfg_param = (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini;
4387 tCsrScanRequest scanRequest;
4388 tANI_U8 *channelList = NULL, i;
4389 v_U32_t scanId = 0;
4390 int status = 0;
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07004391 hdd_scaninfo_t *pScanInfo = &pHddCtx->scan_info;
Jeff Johnson295189b2012-06-20 16:38:30 -07004392 v_U8_t* pP2pIe = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004393
4394 ENTER();
4395
4396 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
4397 __func__,pAdapter->device_mode);
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004398
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004399 if ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) &&
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004400 (eConnectionState_Connecting ==
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004401 (WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))->conn_info.connState))
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004402 {
4403 hddLog(VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08004404 "%s: %p(%d) Connection in progress: Scan request denied (EBUSY)", __func__, \
4405 WLAN_HDD_GET_STATION_CTX_PTR(pAdapter), pAdapter->sessionId);
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004406 return -EBUSY;
4407 }
4408
Jeff Johnson295189b2012-06-20 16:38:30 -07004409#ifdef WLAN_BTAMP_FEATURE
4410 //Scan not supported when AMP traffic is on.
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004411 if (VOS_TRUE == WLANBAP_AmpSessionOn())
Jeff Johnson295189b2012-06-20 16:38:30 -07004412 {
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004413 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07004414 "%s: No scanning when AMP is on", __func__);
4415 return -EOPNOTSUPP;
4416 }
4417#endif
4418 //Scan on any other interface is not supported.
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004419 if (pAdapter->device_mode == WLAN_HDD_SOFTAP)
Jeff Johnson295189b2012-06-20 16:38:30 -07004420 {
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004421 hddLog(VOS_TRACE_LEVEL_ERROR,
Jeff Johnson295189b2012-06-20 16:38:30 -07004422 "%s: Not scanning on device_mode = %d",
4423 __func__, pAdapter->device_mode);
4424 return -EOPNOTSUPP;
4425 }
4426
4427 if (TRUE == pScanInfo->mScanPending)
4428 {
4429 hddLog(VOS_TRACE_LEVEL_INFO, "%s: mScanPending is TRUE", __func__);
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004430 return -EBUSY;
Jeff Johnson295189b2012-06-20 16:38:30 -07004431 }
4432
4433 if ((WLAN_HDD_GET_CTX(pAdapter))->isLogpInProgress)
4434 {
4435 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
4436 "%s:LOGP in Progress. Ignore!!!", __func__);
4437 return -EAGAIN;
4438 }
4439
Mohit Khanna6c52bbf2012-09-11 15:10:12 -07004440 if ((WLAN_HDD_GET_CTX(pAdapter))->isLoadUnloadInProgress)
4441 {
4442 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
4443 "%s:Unloading/Loading in Progress. Ignore!!!", __func__);
4444 return -EAGAIN;
4445 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07004446 //Don't Allow Scan and return busy if Remain On
4447 //Channel and action frame is pending
4448 //Otherwise Cancel Remain On Channel and allow Scan
4449 //If no action frame pending
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004450 if (0 != wlan_hdd_check_remain_on_channel(pAdapter))
Jeff Johnson32d95a32012-09-10 13:15:23 -07004451 {
4452 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Remain On Channel Pending", __func__);
4453 return -EBUSY;
4454 }
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004455#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07004456 /* if tdls disagree scan right now, return immediately.
4457 tdls will schedule the scan when scan is allowed. (return SUCCESS)
4458 or will reject the scan if any TDLS is in progress. (return -EBUSY)
4459 */
4460 status = wlan_hdd_tdls_scan_callback (pAdapter,
4461 wiphy,
4462#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
4463 dev,
Gopichand Nakkalac3c42b92013-03-20 19:42:34 -07004464#endif
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07004465 request);
4466 if(status <= 0)
4467 {
4468 hddLog(VOS_TRACE_LEVEL_INFO, "%s: TDLS Pending %d", __func__, status);
4469 return status;
Gopichand Nakkala681989c2013-03-06 22:27:48 -08004470 }
4471#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -07004472
Jeff Johnson295189b2012-06-20 16:38:30 -07004473 if (mutex_lock_interruptible(&pHddCtx->tmInfo.tmOperationLock))
4474 {
4475 VOS_TRACE(VOS_MODULE_ID_HDD,VOS_TRACE_LEVEL_ERROR,
Jeff Johnson1250df42012-12-10 14:31:52 -08004476 "%s: Acquire lock fail", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07004477 return -EAGAIN;
4478 }
4479 if (TRUE == pHddCtx->tmInfo.tmAction.enterImps)
4480 {
4481 hddLog(VOS_TRACE_LEVEL_WARN,
4482 "%s: MAX TM Level Scan not allowed", __func__);
4483 mutex_unlock(&pHddCtx->tmInfo.tmOperationLock);
4484 return -EBUSY;
4485 }
4486 mutex_unlock(&pHddCtx->tmInfo.tmOperationLock);
4487
Madan Mohan Koyyalamudicfd53742013-01-11 15:29:03 -08004488 /* Check if scan is allowed at this point of time.
4489 */
4490 if (!hdd_isScanAllowed(pHddCtx))
4491 {
4492 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Scan not allowed", __func__);
4493 return -EBUSY;
4494 }
4495
Jeff Johnson295189b2012-06-20 16:38:30 -07004496 vos_mem_zero( &scanRequest, sizeof(scanRequest));
4497
4498 if (NULL != request)
4499 {
4500 hddLog(VOS_TRACE_LEVEL_INFO, "scan request for ssid = %d",
4501 (int)request->n_ssids);
4502
4503 /* Even though supplicant doesn't provide any SSIDs, n_ssids is set to 1.
4504 * Becasue of this, driver is assuming that this is not wildcard scan and so
4505 * is not aging out the scan results.
4506 */
Jeff Johnson32d95a32012-09-10 13:15:23 -07004507 if (request->ssids && '\0' == request->ssids->ssid[0])
Jeff Johnson295189b2012-06-20 16:38:30 -07004508 {
4509 request->n_ssids = 0;
4510 }
4511
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07004512 if ((request->ssids) && (0 < request->n_ssids))
Jeff Johnson295189b2012-06-20 16:38:30 -07004513 {
4514 tCsrSSIDInfo *SsidInfo;
4515 int j;
4516 scanRequest.SSIDs.numOfSSIDs = request->n_ssids;
4517 /* Allocate num_ssid tCsrSSIDInfo structure */
4518 SsidInfo = scanRequest.SSIDs.SSIDList =
4519 ( tCsrSSIDInfo *)vos_mem_malloc(
4520 request->n_ssids*sizeof(tCsrSSIDInfo));
4521
4522 if(NULL == scanRequest.SSIDs.SSIDList)
4523 {
4524 hddLog(VOS_TRACE_LEVEL_ERROR,
4525 "memory alloc failed SSIDInfo buffer");
4526 return -ENOMEM;
4527 }
4528
4529 /* copy all the ssid's and their length */
4530 for(j = 0; j < request->n_ssids; j++, SsidInfo++)
4531 {
4532 /* get the ssid length */
4533 SsidInfo->SSID.length = request->ssids[j].ssid_len;
4534 vos_mem_copy(SsidInfo->SSID.ssId, &request->ssids[j].ssid[0],
4535 SsidInfo->SSID.length);
4536 SsidInfo->SSID.ssId[SsidInfo->SSID.length] = '\0';
4537 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "SSID number %d: %s",
4538 j, SsidInfo->SSID.ssId);
4539 }
4540 /* set the scan type to active */
4541 scanRequest.scanType = eSIR_ACTIVE_SCAN;
4542 }
4543 else if(WLAN_HDD_P2P_GO == pAdapter->device_mode)
4544 {
4545 /* set the scan type to active */
4546 scanRequest.scanType = eSIR_ACTIVE_SCAN;
4547 }
4548 else
4549 {
4550 /*Set the scan type to default type, in this case it is ACTIVE*/
4551 scanRequest.scanType = pScanInfo->scan_mode;
4552 }
4553 scanRequest.minChnTime = cfg_param->nActiveMinChnTime;
4554 scanRequest.maxChnTime = cfg_param->nActiveMaxChnTime;
4555 }
4556 else
4557 {
4558 /* set the scan type to active */
4559 scanRequest.scanType = eSIR_ACTIVE_SCAN;
4560 vos_mem_set( scanRequest.bssid, sizeof( tCsrBssid ), 0xff );
4561
4562 /* set min and max channel time to zero */
4563 scanRequest.minChnTime = 0;
4564 scanRequest.maxChnTime = 0;
4565 }
4566
4567 /* set BSSType to default type */
4568 scanRequest.BSSType = eCSR_BSS_TYPE_ANY;
4569
4570 /*TODO: scan the requested channels only*/
4571
4572 /*Right now scanning all the channels */
4573 if( request )
4574 {
4575 if( request->n_channels )
4576 {
4577 channelList = vos_mem_malloc( request->n_channels );
4578 if( NULL == channelList )
4579 {
4580 status = -ENOMEM;
4581 goto free_mem;
4582 }
4583
4584 for( i = 0 ; i < request->n_channels ; i++ )
4585 channelList[i] = request->channels[i]->hw_value;
4586 }
4587
4588 scanRequest.ChannelInfo.numOfChannels = request->n_channels;
4589 scanRequest.ChannelInfo.ChannelList = channelList;
4590
4591 /* set requestType to full scan */
4592 scanRequest.requestType = eCSR_SCAN_REQUEST_FULL_SCAN;
Madan Mohan Koyyalamudi8d50f312012-11-27 15:48:57 -08004593
4594 /* Flush the scan results(only p2p beacons) for STA scan and P2P
4595 * search (Flush on both full scan and social scan but not on single
4596 * channel scan).P2P search happens on 3 social channels (1, 6, 11)
4597 */
4598
4599 /* Supplicant does single channel scan after 8-way handshake
4600 * and in that case driver shoudnt flush scan results. If
4601 * driver flushes the scan results here and unfortunately if
4602 * the AP doesnt respond to our probe req then association
4603 * fails which is not desired
4604 */
4605
4606 if( request->n_channels != WLAN_HDD_P2P_SINGLE_CHANNEL_SCAN )
4607 {
4608 sme_ScanFlushP2PResult( WLAN_HDD_GET_HAL_CTX(pAdapter),
4609 pAdapter->sessionId );
4610 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004611
4612 if( request->ie_len )
4613 {
4614 /* save this for future association (join requires this) */
4615 memset( &pScanInfo->scanAddIE, 0, sizeof(pScanInfo->scanAddIE) );
4616 memcpy( pScanInfo->scanAddIE.addIEdata, request->ie, request->ie_len);
4617 pScanInfo->scanAddIE.length = request->ie_len;
4618
4619 if((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
Jeff Johnsone7245742012-09-05 17:12:55 -07004620 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) ||
4621 (WLAN_HDD_P2P_DEVICE == pAdapter->device_mode)
Jeff Johnson295189b2012-06-20 16:38:30 -07004622 )
4623 {
4624 pwextBuf->roamProfile.pAddIEScan = pScanInfo->scanAddIE.addIEdata;
4625 pwextBuf->roamProfile.nAddIEScanLength = pScanInfo->scanAddIE.length;
4626 }
4627
4628 scanRequest.uIEFieldLen = pScanInfo->scanAddIE.length;
4629 scanRequest.pIEField = pScanInfo->scanAddIE.addIEdata;
4630
Jeff Johnson295189b2012-06-20 16:38:30 -07004631 pP2pIe = wlan_hdd_get_p2p_ie_ptr((v_U8_t*)request->ie,
4632 request->ie_len);
4633 if (pP2pIe != NULL)
4634 {
Madan Mohan Koyyalamudi26bd7142012-10-30 18:14:19 -07004635#ifdef WLAN_FEATURE_P2P_DEBUG
4636 if (((globalP2PConnectionStatus == P2P_GO_NEG_COMPLETED) ||
4637 (globalP2PConnectionStatus == P2P_GO_NEG_PROCESS)) &&
4638 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
4639 {
4640 globalP2PConnectionStatus = P2P_CLIENT_CONNECTING_STATE_1;
4641 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P State] Changing state from "
4642 "Go nego completed to Connection is started");
4643 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P]P2P Scanning is started "
4644 "for 8way Handshake");
4645 }
4646 else if((globalP2PConnectionStatus == P2P_CLIENT_DISCONNECTED_STATE) &&
4647 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
4648 {
4649 globalP2PConnectionStatus = P2P_CLIENT_CONNECTING_STATE_2;
4650 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P State] Changing state from "
4651 "Disconnected state to Connection is started");
4652 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P]P2P Scanning is started "
4653 "for 4way Handshake");
4654 }
4655#endif
4656
Jeff Johnsone7245742012-09-05 17:12:55 -07004657 /* no_cck will be set during p2p find to disable 11b rates */
4658 if(TRUE == request->no_cck)
Jeff Johnson295189b2012-06-20 16:38:30 -07004659 {
Jeff Johnson295189b2012-06-20 16:38:30 -07004660 hddLog(VOS_TRACE_LEVEL_INFO,
4661 "%s: This is a P2P Search", __func__);
4662 scanRequest.p2pSearch = 1;
Jeff Johnsone7245742012-09-05 17:12:55 -07004663
Jeff Johnsone7245742012-09-05 17:12:55 -07004664 if( request->n_channels == WLAN_HDD_P2P_SOCIAL_CHANNELS )
4665 {
Madan Mohan Koyyalamudi1b1d9e82012-10-21 11:38:33 -07004666 /* set requestType to P2P Discovery */
4667 scanRequest.requestType = eCSR_SCAN_P2P_DISCOVERY;
Jeff Johnsone7245742012-09-05 17:12:55 -07004668 }
4669
4670 /*
4671 Skip Dfs Channel in case of P2P Search
4672 if it is set in ini file
4673 */
4674 if(cfg_param->skipDfsChnlInP2pSearch)
4675 {
4676 scanRequest.skipDfsChnlInP2pSearch = 1;
4677 }
4678 else
4679 {
4680 scanRequest.skipDfsChnlInP2pSearch = 0;
4681 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004682
Jeff Johnson295189b2012-06-20 16:38:30 -07004683 }
4684 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004685 }
4686 }
4687
4688 INIT_COMPLETION(pScanInfo->scan_req_completion_event);
4689
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07004690 /* acquire the wakelock to avoid the apps suspend during the scan. To
4691 * address the following issues.
4692 * 1) Disconnected scenario: we are not allowing the suspend as WLAN is not in
4693 * BMPS/IMPS this result in android trying to suspend aggressively and backing off
4694 * for long time, this result in apps running at full power for long time.
4695 * 2) Connected scenario: If we allow the suspend during the scan, RIVA will
4696 * be stuck in full power because of resume BMPS
4697 */
4698 hdd_prevent_suspend();
Jeff Johnsone7245742012-09-05 17:12:55 -07004699
4700 status = sme_ScanRequest( WLAN_HDD_GET_HAL_CTX(pAdapter),
Jeff Johnson295189b2012-06-20 16:38:30 -07004701 pAdapter->sessionId, &scanRequest, &scanId,
4702 &hdd_cfg80211_scan_done_callback, dev );
Jeff Johnsone7245742012-09-05 17:12:55 -07004703
Jeff Johnson295189b2012-06-20 16:38:30 -07004704 if (eHAL_STATUS_SUCCESS != status)
4705 {
4706 hddLog(VOS_TRACE_LEVEL_ERROR,
4707 "%s: sme_ScanRequest returned error %d", __func__, status);
4708 complete(&pScanInfo->scan_req_completion_event);
Madan Mohan Koyyalamudi3b230fe2012-10-18 14:46:32 -07004709 if(eHAL_STATUS_RESOURCES == status)
4710 {
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07004711 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 -07004712 status = -EBUSY;
4713 } else {
4714 status = -EIO;
4715 }
Madan Mohan Koyyalamudi9f5a10c2012-09-28 14:46:16 -07004716 hdd_allow_suspend();
Jeff Johnson295189b2012-06-20 16:38:30 -07004717 goto free_mem;
4718 }
4719
4720 pScanInfo->mScanPending = TRUE;
4721 pAdapter->request = request;
4722 pScanInfo->scanId = scanId;
4723
4724 complete(&pScanInfo->scan_req_completion_event);
4725
4726free_mem:
4727 if( scanRequest.SSIDs.SSIDList )
4728 {
4729 vos_mem_free(scanRequest.SSIDs.SSIDList);
4730 }
4731
4732 if( channelList )
4733 vos_mem_free( channelList );
4734
4735 EXIT();
4736
4737 return status;
4738}
4739
4740/*
4741 * FUNCTION: wlan_hdd_cfg80211_connect_start
4742 * This function is used to start the association process
4743 */
4744int wlan_hdd_cfg80211_connect_start( hdd_adapter_t *pAdapter,
Jeff Johnson32d95a32012-09-10 13:15:23 -07004745 const u8 *ssid, size_t ssid_len, const u8 *bssid, u8 operatingChannel)
Jeff Johnson295189b2012-06-20 16:38:30 -07004746{
4747 int status = 0;
4748 hdd_wext_state_t *pWextState;
4749 v_U32_t roamId;
4750 tCsrRoamProfile *pRoamProfile;
4751 eMib_dot11DesiredBssType connectedBssType;
4752 eCsrAuthType RSNAuthType;
4753
4754 ENTER();
4755
4756 pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
4757
4758 if (SIR_MAC_MAX_SSID_LENGTH < ssid_len)
4759 {
4760 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: wrong SSID len", __func__);
4761 return -EINVAL;
4762 }
4763
4764 pRoamProfile = &pWextState->roamProfile;
4765
4766 if (pRoamProfile)
4767 {
Jeff Johnsone7245742012-09-05 17:12:55 -07004768 int ret = 0;
4769 hdd_station_ctx_t *pHddStaCtx;
4770 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
4771 hdd_connGetConnectedBssType(pHddStaCtx,&connectedBssType );
4772
4773 if((eMib_dot11DesiredBssType_independent == connectedBssType) ||
4774 (eConnectionState_Associated == pHddStaCtx->conn_info.connState) ||
4775 (eConnectionState_IbssConnected == pHddStaCtx->conn_info.connState))
Jeff Johnson295189b2012-06-20 16:38:30 -07004776 {
4777 /* Issue disconnect to CSR */
4778 INIT_COMPLETION(pAdapter->disconnect_comp_var);
4779 if( eHAL_STATUS_SUCCESS ==
4780 sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
4781 pAdapter->sessionId,
4782 eCSR_DISCONNECT_REASON_UNSPECIFIED ) )
4783 {
Jeff Johnsone7245742012-09-05 17:12:55 -07004784 ret = wait_for_completion_interruptible_timeout(
4785 &pAdapter->disconnect_comp_var,
4786 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
4787 if (0 == ret)
4788 {
4789 VOS_ASSERT(0);
4790 }
4791 }
4792 }
4793 else if(eConnectionState_Disconnecting == pHddStaCtx->conn_info.connState)
4794 {
4795 ret = wait_for_completion_interruptible_timeout(
4796 &pAdapter->disconnect_comp_var,
4797 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
4798 if (0 == ret)
4799 {
4800 VOS_ASSERT(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004801 }
4802 }
4803
4804 if (HDD_WMM_USER_MODE_NO_QOS ==
4805 (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini->WmmMode)
4806 {
4807 /*QoS not enabled in cfg file*/
4808 pRoamProfile->uapsd_mask = 0;
4809 }
4810 else
4811 {
4812 /*QoS enabled, update uapsd mask from cfg file*/
4813 pRoamProfile->uapsd_mask =
4814 (WLAN_HDD_GET_CTX(pAdapter))->cfg_ini->UapsdMask;
4815 }
4816
4817 pRoamProfile->SSIDs.numOfSSIDs = 1;
4818 pRoamProfile->SSIDs.SSIDList->SSID.length = ssid_len;
4819 vos_mem_zero(pRoamProfile->SSIDs.SSIDList->SSID.ssId,
4820 sizeof(pRoamProfile->SSIDs.SSIDList->SSID.ssId));
4821 vos_mem_copy((void *)(pRoamProfile->SSIDs.SSIDList->SSID.ssId),
4822 ssid, ssid_len);
4823
4824 if (bssid)
4825 {
4826 pRoamProfile->BSSIDs.numOfBSSIDs = 1;
4827 vos_mem_copy((void *)(pRoamProfile->BSSIDs.bssid), bssid,
4828 WNI_CFG_BSSID_LEN);
4829 /* Save BSSID in seperate variable as well, as RoamProfile
4830 BSSID is getting zeroed out in the association process. And in
4831 case of join failure we should send valid BSSID to supplicant
4832 */
4833 vos_mem_copy((void *)(pWextState->req_bssId), bssid,
4834 WNI_CFG_BSSID_LEN);
4835 }
4836
4837 if ((IW_AUTH_WPA_VERSION_WPA == pWextState->wpaVersion) ||
4838 (IW_AUTH_WPA_VERSION_WPA2 == pWextState->wpaVersion))
4839 {
4840 /*set gen ie*/
4841 hdd_SetGENIEToCsr(pAdapter, &RSNAuthType);
4842 /*set auth*/
4843 hdd_set_csr_auth_type(pAdapter, RSNAuthType);
4844 }
4845 else if ( (pWextState->roamProfile.AuthType.authType[0] ==
4846 eCSR_AUTH_TYPE_OPEN_SYSTEM)
4847 && ((pWextState->roamProfile.EncryptionType.encryptionType[0] ==
4848 eCSR_ENCRYPT_TYPE_WEP40_STATICKEY)
4849 || (pWextState->roamProfile.EncryptionType.encryptionType[0] ==
4850 eCSR_ENCRYPT_TYPE_WEP104_STATICKEY))
4851 )
4852 {
4853 /*Android UI not having any option to configure the Authentication type to OPEN/SHARED;
4854 * The authentication type will be always eCSR_AUTH_TYPE_OPEN_SYSTEM when WEP is used
4855 * Use eCSR_AUTH_TYPE_AUTOSWITCH when WEP encryption used*/
4856 (WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))->conn_info.authType =
4857 eCSR_AUTH_TYPE_AUTOSWITCH;
4858 pWextState->roamProfile.AuthType.authType[0] =
4859 (WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))->conn_info.authType;
4860 }
4861#ifdef FEATURE_WLAN_WAPI
4862 if (pAdapter->wapi_info.nWapiMode)
4863 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07004864 hddLog(LOG1, "%s: Setting WAPI AUTH Type and Encryption Mode values", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07004865 switch (pAdapter->wapi_info.wapiAuthMode)
4866 {
4867 case WAPI_AUTH_MODE_PSK:
4868 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07004869 hddLog(LOG1, "%s: WAPI AUTH TYPE: PSK: %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07004870 pAdapter->wapi_info.wapiAuthMode);
4871 pRoamProfile->AuthType.authType[0] = eCSR_AUTH_TYPE_WAPI_WAI_PSK;
4872 break;
4873 }
4874 case WAPI_AUTH_MODE_CERT:
4875 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07004876 hddLog(LOG1, "%s: WAPI AUTH TYPE: CERT: %d", __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07004877 pAdapter->wapi_info.wapiAuthMode);
4878 pRoamProfile->AuthType.authType[0] = eCSR_AUTH_TYPE_WAPI_WAI_CERTIFICATE;
4879 break;
4880 }
4881 } // End of switch
4882 if ( pAdapter->wapi_info.wapiAuthMode == WAPI_AUTH_MODE_PSK ||
4883 pAdapter->wapi_info.wapiAuthMode == WAPI_AUTH_MODE_CERT)
4884 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07004885 hddLog(LOG1, "%s: WAPI PAIRWISE/GROUP ENCRYPTION: WPI", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07004886 pRoamProfile->AuthType.numEntries = 1;
4887 pRoamProfile->EncryptionType.numEntries = 1;
4888 pRoamProfile->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_WPI;
4889 pRoamProfile->mcEncryptionType.numEntries = 1;
4890 pRoamProfile->mcEncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_WPI;
4891 }
4892 }
4893#endif /* FEATURE_WLAN_WAPI */
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05304894#ifdef WLAN_FEATURE_GTK_OFFLOAD
4895 /* Initializing gtkOffloadRequestParams */
4896 if ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) ||
4897 (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
4898 {
4899 pHddStaCtx->gtkOffloadRequestParams.requested = FALSE;
4900 memset(&pHddStaCtx->gtkOffloadRequestParams.gtkOffloadReqParams,
4901 0, sizeof (tSirGtkOffloadParams));
4902 }
4903#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004904 pRoamProfile->csrPersona = pAdapter->device_mode;
4905
Jeff Johnson32d95a32012-09-10 13:15:23 -07004906 if( operatingChannel )
4907 {
4908 pRoamProfile->ChannelInfo.ChannelList = &operatingChannel;
4909 pRoamProfile->ChannelInfo.numOfChannels = 1;
4910 }
Chet Lanctot186b5732013-03-18 10:26:30 -07004911 else
4912 {
4913 pRoamProfile->ChannelInfo.ChannelList = NULL;
4914 pRoamProfile->ChannelInfo.numOfChannels = 0;
4915 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07004916
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08004917 /* change conn_state to connecting before sme_RoamConnect(), because sme_RoamConnect()
4918 * has a direct path to call hdd_smeRoamCallback(), which will change the conn_state
4919 * If direct path, conn_state will be accordingly changed to NotConnected or Associated
4920 * by either hdd_AssociationCompletionHandler() or hdd_DisConnectHandler() in sme_RoamCallback()
Madan Mohan Koyyalamudidf86c422012-12-04 17:03:44 -08004921 * if sme_RomConnect is to be queued, Connecting state will remain until it is completed.
4922 */
4923 if (WLAN_HDD_INFRA_STATION == pAdapter->device_mode)
4924 hdd_connSetConnectionState(WLAN_HDD_GET_STATION_CTX_PTR(pAdapter),
4925 eConnectionState_Connecting);
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08004926
Jeff Johnson295189b2012-06-20 16:38:30 -07004927 status = sme_RoamConnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
4928 pAdapter->sessionId, pRoamProfile, &roamId);
4929
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08004930 if( (eHAL_STATUS_SUCCESS != status) &&
Madan Mohan Koyyalamudid5acbf52012-11-28 01:45:08 +05304931 (WLAN_HDD_INFRA_STATION == pAdapter->device_mode) )
4932
4933 {
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08004934 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: sme_RoamConnect (session %d) failed with "
4935 "status %d. -> NotConnected", __func__, pAdapter->sessionId, status);
4936 /* change back to NotAssociated */
Madan Mohan Koyyalamudid5acbf52012-11-28 01:45:08 +05304937 hdd_connSetConnectionState(WLAN_HDD_GET_STATION_CTX_PTR(pAdapter),
Madan Mohan Koyyalamudi42dcd162012-12-03 16:34:04 -08004938 eConnectionState_NotConnected);
Madan Mohan Koyyalamudid5acbf52012-11-28 01:45:08 +05304939 }
Madan Mohan Koyyalamudidf86c422012-12-04 17:03:44 -08004940
4941 pRoamProfile->ChannelInfo.ChannelList = NULL;
4942 pRoamProfile->ChannelInfo.numOfChannels = 0;
4943
Jeff Johnson295189b2012-06-20 16:38:30 -07004944 }
4945 else
4946 {
4947 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: No valid Roam profile", __func__);
4948 return -EINVAL;
4949 }
Madan Mohan Koyyalamudifd4e1da2012-11-09 17:50:19 -08004950 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07004951 return status;
4952}
4953
4954/*
4955 * FUNCTION: wlan_hdd_set_cfg80211_auth_type
4956 * This function is used to set the authentication type (OPEN/SHARED).
4957 *
4958 */
4959static int wlan_hdd_cfg80211_set_auth_type(hdd_adapter_t *pAdapter,
4960 enum nl80211_auth_type auth_type)
4961{
4962 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
4963 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
4964
4965 ENTER();
4966
4967 /*set authentication type*/
4968 switch (auth_type)
4969 {
4970 case NL80211_AUTHTYPE_OPEN_SYSTEM:
4971 case NL80211_AUTHTYPE_AUTOMATIC:
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07004972#ifdef WLAN_FEATURE_VOWIFI_11R
4973 case NL80211_AUTHTYPE_FT:
4974#endif /* WLAN_FEATURE_VOWIFI_11R */
Jeff Johnson295189b2012-06-20 16:38:30 -07004975 hddLog(VOS_TRACE_LEVEL_INFO,
4976 "%s: set authentication type to OPEN", __func__);
4977 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
4978 break;
4979
4980 case NL80211_AUTHTYPE_SHARED_KEY:
4981 hddLog(VOS_TRACE_LEVEL_INFO,
4982 "%s: set authentication type to SHARED", __func__);
4983 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_SHARED_KEY;
4984 break;
4985#ifdef FEATURE_WLAN_CCX
4986 case NL80211_AUTHTYPE_NETWORK_EAP:
4987 hddLog(VOS_TRACE_LEVEL_INFO,
4988 "%s: set authentication type to CCKM WPA", __func__);
4989 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_CCKM_WPA;//eCSR_AUTH_TYPE_CCKM_RSN needs to be handled as well if required.
4990 break;
4991#endif
4992
4993
4994 default:
4995 hddLog(VOS_TRACE_LEVEL_ERROR,
4996 "%s: Unsupported authentication type %d", __func__,
4997 auth_type);
4998 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_UNKNOWN;
4999 return -EINVAL;
5000 }
5001
5002 pWextState->roamProfile.AuthType.authType[0] =
5003 pHddStaCtx->conn_info.authType;
5004 return 0;
5005}
5006
5007/*
5008 * FUNCTION: wlan_hdd_set_akm_suite
5009 * This function is used to set the key mgmt type(PSK/8021x).
5010 *
5011 */
5012static int wlan_hdd_set_akm_suite( hdd_adapter_t *pAdapter,
5013 u32 key_mgmt
5014 )
5015{
5016 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
5017 ENTER();
5018
5019 /*set key mgmt type*/
5020 switch(key_mgmt)
5021 {
5022 case WLAN_AKM_SUITE_PSK:
Gopichand Nakkala356fb102013-03-06 12:34:04 +05305023#ifdef WLAN_FEATURE_VOWIFI_11R
5024 case WLAN_AKM_SUITE_FT_PSK:
5025#endif
5026 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting key mgmt type to PSK",
Jeff Johnson295189b2012-06-20 16:38:30 -07005027 __func__);
5028 pWextState->authKeyMgmt |= IW_AUTH_KEY_MGMT_PSK;
5029 break;
5030
5031 case WLAN_AKM_SUITE_8021X:
Gopichand Nakkala356fb102013-03-06 12:34:04 +05305032#ifdef WLAN_FEATURE_VOWIFI_11R
5033 case WLAN_AKM_SUITE_FT_8021X:
5034#endif
5035 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting key mgmt type to 8021x",
Jeff Johnson295189b2012-06-20 16:38:30 -07005036 __func__);
5037 pWextState->authKeyMgmt |= IW_AUTH_KEY_MGMT_802_1X;
5038 break;
5039#ifdef FEATURE_WLAN_CCX
5040#define WLAN_AKM_SUITE_CCKM 0x00409600 /* Should be in ieee802_11_defs.h */
5041#define IW_AUTH_KEY_MGMT_CCKM 8 /* Should be in linux/wireless.h */
5042 case WLAN_AKM_SUITE_CCKM:
5043 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting key mgmt type to CCKM",
5044 __func__);
5045 pWextState->authKeyMgmt |= IW_AUTH_KEY_MGMT_CCKM;
5046 break;
5047#endif
5048
5049 default:
5050 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported key mgmt type %d",
5051 __func__, key_mgmt);
5052 return -EINVAL;
5053
5054 }
5055 return 0;
5056}
5057
5058/*
5059 * FUNCTION: wlan_hdd_cfg80211_set_cipher
5060 * This function is used to set the encryption type
5061 * (NONE/WEP40/WEP104/TKIP/CCMP).
5062 */
5063static int wlan_hdd_cfg80211_set_cipher( hdd_adapter_t *pAdapter,
5064 u32 cipher,
5065 bool ucast
5066 )
5067{
5068 eCsrEncryptionType encryptionType = eCSR_ENCRYPT_TYPE_NONE;
5069 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
5070 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
5071
5072 ENTER();
5073
5074 if (!cipher)
5075 {
5076 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: received cipher %d - considering none",
5077 __func__, cipher);
5078 encryptionType = eCSR_ENCRYPT_TYPE_NONE;
5079 }
5080 else
5081 {
5082
5083 /*set encryption method*/
5084 switch (cipher)
5085 {
5086 case IW_AUTH_CIPHER_NONE:
5087 encryptionType = eCSR_ENCRYPT_TYPE_NONE;
5088 break;
5089
5090 case WLAN_CIPHER_SUITE_WEP40:
5091 if ((IW_AUTH_KEY_MGMT_802_1X == pWextState->authKeyMgmt) &&
5092 (eCSR_AUTH_TYPE_OPEN_SYSTEM == pHddStaCtx->conn_info.authType))
5093 encryptionType = eCSR_ENCRYPT_TYPE_WEP40;
5094 else
5095 encryptionType = eCSR_ENCRYPT_TYPE_WEP40_STATICKEY;
5096 break;
5097
5098 case WLAN_CIPHER_SUITE_WEP104:
5099 if ((IW_AUTH_KEY_MGMT_802_1X == pWextState->authKeyMgmt) &&
5100 (eCSR_AUTH_TYPE_OPEN_SYSTEM == pHddStaCtx->conn_info.authType))
5101 encryptionType = eCSR_ENCRYPT_TYPE_WEP104;
5102 else
5103 encryptionType = eCSR_ENCRYPT_TYPE_WEP104_STATICKEY;
5104 break;
5105
5106 case WLAN_CIPHER_SUITE_TKIP:
5107 encryptionType = eCSR_ENCRYPT_TYPE_TKIP;
5108 break;
5109
5110 case WLAN_CIPHER_SUITE_CCMP:
5111 encryptionType = eCSR_ENCRYPT_TYPE_AES;
5112 break;
5113#ifdef FEATURE_WLAN_WAPI
5114 case WLAN_CIPHER_SUITE_SMS4:
5115 encryptionType = eCSR_ENCRYPT_TYPE_WPI;
5116 break;
5117#endif
5118
5119#ifdef FEATURE_WLAN_CCX
5120 case WLAN_CIPHER_SUITE_KRK:
5121 encryptionType = eCSR_ENCRYPT_TYPE_KRK;
5122 break;
5123#endif
5124 default:
5125 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Unsupported cipher type %d",
5126 __func__, cipher);
5127 return -EOPNOTSUPP;
5128 }
5129 }
5130
5131 if (ucast)
5132 {
5133 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting unicast cipher type to %d",
5134 __func__, encryptionType);
5135 pHddStaCtx->conn_info.ucEncryptionType = encryptionType;
5136 pWextState->roamProfile.EncryptionType.numEntries = 1;
5137 pWextState->roamProfile.EncryptionType.encryptionType[0] =
5138 encryptionType;
5139 }
5140 else
5141 {
5142 hddLog(VOS_TRACE_LEVEL_INFO, "%s: setting mcast cipher type to %d",
5143 __func__, encryptionType);
5144 pHddStaCtx->conn_info.mcEncryptionType = encryptionType;
5145 pWextState->roamProfile.mcEncryptionType.numEntries = 1;
5146 pWextState->roamProfile.mcEncryptionType.encryptionType[0] = encryptionType;
5147 }
5148
5149 return 0;
5150}
5151
5152
5153/*
5154 * FUNCTION: wlan_hdd_cfg80211_set_ie
5155 * This function is used to parse WPA/RSN IE's.
5156 */
5157int wlan_hdd_cfg80211_set_ie( hdd_adapter_t *pAdapter,
5158 u8 *ie,
5159 size_t ie_len
5160 )
5161{
5162 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
5163 u8 *genie = ie;
5164 v_U16_t remLen = ie_len;
5165#ifdef FEATURE_WLAN_WAPI
5166 v_U32_t akmsuite[MAX_NUM_AKM_SUITES];
5167 u16 *tmp;
5168 v_U16_t akmsuiteCount;
5169 int *akmlist;
5170#endif
5171 ENTER();
5172
5173 /* clear previous assocAddIE */
5174 pWextState->assocAddIE.length = 0;
5175 pWextState->roamProfile.bWPSAssociation = VOS_FALSE;
5176
5177 while (remLen >= 2)
5178 {
5179 v_U16_t eLen = 0;
5180 v_U8_t elementId;
5181 elementId = *genie++;
5182 eLen = *genie++;
5183 remLen -= 2;
5184
5185 hddLog(VOS_TRACE_LEVEL_INFO, "%s: IE[0x%X], LEN[%d]\n",
5186 __func__, elementId, eLen);
5187
5188 switch ( elementId )
5189 {
5190 case DOT11F_EID_WPA:
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005191 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 -07005192 {
5193 hddLog(VOS_TRACE_LEVEL_ERROR,
5194 "%s: Invalid WPA IE", __func__);
5195 return -EINVAL;
5196 }
5197 else if (0 == memcmp(&genie[0], "\x00\x50\xf2\x04", 4))
5198 {
5199 v_U16_t curAddIELen = pWextState->assocAddIE.length;
5200 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set WPS IE(len %d)",
5201 __func__, eLen + 2);
5202
5203 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5204 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005205 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE. "
5206 "Need bigger buffer space");
Jeff Johnson295189b2012-06-20 16:38:30 -07005207 VOS_ASSERT(0);
5208 return -ENOMEM;
5209 }
5210 // WSC IE is saved to Additional IE ; it should be accumulated to handle WPS IE + P2P IE
5211 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5212 pWextState->assocAddIE.length += eLen + 2;
5213
5214 pWextState->roamProfile.bWPSAssociation = VOS_TRUE;
5215 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5216 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5217 }
5218 else if (0 == memcmp(&genie[0], "\x00\x50\xf2", 3))
5219 {
5220 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set WPA IE (len %d)",__func__, eLen + 2);
5221 memset( pWextState->WPARSNIE, 0, MAX_WPA_RSN_IE_LEN );
5222 memcpy( pWextState->WPARSNIE, genie - 2, (eLen + 2) /*ie_len*/);
5223 pWextState->roamProfile.pWPAReqIE = pWextState->WPARSNIE;
5224 pWextState->roamProfile.nWPAReqIELength = eLen + 2;//ie_len;
5225 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005226 else if ( (0 == memcmp(&genie[0], P2P_OUI_TYPE,
5227 P2P_OUI_TYPE_SIZE))
5228 /*Consider P2P IE, only for P2P Client */
5229 && (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) )
5230 {
5231 v_U16_t curAddIELen = pWextState->assocAddIE.length;
5232 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set P2P IE(len %d)",
5233 __func__, eLen + 2);
5234
5235 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5236 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005237 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
5238 "Need bigger buffer space");
Jeff Johnson295189b2012-06-20 16:38:30 -07005239 VOS_ASSERT(0);
5240 return -ENOMEM;
5241 }
5242 // P2P IE is saved to Additional IE ; it should be accumulated to handle WPS IE + P2P IE
5243 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5244 pWextState->assocAddIE.length += eLen + 2;
5245
5246 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5247 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5248 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005249#ifdef WLAN_FEATURE_WFD
5250 else if ( (0 == memcmp(&genie[0], WFD_OUI_TYPE,
5251 WFD_OUI_TYPE_SIZE))
5252 /*Consider WFD IE, only for P2P Client */
5253 && (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) )
5254 {
5255 v_U16_t curAddIELen = pWextState->assocAddIE.length;
5256 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set WFD IE(len %d)",
5257 __func__, eLen + 2);
5258
5259 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5260 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005261 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
5262 "Need bigger buffer space");
Jeff Johnson295189b2012-06-20 16:38:30 -07005263 VOS_ASSERT(0);
5264 return -ENOMEM;
5265 }
5266 // WFD IE is saved to Additional IE ; it should be accumulated to handle
5267 // WPS IE + P2P IE + WFD IE
5268 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5269 pWextState->assocAddIE.length += eLen + 2;
5270
5271 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5272 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5273 }
5274#endif
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005275 /* Appending HS 2.0 Indication Element in Assiciation Request */
5276 else if ( (0 == memcmp(&genie[0], HS20_OUI_TYPE,
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005277 HS20_OUI_TYPE_SIZE)) )
5278 {
5279 v_U16_t curAddIELen = pWextState->assocAddIE.length;
5280 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set HS20 IE(len %d)",
5281 __func__, eLen + 2);
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005282
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005283 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5284 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005285 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
5286 "Need bigger buffer space");
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005287 VOS_ASSERT(0);
5288 return -ENOMEM;
5289 }
5290 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5291 pWextState->assocAddIE.length += eLen + 2;
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005292
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005293 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5294 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5295 }
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005296
Jeff Johnson295189b2012-06-20 16:38:30 -07005297 break;
5298 case DOT11F_EID_RSN:
5299 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set RSN IE(len %d)",__func__, eLen + 2);
5300 memset( pWextState->WPARSNIE, 0, MAX_WPA_RSN_IE_LEN );
5301 memcpy( pWextState->WPARSNIE, genie - 2, (eLen + 2)/*ie_len*/);
5302 pWextState->roamProfile.pRSNReqIE = pWextState->WPARSNIE;
5303 pWextState->roamProfile.nRSNReqIELength = eLen + 2; //ie_len;
5304 break;
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005305 /* Appending Extended Capabilities with Interworking bit set in Assoc Req */
5306 case DOT11F_EID_EXTCAP:
5307 {
5308 v_U16_t curAddIELen = pWextState->assocAddIE.length;
5309 hddLog (VOS_TRACE_LEVEL_INFO, "%s Set Extended CAPS IE(len %d)",
5310 __func__, eLen + 2);
5311
5312 if( SIR_MAC_MAX_IE_LENGTH < (pWextState->assocAddIE.length + eLen) )
5313 {
Jeff Johnson902c9832012-12-10 14:28:09 -08005314 hddLog(VOS_TRACE_LEVEL_FATAL, "Cannot accommodate assocAddIE "
5315 "Need bigger buffer space");
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005316 VOS_ASSERT(0);
5317 return -ENOMEM;
5318 }
5319 memcpy( pWextState->assocAddIE.addIEdata + curAddIELen, genie - 2, eLen + 2);
5320 pWextState->assocAddIE.length += eLen + 2;
5321
5322 pWextState->roamProfile.pAddIEAssoc = pWextState->assocAddIE.addIEdata;
5323 pWextState->roamProfile.nAddIEAssocLength = pWextState->assocAddIE.length;
5324 break;
5325 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005326#ifdef FEATURE_WLAN_WAPI
5327 case WLAN_EID_WAPI:
5328 pAdapter->wapi_info.nWapiMode = 1; //Setting WAPI Mode to ON=1
5329 hddLog(VOS_TRACE_LEVEL_INFO,"WAPI MODE IS %lu \n",
5330 pAdapter->wapi_info.nWapiMode);
5331 tmp = (u16 *)ie;
5332 tmp = tmp + 2; // Skip element Id and Len, Version
5333 akmsuiteCount = WPA_GET_LE16(tmp);
5334 tmp = tmp + 1;
5335 akmlist = (int *)(tmp);
5336 if(akmsuiteCount <= MAX_NUM_AKM_SUITES)
5337 {
5338 memcpy(akmsuite, akmlist, (4*akmsuiteCount));
5339 }
5340 else
5341 {
5342 hddLog(VOS_TRACE_LEVEL_FATAL, "Invalid akmSuite count\n");
5343 VOS_ASSERT(0);
5344 return -EINVAL;
5345 }
5346
5347 if (WAPI_PSK_AKM_SUITE == akmsuite[0])
5348 {
5349 hddLog(VOS_TRACE_LEVEL_INFO, "%s: WAPI AUTH MODE SET TO PSK",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005350 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005351 pAdapter->wapi_info.wapiAuthMode = WAPI_AUTH_MODE_PSK;
5352 }
5353 if (WAPI_CERT_AKM_SUITE == akmsuite[0])
5354 {
5355 hddLog(VOS_TRACE_LEVEL_INFO, "%s: WAPI AUTH MODE SET TO CERTIFICATE",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07005356 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005357 pAdapter->wapi_info.wapiAuthMode = WAPI_AUTH_MODE_CERT;
5358 }
5359 break;
5360#endif
5361 default:
5362 hddLog (VOS_TRACE_LEVEL_ERROR,
5363 "%s Set UNKNOWN IE %X", __func__, elementId);
Madan Mohan Koyyalamudief3b66e2012-10-11 14:29:42 -07005364 /* when Unknown IE is received we should break and continue
5365 * to the next IE in the buffer instead we were returning
5366 * so changing this to break */
5367 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07005368 }
5369 genie += eLen;
5370 remLen -= eLen;
5371 }
5372 EXIT();
5373 return 0;
5374}
5375
5376/*
5377 * FUNCTION: wlan_hdd_cfg80211_set_privacy
5378 * This function is used to initialize the security
5379 * parameters during connect operation.
5380 */
5381int wlan_hdd_cfg80211_set_privacy( hdd_adapter_t *pAdapter,
5382 struct cfg80211_connect_params *req
5383 )
5384{
5385 int status = 0;
5386 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
5387 ENTER();
5388
5389 /*set wpa version*/
5390 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_DISABLED;
5391
5392 if (req->crypto.wpa_versions)
5393 {
5394 if ( (NL80211_WPA_VERSION_1 == req->crypto.wpa_versions)
5395 && ( (req->ie_len)
5396 && (0 == memcmp( &req->ie[2], "\x00\x50\xf2",3) ) ) )
5397 // Make sure that it is including a WPA IE.
5398 /* Currently NL is putting WPA version 1 even for open,
5399 * since p2p ie is also put in same buffer.
5400 * */
5401 {
5402 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA;
5403 }
5404 else if (NL80211_WPA_VERSION_2 == req->crypto.wpa_versions)
5405 {
5406 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA2;
5407 }
5408 }
5409
5410 hddLog(VOS_TRACE_LEVEL_INFO, "%s: set wpa version to %d", __func__,
5411 pWextState->wpaVersion);
5412
5413 /*set authentication type*/
5414 status = wlan_hdd_cfg80211_set_auth_type(pAdapter, req->auth_type);
5415
5416 if (0 > status)
5417 {
5418 hddLog(VOS_TRACE_LEVEL_ERROR,
5419 "%s: failed to set authentication type ", __func__);
5420 return status;
5421 }
5422
5423 /*set key mgmt type*/
5424 if (req->crypto.n_akm_suites)
5425 {
5426 status = wlan_hdd_set_akm_suite(pAdapter, req->crypto.akm_suites[0]);
5427 if (0 > status)
5428 {
5429 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set akm suite",
5430 __func__);
5431 return status;
5432 }
5433 }
5434
5435 /*set pairwise cipher type*/
5436 if (req->crypto.n_ciphers_pairwise)
5437 {
5438 status = wlan_hdd_cfg80211_set_cipher(pAdapter,
5439 req->crypto.ciphers_pairwise[0], true);
5440 if (0 > status)
5441 {
5442 hddLog(VOS_TRACE_LEVEL_ERROR,
5443 "%s: failed to set unicast cipher type", __func__);
5444 return status;
5445 }
5446 }
5447 else
5448 {
5449 /*Reset previous cipher suite to none*/
5450 status = wlan_hdd_cfg80211_set_cipher(pAdapter, 0, true);
5451 if (0 > status)
5452 {
5453 hddLog(VOS_TRACE_LEVEL_ERROR,
5454 "%s: failed to set unicast cipher type", __func__);
5455 return status;
5456 }
5457 }
5458
5459 /*set group cipher type*/
5460 status = wlan_hdd_cfg80211_set_cipher(pAdapter, req->crypto.cipher_group,
5461 false);
5462
5463 if (0 > status)
5464 {
5465 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set mcast cipher type",
5466 __func__);
5467 return status;
5468 }
5469
Chet Lanctot186b5732013-03-18 10:26:30 -07005470#ifdef WLAN_FEATURE_11W
5471 pWextState->roamProfile.MFPEnabled = (req->mfp == NL80211_MFP_REQUIRED);
5472#endif
5473
Jeff Johnson295189b2012-06-20 16:38:30 -07005474 /*parse WPA/RSN IE, and set the correspoing fileds in Roam profile*/
5475 if (req->ie_len)
5476 {
5477 status = wlan_hdd_cfg80211_set_ie(pAdapter, req->ie, req->ie_len);
5478 if ( 0 > status)
5479 {
5480 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to parse the WPA/RSN IE",
5481 __func__);
5482 return status;
5483 }
5484 }
5485
5486 /*incase of WEP set default key information*/
5487 if (req->key && req->key_len)
5488 {
5489 if ( (WLAN_CIPHER_SUITE_WEP40 == req->crypto.ciphers_pairwise[0])
5490 || (WLAN_CIPHER_SUITE_WEP104 == req->crypto.ciphers_pairwise[0])
5491 )
5492 {
5493 if ( IW_AUTH_KEY_MGMT_802_1X
5494 == (pWextState->authKeyMgmt & IW_AUTH_KEY_MGMT_802_1X ))
5495 {
5496 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Dynamic WEP not supported",
5497 __func__);
5498 return -EOPNOTSUPP;
5499 }
5500 else
5501 {
5502 u8 key_len = req->key_len;
5503 u8 key_idx = req->key_idx;
5504
5505 if ((eCSR_SECURITY_WEP_KEYSIZE_MAX_BYTES >= key_len)
5506 && (CSR_MAX_NUM_KEY > key_idx)
5507 )
5508 {
5509 hddLog(VOS_TRACE_LEVEL_INFO,
5510 "%s: setting default wep key, key_idx = %hu key_len %hu",
5511 __func__, key_idx, key_len);
5512 vos_mem_copy(
5513 &pWextState->roamProfile.Keys.KeyMaterial[key_idx][0],
5514 req->key, key_len);
5515 pWextState->roamProfile.Keys.KeyLength[key_idx] =
5516 (u8)key_len;
5517 pWextState->roamProfile.Keys.defaultIndex = (u8)key_idx;
5518 }
5519 }
5520 }
5521 }
5522
5523 return status;
5524}
5525
5526/*
5527 * FUNCTION: wlan_hdd_cfg80211_set_privacy
5528 * This function is used to initialize the security
5529 * parameters during connect operation.
5530 */
5531static int wlan_hdd_cfg80211_connect( struct wiphy *wiphy,
5532 struct net_device *ndev,
5533 struct cfg80211_connect_params *req
5534 )
5535{
5536 int status = 0;
5537 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( ndev );
5538 VOS_STATUS exitbmpsStatus = VOS_STATUS_E_INVAL;
5539 hdd_context_t *pHddCtx = NULL;
5540
5541 ENTER();
5542
5543 hddLog(VOS_TRACE_LEVEL_INFO,
5544 "%s: device_mode = %d\n",__func__,pAdapter->device_mode);
5545
5546 if ( (WLAN_HDD_GET_CTX(pAdapter))->isLogpInProgress )
5547 {
5548 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5549 "%s:LOGP in Progress. Ignore!!!", __func__);
5550 return -EAGAIN;
5551 }
5552
5553#ifdef WLAN_BTAMP_FEATURE
5554 //Infra connect not supported when AMP traffic is on.
5555 if( VOS_TRUE == WLANBAP_AmpSessionOn() )
5556 {
5557 hddLog(VOS_TRACE_LEVEL_ERROR,
5558 "%s: No connection when AMP is on", __func__);
Madan Mohan Koyyalamudicae253a2012-11-06 19:10:35 -08005559 return -ECONNREFUSED;
Jeff Johnson295189b2012-06-20 16:38:30 -07005560 }
5561#endif
5562 /*initialise security parameters*/
5563 status = wlan_hdd_cfg80211_set_privacy(pAdapter, req);
5564
5565 if ( 0 > status)
5566 {
5567 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set security params",
5568 __func__);
5569 return status;
5570 }
5571
5572 //If Device Mode is Station Concurrent Sessions Exit BMps
Jeff Johnsona8a1a482012-12-12 16:49:33 -08005573 //P2P Mode will be taken care in Open/close adapter
Jeff Johnson295189b2012-06-20 16:38:30 -07005574 if((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) &&
5575 (vos_concurrent_sessions_running()))
5576 {
5577 v_CONTEXT_t pVosContext = vos_get_global_context( VOS_MODULE_ID_HDD, NULL );
5578
5579 if (NULL != pVosContext)
5580 {
5581 pHddCtx = vos_get_context( VOS_MODULE_ID_HDD, pVosContext);
5582 if(NULL != pHddCtx)
5583 {
5584 exitbmpsStatus = hdd_disable_bmps_imps(pHddCtx, WLAN_HDD_INFRA_STATION);
5585 }
5586 }
5587 }
5588
Mohit Khanna765234a2012-09-11 15:08:35 -07005589 if ( req->channel )
5590 {
5591 status = wlan_hdd_cfg80211_connect_start(pAdapter, req->ssid,
5592 req->ssid_len, req->bssid,
5593 req->channel->hw_value);
5594 }
5595 else
5596 {
5597 status = wlan_hdd_cfg80211_connect_start(pAdapter, req->ssid,
5598 req->ssid_len, req->bssid,
5599 0);
5600 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005601
5602 if (0 > status)
5603 {
5604 //ReEnable BMPS if disabled
5605 if((VOS_STATUS_SUCCESS == exitbmpsStatus) &&
5606 (NULL != pHddCtx))
5607 {
5608 //ReEnable Bmps and Imps back
5609 hdd_enable_bmps_imps(pHddCtx);
5610 }
5611
5612 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: connect failed", __func__);
5613 return status;
5614 }
5615 (WLAN_HDD_GET_CTX(pAdapter))->isAmpAllowed = VOS_FALSE;
5616 EXIT();
5617 return status;
5618}
5619
5620
5621/*
5622 * FUNCTION: wlan_hdd_cfg80211_disconnect
5623 * This function is used to issue a disconnect request to SME
5624 */
5625static int wlan_hdd_cfg80211_disconnect( struct wiphy *wiphy,
5626 struct net_device *dev,
5627 u16 reason
5628 )
5629{
5630 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
5631 tCsrRoamProfile *pRoamProfile =
5632 &(WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter))->roamProfile;
5633 int status = 0;
5634 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08005635#ifdef FEATURE_WLAN_TDLS
Gopichand Nakkala4327a152013-03-04 23:22:42 -08005636 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08005637 tANI_U8 staIdx;
5638#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005639
5640 ENTER();
5641
5642 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",
5643 __func__,pAdapter->device_mode);
5644
5645 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Disconnect called with reason code %d",
5646 __func__, reason);
5647
5648 if ((WLAN_HDD_GET_CTX(pAdapter))->isLogpInProgress)
5649 {
5650 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5651 "%s:LOGP in Progress. Ignore!!!",__func__);
5652 return -EAGAIN;
5653 }
5654 if (NULL != pRoamProfile)
5655 {
5656 /*issue disconnect request to SME, if station is in connected state*/
5657 if (pHddStaCtx->conn_info.connState == eConnectionState_Associated)
5658 {
5659 eCsrRoamDisconnectReason reasonCode =
5660 eCSR_DISCONNECT_REASON_UNSPECIFIED;
5661 switch(reason)
5662 {
5663 case WLAN_REASON_MIC_FAILURE:
5664 reasonCode = eCSR_DISCONNECT_REASON_MIC_ERROR;
5665 break;
5666
5667 case WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY:
5668 case WLAN_REASON_DISASSOC_AP_BUSY:
5669 case WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA:
5670 reasonCode = eCSR_DISCONNECT_REASON_DISASSOC;
5671 break;
5672
5673 case WLAN_REASON_PREV_AUTH_NOT_VALID:
5674 case WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA:
5675 reasonCode = eCSR_DISCONNECT_REASON_DEAUTH;
5676 break;
5677
5678 case WLAN_REASON_DEAUTH_LEAVING:
5679 default:
5680 reasonCode = eCSR_DISCONNECT_REASON_UNSPECIFIED;
5681 break;
5682 }
5683 pHddStaCtx->conn_info.connState = eConnectionState_NotConnected;
5684 (WLAN_HDD_GET_CTX(pAdapter))->isAmpAllowed = VOS_TRUE;
5685 INIT_COMPLETION(pAdapter->disconnect_comp_var);
5686
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08005687#ifdef FEATURE_WLAN_TDLS
5688 /* First clean up the tdls peers if any */
Gopichand Nakkala4327a152013-03-04 23:22:42 -08005689 for (staIdx = 0 ; staIdx < HDD_MAX_NUM_TDLS_STA; staIdx++)
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08005690 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08005691 if ((pHddCtx->tdlsConnInfo[staIdx].sessionId == pAdapter->sessionId) &&
5692 (pHddCtx->tdlsConnInfo[staIdx].staId))
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08005693 {
Hoonki Lee11f7dda2013-02-14 16:55:44 -08005694 uint8 *mac;
Gopichand Nakkala4327a152013-03-04 23:22:42 -08005695 mac = pHddCtx->tdlsConnInfo[staIdx].peerMac.bytes;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08005696 VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07005697 "%s: call sme_DeleteTdlsPeerSta staId %d sessionId %d " MAC_ADDRESS_STR,
Gopichand Nakkala4327a152013-03-04 23:22:42 -08005698 __func__, pHddCtx->tdlsConnInfo[staIdx].staId, pAdapter->sessionId,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07005699 MAC_ADDR_ARRAY(mac));
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08005700 sme_DeleteTdlsPeerSta(WLAN_HDD_GET_HAL_CTX(pAdapter),
Gopichand Nakkala4327a152013-03-04 23:22:42 -08005701 pAdapter->sessionId,
5702 mac);
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -08005703 }
5704 }
5705#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005706 /*issue disconnect*/
5707 status = sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter),
5708 pAdapter->sessionId, reasonCode);
5709
5710 if ( 0 != status)
5711 {
5712 hddLog(VOS_TRACE_LEVEL_ERROR,
5713 "%s csrRoamDisconnect failure, returned %d \n",
5714 __func__, (int)status );
5715 return -EINVAL;
5716 }
5717
5718 wait_for_completion_interruptible_timeout(
5719 &pAdapter->disconnect_comp_var,
5720 msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
5721
5722
5723 /*stop tx queues*/
5724 netif_tx_disable(dev);
5725 netif_carrier_off(dev);
5726 }
5727 }
5728 else
5729 {
5730 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: No valid roam profile", __func__);
5731 }
5732
5733 return status;
5734}
5735
5736/*
5737 * FUNCTION: wlan_hdd_cfg80211_set_privacy_ibss
5738 * This function is used to initialize the security
5739 * settings in IBSS mode.
5740 */
5741static int wlan_hdd_cfg80211_set_privacy_ibss(
5742 hdd_adapter_t *pAdapter,
5743 struct cfg80211_ibss_params *params
5744 )
5745{
5746 int status = 0;
5747 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
5748 eCsrEncryptionType encryptionType = eCSR_ENCRYPT_TYPE_NONE;
5749 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
5750
5751 ENTER();
5752
5753 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_DISABLED;
5754
5755 if (params->ie_len && ( NULL != params->ie) )
5756 {
5757 if (WLAN_EID_RSN == params->ie[0])
5758 {
5759 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA2;
5760 encryptionType = eCSR_ENCRYPT_TYPE_AES;
5761 }
5762 else
5763 {
5764 pWextState->wpaVersion = IW_AUTH_WPA_VERSION_WPA;
5765 encryptionType = eCSR_ENCRYPT_TYPE_TKIP;
5766 }
5767 status = wlan_hdd_cfg80211_set_ie(pAdapter, params->ie, params->ie_len);
5768
5769 if (0 > status)
5770 {
5771 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to parse WPA/RSN IE",
5772 __func__);
5773 return status;
5774 }
5775 }
5776
5777 pWextState->roamProfile.AuthType.authType[0] =
5778 pHddStaCtx->conn_info.authType =
5779 eCSR_AUTH_TYPE_OPEN_SYSTEM;
5780
5781 if (params->privacy)
5782 {
5783 /* Security enabled IBSS, At this time there is no information available
5784 * about the security paramters, so initialise the encryption type to
5785 * eCSR_ENCRYPT_TYPE_WEP40_STATICKEY.
5786 * The correct security parameters will be updated later in
5787 * wlan_hdd_cfg80211_add_key */
5788 /* Hal expects encryption type to be set inorder
5789 *enable privacy bit in beacons */
5790
5791 encryptionType = eCSR_ENCRYPT_TYPE_WEP40_STATICKEY;
5792 }
5793
5794 pHddStaCtx->conn_info.ucEncryptionType = encryptionType;
5795 pWextState->roamProfile.EncryptionType.numEntries = 1;
5796 pWextState->roamProfile.EncryptionType.encryptionType[0] = encryptionType;
5797
5798 return status;
5799}
5800
5801/*
5802 * FUNCTION: wlan_hdd_cfg80211_join_ibss
5803 * This function is used to create/join an IBSS
5804 */
5805static int wlan_hdd_cfg80211_join_ibss( struct wiphy *wiphy,
5806 struct net_device *dev,
5807 struct cfg80211_ibss_params *params
5808 )
5809{
5810 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
5811 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
5812 tCsrRoamProfile *pRoamProfile;
5813 int status;
5814 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
5815
5816 ENTER();
5817
5818 hddLog(VOS_TRACE_LEVEL_INFO,
5819 "%s: device_mode = %d\n",__func__,pAdapter->device_mode);
5820
5821 if ( (WLAN_HDD_GET_CTX(pAdapter))->isLogpInProgress )
5822 {
5823 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5824 "%s:LOGP in Progress. Ignore!!!", __func__);
5825 return -EAGAIN;
5826 }
5827
5828 if (NULL == pWextState)
5829 {
5830 hddLog (VOS_TRACE_LEVEL_ERROR, "%s ERROR: Data Storage Corruption\n",
5831 __func__);
5832 return -EIO;
5833 }
5834
5835 pRoamProfile = &pWextState->roamProfile;
5836
5837 if ( eCSR_BSS_TYPE_START_IBSS != pRoamProfile->BSSType )
5838 {
5839 hddLog (VOS_TRACE_LEVEL_ERROR,
5840 "%s Interface type is not set to IBSS \n", __func__);
5841 return -EINVAL;
5842 }
5843
5844 /* Set Channel */
5845 if (NULL != params->channel)
5846 {
5847 u8 channelNum;
5848 if (IEEE80211_BAND_5GHZ == params->channel->band)
5849 {
5850 hddLog(VOS_TRACE_LEVEL_ERROR,
5851 "%s: IBSS join is called with unsupported band %d",
5852 __func__, params->channel->band);
5853 return -EOPNOTSUPP;
5854 }
5855
5856 /* Get channel number */
5857 channelNum =
5858 ieee80211_frequency_to_channel(params->channel->center_freq);
5859
5860 /*TODO: use macro*/
5861 if (14 >= channelNum)
5862 {
5863 v_U32_t numChans = WNI_CFG_VALID_CHANNEL_LIST_LEN;
5864 v_U8_t validChan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
5865 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
5866 int indx;
5867
5868 if (0 != ccmCfgGetStr(hHal, WNI_CFG_VALID_CHANNEL_LIST,
5869 validChan, &numChans))
5870 {
5871 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: No valid channel list",
5872 __func__);
5873 return -EOPNOTSUPP;
5874 }
5875
5876 for (indx = 0; indx < numChans; indx++)
5877 {
5878 if (channelNum == validChan[indx])
5879 {
5880 break;
5881 }
5882 }
5883 if (indx >= numChans)
5884 {
5885 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Not valid Channel %d",
5886 __func__, channelNum);
5887 return -EINVAL;
5888 }
5889 /* Set the Operational Channel */
5890 hddLog(VOS_TRACE_LEVEL_INFO_HIGH, "%s: set channel %d", __func__,
5891 channelNum);
5892 pRoamProfile->ChannelInfo.numOfChannels = 1;
5893 pHddStaCtx->conn_info.operationChannel = channelNum;
5894 pRoamProfile->ChannelInfo.ChannelList =
5895 &pHddStaCtx->conn_info.operationChannel;
5896 }
5897 else
5898 {
5899 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Not valid Channel %hu",
5900 __func__, channelNum);
5901 return -EINVAL;
5902 }
5903 }
5904
5905 /* Initialize security parameters */
5906 status = wlan_hdd_cfg80211_set_privacy_ibss(pAdapter, params);
5907 if (status < 0)
5908 {
5909 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: failed to set security parameters",
5910 __func__);
5911 return status;
5912 }
5913
5914 /* Issue connect start */
5915 status = wlan_hdd_cfg80211_connect_start(pAdapter, params->ssid,
Jeff Johnson32d95a32012-09-10 13:15:23 -07005916 params->ssid_len, params->bssid, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005917
5918 if (0 > status)
5919 {
5920 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: connect failed", __func__);
5921 return status;
5922 }
5923
5924 return 0;
5925}
5926
5927/*
5928 * FUNCTION: wlan_hdd_cfg80211_leave_ibss
5929 * This function is used to leave an IBSS
5930 */
5931static int wlan_hdd_cfg80211_leave_ibss( struct wiphy *wiphy,
5932 struct net_device *dev
5933 )
5934{
5935 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
5936 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
5937 tCsrRoamProfile *pRoamProfile;
5938
5939 ENTER();
5940
Jeff Johnson04dd8a82012-06-29 20:41:40 -07005941 if ( (WLAN_HDD_GET_CTX(pAdapter))->isLogpInProgress )
5942 {
5943 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5944 "%s:LOGP in Progress. Ignore!!!", __func__);
5945 return -EAGAIN;
5946 }
5947
Jeff Johnson295189b2012-06-20 16:38:30 -07005948 hddLog(VOS_TRACE_LEVEL_INFO, "%s: device_mode = %d\n",__func__,pAdapter->device_mode);
5949 if (NULL == pWextState)
5950 {
5951 hddLog (VOS_TRACE_LEVEL_ERROR, "%s ERROR: Data Storage Corruption\n",
5952 __func__);
5953 return -EIO;
5954 }
5955
5956 pRoamProfile = &pWextState->roamProfile;
5957
5958 /* Issue disconnect only if interface type is set to IBSS */
5959 if (eCSR_BSS_TYPE_START_IBSS != pRoamProfile->BSSType)
5960 {
5961 hddLog (VOS_TRACE_LEVEL_ERROR, "%s: BSS Type is not set to IBSS",
5962 __func__);
5963 return -EINVAL;
5964 }
5965
5966 /* Issue Disconnect request */
5967 INIT_COMPLETION(pAdapter->disconnect_comp_var);
5968 sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter), pAdapter->sessionId,
5969 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
5970
5971 return 0;
5972}
5973
5974/*
5975 * FUNCTION: wlan_hdd_cfg80211_set_wiphy_params
5976 * This function is used to set the phy parameters
5977 * (RTS Threshold/FRAG Threshold/Retry Count etc ...)
5978 */
5979static int wlan_hdd_cfg80211_set_wiphy_params(struct wiphy *wiphy,
5980 u32 changed)
5981{
5982 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
5983 tHalHandle hHal = pHddCtx->hHal;
5984
5985 ENTER();
5986
Jeff Johnson04dd8a82012-06-29 20:41:40 -07005987 if ( pHddCtx->isLogpInProgress )
5988 {
5989 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
5990 "%s:LOGP in Progress. Ignore!!!", __func__);
5991 return -EAGAIN;
5992 }
5993
Jeff Johnson295189b2012-06-20 16:38:30 -07005994 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
5995 {
5996 u16 rts_threshold = (wiphy->rts_threshold == -1) ?
5997 WNI_CFG_RTS_THRESHOLD_STAMAX :
5998 wiphy->rts_threshold;
5999
6000 if ((WNI_CFG_RTS_THRESHOLD_STAMIN > rts_threshold) ||
6001 (WNI_CFG_RTS_THRESHOLD_STAMAX < rts_threshold))
6002 {
6003 hddLog(VOS_TRACE_LEVEL_ERROR,
6004 "%s: Invalid RTS Threshold value %hu",
6005 __func__, rts_threshold);
6006 return -EINVAL;
6007 }
6008
6009 if (0 != ccmCfgSetInt(hHal, WNI_CFG_RTS_THRESHOLD,
6010 rts_threshold, ccmCfgSetCallback,
6011 eANI_BOOLEAN_TRUE))
6012 {
6013 hddLog(VOS_TRACE_LEVEL_ERROR,
6014 "%s: ccmCfgSetInt failed for rts_threshold value %hu",
6015 __func__, rts_threshold);
6016 return -EIO;
6017 }
6018
6019 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set rts threshold %hu", __func__,
6020 rts_threshold);
6021 }
6022
6023 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
6024 {
6025 u16 frag_threshold = (wiphy->frag_threshold == -1) ?
6026 WNI_CFG_FRAGMENTATION_THRESHOLD_STAMAX :
6027 wiphy->frag_threshold;
6028
6029 if ((WNI_CFG_FRAGMENTATION_THRESHOLD_STAMIN > frag_threshold)||
6030 (WNI_CFG_FRAGMENTATION_THRESHOLD_STAMAX < frag_threshold) )
6031 {
6032 hddLog(VOS_TRACE_LEVEL_ERROR,
6033 "%s: Invalid frag_threshold value %hu", __func__,
6034 frag_threshold);
6035 return -EINVAL;
6036 }
6037
6038 if (0 != ccmCfgSetInt(hHal, WNI_CFG_FRAGMENTATION_THRESHOLD,
6039 frag_threshold, ccmCfgSetCallback,
6040 eANI_BOOLEAN_TRUE))
6041 {
6042 hddLog(VOS_TRACE_LEVEL_ERROR,
6043 "%s: ccmCfgSetInt failed for frag_threshold value %hu",
6044 __func__, frag_threshold);
6045 return -EIO;
6046 }
6047
6048 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set frag threshold %hu", __func__,
6049 frag_threshold);
6050 }
6051
6052 if ((changed & WIPHY_PARAM_RETRY_SHORT)
6053 || (changed & WIPHY_PARAM_RETRY_LONG))
6054 {
6055 u8 retry_value = (changed & WIPHY_PARAM_RETRY_SHORT) ?
6056 wiphy->retry_short :
6057 wiphy->retry_long;
6058
6059 if ((WNI_CFG_LONG_RETRY_LIMIT_STAMIN > retry_value) ||
6060 (WNI_CFG_LONG_RETRY_LIMIT_STAMAX < retry_value))
6061 {
6062 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid Retry count %hu",
6063 __func__, retry_value);
6064 return -EINVAL;
6065 }
6066
6067 if (changed & WIPHY_PARAM_RETRY_SHORT)
6068 {
6069 if (0 != ccmCfgSetInt(hHal, WNI_CFG_LONG_RETRY_LIMIT,
6070 retry_value, ccmCfgSetCallback,
6071 eANI_BOOLEAN_TRUE))
6072 {
6073 hddLog(VOS_TRACE_LEVEL_ERROR,
6074 "%s: ccmCfgSetInt failed for long retry count %hu",
6075 __func__, retry_value);
6076 return -EIO;
6077 }
6078 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set long retry count %hu",
6079 __func__, retry_value);
6080 }
6081 else if (changed & WIPHY_PARAM_RETRY_SHORT)
6082 {
6083 if (0 != ccmCfgSetInt(hHal, WNI_CFG_SHORT_RETRY_LIMIT,
6084 retry_value, ccmCfgSetCallback,
6085 eANI_BOOLEAN_TRUE))
6086 {
6087 hddLog(VOS_TRACE_LEVEL_ERROR,
6088 "%s: ccmCfgSetInt failed for short retry count %hu",
6089 __func__, retry_value);
6090 return -EIO;
6091 }
6092 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set short retry count %hu",
6093 __func__, retry_value);
6094 }
6095 }
6096
6097 return 0;
6098}
6099
6100/*
6101 * FUNCTION: wlan_hdd_cfg80211_set_txpower
6102 * This function is used to set the txpower
6103 */
6104static int wlan_hdd_cfg80211_set_txpower(struct wiphy *wiphy,
6105#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,35)
6106 enum tx_power_setting type,
6107#else
6108 enum nl80211_tx_power_setting type,
6109#endif
6110 int dbm)
6111{
6112 hdd_context_t *pHddCtx = (hdd_context_t*) wiphy_priv(wiphy);
6113 tHalHandle hHal = pHddCtx->hHal;
6114 tSirMacAddr bssid = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
6115 tSirMacAddr selfMac = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
6116
6117 ENTER();
6118
6119 if (0 != ccmCfgSetInt(hHal, WNI_CFG_CURRENT_TX_POWER_LEVEL,
6120 dbm, ccmCfgSetCallback,
6121 eANI_BOOLEAN_TRUE))
6122 {
6123 hddLog(VOS_TRACE_LEVEL_ERROR,
6124 "%s: ccmCfgSetInt failed for tx power %hu", __func__, dbm);
6125 return -EIO;
6126 }
6127
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006128 if ( pHddCtx->isLogpInProgress )
6129 {
6130 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6131 "%s:LOGP in Progress. Ignore!!!", __func__);
6132 return -EAGAIN;
6133 }
6134
Jeff Johnson295189b2012-06-20 16:38:30 -07006135 hddLog(VOS_TRACE_LEVEL_INFO_MED, "%s: set tx power level %d dbm", __func__,
6136 dbm);
6137
6138 switch(type)
6139 {
6140 case NL80211_TX_POWER_AUTOMATIC: /*automatically determine transmit power*/
6141 /* Fall through */
6142 case NL80211_TX_POWER_LIMITED: /*limit TX power by the mBm parameter*/
6143 if( sme_SetMaxTxPower(hHal, bssid, selfMac, dbm) != eHAL_STATUS_SUCCESS )
6144 {
6145 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Setting maximum tx power failed",
6146 __func__);
6147 return -EIO;
6148 }
6149 break;
6150 case NL80211_TX_POWER_FIXED: /*fix TX power to the mBm parameter*/
6151 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: NL80211_TX_POWER_FIXED not supported",
6152 __func__);
6153 return -EOPNOTSUPP;
6154 break;
6155 default:
6156 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Invalid power setting type %d",
6157 __func__, type);
6158 return -EIO;
6159 }
6160
6161 return 0;
6162}
6163
6164/*
6165 * FUNCTION: wlan_hdd_cfg80211_get_txpower
6166 * This function is used to read the txpower
6167 */
6168static int wlan_hdd_cfg80211_get_txpower(struct wiphy *wiphy, int *dbm)
6169{
6170
6171 hdd_adapter_t *pAdapter;
6172 hdd_context_t *pHddCtx = (hdd_context_t*) wiphy_priv(wiphy);
6173
Jeff Johnsone7245742012-09-05 17:12:55 -07006174 ENTER();
6175
Jeff Johnson295189b2012-06-20 16:38:30 -07006176 if (NULL == pHddCtx)
6177 {
6178 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: HDD context is Null",__func__);
6179 *dbm = 0;
6180 return -ENOENT;
6181 }
6182
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006183 if ( pHddCtx->isLogpInProgress )
6184 {
6185 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6186 "%s:LOGP in Progress. Ignore!!!", __func__);
6187 return -EAGAIN;
6188 }
6189
Jeff Johnson295189b2012-06-20 16:38:30 -07006190 pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_INFRA_STATION);
6191 if (NULL == pAdapter)
6192 {
6193 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Not in station context " ,__func__);
6194 return -ENOENT;
6195 }
6196
6197 wlan_hdd_get_classAstats(pAdapter);
6198 *dbm = pAdapter->hdd_stats.ClassA_stat.max_pwr;
6199
Jeff Johnsone7245742012-09-05 17:12:55 -07006200 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07006201 return 0;
6202}
6203
6204static int wlan_hdd_cfg80211_get_station(struct wiphy *wiphy, struct net_device *dev,
6205 u8* mac, struct station_info *sinfo)
6206{
6207 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR( dev );
6208 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
6209 int ssidlen = pHddStaCtx->conn_info.SSID.SSID.length;
6210 tANI_U8 rate_flags;
6211
6212 hdd_context_t *pHddCtx = (hdd_context_t*) wiphy_priv(wiphy);
6213 hdd_config_t *pCfg = pHddCtx->cfg_ini;
Jeff Johnson295189b2012-06-20 16:38:30 -07006214
6215 tANI_U8 OperationalRates[CSR_DOT11_SUPPORTED_RATES_MAX];
6216 tANI_U32 ORLeng = CSR_DOT11_SUPPORTED_RATES_MAX;
6217 tANI_U8 ExtendedRates[CSR_DOT11_EXTENDED_SUPPORTED_RATES_MAX];
6218 tANI_U32 ERLeng = CSR_DOT11_EXTENDED_SUPPORTED_RATES_MAX;
6219 tANI_U8 MCSRates[SIZE_OF_BASIC_MCS_SET];
6220 tANI_U32 MCSLeng = SIZE_OF_BASIC_MCS_SET;
6221 tANI_U16 maxRate = 0;
6222 tANI_U16 myRate;
6223 tANI_U16 currentRate = 0;
6224 tANI_U8 maxSpeedMCS = 0;
6225 tANI_U8 maxMCSIdx = 0;
6226 tANI_U8 rateFlag = 1;
6227 tANI_U8 i, j, rssidx;
Madan Mohan Koyyalamudic75be962012-10-18 19:19:03 -07006228 tANI_U16 temp;
Jeff Johnson295189b2012-06-20 16:38:30 -07006229
Leo Chang6f8870f2013-03-26 18:11:36 -07006230#ifdef WLAN_FEATURE_11AC
6231 tANI_U32 vht_mcs_map;
6232 eDataRate11ACMaxMcs vhtMaxMcs;
6233#endif /* WLAN_FEATURE_11AC */
6234
Jeff Johnsone7245742012-09-05 17:12:55 -07006235 ENTER();
6236
Jeff Johnson295189b2012-06-20 16:38:30 -07006237 if ((eConnectionState_Associated != pHddStaCtx->conn_info.connState) ||
6238 (0 == ssidlen))
6239 {
6240 hddLog(VOS_TRACE_LEVEL_INFO, "%s: Not associated or"
6241 " Invalid ssidlen, %d", __func__, ssidlen);
6242 /*To keep GUI happy*/
6243 return 0;
6244 }
6245
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006246 if ( (WLAN_HDD_GET_CTX(pAdapter))->isLogpInProgress )
6247 {
6248 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6249 "%s:LOGP in Progress. Ignore!!!", __func__);
6250 return -EAGAIN;
6251 }
6252
Jeff Johnson295189b2012-06-20 16:38:30 -07006253 wlan_hdd_get_rssi(pAdapter, &sinfo->signal);
6254 sinfo->filled |= STATION_INFO_SIGNAL;
6255
Madan Mohan Koyyalamudi4d4d2812012-09-24 14:08:29 -07006256 wlan_hdd_get_station_stats(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -07006257 rate_flags = pAdapter->hdd_stats.ClassA_stat.tx_rate_flags;
6258
6259 //convert to the UI units of 100kbps
6260 myRate = pAdapter->hdd_stats.ClassA_stat.tx_rate * 5;
6261
6262#ifdef LINKSPEED_DEBUG_ENABLED
Leo Chang6f8870f2013-03-26 18:11:36 -07006263 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 -07006264 sinfo->signal,
6265 pCfg->reportMaxLinkSpeed,
6266 myRate,
6267 (int) pCfg->linkSpeedRssiHigh,
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07006268 (int) pCfg->linkSpeedRssiMid,
6269 (int) pCfg->linkSpeedRssiLow,
Leo Chang6f8870f2013-03-26 18:11:36 -07006270 (int) rate_flags,
6271 (int) pAdapter->hdd_stats.ClassA_stat.mcs_index);
Jeff Johnson295189b2012-06-20 16:38:30 -07006272#endif //LINKSPEED_DEBUG_ENABLED
6273
6274 if (eHDD_LINK_SPEED_REPORT_ACTUAL != pCfg->reportMaxLinkSpeed)
6275 {
6276 // we do not want to necessarily report the current speed
6277 if (eHDD_LINK_SPEED_REPORT_MAX == pCfg->reportMaxLinkSpeed)
6278 {
6279 // report the max possible speed
6280 rssidx = 0;
6281 }
6282 else if (eHDD_LINK_SPEED_REPORT_MAX_SCALED == pCfg->reportMaxLinkSpeed)
6283 {
6284 // report the max possible speed with RSSI scaling
6285 if (sinfo->signal >= pCfg->linkSpeedRssiHigh)
6286 {
6287 // report the max possible speed
6288 rssidx = 0;
6289 }
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07006290 else if (sinfo->signal >= pCfg->linkSpeedRssiMid)
Jeff Johnson295189b2012-06-20 16:38:30 -07006291 {
6292 // report middle speed
6293 rssidx = 1;
6294 }
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07006295 else if (sinfo->signal >= pCfg->linkSpeedRssiLow)
6296 {
6297 // report middle speed
6298 rssidx = 2;
6299 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006300 else
6301 {
6302 // report actual speed
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07006303 rssidx = 3;
Jeff Johnson295189b2012-06-20 16:38:30 -07006304 }
6305 }
6306 else
6307 {
6308 // unknown, treat as eHDD_LINK_SPEED_REPORT_MAX
6309 hddLog(VOS_TRACE_LEVEL_ERROR,
6310 "%s: Invalid value for reportMaxLinkSpeed: %u",
6311 __func__, pCfg->reportMaxLinkSpeed);
6312 rssidx = 0;
6313 }
6314
6315 maxRate = 0;
6316
6317 /* Get Basic Rate Set */
Gopichand Nakkala05ab1322013-02-15 11:28:38 +05306318 if (0 != ccmCfgGetStr(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_OPERATIONAL_RATE_SET,
6319 OperationalRates, &ORLeng))
6320 {
6321 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: ccm api returned failure", __func__);
6322 /*To keep GUI happy*/
6323 return 0;
6324 }
6325
Jeff Johnson295189b2012-06-20 16:38:30 -07006326 for (i = 0; i < ORLeng; i++)
6327 {
Jeff Johnsone7245742012-09-05 17:12:55 -07006328 for (j = 0; j < (sizeof(supported_data_rate) / sizeof(supported_data_rate[0])); j ++)
Jeff Johnson295189b2012-06-20 16:38:30 -07006329 {
6330 /* Validate Rate Set */
6331 if (supported_data_rate[j].beacon_rate_index == (OperationalRates[i] & 0x7F))
6332 {
6333 currentRate = supported_data_rate[j].supported_rate[rssidx];
6334 break;
6335 }
6336 }
6337 /* Update MAX rate */
6338 maxRate = (currentRate > maxRate)?currentRate:maxRate;
6339 }
6340
6341 /* Get Extended Rate Set */
Gopichand Nakkala05ab1322013-02-15 11:28:38 +05306342 if (0 != ccmCfgGetStr(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_EXTENDED_OPERATIONAL_RATE_SET,
6343 ExtendedRates, &ERLeng))
6344 {
6345 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: ccm api returned failure", __func__);
6346 /*To keep GUI happy*/
6347 return 0;
6348 }
6349
Jeff Johnson295189b2012-06-20 16:38:30 -07006350 for (i = 0; i < ERLeng; i++)
6351 {
Jeff Johnsone7245742012-09-05 17:12:55 -07006352 for (j = 0; j < (sizeof(supported_data_rate) / sizeof(supported_data_rate[0])); j ++)
Jeff Johnson295189b2012-06-20 16:38:30 -07006353 {
6354 if (supported_data_rate[j].beacon_rate_index == (ExtendedRates[i] & 0x7F))
6355 {
6356 currentRate = supported_data_rate[j].supported_rate[rssidx];
6357 break;
6358 }
6359 }
6360 /* Update MAX rate */
6361 maxRate = (currentRate > maxRate)?currentRate:maxRate;
6362 }
6363
6364 /* Get MCS Rate Set -- but only if we are connected at MCS
6365 rates or if we are always reporting max speed or if we have
6366 good rssi */
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07006367 if ((0 == rssidx) && !(rate_flags & eHAL_TX_RATE_LEGACY))
Jeff Johnson295189b2012-06-20 16:38:30 -07006368 {
Gopichand Nakkala05ab1322013-02-15 11:28:38 +05306369 if (0 != ccmCfgGetStr(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_CURRENT_MCS_SET,
6370 MCSRates, &MCSLeng))
6371 {
6372 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: ccm api returned failure", __func__);
6373 /*To keep GUI happy*/
6374 return 0;
6375 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006376 rateFlag = 0;
Leo Chang6f8870f2013-03-26 18:11:36 -07006377#ifdef WLAN_FEATURE_11AC
6378 /* VHT80 rate has seperate rate table */
6379 if (rate_flags & eHAL_TX_RATE_VHT80)
Jeff Johnson295189b2012-06-20 16:38:30 -07006380 {
Leo Chang6f8870f2013-03-26 18:11:36 -07006381 currentRate = supported_vht_mcs_rate[pAdapter->hdd_stats.ClassA_stat.mcs_index].supported_rate[rateFlag];
6382 ccmCfgGetInt(WLAN_HDD_GET_HAL_CTX(pAdapter), WNI_CFG_VHT_TX_MCS_MAP, &vht_mcs_map);
6383 if (rate_flags & eHAL_TX_RATE_SGI)
Jeff Johnson295189b2012-06-20 16:38:30 -07006384 {
Leo Chang6f8870f2013-03-26 18:11:36 -07006385 rateFlag |= 1;
Jeff Johnson295189b2012-06-20 16:38:30 -07006386 }
Leo Chang6f8870f2013-03-26 18:11:36 -07006387 vhtMaxMcs = (eDataRate11ACMaxMcs)(vht_mcs_map & DATA_RATE_11AC_MCS_MASK);
6388 if (DATA_RATE_11AC_MAX_MCS_7 == vhtMaxMcs)
Jeff Johnson295189b2012-06-20 16:38:30 -07006389 {
Leo Chang6f8870f2013-03-26 18:11:36 -07006390 maxMCSIdx = 7;
6391 }
6392 else if (DATA_RATE_11AC_MAX_MCS_8 == vhtMaxMcs)
6393 {
6394 maxMCSIdx = 8;
6395 }
6396 else if (DATA_RATE_11AC_MAX_MCS_9 == vhtMaxMcs)
6397 {
6398 maxMCSIdx = 9;
6399 }
6400 maxRate = supported_vht_mcs_rate[maxMCSIdx].supported_rate[rateFlag];
6401 maxSpeedMCS = 1;
6402 if (currentRate > maxRate)
6403 {
6404 maxRate = currentRate;
6405 }
6406 }
6407 else
6408#endif /* WLAN_FEATURE_11AC */
6409 {
6410 if (rate_flags & eHAL_TX_RATE_HT40)
6411 {
6412 rateFlag |= 1;
6413 }
6414 if (rate_flags & eHAL_TX_RATE_SGI)
6415 {
6416 rateFlag |= 2;
6417 }
6418
6419 for (i = 0; i < MCSLeng; i++)
6420 {
6421 temp = sizeof(supported_mcs_rate) / sizeof(supported_mcs_rate[0]);
6422 for (j = 0; j < temp; j++)
6423 {
6424 if (supported_mcs_rate[j].beacon_rate_index == MCSRates[i])
6425 {
6426 currentRate = supported_mcs_rate[j].supported_rate[rateFlag];
6427 break;
6428 }
6429 }
6430 if ((j < temp) && (currentRate > maxRate))
6431 {
6432 maxRate = currentRate;
6433 maxSpeedMCS = 1;
6434 maxMCSIdx = supported_mcs_rate[j].beacon_rate_index;
6435 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006436 }
6437 }
6438 }
6439
6440 // make sure we report a value at least as big as our current rate
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07006441 if (((maxRate < myRate) && (0 == rssidx)) ||
6442 (0 == maxRate))
Jeff Johnson295189b2012-06-20 16:38:30 -07006443 {
6444 maxRate = myRate;
6445 if (rate_flags & eHAL_TX_RATE_LEGACY)
6446 {
6447 maxSpeedMCS = 0;
6448 }
6449 else
6450 {
6451 maxSpeedMCS = 1;
6452 maxMCSIdx = pAdapter->hdd_stats.ClassA_stat.mcs_index;
6453 }
6454 }
6455
Madan Mohan Koyyalamudi8df78d52012-11-02 12:30:06 -07006456 if ((!maxSpeedMCS) || (0 != rssidx))
Jeff Johnson295189b2012-06-20 16:38:30 -07006457 {
6458 sinfo->txrate.legacy = maxRate;
6459#ifdef LINKSPEED_DEBUG_ENABLED
6460 pr_info("Reporting legacy rate %d\n", sinfo->txrate.legacy);
6461#endif //LINKSPEED_DEBUG_ENABLED
6462 }
6463 else
6464 {
6465 sinfo->txrate.mcs = maxMCSIdx;
Leo Chang6f8870f2013-03-26 18:11:36 -07006466#ifdef WLAN_FEATURE_11AC
6467 sinfo->txrate.nss = 1;
6468 if (rate_flags & eHAL_TX_RATE_VHT80)
6469 {
6470 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
6471 }
6472 else
6473#endif /* WLAN_FEATURE_11AC */
6474 {
6475 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
6476 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006477 if (rate_flags & eHAL_TX_RATE_SGI)
6478 {
6479 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
6480 }
6481 if (rate_flags & eHAL_TX_RATE_HT40)
6482 {
6483 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
6484 }
Leo Chang6f8870f2013-03-26 18:11:36 -07006485#ifdef WLAN_FEATURE_11AC
6486 else if (rate_flags & eHAL_TX_RATE_VHT80)
6487 {
6488 sinfo->txrate.flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
6489 }
6490#endif /* WLAN_FEATURE_11AC */
Jeff Johnson295189b2012-06-20 16:38:30 -07006491#ifdef LINKSPEED_DEBUG_ENABLED
6492 pr_info("Reporting MCS rate %d flags %x\n",
6493 sinfo->txrate.mcs,
6494 sinfo->txrate.flags );
6495#endif //LINKSPEED_DEBUG_ENABLED
6496 }
6497 }
6498 else
6499 {
6500 // report current rate instead of max rate
6501
6502 if (rate_flags & eHAL_TX_RATE_LEGACY)
6503 {
6504 //provide to the UI in units of 100kbps
6505 sinfo->txrate.legacy = myRate;
6506#ifdef LINKSPEED_DEBUG_ENABLED
6507 pr_info("Reporting actual legacy rate %d\n", sinfo->txrate.legacy);
6508#endif //LINKSPEED_DEBUG_ENABLED
6509 }
6510 else
6511 {
6512 //must be MCS
6513 sinfo->txrate.mcs = pAdapter->hdd_stats.ClassA_stat.mcs_index;
Leo Chang6f8870f2013-03-26 18:11:36 -07006514#ifdef WLAN_FEATURE_11AC
6515 sinfo->txrate.nss = 1;
6516 if (rate_flags & eHAL_TX_RATE_VHT80)
6517 {
6518 sinfo->txrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
6519 }
6520 else
6521#endif /* WLAN_FEATURE_11AC */
6522 {
6523 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
6524 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006525 if (rate_flags & eHAL_TX_RATE_SGI)
6526 {
6527 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
6528 }
6529 if (rate_flags & eHAL_TX_RATE_HT40)
6530 {
6531 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
6532 }
Leo Chang6f8870f2013-03-26 18:11:36 -07006533#ifdef WLAN_FEATURE_11AC
6534 else if (rate_flags & eHAL_TX_RATE_VHT80)
6535 {
6536 sinfo->txrate.flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
6537 }
6538#endif /* WLAN_FEATURE_11AC */
Jeff Johnson295189b2012-06-20 16:38:30 -07006539#ifdef LINKSPEED_DEBUG_ENABLED
6540 pr_info("Reporting actual MCS rate %d flags %x\n",
6541 sinfo->txrate.mcs,
6542 sinfo->txrate.flags );
6543#endif //LINKSPEED_DEBUG_ENABLED
6544 }
6545 }
6546 sinfo->filled |= STATION_INFO_TX_BITRATE;
6547
Madan Mohan Koyyalamudi4d4d2812012-09-24 14:08:29 -07006548 sinfo->tx_packets =
6549 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[0] +
6550 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[1] +
6551 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[2] +
6552 pAdapter->hdd_stats.summary_stat.tx_frm_cnt[3];
6553
6554 sinfo->tx_retries =
6555 pAdapter->hdd_stats.summary_stat.retry_cnt[0] +
6556 pAdapter->hdd_stats.summary_stat.retry_cnt[1] +
6557 pAdapter->hdd_stats.summary_stat.retry_cnt[2] +
6558 pAdapter->hdd_stats.summary_stat.retry_cnt[3];
6559
6560 sinfo->tx_failed =
6561 pAdapter->hdd_stats.summary_stat.fail_cnt[0] +
6562 pAdapter->hdd_stats.summary_stat.fail_cnt[1] +
6563 pAdapter->hdd_stats.summary_stat.fail_cnt[2] +
6564 pAdapter->hdd_stats.summary_stat.fail_cnt[3];
6565
6566 sinfo->filled |=
6567 STATION_INFO_TX_PACKETS |
6568 STATION_INFO_TX_RETRIES |
6569 STATION_INFO_TX_FAILED;
6570
6571 EXIT();
6572 return 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07006573}
6574
6575static int wlan_hdd_cfg80211_set_power_mgmt(struct wiphy *wiphy,
6576 struct net_device *dev, bool mode, v_SINT_t timeout)
6577{
6578 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
6579 VOS_STATUS vos_status;
6580
Jeff Johnsone7245742012-09-05 17:12:55 -07006581 ENTER();
6582
Jeff Johnson295189b2012-06-20 16:38:30 -07006583 if (NULL == pAdapter)
6584 {
6585 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Adapter is NULL\n", __func__);
6586 return -ENODEV;
6587 }
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006588 if ( (WLAN_HDD_GET_CTX(pAdapter))->isLogpInProgress )
6589 {
6590 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6591 "%s:LOGP in Progress. Ignore!!!", __func__);
6592 return -EAGAIN;
6593 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006594
6595 /**The get power cmd from the supplicant gets updated by the nl only
6596 *on successful execution of the function call
6597 *we are oppositely mapped w.r.t mode in the driver
6598 **/
6599 vos_status = wlan_hdd_enter_bmps(pAdapter, !mode);
6600
Jeff Johnsone7245742012-09-05 17:12:55 -07006601 EXIT();
Jeff Johnson295189b2012-06-20 16:38:30 -07006602 if (VOS_STATUS_E_FAILURE == vos_status)
6603 {
6604 return -EINVAL;
6605 }
6606 return 0;
6607}
6608
6609
6610#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
6611static int wlan_hdd_set_default_mgmt_key(struct wiphy *wiphy,
6612 struct net_device *netdev,
6613 u8 key_index)
6614{
Jeff Johnsone7245742012-09-05 17:12:55 -07006615 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07006616 return 0;
6617}
6618#endif //LINUX_VERSION_CODE
6619
6620#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
6621static int wlan_hdd_set_txq_params(struct wiphy *wiphy,
6622 struct net_device *dev,
6623 struct ieee80211_txq_params *params)
6624{
Jeff Johnsone7245742012-09-05 17:12:55 -07006625 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07006626 return 0;
6627}
6628#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
6629static int wlan_hdd_set_txq_params(struct wiphy *wiphy,
6630 struct ieee80211_txq_params *params)
6631{
Jeff Johnsone7245742012-09-05 17:12:55 -07006632 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07006633 return 0;
6634}
6635#endif //LINUX_VERSION_CODE
6636
6637static int wlan_hdd_cfg80211_del_station(struct wiphy *wiphy,
6638 struct net_device *dev, u8 *mac)
6639{
6640 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08006641 VOS_STATUS vos_status;
6642 v_U8_t staId;
Jeff Johnson295189b2012-06-20 16:38:30 -07006643
Jeff Johnsone7245742012-09-05 17:12:55 -07006644 ENTER();
Jeff Johnson295189b2012-06-20 16:38:30 -07006645 if ( NULL == pAdapter || NULL == pAdapter->pHddCtx)
6646 {
6647 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Invalid Adapter or HDD Context " ,__func__);
6648 return -EINVAL;
6649 }
6650
6651 if (((hdd_context_t*)pAdapter->pHddCtx)->isLoadUnloadInProgress)
6652 {
6653 hddLog( LOGE,
6654 "%s: Wlan Load/Unload is in progress", __func__);
6655 return -EBUSY;
6656 }
6657
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006658 if ( (WLAN_HDD_GET_CTX(pAdapter))->isLogpInProgress )
6659 {
6660 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6661 "%s:LOGP in Progress. Ignore!!!", __func__);
6662 return -EAGAIN;
6663 }
6664
Jeff Johnson295189b2012-06-20 16:38:30 -07006665 if ( (WLAN_HDD_SOFTAP == pAdapter->device_mode)
Jeff Johnson295189b2012-06-20 16:38:30 -07006666 || (WLAN_HDD_P2P_GO == pAdapter->device_mode)
Jeff Johnson295189b2012-06-20 16:38:30 -07006667 )
6668 {
6669 if( NULL == mac )
6670 {
6671 v_U16_t i;
6672 for(i = 0; i < WLAN_MAX_STA_COUNT; i++)
6673 {
6674 if(pAdapter->aStaInfo[i].isUsed)
6675 {
6676 u8 *macAddr = pAdapter->aStaInfo[i].macAddrSTA.bytes;
6677 hddLog(VOS_TRACE_LEVEL_INFO,
6678 "%s: Delete STA with MAC::"
6679 "%02x:%02x:%02x:%02x:%02x:%02x",
6680 __func__,
6681 macAddr[0], macAddr[1], macAddr[2],
6682 macAddr[3], macAddr[4], macAddr[5]);
6683 hdd_softap_sta_deauth(pAdapter, macAddr);
6684 }
6685 }
6686 }
6687 else
6688 {
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08006689
6690 vos_status = hdd_softap_GetStaId(pAdapter,(v_MACADDR_t *)mac, &staId);
6691 if (!VOS_IS_STATUS_SUCCESS(vos_status))
6692 {
6693 hddLog(VOS_TRACE_LEVEL_INFO,
6694 "%s: Skip this DEL STA as this is not used::"
6695 "%02x:%02x:%02x:%02x:%02x:%02x",
6696 __func__,
6697 mac[0], mac[1], mac[2],
6698 mac[3], mac[4], mac[5]);
6699 return -ENOENT;
6700 }
6701
6702 if( pAdapter->aStaInfo[staId].isDeauthInProgress == TRUE)
6703 {
6704 hddLog(VOS_TRACE_LEVEL_INFO,
6705 "%s: Skip this DEL STA as deauth is in progress::"
6706 "%02x:%02x:%02x:%02x:%02x:%02x",
6707 __func__,
6708 mac[0], mac[1], mac[2],
6709 mac[3], mac[4], mac[5]);
6710 return -ENOENT;
6711 }
6712
6713 pAdapter->aStaInfo[staId].isDeauthInProgress = TRUE;
6714
Jeff Johnson295189b2012-06-20 16:38:30 -07006715 hddLog(VOS_TRACE_LEVEL_INFO,
6716 "%s: Delete STA with MAC::"
6717 "%02x:%02x:%02x:%02x:%02x:%02x",
6718 __func__,
6719 mac[0], mac[1], mac[2],
6720 mac[3], mac[4], mac[5]);
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08006721
6722 vos_status = hdd_softap_sta_deauth(pAdapter, mac);
6723 if (!VOS_IS_STATUS_SUCCESS(vos_status))
6724 {
6725 pAdapter->aStaInfo[staId].isDeauthInProgress = FALSE;
6726 hddLog(VOS_TRACE_LEVEL_INFO,
6727 "%s: STA removal failed for ::"
6728 "%02x:%02x:%02x:%02x:%02x:%02x",
6729 __func__,
6730 mac[0], mac[1], mac[2],
6731 mac[3], mac[4], mac[5]);
6732 return -ENOENT;
6733 }
6734
Jeff Johnson295189b2012-06-20 16:38:30 -07006735 }
6736 }
6737
6738 EXIT();
6739
6740 return 0;
6741}
6742
Hoonki Lee11f7dda2013-02-14 16:55:44 -08006743static int wlan_hdd_cfg80211_add_station(struct wiphy *wiphy,
6744 struct net_device *dev, u8 *mac, struct station_parameters *params)
6745{
Gopichand Nakkalab977a972013-02-18 19:15:09 -08006746 int status = -EPERM;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08006747#ifdef FEATURE_WLAN_TDLS
6748 u32 mask, set;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08006749 ENTER();
Mohit Khanna698ba2a2012-12-04 15:08:18 -08006750 mask = params->sta_flags_mask;
6751
6752 set = params->sta_flags_set;
6753
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07006754#ifdef WLAN_FEATURE_TDLS_DEBUG
6755 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6756 "%s: mask 0x%x set 0x%x " MAC_ADDRESS_STR,
6757 __func__, mask, set, MAC_ADDR_ARRAY(mac));
6758#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -08006759
6760 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
6761 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
Gopichand Nakkala681989c2013-03-06 22:27:48 -08006762 status = wlan_hdd_tdls_add_station(wiphy, dev, mac, 0, NULL);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08006763 }
6764 }
6765#endif
Gopichand Nakkalab977a972013-02-18 19:15:09 -08006766 return status;
Jeff Johnson295189b2012-06-20 16:38:30 -07006767}
6768
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006769
6770#ifdef FEATURE_WLAN_LFR
6771static int wlan_hdd_cfg80211_set_pmksa(struct wiphy *wiphy, struct net_device *dev,
Jeff Johnsond13512a2012-07-17 11:42:19 -07006772 struct cfg80211_pmksa *pmksa)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006773{
6774#define MAX_PMKSAIDS_IN_CACHE 8
6775 static tPmkidCacheInfo PMKIDCache[MAX_PMKSAIDS_IN_CACHE]; // HDD Local cache
Madan Mohan Koyyalamudidfd6aa82012-10-18 20:18:43 -07006776 static tANI_U32 i; // HDD Local Cache index
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006777 tANI_U32 j=0;
6778 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
6779 tHalHandle halHandle;
6780 eHalStatus result;
6781 tANI_U8 BSSIDMatched = 0;
6782
Jeff Johnsone7245742012-09-05 17:12:55 -07006783 ENTER();
6784
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006785 // Validate pAdapter
6786 if ( NULL == pAdapter || NULL == pAdapter->pHddCtx)
6787 {
6788 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Invalid Adapter or HDD Context " ,__func__);
6789 return -EINVAL;
6790 }
6791
6792 if (((hdd_context_t*)pAdapter->pHddCtx)->isLoadUnloadInProgress)
6793 {
6794 hddLog( LOGE,
6795 "%s: Wlan Load/Unload is in progress", __func__);
6796 return -EBUSY;
6797 }
6798
6799 if ( (WLAN_HDD_GET_CTX(pAdapter))->isLogpInProgress )
6800 {
6801 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6802 "%s:LOGP in Progress. Ignore!!!", __func__);
6803 return -EAGAIN;
6804 }
6805
6806 // Retrieve halHandle
6807 halHandle = WLAN_HDD_GET_HAL_CTX(pAdapter);
6808
6809 for (j = 0; j < i; j++)
6810 {
6811 if(vos_mem_compare(PMKIDCache[j].BSSID,
6812 pmksa->bssid, WNI_CFG_BSSID_LEN))
6813 {
6814 /* BSSID matched previous entry. Overwrite it. */
6815 BSSIDMatched = 1;
6816 vos_mem_copy(PMKIDCache[j].BSSID,
6817 pmksa->bssid, WNI_CFG_BSSID_LEN);
6818 vos_mem_copy(PMKIDCache[j].PMKID,
6819 pmksa->pmkid,
6820 CSR_RSN_PMKID_SIZE);
6821 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Reusing cache entry %d.",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07006822 __func__, j );
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006823 dump_bssid(pmksa->bssid);
6824 dump_pmkid(halHandle, pmksa->pmkid);
6825 break;
6826 }
6827 }
6828
Madan Mohan Koyyalamudic4b317d2012-10-18 19:43:08 -07006829 /* Check we compared all entries,if then take the first slot now */
6830 if(j == MAX_PMKSAIDS_IN_CACHE) i=0;
6831
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006832 if (!BSSIDMatched)
6833 {
6834 // Now, we DON'T have a BSSID match, so take a new entry in the cache.
6835 vos_mem_copy(PMKIDCache[i].BSSID,
6836 pmksa->bssid, ETHER_ADDR_LEN);
6837 vos_mem_copy(PMKIDCache[i].PMKID,
6838 pmksa->pmkid,
6839 CSR_RSN_PMKID_SIZE);
6840 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Adding a new cache entry %d.",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07006841 __func__, i );
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006842 dump_bssid(pmksa->bssid);
6843 dump_pmkid(halHandle, pmksa->pmkid);
6844 // Increment the HDD Local Cache index
6845 // The "i=0" doesn't work for the call to sme_RoamSetPMKIDCache() - LFR FIXME
6846 if (i<=(MAX_PMKSAIDS_IN_CACHE-1)) i++; else i=0;
6847 }
6848
6849
6850 // Calling csrRoamSetPMKIDCache to configure the PMKIDs into the cache
6851 //hddLog(LOG1, FL("%s: Calling csrRoamSetPMKIDCache with %d cache entries."),
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07006852 // __func__, i );
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006853 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: Calling csrRoamSetPMKIDCache with %d cache entries.",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07006854 __func__, i );
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006855 // Finally set the PMKSA ID Cache in CSR
6856 result = sme_RoamSetPMKIDCache(halHandle,pAdapter->sessionId,
6857 PMKIDCache,
6858 i );
6859 return 0;
6860}
6861
6862
6863static int wlan_hdd_cfg80211_del_pmksa(struct wiphy *wiphy, struct net_device *dev,
Jeff Johnsond13512a2012-07-17 11:42:19 -07006864 struct cfg80211_pmksa *pmksa)
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006865{
Jeff Johnsone7245742012-09-05 17:12:55 -07006866 ENTER();
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006867 // TODO: Implement this later.
6868 return 0;
6869}
6870
6871static int wlan_hdd_cfg80211_flush_pmksa(struct wiphy *wiphy, struct net_device *dev)
6872{
Jeff Johnsone7245742012-09-05 17:12:55 -07006873 ENTER();
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006874 // TODO: Implement this later.
6875 return 0;
6876}
6877#endif
6878
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07006879#if defined(WLAN_FEATURE_VOWIFI_11R) && defined(KERNEL_SUPPORT_11R_CFG80211)
6880static int wlan_hdd_cfg80211_update_ft_ies(struct wiphy *wiphy,
6881 struct net_device *dev, struct cfg80211_update_ft_ies_params *ftie)
6882{
6883 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
6884 hdd_station_ctx_t *pHddStaCtx;
6885
6886 if (NULL == pAdapter)
6887 {
6888 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: Adapter is NULL\n", __func__);
6889 return -ENODEV;
6890 }
6891
6892 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
6893
6894 // Added for debug on reception of Re-assoc Req.
6895 if (eConnectionState_Associated != pHddStaCtx->conn_info.connState)
6896 {
6897 hddLog(LOGE, FL("Called with Ie of length = %d when not associated\n"),
6898 ftie->ie_len);
6899 hddLog(LOGE, FL("Should be Re-assoc Req IEs\n"));
6900 }
6901
6902#ifdef WLAN_FEATURE_VOWIFI_11R_DEBUG
6903 hddLog(LOGE, FL("%s called with Ie of length = %d\n"), __func__,
6904 ftie->ie_len);
6905#endif
6906
6907 // Pass the received FT IEs to SME
Gopichand Nakkala356fb102013-03-06 12:34:04 +05306908 sme_SetFTIEs( WLAN_HDD_GET_HAL_CTX(pAdapter), pAdapter->sessionId,
6909 (const u8 *)ftie->ie,
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07006910 ftie->ie_len);
6911 return 0;
6912}
6913#endif
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006914
Mohit Khanna698ba2a2012-12-04 15:08:18 -08006915#ifdef FEATURE_WLAN_TDLS
6916static int wlan_hdd_cfg80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
6917 u8 *peer, u8 action_code, u8 dialog_token,
6918 u16 status_code, const u8 *buf, size_t len)
6919{
6920
6921 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
6922 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08006923 u8 peerMac[6];
6924 VOS_STATUS status;
Gopichand Nakkala05922802013-03-14 12:23:19 -07006925 int max_sta_failed = 0;
Hoonki Leea34dd892013-02-05 22:56:02 -08006926 int responder;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08006927
Hoonki Lee11f7dda2013-02-14 16:55:44 -08006928 if (NULL == pHddCtx || NULL == pHddCtx->cfg_ini)
Mohit Khanna698ba2a2012-12-04 15:08:18 -08006929 {
6930 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6931 "Invalid arguments");
6932 return -EINVAL;
6933 }
6934
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08006935 if (pHddCtx->isLogpInProgress)
6936 {
6937 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6938 "%s:LOGP in Progress. Ignore!!!", __func__);
Gopichand Nakkala05922802013-03-14 12:23:19 -07006939 wlan_hdd_tdls_set_link_status(pAdapter, peer, eTDLS_LINK_IDLE);
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08006940 return -EBUSY;
6941 }
6942
Hoonki Lee27511902013-03-14 18:19:06 -07006943 if (eTDLS_SUPPORT_NOT_ENABLED == pHddCtx->tdls_mode)
Mohit Khanna698ba2a2012-12-04 15:08:18 -08006944 {
Hoonki Lee27511902013-03-14 18:19:06 -07006945 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
6946 "%s: TDLS mode is disabled OR not enabled in FW."
6947 MAC_ADDRESS_STR " action %d declined.",
6948 __func__, MAC_ADDR_ARRAY(peer), action_code);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08006949 return -ENOTSUPP;
6950 }
Lee Hoonkic1262f22013-01-24 21:59:00 -08006951
Hoonki Lee27511902013-03-14 18:19:06 -07006952 /* other than teardown frame, other mgmt frames are not sent if disabled */
6953 if (SIR_MAC_TDLS_TEARDOWN != action_code)
6954 {
6955 /* if tdls_mode is disabled to respond to peer's request */
6956 if (eTDLS_SUPPORT_DISABLED == pHddCtx->tdls_mode)
6957 {
6958 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
6959 "%s: " MAC_ADDRESS_STR
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07006960 " TDLS mode is disabled. action %d declined.",
6961 __func__, MAC_ADDR_ARRAY(peer), action_code);
Hoonki Lee27511902013-03-14 18:19:06 -07006962
6963 return -ENOTSUPP;
6964 }
6965 }
6966
Gopichand Nakkalab977a972013-02-18 19:15:09 -08006967 if (WLAN_IS_TDLS_SETUP_ACTION(action_code))
6968 {
Hoonki Leefb8df672013-04-10 18:20:34 -07006969 if (NULL != wlan_hdd_tdls_is_progress(pHddCtx, peer, TRUE, TRUE))
Gopichand Nakkalab977a972013-02-18 19:15:09 -08006970 {
6971 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07006972 "%s: " MAC_ADDRESS_STR
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07006973 " TDLS setup is ongoing. action %d declined.",
6974 __func__, MAC_ADDR_ARRAY(peer), action_code);
6975 return -EPERM;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08006976 }
6977 }
6978
Hoonki Lee11f7dda2013-02-14 16:55:44 -08006979 if (SIR_MAC_TDLS_SETUP_REQ == action_code ||
6980 SIR_MAC_TDLS_SETUP_RSP == action_code )
Lee Hoonkic1262f22013-01-24 21:59:00 -08006981 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08006982 if (HDD_MAX_NUM_TDLS_STA <= wlan_hdd_tdlsConnectedPeers(pAdapter))
Lee Hoonkic1262f22013-01-24 21:59:00 -08006983 {
6984 /* supplicant still sends tdls_mgmt(SETUP_REQ) even after
6985 we return error code at 'add_station()'. Hence we have this
6986 check again in addtion to add_station().
6987 Anyway, there is no hard to double-check. */
Hoonki Lee11f7dda2013-02-14 16:55:44 -08006988 if (SIR_MAC_TDLS_SETUP_REQ == action_code)
Lee Hoonkic1262f22013-01-24 21:59:00 -08006989 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07006990 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
6991 "%s: " MAC_ADDRESS_STR
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07006992 " TDLS Max peer already connected. action %d declined.",
6993 __func__, MAC_ADDR_ARRAY(peer), action_code);
Gopichand Nakkala05922802013-03-14 12:23:19 -07006994 goto error;
Lee Hoonkic1262f22013-01-24 21:59:00 -08006995 }
6996 else
6997 {
Gopichand Nakkalab977a972013-02-18 19:15:09 -08006998 /* maximum reached. tweak to send error code to peer and return
6999 error code to supplicant */
Lee Hoonkic1262f22013-01-24 21:59:00 -08007000 status_code = eSIR_MAC_UNSPEC_FAILURE_STATUS;
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007001 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7002 "%s: " MAC_ADDRESS_STR
7003 " TDLS Max peer already connected send response status %d",
7004 __func__, MAC_ADDR_ARRAY(peer), status_code);
Gopichand Nakkala05922802013-03-14 12:23:19 -07007005 max_sta_failed = -EPERM;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007006 /* fall through to send setup resp with failure status
7007 code */
Lee Hoonkic1262f22013-01-24 21:59:00 -08007008 }
7009 }
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007010 else
7011 {
7012 hddTdlsPeer_t *pTdlsPeer;
Gopichand Nakkala4327a152013-03-04 23:22:42 -08007013 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peer);
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07007014 if (pTdlsPeer && TDLS_IS_CONNECTED(pTdlsPeer))
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007015 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007016 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07007017 "%s:" MAC_ADDRESS_STR " already connected. action %d declined.",
7018 __func__, MAC_ADDR_ARRAY(peer), action_code);
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007019 return -EPERM;
7020 }
7021 }
Lee Hoonkic1262f22013-01-24 21:59:00 -08007022 }
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007023 vos_mem_copy(peerMac, peer, 6);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007024
Hoonki Lee1090c6a2013-01-16 17:40:54 -08007025#ifdef WLAN_FEATURE_TDLS_DEBUG
7026 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007027 "%s: " MAC_ADDRESS_STR " action %d, dialog_token %d status %d, len = %d",
7028 "tdls_mgmt", MAC_ADDR_ARRAY(peer),
7029 action_code, dialog_token, status_code, len);
Hoonki Lee1090c6a2013-01-16 17:40:54 -08007030#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007031
Hoonki Leea34dd892013-02-05 22:56:02 -08007032 /*Except teardown responder will not be used so just make 0*/
7033 responder = 0;
Hoonki Lee11f7dda2013-02-14 16:55:44 -08007034 if (SIR_MAC_TDLS_TEARDOWN == action_code)
Hoonki Leea34dd892013-02-05 22:56:02 -08007035 {
Gopichand Nakkala97a65fd2013-04-16 16:59:38 -07007036
7037 hddTdlsPeer_t *pTdlsPeer;
7038 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peerMac);
7039
7040 if(pTdlsPeer && TDLS_IS_CONNECTED(pTdlsPeer))
7041 responder = pTdlsPeer->is_responder;
7042 else
Hoonki Leea34dd892013-02-05 22:56:02 -08007043 {
Gopichand Nakkala97a65fd2013-04-16 16:59:38 -07007044 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7045 "%s: " MAC_ADDRESS_STR " peer doesn't exist or not connected %d dialog_token %d status %d, len = %d",
7046 __func__, MAC_ADDR_ARRAY(peer), (NULL == pTdlsPeer) ? -1 : pTdlsPeer->link_status,
7047 dialog_token, status_code, len);
7048 return -EPERM;
Hoonki Leea34dd892013-02-05 22:56:02 -08007049 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007050 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007051
Hoonki Lee14621352013-04-16 17:51:19 -07007052 if ((SIR_MAC_TDLS_SETUP_RSP == action_code) ||
7053 (SIR_MAC_TDLS_DIS_RSP == action_code))
7054 {
7055 if (TRUE == sme_IsPmcBmps(WLAN_HDD_GET_HAL_CTX(pAdapter)))
7056 {
7057 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
7058 "%s: Sending Disc/Setup Rsp Frame.Disable BMPS", __func__);
7059 hdd_disable_bmps_imps(pHddCtx, WLAN_HDD_INFRA_STATION);
7060 }
7061 wlan_hdd_tdls_set_cap(pAdapter, peerMac, eTDLS_CAP_SUPPORTED);
7062 }
7063
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007064 INIT_COMPLETION(pAdapter->tdls_mgmt_comp);
7065
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007066 status = sme_SendTdlsMgmtFrame(WLAN_HDD_GET_HAL_CTX(pAdapter), pAdapter->sessionId,
Hoonki Leea34dd892013-02-05 22:56:02 -08007067 peerMac, action_code, dialog_token, status_code, (tANI_U8 *)buf, len, responder);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007068
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007069 if (VOS_STATUS_SUCCESS != status)
7070 {
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007071 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7072 "%s: sme_SendTdlsMgmtFrame failed!", __func__);
Hoonki Lee14621352013-04-16 17:51:19 -07007073 wlan_hdd_tdls_check_bmps(pAdapter);
7074 goto error;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007075 }
7076
Gopichand Nakkalab88f6772013-02-27 18:12:56 -08007077 /* not block discovery request, as it is called from timer callback */
7078 if (SIR_MAC_TDLS_DIS_REQ != action_code)
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007079 {
Pervinder Singhb4638422013-03-04 22:51:36 -08007080 long rc;
7081
7082 rc = wait_for_completion_interruptible_timeout(&pAdapter->tdls_mgmt_comp,
Gopichand Nakkalab88f6772013-02-27 18:12:56 -08007083 msecs_to_jiffies(WAIT_TIME_TDLS_MGMT));
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007084
Pervinder Singhb4638422013-03-04 22:51:36 -08007085 if ((rc <= 0) || (TRUE != pAdapter->mgmtTxCompletionStatus))
Gopichand Nakkalab88f6772013-02-27 18:12:56 -08007086 {
Gopichand Nakkalab88f6772013-02-27 18:12:56 -08007087 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Pervinder Singhb4638422013-03-04 22:51:36 -08007088 "%s: Mgmt Tx Completion failed status %ld TxCompletion %lu",
7089 __func__, rc, pAdapter->mgmtTxCompletionStatus);
Hoonki Lee14621352013-04-16 17:51:19 -07007090 wlan_hdd_tdls_check_bmps(pAdapter);
Hoonki Leefb8df672013-04-10 18:20:34 -07007091 goto error;
Gopichand Nakkalab88f6772013-02-27 18:12:56 -08007092 }
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007093 }
7094
Gopichand Nakkala05922802013-03-14 12:23:19 -07007095 if (max_sta_failed)
Hoonki Lee14621352013-04-16 17:51:19 -07007096 {
7097 wlan_hdd_tdls_check_bmps(pAdapter);
Gopichand Nakkala05922802013-03-14 12:23:19 -07007098 return max_sta_failed;
Hoonki Lee14621352013-04-16 17:51:19 -07007099 }
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007100
Hoonki Leea34dd892013-02-05 22:56:02 -08007101 if (SIR_MAC_TDLS_SETUP_RSP == action_code)
7102 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08007103 wlan_hdd_tdls_set_responder(pAdapter, peerMac, TRUE);
Hoonki Leea34dd892013-02-05 22:56:02 -08007104 }
7105 else if (SIR_MAC_TDLS_SETUP_CNF == action_code)
7106 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08007107 wlan_hdd_tdls_set_responder(pAdapter, peerMac, FALSE);
Hoonki Leea34dd892013-02-05 22:56:02 -08007108 }
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007109
7110 return 0;
Gopichand Nakkala05922802013-03-14 12:23:19 -07007111error:
7112 /* max_sta_failed ; we didn't set to CONNECTING for this case,
7113 because we already know that this transaction will be failed,
7114 but we weren't sure if supplicant call DISABLE_LINK or not. So,
7115 to be safe, do not change the state mahine.
7116 */
7117 if(max_sta_failed == 0 &&
7118 (WLAN_IS_TDLS_SETUP_ACTION(action_code)))
7119 wlan_hdd_tdls_set_link_status(pAdapter, peerMac, eTDLS_LINK_IDLE);
7120 return -EPERM;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007121}
7122
7123static int wlan_hdd_cfg80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
7124 u8 *peer, enum nl80211_tdls_operation oper)
7125{
7126 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7127 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
Hoonki Lee1090c6a2013-01-16 17:40:54 -08007128#ifdef WLAN_FEATURE_TDLS_DEBUG
7129 const char *tdls_oper_str[]= {
7130 "NL80211_TDLS_DISCOVERY_REQ",
7131 "NL80211_TDLS_SETUP",
7132 "NL80211_TDLS_TEARDOWN",
7133 "NL80211_TDLS_ENABLE_LINK",
7134 "NL80211_TDLS_DISABLE_LINK",
7135 "NL80211_TDLS_UNKONW_OPER"};
7136#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007137
Chilam Ngc4244af2013-04-01 15:37:32 -07007138 if ( NULL == pHddCtx || NULL == pHddCtx->cfg_ini || NULL == peer )
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007139 {
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007140 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Chilam Ngc4244af2013-04-01 15:37:32 -07007141 "%s: Invalid arguments", __func__);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007142 return -EINVAL;
7143 }
Hoonki Lee1090c6a2013-01-16 17:40:54 -08007144
Sameer Thalappil75ea31a2013-02-21 19:38:16 -08007145 if (pHddCtx->isLogpInProgress)
7146 {
7147 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7148 "%s:LOGP in Progress. Ignore!!!", __func__);
7149 return -EBUSY;
7150 }
7151
Hoonki Lee1090c6a2013-01-16 17:40:54 -08007152#ifdef WLAN_FEATURE_TDLS_DEBUG
7153 if((int)oper > 4)
7154 oper = 5;
7155
7156 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007157 "%s: " MAC_ADDRESS_STR " %d (%s) ", "tdls_oper",
7158 MAC_ADDR_ARRAY(peer), (int)oper,
7159 tdls_oper_str[(int)oper]);
Hoonki Lee1090c6a2013-01-16 17:40:54 -08007160#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007161
7162 if( FALSE == pHddCtx->cfg_ini->fEnableTDLSSupport ||
Hoonki Lee1090c6a2013-01-16 17:40:54 -08007163 FALSE == sme_IsFeatureSupportedByFW(TDLS))
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007164 {
Hoonki Lee1090c6a2013-01-16 17:40:54 -08007165 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Chilam Ngc4244af2013-04-01 15:37:32 -07007166 "TDLS Disabled in INI OR not enabled in FW. "
7167 "Cannot process TDLS commands");
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007168 return -ENOTSUPP;
7169 }
7170
7171 switch (oper) {
7172 case NL80211_TDLS_ENABLE_LINK:
7173 {
Hoonki Lee387663d2013-02-05 18:08:43 -08007174 hddTdlsPeer_t *pTdlsPeer;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007175 VOS_STATUS status;
7176
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007177 pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peer);
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007178
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007179 hddLog(VOS_TRACE_LEVEL_INFO_HIGH,
7180 "%s: TDLS_LINK_ENABLE " MAC_ADDRESS_STR,
7181 __func__, MAC_ADDR_ARRAY(peer));
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007182
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007183 if ( NULL == pTdlsPeer ) {
7184 hddLog(VOS_TRACE_LEVEL_ERROR, "%s: wlan_hdd_tdls_find_peer "
7185 MAC_ADDRESS_STR " failed",
7186 __func__, MAC_ADDR_ARRAY(peer));
7187 return -EINVAL;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007188 }
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007189
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07007190 if (eTDLS_LINK_CONNECTING == pTdlsPeer->link_status)
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007191 {
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07007192 wlan_hdd_tdls_set_peer_link_status(pTdlsPeer, eTDLS_LINK_CONNECTED);
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007193 /* start TDLS client registration with TL */
7194 status = hdd_roamRegisterTDLSSTA( pAdapter, peer, pTdlsPeer->staId, pTdlsPeer->signature);
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07007195 if (VOS_STATUS_SUCCESS == status)
7196 {
Hoonki Lee14621352013-04-16 17:51:19 -07007197 if (pTdlsPeer->is_responder == 0)
7198 {
7199 v_U8_t staId = (v_U8_t)pTdlsPeer->staId;
7200
7201 wlan_hdd_tdls_timer_restart(pAdapter,
7202 &pTdlsPeer->initiatorWaitTimeoutTimer,
7203 WAIT_TIME_TDLS_INITIATOR);
7204 /* suspend initiator TX until it receives direct packet from the
7205 reponder or WAIT_TIME_TDLS_INITIATOR timer expires */
7206 WLANTL_SuspendDataTx( (WLAN_HDD_GET_CTX(pAdapter))->pvosContext,
7207 &staId, NULL);
7208 }
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07007209 wlan_hdd_tdls_increment_peer_count(pAdapter);
7210 }
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007211 wlan_hdd_tdls_check_bmps(pAdapter);
7212 }
7213
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007214 }
7215 break;
7216 case NL80211_TDLS_DISABLE_LINK:
Lee Hoonkic1262f22013-01-24 21:59:00 -08007217 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08007218 hddTdlsPeer_t *curr_peer = wlan_hdd_tdls_find_peer(pAdapter, peer);
Gopichand Nakkalab977a972013-02-18 19:15:09 -08007219
7220 if(NULL != curr_peer)
Lee Hoonkic1262f22013-01-24 21:59:00 -08007221 {
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07007222 long status;
7223
7224 INIT_COMPLETION(pAdapter->tdls_del_station_comp);
7225
Lee Hoonkic1262f22013-01-24 21:59:00 -08007226 sme_DeleteTdlsPeerSta( WLAN_HDD_GET_HAL_CTX(pAdapter),
7227 pAdapter->sessionId, peer );
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07007228
7229 status = wait_for_completion_interruptible_timeout(&pAdapter->tdls_del_station_comp,
7230 msecs_to_jiffies(WAIT_TIME_TDLS_DEL_STA));
7231 if (status <= 0)
7232 {
7233 wlan_hdd_tdls_set_peer_link_status(curr_peer, eTDLS_LINK_IDLE);
7234 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7235 "%s: Del station failed status %ld",
7236 __func__, status);
7237 return -EPERM;
7238 }
Gopichand Nakkala8b00c632013-03-08 19:47:52 -08007239 wlan_hdd_tdls_set_peer_link_status(curr_peer, eTDLS_LINK_IDLE);
Lee Hoonkic1262f22013-01-24 21:59:00 -08007240 }
7241 else
7242 {
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007243 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7244 "%s: TDLS Peer Station doesn't exist.", __func__);
Lee Hoonkic1262f22013-01-24 21:59:00 -08007245 }
Lee Hoonkic1262f22013-01-24 21:59:00 -08007246 }
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07007247 break;
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007248 case NL80211_TDLS_TEARDOWN:
7249 case NL80211_TDLS_SETUP:
7250 case NL80211_TDLS_DISCOVERY_REQ:
7251 /* We don't support in-driver setup/teardown/discovery */
7252 return -ENOTSUPP;
7253 default:
7254 return -ENOTSUPP;
7255 }
7256 return 0;
7257}
Chilam NG571c65a2013-01-19 12:27:36 +05307258
7259int wlan_hdd_cfg80211_send_tdls_discover_req(struct wiphy *wiphy,
7260 struct net_device *dev, u8 *peer)
7261{
7262 hddLog(VOS_TRACE_LEVEL_INFO, "tdls send discover req: %x %x %x %x %x %x",
7263 peer[0], peer[1], peer[2], peer[3], peer[4], peer[5]);
7264
7265 return wlan_hdd_cfg80211_tdls_mgmt(wiphy, dev, peer,
7266 WLAN_TDLS_DISCOVERY_REQUEST, 1, 0, NULL, 0);
7267}
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007268#endif
7269
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05307270#ifdef WLAN_FEATURE_GTK_OFFLOAD
7271/*
7272 * FUNCTION: wlan_hdd_cfg80211_update_replayCounterCallback
7273 * Callback rountine called upon receiving response for
7274 * get offload info
7275 */
7276void wlan_hdd_cfg80211_update_replayCounterCallback(void *callbackContext,
7277 tpSirGtkOffloadGetInfoRspParams pGtkOffloadGetInfoRsp)
7278{
7279
7280 hdd_adapter_t *pAdapter = (hdd_adapter_t *)callbackContext;
7281
7282 ENTER();
7283
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 ;
7289 }
7290
7291 if (NULL == pGtkOffloadGetInfoRsp)
7292 {
7293 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7294 "%s: pGtkOffloadGetInfoRsp is Null", __func__);
7295 return ;
7296 }
7297
7298 if (VOS_STATUS_SUCCESS != pGtkOffloadGetInfoRsp->ulStatus)
7299 {
7300 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7301 "%s: wlan Failed to get replay counter value",
7302 __func__);
7303 return ;
7304 }
7305
7306 /* Update replay counter to NL */
7307 cfg80211_gtk_rekey_notify(pAdapter->dev, pGtkOffloadGetInfoRsp->bssId,
7308 (tANI_U8 *)&pGtkOffloadGetInfoRsp->ullKeyReplayCounter, GFP_KERNEL);
7309}
7310
7311/*
7312 * FUNCTION: wlan_hdd_cfg80211_set_rekey_data
7313 * This function is used to offload GTK rekeying job to the firmware.
7314 */
7315int wlan_hdd_cfg80211_set_rekey_data(struct wiphy *wiphy, struct net_device *dev,
7316 struct cfg80211_gtk_rekey_data *data)
7317{
7318 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
7319 hdd_context_t *pHddCtx = wiphy_priv(wiphy);
7320 hdd_station_ctx_t *pHddStaCtx;
7321 tHalHandle hHal;
7322 tpSirGtkOffloadParams pGtkOffloadReqParams;
7323 eHalStatus status = eHAL_STATUS_FAILURE;
7324
7325 ENTER();
7326
7327 if (NULL == pAdapter)
7328 {
7329 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
7330 "%s: HDD adapter is Null", __func__);
7331 return -ENODEV;
7332 }
7333
7334 if (NULL == pHddCtx)
7335 {
7336 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7337 "%s: HDD context is Null!!!", __func__);
7338 return -ENODEV;
7339 }
7340
7341 if (pHddCtx->isLogpInProgress)
7342 {
7343 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
7344 "%s: LOGP in Progress. Ignore!!!", __func__);
7345 return -EAGAIN;
7346 }
7347
7348 if (pHddCtx->isLoadUnloadInProgress)
7349 {
7350 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
7351 "%s: Unloading/Loading in Progress. Ignore!!!", __func__);
7352 return -EAGAIN;
7353 }
7354
7355 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
7356 hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
7357 if (NULL == hHal)
7358 {
7359 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7360 "%s: HAL context is Null!!!", __func__);
7361 return -EAGAIN;
7362 }
7363
7364 pGtkOffloadReqParams =
7365 &pHddStaCtx->gtkOffloadRequestParams.gtkOffloadReqParams;
7366
7367 pGtkOffloadReqParams->ulFlags = GTK_OFFLOAD_ENABLE;
7368 memcpy(pGtkOffloadReqParams->aKCK, data->kck, NL80211_KCK_LEN);
7369 memcpy(pGtkOffloadReqParams->aKEK, data->kek, NL80211_KEK_LEN);
7370 memcpy(pGtkOffloadReqParams->bssId, &pHddStaCtx->conn_info.bssId,
7371 WNI_CFG_BSSID_LEN);
7372 memcpy(&pGtkOffloadReqParams->ullKeyReplayCounter, &data->replay_ctr,
7373 sizeof (tANI_U64));
7374
7375 if (TRUE == pHddCtx->hdd_wlan_suspended)
7376 {
7377 /* if wlan is suspended, enable GTK offload directly from here */
7378 status = sme_SetGTKOffload(hHal, pGtkOffloadReqParams,
7379 pAdapter->sessionId);
7380
7381 if (eHAL_STATUS_SUCCESS != status)
7382 {
7383 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
7384 "%s: sme_SetGTKOffload failed, returned %d",
7385 __func__, status);
7386 return status;
7387 }
7388 pHddStaCtx->gtkOffloadRequestParams.requested = FALSE;
7389 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
7390 "%s: sme_SetGTKOffload successfull", __func__);
7391 }
7392 else
7393 {
7394 pHddStaCtx->gtkOffloadRequestParams.requested = TRUE;
7395 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
7396 "%s: wlan not suspended GTKOffload request is stored",
7397 __func__);
7398 return eHAL_STATUS_SUCCESS;
7399 }
7400 return status;
7401}
7402#endif /*WLAN_FEATURE_GTK_OFFLOAD*/
7403
Jeff Johnson295189b2012-06-20 16:38:30 -07007404/* cfg80211_ops */
7405static struct cfg80211_ops wlan_hdd_cfg80211_ops =
7406{
7407 .add_virtual_intf = wlan_hdd_add_virtual_intf,
7408 .del_virtual_intf = wlan_hdd_del_virtual_intf,
7409 .change_virtual_intf = wlan_hdd_cfg80211_change_iface,
7410 .change_station = wlan_hdd_change_station,
7411#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
7412 .add_beacon = wlan_hdd_cfg80211_add_beacon,
7413 .del_beacon = wlan_hdd_cfg80211_del_beacon,
7414 .set_beacon = wlan_hdd_cfg80211_set_beacon,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007415#else
7416 .start_ap = wlan_hdd_cfg80211_start_ap,
7417 .change_beacon = wlan_hdd_cfg80211_change_beacon,
7418 .stop_ap = wlan_hdd_cfg80211_stop_ap,
Jeff Johnson295189b2012-06-20 16:38:30 -07007419#endif
7420 .change_bss = wlan_hdd_cfg80211_change_bss,
7421 .add_key = wlan_hdd_cfg80211_add_key,
7422 .get_key = wlan_hdd_cfg80211_get_key,
7423 .del_key = wlan_hdd_cfg80211_del_key,
7424 .set_default_key = wlan_hdd_cfg80211_set_default_key,
Jeff Johnson3bbe4bf2013-01-18 17:05:29 -08007425#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07007426 .set_channel = wlan_hdd_cfg80211_set_channel,
Jeff Johnson3bbe4bf2013-01-18 17:05:29 -08007427#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07007428 .scan = wlan_hdd_cfg80211_scan,
7429 .connect = wlan_hdd_cfg80211_connect,
7430 .disconnect = wlan_hdd_cfg80211_disconnect,
7431 .join_ibss = wlan_hdd_cfg80211_join_ibss,
7432 .leave_ibss = wlan_hdd_cfg80211_leave_ibss,
7433 .set_wiphy_params = wlan_hdd_cfg80211_set_wiphy_params,
7434 .set_tx_power = wlan_hdd_cfg80211_set_txpower,
7435 .get_tx_power = wlan_hdd_cfg80211_get_txpower,
Jeff Johnson295189b2012-06-20 16:38:30 -07007436 .remain_on_channel = wlan_hdd_cfg80211_remain_on_channel,
7437 .cancel_remain_on_channel = wlan_hdd_cfg80211_cancel_remain_on_channel,
7438 .mgmt_tx = wlan_hdd_action,
7439#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
7440 .mgmt_tx_cancel_wait = wlan_hdd_cfg80211_mgmt_tx_cancel_wait,
7441 .set_default_mgmt_key = wlan_hdd_set_default_mgmt_key,
7442 .set_txq_params = wlan_hdd_set_txq_params,
7443#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07007444 .get_station = wlan_hdd_cfg80211_get_station,
7445 .set_power_mgmt = wlan_hdd_cfg80211_set_power_mgmt,
7446 .del_station = wlan_hdd_cfg80211_del_station,
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007447 .add_station = wlan_hdd_cfg80211_add_station,
7448#ifdef FEATURE_WLAN_LFR
7449 .set_pmksa = wlan_hdd_cfg80211_set_pmksa,
7450 .del_pmksa = wlan_hdd_cfg80211_del_pmksa,
7451 .flush_pmksa = wlan_hdd_cfg80211_flush_pmksa,
7452#endif
Madan Mohan Koyyalamudiea773882012-11-02 13:37:21 -07007453#if defined(WLAN_FEATURE_VOWIFI_11R) && defined(KERNEL_SUPPORT_11R_CFG80211)
7454 .update_ft_ies = wlan_hdd_cfg80211_update_ft_ies,
7455#endif
Mohit Khanna698ba2a2012-12-04 15:08:18 -08007456#ifdef FEATURE_WLAN_TDLS
7457 .tdls_mgmt = wlan_hdd_cfg80211_tdls_mgmt,
7458 .tdls_oper = wlan_hdd_cfg80211_tdls_oper,
7459#endif
Gopichand Nakkala870cbae2013-03-15 21:16:09 +05307460#ifdef WLAN_FEATURE_GTK_OFFLOAD
7461 .set_rekey_data = wlan_hdd_cfg80211_set_rekey_data,
7462#endif /* WLAN_FEATURE_GTK_OFFLOAD */
Jeff Johnson295189b2012-06-20 16:38:30 -07007463};
7464