Pau Espin Pedrol | b2c6b38 | 2019-05-14 13:40:49 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) 2019 by sysmocom s.f.m.c. GmbH <info@sysmocom.de> |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Author: Pau Espin Pedrol <pespin@sysmocom.de> |
| 6 | * |
| 7 | * Released under the terms of GNU General Public License, Version 2 or |
| 8 | * (at your option) any later version. |
| 9 | */ |
| 10 | |
| 11 | module OSMUX_Types { |
| 12 | |
| 13 | import from General_Types all; |
Pau Espin Pedrol | 39bfa02 | 2022-08-12 14:56:12 +0200 | [diff] [blame] | 14 | import from Misc_Helpers all; |
| 15 | |
| 16 | import from AMR_Types all; |
Pau Espin Pedrol | b2c6b38 | 2019-05-14 13:40:49 +0200 | [diff] [blame] | 17 | |
| 18 | external function enc_OSMUX_PDU ( in OSMUX_PDU msg ) return octetstring |
| 19 | with { extension "prototype(convert) encode(RAW)" }; |
| 20 | external function dec_OSMUX_PDU ( in octetstring msg ) return OSMUX_PDU |
| 21 | with { extension "prototype(convert) decode(RAW)" }; |
| 22 | |
| 23 | type INT1 OsmuxCID (0 .. 255); |
| 24 | |
| 25 | type enumerated OsmuxFT { |
| 26 | OSMUX_FT_LAPD, |
| 27 | OSMUX_FT_AMR, |
| 28 | OSMUX_FT_DUMMY |
| 29 | }; |
| 30 | |
| 31 | type record Osmux_AMR_header { |
| 32 | BIT1 marker, |
| 33 | INT2b ft, |
| 34 | INT3b ctr, |
| 35 | BIT1 amr_f, |
| 36 | BIT1 amr_q, |
| 37 | INT1 seq, |
| 38 | OsmuxCID cid, |
| 39 | INT4b amr_ft, |
| 40 | INT4b amr_cmr |
| 41 | } with { |
| 42 | variant "FIELDORDER(msb)" |
| 43 | } |
| 44 | |
| 45 | type record PDU_Osmux_AMR { |
| 46 | Osmux_AMR_header header, |
| 47 | octetstring data |
| 48 | } with { |
| 49 | variant "FIELDORDER(msb)" |
| 50 | }; |
| 51 | |
| 52 | type record PDU_Osmux_DUMMY { |
| 53 | Osmux_AMR_header header, |
| 54 | octetstring data |
| 55 | } with { |
| 56 | variant "FIELDORDER(msb)" |
| 57 | }; |
| 58 | |
| 59 | type record Osmux_session_par { |
| 60 | integer id optional, |
| 61 | charstring local_address optional, |
| 62 | integer local_port optional, |
| 63 | charstring dest_address optional, |
| 64 | integer dest_port optional |
| 65 | } |
| 66 | |
| 67 | type record ASP_Osmux_Open_session { |
| 68 | Osmux_session_par session_id |
| 69 | } |
| 70 | |
| 71 | type record ASP_Osmux_Open_session_result { |
| 72 | Osmux_session_par session_id |
| 73 | } |
| 74 | |
| 75 | type record ASP_Osmux_Close_session { |
| 76 | Osmux_session_par session_id |
| 77 | } |
| 78 | |
| 79 | type union OSMUX_PDU { |
| 80 | PDU_Osmux_AMR osmux_amr, |
| 81 | PDU_Osmux_DUMMY osmux_dummy |
| 82 | } with { |
| 83 | variant "TAG ( |
| 84 | osmux_amr, header.ft = 1; |
| 85 | osmux_dummy, header.ft = 2; |
| 86 | )" |
| 87 | }; |
| 88 | |
Pau Espin Pedrol | 39bfa02 | 2022-08-12 14:56:12 +0200 | [diff] [blame] | 89 | template (present) OSMUX_PDU tr_PDU_Osmux_AMR(template (present) BIT1 marker := ?, |
| 90 | template (present) INT3b ctr := ?, |
| 91 | template (present) BIT1 amr_f := ?, |
| 92 | template (present) BIT1 amr_q := ?, |
| 93 | template (present) INT1 seq := ?, |
| 94 | template (present) OsmuxCID cid := ?, |
| 95 | template (present) INT4b amr_ft := ?, |
| 96 | template (present) INT4b amr_cmr := ?, |
| 97 | template (present) octetstring payload := ?) := { |
| 98 | osmux_amr := { |
| 99 | header := { |
| 100 | marker := marker, |
| 101 | ft := 1, |
| 102 | ctr := ctr, |
| 103 | amr_f := amr_f, |
| 104 | amr_q := amr_q, |
| 105 | seq := seq, |
| 106 | cid := cid, |
| 107 | amr_ft := amr_ft, |
| 108 | amr_cmr := amr_cmr |
| 109 | }, |
| 110 | data := payload |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | /* Get Nth AMR payload of osmux AMR frame (starting from 0) */ |
| 115 | function f_osmux_amr_get_nth_amr_payload(PDU_Osmux_AMR osmux_amr, integer nth) return octetstring |
| 116 | { |
| 117 | var integer amr_pl_len := f_amrft_payload_len(osmux_amr.header.amr_ft); |
| 118 | if (nth > osmux_amr.header.ctr) { |
| 119 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "nth > ctr"); |
| 120 | return ''O; |
| 121 | } |
| 122 | if (amr_pl_len * (nth+1) > lengthof(osmux_amr.data)) { |
| 123 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "osmux payload too short"); |
| 124 | } |
| 125 | var octetstring pl := substr(osmux_amr.data, amr_pl_len * nth, amr_pl_len); |
| 126 | return pl; |
| 127 | } |
| 128 | |
Pau Espin Pedrol | b2c6b38 | 2019-05-14 13:40:49 +0200 | [diff] [blame] | 129 | } with { encode "RAW"} |