Hi Holger,

On Thu, Aug 28, 2014 at 02:01:30PM +0200, Holger Hans Peter Freyther wrote:
> > -   lchan->ciph_state = LCHAN_CIPH_TXRX_REQ;
>
> this looks to belong to a different patch?!

Indeed, I accidentially squashed two wrong commits.  I've fixed it.  The
two affected patcheas are patch 26 and 27 of the series, new commits
are:
69eba91fdc97f042f72049a754f0162c9c289f45 and
0fa6dc976b41757c95c587989185b5bb55d17fdf

attached for your reference (rather than spamming the list with the
entire series again).
-- 
- Harald Welte <[email protected]>           http://laforge.gnumonks.org/
============================================================================
"Privacy in residential applications is a desirable marketing option."
                                                  (ETSI EN 300 175-7 Ch. A6)
>From 69eba91fdc97f042f72049a754f0162c9c289f45 Mon Sep 17 00:00:00 2001
From: Harald Welte <[email protected]>
Date: Wed, 27 Aug 2014 22:13:18 +0200
Subject: [PATCH 1/8] l1sap: Port code to new ciphering handling

... introduced in 2cc37035d73191b71b9ba9c0d559a0da6a5f35e5
---
 include/osmo-bts/l1sap.h       |  2 ++
 src/common/l1sap.c             | 45 ++++++++++++++++++++++++++++++++----------
 src/osmo-bts-sysmo/l1_if.c     | 32 ------------------------------
 src/osmo-bts-sysmo/l1_if.h     |  3 ---
 tests/sysmobts/sysmobts_test.c | 10 +++++++---
 5 files changed, 44 insertions(+), 48 deletions(-)

diff --git a/include/osmo-bts/l1sap.h b/include/osmo-bts/l1sap.h
index dee430f..e76aca6 100644
--- a/include/osmo-bts/l1sap.h
+++ b/include/osmo-bts/l1sap.h
@@ -68,4 +68,6 @@ extern uint8_t gsmtap_sapi_acch;
 
 #define msgb_l1sap_prim(msg) ((struct osmo_phsap_prim *)(msg)->l1h)
 
+int bts_check_for_first_ciphrd(struct gsm_lchan *lchan,
+				uint8_t *data, int len);
 #endif /* L1SAP_H */
diff --git a/src/common/l1sap.c b/src/common/l1sap.c
index 14dbde9..9c7a9c6 100644
--- a/src/common/l1sap.c
+++ b/src/common/l1sap.c
@@ -481,6 +481,39 @@ static void radio_link_timeout(struct gsm_lchan *lchan, int bad_frame)
 	}
 }
 
+static inline int check_for_first_ciphrd(struct gsm_lchan *lchan,
+					  uint8_t *data, int len)
+{
+	uint8_t n_s;
+
+	/* if this is the first valid message after enabling Rx
+	 * decryption, we have to enable Tx encryption */
+	if (lchan->ciph_state != LCHAN_CIPH_RX_CONF)
+		return 0;
+
+	/* HACK: check if it's an I frame, in order to
+	 * ignore some still buffered/queued UI frames received
+	 * before decryption was enabled */
+	if (data[0] != 0x01)
+		return 0;
+
+	if ((data[1] & 0x01) != 0)
+		return 0;
+
+	n_s = data[1] >> 5;
+	if (lchan->ciph_ns != n_s)
+		return 0;
+
+	return 1;
+}
+
+/* public helper for the test */
+int bts_check_for_first_ciphrd(struct gsm_lchan *lchan,
+				uint8_t *data, int len)
+{
+	return check_for_first_ciphrd(lchan, data, len);
+}
+
 /* DATA received from bts model */
 static int l1sap_ph_data_ind(struct gsm_bts_trx *trx,
 	 struct osmo_phsap_prim *l1sap, struct ph_data_param *data_ind)
@@ -557,16 +590,8 @@ static int l1sap_ph_data_ind(struct gsm_bts_trx *trx,
 	} else
 		le = &lchan->lapdm_ch.lapdm_dcch;
 
