blob: b14deb41f103cd85650e8281134938a9e5a36732 [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
2 * Copyright (c) 2012-2015 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
22/*
23 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
26 */
27
28/*===========================================================================
29
30 s a p F s m . C
31
32 OVERVIEW:
33
34 This software unit holds the implementation of the WLAN SAP Finite
35 State Machine modules
36
37 DEPENDENCIES:
38
39 Are listed for each API below.
40 ===========================================================================*/
41
42/*----------------------------------------------------------------------------
43 * Include Files
44 * -------------------------------------------------------------------------*/
45#include "sap_internal.h"
46/* Pick up the SME API definitions */
47#include "sme_api.h"
48/* Pick up the PMC API definitions */
49#include "cds_utils.h"
50#include "cds_ieee80211_common_i.h"
51#include "cds_reg_service.h"
52#include "cdf_util.h"
53#include "cds_concurrency.h"
54
55/*----------------------------------------------------------------------------
56 * Preprocessor Definitions and Constants
57 * -------------------------------------------------------------------------*/
58
59/*----------------------------------------------------------------------------
60 * Type Declarations
61 * -------------------------------------------------------------------------*/
62
63/*----------------------------------------------------------------------------
64 * Global Data Definitions
65 * -------------------------------------------------------------------------*/
66
67/*----------------------------------------------------------------------------
68 * External declarations for global context
69 * -------------------------------------------------------------------------*/
70#ifdef FEATURE_WLAN_CH_AVOID
71extern sapSafeChannelType safe_channels[];
72#endif /* FEATURE_WLAN_CH_AVOID */
73
74/*----------------------------------------------------------------------------
75 * Static Variable Definitions
76 * -------------------------------------------------------------------------*/
77
78#ifdef WLAN_ENABLE_CHNL_MATRIX_RESTRICTION
79/*
80 * TODO: At present SAP Channel leakage matrix for ch 144
81 * is not available from system's team. So to play it safe
82 * and avoid crash if channel 144 is request, in following
83 * matix channel 144 is added such that it will cause code
84 * to avoid selecting channel 144.
85 *
86 * THESE ENTRIES SHOULD BE REPLACED WITH CORRECT VALUES AS
87 * PROVIDED BY SYSTEM'S TEAM.
88 */
89
90/* channel tx leakage table - ht80 */
91tSapChanMatrixInfo ht80_chan[] = {
92 {52,
93 {{36, 148}, {40, 199},
94 {44, 193}, {48, 197},
95 {52, SAP_TX_LEAKAGE_MIN}, {56, 153},
96 {60, 137}, {64, 134},
97 {100, 358}, {104, 350},
98 {108, 404}, {112, 344},
99 {116, 424}, {120, 429},
100 {124, 437}, {128, 435},
101 {132, SAP_TX_LEAKAGE_MAX}, {136, SAP_TX_LEAKAGE_MAX},
102 {140, SAP_TX_LEAKAGE_MAX},
103 {144, SAP_TX_LEAKAGE_MIN}
104 } },
105
106
107 {56,
108 {{36, 171}, {40, 178},
109 {44, 171}, {48, 178},
110 {52, SAP_TX_LEAKAGE_MIN}, {56, SAP_TX_LEAKAGE_MIN},
111 {60, SAP_TX_LEAKAGE_MIN}, {64, 280},
112 {100, 351}, {104, 376},
113 {108, 362}, {112, 362},
114 {116, 403}, {120, 397},
115 {124, SAP_TX_LEAKAGE_MAX}, {128, SAP_TX_LEAKAGE_MAX},
116 {132, SAP_TX_LEAKAGE_MAX}, {136, SAP_TX_LEAKAGE_MAX},
117 {140, SAP_TX_LEAKAGE_MAX},
118 {144, SAP_TX_LEAKAGE_MIN}
119 } },
120
121 {60,
122 {{36, 156}, {40, 146},
123 {44, SAP_TX_LEAKAGE_MIN}, {48, SAP_TX_LEAKAGE_MIN},
124 {52, 180}, {56, SAP_TX_LEAKAGE_MIN},
125 {60, SAP_TX_LEAKAGE_MIN}, {64, SAP_TX_LEAKAGE_MIN},
126 {100, 376}, {104, 360},
127 {108, SAP_TX_LEAKAGE_MAX}, {112, SAP_TX_LEAKAGE_MAX},
128 {116, 395}, {120, 399},
129 {124, SAP_TX_LEAKAGE_MAX}, {128, SAP_TX_LEAKAGE_MAX},
130 {132, SAP_TX_LEAKAGE_MAX}, {136, SAP_TX_LEAKAGE_MAX},
131 {140, SAP_TX_LEAKAGE_MAX},
132 {144, SAP_TX_LEAKAGE_MIN}
133 } },
134
135 {64,
136 {{36, 217}, {40, 221},
137 {44, SAP_TX_LEAKAGE_MIN}, {48, SAP_TX_LEAKAGE_MIN},
138 {52, 176}, {56, 176},
139 {60, SAP_TX_LEAKAGE_MIN}, {64, SAP_TX_LEAKAGE_MIN},
140 {100, 384}, {104, 390},
141 {108, SAP_TX_LEAKAGE_MAX}, {112, SAP_TX_LEAKAGE_MAX},
142 {116, 375}, {120, 374},
143 {124, SAP_TX_LEAKAGE_MAX}, {128, SAP_TX_LEAKAGE_MAX},
144 {132, SAP_TX_LEAKAGE_MAX}, {136, SAP_TX_LEAKAGE_MAX},
145 {140, SAP_TX_LEAKAGE_MAX},
146 {144, SAP_TX_LEAKAGE_MIN}
147 } },
148
149 {100,
150 {{36, 357}, {40, 326},
151 {44, 321}, {48, 326},
152 {52, 378}, {56, 396},
153 {60, SAP_TX_LEAKAGE_MAX}, {64, SAP_TX_LEAKAGE_MAX},
154 {100, SAP_TX_LEAKAGE_MIN}, {104, SAP_TX_LEAKAGE_MIN},
155 {108, 196}, {112, 116},
156 {116, 166}, {120, SAP_TX_LEAKAGE_MIN},
157 {124, SAP_TX_LEAKAGE_MIN}, {128, SAP_TX_LEAKAGE_MIN},
158 {132, SAP_TX_LEAKAGE_MIN}, {136, SAP_TX_LEAKAGE_MIN},
159 {140, SAP_TX_LEAKAGE_MIN},
160 {144, SAP_TX_LEAKAGE_MIN}
161 } },
162
163 {104,
164 {{36, 325}, {40, 325},
165 {44, 305}, {48, 352},
166 {52, 411}, {56, 411},
167 {60, SAP_TX_LEAKAGE_MAX}, {64, SAP_TX_LEAKAGE_MAX},
168 {100, SAP_TX_LEAKAGE_MIN}, {104, SAP_TX_LEAKAGE_MIN},
169 {108, SAP_TX_LEAKAGE_MIN}, {112, 460},
170 {116, 198}, {120, SAP_TX_LEAKAGE_MIN},
171 {124, SAP_TX_LEAKAGE_MIN}, {128, SAP_TX_LEAKAGE_MIN},
172 {132, SAP_TX_LEAKAGE_MIN}, {136, SAP_TX_LEAKAGE_MIN},
173 {140, SAP_TX_LEAKAGE_MIN},
174 {144, SAP_TX_LEAKAGE_MIN}
175 } },
176
177 {108,
178 {{36, 304}, {40, 332},
179 {44, 310}, {48, 335},
180 {52, 431}, {56, 391},
181 {60, SAP_TX_LEAKAGE_MAX}, {64, SAP_TX_LEAKAGE_MAX},
182 {100, 280}, {104, SAP_TX_LEAKAGE_MIN},
183 {108, SAP_TX_LEAKAGE_MIN}, {112, SAP_TX_LEAKAGE_MIN},
184 {116, 185}, {120, SAP_TX_LEAKAGE_MIN},
185 {124, SAP_TX_LEAKAGE_MIN}, {128, SAP_TX_LEAKAGE_MIN},
186 {132, SAP_TX_LEAKAGE_MIN}, {136, SAP_TX_LEAKAGE_MIN},
187 {140, SAP_TX_LEAKAGE_MIN},
188 {144, SAP_TX_LEAKAGE_MIN}
189 } },
190
191 {112,
192 {{36, 327}, {40, 335},
193 {44, 331}, {48, 345},
194 {52, 367}, {56, 401},
195 {60, SAP_TX_LEAKAGE_MAX}, {64, SAP_TX_LEAKAGE_MAX},
196 {100, 131}, {104, 132},
197 {108, SAP_TX_LEAKAGE_MIN}, {112, SAP_TX_LEAKAGE_MIN},
198 {116, 189}, {120, SAP_TX_LEAKAGE_MIN},
199 {124, SAP_TX_LEAKAGE_MIN}, {128, SAP_TX_LEAKAGE_MIN},
200 {132, SAP_TX_LEAKAGE_MIN}, {136, SAP_TX_LEAKAGE_MIN},
201 {140, SAP_TX_LEAKAGE_MIN},
202 {144, SAP_TX_LEAKAGE_MIN}
203 } },
204
205 {116,
206 {{36, 384}, {40, 372},
207 {44, 389}, {48, 396},
208 {52, 348}, {56, 336},
209 {60, SAP_TX_LEAKAGE_MAX}, {64, SAP_TX_LEAKAGE_MAX},
210 {100, 172}, {104, 169},
211 {108, SAP_TX_LEAKAGE_MIN}, {112, SAP_TX_LEAKAGE_MIN},
212 {116, SAP_TX_LEAKAGE_MIN}, {120, SAP_TX_LEAKAGE_MIN},
213 {124, SAP_TX_LEAKAGE_MIN}, {128, SAP_TX_LEAKAGE_MIN},
214 {132, SAP_TX_LEAKAGE_MIN}, {136, SAP_TX_LEAKAGE_MIN},
215 {140, SAP_TX_LEAKAGE_MIN},
216 {144, SAP_TX_LEAKAGE_MIN}
217 } },
218
219 {120,
220 {{36, 395}, {40, 419},
221 {44, 439}, {48, 407},
222 {52, 321}, {56, 334},
223 {60, SAP_TX_LEAKAGE_MAX}, {64, SAP_TX_LEAKAGE_MAX},
224 {100, 134}, {104, 186},
225 {108, SAP_TX_LEAKAGE_MIN}, {112, SAP_TX_LEAKAGE_MIN},
226 {116, SAP_TX_LEAKAGE_MIN}, {120, SAP_TX_LEAKAGE_MIN},
227 {124, SAP_TX_LEAKAGE_MIN}, {128, 159},
228 {132, SAP_TX_LEAKAGE_MIN}, {136, SAP_TX_LEAKAGE_MIN},
229 {140, SAP_TX_LEAKAGE_MIN},
230 {144, SAP_TX_LEAKAGE_MIN}
231 } },
232
233 {124,
234 {{36, 469}, {40, 433},
235 {44, 434}, {48, 435},
236 {52, 332}, {56, 345},
237 {60, SAP_TX_LEAKAGE_MAX}, {64, SAP_TX_LEAKAGE_MAX},
238 {100, 146}, {104, 177},
239 {108, SAP_TX_LEAKAGE_MIN}, {112, SAP_TX_LEAKAGE_MIN},
240 {116, 350}, {120, SAP_TX_LEAKAGE_MIN},
241 {124, SAP_TX_LEAKAGE_MIN}, {128, 138},
242 {132, SAP_TX_LEAKAGE_MIN}, {136, SAP_TX_LEAKAGE_MIN},
243 {140, SAP_TX_LEAKAGE_MIN},
244 {144, SAP_TX_LEAKAGE_MIN}
245 } },
246
247 {128,
248 {{36, 408}, {40, 434},
249 {44, 449}, {48, 444},
250 {52, 341}, {56, 374},
251 {60, SAP_TX_LEAKAGE_MAX}, {64, SAP_TX_LEAKAGE_MAX},
252 {100, 205}, {104, 208},
253 {108, SAP_TX_LEAKAGE_MIN}, {112, SAP_TX_LEAKAGE_MIN},
254 {116, 142}, {120, SAP_TX_LEAKAGE_MIN},
255 {124, SAP_TX_LEAKAGE_MIN}, {128, SAP_TX_LEAKAGE_MIN},
256 {132, SAP_TX_LEAKAGE_MIN}, {136, SAP_TX_LEAKAGE_MIN},
257 {140, SAP_TX_LEAKAGE_MIN},
258 {144, SAP_TX_LEAKAGE_MIN}
259 } },
260
261 {132,
262 {{36, SAP_TX_LEAKAGE_MAX}, {40, SAP_TX_LEAKAGE_MAX},
263 {44, SAP_TX_LEAKAGE_MAX}, {48, SAP_TX_LEAKAGE_MAX},
264 {52, SAP_TX_LEAKAGE_MAX}, {56, SAP_TX_LEAKAGE_MAX},
265 {60, SAP_TX_LEAKAGE_MIN}, {64, SAP_TX_LEAKAGE_MIN},
266 {100, SAP_TX_LEAKAGE_MIN}, {104, SAP_TX_LEAKAGE_MIN},
267 {108, SAP_TX_LEAKAGE_MIN}, {112, SAP_TX_LEAKAGE_MIN},
268 {116, SAP_TX_LEAKAGE_MIN}, {120, SAP_TX_LEAKAGE_MIN},
269 {124, SAP_TX_LEAKAGE_MIN}, {128, SAP_TX_LEAKAGE_MIN},
270 {132, SAP_TX_LEAKAGE_MIN}, {136, SAP_TX_LEAKAGE_MIN},
271 {140, SAP_TX_LEAKAGE_MIN},
272 {144, SAP_TX_LEAKAGE_MIN}
273 } },
274
275 {136,
276 {{36, SAP_TX_LEAKAGE_MAX}, {40, SAP_TX_LEAKAGE_MAX},
277 {44, SAP_TX_LEAKAGE_MAX}, {48, SAP_TX_LEAKAGE_MAX},
278 {52, SAP_TX_LEAKAGE_MAX}, {56, SAP_TX_LEAKAGE_MAX},
279 {60, SAP_TX_LEAKAGE_MIN}, {64, SAP_TX_LEAKAGE_MIN},
280 {100, SAP_TX_LEAKAGE_MIN}, {104, SAP_TX_LEAKAGE_MIN},
281 {108, SAP_TX_LEAKAGE_MIN}, {112, SAP_TX_LEAKAGE_MIN},
282 {116, SAP_TX_LEAKAGE_MIN}, {120, SAP_TX_LEAKAGE_MIN},
283 {124, SAP_TX_LEAKAGE_MIN}, {128, SAP_TX_LEAKAGE_MIN},
284 {132, SAP_TX_LEAKAGE_MIN}, {136, SAP_TX_LEAKAGE_MIN},
285 {140, SAP_TX_LEAKAGE_MIN},
286 {144, SAP_TX_LEAKAGE_MIN}
287 } },
288
289 {140,
290 {{36, SAP_TX_LEAKAGE_MAX}, {40, SAP_TX_LEAKAGE_MAX},
291 {44, SAP_TX_LEAKAGE_MAX}, {48, SAP_TX_LEAKAGE_MAX},
292 {52, SAP_TX_LEAKAGE_MAX}, {56, SAP_TX_LEAKAGE_MAX},
293 {60, SAP_TX_LEAKAGE_MIN}, {64, SAP_TX_LEAKAGE_MIN},
294 {100, SAP_TX_LEAKAGE_MIN}, {104, SAP_TX_LEAKAGE_MIN},
295 {108, SAP_TX_LEAKAGE_MIN}, {112, SAP_TX_LEAKAGE_MIN},
296 {116, SAP_TX_LEAKAGE_MIN}, {120, SAP_TX_LEAKAGE_MIN},
297 {124, SAP_TX_LEAKAGE_MIN}, {128, SAP_TX_LEAKAGE_MIN},
298 {132, SAP_TX_LEAKAGE_MIN}, {136, SAP_TX_LEAKAGE_MIN},
299 {144, SAP_TX_LEAKAGE_MIN}
300 } },
301};
302
303/* channel tx leakage table - ht40 */
304tSapChanMatrixInfo ht40_chan[] = {
305 {52,
306 {{36, SAP_TX_LEAKAGE_AUTO_MIN}, {40, SAP_TX_LEAKAGE_AUTO_MIN},
307 {44, 230}, {48, 230},
308 {52, SAP_TX_LEAKAGE_MIN}, {56, SAP_TX_LEAKAGE_MIN},
309 {60, SAP_TX_LEAKAGE_AUTO_MIN}, {64, SAP_TX_LEAKAGE_AUTO_MIN},
310 {100, 625}, {104, 323},
311 {108, 646}, {112, 646},
312 {116, SAP_TX_LEAKAGE_MAX}, {120, SAP_TX_LEAKAGE_MAX},
313 {124, SAP_TX_LEAKAGE_MAX}, {128, SAP_TX_LEAKAGE_MAX},
314 {132, SAP_TX_LEAKAGE_MAX}, {136, SAP_TX_LEAKAGE_MAX},
315 {140, SAP_TX_LEAKAGE_MAX},
316 {144, SAP_TX_LEAKAGE_MIN}
317 } },
318
319 {56,
320 {{36, SAP_TX_LEAKAGE_AUTO_MIN}, {40, SAP_TX_LEAKAGE_AUTO_MIN},
321 {44, SAP_TX_LEAKAGE_AUTO_MIN}, {48, SAP_TX_LEAKAGE_AUTO_MIN},
322 {52, SAP_TX_LEAKAGE_MIN}, {56, SAP_TX_LEAKAGE_MIN},
323 {60, SAP_TX_LEAKAGE_MIN}, {64, SAP_TX_LEAKAGE_MIN},
324 {100, 611}, {104, 611},
325 {108, 617}, {112, 617},
326 {116, SAP_TX_LEAKAGE_MAX}, {120, SAP_TX_LEAKAGE_MAX},
327 {124, SAP_TX_LEAKAGE_MAX}, {128, SAP_TX_LEAKAGE_MAX},
328 {132, SAP_TX_LEAKAGE_MAX}, {136, SAP_TX_LEAKAGE_MAX},
329 {140, SAP_TX_LEAKAGE_MAX},
330 {144, SAP_TX_LEAKAGE_MIN}
331 } },
332
333 {60,
334 {{36, SAP_TX_LEAKAGE_AUTO_MIN}, {40, SAP_TX_LEAKAGE_AUTO_MIN},
335 {44, SAP_TX_LEAKAGE_AUTO_MIN}, {48, SAP_TX_LEAKAGE_AUTO_MIN},
336 {52, 190}, {56, 190},
337 {60, SAP_TX_LEAKAGE_MIN}, {64, SAP_TX_LEAKAGE_MIN},
338 {100, 608}, {104, 608},
339 {108, 623}, {112, 623},
340 {116, SAP_TX_LEAKAGE_MAX}, {120, SAP_TX_LEAKAGE_MAX},
341 {124, SAP_TX_LEAKAGE_MAX}, {128, SAP_TX_LEAKAGE_MAX},
342 {132, SAP_TX_LEAKAGE_MAX}, {136, SAP_TX_LEAKAGE_MAX},
343 {140, SAP_TX_LEAKAGE_MAX},
344 {144, SAP_TX_LEAKAGE_MIN}
345 } },
346
347 {64,
348 {{36, SAP_TX_LEAKAGE_AUTO_MIN}, {40, SAP_TX_LEAKAGE_AUTO_MIN},
349 {44, SAP_TX_LEAKAGE_AUTO_MIN}, {48, SAP_TX_LEAKAGE_AUTO_MIN},
350 {52, 295}, {56, 295},
351 {60, SAP_TX_LEAKAGE_MIN}, {64, SAP_TX_LEAKAGE_MIN},
352 {100, 594}, {104, 594},
353 {108, 625}, {112, 625},
354 {116, SAP_TX_LEAKAGE_MAX}, {120, SAP_TX_LEAKAGE_MAX},
355 {124, SAP_TX_LEAKAGE_MAX}, {128, SAP_TX_LEAKAGE_MAX},
356 {132, SAP_TX_LEAKAGE_MAX}, {136, SAP_TX_LEAKAGE_MAX},
357 {140, SAP_TX_LEAKAGE_MAX},
358 {144, SAP_TX_LEAKAGE_MIN}
359 } },
360
361 {100,
362 {{36, 618}, {40, 618},
363 {44, 604}, {48, 604},
364 {52, 596}, {56, 596},
365 {60, 584}, {64, 584},
366 {100, SAP_TX_LEAKAGE_MIN}, {104, SAP_TX_LEAKAGE_MIN},
367 {108, 299}, {112, 299},
368 {116, SAP_TX_LEAKAGE_AUTO_MIN}, {120, SAP_TX_LEAKAGE_AUTO_MIN},
369 {124, SAP_TX_LEAKAGE_AUTO_MIN}, {128, SAP_TX_LEAKAGE_AUTO_MIN},
370 {132, 538}, {136, 538},
371 {140, 598},
372 {144, SAP_TX_LEAKAGE_MIN}
373 } },
374
375 {104,
376 {{36, 636}, {40, 636},
377 {44, 601}, {48, 601},
378 {52, 616}, {56, 616},
379 {60, 584}, {64, 584},
380 {100, SAP_TX_LEAKAGE_MIN}, {104, SAP_TX_LEAKAGE_MIN},
381 {108, SAP_TX_LEAKAGE_MIN}, {112, SAP_TX_LEAKAGE_MIN},
382 {116, SAP_TX_LEAKAGE_AUTO_MIN}, {120, SAP_TX_LEAKAGE_AUTO_MIN},
383 {124, SAP_TX_LEAKAGE_AUTO_MIN}, {128, SAP_TX_LEAKAGE_AUTO_MIN},
384 {132, 553}, {136, 553},
385 {140, 568},
386 {144, SAP_TX_LEAKAGE_MIN}
387 } },
388
389 {108,
390 {{36, 600}, {40, 600},
391 {44, 627}, {48, 627},
392 {52, 611}, {56, 611},
393 {60, 611}, {64, 611},
394 {100, 214}, {104, 214},
395 {108, SAP_TX_LEAKAGE_MIN}, {112, SAP_TX_LEAKAGE_MIN},
396 {116, SAP_TX_LEAKAGE_AUTO_MIN}, {120, SAP_TX_LEAKAGE_AUTO_MIN},
397 {124, SAP_TX_LEAKAGE_AUTO_MIN}, {128, SAP_TX_LEAKAGE_AUTO_MIN},
398 {132, SAP_TX_LEAKAGE_AUTO_MIN}, {136, SAP_TX_LEAKAGE_AUTO_MIN},
399 {140, 534},
400 {144, SAP_TX_LEAKAGE_MIN}
401 } },
402
403 {112,
404 {{36, 645}, {40, 645},
405 {44, 641}, {48, 641},
406 {52, 618}, {56, 618},
407 {60, 612}, {64, 612},
408 {100, 293}, {104, 293},
409 {108, SAP_TX_LEAKAGE_MIN}, {112, SAP_TX_LEAKAGE_MIN},
410 {116, SAP_TX_LEAKAGE_MIN}, {120, SAP_TX_LEAKAGE_MIN},
411 {124, SAP_TX_LEAKAGE_AUTO_MIN}, {128, SAP_TX_LEAKAGE_AUTO_MIN},
412 {132, SAP_TX_LEAKAGE_AUTO_MIN}, {136, SAP_TX_LEAKAGE_AUTO_MIN},
413 {140, 521},
414 {144, SAP_TX_LEAKAGE_MIN}
415 } },
416
417 {116,
418 {{36, 661}, {40, 661},
419 {44, 624}, {48, 624},
420 {52, 634}, {56, 634},
421 {60, 611}, {64, 611},
422 {100, SAP_TX_LEAKAGE_AUTO_MIN}, {104, SAP_TX_LEAKAGE_AUTO_MIN},
423 {108, 217}, {112, 217},
424 {116, SAP_TX_LEAKAGE_MIN}, {120, SAP_TX_LEAKAGE_MIN},
425 {124, SAP_TX_LEAKAGE_AUTO_MIN}, {128, SAP_TX_LEAKAGE_AUTO_MIN},
426 {132, SAP_TX_LEAKAGE_AUTO_MIN}, {136, SAP_TX_LEAKAGE_AUTO_MIN},
427 {140, SAP_TX_LEAKAGE_AUTO_MIN},
428 {144, SAP_TX_LEAKAGE_MIN}
429 } },
430
431 {120,
432 {{36, 667}, {40, 667},
433 {44, 645}, {48, 645},
434 {52, 633}, {56, 633},
435 {60, 619}, {64, 619},
436 {100, SAP_TX_LEAKAGE_AUTO_MIN}, {104, SAP_TX_LEAKAGE_AUTO_MIN},
437 {108, 291}, {112, 291},
438 {116, SAP_TX_LEAKAGE_MIN}, {120, SAP_TX_LEAKAGE_MIN},
439 {124, SAP_TX_LEAKAGE_MIN}, {128, SAP_TX_LEAKAGE_MIN},
440 {132, SAP_TX_LEAKAGE_AUTO_MIN}, {136, SAP_TX_LEAKAGE_AUTO_MIN},
441 {140, SAP_TX_LEAKAGE_AUTO_MIN},
442 {144, SAP_TX_LEAKAGE_MIN}
443 } },
444
445 {124,
446 {{36, 676}, {40, 676},
447 {44, 668}, {48, 668},
448 {52, 595}, {56, 595},
449 {60, 622}, {64, 622},
450 {100, SAP_TX_LEAKAGE_AUTO_MIN}, {104, SAP_TX_LEAKAGE_AUTO_MIN},
451 {108, SAP_TX_LEAKAGE_AUTO_MIN}, {112, SAP_TX_LEAKAGE_AUTO_MIN},
452 {116, 225}, {120, 225},
453 {124, SAP_TX_LEAKAGE_MIN}, {128, SAP_TX_LEAKAGE_MIN},
454 {132, SAP_TX_LEAKAGE_AUTO_MIN}, {136, SAP_TX_LEAKAGE_AUTO_MIN},
455 {140, SAP_TX_LEAKAGE_AUTO_MIN},
456 {144, SAP_TX_LEAKAGE_MIN}
457 } },
458
459 {128,
460 {{36, 678}, {40, 678},
461 {44, 664}, {48, 664},
462 {52, 651}, {56, 651},
463 {60, 643}, {64, 643},
464 {100, SAP_TX_LEAKAGE_AUTO_MIN}, {104, SAP_TX_LEAKAGE_AUTO_MIN},
465 {108, SAP_TX_LEAKAGE_AUTO_MIN}, {112, SAP_TX_LEAKAGE_AUTO_MIN},
466 {116, 293}, {120, 293},
467 {124, SAP_TX_LEAKAGE_MIN}, {128, SAP_TX_LEAKAGE_MIN},
468 {132, SAP_TX_LEAKAGE_MIN}, {136, SAP_TX_LEAKAGE_MIN},
469 {140, SAP_TX_LEAKAGE_AUTO_MIN},
470 {144, SAP_TX_LEAKAGE_MIN}
471 } },
472
473 {132,
474 {{36, 689}, {40, 689},
475 {44, 669}, {48, 669},
476 {52, 662}, {56, 662},
477 {60, 609}, {64, 609},
478 {100, 538}, {104, 538},
479 {108, SAP_TX_LEAKAGE_AUTO_MIN}, {112, SAP_TX_LEAKAGE_AUTO_MIN},
480 {116, SAP_TX_LEAKAGE_AUTO_MIN}, {120, SAP_TX_LEAKAGE_AUTO_MIN},
481 {124, 247}, {128, 247},
482 {132, SAP_TX_LEAKAGE_MIN}, {136, SAP_TX_LEAKAGE_MIN},
483 {140, SAP_TX_LEAKAGE_MIN},
484 {144, SAP_TX_LEAKAGE_MIN}
485 } },
486
487 {136,
488 {{36, 703}, {40, 703},
489 {44, 688}, {48, SAP_TX_LEAKAGE_MIN},
490 {52, 671}, {56, 671},
491 {60, 658}, {64, 658},
492 {100, 504}, {104, 504},
493 {108, SAP_TX_LEAKAGE_AUTO_MIN}, {112, SAP_TX_LEAKAGE_AUTO_MIN},
494 {116, SAP_TX_LEAKAGE_AUTO_MIN}, {120, SAP_TX_LEAKAGE_AUTO_MIN},
495 {124, 289}, {128, 289},
496 {132, SAP_TX_LEAKAGE_MIN}, {136, SAP_TX_LEAKAGE_MIN},
497 {140, SAP_TX_LEAKAGE_MIN},
498 {144, SAP_TX_LEAKAGE_MIN}
499 } },
500
501 {140,
502 {{36, 695}, {40, 695},
503 {44, 684}, {48, 684},
504 {52, 664}, {56, 664},
505 {60, 658}, {64, 658},
506 {100, 601}, {104, 601},
507 {108, 545}, {112, 545},
508 {116, SAP_TX_LEAKAGE_AUTO_MIN}, {120, SAP_TX_LEAKAGE_AUTO_MIN},
509 {124, SAP_TX_LEAKAGE_AUTO_MIN}, {128, SAP_TX_LEAKAGE_AUTO_MIN},
510 {132, 262}, {136, 262},
511 {140, SAP_TX_LEAKAGE_MIN},
512 {144, SAP_TX_LEAKAGE_MIN}
513 } },
514
515};
516
517/* channel tx leakage table - ht20 */
518tSapChanMatrixInfo ht20_chan[] = {
519 {52,
520 {{36, SAP_TX_LEAKAGE_AUTO_MIN}, {40, 286},
521 {44, 225}, {48, 121},
522 {52, SAP_TX_LEAKAGE_MIN}, {56, SAP_TX_LEAKAGE_MIN},
523 {60, 300}, {64, SAP_TX_LEAKAGE_AUTO_MIN},
524 {100, 637}, {104, SAP_TX_LEAKAGE_MAX},
525 {108, SAP_TX_LEAKAGE_MAX}, {112, SAP_TX_LEAKAGE_MAX},
526 {116, SAP_TX_LEAKAGE_MAX}, {120, SAP_TX_LEAKAGE_MAX},
527 {124, SAP_TX_LEAKAGE_MAX}, {128, SAP_TX_LEAKAGE_MAX},
528 {132, SAP_TX_LEAKAGE_MAX}, {136, SAP_TX_LEAKAGE_MAX},
529 {140, SAP_TX_LEAKAGE_MAX},
530 {144, SAP_TX_LEAKAGE_MIN}
531 } },
532
533 {56,
534 {{36, 468}, {40, SAP_TX_LEAKAGE_AUTO_MIN},
535 {44, SAP_TX_LEAKAGE_AUTO_MIN}, {48, 206},
536 {52, SAP_TX_LEAKAGE_MIN}, {56, SAP_TX_LEAKAGE_MIN},
537 {60, SAP_TX_LEAKAGE_MIN}, {64, SAP_TX_LEAKAGE_MIN},
538 {100, SAP_TX_LEAKAGE_MAX}, {104, SAP_TX_LEAKAGE_MAX},
539 {108, SAP_TX_LEAKAGE_MAX}, {112, SAP_TX_LEAKAGE_MAX},
540 {116, SAP_TX_LEAKAGE_MAX}, {120, SAP_TX_LEAKAGE_MAX},
541 {124, SAP_TX_LEAKAGE_MAX}, {128, SAP_TX_LEAKAGE_MAX},
542 {132, SAP_TX_LEAKAGE_MAX}, {136, SAP_TX_LEAKAGE_MAX},
543 {140, SAP_TX_LEAKAGE_MAX},
544 {144, SAP_TX_LEAKAGE_MIN}
545 } },
546
547 {60,
548 {{36, 507}, {40, 440},
549 {44, SAP_TX_LEAKAGE_AUTO_MIN}, {48, 313},
550 {52, SAP_TX_LEAKAGE_MIN}, {56, SAP_TX_LEAKAGE_MIN},
551 {60, SAP_TX_LEAKAGE_MIN}, {64, SAP_TX_LEAKAGE_MIN},
552 {100, SAP_TX_LEAKAGE_MAX}, {104, SAP_TX_LEAKAGE_MAX},
553 {108, SAP_TX_LEAKAGE_MAX}, {112, SAP_TX_LEAKAGE_MAX},
554 {116, SAP_TX_LEAKAGE_MAX}, {120, SAP_TX_LEAKAGE_MAX},
555 {124, SAP_TX_LEAKAGE_MAX}, {128, SAP_TX_LEAKAGE_MAX},
556 {132, SAP_TX_LEAKAGE_MAX}, {136, SAP_TX_LEAKAGE_MAX},
557 {140, SAP_TX_LEAKAGE_MAX},
558 {144, SAP_TX_LEAKAGE_MIN}
559 } },
560
561 {64,
562 {{36, 516}, {40, 520},
563 {44, 506}, {48, SAP_TX_LEAKAGE_AUTO_MIN},
564 {52, 301}, {56, 258},
565 {60, SAP_TX_LEAKAGE_MIN}, {64, SAP_TX_LEAKAGE_MIN},
566 {100, 620}, {104, 617},
567 {108, SAP_TX_LEAKAGE_MAX}, {112, SAP_TX_LEAKAGE_MAX},
568 {116, SAP_TX_LEAKAGE_MAX}, {120, SAP_TX_LEAKAGE_MAX},
569 {124, SAP_TX_LEAKAGE_MAX}, {128, SAP_TX_LEAKAGE_MAX},
570 {132, SAP_TX_LEAKAGE_MAX}, {136, SAP_TX_LEAKAGE_MAX},
571 {140, SAP_TX_LEAKAGE_MAX},
572 {144, SAP_TX_LEAKAGE_MIN}
573 } },
574
575 {100,
576 {{36, 616}, {40, 601},
577 {44, 604}, {48, 589},
578 {52, 612}, {56, 592},
579 {60, 590}, {64, 582},
580 {100, SAP_TX_LEAKAGE_MIN}, {104, 131},
581 {108, SAP_TX_LEAKAGE_AUTO_MIN}, {112, SAP_TX_LEAKAGE_AUTO_MIN},
582 {116, SAP_TX_LEAKAGE_AUTO_MIN}, {120, 522},
583 {124, 571}, {128, 589},
584 {132, 593}, {136, 598},
585 {140, 594},
586 {144, SAP_TX_LEAKAGE_MIN},
587 } },
588
589 {104,
590 {{36, 622}, {40, 624},
591 {44, 618}, {48, 610},
592 {52, SAP_TX_LEAKAGE_MAX}, {56, SAP_TX_LEAKAGE_MAX},
593 {60, SAP_TX_LEAKAGE_MAX}, {64, SAP_TX_LEAKAGE_MAX},
594 {100, SAP_TX_LEAKAGE_MIN}, {104, SAP_TX_LEAKAGE_MIN},
595 {108, SAP_TX_LEAKAGE_MIN}, {112, 463},
596 {116, 483}, {120, 503},
597 {124, 523}, {128, 565},
598 {132, 570}, {136, 588},
599 {140, 585},
600 {144, SAP_TX_LEAKAGE_MIN},
601 } },
602
603 {108,
604 {{36, 620}, {40, 638},
605 {44, 611}, {48, 614},
606 {52, SAP_TX_LEAKAGE_MAX}, {56, SAP_TX_LEAKAGE_MAX},
607 {60, SAP_TX_LEAKAGE_MAX}, {64, SAP_TX_LEAKAGE_MAX},
608 {100, 477}, {104, SAP_TX_LEAKAGE_MIN},
609 {108, SAP_TX_LEAKAGE_MIN}, {112, SAP_TX_LEAKAGE_MIN},
610 {116, 477}, {120, 497},
611 {124, 517}, {128, 537},
612 {132, 557}, {136, 577},
613 {140, 603},
614 {144, SAP_TX_LEAKAGE_MIN},
615 } },
616
617 {112,
618 {{36, 636}, {40, 623},
619 {44, 638}, {48, 628},
620 {52, SAP_TX_LEAKAGE_MAX}, {56, SAP_TX_LEAKAGE_MAX},
621 {60, SAP_TX_LEAKAGE_MAX}, {64, 606},
622 {100, 501}, {104, 481},
623 {108, SAP_TX_LEAKAGE_MIN}, {112, SAP_TX_LEAKAGE_MIN},
624 {116, SAP_TX_LEAKAGE_MIN}, {120, 481},
625 {124, 501}, {128, 421},
626 {132, 541}, {136, 561},
627 {140, 583},
628 {144, SAP_TX_LEAKAGE_MIN},
629 } },
630
631 {116,
632 {{36, 646}, {40, 648},
633 {44, 633}, {48, 634},
634 {52, SAP_TX_LEAKAGE_MAX}, {56, SAP_TX_LEAKAGE_MAX},
635 {60, 615}, {64, 594},
636 {100, 575}, {104, 554},
637 {108, 534}, {112, SAP_TX_LEAKAGE_MIN},
638 {116, SAP_TX_LEAKAGE_MIN}, {120, SAP_TX_LEAKAGE_MIN},
639 {124, SAP_TX_LEAKAGE_MIN}, {128, SAP_TX_LEAKAGE_MIN},
640 {132, 534}, {136, 554},
641 {140, 574},
642 {144, SAP_TX_LEAKAGE_MIN},
643 } },
644
645 {120,
646 {{36, 643}, {40, 649},
647 {44, 654}, {48, 629},
648 {52, SAP_TX_LEAKAGE_MAX}, {56, 621},
649 {60, SAP_TX_LEAKAGE_MAX}, {64, SAP_TX_LEAKAGE_MAX},
650 {100, 565}, {104, 545},
651 {108, 525}, {112, 505},
652 {116, SAP_TX_LEAKAGE_MIN}, {120, SAP_TX_LEAKAGE_MIN},
653 {124, SAP_TX_LEAKAGE_MIN}, {128, 505},
654 {132, 525}, {136, 545},
655 {140, 565},
656 {144, SAP_TX_LEAKAGE_MIN},
657 } },
658
659 {124,
660 {{36, 638}, {40, 657},
661 {44, 663}, {48, 649},
662 {52, SAP_TX_LEAKAGE_MAX}, {56, SAP_TX_LEAKAGE_MAX},
663 {60, SAP_TX_LEAKAGE_MAX}, {64, SAP_TX_LEAKAGE_MAX},
664 {100, 581}, {104, 561},
665 {108, 541}, {112, 521},
666 {116, 499}, {120, SAP_TX_LEAKAGE_MIN},
667 {124, SAP_TX_LEAKAGE_MIN}, {128, SAP_TX_LEAKAGE_MIN},
668 {132, 499}, {136, 519},
669 {140, 539},
670 {144, SAP_TX_LEAKAGE_MIN}
671 } },
672
673 {128,
674 {{36, 651}, {40, 651},
675 {44, 674}, {48, 640},
676 {52, SAP_TX_LEAKAGE_MAX}, {56, SAP_TX_LEAKAGE_MAX},
677 {60, SAP_TX_LEAKAGE_MAX}, {64, SAP_TX_LEAKAGE_MAX},
678 {100, 603}, {104, 560},
679 {108, 540}, {112, 520},
680 {116, 499}, {120, 479},
681 {124, SAP_TX_LEAKAGE_MIN}, {128, SAP_TX_LEAKAGE_MIN},
682 {132, SAP_TX_LEAKAGE_MIN}, {136, 479},
683 {140, 499},
684 {144, SAP_TX_LEAKAGE_MIN}
685 } },
686
687 {132,
688 {{36, 643}, {40, 668},
689 {44, 651}, {48, 657},
690 {52, SAP_TX_LEAKAGE_MAX}, {56, SAP_TX_LEAKAGE_MAX},
691 {60, SAP_TX_LEAKAGE_MAX}, {64, SAP_TX_LEAKAGE_MAX},
692 {100, SAP_TX_LEAKAGE_MAX}, {104, 602},
693 {108, 578}, {112, 570},
694 {116, 550}, {120, 530},
695 {124, 510}, {128, SAP_TX_LEAKAGE_MIN},
696 {132, SAP_TX_LEAKAGE_MIN}, {136, SAP_TX_LEAKAGE_MIN},
697 {140, 490},
698 {144, SAP_TX_LEAKAGE_MIN}
699 } },
700
701 {136,
702 {{36, 654}, {40, 667},
703 {44, 666}, {48, 642},
704 {52, SAP_TX_LEAKAGE_MAX}, {56, SAP_TX_LEAKAGE_MAX},
705 {60, SAP_TX_LEAKAGE_MAX}, {64, SAP_TX_LEAKAGE_MAX},
706 {100, SAP_TX_LEAKAGE_MAX}, {104, SAP_TX_LEAKAGE_MAX},
707 {108, SAP_TX_LEAKAGE_MAX}, {112, 596},
708 {116, 555}, {120, 535},
709 {124, 515}, {128, 495},
710 {132, SAP_TX_LEAKAGE_MIN}, {136, SAP_TX_LEAKAGE_MIN},
711 {140, SAP_TX_LEAKAGE_MIN},
712 {144, SAP_TX_LEAKAGE_MIN}
713 } },
714
715 {140,
716 {{36, 679}, {40, 673},
717 {44, 667}, {48, 656},
718 {52, 634}, {56, 663},
719 {60, 662}, {64, 660},
720 {100, SAP_TX_LEAKAGE_MAX}, {104, SAP_TX_LEAKAGE_MAX},
721 {108, SAP_TX_LEAKAGE_MAX}, {112, 590},
722 {116, 573}, {120, 553},
723 {124, 533}, {128, 513},
724 {132, 490}, {136, SAP_TX_LEAKAGE_MIN},
725 {140, SAP_TX_LEAKAGE_MIN},
726 {144, SAP_TX_LEAKAGE_MIN}
727 } },
728};
729#endif /* WLAN_ENABLE_CHNL_MATRIX_RESTRICTION */
730
731/*----------------------------------------------------------------------------
732 * Static Function Declarations and Definitions
733 * -------------------------------------------------------------------------*/
734#ifdef SOFTAP_CHANNEL_RANGE
735static CDF_STATUS sap_get_channel_list(ptSapContext sapContext,
736 uint8_t **channelList,
737 uint8_t *numberOfChannels);
738#endif
739
740/*==========================================================================
741 FUNCTION sapGet5GHzChannelList
742
743 DESCRIPTION
744 Function for initializing list of 2.4/5 Ghz [NON-DFS/DFS] available
745 channels in the current regulatory domain.
746
747 DEPENDENCIES
748 NA.
749
750 PARAMETERS
751
752 IN
753 sapContext: SAP Context
754
755 RETURN VALUE
756 NA
757
758 SIDE EFFECTS
759 ============================================================================*/
760static CDF_STATUS sap_get5_g_hz_channel_list(ptSapContext sapContext);
761
762/*==========================================================================
763 FUNCTION sapStopDfsCacTimer
764
765 DESCRIPTION
766 Function to sttop the DFS CAC timer when SAP is stopped
767 DEPENDENCIES
768 NA.
769
770 PARAMETERS
771
772 IN
773 sapContext: SAP Context
774 RETURN VALUE
775 DFS Timer start status
776 SIDE EFFECTS
777 ============================================================================*/
778
779static int sap_stop_dfs_cac_timer(ptSapContext sapContext);
780
781/*==========================================================================
782 FUNCTION sapStartDfsCacTimer
783
784 DESCRIPTION
785 Function to start the DFS CAC timer when SAP is started on DFS Channel
786 DEPENDENCIES
787 NA.
788
789 PARAMETERS
790
791 IN
792 sapContext: SAP Context
793 RETURN VALUE
794 DFS Timer start status
795 SIDE EFFECTS
796 ============================================================================*/
797
798int sap_start_dfs_cac_timer(ptSapContext sapContext);
799
800/** sap_hdd_event_to_string() - convert hdd event to string
801 * @event: eSapHddEvent event type
802 *
803 * This function converts eSapHddEvent into string
804 *
805 * Return: string for the @event.
806 */
807static uint8_t *sap_hdd_event_to_string(eSapHddEvent event)
808{
809 switch (event) {
810 CASE_RETURN_STRING(eSAP_START_BSS_EVENT);
811 CASE_RETURN_STRING(eSAP_STOP_BSS_EVENT);
812 CASE_RETURN_STRING(eSAP_STA_ASSOC_IND);
813 CASE_RETURN_STRING(eSAP_STA_ASSOC_EVENT);
814 CASE_RETURN_STRING(eSAP_STA_REASSOC_EVENT);
815 CASE_RETURN_STRING(eSAP_STA_DISASSOC_EVENT);
816 CASE_RETURN_STRING(eSAP_STA_SET_KEY_EVENT);
817 CASE_RETURN_STRING(eSAP_STA_MIC_FAILURE_EVENT);
818 CASE_RETURN_STRING(eSAP_ASSOC_STA_CALLBACK_EVENT);
819 CASE_RETURN_STRING(eSAP_GET_WPSPBC_SESSION_EVENT);
820 CASE_RETURN_STRING(eSAP_WPS_PBC_PROBE_REQ_EVENT);
821 CASE_RETURN_STRING(eSAP_INDICATE_MGMT_FRAME);
822 CASE_RETURN_STRING(eSAP_REMAIN_CHAN_READY);
823 CASE_RETURN_STRING(eSAP_SEND_ACTION_CNF);
824 CASE_RETURN_STRING(eSAP_DISCONNECT_ALL_P2P_CLIENT);
825 CASE_RETURN_STRING(eSAP_MAC_TRIG_STOP_BSS_EVENT);
826 CASE_RETURN_STRING(eSAP_UNKNOWN_STA_JOIN);
827 CASE_RETURN_STRING(eSAP_MAX_ASSOC_EXCEEDED);
828 CASE_RETURN_STRING(eSAP_CHANNEL_CHANGE_EVENT);
829 CASE_RETURN_STRING(eSAP_DFS_CAC_START);
830 CASE_RETURN_STRING(eSAP_DFS_CAC_END);
831 CASE_RETURN_STRING(eSAP_DFS_RADAR_DETECT);
832 CASE_RETURN_STRING(eSAP_DFS_NOL_GET);
833 CASE_RETURN_STRING(eSAP_DFS_NOL_SET);
834 CASE_RETURN_STRING(eSAP_DFS_NO_AVAILABLE_CHANNEL);
835#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
836 CASE_RETURN_STRING(eSAP_ACS_SCAN_SUCCESS_EVENT);
837#endif
838 CASE_RETURN_STRING(eSAP_ACS_CHANNEL_SELECTED);
839 default:
840 return "eSAP_HDD_EVENT_UNKNOWN";
841 }
842}
843
844/*----------------------------------------------------------------------------
845 * Externalized Function Definitions
846 * -------------------------------------------------------------------------*/
847
848/*----------------------------------------------------------------------------
849 * Function Declarations and Documentation
850 * -------------------------------------------------------------------------*/
851
852/*==========================================================================
853 FUNCTION sap_event_init
854
855 DESCRIPTION
856 Function for initializing sWLAN_SAPEvent structure
857
858 DEPENDENCIES
859 NA.
860
861 PARAMETERS
862
863 IN
864 sapEvent : State machine event
865
866 RETURN VALUE
867
868 None
869
870 SIDE EFFECTS
871 ============================================================================*/
872static inline void sap_event_init(ptWLAN_SAPEvent sapEvent)
873{
874 sapEvent->event = eSAP_MAC_SCAN_COMPLETE;
875 sapEvent->params = 0;
876 sapEvent->u1 = 0;
877 sapEvent->u2 = 0;
878}
879
880#ifdef WLAN_ENABLE_CHNL_MATRIX_RESTRICTION
881/*
882 * This function gives the leakage matrix for given NOL channel and cbMode
883 *
884 * PARAMETERS
885 * IN
886 * sapContext : Pointer to vos global context structure
887 * cbMode : target channel bonding mode
888 * NOL_channel : the NOL channel whose leakage matrix is required
889 * pTarget_chnl_mtrx : pointer to target channel matrix returned.
890 *
891 * RETURN VALUE
892 * BOOLEAN
893 * TRUE: leakage matrix was found
894 * FALSE: leakage matrix was not found
895 */
896bool
897sap_find_target_channel_in_channel_matrix(ptSapContext sapContext,
898 ePhyChanBondState cbMode,
899 uint8_t NOL_channel,
900 tSapTxLeakInfo **pTarget_chnl_mtrx)
901{
902 tSapTxLeakInfo *target_chan_matrix = NULL;
903 tSapChanMatrixInfo *pchan_matrix = NULL;
904 uint32_t nchan_matrix;
905 int i = 0;
906
907 switch (cbMode) {
908 case PHY_SINGLE_CHANNEL_CENTERED:
909 /* HT20 */
910 pchan_matrix = ht20_chan;
911 nchan_matrix = CDF_ARRAY_SIZE(ht20_chan);
912 break;
913 case PHY_DOUBLE_CHANNEL_HIGH_PRIMARY:
914 case PHY_DOUBLE_CHANNEL_LOW_PRIMARY:
915 /* HT40 */
916 pchan_matrix = ht40_chan;
917 nchan_matrix = CDF_ARRAY_SIZE(ht40_chan);
918 break;
919#ifdef WLAN_FEATURE_11AC
920 case PHY_QUADRUPLE_CHANNEL_20MHZ_LOW_40MHZ_LOW:
921 case PHY_QUADRUPLE_CHANNEL_20MHZ_HIGH_40MHZ_LOW:
922 case PHY_QUADRUPLE_CHANNEL_20MHZ_LOW_40MHZ_HIGH:
923 case PHY_QUADRUPLE_CHANNEL_20MHZ_HIGH_40MHZ_HIGH:
924 /* HT80 */
925 pchan_matrix = ht80_chan;
926 nchan_matrix = CDF_ARRAY_SIZE(ht80_chan);
927 break;
928#endif
929 default:
930 /* handle exception and fall back to HT20 table */
931 pchan_matrix = ht20_chan;
932 nchan_matrix = CDF_ARRAY_SIZE(ht20_chan);
933 break;
934 }
935
936 for (i = 0; i < nchan_matrix; i++) {
937 /* find the SAP channel to map the leakage matrix */
938 if (NOL_channel == pchan_matrix[i].channel) {
939 target_chan_matrix = pchan_matrix[i].chan_matrix;
940 break;
941 }
942 }
943
944 if (NULL == target_chan_matrix) {
945 return false;
946 } else {
947 *pTarget_chnl_mtrx = target_chan_matrix;
948 return true;
949 }
950}
951
952/**
953 * sap_mark_channels_leaking_into_nol() - to mark channel leaking in to nol
954 * @sap_ctx: pointer to SAP context
955 * @cb_mode: channel bonding mode
956 * @nol: nol info
957 * @temp_ch_lst_sz: the target channel list
958 * @temp_ch_lst: the target channel list
959 *
960 * This function removes the channels from temp channel list that
961 * (if selected as target channel) will cause leakage in one of
962 * the NOL channels
963 *
964 * Return: CDF_STATUS
965 */
966
967CDF_STATUS
968sap_mark_channels_leaking_into_nol(ptSapContext sap_ctx,
969 ePhyChanBondState cb_mode,
970 tSapDfsNolInfo *nol,
971 uint8_t temp_ch_lst_sz,
972 uint8_t *temp_ch_lst)
973{
974 tSapTxLeakInfo *target_chan_matrix = NULL;
975 uint32_t num_channel = (RF_CHAN_144 - RF_CHAN_36) + 1;
976 uint32_t i = 0;
977 uint32_t j = 0;
978 uint32_t k = 0;
979 uint8_t dfs_nol_channel;
980
981
982 /* traverse target_chan_matrix and */
983 for (i = 0; i < NUM_5GHZ_CHANNELS ; i++) {
984 dfs_nol_channel = nol[i].dfs_channel_number;
985 if (nol[i].radar_status_flag == eSAP_DFS_CHANNEL_USABLE ||
986 nol[i].radar_status_flag == eSAP_DFS_CHANNEL_AVAILABLE) {
987 /* not present in NOL */
988 continue;
989 }
990 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_DEBUG,
991 FL("sapdfs: processing NOL channel: %d"),
992 dfs_nol_channel);
993 if (false == sap_find_target_channel_in_channel_matrix(
994 sap_ctx, cb_mode, dfs_nol_channel,
995 &target_chan_matrix)) {
996 /*
997 * should never happen, we should always find a table
998 * here, if we don't, need a fix here!
999 */
1000 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_ERROR,
1001 FL("Couldn't find target channel matrix!"));
1002 CDF_ASSERT(0);
1003 return CDF_STATUS_E_FAILURE;
1004 }
1005 /*
1006 * following is based on assumption that both temp_ch_lst
1007 * and target channel matrix are in increasing order of
1008 * channelID
1009 */
1010 for (j = 0, k = 0; j < temp_ch_lst_sz && k < num_channel;) {
1011 if (temp_ch_lst[j] == 0) {
1012 j++;
1013 continue;
1014 }
1015 if (target_chan_matrix[k].leak_chan != temp_ch_lst[j]) {
1016 k++;
1017 continue;
1018 }
1019 /*
1020 * check leakage from candidate channel
1021 * to NOL channel
1022 */
1023 if (target_chan_matrix[k].leak_lvl <=
1024 SAP_TX_LEAKAGE_THRES) {
1025 /*
1026 * candidate channel will have
1027 * bad leakage in NOL channel,
1028 * remove from temp list
1029 */
1030 CDF_TRACE(CDF_MODULE_ID_SAP,
1031 CDF_TRACE_LEVEL_INFO_LOW,
1032 FL("sapdfs: channel: %d will have bad leakage due to channel: %d\n"),
1033 dfs_nol_channel, temp_ch_lst[j]);
1034 temp_ch_lst[j] = 0;
1035 break;
1036 }
1037 j++;
1038 k++;
1039 }
1040 } /* end of loop that selects each NOL */
1041 return CDF_STATUS_SUCCESS;
1042}
1043#endif /* end of WLAN_ENABLE_CHNL_MATRIX_RESTRICTION */
1044
1045/*
1046 * This function adds availabe channel to bitmap
1047 *
1048 * PARAMETERS
1049 * IN
1050 * pBitmap: bitmap to populate
1051 * channel: channel to set in bitmap
1052 */
1053static void sap_set_bitmap(chan_bonding_bitmap *pBitmap, uint8_t channel)
1054{
1055 int i = 0;
1056 int start_channel = 0;
1057 for (i = 0; i < MAX_80MHZ_BANDS; i++) {
1058 start_channel = pBitmap->chanBondingSet[i].startChannel;
1059 if (channel >= start_channel && channel <= start_channel + 12) {
1060 pBitmap->chanBondingSet[i].channelMap |=
1061 1 << ((channel - start_channel) / 4);
1062 return;
1063 }
1064 }
1065 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_ERROR,
1066 FL("Channel=%d is not in the bitmap"), channel);
1067}
1068
1069/**
1070 * sap_populate_available_channels - To populate available channel
1071 * @bitmap: bitmap to populate
1072 * @current_cbmode: cb mode to check for channel availability
1073 * @avail_chnl: available channel list to populate
1074 *
1075 * This function reads the bitmap and populates available channel
1076 * list according to channel bonding mode. This will be called for
1077 * 80 MHz and 40 Mhz only. For 20 MHz no need for bitmap hence list
1078 * is directly created while parsing the main list
1079 *
1080 * Return: number of channels found
1081 */
1082static uint8_t sap_populate_available_channels(chan_bonding_bitmap *bitmap,
1083 ePhyChanBondState current_cbmode,
1084 uint8_t *avail_chnl)
1085{
1086 uint8_t i = 0;
1087 uint8_t chnl_count = 0;
1088 uint8_t start_channel = 0;
1089
1090 switch (current_cbmode) {
1091#ifdef WLAN_FEATURE_11AC
1092 /* HT80 */
1093 case PHY_QUADRUPLE_CHANNEL_20MHZ_LOW_40MHZ_LOW:
1094 case PHY_QUADRUPLE_CHANNEL_20MHZ_HIGH_40MHZ_LOW:
1095 case PHY_QUADRUPLE_CHANNEL_20MHZ_LOW_40MHZ_HIGH:
1096 case PHY_QUADRUPLE_CHANNEL_20MHZ_HIGH_40MHZ_HIGH:
1097 for (i = 0; i < MAX_80MHZ_BANDS; i++) {
1098 start_channel = bitmap->chanBondingSet[i].startChannel;
1099 if (bitmap->chanBondingSet[i].channelMap ==
1100 SAP_80MHZ_MASK) {
1101 avail_chnl[chnl_count++] = start_channel;
1102 avail_chnl[chnl_count++] = start_channel + 4;
1103 avail_chnl[chnl_count++] = start_channel + 8;
1104 avail_chnl[chnl_count++] = start_channel + 12;
1105 }
1106 }
1107 break;
1108#endif
1109 /* HT40 */
1110 case PHY_DOUBLE_CHANNEL_HIGH_PRIMARY:
1111 case PHY_DOUBLE_CHANNEL_LOW_PRIMARY:
1112 for (i = 0; i < MAX_80MHZ_BANDS; i++) {
1113 start_channel = bitmap->chanBondingSet[i].startChannel;
1114 if ((bitmap->chanBondingSet[i].channelMap &
1115 SAP_40MHZ_MASK_L) == SAP_40MHZ_MASK_L) {
1116 avail_chnl[chnl_count++] = start_channel;
1117 avail_chnl[chnl_count++] = start_channel + 4;
1118 } else if ((bitmap->chanBondingSet[i].channelMap &
1119 SAP_40MHZ_MASK_H) == SAP_40MHZ_MASK_H) {
1120 avail_chnl[chnl_count++] = start_channel + 8;
1121 avail_chnl[chnl_count++] = start_channel + 12;
1122 }
1123 }
1124 break;
1125 default:
1126 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_ERROR,
1127 FL("Invalid case."));
1128 break;
1129 }
1130
1131 return chnl_count;
1132}
1133
1134/*
1135 * FUNCTION sap_dfs_is_w53_invalid
1136 *
1137 * DESCRIPTION Checks if the passed channel is W53 and returns if
1138 * SAP W53 opearation is allowed.
1139 *
1140 * DEPENDENCIES PARAMETERS
1141 * IN hHAL : HAL pointer
1142 * channelID: Channel Number to be verified
1143 *
1144 * RETURN VALUE : bool
1145 * true: If W53 operation is disabled
1146 * false: If W53 operation is enabled
1147 *
1148 * SIDE EFFECTS
1149 */
1150bool sap_dfs_is_w53_invalid(tHalHandle hHal, uint8_t channelID)
1151{
1152 tpAniSirGlobal pMac;
1153
1154 pMac = PMAC_STRUCT(hHal);
1155 if (NULL == pMac) {
1156 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_ERROR,
1157 FL("invalid pMac"));
1158 return false;
1159 }
1160
1161 /*
1162 * Check for JAPAN W53 Channel operation capability
1163 */
1164 if (true == pMac->sap.SapDfsInfo.is_dfs_w53_disabled &&
1165 true == IS_CHAN_JAPAN_W53(channelID)) {
1166 return true;
1167 }
1168
1169 return false;
1170}
1171
1172/*
1173 * FUNCTION sap_dfs_is_channel_in_preferred_location
1174 *
1175 * DESCRIPTION Checks if the passed channel is in accordance with preferred
1176 * Channel location settings.
1177 *
1178 * DEPENDENCIES PARAMETERS
1179 * IN hHAL : HAL pointer
1180 * channelID: Channel Number to be verified
1181 *
1182 * RETURN VALUE :bool
1183 * true:If Channel location is same as the preferred location
1184 * false:If Channel location is not same as the preferred location
1185 *
1186 * SIDE EFFECTS
1187 */
1188bool sap_dfs_is_channel_in_preferred_location(tHalHandle hHal, uint8_t channelID)
1189{
1190 tpAniSirGlobal pMac;
1191
1192 pMac = PMAC_STRUCT(hHal);
1193 if (NULL == pMac) {
1194 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_ERROR,
1195 FL("invalid pMac"));
1196 return true;
1197 }
1198 if ((SAP_CHAN_PREFERRED_INDOOR ==
1199 pMac->sap.SapDfsInfo.sap_operating_chan_preferred_location) &&
1200 (true == IS_CHAN_JAPAN_OUTDOOR(channelID))) {
1201 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_LOW,
1202 FL
1203 ("CHAN=%d is Outdoor so invalid,preferred Indoor only"),
1204 channelID);
1205 return false;
1206 } else if ((SAP_CHAN_PREFERRED_OUTDOOR ==
1207 pMac->sap.SapDfsInfo.sap_operating_chan_preferred_location)
1208 && (true == IS_CHAN_JAPAN_INDOOR(channelID))) {
1209 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_LOW,
1210 FL
1211 ("CHAN=%d is Indoor so invalid,preferred Outdoor only"),
1212 channelID);
1213 return false;
1214 }
1215
1216 return true;
1217}
1218
1219#ifdef FEATURE_AP_MCC_CH_AVOIDANCE
1220/**
1221 * sap_check_in_avoid_ch_list() - checks if given channel present is channel
1222 * avoidance list
1223 *
1224 * @sap_ctx: sap context.
1225 * @channel: channel to be checked in sap_ctx's avoid ch list
1226 *
1227 * sap_ctx contains sap_avoid_ch_info strcut containing the list of channels on
1228 * which MDM device's AP with MCC was detected. This function checks if given
1229 * channel is present in that list.
1230 *
1231 * Return: true, if channel was present, false othersie.
1232 */
1233bool sap_check_in_avoid_ch_list(ptSapContext sap_ctx, uint8_t channel)
1234{
1235 uint8_t i = 0;
1236 struct sap_avoid_channels_info *ie_info =
1237 &sap_ctx->sap_detected_avoid_ch_ie;
1238 for (i = 0; i < sizeof(ie_info->channels); i++)
1239 if (ie_info->channels[i] == channel)
1240 return true;
1241 return false;
1242}
1243#endif /* FEATURE_AP_MCC_CH_AVOIDANCE */
1244
1245/*
1246 * This function randomly pick up an AVAILABLE channel
1247 */
1248static uint8_t sap_random_channel_sel(ptSapContext sapContext)
1249{
1250 uint32_t random_byte = 0;
1251 uint8_t available_ch_cnt = 0;
1252 uint8_t avail_dfs_chan_count = 0;
1253 uint8_t avail_non_dfs_chan_count = 0;
1254 uint8_t valid_chnl_count = 0;
1255 uint8_t availableChannels[WNI_CFG_VALID_CHANNEL_LIST_LEN] = { 0, };
1256 uint8_t avail_dfs_chan_list[WNI_CFG_VALID_CHANNEL_LIST_LEN] = {0,};
1257 uint8_t avail_non_dfs_chan_list[WNI_CFG_VALID_CHANNEL_LIST_LEN] = {0,};
1258 uint8_t target_channel = 0;
1259 bool isChannelNol = false;
1260 bool isOutOfRange = false;
1261 chan_bonding_bitmap channelBitmap;
1262 uint8_t i = 0;
1263 uint8_t channelID;
1264 tHalHandle hHal = CDS_GET_HAL_CB(sapContext->p_cds_gctx);
1265 tpAniSirGlobal pMac;
1266 uint32_t chanWidth;
1267 ePhyChanBondState cbModeCurrent;
1268 uint8_t *tmp_ch_lst = NULL;
1269 uint8_t dfs_region;
1270
1271 if (NULL == hHal) {
1272 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_ERROR,
1273 FL("invalid hHal"));
1274 return target_channel;
1275 }
1276
1277 pMac = PMAC_STRUCT(hHal);
1278 if (NULL == pMac) {
1279 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_ERROR,
1280 FL("invalid pMac"));
1281 return target_channel;
1282 }
1283
1284 /*
1285 * Retrieve the original one and store it.
1286 * use the stored original value when you call this function next time
1287 * so fall back mechanism always starts with original ini value.
1288 */
1289 if (pMac->sap.SapDfsInfo.orig_cbMode == 0) {
1290 pMac->sap.SapDfsInfo.orig_cbMode =
1291 (sapContext->ch_width_orig > CH_WIDTH_20MHZ ? 1 : 0);
1292 cbModeCurrent = pMac->sap.SapDfsInfo.orig_cbMode;
1293 } else {
1294 cbModeCurrent = pMac->sap.SapDfsInfo.orig_cbMode;
1295 }
1296
1297 /*
1298 * Retrieve the original one and store it.
1299 * use the stored original value when you call this function next time
1300 * so fall back mechanism always starts with original ini value.
1301 */
1302 if (pMac->sap.SapDfsInfo.orig_chanWidth == 0) {
1303 pMac->sap.SapDfsInfo.orig_chanWidth =
1304 sapContext->ch_width_orig;
1305 chanWidth = pMac->sap.SapDfsInfo.orig_chanWidth;
1306 } else {
1307 chanWidth = pMac->sap.SapDfsInfo.orig_chanWidth;
1308 }
1309
1310 if (sap_get5_g_hz_channel_list(sapContext)) {
1311 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_LOW,
1312 FL("Getting 5Ghz channel list failed"));
1313 return target_channel;
1314 }
1315
1316 cds_get_dfs_region(&dfs_region);
1317
1318 /*
1319 * valid_chnl_count will be used to find number of valid channels
1320 * after following for loop ends
1321 */
1322 valid_chnl_count = sapContext->SapAllChnlList.numChannel;
1323 /* loop to check ACS range or NOL channels */
1324 for (i = 0; i < sapContext->SapAllChnlList.numChannel; i++) {
1325 channelID = sapContext->SapAllChnlList.channelList[i].channel;
1326
1327 /*
1328 * IN JAPAN REGULATORY DOMAIN CHECK IF THE FOLLOWING TWO
1329 * TWO RULES APPLY AND FILTER THE AVAILABLE CHANNELS
1330 * ACCORDINGLY.
1331 *
1332 * 1. If we are operating in Japan regulatory domain
1333 * Check if Japan W53 Channel operation is NOT
1334 * allowed and if its not allowed then mark all the
1335 * W53 channels as Invalid.
1336 *
1337 * 2. If we are operating in Japan regulatory domain
1338 * Check if channel switch between Indoor/Outdoor
1339 * is allowed. If it is not allowed then limit
1340 * the avaiable channels to Indoor or Outdoor
1341 * channels only based up on the SAP Channel location
1342 * indicated by "sap_operating_channel_location" param.
1343 */
1344 if (DFS_MKK4_DOMAIN == dfs_region) {
1345 /*
1346 * Check for JAPAN W53 Channel operation capability
1347 */
1348 if (true == sap_dfs_is_w53_invalid(hHal, channelID)) {
1349 CDF_TRACE(CDF_MODULE_ID_SAP,
1350 CDF_TRACE_LEVEL_INFO_LOW,
1351 FL
1352 ("index:%d, Channel=%d Invalid,Japan W53 Disabled"),
1353 i, channelID);
1354 sapContext->SapAllChnlList.channelList[i].
1355 valid = false;
1356 valid_chnl_count--;
1357 continue;
1358 }
1359
1360 /*
1361 * If SAP's preferred channel location is Indoor
1362 * then set all the outdoor channels in the domain
1363 * to invalid.If the preferred channel location is
1364 * outdoor then set all the Indoor channels in the
1365 * domain to Invalid.
1366 */
1367 if (false ==
1368 sap_dfs_is_channel_in_preferred_location(hHal,
1369 channelID)) {
1370 CDF_TRACE(CDF_MODULE_ID_SAP,
1371 CDF_TRACE_LEVEL_INFO_LOW,
1372 FL
1373 ("CHAN=%d is invalid,preferred Channel Location %d Only"),
1374 channelID,
1375 pMac->sap.SapDfsInfo.
1376 sap_operating_chan_preferred_location);
1377 sapContext->SapAllChnlList.channelList[i].
1378 valid = false;
1379 valid_chnl_count--;
1380 continue;
1381 }
1382 }
1383
1384 if (cds_get_channel_state(channelID) ==
1385 CHANNEL_STATE_DFS) {
1386 isChannelNol =
1387 sap_dfs_is_channel_in_nol_list(sapContext,
1388 channelID,
1389 PHY_SINGLE_CHANNEL_CENTERED);
1390 if (true == isChannelNol) {
1391 /*
1392 * Mark this channel invalid since it is still
1393 * in DFS Non-Occupancy-Period which is 30 mins.
1394 */
1395 CDF_TRACE(CDF_MODULE_ID_SAP,
1396 CDF_TRACE_LEVEL_INFO_LOW,
1397 FL
1398 ("index: %d, Channel = %d Present in NOL LIST"),
1399 i, channelID);
1400 sapContext->SapAllChnlList.channelList[i].
1401 valid = false;
1402 valid_chnl_count--;
1403 continue;
1404 }
1405 }
1406
1407#ifdef FEATURE_AP_MCC_CH_AVOIDANCE
1408 /* avoid ch on which another MDM AP in MCC mode is detected */
1409 if (pMac->sap.sap_channel_avoidance
1410 && sapContext->sap_detected_avoid_ch_ie.present) {
1411 if (sap_check_in_avoid_ch_list(sapContext, channelID)) {
1412 CDF_TRACE(CDF_MODULE_ID_SAP,
1413 CDF_TRACE_LEVEL_INFO_LOW,
1414 FL("index: %d, Channel = %d, avoided due to presence of another AP+AP MCC device in same channel."),
1415 i, channelID);
1416 sapContext->SapAllChnlList.channelList[i].valid
1417 = false;
1418 }
1419 }
1420#endif /* FEATURE_AP_MCC_CH_AVOIDANCE */
1421
1422 /* check if the channel is within ACS channel range */
1423 isOutOfRange = sap_acs_channel_check(sapContext, channelID);
1424 if (true == isOutOfRange) {
1425 /*
1426 * mark this channel invalid since it is out of ACS
1427 * channel range
1428 */
1429 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_LOW,
1430 FL
1431 ("index: %d, Channel = %d out of ACS channel range"),
1432 i, channelID);
1433 sapContext->SapAllChnlList.channelList[i].valid = false;
1434 valid_chnl_count--;
1435 continue;
1436 }
1437 } /* end of check for NOL or ACS channels */
1438
1439 /* valid_chnl_count now have number of valid channels */
1440 tmp_ch_lst = cdf_mem_malloc(valid_chnl_count);
1441 if (tmp_ch_lst == NULL) {
1442 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_ERROR,
1443 FL("sapdfs: memory alloc failed"));
1444 return target_channel;
1445 }
1446
1447 do {
1448 uint8_t j = 0;
1449#ifdef WLAN_ENABLE_CHNL_MATRIX_RESTRICTION
1450 tSapDfsNolInfo *nol = pMac->sap.SapDfsInfo.sapDfsChannelNolList;
1451#endif
1452
1453 /* prepare temp list of just the valid channels */
1454 for (i = 0; i < sapContext->SapAllChnlList.numChannel; i++) {
1455 if (sapContext->SapAllChnlList.channelList[i].valid) {
1456 CDF_TRACE(CDF_MODULE_ID_SAP,
1457 CDF_TRACE_LEVEL_ERROR,
1458 FL
1459 ("sapdfs: Adding Channel = %d to temp List"),
1460 sapContext->SapAllChnlList.
1461 channelList[i].channel);
1462 tmp_ch_lst[j++] = sapContext->SapAllChnlList.
1463 channelList[i].channel;
1464 }
1465 }
1466
1467#ifdef WLAN_ENABLE_CHNL_MATRIX_RESTRICTION
1468 CDF_TRACE(CDF_MODULE_ID_SAP,
1469 CDF_TRACE_LEVEL_ERROR,
1470 FL
1471 ("sapdfs: Processing temp channel list against NOL.")
1472 );
1473 if (CDF_STATUS_SUCCESS !=
1474 sap_mark_channels_leaking_into_nol(sapContext,
1475 cbModeCurrent,
1476 nol,
1477 valid_chnl_count,
1478 tmp_ch_lst)) {
1479 cdf_mem_free(tmp_ch_lst);
1480 return target_channel;
1481 }
1482#endif
1483 cdf_mem_zero(availableChannels, sizeof(availableChannels));
1484 cdf_mem_zero(&channelBitmap, sizeof(channelBitmap));
1485 channelBitmap.chanBondingSet[0].startChannel = 36;
1486 channelBitmap.chanBondingSet[1].startChannel = 52;
1487 channelBitmap.chanBondingSet[2].startChannel = 100;
1488 channelBitmap.chanBondingSet[3].startChannel = 116;
1489 channelBitmap.chanBondingSet[3].startChannel = 132;
1490 channelBitmap.chanBondingSet[4].startChannel = 149;
1491 /* now loop through whatever is left of channel list */
1492 CDF_TRACE(CDF_MODULE_ID_SAP,
1493 CDF_TRACE_LEVEL_ERROR,
1494 FL("sapdfs: Moving temp channel list to final."));
1495 for (i = 0; i < valid_chnl_count; i++) {
1496 /*
1497 * add channel from temp channel list to bitmap or fianl
1498 * channel list (in case of 20MHz width)
1499 */
1500 if (tmp_ch_lst[i] != 0) {
1501 CDF_TRACE(CDF_MODULE_ID_SAP,
1502 CDF_TRACE_LEVEL_DEBUG,
1503 FL("sapdfs: processing channel: %d "),
1504 tmp_ch_lst[i]);
1505 /*
1506 * for 20MHz, directly create available
1507 * channel list
1508 */
1509 if (cbModeCurrent ==
1510 PHY_SINGLE_CHANNEL_CENTERED) {
1511 CDF_TRACE(CDF_MODULE_ID_SAP,
1512 CDF_TRACE_LEVEL_DEBUG,
1513 FL
1514 ("sapdfs: Channel=%d added to available list"),
1515 tmp_ch_lst[i]);
1516 availableChannels[available_ch_cnt++] =
1517 tmp_ch_lst[i];
1518 } else {
1519 CDF_TRACE(CDF_MODULE_ID_SAP,
1520 CDF_TRACE_LEVEL_DEBUG,
1521 FL("sapdfs: Channel=%d added to bitmap"),
1522 tmp_ch_lst[i]);
1523 sap_set_bitmap(&channelBitmap,
1524 tmp_ch_lst[i]);
1525 }
1526 }
1527 }
1528
1529 /*
1530 * if 40 MHz or 80 MHz, populate available
1531 * channel list from bitmap
1532 */
1533 if (cbModeCurrent != PHY_SINGLE_CHANNEL_CENTERED) {
1534 available_ch_cnt =
1535 sap_populate_available_channels(&channelBitmap,
1536 cbModeCurrent,
1537 availableChannels);
1538 /*
1539 * if no valid channel bonding found,
1540 * fallback to lower bandwidth
1541 */
1542 if (available_ch_cnt == 0) {
1543 if (cbModeCurrent >=
1544 PHY_QUADRUPLE_CHANNEL_20MHZ_LOW_40MHZ_CENTERED) {
1545 CDF_TRACE(CDF_MODULE_ID_SAP,
1546 CDF_TRACE_LEVEL_WARN,
1547 FL
1548 ("sapdfs:No 80MHz cb found, falling to 40MHz"));
1549 CDF_TRACE(CDF_MODULE_ID_SAP,
1550 CDF_TRACE_LEVEL_WARN,
1551 FL
1552 ("sapdfs:Changing chanWidth from [%d] to [%d]"),
1553 chanWidth,
1554 CH_WIDTH_40MHZ);
1555 CDF_TRACE(CDF_MODULE_ID_SAP,
1556 CDF_TRACE_LEVEL_WARN,
1557 FL
1558 ("sapdfs:Changing CB mode from [%d] to [%d]"),
1559 cbModeCurrent,
1560 PHY_DOUBLE_CHANNEL_LOW_PRIMARY
1561 );
1562 cbModeCurrent =
1563 PHY_DOUBLE_CHANNEL_LOW_PRIMARY;
1564 chanWidth = CH_WIDTH_40MHZ;
1565 /* continue to start of do loop */
1566 continue;
1567 } else if (cbModeCurrent >=
1568 PHY_DOUBLE_CHANNEL_LOW_PRIMARY) {
1569 CDF_TRACE(CDF_MODULE_ID_SAP,
1570 CDF_TRACE_LEVEL_WARN,
1571 FL
1572 ("sapdfs:No 40MHz cb found, falling to 20MHz"));
1573 CDF_TRACE(CDF_MODULE_ID_SAP,
1574 CDF_TRACE_LEVEL_WARN,
1575 FL
1576 ("sapdfs:Changing chanWidth from [%d] to [%d]"),
1577 chanWidth,
1578 CH_WIDTH_20MHZ);
1579 CDF_TRACE(CDF_MODULE_ID_SAP,
1580 CDF_TRACE_LEVEL_WARN,
1581 FL
1582 ("sapdfs:Changing CB mode from [%d] to [%d]"),
1583 cbModeCurrent,
1584 PHY_SINGLE_CHANNEL_CENTERED);
1585 cbModeCurrent =
1586 PHY_SINGLE_CHANNEL_CENTERED;
1587 chanWidth = CH_WIDTH_20MHZ;
1588 /* continue to start of do loop */
1589 continue;
1590 }
1591 }
1592 }
1593
1594 /*
1595 * by now, available channels list will be populated or
1596 * no channels are avaialbe
1597 */
1598 if (available_ch_cnt) {
1599 for (i = 0; i < available_ch_cnt; i++) {
1600 if (CDS_IS_DFS_CH(availableChannels[i])) {
1601 avail_dfs_chan_list[
1602 avail_dfs_chan_count++] =
1603 availableChannels[i];
1604 } else {
1605 avail_non_dfs_chan_list[
1606 avail_non_dfs_chan_count++] =
1607 availableChannels[i];
1608 }
1609 }
1610 } else {
1611 CDF_TRACE(CDF_MODULE_ID_SAP,
1612 CDF_TRACE_LEVEL_INFO_LOW,
1613 FL("No target channel found"));
1614 }
1615
1616 cds_rand_get_bytes(0, (uint8_t *)&random_byte, 1);
1617
1618 /* Give preference to non-DFS channel */
1619 if (!pMac->f_prefer_non_dfs_on_radar) {
1620 i = (random_byte + cdf_mc_timer_get_system_ticks()) %
1621 available_ch_cnt;
1622 target_channel = availableChannels[i];
1623 } else if (avail_non_dfs_chan_count) {
1624 i = (random_byte + cdf_mc_timer_get_system_ticks()) %
1625 avail_non_dfs_chan_count;
1626 target_channel = avail_non_dfs_chan_list[i];
1627 } else {
1628 i = (random_byte + cdf_mc_timer_get_system_ticks()) %
1629 avail_dfs_chan_count;
1630 target_channel = avail_dfs_chan_list[i];
1631 }
1632
1633 pMac->sap.SapDfsInfo.new_chanWidth = chanWidth;
1634 pMac->sap.SapDfsInfo.new_cbMode = cbModeCurrent;
1635 CDF_TRACE(CDF_MODULE_ID_SAP,
1636 CDF_TRACE_LEVEL_INFO_LOW,
1637 FL("sapdfs: New CB mode = %d"),
1638 pMac->sap.SapDfsInfo.new_cbMode);
1639 CDF_TRACE(CDF_MODULE_ID_SAP,
1640 CDF_TRACE_LEVEL_INFO_LOW,
1641 FL("sapdfs: New Channel width = %d"),
1642 pMac->sap.SapDfsInfo.new_chanWidth);
1643 CDF_TRACE(CDF_MODULE_ID_SAP,
1644 CDF_TRACE_LEVEL_INFO_LOW,
1645 FL("sapdfs: target_channel = %d"),
1646 target_channel);
1647 break;
1648 /* this loop will iterate at max 3 times */
1649 } while (1);
1650 cdf_mem_free(tmp_ch_lst);
1651 return target_channel;
1652}
1653
1654bool sap_acs_channel_check(ptSapContext sapContext, uint8_t channelNumber)
1655{
1656 int i = 0;
1657 if (!sapContext->acs_cfg->acs_mode)
1658 return false;
1659
1660 if ((channelNumber >= sapContext->acs_cfg->start_ch) ||
1661 (channelNumber <= sapContext->acs_cfg->end_ch)) {
1662 if (!sapContext->acs_cfg->ch_list) {
1663 return false;
1664 } else {
1665 for (i = 0; i < sapContext->acs_cfg->ch_list_count; i++)
1666 if (channelNumber ==
1667 sapContext->acs_cfg->ch_list[i])
1668 return false;
1669 }
1670 }
1671 return true;
1672}
1673
1674/**
1675 * sap_mark_dfs_channels() - to mark dfs channel
1676 * @sapContext: pointer sap context
1677 * @channels: list of channels
1678 * @numChannels: number of channels
1679 * @time: time
1680 *
1681 * Mark the channels in NOL with time and eSAP_DFS_CHANNEL_UNAVAILABLE
1682 *
1683 * Return: none
1684 */
1685void sap_mark_dfs_channels(ptSapContext sapContext, uint8_t *channels,
1686 uint8_t numChannels, uint64_t time)
1687{
1688 int i, j;
1689 tSapDfsNolInfo *psapDfsChannelNolList = NULL;
1690 uint8_t nRegDomainDfsChannels;
1691 tHalHandle hHal;
1692 tpAniSirGlobal pMac;
1693
1694 hHal = CDS_GET_HAL_CB(sapContext->p_cds_gctx);
1695 if (NULL == channels)
1696 return;
1697 if (NULL == hHal) {
1698 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_ERROR,
1699 FL("invalid hHal"));
1700 return;
1701 }
1702 pMac = PMAC_STRUCT(hHal);
1703 if (NULL == pMac) {
1704 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_ERROR,
1705 FL("invalid pMac"));
1706 return;
1707 }
1708
1709 /*
1710 * Mark the current channel on which Radar is found
1711 * in the NOL list as eSAP_DFS_CHANNEL_UNAVAILABLE.
1712 */
1713 psapDfsChannelNolList = pMac->sap.SapDfsInfo.sapDfsChannelNolList;
1714 nRegDomainDfsChannels =
1715 pMac->sap.SapDfsInfo.numCurrentRegDomainDfsChannels;
1716
1717 for (i = 0; i < numChannels; i++) {
1718 for (j = 0; j <= nRegDomainDfsChannels; j++) {
1719 if (!(psapDfsChannelNolList[j].dfs_channel_number ==
1720 channels[i]))
1721 continue;
1722 /*
1723 * If channel is already in NOL, don't update it again.
1724 * This is useful when marking bonding channels which
1725 * are already unavailable.
1726 */
1727 if (psapDfsChannelNolList[j].radar_status_flag ==
1728 eSAP_DFS_CHANNEL_UNAVAILABLE) {
1729 CDF_TRACE(CDF_MODULE_ID_SAP,
1730 CDF_TRACE_LEVEL_INFO_HIGH,
1731 FL("Channel=%d already in NOL"),
1732 channels[i]);
1733 continue;
1734 }
1735 /*
1736 * Capture the Radar Found timestamp on the
1737 * Current Channel in ms.
1738 */
1739 psapDfsChannelNolList[j].radar_found_timestamp = time;
1740 /* Mark the Channel to be unavailble for next 30 mins */
1741 psapDfsChannelNolList[j].radar_status_flag =
1742 eSAP_DFS_CHANNEL_UNAVAILABLE;
1743
1744 CDF_TRACE(CDF_MODULE_ID_SAP,
1745 CDF_TRACE_LEVEL_INFO_HIGH,
1746 FL("Channel=%d Added to NOL LIST"),
1747 channels[i]);
1748 }
1749 }
1750}
1751
1752/*
1753 * This Function is to get bonding channels from primary channel.
1754 *
1755 */
1756uint8_t sap_get_bonding_channels(ptSapContext sapContext, uint8_t channel,
1757 uint8_t *channels, uint8_t size,
1758 ePhyChanBondState chanBondState)
1759{
1760 tHalHandle hHal = CDS_GET_HAL_CB(sapContext->p_cds_gctx);
1761 tpAniSirGlobal pMac;
1762 uint8_t numChannel;
1763
1764 if (channels == NULL)
1765 return 0;
1766
1767 if (size < MAX_BONDED_CHANNELS)
1768 return 0;
1769
1770 if (NULL != hHal) {
1771 pMac = PMAC_STRUCT(hHal);
1772 } else
1773 return 0;
1774
1775 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO,
1776 FL("cbmode: %d, channel: %d"), chanBondState, channel);
1777
1778 switch (chanBondState) {
1779 case PHY_SINGLE_CHANNEL_CENTERED:
1780 numChannel = 1;
1781 channels[0] = channel;
1782 break;
1783 case PHY_DOUBLE_CHANNEL_HIGH_PRIMARY:
1784 numChannel = 2;
1785 channels[0] = channel - 4;
1786 channels[1] = channel;
1787 break;
1788 case PHY_DOUBLE_CHANNEL_LOW_PRIMARY:
1789 numChannel = 2;
1790 channels[0] = channel;
1791 channels[1] = channel + 4;
1792 break;
1793#ifdef WLAN_FEATURE_11AC
1794 case PHY_QUADRUPLE_CHANNEL_20MHZ_LOW_40MHZ_LOW:
1795 numChannel = 4;
1796 channels[0] = channel;
1797 channels[1] = channel + 4;
1798 channels[2] = channel + 8;
1799 channels[3] = channel + 12;
1800 break;
1801 case PHY_QUADRUPLE_CHANNEL_20MHZ_HIGH_40MHZ_LOW:
1802 numChannel = 4;
1803 channels[0] = channel - 4;
1804 channels[1] = channel;
1805 channels[2] = channel + 4;
1806 channels[3] = channel + 8;
1807 break;
1808 case PHY_QUADRUPLE_CHANNEL_20MHZ_LOW_40MHZ_HIGH:
1809 numChannel = 4;
1810 channels[0] = channel - 8;
1811 channels[1] = channel - 4;
1812 channels[2] = channel;
1813 channels[3] = channel + 4;
1814 break;
1815 case PHY_QUADRUPLE_CHANNEL_20MHZ_HIGH_40MHZ_HIGH:
1816 numChannel = 4;
1817 channels[0] = channel - 12;
1818 channels[1] = channel - 8;
1819 channels[2] = channel - 4;
1820 channels[3] = channel;
1821 break;
1822#endif
1823 default:
1824 numChannel = 1;
1825 channels[0] = channel;
1826 break;
1827 }
1828
1829 return numChannel;
1830}
1831
1832/**
1833 * sap_dfs_check_if_channel_avaialable() - Check if a channel is out of NOL
1834 * @nol: Pointer to the Non-Occupancy List.
1835 *
1836 * This function Checks if a given channel is available or
1837 * usable or unavailable based on the time lapse since the
1838 * last radar time stamp.
1839 *
1840 * Return: true if channel available or usable, false if unavailable.
1841 */
1842static bool sap_dfs_check_if_channel_avaialable(tSapDfsNolInfo *nol)
1843{
1844 uint64_t time_since_last_radar, time_when_radar_found, current_time = 0;
1845 uint64_t max_jiffies;
1846
1847 if ((nol->radar_status_flag == eSAP_DFS_CHANNEL_USABLE) ||
1848 (nol->radar_status_flag == eSAP_DFS_CHANNEL_AVAILABLE)) {
1849 /*
1850 * Allow SAP operation on this channel
1851 * either the DFS channel has not been used
1852 * for SAP operation or it is available for
1853 * SAP operation since it is past
1854 * Non-Occupancy-Period so, return false.
1855 */
1856 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_LOW,
1857 FL("Chan=%d not in NOL,CHAN AVAILABLE"),
1858 nol->dfs_channel_number);
1859 return true;
1860 } else if (nol->radar_status_flag == eSAP_DFS_CHANNEL_UNAVAILABLE) {
1861 /*
1862 * If a DFS Channel is UNAVAILABLE then
1863 * check to see if it is past
1864 * Non-occupancy-period
1865 * of 30 minutes. If it is past 30 mins then
1866 * mark the channel as AVAILABLE and return
1867 * false as the channel is not anymore in
1868 * NON-Occupancy-Period.
1869 */
1870 time_when_radar_found = nol->radar_found_timestamp;
1871 current_time = cds_get_monotonic_boottime();
1872 if (current_time < time_when_radar_found) {
1873 /* cds_get_monotonic_boottime() can overflow.
1874 * Jiffies is initialized such that 32 bit jiffies
1875 * value wrap 5 minutes after boot so jiffies wrap bugs
1876 * show up earlier
1877 */
1878 max_jiffies = (uint64_t)UINT_MAX * 1000;
1879 time_since_last_radar = (max_jiffies -
1880 time_when_radar_found) + (current_time);
1881 } else {
1882 time_since_last_radar = current_time -
1883 time_when_radar_found;
1884 }
1885 if (time_since_last_radar >= SAP_DFS_NON_OCCUPANCY_PERIOD) {
1886 nol->radar_status_flag = eSAP_DFS_CHANNEL_AVAILABLE;
1887 nol->radar_found_timestamp = 0;
1888
1889 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_LOW,
1890 FL("Chan=%d not in NOL, Channel AVAILABLE"),
1891 nol->dfs_channel_number);
1892 return true;
1893 } else {
1894 /*
1895 * Channel is not still available for
1896 * SAP operation so return true; As the
1897 * Channel is still in
1898 * Non-occupancy-Period.
1899 */
1900 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_LOW,
1901 FL("Chan=%d in NOL, Channel UNAVAILBLE"),
1902 nol->dfs_channel_number);
1903 return false;
1904 }
1905 } else {
1906 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_ERROR,
1907 FL("Invalid Radar Status Flag"));
1908 }
1909 return true;
1910}
1911
1912/**
1913 * sap_dfs_is_channel_in_nol_list() - given bonded channel is available
1914 * @sap_context: Handle to SAP context.
1915 * @channel_number: Channel on which availability should be checked.
1916 * @chan_bondState: The channel bonding mode of the passed channel.
1917 *
1918 * This function Checks if a given bonded channel is available or
1919 * usable for DFS operation.
1920 *
1921 * Return: false if channel is available, true if channel is in NOL.
1922 */
1923bool
1924sap_dfs_is_channel_in_nol_list(ptSapContext sap_context,
1925 uint8_t channel_number,
1926 ePhyChanBondState chan_bondState)
1927{
1928 int i, j;
1929 tHalHandle h_hal = CDS_GET_HAL_CB(sap_context->p_cds_gctx);
1930 tpAniSirGlobal mac_ctx;
1931 uint8_t channels[MAX_BONDED_CHANNELS];
1932 uint8_t num_channels;
1933 tSapDfsNolInfo *nol;
1934 tSapDfsInfo *dfs_info;
1935 bool channel_available;
1936
1937 if (NULL == h_hal) {
1938 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_ERROR,
1939 FL("invalid h_hal"));
1940 return false;
1941 } else {
1942 mac_ctx = PMAC_STRUCT(h_hal);
1943 }
1944
1945 dfs_info = &mac_ctx->sap.SapDfsInfo;
1946 if ((dfs_info->numCurrentRegDomainDfsChannels == 0) ||
1947 (dfs_info->numCurrentRegDomainDfsChannels >
1948 NUM_5GHZ_CHANNELS)) {
1949 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_LOW,
1950 FL("invalid dfs channel count %d"),
1951 dfs_info->numCurrentRegDomainDfsChannels);
1952 return false;
1953 }
1954
1955 /* get the bonded channels */
1956 num_channels = sap_get_bonding_channels(sap_context, channel_number,
1957 channels, MAX_BONDED_CHANNELS, chan_bondState);
1958
1959 /* check for NOL, first on will break the loop */
1960 for (j = 0; j < num_channels; j++) {
1961 for (i = 0; i < dfs_info->numCurrentRegDomainDfsChannels; i++) {
1962 nol = &dfs_info->sapDfsChannelNolList[i];
1963 if (nol->dfs_channel_number != channels[j])
1964 continue;
1965
1966 channel_available =
1967 sap_dfs_check_if_channel_avaialable(nol);
1968
1969 if (channel_available == false)
1970 break;
1971
1972 } /* loop for dfs channels */
1973
1974 if (i < dfs_info->numCurrentRegDomainDfsChannels)
1975 break;
1976
1977 } /* loop for bonded channels */
1978
1979 /*
1980 * if any of the channel is not available, mark all available channels
1981 * as unavailable with same time stamp.
1982 */
1983 if (j < num_channels &&
1984 i < dfs_info->numCurrentRegDomainDfsChannels) {
1985 if (num_channels > MAX_BONDED_CHANNELS) {
1986 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_WARN,
1987 FL("num_channel>MAX_BONDED_CHANNEL, reset"));
1988 num_channels = MAX_BONDED_CHANNELS;
1989 }
1990 nol = &dfs_info->sapDfsChannelNolList[i];
1991 sap_mark_dfs_channels(sap_context, channels, num_channels,
1992 nol->radar_found_timestamp);
1993
1994 /* set DFS-NOL back to keep it update-to-date in CNSS */
1995 sap_signal_hdd_event(sap_context, NULL, eSAP_DFS_NOL_SET,
1996 (void *) eSAP_STATUS_SUCCESS);
1997
1998 return true;
1999 }
2000
2001 return false;
2002}
2003
2004/**
2005 * sap_goto_channel_sel - Function for initiating scan request for SME
2006 * @sap_context: Sap Context value.
2007 * @sap_event: State machine event
2008 * @sap_do_acs_pre_start_bss: true, if ACS scan is issued pre start BSS
2009 * false, if ACS scan is issued post start BSS.
2010 *
2011 * Initiates sme scan for ACS to pick a channel.
2012 *
2013 * Return: The CDF_STATUS code associated with performing the operation.
2014 */
2015CDF_STATUS sap_goto_channel_sel(ptSapContext sap_context,
2016 ptWLAN_SAPEvent sap_event,
2017 bool sap_do_acs_pre_start_bss)
2018{
2019
2020 /* Initiate a SCAN request */
2021 CDF_STATUS cdf_ret_status;
2022 /* To be initialised if scan is required */
2023 tCsrScanRequest scan_request;
2024 CDF_STATUS cdf_status = CDF_STATUS_SUCCESS;
2025
2026#ifdef SOFTAP_CHANNEL_RANGE
2027 uint8_t *channel_list = NULL;
2028 uint8_t num_of_channels = 0;
2029#endif
2030 tHalHandle h_hal;
2031 uint8_t con_ch;
2032
2033 h_hal = cds_get_context(CDF_MODULE_ID_SME);
2034 if (NULL == h_hal) {
2035 /* we have a serious problem */
2036 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_FATAL,
2037 FL("invalid h_hal"));
2038 return CDF_STATUS_E_FAULT;
2039 }
2040#ifdef WLAN_FEATURE_MBSSID
2041 if (cds_concurrent_beaconing_sessions_running()) {
2042 con_ch =
2043 sme_get_concurrent_operation_channel(h_hal);
2044
2045 if (con_ch && sap_context->channel == AUTO_CHANNEL_SELECT) {
2046 sap_context->dfs_ch_disable = true;
2047 } else if (con_ch && sap_context->channel != con_ch &&
2048 CDS_IS_DFS_CH(sap_context->channel)) {
2049 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_WARN,
2050 FL("MCC DFS not supported in AP_AP Mode"));
2051 return CDF_STATUS_E_ABORTED;
2052 }
2053#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
2054 if (sap_context->cc_switch_mode !=
2055 CDF_MCC_TO_SCC_SWITCH_DISABLE) {
2056 con_ch = sme_check_concurrent_channel_overlap(h_hal,
2057 sap_context->channel,
2058 sap_context->csr_roamProfile.phyMode,
2059 sap_context->cc_switch_mode);
2060 if (con_ch) {
2061 CDF_TRACE(CDF_MODULE_ID_SAP,
2062 CDF_TRACE_LEVEL_ERROR,
2063 "%s: Override ch %d to %d due to CC Intf",
2064 __func__, sap_context->channel, con_ch);
2065 sap_context->channel = con_ch;
2066 }
2067 }
2068#endif
2069 }
2070#endif
2071
2072 if (cds_get_concurrency_mode() == (CDF_STA_MASK | CDF_SAP_MASK)) {
2073#ifdef FEATURE_WLAN_STA_AP_MODE_DFS_DISABLE
2074 if (sap_context->channel == AUTO_CHANNEL_SELECT)
2075 sap_context->dfs_ch_disable = true;
2076 else if (CDS_IS_DFS_CH(sap_context->channel)) {
2077 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_WARN,
2078 FL("DFS not supported in STA_AP Mode"));
2079 return CDF_STATUS_E_ABORTED;
2080 }
2081#endif
2082#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
2083 if (sap_context->cc_switch_mode !=
2084 CDF_MCC_TO_SCC_SWITCH_DISABLE) {
2085 con_ch = sme_check_concurrent_channel_overlap(h_hal,
2086 sap_context->channel,
2087 sap_context->csr_roamProfile.phyMode,
2088 sap_context->cc_switch_mode);
2089 if (con_ch && !CDS_IS_DFS_CH(con_ch)) {
2090 CDF_TRACE(CDF_MODULE_ID_SAP,
2091 CDF_TRACE_LEVEL_ERROR,
2092 "%s: Override ch %d to %d due to CC Intf",
2093 __func__, sap_context->channel, con_ch);
2094 sap_context->channel = con_ch;
2095 }
2096 }
2097#endif
2098 }
2099
2100 if (sap_context->channel == AUTO_CHANNEL_SELECT) {
2101#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
2102 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_HIGH,
2103 FL("%s skip_acs_status = %d "), __func__,
2104 sap_context->acs_cfg->skip_scan_status);
2105 if (sap_context->acs_cfg->skip_scan_status !=
2106 eSAP_SKIP_ACS_SCAN) {
2107#endif
2108 cdf_mem_zero(&scan_request, sizeof(scan_request));
2109
2110 /*
2111 * Set scanType to Active scan. FW takes care of using passive
2112 * scan for DFS and active for non DFS channels.
2113 */
2114 scan_request.scanType = eSIR_ACTIVE_SCAN;
2115
2116 /* Set min and max channel time to zero */
2117 scan_request.minChnTime = 0;
2118 scan_request.maxChnTime = 0;
2119
2120 /* Set BSSType to default type */
2121 scan_request.BSSType = eCSR_BSS_TYPE_ANY;
2122
2123#ifndef SOFTAP_CHANNEL_RANGE
2124 /*Scan all the channels */
2125 scan_request.ChannelInfo.num_of_channels = 0;
2126
2127 scan_request.ChannelInfo.ChannelList = NULL;
2128
2129 scan_request.requestType = eCSR_SCAN_REQUEST_FULL_SCAN;
2130 /* eCSR_SCAN_REQUEST_11D_SCAN; */
2131
2132#else
2133
2134 sap_get_channel_list(sap_context, &channel_list,
2135 &num_of_channels);
2136#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
2137 if (num_of_channels != 0) {
2138#endif
2139 /*Scan the channels in the list */
2140 scan_request.ChannelInfo.numOfChannels =
2141 num_of_channels;
2142
2143 scan_request.ChannelInfo.ChannelList =
2144 channel_list;
2145
2146 scan_request.requestType =
2147 eCSR_SCAN_SOFTAP_CHANNEL_RANGE;
2148
2149 sap_context->channelList = channel_list;
2150
2151#endif
2152 /* Set requestType to Full scan */
2153
2154 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_HIGH,
2155 FL("calling sme_scan_request"));
2156#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
2157 if (sap_context->acs_cfg->skip_scan_status ==
2158 eSAP_DO_NEW_ACS_SCAN)
2159#endif
2160 sme_scan_flush_result(h_hal);
2161 if (true == sap_do_acs_pre_start_bss) {
2162 /*
2163 * when ID == 0 11D scan/active scan with callback,
2164 * min-maxChntime set in csrScanRequest()?
2165 * csrScanCompleteCallback callback
2166 * pContext scan_request_id filled up
2167 */
2168 cdf_ret_status = sme_scan_request(h_hal,
2169 sap_context->sessionId,
2170 &scan_request,
2171 &wlansap_pre_start_bss_acs_scan_callback,
2172 sap_context);
2173 } else {
2174 /*
2175 * when ID == 0 11D scan/active scan with callback,
2176 * min-maxChntime set in csrScanRequest()?
2177 * csrScanCompleteCallback callback,
2178 * pContext scan_request_id filled up
2179 */
2180 cdf_ret_status = sme_scan_request(h_hal,
2181 sap_context->sessionId,
2182 &scan_request,
2183 &wlansap_scan_callback,
2184 sap_context);
2185 }
2186 if (CDF_STATUS_SUCCESS != cdf_ret_status) {
2187 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_ERROR,
2188 FL("sme_scan_request fail %d!!!"),
2189 cdf_ret_status);
2190 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_HIGH,
2191 FL("SAP Configuring default channel, Ch=%d"),
2192 sap_context->channel);
2193 /* In case of error, switch to default channel */
2194 sap_context->channel = SAP_DEFAULT_24GHZ_CHANNEL;
2195
2196#ifdef SOFTAP_CHANNEL_RANGE
2197 if (sap_context->channelList != NULL) {
2198 sap_context->channel =
2199 sap_context->channelList[0];
2200 cdf_mem_free(sap_context->
2201 channelList);
2202 sap_context->channelList = NULL;
2203 }
2204#endif
2205 if (true == sap_do_acs_pre_start_bss) {
2206 /*
2207 * In case of ACS req before start Bss,
2208 * return failure so that the calling
2209 * fucntion can use the default channel.
2210 */
2211 return CDF_STATUS_E_FAILURE;
2212 } else {
2213 /* Fill in the event structure */
2214 sap_event_init(sap_event);
2215 /* Handle event */
2216 cdf_status = sap_fsm(sap_context, sap_event);
2217 }
2218 } else {
2219 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_HIGH,
2220 FL("return sme_ScanReq, scanID=%d, Ch=%d"),
2221 scan_request.scan_id, sap_context->channel);
2222 }
2223#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
2224 }
2225 } else {
2226 sap_context->acs_cfg->skip_scan_status = eSAP_SKIP_ACS_SCAN;
2227 }
2228
2229 if (sap_context->acs_cfg->skip_scan_status == eSAP_SKIP_ACS_SCAN) {
2230 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_ERROR,
2231 FL("## %s SKIPPED ACS SCAN"), __func__);
2232 wlansap_scan_callback(h_hal, sap_context,
2233 sap_context->sessionId, 0, eCSR_SCAN_SUCCESS);
2234 }
2235#endif
2236 } else {
2237 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_HIGH,
2238 FL("for configured channel, Ch= %d"),
2239 sap_context->channel);
2240 if (sap_do_acs_pre_start_bss == true) {
2241 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO,
2242 FL("ACS end due to Ch override. Sel Ch = %d"),
2243 sap_context->channel);
2244 sap_context->acs_cfg->pri_ch = sap_context->channel;
2245 sap_context->acs_cfg->ch_width =
2246 sap_context->ch_width_orig;
2247 sap_config_acs_result(h_hal, sap_context, 0);
2248 return CDF_STATUS_E_CANCELED;
2249 } else {
2250 /*
2251 * Fill in the event structure
2252 * Eventhough scan was not done,
2253 * means a user set channel was chosen
2254 */
2255 sap_event_init(sap_event);
2256 /* Handle event */
2257 cdf_status = sap_fsm(sap_context, sap_event);
2258 }
2259 }
2260
2261 /*
2262 * If scan failed, get default channel and advance state
2263 * machine as success with default channel
2264 *
2265 * Have to wait for the call back to be called to get the
2266 * channel cannot advance state machine here as said above
2267 */
2268 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_HIGH,
2269 FL("before exiting sap_goto_channel_sel channel=%d"),
2270 sap_context->channel);
2271
2272 return CDF_STATUS_SUCCESS;
2273}
2274
2275/*==========================================================================
2276 FUNCTION sap_OpenSession
2277
2278 DESCRIPTION
2279 Function for opening SME and SAP sessions when system is in SoftAP role
2280
2281 DEPENDENCIES
2282 NA.
2283
2284 PARAMETERS
2285
2286 IN
2287 hHal : Hal handle
2288 sapContext : Sap Context value
2289
2290 RETURN VALUE
2291 The CDF_STATUS code associated with performing the operation
2292
2293 CDF_STATUS_SUCCESS: Success
2294
2295 SIDE EFFECTS
2296 ============================================================================*/
2297CDF_STATUS sap_open_session(tHalHandle hHal, ptSapContext sapContext)
2298{
2299 uint32_t type, subType;
2300 CDF_STATUS cdf_ret_status;
2301 CDF_STATUS status = CDF_STATUS_E_FAILURE;
2302 tpAniSirGlobal pMac = PMAC_STRUCT(hHal);
2303
2304 if (sapContext->csr_roamProfile.csrPersona == CDF_P2P_GO_MODE)
2305 status = cds_get_vdev_types(CDF_P2P_GO_MODE, &type, &subType);
2306 else
2307 status = cds_get_vdev_types(CDF_SAP_MODE, &type, &subType);
2308
2309 if (CDF_STATUS_SUCCESS != status) {
2310 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_FATAL,
2311 "failed to get vdev type");
2312 return CDF_STATUS_E_FAILURE;
2313 }
2314 /* Open SME Session for Softap */
2315 cdf_ret_status = sme_open_session(hHal,
2316 &wlansap_roam_callback,
2317 sapContext,
2318 sapContext->self_mac_addr,
2319 &sapContext->sessionId, type, subType);
2320
2321 if (CDF_STATUS_SUCCESS != cdf_ret_status) {
2322 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_ERROR,
2323 "Error: In %s calling sme_roam_connect status = %d",
2324 __func__, cdf_ret_status);
2325
2326 return CDF_STATUS_E_FAILURE;
2327 }
2328
2329 pMac->sap.sapCtxList[sapContext->sessionId].sessionID =
2330 sapContext->sessionId;
2331 pMac->sap.sapCtxList[sapContext->sessionId].pSapContext = sapContext;
2332 pMac->sap.sapCtxList[sapContext->sessionId].sapPersona =
2333 sapContext->csr_roamProfile.csrPersona;
2334 return CDF_STATUS_SUCCESS;
2335}
2336
2337/*==========================================================================
2338 FUNCTION sapGotoStarting
2339
2340 DESCRIPTION
2341 Function for initiating start bss request for SME
2342
2343 DEPENDENCIES
2344 NA.
2345
2346 PARAMETERS
2347
2348 IN
2349 sapContext : Sap Context value
2350 sapEvent : State machine event
2351 bssType : Type of bss to start, INRA AP
2352 status : Return the SAP status here
2353
2354 RETURN VALUE
2355 The CDF_STATUS code associated with performing the operation
2356
2357 CDF_STATUS_SUCCESS: Success
2358
2359 SIDE EFFECTS
2360 ============================================================================*/
2361CDF_STATUS
2362sap_goto_starting
2363 (ptSapContext sapContext,
2364 ptWLAN_SAPEvent sapEvent, eCsrRoamBssType bssType) {
2365 /* tHalHandle */
2366 tHalHandle hHal = CDS_GET_HAL_CB(sapContext->p_cds_gctx);
2367 CDF_STATUS cdf_ret_status;
2368
2369 /*- - - - - - - - TODO:once configs from hdd available - - - - - - - - -*/
2370 char key_material[32] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3,
2371 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, };
2372 sapContext->key_type = 0x05;
2373 sapContext->key_length = 32;
2374 cdf_mem_copy(sapContext->key_material, key_material, sizeof(key_material)); /* Need a key size define */
2375
2376 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_HIGH, "In %s",
2377 __func__);
2378
2379 if (NULL == hHal) {
2380 /* we have a serious problem */
2381 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_FATAL,
2382 "In %s, invalid hHal", __func__);
2383 return CDF_STATUS_E_FAULT;
2384 }
2385
2386 cdf_ret_status = sap_open_session(hHal, sapContext);
2387
2388 if (CDF_STATUS_SUCCESS != cdf_ret_status) {
2389 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_ERROR,
2390 "Error: In %s calling sap_open_session status = %d",
2391 __func__, cdf_ret_status);
2392 return CDF_STATUS_E_FAILURE;
2393 }
2394
2395 return CDF_STATUS_SUCCESS;
2396} /* sapGotoStarting */
2397
2398/*==========================================================================
2399 FUNCTION sapGotoDisconnecting
2400
2401 DESCRIPTION
2402 Processing of SAP FSM Disconnecting state
2403
2404 DEPENDENCIES
2405 NA.
2406
2407 PARAMETERS
2408
2409 IN
2410 sapContext : Sap Context value
2411 status : Return the SAP status here
2412
2413 RETURN VALUE
2414 The CDF_STATUS code associated with performing the operation
2415
2416 CDF_STATUS_SUCCESS: Success
2417
2418 SIDE EFFECTS
2419 ============================================================================*/
2420CDF_STATUS sap_goto_disconnecting(ptSapContext sapContext)
2421{
2422 CDF_STATUS cdf_ret_status;
2423 tHalHandle hHal;
2424
2425 hHal = CDS_GET_HAL_CB(sapContext->p_cds_gctx);
2426 if (NULL == hHal) {
2427 /* we have a serious problem */
2428 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_ERROR,
2429 "In %s, invalid hHal", __func__);
2430 return CDF_STATUS_E_FAULT;
2431 }
2432
2433 sap_free_roam_profile(&sapContext->csr_roamProfile);
2434 cdf_ret_status = sme_roam_stop_bss(hHal, sapContext->sessionId);
2435 if (CDF_STATUS_SUCCESS != cdf_ret_status) {
2436 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_ERROR,
2437 "Error: In %s calling sme_roam_stop_bss status = %d",
2438 __func__, cdf_ret_status);
2439 return CDF_STATUS_E_FAILURE;
2440 }
2441
2442 return CDF_STATUS_SUCCESS;
2443}
2444
2445static CDF_STATUS sap_roam_session_close_callback(void *pContext)
2446{
2447 ptSapContext sapContext = (ptSapContext) pContext;
2448 return sap_signal_hdd_event(sapContext, NULL,
2449 eSAP_STOP_BSS_EVENT,
2450 (void *) eSAP_STATUS_SUCCESS);
2451}
2452
2453/*==========================================================================
2454 FUNCTION sapGotoDisconnected
2455
2456 DESCRIPTION
2457 Function for setting the SAP FSM to Disconnection state
2458
2459 DEPENDENCIES
2460 NA.
2461
2462 PARAMETERS
2463
2464 IN
2465 sapContext : Sap Context value
2466 sapEvent : State machine event
2467 status : Return the SAP status here
2468
2469 RETURN VALUE
2470 The CDF_STATUS code associated with performing the operation
2471
2472 CDF_STATUS_SUCCESS: Success
2473
2474 SIDE EFFECTS
2475 ============================================================================*/
2476CDF_STATUS sap_goto_disconnected(ptSapContext sapContext)
2477{
2478 CDF_STATUS cdf_status = CDF_STATUS_E_FAILURE;
2479 tWLAN_SAPEvent sapEvent;
2480 /* Processing has to be coded */
2481 /* Clean up stations from TL etc as AP BSS is shut down then set event */
2482 sapEvent.event = eSAP_MAC_READY_FOR_CONNECTIONS; /* hardcoded */
2483 sapEvent.params = 0;
2484 sapEvent.u1 = 0;
2485 sapEvent.u2 = 0;
2486 /* Handle event */
2487 cdf_status = sap_fsm(sapContext, &sapEvent);
2488
2489 return cdf_status;
2490}
2491
2492/**
2493 * sap_signal_hdd_event() - send event notification
2494 * @sap_ctx: Sap Context
2495 * @csr_roaminfo: Pointer to CSR roam information
2496 * @sap_hddevent: SAP HDD event
2497 * @context: to pass the element for future support
2498 *
2499 * Function for HDD to send the event notification using callback
2500 *
2501 * Return: CDF_STATUS
2502 */
2503CDF_STATUS sap_signal_hdd_event(ptSapContext sap_ctx,
2504 tCsrRoamInfo *csr_roaminfo, eSapHddEvent sap_hddevent,
2505 void *context)
2506{
2507 CDF_STATUS cdf_status = CDF_STATUS_SUCCESS;
2508 tSap_Event sap_ap_event; /* This now encodes ALL event types */
2509 tHalHandle hal = CDS_GET_HAL_CB(sap_ctx->p_cds_gctx);
2510 tpAniSirGlobal mac_ctx;
2511 tSirSmeChanInfo *chaninfo;
2512 tSap_StationAssocIndication *assoc_ind;
2513 tSap_StartBssCompleteEvent *bss_complete;
2514 struct sap_ch_selected_s *acs_selected;
2515 tSap_StationAssocReassocCompleteEvent *reassoc_complete;
2516 tSap_StationDisassocCompleteEvent *disassoc_comp;
2517 tSap_StationSetKeyCompleteEvent *key_complete;
2518 tSap_StationMICFailureEvent *mic_failure;
2519 tSap_ManagementFrameInfo *mgmt_frame;
2520
2521 /* Format the Start BSS Complete event to return... */
2522 if (NULL == sap_ctx->pfnSapEventCallback) {
2523 CDF_ASSERT(0);
2524 return CDF_STATUS_E_FAILURE;
2525 }
2526 if (NULL == hal) {
2527 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_ERROR,
2528 FL("Invalid hal"));
2529 return CDF_STATUS_E_FAILURE;
2530 }
2531 mac_ctx = PMAC_STRUCT(hal);
2532 if (NULL == mac_ctx) {
2533 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_ERROR,
2534 FL("Invalid MAC context"));
2535 return CDF_STATUS_E_FAILURE;
2536 }
2537
2538 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_HIGH,
2539 FL("SAP event callback event = %s"),
2540 sap_hdd_event_to_string(sap_hddevent));
2541
2542 switch (sap_hddevent) {
2543 case eSAP_STA_ASSOC_IND:
2544 /* TODO - Indicate the assoc request indication to OS */
2545 sap_ap_event.sapHddEventCode = eSAP_STA_ASSOC_IND;
2546 assoc_ind = &sap_ap_event.sapevt.sapAssocIndication;
2547
2548 cdf_copy_macaddr(&assoc_ind->staMac, &csr_roaminfo->peerMac);
2549 assoc_ind->staId = csr_roaminfo->staId;
2550 assoc_ind->status = 0;
2551 /* Required for indicating the frames to upper layer */
2552 assoc_ind->beaconLength = csr_roaminfo->beaconLength;
2553 assoc_ind->beaconPtr = csr_roaminfo->beaconPtr;
2554 assoc_ind->assocReqLength = csr_roaminfo->assocReqLength;
2555 assoc_ind->assocReqPtr = csr_roaminfo->assocReqPtr;
2556 assoc_ind->fWmmEnabled = csr_roaminfo->wmmEnabledSta;
2557 if (csr_roaminfo->u.pConnectedProfile != NULL) {
2558 assoc_ind->negotiatedAuthType =
2559 csr_roaminfo->u.pConnectedProfile->AuthType;
2560 assoc_ind->negotiatedUCEncryptionType =
2561 csr_roaminfo->u.pConnectedProfile->EncryptionType;
2562 assoc_ind->negotiatedMCEncryptionType =
2563 csr_roaminfo->u.pConnectedProfile->mcEncryptionType;
2564 assoc_ind->fAuthRequired = csr_roaminfo->fAuthRequired;
2565 }
2566 break;
2567 case eSAP_START_BSS_EVENT:
2568 sap_ap_event.sapHddEventCode = eSAP_START_BSS_EVENT;
2569 bss_complete = &sap_ap_event.sapevt.sapStartBssCompleteEvent;
2570
2571 bss_complete->status = (eSapStatus) context;
2572 if (csr_roaminfo != NULL)
2573 bss_complete->staId = csr_roaminfo->staId;
2574 else
2575 bss_complete->staId = 0;
2576
2577 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_HIGH,
2578 FL("(eSAP_START_BSS_EVENT): staId = %d"),
2579 bss_complete->staId);
2580
2581 bss_complete->operatingChannel = (uint8_t) sap_ctx->channel;
2582 bss_complete->sessionId = sap_ctx->sessionId;
2583 break;
2584 case eSAP_DFS_CAC_START:
2585 case eSAP_DFS_CAC_INTERRUPTED:
2586 case eSAP_DFS_CAC_END:
2587 case eSAP_DFS_RADAR_DETECT:
2588 case eSAP_DFS_NO_AVAILABLE_CHANNEL:
2589#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
2590 case eSAP_ACS_SCAN_SUCCESS_EVENT:
2591#endif
2592 sap_ap_event.sapHddEventCode = sap_hddevent;
2593 sap_ap_event.sapevt.sapStopBssCompleteEvent.status =
2594 (eSapStatus) context;
2595 break;
2596
2597 case eSAP_ACS_CHANNEL_SELECTED:
2598 sap_ap_event.sapHddEventCode = sap_hddevent;
2599 acs_selected = &sap_ap_event.sapevt.sap_ch_selected;
2600 if (eSAP_STATUS_SUCCESS == (eSapStatus)context) {
2601 acs_selected->pri_ch = sap_ctx->acs_cfg->pri_ch;
2602 acs_selected->ht_sec_ch = sap_ctx->acs_cfg->ht_sec_ch;
2603 acs_selected->ch_width = sap_ctx->acs_cfg->ch_width;
2604 acs_selected->vht_seg0_center_ch =
2605 sap_ctx->acs_cfg->vht_seg0_center_ch;
2606 acs_selected->vht_seg1_center_ch =
2607 sap_ctx->acs_cfg->vht_seg1_center_ch;
2608 } else if (eSAP_STATUS_FAILURE == (eSapStatus)context) {
2609 acs_selected->pri_ch = 0;
2610 }
2611 break;
2612
2613 case eSAP_STOP_BSS_EVENT:
2614 sap_ap_event.sapHddEventCode = eSAP_STOP_BSS_EVENT;
2615 sap_ap_event.sapevt.sapStopBssCompleteEvent.status =
2616 (eSapStatus) context;
2617 break;
2618
2619 case eSAP_STA_ASSOC_EVENT:
2620 case eSAP_STA_REASSOC_EVENT:
2621 reassoc_complete =
2622 &sap_ap_event.sapevt.sapStationAssocReassocCompleteEvent;
2623
2624 if (csr_roaminfo->fReassocReq)
2625 sap_ap_event.sapHddEventCode = eSAP_STA_REASSOC_EVENT;
2626 else
2627 sap_ap_event.sapHddEventCode = eSAP_STA_ASSOC_EVENT;
2628
2629 cdf_copy_macaddr(&reassoc_complete->staMac,
2630 &csr_roaminfo->peerMac);
2631 reassoc_complete->staId = csr_roaminfo->staId;
2632 reassoc_complete->statusCode = csr_roaminfo->statusCode;
2633 reassoc_complete->iesLen = csr_roaminfo->rsnIELen;
2634 cdf_mem_copy(reassoc_complete->ies, csr_roaminfo->prsnIE,
2635 csr_roaminfo->rsnIELen);
2636
2637#ifdef FEATURE_WLAN_WAPI
2638 if (csr_roaminfo->wapiIELen) {
2639 uint8_t len = reassoc_complete->iesLen;
2640 reassoc_complete->iesLen += csr_roaminfo->wapiIELen;
2641 cdf_mem_copy(&reassoc_complete->ies[len],
2642 csr_roaminfo->pwapiIE,
2643 csr_roaminfo->wapiIELen);
2644 }
2645#endif
2646 if (csr_roaminfo->addIELen) {
2647 uint8_t len = reassoc_complete->iesLen;
2648 reassoc_complete->iesLen += csr_roaminfo->addIELen;
2649 cdf_mem_copy(&reassoc_complete->ies[len],
2650 csr_roaminfo->paddIE,
2651 csr_roaminfo->addIELen);
2652 }
2653
2654 /* also fill up the channel info from the csr_roamInfo */
2655 chaninfo = &reassoc_complete->chan_info;
2656
2657 chaninfo->chan_id = csr_roaminfo->chan_info.chan_id;
2658 chaninfo->mhz = csr_roaminfo->chan_info.mhz;
2659 chaninfo->info = csr_roaminfo->chan_info.info;
2660 chaninfo->band_center_freq1 =
2661 csr_roaminfo->chan_info.band_center_freq1;
2662 chaninfo->band_center_freq2 =
2663 csr_roaminfo->chan_info.band_center_freq2;
2664 chaninfo->reg_info_1 =
2665 csr_roaminfo->chan_info.reg_info_1;
2666 chaninfo->reg_info_2 =
2667 csr_roaminfo->chan_info.reg_info_2;
Kanchanapally, Vidyullathae3062812015-05-22 17:28:57 +05302668 chaninfo->nss = csr_roaminfo->chan_info.nss;
2669 chaninfo->rate_flags = csr_roaminfo->chan_info.rate_flags;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002670
2671 reassoc_complete->wmmEnabled = csr_roaminfo->wmmEnabledSta;
2672 reassoc_complete->status = (eSapStatus) context;
2673 reassoc_complete->timingMeasCap = csr_roaminfo->timingMeasCap;
2674 break;
2675
2676 case eSAP_STA_DISASSOC_EVENT:
2677 sap_ap_event.sapHddEventCode = eSAP_STA_DISASSOC_EVENT;
2678 disassoc_comp =
2679 &sap_ap_event.sapevt.sapStationDisassocCompleteEvent;
2680
2681 cdf_copy_macaddr(&disassoc_comp->staMac,
2682 &csr_roaminfo->peerMac);
2683 disassoc_comp->staId = csr_roaminfo->staId;
2684 if (csr_roaminfo->reasonCode == eCSR_ROAM_RESULT_FORCED)
2685 disassoc_comp->reason = eSAP_USR_INITATED_DISASSOC;
2686 else
2687 disassoc_comp->reason = eSAP_MAC_INITATED_DISASSOC;
2688
2689 disassoc_comp->statusCode = csr_roaminfo->statusCode;
2690 disassoc_comp->status = (eSapStatus) context;
2691 break;
2692
2693 case eSAP_STA_SET_KEY_EVENT:
2694 sap_ap_event.sapHddEventCode = eSAP_STA_SET_KEY_EVENT;
2695 key_complete =
2696 &sap_ap_event.sapevt.sapStationSetKeyCompleteEvent;
2697 key_complete->status = (eSapStatus) context;
2698 cdf_copy_macaddr(&key_complete->peerMacAddr,
2699 &csr_roaminfo->peerMac);
2700 break;
2701
2702 case eSAP_STA_MIC_FAILURE_EVENT:
2703 sap_ap_event.sapHddEventCode = eSAP_STA_MIC_FAILURE_EVENT;
2704 mic_failure = &sap_ap_event.sapevt.sapStationMICFailureEvent;
2705
2706 cdf_mem_copy(&mic_failure->srcMacAddr,
2707 csr_roaminfo->u.pMICFailureInfo->srcMacAddr,
2708 sizeof(tSirMacAddr));
2709 cdf_mem_copy(&mic_failure->staMac.bytes,
2710 csr_roaminfo->u.pMICFailureInfo->taMacAddr,
2711 sizeof(tSirMacAddr));
2712 cdf_mem_copy(&mic_failure->dstMacAddr.bytes,
2713 csr_roaminfo->u.pMICFailureInfo->dstMacAddr,
2714 sizeof(tSirMacAddr));
2715 mic_failure->multicast =
2716 csr_roaminfo->u.pMICFailureInfo->multicast;
2717 mic_failure->IV1 = csr_roaminfo->u.pMICFailureInfo->IV1;
2718 mic_failure->keyId = csr_roaminfo->u.pMICFailureInfo->keyId;
2719 cdf_mem_copy(mic_failure->TSC,
2720 csr_roaminfo->u.pMICFailureInfo->TSC,
2721 SIR_CIPHER_SEQ_CTR_SIZE);
2722 break;
2723
2724 case eSAP_ASSOC_STA_CALLBACK_EVENT:
2725 break;
2726
2727 case eSAP_WPS_PBC_PROBE_REQ_EVENT:
2728 sap_ap_event.sapHddEventCode = eSAP_WPS_PBC_PROBE_REQ_EVENT;
2729
2730 cdf_mem_copy(&sap_ap_event.sapevt.sapPBCProbeReqEvent.
2731 WPSPBCProbeReq, csr_roaminfo->u.pWPSPBCProbeReq,
2732 sizeof(tSirWPSPBCProbeReq));
2733 break;
2734
2735 case eSAP_INDICATE_MGMT_FRAME:
2736 sap_ap_event.sapHddEventCode = eSAP_INDICATE_MGMT_FRAME;
2737 mgmt_frame = &sap_ap_event.sapevt.sapManagementFrameInfo;
2738
2739 mgmt_frame->nFrameLength = csr_roaminfo->nFrameLength;
2740 mgmt_frame->pbFrames = csr_roaminfo->pbFrames;
2741 mgmt_frame->frameType = csr_roaminfo->frameType;
2742 mgmt_frame->rxChan = csr_roaminfo->rxChan;
2743 break;
2744
2745 case eSAP_REMAIN_CHAN_READY:
2746 sap_ap_event.sapHddEventCode = eSAP_REMAIN_CHAN_READY;
2747 sap_ap_event.sapevt.sap_roc_ind.scan_id =
2748 sap_ctx->roc_ind_scan_id;
2749 break;
2750 case eSAP_SEND_ACTION_CNF:
2751 sap_ap_event.sapHddEventCode = eSAP_SEND_ACTION_CNF;
2752 sap_ap_event.sapevt.sapActionCnf.actionSendSuccess =
2753 (eSapStatus) context;
2754 break;
2755
2756 case eSAP_DISCONNECT_ALL_P2P_CLIENT:
2757 sap_ap_event.sapHddEventCode = eSAP_DISCONNECT_ALL_P2P_CLIENT;
2758 sap_ap_event.sapevt.sapActionCnf.actionSendSuccess =
2759 (eSapStatus) context;
2760 break;
2761
2762 case eSAP_MAC_TRIG_STOP_BSS_EVENT:
2763 sap_ap_event.sapHddEventCode = eSAP_MAC_TRIG_STOP_BSS_EVENT;
2764 sap_ap_event.sapevt.sapActionCnf.actionSendSuccess =
2765 (eSapStatus) context;
2766 break;
2767
2768 case eSAP_UNKNOWN_STA_JOIN:
2769 sap_ap_event.sapHddEventCode = eSAP_UNKNOWN_STA_JOIN;
2770 cdf_mem_copy((void *) sap_ap_event.sapevt.sapUnknownSTAJoin.
2771 macaddr.bytes, (void *) context,
2772 CDF_MAC_ADDR_SIZE);
2773 break;
2774
2775 case eSAP_MAX_ASSOC_EXCEEDED:
2776 sap_ap_event.sapHddEventCode = eSAP_MAX_ASSOC_EXCEEDED;
2777 cdf_copy_macaddr(&sap_ap_event.sapevt.
2778 sapMaxAssocExceeded.macaddr,
2779 &csr_roaminfo->peerMac);
2780 break;
2781
2782 case eSAP_CHANNEL_CHANGE_EVENT:
2783 /*
2784 * Reconfig ACS result info. For DFS AP-AP Mode Sec AP ACS
2785 * follows pri AP
2786 */
2787 sap_ctx->acs_cfg->pri_ch = sap_ctx->channel;
2788 sap_ctx->acs_cfg->ch_width = sap_ctx->ch_params.ch_width;
2789 sap_config_acs_result(hal, sap_ctx, sap_ctx->secondary_ch);
2790
2791 sap_ap_event.sapHddEventCode = eSAP_CHANNEL_CHANGE_EVENT;
2792
2793 acs_selected = &sap_ap_event.sapevt.sap_ch_selected;
2794 acs_selected->pri_ch = sap_ctx->acs_cfg->pri_ch;
2795 acs_selected->ht_sec_ch = sap_ctx->acs_cfg->ht_sec_ch;
2796 acs_selected->ch_width = sap_ctx->acs_cfg->ch_width;
2797 acs_selected->vht_seg0_center_ch =
2798 sap_ctx->acs_cfg->vht_seg0_center_ch;
2799 acs_selected->vht_seg1_center_ch =
2800 sap_ctx->acs_cfg->vht_seg1_center_ch;
2801 break;
2802
2803 case eSAP_DFS_NOL_GET:
2804 sap_ap_event.sapHddEventCode = eSAP_DFS_NOL_GET;
2805 sap_ap_event.sapevt.sapDfsNolInfo.sDfsList =
2806 NUM_5GHZ_CHANNELS * sizeof(tSapDfsNolInfo);
2807 sap_ap_event.sapevt.sapDfsNolInfo.pDfsList = (void *)
2808 (&mac_ctx->sap.SapDfsInfo.sapDfsChannelNolList[0]);
2809 break;
2810
2811 case eSAP_DFS_NOL_SET:
2812 sap_ap_event.sapHddEventCode = eSAP_DFS_NOL_SET;
2813 sap_ap_event.sapevt.sapDfsNolInfo.sDfsList =
2814 mac_ctx->sap.SapDfsInfo.numCurrentRegDomainDfsChannels *
2815 sizeof(tSapDfsNolInfo);
2816 sap_ap_event.sapevt.sapDfsNolInfo.pDfsList = (void *)
2817 (&mac_ctx->sap.SapDfsInfo.sapDfsChannelNolList[0]);
2818 break;
Abhishek Singh518323d2015-10-19 17:42:01 +05302819 case eSAP_ECSA_CHANGE_CHAN_IND:
2820 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_HIGH,
2821 "In %s, SAP event callback event = %s",
2822 __func__, "eSAP_ECSA_CHANGE_CHAN_IND");
2823 sap_ap_event.sapHddEventCode = eSAP_ECSA_CHANGE_CHAN_IND;
2824 sap_ap_event.sapevt.sap_chan_cng_ind.new_chan =
2825 csr_roaminfo->target_channel;
2826 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002827 default:
2828 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_ERROR,
2829 FL("SAP Unknown callback event = %d"),
2830 sap_hddevent);
2831 break;
2832 }
2833 cdf_status = (*sap_ctx->pfnSapEventCallback)
2834 (&sap_ap_event, sap_ctx->pUsrContext);
2835
2836 return cdf_status;
2837
2838}
2839
2840/*==========================================================================
2841 FUNCTION sap_find_valid_concurrent_session
2842
2843 DESCRIPTION
2844 This function will return sapcontext of any valid sap session.
2845
2846 PARAMETERS
2847
2848 IN
2849 hHal : HAL pointer
2850
2851 RETURN VALUE
2852 ptSapContext : valid sap context
2853
2854 SIDE EFFECTS
2855 NA
2856 ============================================================================*/
2857ptSapContext sap_find_valid_concurrent_session(tHalHandle hHal)
2858{
2859 tpAniSirGlobal pMac = PMAC_STRUCT(hHal);
2860 uint8_t intf = 0;
2861
2862 for (intf = 0; intf < SAP_MAX_NUM_SESSION; intf++) {
2863 if (((CDF_SAP_MODE == pMac->sap.sapCtxList[intf].sapPersona)
2864 ||
2865 (CDF_P2P_GO_MODE == pMac->sap.sapCtxList[intf].sapPersona)) &&
2866 pMac->sap.sapCtxList[intf].pSapContext != NULL) {
2867 return pMac->sap.sapCtxList[intf].pSapContext;
2868 }
2869 }
2870
2871 return NULL;
2872}
2873
2874/*==========================================================================
2875 FUNCTION sap_close_session
2876
2877 DESCRIPTION
2878 This function will close all the sme sessions as well as zero-out the
2879 sap global structure
2880
2881 PARAMETERS
2882
2883 IN
2884 hHal : HAL pointer
2885 sapContext : Sap Context value
2886 callback : Roam Session close callback
2887 valid : Sap context is valid or no
2888
2889 RETURN VALUE
2890 The CDF_STATUS code associated with performing the operation
2891 CDF_STATUS_SUCCESS: Success
2892
2893 SIDE EFFECTS
2894 NA
2895 ============================================================================*/
2896CDF_STATUS sap_close_session(tHalHandle hHal,
2897 ptSapContext sapContext,
2898 csr_roamSessionCloseCallback callback, bool valid)
2899{
2900 CDF_STATUS cdf_status;
2901 tpAniSirGlobal pMac = PMAC_STRUCT(hHal);
2902
2903 if (false == valid) {
2904 cdf_status = sme_close_session(hHal,
2905 sapContext->sessionId,
2906 callback, NULL);
2907 } else {
2908 cdf_status = sme_close_session(hHal,
2909 sapContext->sessionId,
2910 callback, sapContext);
2911 }
2912
2913 sapContext->isCacStartNotified = false;
2914 sapContext->isCacEndNotified = false;
2915 pMac->sap.sapCtxList[sapContext->sessionId].pSapContext = NULL;
2916
2917 if (NULL == sap_find_valid_concurrent_session(hHal)) {
2918 /* If timer is running then stop the timer and destory it */
2919 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_MED,
2920 "sapdfs: no session are valid, so clearing dfs global structure");
2921 /*
2922 * CAC timer will be initiated and started only when SAP starts
2923 * on DFS channel and it will be stopped and destroyed
2924 * immediately once the radar detected or timedout. So
2925 * as per design CAC timer should be destroyed after stop
2926 */
2927 if (pMac->sap.SapDfsInfo.is_dfs_cac_timer_running) {
2928 cdf_mc_timer_stop(&pMac->sap.SapDfsInfo.
2929 sap_dfs_cac_timer);
2930 pMac->sap.SapDfsInfo.is_dfs_cac_timer_running = 0;
2931 cdf_mc_timer_destroy(
2932 &pMac->sap.SapDfsInfo.sap_dfs_cac_timer);
2933 }
2934 pMac->sap.SapDfsInfo.cac_state = eSAP_DFS_DO_NOT_SKIP_CAC;
2935 sap_cac_reset_notify(hHal);
2936 cdf_mem_zero(&pMac->sap, sizeof(pMac->sap));
2937 }
2938
2939 return cdf_status;
2940}
2941
2942/*==========================================================================
2943 FUNCTION sap_cac_reset_notify
2944
2945 DESCRIPTION Function will be called up on stop bss indication to clean up
2946 DFS global structure.
2947
2948 DEPENDENCIES PARAMETERS
2949 IN hHAL : HAL pointer
2950
2951 RETURN VALUE : void.
2952
2953 SIDE EFFECTS
2954 ============================================================================*/
2955void sap_cac_reset_notify(tHalHandle hHal)
2956{
2957 uint8_t intf = 0;
2958 tpAniSirGlobal pMac = PMAC_STRUCT(hHal);
2959
2960 for (intf = 0; intf < SAP_MAX_NUM_SESSION; intf++) {
2961 ptSapContext pSapContext =
2962 (ptSapContext) pMac->sap.sapCtxList[intf].pSapContext;
2963 if (((CDF_SAP_MODE == pMac->sap.sapCtxList[intf].sapPersona)
2964 ||
2965 (CDF_P2P_GO_MODE == pMac->sap.sapCtxList[intf].sapPersona))
2966 && pMac->sap.sapCtxList[intf].pSapContext != NULL) {
2967 pSapContext->isCacStartNotified = false;
2968 pSapContext->isCacEndNotified = false;
2969 }
2970 }
2971}
2972
2973/*==========================================================================
2974 FUNCTION sap_cac_start_notify
2975
2976 DESCRIPTION Function will be called to notify eSAP_DFS_CAC_START event
2977 to HDD
2978
2979 DEPENDENCIES PARAMETERS
2980 IN hHAL : HAL pointer
2981
2982 RETURN VALUE : CDF_STATUS.
2983
2984 SIDE EFFECTS
2985 ============================================================================*/
2986CDF_STATUS sap_cac_start_notify(tHalHandle hHal)
2987{
2988 uint8_t intf = 0;
2989 tpAniSirGlobal pMac = PMAC_STRUCT(hHal);
2990 CDF_STATUS cdf_status = CDF_STATUS_E_FAILURE;
2991
2992 for (intf = 0; intf < SAP_MAX_NUM_SESSION; intf++) {
2993 ptSapContext pSapContext =
2994 (ptSapContext) pMac->sap.sapCtxList[intf].pSapContext;
2995 if (((CDF_SAP_MODE == pMac->sap.sapCtxList[intf].sapPersona)
2996 ||
2997 (CDF_P2P_GO_MODE == pMac->sap.sapCtxList[intf].sapPersona))
2998 && pMac->sap.sapCtxList[intf].pSapContext != NULL &&
2999 (false == pSapContext->isCacStartNotified)) {
3000 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_MED,
3001 "sapdfs: Signaling eSAP_DFS_CAC_START to HDD for sapctx[%p]",
3002 pSapContext);
3003
3004 cdf_status = sap_signal_hdd_event(pSapContext, NULL,
3005 eSAP_DFS_CAC_START,
3006 (void *)
3007 eSAP_STATUS_SUCCESS);
3008 if (CDF_STATUS_SUCCESS != cdf_status) {
3009 CDF_TRACE(CDF_MODULE_ID_SAP,
3010 CDF_TRACE_LEVEL_ERROR,
3011 "In %s, failed setting isCacStartNotified on interface[%d]",
3012 __func__, intf);
3013 return cdf_status;
3014 }
3015 pSapContext->isCacStartNotified = true;
3016 }
3017 }
3018 return cdf_status;
3019}
3020
3021/*==========================================================================
3022 FUNCTION sap_cac_end_notify
3023
3024 DESCRIPTION Function will be called to notify eSAP_DFS_CAC_END event
3025 to HDD
3026
3027 DEPENDENCIES PARAMETERS
3028 IN hHAL : HAL pointer
3029
3030 RETURN VALUE : CDF_STATUS.
3031
3032 SIDE EFFECTS
3033 ============================================================================*/
3034CDF_STATUS sap_cac_end_notify(tHalHandle hHal, tCsrRoamInfo *roamInfo)
3035{
3036 uint8_t intf;
3037 tpAniSirGlobal pMac = PMAC_STRUCT(hHal);
3038 CDF_STATUS cdf_status = CDF_STATUS_E_FAILURE;
3039
3040 /*
3041 * eSAP_DFS_CHANNEL_CAC_END:
3042 * CAC Period elapsed and there was no radar
3043 * found so, SAP can continue beaconing.
3044 * sap_radar_found_status is set to 0
3045 */
3046 for (intf = 0; intf < SAP_MAX_NUM_SESSION; intf++) {
3047 ptSapContext pSapContext =
3048 (ptSapContext) pMac->sap.sapCtxList[intf].pSapContext;
3049 if (((CDF_SAP_MODE == pMac->sap.sapCtxList[intf].sapPersona)
3050 ||
3051 (CDF_P2P_GO_MODE == pMac->sap.sapCtxList[intf].sapPersona))
3052 && pMac->sap.sapCtxList[intf].pSapContext != NULL &&
3053 (false == pSapContext->isCacEndNotified)) {
3054 pSapContext = pMac->sap.sapCtxList[intf].pSapContext;
3055 cdf_status = sap_signal_hdd_event(pSapContext, NULL,
3056 eSAP_DFS_CAC_END,
3057 (void *)
3058 eSAP_STATUS_SUCCESS);
3059 if (CDF_STATUS_SUCCESS != cdf_status) {
3060 CDF_TRACE(CDF_MODULE_ID_SAP,
3061 CDF_TRACE_LEVEL_ERROR,
3062 "In %s, failed setting isCacEndNotified on interface[%d]",
3063 __func__, intf);
3064 return cdf_status;
3065 }
3066 pSapContext->isCacEndNotified = true;
3067 pMac->sap.SapDfsInfo.sap_radar_found_status = false;
3068 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_MED,
3069 "sapdfs: Start beacon request on sapctx[%p]",
3070 pSapContext);
3071
3072 /* Start beaconing on the new channel */
3073 wlansap_start_beacon_req(pSapContext);
3074
3075 /* Transition from eSAP_STARTING to eSAP_STARTED
3076 * (both without substates)
3077 */
3078 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_MED,
3079 "sapdfs: channel[%d] from state %s => %s",
3080 pSapContext->channel, "eSAP_STARTING",
3081 "eSAP_STARTED");
3082
3083 pSapContext->sapsMachine = eSAP_STARTED;
3084
3085 /*Action code for transition */
3086 cdf_status = sap_signal_hdd_event(pSapContext, roamInfo,
3087 eSAP_START_BSS_EVENT,
3088 (void *)
3089 eSAP_STATUS_SUCCESS);
3090 if (CDF_STATUS_SUCCESS != cdf_status) {
3091 CDF_TRACE(CDF_MODULE_ID_SAP,
3092 CDF_TRACE_LEVEL_ERROR,
3093 "In %s, failed setting isCacEndNotified on interface[%d]",
3094 __func__, intf);
3095 return cdf_status;
3096 }
3097
3098 /* Transition from eSAP_STARTING to eSAP_STARTED
3099 * (both without substates)
3100 */
3101 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_HIGH,
3102 "In %s, from state %s => %s",
3103 __func__, "eSAP_DFS_CAC_WAIT",
3104 "eSAP_STARTED");
3105 }
3106 }
3107 /*
3108 * All APs are done with CAC timer, all APs should start beaconing.
3109 * Lets assume AP1 and AP2 started beaconing on DFS channel, Now lets
3110 * say AP1 goes down and comes back on same DFS channel. In this case
3111 * AP1 shouldn't start CAC timer and start beacon immediately beacause
3112 * AP2 is already beaconing on this channel. This case will be handled
3113 * by checking against eSAP_DFS_SKIP_CAC while starting the timer.
3114 */
3115 pMac->sap.SapDfsInfo.cac_state = eSAP_DFS_SKIP_CAC;
3116 return cdf_status;
3117}
3118
3119/**
3120 * sap_fsm_state_disconnected() - utility function called from sap fsm
3121 * @sap_ctx: SAP context
3122 * @sap_event: SAP event buffer
3123 * @mac_ctx: global MAC context
3124 * @hal: HAL handle
3125 *
3126 * This function is called for state transition from "eSAP_DISCONNECTED"
3127 *
3128 * Return: CDF_STATUS
3129 */
3130static CDF_STATUS sap_fsm_state_disconnected(ptSapContext sap_ctx,
3131 ptWLAN_SAPEvent sap_event, tpAniSirGlobal mac_ctx,
3132 tHalHandle hal)
3133{
3134 uint32_t msg = sap_event->event;
3135 CDF_STATUS cdf_status = CDF_STATUS_E_FAILURE;
3136
3137 if (msg == eSAP_HDD_START_INFRA_BSS) {
3138 /*
3139 * Transition from eSAP_DISCONNECTED to eSAP_CH_SELECT
3140 * (both without substates)
3141 */
3142 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_HIGH,
3143 FL("new from state %s => %s"),
3144 "eSAP_DISCONNECTED", "eSAP_CH_SELECT");
3145
3146 /* There can be one SAP Session for softap */
3147 if (sap_ctx->isSapSessionOpen == eSAP_TRUE) {
3148 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_FATAL,
3149 FL("SME Session is already opened"));
3150 return CDF_STATUS_E_EXISTS;
3151 }
3152
3153 sap_ctx->sessionId = 0xff;
3154
3155 if ((sap_ctx->channel == AUTO_CHANNEL_SELECT) &&
3156 (sap_ctx->isScanSessionOpen == eSAP_FALSE)) {
3157 uint32_t type, subtype;
3158 if (CDF_STATUS_SUCCESS == cds_get_vdev_types(
3159 CDF_STA_MODE, &type, &subtype)) {
3160 /* Open SME Session for scan */
3161 cdf_status = sme_open_session(hal, NULL,
3162 sap_ctx, sap_ctx->self_mac_addr,
3163 &sap_ctx->sessionId, type, subtype);
3164 if (CDF_STATUS_SUCCESS != cdf_status) {
3165 CDF_TRACE(CDF_MODULE_ID_SAP,
3166 CDF_TRACE_LEVEL_ERROR,
3167 FL("Error: calling sme_open_session"));
3168 } else {
3169 sap_ctx->isScanSessionOpen = eSAP_TRUE;
3170 }
3171 }
3172 }
3173 /* init dfs channel nol */
3174 sap_init_dfs_channel_nol_list(sap_ctx);
3175
3176 /* Set SAP device role */
3177 sap_ctx->sapsMachine = eSAP_CH_SELECT;
3178
3179 /*
3180 * Perform sme_ScanRequest. This scan request is post start bss
3181 * request so, set the third to false.
3182 */
3183 cdf_status = sap_goto_channel_sel(sap_ctx, sap_event, false);
3184
3185 /*
3186 * Transition from eSAP_DISCONNECTED to eSAP_CH_SELECT
3187 * (both without substates)
3188 */
3189 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_HIGH,
3190 FL("from state %s => %s"),
3191 "eSAP_DISCONNECTED", "eSAP_CH_SELECT");
3192 } else if (msg == eSAP_DFS_CHANNEL_CAC_START) {
3193 /*
3194 * No need of state check here, caller is expected to perform
3195 * the checks before sending the event
3196 */
3197 sap_ctx->sapsMachine = eSAP_DFS_CAC_WAIT;
3198
3199 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_MED,
3200 FL("from state eSAP_DISCONNECTED => SAP_DFS_CAC_WAIT"));
3201 if (mac_ctx->sap.SapDfsInfo.is_dfs_cac_timer_running != true) {
3202 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_MED,
3203 FL("sapdfs: starting dfs cac timer on sapctx[%p]"),
3204 sap_ctx);
3205 sap_start_dfs_cac_timer(sap_ctx);
3206 }
3207
3208 cdf_status = sap_cac_start_notify(hal);
3209 } else if (msg == eSAP_CHANNEL_SELECTION_RETRY) {
3210 /* Set SAP device role */
3211 sap_ctx->sapsMachine = eSAP_CH_SELECT;
3212
3213 /*
3214 * Perform sme_ScanRequest. This scan request is post start bss
3215 * request so, set the third to false.
3216 */
3217 cdf_status = sap_goto_channel_sel(sap_ctx, sap_event, false);
3218 } else {
3219 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_ERROR,
3220 FL("in state %s, event msg %d"),
3221 "eSAP_DISCONNECTED", msg);
3222 }
3223
3224 return cdf_status;
3225}
3226
3227/**
3228 * sap_fsm_state_ch_select() - utility function called from sap fsm
3229 * @sap_ctx: SAP context
3230 * @sap_event: SAP event buffer
3231 * @mac_ctx: global MAC context
3232 * @hal: HAL handle
3233 *
3234 * This function is called for state transition from "eSAP_CH_SELECT"
3235 *
3236 * Return: CDF_STATUS
3237 */
3238static CDF_STATUS sap_fsm_state_ch_select(ptSapContext sap_ctx,
3239 ptWLAN_SAPEvent sap_event, tpAniSirGlobal mac_ctx,
3240 tHalHandle hal)
3241{
3242 uint32_t msg = sap_event->event;
3243 CDF_STATUS cdf_status = CDF_STATUS_E_FAILURE;
3244 uint32_t cbmode;
3245 bool b_leak_chan = false;
3246#ifdef WLAN_ENABLE_CHNL_MATRIX_RESTRICTION
3247 uint8_t temp_chan;
3248 tSapDfsNolInfo *p_nol;
3249#endif
3250
3251 if (sap_ctx->isScanSessionOpen == eSAP_TRUE) {
3252 /* scan completed, so close the session */
3253 cdf_status = sme_close_session(hal, sap_ctx->sessionId,
3254 NULL, NULL);
3255 if (CDF_STATUS_SUCCESS != cdf_status)
3256 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_ERROR,
3257 FL("CloseSession error event msg %d"), msg);
3258 else
3259 sap_ctx->isScanSessionOpen = eSAP_FALSE;
3260 sap_ctx->sessionId = 0xff;
3261 }
3262
3263 if (msg == eSAP_MAC_SCAN_COMPLETE) {
3264 /* get the bonding mode */
3265 if (sap_ctx->channel <= 14)
3266 cbmode = sme_get_cb_phy_state_from_cb_ini_value(
3267 sme_get_channel_bonding_mode24_g(hal));
3268 else
3269 cbmode = sme_get_cb_phy_state_from_cb_ini_value(
3270 sme_get_channel_bonding_mode5_g(hal));
3271
3272#ifdef WLAN_ENABLE_CHNL_MATRIX_RESTRICTION
3273 temp_chan = sap_ctx->channel;
3274 p_nol = mac_ctx->sap.SapDfsInfo.sapDfsChannelNolList;
3275
3276 sap_mark_channels_leaking_into_nol(sap_ctx,
3277 cbmode, p_nol, 1, &temp_chan);
3278
3279 /*
3280 * if selelcted channel has leakage to channels
3281 * in NOL, the temp_chan will be reset
3282 */
3283 b_leak_chan = (temp_chan != sap_ctx->channel);
3284#endif
3285 /*
3286 * check if channel is in DFS_NOL or if the channel
3287 * has leakage to the channels in NOL
3288 */
3289 if (sap_dfs_is_channel_in_nol_list(sap_ctx, sap_ctx->channel,
3290 cbmode) || b_leak_chan) {
3291 uint8_t ch;
3292
3293 /* find a new available channel */
3294 ch = sap_random_channel_sel(sap_ctx);
3295 if (ch == 0) {
3296 /* No available channel found */
3297 CDF_TRACE(CDF_MODULE_ID_SAP,
3298 CDF_TRACE_LEVEL_ERROR,
3299 FL("No available channel found!!!"));
3300 sap_signal_hdd_event(sap_ctx, NULL,
3301 eSAP_DFS_NO_AVAILABLE_CHANNEL,
3302 (void *)eSAP_STATUS_SUCCESS);
3303 return CDF_STATUS_E_FAULT;
3304 }
3305
3306 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_HIGH,
3307 FL("channel %d is in NOL, StartBss on new channel %d"),
3308 sap_ctx->channel, ch);
3309
3310 sap_ctx->channel = ch;
3311 sme_set_ch_params(hal, sap_ctx->csr_roamProfile.phyMode,
3312 sap_ctx->channel, sap_ctx->secondary_ch,
3313 &sap_ctx->ch_params);
3314 }
3315 if (sap_ctx->channel > 14 &&
3316 (sap_ctx->csr_roamProfile.phyMode == eCSR_DOT11_MODE_11g ||
3317 sap_ctx->csr_roamProfile.phyMode ==
3318 eCSR_DOT11_MODE_11g_ONLY))
3319 sap_ctx->csr_roamProfile.phyMode = eCSR_DOT11_MODE_11a;
3320
3321#ifdef WLAN_FEATURE_MBSSID
3322 /*
3323 * when AP2 is started while AP1 is performing ACS, we may not
3324 * have the AP1 channel yet.So here after the completion of AP2
3325 * ACS check if AP1 ACS resulting channel is DFS and if yes
3326 * override AP2 ACS scan result with AP1 DFS channel
3327 */
3328 if (cds_concurrent_beaconing_sessions_running()) {
3329 uint16_t con_ch;
3330
3331 con_ch = sme_get_concurrent_operation_channel(hal);
3332 if (con_ch && CDS_IS_DFS_CH(con_ch))
3333 sap_ctx->channel = con_ch;
3334 }
3335#endif
3336 /*
3337 * Transition from eSAP_CH_SELECT to eSAP_STARTING
3338 * (both without substates)
3339 */
3340 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_HIGH,
3341 FL("from state %s => %s"),
3342 "eSAP_CH_SELECT", "eSAP_STARTING");
3343 /* Channel selected. Now can sap_goto_starting */
3344 sap_ctx->sapsMachine = eSAP_STARTING;
3345 /* Specify the channel */
3346 sap_ctx->csr_roamProfile.ChannelInfo.numOfChannels =
3347 1;
3348 sap_ctx->csr_roamProfile.ChannelInfo.ChannelList =
3349 &sap_ctx->csr_roamProfile.operationChannel;
3350 sap_ctx->csr_roamProfile.operationChannel =
3351 (uint8_t) sap_ctx->channel;
3352 sap_ctx->csr_roamProfile.ch_params.ch_width =
3353 sap_ctx->ch_params.ch_width;
3354 sap_ctx->csr_roamProfile.ch_params.center_freq_seg0 =
3355 sap_ctx->ch_params.center_freq_seg0;
3356 sap_ctx->csr_roamProfile.ch_params.center_freq_seg1 =
3357 sap_ctx->ch_params.center_freq_seg1;
3358 sap_ctx->csr_roamProfile.ch_params.sec_ch_offset =
3359 sap_ctx->ch_params.sec_ch_offset;
3360 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_HIGH,
3361 FL("notify hostapd about channel selection: %d"),
3362 sap_ctx->channel);
3363 sap_signal_hdd_event(sap_ctx, NULL,
3364 eSAP_CHANNEL_CHANGE_EVENT,
3365 (void *) eSAP_STATUS_SUCCESS);
3366 cdf_status = sap_goto_starting(sap_ctx, sap_event,
3367 eCSR_BSS_TYPE_INFRA_AP);
3368 } else if (msg == eSAP_CHANNEL_SELECTION_FAILED) {
3369 sap_ctx->sapsMachine = eSAP_DISCONNECTED;
3370 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_ERROR,
3371 FL("Cannot start BSS, ACS Fail"));
3372 } else if (msg == eSAP_HDD_STOP_INFRA_BSS) {
3373 sap_ctx->sapsMachine = eSAP_DISCONNECTED;
3374 sap_signal_hdd_event(sap_ctx, NULL, eSAP_START_BSS_EVENT,
3375 (void *)eSAP_STATUS_FAILURE);
3376 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO,
3377 "%s: BSS stopped when Ch select in Progress", __func__);
3378 } else {
3379 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_ERROR,
3380 FL("in state %s, invalid event msg %d"),
3381 "eSAP_CH_SELECT", msg);
3382 }
3383
3384 return cdf_status;
3385}
3386
3387/**
3388 * sap_fsm_state_dfs_cac_wait() - utility function called from sap fsm
3389 * @sap_ctx: SAP context
3390 * @sap_event: SAP event buffer
3391 * @mac_ctx: global MAC context
3392 * @hal: HAL handle
3393 *
3394 * This function is called for state transition from "eSAP_DFS_CAC_WAIT"
3395 *
3396 * Return: CDF_STATUS
3397 */
3398static CDF_STATUS sap_fsm_state_dfs_cac_wait(ptSapContext sap_ctx,
3399 ptWLAN_SAPEvent sap_event, tpAniSirGlobal mac_ctx,
3400 tHalHandle hal)
3401{
3402 uint32_t msg = sap_event->event;
3403 tCsrRoamInfo *roam_info = (tCsrRoamInfo *) (sap_event->params);
3404 CDF_STATUS cdf_status = CDF_STATUS_E_FAILURE;
3405
3406 if (msg == eSAP_DFS_CHANNEL_CAC_START) {
3407 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_HIGH,
3408 FL("from state %s => %s"),
3409 "eSAP_CH_SELECT", "eSAP_DFS_CAC_WAIT");
3410 if (mac_ctx->sap.SapDfsInfo.is_dfs_cac_timer_running != true)
3411 sap_start_dfs_cac_timer(sap_ctx);
3412 cdf_status = sap_cac_start_notify(hal);
3413 } else if (msg == eSAP_DFS_CHANNEL_CAC_RADAR_FOUND) {
3414 uint8_t intf;
3415 /*
3416 * Radar found while performing channel availability
3417 * check, need to switch the channel again
3418 */
3419 eCsrPhyMode phymode = sap_ctx->csr_roamProfile.phyMode;
3420 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO,
3421 "ENTERTRED CAC WAIT STATE-->eSAP_DISCONNECTING\n");
3422 if (mac_ctx->sap.SapDfsInfo.target_channel) {
3423 sme_set_ch_params(hal, phymode,
3424 mac_ctx->sap.SapDfsInfo.target_channel, 0,
3425 &sap_ctx->ch_params);
3426 }
3427
3428 for (intf = 0; intf < SAP_MAX_NUM_SESSION; intf++) {
3429 ptSapContext t_sap_ctx;
3430 if (((CDF_SAP_MODE ==
3431 mac_ctx->sap.sapCtxList[intf].sapPersona) ||
3432 (CDF_P2P_GO_MODE ==
3433 mac_ctx->sap.sapCtxList[intf].sapPersona)) &&
3434 mac_ctx->sap.sapCtxList[intf].pSapContext != NULL) {
3435 t_sap_ctx =
3436 mac_ctx->sap.sapCtxList[intf].pSapContext;
3437 /* SAP to be moved to DISCONNECTING state */
3438 sap_ctx->sapsMachine = eSAP_DISCONNECTING;
3439 /*
3440 * eSAP_DFS_CHANNEL_CAC_RADAR_FOUND:
3441 * A Radar is found on current DFS Channel
3442 * while in CAC WAIT period So, do a channel
3443 * switch to randomly selected target channel.
3444 * Send the Channel change message to SME/PE.
3445 * sap_radar_found_status is set to 1
3446 */
3447 sap_signal_hdd_event(t_sap_ctx, NULL,
3448 eSAP_DFS_RADAR_DETECT,
3449 (void *)eSAP_STATUS_SUCCESS);
3450
3451 wlansap_channel_change_request(
3452 (void *)t_sap_ctx,
3453 mac_ctx->sap.SapDfsInfo.target_channel);
3454 }
3455 }
3456 } else if (msg == eSAP_DFS_CHANNEL_CAC_END) {
3457 cdf_status = sap_cac_end_notify(hal, roam_info);
3458 } else if (msg == eSAP_HDD_STOP_INFRA_BSS) {
3459 /* Transition from eSAP_DFS_CAC_WAIT to eSAP_DISCONNECTING */
3460 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_HIGH,
3461 FL("from state %s => %s"),
3462 "eSAP_DFS_CAC_WAIT", "eSAP_DISCONNECTING");
3463
3464 /*
3465 * Stop the CAC timer only in following conditions
3466 * single AP: if there is a single AP then stop the timer
3467 * mulitple APs: incase of multiple APs, make sure that
3468 * all APs are down.
3469 */
3470 if (NULL == sap_find_valid_concurrent_session(hal)) {
3471 CDF_TRACE(CDF_MODULE_ID_SAP,
3472 CDF_TRACE_LEVEL_INFO_MED,
3473 FL("sapdfs: no sessions are valid, stopping timer"));
3474 sap_stop_dfs_cac_timer(sap_ctx);
3475 }
3476
3477 sap_ctx->sapsMachine = eSAP_DISCONNECTING;
3478 cdf_status = sap_goto_disconnecting(sap_ctx);
3479 } else {
3480 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_ERROR,
3481 FL("in state %s, invalid event msg %d"),
3482 "eSAP_DFS_CAC_WAIT", msg);
3483 }
3484
3485 return cdf_status;
3486}
3487
3488/**
3489 * sap_fsm_state_starting() - utility function called from sap fsm
3490 * @sap_ctx: SAP context
3491 * @sap_event: SAP event buffer
3492 * @mac_ctx: global MAC context
3493 * @hal: HAL handle
3494 *
3495 * This function is called for state transition from "eSAP_STARTING"
3496 *
3497 * Return: CDF_STATUS
3498 */
3499static CDF_STATUS sap_fsm_state_starting(ptSapContext sap_ctx,
3500 ptWLAN_SAPEvent sap_event, tpAniSirGlobal mac_ctx,
3501 tHalHandle hal)
3502{
3503 uint32_t msg = sap_event->event;
3504 tCsrRoamInfo *roam_info = (tCsrRoamInfo *) (sap_event->params);
3505 tSapDfsInfo *sap_dfs_info;
3506 CDF_STATUS cdf_status = CDF_STATUS_E_FAILURE;
3507
3508 if (msg == eSAP_MAC_START_BSS_SUCCESS) {
3509 /*
3510 * Transition from eSAP_STARTING to eSAP_STARTED
3511 * (both without substates)
3512 */
3513 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_HIGH,
3514 FL("from state channel = %d %s => %s"),
3515 sap_ctx->channel, "eSAP_STARTING", "eSAP_STARTED");
3516 sap_ctx->sapsMachine = eSAP_STARTED;
3517
3518 /* Action code for transition */
3519 cdf_status = sap_signal_hdd_event(sap_ctx, roam_info,
3520 eSAP_START_BSS_EVENT,
3521 (void *) eSAP_STATUS_SUCCESS);
3522
3523 /*
3524 * The upper layers have been informed that AP is up and
3525 * running, however, the AP is still not beaconing, until
3526 * CAC is done if the operating channel is DFS
3527 */
3528 if (CHANNEL_STATE_DFS ==
3529 cds_get_channel_state(sap_ctx->channel)) {
3530 sap_dfs_info = &mac_ctx->sap.SapDfsInfo;
3531 if ((false == sap_dfs_info->ignore_cac) &&
3532 (eSAP_DFS_DO_NOT_SKIP_CAC ==
3533 sap_dfs_info->cac_state)) {
3534 /* Move the device in CAC_WAIT_STATE */
3535 sap_ctx->sapsMachine = eSAP_DFS_CAC_WAIT;
3536
3537 /*
3538 * Need to stop the OS transmit queues,
3539 * so that no traffic can flow down the stack
3540 */
3541
3542 /* Start CAC wait timer */
3543 if (sap_dfs_info->is_dfs_cac_timer_running !=
3544 true)
3545 sap_start_dfs_cac_timer(sap_ctx);
3546 cdf_status = sap_cac_start_notify(hal);
3547
3548 } else {
3549 wlansap_start_beacon_req(sap_ctx);
3550 }
3551 }
3552 } else if (msg == eSAP_MAC_START_FAILS) {
3553 /*
3554 * Transition from STARTING to DISCONNECTED
3555 * (both without substates)
3556 */
3557 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_ERROR,
3558 FL("from state %s => %s"),
3559 "eSAP_STARTING", "eSAP_DISCONNECTED");
3560
3561 /*Action code for transition */
3562 cdf_status = sap_signal_hdd_event(sap_ctx, NULL,
3563 eSAP_START_BSS_EVENT,
3564 (void *) eSAP_STATUS_FAILURE);
3565 cdf_status = sap_goto_disconnected(sap_ctx);
3566 /* Advance outer statevar */
3567 sap_ctx->sapsMachine = eSAP_DISCONNECTED;
3568 } else if (msg == eSAP_HDD_STOP_INFRA_BSS) {
3569 /*
3570 * Transition from eSAP_STARTING to eSAP_DISCONNECTED
3571 * (both without substates)
3572 */
3573 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_HIGH,
3574 FL("from state %s => %s"),
3575 "eSAP_STARTING", "eSAP_DISCONNECTED");
3576
3577 /* Advance outer statevar */
3578 sap_ctx->sapsMachine = eSAP_DISCONNECTED;
3579 cdf_status = sap_signal_hdd_event(sap_ctx, NULL,
3580 eSAP_START_BSS_EVENT,
3581 (void *) eSAP_STATUS_FAILURE);
3582 cdf_status = sap_goto_disconnected(sap_ctx);
3583 /* Close the SME session */
3584
3585 if (eSAP_TRUE == sap_ctx->isSapSessionOpen) {
3586 if (CDF_STATUS_SUCCESS == sap_close_session(hal,
3587 sap_ctx, NULL, false))
3588 sap_ctx->isSapSessionOpen = eSAP_FALSE;
3589 }
3590 } else if (msg == eSAP_OPERATING_CHANNEL_CHANGED) {
3591 /* The operating channel has changed, update hostapd */
3592 sap_ctx->channel =
3593 (uint8_t) mac_ctx->sap.SapDfsInfo.target_channel;
3594
3595 sap_ctx->sapsMachine = eSAP_STARTED;
3596
3597 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_HIGH,
3598 FL("from state %s => %s"),
3599 "eSAP_STARTING", "eSAP_STARTED");
3600
3601 /* Indicate change in the state to upper layers */
3602 cdf_status = sap_signal_hdd_event(sap_ctx, roam_info,
3603 eSAP_START_BSS_EVENT,
3604 (void *)eSAP_STATUS_SUCCESS);
3605 } else {
3606 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_ERROR,
3607 FL("in state %s, invalid event msg %d"),
3608 "eSAP_STARTING", msg);
3609 }
3610
3611 return cdf_status;
3612}
3613
3614/**
3615 * sap_fsm_state_started() - utility function called from sap fsm
3616 * @sap_ctx: SAP context
3617 * @sap_event: SAP event buffer
3618 * @mac_ctx: global MAC context
3619 *
3620 * This function is called for state transition from "eSAP_STARTED"
3621 *
3622 * Return: CDF_STATUS
3623 */
3624static CDF_STATUS sap_fsm_state_started(ptSapContext sap_ctx,
3625 ptWLAN_SAPEvent sap_event, tpAniSirGlobal mac_ctx)
3626{
3627 uint32_t msg = sap_event->event;
3628 CDF_STATUS cdf_status = CDF_STATUS_E_FAILURE;
3629
3630 if (msg == eSAP_HDD_STOP_INFRA_BSS) {
3631 /*
3632 * Transition from eSAP_STARTED to eSAP_DISCONNECTING
3633 * (both without substates)
3634 */
3635 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_HIGH,
3636 FL("from state %s => %s"),
3637 "eSAP_STARTED", "eSAP_DISCONNECTING");
3638 sap_ctx->sapsMachine = eSAP_DISCONNECTING;
3639 cdf_status = sap_goto_disconnecting(sap_ctx);
3640 } else if (eSAP_DFS_CHNL_SWITCH_ANNOUNCEMENT_START == msg) {
3641 uint8_t intf;
3642 /*
3643 * Radar is seen on the current operating channel
3644 * send CSA IE for all associated stations
3645 * Request for CSA IE transmission
3646 */
3647 for (intf = 0; intf < SAP_MAX_NUM_SESSION; intf++) {
3648 ptSapContext temp_sap_ctx;
3649 if (((CDF_SAP_MODE ==
3650 mac_ctx->sap.sapCtxList[intf].sapPersona) ||
3651 (CDF_P2P_GO_MODE ==
3652 mac_ctx->sap.sapCtxList[intf].sapPersona)) &&
3653 mac_ctx->sap.sapCtxList[intf].pSapContext != NULL) {
3654 temp_sap_ctx =
3655 mac_ctx->sap.sapCtxList[intf].pSapContext;
3656 CDF_TRACE(CDF_MODULE_ID_SAP,
3657 CDF_TRACE_LEVEL_INFO_MED,
3658 FL("sapdfs: Sending CSAIE for sapctx[%p]"),
3659 temp_sap_ctx);
3660
3661 cdf_status = wlansap_dfs_send_csa_ie_request(
3662 (void *) temp_sap_ctx);
3663 }
3664 }
3665 } else {
3666 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_ERROR,
3667 FL("in state %s, invalid event msg %d"),
3668 "eSAP_STARTED", msg);
3669 }
3670
3671 return cdf_status;
3672}
3673
3674/**
3675 * sap_fsm_state_disconnecting() - utility function called from sap fsm
3676 * @sap_ctx: SAP context
3677 * @sap_event: SAP event buffer
3678 * @mac_ctx: global MAC context
3679 *
3680 * This function is called for state transition from "eSAP_DISCONNECTING"
3681 *
3682 * Return: CDF_STATUS
3683 */
3684static CDF_STATUS sap_fsm_state_disconnecting(ptSapContext sap_ctx,
3685 ptWLAN_SAPEvent sap_event, tpAniSirGlobal mac_ctx,
3686 tHalHandle hal)
3687{
3688 uint32_t msg = sap_event->event;
3689 CDF_STATUS cdf_status = CDF_STATUS_E_FAILURE;
3690
3691 if (msg == eSAP_MAC_READY_FOR_CONNECTIONS) {
3692 /*
3693 * Transition from eSAP_DISCONNECTING to eSAP_DISCONNECTED
3694 * (both without substates)
3695 */
3696 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_HIGH,
3697 FL("from state %s => %s"),
3698 "eSAP_DISCONNECTING", "eSAP_DISCONNECTED");
3699 sap_ctx->sapsMachine = eSAP_DISCONNECTED;
3700
3701 /* Close the SME session */
3702 if (eSAP_TRUE == sap_ctx->isSapSessionOpen) {
3703 sap_ctx->isSapSessionOpen = eSAP_FALSE;
3704 cdf_status = sap_close_session(hal, sap_ctx,
3705 sap_roam_session_close_callback, true);
3706 if (!CDF_IS_STATUS_SUCCESS(cdf_status)) {
3707 cdf_status = sap_signal_hdd_event(sap_ctx, NULL,
3708 eSAP_STOP_BSS_EVENT,
3709 (void *)eSAP_STATUS_SUCCESS);
3710 }
3711 }
3712 } else if (msg == eWNI_SME_CHANNEL_CHANGE_REQ) {
3713 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_MED,
3714 FL("sapdfs: Send channel change request on sapctx[%p]"),
3715 sap_ctx);
3716 /*
3717 * Most likely, radar has been detected and SAP wants to
3718 * change the channel
3719 */
3720 cdf_status = wlansap_channel_change_request((void *) sap_ctx,
3721 mac_ctx->sap.SapDfsInfo.target_channel);
3722
3723 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO,
3724 FL("Sending DFS eWNI_SME_CHANNEL_CHANGE_REQ"));
3725 } else {
3726 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_ERROR,
3727 FL("in state %s, invalid event msg %d"),
3728 "eSAP_DISCONNECTING", msg);
3729 }
3730
3731 return cdf_status;
3732}
3733
3734/**
3735 * sap_fsm() - SAP statem machine entry function
3736 * @sap_ctx: SAP context
3737 * @sap_event: SAP event
3738 *
3739 * SAP statem machine entry function
3740 *
3741 * Return: CDF_STATUS
3742 */
3743CDF_STATUS sap_fsm(ptSapContext sap_ctx, ptWLAN_SAPEvent sap_event)
3744{
3745 /*
3746 * Retrieve the phy link state machine structure
3747 * from the sap_ctx value
3748 * state var that keeps track of state machine
3749 */
3750 eSapFsmStates_t state_var = sap_ctx->sapsMachine;
3751 uint32_t msg = sap_event->event; /* State machine input event message */
3752 CDF_STATUS cdf_status = CDF_STATUS_E_FAILURE;
3753 tHalHandle hal = CDS_GET_HAL_CB(sap_ctx->p_cds_gctx);
3754 tpAniSirGlobal mac_ctx;
3755
3756 if (NULL == hal) {
3757 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_ERROR,
3758 FL("Invalid hal"));
3759 return CDF_STATUS_E_FAILURE;
3760 }
3761
3762 mac_ctx = PMAC_STRUCT(hal);
3763 if (NULL == mac_ctx) {
3764 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_ERROR,
3765 FL("Invalid MAC context"));
3766 return CDF_STATUS_E_FAILURE;
3767 }
3768
3769 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_DEBUG,
3770 FL("sap_ctx=%p, state_var=%d, msg=0x%x"),
3771 sap_ctx, state_var, msg);
3772
3773 switch (state_var) {
3774 case eSAP_DISCONNECTED:
3775 cdf_status = sap_fsm_state_disconnected(sap_ctx, sap_event,
3776 mac_ctx, hal);
3777 break;
3778
3779 case eSAP_CH_SELECT:
3780 cdf_status = sap_fsm_state_ch_select(sap_ctx, sap_event,
3781 mac_ctx, hal);
3782 break;
3783
3784 case eSAP_DFS_CAC_WAIT:
3785 cdf_status = sap_fsm_state_dfs_cac_wait(sap_ctx, sap_event,
3786 mac_ctx, hal);
3787 break;
3788
3789 case eSAP_STARTING:
3790 cdf_status = sap_fsm_state_starting(sap_ctx, sap_event,
3791 mac_ctx, hal);
3792 break;
3793
3794 case eSAP_STARTED:
3795 cdf_status = sap_fsm_state_started(sap_ctx, sap_event,
3796 mac_ctx);
3797 break;
3798
3799 case eSAP_DISCONNECTING:
3800 cdf_status = sap_fsm_state_disconnecting(sap_ctx, sap_event,
3801 mac_ctx, hal);
3802 break;
3803 }
3804 return cdf_status;
3805}
3806
3807eSapStatus
3808sapconvert_to_csr_profile(tsap_Config_t *pconfig_params, eCsrRoamBssType bssType,
3809 tCsrRoamProfile *profile)
3810{
3811 /* Create Roam profile for SoftAP to connect */
3812 profile->BSSType = eCSR_BSS_TYPE_INFRA_AP;
3813 profile->SSIDs.numOfSSIDs = 1;
3814 profile->csrPersona = pconfig_params->persona;
3815 profile->disableDFSChSwitch = pconfig_params->disableDFSChSwitch;
3816
3817 cdf_mem_zero(profile->SSIDs.SSIDList[0].SSID.ssId,
3818 sizeof(profile->SSIDs.SSIDList[0].SSID.ssId));
3819
3820 /* Flag to not broadcast the SSID information */
3821 profile->SSIDs.SSIDList[0].ssidHidden =
3822 pconfig_params->SSIDinfo.ssidHidden;
3823
3824 profile->SSIDs.SSIDList[0].SSID.length =
3825 pconfig_params->SSIDinfo.ssid.length;
3826 cdf_mem_copy(&profile->SSIDs.SSIDList[0].SSID.ssId,
3827 pconfig_params->SSIDinfo.ssid.ssId,
3828 sizeof(pconfig_params->SSIDinfo.ssid.ssId));
3829
3830 profile->negotiatedAuthType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
3831
3832 if (pconfig_params->authType == eSAP_OPEN_SYSTEM) {
3833 profile->negotiatedAuthType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
3834 } else if (pconfig_params->authType == eSAP_SHARED_KEY) {
3835 profile->negotiatedAuthType = eCSR_AUTH_TYPE_SHARED_KEY;
3836 } else {
3837 profile->negotiatedAuthType = eCSR_AUTH_TYPE_AUTOSWITCH;
3838 }
3839
3840 profile->AuthType.numEntries = 1;
3841 profile->AuthType.authType[0] = eCSR_AUTH_TYPE_OPEN_SYSTEM;
3842
3843 /* Always set the Encryption Type */
3844 profile->EncryptionType.numEntries = 1;
3845 profile->EncryptionType.encryptionType[0] =
3846 pconfig_params->RSNEncryptType;
3847
3848 profile->mcEncryptionType.numEntries = 1;
3849 profile->mcEncryptionType.encryptionType[0] =
3850 pconfig_params->mcRSNEncryptType;
3851
3852 if (pconfig_params->privacy & eSAP_SHARED_KEY) {
3853 profile->AuthType.authType[0] = eCSR_AUTH_TYPE_SHARED_KEY;
3854 }
3855
3856 profile->privacy = pconfig_params->privacy;
3857 profile->fwdWPSPBCProbeReq = pconfig_params->fwdWPSPBCProbeReq;
3858
3859 if (pconfig_params->authType == eSAP_SHARED_KEY) {
3860 profile->csr80211AuthType = eSIR_SHARED_KEY;
3861 } else if (pconfig_params->authType == eSAP_OPEN_SYSTEM) {
3862 profile->csr80211AuthType = eSIR_OPEN_SYSTEM;
3863 } else {
3864 profile->csr80211AuthType = eSIR_AUTO_SWITCH;
3865 }
3866
3867 /* Initialize we are not going to use it */
3868 profile->pWPAReqIE = NULL;
3869 profile->nWPAReqIELength = 0;
3870
3871 /* set the RSN/WPA IE */
3872 profile->pRSNReqIE = NULL;
3873 profile->nRSNReqIELength = pconfig_params->RSNWPAReqIELength;
3874 if (pconfig_params->RSNWPAReqIELength) {
3875 profile->pRSNReqIE =
3876 cdf_mem_malloc(pconfig_params->RSNWPAReqIELength);
3877 if (NULL == profile->pRSNReqIE) {
3878 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_ERROR,
3879 " %s Fail to alloc memory", __func__);
3880 return eSAP_STATUS_FAILURE;
3881 }
3882 cdf_mem_copy(profile->pRSNReqIE, pconfig_params->RSNWPAReqIE,
3883 pconfig_params->RSNWPAReqIELength);
3884 profile->nRSNReqIELength = pconfig_params->RSNWPAReqIELength;
3885 }
3886 /* Turn off CB mode */
3887 profile->CBMode = eCSR_CB_OFF;
3888
3889 /* set the phyMode to accept anything */
3890 /* Best means everything because it covers all the things we support */
3891 /* eCSR_DOT11_MODE_BEST */
3892 profile->phyMode = pconfig_params->SapHw_mode;
3893
3894 /* Configure beaconInterval */
3895 profile->beaconInterval = (uint16_t) pconfig_params->beacon_int;
3896
3897 /* set DTIM period */
3898 profile->dtimPeriod = pconfig_params->dtim_period;
3899
3900 /* set Uapsd enable bit */
3901 profile->ApUapsdEnable = pconfig_params->UapsdEnable;
3902
3903 /* Enable protection parameters */
3904 profile->protEnabled = pconfig_params->protEnabled;
3905 profile->obssProtEnabled = pconfig_params->obssProtEnabled;
3906 profile->cfg_protection = pconfig_params->ht_capab;
3907
3908 /* country code */
3909 if (pconfig_params->countryCode[0])
3910 cdf_mem_copy(profile->countryCode, pconfig_params->countryCode,
3911 WNI_CFG_COUNTRY_CODE_LEN);
3912 profile->ieee80211d = pconfig_params->ieee80211d;
3913 /* wps config info */
3914 profile->wps_state = pconfig_params->wps_state;
3915
3916#ifdef WLAN_FEATURE_11W
3917 /* MFP capable/required */
3918 profile->MFPCapable = pconfig_params->mfpCapable ? 1 : 0;
3919 profile->MFPRequired = pconfig_params->mfpRequired ? 1 : 0;
3920#endif
3921
3922 if (pconfig_params->probeRespIEsBufferLen > 0 &&
3923 pconfig_params->pProbeRespIEsBuffer != NULL) {
3924 profile->addIeParams.probeRespDataLen =
3925 pconfig_params->probeRespIEsBufferLen;
3926 profile->addIeParams.probeRespData_buff =
3927 pconfig_params->pProbeRespIEsBuffer;
3928 } else {
3929 profile->addIeParams.probeRespDataLen = 0;
3930 profile->addIeParams.probeRespData_buff = NULL;
3931 }
3932 /*assoc resp IE */
3933 if (pconfig_params->assocRespIEsLen > 0 &&
3934 pconfig_params->pAssocRespIEsBuffer != NULL) {
3935 profile->addIeParams.assocRespDataLen =
3936 pconfig_params->assocRespIEsLen;
3937 profile->addIeParams.assocRespData_buff =
3938 pconfig_params->pAssocRespIEsBuffer;
3939 } else {
3940 profile->addIeParams.assocRespDataLen = 0;
3941 profile->addIeParams.assocRespData_buff = NULL;
3942 }
3943
3944 if (pconfig_params->probeRespBcnIEsLen > 0 &&
3945 pconfig_params->pProbeRespBcnIEsBuffer != NULL) {
3946 profile->addIeParams.probeRespBCNDataLen =
3947 pconfig_params->probeRespBcnIEsLen;
3948 profile->addIeParams.probeRespBCNData_buff =
3949 pconfig_params->pProbeRespBcnIEsBuffer;
3950 } else {
3951 profile->addIeParams.probeRespBCNDataLen = 0;
3952 profile->addIeParams.probeRespBCNData_buff = NULL;
3953 }
3954 profile->sap_dot11mc = pconfig_params->sap_dot11mc;
3955
3956 return eSAP_STATUS_SUCCESS; /* Success. */
3957}
3958
3959void sap_free_roam_profile(tCsrRoamProfile *profile)
3960{
3961 if (profile->pRSNReqIE) {
3962 cdf_mem_free(profile->pRSNReqIE);
3963 profile->pRSNReqIE = NULL;
3964 }
3965}
3966
3967void sap_sort_mac_list(struct cdf_mac_addr *macList, uint8_t size)
3968{
3969 uint8_t outer, inner;
3970 struct cdf_mac_addr temp;
3971 int32_t nRes = -1;
3972
3973 if ((NULL == macList) || (size > MAX_ACL_MAC_ADDRESS)) {
3974 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_HIGH,
3975 FL("either buffer is NULL or size = %d is more"), size);
3976 return;
3977 }
3978
3979 for (outer = 0; outer < size; outer++) {
3980 for (inner = 0; inner < size - 1; inner++) {
3981 nRes =
3982 cdf_mem_compare2((macList + inner)->bytes,
3983 (macList + inner + 1)->bytes,
3984 CDF_MAC_ADDR_SIZE);
3985 if (nRes > 0) {
3986 cdf_mem_copy(temp.bytes,
3987 (macList + inner + 1)->bytes,
3988 CDF_MAC_ADDR_SIZE);
3989 cdf_mem_copy((macList + inner + 1)->bytes,
3990 (macList + inner)->bytes,
3991 CDF_MAC_ADDR_SIZE);
3992 cdf_mem_copy((macList + inner)->bytes,
3993 temp.bytes, CDF_MAC_ADDR_SIZE);
3994 }
3995 }
3996 }
3997}
3998
3999eSapBool
4000sap_search_mac_list(struct cdf_mac_addr *macList,
4001 uint8_t num_mac, uint8_t *peerMac,
4002 uint8_t *index)
4003{
4004 int32_t nRes = -1;
4005 int8_t nStart = 0, nEnd, nMiddle;
4006 nEnd = num_mac - 1;
4007
4008 if ((NULL == macList) || (num_mac > MAX_ACL_MAC_ADDRESS)) {
4009 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_HIGH,
4010 FL("either buffer is NULL or size = %d is more."), num_mac);
4011 return eSAP_FALSE;
4012 }
4013
4014 while (nStart <= nEnd) {
4015 nMiddle = (nStart + nEnd) / 2;
4016 nRes =
4017 cdf_mem_compare2(&macList[nMiddle], peerMac,
4018 CDF_MAC_ADDR_SIZE);
4019
4020 if (0 == nRes) {
4021 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_HIGH,
4022 "search SUCC");
4023 /* "index equals NULL" means the caller does not need the */
4024 /* index value of the peerMac being searched */
4025 if (index != NULL) {
4026 *index = (uint8_t) nMiddle;
4027 CDF_TRACE(CDF_MODULE_ID_SAP,
4028 CDF_TRACE_LEVEL_INFO_HIGH, "index %d",
4029 *index);
4030 }
4031 return eSAP_TRUE;
4032 }
4033 if (nRes < 0)
4034 nStart = nMiddle + 1;
4035 else
4036 nEnd = nMiddle - 1;
4037 }
4038
4039 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_HIGH,
4040 "search not succ");
4041 return eSAP_FALSE;
4042}
4043
4044void sap_add_mac_to_acl(struct cdf_mac_addr *macList,
4045 uint8_t *size, uint8_t *peerMac)
4046{
4047 int32_t nRes = -1;
4048 int i;
4049
4050 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_HIGH,
4051 "add acl entered");
4052
4053 if (NULL == macList || *size == 0 || *size > MAX_ACL_MAC_ADDRESS) {
4054 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_HIGH,
4055 FL("either buffer is NULL or size = %d is incorrect."),
4056 *size);
4057 return;
4058 }
4059
4060 for (i = ((*size) - 1); i >= 0; i--) {
4061 nRes =
4062 cdf_mem_compare2(&macList[i], peerMac, CDF_MAC_ADDR_SIZE);
4063 if (nRes > 0) {
4064 /* Move alphabetically greater mac addresses one index down to allow for insertion
4065 of new mac in sorted order */
4066 cdf_mem_copy((macList + i + 1)->bytes,
4067 (macList + i)->bytes, CDF_MAC_ADDR_SIZE);
4068 } else {
4069 break;
4070 }
4071 }
4072 /* This should also take care of if the element is the first to be added in the list */
4073 cdf_mem_copy((macList + i + 1)->bytes, peerMac, CDF_MAC_ADDR_SIZE);
4074 /* increment the list size */
4075 (*size)++;
4076}
4077
4078void sap_remove_mac_from_acl(struct cdf_mac_addr *macList,
4079 uint8_t *size, uint8_t index)
4080{
4081 int i;
4082
4083 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_HIGH,
4084 "remove acl entered");
4085 /*
4086 * Return if the list passed is empty. Ideally this should never happen
4087 * since this funcn is always called after sap_search_mac_list to get
4088 * the index of the mac addr to be removed and this will only get
4089 * called if the search is successful. Still no harm in having the check
4090 */
4091 if ((macList == NULL) || (*size == 0) ||
4092 (*size > MAX_ACL_MAC_ADDRESS)) {
4093 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_HIGH,
4094 FL("either buffer is NULL or size %d is incorrect."),
4095 *size);
4096 return;
4097 }
4098 for (i = index; i < ((*size) - 1); i++) {
4099 /* Move mac addresses starting from "index" passed one index up to delete the void
4100 created by deletion of a mac address in ACL */
4101 cdf_mem_copy((macList + i)->bytes, (macList + i + 1)->bytes,
4102 CDF_MAC_ADDR_SIZE);
4103 }
4104 /* The last space should be made empty since all mac addesses moved one step up */
4105 cdf_mem_zero((macList + (*size) - 1)->bytes, CDF_MAC_ADDR_SIZE);
4106 /* reduce the list size by 1 */
4107 (*size)--;
4108}
4109
4110void sap_print_acl(struct cdf_mac_addr *macList, uint8_t size)
4111{
4112 int i;
4113 uint8_t *macArray;
4114 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_HIGH,
4115 "print acl entered");
4116
4117 if ((NULL == macList) || (size == 0) || (size >= MAX_ACL_MAC_ADDRESS)) {
4118 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_HIGH,
4119 "In %s, either buffer is NULL or size %d is incorrect.",
4120 __func__, size);
4121 return;
4122 }
4123
4124 for (i = 0; i < size; i++) {
4125 macArray = (macList + i)->bytes;
4126 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_HIGH,
4127 "** ACL entry %i - " MAC_ADDRESS_STR, i,
4128 MAC_ADDR_ARRAY(macArray));
4129 }
4130 return;
4131}
4132
4133CDF_STATUS sap_is_peer_mac_allowed(ptSapContext sapContext, uint8_t *peerMac)
4134{
4135 if (eSAP_ALLOW_ALL == sapContext->eSapMacAddrAclMode)
4136 return CDF_STATUS_SUCCESS;
4137
4138 if (sap_search_mac_list
4139 (sapContext->acceptMacList, sapContext->nAcceptMac, peerMac, NULL))
4140 return CDF_STATUS_SUCCESS;
4141
4142 if (sap_search_mac_list
4143 (sapContext->denyMacList, sapContext->nDenyMac, peerMac, NULL)) {
4144 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_HIGH,
4145 "In %s, Peer " MAC_ADDRESS_STR " in deny list",
4146 __func__, MAC_ADDR_ARRAY(peerMac));
4147 return CDF_STATUS_E_FAILURE;
4148 }
4149 /* A new station CAN associate, unless in deny list. Less stringent mode */
4150 if (eSAP_ACCEPT_UNLESS_DENIED == sapContext->eSapMacAddrAclMode)
4151 return CDF_STATUS_SUCCESS;
4152
4153 /* A new station CANNOT associate, unless in accept list. More stringent mode */
4154 if (eSAP_DENY_UNLESS_ACCEPTED == sapContext->eSapMacAddrAclMode) {
4155 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_HIGH,
4156 "In %s, Peer " MAC_ADDRESS_STR
4157 " denied, Mac filter mode is eSAP_DENY_UNLESS_ACCEPTED",
4158 __func__, MAC_ADDR_ARRAY(peerMac));
4159 return CDF_STATUS_E_FAILURE;
4160 }
4161
4162 /* The new STA is neither in accept list nor in deny list. In this case, deny the association
4163 * but send a wifi event notification indicating the mac address being denied
4164 */
4165 if (eSAP_SUPPORT_ACCEPT_AND_DENY == sapContext->eSapMacAddrAclMode) {
4166 sap_signal_hdd_event(sapContext, NULL, eSAP_UNKNOWN_STA_JOIN,
4167 (void *) peerMac);
4168 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_HIGH,
4169 "In %s, Peer " MAC_ADDRESS_STR
4170 " denied, Mac filter mode is eSAP_SUPPORT_ACCEPT_AND_DENY",
4171 __func__, MAC_ADDR_ARRAY(peerMac));
4172 return CDF_STATUS_E_FAILURE;
4173 }
4174 return CDF_STATUS_SUCCESS;
4175}
4176
4177#ifdef SOFTAP_CHANNEL_RANGE
4178/**
4179 * sap_get_channel_list() - get the list of channels
4180 * @sap_ctx: sap context
4181 * @ch_list: pointer to channel list array
4182 * @num_ch: pointer to number of channels.
4183 *
4184 * This function populates the list of channels for scanning.
4185 *
4186 * Return: CDF_STATUS
4187 */
4188static CDF_STATUS sap_get_channel_list(ptSapContext sap_ctx,
4189 uint8_t **ch_list,
4190 uint8_t *num_ch)
4191{
4192 uint8_t loop_count;
4193 uint8_t *list;
4194 uint8_t ch_count;
4195 uint8_t start_ch_num, band_start_ch;
4196 uint8_t end_ch_num, band_end_ch;
4197 uint32_t en_lte_coex;
4198 tHalHandle hal = CDS_GET_HAL_CB(sap_ctx->p_cds_gctx);
4199#ifdef FEATURE_WLAN_CH_AVOID
4200 uint8_t i;
4201#endif
4202 tpAniSirGlobal mac_ctx = PMAC_STRUCT(hal);
4203
4204 if (NULL == hal) {
4205 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_ERROR,
4206 FL("Invalid HAL pointer from p_cds_gctx"));
4207 *num_ch = 0;
4208 *ch_list = NULL;
4209 return CDF_STATUS_E_FAULT;
4210 }
4211
4212 start_ch_num = sap_ctx->acs_cfg->start_ch;
4213 end_ch_num = sap_ctx->acs_cfg->end_ch;
4214 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO,
4215 FL("startChannel %d, EndChannel %d, HW:%d"),
4216 start_ch_num, end_ch_num,
4217 sap_ctx->acs_cfg->hw_mode);
4218
4219 wlansap_extend_to_acs_range(&start_ch_num, &end_ch_num,
4220 &band_start_ch, &band_end_ch);
4221
4222 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO,
4223 FL("expanded startChannel %d,EndChannel %d"),
4224 start_ch_num, end_ch_num);
4225
4226 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO,
4227 FL("band_start_ch %d, band_end_ch %d"),
4228 band_start_ch, band_end_ch);
4229
4230 sme_cfg_get_int(hal, WNI_CFG_ENABLE_LTE_COEX, &en_lte_coex);
4231
4232 /* Check if LTE coex is enabled and 2.4GHz is selected */
4233 if (en_lte_coex && (band_start_ch == RF_CHAN_1) &&
4234 (band_end_ch == RF_CHAN_14)) {
4235 /* Set 2.4GHz upper limit to channel 9 for LTE COEX */
4236 band_end_ch = RF_CHAN_9;
4237 }
4238
4239 /* Allocate the max number of channel supported */
4240 list = (uint8_t *) cdf_mem_malloc(NUM_5GHZ_CHANNELS +
4241 NUM_24GHZ_CHANNELS);
4242 if (NULL == list) {
4243 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_ERROR,
4244 FL("Unable to allocate channel list"));
4245 *num_ch = 0;
4246 *ch_list = NULL;
4247 return CDF_STATUS_E_NOMEM;
4248 }
4249
4250 /* Search for the Active channels in the given range */
4251 ch_count = 0;
4252 for (loop_count = band_start_ch; loop_count <= band_end_ch;
4253 loop_count++) {
4254 /* go to next channel if rf_channel is out of range */
4255 if ((start_ch_num > rf_channels[loop_count].channelNum) ||
4256 (end_ch_num < rf_channels[loop_count].channelNum))
4257 continue;
4258 /*
4259 * go to next channel if none of these condition pass
4260 * - DFS scan enabled and chan not in CHANNEL_STATE_DISABLE
4261 * - DFS scan disable but chan in CHANNEL_STATE_ENABLE
4262 */
4263 if (!(((eSAP_TRUE == mac_ctx->scan.fEnableDFSChnlScan) &&
4264 (reg_channels[loop_count].enabled)) ||
4265 ((eSAP_FALSE == mac_ctx->scan.fEnableDFSChnlScan) &&
4266 (CHANNEL_STATE_ENABLE ==
4267 reg_channels[loop_count].enabled))))
4268 continue;
4269
4270#ifdef FEATURE_WLAN_CH_AVOID
4271 for (i = 0; i < NUM_20MHZ_RF_CHANNELS; i++) {
4272 if ((safe_channels[i].channelNumber ==
4273 rf_channels[loop_count].channelNum)) {
4274 /* Check if channel is safe */
4275 if (true == safe_channels[i].isSafe) {
4276#endif
4277#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
4278 uint8_t ch;
4279 ch = rf_channels[loop_count].channelNum;
4280 if ((sap_ctx->acs_cfg->skip_scan_status ==
4281 eSAP_DO_PAR_ACS_SCAN)) {
4282 if ((ch >= sap_ctx->acs_cfg->skip_scan_range1_stch &&
4283 ch <= sap_ctx->acs_cfg->skip_scan_range1_endch) ||
4284 (ch >= sap_ctx->acs_cfg->skip_scan_range2_stch &&
4285 ch <= sap_ctx->acs_cfg->skip_scan_range2_endch)) {
4286 list[ch_count] =
4287 rf_channels[loop_count].channelNum;
4288 ch_count++;
4289 CDF_TRACE(CDF_MODULE_ID_SAP,
4290 CDF_TRACE_LEVEL_INFO,
4291 FL("%d %d added to ACS ch range"),
4292 ch_count, ch);
4293 } else {
4294 CDF_TRACE(CDF_MODULE_ID_SAP,
4295 CDF_TRACE_LEVEL_INFO_HIGH,
4296 FL("%d %d skipped from ACS ch range"),
4297 ch_count, ch);
4298 }
4299 } else {
4300 list[ch_count] =
4301 rf_channels[loop_count].channelNum;
4302 ch_count++;
4303 CDF_TRACE(CDF_MODULE_ID_SAP,
4304 CDF_TRACE_LEVEL_INFO,
4305 FL("%d %d added to ACS ch range"),
4306 ch_count, ch);
4307 }
4308#else
4309 list[ch_count] = rf_channels[loop_count].channelNum;
4310 ch_count++;
4311#endif
4312#ifdef FEATURE_WLAN_CH_AVOID
4313 }
4314 break;
4315 }
4316 }
4317#endif
4318 }
4319 if (0 == ch_count) {
4320 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_ERROR,
4321 FL("No active channels present for the current region"));
4322 /*
4323 * LTE COEX: channel range outside the restricted 2.4GHz
4324 * band limits
4325 */
4326 if (en_lte_coex && (start_ch_num > band_end_ch))
4327 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_FATAL,
4328 FL("SAP can't be started as due to LTE COEX"));
4329 }
4330
4331 /* return the channel list and number of channels to scan */
4332 *num_ch = ch_count;
4333 if (ch_count != 0) {
4334 *ch_list = list;
4335 } else {
4336 *ch_list = NULL;
4337 cdf_mem_free(list);
4338 }
4339
4340 for (loop_count = 0; loop_count < ch_count; loop_count++) {
4341 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_DEBUG,
4342 FL("channel number: %d"), list[loop_count]);
4343 }
4344 return CDF_STATUS_SUCCESS;
4345}
4346#endif
4347
4348/*
4349 * Function for initializing list of 2.4/5 Ghz [NON-DFS/DFS]
4350 * available channels in the current regulatory domain.
4351 */
4352static CDF_STATUS sap_get5_g_hz_channel_list(ptSapContext sapContext)
4353{
4354 uint8_t count = 0;
4355 int i;
4356 if (NULL == sapContext) {
4357 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_ERROR,
4358 "Invalid sapContext pointer on sap_get_channel_list");
4359 return CDF_STATUS_E_FAULT;
4360 }
4361
4362 if (sapContext->SapAllChnlList.channelList) {
4363 cdf_mem_free(sapContext->SapAllChnlList.channelList);
4364 sapContext->SapAllChnlList.channelList = NULL;
4365 }
4366
4367 sapContext->SapAllChnlList.channelList =
4368 (tChannelInfo *) cdf_mem_malloc(WNI_CFG_VALID_CHANNEL_LIST_LEN *
4369 sizeof(tChannelInfo));
4370 if (NULL == sapContext->SapAllChnlList.channelList) {
4371 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_ERROR,
4372 " Memory Allocation failed sap_get_channel_list");
4373 return CDF_STATUS_E_NOMEM;
4374 }
4375
4376 for (i = RF_CHAN_36; i <= RF_CHAN_165; i++) {
4377 if (reg_channels[i].enabled == CHANNEL_STATE_ENABLE ||
4378 reg_channels[i].enabled == CHANNEL_STATE_DFS) {
4379 sapContext->SapAllChnlList.channelList[count].channel =
4380 rf_channels[i].channelNum;
4381 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_LOW,
4382 "%s[%d] CHANNEL = %d", __func__, __LINE__,
4383 sapContext->SapAllChnlList.channelList[count].
4384 channel);
4385 sapContext->SapAllChnlList.channelList[count].valid =
4386 true;
4387 count++;
4388 }
4389 }
4390
4391 sapContext->SapAllChnlList.numChannel = count;
4392 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_LOW,
4393 "%s[%d] NUMBER OF CHANNELS count = %d"
4394 "sapContext->SapAllChnlList.numChannel = %d",
4395 __func__, __LINE__, count,
4396 sapContext->SapAllChnlList.numChannel);
4397 return CDF_STATUS_SUCCESS;
4398}
4399
4400/*
4401 * This function randomly selects the channel to switch after the detection
4402 * of radar
4403 * param sapContext - sap context
4404 * dfs_event - Dfs information from DFS
4405 * return - channel to which AP wishes to switch
4406 */
4407uint8_t sap_indicate_radar(ptSapContext sapContext,
4408 tSirSmeDfsEventInd *dfs_event)
4409{
4410 uint8_t target_channel = 0;
4411 tHalHandle hHal;
4412 tpAniSirGlobal pMac;
4413
4414 if (NULL == sapContext || NULL == dfs_event) {
4415 /* Invalid sap context of dfs event passed */
4416 return 0;
4417 }
4418 hHal = CDS_GET_HAL_CB(sapContext->p_cds_gctx);
4419
4420 if (NULL == hHal) {
4421 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_ERROR,
4422 "In %s invalid hHal", __func__);
4423 return 0;
4424 }
4425 pMac = PMAC_STRUCT(hHal);
4426
4427 if (!dfs_event->dfs_radar_status) {
4428 /*dfs status does not indicate a radar on the channel-- False Alarm */
4429 return 0;
4430 }
4431
4432 /*
4433 * SAP needs to generate Channel Switch IE
4434 * if the radar is found in the STARTED state
4435 */
4436 if (eSAP_STARTED == sapContext->sapsMachine)
4437 pMac->sap.SapDfsInfo.csaIERequired = eSAP_TRUE;
4438
4439 if (sapContext->csr_roamProfile.disableDFSChSwitch) {
4440 return sapContext->channel;
4441 }
4442
4443 /* set the Radar Found flag in SapDfsInfo */
4444 pMac->sap.SapDfsInfo.sap_radar_found_status = true;
4445
4446 sap_get5_g_hz_channel_list(sapContext);
4447
4448 if (dfs_event->chan_list.nchannels > SIR_DFS_MAX_20M_SUB_CH) {
4449 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_WARN,
4450 FL("nchannels >SIR_DFS_MAX_20M_SUB_CH so resetting"));
4451 dfs_event->chan_list.nchannels = SIR_DFS_MAX_20M_SUB_CH;
4452 }
4453
4454 sap_mark_dfs_channels(sapContext, dfs_event->chan_list.channels,
4455 dfs_event->chan_list.nchannels,
4456 cds_get_monotonic_boottime());
4457
4458 /*
4459 * (1) skip static turbo channel as it will require STA to be in
4460 * static turbo to work.
4461 * (2) skip channel which's marked with radar detction
4462 * (3) WAR: we allow user to config not to use any DFS channel
4463 * (4) When we pick a channel, skip excluded 11D channels
4464 * (5) Create the available channel list with the above rules
4465 */
4466
4467 target_channel = sap_random_channel_sel(sapContext);
4468 if (0 == target_channel) {
4469 sap_signal_hdd_event(sapContext, NULL,
4470 eSAP_DFS_NO_AVAILABLE_CHANNEL,
4471 (void *) eSAP_STATUS_SUCCESS);
4472 }
4473 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_WARN,
4474 FL("sapdfs: New selected target channel is [%d]"),
4475 target_channel);
4476 return target_channel;
4477}
4478
4479/*
4480 * CAC timer callback function.
4481 * Post eSAP_DFS_CHANNEL_CAC_END event to sap_fsm().
4482 */
4483void sap_dfs_cac_timer_callback(void *data)
4484{
4485 ptSapContext sapContext;
4486 tWLAN_SAPEvent sapEvent;
4487 tHalHandle hHal = (tHalHandle) data;
4488 tpAniSirGlobal pMac;
4489
4490 if (NULL == hHal) {
4491 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_ERROR,
4492 "In %s invalid hHal", __func__);
4493 return;
4494 }
4495 pMac = PMAC_STRUCT(hHal);
4496 sapContext = sap_find_valid_concurrent_session(hHal);
4497
4498 if (NULL == sapContext) {
4499 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_ERROR,
4500 "In %s no SAP contexts are found", __func__);
4501 return;
4502 }
4503
4504 /* Check to ensure that SAP is in DFS WAIT state */
4505 if (sapContext->sapsMachine == eSAP_DFS_CAC_WAIT) {
4506 cdf_mc_timer_destroy(&pMac->sap.SapDfsInfo.sap_dfs_cac_timer);
4507 pMac->sap.SapDfsInfo.is_dfs_cac_timer_running = false;
4508
4509 /*
4510 * CAC Complete, post eSAP_DFS_CHANNEL_CAC_END to sap_fsm
4511 */
4512 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_MED,
4513 "sapdfs: Sending eSAP_DFS_CHANNEL_CAC_END for target_channel = %d on sapctx[%p]",
4514 sapContext->channel, sapContext);
4515
4516 sapEvent.event = eSAP_DFS_CHANNEL_CAC_END;
4517 sapEvent.params = 0;
4518 sapEvent.u1 = 0;
4519 sapEvent.u2 = 0;
4520
4521 sap_fsm(sapContext, &sapEvent);
4522 }
4523
4524}
4525
4526/*
4527 * Function to stop the DFS CAC Timer
4528 */
4529static int sap_stop_dfs_cac_timer(ptSapContext sapContext)
4530{
4531 tHalHandle hHal;
4532 tpAniSirGlobal pMac;
4533 if (sapContext == NULL)
4534 return 0;
4535
4536 hHal = CDS_GET_HAL_CB(sapContext->p_cds_gctx);
4537 if (NULL == hHal) {
4538 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_ERROR,
4539 "In %s invalid hHal", __func__);
4540 return 0;
4541 }
4542 pMac = PMAC_STRUCT(hHal);
4543
4544 if (CDF_TIMER_STATE_RUNNING !=
4545 cdf_mc_timer_get_current_state(&pMac->sap.SapDfsInfo.
4546 sap_dfs_cac_timer)) {
4547 return 0;
4548 }
4549
4550 cdf_mc_timer_stop(&pMac->sap.SapDfsInfo.sap_dfs_cac_timer);
4551 pMac->sap.SapDfsInfo.is_dfs_cac_timer_running = 0;
4552
4553 return 0;
4554}
4555
4556
4557/**
4558 * sap_is_channel_bonding_etsi_weather_channel() - check weather chan bonding.
4559 * @sap_context: SAP context
4560 *
4561 * Check if the current SAP operating channel is bonded to weather radar
4562 * channel in ETSI domain.
4563 *
4564 * Return: True if bonded to weather channel in ETSI
4565 */
4566static bool
4567sap_is_channel_bonding_etsi_weather_channel(ptSapContext sap_context)
4568{
4569 if (IS_CH_BONDING_WITH_WEATHER_CH(sap_context->channel) &&
4570 (sap_context->ch_params.ch_width != CH_WIDTH_20MHZ))
4571 return true;
4572
4573 return false;
4574}
4575
4576/*
4577 * Function to start the DFS CAC Timer
4578 * when SAP is started on a DFS channel
4579 */
4580int sap_start_dfs_cac_timer(ptSapContext sapContext)
4581{
4582 CDF_STATUS status;
4583 uint32_t cacTimeOut;
4584 tHalHandle hHal = NULL;
4585 tpAniSirGlobal pMac = NULL;
4586 uint8_t dfs_region;
4587
4588 if (sapContext == NULL) {
4589 return 0;
4590 }
4591 hHal = CDS_GET_HAL_CB(sapContext->p_cds_gctx);
4592
4593 if (NULL == hHal) {
4594 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_ERROR,
4595 "In %s invalid hHal", __func__);
4596 return 0;
4597 }
4598 pMac = PMAC_STRUCT(hHal);
4599
4600 if (pMac->sap.SapDfsInfo.ignore_cac) {
4601 /*
4602 * If User has set to ignore the CAC
4603 * so, continue without CAC Timer.
4604 */
4605 return 2;
4606 }
4607 cacTimeOut = DEFAULT_CAC_TIMEOUT;
4608
4609 cds_get_dfs_region(&dfs_region);
4610
4611 if ((dfs_region == DFS_ETSI_DOMAIN)
4612 && ((IS_ETSI_WEATHER_CH(sapContext->channel)) ||
4613 (sap_is_channel_bonding_etsi_weather_channel(sapContext)))) {
4614 cacTimeOut = ETSI_WEATHER_CH_CAC_TIMEOUT;
4615 }
4616 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_MED,
4617 "sapdfs: SAP_DFS_CHANNEL_CAC_START on CH - %d, CAC TIMEOUT - %d sec",
4618 sapContext->channel, cacTimeOut / 1000);
4619
4620 cdf_mc_timer_init(&pMac->sap.SapDfsInfo.sap_dfs_cac_timer,
4621 CDF_TIMER_TYPE_SW,
4622 sap_dfs_cac_timer_callback, (void *) hHal);
4623
4624 /*Start the CAC timer */
4625 status =
4626 cdf_mc_timer_start(&pMac->sap.SapDfsInfo.sap_dfs_cac_timer,
4627 cacTimeOut);
4628 if (status == CDF_STATUS_SUCCESS) {
4629 pMac->sap.SapDfsInfo.is_dfs_cac_timer_running = true;
4630 return 1;
4631 } else {
4632 return 0;
4633 }
4634}
4635
4636/*
4637 * This function initializes the NOL list
4638 * parameters required to track the radar
4639 * found DFS channels in the current Reg. Domain .
4640 */
4641CDF_STATUS sap_init_dfs_channel_nol_list(ptSapContext sapContext)
4642{
4643 uint8_t count = 0;
4644 int i;
4645 bool bFound = false;
4646 tHalHandle hHal;
4647 tpAniSirGlobal pMac;
4648
4649 if (NULL == sapContext) {
4650 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_ERROR,
4651 "Invalid sapContext pointer on sap_init_dfs_channel_nol_list");
4652 return CDF_STATUS_E_FAULT;
4653 }
4654 hHal = CDS_GET_HAL_CB(sapContext->p_cds_gctx);
4655
4656 if (NULL == hHal) {
4657 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_ERROR,
4658 "In %s invalid hHal", __func__);
4659 return CDF_STATUS_E_FAULT;
4660 }
4661 pMac = PMAC_STRUCT(hHal);
4662
4663 /* to indicate hdd to get cnss dfs nol */
4664 if (CDF_STATUS_SUCCESS == sap_signal_hdd_event(sapContext, NULL,
4665 eSAP_DFS_NOL_GET,
4666 (void *)
4667 eSAP_STATUS_SUCCESS)) {
4668 bFound = true;
4669 }
4670
4671 for (i = RF_CHAN_36; i <= RF_CHAN_165; i++) {
4672 if (reg_channels[i].enabled == CHANNEL_STATE_DFS) {
4673 /* if dfs nol is not found, initialize it */
4674 if (!bFound) {
4675 pMac->sap.SapDfsInfo.sapDfsChannelNolList[count]
4676 .dfs_channel_number =
4677 rf_channels[i].channelNum;
4678
4679 CDF_TRACE(CDF_MODULE_ID_SAP,
4680 CDF_TRACE_LEVEL_INFO_LOW,
4681 "%s: CHANNEL = %d", __func__,
4682 pMac->sap.SapDfsInfo.
4683 sapDfsChannelNolList[count].
4684 dfs_channel_number);
4685
4686 pMac->sap.SapDfsInfo.sapDfsChannelNolList[count]
4687 .radar_status_flag =
4688 eSAP_DFS_CHANNEL_USABLE;
4689 pMac->sap.SapDfsInfo.sapDfsChannelNolList[count]
4690 .radar_found_timestamp = 0;
4691 }
4692 count++;
4693 }
4694 }
4695
4696 pMac->sap.SapDfsInfo.numCurrentRegDomainDfsChannels = count;
4697
4698 CDF_TRACE(CDF_MODULE_ID_SAP, CDF_TRACE_LEVEL_INFO_LOW,
4699 "%s[%d] NUMBER OF DFS CHANNELS = %d",
4700 __func__, __LINE__,
4701 pMac->sap.SapDfsInfo.numCurrentRegDomainDfsChannels);
4702
4703 return CDF_STATUS_SUCCESS;
4704}
4705
4706/*
4707 * This function will calculate how many interfaces
4708 * have sap persona and returns total number of sap persona.
4709 */
4710uint8_t sap_get_total_number_sap_intf(tHalHandle hHal)
4711{
4712 tpAniSirGlobal pMac = PMAC_STRUCT(hHal);
4713 uint8_t intf = 0;
4714 uint8_t intf_count = 0;
4715
4716 for (intf = 0; intf < SAP_MAX_NUM_SESSION; intf++) {
4717 if (((CDF_SAP_MODE == pMac->sap.sapCtxList[intf].sapPersona)
4718 ||
4719 (CDF_P2P_GO_MODE == pMac->sap.sapCtxList[intf].sapPersona))
4720 && pMac->sap.sapCtxList[intf].pSapContext != NULL) {
4721 intf_count++;
4722 }
4723 }
4724 return intf_count;
4725}
4726
4727/*
4728 * This function will find the concurrent sap context apart from
4729 * passed sap context and return its channel change ready status
4730 */
4731bool is_concurrent_sap_ready_for_channel_change(tHalHandle hHal,
4732 ptSapContext sapContext)
4733{
4734 tpAniSirGlobal pMac = PMAC_STRUCT(hHal);
4735 ptSapContext pSapContext;
4736 uint8_t intf = 0;
4737
4738 for (intf = 0; intf < SAP_MAX_NUM_SESSION; intf++) {
4739 if (((CDF_SAP_MODE == pMac->sap.sapCtxList[intf].sapPersona)
4740 ||
4741 (CDF_P2P_GO_MODE == pMac->sap.sapCtxList[intf].sapPersona))
4742 && pMac->sap.sapCtxList[intf].pSapContext != NULL) {
4743 pSapContext =
4744 (ptSapContext) pMac->sap.sapCtxList[intf].
4745 pSapContext;
4746 if (pSapContext == sapContext) {
4747 CDF_TRACE(CDF_MODULE_ID_SAP,
4748 CDF_TRACE_LEVEL_ERROR,
4749 FL("sapCtx matched [%p]"),
4750 sapContext);
4751 continue;
4752 } else {
4753 CDF_TRACE(CDF_MODULE_ID_SAP,
4754 CDF_TRACE_LEVEL_ERROR,
4755 FL
4756 ("concurrent sapCtx[%p] didn't matche with [%p]"),
4757 pSapContext, sapContext);
4758 return pSapContext->is_sap_ready_for_chnl_chng;
4759 }
4760 }
4761 }
4762 return false;
4763}