fixeria has uploaded this change for review. (
https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/26404 )
Change subject: msc/BSC_ConnectionHandler: refactor and split f_mm_common()
......................................................................
msc/BSC_ConnectionHandler: refactor and split f_mm_common()
Reduce nesting and improve readability by splitting GERAN/UTRAN
specific CMC/SMC message handling into separate functions.
Change-Id: Ib7ebe8fd675295beb02cadebb19d8465dffeb732
Related: OS#5333
---
M msc/BSC_ConnectionHandler.ttcn
1 file changed, 69 insertions(+), 57 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-ttcn3-hacks
refs/changes/04/26404/1
diff --git a/msc/BSC_ConnectionHandler.ttcn b/msc/BSC_ConnectionHandler.ttcn
index 2f270ca..873ec5b 100644
--- a/msc/BSC_ConnectionHandler.ttcn
+++ b/msc/BSC_ConnectionHandler.ttcn
@@ -611,68 +611,80 @@
}
+private function f_mm_ciph_geran() runs on BSC_ConnHdlr
+{
+ var template BSSMAP_IE_EncryptionInformation encryptionInformation;
+ var template BSSMAP_IE_ChosenEncryptionAlgorithm
chosenEncryptionAlgorithm;
+ var template BSSMAP_IE_KC128 kC128;
+ var OCT1 a5_perm_alg;
+ var PDU_BSSAP pdu;
+
+ if (g_pars.net.expect_ciph) {
+ /* There is nothing to do */
+ return;
+ }
+
+ f_get_expected_encryption(encryptionInformation,
chosenEncryptionAlgorithm, kC128, a5_perm_alg);
+ alt {
+ [] BSSAP.receive(tr_BSSMAP_CipherModeCmd2(encryptionInformation,
kC128)) -> value pdu {
+ var OCT1 a5_chosen := f_best_alg_from_mask(a5_perm_alg);
+ var integer a5_nr := f_alg_from_mask(a5_chosen);
+ BSSAP.send(ts_BSSMAP_CipherModeCompl(int2oct(a5_nr+1, 1)));
+ }
+ [] BSSAP.receive(tr_BSSMAP_CipherModeCmd2) -> value pdu {
+ log("Error: Ciphering Mode Command with unexpected content.
Expected: ",
+ tr_BSSMAP_CipherModeCmd2(encryptionInformation, kC128), "
got: ", pdu);
+ setverdict(fail, "Ciphering Mode Command with unexpected
content.");
+ mtc.stop;
+ }
+ [] BSSAP.receive(tr_BSSMAP_ClassmarkRequest) {
+ BSSAP.send(ts_BSSMAP_ClassmarkUpd(g_pars.cm2, g_pars.cm3))
+ repeat;
+ }
+ }
+ /* FIXME: Send the best available algorithm */
+}
+
+private function f_mm_ciph_utran() runs on BSC_ConnHdlr
+{
+ alt {
+ [g_pars.net.expect_ciph]
BSSAP.receive(tr_RANAP_SecurityModeCmdEnc(uia_algs := ?,
+
uia_key := oct2bit(g_pars.vec.ik),
+
key_sts := ?,
+
uea_algs := ?,
+
uea_key := oct2bit(g_pars.vec.ck))) {
+ var IntegrityProtectionAlgorithm uia_chosen := 0;
/*standard_UMTS_integrity_algorithm_UIA1*/
+ var EncryptionAlgorithm uea_chosen := 1;
/*standard_UMTS_encryption_algorith_UEA1*/
+ BSSAP.send(ts_RANAP_SecurityModeCompleteEnc(uia_chosen,
uea_chosen));
+ }
+ [g_pars.net.expect_ciph]
BSSAP.receive(tr_RANAP_SecurityModeCmdEnc(?,?,?,?,?)) {
+ setverdict(fail, "Invalid SecurityModeCommand (ciphering
case)");
+ mtc.stop;
+ }
+ [not g_pars.net.expect_ciph]
BSSAP.receive(tr_RANAP_SecurityModeCmd(uia_algs := ?,
+
uia_key := oct2bit(g_pars.vec.ik),
+
key_sts := ?)) {
+ var IntegrityProtectionAlgorithm uia_chosen := 0;
/*standard_UMTS_integrity_algorithm_UIA1;*/
+ BSSAP.send(ts_RANAP_SecurityModeComplete(uia_chosen));
+ }
+ [not g_pars.net.expect_ciph]
BSSAP.receive(tr_RANAP_SecurityModeCmd(?,?,?)) {
+ setverdict(fail, "Invalid SecurityModeCommand (non-ciphering
case)");
+ mtc.stop;
+ }
+ }
+}
+
function f_mm_common() runs on BSC_ConnHdlr
{
f_mm_auth();
- if (g_pars.ran_is_geran) {
- if (g_pars.net.expect_ciph) {
- var template BSSMAP_IE_EncryptionInformation
encryptionInformation;
- var template BSSMAP_IE_ChosenEncryptionAlgorithm
chosenEncryptionAlgorithm;
- var template BSSMAP_IE_KC128 kC128;
- var OCT1 a5_perm_alg;
- f_get_expected_encryption(encryptionInformation,
chosenEncryptionAlgorithm, kC128, a5_perm_alg);
- var PDU_BSSAP pdu;
- var template PDU_BSSAP expect_ciph_mode_cmd :=
tr_BSSMAP_CipherModeCmd2(encryptionInformation, kC128);
- alt {
- [] BSSAP.receive(expect_ciph_mode_cmd) -> value pdu {
- var OCT1 a5_chosen :=
f_best_alg_from_mask(a5_perm_alg);
- var integer a5_nr := f_alg_from_mask(a5_chosen);
-
BSSAP.send(ts_BSSMAP_CipherModeCompl(int2oct(a5_nr+1, 1)));
- }
- [] BSSAP.receive(tr_BSSMAP_CipherModeCmd2) -> value pdu
{
- log("Error: Ciphering Mode Command with
unexpected content. Expected: ",
- expect_ciph_mode_cmd, " got: ", pdu);
- setverdict(fail, "Ciphering Mode Command with
unexpected content.");
- mtc.stop;
- }
- [] BSSAP.receive(tr_BSSMAP_ClassmarkRequest) {
- BSSAP.send(ts_BSSMAP_ClassmarkUpd(g_pars.cm2,
g_pars.cm3))
- repeat;
- }
- }
- /* FIXME: Send the best available algorithm */
- }
- f_expect_common_id();
- } else { /* UTRAN */
- alt {
- [g_pars.net.expect_ciph]
BSSAP.receive(tr_RANAP_SecurityModeCmdEnc(uia_algs := ?,
-
uia_key := oct2bit(g_pars.vec.ik),
-
key_sts := ?,
-
uea_algs := ?,
-
uea_key := oct2bit(g_pars.vec.ck))) {
- var IntegrityProtectionAlgorithm uia_chosen := 0;
/*standard_UMTS_integrity_algorithm_UIA1*/
- var EncryptionAlgorithm uea_chosen := 1;
/*standard_UMTS_encryption_algorith_UEA1*/
- BSSAP.send(ts_RANAP_SecurityModeCompleteEnc(uia_chosen,
uea_chosen));
- f_expect_common_id();
- }
- [g_pars.net.expect_ciph]
BSSAP.receive(tr_RANAP_SecurityModeCmdEnc(?,?,?,?,?)) {
- setverdict(fail, "Invalid SecurityModeCommand
(ciphering case)");
- mtc.stop;
- }
- [not g_pars.net.expect_ciph]
BSSAP.receive(tr_RANAP_SecurityModeCmd(uia_algs := ?,
-
uia_key := oct2bit(g_pars.vec.ik),
-
key_sts := ?)) {
- var IntegrityProtectionAlgorithm uia_chosen := 0;
/*standard_UMTS_integrity_algorithm_UIA1;*/
- BSSAP.send(ts_RANAP_SecurityModeComplete(uia_chosen));
- f_expect_common_id();
- }
- [not g_pars.net.expect_ciph]
BSSAP.receive(tr_RANAP_SecurityModeCmd(?,?,?)) {
- setverdict(fail, "Invalid SecurityModeCommand
(non-ciphering case)");
- mtc.stop;
- }
- }
+ if (g_pars.ran_is_geran) {
+ f_mm_ciph_geran();
+ } else {
+ f_mm_ciph_utran();
}
+
+ f_expect_common_id();
}
function f_expect_mm_info() runs on BSC_ConnHdlr {
--
To view, visit https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/26404
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-ttcn3-hacks
Gerrit-Branch: master
Gerrit-Change-Id: Ib7ebe8fd675295beb02cadebb19d8465dffeb732
Gerrit-Change-Number: 26404
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <[email protected]>
Gerrit-MessageType: newchange