1// Copyright (C) 2021 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//      http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package {
16    default_applicable_licenses: ["Android-Apache-2.0"],
17}
18
19soong_config_module_type {
20    name: "wifi_cc_defaults",
21    module_type: "cc_defaults",
22    config_namespace: "wifi",
23    bool_variables: [
24        "multiple_vendor_hals", // WIFI_MULTIPLE_VENDOR_HALS
25        "google_wifi_config_lib", // $(wildcard vendor/google/libraries/GoogleWifiConfigLib)
26    ],
27    value_variables: [
28        "driver_module_path", // WIFI_DRIVER_MODULE_PATH
29        "driver_module_arg", // WIFI_DRIVER_MODULE_ARG
30        "driver_module_name", // WIFI_DRIVER_MODULE_NAME
31        "driver_fw_path_sta", // WIFI_DRIVER_FW_PATH_STA
32        "driver_fw_path_ap", // WIFI_DRIVER_FW_PATH_AP
33        "driver_fw_path_p2p", // WIFI_DRIVER_FW_PATH_P2P
34        "driver_fw_path_param", // WIFI_DRIVER_FW_PATH_PARAM
35        "driver_state_ctrl_param", // WIFI_DRIVER_STATE_CTRL_PARAM
36        "driver_state_on", // WIFI_DRIVER_STATE_ON
37        "driver_state_off", // WIFI_DRIVER_STATE_OFF
38    ],
39    variables: [
40        "board_wlan_device", // BOARD_WLAN_DEVICE
41    ],
42    properties: [
43        "cflags",
44        "defaults",
45        "shared_libs",
46        "srcs",
47        "static_libs",
48        "whole_static_libs",
49    ],
50}
51
52soong_config_string_variable {
53    name: "board_wlan_device",
54    values: [
55        "bcmdhd",
56        "synadhd",
57        "qcwcn",
58        "mrvl",
59        "nxp",
60        "MediaTek",
61        "realtek",
62        "emulator",
63        "rtl",
64        "slsi",
65        "wlan0",
66        "unisoc",
67    ],
68}
69
70wifi_cc_defaults {
71    name: "libwifi_hal_cflags_defaults",
72    cflags: [
73        "-Wall",
74        "-Werror",
75        "-Wextra",
76        "-Winit-self",
77        "-Wno-unused-function",
78        "-Wno-unused-parameter",
79        "-Wshadow",
80        "-Wunused-variable",
81        "-Wwrite-strings",
82    ],
83    soong_config_variables: {
84        driver_module_path: {
85            cflags: ["-DWIFI_DRIVER_MODULE_PATH=%s"],
86        },
87        driver_module_arg: {
88            cflags: ["-DWIFI_DRIVER_MODULE_ARG=%s"],
89        },
90        driver_module_name: {
91            cflags: ["-DWIFI_DRIVER_MODULE_NAME=%s"],
92        },
93        driver_fw_path_sta: {
94            cflags: ["-DWIFI_DRIVER_FW_PATH_STA=%s"],
95        },
96        driver_fw_path_ap: {
97            cflags: ["-DWIFI_DRIVER_FW_PATH_AP=%s"],
98        },
99        driver_fw_path_p2p: {
100            cflags: ["-DWIFI_DRIVER_FW_PATH_P2P=%s"],
101        },
102        // Some devices use a different path (e.g. devices with broadcom WiFi parts).
103        driver_fw_path_param: {
104            cflags: ["-DWIFI_DRIVER_FW_PATH_PARAM=%s"],
105            conditions_default: {
106                cflags: ["-DWIFI_DRIVER_FW_PATH_PARAM=\"/sys/module/wlan/parameters/fwpath\""],
107            },
108        },
109        driver_state_ctrl_param: {
110            cflags: ["-DWIFI_DRIVER_STATE_CTRL_PARAM=%s"],
111        },
112        driver_state_on: {
113            cflags: ["-DWIFI_DRIVER_STATE_ON=%s"],
114        },
115        driver_state_off: {
116            cflags: ["-DWIFI_DRIVER_STATE_OFF=%s"],
117        },
118        multiple_vendor_hals: {
119            cflags: ["-DWIFI_MULTIPLE_VENDOR_HALS"],
120        },
121    },
122}
123
124// Common code shared between the HALs.
125cc_library_static {
126    name: "libwifi-hal-common",
127    vendor: true,
128    defaults: ["libwifi_hal_cflags_defaults"],
129    srcs: ["wifi_hal_common.cpp"],
130    shared_libs: ["libbase"],
131    header_libs: ["libcutils_headers"],
132    local_include_dirs: ["include"],
133}
134
135// A fallback "vendor" HAL library.
136// Don't link this, link libwifi-hal.
137cc_library_static {
138    name: "libwifi-hal-fallback",
139    vendor: true,
140    defaults: ["libwifi_hal_cflags_defaults"],
141    srcs: ["wifi_hal_fallback.cpp"],
142    header_libs: ["wifi_legacy_headers"],
143}
144
145wifi_cc_defaults {
146    name: "google_wifi_config_lib_defaults",
147    soong_config_variables: {
148        google_wifi_config_lib: {
149            shared_libs: ["google_wifi_firmware_config_version_c_wrapper"],
150        },
151    },
152}
153
154wifi_cc_defaults {
155    name: "libwifi_hal_vendor_impl_defaults",
156    soong_config_variables: {
157        board_wlan_device: {
158            bcmdhd: {
159                whole_static_libs: ["libwifi-hal-bcm"],
160            },
161            synadhd: {
162                whole_static_libs: ["libwifi-hal-syna"],
163            },
164            qcwcn: {
165                defaults: ["libwifi-hal-qcom"],
166            },
167            mrvl: {
168                // this is commented because none of the nexus devices
169                // that sport Marvell's wifi have support for HAL
170                // whole_static_libs: ["libwifi-hal-mrvl"],
171            },
172            mediaTek: {
173                defaults: ["libwifi-hal-mediatek"],
174            },
175            nxp: {
176                whole_static_libs: ["libwifi-hal-nxp"],
177            },
178            realtek: {
179                whole_static_libs: ["libwifi-hal-rtk"],
180            },
181            emulator: {
182                whole_static_libs: ["//device/generic/goldfish:libwifi-hal-emu"],
183            },
184            slsi: {
185                whole_static_libs: ["libwifi-hal-slsi"],
186            },
187            unisoc: {
188                whole_static_libs: ["libwifi-hal-uni"],
189            },
190            conditions_default: {
191                whole_static_libs: ["libwifi-hal-fallback"],
192            },
193        },
194    },
195}
196
197wifi_cc_defaults {
198    name: "libwifi_hal_vendor_deps_defaults",
199    soong_config_variables: {
200        board_wlan_device: {
201            bcmdhd: {
202                shared_libs: ["libcrypto"],
203                defaults: ["google_wifi_config_lib_defaults"],
204            },
205            synadhd: {
206                shared_libs: ["libcrypto"],
207                defaults: ["google_wifi_config_lib_defaults"],
208            },
209        },
210    },
211}
212
213cc_library_shared {
214    name: "libwifi-hal",
215    proprietary: true,
216    compile_multilib: "first",
217    defaults: [
218        "libwifi_hal_cflags_defaults",
219        "libwifi_hal_vendor_deps_defaults", // shared_libs used by libwifi-hal-<vendor>
220        "libwifi_hal_vendor_impl_defaults",
221    ],
222    local_include_dirs: ["include"],
223    export_include_dirs: ["include"],
224    header_libs: ["wifi_legacy_headers"],
225    export_header_lib_headers: ["wifi_legacy_headers"],
226    shared_libs: [
227        "libbase",
228        "libcutils",
229        "liblog",
230        "libnl",
231        "libutils",
232    ],
233    srcs: [
234        "driver_tool.cpp",
235        "hal_tool.cpp",
236    ],
237    whole_static_libs: ["libwifi-hal-common"],
238    // b/242259479 remove this
239    sanitize: {
240        cfi: true,
241        integer_overflow: true,
242    },
243}
244