Srinivas Dasari | dc48894 | 2018-01-24 19:35:19 +0530 | [diff] [blame] | 1 | /* Copyright (c) 2015, 2018 The Linux Foundation. All rights reserved. |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 2 | * |
| 3 | * Redistribution and use in source and binary forms, with or without |
| 4 | * modification, are permitted provided that the following conditions |
| 5 | * are met: |
| 6 | * * Redistributions of source code must retain the above copyright |
| 7 | * notice, this list of conditions and the following disclaimer. |
| 8 | * * Redistributions in binary form must reproduce the above |
| 9 | * copyright notice, this list of conditions and the following |
| 10 | * disclaimer in the documentation and/or other materials provided |
| 11 | * with the distribution. |
| 12 | * * Neither the name of The Linux Foundation nor the names of its |
| 13 | * contributors may be used to endorse or promote products derived |
| 14 | * from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 23 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 24 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 25 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 26 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | #include "sync.h" |
| 30 | #define LOG_TAG "WifiHAL" |
| 31 | #include <utils/Log.h> |
| 32 | #include <time.h> |
Ajay Dudani | 65b8c55 | 2015-04-11 22:52:06 -0700 | [diff] [blame] | 33 | #include <errno.h> |
Amarnath Hullur Subramanyam | b131c77 | 2015-08-06 14:22:50 -0700 | [diff] [blame] | 34 | #include <stdlib.h> |
Srinivas Girigowda | 2bba36f | 2018-01-29 15:43:59 -0800 | [diff] [blame] | 35 | #include <unistd.h> |
Khanjan Desai | 80f7849 | 2020-03-03 00:04:51 +0530 | [diff] [blame] | 36 | #include <string> |
| 37 | #include <net/if.h> |
| 38 | #include <vector> |
Khanjan Desai | 3dfdeb3 | 2021-10-13 15:03:09 +0530 | [diff] [blame] | 39 | #include <sys/ioctl.h> |
| 40 | #include <net/if.h> |
| 41 | #include <net/if_arp.h> |
| 42 | #include <sys/socket.h> |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 43 | #include "wificonfigcommand.h" |
| 44 | |
| 45 | /* Implementation of the API functions exposed in wifi_config.h */ |
| 46 | wifi_error wifi_extended_dtim_config_set(wifi_request_id id, |
| 47 | wifi_interface_handle iface, |
| 48 | int extended_dtim) |
| 49 | { |
Srinivas Dasari | 30b13c7 | 2017-08-08 15:44:23 +0530 | [diff] [blame] | 50 | wifi_error ret; |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 51 | WiFiConfigCommand *wifiConfigCommand; |
| 52 | struct nlattr *nlData; |
| 53 | interface_info *ifaceInfo = getIfaceInfo(iface); |
| 54 | wifi_handle wifiHandle = getWifiHandle(iface); |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 55 | |
Subhani Shaik | eb97b6e | 2016-03-29 11:33:25 +0530 | [diff] [blame] | 56 | ALOGV("%s: extended_dtim:%d", __FUNCTION__, extended_dtim); |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 57 | |
| 58 | wifiConfigCommand = new WiFiConfigCommand( |
| 59 | wifiHandle, |
| 60 | id, |
| 61 | OUI_QCA, |
| 62 | QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION); |
| 63 | |
| 64 | if (wifiConfigCommand == NULL) { |
Dasari Srinivas | 9b3d8d4 | 2015-09-10 11:16:45 +0530 | [diff] [blame] | 65 | ALOGE("%s: Error wifiConfigCommand NULL", __FUNCTION__); |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 66 | return WIFI_ERROR_UNKNOWN; |
| 67 | } |
| 68 | |
| 69 | /* Create the NL message. */ |
| 70 | ret = wifiConfigCommand->create(); |
Srinivas Dasari | 30b13c7 | 2017-08-08 15:44:23 +0530 | [diff] [blame] | 71 | if (ret != WIFI_SUCCESS) { |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 72 | ALOGE("wifi_extended_dtim_config_set: failed to create NL msg. " |
| 73 | "Error:%d", ret); |
| 74 | goto cleanup; |
| 75 | } |
| 76 | |
| 77 | /* Set the interface Id of the message. */ |
| 78 | ret = wifiConfigCommand->set_iface_id(ifaceInfo->name); |
Srinivas Dasari | 30b13c7 | 2017-08-08 15:44:23 +0530 | [diff] [blame] | 79 | if (ret != WIFI_SUCCESS) { |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 80 | ALOGE("wifi_extended_dtim_config_set: failed to set iface id. " |
| 81 | "Error:%d", ret); |
| 82 | goto cleanup; |
| 83 | } |
| 84 | |
| 85 | /* Add the vendor specific attributes for the NL command. */ |
| 86 | nlData = wifiConfigCommand->attr_start(NL80211_ATTR_VENDOR_DATA); |
| 87 | if (!nlData) { |
| 88 | ALOGE("wifi_extended_dtim_config_set: failed attr_start for " |
| 89 | "VENDOR_DATA. Error:%d", ret); |
| 90 | goto cleanup; |
| 91 | } |
| 92 | |
Srinivas Dasari | 30b13c7 | 2017-08-08 15:44:23 +0530 | [diff] [blame] | 93 | ret = wifiConfigCommand->put_u32( |
Srinivas Dasari | c0854c7 | 2018-06-14 16:55:55 +0530 | [diff] [blame] | 94 | QCA_WLAN_VENDOR_ATTR_CONFIG_DYNAMIC_DTIM, extended_dtim); |
Srinivas Dasari | 30b13c7 | 2017-08-08 15:44:23 +0530 | [diff] [blame] | 95 | if (ret != WIFI_SUCCESS) { |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 96 | ALOGE("wifi_extended_dtim_config_set(): failed to put vendor data. " |
| 97 | "Error:%d", ret); |
| 98 | goto cleanup; |
| 99 | } |
| 100 | wifiConfigCommand->attr_end(nlData); |
| 101 | |
| 102 | /* Send the NL msg. */ |
| 103 | wifiConfigCommand->waitForRsp(false); |
| 104 | ret = wifiConfigCommand->requestEvent(); |
Srinivas Dasari | 30b13c7 | 2017-08-08 15:44:23 +0530 | [diff] [blame] | 105 | if (ret != WIFI_SUCCESS) { |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 106 | ALOGE("wifi_extended_dtim_config_set(): requestEvent Error:%d", ret); |
| 107 | goto cleanup; |
| 108 | } |
| 109 | |
| 110 | cleanup: |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 111 | delete wifiConfigCommand; |
Srinivas Dasari | dc48894 | 2018-01-24 19:35:19 +0530 | [diff] [blame] | 112 | return ret; |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Peng Xu | 2eef57d | 2018-03-14 14:11:37 -0700 | [diff] [blame] | 115 | int check_feature(enum qca_wlan_vendor_features feature, features_info *info) |
| 116 | { |
| 117 | size_t idx = feature / 8; |
| 118 | |
| 119 | return (idx < info->flags_len) && |
| 120 | (info->flags[idx] & BIT(feature % 8)); |
| 121 | } |
| 122 | |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 123 | /* Set the country code to driver. */ |
| 124 | wifi_error wifi_set_country_code(wifi_interface_handle iface, |
| 125 | const char* country_code) |
| 126 | { |
Srinivas Dasari | 30b13c7 | 2017-08-08 15:44:23 +0530 | [diff] [blame] | 127 | int requestId; |
| 128 | wifi_error ret; |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 129 | WiFiConfigCommand *wifiConfigCommand; |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 130 | wifi_handle wifiHandle = getWifiHandle(iface); |
Peng Xu | 2eef57d | 2018-03-14 14:11:37 -0700 | [diff] [blame] | 131 | hal_info *info = getHalInfo(wifiHandle); |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 132 | |
Subhani Shaik | eb97b6e | 2016-03-29 11:33:25 +0530 | [diff] [blame] | 133 | ALOGV("%s: %s", __FUNCTION__, country_code); |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 134 | |
| 135 | /* No request id from caller, so generate one and pass it on to the driver. |
| 136 | * Generate it randomly. |
| 137 | */ |
Amarnath Hullur Subramanyam | b131c77 | 2015-08-06 14:22:50 -0700 | [diff] [blame] | 138 | requestId = get_requestid(); |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 139 | |
| 140 | wifiConfigCommand = new WiFiConfigCommand( |
| 141 | wifiHandle, |
| 142 | requestId, |
| 143 | OUI_QCA, |
| 144 | QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION); |
| 145 | if (wifiConfigCommand == NULL) { |
Dasari Srinivas | 9b3d8d4 | 2015-09-10 11:16:45 +0530 | [diff] [blame] | 146 | ALOGE("%s: Error wifiConfigCommand NULL", __FUNCTION__); |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 147 | return WIFI_ERROR_UNKNOWN; |
| 148 | } |
| 149 | |
| 150 | /* Create the NL message with NL80211_CMD_REQ_SET_REG NL cmd. */ |
| 151 | ret = wifiConfigCommand->create_generic(NL80211_CMD_REQ_SET_REG); |
Srinivas Dasari | 30b13c7 | 2017-08-08 15:44:23 +0530 | [diff] [blame] | 152 | if (ret != WIFI_SUCCESS) { |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 153 | ALOGE("wifi_set_country_code: failed to create NL msg. Error:%d", ret); |
| 154 | goto cleanup; |
| 155 | } |
| 156 | |
Srinivas Dasari | 30b13c7 | 2017-08-08 15:44:23 +0530 | [diff] [blame] | 157 | ret = wifiConfigCommand->put_string(NL80211_ATTR_REG_ALPHA2, country_code); |
| 158 | if (ret != WIFI_SUCCESS) { |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 159 | ALOGE("wifi_set_country_code: put country code failed. Error:%d", ret); |
| 160 | goto cleanup; |
| 161 | } |
| 162 | |
Peng Xu | 2eef57d | 2018-03-14 14:11:37 -0700 | [diff] [blame] | 163 | if (check_feature(QCA_WLAN_VENDOR_FEATURE_SELF_MANAGED_REGULATORY, |
| 164 | &info->driver_supported_features)) { |
| 165 | ret = wifiConfigCommand->put_u32(NL80211_ATTR_USER_REG_HINT_TYPE, |
| 166 | NL80211_USER_REG_HINT_CELL_BASE); |
| 167 | if (ret != WIFI_SUCCESS) { |
| 168 | ALOGE("wifi_set_country_code: put reg hint type failed. Error:%d", |
| 169 | ret); |
| 170 | goto cleanup; |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 175 | /* Send the NL msg. */ |
| 176 | wifiConfigCommand->waitForRsp(false); |
| 177 | ret = wifiConfigCommand->requestEvent(); |
Srinivas Dasari | 30b13c7 | 2017-08-08 15:44:23 +0530 | [diff] [blame] | 178 | if (ret != WIFI_SUCCESS) { |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 179 | ALOGE("wifi_set_country_code(): requestEvent Error:%d", ret); |
| 180 | goto cleanup; |
| 181 | } |
Srinivas Dasari | 02d14ee | 2015-08-19 16:52:08 +0530 | [diff] [blame] | 182 | usleep(WAIT_TIME_FOR_SET_REG_DOMAIN); |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 183 | |
| 184 | cleanup: |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 185 | delete wifiConfigCommand; |
Srinivas Dasari | dc48894 | 2018-01-24 19:35:19 +0530 | [diff] [blame] | 186 | return ret; |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 187 | } |
| 188 | |
Jian Tang | 95979d7 | 2017-11-16 16:52:30 +0800 | [diff] [blame] | 189 | /* |
| 190 | * Set the powersave to driver. |
| 191 | */ |
| 192 | wifi_error wifi_set_qpower(wifi_interface_handle iface, |
| 193 | u8 powersave) |
| 194 | { |
| 195 | int requestId, ret = 0; |
| 196 | WiFiConfigCommand *wifiConfigCommand; |
| 197 | struct nlattr *nlData; |
| 198 | interface_info *ifaceInfo = getIfaceInfo(iface); |
| 199 | wifi_handle wifiHandle = getWifiHandle(iface); |
| 200 | //hal_info *info = getHalInfo(wifiHandle); |
| 201 | |
| 202 | ALOGD("%s: %d", __FUNCTION__, powersave); |
| 203 | |
| 204 | requestId = get_requestid(); |
| 205 | |
| 206 | wifiConfigCommand = new WiFiConfigCommand( |
| 207 | wifiHandle, |
| 208 | requestId, |
| 209 | OUI_QCA, |
| 210 | QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION); |
| 211 | |
| 212 | if (wifiConfigCommand == NULL) { |
| 213 | ALOGE("%s: Error wifiConfigCommand NULL", __FUNCTION__); |
| 214 | return WIFI_ERROR_UNKNOWN; |
| 215 | } |
| 216 | |
| 217 | /* Create the NL message. */ |
| 218 | ret = wifiConfigCommand->create(); |
| 219 | if (ret < 0) { |
| 220 | ALOGE("wifi_set_qpower: failed to create NL msg. " |
| 221 | "Error:%d", ret); |
| 222 | goto cleanup; |
| 223 | } |
| 224 | |
| 225 | /* Set the interface Id of the message. */ |
| 226 | ret = wifiConfigCommand->set_iface_id(ifaceInfo->name); |
| 227 | if (ret < 0) { |
| 228 | ALOGE("wifi_set_qpower: failed to set iface id. " |
| 229 | "Error:%d", ret); |
| 230 | goto cleanup; |
| 231 | } |
| 232 | |
| 233 | /* Add the vendor specific attributes for the NL command. */ |
| 234 | nlData = wifiConfigCommand->attr_start(NL80211_ATTR_VENDOR_DATA); |
| 235 | if (!nlData) { |
| 236 | ALOGE("wifi_set_qpower: failed attr_start for " |
| 237 | "VENDOR_DATA. Error:%d", ret); |
| 238 | goto cleanup; |
| 239 | } |
| 240 | |
| 241 | if (wifiConfigCommand->put_u8( |
Srinivas Dasari | c0854c7 | 2018-06-14 16:55:55 +0530 | [diff] [blame] | 242 | QCA_WLAN_VENDOR_ATTR_CONFIG_QPOWER, powersave)) { |
Jian Tang | 95979d7 | 2017-11-16 16:52:30 +0800 | [diff] [blame] | 243 | ALOGE("wifi_set_qpower(): failed to put vendor data. " |
| 244 | "Error:%d", ret); |
| 245 | goto cleanup; |
| 246 | } |
| 247 | wifiConfigCommand->attr_end(nlData); |
| 248 | |
| 249 | /* Send the NL msg. */ |
| 250 | wifiConfigCommand->waitForRsp(false); |
| 251 | ret = wifiConfigCommand->requestEvent(); |
| 252 | if (ret != 0) { |
| 253 | ALOGE("wifi_set_qpower(): requestEvent Error:%d", ret); |
| 254 | goto cleanup; |
| 255 | } |
| 256 | |
| 257 | cleanup: |
| 258 | delete wifiConfigCommand; |
| 259 | return (wifi_error)ret; |
| 260 | |
| 261 | } |
| 262 | |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 263 | wifi_error wifi_set_beacon_wifi_iface_stats_averaging_factor( |
| 264 | wifi_request_id id, |
| 265 | wifi_interface_handle iface, |
| 266 | u16 factor) |
| 267 | { |
Srinivas Dasari | 30b13c7 | 2017-08-08 15:44:23 +0530 | [diff] [blame] | 268 | wifi_error ret; |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 269 | WiFiConfigCommand *wifiConfigCommand; |
| 270 | struct nlattr *nlData; |
| 271 | interface_info *ifaceInfo = getIfaceInfo(iface); |
| 272 | wifi_handle wifiHandle = getWifiHandle(iface); |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 273 | |
Subhani Shaik | eb97b6e | 2016-03-29 11:33:25 +0530 | [diff] [blame] | 274 | ALOGV("%s factor:%u", __FUNCTION__, factor); |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 275 | wifiConfigCommand = new WiFiConfigCommand( |
| 276 | wifiHandle, |
| 277 | id, |
| 278 | OUI_QCA, |
| 279 | QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION); |
| 280 | if (wifiConfigCommand == NULL) { |
Dasari Srinivas | 9b3d8d4 | 2015-09-10 11:16:45 +0530 | [diff] [blame] | 281 | ALOGE("%s: Error wifiConfigCommand NULL", __FUNCTION__); |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 282 | return WIFI_ERROR_UNKNOWN; |
| 283 | } |
| 284 | |
| 285 | /* Create the NL message. */ |
| 286 | ret = wifiConfigCommand->create(); |
Srinivas Dasari | 30b13c7 | 2017-08-08 15:44:23 +0530 | [diff] [blame] | 287 | if (ret != WIFI_SUCCESS) { |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 288 | ALOGE("wifi_set_beacon_wifi_iface_stats_averaging_factor: failed to " |
| 289 | "create NL msg. Error:%d", ret); |
| 290 | goto cleanup; |
| 291 | } |
| 292 | |
| 293 | /* Set the interface Id of the message. */ |
| 294 | ret = wifiConfigCommand->set_iface_id(ifaceInfo->name); |
Srinivas Dasari | 30b13c7 | 2017-08-08 15:44:23 +0530 | [diff] [blame] | 295 | if (ret != WIFI_SUCCESS) { |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 296 | ALOGE("wifi_set_beacon_wifi_iface_stats_averaging_factor: failed to " |
| 297 | "set iface id. Error:%d", ret); |
| 298 | goto cleanup; |
| 299 | } |
| 300 | |
| 301 | /* Add the vendor specific attributes for the NL command. */ |
| 302 | nlData = wifiConfigCommand->attr_start(NL80211_ATTR_VENDOR_DATA); |
| 303 | if (!nlData) { |
| 304 | ALOGE("wifi_set_beacon_wifi_iface_stats_averaging_factor: failed " |
| 305 | "attr_start for VENDOR_DATA. Error:%d", ret); |
| 306 | goto cleanup; |
| 307 | } |
| 308 | |
| 309 | if (wifiConfigCommand->put_u32( |
Srinivas Dasari | c0854c7 | 2018-06-14 16:55:55 +0530 | [diff] [blame] | 310 | QCA_WLAN_VENDOR_ATTR_CONFIG_STATS_AVG_FACTOR, factor)) { |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 311 | ALOGE("wifi_set_beacon_wifi_iface_stats_averaging_factor(): failed to " |
| 312 | "put vendor data. Error:%d", ret); |
| 313 | goto cleanup; |
| 314 | } |
| 315 | wifiConfigCommand->attr_end(nlData); |
| 316 | |
| 317 | /* Send the NL msg. */ |
| 318 | wifiConfigCommand->waitForRsp(false); |
| 319 | ret = wifiConfigCommand->requestEvent(); |
Srinivas Dasari | 30b13c7 | 2017-08-08 15:44:23 +0530 | [diff] [blame] | 320 | if (ret != WIFI_SUCCESS) { |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 321 | ALOGE("wifi_set_beacon_wifi_iface_stats_averaging_factor(): " |
| 322 | "requestEvent Error:%d", ret); |
| 323 | goto cleanup; |
| 324 | } |
| 325 | |
| 326 | cleanup: |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 327 | delete wifiConfigCommand; |
Srinivas Dasari | dc48894 | 2018-01-24 19:35:19 +0530 | [diff] [blame] | 328 | return ret; |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | wifi_error wifi_set_guard_time(wifi_request_id id, |
| 332 | wifi_interface_handle iface, |
| 333 | u32 guard_time) |
| 334 | { |
Srinivas Dasari | 30b13c7 | 2017-08-08 15:44:23 +0530 | [diff] [blame] | 335 | wifi_error ret; |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 336 | WiFiConfigCommand *wifiConfigCommand; |
| 337 | struct nlattr *nlData; |
| 338 | interface_info *ifaceInfo = getIfaceInfo(iface); |
| 339 | wifi_handle wifiHandle = getWifiHandle(iface); |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 340 | |
Subhani Shaik | eb97b6e | 2016-03-29 11:33:25 +0530 | [diff] [blame] | 341 | ALOGV("%s : guard_time:%u", __FUNCTION__, guard_time); |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 342 | |
| 343 | wifiConfigCommand = new WiFiConfigCommand( |
| 344 | wifiHandle, |
| 345 | id, |
| 346 | OUI_QCA, |
| 347 | QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION); |
| 348 | if (wifiConfigCommand == NULL) { |
Dasari Srinivas | 9b3d8d4 | 2015-09-10 11:16:45 +0530 | [diff] [blame] | 349 | ALOGE("%s: Error wifiConfigCommand NULL", __FUNCTION__); |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 350 | return WIFI_ERROR_UNKNOWN; |
| 351 | } |
| 352 | |
| 353 | /* Create the NL message. */ |
| 354 | ret = wifiConfigCommand->create(); |
Srinivas Dasari | 30b13c7 | 2017-08-08 15:44:23 +0530 | [diff] [blame] | 355 | if (ret != WIFI_SUCCESS) { |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 356 | ALOGE("wifi_set_guard_time: failed to create NL msg. Error:%d", ret); |
| 357 | goto cleanup; |
| 358 | } |
| 359 | |
| 360 | /* Set the interface Id of the message. */ |
| 361 | ret = wifiConfigCommand->set_iface_id(ifaceInfo->name); |
Srinivas Dasari | 30b13c7 | 2017-08-08 15:44:23 +0530 | [diff] [blame] | 362 | if (ret != WIFI_SUCCESS) { |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 363 | ALOGE("wifi_set_guard_time: failed to set iface id. Error:%d", ret); |
| 364 | goto cleanup; |
| 365 | } |
| 366 | |
| 367 | /* Add the vendor specific attributes for the NL command. */ |
| 368 | nlData = wifiConfigCommand->attr_start(NL80211_ATTR_VENDOR_DATA); |
| 369 | if (!nlData) { |
| 370 | ALOGE("wifi_set_guard_time: failed attr_start for VENDOR_DATA. " |
| 371 | "Error:%d", ret); |
| 372 | goto cleanup; |
| 373 | } |
| 374 | |
| 375 | if (wifiConfigCommand->put_u32( |
Srinivas Dasari | c0854c7 | 2018-06-14 16:55:55 +0530 | [diff] [blame] | 376 | QCA_WLAN_VENDOR_ATTR_CONFIG_GUARD_TIME, guard_time)) { |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 377 | ALOGE("wifi_set_guard_time: failed to add vendor data."); |
| 378 | goto cleanup; |
| 379 | } |
| 380 | wifiConfigCommand->attr_end(nlData); |
| 381 | |
| 382 | /* Send the NL msg. */ |
| 383 | wifiConfigCommand->waitForRsp(false); |
| 384 | ret = wifiConfigCommand->requestEvent(); |
Srinivas Dasari | 30b13c7 | 2017-08-08 15:44:23 +0530 | [diff] [blame] | 385 | if (ret != WIFI_SUCCESS) { |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 386 | ALOGE("wifi_set_guard_time(): requestEvent Error:%d", ret); |
| 387 | goto cleanup; |
| 388 | } |
| 389 | |
| 390 | cleanup: |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 391 | delete wifiConfigCommand; |
Srinivas Dasari | dc48894 | 2018-01-24 19:35:19 +0530 | [diff] [blame] | 392 | return ret; |
Srinivas Girigowda | 2bba36f | 2018-01-29 15:43:59 -0800 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | wifi_error wifi_select_tx_power_scenario(wifi_interface_handle handle, |
| 396 | wifi_power_scenario scenario) |
| 397 | { |
| 398 | wifi_error ret; |
| 399 | WiFiConfigCommand *wifiConfigCommand; |
| 400 | struct nlattr *nlData; |
| 401 | interface_info *ifaceInfo = getIfaceInfo(handle); |
| 402 | wifi_handle wifiHandle = getWifiHandle(handle); |
| 403 | u32 bdf_file = 0; |
| 404 | |
zhangjie | 70cdc9c | 2021-06-07 09:52:45 +0800 | [diff] [blame] | 405 | /* The set(0~4) we will read in bdwlan.bin */ |
| 406 | u32 set_sar_number = 1; |
| 407 | u32 chip_mimo_number = 2; |
Srinivas Girigowda | 2bba36f | 2018-01-29 15:43:59 -0800 | [diff] [blame] | 408 | ALOGV("%s : power scenario:%d", __FUNCTION__, scenario); |
| 409 | |
| 410 | wifiConfigCommand = new WiFiConfigCommand( |
| 411 | wifiHandle, |
| 412 | 1, |
| 413 | OUI_QCA, |
| 414 | QCA_NL80211_VENDOR_SUBCMD_SET_SAR_LIMITS); |
| 415 | if (wifiConfigCommand == NULL) { |
| 416 | ALOGE("%s: Error wifiConfigCommand NULL", __FUNCTION__); |
| 417 | return WIFI_ERROR_UNKNOWN; |
| 418 | } |
| 419 | |
| 420 | /* Create the NL message. */ |
| 421 | ret = wifiConfigCommand->create(); |
| 422 | if (ret != WIFI_SUCCESS) { |
| 423 | ALOGE("wifi_select_tx_power_scenario: failed to create NL msg. Error:%d", ret); |
| 424 | goto cleanup; |
| 425 | } |
| 426 | |
| 427 | /* Set the interface Id of the message. */ |
| 428 | ret = wifiConfigCommand->set_iface_id(ifaceInfo->name); |
| 429 | if (ret != WIFI_SUCCESS) { |
| 430 | ALOGE("wifi_select_tx_power_scenario: failed to set iface id. Error:%d", ret); |
| 431 | goto cleanup; |
| 432 | } |
| 433 | |
| 434 | /* Add the vendor specific attributes for the NL command. */ |
| 435 | nlData = wifiConfigCommand->attr_start(NL80211_ATTR_VENDOR_DATA); |
| 436 | if (!nlData) { |
| 437 | ALOGE("wifi_select_tx_power_scenario: failed attr_start for VENDOR_DATA. " |
| 438 | "Error:%d", ret); |
| 439 | goto cleanup; |
| 440 | } |
| 441 | |
Srinivas Girigowda | 8e444fd | 2018-04-12 07:53:40 -0700 | [diff] [blame] | 442 | switch (scenario) { |
| 443 | case WIFI_POWER_SCENARIO_VOICE_CALL: |
| 444 | case WIFI_POWER_SCENARIO_ON_HEAD_CELL_OFF: |
zhangjie | 70cdc9c | 2021-06-07 09:52:45 +0800 | [diff] [blame] | 445 | // bdf_file = QCA_WLAN_VENDOR_ATTR_SAR_LIMITS_SELECT_BDF0; |
| 446 | bdf_file = QCA_WLAN_VENDOR_ATTR_SAR_LIMITS_SELECT_NONE; |
| 447 | set_sar_number = 1; |
Srinivas Girigowda | 8e444fd | 2018-04-12 07:53:40 -0700 | [diff] [blame] | 448 | break; |
| 449 | |
| 450 | case WIFI_POWER_SCENARIO_ON_HEAD_CELL_ON: |
zhangjie | 70cdc9c | 2021-06-07 09:52:45 +0800 | [diff] [blame] | 451 | // bdf_file = QCA_WLAN_VENDOR_ATTR_SAR_LIMITS_SELECT_BDF1; |
| 452 | bdf_file = QCA_WLAN_VENDOR_ATTR_SAR_LIMITS_SELECT_V2_0; |
| 453 | set_sar_number = 0; |
Srinivas Girigowda | 8e444fd | 2018-04-12 07:53:40 -0700 | [diff] [blame] | 454 | break; |
| 455 | |
| 456 | case WIFI_POWER_SCENARIO_ON_BODY_CELL_OFF: |
| 457 | bdf_file = QCA_WLAN_VENDOR_ATTR_SAR_LIMITS_SELECT_BDF2; |
zhangjie | 70cdc9c | 2021-06-07 09:52:45 +0800 | [diff] [blame] | 458 | set_sar_number = 3; |
Srinivas Girigowda | 8e444fd | 2018-04-12 07:53:40 -0700 | [diff] [blame] | 459 | break; |
| 460 | |
| 461 | case WIFI_POWER_SCENARIO_ON_BODY_CELL_ON: |
| 462 | bdf_file = QCA_WLAN_VENDOR_ATTR_SAR_LIMITS_SELECT_BDF3; |
zhangjie | 70cdc9c | 2021-06-07 09:52:45 +0800 | [diff] [blame] | 463 | set_sar_number = 2; |
Srinivas Girigowda | 8e444fd | 2018-04-12 07:53:40 -0700 | [diff] [blame] | 464 | break; |
| 465 | |
| 466 | default: |
| 467 | ALOGE("wifi_select_tx_power_scenario: invalid scenario %d", scenario); |
| 468 | ret = WIFI_ERROR_INVALID_ARGS; |
| 469 | goto cleanup; |
Srinivas Girigowda | 2bba36f | 2018-01-29 15:43:59 -0800 | [diff] [blame] | 470 | } |
Srinivas Girigowda | 8e444fd | 2018-04-12 07:53:40 -0700 | [diff] [blame] | 471 | |
zhangjie | 70cdc9c | 2021-06-07 09:52:45 +0800 | [diff] [blame] | 472 | wifiConfigCommand->put_u32(QCA_WLAN_VENDOR_ATTR_SAR_LIMITS_NUM_SPECS, chip_mimo_number); |
| 473 | struct nlattr *nlData_spec, *nlData_spec_attr; |
| 474 | nlData_spec = wifiConfigCommand->attr_start(QCA_WLAN_VENDOR_ATTR_SAR_LIMITS_SPEC); |
| 475 | for (int i = 0; i < chip_mimo_number; i++) { |
| 476 | nlData_spec_attr = wifiConfigCommand->attr_start(QCA_WLAN_VENDOR_ATTR_SAR_LIMITS_SPEC_POWER_LIMIT_INDEX); |
| 477 | wifiConfigCommand->put_u32(QCA_WLAN_VENDOR_ATTR_SAR_LIMITS_SPEC_POWER_LIMIT_INDEX, set_sar_number); |
| 478 | wifiConfigCommand->put_u32(QCA_WLAN_VENDOR_ATTR_SAR_LIMITS_SPEC_CHAIN, i); |
| 479 | wifiConfigCommand->attr_end(nlData_spec_attr); |
| 480 | } |
| 481 | wifiConfigCommand->attr_end(nlData_spec); |
Srinivas Girigowda | 2bba36f | 2018-01-29 15:43:59 -0800 | [diff] [blame] | 482 | if (wifiConfigCommand->put_u32( |
| 483 | QCA_WLAN_VENDOR_ATTR_SAR_LIMITS_SAR_ENABLE, |
zhangjie | 70cdc9c | 2021-06-07 09:52:45 +0800 | [diff] [blame] | 484 | QCA_WLAN_VENDOR_ATTR_SAR_LIMITS_SELECT_V2_0)) { |
Srinivas Girigowda | 2bba36f | 2018-01-29 15:43:59 -0800 | [diff] [blame] | 485 | ALOGE("failed to put SAR_ENABLE"); |
| 486 | goto cleanup; |
| 487 | } |
| 488 | wifiConfigCommand->attr_end(nlData); |
| 489 | |
| 490 | ret = wifiConfigCommand->requestEvent(); |
| 491 | if (ret != WIFI_SUCCESS) { |
| 492 | ALOGE("wifi_select_tx_power_scenario(): requestEvent Error:%d", ret); |
| 493 | goto cleanup; |
| 494 | } |
| 495 | |
| 496 | cleanup: |
| 497 | delete wifiConfigCommand; |
Srinivas Dasari | dc48894 | 2018-01-24 19:35:19 +0530 | [diff] [blame] | 498 | return ret; |
Srinivas Girigowda | 2bba36f | 2018-01-29 15:43:59 -0800 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | wifi_error wifi_reset_tx_power_scenario(wifi_interface_handle handle) |
| 502 | { |
| 503 | wifi_error ret; |
| 504 | WiFiConfigCommand *wifiConfigCommand; |
| 505 | struct nlattr *nlData; |
| 506 | interface_info *ifaceInfo = getIfaceInfo(handle); |
| 507 | wifi_handle wifiHandle = getWifiHandle(handle); |
| 508 | |
| 509 | wifiConfigCommand = new WiFiConfigCommand( |
| 510 | wifiHandle, |
| 511 | 1, |
| 512 | OUI_QCA, |
| 513 | QCA_NL80211_VENDOR_SUBCMD_SET_SAR_LIMITS); |
| 514 | if (wifiConfigCommand == NULL) { |
| 515 | ALOGE("%s: Error wifiConfigCommand NULL", __FUNCTION__); |
| 516 | return WIFI_ERROR_UNKNOWN; |
| 517 | } |
| 518 | |
| 519 | /* Create the NL message. */ |
| 520 | ret = wifiConfigCommand->create(); |
| 521 | if (ret != WIFI_SUCCESS) { |
| 522 | ALOGE("wifi_reset_tx_power_scenario: failed to create NL msg. Error:%d", ret); |
| 523 | goto cleanup; |
| 524 | } |
| 525 | |
| 526 | /* Set the interface Id of the message. */ |
| 527 | ret = wifiConfigCommand->set_iface_id(ifaceInfo->name); |
| 528 | if (ret != WIFI_SUCCESS) { |
| 529 | ALOGE("wifi_reset_tx_power_scenario: failed to set iface id. Error:%d", ret); |
| 530 | goto cleanup; |
| 531 | } |
| 532 | |
| 533 | /* Add the vendor specific attributes for the NL command. */ |
| 534 | nlData = wifiConfigCommand->attr_start(NL80211_ATTR_VENDOR_DATA); |
| 535 | if (!nlData) { |
| 536 | ALOGE("wifi_reset_tx_power_scenario: failed attr_start for VENDOR_DATA. " |
| 537 | "Error:%d", ret); |
| 538 | goto cleanup; |
| 539 | } |
| 540 | |
| 541 | if (wifiConfigCommand->put_u32(QCA_WLAN_VENDOR_ATTR_SAR_LIMITS_SAR_ENABLE, |
| 542 | QCA_WLAN_VENDOR_ATTR_SAR_LIMITS_SELECT_NONE)) { |
| 543 | ALOGE("failed to put SAR_ENABLE or NUM_SPECS"); |
| 544 | goto cleanup; |
| 545 | } |
| 546 | wifiConfigCommand->attr_end(nlData); |
| 547 | |
| 548 | ret = wifiConfigCommand->requestEvent(); |
| 549 | if (ret != WIFI_SUCCESS) { |
| 550 | ALOGE("wifi_reset_tx_power_scenario(): requestEvent Error:%d", ret); |
| 551 | goto cleanup; |
| 552 | } |
| 553 | |
| 554 | cleanup: |
| 555 | delete wifiConfigCommand; |
Srinivas Dasari | dc48894 | 2018-01-24 19:35:19 +0530 | [diff] [blame] | 556 | return ret; |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 557 | } |
| 558 | |
Vamsi Krishna | 4b90cd5 | 2020-02-03 10:11:34 +0530 | [diff] [blame] | 559 | wifi_error wifi_set_thermal_mitigation_mode(wifi_handle handle, |
| 560 | wifi_thermal_mode mode, |
| 561 | u32 completion_window) |
| 562 | { |
| 563 | wifi_error ret; |
| 564 | WiFiConfigCommand *wifiConfigCommand; |
| 565 | struct nlattr *nlData; |
| 566 | u32 qca_vendor_thermal_level; |
| 567 | hal_info *info = getHalInfo(handle); |
| 568 | |
| 569 | if (!info || info->num_interfaces < 1) { |
| 570 | ALOGE("%s: Error wifi_handle NULL or base wlan interface not present", |
| 571 | __FUNCTION__); |
| 572 | return WIFI_ERROR_UNKNOWN; |
| 573 | } |
| 574 | |
| 575 | wifiConfigCommand = new WiFiConfigCommand( |
| 576 | handle, |
| 577 | 1, |
| 578 | OUI_QCA, |
| 579 | QCA_NL80211_VENDOR_SUBCMD_THERMAL_CMD); |
| 580 | if (wifiConfigCommand == NULL) { |
| 581 | ALOGE("%s: Error, Failed to create wifiConfigCommand", __FUNCTION__); |
| 582 | return WIFI_ERROR_UNKNOWN; |
| 583 | } |
| 584 | |
| 585 | /* Create the NL message. */ |
| 586 | ret = wifiConfigCommand->create(); |
| 587 | if (ret != WIFI_SUCCESS) { |
| 588 | ALOGE("Failed to create thermal vendor command, Error:%d", ret); |
| 589 | goto cleanup; |
| 590 | } |
| 591 | |
| 592 | /* Set the interface Id of the message. */ |
| 593 | if (wifiConfigCommand->put_u32(NL80211_ATTR_IFINDEX, |
| 594 | info->interfaces[0]->id)) { |
| 595 | ALOGE("%s: Failed to put iface id", __FUNCTION__); |
| 596 | goto cleanup; |
| 597 | } |
| 598 | |
| 599 | nlData = wifiConfigCommand->attr_start(NL80211_ATTR_VENDOR_DATA); |
| 600 | if (!nlData) { |
| 601 | ALOGE("%s: Failed in attr_start for VENDOR_DATA, Error:%d", |
| 602 | __FUNCTION__, ret); |
| 603 | goto cleanup; |
| 604 | } |
| 605 | |
| 606 | if (wifiConfigCommand->put_u32(QCA_WLAN_VENDOR_ATTR_THERMAL_CMD_VALUE, |
| 607 | QCA_WLAN_VENDOR_ATTR_THERMAL_CMD_TYPE_SET_LEVEL)) { |
| 608 | ALOGE("Failed to put THERMAL_LEVEL command type"); |
| 609 | goto cleanup; |
| 610 | } |
| 611 | |
| 612 | switch(mode) { |
| 613 | case WIFI_MITIGATION_NONE: |
| 614 | qca_vendor_thermal_level = QCA_WLAN_VENDOR_THERMAL_LEVEL_NONE; |
| 615 | break; |
| 616 | case WIFI_MITIGATION_LIGHT: |
| 617 | qca_vendor_thermal_level = QCA_WLAN_VENDOR_THERMAL_LEVEL_LIGHT; |
| 618 | break; |
| 619 | case WIFI_MITIGATION_MODERATE: |
| 620 | qca_vendor_thermal_level = QCA_WLAN_VENDOR_THERMAL_LEVEL_MODERATE; |
| 621 | break; |
| 622 | case WIFI_MITIGATION_SEVERE: |
| 623 | qca_vendor_thermal_level = QCA_WLAN_VENDOR_THERMAL_LEVEL_SEVERE; |
| 624 | break; |
| 625 | case WIFI_MITIGATION_CRITICAL: |
| 626 | qca_vendor_thermal_level = QCA_WLAN_VENDOR_THERMAL_LEVEL_CRITICAL; |
| 627 | break; |
| 628 | case WIFI_MITIGATION_EMERGENCY: |
| 629 | qca_vendor_thermal_level = QCA_WLAN_VENDOR_THERMAL_LEVEL_EMERGENCY; |
| 630 | break; |
| 631 | default: |
| 632 | ALOGE("Unknown thermal mitigation level %d", mode); |
| 633 | ret = WIFI_ERROR_UNKNOWN; |
| 634 | goto cleanup; |
| 635 | } |
| 636 | |
| 637 | if (wifiConfigCommand->put_u32( |
| 638 | QCA_WLAN_VENDOR_ATTR_THERMAL_LEVEL, |
| 639 | qca_vendor_thermal_level)) { |
| 640 | ALOGE("Failed to put thermal level"); |
| 641 | goto cleanup; |
| 642 | } |
| 643 | |
| 644 | if (wifiConfigCommand->put_u32( |
| 645 | QCA_WLAN_VENDOR_ATTR_THERMAL_COMPLETION_WINDOW, |
| 646 | completion_window)) { |
| 647 | ALOGE("Failed to put thermal completion window"); |
| 648 | goto cleanup; |
| 649 | } |
| 650 | wifiConfigCommand->attr_end(nlData); |
| 651 | |
| 652 | wifiConfigCommand->waitForRsp(false); |
| 653 | ret = wifiConfigCommand->requestEvent(); |
| 654 | if (ret != WIFI_SUCCESS) { |
| 655 | ALOGE("Failed to set thermal level with Error: %d", ret); |
| 656 | goto cleanup; |
| 657 | } |
| 658 | |
| 659 | cleanup: |
| 660 | delete wifiConfigCommand; |
| 661 | return ret; |
| 662 | } |
| 663 | |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 664 | WiFiConfigCommand::WiFiConfigCommand(wifi_handle handle, |
| 665 | int id, u32 vendor_id, |
| 666 | u32 subcmd) |
| 667 | : WifiVendorCommand(handle, id, vendor_id, subcmd) |
| 668 | { |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 669 | /* Initialize the member data variables here */ |
| 670 | mWaitforRsp = false; |
| 671 | mRequestId = id; |
| 672 | } |
| 673 | |
| 674 | WiFiConfigCommand::~WiFiConfigCommand() |
| 675 | { |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 676 | unregisterVendorHandler(mVendor_id, mSubcmd); |
| 677 | } |
| 678 | |
| 679 | /* This function implements creation of Vendor command */ |
Srinivas Dasari | 30b13c7 | 2017-08-08 15:44:23 +0530 | [diff] [blame] | 680 | wifi_error WiFiConfigCommand::create() |
| 681 | { |
| 682 | wifi_error ret = mMsg.create(NL80211_CMD_VENDOR, 0, 0); |
| 683 | if (ret != WIFI_SUCCESS) |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 684 | return ret; |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 685 | |
| 686 | /* Insert the oui in the msg */ |
| 687 | ret = mMsg.put_u32(NL80211_ATTR_VENDOR_ID, mVendor_id); |
Srinivas Dasari | 30b13c7 | 2017-08-08 15:44:23 +0530 | [diff] [blame] | 688 | if (ret != WIFI_SUCCESS) |
| 689 | return ret; |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 690 | /* Insert the subcmd in the msg */ |
| 691 | ret = mMsg.put_u32(NL80211_ATTR_VENDOR_SUBCMD, mSubcmd); |
Srinivas Dasari | 30b13c7 | 2017-08-08 15:44:23 +0530 | [diff] [blame] | 692 | |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 693 | return ret; |
| 694 | } |
| 695 | |
| 696 | /* This function implements creation of generic NL command */ |
Srinivas Dasari | 30b13c7 | 2017-08-08 15:44:23 +0530 | [diff] [blame] | 697 | wifi_error WiFiConfigCommand::create_generic(u8 cmdId) |
| 698 | { |
| 699 | wifi_error ret = mMsg.create(cmdId, 0, 0); |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 700 | return ret; |
| 701 | } |
| 702 | |
| 703 | void WiFiConfigCommand::waitForRsp(bool wait) |
| 704 | { |
| 705 | mWaitforRsp = wait; |
| 706 | } |
| 707 | |
| 708 | /* Callback handlers registered for nl message send */ |
| 709 | static int error_handler_wifi_config(struct sockaddr_nl *nla, |
| 710 | struct nlmsgerr *err, |
| 711 | void *arg) |
| 712 | { |
| 713 | struct sockaddr_nl *tmp; |
| 714 | int *ret = (int *)arg; |
| 715 | tmp = nla; |
| 716 | *ret = err->error; |
Dasari Srinivas | 9b3d8d4 | 2015-09-10 11:16:45 +0530 | [diff] [blame] | 717 | ALOGE("%s: Error code:%d (%s)", __FUNCTION__, *ret, strerror(-(*ret))); |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 718 | return NL_STOP; |
| 719 | } |
| 720 | |
| 721 | /* Callback handlers registered for nl message send */ |
| 722 | static int ack_handler_wifi_config(struct nl_msg *msg, void *arg) |
| 723 | { |
| 724 | int *ret = (int *)arg; |
| 725 | struct nl_msg * a; |
| 726 | |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 727 | a = msg; |
| 728 | *ret = 0; |
| 729 | return NL_STOP; |
| 730 | } |
| 731 | |
| 732 | /* Callback handlers registered for nl message send */ |
| 733 | static int finish_handler_wifi_config(struct nl_msg *msg, void *arg) |
| 734 | { |
| 735 | int *ret = (int *)arg; |
| 736 | struct nl_msg * a; |
| 737 | |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 738 | a = msg; |
| 739 | *ret = 0; |
| 740 | return NL_SKIP; |
| 741 | } |
| 742 | |
| 743 | /* |
| 744 | * Override base class requestEvent and implement little differently here. |
| 745 | * This will send the request message. |
| 746 | * We don't wait for any response back in case of wificonfig, |
| 747 | * thus no wait for condition. |
| 748 | */ |
Srinivas Dasari | 30b13c7 | 2017-08-08 15:44:23 +0530 | [diff] [blame] | 749 | wifi_error WiFiConfigCommand::requestEvent() |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 750 | { |
Srinivas Dasari | 30b13c7 | 2017-08-08 15:44:23 +0530 | [diff] [blame] | 751 | int status; |
| 752 | wifi_error res = WIFI_SUCCESS; |
Hu Wang | c1a1901 | 2019-04-15 15:35:12 +0800 | [diff] [blame] | 753 | struct nl_cb *cb = NULL; |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 754 | |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 755 | cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 756 | if (!cb) { |
Dasari Srinivas | 9b3d8d4 | 2015-09-10 11:16:45 +0530 | [diff] [blame] | 757 | ALOGE("%s: Callback allocation failed",__FUNCTION__); |
Srinivas Dasari | 30b13c7 | 2017-08-08 15:44:23 +0530 | [diff] [blame] | 758 | res = WIFI_ERROR_OUT_OF_MEMORY; |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 759 | goto out; |
| 760 | } |
| 761 | |
Srinivas Dasari | 30b13c7 | 2017-08-08 15:44:23 +0530 | [diff] [blame] | 762 | status = nl_send_auto_complete(mInfo->cmd_sock, mMsg.getMessage()); |
| 763 | if (status < 0) { |
| 764 | res = mapKernelErrortoWifiHalError(status); |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 765 | goto out; |
Srinivas Dasari | 30b13c7 | 2017-08-08 15:44:23 +0530 | [diff] [blame] | 766 | } |
| 767 | status = 1; |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 768 | |
Srinivas Dasari | 30b13c7 | 2017-08-08 15:44:23 +0530 | [diff] [blame] | 769 | nl_cb_err(cb, NL_CB_CUSTOM, error_handler_wifi_config, &status); |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 770 | nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler_wifi_config, |
Srinivas Dasari | 30b13c7 | 2017-08-08 15:44:23 +0530 | [diff] [blame] | 771 | &status); |
| 772 | nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_handler_wifi_config, &status); |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 773 | |
| 774 | /* Err is populated as part of finish_handler. */ |
Srinivas Dasari | 30b13c7 | 2017-08-08 15:44:23 +0530 | [diff] [blame] | 775 | while (status > 0) { |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 776 | nl_recvmsgs(mInfo->cmd_sock, cb); |
| 777 | } |
| 778 | |
Srinivas Dasari | 30b13c7 | 2017-08-08 15:44:23 +0530 | [diff] [blame] | 779 | if (status < 0) { |
| 780 | res = mapKernelErrortoWifiHalError(status); |
| 781 | goto out; |
| 782 | } |
| 783 | |
| 784 | if (mWaitforRsp == true) { |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 785 | struct timespec abstime; |
| 786 | abstime.tv_sec = 4; |
| 787 | abstime.tv_nsec = 0; |
| 788 | res = mCondition.wait(abstime); |
Srinivas Dasari | 30b13c7 | 2017-08-08 15:44:23 +0530 | [diff] [blame] | 789 | if (res == WIFI_ERROR_TIMED_OUT) |
Dasari Srinivas | 9b3d8d4 | 2015-09-10 11:16:45 +0530 | [diff] [blame] | 790 | ALOGE("%s: Time out happened.", __FUNCTION__); |
Srinivas Dasari | 30b13c7 | 2017-08-08 15:44:23 +0530 | [diff] [blame] | 791 | |
Subhani Shaik | eb97b6e | 2016-03-29 11:33:25 +0530 | [diff] [blame] | 792 | ALOGV("%s: Command invoked return value:%d, mWaitForRsp=%d", |
Dasari Srinivas | 9b3d8d4 | 2015-09-10 11:16:45 +0530 | [diff] [blame] | 793 | __FUNCTION__, res, mWaitforRsp); |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 794 | } |
| 795 | out: |
Hu Wang | c1a1901 | 2019-04-15 15:35:12 +0800 | [diff] [blame] | 796 | nl_cb_put(cb); |
Ahmad Kholaif | 159de4f | 2015-03-23 16:02:05 -0700 | [diff] [blame] | 797 | /* Cleanup the mMsg */ |
| 798 | mMsg.destroy(); |
| 799 | return res; |
| 800 | } |
| 801 | |
Khanjan Desai | 80f7849 | 2020-03-03 00:04:51 +0530 | [diff] [blame] | 802 | |
| 803 | |
| 804 | static std::vector<std::string> added_ifaces; |
| 805 | |
| 806 | static bool is_dynamic_interface(const char * ifname) |
| 807 | { |
| 808 | for (const auto& iface : added_ifaces) { |
| 809 | if (iface == std::string(ifname)) |
| 810 | return true; |
| 811 | } |
| 812 | return false; |
| 813 | } |
| 814 | |
| 815 | void wifi_cleanup_dynamic_ifaces(wifi_handle handle) |
| 816 | { |
| 817 | int len = added_ifaces.size(); |
| 818 | while (len--) { |
| 819 | wifi_virtual_interface_delete(handle, added_ifaces.front().c_str()); |
| 820 | } |
| 821 | added_ifaces.clear(); // could be redundent. But to be on safe side. |
| 822 | } |
| 823 | |
Hu Wang | 2a4e1a8 | 2020-03-24 10:57:49 +0800 | [diff] [blame] | 824 | static wifi_error wifi_set_interface_mode(wifi_handle handle, |
| 825 | const char* ifname, |
| 826 | u32 iface_type) |
| 827 | { |
| 828 | wifi_error ret; |
| 829 | WiFiConfigCommand *wifiConfigCommand; |
| 830 | |
| 831 | ALOGD("%s: ifname=%s iface_type=%u", __FUNCTION__, ifname, iface_type); |
| 832 | |
| 833 | wifiConfigCommand = new WiFiConfigCommand(handle, get_requestid(), 0, 0); |
| 834 | if (wifiConfigCommand == NULL) { |
| 835 | ALOGE("%s: Error wifiConfigCommand NULL", __FUNCTION__); |
| 836 | return WIFI_ERROR_UNKNOWN; |
| 837 | } |
| 838 | |
| 839 | nl80211_iftype type; |
| 840 | switch(iface_type) { |
| 841 | case WIFI_INTERFACE_TYPE_STA: /* IfaceType:STA */ |
| 842 | type = NL80211_IFTYPE_STATION; |
| 843 | break; |
| 844 | case WIFI_INTERFACE_TYPE_AP: /* IfaceType:AP */ |
| 845 | type = NL80211_IFTYPE_AP; |
| 846 | break; |
| 847 | case WIFI_INTERFACE_TYPE_P2P: /* IfaceType:P2P */ |
| 848 | type = NL80211_IFTYPE_P2P_DEVICE; |
| 849 | break; |
| 850 | case WIFI_INTERFACE_TYPE_NAN: /* IfaceType:NAN */ |
| 851 | type = NL80211_IFTYPE_NAN; |
| 852 | break; |
| 853 | default: |
| 854 | ALOGE("%s: Wrong interface type %u", __FUNCTION__, iface_type); |
| 855 | ret = WIFI_ERROR_UNKNOWN; |
| 856 | goto done; |
| 857 | break; |
| 858 | } |
| 859 | wifiConfigCommand->create_generic(NL80211_CMD_SET_INTERFACE); |
| 860 | wifiConfigCommand->put_u32(NL80211_ATTR_IFINDEX, if_nametoindex(ifname)); |
| 861 | wifiConfigCommand->put_u32(NL80211_ATTR_IFTYPE, type); |
| 862 | |
| 863 | /* Send the NL msg. */ |
| 864 | wifiConfigCommand->waitForRsp(false); |
| 865 | ret = wifiConfigCommand->requestEvent(); |
| 866 | if (ret != WIFI_SUCCESS) { |
| 867 | ALOGE("%s: requestEvent Error:%d", __FUNCTION__, ret); |
| 868 | } |
| 869 | |
| 870 | done: |
| 871 | delete wifiConfigCommand; |
| 872 | return ret; |
| 873 | } |
| 874 | |
Khanjan Desai | 80f7849 | 2020-03-03 00:04:51 +0530 | [diff] [blame] | 875 | wifi_error wifi_virtual_interface_create(wifi_handle handle, |
| 876 | const char* ifname, |
| 877 | wifi_interface_type iface_type) |
Purushottam Kushwaha | e1cf8f9 | 2018-06-08 17:47:53 +0530 | [diff] [blame] | 878 | { |
| 879 | wifi_error ret; |
| 880 | WiFiConfigCommand *wifiConfigCommand; |
Khanjan Desai | 3dfce20 | 2020-03-18 18:02:40 +0530 | [diff] [blame] | 881 | hal_info *info = getHalInfo(handle); |
| 882 | if (!info || info->num_interfaces < 1) { |
| 883 | ALOGE("%s: Error wifi_handle NULL or base wlan interface not present", __FUNCTION__); |
Khanjan Desai | 80f7849 | 2020-03-03 00:04:51 +0530 | [diff] [blame] | 884 | return WIFI_ERROR_UNKNOWN; |
| 885 | } |
Purushottam Kushwaha | e1cf8f9 | 2018-06-08 17:47:53 +0530 | [diff] [blame] | 886 | |
Hu Wang | 2a4e1a8 | 2020-03-24 10:57:49 +0800 | [diff] [blame] | 887 | // Already exists and set interface mode only |
| 888 | if (if_nametoindex(ifname) != 0) { |
| 889 | return wifi_set_interface_mode(handle, ifname, iface_type); |
| 890 | } |
| 891 | |
Khanjan Desai | 80f7849 | 2020-03-03 00:04:51 +0530 | [diff] [blame] | 892 | ALOGD("%s: ifname=%s create", __FUNCTION__, ifname); |
Purushottam Kushwaha | e1cf8f9 | 2018-06-08 17:47:53 +0530 | [diff] [blame] | 893 | |
Khanjan Desai | 80f7849 | 2020-03-03 00:04:51 +0530 | [diff] [blame] | 894 | wifiConfigCommand = new WiFiConfigCommand(handle, get_requestid(), 0, 0); |
Purushottam Kushwaha | e1cf8f9 | 2018-06-08 17:47:53 +0530 | [diff] [blame] | 895 | if (wifiConfigCommand == NULL) { |
| 896 | ALOGE("%s: Error wifiConfigCommand NULL", __FUNCTION__); |
| 897 | return WIFI_ERROR_UNKNOWN; |
| 898 | } |
| 899 | |
Khanjan Desai | 80f7849 | 2020-03-03 00:04:51 +0530 | [diff] [blame] | 900 | nl80211_iftype type; |
| 901 | switch(iface_type) { |
| 902 | case WIFI_INTERFACE_TYPE_STA: /* IfaceType:STA */ |
| 903 | type = NL80211_IFTYPE_STATION; |
| 904 | break; |
| 905 | case WIFI_INTERFACE_TYPE_AP: /* IfaceType:AP */ |
| 906 | type = NL80211_IFTYPE_AP; |
| 907 | break; |
| 908 | case WIFI_INTERFACE_TYPE_P2P: /* IfaceType:P2P */ |
| 909 | type = NL80211_IFTYPE_P2P_DEVICE; |
| 910 | break; |
Swarn Singh | c2c9bc8 | 2019-12-05 18:08:27 +0530 | [diff] [blame] | 911 | case WIFI_INTERFACE_TYPE_NAN: /* IfaceType:NAN */ |
| 912 | type = NL80211_IFTYPE_NAN; |
| 913 | break; |
Khanjan Desai | 80f7849 | 2020-03-03 00:04:51 +0530 | [diff] [blame] | 914 | default: |
| 915 | ALOGE("%s: Wrong interface type %u", __FUNCTION__, iface_type); |
| 916 | ret = WIFI_ERROR_UNKNOWN; |
| 917 | goto done; |
| 918 | break; |
Purushottam Kushwaha | e1cf8f9 | 2018-06-08 17:47:53 +0530 | [diff] [blame] | 919 | } |
Khanjan Desai | 80f7849 | 2020-03-03 00:04:51 +0530 | [diff] [blame] | 920 | wifiConfigCommand->create_generic(NL80211_CMD_NEW_INTERFACE); |
Khanjan Desai | 3dfce20 | 2020-03-18 18:02:40 +0530 | [diff] [blame] | 921 | wifiConfigCommand->put_u32(NL80211_ATTR_IFINDEX,info->interfaces[0]->id); |
Khanjan Desai | 80f7849 | 2020-03-03 00:04:51 +0530 | [diff] [blame] | 922 | wifiConfigCommand->put_string(NL80211_ATTR_IFNAME, ifname); |
| 923 | wifiConfigCommand->put_u32(NL80211_ATTR_IFTYPE, type); |
Purushottam Kushwaha | e1cf8f9 | 2018-06-08 17:47:53 +0530 | [diff] [blame] | 924 | /* Send the NL msg. */ |
| 925 | wifiConfigCommand->waitForRsp(false); |
| 926 | ret = wifiConfigCommand->requestEvent(); |
Khanjan Desai | 80f7849 | 2020-03-03 00:04:51 +0530 | [diff] [blame] | 927 | if (ret != WIFI_SUCCESS) { |
| 928 | ALOGE("%s: requestEvent Error:%d", __FUNCTION__,ret); |
Purushottam Kushwaha | e1cf8f9 | 2018-06-08 17:47:53 +0530 | [diff] [blame] | 929 | } |
Khanjan Desai | 80f7849 | 2020-03-03 00:04:51 +0530 | [diff] [blame] | 930 | // Update dynamic interface list |
| 931 | added_ifaces.push_back(std::string(ifname)); |
Khanjan Desai | 3dfdeb3 | 2021-10-13 15:03:09 +0530 | [diff] [blame] | 932 | if (iface_type == WIFI_INTERFACE_TYPE_STA) { |
| 933 | int sock = socket(AF_INET, SOCK_DGRAM, 0); |
| 934 | if(sock < 0) { |
| 935 | ALOGE("%s :socket error, Failed to bring up iface \n", __func__); |
| 936 | goto done; |
| 937 | } |
| 938 | struct ifreq ifr; |
| 939 | memset(&ifr, 0, sizeof(ifr)); |
| 940 | strlcpy(ifr.ifr_name, ifname, IFNAMSIZ); |
| 941 | if (ioctl(sock, SIOCGIFFLAGS, &ifr) != 0) { |
| 942 | ALOGE("%s :Could not read interface %s flags \n", __func__, ifname); |
| 943 | goto done; |
| 944 | } |
| 945 | ifr.ifr_flags |= IFF_UP; |
| 946 | if (ioctl(sock, SIOCSIFFLAGS, &ifr) != 0) { |
| 947 | ALOGE("%s :Could not bring iface %s up \n", __func__, ifname); |
| 948 | } |
| 949 | } |
Purushottam Kushwaha | e1cf8f9 | 2018-06-08 17:47:53 +0530 | [diff] [blame] | 950 | |
| 951 | done: |
| 952 | delete wifiConfigCommand; |
| 953 | return ret; |
| 954 | } |
Hu Wang | 38714b6 | 2018-11-08 19:57:21 +0800 | [diff] [blame] | 955 | |
Khanjan Desai | 80f7849 | 2020-03-03 00:04:51 +0530 | [diff] [blame] | 956 | wifi_error wifi_virtual_interface_delete(wifi_handle handle, |
| 957 | const char* ifname) |
| 958 | { |
| 959 | wifi_error ret; |
| 960 | WiFiConfigCommand *wifiConfigCommand; |
Khanjan Desai | 3dfce20 | 2020-03-18 18:02:40 +0530 | [diff] [blame] | 961 | if (!handle) { |
| 962 | ALOGE("%s: Error wifi_handle NULL", __FUNCTION__); |
Khanjan Desai | 80f7849 | 2020-03-03 00:04:51 +0530 | [diff] [blame] | 963 | return WIFI_ERROR_UNKNOWN; |
| 964 | } |
| 965 | |
| 966 | ALOGD("%s: ifname=%s delete", __FUNCTION__, ifname); |
| 967 | if (if_nametoindex(ifname) && !is_dynamic_interface(ifname)) { |
| 968 | // Do not remove interface if it was not added dynamically. |
| 969 | return WIFI_SUCCESS; |
| 970 | } |
| 971 | wifiConfigCommand = new WiFiConfigCommand(handle, get_requestid(), 0, 0); |
| 972 | if (wifiConfigCommand == NULL) { |
| 973 | ALOGE("%s: Error wifiConfigCommand NULL", __FUNCTION__); |
| 974 | return WIFI_ERROR_UNKNOWN; |
| 975 | } |
| 976 | wifiConfigCommand->create_generic(NL80211_CMD_DEL_INTERFACE); |
| 977 | wifiConfigCommand->put_u32(NL80211_ATTR_IFINDEX, if_nametoindex(ifname)); |
| 978 | /* Send the NL msg. */ |
| 979 | wifiConfigCommand->waitForRsp(false); |
| 980 | ret = wifiConfigCommand->requestEvent(); |
| 981 | if (ret != WIFI_SUCCESS) { |
| 982 | ALOGE("%s: requestEvent Error:%d", __FUNCTION__,ret); |
| 983 | } |
| 984 | // Update dynamic interface list |
| 985 | added_ifaces.erase(std::remove(added_ifaces.begin(), added_ifaces.end(), std::string(ifname)), |
| 986 | added_ifaces.end()); |
| 987 | |
| 988 | delete wifiConfigCommand; |
| 989 | return ret; |
| 990 | } |
| 991 | |
Hu Wang | 38714b6 | 2018-11-08 19:57:21 +0800 | [diff] [blame] | 992 | /** |
| 993 | * Set latency level |
| 994 | */ |
| 995 | wifi_error wifi_set_latency_mode(wifi_interface_handle iface, |
| 996 | wifi_latency_mode mode) |
| 997 | { |
| 998 | int requestId, ret = 0; |
Hu Wang | c193635 | 2019-04-25 15:26:03 +0800 | [diff] [blame] | 999 | u16 level; |
Hu Wang | 38714b6 | 2018-11-08 19:57:21 +0800 | [diff] [blame] | 1000 | WiFiConfigCommand *wifiConfigCommand; |
| 1001 | struct nlattr *nlData; |
| 1002 | interface_info *ifaceInfo = getIfaceInfo(iface); |
| 1003 | wifi_handle wifiHandle = getWifiHandle(iface); |
Sunil Dutt | 2447fbc | 2020-08-27 12:42:10 +0530 | [diff] [blame] | 1004 | hal_info *info = getHalInfo(wifiHandle); |
Hu Wang | 38714b6 | 2018-11-08 19:57:21 +0800 | [diff] [blame] | 1005 | |
| 1006 | ALOGD("%s: %d", __FUNCTION__, mode); |
| 1007 | |
Sunil Dutt | 2447fbc | 2020-08-27 12:42:10 +0530 | [diff] [blame] | 1008 | if (!(info->supported_feature_set & WIFI_FEATURE_SET_LATENCY_MODE)) { |
| 1009 | ALOGE("%s: Latency Mode is not supported by driver", __FUNCTION__); |
| 1010 | return WIFI_ERROR_NOT_SUPPORTED; |
| 1011 | }; |
| 1012 | |
Hu Wang | c193635 | 2019-04-25 15:26:03 +0800 | [diff] [blame] | 1013 | switch (mode) { |
| 1014 | case WIFI_LATENCY_MODE_NORMAL: |
| 1015 | level = QCA_WLAN_VENDOR_ATTR_CONFIG_LATENCY_LEVEL_NORMAL; |
| 1016 | break; |
| 1017 | case WIFI_LATENCY_MODE_LOW: |
| 1018 | level = QCA_WLAN_VENDOR_ATTR_CONFIG_LATENCY_LEVEL_ULTRALOW; |
| 1019 | break; |
| 1020 | default: |
| 1021 | ALOGI("%s: Unsupported latency mode=%d, resetting to NORMAL!", __FUNCTION__, mode); |
| 1022 | level = QCA_WLAN_VENDOR_ATTR_CONFIG_LATENCY_LEVEL_NORMAL; |
| 1023 | break; |
| 1024 | } |
| 1025 | |
Hu Wang | 38714b6 | 2018-11-08 19:57:21 +0800 | [diff] [blame] | 1026 | requestId = get_requestid(); |
| 1027 | |
| 1028 | wifiConfigCommand = new WiFiConfigCommand( |
| 1029 | wifiHandle, |
| 1030 | requestId, |
| 1031 | OUI_QCA, |
| 1032 | QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION); |
| 1033 | |
| 1034 | if (wifiConfigCommand == NULL) { |
| 1035 | ALOGE("%s: Error wifiConfigCommand NULL", __FUNCTION__); |
| 1036 | return WIFI_ERROR_UNKNOWN; |
| 1037 | } |
| 1038 | |
| 1039 | /* Create the NL message. */ |
| 1040 | ret = wifiConfigCommand->create(); |
| 1041 | if (ret < 0) { |
| 1042 | ALOGE("%s: failed to create NL msg. Error:%d", |
| 1043 | __FUNCTION__, ret); |
| 1044 | goto cleanup; |
| 1045 | } |
| 1046 | |
| 1047 | /* Set the interface Id of the message. */ |
| 1048 | ret = wifiConfigCommand->set_iface_id(ifaceInfo->name); |
| 1049 | if (ret < 0) { |
| 1050 | ALOGE("%s: failed to set iface id. Error:%d", |
| 1051 | __FUNCTION__, ret); |
| 1052 | goto cleanup; |
| 1053 | } |
| 1054 | |
| 1055 | /* Add the vendor specific attributes for the NL command. */ |
| 1056 | nlData = wifiConfigCommand->attr_start(NL80211_ATTR_VENDOR_DATA); |
| 1057 | if (!nlData) { |
| 1058 | ALOGE("%s: failed attr_start for VENDOR_DATA. Error:%d", |
| 1059 | __FUNCTION__, ret); |
| 1060 | goto cleanup; |
| 1061 | } |
| 1062 | |
| 1063 | if (wifiConfigCommand->put_u16( |
Hu Wang | c193635 | 2019-04-25 15:26:03 +0800 | [diff] [blame] | 1064 | QCA_WLAN_VENDOR_ATTR_CONFIG_LATENCY_LEVEL, level)) { |
Hu Wang | 38714b6 | 2018-11-08 19:57:21 +0800 | [diff] [blame] | 1065 | ALOGE("%s: failed to put vendor data. Error:%d", |
| 1066 | __FUNCTION__, ret); |
| 1067 | goto cleanup; |
| 1068 | } |
| 1069 | wifiConfigCommand->attr_end(nlData); |
| 1070 | |
| 1071 | /* Send the NL msg. */ |
| 1072 | wifiConfigCommand->waitForRsp(false); |
| 1073 | ret = wifiConfigCommand->requestEvent(); |
| 1074 | if (ret != 0) { |
| 1075 | ALOGE("%s: requestEvent Error:%d", __FUNCTION__, ret); |
| 1076 | goto cleanup; |
| 1077 | } |
| 1078 | |
| 1079 | cleanup: |
| 1080 | delete wifiConfigCommand; |
| 1081 | return (wifi_error)ret; |
| 1082 | } |