Properly implement N3101

N3101 is incremented by unanswered USF requests, not from unanswered
POLLs.

Related: OS#5033
Change-Id: I1a55bdd39db8843976915b9f74fadb0942298413
diff --git a/src/pdch_ul_controller.c b/src/pdch_ul_controller.c
index c865f59..3f3776d 100644
--- a/src/pdch_ul_controller.c
+++ b/src/pdch_ul_controller.c
@@ -26,6 +26,7 @@
 #include "sba.h"
 #include "pdch.h"
 #include "pcu_utils.h"
+#include "tbf_ul.h"
 
 /* TS 44.060 Table 10.4.5.1 states maximum RRBP is N + 26. Give extra space for time diff between Tx and Rx? */
 #define MAX_FN_RESERVED (27 + 50)
@@ -261,7 +262,7 @@
 			LOGPDCH(ulc->pdch, DRLCMAC, LOGL_INFO,
 				"Timeout for registered USF (FN=%u): %s\n",
 				item->fn, tbf_name((struct gprs_rlcmac_tbf *)item->tbf_usf.ul_tbf));
-			/* TODO: increase N3101 */
+			tbf_usf_timeout(item->tbf_usf.ul_tbf);
 			break;
 		case PDCH_ULC_NODE_TBF_POLL:
 			LOGPDCH(ulc->pdch, DRLCMAC, LOGL_NOTICE,
diff --git a/src/tbf.cpp b/src/tbf.cpp
index 7237f58..a24f536 100644
--- a/src/tbf.cpp
+++ b/src/tbf.cpp
@@ -637,12 +637,6 @@
 
 	poll_state = GPRS_RLCMAC_POLL_NONE;
 
-	if (n_inc(N3101)) {
-		TBF_SET_STATE(this, GPRS_RLCMAC_RELEASING);
-		T_START(this, T3169, 3169, "MAX N3101 reached", false);
-		return;
-	}
-
 	if (ul_tbf && ul_tbf->handle_ctrl_ack()) {
 		if (!ul_tbf->ctrl_ack_to_toggle()) {
 			LOGPTBF(this, LOGL_NOTICE,
diff --git a/src/tbf_ul.cpp b/src/tbf_ul.cpp
index f226b29..ba491f6 100644
--- a/src/tbf_ul.cpp
+++ b/src/tbf_ul.cpp
@@ -772,6 +772,15 @@
 	return &m_window;
 }
 
+void gprs_rlcmac_ul_tbf::usf_timeout()
+{
+	if (n_inc(N3101)) {
+		TBF_SET_STATE(this, GPRS_RLCMAC_RELEASING);
+		T_START(this, T3169, 3169, "MAX N3101 reached", false);
+		return;
+	}
+}
+
 struct gprs_rlcmac_ul_tbf *as_ul_tbf(struct gprs_rlcmac_tbf *tbf)
 {
 	if (tbf && tbf->direction == GPRS_RLCMAC_UL_TBF)
@@ -779,3 +788,8 @@
 	else
 		return NULL;
 }
+
+void tbf_usf_timeout(struct gprs_rlcmac_ul_tbf *tbf)
+{
+	tbf->usf_timeout();
+}
diff --git a/src/tbf_ul.h b/src/tbf_ul.h
index 0c78e10..e3de1da 100644
--- a/src/tbf_ul.h
+++ b/src/tbf_ul.h
@@ -86,6 +86,7 @@
 	uint16_t window_size() const;
 	void set_window_size();
 	void update_coding_scheme_counter_ul(enum CodingScheme cs);
+        void usf_timeout();
 
 	/* Please note that all variables here will be reset when changing
 	 * from WAIT RELEASE back to FLOW state (re-use of TBF).
@@ -133,6 +134,7 @@
 void update_tbf_ta(struct gprs_rlcmac_ul_tbf *tbf, int8_t ta_delta);
 void set_tbf_ta(struct gprs_rlcmac_ul_tbf *tbf, uint8_t ta);
 struct gprs_rlcmac_ul_tbf *as_ul_tbf(struct gprs_rlcmac_tbf *tbf);
+void tbf_usf_timeout(struct gprs_rlcmac_ul_tbf *tbf);
 #ifdef __cplusplus
 }
 #endif