Update to nimble 1.3 master branch commit 82153e744833821e20e9a8b0d61c38b2b0dbcfe1

WARNING : heartbeat task is disabled!
This commit is contained in:
Jean-François Milants 2021-02-02 22:09:00 +01:00
parent 9c35b6fe5d
commit d90b7274fa
286 changed files with 31459 additions and 9391 deletions

View file

@ -0,0 +1,54 @@
<!--
#
# 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.
#
-->
# Sample applications
## advertiser
This is the simplest example of advertising. Application sets NRPA, configures
advertisement parameters: general discoverable and not connectable and fills
advertisement fields. Transmited data contains only flags, tx power level and
device name, which fits in 31B limit of single package. With this data set,
device advertises for 10 seconds, terminates advertisement and repeats process
again infinitely.
## scanner
This application shows how to perform simple scan. Device performs discovery
procedure, during which receives advertising reports (if any devices are
advertising nearby). These reports are being parsed and results are printed to
serial port. Applicaton starts new discovery every second.
## peripheral
Peripheral application is based on advertiser, but has added capability of
connecting with other devices. As peripheral, device doesn't initiate any
connection by itself; instead, advertises infinitely and accepts any connection
request it receives. Because we cannot use any 16 or 32 bit UUIDs, as these are
reserved by Bluetooth SIG, we are forced to use 128-bit one. Including such
long UUID in advertising data consumes large part of available payload, so this
data is split in advertising data and response data.
## central
This application works in pair with peripheral. It's based on scanner
application - the difference is, that if there was detected device with UUID
fitting to the one predefined in central application, connection is initiated.

View file

