summaryrefslogtreecommitdiff
path: root/wifi/hostapd/1.0/vts/functional/hostapd_hidl_test_utils.cpp
blob: 75d6252cd2bad4ff627c9c6828b54e2e5f1ad40b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <android-base/logging.h>

#include <android/hidl/manager/1.0/IServiceManager.h>
#include <hidl/HidlTransportSupport.h>

#include <wifi_system/hostapd_manager.h>
#include <wifi_system/interface_tool.h>
#include <wifi_system/supplicant_manager.h>

#include "hostapd_hidl_test_utils.h"
#include "wifi_hidl_test_utils.h"

using ::android::sp;
using ::android::hardware::configureRpcThreadpool;
using ::android::hardware::hidl_string;
using ::android::hardware::hidl_vec;
using ::android::hardware::joinRpcThreadpool;
using ::android::hardware::Return;
using ::android::hardware::Void;
using ::android::hardware::wifi::hostapd::V1_0::HostapdStatus;
using ::android::hardware::wifi::hostapd::V1_0::HostapdStatusCode;
using ::android::hardware::wifi::hostapd::V1_0::IHostapd;
using ::android::hardware::wifi::V1_0::ChipModeId;
using ::android::hardware::wifi::V1_0::IWifiChip;
using ::android::wifi_system::HostapdManager;
using ::android::wifi_system::SupplicantManager;

namespace {
// Helper function to initialize the driver and firmware to AP mode
// using the vendor HAL HIDL interface.
void initilializeDriverAndFirmware(const std::string& wifi_instance_name) {
    if (getWifi(wifi_instance_name) != nullptr) {
        sp<IWifiChip> wifi_chip = getWifiChip(wifi_instance_name);
        ChipModeId mode_id;
        EXPECT_TRUE(configureChipToSupportIfaceType(
            wifi_chip, ::android::hardware::wifi::V1_0::IfaceType::AP, &mode_id));
    } else {
        LOG(WARNING) << __func__ << ": Vendor HAL not supported";
    }
}

// Helper function to deinitialize the driver and firmware
// using the vendor HAL HIDL interface.
void deInitilializeDriverAndFirmware(const std::string& wifi_instance_name) {
    if (getWifi(wifi_instance_name) != nullptr) {
        stopWifi(wifi_instance_name);
    } else {
        LOG(WARNING) << __func__ << ": Vendor HAL not supported";
    }
}
}  // namespace

void stopSupplicantIfNeeded(const std::string& instance_name) {
    SupplicantManager supplicant_manager;
    if (supplicant_manager.IsSupplicantRunning()) {
        LOG(INFO) << "Supplicant is running, stop supplicant first.";
        ASSERT_TRUE(supplicant_manager.StopSupplicant());
        deInitilializeDriverAndFirmware(instance_name);
        ASSERT_FALSE(supplicant_manager.IsSupplicantRunning());
    }
}

void stopHostapd(const std::string& instance_name) {
    HostapdManager hostapd_manager;

    ASSERT_TRUE(hostapd_manager.StopHostapd());
    deInitilializeDriverAndFirmware(instance_name);
}

void startHostapdAndWaitForHidlService(
    const std::string& wifi_instance_name,
    const std::string& hostapd_instance_name) {
    initilializeDriverAndFirmware(wifi_instance_name);

    HostapdManager hostapd_manager;
    ASSERT_TRUE(hostapd_manager.StartHostapd());

    // Wait for hostapd service to come up.
    IHostapd::getService(hostapd_instance_name);
}

bool is_1_1(const sp<IHostapd>& hostapd) {
    sp<::android::hardware::wifi::hostapd::V1_1::IHostapd> hostapd_1_1 =
        ::android::hardware::wifi::hostapd::V1_1::IHostapd::castFrom(hostapd);
    return hostapd_1_1.get() != nullptr;
}