1 /*
2  * Copyright (c) 2011-2020 The Linux Foundation. All rights reserved.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for
5  * any purpose with or without fee is hereby granted, provided that the
6  * above copyright notice and this permission notice appear in all
7  * copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16  * PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 /**=========================================================================
20 
21    \file  lim_session_utils.c
22    \brief implementation for lim Session Utility  APIs
23    \author Sunit Bhatia
24    ========================================================================*/
25 
26 /*--------------------------------------------------------------------------
27    Include Files
28    ------------------------------------------------------------------------*/
29 #include "ani_global.h"
30 #include "lim_ft_defs.h"
31 #include "lim_session.h"
32 #include "lim_session_utils.h"
33 #include "lim_utils.h"
34 
35 /**
36  * lim_is_in_mcc() - check if device is in MCC
37  * @mac_ctx: Global MAC context.
38  *
39  * Return: true - if in MCC.
40  *         false - Not in MCC
41  **/
lim_is_in_mcc(struct mac_context * mac_ctx)42 uint8_t lim_is_in_mcc(struct mac_context *mac_ctx)
43 {
44 	uint8_t i;
45 	uint32_t freq = 0;
46 	uint32_t curr_oper_freq = 0;
47 
48 	for (i = 0; i < mac_ctx->lim.maxBssId; i++) {
49 		/*
50 		 * if another session is valid and it is on different channel
51 		 * it is an off channel operation.
52 		 */
53 		if ((mac_ctx->lim.gpSession[i].valid)) {
54 			curr_oper_freq =
55 				mac_ctx->lim.gpSession[i].curr_op_freq;
56 			if (curr_oper_freq == 0)
57 				continue;
58 			if (freq == 0)
59 				freq = curr_oper_freq;
60 			else if (freq != curr_oper_freq)
61 				return true;
62 		}
63 	}
64 	return false;
65 }
66 
67 /**
68  * pe_get_current_stas_count() - Total stations associated on all sessions.
69  * @mac_ctx: Global MAC context.
70  *
71  * Return: true - Number of stations active on all sessions.
72  **/
pe_get_current_stas_count(struct mac_context * mac_ctx)73 uint8_t pe_get_current_stas_count(struct mac_context *mac_ctx)
74 {
75 	uint8_t i;
76 	uint8_t stacount = 0;
77 
78 	for (i = 0; i < mac_ctx->lim.maxBssId; i++)
79 		if (mac_ctx->lim.gpSession[i].valid == true)
80 			stacount +=
81 				mac_ctx->lim.gpSession[i].gLimNumOfCurrentSTAs;
82 	return stacount;
83 }
84