blob: 2d6036fb74043412cf3609fce5e79ff57d372159 [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,
32 hexstring msisdn
33};
34
35
36/* Callback function from general BSSMAP_Emulation whenever a connectionless
37 * BSSMAP message arrives. Canreturn a PDU_BSSAPthat should be sent in return */
38private function BscUnitdataCallback(PDU_BSSAP bssap)
39runs on BSSMAP_Emulation_CT return template PDU_BSSAP {
40 var template PDU_BSSAP resp := omit;
41
42 log("BSSMAP_BscUnitdataCallback");
43 /* answer all RESET with RESET ACK */
44 if (match(bssap, tr_BSSMAP_Reset)){
45 log("BSSMAP_BscUnitdataCallback: Responding to RESET with RESET-ACK");
46 resp := ts_BSSMAP_ResetAck;
47 }
48
49 /* FIXME: Handle paging, etc. */
50 return resp;
51}
52
53const BssmapOps BSC_BssmapOps := {
54 /* Create call-back for inbound connections from MSC (hand-over) */
55 create_cb := refers(BSSMAP_Emulation.ExpectedCreateCallback),
56 unitdata_cb := refers(BscUnitdataCallback),
57 decode_dtap := true,
58 role_ms := true
59}
60
61
62private function MnccUnitdataCallback(MNCC_PDU mncc)
63runs on MNCC_Emulation_CT return template MNCC_PDU {
64 log("Ignoring MNCC", mncc);
65 return omit;
66}
67
68const MnccOps BCC_MnccOps := {
69 create_cb := refers(MNCC_Emulation.ExpectedCreateCallback),
70 unitdata_cb := refers(MnccUnitdataCallback)
71}
72
73
74
75template BSSAP_Conn_Req ts_BSSAP_Conn_Req(SCCP_PAR_Address peer, SCCP_PAR_Address own, PDU_BSSAP bssap) := {
76 addr_peer := peer,
77 addr_own := own,
78 bssap := bssap
79};
80
81template (value) MobileStationClassmark1_V ts_CM1(BIT1 a5_1_unavail := '0'B, BIT2 rev := '10'B) := {
82 rf_PowerCapability := '010'B,
83 a5_1 := a5_1_unavail,
84 esind := '1'B,
85 revisionLevel := rev,
86 spare1_1 := '0'B
87}
88
89/* 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 {
108 var PDU_ML3_MS_NW l3_info := valueof(ts_CM_SERV_REQ('0001'B, mi));
109 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}
126private function f_build_lu(MobileIdentityLV mi) return PDU_ML3_MS_NW
127{
128 var LocationAreaIdentification_V old_lai := { '62F220'O, '9999'O };
129 var PDU_ML3_MS_NW l3_info := valueof(ts_ML3_MO_LU_Req(valueof(ts_ML3_IE_LuType_Attach),
130 old_lai, mi, valueof(ts_CM1)));
131 return l3_info;
132}
133
134function f_perform_lu(boolean expect_auth, boolean expect_tmsi)
135runs on BSC_ConnHdlr {
136 var PDU_ML3_MS_NW l3_lu := f_build_lu_imsi(g_pars.imsi)
137 var PDU_DTAP_MT dtap_mt;
138
139 /* tell GSUP dispatcher to send this IMSI to us */
140 f_create_gsup_expect(hex2str(g_pars.imsi));
141
142 /* Send BSSAP_Conn_Req with COMPL L3 INFO to MSC */
143 f_bssap_compl_l3(l3_lu);
144
145 if (expect_auth) {
146 /* FIXME */
147 }
148
149 /* Expect MSC to perform LU with HLR */
150 GSUP.receive(tr_GSUP_UL_REQ(g_pars.imsi));
151 GSUP.send(ts_GSUP_ISD_REQ(g_pars.imsi, g_pars.msisdn));
152 GSUP.receive(tr_GSUP_ISD_RES(g_pars.imsi));
153 GSUP.send(ts_GSUP_UL_RES(g_pars.imsi));
154
155 alt {
156 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Acc)) -> value dtap_mt {
157 var PDU_ML3_LocationUpdateAccept lu_acc := dtap_mt.dtap.msgs.mm.locationUpdateAccept;
158 if (expect_tmsi) {
159 if (not ispresent(lu_acc.mobileIdentityTLV) or
160 not ischosen(lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi)) {
161 setverdict(fail, "Expected TMSI but no TMSI was allocated");
162 self.stop;
163 } else {
164 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_TmsiRealloc_Cmpl));
165 }
166 } else {
167 if (ispresent(lu_acc.mobileIdentityTLV) and
168 ischosen(lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi)) {
169 setverdict(fail, "Expected no TMSI but TMSI was allocated");
170 self.stop;
171 }
172 }
173 }
174 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Rej)) {
175 setverdict(fail, "Expected LU ACK, but received LU REJ");
176 self.stop;
177 }
178 }
179 /* FIXME: there could be pending SMS or other common procedures by the MSC, let's ignore them */
180 BSSAP.receive(tr_BSSMAP_ClearCommand);
181 BSSAP.send(ts_BSSMAP_ClearComplete);
182 BSSAP.receive(BSSAP_Conn_Prim:MSC_CONN_PRIM_DISC_IND);
183 setverdict(pass);
184}
185
186function f_foo() runs on BSC_ConnHdlr{
187 /* SCCP CC handled by BSSMAP_Emulation_CT.main() */
188 /* Expect auth, if enabled */
189
190 /* TODO: ISD */
191 /* Expect encr, if enabled */
192 /* Expect encr, if enabled */
193 /* Expect ASS CMD, if chan_type != requested */
194 /* Send ASS CMPL in successful case */
195
196 /* Expect AoIP port/ip information for RTP stream */
197 /* Expect MSC-originated MGCP to our simulated MGW */
198 /* Verify Counters via CTRL */
199 /* re-configure MSC behaviour via VTY */
200}
201
202
203
204
205
206}
207
208