Skip to content

Commit cb3ac74

Browse files
committed
Merge branch 'feature/support_bt_pba_client' into 'master'
feature(bt/bluedroid): Support bt pba client Closes BT-3326 and IDFGH-10260 See merge request espressif/esp-idf!34260
2 parents 0d68aa8 + 125b303 commit cb3ac74

39 files changed

+4235
-39
lines changed

components/bt/CMakeLists.txt

+8
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ if(CONFIG_BT_ENABLED)
146146
host/bluedroid/bta/hd/include
147147
host/bluedroid/bta/hh/include
148148
host/bluedroid/bta/jv/include
149+
host/bluedroid/bta/pba/include
149150
host/bluedroid/bta/sdp/include
150151
host/bluedroid/bta/sys/include
151152
host/bluedroid/device/include
@@ -194,6 +195,7 @@ if(CONFIG_BT_ENABLED)
194195
"host/bluedroid/api/esp_spp_api.c"
195196
"host/bluedroid/api/esp_sdp_api.c"
196197
"host/bluedroid/api/esp_l2cap_bt_api.c"
198+
"host/bluedroid/api/esp_pbac_api.c"
197199
"host/bluedroid/bta/ar/bta_ar.c"
198200
"host/bluedroid/bta/av/bta_av_aact.c"
199201
"host/bluedroid/bta/av/bta_av_act.c"
@@ -257,6 +259,10 @@ if(CONFIG_BT_ENABLED)
257259
"host/bluedroid/bta/hf_client/bta_hf_client_rfc.c"
258260
"host/bluedroid/bta/hf_client/bta_hf_client_sco.c"
259261
"host/bluedroid/bta/hf_client/bta_hf_client_sdp.c"
262+
"host/bluedroid/bta/pba/bta_pba_client_act.c"
263+
"host/bluedroid/bta/pba/bta_pba_client_api.c"
264+
"host/bluedroid/bta/pba/bta_pba_client_main.c"
265+
"host/bluedroid/bta/pba/bta_pba_client_sdp.c"
260266
"host/bluedroid/bta/sdp/bta_sdp.c"
261267
"host/bluedroid/bta/sdp/bta_sdp_act.c"
262268
"host/bluedroid/bta/sdp/bta_sdp_api.c"
@@ -299,6 +305,7 @@ if(CONFIG_BT_ENABLED)
299305
"host/bluedroid/btc/profile/std/spp/btc_spp.c"
300306
"host/bluedroid/btc/profile/std/sdp/btc_sdp.c"
301307
"host/bluedroid/btc/profile/std/l2cap/btc_l2cap.c"
308+
"host/bluedroid/btc/profile/std/pba/btc_pba_client.c"
302309
"host/bluedroid/device/bdaddr.c"
303310
"host/bluedroid/device/controller.c"
304311
"host/bluedroid/device/interop.c"
@@ -411,6 +418,7 @@ if(CONFIG_BT_ENABLED)
411418
"host/bluedroid/stack/obex/obex_api.c"
412419
"host/bluedroid/stack/obex/obex_main.c"
413420
"host/bluedroid/stack/obex/obex_tl_l2cap.c"
421+
"host/bluedroid/stack/obex/obex_tl_rfcomm.c"
414422
"host/bluedroid/stack/rfcomm/port_api.c"
415423
"host/bluedroid/stack/rfcomm/port_rfc.c"
416424
"host/bluedroid/stack/rfcomm/port_utils.c"

components/bt/common/btc/core/btc_task.c

+6
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@
5757
#if BTC_HH_INCLUDED == TRUE
5858
#include "btc_hh.h"
5959
#endif /* BTC_HH_INCLUDED */
60+
#if BTC_PBA_CLIENT_INCLUDED
61+
#include "btc_pba_client.h"
62+
#endif
6063
#endif /* #if CLASSIC_BT_INCLUDED */
6164
#endif
6265

