blob: 5c4527e5e12617a02b012bccd32e035c806a7150 [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
97template CtrlMessage tr_CtrlMsgGetRepl(template CtrlId id, template CtrlVariable variable := ?) := {
98 resp := {
99 verb := "GET_REPLY",
100 id := id,
101 variable := variable,
102 val := ?
103 }
104}
105
106template CtrlMessage tr_CtrlMsgSetRepl(template CtrlId id, template CtrlVariable variable := ?,
107 template CtrlValue val := ?) := {
108 resp := {
109 verb := "SET_REPLY",
110 id := id,
111 variable := variable,
112 val := val
113 }
114}
115
116template CtrlMessage tr_CtrlMsgTrap(template CtrlVariable variable := ?,
117 template CtrlValue val := ?) := {
118 trap := {
119 variable := variable,
120 val := val
121 }
122}
123
124template CtrlMessage tr_CtrlMsgError(template CtrlId id := ?, template CtrlReason reason := ?) := {
125 err := {
126 id := id,
127 reason := reason
128 }
129}
130
131
Harald Weltea76c4bb2017-12-09 02:06:07 +0100132} with { encode "TEXT" }