blob: 0fb17021590a1f8c7cba37f186d598aeb5bb01ed [file] [log] [blame]
Harald Weltea49e36e2018-01-21 19:29:33 +01001module BSC_ConnectionHandler {
2
3import from General_Types all;
4import from Osmocom_Types all;
5import from GSM_Types all;
6import from SCCPasp_Types all;
7import from BSSAP_Types all;
8import from BSSMAP_Emulation all;
9import from BSSMAP_Templates all;
10
11import from GSUP_Types all;
12import from GSUP_Emulation all;
13
14import from MNCC_Types all;
15import from MNCC_Emulation all;
16
17import from MobileL3_Types all;
18import from MobileL3_CommonIE_Types all;
19import from MobileL3_MM_Types all;
20import from L3_Templates all;
21
22/* this component represents a single subscriber connection */
23type component BSC_ConnHdlr extends BSSAP_ConnHdlr, MNCC_ConnHdlr, GSUP_ConnHdlr {
24 var BSC_ConnHdlrPars g_pars;
25}
26
27type record BSC_ConnHdlrPars {
28 SCCP_PAR_Address sccp_addr_own,
29 SCCP_PAR_Address sccp_addr_peer,
30 BSSMAP_IE_CellIdentifier cell_id,
31 hexstring imsi,
Harald Welte82600572018-01-21 20:54:08 +010032 hexstring msisdn,
33 BSSMAP_IE_ClassmarkInformationType2 cm2,
34 BSSMAP_IE_ClassmarkInformationType3 cm3 optional
Harald Weltea49e36e2018-01-21 19:29:33 +010035};
36
37
38/* Callback function from general BSSMAP_Emulation whenever a connectionless
39 * BSSMAP message arrives. Canreturn a PDU_BSSAPthat should be sent in return */
40private function BscUnitdataCallback(PDU_BSSAP bssap)
41runs on BSSMAP_Emulation_CT return template PDU_BSSAP {
42 var template PDU_BSSAP resp := omit;
43
44 log("BSSMAP_BscUnitdataCallback");
45 /* answer all RESET with RESET ACK */
46 if (match(bssap, tr_BSSMAP_Reset)){
47 log("BSSMAP_BscUnitdataCallback: Responding to RESET with RESET-ACK");
48 resp := ts_BSSMAP_ResetAck;
49 }
50
51 /* FIXME: Handle paging, etc. */
52 return resp;
53}
54
55const BssmapOps BSC_BssmapOps := {
56 /* Create call-back for inbound connections from MSC (hand-over) */
57 create_cb := refers(BSSMAP_Emulation.ExpectedCreateCallback),
58 unitdata_cb := refers(BscUnitdataCallback),
59 decode_dtap := true,
60 role_ms := true
61}
62
63
64private function MnccUnitdataCallback(MNCC_PDU mncc)
65runs on MNCC_Emulation_CT return template MNCC_PDU {
66 log("Ignoring MNCC", mncc);
67 return omit;
68}
69
70const MnccOps BCC_MnccOps := {
71 create_cb := refers(MNCC_Emulation.ExpectedCreateCallback),
72 unitdata_cb := refers(MnccUnitdataCallback)
73}
74
75
76
77template BSSAP_Conn_Req ts_BSSAP_Conn_Req(SCCP_PAR_Address peer, SCCP_PAR_Address own, PDU_BSSAP bssap) := {
78 addr_peer := peer,
79 addr_own := own,
80 bssap := bssap
81};
82
83template (value) MobileStationClassmark1_V ts_CM1(BIT1 a5_1_unavail := '0'B, BIT2 rev := '10'B) := {
84 rf_PowerCapability := '010'B,
85 a5_1 := a5_1_unavail,
86 esind := '1'B,
87 revisionLevel := rev,
88 spare1_1 := '0'B
89}
90
91/* Encode 'l3' and ask BSSMAP_Emulation to create new connection with COMPL L3 INFO */
92function f_bssap_compl_l3(PDU_ML3_MS_NW l3)
93runs on BSC_ConnHdlr {
94 log("Sending COMPL L3: ", l3);
95 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3);
96 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_peer, g_pars.sccp_addr_own,
97 valueof(ts_BSSMAP_ComplL3(g_pars.cell_id, l3_enc))));
Harald Welte71b69332018-01-21 20:43:53 +010098 alt {
99 [] BSSAP.receive(BSSAP_Conn_Prim:MSC_CONN_PRIM_CONF_IND) {}
100 [] BSSAP.receive(BSSAP_Conn_Prim:MSC_CONN_PRIM_DISC_IND) {
101 setverdict(fail, "DISC.ind from SCCP");
102 self.stop;
103 }
104 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100105}
106
107/* helper function to fully establish a dedicated channel */
108function f_establish_fully(MobileIdentityLV mi, boolean expect_auth)
109runs on BSC_ConnHdlr {
110 var PDU_ML3_MS_NW l3_info := valueof(ts_CM_SERV_REQ('0001'B, mi));
111 var PDU_DTAP_MT dtap_mt;
112
113 /* Send BSSAP_Conn_Req with COMPL L3 INFO to MSC */
114 f_bssap_compl_l3(l3_info);
115
116 if (expect_auth) {
117 /* FIXME */
118 }
119 BSSAP.receive(tr_PDU_DTAP_MT(tr_CM_SERV_ACC));
120}
121
122/* build a PDU_ML3_MS_NW containing a Location Update by IMSI */
123function f_build_lu_imsi(hexstring imsi) return PDU_ML3_MS_NW
124{
125 var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(imsi));
126 return f_build_lu(mi);
127}
Harald Welteba7b6d92018-01-23 21:32:34 +0100128function f_build_lu_imei(hexstring imei) return PDU_ML3_MS_NW
129{
130 var MobileIdentityLV mi := valueof(ts_MI_IMEI_LV(imei));
131 return f_build_lu(mi);
132}
133function f_build_lu_tmsi(OCT4 tmsi) return PDU_ML3_MS_NW
134{
135 var MobileIdentityLV mi := valueof(ts_MI_TMSI_LV(tmsi));
136 return f_build_lu(mi);
137}
Harald Weltea49e36e2018-01-21 19:29:33 +0100138private function f_build_lu(MobileIdentityLV mi) return PDU_ML3_MS_NW
139{
140 var LocationAreaIdentification_V old_lai := { '62F220'O, '9999'O };
141 var PDU_ML3_MS_NW l3_info := valueof(ts_ML3_MO_LU_Req(valueof(ts_ML3_IE_LuType_Attach),
142 old_lai, mi, valueof(ts_CM1)));
143 return l3_info;
144}
145
Harald Weltecf66d5a2018-01-23 19:24:28 +0100146type record AuthVector {
147 OCT16 rand,
148 OCT4 sres,
149 OCT8 kc
150 /* FIXME: 3G elements */
151}
152
153private function f_rnd_oct(integer len) return octetstring {
154 var integer i;
155 var octetstring res;
156 for (i := 0; i < len; i := i + 1) {
157 res[i] := int2oct(float2int(rnd()*256.0), 1);
158 }
159 return res;
160}
161
162function f_gen_auth_vec_2g() return AuthVector {
163 var AuthVector vec;
164 vec.rand := f_rnd_oct(16);
165 vec.sres := f_rnd_oct(4);
166 vec.kc := f_rnd_oct(8);
167 return vec;
168}
169
Harald Welte8a121b32018-01-22 03:00:41 +0100170function f_perform_lu(boolean expect_auth, boolean expect_tmsi, boolean send_early_cm)
Harald Weltea49e36e2018-01-21 19:29:33 +0100171runs on BSC_ConnHdlr {
172 var PDU_ML3_MS_NW l3_lu := f_build_lu_imsi(g_pars.imsi)
173 var PDU_DTAP_MT dtap_mt;
174
175 /* tell GSUP dispatcher to send this IMSI to us */
176 f_create_gsup_expect(hex2str(g_pars.imsi));
177
178 /* Send BSSAP_Conn_Req with COMPL L3 INFO to MSC */
179 f_bssap_compl_l3(l3_lu);
180
Harald Welte8a121b32018-01-22 03:00:41 +0100181 if (send_early_cm) {
182 BSSAP.send(ts_BSSMAP_ClassmarkUpd(g_pars.cm2, g_pars.cm3));
183 }
Harald Welte5c2622c2018-01-21 20:45:20 +0100184
Harald Weltea49e36e2018-01-21 19:29:33 +0100185 if (expect_auth) {
Harald Weltecf66d5a2018-01-23 19:24:28 +0100186 var AuthVector vec := f_gen_auth_vec_2g();
187 var GSUP_IE auth_tuple := valueof(ts_GSUP_IE_AuthTuple2G(vec.rand, vec.sres, vec.kc));
Harald Welteef9fa872018-01-22 03:00:17 +0100188 GSUP.receive(tr_GSUP_SAI_REQ(g_pars.imsi));
Harald Welte7b1b2812018-01-22 21:23:06 +0100189 GSUP.send(ts_GSUP_SAI_RES(g_pars.imsi, auth_tuple));
190
Harald Weltecf66d5a2018-01-23 19:24:28 +0100191 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_AUTH_REQ(vec.rand)));
192 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MT_MM_AUTH_RESP_2G(vec.sres)));
Harald Weltea49e36e2018-01-21 19:29:33 +0100193 }
194
195 /* Expect MSC to perform LU with HLR */
196 GSUP.receive(tr_GSUP_UL_REQ(g_pars.imsi));
197 GSUP.send(ts_GSUP_ISD_REQ(g_pars.imsi, g_pars.msisdn));
198 GSUP.receive(tr_GSUP_ISD_RES(g_pars.imsi));
199 GSUP.send(ts_GSUP_UL_RES(g_pars.imsi));
200
201 alt {
202 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Acc)) -> value dtap_mt {
203 var PDU_ML3_LocationUpdateAccept lu_acc := dtap_mt.dtap.msgs.mm.locationUpdateAccept;
204 if (expect_tmsi) {
205 if (not ispresent(lu_acc.mobileIdentityTLV) or
206 not ischosen(lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi)) {
207 setverdict(fail, "Expected TMSI but no TMSI was allocated");
208 self.stop;
209 } else {
210 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_TmsiRealloc_Cmpl));
211 }
212 } else {
213 if (ispresent(lu_acc.mobileIdentityTLV) and
214 ischosen(lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi)) {
215 setverdict(fail, "Expected no TMSI but TMSI was allocated");
216 self.stop;
217 }
218 }
219 }
220 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Rej)) {
221 setverdict(fail, "Expected LU ACK, but received LU REJ");
222 self.stop;
223 }
224 }
225 /* FIXME: there could be pending SMS or other common procedures by the MSC, let's ignore them */
226 BSSAP.receive(tr_BSSMAP_ClearCommand);
227 BSSAP.send(ts_BSSMAP_ClearComplete);
228 BSSAP.receive(BSSAP_Conn_Prim:MSC_CONN_PRIM_DISC_IND);
229 setverdict(pass);
230}
231
232function f_foo() runs on BSC_ConnHdlr{
233 /* SCCP CC handled by BSSMAP_Emulation_CT.main() */
234 /* Expect auth, if enabled */
235
236 /* TODO: ISD */
237 /* Expect encr, if enabled */
238 /* Expect encr, if enabled */
239 /* Expect ASS CMD, if chan_type != requested */
240 /* Send ASS CMPL in successful case */
241
242 /* Expect AoIP port/ip information for RTP stream */
243 /* Expect MSC-originated MGCP to our simulated MGW */
244 /* Verify Counters via CTRL */
245 /* re-configure MSC behaviour via VTY */
246}
247
248
249
250
251
252}
253
254