based on android10
Android10版本(应该是从andorid9开始就是这样了)hostap start 关键是hostap.conf的生成。
每次打开hostap, 都会自动生成conf
code如下:
external/wpa_supplicant_8/hostapd/hidl/1.2/hostapd.cpp
531HostapdStatus Hostapd::addAccessPointInternal_1_2(
532 const IfaceParams& iface_params, const NetworkParams& nw_params)
533{
534 if (hostapd_get_iface(interfaces_, iface_params.V1_1.V1_0.ifaceName.c_str())) {
535 wpa_printf(
536 MSG_ERROR, "Interface %s already present",
537 iface_params.V1_1.V1_0.ifaceName.c_str());
538 return {HostapdStatusCode::FAILURE_IFACE_EXISTS, ""};
539 }
540 const auto conf_params = CreateHostapdConfig(iface_params, nw_params);
541 if (conf_params.empty()) {
542 wpa_printf(MSG_ERROR, "Failed to create config params");
543 return {HostapdStatusCode::FAILURE_ARGS_INVALID, ""};
544 }
545 const auto conf_file_path =
546 WriteHostapdConfig(iface_params.V1_1.V1_0.ifaceName, conf_params);
547 if (conf_file_path.empty()) {
548 wpa_printf(MSG_ERROR, "Failed to write config file");
549 return {HostapdStatusCode::FAILURE_UNKNOWN, ""};
550 }
551 std::string add_iface_param_str = StringPrintf(
552 "%s config=%s", iface_params.V1_1.V1_0.ifaceName.c_str(),
553 conf_file_path.c_str());
554 std::vector<char> add_iface_param_vec(
555 add_iface_param_str.begin(), add_iface_param_str.end() + 1);
556 if (hostapd_add_iface(interfaces_, add_iface_param_vec.data()) < 0) {
557 wpa_printf(
558 MSG_ERROR, "Adding interface %s failed",
559 add_iface_param_str.c_str());
560 return {HostapdStatusCode::FAILURE_UNKNOWN, ""};
561 }
562 struct hostapd_data* iface_hapd =
563 hostapd_get_iface(interfaces_, iface_params.V1_1.V1_0.ifaceName.c_str());
564 WPA_ASSERT(iface_hapd != nullptr && iface_hapd->iface != nullptr);
565 // Register the setup complete callbacks
566 on_setup_complete_internal_callback =
567 [this](struct hostapd_data* iface_hapd) {
568 wpa_printf(
569 MSG_DEBUG, "AP interface setup completed - state %s",
570 hostapd_state_text(iface_hapd->iface->state));
571 if (iface_hapd->iface->state == HAPD_IFACE_DISABLED) {
572 // Invoke the failure callback on all registered
573 // clients.
574 for (const auto& callback : callbacks_) {
575 callback->onFailure(
576 iface_hapd->conf->iface);
577 }
578 }
579 };
580 iface_hapd->setup_complete_cb = onAsyncSetupCompleteCb;
581 iface_hapd->setup_complete_cb_ctx = iface_hapd;
582 if (hostapd_enable_iface(iface_hapd->iface) < 0) {
583 wpa_printf(
584 MSG_ERROR, "Enabling interface %s failed",
585 iface_params.V1_1.V1_0.ifaceName.c_str());
586 return {HostapdStatusCode::FAILURE_UNKNOWN, ""};
587 }
588 return {HostapdStatusCode::SUCCESS, ""};
589}