blob: 58b64d3d37a27f0d75c13fc34c2a9579c0717c06 [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
Harald Welte4aa970c2018-01-26 10:38:09 +010017import from MGCP_Types all;
18import from MGCP_Emulation all;
19
Harald Weltea49e36e2018-01-21 19:29:33 +010020import from MobileL3_Types all;
21import from MobileL3_CommonIE_Types all;
22import from MobileL3_MM_Types all;
23import from L3_Templates all;
24
25/* this component represents a single subscriber connection */
Harald Welte4aa970c2018-01-26 10:38:09 +010026type component BSC_ConnHdlr extends BSSAP_ConnHdlr, MNCC_ConnHdlr, GSUP_ConnHdlr, MGCP_ConnHdlr {
Harald Weltea49e36e2018-01-21 19:29:33 +010027 var BSC_ConnHdlrPars g_pars;
28}
29
30type record BSC_ConnHdlrPars {
31 SCCP_PAR_Address sccp_addr_own,
32 SCCP_PAR_Address sccp_addr_peer,
33 BSSMAP_IE_CellIdentifier cell_id,
Harald Welte256571e2018-01-24 18:47:19 +010034 hexstring imei,
Harald Weltea49e36e2018-01-21 19:29:33 +010035 hexstring imsi,
Harald Welte82600572018-01-21 20:54:08 +010036 hexstring msisdn,
Harald Welte256571e2018-01-24 18:47:19 +010037 OCT4 tmsi optional,
Harald Welte82600572018-01-21 20:54:08 +010038 BSSMAP_IE_ClassmarkInformationType2 cm2,
Harald Welte16114282018-01-24 22:41:21 +010039 BSSMAP_IE_ClassmarkInformationType3 cm3 optional,
40 octetstring kc optional
Harald Weltea49e36e2018-01-21 19:29:33 +010041};
42
43
44/* Callback function from general BSSMAP_Emulation whenever a connectionless
45 * BSSMAP message arrives. Canreturn a PDU_BSSAPthat should be sent in return */
46private function BscUnitdataCallback(PDU_BSSAP bssap)
47runs on BSSMAP_Emulation_CT return template PDU_BSSAP {
48 var template PDU_BSSAP resp := omit;
49
50 log("BSSMAP_BscUnitdataCallback");
51 /* answer all RESET with RESET ACK */
52 if (match(bssap, tr_BSSMAP_Reset)){
53 log("BSSMAP_BscUnitdataCallback: Responding to RESET with RESET-ACK");
54 resp := ts_BSSMAP_ResetAck;
55 }
56
57 /* FIXME: Handle paging, etc. */
58 return resp;
59}
60
61const BssmapOps BSC_BssmapOps := {
62 /* Create call-back for inbound connections from MSC (hand-over) */
63 create_cb := refers(BSSMAP_Emulation.ExpectedCreateCallback),
64 unitdata_cb := refers(BscUnitdataCallback),
65 decode_dtap := true,
66 role_ms := true
67}
68
69
70private function MnccUnitdataCallback(MNCC_PDU mncc)
71runs on MNCC_Emulation_CT return template MNCC_PDU {
72 log("Ignoring MNCC", mncc);
73 return omit;
74}
75
76const MnccOps BCC_MnccOps := {
77 create_cb := refers(MNCC_Emulation.ExpectedCreateCallback),
78 unitdata_cb := refers(MnccUnitdataCallback)
79}
80
81
82
83template BSSAP_Conn_Req ts_BSSAP_Conn_Req(SCCP_PAR_Address peer, SCCP_PAR_Address own, PDU_BSSAP bssap) := {
84 addr_peer := peer,
85 addr_own := own,
86 bssap := bssap
87};
88
Harald Weltea49e36e2018-01-21 19:29:33 +010089/* Encode 'l3' and ask BSSMAP_Emulation to create new connection with COMPL L3 INFO */
90function f_bssap_compl_l3(PDU_ML3_MS_NW l3)
91runs on BSC_ConnHdlr {
92 log("Sending COMPL L3: ", l3);
93 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3);
94 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_peer, g_pars.sccp_addr_own,
95 valueof(ts_BSSMAP_ComplL3(g_pars.cell_id, l3_enc))));
Harald Welte71b69332018-01-21 20:43:53 +010096 alt {
97 [] BSSAP.receive(BSSAP_Conn_Prim:MSC_CONN_PRIM_CONF_IND) {}
98 [] BSSAP.receive(BSSAP_Conn_Prim:MSC_CONN_PRIM_DISC_IND) {
99 setverdict(fail, "DISC.ind from SCCP");
100 self.stop;
101 }
102 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100103}
104
105/* helper function to fully establish a dedicated channel */
106function f_establish_fully(MobileIdentityLV mi, boolean expect_auth)
107runs on BSC_ConnHdlr {
Harald Welte6ed6bf92018-01-24 21:09:15 +0100108 var PDU_ML3_MS_NW l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, mi));
Harald Weltea49e36e2018-01-21 19:29:33 +0100109 var PDU_DTAP_MT dtap_mt;
110
111 /* Send BSSAP_Conn_Req with COMPL L3 INFO to MSC */
112 f_bssap_compl_l3(l3_info);
113
114 if (expect_auth) {
115 /* FIXME */
116 }
117 BSSAP.receive(tr_PDU_DTAP_MT(tr_CM_SERV_ACC));
118}
119
120/* build a PDU_ML3_MS_NW containing a Location Update by IMSI */
121function f_build_lu_imsi(hexstring imsi) return PDU_ML3_MS_NW
122{
123 var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(imsi));
124 return f_build_lu(mi);
125}
Harald Welteba7b6d92018-01-23 21:32:34 +0100126function f_build_lu_imei(hexstring imei) return PDU_ML3_MS_NW
127{
128 var MobileIdentityLV mi := valueof(ts_MI_IMEI_LV(imei));
129 return f_build_lu(mi);
130}
131function f_build_lu_tmsi(OCT4 tmsi) return PDU_ML3_MS_NW
132{
133 var MobileIdentityLV mi := valueof(ts_MI_TMSI_LV(tmsi));
134 return f_build_lu(mi);
135}
Harald Weltea49e36e2018-01-21 19:29:33 +0100136private function f_build_lu(MobileIdentityLV mi) return PDU_ML3_MS_NW
137{
138 var LocationAreaIdentification_V old_lai := { '62F220'O, '9999'O };
139 var PDU_ML3_MS_NW l3_info := valueof(ts_ML3_MO_LU_Req(valueof(ts_ML3_IE_LuType_Attach),
140 old_lai, mi, valueof(ts_CM1)));
141 return l3_info;
142}
143
Harald Weltecf66d5a2018-01-23 19:24:28 +0100144type record AuthVector {
145 OCT16 rand,
146 OCT4 sres,
147 OCT8 kc
148 /* FIXME: 3G elements */
149}
150
151private function f_rnd_oct(integer len) return octetstring {
152 var integer i;
153 var octetstring res;
154 for (i := 0; i < len; i := i + 1) {
155 res[i] := int2oct(float2int(rnd()*256.0), 1);
156 }
157 return res;
158}
159
160function f_gen_auth_vec_2g() return AuthVector {
161 var AuthVector vec;
162 vec.rand := f_rnd_oct(16);
163 vec.sres := f_rnd_oct(4);
164 vec.kc := f_rnd_oct(8);
165 return vec;
166}
167
Harald Welte16114282018-01-24 22:41:21 +0100168function f_perform_lu(boolean expect_auth, boolean expect_tmsi, boolean send_early_cm,
169 boolean expect_ciph := false)
Harald Weltea49e36e2018-01-21 19:29:33 +0100170runs on BSC_ConnHdlr {
171 var PDU_ML3_MS_NW l3_lu := f_build_lu_imsi(g_pars.imsi)
172 var PDU_DTAP_MT dtap_mt;
Harald Welte16114282018-01-24 22:41:21 +0100173 var AuthVector vec;
Harald Weltea49e36e2018-01-21 19:29:33 +0100174
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 Welte16114282018-01-24 22:41:21 +0100186 vec := f_gen_auth_vec_2g();
Harald Weltecf66d5a2018-01-23 19:24:28 +0100187 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
Harald Welte16114282018-01-24 22:41:21 +0100195 if (expect_ciph) {
196 BSSAP.receive(tr_BSSMAP_CipherModeCmd(?, vec.kc));
197 g_pars.kc := vec.kc;
198 BSSAP.send(ts_BSSMAP_CipherModeCompl('02'O));
199 }
200
Harald Weltea49e36e2018-01-21 19:29:33 +0100201 /* Expect MSC to perform LU with HLR */
202 GSUP.receive(tr_GSUP_UL_REQ(g_pars.imsi));
203 GSUP.send(ts_GSUP_ISD_REQ(g_pars.imsi, g_pars.msisdn));
204 GSUP.receive(tr_GSUP_ISD_RES(g_pars.imsi));
205 GSUP.send(ts_GSUP_UL_RES(g_pars.imsi));
206
207 alt {
208 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Acc)) -> value dtap_mt {
209 var PDU_ML3_LocationUpdateAccept lu_acc := dtap_mt.dtap.msgs.mm.locationUpdateAccept;
210 if (expect_tmsi) {
211 if (not ispresent(lu_acc.mobileIdentityTLV) or
212 not ischosen(lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi)) {
213 setverdict(fail, "Expected TMSI but no TMSI was allocated");
214 self.stop;
215 } else {
Harald Welte256571e2018-01-24 18:47:19 +0100216 g_pars.tmsi := lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi.octets;
Harald Weltea49e36e2018-01-21 19:29:33 +0100217 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_TmsiRealloc_Cmpl));
218 }
219 } else {
220 if (ispresent(lu_acc.mobileIdentityTLV) and
221 ischosen(lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi)) {
222 setverdict(fail, "Expected no TMSI but TMSI was allocated");
223 self.stop;
224 }
225 }
226 }
227 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Rej)) {
228 setverdict(fail, "Expected LU ACK, but received LU REJ");
229 self.stop;
230 }
231 }
232 /* FIXME: there could be pending SMS or other common procedures by the MSC, let's ignore them */
233 BSSAP.receive(tr_BSSMAP_ClearCommand);
234 BSSAP.send(ts_BSSMAP_ClearComplete);
235 BSSAP.receive(BSSAP_Conn_Prim:MSC_CONN_PRIM_DISC_IND);
236 setverdict(pass);
237}
238
239function f_foo() runs on BSC_ConnHdlr{
240 /* SCCP CC handled by BSSMAP_Emulation_CT.main() */
241 /* Expect auth, if enabled */
242
243 /* TODO: ISD */
244 /* Expect encr, if enabled */
245 /* Expect encr, if enabled */
246 /* Expect ASS CMD, if chan_type != requested */
247 /* Send ASS CMPL in successful case */
248
249 /* Expect AoIP port/ip information for RTP stream */
250 /* Expect MSC-originated MGCP to our simulated MGW */
251 /* Verify Counters via CTRL */
252 /* re-configure MSC behaviour via VTY */
253}
254
255
256
257
258
259}
260
261