Skip to content

Commit a047113

Browse files
lylezhu2012kartben
authored andcommitted
Bluetooth: Classic: SDP: Improve SDP discover
Extend the function `bt_sdp_discover` to support service search transaction and service attribute transaction. Improve the `session->rec_buf`. If the net buffer cannot be allocated from the channel, disconnect the SDP session. Set the `MaximumAttributeByteCount` of the request `SDP_SERVICE_SEARCH_ATTR_REQ` with the tail room of `session->rec_buf`. Set the `MaximumAttributeByteCount` of the request `SDP_SERVICE_ATTR_REQ` with the tail room of `session->rec_buf`. Set the `MaximumServiceRecordCount` of the request `SDP_SERVICE_SEARCH_REQ` according to the tail room of `session->rec_buf`. Handle the response code `SDP_SERVICE_SEARCH_RSP`, and `SDP_SERVICE_ATTR_RSP`. Handle the error `SDP_ERROR_RSP`. Start the next SDP discovery if the error received. If there no more request, disconnect the session. If the request cannot be sent, start the next SDP discovery. Signed-off-by: Lyle Zhu <[email protected]>
1 parent ff5a458 commit a047113

File tree

2 files changed

+437
-120
lines changed
  • include/zephyr/bluetooth/classic
  • subsys/bluetooth/host/classic

2 files changed

+437
-120
lines changed

include/zephyr/bluetooth/classic/sdp.h

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -481,8 +481,6 @@ struct bt_sdp_client_result {
481481
struct net_buf *resp_buf;
482482
/** flag pointing that there are more result chunks for given UUID */
483483
bool next_record_hint;
484-
/** Reference to UUID object on behalf one discovery was started */
485-
const struct bt_uuid *uuid;
486484
};
487485

488486
/** @brief Helper enum to be used as return value of bt_sdp_discover_func_t.
@@ -493,6 +491,8 @@ enum {
493491
BT_SDP_DISCOVER_UUID_CONTINUE,
494492
};
495493

494+
struct bt_sdp_discover_params;
495+
496496
/** @typedef bt_sdp_discover_func_t
497497
*
498498
* @brief Callback type reporting to user that there is a resolved result
@@ -514,24 +514,41 @@ enum {
514514
*
515515
* @param conn Connection object identifying connection to queried remote.
516516
* @param result Object pointing to logical unparsed SDP record collected on
517-
* base of response driven by given UUID.
517+
* base of response driven by given discover params.
518+
* @param params Discover parameters.
518519
*
519520
* @return BT_SDP_DISCOVER_UUID_STOP in case of no more need to read next
520521
* record data and continue discovery for given UUID. By returning
521-
* BT_SDP_DISCOVER_UUID_CONTINUE user allows this discovery continuation.
522+
* @return BT_SDP_DISCOVER_UUID_CONTINUE user allows this discovery continuation.
522523
*/
523-
typedef uint8_t (*bt_sdp_discover_func_t)
524-
(struct bt_conn *conn, struct bt_sdp_client_result *result);
524+
typedef uint8_t (*bt_sdp_discover_func_t)(struct bt_conn *conn, struct bt_sdp_client_result *result,
525+
const struct bt_sdp_discover_params *params);
526+
527+
/** SDP Discover types */
528+
enum {
529+
/** Discover Service Search. */
530+
BT_SDP_DISCOVER_SERVICE_SEARCH,
531+
/** Discover Service Attribute. */
532+
BT_SDP_DISCOVER_SERVICE_ATTR,
533+
/** Discover Service Search Attribute. */
534+
BT_SDP_DISCOVER_SERVICE_SEARCH_ATTR,
535+
};
525536

526537
/** @brief Main user structure used in SDP discovery of remote. */
527538
struct bt_sdp_discover_params {
528-
sys_snode_t _node;
529-
/** UUID (service) to be discovered on remote SDP entity */
530-
const struct bt_uuid *uuid;
539+
sys_snode_t _node;
540+
union {
541+
/** UUID (service) to be discovered on remote SDP entity */
542+
const struct bt_uuid *uuid;
543+
/** Service record handle */
544+
uint32_t handle;
545+
};
531546
/** Discover callback to be called on resolved SDP record */
532-
bt_sdp_discover_func_t func;
547+
bt_sdp_discover_func_t func;
533548
/** Memory buffer enabled by user for SDP query results */
534-
struct net_buf_pool *pool;
549+
struct net_buf_pool *pool;
550+
/** Discover type */
551+
uint8_t type;
535552
};
536553

537554
/** @brief Allows user to start SDP discovery session.
@@ -543,6 +560,21 @@ struct bt_sdp_discover_params {
543560
* On the service discovery completion the callback function will be
544561
* called to get feedback to user about findings.
545562
*
563+
* Service Search: The SDP Client generates an
564+
* SDP_SERVICE_SEARCH_REQ to locate service
565+
* records that match the service search
566+
* pattern (`params->uuid`) given as the first
567+
* parameter of the PDU.
568+
* Service Attribute: The SDP Client generates an
569+
* SDP_SERVICE_ATTR_REQ to retrieve specified
570+
* attribute values from a specific service
571+
* record (`params->handle`).
572+
* Service Search Attribute: The SDP Client generates an
573+
* SDP_SERVICE_SEARCH_ATTR_REQ to retrieve
574+
* specified attribute values that match the
575+
* service search pattern (`params->uuid`)
576+
* given as the first parameter of the PDU.
577+
*
546578
* @param conn Object identifying connection to remote.
547579
* @param params SDP discovery parameters.
548580
*

0 commit comments

Comments
 (0)