[PATCH libosmocore 3/8] smscb: process Null messages
Alex Badea
vamposdecampos at gmail.com
Sat Jan 5 20:26:27 CET 2013
Pick smscb messages with a sequence-number of "null". For these,
construct a RSL_MT_SMS_BC_CMD message and send it upstream.
Signed-off-by: Alex Badea <vamposdecampos at gmail.com>
---
src/gsm/smscb.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 67 insertions(+), 4 deletions(-)
diff --git a/src/gsm/smscb.c b/src/gsm/smscb.c
index a9f38eb..db7f1cc 100644
--- a/src/gsm/smscb.c
+++ b/src/gsm/smscb.c
@@ -28,9 +28,21 @@
/*! \file smscb.c */
#include <osmocom/gsm/smscb.h>
+#include <osmocom/gsm/rsl.h>
+#include <osmocom/gsm/tlv.h>
+#include <osmocom/gsm/protocol/gsm_04_12.h>
+#include <osmocom/gsm/protocol/gsm_08_58.h>
#include <osmocom/core/logging.h>
#include <osmocom/core/msgb.h>
+#include <errno.h>
+
+#define SMSCB_ALLOC_SIZE 256
+#define SMSCB_ALLOC_HEADROOM 64
+
+/* Link Protocol Discriminator for SMSCB */
+#define SMSCB_LPD 1
+
/*! \brief Initialize a SMSCB entity */
void smscb_init(struct smscb_entity *se)
{
@@ -48,14 +60,65 @@ void smscb_set_l3(struct smscb_entity *se, smscb_cb_t cb, void *ctx)
se->l3_ctx = ctx;
}
+static int rslms_sendmsg(struct msgb *msg, struct smscb_entity *se)
+{
+ if (!se->l3_cb) {
+ msgb_free(msg);
+ return -EIO;
+ }
+ return se->l3_cb(msg, se, se->l3_ctx);
+}
+
+static int smscb_rx_null_msg(struct smscb_entity *se)
+{
+ struct msgb *msg;
+ struct abis_rsl_cchan_hdr *ch;
+ struct rsl_ie_cb_cmd_type cmd_type = {};
+
+ msg = msgb_alloc_headroom(
+ SMSCB_ALLOC_HEADROOM + SMSCB_ALLOC_SIZE,
+ SMSCB_ALLOC_HEADROOM, "smscb_data");
+ if (!msg)
+ return -ENOMEM;
+
+ msg->l2h = msgb_put(msg, sizeof(*ch));
+ ch = (struct abis_rsl_cchan_hdr *) msg->l2h;
+ rsl_init_cchan_hdr(ch, RSL_MT_SMS_BC_CMD);
+ ch->c.msg_discr |= ABIS_RSL_MDISC_TRANSP;
+ /* TODO: we need ->chan_nr from L1: */
+ ch->chan_nr = rsl_enc_chan_nr(RSL_CHAN_SDCCH8_ACCH, 2, 2);
+
+ cmd_type.command = RSL_CB_CMD_TYPE_NULL;
+ msgb_tv_put(msg, RSL_IE_CB_CMD_TYPE, *((uint8_t *) &cmd_type));
+ msgb_tlv_put(msg, RSL_IE_SMSCB_MSG, 0, NULL);
+
+ /*
+ * TODO: we need ->frame_nr from L1:
+ * gsm_fn2gsmtime(&tm, ntohl(l1i->frame_nr));
+ * msgb_tv_put(msg, RSL_IE_SMSCB_CHAN_INDICATOR, !(tm.tc < 4));
+ */
+
+ return rslms_sendmsg(msg, se);
+}
+
+
+
/*! \brief Input data from layer 1 */
int smscb_ph_data_ind(struct smscb_entity *se, struct msgb *msg)
{
- uint8_t addr = msg->l2h[0];
- uint8_t seq = addr & 0x0f;
+ struct gsm412_block_type *bt = (struct gsm412_block_type *) msg->l2h;
+
+ LOGP(DLLAPD, LOGL_NOTICE, "SMSCB: received message: len=%d"
+ " seq=%d lb=%d lpd=%d spare=%d\n",
+ msg->len, bt->seq_nr, bt->lb, bt->lpd, bt->spare);
+
+ if (bt->lpd != SMSCB_LPD) {
+ msgb_free(msg);
+ return -EINVAL;
+ }
- LOGP(DLLAPD, LOGL_NOTICE, "SMSCB: received message: seq=%d len=%d\n",
- seq, msg->len);
+ if (bt->seq_nr == GSM412_SEQ_NULL_MSG)
+ smscb_rx_null_msg(se);
msgb_free(msg);
return 0;
--
1.7.0.4
More information about the baseband-devel
mailing list