Split tbf_fsm as tbf_{ul,dl}_fsm

The 2 types of TBF share some parts of the implementation, but actually
half of the code is specific to one direction or another.
Since FSM are becoming (and will become even) more complex, split the
FSM implementation into 2 separate FSMs, one for each direction.
The FSM interface is kept compatible (events and states), hence code can
still operate on the tbfs on events and states which are shared.

Test output changes are mainly due to:
* FSM instance now created in subclass constructor, so order of log
  lines during constructor of parent class and subclass slightly
  changes.
* osmo_fsm doesn't allow having 2 FSM types with same name registered,
  hence the "TBF" name has to be changed to "DL_TBF" and "UL_TBF" for
  each FSM class.
* FSM classes now use DTBFUL and DTBFDL instead of DTBF for logging. Some
  tests don't have those categories enabled, hence some log lines
  dissappear (it's actually fine we don't care about those in the test
  cases).

Change-Id: I879af3f4b3e330687d498cd59f5f4933d6ca56f0
diff --git a/src/tbf_fsm.h b/src/tbf_fsm.h
index 8f4f839..feb9e04 100644
--- a/src/tbf_fsm.h
+++ b/src/tbf_fsm.h
@@ -23,36 +23,50 @@
 struct gprs_rlcmac_tbf;
 
 enum tbf_fsm_event {
-	TBF_EV_ASSIGN_ADD_CCCH, /* An assignment is sent over CCCH and confirmation from MS is pending */
+	/* For both UL/DL TBF: */
+	TBF_EV_ASSIGN_ADD_CCCH,  /* An assignment is sent over CCCH and confirmation from MS is pending */
 	TBF_EV_ASSIGN_ADD_PACCH, /* An assignment is sent over PACCH and confirmation from MS is pending */
-	TBF_EV_ASSIGN_ACK_PACCH, /*  We received a CTRL ACK confirming assignment started on PACCH */
+	TBF_EV_ASSIGN_ACK_PACCH, /* We received a CTRL ACK confirming assignment started on PACCH */
+	TBF_EV_MAX_N3105, /* MAX N3105 (max poll timeout) reached */
+
+	/* Only for DL TBF: */
 	TBF_EV_ASSIGN_READY_CCCH, /* TBF Start Time timer triggered */
-	TBF_EV_ASSIGN_PCUIF_CNF, /* Transmission of IMM.ASS for DL TBF to the MS confirmed by BTS over PCUIF */
-	TBF_EV_FIRST_UL_DATA_RECVD, /* UL TBF: Received first UL data from MS. Equals to Contention Resolution completed on the network side */
-	TBF_EV_CONTENTION_RESOLUTION_MS_SUCCESS, /* UL TBF: Contention resolution success at the mobile station side (first UL_ACK_NACK confirming TLLI is received at the MS) */
-	TBF_EV_DL_ACKNACK_MISS, /* DL TBF: We polled for DL ACK/NACK but we received none (POLL timeout) */
-	TBF_EV_LAST_DL_DATA_SENT, /* DL TBF sends RLCMAC block containing last DL avilable data buffered */
-	TBF_EV_LAST_UL_DATA_RECVD, /* UL TBF sends RLCMAC block containing last UL data (cv=0) */
+	TBF_EV_ASSIGN_PCUIF_CNF, /* Transmission of IMM.ASS for to the MS confirmed by BTS over PCUIF */
+	TBF_EV_DL_ACKNACK_MISS, /* We polled for DL ACK/NACK but we received none (POLL timeout) */
+	TBF_EV_LAST_DL_DATA_SENT, /* Network sends RLCMAC block containing last DL avilable data buffered */
 	TBF_EV_FINAL_ACK_RECVD, /* DL ACK/NACK with FINAL_ACK=1 received from MS */
-	TBF_EV_FINAL_UL_ACK_CONFIRMED, /* UL TBF: MS ACKs (CtrlAck or PktResReq) our UL ACK/NACK w/ FinalAckInd=1. data = (bool) MS requests establishment of a new UL-TBF. */
-	TBF_EV_MAX_N3101, /* MAX N3101 (max usf timeout) reached (UL TBF) */
-	TBF_EV_MAX_N3103, /* MAX N3103 (max Pkt Ctrl Ack for last UL ACK/NACK timeout) reached (UL TBF) */
-	TBF_EV_MAX_N3105, /* MAX N3105 (max poll timeout) reached (UL/DL TBF) */
+
+	/* Only for UL TBF: */
+	TBF_EV_FIRST_UL_DATA_RECVD, /* Received first UL data from MS. Equals to Contention Resolution completed on the network side */
+	TBF_EV_CONTENTION_RESOLUTION_MS_SUCCESS, /* Contention resolution success at the mobile station side (first UL_ACK_NACK confirming TLLI is received at the MS) */
+	TBF_EV_LAST_UL_DATA_RECVD, /* MS ends RLCMAC block containing last UL data (cv=0) */
+	TBF_EV_FINAL_UL_ACK_CONFIRMED, /* MS ACKs (CtrlAck or PktResReq) our UL ACK/NACK w/ FinalAckInd=1. data = (bool) MS requests establishment of a new UL-TBF. */
+	TBF_EV_MAX_N3101, /* MAX N3101 (max usf timeout) reached */
+	TBF_EV_MAX_N3103, /* MAX N3103 (max Pkt Ctrl Ack for last UL ACK/NACK timeout) reached */
 };
 
+extern const struct value_string tbf_fsm_event_names[];
+
 enum tbf_fsm_states {
 	TBF_ST_NEW = 0,	/* new created TBF */
 	TBF_ST_ASSIGN,	/* wait for downlink assignment */
 	TBF_ST_FLOW,	/* RLC/MAC flow, resource needed */
 	TBF_ST_FINISHED,	/* flow finished, wait for release */
-	TBF_ST_WAIT_RELEASE,/* wait for release or restart of DL TBF */
+	TBF_ST_WAIT_RELEASE,/* DL TBF: wait for release or restart */
 	TBF_ST_RELEASING,	/* releasing, wait to free TBI/USF */
 };
 
-struct tbf_fsm_ctx {
-	struct gprs_rlcmac_tbf* tbf; /* back pointer */
+struct tbf_dl_fsm_ctx {
+	struct gprs_rlcmac_tbf *tbf; /* back pointer */
 	uint32_t state_flags;
 	unsigned int T_release; /* Timer to be used to end release: T3169 or T3195 */
 };
 
-extern struct osmo_fsm tbf_fsm;
+struct tbf_ul_fsm_ctx {
+	struct gprs_rlcmac_tbf *tbf; /* back pointer */
+	uint32_t state_flags;
+	unsigned int T_release; /* Timer to be used to end release: T3169 or T3195 */
+};
+
+extern struct osmo_fsm tbf_dl_fsm;
+extern struct osmo_fsm tbf_ul_fsm;