mirror of
https://github.com/espressif/esp-nimble.git
synced 2026-08-12 21:17:57 +00:00
apps/bttester: drop glue module
There is no need to be dependent on `glue` module and it can be dropped from application. Mesh part of bttester can still use one from `"mesh/glue.h"`
This commit is contained in:
committed by
Szymon Janc
parent
2d4c591e27
commit
ba8a946fba
@@ -34,12 +34,6 @@
|
||||
#include "btp_l2cap.h"
|
||||
#include "btp_mesh.h"
|
||||
|
||||
#if MYNEWT_VAL(BLE_MESH)
|
||||
#include "mesh/glue.h"
|
||||
#else
|
||||
#include "../glue.h"
|
||||
#endif
|
||||
|
||||
#define BTP_MTU MYNEWT_VAL(BTTESTER_BTP_DATA_SIZE_MAX)
|
||||
#define BTP_DATA_MAX_SIZE (BTP_MTU - sizeof(struct btp_hdr))
|
||||
|
||||
@@ -78,10 +72,6 @@
|
||||
#define SYS_LOG_LEVEL SYS_LOG_LEVEL_DEBUG
|
||||
#define SYS_LOG_DOMAIN "bttester"
|
||||
|
||||
#define sys_cpu_to_le32 htole32
|
||||
#define sys_le32_to_cpu le32toh
|
||||
#define sys_cpu_to_le16 htole16
|
||||
|
||||
struct btp_hdr {
|
||||
uint8_t service;
|
||||
uint8_t opcode;
|
||||
|
||||
@@ -26,6 +26,21 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "nimble/ble.h"
|
||||
|
||||
struct adv_data {
|
||||
uint8_t type;
|
||||
uint8_t data_len;
|
||||
const uint8_t *data;
|
||||
};
|
||||
|
||||
#define ADV_DATA(_type, _data, _data_len) \
|
||||
{ \
|
||||
.type = (_type), \
|
||||
.data_len = (_data_len), \
|
||||
.data = (const uint8_t *)(_data), \
|
||||
}
|
||||
|
||||
/* GAP Service */
|
||||
/* commands */
|
||||
#define BTP_GAP_READ_SUPPORTED_COMMANDS 0x01
|
||||
|
||||
@@ -31,13 +31,18 @@
|
||||
|
||||
#include "syscfg/syscfg.h"
|
||||
#include "host/ble_gatt.h"
|
||||
#if MYNEWT_VAL(BLE_MESH)
|
||||
#include "mesh/glue.h"
|
||||
#else
|
||||
#include "glue.h"
|
||||
#endif
|
||||
#include "os/os_mbuf.h"
|
||||
#include <sys/types.h>
|
||||
|
||||
#define BIT(n) (1UL << (n))
|
||||
|
||||
/* Reset os_mbuf to reusable state */
|
||||
void
|
||||
tester_mbuf_reset(struct os_mbuf *buf);
|
||||
|
||||
const char *
|
||||
string_from_bytes(const void *buf, size_t len);
|
||||
|
||||
static inline void
|
||||
tester_set_bit(uint8_t *addr, unsigned int bit)
|
||||
{
|
||||
|
||||
+41
-23
@@ -35,6 +35,8 @@
|
||||
|
||||
#include "btp/btp.h"
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#define CONTROLLER_INDEX 0
|
||||
#define CONTROLLER_NAME "btp_tester"
|
||||
|
||||
@@ -235,8 +237,8 @@ controller_info(const void *cmd, uint16_t cmd_len,
|
||||
current_settings |= BIT(BTP_GAP_SETTINGS_SC);
|
||||
}
|
||||
|
||||
rp->supported_settings = sys_cpu_to_le32(supported_settings);
|
||||
rp->current_settings = sys_cpu_to_le32(current_settings);
|
||||
rp->supported_settings = htole32(supported_settings);
|
||||
rp->current_settings = htole32(current_settings);
|
||||
|
||||
memcpy(rp->name, CONTROLLER_NAME, sizeof(CONTROLLER_NAME));
|
||||
|
||||
@@ -299,7 +301,7 @@ set_connectable(const void *cmd, uint16_t cmd_len,
|
||||
adv_params.conn_mode = BLE_GAP_CONN_MODE_NON;
|
||||
}
|
||||
|
||||
rp->current_settings = sys_cpu_to_le32(current_settings);
|
||||
rp->current_settings = htole32(current_settings);
|
||||
|
||||
*rsp_len = sizeof(*rp);
|
||||
|
||||
@@ -339,7 +341,7 @@ set_discoverable(const void *cmd, uint16_t cmd_len,
|
||||
return BTP_STATUS_FAILED;
|
||||
}
|
||||
|
||||
rp->current_settings = sys_cpu_to_le32(current_settings);
|
||||
rp->current_settings = htole32(current_settings);
|
||||
|
||||
*rsp_len = sizeof(*rp);
|
||||
|
||||
@@ -362,18 +364,18 @@ set_bondable(const void *cmd, uint16_t cmd_len,
|
||||
current_settings &= ~BIT(BTP_GAP_SETTINGS_BONDABLE);
|
||||
}
|
||||
|
||||
rp->current_settings = sys_cpu_to_le32(current_settings);
|
||||
rp->current_settings = htole32(current_settings);
|
||||
*rsp_len = sizeof(*rp);
|
||||
return BTP_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static struct bt_data ad[10] = {
|
||||
BT_DATA(BLE_HS_ADV_TYPE_FLAGS, &ad_flags, sizeof(ad_flags)),
|
||||
static struct adv_data ad[10] = {
|
||||
ADV_DATA(BLE_HS_ADV_TYPE_FLAGS, &ad_flags, sizeof(ad_flags)),
|
||||
};
|
||||
static struct bt_data sd[10];
|
||||
static struct adv_data sd[10];
|
||||
|
||||
static int
|
||||
set_ad(const struct bt_data *ad_data, size_t ad_len,
|
||||
set_ad(const struct adv_data *ad_data, size_t ad_len,
|
||||
uint8_t *buf, uint8_t *buf_len)
|
||||
{
|
||||
int i;
|
||||
@@ -519,7 +521,7 @@ start_advertising(const void *cmd, uint16_t cmd_len,
|
||||
}
|
||||
|
||||
current_settings |= BIT(BTP_GAP_SETTINGS_ADVERTISING);
|
||||
rp->current_settings = sys_cpu_to_le32(current_settings);
|
||||
rp->current_settings = htole32(current_settings);
|
||||
|
||||
*rsp_len = sizeof(*rp);
|
||||
|
||||
@@ -541,7 +543,7 @@ stop_advertising(const void *cmd, uint16_t cmd_len,
|
||||
}
|
||||
|
||||
current_settings &= ~BIT(BTP_GAP_SETTINGS_ADVERTISING);
|
||||
rp->current_settings = sys_cpu_to_le32(current_settings);
|
||||
rp->current_settings = htole32(current_settings);
|
||||
|
||||
*rsp_len = sizeof(*rp);
|
||||
|
||||
@@ -584,18 +586,27 @@ store_adv(const ble_addr_t *addr, int8_t rssi,
|
||||
const uint8_t *data, uint8_t len)
|
||||
{
|
||||
struct btp_gap_device_found_ev *ev;
|
||||
|
||||
void *adv_data;
|
||||
/* cleanup */
|
||||
net_buf_simple_init(adv_buf, 0);
|
||||
tester_mbuf_reset(adv_buf);
|
||||
|
||||
ev = net_buf_simple_add(adv_buf, sizeof(*ev));
|
||||
ev = os_mbuf_extend(adv_buf, sizeof(*ev));
|
||||
if (!ev) {
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(ev->address, addr->val, sizeof(ev->address));
|
||||
ev->address_type = addr->type;
|
||||
ev->rssi = rssi;
|
||||
ev->flags = BTP_GAP_DEVICE_FOUND_FLAG_AD | BTP_GAP_DEVICE_FOUND_FLAG_RSSI;
|
||||
ev->eir_data_len = len;
|
||||
memcpy(net_buf_simple_add(adv_buf, len), data, len);
|
||||
|
||||
adv_data = os_mbuf_extend(adv_buf, len);
|
||||
if (!adv_data) {
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(adv_data, data, len);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -603,6 +614,7 @@ device_found(ble_addr_t *addr, int8_t rssi, uint8_t evtype,
|
||||
const uint8_t *data, uint8_t len)
|
||||
{
|
||||
struct btp_gap_device_found_ev *ev;
|
||||
void *adv_data;
|
||||
ble_addr_t a;
|
||||
|
||||
/* if General/Limited Discovery - parse Advertising data to get flags */
|
||||
@@ -649,7 +661,12 @@ device_found(ble_addr_t *addr, int8_t rssi, uint8_t evtype,
|
||||
ev->eir_data_len += len;
|
||||
ev->flags |= BTP_GAP_DEVICE_FOUND_FLAG_SD;
|
||||
|
||||
memcpy(net_buf_simple_add(adv_buf, len), data, len);
|
||||
adv_data = os_mbuf_extend(adv_buf, len);
|
||||
if (!adv_data) {
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(adv_data, data, len);
|
||||
|
||||
goto done;
|
||||
}
|
||||
@@ -712,7 +729,7 @@ start_discovery(const void *cmd, uint16_t cmd_len,
|
||||
return BTP_STATUS_FAILED;
|
||||
}
|
||||
|
||||
net_buf_simple_init(adv_buf, 0);
|
||||
tester_mbuf_reset(adv_buf);
|
||||
discovery_flags = cp->flags;
|
||||
|
||||
return BTP_STATUS_SUCCESS;
|
||||
@@ -910,7 +927,7 @@ auth_passkey_display(uint16_t conn_handle, unsigned int passkey)
|
||||
|
||||
memcpy(ev.address, addr->val, sizeof(ev.address));
|
||||
ev.address_type = addr->type;
|
||||
ev.passkey = sys_cpu_to_le32(pk.passkey);
|
||||
ev.passkey = htole32(pk.passkey);
|
||||
|
||||
tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_PASSKEY_DISPLAY,
|
||||
(uint8_t *) &ev, sizeof(ev));
|
||||
@@ -959,7 +976,7 @@ auth_passkey_numcmp(uint16_t conn_handle, unsigned int passkey)
|
||||
|
||||
memcpy(ev.address, addr->val, sizeof(ev.address));
|
||||
ev.address_type = addr->type;
|
||||
ev.passkey = sys_cpu_to_le32(passkey);
|
||||
ev.passkey = htole32(passkey);
|
||||
|
||||
tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_PASSKEY_CONFIRM_REQ,
|
||||
(uint8_t *) &ev, sizeof(ev));
|
||||
@@ -1206,7 +1223,7 @@ adv_complete(void)
|
||||
struct btp_gap_new_settings_ev ev;
|
||||
|
||||
current_settings &= ~BIT(BTP_GAP_SETTINGS_ADVERTISING);
|
||||
ev.current_settings = sys_cpu_to_le32(current_settings);
|
||||
ev.current_settings = htole32(current_settings);
|
||||
|
||||
tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_NEW_SETTINGS,
|
||||
(uint8_t *) &ev, sizeof(ev));
|
||||
@@ -1525,7 +1542,7 @@ passkey_entry(const void *cmd, uint16_t cmd_len,
|
||||
}
|
||||
|
||||
pk.action = BLE_SM_IOACT_INPUT;
|
||||
pk.passkey = sys_le32_to_cpu(cp->passkey);
|
||||
pk.passkey = le32toh(cp->passkey);
|
||||
|
||||
rc = ble_sm_inject_io(desc.conn_handle, &pk);
|
||||
if (rc) {
|
||||
@@ -1587,7 +1604,7 @@ start_direct_adv(const void *cmd, uint16_t cmd_len,
|
||||
}
|
||||
|
||||
current_settings |= BIT(BTP_GAP_SETTINGS_ADVERTISING);
|
||||
rp->current_settings = sys_cpu_to_le32(current_settings);
|
||||
rp->current_settings = htole32(current_settings);
|
||||
|
||||
*rsp_len = sizeof(*rp);
|
||||
|
||||
@@ -1920,7 +1937,8 @@ tester_init_gap(void)
|
||||
os_callout_init(&bttester_nrpa_rotate_timer, os_eventq_dflt_get(),
|
||||
rotate_nrpa_cb, NULL);
|
||||
#endif
|
||||
adv_buf = NET_BUF_SIMPLE(ADV_BUF_LEN);
|
||||
adv_buf = os_msys_get(ADV_BUF_LEN, 0);
|
||||
assert(adv_buf);
|
||||
|
||||
tester_init_gap_cb();
|
||||
|
||||
|
||||
@@ -260,11 +260,13 @@ attr_value_changed_ev(uint16_t handle, struct os_mbuf *data)
|
||||
|
||||
SYS_LOG_DBG("");
|
||||
|
||||
net_buf_simple_init(buf, 0);
|
||||
ev = net_buf_simple_add(buf, sizeof(*ev));
|
||||
ev = os_mbuf_extend(buf, sizeof(*ev));
|
||||
if (!ev) {
|
||||
return;
|
||||
}
|
||||
|
||||
ev->handle = sys_cpu_to_le16(handle);
|
||||
ev->data_length = sys_cpu_to_le16(os_mbuf_len(data));
|
||||
ev->handle = htole16(handle);
|
||||
ev->data_length = htole16(os_mbuf_len(data));
|
||||
os_mbuf_appendfrom(buf, data, 0, os_mbuf_len(data));
|
||||
|
||||
tester_send_buf(BTP_SERVICE_ID_GATT, BTP_GATT_EV_ATTR_VALUE_CHANGED,
|
||||
@@ -598,7 +600,7 @@ btp2bt_uuid(const uint8_t *uuid, uint8_t len,
|
||||
case 0x02: /* UUID 16 */
|
||||
bt_uuid->u.type = BLE_UUID_TYPE_16;
|
||||
memcpy(&le16, uuid, sizeof(le16));
|
||||
BLE_UUID16(bt_uuid)->value = sys_le16_to_cpu(le16);
|
||||
BLE_UUID16(bt_uuid)->value = le16toh(le16);
|
||||
break;
|
||||
case 0x10: /* UUID 128*/
|
||||
bt_uuid->u.type = BLE_UUID_TYPE_128;
|
||||
@@ -721,7 +723,7 @@ read(uint8_t *data, uint16_t len)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (ble_gattc_read(conn.conn_handle, sys_le16_to_cpu(cmd->handle),
|
||||
if (ble_gattc_read(conn.conn_handle, le16toh(cmd->handle),
|
||||
read_cb, (void *) BTP_GATT_READ)) {
|
||||
read_destroy();
|
||||
goto fail;
|
||||
@@ -793,8 +795,8 @@ read_long(uint8_t *data, uint16_t len)
|
||||
}
|
||||
|
||||
if (ble_gattc_read_long(conn.conn_handle,
|
||||
sys_le16_to_cpu(cmd->handle),
|
||||
sys_le16_to_cpu(cmd->offset),
|
||||
le16toh(cmd->handle),
|
||||
le16toh(cmd->offset),
|
||||
read_long_cb, (void *) BTP_GATT_READ_LONG)) {
|
||||
read_destroy();
|
||||
goto fail;
|
||||
@@ -817,7 +819,7 @@ read_multiple(uint8_t *data, uint16_t len)
|
||||
SYS_LOG_DBG("");
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(handles); i++) {
|
||||
handles[i] = sys_le16_to_cpu(cmd->handles[i]);
|
||||
handles[i] = le16toh(cmd->handles[i]);
|
||||
}
|
||||
|
||||
rc = ble_gap_conn_find_by_addr((ble_addr_t *) data, &conn);
|
||||
@@ -862,8 +864,8 @@ write_without_rsp(uint8_t *data, uint16_t len, uint8_t op, bool sign)
|
||||
}
|
||||
|
||||
if (ble_gattc_write_no_rsp_flat(conn.conn_handle,
|
||||
sys_le16_to_cpu(cmd->handle), cmd->data,
|
||||
sys_le16_to_cpu(cmd->data_length))) {
|
||||
le16toh(cmd->handle), cmd->data,
|
||||
le16toh(cmd->data_length))) {
|
||||
status = BTP_STATUS_FAILED;
|
||||
}
|
||||
|
||||
@@ -900,8 +902,8 @@ write(uint8_t *data, uint16_t len)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (ble_gattc_write_flat(conn.conn_handle, sys_le16_to_cpu(cmd->handle),
|
||||
cmd->data, sys_le16_to_cpu(cmd->data_length),
|
||||
if (ble_gattc_write_flat(conn.conn_handle, le16toh(cmd->handle),
|
||||
cmd->data, le16toh(cmd->data_length),
|
||||
write_rsp, (void *) BTP_GATT_WRITE)) {
|
||||
goto fail;
|
||||
}
|
||||
@@ -927,15 +929,15 @@ write_long(uint8_t *data, uint16_t len)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
om = ble_hs_mbuf_from_flat(cmd->data, sys_le16_to_cpu(cmd->data_length));
|
||||
om = ble_hs_mbuf_from_flat(cmd->data, le16toh(cmd->data_length));
|
||||
if (!om) {
|
||||
SYS_LOG_ERR("Insufficient resources");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
rc = ble_gattc_write_long(conn.conn_handle,
|
||||
sys_le16_to_cpu(cmd->handle),
|
||||
sys_le16_to_cpu(cmd->offset),
|
||||
le16toh(cmd->handle),
|
||||
le16toh(cmd->offset),
|
||||
om, write_rsp,
|
||||
(void *) BTP_GATT_WRITE_LONG);
|
||||
if (!rc) {
|
||||
@@ -980,16 +982,16 @@ reliable_write(uint8_t *data, uint16_t len)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
om = ble_hs_mbuf_from_flat(cmd->data, sys_le16_to_cpu(cmd->data_length));
|
||||
om = ble_hs_mbuf_from_flat(cmd->data, le16toh(cmd->data_length));
|
||||
/* This is required, because Nimble checks if
|
||||
* the data is longer than offset
|
||||
*/
|
||||
if (os_mbuf_extend(om, sys_le16_to_cpu(cmd->offset) + 1) == NULL) {
|
||||
if (os_mbuf_extend(om, le16toh(cmd->offset) + 1) == NULL) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
attr.handle = sys_le16_to_cpu(cmd->handle);
|
||||
attr.offset = sys_le16_to_cpu(cmd->offset);
|
||||
attr.handle = le16toh(cmd->handle);
|
||||
attr.offset = le16toh(cmd->offset);
|
||||
attr.om = om;
|
||||
|
||||
if (ble_gattc_write_reliable(conn.conn_handle, &attr, 1,
|
||||
@@ -1038,8 +1040,8 @@ read_uuid(uint8_t *data, uint16_t len)
|
||||
}
|
||||
|
||||
if (ble_gattc_read_by_uuid(conn.conn_handle,
|
||||
sys_le16_to_cpu(cmd->start_handle),
|
||||
sys_le16_to_cpu(cmd->end_handle), &uuid.u,
|
||||
le16toh(cmd->start_handle),
|
||||
le16toh(cmd->end_handle), &uuid.u,
|
||||
read_long_cb, (void *) BTP_GATT_READ_UUID)) {
|
||||
read_destroy();
|
||||
goto fail;
|
||||
@@ -1088,12 +1090,12 @@ disc_prim_uuid_cb(uint16_t conn_handle,
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
service->start_handle = sys_cpu_to_le16(gatt_svc->start_handle);
|
||||
service->end_handle = sys_cpu_to_le16(gatt_svc->end_handle);
|
||||
service->start_handle = htole16(gatt_svc->start_handle);
|
||||
service->end_handle = htole16(gatt_svc->end_handle);
|
||||
service->uuid_length = uuid_length;
|
||||
|
||||
if (uuid->u.type == BLE_UUID_TYPE_16) {
|
||||
uint16_t u16 = sys_cpu_to_le16(BLE_UUID16(uuid)->value);
|
||||
uint16_t u16 = htole16(BLE_UUID16(uuid)->value);
|
||||
memcpy(service->uuid, &u16, uuid_length);
|
||||
} else {
|
||||
memcpy(service->uuid, BLE_UUID128(uuid)->value,
|
||||
@@ -1144,11 +1146,11 @@ disc_all_desc_cb(uint16_t conn_handle,
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
dsc->descriptor_handle = sys_cpu_to_le16(gatt_dsc->handle);
|
||||
dsc->descriptor_handle = htole16(gatt_dsc->handle);
|
||||
dsc->uuid_length = uuid_length;
|
||||
|
||||
if (uuid->u.type == BLE_UUID_TYPE_16) {
|
||||
uint16_t u16 = sys_cpu_to_le16(BLE_UUID16(uuid)->value);
|
||||
uint16_t u16 = htole16(BLE_UUID16(uuid)->value);
|
||||
memcpy(dsc->uuid, &u16, uuid_length);
|
||||
} else {
|
||||
memcpy(dsc->uuid, BLE_UUID128(uuid)->value, uuid_length);
|
||||
@@ -1208,8 +1210,8 @@ disc_all_desc(uint8_t *data, uint16_t len)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
start_handle = sys_le16_to_cpu(cmd->start_handle) - 1;
|
||||
end_handle = sys_le16_to_cpu(cmd->end_handle);
|
||||
start_handle = le16toh(cmd->start_handle) - 1;
|
||||
end_handle = le16toh(cmd->end_handle);
|
||||
|
||||
rc = ble_gattc_disc_all_dscs(conn.conn_handle, start_handle, end_handle,
|
||||
disc_all_desc_cb, NULL);
|
||||
@@ -1266,14 +1268,14 @@ find_included_cb(uint16_t conn_handle,
|
||||
}
|
||||
|
||||
/* FIXME */
|
||||
included->included_handle = sys_cpu_to_le16(service_handle + 1 +
|
||||
included->included_handle = htole16(service_handle + 1 +
|
||||
rp->services_count);
|
||||
included->service.start_handle = sys_cpu_to_le16(gatt_svc->start_handle);
|
||||
included->service.end_handle = sys_cpu_to_le16(gatt_svc->end_handle);
|
||||
included->service.start_handle = htole16(gatt_svc->start_handle);
|
||||
included->service.end_handle = htole16(gatt_svc->end_handle);
|
||||
included->service.uuid_length = uuid_length;
|
||||
|
||||
if (uuid->u.type == BLE_UUID_TYPE_16) {
|
||||
uint16_t u16 = sys_cpu_to_le16(BLE_UUID16(uuid)->value);
|
||||
uint16_t u16 = htole16(BLE_UUID16(uuid)->value);
|
||||
memcpy(included->service.uuid, &u16, uuid_length);
|
||||
} else {
|
||||
memcpy(included->service.uuid, BLE_UUID128(uuid)->value,
|
||||
@@ -1323,13 +1325,13 @@ disc_chrc_cb(uint16_t conn_handle,
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
chrc->characteristic_handle = sys_cpu_to_le16(gatt_chr->def_handle);
|
||||
chrc->characteristic_handle = htole16(gatt_chr->def_handle);
|
||||
chrc->properties = gatt_chr->properties;
|
||||
chrc->value_handle = sys_cpu_to_le16(gatt_chr->val_handle);
|
||||
chrc->value_handle = htole16(gatt_chr->val_handle);
|
||||
chrc->uuid_length = uuid_length;
|
||||
|
||||
if (uuid->u.type == BLE_UUID_TYPE_16) {
|
||||
uint16_t u16 = sys_cpu_to_le16(BLE_UUID16(uuid)->value);
|
||||
uint16_t u16 = htole16(BLE_UUID16(uuid)->value);
|
||||
memcpy(chrc->uuid, &u16, uuid_length);
|
||||
} else {
|
||||
memcpy(chrc->uuid, BLE_UUID128(uuid)->value,
|
||||
@@ -1365,8 +1367,8 @@ disc_chrc_uuid(uint8_t *data, uint16_t len)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
start_handle = sys_le16_to_cpu(cmd->start_handle);
|
||||
end_handle = sys_le16_to_cpu(cmd->end_handle);
|
||||
start_handle = le16toh(cmd->start_handle);
|
||||
end_handle = le16toh(cmd->end_handle);
|
||||
|
||||
if (ble_gattc_disc_chrs_by_uuid(conn.conn_handle, start_handle,
|
||||
end_handle, &uuid.u, disc_chrc_cb,
|
||||
@@ -1440,8 +1442,8 @@ disc_all_chrc(uint8_t *data, uint16_t len)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
start_handle = sys_le16_to_cpu(cmd->start_handle);
|
||||
end_handle = sys_le16_to_cpu(cmd->end_handle);
|
||||
start_handle = le16toh(cmd->start_handle);
|
||||
end_handle = le16toh(cmd->end_handle);
|
||||
|
||||
rc = ble_gattc_disc_all_chrs(conn.conn_handle, start_handle, end_handle,
|
||||
disc_chrc_cb, (void *) BTP_GATT_DISC_ALL_CHRC);
|
||||
@@ -1476,8 +1478,8 @@ find_included(uint8_t *data, uint16_t len)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
start_handle = sys_le16_to_cpu(cmd->start_handle);
|
||||
end_handle = sys_le16_to_cpu(cmd->end_handle);
|
||||
start_handle = le16toh(cmd->start_handle);
|
||||
end_handle = le16toh(cmd->end_handle);
|
||||
service_handle_arg = start_handle;
|
||||
|
||||
if (ble_gattc_find_inc_svcs(conn.conn_handle, start_handle, end_handle,
|
||||
@@ -1583,7 +1585,7 @@ config_subscription(uint8_t *data, uint16_t len, uint8_t op)
|
||||
{
|
||||
const struct btp_gatt_cfg_notify_cmd *cmd = (void *) data;
|
||||
struct ble_gap_conn_desc conn;
|
||||
uint16_t ccc_handle = sys_le16_to_cpu(cmd->ccc_handle);
|
||||
uint16_t ccc_handle = le16toh(cmd->ccc_handle);
|
||||
uint8_t status;
|
||||
int rc;
|
||||
|
||||
@@ -1677,8 +1679,8 @@ get_attrs(uint8_t *data, uint16_t len)
|
||||
|
||||
memset(str, 0, sizeof(str));
|
||||
memset(&uuid, 0, sizeof(uuid));
|
||||
start_handle = sys_le16_to_cpu(cmd->start_handle);
|
||||
end_handle = sys_le16_to_cpu(cmd->end_handle);
|
||||
start_handle = le16toh(cmd->start_handle);
|
||||
end_handle = le16toh(cmd->end_handle);
|
||||
|
||||
if (cmd->type_length) {
|
||||
if (btp2bt_uuid(cmd->type, cmd->type_length, &uuid)) {
|
||||
@@ -1694,8 +1696,10 @@ get_attrs(uint8_t *data, uint16_t len)
|
||||
SYS_LOG_DBG("start 0x%04x end 0x%04x", start_handle, end_handle);
|
||||
}
|
||||
|
||||
net_buf_simple_init(buf, 0);
|
||||
rp = net_buf_simple_add(buf, sizeof(*rp));
|
||||
rp = os_mbuf_extend(buf, sizeof(*rp));
|
||||
if (!rp) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
entry = ble_att_svr_find_by_uuid(entry, uuid_ptr, end_handle);
|
||||
while (entry) {
|
||||
@@ -1706,19 +1710,23 @@ get_attrs(uint8_t *data, uint16_t len)
|
||||
continue;
|
||||
}
|
||||
|
||||
gatt_attr = net_buf_simple_add(buf, sizeof(*gatt_attr));
|
||||
gatt_attr->handle = sys_cpu_to_le16(entry->ha_handle_id);
|
||||
gatt_attr = os_mbuf_extend(buf, sizeof(*gatt_attr));
|
||||
if (!gatt_attr) {
|
||||
goto fail;
|
||||
}
|
||||
gatt_attr->handle = htole16(entry->ha_handle_id);
|
||||
gatt_attr->permission = flags_hs2btp(entry->ha_flags);
|
||||
|
||||
if (entry->ha_uuid->type == BLE_UUID_TYPE_16) {
|
||||
uint16_t uuid_val;
|
||||
|
||||
gatt_attr->type_length = 2;
|
||||
net_buf_simple_add_le16(buf,
|
||||
BLE_UUID16(entry->ha_uuid)->value);
|
||||
uuid_val = htole16(BLE_UUID16(entry->ha_uuid)->value);
|
||||
os_mbuf_append(buf, &uuid_val, sizeof(uuid_val));
|
||||
} else {
|
||||
gatt_attr->type_length = 16;
|
||||
net_buf_simple_add_mem(buf,
|
||||
BLE_UUID128(entry->ha_uuid)->value,
|
||||
gatt_attr->type_length);
|
||||
os_mbuf_append(buf, BLE_UUID128(entry->ha_uuid)->value,
|
||||
gatt_attr->type_length);
|
||||
}
|
||||
|
||||
count++;
|
||||
@@ -1746,15 +1754,17 @@ get_attr_val(uint8_t *data, uint16_t len)
|
||||
struct btp_gatt_get_attribute_value_rp *rp;
|
||||
struct ble_gap_conn_desc conn;
|
||||
struct os_mbuf *buf = os_msys_get(0, 0);
|
||||
uint16_t handle = sys_cpu_to_le16(cmd->handle);
|
||||
uint16_t handle = le16toh(cmd->handle);
|
||||
uint8_t out_att_err = 0;
|
||||
int conn_status;
|
||||
|
||||
conn_status = ble_gap_conn_find_by_addr((ble_addr_t *) data, &conn);
|
||||
|
||||
if (conn_status) {
|
||||
net_buf_simple_init(buf, 0);
|
||||
rp = net_buf_simple_add(buf, sizeof(*rp));
|
||||
rp = os_mbuf_extend(buf, sizeof(*rp));
|
||||
if (!rp) {
|
||||
goto free;
|
||||
}
|
||||
|
||||
ble_att_svr_read_handle(BLE_HS_CONN_HANDLE_NONE,
|
||||
handle, 0, buf,
|
||||
@@ -1768,8 +1778,10 @@ get_attr_val(uint8_t *data, uint16_t len)
|
||||
|
||||
goto free;
|
||||
} else {
|
||||
net_buf_simple_init(buf, 0);
|
||||
rp = net_buf_simple_add(buf, sizeof(*rp));
|
||||
rp = os_mbuf_extend(buf, sizeof(*rp));
|
||||
if (!rp) {
|
||||
goto free;
|
||||
}
|
||||
|
||||
ble_att_svr_read_handle(conn.conn_handle,
|
||||
handle, 0, buf,
|
||||
@@ -1951,16 +1963,17 @@ tester_gatt_notify_rx_ev(uint16_t conn_handle, uint16_t attr_handle,
|
||||
goto fail;
|
||||
}
|
||||
|
||||
net_buf_simple_init(buf, 0);
|
||||
ev = net_buf_simple_add(buf, sizeof(*ev));
|
||||
ev = os_mbuf_extend(buf, sizeof(*ev));
|
||||
if (!ev) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
addr = &conn.peer_ota_addr;
|
||||
|
||||
ev->address_type = addr->type;
|
||||
memcpy(ev->address, addr->val, sizeof(ev->address));
|
||||
memcpy(&ev->address, addr, sizeof(ev->address));
|
||||
ev->type = (uint8_t) (indication ? 0x02 : 0x01);
|
||||
ev->handle = sys_cpu_to_le16(attr_handle);
|
||||
ev->data_length = sys_cpu_to_le16(os_mbuf_len(om));
|
||||
ev->handle = htole16(attr_handle);
|
||||
ev->data_length = htole16(os_mbuf_len(om));
|
||||
os_mbuf_appendfrom(buf, om, 0, os_mbuf_len(om));
|
||||
|
||||
tester_send_buf(BTP_SERVICE_ID_GATT, BTP_GATT_EV_NOTIFICATION,
|
||||
|
||||
+100
-66
@@ -44,7 +44,7 @@ btp2bt_uuid(const uint8_t *uuid, uint8_t len,
|
||||
case 0x02: /* UUID 16 */
|
||||
bt_uuid->u.type = BLE_UUID_TYPE_16;
|
||||
memcpy(&le16, uuid, sizeof(le16));
|
||||
BLE_UUID16(bt_uuid)->value = sys_le16_to_cpu(le16);
|
||||
BLE_UUID16(bt_uuid)->value = le16toh(le16);
|
||||
break;
|
||||
case 0x10: /* UUID 128*/
|
||||
bt_uuid->u.type = BLE_UUID_TYPE_128;
|
||||
@@ -134,8 +134,10 @@ tester_mtu_exchanged_ev(uint16_t conn_handle,
|
||||
goto fail;
|
||||
}
|
||||
|
||||
net_buf_simple_init(buf, 0);
|
||||
ev = net_buf_simple_add(buf, sizeof(*ev));
|
||||
ev = os_mbuf_extend(buf, sizeof(*ev));
|
||||
if (!ev) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
addr = &conn.peer_ota_addr;
|
||||
|
||||
@@ -200,8 +202,11 @@ disc_prim_svcs_cb(uint16_t conn_handle,
|
||||
goto free;
|
||||
}
|
||||
|
||||
net_buf_simple_init(buf, 0);
|
||||
rp = net_buf_simple_add(buf, sizeof(*rp));
|
||||
rp = os_mbuf_extend(buf, sizeof(*rp));
|
||||
if (!rp) {
|
||||
rc = BLE_HS_ENOMEM;
|
||||
goto free;
|
||||
}
|
||||
|
||||
addr = &conn.peer_ota_addr;
|
||||
|
||||
@@ -237,12 +242,12 @@ disc_prim_svcs_cb(uint16_t conn_handle,
|
||||
goto free;
|
||||
}
|
||||
|
||||
service->start_handle = sys_cpu_to_le16(gatt_svc->start_handle);
|
||||
service->end_handle = sys_cpu_to_le16(gatt_svc->end_handle);
|
||||
service->start_handle = htole16(gatt_svc->start_handle);
|
||||
service->end_handle = htole16(gatt_svc->end_handle);
|
||||
service->uuid_length = uuid_length;
|
||||
|
||||
if (uuid->u.type == BLE_UUID_TYPE_16) {
|
||||
uint16_t u16 = sys_cpu_to_le16(BLE_UUID16(uuid)->value);
|
||||
uint16_t u16 = htole16(BLE_UUID16(uuid)->value);
|
||||
memcpy(service->uuid, &u16, uuid_length);
|
||||
} else {
|
||||
memcpy(service->uuid, BLE_UUID128(uuid)->value,
|
||||
@@ -340,8 +345,11 @@ find_included_cb(uint16_t conn_handle,
|
||||
goto free;
|
||||
}
|
||||
|
||||
net_buf_simple_init(buf, 0);
|
||||
rp = net_buf_simple_add(buf, sizeof(*rp));
|
||||
rp = os_mbuf_extend(buf, sizeof(*rp));
|
||||
if (!rp) {
|
||||
rc = BLE_HS_ENOMEM;
|
||||
goto free;
|
||||
}
|
||||
|
||||
addr = &conn.peer_ota_addr;
|
||||
|
||||
@@ -379,14 +387,14 @@ find_included_cb(uint16_t conn_handle,
|
||||
goto free;
|
||||
}
|
||||
|
||||
included->included_handle = sys_cpu_to_le16(service_handle + 1 +
|
||||
included->included_handle = htole16(service_handle + 1 +
|
||||
rp->services_count);
|
||||
included->service.start_handle = sys_cpu_to_le16(gatt_svc->start_handle);
|
||||
included->service.end_handle = sys_cpu_to_le16(gatt_svc->end_handle);
|
||||
included->service.start_handle = htole16(gatt_svc->start_handle);
|
||||
included->service.end_handle = htole16(gatt_svc->end_handle);
|
||||
included->service.uuid_length = uuid_length;
|
||||
|
||||
if (uuid->u.type == BLE_UUID_TYPE_16) {
|
||||
uint16_t u16 = sys_cpu_to_le16(BLE_UUID16(uuid)->value);
|
||||
uint16_t u16 = htole16(BLE_UUID16(uuid)->value);
|
||||
memcpy(included->service.uuid, &u16, uuid_length);
|
||||
} else {
|
||||
memcpy(included->service.uuid, BLE_UUID128(uuid)->value,
|
||||
@@ -418,8 +426,8 @@ find_included(uint8_t *data, uint16_t len)
|
||||
goto rsp;
|
||||
}
|
||||
|
||||
start_handle = sys_le16_to_cpu(cmd->start_handle);
|
||||
end_handle = sys_le16_to_cpu(cmd->end_handle);
|
||||
start_handle = le16toh(cmd->start_handle);
|
||||
end_handle = le16toh(cmd->end_handle);
|
||||
service_handle_arg = start_handle;
|
||||
|
||||
if (ble_gattc_find_inc_svcs(conn.conn_handle, start_handle, end_handle,
|
||||
@@ -455,8 +463,11 @@ disc_chrc_cb(uint16_t conn_handle,
|
||||
goto free;
|
||||
}
|
||||
|
||||
net_buf_simple_init(buf, 0);
|
||||
rp = net_buf_simple_add(buf, sizeof(*rp));
|
||||
rp = os_mbuf_extend(buf, sizeof(*rp));
|
||||
if (!rp) {
|
||||
rc = BLE_HS_ENOMEM;
|
||||
goto free;
|
||||
}
|
||||
|
||||
addr = &conn.peer_ota_addr;
|
||||
|
||||
@@ -498,13 +509,13 @@ disc_chrc_cb(uint16_t conn_handle,
|
||||
goto free;
|
||||
}
|
||||
|
||||
chrc->characteristic_handle = sys_cpu_to_le16(gatt_chr->def_handle);
|
||||
chrc->characteristic_handle = htole16(gatt_chr->def_handle);
|
||||
chrc->properties = gatt_chr->properties;
|
||||
chrc->value_handle = sys_cpu_to_le16(gatt_chr->val_handle);
|
||||
chrc->value_handle = htole16(gatt_chr->val_handle);
|
||||
chrc->uuid_length = uuid_length;
|
||||
|
||||
if (uuid->u.type == BLE_UUID_TYPE_16) {
|
||||
uint16_t u16 = sys_cpu_to_le16(BLE_UUID16(uuid)->value);
|
||||
uint16_t u16 = htole16(BLE_UUID16(uuid)->value);
|
||||
memcpy(chrc->uuid, &u16, uuid_length);
|
||||
} else {
|
||||
memcpy(chrc->uuid, BLE_UUID128(uuid)->value,
|
||||
@@ -535,8 +546,8 @@ disc_all_chrc(uint8_t *data, uint16_t len)
|
||||
goto rsp;
|
||||
}
|
||||
|
||||
start_handle = sys_le16_to_cpu(cmd->start_handle);
|
||||
end_handle = sys_le16_to_cpu(cmd->end_handle);
|
||||
start_handle = le16toh(cmd->start_handle);
|
||||
end_handle = le16toh(cmd->end_handle);
|
||||
|
||||
rc = ble_gattc_disc_all_chrs(conn.conn_handle,
|
||||
start_handle,
|
||||
@@ -576,8 +587,8 @@ disc_chrc_uuid(uint8_t *data, uint16_t len)
|
||||
goto rsp;
|
||||
}
|
||||
|
||||
start_handle = sys_le16_to_cpu(cmd->start_handle);
|
||||
end_handle = sys_le16_to_cpu(cmd->end_handle);
|
||||
start_handle = le16toh(cmd->start_handle);
|
||||
end_handle = le16toh(cmd->end_handle);
|
||||
|
||||
rc = ble_gattc_disc_chrs_by_uuid(conn.conn_handle, start_handle,
|
||||
end_handle, &uuid.u, disc_chrc_cb,
|
||||
@@ -616,8 +627,11 @@ disc_all_desc_cb(uint16_t conn_handle,
|
||||
goto free;
|
||||
}
|
||||
|
||||
net_buf_simple_init(buf, 0);
|
||||
rp = net_buf_simple_add(buf, sizeof(*rp));
|
||||
rp = os_mbuf_extend(buf, sizeof(*rp));
|
||||
if (!rp) {
|
||||
rc = BLE_HS_ENOMEM;
|
||||
goto free;
|
||||
}
|
||||
|
||||
addr = &conn.peer_ota_addr;
|
||||
|
||||
@@ -654,11 +668,11 @@ disc_all_desc_cb(uint16_t conn_handle,
|
||||
goto free;
|
||||
}
|
||||
|
||||
dsc->descriptor_handle = sys_cpu_to_le16(gatt_dsc->handle);
|
||||
dsc->descriptor_handle = htole16(gatt_dsc->handle);
|
||||
dsc->uuid_length = uuid_length;
|
||||
|
||||
if (uuid->u.type == BLE_UUID_TYPE_16) {
|
||||
uint16_t u16 = sys_cpu_to_le16(BLE_UUID16(uuid)->value);
|
||||
uint16_t u16 = htole16(BLE_UUID16(uuid)->value);
|
||||
memcpy(dsc->uuid, &u16, uuid_length);
|
||||
} else {
|
||||
memcpy(dsc->uuid, BLE_UUID128(uuid)->value, uuid_length);
|
||||
@@ -688,8 +702,8 @@ disc_all_desc(uint8_t *data, uint16_t len)
|
||||
goto rsp;
|
||||
}
|
||||
|
||||
start_handle = sys_le16_to_cpu(cmd->start_handle) - 1;
|
||||
end_handle = sys_le16_to_cpu(cmd->end_handle);
|
||||
start_handle = le16toh(cmd->start_handle) - 1;
|
||||
end_handle = le16toh(cmd->end_handle);
|
||||
|
||||
rc = ble_gattc_disc_all_dscs(conn.conn_handle,
|
||||
start_handle,
|
||||
@@ -727,8 +741,11 @@ read_cb(uint16_t conn_handle,
|
||||
goto free;
|
||||
}
|
||||
|
||||
net_buf_simple_init(buf, 0);
|
||||
rp = net_buf_simple_add(buf, sizeof(*rp));
|
||||
rp = os_mbuf_extend(buf, sizeof(*rp));
|
||||
if (!rp) {
|
||||
rc = BLE_HS_ENOMEM;
|
||||
goto free;
|
||||
}
|
||||
|
||||
addr = &conn.peer_ota_addr;
|
||||
|
||||
@@ -782,7 +799,7 @@ read(uint8_t *data, uint16_t len)
|
||||
/* Clear buffer */
|
||||
read_destroy();
|
||||
|
||||
if (ble_gattc_read(conn.conn_handle, sys_le16_to_cpu(cmd->handle),
|
||||
if (ble_gattc_read(conn.conn_handle, le16toh(cmd->handle),
|
||||
read_cb, (void *) BTP_GATTC_READ_RP)) {
|
||||
read_destroy();
|
||||
status = BTP_STATUS_FAILED;
|
||||
@@ -816,8 +833,11 @@ read_uuid_cb(uint16_t conn_handle,
|
||||
goto free;
|
||||
}
|
||||
|
||||
net_buf_simple_init(buf, 0);
|
||||
rp = net_buf_simple_add(buf, sizeof(*rp));
|
||||
rp = os_mbuf_extend(buf, sizeof(*rp));
|
||||
if (!rp) {
|
||||
rc = BLE_HS_ENOMEM;
|
||||
goto free;
|
||||
}
|
||||
|
||||
addr = &conn.peer_ota_addr;
|
||||
|
||||
@@ -857,7 +877,7 @@ read_uuid_cb(uint16_t conn_handle,
|
||||
goto free;
|
||||
}
|
||||
|
||||
chr->handle = sys_cpu_to_be16(attr->handle);
|
||||
chr->handle = htobe16(attr->handle);
|
||||
memcpy(chr->data, attr->om->om_data, attr->om->om_len);
|
||||
|
||||
free:
|
||||
@@ -891,8 +911,8 @@ read_uuid(uint8_t *data, uint16_t len)
|
||||
read_destroy();
|
||||
|
||||
if (ble_gattc_read_by_uuid(conn.conn_handle,
|
||||
sys_le16_to_cpu(cmd->start_handle),
|
||||
sys_le16_to_cpu(cmd->end_handle), &uuid.u,
|
||||
le16toh(cmd->start_handle),
|
||||
le16toh(cmd->end_handle), &uuid.u,
|
||||
read_uuid_cb, (void *) BTP_GATTC_READ_UUID_RP)) {
|
||||
read_destroy();
|
||||
status = BTP_STATUS_FAILED;
|
||||
@@ -923,8 +943,11 @@ read_long_cb(uint16_t conn_handle,
|
||||
goto free;
|
||||
}
|
||||
|
||||
net_buf_simple_init(buf, 0);
|
||||
rp = net_buf_simple_add(buf, sizeof(*rp));
|
||||
rp = os_mbuf_extend(buf, sizeof(*rp));
|
||||
if (!rp) {
|
||||
rc = BLE_HS_ENOMEM;
|
||||
goto free;
|
||||
}
|
||||
|
||||
addr = &conn.peer_ota_addr;
|
||||
|
||||
@@ -984,8 +1007,8 @@ read_long(uint8_t *data, uint16_t len)
|
||||
read_destroy();
|
||||
|
||||
if (ble_gattc_read_long(conn.conn_handle,
|
||||
sys_le16_to_cpu(cmd->handle),
|
||||
sys_le16_to_cpu(cmd->offset),
|
||||
le16toh(cmd->handle),
|
||||
le16toh(cmd->offset),
|
||||
read_long_cb, (void *) BTP_GATTC_READ_LONG_RP)) {
|
||||
read_destroy();
|
||||
status = BTP_STATUS_FAILED;
|
||||
@@ -1007,7 +1030,7 @@ read_multiple(uint8_t *data, uint16_t len)
|
||||
SYS_LOG_DBG("");
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(handles); i++) {
|
||||
handles[i] = sys_le16_to_cpu(cmd->handles[i]);
|
||||
handles[i] = le16toh(cmd->handles[i]);
|
||||
}
|
||||
|
||||
rc = ble_gap_conn_find_by_addr((ble_addr_t *) data, &conn);
|
||||
@@ -1049,8 +1072,8 @@ write_without_rsp(uint8_t *data, uint16_t len, uint8_t op, bool sign)
|
||||
}
|
||||
|
||||
if (ble_gattc_write_no_rsp_flat(conn.conn_handle,
|
||||
sys_le16_to_cpu(cmd->handle), cmd->data,
|
||||
sys_le16_to_cpu(cmd->data_length))) {
|
||||
le16toh(cmd->handle), cmd->data,
|
||||
le16toh(cmd->data_length))) {
|
||||
status = BTP_STATUS_FAILED;
|
||||
}
|
||||
|
||||
@@ -1078,8 +1101,11 @@ write_cb(uint16_t conn_handle, const struct ble_gatt_error *error,
|
||||
goto free;
|
||||
}
|
||||
|
||||
net_buf_simple_init(buf, 0);
|
||||
rp = net_buf_simple_add(buf, sizeof(*rp));
|
||||
rp = os_mbuf_extend(buf, sizeof(*rp));
|
||||
if (!rp) {
|
||||
rc = BLE_HS_ENOMEM;
|
||||
goto free;
|
||||
}
|
||||
|
||||
addr = &conn.peer_ota_addr;
|
||||
|
||||
@@ -1110,8 +1136,8 @@ write(uint8_t *data, uint16_t len)
|
||||
goto rsp;
|
||||
}
|
||||
|
||||
if (ble_gattc_write_flat(conn.conn_handle, sys_le16_to_cpu(cmd->handle),
|
||||
cmd->data, sys_le16_to_cpu(cmd->data_length),
|
||||
if (ble_gattc_write_flat(conn.conn_handle, le16toh(cmd->handle),
|
||||
cmd->data, le16toh(cmd->data_length),
|
||||
write_cb, (void *) BTP_GATTC_WRITE_RP)) {
|
||||
status = BTP_STATUS_FAILED;
|
||||
}
|
||||
@@ -1136,7 +1162,7 @@ write_long(uint8_t *data, uint16_t len)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
om = ble_hs_mbuf_from_flat(cmd->data, sys_le16_to_cpu(cmd->data_length));
|
||||
om = ble_hs_mbuf_from_flat(cmd->data, le16toh(cmd->data_length));
|
||||
if (!om) {
|
||||
SYS_LOG_ERR("Insufficient resources");
|
||||
status = BTP_STATUS_FAILED;
|
||||
@@ -1144,8 +1170,8 @@ write_long(uint8_t *data, uint16_t len)
|
||||
}
|
||||
|
||||
rc = ble_gattc_write_long(conn.conn_handle,
|
||||
sys_le16_to_cpu(cmd->handle),
|
||||
sys_le16_to_cpu(cmd->offset),
|
||||
le16toh(cmd->handle),
|
||||
le16toh(cmd->offset),
|
||||
om, write_cb,
|
||||
(void *) BTP_GATTC_WRITE_LONG_RP);
|
||||
if (rc) {
|
||||
@@ -1182,8 +1208,11 @@ reliable_write_cb(uint16_t conn_handle,
|
||||
goto free;
|
||||
}
|
||||
|
||||
net_buf_simple_init(buf, 0);
|
||||
rp = net_buf_simple_add(buf, sizeof(*rp));
|
||||
rp = os_mbuf_extend(buf, sizeof(*rp));
|
||||
if (!rp) {
|
||||
rc = BLE_HS_ENOMEM;
|
||||
goto free;
|
||||
}
|
||||
|
||||
addr = &conn.peer_ota_addr;
|
||||
|
||||
@@ -1216,17 +1245,17 @@ reliable_write(uint8_t *data, uint16_t len)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
om = ble_hs_mbuf_from_flat(cmd->data, sys_le16_to_cpu(cmd->data_length));
|
||||
om = ble_hs_mbuf_from_flat(cmd->data, le16toh(cmd->data_length));
|
||||
/* This is required, because Nimble checks if
|
||||
* the data is longer than offset
|
||||
*/
|
||||
if (os_mbuf_extend(om, sys_le16_to_cpu(cmd->offset) + 1) == NULL) {
|
||||
if (os_mbuf_extend(om, le16toh(cmd->offset) + 1) == NULL) {
|
||||
status = BTP_STATUS_FAILED;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
attr.handle = sys_le16_to_cpu(cmd->handle);
|
||||
attr.offset = sys_le16_to_cpu(cmd->offset);
|
||||
attr.handle = le16toh(cmd->handle);
|
||||
attr.offset = le16toh(cmd->offset);
|
||||
attr.om = om;
|
||||
|
||||
if (ble_gattc_write_reliable(conn.conn_handle, &attr, 1,
|
||||
@@ -1264,8 +1293,11 @@ subscribe_cb(uint16_t conn_handle,
|
||||
goto free;
|
||||
}
|
||||
|
||||
net_buf_simple_init(buf, 0);
|
||||
rp = net_buf_simple_add(buf, sizeof(*rp));
|
||||
rp = os_mbuf_extend(buf, sizeof(*rp));
|
||||
if (!rp) {
|
||||
rc = BLE_HS_ENOMEM;
|
||||
goto free;
|
||||
}
|
||||
|
||||
addr = &conn.peer_ota_addr;
|
||||
|
||||
@@ -1340,7 +1372,7 @@ config_subscription(uint8_t *data, uint16_t len, uint8_t op)
|
||||
{
|
||||
const struct btp_gattc_cfg_notify_cmd *cmd = (void *) data;
|
||||
struct ble_gap_conn_desc conn;
|
||||
uint16_t ccc_handle = sys_le16_to_cpu(cmd->ccc_handle);
|
||||
uint16_t ccc_handle = le16toh(cmd->ccc_handle);
|
||||
uint8_t status = BTP_STATUS_SUCCESS;
|
||||
int rc;
|
||||
|
||||
@@ -1399,16 +1431,18 @@ tester_gattc_notify_rx_ev(uint16_t conn_handle, uint16_t attr_handle,
|
||||
goto fail;
|
||||
}
|
||||
|
||||
net_buf_simple_init(buf, 0);
|
||||
ev = net_buf_simple_add(buf, sizeof(*ev));
|
||||
ev = os_mbuf_extend(buf, sizeof(*ev));
|
||||
if (!ev) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
addr = &conn.peer_ota_addr;
|
||||
|
||||
ev->address_type = addr->type;
|
||||
memcpy(ev->address, addr->val, sizeof(ev->address));
|
||||
ev->type = (uint8_t) (indication ? 0x02 : 0x01);
|
||||
ev->handle = sys_cpu_to_le16(attr_handle);
|
||||
ev->data_length = sys_cpu_to_le16(os_mbuf_len(om));
|
||||
ev->handle = htole16(attr_handle);
|
||||
ev->data_length = htole16(os_mbuf_len(om));
|
||||
os_mbuf_appendfrom(buf, om, 0, os_mbuf_len(om));
|
||||
|
||||
tester_send_buf(BTP_SERVICE_ID_GATTC, BTP_GATTC_EV_NOTIFICATION_RXED,
|
||||
|
||||
@@ -421,7 +421,7 @@ connect(uint8_t *data, uint16_t len)
|
||||
|
||||
SYS_LOG_DBG("connect: type: %d addr: %s",
|
||||
addr->type,
|
||||
bt_hex(addr->val, 6));
|
||||
string_from_bytes(addr->val, 6));
|
||||
|
||||
if (mtu == 0 || mtu > TESTER_COC_MTU) {
|
||||
mtu = TESTER_COC_MTU;
|
||||
@@ -523,7 +523,7 @@ send_data(const uint8_t *data, uint16_t len)
|
||||
const struct btp_l2cap_send_data_cmd *cmd = (void *) data;
|
||||
struct os_mbuf *sdu_tx = NULL;
|
||||
int rc;
|
||||
uint16_t data_len = sys_le16_to_cpu(cmd->data_len);
|
||||
uint16_t data_len = le16toh(cmd->data_len);
|
||||
struct channel *chan = get_channel(cmd->chan_id);
|
||||
|
||||
SYS_LOG_DBG("cmd->chan_id=%d", cmd->chan_id);
|
||||
@@ -567,7 +567,7 @@ static void
|
||||
listen(const uint8_t *data, uint16_t len)
|
||||
{
|
||||
const struct btp_l2cap_listen_cmd *cmd = (void *) data;
|
||||
uint16_t mtu = htole16(cmd->mtu);
|
||||
uint16_t mtu = htole16(cmd->mtu);
|
||||
int rc;
|
||||
|
||||
SYS_LOG_DBG("");
|
||||
@@ -625,7 +625,7 @@ static void
|
||||
reconfigure(const uint8_t *data, uint16_t len)
|
||||
{
|
||||
const struct btp_l2cap_reconfigure_cmd *cmd = (void *) data;
|
||||
uint16_t mtu = htole16(cmd->mtu);
|
||||
uint16_t mtu = htole16(cmd->mtu);
|
||||
struct ble_gap_conn_desc desc;
|
||||
ble_addr_t *addr = (void *) data;
|
||||
struct ble_l2cap_chan *chans[cmd->num];
|
||||
|
||||
@@ -318,8 +318,8 @@ output_number(bt_mesh_output_action_t action, uint32_t number)
|
||||
|
||||
SYS_LOG_DBG("action 0x%04x number 0x%08lx", action, number);
|
||||
|
||||
ev.action = sys_cpu_to_le16(action);
|
||||
ev.number = sys_cpu_to_le32(number);
|
||||
ev.action = htole16(action);
|
||||
ev.number = htole32(number);
|
||||
|
||||
tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_EV_OUT_NUMBER_ACTION,
|
||||
(uint8_t *) &ev, sizeof(ev));
|
||||
@@ -358,7 +358,7 @@ input(bt_mesh_input_action_t action, uint8_t size)
|
||||
|
||||
input_size = size;
|
||||
|
||||
ev.action = sys_cpu_to_le16(action);
|
||||
ev.action = htole16(action);
|
||||
ev.size = size;
|
||||
|
||||
tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_EV_IN_ACTION,
|
||||
@@ -441,7 +441,7 @@ provision_node(uint8_t *data, uint16_t len)
|
||||
|
||||
addr = sys_le16_to_cpu(cmd->addr);
|
||||
flags = cmd->flags;
|
||||
iv_index = sys_le32_to_cpu(cmd->iv_index);
|
||||
iv_index = le32toh(cmd->iv_index);
|
||||
net_key_idx = sys_le16_to_cpu(cmd->net_key_idx);
|
||||
|
||||
tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_PROVISION_NODE,
|
||||
@@ -499,7 +499,7 @@ input_number(uint8_t *data, uint16_t len)
|
||||
uint32_t number;
|
||||
int err;
|
||||
|
||||
number = sys_le32_to_cpu(cmd->number);
|
||||
number = le32toh(cmd->number);
|
||||
|
||||
SYS_LOG_DBG("number 0x%04lx", number);
|
||||
|
||||
@@ -896,8 +896,8 @@ net_recv_ev(uint8_t ttl,
|
||||
ev = net_buf_simple_add(buf, sizeof(*ev));
|
||||
ev->ttl = ttl;
|
||||
ev->ctl = ctl;
|
||||
ev->src = sys_cpu_to_le16(src);
|
||||
ev->dst = sys_cpu_to_le16(dst);
|
||||
ev->src = htole16(src);
|
||||
ev->dst = htole16(dst);
|
||||
ev->payload_len = payload_len;
|
||||
net_buf_simple_add_mem(buf, payload, payload_len);
|
||||
|
||||
|
||||
@@ -57,6 +57,14 @@ static struct {
|
||||
uint8_t num;
|
||||
} service_handler[BTP_SERVICE_ID_MAX + 1];
|
||||
|
||||
|
||||
void
|
||||
tester_mbuf_reset(struct os_mbuf *buf)
|
||||
{
|
||||
buf->om_data = &buf->om_databuf[buf->om_pkthdr_len];
|
||||
buf->om_len = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
tester_send_with_index(uint8_t service, uint8_t opcode, uint8_t index,
|
||||
uint8_t *data, size_t len);
|
||||
@@ -69,13 +77,38 @@ tester_register_command_handlers(uint8_t service,
|
||||
const struct btp_handler *handlers,
|
||||
size_t num)
|
||||
{
|
||||
__ASSERT_NO_MSG(service <= BTP_SERVICE_ID_MAX);
|
||||
__ASSERT_NO_MSG(service_handler[service].handlers == NULL);
|
||||
assert(service <= BTP_SERVICE_ID_MAX);
|
||||
assert(service_handler[service].handlers == NULL);
|
||||
|
||||
service_handler[service].handlers = handlers;
|
||||
service_handler[service].num = num;
|
||||
}
|
||||
|
||||
const char *
|
||||
string_from_bytes(const void *buf, size_t len)
|
||||
{
|
||||
static const char hex[] = "0123456789abcdef";
|
||||
static char hexbufs[4][137];
|
||||
static uint8_t curbuf;
|
||||
const uint8_t *b = buf;
|
||||
char *str;
|
||||
int i;
|
||||
|
||||
str = hexbufs[curbuf++];
|
||||
curbuf %= ARRAY_SIZE(hexbufs);
|
||||
|
||||
len = min(len, (sizeof(hexbufs[0]) - 1) / 2);
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
str[i * 2] = hex[b[i] >> 4];
|
||||
str[i * 2 + 1] = hex[b[i] & 0xf];
|
||||
}
|
||||
|
||||
str[i * 2] = '\0';
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
static const struct btp_handler *
|
||||
find_btp_handler(uint8_t service, uint8_t opcode)
|
||||
{
|
||||
@@ -108,12 +141,12 @@ cmd_handler(struct os_event *ev)
|
||||
|
||||
cmd = ev->ev_arg;
|
||||
|
||||
len = sys_le16_to_cpu(cmd->hdr.len);
|
||||
len = le16toh(cmd->hdr.len);
|
||||
if (MYNEWT_VAL(BTTESTER_BTP_LOG)) {
|
||||
console_printf("[DBG] received %d bytes: %s\n",
|
||||
sizeof(cmd->hdr) + len,
|
||||
bt_hex(cmd->data,
|
||||
sizeof(cmd->hdr) + len));
|
||||
string_from_bytes(cmd->data,
|
||||
sizeof(cmd->hdr) + len));
|
||||
}
|
||||
|
||||
btp = find_btp_handler(cmd->hdr.service, cmd->hdr.opcode);
|
||||
@@ -127,7 +160,7 @@ cmd_handler(struct os_event *ev)
|
||||
cmd->rsp, &rsp_len);
|
||||
}
|
||||
|
||||
__ASSERT_NO_MSG((rsp_len + sizeof(struct btp_hdr)) <= BTP_MTU);
|
||||
assert((rsp_len + sizeof(struct btp_hdr)) <= BTP_MTU);
|
||||
} else {
|
||||
status = BTP_STATUS_UNKNOWN_CMD;
|
||||
}
|
||||
@@ -157,7 +190,7 @@ recv_cb(uint8_t *buf, size_t *off)
|
||||
return buf;
|
||||
}
|
||||
|
||||
len = sys_le16_to_cpu(cmd->len);
|
||||
len = le16toh(cmd->len);
|
||||
if (len > BTP_MTU - sizeof(*cmd)) {
|
||||
*off = 0;
|
||||
return buf;
|
||||
@@ -239,7 +272,7 @@ tester_send_with_index(uint8_t service, uint8_t opcode, uint8_t index,
|
||||
msg.service = service;
|
||||
msg.opcode = opcode;
|
||||
msg.index = index;
|
||||
msg.len = sys_cpu_to_le16(len);
|
||||
msg.len = htole16(len);
|
||||
|
||||
bttester_pipe_send((uint8_t *) &msg, sizeof(msg));
|
||||
if (data && len) {
|
||||
@@ -248,10 +281,10 @@ 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),
|
||||
bt_hex((char *) &msg, sizeof(msg)));
|
||||
string_from_bytes((char *) &msg, sizeof(msg)));
|
||||
if (data && len) {
|
||||
console_printf("[DBG] send %d bytes data: %s\n", len,
|
||||
bt_hex((char *) data, len));
|
||||
string_from_bytes((char *) data, len));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,129 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.
|
||||
*/
|
||||
|
||||
#include "syscfg/syscfg.h"
|
||||
|
||||
#if !MYNEWT_VAL(BLE_MESH)
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include "os/os.h"
|
||||
#include "os/os_mbuf.h"
|
||||
#include "glue.h"
|
||||
|
||||
|
||||
#define ASSERT_NOT_CHAIN(om) assert(SLIST_NEXT(om, om_next) == NULL)
|
||||
|
||||
const char *bt_hex(const void *buf, size_t len)
|
||||
{
|
||||
static const char hex[] = "0123456789abcdef";
|
||||
static char hexbufs[4][137];
|
||||
static uint8_t curbuf;
|
||||
const uint8_t *b = buf;
|
||||
char *str;
|
||||
int i;
|
||||
|
||||
str = hexbufs[curbuf++];
|
||||
curbuf %= ARRAY_SIZE(hexbufs);
|
||||
|
||||
len = min(len, (sizeof(hexbufs[0]) - 1) / 2);
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
str[i * 2] = hex[b[i] >> 4];
|
||||
str[i * 2 + 1] = hex[b[i] & 0xf];
|
||||
}
|
||||
|
||||
str[i * 2] = '\0';
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
struct os_mbuf * NET_BUF_SIMPLE(uint16_t size)
|
||||
{
|
||||
struct os_mbuf *buf;
|
||||
|
||||
buf = os_msys_get(size, 0);
|
||||
assert(buf);
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
/* This is by purpose */
|
||||
void net_buf_simple_init(struct os_mbuf *buf,
|
||||
size_t reserve_head)
|
||||
{
|
||||
/* This is called in Zephyr after init.
|
||||
* Note in Mynewt case we don't care abour reserved head*/
|
||||
buf->om_data = &buf->om_databuf[buf->om_pkthdr_len] + reserve_head;
|
||||
buf->om_len = 0;
|
||||
}
|
||||
|
||||
void
|
||||
net_buf_simple_add_le16(struct os_mbuf *om, uint16_t val)
|
||||
{
|
||||
val = htole16(val);
|
||||
os_mbuf_append(om, &val, sizeof(val));
|
||||
ASSERT_NOT_CHAIN(om);
|
||||
}
|
||||
|
||||
void
|
||||
net_buf_simple_add_be16(struct os_mbuf *om, uint16_t val)
|
||||
{
|
||||
val = htobe16(val);
|
||||
os_mbuf_append(om, &val, sizeof(val));
|
||||
ASSERT_NOT_CHAIN(om);
|
||||
}
|
||||
|
||||
void
|
||||
net_buf_simple_add_be32(struct os_mbuf *om, uint32_t val)
|
||||
{
|
||||
val = htobe32(val);
|
||||
os_mbuf_append(om, &val, sizeof(val));
|
||||
ASSERT_NOT_CHAIN(om);
|
||||
}
|
||||
|
||||
void
|
||||
net_buf_simple_add_u8(struct os_mbuf *om, uint8_t val)
|
||||
{
|
||||
os_mbuf_append(om, &val, 1);
|
||||
ASSERT_NOT_CHAIN(om);
|
||||
}
|
||||
|
||||
void*
|
||||
net_buf_simple_add(struct os_mbuf *om, uint8_t len)
|
||||
{
|
||||
void * tmp;
|
||||
|
||||
tmp = os_mbuf_extend(om, len);
|
||||
ASSERT_NOT_CHAIN(om);
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
uint8_t *
|
||||
net_buf_simple_push(struct os_mbuf *om, uint8_t len)
|
||||
{
|
||||
uint8_t headroom = om->om_data - &om->om_databuf[om->om_pkthdr_len];
|
||||
|
||||
assert(headroom >= len);
|
||||
om->om_data -= len;
|
||||
om->om_len += len;
|
||||
|
||||
return om->om_data;
|
||||
}
|
||||
#endif
|
||||
@@ -1,89 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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 __GLUE_H__
|
||||
#define __GLUE_H__
|
||||
|
||||
#include "os/endian.h"
|
||||
|
||||
#define uint8_t uint8_t
|
||||
#define int8_t int8_t
|
||||
#define uint16_t uint16_t
|
||||
#define uint32_t uint32_t
|
||||
#define int32_t int32_t
|
||||
|
||||
#ifndef BIT
|
||||
#define BIT(n) (1UL << (n))
|
||||
#endif
|
||||
|
||||
#define __packed __attribute__((__packed__))
|
||||
|
||||
#define sys_le16_to_cpu le16toh
|
||||
|
||||
struct bt_data {
|
||||
uint8_t type;
|
||||
uint8_t data_len;
|
||||
const uint8_t *data;
|
||||
};
|
||||
|
||||
#define BT_DATA(_type, _data, _data_len) \
|
||||
{ \
|
||||
.type = (_type), \
|
||||
.data_len = (_data_len), \
|
||||
.data = (const uint8_t *)(_data), \
|
||||
}
|
||||
|
||||
struct os_mbuf *
|
||||
NET_BUF_SIMPLE(uint16_t size);
|
||||
void
|
||||
net_buf_simple_init(struct os_mbuf *buf, size_t reserve_head);
|
||||
void
|
||||
net_buf_simple_add_le16(struct os_mbuf *om, uint16_t val);
|
||||
void
|
||||
net_buf_simple_add_u8(struct os_mbuf *om, uint8_t val);
|
||||
void *
|
||||
net_buf_simple_add(struct os_mbuf *om, uint8_t len);
|
||||
uint8_t *
|
||||
net_buf_simple_push(struct os_mbuf *om, uint8_t len);
|
||||
|
||||
#define net_buf_simple_add_mem(a, b, c) os_mbuf_append(a,b,c)
|
||||
|
||||
const char *
|
||||
bt_hex(const void *buf, size_t len);
|
||||
|
||||
/**
|
||||
* INTERNAL_HIDDEN @endcond
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Define an array of atomic variables.
|
||||
*
|
||||
* This macro defines an array of atomic variables containing at least
|
||||
* @a num_bits bits.
|
||||
*
|
||||
* @note
|
||||
* If used from file scope, the bits of the array are initialized to zero;
|
||||
* if used from within a function, the bits are left uninitialized.
|
||||
*
|
||||
* @param name Name of array of atomic variables.
|
||||
* @param num_bits Number of bits needed.
|
||||
*/
|
||||
#define ATOMIC_DEFINE(name, num_bits) \
|
||||
atomic_t name[1 + ((num_bits) - 1) / ATOMIC_BITS]
|
||||
#endif /* __GLUE_H__ */
|
||||
Reference in New Issue
Block a user