Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 1 | module BSC_ConnectionHandler { |
| 2 | |
| 3 | import from General_Types all; |
| 4 | import from Osmocom_Types all; |
| 5 | import from GSM_Types all; |
| 6 | import from SCCPasp_Types all; |
| 7 | import from BSSAP_Types all; |
| 8 | import from BSSMAP_Emulation all; |
| 9 | import from BSSMAP_Templates all; |
| 10 | |
| 11 | import from GSUP_Types all; |
| 12 | import from GSUP_Emulation all; |
| 13 | |
| 14 | import from MNCC_Types all; |
| 15 | import from MNCC_Emulation all; |
| 16 | |
| 17 | import from MobileL3_Types all; |
| 18 | import from MobileL3_CommonIE_Types all; |
| 19 | import from MobileL3_MM_Types all; |
| 20 | import from L3_Templates all; |
| 21 | |
| 22 | /* this component represents a single subscriber connection */ |
| 23 | type component BSC_ConnHdlr extends BSSAP_ConnHdlr, MNCC_ConnHdlr, GSUP_ConnHdlr { |
| 24 | var BSC_ConnHdlrPars g_pars; |
| 25 | } |
| 26 | |
| 27 | type 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 Welte | 8260057 | 2018-01-21 20:54:08 +0100 | [diff] [blame] | 32 | hexstring msisdn, |
| 33 | BSSMAP_IE_ClassmarkInformationType2 cm2, |
| 34 | BSSMAP_IE_ClassmarkInformationType3 cm3 optional |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 35 | }; |
| 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 */ |
| 40 | private function BscUnitdataCallback(PDU_BSSAP bssap) |
| 41 | runs 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 | |
| 55 | const 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 | |
| 64 | private function MnccUnitdataCallback(MNCC_PDU mncc) |
| 65 | runs on MNCC_Emulation_CT return template MNCC_PDU { |
| 66 | log("Ignoring MNCC", mncc); |
| 67 | return omit; |
| 68 | } |
| 69 | |
| 70 | const MnccOps BCC_MnccOps := { |
| 71 | create_cb := refers(MNCC_Emulation.ExpectedCreateCallback), |
| 72 | unitdata_cb := refers(MnccUnitdataCallback) |
| 73 | } |
| 74 | |
| 75 | |
| 76 | |
| 77 | template 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 | |
| 83 | template (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 */ |
| 92 | function f_bssap_compl_l3(PDU_ML3_MS_NW l3) |
| 93 | runs 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 Welte | 71b6933 | 2018-01-21 20:43:53 +0100 | [diff] [blame] | 98 | 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 Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | /* helper function to fully establish a dedicated channel */ |
| 108 | function f_establish_fully(MobileIdentityLV mi, boolean expect_auth) |
| 109 | runs 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 */ |
| 123 | function 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 | } |
| 128 | private function f_build_lu(MobileIdentityLV mi) return PDU_ML3_MS_NW |
| 129 | { |
| 130 | var LocationAreaIdentification_V old_lai := { '62F220'O, '9999'O }; |
| 131 | var PDU_ML3_MS_NW l3_info := valueof(ts_ML3_MO_LU_Req(valueof(ts_ML3_IE_LuType_Attach), |
| 132 | old_lai, mi, valueof(ts_CM1))); |
| 133 | return l3_info; |
| 134 | } |
| 135 | |
| 136 | function f_perform_lu(boolean expect_auth, boolean expect_tmsi) |
| 137 | runs on BSC_ConnHdlr { |
| 138 | var PDU_ML3_MS_NW l3_lu := f_build_lu_imsi(g_pars.imsi) |
| 139 | var PDU_DTAP_MT dtap_mt; |
| 140 | |
| 141 | /* tell GSUP dispatcher to send this IMSI to us */ |
| 142 | f_create_gsup_expect(hex2str(g_pars.imsi)); |
| 143 | |
| 144 | /* Send BSSAP_Conn_Req with COMPL L3 INFO to MSC */ |
| 145 | f_bssap_compl_l3(l3_lu); |
| 146 | |
Harald Welte | 8260057 | 2018-01-21 20:54:08 +0100 | [diff] [blame] | 147 | BSSAP.send(ts_BSSMAP_ClassmarkUpd(g_pars.cm2, g_pars.cm3)); |
Harald Welte | 5c2622c | 2018-01-21 20:45:20 +0100 | [diff] [blame] | 148 | |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 149 | if (expect_auth) { |
| 150 | /* FIXME */ |
| 151 | } |
| 152 | |
| 153 | /* Expect MSC to perform LU with HLR */ |
| 154 | GSUP.receive(tr_GSUP_UL_REQ(g_pars.imsi)); |
| 155 | GSUP.send(ts_GSUP_ISD_REQ(g_pars.imsi, g_pars.msisdn)); |
| 156 | GSUP.receive(tr_GSUP_ISD_RES(g_pars.imsi)); |
| 157 | GSUP.send(ts_GSUP_UL_RES(g_pars.imsi)); |
| 158 | |
| 159 | alt { |
| 160 | [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Acc)) -> value dtap_mt { |
| 161 | var PDU_ML3_LocationUpdateAccept lu_acc := dtap_mt.dtap.msgs.mm.locationUpdateAccept; |
| 162 | if (expect_tmsi) { |
| 163 | if (not ispresent(lu_acc.mobileIdentityTLV) or |
| 164 | not ischosen(lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi)) { |
| 165 | setverdict(fail, "Expected TMSI but no TMSI was allocated"); |
| 166 | self.stop; |
| 167 | } else { |
| 168 | BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_TmsiRealloc_Cmpl)); |
| 169 | } |
| 170 | } else { |
| 171 | if (ispresent(lu_acc.mobileIdentityTLV) and |
| 172 | ischosen(lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi)) { |
| 173 | setverdict(fail, "Expected no TMSI but TMSI was allocated"); |
| 174 | self.stop; |
| 175 | } |
| 176 | } |
| 177 | } |
| 178 | [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Rej)) { |
| 179 | setverdict(fail, "Expected LU ACK, but received LU REJ"); |
| 180 | self.stop; |
| 181 | } |
| 182 | } |
| 183 | /* FIXME: there could be pending SMS or other common procedures by the MSC, let's ignore them */ |
| 184 | BSSAP.receive(tr_BSSMAP_ClearCommand); |
| 185 | BSSAP.send(ts_BSSMAP_ClearComplete); |
| 186 | BSSAP.receive(BSSAP_Conn_Prim:MSC_CONN_PRIM_DISC_IND); |
| 187 | setverdict(pass); |
| 188 | } |
| 189 | |
| 190 | function f_foo() runs on BSC_ConnHdlr{ |
| 191 | /* SCCP CC handled by BSSMAP_Emulation_CT.main() */ |
| 192 | /* Expect auth, if enabled */ |
| 193 | |
| 194 | /* TODO: ISD */ |
| 195 | /* Expect encr, if enabled */ |
| 196 | /* Expect encr, if enabled */ |
| 197 | /* Expect ASS CMD, if chan_type != requested */ |
| 198 | /* Send ASS CMPL in successful case */ |
| 199 | |
| 200 | /* Expect AoIP port/ip information for RTP stream */ |
| 201 | /* Expect MSC-originated MGCP to our simulated MGW */ |
| 202 | /* Verify Counters via CTRL */ |
| 203 | /* re-configure MSC behaviour via VTY */ |
| 204 | } |
| 205 | |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | } |
| 211 | |
| 212 | |