blob: 443babee6b2fcbb359b71488ff10b4e7a0a8417b [file] [log] [blame]
Harald Welteb3414b22017-11-23 18:22:10 +01001module BSC_MS_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
10import from MobileL3_Types all;
11import from MobileL3_CommonIE_Types all;
12import 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 */
17type 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 */
24private function CreateCallback(ASP_SCCP_N_CONNECT_ind conn_ind)
25runs 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 */
32private function UnitdataCallback(PDU_BSSAP bssap)
33runs 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
43const BssmapOps BSC_MS_BssmapOps := {
44 create_cb := refers(CreateCallback),
45 unitdata_cb := refers(UnitdataCallback)
46}
47
48
49function 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 */
58function main(SCCP_PAR_Address sccp_addr_own, SCCP_PAR_Address sccp_addr_remote)
59runs 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 */
77 [] BSSAP.receive(tr_BSSMAP_AssignmentCmd) -> value bssap {
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}