From 58a3e5fc73a7750b056cf11c00186d8186505df5 Mon Sep 17 00:00:00 2001 From: skarg Date: Tue, 17 Apr 2007 13:13:23 +0000 Subject: [PATCH] Corrected transaction state machine from a potential infinite loop when more than one invokeID is used at a time. --- bacnet-stack/tsm.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/bacnet-stack/tsm.c b/bacnet-stack/tsm.c index 434d1cdf..26800f1d 100644 --- a/bacnet-stack/tsm.c +++ b/bacnet-stack/tsm.c @@ -136,8 +136,8 @@ uint8_t tsm_next_free_invokeID(void) if (tsm_transaction_available()) { while (!found) { index = tsm_find_invokeID_index(current_invokeID); - /* not found - that is good! */ if (index == MAX_TSM_TRANSACTIONS) { + /* Not found, so this invokeID is not used */ found = true; /* set this id into the table */ index = tsm_find_first_free_index(); @@ -148,8 +148,17 @@ uint8_t tsm_next_free_invokeID(void) /* update for the next call or check */ current_invokeID++; /* skip zero - we treat that internally as invalid or no free */ - if (current_invokeID == 0) + if (current_invokeID == 0) { current_invokeID = 1; + } + } + } else { + /* found! This invokeID is already used */ + /* try next one */ + current_invokeID++; + /* skip zero - we treat that internally as invalid or no free */ + if (current_invokeID == 0) { + current_invokeID = 1; } } } @@ -247,6 +256,7 @@ void tsm_timer_milliseconds(uint16_t milliseconds) } } +/* frees the invokeID and sets its state to IDLE */ void tsm_free_invoke_id(uint8_t invokeID) { uint8_t index; @@ -258,7 +268,7 @@ void tsm_free_invoke_id(uint8_t invokeID) } } -/* see if the invoke ID has been made free */ +/* check if the invoke ID has been made free */ bool tsm_invoke_id_free(uint8_t invokeID) { bool status = true;