1 /* 2 * Copyright (c) 2012-2021 The Linux Foundation. All rights reserved. 3 * Copyright (c) 2021-2023 Qualcomm Innovation Center, Inc. All rights reserved. 4 * 5 * Permission to use, copy, modify, and/or distribute this software for 6 * any purpose with or without fee is hereby granted, provided that the 7 * above copyright notice and this permission notice appear in all 8 * copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 11 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 12 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 13 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 14 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 15 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 16 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 17 * PERFORMANCE OF THIS SOFTWARE. 18 */ 19 20 /** 21 * DOC: contains declaration of common utility APIs and private structs to be 22 * used in NAN modules 23 */ 24 25 #ifdef WLAN_FEATURE_NAN 26 #ifndef _WLAN_NAN_MAIN_I_H_ 27 #define _WLAN_NAN_MAIN_I_H_ 28 29 #include "qdf_types.h" 30 #include "qdf_status.h" 31 #include "nan_public_structs.h" 32 #include "wlan_objmgr_cmn.h" 33 #include "cfg_nan.h" 34 #include "sir_mac_prot_def.h" 35 36 struct wlan_objmgr_vdev; 37 struct wlan_objmgr_psoc; 38 struct scheduler_msg; 39 40 #define nan_alert(params...) \ 41 QDF_TRACE_FATAL(QDF_MODULE_ID_NAN, params) 42 #define nan_err(params...) \ 43 QDF_TRACE_ERROR(QDF_MODULE_ID_NAN, params) 44 #define nan_warn(params...) \ 45 QDF_TRACE_WARN(QDF_MODULE_ID_NAN, params) 46 #define nan_notice(params...) \ 47 QDF_TRACE_INFO(QDF_MODULE_ID_NAN, params) 48 #define nan_info(params...) \ 49 QDF_TRACE_INFO(QDF_MODULE_ID_NAN, params) 50 #define nan_debug(params...) \ 51 QDF_TRACE_DEBUG(QDF_MODULE_ID_NAN, params) 52 53 #define nan_nofl_alert(params...) \ 54 QDF_TRACE_FATAL_NO_FL(QDF_MODULE_ID_NAN, params) 55 #define nan_nofl_err(params...) \ 56 QDF_TRACE_ERROR_NO_FL(QDF_MODULE_ID_NAN, params) 57 #define nan_nofl_warn(params...) \ 58 QDF_TRACE_WARN_NO_FL(QDF_MODULE_ID_NAN, params) 59 #define nan_nofl_info(params...) \ 60 QDF_TRACE_INFO_NO_FL(QDF_MODULE_ID_NAN, params) 61 #define nan_nofl_debug(params...) \ 62 QDF_TRACE_DEBUG_NO_FL(QDF_MODULE_ID_NAN, params) 63 64 #define nan_alert_rl(params...) \ 65 QDF_TRACE_FATAL_RL(QDF_MODULE_ID_NAN, params) 66 #define nan_err_rl(params...) \ 67 QDF_TRACE_ERROR_RL(QDF_MODULE_ID_NAN, params) 68 #define nan_warn_rl(params...) \ 69 QDF_TRACE_WARN_RL(QDF_MODULE_ID_NAN, params) 70 #define nan_info_rl(params...) \ 71 QDF_TRACE_INFO_RL(QDF_MODULE_ID_NAN, params) 72 #define nan_debug_rl(params...) \ 73 QDF_TRACE_DEBUG_RL(QDF_MODULE_ID_NAN, params) 74 75 /** 76 * enum nan_disc_state - NAN Discovery states 77 * @NAN_DISC_DISABLED: NAN Discovery is disabled 78 * @NAN_DISC_ENABLE_IN_PROGRESS: NAN Discovery enable is in progress 79 * @NAN_DISC_ENABLED: NAN Discovery is enabled 80 * @NAN_DISC_DISABLE_IN_PROGRESS: NAN Discovery disable is in progress 81 */ 82 enum nan_disc_state { 83 NAN_DISC_DISABLED, 84 NAN_DISC_ENABLE_IN_PROGRESS, 85 NAN_DISC_ENABLED, 86 NAN_DISC_DISABLE_IN_PROGRESS, 87 }; 88 89 /** 90 * struct nan_cfg_params - NAN INI config params 91 * @enable: NAN feature enable 92 * @dp_enable: NAN Datapath feature enable 93 * @ndi_mac_randomize: Randomize NAN datapath interface MAC 94 * @ndp_inactivity_timeout: NDP inactivity timeout 95 * @nan_separate_iface_support: To supports separate iface creation for NAN 96 * @ndp_keep_alive_period: To configure duration of how many seconds to 97 * wait to kickout peer if peer is not reachable 98 * @support_mp0_discovery: To support discovery of NAN cluster with Master 99 * Preference (MP) as 0 when a new device is enabling NAN 100 * @max_ndp_sessions: max ndp sessions host supports 101 * @max_ndi: max number of ndi host supports 102 * @nan_feature_config: Bitmap to enable/disable a particular NAN feature 103 * configuration in firmware. It's sent to firmware through 104 * wmi_vdev_param_enable_disable_nan_config_features 105 * @disable_6g_nan: Disable NAN in 6GHz frequency band 106 * @enable_nan_eht_cap: Enable(1)/Disable(0) NAN EHT capability 107 */ 108 struct nan_cfg_params { 109 bool enable; 110 bool dp_enable; 111 bool ndi_mac_randomize; 112 uint16_t ndp_inactivity_timeout; 113 bool nan_separate_iface_support; 114 uint16_t ndp_keep_alive_period; 115 bool support_mp0_discovery; 116 uint32_t max_ndp_sessions; 117 uint32_t max_ndi; 118 uint32_t nan_feature_config; 119 bool disable_6g_nan; 120 bool enable_nan_eht_cap; 121 }; 122 123 /** 124 * struct nan_psoc_priv_obj - nan private psoc obj 125 * @lock: lock to be acquired before reading or writing to object 126 * @cb_obj: struct containing callback pointers 127 * @cfg_param: NAN Config parameters in INI 128 * @nan_caps: NAN Target capabilities 129 * @tx_ops: Tx ops registered with Target IF interface 130 * @rx_ops: Rx ops registered with Target IF interface 131 * @disc_state: Present NAN Discovery state 132 * @nan_social_ch_2g_freq: NAN 2G Social channel for discovery 133 * @nan_social_ch_5g_freq: NAN 5G Social channel for discovery 134 * @nan_disc_mac_id: MAC id used for NAN Discovery 135 * @is_explicit_disable: Flag to indicate that NAN is being explicitly 136 * disabled by driver or user-space 137 * @ndp_request_ctx: NDP request context 138 * @nan_disc_request_ctx: NAN discovery enable/disable request context 139 */ 140 struct nan_psoc_priv_obj { 141 qdf_spinlock_t lock; 142 struct nan_callbacks cb_obj; 143 struct nan_cfg_params cfg_param; 144 struct nan_tgt_caps nan_caps; 145 struct wlan_nan_tx_ops tx_ops; 146 struct wlan_nan_rx_ops rx_ops; 147 enum nan_disc_state disc_state; 148 uint32_t nan_social_ch_2g_freq; 149 uint32_t nan_social_ch_5g_freq; 150 uint8_t nan_disc_mac_id; 151 bool is_explicit_disable; 152 void *ndp_request_ctx; 153 void *nan_disc_request_ctx; 154 }; 155 156 /** 157 * struct nan_vdev_priv_obj - nan private vdev obj 158 * @lock: lock to be acquired before reading or writing to object 159 * @state: Current state of NDP 160 * @active_ndp_peers: number of active ndp peers 161 * @ndp_create_transaction_id: transaction id for create req 162 * @ndp_delete_transaction_id: transaction id for delete req 163 * @ndi_delete_rsp_reason: reason code for ndi_delete rsp 164 * @ndi_delete_rsp_status: status for ndi_delete rsp 165 * @primary_peer_mac: Primary NDP Peer mac address for the vdev 166 * @disable_context: Disable all NDP's operation context 167 * @ndp_init_done: Flag to indicate NDP initialization complete after first peer 168 * connection. 169 * @peer_mc_addr_list: Peer multicast address list 170 */ 171 struct nan_vdev_priv_obj { 172 qdf_spinlock_t lock; 173 enum nan_datapath_state state; 174 uint32_t active_ndp_peers; 175 uint16_t ndp_create_transaction_id; 176 uint16_t ndp_delete_transaction_id; 177 uint32_t ndi_delete_rsp_reason; 178 uint32_t ndi_delete_rsp_status; 179 struct qdf_mac_addr primary_peer_mac; 180 void *disable_context; 181 bool ndp_init_done; 182 struct qdf_mac_addr peer_mc_addr_list[MAX_NDP_SESSIONS]; 183 }; 184 185 /** 186 * struct nan_peer_priv_obj - nan private peer obj 187 * @lock: lock to be acquired before reading or writing to object 188 * @active_ndp_sessions: number of active ndp sessions for this peer 189 * @home_chan_info: Home channel info for the NDP associated with the Peer 190 */ 191 struct nan_peer_priv_obj { 192 qdf_spinlock_t lock; 193 uint32_t active_ndp_sessions; 194 struct nan_datapath_channel_info home_chan_info; 195 }; 196 197 /** 198 * nan_release_cmd: frees resources for NAN command. 199 * @in_req: pointer to msg buffer to be freed 200 * @req_type: type of request 201 * 202 * Return: None 203 */ 204 void nan_release_cmd(void *in_req, uint32_t req_type); 205 206 /** 207 * nan_scheduled_msg_handler: callback pointer to be called when scheduler 208 * starts executing enqueued NAN command. 209 * @msg: pointer to msg 210 * 211 * Return: status of operation 212 */ 213 QDF_STATUS nan_scheduled_msg_handler(struct scheduler_msg *msg); 214 215 /** 216 * nan_discovery_flush_callback: callback to flush the NAN scheduler msg 217 * @msg: pointer to msg 218 * 219 * Return: QDF_STATUS 220 */ 221 QDF_STATUS nan_discovery_flush_callback(struct scheduler_msg *msg); 222 223 /** 224 * nan_discovery_scheduled_handler: callback pointer to be called when scheduler 225 * starts executing enqueued NAN command. 226 * @msg: pointer to msg 227 * 228 * Return: status of operation 229 */ 230 QDF_STATUS nan_discovery_scheduled_handler(struct scheduler_msg *msg); 231 232 /* 233 * nan_discovery_event_handler: function to process NAN events from firmware 234 * @msg: message received from Target IF 235 * 236 * Return: status of operation 237 */ 238 QDF_STATUS nan_discovery_event_handler(struct scheduler_msg *msg); 239 240 /* 241 * nan_datapath_event_handler: function to process NDP events from firmware 242 * @msg: message received from Target IF 243 * 244 * Return: status of operation 245 */ 246 QDF_STATUS nan_datapath_event_handler(struct scheduler_msg *msg); 247 248 /* 249 * nan_set_discovery_state: Attempts to set NAN Discovery state as the given one 250 * @psoc: PSOC object 251 * @new_state: Attempting to this NAN discovery state 252 * 253 * Return: status of operation 254 */ 255 QDF_STATUS nan_set_discovery_state(struct wlan_objmgr_psoc *psoc, 256 enum nan_disc_state new_state); 257 258 /* 259 * nan_discovery_pre_enable: Takes steps before sending NAN Enable to Firmware 260 * @pdev: pdev object 261 * @nan_ch_freq: Primary social channel for NAN Discovery 262 * 263 * Return: status of operation 264 */ 265 QDF_STATUS nan_discovery_pre_enable(struct wlan_objmgr_pdev *pdev, 266 uint32_t nan_ch_freq); 267 268 /* 269 * nan_get_discovery_state: Returns the current NAN Discovery state 270 * @psoc: PSOC object 271 * 272 * Return: Current NAN Discovery state 273 */ 274 enum nan_disc_state nan_get_discovery_state(struct wlan_objmgr_psoc *psoc); 275 276 /* 277 * nan_is_enable_allowed: Queries whether NAN Discovery is allowed 278 * @psoc: PSOC object 279 * @nan_ch_freq: Possible primary social channel for NAN Discovery 280 * @vdev_id: Vdev Id 281 * 282 * Return: True if NAN Enable is allowed on given channel, False otherwise 283 */ 284 bool nan_is_enable_allowed(struct wlan_objmgr_psoc *psoc, uint32_t nan_ch_freq, 285 uint8_t vdev_id); 286 287 /* 288 * nan_is_disc_active: Queries whether NAN Discovery is active 289 * @psoc: PSOC object 290 * 291 * Return: True if NAN Disc is active, False otherwise 292 */ 293 bool nan_is_disc_active(struct wlan_objmgr_psoc *psoc); 294 295 /* 296 * nan_get_connection_info: Gets connection info of the NAN Discovery interface 297 * @psoc: PSOC object 298 * @chan: NAN Social channel to be returned 299 * @mac_if: MAC ID associated with NAN Discovery 300 * 301 * Return: QDF_STATUS 302 */ 303 QDF_STATUS 304 nan_get_connection_info(struct wlan_objmgr_psoc *psoc, uint8_t *chan, 305 uint8_t *mac_id); 306 307 /** 308 * nan_get_vdev_id_from_bssid() -get NAN vdev_id for NAN BSSID 309 * @pdev: PDEV object 310 * @bssid: BSSID present in mgmt frame 311 * @dbg_id: Object Manager ref debug id 312 * 313 * API to get NAN vdev_id for only NAN BSSID. 314 * 315 * Return: NAN vdev_id 316 */ 317 uint8_t nan_get_vdev_id_from_bssid(struct wlan_objmgr_pdev *pdev, 318 tSirMacAddr bssid, 319 wlan_objmgr_ref_dbgid dbg_id); 320 321 /* 322 * nan_is_sta_sta_concurrency_present: Queries whether STA + STA concurrency 323 * present 324 * @psoc: PSOC object 325 * 326 * Return: True if concurrency is present, False otherwise 327 */ 328 bool nan_is_sta_sta_concurrency_present(struct wlan_objmgr_psoc *psoc); 329 #endif /* _WLAN_NAN_MAIN_I_H_ */ 330 #endif /* WLAN_FEATURE_NAN */ 331