-	/* if this is the first valid message after enabling Rx
-	 * decryption, we have to enable Tx encryption */
-	if (lchan->ciph_state == LCHAN_CIPH_RX_CONF) {
-		/* HACK: check if it's an I frame, in order to
-		 * ignore some still buffered/queued UI frames received
-		 * before decryption was enabled */
-		if (data[0] == 0x01 && (data[1] & 0x01) == 0) {
-			l1sap_tx_ciph_req(trx, chan_nr, 1, 0);
-		}
-	}
+	if (check_for_first_ciphrd(lchan, data, len))
+		l1sap_tx_ciph_req(lchan->ts->trx, chan_nr, 1, 0);
 
 	/* SDCCH, SACCH and FACCH all go to LAPDm */
 	msgb_pull(msg, (msg->l2h - msg->data));
diff --git a/src/osmo-bts-sysmo/l1_if.c b/src/osmo-bts-sysmo/l1_if.c
index b62a2a3..14efc2c 100644
--- a/src/osmo-bts-sysmo/l1_if.c
+++ b/src/osmo-bts-sysmo/l1_if.c
@@ -356,31 +356,6 @@ static int check_for_ciph_cmd(struct femtol1_hdl *fl1h,
 	return 1;
 }
 
-static inline void check_for_first_ciphrd(struct femtol1_hdl *fl1h,
-					GsmL1_MsgUnitParam_t *msgUnitParam,
-					struct gsm_lchan *lchan)
-{
-	uint8_t n_s;
-
-	/* if this is the first valid message after enabling Rx
-	 * decryption, we have to enable Tx encryption */
-	if (lchan->ciph_state != LCHAN_CIPH_RX_CONF)
-		return;
-
-	/* HACK: check if it's an I frame, in order to
-	 * ignore some still buffered/queued UI frames received
-	 * before decryption was enabled */
-	if (msgUnitParam->u8Buffer[0] != 0x01)
-		return;
-	if ((msgUnitParam->u8Buffer[1] & 0x01) != 0)
-		return;
-	n_s = msgUnitParam->u8Buffer[1] >> 5;
-	if (lchan->ciph_ns != n_s)
-		return;
-	lchan->ciph_state = LCHAN_CIPH_TXRX_REQ;
-	l1if_set_ciphering(fl1h, lchan, 1);
-}
-
 /* public helpers for the test */
 int bts_check_for_ciph_cmd(struct femtol1_hdl *fl1h,
 			      struct msgb *msg, struct gsm_lchan *lchan)
@@ -388,13 +363,6 @@ int bts_check_for_ciph_cmd(struct femtol1_hdl *fl1h,
 	return check_for_ciph_cmd(fl1h, msg, lchan);
 }
 
