Skip to content

tester: bas: Add support for testing Battery Service #77745

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
4 changes: 4 additions & 0 deletions tests/bluetooth/tester/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,9 @@ if(CONFIG_BT_OTS)
target_sources(app PRIVATE src/btp_ots.c)
endif()

if(CONFIG_BT_BAS)
target_sources(app PRIVATE src/btp_bas.c)
endif()

zephyr_library_include_directories(src src/btp src/audio/btp)
add_subdirectory_ifdef(CONFIG_BT_AUDIO src/audio)
6 changes: 6 additions & 0 deletions tests/bluetooth/tester/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,9 @@ CONFIG_BT_BUF_EVT_RX_SIZE=255
CONFIG_BT_BUF_CMD_TX_SIZE=255
CONFIG_BT_BUF_ACL_TX_SIZE=251
CONFIG_BT_BUF_ACL_RX_SIZE=255

CONFIG_BT_BAS=y
CONFIG_BT_BAS_BLS=y
CONFIG_BT_BAS_BLS_IDENTIFIER_PRESENT=y
CONFIG_BT_BAS_BLS_BATTERY_LEVEL_PRESENT=y
CONFIG_BT_BAS_BLS_ADDITIONAL_STATUS_PRESENT=y
4 changes: 3 additions & 1 deletion tests/bluetooth/tester/src/btp/btp.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "btp_tmap.h"
#include "btp_ots.h"
#include "btp_pbp.h"
#include "btp_bas.h"

#define BTP_MTU 1024
#define BTP_DATA_MAX_SIZE (BTP_MTU - sizeof(struct btp_hdr))
Expand Down Expand Up @@ -77,8 +78,9 @@
#define BTP_SERVICE_ID_TMAP 0x1c
#define BTP_SERVICE_ID_OTS 0x1d
#define BTP_SERVICE_ID_PBP 0x1e
#define BTP_SERVICE_ID_BAS 0x1f

#define BTP_SERVICE_ID_MAX BTP_SERVICE_ID_PBP
#define BTP_SERVICE_ID_MAX BTP_SERVICE_ID_BAS

#define BTP_STATUS_SUCCESS 0x00
#define BTP_STATUS_FAILED 0x01
Expand Down
92 changes: 92 additions & 0 deletions tests/bluetooth/tester/src/btp/btp_bas.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* Copyright (c) 2024 Demant A/S
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef BTP_BAS_H_
#define BTP_BAS_H_

#include <stdint.h>
#include <stddef.h>

/* BTP BAS Service Opcodes */
#define BTP_BAS_READ_SUPPORTED_COMMANDS 0x01
#define BTP_BAS_SET_BATTERY_LEVEL 0x02
#define BTP_BAS_BLS_SET_BATTERY_PRESENT 0x03
#define BTP_BAS_BLS_SET_WIRED_POWER_SOURCE 0x04
#define BTP_BAS_BLS_SET_WIRELESS_POWER_SOURCE 0x05
#define BTP_BAS_BLS_SET_BATTERY_CHARGE_STATE 0x06
#define BTP_BAS_BLS_SET_BATTERY_CHARGE_LEVEL 0x07
#define BTP_BAS_BLS_SET_BATTERY_CHARGE_TYPE 0x08
#define BTP_BAS_BLS_SET_CHARGING_FAULT_REASON 0x09
#define BTP_BAS_BLS_SET_IDENTIFIER 0x0A
#define BTP_BAS_BLS_SET_SERVICE_REQUIRED 0x0B
#define BTP_BAS_BLS_SET_BATTERY_FAULT 0x0C

/* Command structures */
struct btp_bas_read_supported_commands_rp {
uint8_t data[0];
} __packed;

struct btp_bas_set_battery_level_cmd {
uint8_t level;
} __packed;

struct btp_bas_bls_set_battery_present_cmd {
uint8_t present;
} __packed;

struct btp_bas_bls_set_wired_power_source_cmd {
uint8_t source;
} __packed;

struct btp_bas_bls_set_wireless_power_source_cmd {
uint8_t source;
} __packed;

struct btp_bas_bls_set_battery_charge_state_cmd {
uint8_t state;
} __packed;

struct btp_bas_bls_set_battery_charge_level_cmd {
uint8_t level;
} __packed;

struct btp_bas_bls_set_battery_charge_type_cmd {
uint8_t type;
} __packed;

struct btp_bas_bls_set_charging_fault_reason_cmd {
uint8_t reason;
} __packed;

struct btp_bas_bls_set_identifier_cmd {
uint16_t identifier;
} __packed;

struct btp_bas_bls_set_service_required_cmd {
uint8_t service_required;
} __packed;

struct btp_bas_bls_set_battery_fault_cmd {
uint8_t battery_fault;
} __packed;

/**
* @brief Initialize the Battery Service (BAS) tester.
*
* @return Status of the initialization. Returns `BTP_STATUS_SUCCESS`
* if the initialization is successful. Other values indicate failure.
*/
uint8_t tester_init_bas(void);

/**
* @brief Unregister the Battery Service (BAS) tester.
*
* @return Status of the unregistration. Returns `BTP_STATUS_SUCCESS`
* if the unregistration is successful. Other values indicate failure.
*/
uint8_t tester_unregister_bas(void);

#endif /* BTP_BAS_H_ */
Loading
Loading