Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ choice
bool "Not support BLE Stack"
endchoice

config BLUETOOTH_LE_CS
bool "Bluetooth LE Channel Sounding supported"
depends on BLUETOOTH_STACK_LE_ZBLUE
default n

config BLUETOOTH_LE_SCANNER_MAX_NUM
int "LE Scanner max register number"
default 2
Expand Down
26 changes: 25 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ CSRCS += framework/common/*.c
CSRCS += framework/api/bluetooth.c
CSRCS += framework/api/bt_adapter.c
CSRCS += framework/api/bt_device.c

CSRCS += framework/api/bt_cs.c
ifeq ($(CONFIG_BLUETOOTH_A2DP_SINK), y)
CSRCS += framework/api/bt_a2dp_sink.c
endif #CONFIG_BLUETOOTH_A2DP_SINK
Expand Down Expand Up @@ -72,6 +72,7 @@ ifeq ($(CONFIG_BLUETOOTH_BLE_AUDIO), y)
CSRCS := framework/api/bt_lea*.c
endif #CONFIG_BLUETOOTH_BLE_AUDIO


ifeq ($(CONFIG_BLUETOOTH_FRAMEWORK_SOCKET_IPC), y)
CSRCS += service/ipc/bluetooth_ipc.c
CSRCS += framework/socket/bt_device.c
Expand Down Expand Up @@ -160,6 +161,11 @@ CSRCS += framework/socket/bt_trace.c
CSRCS += service/ipc/socket/src/bt_socket_log.c
endif #CONFIG_BLUETOOTH_BLE_AUDIO

ifeq ($(CONFIG_BLUETOOTH_LE_CS), y)
CSRCS += framework/socket/bt_cs.c
CSRCS += service/ipc/socket/src/bt_socket_cs.c
endif #CONFIG_BLUETOOTH_LE_CS

CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/service/ipc/socket/include
ifeq ($(CONFIG_BLUETOOTH_FRAMEWORK_ASYNC), y)
CSRCS += framework/socket/async/*.c
Expand Down Expand Up @@ -265,6 +271,9 @@ endif #CONFIG_BLUETOOTH_GATT_CLIENT
ifeq ($(CONFIG_BLUETOOTH_GATT_SERVER), y)
CSRCS += service/stacks/zephyr/sal_gatt_server_interface.c
endif #CONFIG_BLUETOOTH_GATT_SERVER
ifeq ($(CONFIG_BLUETOOTH_LE_CS), y)
CSRCS += service/stacks/zephyr/sal_le_cs_interface.c
endif #CONFIG_BLUETOOTH_LE_CS
endif #CONFIG_BLUETOOTH_STACK_LE_ZBLUE

endif
Expand Down Expand Up @@ -383,6 +392,11 @@ CSRCS += service/utils/btsnoop_writer.c
CSRCS += service/utils/btsnoop_filter.c
endif #CONFIG_BLUETOOTH_LOG

ifeq ($(CONFIG_BLUETOOTH_LE_CS), y)
CSRCS += service/profiles/cs/*.c
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/service/profiles/cs
endif #CONFIG_BLUETOOTH_CS

ifeq ($(CONFIG_BLUETOOTH_HCI_FILTER), y)
CSRCS += service/vhal/bt_hci_filter.c
endif
Expand Down Expand Up @@ -508,6 +522,10 @@ ifeq ($(CONFIG_BLUETOOTH_STORAGE_UPDATE), y)
CSRCS += tools/storage_update/storage_tool.c
endif #CONFIG_BLUETOOTH_STORAGE_UPDATE

ifeq ($(CONFIG_BLUETOOTH_LE_CS), y)
CSRCS += tools/le_cs.c
endif

endif

# framework/service/stack/tools dependence
Expand Down Expand Up @@ -544,7 +562,13 @@ ifneq ($(CONFIG_BLUETOOTH_STACK_BREDR_ZBLUE)$(CONFIG_BLUETOOTH_STACK_LE_ZBLUE),)
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/external/zblue/zblue/port/include/
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/external/zblue/zblue/subsys/bluetooth/host
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/external/zblue/zblue/subsys/settings/include/settings
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/external/zblue/zblue/subsys/bluetooth
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/external/zblue/zblue/port/include/kernel/include
CFLAGS += ${INCDIR_PREFIX}${APPDIR}/frameworks/connectivity/bluetooth/framework/include
CFLAGS += ${INCDIR_PREFIX}${APPDIR}/frameworks/connectivity/bluetooth/service/ipc/socket/include
CFLAGS += ${INCDIR_PREFIX}${APPDIR}frameworks/connectivity/bluetooth/service/profiles/cs
CFLAGS += ${INCDIR_PREFIX}${APPDIR}frameworks/connectivity/bluetooth/service/profiles/include
CFLAGS += ${INCDIR_PREFIX}${APPDIR}frameworks/connectivity/bluetooth/service/stacks/include
endif
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/service/ipc
endif
Expand Down
68 changes: 68 additions & 0 deletions framework/api/bt_cs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/****************************************************************************
* Copyright (C) 2024 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#define LOG_TAG "channel_sounding_api"

#include <stdint.h>

#include "bt_cs.h"
#include "bt_internal.h"
#include "bt_profile.h"
#include "cs_service.h"
#include "service_manager.h"
#include "utils/log.h"

#ifdef CONFIG_BLUETOOTH_LE_CS

static bt_cs_interface_t* get_profile_service(void)
{
return (bt_cs_interface_t*)service_manager_get_profile(PROFILE_CS);
}
void* BTSYMBOLS(bt_cs_register_callbacks)(bt_instance_t* ins, const cs_callbacks_t* callbacks)
{
bt_cs_interface_t* profile = get_profile_service();

return profile->register_callbacks(NULL, callbacks);
}

bool BTSYMBOLS(bt_cs_unregister_callbacks)(bt_instance_t* ins, void* cookie)
{
bt_cs_interface_t* profile = get_profile_service();

return profile->unregister_callbacks(NULL, cookie);
}

bt_status_t BTSYMBOLS(bt_cs_start_distance_measurement)(bt_instance_t* ins, bt_distance_measurement_params_t* params)
{
bt_cs_interface_t* profile = get_profile_service();

return profile->start_distance_measurement(params);
}

bt_status_t BTSYMBOLS(bt_cs_stop_distance_measurement)(bt_instance_t* ins, bt_address_t* addr, uint8_t method, bool timeout)
{
bt_cs_interface_t* profile = get_profile_service();

return profile->stop_distance_measurement(addr, method, timeout);
}

bt_status_t BTSYMBOLS(bt_cs_test)(bt_instance_t* ins, void* data, uint16_t len)
{
bt_cs_interface_t* profile = get_profile_service();

return profile->cs_test(data, len);
}

#endif /* CONFIG_BLUETOOTH_LE_CS */
2 changes: 2 additions & 0 deletions framework/include/bluetooth.h
Original file line number Diff line number Diff line change
Expand Up @@ -459,11 +459,13 @@ typedef struct bt_instance {
callbacks_list_t* a2dp_source_callbacks;
callbacks_list_t* avrcp_target_callbacks;
callbacks_list_t* avrcp_control_callbacks;
callbacks_list_t* cs_callbacks;
void* adapter_cookie;
void* a2dp_sink_cookie;
void* a2dp_source_cookie;
void* avrcp_target_cookie;
void* avrcp_control_cookie;
void* cs_cookie;

callbacks_list_t* hfp_ag_callbacks;
callbacks_list_t* hfp_hf_callbacks;
Expand Down
3 changes: 2 additions & 1 deletion framework/include/bt_addr.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ extern "C" {
#define BT_ADDR_LENGTH 6 /*define the address length*/
#define BT_ADDR_STR_LENGTH 18

#ifndef bt_addr_str
#define bt_addr_str(addr) bt_addr_bastr(addr)

#endif
/**
* @cond
*/
Expand Down
78 changes: 78 additions & 0 deletions framework/include/bt_cs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/****************************************************************************
* Copyright (C) 2025 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#ifndef __BT_CS_H__
#define __BT_CS_H__

#include "bt_addr.h"
#include "bt_device.h"
#include "bt_internal.h"
#include <stddef.h>

#ifndef BTSYMBOLS
#define BTSYMBOLS(s) s
#endif

typedef void (*cs_distance_measure_started_cb)(void* cookie, bt_address_t* addr, uint8_t method);
typedef void (*cs_distance_measure_stopped_cb)(void* cookie, bt_address_t* addr, uint8_t reason, uint8_t method);
typedef void (*cs_distance_measure_result_cb)(void* cookie, bt_address_t* addr, uint8_t centimeter, uint8_t errorCentimeter,
uint8_t azimuthAngle, uint8_t errorAzimuthAngle, uint8_t altitudeAngle, uint8_t errorAltitudeAngle,
long elapsedRealtimeNanos, uint8_t confidenceLevel, double delaySpreadMeters,
uint8_t detectedAttackLevel, double velocityMetersPerSecond, uint8_t method);

/**
* @cond
*/
typedef struct {
bt_address_t addr;
uint8_t method;
uint8_t role;
uint16_t interval_ms;
uint16_t duration_ms;
uint8_t submode;
uint8_t max_steps;
uint8_t mode0_steps;
uint8_t rtt_type;
uint8_t sync_phy;
uint8_t channel_map;
uint8_t antenna_paths_mask;
uint8_t vendor_specific;
uint8_t debug_flags;
} bt_distance_measurement_params_t;

typedef struct {
size_t size;
cs_distance_measure_started_cb cs_distance_measure_started_cb;
cs_distance_measure_stopped_cb cs_distance_measure_stopped_cb;
cs_distance_measure_result_cb cs_distance_measure_result_cb;
} cs_callbacks_t;

typedef enum {
METHOD_AUTO,
METHOD_RSSI,
METHOD_CS,
} cs_method_t;

/**
* @endcond
*/
void* BTSYMBOLS(bt_cs_register_callbacks)(bt_instance_t* ins, const cs_callbacks_t* callbacks);
bool BTSYMBOLS(bt_cs_unregister_callbacks)(bt_instance_t* ins, void* cookie);
bt_status_t BTSYMBOLS(bt_cs_start_distance_measurement)(bt_instance_t* ins, bt_distance_measurement_params_t* params);
bt_status_t BTSYMBOLS(bt_cs_stop_distance_measurement)(bt_instance_t* ins, bt_address_t* addr, uint8_t method, bool timeout);
bt_status_t BTSYMBOLS(bt_get_cs_max_supported_security_level)(bt_instance_t* ins, bt_address_t* addr);
bt_status_t BTSYMBOLS(bt_cs_test)(bt_instance_t* ins, void* data, uint16_t len);

#endif /* __BT_CS_H__ */
2 changes: 1 addition & 1 deletion framework/include/bt_gatts.h
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ typedef struct {
gatts_phy_read_cb_t on_phy_read;
gatts_phy_updated_cb_t on_phy_updated;
gatts_connection_parameter_changed_cb_t on_conn_param_changed;

} gatts_callbacks_t;

/**
Expand Down
2 changes: 2 additions & 0 deletions framework/include/bt_profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ extern "C" {
#define PROFILE_A2DP_SINK_NAME "A2DP-Sink"
#define PROFILE_AVRCP_CT_NAME "AVRCP-CT"
#define PROFILE_AVRCP_TG_NAME "AVRCP-TG"
#define PROFILE_CS_NAME "CS"
#define PROFILE_HFP_HF_NAME "HFP-HF"
#define PROFILE_HFP_AG_NAME "HFP-AG"
#define PROFILE_SPP_NAME "SPP"
Expand Down Expand Up @@ -60,6 +61,7 @@ enum profile_id {
PROFILE_LEAUDIO_MCS,
PROFILE_LEAUDIO_TBS,
PROFILE_LEAUDIO_VMICP,
PROFILE_CS,
PROFILE_UNKOWN,
PROFILE_MAX
};
Expand Down
Loading
Loading