blob: 75c45ddab1f2b2d1ea8e623da03e5bbfd4aa62b4 [file] [log] [blame]
Pau Espin Pedrolb54acca2021-11-22 20:35:44 +01001module Iuh_CodecPort {
2
3/* Simple Iuh Codec Port, translating between raw SCTP primitives with
4 * octetstring payload towards the IPL4asp provider, and Iuh primitives
5 * which carry the decoded Iuh data types as payload.
6 *
7 * (C) 2021 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
8 * Author: Pau Espin Pedrol <pespin@sysmocom.de>
9 * All rights reserved.
10 *
11 * Released under the terms of GNU General Public License, Version 2 or
12 * (at your option) any later version.
13 *
14 * SPDX-License-Identifier: GPL-2.0-or-later
15 */
16
17 import from IPL4asp_PortType all;
18 import from IPL4asp_Types all;
19 import from HNBAP_PDU_Descriptions all;
20 import from HNBAP_Types all;
21 import from RUA_PDU_Descriptions all;
22 import from RUA_Types all;
23 import from Iuh_Types all;
24
25 type record Iuh_RecvFrom {
26 ConnectionId connId,
27 HostName remName,
28 PortNumber remPort,
29 HostName locName,
30 PortNumber locPort,
31 Iuh_PDU msg
32 };
33
34 template Iuh_RecvFrom t_Iuh_RecvFrom(template Iuh_PDU msg) := {
35 connId := ?,
36 remName := ?,
37 remPort := ?,
38 locName := ?,
39 locPort := ?,
40 msg := msg
41 }
42
43 template Iuh_RecvFrom t_Iuh_RecvFrom_HNBAP(template HNBAP_PDU hnbap_msg := ?) := {
44 connId := ?,
45 remName := ?,
46 remPort := ?,
47 locName := ?,
48 locPort := ?,
49 msg := {
50 hnbap := hnbap_msg
51 }
52 }
53
54 template Iuh_RecvFrom t_Iuh_RecvFrom_RUA(template RUA_PDU rua_msg := ?) := {
55 connId := ?,
56 remName := ?,
57 remPort := ?,
58 locName := ?,
59 locPort := ?,
60 msg := {
61 rua := rua_msg
62 }
63 }
64
65 type record Iuh_Send {
66 ConnectionId connId,
67 Iuh_PDU msg
68 };
69
70 template Iuh_Send t_Iuh_Send_HNBAP(template ConnectionId connId, template HNBAP_PDU hnbap_msg) := {
71 connId := connId,
72 msg := {
73 hnbap := hnbap_msg
74 }
75 }
76
77 template Iuh_Send t_Iuh_Send_RUA(template ConnectionId connId, template RUA_PDU rua_msg) := {
78 connId := connId,
79 msg := {
80 rua := rua_msg
81 }
82 }
83
84 private function IPL4_to_Iuh_RecvFrom(in ASP_RecvFrom pin, out Iuh_RecvFrom pout) {
85 pout.connId := pin.connId;
86 pout.remName := pin.remName;
87 pout.remPort := pin.remPort;
88 pout.locName := pin.locName;
89 pout.locPort := pin.locPort;
90 select (pin.proto.sctp.sinfo_ppid) {
91 case (19) {
92 pout.msg.rua := dec_RUA_PDU(pin.msg);
93 }
94 case (20) {
95 pout.msg.hnbap := dec_HNBAP_PDU(pin.msg);
96 }
Pau Espin Pedrolb54acca2021-11-22 20:35:44 +010097 case else {
98 pout.msg.payload := pin.msg;
99 }
100 }
101 } with { extension "prototype(fast)" };
102
103 private function Iuh_to_IPL4_Send(in Iuh_Send pin, out ASP_Send pout) {
104 var integer sctp_ppid;
105 if (ischosen(pin.msg.rua)) {
106 sctp_ppid := 19;
107 pout.msg := enc_RUA_PDU(pin.msg.rua);
108 } else if (ischosen(pin.msg.hnbap)) {
109 sctp_ppid := 20;
110 pout.msg := enc_HNBAP_PDU(pin.msg.hnbap);
111 } else { /*TODO: abort?*/
112 sctp_ppid := 0;
113 pout.msg := pin.msg.payload;
114 }
115 pout.connId := pin.connId;
116 pout.proto := {
117 sctp := {
118 sinfo_stream := omit,
119 sinfo_ppid := sctp_ppid,
120 remSocks := omit,
121 assocId := omit
122 }
123 };
124 } with { extension "prototype(fast)" };
125
126 type port Iuh_CODEC_PT message {
127 out Iuh_Send;
128 in Iuh_RecvFrom,
129 ASP_ConnId_ReadyToRelease,
130 ASP_Event;
131 } with { extension "user IPL4asp_PT
132 out(Iuh_Send -> ASP_Send:function(Iuh_to_IPL4_Send))
133 in(ASP_RecvFrom -> Iuh_RecvFrom: function(IPL4_to_Iuh_RecvFrom);
134 ASP_ConnId_ReadyToRelease -> ASP_ConnId_ReadyToRelease: simple;
135 ASP_Event -> ASP_Event: simple)"
136 }
137}