-void bts_check_for_first_ciphrd(struct femtol1_hdl *fl1h,
-				GsmL1_MsgUnitParam_t *msgUnitParam,
-				struct gsm_lchan *lchan)
-{
-	return check_for_first_ciphrd(fl1h, msgUnitParam, lchan);
-}
-
 static const uint8_t fill_frame[GSM_MACBLOCK_LEN] = {
 	0x03, 0x03, 0x01, 0x2B, 0x2B, 0x2B, 0x2B, 0x2B, 0x2B, 0x2B,
 	0x2B, 0x2B, 0x2B, 0x2B, 0x2B, 0x2B, 0x2B, 0x2B, 0x2B, 0x2B,
diff --git a/src/osmo-bts-sysmo/l1_if.h b/src/osmo-bts-sysmo/l1_if.h
index 6f58e95..a425776 100644
--- a/src/osmo-bts-sysmo/l1_if.h
+++ b/src/osmo-bts-sysmo/l1_if.h
@@ -138,7 +138,4 @@ int l1if_rf_clock_info_correct(struct femtol1_hdl *fl1h);
 /* public helpers for test */
 int bts_check_for_ciph_cmd(struct femtol1_hdl *fl1h,
 			      struct msgb *msg, struct gsm_lchan *lchan);
-void bts_check_for_first_ciphrd(struct femtol1_hdl *fl1h,
-				GsmL1_MsgUnitParam_t *msgUnitParam,
-				struct gsm_lchan *lchan);
 #endif /* _FEMTO_L1_H */
diff --git a/tests/sysmobts/sysmobts_test.c b/tests/sysmobts/sysmobts_test.c
index acbc09c..3ed78fd 100644
--- a/tests/sysmobts/sysmobts_test.c
+++ b/tests/sysmobts/sysmobts_test.c
@@ -18,6 +18,7 @@
  */
 
 #include <osmo-bts/bts.h>
+#include <osmo-bts/l1sap.h>
 
 #include "femtobts.h"
 #include "l1_if.h"
@@ -169,14 +170,17 @@ static void test_sysmobts_cipher(void)
 	/* Handle message sent before ciphering was received */
 	memcpy(&unit.u8Buffer[0], too_early_classmark, ARRAY_SIZE(too_early_classmark));
 	unit.u8Size = ARRAY_SIZE(too_early_classmark);
-	bts_check_for_first_ciphrd(&fl1h, &unit, &lchan);
+	rc = bts_check_for_first_ciphrd(&lchan, unit.u8Buffer, unit.u8Size);
+	OSMO_ASSERT(rc == 0);
 	OSMO_ASSERT(lchan.ciph_state == LCHAN_CIPH_RX_CONF);
 
 	/* Now send the first ciphered message */
 	memcpy(&unit.u8Buffer[0], first_ciphered_cipher_cmpl, ARRAY_SIZE(first_ciphered_cipher_cmpl));
 	unit.u8Size = ARRAY_SIZE(first_ciphered_cipher_cmpl);
-	bts_check_for_first_ciphrd(&fl1h, &unit, &lchan);
-	OSMO_ASSERT(lchan.ciph_state == LCHAN_CIPH_TXRX_REQ);
+	rc = bts_check_for_first_ciphrd(&lchan, unit.u8Buffer, unit.u8Size);
+	OSMO_ASSERT(rc == 1);
+	/* we cannot test for lchan.ciph_state == * LCHAN_CIPH_RX_CONF_TX_REQ, as
+	 * this happens asynchronously on the other side of the l1sap queue */
 }
 
 int main(int argc, char **argv)
-- 
2.1.0

>From 0fa6dc976b41757c95c587989185b5bb55d17fdf Mon Sep 17 00:00:00 2001
From: Andreas Eversberg <[email protected]>
Date: Sat, 31 Aug 2013 20:30:40 +0200
Subject: [PATCH 2/8] Add MEAS (MPH_INFO) IND message to PH-/MPH-/TCH-SAP
 interface

This part moves processing of measurement infos from osmo-bts-sysmo to
common part.
---
 src/common/l1sap.c         | 32 ++++++++++++++++++++++++++++++++
 src/osmo-bts-sysmo/l1_if.c | 26 +++++++++++++-------------
 2 files changed, 45 insertions(+), 13 deletions(-)

diff --git a/src/common/l1sap.c b/src/common/l1sap.c
index 9c7a9c6..c1e9f9f 100644
--- a/src/common/l1sap.c
+++ b/src/common/l1sap.c
@@ -155,6 +155,35 @@ static int l1sap_info_time_ind(struct gsm_bts_trx *trx,
 	return 0;
 }
 
+/* measurement information received from bts model */
+static int l1sap_info_meas_ind(struct gsm_bts_trx *trx,
+	struct osmo_phsap_prim *l1sap,
+	struct info_meas_ind_param *info_meas_ind)
+{
+	struct bts_ul_meas ulm;
+	struct gsm_lchan *lchan;
+
+	DEBUGP(DL1P, "MPH_INFO meas ind chan_nr=%02x\n",
+		info_meas_ind->chan_nr);
+
+	lchan = &trx->ts[L1SAP_CHAN2TS(info_meas_ind->chan_nr)]
+				.lchan[l1sap_chan2ss(info_meas_ind->chan_nr)];
+
+	/* in the GPRS case we are not interested in measurement
+	 * processing.  The PCU will take care of it */
+	if (lchan->type == GSM_LCHAN_PDTCH)
+		return 0;
+
+	memset(&ulm, 0, sizeof(ulm));
+	ulm.ta_offs_qbits = info_meas_ind->ta_offs_qbits;
+	ulm.ber10k = info_meas_ind->ber10k;
+	ulm.inv_rssi = info_meas_ind->inv_rssi;
+
+	lchan_new_ul_meas(lchan, &ulm);
+
+	return 0;
+}
+
 /* any L1 MPH_INFO indication prim recevied from bts model */
 static int l1sap_mph_info_ind(struct gsm_bts_trx *trx,
 	 struct osmo_phsap_prim *l1sap, struct mph_info_param *info)
