1 /*
2  * Copyright (C) 2020 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 #ifndef WIFI_LEGACY_HAL_FACTORY_H_
18 #define WIFI_LEGACY_HAL_FACTORY_H_
19 
20 #include <wifi_system/interface_tool.h>
21 
22 #include "wifi_legacy_hal.h"
23 
24 namespace android {
25 namespace hardware {
26 namespace wifi {
27 namespace V1_5 {
28 namespace implementation {
29 // This is in a separate namespace to prevent typename conflicts between
30 // the legacy HAL types and the HIDL interface types.
31 namespace legacy_hal {
32 /**
33  * Class that creates WifiLegacyHal objects for vendor HALs in the system.
34  */
35 class WifiLegacyHalFactory {
36    public:
37     WifiLegacyHalFactory(
38         const std::weak_ptr<wifi_system::InterfaceTool> iface_tool);
39     virtual ~WifiLegacyHalFactory() = default;
40 
41     std::vector<std::shared_ptr<WifiLegacyHal>> getHals();
42 
43    private:
44     typedef struct {
45         wifi_hal_fn fn;
46         bool primary;
47         void* handle;
48     } wifi_hal_lib_desc;
49 
50     bool initVendorHalDescriptorFromLinked();
51     void initVendorHalsDescriptorList();
52     bool initLinkedHalFunctionTable(wifi_hal_fn* hal_fn);
53     bool loadVendorHalLib(const std::string& path, wifi_hal_lib_desc& desc);
54 
55     std::weak_ptr<wifi_system::InterfaceTool> iface_tool_;
56     std::vector<wifi_hal_lib_desc> descs_;
57     std::vector<std::shared_ptr<WifiLegacyHal>> legacy_hals_;
58 };
59 
60 }  // namespace legacy_hal
61 }  // namespace implementation
62 }  // namespace V1_5
63 }  // namespace wifi
64 }  // namespace hardware
65 }  // namespace android
66 
67 #endif  // WIFI_LEGACY_HAL_FACTORY_H_
68