blob: 1d776689bb49541c5a65790d9822347074129fe8 [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 *
6 * (C) 2017 by Harald Welte <laforge@gnumonks.org>
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.
11 */
12
Harald Weltea76c4bb2017-12-09 02:06:07 +010013type charstring CtrlVerb ("GET", "SET") with {
14 /* see https://www.eclipse.org/forums/index.php/t/1088893/ on why this
15 * match expression is needed here */
Harald Weltefdfa0462017-12-10 18:09:40 +010016 variant "TEXT_CODING(,convert=upper_case,'((GET)|(SET))',case_insensitive)"
Harald Weltea76c4bb2017-12-09 02:06:07 +010017};
18
Harald Welte03c0e562017-12-09 02:55:12 +010019type charstring CtrlReplyVerb ("GET_REPLY", "SET_REPLY") with {
20 variant "TEXT_CODING(,convert=upper_case,'((GET_REPLY)|(SET_REPLY))',case_insensitive)"
Harald Weltea76c4bb2017-12-09 02:06:07 +010021};
22
23type charstring CtrlId (pattern "\d#(1,9)");
Harald Welte0ac46672017-12-09 14:19:58 +010024type charstring CtrlVariable (pattern "[^, \{\}\[\]\(\)<>\|~\\\^`'\"\?=;/\+&%$\#!]#(1,)");
25type charstring CtrlValue (pattern "[^ ]#(0,)");
Harald Weltea76c4bb2017-12-09 02:06:07 +010026type charstring CtrlReason;
27
28
29type record CtrlCommand {
30 CtrlVerb verb,
31 CtrlId id,
32 CtrlVariable variable,
33 CtrlValue val optional /* only for SET */
34} with {
35 variant "SEPARATOR(' ',)"
36};
37
38type record CtrlResponse {
Harald Welte03c0e562017-12-09 02:55:12 +010039 CtrlReplyVerb verb,
Harald Weltea76c4bb2017-12-09 02:06:07 +010040 CtrlId id,
41 CtrlVariable variable,
42 CtrlValue val
43} with {
Harald Weltea76c4bb2017-12-09 02:06:07 +010044 variant "SEPARATOR(' ',)"
45};
46
47type record CtrlError {
48 CtrlId id,
49 CtrlReason reason
50} with {
51 variant "BEGIN('ERROR ',,case_insensitive)"
52 variant "SEPARATOR(' ',)"
53};
54
55type record CtrlTrap {
56 CtrlVariable variable,
57 CtrlValue val
58} with {
Harald Weltefdfa0462017-12-10 18:09:40 +010059 variant "BEGIN('TRAP 0 ',,case_insensitive)"
Harald Weltea76c4bb2017-12-09 02:06:07 +010060 variant "SEPARATOR(' ',)"
61};
62
63type union CtrlMessage {
64 CtrlCommand cmd,
65 CtrlResponse resp,
66 CtrlError err,
67 CtrlTrap trap
Harald Welte16979762017-12-13 00:45:44 +010068} with { variant "BEGIN('')" };
Harald Weltea76c4bb2017-12-09 02:06:07 +010069
70external function enc_CtrlMessage(in CtrlMessage id) return charstring
71 with { extension "prototype(convert) encode(TEXT)"};
72
73external function dec_CtrlMessage(in charstring id) return CtrlMessage
74 with { extension "prototype(convert) decode(TEXT)"};
75
76
Harald Welte03c0e562017-12-09 02:55:12 +010077template CtrlMessage ts_CtrlMsgGet(CtrlId id, CtrlVariable variable) := {
78 cmd := {
79 verb := "GET",
80 id := id,
81 variable := variable,
82 val := omit
83 }
84};
85
86template CtrlMessage ts_CtrlMsgSet(CtrlId id, CtrlVariable variable, CtrlValue val) := {
87 cmd := {
88 verb := "SET",
89 id := id,
90 variable := variable,
91 val := omit
92 }
93}
94
95template CtrlMessage tr_CtrlMsgGetRepl(template CtrlId id, template CtrlVariable variable := ?) := {
96 resp := {
97 verb := "GET_REPLY",
98 id := id,
99 variable := variable,
100 val := ?
101 }
102}
103
104template CtrlMessage tr_CtrlMsgSetRepl(template CtrlId id, template CtrlVariable variable := ?,
105 template CtrlValue val := ?) := {
106 resp := {
107 verb := "SET_REPLY",
108 id := id,
109 variable := variable,
110 val := val
111 }
112}
113
114template CtrlMessage tr_CtrlMsgTrap(template CtrlVariable variable := ?,
115 template CtrlValue val := ?) := {
116 trap := {
117 variable := variable,
118 val := val
119 }
120}
121
122template CtrlMessage tr_CtrlMsgError(template CtrlId id := ?, template CtrlReason reason := ?) := {
123 err := {
124 id := id,
125 reason := reason
126 }
127}
128
129
Harald Weltea76c4bb2017-12-09 02:06:07 +0100130} with { encode "TEXT" }