From ef8ae607148015dc68202f080bb60d982eb86d29 Mon Sep 17 00:00:00 2001
From: Marek Puzyniak <marek.puzyniak@iopsys.eu>
Date: Thu, 10 Aug 2023 13:37:41 +0200
Subject: [PATCH] Prevent tlv index exceeding

Use TLV_MAXNUM.

Signed-off-by: Marek Puzyniak <marek.puzyniak@iopsys.eu>
---
 src/cmdu_validate.c   | 47 ++++++++++++------------
 src/cmdu_validate.h   | 28 +++++++--------
 src/cntlr_map.c       | 74 +++++++++++++++++++-------------------
 src/cntlr_map_debug.c | 83 +++++++++++++++++++++----------------------
 4 files changed, 115 insertions(+), 117 deletions(-)

diff --git a/src/cmdu_validate.c b/src/cmdu_validate.c
index e3161a3f..29b91585 100644
--- a/src/cmdu_validate.c
+++ b/src/cmdu_validate.c
@@ -443,7 +443,7 @@ static int check_assoc_sta_ext_link_metrics_tlv(struct tlv *tlv)
 	return 0;
 }
 
-bool validate_1905_ack(struct cmdu_buff *cmdu, struct tlv *tv[][16], uint8_t profile)
+bool validate_1905_ack(struct cmdu_buff *cmdu, struct tlv *tv[][TLV_MAXNUM], uint8_t profile)
 {
 	int num = 0;
 	int ret;
@@ -749,7 +749,7 @@ static int check_bss_config_request_tlv(struct tlv *t)
 }
 #endif /* EASYMESH_VERSION > 2 */
 
