You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by na...@apache.org on 2021/05/27 08:19:42 UTC
[mynewt-nimble] 04/31: mesh: Check response address in
Configuration Client
This is an automated email from the ASF dual-hosted git repository.
naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
commit 299b2ebe9ab2ac6c9cb85cffb0f10e18428212e1
Author: Krzysztof Kopyściński <kr...@codecoup.pl>
AuthorDate: Mon Mar 29 12:15:23 2021 +0200
mesh: Check response address in Configuration Client
The Configuration Client doesn't check the address in a received
response. This means that a response from any device will be accepted.
This change ensures that the correct response will be accepted.
this is port of 8bcc85b38cccf1f36e769e907f43137f68305aa7
---
nimble/host/mesh/include/mesh/cfg_cli.h | 3 +-
nimble/host/mesh/src/cfg_cli.c | 91 ++++++++++++++++++---------------
2 files changed, 51 insertions(+), 43 deletions(-)
diff --git a/nimble/host/mesh/include/mesh/cfg_cli.h b/nimble/host/mesh/include/mesh/cfg_cli.h
index bd2f9fe..368bdfc 100644
--- a/nimble/host/mesh/include/mesh/cfg_cli.h
+++ b/nimble/host/mesh/include/mesh/cfg_cli.h
@@ -26,8 +26,9 @@ struct bt_mesh_cfg_cli {
struct bt_mesh_model *model;
struct k_sem op_sync;
- uint32_t op_pending;
+ uint32_t op_pending;
void *op_param;
+ uint16_t op_addr;
};
extern const struct bt_mesh_model_op bt_mesh_cfg_cli_op[];
diff --git a/nimble/host/mesh/src/cfg_cli.c b/nimble/host/mesh/src/cfg_cli.c
index 104d4e6..2df7d70 100644
--- a/nimble/host/mesh/src/cfg_cli.c
+++ b/nimble/host/mesh/src/cfg_cli.c
@@ -33,6 +33,11 @@ static int32_t msg_timeout = K_SECONDS(5);
static struct bt_mesh_cfg_cli *cli;
+static inline bool cli_response_check(uint32_t resp_opcode, uint16_t resp_addr)
+{
+ return cli->op_pending == resp_opcode && cli->op_addr == resp_addr;
+}
+
static void comp_data_status(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct os_mbuf *buf)
@@ -44,7 +49,7 @@ static void comp_data_status(struct bt_mesh_model *model,
ctx->net_idx, ctx->app_idx, ctx->addr, buf->om_len,
bt_hex(buf->om_data, buf->om_len));
- if (cli->op_pending != OP_DEV_COMP_DATA_STATUS) {
+ if (!cli_response_check(OP_DEV_COMP_DATA_STATUS, ctx->addr)) {
BT_WARN("Unexpected Composition Data Status");
return;
}
@@ -69,7 +74,7 @@ static void state_status_u8(struct bt_mesh_model *model,
ctx->net_idx, ctx->app_idx, ctx->addr, buf->om_len,
bt_hex(buf->om_data, buf->om_len));
- if (cli->op_pending != expect_status) {
+ if (!cli_response_check(expect_status, ctx->addr)) {
BT_WARN("Unexpected Status (0x%08x != 0x%08x)",
(unsigned) cli->op_pending, (unsigned) expect_status);
return;
@@ -124,7 +129,7 @@ static void relay_status(struct bt_mesh_model *model,
ctx->net_idx, ctx->app_idx, ctx->addr, buf->om_len,
bt_hex(buf->om_data, buf->om_len));
- if (cli->op_pending != OP_RELAY_STATUS) {
+ if (!cli_response_check(OP_RELAY_STATUS, ctx->addr)) {
BT_WARN("Unexpected Relay Status message");
return;
}
@@ -146,7 +151,7 @@ static void net_transmit_status(struct bt_mesh_model *model,
ctx->net_idx, ctx->app_idx, ctx->addr, buf->om_len,
bt_hex(buf->om_data, buf->om_len));
- if (cli->op_pending != OP_NET_TRANSMIT_STATUS) {
+ if (!cli_response_check(OP_NET_TRANSMIT_STATUS, ctx->addr)) {
BT_WARN("Unexpected Net Transmit Status message");
return;
}
@@ -174,7 +179,7 @@ static void net_key_status(struct bt_mesh_model *model,
ctx->net_idx, ctx->app_idx, ctx->addr, buf->om_len,
bt_hex(buf->om_data, buf->om_len));
- if (cli->op_pending != OP_NET_KEY_STATUS) {
+ if (!cli_response_check(OP_NET_KEY_STATUS, ctx->addr)) {
BT_WARN("Unexpected Net Key Status message");
return;
}
@@ -211,7 +216,7 @@ static void net_key_list(struct bt_mesh_model *model,
ctx->net_idx, ctx->app_idx, ctx->addr, buf->om_len,
bt_hex(buf->om_data, buf->om_len));
- if (cli->op_pending != OP_NET_KEY_LIST) {
+ if (!cli_response_check(OP_NET_KEY_LIST, ctx->addr)) {
BT_WARN("Unexpected Net Key List message");
return;
}
@@ -238,7 +243,7 @@ static void node_reset_status(struct bt_mesh_model *model,
BT_DBG("net_idx 0x%04x app_idx 0x%04x src 0x%04x",
ctx->net_idx, ctx->app_idx, ctx->addr);
- if (cli->op_pending != OP_NODE_RESET_STATUS) {
+ if (!cli_response_check(OP_NODE_RESET_STATUS, ctx->addr)) {
BT_WARN("Unexpected Node Reset Status message");
return;
}
@@ -269,7 +274,7 @@ static void app_key_status(struct bt_mesh_model *model,
ctx->net_idx, ctx->app_idx, ctx->addr, buf->om_len,
bt_hex(buf->om_data, buf->om_len));
- if (cli->op_pending != OP_APP_KEY_STATUS) {
+ if (!cli_response_check(OP_APP_KEY_STATUS, ctx->addr)) {
BT_WARN("Unexpected App Key Status message");
return;
}
@@ -310,7 +315,7 @@ static void app_key_list(struct bt_mesh_model *model,
ctx->net_idx, ctx->app_idx, ctx->addr, buf->om_len,
bt_hex(buf->om_data, buf->om_len));
- if (cli->op_pending != OP_APP_KEY_LIST) {
+ if (!cli_response_check(OP_APP_KEY_LIST, ctx->addr)) {
BT_WARN("Unexpected App Key List message");
return;
}
@@ -360,7 +365,7 @@ static void mod_app_status(struct bt_mesh_model *model,
ctx->net_idx, ctx->app_idx, ctx->addr, buf->om_len,
bt_hex(buf->om_data, buf->om_len));
- if (cli->op_pending != OP_MOD_APP_STATUS) {
+ if (!cli_response_check(OP_MOD_APP_STATUS, ctx->addr)) {
BT_WARN("Unexpected Model App Status message");
return;
}
@@ -449,7 +454,7 @@ static void mod_app_list(struct bt_mesh_model *model,
ctx->net_idx, ctx->app_idx, ctx->addr, buf->om_len,
bt_hex(buf->om_data, buf->om_len));
- if (cli->op_pending != OP_SIG_MOD_APP_LIST) {
+ if (!cli_response_check(OP_SIG_MOD_APP_LIST, ctx->addr)) {
BT_WARN("Unexpected Model App List message");
return;
}
@@ -465,7 +470,7 @@ static void mod_app_list_vnd(struct bt_mesh_model *model,
ctx->net_idx, ctx->app_idx, ctx->addr, buf->om_len,
bt_hex(buf->om_data, buf->om_len));
- if (cli->op_pending != OP_VND_MOD_APP_LIST) {
+ if (!cli_response_check(OP_VND_MOD_APP_LIST, ctx->addr)) {
BT_WARN("Unexpected Model App List Vendor message");
return;
}
@@ -493,7 +498,7 @@ static void mod_pub_status(struct bt_mesh_model *model,
ctx->net_idx, ctx->app_idx, ctx->addr, buf->om_len,
bt_hex(buf->om_data, buf->om_len));
- if (cli->op_pending != OP_MOD_PUB_STATUS) {
+ if (!cli_response_check(OP_MOD_PUB_STATUS, ctx->addr)) {
BT_WARN("Unexpected Model Pub Status message");
return;
}
@@ -569,7 +574,7 @@ static void mod_sub_status(struct bt_mesh_model *model,
ctx->net_idx, ctx->app_idx, ctx->addr, buf->om_len,
bt_hex(buf->om_data, buf->om_len));
- if (cli->op_pending != OP_MOD_SUB_STATUS) {
+ if (!cli_response_check(OP_MOD_SUB_STATUS, ctx->addr)) {
BT_WARN("Unexpected Model Subscription Status message");
return;
}
@@ -613,7 +618,7 @@ static void mod_sub_list(struct bt_mesh_model *model,
ctx->net_idx, ctx->app_idx, ctx->addr, buf->om_len,
bt_hex(buf->om_data, buf->om_len));
- if (cli->op_pending != OP_MOD_SUB_LIST) {
+ if (!cli_response_check(OP_MOD_SUB_LIST, ctx->addr)) {
BT_WARN("Unexpected Model Subscription List message");
return;
}
@@ -629,7 +634,7 @@ static void mod_sub_list_vnd(struct bt_mesh_model *model,
ctx->net_idx, ctx->app_idx, ctx->addr, buf->om_len,
bt_hex(buf->om_data, buf->om_len));
- if (cli->op_pending != OP_MOD_SUB_LIST_VND) {
+ if (!cli_response_check(OP_MOD_SUB_LIST_VND, ctx->addr)) {
BT_WARN("Unexpected Model Subscription List Vendor message");
return;
}
@@ -652,7 +657,7 @@ static void hb_sub_status(struct bt_mesh_model *model,
ctx->net_idx, ctx->app_idx, ctx->addr, buf->om_len,
bt_hex(buf->om_data, buf->om_len));
- if (cli->op_pending != OP_HEARTBEAT_SUB_STATUS) {
+ if (!cli_response_check(OP_HEARTBEAT_SUB_STATUS, ctx->addr)) {
BT_WARN("Unexpected Heartbeat Subscription Status message");
return;
}
@@ -686,7 +691,7 @@ static void hb_pub_status(struct bt_mesh_model *model,
ctx->net_idx, ctx->app_idx, ctx->addr, buf->om_len,
bt_hex(buf->om_data, buf->om_len));
- if (cli->op_pending != OP_HEARTBEAT_PUB_STATUS) {
+ if (!cli_response_check(OP_HEARTBEAT_PUB_STATUS, ctx->addr)) {
BT_WARN("Unexpected Heartbeat Publication Status message");
return;
}
@@ -764,7 +769,7 @@ const struct bt_mesh_model_cb bt_mesh_cfg_cli_cb = {
.init = cfg_cli_init,
};
-static int cli_prepare(void *param, uint32_t op)
+static int cli_prepare(void *param, uint32_t op, uint16_t addr)
{
if (!cli) {
BT_ERR("No available Configuration Client context!");
@@ -778,6 +783,7 @@ static int cli_prepare(void *param, uint32_t op)
cli->op_param = param;
cli->op_pending = op;
+ cli->op_addr = addr;
return 0;
}
@@ -786,6 +792,7 @@ static void cli_reset(void)
{
cli->op_pending = 0;
cli->op_param = NULL;
+ cli->op_addr = BT_MESH_ADDR_UNASSIGNED;
}
static int cli_wait(void)
@@ -815,7 +822,7 @@ int bt_mesh_cfg_comp_data_get(uint16_t net_idx, uint16_t addr, uint8_t page,
};
int err;
- err = cli_prepare(¶m, OP_DEV_COMP_DATA_STATUS);
+ err = cli_prepare(¶m, OP_DEV_COMP_DATA_STATUS, addr);
if (err) {
goto done;
}
@@ -848,7 +855,7 @@ static int get_state_u8(uint16_t net_idx, uint16_t addr, uint32_t op, uint32_t r
};
int err;
- err = cli_prepare(val, rsp);
+ err = cli_prepare(val, rsp, addr);
if (err) {
goto done;
}
@@ -880,7 +887,7 @@ static int set_state_u8(uint16_t net_idx, uint16_t addr, uint32_t op, uint32_t r
};
int err;
- err = cli_prepare(val, rsp);
+ err = cli_prepare(val, rsp, addr);
if (err) {
goto done;
}
@@ -980,7 +987,7 @@ int bt_mesh_cfg_relay_get(uint16_t net_idx, uint16_t addr, uint8_t *status,
};
int err;
- err = cli_prepare(¶m, OP_RELAY_STATUS);
+ err = cli_prepare(¶m, OP_RELAY_STATUS, addr);
if (err) {
goto done;
}
@@ -1016,7 +1023,7 @@ int bt_mesh_cfg_relay_set(uint16_t net_idx, uint16_t addr, uint8_t new_relay,
};
int err;
- err = cli_prepare(¶m, OP_RELAY_STATUS);
+ err = cli_prepare(¶m, OP_RELAY_STATUS, addr);
if (err) {
goto done;
}
@@ -1054,7 +1061,7 @@ int bt_mesh_cfg_net_key_add(uint16_t net_idx, uint16_t addr, uint16_t key_net_id
};
int err;
- err = cli_prepare(¶m, OP_NET_KEY_STATUS);
+ err = cli_prepare(¶m, OP_NET_KEY_STATUS, addr);
if (err) {
goto done;
}
@@ -1097,7 +1104,7 @@ int bt_mesh_cfg_net_key_get(uint16_t net_idx, uint16_t addr, uint16_t *keys,
};
int err;
- err = cli_prepare(¶m, OP_NET_KEY_LIST);
+ err = cli_prepare(¶m, OP_NET_KEY_LIST, addr);
if (err) {
return err;
}
@@ -1131,7 +1138,7 @@ int bt_mesh_cfg_net_key_del(uint16_t net_idx, uint16_t addr,
};
int err;
- err = cli_prepare(¶m, OP_NET_KEY_STATUS);
+ err = cli_prepare(¶m, OP_NET_KEY_STATUS, addr);
if (err) {
goto done;
}
@@ -1175,7 +1182,7 @@ int bt_mesh_cfg_app_key_add(uint16_t net_idx, uint16_t addr, uint16_t key_net_id
};
int err;
- err = cli_prepare(¶m, OP_APP_KEY_STATUS);
+ err = cli_prepare(¶m, OP_APP_KEY_STATUS, addr);
if (err) {
goto done;
}
@@ -1218,7 +1225,7 @@ int bt_mesh_cfg_node_reset(uint16_t net_idx, uint16_t addr, bool *status)
*status = false;
}
- err = cli_prepare(status, OP_NODE_RESET_STATUS);
+ err = cli_prepare(status, OP_NODE_RESET_STATUS, addr);
if (err) {
goto done;
}
@@ -1265,7 +1272,7 @@ int bt_mesh_cfg_app_key_get(uint16_t net_idx, uint16_t addr, uint16_t key_net_id
};
int err;
- err = cli_prepare(¶m, OP_APP_KEY_LIST);
+ err = cli_prepare(¶m, OP_APP_KEY_LIST, addr);
if (err) {
os_mbuf_free_chain(msg);
return err;
@@ -1303,7 +1310,7 @@ int bt_mesh_cfg_app_key_del(uint16_t net_idx, uint16_t addr,
};
int err;
- err = cli_prepare(¶m, OP_APP_KEY_STATUS);
+ err = cli_prepare(¶m, OP_APP_KEY_STATUS, addr);
if (err) {
os_mbuf_free_chain(msg);
return err;
@@ -1350,7 +1357,7 @@ static int mod_app_bind(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
};
int err;
- err = cli_prepare(¶m, OP_MOD_APP_STATUS);
+ err = cli_prepare(¶m, OP_MOD_APP_STATUS, addr);
if (err) {
goto done;
}
@@ -1422,7 +1429,7 @@ static int mod_app_unbind(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
};
int err;
- err = cli_prepare(¶m, OP_MOD_APP_STATUS);
+ err = cli_prepare(¶m, OP_MOD_APP_STATUS, addr);
if (err) {
goto done;
}
@@ -1501,7 +1508,7 @@ static int mod_member_list_get(uint32_t op, uint32_t expect_op, uint16_t net_idx
};
int err;
- err = cli_prepare(¶m, expect_op);
+ err = cli_prepare(¶m, expect_op, addr);
if (err) {
goto done;
}
@@ -1573,7 +1580,7 @@ static int mod_sub(uint32_t op, uint16_t net_idx, uint16_t addr, uint16_t elem_a
};
int err;
- err = cli_prepare(¶m, OP_MOD_SUB_STATUS);
+ err = cli_prepare(¶m, OP_MOD_SUB_STATUS, addr);
if (err) {
goto done;
}
@@ -1684,7 +1691,7 @@ static int mod_sub_va(uint32_t op, uint16_t net_idx, uint16_t addr, uint16_t ele
};
int err;
- err = cli_prepare(¶m, OP_MOD_SUB_STATUS);
+ err = cli_prepare(¶m, OP_MOD_SUB_STATUS, addr);
if (err) {
goto done;
}
@@ -1825,7 +1832,7 @@ static int mod_pub_get(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
};
int err;
- err = cli_prepare(¶m, OP_MOD_PUB_STATUS);
+ err = cli_prepare(¶m, OP_MOD_PUB_STATUS, addr);
if (err) {
goto done;
}
@@ -1897,7 +1904,7 @@ static int mod_pub_set(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
};
int err;
- err = cli_prepare(¶m, OP_MOD_PUB_STATUS);
+ err = cli_prepare(¶m, OP_MOD_PUB_STATUS, addr);
if (err) {
goto done;
}
@@ -1970,7 +1977,7 @@ int bt_mesh_cfg_hb_sub_set(uint16_t net_idx, uint16_t addr,
};
int err;
- err = cli_prepare(¶m, OP_HEARTBEAT_SUB_STATUS);
+ err = cli_prepare(¶m, OP_HEARTBEAT_SUB_STATUS, addr);
if (err) {
goto done;
}
@@ -2014,7 +2021,7 @@ int bt_mesh_cfg_hb_sub_get(uint16_t net_idx, uint16_t addr,
};
int err;
- err = cli_prepare(¶m, OP_HEARTBEAT_SUB_STATUS);
+ err = cli_prepare(¶m, OP_HEARTBEAT_SUB_STATUS, addr);
if (err) {
goto done;
}
@@ -2054,7 +2061,7 @@ int bt_mesh_cfg_hb_pub_set(uint16_t net_idx, uint16_t addr,
};
int err;
- err = cli_prepare(¶m, OP_HEARTBEAT_PUB_STATUS);
+ err = cli_prepare(¶m, OP_HEARTBEAT_PUB_STATUS, addr);
if (err) {
goto done;
}
@@ -2101,7 +2108,7 @@ int bt_mesh_cfg_hb_pub_get(uint16_t net_idx, uint16_t addr,
};
int err;
- err = cli_prepare(¶m, OP_HEARTBEAT_PUB_STATUS);
+ err = cli_prepare(¶m, OP_HEARTBEAT_PUB_STATUS, addr);
if (err) {
goto done;
}