library/GSM_Types: add {enc,dec}_BcdMccMnc() functions

Change-Id: Id501ea146eb596085c204a51387f1b92300d1285
Related: SYS#5602, OS#5901
This commit is contained in:
Vadim Yanitskiy 2023-02-10 07:33:57 +07:00
parent 8cc1f72289
commit 08c90219db
1 changed files with 11 additions and 0 deletions

View File

@ -435,6 +435,13 @@ function f_gsm_compute_tc(integer fn) return integer {
type hexstring GsmBcdString with { variant "HEXORDER(low)" };
type GsmBcdString BcdMccMnc with { variant "FIELDLENGTH(6)" };
/* hex2oct()/oct2hex() do not respect the HEXORDER/FIELDLENGTH attributes,
* so better use the functions, employing TITAN's RAW codec, dclared below. */
external function enc_BcdMccMnc(in BcdMccMnc str) return octetstring
with { extension "prototype(convert) encode(RAW)" };
external function dec_BcdMccMnc(in octetstring str) return BcdMccMnc
with { extension "prototype(convert) decode(RAW)" };
/* Compute BcdMccMnc from a pair of GsmMcc/GsmMnc values */
function f_build_BcdMccMnc(GsmMcc mcc, GsmMnc mnc) return BcdMccMnc {
if (lengthof(mnc) == 2) {
@ -468,6 +475,10 @@ testcase TC_selftest_BcdMccMnc() runs on Dummy_CT {
if (not match('21F354'O, decmatch BcdMccMnc:'123F45'H)) { setverdict(fail); }
if (not match('216354'O, decmatch BcdMccMnc:'123645'H)) { setverdict(fail); }
if (not match(enc_BcdMccMnc('262F42'H), '62F224'O)) { setverdict(fail); }
if (not match(enc_BcdMccMnc('123F45'H), '21F354'O)) { setverdict(fail); }
if (not match(enc_BcdMccMnc('123645'H), '216354'O)) { setverdict(fail); }
if (not match(f_build_BcdMccMnc('262'H, '42'H), BcdMccMnc:'262F42'H)) { setverdict(fail); }
if (not match(f_build_BcdMccMnc('123'H, '45'H), BcdMccMnc:'123F45'H)) { setverdict(fail); }
if (not match(f_build_BcdMccMnc('123'H, '456'H), BcdMccMnc:'123645'H)) { setverdict(fail); }