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 * @brief Service Discovery Protocol (SDP) 15 * @defgroup bt_sdp Service Discovery Protocol (SDP) 16 * @ingroup bluetooth 17 * @{ 18 */ 19 20 #include <bluetooth/uuid.h> 21 #include <bluetooth/conn.h> 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 /* 28 * All definitions are based on Bluetooth Assigned Numbers 29 * of the Bluetooth Specification 30 */ 31 32 /* 33 * Service class identifiers of standard services and service groups 34 */ 35 #define BT_SDP_SDP_SERVER_SVCLASS 0x1000 36 #define BT_SDP_BROWSE_GRP_DESC_SVCLASS 0x1001 37 #define BT_SDP_PUBLIC_BROWSE_GROUP 0x1002 38 #define BT_SDP_SERIAL_PORT_SVCLASS 0x1101 39 #define BT_SDP_LAN_ACCESS_SVCLASS 0x1102 40 #define BT_SDP_DIALUP_NET_SVCLASS 0x1103 41 #define BT_SDP_IRMC_SYNC_SVCLASS 0x1104 42 #define BT_SDP_OBEX_OBJPUSH_SVCLASS 0x1105 43 #define BT_SDP_OBEX_FILETRANS_SVCLASS 0x1106 44 #define BT_SDP_IRMC_SYNC_CMD_SVCLASS 0x1107 45 #define BT_SDP_HEADSET_SVCLASS 0x1108 46 #define BT_SDP_CORDLESS_TELEPHONY_SVCLASS 0x1109 47 #define BT_SDP_AUDIO_SOURCE_SVCLASS 0x110a 48 #define BT_SDP_AUDIO_SINK_SVCLASS 0x110b 49 #define BT_SDP_AV_REMOTE_TARGET_SVCLASS 0x110c 50 #define BT_SDP_ADVANCED_AUDIO_SVCLASS 0x110d 51 #define BT_SDP_AV_REMOTE_SVCLASS 0x110e 52 #define BT_SDP_AV_REMOTE_CONTROLLER_SVCLASS 0x110f 53 #define BT_SDP_INTERCOM_SVCLASS 0x1110 54 #define BT_SDP_FAX_SVCLASS 0x1111 55 #define BT_SDP_HEADSET_AGW_SVCLASS 0x1112 56 #define BT_SDP_WAP_SVCLASS 0x1113 57 #define BT_SDP_WAP_CLIENT_SVCLASS 0x1114 58 #define BT_SDP_PANU_SVCLASS 0x1115 59 #define BT_SDP_NAP_SVCLASS 0x1116 60 #define BT_SDP_GN_SVCLASS 0x1117 61 #define BT_SDP_DIRECT_PRINTING_SVCLASS 0x1118 62 #define BT_SDP_REFERENCE_PRINTING_SVCLASS 0x1119 63 #define BT_SDP_IMAGING_SVCLASS 0x111a 64 #define BT_SDP_IMAGING_RESPONDER_SVCLASS 0x111b 65 #define BT_SDP_IMAGING_ARCHIVE_SVCLASS 0x111c 66 #define BT_SDP_IMAGING_REFOBJS_SVCLASS 0x111d 67 #define BT_SDP_HANDSFREE_SVCLASS 0x111e 68 #define BT_SDP_HANDSFREE_AGW_SVCLASS 0x111f 69 #define BT_SDP_DIRECT_PRT_REFOBJS_SVCLASS 0x1120 70 #define BT_SDP_REFLECTED_UI_SVCLASS 0x1121 71 #define BT_SDP_BASIC_PRINTING_SVCLASS 0x1122 72 #define BT_SDP_PRINTING_STATUS_SVCLASS 0x1123 73 #define BT_SDP_HID_SVCLASS 0x1124 74 #define BT_SDP_HCR_SVCLASS 0x1125 75 #define BT_SDP_HCR_PRINT_SVCLASS 0x1126 76 #define BT_SDP_HCR_SCAN_SVCLASS 0x1127 77 #define BT_SDP_CIP_SVCLASS 0x1128 78 #define BT_SDP_VIDEO_CONF_GW_SVCLASS 0x1129 79 #define BT_SDP_UDI_MT_SVCLASS 0x112a 80 #define BT_SDP_UDI_TA_SVCLASS 0x112b 81 #define BT_SDP_AV_SVCLASS 0x112c 82 #define BT_SDP_SAP_SVCLASS 0x112d 83 #define BT_SDP_PBAP_PCE_SVCLASS 0x112e 84 #define BT_SDP_PBAP_PSE_SVCLASS 0x112f 85 #define BT_SDP_PBAP_SVCLASS 0x1130 86 #define BT_SDP_MAP_MSE_SVCLASS 0x1132 87 #define BT_SDP_MAP_MCE_SVCLASS 0x1133 88 #define BT_SDP_MAP_SVCLASS 0x1134 89 #define BT_SDP_GNSS_SVCLASS 0x1135 90 #define BT_SDP_GNSS_SERVER_SVCLASS 0x1136 91 #define BT_SDP_MPS_SC_SVCLASS 0x113a 92 #define BT_SDP_MPS_SVCLASS 0x113b 93 #define BT_SDP_PNP_INFO_SVCLASS 0x1200 94 #define BT_SDP_GENERIC_NETWORKING_SVCLASS 0x1201 95 #define BT_SDP_GENERIC_FILETRANS_SVCLASS 0x1202 96 #define BT_SDP_GENERIC_AUDIO_SVCLASS 0x1203 97 #define BT_SDP_GENERIC_TELEPHONY_SVCLASS 0x1204 98 #define BT_SDP_UPNP_SVCLASS 0x1205 99 #define BT_SDP_UPNP_IP_SVCLASS 0x1206 100 #define BT_SDP_UPNP_PAN_SVCLASS 0x1300 101 #define BT_SDP_UPNP_LAP_SVCLASS 0x1301 102 #define BT_SDP_UPNP_L2CAP_SVCLASS 0x1302 103 #define BT_SDP_VIDEO_SOURCE_SVCLASS 0x1303 104 #define BT_SDP_VIDEO_SINK_SVCLASS 0x1304 105 #define BT_SDP_VIDEO_DISTRIBUTION_SVCLASS 0x1305 106 #define BT_SDP_HDP_SVCLASS 0x1400 107 #define BT_SDP_HDP_SOURCE_SVCLASS 0x1401 108 #define BT_SDP_HDP_SINK_SVCLASS 0x1402 109 #define BT_SDP_GENERIC_ACCESS_SVCLASS 0x1800 110 #define BT_SDP_GENERIC_ATTRIB_SVCLASS 0x1801 111 #define BT_SDP_APPLE_AGENT_SVCLASS 0x2112 112 113 /* 114 * Attribute identifier codes 115 */ 116 #define BT_SDP_SERVER_RECORD_HANDLE 0x0000 117 118 /* 119 * Possible values for attribute-id are listed below. 120 * See SDP Spec, section "Service Attribute Definitions" for more details. 121 */ 122 #define BT_SDP_ATTR_RECORD_HANDLE 0x0000 123 #define BT_SDP_ATTR_SVCLASS_ID_LIST 0x0001 124 #define BT_SDP_ATTR_RECORD_STATE 0x0002 125 #define BT_SDP_ATTR_SERVICE_ID 0x0003 126 #define BT_SDP_ATTR_PROTO_DESC_LIST 0x0004 127 #define BT_SDP_ATTR_BROWSE_GRP_LIST 0x0005 128 #define BT_SDP_ATTR_LANG_BASE_ATTR_ID_LIST 0x0006 129 #define BT_SDP_ATTR_SVCINFO_TTL 0x0007 130 #define BT_SDP_ATTR_SERVICE_AVAILABILITY 0x0008 131 #define BT_SDP_ATTR_PROFILE_DESC_LIST 0x0009 132 #define BT_SDP_ATTR_DOC_URL 0x000a 133 #define BT_SDP_ATTR_CLNT_EXEC_URL 0x000b 134 #define BT_SDP_ATTR_ICON_URL 0x000c 135 #define BT_SDP_ATTR_ADD_PROTO_DESC_LIST 0x000d 136 137 #define BT_SDP_ATTR_GROUP_ID 0x0200 138 #define BT_SDP_ATTR_IP_SUBNET 0x0200 139 #define BT_SDP_ATTR_VERSION_NUM_LIST 0x0200 140 #define BT_SDP_ATTR_SUPPORTED_FEATURES_LIST 0x0200 141 #define BT_SDP_ATTR_GOEP_L2CAP_PSM 0x0200 142 #define BT_SDP_ATTR_SVCDB_STATE 0x0201 143 144 #define BT_SDP_ATTR_MPSD_SCENARIOS 0x0200 145 #define BT_SDP_ATTR_MPMD_SCENARIOS 0x0201 146 #define BT_SDP_ATTR_MPS_DEPENDENCIES 0x0202 147 148 #define BT_SDP_ATTR_SERVICE_VERSION 0x0300 149 #define BT_SDP_ATTR_EXTERNAL_NETWORK 0x0301 150 #define BT_SDP_ATTR_SUPPORTED_DATA_STORES_LIST 0x0301 151 #define BT_SDP_ATTR_DATA_EXCHANGE_SPEC 0x0301 152 #define BT_SDP_ATTR_NETWORK 0x0301 153 #define BT_SDP_ATTR_FAX_CLASS1_SUPPORT 0x0302 154 #define BT_SDP_ATTR_REMOTE_AUDIO_VOLUME_CONTROL 0x0302 155 #define BT_SDP_ATTR_MCAP_SUPPORTED_PROCEDURES 0x0302 156 #define BT_SDP_ATTR_FAX_CLASS20_SUPPORT 0x0303 157 #define BT_SDP_ATTR_SUPPORTED_FORMATS_LIST 0x0303 158 #define BT_SDP_ATTR_FAX_CLASS2_SUPPORT 0x0304 159 #define BT_SDP_ATTR_AUDIO_FEEDBACK_SUPPORT 0x0305 160 #define BT_SDP_ATTR_NETWORK_ADDRESS 0x0306 161 #define BT_SDP_ATTR_WAP_GATEWAY 0x0307 162 #define BT_SDP_ATTR_HOMEPAGE_URL 0x0308 163 #define BT_SDP_ATTR_WAP_STACK_TYPE 0x0309 164 #define BT_SDP_ATTR_SECURITY_DESC 0x030a 165 #define BT_SDP_ATTR_NET_ACCESS_TYPE 0x030b 166 #define BT_SDP_ATTR_MAX_NET_ACCESSRATE 0x030c 167 #define BT_SDP_ATTR_IP4_SUBNET 0x030d 168 #define BT_SDP_ATTR_IP6_SUBNET 0x030e 169 #define BT_SDP_ATTR_SUPPORTED_CAPABILITIES 0x0310 170 #define BT_SDP_ATTR_SUPPORTED_FEATURES 0x0311 171 #define BT_SDP_ATTR_SUPPORTED_FUNCTIONS 0x0312 172 #define BT_SDP_ATTR_TOTAL_IMAGING_DATA_CAPACITY 0x0313 173 #define BT_SDP_ATTR_SUPPORTED_REPOSITORIES 0x0314 174 #define BT_SDP_ATTR_MAS_INSTANCE_ID 0x0315 175 #define BT_SDP_ATTR_SUPPORTED_MESSAGE_TYPES 0x0316 176 #define BT_SDP_ATTR_PBAP_SUPPORTED_FEATURES 0x0317 177 #define BT_SDP_ATTR_MAP_SUPPORTED_FEATURES 0x0317 178 179 #define BT_SDP_ATTR_SPECIFICATION_ID 0x0200 180 #define BT_SDP_ATTR_VENDOR_ID 0x0201 181 #define BT_SDP_ATTR_PRODUCT_ID 0x0202 182 #define BT_SDP_ATTR_VERSION 0x0203 183 #define BT_SDP_ATTR_PRIMARY_RECORD 0x0204 184 #define BT_SDP_ATTR_VENDOR_ID_SOURCE 0x0205 185 186 #define BT_SDP_ATTR_HID_DEVICE_RELEASE_NUMBER 0x0200 187 #define BT_SDP_ATTR_HID_PARSER_VERSION 0x0201 188 #define BT_SDP_ATTR_HID_DEVICE_SUBCLASS 0x0202 189 #define BT_SDP_ATTR_HID_COUNTRY_CODE 0x0203 190 #define BT_SDP_ATTR_HID_VIRTUAL_CABLE 0x0204 191 #define BT_SDP_ATTR_HID_RECONNECT_INITIATE 0x0205 192 #define BT_SDP_ATTR_HID_DESCRIPTOR_LIST 0x0206 193 #define BT_SDP_ATTR_HID_LANG_ID_BASE_LIST 0x0207 194 #define BT_SDP_ATTR_HID_SDP_DISABLE 0x0208 195 #define BT_SDP_ATTR_HID_BATTERY_POWER 0x0209 196 #define BT_SDP_ATTR_HID_REMOTE_WAKEUP 0x020a 197 #define BT_SDP_ATTR_HID_PROFILE_VERSION 0x020b 198 #define BT_SDP_ATTR_HID_SUPERVISION_TIMEOUT 0x020c 199 #define BT_SDP_ATTR_HID_NORMALLY_CONNECTABLE 0x020d 200 #define BT_SDP_ATTR_HID_BOOT_DEVICE 0x020e 201 202 /* 203 * These identifiers are based on the SDP spec stating that 204 * "base attribute id of the primary (universal) language must be 0x0100" 205 * 206 * Other languages should have their own offset; e.g.: 207 * #define XXXLangBase yyyy 208 * #define AttrServiceName_XXX 0x0000+XXXLangBase 209 */ 210 #define BT_SDP_PRIMARY_LANG_BASE 0x0100 211 212 #define BT_SDP_ATTR_SVCNAME_PRIMARY (0x0000 + BT_SDP_PRIMARY_LANG_BASE) 213 #define BT_SDP_ATTR_SVCDESC_PRIMARY (0x0001 + BT_SDP_PRIMARY_LANG_BASE) 214 #define BT_SDP_ATTR_PROVNAME_PRIMARY (0x0002 + BT_SDP_PRIMARY_LANG_BASE) 215 216 /* 217 * The Data representation in SDP PDUs (pps 339, 340 of BT SDP Spec) 218 * These are the exact data type+size descriptor values 219 * that go into the PDU buffer. 220 * 221 * The datatype (leading 5bits) + size descriptor (last 3 bits) 222 * is 8 bits. The size descriptor is critical to extract the 223 * right number of bytes for the data value from the PDU. 224 * 225 * For most basic types, the datatype+size descriptor is 226 * straightforward. However for constructed types and strings, 227 * the size of the data is in the next "n" bytes following the 228 * 8 bits (datatype+size) descriptor. Exactly what the "n" is 229 * specified in the 3 bits of the data size descriptor. 230 * 231 * TextString and URLString can be of size 2^{8, 16, 32} bytes 232 * DataSequence and DataSequenceAlternates can be of size 2^{8, 16, 32} 233 * The size are computed post-facto in the API and are not known apriori 234 */ 235 #define BT_SDP_DATA_NIL 0x00 236 #define BT_SDP_UINT8 0x08 237 #define BT_SDP_UINT16 0x09 238 #define BT_SDP_UINT32 0x0a 239 #define BT_SDP_UINT64 0x0b 240 #define BT_SDP_UINT128 0x0c 241 #define BT_SDP_INT8 0x10 242 #define BT_SDP_INT16 0x11 243 #define BT_SDP_INT32 0x12 244 #define BT_SDP_INT64 0x13 245 #define BT_SDP_INT128 0x14 246 #define BT_SDP_UUID_UNSPEC 0x18 247 #define BT_SDP_UUID16 0x19 248 #define BT_SDP_UUID32 0x1a 249 #define BT_SDP_UUID128 0x1c 250 #define BT_SDP_TEXT_STR_UNSPEC 0x20 251 #define BT_SDP_TEXT_STR8 0x25 252 #define BT_SDP_TEXT_STR16 0x26 253 #define BT_SDP_TEXT_STR32 0x27 254 #define BT_SDP_BOOL 0x28 255 #define BT_SDP_SEQ_UNSPEC 0x30 256 #define BT_SDP_SEQ8 0x35 257 #define BT_SDP_SEQ16 0x36 258 #define BT_SDP_SEQ32 0x37 259 #define BT_SDP_ALT_UNSPEC 0x38 260 #define BT_SDP_ALT8 0x3d 261 #define BT_SDP_ALT16 0x3e 262 #define BT_SDP_ALT32 0x3f 263 #define BT_SDP_URL_STR_UNSPEC 0x40 264 #define BT_SDP_URL_STR8 0x45 265 #define BT_SDP_URL_STR16 0x46 266 #define BT_SDP_URL_STR32 0x47 267 268 #define BT_SDP_TYPE_DESC_MASK 0xf8 269 #define BT_SDP_SIZE_DESC_MASK 0x07 270 #define BT_SDP_SIZE_INDEX_OFFSET 5 271 272 /** @brief SDP Generic Data Element Value. */ 273 struct bt_sdp_data_elem { 274 uint8_t type; 275 uint32_t data_size; 276 uint32_t total_size; 277 const void *data; 278 }; 279 280 /** @brief SDP Attribute Value. */ 281 struct bt_sdp_attribute { 282 uint16_t id; /* Attribute ID */ 283 struct bt_sdp_data_elem val; /* Attribute data */ 284 }; 285 286 /** @brief SDP Service Record Value. */ 287 struct bt_sdp_record { 288 uint32_t handle; /* Redundant, for quick ref */ 289 struct bt_sdp_attribute *attrs; /* Base addr of attr array */ 290 size_t attr_count; /* Number of attributes */ 291 uint8_t index; /* Index of the record in LL */ 292 struct bt_sdp_record *next; 293 }; 294 295 /* 296 * --------------------------------------------------- ------------------ 297 * | Service Hdl | Attr list ptr | Attr count | Next | -> | Service Hdl | ... 298 * --------------------------------------------------- ------------------ 299 */ 300 301 /** @def BT_SDP_ARRAY_8 302 * @brief Declare an array of 8-bit elements in an attribute. 303 */ 304 #define BT_SDP_ARRAY_8(...) ((uint8_t[]) {__VA_ARGS__}) 305 306 /** @def BT_SDP_ARRAY_16 307 * @brief Declare an array of 16-bit elements in an attribute. 308 */ 309 #define BT_SDP_ARRAY_16(...) ((uint16_t[]) {__VA_ARGS__}) 310 311 /** @def BT_SDP_ARRAY_32 312 * @brief Declare an array of 32-bit elements in an attribute. 313 */ 314 #define BT_SDP_ARRAY_32(...) ((uint32_t[]) {__VA_ARGS__}) 315 316 /** @def BT_SDP_TYPE_SIZE 317 * @brief Declare a fixed-size data element header. 318 * 319 * @param _type Data element header containing type and size descriptors. 320 */ 321 #define BT_SDP_TYPE_SIZE(_type) .type = _type, \ 322 .data_size = BIT(_type & BT_SDP_SIZE_DESC_MASK), \ 323 .total_size = BIT(_type & BT_SDP_SIZE_DESC_MASK) + 1 324 325 /** @def BT_SDP_TYPE_SIZE_VAR 326 * @brief Declare a variable-size data element header. 327 * 328 * @param _type Data element header containing type and size descriptors. 329 * @param _size The actual size of the data. 330 */ 331 #define BT_SDP_TYPE_SIZE_VAR(_type, _size) .type = _type, \ 332 .data_size = _size, \ 333 .total_size = BIT((_type & BT_SDP_SIZE_DESC_MASK) - \ 334 BT_SDP_SIZE_INDEX_OFFSET) + _size + 1 335 336 /** @def BT_SDP_DATA_ELEM_LIST 337 * @brief Declare a list of data elements. 338 */ 339 #define BT_SDP_DATA_ELEM_LIST(...) ((struct bt_sdp_data_elem[]) {__VA_ARGS__}) 340 341 342 /** @def BT_SDP_NEW_SERVICE 343 * @brief SDP New Service Record Declaration Macro. 344 * 345 * Helper macro to declare a new service record. 346 * Default attributes: Record Handle, Record State, 347 * Language Base, Root Browse Group 348 * 349 */ 350 #define BT_SDP_NEW_SERVICE \ 351 { \ 352 BT_SDP_ATTR_RECORD_HANDLE, \ 353 { BT_SDP_TYPE_SIZE(BT_SDP_UINT32), BT_SDP_ARRAY_32(0) } \ 354 }, \ 355 { \ 356 BT_SDP_ATTR_RECORD_STATE, \ 357 { BT_SDP_TYPE_SIZE(BT_SDP_UINT32), BT_SDP_ARRAY_32(0) } \ 358 }, \ 359 { \ 360 BT_SDP_ATTR_LANG_BASE_ATTR_ID_LIST, \ 361 { BT_SDP_TYPE_SIZE_VAR(BT_SDP_SEQ8, 9), \ 362 BT_SDP_DATA_ELEM_LIST( \ 363 { BT_SDP_TYPE_SIZE(BT_SDP_UINT16), BT_SDP_ARRAY_8('n', 'e') }, \ 364 { BT_SDP_TYPE_SIZE(BT_SDP_UINT16), BT_SDP_ARRAY_16(106) }, \ 365 { BT_SDP_TYPE_SIZE(BT_SDP_UINT16), \ 366 BT_SDP_ARRAY_16(BT_SDP_PRIMARY_LANG_BASE) } \ 367 ), \ 368 } \ 369 }, \ 370 { \ 371 BT_SDP_ATTR_BROWSE_GRP_LIST, \ 372 { BT_SDP_TYPE_SIZE_VAR(BT_SDP_SEQ8, 3), \ 373 BT_SDP_DATA_ELEM_LIST( \ 374 { BT_SDP_TYPE_SIZE(BT_SDP_UUID16), \ 375 BT_SDP_ARRAY_16(BT_SDP_PUBLIC_BROWSE_GROUP) }, \ 376 ), \ 377 } \ 378 } 379 380 381 /** @def BT_SDP_LIST 382 * @brief Generic SDP List Attribute Declaration Macro. 383 * 384 * Helper macro to declare a list attribute. 385 * 386 * @param _att_id List Attribute ID. 387 * @param _data_elem_seq Data element sequence for the list. 388 * @param _type_size SDP type and size descriptor. 389 */ 390 #define BT_SDP_LIST(_att_id, _type_size, _data_elem_seq) \ 391 { \ 392 _att_id, { _type_size, _data_elem_seq } \ 393 } 394 395 /** @def BT_SDP_SERVICE_ID 396 * @brief SDP Service ID Attribute Declaration Macro. 397 * 398 * Helper macro to declare a service ID attribute. 399 * 400 * @param _uuid Service ID 16bit UUID. 401 */ 402 #define BT_SDP_SERVICE_ID(_uuid) \ 403 { \ 404 BT_SDP_ATTR_SERVICE_ID, \ 405 { BT_SDP_TYPE_SIZE(BT_SDP_UUID16), &((struct bt_uuid_16) _uuid) } \ 406 } 407 408 /** @def BT_SDP_SERVICE_NAME 409 * @brief SDP Name Attribute Declaration Macro. 410 * 411 * Helper macro to declare a service name attribute. 412 * 413 * @param _name Service name as a string (up to 256 chars). 414 */ 415 #define BT_SDP_SERVICE_NAME(_name) \ 416 { \ 417 BT_SDP_ATTR_SVCNAME_PRIMARY, \ 418 { BT_SDP_TYPE_SIZE_VAR(BT_SDP_TEXT_STR8, (sizeof(_name)-1)), _name } \ 419 } 420 421 /** @def BT_SDP_SUPPORTED_FEATURES 422 * @brief SDP Supported Features Attribute Declaration Macro. 423 * 424 * Helper macro to declare supported features of a profile/protocol. 425 * 426 * @param _features Feature mask as 16bit unsigned integer. 427 */ 428 #define BT_SDP_SUPPORTED_FEATURES(_features) \ 429 { \ 430 BT_SDP_ATTR_SUPPORTED_FEATURES, \ 431 { BT_SDP_TYPE_SIZE(BT_SDP_UINT16), BT_SDP_ARRAY_16(_features) } \ 432 } 433 434 /** @def BT_SDP_RECORD 435 * @brief SDP Service Declaration Macro. 436 * 437 * Helper macro to declare a service. 438 * 439 * @param _attrs List of attributes for the service record. 440 */ 441 #define BT_SDP_RECORD(_attrs) \ 442 { \ 443 .attrs = _attrs, \ 444 .attr_count = ARRAY_SIZE((_attrs)), \ 445 } 446 447 /* Server API */ 448 449 /** @brief Register a Service Record. 450 * 451 * Register a Service Record. Applications can make use of 452 * macros such as BT_SDP_DECLARE_SERVICE, BT_SDP_LIST, 453 * BT_SDP_SERVICE_ID, BT_SDP_SERVICE_NAME, etc. 454 * A service declaration must start with BT_SDP_NEW_SERVICE. 455 * 456 * @param service Service record declared using BT_SDP_DECLARE_SERVICE. 457 * 458 * @return 0 in case of success or negative value in case of error. 459 */ 460 int bt_sdp_register_service(struct bt_sdp_record *service); 461 462 /* Client API */ 463 464 /** @brief Generic SDP Client Query Result data holder */ 465 struct bt_sdp_client_result { 466 /* buffer containing unparsed SDP record result for given UUID */ 467 struct net_buf *resp_buf; 468 /* flag pointing that there are more result chunks for given UUID */ 469 bool next_record_hint; 470 /* Reference to UUID object on behalf one discovery was started */ 471 const struct bt_uuid *uuid; 472 }; 473 474 /** @brief Helper enum to be used as return value of bt_sdp_discover_func_t. 475 * The value informs the caller to perform further pending actions or stop them. 476 */ 477 enum { 478 BT_SDP_DISCOVER_UUID_STOP = 0, 479 BT_SDP_DISCOVER_UUID_CONTINUE, 480 }; 481 482 /** @typedef bt_sdp_discover_func_t 483 * 484 * @brief Callback type reporting to user that there is a resolved result 485 * on remote for given UUID and the result record buffer can be used by user 486 * for further inspection. 487 * 488 * A function of this type is given by the user to the bt_sdp_discover_params 489 * object. It'll be called on each valid record discovery completion for given 490 * UUID. When UUID resolution gives back no records then NULL is passed 491 * to the user. Otherwise user can get valid record(s) and then the internal 492 * hint 'next record' is set to false saying the UUID resolution is complete or 493 * the hint can be set by caller to true meaning that next record is available 494 * for given UUID. 495 * The returned function value allows the user to control retrieving follow-up 496 * resolved records if any. If the user doesn't want to read more resolved 497 * records for given UUID since current record data fulfills its requirements 498 * then should return BT_SDP_DISCOVER_UUID_STOP. Otherwise returned value means 499 * more subcall iterations are allowable. 500 * 501 * @param conn Connection object identifying connection to queried remote. 502 * @param result Object pointing to logical unparsed SDP record collected on 503 * base of response driven by given UUID. 504 * 505 * @return BT_SDP_DISCOVER_UUID_STOP in case of no more need to read next 506 * record data and continue discovery for given UUID. By returning 507 * BT_SDP_DISCOVER_UUID_CONTINUE user allows this discovery continuation. 508 */ 509 typedef uint8_t (*bt_sdp_discover_func_t) 510 (struct bt_conn *conn, struct bt_sdp_client_result *result); 511 512 /** @brief Main user structure used in SDP discovery of remote. */ 513 struct bt_sdp_discover_params { 514 sys_snode_t _node; 515 /** UUID (service) to be discovered on remote SDP entity */ 516 const struct bt_uuid *uuid; 517 /** Discover callback to be called on resolved SDP record */ 518 bt_sdp_discover_func_t func; 519 /** Memory buffer enabled by user for SDP query results */ 520 struct net_buf_pool *pool; 521 }; 522 523 /** @brief Allows user to start SDP discovery session. 524 * 525 * The function performs SDP service discovery on remote server driven by user 526 * delivered discovery parameters. Discovery session is made as soon as 527 * no SDP transaction is ongoing between peers and if any then this one 528 * is queued to be processed at discovery completion of previous one. 529 * On the service discovery completion the callback function will be 530 * called to get feedback to user about findings. 531 * 532 * @param conn Object identifying connection to remote. 533 * @param params SDP discovery parameters. 534 * 535 * @return 0 in case of success or negative value in case of error. 536 */ 537 538 int bt_sdp_discover(struct bt_conn *conn, 539 const struct bt_sdp_discover_params *params); 540 541 /** @brief Release waiting SDP discovery request. 542 * 543 * It can cancel valid waiting SDP client request identified by SDP discovery 544 * parameters object. 545 * 546 * @param conn Object identifying connection to remote. 547 * @param params SDP discovery parameters. 548 * 549 * @return 0 in case of success or negative value in case of error. 550 */ 551 int bt_sdp_discover_cancel(struct bt_conn *conn, 552 const struct bt_sdp_discover_params *params); 553 554 555 /* Helper types & functions for SDP client to get essential data from server */ 556 557 /** @brief Protocols to be asked about specific parameters */ 558 enum bt_sdp_proto { 559 BT_SDP_PROTO_RFCOMM = 0x0003, 560 BT_SDP_PROTO_L2CAP = 0x0100, 561 }; 562 563 /** @brief Give to user parameter value related to given stacked protocol UUID. 564 * 565 * API extracts specific parameter associated with given protocol UUID 566 * available in Protocol Descriptor List attribute. 567 * 568 * @param buf Original buffered raw record data. 569 * @param proto Known protocol to be checked like RFCOMM or L2CAP. 570 * @param param On success populated by found parameter value. 571 * 572 * @return 0 on success when specific parameter associated with given protocol 573 * value is found, or negative if error occurred during processing. 574 */ 575 int bt_sdp_get_proto_param(const struct net_buf *buf, enum bt_sdp_proto proto, 576 uint16_t *param); 577 578 /** @brief Get additional parameter value related to given stacked protocol UUID. 579 * 580 * API extracts specific parameter associated with given protocol UUID 581 * available in Additional Protocol Descriptor List attribute. 582 * 583 * @param buf Original buffered raw record data. 584 * @param proto Known protocol to be checked like RFCOMM or L2CAP. 585 * @param param_index There may be more than one parameter realted to the 586 * given protocol UUID. This function returns the result that is 587 * indexed by this parameter. It's value is from 0, 0 means the 588 * first matched result, 1 means the second matched result. 589 * @param[out] param On success populated by found parameter value. 590 * 591 * @return 0 on success when a specific parameter associated with a given protocol 592 * value is found, or negative if error occurred during processing. 593 */ 594 int bt_sdp_get_addl_proto_param(const struct net_buf *buf, enum bt_sdp_proto proto, 595 uint8_t param_index, uint16_t *param); 596 597 /** @brief Get profile version. 598 * 599 * Helper API extracting remote profile version number. To get it proper 600 * generic profile parameter needs to be selected usually listed in SDP 601 * Interoperability Requirements section for given profile specification. 602 * 603 * @param buf Original buffered raw record data. 604 * @param profile Profile family identifier the profile belongs. 605 * @param version On success populated by found version number. 606 * 607 * @return 0 on success, negative value if error occurred during processing. 608 */ 609 int bt_sdp_get_profile_version(const struct net_buf *buf, uint16_t profile, 610 uint16_t *version); 611 612 /** @brief Get SupportedFeatures attribute value 613 * 614 * Allows if exposed by remote retrieve SupportedFeature attribute. 615 * 616 * @param buf Buffer holding original raw record data from remote. 617 * @param features On success object to be populated with SupportedFeature 618 * mask. 619 * 620 * @return 0 on success if feature found and valid, negative in case any error 621 */ 622 int bt_sdp_get_features(const struct net_buf *buf, uint16_t *features); 623 624 #ifdef __cplusplus 625 } 626 #endif 627 628 /** 629 * @} 630 */ 631 632 #endif /* ZEPHYR_INCLUDE_BLUETOOTH_SDP_H_ */ 633