@ -42,26 +42,6 @@ static int recent_test_id = STANDARD_TEST_ID;
static bool has_reg_fault = true;
static struct bt_mesh_cfg_srv cfg_srv = {
.relay = BT_MESH_RELAY_DISABLED,
.beacon = BT_MESH_BEACON_ENABLED,
#if MYNEWT_VAL(BLE_MESH_FRIEND)
.frnd = BT_MESH_FRIEND_ENABLED,
#else
.gatt_proxy = BT_MESH_GATT_PROXY_NOT_SUPPORTED,
#endif
#if MYNEWT_VAL(BLE_MESH_GATT_PROXY)
.gatt_proxy = BT_MESH_GATT_PROXY_ENABLED,
#else
.gatt_proxy = BT_MESH_GATT_PROXY_NOT_SUPPORTED,
#endif
.default_ttl = 7,
/* 3 transmissions with 20ms interval */
.net_transmit = BT_MESH_TRANSMIT(2, 20),
.relay_retransmit = BT_MESH_TRANSMIT(2, 20),
};
static int
fault_get_cur(struct bt_mesh_model *model,
uint8_t *test_id,
@ -327,7 +307,7 @@ static const struct bt_mesh_model_op gen_level_op[] = {
};
static struct bt_mesh_model root_models[] = {
BT_MESH_MODEL_CFG_SRV(&cfg_srv),
BT_MESH_MODEL_CFG_SRV,
BT_MESH_MODEL_HEALTH_SRV(&health_srv, &health_pub),
BT_MESH_MODEL(BT_MESH_MODEL_ID_GEN_ONOFF_SRV, gen_onoff_op,
&gen_onoff_pub, NULL),
@ -385,7 +365,7 @@ static int output_number(bt_mesh_output_action_t action, uint32_t number)
return 0;
}
static void prov_complete(u16_t net_idx, u16_t addr)
static void prov_complete(uint16_t net_idx, uint16_t addr)
{
console_printf("Local node provisioned, primary address 0x%04x\n", addr);
}

View file

@ -48,10 +48,10 @@ static uint16_t top_val;
static uint32_t neopixel[WS2812_NUM_LED];
#endif
static u8_t gen_onoff_state;
static s16_t gen_level_state;
static uint8_t gen_onoff_state;
static int16_t gen_level_state;
static void light_set_lightness(u8_t percentage)
static void light_set_lightness(uint8_t percentage)
{
#if (!MYNEWT_VAL(USE_NEOPIXEL))
int rc;
@ -76,10 +76,10 @@ static void light_set_lightness(u8_t percentage)
#endif
#else
int i;
u32_t lightness;
u8_t max_lightness = 0x1f;
uint32_t lightness;
uint8_t max_lightness = 0x1f;
lightness = (u8_t) (percentage * max_lightness / 100);
lightness = (uint8_t) (percentage * max_lightness / 100);
for (i = 0; i < WS2812_NUM_LED; i++) {
neopixel[i] = (lightness | lightness << 8 | lightness << 16);
@ -90,7 +90,7 @@ static void light_set_lightness(u8_t percentage)
static void update_light_state(void)
{
u16_t level = (u16_t)gen_level_state;
uint16_t level = (uint16_t)gen_level_state;
int percent = 100 * level / 0xffff;
if (gen_onoff_state == 0) {
@ -99,44 +99,44 @@ static void update_light_state(void)
light_set_lightness((uint8_t) percent);
}
int light_model_gen_onoff_get(struct bt_mesh_model *model, u8_t *state)
int light_model_gen_onoff_get(struct bt_mesh_model *model, uint8_t *state)
{
*state = gen_onoff_state;
return 0;
}
int light_model_gen_onoff_set(struct bt_mesh_model *model, u8_t state)
int light_model_gen_onoff_set(struct bt_mesh_model *model, uint8_t state)
{
gen_onoff_state = state;
update_light_state();
return 0;
}
int light_model_gen_level_get(struct bt_mesh_model *model, s16_t *level)
int light_model_gen_level_get(struct bt_mesh_model *model, int16_t *level)
{
*level = gen_level_state;
return 0;
}
int light_model_gen_level_set(struct bt_mesh_model *model, s16_t level)
int light_model_gen_level_set(struct bt_mesh_model *model, int16_t level)
{
gen_level_state = level;
if ((u16_t)gen_level_state > 0x0000) {
if ((uint16_t)gen_level_state > 0x0000) {
gen_onoff_state = 1;
}
if ((u16_t)gen_level_state == 0x0000) {
if ((uint16_t)gen_level_state == 0x0000) {
gen_onoff_state = 0;
}
update_light_state();
return 0;
}
int light_model_light_lightness_get(struct bt_mesh_model *model, s16_t *lightness)
int light_model_light_lightness_get(struct bt_mesh_model *model, int16_t *lightness)
{
return light_model_gen_level_get(model, lightness);
}
int light_model_light_lightness_set(struct bt_mesh_model *model, s16_t lightness)
int light_model_light_lightness_set(struct bt_mesh_model *model, int16_t lightness)
{
return light_model_gen_level_set(model, lightness);
}

View file

@ -26,12 +26,12 @@
#include "syscfg/syscfg.h"
#include "mesh/mesh.h"
int light_model_gen_onoff_get(struct bt_mesh_model *model, u8_t *state);
int light_model_gen_onoff_set(struct bt_mesh_model *model, u8_t state);
int light_model_gen_level_get(struct bt_mesh_model *model, s16_t *level);
int light_model_gen_level_set(struct bt_mesh_model *model, s16_t level);
int light_model_light_lightness_get(struct bt_mesh_model *model, s16_t *lightness);
int light_model_light_lightness_set(struct bt_mesh_model *model, s16_t lightness);
int light_model_gen_onoff_get(struct bt_mesh_model *model, uint8_t *state);
int light_model_gen_onoff_set(struct bt_mesh_model *model, uint8_t state);
int light_model_gen_level_get(struct bt_mesh_model *model, int16_t *level);
int light_model_gen_level_set(struct bt_mesh_model *model, int16_t level);
int light_model_light_lightness_get(struct bt_mesh_model *model, int16_t *lightness);
int light_model_light_lightness_set(struct bt_mesh_model *model, int16_t lightness);
int light_model_init(void);
#endif

View file

@ -31,8 +31,8 @@
#include "light_model.h"
static void model_bound_cb(u16_t addr, struct bt_mesh_model *model,
u16_t key_idx)
static void model_bound_cb(uint16_t addr, struct bt_mesh_model *model,
uint16_t key_idx)
{
int rc;

View file

@ -84,30 +84,6 @@ static void gen_onoff_status(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct os_mbuf *buf);
/*
* Server Configuration Declaration
*/
static struct bt_mesh_cfg_srv cfg_srv = {
.relay = BT_MESH_RELAY_DISABLED,
.beacon = BT_MESH_BEACON_ENABLED,
#if defined(CONFIG_BT_MESH_FRIEND)
.frnd = BT_MESH_FRIEND_ENABLED,
#else
.frnd = BT_MESH_FRIEND_NOT_SUPPORTED,
#endif
#if defined(CONFIG_BT_MESH_GATT_PROXY)
.gatt_proxy = BT_MESH_GATT_PROXY_ENABLED,
#else
.gatt_proxy = BT_MESH_GATT_PROXY_NOT_SUPPORTED,
#endif
.default_ttl = 7,
/* 3 transmissions with 20ms interval */
.net_transmit = BT_MESH_TRANSMIT(2, 20),
.relay_retransmit = BT_MESH_TRANSMIT(2, 20),
};
/*
* Client Configuration Declaration
*/
@ -213,9 +189,9 @@ static const struct bt_mesh_model_op gen_onoff_cli_op[] = {
};
struct onoff_state {
u8_t current;
u8_t previous;
u8_t led_gpio_pin;
uint8_t current;
uint8_t previous;
uint8_t led_gpio_pin;
};
/*
@ -238,7 +214,7 @@ static struct onoff_state onoff_state_arr[] = {
*/
static struct bt_mesh_model root_models[] = {
BT_MESH_MODEL_CFG_SRV(&cfg_srv),
BT_MESH_MODEL_CFG_SRV,
BT_MESH_MODEL_CFG_CLI(&cfg_cli),
BT_MESH_MODEL_HEALTH_SRV(&health_srv, &health_pub),
BT_MESH_MODEL(BT_MESH_MODEL_ID_GEN_ONOFF_SRV, gen_onoff_srv_op,
@ -320,20 +296,20 @@ static const struct bt_mesh_comp comp = {
};
struct sw {
u8_t sw_num;
u8_t onoff_state;
uint8_t sw_num;
uint8_t onoff_state;
struct os_callout button_work;
struct os_callout button_timer;
};
static u8_t button_press_cnt;
static uint8_t button_press_cnt;
static struct sw sw;
static u8_t trans_id;
static u32_t time, last_time;
static u16_t primary_addr;
static u16_t primary_net_idx;
static uint8_t trans_id;
static uint32_t time, last_time;
static uint16_t primary_addr;
static uint16_t primary_net_idx;
/*
* Generic OnOff Model Server Message Handlers
@ -416,7 +392,7 @@ static void gen_onoff_status(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct os_mbuf *buf)
{
u8_t state;
uint8_t state;
state = net_buf_simple_pull_u8(buf);
@ -424,7 +400,7 @@ static void gen_onoff_status(struct bt_mesh_model *model,
bt_mesh_model_elem(model)->addr, ctx->addr, state);
}
static int output_number(bt_mesh_output_action_t action, u32_t number)
static int output_number(bt_mesh_output_action_t action, uint32_t number)
{
BT_INFO("OOB Number %u", number);
return 0;
@ -436,7 +412,7 @@ static int output_string(const char *str)
return 0;
}
static void prov_complete(u16_t net_idx, u16_t addr)
static void prov_complete(uint16_t net_idx, uint16_t addr)
{
BT_INFO("provisioning complete for net_idx 0x%04x addr 0x%04x",
net_idx, addr);
@ -449,7 +425,7 @@ static void prov_reset(void)
bt_mesh_prov_enable(BT_MESH_PROV_ADV | BT_MESH_PROV_GATT);
}
static u8_t dev_uuid[16] = MYNEWT_VAL(BLE_MESH_DEV_UUID);
static uint8_t dev_uuid[16] = MYNEWT_VAL(BLE_MESH_DEV_UUID);
#define BUTTON_DEBOUNCE_DELAY_MS 250
@ -528,7 +504,7 @@ static void button_pressed_worker(struct os_event *work)
struct bt_mesh_model *mod_cli, *mod_srv;
struct bt_mesh_model_pub *pub_cli, *pub_srv;
struct sw *sw = work->ev_arg;
u8_t sw_idx = sw->sw_num;
uint8_t sw_idx = sw->sw_num;
int err;
mod_cli = mod_cli_sw[sw_idx];
@ -599,7 +575,7 @@ static const struct bt_mesh_prov prov = {
.reset = prov_reset,
};
void init_led(u8_t dev)
void init_led(uint8_t dev)
{
hal_gpio_init_out(onoff_state_arr[dev].led_gpio_pin, 1);
}

View file

@ -34,7 +34,7 @@
#ifdef OOB_AUTH_ENABLE
static int output_number(bt_mesh_output_action_t action, u32_t number)
static int output_number(bt_mesh_output_action_t action, uint32_t number)
{
printk("OOB Number: %lu\n", number);
return 0;
@ -48,7 +48,7 @@ static int output_string(const char *str)
#endif
static void prov_complete(u16_t net_idx, u16_t addr)
static void prov_complete(uint16_t net_idx, uint16_t addr)
{
printk("Local node provisioned, primary address 0x%04x\n", addr);
}
@ -58,7 +58,7 @@ static void prov_reset(void)
bt_mesh_prov_enable(BT_MESH_PROV_ADV | BT_MESH_PROV_GATT);
}
static u8_t dev_uuid[16] = MYNEWT_VAL(BLE_MESH_DEV_UUID);
static uint8_t dev_uuid[16] = MYNEWT_VAL(BLE_MESH_DEV_UUID);
static const struct bt_mesh_prov prov = {
.uuid = dev_uuid,

View file

@ -36,31 +36,6 @@
#include "state_binding.h"
#include "transition.h"
static struct bt_mesh_cfg_srv cfg_srv = {
.relay = BT_MESH_RELAY_ENABLED,
.beacon = BT_MESH_BEACON_ENABLED,
#if defined(CONFIG_BT_MESH_FRIEND)
.frnd = BT_MESH_FRIEND_ENABLED,
#else
.frnd = BT_MESH_FRIEND_NOT_SUPPORTED,
#endif
#if defined(CONFIG_BT_MESH_GATT_PROXY)
.gatt_proxy = BT_MESH_GATT_PROXY_ENABLED,
#else
.gatt_proxy = BT_MESH_GATT_PROXY_NOT_SUPPORTED,
#endif
.default_ttl = 7,
/* 2 transmissions with 20ms interval */
.net_transmit = BT_MESH_TRANSMIT(2, 20),
/* 3 transmissions with 20ms interval */
.relay_retransmit = BT_MESH_TRANSMIT(3, 20),
};
static struct bt_mesh_health_srv health_srv = {
};
@ -224,8 +199,8 @@ static void gen_onoff_set_unack(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct os_mbuf *buf)
{
u8_t tid, onoff, tt, delay;
s64_t now;
uint8_t tid, onoff, tt, delay;
int64_t now;
struct generic_onoff_state *state = model->user_data;
onoff = net_buf_simple_pull_u8(buf);
@ -290,8 +265,8 @@ static void gen_onoff_set(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct os_mbuf *buf)
{
u8_t tid, onoff, tt, delay;
s64_t now;
uint8_t tid, onoff, tt, delay;
int64_t now;
struct generic_onoff_state *state = model->user_data;
onoff = net_buf_simple_pull_u8(buf);
@ -422,12 +397,12 @@ static void gen_level_set_unack(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct os_mbuf *buf)
{
u8_t tid, tt, delay;
s16_t level;
s64_t now;
uint8_t tid, tt, delay;
int16_t level;
int64_t now;
struct generic_level_state *state = model->user_data;
level = (s16_t) net_buf_simple_pull_le16(buf);
level = (int16_t) net_buf_simple_pull_le16(buf);
tid = net_buf_simple_pull_u8(buf);
now = k_uptime_get();
@ -494,12 +469,12 @@ static void gen_level_set(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct os_mbuf *buf)
{
u8_t tid, tt, delay;
s16_t level;
s64_t now;
uint8_t tid, tt, delay;
int16_t level;
int64_t now;
struct generic_level_state *state = model->user_data;
level = (s16_t) net_buf_simple_pull_le16(buf);
level = (int16_t) net_buf_simple_pull_le16(buf);
tid = net_buf_simple_pull_u8(buf);
now = k_uptime_get();
@ -569,12 +544,12 @@ static void gen_delta_set_unack(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct os_mbuf *buf)
{
u8_t tid, tt, delay;
s32_t tmp32, delta;
s64_t now;
uint8_t tid, tt, delay;
int32_t tmp32, delta;
int64_t now;
struct generic_level_state *state = model->user_data;
delta = (s32_t) net_buf_simple_pull_le32(buf);
delta = (int32_t) net_buf_simple_pull_le32(buf);
tid = net_buf_simple_pull_u8(buf);
now = k_uptime_get();
@ -658,12 +633,12 @@ static void gen_delta_set(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct os_mbuf *buf)
{
u8_t tid, tt, delay;
s32_t tmp32, delta;
s64_t now;
uint8_t tid, tt, delay;
int32_t tmp32, delta;
int64_t now;
struct generic_level_state *state = model->user_data;
delta = (s32_t) net_buf_simple_pull_le32(buf);
delta = (int32_t) net_buf_simple_pull_le32(buf);
tid = net_buf_simple_pull_u8(buf);
now = k_uptime_get();
@ -805,13 +780,13 @@ static void gen_move_set_unack(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct os_mbuf *buf)
{
u8_t tid, tt, delay;
s16_t delta;
s32_t tmp32;
s64_t now;
uint8_t tid, tt, delay;
int16_t delta;
int32_t tmp32;
int64_t now;
struct generic_level_state *state = model->user_data;
delta = (s16_t) net_buf_simple_pull_le16(buf);
delta = (int16_t) net_buf_simple_pull_le16(buf);
tid = net_buf_simple_pull_u8(buf);
now = k_uptime_get();
@ -886,13 +861,13 @@ static void gen_move_set(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct os_mbuf *buf)
{
u8_t tid, tt, delay;
s16_t delta;
s32_t tmp32;
s64_t now;
uint8_t tid, tt, delay;
int16_t delta;
int32_t tmp32;
int64_t now;
struct generic_level_state *state = model->user_data;
delta = (s16_t) net_buf_simple_pull_le16(buf);
delta = (int16_t) net_buf_simple_pull_le16(buf);
tid = net_buf_simple_pull_u8(buf);
now = k_uptime_get();
@ -1021,7 +996,7 @@ static bool gen_def_trans_time_setunack(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct os_mbuf *buf)
{
u8_t tt;
uint8_t tt;
struct gen_def_trans_time_state *state = model->user_data;
tt = net_buf_simple_pull_u8(buf);
@ -1122,7 +1097,7 @@ static bool gen_onpowerup_setunack(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct os_mbuf *buf)
{
u8_t onpowerup;
uint8_t onpowerup;
struct generic_onpowerup_state *state = model->user_data;
onpowerup = net_buf_simple_pull_u8(buf);
@ -1187,9 +1162,9 @@ static void vnd_set_unack(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct os_mbuf *buf)
{
u8_t tid;
uint8_t tid;
int current;
s64_t now;
int64_t now;
struct vendor_state *state = model->user_data;
current = net_buf_simple_pull_le16(buf);
@ -1290,9 +1265,9 @@ static void light_lightness_set_unack(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct os_mbuf *buf)
{
u8_t tid, tt, delay;
u16_t actual;
s64_t now;
uint8_t tid, tt, delay;
uint16_t actual;
int64_t now;
struct light_lightness_state *state = model->user_data;
actual = net_buf_simple_pull_le16(buf);
@ -1360,9 +1335,9 @@ static void light_lightness_set(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct os_mbuf *buf)
{
u8_t tid, tt, delay;
u16_t actual;
s64_t now;
uint8_t tid, tt, delay;
uint16_t actual;
int64_t now;
struct light_lightness_state *state = model->user_data;
actual = net_buf_simple_pull_le16(buf);
@ -1483,9 +1458,9 @@ static void light_lightness_linear_set_unack(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct os_mbuf *buf)
{
u8_t tid, tt, delay;
u16_t linear;
s64_t now;
uint8_t tid, tt, delay;
uint16_t linear;
int64_t now;
struct light_lightness_state *state = model->user_data;
linear = net_buf_simple_pull_le16(buf);
@ -1546,9 +1521,9 @@ static void light_lightness_linear_set(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct os_mbuf *buf)
{
u8_t tid, tt, delay;
u16_t linear;
s64_t now;
uint8_t tid, tt, delay;
uint16_t linear;
int64_t now;
struct light_lightness_state *state = model->user_data;
linear = net_buf_simple_pull_le16(buf);
@ -1690,7 +1665,7 @@ static void light_lightness_default_set_unack(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct os_mbuf *buf)
{
u16_t lightness;
uint16_t lightness;
struct light_lightness_state *state = model->user_data;
lightness = net_buf_simple_pull_le16(buf);
@ -1741,7 +1716,7 @@ static bool light_lightness_range_setunack(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct os_mbuf *buf)
{
u16_t min, max;
uint16_t min, max;
struct light_lightness_state *state = model->user_data;
min = net_buf_simple_pull_le16(buf);
@ -1908,15 +1883,15 @@ static void light_ctl_set_unack(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct os_mbuf *buf)
{
u8_t tid, tt, delay;
s16_t delta_uv;
u16_t lightness, temp;
s64_t now;
uint8_t tid, tt, delay;
int16_t delta_uv;
uint16_t lightness, temp;
int64_t now;
struct light_ctl_state *state = model->user_data;
lightness = net_buf_simple_pull_le16(buf);
temp = net_buf_simple_pull_le16(buf);
delta_uv = (s16_t) net_buf_simple_pull_le16(buf);
delta_uv = (int16_t) net_buf_simple_pull_le16(buf);
tid = net_buf_simple_pull_u8(buf);
if (temp < TEMP_MIN || temp > TEMP_MAX) {
@ -1991,15 +1966,15 @@ static void light_ctl_set(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct os_mbuf *buf)
{
u8_t tid, tt, delay;
s16_t delta_uv;
u16_t lightness, temp;
s64_t now;
uint8_t tid, tt, delay;
int16_t delta_uv;
uint16_t lightness, temp;
int64_t now;
struct light_ctl_state *state = model->user_data;
lightness = net_buf_simple_pull_le16(buf);
temp = net_buf_simple_pull_le16(buf);
delta_uv = (s16_t) net_buf_simple_pull_le16(buf);
delta_uv = (int16_t) net_buf_simple_pull_le16(buf);
tid = net_buf_simple_pull_u8(buf);
if (temp < TEMP_MIN || temp > TEMP_MAX) {
@ -2140,13 +2115,13 @@ static bool light_ctl_default_setunack(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct os_mbuf *buf)
{
u16_t lightness, temp;
s16_t delta_uv;
uint16_t lightness, temp;
int16_t delta_uv;
struct light_ctl_state *state = model->user_data;
lightness = net_buf_simple_pull_le16(buf);
temp = net_buf_simple_pull_le16(buf);
delta_uv = (s16_t) net_buf_simple_pull_le16(buf);
delta_uv = (int16_t) net_buf_simple_pull_le16(buf);
/* Here, Model specification is silent about tid implementation */
@ -2216,7 +2191,7 @@ static bool light_ctl_temp_range_setunack(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct os_mbuf *buf)
{
u16_t min, max;
uint16_t min, max;
struct light_ctl_state *state = model->user_data;
min = net_buf_simple_pull_le16(buf);
@ -2384,14 +2359,14 @@ static void light_ctl_temp_set_unack(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct os_mbuf *buf)
{
u8_t tid, tt, delay;
s16_t delta_uv;
u16_t temp;
s64_t now;
uint8_t tid, tt, delay;
int16_t delta_uv;
uint16_t temp;
int64_t now;
struct light_ctl_state *state = model->user_data;
temp = net_buf_simple_pull_le16(buf);
delta_uv = (s16_t) net_buf_simple_pull_le16(buf);
delta_uv = (int16_t) net_buf_simple_pull_le16(buf);
tid = net_buf_simple_pull_u8(buf);
if (temp < TEMP_MIN || temp > TEMP_MAX) {
@ -2463,14 +2438,14 @@ static void light_ctl_temp_set(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct os_mbuf *buf)
{
u8_t tid, tt, delay;
s16_t delta_uv;
u16_t temp;
s64_t now;
uint8_t tid, tt, delay;
int16_t delta_uv;
uint16_t temp;
int64_t now;
struct light_ctl_state *state = model->user_data;
temp = net_buf_simple_pull_le16(buf);
delta_uv = (s16_t) net_buf_simple_pull_le16(buf);
delta_uv = (int16_t) net_buf_simple_pull_le16(buf);
tid = net_buf_simple_pull_u8(buf);
if (temp < TEMP_MIN || temp > TEMP_MAX) {
@ -2689,7 +2664,7 @@ static const struct bt_mesh_model_op vnd_ops[] = {
};
struct bt_mesh_model root_models[] = {
BT_MESH_MODEL_CFG_SRV(&cfg_srv),
BT_MESH_MODEL_CFG_SRV,
BT_MESH_MODEL_HEALTH_SRV(&health_srv, &health_pub),
BT_MESH_MODEL(BT_MESH_MODEL_ID_GEN_ONOFF_SRV,

View file

@ -46,109 +46,109 @@
#define CANNOT_SET_RANGE_MAX 0x02
struct generic_onoff_state {
u8_t onoff;
u8_t target_onoff;
uint8_t onoff;
uint8_t target_onoff;
u8_t last_tid;
u16_t last_src_addr;
u16_t last_dst_addr;
s64_t last_msg_timestamp;
uint8_t last_tid;
uint16_t last_src_addr;
uint16_t last_dst_addr;
int64_t last_msg_timestamp;
s32_t tt_delta;
int32_t tt_delta;
struct transition *transition;
};
struct generic_level_state {
s16_t level;
s16_t target_level;
int16_t level;
int16_t target_level;
s16_t last_level;
s32_t last_delta;
int16_t last_level;
int32_t last_delta;
u8_t last_tid;
u16_t last_src_addr;
u16_t last_dst_addr;
s64_t last_msg_timestamp;
uint8_t last_tid;
uint16_t last_src_addr;
uint16_t last_dst_addr;
int64_t last_msg_timestamp;
s32_t tt_delta;
int32_t tt_delta;
struct transition *transition;
};
struct generic_onpowerup_state {
u8_t onpowerup;
uint8_t onpowerup;
};
struct gen_def_trans_time_state {
u8_t tt;
uint8_t tt;
};
struct vendor_state {
int current;
u32_t response;
u8_t last_tid;
u16_t last_src_addr;
u16_t last_dst_addr;
s64_t last_msg_timestamp;
uint32_t response;
uint8_t last_tid;
uint16_t last_src_addr;
uint16_t last_dst_addr;
int64_t last_msg_timestamp;
};
struct light_lightness_state {
u16_t linear;
u16_t target_linear;
uint16_t linear;
uint16_t target_linear;
u16_t actual;
u16_t target_actual;
uint16_t actual;
uint16_t target_actual;
u16_t last;
u16_t def;
uint16_t last;
uint16_t def;
u8_t status_code;
u16_t light_range_min;
u16_t light_range_max;
u32_t lightness_range;
uint8_t status_code;
uint16_t light_range_min;
uint16_t light_range_max;
uint32_t lightness_range;
u8_t last_tid;
u16_t last_src_addr;
u16_t last_dst_addr;
s64_t last_msg_timestamp;
uint8_t last_tid;
uint16_t last_src_addr;
uint16_t last_dst_addr;
int64_t last_msg_timestamp;
s32_t tt_delta_actual;
s32_t tt_delta_linear;
int32_t tt_delta_actual;
int32_t tt_delta_linear;
struct transition *transition;
};
struct light_ctl_state {
u16_t lightness;
u16_t target_lightness;
uint16_t lightness;
uint16_t target_lightness;
u16_t temp;
u16_t target_temp;
uint16_t temp;
uint16_t target_temp;
s16_t delta_uv;
s16_t target_delta_uv;
int16_t delta_uv;
int16_t target_delta_uv;
u8_t status_code;
u16_t temp_range_min;
u16_t temp_range_max;
u32_t temperature_range;
uint8_t status_code;
uint16_t temp_range_min;
uint16_t temp_range_max;
uint32_t temperature_range;
u16_t lightness_def;
u16_t temp_def;
u32_t lightness_temp_def;
s16_t delta_uv_def;
uint16_t lightness_def;
uint16_t temp_def;
uint32_t lightness_temp_def;
int16_t delta_uv_def;
u32_t lightness_temp_last;
uint32_t lightness_temp_last;
u8_t last_tid;
u16_t last_src_addr;
u16_t last_dst_addr;
s64_t last_msg_timestamp;
uint8_t last_tid;
uint16_t last_src_addr;
uint16_t last_dst_addr;
int64_t last_msg_timestamp;
s32_t tt_delta_lightness;
s32_t tt_delta_temp;
s32_t tt_delta_duv;
int32_t tt_delta_lightness;
int32_t tt_delta_temp;
int32_t tt_delta_duv;
struct transition *transition;
};

View file

@ -59,14 +59,14 @@ static void light_default_var_init(void)
light_ctl_srv_user_data.temp_def = TEMP_MIN;
light_ctl_srv_user_data.lightness_temp_last =
(u32_t) ((LIGHTNESS_MAX << 16) | TEMP_MIN);
(uint32_t) ((LIGHTNESS_MAX << 16) | TEMP_MIN);
}
static void light_default_status_init(void)
{
u16_t lightness;
uint16_t lightness;
lightness = (u16_t) (light_ctl_srv_user_data.lightness_temp_last >> 16);
lightness = (uint16_t) (light_ctl_srv_user_data.lightness_temp_last >> 16);
if (lightness) {
gen_onoff_srv_root_user_data.onoff = STATE_ON;
@ -77,10 +77,10 @@ static void light_default_status_init(void)
/* Retrieve Default Lightness & Temperature Values */
if (light_ctl_srv_user_data.lightness_temp_def) {
light_ctl_srv_user_data.lightness_def = (u16_t)
light_ctl_srv_user_data.lightness_def = (uint16_t)
(light_ctl_srv_user_data.lightness_temp_def >> 16);
light_ctl_srv_user_data.temp_def = (u16_t)
light_ctl_srv_user_data.temp_def = (uint16_t)
(light_ctl_srv_user_data.lightness_temp_def);
}
@ -92,18 +92,18 @@ static void light_default_status_init(void)
/* Retrieve Range of Lightness & Temperature */
if (light_lightness_srv_user_data.lightness_range) {
light_lightness_srv_user_data.light_range_max = (u16_t)
light_lightness_srv_user_data.light_range_max = (uint16_t)
(light_lightness_srv_user_data.lightness_range >> 16);
light_lightness_srv_user_data.light_range_min = (u16_t)
light_lightness_srv_user_data.light_range_min = (uint16_t)
(light_lightness_srv_user_data.lightness_range);
}
if (light_ctl_srv_user_data.temperature_range) {
light_ctl_srv_user_data.temp_range_max = (u16_t)
light_ctl_srv_user_data.temp_range_max = (uint16_t)
(light_ctl_srv_user_data.temperature_range >> 16);
light_ctl_srv_user_data.temp_range_min = (u16_t)
light_ctl_srv_user_data.temp_range_min = (uint16_t)
(light_ctl_srv_user_data.temperature_range);
}
@ -117,11 +117,11 @@ static void light_default_status_init(void)
state_binding(ONOFF, ONOFF_TEMP);
break;
case STATE_RESTORE:
light_lightness_srv_user_data.last = (u16_t)
light_lightness_srv_user_data.last = (uint16_t)
(light_ctl_srv_user_data.lightness_temp_last >> 16);
light_ctl_srv_user_data.temp =
(u16_t) (light_ctl_srv_user_data.lightness_temp_last);
(uint16_t) (light_ctl_srv_user_data.lightness_temp_last);
state_binding(ONPOWERUP, ONOFF_TEMP);
break;
@ -132,7 +132,7 @@ static void light_default_status_init(void)
void update_light_state(void)
{
u8_t power, color;
uint8_t power, color;
power = 100 * ((float) lightness / 65535);
color = 100 * ((float) (temperature + 32768) / 65535);

View file

@ -41,12 +41,12 @@
static bool is_randomization_of_TIDs_done;
#if (defined(ONOFF) || defined(ONOFF_TT))
static u8_t tid_onoff;
static uint8_t tid_onoff;
#elif defined(VND_MODEL_TEST)
static u8_t tid_vnd;
static uint8_t tid_vnd;
#endif
static u8_t tid_level;
static uint8_t tid_level;
void randomize_publishers_TID(void)
{
@ -61,7 +61,7 @@ void randomize_publishers_TID(void)
is_randomization_of_TIDs_done = true;
}
static u32_t button_read(int button)
static uint32_t button_read(int button)
{
return (uint32_t) hal_gpio_read(button);
}

View file

@ -32,14 +32,14 @@
#include "transition.h"
u16_t lightness, target_lightness;
s16_t temperature, target_temperature;
uint16_t lightness, target_lightness;
int16_t temperature, target_temperature;
static s32_t ceiling(float num)
static int32_t ceiling(float num)
{
s32_t inum;
int32_t inum;
inum = (s32_t) num;
inum = (int32_t) num;
if (num == (float) inum) {
return inum;
}
@ -47,21 +47,21 @@ static s32_t ceiling(float num)
return inum + 1;
}
u16_t actual_to_linear(u16_t val)
uint16_t actual_to_linear(uint16_t val)
{
float tmp;
tmp = ((float) val / 65535);
return (u16_t) ceiling(65535 * tmp * tmp);
return (uint16_t) ceiling(65535 * tmp * tmp);
}
u16_t linear_to_actual(u16_t val)
uint16_t linear_to_actual(uint16_t val)
{
return (u16_t) (65535 * sqrt(((float) val / 65535)));
return (uint16_t) (65535 * sqrt(((float) val / 65535)));
}
static void constrain_lightness(u16_t var)
static void constrain_lightness(uint16_t var)
{
if (var > 0 && var < light_lightness_srv_user_data.light_range_min) {
var = light_lightness_srv_user_data.light_range_min;
@ -72,7 +72,7 @@ static void constrain_lightness(u16_t var)
lightness = var;
}
static void constrain_lightness2(u16_t var)
static void constrain_lightness2(uint16_t var)
{
/* This is as per Mesh Model Specification 3.3.2.2.3 */
if (var > 0 && var < light_lightness_srv_user_data.light_range_min) {
@ -88,7 +88,7 @@ static void constrain_lightness2(u16_t var)
lightness = var;
}
static void constrain_target_lightness(u16_t var)
static void constrain_target_lightness(uint16_t var)
{
if (var > 0 &&
var < light_lightness_srv_user_data.light_range_min) {
@ -100,7 +100,7 @@ static void constrain_target_lightness(u16_t var)
target_lightness = var;
}
static s16_t light_ctl_temp_to_level(u16_t temp)
static int16_t light_ctl_temp_to_level(uint16_t temp)
{
float tmp;
@ -111,14 +111,14 @@ static s16_t light_ctl_temp_to_level(u16_t temp)
tmp = tmp / (light_ctl_srv_user_data.temp_range_max -
light_ctl_srv_user_data.temp_range_min);
return (s16_t) (tmp - 32768);
return (int16_t) (tmp - 32768);
/* 6.1.3.1.1 2nd formula end */
}
static u16_t level_to_light_ctl_temp(s16_t level)
static uint16_t level_to_light_ctl_temp(int16_t level)
{
u16_t tmp;
uint16_t tmp;
float diff;
/* Mesh Model Specification 6.1.3.1.1 1st formula start */
@ -126,14 +126,14 @@ static u16_t level_to_light_ctl_temp(s16_t level)
light_ctl_srv_user_data.temp_range_min) / 65535;
tmp = (u16_t) ((level + 32768) * diff);
tmp = (uint16_t) ((level + 32768) * diff);
return (light_ctl_srv_user_data.temp_range_min + tmp);
/* 6.1.3.1.1 1st formula end */
}
void state_binding(u8_t light, u8_t temp)
void state_binding(uint8_t light, uint8_t temp)
{
switch (temp) {
case ONOFF_TEMP:
@ -211,10 +211,10 @@ jump:
light_ctl_srv_user_data.lightness = lightness;
}
void calculate_lightness_target_values(u8_t type)
void calculate_lightness_target_values(uint8_t type)
{
bool set_light_ctl_temp_target_value;
u16_t tmp;
uint16_t tmp;
set_light_ctl_temp_target_value = true;
@ -274,7 +274,7 @@ void calculate_lightness_target_values(u8_t type)
}
}
void calculate_temp_target_values(u8_t type)
void calculate_temp_target_values(uint8_t type)
{
bool set_light_ctl_delta_uv_target_value;

View file

@ -43,11 +43,11 @@ enum state_binding {
IGNORE_TEMP
};
extern u16_t lightness, target_lightness;
extern s16_t temperature, target_temperature;
extern uint16_t lightness, target_lightness;
extern int16_t temperature, target_temperature;
void state_binding(u8_t lightness, u8_t temperature);
void calculate_lightness_target_values(u8_t type);
void calculate_temp_target_values(u8_t type);
void state_binding(uint8_t lightness, uint8_t temperature);
void calculate_lightness_target_values(uint8_t type);
void calculate_temp_target_values(uint8_t type);
#endif

View file

@ -32,8 +32,8 @@
#include "device_composition.h"
#include "storage.h"
static u8_t storage_id;
u8_t reset_counter;
static uint8_t storage_id;
uint8_t reset_counter;
static void save_reset_counter(void)
{
@ -76,7 +76,7 @@ static void save_lightness_temp_def_state(void)
char buf[12];
light_ctl_srv_user_data.lightness_temp_def =
(u32_t) ((light_ctl_srv_user_data.lightness_def << 16) |
(uint32_t) ((light_ctl_srv_user_data.lightness_def << 16) |
light_ctl_srv_user_data.temp_def);
settings_str_from_bytes(&light_ctl_srv_user_data.lightness_temp_def,
@ -91,7 +91,7 @@ static void save_lightness_temp_last_state(void)
char buf[12];
light_ctl_srv_user_data.lightness_temp_last =
(u32_t) ((light_ctl_srv_user_data.lightness << 16) |
(uint32_t) ((light_ctl_srv_user_data.lightness << 16) |
light_ctl_srv_user_data.temp);
settings_str_from_bytes(&light_ctl_srv_user_data.lightness_temp_last,
@ -108,7 +108,7 @@ static void save_lightness_range(void)
char buf[12];
light_lightness_srv_user_data.lightness_range =
(u32_t) ((light_lightness_srv_user_data.light_range_max << 16) |
(uint32_t) ((light_lightness_srv_user_data.light_range_max << 16) |
light_lightness_srv_user_data.light_range_min);
settings_str_from_bytes(&light_lightness_srv_user_data.lightness_range,
@ -123,7 +123,7 @@ static void save_temperature_range(void)
char buf[12];
light_ctl_srv_user_data.temperature_range =
(u32_t) ((light_ctl_srv_user_data.temp_range_max << 16) |
(uint32_t) ((light_ctl_srv_user_data.temp_range_max << 16) |
light_ctl_srv_user_data.temp_range_min);
settings_str_from_bytes(&light_ctl_srv_user_data.temperature_range,
@ -162,7 +162,7 @@ static void storage_work_handler(struct os_event *work)
struct os_callout storage_work;
void save_on_flash(u8_t id)
void save_on_flash(uint8_t id)
{
storage_id = id;
os_callout_reset(&storage_work, 0);

View file

@ -37,11 +37,11 @@ enum ps_variables_id {
TEMPERATURE_RANGE
};
extern u8_t reset_counter;
extern uint8_t reset_counter;
extern struct os_callout storage_work;
int ps_settings_init(void);
void save_on_flash(u8_t id);
void save_on_flash(uint8_t id);
#endif

View file

@ -40,8 +40,8 @@ struct os_callout light_ctl_temp_work;
struct os_callout dummy_timer;
u8_t transition_type, default_tt;
u32_t *ptr_counter;
uint8_t transition_type, default_tt;
uint32_t *ptr_counter;
struct os_callout *ptr_timer = &dummy_timer;
struct transition lightness_transition, temp_transition;
@ -50,9 +50,9 @@ struct transition lightness_transition, temp_transition;
void calculate_rt(struct transition *transition)
{
u8_t steps, resolution;
s32_t duration_remainder;
s64_t now;
uint8_t steps, resolution;
int32_t duration_remainder;
int64_t now;
if (transition->just_started) {
transition->rt = transition->tt;
@ -88,7 +88,7 @@ void calculate_rt(struct transition *transition)
/* Function to calculate Remaining Time (End) */
static void bound_states_transition_type_reassignment(u8_t type)
static void bound_states_transition_type_reassignment(uint8_t type)
{
switch (type) {
case ONOFF:
@ -113,7 +113,7 @@ static void bound_states_transition_type_reassignment(u8_t type)
static void tt_values_calculator(struct transition *transition)
{
u8_t steps_multiplier, resolution;
uint8_t steps_multiplier, resolution;
resolution = (transition->tt >> 6);
steps_multiplier = (transition->tt & 0x3F);
@ -142,7 +142,7 @@ static void tt_values_calculator(struct transition *transition)
ptr_counter = &transition->counter;
}
void onoff_tt_values(struct generic_onoff_state *state, u8_t tt, u8_t delay)
void onoff_tt_values(struct generic_onoff_state *state, uint8_t tt, uint8_t delay)
{
bound_states_transition_type_reassignment(ONOFF);
calculate_lightness_target_values(ONOFF);
@ -162,7 +162,7 @@ void onoff_tt_values(struct generic_onoff_state *state, u8_t tt, u8_t delay)
state->transition->counter);
}
void level_tt_values(struct generic_level_state *state, u8_t tt, u8_t delay)
void level_tt_values(struct generic_level_state *state, uint8_t tt, uint8_t delay)
{
if (state == &gen_level_srv_root_user_data) {
bound_states_transition_type_reassignment(LEVEL);
@ -188,7 +188,7 @@ void level_tt_values(struct generic_level_state *state, u8_t tt, u8_t delay)
}
void light_lightness_actual_tt_values(struct light_lightness_state *state,
u8_t tt, u8_t delay)
uint8_t tt, uint8_t delay)
{
bound_states_transition_type_reassignment(ACTUAL);
calculate_lightness_target_values(ACTUAL);
@ -210,7 +210,7 @@ void light_lightness_actual_tt_values(struct light_lightness_state *state,
}
void light_lightness_linear_tt_values(struct light_lightness_state *state,
u8_t tt, u8_t delay)
uint8_t tt, uint8_t delay)
{
bound_states_transition_type_reassignment(LINEAR);
calculate_lightness_target_values(LINEAR);
@ -231,7 +231,7 @@ void light_lightness_linear_tt_values(struct light_lightness_state *state,
state->transition->counter);
}
void light_ctl_tt_values(struct light_ctl_state *state, u8_t tt, u8_t delay)
void light_ctl_tt_values(struct light_ctl_state *state, uint8_t tt, uint8_t delay)
{
bound_states_transition_type_reassignment(CTL);
calculate_lightness_target_values(CTL);
@ -261,7 +261,7 @@ void light_ctl_tt_values(struct light_ctl_state *state, u8_t tt, u8_t delay)
}
void light_ctl_temp_tt_values(struct light_ctl_state *state,
u8_t tt, u8_t delay)
uint8_t tt, uint8_t delay)
{
bound_states_transition_type_reassignment(CTL_TEMP);
calculate_temp_target_values(CTL_TEMP);
@ -331,7 +331,7 @@ static void onoff_work_handler(struct os_event *work)
static void level_lightness_work_handler(struct os_event *work)
{
u8_t level;
uint8_t level;
struct generic_level_state *state = &gen_level_srv_root_user_data;
switch (transition_type) {

View file

@ -42,19 +42,19 @@ enum level_transition_types {
struct transition {
bool just_started;
u8_t tt;
u8_t rt;
u8_t delay;
u32_t quo_tt;
u32_t counter;
u32_t total_duration;
s64_t start_timestamp;
uint8_t tt;
uint8_t rt;
uint8_t delay;
uint32_t quo_tt;
uint32_t counter;
uint32_t total_duration;
int64_t start_timestamp;
struct os_callout timer;
};
extern u8_t transition_type, default_tt;
extern u32_t *ptr_counter;
extern uint8_t transition_type, default_tt;
extern uint32_t *ptr_counter;
extern struct os_callout *ptr_timer;
extern struct transition lightness_transition, temp_transition;
@ -64,15 +64,15 @@ extern struct os_callout dummy_timer;
void calculate_rt(struct transition *transition);
void onoff_tt_values(struct generic_onoff_state *state, u8_t tt, u8_t delay);
void level_tt_values(struct generic_level_state *state, u8_t tt, u8_t delay);
void onoff_tt_values(struct generic_onoff_state *state, uint8_t tt, uint8_t delay);
void level_tt_values(struct generic_level_state *state, uint8_t tt, uint8_t delay);
void light_lightness_actual_tt_values(struct light_lightness_state *state,
u8_t tt, u8_t delay);
uint8_t tt, uint8_t delay);
void light_lightness_linear_tt_values(struct light_lightness_state *state,
u8_t tt, u8_t delay);
void light_ctl_tt_values(struct light_ctl_state *state, u8_t tt, u8_t delay);
uint8_t tt, uint8_t delay);
void light_ctl_tt_values(struct light_ctl_state *state, uint8_t tt, uint8_t delay);
void light_ctl_temp_tt_values(struct light_ctl_state *state,
u8_t tt, u8_t delay);
uint8_t tt, uint8_t delay);
void onoff_handler(struct generic_onoff_state *state);
void level_lightness_handler(struct generic_level_state *state);

View file

@ -44,21 +44,21 @@ void net_recv_ev(uint8_t ttl, uint8_t ctl, uint16_t src, uint16_t dst,
payload_len);
}
static void model_bound_cb(u16_t addr, struct bt_mesh_model *model,
u16_t key_idx)
static void model_bound_cb(uint16_t addr, struct bt_mesh_model *model,
uint16_t key_idx)
{
console_printf("Model bound: remote addr 0x%04x key_idx 0x%04x model %p\n",
addr, key_idx, model);
}
static void model_unbound_cb(u16_t addr, struct bt_mesh_model *model,
u16_t key_idx)
static void model_unbound_cb(uint16_t addr, struct bt_mesh_model *model,
uint16_t key_idx)
{
console_printf("Model unbound: remote addr 0x%04x key_idx 0x%04x "
"model %p\n", addr, key_idx, model);
}
static void invalid_bearer_cb(u8_t opcode)
static void invalid_bearer_cb(uint8_t opcode)
{
console_printf("Invalid bearer: opcode 0x%02x\n", opcode);
}

View file

@ -837,14 +837,6 @@ rx_stress_10_l2cap_event(struct ble_l2cap_event *event, void *arg)
MODLOG_DFLT(INFO, "Data buf %s\n", data_buf ? "OK" : "NOK");
assert(data_buf != NULL);
/* The first 2 bytes of data is the size of appended pattern data. */
rc = os_mbuf_append(data_buf, (uint8_t[]) {data_len >> 8, data_len},
2);
if (rc) {
os_mbuf_free_chain(data_buf);
assert(0);
}
/* Fill mbuf with the pattern */
stress_fill_mbuf_with_pattern(data_buf, data_len);
@ -852,8 +844,13 @@ rx_stress_10_l2cap_event(struct ble_l2cap_event *event, void *arg)
rc = ble_l2cap_send(rx_stress_ctx->chan, data_buf);
MODLOG_DFLT(INFO, "Return code=%d\n", rc);
if (rc) {
MODLOG_DFLT(INFO, "L2CAP stalled - waiting\n");
stalled = true;
if (rc == BLE_HS_ESTALLED) {
MODLOG_DFLT(INFO, "L2CAP stalled - waiting\n");
stalled = true;
} else {
MODLOG_DFLT(INFO, "Sending data via L2CAP failed with error "
"code %d\n", rc);
}
}
MODLOG_DFLT(INFO, " %d, %d\n", ++send_cnt, data_len);
@ -1365,7 +1362,7 @@ rx_stress_start(int test_num)
break;
case 10:
console_printf("Stress L2CAP send\033[0m\n");
rc = ble_l2cap_create_server(1, STRESS_COC_MTU,
rc = ble_l2cap_create_server(TEST_PSM, STRESS_COC_MTU,
rx_stress_10_l2cap_event, NULL);
assert(rc == 0);
rx_stress_simple_adv(&rx_stress_adv_sets[10]);

View file

@ -19,6 +19,8 @@
#include "stress.h"
static struct os_callout stress_timer_callout;
void
com_stress_print_report(const struct com_stress_test_ctx *test_ctxs)
{
@ -119,7 +121,7 @@ stress_fill_mbuf_with_pattern(struct os_mbuf *om, uint16_t len)
rest = len % STRESS_PAT_LEN;
for (i = 0; i < mul; ++i) {
rc = os_mbuf_append(om, &test_6_pattern[29], STRESS_PAT_LEN);
rc = os_mbuf_append(om, &test_6_pattern[0], STRESS_PAT_LEN);
if (rc) {
os_mbuf_free_chain(om);
@ -127,7 +129,7 @@ stress_fill_mbuf_with_pattern(struct os_mbuf *om, uint16_t len)
}
}
rc = os_mbuf_append(om, &test_6_pattern[29], rest);
rc = os_mbuf_append(om, &test_6_pattern[0], rest);
if (rc) {
os_mbuf_free_chain(om);
@ -176,6 +178,7 @@ void
stress_start_timer(uint32_t timeout_ms, os_event_fn *ev_cb)
{
int rc;
os_callout_stop(&stress_timer_callout);
os_callout_init(&stress_timer_callout, os_eventq_dflt_get(), ev_cb, NULL);

View file

@ -44,8 +44,9 @@ extern "C" {
#define STRESS_FIND_SRV 1
#define STRESS_FIND_CHR 2
#define STRESS_FIND_DSC 3
/* L2CAP PSM */
#define TEST_PSM 0x80
struct os_callout stress_timer_callout;
struct stress_gatt_search_ctx;
typedef void stress_gatt_disc_end_fn(struct stress_gatt_search_ctx *search_ctx);

View file

@ -1127,7 +1127,7 @@ tx_stress_10_gap_event(struct ble_gap_event *event, void *arg)
assert(sdu_rx != NULL);
tx_stress_ctx->conn_handle = event->connect.conn_handle;
rc = ble_l2cap_connect(event->connect.conn_handle, 1,
rc = ble_l2cap_connect(event->connect.conn_handle, TEST_PSM,
STRESS_COC_MTU, sdu_rx,
tx_stress_10_l2cap_event, NULL);
assert(rc == 0);
@ -1292,17 +1292,16 @@ tx_stress_14_subs_cb(uint16_t conn_handle, const struct ble_gatt_error *error,
assert(error->status == 0);
/* If the first subscription after finding cccd */
if(arg == NULL) {
if (arg == NULL) {
return 0;
}
sub = (bool*)arg;
sub = (bool *)arg;
/* Enable notifications */
if(*sub == 0) {
if (*sub == 0) {
*sub = true;
om = ble_hs_mbuf_from_flat(
(uint8_t[]) {0x01, 0x00}, 2);
om = ble_hs_mbuf_from_flat((uint8_t[]) {0x01, 0x00}, 2);
tx_stress_ctx->begin_us = tx_stress_ctx->end_us;
@ -1415,7 +1414,7 @@ tx_stress_14_gap_event(struct ble_gap_event *event, void *arg)
static int
tx_stress_15_write_cb(uint16_t conn_handle, const struct ble_gatt_error *error,
struct ble_gatt_attr *attr, void *arg)
struct ble_gatt_attr *attr, void *arg)
{
/* Disconnect */
ble_gap_terminate(conn_handle, BLE_ERR_REM_USER_CONN_TERM);
@ -1464,7 +1463,7 @@ tx_stress_15_gap_event(struct ble_gap_event *event, void *arg)
case BLE_GAP_EVENT_DISCONNECT:
/* Perform use case specified number of times */
if(tx_stress_ctx->con_stat[15].num >= MYNEWT_VAL(BLE_STRESS_REPEAT)) {
if (tx_stress_ctx->con_stat[15].num >= MYNEWT_VAL(BLE_STRESS_REPEAT)) {
tx_stress_on_test_finish(15);
return 0;
}
@ -1473,7 +1472,7 @@ tx_stress_15_gap_event(struct ble_gap_event *event, void *arg)
return 0;
default:
MODLOG_DFLT(INFO, "Other event occurs=%d\n", event->type);
MODLOG_DFLT(INFO, "Other event occurs=%d\n", event->type);
return 0;
}
}
@ -1607,7 +1606,8 @@ tx_stress_test_perform(int test_num)
}
static void
tx_stress_read_command_cb(void) {
tx_stress_read_command_cb(void)
{
console_printf("Start testing\n");
os_sem_release(&tx_stress_main_sem);
}
@ -1642,7 +1642,7 @@ tx_stress_main_task_fn(void *arg)
/* Wait for the scan to find the test. Then 1 token will be
* released allowing to pass through semaphore. */
os_sem_pend(&tx_stress_main_sem, OS_TIMEOUT_NEVER);
if(tx_stress_ctx->scan_timeout) {
if (tx_stress_ctx->scan_timeout) {
break;
}

View file

@ -2691,15 +2691,28 @@ cmd_security_unpair(int argc, char **argv)
{
ble_addr_t peer;
int rc;
int oldest;
rc = parse_arg_all(argc - 1, argv + 1);
if (rc != 0) {
return rc;
}
rc = parse_arg_bool_dflt("oldest", 0, &oldest);
if (rc != 0) {
console_printf("invalid 'oldest' parameter\n");
return rc;
}
if (oldest) {
rc = ble_gap_unpair_oldest_peer();
console_printf("Unpair oldest status: 0x%02x\n", rc);
return 0;
}
rc = parse_dev_addr("peer_", cmd_peer_addr_types, &peer);
if (rc != 0) {
console_printf("invalid 'peer_addr' parameter\n");
console_printf("invalid peer address\n");
return rc;
}
@ -2714,6 +2727,7 @@ cmd_security_unpair(int argc, char **argv)
#if MYNEWT_VAL(SHELL_CMD_HELP)
static const struct shell_param security_unpair_params[] = {
{"oldest", "usage: =[true|false], default: false"},
{"peer_addr_type", "usage: =[public|random|public_id|random_id], default: public"},
{"peer_addr", "usage: =[XX:XX:XX:XX:XX:XX]"},
{NULL, NULL}

View file

@ -37,7 +37,7 @@ pkg.deps:
- "@apache-mynewt-nimble/nimble/host/services/gap"
- "@apache-mynewt-nimble/nimble/host/services/gatt"
- "@apache-mynewt-nimble/nimble/host/services/dis"
- "@apache-mynewt-nimble/nimble/host/store/ram"
- "@apache-mynewt-nimble/nimble/host/store/config"
- "@apache-mynewt-nimble/nimble/transport/ram"
- "@apache-mynewt-core/hw/drivers/uart"
- "@apache-mynewt-core/hw/drivers/rtt"

View file

@ -44,16 +44,16 @@ static struct os_event bttester_ev[CMD_QUEUED];
struct btp_buf {
struct os_event *ev;
union {
u8_t data[BTP_MTU];
uint8_t data[BTP_MTU];
struct btp_hdr hdr;
};
};
static struct btp_buf cmd_buf[CMD_QUEUED];
static void supported_commands(u8_t *data, u16_t len)
static void supported_commands(uint8_t *data, uint16_t len)
{
u8_t buf[1];
uint8_t buf[1];
struct core_read_supported_commands_rp *rp = (void *) buf;
memset(buf, 0, sizeof(buf));
@ -64,12 +64,12 @@ static void supported_commands(u8_t *data, u16_t len)
tester_set_bit(buf, CORE_UNREGISTER_SERVICE);
tester_send(BTP_SERVICE_ID_CORE, CORE_READ_SUPPORTED_COMMANDS,
BTP_INDEX_NONE, (u8_t *) rp, sizeof(buf));
BTP_INDEX_NONE, (uint8_t *) rp, sizeof(buf));
}
static void supported_services(u8_t *data, u16_t len)
static void supported_services(uint8_t *data, uint16_t len)
{
u8_t buf[1];
uint8_t buf[1];
struct core_read_supported_services_rp *rp = (void *) buf;
memset(buf, 0, sizeof(buf));
@ -85,13 +85,13 @@ static void supported_services(u8_t *data, u16_t len)
#endif /* MYNEWT_VAL(BLE_MESH) */
tester_send(BTP_SERVICE_ID_CORE, CORE_READ_SUPPORTED_SERVICES,
BTP_INDEX_NONE, (u8_t *) rp, sizeof(buf));
BTP_INDEX_NONE, (uint8_t *) rp, sizeof(buf));
}
static void register_service(u8_t *data, u16_t len)
static void register_service(uint8_t *data, uint16_t len)
{
struct core_register_service_cmd *cmd = (void *) data;
u8_t status;
uint8_t status;
switch (cmd->id) {
case BTP_SERVICE_ID_GAP:
@ -124,10 +124,10 @@ rsp:
status);
}
static void unregister_service(u8_t *data, u16_t len)
static void unregister_service(uint8_t *data, uint16_t len)
{
struct core_unregister_service_cmd *cmd = (void *) data;
u8_t status;
uint8_t status;
switch (cmd->id) {
case BTP_SERVICE_ID_GAP:
@ -155,8 +155,8 @@ static void unregister_service(u8_t *data, u16_t len)
status);
}
static void handle_core(u8_t opcode, u8_t index, u8_t *data,
u16_t len)
static void handle_core(uint8_t opcode, uint8_t index, uint8_t *data,
uint16_t len)
{
if (index != BTP_INDEX_NONE) {
tester_rsp(BTP_SERVICE_ID_CORE, opcode, index,
@ -186,7 +186,7 @@ static void handle_core(u8_t opcode, u8_t index, u8_t *data,
static void cmd_handler(struct os_event *ev)
{
u16_t len;
uint16_t len;
struct btp_buf *cmd;
if (!ev || !ev->ev_arg) {
@ -241,12 +241,12 @@ static void cmd_handler(struct os_event *ev)
os_eventq_put(&avail_queue, ev);
}
static u8_t *recv_cb(u8_t *buf, size_t *off)
static uint8_t *recv_cb(uint8_t *buf, size_t *off)
{
struct btp_hdr *cmd = (void *) buf;
struct os_event *new_ev;
struct btp_buf *new_buf, *old_buf;
u16_t len;
uint16_t len;
if (*off < sizeof(*cmd)) {
return buf;
@ -319,7 +319,7 @@ void tester_init(void)
NULL, 0);
}
void tester_send(u8_t service, u8_t opcode, u8_t index, u8_t *data,
void tester_send(uint8_t service, uint8_t opcode, uint8_t index, uint8_t *data,
size_t len)
{
struct btp_hdr msg;
@ -329,7 +329,7 @@ void tester_send(u8_t service, u8_t opcode, u8_t index, u8_t *data,
msg.index = index;
msg.len = len;
bttester_pipe_send((u8_t *)&msg, sizeof(msg));
bttester_pipe_send((uint8_t *)&msg, sizeof(msg));
if (data && len) {
bttester_pipe_send(data, len);
}
@ -344,7 +344,7 @@ void tester_send(u8_t service, u8_t opcode, u8_t index, u8_t *data,
}
}
void tester_send_buf(u8_t service, u8_t opcode, u8_t index,
void tester_send_buf(uint8_t service, uint8_t opcode, uint8_t index,
struct os_mbuf *data)
{
struct btp_hdr msg;
@ -354,13 +354,13 @@ void tester_send_buf(u8_t service, u8_t opcode, u8_t index,
msg.index = index;
msg.len = os_mbuf_len(data);
bttester_pipe_send((u8_t *)&msg, sizeof(msg));
bttester_pipe_send((uint8_t *)&msg, sizeof(msg));
if (data && msg.len) {
bttester_pipe_send_buf(data);
}
}
void tester_rsp(u8_t service, u8_t opcode, u8_t index, u8_t status)
void tester_rsp(uint8_t service, uint8_t opcode, uint8_t index, uint8_t status)
{
struct btp_status s;
@ -370,5 +370,5 @@ void tester_rsp(u8_t service, u8_t opcode, u8_t index, u8_t status)
}
s.code = status;
tester_send(service, BTP_STATUS, index, (u8_t *) &s, sizeof(s));
tester_send(service, BTP_STATUS, index, (uint8_t *) &s, sizeof(s));
}

File diff suppressed because it is too large Load diff

View file

@ -27,9 +27,9 @@
extern "C" {
#endif
typedef u8_t *(*bttester_pipe_recv_cb)(u8_t *buf, size_t *off);
void bttester_pipe_register(u8_t *buf, size_t len, bttester_pipe_recv_cb cb);
int bttester_pipe_send(const u8_t *data, int len);
typedef uint8_t *(*bttester_pipe_recv_cb)(uint8_t *buf, size_t *off);
void bttester_pipe_register(uint8_t *buf, size_t len, bttester_pipe_recv_cb cb);
int bttester_pipe_send(const uint8_t *data, int len);
int bttester_pipe_send_buf(struct os_mbuf *buf);
int bttester_pipe_init(void);

View file

@ -51,7 +51,7 @@ static struct ble_sm_sc_oob_data oob_data_local;
static struct ble_sm_sc_oob_data oob_data_remote;
static uint16_t current_settings;
u8_t own_addr_type;
uint8_t own_addr_type;
static ble_addr_t peer_id_addr;
static ble_addr_t peer_ota_addr;
static bool encrypted = false;
@ -109,9 +109,9 @@ static int gap_conn_find_by_addr(const ble_addr_t *dev_addr,
static int gap_event_cb(struct ble_gap_event *event, void *arg);
static void supported_commands(u8_t *data, u16_t len)
static void supported_commands(uint8_t *data, uint16_t len)
{
u8_t cmds[3];
uint8_t cmds[3];
struct gap_read_supported_commands_rp *rp = (void *) &cmds;
SYS_LOG_DBG("");
@ -143,13 +143,13 @@ static void supported_commands(u8_t *data, u16_t len)
tester_set_bit(cmds, GAP_SET_MITM);
tester_send(BTP_SERVICE_ID_GAP, GAP_READ_SUPPORTED_COMMANDS,
CONTROLLER_INDEX, (u8_t *) rp, sizeof(cmds));
CONTROLLER_INDEX, (uint8_t *) rp, sizeof(cmds));
}
static void controller_index_list(u8_t *data, u16_t len)
static void controller_index_list(uint8_t *data, uint16_t len)
{
struct gap_read_controller_index_list_rp *rp;
u8_t buf[sizeof(*rp) + 1];
uint8_t buf[sizeof(*rp) + 1];
SYS_LOG_DBG("");
@ -159,7 +159,7 @@ static void controller_index_list(u8_t *data, u16_t len)
rp->index[0] = CONTROLLER_INDEX;
tester_send(BTP_SERVICE_ID_GAP, GAP_READ_CONTROLLER_INDEX_LIST,
BTP_INDEX_NONE, (u8_t *) rp, sizeof(buf));
BTP_INDEX_NONE, (uint8_t *) rp, sizeof(buf));
}
static int check_pub_addr_unassigned(void)
@ -174,10 +174,10 @@ static int check_pub_addr_unassigned(void)
#endif
}
static void controller_info(u8_t *data, u16_t len)
static void controller_info(uint8_t *data, uint16_t len)
{
struct gap_read_controller_info_rp rp;
u32_t supported_settings = 0;
uint32_t supported_settings = 0;
ble_addr_t addr;
int rc;
@ -240,7 +240,7 @@ static void controller_info(u8_t *data, u16_t len)
memcpy(rp.name, CONTROLLER_NAME, sizeof(CONTROLLER_NAME));
tester_send(BTP_SERVICE_ID_GAP, GAP_READ_CONTROLLER_INFO,
CONTROLLER_INDEX, (u8_t *) &rp, sizeof(rp));
CONTROLLER_INDEX, (uint8_t *) &rp, sizeof(rp));
}
static struct ble_gap_adv_params adv_params = {
@ -248,7 +248,7 @@ static struct ble_gap_adv_params adv_params = {
.disc_mode = BLE_GAP_DISC_MODE_NON,
};
static void set_connectable(u8_t *data, u16_t len)
static void set_connectable(uint8_t *data, uint16_t len)
{
const struct gap_set_connectable_cmd *cmd = (void *) data;
struct gap_set_connectable_rp rp;
@ -266,12 +266,12 @@ static void set_connectable(u8_t *data, u16_t len)
rp.current_settings = sys_cpu_to_le32(current_settings);
tester_send(BTP_SERVICE_ID_GAP, GAP_SET_CONNECTABLE, CONTROLLER_INDEX,
(u8_t *) &rp, sizeof(rp));
(uint8_t *) &rp, sizeof(rp));
}
static u8_t ad_flags = BLE_HS_ADV_F_BREDR_UNSUP;
static uint8_t ad_flags = BLE_HS_ADV_F_BREDR_UNSUP;
static void set_discoverable(u8_t *data, u16_t len)
static void set_discoverable(uint8_t *data, uint16_t len)
{
const struct gap_set_discoverable_cmd *cmd = (void *) data;
struct gap_set_discoverable_rp rp;
@ -305,10 +305,10 @@ static void set_discoverable(u8_t *data, u16_t len)
rp.current_settings = sys_cpu_to_le32(current_settings);
tester_send(BTP_SERVICE_ID_GAP, GAP_SET_DISCOVERABLE, CONTROLLER_INDEX,
(u8_t *) &rp, sizeof(rp));
(uint8_t *) &rp, sizeof(rp));
}
static void set_bondable(const u8_t *data, u16_t len)
static void set_bondable(const uint8_t *data, uint16_t len)
{
const struct gap_set_bondable_cmd *cmd = (void *) data;
struct gap_set_bondable_rp rp;
@ -325,7 +325,7 @@ static void set_bondable(const u8_t *data, u16_t len)
rp.current_settings = sys_cpu_to_le32(current_settings);
tester_send(BTP_SERVICE_ID_GAP, GAP_SET_BONDABLE, CONTROLLER_INDEX,
(u8_t *) &rp, sizeof(rp));
(uint8_t *) &rp, sizeof(rp));
}
static struct bt_data ad[10] = {
@ -334,7 +334,7 @@ static struct bt_data ad[10] = {
static struct bt_data sd[10];
static int set_ad(const struct bt_data *ad, size_t ad_len,
u8_t *buf, u8_t *buf_len)
uint8_t *buf, uint8_t *buf_len)
{
int i;
@ -350,14 +350,14 @@ static int set_ad(const struct bt_data *ad, size_t ad_len,
return 0;
}
static void start_advertising(const u8_t *data, u16_t len)
static void start_advertising(const uint8_t *data, uint16_t len)
{
const struct gap_start_advertising_cmd *cmd = (void *) data;
struct gap_start_advertising_rp rp;
int32_t duration_ms = BLE_HS_FOREVER;
uint8_t buf[BLE_HS_ADV_MAX_SZ];
uint8_t buf_len = 0;
u8_t adv_len, sd_len;
uint8_t adv_len, sd_len;
int err;
int i;
@ -429,14 +429,14 @@ static void start_advertising(const u8_t *data, u16_t len)
rp.current_settings = sys_cpu_to_le32(current_settings);
tester_send(BTP_SERVICE_ID_GAP, GAP_START_ADVERTISING, CONTROLLER_INDEX,
(u8_t *) &rp, sizeof(rp));
(uint8_t *) &rp, sizeof(rp));
return;
fail:
tester_rsp(BTP_SERVICE_ID_GAP, GAP_START_ADVERTISING, CONTROLLER_INDEX,
BTP_STATUS_FAILED);
}
static void stop_advertising(const u8_t *data, u16_t len)
static void stop_advertising(const uint8_t *data, uint16_t len)
{
struct gap_stop_advertising_rp rp;
@ -452,12 +452,12 @@ static void stop_advertising(const u8_t *data, u16_t len)
rp.current_settings = sys_cpu_to_le32(current_settings);
tester_send(BTP_SERVICE_ID_GAP, GAP_STOP_ADVERTISING, CONTROLLER_INDEX,
(u8_t *) &rp, sizeof(rp));
(uint8_t *) &rp, sizeof(rp));
}
static u8_t get_ad_flags(const u8_t *data, u8_t data_len)
static uint8_t get_ad_flags(const uint8_t *data, uint8_t data_len)
{
u8_t len, i;
uint8_t len, i;
/* Parse advertisement to get flags */
for (i = 0; i < data_len; i += len - 1) {
@ -482,11 +482,11 @@ static u8_t get_ad_flags(const u8_t *data, u8_t data_len)
return 0;
}
static u8_t discovery_flags;
static uint8_t discovery_flags;
static struct os_mbuf *adv_buf;
static void store_adv(const ble_addr_t *addr, s8_t rssi,
const u8_t *data, u8_t len)
static void store_adv(const ble_addr_t *addr, int8_t rssi,
const uint8_t *data, uint8_t len)
{
struct gap_device_found_ev *ev;
@ -503,8 +503,8 @@ static void store_adv(const ble_addr_t *addr, s8_t rssi,
memcpy(net_buf_simple_add(adv_buf, len), data, len);
}
static void device_found(ble_addr_t *addr, s8_t rssi, u8_t evtype,
const u8_t *data, u8_t len)
static void device_found(ble_addr_t *addr, int8_t rssi, uint8_t evtype,
const uint8_t *data, uint8_t len)
{
struct gap_device_found_ev *ev;
ble_addr_t a;
@ -512,7 +512,7 @@ static void device_found(ble_addr_t *addr, s8_t rssi, u8_t evtype,
/* if General/Limited Discovery - parse Advertising data to get flags */
if (!(discovery_flags & GAP_DISCOVERY_FLAG_LE_OBSERVE) &&
(evtype != BLE_HCI_ADV_RPT_EVTYPE_SCAN_RSP)) {
u8_t flags = get_ad_flags(data, len);
uint8_t flags = get_ad_flags(data, len);
/* ignore non-discoverable devices */
if (!(flags & BLE_AD_DISCOV_MASK)) {
@ -593,11 +593,11 @@ static int discovery_cb(struct ble_gap_event *event, void *arg)
return 0;
}
static void start_discovery(const u8_t *data, u16_t len)
static void start_discovery(const uint8_t *data, uint16_t len)
{
const struct gap_start_discovery_cmd *cmd = (void *) data;
struct ble_gap_disc_params params = {0};
u8_t status;
uint8_t status;
SYS_LOG_DBG("");
@ -626,9 +626,9 @@ reply:
status);
}
static void stop_discovery(const u8_t *data, u16_t len)
static void stop_discovery(const uint8_t *data, uint16_t len)
{
u8_t status = BTP_STATUS_SUCCESS;
uint8_t status = BTP_STATUS_SUCCESS;
SYS_LOG_DBG("");
@ -680,13 +680,13 @@ static void device_connected_ev_send(struct os_event *ev)
}
tester_send(BTP_SERVICE_ID_GAP, GAP_EV_DEVICE_CONNECTED,
CONTROLLER_INDEX, (u8_t *) &connected_ev,
CONTROLLER_INDEX, (uint8_t *) &connected_ev,
sizeof(connected_ev));
periph_privacy(desc);
}
static void le_connected(u16_t conn_handle, int status)
static void le_connected(uint16_t conn_handle, int status)
{
struct ble_gap_conn_desc desc;
ble_addr_t *addr;
@ -720,7 +720,7 @@ static void le_connected(u16_t conn_handle, int status)
CONNECTED_EV_DELAY_MS(desc.conn_itvl)));
#else
tester_send(BTP_SERVICE_ID_GAP, GAP_EV_DEVICE_CONNECTED,
CONTROLLER_INDEX, (u8_t *) &connected_ev,
CONTROLLER_INDEX, (uint8_t *) &connected_ev,
sizeof(connected_ev));
#endif
}
@ -763,10 +763,10 @@ static void le_disconnected(struct ble_gap_conn_desc *conn, int reason)
ev.address_type = addr->type;
tester_send(BTP_SERVICE_ID_GAP, GAP_EV_DEVICE_DISCONNECTED,
CONTROLLER_INDEX, (u8_t *) &ev, sizeof(ev));
CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev));
}
static void auth_passkey_oob(u16_t conn_handle)
static void auth_passkey_oob(uint16_t conn_handle)
{
struct ble_gap_conn_desc desc;
struct ble_sm_io pk;
@ -786,7 +786,7 @@ static void auth_passkey_oob(u16_t conn_handle)
assert(rc == 0);
}
static void auth_passkey_display(u16_t conn_handle, unsigned int passkey)
static void auth_passkey_display(uint16_t conn_handle, unsigned int passkey)
{
struct ble_gap_conn_desc desc;
struct gap_passkey_display_ev ev;
@ -817,10 +817,10 @@ static void auth_passkey_display(u16_t conn_handle, unsigned int passkey)
ev.passkey = sys_cpu_to_le32(pk.passkey);
tester_send(BTP_SERVICE_ID_GAP, GAP_EV_PASSKEY_DISPLAY,
CONTROLLER_INDEX, (u8_t *) &ev, sizeof(ev));
CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev));
}
static void auth_passkey_entry(u16_t conn_handle)
static void auth_passkey_entry(uint16_t conn_handle)
{
struct ble_gap_conn_desc desc;
struct gap_passkey_entry_req_ev ev;
@ -840,10 +840,10 @@ static void auth_passkey_entry(u16_t conn_handle)
ev.address_type = addr->type;
tester_send(BTP_SERVICE_ID_GAP, GAP_EV_PASSKEY_ENTRY_REQ,
CONTROLLER_INDEX, (u8_t *) &ev, sizeof(ev));
CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev));
}
static void auth_passkey_numcmp(u16_t conn_handle, unsigned int passkey)
static void auth_passkey_numcmp(uint16_t conn_handle, unsigned int passkey)
{
struct ble_gap_conn_desc desc;
struct gap_passkey_confirm_req_ev ev;
@ -864,10 +864,10 @@ static void auth_passkey_numcmp(u16_t conn_handle, unsigned int passkey)
ev.passkey = sys_cpu_to_le32(passkey);
tester_send(BTP_SERVICE_ID_GAP, GAP_EV_PASSKEY_CONFIRM_REQ,
CONTROLLER_INDEX, (u8_t *) &ev, sizeof(ev));
CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev));
}
static void auth_passkey_oob_sc(u16_t conn_handle)
static void auth_passkey_oob_sc(uint16_t conn_handle)
{
int rc;
struct ble_sm_io pk;
@ -889,7 +889,7 @@ static void auth_passkey_oob_sc(u16_t conn_handle)
}
}
static void le_passkey_action(u16_t conn_handle,
static void le_passkey_action(uint16_t conn_handle,
struct ble_gap_passkey_params *params)
{
SYS_LOG_DBG("");
@ -917,7 +917,7 @@ static void le_passkey_action(u16_t conn_handle,
}
}
static void le_identity_resolved(u16_t conn_handle)
static void le_identity_resolved(uint16_t conn_handle)
{
struct ble_gap_conn_desc desc;
struct gap_identity_resolved_ev ev;
@ -941,7 +941,7 @@ static void le_identity_resolved(u16_t conn_handle)
sizeof(ev.identity_address));
tester_send(BTP_SERVICE_ID_GAP, GAP_EV_IDENTITY_RESOLVED,
CONTROLLER_INDEX, (u8_t *) &ev, sizeof(ev));
CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev));
}
static void le_conn_param_update(struct ble_gap_conn_desc *desc)
@ -958,7 +958,7 @@ static void le_conn_param_update(struct ble_gap_conn_desc *desc)
ev.supervision_timeout = desc->supervision_timeout;
tester_send(BTP_SERVICE_ID_GAP, GAP_EV_CONN_PARAM_UPDATE,
CONTROLLER_INDEX, (u8_t *) &ev, sizeof(ev));
CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev));
}
static void le_encryption_changed(struct ble_gap_conn_desc *desc)
@ -986,7 +986,7 @@ static void le_encryption_changed(struct ble_gap_conn_desc *desc)
}
tester_send(BTP_SERVICE_ID_GAP, GAP_EV_SEC_LEVEL_CHANGED,
CONTROLLER_INDEX, (u8_t *) &ev, sizeof(ev));
CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev));
}
static void print_bytes(const uint8_t *bytes, int len)
@ -1055,7 +1055,7 @@ static void adv_complete(void)
ev.current_settings = sys_cpu_to_le32(current_settings);
tester_send(BTP_SERVICE_ID_GAP, GAP_EV_NEW_SETTINGS, CONTROLLER_INDEX,
(u8_t *) &ev, sizeof(ev));
(uint8_t *) &ev, sizeof(ev));
}
static int gap_event_cb(struct ble_gap_event *event, void *arg)
@ -1197,9 +1197,9 @@ static int gap_event_cb(struct ble_gap_event *event, void *arg)
return 0;
}
static void connect(const u8_t *data, u16_t len)
static void connect(const uint8_t *data, uint16_t len)
{
u8_t status = BTP_STATUS_SUCCESS;
uint8_t status = BTP_STATUS_SUCCESS;
SYS_LOG_DBG("");
@ -1211,10 +1211,10 @@ static void connect(const u8_t *data, u16_t len)
tester_rsp(BTP_SERVICE_ID_GAP, GAP_CONNECT, CONTROLLER_INDEX, status);
}
static void disconnect(const u8_t *data, u16_t len)
static void disconnect(const uint8_t *data, uint16_t len)
{
struct ble_gap_conn_desc desc;
u8_t status;
uint8_t status;
int rc;
SYS_LOG_DBG("");
@ -1236,10 +1236,10 @@ rsp:
status);
}
static void set_io_cap(const u8_t *data, u16_t len)
static void set_io_cap(const uint8_t *data, uint16_t len)
{
const struct gap_set_io_cap_cmd *cmd = (void *) data;
u8_t status;
uint8_t status;
SYS_LOG_DBG("");
@ -1276,10 +1276,10 @@ rsp:
status);
}
static void pair(const u8_t *data, u16_t len)
static void pair(const uint8_t *data, uint16_t len)
{
struct ble_gap_conn_desc desc;
u8_t status;
uint8_t status;
int rc;
SYS_LOG_DBG("");
@ -1301,9 +1301,9 @@ rsp:
tester_rsp(BTP_SERVICE_ID_GAP, GAP_PAIR, CONTROLLER_INDEX, status);
}
static void unpair(const u8_t *data, u16_t len)
static void unpair(const uint8_t *data, uint16_t len)
{
u8_t status;
uint8_t status;
int err;
SYS_LOG_DBG("");
@ -1313,12 +1313,12 @@ static void unpair(const u8_t *data, u16_t len)
tester_rsp(BTP_SERVICE_ID_GAP, GAP_UNPAIR, CONTROLLER_INDEX, status);
}
static void passkey_entry(const u8_t *data, u16_t len)
static void passkey_entry(const uint8_t *data, uint16_t len)
{
const struct gap_passkey_entry_cmd *cmd = (void *) data;
struct ble_gap_conn_desc desc;
struct ble_sm_io pk;
u8_t status;
uint8_t status;
int rc;
SYS_LOG_DBG("");
@ -1345,12 +1345,12 @@ rsp:
status);
}
static void passkey_confirm(const u8_t *data, u16_t len)
static void passkey_confirm(const uint8_t *data, uint16_t len)
{
const struct gap_passkey_confirm_cmd *cmd = (void *) data;
struct ble_gap_conn_desc desc;
struct ble_sm_io pk;
u8_t status;
uint8_t status;
int rc;
SYS_LOG_DBG("");
@ -1378,7 +1378,7 @@ rsp:
status);
}
static void start_direct_adv(const u8_t *data, u16_t len)
static void start_direct_adv(const uint8_t *data, uint16_t len)
{
const struct gap_start_direct_adv_cmd *cmd = (void *) data;
struct gap_start_advertising_rp rp;
@ -1403,7 +1403,7 @@ static void start_direct_adv(const u8_t *data, u16_t len)
rp.current_settings = sys_cpu_to_le32(current_settings);
tester_send(BTP_SERVICE_ID_GAP, GAP_START_DIRECT_ADV, CONTROLLER_INDEX,
(u8_t *) &rp, sizeof(rp));
(uint8_t *) &rp, sizeof(rp));
return;
fail:
tester_rsp(BTP_SERVICE_ID_GAP, GAP_START_DIRECT_ADV, CONTROLLER_INDEX,
@ -1416,7 +1416,7 @@ static void conn_param_update_cb(uint16_t conn_handle, int status, void *arg)
conn_handle, status);
}
static int conn_param_update_slave(u16_t conn_handle,
static int conn_param_update_slave(uint16_t conn_handle,
const struct gap_conn_param_update_cmd *cmd)
{
int rc;
@ -1436,7 +1436,7 @@ static int conn_param_update_slave(u16_t conn_handle,
return 0;
}
static int conn_param_update_master(u16_t conn_handle,
static int conn_param_update_master(uint16_t conn_handle,
const struct gap_conn_param_update_cmd *cmd)
{
int rc;
@ -1489,7 +1489,7 @@ rsp:
SYS_LOG_ERR("Conn param update fail; rc=%d", rc);
}
static void conn_param_update_async(const u8_t *data, u16_t len)
static void conn_param_update_async(const uint8_t *data, uint16_t len)
{
const struct gap_conn_param_update_cmd *cmd = (void *) data;
update_params = *cmd;
@ -1500,7 +1500,7 @@ static void conn_param_update_async(const u8_t *data, u16_t len)
BTP_STATUS_SUCCESS);
}
static void oob_legacy_set_data(const u8_t *data, u16_t len)
static void oob_legacy_set_data(const uint8_t *data, uint16_t len)
{
const struct gap_oob_legacy_set_data_cmd *cmd = (void *) data;
@ -1511,7 +1511,7 @@ static void oob_legacy_set_data(const u8_t *data, u16_t len)
CONTROLLER_INDEX, BTP_STATUS_SUCCESS);
}
static void oob_sc_get_local_data(const u8_t *data, u16_t len)
static void oob_sc_get_local_data(const uint8_t *data, uint16_t len)
{
struct gap_oob_sc_get_local_data_rp rp;
@ -1519,10 +1519,10 @@ static void oob_sc_get_local_data(const u8_t *data, u16_t len)
memcpy(rp.c, oob_data_local.c, 16);
tester_send(BTP_SERVICE_ID_GAP, GAP_OOB_SC_GET_LOCAL_DATA,
CONTROLLER_INDEX, (u8_t *) &rp, sizeof(rp));
CONTROLLER_INDEX, (uint8_t *) &rp, sizeof(rp));
}
static void oob_sc_set_remote_data(const u8_t *data, u16_t len)
static void oob_sc_set_remote_data(const uint8_t *data, uint16_t len)
{
const struct gap_oob_sc_set_remote_data_cmd *cmd = (void *) data;
@ -1534,7 +1534,7 @@ static void oob_sc_set_remote_data(const u8_t *data, u16_t len)
CONTROLLER_INDEX, BTP_STATUS_SUCCESS);
}
static void set_mitm(const u8_t *data, u16_t len)
static void set_mitm(const uint8_t *data, uint16_t len)
{
const struct gap_set_mitm_cmd *cmd = (void *) data;
@ -1544,8 +1544,8 @@ static void set_mitm(const u8_t *data, u16_t len)
CONTROLLER_INDEX, BTP_STATUS_SUCCESS);
}
void tester_handle_gap(u8_t opcode, u8_t index, u8_t *data,
u16_t len)
void tester_handle_gap(uint8_t opcode, uint8_t index, uint8_t *data,
uint16_t len)
{
switch (opcode) {
case GAP_READ_SUPPORTED_COMMANDS:
@ -1664,7 +1664,7 @@ static void tester_init_gap_cb(int err)
BTP_STATUS_SUCCESS);
}
u8_t tester_init_gap(void)
uint8_t tester_init_gap(void)
{
#if MYNEWT_VAL(BLE_SM_SC)
int rc;
@ -1682,7 +1682,7 @@ u8_t tester_init_gap(void)
return BTP_STATUS_SUCCESS;
}
u8_t tester_unregister_gap(void)
uint8_t tester_unregister_gap(void)
{
return BTP_STATUS_SUCCESS;
}

View file

@ -76,8 +76,8 @@
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;
static u8_t notify_state;
static u8_t indicate_state;
static uint8_t notify_state;
static uint8_t indicate_state;
static uint16_t myconn_handle;
static struct os_callout notify_tx_timer;
uint16_t notify_handle;
@ -253,7 +253,7 @@ static const struct ble_gatt_svc_def gatt_svr_svcs[] = {
},
};
static void attr_value_changed_ev(u16_t handle, struct os_mbuf *data)
static void attr_value_changed_ev(uint16_t handle, struct os_mbuf *data)
{
struct gatt_attr_value_changed_ev *ev;
struct os_mbuf *buf = os_msys_get(0, 0);
@ -569,7 +569,7 @@ gatt_svr_rel_write_test(uint16_t conn_handle, uint16_t attr_handle,
}
}
static void start_server(u8_t *data, u16_t len)
static void start_server(uint8_t *data, uint16_t len)
{
struct gatt_start_server_rp rp;
@ -583,14 +583,14 @@ static void start_server(u8_t *data, u16_t len)
rp.db_attr_cnt = 0;
tester_send(BTP_SERVICE_ID_GATT, GATT_START_SERVER, CONTROLLER_INDEX,
(u8_t *) &rp, sizeof(rp));
(uint8_t *) &rp, sizeof(rp));
}
/* Convert UUID from BTP command to bt_uuid */
static u8_t btp2bt_uuid(const u8_t *uuid, u8_t len,
static uint8_t btp2bt_uuid(const uint8_t *uuid, uint8_t len,
ble_uuid_any_t *bt_uuid)
{
u16_t le16;
uint16_t le16;
switch (len) {
case 0x02: /* UUID 16 */
@ -614,8 +614,8 @@ static u8_t btp2bt_uuid(const u8_t *uuid, u8_t len,
* It is not intended to be used by client and server at the same time.
*/
static struct {
u16_t len;
u8_t buf[MAX_BUFFER_SIZE];
uint16_t len;
uint8_t buf[MAX_BUFFER_SIZE];
} gatt_buf;
static void *gatt_buf_add(const void *data, size_t len)
@ -665,7 +665,7 @@ static int read_cb(uint16_t conn_handle,
void *arg)
{
struct gatt_read_rp *rp = (void *) gatt_buf.buf;
u8_t btp_opcode = (uint8_t) (int) arg;
uint8_t btp_opcode = (uint8_t) (int) arg;
SYS_LOG_DBG("status=%d", error->status);
@ -692,7 +692,7 @@ static int read_cb(uint16_t conn_handle,
return 0;
}
static void read(u8_t *data, u16_t len)
static void read(uint8_t *data, uint16_t len)
{
const struct gatt_read_cmd *cmd = (void *) data;
struct ble_gap_conn_desc conn;
@ -731,7 +731,7 @@ static int read_long_cb(uint16_t conn_handle,
void *arg)
{
struct gatt_read_rp *rp = (void *) gatt_buf.buf;
u8_t btp_opcode = (uint8_t) (int) arg;
uint8_t btp_opcode = (uint8_t) (int) arg;
SYS_LOG_DBG("status=%d", error->status);
@ -762,7 +762,7 @@ static int read_long_cb(uint16_t conn_handle,
return 0;
}
static void read_long(u8_t *data, u16_t len)
static void read_long(uint8_t *data, uint16_t len)
{
const struct gatt_read_long_cmd *cmd = (void *) data;
struct ble_gap_conn_desc conn;
@ -797,10 +797,10 @@ fail:
BTP_STATUS_FAILED);
}
static void read_multiple(u8_t *data, u16_t len)
static void read_multiple(uint8_t *data, uint16_t len)
{
const struct gatt_read_multiple_cmd *cmd = (void *) data;
u16_t handles[cmd->handles_count];
uint16_t handles[cmd->handles_count];
struct ble_gap_conn_desc conn;
int rc, i;
@ -836,11 +836,11 @@ fail:
BTP_STATUS_FAILED);
}
static void write_without_rsp(u8_t *data, u16_t len, u8_t op, bool sign)
static void write_without_rsp(uint8_t *data, uint16_t len, uint8_t op, bool sign)
{
const struct gatt_write_without_rsp_cmd *cmd = (void *) data;
struct ble_gap_conn_desc conn;
u8_t status = BTP_STATUS_SUCCESS;
uint8_t status = BTP_STATUS_SUCCESS;
int rc;
SYS_LOG_DBG("");
@ -866,7 +866,7 @@ static int write_rsp(uint16_t conn_handle, const struct ble_gatt_error *error,
void *arg)
{
uint8_t err = (uint8_t) error->status;
u8_t btp_opcode = (uint8_t) (int) arg;
uint8_t btp_opcode = (uint8_t) (int) arg;
SYS_LOG_DBG("");
@ -875,7 +875,7 @@ static int write_rsp(uint16_t conn_handle, const struct ble_gatt_error *error,
return 0;
}
static void write(u8_t *data, u16_t len)
static void write(uint8_t *data, uint16_t len)
{
const struct gatt_write_cmd *cmd = (void *) data;
struct ble_gap_conn_desc conn;
@ -901,7 +901,7 @@ fail:
BTP_STATUS_FAILED);
}
static void write_long(u8_t *data, u16_t len)
static void write_long(uint8_t *data, uint16_t len)
{
const struct gatt_write_long_cmd *cmd = (void *) data;
struct ble_gap_conn_desc conn;
@ -952,7 +952,7 @@ static int reliable_write_rsp(uint16_t conn_handle,
return 0;
}
static void reliable_write(u8_t *data, u16_t len)
static void reliable_write(uint8_t *data, uint16_t len)
{
const struct gatt_reliable_write_cmd *cmd = (void *) data;
struct ble_gap_conn_desc conn;
@ -994,12 +994,12 @@ fail:
}
static struct bt_gatt_subscribe_params {
u16_t ccc_handle;
u16_t value;
u16_t value_handle;
uint16_t ccc_handle;
uint16_t value;
uint16_t value_handle;
} subscribe_params;
static void read_uuid(u8_t *data, u16_t len)
static void read_uuid(uint8_t *data, uint16_t len)
{
const struct gatt_read_uuid_cmd *cmd = (void *) data;
struct ble_gap_conn_desc conn;
@ -1046,8 +1046,8 @@ static int disc_prim_uuid_cb(uint16_t conn_handle,
struct gatt_disc_prim_uuid_rp *rp = (void *) gatt_buf.buf;
struct gatt_service *service;
const ble_uuid_any_t *uuid;
u8_t uuid_length;
u8_t opcode = (u8_t) (int) arg;
uint8_t uuid_length;
uint8_t opcode = (uint8_t) (int) arg;
SYS_LOG_DBG("");
@ -1081,7 +1081,7 @@ static int disc_prim_uuid_cb(uint16_t conn_handle,
service->uuid_length = uuid_length;
if (uuid->u.type == BLE_UUID_TYPE_16) {
u16_t u16 = sys_cpu_to_le16(BLE_UUID16(uuid)->value);
uint16_t u16 = sys_cpu_to_le16(BLE_UUID16(uuid)->value);
memcpy(service->uuid, &u16, uuid_length);
} else {
memcpy(service->uuid, BLE_UUID128(uuid)->value,
@ -1102,7 +1102,7 @@ static int disc_all_desc_cb(uint16_t conn_handle,
struct gatt_disc_all_desc_rp *rp = (void *) gatt_buf.buf;
struct gatt_descriptor *dsc;
const ble_uuid_any_t *uuid;
u8_t uuid_length;
uint8_t uuid_length;
SYS_LOG_DBG("");
@ -1135,7 +1135,7 @@ static int disc_all_desc_cb(uint16_t conn_handle,
dsc->uuid_length = uuid_length;
if (uuid->u.type == BLE_UUID_TYPE_16) {
u16_t u16 = sys_cpu_to_le16(BLE_UUID16(uuid)->value);
uint16_t u16 = sys_cpu_to_le16(BLE_UUID16(uuid)->value);
memcpy(dsc->uuid, &u16, uuid_length);
} else {
memcpy(dsc->uuid, BLE_UUID128(uuid)->value, uuid_length);
@ -1146,7 +1146,7 @@ static int disc_all_desc_cb(uint16_t conn_handle,
return 0;
}
static void disc_all_prim_svcs(u8_t *data, u16_t len)
static void disc_all_prim_svcs(uint8_t *data, uint16_t len)
{
struct ble_gap_conn_desc conn;
int rc;
@ -1175,7 +1175,7 @@ fail:
CONTROLLER_INDEX, BTP_STATUS_FAILED);
}
static void disc_all_desc(u8_t *data, u16_t len)
static void disc_all_desc(uint8_t *data, uint16_t len)
{
const struct gatt_disc_all_desc_cmd *cmd = (void *) data;
struct ble_gap_conn_desc conn;
@ -1221,7 +1221,7 @@ static int find_included_cb(uint16_t conn_handle,
struct gatt_included *included;
const ble_uuid_any_t *uuid;
int service_handle = (int) arg;
u8_t uuid_length;
uint8_t uuid_length;
SYS_LOG_DBG("");
@ -1259,7 +1259,7 @@ static int find_included_cb(uint16_t conn_handle,
included->service.uuid_length = uuid_length;
if (uuid->u.type == BLE_UUID_TYPE_16) {
u16_t u16 = sys_cpu_to_le16(BLE_UUID16(uuid)->value);
uint16_t u16 = sys_cpu_to_le16(BLE_UUID16(uuid)->value);
memcpy(included->service.uuid, &u16, uuid_length);
} else {
memcpy(included->service.uuid, BLE_UUID128(uuid)->value,
@ -1278,8 +1278,8 @@ static int disc_chrc_cb(uint16_t conn_handle,
struct gatt_disc_chrc_rp *rp = (void *) gatt_buf.buf;
struct gatt_characteristic *chrc;
const ble_uuid_any_t *uuid;
u8_t btp_opcode = (uint8_t) (int) arg;
u8_t uuid_length;
uint8_t btp_opcode = (uint8_t) (int) arg;
uint8_t uuid_length;
SYS_LOG_DBG("");
@ -1314,7 +1314,7 @@ static int disc_chrc_cb(uint16_t conn_handle,
chrc->uuid_length = uuid_length;
if (uuid->u.type == BLE_UUID_TYPE_16) {
u16_t u16 = sys_cpu_to_le16(BLE_UUID16(uuid)->value);
uint16_t u16 = sys_cpu_to_le16(BLE_UUID16(uuid)->value);
memcpy(chrc->uuid, &u16, uuid_length);
} else {
memcpy(chrc->uuid, BLE_UUID128(uuid)->value,
@ -1326,7 +1326,7 @@ static int disc_chrc_cb(uint16_t conn_handle,
return 0;
}
static void disc_chrc_uuid(u8_t *data, u16_t len)
static void disc_chrc_uuid(uint8_t *data, uint16_t len)
{
const struct gatt_disc_chrc_uuid_cmd *cmd = (void *) data;
struct ble_gap_conn_desc conn;
@ -1366,7 +1366,7 @@ fail:
BTP_STATUS_FAILED);
}
static void disc_prim_uuid(u8_t *data, u16_t len)
static void disc_prim_uuid(uint8_t *data, uint16_t len)
{
const struct gatt_disc_prim_uuid_cmd *cmd = (void *) data;
struct ble_gap_conn_desc conn;
@ -1402,7 +1402,7 @@ fail:
BTP_STATUS_FAILED);
}
static void disc_all_chrc(u8_t *data, u16_t len)
static void disc_all_chrc(uint8_t *data, uint16_t len)
{
const struct gatt_disc_all_chrc_cmd *cmd = (void *) data;
struct ble_gap_conn_desc conn;
@ -1439,7 +1439,7 @@ fail:
BTP_STATUS_FAILED);
}
static void find_included(u8_t *data, u16_t len)
static void find_included(uint8_t *data, uint16_t len)
{
const struct gatt_find_included_cmd *cmd = (void *) data;
struct ble_gap_conn_desc conn;
@ -1495,7 +1495,7 @@ static int exchange_func(uint16_t conn_handle,
return 0;
}
static void exchange_mtu(u8_t *data, u16_t len)
static void exchange_mtu(uint8_t *data, uint16_t len)
{
struct ble_gap_conn_desc conn;
int rc;
@ -1517,10 +1517,10 @@ fail:
CONTROLLER_INDEX, BTP_STATUS_FAILED);
}
static int enable_subscription(u16_t conn_handle, u16_t ccc_handle,
u16_t value)
static int enable_subscription(uint16_t conn_handle, uint16_t ccc_handle,
uint16_t value)
{
u8_t op;
uint8_t op;
SYS_LOG_DBG("");
@ -1538,9 +1538,9 @@ static int enable_subscription(u16_t conn_handle, u16_t ccc_handle,
return 0;
}
static int disable_subscription(u16_t conn_handle, u16_t ccc_handle)
static int disable_subscription(uint16_t conn_handle, uint16_t ccc_handle)
{
u16_t value = 0x00;
uint16_t value = 0x00;
SYS_LOG_DBG("");
@ -1559,12 +1559,12 @@ static int disable_subscription(u16_t conn_handle, u16_t ccc_handle)
return 0;
}
static void config_subscription(u8_t *data, u16_t len, u8_t op)
static void config_subscription(uint8_t *data, uint16_t len, uint8_t op)
{
const struct gatt_cfg_notify_cmd *cmd = (void *) data;
struct ble_gap_conn_desc conn;
u16_t ccc_handle = sys_le16_to_cpu(cmd->ccc_handle);
u8_t status;
uint16_t ccc_handle = sys_le16_to_cpu(cmd->ccc_handle);
uint8_t status;
int rc;
SYS_LOG_DBG("");
@ -1577,7 +1577,7 @@ static void config_subscription(u8_t *data, u16_t len, u8_t op)
}
if (cmd->enable) {
u16_t value;
uint16_t value;
if (op == GATT_CFG_NOTIFY) {
value = 0x0001;
@ -1625,10 +1625,10 @@ static int flags_hs2btp_map[] = {
BTP_PERM_F_WRITE_AUTHOR,
};
static u8_t flags_hs2btp(u8_t flags)
static uint8_t flags_hs2btp(uint8_t flags)
{
int i;
u8_t ret = 0;
uint8_t ret = 0;
for (i = 0; i < 8; ++i) {
if (flags & BIT(i)) {
@ -1639,17 +1639,17 @@ static u8_t flags_hs2btp(u8_t flags)
return ret;
}
static void get_attrs(u8_t *data, u16_t len)
static void get_attrs(uint8_t *data, uint16_t len)
{
const struct gatt_get_attributes_cmd *cmd = (void *) data;
struct gatt_get_attributes_rp *rp;
struct gatt_attr *gatt_attr;
struct os_mbuf *buf = os_msys_get(0, 0);
u16_t start_handle, end_handle;
uint16_t start_handle, end_handle;
struct ble_att_svr_entry *entry = NULL;
ble_uuid_any_t uuid;
ble_uuid_t *uuid_ptr = NULL;
u8_t count = 0;
uint8_t count = 0;
char str[BLE_UUID_STR_LEN];
SYS_LOG_DBG("");
@ -1718,13 +1718,13 @@ free:
os_mbuf_free_chain(buf);
}
static void get_attr_val(u8_t *data, u16_t len)
static void get_attr_val(uint8_t *data, uint16_t len)
{
const struct gatt_get_attribute_value_cmd *cmd = (void *) data;
struct gatt_get_attribute_value_rp *rp;
struct ble_gap_conn_desc conn;
struct os_mbuf *buf = os_msys_get(0, 0);
u16_t handle = sys_cpu_to_le16(cmd->handle);
uint16_t handle = sys_cpu_to_le16(cmd->handle);
uint8_t out_att_err;
int conn_status;
@ -1766,7 +1766,7 @@ free:
os_mbuf_free_chain(buf);
}
static void change_database(u8_t *data, u16_t len)
static void change_database(uint8_t *data, uint16_t len)
{
const struct gatt_change_database *cmd = (void *) data;
@ -1782,9 +1782,9 @@ static void change_database(u8_t *data, u16_t len)
return;
}
static void supported_commands(u8_t *data, u16_t len)
static void supported_commands(uint8_t *data, uint16_t len)
{
u8_t cmds[4];
uint8_t cmds[4];
struct gatt_read_supported_commands_rp *rp = (void *) cmds;
SYS_LOG_DBG("");
@ -1816,7 +1816,7 @@ static void supported_commands(u8_t *data, u16_t len)
tester_set_bit(cmds, GATT_CHANGE_DATABASE);
tester_send(BTP_SERVICE_ID_GATT, GATT_READ_SUPPORTED_COMMANDS,
CONTROLLER_INDEX, (u8_t *) rp, sizeof(cmds));
CONTROLLER_INDEX, (uint8_t *) rp, sizeof(cmds));
}
enum attr_type {
@ -1825,8 +1825,8 @@ enum attr_type {
BLE_GATT_ATTR_DSC,
};
void tester_handle_gatt(u8_t opcode, u8_t index, u8_t *data,
u16_t len)
void tester_handle_gatt(uint8_t opcode, uint8_t index, uint8_t *data,
uint16_t len)
{
switch (opcode) {
case GATT_READ_SUPPORTED_COMMANDS:
@ -1905,8 +1905,8 @@ void tester_handle_gatt(u8_t opcode, u8_t index, u8_t *data,
}
}
int tester_gatt_notify_rx_ev(u16_t conn_handle, u16_t attr_handle,
u8_t indication, struct os_mbuf *om)
int tester_gatt_notify_rx_ev(uint16_t conn_handle, uint16_t attr_handle,
uint8_t indication, struct os_mbuf *om)
{
struct gatt_notification_ev *ev;
struct ble_gap_conn_desc conn;
@ -1930,7 +1930,7 @@ int tester_gatt_notify_rx_ev(u16_t conn_handle, u16_t attr_handle,
ev->address_type = addr->type;
memcpy(ev->address, addr->val, sizeof(ev->address));
ev->type = (u8_t) (indication ? 0x02 : 0x01);
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));
os_mbuf_appendfrom(buf, om, 0, os_mbuf_len(om));
@ -1988,9 +1988,9 @@ void notify_test(struct os_event *ev)
}
}
int tester_gatt_subscribe_ev(u16_t conn_handle, u16_t attr_handle, u8_t reason,
u8_t prev_notify, u8_t cur_notify,
u8_t prev_indicate, u8_t cur_indicate)
int tester_gatt_subscribe_ev(uint16_t conn_handle, uint16_t attr_handle, uint8_t reason,
uint8_t prev_notify, uint8_t cur_notify,
uint8_t prev_indicate, uint8_t cur_indicate)
{
SYS_LOG_DBG("");
myconn_handle = conn_handle;
@ -2084,7 +2084,7 @@ int gatt_svr_init(void)
return 0;
}
u8_t tester_init_gatt(void)
uint8_t tester_init_gatt(void)
{
os_callout_init(&notify_tx_timer, os_eventq_dflt_get(),
notify_test, NULL);
@ -2092,7 +2092,7 @@ u8_t tester_init_gatt(void)
return BTP_STATUS_SUCCESS;
}
u8_t tester_unregister_gatt(void)
uint8_t tester_unregister_gatt(void)
{
return BTP_STATUS_SUCCESS;
}

View file

@ -33,8 +33,8 @@ const char *bt_hex(const void *buf, size_t len)
{
static const char hex[] = "0123456789abcdef";
static char hexbufs[4][137];
static u8_t curbuf;
const u8_t *b = buf;
static uint8_t curbuf;
const uint8_t *b = buf;
char *str;
int i;

View file

@ -22,11 +22,11 @@
#include "os/endian.h"
#define u8_t uint8_t
#define s8_t int8_t
#define u16_t uint16_t
#define u32_t uint32_t
#define s32_t int32_t
#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))
@ -37,16 +37,16 @@
#define sys_le16_to_cpu le16toh
struct bt_data {
u8_t type;
u8_t data_len;
const u8_t *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 u8_t *)(_data), \
.data = (const uint8_t *)(_data), \
}
struct os_mbuf * NET_BUF_SIMPLE(uint16_t size);

View file

@ -33,11 +33,13 @@
#include "host/ble_gap.h"
#include "host/ble_l2cap.h"
#include "../../../nimble/host/src/ble_l2cap_priv.h"
#include "bttester.h"
#define CONTROLLER_INDEX 0
#define CHANNELS MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM)
#define TESTER_COC_MTU (230)
#define TESTER_COC_MTU MYNEWT_VAL(BTTESTER_L2CAP_COC_MTU)
#define TESTER_COC_BUF_COUNT (3 * MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM))
static os_membuf_t tester_sdu_coc_mem[
@ -48,14 +50,34 @@ struct os_mbuf_pool sdu_os_mbuf_pool;
static struct os_mempool sdu_coc_mbuf_mempool;
static struct channel {
u8_t chan_id; /* Internal number that identifies L2CAP channel. */
u8_t state;
uint8_t chan_id; /* Internal number that identifies L2CAP channel. */
uint8_t state;
struct ble_l2cap_chan *chan;
} channels[CHANNELS];
static u8_t recv_cb_buf[TESTER_COC_MTU + sizeof(struct l2cap_data_received_ev)];
static uint8_t recv_cb_buf[TESTER_COC_MTU + sizeof(struct l2cap_data_received_ev)];
struct channel *find_channel(struct ble_l2cap_chan *chan) {
static struct channel *get_free_channel(void)
{
uint8_t i;
struct channel *chan;
for (i = 0; i < CHANNELS; i++) {
if (channels[i].state) {
continue;
}
chan = &channels[i];
chan->chan_id = i;
return chan;
}
return NULL;
}
struct channel *find_channel(struct ble_l2cap_chan *chan)
{
int i;
for (i = 0; i < CHANNELS; ++i) {
@ -67,6 +89,15 @@ struct channel *find_channel(struct ble_l2cap_chan *chan) {
return NULL;
}
struct channel *get_channel(uint8_t chan_id)
{
if (chan_id >= CHANNELS) {
return NULL;
}
return &channels[chan_id];
}
static void
tester_l2cap_coc_recv(struct ble_l2cap_chan *chan, struct os_mbuf *sdu)
{
@ -84,14 +115,20 @@ static void recv_cb(uint16_t conn_handle, struct ble_l2cap_chan *chan,
struct os_mbuf *buf, void *arg)
{
struct l2cap_data_received_ev *ev = (void *) recv_cb_buf;
struct channel *channel = arg;
struct channel *channel = find_channel(chan);
assert(channel != NULL);
ev->chan_id = channel->chan_id;
ev->data_length = buf->om_len;
memcpy(ev->data, buf->om_data, buf->om_len);
ev->data_length = OS_MBUF_PKTLEN(buf);
if (ev->data_length > TESTER_COC_MTU) {
SYS_LOG_ERR("Too large sdu received, truncating data");
ev->data_length = TESTER_COC_MTU;
}
os_mbuf_copydata(buf, 0, ev->data_length, ev->data);
tester_send(BTP_SERVICE_ID_L2CAP, L2CAP_EV_DATA_RECEIVED,
CONTROLLER_INDEX, recv_cb_buf, sizeof(*ev) + buf->om_len);
CONTROLLER_INDEX, recv_cb_buf, sizeof(*ev) + ev->data_length);
tester_l2cap_coc_recv(chan, buf);
}
@ -108,44 +145,49 @@ static void unstalled_cb(uint16_t conn_handle, struct ble_l2cap_chan *chan,
}
}
static struct channel *get_free_channel(void)
static void reconfigured_ev(uint16_t conn_handle, struct ble_l2cap_chan *chan,
struct ble_l2cap_chan_info *chan_info,
int status)
{
u8_t i;
struct channel *chan;
struct l2cap_reconfigured_ev ev;
struct channel *channel;
for (i = 0; i < CHANNELS; i++) {
if (channels[i].state) {
continue;
}
chan = &channels[i];
chan->chan_id = i;
return chan;
if (status != 0) {
return;
}
return NULL;
channel = find_channel(chan);
assert(channel != NULL);
ev.chan_id = channel->chan_id;
ev.peer_mtu = chan_info->peer_coc_mtu;
ev.peer_mps = chan_info->peer_l2cap_mtu;
ev.our_mtu = chan_info->our_coc_mtu;
ev.our_mps = chan_info->our_l2cap_mtu;
tester_send(BTP_SERVICE_ID_L2CAP, L2CAP_EV_RECONFIGURED,
CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev));
}
static void connected_cb(uint16_t conn_handle, struct ble_l2cap_chan *chan,
void *arg)
struct ble_l2cap_chan_info *chan_info, void *arg)
{
struct l2cap_connected_ev ev;
struct ble_gap_conn_desc desc;
struct channel *channel;
struct channel *channel = find_channel(chan);
channel = get_free_channel();
if (!channel) {
assert(0);
if (channel == NULL) {
channel = get_free_channel();
}
channel->chan = chan;
channel->state = 0;
ev.chan_id = channel->chan_id;
ev.psm = chan_info->psm;
ev.peer_mtu = chan_info->peer_coc_mtu;
ev.peer_mps = chan_info->peer_l2cap_mtu;
ev.our_mtu = chan_info->our_coc_mtu;
ev.our_mps = chan_info->our_l2cap_mtu;
channel->state = 1;
channel->chan = chan;
/* TODO: ev.psm */
if (!ble_gap_conn_find(conn_handle, &desc)) {
ev.address_type = desc.peer_ota_addr.type;
@ -154,11 +196,11 @@ static void connected_cb(uint16_t conn_handle, struct ble_l2cap_chan *chan,
}
tester_send(BTP_SERVICE_ID_L2CAP, L2CAP_EV_CONNECTED, CONTROLLER_INDEX,
(u8_t *) &ev, sizeof(ev));
(uint8_t *) &ev, sizeof(ev));
}
static void disconnected_cb(uint16_t conn_handle, struct ble_l2cap_chan *chan,
void *arg)
struct ble_l2cap_chan_info *chan_info, void *arg)
{
struct l2cap_disconnected_ev ev;
struct ble_gap_conn_desc desc;
@ -167,14 +209,12 @@ static void disconnected_cb(uint16_t conn_handle, struct ble_l2cap_chan *chan,
memset(&ev, 0, sizeof(struct l2cap_disconnected_ev));
channel = find_channel(chan);
if (channel != NULL) {
channel->state = 0;
channel->chan = chan;
assert(channel != NULL);
ev.chan_id = channel->chan_id;
/* TODO: ev.result */
/* TODO: ev.psm */
}
channel->state = 0;
channel->chan = chan;
ev.chan_id = channel->chan_id;
ev.psm = chan_info->psm;
if (!ble_gap_conn_find(conn_handle, &desc)) {
ev.address_type = desc.peer_ota_addr.type;
@ -183,7 +223,7 @@ static void disconnected_cb(uint16_t conn_handle, struct ble_l2cap_chan *chan,
}
tester_send(BTP_SERVICE_ID_L2CAP, L2CAP_EV_DISCONNECTED,
CONTROLLER_INDEX, (u8_t *) &ev, sizeof(ev));
CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev));
}
static int accept_cb(uint16_t conn_handle, uint16_t peer_mtu,
@ -208,39 +248,51 @@ static int
tester_l2cap_event(struct ble_l2cap_event *event, void *arg)
{
struct ble_l2cap_chan_info chan_info;
int accept_response;
switch (event->type) {
case BLE_L2CAP_EVENT_COC_CONNECTED:
case BLE_L2CAP_EVENT_COC_CONNECTED:
if (ble_l2cap_get_chan_info(event->connect.chan, &chan_info)) {
assert(0);
}
if (event->connect.status) {
console_printf("LE COC error: %d\n", event->connect.status);
disconnected_cb(event->connect.conn_handle,
event->connect.chan, arg);
event->connect.chan, &chan_info, arg);
return 0;
}
ble_l2cap_get_chan_info(event->connect.chan, &chan_info);
console_printf("LE COC connected, conn: %d, chan: 0x%08lx, scid: 0x%04x, "
"dcid: 0x%04x, our_mtu: 0x%04x, peer_mtu: 0x%04x\n",
event->connect.conn_handle,
(uint32_t) event->connect.chan,
chan_info.scid,
chan_info.dcid,
chan_info.our_l2cap_mtu,
chan_info.peer_l2cap_mtu);
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);
connected_cb(event->connect.conn_handle,
event->connect.chan, arg);
event->connect.chan, &chan_info, arg);
return 0;
case BLE_L2CAP_EVENT_COC_DISCONNECTED:
if (ble_l2cap_get_chan_info(event->disconnect.chan,
&chan_info)) {
assert(0);
}
console_printf("LE CoC disconnected, chan: 0x%08lx\n",
(uint32_t) event->disconnect.chan);
disconnected_cb(event->disconnect.conn_handle,
event->disconnect.chan, arg);
event->disconnect.chan, &chan_info, arg);
return 0;
case BLE_L2CAP_EVENT_COC_ACCEPT:
accept_response = POINTER_TO_INT(arg);
if (accept_response) {
return accept_response;
}
console_printf("LE CoC accept, chan: 0x%08lx, handle: %u, sdu_size: %u\n",
(uint32_t) event->accept.chan,
event->accept.conn_handle,
@ -254,7 +306,8 @@ tester_l2cap_event(struct ble_l2cap_event *event, void *arg)
console_printf("LE CoC data received, chan: 0x%08lx, handle: %u, sdu_len: %u\n",
(uint32_t) event->receive.chan,
event->receive.conn_handle,
event->receive.sdu_rx->om_len);
OS_MBUF_PKTLEN(event->receive.sdu_rx));
recv_cb(event->receive.conn_handle, event->receive.chan,
event->receive.sdu_rx, arg);
return 0;
@ -263,57 +316,118 @@ tester_l2cap_event(struct ble_l2cap_event *event, void *arg)
(uint32_t) event->tx_unstalled.chan,
event->tx_unstalled.conn_handle,
event->tx_unstalled.status);
unstalled_cb(event->tx_unstalled.conn_handle,
event->tx_unstalled.chan,
event->tx_unstalled.status, arg);
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, "
"chan: 0x%08lx\n", event->reconfigured.status,
(uint32_t) event->reconfigured.chan);
if (event->reconfigured.status == 0) {
console_printf("\t our_mps: %d our_mtu %d\n",
chan_info.our_l2cap_mtu, chan_info.our_coc_mtu);
}
reconfigured_ev(event->reconfigured.conn_handle,
event->reconfigured.chan,
&chan_info,
event->reconfigured.status);
return 0;
case BLE_L2CAP_EVENT_COC_PEER_RECONFIGURED:
if (ble_l2cap_get_chan_info(event->reconfigured.chan,
&chan_info)) {
assert(0);
}
console_printf("LE CoC peer reconfigured status 0x%02x, "
"chan: 0x%08lx\n", event->reconfigured.status,
(uint32_t) event->reconfigured.chan);
if (event->reconfigured.status == 0) {
console_printf("\t peer_mps: %d peer_mtu %d\n",
chan_info.peer_l2cap_mtu, chan_info.peer_coc_mtu);
}
reconfigured_ev(event->reconfigured.conn_handle,
event->reconfigured.chan,
&chan_info,
event->reconfigured.status);
return 0;
default:
return 0;
}
}
static void connect(u8_t *data, u16_t len)
static void connect(uint8_t *data, uint16_t len)
{
const struct l2cap_connect_cmd *cmd = (void *) data;
struct l2cap_connect_rp rp;
uint8_t rp_buf[sizeof(struct l2cap_connect_rp) + cmd->num];
struct l2cap_connect_rp *rp = (void *) rp_buf;
struct ble_gap_conn_desc desc;
struct channel *chan;
struct os_mbuf *sdu_rx;
struct os_mbuf *sdu_rx[cmd->num];
ble_addr_t *addr = (void *) data;
uint16_t mtu = htole16(cmd->mtu);
int rc;
int i;
SYS_LOG_DBG("connect: type: %d addr: %s", addr->type, bt_hex(addr->val, 6));
if (mtu == 0 || mtu > TESTER_COC_MTU) {
mtu = TESTER_COC_MTU;
}
rc = ble_gap_conn_find_by_addr(addr, &desc);
if (rc) {
SYS_LOG_ERR("GAP conn find failed");
goto fail;
}
chan = get_free_channel();
if (!chan) {
SYS_LOG_ERR("No free channels");
rp->num = cmd->num;
for (i = 0; i < cmd->num; i++) {
chan = get_free_channel();
if (!chan) {
SYS_LOG_ERR("No free channels");
goto fail;
}
rp->chan_ids[i] = chan->chan_id;
sdu_rx[i] = os_mbuf_get_pkthdr(&sdu_os_mbuf_pool, 0);
if (sdu_rx[i] == NULL) {
SYS_LOG_ERR("Failed to alloc buf");
goto fail;
}
}
if (cmd->num == 1) {
rc = ble_l2cap_connect(desc.conn_handle, htole16(cmd->psm),
mtu, sdu_rx[0],
tester_l2cap_event, NULL);
} else if (cmd->num > 1) {
rc = ble_l2cap_enhanced_connect(desc.conn_handle,
htole16(cmd->psm), mtu,
cmd->num, sdu_rx,
tester_l2cap_event, NULL);
} else {
SYS_LOG_ERR("Invalid 'num' parameter value");
goto fail;
}
sdu_rx = os_mbuf_get_pkthdr(&sdu_os_mbuf_pool, 0);
if (sdu_rx == NULL) {
SYS_LOG_ERR("Failed to alloc buf");
goto fail;
}
rc = ble_l2cap_connect(desc.conn_handle, htole16(cmd->psm),
TESTER_COC_MTU, sdu_rx,
tester_l2cap_event, chan);
if (rc) {
SYS_LOG_ERR("L2CAP connect failed\n");
goto fail;
}
rp.chan_id = chan->chan_id;
tester_send(BTP_SERVICE_ID_L2CAP, L2CAP_CONNECT, CONTROLLER_INDEX,
(u8_t *) &rp, sizeof(rp));
(uint8_t *) rp, sizeof(rp_buf));
return;
@ -322,16 +436,17 @@ fail:
BTP_STATUS_FAILED);
}
static void disconnect(u8_t *data, u16_t len)
static void disconnect(const uint8_t *data, uint16_t len)
{
const struct l2cap_disconnect_cmd *cmd = (void *) data;
struct channel *chan;
u8_t status;
uint8_t status;
int err;
SYS_LOG_DBG("");
chan = &channels[cmd->chan_id];
chan = get_channel(cmd->chan_id);
assert(chan != NULL);
err = ble_l2cap_disconnect(chan->chan);
if (err) {
@ -346,16 +461,21 @@ rsp:
status);
}
static void send_data(u8_t *data, u16_t len)
static void send_data(const uint8_t *data, uint16_t len)
{
const struct l2cap_send_data_cmd *cmd = (void *) data;
struct channel *chan = &channels[cmd->chan_id];
struct os_mbuf *sdu_tx = NULL;
int rc;
u16_t data_len = sys_le16_to_cpu(cmd->data_len);
uint16_t data_len = sys_le16_to_cpu(cmd->data_len);
struct channel *chan = get_channel(cmd->chan_id);
SYS_LOG_DBG("cmd->chan_id=%d", cmd->chan_id);
if (!chan) {
SYS_LOG_ERR("Invalid channel\n");
goto fail;
}
/* FIXME: For now, fail if data length exceeds buffer length */
if (data_len > TESTER_COC_MTU) {
SYS_LOG_ERR("Data length exceeds buffer length");
@ -386,16 +506,48 @@ fail:
BTP_STATUS_FAILED);
}
static void listen(u8_t *data, u16_t len)
static int
l2cap_coc_err2hs_err(uint16_t coc_err)
{
switch (coc_err) {
case BLE_L2CAP_COC_ERR_UNKNOWN_LE_PSM:
return BLE_HS_ENOTSUP;
case BLE_L2CAP_COC_ERR_NO_RESOURCES:
return BLE_HS_ENOMEM;
case BLE_L2CAP_COC_ERR_INSUFFICIENT_AUTHEN:
return BLE_HS_EAUTHEN;
case BLE_L2CAP_COC_ERR_INSUFFICIENT_AUTHOR:
return BLE_HS_EAUTHOR;
case BLE_L2CAP_COC_ERR_INSUFFICIENT_ENC:
return BLE_HS_EENCRYPT;
case BLE_L2CAP_COC_ERR_INSUFFICIENT_KEY_SZ:
return BLE_HS_EENCRYPT_KEY_SZ;
case BLE_L2CAP_COC_ERR_UNACCEPTABLE_PARAMETERS:
return BLE_HS_EINVAL;
default:
return 0;
}
}
static void listen(const uint8_t *data, uint16_t len)
{
const struct l2cap_listen_cmd *cmd = (void *) data;
uint16_t mtu = htole16(cmd->mtu);
uint16_t rsp = htole16(cmd->response);
int rc;
SYS_LOG_DBG("");
if (mtu == 0 || mtu > TESTER_COC_MTU) {
mtu = TESTER_COC_MTU;
}
rsp = l2cap_coc_err2hs_err(rsp);
/* TODO: Handle cmd->transport flag */
rc = ble_l2cap_create_server(cmd->psm, TESTER_COC_MTU,
tester_l2cap_event, NULL);
rc = ble_l2cap_create_server(cmd->psm, mtu, tester_l2cap_event,
INT_TO_POINTER(rsp));
if (rc) {
goto fail;
}
@ -409,9 +561,54 @@ fail:
BTP_STATUS_FAILED);
}
static void supported_commands(u8_t *data, u16_t len)
static void reconfigure(const uint8_t *data, uint16_t len)
{
u8_t cmds[1];
const struct l2cap_reconfigure_cmd *cmd = (void *) data;
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];
struct channel *channel;
int rc;
int i;
SYS_LOG_DBG("");
if (mtu == 0 || mtu > TESTER_COC_MTU) {
mtu = TESTER_COC_MTU;
}
rc = ble_gap_conn_find_by_addr(addr, &desc);
if (rc) {
SYS_LOG_ERR("GAP conn find failed");
goto fail;
}
for (i = 0; i < cmd->num; ++i) {
channel = get_channel(cmd->idxs[i]);
if (channel == NULL) {
goto fail;
}
chans[i] = channel->chan;
}
rc = ble_l2cap_reconfig(chans, cmd->num, mtu);
if (rc) {
goto fail;
}
tester_rsp(BTP_SERVICE_ID_L2CAP, L2CAP_RECONFIGURE, CONTROLLER_INDEX,
BTP_STATUS_SUCCESS);
return;
fail:
tester_rsp(BTP_SERVICE_ID_L2CAP, L2CAP_RECONFIGURE, CONTROLLER_INDEX,
BTP_STATUS_FAILED);
}
static void supported_commands(uint8_t *data, uint16_t len)
{
uint8_t cmds[1];
struct l2cap_read_supported_commands_rp *rp = (void *) cmds;
memset(cmds, 0, sizeof(cmds));
@ -421,13 +618,14 @@ static void supported_commands(u8_t *data, u16_t len)
tester_set_bit(cmds, L2CAP_DISCONNECT);
tester_set_bit(cmds, L2CAP_LISTEN);
tester_set_bit(cmds, L2CAP_SEND_DATA);
tester_set_bit(cmds, L2CAP_RECONFIGURE);
tester_send(BTP_SERVICE_ID_L2CAP, L2CAP_READ_SUPPORTED_COMMANDS,
CONTROLLER_INDEX, (u8_t *) rp, sizeof(cmds));
CONTROLLER_INDEX, (uint8_t *) rp, sizeof(cmds));
}
void tester_handle_l2cap(u8_t opcode, u8_t index, u8_t *data,
u16_t len)
void tester_handle_l2cap(uint8_t opcode, uint8_t index, uint8_t *data,
uint16_t len)
{
switch (opcode) {
case L2CAP_READ_SUPPORTED_COMMANDS:
@ -445,6 +643,9 @@ void tester_handle_l2cap(u8_t opcode, u8_t index, u8_t *data,
case L2CAP_LISTEN:
listen(data, len);
return;
case L2CAP_RECONFIGURE:
reconfigure(data, len);
return;
default:
tester_rsp(BTP_SERVICE_ID_L2CAP, opcode, index,
BTP_STATUS_UNKNOWN_CMD);
@ -452,7 +653,7 @@ void tester_handle_l2cap(u8_t opcode, u8_t index, u8_t *data,
}
}
u8_t tester_init_l2cap(void)
uint8_t tester_init_l2cap(void)
{
int rc;
@ -469,7 +670,7 @@ u8_t tester_init_l2cap(void)
return BTP_STATUS_SUCCESS;
}
u8_t tester_unregister_l2cap(void)
uint8_t tester_unregister_l2cap(void)
{
return BTP_STATUS_SUCCESS;
}

View file

@ -38,7 +38,7 @@
#include "bttester.h"
extern u8_t own_addr_type;
extern uint8_t own_addr_type;
#define CONTROLLER_INDEX 0
#define CID_LOCAL 0xffff
@ -47,21 +47,21 @@ extern u8_t own_addr_type;
#define CUR_FAULTS_MAX 4
#define HEALTH_TEST_ID 0x00
static u8_t cur_faults[CUR_FAULTS_MAX];
static u8_t reg_faults[CUR_FAULTS_MAX * 2];
static uint8_t cur_faults[CUR_FAULTS_MAX];
static uint8_t reg_faults[CUR_FAULTS_MAX * 2];
/* Provision node data */
static u8_t net_key[16];
static u16_t net_key_idx;
static u8_t flags;
static u32_t iv_index;
static u16_t addr;
static u8_t dev_key[16];
static u8_t input_size;
static uint8_t net_key[16];
static uint16_t net_key_idx;
static uint8_t flags;
static uint32_t iv_index;
static uint16_t addr;
static uint8_t dev_key[16];
static uint8_t input_size;
/* Configured provisioning data */
static u8_t dev_uuid[16];
static u8_t static_auth[16];
static uint8_t dev_uuid[16];
static uint8_t static_auth[16];
/* Vendor Model data */
#define VND_MODEL_ID_1 0x1234
@ -71,20 +71,20 @@ static u8_t static_auth[16];
static struct model_data {
struct bt_mesh_model *model;
u16_t addr;
u16_t appkey_idx;
uint16_t addr;
uint16_t appkey_idx;
} model_bound[MODEL_BOUNDS_MAX];
static struct {
u16_t local;
u16_t dst;
u16_t net_idx;
uint16_t local;
uint16_t dst;
uint16_t net_idx;
} net = {
.local = BT_MESH_ADDR_UNASSIGNED,
.dst = BT_MESH_ADDR_UNASSIGNED,
};
static void supported_commands(u8_t *data, u16_t len)
static void supported_commands(uint8_t *data, uint16_t len)
{
struct os_mbuf *buf = NET_BUF_SIMPLE(BTP_DATA_MAX_SIZE);
@ -121,29 +121,9 @@ static void supported_commands(u8_t *data, u16_t len)
CONTROLLER_INDEX, buf);
}
static struct bt_mesh_cfg_srv cfg_srv = {
.relay = BT_MESH_RELAY_ENABLED,
.beacon = BT_MESH_BEACON_ENABLED,
#if MYNEWT_VAL(BLE_MESH_FRIEND)
.frnd = BT_MESH_FRIEND_ENABLED,
#else
.frnd = BT_MESH_FRIEND_NOT_SUPPORTED,
#endif
#if MYNEWT_VAL(BLE_MESH_GATT_PROXY)
.gatt_proxy = BT_MESH_GATT_PROXY_ENABLED,
#else
.gatt_proxy = BT_MESH_GATT_PROXY_NOT_SUPPORTED,
#endif
.default_ttl = 7,
/* 3 transmissions with 20ms interval */
.net_transmit = BT_MESH_TRANSMIT(2, 20),
.relay_retransmit = BT_MESH_TRANSMIT(2, 20),
};
static void get_faults(u8_t *faults, u8_t faults_size, u8_t *dst, u8_t *count)
static void get_faults(uint8_t *faults, uint8_t faults_size, uint8_t *dst, uint8_t *count)
{
u8_t i, limit = *count;
uint8_t i, limit = *count;
for (i = 0, *count = 0; i < faults_size && *count < limit; i++) {
if (faults[i]) {
@ -153,8 +133,8 @@ static void get_faults(u8_t *faults, u8_t faults_size, u8_t *dst, u8_t *count)
}
}
static int fault_get_cur(struct bt_mesh_model *model, u8_t *test_id,
u16_t *company_id, u8_t *faults, u8_t *fault_count)
static int fault_get_cur(struct bt_mesh_model *model, uint8_t *test_id,
uint16_t *company_id, uint8_t *faults, uint8_t *fault_count)
{
SYS_LOG_DBG("");
@ -166,8 +146,8 @@ static int fault_get_cur(struct bt_mesh_model *model, u8_t *test_id,
return 0;
}
static int fault_get_reg(struct bt_mesh_model *model, u16_t company_id,
u8_t *test_id, u8_t *faults, u8_t *fault_count)
static int fault_get_reg(struct bt_mesh_model *model, uint16_t company_id,
uint8_t *test_id, uint8_t *faults, uint8_t *fault_count)
{
SYS_LOG_DBG("company_id 0x%04x", company_id);
@ -229,7 +209,7 @@ health_pub_init(void)
static struct bt_mesh_cfg_cli cfg_cli = {
};
void show_faults(u8_t test_id, u16_t cid, u8_t *faults, size_t fault_count)
void show_faults(uint8_t test_id, uint16_t cid, uint8_t *faults, size_t fault_count)
{
size_t i;
@ -247,8 +227,8 @@ void show_faults(u8_t test_id, u16_t cid, u8_t *faults, size_t fault_count)
}
}
static void health_current_status(struct bt_mesh_health_cli *cli, u16_t addr,
u8_t test_id, u16_t cid, u8_t *faults,
static void health_current_status(struct bt_mesh_health_cli *cli, uint16_t addr,
uint8_t test_id, uint16_t cid, uint8_t *faults,
size_t fault_count)
{
SYS_LOG_DBG("Health Current Status from 0x%04x", addr);
@ -260,7 +240,7 @@ static struct bt_mesh_health_cli health_cli = {
};
static struct bt_mesh_model root_models[] = {
BT_MESH_MODEL_CFG_SRV(&cfg_srv),
BT_MESH_MODEL_CFG_SRV,
BT_MESH_MODEL_CFG_CLI(&cfg_cli),
BT_MESH_MODEL_HEALTH_SRV(&health_srv, &health_pub),
BT_MESH_MODEL_HEALTH_CLI(&health_cli),
@ -295,7 +275,7 @@ static void link_open(bt_mesh_prov_bearer_t bearer)
}
tester_send(BTP_SERVICE_ID_MESH, MESH_EV_PROV_LINK_OPEN,
CONTROLLER_INDEX, (u8_t *) &ev, sizeof(ev));
CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev));
}
static void link_close(bt_mesh_prov_bearer_t bearer)
@ -318,10 +298,10 @@ static void link_close(bt_mesh_prov_bearer_t bearer)
}
tester_send(BTP_SERVICE_ID_MESH, MESH_EV_PROV_LINK_CLOSED,
CONTROLLER_INDEX, (u8_t *) &ev, sizeof(ev));
CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev));
}
static int output_number(bt_mesh_output_action_t action, u32_t number)
static int output_number(bt_mesh_output_action_t action, uint32_t number)
{
struct mesh_out_number_action_ev ev;
@ -331,7 +311,7 @@ static int output_number(bt_mesh_output_action_t action, u32_t number)
ev.number = sys_cpu_to_le32(number);
tester_send(BTP_SERVICE_ID_MESH, MESH_EV_OUT_NUMBER_ACTION,
CONTROLLER_INDEX, (u8_t *) &ev, sizeof(ev));
CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev));
return 0;
}
@ -357,7 +337,7 @@ static int output_string(const char *str)
return 0;
}
static int input(bt_mesh_input_action_t action, u8_t size)
static int input(bt_mesh_input_action_t action, uint8_t size)
{
struct mesh_in_action_ev ev;
@ -369,12 +349,15 @@ static int input(bt_mesh_input_action_t action, u8_t size)
ev.size = size;
tester_send(BTP_SERVICE_ID_MESH, MESH_EV_IN_ACTION, CONTROLLER_INDEX,
(u8_t *) &ev, sizeof(ev));
(uint8_t *) &ev, sizeof(ev));
return 0;
}
static void prov_complete(u16_t net_idx, u16_t addr)
static uint8_t vnd_app_key[16];
static uint16_t vnd_app_key_idx = 0x000f;
static void prov_complete(uint16_t net_idx, uint16_t addr)
{
SYS_LOG_DBG("net_idx 0x%04x addr 0x%04x", net_idx, addr);
@ -412,7 +395,7 @@ static struct bt_mesh_prov prov = {
.reset = prov_reset,
};
static void config_prov(u8_t *data, u16_t len)
static void config_prov(uint8_t *data, uint16_t len)
{
const struct mesh_config_provisioning_cmd *cmd = (void *) data;
@ -430,7 +413,7 @@ static void config_prov(u8_t *data, u16_t len)
CONTROLLER_INDEX, BTP_STATUS_SUCCESS);
}
static void provision_node(u8_t *data, u16_t len)
static void provision_node(uint8_t *data, uint16_t len)
{
const struct mesh_provision_node_cmd *cmd = (void *) data;
@ -448,9 +431,9 @@ static void provision_node(u8_t *data, u16_t len)
CONTROLLER_INDEX, BTP_STATUS_SUCCESS);
}
static void init(u8_t *data, u16_t len)
static void init(uint8_t *data, uint16_t len)
{
u8_t status = BTP_STATUS_SUCCESS;
uint8_t status = BTP_STATUS_SUCCESS;
int err;
SYS_LOG_DBG("");
@ -475,15 +458,12 @@ static void init(u8_t *data, u16_t len)
}
}
/* Set device key for vendor model */
vnd_models[0].keys[0] = BT_MESH_KEY_DEV;
rsp:
tester_rsp(BTP_SERVICE_ID_MESH, MESH_INIT, CONTROLLER_INDEX,
status);
}
static void reset(u8_t *data, u16_t len)
static void reset(uint8_t *data, uint16_t len)
{
SYS_LOG_DBG("");
@ -493,11 +473,11 @@ static void reset(u8_t *data, u16_t len)
BTP_STATUS_SUCCESS);
}
static void input_number(u8_t *data, u16_t len)
static void input_number(uint8_t *data, uint16_t len)
{
const struct mesh_input_number_cmd *cmd = (void *) data;
u8_t status = BTP_STATUS_SUCCESS;
u32_t number;
uint8_t status = BTP_STATUS_SUCCESS;
uint32_t number;
int err;
number = sys_le32_to_cpu(cmd->number);
@ -513,11 +493,11 @@ static void input_number(u8_t *data, u16_t len)
status);
}
static void input_string(u8_t *data, u16_t len)
static void input_string(uint8_t *data, uint16_t len)
{
const struct mesh_input_string_cmd *cmd = (void *) data;
u8_t status = BTP_STATUS_SUCCESS;
u8_t str_auth[16];
uint8_t status = BTP_STATUS_SUCCESS;
uint8_t str_auth[16];
int err;
SYS_LOG_DBG("");
@ -544,7 +524,7 @@ rsp:
status);
}
static void ivu_test_mode(u8_t *data, u16_t len)
static void ivu_test_mode(uint8_t *data, uint16_t len)
{
const struct mesh_ivu_test_mode_cmd *cmd = (void *) data;
@ -556,7 +536,7 @@ static void ivu_test_mode(u8_t *data, u16_t len)
BTP_STATUS_SUCCESS);
}
static void ivu_toggle_state(u8_t *data, u16_t len)
static void ivu_toggle_state(uint8_t *data, uint16_t len)
{
bool result;
@ -571,7 +551,7 @@ static void ivu_toggle_state(u8_t *data, u16_t len)
result ? BTP_STATUS_SUCCESS : BTP_STATUS_FAILED);
}
static void lpn(u8_t *data, u16_t len)
static void lpn(uint8_t *data, uint16_t len)
{
struct mesh_lpn_set_cmd *cmd = (void *) data;
bool enable;
@ -589,7 +569,7 @@ static void lpn(u8_t *data, u16_t len)
err ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS);
}
static void lpn_poll(u8_t *data, u16_t len)
static void lpn_poll(uint8_t *data, uint16_t len)
{
int err;
@ -604,13 +584,13 @@ static void lpn_poll(u8_t *data, u16_t len)
err ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS);
}
static void net_send(u8_t *data, u16_t len)
static void net_send(uint8_t *data, uint16_t len)
{
struct mesh_net_send_cmd *cmd = (void *) data;
struct os_mbuf *msg = NET_BUF_SIMPLE(UINT8_MAX);
struct os_mbuf *msg = NET_BUF_SIMPLE(UINT8_MAX);
struct bt_mesh_msg_ctx ctx = {
.net_idx = net.net_idx,
.app_idx = BT_MESH_KEY_DEV,
.app_idx = vnd_app_key_idx,
.addr = sys_le16_to_cpu(cmd->dst),
.send_ttl = cmd->ttl,
};
@ -619,6 +599,12 @@ static void net_send(u8_t *data, u16_t len)
SYS_LOG_DBG("ttl 0x%02x dst 0x%04x payload_len %d", ctx.send_ttl,
ctx.addr, cmd->payload_len);
if (!bt_mesh_app_key_get(vnd_app_key_idx)) {
(void)bt_mesh_app_key_add(vnd_app_key_idx, net.net_idx,
vnd_app_key);
vnd_models[0].keys[0] = vnd_app_key_idx;
}
net_buf_simple_add_mem(msg, cmd->payload, cmd->payload_len);
err = bt_mesh_model_send(&vnd_models[0], &ctx, msg, NULL, NULL);
@ -632,13 +618,13 @@ static void net_send(u8_t *data, u16_t len)
os_mbuf_free_chain(msg);
}
static void health_generate_faults(u8_t *data, u16_t len)
static void health_generate_faults(uint8_t *data, uint16_t len)
{
struct mesh_health_generate_faults_rp *rp;
struct os_mbuf *buf = NET_BUF_SIMPLE(sizeof(*rp) + sizeof(cur_faults) +
sizeof(reg_faults));
u8_t some_faults[] = { 0x01, 0x02, 0x03, 0xff, 0x06 };
u8_t cur_faults_count, reg_faults_count;
uint8_t some_faults[] = { 0x01, 0x02, 0x03, 0xff, 0x06 };
uint8_t cur_faults_count, reg_faults_count;
rp = net_buf_simple_add(buf, sizeof(*rp));
@ -658,7 +644,7 @@ static void health_generate_faults(u8_t *data, u16_t len)
CONTROLLER_INDEX, buf);
}
static void health_clear_faults(u8_t *data, u16_t len)
static void health_clear_faults(uint8_t *data, uint16_t len)
{
SYS_LOG_DBG("");
@ -671,7 +657,7 @@ static void health_clear_faults(u8_t *data, u16_t len)
CONTROLLER_INDEX, BTP_STATUS_SUCCESS);
}
static void model_send(u8_t *data, u16_t len)
static void model_send(uint8_t *data, uint16_t len)
{
struct mesh_model_send_cmd *cmd = (void *) data;
struct os_mbuf *msg = NET_BUF_SIMPLE(UINT8_MAX);
@ -683,7 +669,7 @@ static void model_send(u8_t *data, u16_t len)
};
struct bt_mesh_model *model = NULL;
int err, i;
u16_t src = sys_le16_to_cpu(cmd->src);
uint16_t src = sys_le16_to_cpu(cmd->src);
/* Lookup source address */
for (i = 0; i < ARRAY_SIZE(model_bound); i++) {
@ -720,10 +706,10 @@ fail:
}
#if MYNEWT_VAL(BLE_MESH_TESTING)
static void lpn_subscribe(u8_t *data, u16_t len)
static void lpn_subscribe(uint8_t *data, uint16_t len)
{
struct mesh_lpn_subscribe_cmd *cmd = (void *) data;
u16_t address = sys_le16_to_cpu(cmd->address);
uint16_t address = sys_le16_to_cpu(cmd->address);
int err;
SYS_LOG_DBG("address 0x%04x", address);
@ -737,10 +723,10 @@ static void lpn_subscribe(u8_t *data, u16_t len)
err ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS);
}
static void lpn_unsubscribe(u8_t *data, u16_t len)
static void lpn_unsubscribe(uint8_t *data, uint16_t len)
{
struct mesh_lpn_unsubscribe_cmd *cmd = (void *) data;
u16_t address = sys_le16_to_cpu(cmd->address);
uint16_t address = sys_le16_to_cpu(cmd->address);
int err;
SYS_LOG_DBG("address 0x%04x", address);
@ -754,7 +740,7 @@ static void lpn_unsubscribe(u8_t *data, u16_t len)
err ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS);
}
static void rpl_clear(u8_t *data, u16_t len)
static void rpl_clear(uint8_t *data, uint16_t len)
{
int err;
@ -770,7 +756,7 @@ static void rpl_clear(u8_t *data, u16_t len)
}
#endif /* MYNEWT_VAL(BLE_MESH_TESTING) */
static void proxy_identity_enable(u8_t *data, u16_t len)
static void proxy_identity_enable(uint8_t *data, uint16_t len)
{
int err;
@ -785,7 +771,7 @@ static void proxy_identity_enable(u8_t *data, u16_t len)
err ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS);
}
void tester_handle_mesh(u8_t opcode, u8_t index, u8_t *data, u16_t len)
void tester_handle_mesh(uint8_t opcode, uint8_t index, uint8_t *data, uint16_t len)
{
switch (opcode) {
case MESH_READ_SUPPORTED_COMMANDS:
@ -854,7 +840,7 @@ void tester_handle_mesh(u8_t opcode, u8_t index, u8_t *data, u16_t len)
}
}
void net_recv_ev(u8_t ttl, u8_t ctl, u16_t src, u16_t dst, const void *payload,
void net_recv_ev(uint8_t ttl, uint8_t ctl, uint16_t src, uint16_t dst, const void *payload,
size_t payload_len)
{
struct os_mbuf *buf = NET_BUF_SIMPLE(UINT8_MAX);
@ -883,8 +869,8 @@ done:
os_mbuf_free_chain(buf);
}
static void model_bound_cb(u16_t addr, struct bt_mesh_model *model,
u16_t key_idx)
static void model_bound_cb(uint16_t addr, struct bt_mesh_model *model,
uint16_t key_idx)
{
int i;
@ -904,8 +890,8 @@ static void model_bound_cb(u16_t addr, struct bt_mesh_model *model,
SYS_LOG_ERR("model_bound is full");
}
static void model_unbound_cb(u16_t addr, struct bt_mesh_model *model,
u16_t key_idx)
static void model_unbound_cb(uint16_t addr, struct bt_mesh_model *model,
uint16_t key_idx)
{
int i;
@ -925,7 +911,7 @@ static void model_unbound_cb(u16_t addr, struct bt_mesh_model *model,
SYS_LOG_INF("model not found");
}
static void invalid_bearer_cb(u8_t opcode)
static void invalid_bearer_cb(uint8_t opcode)
{
struct mesh_invalid_bearer_ev ev = {
.opcode = opcode,
@ -934,7 +920,7 @@ static void invalid_bearer_cb(u8_t opcode)
SYS_LOG_DBG("opcode 0x%02x", opcode);
tester_send(BTP_SERVICE_ID_MESH, MESH_EV_INVALID_BEARER,
CONTROLLER_INDEX, (u8_t *) &ev, sizeof(ev));
CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev));
}
static void incomp_timer_exp_cb(void)
@ -951,7 +937,7 @@ static struct bt_test_cb bt_test_cb = {
.mesh_trans_incomp_timer_exp = incomp_timer_exp_cb,
};
u8_t tester_init_mesh(void)
uint8_t tester_init_mesh(void)
{
health_pub_init();
@ -962,7 +948,7 @@ u8_t tester_init_mesh(void)
return BTP_STATUS_SUCCESS;
}
u8_t tester_unregister_mesh(void)
uint8_t tester_unregister_mesh(void)
{
return BTP_STATUS_SUCCESS;
}

View file

@ -31,7 +31,7 @@ static struct hal_timer rtt_timer;
static bttester_pipe_recv_cb app_cb;
static u8_t *recv_buf;
static uint8_t *recv_buf;
static size_t recv_buf_len;
static size_t recv_off;
@ -74,7 +74,7 @@ rtt_pipe_poll_func(void *arg)
itvl_ms = min(itvl_ms, RTT_INPUT_POLL_INTERVAL_MAX);
} else {
while (key >= 0 && avail > 0) {
recv_buf[recv_off] = (u8_t) key;
recv_buf[recv_off] = (uint8_t) key;
recv_off++;
avail = recv_buf_len - recv_off;
key = rtt_pipe_get_char((unsigned int) rtt_index_down);
@ -93,14 +93,14 @@ rtt_pipe_poll_func(void *arg)
}
int
bttester_pipe_send(const u8_t *data, int len)
bttester_pipe_send(const uint8_t *data, int len)
{
SEGGER_RTT_Write((unsigned int) rtt_index_up, data, (unsigned int) len);
return 0;
}
void
bttester_pipe_register(u8_t *buf, size_t len, bttester_pipe_recv_cb cb)
bttester_pipe_register(uint8_t *buf, size_t len, bttester_pipe_recv_cb cb)
{
recv_buf = buf;
recv_buf_len = len;

View file

@ -26,7 +26,7 @@
#include "bttester_pipe.h"
static u8_t *recv_buf;
static uint8_t *recv_buf;
static size_t recv_buf_len;
static bttester_pipe_recv_cb app_cb;
static size_t recv_off;
@ -144,7 +144,7 @@ uart_console_rx_char(void *arg, uint8_t byte)
static int
uart_pipe_handle_char(int key)
{
recv_buf[recv_off] = (u8_t) key;
recv_buf[recv_off] = (uint8_t) key;
recv_off++;
return 0;
@ -194,7 +194,7 @@ uart_console_rx_char_event(struct os_event *ev)
}
int
bttester_pipe_send(const u8_t *data, int len)
bttester_pipe_send(const uint8_t *data, int len)
{
int i;
@ -272,7 +272,7 @@ bttester_pipe_init(void)
}
void
bttester_pipe_register(u8_t *buf, size_t len, bttester_pipe_recv_cb cb)
bttester_pipe_register(uint8_t *buf, size_t len, bttester_pipe_recv_cb cb)
{
recv_buf = buf;
recv_buf_len = len;

View file

@ -53,7 +53,7 @@ syscfg.defs:
BTTESTER_CONN_RETRY:
description: Retry connections when connection failed to be established
value: 3
value: 0
BTTESTER_BTP_DATA_SIZE_MAX:
description: Maximum BTP payload
@ -71,12 +71,16 @@ syscfg.defs:
description: Enable logging BTP traffic
value: 0
BTTESTER_L2CAP_COC_MTU:
description: Maximum MTU size the application can handle
value: 230
syscfg.vals:
OS_MAIN_STACK_SIZE: 512
SHELL_TASK: 0
SHELL_NEWTMGR: 0
LOG_LEVEL: 12
MSYS_1_BLOCK_COUNT: 48
MSYS_1_BLOCK_COUNT: 80
BLE_MONITOR_RTT: 1
CONSOLE_RTT: 0
@ -86,6 +90,8 @@ syscfg.vals:
BLE_L2CAP_COC_MAX_NUM: 2
BLE_L2CAP_SIG_MAX_PROCS: 2
BLE_L2CAP_ENHANCED_COC: 1
BLE_VERSION: 52
# Some testcases require MPS < MTU
BLE_L2CAP_COC_MPS: 100
BLE_RPA_TIMEOUT: 30
@ -98,6 +104,9 @@ syscfg.vals:
BLE_SVC_GAP_PPCP_MIN_CONN_INTERVAL: 9
BLE_SVC_GAP_PPCP_MAX_CONN_INTERVAL: 30
BLE_SVC_GAP_PPCP_SUPERVISION_TMO: 2000
BLE_SVC_GAP_APPEARANCE_WRITE_PERM: 0
BLE_SVC_GAP_DEVICE_NAME_WRITE_PERM: 0
BLE_STORE_CONFIG_PERSIST: 0
BLE_MESH: 1
BLE_MESH_SHELL: 0
@ -117,6 +126,11 @@ syscfg.vals:
BLE_MESH_FRIEND: 1
BLE_MESH_CFG_CLI: 1
BLE_MESH_RX_SDU_MAX: 110
BLE_MESH_HEALTH_CLI: 1
BLE_MESH_FRIEND_QUEUE_SIZE: 32
BLE_MESH_RX_SEG_MAX: 13
BLE_MESH_TX_SEG_MSG_COUNT: 2
BLE_MAX_CONNECTIONS: 8
BLE_MESH_ADV_BUF_COUNT: 20
BLE_MESH_TX_SEG_MAX: 6

View file

@ -0,0 +1,34 @@
#
# 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.
#
pkg.name: "apps/central"
pkg.type: app
pkg.description: "Basic central application"
pkg.author: "Krzysztof Kopyściński <krzysztof.kopyscinski@codecoup.pl>"
pkg.deps:
- "@apache-mynewt-core/kernel/os"
- "@apache-mynewt-core/sys/console/full"
- "@apache-mynewt-core/sys/log/full"
- "@apache-mynewt-core/sys/stats/full"
- "@apache-mynewt-core/sys/log/modlog"
- "@apache-mynewt-nimble/nimble/host"
- "@apache-mynewt-nimble/nimble/host/util/"
- "@apache-mynewt-nimble/nimble/host/store/config"
- "@apache-mynewt-nimble/nimble/transport"

View file

@ -0,0 +1,186 @@
/*
* 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 "sysinit/sysinit.h"
#include "os/os.h"
#include "console/console.h"
#include "host/ble_hs.h"
#include "host/util/util.h"
#include "console/console.h"
#include "log/log.h"
static uint8_t g_own_addr_type;
static void
ble_app_set_addr(void)
{
ble_addr_t addr;
int rc;
/* generate new non-resolvable private address */
rc = ble_hs_id_gen_rnd(0, &addr);
assert(rc == 0);
/* set generated address */
rc = ble_hs_id_set_rnd(addr.val);
assert(rc == 0);
}
/* scan_event() calls scan(), so forward declaration is required */
static void scan(void);
/* connection has separate event handler from scan */
static int
conn_event(struct ble_gap_event *event, void *arg)
{
switch (event->type) {
case BLE_GAP_EVENT_CONNECT:
if (event->connect.status == 0) {
MODLOG_DFLT(INFO,"Connection was established\n");
ble_gap_terminate(event->connect.conn_handle, 0x13);
} else {
MODLOG_DFLT(INFO,"Connection failed, error code: %i\n",
event->connect.status);
}
break;
case BLE_GAP_EVENT_DISCONNECT:
MODLOG_DFLT(INFO,"Disconnected, reason code: %i\n",
event->disconnect.reason);
scan();
break;
case BLE_GAP_EVENT_CONN_UPDATE_REQ:
MODLOG_DFLT(INFO,"Connection update request received\n");
break;
case BLE_GAP_EVENT_CONN_UPDATE:
if (event->conn_update.status == 0) {
MODLOG_DFLT(INFO,"Connection update successful\n");
} else {
MODLOG_DFLT(INFO,"Connection update failed; reson: %d\n",
event->conn_update.status);
}
break;
default:
MODLOG_DFLT(INFO,"Connection event type not supported, %d\n",
event->type);
break;
}
return 0;
}
static int
scan_event(struct ble_gap_event *event, void *arg)
{
/* predef_uuid stores information about UUID of device,
that we connect to */
const ble_uuid128_t predef_uuid =
BLE_UUID128_INIT(0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff);
struct ble_hs_adv_fields parsed_fields;
int uuid_cmp_result;
memset(&parsed_fields, 0, sizeof(parsed_fields));
switch (event->type) {
/* advertising report has been received during discovery procedure */
case BLE_GAP_EVENT_DISC:
MODLOG_DFLT(INFO, "Advertising report received! Checking UUID...\n");
ble_hs_adv_parse_fields(&parsed_fields, event->disc.data,
event->disc.length_data);
/* Predefined UUID is compared to recieved one;
if doesn't fit - end procedure and go back to scanning,
else - connect. */
uuid_cmp_result = ble_uuid_cmp(&predef_uuid.u, &parsed_fields.uuids128->u);
if (uuid_cmp_result) {
MODLOG_DFLT(INFO, "UUID doesn't fit\n");
} else {
MODLOG_DFLT(INFO, "UUID fits, connecting...\n");
ble_gap_disc_cancel();
ble_gap_connect(g_own_addr_type, &(event->disc.addr), 10000,
NULL, conn_event, NULL);
}
break;
case BLE_GAP_EVENT_DISC_COMPLETE:
MODLOG_DFLT(INFO,"Discovery completed, reason: %d\n",
event->disc_complete.reason);
scan();
break;
default:
MODLOG_DFLT(ERROR, "Discovery event not handled\n");
break;
}
return 0;
}
static void
scan(void)
{
int rc;
/* set scan parameters:
- scan interval in 0.625ms units
- scan window in 0.625ms units
- filter policy - 0 if whitelisting not used
- limited - should limited discovery be used
- passive - should passive scan be used
- filter duplicates - 1 enables filtering duplicated advertisements */
const struct ble_gap_disc_params scan_params = {10000, 200, 0, 0, 0, 1};
/* performs discovery procedure */
rc = ble_gap_disc(g_own_addr_type, 10000, &scan_params,scan_event, NULL);
assert(rc == 0);
}
static void
on_sync(void)
{
int rc;
/* Generate a non-resolvable private address. */
ble_app_set_addr();
/* g_own_addr_type will store type of addres our BSP uses */
rc = ble_hs_util_ensure_addr(0);
rc = ble_hs_id_infer_auto(0, &g_own_addr_type);
assert(rc == 0);
/* begin scanning */
scan();
}
static void
on_reset(int reason)
{
console_printf("Resetting state; reason=%d\n", reason);
}
int
main(int argc, char **argv)
{
/* Initialize all packages. */
sysinit();
ble_hs_cfg.sync_cb = on_sync;
ble_hs_cfg.reset_cb = on_reset;
/* As the last thing, process events from default event queue. */
while (1) {
os_eventq_run(os_eventq_dflt_get());
}
return 0;
}

View file

@ -0,0 +1,48 @@
### Mesh Badge
##### Overview
********
This sample app for the reel board showcases Bluetooth Mesh
The app starts off as a regular Bluetooth GATT peripheral application.
Install the the "nRF Connect" app on your phone (available both for
Android and iOS) to access the service that the app exposes. The service
can also be accessed with any Bluetooth LE GATT client from your PC,
however these instructions focus on the necessary steps for phones.
##### Steps to set up
***************
* On your phone, use the nRF Connect app to Scan for devices and look
for "reel board"
* Connect to the device. You'll see a single service - select it
* Request to write to the characteristic by pressing on the upward pointing
arrow symbol
* Select "Text" to enter text instead of hex
* Enter your name (or any other arbitrary text). Multiple words
separated by spaces are possible. The font used on the reel display
allows three rows of up to 12 characters
wide text. You can force line breaks with a comma.
* Press "Send" - this will trigger pairing since this is a protected
characteristic. The passkey for the pairing will be shown on the board's
display. Enter the passkey in your phone.
* Once pairing is complete the board will show the text you sent. If
you're not happy with it you can try writing something else.
* When you're happy with the text, disconnect from the board (exit the app or
go back to the device scan page)
* Once disconnected the board switches over to Bluetooth Mesh mode, and you
can't connect to it anymore over GATT.
If you configure multiple boards like this they can communicate with
each other over mesh: by pressing the user button on the board the first
word (name) of the stored text will be sent to all other boards in
the network and cause the other boards to display "<name> says hi!".
To reset a board to its initial state (disable mesh, erase the stored
text, and make it connectable over GATT):
* Keep the user button pressed when powering on (or press the reset button
when powered)
* Wait until "Reseting Device" is shown

View file

@ -0,0 +1,39 @@
# 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.
#
pkg.name: apps/mesh_badge
pkg.type: app
pkg.description: Sample app for the reel board that showcases Bluetooth Mesh
pkg.author: "Apache Mynewt <dev@mynewt.apache.org>"
pkg.homepage: "http://mynewt.apache.org/"
pkg.keywords:
pkg.deps:
- "@apache-mynewt-core/hw/drivers/display/cfb"
- "@apache-mynewt-core/hw/drivers/display/ssd1673"
- "@apache-mynewt-core/kernel/os"
- "@apache-mynewt-core/sys/console/full"
- "@apache-mynewt-core/sys/log/full"
- "@apache-mynewt-core/sys/log/modlog"
- "@apache-mynewt-core/sys/stats/full"
- "@apache-mynewt-core/sys/shell"
- nimble/controller
- nimble/host
- nimble/host/services/gap
- nimble/host/services/gatt
- nimble/host/store/config
- nimble/transport/ram

View file

@ -0,0 +1,15 @@
/*
* Copyright (c) 2018 Phytec Messtechnik GmbH
* Copyright (c) 2018 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "mesh/mesh.h"
void board_refresh_display(void);
void board_show_text(const char *text, bool center, int32_t duration);
void board_blink_leds(void);
void board_add_hello(uint16_t addr, const char *name);
void board_add_heartbeat(uint16_t addr, uint8_t hops);
int board_init(void);

View file

@ -0,0 +1,226 @@
/*
* 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 <assert.h>
#include <stdio.h>
#include <string.h>
#include "services/gap/ble_svc_gap.h"
#include "bsp/bsp.h"
#include "host/ble_hs.h"
#include "host/ble_uuid.h"
#include "mesh.h"
#include "board.h"
#include "mesh_badge.h"
static const ble_uuid16_t gatt_cud_uuid = BLE_UUID16_INIT(0x2901);
static const ble_uuid16_t gatt_cpf_uuid = BLE_UUID16_INIT(0x2904);
/** @brief GATT Characteristic Presentation Format Attribute Value. */
struct bt_gatt_cpf {
/** Format of the value of the characteristic */
uint8_t format;
/** Exponent field to determine how the value of this characteristic is further formatted */
int8_t exponent;
/** Unit of the characteristic */
uint16_t unit;
/** Name space of the description */
uint8_t name_space;
/** Description of the characteristic as defined in a higher layer profile */
uint16_t description;
} __packed;
#define CPF_FORMAT_UTF8 0x19
static const struct bt_gatt_cpf name_cpf = {
.format = CPF_FORMAT_UTF8,
};
static const ble_uuid128_t name_uuid = BLE_UUID128_INIT(
0xf0, 0xde, 0xbc, 0x9a, 0x78, 0x56, 0x34, 0x12,
0x78, 0x56, 0x34, 0x12, 0x78, 0x56, 0x34, 0x12);
static const ble_uuid128_t name_enc_uuid = BLE_UUID128_INIT(
0xf1, 0xde, 0xbc, 0x9a, 0x78, 0x56, 0x34, 0x12,
0x78, 0x56, 0x34, 0x12, 0x78, 0x56, 0x34, 0x12);
static int
gatt_svr_chr_access(uint16_t conn_handle, uint16_t attr_handle,
struct ble_gatt_access_ctxt *ctxt,
void *arg);
static const struct ble_gatt_svc_def gatt_svr_svcs[] = {
{
.type = BLE_GATT_SVC_TYPE_PRIMARY,
.uuid = &name_uuid.u,
.characteristics = (struct ble_gatt_chr_def[]) { {
.uuid = &name_enc_uuid.u,
.access_cb = gatt_svr_chr_access,
.flags = BLE_GATT_CHR_F_READ |
BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_WRITE_ENC,
.descriptors = (struct ble_gatt_dsc_def[]) { {
.uuid = &gatt_cud_uuid.u,
.access_cb = gatt_svr_chr_access,
.att_flags = BLE_ATT_F_READ,
}, {
.uuid = &gatt_cpf_uuid.u,
.access_cb = gatt_svr_chr_access,
.att_flags = BLE_ATT_F_READ,
}, {
0, /* No more descriptors in this characteristic. */
} }
}, {
0, /* No more characteristics in this service. */
} },
},
{
0, /* No more services. */
},
};
static int read_name(struct os_mbuf *om)
{
const char *value = bt_get_name();
int rc;
rc = os_mbuf_append(om, value, (uint16_t) strlen(value));
return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
}
static int write_name(struct os_mbuf *om)
{
char name[MYNEWT_VAL(BLE_SVC_GAP_DEVICE_NAME_MAX_LENGTH)];
uint16_t len;
uint16_t om_len;
int rc;
om_len = OS_MBUF_PKTLEN(om);
if (om_len >= sizeof(name)) {
return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
}
rc = ble_hs_mbuf_to_flat(om, name, sizeof(name) - 1, &len);
if (rc != 0) {
return BLE_ATT_ERR_UNLIKELY;
}
name[len] = '\0';
rc = bt_set_name(name);
if (rc) {
return BLE_ATT_ERR_INSUFFICIENT_RES;
}
board_refresh_display();
return 0;
}
static int
gatt_svr_chr_access(uint16_t conn_handle, uint16_t attr_handle,
struct ble_gatt_access_ctxt *ctxt,
void *arg)
{
const ble_uuid_t *uuid;
int rc;
uuid = ctxt->chr->uuid;
if (ble_uuid_cmp(uuid, &name_enc_uuid.u) == 0) {
switch (ctxt->op) {
case BLE_GATT_ACCESS_OP_READ_CHR:
rc = read_name(ctxt->om);
return rc;
case BLE_GATT_ACCESS_OP_WRITE_CHR:
rc = write_name(ctxt->om);
return rc;
default:
assert(0);
return BLE_ATT_ERR_UNLIKELY;
}
} else if (ble_uuid_cmp(uuid, &gatt_cud_uuid.u) == 0) {
rc = os_mbuf_append(ctxt->om, "Badge Name",
(uint16_t) strlen("Badge Name"));
return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
} else if (ble_uuid_cmp(uuid, &gatt_cpf_uuid.u) == 0) {
rc = os_mbuf_append(ctxt->om, &name_cpf,
(uint16_t) sizeof(name_cpf));
return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
}
/* Unknown characteristic; the nimble stack should not have called this
* function.
*/
assert(0);
return BLE_ATT_ERR_UNLIKELY;
}
void
gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg)
{
char buf[BLE_UUID_STR_LEN];
switch (ctxt->op) {
case BLE_GATT_REGISTER_OP_SVC:
MODLOG_DFLT(DEBUG, "registered service %s with handle=%d\n",
ble_uuid_to_str(ctxt->svc.svc_def->uuid, buf),
ctxt->svc.handle);
break;
case BLE_GATT_REGISTER_OP_CHR:
MODLOG_DFLT(DEBUG, "registering characteristic %s with "
"def_handle=%d val_handle=%d\n",
ble_uuid_to_str(ctxt->chr.chr_def->uuid, buf),
ctxt->chr.def_handle,
ctxt->chr.val_handle);
break;
case BLE_GATT_REGISTER_OP_DSC:
MODLOG_DFLT(DEBUG, "registering descriptor %s with handle=%d\n",
ble_uuid_to_str(ctxt->dsc.dsc_def->uuid, buf),
ctxt->dsc.handle);
break;
default:
assert(0);
break;
}
}
int
gatt_svr_init(void)
{
int rc;
rc = ble_gatts_count_cfg(gatt_svr_svcs);
if (rc != 0) {
return rc;
}
rc = ble_gatts_add_svcs(gatt_svr_svcs);
if (rc != 0) {
return rc;
}
return 0;
}

View file

@ -0,0 +1,393 @@
/*
* Copyright (c) 2018 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "console/console.h"
#include "host/ble_gap.h"
#include "mesh/glue.h"
#include "services/gap/ble_svc_gap.h"
#include "base64/base64.h"
#include "mesh_badge.h"
#include "mesh.h"
#include "board.h"
static char badge_name[MYNEWT_VAL(BLE_SVC_GAP_DEVICE_NAME_MAX_LENGTH)];
#define MESH_BADGE_NAME_ENCODE_SIZE \
BASE64_ENCODE_SIZE(sizeof(badge_name))
static bool reset_mesh;
void print_addr(const void *addr)
{
const uint8_t *u8p;
u8p = addr;
MODLOG_DFLT(INFO, "%02x:%02x:%02x:%02x:%02x:%02x",
u8p[5], u8p[4], u8p[3], u8p[2], u8p[1], u8p[0]);
}
static void
print_conn_desc(struct ble_gap_conn_desc *desc)
{
MODLOG_DFLT(INFO, "handle=%d our_ota_addr_type=%d our_ota_addr=",
desc->conn_handle, desc->our_ota_addr.type);
print_addr(desc->our_ota_addr.val);
MODLOG_DFLT(INFO, " our_id_addr_type=%d our_id_addr=",
desc->our_id_addr.type);
print_addr(desc->our_id_addr.val);
MODLOG_DFLT(INFO, " peer_ota_addr_type=%d peer_ota_addr=",
desc->peer_ota_addr.type);
print_addr(desc->peer_ota_addr.val);
MODLOG_DFLT(INFO, " peer_id_addr_type=%d peer_id_addr=",
desc->peer_id_addr.type);
print_addr(desc->peer_id_addr.val);
MODLOG_DFLT(INFO, " conn_itvl=%d conn_latency=%d supervision_timeout=%d "
"encrypted=%d authenticated=%d bonded=%d\n",
desc->conn_itvl, desc->conn_latency,
desc->supervision_timeout,
desc->sec_state.encrypted,
desc->sec_state.authenticated,
desc->sec_state.bonded);
}
static int gap_event(struct ble_gap_event *event, void *arg);
static void advertise(void)
{
uint8_t own_addr_type;
struct ble_gap_adv_params adv_params;
struct ble_hs_adv_fields fields;
const char *name;
int rc;
/* Figure out address to use while advertising (no privacy for now) */
rc = ble_hs_id_infer_auto(0, &own_addr_type);
if (rc != 0) {
MODLOG_DFLT(ERROR, "error determining address type; rc=%d\n", rc);
return;
}
/**
* Set the advertisement data included in our advertisements:
* o Flags (indicates advertisement type and other general info).
* o Advertising tx power.
* o Device name.
* o 16-bit service UUIDs (alert notifications).
*/
memset(&fields, 0, sizeof fields);
/* Advertise two flags:
* o Discoverability in forthcoming advertisement (general)
* o BLE-only (BR/EDR unsupported).
*/
fields.flags = BLE_HS_ADV_F_DISC_GEN |
BLE_HS_ADV_F_BREDR_UNSUP;
#if 0
/* Indicate that the TX power level field should be included; have the
* stack fill this value automatically. This is done by assiging the
* special value BLE_HS_ADV_TX_PWR_LVL_AUTO.
*/
fields.tx_pwr_lvl_is_present = 1;
fields.tx_pwr_lvl = BLE_HS_ADV_TX_PWR_LVL_AUTO;
#endif
name = ble_svc_gap_device_name();
fields.name = (uint8_t *)name;
fields.name_len = (uint8_t) strlen(name);
fields.name_is_complete = 1;
rc = ble_gap_adv_set_fields(&fields);
if (rc != 0) {
MODLOG_DFLT(ERROR, "error setting advertisement data; rc=%d\n", rc);
return;
}
/* Begin advertising. */
memset(&adv_params, 0, sizeof adv_params);
adv_params.conn_mode = BLE_GAP_CONN_MODE_UND;
adv_params.disc_mode = BLE_GAP_DISC_MODE_GEN;
rc = ble_gap_adv_start(own_addr_type, NULL, BLE_HS_FOREVER,
&adv_params, gap_event, NULL);
if (rc != 0) {
MODLOG_DFLT(ERROR, "error enabling advertisement; rc=%d\n", rc);
return;
}
}
static void passkey_display(uint16_t conn_handle)
{
char buf[20];
struct ble_sm_io pk;
int rc;
bt_rand(&pk.passkey, sizeof(pk.passkey));
/* Max value is 999999 */
pk.passkey %= 1000000;
pk.action = BLE_SM_IOACT_DISP;
rc = ble_sm_inject_io(conn_handle, &pk);
assert(rc == 0);
snprintk(buf, sizeof(buf), "Passkey:\n%06lu", pk.passkey);
printk("%s\n", buf);
board_show_text(buf, false, K_FOREVER);
}
static void pairing_complete(uint16_t conn_handle, bool bonded)
{
printk("Pairing Complete\n");
board_show_text("Pairing Complete", false, K_SECONDS(2));
}
static void pairing_failed(uint16_t conn_handle)
{
printk("Pairing Failed\n");
board_show_text("Pairing Failed", false, K_SECONDS(2));
}
static void connected(uint16_t conn_handle, int err)
{
printk("Connected (err 0x%02x)\n", err);
if (err) {
board_show_text("Connection failed", false, K_SECONDS(2));
} else {
board_show_text("Connected", false, K_FOREVER);
}
}
static void disconnected(uint16_t conn_handle, int reason)
{
printk("Disconnected (reason 0x%02x)\n", reason);
if (strcmp(MYNEWT_VAL(BLE_SVC_GAP_DEVICE_NAME), bt_get_name()) != 0 &&
!mesh_is_initialized()) {
/* Mesh will take over advertising control */
ble_gap_adv_stop();
mesh_start();
} else {
board_show_text("Disconnected", false, K_SECONDS(2));
}
}
static int gap_event(struct ble_gap_event *event, void *arg)
{
struct ble_gap_conn_desc desc;
int rc;
switch (event->type) {
case BLE_GAP_EVENT_CONNECT:
/* A new connection was established or a connection attempt failed. */
MODLOG_DFLT(INFO, "connection %s; status=%d ",
event->connect.status == 0 ? "established" : "failed",
event->connect.status);
if (event->connect.status == 0) {
rc = ble_gap_conn_find(event->connect.conn_handle, &desc);
assert(rc == 0);
print_conn_desc(&desc);
connected(event->connect.conn_handle,
event->connect.status);
}
MODLOG_DFLT(INFO, "\n");
if (event->connect.status != 0) {
/* Connection failed; resume advertising. */
advertise();
}
return 0;
case BLE_GAP_EVENT_DISCONNECT:
MODLOG_DFLT(INFO, "disconnect; reason=%d ", event->disconnect.reason);
print_conn_desc(&event->disconnect.conn);
MODLOG_DFLT(INFO, "\n");
/* Connection terminated; resume advertising. */
advertise();
disconnected(event->disconnect.conn.conn_handle,
event->disconnect.reason);
return 0;
case BLE_GAP_EVENT_CONN_UPDATE:
/* The central has updated the connection parameters. */
MODLOG_DFLT(INFO, "connection updated; status=%d ",
event->conn_update.status);
rc = ble_gap_conn_find(event->connect.conn_handle, &desc);
assert(rc == 0);
print_conn_desc(&desc);
MODLOG_DFLT(INFO, "\n");
return 0;
case BLE_GAP_EVENT_ENC_CHANGE:
/* Encryption has been enabled or disabled for this connection. */
MODLOG_DFLT(INFO, "encryption change event; status=%d ",
event->enc_change.status);
rc = ble_gap_conn_find(event->connect.conn_handle, &desc);
assert(rc == 0);
print_conn_desc(&desc);
MODLOG_DFLT(INFO, "\n");
if (desc.sec_state.bonded) {
pairing_complete(event->enc_change.conn_handle, true);
} else if(desc.sec_state.encrypted) {
pairing_complete(event->enc_change.conn_handle, false);
} else {
pairing_failed(event->enc_change.conn_handle);
}
return 0;
case BLE_GAP_EVENT_PASSKEY_ACTION:
MODLOG_DFLT(INFO, "passkey action event; conn_handle=%d action=%d numcmp=%d\n",
event->passkey.conn_handle,
event->passkey.params.action,
event->passkey.params.numcmp);
passkey_display(event->passkey.conn_handle);
return 0;
case BLE_GAP_EVENT_REPEAT_PAIRING:
/* We already have a bond with the peer, but it is attempting to
* establish a new secure link. This app sacrifices security for
* convenience: just throw away the old bond and accept the new link.
*/
/* Delete the old bond. */
rc = ble_gap_conn_find(event->repeat_pairing.conn_handle, &desc);
assert(rc == 0);
ble_store_util_delete_peer(&desc.peer_id_addr);
/* Return BLE_GAP_REPEAT_PAIRING_RETRY to indicate that the host should
* continue with the pairing operation.
*/
return BLE_GAP_REPEAT_PAIRING_RETRY;
}
return 0;
}
static void on_sync(void)
{
int err;
ble_addr_t addr;
/* Use NRPA */
err = ble_hs_id_gen_rnd(1, &addr);
assert(err == 0);
err = ble_hs_id_set_rnd(addr.val);
assert(err == 0);
printk("Bluetooth initialized\n");
err = mesh_init(addr.type);
if (err) {
printk("Initializing mesh failed (err %d)\n", err);
return;
}
printk("Mesh initialized\n");
if (IS_ENABLED(CONFIG_SETTINGS)) {
settings_load();
}
if (reset_mesh) {
bt_mesh_reset();
reset_mesh = false;
}
if (!mesh_is_initialized()) {
advertise();
} else {
printk("Already provisioned\n");
ble_svc_gap_device_name_set(bt_get_name());
}
board_refresh_display();
printk("Board started\n");
}
void schedule_mesh_reset(void)
{
reset_mesh = true;
}
static void on_reset(int reason)
{
MODLOG_DFLT(ERROR, "Resetting state; reason=%d\n", reason);
}
const char *bt_get_name(void)
{
char buf[MESH_BADGE_NAME_ENCODE_SIZE];
int rc, len;
rc = conf_get_stored_value("mesh_badge/badge_name",
buf, sizeof(buf));
if (rc == OS_ENOENT) {
bt_set_name(MYNEWT_VAL(BLE_SVC_GAP_DEVICE_NAME));
} else {
assert(rc == 0);
}
memset(badge_name, '\0', sizeof(badge_name));
len = base64_decode(buf, badge_name);
if (len < 0) {
bt_set_name(MYNEWT_VAL(BLE_SVC_GAP_DEVICE_NAME));
}
return badge_name;
}
int bt_set_name(const char *name)
{
char buf[MESH_BADGE_NAME_ENCODE_SIZE];
int rc;
memset(badge_name, '\0', sizeof(badge_name));
memcpy(badge_name, name, strlen(name));
base64_encode(badge_name, sizeof(badge_name), buf, 1);
rc = conf_save_one("mesh_badge/badge_name", buf);
assert(rc == 0);
return 0;
}
int main(void)
{
int err;
/* Initialize OS */
sysinit();
err = board_init();
if (err) {
printk("board init failed (err %d)\n", err);
assert(err == 0);
}
/* Initialize the NimBLE host configuration. */
ble_hs_cfg.reset_cb = on_reset;
ble_hs_cfg.sync_cb = on_sync;
ble_hs_cfg.gatts_register_cb = gatt_svr_register_cb;
ble_hs_cfg.store_status_cb = ble_store_util_status_rr;
ble_hs_cfg.sm_io_cap = BLE_SM_IO_CAP_DISP_ONLY;
err = gatt_svr_init();
assert(err == 0);
/*
* As the last thing, process events from default event queue.
*/
while (1) {
os_eventq_run(os_eventq_dflt_get());
}
return 0;
}

View file

@ -0,0 +1,313 @@
/*
* Copyright (c) 2018 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "console/console.h"
#include "mesh/mesh.h"
#include "mesh_badge.h"
#include "mesh.h"
#include "board.h"
#define BT_COMP_ID_LF 0x05f1
#define MOD_LF 0x0000
#define OP_HELLO 0xbb
#define OP_HEARTBEAT 0xbc
#define OP_VND_HELLO BT_MESH_MODEL_OP_3(OP_HELLO, BT_COMP_ID_LF)
#define OP_VND_HEARTBEAT BT_MESH_MODEL_OP_3(OP_HEARTBEAT, BT_COMP_ID_LF)
#define DEFAULT_TTL 31
#define GROUP_ADDR 0xc123
#define NET_IDX 0x000
#define APP_IDX 0x000
#define FLAGS 0
static struct ble_npl_callout hello_work;
static struct ble_npl_callout mesh_start_work;
static void heartbeat(const struct bt_mesh_hb_sub *sub, uint8_t hops,
uint16_t feat)
{
board_show_text("Heartbeat Received", false, K_SECONDS(2));
}
static struct bt_mesh_cfg_cli cfg_cli = {
};
static void attention_on(struct bt_mesh_model *model)
{
board_show_text("Attention!", false, K_SECONDS(2));
}
static void attention_off(struct bt_mesh_model *model)
{
board_refresh_display();
}
static const struct bt_mesh_health_srv_cb health_srv_cb = {
.attn_on = attention_on,
.attn_off = attention_off,
};
static struct bt_mesh_health_srv health_srv = {
.cb = &health_srv_cb,
};
static struct os_mbuf *bt_mesh_pub_msg_health_pub;
static struct bt_mesh_model_pub health_pub;
static struct bt_mesh_model root_models[] = {
BT_MESH_MODEL_CFG_SRV,
BT_MESH_MODEL_CFG_CLI(&cfg_cli),
BT_MESH_MODEL_HEALTH_SRV(&health_srv, &health_pub),
};
static void vnd_hello(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct os_mbuf *buf)
{
char str[32];
size_t len;
printk("Hello message from 0x%04x\n", ctx->addr);
if (ctx->addr == bt_mesh_model_elem(model)->addr) {
printk("Ignoring message from self\n");
return;
}
len = min(buf->om_len, 8);
memcpy(str, buf->om_data, len);
str[len] = '\0';
board_add_hello(ctx->addr, str);
strcpy(str + len, " says hi!");
board_show_text(str, false, K_SECONDS(3));
board_blink_leds();
}
static void vnd_heartbeat(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct os_mbuf *buf)
{
uint8_t init_ttl, hops;
/* Ignore messages from self */
if (ctx->addr == bt_mesh_model_elem(model)->addr) {
return;
}
init_ttl = net_buf_simple_pull_u8(buf);
hops = init_ttl - ctx->recv_ttl + 1;
printk("Heartbeat from 0x%04x over %u hop%s\n", ctx->addr,
hops, hops == 1 ? "" : "s");
board_add_heartbeat(ctx->addr, hops);
}
static const struct bt_mesh_model_op vnd_ops[] = {
{ OP_VND_HELLO, 1, vnd_hello },
{ OP_VND_HEARTBEAT, 1, vnd_heartbeat },
BT_MESH_MODEL_OP_END,
};
static int pub_update(struct bt_mesh_model *mod)
{
struct os_mbuf *msg = mod->pub->msg;
printk("Preparing to send heartbeat\n");
bt_mesh_model_msg_init(msg, OP_VND_HEARTBEAT);
net_buf_simple_add_u8(msg, DEFAULT_TTL);
return 0;
}
static struct os_mbuf *bt_mesh_pub_msg_vnd_pub;
static struct bt_mesh_model_pub vnd_pub;
static struct bt_mesh_model vnd_models[] = {
BT_MESH_MODEL_VND(BT_COMP_ID_LF, MOD_LF, vnd_ops, &vnd_pub, NULL),
};
static struct bt_mesh_elem elements[] = {
BT_MESH_ELEM(0, root_models, vnd_models),
};
static const struct bt_mesh_comp comp = {
.cid = BT_COMP_ID_LF,
.elem = elements,
.elem_count = ARRAY_SIZE(elements),
};
static size_t first_name_len(const char *name)
{
size_t len;
for (len = 0; *name; name++, len++) {
switch (*name) {
case ' ':
case ',':
case '\n':
return len;
}
}
return len;
}
static void send_hello(struct ble_npl_event *work)
{
struct os_mbuf *msg = NET_BUF_SIMPLE(3 + 8 + 4);
struct bt_mesh_msg_ctx ctx = {
.net_idx = NET_IDX,
.app_idx = APP_IDX,
.addr = GROUP_ADDR,
.send_ttl = DEFAULT_TTL,
};
const char *name = bt_get_name();
bt_mesh_model_msg_init(msg, OP_VND_HELLO);
net_buf_simple_add_mem(msg, name, first_name_len(name));
if (bt_mesh_model_send(&vnd_models[0], &ctx, msg, NULL, NULL) == 0) {
board_show_text("Saying \"hi!\" to everyone", false,
K_SECONDS(2));
} else {
board_show_text("Sending Failed!", false, K_SECONDS(2));
}
os_mbuf_free_chain(msg);
}
void mesh_send_hello(void)
{
k_work_submit(&hello_work);
}
static int provision_and_configure(void)
{
static const uint8_t net_key[16] = {
0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
};
static const uint8_t app_key[16] = {
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
};
static const uint16_t iv_index;
struct bt_mesh_cfg_mod_pub pub = {
.addr = GROUP_ADDR,
.app_idx = APP_IDX,
.ttl = DEFAULT_TTL,
.period = BT_MESH_PUB_PERIOD_SEC(10),
};
uint8_t dev_key[16];
uint16_t addr;
int err;
err = bt_rand(dev_key, sizeof(dev_key));
if (err) {
return err;
}
do {
err = bt_rand(&addr, sizeof(addr));
if (err) {
return err;
}
} while (!addr);
/* Make sure it's a unicast address (highest bit unset) */
addr &= ~0x8000;
err = bt_mesh_provision(net_key, NET_IDX, FLAGS, iv_index, addr,
dev_key);
if (err) {
return err;
}
printk("Configuring...\n");
/* Add Application Key */
bt_mesh_cfg_app_key_add(NET_IDX, addr, NET_IDX, APP_IDX, app_key, NULL);
/* Bind to vendor model */
bt_mesh_cfg_mod_app_bind_vnd(NET_IDX, addr, addr, APP_IDX,
MOD_LF, BT_COMP_ID_LF, NULL);
/* Bind to Health model */
bt_mesh_cfg_mod_app_bind(NET_IDX, addr, addr, APP_IDX,
BT_MESH_MODEL_ID_HEALTH_SRV, NULL);
/* Add model subscription */
bt_mesh_cfg_mod_sub_add_vnd(NET_IDX, addr, addr, GROUP_ADDR,
MOD_LF, BT_COMP_ID_LF, NULL);
bt_mesh_cfg_mod_pub_set_vnd(NET_IDX, addr, addr, MOD_LF, BT_COMP_ID_LF,
&pub, NULL);
printk("Configuration complete\n");
return addr;
}
static void start_mesh(struct ble_npl_event *work)
{
int err;
err = provision_and_configure();
if (err < 0) {
board_show_text("Starting Mesh Failed", false,
K_SECONDS(2));
} else {
char buf[32];
snprintk(buf, sizeof(buf),
"Mesh Started\nAddr: 0x%04x", err);
board_show_text(buf, false, K_SECONDS(4));
}
}
void mesh_start(void)
{
k_work_submit(&mesh_start_work);
}
bool mesh_is_initialized(void)
{
return bt_mesh_is_provisioned();
}
uint16_t mesh_get_addr(void)
{
return elements[0].addr;
}
int mesh_init(uint8_t addr_type)
{
static const uint8_t dev_uuid[16] = { 0xc0, 0xff, 0xee };
static const struct bt_mesh_prov prov = {
.uuid = dev_uuid,
};
hb_cb = { .recv = heartbeat };
bt_mesh_pub_msg_health_pub = NET_BUF_SIMPLE(0);
health_pub.msg = bt_mesh_pub_msg_health_pub;
bt_mesh_pub_msg_vnd_pub = NET_BUF_SIMPLE(3 + 1);
vnd_pub.msg = bt_mesh_pub_msg_vnd_pub;
vnd_pub.update = pub_update;
k_work_init(&hello_work, send_hello);
k_work_init(&mesh_start_work, start_mesh);
return bt_mesh_init(addr_type, &prov, &comp);
}

View file

@ -0,0 +1,14 @@
/*
* Copyright (c) 2018 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "mesh/mesh.h"
void mesh_send_hello(void);
uint16_t mesh_get_addr(void);
bool mesh_is_initialized(void);
void mesh_start(void);
int mesh_init(uint8_t addr_type);

View file

@ -0,0 +1,28 @@
/*
* 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.
*/
struct ble_gatt_register_ctxt;
void gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg);
int gatt_svr_init(void);
void schedule_mesh_reset(void);
const char *bt_get_name(void);
int bt_set_name(const char *);

View file

@ -0,0 +1,508 @@
/*
* Copyright (c) 2018 Phytec Messtechnik GmbH
* Copyright (c) 2018 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "os/mynewt.h"
#include "bsp/bsp.h"
#include "console/console.h"
#include "hal/hal_flash.h"
#include "hal/hal_gpio.h"
#include "mesh/glue.h"
#include "services/gap/ble_svc_gap.h"
#include "mesh_badge.h"
#include "display/cfb.h"
#include "mesh.h"
#include "board.h"
#define printk console_printf
enum font_size {
FONT_BIG = 0,
FONT_MEDIUM = 1,
FONT_SMALL = 2,
};
struct font_info {
uint8_t columns;
} fonts[] = {
[FONT_BIG] = { .columns = 12 },
[FONT_MEDIUM] = { .columns = 16 },
[FONT_SMALL] = { .columns = 25 },
};
#define LONG_PRESS_TIMEOUT K_SECONDS(1)
#define STAT_COUNT 128
#define EDGE (GPIO_INT_EDGE | GPIO_INT_DOUBLE_EDGE)
#ifdef SW0_GPIO_FLAGS
#define PULL_UP SW0_GPIO_FLAGS
#else
#define PULL_UP 0
#endif
static struct os_dev *epd_dev;
static bool pressed;
static bool stats_view;
static struct k_delayed_work epd_work;
static struct k_delayed_work long_press_work;
static struct {
int pin;
} leds[] = {
{ .pin = LED_1, },
{ .pin = RGB_LED_RED, },
{ .pin = RGB_LED_GRN, },
{ .pin = RGB_LED_BLU, },
};
struct k_delayed_work led_timer;
static size_t print_line(enum font_size font_size, int row, const char *text,
size_t len, bool center)
{
uint8_t font_height, font_width;
char line[fonts[FONT_SMALL].columns + 1];
int pad;
cfb_framebuffer_set_font(epd_dev, font_size);
len = min(len, fonts[font_size].columns);
memcpy(line, text, len);
line[len] = '\0';
if (center) {
pad = (fonts[font_size].columns - len) / 2;
} else {
pad = 0;
}
cfb_get_font_size(epd_dev, font_size, &font_width, &font_height);
if (cfb_print(epd_dev, line, font_width * pad, font_height * row)) {
printk("Failed to print a string\n");
}
return len;
}
static size_t get_len(enum font_size font, const char *text)
{
const char *space = NULL;
size_t i;
for (i = 0; i <= fonts[font].columns; i++) {
switch (text[i]) {
case '\n':
case '\0':
return i;
case ' ':
space = &text[i];
break;
default:
continue;
}
}
/* If we got more characters than fits a line, and a space was
* encountered, fall back to the last space.
*/
if (space) {
return space - text;
}
return fonts[font].columns;
}
void board_blink_leds(void)
{
k_delayed_work_submit(&led_timer, K_MSEC(100));
}
void board_show_text(const char *text, bool center, int32_t duration)
{
int i;
cfb_framebuffer_clear(epd_dev, false);
for (i = 0; i < 3; i++) {
size_t len;
while (*text == ' ' || *text == '\n') {
text++;
}
len = get_len(FONT_BIG, text);
if (!len) {
break;
}
text += print_line(FONT_BIG, i, text, len, center);
if (!*text) {
break;
}
}
cfb_framebuffer_finalize(epd_dev);
if (duration != K_FOREVER) {
k_delayed_work_submit(&epd_work, duration);
}
}
static struct stat {
uint16_t addr;
char name[9];
uint8_t min_hops;
uint8_t max_hops;
uint16_t hello_count;
uint16_t heartbeat_count;
} stats[STAT_COUNT] = {
[0 ... (STAT_COUNT - 1)] = {
.min_hops = BT_MESH_TTL_MAX,
.max_hops = 0,
},
};
static uint32_t stat_count;
#define NO_UPDATE -1
static int add_hello(uint16_t addr, const char *name)
{
int i;
for (i = 0; i < ARRAY_SIZE(stats); i++) {
struct stat *stat = &stats[i];
if (!stat->addr) {
stat->addr = addr;
strncpy(stat->name, name, sizeof(stat->name) - 1);
stat->hello_count = 1;
stat_count++;
return i;
}
if (stat->addr == addr) {
/* Update name, incase it has changed */
strncpy(stat->name, name, sizeof(stat->name) - 1);
if (stat->hello_count < 0xffff) {
stat->hello_count++;
return i;
}
return NO_UPDATE;
}
}
return NO_UPDATE;
}
static int add_heartbeat(uint16_t addr, uint8_t hops)
{
int i;
for (i = 0; i < ARRAY_SIZE(stats); i++) {
struct stat *stat = &stats[i];
if (!stat->addr) {
stat->addr = addr;
stat->heartbeat_count = 1;
stat->min_hops = hops;
stat->max_hops = hops;
stat_count++;
return i;
}
if (stat->addr == addr) {
if (hops < stat->min_hops) {
stat->min_hops = hops;
} else if (hops > stat->max_hops) {
stat->max_hops = hops;
}
if (stat->heartbeat_count < 0xffff) {
stat->heartbeat_count++;
return i;
}
return NO_UPDATE;
}
}
return NO_UPDATE;
}
void board_add_hello(uint16_t addr, const char *name)
{
uint32_t sort_i;
sort_i = add_hello(addr, name);
if (sort_i != NO_UPDATE) {
}
}
void board_add_heartbeat(uint16_t addr, uint8_t hops)
{
uint32_t sort_i;
sort_i = add_heartbeat(addr, hops);
if (sort_i != NO_UPDATE) {
}
}
static void show_statistics(void)
{
int top[4] = { -1, -1, -1, -1 };
int len, i, line = 0;
struct stat *stat;
char str[32];
cfb_framebuffer_clear(epd_dev, false);
len = snprintk(str, sizeof(str),
"Own Address: 0x%04x", mesh_get_addr());
print_line(FONT_SMALL, line++, str, len, false);
len = snprintk(str, sizeof(str),
"Node Count: %lu", stat_count + 1);
print_line(FONT_SMALL, line++, str, len, false);
/* Find the top sender */
for (i = 0; i < ARRAY_SIZE(stats); i++) {
int j;
stat = &stats[i];
if (!stat->addr) {
break;
}
if (!stat->hello_count) {
continue;
}
for (j = 0; j < ARRAY_SIZE(top); j++) {
if (top[j] < 0) {
top[j] = i;
break;
}
if (stat->hello_count <= stats[top[j]].hello_count) {
continue;
}
/* Move other elements down the list */
if (j < ARRAY_SIZE(top) - 1) {
memmove(&top[j + 1], &top[j],
((ARRAY_SIZE(top) - j - 1) *
sizeof(top[j])));
}
top[j] = i;
break;
}
}
if (stat_count >= 0) {
len = snprintk(str, sizeof(str), "Most messages from:");
print_line(FONT_SMALL, line++, str, len, false);
for (i = 0; i < ARRAY_SIZE(top); i++) {
if (top[i] < 0) {
break;
}
stat = &stats[top[i]];
len = snprintk(str, sizeof(str), "%-3u 0x%04x %s",
stat->hello_count, stat->addr,
stat->name);
print_line(FONT_SMALL, line++, str, len, false);
}
}
cfb_framebuffer_finalize(epd_dev);
}
static void epd_update(struct ble_npl_event *work)
{
char buf[MYNEWT_VAL(BLE_SVC_GAP_DEVICE_NAME_MAX_LENGTH)];
int i;
if (stats_view) {
show_statistics();
return;
}
strncpy(buf, bt_get_name(), sizeof(buf));
/* Convert commas to newlines */
for (i = 0; buf[i] != '\0'; i++) {
if (buf[i] == ',') {
buf[i] = '\n';
}
}
board_show_text(buf, true, K_FOREVER);
}
static void long_press(struct ble_npl_event *work)
{
/* Treat as release so actual release doesn't send messages */
pressed = false;
stats_view = !stats_view;
board_refresh_display();
}
static bool button_is_pressed(void)
{
uint32_t val;
val = (uint32_t) hal_gpio_read(BUTTON_1);
return !val;
}
static void button_interrupt(struct os_event *ev)
{
int pin_pos = (int ) ev->ev_arg;
if (button_is_pressed() == pressed) {
return;
}
pressed = !pressed;
printk("Button %s\n", pressed ? "pressed" : "released");
if (pressed) {
k_delayed_work_submit(&long_press_work, LONG_PRESS_TIMEOUT);
return;
}
k_delayed_work_cancel(&long_press_work);
if (!mesh_is_initialized()) {
return;
}
/* Short press does currently nothing in statistics view */
if (stats_view) {
return;
}
if (pin_pos == BUTTON_1) {
mesh_send_hello();
}
}
static struct os_event button_event;
static void
gpio_irq_handler(void *arg)
{
button_event.ev_arg = arg;
os_eventq_put(os_eventq_dflt_get(), &button_event);
}
static int configure_button(void)
{
button_event.ev_cb = button_interrupt;
hal_gpio_irq_init(BUTTON_1, gpio_irq_handler, (void *) BUTTON_1,
HAL_GPIO_TRIG_BOTH, HAL_GPIO_PULL_UP);
hal_gpio_irq_enable(BUTTON_1);
return 0;
}
static void led_timeout(struct ble_npl_event *work)
{
static int led_cntr;
int i;
/* Disable all LEDs */
for (i = 0; i < ARRAY_SIZE(leds); i++) {
hal_gpio_write(leds[i].pin, 1);
}
/* Stop after 5 iterations */
if (led_cntr > (ARRAY_SIZE(leds) * 5)) {
led_cntr = 0;
return;
}
/* Select and enable current LED */
i = led_cntr++ % ARRAY_SIZE(leds);
hal_gpio_write(leds[i].pin, 0);
k_delayed_work_submit(&led_timer, K_MSEC(100));
}
static int configure_leds(void)
{
int i;
for (i = 0; i < ARRAY_SIZE(leds); i++) {
hal_gpio_init_out(leds[i].pin, 1);
}
k_delayed_work_init(&led_timer, led_timeout);
return 0;
}
static int erase_storage(void)
{
bt_set_name(MYNEWT_VAL(BLE_SVC_GAP_DEVICE_NAME));
ble_store_clear();
schedule_mesh_reset();
return 0;
}
void board_refresh_display(void)
{
k_delayed_work_submit(&epd_work, K_NO_WAIT);
}
int board_init(void)
{
epd_dev = os_dev_lookup(MYNEWT_VAL(SSD1673_OS_DEV_NAME));
if (epd_dev == NULL) {
printk("SSD1673 device not found\n");
return -ENODEV;
}
if (cfb_framebuffer_init(epd_dev)) {
printk("Framebuffer initialization failed\n");
return -EIO;
}
cfb_framebuffer_clear(epd_dev, true);
if (configure_button()) {
printk("Failed to configure button\n");
return -EIO;
}
if (configure_leds()) {
printk("LED init failed\n");
return -EIO;
}
k_delayed_work_init(&epd_work, epd_update);
k_delayed_work_init(&long_press_work, long_press);
pressed = button_is_pressed();
if (pressed) {
printk("Erasing storage\n");
board_show_text("Resetting Device", false, K_SECONDS(4));
erase_storage();
}
return 0;
}

View file

@ -0,0 +1,58 @@
# 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.
#
# Package: apps/mesh_badge
syscfg.vals:
# Enable the shell task.
SHELL_TASK: 1
# Set log level to info (disable debug logging).
LOG_LEVEL: 1
# Default task settings
OS_MAIN_STACK_SIZE: 768
# Newtmgr is not supported in this app, so disable newtmgr-over-shell.
SHELL_NEWTMGR: 0
REEL_BOARD_ENABLE_ACTIVE_MODE: 1
SPI_0_MASTER: 1
BLE_MESH: 1
MSYS_1_BLOCK_COUNT: 48
BLE_SVC_GAP_DEVICE_NAME: '"reel board"'
BLE_SM_SC: 1
BLE_SM_BONDING: 1
BLE_MESH_RELAY: 1
BLE_MESH_GATT_PROXY: 0
BLE_MESH_PB_ADV: 0
BLE_MESH_PB_GATT: 0
BLE_MESH_ADV_BUF_COUNT: 30
BLE_MESH_LABEL_COUNT: 0
BLE_MESH_CFG_CLI: 1
BLE_MESH_TX_SEG_MAX: 6
BLE_MESH_TX_SEG_MSG_COUNT: 3
BLE_MESH_RX_SEG_MSG_COUNT: 3
BLE_MESH_CRPL: 128
BLE_MESH_RPL_STORE_TIMEOUT: 120
BLE_MESH_SETTINGS: 1
CONFIG_NFFS: 1
BLE_MESH_PB_ADV: 1