Harald Welte | 4029e8c | 2017-11-23 22:00:42 +0100 | [diff] [blame] | 1 | module MGCP_Templates { |
| 2 | |
Harald Welte | 35bb716 | 2018-01-03 21:07:52 +0100 | [diff] [blame] | 3 | /* 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 Welte | 4029e8c | 2017-11-23 22:00:42 +0100 | [diff] [blame] | 13 | 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 Welte | 363cb0a | 2018-01-30 19:35:53 +0100 | [diff] [blame] | 37 | /* 3.2.1.3 SpecificEndpointId */ |
| 38 | template MgcpParameter ts_MgcpParSpecEP(MgcpEndpoint ep) := { |
| 39 | code := "Z", |
| 40 | val := ep |
| 41 | }; |
| 42 | |
Harald Welte | 4029e8c | 2017-11-23 22:00:42 +0100 | [diff] [blame] | 43 | /* 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 Pedrol | b2c6b38 | 2019-05-14 13:40:49 +0200 | [diff] [blame] | 52 | /* 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 | |
Harald Welte | 4029e8c | 2017-11-23 22:00:42 +0100 | [diff] [blame] | 58 | /* osmo-bsc_mgcp implements L/C/M/X only, osmo-mgw adds 'I' */ |
| 59 | /* SDP: osmo-bsc_mgcp implements Tx of v,o,s,c,t,m,a */ |
| 60 | |
| 61 | template MgcpResponse tr_MgcpResp_Err(template MgcpResponseCode code) := { |
| 62 | line := { |
| 63 | code := code, |
| 64 | trans_id := ?, |
| 65 | string := ? |
| 66 | }, |
| 67 | params := {}, |
| 68 | sdp := omit |
| 69 | } |
| 70 | |
| 71 | template MgcpCommandLine t_MgcpCmdLine(template charstring verb, template MgcpTransId trans_id, template charstring ep) := { |
| 72 | verb := verb, |
| 73 | trans_id := trans_id, |
| 74 | ep := ep, |
| 75 | ver := "1.0" |
| 76 | }; |
| 77 | |
| 78 | template MgcpCommand ts_CRCX(MgcpTransId trans_id, charstring ep, MgcpConnectionMode mode, MgcpCallId call_id, template SDP_Message sdp := omit) := { |
| 79 | line := t_MgcpCmdLine("CRCX", trans_id, ep), |
| 80 | params := { |
| 81 | t_MgcpParConnMode(mode), |
| 82 | ts_MgcpParCallId(call_id), |
| 83 | //t_MgcpParReqId(omit), |
Daniel Willmann | fbef714 | 2017-11-30 13:16:14 +0100 | [diff] [blame] | 84 | t_MgcpParLocConnOpt("p:20, a:AMR") |
Harald Welte | 4029e8c | 2017-11-23 22:00:42 +0100 | [diff] [blame] | 85 | }, |
| 86 | sdp := sdp |
| 87 | } |
| 88 | |
Philipp Maier | 45635f4 | 2018-06-05 17:28:02 +0200 | [diff] [blame] | 89 | template MgcpCommand ts_CRCX_no_lco(MgcpTransId trans_id, charstring ep, MgcpConnectionMode mode, MgcpCallId call_id, template SDP_Message sdp := omit) := { |
| 90 | line := t_MgcpCmdLine("CRCX", trans_id, ep), |
| 91 | params := { |
| 92 | t_MgcpParConnMode(mode), |
| 93 | ts_MgcpParCallId(call_id) |
| 94 | }, |
| 95 | sdp := sdp |
| 96 | } |
| 97 | |
Pau Espin Pedrol | b2c6b38 | 2019-05-14 13:40:49 +0200 | [diff] [blame] | 98 | template MgcpCommand ts_CRCX_osmux(MgcpTransId trans_id, charstring ep, MgcpConnectionMode mode, MgcpCallId call_id, MgcpOsmuxCID osmux_cid, template SDP_Message sdp := omit) := { |
| 99 | line := t_MgcpCmdLine("CRCX", trans_id, ep), |
| 100 | params := { |
| 101 | t_MgcpParConnMode(mode), |
| 102 | ts_MgcpParCallId(call_id), |
| 103 | //t_MgcpParReqId(omit), |
| 104 | t_MgcpParLocConnOpt("p:20, a:AMR"), |
| 105 | ts_MgcpParOsmuxCID(osmux_cid) |
| 106 | }, |
| 107 | sdp := sdp |
| 108 | } |
| 109 | |
Harald Welte | 4017d55 | 2018-01-26 21:40:05 +0100 | [diff] [blame] | 110 | template MgcpCommand tr_CRCX(template MgcpEndpoint ep := ?) := { |
| 111 | line := t_MgcpCmdLine("CRCX", ?, ep), |
Harald Welte | 9002957 | 2017-11-24 23:39:50 +0100 | [diff] [blame] | 112 | params := *, |
| 113 | sdp := * |
| 114 | } |
| 115 | |
Harald Welte | 4029e8c | 2017-11-23 22:00:42 +0100 | [diff] [blame] | 116 | template MgcpResponse tr_CRCX_ACK := { |
| 117 | line := { |
| 118 | code := "200", |
Harald Welte | 51f34ad | 2017-11-24 20:40:43 +0100 | [diff] [blame] | 119 | trans_id := ?, |
Harald Welte | 4029e8c | 2017-11-23 22:00:42 +0100 | [diff] [blame] | 120 | string := "OK" |
| 121 | }, |
| 122 | params:= { { "I", ? }, *}, |
| 123 | sdp := ? |
| 124 | } |
| 125 | |
Pau Espin Pedrol | b2c6b38 | 2019-05-14 13:40:49 +0200 | [diff] [blame] | 126 | template MgcpResponse tr_CRCX_ACK_osmux := { |
| 127 | line := { |
| 128 | code := "200", |
| 129 | trans_id := ?, |
| 130 | string := "OK" |
| 131 | }, |
| 132 | params:= { { "I", ? }, {"X-OSMUX", ?}, *}, |
| 133 | sdp := ? |
| 134 | } |
| 135 | |
Harald Welte | 9002957 | 2017-11-24 23:39:50 +0100 | [diff] [blame] | 136 | template MgcpResponse ts_CRCX_ACK(MgcpTransId trans_id, MgcpConnectionId conn_id, template SDP_Message sdp := omit) := { |
| 137 | line := { |
| 138 | code := "200", |
| 139 | trans_id := trans_id, |
| 140 | string := "OK" |
| 141 | }, |
| 142 | params:= { ts_MgcpParConnectionId(conn_id) }, |
| 143 | sdp := sdp |
| 144 | } |
| 145 | |
Pau Espin Pedrol | c6a53db | 2019-05-20 19:31:47 +0200 | [diff] [blame] | 146 | template MgcpResponse ts_CRCX_ACK_osmux(MgcpTransId trans_id, MgcpConnectionId conn_id, MgcpOsmuxCID osmux_cid, template SDP_Message sdp := omit) := { |
| 147 | line := { |
| 148 | code := "200", |
| 149 | trans_id := trans_id, |
| 150 | string := "OK" |
| 151 | }, |
| 152 | params:= { |
| 153 | ts_MgcpParConnectionId(conn_id), |
| 154 | ts_MgcpParOsmuxCID(osmux_cid) |
| 155 | }, |
| 156 | sdp := sdp |
| 157 | } |
| 158 | |
Harald Welte | 4029e8c | 2017-11-23 22:00:42 +0100 | [diff] [blame] | 159 | template MgcpCommand ts_MDCX(MgcpTransId trans_id, charstring ep, MgcpConnectionMode mode, MgcpCallId call_id, MgcpConnectionId conn_id, template SDP_Message sdp := omit) := { |
| 160 | line := t_MgcpCmdLine("MDCX", trans_id, ep), |
| 161 | params := { |
| 162 | t_MgcpParConnMode(mode), |
| 163 | ts_MgcpParCallId(call_id), |
| 164 | ts_MgcpParConnectionId(conn_id), |
| 165 | //t_MgcpParReqId(omit), |
Daniel Willmann | fbef714 | 2017-11-30 13:16:14 +0100 | [diff] [blame] | 166 | t_MgcpParLocConnOpt("p:20, a:AMR") |
Harald Welte | 4029e8c | 2017-11-23 22:00:42 +0100 | [diff] [blame] | 167 | }, |
| 168 | sdp := sdp |
| 169 | } |
| 170 | |
Pau Espin Pedrol | b2c6b38 | 2019-05-14 13:40:49 +0200 | [diff] [blame] | 171 | 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) := { |
| 172 | line := t_MgcpCmdLine("MDCX", trans_id, ep), |
| 173 | params := { |
| 174 | t_MgcpParConnMode(mode), |
| 175 | ts_MgcpParCallId(call_id), |
| 176 | ts_MgcpParConnectionId(conn_id), |
| 177 | //t_MgcpParReqId(omit), |
| 178 | t_MgcpParLocConnOpt("p:20, a:AMR"), |
| 179 | ts_MgcpParOsmuxCID(osmux_cid) |
| 180 | }, |
| 181 | sdp := sdp |
| 182 | } |
| 183 | |
Harald Welte | 9002957 | 2017-11-24 23:39:50 +0100 | [diff] [blame] | 184 | template MgcpCommand tr_MDCX := { |
| 185 | line := t_MgcpCmdLine("MDCX", ?, ?), |
| 186 | params := *, |
| 187 | sdp := * |
| 188 | } |
| 189 | |
Harald Welte | bb7523b | 2018-03-29 08:52:01 +0200 | [diff] [blame] | 190 | template MgcpResponse tr_MDCX_ACK := { |
| 191 | line := { |
| 192 | code := "200", |
| 193 | trans_id := ?, |
| 194 | string := "OK" |
| 195 | }, |
| 196 | params := *, |
| 197 | sdp := ? |
| 198 | } |
| 199 | |
Harald Welte | 9002957 | 2017-11-24 23:39:50 +0100 | [diff] [blame] | 200 | 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 Pedrol | a65697d | 2019-05-21 12:54:39 +0200 | [diff] [blame] | 201 | 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 Welte | 9002957 | 2017-11-24 23:39:50 +0100 | [diff] [blame] | 202 | |
Harald Welte | 4029e8c | 2017-11-23 22:00:42 +0100 | [diff] [blame] | 203 | /* have a function that generates a template, rather than a template in order to handle |
| 204 | * optional parameters */ |
| 205 | function ts_DLCX(MgcpTransId trans_id, charstring ep, template MgcpCallId call_id := omit, |
| 206 | template MgcpConnectionId conn_id := omit) return template MgcpCommand { |
| 207 | var template MgcpCommand cmd; |
| 208 | cmd.line := t_MgcpCmdLine("DLCX", trans_id, ep); |
| 209 | cmd.params := {}; |
| 210 | cmd.sdp := omit; |
| 211 | if (isvalue(call_id)) { |
| 212 | f_mgcp_par_append(cmd.params, ts_MgcpParCallId(valueof(call_id))); |
| 213 | if (isvalue(conn_id)) { |
| 214 | f_mgcp_par_append(cmd.params, ts_MgcpParConnectionId(valueof(conn_id))); |
| 215 | } |
| 216 | } |
| 217 | return cmd; |
| 218 | } |
| 219 | |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 220 | template MgcpCommand tr_DLCX(template MgcpEndpoint ep := ?) := { |
| 221 | line := t_MgcpCmdLine("DLCX", ?, ep), |
Harald Welte | 9002957 | 2017-11-24 23:39:50 +0100 | [diff] [blame] | 222 | params := *, |
| 223 | sdp := * |
| 224 | } |
| 225 | |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 226 | template MgcpResponse tr_DLCX_ACK := { |
| 227 | line := { |
Daniel Willmann | 961e5c9 | 2017-11-30 16:37:40 +0100 | [diff] [blame] | 228 | code := ("200", "250"), |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 229 | trans_id := ?, |
| 230 | string := "OK" |
| 231 | }, |
| 232 | params:= *, |
| 233 | sdp := * |
| 234 | } |
| 235 | |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 236 | template MgcpResponse ts_DLCX_ACK2(MgcpTransId trans_id) := { |
| 237 | line := { |
| 238 | code := "250", |
| 239 | trans_id := trans_id, |
| 240 | string := "OK" |
| 241 | }, |
| 242 | params:= { /* list of ConnectionIDs */ }, |
| 243 | sdp := omit |
| 244 | } |
| 245 | |
| 246 | |
| 247 | |
Harald Welte | 9002957 | 2017-11-24 23:39:50 +0100 | [diff] [blame] | 248 | template MgcpResponse ts_DLCX_ACK(MgcpTransId trans_id, MgcpConnectionId conn_id, template SDP_Message sdp := omit) := ts_CRCX_ACK(trans_id, conn_id, sdp); |
| 249 | |
Harald Welte | e98bb2e | 2017-11-29 12:09:48 +0100 | [diff] [blame] | 250 | template MgcpCommand tr_RSIP := { |
| 251 | line := t_MgcpCmdLine("RSIP", ?, ?), |
| 252 | params := *, |
| 253 | sdp := * |
| 254 | } |
| 255 | |
Harald Welte | 4029e8c | 2017-11-23 22:00:42 +0100 | [diff] [blame] | 256 | /* SDP Templates */ |
| 257 | template SDP_Origin ts_SDP_origin(charstring addr, charstring session_id, |
| 258 | charstring session_version := "1", |
| 259 | charstring addr_type := "IP4", |
| 260 | charstring user_name := "-") := { |
| 261 | user_name := user_name, |
| 262 | session_id := session_id, |
| 263 | session_version := session_version, |
| 264 | net_type := "IN", |
| 265 | addr_type := addr_type, |
| 266 | addr := addr |
| 267 | } |
| 268 | |
| 269 | template SDP_connection ts_SDP_connection_IP(charstring addr, charstring addr_type := "IP4", |
| 270 | template integer ttl := omit, |
| 271 | template integer num_of_addr := omit) :={ |
| 272 | net_type := "IN", |
| 273 | addr_type := addr_type, |
| 274 | conn_addr := { |
| 275 | addr := addr, |
| 276 | ttl := ttl, |
| 277 | num_of_addr := num_of_addr |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | template SDP_time ts_SDP_time(charstring beg, charstring end) := { |
| 282 | time_field := { |
| 283 | start_time := beg, |
| 284 | stop_time := end |
| 285 | }, |
| 286 | time_repeat := omit |
| 287 | } |
| 288 | |
| 289 | template SDP_media_desc ts_SDP_media_desc(integer port_number, SDP_fmt_list fmts, |
| 290 | SDP_attribute_list attributes) := { |
| 291 | media_field := { |
| 292 | media := "audio", |
| 293 | ports := { |
| 294 | port_number := port_number, |
| 295 | num_of_ports := omit |
| 296 | }, |
| 297 | transport := "RTP/AVP", |
| 298 | fmts := fmts |
| 299 | }, |
| 300 | information := omit, |
| 301 | connections := omit, |
| 302 | bandwidth := omit, |
| 303 | key := omit, |
| 304 | attributes := attributes |
| 305 | } |
| 306 | |
| 307 | /* master template for generating SDP based in template arguments */ |
| 308 | template SDP_Message ts_SDP(charstring local_addr, charstring remote_addr, |
| 309 | charstring session_id, charstring session_version, |
| 310 | integer rtp_port, SDP_fmt_list fmts, |
| 311 | SDP_attribute_list attributes) := { |
| 312 | protocol_version := 0, |
| 313 | origin := ts_SDP_origin(local_addr, session_id, session_version), |
| 314 | session_name := "-", |
| 315 | information := omit, |
| 316 | uri := omit, |
| 317 | emails := omit, |
| 318 | phone_numbers := omit, |
| 319 | connection := ts_SDP_connection_IP(remote_addr), |
| 320 | bandwidth := omit, |
| 321 | times := { ts_SDP_time("0","0") }, |
| 322 | timezone_adjustments := omit, |
| 323 | key := omit, |
| 324 | attributes := omit, |
| 325 | media_list := { ts_SDP_media_desc(rtp_port, fmts, attributes) } |
| 326 | } |
| 327 | |
| 328 | template SDP_attribute ts_SDP_rtpmap(integer fmt, charstring val) := { |
| 329 | rtpmap := { |
| 330 | attr_value := int2str(fmt) & " " & val |
| 331 | } |
| 332 | } |
| 333 | template SDP_attribute ts_SDP_ptime(integer p) := { |
| 334 | ptime := { |
| 335 | attr_value := int2str(p) |
| 336 | } |
| 337 | } |
Philipp Maier | c8c0b40 | 2019-03-07 10:48:45 +0100 | [diff] [blame] | 338 | template SDP_attribute ts_SDP_fmtp(integer fmt, charstring val) := { |
| 339 | fmtp := { |
| 340 | attr_value := int2str(fmt) & " " & val |
| 341 | } |
| 342 | } |
Harald Welte | 4029e8c | 2017-11-23 22:00:42 +0100 | [diff] [blame] | 343 | |
Pau Espin Pedrol | b2c6b38 | 2019-05-14 13:40:49 +0200 | [diff] [blame] | 344 | /* -1 is wildcard, positive is translated as string */ |
| 345 | function f_mgcp_osmux_cid_encode(MgcpOsmuxCID osmux_cid) return charstring { |
| 346 | if (osmux_cid == -1) { |
| 347 | return "*"; |
| 348 | } |
| 349 | return int2str(osmux_cid); |
| 350 | } |
| 351 | |
| 352 | function f_mgcp_osmux_cid_decode(charstring osmux_cid) return MgcpOsmuxCID { |
| 353 | if (osmux_cid == "*") { |
| 354 | return -1; |
| 355 | } |
| 356 | return str2int(osmux_cid); |
| 357 | } |
| 358 | |
Neels Hofmeyr | 2ca1ab4 | 2019-03-08 03:45:43 +0100 | [diff] [blame] | 359 | function f_mgcp_contains_par(MgcpMessage msg, MgcpInfoCode code) return boolean { |
| 360 | var MgcpParameterList pars; |
| 361 | if (ischosen(msg.command)) { |
| 362 | pars := msg.command.params; |
| 363 | } else { |
| 364 | pars := msg.response.params; |
| 365 | } |
| 366 | for (var integer i := 0; i < lengthof(pars); i := i + 1) { |
| 367 | var MgcpParameter par := pars[i]; |
| 368 | if (par.code == code) { |
| 369 | return true; |
| 370 | } |
| 371 | } |
| 372 | return false; |
| 373 | } |
| 374 | |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 375 | function f_mgcp_extract_par(MgcpMessage msg, MgcpInfoCode code) return charstring { |
| 376 | var MgcpParameterList pars; |
| 377 | if (ischosen(msg.command)) { |
| 378 | pars := msg.command.params; |
| 379 | } else { |
| 380 | pars := msg.response.params; |
| 381 | } |
| 382 | for (var integer i := 0; i < lengthof(pars); i := i + 1) { |
| 383 | var MgcpParameter par := pars[i]; |
| 384 | if (par.code == code) { |
| 385 | return par.val; |
Harald Welte | 4c11d56 | 2017-11-24 23:39:00 +0100 | [diff] [blame] | 386 | } |
| 387 | } |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 388 | setverdict(fail, "Could not extract parameters for code ", code); |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 389 | return ""; |
| 390 | } |
| 391 | |
Harald Welte | 1fe7481 | 2018-01-29 21:57:26 +0100 | [diff] [blame] | 392 | function f_MgcpResp_extract_par(MgcpResponse resp, MgcpInfoCode code) return charstring { |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 393 | var MgcpMessage msg := { |
| 394 | response := resp |
| 395 | } |
Harald Welte | 1fe7481 | 2018-01-29 21:57:26 +0100 | [diff] [blame] | 396 | return f_mgcp_extract_par(msg, code); |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 397 | } |
| 398 | |
Harald Welte | 1fe7481 | 2018-01-29 21:57:26 +0100 | [diff] [blame] | 399 | function f_MgcpCmd_extract_par(MgcpCommand cmd, MgcpInfoCode code) return charstring { |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 400 | var MgcpMessage msg := { |
| 401 | command := cmd |
| 402 | } |
Harald Welte | 1fe7481 | 2018-01-29 21:57:26 +0100 | [diff] [blame] | 403 | return f_mgcp_extract_par(msg, code); |
Harald Welte | 4c11d56 | 2017-11-24 23:39:00 +0100 | [diff] [blame] | 404 | } |
| 405 | |
Neels Hofmeyr | 2ca1ab4 | 2019-03-08 03:45:43 +0100 | [diff] [blame] | 406 | function f_MgcpCmd_contains_par(MgcpCommand cmd, MgcpInfoCode code) return boolean { |
| 407 | var MgcpMessage msg := { |
| 408 | command := cmd |
| 409 | } |
| 410 | return f_mgcp_contains_par(msg, code); |
| 411 | } |
| 412 | |
Harald Welte | 1fe7481 | 2018-01-29 21:57:26 +0100 | [diff] [blame] | 413 | function f_MgcpResp_extract_conn_id(MgcpResponse resp) return MgcpConnectionId { |
| 414 | return str2hex(f_MgcpResp_extract_par(resp, "I")); |
| 415 | } |
| 416 | |
| 417 | function f_MgcpCmd_extract_call_id(MgcpCommand cmd) return MgcpCallId { |
| 418 | return str2hex(f_MgcpCmd_extract_par(cmd, "C")); |
| 419 | } |
| 420 | |
| 421 | function f_MgcpCmd_extract_conn_id(MgcpCommand cmd) return MgcpConnectionId { |
| 422 | return str2hex(f_MgcpCmd_extract_par(cmd, "I")); |
| 423 | } |
| 424 | |
Pau Espin Pedrol | b2c6b38 | 2019-05-14 13:40:49 +0200 | [diff] [blame] | 425 | function f_MgcpCmd_extract_osmux_cid(MgcpCommand cmd) return MgcpOsmuxCID { |
| 426 | return f_mgcp_osmux_cid_decode(f_MgcpCmd_extract_par(cmd, "X-OSMUX")); |
| 427 | } |
| 428 | |
Harald Welte | 1fe7481 | 2018-01-29 21:57:26 +0100 | [diff] [blame] | 429 | |
Harald Welte | 4c11d56 | 2017-11-24 23:39:00 +0100 | [diff] [blame] | 430 | function f_mgcp_alloc_tid() return MgcpTransId { |
| 431 | return int2str(float2int(rnd()*2147483647.0)); |
| 432 | } |
| 433 | |
| 434 | function f_mgcp_alloc_call_id() return MgcpCallId { |
| 435 | return int2hex(float2int(rnd()*2147483647.0), 8); |
| 436 | } |
| 437 | |
| 438 | function f_mgcp_alloc_conn_id() return MgcpConnectionId { |
| 439 | return int2hex(float2int(rnd()*2147483647.0), 8); |
| 440 | } |
| 441 | |
Harald Welte | bb5a121 | 2018-01-26 10:34:44 +0100 | [diff] [blame] | 442 | /* those verbs that related to a connection (and hence have ConnectionId) */ |
| 443 | template MgcpVerb tr_MgcpVerb_ConnectionOriented := ("CRCX", "MDCX", "DLCX", "AUCX"); |
| 444 | /* entire command template matching only connection oriented verbs */ |
| 445 | template MgcpCommand tr_MgcpCommand_CO := { |
| 446 | line := { |
| 447 | verb := tr_MgcpVerb_ConnectionOriented, |
| 448 | trans_id := ?, |
| 449 | ep := ?, |
| 450 | ver := ? |
| 451 | }, |
| 452 | params := *, |
| 453 | sdp := * |
| 454 | } |
| 455 | |
Neels Hofmeyr | ac7526d | 2019-10-15 16:54:37 +0200 | [diff] [blame^] | 456 | function f_mgcp_find_param_entry(MgcpParameterList pars, MgcpInfoCode code, out charstring ret) |
| 457 | return boolean { |
| 458 | for (var integer i := 0; i < sizeof(pars); i := i+1) { |
| 459 | if (pars[i].code == code) { |
| 460 | ret := pars[i].val; |
| 461 | return true; |
| 462 | } |
| 463 | } |
| 464 | return false; |
| 465 | } |
| 466 | |
Harald Welte | 363cb0a | 2018-01-30 19:35:53 +0100 | [diff] [blame] | 467 | function f_mgcp_find_param(MgcpMessage msg, MgcpInfoCode code, out charstring ret) |
| 468 | return boolean { |
| 469 | var MgcpParameterList pars; |
| 470 | if (ischosen(msg.command)) { |
| 471 | pars := msg.command.params; |
| 472 | } else { |
| 473 | pars := msg.response.params; |
| 474 | } |
Neels Hofmeyr | ac7526d | 2019-10-15 16:54:37 +0200 | [diff] [blame^] | 475 | return f_mgcp_find_param_entry(pars, code, ret); |
Harald Welte | 363cb0a | 2018-01-30 19:35:53 +0100 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | /* template to determine if a MGCP endpoint is a wildcard endpoint */ |
| 479 | template charstring t_MGCP_EP_wildcard := (pattern "\*@*", pattern "rtpbridge/\*@*"); |
| 480 | |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 481 | |
Harald Welte | 4029e8c | 2017-11-23 22:00:42 +0100 | [diff] [blame] | 482 | } |