Harald Welte | a76c4bb | 2017-12-09 02:06:07 +0100 | [diff] [blame] | 1 | module Osmocom_CTRL_Types { |
| 2 | |
Harald Welte | 35bb716 | 2018-01-03 21:07:52 +0100 | [diff] [blame] | 3 | /* Definition of abstract types for the CTRL protocol as used in Osmocom. |
| 4 | * Uses the TITAN "TEXT" codec to auto-generate encoder/decoder functions. |
| 5 | * |
Harald Welte | 34b5a95 | 2019-05-27 11:54:11 +0200 | [diff] [blame] | 6 | * (C) 2017-2018 by Harald Welte <laforge@gnumonks.org> |
Harald Welte | 35bb716 | 2018-01-03 21:07:52 +0100 | [diff] [blame] | 7 | * All rights reserved. |
| 8 | * |
| 9 | * Released under the terms of GNU General Public License, Version 2 or |
| 10 | * (at your option) any later version. |
Harald Welte | 34b5a95 | 2019-05-27 11:54:11 +0200 | [diff] [blame] | 11 | * |
| 12 | * SPDX-License-Identifier: GPL-2.0-or-later |
Harald Welte | 35bb716 | 2018-01-03 21:07:52 +0100 | [diff] [blame] | 13 | */ |
| 14 | |
Harald Welte | a76c4bb | 2017-12-09 02:06:07 +0100 | [diff] [blame] | 15 | type charstring CtrlVerb ("GET", "SET") with { |
| 16 | /* see https://www.eclipse.org/forums/index.php/t/1088893/ on why this |
| 17 | * match expression is needed here */ |
Harald Welte | fdfa046 | 2017-12-10 18:09:40 +0100 | [diff] [blame] | 18 | variant "TEXT_CODING(,convert=upper_case,'((GET)|(SET))',case_insensitive)" |
Harald Welte | a76c4bb | 2017-12-09 02:06:07 +0100 | [diff] [blame] | 19 | }; |
| 20 | |
Harald Welte | 03c0e56 | 2017-12-09 02:55:12 +0100 | [diff] [blame] | 21 | type charstring CtrlReplyVerb ("GET_REPLY", "SET_REPLY") with { |
| 22 | variant "TEXT_CODING(,convert=upper_case,'((GET_REPLY)|(SET_REPLY))',case_insensitive)" |
Harald Welte | a76c4bb | 2017-12-09 02:06:07 +0100 | [diff] [blame] | 23 | }; |
| 24 | |
| 25 | type charstring CtrlId (pattern "\d#(1,9)"); |
Harald Welte | 0ac4667 | 2017-12-09 14:19:58 +0100 | [diff] [blame] | 26 | type charstring CtrlVariable (pattern "[^, \{\}\[\]\(\)<>\|~\\\^`'\"\?=;/\+&%$\#!]#(1,)"); |
| 27 | type charstring CtrlValue (pattern "[^ ]#(0,)"); |
Harald Welte | a76c4bb | 2017-12-09 02:06:07 +0100 | [diff] [blame] | 28 | type charstring CtrlReason; |
| 29 | |
| 30 | |
| 31 | type record CtrlCommand { |
| 32 | CtrlVerb verb, |
| 33 | CtrlId id, |
| 34 | CtrlVariable variable, |
| 35 | CtrlValue val optional /* only for SET */ |
| 36 | } with { |
| 37 | variant "SEPARATOR(' ',)" |
| 38 | }; |
| 39 | |
| 40 | type record CtrlResponse { |
Harald Welte | 03c0e56 | 2017-12-09 02:55:12 +0100 | [diff] [blame] | 41 | CtrlReplyVerb verb, |
Harald Welte | a76c4bb | 2017-12-09 02:06:07 +0100 | [diff] [blame] | 42 | CtrlId id, |
| 43 | CtrlVariable variable, |
| 44 | CtrlValue val |
| 45 | } with { |
Harald Welte | a76c4bb | 2017-12-09 02:06:07 +0100 | [diff] [blame] | 46 | variant "SEPARATOR(' ',)" |
| 47 | }; |
| 48 | |
| 49 | type record CtrlError { |
| 50 | CtrlId id, |
| 51 | CtrlReason reason |
| 52 | } with { |
| 53 | variant "BEGIN('ERROR ',,case_insensitive)" |
| 54 | variant "SEPARATOR(' ',)" |
| 55 | }; |
| 56 | |
| 57 | type record CtrlTrap { |
| 58 | CtrlVariable variable, |
| 59 | CtrlValue val |
| 60 | } with { |
Harald Welte | fdfa046 | 2017-12-10 18:09:40 +0100 | [diff] [blame] | 61 | variant "BEGIN('TRAP 0 ',,case_insensitive)" |
Harald Welte | a76c4bb | 2017-12-09 02:06:07 +0100 | [diff] [blame] | 62 | variant "SEPARATOR(' ',)" |
| 63 | }; |
| 64 | |
| 65 | type union CtrlMessage { |
| 66 | CtrlCommand cmd, |
| 67 | CtrlResponse resp, |
| 68 | CtrlError err, |
| 69 | CtrlTrap trap |
Harald Welte | 1697976 | 2017-12-13 00:45:44 +0100 | [diff] [blame] | 70 | } with { variant "BEGIN('')" }; |
Harald Welte | a76c4bb | 2017-12-09 02:06:07 +0100 | [diff] [blame] | 71 | |
| 72 | external function enc_CtrlMessage(in CtrlMessage id) return charstring |
| 73 | with { extension "prototype(convert) encode(TEXT)"}; |
| 74 | |
| 75 | external function dec_CtrlMessage(in charstring id) return CtrlMessage |
| 76 | with { extension "prototype(convert) decode(TEXT)"}; |
| 77 | |
| 78 | |
Harald Welte | 03c0e56 | 2017-12-09 02:55:12 +0100 | [diff] [blame] | 79 | template CtrlMessage ts_CtrlMsgGet(CtrlId id, CtrlVariable variable) := { |
| 80 | cmd := { |
| 81 | verb := "GET", |
| 82 | id := id, |
| 83 | variable := variable, |
| 84 | val := omit |
| 85 | } |
| 86 | }; |
| 87 | |
| 88 | template CtrlMessage ts_CtrlMsgSet(CtrlId id, CtrlVariable variable, CtrlValue val) := { |
| 89 | cmd := { |
| 90 | verb := "SET", |
| 91 | id := id, |
| 92 | variable := variable, |
Pau Espin Pedrol | 6bf6313 | 2019-06-07 15:37:36 +0200 | [diff] [blame] | 93 | val := val |
Harald Welte | 03c0e56 | 2017-12-09 02:55:12 +0100 | [diff] [blame] | 94 | } |
| 95 | } |
| 96 | |
Pau Espin Pedrol | 579cd7a | 2019-06-10 21:01:30 +0200 | [diff] [blame] | 97 | template CtrlMessage ts_CtrlMsgTrap(CtrlVariable variable, template (omit) CtrlValue val := omit) := { |
| 98 | trap := { |
| 99 | variable := variable, |
| 100 | val := val |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | template CtrlMessage ts_CtrlMsgGetRepl(CtrlId id, CtrlVariable variable, CtrlValue val) := { |
| 105 | resp := { |
| 106 | verb := "GET_REPLY", |
| 107 | id := id, |
| 108 | variable := variable, |
| 109 | val := val |
| 110 | } |
| 111 | }; |
| 112 | |
| 113 | template CtrlMessage ts_CtrlMsgSetRepl(CtrlId id, CtrlVariable variable, CtrlValue val) := { |
| 114 | resp := { |
| 115 | verb := "SET_REPLY", |
| 116 | id := id, |
| 117 | variable := variable, |
| 118 | val := val |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | template CtrlMessage tr_CtrlMsgGet(template CtrlId id, template CtrlVariable variable := ?) := { |
| 123 | cmd := { |
| 124 | verb := "GET", |
| 125 | id := id, |
| 126 | variable := variable, |
Pau Espin Pedrol | ec2ee46 | 2021-01-05 17:37:41 +0100 | [diff] [blame] | 127 | val := omit |
Pau Espin Pedrol | 579cd7a | 2019-06-10 21:01:30 +0200 | [diff] [blame] | 128 | } |
| 129 | } |
| 130 | |
| 131 | template CtrlMessage tr_CtrlMsgSet(template CtrlId id, template CtrlVariable variable := ?, |
| 132 | template CtrlValue val := ?) := { |
| 133 | cmd := { |
| 134 | verb := "SET", |
| 135 | id := id, |
| 136 | variable := variable, |
| 137 | val := val |
| 138 | } |
| 139 | } |
| 140 | |
Harald Welte | 03c0e56 | 2017-12-09 02:55:12 +0100 | [diff] [blame] | 141 | template CtrlMessage tr_CtrlMsgGetRepl(template CtrlId id, template CtrlVariable variable := ?) := { |
| 142 | resp := { |
| 143 | verb := "GET_REPLY", |
| 144 | id := id, |
| 145 | variable := variable, |
| 146 | val := ? |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | template CtrlMessage tr_CtrlMsgSetRepl(template CtrlId id, template CtrlVariable variable := ?, |
| 151 | template CtrlValue val := ?) := { |
| 152 | resp := { |
| 153 | verb := "SET_REPLY", |
| 154 | id := id, |
| 155 | variable := variable, |
| 156 | val := val |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | template CtrlMessage tr_CtrlMsgTrap(template CtrlVariable variable := ?, |
| 161 | template CtrlValue val := ?) := { |
| 162 | trap := { |
| 163 | variable := variable, |
| 164 | val := val |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | template CtrlMessage tr_CtrlMsgError(template CtrlId id := ?, template CtrlReason reason := ?) := { |
| 169 | err := { |
| 170 | id := id, |
| 171 | reason := reason |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | |
Harald Welte | a76c4bb | 2017-12-09 02:06:07 +0100 | [diff] [blame] | 176 | } with { encode "TEXT" } |