From 9e76905c566e5c61bc9889b9b981b49c1b49fc89 Mon Sep 17 00:00:00 2001 From: Sylvain Munaut Date: Fri, 15 Nov 2013 18:00:09 +0100 Subject: lapdm: Implement randomized padding Specs taken from ETSI TS 144 006 V11.0.0 (2012-10), Section 5.2 The default behavior stays the same, but randomization can be enabled via a flag. The test is also modified to check that stuff is indeed getting randomized. Note that this is only part of a full randomized padding implementation. Some other part should get randomized as well but those aren't implemented here ... (like SI5/6 padding and the empty frames). Signed-off-by: Sylvain Munaut --- src/gsm/lapdm.c | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/gsm/lapdm.c b/src/gsm/lapdm.c index 19f78a1a..6f08223e 100644 --- a/src/gsm/lapdm.c +++ b/src/gsm/lapdm.c @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -201,11 +202,24 @@ static inline unsigned char *msgb_pull_l2h(struct msgb *msg) return ret; } +/* Choose padding mode for a given entity */ +static enum lapdm_pad_mode lapdm_select_pad_mode(struct lapdm_entity *ent) +{ + if (!(ent->flags & LAPDM_ENT_F_RANDOM_PADDING)) + return LAPDM_PAD_MODE_LEGACY; + + return ent->mode == LAPDM_MODE_MS ? + LAPDM_PAD_MODE_RANDOM_MS : + LAPDM_PAD_MODE_RANDOM_BTS; +} + /* Append padding (if required) */ -static void lapdm_pad_msgb(struct msgb *msg, uint8_t n201) +static void lapdm_pad_msgb(struct msgb *msg, uint8_t n201, + enum lapdm_pad_mode mode) { int pad_len = n201 - msgb_l2len(msg); uint8_t *data; + int i; if (pad_len < 0) { LOGP(DLLAPD, LOGL_ERROR, @@ -213,8 +227,27 @@ static void lapdm_pad_msgb(struct msgb *msg, uint8_t n201) return; } + if (!pad_len) + return; + data = msgb_put(msg, pad_len); - memset(data, 0x2B, pad_len); + + switch (mode) + { + case LAPDM_PAD_MODE_LEGACY: + memset(data, 0x2b, pad_len); + break; + + case LAPDM_PAD_MODE_RANDOM_MS: + for (i=0; itx_pending = 0; /* disabled flow control */ - lapdm_pad_msgb(msg, pad); + lapdm_pad_msgb(msg, pad, lapdm_select_pad_mode(le)); return le->l1_prim_cb(&pp.oph, le->l1_ctx); } @@ -305,7 +338,7 @@ int lapdm_phsap_dequeue_prim(struct lapdm_entity *le, struct osmo_phsap_prim *pp msgb_pull(msg, 1); /* Pad the frame, we can transmit now */ - lapdm_pad_msgb(msg, pad); + lapdm_pad_msgb(msg, pad, lapdm_select_pad_mode(le)); return 0; } -- cgit v1.2.3