Skip to content

Commit

Permalink
Merge branch 'espressif:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason2866 authored Dec 13, 2024
2 parents d3925e1 + cb3ac74 commit 97756d6
Show file tree
Hide file tree
Showing 122 changed files with 5,313 additions and 316 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ repos:
require_serial: true
additional_dependencies:
- PyYAML == 5.3.1
- idf-build-apps~=2.0
- idf-build-apps~=2.5
- id: sort-yaml-files
name: sort yaml files
entry: tools/ci/sort_yaml.py
Expand Down
8 changes: 8 additions & 0 deletions components/bt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ if(CONFIG_BT_ENABLED)
host/bluedroid/bta/hd/include
host/bluedroid/bta/hh/include
host/bluedroid/bta/jv/include
host/bluedroid/bta/pba/include
host/bluedroid/bta/sdp/include
host/bluedroid/bta/sys/include
host/bluedroid/device/include
Expand Down Expand Up @@ -194,6 +195,7 @@ if(CONFIG_BT_ENABLED)
"host/bluedroid/api/esp_spp_api.c"
"host/bluedroid/api/esp_sdp_api.c"
"host/bluedroid/api/esp_l2cap_bt_api.c"
"host/bluedroid/api/esp_pbac_api.c"
"host/bluedroid/bta/ar/bta_ar.c"
"host/bluedroid/bta/av/bta_av_aact.c"
"host/bluedroid/bta/av/bta_av_act.c"
Expand Down Expand Up @@ -257,6 +259,10 @@ if(CONFIG_BT_ENABLED)
"host/bluedroid/bta/hf_client/bta_hf_client_rfc.c"
"host/bluedroid/bta/hf_client/bta_hf_client_sco.c"
"host/bluedroid/bta/hf_client/bta_hf_client_sdp.c"
"host/bluedroid/bta/pba/bta_pba_client_act.c"
"host/bluedroid/bta/pba/bta_pba_client_api.c"
"host/bluedroid/bta/pba/bta_pba_client_main.c"
"host/bluedroid/bta/pba/bta_pba_client_sdp.c"
"host/bluedroid/bta/sdp/bta_sdp.c"
"host/bluedroid/bta/sdp/bta_sdp_act.c"
"host/bluedroid/bta/sdp/bta_sdp_api.c"
Expand Down Expand Up @@ -299,6 +305,7 @@ if(CONFIG_BT_ENABLED)
"host/bluedroid/btc/profile/std/spp/btc_spp.c"
"host/bluedroid/btc/profile/std/sdp/btc_sdp.c"
"host/bluedroid/btc/profile/std/l2cap/btc_l2cap.c"
"host/bluedroid/btc/profile/std/pba/btc_pba_client.c"
"host/bluedroid/device/bdaddr.c"
"host/bluedroid/device/controller.c"
"host/bluedroid/device/interop.c"
Expand Down Expand Up @@ -411,6 +418,7 @@ if(CONFIG_BT_ENABLED)
"host/bluedroid/stack/obex/obex_api.c"
"host/bluedroid/stack/obex/obex_main.c"
"host/bluedroid/stack/obex/obex_tl_l2cap.c"
"host/bluedroid/stack/obex/obex_tl_rfcomm.c"
"host/bluedroid/stack/rfcomm/port_api.c"
"host/bluedroid/stack/rfcomm/port_rfc.c"
"host/bluedroid/stack/rfcomm/port_utils.c"
Expand Down
6 changes: 6 additions & 0 deletions components/bt/common/btc/core/btc_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
#if BTC_HH_INCLUDED == TRUE
#include "btc_hh.h"
#endif /* BTC_HH_INCLUDED */
#if BTC_PBA_CLIENT_INCLUDED
#include "btc_pba_client.h"
#endif
#endif /* #if CLASSIC_BT_INCLUDED */
#endif