-bool validate_topology_notification(struct cmdu_buff *cmdu, struct tlv *tv[][16], uint8_t profile)
+bool validate_topology_notification(struct cmdu_buff *cmdu, struct tlv *tv[][TLV_MAXNUM], uint8_t profile)
 {
 	int ret;
 
@@ -766,7 +766,7 @@ bool validate_topology_notification(struct cmdu_buff *cmdu, struct tlv *tv[][16]
 	return true;
 }
 
-bool validate_ap_caps_report(struct cmdu_buff *cmdu, struct tlv *tv[][16], uint8_t profile)
+bool validate_ap_caps_report(struct cmdu_buff *cmdu, struct tlv *tv[][TLV_MAXNUM], uint8_t profile)
 {
 	int ret = 0;
 	int idx;
@@ -790,7 +790,7 @@ bool validate_ap_caps_report(struct cmdu_buff *cmdu, struct tlv *tv[][16], uint8
 
 	/* AP Radio Basic Capabilities TLV */
 	idx = 0;
-	while (tv[1][idx] && (idx < 16)) {
+	while (idx < TLV_MAXNUM && tv[1][idx]) {
 		if (check_ap_radio_basic_cap_tlv(tv[1][idx]))
 			return false;
 		idx++;
@@ -798,7 +798,7 @@ bool validate_ap_caps_report(struct cmdu_buff *cmdu, struct tlv *tv[][16], uint8
 
 	/* AP HT Capabilities TLV */
 	idx = 0;
-	while (tv[2][idx] && (idx < 16)) {
+	while (idx < TLV_MAXNUM && tv[2][idx]) {
 		if (check_ap_ht_cap_tlv(tv[2][idx]))
 			return false;
 		idx++;
@@ -806,7 +806,7 @@ bool validate_ap_caps_report(struct cmdu_buff *cmdu, struct tlv *tv[][16], uint8
 
 	idx = 0;
 	/* AP VHT Capabilities TLV */
-	while (tv[3][idx] && (idx < 16)) {
+	while (idx < TLV_MAXNUM && tv[3][idx] ) {
 		if (check_ap_vht_cap_tlv(tv[3][idx]))
 			return false;
 		idx++;
@@ -814,7 +814,7 @@ bool validate_ap_caps_report(struct cmdu_buff *cmdu, struct tlv *tv[][16], uint8
 
 	/* AP HE Capabilities TLV */
 	idx = 0;
-	while (tv[4][idx] && (idx < 16)) {
+	while (idx < TLV_MAXNUM && tv[4][idx]) {
 		if (check_ap_he_cap_tlv(tv[4][idx]))
 			return false;
 		idx++;
@@ -833,7 +833,7 @@ bool validate_ap_caps_report(struct cmdu_buff *cmdu, struct tlv *tv[][16], uint8
 	return true;
 }
 
-bool validate_ap_metrics_response(struct cmdu_buff *cmdu, struct tlv *tv[][16], uint8_t profile)
+bool validate_ap_metrics_response(struct cmdu_buff *cmdu, struct tlv *tv[][TLV_MAXNUM], uint8_t profile)
 {
 	int ret = 0;
 	int idx;
@@ -905,7 +905,7 @@ bool validate_ap_metrics_response(struct cmdu_buff *cmdu, struct tlv *tv[][16],
 	return true;
 }
 
-bool validate_channel_scan_report(struct cmdu_buff *cmdu, struct tlv *tv_tsp[][16],
+bool validate_channel_scan_report(struct cmdu_buff *cmdu, struct tlv *tv_tsp[][TLV_MAXNUM],
 		struct tlv *tv_scan[], int *num, uint8_t profile)
 {
 	int i, j;
@@ -1041,7 +1041,7 @@ bool validate_channel_scan_report(struct cmdu_buff *cmdu, struct tlv *tv_tsp[][1
 
 
 #ifdef EASYMESH_VENDOR_EXT
-static int validate_topology_response_vext(struct tlv *tv[16])
+static int validate_topology_response_vext(struct tlv *tv[TLV_MAXNUM])
 {
 	const uint8_t vendor_oui[4] = {0};
 	uint32_t oui = 0;
@@ -1054,7 +1054,7 @@ static int validate_topology_response_vext(struct tlv *tv[16])
 	BUF_PUT_BE24(vendor_oui, oui);
 #endif
 
-	while (num < 16 && tv[num]) {
+	while (num < TLV_MAXNUM && tv[num]) {
 		uint16_t tlv_len = 0;
 		struct tlv_vendor_bbss *tlv;
 		int i, offset = 0;
@@ -1119,7 +1119,7 @@ static int validate_topology_response_vext(struct tlv *tv[16])
 
 #endif
 
-bool validate_topology_response(struct cmdu_buff *cmdu, struct tlv *tv[][16], uint8_t profile)
+bool validate_topology_response(struct cmdu_buff *cmdu, struct tlv *tv[][TLV_MAXNUM], uint8_t profile)
 {
 	trace("%s: --->\n", __func__);
 
@@ -1354,7 +1354,7 @@ static int check_wsc_tlv(struct tlv *t)
 	return validate_wsc_m1(tv_data, tlv_len);
 }
 
-bool validate_ap_autoconfig_wsc(struct cmdu_buff *cmdu, struct tlv *tv[][16], uint8_t profile)
+bool validate_ap_autoconfig_wsc(struct cmdu_buff *cmdu, struct tlv *tv[][TLV_MAXNUM], uint8_t profile)
 {
 	struct tlv_policy a_policy[] = {
 		[0] = { .type = MAP_TLV_AP_RADIO_BASIC_CAPABILITIES,
@@ -1419,7 +1419,7 @@ bool validate_ap_autoconfig_wsc(struct cmdu_buff *cmdu, struct tlv *tv[][16], ui
  * 5: MultiAP Profile TLV
  * 6: MAP_TLV_DPP_CHIRP_VALUE
  **/
-bool validate_ap_autoconfig_search(struct cmdu_buff *cmdu, struct tlv *tv[][16], uint8_t profile)
+bool validate_ap_autoconfig_search(struct cmdu_buff *cmdu, struct tlv *tv[][TLV_MAXNUM], uint8_t profile)
 {
 	int ret;
 
@@ -1450,7 +1450,7 @@ bool validate_ap_autoconfig_search(struct cmdu_buff *cmdu, struct tlv *tv[][16],
  * 5: MAP_TLV_DPP_CHIRP_VALUE\
  * 6: MAP_TLV_CONTROLLER_CAPS
  **/
-bool validate_ap_autoconfig_response(struct cmdu_buff *cmdu, struct tlv *tv[][16], uint8_t profile)
+bool validate_ap_autoconfig_response(struct cmdu_buff *cmdu, struct tlv *tv[][TLV_MAXNUM], uint8_t profile)
 {
 	int ret;
 
@@ -1471,7 +1471,7 @@ bool validate_ap_autoconfig_response(struct cmdu_buff *cmdu, struct tlv *tv[][16
 }
 
 #if (EASYMESH_VERSION > 2)
-bool validate_proxied_encap_dpp(struct cmdu_buff *cmdu, struct tlv *tlvs[][16])
+bool validate_proxied_encap_dpp(struct cmdu_buff *cmdu, struct tlv *tlvs[][TLV_MAXNUM])
 {
 	const int easymesh_rev = 4;
 
@@ -1496,7 +1496,7 @@ bool validate_proxied_encap_dpp(struct cmdu_buff *cmdu, struct tlv *tlvs[][16])
 	return true;
 }
 
-bool validate_direct_encap_dpp(struct cmdu_buff *cmdu, struct tlv *tlvs[][16])
+bool validate_direct_encap_dpp(struct cmdu_buff *cmdu, struct tlv *tlvs[][TLV_MAXNUM])
 {
 	const int easymesh_rev = 4;
 
@@ -1514,9 +1514,8 @@ bool validate_direct_encap_dpp(struct cmdu_buff *cmdu, struct tlv *tlvs[][16])
 	return true;
 }
 
-bool validate_bss_configuration_request(struct cmdu_buff *cmdu, struct tlv *tlvs[][16], uint8_t profile)
+bool validate_bss_configuration_request(struct cmdu_buff *cmdu, struct tlv *tlvs[][TLV_MAXNUM], uint8_t profile)
 {
-	const int max_num_of_tlvs = 16;
 	int i;
 
 
@@ -1542,7 +1541,7 @@ bool validate_bss_configuration_request(struct cmdu_buff *cmdu, struct tlv *tlvs
 	}
 
 	i = 0;
-	while ((i < max_num_of_tlvs) && tlvs[BSS_CFG_REQ_AP_RADIO_BASIC_CAPS_IDX][i]) {
+	while (i < TLV_MAXNUM && tlvs[BSS_CFG_REQ_AP_RADIO_BASIC_CAPS_IDX][i]) {
 		if (check_ap_radio_basic_cap_tlv(tlvs[BSS_CFG_REQ_AP_RADIO_BASIC_CAPS_IDX][i])) {
 			dbg("%s: check_ap_radio_basic_cap_tlv failed.\n", __func__);
 			return false;
@@ -1552,7 +1551,7 @@ bool validate_bss_configuration_request(struct cmdu_buff *cmdu, struct tlv *tlvs
 	}
 
 	i = 0;
-	while ((i < max_num_of_tlvs) && tlvs[BSS_CFG_REQ_BACKHAUL_STA_RADIO_CAPS_IDX][i]) {
+	while (i < TLV_MAXNUM && tlvs[BSS_CFG_REQ_BACKHAUL_STA_RADIO_CAPS_IDX][i]) {
 		if (check_backhaul_sta_radio_caps_tlv(tlvs[BSS_CFG_REQ_BACKHAUL_STA_RADIO_CAPS_IDX][i])) {
 			dbg("%s: check_backhaul_sta_radio_caps_tlv failed.\n", __func__);
 			return false;
@@ -1567,7 +1566,7 @@ bool validate_bss_configuration_request(struct cmdu_buff *cmdu, struct tlv *tlvs
 	}
 
 	i = 0;
-	while ((i < max_num_of_tlvs) && tlvs[BSS_CFG_REQ_AP_RADIO_ADVANCED_CAPS_IDX][i]) {
+	while (i < TLV_MAXNUM && tlvs[BSS_CFG_REQ_AP_RADIO_ADVANCED_CAPS_IDX][i]) {
 		if (check_ap_radio_adv_cap_tlv(tlvs[BSS_CFG_REQ_AP_RADIO_ADVANCED_CAPS_IDX][i])) {
 			dbg("%s: check_ap_radio_adv_cap_tlv failed.\n", __func__);
 			return false;
@@ -1585,7 +1584,7 @@ bool validate_bss_configuration_request(struct cmdu_buff *cmdu, struct tlv *tlvs
 }
 
 bool validate_bss_configuration_result(struct cmdu_buff *cmdu,
-				       struct tlv *tlvs[][16], uint8_t profile)
+				       struct tlv *tlvs[][TLV_MAXNUM], uint8_t profile)
 {
 
 	if (map_cmdu_parse_tlvs(cmdu, tlvs, BSS_CFG_RESULT_MAX_NUMBER_OF_TLV_TYPES, profile)) {
@@ -1603,7 +1602,7 @@ bool validate_bss_configuration_result(struct cmdu_buff *cmdu,
 }
 
 bool validate_dpp_bootstraping_uri_notification(struct cmdu_buff *cmdu,
-				       struct tlv *tlvs[][16])
+				       struct tlv *tlvs[][TLV_MAXNUM])
 {
 	const int easymesh_rev = 4;
 
diff --git a/src/cmdu_validate.h b/src/cmdu_validate.h
index 795fd177..70ceffc9 100644
--- a/src/cmdu_validate.h
+++ b/src/cmdu_validate.h
@@ -3,16 +3,16 @@
 #ifndef CMDU_VALIDATE
 #define CMDU_VALIDATE
 
-bool validate_topology_notification(struct cmdu_buff *cmdu, struct tlv *tv[][16], uint8_t profile);
-bool validate_1905_ack(struct cmdu_buff *cmdu, struct tlv *tv[][16], uint8_t profile);
-bool validate_ap_caps_report(struct cmdu_buff *cmdu, struct tlv *tv[][16], uint8_t profile);
-bool validate_ap_metrics_response(struct cmdu_buff *cmdu, struct tlv *tv[][16], uint8_t profile);
-bool validate_channel_scan_report(struct cmdu_buff *cmdu, struct tlv *tv_tsp[][16],
+bool validate_topology_notification(struct cmdu_buff *cmdu, struct tlv *tv[][TLV_MAXNUM], uint8_t profile);
+bool validate_1905_ack(struct cmdu_buff *cmdu, struct tlv *tv[][TLV_MAXNUM], uint8_t profile);
+bool validate_ap_caps_report(struct cmdu_buff *cmdu, struct tlv *tv[][TLV_MAXNUM], uint8_t profile);
+bool validate_ap_metrics_response(struct cmdu_buff *cmdu, struct tlv *tv[][TLV_MAXNUM], uint8_t profile);
+bool validate_channel_scan_report(struct cmdu_buff *cmdu, struct tlv *tv_tsp[][TLV_MAXNUM],
 				  struct tlv *tv_scan[], int *num, uint8_t profile);
-bool validate_topology_response(struct cmdu_buff *cmdu, struct tlv *tv_tsp[][16], uint8_t profile);
-bool validate_ap_autoconfig_wsc(struct cmdu_buff *cmdu, struct tlv *tv[][16], uint8_t profile);
-bool validate_ap_autoconfig_search(struct cmdu_buff *cmdu, struct tlv *tv[][16], uint8_t profile);
-bool validate_ap_autoconfig_response(struct cmdu_buff *cmdu, struct tlv *tv[][16], uint8_t profile);
+bool validate_topology_response(struct cmdu_buff *cmdu, struct tlv *tv_tsp[][TLV_MAXNUM], uint8_t profile);
+bool validate_ap_autoconfig_wsc(struct cmdu_buff *cmdu, struct tlv *tv[][TLV_MAXNUM], uint8_t profile);
+bool validate_ap_autoconfig_search(struct cmdu_buff *cmdu, struct tlv *tv[][TLV_MAXNUM], uint8_t profile);
+bool validate_ap_autoconfig_response(struct cmdu_buff *cmdu, struct tlv *tv[][TLV_MAXNUM], uint8_t profile);
 
 #if (EASYMESH_VERSION > 2)
 /**
@@ -27,7 +27,7 @@ enum proxied_encap_dpp_order {
 	PROXIED_ENCAP_DPP_MAX_NUMBER_OF_TLV_TYPES
 };
 
-bool validate_proxied_encap_dpp(struct cmdu_buff *cmdu, struct tlv *tlvs[][16]);
+bool validate_proxied_encap_dpp(struct cmdu_buff *cmdu, struct tlv *tlvs[][TLV_MAXNUM]);
 
 /**
  * @enum enum direct_encap_dpp_order
@@ -40,7 +40,7 @@ enum direct_encap_dpp_order {
 	DIRECT_ENCAP_DPP_MAX_NUMBER_OF_TLV_TYPES
 };
 
-bool validate_direct_encap_dpp(struct cmdu_buff *cmdu, struct tlv *tlvs[][16]);
+bool validate_direct_encap_dpp(struct cmdu_buff *cmdu, struct tlv *tlvs[][TLV_MAXNUM]);
 
 /**
  * @enum enum bss_configuration_request_tlvs_order
@@ -61,7 +61,7 @@ enum bss_configuration_request_tlvs_order {
 };
 
 bool validate_bss_configuration_request(struct cmdu_buff *cmdu,
-					struct tlv *tlvs[][16], uint8_t profile);
+					struct tlv *tlvs[][TLV_MAXNUM], uint8_t profile);
 
 /**
  * @enum enum bss_configuration_result_tlvs_order
@@ -75,7 +75,7 @@ enum bss_configuration_result_tlvs_order {
 };
 
 bool validate_bss_configuration_result(struct cmdu_buff *cmdu,
-				       struct tlv *tlvs[][16],
+				       struct tlv *tlvs[][TLV_MAXNUM],
 				       uint8_t profile);
 
 /**
@@ -90,7 +90,7 @@ enum dpp_bootstraping_uri_notification_order {
 };
 
 bool validate_dpp_bootstraping_uri_notification(struct cmdu_buff *cmdu,
-				       struct tlv *tlvs[][16]);
+				       struct tlv *tlvs[][TLV_MAXNUM]);
 
 #endif /* EASYMESH_VERSION> 2 */
 
diff --git a/src/cntlr_map.c b/src/cntlr_map.c
index a69c0752..88d0d4cc 100644
--- a/src/cntlr_map.c
+++ b/src/cntlr_map.c
@@ -184,7 +184,7 @@ int handle_topology_notification(void *cntlr, struct cmdu_buff *cmdu,
 				  struct node *n)
 {
 	uint8_t almac[6] = {0};
-	struct tlv *tv[2][16] = {0};
+	struct tlv *tv[2][TLV_MAXNUM] = {0};
 	struct controller *c = (struct controller *) cntlr;
 	struct tlv_aladdr *aladdr;
 	struct tlv *t;
@@ -235,7 +235,7 @@ int handle_topology_query(void *cntlr, struct cmdu_buff *cmdu, struct node *n)
 }
 
 #ifdef EASYMESH_VENDOR_EXT
-static int topology_response_vext(struct controller *c, struct node *n, struct tlv *tv[16])
+static int topology_response_vext(struct controller *c, struct node *n, struct tlv *tv[TLV_MAXNUM])
 {
 	const uint8_t vendor_oui[4] = {0};
 	uint32_t oui = 0;
@@ -249,7 +249,7 @@ static int topology_response_vext(struct controller *c, struct node *n, struct t
 #endif
 
 	/* vendor tlv containing backhaul interfaces only */
-	while (num < 16 && tv[num]) {
+	while (num < TLV_MAXNUM && tv[num]) {
 		struct tlv_vendor_bbss *tlv;
 		int i, offset = 0;
 		uint8_t oui2[3];  /* TODO: use the same vendor oui-type */
@@ -312,11 +312,11 @@ static int topology_response_vext(struct controller *c, struct node *n, struct t
 int handle_topology_response(void *cntlr, struct cmdu_buff *cmdu, struct node *n)
 {
 	struct controller *c = (struct controller *) cntlr;
-	struct tlv *tv[12][16] = {0};
+	struct tlv *tv[12][TLV_MAXNUM] = {0};
 	struct bh_topology_dev *bh_topo_dev = NULL;
-	const struct tlv_1905neighbor *neighbor_tlvs[16] = { NULL };
+	const struct tlv_1905neighbor *neighbor_tlvs[TLV_MAXNUM] = { NULL };
 	uint8_t neigh_tlv_cnt = 0;
-	uint16_t tlv_lengths[16] = { 0 };
+	uint16_t tlv_lengths[TLV_MAXNUM] = { 0 };
 
 	trace("%s: --->\n", __func__);
 
@@ -369,7 +369,7 @@ int handle_topology_response(void *cntlr, struct cmdu_buff *cmdu, struct node *n
 
 	/* 1905.1 neighbor device TLVs */
 	neigh_tlv_cnt = 0;
-	while (tv[3][neigh_tlv_cnt] && (neigh_tlv_cnt < 16)) {
+	while (tv[3][neigh_tlv_cnt] && (neigh_tlv_cnt < TLV_MAXNUM)) {
 		neighbor_tlvs[neigh_tlv_cnt] =
 			(struct tlv_1905neighbor *)tv[3][neigh_tlv_cnt]->data;
 
@@ -953,7 +953,7 @@ int handle_ap_autoconfig_search(void *cntlr, struct cmdu_buff *rx_cmdu,
 	struct tlv *t;
 	struct cmdu_buff *cmdu;
 	uint8_t almac[6] = {0};
-	struct tlv *tv[7][16] = {0};
+	struct tlv *tv[7][TLV_MAXNUM] = {0};
 	int ret = 0;
 	char freq_band[8] = {0};
 
@@ -1058,7 +1058,7 @@ int handle_ap_autoconfig_response(void *cntlr, struct cmdu_buff *rx_cmdu, struct
 	trace("%s: --->\n", __func__);
 	struct controller *c = (struct controller *) cntlr;
 	bool has_cntlr = false;
-	struct tlv *tv[7][16] = {0};
+	struct tlv *tv[7][TLV_MAXNUM] = {0};
 	int self_response = !memcmp(rx_cmdu->origin, c->almac, 6);
 
 	cntlr_set_link_profile(c, n, rx_cmdu);
@@ -1147,7 +1147,7 @@ int handle_ap_autoconfig_wsc(void *cntlr, struct cmdu_buff *rx_cmdu,
 
 	struct controller *c = (struct controller *) cntlr;
 	struct cmdu_buff *cmdu;
-	struct tlv *tv[4][16] = {0};
+	struct tlv *tv[4][TLV_MAXNUM] = {0};
 	struct tlv_ap_radio_basic_cap *ap_caps;
 	uint8_t wildcard[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
 	struct node_policy *np;
@@ -1194,7 +1194,7 @@ int handle_1905_ack(void *cntlr, struct cmdu_buff *cmdu, struct node *n)
 	trace("%s: --->\n", __func__);
 
 	struct controller *c = (struct controller *) cntlr;
-	struct tlv *tv[1][16] = {0};
+	struct tlv *tv[1][TLV_MAXNUM] = {0};
 	int idx;
 
 	trace("parsing 1905 ack |" MACFMT "|\n", MAC2STR(cmdu->origin));
@@ -1206,7 +1206,7 @@ int handle_1905_ack(void *cntlr, struct cmdu_buff *cmdu, struct node *n)
 	}
 
 	idx = 0;
-	while (tv[0][idx]) {
+	while (idx < TLV_MAXNUM && tv[0][idx]) {
 		struct tlv_error_code *data;
 		struct tlv *t = (struct tlv *)tv[0][idx++];
 		uint16_t mid = cmdu_get_mid(cmdu);
@@ -1464,7 +1464,7 @@ int handle_ap_caps_report(void *cntlr, struct cmdu_buff *cmdu, struct node *n)
 	int i = 0;
 	int offset = 0;
 	struct controller *c = (struct controller *) cntlr;
-	struct tlv *tv[13][16];
+	struct tlv *tv[13][TLV_MAXNUM] = {0};
 
 	if (!validate_ap_caps_report(cmdu, tv, n->map_profile)) {
 		dbg("cmdu validation: [AP_CAPS_REPORT] failed, ifce \"%s\"\n",
@@ -1489,7 +1489,7 @@ int handle_ap_caps_report(void *cntlr, struct cmdu_buff *cmdu, struct node *n)
 
 	index = 0;
 	/* Parse AP Radio Basic Capabilities TLV */
-	while (tv[1][index] && (index < 16)) {
+	while (index < TLV_MAXNUM && tv[1][index]) {
 		struct wifi_radio_opclass e4 = {};
 		struct wifi_radio_opclass *opclass;
 		struct netif_radio *r;
@@ -1564,7 +1564,7 @@ int handle_ap_caps_report(void *cntlr, struct cmdu_buff *cmdu, struct node *n)
 
 	index = 0;
 	/* AP HT Capabilities TLV */
-	while (tv[2][index] && (index < 16)) {
+	while (index < TLV_MAXNUM && tv[2][index]) {
 		struct netif_radio *r;
 		uint8_t *tv_data = (uint8_t *)tv[2][index++]->data;
 		struct tlv_ap_ht_cap *ht_caps =
@@ -1579,7 +1579,7 @@ int handle_ap_caps_report(void *cntlr, struct cmdu_buff *cmdu, struct node *n)
 
 	index = 0;
 	/* AP VHT Capabilities TLV */
-	while (tv[3][index] && (index < 16)) {
+	while (index < TLV_MAXNUM && tv[3][index]) {
 		struct netif_radio *r;
 		uint8_t *tv_data = (uint8_t *)tv[3][index++]->data;
 		struct tlv_ap_vht_cap *vht_caps =
@@ -1597,7 +1597,7 @@ int handle_ap_caps_report(void *cntlr, struct cmdu_buff *cmdu, struct node *n)
 	offset = 0;
 	index = 0;
 	/* AP HE Capabilities TLV */
-	while (tv[4][index] && (index < 16)) {
+	while (index < TLV_MAXNUM && tv[4][index]) {
 		struct netif_radio *r;
 		uint8_t *tv_data = (uint8_t *)tv[4][index++]->data;
 		struct tlv_ap_he_cap *he_caps =
@@ -1636,7 +1636,7 @@ int handle_channel_pref_report(void *cntlr, struct cmdu_buff *cmdu, struct node
 {
 	int idx, offset = 0;
 	int i, j;
-	struct tlv *tv[4][16] = { 0 };
+	struct tlv *tv[4][TLV_MAXNUM] = { 0 };
 	struct netif_radio *r;
 	int ret;
 
@@ -1650,7 +1650,7 @@ int handle_channel_pref_report(void *cntlr, struct cmdu_buff *cmdu, struct node
 	}
 
 	idx = 0;
-	while (tv[0][idx]) {
+	while (idx < TLV_MAXNUM && tv[0][idx]) {
 		struct tlv *t = (struct tlv *)tv[0][idx++];
 		uint8_t mac[6] = { 0 };
 		int num_opclass;
@@ -1709,7 +1709,7 @@ int handle_oper_channel_report(void *cntlr, struct cmdu_buff *cmdu, struct node
 	int idx = 0;
 	struct controller *c = (struct controller *) cntlr;
 	int ret;
-	struct tlv *tv[2][16];
+	struct tlv *tv[2][TLV_MAXNUM] = {0};
 	/*
 	 * [0] MAP_TLV_OPERATING_CHANNEL_REPORT
 	 * todo:
@@ -1725,7 +1725,7 @@ int handle_oper_channel_report(void *cntlr, struct cmdu_buff *cmdu, struct node
 		return ret;
 	}
 
-	while (tv[0][idx]) {
+	while (idx < TLV_MAXNUM && tv[0][idx]) {
 		int i;
 		int offset = 0;
 		uint8_t mac[6] = {0};
@@ -1782,7 +1782,7 @@ int handle_ap_metrics_response(void *cntlr, struct cmdu_buff *cmdu, struct node
 	struct netif_iface *ifc;
 	struct wifi_bss_element *b;
 	//struct link_metrics *link;
-	struct tlv *tv[7][16] = { 0 };
+	struct tlv *tv[7][TLV_MAXNUM] = { 0 };
 	struct tlv_ap_metrics *p;
 
 	if (!cmdu) {
@@ -1802,7 +1802,7 @@ int handle_ap_metrics_response(void *cntlr, struct cmdu_buff *cmdu, struct node
 
 	/* Storing AP Metrics TLV */
 	idx = 0;
-	while (tv[0][idx]) {
+	while (idx < TLV_MAXNUM && tv[0][idx]) {
 		p = (struct tlv_ap_metrics *) tv[0][idx++]->data;
 		if (!p)
 			continue;
@@ -2147,7 +2147,7 @@ int handle_link_metrics_response(struct controller *c, struct cmdu_buff *cmdu,
 				 struct node *n)
 {
 	trace("%s: --->\n", __func__);
-	struct tlv *tv[2][16];
+	struct tlv *tv[2][TLV_MAXNUM] = {0};
 	int num = 0;
 	int ret;
 
@@ -2261,7 +2261,7 @@ int handle_sta_link_metrics_response(void *cntlr, struct cmdu_buff *cmdu,
 	int i, idx = 0;
 	int offset = 0;
 	struct controller *c = (struct controller *) cntlr;
-	struct tlv *tv[3][16] = { 0 };
+	struct tlv *tv[3][TLV_MAXNUM] = { 0 };
 	int ret;
 
 	trace("%s: --->\n", __func__);
@@ -2529,7 +2529,7 @@ int handle_unassoc_sta_link_metrics_response(void *cntlr,
 		struct cmdu_buff *cmdu, struct node *n)
 {
 	struct controller *c = (struct controller *) cntlr;
-	struct tlv *tv[1][16] = {0};
+	struct tlv *tv[1][TLV_MAXNUM] = {0};
 	int i = 0;
 	int ret = 0;
 
@@ -2606,7 +2606,7 @@ int handle_beacon_metrics_response(void *cntlr, struct cmdu_buff *cmdu,
 {
 	struct controller *c = (struct controller *) cntlr;
 	struct tlv_beacon_metrics_resp *resp;
-	struct tlv *tv[1][16] = {0};
+	struct tlv *tv[1][TLV_MAXNUM] = {0};
 	uint8_t *ppos;
 	struct sta *s;
 	struct bcnreq *br;
@@ -2774,7 +2774,7 @@ int handle_sta_steer_btm_report(void *cntlr, struct cmdu_buff *cmdu,
 {
 	struct controller *c = (struct controller *) cntlr;
 	struct tlv_steer_btm_report *resp;
-	struct tlv *tv[1][16] = {0};
+	struct tlv *tv[1][TLV_MAXNUM] = {0};
 	struct sta *s;
 	struct wifi_apsta_steer_history *attempt;
 	char ev_data[512] = {0};
@@ -3270,8 +3270,8 @@ int handle_channel_scan_report(void *cntlr, struct cmdu_buff *cmdu,
 	dbg("%s: --->\n", __func__);
 
 	int num_result = 256;
-	struct tlv *tv_tsp[1][16];
-	struct tlv *tv_scan[256];
+	struct tlv *tv_tsp[1][TLV_MAXNUM] = {0};
+	struct tlv *tv_scan[256] = {0};
 	char timestamp[TIMESTAMP_MAX_LEN] = {0};
 	int len;
 	struct tlv_timestamp *p = NULL;
@@ -3322,7 +3322,7 @@ int handle_backhaul_sta_caps_report(void *cntlr, struct cmdu_buff *cmdu,
 				    struct node *n)
 {
 	uint8_t *tv_data;
-	struct tlv *tv[1][16];
+	struct tlv *tv[1][TLV_MAXNUM] = {0};
 	int num = 0;
 	struct controller *c = (struct controller *) cntlr;
 	int ret;
@@ -3339,7 +3339,7 @@ int handle_backhaul_sta_caps_report(void *cntlr, struct cmdu_buff *cmdu,
 		return -1;
 	}
 
-	while (tv[0][num]) {
+	while (num < TLV_MAXNUM && tv[0][num]) {
 		struct netif_radio *r;
 		struct tlv_bsta_radio_cap *p;
 
@@ -3382,7 +3382,7 @@ int handle_proxied_encap_dpp(void *cntlr, struct cmdu_buff *cmdu,
 	trace("%s: --->\n", __func__);
 	struct controller *c = (struct controller *)cntlr;
 	struct tlv *t;
-	struct tlv *tv[PROXIED_ENCAP_DPP_MAX_NUMBER_OF_TLV_TYPES][16] = { 0 };
+	struct tlv *tv[PROXIED_ENCAP_DPP_MAX_NUMBER_OF_TLV_TYPES][TLV_MAXNUM] = { 0 };
 	struct tlv_1905_encap_dpp *encap;
 	struct encap_dpp_frame *frm;
 	bool mac_present;
@@ -3560,7 +3560,7 @@ int handle_direct_encap_dpp(void *cntlr, struct cmdu_buff *cmdu,
 
 	struct controller *c = (struct controller *)cntlr;
 	struct tlv *tlv;
-	struct tlv *tlvs[DIRECT_ENCAP_DPP_MAX_NUMBER_OF_TLV_TYPES][16] = { 0 };
+	struct tlv *tlvs[DIRECT_ENCAP_DPP_MAX_NUMBER_OF_TLV_TYPES][TLV_MAXNUM] = { 0 };
 
 	if (!validate_direct_encap_dpp(cmdu, tlvs)) {
 		dbg("cmdu validation: [DIRECT_ENCAP_DPP] failed\n");
@@ -3584,7 +3584,7 @@ int handle_bss_configuration_request(void *cntlr, struct cmdu_buff *request_cmdu
 	int res;
 	struct cmdu_buff *response_cmdu;
 	struct controller *c = (struct controller *)cntlr;
-	struct tlv *tlvs[BSS_CFG_REQ_MAX_NUMBER_OF_TLV_TYPES][16] = { 0 };
+	struct tlv *tlvs[BSS_CFG_REQ_MAX_NUMBER_OF_TLV_TYPES][TLV_MAXNUM] = { 0 };
 
 	cntlr_set_link_profile(c, n, request_cmdu);
 
@@ -3631,7 +3631,7 @@ int handle_bss_configuration_result(void *cntlr, struct cmdu_buff *cmdu,
 	struct controller *c = (struct controller *)cntlr;
 	struct tlv *tlv;
 
-	struct tlv *tlvs[BSS_CFG_RESULT_MAX_NUMBER_OF_TLV_TYPES][16] = { 0 };
+	struct tlv *tlvs[BSS_CFG_RESULT_MAX_NUMBER_OF_TLV_TYPES][TLV_MAXNUM] = { 0 };
 
 	if (!validate_bss_configuration_result(cmdu, tlvs, n->map_profile)) {
 		dbg("cmdu validation: [BSS_CONFIGURATION_RESULT] failed\n");
@@ -3657,7 +3657,7 @@ int handle_dpp_bootstraping_uri_notificiation(void *cntlr, struct cmdu_buff *cmd
 
 	struct controller *controller = (struct controller *)cntlr;
 	struct tlv *tlv;
-	struct tlv *tlvs[DPP_BOOTSTRAP_URI_NOTIF_MAX_NUMBER_OF_TLV_TYPES][16] = { 0 };
+	struct tlv *tlvs[DPP_BOOTSTRAP_URI_NOTIF_MAX_NUMBER_OF_TLV_TYPES][TLV_MAXNUM] = { 0 };
 
 	if (!validate_dpp_bootstraping_uri_notification(cmdu, tlvs)) {
 		dbg("cmdu validation: [DPP_BOOTSTRAP_URI_NOTIF] failed\n");
diff --git a/src/cntlr_map_debug.c b/src/cntlr_map_debug.c
index 98ee7655..4ff59d91 100644
--- a/src/cntlr_map_debug.c
+++ b/src/cntlr_map_debug.c
@@ -77,7 +77,7 @@ int debug_topology_response(void *cntlr, struct cmdu_buff *cmdu, struct node *n)
 	trace("%s: --->\n", __func__);
 
 	/* TODO: TODO: debug base TLVs */
-	struct tlv *tv[12][16] = {0};
+	struct tlv *tv[12][TLV_MAXNUM] = {0};
 
 	if (!validate_topology_response(cmdu, tv, n->map_profile)) {
 		dbg("cmdu validation: [TOPOLOGY_RESPONSE] failed\n");
@@ -211,7 +211,7 @@ int debug_ap_autoconfig_wsc(void *cntlr, struct cmdu_buff *cmdu, struct node *n)
 int debug_1905_ack(void *cntlr, struct cmdu_buff *cmdu, struct node *n)
 {
 	int idx;
-	struct tlv *tv[1][16] = {0};
+	struct tlv *tv[1][TLV_MAXNUM] = {0};
 	int ret;
 
 	ret = map_cmdu_parse_tlvs(cmdu, tv, 1, n->map_profile);
@@ -246,7 +246,7 @@ int debug_ap_caps_report(void *cntlr, struct cmdu_buff *cmdu, struct node *n)
 	int i, j;
 	int index = 0;
 	int offset = 0;
-	struct tlv *tv[13][16];
+	struct tlv *tv[13][TLV_MAXNUM] = {0};
 	int ret;
 
 	ret = map_cmdu_parse_tlvs(cmdu, tv, 13, n->map_profile);
@@ -268,7 +268,7 @@ int debug_ap_caps_report(void *cntlr, struct cmdu_buff *cmdu, struct node *n)
 
 	index = 0;
 	/* Parse AP Radio Basic Capabilities TLV */
-	while (tv[1][index] && (index < 16)) {
+	while (index < TLV_MAXNUM && tv[1][index]) {
 		uint8_t *tv_data = (uint8_t *)tv[1][index++]->data;
 
 		trace_tlv_ap_radio_basic_cap((struct tlv_ap_radio_basic_cap *)tv_data);
@@ -276,7 +276,7 @@ int debug_ap_caps_report(void *cntlr, struct cmdu_buff *cmdu, struct node *n)
 
 	index = 0;
 	/* Parse AP HT Capabilities TLV */
-	while (tv[2][index] && (index < 16)) {
+	while (index < TLV_MAXNUM && tv[2][index]) {
 		struct tlv_ap_ht_cap *p =
 			(struct tlv_ap_ht_cap *)tv[2][index++]->data;
 		trace("\nTLV type: MAP_TLV_AP_HT_CAPABILITIES\n");
@@ -287,7 +287,7 @@ int debug_ap_caps_report(void *cntlr, struct cmdu_buff *cmdu, struct node *n)
 
 	index = 0;
 	/* AP VHT Capabilities TLV */
-	while (tv[3][index] && (index < 16)) {
+	while (index < TLV_MAXNUM && tv[3][index]) {
 		struct tlv_ap_vht_cap *p =
 			(struct tlv_ap_vht_cap *)tv[3][index++]->data;
 
@@ -302,7 +302,7 @@ int debug_ap_caps_report(void *cntlr, struct cmdu_buff *cmdu, struct node *n)
 
 	index = 0;
 	/* Parse AP HE Capabilities TLV */
-	while (tv[4][index] && (index < 16)) {
+	while (index < TLV_MAXNUM && tv[4][index]) {
 		uint8_t *tv_data = (uint8_t *)tv[4][index++]->data;
 		struct tlv_ap_he_cap *p =
 			(struct tlv_ap_he_cap *)tv_data;
@@ -458,7 +458,7 @@ int debug_channel_pref_report(void *cntlr, struct cmdu_buff *cmdu, struct node *
 {
 	int idx, offset = 0;
 	int i, j;
-	struct tlv *tv[4][16] = { 0 };
+	struct tlv *tv[4][TLV_MAXNUM] = { 0 };
 	int ret;
 
 	trace("%s: --->\n", __func__);
@@ -473,7 +473,7 @@ int debug_channel_pref_report(void *cntlr, struct cmdu_buff *cmdu, struct node *
 	}
 
 	idx = 0;
-	while (tv[0][idx]) {
+	while (idx < TLV_MAXNUM && tv[0][idx]) {
 		int num_opclass;
 		uint8_t mac[6] = { 0 };
 		struct tlv *t = (struct tlv *)tv[0][idx++];
@@ -505,7 +505,7 @@ int debug_channel_pref_report(void *cntlr, struct cmdu_buff *cmdu, struct node *
 	}
 
 	idx = 0;
-	while (tv[1][idx]) {
+	while (idx < TLV_MAXNUM && tv[1][idx]) {
 		uint8_t mac[6] = { 0 };
 		int num_opclass;
 		struct tlv *t = (struct tlv *)tv[1][idx++];
@@ -605,7 +605,7 @@ int debug_channel_sel_response(void *cntlr, struct cmdu_buff *cmdu, struct node
 			MAC2STR(cmdu->origin));
 
 	int idx;
-	struct tlv *tv[1][16];
+	struct tlv *tv[1][TLV_MAXNUM] = {0};
 	int ret;
 
 	ret = map_cmdu_parse_tlvs(cmdu, tv, 1, n->map_profile);
@@ -616,7 +616,7 @@ int debug_channel_sel_response(void *cntlr, struct cmdu_buff *cmdu, struct node
 	}
 
 	idx = 0;
-	while (tv[0][idx]) {
+	while (idx < TLV_MAXNUM && tv[0][idx]) {
 		struct tlv_channel_selection_resp *p =
 			(struct tlv_channel_selection_resp *)tv[0][idx++]->data;
 
@@ -635,7 +635,7 @@ int debug_oper_channel_report(void *cntlr, struct cmdu_buff *cmdu, struct node *
 
 	int idx;
 	int ret;
-	struct tlv *tv[2][16];
+	struct tlv *tv[2][TLV_MAXNUM] = {0};
 	/*
 	 * [0] MAP_TLV_OPERATING_CHANNEL_REPORT
 	 * todo:
@@ -650,7 +650,7 @@ int debug_oper_channel_report(void *cntlr, struct cmdu_buff *cmdu, struct node *
 	}
 
 	idx= 0;
-	while (tv[0][idx]) {
+	while (idx < TLV_MAXNUM && tv[0][idx]) {
 		int i, num_opclass;
 		int offset = 0;
 		uint8_t mac[6] = {0};
@@ -675,7 +675,7 @@ int debug_oper_channel_report(void *cntlr, struct cmdu_buff *cmdu, struct node *
 
 int debug_sta_caps_report(void *cntlr, struct cmdu_buff *cmdu, struct node *n)
 {
-	struct tlv *tv[3][16];
+	struct tlv *tv[3][TLV_MAXNUM] = {0};
 	int ret;
 
 	ret = map_cmdu_parse_tlvs(cmdu, tv, 3, n->map_profile);
@@ -734,7 +734,7 @@ int debug_ap_metrics_response(void *cntlr, struct cmdu_buff *cmdu, struct node *
 {
 	int i;
 	int offset, idx = 0;
-	struct tlv *tv[7][16] = { 0 };
+	struct tlv *tv[7][TLV_MAXNUM] = { 0 };
 	int ret;
 
 	trace("%s: --->\n", __func__);
@@ -749,7 +749,7 @@ int debug_ap_metrics_response(void *cntlr, struct cmdu_buff *cmdu, struct node *
 	}
 
 	idx = 0;
-	while (tv[0][idx]) {
+	while (idx < TLV_MAXNUM && tv[0][idx]) {
 		size_t out_len;
 		int index = 0;
 		unsigned char est_str[16];
@@ -789,7 +789,7 @@ int debug_ap_metrics_response(void *cntlr, struct cmdu_buff *cmdu, struct node *
 	}
 
 	idx = 0;
-	while (tv[1][idx]) {
+	while (idx < TLV_MAXNUM && tv[1][idx]) {
 		struct tlv_assoc_sta_traffic_stats *p =
 			(struct tlv_assoc_sta_traffic_stats *) tv[1][idx++]->data;
 
@@ -805,7 +805,7 @@ int debug_ap_metrics_response(void *cntlr, struct cmdu_buff *cmdu, struct node *
 	}
 
 	idx = 0;
-	while (tv[2][idx]) {
+	while (idx < TLV_MAXNUM && tv[2][idx]) {
 		uint8_t *tv_data = (uint8_t *)tv[2][idx++]->data;
 		struct tlv_assoc_sta_link_metrics *p =
 			(struct tlv_assoc_sta_link_metrics *)tv_data;
@@ -831,7 +831,7 @@ int debug_ap_metrics_response(void *cntlr, struct cmdu_buff *cmdu, struct node *
 	}
 
 	idx = 0;
-	while (tv[3][idx]) {
+	while (idx < TLV_MAXNUM && tv[3][idx]) {
 		struct tlv_ap_ext_metrics *p =
 			(struct tlv_ap_ext_metrics *) tv[3][idx++]->data;
 
@@ -846,7 +846,7 @@ int debug_ap_metrics_response(void *cntlr, struct cmdu_buff *cmdu, struct node *
 	}
 
 	idx = 0;
-	while (tv[4][idx]) {
+	while (idx < TLV_MAXNUM && tv[4][idx]) {
 		struct tlv_radio_metrics *p =
 			(struct tlv_radio_metrics *) tv[4][idx++]->data;
 
@@ -859,7 +859,7 @@ int debug_ap_metrics_response(void *cntlr, struct cmdu_buff *cmdu, struct node *
 	}
 
 	idx = 0;
-	while (tv[5][idx]) {
+	while (idx < TLV_MAXNUM && tv[5][idx]) {
 		uint8_t *tv_data = (uint8_t *)tv[5][idx++]->data;
 		struct tlv_sta_ext_link_metric *p =
 			(struct tlv_sta_ext_link_metric *)tv_data;
@@ -893,7 +893,7 @@ int debug_sta_link_metrics_response(void *cntlr, struct cmdu_buff *cmdu, struct
 {
 	int i;
 	int offset = 0;
-	struct tlv *tv[3][16] = { 0 };
+	struct tlv *tv[3][TLV_MAXNUM] = { 0 };
 	int ret;
 
 	trace("%s: --->\n", __func__);
@@ -972,7 +972,7 @@ int debug_unassoc_sta_link_metrics_response(void *cntlr,
 
 	int i;
 	int offset = 0;
-	struct tlv *tv[1][16];
+	struct tlv *tv[1][TLV_MAXNUM] = {0};
 	int ret;
 
 	trace("parsing unassociated sta link metric response |" \
@@ -1012,7 +1012,7 @@ int debug_unassoc_sta_link_metrics_response(void *cntlr,
 
 int debug_beacon_metrics_response(void *cntlr, struct cmdu_buff *cmdu, struct node *n)
 {
-	struct tlv *tv[1][16] = {0};
+	struct tlv *tv[1][TLV_MAXNUM] = {0};
 	int ret = 0;
 
 	trace("%s: --->\n", __func__);
@@ -1064,7 +1064,7 @@ int debug_sta_steer_btm_report(void *cntlr, struct cmdu_buff *cmdu, struct node
 	trace("parsing steer btm report of |:" MACFMT "|\n",
 			MAC2STR(cmdu->origin));
 
-	struct tlv *tv[1][16];
+	struct tlv *tv[1][TLV_MAXNUM] = {0};
 	int ret;
 
 	ret = map_cmdu_parse_tlvs(cmdu, tv, 1, n->map_profile);
@@ -1183,8 +1183,8 @@ int debug_channel_scan_report(void *cntlr, struct cmdu_buff *cmdu, struct node *
 	uint16_t num_neightbor;
 	uint8_t bw_len;
 	uint8_t *tv_data = NULL;
-	struct tlv *tv_tsp[1][16];
-	struct tlv *tv_scan[256];
+	struct tlv *tv_tsp[1][TLV_MAXNUM] = {0};
+	struct tlv *tv_scan[256] = {0};
 	char timestamp[TIMESTAMP_MAX_LEN] = {0};
 	struct tlv_timestamp *p = NULL;
 
@@ -1281,7 +1281,7 @@ int debug_sta_disassoc_stats(void *cntlr, struct cmdu_buff *cmdu, struct node *n
 {
 	trace("%s: --->\n", __func__);
 
-	struct tlv *tv[3][16];
+	struct tlv *tv[3][TLV_MAXNUM] = {0};
 	int ret;
 
 	ret = map_cmdu_parse_tlvs(cmdu, tv, 3, n->map_profile);
@@ -1328,7 +1328,7 @@ int debug_assoc_status_notification(void *cntlr, struct cmdu_buff *cmdu, struct
 	uint8_t *p;
 	int i, num_bss;
 	int offset = 0;
-	struct tlv *tv[1][16];
+	struct tlv *tv[1][TLV_MAXNUM] = {0};
 	int ret;
 
 	trace("%s: ---> origin: " MACFMT "\n", __func__, MAC2STR(cmdu->origin));
@@ -1356,7 +1356,7 @@ int debug_assoc_status_notification(void *cntlr, struct cmdu_buff *cmdu, struct
 
 int debug_tunneled_message(void *cntlr, struct cmdu_buff *cmdu, struct node *n)
 {
-	struct tlv *tv[3][16] = { 0 };
+	struct tlv *tv[3][TLV_MAXNUM] = { 0 };
 	int ret;
 
 	trace("%s: --->\n", __func__);
@@ -1412,7 +1412,7 @@ int debug_backhaul_sta_caps_report(void *cntlr, struct cmdu_buff *cmdu, struct n
 {
 	trace("%s: --->\n", __func__);
 	uint8_t *tv_data;
-	struct tlv *tv[1][16];
+	struct tlv *tv[1][TLV_MAXNUM] = {0};
 	int num = 0;
 	int ret;
 
@@ -1428,7 +1428,7 @@ int debug_backhaul_sta_caps_report(void *cntlr, struct cmdu_buff *cmdu, struct n
 		return -1;
 	}
 
-	while (tv[0][num]) {
+	while (num < TLV_MAXNUM && tv[0][num]) {
 		if (tv[0][num]->type != MAP_TLV_BACKHAUL_STA_RADIO_CAPABILITY) {
 			dbg("Wrong received TLV type!\n");
 			return -1;
@@ -1459,7 +1459,7 @@ int debug_proxied_encap_dpp(void *cntlr, struct cmdu_buff *cmdu, struct node *n)
 	trace("%s: --->\n", __func__);
 
 	const int easymesh_rev = 4;
-	struct tlv *tlvs[PROXIED_ENCAP_DPP_MAX_NUMBER_OF_TLV_TYPES][16] = { 0 };
+	struct tlv *tlvs[PROXIED_ENCAP_DPP_MAX_NUMBER_OF_TLV_TYPES][TLV_MAXNUM] = { 0 };
 
 	if (map_cmdu_parse_tlvs(cmdu, tlvs, PROXIED_ENCAP_DPP_MAX_NUMBER_OF_TLV_TYPES, easymesh_rev)) {
 		dbg("%s: map_cmdu_parse_tlvs failed,  err = (%d) '%s'\n", __func__,
@@ -1482,7 +1482,7 @@ int debug_direct_encap_dpp(void *cntlr, struct cmdu_buff *cmdu, struct node *n)
 	trace("%s: --->\n", __func__);
 
 	const int easymesh_rev = 4;
-	struct tlv *tlvs[DIRECT_ENCAP_DPP_MAX_NUMBER_OF_TLV_TYPES][16] = { 0 };
+	struct tlv *tlvs[DIRECT_ENCAP_DPP_MAX_NUMBER_OF_TLV_TYPES][TLV_MAXNUM] = { 0 };
 
 	if (map_cmdu_parse_tlvs(cmdu, tlvs, DIRECT_ENCAP_DPP_MAX_NUMBER_OF_TLV_TYPES, easymesh_rev)) {
 		dbg("%s: map_cmdu_parse_tlvs failed,  err = (%d) '%s'\n", __func__,
@@ -1501,8 +1501,7 @@ int debug_bss_configuration_request(void *cntlr, struct cmdu_buff *cmdu, struct
 	trace("%s: --->\n", __func__);
 
 	int easymesh_rev = n->map_profile;
-	const int max_num_of_tlvs = 16;
-	struct tlv *tlvs[BSS_CFG_REQ_MAX_NUMBER_OF_TLV_TYPES][16] = { 0 };
+	struct tlv *tlvs[BSS_CFG_REQ_MAX_NUMBER_OF_TLV_TYPES][TLV_MAXNUM] = { 0 };
 	const struct tlv *tlv;
 	int i;
 
@@ -1526,7 +1525,7 @@ int debug_bss_configuration_request(void *cntlr, struct cmdu_buff *cmdu, struct
 
 	/* One or more AP Radio Basic Capabilities TLV */
 	i = 0;
-	while ((i < max_num_of_tlvs) && tlvs[BSS_CFG_REQ_AP_RADIO_BASIC_CAPS_IDX][i]) {
+	while (i < TLV_MAXNUM && tlvs[BSS_CFG_REQ_AP_RADIO_BASIC_CAPS_IDX][i]) {
 
 		tlv = tlvs[BSS_CFG_REQ_AP_RADIO_BASIC_CAPS_IDX][i++];
 		trace_tlv_ap_radio_basic_cap((struct tlv_ap_radio_basic_cap *)tlv->data);
@@ -1534,7 +1533,7 @@ int debug_bss_configuration_request(void *cntlr, struct cmdu_buff *cmdu, struct
 
 	/* Zero or more Backhaul STA Radio Capabilities TLV */
 	i = 0;
-	while ((i < max_num_of_tlvs) && tlvs[BSS_CFG_REQ_BACKHAUL_STA_RADIO_CAPS_IDX][i]) {
+	while (i < TLV_MAXNUM && tlvs[BSS_CFG_REQ_BACKHAUL_STA_RADIO_CAPS_IDX][i]) {
 
 		tlv = tlvs[BSS_CFG_REQ_BACKHAUL_STA_RADIO_CAPS_IDX][i++];
 		trace_tlv_bsta_radio_cap((struct tlv_bsta_radio_cap  *)tlv->data);
@@ -1546,7 +1545,7 @@ int debug_bss_configuration_request(void *cntlr, struct cmdu_buff *cmdu, struct
 
 	/* One or more AP Radio Advanced Capabilities TLV */
 	i = 0;
-	while ((i < max_num_of_tlvs) && tlvs[BSS_CFG_REQ_AP_RADIO_ADVANCED_CAPS_IDX][i]) {
+	while (i < TLV_MAXNUM && tlvs[BSS_CFG_REQ_AP_RADIO_ADVANCED_CAPS_IDX][i]) {
 
 		tlv = tlvs[BSS_CFG_REQ_AP_RADIO_ADVANCED_CAPS_IDX][i++];
 		trace_tlv_ap_radio_adv_cap((struct tlv_ap_radio_adv_cap  *)tlv->data);
@@ -1564,7 +1563,7 @@ int debug_bss_configuration_result(void *cntlr, struct cmdu_buff *cmdu, struct n
 	trace("%s: --->\n", __func__);
 	int easymesh_rev = n->map_profile;
 
-	struct tlv *tlvs[BSS_CFG_RESULT_MAX_NUMBER_OF_TLV_TYPES][16] = { 0 };
+	struct tlv *tlvs[BSS_CFG_RESULT_MAX_NUMBER_OF_TLV_TYPES][TLV_MAXNUM] = { 0 };
 
 	if (map_cmdu_parse_tlvs(cmdu, tlvs, BSS_CFG_RESULT_MAX_NUMBER_OF_TLV_TYPES, easymesh_rev)) {
 		dbg("%s: map_cmdu_parse_tlvs failed,  err = (%d) '%s'\n", __func__,
@@ -1586,7 +1585,7 @@ int debug_dpp_bootstraping_uri_notificiation(void *cntlr, struct cmdu_buff *cmdu
 	trace("%s: --->\n", __func__);
 
 	const int easymesh_rev = 4;
-	struct tlv *tlvs[DPP_BOOTSTRAP_URI_NOTIF_MAX_NUMBER_OF_TLV_TYPES][16] = { 0 };
+	struct tlv *tlvs[DPP_BOOTSTRAP_URI_NOTIF_MAX_NUMBER_OF_TLV_TYPES][TLV_MAXNUM] = { 0 };
 
 	if (map_cmdu_parse_tlvs(cmdu, tlvs, DPP_BOOTSTRAP_URI_NOTIF_MAX_NUMBER_OF_TLV_TYPES, easymesh_rev)) {
 		dbg("%s: map_cmdu_parse_tlvs failed,  err = (%d) '%s'\n", __func__,
-- 
GitLab