[28/33] sysmobts: Clean up transitions for lchan cipher state
diff mbox

Message ID 1409176492-13269-29-git-send-email-laforge@gnumonks.org
State Superseded
Headers show

Commit Message

Harald Welte Aug. 27, 2014, 9:54 p.m. UTC
From: Andreas Eversberg <jolly@eversberg.eu>

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/osmo-bts-sysmo/l1_if.c  |  5 ++++-
 src/osmo-bts-sysmo/oml.c    | 19 +++++++++++++++----
 4 files changed, 22 insertions(+), 8 deletions(-)

Patch
diff mbox

diff --git a/include/osmo-bts/gsm_data.h b/include/osmo-bts/gsm_data.h
index c6866a3..bd726e2 100644
--- a/include/osmo-bts/gsm_data.h
+++ b/include/osmo-bts/gsm_data.h
@@ -91,8 +91,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 f00c5d2..3f099b0 100644
--- a/src/common/l1sap.c
+++ b/src/common/l1sap.c
@@ -96,7 +96,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/osmo-bts-sysmo/l1_if.c b/src/osmo-bts-sysmo/l1_if.c
index 38daa97..b4ae300 100644
--- a/src/osmo-bts-sysmo/l1_if.c
+++ b/src/osmo-bts-sysmo/l1_if.c
@@ -606,8 +606,11 @@  static int mph_info_req(struct gsm_bts_trx *trx, struct msgb *msg,
 		}
 		if (l1sap->u.info.u.ciph_req.downlink) {
 			l1if_set_ciphering(fl1, lchan, 1);
-			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 f490195..dc8a625 100644
--- a/src/osmo-bts-sysmo/oml.c
+++ b/src/osmo-bts-sysmo/oml.c
@@ -980,8 +980,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;
 }
@@ -1130,9 +1134,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);