blob: 52be9566acd62d2fd352a609225128bd30eeb280 [file] [log] [blame]
Harald Weltea76c4bb2017-12-09 02:06:07 +01001module Osmocom_CTRL_Types {
2
Harald Welte35bb7162018-01-03 21:07:52 +01003/* 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 Welte34b5a952019-05-27 11:54:11 +02006 * (C) 2017-2018 by Harald Welte <laforge@gnumonks.org>
Harald Welte35bb7162018-01-03 21:07:52 +01007 * 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 Welte34b5a952019-05-27 11:54:11 +020011 *
12 * SPDX-License-Identifier: GPL-2.0-or-later
Harald Welte35bb7162018-01-03 21:07:52 +010013 */
14
Harald Weltea76c4bb2017-12-09 02:06:07 +010015type 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 Weltefdfa0462017-12-10 18:09:40 +010018 variant "TEXT_CODING(,convert=upper_case,'((GET)|(SET))',case_insensitive)"
Harald Weltea76c4bb2017-12-09 02:06:07 +010019};
20
Harald Welte03c0e562017-12-09 02:55:12 +010021type charstring CtrlReplyVerb ("GET_REPLY", "SET_REPLY") with {
22 variant "TEXT_CODING(,convert=upper_case,'((GET_REPLY)|(SET_REPLY))',case_insensitive)"
Harald Weltea76c4bb2017-12-09 02:06:07 +010023};
24
25type charstring CtrlId (pattern "\d#(1,9)");
Harald Welte0ac46672017-12-09 14:19:58 +010026type charstring CtrlVariable (pattern "[^, \{\}\[\]\(\)<>\|~\\\^`'\"\?=;/\+&%$\#!]#(1,)");
27type charstring CtrlValue (pattern "[^ ]#(0,)");
Harald Weltea76c4bb2017-12-09 02:06:07 +010028type charstring CtrlReason;
29
30
31type 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
40type record CtrlResponse {
Harald Welte03c0e562017-12-09 02:55:12 +010041 CtrlReplyVerb verb,
Harald Weltea76c4bb2017-12-09 02:06:07 +010042 CtrlId id,
43 CtrlVariable variable,
44 CtrlValue val
45} with {
Harald Weltea76c4bb2017-12-09 02:06:07 +010046 variant "SEPARATOR(' ',)"
47};
48
49type record CtrlError {
50 CtrlId id,
51 CtrlReason reason
52} with {
53 variant "BEGIN('ERROR ',,case_insensitive)"
54 variant "SEPARATOR(' ',)"
55};
56
57type record CtrlTrap {
58 CtrlVariable variable,
59 CtrlValue val
60} with {
Harald Weltefdfa0462017-12-10 18:09:40 +010061 variant "BEGIN('TRAP 0 ',,case_insensitive)"
Harald Weltea76c4bb2017-12-09 02:06:07 +010062 variant "SEPARATOR(' ',)"
63};
64
65type union CtrlMessage {
66 CtrlCommand cmd,
67 CtrlResponse resp,
68 CtrlError err,
69 CtrlTrap trap
Harald Welte16979762017-12-13 00:45:44 +010070} with { variant "BEGIN('')" };
Harald Weltea76c4bb2017-12-09 02:06:07 +010071
72external function enc_CtrlMessage(in CtrlMessage id) return charstring
73 with { extension "prototype(convert) encode(TEXT)"};
74
75external function dec_CtrlMessage(in charstring id) return CtrlMessage
76 with { extension "prototype(convert) decode(TEXT)"};
77
78
Harald Welte03c0e562017-12-09 02:55:12 +010079template CtrlMessage ts_CtrlMsgGet(CtrlId id, CtrlVariable variable) := {
80 cmd := {
81 verb := "GET",
82 id := id,
83 variable := variable,
84 val := omit
85 }
86};
87
88template CtrlMessage ts_CtrlMsgSet(CtrlId id, CtrlVariable variable, CtrlValue val) := {
89 cmd := {
90 verb := "SET",
91 id := id,
92 variable := variable,
Pau Espin Pedrol6bf63132019-06-07 15:37:36 +020093 val := val
Harald Welte03c0e562017-12-09 02:55:12 +010094 }
95}
96
Pau Espin Pedrol579cd7a2019-06-10 21:01:30 +020097template CtrlMessage ts_CtrlMsgTrap(CtrlVariable variable, template (omit) CtrlValue val := omit) := {
98 trap := {
99 variable := variable,
100 val := val
101 }
102}
103
104template 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
113template 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
122template CtrlMessage tr_CtrlMsgGet(template CtrlId id, template CtrlVariable variable := ?) := {
123 cmd := {
124 verb := "GET",
125 id := id,
126 variable := variable,
127 val := ?
128 }
129}
130
131template 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 Welte03c0e562017-12-09 02:55:12 +0100141template 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
150template 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
160template CtrlMessage tr_CtrlMsgTrap(template CtrlVariable variable := ?,
161 template CtrlValue val := ?) := {
162 trap := {
163 variable := variable,
164 val := val
165 }
166}
167
168template CtrlMessage tr_CtrlMsgError(template CtrlId id := ?, template CtrlReason reason := ?) := {
169 err := {
170 id := id,
171 reason := reason
172 }
173}
174
175
Harald Weltea76c4bb2017-12-09 02:06:07 +0100176} with { encode "TEXT" }