blob: 0d7cd20bd0c1e09f827a613f1bf754fa96db8136 [file] [log] [blame]
Harald Welte365f4ed2017-11-23 00:00:43 +01001module MSC_ConnectionHandler {
2
3import from General_Types all;
4import from Osmocom_Types all;
5import from SCCPasp_Types all;
6import from BSSAP_Types all;
7import from BSSMAP_Emulation all;
8import 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 */
13type 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 */
22private function CreateCallback(ASP_SCCP_N_CONNECT_ind conn_ind)
23runs 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 */
36private function UnitdataCallback(PDU_BSSAP bssap)
37runs 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
47const BssmapOps MSC_BssmapOps := {
48 create_cb := refers(CreateCallback),
49 unitdata_cb := refers(UnitdataCallback)
50}
51
52/* main function processing various incoming events */
53function main(integer connection_id, integer timeslot) runs on MSC_ConnHdlr {
54 g_sccp_conn_id := connection_id;
55 g_e1_timeslot := timeslot
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}