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 | { |
| 22 | #include "utils/eloop.h" |
| 23 | } |
| 24 | |
Roshan Pius | 30b452e | 2017-12-27 13:36:21 -0800 | [diff] [blame] | 25 | // The HIDL implementation for hostapd creates a hostapd.conf dynamically for |
| 26 | // each interface. This file can then be used to hook onto the normal config |
| 27 | // file parsing logic in hostapd code. Helps us to avoid duplication of code |
| 28 | // in the HIDL interface. |
| 29 | // TOOD(b/71872409): Add unit tests for this. |
| 30 | namespace { |
| 31 | constexpr char kConfFileNameFmt[] = "/data/vendor/wifi/hostapd/hostapd_%s.conf"; |
| 32 | |
| 33 | using android::base::RemoveFileIfExists; |
| 34 | using android::base::StringPrintf; |
| 35 | using android::base::WriteStringToFile; |
lesl | 1a842e6 | 2019-12-02 19:00:37 +0800 | [diff] [blame] | 36 | using android::hardware::wifi::hostapd::V1_2::IHostapd; |
Roshan Pius | 30b452e | 2017-12-27 13:36:21 -0800 | [diff] [blame] | 37 | |
| 38 | std::string WriteHostapdConfig( |
| 39 | const std::string& interface_name, const std::string& config) |
| 40 | { |
| 41 | const std::string file_path = |
| 42 | StringPrintf(kConfFileNameFmt, interface_name.c_str()); |
| 43 | if (WriteStringToFile( |
| 44 | config, file_path, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP, |
| 45 | getuid(), getgid())) { |
| 46 | return file_path; |
| 47 | } |
| 48 | // Diagnose failure |
| 49 | int error = errno; |
| 50 | wpa_printf( |
| 51 | MSG_ERROR, "Cannot write hostapd config to %s, error: %s", |
| 52 | file_path.c_str(), strerror(error)); |
| 53 | struct stat st; |
| 54 | int result = stat(file_path.c_str(), &st); |
| 55 | if (result == 0) { |
| 56 | wpa_printf( |
| 57 | MSG_ERROR, "hostapd config file uid: %d, gid: %d, mode: %d", |
| 58 | st.st_uid, st.st_gid, st.st_mode); |
| 59 | } else { |
| 60 | wpa_printf( |
| 61 | MSG_ERROR, |
| 62 | "Error calling stat() on hostapd config file: %s", |
| 63 | strerror(errno)); |
| 64 | } |
| 65 | return ""; |
| 66 | } |
| 67 | |
| 68 | std::string CreateHostapdConfig( |
| 69 | const IHostapd::IfaceParams& iface_params, |
| 70 | const IHostapd::NetworkParams& nw_params) |
| 71 | { |
| 72 | if (nw_params.ssid.size() > |
| 73 | static_cast<uint32_t>( |
| 74 | IHostapd::ParamSizeLimits::SSID_MAX_LEN_IN_BYTES)) { |
| 75 | wpa_printf( |
| 76 | MSG_ERROR, "Invalid SSID size: %zu", nw_params.ssid.size()); |
| 77 | return ""; |
| 78 | } |
Roshan Pius | 0b8a64f | 2018-01-23 11:42:34 -0800 | [diff] [blame] | 79 | if ((nw_params.encryptionType != IHostapd::EncryptionType::NONE) && |
| 80 | (nw_params.pskPassphrase.size() < |
| 81 | static_cast<uint32_t>( |
| 82 | IHostapd::ParamSizeLimits:: |
| 83 | WPA2_PSK_PASSPHRASE_MIN_LEN_IN_BYTES) || |
| 84 | nw_params.pskPassphrase.size() > |
| 85 | static_cast<uint32_t>( |
| 86 | IHostapd::ParamSizeLimits:: |
| 87 | WPA2_PSK_PASSPHRASE_MAX_LEN_IN_BYTES))) { |
Roshan Pius | 30b452e | 2017-12-27 13:36:21 -0800 | [diff] [blame] | 88 | wpa_printf( |
| 89 | MSG_ERROR, "Invalid psk passphrase size: %zu", |
| 90 | nw_params.pskPassphrase.size()); |
| 91 | return ""; |
| 92 | } |
| 93 | |
| 94 | // SSID string |
| 95 | std::stringstream ss; |
| 96 | ss << std::hex; |
| 97 | ss << std::setfill('0'); |
| 98 | for (uint8_t b : nw_params.ssid) { |
| 99 | ss << std::setw(2) << static_cast<unsigned int>(b); |
| 100 | } |
| 101 | const std::string ssid_as_string = ss.str(); |
| 102 | |
| 103 | // Encryption config string |
| 104 | std::string encryption_config_as_string; |
| 105 | switch (nw_params.encryptionType) { |
| 106 | case IHostapd::EncryptionType::NONE: |
| 107 | // no security params |
| 108 | break; |
| 109 | case IHostapd::EncryptionType::WPA: |
| 110 | encryption_config_as_string = StringPrintf( |
| 111 | "wpa=3\n" |
| 112 | "wpa_pairwise=TKIP CCMP\n" |
| 113 | "wpa_passphrase=%s", |
| 114 | nw_params.pskPassphrase.c_str()); |
| 115 | break; |
| 116 | case IHostapd::EncryptionType::WPA2: |
| 117 | encryption_config_as_string = StringPrintf( |
| 118 | "wpa=2\n" |
| 119 | "rsn_pairwise=CCMP\n" |
| 120 | "wpa_passphrase=%s", |
| 121 | nw_params.pskPassphrase.c_str()); |
| 122 | break; |
| 123 | default: |
| 124 | wpa_printf(MSG_ERROR, "Unknown encryption type"); |
| 125 | return ""; |
| 126 | } |
| 127 | |
| 128 | std::string channel_config_as_string; |
Ahmed ElArabawy | 3498267 | 2019-12-06 10:10:17 -0800 | [diff] [blame] | 129 | if (iface_params.V1_1.V1_0.channelParams.enableAcs) { |
Daisuke Niwa | c1bd20f | 2019-01-09 13:51:02 +0900 | [diff] [blame] | 130 | std::string chanlist_as_string; |
| 131 | for (const auto &range : |
Ahmed ElArabawy | 3498267 | 2019-12-06 10:10:17 -0800 | [diff] [blame] | 132 | iface_params.V1_1.channelParams.acsChannelRanges) { |
Daisuke Niwa | c1bd20f | 2019-01-09 13:51:02 +0900 | [diff] [blame] | 133 | if (range.start != range.end) { |
| 134 | chanlist_as_string += |
Ahmed ElArabawy | 3498267 | 2019-12-06 10:10:17 -0800 | [diff] [blame] | 135 | StringPrintf("%d-%d ", range.start, range.end); |
Daisuke Niwa | c1bd20f | 2019-01-09 13:51:02 +0900 | [diff] [blame] | 136 | } else { |
| 137 | chanlist_as_string += StringPrintf("%d ", range.start); |
| 138 | } |
| 139 | } |
Roshan Pius | 30b452e | 2017-12-27 13:36:21 -0800 | [diff] [blame] | 140 | channel_config_as_string = StringPrintf( |
| 141 | "channel=0\n" |
Daisuke Niwa | c1bd20f | 2019-01-09 13:51:02 +0900 | [diff] [blame] | 142 | "acs_exclude_dfs=%d\n" |
| 143 | "chanlist=%s", |
Ahmed ElArabawy | 3498267 | 2019-12-06 10:10:17 -0800 | [diff] [blame] | 144 | iface_params.V1_1.V1_0.channelParams.acsShouldExcludeDfs, |
Daisuke Niwa | c1bd20f | 2019-01-09 13:51:02 +0900 | [diff] [blame] | 145 | chanlist_as_string.c_str()); |
Roshan Pius | 30b452e | 2017-12-27 13:36:21 -0800 | [diff] [blame] | 146 | } else { |
| 147 | channel_config_as_string = StringPrintf( |
Ahmed ElArabawy | 3498267 | 2019-12-06 10:10:17 -0800 | [diff] [blame] | 148 | "channel=%d", iface_params.V1_1.V1_0.channelParams.channel); |
Roshan Pius | 30b452e | 2017-12-27 13:36:21 -0800 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | // Hw Mode String |
Ahmed ElArabawy | 3498267 | 2019-12-06 10:10:17 -0800 | [diff] [blame] | 152 | // TODO: b/146186687 Still missing the handling when 6GHz band is included |
Roshan Pius | 30b452e | 2017-12-27 13:36:21 -0800 | [diff] [blame] | 153 | std::string hw_mode_as_string; |
Roshan Pius | 4944647 | 2018-03-07 10:23:46 -0800 | [diff] [blame] | 154 | std::string ht_cap_vht_oper_chwidth_as_string; |
Ahmed ElArabawy | 3498267 | 2019-12-06 10:10:17 -0800 | [diff] [blame] | 155 | unsigned int band = 0; |
lesl | 00ac8a5 | 2020-01-08 15:54:51 +0800 | [diff] [blame] | 156 | band |= iface_params.channelParams.bandMask; |
Ahmed ElArabawy | 3498267 | 2019-12-06 10:10:17 -0800 | [diff] [blame] | 157 | |
| 158 | if ((band & IHostapd::BandMask::BAND_2_GHZ) != 0) { |
| 159 | if ((band & IHostapd::BandMask::BAND_5_GHZ) != 0) { |
| 160 | hw_mode_as_string = "hw_mode=any"; |
| 161 | if (iface_params.V1_1.V1_0.channelParams.enableAcs) { |
| 162 | ht_cap_vht_oper_chwidth_as_string = |
| 163 | "ht_capab=[HT40+]\n" |
| 164 | "vht_oper_chwidth=1"; |
| 165 | } |
| 166 | } else { |
| 167 | hw_mode_as_string = "hw_mode=g"; |
Roshan Pius | 4944647 | 2018-03-07 10:23:46 -0800 | [diff] [blame] | 168 | } |
Ahmed ElArabawy | 3498267 | 2019-12-06 10:10:17 -0800 | [diff] [blame] | 169 | } else { |
| 170 | if ((band & IHostapd::BandMask::BAND_5_GHZ) != 0) { |
| 171 | hw_mode_as_string = "hw_mode=a"; |
| 172 | if (iface_params.V1_1.V1_0.channelParams.enableAcs) { |
| 173 | ht_cap_vht_oper_chwidth_as_string = |
| 174 | "ht_capab=[HT40+]\n" |
| 175 | "vht_oper_chwidth=1"; |
| 176 | } |
| 177 | } else { |
| 178 | wpa_printf(MSG_ERROR, "Invalid band"); |
| 179 | return ""; |
Roshan Pius | 4944647 | 2018-03-07 10:23:46 -0800 | [diff] [blame] | 180 | } |
Roshan Pius | 30b452e | 2017-12-27 13:36:21 -0800 | [diff] [blame] | 181 | } |
| 182 | |
Ahmed ElArabawy | 5362fb1 | 2020-01-02 15:01:31 -0800 | [diff] [blame] | 183 | std::string he_params_as_string; |
| 184 | if (iface_params.hwModeParams.enable80211AX) { |
| 185 | he_params_as_string = StringPrintf( |
| 186 | "ieee80211ax=1\n" |
| 187 | "he_su_beamformer=%d\n" |
| 188 | "he_su_beamformee=%d\n" |
| 189 | "he_mu_beamformer=%d\n" |
| 190 | "he_bss_color=%d\n" |
| 191 | "he_twt_required=%d\n", |
| 192 | iface_params.hwModeParams.enableHeSingleUserBeamformer ? 1 : 0, |
| 193 | iface_params.hwModeParams.enableHeSingleUserBeamformee ? 1 : 0, |
| 194 | iface_params.hwModeParams.enableHeMultiUserBeamformer ? 1 : 0, |
| 195 | iface_params.hwModeParams.heBssColor, |
| 196 | iface_params.hwModeParams.enableHeTargetWakeTime ? 1 : 0); |
| 197 | } else { |
| 198 | he_params_as_string = "ieee80211ax=0"; |
| 199 | } |
| 200 | |
Roshan Pius | 30b452e | 2017-12-27 13:36:21 -0800 | [diff] [blame] | 201 | return StringPrintf( |
| 202 | "interface=%s\n" |
| 203 | "driver=nl80211\n" |
Daichi Ueura | caa74a8 | 2018-02-14 22:25:39 +0900 | [diff] [blame] | 204 | "ctrl_interface=/data/vendor/wifi/hostapd/ctrl\n" |
Roshan Pius | 30b452e | 2017-12-27 13:36:21 -0800 | [diff] [blame] | 205 | // ssid2 signals to hostapd that the value is not a literal value |
| 206 | // for use as a SSID. In this case, we're giving it a hex |
| 207 | // std::string and hostapd needs to expect that. |
| 208 | "ssid2=%s\n" |
| 209 | "%s\n" |
| 210 | "ieee80211n=%d\n" |
| 211 | "ieee80211ac=%d\n" |
Ahmed ElArabawy | 5362fb1 | 2020-01-02 15:01:31 -0800 | [diff] [blame] | 212 | "%s\n" |
Roshan Pius | e453f71 | 2018-02-09 15:49:57 -0800 | [diff] [blame] | 213 | "%s\n" |
Roshan Pius | 4944647 | 2018-03-07 10:23:46 -0800 | [diff] [blame] | 214 | "%s\n" |
Roshan Pius | 30b452e | 2017-12-27 13:36:21 -0800 | [diff] [blame] | 215 | "ignore_broadcast_ssid=%d\n" |
| 216 | "wowlan_triggers=any\n" |
| 217 | "%s\n", |
Ahmed ElArabawy | 3498267 | 2019-12-06 10:10:17 -0800 | [diff] [blame] | 218 | 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] | 219 | channel_config_as_string.c_str(), |
Ahmed ElArabawy | 3498267 | 2019-12-06 10:10:17 -0800 | [diff] [blame] | 220 | iface_params.V1_1.V1_0.hwModeParams.enable80211N ? 1 : 0, |
| 221 | iface_params.V1_1.V1_0.hwModeParams.enable80211AC ? 1 : 0, |
Ahmed ElArabawy | 5362fb1 | 2020-01-02 15:01:31 -0800 | [diff] [blame] | 222 | he_params_as_string.c_str(), |
Roshan Pius | 4944647 | 2018-03-07 10:23:46 -0800 | [diff] [blame] | 223 | hw_mode_as_string.c_str(), ht_cap_vht_oper_chwidth_as_string.c_str(), |
| 224 | nw_params.isHidden ? 1 : 0, encryption_config_as_string.c_str()); |
Roshan Pius | 30b452e | 2017-12-27 13:36:21 -0800 | [diff] [blame] | 225 | } |
Roshan Pius | e2d2101 | 2018-08-17 11:22:06 -0700 | [diff] [blame] | 226 | |
| 227 | // hostapd core functions accept "C" style function pointers, so use global |
| 228 | // functions to pass to the hostapd core function and store the corresponding |
| 229 | // std::function methods to be invoked. |
| 230 | // |
| 231 | // NOTE: Using the pattern from the vendor HAL (wifi_legacy_hal.cpp). |
| 232 | // |
| 233 | // Callback to be invoked once setup is complete |
| 234 | std::function<void(struct hostapd_data*)> on_setup_complete_internal_callback; |
| 235 | void onAsyncSetupCompleteCb(void* ctx) |
| 236 | { |
| 237 | struct hostapd_data* iface_hapd = (struct hostapd_data*)ctx; |
| 238 | if (on_setup_complete_internal_callback) { |
| 239 | on_setup_complete_internal_callback(iface_hapd); |
| 240 | // Invalidate this callback since we don't want this firing |
| 241 | // again. |
| 242 | on_setup_complete_internal_callback = nullptr; |
| 243 | } |
| 244 | } |
Roshan Pius | 30b452e | 2017-12-27 13:36:21 -0800 | [diff] [blame] | 245 | } // namespace |
| 246 | |
Roshan Pius | cc81756 | 2017-12-22 14:45:05 -0800 | [diff] [blame] | 247 | namespace android { |
| 248 | namespace hardware { |
| 249 | namespace wifi { |
| 250 | namespace hostapd { |
lesl | 1a842e6 | 2019-12-02 19:00:37 +0800 | [diff] [blame] | 251 | namespace V1_2 { |
Roshan Pius | cc81756 | 2017-12-22 14:45:05 -0800 | [diff] [blame] | 252 | namespace implementation { |
| 253 | using hidl_return_util::call; |
Roshan Pius | e2d2101 | 2018-08-17 11:22:06 -0700 | [diff] [blame] | 254 | using namespace android::hardware::wifi::hostapd::V1_0; |
Roshan Pius | cc81756 | 2017-12-22 14:45:05 -0800 | [diff] [blame] | 255 | |
| 256 | Hostapd::Hostapd(struct hapd_interfaces* interfaces) : interfaces_(interfaces) |
| 257 | {} |
| 258 | |
| 259 | Return<void> Hostapd::addAccessPoint( |
Daisuke Niwa | c1bd20f | 2019-01-09 13:51:02 +0900 | [diff] [blame] | 260 | const V1_0::IHostapd::IfaceParams& iface_params, |
| 261 | const NetworkParams& nw_params, addAccessPoint_cb _hidl_cb) |
| 262 | { |
| 263 | return call( |
| 264 | this, &Hostapd::addAccessPointInternal, _hidl_cb, iface_params, |
| 265 | nw_params); |
| 266 | } |
| 267 | |
| 268 | Return<void> Hostapd::addAccessPoint_1_1( |
Ahmed ElArabawy | 3498267 | 2019-12-06 10:10:17 -0800 | [diff] [blame] | 269 | const V1_1::IHostapd::IfaceParams& iface_params, |
| 270 | const NetworkParams& nw_params, addAccessPoint_cb _hidl_cb) |
Roshan Pius | cc81756 | 2017-12-22 14:45:05 -0800 | [diff] [blame] | 271 | { |
| 272 | return call( |
Daisuke Niwa | c1bd20f | 2019-01-09 13:51:02 +0900 | [diff] [blame] | 273 | this, &Hostapd::addAccessPointInternal_1_1, _hidl_cb, iface_params, |
Roshan Pius | cc81756 | 2017-12-22 14:45:05 -0800 | [diff] [blame] | 274 | nw_params); |
| 275 | } |
| 276 | |
Ahmed ElArabawy | 3498267 | 2019-12-06 10:10:17 -0800 | [diff] [blame] | 277 | Return<void> Hostapd::addAccessPoint_1_2( |
| 278 | const IfaceParams& iface_params, const NetworkParams& nw_params, |
| 279 | addAccessPoint_1_2_cb _hidl_cb) |
| 280 | { |
| 281 | return call( |
| 282 | this, &Hostapd::addAccessPointInternal_1_2, _hidl_cb, iface_params, |
| 283 | nw_params); |
| 284 | } |
| 285 | |
Roshan Pius | cc81756 | 2017-12-22 14:45:05 -0800 | [diff] [blame] | 286 | Return<void> Hostapd::removeAccessPoint( |
| 287 | const hidl_string& iface_name, removeAccessPoint_cb _hidl_cb) |
| 288 | { |
| 289 | return call( |
| 290 | this, &Hostapd::removeAccessPointInternal, _hidl_cb, iface_name); |
| 291 | } |
| 292 | |
Roshan Pius | e2d2101 | 2018-08-17 11:22:06 -0700 | [diff] [blame] | 293 | Return<void> Hostapd::terminate() |
| 294 | { |
Roshan Pius | 3455af4 | 2018-02-01 09:19:49 -0800 | [diff] [blame] | 295 | wpa_printf(MSG_INFO, "Terminating..."); |
| 296 | eloop_terminate(); |
| 297 | return Void(); |
| 298 | } |
| 299 | |
Roshan Pius | e2d2101 | 2018-08-17 11:22:06 -0700 | [diff] [blame] | 300 | Return<void> Hostapd::registerCallback( |
lesl | 1a842e6 | 2019-12-02 19:00:37 +0800 | [diff] [blame] | 301 | const sp<V1_1::IHostapdCallback>& callback, registerCallback_cb _hidl_cb) |
Roshan Pius | e2d2101 | 2018-08-17 11:22:06 -0700 | [diff] [blame] | 302 | { |
| 303 | return call( |
| 304 | this, &Hostapd::registerCallbackInternal, _hidl_cb, callback); |
| 305 | } |
| 306 | |
lesl | 1a842e6 | 2019-12-02 19:00:37 +0800 | [diff] [blame] | 307 | Return<void> Hostapd::forceClientDisconnect( |
| 308 | const hidl_string& iface_name, const hidl_array<uint8_t, 6>& client_address, |
| 309 | V1_2::Ieee80211ReasonCode reason_code, forceClientDisconnect_cb _hidl_cb) |
| 310 | { |
| 311 | return call( |
| 312 | this, &Hostapd::forceClientDisconnectInternal, _hidl_cb, iface_name, |
| 313 | client_address, reason_code); |
| 314 | } |
| 315 | |
Roger Wang | cede506 | 2019-12-30 12:56:28 +0800 | [diff] [blame] | 316 | Return<void> Hostapd::setDebugParams( |
| 317 | DebugLevel level, setDebugParams_cb _hidl_cb) |
| 318 | { |
| 319 | return call( |
| 320 | this, &Hostapd::setDebugParamsInternal, _hidl_cb, level); |
| 321 | } |
lesl | 1a842e6 | 2019-12-02 19:00:37 +0800 | [diff] [blame] | 322 | |
| 323 | V1_0::HostapdStatus Hostapd::addAccessPointInternal( |
Daisuke Niwa | c1bd20f | 2019-01-09 13:51:02 +0900 | [diff] [blame] | 324 | const V1_0::IHostapd::IfaceParams& iface_params, |
| 325 | const NetworkParams& nw_params) |
| 326 | { |
lesl | 1a842e6 | 2019-12-02 19:00:37 +0800 | [diff] [blame] | 327 | return {V1_0::HostapdStatusCode::FAILURE_UNKNOWN, ""}; |
Daisuke Niwa | c1bd20f | 2019-01-09 13:51:02 +0900 | [diff] [blame] | 328 | } |
| 329 | |
lesl | 1a842e6 | 2019-12-02 19:00:37 +0800 | [diff] [blame] | 330 | V1_0::HostapdStatus Hostapd::addAccessPointInternal_1_1( |
Ahmed ElArabawy | 3498267 | 2019-12-06 10:10:17 -0800 | [diff] [blame] | 331 | const V1_1::IHostapd::IfaceParams& iface_params, |
| 332 | const NetworkParams& nw_params) |
| 333 | { |
| 334 | return {V1_0::HostapdStatusCode::FAILURE_UNKNOWN, ""}; |
| 335 | } |
| 336 | |
| 337 | HostapdStatus Hostapd::addAccessPointInternal_1_2( |
Roshan Pius | cc81756 | 2017-12-22 14:45:05 -0800 | [diff] [blame] | 338 | const IfaceParams& iface_params, const NetworkParams& nw_params) |
| 339 | { |
Ahmed ElArabawy | 3498267 | 2019-12-06 10:10:17 -0800 | [diff] [blame] | 340 | 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] | 341 | wpa_printf( |
| 342 | MSG_ERROR, "Interface %s already present", |
Ahmed ElArabawy | 3498267 | 2019-12-06 10:10:17 -0800 | [diff] [blame] | 343 | iface_params.V1_1.V1_0.ifaceName.c_str()); |
| 344 | return {HostapdStatusCode::FAILURE_IFACE_EXISTS, ""}; |
Roshan Pius | 087d869 | 2017-12-27 14:11:44 -0800 | [diff] [blame] | 345 | } |
| 346 | const auto conf_params = CreateHostapdConfig(iface_params, nw_params); |
| 347 | if (conf_params.empty()) { |
| 348 | wpa_printf(MSG_ERROR, "Failed to create config params"); |
Ahmed ElArabawy | 3498267 | 2019-12-06 10:10:17 -0800 | [diff] [blame] | 349 | return {HostapdStatusCode::FAILURE_ARGS_INVALID, ""}; |
Roshan Pius | 087d869 | 2017-12-27 14:11:44 -0800 | [diff] [blame] | 350 | } |
| 351 | const auto conf_file_path = |
Ahmed ElArabawy | 3498267 | 2019-12-06 10:10:17 -0800 | [diff] [blame] | 352 | WriteHostapdConfig(iface_params.V1_1.V1_0.ifaceName, conf_params); |
Roshan Pius | 087d869 | 2017-12-27 14:11:44 -0800 | [diff] [blame] | 353 | if (conf_file_path.empty()) { |
| 354 | wpa_printf(MSG_ERROR, "Failed to write config file"); |
Ahmed ElArabawy | 3498267 | 2019-12-06 10:10:17 -0800 | [diff] [blame] | 355 | return {HostapdStatusCode::FAILURE_UNKNOWN, ""}; |
Roshan Pius | 087d869 | 2017-12-27 14:11:44 -0800 | [diff] [blame] | 356 | } |
| 357 | std::string add_iface_param_str = StringPrintf( |
Ahmed ElArabawy | 3498267 | 2019-12-06 10:10:17 -0800 | [diff] [blame] | 358 | "%s config=%s", iface_params.V1_1.V1_0.ifaceName.c_str(), |
Roshan Pius | 087d869 | 2017-12-27 14:11:44 -0800 | [diff] [blame] | 359 | conf_file_path.c_str()); |
| 360 | std::vector<char> add_iface_param_vec( |
| 361 | add_iface_param_str.begin(), add_iface_param_str.end() + 1); |
| 362 | if (hostapd_add_iface(interfaces_, add_iface_param_vec.data()) < 0) { |
| 363 | wpa_printf( |
| 364 | MSG_ERROR, "Adding interface %s failed", |
| 365 | add_iface_param_str.c_str()); |
Ahmed ElArabawy | 3498267 | 2019-12-06 10:10:17 -0800 | [diff] [blame] | 366 | return {HostapdStatusCode::FAILURE_UNKNOWN, ""}; |
Roshan Pius | 087d869 | 2017-12-27 14:11:44 -0800 | [diff] [blame] | 367 | } |
| 368 | struct hostapd_data* iface_hapd = |
Ahmed ElArabawy | 3498267 | 2019-12-06 10:10:17 -0800 | [diff] [blame] | 369 | 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] | 370 | WPA_ASSERT(iface_hapd != nullptr && iface_hapd->iface != nullptr); |
Roshan Pius | e2d2101 | 2018-08-17 11:22:06 -0700 | [diff] [blame] | 371 | // Register the setup complete callbacks |
| 372 | on_setup_complete_internal_callback = |
| 373 | [this](struct hostapd_data* iface_hapd) { |
| 374 | wpa_printf( |
| 375 | MSG_DEBUG, "AP interface setup completed - state %s", |
| 376 | hostapd_state_text(iface_hapd->iface->state)); |
| 377 | if (iface_hapd->iface->state == HAPD_IFACE_DISABLED) { |
| 378 | // Invoke the failure callback on all registered |
| 379 | // clients. |
| 380 | for (const auto& callback : callbacks_) { |
| 381 | callback->onFailure( |
| 382 | iface_hapd->conf->iface); |
| 383 | } |
| 384 | } |
| 385 | }; |
| 386 | iface_hapd->setup_complete_cb = onAsyncSetupCompleteCb; |
| 387 | iface_hapd->setup_complete_cb_ctx = iface_hapd; |
Roshan Pius | 087d869 | 2017-12-27 14:11:44 -0800 | [diff] [blame] | 388 | if (hostapd_enable_iface(iface_hapd->iface) < 0) { |
| 389 | wpa_printf( |
| 390 | MSG_ERROR, "Enabling interface %s failed", |
Ahmed ElArabawy | 3498267 | 2019-12-06 10:10:17 -0800 | [diff] [blame] | 391 | iface_params.V1_1.V1_0.ifaceName.c_str()); |
| 392 | return {HostapdStatusCode::FAILURE_UNKNOWN, ""}; |
Roshan Pius | 087d869 | 2017-12-27 14:11:44 -0800 | [diff] [blame] | 393 | } |
Ahmed ElArabawy | 3498267 | 2019-12-06 10:10:17 -0800 | [diff] [blame] | 394 | return {HostapdStatusCode::SUCCESS, ""}; |
Roshan Pius | cc81756 | 2017-12-22 14:45:05 -0800 | [diff] [blame] | 395 | } |
| 396 | |
lesl | 1a842e6 | 2019-12-02 19:00:37 +0800 | [diff] [blame] | 397 | V1_0::HostapdStatus Hostapd::removeAccessPointInternal(const std::string& iface_name) |
Roshan Pius | cc81756 | 2017-12-22 14:45:05 -0800 | [diff] [blame] | 398 | { |
Roshan Pius | 087d869 | 2017-12-27 14:11:44 -0800 | [diff] [blame] | 399 | std::vector<char> remove_iface_param_vec( |
| 400 | iface_name.begin(), iface_name.end() + 1); |
| 401 | if (hostapd_remove_iface(interfaces_, remove_iface_param_vec.data()) < |
| 402 | 0) { |
| 403 | wpa_printf( |
| 404 | MSG_ERROR, "Removing interface %s failed", |
| 405 | iface_name.c_str()); |
lesl | 1a842e6 | 2019-12-02 19:00:37 +0800 | [diff] [blame] | 406 | return {V1_0::HostapdStatusCode::FAILURE_UNKNOWN, ""}; |
Roshan Pius | 087d869 | 2017-12-27 14:11:44 -0800 | [diff] [blame] | 407 | } |
lesl | 1a842e6 | 2019-12-02 19:00:37 +0800 | [diff] [blame] | 408 | return {V1_0::HostapdStatusCode::SUCCESS, ""}; |
Roshan Pius | cc81756 | 2017-12-22 14:45:05 -0800 | [diff] [blame] | 409 | } |
Roshan Pius | e2d2101 | 2018-08-17 11:22:06 -0700 | [diff] [blame] | 410 | |
lesl | 1a842e6 | 2019-12-02 19:00:37 +0800 | [diff] [blame] | 411 | V1_0::HostapdStatus Hostapd::registerCallbackInternal( |
| 412 | const sp<V1_1::IHostapdCallback>& callback) |
Roshan Pius | e2d2101 | 2018-08-17 11:22:06 -0700 | [diff] [blame] | 413 | { |
| 414 | callbacks_.push_back(callback); |
lesl | 1a842e6 | 2019-12-02 19:00:37 +0800 | [diff] [blame] | 415 | return {V1_0::HostapdStatusCode::SUCCESS, ""}; |
| 416 | } |
| 417 | |
| 418 | V1_2::HostapdStatus Hostapd::forceClientDisconnectInternal(const std::string& iface_name, |
| 419 | const std::array<uint8_t, 6>& client_address, V1_2::Ieee80211ReasonCode reason_code) |
| 420 | { |
| 421 | struct hostapd_data *hapd = hostapd_get_iface(interfaces_, iface_name.c_str()); |
| 422 | struct sta_info *sta; |
| 423 | if (!hapd) { |
| 424 | wpa_printf(MSG_ERROR, "Interface %s doesn't exist", iface_name.c_str()); |
| 425 | return {V1_2::HostapdStatusCode::FAILURE_IFACE_UNKNOWN, ""}; |
| 426 | } |
| 427 | for (sta = hapd->sta_list; sta; sta = sta->next) { |
| 428 | int res; |
| 429 | res = memcmp(sta->addr, client_address.data(), ETH_ALEN); |
| 430 | if (res == 0) { |
| 431 | wpa_printf(MSG_INFO, "Force client:" MACSTR " disconnect with reason: %d", |
| 432 | MAC2STR(client_address.data()), (uint16_t) reason_code); |
| 433 | ap_sta_disconnect(hapd, sta, sta->addr, (uint16_t) reason_code); |
| 434 | return {V1_2::HostapdStatusCode::SUCCESS, ""}; |
| 435 | } |
| 436 | } |
| 437 | return {V1_2::HostapdStatusCode::FAILURE_CLIENT_UNKNOWN, ""}; |
Roshan Pius | e2d2101 | 2018-08-17 11:22:06 -0700 | [diff] [blame] | 438 | } |
| 439 | |
Roger Wang | cede506 | 2019-12-30 12:56:28 +0800 | [diff] [blame] | 440 | V1_2::HostapdStatus Hostapd::setDebugParamsInternal(DebugLevel level) |
| 441 | { |
| 442 | wpa_debug_level = static_cast<uint32_t>(level); |
| 443 | return {V1_2::HostapdStatusCode::SUCCESS, ""}; |
| 444 | } |
| 445 | |
Roshan Pius | cc81756 | 2017-12-22 14:45:05 -0800 | [diff] [blame] | 446 | } // namespace implementation |
lesl | 1a842e6 | 2019-12-02 19:00:37 +0800 | [diff] [blame] | 447 | } // namespace V1_2 |
Roshan Pius | cc81756 | 2017-12-22 14:45:05 -0800 | [diff] [blame] | 448 | } // namespace hostapd |
| 449 | } // namespace wifi |
| 450 | } // namespace hardware |
| 451 | } // namespace android |