[PATCH 6/7] sysmobts: Clean up transitions for lchan cipher state

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/OpenBSC@lists.osmocom.org/.

Andreas Eversberg jolly at eversberg.eu
Mon Jul 15 08:35:35 UTC 2013


There are three transitions:

1. LCHAN_CIPH_NONE -> LCHAN_CIPH_RX_REQ -> LCHAN_CIPH_RX_CONF

It is used to enable ciphering in RX (uplink) direction only.

2. LCHAN_CIPH_RX_CONF -> LCHAN_CIPH_RX_CONF_TX_REQ -> LCHAN_CIPH_RXTX_CONF

It is used to additionally enable ciphering in TX (downlink) direction.

3. LCHAN_CIPH_NONE -> LCHAN_CIPH_RXTX_REQ -> LCHAN_CIPH_RX_CONF_TX_REQ
   -> LCHAN_CIPH_RXTX_CONF

It is used to enable ciphering in both TX and RX directions. This is used
when the channel is activated with encryption already enabled. (assignment
or handover)

In order to follow the order of these transitions, the RX direction must
always be set before the TX direction.

If no cipher key is set (A5/0), ciphering is set to ALG 0, but lchan cipher
state remains at LCHAN_CIPH_NONE.
---
 include/osmo-bts/gsm_data.h |  5 +++--
 src/common/l1sap.c          |  1 -
 src/common/rsl.c            |  1 -
 src/osmo-bts-sysmo/l1_if.c  |  9 ++++++---
 src/osmo-bts-sysmo/oml.c    | 19 +++++++++++++++----
 5 files changed, 24 insertions(+), 11 deletions(-)

diff --git a/include/osmo-bts/gsm_data.h b/include/osmo-bts/gsm_data.h
index 980f8ef..3949292 100644
--- a/include/osmo-bts/gsm_data.h
+++ b/include/osmo-bts/gsm_data.h
@@ -69,8 +69,9 @@ enum lchan_ciph_state {
 	LCHAN_CIPH_NONE,
 	LCHAN_CIPH_RX_REQ,
 	LCHAN_CIPH_RX_CONF,
-	LCHAN_CIPH_TXRX_REQ,
-	LCHAN_CIPH_TXRX_CONF,
+	LCHAN_CIPH_RXTX_REQ,
+	LCHAN_CIPH_RX_CONF_TX_REQ,
+	LCHAN_CIPH_RXTX_CONF,
 };
 
 #define bts_role_bts(x)	((struct gsm_bts_role_bts *)(x)->role)
