aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <holger@moiji-mobile.com>2013-10-20 08:44:02 +0200
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2013-10-30 21:24:10 +0100
commit1702f102afd042b0e91a0d3f23edc83632cec94f (patch)
treef4118b8a04ba800b7597784818936fdd637aa5eb /src
parent7ce21eb042124b05faba929712de61de415973d0 (diff)
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.
Diffstat (limited to 'src')
-rw-r--r--src/gprs_rlcmac_data.cpp58
-rw-r--r--src/tbf.cpp49
-rw-r--r--src/tbf.h6
3 files changed, 60 insertions, 53 deletions
diff --git a/src/gprs_rlcmac_data.cpp b/src/gprs_rlcmac_data.cpp
index 67a8ed7..b33dd5e 100644
--- a/src/gprs_rlcmac_data.cpp
+++ b/src/gprs_rlcmac_data.cpp
@@ -37,11 +37,6 @@ static struct gprs_rlcmac_cs gprs_rlcmac_cs[] = {
extern void *tall_pcu_ctx;
-extern "C" {
-int bssgp_tx_llc_discarded(struct bssgp_bvc_ctx *bctx, uint32_t tlli,
- uint8_t num_frames, uint32_t num_octets);
-}
-
/* After receiving these frames, we send ack/nack. */
#define SEND_ACK_AFTER_FRAMES 20
@@ -1113,48 +1108,6 @@ int gprs_rlcmac_rcv_rach(struct gprs_rlcmac_bts *bts,
}
-/*
- * DL data block flow
- */
-
-static struct msgb *llc_dequeue(struct gprs_rlcmac_tbf *tbf)
-{
- struct msgb *msg;
- struct timeval *tv, tv_now;
- uint32_t octets = 0, frames = 0;
-
- gettimeofday(&tv_now, NULL);
-
- while ((msg = msgb_dequeue(&tbf->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",
- tbf->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(gprs_bssgp_pcu_current_bctx(),
- tbf->tlli, frames, octets);
- }
-
- return msg;
-}
-
/* send DL data block
*
* The messages are fragmented and forwarded as data blocks.
@@ -1363,12 +1316,11 @@ do_resend:
/* reset LLC frame */
tbf->llc_index = tbf->llc_length = 0;
/* dequeue next LLC frame, if any */
- msg = llc_dequeue(tbf);
+ msg = tbf->llc_dequeue(gprs_bssgp_pcu_current_bctx());
if (msg) {
LOGP(DRLCMACDL, LOGL_INFO, "- Dequeue next LLC for "
"TBF=%d (len=%d)\n", tbf->tfi, msg->len);
- memcpy(tbf->llc_frame, msg->data, msg->len);
- tbf->llc_length = msg->len;
+ tbf->update_llc_frame(msg);
msgb_free(msg);
}
/* if we have more data and we have space left */
@@ -1588,7 +1540,7 @@ int gprs_rlcmac_downlink_ack(struct gprs_rlcmac_bts *bts,
gprs_rlcmac_received_lost(tbf, received, lost);
/* check for LLC PDU in the LLC Queue */
- msg = llc_dequeue(tbf);
+ msg = tbf->llc_dequeue(gprs_bssgp_pcu_current_bctx());
if (!msg) {
/* no message, start T3193, change state to RELEASE */
LOGP(DRLCMACDL, LOGL_DEBUG, "- No new message, so we "
@@ -1601,8 +1553,8 @@ int gprs_rlcmac_downlink_ack(struct gprs_rlcmac_bts *bts,
return 0;
}
- memcpy(tbf->llc_frame, msg->data, msg->len);
- tbf->llc_length = msg->len;
+ #warning "Copy and paste on the sender path"
+ tbf->update_llc_frame(msg);
msgb_free(msg);
/* we have a message, so we trigger downlink assignment, and there
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 @@ extern "C" {
#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 @@ int gprs_rlcmac_tbf::rlcmac_diag()
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++) {
diff --git a/src/tbf.h b/src/tbf.h
index addf651..0441096 100644
--- a/src/tbf.h
+++ b/src/tbf.h
@@ -22,6 +22,8 @@
#include <stdint.h>
+struct bssgp_bvc_ctx;
+
/*
* TBF instance
*/
@@ -90,6 +92,10 @@ struct gprs_rlcmac_tbf {
bool state_is_not(enum gprs_rlcmac_tbf_state rhs) const;
void set_state(enum gprs_rlcmac_tbf_state new_state);
+ /* TODO: add the gettimeofday as parameter */
+ struct msgb *llc_dequeue(bssgp_bvc_ctx *bctx);
+ void update_llc_frame(struct msgb *msg);
+
int rlcmac_diag();
struct llist_head list;