Skip to contentSkip to conversation

tools/mesh-cfgclient: add unbind command

PATCH Applied Aurelien Jarno 3 participants 4 messages Nov 11, 2019 – Nov 12, 2019 Bluetooth drivers

v1 of 2 Applied Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/mesh-cfgclient: add unbind command

This is basically a copy of cmd_bind with OP_MODEL_APP_BIND replaced by OP_MODEL_APP_UNBIND as cmds[] already has code to handle it.

---
 tools/mesh/cfgcli.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
tools/mesh/cfgcli.c +36 -0
index 086998910..a4de42943 100644
@@ -897,6 +897,40 @@ static void cmd_bind(int argc, char *argv[])
 	return bt_shell_noninteractive_quit(EXIT_SUCCESS);
 }
 
+static void cmd_unbind(int argc, char *argv[])
+{
+	uint16_t n;
+	uint8_t msg[32];
+	int parm_cnt;
+
+	parm_cnt = read_input_parameters(argc, argv);
+	if (parm_cnt != 3 && parm_cnt != 4) {
+		bt_shell_printf("Bad arguments\n");
+		return bt_shell_noninteractive_quit(EXIT_FAILURE);
+	}
+
+	n = mesh_opcode_set(OP_MODEL_APP_UNBIND, msg);
+
+	put_le16(parms[0], msg + n);
+	n += 2;
+	put_le16(parms[1], msg + n);
+	n += 2;
+
+	if (parm_cnt == 4) {
+		put_le16(parms[3], msg + n);
+		put_le16(parms[2], msg + n + 2);
+		n += 4;
+	} else {
+		put_le16(parms[2], msg + n);
+		n += 2;
+	}
+
+	if (!config_send(msg, n, OP_MODEL_APP_UNBIND))
+		return bt_shell_noninteractive_quit(EXIT_FAILURE);
+
+	return bt_shell_noninteractive_quit(EXIT_SUCCESS);
+}
+
 static void cmd_beacon_set(int argc, char *argv[])
 {
 	uint16_t n;
@@ -1335,6 +1369,8 @@ static const struct bt_shell_menu cfg_menu = {
 				"Delete application key"},
 	{"bind", "<ele_addr> <app_idx> <mod_id> [vendor_id]", cmd_bind,
 				"Bind app key to a model"},
+	{"unbind", "<ele_addr> <app_idx> <mod_id> [vendor_id]", cmd_unbind,
+				"Remove app key from a model"},
 	{"mod-appidx-get", "<ele_addr> <model id>", cmd_mod_appidx_get,
 				"Get model app_idx"},
 	{"ttl-set", "<ttl>", cmd_ttl_set,
Signature · 1 line
2.24.0
#1 lore raw

Hi Aurelien,

Quoted 37 lines · Aurelien Jarno

This is basically a copy of cmd_bind with OP_MODEL_APP_BIND replaced by OP_MODEL_APP_UNBIND as cmds[] already has code to handle it.

---
 tools/mesh/cfgcli.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
tools/mesh/cfgcli.c +23 -0
index 086998910..a4de42943 100644
@@ -897,6 +897,40 @@ static void cmd_bind(int argc, char *argv[])
 	return bt_shell_noninteractive_quit(EXIT_SUCCESS);
 }
 
+static void cmd_unbind(int argc, char *argv[])
+{
+	uint16_t n;
+	uint8_t msg[32];
+	int parm_cnt;
+
+	parm_cnt = read_input_parameters(argc, argv);
+	if (parm_cnt != 3 && parm_cnt != 4) {
+		bt_shell_printf("Bad arguments\n");
+		return bt_shell_noninteractive_quit(EXIT_FAILURE);
+	}
+
+	n = mesh_opcode_set(OP_MODEL_APP_UNBIND, msg);
+
+	put_le16(parms[0], msg + n);
+	n += 2;
+	put_le16(parms[1], msg + n);
+	n += 2;
+
+	if (parm_cnt == 4) {
+		put_le16(parms[3], msg + n);
+		put_le16(parms[2], msg + n + 2);
+		n += 4;

tools/mesh/cfgcli.c static void cmd_bind(int argc, char *argv[]) · line 932

Quoted 10 lines
tools/mesh/cfgcli.c +10 -0
+	} else {
+		put_le16(parms[2], msg + n);
+		n += 2;
+	}
+
+	if (!config_send(msg, n, OP_MODEL_APP_UNBIND))
+		return bt_shell_noninteractive_quit(EXIT_FAILURE);
+
+	return bt_shell_noninteractive_quit(EXIT_SUCCESS);
+}

Since cmd_bind() & and cmd_unbind()
are virtually identical with the exception of the opcode, let's combine them to call one routine, e.g.
cmd_add_binding() and cmd delete_binding() would call cmd_bind(int argc, char*argv[], int opcode)

tools/mesh/cfgcli.c static const struct bt_shell_menu cfg_menu = { · line 1376

Quoted 13 lines
tools/mesh/cfgcli.c +3 -0
+
 static void cmd_beacon_set(int argc, char *argv[])
 {
 	uint16_t n;
@@ -1335,6 +1369,8 @@ static const struct bt_shell_menu cfg_menu = {
 				"Delete application key"},
 	{"bind", "<ele_addr> <app_idx> <mod_id> [vendor_id]", cmd_bind,
 				"Bind app key to a model"},
+	{"unbind", "<ele_addr> <app_idx> <mod_id> [vendor_id]", cmd_unbind,
+				"Remove app key from a model"},
 	{"mod-appidx-get", "<ele_addr> <model id>", cmd_mod_appidx_get,
 				"Get model app_idx"},
 	{"ttl-set", "<ttl>", cmd_ttl_set,

Best regards,
Inga

Applied
#2 lore raw
In reply to Aurelien Jarno

Applied, Thanks

Quoted 60 lines · Aurelien Jarno

This is basically a copy of cmd_bind with OP_MODEL_APP_BIND replaced by OP_MODEL_APP_UNBIND as cmds[] already has code to handle it.

---
 tools/mesh/cfgcli.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
tools/mesh/cfgcli.c +36 -0
index 086998910..a4de42943 100644
@@ -897,6 +897,40 @@ static void cmd_bind(int argc, char *argv[])
 	return bt_shell_noninteractive_quit(EXIT_SUCCESS);
 }
 
+static void cmd_unbind(int argc, char *argv[])
+{
+	uint16_t n;
+	uint8_t msg[32];
+	int parm_cnt;
+
+	parm_cnt = read_input_parameters(argc, argv);
+	if (parm_cnt != 3 && parm_cnt != 4) {
+		bt_shell_printf("Bad arguments\n");
+		return bt_shell_noninteractive_quit(EXIT_FAILURE);
+	}
+
+	n = mesh_opcode_set(OP_MODEL_APP_UNBIND, msg);
+
+	put_le16(parms[0], msg + n);
+	n += 2;
+	put_le16(parms[1], msg + n);
+	n += 2;
+
+	if (parm_cnt == 4) {
+		put_le16(parms[3], msg + n);
+		put_le16(parms[2], msg + n + 2);
+		n += 4;
+	} else {
+		put_le16(parms[2], msg + n);
+		n += 2;
+	}
+
+	if (!config_send(msg, n, OP_MODEL_APP_UNBIND))
+		return bt_shell_noninteractive_quit(EXIT_FAILURE);
+
+	return bt_shell_noninteractive_quit(EXIT_SUCCESS);
+}
+
 static void cmd_beacon_set(int argc, char *argv[])
 {
 	uint16_t n;
@@ -1335,6 +1369,8 @@ static const struct bt_shell_menu cfg_menu = {
 				"Delete application key"},
 	{"bind", "<ele_addr> <app_idx> <mod_id> [vendor_id]", cmd_bind,
 				"Bind app key to a model"},
+	{"unbind", "<ele_addr> <app_idx> <mod_id> [vendor_id]", cmd_unbind,
+				"Remove app key from a model"},
 	{"mod-appidx-get", "<ele_addr> <model id>", cmd_mod_appidx_get,
 				"Get model app_idx"},
 	{"ttl-set", "<ttl>", cmd_ttl_set,
#3 lore raw

Actually applied v2 of this patch

Quoted 63 lines · Brian

Applied, Thanks

Quoted 60 lines · Aurelien Jarno

This is basically a copy of cmd_bind with OP_MODEL_APP_BIND replaced by OP_MODEL_APP_UNBIND as cmds[] already has code to handle it.

---
 tools/mesh/cfgcli.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
tools/mesh/cfgcli.c +36 -0
index 086998910..a4de42943 100644
@@ -897,6 +897,40 @@ static void cmd_bind(int argc, char *argv[])
 	return bt_shell_noninteractive_quit(EXIT_SUCCESS);
 }
 
+static void cmd_unbind(int argc, char *argv[])
+{
+	uint16_t n;
+	uint8_t msg[32];
+	int parm_cnt;
+
+	parm_cnt = read_input_parameters(argc, argv);
+	if (parm_cnt != 3 && parm_cnt != 4) {
+		bt_shell_printf("Bad arguments\n");
+		return bt_shell_noninteractive_quit(EXIT_FAILURE);
+	}
+
+	n = mesh_opcode_set(OP_MODEL_APP_UNBIND, msg);
+
+	put_le16(parms[0], msg + n);
+	n += 2;
+	put_le16(parms[1], msg + n);
+	n += 2;
+
+	if (parm_cnt == 4) {
+		put_le16(parms[3], msg + n);
+		put_le16(parms[2], msg + n + 2);
+		n += 4;
+	} else {
+		put_le16(parms[2], msg + n);
+		n += 2;
+	}
+
+	if (!config_send(msg, n, OP_MODEL_APP_UNBIND))
+		return bt_shell_noninteractive_quit(EXIT_FAILURE);
+
+	return bt_shell_noninteractive_quit(EXIT_SUCCESS);
+}
+
 static void cmd_beacon_set(int argc, char *argv[])
 {
 	uint16_t n;
@@ -1335,6 +1369,8 @@ static const struct bt_shell_menu cfg_menu = {
 				"Delete application key"},
 	{"bind", "<ele_addr> <app_idx> <mod_id> [vendor_id]", cmd_bind,
 				"Bind app key to a model"},
+	{"unbind", "<ele_addr> <app_idx> <mod_id> [vendor_id]", cmd_unbind,
+				"Remove app key from a model"},
 	{"mod-appidx-get", "<ele_addr> <model id>", cmd_mod_appidx_get,
 				"Get model app_idx"},
 	{"ttl-set", "<ttl>", cmd_ttl_set,