1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <android/hardware/wifi/1.0/IWifi.h>
20 #include <android/hardware/wifi/1.0/IWifiApIface.h>
21 #include <android/hardware/wifi/1.0/IWifiChip.h>
22 #include <android/hardware/wifi/1.0/IWifiNanIface.h>
23 #include <android/hardware/wifi/1.0/IWifiP2pIface.h>
24 #include <android/hardware/wifi/1.0/IWifiRttController.h>
25 #include <android/hardware/wifi/1.0/IWifiStaIface.h>
26 
27 #include <getopt.h>
28 
29 #include <VtsHalHidlTargetTestEnvBase.h>
30 // Helper functions to obtain references to the various HIDL interface objects.
31 // Note: We only have a single instance of each of these objects currently.
32 // These helper functions should be modified to return vectors if we support
33 // multiple instances.
34 // TODO(b/143892896): Remove the default value as part of the cleanup.
35 android::sp<android::hardware::wifi::V1_0::IWifi> getWifi(
36     const std::string& instance_name = "");
37 android::sp<android::hardware::wifi::V1_0::IWifiChip> getWifiChip(
38     const std::string& instance_name = "");
39 android::sp<android::hardware::wifi::V1_0::IWifiApIface> getWifiApIface(
40     const std::string& instance_name = "");
41 android::sp<android::hardware::wifi::V1_0::IWifiNanIface> getWifiNanIface(
42     const std::string& instance_name = "");
43 android::sp<android::hardware::wifi::V1_0::IWifiP2pIface> getWifiP2pIface(
44     const std::string& instance_name = "");
45 android::sp<android::hardware::wifi::V1_0::IWifiStaIface> getWifiStaIface(
46     const std::string& instance_name = "");
47 android::sp<android::hardware::wifi::V1_0::IWifiRttController>
48 getWifiRttController(const std::string& instance_name = "");
49 // Configure the chip in a mode to support the creation of the provided
50 // iface type.
51 bool configureChipToSupportIfaceType(
52     const android::sp<android::hardware::wifi::V1_0::IWifiChip>& wifi_chip,
53     android::hardware::wifi::V1_0::IfaceType type,
54     android::hardware::wifi::V1_0::ChipModeId* configured_mode_id);
55 // Used to trigger IWifi.stop() at the end of every test.
56 void stopWifi(const std::string& instance_name = "");
57 
58 class WifiHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
59    protected:
HidlSetUp()60     virtual void HidlSetUp() override {
61         stopWifi();
62         sleep(5);
63     }
64 
65    public:
66     // Whether NaN feature is supported on the device.
67     bool isNanOn = false;
68     // Whether SoftAp feature is supported on the device.
69     bool isSoftApOn = false;
70 
usage(char * me,char * arg)71     void usage(char* me, char* arg) {
72         fprintf(stderr,
73                 "unrecognized option: %s\n\n"
74                 "usage: %s <gtest options> <test options>\n\n"
75                 "test options are:\n\n"
76                 "-N, --nan_on: Whether NAN feature is supported\n"
77                 "-S, --softap_on: Whether SOFTAP feature is supported\n",
78                 arg, me);
79     }
80 
initFromOptions(int argc,char ** argv)81     int initFromOptions(int argc, char** argv) {
82         static struct option options[] = {{"nan_on", no_argument, 0, 'N'},
83                                           {"softap_on", no_argument, 0, 'S'},
84                                           {0, 0, 0, 0}};
85 
86         int c;
87         while ((c = getopt_long(argc, argv, "NS", options, NULL)) >= 0) {
88             switch (c) {
89                 case 'N':
90                     isNanOn = true;
91                     break;
92                 case 'S':
93                     isSoftApOn = true;
94                     break;
95                 default:
96                     usage(argv[0], argv[optind]);
97                     return 2;
98             }
99         }
100 
101         if (optind < argc) {
102             usage(argv[0], argv[optind]);
103             return 2;
104         }
105 
106         return 0;
107     }
108 };
109