blob: 77ee425448dd4593eb9ba9a6e1a03b8df2735bd8 [file] [log] [blame]
Jeff Johnson8bb61112018-03-31 13:33:54 -07001/*
2 * Copyright (c) 2012-2018 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 * DOC: wlan_hdd_green_ap.c
21 *
22 * WLAN Host Device Driver Green AP implementation
23 *
24 */
25
26#include <wlan_hdd_green_ap.h>
27#include <wlan_hdd_main.h>
28#include <wlan_policy_mgr_api.h>
29#include <wlan_green_ap_ucfg_api.h>
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053030#include "wlan_mlme_ucfg_api.h"
Jeff Johnson8bb61112018-03-31 13:33:54 -070031
32/**
33 * hdd_green_ap_check_enable() - to check whether to enable green ap or not
34 * @hdd_ctx: hdd context
35 * @enable_green_ap: 1 - enable green ap enabled, 0 - disbale green ap
36 *
37 * Return: 0 - success, < 0 - failure
38 */
39static int hdd_green_ap_check_enable(struct hdd_context *hdd_ctx,
40 bool *enable_green_ap)
41{
42 uint8_t num_sessions, mode;
43 QDF_STATUS status;
44
45 for (mode = 0;
46 mode < QDF_MAX_NO_OF_MODE;
47 mode++) {
48 if (mode == QDF_SAP_MODE || mode == QDF_P2P_GO_MODE)
49 continue;
50
51 status = policy_mgr_mode_specific_num_active_sessions(
Dustin Brown1dbefe62018-09-11 16:32:03 -070052 hdd_ctx->psoc, mode, &num_sessions);
Jeff Johnson8bb61112018-03-31 13:33:54 -070053 hdd_debug("No. of active sessions for mode: %d is %d",
54 mode, num_sessions);
55 if (status != QDF_STATUS_SUCCESS) {
56 hdd_err("Failed to get num sessions for mode: %d",
57 mode);
58 return -EINVAL;
59 } else if (num_sessions) {
60 *enable_green_ap = false;
61 return 0;
62 }
63 }
64 *enable_green_ap = true;
65 return 0;
66}
67
68void hdd_green_ap_add_sta(struct hdd_context *hdd_ctx)
69{
Dustin Brown07901ec2018-09-07 11:02:41 -070070 wlan_green_ap_add_sta(hdd_ctx->pdev);
Jeff Johnson8bb61112018-03-31 13:33:54 -070071}
72
73void hdd_green_ap_del_sta(struct hdd_context *hdd_ctx)
74{
Dustin Brown07901ec2018-09-07 11:02:41 -070075 wlan_green_ap_del_sta(hdd_ctx->pdev);
Jeff Johnson8bb61112018-03-31 13:33:54 -070076}
77
78int hdd_green_ap_enable_egap(struct hdd_context *hdd_ctx)
79{
80 QDF_STATUS status;
81
Dustin Brown07901ec2018-09-07 11:02:41 -070082 status = ucfg_green_ap_enable_egap(hdd_ctx->pdev);
Jeff Johnson8bb61112018-03-31 13:33:54 -070083 if (QDF_IS_STATUS_ERROR(status)) {
84 hdd_debug("enhance green ap is not enabled, status %d",
85 status);
86 return qdf_status_to_os_return(status);
87 }
88
89 return 0;
90}
91
Jeff Johnson8bb61112018-03-31 13:33:54 -070092int hdd_green_ap_start_state_mc(struct hdd_context *hdd_ctx,
93 enum QDF_OPMODE mode, bool is_session_start)
94{
95 struct hdd_config *cfg;
96 bool enable_green_ap = false;
97 uint8_t num_sap_sessions = 0, num_p2p_go_sessions = 0, ret = 0;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053098 QDF_STATUS status;
99 bool bval = false;
gaurank kathpalia4a205fc2018-09-15 00:59:15 +0530100 uint8_t ps_enable;
Jeff Johnson8bb61112018-03-31 13:33:54 -0700101
102 cfg = hdd_ctx->config;
103 if (!cfg) {
104 hdd_err("NULL hdd config");
105 return -EINVAL;
106 }
107
Abhinav Kumarb074f2f2018-09-15 15:32:11 +0530108 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &bval);
109 if (!QDF_IS_STATUS_SUCCESS(status)) {
110 hdd_err("unable to get vht_enable2x2");
111 return -EINVAL;
112 }
113
gaurank kathpalia4a205fc2018-09-15 00:59:15 +0530114 if (!bval) {
115 hdd_debug(" 2x2 not enabled");
116 }
117
118 if (QDF_IS_STATUS_ERROR(ucfg_green_ap_get_ps_config(hdd_ctx->pdev,
119 &ps_enable)))
120 return 0;
121
122 if (!ps_enable) {
123 hdd_debug("Green AP not enabled");
Jeff Johnson8bb61112018-03-31 13:33:54 -0700124 return 0;
125 }
126
Dustin Brown1dbefe62018-09-11 16:32:03 -0700127 policy_mgr_mode_specific_num_active_sessions(hdd_ctx->psoc,
Jeff Johnson8bb61112018-03-31 13:33:54 -0700128 QDF_SAP_MODE,
129 &num_sap_sessions);
Dustin Brown1dbefe62018-09-11 16:32:03 -0700130 policy_mgr_mode_specific_num_active_sessions(hdd_ctx->psoc,
Jeff Johnson8bb61112018-03-31 13:33:54 -0700131 QDF_P2P_GO_MODE,
132 &num_p2p_go_sessions);
133
134 switch (mode) {
135 case QDF_STA_MODE:
136 case QDF_P2P_CLIENT_MODE:
137 case QDF_IBSS_MODE:
138 if (!num_sap_sessions && !num_p2p_go_sessions)
139 return 0;
140
141 if (is_session_start) {
142 hdd_debug("Disabling Green AP");
Dustin Brown07901ec2018-09-07 11:02:41 -0700143 ucfg_green_ap_set_ps_config(hdd_ctx->pdev,
Jeff Johnson8bb61112018-03-31 13:33:54 -0700144 false);
Dustin Brown07901ec2018-09-07 11:02:41 -0700145 wlan_green_ap_stop(hdd_ctx->pdev);
Jeff Johnson8bb61112018-03-31 13:33:54 -0700146 } else {
147 ret = hdd_green_ap_check_enable(hdd_ctx,
148 &enable_green_ap);
149 if (!ret) {
150 if (enable_green_ap) {
151 hdd_debug("Enabling Green AP");
152 ucfg_green_ap_set_ps_config(
Dustin Brown07901ec2018-09-07 11:02:41 -0700153 hdd_ctx->pdev, true);
154 wlan_green_ap_start(hdd_ctx->pdev);
Jeff Johnson8bb61112018-03-31 13:33:54 -0700155 }
156 } else {
157 hdd_err("Failed to check Green AP enable status");
158 }
159 }
160 break;
161 case QDF_SAP_MODE:
162 case QDF_P2P_GO_MODE:
163 if (is_session_start) {
164 ret = hdd_green_ap_check_enable(hdd_ctx,
165 &enable_green_ap);
166 if (!ret) {
167 if (enable_green_ap) {
168 hdd_debug("Enabling Green AP");
169 ucfg_green_ap_set_ps_config(
Dustin Brown07901ec2018-09-07 11:02:41 -0700170 hdd_ctx->pdev, true);
171 wlan_green_ap_start(hdd_ctx->pdev);
Jeff Johnson8bb61112018-03-31 13:33:54 -0700172 }
173 } else {
174 hdd_err("Failed to check Green AP enable status");
175 }
176 } else {
177 if (!num_sap_sessions && !num_p2p_go_sessions) {
178 hdd_debug("Disabling Green AP");
Dustin Brown07901ec2018-09-07 11:02:41 -0700179 ucfg_green_ap_set_ps_config(hdd_ctx->pdev,
Jeff Johnson8bb61112018-03-31 13:33:54 -0700180 false);
Dustin Brown07901ec2018-09-07 11:02:41 -0700181 wlan_green_ap_stop(hdd_ctx->pdev);
Jeff Johnson8bb61112018-03-31 13:33:54 -0700182 }
183 }
184 break;
185 default:
186 break;
187 }
188 return ret;
189}