diff --git a/src/common/l1sap.c b/src/common/l1sap.c
index ad833ea..b6621e0 100644
--- a/src/common/l1sap.c
+++ b/src/common/l1sap.c
@@ -94,7 +94,6 @@ static int check_for_ciph_cmd(struct msgb *msg, struct gsm_lchan *lchan,
 	/* only do this if we are in the right state */
 	switch (lchan->ciph_state) {
 	case LCHAN_CIPH_NONE:
-	case LCHAN_CIPH_RX_REQ:
 		break;
 	default:
 		return 0;
diff --git a/src/common/rsl.c b/src/common/rsl.c
index 128990d..91e5099 100644
--- a/src/common/rsl.c
+++ b/src/common/rsl.c
@@ -890,7 +890,6 @@ static int rsl_rx_encr_cmd(struct msgb *msg)
 	/* push a fake RLL DATA REQ header */
 	rsl_rll_push_l3(msg, RSL_MT_DATA_REQ, dch->chan_nr, link_id, 1);
 
-
 #ifdef FAKE_CIPH_MODE_COMPL
 	if (lchan->encr.alg_id != RSL_ENC_ALG_A5(0)) {
 		struct ciph_mod_compl *cmc;
diff --git a/src/osmo-bts-sysmo/l1_if.c b/src/osmo-bts-sysmo/l1_if.c
index f2e4440..b262b28 100644
--- a/src/osmo-bts-sysmo/l1_if.c
+++ b/src/osmo-bts-sysmo/l1_if.c
@@ -442,14 +442,17 @@ int bts_model_l1sap_down(struct gsm_bts_trx *trx, struct osmo_phsap_prim *l1sap)
 			u8Tn = L1SAP_CHAN2TS(chan_nr);
 			ss = l1sap_chan2ss(chan_nr);
 			lchan = &trx->ts[u8Tn].lchan[ss];
-			if (l1sap->u.info.u.ciph_req.downlink) {
+			if (l1sap->u.info.u.ciph_req.uplink) {
 				l1if_set_ciphering(fl1, lchan, 1);
 				lchan->ciph_state = LCHAN_CIPH_RX_REQ;
 			}
-			if (l1sap->u.info.u.ciph_req.uplink) {
+			if (l1sap->u.info.u.ciph_req.downlink) {
 				l1if_set_ciphering(fl1, lchan, 0);
-				lchan->ciph_state = LCHAN_CIPH_TXRX_REQ;
+				lchan->ciph_state = LCHAN_CIPH_RX_CONF_TX_REQ;
 			}
+			if (l1sap->u.info.u.ciph_req.downlink
+			 && l1sap->u.info.u.ciph_req.uplink)
+				lchan->ciph_state = LCHAN_CIPH_RXTX_REQ;
 			break;
 		case PRIM_INFO_ACTIVATE:
 		case PRIM_INFO_DEACTIVATE:
diff --git a/src/osmo-bts-sysmo/oml.c b/src/osmo-bts-sysmo/oml.c
index 399576e..c16f7c5 100644
--- a/src/osmo-bts-sysmo/oml.c
+++ b/src/osmo-bts-sysmo/oml.c
@@ -888,8 +888,12 @@ static int sapi_activate_cb(struct gsm_lchan *lchan, int status)
 	mph_info_chan_confirm(lchan, PRIM_INFO_ACTIVATE, 0);
 
 	/* set the initial ciphering parameters for both directions */
-	l1if_set_ciphering(fl1h, lchan, 0);
 	l1if_set_ciphering(fl1h, lchan, 1);
+	l1if_set_ciphering(fl1h, lchan, 0);
+	if (lchan->encr.alg_id)
+		lchan->ciph_state = LCHAN_CIPH_RXTX_REQ;
+	else
+		lchan->ciph_state = LCHAN_CIPH_NONE;
 
 	return 0;
 }
@@ -1028,9 +1032,16 @@ static int chmod_modif_compl_cb(struct gsm_bts_trx *trx, struct msgb *l1_msg)
 			LOGPC(DL1C, LOGL_INFO, "RX_REQ -> RX_CONF\n");
 			lchan->ciph_state = LCHAN_CIPH_RX_CONF;
 			break;
-		case LCHAN_CIPH_TXRX_REQ:
-			LOGPC(DL1C, LOGL_INFO, "TX_REQ -> TX_CONF\n");
-			lchan->ciph_state = LCHAN_CIPH_TXRX_CONF;
+		case LCHAN_CIPH_RX_CONF_TX_REQ:
+			LOGPC(DL1C, LOGL_INFO, "RX_CONF_TX_REQ -> RXTX_CONF\n");
+			lchan->ciph_state = LCHAN_CIPH_RXTX_CONF;
+			break;
+		case LCHAN_CIPH_RXTX_REQ:
+			LOGPC(DL1C, LOGL_INFO, "RXTX_REQ -> RX_CONF_TX_REQ\n");
+			lchan->ciph_state = LCHAN_CIPH_RX_CONF_TX_REQ;
+			break;
+		case LCHAN_CIPH_NONE:
+			LOGPC(DL1C, LOGL_INFO, "\n");
 			break;
 		default:
 			LOGPC(DL1C, LOGL_INFO, "unhandled state %u\n", lchan->ciph_state);
-- 
1.8.1.5





More information about the OpenBSC mailing list