Skip to content

Commit 25b783c

Browse files
committed
Merge branch 'feat/add_param_indicate_create_spp_records_v5.4' into 'release/v5.4'
feat(bt): Add an SPP API parameter to indicate whether to create the SPP record(v5.4) See merge request espressif/esp-idf!43584
2 parents 65b7c19 + c7d1f8b commit 25b783c

File tree

4 files changed

+63
-14
lines changed

4 files changed

+63
-14
lines changed

components/bt/host/bluedroid/api/esp_spp_api.c

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -145,22 +145,34 @@ esp_err_t esp_spp_disconnect(uint32_t handle)
145145

146146
esp_err_t esp_spp_start_srv(esp_spp_sec_t sec_mask,
147147
esp_spp_role_t role, uint8_t local_scn, const char *name)
148+
{
149+
esp_spp_start_srv_cfg_t cfg = {0};
150+
151+
cfg.local_scn = local_scn;
152+
cfg.sec_mask = sec_mask;
153+
cfg.role = role;
154+
cfg.create_spp_record = true;
155+
cfg.name = name;
156+
return esp_spp_start_srv_with_cfg(&cfg);
157+
}
158+
159+
esp_err_t esp_spp_start_srv_with_cfg(const esp_spp_start_srv_cfg_t *cfg)
148160
{
149161
btc_msg_t msg;
150162
btc_spp_args_t arg;
151163
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
152164

153-
if (name == NULL || strlen(name) > ESP_SPP_SERVER_NAME_MAX) {
165+
if (cfg == NULL || cfg->name == NULL || strlen(cfg->name) > ESP_SPP_SERVER_NAME_MAX) {
154166
LOG_ERROR("Invalid server name!\n");
155167
return ESP_ERR_INVALID_ARG;
156168
}
157169

158-
if (sec_mask != ESP_SPP_SEC_NONE &&
159-
sec_mask != ESP_SPP_SEC_AUTHENTICATE &&
160-
sec_mask != (ESP_SPP_SEC_AUTHENTICATE | ESP_SPP_SEC_ENCRYPT) &&
161-
sec_mask != ESP_SPP_SEC_IN_16_DIGITS &&
162-
sec_mask != (ESP_SPP_SEC_IN_16_DIGITS | ESP_SPP_SEC_AUTHENTICATE) &&
163-
sec_mask != (ESP_SPP_SEC_IN_16_DIGITS | ESP_SPP_SEC_AUTHENTICATE | ESP_SPP_SEC_ENCRYPT)) {
170+
if (cfg->sec_mask != ESP_SPP_SEC_NONE &&
171+
cfg->sec_mask != ESP_SPP_SEC_AUTHENTICATE &&
172+
cfg->sec_mask != (ESP_SPP_SEC_AUTHENTICATE | ESP_SPP_SEC_ENCRYPT) &&
173+
cfg->sec_mask != ESP_SPP_SEC_IN_16_DIGITS &&
174+
cfg->sec_mask != (ESP_SPP_SEC_IN_16_DIGITS | ESP_SPP_SEC_AUTHENTICATE) &&
175+
cfg->sec_mask != (ESP_SPP_SEC_IN_16_DIGITS | ESP_SPP_SEC_AUTHENTICATE | ESP_SPP_SEC_ENCRYPT)) {
164176
LOG_WARN("Suggest to use ESP_SPP_SEC_NONE, ESP_SPP_SEC_AUTHENTICATE,"
165177
"(ESP_SPP_SEC_AUTHENTICATE | ESP_SPP_SEC_ENCRYPT),"
166178
"ESP_SPP_SEC_IN_16_DIGITS, (ESP_SPP_SEC_IN_16_DIGITS | ESP_SPP_SEC_AUTHENTICATE), or"
@@ -171,11 +183,12 @@ esp_err_t esp_spp_start_srv(esp_spp_sec_t sec_mask,
171183
msg.pid = BTC_PID_SPP;
172184
msg.act = BTC_SPP_ACT_START_SRV;
173185

174-
arg.start_srv.sec_mask = sec_mask;
175-
arg.start_srv.role = role;
176-
arg.start_srv.local_scn = local_scn;
186+
arg.start_srv.sec_mask = cfg->sec_mask;
187+
arg.start_srv.role = cfg->role;
188+
arg.start_srv.local_scn = cfg->local_scn;
189+
arg.start_srv.create_spp_record = cfg->create_spp_record;
177190
arg.start_srv.max_session = ESP_SPP_MAX_SESSION;
178-
strcpy(arg.start_srv.name, name);
191+
strcpy(arg.start_srv.name, cfg->name);
179192

180193
return (btc_transfer_context(&msg, &arg, sizeof(btc_spp_args_t), NULL, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
181194
}

components/bt/host/bluedroid/api/include/api/esp_spp_api.h

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,25 @@ typedef enum {
7474
} esp_spp_mode_t;
7575

7676
/**
77-
* @brief SPP configuration parameters
77+
* @brief SPP initialization configuration parameters.
7878
*/
7979
typedef struct {
8080
esp_spp_mode_t mode; /*!< Choose the mode of SPP, ESP_SPP_MODE_CB or ESP_SPP_MODE_VFS. */
8181
bool enable_l2cap_ertm; /*!< Enable/disable Logical Link Control and Adaptation Layer Protocol enhanced retransmission mode. */
8282
uint16_t tx_buffer_size; /*!< Tx buffer size for a new SPP channel. A smaller setting can save memory, but may incur a decrease in throughput. Only for ESP_SPP_MODE_VFS mode. */
8383
} esp_spp_cfg_t;
8484

85+
/**
86+
* @brief SPP start server configuration parameters.
87+
*/
88+
typedef struct {
89+
uint8_t local_scn; /*!< The specific channel you want to get. If channel is 0, means get any channel. */
90+
bool create_spp_record; /*!< Specifies whether to create the SPP record */
91+
esp_spp_sec_t sec_mask; /*!< Security Setting Mask. Suggest to use ESP_SPP_SEC_NONE, ESP_SPP_SEC_AUTHORIZE or ESP_SPP_SEC_AUTHENTICATE only */
92+
esp_spp_role_t role; /*!< Master or slave. */
93+
const char *name; /*!< Server's name. */
94+
} esp_spp_start_srv_cfg_t;
95+
8596
/**
8697
* @brief SPP callback function events
8798
*/
@@ -368,6 +379,19 @@ esp_err_t esp_spp_disconnect(uint32_t handle);
368379
*/
369380
esp_err_t esp_spp_start_srv(esp_spp_sec_t sec_mask, esp_spp_role_t role, uint8_t local_scn, const char *name);
370381

382+
/**
383+
* @brief This function is similar to `esp_spp_start_srv`.
384+
* The only difference is that it adds a parameter to specify whether to create the SPP record.
385+
* @note If the SPP record is not created, it is suggested to use it together with the SDP API.
386+
*
387+
* @param[in] cfg: Configuration parameters for starting the server.
388+
*
389+
* @return
390+
* - ESP_OK: success
391+
* - other: failed
392+
*/
393+
esp_err_t esp_spp_start_srv_with_cfg(const esp_spp_start_srv_cfg_t *cfg);
394+
371395
/**
372396
* @brief This function stops all SPP servers.
373397
* The operation will close all active SPP connection first, then the callback function will be called

components/bt/host/bluedroid/btc/profile/std/include/btc_spp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ typedef union {
6767
esp_spp_sec_t sec_mask;
6868
esp_spp_role_t role;
6969
UINT8 local_scn;
70+
bool create_spp_record;
7071
UINT8 max_session;
7172
char name[ESP_SPP_SERVER_NAME_MAX + 1];
7273
} start_srv;

components/bt/host/bluedroid/btc/profile/std/spp/btc_spp.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ typedef struct {
5050
bool connected;
5151
bool is_server;
5252
bool is_writing;
53+
bool create_spp_record;
5354
uint8_t serial;
5455
uint8_t scn;
5556
uint8_t max_session;
@@ -143,6 +144,7 @@ static spp_slot_t *spp_malloc_slot(void)
143144
(*slot)->rfc_port_handle = 0;
144145
(*slot)->fd = -1;
145146
(*slot)->connected = false;
147+
(*slot)->create_spp_record = false;
146148
(*slot)->is_server = false;
147149
(*slot)->mtu = 0;
148150
(*slot)->credit_rx = BTA_JV_MAX_CREDIT_NUM;
@@ -378,6 +380,7 @@ static void *btc_spp_rfcomm_inter_cb(tBTA_JV_EVT event, tBTA_JV *p_data, void *u
378380
strcpy(slot_new->service_name, slot->service_name);
379381
slot_new->sdp_handle = slot->sdp_handle;
380382
slot_new->mtu = p_data->rfc_srv_open.peer_mtu;
383+
slot_new->create_spp_record = slot->create_spp_record;
381384
slot_new->rfc_handle = p_data->rfc_srv_open.handle;
382385
slot_new->rfc_port_handle = BTA_JvRfcommGetPortHdl(slot_new->rfc_handle);
383386
BTA_JvSetPmProfile(p_data->rfc_srv_open.handle, BTA_JV_PM_ALL, BTA_JV_CONN_OPEN);
@@ -482,7 +485,14 @@ static void btc_spp_dm_inter_cb(tBTA_JV_EVT event, tBTA_JV *p_data, void *user_d
482485
}
483486

484487
slot->scn = p_data->scn;
485-
BTA_JvCreateRecordByUser(slot->service_name, slot->scn, (void *)slot->id);
488+
if (slot->create_spp_record) {
489+
BTA_JvCreateRecordByUser(slot->service_name, slot->scn, (void *)slot->id);
490+
} else {
491+
slot->sdp_handle = 0xffff;
492+
BTA_JvRfcommStartServer(slot->security, slot->role, slot->scn,
493+
slot->max_session, (tBTA_JV_RFCOMM_CBACK *)btc_spp_rfcomm_inter_cb, (void *)slot->id);
494+
}
495+
486496
osi_mutex_unlock(&spp_local_param.spp_slot_mutex);
487497
break;
488498
case BTA_JV_CREATE_RECORD_EVT:
@@ -748,6 +758,7 @@ static void btc_spp_start_srv(btc_spp_args_t *arg)
748758
* make this slot become a listening slot
749759
*/
750760
slot->is_server = true;
761+
slot->create_spp_record = arg->start_srv.create_spp_record;
751762
slot->security = arg->start_srv.sec_mask;
752763
slot->role = arg->start_srv.role;
753764
slot->scn = arg->start_srv.local_scn;
@@ -832,7 +843,7 @@ static void btc_spp_stop_srv(btc_spp_args_t *arg)
832843
if (spp_local_param.spp_slots[i] != NULL && spp_local_param.spp_slots[i]->is_server &&
833844
spp_local_param.spp_slots[i]->sdp_handle > 0 &&
834845
spp_local_param.spp_slots[i]->scn == srv_scn_arr[j]) {
835-
if (spp_local_param.spp_slots[i]->sdp_handle > 0) {
846+
if (spp_local_param.spp_slots[i]->sdp_handle > 0 && spp_local_param.spp_slots[i]->create_spp_record) {
836847
BTA_JvDeleteRecord(spp_local_param.spp_slots[i]->sdp_handle);
837848
}
838849

0 commit comments

Comments
 (0)