Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 1 | module BSC_MS_ConnectionHandler { |
| 2 | |
| 3 | import from General_Types all; |
| 4 | import from Osmocom_Types all; |
| 5 | import from SCCPasp_Types all; |
| 6 | import from BSSAP_Types all; |
| 7 | import from BSSMAP_Emulation all; |
| 8 | import from BSSMAP_Templates all; |
| 9 | |
| 10 | import from MobileL3_Types all; |
| 11 | import from MobileL3_CommonIE_Types all; |
| 12 | import from L3_Templates all; |
| 13 | |
| 14 | /* this component represents a single subscriber connection at the MSC. |
| 15 | * There is a 1:1 mapping between SCCP connections and BSSAP_ConnHdlr components. |
| 16 | * We inherit all component variables, ports, functions, ... from BSSAP_ConnHdlr */ |
| 17 | type component BSC_MS_ConnHdlr extends BSSAP_ConnHdlr { |
| 18 | /* SCCP Connecction Identifier for the underlying SCCP connection */ |
| 19 | var integer g_sccp_conn_id; |
| 20 | } |
| 21 | |
| 22 | /* Callback function from general BSSMAP_Emulation whenever a new incoming |
| 23 | * SCCP connection arrivces. Must create + start a new component */ |
| 24 | private function CreateCallback(ASP_SCCP_N_CONNECT_ind conn_ind) |
| 25 | runs on BSSMAP_Emulation_CT return BSSAP_ConnHdlr { |
| 26 | log("Incoming SCCP Connection on BSC ?!?"); |
| 27 | self.stop; |
| 28 | } |
| 29 | |
| 30 | /* Callback function from general BSSMAP_Emulation whenever a connectionless |
| 31 | * BSSMAP message arrives. Can retunr a PDU_BSSAP that should be sent in return */ |
| 32 | private function UnitdataCallback(PDU_BSSAP bssap) |
| 33 | runs on BSSMAP_Emulation_CT return template PDU_BSSAP { |
| 34 | var template PDU_BSSAP resp := omit; |
| 35 | |
| 36 | if (match(bssap, tr_BSSMAP_Reset)) { |
| 37 | resp := ts_BSSMAP_ResetAck; |
| 38 | } |
| 39 | |
| 40 | return resp; |
| 41 | } |
| 42 | |
| 43 | const BssmapOps BSC_MS_BssmapOps := { |
| 44 | create_cb := refers(CreateCallback), |
| 45 | unitdata_cb := refers(UnitdataCallback) |
| 46 | } |
| 47 | |
| 48 | |
| 49 | function f_gen_cl3(hexstring imsi) return PDU_BSSAP { |
| 50 | var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(imsi)); |
| 51 | var PDU_ML3_MS_NW l3 := valueof(ts_CM_SERV_REQ('0001'B, mi)); |
| 52 | var BSSMAP_IE_CellIdentifier cell_id := valueof(ts_CellID_LAC_CI(23, 42)); |
| 53 | var PDU_BSSAP bssap := valueof(ts_BSSMAP_ComplL3(cell_id, enc_PDU_ML3_MS_NW(l3))); |
| 54 | return bssap; |
| 55 | } |
| 56 | |
| 57 | /* main function processing various incoming events */ |
| 58 | function main(SCCP_PAR_Address sccp_addr_own, SCCP_PAR_Address sccp_addr_remote) |
| 59 | runs on BSC_MS_ConnHdlr { |
| 60 | var PDU_BSSAP bssap; |
| 61 | |
| 62 | log("Starting main of BSC_MS_ConnHdlr"); |
| 63 | |
| 64 | /* generate and send the Complete Layer3 Info */ |
| 65 | bssap := f_gen_cl3('901770123456789'H); |
| 66 | |
| 67 | var BSSAP_Conn_Req creq := { |
| 68 | addr_peer := sccp_addr_remote, |
| 69 | addr_own := sccp_addr_own, |
| 70 | bssap := bssap |
| 71 | } |
| 72 | BSSAP.send(creq); |
| 73 | |
| 74 | while (true) { |
| 75 | alt { |
| 76 | /* new SCCP-level connection indication from BSC */ |
Harald Welte | ab05d6c | 2017-11-23 18:50:52 +0100 | [diff] [blame^] | 77 | [] BSSAP.receive(tr_BSSMAP_AssignmentReq) -> value bssap { |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 78 | /* TODO: Read CIC */ |
| 79 | /* respond with ASSIGNMENT COMPL */ |
| 80 | BSSAP.send(ts_BSSMAP_AssignmentComplete(bssap.pdu.bssmap.assignmentRequest.circuitIdentityCode)); |
| 81 | } |
| 82 | /* TODO: CLEAR REQUEST from BSS */ |
| 83 | /* CLEAR COMMAND from MSC; respond with CLEAR COMPLETE) */ |
| 84 | [] BSSAP.receive(tr_BSSMAP_ClearCommand) -> value bssap { |
| 85 | BSSAP.send(ts_BSSMAP_ClearComplete); |
| 86 | /* FIXME: local release? */ |
| 87 | } |
| 88 | |
| 89 | [] BSSAP.receive(tr_BSSAP_DTAP) -> value bssap { |
| 90 | var PDU_ML3_MS_NW l3 := dec_PDU_ML3_MS_NW(bssap.pdu.dtap); |
| 91 | log("Unhandled DTAP ", l3); |
| 92 | } |
| 93 | |
| 94 | [] BSSAP.receive(BSSAP_Conn_Prim:MSC_CONN_PRIM_DISC_IND) { |
| 95 | self.stop; |
| 96 | } |
| 97 | |
| 98 | [] BSSAP.receive(PDU_BSSAP:?) -> value bssap { |
| 99 | log("Received unhandled SCCP-CO: ", bssap); |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | } |