lapdm: Track fn of primitives in struct lapdm_msg_ctx

This field will be used in follow-up commits to provide FN information
in RSLms primitives towars upper layers. This is needed for instance on
the MS side when a CCCH_DATA.ind is received containing a TBF ImmAss
with a relative FN indicating the Starting Time. Without tracking FN
advance, the uppers layers are not capable of figuring out the absolute
FN of the TBF Starting time.

The struct lapdm_msg_ctx is not really used outside of libosmocore, so
we are safe extending it.

Related: OS#3626
Change-Id: Icf986f4202703eb452bedc1b749bb8ce0c73706f
diff --git a/include/osmocom/gsm/lapdm.h b/include/osmocom/gsm/lapdm.h
index 0e99743..1a39fca 100644
--- a/include/osmocom/gsm/lapdm.h
+++ b/include/osmocom/gsm/lapdm.h
@@ -24,6 +24,7 @@
 	uint8_t link_id;
 	uint8_t ta_ind;		/* TA indicated by network */
 	uint8_t tx_power_ind;	/* MS power indicated by network */
+	uint32_t fn;
 };
 
 /*! LAPDm datalink like TS 04.06 / Section 3.5.2 */
diff --git a/src/gsm/lapdm.c b/src/gsm/lapdm.c
index 4a82c4d..e96e218 100644
--- a/src/gsm/lapdm.c
+++ b/src/gsm/lapdm.c
@@ -700,7 +700,7 @@
 
 /* input into layer2 (from layer 1) */
 static int l2_ph_data_ind(struct msgb *msg, struct lapdm_entity *le,
-	uint8_t chan_nr, uint8_t link_id)
+	uint8_t chan_nr, uint8_t link_id, uint32_t fn)
 {
 	uint8_t cbits = chan_nr >> 3;
 	uint8_t sapi; /* we cannot take SAPI from link_id, as L1 has no clue */
@@ -715,6 +715,7 @@
 	memset(&mctx, 0, sizeof(mctx));
 	mctx.chan_nr = chan_nr;
 	mctx.link_id = link_id;
+	mctx.fn = fn;
 
 	/* check for L1 chan_nr/link_id and determine LAPDm hdr format */
 	if (cbits == 0x10 || cbits == 0x12) {
@@ -916,7 +917,7 @@
 	switch (OSMO_PRIM_HDR(oph)) {
 	case OSMO_PRIM(PRIM_PH_DATA, PRIM_OP_INDICATION):
 		rc = l2_ph_data_ind(oph->msg, le, pp->u.data.chan_nr,
-				    pp->u.data.link_id);
+				    pp->u.data.link_id, pp->u.data.fn);
 		break;
 	case OSMO_PRIM(PRIM_PH_RTS, PRIM_OP_INDICATION):
 		rc = l2_ph_data_conf(oph->msg, le);
diff --git a/tests/lapd/lapd_test.c b/tests/lapd/lapd_test.c
index 739f9b7..2f2a7f4 100644
--- a/tests/lapd/lapd_test.c
+++ b/tests/lapd/lapd_test.c
@@ -184,6 +184,7 @@
 	/* LAPDm requires those... */
 	pp.u.data.chan_nr = 0;
 	pp.u.data.link_id = 0;
+	pp.u.data.fn = 0;
         /* feed into the LAPDm code of libosmogsm */
         rc = lapdm_phsap_up(&pp.oph, &chan->lapdm_dcch);
 	OSMO_ASSERT(rc == 0 || rc == -EBUSY);
@@ -206,6 +207,7 @@
 	/* LAPDm requires those... */
 	pp.u.data.chan_nr = 0;
 	pp.u.data.link_id = 0;
+	pp.u.data.fn = 0;
         /* feed into the LAPDm code of libosmogsm */
         rc = lapdm_phsap_up(&pp.oph, &chan->lapdm_dcch);
 	OSMO_ASSERT(rc == 0 || rc == -EBUSY);