aboutsummaryrefslogtreecommitdiffstats
path: root/library/Osmocom_CTRL_Types.ttcn
blob: 36e67622341b67a2237a392123168c8712da6b49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
module Osmocom_CTRL_Types {

/* Definition of abstract types for the CTRL protocol as used in Osmocom.
 * Uses the TITAN "TEXT" codec to auto-generate encoder/decoder functions.
 *
 * (C) 2017-2018 by Harald Welte <laforge@gnumonks.org>
 * All rights reserved.
 *
 * Released under the terms of GNU General Public License, Version 2 or
 * (at your option) any later version.
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

type charstring CtrlVerb ("GET", "SET") with {
	/* see https://www.eclipse.org/forums/index.php/t/1088893/ on why this
	 * match expression is needed here */
	variant "TEXT_CODING(,convert=upper_case,'((GET)|(SET))',case_insensitive)"
};

type charstring CtrlReplyVerb ("GET_REPLY", "SET_REPLY") with {
	variant "TEXT_CODING(,convert=upper_case,'((GET_REPLY)|(SET_REPLY))',case_insensitive)"
};

type charstring CtrlId	(pattern "\d#(1,9)");
type charstring CtrlVariable (pattern "[^, \{\}\[\]\(\)<>\|~\\\^`'\"\?=;/\+&%$\#!]#(1,)");
type charstring CtrlValue (pattern "[^ ]#(0,)");
type charstring CtrlReason;


type record CtrlCommand {
	CtrlVerb	verb,
	CtrlId		id,
	CtrlVariable	variable,
	CtrlValue	val optional	/* only for SET */
} with {
	variant "SEPARATOR(' ',)"
};

type record CtrlResponse {
	CtrlReplyVerb	verb,
	CtrlId		id,
	CtrlVariable	variable,
	CtrlValue	val
} with {
	variant "SEPARATOR(' ',)"
};

type record CtrlError {
	CtrlId		id,
	CtrlReason	reason
} with {
	variant "BEGIN('ERROR ',,case_insensitive)"
	variant "SEPARATOR(' ',)"
};

type record CtrlTrap {
	CtrlVariable	variable,
	CtrlValue	val
} with {
	variant "BEGIN('TRAP 0 ',,case_insensitive)"
	variant "SEPARATOR(' ',)"
};

type union CtrlMessage {
	CtrlCommand	cmd,
	CtrlResponse	resp,
	CtrlError	err,
	CtrlTrap	trap
} with { variant "BEGIN('')" };

external function enc_CtrlMessage(in CtrlMessage id) return charstring
	with { extension "prototype(convert) encode(TEXT)"};

external function dec_CtrlMessage(in charstring id) return CtrlMessage
	with { extension "prototype(convert) decode(TEXT)"};


template CtrlMessage ts_CtrlMsgGet(CtrlId id, CtrlVariable variable) := {
	cmd := {
		verb := "GET",
		id := id,
		variable := variable,
		val := omit
	}
};

template CtrlMessage ts_CtrlMsgSet(CtrlId id, CtrlVariable variable, CtrlValue val) := {
	cmd := {
		verb := "SET",
		id := id,
		variable := variable,
		val := val
	}
}

template CtrlMessage ts_CtrlMsgTrap(CtrlVariable variable, template (omit) CtrlValue val := omit) := {
	trap := {
		variable := variable,
		val := val
	}
}

template CtrlMessage ts_CtrlMsgGetRepl(CtrlId id, CtrlVariable variable, CtrlValue val) := {
	resp := {
		verb := "GET_REPLY",
		id := id,
		variable := variable,
		val := val
	}
};

template CtrlMessage ts_CtrlMsgSetRepl(CtrlId id, CtrlVariable variable, CtrlValue val) := {
	resp := {
		verb := "SET_REPLY",
		id := id,
		variable := variable,
		val := val
	}
}

template CtrlMessage tr_CtrlMsgGet(template CtrlId id, template CtrlVariable variable := ?) := {
	cmd := {
		verb := "GET",
		id := id,
		variable := variable,
		val := omit
	}
}

template CtrlMessage tr_CtrlMsgSet(template CtrlId id, template CtrlVariable variable := ?,
			   template CtrlValue val := ?) := {
	cmd := {
		verb := "SET",
		id := id,
		variable := variable,
		val := val
	}
}

template CtrlMessage tr_CtrlMsgGetRepl(template CtrlId id, template CtrlVariable variable := ?) := {
	resp := {
		verb := "GET_REPLY",
		id := id,
		variable := variable,
		val := ?
	}
}

template CtrlMessage tr_CtrlMsgSetRepl(template CtrlId id, template CtrlVariable variable := ?,
			   template CtrlValue val := ?) := {
	resp := {
		verb := "SET_REPLY",
		id := id,
		variable := variable,
		val := val
	}
}

template CtrlMessage tr_CtrlMsgTrap(template CtrlVariable variable := ?,
			template CtrlValue val := ?) := {
	trap := {
		variable := variable,
		val := val
	}
}

template CtrlMessage tr_CtrlMsgError(template CtrlId id := ?, template CtrlReason reason := ?) := {
	err := {
		id := id,
		reason := reason
	}
}


} with { encode "TEXT" }