@@ -155,6 +158,9 @@ static const btc_func_t profile_tab[BTC_PID_NUM] = {
155158
#if BTC_HH_INCLUDED
156159
[BTC_PID_HH] = {btc_hh_call_handler, btc_hh_cb_handler },
157160
#endif
161+
#if BTC_PBA_CLIENT_INCLUDED
162+
[BTC_PID_PBA_CLIENT] = {btc_pba_client_call_handler, btc_pba_client_cb_handler},
163+
#endif
158164
#endif /* #if CLASSIC_BT_INCLUDED */
159165
#endif
160166
#if CONFIG_BLE_MESH

components/bt/common/btc/include/btc/btc_task.h

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -67,6 +67,9 @@ typedef enum {
6767
#if (BTC_HF_CLIENT_INCLUDED == TRUE)
6868
BTC_PID_HF_CLIENT,
6969
#endif /* BTC_HF_CLIENT_INCLUDED */
70+
#if (BTC_PBA_CLIENT_INCLUDED == TRUE)
71+
BTC_PID_PBA_CLIENT,
72+
#endif /* BTC_PBA_CLIENT_INCLUDED */
7073
#endif /* CLASSIC_BT_INCLUDED */
7174
#if CONFIG_BLE_MESH
7275
BTC_PID_PROV,
@@ -123,8 +126,8 @@ extern "C" {
123126
/**
124127
* transfer an message to another module in the different task.
125128
* @param msg message
126-
* @param arg paramter
127-
* @param arg_len length of paramter
129+
* @param arg parameter
130+
* @param arg_len length of parameter
128131
* @param copy_func deep copy function
129132
* @param free_func deep free function
130133
* @return BT_STATUS_SUCCESS: success
@@ -134,7 +137,7 @@ bt_status_t btc_transfer_context(btc_msg_t *msg, void *arg, int arg_len, btc_arg
134137
btc_arg_deep_free_t free_func);
135138

136139
/**
137-
* transfer an message to another module in tha same task.
140+
* transfer an message to another module in the same task.
138141
* @param msg message
139142
* @return BT_STATUS_SUCCESS: success
140143
* others: fail

components/bt/host/bluedroid/Kconfig.in

+23
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,29 @@ config BT_HID_DEVICE_ENABLED
191191
help
192192
This enables the BT HID Device
193193

194+
menuconfig BT_PBAC_ENABLED
195+
bool "PBAP Client"
196+
depends on BT_CLASSIC_ENABLED
197+
default n
198+
select BT_GOEPC_ENABLED
199+
help
200+
This enables the Phone Book Access Profile Client
201+
202+
config BT_PBAC_SUPPORTED_FEAT
203+
hex "PBAP Client Supported Features"
204+
depends on BT_PBAC_ENABLED
205+
default 0x000003FF
206+
help
207+
Set the supported features of PBAP Client, the default value is supported all features
208+
209+
config BT_PBAC_PREFERRED_MTU
210+
int "PBAP Client Preferred MTU"
211+
depends on BT_PBAC_ENABLED
212+
default 0
213+
help
214+
MTU is limited by the max MTU of transport layer, and should not be smaller than 255,
215+
but can be set to zero to use a default MTU of transport layer
216+
194217
config BT_GOEPC_ENABLED
195218
bool
196219
depends on BT_CLASSIC_ENABLED
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,251 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <string.h>
8+
#include "esp_err.h"
9+
#include "esp_bt_main.h"
10+
#include "esp_pbac_api.h"
11+
#include "btc/btc_manage.h"
12+
#include "btc_pba_client.h"
13+
14+
#if BTC_PBA_CLIENT_INCLUDED
15+
16+
esp_err_t esp_pbac_init(void)
17+
{
18+
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
19+
return ESP_ERR_INVALID_STATE;
20+
}
21+
22+
btc_msg_t msg;
23+
24+
msg.sig = BTC_SIG_API_CALL;
25+
msg.pid = BTC_PID_PBA_CLIENT;
26+
msg.act = BTC_PBA_CLIENT_INIT_EVT;
27+
28+
/* Switch to BTC context */
29+
bt_status_t stat = btc_transfer_context(&msg, NULL, 0, NULL, NULL);
30+
return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
31+
}
32+
33+
esp_err_t esp_pbac_deinit(void)
34+
{
35+
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
36+
return ESP_ERR_INVALID_STATE;
37+
}
38+
39+
btc_msg_t msg;
40+
41+
msg.sig = BTC_SIG_API_CALL;
42+
msg.pid = BTC_PID_PBA_CLIENT;
43+
msg.act = BTC_PBA_CLIENT_DEINIT_EVT;
44+
45+
/* Switch to BTC context */
46+
bt_status_t stat = btc_transfer_context(&msg, NULL, 0, NULL, NULL);
47+
return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
48+
}
49+
50+
esp_err_t esp_pbac_register_callback(esp_pbac_callback_t callback)
51+
{
52+
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
53+
return ESP_ERR_INVALID_STATE;
54+
}
55+
56+
if (callback == NULL) {
57+
return ESP_FAIL;
58+
}
59+
60+
btc_profile_cb_set(BTC_PID_PBA_CLIENT, callback);
61+
return ESP_OK;
62+
}
63+
64+
esp_err_t esp_pbac_connect(esp_bd_addr_t bd_addr)
65+
{
66+
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
67+
return ESP_ERR_INVALID_STATE;
68+
}
69+
70+
if (bd_addr == NULL) {
71+
return ESP_ERR_INVALID_ARG;
72+
}
73+
74+
btc_msg_t msg;
75+
msg.sig = BTC_SIG_API_CALL;
76+
msg.pid = BTC_PID_PBA_CLIENT;
77+
msg.act = BTC_PBA_CLIENT_CONNECT_EVT;
78+
79+
btc_pba_client_args_t args = {0};
80+
memcpy(args.connect.bd_addr.address, bd_addr, sizeof(esp_bd_addr_t));
81+
82+
/* Switch to BTC context */
83+
bt_status_t stat = btc_transfer_context(&msg, &args, sizeof(btc_pba_client_args_t), NULL, NULL);
84+
return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
85+
}
86+
87+
esp_err_t esp_pbac_disconnect(esp_pbac_conn_hdl_t handle)
88+
{
89+
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
90+
return ESP_ERR_INVALID_STATE;
91+
}
92+
93+
if (handle == ESP_PBAC_INVALID_HANDLE) {
94+
return ESP_ERR_INVALID_ARG;
95+
}
96+
97+
btc_msg_t msg;
98+
msg.sig = BTC_SIG_API_CALL;
99+
msg.pid = BTC_PID_PBA_CLIENT;
100+
msg.act = BTC_PBA_CLIENT_DISCONNECT_EVT;
101+
102+
btc_pba_client_args_t args = {0};
103+
args.disconnect.handle = handle;
104+
105+
/* Switch to BTC context */
106+
bt_status_t stat = btc_transfer_context(&msg, &args, sizeof(btc_pba_client_args_t), NULL, NULL);
107+
return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
108+
}
109+
110+
111+
esp_err_t esp_pbac_pull_phone_book(esp_pbac_conn_hdl_t handle, const char *name, esp_pbac_pull_phone_book_app_param_t *app_param)
112+
{
113+
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
114+
return ESP_ERR_INVALID_STATE;
115+
}
116+
117+
if (handle == ESP_PBAC_INVALID_HANDLE || name == NULL) {
118+
return ESP_ERR_INVALID_ARG;
119+
}
120+
121+
btc_msg_t msg;
122+
msg.sig = BTC_SIG_API_CALL;
123+
msg.pid = BTC_PID_PBA_CLIENT;
124+
msg.act = BTC_PBA_CLIENT_PULL_PHONE_BOOK_EVT;
125+
126+
btc_pba_client_args_t args = {0};
127+
args.pull_phone_book.handle = handle;
128+
args.pull_phone_book.name = (char *)name;
129+
if (app_param != NULL) {
130+
args.pull_phone_book.include_app_param = true;
131+
memcpy(&args.pull_phone_book.app_param, app_param, sizeof(esp_pbac_pull_phone_book_app_param_t));
132+
}
133+
else {
134+
args.pull_phone_book.include_app_param = false;
135+
}
136+
137+
/* Switch to BTC context */
138+
bt_status_t stat = btc_transfer_context(&msg, &args, sizeof(btc_pba_client_args_t), btc_pba_client_args_deep_copy, btc_pba_client_args_deep_free);
139+
return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
140+
}
141+
142+
esp_err_t esp_pbac_set_phone_book(esp_pbac_conn_hdl_t handle, esp_pbac_set_phone_book_flags_t flags, const char *name)
143+
{
144+
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
145+
return ESP_ERR_INVALID_STATE;
146+
}
147+
148+
/* since ESP_PBAC_SET_PHONE_BOOK_FLAGS_ROOT is equal to ESP_PBAC_SET_PHONE_BOOK_FLAGS_DOWN, we dont check XXX_DOWN */
149+
if (handle == ESP_PBAC_INVALID_HANDLE || (flags != ESP_PBAC_SET_PHONE_BOOK_FLAGS_ROOT && flags != ESP_PBAC_SET_PHONE_BOOK_FLAGS_UP)) {
150+
return ESP_ERR_INVALID_ARG;
151+
}
152+
153+
btc_msg_t msg;
154+
msg.sig = BTC_SIG_API_CALL;
155+
msg.pid = BTC_PID_PBA_CLIENT;
156+
msg.act = BTC_PBA_CLIENT_SET_PHONE_BOOK_EVT;
157+
158+
btc_pba_client_args_t args = {0};
159+
args.set_phone_book.handle = handle;
160+
args.set_phone_book.flags = flags;
161+
/* set phone book name is allowed to be NULL */
162+
args.set_phone_book.name = (char *)name;
163+
164+
/* Switch to BTC context */
165+
bt_status_t stat = btc_transfer_context(&msg, &args, sizeof(btc_pba_client_args_t), btc_pba_client_args_deep_copy, btc_pba_client_args_deep_free);
166+
return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
167+
}
168+
169+
esp_err_t esp_pbac_set_phone_book2(esp_pbac_conn_hdl_t handle, const char *path)
170+
{
171+
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
172+
return ESP_ERR_INVALID_STATE;
173+
}
174+
175+
btc_msg_t msg;
176+
msg.sig = BTC_SIG_API_CALL;
177+
msg.pid = BTC_PID_PBA_CLIENT;
178+
msg.act = BTC_PBA_CLIENT_SET_PHONE_BOOK2_EVT;
179+
180+
btc_pba_client_args_t args = {0};
181+
args.set_phone_book.handle = handle;
182+
args.set_phone_book.name = (char *)path;
183+
184+
/* Switch to BTC context */
185+
bt_status_t stat = btc_transfer_context(&msg, &args, sizeof(btc_pba_client_args_t), btc_pba_client_args_deep_copy, btc_pba_client_args_deep_free);
186+
return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
187+
}
188+
189+
esp_err_t esp_pbac_pull_vcard_listing(esp_pbac_conn_hdl_t handle, const char *name, esp_pbac_pull_vcard_listing_app_param_t *app_param)
190+
{
191+
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
192+
return ESP_ERR_INVALID_STATE;
193+
}
194+
195+
if (handle == ESP_PBAC_INVALID_HANDLE || name == NULL) {
196+
return ESP_ERR_INVALID_ARG;
197+
}
198+
199+
btc_msg_t msg;
200+
msg.sig = BTC_SIG_API_CALL;
201+
msg.pid = BTC_PID_PBA_CLIENT;
202+
msg.act = BTC_PBA_CLIENT_PULL_VCARD_LISTING_EVT;
203+
204+
btc_pba_client_args_t args = {0};
205+
args.pull_vcard_listing.handle = handle;
206+
args.pull_vcard_listing.name = (char *)name;
207+
if (app_param != NULL) {
208+
args.pull_vcard_listing.include_app_param = true;
209+
memcpy(&args.pull_vcard_listing.app_param, app_param, sizeof(esp_pbac_pull_vcard_listing_app_param_t));
210+
}
211+
else {
212+
args.pull_vcard_listing.include_app_param = false;
213+
}
214+
215+
/* Switch to BTC context */
216+
bt_status_t stat = btc_transfer_context(&msg, &args, sizeof(btc_pba_client_args_t), btc_pba_client_args_deep_copy, btc_pba_client_args_deep_free);
217+
return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
218+
}
219+
220+
esp_err_t esp_pbac_pull_vcard_entry(esp_pbac_conn_hdl_t handle, const char *name, esp_pbac_pull_vcard_entry_app_param_t *app_param)
221+
{
222+
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
223+
return ESP_ERR_INVALID_STATE;
224+
}
225+
226+
if (handle == ESP_PBAC_INVALID_HANDLE || name == NULL) {
227+
return ESP_ERR_INVALID_ARG;
228+
}
229+
230+
btc_msg_t msg;
231+
msg.sig = BTC_SIG_API_CALL;
232+
msg.pid = BTC_PID_PBA_CLIENT;
233+
msg.act = BTC_PBA_CLIENT_PULL_VCARD_ENTRY_EVT;
234+
235+
btc_pba_client_args_t args = {0};
236+
args.pull_vcard_entry.handle = handle;
237+
args.pull_vcard_entry.name = (char *)name;
238+
if (app_param != NULL) {
239+
args.pull_vcard_entry.include_app_param = true;
240+
memcpy(&args.pull_vcard_entry.app_param, app_param, sizeof(esp_pbac_pull_vcard_entry_app_param_t));
241+
}
242+
else {
243+
args.pull_vcard_entry.include_app_param = false;
244+
}
245+
246+
/* Switch to BTC context */
247+
bt_status_t stat = btc_transfer_context(&msg, &args, sizeof(btc_pba_client_args_t), btc_pba_client_args_deep_copy, btc_pba_client_args_deep_free);
248+
return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
249+
}
250+
251+
#endif

0 commit comments

Comments
 (0)