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
4 changes: 4 additions & 0 deletions apps/bttester/src/btp/btp.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@
#define BTP_STATUS_UNKNOWN_CMD 0x02
#define BTP_STATUS_NOT_READY 0x03

#define BTP_EVENT_OPCODE_BASE 0x80
#define BTP_EVENT_BIT(ev) ((uint8_t)(ev) - BTP_EVENT_OPCODE_BASE)
#define BTP_EVENT_BITMAP_LEN(last_ev) (BTP_EVENT_BIT(last_ev) / 8 + 1)

/* TODO indicate delay response, should be removed when all commands are
* converted to cmd+status+ev pattern
*/
Expand Down
6 changes: 6 additions & 0 deletions apps/bttester/src/btp/btp_bap.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ struct btp_bap_broadcast_source_setup_v2_rp {
uint32_t gap_settings;
} __packed;

#define BTP_BAP_READ_SUPPORTED_EVENTS 0x1b
struct btp_bap_read_supported_events_rp {
uint8_t data[0];
} __packed;

/* events */
#define BTP_BAP_EV_DISCOVERY_COMPLETED 0x80
struct btp_bap_discovery_completed_ev {
ble_addr_t address;
Expand Down
5 changes: 5 additions & 0 deletions apps/bttester/src/btp/btp_gap.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,11 @@ struct gap_subrate_request_cmd {
uint16_t supervision_timeout;
} __packed;

#define BTP_GAP_READ_SUPPORTED_EVENTS 0x34
struct btp_gap_read_supported_events_rp {
uint8_t data[0];
} __packed;

/* events */
#define BTP_GAP_EV_NEW_SETTINGS 0x80
struct btp_gap_new_settings_ev {
Expand Down
5 changes: 5 additions & 0 deletions apps/bttester/src/btp/btp_gatt.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,11 @@ struct btp_gatt_notify_mult_val_cmd {
uint16_t handles[0];
} __packed;

#define BTP_GATT_READ_SUPPORTED_EVENTS 0x24
struct btp_gatt_read_supported_events_rp {
uint8_t data[0];
} __packed;

/* GATT events */
#define BTP_GATT_EV_NOTIFICATION 0x80
struct btp_gatt_notification_ev {
Expand Down
5 changes: 5 additions & 0 deletions apps/bttester/src/btp/btp_gattc.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ struct btp_gattc_read_multiple_var_cmd {
uint16_t handles[0];
} __packed;

#define BTP_GATTC_READ_SUPPORTED_EVENTS 0x15
struct btp_gattc_read_supported_events_rp {
uint8_t data[0];
} __packed;

/* events */
#define BTP_GATTC_EV_MTU_EXCHANGED 0x80
struct btp_gattc_exchange_mtu_ev {
Expand Down
5 changes: 5 additions & 0 deletions apps/bttester/src/btp/btp_l2cap.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ struct btp_l2cap_credits_cmd {
uint8_t chan_id;
} __packed;

#define BTP_L2CAP_READ_SUPPORTED_EVENTS 0x0e
struct btp_l2cap_read_supported_events_rp {
uint8_t data[0];
} __packed;

/* events */
#define BTP_L2CAP_EV_CONNECTION_REQ 0x80
struct btp_l2cap_connection_req_ev {
Expand Down
5 changes: 5 additions & 0 deletions apps/bttester/src/btp/btp_mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ struct btp_mesh_lpn_unsubscribe_cmd {
#define BTP_MESH_PROXY_IDENTITY 0x13
#define BTP_MESH_START 0x78

#define BTP_MESH_READ_SUPPORTED_EVENTS 0x79
struct btp_mesh_read_supported_events_rp {
uint8_t data[0];
} __packed;

/* events */
#define BTP_MESH_EV_OUT_NUMBER_ACTION 0x80
struct btp_mesh_out_number_action_ev {
Expand Down
4 changes: 4 additions & 0 deletions apps/bttester/src/btp/bttester.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ void tester_register_command_handlers(uint8_t service,
const struct btp_handler *handlers,
size_t num);

void tester_register_supported_events(uint8_t service, const uint8_t *events,
uint8_t len);

uint16_t tester_supported_commands(uint8_t service, uint8_t *cmds);
uint16_t tester_supported_events(uint8_t service, uint8_t *events);

void
tester_send_buf(uint8_t service, uint8_t opcode, uint8_t index,
Expand Down
50 changes: 50 additions & 0 deletions apps/bttester/src/btp_bap.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,33 @@ static uint32_t sdu_interval;

static struct ble_audio_base tester_base;

/* Important: Remember to update this if new events are introduced */
#define BTP_BAP_EV_MAX BTP_BAP_EV_PA_SYNC_REQ

#define BAP_SUPPORTED_EVENTS_LEN \
BTP_EVENT_BITMAP_LEN(BTP_BAP_EV_MAX)

static uint8_t bap_supported_events[BAP_SUPPORTED_EVENTS_LEN];

static void
bap_init_supported_events(void)
{
memset(bap_supported_events, 0, sizeof(bap_supported_events));

tester_set_bit(bap_supported_events, BTP_EVENT_BIT(BTP_BAP_EV_DISCOVERY_COMPLETED));
tester_set_bit(bap_supported_events, BTP_EVENT_BIT(BTP_BAP_EV_CODEC_CAP_FOUND));
tester_set_bit(bap_supported_events, BTP_EVENT_BIT(BTP_BAP_EV_ASE_FOUND));
tester_set_bit(bap_supported_events, BTP_EVENT_BIT(BTP_BAP_EV_STREAM_RECEIVED));
tester_set_bit(bap_supported_events, BTP_EVENT_BIT(BTP_BAP_EV_BAA_FOUND));
tester_set_bit(bap_supported_events, BTP_EVENT_BIT(BTP_BAP_EV_BIS_FOUND));
tester_set_bit(bap_supported_events, BTP_EVENT_BIT(BTP_BAP_EV_BIS_SYNCED));
tester_set_bit(bap_supported_events, BTP_EVENT_BIT(BTP_BAP_EV_BIS_STREAM_RECEIVED));
tester_set_bit(bap_supported_events, BTP_EVENT_BIT(BTP_BAP_EV_SCAN_DELEGATOR_FOUND));
tester_set_bit(bap_supported_events, BTP_EVENT_BIT(BTP_BAP_EV_BROADCAST_RECEIVE_STATE));
tester_set_bit(bap_supported_events, BTP_EVENT_BIT(BTP_BAP_EV_PA_SYNC_REQ));
}


static os_membuf_t bis_mem[
OS_MEMPOOL_SIZE(MYNEWT_VAL(BLE_ISO_MAX_BISES),
sizeof(struct ble_audio_bis))
Expand Down Expand Up @@ -145,6 +172,18 @@ supported_commands(const void *cmd, uint16_t cmd_len,
return BTP_STATUS_SUCCESS;
}

static uint8_t
supported_events(const void *cmd, uint16_t cmd_len,
void *rsp, uint16_t *rsp_len)
{
struct btp_bap_read_supported_events_rp *rp = rsp;

*rsp_len = tester_supported_events(BTP_SERVICE_ID_BAP, rp->data);
*rsp_len += sizeof(*rp);

return BTP_STATUS_SUCCESS;
}

static int
base_create(const struct bap_broadcast_source_setup_cmd *cmd)
{
Expand Down Expand Up @@ -402,6 +441,12 @@ static const struct btp_handler handlers[] = {
.expect_len = 0,
.func = supported_commands,
},
{
.opcode = BTP_BAP_READ_SUPPORTED_EVENTS,
.index = BTP_INDEX_NONE,
.expect_len = 0,
.func = supported_events,
},
{
.opcode = BTP_BAP_BROADCAST_SOURCE_SETUP,
.index = BTP_INDEX,
Expand Down Expand Up @@ -653,8 +698,13 @@ tester_init_bap(void)
scan_delegator_audio_event_handler, NULL);
assert(rc == 0);

bap_init_supported_events();

tester_register_command_handlers(BTP_SERVICE_ID_BAP, handlers,
ARRAY_SIZE(handlers));
tester_register_supported_events(BTP_SERVICE_ID_BAP,
bap_supported_events,
sizeof(bap_supported_events));

return BTP_STATUS_SUCCESS;
}
Expand Down
61 changes: 61 additions & 0 deletions apps/bttester/src/btp_gap.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "../../../nimble/host/src/ble_sm_priv.h"

#include "btp/btp.h"
#include "btp/bttester.h"

#include <errno.h>

Expand Down Expand Up @@ -89,6 +90,44 @@ static const struct ble_gap_conn_params dflt_conn_params = {
.max_ce_len = 0x0300,
};

/* Important: Remember to update this if new events are introduced */
#define BTP_GAP_EV_MAX GAP_EV_SUBRATE_CHANGE

#define GAP_SUPPORTED_EVENTS_LEN \
BTP_EVENT_BITMAP_LEN(BTP_GAP_EV_MAX)

static uint8_t gap_supported_events[GAP_SUPPORTED_EVENTS_LEN];

static void
gap_init_supported_events(void)
{
memset(gap_supported_events, 0, sizeof(gap_supported_events));

tester_set_bit(gap_supported_events, BTP_EVENT_BIT(BTP_GAP_EV_NEW_SETTINGS));
tester_set_bit(gap_supported_events, BTP_EVENT_BIT(BTP_GAP_EV_DEVICE_FOUND));
tester_set_bit(gap_supported_events, BTP_EVENT_BIT(BTP_GAP_EV_DEVICE_CONNECTED));
tester_set_bit(gap_supported_events, BTP_EVENT_BIT(BTP_GAP_EV_DEVICE_DISCONNECTED));
tester_set_bit(gap_supported_events, BTP_EVENT_BIT(BTP_GAP_EV_PASSKEY_DISPLAY));
tester_set_bit(gap_supported_events, BTP_EVENT_BIT(BTP_GAP_EV_PASSKEY_ENTRY_REQ));
tester_set_bit(gap_supported_events, BTP_EVENT_BIT(BTP_GAP_EV_PASSKEY_CONFIRM_REQ));
tester_set_bit(gap_supported_events, BTP_EVENT_BIT(BTP_GAP_EV_IDENTITY_RESOLVED));
tester_set_bit(gap_supported_events, BTP_EVENT_BIT(BTP_GAP_EV_CONN_PARAM_UPDATE));
tester_set_bit(gap_supported_events, BTP_EVENT_BIT(BTP_GAP_EV_SEC_LEVEL_CHANGED));
tester_set_bit(gap_supported_events, BTP_EVENT_BIT(BTP_GAP_EV_BOND_LOST));
tester_set_bit(gap_supported_events, BTP_EVENT_BIT(BTP_GAP_EV_SEC_PAIRING_FAILED));
#if MYNEWT_VAL(BLE_PERIODIC_ADV)
tester_set_bit(gap_supported_events, BTP_EVENT_BIT(GAP_EV_PERIODIC_SYNC_ESTABLISHED));
tester_set_bit(gap_supported_events, BTP_EVENT_BIT(GAP_EV_PERIODIC_SYNC_LOST));
tester_set_bit(gap_supported_events, BTP_EVENT_BIT(GAP_EV_PERIODIC_REPORT));
#endif
#if MYNEWT_VAL(BLE_PERIODIC_ADV_SYNC_TRANSFER)
tester_set_bit(gap_supported_events, BTP_EVENT_BIT(GAP_EV_PERIODIC_TRANSFER_RECEIVED));
#endif
#if MYNEWT_VAL(BLE_CONN_SUBRATING)
tester_set_bit(gap_supported_events, BTP_EVENT_BIT(GAP_EV_SUBRATE_CHANGE));
#endif
}

static int
gap_conn_find_by_addr(const ble_addr_t *dev_addr,
struct ble_gap_conn_desc *out_desc)
Expand Down Expand Up @@ -134,6 +173,18 @@ supported_commands(const void *cmd, uint16_t cmd_len,
return BTP_STATUS_SUCCESS;
}

static uint8_t
supported_events(const void *cmd, uint16_t cmd_len,
void *rsp, uint16_t *rsp_len)
{
struct btp_gap_read_supported_events_rp *rp = rsp;

*rsp_len = tester_supported_events(BTP_SERVICE_ID_GAP, rp->data);
*rsp_len += sizeof(*rp);

return BTP_STATUS_SUCCESS;
}

static uint8_t
controller_index_list(const void *cmd, uint16_t cmd_len,
void *rsp, uint16_t *rsp_len)
Expand Down Expand Up @@ -2277,6 +2328,12 @@ static const struct btp_handler handlers[] = {
.expect_len = 0,
.func = supported_commands,
},
{
.opcode = BTP_GAP_READ_SUPPORTED_EVENTS,
.index = BTP_INDEX_NONE,
.expect_len = 0,
.func = supported_events,
},
{
.opcode = BTP_GAP_READ_CONTROLLER_INDEX_LIST,
.index = BTP_INDEX_NONE,
Expand Down Expand Up @@ -2483,9 +2540,13 @@ tester_init_gap(void)
assert(adv_buf);

tester_init_gap_cb();
gap_init_supported_events();

tester_register_command_handlers(BTP_SERVICE_ID_GAP, handlers,
ARRAY_SIZE(handlers));
tester_register_supported_events(BTP_SERVICE_ID_GAP,
gap_supported_events,
sizeof(gap_supported_events));

return BTP_STATUS_SUCCESS;
}
Expand Down
40 changes: 40 additions & 0 deletions apps/bttester/src/btp_gatt.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,23 @@
#define PTS_INC_SVC 0x001e
#define PTS_CHR_READ_WRITE_ALT 0x001f

/* Important: Remember to update this if new events are introduced */
#define BTP_GATT_EV_MAX BTP_GATT_EV_ATTR_VALUE_CHANGED

#define GATT_SUPPORTED_EVENTS_LEN \
BTP_EVENT_BITMAP_LEN(BTP_GATT_EV_MAX)

static uint8_t gatt_supported_events[GATT_SUPPORTED_EVENTS_LEN];

static void
gatt_init_supported_events(void)
{
memset(gatt_supported_events, 0, sizeof(gatt_supported_events));

tester_set_bit(gatt_supported_events, BTP_EVENT_BIT(BTP_GATT_EV_NOTIFICATION));
tester_set_bit(gatt_supported_events, BTP_EVENT_BIT(BTP_GATT_EV_ATTR_VALUE_CHANGED));
}

static uint8_t gatt_svr_pts_static_long_val[300];
static uint8_t gatt_svr_pts_static_val[30];
static uint8_t gatt_svr_pts_static_short_val;
Expand Down Expand Up @@ -1958,6 +1975,18 @@ supported_commands(const void *cmd, uint16_t cmd_len,
return BTP_STATUS_SUCCESS;
}

static uint8_t
supported_events(const void *cmd, uint16_t cmd_len,
void *rsp, uint16_t *rsp_len)
{
struct btp_gatt_read_supported_events_rp *rp = rsp;

*rsp_len = tester_supported_events(BTP_SERVICE_ID_GATT, rp->data);
*rsp_len += sizeof(*rp);

return BTP_STATUS_SUCCESS;
}

enum attr_type {
BLE_GATT_ATTR_SVC = 0,
BLE_GATT_ATTR_CHR,
Expand All @@ -1971,6 +2000,12 @@ static const struct btp_handler handlers[] = {
.expect_len = 0,
.func = supported_commands,
},
{
.opcode = BTP_GATT_READ_SUPPORTED_EVENTS,
.index = BTP_INDEX_NONE,
.expect_len = 0,
.func = supported_events,
},
{
.opcode = BTP_GATT_START_SERVER,
.expect_len = 0,
Expand Down Expand Up @@ -2294,8 +2329,13 @@ tester_init_gatt(void)
os_callout_init(&notify_tx_timer, os_eventq_dflt_get(),
notify_test, NULL);

gatt_init_supported_events();

tester_register_command_handlers(BTP_SERVICE_ID_GATT, handlers,
ARRAY_SIZE(handlers));
tester_register_supported_events(BTP_SERVICE_ID_GATT,
gatt_supported_events,
sizeof(gatt_supported_events));

return BTP_STATUS_SUCCESS;
}
Expand Down
Loading
Loading