mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Merge branch 'bugfix/fix_sdp_compatibility' into 'master'
Bugfix/fix sdp compatibility See merge request espressif/esp-idf!33442
This commit is contained in:
commit
4b74e4e595
@ -126,6 +126,7 @@ config BT_L2CAP_ENABLED
|
||||
config BT_SDP_COMMON_ENABLED
|
||||
bool "BT SDP COMMON"
|
||||
depends on BT_CLASSIC_ENABLED
|
||||
default y if BT_L2CAP_ENABLED
|
||||
default n
|
||||
help
|
||||
This enables common SDP operation, such as SDP record creation and deletion.
|
||||
|
@ -65,30 +65,32 @@ typedef enum {
|
||||
/**
|
||||
* @brief SDP header structure
|
||||
*/
|
||||
typedef struct {
|
||||
typedef struct bluetooth_sdp_hdr_overlay {
|
||||
esp_bluetooth_sdp_types_t type; /*!< SDP type */
|
||||
esp_bt_uuid_t uuid; /*!< UUID type, include uuid and uuid length, only needed to be set for RAW record creation */
|
||||
uint32_t service_name_length; /*!< Service name length */
|
||||
char *service_name; /*!< Service name */
|
||||
int32_t rfcomm_channel_number; /*!< RFCOMM channel number, if not used set to -1*/
|
||||
int32_t l2cap_psm; /*!< L2CAP psm, if not used set to -1 */
|
||||
int32_t profile_version; /*!< Profile version */
|
||||
} esp_bluetooth_sdp_hdr_t;
|
||||
int user1_ptr_len; /*!< User data1 length, only used for searching RAW record */
|
||||
uint8_t *user1_ptr; /*!< User data1 pointer to the raw SDP response data, only used for searching RAW record */
|
||||
int user2_ptr_len __attribute__((deprecated)); /*!< User data2 length, only used for searching RAW record */
|
||||
uint8_t *user2_ptr __attribute__((deprecated)); /*!< User data2 pointer, only used for searching RAW record */
|
||||
} esp_bluetooth_sdp_hdr_overlay_t;
|
||||
|
||||
/**
|
||||
* @brief Raw SDP record
|
||||
*/
|
||||
typedef struct {
|
||||
esp_bluetooth_sdp_hdr_t hdr; /*!< General info */
|
||||
esp_bt_uuid_t uuid; /*!< UUID type, include uuid and uuid length */
|
||||
int user1_ptr_len; /*!< Length of raw SDP data */
|
||||
uint8_t *user1_ptr; /*!< Raw SDP data */
|
||||
typedef struct bluetooth_sdp_raw_record {
|
||||
esp_bluetooth_sdp_hdr_overlay_t hdr; /*!< General info */
|
||||
} esp_bluetooth_sdp_raw_record_t;
|
||||
|
||||
/**
|
||||
* @brief Message Access Profile - Server parameters
|
||||
*/
|
||||
typedef struct {
|
||||
esp_bluetooth_sdp_hdr_t hdr; /*!< General info */
|
||||
typedef struct bluetooth_sdp_mas_record {
|
||||
esp_bluetooth_sdp_hdr_overlay_t hdr; /*!< General info */
|
||||
uint32_t mas_instance_id; /*!< MAS Instance ID */
|
||||
uint32_t supported_features; /*!< Map supported features */
|
||||
uint32_t supported_message_types; /*!< Supported message types */
|
||||
@ -97,16 +99,16 @@ typedef struct {
|
||||
/**
|
||||
* @brief Message Access Profile - Client (Notification Server) parameters
|
||||
*/
|
||||
typedef struct {
|
||||
esp_bluetooth_sdp_hdr_t hdr; /*!< General info */
|
||||
typedef struct bluetooth_sdp_mns_record {
|
||||
esp_bluetooth_sdp_hdr_overlay_t hdr; /*!< General info */
|
||||
uint32_t supported_features; /*!< Supported features */
|
||||
} esp_bluetooth_sdp_mns_record_t;
|
||||
|
||||
/**
|
||||
* @brief Phone Book Profile - Server parameters
|
||||
*/
|
||||
typedef struct {
|
||||
esp_bluetooth_sdp_hdr_t hdr; /*!< General info */
|
||||
typedef struct bluetooth_sdp_pse_record {
|
||||
esp_bluetooth_sdp_hdr_overlay_t hdr; /*!< General info */
|
||||
uint32_t supported_features; /*!< PBAP Supported Features */
|
||||
uint32_t supported_repositories; /*!< Supported Repositories */
|
||||
} esp_bluetooth_sdp_pse_record_t;
|
||||
@ -114,15 +116,15 @@ typedef struct {
|
||||
/**
|
||||
* @brief Phone Book Profile - Client parameters
|
||||
*/
|
||||
typedef struct {
|
||||
esp_bluetooth_sdp_hdr_t hdr; /*!< General info */
|
||||
typedef struct bluetooth_sdp_pce_record {
|
||||
esp_bluetooth_sdp_hdr_overlay_t hdr; /*!< General info */
|
||||
} esp_bluetooth_sdp_pce_record_t;
|
||||
|
||||
/**
|
||||
* @brief Object Push Profile parameters
|
||||
*/
|
||||
typedef struct {
|
||||
esp_bluetooth_sdp_hdr_t hdr; /*!< General info */
|
||||
typedef struct bluetooth_sdp_ops_record {
|
||||
esp_bluetooth_sdp_hdr_overlay_t hdr; /*!< General info */
|
||||
int supported_formats_list_len; /*!< Supported formats list length */
|
||||
uint8_t supported_formats_list[SDP_OPP_SUPPORTED_FORMATS_MAX_LENGTH]; /*!< Supported formats list */
|
||||
} esp_bluetooth_sdp_ops_record_t;
|
||||
@ -130,8 +132,8 @@ typedef struct {
|
||||
/**
|
||||
* @brief SIM Access Profile parameters
|
||||
*/
|
||||
typedef struct {
|
||||
esp_bluetooth_sdp_hdr_t hdr; /*!< General info */
|
||||
typedef struct bluetooth_sdp_sap_record {
|
||||
esp_bluetooth_sdp_hdr_overlay_t hdr; /*!< General info */
|
||||
} esp_bluetooth_sdp_sap_record_t;
|
||||
|
||||
/**
|
||||
@ -148,8 +150,8 @@ typedef enum {
|
||||
* @note Only one primary Device Identification service record can be added in the SDP database. If primary
|
||||
* Device Identification service is created multiple times, only the last one will take effect.
|
||||
*/
|
||||
typedef struct {
|
||||
esp_bluetooth_sdp_hdr_t hdr; /*!< General info */
|
||||
typedef struct bluetooth_sdp_dip_record {
|
||||
esp_bluetooth_sdp_hdr_overlay_t hdr; /*!< General info */
|
||||
uint16_t vendor; /*!< Vendor ID */
|
||||
uint16_t vendor_id_source; /*!< Vendor ID source, 0x0001 for Bluetooth, 0x0002 for USB, other values reserved, see `esp_sdp_vendor_id_source_t` */
|
||||
uint16_t product; /*!< Product ID */
|
||||
@ -162,7 +164,7 @@ typedef struct {
|
||||
* @brief SDP record parameters union
|
||||
*/
|
||||
typedef union {
|
||||
esp_bluetooth_sdp_hdr_t hdr; /*!< General info */
|
||||
esp_bluetooth_sdp_hdr_overlay_t hdr; /*!< General info */
|
||||
esp_bluetooth_sdp_raw_record_t raw; /*!< Raw SDP search data for unknown UUIDs */
|
||||
esp_bluetooth_sdp_mas_record_t mas; /*!< Message Access Profile - Server */
|
||||
esp_bluetooth_sdp_mns_record_t mns; /*!< Message Access Profile - Client (Notification Server) */
|
||||
@ -205,7 +207,7 @@ typedef union {
|
||||
/**
|
||||
* @brief ESP_SDP_CREATE_RECORD_COMP_EVT
|
||||
*/
|
||||
struct sdp_crate_record_evt_param {
|
||||
struct sdp_create_record_evt_param {
|
||||
esp_sdp_status_t status; /*!< Status */
|
||||
int record_handle; /*!< SDP record handle */
|
||||
} create_record; /*!< SDP callback param of ESP_SDP_CREATE_RECORD_COMP_EVT */
|
||||
|
@ -85,8 +85,10 @@ typedef void (tBTA_SDP_DM_CBACK)(tBTA_SDP_EVT event, tBTA_SDP *p_data, void *use
|
||||
|
||||
/* MCE configuration structure */
|
||||
typedef struct {
|
||||
UINT16 sdp_raw_size; /* The size of p_sdp_raw_data */
|
||||
UINT16 sdp_db_size; /* The size of p_sdp_db */
|
||||
#if (SDP_INCLUDED == TRUE)
|
||||
UINT8 *p_sdp_raw_data; /* The data buffer to keep raw data */
|
||||
tSDP_DISCOVERY_DB *p_sdp_db; /* The data buffer to keep SDP database */
|
||||
#endif ///SDP_INCLUDED == TRUE
|
||||
} tBTA_SDP_CFG;
|
||||
|
@ -395,29 +395,29 @@ static void bta_create_raw_sdp_record(bluetooth_sdp_record *record, tSDP_DISC_RE
|
||||
tSDP_DISC_ATTR *p_attr;
|
||||
tSDP_PROTOCOL_ELEM pe;
|
||||
|
||||
record->hdr.type = SDP_TYPE_RAW;
|
||||
record->hdr.service_name_length = 0;
|
||||
record->hdr.service_name = NULL;
|
||||
record->hdr.rfcomm_channel_number = -1;
|
||||
record->hdr.l2cap_psm = -1;
|
||||
record->hdr.profile_version = -1;
|
||||
record->raw.hdr.type = SDP_TYPE_RAW;
|
||||
record->raw.hdr.service_name_length = 0;
|
||||
record->raw.hdr.service_name = NULL;
|
||||
record->raw.hdr.rfcomm_channel_number = -1;
|
||||
record->raw.hdr.l2cap_psm = -1;
|
||||
record->raw.hdr.profile_version = -1;
|
||||
|
||||
/* Try to extract a service name */
|
||||
if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_SERVICE_NAME)) != NULL) {
|
||||
record->pse.hdr.service_name_length = SDP_DISC_ATTR_LEN(p_attr->attr_len_type);
|
||||
record->pse.hdr.service_name = (char *)p_attr->attr_value.v.array;
|
||||
record->raw.hdr.service_name_length = SDP_DISC_ATTR_LEN(p_attr->attr_len_type);
|
||||
record->raw.hdr.service_name = (char *)p_attr->attr_value.v.array;
|
||||
}
|
||||
|
||||
if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_GOEP_L2CAP_PSM)) != NULL) {
|
||||
record->hdr.l2cap_psm = p_attr->attr_value.v.u16;
|
||||
record->raw.hdr.l2cap_psm = p_attr->attr_value.v.u16;
|
||||
}
|
||||
|
||||
/* Try to extract an RFCOMM channel */
|
||||
if (SDP_FindProtocolListElemInRec(p_rec, UUID_PROTOCOL_RFCOMM, &pe)) {
|
||||
record->pse.hdr.rfcomm_channel_number = pe.params[0];
|
||||
record->raw.hdr.rfcomm_channel_number = pe.params[0];
|
||||
}
|
||||
record->raw.user1_ptr_len = p_bta_sdp_cfg->p_sdp_db->raw_size;
|
||||
record->raw.user1_ptr = p_bta_sdp_cfg->p_sdp_db->raw_data;
|
||||
record->raw.hdr.user1_ptr_len = p_bta_sdp_cfg->p_sdp_db->raw_used;
|
||||
record->raw.hdr.user1_ptr = p_bta_sdp_cfg->p_sdp_db->raw_data;
|
||||
}
|
||||
|
||||
|
||||
@ -570,6 +570,10 @@ void bta_sdp_search(tBTA_SDP_MSG *p_data)
|
||||
SDP_InitDiscoveryDb (p_bta_sdp_cfg->p_sdp_db, p_bta_sdp_cfg->sdp_db_size, 1,
|
||||
bta_sdp_search_uuid, 0, NULL);
|
||||
|
||||
/* tell SDP to keep the raw data */
|
||||
p_bta_sdp_cfg->p_sdp_db->raw_size = p_bta_sdp_cfg->sdp_raw_size;
|
||||
p_bta_sdp_cfg->p_sdp_db->raw_data = p_bta_sdp_cfg->p_sdp_raw_data;
|
||||
|
||||
if (!SDP_ServiceSearchAttributeRequest2(p_data->get_search.bd_addr, p_bta_sdp_cfg->p_sdp_db,
|
||||
bta_sdp_search_cback, (void *)bta_sdp_search_uuid)) {
|
||||
bta_sdp_cb.sdp_active = BTA_SDP_ACTIVE_NONE;
|
||||
|
@ -65,7 +65,9 @@ tBTA_SDP_STATUS BTA_SdpEnable(tBTA_SDP_DM_CBACK *p_cback)
|
||||
#if BTA_DYNAMIC_MEMORY == TRUE
|
||||
/* Malloc buffer for SDP configuration structure */
|
||||
p_bta_sdp_cfg->p_sdp_db = (tSDP_DISCOVERY_DB *)osi_malloc(p_bta_sdp_cfg->sdp_db_size);
|
||||
if (p_bta_sdp_cfg->p_sdp_db == NULL) {
|
||||
p_bta_sdp_cfg->p_sdp_raw_data = (UINT8 *)osi_malloc(p_bta_sdp_cfg->sdp_raw_size);
|
||||
if (p_bta_sdp_cfg->p_sdp_db == NULL || p_bta_sdp_cfg->p_sdp_raw_data == NULL) {
|
||||
BTA_SdpCleanup();
|
||||
return BTA_SDP_FAILURE;
|
||||
}
|
||||
#endif
|
||||
@ -118,8 +120,15 @@ tBTA_SDP_STATUS BTA_SdpCleanup(void)
|
||||
bta_sys_deregister(BTA_ID_SDP);
|
||||
#if BTA_DYNAMIC_MEMORY == TRUE
|
||||
/* Free buffer for SDP configuration structure */
|
||||
if (p_bta_sdp_cfg->p_sdp_db) {
|
||||
osi_free(p_bta_sdp_cfg->p_sdp_db);
|
||||
p_bta_sdp_cfg->p_sdp_db = NULL;
|
||||
}
|
||||
|
||||
if (p_bta_sdp_cfg->p_sdp_raw_data) {
|
||||
osi_free(p_bta_sdp_cfg->p_sdp_raw_data);
|
||||
p_bta_sdp_cfg->p_sdp_raw_data = NULL;
|
||||
}
|
||||
#endif
|
||||
return BTA_SDP_SUCCESS;
|
||||
}
|
||||
|
@ -30,16 +30,24 @@
|
||||
#define BTA_SDP_DB_SIZE 1500
|
||||
#endif
|
||||
|
||||
#ifndef BTA_SDP_RAW_DATA_SIZE
|
||||
#define BTA_SDP_RAW_DATA_SIZE 1024
|
||||
#endif
|
||||
|
||||
#if BTA_DYNAMIC_MEMORY == FALSE
|
||||
static UINT8 bta_sdp_raw_data[BTA_SDP_RAW_DATA_SIZE];
|
||||
static UINT8 __attribute__ ((aligned(4))) bta_sdp_db_data[BTA_SDP_DB_SIZE];
|
||||
#endif
|
||||
|
||||
/* SDP configuration structure */
|
||||
tBTA_SDP_CFG bta_sdp_cfg = {
|
||||
BTA_SDP_RAW_DATA_SIZE,
|
||||
BTA_SDP_DB_SIZE,
|
||||
#if BTA_DYNAMIC_MEMORY == FALSE
|
||||
bta_sdp_raw_data,
|
||||
(tSDP_DISCOVERY_DB *)bta_sdp_db_data /* The data buffer to keep SDP database */
|
||||
#else
|
||||
NULL,
|
||||
NULL
|
||||
#endif
|
||||
};
|
||||
|
@ -38,56 +38,62 @@ typedef enum {
|
||||
SDP_TYPE_DIP_SERVER, // Device Identification Profile
|
||||
} bluetooth_sdp_types;
|
||||
|
||||
typedef struct _bluetooth_sdp_hdr {
|
||||
/**
|
||||
* Some signals need additional pointers, hence we introduce a
|
||||
* generic way to handle these pointers.
|
||||
*/
|
||||
typedef struct _bluetooth_sdp_hdr_overlay {
|
||||
bluetooth_sdp_types type;
|
||||
esp_bt_uuid_t uuid;
|
||||
uint32_t service_name_length;
|
||||
char *service_name;
|
||||
int32_t rfcomm_channel_number;
|
||||
int32_t l2cap_psm;
|
||||
int32_t profile_version;
|
||||
} bluetooth_sdp_hdr;
|
||||
|
||||
typedef struct _bluetooth_sdp_raw_record {
|
||||
bluetooth_sdp_hdr hdr;
|
||||
esp_bt_uuid_t uuid;
|
||||
int user1_ptr_len;
|
||||
uint8_t *user1_ptr;
|
||||
int user2_ptr_len; // not used
|
||||
uint8_t *user2_ptr; // not used
|
||||
} bluetooth_sdp_hdr_overlay;
|
||||
|
||||
typedef struct _bluetooth_sdp_raw_record {
|
||||
bluetooth_sdp_hdr_overlay hdr;
|
||||
} bluetooth_sdp_raw_record;
|
||||
|
||||
typedef struct _bluetooth_sdp_mas_record {
|
||||
bluetooth_sdp_hdr hdr;
|
||||
bluetooth_sdp_hdr_overlay hdr;
|
||||
uint32_t mas_instance_id;
|
||||
uint32_t supported_features;
|
||||
uint32_t supported_message_types;
|
||||
} bluetooth_sdp_mas_record;
|
||||
|
||||
typedef struct _bluetooth_sdp_mns_record {
|
||||
bluetooth_sdp_hdr hdr;
|
||||
bluetooth_sdp_hdr_overlay hdr;
|
||||
uint32_t supported_features;
|
||||
} bluetooth_sdp_mns_record;
|
||||
|
||||
typedef struct _bluetooth_sdp_pse_record {
|
||||
bluetooth_sdp_hdr hdr;
|
||||
bluetooth_sdp_hdr_overlay hdr;
|
||||
uint32_t supported_features;
|
||||
uint32_t supported_repositories;
|
||||
} bluetooth_sdp_pse_record;
|
||||
|
||||
typedef struct _bluetooth_sdp_pce_record {
|
||||
bluetooth_sdp_hdr hdr;
|
||||
bluetooth_sdp_hdr_overlay hdr;
|
||||
} bluetooth_sdp_pce_record;
|
||||
|
||||
typedef struct _bluetooth_sdp_ops_record {
|
||||
bluetooth_sdp_hdr hdr;
|
||||
bluetooth_sdp_hdr_overlay hdr;
|
||||
int supported_formats_list_len;
|
||||
uint8_t supported_formats_list[SDP_OPP_SUPPORTED_FORMATS_MAX_LENGTH];
|
||||
} bluetooth_sdp_ops_record;
|
||||
|
||||
typedef struct _bluetooth_sdp_sap_record {
|
||||
bluetooth_sdp_hdr hdr;
|
||||
bluetooth_sdp_hdr_overlay hdr;
|
||||
} bluetooth_sdp_sap_record;
|
||||
|
||||
typedef struct _bluetooth_sdp_dip_record {
|
||||
bluetooth_sdp_hdr hdr;
|
||||
bluetooth_sdp_hdr_overlay hdr;
|
||||
uint16_t vendor;
|
||||
uint16_t vendor_id_source;
|
||||
uint16_t product;
|
||||
@ -96,7 +102,7 @@ typedef struct _bluetooth_sdp_dip_record {
|
||||
} bluetooth_sdp_dip_record;
|
||||
|
||||
typedef union {
|
||||
bluetooth_sdp_hdr hdr;
|
||||
bluetooth_sdp_hdr_overlay hdr;
|
||||
bluetooth_sdp_raw_record raw;
|
||||
bluetooth_sdp_mas_record mas;
|
||||
bluetooth_sdp_mns_record mns;
|
||||
|
@ -91,11 +91,6 @@ static int get_sdp_record_size(bluetooth_sdp_record* in_record)
|
||||
records_size = sizeof(bluetooth_sdp_record);
|
||||
break;
|
||||
|
||||
case SDP_TYPE_RAW:
|
||||
if (record->raw.user1_ptr != NULL) {
|
||||
records_size += record->raw.user1_ptr_len;
|
||||
}
|
||||
/* fall through */
|
||||
default:
|
||||
records_size += sizeof(bluetooth_sdp_record);
|
||||
records_size += record->hdr.service_name_length;
|
||||
@ -254,12 +249,6 @@ static void copy_sdp_record_common(bluetooth_sdp_record* in_record, bluetooth_sd
|
||||
*(free_ptr) = '\0'; // Set '\0' termination of string
|
||||
free_ptr++;
|
||||
}
|
||||
|
||||
if (in_record->hdr.type == SDP_TYPE_RAW && in_record->raw.user1_ptr != NULL) {
|
||||
out_record->raw.user1_ptr = (UINT8 *)free_ptr; // Update pointer
|
||||
memcpy(free_ptr, in_record->raw.user1_ptr, in_record->raw.user1_ptr_len); // Copy content
|
||||
free_ptr += in_record->raw.user1_ptr_len;
|
||||
}
|
||||
}
|
||||
|
||||
static void copy_sdp_record(bluetooth_sdp_record* in_record, bluetooth_sdp_record* out_record)
|
||||
@ -402,6 +391,7 @@ static int add_raw_sdp(const bluetooth_sdp_raw_record *rec)
|
||||
UINT8 temp[LEN_UUID_128];
|
||||
UINT8* p_temp = temp;
|
||||
UINT32 sdp_handle = 0;
|
||||
const esp_bt_uuid_t *p_uuid = &rec->hdr.uuid;
|
||||
|
||||
BTC_TRACE_DEBUG("%s(): scn 0x%02x, psm = 0x%04x\n service name %s", __func__,
|
||||
rec->hdr.rfcomm_channel_number, rec->hdr.l2cap_psm, rec->hdr.service_name);
|
||||
@ -411,15 +401,15 @@ static int add_raw_sdp(const bluetooth_sdp_raw_record *rec)
|
||||
return sdp_handle;
|
||||
}
|
||||
|
||||
if (rec->uuid.len == ESP_UUID_LEN_16) {
|
||||
if (p_uuid->len == ESP_UUID_LEN_16) {
|
||||
UINT8_TO_BE_STREAM (p_temp, (UUID_DESC_TYPE << 3) | SIZE_TWO_BYTES);
|
||||
UINT16_TO_BE_STREAM (p_temp, rec->uuid.uuid.uuid16);
|
||||
} else if (rec->uuid.len == ESP_UUID_LEN_32) {
|
||||
UINT16_TO_BE_STREAM (p_temp, p_uuid->uuid.uuid16);
|
||||
} else if (p_uuid->len == ESP_UUID_LEN_32) {
|
||||
UINT8_TO_BE_STREAM (p_temp, (UUID_DESC_TYPE << 3) | SIZE_FOUR_BYTES);
|
||||
UINT32_TO_BE_STREAM (p_temp, rec->uuid.uuid.uuid32);
|
||||
} else if (rec->uuid.len == ESP_UUID_LEN_128) {
|
||||
UINT32_TO_BE_STREAM (p_temp, p_uuid->uuid.uuid32);
|
||||
} else if (p_uuid->len == ESP_UUID_LEN_128) {
|
||||
UINT8_TO_BE_STREAM (p_temp, (UUID_DESC_TYPE << 3) | SIZE_SIXTEEN_BYTES);
|
||||
ARRAY_TO_BE_STREAM (p_temp, rec->uuid.uuid.uuid128, LEN_UUID_128);
|
||||
ARRAY_TO_BE_STREAM (p_temp, p_uuid->uuid.uuid128, LEN_UUID_128);
|
||||
} else {
|
||||
SDP_DeleteRecord(sdp_handle);
|
||||
sdp_handle = 0;
|
||||
@ -466,12 +456,12 @@ static int add_raw_sdp(const bluetooth_sdp_raw_record *rec)
|
||||
sdp_handle = 0;
|
||||
BTC_TRACE_ERROR("%s() FAILED, status = %d", __func__, status);
|
||||
} else {
|
||||
if (rec->uuid.len == ESP_UUID_LEN_16) {
|
||||
bta_sys_add_uuid(rec->uuid.uuid.uuid16);
|
||||
} else if (rec->uuid.len == ESP_UUID_LEN_32) {
|
||||
bta_sys_add_uuid_32(rec->uuid.uuid.uuid32);
|
||||
} else if (rec->uuid.len == ESP_UUID_LEN_128) {
|
||||
bta_sys_add_uuid_128((UINT8 *)&rec->uuid.uuid.uuid128);
|
||||
if (p_uuid->len == ESP_UUID_LEN_16) {
|
||||
bta_sys_add_uuid(p_uuid->uuid.uuid16);
|
||||
} else if (p_uuid->len == ESP_UUID_LEN_32) {
|
||||
bta_sys_add_uuid_32(p_uuid->uuid.uuid32);
|
||||
} else if (p_uuid->len == ESP_UUID_LEN_128) {
|
||||
bta_sys_add_uuid_128((UINT8 *)&p_uuid->uuid.uuid128);
|
||||
}
|
||||
BTC_TRACE_DEBUG("%s(): SDP Registered (handle 0x%08x)", __func__, sdp_handle);
|
||||
}
|
||||
@ -943,7 +933,7 @@ static int btc_handle_create_record_event(int id)
|
||||
switch (record->hdr.type) {
|
||||
case SDP_TYPE_RAW:
|
||||
sdp_handle = add_raw_sdp(&record->raw);
|
||||
memcpy(&service_uuid, &record->raw.uuid, sizeof(esp_bt_uuid_t));
|
||||
memcpy(&service_uuid, &record->hdr.uuid, sizeof(esp_bt_uuid_t));
|
||||
break;
|
||||
case SDP_TYPE_MAP_MAS:
|
||||
sdp_handle = add_maps_sdp(&record->mas);
|
||||
@ -1041,6 +1031,83 @@ static bool btc_sdp_remove_record_event(int id, int *p_sdp_handle)
|
||||
return result;
|
||||
}
|
||||
|
||||
static void btc_sdp_cb_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
|
||||
{
|
||||
switch (msg->act) {
|
||||
case BTA_SDP_SEARCH_COMP_EVT: {
|
||||
tBTA_SDP_SEARCH_COMP *src_search_comp = (tBTA_SDP_SEARCH_COMP *)p_src;
|
||||
tBTA_SDP_SEARCH_COMP *dest_search_comp = (tBTA_SDP_SEARCH_COMP *)p_dest;
|
||||
int record_count = src_search_comp->record_count;
|
||||
|
||||
for (int i = 0; i < record_count; i++) {
|
||||
bluetooth_sdp_record *src_record = &src_search_comp->records[i];
|
||||
bluetooth_sdp_record *dest_record = &dest_search_comp->records[i];
|
||||
// deep copy service name
|
||||
uint32_t src_service_name_length = src_record->hdr.service_name_length;
|
||||
char *src_service_name = src_record->hdr.service_name;
|
||||
dest_record->hdr.service_name_length = 0;
|
||||
dest_record->hdr.service_name = NULL;
|
||||
if (src_service_name && src_service_name_length) {
|
||||
char *service_name = (char *)osi_malloc(src_service_name_length + 1);
|
||||
if (service_name) {
|
||||
memcpy(service_name, src_service_name, src_service_name_length);
|
||||
service_name[src_service_name_length] = '\0';
|
||||
|
||||
dest_record->hdr.service_name_length = src_service_name_length;
|
||||
dest_record->hdr.service_name = service_name;
|
||||
} else {
|
||||
BTC_TRACE_ERROR("%s malloc service name failed, orig service name:%s", __func__, src_service_name);
|
||||
}
|
||||
}
|
||||
|
||||
// deep copy user1_ptr fow RAW type
|
||||
int src_user1_ptr_len = src_record->hdr.user1_ptr_len;
|
||||
uint8_t *src_user1_ptr = src_record->hdr.user1_ptr;
|
||||
dest_record->hdr.user1_ptr_len = 0;
|
||||
dest_record->hdr.user1_ptr = NULL;
|
||||
if (src_record->hdr.type == SDP_TYPE_RAW && src_user1_ptr && src_user1_ptr_len) {
|
||||
uint8_t *user1_ptr = (uint8_t *)osi_malloc(src_user1_ptr_len);
|
||||
if (user1_ptr) {
|
||||
memcpy(user1_ptr, src_user1_ptr, src_user1_ptr_len);
|
||||
|
||||
dest_record->hdr.user1_ptr_len = src_user1_ptr_len;
|
||||
dest_record->hdr.user1_ptr = user1_ptr;
|
||||
} else {
|
||||
BTC_TRACE_ERROR("%s malloc user1_ptr failed", __func__);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_sdp_cb_arg_deep_free(btc_msg_t *msg)
|
||||
{
|
||||
switch (msg->act) {
|
||||
case BTA_SDP_SEARCH_COMP_EVT: {
|
||||
tBTA_SDP_SEARCH_COMP *search_comp = (tBTA_SDP_SEARCH_COMP *)msg->arg;
|
||||
for (size_t i = 0; i < search_comp->record_count; i++) {
|
||||
bluetooth_sdp_record *record = &search_comp->records[i];
|
||||
if (record->hdr.service_name) {
|
||||
osi_free(record->hdr.service_name);
|
||||
}
|
||||
|
||||
if (record->hdr.user1_ptr) {
|
||||
osi_free(record->hdr.user1_ptr);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_sdp_dm_cback(tBTA_SDP_EVT event, tBTA_SDP* p_data, void* user_data)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
@ -1072,7 +1139,7 @@ static void btc_sdp_dm_cback(tBTA_SDP_EVT event, tBTA_SDP* p_data, void* user_da
|
||||
msg.pid = BTC_PID_SDP;
|
||||
msg.act = event;
|
||||
|
||||
status = btc_transfer_context(&msg, p_data, sizeof(tBTA_SDP), NULL, NULL);
|
||||
status = btc_transfer_context(&msg, p_data, sizeof(tBTA_SDP), btc_sdp_cb_arg_deep_copy, btc_sdp_cb_arg_deep_free);
|
||||
|
||||
if (status != BT_STATUS_SUCCESS) {
|
||||
BTC_TRACE_ERROR("%s btc_transfer_context failed", __func__);
|
||||
@ -1244,11 +1311,10 @@ static void btc_sdp_search(btc_sdp_args_t *arg)
|
||||
|
||||
void btc_sdp_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
|
||||
{
|
||||
switch (msg->act) {
|
||||
case BTC_SDP_ACT_CREATE_RECORD: {
|
||||
bluetooth_sdp_record **dst_record = &((btc_sdp_args_t *)p_dest)->create_record.record;
|
||||
bluetooth_sdp_record *src_record = ((btc_sdp_args_t *)p_src)->create_record.record;
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_SDP_ACT_CREATE_RECORD:
|
||||
bluetooth_sdp_record *record = (bluetooth_sdp_record *)osi_calloc(get_sdp_record_size(src_record));
|
||||
if (record) {
|
||||
copy_sdp_record(src_record, record);
|
||||
@ -1259,6 +1325,7 @@ void btc_sdp_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
|
||||
|
||||
*dst_record = record;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -1266,15 +1333,15 @@ void btc_sdp_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
|
||||
|
||||
void btc_sdp_arg_deep_free(btc_msg_t *msg)
|
||||
{
|
||||
switch (msg->act) {
|
||||
case BTC_SDP_ACT_CREATE_RECORD: {
|
||||
btc_sdp_args_t *arg = (btc_sdp_args_t *)msg->arg;
|
||||
bluetooth_sdp_record *record = arg->create_record.record;
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_SDP_ACT_CREATE_RECORD:
|
||||
if (record) {
|
||||
osi_free(record);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -1331,23 +1398,11 @@ void btc_sdp_cb_handler(btc_msg_t *msg)
|
||||
sdp_local_param.search_allowed = true;
|
||||
|
||||
param.search.status = p_data->sdp_search_comp.status;
|
||||
if (param.search.status == ESP_SDP_SUCCESS) {
|
||||
memcpy(param.search.remote_addr, p_data->sdp_search_comp.remote_addr, sizeof(BD_ADDR));
|
||||
memcpy(¶m.search.sdp_uuid, &p_data->sdp_search_comp.uuid, sizeof(tSDP_UUID));
|
||||
param.search.record_count = p_data->sdp_search_comp.record_count;
|
||||
param.search.records = osi_malloc(sizeof(esp_bluetooth_sdp_record_t)*p_data->sdp_search_comp.record_count);
|
||||
if (param.search.records != NULL) {
|
||||
memcpy(param.search.records, p_data->sdp_search_comp.records,
|
||||
sizeof(esp_bluetooth_sdp_record_t)*p_data->sdp_search_comp.record_count);
|
||||
} else {
|
||||
BTC_TRACE_ERROR("%s %d osi_malloc failed\n", __func__, event);
|
||||
param.search.status = ESP_SDP_NO_RESOURCE;
|
||||
}
|
||||
}
|
||||
param.search.records = (esp_bluetooth_sdp_record_t *)p_data->sdp_search_comp.records;
|
||||
btc_sdp_cb_to_app(ESP_SDP_SEARCH_COMP_EVT, ¶m);
|
||||
if (param.search.records != NULL) {
|
||||
osi_free(param.search.records);
|
||||
}
|
||||
break;
|
||||
case BTA_SDP_CREATE_RECORD_USER_EVT:
|
||||
param.create_record.status = p_data->sdp_create_record.status;
|
||||
@ -1372,6 +1427,8 @@ void btc_sdp_cb_handler(btc_msg_t *msg)
|
||||
BTC_TRACE_DEBUG("%s: Unhandled event (%d)!", __func__, msg->act);
|
||||
break;
|
||||
}
|
||||
|
||||
btc_sdp_cb_arg_deep_free(msg);
|
||||
}
|
||||
|
||||
#endif ///defined BTC_SDP_COMMON_INCLUDED && BTC_SDP_COMMON_INCLUDED == TRUE
|
||||
|
@ -11,6 +11,4 @@ Bluedroid
|
||||
|
||||
- :component_file:`/bt/host/bluedroid/api/include/api/esp_sdp_api.h`
|
||||
|
||||
- structure ``esp_bluetooth_sdp_hdr_overlay_t`` has been renamed to ``esp_bluetooth_sdp_hdr_t``
|
||||
- field ``uuid``, ``user1_ptr_len`` and ``user1_ptr`` in ``esp_bluetooth_sdp_hdr_overlay_t`` have been moved into ``esp_bluetooth_sdp_raw_record_t``
|
||||
- field ``user2_ptr_len`` and ``user2_ptr`` in ``esp_bluetooth_sdp_hdr_overlay_t`` have been removed
|
||||
- Field ``user2_ptr_len`` and ``user2_ptr`` is deprecated in structure ``esp_bluetooth_sdp_hdr_overlay_t``, since they are not used in SDP record creation or searching.
|
||||
|
@ -11,6 +11,4 @@ Bluedroid
|
||||
|
||||
- :component_file:`/bt/host/bluedroid/api/include/api/esp_sdp_api.h`
|
||||
|
||||
- 结构体 ``esp_bluetooth_sdp_hdr_overlay_t`` 被重命名为 ``esp_bluetooth_sdp_hdr_t``
|
||||
- 结构体 ``esp_bluetooth_sdp_hdr_overlay_t`` 中的字段 ``uuid``, ``user1_ptr_len`` 和 ``user1_ptr`` 被移动到结构体 ``esp_bluetooth_sdp_raw_record_t`` 中
|
||||
- 结构体 ``esp_bluetooth_sdp_hdr_overlay_t`` 中的字段 ``user2_ptr_len`` 和 ``user2_ptr`` 被删除
|
||||
- 结构体 ``esp_bluetooth_sdp_hdr_overlay_t`` 中的字段 ``user2_ptr_len`` 和 ``user2_ptr`` 被弃用,因为 SDP 的 API 或者事件中不会用到该字段。
|
||||
|
@ -340,15 +340,13 @@ static void esp_hdl_sdp_cb_evt(uint16_t event, void *p_param)
|
||||
ESP_LOGI(SDP_TAG, "ESP_SDP_INIT_EVT: status:%d", sdp_param->init.status);
|
||||
if (sdp_param->init.status == ESP_SDP_SUCCESS) {
|
||||
record.hdr.type = ESP_SDP_TYPE_RAW;
|
||||
record.hdr.uuid.len = sizeof(UUID_UNKNOWN);
|
||||
memcpy(record.hdr.uuid.uuid.uuid128, UUID_UNKNOWN, sizeof(UUID_UNKNOWN));
|
||||
record.hdr.service_name_length = strlen(sdp_service_name) + 1;
|
||||
record.hdr.service_name = sdp_service_name;
|
||||
record.hdr.rfcomm_channel_number = BT_UNUSED_RFCOMM;
|
||||
record.hdr.l2cap_psm = BT_L2CAP_DYNMIC_PSM;
|
||||
record.hdr.profile_version = BT_UNKONWN_PROFILE_VERSION;
|
||||
record.uuid.len = sizeof(UUID_UNKNOWN);
|
||||
memcpy(record.uuid.uuid.uuid128, UUID_UNKNOWN, sizeof(UUID_UNKNOWN));
|
||||
record.user1_ptr = NULL;
|
||||
record.user1_ptr_len = 0;
|
||||
esp_sdp_create_record((esp_bluetooth_sdp_record_t *)&record);
|
||||
}
|
||||
break;
|
||||
|
@ -250,15 +250,13 @@ static void esp_hdl_sdp_cb_evt(uint16_t event, void *p_param)
|
||||
ESP_LOGI(SDP_TAG, "ESP_SDP_INIT_EVT: status:%d", sdp_param->init.status);
|
||||
if (sdp_param->init.status == ESP_SDP_SUCCESS) {
|
||||
record.hdr.type = ESP_SDP_TYPE_RAW;
|
||||
record.hdr.uuid.len = sizeof(UUID_UNKNOWN);
|
||||
memcpy(record.hdr.uuid.uuid.uuid128, UUID_UNKNOWN, sizeof(UUID_UNKNOWN));
|
||||
record.hdr.service_name_length = strlen(sdp_service_name) + 1;
|
||||
record.hdr.service_name = sdp_service_name;
|
||||
record.hdr.rfcomm_channel_number = BT_UNUSED_RFCOMM;
|
||||
record.hdr.l2cap_psm = BT_L2CAP_DYNMIC_PSM;
|
||||
record.hdr.profile_version = BT_UNKONWN_PROFILE_VERSION;
|
||||
record.uuid.len = sizeof(UUID_UNKNOWN);
|
||||
memcpy(record.uuid.uuid.uuid128, UUID_UNKNOWN, sizeof(UUID_UNKNOWN));
|
||||
record.user1_ptr = NULL;
|
||||
record.user1_ptr_len = 0;
|
||||
esp_sdp_create_record((esp_bluetooth_sdp_record_t *)&record);
|
||||
}
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user