Skip to content

Commit

Permalink
[WIP] Bttester native
Browse files Browse the repository at this point in the history
Develop native mode for bttester.
  • Loading branch information
szymon-czapracki committed Aug 1, 2024
1 parent 72eed31 commit 70c95c1
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 77 deletions.
9 changes: 5 additions & 4 deletions apps/bttester/src/btp/btp.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
#include "btp_mesh.h"
#include "btp_bap.h"

#ifndef __packed
#define __packed __attribute__((__packed__))
#endif

#define BTP_MTU MYNEWT_VAL(BTTESTER_BTP_DATA_SIZE_MAX)
#define BTP_DATA_MAX_SIZE (BTP_MTU - sizeof(struct btp_hdr))

Expand Down Expand Up @@ -63,10 +67,7 @@
#define BTP_STATUS_DELAY_REPLY 0xFF

#define SYS_LOG_DBG(fmt, ...) \
if (MYNEWT_VAL(BTTESTER_DEBUG)) { \
console_printf("[DBG] %s: " fmt "\n", \
__func__, ## __VA_ARGS__); \
}
//if (MYNEWT_VAL(BTTESTER_DEBUG)) {}
#define SYS_LOG_INF(fmt, ...) console_printf("[INF] %s: " fmt "\n", \
__func__, ## __VA_ARGS__);
#define SYS_LOG_ERR(fmt, ...) console_printf("[WRN] %s: " fmt "\n", \
Expand Down
4 changes: 4 additions & 0 deletions apps/bttester/src/btp/btp_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef __packed
#define __packed __attribute__((__packed__))
#endif

/* Core Service */
#define BTP_CORE_READ_SUPPORTED_COMMANDS 0x01
struct btp_core_read_supported_commands_rp {
Expand Down
14 changes: 7 additions & 7 deletions apps/bttester/src/btp_gatt.c
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ read_cb(uint16_t conn_handle,
void *arg)
{
struct btp_gatt_read_rp *rp = (void *) gatt_buf.buf;
uint8_t btp_opcode = (uint8_t) (int) arg;
uint8_t btp_opcode = (uint8_t) (intptr_t) arg;

SYS_LOG_DBG("status=%d", error->status);

Expand Down Expand Up @@ -760,7 +760,7 @@ read_long_cb(uint16_t conn_handle,
void *arg)
{
struct btp_gatt_read_rp *rp = (void *) gatt_buf.buf;
uint8_t btp_opcode = (uint8_t) (int) arg;
uint8_t btp_opcode = (uint8_t) (intptr_t) arg;

SYS_LOG_DBG("status=%d", error->status);

Expand Down Expand Up @@ -896,7 +896,7 @@ write_rsp(uint16_t conn_handle, const struct ble_gatt_error *error,
void *arg)
{
uint8_t err = (uint8_t) error->status;
uint8_t btp_opcode = (uint8_t) (int) arg;
uint8_t btp_opcode = (uint8_t) (intptr_t) arg;

SYS_LOG_DBG("");

Expand Down Expand Up @@ -1087,7 +1087,7 @@ disc_prim_uuid_cb(uint16_t conn_handle,
struct btp_gatt_service *service;
const ble_uuid_any_t *uuid;
uint8_t uuid_length;
uint8_t opcode = (uint8_t) (int) arg;
uint8_t opcode = (uint8_t) (intptr_t) arg;

SYS_LOG_DBG("");

Expand Down Expand Up @@ -1259,7 +1259,7 @@ find_included_cb(uint16_t conn_handle,
struct btp_gatt_find_included_rp *rp = (void *) gatt_buf.buf;
struct btp_gatt_included *included;
const ble_uuid_any_t *uuid;
int service_handle = (int) arg;
int service_handle = (intptr_t) arg;
uint8_t uuid_length;

SYS_LOG_DBG("");
Expand Down Expand Up @@ -1316,7 +1316,7 @@ disc_chrc_cb(uint16_t conn_handle,
struct btp_gatt_disc_chrc_rp *rp = (void *) gatt_buf.buf;
struct btp_gatt_characteristic *chrc;
const ble_uuid_any_t *uuid;
uint8_t btp_opcode = (uint8_t) (int) arg;
uint8_t btp_opcode = (uint8_t) (intptr_t) arg;
uint8_t uuid_length;

SYS_LOG_DBG("");
Expand Down Expand Up @@ -1503,7 +1503,7 @@ find_included(const void *cmd, uint16_t cmd_len,

if (ble_gattc_find_inc_svcs(conn.conn_handle, start_handle, end_handle,
find_included_cb,
(void *) service_handle_arg)) {
(void *) (uintptr_t) service_handle_arg)) {
discover_destroy();
return BTP_STATUS_FAILED;
}
Expand Down
22 changes: 11 additions & 11 deletions apps/bttester/src/btp_gatt_cl.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ disc_prim_svcs_cb(uint16_t conn_handle,
const ble_uuid_any_t *uuid;
uint8_t uuid_length;
struct os_mbuf *buf = os_msys_get(0, 0);
uint8_t opcode = (uint8_t) (int) arg;
uint8_t opcode = (uint8_t) (intptr_t) arg;
uint8_t err = (uint8_t) error->status;
int rc = 0;

Expand Down Expand Up @@ -312,7 +312,7 @@ find_included_cb(uint16_t conn_handle,
struct btp_gattc_find_included_rp *rp;
struct btp_gatt_included *included;
const ble_uuid_any_t *uuid;
int service_handle = (int) arg;
int service_handle = (intptr_t) arg;
uint8_t uuid_length;
uint8_t err = (uint8_t) error->status;
struct os_mbuf *buf = os_msys_get(0, 0);
Expand Down Expand Up @@ -409,7 +409,7 @@ find_included(const void *cmd, uint16_t cmd_len,

if (ble_gattc_find_inc_svcs(conn.conn_handle, start_handle, end_handle,
find_included_cb,
(void *) service_handle_arg)) {
(void *) (uintptr_t) service_handle_arg)) {
discover_destroy();
return BTP_STATUS_FAILED;
}
Expand All @@ -426,7 +426,7 @@ disc_chrc_cb(uint16_t conn_handle,
struct btp_gatt_characteristic *chrc;
const ble_uuid_any_t *uuid;
uint8_t uuid_length;
uint8_t opcode = (uint8_t) (int) arg;
uint8_t opcode = (uint8_t) (intptr_t) arg;
uint8_t err = (uint8_t) error->status;
struct os_mbuf *buf = os_msys_get(0, 0);
struct ble_gap_conn_desc conn;
Expand Down Expand Up @@ -687,7 +687,7 @@ read_cb(uint16_t conn_handle,
void *arg)
{
struct btp_gattc_read_rp *rp;
uint8_t opcode = (uint8_t) (int) arg;
uint8_t opcode = (uint8_t) (intptr_t) arg;
struct os_mbuf *buf = os_msys_get(0, 0);
struct ble_gap_conn_desc conn;
int rc = 0;
Expand Down Expand Up @@ -768,7 +768,7 @@ read_uuid_cb(uint16_t conn_handle,
{
struct btp_gattc_read_uuid_rp *rp;
struct btp_gatt_read_uuid_chr *chr;
uint8_t opcode = (uint8_t) (int) arg;
uint8_t opcode = (uint8_t) (intptr_t) arg;
uint8_t err = (uint8_t) error->status;
struct os_mbuf *buf = os_msys_get(0, 0);
struct ble_gap_conn_desc conn;
Expand Down Expand Up @@ -872,7 +872,7 @@ read_long_cb(uint16_t conn_handle,
void *arg)
{
struct btp_gattc_read_rp *rp;;
uint8_t opcode = (uint8_t) (int) arg;
uint8_t opcode = (uint8_t) (intptr_t) arg;
uint8_t err = (uint8_t) error->status;
struct os_mbuf *buf = os_msys_get(0, 0);
struct ble_gap_conn_desc conn;
Expand Down Expand Up @@ -1026,7 +1026,7 @@ write_cb(uint16_t conn_handle, const struct ble_gatt_error *error,
{
struct btp_gattc_write_rp *rp;
uint8_t err = (uint8_t) error->status;
uint8_t opcode = (uint8_t) (int) arg;
uint8_t opcode = (uint8_t) (intptr_t) arg;
struct os_mbuf *buf = os_msys_get(0, 0);
struct ble_gap_conn_desc conn;
int rc = 0;
Expand Down Expand Up @@ -1211,7 +1211,7 @@ subscribe_cb(uint16_t conn_handle,
{
struct btp_subscribe_rp *rp;
uint8_t err = (uint8_t) error->status;
uint8_t opcode = (uint8_t) (int) arg;
uint8_t opcode = (uint8_t) (intptr_t) arg;
struct os_mbuf *buf = os_msys_get(0, 0);
struct ble_gap_conn_desc conn;
int rc = 0;
Expand Down Expand Up @@ -1255,7 +1255,7 @@ enable_subscription(uint16_t conn_handle, uint16_t ccc_handle,
&value,
sizeof(value),
subscribe_cb,
(void *) opcode)) {
(void *) (uintptr_t) opcode)) {
return -EINVAL;
}

Expand Down Expand Up @@ -1286,7 +1286,7 @@ disable_subscription(uint16_t conn_handle, uint16_t ccc_handle)
&value,
sizeof(value),
subscribe_cb,
(void *) opcode)) {
(void *) (uintptr_t) opcode)) {
return -EINVAL;
}

Expand Down
36 changes: 18 additions & 18 deletions apps/bttester/src/btp_l2cap.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ get_channel(uint8_t chan_id)
static void
tester_l2cap_coc_recv(struct ble_l2cap_chan *chan, struct os_mbuf *sdu)
{
SYS_LOG_DBG("LE CoC SDU received, chan: 0x%08lx, data len %d",
(uint32_t) chan, OS_MBUF_PKTLEN(sdu));
/*SYS_LOG_DBG("LE CoC SDU received, chan: 0x%08lx, data len %d",
(uint32_t) chan, OS_MBUF_PKTLEN(sdu));*/

os_mbuf_free_chain(sdu);
if (!hold_credit) {
Expand Down Expand Up @@ -226,8 +226,8 @@ accept_cb(uint16_t conn_handle, uint16_t peer_mtu,
{
struct os_mbuf *sdu_rx;

SYS_LOG_DBG("LE CoC accepting, chan: 0x%08lx, peer_mtu %d",
(uint32_t) chan, peer_mtu);
/*SYS_LOG_DBG("LE CoC accepting, chan: 0x%08lx, peer_mtu %d",
(uint32_t) chan, peer_mtu);*/

sdu_rx = os_mbuf_get_pkthdr(&sdu_os_mbuf_pool, 0);
if (!sdu_rx) {
Expand Down Expand Up @@ -256,14 +256,14 @@ tester_l2cap_event(struct ble_l2cap_event *event, void *arg)
return 0;
}

console_printf("LE COC connected, conn: %d, chan: 0x%08lx, "
/*console_printf("LE COC connected, conn: %d, chan: 0x%08lx, "
"psm: 0x%02x, scid: 0x%04x, dcid: 0x%04x, "
"our_mps: %d, our_mtu: %d, peer_mps: %d, "
"peer_mtu: %d\n", event->connect.conn_handle,
(uint32_t) event->connect.chan, chan_info.psm,
chan_info.scid, chan_info.dcid,
chan_info.our_l2cap_mtu, chan_info.our_coc_mtu,
chan_info.peer_l2cap_mtu, chan_info.peer_coc_mtu);
chan_info.peer_l2cap_mtu, chan_info.peer_coc_mtu);*/

connected_cb(event->connect.conn_handle,
event->connect.chan, &chan_info, arg);
Expand All @@ -274,8 +274,8 @@ tester_l2cap_event(struct ble_l2cap_event *event, void *arg)
&chan_info)) {
assert(0);
}
console_printf("LE CoC disconnected, chan: 0x%08lx\n",
(uint32_t) event->disconnect.chan);
/*console_printf("LE CoC disconnected, chan: 0x%08lx\n",
(uint32_t) event->disconnect.chan);*/

disconnected_cb(event->disconnect.conn_handle,
event->disconnect.chan, &chan_info, arg);
Expand Down Expand Up @@ -310,41 +310,41 @@ tester_l2cap_event(struct ble_l2cap_event *event, void *arg)
}
}

console_printf(
/*console_printf(
"LE CoC accept, chan: 0x%08lx, handle: %u, sdu_size: %u\n",
(uint32_t) event->accept.chan,
event->accept.conn_handle,
event->accept.peer_sdu_size);
event->accept.peer_sdu_size);*/

return accept_cb(event->accept.conn_handle,
event->accept.peer_sdu_size,
event->accept.chan);

case BLE_L2CAP_EVENT_COC_DATA_RECEIVED:
console_printf(
/*console_printf(
"LE CoC data received, chan: 0x%08lx, handle: %u, sdu_len: %u\n",
(uint32_t) event->receive.chan,
event->receive.conn_handle,
OS_MBUF_PKTLEN(event->receive.sdu_rx));
OS_MBUF_PKTLEN(event->receive.sdu_rx));*/

recv_cb(event->receive.conn_handle, event->receive.chan,
event->receive.sdu_rx, arg);
return 0;
case BLE_L2CAP_EVENT_COC_TX_UNSTALLED:
console_printf(
/*console_printf(
"LE CoC tx unstalled, chan: 0x%08lx, handle: %u, status: %d\n",
(uint32_t) event->tx_unstalled.chan,
event->tx_unstalled.conn_handle,
event->tx_unstalled.status);
event->tx_unstalled.status);*/
return 0;
case BLE_L2CAP_EVENT_COC_RECONFIG_COMPLETED:
if (ble_l2cap_get_chan_info(event->reconfigured.chan,
&chan_info)) {
assert(0);
}
console_printf("LE CoC reconfigure completed status 0x%02x, "
/*console_printf("LE CoC reconfigure completed status 0x%02x, "
"chan: 0x%08lx\n", event->reconfigured.status,
(uint32_t) event->reconfigured.chan);
(uint32_t) event->reconfigured.chan);*/

if (event->reconfigured.status == 0) {
console_printf("\t our_mps: %d our_mtu %d\n",
Expand All @@ -361,9 +361,9 @@ tester_l2cap_event(struct ble_l2cap_event *event, void *arg)
&chan_info)) {
assert(0);
}
console_printf("LE CoC peer reconfigured status 0x%02x, "
/*console_printf("LE CoC peer reconfigured status 0x%02x, "
"chan: 0x%08lx\n", event->reconfigured.status,
(uint32_t) event->reconfigured.chan);
(uint32_t) event->reconfigured.chan);*/

if (event->reconfigured.status == 0) {
console_printf("\t peer_mps: %d peer_mtu %d\n",
Expand Down
13 changes: 7 additions & 6 deletions apps/bttester/src/bttester.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

#include "syscfg/syscfg.h"
#include "console/console.h"
Expand Down Expand Up @@ -144,10 +145,10 @@ cmd_handler(struct os_event *ev)

len = le16toh(cmd->hdr.len);
if (MYNEWT_VAL(BTTESTER_BTP_LOG)) {
console_printf("[DBG] received %d bytes: %s\n",
/*console_printf("[DBG] received %d bytes: %s\n",
sizeof(cmd->hdr) + len,
string_from_bytes(cmd->data,
sizeof(cmd->hdr) + len));
sizeof(cmd->hdr) + len));*/
}

btp = find_btp_handler(cmd->hdr.service, cmd->hdr.opcode);
Expand Down Expand Up @@ -289,11 +290,11 @@ tester_send_with_index(uint8_t service, uint8_t opcode, uint8_t index,
}

if (MYNEWT_VAL(BTTESTER_BTP_LOG)) {
console_printf("[DBG] send %d bytes hdr: %s\n", sizeof(msg),
string_from_bytes((char *) &msg, sizeof(msg)));
/*console_printf("[DBG] send %d bytes hdr: %s\n", sizeof(msg),
string_from_bytes((char *) &msg, sizeof(msg)));*/
if (data && len) {
console_printf("[DBG] send %d bytes data: %s\n", len,
string_from_bytes((char *) data, len));
/*console_printf("[DBG] send %d bytes data: %s\n", len,
string_from_bytes((char *) data, len));*/
}
}
}
Expand Down
Loading

0 comments on commit 70c95c1

Please sign in to comment.