TBF: cleanup state flag handling

 * introduce generic function to check whether particular flag was set
   for'a TBF and clear it if necessary. Use this instead of
   clear_poll_timeout_flag()
 * add function to explicitly set assignment and appropriate state flags

Overall this makes the code easier to read and debug.

Related: OS#1759
Change-Id: Ic4560280c72f91700f2e19c6c7f6658dc29625c2
diff --git a/src/tbf.h b/src/tbf.h
index 943ec92..6d7edbc 100644
--- a/src/tbf.h
+++ b/src/tbf.h
@@ -180,6 +180,8 @@
 	bool state_is(enum gprs_rlcmac_tbf_state rhs) const;
 	bool state_is_not(enum gprs_rlcmac_tbf_state rhs) const;
 	void set_state(enum gprs_rlcmac_tbf_state new_state);
+	bool check_n_clear(uint8_t state_flag);
+	void set_assigned_on(uint8_t state_flag, bool check_ccch);
 	const char *state_name() const;
 
 	const char *name() const;
@@ -368,6 +370,17 @@
 	return tbf_state_name[state];
 }
 
+/* Set assignment state and corrsponding flags */
+inline void gprs_rlcmac_tbf::set_assigned_on(uint8_t state_flag, bool check_ccch)
+{
+	set_state(GPRS_RLCMAC_ASSIGN);
+	if (check_ccch) {
+		if (!(state_flags & (1 << GPRS_RLCMAC_FLAG_CCCH)))
+			state_flags |= (1 << state_flag);
+	} else
+		state_flags |= (1 << state_flag);
+}
+
 inline void gprs_rlcmac_tbf::set_state(enum gprs_rlcmac_tbf_state new_state)
 {
 	LOGP(DRLCMAC, LOGL_DEBUG, "%s changes state from %s to %s\n",
@@ -376,6 +389,16 @@
 	state = new_state;
 }
 
+inline bool gprs_rlcmac_tbf::check_n_clear(uint8_t state_flag)
+{
+	if ((state_flags & (1 << state_flag))) {
+		state_flags &= ~(1 << state_flag);
+		return true;
+	}
+
+	return false;
+}
+
 inline LListHead<gprs_rlcmac_tbf>& gprs_rlcmac_tbf::list()
 {
 	return this->m_list;
@@ -451,7 +474,7 @@
 	int rcvd_dl_ack(bool final_ack, unsigned first_bsn, struct bitvec *rbb);
 	struct msgb *create_dl_acked_block(uint32_t fn, uint8_t ts);
 	void trigger_ass(struct gprs_rlcmac_tbf *old_tbf);
-	void clear_poll_timeout_flag();
+
 	bool handle_ack_nack();
 	void request_dl_ack();
 	bool need_control_ts() const;