@@ -165,6 +194,9 @@ static int l1sap_mph_info_ind(struct gsm_bts_trx *trx,
 	case PRIM_INFO_TIME:
 		rc = l1sap_info_time_ind(trx, l1sap, &info->u.time_ind);
 		break;
+	case PRIM_INFO_MEAS:
+		rc = l1sap_info_meas_ind(trx, l1sap, &info->u.meas_ind);
+		break;
 	default:
 		LOGP(DL1P, LOGL_NOTICE, "unknown MPH_INFO ind type %d\n",
 			info->type);
diff --git a/src/osmo-bts-sysmo/l1_if.c b/src/osmo-bts-sysmo/l1_if.c
index 14efc2c..38daa97 100644
--- a/src/osmo-bts-sysmo/l1_if.c
+++ b/src/osmo-bts-sysmo/l1_if.c
@@ -891,20 +891,20 @@ static void dump_meas_res(int ll, GsmL1_MeasParam_t *m)
 		m->fBer, m->i16BurstTiming);
 }
 
-static int process_meas_res(struct gsm_lchan *lchan, GsmL1_MeasParam_t *m)
+static int process_meas_res(struct gsm_bts_trx *trx, uint8_t chan_nr,
+				GsmL1_MeasParam_t *m)
 {
-	struct bts_ul_meas ulm;
-
-	/* in the GPRS case we are not interested in measurement
-	 * processing.  The PCU will take care of it */
-	if (lchan->type == GSM_LCHAN_PDTCH)
-		return 0;
-
-	ulm.ta_offs_qbits = m->i16BurstTiming;
-	ulm.ber10k = (unsigned int) (m->fBer * 100);
-	ulm.inv_rssi = (uint8_t) (m->fRssi * -1);
+	struct osmo_phsap_prim l1sap;
+	memset(&l1sap, 0, sizeof(l1sap));
+	osmo_prim_init(&l1sap.oph, SAP_GSM_PH, PRIM_MPH_INFO,
+		PRIM_OP_INDICATION, NULL);
+	l1sap.u.info.type = PRIM_INFO_MEAS;
+	l1sap.u.info.u.meas_ind.chan_nr = chan_nr;
+	l1sap.u.info.u.meas_ind.ta_offs_qbits = m->i16BurstTiming;
+	l1sap.u.info.u.meas_ind.ber10k = (unsigned int) (m->fBer * 100);
+	l1sap.u.info.u.meas_ind.inv_rssi = (uint8_t) (m->fRssi * -1);
 
-	return lchan_new_ul_meas(lchan, &ulm);
+	return l1sap_up(trx, &l1sap);
 }
 
 static int handle_ph_data_ind(struct femtol1_hdl *fl1, GsmL1_PhDataInd_t *data_ind,
@@ -940,7 +940,7 @@ static int handle_ph_data_ind(struct femtol1_hdl *fl1, GsmL1_PhDataInd_t *data_i
 	fn = data_ind->u32Fn;
 	link_id =  (data_ind->sapi == GsmL1_Sapi_Sacch) ? 0x40 : 0x00;
 
-	process_meas_res(lchan, &data_ind->measParam);
+	process_meas_res(trx, chan_nr, &data_ind->measParam);
 
 	if (data_ind->measParam.fLinkQuality < fl1->min_qual_norm
 	 && data_ind->msgUnitParam.u8Size != 0) {
-- 
2.1.0

Reply via email to