Expand Down Expand Up @@ -155,6 +158,9 @@ static const btc_func_t profile_tab[BTC_PID_NUM] = {
#if BTC_HH_INCLUDED
[BTC_PID_HH] = {btc_hh_call_handler, btc_hh_cb_handler },
#endif
#if BTC_PBA_CLIENT_INCLUDED
[BTC_PID_PBA_CLIENT] = {btc_pba_client_call_handler, btc_pba_client_cb_handler},
#endif
#endif /* #if CLASSIC_BT_INCLUDED */
#endif
#if CONFIG_BLE_MESH
Expand Down
11 changes: 7 additions & 4 deletions components/bt/common/btc/include/btc/btc_task.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -67,6 +67,9 @@ typedef enum {
#if (BTC_HF_CLIENT_INCLUDED == TRUE)
BTC_PID_HF_CLIENT,
#endif /* BTC_HF_CLIENT_INCLUDED */
#if (BTC_PBA_CLIENT_INCLUDED == TRUE)
BTC_PID_PBA_CLIENT,
#endif /* BTC_PBA_CLIENT_INCLUDED */
#endif /* CLASSIC_BT_INCLUDED */
#if CONFIG_BLE_MESH
BTC_PID_PROV,
Expand Down Expand Up @@ -123,8 +126,8 @@ extern "C" {
/**
* transfer an message to another module in the different task.
* @param msg message
* @param arg paramter
* @param arg_len length of paramter
* @param arg parameter
* @param arg_len length of parameter
* @param copy_func deep copy function
* @param free_func deep free function
* @return BT_STATUS_SUCCESS: success
Expand All @@ -134,7 +137,7 @@ bt_status_t btc_transfer_context(btc_msg_t *msg, void *arg, int arg_len, btc_arg
btc_arg_deep_free_t free_func);

/**
* transfer an message to another module in tha same task.
* transfer an message to another module in the same task.
* @param msg message
* @return BT_STATUS_SUCCESS: success
* others: fail
Expand Down
23 changes: 23 additions & 0 deletions components/bt/host/bluedroid/Kconfig.in
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,29 @@ config BT_HID_DEVICE_ENABLED
help
This enables the BT HID Device

menuconfig BT_PBAC_ENABLED
bool "PBAP Client"
depends on BT_CLASSIC_ENABLED
default n
select BT_GOEPC_ENABLED
help
This enables the Phone Book Access Profile Client

config BT_PBAC_SUPPORTED_FEAT
hex "PBAP Client Supported Features"
depends on BT_PBAC_ENABLED
default 0x000003FF
help
Set the supported features of PBAP Client, the default value is supported all features

config BT_PBAC_PREFERRED_MTU
int "PBAP Client Preferred MTU"
depends on BT_PBAC_ENABLED
default 0
help
MTU is limited by the max MTU of transport layer, and should not be smaller than 255,
but can be set to zero to use a default MTU of transport layer

config BT_GOEPC_ENABLED
bool
depends on BT_CLASSIC_ENABLED
Expand Down
251 changes: 251 additions & 0 deletions components/bt/host/bluedroid/api/esp_pbac_api.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <string.h>
#include "esp_err.h"
#include "esp_bt_main.h"
#include "esp_pbac_api.h"
#include "btc/btc_manage.h"
#include "btc_pba_client.h"

#if BTC_PBA_CLIENT_INCLUDED

esp_err_t esp_pbac_init(void)
{
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}

btc_msg_t msg;

msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_PBA_CLIENT;
msg.act = BTC_PBA_CLIENT_INIT_EVT;

/* Switch to BTC context */
bt_status_t stat = btc_transfer_context(&msg, NULL, 0, NULL, NULL);
return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
}

esp_err_t esp_pbac_deinit(void)
{
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}

btc_msg_t msg;

msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_PBA_CLIENT;
msg.act = BTC_PBA_CLIENT_DEINIT_EVT;

/* Switch to BTC context */
bt_status_t stat = btc_transfer_context(&msg, NULL, 0, NULL, NULL);
return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
}

esp_err_t esp_pbac_register_callback(esp_pbac_callback_t callback)
{
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}

if (callback == NULL) {
return ESP_FAIL;
}

btc_profile_cb_set(BTC_PID_PBA_CLIENT, callback);
return ESP_OK;
}

esp_err_t esp_pbac_connect(esp_bd_addr_t bd_addr)
{
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}

if (bd_addr == NULL) {
return ESP_ERR_INVALID_ARG;
}

btc_msg_t msg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_PBA_CLIENT;
msg.act = BTC_PBA_CLIENT_CONNECT_EVT;

btc_pba_client_args_t args = {0};
memcpy(args.connect.bd_addr.address, bd_addr, sizeof(esp_bd_addr_t));

/* Switch to BTC context */
bt_status_t stat = btc_transfer_context(&msg, &args, sizeof(btc_pba_client_args_t), NULL, NULL);
return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
}

