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, |
| 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 */ |
| 38 | private function BscUnitdataCallback(PDU_BSSAP bssap) |
| 39 | runs 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 | |
| 53 | const 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 | |
| 62 | private function MnccUnitdataCallback(MNCC_PDU mncc) |
| 63 | runs on MNCC_Emulation_CT return template MNCC_PDU { |
| 64 | log("Ignoring MNCC", mncc); |
| 65 | return omit; |
| 66 | } |
| 67 | |
| 68 | const MnccOps BCC_MnccOps := { |
| 69 | create_cb := refers(MNCC_Emulation.ExpectedCreateCallback), |
| 70 | unitdata_cb := refers(MnccUnitdataCallback) |
| 71 | } |
| 72 | |
| 73 | |
| 74 | |
| 75 | template 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 | |
| 81 | template (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 */ |
| 90 | function f_bssap_compl_l3(PDU_ML3_MS_NW l3) |
| 91 | runs 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 Welte | 71b6933 | 2018-01-21 20:43:53 +0100 | [diff] [blame] | 96 | 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 Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | /* helper function to fully establish a dedicated channel */ |
| 106 | function f_establish_fully(MobileIdentityLV mi, boolean expect_auth) |
| 107 | runs 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 */ |
| 121 | function 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 | } |
| 126 | private 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 | |
| 134 | function f_perform_lu(boolean expect_auth, boolean expect_tmsi) |
| 135 | runs 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 | |
Harald Welte | 5c2622c | 2018-01-21 20:45:20 +0100 | [diff] [blame^] | 145 | BSSAP.send(ts_BSSMAP_ClassmarkUpd); |
| 146 | |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 147 | if (expect_auth) { |
| 148 | /* FIXME */ |
| 149 | } |
| 150 | |
| 151 | /* Expect MSC to perform LU with HLR */ |
| 152 | GSUP.receive(tr_GSUP_UL_REQ(g_pars.imsi)); |
| 153 | GSUP.send(ts_GSUP_ISD_REQ(g_pars.imsi, g_pars.msisdn)); |
| 154 | GSUP.receive(tr_GSUP_ISD_RES(g_pars.imsi)); |
| 155 | GSUP.send(ts_GSUP_UL_RES(g_pars.imsi)); |
| 156 | |
| 157 | alt { |
| 158 | [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Acc)) -> value dtap_mt { |
| 159 | var PDU_ML3_LocationUpdateAccept lu_acc := dtap_mt.dtap.msgs.mm.locationUpdateAccept; |
| 160 | if (expect_tmsi) { |
| 161 | if (not ispresent(lu_acc.mobileIdentityTLV) or |
| 162 | not ischosen(lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi)) { |
| 163 | setverdict(fail, "Expected TMSI but no TMSI was allocated"); |
| 164 | self.stop; |
| 165 | } else { |
| 166 | BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_TmsiRealloc_Cmpl)); |
| 167 | } |
| 168 | } else { |
| 169 | if (ispresent(lu_acc.mobileIdentityTLV) and |
| 170 | ischosen(lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi)) { |
| 171 | setverdict(fail, "Expected no TMSI but TMSI was allocated"); |
| 172 | self.stop; |
| 173 | } |
| 174 | } |
| 175 | } |
| 176 | [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Rej)) { |
| 177 | setverdict(fail, "Expected LU ACK, but received LU REJ"); |
| 178 | self.stop; |
| 179 | } |
| 180 | } |
| 181 | /* FIXME: there could be pending SMS or other common procedures by the MSC, let's ignore them */ |
| 182 | BSSAP.receive(tr_BSSMAP_ClearCommand); |
| 183 | BSSAP.send(ts_BSSMAP_ClearComplete); |
| 184 | BSSAP.receive(BSSAP_Conn_Prim:MSC_CONN_PRIM_DISC_IND); |
| 185 | setverdict(pass); |
| 186 | } |
| 187 | |
| 188 | function f_foo() runs on BSC_ConnHdlr{ |
| 189 | /* SCCP CC handled by BSSMAP_Emulation_CT.main() */ |
| 190 | /* Expect auth, if enabled */ |
| 191 | |
| 192 | /* TODO: ISD */ |
| 193 | /* Expect encr, if enabled */ |
| 194 | /* Expect encr, if enabled */ |
| 195 | /* Expect ASS CMD, if chan_type != requested */ |
| 196 | /* Send ASS CMPL in successful case */ |
| 197 | |
| 198 | /* Expect AoIP port/ip information for RTP stream */ |
| 199 | /* Expect MSC-originated MGCP to our simulated MGW */ |
| 200 | /* Verify Counters via CTRL */ |
| 201 | /* re-configure MSC behaviour via VTY */ |
| 202 | } |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | |
| 208 | } |
| 209 | |
| 210 | |