blob: ec2b2904f24f1f67faf0259d56d1bb3ace0df2c4 [file] [log] [blame]
Subhani Shaik4a7be102016-12-16 16:16:18 +05301/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
Sumit Agre8ded1252022-08-10 14:13:40 +053015
16 * Changes from Qualcomm Innovation Center are provided under the following license:
17
18 * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
19 * SPDX-License-Identifier: BSD-3-Clause-Clear
Subhani Shaik4a7be102016-12-16 16:16:18 +053020 */
21
22#include <errno.h>
23
24#include "common.h"
25#include "roamcommand.h"
Subhani Shaik4a7be102016-12-16 16:16:18 +053026
Veerendranath Jakkamb53f7002021-03-16 16:31:25 +053027#define WLAN_ROAM_MAX_NUM_WHITE_LIST 8
Hu Wange963c592019-02-21 10:22:22 +080028#define WLAN_ROAM_MAX_NUM_BLACK_LIST 16
29
Subhani Shaik4a7be102016-12-16 16:16:18 +053030RoamCommand::RoamCommand(wifi_handle handle, int id, u32 vendor_id, u32 subcmd)
31 : WifiVendorCommand(handle, id, vendor_id, subcmd)
32{
33}
34
35RoamCommand::~RoamCommand()
36{
37}
38
39/* This function implements creation of Vendor command */
Srinivas Dasari30b13c72017-08-08 15:44:23 +053040wifi_error RoamCommand::create() {
41 wifi_error ret = mMsg.create(NL80211_CMD_VENDOR, 0, 0);
42 if (ret != WIFI_SUCCESS)
Subhani Shaik4a7be102016-12-16 16:16:18 +053043 return ret;
Subhani Shaik4a7be102016-12-16 16:16:18 +053044
45 /* Insert the oui in the msg */
46 ret = mMsg.put_u32(NL80211_ATTR_VENDOR_ID, mVendor_id);
Srinivas Dasari30b13c72017-08-08 15:44:23 +053047 if (ret != WIFI_SUCCESS)
48 return ret;
Subhani Shaik4a7be102016-12-16 16:16:18 +053049 /* Insert the subcmd in the msg */
50 ret = mMsg.put_u32(NL80211_ATTR_VENDOR_SUBCMD, mSubcmd);
Srinivas Dasari30b13c72017-08-08 15:44:23 +053051 if (ret != WIFI_SUCCESS)
52 return ret;
Subhani Shaik4a7be102016-12-16 16:16:18 +053053
54 ALOGV("%s: mVendor_id = %d, Subcmd = %d.",
55 __FUNCTION__, mVendor_id, mSubcmd);
Subhani Shaik4a7be102016-12-16 16:16:18 +053056 return ret;
57}
58
Srinivas Dasari30b13c72017-08-08 15:44:23 +053059wifi_error RoamCommand::requestResponse()
Subhani Shaik4a7be102016-12-16 16:16:18 +053060{
61 return WifiCommand::requestResponse(mMsg);
62}
63
64wifi_error wifi_set_bssid_blacklist(wifi_request_id id,
65 wifi_interface_handle iface,
66 wifi_bssid_params params)
67{
Srinivas Dasari30b13c72017-08-08 15:44:23 +053068 wifi_error ret;
69 int i;
Subhani Shaik4a7be102016-12-16 16:16:18 +053070 RoamCommand *roamCommand;
71 struct nlattr *nlData, *nlBssids;
72 interface_info *ifaceInfo = getIfaceInfo(iface);
73 wifi_handle wifiHandle = getWifiHandle(iface);
74 hal_info *info = getHalInfo(wifiHandle);
75
Hu Wange963c592019-02-21 10:22:22 +080076 if (!(info->supported_feature_set & WIFI_FEATURE_CONTROL_ROAMING)) {
77 ALOGE("%s: Roaming is not supported by driver",
Subhani Shaik4a7be102016-12-16 16:16:18 +053078 __FUNCTION__);
79 return WIFI_ERROR_NOT_SUPPORTED;
80 }
81
82 for (i = 0; i < params.num_bssid; i++) {
Hu Wang30864af2022-11-18 18:29:48 +080083 ALOGV("BSSID: %d : " MACSTR, i, MAC2STR(params.bssids[i]));
Subhani Shaik4a7be102016-12-16 16:16:18 +053084 }
85
86 roamCommand =
87 new RoamCommand(wifiHandle,
88 id,
89 OUI_QCA,
90 QCA_NL80211_VENDOR_SUBCMD_ROAM);
91 if (roamCommand == NULL) {
92 ALOGE("%s: Error roamCommand NULL", __FUNCTION__);
93 return WIFI_ERROR_UNKNOWN;
94 }
95
96 /* Create the NL message. */
97 ret = roamCommand->create();
Srinivas Dasari30b13c72017-08-08 15:44:23 +053098 if (ret != WIFI_SUCCESS)
Subhani Shaik4a7be102016-12-16 16:16:18 +053099 goto cleanup;
100
101 /* Set the interface Id of the message. */
102 ret = roamCommand->set_iface_id(ifaceInfo->name);
Srinivas Dasari30b13c72017-08-08 15:44:23 +0530103 if (ret != WIFI_SUCCESS)
Subhani Shaik4a7be102016-12-16 16:16:18 +0530104 goto cleanup;
105
106 /* Add the vendor specific attributes for the NL command. */
107 nlData = roamCommand->attr_start(NL80211_ATTR_VENDOR_DATA);
Sumit Agre8ded1252022-08-10 14:13:40 +0530108 if (!nlData){
109 ret = WIFI_ERROR_UNKNOWN;
Subhani Shaik4a7be102016-12-16 16:16:18 +0530110 goto cleanup;
Sumit Agre8ded1252022-08-10 14:13:40 +0530111 }
Subhani Shaik4a7be102016-12-16 16:16:18 +0530112
Srinivas Dasari30b13c72017-08-08 15:44:23 +0530113 ret = roamCommand->put_u32(QCA_WLAN_VENDOR_ATTR_ROAMING_SUBCMD,
Vamsi Krishnab8b5cf92020-02-04 10:44:02 +0530114 QCA_WLAN_VENDOR_ROAMING_SUBCMD_SET_BLACKLIST_BSSID);
Srinivas Dasari30b13c72017-08-08 15:44:23 +0530115 if (ret != WIFI_SUCCESS)
Subhani Shaik4a7be102016-12-16 16:16:18 +0530116 goto cleanup;
Srinivas Dasari30b13c72017-08-08 15:44:23 +0530117
118 ret = roamCommand->put_u32( QCA_WLAN_VENDOR_ATTR_ROAMING_REQ_ID, id);
119 if (ret != WIFI_SUCCESS)
120 goto cleanup;
121
122 ret = roamCommand->put_u32(
123 QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_NUM_BSSID,
124 params.num_bssid);
125 if (ret != WIFI_SUCCESS)
126 goto cleanup;
Subhani Shaik4a7be102016-12-16 16:16:18 +0530127
128 nlBssids = roamCommand->attr_start(
129 QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS);
130 for (i = 0; i < params.num_bssid; i++) {
131 struct nlattr *nl_ssid = roamCommand->attr_start(i);
132
Srinivas Dasari30b13c72017-08-08 15:44:23 +0530133 ret = roamCommand->put_addr(
134 QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_BSSID,
135 (u8 *)params.bssids[i]);
136 if (ret != WIFI_SUCCESS)
Subhani Shaik4a7be102016-12-16 16:16:18 +0530137 goto cleanup;
Subhani Shaik4a7be102016-12-16 16:16:18 +0530138
139 roamCommand->attr_end(nl_ssid);
140 }
141 roamCommand->attr_end(nlBssids);
142
143 roamCommand->attr_end(nlData);
144
145 ret = roamCommand->requestResponse();
Srinivas Dasari30b13c72017-08-08 15:44:23 +0530146 if (ret != WIFI_SUCCESS)
Subhani Shaik4a7be102016-12-16 16:16:18 +0530147 ALOGE("wifi_set_bssid_blacklist(): requestResponse Error:%d", ret);
Subhani Shaik4a7be102016-12-16 16:16:18 +0530148
149cleanup:
150 delete roamCommand;
Srinivas Dasari30b13c72017-08-08 15:44:23 +0530151 return ret;
Subhani Shaik4a7be102016-12-16 16:16:18 +0530152
153}
154
155wifi_error wifi_set_ssid_white_list(wifi_request_id id, wifi_interface_handle iface,
156 int num_networks, ssid_t *ssid_list)
157{
Srinivas Dasari30b13c72017-08-08 15:44:23 +0530158 wifi_error ret;
159 int i;
Subhani Shaik4a7be102016-12-16 16:16:18 +0530160 RoamCommand *roamCommand;
161 struct nlattr *nlData, *nlSsids;
162 interface_info *ifaceInfo = getIfaceInfo(iface);
163 wifi_handle wifiHandle = getWifiHandle(iface);
164 char ssid[MAX_SSID_LENGTH + 1];
165
166 ALOGV("%s: Number of SSIDs : %d", __FUNCTION__, num_networks);
167
168 roamCommand = new RoamCommand(
169 wifiHandle,
170 id,
171 OUI_QCA,
172 QCA_NL80211_VENDOR_SUBCMD_ROAM);
173 if (roamCommand == NULL) {
174 ALOGE("%s: Failed to create object of RoamCommand class", __FUNCTION__);
175 return WIFI_ERROR_UNKNOWN;
176 }
177
178 /* Create the NL message. */
179 ret = roamCommand->create();
Srinivas Dasari30b13c72017-08-08 15:44:23 +0530180 if (ret != WIFI_SUCCESS) {
Subhani Shaik4a7be102016-12-16 16:16:18 +0530181 ALOGE("%s: Failed to create NL message, Error: %d", __FUNCTION__, ret);
Subhani Shaik4a7be102016-12-16 16:16:18 +0530182 goto cleanup;
183 }
184
185 /* Set the interface Id of the message. */
186 ret = roamCommand->set_iface_id(ifaceInfo->name);
Srinivas Dasari30b13c72017-08-08 15:44:23 +0530187 if (ret != WIFI_SUCCESS) {
Subhani Shaik4a7be102016-12-16 16:16:18 +0530188 ALOGE("%s: Failed to set interface Id of message, Error: %d", __FUNCTION__, ret);
Subhani Shaik4a7be102016-12-16 16:16:18 +0530189 goto cleanup;
190 }
191
192 /* Add the vendor specific attributes for the NL command. */
193 nlData = roamCommand->attr_start(NL80211_ATTR_VENDOR_DATA);
194 if (!nlData) {
Sumit Agre8ded1252022-08-10 14:13:40 +0530195 ret = WIFI_ERROR_UNKNOWN;
Subhani Shaik4a7be102016-12-16 16:16:18 +0530196 goto cleanup;
197 }
198
Srinivas Dasari30b13c72017-08-08 15:44:23 +0530199 ret = roamCommand->put_u32(QCA_WLAN_VENDOR_ATTR_ROAMING_SUBCMD,
Vamsi Krishnab8b5cf92020-02-04 10:44:02 +0530200 QCA_WLAN_VENDOR_ROAMING_SUBCMD_SSID_WHITE_LIST);
Srinivas Dasari30b13c72017-08-08 15:44:23 +0530201 if (ret != WIFI_SUCCESS)
Subhani Shaik4a7be102016-12-16 16:16:18 +0530202 goto cleanup;
Srinivas Dasari30b13c72017-08-08 15:44:23 +0530203 ret = roamCommand->put_u32(QCA_WLAN_VENDOR_ATTR_ROAMING_REQ_ID, id);
204 if (ret != WIFI_SUCCESS)
205 goto cleanup;
206 ret = roamCommand->put_u32(QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_WHITE_LIST_SSID_NUM_NETWORKS,
207 num_networks);
208 if (ret != WIFI_SUCCESS)
209 goto cleanup;
Subhani Shaik4a7be102016-12-16 16:16:18 +0530210
211 nlSsids = roamCommand->attr_start(QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_WHITE_LIST_SSID_LIST);
212 for (i = 0; i < num_networks; i++) {
213 struct nlattr *nl_ssid = roamCommand->attr_start(i);
214
215 memcpy(ssid, ssid_list[i].ssid_str, ssid_list[i].length);
216 ssid[ssid_list[i].length] = '\0';
217 ALOGV("ssid[%d] : %s", i, ssid);
218
Srinivas Dasari30b13c72017-08-08 15:44:23 +0530219 ret = roamCommand->put_bytes(QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_WHITE_LIST_SSID,
220 ssid, (ssid_list[i].length + 1));
221 if (ret != WIFI_SUCCESS) {
Subhani Shaik4a7be102016-12-16 16:16:18 +0530222 ALOGE("%s: Failed to add ssid atribute, Error: %d", __FUNCTION__, ret);
Subhani Shaik4a7be102016-12-16 16:16:18 +0530223 goto cleanup;
224 }
225
226 roamCommand->attr_end(nl_ssid);
227 }
228 roamCommand->attr_end(nlSsids);
229
230 roamCommand->attr_end(nlData);
231
232 ret = roamCommand->requestResponse();
Srinivas Dasari30b13c72017-08-08 15:44:23 +0530233 if (ret != WIFI_SUCCESS)
Subhani Shaik4a7be102016-12-16 16:16:18 +0530234 ALOGE("%s: Failed to send request, Error:%d", __FUNCTION__, ret);
Subhani Shaik4a7be102016-12-16 16:16:18 +0530235
236cleanup:
237 delete roamCommand;
Srinivas Dasari30b13c72017-08-08 15:44:23 +0530238 return ret;
Subhani Shaik4a7be102016-12-16 16:16:18 +0530239}
240
241wifi_error wifi_get_roaming_capabilities(wifi_interface_handle iface,
242 wifi_roaming_capabilities *caps)
243{
244 wifi_handle wifiHandle = getWifiHandle(iface);
245 hal_info *info = getHalInfo(wifiHandle);
246
247 if (!caps) {
248 ALOGE("%s: Invalid Buffer provided. Exit", __FUNCTION__);
249 return WIFI_ERROR_INVALID_ARGS;
250 }
251
252 if (!info) {
253 ALOGE("%s: hal_info is NULL", __FUNCTION__);
254 return WIFI_ERROR_INVALID_ARGS;
255 }
256
Hu Wange963c592019-02-21 10:22:22 +0800257 // Per WiFi HAL design, roaming feature should have nothing to do with Gscan
258 // But for current driver impl, roaming_capa is provided as part of
259 // GSCAN_GET_CAPABILITY query, so if Gscan is not supported, roaming_capa
260 // is not set (uses initial value 0).
261 // To de-couple roaming with Gscan, set default values for roaming_capa
262 // if Gscan is not supported.
263 // TODO: removes below if driver has new API to get roaming_capa.
264 if (!(info->supported_feature_set & WIFI_FEATURE_GSCAN)) {
265 info->capa.roaming_capa.max_whitelist_size = WLAN_ROAM_MAX_NUM_WHITE_LIST;
266 info->capa.roaming_capa.max_blacklist_size = WLAN_ROAM_MAX_NUM_BLACK_LIST;
267 }
Subhani Shaik4a7be102016-12-16 16:16:18 +0530268 memcpy(caps, &info->capa.roaming_capa, sizeof(wifi_roaming_capabilities));
269
270 return WIFI_SUCCESS;
271}
272
273wifi_error wifi_configure_roaming(wifi_interface_handle iface, wifi_roaming_config *roaming_config)
274{
275 wifi_error ret;
276 int requestId;
277 wifi_bssid_params bssid_params;
278 wifi_handle wifiHandle = getWifiHandle(iface);
279 hal_info *info = getHalInfo(wifiHandle);
280
281 if (!roaming_config) {
282 ALOGE("%s: Invalid Buffer provided. Exit", __FUNCTION__);
283 return WIFI_ERROR_INVALID_ARGS;
284 }
285
286 /* No request id from caller, so generate one and pass it on to the driver.
287 * Generate it randomly.
288 */
289 requestId = get_requestid();
290
291 /* Set bssid blacklist */
292 if (roaming_config->num_blacklist_bssid > info->capa.roaming_capa.max_blacklist_size) {
293 ALOGE("%s: Number of blacklist bssids(%d) provided is more than maximum blacklist bssids(%d)"
294 " supported", __FUNCTION__, roaming_config->num_blacklist_bssid,
295 info->capa.roaming_capa.max_blacklist_size);
296 return WIFI_ERROR_NOT_SUPPORTED;
297 }
298 bssid_params.num_bssid = roaming_config->num_blacklist_bssid;
299
300 memcpy(bssid_params.bssids, roaming_config->blacklist_bssid,
301 (bssid_params.num_bssid * sizeof(mac_addr)));
302
303 ret = wifi_set_bssid_blacklist(requestId, iface, bssid_params);
304 if (ret != WIFI_SUCCESS) {
305 ALOGE("%s: Failed to configure blacklist bssids", __FUNCTION__);
306 return WIFI_ERROR_UNKNOWN;
307 }
308
309 /* Set ssid whitelist */
310 if (roaming_config->num_whitelist_ssid > info->capa.roaming_capa.max_whitelist_size) {
311 ALOGE("%s: Number of whitelist ssid(%d) provided is more than maximum whitelist ssids(%d) "
312 "supported", __FUNCTION__, roaming_config->num_whitelist_ssid,
313 info->capa.roaming_capa.max_whitelist_size);
314 return WIFI_ERROR_NOT_SUPPORTED;
315 }
Veerendranath Jakkam945c1542019-12-05 22:43:17 +0530316
317 // Framework is always sending SSID length as 32 though null terminated lengths
318 // are lesser. Thus update correct lengths before sending to driver.
319 for (int i = 0; i < roaming_config->num_whitelist_ssid; i++) {
320 int j;
321
322 for (j = 0; j < roaming_config->whitelist_ssid[i].length; j++) {
323 if (roaming_config->whitelist_ssid[i].ssid_str[j] == '\0')
324 break;
325 }
326
327 if (roaming_config->whitelist_ssid[i].length == j)
328 continue;
329
330 ALOGI("%s: ssid_str %s reported length = %d , null terminated length = %d", __FUNCTION__,
331 roaming_config->whitelist_ssid[i].ssid_str,
332 roaming_config->whitelist_ssid[i].length, j);
333 roaming_config->whitelist_ssid[i].length = j;
334 }
335
Subhani Shaik4a7be102016-12-16 16:16:18 +0530336 ret = wifi_set_ssid_white_list(requestId, iface, roaming_config->num_whitelist_ssid,
337 roaming_config->whitelist_ssid);
338 if (ret != WIFI_SUCCESS)
339 ALOGE("%s: Failed to configure whitelist ssids", __FUNCTION__);
340
341 return ret;
342}
343
344/* Enable/disable firmware roaming */
345wifi_error wifi_enable_firmware_roaming(wifi_interface_handle iface, fw_roaming_state_t state)
346{
Srinivas Dasari30b13c72017-08-08 15:44:23 +0530347 int requestId;
348 wifi_error ret;
Subhani Shaik4a7be102016-12-16 16:16:18 +0530349 RoamCommand *roamCommand;
350 struct nlattr *nlData;
351 interface_info *ifaceInfo = getIfaceInfo(iface);
352 wifi_handle wifiHandle = getWifiHandle(iface);
353 qca_roaming_policy policy;
354
355 ALOGV("%s: set firmware roam state : %d", __FUNCTION__, state);
356
357 if (state == ROAMING_ENABLE) {
358 policy = QCA_ROAMING_ALLOWED_WITHIN_ESS;
359 } else if(state == ROAMING_DISABLE) {
360 policy = QCA_ROAMING_NOT_ALLOWED;
361 } else {
362 ALOGE("%s: Invalid state provided: %d. Exit \n", __FUNCTION__, state);
363 return WIFI_ERROR_INVALID_ARGS;
364 }
365
366 /* No request id from caller, so generate one and pass it on to the driver.
367 * Generate it randomly.
368 */
369 requestId = get_requestid();
370
371 roamCommand =
372 new RoamCommand(wifiHandle,
373 requestId,
374 OUI_QCA,
375 QCA_NL80211_VENDOR_SUBCMD_ROAMING);
376 if (roamCommand == NULL) {
377 ALOGE("%s: Failed to create object of RoamCommand class", __FUNCTION__);
378 return WIFI_ERROR_UNKNOWN;
379 }
380
381 /* Create the NL message. */
382 ret = roamCommand->create();
Srinivas Dasari30b13c72017-08-08 15:44:23 +0530383 if (ret != WIFI_SUCCESS) {
Subhani Shaik4a7be102016-12-16 16:16:18 +0530384 ALOGE("%s: Failed to create NL message, Error: %d", __FUNCTION__, ret);
Subhani Shaik4a7be102016-12-16 16:16:18 +0530385 goto cleanup;
386 }
387
388 /* Set the interface Id of the message. */
389 ret = roamCommand->set_iface_id(ifaceInfo->name);
Srinivas Dasari30b13c72017-08-08 15:44:23 +0530390 if (ret != WIFI_SUCCESS) {
Subhani Shaik4a7be102016-12-16 16:16:18 +0530391 ALOGE("%s: Failed to set interface Id of message, Error: %d", __FUNCTION__, ret);
Subhani Shaik4a7be102016-12-16 16:16:18 +0530392 goto cleanup;
393 }
394
395 /* Add the vendor specific attributes for the NL command. */
396 nlData = roamCommand->attr_start(NL80211_ATTR_VENDOR_DATA);
397 if (!nlData) {
Srinivas Dasari30b13c72017-08-08 15:44:23 +0530398 ret = WIFI_ERROR_UNKNOWN;
Subhani Shaik4a7be102016-12-16 16:16:18 +0530399 goto cleanup;
400 }
401
Srinivas Dasari30b13c72017-08-08 15:44:23 +0530402 ret = roamCommand->put_u32(QCA_WLAN_VENDOR_ATTR_ROAMING_POLICY, policy);
403 if (ret != WIFI_SUCCESS) {
Subhani Shaik4a7be102016-12-16 16:16:18 +0530404 ALOGE("%s: Failed to add roaming policy atribute, Error: %d", __FUNCTION__, ret);
Subhani Shaik4a7be102016-12-16 16:16:18 +0530405 goto cleanup;
406 }
407
408 roamCommand->attr_end(nlData);
409
410 ret = roamCommand->requestResponse();
Srinivas Dasari30b13c72017-08-08 15:44:23 +0530411 if (ret != WIFI_SUCCESS)
Subhani Shaik4a7be102016-12-16 16:16:18 +0530412 ALOGE("%s: Failed to send request, Error:%d", __FUNCTION__, ret);
Subhani Shaik4a7be102016-12-16 16:16:18 +0530413
414cleanup:
415 delete roamCommand;
Srinivas Dasari30b13c72017-08-08 15:44:23 +0530416 return ret;
Subhani Shaik4a7be102016-12-16 16:16:18 +0530417}