esp_err_t esp_pbac_disconnect(esp_pbac_conn_hdl_t handle)
{
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}

if (handle == ESP_PBAC_INVALID_HANDLE) {
return ESP_ERR_INVALID_ARG;
}

btc_msg_t msg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_PBA_CLIENT;
msg.act = BTC_PBA_CLIENT_DISCONNECT_EVT;

btc_pba_client_args_t args = {0};
args.disconnect.handle = handle;

/* Switch to BTC context */
bt_status_t stat = btc_transfer_context(&msg, &args, sizeof(btc_pba_client_args_t), NULL, NULL);
return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
}


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)
{
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}

if (handle == ESP_PBAC_INVALID_HANDLE || name == NULL) {
return ESP_ERR_INVALID_ARG;
}

btc_msg_t msg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_PBA_CLIENT;
msg.act = BTC_PBA_CLIENT_PULL_PHONE_BOOK_EVT;

btc_pba_client_args_t args = {0};
args.pull_phone_book.handle = handle;
args.pull_phone_book.name = (char *)name;
if (app_param != NULL) {
args.pull_phone_book.include_app_param = true;
memcpy(&args.pull_phone_book.app_param, app_param, sizeof(esp_pbac_pull_phone_book_app_param_t));
}
else {
args.pull_phone_book.include_app_param = false;
}

/* Switch to BTC context */
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);
return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
}

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)
{
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}

/* since ESP_PBAC_SET_PHONE_BOOK_FLAGS_ROOT is equal to ESP_PBAC_SET_PHONE_BOOK_FLAGS_DOWN, we dont check XXX_DOWN */
if (handle == ESP_PBAC_INVALID_HANDLE || (flags != ESP_PBAC_SET_PHONE_BOOK_FLAGS_ROOT && flags != ESP_PBAC_SET_PHONE_BOOK_FLAGS_UP)) {
return ESP_ERR_INVALID_ARG;
}

btc_msg_t msg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_PBA_CLIENT;
msg.act = BTC_PBA_CLIENT_SET_PHONE_BOOK_EVT;

btc_pba_client_args_t args = {0};
args.set_phone_book.handle = handle;
args.set_phone_book.flags = flags;
/* set phone book name is allowed to be NULL */
args.set_phone_book.name = (char *)name;

/* Switch to BTC context */
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);
return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
}

esp_err_t esp_pbac_set_phone_book2(esp_pbac_conn_hdl_t handle, const char *path)
{
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}

btc_msg_t msg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_PBA_CLIENT;
msg.act = BTC_PBA_CLIENT_SET_PHONE_BOOK2_EVT;

btc_pba_client_args_t args = {0};
args.set_phone_book.handle = handle;
args.set_phone_book.name = (char *)path;

/* Switch to BTC context */
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);
return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
}

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)
{
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}

if (handle == ESP_PBAC_INVALID_HANDLE || name == NULL) {
return ESP_ERR_INVALID_ARG;
}

btc_msg_t msg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_PBA_CLIENT;
msg.act = BTC_PBA_CLIENT_PULL_VCARD_LISTING_EVT;

btc_pba_client_args_t args = {0};
args.pull_vcard_listing.handle = handle;
args.pull_vcard_listing.name = (char *)name;
if (app_param != NULL) {
args.pull_vcard_listing.include_app_param = true;
memcpy(&args.pull_vcard_listing.app_param, app_param, sizeof(esp_pbac_pull_vcard_listing_app_param_t));
}
else {
args.pull_vcard_listing.include_app_param = false;
}

/* Switch to BTC context */
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);
return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
}

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)
{
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}

if (handle == ESP_PBAC_INVALID_HANDLE || name == NULL) {
return ESP_ERR_INVALID_ARG;
}

btc_msg_t msg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_PBA_CLIENT;
msg.act = BTC_PBA_CLIENT_PULL_VCARD_ENTRY_EVT;

btc_pba_client_args_t args = {0};
args.pull_vcard_entry.handle = handle;
args.pull_vcard_entry.name = (char *)name;
if (app_param != NULL) {
args.pull_vcard_entry.include_app_param = true;
memcpy(&args.pull_vcard_entry.app_param, app_param, sizeof(esp_pbac_pull_vcard_entry_app_param_t));
}
else {
args.pull_vcard_entry.include_app_param = false;
}

/* Switch to BTC context */
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);
return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
}

#endif
Loading

0 comments on commit 97756d6

Please sign in to comment.