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