blob: 3a5f139cdf855b229c0e379d651662b566b675ef [file] [log] [blame]
Harald Welte4029e8c2017-11-23 22:00:42 +01001module MGCP_Templates {
2
Harald Welte35bb7162018-01-03 21:07:52 +01003/* MGCP Templates, building on top of MGCP_Types (Osmocom) and SDP_Types from Ericsson.
4 *
5 * (C) 2017 by Harald Welte <laforge@gnumonks.org>
6 * All rights reserved.
7 *
8 * Released under the terms of GNU General Public License, Version 2 or
9 * (at your option) any later version.
10 */
11
12
Harald Welte4029e8c2017-11-23 22:00:42 +010013 import from MGCP_Types all;
14 import from SDP_Types all;
15
16 function f_mgcp_par_append(inout template MgcpParameterList list, template MgcpParameter par) {
17 var integer len := lengthof(list);
18 list[len] := par;
19 }
20
21 /* 3.2.2.6 Connection Mode (sendonly, recvonly, sendrecv, confrnce, inactive, loopback,
22 * conttest, netwloop, netwtest) */
23 template MgcpParameter t_MgcpParConnMode(template MgcpConnectionMode mode) := { "M", mode };
24
25 /* 3.2.2.2 CallId: maximum 32 hex chars */
26 template MgcpParameter ts_MgcpParCallId(MgcpCallId cid) := {
27 code := "C",
28 val := hex2str(cid)
29 };
30
31 /* 3.2.2.18 RequestIdentifier: Maximum 32 hex chars */
32 template MgcpParameter ts_MgcpParReqId(MgcpRequestId rid) := {
33 code := "X",
34 val := hex2str(rid)
35 };
36
Harald Welte363cb0a2018-01-30 19:35:53 +010037 /* 3.2.1.3 SpecificEndpointId */
38 template MgcpParameter ts_MgcpParSpecEP(MgcpEndpoint ep) := {
39 code := "Z",
40 val := ep
41 };
42
Harald Welte4029e8c2017-11-23 22:00:42 +010043 /* 3.2.2.10: LocalConnectionOptions (codec, packetization, bandwidth, ToS, eco, gain, silence, ...) */
44 template MgcpParameter t_MgcpParLocConnOpt(template charstring lco) := { "L", lco };
45
46 /* 3.2.2.5: ConnectionId: maximum 32 hex chars */
47 template MgcpParameter ts_MgcpParConnectionId(MgcpConnectionId cid) := {
48 code := "I",
49 val := hex2str(cid)
50 };
51
Pau Espin Pedrolb2c6b382019-05-14 13:40:49 +020052 /* Osmocom extension: X-Osmux: {*,%u} */
53 template MgcpParameter ts_MgcpParOsmuxCID(MgcpOsmuxCID osmux_cid) := {
54 code := "X-OSMUX",
55 val := f_mgcp_osmux_cid_encode(osmux_cid)
56 };
57
Pau Espin Pedrolbefd3aa2020-09-21 10:54:42 +020058 /* Osmocom extension: X-Osmux: {*,%u} */
59 template MgcpParameter t_MgcpParOsmoIGN(template charstring val) := {
60 code := "X-OSMO-IGN",
61 val := val
62 };
63
Harald Welte4029e8c2017-11-23 22:00:42 +010064 /* osmo-bsc_mgcp implements L/C/M/X only, osmo-mgw adds 'I' */
65 /* SDP: osmo-bsc_mgcp implements Tx of v,o,s,c,t,m,a */
66
Vadim Yanitskiy87ebd0b2022-06-28 03:58:33 +070067 template (value) MgcpResponse
68 ts_MgcpResp_Err(template (value) MgcpTransId trans_id,
69 template (value) MgcpResponseCode code,
70 template (value) charstring string := "FAIL") := {
71 line := {
72 code := code,
73 trans_id := trans_id,
74 string := string
75 },
76 params := {},
77 sdp := omit
78 }
79 template MgcpResponse
80 tr_MgcpResp_Err(template (present) MgcpResponseCode code) := {
Harald Welte4029e8c2017-11-23 22:00:42 +010081 line := {
82 code := code,
83 trans_id := ?,
84 string := ?
85 },
86 params := {},
87 sdp := omit
88 }
89
90 template MgcpCommandLine t_MgcpCmdLine(template charstring verb, template MgcpTransId trans_id, template charstring ep) := {
91 verb := verb,
92 trans_id := trans_id,
93 ep := ep,
94 ver := "1.0"
95 };
96
Pau Espin Pedrolb26d4462023-06-15 11:38:02 +020097 template MgcpCommand ts_AUEP(MgcpTransId trans_id, charstring ep) := {
98 line := t_MgcpCmdLine("AUEP", trans_id, ep),
99 params := omit,
100 sdp := omit
101 }
102
103 template MgcpResponse tr_AUEP_ACK := {
104 line := {
105 code := "200",
106 trans_id := ?,
107 string := "OK"
108 },
109 params:= *,
110 sdp := omit
111 }
112
Harald Welte4029e8c2017-11-23 22:00:42 +0100113 template MgcpCommand ts_CRCX(MgcpTransId trans_id, charstring ep, MgcpConnectionMode mode, MgcpCallId call_id, template SDP_Message sdp := omit) := {
114 line := t_MgcpCmdLine("CRCX", trans_id, ep),
115 params := {
116 t_MgcpParConnMode(mode),
117 ts_MgcpParCallId(call_id),
118 //t_MgcpParReqId(omit),
Daniel Willmannfbef7142017-11-30 13:16:14 +0100119 t_MgcpParLocConnOpt("p:20, a:AMR")
Harald Welte4029e8c2017-11-23 22:00:42 +0100120 },
121 sdp := sdp
122 }
123
Philipp Maier45635f42018-06-05 17:28:02 +0200124 template MgcpCommand ts_CRCX_no_lco(MgcpTransId trans_id, charstring ep, MgcpConnectionMode mode, MgcpCallId call_id, template SDP_Message sdp := omit) := {
125 line := t_MgcpCmdLine("CRCX", trans_id, ep),
126 params := {
127 t_MgcpParConnMode(mode),
128 ts_MgcpParCallId(call_id)
129 },
130 sdp := sdp
131 }
132
Pau Espin Pedrolb2c6b382019-05-14 13:40:49 +0200133 template MgcpCommand ts_CRCX_osmux(MgcpTransId trans_id, charstring ep, MgcpConnectionMode mode, MgcpCallId call_id, MgcpOsmuxCID osmux_cid, template SDP_Message sdp := omit) := {
134 line := t_MgcpCmdLine("CRCX", trans_id, ep),
135 params := {
136 t_MgcpParConnMode(mode),
137 ts_MgcpParCallId(call_id),
138 //t_MgcpParReqId(omit),
139 t_MgcpParLocConnOpt("p:20, a:AMR"),
140 ts_MgcpParOsmuxCID(osmux_cid)
141 },
142 sdp := sdp
143 }
144
Daniel Willmannfdb48682022-02-08 16:22:59 +0100145 template MgcpCommand tr_CRCX(template MgcpEndpoint ep := ?, template SDP_Message sdp := *) := {
Harald Welte4017d552018-01-26 21:40:05 +0100146 line := t_MgcpCmdLine("CRCX", ?, ep),
Harald Welte90029572017-11-24 23:39:50 +0100147 params := *,
Daniel Willmannfdb48682022-02-08 16:22:59 +0100148 sdp := sdp
Harald Welte90029572017-11-24 23:39:50 +0100149 }
150
Harald Welte4029e8c2017-11-23 22:00:42 +0100151 template MgcpResponse tr_CRCX_ACK := {
152 line := {
153 code := "200",
Harald Welte51f34ad2017-11-24 20:40:43 +0100154 trans_id := ?,
Harald Welte4029e8c2017-11-23 22:00:42 +0100155 string := "OK"
156 },
157 params:= { { "I", ? }, *},
158 sdp := ?
159 }
160
Pau Espin Pedrolb2c6b382019-05-14 13:40:49 +0200161 template MgcpResponse tr_CRCX_ACK_osmux := {
162 line := {
163 code := "200",
164 trans_id := ?,
165 string := "OK"
166 },
167 params:= { { "I", ? }, {"X-OSMUX", ?}, *},
168 sdp := ?
169 }
170
Harald Welte90029572017-11-24 23:39:50 +0100171 template MgcpResponse ts_CRCX_ACK(MgcpTransId trans_id, MgcpConnectionId conn_id, template SDP_Message sdp := omit) := {
172 line := {
173 code := "200",
174 trans_id := trans_id,
175 string := "OK"
176 },
177 params:= { ts_MgcpParConnectionId(conn_id) },
178 sdp := sdp
179 }
180
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200181 template MgcpResponse ts_CRCX_ACK_osmux(MgcpTransId trans_id, MgcpConnectionId conn_id, MgcpOsmuxCID osmux_cid, template SDP_Message sdp := omit) := {
182 line := {
183 code := "200",
184 trans_id := trans_id,
185 string := "OK"
186 },
187 params:= {
188 ts_MgcpParConnectionId(conn_id),
189 ts_MgcpParOsmuxCID(osmux_cid)
190 },
191 sdp := sdp
192 }
193
Harald Welte4029e8c2017-11-23 22:00:42 +0100194 template MgcpCommand ts_MDCX(MgcpTransId trans_id, charstring ep, MgcpConnectionMode mode, MgcpCallId call_id, MgcpConnectionId conn_id, template SDP_Message sdp := omit) := {
195 line := t_MgcpCmdLine("MDCX", trans_id, ep),
196 params := {
197 t_MgcpParConnMode(mode),
198 ts_MgcpParCallId(call_id),
199 ts_MgcpParConnectionId(conn_id),
200 //t_MgcpParReqId(omit),
Daniel Willmannfbef7142017-11-30 13:16:14 +0100201 t_MgcpParLocConnOpt("p:20, a:AMR")
Harald Welte4029e8c2017-11-23 22:00:42 +0100202 },
203 sdp := sdp
204 }
205
Pau Espin Pedrolb2c6b382019-05-14 13:40:49 +0200206 template MgcpCommand ts_MDCX_osmux(MgcpTransId trans_id, charstring ep, MgcpConnectionMode mode, MgcpCallId call_id, MgcpConnectionId conn_id, MgcpOsmuxCID osmux_cid, template SDP_Message sdp := omit) := {
207 line := t_MgcpCmdLine("MDCX", trans_id, ep),
208 params := {
209 t_MgcpParConnMode(mode),
210 ts_MgcpParCallId(call_id),
211 ts_MgcpParConnectionId(conn_id),
212 //t_MgcpParReqId(omit),
213 t_MgcpParLocConnOpt("p:20, a:AMR"),
214 ts_MgcpParOsmuxCID(osmux_cid)
215 },
216 sdp := sdp
217 }
218
Daniel Willmannfdb48682022-02-08 16:22:59 +0100219 template MgcpCommand tr_MDCX(template SDP_Message sdp := *) := {
Harald Welte90029572017-11-24 23:39:50 +0100220 line := t_MgcpCmdLine("MDCX", ?, ?),
221 params := *,
Daniel Willmannfdb48682022-02-08 16:22:59 +0100222 sdp := sdp
Harald Welte90029572017-11-24 23:39:50 +0100223 }
224
Harald Weltebb7523b2018-03-29 08:52:01 +0200225 template MgcpResponse tr_MDCX_ACK := {
226 line := {
227 code := "200",
228 trans_id := ?,
229 string := "OK"
230 },
231 params := *,
232 sdp := ?
233 }
234
Harald Welte90029572017-11-24 23:39:50 +0100235 template MgcpResponse ts_MDCX_ACK(MgcpTransId trans_id, MgcpConnectionId conn_id, template SDP_Message sdp := omit) := ts_CRCX_ACK(trans_id, conn_id, sdp);
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200236 template MgcpResponse ts_MDCX_ACK_osmux(MgcpTransId trans_id, MgcpConnectionId conn_id, MgcpOsmuxCID osmux_cid, template SDP_Message sdp := omit) := ts_CRCX_ACK_osmux(trans_id, conn_id, osmux_cid, sdp);
Harald Welte90029572017-11-24 23:39:50 +0100237
Harald Welte4029e8c2017-11-23 22:00:42 +0100238 /* have a function that generates a template, rather than a template in order to handle
239 * optional parameters */
240 function ts_DLCX(MgcpTransId trans_id, charstring ep, template MgcpCallId call_id := omit,
241 template MgcpConnectionId conn_id := omit) return template MgcpCommand {
242 var template MgcpCommand cmd;
243 cmd.line := t_MgcpCmdLine("DLCX", trans_id, ep);
244 cmd.params := {};
245 cmd.sdp := omit;
246 if (isvalue(call_id)) {
247 f_mgcp_par_append(cmd.params, ts_MgcpParCallId(valueof(call_id)));
248 if (isvalue(conn_id)) {
249 f_mgcp_par_append(cmd.params, ts_MgcpParConnectionId(valueof(conn_id)));
250 }
251 }
252 return cmd;
253 }
254
Harald Welteb71901a2018-01-26 19:16:05 +0100255 template MgcpCommand tr_DLCX(template MgcpEndpoint ep := ?) := {
256 line := t_MgcpCmdLine("DLCX", ?, ep),
Harald Welte90029572017-11-24 23:39:50 +0100257 params := *,
258 sdp := *
259 }
260
Harald Weltec82eef42017-11-24 20:40:12 +0100261 template MgcpResponse tr_DLCX_ACK := {
262 line := {
Daniel Willmann961e5c92017-11-30 16:37:40 +0100263 code := ("200", "250"),
Harald Weltec82eef42017-11-24 20:40:12 +0100264 trans_id := ?,
265 string := "OK"
266 },
267 params:= *,
268 sdp := *
269 }
270
Harald Welteb71901a2018-01-26 19:16:05 +0100271 template MgcpResponse ts_DLCX_ACK2(MgcpTransId trans_id) := {
272 line := {
273 code := "250",
274 trans_id := trans_id,
275 string := "OK"
276 },
277 params:= { /* list of ConnectionIDs */ },
278 sdp := omit
279 }
280
281
282
Harald Welte90029572017-11-24 23:39:50 +0100283 template MgcpResponse ts_DLCX_ACK(MgcpTransId trans_id, MgcpConnectionId conn_id, template SDP_Message sdp := omit) := ts_CRCX_ACK(trans_id, conn_id, sdp);
284
Harald Weltee98bb2e2017-11-29 12:09:48 +0100285 template MgcpCommand tr_RSIP := {
286 line := t_MgcpCmdLine("RSIP", ?, ?),
287 params := *,
288 sdp := *
289 }
290
Harald Welte4029e8c2017-11-23 22:00:42 +0100291 /* SDP Templates */
292 template SDP_Origin ts_SDP_origin(charstring addr, charstring session_id,
293 charstring session_version := "1",
294 charstring addr_type := "IP4",
295 charstring user_name := "-") := {
296 user_name := user_name,
297 session_id := session_id,
298 session_version := session_version,
299 net_type := "IN",
300 addr_type := addr_type,
301 addr := addr
302 }
303
304 template SDP_connection ts_SDP_connection_IP(charstring addr, charstring addr_type := "IP4",
305 template integer ttl := omit,
306 template integer num_of_addr := omit) :={
307 net_type := "IN",
308 addr_type := addr_type,
309 conn_addr := {
310 addr := addr,
311 ttl := ttl,
312 num_of_addr := num_of_addr
313 }
314 }
315
Daniel Willmannfdb48682022-02-08 16:22:59 +0100316 template SDP_connection tr_SDP_connection_IP(template charstring addr, template charstring addr_type := ?,
317 template integer ttl := *,
318 template integer num_of_addr := *) := {
319 net_type := "IN",
320 addr_type := addr_type,
321 conn_addr := {
322 addr := addr,
323 ttl := ttl,
324 num_of_addr := num_of_addr
325 }
326 }
327
Harald Welte4029e8c2017-11-23 22:00:42 +0100328 template SDP_time ts_SDP_time(charstring beg, charstring end) := {
329 time_field := {
330 start_time := beg,
331 stop_time := end
332 },
333 time_repeat := omit
334 }
335
336 template SDP_media_desc ts_SDP_media_desc(integer port_number, SDP_fmt_list fmts,
337 SDP_attribute_list attributes) := {
338 media_field := {
339 media := "audio",
340 ports := {
341 port_number := port_number,
342 num_of_ports := omit
343 },
344 transport := "RTP/AVP",
345 fmts := fmts
346 },
347 information := omit,
348 connections := omit,
349 bandwidth := omit,
350 key := omit,
351 attributes := attributes
352 }
353
Daniel Willmannfdb48682022-02-08 16:22:59 +0100354 template SDP_media_desc tr_SDP_media_desc(template integer port_number := ?,
355 template SDP_fmt_list fmts := ?,
356 template SDP_attribute_list attributes := ?) := {
357 media_field := {
358 media := "audio",
359 ports := {
360 port_number := port_number,
361 num_of_ports := omit
362 },
363 transport := "RTP/AVP",
364 fmts := fmts
365 },
366 information := *,
367 connections := *,
368 bandwidth := *,
369 key := *,
370 attributes := attributes
371 }
372
Harald Welte4029e8c2017-11-23 22:00:42 +0100373 /* master template for generating SDP based in template arguments */
374 template SDP_Message ts_SDP(charstring local_addr, charstring remote_addr,
375 charstring session_id, charstring session_version,
376 integer rtp_port, SDP_fmt_list fmts,
377 SDP_attribute_list attributes) := {
378 protocol_version := 0,
Pau Espin Pedrol384e9492020-09-03 17:05:19 +0200379 origin := ts_SDP_origin(local_addr, session_id, session_version, f_mgcp_addr2addrtype(local_addr)),
Harald Welte4029e8c2017-11-23 22:00:42 +0100380 session_name := "-",
381 information := omit,
382 uri := omit,
383 emails := omit,
384 phone_numbers := omit,
Pau Espin Pedrol384e9492020-09-03 17:05:19 +0200385 connection := ts_SDP_connection_IP(remote_addr, f_mgcp_addr2addrtype(remote_addr)),
Harald Welte4029e8c2017-11-23 22:00:42 +0100386 bandwidth := omit,
387 times := { ts_SDP_time("0","0") },
388 timezone_adjustments := omit,
389 key := omit,
390 attributes := omit,
391 media_list := { ts_SDP_media_desc(rtp_port, fmts, attributes) }
392 }
393
Daniel Willmannfdb48682022-02-08 16:22:59 +0100394 template SDP_Message tr_SDP(template charstring remote_addr := ?, template integer rtp_port := ?) := {
395 protocol_version := 0,
396 origin := ?,
397 session_name := ?,
398 information := *,
399 uri := *,
400 emails := *,
401 phone_numbers := *,
402 connection := tr_SDP_connection_IP(remote_addr, ?),
403 bandwidth := *,
404 times := ?,
405 timezone_adjustments := *,
406 key := *,
407 attributes := *,
408 media_list := { tr_SDP_media_desc(rtp_port) }
409 }
410
Harald Welte4029e8c2017-11-23 22:00:42 +0100411 template SDP_attribute ts_SDP_rtpmap(integer fmt, charstring val) := {
412 rtpmap := {
413 attr_value := int2str(fmt) & " " & val
414 }
415 }
416 template SDP_attribute ts_SDP_ptime(integer p) := {
417 ptime := {
418 attr_value := int2str(p)
419 }
420 }
Philipp Maierc8c0b402019-03-07 10:48:45 +0100421 template SDP_attribute ts_SDP_fmtp(integer fmt, charstring val) := {
422 fmtp := {
423 attr_value := int2str(fmt) & " " & val
424 }
425 }
Harald Welte4029e8c2017-11-23 22:00:42 +0100426
Pau Espin Pedrol384e9492020-09-03 17:05:19 +0200427 function f_mgcp_addr2addrtype(charstring addr) return charstring {
428 for (var integer i := 0; i < lengthof(addr); i := i + 1) {
429 if (addr[i] == ":") {
430 return "IP6";
431 }
432 }
433 return "IP4";
434 }
435
Pau Espin Pedrolb2c6b382019-05-14 13:40:49 +0200436 /* -1 is wildcard, positive is translated as string */
437 function f_mgcp_osmux_cid_encode(MgcpOsmuxCID osmux_cid) return charstring {
438 if (osmux_cid == -1) {
439 return "*";
440 }
441 return int2str(osmux_cid);
442 }
443
444 function f_mgcp_osmux_cid_decode(charstring osmux_cid) return MgcpOsmuxCID {
445 if (osmux_cid == "*") {
446 return -1;
447 }
448 return str2int(osmux_cid);
449 }
450
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100451 function f_mgcp_contains_par(MgcpMessage msg, MgcpInfoCode code) return boolean {
452 var MgcpParameterList pars;
453 if (ischosen(msg.command)) {
454 pars := msg.command.params;
455 } else {
456 pars := msg.response.params;
457 }
458 for (var integer i := 0; i < lengthof(pars); i := i + 1) {
459 var MgcpParameter par := pars[i];
460 if (par.code == code) {
461 return true;
462 }
463 }
464 return false;
465 }
466
Harald Welteb71901a2018-01-26 19:16:05 +0100467 function f_mgcp_extract_par(MgcpMessage msg, MgcpInfoCode code) return charstring {
468 var MgcpParameterList pars;
469 if (ischosen(msg.command)) {
470 pars := msg.command.params;
471 } else {
472 pars := msg.response.params;
473 }
474 for (var integer i := 0; i < lengthof(pars); i := i + 1) {
475 var MgcpParameter par := pars[i];
476 if (par.code == code) {
477 return par.val;
Harald Welte4c11d562017-11-24 23:39:00 +0100478 }
479 }
Daniel Willmanne4ff5372018-07-05 17:35:03 +0200480 setverdict(fail, "Could not extract parameters for code ", code);
Harald Welteb71901a2018-01-26 19:16:05 +0100481 return "";
482 }
483
Harald Welte1fe74812018-01-29 21:57:26 +0100484 function f_MgcpResp_extract_par(MgcpResponse resp, MgcpInfoCode code) return charstring {
Harald Welteb71901a2018-01-26 19:16:05 +0100485 var MgcpMessage msg := {
486 response := resp
487 }
Harald Welte1fe74812018-01-29 21:57:26 +0100488 return f_mgcp_extract_par(msg, code);
Harald Welteb71901a2018-01-26 19:16:05 +0100489 }
490
Harald Welte1fe74812018-01-29 21:57:26 +0100491 function f_MgcpCmd_extract_par(MgcpCommand cmd, MgcpInfoCode code) return charstring {
Harald Welteb71901a2018-01-26 19:16:05 +0100492 var MgcpMessage msg := {
493 command := cmd
494 }
Harald Welte1fe74812018-01-29 21:57:26 +0100495 return f_mgcp_extract_par(msg, code);
Harald Welte4c11d562017-11-24 23:39:00 +0100496 }
497
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100498 function f_MgcpCmd_contains_par(MgcpCommand cmd, MgcpInfoCode code) return boolean {
499 var MgcpMessage msg := {
500 command := cmd
501 }
502 return f_mgcp_contains_par(msg, code);
503 }
504
Harald Welte1fe74812018-01-29 21:57:26 +0100505 function f_MgcpResp_extract_conn_id(MgcpResponse resp) return MgcpConnectionId {
506 return str2hex(f_MgcpResp_extract_par(resp, "I"));
507 }
508
509 function f_MgcpCmd_extract_call_id(MgcpCommand cmd) return MgcpCallId {
510 return str2hex(f_MgcpCmd_extract_par(cmd, "C"));
511 }
512
513 function f_MgcpCmd_extract_conn_id(MgcpCommand cmd) return MgcpConnectionId {
514 return str2hex(f_MgcpCmd_extract_par(cmd, "I"));
515 }
516
Pau Espin Pedrolb2c6b382019-05-14 13:40:49 +0200517 function f_MgcpCmd_extract_osmux_cid(MgcpCommand cmd) return MgcpOsmuxCID {
518 return f_mgcp_osmux_cid_decode(f_MgcpCmd_extract_par(cmd, "X-OSMUX"));
519 }
520
Harald Welte1fe74812018-01-29 21:57:26 +0100521
Harald Welte4c11d562017-11-24 23:39:00 +0100522 function f_mgcp_alloc_tid() return MgcpTransId {
523 return int2str(float2int(rnd()*2147483647.0));
524 }
525
526 function f_mgcp_alloc_call_id() return MgcpCallId {
527 return int2hex(float2int(rnd()*2147483647.0), 8);
528 }
529
530 function f_mgcp_alloc_conn_id() return MgcpConnectionId {
531 return int2hex(float2int(rnd()*2147483647.0), 8);
532 }
533
Harald Weltebb5a1212018-01-26 10:34:44 +0100534 /* those verbs that related to a connection (and hence have ConnectionId) */
535 template MgcpVerb tr_MgcpVerb_ConnectionOriented := ("CRCX", "MDCX", "DLCX", "AUCX");
536 /* entire command template matching only connection oriented verbs */
537 template MgcpCommand tr_MgcpCommand_CO := {
538 line := {
539 verb := tr_MgcpVerb_ConnectionOriented,
540 trans_id := ?,
541 ep := ?,
542 ver := ?
543 },
544 params := *,
545 sdp := *
546 }
547
Neels Hofmeyrac7526d2019-10-15 16:54:37 +0200548 function f_mgcp_find_param_entry(MgcpParameterList pars, MgcpInfoCode code, out charstring ret)
549 return boolean {
550 for (var integer i := 0; i < sizeof(pars); i := i+1) {
551 if (pars[i].code == code) {
552 ret := pars[i].val;
553 return true;
554 }
555 }
556 return false;
557 }
558
Harald Welte363cb0a2018-01-30 19:35:53 +0100559 function f_mgcp_find_param(MgcpMessage msg, MgcpInfoCode code, out charstring ret)
560 return boolean {
561 var MgcpParameterList pars;
562 if (ischosen(msg.command)) {
563 pars := msg.command.params;
564 } else {
565 pars := msg.response.params;
566 }
Neels Hofmeyrac7526d2019-10-15 16:54:37 +0200567 return f_mgcp_find_param_entry(pars, code, ret);
Harald Welte363cb0a2018-01-30 19:35:53 +0100568 }
569
570 /* template to determine if a MGCP endpoint is a wildcard endpoint */
571 template charstring t_MGCP_EP_wildcard := (pattern "\*@*", pattern "rtpbridge/\*@*");
572
Harald Welteb71901a2018-01-26 19:16:05 +0100573
Harald Welte4029e8c2017-11-23 22:00:42 +0100574}