Pau Espin Pedrol | b54acca | 2021-11-22 20:35:44 +0100 | [diff] [blame] | 1 | module 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 | } |
| 97 | case (0) { |
| 98 | /* FIXME: lower layers report sinfo_ppid=0: */ |
Pau Espin Pedrol | a6bbb8c | 2021-11-24 17:00:03 +0100 | [diff] [blame] | 99 | if (match(pin.msg, '000100380000070003000C02404F736D6F484E6F64654200080001000009000300F110000B0004000000100006000200020007000103000A00020004'O)) { |
| 100 | pout.msg.hnbap := dec_HNBAP_PDU(pin.msg); |
| 101 | } else { |
| 102 | pout.msg.rua := dec_RUA_PDU(pin.msg); |
| 103 | } |
Pau Espin Pedrol | b54acca | 2021-11-22 20:35:44 +0100 | [diff] [blame] | 104 | } |
| 105 | case else { |
| 106 | pout.msg.payload := pin.msg; |
| 107 | } |
| 108 | } |
| 109 | } with { extension "prototype(fast)" }; |
| 110 | |
| 111 | private function Iuh_to_IPL4_Send(in Iuh_Send pin, out ASP_Send pout) { |
| 112 | var integer sctp_ppid; |
| 113 | if (ischosen(pin.msg.rua)) { |
| 114 | sctp_ppid := 19; |
| 115 | pout.msg := enc_RUA_PDU(pin.msg.rua); |
| 116 | } else if (ischosen(pin.msg.hnbap)) { |
| 117 | sctp_ppid := 20; |
| 118 | pout.msg := enc_HNBAP_PDU(pin.msg.hnbap); |
| 119 | } else { /*TODO: abort?*/ |
| 120 | sctp_ppid := 0; |
| 121 | pout.msg := pin.msg.payload; |
| 122 | } |
| 123 | pout.connId := pin.connId; |
| 124 | pout.proto := { |
| 125 | sctp := { |
| 126 | sinfo_stream := omit, |
| 127 | sinfo_ppid := sctp_ppid, |
| 128 | remSocks := omit, |
| 129 | assocId := omit |
| 130 | } |
| 131 | }; |
| 132 | } with { extension "prototype(fast)" }; |
| 133 | |
| 134 | type port Iuh_CODEC_PT message { |
| 135 | out Iuh_Send; |
| 136 | in Iuh_RecvFrom, |
| 137 | ASP_ConnId_ReadyToRelease, |
| 138 | ASP_Event; |
| 139 | } with { extension "user IPL4asp_PT |
| 140 | out(Iuh_Send -> ASP_Send:function(Iuh_to_IPL4_Send)) |
| 141 | in(ASP_RecvFrom -> Iuh_RecvFrom: function(IPL4_to_Iuh_RecvFrom); |
| 142 | ASP_ConnId_ReadyToRelease -> ASP_ConnId_ReadyToRelease: simple; |
| 143 | ASP_Event -> ASP_Event: simple)" |
| 144 | } |
| 145 | } |