1 /* 2 * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef __ESP_SDP_API_H__ 8 #define __ESP_SDP_API_H__ 9 10 #include "esp_err.h" 11 #include "esp_bt_defs.h" 12 13 #ifdef __cplusplus 14 extern "C" { 15 #endif 16 17 #define ESP_SDP_SERVER_NAME_MAX 32 /*!< Service name max length */ 18 #define SDP_OPP_SUPPORTED_FORMATS_MAX_LENGTH 15 /*!< OPP supported format list maximum length */ 19 20 typedef enum { 21 ESP_SDP_SUCCESS = 0, /*!< Successful operation. */ 22 ESP_SDP_FAILURE, /*!< Generic failure. */ 23 ESP_SDP_NO_RESOURCE, /*!< No more resource */ 24 ESP_SDP_NEED_INIT, /*!< SDP module shall init first */ 25 ESP_SDP_NEED_DEINIT, /*!< SDP module shall deinit first */ 26 ESP_SDP_NO_CREATE_RECORD, /*!< No record created */ 27 } esp_sdp_status_t; 28 29 /** 30 * @brief SDP callback function events 31 */ 32 typedef enum { 33 ESP_SDP_INIT_EVT = 0, /*!< When SDP is initialized, the event comes */ 34 ESP_SDP_DEINIT_EVT = 1, /*!< When SDP is deinitialized, the event comes */ 35 ESP_SDP_SEARCH_COMP_EVT = 2, /*!< When SDP search complete, the event comes */ 36 ESP_SDP_CREATE_RECORD_COMP_EVT = 3, /*!< When create SDP records complete, the event comes */ 37 ESP_SDP_REMOVE_RECORD_COMP_EVT = 4, /*!< When remove a SDP record complete, the event comes */ 38 } esp_sdp_cb_event_t; 39 40 /** 41 * @brief SDP record type 42 */ 43 typedef enum { 44 ESP_SDP_TYPE_RAW, /*!< Used to carry raw SDP search data for unknown UUIDs */ 45 ESP_SDP_TYPE_MAP_MAS, /*!< Message Access Profile - Server */ 46 ESP_SDP_TYPE_MAP_MNS, /*!< Message Access Profile - Client (Notification Server) */ 47 ESP_SDP_TYPE_PBAP_PSE, /*!< Phone Book Profile - Server */ 48 ESP_SDP_TYPE_PBAP_PCE, /*!< Phone Book Profile - Client */ 49 ESP_SDP_TYPE_OPP_SERVER, /*!< Object Push Profile */ 50 ESP_SDP_TYPE_SAP_SERVER /*!< SIM Access Profile */ 51 } esp_bluetooth_sdp_types_t; 52 53 /** 54 * @brief Some signals need additional pointers, hence we introduce a 55 * generic way to handle these pointers. 56 */ 57 typedef struct bluetooth_sdp_hdr_overlay { 58 esp_bluetooth_sdp_types_t type; /*!< SDP type */ 59 esp_bt_uuid_t uuid; /*!< UUID type, include uuid and uuid length */ 60 uint32_t service_name_length; /*!< Service name length */ 61 char *service_name; /*!< service name */ 62 int32_t rfcomm_channel_number; /*!< rfcomm channel number, if not used set to -1*/ 63 int32_t l2cap_psm; /*!< l2cap psm, if not used set to -1 */ 64 int32_t profile_version; /*!< profile version */ 65 66 // User pointers, only used for some signals - see esp_bluetooth_sdp_ops_record_t 67 int user1_ptr_len; /*!< see esp_bluetooth_sdp_ops_record_t */ 68 uint8_t *user1_ptr; /*!< see esp_bluetooth_sdp_ops_record_t */ 69 int user2_ptr_len; /*!< see esp_bluetooth_sdp_ops_record_t */ 70 uint8_t *user2_ptr; /*!< see esp_bluetooth_sdp_ops_record_t */ 71 } esp_bluetooth_sdp_hdr_overlay_t; 72 73 /** 74 * @brief Message Access Profile - Server parameters 75 */ 76 typedef struct bluetooth_sdp_mas_record { 77 esp_bluetooth_sdp_hdr_overlay_t hdr; /*!< General info */ 78 uint32_t mas_instance_id; /*!< MAS Instance ID */ 79 uint32_t supported_features; /*!< Map supported features */ 80 uint32_t supported_message_types; /*!< Supported message types */ 81 } esp_bluetooth_sdp_mas_record_t; 82 83 /** 84 * @brief Message Access Profile - Client (Notification Server) parameters 85 */ 86 typedef struct bluetooth_sdp_mns_record { 87 esp_bluetooth_sdp_hdr_overlay_t hdr; /*!< General info */ 88 uint32_t supported_features; /*!< Supported features */ 89 } esp_bluetooth_sdp_mns_record_t; 90 91 /** 92 * @brief Phone Book Profile - Server parameters 93 */ 94 typedef struct bluetooth_sdp_pse_record { 95 esp_bluetooth_sdp_hdr_overlay_t hdr; /*!< General info */ 96 uint32_t supported_features; /*!< Pbap Supported Features */ 97 uint32_t supported_repositories; /*!< Supported Repositories */ 98 } esp_bluetooth_sdp_pse_record_t; 99 100 /** 101 * @brief Phone Book Profile - Client parameters 102 */ 103 typedef struct bluetooth_sdp_pce_record { 104 esp_bluetooth_sdp_hdr_overlay_t hdr; /*!< General info */ 105 } esp_bluetooth_sdp_pce_record_t; 106 107 /** 108 * @brief Object Push Profile parameters 109 */ 110 typedef struct bluetooth_sdp_ops_record { 111 esp_bluetooth_sdp_hdr_overlay_t hdr; /*!< General info */ 112 int supported_formats_list_len; /*!< Supported formats list length */ 113 uint8_t supported_formats_list[SDP_OPP_SUPPORTED_FORMATS_MAX_LENGTH]; /*!< Supported formats list */ 114 } esp_bluetooth_sdp_ops_record_t; 115 116 /** 117 * @brief SIM Access Profile parameters 118 */ 119 typedef struct bluetooth_sdp_sap_record { 120 esp_bluetooth_sdp_hdr_overlay_t hdr; /*!< General info */ 121 } esp_bluetooth_sdp_sap_record_t; 122 123 /** 124 * @brief SDP record parameters union 125 */ 126 typedef union { 127 esp_bluetooth_sdp_hdr_overlay_t hdr; /*!< General info */ 128 esp_bluetooth_sdp_mas_record_t mas; /*!< Message Access Profile - Server */ 129 esp_bluetooth_sdp_mns_record_t mns; /*!< Message Access Profile - Client (Notification Server) */ 130 esp_bluetooth_sdp_pse_record_t pse; /*!< Phone Book Profile - Server */ 131 esp_bluetooth_sdp_pce_record_t pce; /*!< Phone Book Profile - Client */ 132 esp_bluetooth_sdp_ops_record_t ops; /*!< Object Push Profile */ 133 esp_bluetooth_sdp_sap_record_t sap; /*!< SIM Access Profile */ 134 } esp_bluetooth_sdp_record_t; 135 136 /** 137 * @brief SDP callback parameters union 138 */ 139 typedef union { 140 /** 141 * @brief ESP_SDP_INIT_EVT 142 */ 143 struct sdp_init_evt_param { 144 esp_sdp_status_t status; /*!< status */ 145 } init; /*!< SDP callback param of ESP_SDP_INIT_EVT */ 146 147 /** 148 * @brief ESP_SDP_DEINIT_EVT 149 */ 150 struct sdp_deinit_evt_param { 151 esp_sdp_status_t status; /*!< status */ 152 } deinit; /*!< SDP callback param of ESP_SDP_DEINIT_EVT */ 153 154 /** 155 * @brief ESP_SDP_SEARCH_COMP_EVT 156 */ 157 struct sdp_search_evt_param { 158 esp_sdp_status_t status; /*!< status */ 159 esp_bd_addr_t remote_addr; /*!< remote device address */ 160 esp_bt_uuid_t sdp_uuid; /*!< service uuid */ 161 int record_count; /*!< Number of SDP records */ 162 esp_bluetooth_sdp_record_t *records;/*!< SDP records */ 163 } search; /*!< SDP callback param of ESP_SDP_SEARCH_COMP_EVT */ 164 165 /** 166 * @brief ESP_SDP_CREATE_RECORD_COMP_EVT 167 */ 168 struct sdp_crate_record_evt_param { 169 esp_sdp_status_t status; /*!< status */ 170 int record_handle; /*!< SDP record handle */ 171 } create_record; /*!< SDP callback param of ESP_SDP_CREATE_RECORD_COMP_EVT */ 172 173 /** 174 * @brief ESP_SDP_REMOVE_RECORD_COMP_EVT 175 */ 176 struct sdp_remove_record_evt_param { 177 esp_sdp_status_t status; /*!< status */ 178 } remove_record; /*!< SDP callback param of ESP_SDP_REMOVE_RECORD_COMP_EVT */ 179 180 } esp_sdp_cb_param_t; /*!< SDP callback parameter union type */ 181 182 183 /** 184 * @brief SDP callback function type. 185 * 186 * @param event: Event type 187 * @param param: Point to callback parameter, currently is union type 188 */ 189 typedef void (* esp_sdp_cb_t)(esp_sdp_cb_event_t event, esp_sdp_cb_param_t *param); 190 191 /** 192 * @brief This function is called to init callbacks with SDP module. 193 * 194 * @param[in] callback: pointer to the init callback function. 195 * 196 * @return 197 * - ESP_OK: success 198 * - other: failed 199 */ 200 esp_err_t esp_sdp_register_callback(esp_sdp_cb_t callback); 201 202 /** 203 * @brief This function is called to init SDP module. 204 * When the operation is completed, the callback function will be called with ESP_SDP_INIT_EVT. 205 * This function should be called after esp_bluedroid_enable() completes successfully. 206 * 207 * @return 208 * - ESP_OK: success 209 * - other: failed 210 */ 211 esp_err_t esp_sdp_init(void); 212 213 /** 214 * @brief This function is called to de-initialize SDP module. 215 * The operation will remove all SDP records, then the callback function will be called 216 * with ESP_SDP_REMOVE_RECORD_COMP_EVT, and the number of ESP_SDP_REMOVE_RECORD_COMP_EVT is 217 * equal to the number of SDP records.When the operation is completed, the callback function 218 * will be called with ESP_SDP_DEINIT_EVT. This function should be called after esp_sdp_init() 219 * completes successfully. 220 * 221 * @return 222 * - ESP_OK: success 223 * - other: failed 224 */ 225 esp_err_t esp_sdp_deinit(void); 226 227 /** 228 * @brief This function is called to performs service discovery for the services provided by the given peer device. 229 * When the operation is completed, the callback function will be called with ESP_SDP_SEARCH_COMP_EVT. 230 * This function must be called after esp_sdp_init() successful and before esp_sdp_deinit(). 231 * 232 * @param[in] bd_addr: Remote device bluetooth device address. 233 * @param[in] uuid: Service UUID of the remote device. 234 * 235 * @return 236 * - ESP_OK: success 237 * - other: failed 238 */ 239 esp_err_t esp_sdp_search_record(esp_bd_addr_t bd_addr, esp_bt_uuid_t uuid); 240 241 /** 242 * @brief This function is called to create SDP records. 243 * When the operation is completed, the callback function will be called with ESP_SDP_CREATE_RECORD_COMP_EVT. 244 * This function must be called after esp_sdp_init() successful and before esp_sdp_deinit(). 245 * 246 * @param[in] record: The SDP record to create. 247 * 248 * @return 249 * - ESP_OK: success 250 * - other: failed 251 */ 252 esp_err_t esp_sdp_create_record(esp_bluetooth_sdp_record_t *record); 253 254 /** 255 * @brief This function is called to remove a SDP record. 256 * When the operation is completed, the callback function will be called with ESP_SDP_REMOVE_RECORD_COMP_EVT. 257 * This function must be called after esp_sdp_init() successful and before esp_sdp_deinit(). 258 * 259 * @param[in] record_handle: The SDP record handle. 260 * 261 * @return 262 * - ESP_OK: success 263 * - other: failed 264 */ 265 esp_err_t esp_sdp_remove_record(int record_handle); 266 267 #ifdef __cplusplus 268 } 269 #endif 270 271 #endif ///__ESP_SDP_API_H__ 272