1 /** @file 2 * @brief Service Discovery Protocol handling. 3 */ 4 5 /* 6 * Copyright (c) 2016 Intel Corporation 7 * 8 * SPDX-License-Identifier: Apache-2.0 9 */ 10 #ifndef ZEPHYR_INCLUDE_BLUETOOTH_SDP_H_ 11 #define ZEPHYR_INCLUDE_BLUETOOTH_SDP_H_ 12 13 /** 14 * @file 15 * @brief Service Discovery Protocol (SDP) 16 * @defgroup bt_sdp Service Discovery Protocol (SDP) 17 * @ingroup bluetooth 18 * @{ 19 */ 20 21 #include <sys/types.h> 22 23 #include <zephyr/bluetooth/uuid.h> 24 #include <zephyr/bluetooth/conn.h> 25 26 #ifdef __cplusplus 27 extern "C" { 28 #endif 29 30 /* 31 * All definitions are based on Bluetooth Assigned Numbers 32 * of the Bluetooth Specification 33 */ 34 35 /** 36 * @name Service class identifiers of standard services and service groups 37 * @{ 38 */ 39 #define BT_SDP_SDP_SERVER_SVCLASS 0x1000 /**< Service Discovery Server */ 40 #define BT_SDP_BROWSE_GRP_DESC_SVCLASS 0x1001 /**< Browse Group Descriptor */ 41 #define BT_SDP_PUBLIC_BROWSE_GROUP 0x1002 /**< Public Browse Group */ 42 #define BT_SDP_SERIAL_PORT_SVCLASS 0x1101 /**< Serial Port */ 43 #define BT_SDP_LAN_ACCESS_SVCLASS 0x1102 /**< LAN Access Using PPP */ 44 #define BT_SDP_DIALUP_NET_SVCLASS 0x1103 /**< Dialup Networking */ 45 #define BT_SDP_IRMC_SYNC_SVCLASS 0x1104 /**< IrMC Sync */ 46 #define BT_SDP_OBEX_OBJPUSH_SVCLASS 0x1105 /**< OBEX Object Push */ 47 #define BT_SDP_OBEX_FILETRANS_SVCLASS 0x1106 /**< OBEX File Transfer */ 48 #define BT_SDP_IRMC_SYNC_CMD_SVCLASS 0x1107 /**< IrMC Sync Command */ 49 #define BT_SDP_HEADSET_SVCLASS 0x1108 /**< Headset */ 50 #define BT_SDP_CORDLESS_TELEPHONY_SVCLASS 0x1109 /**< Cordless Telephony */ 51 #define BT_SDP_AUDIO_SOURCE_SVCLASS 0x110a /**< Audio Source */ 52 #define BT_SDP_AUDIO_SINK_SVCLASS 0x110b /**< Audio Sink */ 53 #define BT_SDP_AV_REMOTE_TARGET_SVCLASS 0x110c /**< A/V Remote Control Target */ 54 #define BT_SDP_ADVANCED_AUDIO_SVCLASS 0x110d /**< Advanced Audio Distribution */ 55 #define BT_SDP_AV_REMOTE_SVCLASS 0x110e /**< A/V Remote Control */ 56 #define BT_SDP_AV_REMOTE_CONTROLLER_SVCLASS 0x110f /**< A/V Remote Control Controller */ 57 #define BT_SDP_INTERCOM_SVCLASS 0x1110 /**< Intercom */ 58 #define BT_SDP_FAX_SVCLASS 0x1111 /**< Fax */ 59 #define BT_SDP_HEADSET_AGW_SVCLASS 0x1112 /**< Headset AG */ 60 #define BT_SDP_WAP_SVCLASS 0x1113 /**< WAP */ 61 #define BT_SDP_WAP_CLIENT_SVCLASS 0x1114 /**< WAP Client */ 62 #define BT_SDP_PANU_SVCLASS 0x1115 /**< Personal Area Networking User */ 63 #define BT_SDP_NAP_SVCLASS 0x1116 /**< Network Access Point */ 64 #define BT_SDP_GN_SVCLASS 0x1117 /**< Group Network */ 65 #define BT_SDP_DIRECT_PRINTING_SVCLASS 0x1118 /**< Direct Printing */ 66 #define BT_SDP_REFERENCE_PRINTING_SVCLASS 0x1119 /**< Reference Printing */ 67 #define BT_SDP_IMAGING_SVCLASS 0x111a /**< Basic Imaging Profile */ 68 #define BT_SDP_IMAGING_RESPONDER_SVCLASS 0x111b /**< Imaging Responder */ 69 #define BT_SDP_IMAGING_ARCHIVE_SVCLASS 0x111c /**< Imaging Automatic Archive */ 70 #define BT_SDP_IMAGING_REFOBJS_SVCLASS 0x111d /**< Imaging Referenced Objects */ 71 #define BT_SDP_HANDSFREE_SVCLASS 0x111e /**< Handsfree */ 72 #define BT_SDP_HANDSFREE_AGW_SVCLASS 0x111f /**< Handsfree Audio Gateway */ 73 #define BT_SDP_DIRECT_PRT_REFOBJS_SVCLASS 0x1120 /**< Direct Printing Reference Objects Service */ 74 #define BT_SDP_REFLECTED_UI_SVCLASS 0x1121 /**< Reflected UI */ 75 #define BT_SDP_BASIC_PRINTING_SVCLASS 0x1122 /**< Basic Printing */ 76 #define BT_SDP_PRINTING_STATUS_SVCLASS 0x1123 /**< Printing Status */ 77 #define BT_SDP_HID_SVCLASS 0x1124 /**< Human Interface Device Service */ 78 #define BT_SDP_HCR_SVCLASS 0x1125 /**< Hardcopy Cable Replacement */ 79 #define BT_SDP_HCR_PRINT_SVCLASS 0x1126 /**< HCR Print */ 80 #define BT_SDP_HCR_SCAN_SVCLASS 0x1127 /**< HCR Scan */ 81 #define BT_SDP_CIP_SVCLASS 0x1128 /**< Common ISDN Access */ 82 #define BT_SDP_VIDEO_CONF_GW_SVCLASS 0x1129 /**< Video Conferencing Gateway */ 83 #define BT_SDP_UDI_MT_SVCLASS 0x112a /**< UDI MT */ 84 #define BT_SDP_UDI_TA_SVCLASS 0x112b /**< UDI TA */ 85 #define BT_SDP_AV_SVCLASS 0x112c /**< Audio/Video */ 86 #define BT_SDP_SAP_SVCLASS 0x112d /**< SIM Access */ 87 #define BT_SDP_PBAP_PCE_SVCLASS 0x112e /**< Phonebook Access Client */ 88 #define BT_SDP_PBAP_PSE_SVCLASS 0x112f /**< Phonebook Access Server */ 89 #define BT_SDP_PBAP_SVCLASS 0x1130 /**< Phonebook Access */ 90 #define BT_SDP_MAP_MSE_SVCLASS 0x1132 /**< Message Access Server */ 91 #define BT_SDP_MAP_MCE_SVCLASS 0x1133 /**< Message Notification Server */ 92 #define BT_SDP_MAP_SVCLASS 0x1134 /**< Message Access Profile */ 93 #define BT_SDP_GNSS_SVCLASS 0x1135 /**< GNSS */ 94 #define BT_SDP_GNSS_SERVER_SVCLASS 0x1136 /**< GNSS Server */ 95 #define BT_SDP_MPS_SC_SVCLASS 0x113a /**< MPS SC */ 96 #define BT_SDP_MPS_SVCLASS 0x113b /**< MPS */ 97 #define BT_SDP_PNP_INFO_SVCLASS 0x1200 /**< PnP Information */ 98 #define BT_SDP_GENERIC_NETWORKING_SVCLASS 0x1201 /**< Generic Networking */ 99 #define BT_SDP_GENERIC_FILETRANS_SVCLASS 0x1202 /**< Generic File Transfer */ 100 #define BT_SDP_GENERIC_AUDIO_SVCLASS 0x1203 /**< Generic Audio */ 101 #define BT_SDP_GENERIC_TELEPHONY_SVCLASS 0x1204 /**< Generic Telephony */ 102 #define BT_SDP_UPNP_SVCLASS 0x1205 /**< UPnP Service */ 103 #define BT_SDP_UPNP_IP_SVCLASS 0x1206 /**< UPnP IP Service */ 104 #define BT_SDP_UPNP_PAN_SVCLASS 0x1300 /**< UPnP IP PAN */ 105 #define BT_SDP_UPNP_LAP_SVCLASS 0x1301 /**< UPnP IP LAP */ 106 #define BT_SDP_UPNP_L2CAP_SVCLASS 0x1302 /**< UPnP IP L2CAP */ 107 #define BT_SDP_VIDEO_SOURCE_SVCLASS 0x1303 /**< Video Source */ 108 #define BT_SDP_VIDEO_SINK_SVCLASS 0x1304 /**< Video Sink */ 109 #define BT_SDP_VIDEO_DISTRIBUTION_SVCLASS 0x1305 /**< Video Distribution */ 110 #define BT_SDP_HDP_SVCLASS 0x1400 /**< HDP */ 111 #define BT_SDP_HDP_SOURCE_SVCLASS 0x1401 /**< HDP Source */ 112 #define BT_SDP_HDP_SINK_SVCLASS 0x1402 /**< HDP Sink */ 113 #define BT_SDP_GENERIC_ACCESS_SVCLASS 0x1800 /**< Generic Access Profile */ 114 #define BT_SDP_GENERIC_ATTRIB_SVCLASS 0x1801 /**< Generic Attribute Profile */ 115 #define BT_SDP_APPLE_AGENT_SVCLASS 0x2112 /**< Apple Agent */ 116 /** 117 * @} 118 */ 119 120 #define BT_SDP_SERVER_RECORD_HANDLE 0x0000 121 122 /** 123 * @name Attribute identifier codes 124 * 125 * Possible values for attribute-id are listed below. 126 * See SDP Spec, section "Service Attribute Definitions" for more details. 127 * 128 * @{ 129 */ 130 #define BT_SDP_ATTR_RECORD_HANDLE 0x0000 /**< Service Record Handle */ 131 #define BT_SDP_ATTR_SVCLASS_ID_LIST 0x0001 /**< Service Class ID List */ 132 #define BT_SDP_ATTR_RECORD_STATE 0x0002 /**< Service Record State */ 133 #define BT_SDP_ATTR_SERVICE_ID 0x0003 /**< Service ID */ 134 #define BT_SDP_ATTR_PROTO_DESC_LIST 0x0004 /**< Protocol Descriptor List */ 135 #define BT_SDP_ATTR_BROWSE_GRP_LIST 0x0005 /**< Browse Group List */ 136 #define BT_SDP_ATTR_LANG_BASE_ATTR_ID_LIST 0x0006 /**< Language Base Attribute ID List */ 137 #define BT_SDP_ATTR_SVCINFO_TTL 0x0007 /**< Service Info Time to Live */ 138 #define BT_SDP_ATTR_SERVICE_AVAILABILITY 0x0008 /**< Service Availability */ 139 #define BT_SDP_ATTR_PROFILE_DESC_LIST 0x0009 /**< Bluetooth Profile Descriptor List */ 140 #define BT_SDP_ATTR_DOC_URL 0x000a /**< Documentation URL */ 141 #define BT_SDP_ATTR_CLNT_EXEC_URL 0x000b /**< Client Executable URL */ 142 #define BT_SDP_ATTR_ICON_URL 0x000c /**< Icon URL */ 143 #define BT_SDP_ATTR_ADD_PROTO_DESC_LIST 0x000d /**< Additional Protocol Descriptor List */ 144 145 #define BT_SDP_ATTR_GROUP_ID 0x0200 /**< Group ID */ 146 #define BT_SDP_ATTR_IP_SUBNET 0x0200 /**< IP Subnet */ 147 #define BT_SDP_ATTR_VERSION_NUM_LIST 0x0200 /**< Version Number List */ 148 #define BT_SDP_ATTR_SUPPORTED_FEATURES_LIST 0x0200 /**< Supported Features List */ 149 #define BT_SDP_ATTR_GOEP_L2CAP_PSM 0x0200 /**< GOEP L2CAP PSM */ 150 #define BT_SDP_ATTR_SVCDB_STATE 0x0201 /**< Service Database State */ 151 152 #define BT_SDP_ATTR_MPSD_SCENARIOS 0x0200 /**< MPSD Scenarios */ 153 #define BT_SDP_ATTR_MPMD_SCENARIOS 0x0201 /**< MPMD Scenarios */ 154 #define BT_SDP_ATTR_MPS_DEPENDENCIES 0x0202 /**< Supported Profiles & Protocols */ 155 156 #define BT_SDP_ATTR_SERVICE_VERSION 0x0300 /**< Service Version */ 157 #define BT_SDP_ATTR_EXTERNAL_NETWORK 0x0301 /**< External Network */ 158 #define BT_SDP_ATTR_SUPPORTED_DATA_STORES_LIST 0x0301 /**< Supported Data Stores List */ 159 #define BT_SDP_ATTR_DATA_EXCHANGE_SPEC 0x0301 /**< Data Exchange Specification */ 160 #define BT_SDP_ATTR_NETWORK 0x0301 /**< Network */ 161 #define BT_SDP_ATTR_FAX_CLASS1_SUPPORT 0x0302 /**< Fax Class 1 Support */ 162 #define BT_SDP_ATTR_REMOTE_AUDIO_VOLUME_CONTROL 0x0302 /**< Remote Audio Volume Control */ 163 #define BT_SDP_ATTR_MCAP_SUPPORTED_PROCEDURES 0x0302 /**< MCAP Supported Procedures */ 164 #define BT_SDP_ATTR_FAX_CLASS20_SUPPORT 0x0303 /**< Fax Class 2.0 Support */ 165 #define BT_SDP_ATTR_SUPPORTED_FORMATS_LIST 0x0303 /**< Supported Formats List */ 166 #define BT_SDP_ATTR_FAX_CLASS2_SUPPORT 0x0304 /**< Fax Class 2 Support (vendor-specific)*/ 167 #define BT_SDP_ATTR_AUDIO_FEEDBACK_SUPPORT 0x0305 /**< Audio Feedback Support */ 168 #define BT_SDP_ATTR_NETWORK_ADDRESS 0x0306 /**< Network Address */ 169 #define BT_SDP_ATTR_WAP_GATEWAY 0x0307 /**< WAP Gateway */ 170 #define BT_SDP_ATTR_HOMEPAGE_URL 0x0308 /**< Homepage URL */ 171 #define BT_SDP_ATTR_WAP_STACK_TYPE 0x0309 /**< WAP Stack Type */ 172 #define BT_SDP_ATTR_SECURITY_DESC 0x030a /**< Security Description */ 173 #define BT_SDP_ATTR_NET_ACCESS_TYPE 0x030b /**< Net Access Type */ 174 #define BT_SDP_ATTR_MAX_NET_ACCESSRATE 0x030c /**< Max Net Access Rate */ 175 #define BT_SDP_ATTR_IP4_SUBNET 0x030d /**< IPv4 Subnet */ 176 #define BT_SDP_ATTR_IP6_SUBNET 0x030e /**< IPv6 Subnet */ 177 #define BT_SDP_ATTR_SUPPORTED_CAPABILITIES 0x0310 /**< BIP Supported Capabilities */ 178 #define BT_SDP_ATTR_SUPPORTED_FEATURES 0x0311 /**< BIP Supported Features */ 179 #define BT_SDP_ATTR_SUPPORTED_FUNCTIONS 0x0312 /**< BIP Supported Functions */ 180 #define BT_SDP_ATTR_TOTAL_IMAGING_DATA_CAPACITY 0x0313 /**< BIP Total Imaging Data Capacity */ 181 #define BT_SDP_ATTR_SUPPORTED_REPOSITORIES 0x0314 /**< Supported Repositories */ 182 #define BT_SDP_ATTR_MAS_INSTANCE_ID 0x0315 /**< MAS Instance ID */ 183 #define BT_SDP_ATTR_SUPPORTED_MESSAGE_TYPES 0x0316 /**< Supported Message Types */ 184 #define BT_SDP_ATTR_PBAP_SUPPORTED_FEATURES 0x0317 /**< PBAP Supported Features */ 185 #define BT_SDP_ATTR_MAP_SUPPORTED_FEATURES 0x0317 /**< MAP Supported Features */ 186 187 #define BT_SDP_ATTR_SPECIFICATION_ID 0x0200 /**< Specification ID */ 188 #define BT_SDP_ATTR_VENDOR_ID 0x0201 /**< Vendor ID */ 189 #define BT_SDP_ATTR_PRODUCT_ID 0x0202 /**< Product ID */ 190 #define BT_SDP_ATTR_VERSION 0x0203 /**< Version */ 191 #define BT_SDP_ATTR_PRIMARY_RECORD 0x0204 /**< Primary Record */ 192 #define BT_SDP_ATTR_VENDOR_ID_SOURCE 0x0205 /**< Vendor ID Source */ 193 194 #define BT_SDP_ATTR_HID_DEVICE_RELEASE_NUMBER 0x0200 /**< HID Device Release Number */ 195 #define BT_SDP_ATTR_HID_PARSER_VERSION 0x0201 /**< HID Parser Version */ 196 #define BT_SDP_ATTR_HID_DEVICE_SUBCLASS 0x0202 /**< HID Device Subclass */ 197 #define BT_SDP_ATTR_HID_COUNTRY_CODE 0x0203 /**< HID Country Code */ 198 #define BT_SDP_ATTR_HID_VIRTUAL_CABLE 0x0204 /**< HID Virtual Cable */ 199 #define BT_SDP_ATTR_HID_RECONNECT_INITIATE 0x0205 /**< HID Reconnect Initiate */ 200 #define BT_SDP_ATTR_HID_DESCRIPTOR_LIST 0x0206 /**< HID Descriptor List */ 201 #define BT_SDP_ATTR_HID_LANG_ID_BASE_LIST 0x0207 /**< HID Language ID Base List */ 202 #define BT_SDP_ATTR_HID_SDP_DISABLE 0x0208 /**< HID SDP Disable */ 203 #define BT_SDP_ATTR_HID_BATTERY_POWER 0x0209 /**< HID Battery Power */ 204 #define BT_SDP_ATTR_HID_REMOTE_WAKEUP 0x020a /**< HID Remote Wakeup */ 205 #define BT_SDP_ATTR_HID_PROFILE_VERSION 0x020b /**< HID Profile Version */ 206 #define BT_SDP_ATTR_HID_SUPERVISION_TIMEOUT 0x020c /**< HID Supervision Timeout */ 207 #define BT_SDP_ATTR_HID_NORMALLY_CONNECTABLE 0x020d /**< HID Normally Connectable */ 208 #define BT_SDP_ATTR_HID_BOOT_DEVICE 0x020e /**< HID Boot Device */ 209 /** 210 * @} 211 */ 212 213 /* 214 * These identifiers are based on the SDP spec stating that 215 * "base attribute id of the primary (universal) language must be 0x0100" 216 * 217 * Other languages should have their own offset; e.g.: 218 * #define XXXLangBase yyyy 219 * #define AttrServiceName_XXX 0x0000+XXXLangBase 220 */ 221 #define BT_SDP_PRIMARY_LANG_BASE 0x0100 222 223 #define BT_SDP_ATTR_SVCNAME_PRIMARY (0x0000 + BT_SDP_PRIMARY_LANG_BASE) 224 #define BT_SDP_ATTR_SVCDESC_PRIMARY (0x0001 + BT_SDP_PRIMARY_LANG_BASE) 225 #define BT_SDP_ATTR_PROVNAME_PRIMARY (0x0002 + BT_SDP_PRIMARY_LANG_BASE) 226 227 /** 228 * @name Protocol identifier codes 229 * @brief Protocol identifiers used in Bluetooth Service Discovery Protocol (SDP) 230 * @note Based on Bluetooth Assigned Numbers specification 231 * 232 * Possible values for protocol-id are listed below. 233 * See Assigned Numbers Spec, section "Protocol Identifiers" for more details. 234 * 235 * @{ 236 */ 237 #define BT_SDP_PROTO_SDP 0x0001 /**< Service Discovery Protocol */ 238 #define BT_SDP_PROTO_UDP 0x0002 /**< User Datagram Protocol */ 239 #define BT_SDP_PROTO_RFCOMM 0x0003 /**< Radio Frequency Communication */ 240 #define BT_SDP_PROTO_TCP 0x0004 /**< Transmission Control Protocol */ 241 #define BT_SDP_PROTO_TCS_BIN 0x0005 /**< Telephony Control Specification Binary */ 242 #define BT_SDP_PROTO_TCS_AT 0x0006 /**< Telephony Control Specification AT */ 243 #define BT_SDP_PROTO_ATT 0x0007 /**< Attribute Protocol */ 244 #define BT_SDP_PROTO_OBEX 0x0008 /**< Object Exchange Protocol */ 245 #define BT_SDP_PROTO_IP 0x0009 /**< Internet Protocol */ 246 #define BT_SDP_PROTO_FTP 0x000a /**< File Transfer Protocol */ 247 #define BT_SDP_PROTO_HTTP 0x000c /**< HyperText Transfer Protocol */ 248 #define BT_SDP_PROTO_WSP 0x000e /**< Wireless Session Protocol */ 249 #define BT_SDP_PROTO_BNEP 0x000f /**< Bluetooth Network Encapsulation Protocol */ 250 #define BT_SDP_PROTO_UPNP 0x0010 /**< Universal Plug and Play */ 251 #define BT_SDP_PROTO_HID 0x0011 /**< Human Interface Device Protocol */ 252 #define BT_SDP_PROTO_HARDCOPY_CTRL 0x0012 /**< Hardcopy Control Channel */ 253 #define BT_SDP_PROTO_HARDCOPY_DATA 0x0014 /**< Hardcopy Data Channel */ 254 #define BT_SDP_PROTO_HARDCOPY_NTF 0x0016 /**< Hardcopy Notification Channel */ 255 #define BT_SDP_PROTO_AVCTP 0x0017 /**< Audio/Video Control Transport Protocol */ 256 #define BT_SDP_PROTO_AVDTP 0x0019 /**< Audio/Video Distribution Transport Protocol */ 257 #define BT_SDP_PROTO_CMTP 0x001b /**< Common ISDN Access Protocol */ 258 #define BT_SDP_PROTO_MCAP_CTRL 0x001e /**< Multi-Channel Adaptation Protocol Control */ 259 #define BT_SDP_PROTO_MCAP_DATA 0x001f /**< Multi-Channel Adaptation Protocol Data */ 260 #define BT_SDP_PROTO_L2CAP 0x0100 /**< Logical Link Control and Adaptation Protocol */ 261 /** 262 * @} 263 */ 264 265 /** 266 * @name The Data representation in SDP PDUs (pps 339, 340 of BT SDP Spec) 267 * 268 * These are the exact data type+size descriptor values 269 * that go into the PDU buffer. 270 * 271 * The datatype (leading 5bits) + size descriptor (last 3 bits) 272 * is 8 bits. The size descriptor is critical to extract the 273 * right number of bytes for the data value from the PDU. 274 * 275 * For most basic types, the datatype+size descriptor is 276 * straightforward. However for constructed types and strings, 277 * the size of the data is in the next "n" bytes following the 278 * 8 bits (datatype+size) descriptor. Exactly what the "n" is 279 * specified in the 3 bits of the data size descriptor. 280 * 281 * TextString and URLString can be of size 2^{8, 16, 32} bytes 282 * DataSequence and DataSequenceAlternates can be of size 2^{8, 16, 32} 283 * The size are computed post-facto in the API and are not known apriori. 284 * 285 * For the type BT_SDP_UINT128, BT_SDP_INT128, and BT_SDP_UUID128, the 286 * byteorder of data should be little-endian. Such as, SPP UUID128: 287 * `00001101-0000-1000-8000-00805F9B34FB` will be represented as 288 * {0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 289 * 0x01, 0x11, 0x00, 0x00} 290 * For UUID 128, @ref BT_SDP_ARRAY_UUID_128 is used to declare the array. 291 * @{ 292 */ 293 #define BT_SDP_DATA_NIL 0x00 /**< Nil, the null type */ 294 #define BT_SDP_UINT8 0x08 /**< Unsigned 8-bit integer */ 295 #define BT_SDP_UINT16 0x09 /**< Unsigned 16-bit integer */ 296 #define BT_SDP_UINT32 0x0a /**< Unsigned 32-bit integer */ 297 #define BT_SDP_UINT64 0x0b /**< Unsigned 64-bit integer */ 298 #define BT_SDP_UINT128 0x0c /**< Unsigned 128-bit integer */ 299 #define BT_SDP_INT8 0x10 /**< Signed 8-bit integer */ 300 #define BT_SDP_INT16 0x11 /**< Signed 16-bit integer */ 301 #define BT_SDP_INT32 0x12 /**< Signed 32-bit integer */ 302 #define BT_SDP_INT64 0x13 /**< Signed 64-bit integer */ 303 #define BT_SDP_INT128 0x14 /**< Signed 128-bit integer */ 304 #define BT_SDP_UUID_UNSPEC 0x18 /**< UUID, unspecified size */ 305 #define BT_SDP_UUID16 0x19 /**< UUID, 16-bit */ 306 #define BT_SDP_UUID32 0x1a /**< UUID, 32-bit */ 307 #define BT_SDP_UUID128 0x1c /**< UUID, 128-bit */ 308 #define BT_SDP_TEXT_STR_UNSPEC 0x20 /**< Text string, unspecified size */ 309 #define BT_SDP_TEXT_STR8 0x25 /**< Text string, 8-bit length */ 310 #define BT_SDP_TEXT_STR16 0x26 /**< Text string, 16-bit length */ 311 #define BT_SDP_TEXT_STR32 0x27 /**< Text string, 32-bit length */ 312 #define BT_SDP_BOOL 0x28 /**< Boolean */ 313 #define BT_SDP_SEQ_UNSPEC 0x30 /**< Data element sequence, unspecified size */ 314 #define BT_SDP_SEQ8 0x35 /**< Data element sequence, 8-bit length */ 315 #define BT_SDP_SEQ16 0x36 /**< Data element sequence, 16-bit length */ 316 #define BT_SDP_SEQ32 0x37 /**< Data element sequence, 32-bit length */ 317 #define BT_SDP_ALT_UNSPEC 0x38 /**< Data element alternative, unspecified size */ 318 #define BT_SDP_ALT8 0x3d /**< Data element alternative, 8-bit length */ 319 #define BT_SDP_ALT16 0x3e /**< Data element alternative, 16-bit length */ 320 #define BT_SDP_ALT32 0x3f /**< Data element alternative, 32-bit length */ 321 #define BT_SDP_URL_STR_UNSPEC 0x40 /**< URL string, unspecified size */ 322 #define BT_SDP_URL_STR8 0x45 /**< URL string, 8-bit length */ 323 #define BT_SDP_URL_STR16 0x46 /**< URL string, 16-bit length */ 324 #define BT_SDP_URL_STR32 0x47 /**< URL string, 32-bit length */ 325 /** 326 * @} 327 */ 328 329 #define BT_SDP_TYPE_DESC_MASK 0xf8 330 #define BT_SDP_SIZE_DESC_MASK 0x07 331 #define BT_SDP_SIZE_INDEX_OFFSET 5 332 333 /** @brief SDP Generic Data Element Value. */ 334 struct bt_sdp_data_elem { 335 uint8_t type; /**< Type of the data element */ 336 uint32_t data_size; /**< Size of the data element */ 337 uint32_t total_size; /**< Total size of the data element */ 338 const void *data; 339 }; 340 341 /** @brief SDP Attribute Value. */ 342 struct bt_sdp_attribute { 343 uint16_t id; /**< Attribute ID */ 344 struct bt_sdp_data_elem val; /**< Attribute data */ 345 }; 346 347 /** @brief SDP Service Record Value. */ 348 struct bt_sdp_record { 349 uint32_t handle; /**< Redundant, for quick ref */ 350 struct bt_sdp_attribute *attrs; /**< Base addr of attr array */ 351 size_t attr_count; /**< Number of attributes */ 352 uint8_t index; /**< Index of the record in LL */ 353 sys_snode_t node; 354 }; 355 356 /* 357 * --------------------------------------------------- ------------------ 358 * | Service Hdl | Attr list ptr | Attr count | Next | -> | Service Hdl | ... 359 * --------------------------------------------------- ------------------ 360 */ 361 362 /** 363 * @brief Declare an array of 8-bit elements in an attribute. 364 */ 365 #define BT_SDP_ARRAY_8(...) ((uint8_t[]) {__VA_ARGS__}) 366 367 /** 368 * @brief Declare an array of 16-bit elements in an attribute. 369 */ 370 #define BT_SDP_ARRAY_16(...) ((uint16_t[]) {__VA_ARGS__}) 371 372 /** 373 * @brief Declare an array of 32-bit elements in an attribute. 374 */ 375 #define BT_SDP_ARRAY_32(...) ((uint32_t[]) {__VA_ARGS__}) 376 377 /** 378 * @brief Declare a UUID 128 in little-endian format in an attribute. 379 * 380 * Helper macro to initialize a 128-bit UUID array value from the readable form 381 * of UUIDs. 382 * 383 * Example of how to declare the UUID `6E400001-B5A3-F393-E0A9-E50E24DCCA9E` 384 * 385 * @code 386 * BT_SDP_ARRAY_UUID_128(0x6E400001, 0xB5A3, 0xF393, 0xE0A9, 0xE50E24DCCA9E) 387 * @endcode 388 * 389 * Just replace the hyphen by the comma and add `0x` prefixes. 390 * 391 * @param w32 First part of the UUID (32 bits) 392 * @param w1 Second part of the UUID (16 bits) 393 * @param w2 Third part of the UUID (16 bits) 394 * @param w3 Fourth part of the UUID (16 bits) 395 * @param w48 Fifth part of the UUID (48 bits) 396 * 397 * @return The comma separated values for UUID 128. 398 */ 399 #define BT_SDP_ARRAY_UUID_128(w32, w1, w2, w3, w48) \ 400 BT_SDP_ARRAY_8(BT_UUID_128_ENCODE(w32, w1, w2, w3, w48)) 401 402 /** 403 * @brief Declare a fixed-size data element header. 404 * 405 * @param _type Data element header containing type and size descriptors. 406 */ 407 #define BT_SDP_TYPE_SIZE(_type) .type = _type, \ 408 .data_size = BIT(_type & BT_SDP_SIZE_DESC_MASK), \ 409 .total_size = BIT(_type & BT_SDP_SIZE_DESC_MASK) + 1 410 411 /** 412 * @brief Declare a variable-size data element header. 413 * 414 * @param _type Data element header containing type and size descriptors. 415 * @param _size The actual size of the data. 416 */ 417 #define BT_SDP_TYPE_SIZE_VAR(_type, _size) .type = _type, \ 418 .data_size = _size, \ 419 .total_size = BIT((_type & BT_SDP_SIZE_DESC_MASK) - \ 420 BT_SDP_SIZE_INDEX_OFFSET) + _size + 1 421 422 /** 423 * @brief Declare a list of data elements. 424 */ 425 #define BT_SDP_DATA_ELEM_LIST(...) ((struct bt_sdp_data_elem[]) {__VA_ARGS__}) 426 427 428 /** 429 * @brief SDP New Service Record Declaration Macro. 430 * 431 * Helper macro to declare a new service record. 432 * Default attributes: Record Handle, Record State, 433 * Language Base, Root Browse Group 434 * 435 */ 436 #define BT_SDP_NEW_SERVICE \ 437 { \ 438 BT_SDP_ATTR_RECORD_HANDLE, \ 439 { BT_SDP_TYPE_SIZE(BT_SDP_UINT32), BT_SDP_ARRAY_32(0) } \ 440 }, \ 441 { \ 442 BT_SDP_ATTR_RECORD_STATE, \ 443 { BT_SDP_TYPE_SIZE(BT_SDP_UINT32), BT_SDP_ARRAY_32(0) } \ 444 }, \ 445 { \ 446 BT_SDP_ATTR_LANG_BASE_ATTR_ID_LIST, \ 447 { BT_SDP_TYPE_SIZE_VAR(BT_SDP_SEQ8, 9), \ 448 BT_SDP_DATA_ELEM_LIST( \ 449 { BT_SDP_TYPE_SIZE(BT_SDP_UINT16), BT_SDP_ARRAY_8('n', 'e') }, \ 450 { BT_SDP_TYPE_SIZE(BT_SDP_UINT16), BT_SDP_ARRAY_16(106) }, \ 451 { BT_SDP_TYPE_SIZE(BT_SDP_UINT16), \ 452 BT_SDP_ARRAY_16(BT_SDP_PRIMARY_LANG_BASE) } \ 453 ), \ 454 } \ 455 }, \ 456 { \ 457 BT_SDP_ATTR_BROWSE_GRP_LIST, \ 458 { BT_SDP_TYPE_SIZE_VAR(BT_SDP_SEQ8, 3), \ 459 BT_SDP_DATA_ELEM_LIST( \ 460 { BT_SDP_TYPE_SIZE(BT_SDP_UUID16), \ 461 BT_SDP_ARRAY_16(BT_SDP_PUBLIC_BROWSE_GROUP) }, \ 462 ), \ 463 } \ 464 } 465 466 467 /** 468 * @brief Generic SDP List Attribute Declaration Macro. 469 * 470 * Helper macro to declare a list attribute. 471 * 472 * @param _att_id List Attribute ID. 473 * @param _data_elem_seq Data element sequence for the list. 474 * @param _type_size SDP type and size descriptor. 475 */ 476 #define BT_SDP_LIST(_att_id, _type_size, _data_elem_seq) \ 477 { \ 478 _att_id, { _type_size, _data_elem_seq } \ 479 } 480 481 /** 482 * @brief SDP Service ID Attribute Declaration Macro. 483 * 484 * Helper macro to declare a service ID attribute. 485 * 486 * @param _uuid Service ID 16bit UUID. 487 */ 488 #define BT_SDP_SERVICE_ID(_uuid) \ 489 { \ 490 BT_SDP_ATTR_SERVICE_ID, \ 491 { BT_SDP_TYPE_SIZE(BT_SDP_UUID16), &((struct bt_uuid_16) _uuid) } \ 492 } 493 494 /** 495 * @brief SDP Name Attribute Declaration Macro. 496 * 497 * Helper macro to declare a service name attribute. 498 * 499 * @param _name Service name as a string (up to 256 chars). 500 */ 501 #define BT_SDP_SERVICE_NAME(_name) \ 502 { \ 503 BT_SDP_ATTR_SVCNAME_PRIMARY, \ 504 { BT_SDP_TYPE_SIZE_VAR(BT_SDP_TEXT_STR8, (sizeof(_name)-1)), _name } \ 505 } 506 507 /** 508 * @brief SDP Supported Features Attribute Declaration Macro. 509 * 510 * Helper macro to declare supported features of a profile/protocol. 511 * 512 * @param _features Feature mask as 16bit unsigned integer. 513 */ 514 #define BT_SDP_SUPPORTED_FEATURES(_features) \ 515 { \ 516 BT_SDP_ATTR_SUPPORTED_FEATURES, \ 517 { BT_SDP_TYPE_SIZE(BT_SDP_UINT16), BT_SDP_ARRAY_16(_features) } \ 518 } 519 520 /** 521 * @brief SDP Supported Capabilities Attribute Declaration Macro. 522 * 523 * Helper macro to declare supported capabilities of a profile/protocol. 524 * 525 * @param _capabilities Capability mask as 8bit unsigned integer. 526 */ 527 #define BT_SDP_SUPPORTED_CAPABILITIES(_capabilities) \ 528 { \ 529 BT_SDP_ATTR_SUPPORTED_CAPABILITIES, \ 530 { BT_SDP_TYPE_SIZE(BT_SDP_UINT8), BT_SDP_ARRAY_8(_capabilities) } \ 531 } 532 533 /** 534 * @brief SDP Supported Functions Attribute Declaration Macro. 535 * 536 * Helper macro to declare supported functions of a profile/protocol. 537 * 538 * @param _functions Function mask as 32bit unsigned integer. 539 */ 540 #define BT_SDP_SUPPORTED_FUNCTIONS(_functions) \ 541 { \ 542 BT_SDP_ATTR_SUPPORTED_FUNCTIONS, \ 543 { BT_SDP_TYPE_SIZE(BT_SDP_UINT32), BT_SDP_ARRAY_32(_functions) } \ 544 } 545 546 /** 547 * @brief SDP Service Declaration Macro. 548 * 549 * Helper macro to declare a service. 550 * 551 * @param _attrs List of attributes for the service record. 552 */ 553 #define BT_SDP_RECORD(_attrs) \ 554 { \ 555 .attrs = _attrs, \ 556 .attr_count = ARRAY_SIZE((_attrs)), \ 557 } 558 559 /* Server API */ 560 561 /** @brief Register a Service Record. 562 * 563 * Register a Service Record. Applications can make use of 564 * macros such as BT_SDP_DECLARE_SERVICE, BT_SDP_LIST, 565 * BT_SDP_SERVICE_ID, BT_SDP_SERVICE_NAME, etc. 566 * A service declaration must start with BT_SDP_NEW_SERVICE. 567 * 568 * @param service Service record declared using BT_SDP_DECLARE_SERVICE. 569 * 570 * @return 0 in case of success or negative value in case of error. 571 */ 572 int bt_sdp_register_service(struct bt_sdp_record *service); 573 574 /* Client API */ 575 576 /** @brief Generic SDP Client Query Result data holder */ 577 struct bt_sdp_client_result { 578 /** buffer containing unparsed SDP record result for given UUID */ 579 struct net_buf *resp_buf; 580 /** flag pointing that there are more result chunks for given UUID */ 581 bool next_record_hint; 582 }; 583 584 /** @brief Helper enum to be used as return value of bt_sdp_discover_func_t. 585 * The value informs the caller to perform further pending actions or stop them. 586 */ 587 enum { 588 BT_SDP_DISCOVER_UUID_STOP = 0, 589 BT_SDP_DISCOVER_UUID_CONTINUE, 590 }; 591 592 struct bt_sdp_discover_params; 593 594 /** @typedef bt_sdp_discover_func_t 595 * 596 * @brief Callback type reporting to user that there is a resolved result 597 * on remote for given UUID and the result record buffer can be used by user 598 * for further inspection. 599 * 600 * A function of this type is given by the user to the bt_sdp_discover_params 601 * object. It'll be called on each valid record discovery completion for given 602 * UUID. When UUID resolution gives back no records then NULL is passed 603 * to the user. Otherwise user can get valid record(s) and then the internal 604 * hint 'next record' is set to false saying the UUID resolution is complete or 605 * the hint can be set by caller to true meaning that next record is available 606 * for given UUID. 607 * The returned function value allows the user to control retrieving follow-up 608 * resolved records if any. If the user doesn't want to read more resolved 609 * records for given UUID since current record data fulfills its requirements 610 * then should return BT_SDP_DISCOVER_UUID_STOP. Otherwise returned value means 611 * more subcall iterations are allowable. 612 * 613 * @param conn Connection object identifying connection to queried remote. 614 * @param result Object pointing to logical unparsed SDP record collected on 615 * base of response driven by given discover params. 616 * @param params Discover parameters. 617 * 618 * @return BT_SDP_DISCOVER_UUID_STOP in case of no more need to read next 619 * record data and continue discovery for given UUID. By returning 620 * @return BT_SDP_DISCOVER_UUID_CONTINUE user allows this discovery continuation. 621 */ 622 typedef uint8_t (*bt_sdp_discover_func_t)(struct bt_conn *conn, struct bt_sdp_client_result *result, 623 const struct bt_sdp_discover_params *params); 624 625 /** SDP Discover types */ 626 enum { 627 /** Discover Service Search. */ 628 BT_SDP_DISCOVER_SERVICE_SEARCH, 629 /** Discover Service Attribute. */ 630 BT_SDP_DISCOVER_SERVICE_ATTR, 631 /** Discover Service Search Attribute. */ 632 BT_SDP_DISCOVER_SERVICE_SEARCH_ATTR, 633 }; 634 635 /** Initializes SDP attribute ID range */ 636 #define BT_SDP_ATTR_ID_RANGE(beginning, ending) {(beginning), (ending)} 637 638 /** 639 * @brief SDP attribute ID range 640 * 641 * If the beginning attribute ID is same with the ending attribute ID, the range represents a 642 * single attribute ID. 643 */ 644 struct bt_sdp_attribute_id_range { 645 /** Beginning attribute ID of the range */ 646 uint16_t beginning; 647 /** Ending attribute ID of the range */ 648 uint16_t ending; 649 }; 650 651 /** @brief SDP attribute ID list for Service Attribute and Service Search Attribute transactions */ 652 struct bt_sdp_attribute_id_list { 653 /** Count of the SDP attribute ID range */ 654 size_t count; 655 /** Attribute ID range array list */ 656 struct bt_sdp_attribute_id_range *ranges; 657 }; 658 659 /** @brief Main user structure used in SDP discovery of remote. */ 660 struct bt_sdp_discover_params { 661 sys_snode_t _node; 662 union { 663 /** UUID (service) to be discovered on remote SDP entity */ 664 const struct bt_uuid *uuid; 665 /** Service record handle */ 666 uint32_t handle; 667 }; 668 /** Discover callback to be called on resolved SDP record */ 669 bt_sdp_discover_func_t func; 670 /** Memory buffer enabled by user for SDP query results */ 671 struct net_buf_pool *pool; 672 /** Discover type */ 673 uint8_t type; 674 /** 675 * Attribute ID list for Service Attribute and Service Search Attribute transactions 676 * 677 * If the `ids` is NULL or `ids->count` is 0, the default range `(0x0000, 0xffff)` will 678 * be used. 679 */ 680 struct bt_sdp_attribute_id_list *ids; 681 }; 682 683 /** @brief Allows user to start SDP discovery session. 684 * 685 * The function performs SDP service discovery on remote server driven by user 686 * delivered discovery parameters. Discovery session is made as soon as 687 * no SDP transaction is ongoing between peers and if any then this one 688 * is queued to be processed at discovery completion of previous one. 689 * On the service discovery completion the callback function will be 690 * called to get feedback to user about findings. 691 * 692 * If the UUID is UUID 128 for discovery type `Service Search` and 693 * `Service Search Attribute`, the UUID data should be represented as the 694 * little-endian byteorder sequence. 695 * 696 * Service Search: The SDP Client generates an 697 * SDP_SERVICE_SEARCH_REQ to locate service 698 * records that match the service search 699 * pattern (`params->uuid`) given as the first 700 * parameter of the PDU. 701 * Service Attribute: The SDP Client generates an 702 * SDP_SERVICE_ATTR_REQ to retrieve specified 703 * attribute values from a specific service 704 * record (`params->handle`). The AttributeIDList 705 * is specified by `params->ids`. 706 * Service Search Attribute: The SDP Client generates an 707 * SDP_SERVICE_SEARCH_ATTR_REQ to retrieve 708 * specified attribute values that match the 709 * service search pattern (`params->uuid`) 710 * given as the first parameter of the PDU. 711 * The AttributeIDList is specified by `params->ids`. 712 * 713 * @param conn Object identifying connection to remote. 714 * @param params SDP discovery parameters. 715 * 716 * @return 0 in case of success or negative value in case of error. 717 */ 718 719 int bt_sdp_discover(struct bt_conn *conn, 720 struct bt_sdp_discover_params *params); 721 722 /** @brief Release waiting SDP discovery request. 723 * 724 * It can cancel valid waiting SDP client request identified by SDP discovery 725 * parameters object. 726 * 727 * @param conn Object identifying connection to remote. 728 * @param params SDP discovery parameters. 729 * 730 * @return 0 in case of success or negative value in case of error. 731 */ 732 int bt_sdp_discover_cancel(struct bt_conn *conn, 733 const struct bt_sdp_discover_params *params); 734 735 736 /* Helper types & functions for SDP client to get essential data from server */ 737 738 /** @brief Give to user parameter value related to given stacked protocol UUID. 739 * 740 * API extracts specific parameter associated with given protocol UUID 741 * available in Protocol Descriptor List attribute. 742 * 743 * @param buf Original buffered raw record data. 744 * @param proto Known protocol to be checked like RFCOMM or L2CAP. 745 * @param param On success populated by found parameter value. 746 * 747 * @return 0 on success when specific parameter associated with given protocol 748 * value is found, or negative if error occurred during processing. 749 */ 750 int bt_sdp_get_proto_param(const struct net_buf *buf, uint16_t proto, 751 uint16_t *param); 752 753 /** @brief Get additional parameter value related to given stacked protocol UUID. 754 * 755 * API extracts specific parameter associated with given protocol UUID 756 * available in Additional Protocol Descriptor List attribute. 757 * 758 * @param buf Original buffered raw record data. 759 * @param proto Known protocol to be checked like RFCOMM or L2CAP. 760 * @param index Zero-based index of the protocol descriptor (alternative protocol stack). 761 * Use 0 for the first protocol descriptor, 1 for the second, etc. 762 * @param[out] param On success populated by found parameter value. 763 * 764 * @return 0 on success when a specific parameter associated with a given protocol 765 * value is found, or negative if error occurred during processing. 766 */ 767 int bt_sdp_get_addl_proto_param(const struct net_buf *buf, uint16_t proto, uint8_t index, 768 uint16_t *param); 769 770 /** @brief Get profile version. 771 * 772 * Helper API extracting remote profile version number. To get it proper 773 * generic profile parameter needs to be selected usually listed in SDP 774 * Interoperability Requirements section for given profile specification. 775 * 776 * @param buf Original buffered raw record data. 777 * @param profile Profile family identifier the profile belongs. 778 * @param version On success populated by found version number. 779 * 780 * @return 0 on success, negative value if error occurred during processing. 781 */ 782 int bt_sdp_get_profile_version(const struct net_buf *buf, uint16_t profile, 783 uint16_t *version); 784 785 /** @brief Get SupportedFeatures attribute value 786 * 787 * Allows if exposed by remote retrieve SupportedFeature attribute. 788 * 789 * @param buf Buffer holding original raw record data from remote. 790 * @param features On success object to be populated with SupportedFeature 791 * mask. 792 * 793 * @return 0 on success if feature found and valid, negative in case any error 794 */ 795 int bt_sdp_get_features(const struct net_buf *buf, uint16_t *features); 796 797 /** @brief Get Vendor ID 798 * 799 * Helper API extracting remote Vendor ID. To get it proper 800 * generic profile parameter needs to be selected usually listed in SDP 801 * Interoperability Requirements section for given profile specification. 802 * 803 * @param buf Buffer holding original raw record data from remote. 804 * @param vendor_id On success populated by found Vendor ID. 805 * 806 * @return 0 on success if vendor_id found and valid, negative in case any error 807 */ 808 int bt_sdp_get_vendor_id(const struct net_buf *buf, uint16_t *vendor_id); 809 810 /** @brief Get Product ID 811 * 812 * Helper API extracting remote Product ID. To get it proper 813 * generic profile parameter needs to be selected usually listed in SDP 814 * Interoperability Requirements section for given profile specification. 815 * 816 * @param buf Buffer holding original raw record data from remote. 817 * @param product_id On success populated by found Product ID. 818 * mask. 819 * 820 * @return 0 on success if product_id found and valid, negative in case any error 821 */ 822 int bt_sdp_get_product_id(const struct net_buf *buf, uint16_t *product_id); 823 824 /** @brief Iterate through discovered SDP record 825 * 826 * Helper API iterating through the discovered SDP record. It parses the specified SDP RAW record 827 * data in the provided buffer and calls the specified callback function for each attribute found. 828 * The iteration continues until all attributes have been processed or the callback function 829 * returns false to stop the iteration. 830 * 831 * @param buf Buffer holding original discovered raw SDP record data from remote. 832 * @param func Callback function to be called for each attribute. 833 * The callback receives a pointer to the current attribute and user-provided data. 834 * Return the `true` to continue iteration, `false` to stop. 835 * @param user_data Optional user-provided context data passed to the callback function. 836 * 837 * @return 0 on success, negative value on error during the parsing or iteration. 838 */ 839 int bt_sdp_record_parse(const struct net_buf *buf, 840 bool (*func)(const struct bt_sdp_attribute *attr, void *user_data), 841 void *user_data); 842 843 /** @brief check if the specific attribute identifier is found. 844 * 845 * API checks if the specific attribute identifier is found. 846 * 847 * @param buf Buffer containing the discovered SDP record data to be parsed. 848 * @param attr_id Specific attribute identifier. 849 * 850 * @return true if attribute identifier is found, false otherwise. 851 */ 852 bool bt_sdp_has_attr(const struct net_buf *buf, uint16_t attr_id); 853 854 /** @brief Get a specific attribute by ID from SDP record 855 * 856 * This function retrieves a specific attribute from the SDP record data by searching for the 857 * given attribute identifier. 858 * 859 * @param buf Buffer containing the discovered SDP record data to be parsed. 860 * @param attr_id The specific attribute identifier to search for. 861 * @param[out] attr Pointer to bt_sdp_attribute structure to store the found attribute. 862 * 863 * @return 0 on success when the attribute is found and populated, 864 * negative value if the attribute is not found or an error occurred. 865 */ 866 int bt_sdp_get_attr(const struct net_buf *buf, uint16_t attr_id, struct bt_sdp_attribute *attr); 867 868 /** @brief SDP attribute value for unsigned integer types 869 * 870 * Structure to hold parsed unsigned integer values from SDP attributes. 871 * The size field indicates the actual size of the integer value. 872 */ 873 struct bt_sdp_attr_value_uint { 874 /** Size of the unsigned integer value in bytes */ 875 uint8_t size; 876 /** Union containing the unsigned integer value based on size */ 877 union { 878 uint8_t u8; /**< 8-bit unsigned integer value */ 879 uint16_t u16; /**< 16-bit unsigned integer value */ 880 uint32_t u32; /**< 32-bit unsigned integer value */ 881 uint64_t u64; /**< 64-bit unsigned integer value */ 882 /** 128-bit unsigned integer value as byte array */ 883 uint8_t u128[BIT(BT_SDP_UINT128 & BT_SDP_SIZE_DESC_MASK)]; 884 }; 885 }; 886 887 /** @brief SDP attribute value for signed integer types 888 * 889 * Structure to hold parsed signed integer values from SDP attributes. 890 * The size field indicates the actual size of the integer value. 891 */ 892 struct bt_sdp_attr_value_int { 893 /** Size of the signed integer value in bytes */ 894 uint8_t size; 895 /** Union containing the signed integer value based on size */ 896 union { 897 int8_t s8; /**< 8-bit signed integer value */ 898 int16_t s16; /**< 16-bit signed integer value */ 899 int32_t s32; /**< 32-bit signed integer value */ 900 int64_t s64; /**< 64-bit signed integer value */ 901 /** 128-bit signed integer value as byte array */ 902 uint8_t s128[BIT(BT_SDP_INT128 & BT_SDP_SIZE_DESC_MASK)]; 903 }; 904 }; 905 906 /** @brief SDP attribute value for text string types 907 * 908 * Structure to hold parsed text string values from SDP attributes. 909 */ 910 struct bt_sdp_attr_value_text { 911 /** Length of the text string in bytes */ 912 uint32_t len; 913 /** Pointer to the text string data */ 914 uint8_t *text; 915 }; 916 917 /** @brief SDP attribute value for URL string types 918 * 919 * Structure to hold parsed URL string values from SDP attributes. 920 */ 921 struct bt_sdp_attr_value_url { 922 /** Length of the URL string in bytes */ 923 uint32_t len; 924 /** Pointer to the URL string data */ 925 uint8_t *url; 926 }; 927 928 /** @brief SDP attribute value type enumeration 929 * 930 * Enumeration defining the different types of attribute values 931 * that can be parsed from SDP attributes. 932 */ 933 enum bt_sdp_attr_value_type { 934 BT_SDP_ATTR_VALUE_TYPE_NONE = 0, /**< No value */ 935 BT_SDP_ATTR_VALUE_TYPE_UINT, /**< Unsigned integer */ 936 BT_SDP_ATTR_VALUE_TYPE_SINT, /**< Signed integer */ 937 BT_SDP_ATTR_VALUE_TYPE_BOOL, /**< Boolean */ 938 BT_SDP_ATTR_VALUE_TYPE_TEXT, /**< Text string */ 939 BT_SDP_ATTR_VALUE_TYPE_URL, /**< URL string */ 940 }; 941 942 /** @brief SDP attribute value container structure 943 * 944 * Structure that holds a parsed attribute value of any supported type. 945 * The type field indicates which member of the union contains the actual value. 946 * This structure provides a unified way to handle different types of SDP 947 * attribute values after parsing. 948 */ 949 struct bt_sdp_attr_value { 950 /** Type of the attribute value */ 951 enum bt_sdp_attr_value_type type; 952 /** Union containing the actual attribute value based on type */ 953 union { 954 /**< Boolean value (when type is BT_SDP_ATTR_VALUE_TYPE_BOOL) */ 955 bool value; 956 /**< Unsigned integer value (when type is BT_SDP_ATTR_VALUE_TYPE_UINT) */ 957 struct bt_sdp_attr_value_uint uint; 958 /**< Signed integer value (when type is BT_SDP_ATTR_VALUE_TYPE_SINT) */ 959 struct bt_sdp_attr_value_int sint; 960 /**< Text string value (when type is BT_SDP_ATTR_VALUE_TYPE_TEXT) */ 961 struct bt_sdp_attr_value_text text; 962 /**< URL string value (when type is BT_SDP_ATTR_VALUE_TYPE_URL) */ 963 struct bt_sdp_attr_value_url url; 964 }; 965 }; 966 967 /** @brief SDP attribute value pair structure 968 * 969 * Structure containing parsed attribute value information including the UUID identifier and the 970 * actual value with its type. This structure is used to associate a UUID with its corresponding 971 * attribute value, providing a complete representation of a parsed SDP attribute element. 972 * 973 * @note The UUID and value pointers will be invalid if the callback function returned. 974 * 975 * @note The UUID or value pointer may be NULL. If the UUID is NULL, it means the value does not 976 * belong to any UUID. If the value is NULL, it means UUID has not value. 977 */ 978 struct bt_sdp_attr_value_pair { 979 /** UUID identifier for the attribute */ 980 struct bt_uuid *uuid; 981 /** Pointer to the parsed attribute value */ 982 struct bt_sdp_attr_value *value; 983 }; 984 985 /** @brief Parse SDP attribute values 986 * 987 * Parses the SDP attribute and calls the provided callback function for each parsed value found 988 * within the attribute. This function handles complex attribute structures that may contain 989 * multiple values. 990 * 991 * @param attr Pointer to the SDP attribute to be parsed. 992 * @param func Callback function to be called for each parsed value. 993 * The callback receives a bt_sdp_attr_value_pair structure 994 * containing the parsed value and user data. 995 * Return true to continue parsing, false to stop. 996 * @param user_data Optional user-provided context data passed to the callback. 997 * 998 * @return 0 on success, negative value if an error occurred during parsing. 999 */ 1000 int bt_sdp_attr_value_parse(const struct bt_sdp_attribute *attr, 1001 bool (*func)(const struct bt_sdp_attr_value_pair *value, 1002 void *user_data), 1003 void *user_data); 1004 1005 /** @brief Check if SDP attribute contains a specific UUID 1006 * 1007 * This function checks whether the specified SDP attribute contains the given UUID. This is 1008 * useful for verifying if an attribute references a particular service or protocol UUID. 1009 * 1010 * @param attr Pointer to the SDP attribute to be checked. 1011 * @param uuid Pointer to the UUID to search for within the attribute. 1012 * 1013 * @return true if the attribute contains the specified UUID, false otherwise. 1014 */ 1015 bool bt_sdp_attr_has_uuid(const struct bt_sdp_attribute *attr, const struct bt_uuid *uuid); 1016 1017 /** @brief Read SDP attribute value for a specific UUID 1018 * 1019 * This function reads and extracts the attribute value associated with the specified UUID 1020 * from the given SDP attribute. The parsed value is stored in the provided bt_sdp_attr_value 1021 * structure. 1022 * 1023 * @param attr Pointer to the SDP attribute to read from. 1024 * @param uuid Pointer to the UUID identifier for the value to be read. 1025 * @param[out] value Pointer to bt_sdp_attr_value structure to store the extracted attribute value. 1026 * 1027 * @return 0 on success when the value is found and extracted, negative value if the UUID is not 1028 * found or an error occurred. 1029 */ 1030 int bt_sdp_attr_read(const struct bt_sdp_attribute *attr, const struct bt_uuid *uuid, 1031 struct bt_sdp_attr_value *value); 1032 1033 /** @brief Parse Additional Protocol Descriptor List attribute 1034 * 1035 * This function parses the Additional Protocol Descriptor List attribute and calls the provided 1036 * callback function for each protocol descriptor found within the attribute. The Additional 1037 * Protocol Descriptor List contains alternative protocol stacks that can be used to access 1038 * the service. 1039 * 1040 * @param attr Pointer to the SDP attribute containing Additional Protocol Descriptor List. 1041 * @param func Callback function to be called for each protocol descriptor. 1042 * The callback receives a pointer to the protocol descriptor attribute 1043 * and user-provided data. Return true to continue parsing, false to stop. 1044 * @param user_data Optional user-provided context data passed to the callback function. 1045 * 1046 * @return 0 on success, negative value if an error occurred during parsing. 1047 */ 1048 int bt_sdp_attr_addl_proto_parse(const struct bt_sdp_attribute *attr, 1049 bool (*func)(const struct bt_sdp_attribute *attr, void *user_data), 1050 void *user_data); 1051 1052 /** @brief Get count of protocol descriptors in Additional Protocol Descriptor List 1053 * 1054 * This function returns the number of protocol descriptors contained in the 1055 * Additional Protocol Descriptor List attribute. This is useful for determining 1056 * how many alternative protocol stacks are available for the service. 1057 * 1058 * @param attr Pointer to the SDP attribute containing Additional Protocol Descriptor List. 1059 * 1060 * @return Number of protocol descriptors found on success, negative value if an error 1061 * occurred during parsing. 1062 */ 1063 ssize_t bt_sdp_attr_addl_proto_count(const struct bt_sdp_attribute *attr); 1064 1065 /** @brief Read value from Additional Protocol Descriptor List for specific index and UUID 1066 * 1067 * This function searches the Additional Protocol Descriptor List attribute for a specific 1068 * protocol UUID at the given protocol descriptor index and extracts its associated parameter 1069 * value. The index parameter specifies which protocol descriptor (alternative protocol stack) 1070 * to search within, and the UUID identifies the specific protocol within that descriptor. 1071 * 1072 * @param attr Pointer to the SDP attribute containing Additional Protocol Descriptor List. 1073 * @param index Zero-based index of the protocol descriptor (alternative protocol stack). 1074 * Use 0 for the first protocol descriptor, 1 for the second, etc. 1075 * @param uuid Pointer to the UUID identifier of the protocol to search for within 1076 * the specified protocol descriptor. 1077 * @param[out] value Pointer to bt_sdp_attr_value structure to store the extracted parameter value. 1078 * 1079 * @return 0 on success when the protocol and its parameter are found and extracted, 1080 * negative value if the protocol descriptor index is invalid, the UUID is not 1081 * found within the specified descriptor, or an error occurred during parsing. 1082 */ 1083 int bt_sdp_attr_addl_proto_read(const struct bt_sdp_attribute *attr, uint16_t index, 1084 const struct bt_uuid *uuid, struct bt_sdp_attr_value *value); 1085 1086 #ifdef __cplusplus 1087 } 1088 #endif 1089 1090 /** 1091 * @} 1092 */ 1093 1094 #endif /* ZEPHYR_INCLUDE_BLUETOOTH_SDP_H_ */ 1095