Diff between 37aafbbf0eb7501c3d83acd2fb9382b6f65857dc and 61ca29dff5dee46a12ddc41fe17b1a1ee2de0486

Changed Files

File Additions Deletions Status
mesh/config-client.c +107 -0 modified

Full Patch

diff --git a/mesh/config-client.c b/mesh/config-client.c
index 3f34959..37fb5d0 100644
--- a/mesh/config-client.c
+++ b/mesh/config-client.c
@@ -61,6 +61,7 @@ static bool client_msg_recvd(uint16_t src, uint8_t *data,
 	uint8_t ele_idx;
 	struct mesh_publication pub;
 	int n;
+	uint16_t i;
 
 	if (mesh_opcode_get(data, len, &opcode, &n)) {
 		len -= n;
@@ -220,6 +221,43 @@ static bool client_msg_recvd(uint16_t src, uint8_t *data,
 			prov_db_node_set_model_pub(node, ele_idx, mod_id,
 				     node_model_pub_get(node, ele_idx, mod_id));
 		break;
+
+	/* Per Mesh Profile 4.3.2.19 */
+	case OP_CONFIG_MODEL_SUB_STATUS:
+		bt_shell_printf("\nSubscription changed"
+				" for node %4.4x status: %s\n", src,
+				data[0] == MESH_STATUS_SUCCESS ? "Success" :
+						mesh_status_str(data[0]));
+
+		if (data[0] != MESH_STATUS_SUCCESS)
+			return true;
+
+		bt_shell_printf("Element Addr:\t%4.4x\n", get_le16(data + 1));
+		bt_shell_printf("Subscr Addr:\t%4.4x\n", get_le16(data + 3));
+		bt_shell_printf("Model ID:\t%4.4x\n", get_le16(data + 5));
+		break;
+
+		/* TODO */
+		/* Save subscription info in database */
+
+	/* Per Mesh Profile 4.3.2.27 */
+	case OP_CONFIG_MODEL_SUB_LIST:
+
+		bt_shell_printf("\nSubscription list for node %4.4x "
+				"length: %u status: %s\n", src, len,
+				data[0] == MESH_STATUS_SUCCESS ? "Success" :
+						mesh_status_str(data[0]));
+
+		if (data[0] != MESH_STATUS_SUCCESS)
+			return true;
+
+		bt_shell_printf("Element Addr:\t%4.4x\n", get_le16(data + 1));
+		bt_shell_printf("Model ID:\t%4.4x\n", get_le16(data + 3));
+
+		for (i = 5; i < len; i += 2)
+			bt_shell_printf("Subscr Addr:\t%4.4x\n",
+					get_le16(data + i));
+		break;
 	}
 
 	return true;
@@ -609,6 +647,71 @@ static void cmd_set_pub(int argc, char *argv[])
 		bt_shell_printf("Failed to send \"SET MODEL PUBLICATION\"\n");
 }
 
+static void cmd_sub_add(int argc, char *argv[])
+{
+	uint16_t n;
+	uint8_t msg[32];
+	int parm_cnt;
+
+	if (IS_UNASSIGNED(target)) {
+		bt_shell_printf("Destination not set\n");
+		return;
+	}
+
+	n = mesh_opcode_set(OP_CONFIG_MODEL_SUB_ADD, msg);
+
+	parm_cnt = read_input_parameters(argc, argv);
+	if (parm_cnt != 3) {
+		bt_shell_printf("Bad arguments: %s\n", argv[1]);
+		return;
+	}
+
+	/* Per Mesh Profile 4.3.2.19 */
+	/* Element Address */
+	put_le16(parms[0], msg + n);
+	n += 2;
+	/* Subscription Address */
+	put_le16(parms[1], msg + n);
+	n += 2;
+	/* SIG Model ID */
+	put_le16(parms[2], msg + n);
+	n += 2;
+
+	if (!config_send(msg, n))
+		bt_shell_printf("Failed to send \"ADD SUBSCRIPTION\"\n");
+}
+
+static void cmd_sub_get(int argc, char *argv[])
+{
+	uint16_t n;
+	uint8_t msg[32];
+	int parm_cnt;
+
+	if (IS_UNASSIGNED(target)) {
+		bt_shell_printf("Destination not set\n");
+		return;
+	}
+
+	n = mesh_opcode_set(OP_CONFIG_MODEL_SUB_GET, msg);
+
+	parm_cnt = read_input_parameters(argc, argv);
+	if (parm_cnt != 2) {
+		bt_shell_printf("Bad arguments: %s\n", argv[1]);
+		return;
+	}
+
+	/* Per Mesh Profile 4.3.2.27 */
+	/* Element Address */
+	put_le16(parms[0], msg + n);
+	n += 2;
+	/* Model ID */
+	put_le16(parms[1], msg + n);
+	n += 2;
+
+	if (!config_send(msg, n))
+		bt_shell_printf("Failed to send \"GET SUB GET\"\n");
+}
+
 static void cmd_get_ttl(int argc, char *argv[])
 {
 	cmd_default(OP_CONFIG_DEFAULT_TTL_GET);
@@ -639,6 +742,10 @@ static const struct bt_shell_menu cfg_menu = {
 	{"pub-set", "<ele_addr> <pub_addr> <app_idx> "
 			"<period (step|res)> <re-xmt (count|per)> <model>",
 				cmd_set_pub,	"Set publication"},
+	{"sub-add", "<ele_addr> <sub_addr> <model id>",
+				cmd_sub_add,    "Subscription add"},
+	{"sub-get", "<ele_addr> <model id>",
+				cmd_sub_get,    "Subscription get"},
 
 	{} },
 };