tbf: First round of removing llc handling from the rlcmac_data

The code in gprs_rlcmac_data should ask the TBF for help in packing
the frames but it really shouldn't poke in the internals of the
tbf structure. This is very bad capsuling and has plenty of copy
and paste.

At the same thime this will be the most dangerous refactoring of
the code base.
diff --git a/src/tbf.cpp b/src/tbf.cpp
index 2fcb51c..8800cca 100644
--- a/src/tbf.cpp
+++ b/src/tbf.cpp
@@ -32,6 +32,11 @@
 #include <errno.h>
 #include <string.h>
 
+extern "C" {
+int bssgp_tx_llc_discarded(struct bssgp_bvc_ctx *bctx, uint32_t tlli,
+                           uint8_t num_frames, uint32_t num_octets);
+}
+
 extern void *tall_pcu_ctx;
 
 static inline void tbf_update_ms_class(struct gprs_rlcmac_tbf *tbf,
@@ -577,6 +582,50 @@
 	return 0;
 }
 
+struct msgb *gprs_rlcmac_tbf::llc_dequeue(bssgp_bvc_ctx *bctx)
+{
+	struct msgb *msg;
+	struct timeval *tv, tv_now;
+	uint32_t octets = 0, frames = 0;
+
+	gettimeofday(&tv_now, NULL);
+
+	while ((msg = msgb_dequeue(&llc_queue))) {
+		tv = (struct timeval *)msg->data;
+		msgb_pull(msg, sizeof(*tv));
+		if (tv->tv_sec /* not infinite */
+		 && (tv_now.tv_sec > tv->tv_sec /* and secs expired */
+		  || (tv_now.tv_sec == tv->tv_sec /* .. or if secs equal .. */
+		   && tv_now.tv_usec > tv->tv_usec))) { /* .. usecs expired */
+			LOGP(DRLCMACDL, LOGL_NOTICE, "Discarding LLC PDU of "
+				"DL TBF=%d, because lifetime limit reached\n",
+				tfi);
+			frames++;
+			octets += msg->len;
+			msgb_free(msg);
+			continue;
+		}
+		break;
+	}
+
+	if (frames) {
+		if (frames > 0xff)
+			frames = 0xff;
+		if (octets > 0xffffff)
+			octets = 0xffffff;
+		bssgp_tx_llc_discarded(bctx, tlli, frames, octets);
+	}
+
+	return msg;
+}
+
+void gprs_rlcmac_tbf::update_llc_frame(struct msgb *msg)
+{
+	/* TODO: bounds check */
+	memcpy(llc_frame, msg->data, msg->len);
+	llc_length = msg->len;
+}
+
 void gprs_rlcmac_tbf::free_all(struct gprs_rlcmac_trx *trx)
 {
 	for (uint8_t tfi = 0; tfi < 32; tfi++) {