Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 1 | module MSC_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 | /* this component represents a single subscriber connection at the MSC. |
| 11 | * There is a 1:1 mapping between SCCP connections and BSSAP_ConnHdlr components. |
| 12 | * We inherit all component variables, ports, functions, ... from BSSAP_ConnHdlr */ |
| 13 | type component MSC_ConnHdlr extends BSSAP_ConnHdlr { |
| 14 | /* E1 timeslot that is allocated to this component/connection */ |
| 15 | var uint5_t g_e1_timeslot; |
| 16 | /* SCCP Connecction Identifier for the underlying SCCP connection */ |
| 17 | var integer g_sccp_conn_id; |
| 18 | } |
| 19 | |
| 20 | /* Callback function from general BSSMAP_Emulation whenever a new incoming |
| 21 | * SCCP connection arrivces. Must create + start a new component */ |
| 22 | private function CreateCallback(ASP_SCCP_N_CONNECT_ind conn_ind) |
| 23 | runs on BSSMAP_Emulation_CT return BSSAP_ConnHdlr { |
| 24 | var MSC_ConnHdlr vc_conn; |
| 25 | /* Create a new BSSAP_ConnHdlr component */ |
| 26 | vc_conn := MSC_ConnHdlr.create; |
| 27 | /* connect it to the port */ |
| 28 | connect(vc_conn:BSSAP, self:CLIENT); |
| 29 | /* start it */ |
| 30 | vc_conn.start(MSC_ConnectionHandler.main(conn_ind.connectionId, conn_ind.connectionId)); |
| 31 | return vc_conn; |
| 32 | } |
| 33 | |
| 34 | /* Callback function from general BSSMAP_Emulation whenever a connectionless |
| 35 | * BSSMAP message arrives. Can retunr a PDU_BSSAP that should be sent in return */ |
| 36 | private function UnitdataCallback(PDU_BSSAP bssap) |
| 37 | runs on BSSMAP_Emulation_CT return template PDU_BSSAP { |
| 38 | var template PDU_BSSAP resp := omit; |
| 39 | |
| 40 | if (match(bssap, tr_BSSMAP_Reset)) { |
| 41 | resp := ts_BSSMAP_ResetAck; |
| 42 | } |
| 43 | |
| 44 | return resp; |
| 45 | } |
| 46 | |
| 47 | const BssmapOps MSC_BssmapOps := { |
| 48 | create_cb := refers(CreateCallback), |
| 49 | unitdata_cb := refers(UnitdataCallback) |
| 50 | } |
| 51 | |
| 52 | /* main function processing various incoming events */ |
| 53 | function main(integer connection_id, integer timeslot) runs on MSC_ConnHdlr { |
| 54 | g_sccp_conn_id := connection_id; |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame^] | 55 | g_e1_timeslot := 1; /* FIXME */ |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 56 | |
| 57 | while (true) { |
| 58 | var PDU_BSSAP bssap; |
| 59 | alt { |
| 60 | /* new SCCP-level connection indication from BSC */ |
| 61 | [] BSSAP.receive(tr_BSSMAP_ComplL3) -> value bssap { |
| 62 | /* respond with ASSIGNMENT CMD */ |
| 63 | BSSAP.send(ts_BSSMAP_AssignmentCmd(0, g_e1_timeslot)); |
| 64 | /* FIXME: Send MGCP */ |
| 65 | } |
| 66 | /* |
| 67 | [] BSSAP.receive(tr_BSSMAP_AssignmentCompl) { |
| 68 | } |
| 69 | [] BSSAP.receive(tr_BSSMAP_AssignmentFail) { |
| 70 | } |
| 71 | */ |
| 72 | /* TODO: CLEAR REQUEST from BSS */ |
| 73 | /* TODO: CLEAR COMPLETE from BSS (response to CLEAR COMMAND) */ |
| 74 | |
| 75 | [] BSSAP.receive(BSSAP_Conn_Prim:MSC_CONN_PRIM_DISC_IND) { |
| 76 | self.stop; |
| 77 | } |
| 78 | |
| 79 | [] BSSAP.receive(PDU_BSSAP:?) -> value bssap { |
| 80 | log("Received unhandled SCCP-CO: ", bssap); |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | } |