From 057052945f58bffd49b459e2b997332fbdbe6e7b Mon Sep 17 00:00:00 2001
From: sverma <saurabh.verma@iopsys.eu>
Date: Tue, 29 Mar 2022 15:12:34 +0530
Subject: [PATCH] add failed connection message CMDU

---
 src/cmdu_validate.c   | 38 ++++++++++++++++++++++++++++++++++++++
 src/cmdu_validate.h   |  1 +
 src/cntlr.c           |  1 +
 src/cntlr_map_debug.c | 28 ++++++++++++++++++++++++++++
 4 files changed, 68 insertions(+)

diff --git a/src/cmdu_validate.c b/src/cmdu_validate.c
index e4cb05da..5b16b842 100644
--- a/src/cmdu_validate.c
+++ b/src/cmdu_validate.c
@@ -817,3 +817,41 @@ bool validate_ap_autoconfig_response(struct cmdu_buff *cmdu, struct tlv *tv[][16
 
 	return true;
 }
+
+bool validate_failed_connection_msg(struct cmdu_buff *cmdu, struct tlv *tv[][16])
+{
+	int ret;
+	struct tlv_policy c_policy[] = {
+		[0] = {
+			.type = MAP_TLV_STA_MAC_ADDRESS,
+			.present = TLV_PRESENT_ONE,
+			.minlen = 6,
+			.maxlen = 6
+		},
+		[1] = {
+			.type = MAP_TLV_STATUS_CODE,
+			.present = TLV_PRESENT_ONE,
+			.minlen = 2,
+			.maxlen = 2
+		},
+		[2] = {
+			.type = MAP_TLV_REASON_CODE,
+			.present = TLV_PRESENT_MORE,
+			.minlen = 2,
+			.maxlen = 2
+		}
+	};
+
+	ret = cmdu_parse_tlvs(cmdu, tv, c_policy, 3);
+	if (ret) {
+		dbg("%s: parse_tlv failed\n", __func__);
+		return false;
+	}
+
+	if (!tv[0][0] || !tv[1][0]) {
+		dbg("%s: mandatory tlv missing\n", __func__);
+		return false;
+	}
+
+	return true;
+}
diff --git a/src/cmdu_validate.h b/src/cmdu_validate.h
index d173b6da..9e925588 100644
--- a/src/cmdu_validate.h
+++ b/src/cmdu_validate.h
@@ -9,5 +9,6 @@ bool validate_topology_response(struct cmdu_buff *cmdu, struct tlv *tv_tsp[][16]
 bool validate_ap_autoconfig_wsc(struct cmdu_buff *cmdu, struct tlv *tv[][16]);
 bool validate_ap_autoconfig_search(struct cmdu_buff *cmdu, struct tlv *tv[][16]);
 bool validate_ap_autoconfig_response(struct cmdu_buff *cmdu, struct tlv *tv[][16]);
+bool validate_failed_connection_msg(struct cmdu_buff *cmdu, struct tlv *tv[][16]);
 
 #endif	// CMDU_VALIDATE
diff --git a/src/cntlr.c b/src/cntlr.c
index d3f5538d..5c1a1295 100644
--- a/src/cntlr.c
+++ b/src/cntlr.c
@@ -2249,6 +2249,7 @@ static int controller_subscribe_for_cmdus(struct controller *c)
 			CMDU_AP_CAPABILITY_REPORT,
 			CMDU_CLIENT_CAPABILITY_REPORT,
 			CMDU_HIGHER_LAYER_DATA,
+			CMDU_FAILED_CONNECTION,
 			-1);
 	memcpy(c->cmdu_mask, cmdu_mask, sizeof(c->cmdu_mask));
 
diff --git a/src/cntlr_map_debug.c b/src/cntlr_map_debug.c
index 632aca65..01c675c3 100644
--- a/src/cntlr_map_debug.c
+++ b/src/cntlr_map_debug.c
@@ -1350,6 +1350,34 @@ int debug_backhaul_sta_caps_report(void *cntlr, struct cmdu_buff *cmdu)
 
 int debug_failed_connection_msg(void *cntlr, struct cmdu_buff *cmdu)
 {
+	struct tlv *tv[3][16];
+
+	if (!validate_failed_connection_msg(cmdu, tv)) {
+		trace("%s: cmdu validation "\
+				"[FAILED_CONNECTION] failed\n", __func__);
+		return -1;
+	}
+
 	trace("%s: --->\n", __func__);
+	trace("parsing failed connection message\n");
+
+	if (tv[0][0]) {
+		struct tlv_sta_mac *t = (struct tlv_sta_mac *)tv[0][0]->data;
+
+		trace("\tmacaddr: " MACFMT "\n", MAC2STR(t->macaddr));
+	}
+
+	if (tv[1][0]) {
+		struct tlv_status_code *t = (struct tlv_status_code *)tv[1][0]->data;
+
+		trace("\tstatus code: %d\n", BUF_GET_BE16(t->code));
+	}
+
+	if (tv[2][0]) {
+		struct tlv_reason_code *t = (struct tlv_reason_code *)tv[2][0]->data;
+
+		trace("\treason code: %d\n", BUF_GET_BE16(t->code));
+	}
+
 	return 0;
 }
-- 
GitLab