Roshan Pius | cc81756 | 2017-12-22 14:45:05 -0800 | [diff] [blame] | 1 | /* |
| 2 | * hidl interface for wpa_hostapd daemon |
| 3 | * Copyright (c) 2004-2018, Jouni Malinen <j@w1.fi> |
| 4 | * Copyright (c) 2004-2018, Roshan Pius <rpius@google.com> |
| 5 | * |
| 6 | * This software may be distributed under the terms of the BSD license. |
| 7 | * See README for more details. |
| 8 | */ |
Roshan Pius | 30b452e | 2017-12-27 13:36:21 -0800 | [diff] [blame] | 9 | #include <iomanip> |
| 10 | #include <sstream> |
| 11 | #include <string> |
| 12 | #include <vector> |
lesl | 0cb0e27 | 2020-10-30 16:58:08 +0800 | [diff] [blame] | 13 | #include <net/if.h> |
| 14 | #include <sys/socket.h> |
| 15 | #include <linux/if_bridge.h> |
| 16 | |
Roshan Pius | 30b452e | 2017-12-27 13:36:21 -0800 | [diff] [blame] | 17 | |
| 18 | #include <android-base/file.h> |
| 19 | #include <android-base/stringprintf.h> |
lesl | 0cb0e27 | 2020-10-30 16:58:08 +0800 | [diff] [blame] | 20 | #include <android-base/unique_fd.h> |
Roshan Pius | cc81756 | 2017-12-22 14:45:05 -0800 | [diff] [blame] | 21 | |
| 22 | #include "hostapd.h" |
| 23 | #include "hidl_return_util.h" |
| 24 | |
Roshan Pius | 3455af4 | 2018-02-01 09:19:49 -0800 | [diff] [blame] | 25 | extern "C" |
| 26 | { |
lesl | dab9150 | 2020-08-17 18:29:47 +0800 | [diff] [blame] | 27 | #include "common/wpa_ctrl.h" |
lesl | 0cb0e27 | 2020-10-30 16:58:08 +0800 | [diff] [blame] | 28 | #include "drivers/linux_ioctl.h" |
Roshan Pius | 3455af4 | 2018-02-01 09:19:49 -0800 | [diff] [blame] | 29 | } |
| 30 | |
Roshan Pius | 30b452e | 2017-12-27 13:36:21 -0800 | [diff] [blame] | 31 | // The HIDL implementation for hostapd creates a hostapd.conf dynamically for |
| 32 | // each interface. This file can then be used to hook onto the normal config |
| 33 | // file parsing logic in hostapd code. Helps us to avoid duplication of code |
| 34 | // in the HIDL interface. |
| 35 | // TOOD(b/71872409): Add unit tests for this. |
| 36 | namespace { |
| 37 | constexpr char kConfFileNameFmt[] = "/data/vendor/wifi/hostapd/hostapd_%s.conf"; |
| 38 | |
| 39 | using android::base::RemoveFileIfExists; |
| 40 | using android::base::StringPrintf; |
| 41 | using android::base::WriteStringToFile; |
lesl | b0f4d54 | 2020-09-16 23:06:03 +0800 | [diff] [blame] | 42 | using android::hardware::wifi::hostapd::V1_3::IHostapd; |
lesl | dab9150 | 2020-08-17 18:29:47 +0800 | [diff] [blame] | 43 | using android::hardware::wifi::hostapd::V1_3::Generation; |
| 44 | using android::hardware::wifi::hostapd::V1_3::Bandwidth; |
Roshan Pius | 30b452e | 2017-12-27 13:36:21 -0800 | [diff] [blame] | 45 | |
lesl | 0cb0e27 | 2020-10-30 16:58:08 +0800 | [diff] [blame] | 46 | #define MAX_PORTS 1024 |
| 47 | bool GetInterfacesInBridge(std::string br_name, |
| 48 | std::vector<std::string>* interfaces) { |
| 49 | android::base::unique_fd sock(socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0)); |
| 50 | if (sock.get() < 0) { |
| 51 | wpa_printf(MSG_ERROR, "Failed to create sock (%s) in %s", |
| 52 | strerror(errno), __FUNCTION__); |
| 53 | return false; |
| 54 | } |
| 55 | |
| 56 | struct ifreq request; |
| 57 | int i, ifindices[MAX_PORTS]; |
| 58 | char if_name[IFNAMSIZ]; |
| 59 | unsigned long args[3]; |
| 60 | |
| 61 | memset(ifindices, 0, MAX_PORTS * sizeof(int)); |
| 62 | |
| 63 | args[0] = BRCTL_GET_PORT_LIST; |
| 64 | args[1] = (unsigned long) ifindices; |
| 65 | args[2] = MAX_PORTS; |
| 66 | |
| 67 | strlcpy(request.ifr_name, br_name.c_str(), IFNAMSIZ); |
| 68 | request.ifr_data = (char *)args; |
| 69 | |
| 70 | if (ioctl(sock.get(), SIOCDEVPRIVATE, &request) < 0) { |
| 71 | wpa_printf(MSG_ERROR, "Failed to ioctl SIOCDEVPRIVATE in %s", |
| 72 | __FUNCTION__); |
| 73 | return false; |
| 74 | } |
| 75 | |
| 76 | for (i = 0; i < MAX_PORTS; i ++) { |
| 77 | memset(if_name, 0, IFNAMSIZ); |
| 78 | if (ifindices[i] == 0 || !if_indextoname(ifindices[i], if_name)) { |
| 79 | continue; |
| 80 | } |
| 81 | interfaces->push_back(if_name); |
| 82 | } |
| 83 | return true; |
| 84 | } |
| 85 | |
Roshan Pius | 30b452e | 2017-12-27 13:36:21 -0800 | [diff] [blame] | 86 | std::string WriteHostapdConfig( |
| 87 | const std::string& interface_name, const std::string& config) |
| 88 | { |
| 89 | const std::string file_path = |
| 90 | StringPrintf(kConfFileNameFmt, interface_name.c_str()); |
| 91 | if (WriteStringToFile( |
| 92 | config, file_path, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP, |
| 93 | getuid(), getgid())) { |
| 94 | return file_path; |
| 95 | } |
| 96 | // Diagnose failure |
| 97 | int error = errno; |
| 98 | wpa_printf( |
| 99 | MSG_ERROR, "Cannot write hostapd config to %s, error: %s", |
| 100 | file_path.c_str(), strerror(error)); |
| 101 | struct stat st; |
| 102 | int result = stat(file_path.c_str(), &st); |
| 103 | if (result == 0) { |
| 104 | wpa_printf( |
| 105 | MSG_ERROR, "hostapd config file uid: %d, gid: %d, mode: %d", |
| 106 | st.st_uid, st.st_gid, st.st_mode); |
| 107 | } else { |
| 108 | wpa_printf( |
| 109 | MSG_ERROR, |
| 110 | "Error calling stat() on hostapd config file: %s", |
| 111 | strerror(errno)); |
| 112 | } |
| 113 | return ""; |
| 114 | } |
| 115 | |
Ahmed ElArabawy | 7b4b40a | 2020-01-02 08:55:38 -0800 | [diff] [blame] | 116 | /* |
| 117 | * Get the op_class for a channel/band |
| 118 | * The logic here is based on Table E-4 in the 802.11 Specification |
| 119 | */ |
| 120 | int getOpClassForChannel(int channel, int band, bool support11n, bool support11ac) { |
| 121 | // 2GHz Band |
| 122 | if ((band & IHostapd::BandMask::BAND_2_GHZ) != 0) { |
| 123 | if (channel == 14) { |
| 124 | return 82; |
| 125 | } |
| 126 | if (channel >= 1 && channel <= 13) { |
| 127 | if (!support11n) { |
| 128 | //20MHz channel |
| 129 | return 81; |
| 130 | } |
| 131 | if (channel <= 9) { |
| 132 | // HT40 with secondary channel above primary |
| 133 | return 83; |
| 134 | } |
| 135 | // HT40 with secondary channel below primary |
| 136 | return 84; |
| 137 | } |
| 138 | // Error |
| 139 | return 0; |
| 140 | } |
| 141 | |
| 142 | // 5GHz Band |
| 143 | if ((band & IHostapd::BandMask::BAND_5_GHZ) != 0) { |
| 144 | if (support11ac) { |
| 145 | switch (channel) { |
| 146 | case 42: |
| 147 | case 58: |
| 148 | case 106: |
| 149 | case 122: |
| 150 | case 138: |
| 151 | case 155: |
| 152 | // 80MHz channel |
| 153 | return 128; |
| 154 | case 50: |
| 155 | case 114: |
| 156 | // 160MHz channel |
| 157 | return 129; |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | if (!support11n) { |
| 162 | if (channel >= 36 && channel <= 48) { |
| 163 | return 115; |
| 164 | } |
| 165 | if (channel >= 52 && channel <= 64) { |
| 166 | return 118; |
| 167 | } |
| 168 | if (channel >= 100 && channel <= 144) { |
| 169 | return 121; |
| 170 | } |
| 171 | if (channel >= 149 && channel <= 161) { |
| 172 | return 124; |
| 173 | } |
| 174 | if (channel >= 165 && channel <= 169) { |
| 175 | return 125; |
| 176 | } |
| 177 | } else { |
| 178 | switch (channel) { |
| 179 | case 36: |
| 180 | case 44: |
| 181 | // HT40 with secondary channel above primary |
| 182 | return 116; |
| 183 | case 40: |
| 184 | case 48: |
| 185 | // HT40 with secondary channel below primary |
| 186 | return 117; |
| 187 | case 52: |
| 188 | case 60: |
| 189 | // HT40 with secondary channel above primary |
| 190 | return 119; |
| 191 | case 56: |
| 192 | case 64: |
| 193 | // HT40 with secondary channel below primary |
| 194 | return 120; |
| 195 | case 100: |
| 196 | case 108: |
| 197 | case 116: |
| 198 | case 124: |
| 199 | case 132: |
| 200 | case 140: |
| 201 | // HT40 with secondary channel above primary |
| 202 | return 122; |
| 203 | case 104: |
| 204 | case 112: |
| 205 | case 120: |
| 206 | case 128: |
| 207 | case 136: |
| 208 | case 144: |
| 209 | // HT40 with secondary channel below primary |
| 210 | return 123; |
| 211 | case 149: |
| 212 | case 157: |
| 213 | // HT40 with secondary channel above primary |
| 214 | return 126; |
| 215 | case 153: |
| 216 | case 161: |
| 217 | // HT40 with secondary channel below primary |
| 218 | return 127; |
| 219 | } |
| 220 | } |
| 221 | // Error |
| 222 | return 0; |
| 223 | } |
| 224 | |
| 225 | // 6GHz Band |
| 226 | if ((band & IHostapd::BandMask::BAND_6_GHZ) != 0) { |
| 227 | // Channels 1, 5. 9, 13, ... |
| 228 | if ((channel & 0x03) == 0x01) { |
| 229 | // 20MHz channel |
| 230 | return 131; |
| 231 | } |
| 232 | // Channels 3, 11, 19, 27, ... |
| 233 | if ((channel & 0x07) == 0x03) { |
| 234 | // 40MHz channel |
| 235 | return 132; |
| 236 | } |
| 237 | // Channels 7, 23, 39, 55, ... |
| 238 | if ((channel & 0x0F) == 0x07) { |
| 239 | // 80MHz channel |
| 240 | return 133; |
| 241 | } |
| 242 | // Channels 15, 47, 69, ... |
| 243 | if ((channel & 0x1F) == 0x0F) { |
| 244 | // 160MHz channel |
| 245 | return 134; |
| 246 | } |
Kai Shi | a0cfc14 | 2020-09-16 20:05:13 -0700 | [diff] [blame] | 247 | if (channel == 2) { |
| 248 | // 20MHz channel |
| 249 | return 136; |
| 250 | } |
Ahmed ElArabawy | 7b4b40a | 2020-01-02 08:55:38 -0800 | [diff] [blame] | 251 | // Error |
| 252 | return 0; |
| 253 | } |
| 254 | |
| 255 | return 0; |
| 256 | } |
| 257 | |
lesl | dd48efd | 2019-12-26 15:13:51 +0800 | [diff] [blame] | 258 | bool validatePassphrase(int passphrase_len, int min_len, int max_len) |
| 259 | { |
| 260 | if (min_len != -1 && passphrase_len < min_len) return false; |
| 261 | if (max_len != -1 && passphrase_len > max_len) return false; |
| 262 | return true; |
| 263 | } |
| 264 | |
Roshan Pius | 30b452e | 2017-12-27 13:36:21 -0800 | [diff] [blame] | 265 | std::string CreateHostapdConfig( |
lesl | 3129425 | 2020-11-06 17:06:03 +0800 | [diff] [blame^] | 266 | const android::hardware::wifi::hostapd::V1_3::IHostapd::IfaceParams& iface_params, |
| 267 | const android::hardware::wifi::hostapd::V1_3::IHostapd::ChannelParams& channelParams, |
lesl | 0cb0e27 | 2020-10-30 16:58:08 +0800 | [diff] [blame] | 268 | const IHostapd::NetworkParams& nw_params, |
| 269 | const std::string br_name) |
Roshan Pius | 30b452e | 2017-12-27 13:36:21 -0800 | [diff] [blame] | 270 | { |
lesl | b0f4d54 | 2020-09-16 23:06:03 +0800 | [diff] [blame] | 271 | if (nw_params.V1_2.V1_0.ssid.size() > |
Roshan Pius | 30b452e | 2017-12-27 13:36:21 -0800 | [diff] [blame] | 272 | static_cast<uint32_t>( |
| 273 | IHostapd::ParamSizeLimits::SSID_MAX_LEN_IN_BYTES)) { |
| 274 | wpa_printf( |
lesl | b0f4d54 | 2020-09-16 23:06:03 +0800 | [diff] [blame] | 275 | MSG_ERROR, "Invalid SSID size: %zu", nw_params.V1_2.V1_0.ssid.size()); |
Roshan Pius | 30b452e | 2017-12-27 13:36:21 -0800 | [diff] [blame] | 276 | return ""; |
| 277 | } |
| 278 | |
| 279 | // SSID string |
| 280 | std::stringstream ss; |
| 281 | ss << std::hex; |
| 282 | ss << std::setfill('0'); |
lesl | b0f4d54 | 2020-09-16 23:06:03 +0800 | [diff] [blame] | 283 | for (uint8_t b : nw_params.V1_2.V1_0.ssid) { |
Roshan Pius | 30b452e | 2017-12-27 13:36:21 -0800 | [diff] [blame] | 284 | ss << std::setw(2) << static_cast<unsigned int>(b); |
| 285 | } |
| 286 | const std::string ssid_as_string = ss.str(); |
| 287 | |
| 288 | // Encryption config string |
Kai Shi | 35d8ea4 | 2020-10-07 15:24:01 -0700 | [diff] [blame] | 289 | uint32_t band = 0; |
lesl | 3129425 | 2020-11-06 17:06:03 +0800 | [diff] [blame^] | 290 | band |= channelParams.V1_2.bandMask; |
Kai Shi | 35d8ea4 | 2020-10-07 15:24:01 -0700 | [diff] [blame] | 291 | bool is_6Ghz_band_only = band == static_cast<uint32_t>(IHostapd::BandMask::BAND_6_GHZ); |
Roshan Pius | 30b452e | 2017-12-27 13:36:21 -0800 | [diff] [blame] | 292 | std::string encryption_config_as_string; |
lesl | b0f4d54 | 2020-09-16 23:06:03 +0800 | [diff] [blame] | 293 | switch (nw_params.V1_2.encryptionType) { |
Roshan Pius | 30b452e | 2017-12-27 13:36:21 -0800 | [diff] [blame] | 294 | case IHostapd::EncryptionType::NONE: |
| 295 | // no security params |
| 296 | break; |
| 297 | case IHostapd::EncryptionType::WPA: |
lesl | dd48efd | 2019-12-26 15:13:51 +0800 | [diff] [blame] | 298 | if (!validatePassphrase( |
lesl | b0f4d54 | 2020-09-16 23:06:03 +0800 | [diff] [blame] | 299 | nw_params.V1_2.passphrase.size(), |
lesl | dd48efd | 2019-12-26 15:13:51 +0800 | [diff] [blame] | 300 | static_cast<uint32_t>(IHostapd::ParamSizeLimits:: |
| 301 | WPA2_PSK_PASSPHRASE_MIN_LEN_IN_BYTES), |
| 302 | static_cast<uint32_t>(IHostapd::ParamSizeLimits:: |
| 303 | WPA2_PSK_PASSPHRASE_MAX_LEN_IN_BYTES))) { |
| 304 | return ""; |
| 305 | } |
Roshan Pius | 30b452e | 2017-12-27 13:36:21 -0800 | [diff] [blame] | 306 | encryption_config_as_string = StringPrintf( |
| 307 | "wpa=3\n" |
| 308 | "wpa_pairwise=TKIP CCMP\n" |
| 309 | "wpa_passphrase=%s", |
lesl | b0f4d54 | 2020-09-16 23:06:03 +0800 | [diff] [blame] | 310 | nw_params.V1_2.passphrase.c_str()); |
Roshan Pius | 30b452e | 2017-12-27 13:36:21 -0800 | [diff] [blame] | 311 | break; |
| 312 | case IHostapd::EncryptionType::WPA2: |
lesl | dd48efd | 2019-12-26 15:13:51 +0800 | [diff] [blame] | 313 | if (!validatePassphrase( |
lesl | b0f4d54 | 2020-09-16 23:06:03 +0800 | [diff] [blame] | 314 | nw_params.V1_2.passphrase.size(), |
lesl | dd48efd | 2019-12-26 15:13:51 +0800 | [diff] [blame] | 315 | static_cast<uint32_t>(IHostapd::ParamSizeLimits:: |
| 316 | WPA2_PSK_PASSPHRASE_MIN_LEN_IN_BYTES), |
| 317 | static_cast<uint32_t>(IHostapd::ParamSizeLimits:: |
| 318 | WPA2_PSK_PASSPHRASE_MAX_LEN_IN_BYTES))) { |
| 319 | return ""; |
| 320 | } |
Roshan Pius | 30b452e | 2017-12-27 13:36:21 -0800 | [diff] [blame] | 321 | encryption_config_as_string = StringPrintf( |
| 322 | "wpa=2\n" |
| 323 | "rsn_pairwise=CCMP\n" |
| 324 | "wpa_passphrase=%s", |
lesl | b0f4d54 | 2020-09-16 23:06:03 +0800 | [diff] [blame] | 325 | nw_params.V1_2.passphrase.c_str()); |
lesl | dd48efd | 2019-12-26 15:13:51 +0800 | [diff] [blame] | 326 | break; |
| 327 | case IHostapd::EncryptionType::WPA3_SAE_TRANSITION: |
| 328 | if (!validatePassphrase( |
lesl | b0f4d54 | 2020-09-16 23:06:03 +0800 | [diff] [blame] | 329 | nw_params.V1_2.passphrase.size(), |
lesl | dd48efd | 2019-12-26 15:13:51 +0800 | [diff] [blame] | 330 | static_cast<uint32_t>(IHostapd::ParamSizeLimits:: |
| 331 | WPA2_PSK_PASSPHRASE_MIN_LEN_IN_BYTES), |
| 332 | static_cast<uint32_t>(IHostapd::ParamSizeLimits:: |
| 333 | WPA2_PSK_PASSPHRASE_MAX_LEN_IN_BYTES))) { |
| 334 | return ""; |
| 335 | } |
| 336 | encryption_config_as_string = StringPrintf( |
| 337 | "wpa=2\n" |
| 338 | "rsn_pairwise=CCMP\n" |
| 339 | "wpa_key_mgmt=WPA-PSK SAE\n" |
| 340 | "ieee80211w=1\n" |
| 341 | "sae_require_mfp=1\n" |
| 342 | "wpa_passphrase=%s\n" |
| 343 | "sae_password=%s", |
lesl | b0f4d54 | 2020-09-16 23:06:03 +0800 | [diff] [blame] | 344 | nw_params.V1_2.passphrase.c_str(), |
| 345 | nw_params.V1_2.passphrase.c_str()); |
lesl | dd48efd | 2019-12-26 15:13:51 +0800 | [diff] [blame] | 346 | break; |
| 347 | case IHostapd::EncryptionType::WPA3_SAE: |
lesl | b0f4d54 | 2020-09-16 23:06:03 +0800 | [diff] [blame] | 348 | if (!validatePassphrase(nw_params.V1_2.passphrase.size(), 1, -1)) { |
lesl | dd48efd | 2019-12-26 15:13:51 +0800 | [diff] [blame] | 349 | return ""; |
| 350 | } |
| 351 | encryption_config_as_string = StringPrintf( |
| 352 | "wpa=2\n" |
| 353 | "rsn_pairwise=CCMP\n" |
| 354 | "wpa_key_mgmt=SAE\n" |
| 355 | "ieee80211w=2\n" |
| 356 | "sae_require_mfp=2\n" |
Kai Shi | 35d8ea4 | 2020-10-07 15:24:01 -0700 | [diff] [blame] | 357 | "sae_pwe=%d\n" |
lesl | dd48efd | 2019-12-26 15:13:51 +0800 | [diff] [blame] | 358 | "sae_password=%s", |
Kai Shi | 35d8ea4 | 2020-10-07 15:24:01 -0700 | [diff] [blame] | 359 | is_6Ghz_band_only ? 1 : 2, |
lesl | b0f4d54 | 2020-09-16 23:06:03 +0800 | [diff] [blame] | 360 | nw_params.V1_2.passphrase.c_str()); |
Roshan Pius | 30b452e | 2017-12-27 13:36:21 -0800 | [diff] [blame] | 361 | break; |
| 362 | default: |
| 363 | wpa_printf(MSG_ERROR, "Unknown encryption type"); |
| 364 | return ""; |
| 365 | } |
| 366 | |
| 367 | std::string channel_config_as_string; |
Ahmed ElArabawy | a390f29 | 2019-12-21 13:07:02 -0800 | [diff] [blame] | 368 | bool isFirst = true; |
lesl | 3129425 | 2020-11-06 17:06:03 +0800 | [diff] [blame^] | 369 | if (channelParams.enableAcs) { |
Ahmed ElArabawy | a390f29 | 2019-12-21 13:07:02 -0800 | [diff] [blame] | 370 | std::string freqList_as_string; |
Daisuke Niwa | c1bd20f | 2019-01-09 13:51:02 +0900 | [diff] [blame] | 371 | for (const auto &range : |
lesl | 3129425 | 2020-11-06 17:06:03 +0800 | [diff] [blame^] | 372 | channelParams.V1_2.acsChannelFreqRangesMhz) { |
Ahmed ElArabawy | a390f29 | 2019-12-21 13:07:02 -0800 | [diff] [blame] | 373 | if (!isFirst) { |
| 374 | freqList_as_string += ","; |
| 375 | } |
| 376 | isFirst = false; |
| 377 | |
Daisuke Niwa | c1bd20f | 2019-01-09 13:51:02 +0900 | [diff] [blame] | 378 | if (range.start != range.end) { |
Ahmed ElArabawy | a390f29 | 2019-12-21 13:07:02 -0800 | [diff] [blame] | 379 | freqList_as_string += |
| 380 | StringPrintf("%d-%d", range.start, range.end); |
Daisuke Niwa | c1bd20f | 2019-01-09 13:51:02 +0900 | [diff] [blame] | 381 | } else { |
Ahmed ElArabawy | a390f29 | 2019-12-21 13:07:02 -0800 | [diff] [blame] | 382 | freqList_as_string += StringPrintf("%d", range.start); |
Daisuke Niwa | c1bd20f | 2019-01-09 13:51:02 +0900 | [diff] [blame] | 383 | } |
| 384 | } |
Roshan Pius | 30b452e | 2017-12-27 13:36:21 -0800 | [diff] [blame] | 385 | channel_config_as_string = StringPrintf( |
| 386 | "channel=0\n" |
Daisuke Niwa | c1bd20f | 2019-01-09 13:51:02 +0900 | [diff] [blame] | 387 | "acs_exclude_dfs=%d\n" |
Ahmed ElArabawy | a390f29 | 2019-12-21 13:07:02 -0800 | [diff] [blame] | 388 | "freqlist=%s", |
lesl | 3129425 | 2020-11-06 17:06:03 +0800 | [diff] [blame^] | 389 | iface_params.V1_2.V1_1.V1_0.channelParams.acsShouldExcludeDfs, |
Ahmed ElArabawy | a390f29 | 2019-12-21 13:07:02 -0800 | [diff] [blame] | 390 | freqList_as_string.c_str()); |
Roshan Pius | 30b452e | 2017-12-27 13:36:21 -0800 | [diff] [blame] | 391 | } else { |
Ahmed ElArabawy | 7b4b40a | 2020-01-02 08:55:38 -0800 | [diff] [blame] | 392 | int op_class = getOpClassForChannel( |
lesl | 3129425 | 2020-11-06 17:06:03 +0800 | [diff] [blame^] | 393 | channelParams.channel, |
Ahmed ElArabawy | 7b4b40a | 2020-01-02 08:55:38 -0800 | [diff] [blame] | 394 | band, |
lesl | 3129425 | 2020-11-06 17:06:03 +0800 | [diff] [blame^] | 395 | iface_params.V1_2.V1_1.V1_0.hwModeParams.enable80211N, |
| 396 | iface_params.V1_2.V1_1.V1_0.hwModeParams.enable80211AC); |
Roshan Pius | 30b452e | 2017-12-27 13:36:21 -0800 | [diff] [blame] | 397 | channel_config_as_string = StringPrintf( |
Ahmed ElArabawy | 7b4b40a | 2020-01-02 08:55:38 -0800 | [diff] [blame] | 398 | "channel=%d\n" |
| 399 | "op_class=%d", |
lesl | 3129425 | 2020-11-06 17:06:03 +0800 | [diff] [blame^] | 400 | channelParams.channel, op_class); |
Roshan Pius | 30b452e | 2017-12-27 13:36:21 -0800 | [diff] [blame] | 401 | } |
| 402 | |
Roshan Pius | 30b452e | 2017-12-27 13:36:21 -0800 | [diff] [blame] | 403 | std::string hw_mode_as_string; |
Roshan Pius | 4944647 | 2018-03-07 10:23:46 -0800 | [diff] [blame] | 404 | std::string ht_cap_vht_oper_chwidth_as_string; |
Ahmed ElArabawy | 3498267 | 2019-12-06 10:10:17 -0800 | [diff] [blame] | 405 | |
| 406 | if ((band & IHostapd::BandMask::BAND_2_GHZ) != 0) { |
Ahmed ElArabawy | a390f29 | 2019-12-21 13:07:02 -0800 | [diff] [blame] | 407 | if (((band & IHostapd::BandMask::BAND_5_GHZ) != 0) |
| 408 | || ((band & IHostapd::BandMask::BAND_6_GHZ) != 0)) { |
Ahmed ElArabawy | 3498267 | 2019-12-06 10:10:17 -0800 | [diff] [blame] | 409 | hw_mode_as_string = "hw_mode=any"; |
lesl | 3129425 | 2020-11-06 17:06:03 +0800 | [diff] [blame^] | 410 | if (iface_params.V1_2.V1_1.V1_0.hwModeParams.enable80211AC) { |
Ahmed ElArabawy | 3498267 | 2019-12-06 10:10:17 -0800 | [diff] [blame] | 411 | ht_cap_vht_oper_chwidth_as_string = |
| 412 | "ht_capab=[HT40+]\n" |
| 413 | "vht_oper_chwidth=1"; |
| 414 | } |
| 415 | } else { |
| 416 | hw_mode_as_string = "hw_mode=g"; |
Roshan Pius | 4944647 | 2018-03-07 10:23:46 -0800 | [diff] [blame] | 417 | } |
Ahmed ElArabawy | 3498267 | 2019-12-06 10:10:17 -0800 | [diff] [blame] | 418 | } else { |
Ahmed ElArabawy | a390f29 | 2019-12-21 13:07:02 -0800 | [diff] [blame] | 419 | if (((band & IHostapd::BandMask::BAND_5_GHZ) != 0) |
| 420 | || ((band & IHostapd::BandMask::BAND_6_GHZ) != 0)) { |
Ahmed ElArabawy | 3498267 | 2019-12-06 10:10:17 -0800 | [diff] [blame] | 421 | hw_mode_as_string = "hw_mode=a"; |
lesl | 3129425 | 2020-11-06 17:06:03 +0800 | [diff] [blame^] | 422 | if (iface_params.V1_2.V1_1.V1_0.hwModeParams.enable80211AC) { |
Ahmed ElArabawy | 3498267 | 2019-12-06 10:10:17 -0800 | [diff] [blame] | 423 | ht_cap_vht_oper_chwidth_as_string = |
| 424 | "ht_capab=[HT40+]\n" |
| 425 | "vht_oper_chwidth=1"; |
| 426 | } |
| 427 | } else { |
| 428 | wpa_printf(MSG_ERROR, "Invalid band"); |
| 429 | return ""; |
Roshan Pius | 4944647 | 2018-03-07 10:23:46 -0800 | [diff] [blame] | 430 | } |
Roshan Pius | 30b452e | 2017-12-27 13:36:21 -0800 | [diff] [blame] | 431 | } |
| 432 | |
Ahmed ElArabawy | 5362fb1 | 2020-01-02 15:01:31 -0800 | [diff] [blame] | 433 | std::string he_params_as_string; |
Roshan Pius | 3651030 | 2020-05-09 21:01:01 -0700 | [diff] [blame] | 434 | #ifdef CONFIG_IEEE80211AX |
lesl | 3129425 | 2020-11-06 17:06:03 +0800 | [diff] [blame^] | 435 | if (iface_params.V1_2.hwModeParams.enable80211AX) { |
Ahmed ElArabawy | 5362fb1 | 2020-01-02 15:01:31 -0800 | [diff] [blame] | 436 | he_params_as_string = StringPrintf( |
| 437 | "ieee80211ax=1\n" |
| 438 | "he_su_beamformer=%d\n" |
| 439 | "he_su_beamformee=%d\n" |
| 440 | "he_mu_beamformer=%d\n" |
Ahmed ElArabawy | 5362fb1 | 2020-01-02 15:01:31 -0800 | [diff] [blame] | 441 | "he_twt_required=%d\n", |
lesl | 3129425 | 2020-11-06 17:06:03 +0800 | [diff] [blame^] | 442 | iface_params.V1_2.hwModeParams.enableHeSingleUserBeamformer ? 1 : 0, |
| 443 | iface_params.V1_2.hwModeParams.enableHeSingleUserBeamformee ? 1 : 0, |
| 444 | iface_params.V1_2.hwModeParams.enableHeMultiUserBeamformer ? 1 : 0, |
| 445 | iface_params.V1_2.hwModeParams.enableHeTargetWakeTime ? 1 : 0); |
Ahmed ElArabawy | 5362fb1 | 2020-01-02 15:01:31 -0800 | [diff] [blame] | 446 | } else { |
| 447 | he_params_as_string = "ieee80211ax=0"; |
| 448 | } |
Roshan Pius | 3651030 | 2020-05-09 21:01:01 -0700 | [diff] [blame] | 449 | #endif /* CONFIG_IEEE80211AX */ |
Ahmed ElArabawy | 5362fb1 | 2020-01-02 15:01:31 -0800 | [diff] [blame] | 450 | |
lesl | b0f4d54 | 2020-09-16 23:06:03 +0800 | [diff] [blame] | 451 | #ifdef CONFIG_INTERWORKING |
| 452 | std::string access_network_params_as_string; |
| 453 | if (nw_params.isMetered) { |
| 454 | access_network_params_as_string = StringPrintf( |
| 455 | "interworking=1\n" |
| 456 | "access_network_type=2\n"); // CHARGEABLE_PUBLIC_NETWORK |
| 457 | } else { |
| 458 | access_network_params_as_string = StringPrintf( |
| 459 | "interworking=0\n"); |
| 460 | } |
| 461 | #endif /* CONFIG_INTERWORKING */ |
| 462 | |
lesl | 0cb0e27 | 2020-10-30 16:58:08 +0800 | [diff] [blame] | 463 | std::string bridge_as_string; |
| 464 | if (!br_name.empty()) { |
| 465 | bridge_as_string = StringPrintf("bridge=%s", br_name.c_str()); |
| 466 | } |
| 467 | |
Roshan Pius | 30b452e | 2017-12-27 13:36:21 -0800 | [diff] [blame] | 468 | return StringPrintf( |
| 469 | "interface=%s\n" |
| 470 | "driver=nl80211\n" |
Daichi Ueura | caa74a8 | 2018-02-14 22:25:39 +0900 | [diff] [blame] | 471 | "ctrl_interface=/data/vendor/wifi/hostapd/ctrl\n" |
Roshan Pius | 30b452e | 2017-12-27 13:36:21 -0800 | [diff] [blame] | 472 | // ssid2 signals to hostapd that the value is not a literal value |
| 473 | // for use as a SSID. In this case, we're giving it a hex |
| 474 | // std::string and hostapd needs to expect that. |
| 475 | "ssid2=%s\n" |
| 476 | "%s\n" |
| 477 | "ieee80211n=%d\n" |
| 478 | "ieee80211ac=%d\n" |
Ahmed ElArabawy | 5362fb1 | 2020-01-02 15:01:31 -0800 | [diff] [blame] | 479 | "%s\n" |
Roshan Pius | e453f71 | 2018-02-09 15:49:57 -0800 | [diff] [blame] | 480 | "%s\n" |
Roshan Pius | 4944647 | 2018-03-07 10:23:46 -0800 | [diff] [blame] | 481 | "%s\n" |
Roshan Pius | 30b452e | 2017-12-27 13:36:21 -0800 | [diff] [blame] | 482 | "ignore_broadcast_ssid=%d\n" |
| 483 | "wowlan_triggers=any\n" |
lesl | b0f4d54 | 2020-09-16 23:06:03 +0800 | [diff] [blame] | 484 | #ifdef CONFIG_INTERWORKING |
| 485 | "%s\n" |
| 486 | #endif /* CONFIG_INTERWORKING */ |
lesl | 0cb0e27 | 2020-10-30 16:58:08 +0800 | [diff] [blame] | 487 | "%s\n" |
Roshan Pius | 30b452e | 2017-12-27 13:36:21 -0800 | [diff] [blame] | 488 | "%s\n", |
lesl | 3129425 | 2020-11-06 17:06:03 +0800 | [diff] [blame^] | 489 | iface_params.V1_2.V1_1.V1_0.ifaceName.c_str(), ssid_as_string.c_str(), |
Roshan Pius | 30b452e | 2017-12-27 13:36:21 -0800 | [diff] [blame] | 490 | channel_config_as_string.c_str(), |
lesl | 3129425 | 2020-11-06 17:06:03 +0800 | [diff] [blame^] | 491 | iface_params.V1_2.V1_1.V1_0.hwModeParams.enable80211N ? 1 : 0, |
| 492 | iface_params.V1_2.V1_1.V1_0.hwModeParams.enable80211AC ? 1 : 0, |
Ahmed ElArabawy | 5362fb1 | 2020-01-02 15:01:31 -0800 | [diff] [blame] | 493 | he_params_as_string.c_str(), |
Roshan Pius | 4944647 | 2018-03-07 10:23:46 -0800 | [diff] [blame] | 494 | hw_mode_as_string.c_str(), ht_cap_vht_oper_chwidth_as_string.c_str(), |
lesl | b0f4d54 | 2020-09-16 23:06:03 +0800 | [diff] [blame] | 495 | nw_params.V1_2.V1_0.isHidden ? 1 : 0, |
| 496 | #ifdef CONFIG_INTERWORKING |
lesl | 0cb0e27 | 2020-10-30 16:58:08 +0800 | [diff] [blame] | 497 | access_network_params_as_string.c_str(), |
lesl | b0f4d54 | 2020-09-16 23:06:03 +0800 | [diff] [blame] | 498 | #endif /* CONFIG_INTERWORKING */ |
lesl | 0cb0e27 | 2020-10-30 16:58:08 +0800 | [diff] [blame] | 499 | encryption_config_as_string.c_str(), |
| 500 | bridge_as_string.c_str()); |
Roshan Pius | 30b452e | 2017-12-27 13:36:21 -0800 | [diff] [blame] | 501 | } |
Roshan Pius | e2d2101 | 2018-08-17 11:22:06 -0700 | [diff] [blame] | 502 | |
lesl | dab9150 | 2020-08-17 18:29:47 +0800 | [diff] [blame] | 503 | Generation getGeneration(hostapd_hw_modes *current_mode) |
| 504 | { |
| 505 | wpa_printf(MSG_DEBUG, "getGeneration hwmode=%d, ht_enabled=%d, vht_enabled=%d", |
| 506 | current_mode->mode, current_mode->ht_capab != 0, |
| 507 | current_mode->vht_capab != 0); |
| 508 | switch (current_mode->mode) { |
| 509 | case HOSTAPD_MODE_IEEE80211B: |
| 510 | return Generation::WIFI_STANDARD_LEGACY; |
| 511 | case HOSTAPD_MODE_IEEE80211G: |
| 512 | return current_mode->ht_capab == 0 ? |
| 513 | Generation::WIFI_STANDARD_LEGACY : Generation::WIFI_STANDARD_11N; |
| 514 | case HOSTAPD_MODE_IEEE80211A: |
| 515 | return current_mode->vht_capab == 0 ? |
| 516 | Generation::WIFI_STANDARD_11N : Generation::WIFI_STANDARD_11AC; |
| 517 | // TODO: b/162484222 miss HOSTAPD_MODE_IEEE80211AX definition. |
| 518 | default: |
| 519 | return Generation::WIFI_STANDARD_UNKNOWN; |
| 520 | } |
| 521 | } |
| 522 | |
| 523 | Bandwidth getBandwidth(struct hostapd_config *iconf) |
| 524 | { |
| 525 | wpa_printf(MSG_DEBUG, "getBandwidth %d, isHT=%d, isHT40=%d", |
| 526 | iconf->vht_oper_chwidth, iconf->ieee80211n, |
| 527 | iconf->secondary_channel); |
| 528 | switch (iconf->vht_oper_chwidth) { |
| 529 | case CHANWIDTH_80MHZ: |
| 530 | return Bandwidth::WIFI_BANDWIDTH_80; |
| 531 | case CHANWIDTH_80P80MHZ: |
| 532 | return Bandwidth::WIFI_BANDWIDTH_80P80; |
| 533 | break; |
| 534 | case CHANWIDTH_160MHZ: |
| 535 | return Bandwidth::WIFI_BANDWIDTH_160; |
| 536 | break; |
| 537 | case CHANWIDTH_USE_HT: |
| 538 | if (iconf->ieee80211n) { |
| 539 | return iconf->secondary_channel != 0 ? |
| 540 | Bandwidth::WIFI_BANDWIDTH_40 : Bandwidth::WIFI_BANDWIDTH_20; |
| 541 | } |
| 542 | return Bandwidth::WIFI_BANDWIDTH_20_NOHT; |
| 543 | default: |
| 544 | return Bandwidth::WIFI_BANDWIDTH_INVALID; |
| 545 | } |
| 546 | } |
| 547 | |
Roshan Pius | e2d2101 | 2018-08-17 11:22:06 -0700 | [diff] [blame] | 548 | // hostapd core functions accept "C" style function pointers, so use global |
| 549 | // functions to pass to the hostapd core function and store the corresponding |
| 550 | // std::function methods to be invoked. |
| 551 | // |
| 552 | // NOTE: Using the pattern from the vendor HAL (wifi_legacy_hal.cpp). |
| 553 | // |
| 554 | // Callback to be invoked once setup is complete |
| 555 | std::function<void(struct hostapd_data*)> on_setup_complete_internal_callback; |
| 556 | void onAsyncSetupCompleteCb(void* ctx) |
| 557 | { |
| 558 | struct hostapd_data* iface_hapd = (struct hostapd_data*)ctx; |
| 559 | if (on_setup_complete_internal_callback) { |
| 560 | on_setup_complete_internal_callback(iface_hapd); |
| 561 | // Invalidate this callback since we don't want this firing |
lesl | 0cb0e27 | 2020-10-30 16:58:08 +0800 | [diff] [blame] | 562 | // again in single AP mode. |
| 563 | if (strlen(iface_hapd->conf->bridge) > 0) { |
| 564 | on_setup_complete_internal_callback = nullptr; |
| 565 | } |
Roshan Pius | e2d2101 | 2018-08-17 11:22:06 -0700 | [diff] [blame] | 566 | } |
| 567 | } |
lesl | d062105 | 2020-08-10 13:54:28 +0800 | [diff] [blame] | 568 | |
| 569 | // Callback to be invoked on hotspot client connection/disconnection |
| 570 | std::function<void(struct hostapd_data*, const u8 *mac_addr, int authorized, |
| 571 | const u8 *p2p_dev_addr)> on_sta_authorized_internal_callback; |
| 572 | void onAsyncStaAuthorizedCb(void* ctx, const u8 *mac_addr, int authorized, |
| 573 | const u8 *p2p_dev_addr) |
| 574 | { |
| 575 | struct hostapd_data* iface_hapd = (struct hostapd_data*)ctx; |
| 576 | if (on_sta_authorized_internal_callback) { |
| 577 | on_sta_authorized_internal_callback(iface_hapd, mac_addr, |
| 578 | authorized, p2p_dev_addr); |
| 579 | } |
| 580 | } |
| 581 | |
lesl | dab9150 | 2020-08-17 18:29:47 +0800 | [diff] [blame] | 582 | std::function<void(struct hostapd_data*, int level, |
| 583 | enum wpa_msg_type type, const char *txt, |
| 584 | size_t len)> on_wpa_msg_internal_callback; |
| 585 | |
| 586 | void onAsyncWpaEventCb(void *ctx, int level, |
| 587 | enum wpa_msg_type type, const char *txt, |
| 588 | size_t len) |
| 589 | { |
| 590 | struct hostapd_data* iface_hapd = (struct hostapd_data*)ctx; |
| 591 | if (on_wpa_msg_internal_callback) { |
| 592 | on_wpa_msg_internal_callback(iface_hapd, level, |
| 593 | type, txt, len); |
| 594 | } |
| 595 | } |
| 596 | |
| 597 | |
Roshan Pius | 30b452e | 2017-12-27 13:36:21 -0800 | [diff] [blame] | 598 | } // namespace |
| 599 | |
Roshan Pius | cc81756 | 2017-12-22 14:45:05 -0800 | [diff] [blame] | 600 | namespace android { |
| 601 | namespace hardware { |
| 602 | namespace wifi { |
| 603 | namespace hostapd { |
lesl | f8b1b40 | 2020-08-04 17:09:39 +0800 | [diff] [blame] | 604 | namespace V1_3 { |
Roshan Pius | cc81756 | 2017-12-22 14:45:05 -0800 | [diff] [blame] | 605 | namespace implementation { |
| 606 | using hidl_return_util::call; |
Roshan Pius | e2d2101 | 2018-08-17 11:22:06 -0700 | [diff] [blame] | 607 | using namespace android::hardware::wifi::hostapd::V1_0; |
Roshan Pius | cc81756 | 2017-12-22 14:45:05 -0800 | [diff] [blame] | 608 | |
Roshan Pius | 80e5a0f | 2020-10-19 13:48:22 -0700 | [diff] [blame] | 609 | Hostapd::Hostapd(struct hapd_interfaces* interfaces) |
| 610 | : interfaces_(interfaces), death_notifier_(sp<DeathNotifier>::make()) |
Roshan Pius | cc81756 | 2017-12-22 14:45:05 -0800 | [diff] [blame] | 611 | {} |
| 612 | |
| 613 | Return<void> Hostapd::addAccessPoint( |
Daisuke Niwa | c1bd20f | 2019-01-09 13:51:02 +0900 | [diff] [blame] | 614 | const V1_0::IHostapd::IfaceParams& iface_params, |
lesl | dd48efd | 2019-12-26 15:13:51 +0800 | [diff] [blame] | 615 | const V1_0::IHostapd::NetworkParams& nw_params, addAccessPoint_cb _hidl_cb) |
Daisuke Niwa | c1bd20f | 2019-01-09 13:51:02 +0900 | [diff] [blame] | 616 | { |
| 617 | return call( |
| 618 | this, &Hostapd::addAccessPointInternal, _hidl_cb, iface_params, |
| 619 | nw_params); |
| 620 | } |
| 621 | |
| 622 | Return<void> Hostapd::addAccessPoint_1_1( |
Ahmed ElArabawy | 3498267 | 2019-12-06 10:10:17 -0800 | [diff] [blame] | 623 | const V1_1::IHostapd::IfaceParams& iface_params, |
lesl | dd48efd | 2019-12-26 15:13:51 +0800 | [diff] [blame] | 624 | const V1_0::IHostapd::NetworkParams& nw_params, addAccessPoint_cb _hidl_cb) |
Roshan Pius | cc81756 | 2017-12-22 14:45:05 -0800 | [diff] [blame] | 625 | { |
| 626 | return call( |
Daisuke Niwa | c1bd20f | 2019-01-09 13:51:02 +0900 | [diff] [blame] | 627 | this, &Hostapd::addAccessPointInternal_1_1, _hidl_cb, iface_params, |
Roshan Pius | cc81756 | 2017-12-22 14:45:05 -0800 | [diff] [blame] | 628 | nw_params); |
| 629 | } |
| 630 | |
Ahmed ElArabawy | 3498267 | 2019-12-06 10:10:17 -0800 | [diff] [blame] | 631 | Return<void> Hostapd::addAccessPoint_1_2( |
lesl | b0f4d54 | 2020-09-16 23:06:03 +0800 | [diff] [blame] | 632 | const V1_2::IHostapd::IfaceParams& iface_params, |
| 633 | const V1_2::IHostapd::NetworkParams& nw_params, |
Ahmed ElArabawy | 3498267 | 2019-12-06 10:10:17 -0800 | [diff] [blame] | 634 | addAccessPoint_1_2_cb _hidl_cb) |
| 635 | { |
| 636 | return call( |
| 637 | this, &Hostapd::addAccessPointInternal_1_2, _hidl_cb, iface_params, |
| 638 | nw_params); |
| 639 | } |
| 640 | |
lesl | b0f4d54 | 2020-09-16 23:06:03 +0800 | [diff] [blame] | 641 | Return<void> Hostapd::addAccessPoint_1_3( |
| 642 | const V1_3::IHostapd::IfaceParams& iface_params, |
| 643 | const V1_3::IHostapd::NetworkParams& nw_params, |
| 644 | addAccessPoint_1_3_cb _hidl_cb) |
| 645 | { |
| 646 | return call( |
| 647 | this, &Hostapd::addAccessPointInternal_1_3, _hidl_cb, iface_params, |
| 648 | nw_params); |
| 649 | } |
| 650 | |
Roshan Pius | cc81756 | 2017-12-22 14:45:05 -0800 | [diff] [blame] | 651 | Return<void> Hostapd::removeAccessPoint( |
| 652 | const hidl_string& iface_name, removeAccessPoint_cb _hidl_cb) |
| 653 | { |
| 654 | return call( |
| 655 | this, &Hostapd::removeAccessPointInternal, _hidl_cb, iface_name); |
| 656 | } |
| 657 | |
Roshan Pius | e2d2101 | 2018-08-17 11:22:06 -0700 | [diff] [blame] | 658 | Return<void> Hostapd::terminate() |
| 659 | { |
Roshan Pius | 3455af4 | 2018-02-01 09:19:49 -0800 | [diff] [blame] | 660 | wpa_printf(MSG_INFO, "Terminating..."); |
| 661 | eloop_terminate(); |
| 662 | return Void(); |
| 663 | } |
| 664 | |
Roshan Pius | e2d2101 | 2018-08-17 11:22:06 -0700 | [diff] [blame] | 665 | Return<void> Hostapd::registerCallback( |
lesl | 1a842e6 | 2019-12-02 19:00:37 +0800 | [diff] [blame] | 666 | const sp<V1_1::IHostapdCallback>& callback, registerCallback_cb _hidl_cb) |
Roshan Pius | e2d2101 | 2018-08-17 11:22:06 -0700 | [diff] [blame] | 667 | { |
| 668 | return call( |
| 669 | this, &Hostapd::registerCallbackInternal, _hidl_cb, callback); |
| 670 | } |
| 671 | |
lesl | f8b1b40 | 2020-08-04 17:09:39 +0800 | [diff] [blame] | 672 | Return<void> Hostapd::registerCallback_1_3( |
| 673 | const sp<V1_3::IHostapdCallback>& callback, registerCallback_1_3_cb _hidl_cb) |
| 674 | { |
| 675 | return call( |
| 676 | this, &Hostapd::registerCallbackInternal_1_3, _hidl_cb, callback); |
| 677 | } |
| 678 | |
lesl | 1a842e6 | 2019-12-02 19:00:37 +0800 | [diff] [blame] | 679 | Return<void> Hostapd::forceClientDisconnect( |
| 680 | const hidl_string& iface_name, const hidl_array<uint8_t, 6>& client_address, |
| 681 | V1_2::Ieee80211ReasonCode reason_code, forceClientDisconnect_cb _hidl_cb) |
| 682 | { |
| 683 | return call( |
| 684 | this, &Hostapd::forceClientDisconnectInternal, _hidl_cb, iface_name, |
| 685 | client_address, reason_code); |
| 686 | } |
| 687 | |
Roger Wang | cede506 | 2019-12-30 12:56:28 +0800 | [diff] [blame] | 688 | Return<void> Hostapd::setDebugParams( |
lesl | f8b1b40 | 2020-08-04 17:09:39 +0800 | [diff] [blame] | 689 | V1_2::DebugLevel level, setDebugParams_cb _hidl_cb) |
Roger Wang | cede506 | 2019-12-30 12:56:28 +0800 | [diff] [blame] | 690 | { |
| 691 | return call( |
| 692 | this, &Hostapd::setDebugParamsInternal, _hidl_cb, level); |
| 693 | } |
lesl | 1a842e6 | 2019-12-02 19:00:37 +0800 | [diff] [blame] | 694 | |
| 695 | V1_0::HostapdStatus Hostapd::addAccessPointInternal( |
Daisuke Niwa | c1bd20f | 2019-01-09 13:51:02 +0900 | [diff] [blame] | 696 | const V1_0::IHostapd::IfaceParams& iface_params, |
lesl | dd48efd | 2019-12-26 15:13:51 +0800 | [diff] [blame] | 697 | const V1_0::IHostapd::NetworkParams& nw_params) |
Daisuke Niwa | c1bd20f | 2019-01-09 13:51:02 +0900 | [diff] [blame] | 698 | { |
lesl | 1a842e6 | 2019-12-02 19:00:37 +0800 | [diff] [blame] | 699 | return {V1_0::HostapdStatusCode::FAILURE_UNKNOWN, ""}; |
Daisuke Niwa | c1bd20f | 2019-01-09 13:51:02 +0900 | [diff] [blame] | 700 | } |
| 701 | |
lesl | 1a842e6 | 2019-12-02 19:00:37 +0800 | [diff] [blame] | 702 | V1_0::HostapdStatus Hostapd::addAccessPointInternal_1_1( |
Ahmed ElArabawy | 3498267 | 2019-12-06 10:10:17 -0800 | [diff] [blame] | 703 | const V1_1::IHostapd::IfaceParams& iface_params, |
lesl | dd48efd | 2019-12-26 15:13:51 +0800 | [diff] [blame] | 704 | const V1_1::IHostapd::NetworkParams& nw_params) |
Ahmed ElArabawy | 3498267 | 2019-12-06 10:10:17 -0800 | [diff] [blame] | 705 | { |
| 706 | return {V1_0::HostapdStatusCode::FAILURE_UNKNOWN, ""}; |
| 707 | } |
| 708 | |
lesl | f8b1b40 | 2020-08-04 17:09:39 +0800 | [diff] [blame] | 709 | V1_2::HostapdStatus Hostapd::addAccessPointInternal_1_2( |
lesl | b0f4d54 | 2020-09-16 23:06:03 +0800 | [diff] [blame] | 710 | const V1_2::IHostapd::IfaceParams& iface_params, |
| 711 | const V1_2::IHostapd::NetworkParams& nw_params) { |
| 712 | return {V1_2::HostapdStatusCode::FAILURE_UNKNOWN, ""}; |
| 713 | } |
| 714 | |
| 715 | V1_2::HostapdStatus Hostapd::addAccessPointInternal_1_3( |
lesl | 0cb0e27 | 2020-10-30 16:58:08 +0800 | [diff] [blame] | 716 | const V1_3::IHostapd::IfaceParams& iface_params, |
lesl | b0f4d54 | 2020-09-16 23:06:03 +0800 | [diff] [blame] | 717 | const V1_3::IHostapd::NetworkParams& nw_params) |
Roshan Pius | cc81756 | 2017-12-22 14:45:05 -0800 | [diff] [blame] | 718 | { |
lesl | 0cb0e27 | 2020-10-30 16:58:08 +0800 | [diff] [blame] | 719 | int channelParamsListSize = iface_params.channelParamsList.size(); |
| 720 | if (channelParamsListSize == 1) { |
| 721 | // Single AP |
| 722 | wpa_printf(MSG_INFO, "AddSingleAccessPoint, iface=%s", |
| 723 | iface_params.V1_2.V1_1.V1_0.ifaceName.c_str()); |
lesl | 3129425 | 2020-11-06 17:06:03 +0800 | [diff] [blame^] | 724 | return addSingleAccessPoint(iface_params, iface_params.channelParamsList[0], |
lesl | 0cb0e27 | 2020-10-30 16:58:08 +0800 | [diff] [blame] | 725 | nw_params, ""); |
| 726 | } else if (channelParamsListSize == 2) { |
| 727 | // Concurrent APs |
| 728 | wpa_printf(MSG_INFO, "AddDualAccessPoint, iface=%s", |
| 729 | iface_params.V1_2.V1_1.V1_0.ifaceName.c_str()); |
| 730 | return addConcurrentAccessPoints(iface_params, nw_params); |
| 731 | } |
| 732 | return {V1_2::HostapdStatusCode::FAILURE_ARGS_INVALID, ""}; |
| 733 | } |
| 734 | |
| 735 | V1_2::HostapdStatus Hostapd::addConcurrentAccessPoints( |
| 736 | const V1_3::IHostapd::IfaceParams& iface_params, const V1_3::IHostapd::NetworkParams& nw_params) |
| 737 | { |
| 738 | int channelParamsListSize = iface_params.channelParamsList.size(); |
| 739 | // Get available interfaces in bridge |
| 740 | std::vector<std::string> managed_interfaces; |
| 741 | std::string br_name = StringPrintf( |
| 742 | "%s", iface_params.V1_2.V1_1.V1_0.ifaceName.c_str()); |
| 743 | if (!GetInterfacesInBridge(br_name, &managed_interfaces)) { |
| 744 | return {V1_2::HostapdStatusCode::FAILURE_UNKNOWN, |
| 745 | "Get interfaces in bridge failed."}; |
| 746 | } |
| 747 | if (managed_interfaces.size() < channelParamsListSize) { |
| 748 | return {V1_2::HostapdStatusCode::FAILURE_UNKNOWN, |
| 749 | "Available interfaces less than requested bands"}; |
| 750 | } |
| 751 | // start BSS on specified bands |
| 752 | for (std::size_t i = 0; i < channelParamsListSize; i ++) { |
lesl | 3129425 | 2020-11-06 17:06:03 +0800 | [diff] [blame^] | 753 | V1_3::IHostapd::IfaceParams iface_params_new = iface_params; |
| 754 | iface_params_new.V1_2.V1_1.V1_0.ifaceName = managed_interfaces[i]; |
lesl | 0cb0e27 | 2020-10-30 16:58:08 +0800 | [diff] [blame] | 755 | V1_2::HostapdStatus status = addSingleAccessPoint( |
lesl | 3129425 | 2020-11-06 17:06:03 +0800 | [diff] [blame^] | 756 | iface_params_new, iface_params.channelParamsList[i], nw_params, br_name); |
lesl | 0cb0e27 | 2020-10-30 16:58:08 +0800 | [diff] [blame] | 757 | if (status.code != V1_2::HostapdStatusCode::SUCCESS) { |
| 758 | wpa_printf(MSG_ERROR, "Failed to addAccessPoint %s", |
| 759 | managed_interfaces[i].c_str()); |
| 760 | return status; |
| 761 | } |
| 762 | } |
| 763 | // Save bridge interface info |
| 764 | br_interfaces_[br_name] = managed_interfaces; |
| 765 | return {V1_2::HostapdStatusCode::SUCCESS, ""}; |
| 766 | } |
| 767 | |
| 768 | V1_2::HostapdStatus Hostapd::addSingleAccessPoint( |
lesl | 3129425 | 2020-11-06 17:06:03 +0800 | [diff] [blame^] | 769 | const V1_3::IHostapd::IfaceParams& iface_params, |
| 770 | const V1_3::IHostapd::ChannelParams& channelParams, |
lesl | 0cb0e27 | 2020-10-30 16:58:08 +0800 | [diff] [blame] | 771 | const V1_3::IHostapd::NetworkParams& nw_params, |
| 772 | const std::string br_name) |
| 773 | { |
lesl | 3129425 | 2020-11-06 17:06:03 +0800 | [diff] [blame^] | 774 | if (hostapd_get_iface(interfaces_, iface_params.V1_2.V1_1.V1_0.ifaceName.c_str())) { |
Roshan Pius | 087d869 | 2017-12-27 14:11:44 -0800 | [diff] [blame] | 775 | wpa_printf( |
| 776 | MSG_ERROR, "Interface %s already present", |
lesl | 3129425 | 2020-11-06 17:06:03 +0800 | [diff] [blame^] | 777 | iface_params.V1_2.V1_1.V1_0.ifaceName.c_str()); |
lesl | f8b1b40 | 2020-08-04 17:09:39 +0800 | [diff] [blame] | 778 | return {V1_2::HostapdStatusCode::FAILURE_IFACE_EXISTS, ""}; |
Roshan Pius | 087d869 | 2017-12-27 14:11:44 -0800 | [diff] [blame] | 779 | } |
lesl | 3129425 | 2020-11-06 17:06:03 +0800 | [diff] [blame^] | 780 | const auto conf_params = CreateHostapdConfig(iface_params, channelParams, nw_params, br_name); |
Roshan Pius | 087d869 | 2017-12-27 14:11:44 -0800 | [diff] [blame] | 781 | if (conf_params.empty()) { |
| 782 | wpa_printf(MSG_ERROR, "Failed to create config params"); |
lesl | f8b1b40 | 2020-08-04 17:09:39 +0800 | [diff] [blame] | 783 | return {V1_2::HostapdStatusCode::FAILURE_ARGS_INVALID, ""}; |
Roshan Pius | 087d869 | 2017-12-27 14:11:44 -0800 | [diff] [blame] | 784 | } |
| 785 | const auto conf_file_path = |
lesl | 3129425 | 2020-11-06 17:06:03 +0800 | [diff] [blame^] | 786 | WriteHostapdConfig(iface_params.V1_2.V1_1.V1_0.ifaceName, conf_params); |
Roshan Pius | 087d869 | 2017-12-27 14:11:44 -0800 | [diff] [blame] | 787 | if (conf_file_path.empty()) { |
| 788 | wpa_printf(MSG_ERROR, "Failed to write config file"); |
lesl | f8b1b40 | 2020-08-04 17:09:39 +0800 | [diff] [blame] | 789 | return {V1_2::HostapdStatusCode::FAILURE_UNKNOWN, ""}; |
Roshan Pius | 087d869 | 2017-12-27 14:11:44 -0800 | [diff] [blame] | 790 | } |
| 791 | std::string add_iface_param_str = StringPrintf( |
lesl | 3129425 | 2020-11-06 17:06:03 +0800 | [diff] [blame^] | 792 | "%s config=%s", iface_params.V1_2.V1_1.V1_0.ifaceName.c_str(), |
Roshan Pius | 087d869 | 2017-12-27 14:11:44 -0800 | [diff] [blame] | 793 | conf_file_path.c_str()); |
| 794 | std::vector<char> add_iface_param_vec( |
| 795 | add_iface_param_str.begin(), add_iface_param_str.end() + 1); |
| 796 | if (hostapd_add_iface(interfaces_, add_iface_param_vec.data()) < 0) { |
| 797 | wpa_printf( |
| 798 | MSG_ERROR, "Adding interface %s failed", |
| 799 | add_iface_param_str.c_str()); |
lesl | f8b1b40 | 2020-08-04 17:09:39 +0800 | [diff] [blame] | 800 | return {V1_2::HostapdStatusCode::FAILURE_UNKNOWN, ""}; |
Roshan Pius | 087d869 | 2017-12-27 14:11:44 -0800 | [diff] [blame] | 801 | } |
| 802 | struct hostapd_data* iface_hapd = |
lesl | 3129425 | 2020-11-06 17:06:03 +0800 | [diff] [blame^] | 803 | hostapd_get_iface(interfaces_, iface_params.V1_2.V1_1.V1_0.ifaceName.c_str()); |
Roshan Pius | 087d869 | 2017-12-27 14:11:44 -0800 | [diff] [blame] | 804 | WPA_ASSERT(iface_hapd != nullptr && iface_hapd->iface != nullptr); |
Roshan Pius | e2d2101 | 2018-08-17 11:22:06 -0700 | [diff] [blame] | 805 | // Register the setup complete callbacks |
| 806 | on_setup_complete_internal_callback = |
| 807 | [this](struct hostapd_data* iface_hapd) { |
| 808 | wpa_printf( |
lesl | 0cb0e27 | 2020-10-30 16:58:08 +0800 | [diff] [blame] | 809 | MSG_INFO, "AP interface setup completed - state %s", |
Roshan Pius | e2d2101 | 2018-08-17 11:22:06 -0700 | [diff] [blame] | 810 | hostapd_state_text(iface_hapd->iface->state)); |
| 811 | if (iface_hapd->iface->state == HAPD_IFACE_DISABLED) { |
| 812 | // Invoke the failure callback on all registered |
| 813 | // clients. |
| 814 | for (const auto& callback : callbacks_) { |
| 815 | callback->onFailure( |
| 816 | iface_hapd->conf->iface); |
| 817 | } |
| 818 | } |
| 819 | }; |
lesl | d062105 | 2020-08-10 13:54:28 +0800 | [diff] [blame] | 820 | |
| 821 | // Rgegister for new client connect/disconnect indication. |
| 822 | on_sta_authorized_internal_callback = |
| 823 | [this](struct hostapd_data* iface_hapd, const u8 *mac_addr, |
| 824 | int authorized, const u8 *p2p_dev_addr) { |
| 825 | wpa_printf(MSG_DEBUG, "notify client " MACSTR " %s", |
| 826 | MAC2STR(mac_addr), |
| 827 | (authorized) ? "Connected" : "Disconnected"); |
lesl | d062105 | 2020-08-10 13:54:28 +0800 | [diff] [blame] | 828 | for (const auto &callback : callbacks_) { |
lesl | 0cb0e27 | 2020-10-30 16:58:08 +0800 | [diff] [blame] | 829 | callback->onConnectedClientsChanged(strlen(iface_hapd->conf->bridge) > 0 ? |
| 830 | iface_hapd->conf->bridge : iface_hapd->conf->iface, |
lesl | d062105 | 2020-08-10 13:54:28 +0800 | [diff] [blame] | 831 | iface_hapd->conf->iface, mac_addr, authorized); |
| 832 | } |
| 833 | }; |
| 834 | |
lesl | dab9150 | 2020-08-17 18:29:47 +0800 | [diff] [blame] | 835 | // Register for wpa_event which used to get channel switch event |
| 836 | on_wpa_msg_internal_callback = |
| 837 | [this](struct hostapd_data* iface_hapd, int level, |
| 838 | enum wpa_msg_type type, const char *txt, |
| 839 | size_t len) { |
| 840 | wpa_printf(MSG_DEBUG, "Receive wpa msg : %s", txt); |
| 841 | if (os_strncmp(txt, WPA_EVENT_CHANNEL_SWITCH, |
| 842 | strlen(WPA_EVENT_CHANNEL_SWITCH)) == 0) { |
| 843 | for (const auto &callback : callbacks_) { |
| 844 | callback->onApInstanceInfoChanged( |
lesl | 0cb0e27 | 2020-10-30 16:58:08 +0800 | [diff] [blame] | 845 | strlen(iface_hapd->conf->bridge) > 0 ? |
| 846 | iface_hapd->conf->bridge : iface_hapd->conf->iface, |
| 847 | iface_hapd->conf->iface, iface_hapd->iface->freq, |
| 848 | getBandwidth(iface_hapd->iconf), |
lesl | 29973f8 | 2020-09-10 22:40:06 +0800 | [diff] [blame] | 849 | getGeneration(iface_hapd->iface->current_mode), |
| 850 | iface_hapd->own_addr); |
lesl | dab9150 | 2020-08-17 18:29:47 +0800 | [diff] [blame] | 851 | } |
| 852 | } |
| 853 | }; |
lesl | d062105 | 2020-08-10 13:54:28 +0800 | [diff] [blame] | 854 | |
| 855 | // Setup callback |
Roshan Pius | e2d2101 | 2018-08-17 11:22:06 -0700 | [diff] [blame] | 856 | iface_hapd->setup_complete_cb = onAsyncSetupCompleteCb; |
| 857 | iface_hapd->setup_complete_cb_ctx = iface_hapd; |
lesl | d062105 | 2020-08-10 13:54:28 +0800 | [diff] [blame] | 858 | iface_hapd->sta_authorized_cb = onAsyncStaAuthorizedCb; |
| 859 | iface_hapd->sta_authorized_cb_ctx = iface_hapd; |
lesl | dab9150 | 2020-08-17 18:29:47 +0800 | [diff] [blame] | 860 | wpa_msg_register_cb(onAsyncWpaEventCb); |
lesl | d062105 | 2020-08-10 13:54:28 +0800 | [diff] [blame] | 861 | |
Roshan Pius | 087d869 | 2017-12-27 14:11:44 -0800 | [diff] [blame] | 862 | if (hostapd_enable_iface(iface_hapd->iface) < 0) { |
| 863 | wpa_printf( |
| 864 | MSG_ERROR, "Enabling interface %s failed", |
lesl | 3129425 | 2020-11-06 17:06:03 +0800 | [diff] [blame^] | 865 | iface_params.V1_2.V1_1.V1_0.ifaceName.c_str()); |
lesl | f8b1b40 | 2020-08-04 17:09:39 +0800 | [diff] [blame] | 866 | return {V1_2::HostapdStatusCode::FAILURE_UNKNOWN, ""}; |
Roshan Pius | 087d869 | 2017-12-27 14:11:44 -0800 | [diff] [blame] | 867 | } |
lesl | f8b1b40 | 2020-08-04 17:09:39 +0800 | [diff] [blame] | 868 | return {V1_2::HostapdStatusCode::SUCCESS, ""}; |
Roshan Pius | cc81756 | 2017-12-22 14:45:05 -0800 | [diff] [blame] | 869 | } |
| 870 | |
lesl | 1a842e6 | 2019-12-02 19:00:37 +0800 | [diff] [blame] | 871 | V1_0::HostapdStatus Hostapd::removeAccessPointInternal(const std::string& iface_name) |
Roshan Pius | cc81756 | 2017-12-22 14:45:05 -0800 | [diff] [blame] | 872 | { |
Roshan Pius | 087d869 | 2017-12-27 14:11:44 -0800 | [diff] [blame] | 873 | std::vector<char> remove_iface_param_vec( |
| 874 | iface_name.begin(), iface_name.end() + 1); |
| 875 | if (hostapd_remove_iface(interfaces_, remove_iface_param_vec.data()) < |
| 876 | 0) { |
| 877 | wpa_printf( |
| 878 | MSG_ERROR, "Removing interface %s failed", |
| 879 | iface_name.c_str()); |
lesl | 1a842e6 | 2019-12-02 19:00:37 +0800 | [diff] [blame] | 880 | return {V1_0::HostapdStatusCode::FAILURE_UNKNOWN, ""}; |
Roshan Pius | 087d869 | 2017-12-27 14:11:44 -0800 | [diff] [blame] | 881 | } |
lesl | 1a842e6 | 2019-12-02 19:00:37 +0800 | [diff] [blame] | 882 | return {V1_0::HostapdStatusCode::SUCCESS, ""}; |
Roshan Pius | cc81756 | 2017-12-22 14:45:05 -0800 | [diff] [blame] | 883 | } |
Roshan Pius | e2d2101 | 2018-08-17 11:22:06 -0700 | [diff] [blame] | 884 | |
lesl | 1a842e6 | 2019-12-02 19:00:37 +0800 | [diff] [blame] | 885 | V1_0::HostapdStatus Hostapd::registerCallbackInternal( |
| 886 | const sp<V1_1::IHostapdCallback>& callback) |
Roshan Pius | e2d2101 | 2018-08-17 11:22:06 -0700 | [diff] [blame] | 887 | { |
lesl | f8b1b40 | 2020-08-04 17:09:39 +0800 | [diff] [blame] | 888 | return {V1_0::HostapdStatusCode::FAILURE_UNKNOWN, ""}; |
| 889 | } |
| 890 | |
| 891 | V1_2::HostapdStatus Hostapd::registerCallbackInternal_1_3( |
| 892 | const sp<V1_3::IHostapdCallback>& callback) |
| 893 | { |
Roshan Pius | 80e5a0f | 2020-10-19 13:48:22 -0700 | [diff] [blame] | 894 | if (!callback->linkToDeath(death_notifier_, 0)) { |
| 895 | wpa_printf( |
| 896 | MSG_ERROR, |
| 897 | "Error registering for death notification for " |
| 898 | "hostapd callback object"); |
| 899 | return {V1_2::HostapdStatusCode::FAILURE_UNKNOWN, ""}; |
| 900 | } |
Roshan Pius | e2d2101 | 2018-08-17 11:22:06 -0700 | [diff] [blame] | 901 | callbacks_.push_back(callback); |
lesl | f8b1b40 | 2020-08-04 17:09:39 +0800 | [diff] [blame] | 902 | return {V1_2::HostapdStatusCode::SUCCESS, ""}; |
lesl | 1a842e6 | 2019-12-02 19:00:37 +0800 | [diff] [blame] | 903 | } |
| 904 | |
| 905 | V1_2::HostapdStatus Hostapd::forceClientDisconnectInternal(const std::string& iface_name, |
| 906 | const std::array<uint8_t, 6>& client_address, V1_2::Ieee80211ReasonCode reason_code) |
| 907 | { |
| 908 | struct hostapd_data *hapd = hostapd_get_iface(interfaces_, iface_name.c_str()); |
| 909 | struct sta_info *sta; |
| 910 | if (!hapd) { |
| 911 | wpa_printf(MSG_ERROR, "Interface %s doesn't exist", iface_name.c_str()); |
| 912 | return {V1_2::HostapdStatusCode::FAILURE_IFACE_UNKNOWN, ""}; |
| 913 | } |
| 914 | for (sta = hapd->sta_list; sta; sta = sta->next) { |
| 915 | int res; |
| 916 | res = memcmp(sta->addr, client_address.data(), ETH_ALEN); |
| 917 | if (res == 0) { |
| 918 | wpa_printf(MSG_INFO, "Force client:" MACSTR " disconnect with reason: %d", |
| 919 | MAC2STR(client_address.data()), (uint16_t) reason_code); |
| 920 | ap_sta_disconnect(hapd, sta, sta->addr, (uint16_t) reason_code); |
| 921 | return {V1_2::HostapdStatusCode::SUCCESS, ""}; |
| 922 | } |
| 923 | } |
| 924 | return {V1_2::HostapdStatusCode::FAILURE_CLIENT_UNKNOWN, ""}; |
Roshan Pius | e2d2101 | 2018-08-17 11:22:06 -0700 | [diff] [blame] | 925 | } |
| 926 | |
lesl | f8b1b40 | 2020-08-04 17:09:39 +0800 | [diff] [blame] | 927 | V1_2::HostapdStatus Hostapd::setDebugParamsInternal(V1_2::DebugLevel level) |
Roger Wang | cede506 | 2019-12-30 12:56:28 +0800 | [diff] [blame] | 928 | { |
| 929 | wpa_debug_level = static_cast<uint32_t>(level); |
| 930 | return {V1_2::HostapdStatusCode::SUCCESS, ""}; |
| 931 | } |
| 932 | |
Roshan Pius | cc81756 | 2017-12-22 14:45:05 -0800 | [diff] [blame] | 933 | } // namespace implementation |
lesl | f8b1b40 | 2020-08-04 17:09:39 +0800 | [diff] [blame] | 934 | } // namespace V1_3 |
Roshan Pius | cc81756 | 2017-12-22 14:45:05 -0800 | [diff] [blame] | 935 | } // namespace hostapd |
| 936 | } // namespace wifi |
| 937 | } // namespace hardware |
| 938 | } // namespace android |