summaryrefslogtreecommitdiffstats
path: root/library/L3_Common.ttcn
blob: 57db6b316d8579e204591866dfbdc74ad164fc26 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
module L3_Common {

import from Osmocom_Types all;
import from General_Types all;
import from MobileL3_GMM_SM_Types all;

type record AuthVector {
	OCT16 rand,
	OCT4 sres,
	OCT8 kc,
	OCT16 ik,
	OCT16 ck,
	OCT16 autn,
	OCT8 res,
	/* auts is usally calculated from autn + rand on the MS.
	 * To simplify the test case, auts is generated instead calculated here.
	 */
	OCT14 auts
}

private function f_rnd_oct(integer len) return octetstring {
	var integer i;
	var octetstring res;
	for (i := 0; i < len; i := i + 1) {
		res[i] := int2oct(float2int(rnd()*256.0), 1);
	}
	return res;
}

function f_gen_auth_vec_2g() return AuthVector {
	var AuthVector vec;
	vec.rand := f_rnd_oct(16);
	vec.sres := f_rnd_oct(4);
	vec.kc := f_rnd_oct(8);
	return vec;
}

function f_gen_auth_vec_3g() return AuthVector {
	var AuthVector vec := f_gen_auth_vec_2g();
	vec.ik := f_rnd_oct(16);
	vec.ck := f_rnd_oct(16);
	vec.autn := f_rnd_oct(16);
	vec.res := f_rnd_oct(8);
	vec.auts := f_rnd_oct(14);
	return vec;
}

/* 3GPP TS 23.003 2.6 */
type enumerated TlliType {
	TLLI_LOCAL,
	TLLI_FOREIGN,
	TLLI_RANDOM,
	TLLI_AUXILIARY,
	TLLI_RESERVED,
	TLLI_G_RNTI,
	TLLI_RAND_G_RNTI
}

/* 3GPP TS 23.003 2.6 */
function f_gprs_tlli_type(OCT4 tlli) return TlliType {
	var bitstring tllib := oct2bit(tlli);
	if (substr(tllib, 0, 2) == '11'B) {
		return TLLI_LOCAL;
	} else if (substr(tllib, 0, 2) == '10'B) {
		return TLLI_FOREIGN;
	} else if (substr(tllib, 0, 5) == '01111'B) {
		return TLLI_RANDOM;
	} else if (substr(tllib, 0, 4) == '0110'B) {
		return TLLI_RESERVED;
	} else if (substr(tllib, 0, 3) == '010'B) {
		return TLLI_RESERVED;
	} else if (substr(tllib, 0, 4) == '0000'B) {
		return TLLI_G_RNTI;
	} else if (substr(tllib, 0, 4) == '0001'B) {
		return TLLI_RAND_G_RNTI;
	} else {
		setverdict(fail, "Unknonw TLLI Type ", tllib);
		mtc.stop;
	}
}

function f_gprs_tlli_random() return OCT4 {
	var OCT4 tlli := f_rnd_octstring(4);
	return tlli or4b 'c0000000'O;
}

function f_RAI(HEX0_3n mcc, HEX0_3n mnc, OCT2 lac, OCT1 rac) return RoutingAreaIdentificationV {
	if (lengthof(mnc) == 2) {
		mnc := mnc & 'F'H;
	}
	var RoutingAreaIdentificationV ret := {
		mccDigit1 := mcc[0],
		mccDigit2 := mcc[1],
		mccDigit3 := mcc[2],
		mncDigit3 := mnc[2],
		mncDigit1 := mnc[0],
		mncDigit2 := mnc[1],
		lac := lac,
		rac := rac
	}
	return ret;
}

function f_RAI_to_plmn_hexstr(RoutingAreaIdentificationV rai) return hexstring {
	var hexstring plmn :=
		  rai.mccDigit1
		& rai.mccDigit2
		& rai.mccDigit3
		& rai.mncDigit1
		& rai.mncDigit2
		& rai.mncDigit3;
	return plmn;
}

}