1 /* 2 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. 3 * 4 * HDF is dual licensed: you can use it either under the terms of 5 * the GPL, or the BSD license, at your option. 6 * See the LICENSE file in the root of this repository for complete details. 7 */ 8 9 /** 10 * @addtogroup WLAN 11 * @{ 12 * 13 * @brief Provides cross-OS migration, component adaptation, and modular assembly and compilation. 14 * 15 * Based on the unified APIs provided by the WLAN module, developers of the Hardware Driver Interface 16 * (HDI) are capable of creating, disabling, scanning for, and connecting to WLAN hotspots, managing WLAN chips, 17 * network devices, and power, and applying for, releasing, and moving network data buffers. 18 * 19 * @since 1.0 20 * @version 1.0 21 */ 22 23 /** 24 * @file wifi_module.h 25 * 26 * @brief Provides features of the WLAN module and functions to create and delete modules. 27 * 28 * The {@link WifiModule} object is a core abstraction of the WLAN driver. It contains a module that communicates 29 * with user-level processes and also contains features. 30 * 31 * @since 1.0 32 * @version 1.0 33 */ 34 35 #ifndef HDFLITE_WIFI_MODULE_H 36 #define HDFLITE_WIFI_MODULE_H 37 38 #include "wifi_inc.h" 39 #include "wifi_module_config.h" 40 #include "net_device.h" 41 42 #ifdef __cplusplus 43 extern "C" { 44 #endif 45 46 /** 47 * @brief Defines a WLAN feature. 48 * 49 * @since 1.0 50 * @version 1.0 51 */ 52 struct WifiFeature { 53 char name[MAX_WIFI_COMPONENT_NAME_LEN]; /**< Feature name, which contains a maximum of 10 characters */ 54 /** 55 * @brief Initializes a feature. 56 * 57 * @param feature Indicates the pointer to the feature. 58 * 59 * @return Returns <b>0</b> if the feature is initialized; returns a negative value otherwise. 60 * 61 * @since 1.0 62 * @version 1.0 63 */ 64 int32_t (*init)(struct WifiFeature *feature); 65 66 /** 67 * @brief Deinitializes a feature. 68 * 69 * @param feature Indicates the pointer to the feature. 70 * 71 * @return Returns <b>0</b> if the feature is deinitialized; returns a negative value otherwise. 72 * 73 * @since 1.0 74 * @version 1.0 75 */ 76 int32_t (*deInit)(struct WifiFeature *feature); 77 }; 78 79 /** 80 * @brief Defines the WLAN feature list. 81 * 82 * @since 1.0 83 * @version 1.0 84 */ 85 struct WifiFeatureList { 86 struct WifiFeature *fe[HDF_WIFI_FEATURE_NUM]; /**< An array of WLAN features */ 87 }; 88 89 /** 90 * @brief Defines WLAN module APIs. 91 * 92 * The APIs can be used to obtain, initialize, update, and perform other operations on a WLAN module. 93 * 94 * @since 1.0 95 * @version 1.0 96 */ 97 struct WifiModuleIface { 98 /** 99 * @brief Deinitializes a WLAN module. 100 * 101 * @param module Indicates the pointer to the WLAN module. 102 * 103 * @return Returns <b>0</b> if the WLAN module is deinitialized; returns a negative value otherwise. 104 * 105 * @since 1.0 106 * @version 1.0 107 */ 108 int32_t (*deInit)(struct WifiModule *module); 109 110 /** 111 * @brief Adds a feature. 112 * 113 * @param module Indicates the pointer to the WLAN module. 114 * @param featureType Indicates the feature type. 115 * @param feature Indicates the pointer to the feature. 116 * 117 * @return Returns <b>0</b> if the feature is added; returns a negative value otherwise. 118 * 119 * @since 1.0 120 * @version 1.0 121 */ 122 int32_t (*addFeature)(struct WifiModule *module, uint16_t featureType, struct WifiFeature *feature); 123 124 /** 125 * @brief Deletes a feature. 126 * 127 * @param module Indicates the pointer to the WLAN module. 128 * @param featureType Indicates the feature type. 129 * 130 * @return Returns <b>0</b> if the feature is deleted; returns a negative value otherwise. 131 * 132 * @since 1.0 133 * @version 1.0 134 */ 135 int32_t (*delFeature)(struct WifiModule *module, uint16_t featureType); 136 }; 137 138 /** 139 * @brief Defines the WLAN module. 140 * 141 * The structure contains private data, APIs, module configurations, a module that communicates with user-level 142 * processes, and WLAN features. 143 * 144 * @since 1.0 145 * @version 1.0 146 */ 147 struct WifiModule { 148 void *modulePrivate; /**< Private data */ 149 struct WifiModuleIface iface; /**< APIs */ 150 struct WifiModuleConfig moduleConfig; /**< Module configurations */ 151 struct WifiFeatureList feList; /**< WLAN features */ 152 }; 153 154 /** 155 * @brief Defines a WLAN chip driver. 156 * 157 * @since 1.0 158 * @version 1.0 159 */ 160 struct HdfChipDriver { 161 uint16_t type; /**< Chip type */ 162 char name[MAX_WIFI_COMPONENT_NAME_LEN]; /**< Chip name */ 163 struct HdfMac80211BaseOps *ops; /**< MAC address for the basic feature */ 164 struct HdfMac80211STAOps *staOps; /**< MAC address for the STA feature */ 165 struct HdfMac80211APOps *apOps; /**< MAC address for the AP feature */ 166 struct HdfMac80211P2POps *p2pOps; /**< MAC address for the P2Pfeature */ 167 void *priv; /**< Private data of the chip driver */ 168 /** 169 * @brief Initializes a chip driver. 170 * 171 * @param chipDriver Indicates the pointer to the chip driver. 172 * @param netDev Indicates the pointer to the network device structure obtained during initialization. 173 * 174 * @return Returns <b>0</b> if the chip is initialized; returns a negative value otherwise. 175 * 176 * @since 1.0 177 * @version 1.0 178 */ 179 int32_t (*init)(struct HdfChipDriver *chipDriver, NetDevice *netDev); 180 181 /** 182 * @brief Deinitializes a chip driver. 183 * 184 * @param chipDriver Indicates the pointer to the chip driver. 185 * @param netDev Indicates the pointer to the network device structure obtained during initialization. 186 * 187 * @return Returns <b>0</b> if the chip is deinitialized; returns a negative value otherwise. 188 * 189 * @since 1.0 190 * @version 1.0 191 */ 192 int32_t (*deinit)(struct HdfChipDriver *chipDriver, NetDevice *netDev); 193 }; 194 195 /** 196 * @brief Initializes a <b>WifiModule</b> object. 197 * 198 * @param module Indicates the pointer to the <b>WifiModule</b> object to initialize. 199 * @param config Indicates the pointer to the configuration generated by the HDF Configuration Source (HCS). 200 * 201 * @return Returns <b>0</b> if the <b>WifiModule</b> object is initialized; returns a negative value otherwise. 202 * 203 * @since 1.0 204 * @version 1.0 205 */ 206 int16_t InitWifiModule(struct WifiModule *module, const struct HdfConfigWlanModuleConfig *config); 207 208 #define RETURN_IF_CHIPOPS_NOT_IMPLEMENT(chipOps, opsName) \ 209 do { \ 210 if ((chipOps) == NULL || (chipOps)->opsName == NULL) { \ 211 HDF_LOGE("macOps" #opsName "not implement"); \ 212 return HDF_ERR_INVALID_OBJECT; \ 213 } \ 214 } while (0) 215 216 217 #ifdef __cplusplus 218 } 219 #endif 220 221 #endif // HDFLITE_WIFI_MODULE_H 222 /** @} */ 223