blob: c00cdc6dcf8f31abf748fcf468f28c1c41c80bfa [file] [log] [blame]
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001/* A Media Gateway Control Protocol Media Gateway: RFC 3435 */
2/* The protocol implementation */
3
4/*
5 * (C) 2009-2012 by Holger Hans Peter Freyther <zecke@selfish.org>
6 * (C) 2009-2012 by On-Waves
7 * All Rights Reserved
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
18 *
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 *
22 */
23
24#include <ctype.h>
25#include <stdio.h>
26#include <stdlib.h>
27#include <time.h>
28#include <limits.h>
29#include <unistd.h>
30#include <errno.h>
31
32#include <osmocom/core/msgb.h>
33#include <osmocom/core/talloc.h>
34#include <osmocom/core/select.h>
35
Philipp Maier87bd9be2017-08-22 16:35:41 +020036#include <osmocom/mgcp/mgcp.h>
Neels Hofmeyr67793542017-09-08 04:25:16 +020037#include <osmocom/mgcp/mgcp_common.h>
Philipp Maier87bd9be2017-08-22 16:35:41 +020038#include <osmocom/mgcp/mgcp_internal.h>
39#include <osmocom/mgcp/mgcp_stat.h>
40#include <osmocom/mgcp/mgcp_msg.h>
41#include <osmocom/mgcp/mgcp_ep.h>
Neels Hofmeyrf83ec562017-09-07 19:18:40 +020042
43struct mgcp_request {
44 char *name;
Philipp Maier87bd9be2017-08-22 16:35:41 +020045 struct msgb *(*handle_request) (struct mgcp_parse_data * data);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +020046 char *debug_name;
47};
48
49#define MGCP_REQUEST(NAME, REQ, DEBUG_NAME) \
50 { .name = NAME, .handle_request = REQ, .debug_name = DEBUG_NAME },
51
52static struct msgb *handle_audit_endpoint(struct mgcp_parse_data *data);
53static struct msgb *handle_create_con(struct mgcp_parse_data *data);
54static struct msgb *handle_delete_con(struct mgcp_parse_data *data);
55static struct msgb *handle_modify_con(struct mgcp_parse_data *data);
56static struct msgb *handle_rsip(struct mgcp_parse_data *data);
57static struct msgb *handle_noti_req(struct mgcp_parse_data *data);
58
Philipp Maier87bd9be2017-08-22 16:35:41 +020059/* Initalize transcoder */
60static int setup_rtp_processing(struct mgcp_endpoint *endp,
61 struct mgcp_conn_rtp *conn)
Neels Hofmeyrf83ec562017-09-07 19:18:40 +020062{
Philipp Maier87bd9be2017-08-22 16:35:41 +020063 struct mgcp_config *cfg = endp->cfg;
64 struct mgcp_conn_rtp *conn_src = NULL;
65 struct mgcp_conn_rtp *conn_dst = conn;
66 struct mgcp_conn *_conn;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +020067
Philipp Maier87bd9be2017-08-22 16:35:41 +020068 if (conn->type != MGCP_RTP_DEFAULT) {
69 LOGP(DLMGCP, LOGL_NOTICE,
70 "endpoint:%x RTP-setup: Endpoint is not configured as RTP default, stopping here!\n",
71 ENDPOINT_NUMBER(endp));
Neels Hofmeyrf83ec562017-09-07 19:18:40 +020072 return 0;
73 }
74
Philipp Maier87bd9be2017-08-22 16:35:41 +020075 if (conn->conn->mode == MGCP_CONN_LOOPBACK) {
76 LOGP(DLMGCP, LOGL_NOTICE,
77 "endpoint:%x RTP-setup: Endpoint is in loopback mode, stopping here!\n",
78 ENDPOINT_NUMBER(endp));
79 return 0;
80 }
81
82 /* Find the "sister" connection */
83 llist_for_each_entry(_conn, &endp->conns, entry) {
84 if (_conn->id != conn->conn->id) {
85 conn_src = &_conn->u.rtp;
86 break;
87 }
88 }
89
90 return cfg->setup_rtp_processing_cb(endp, &conn_dst->end,
91 &conn_src->end);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +020092}
93
Philipp Maier87bd9be2017-08-22 16:35:41 +020094/* array of function pointers for handling various
Neels Hofmeyrf83ec562017-09-07 19:18:40 +020095 * messages. In the future this might be binary sorted
Philipp Maier87bd9be2017-08-22 16:35:41 +020096 * for performance reasons. */
97static const struct mgcp_request mgcp_requests[] = {
Neels Hofmeyrf83ec562017-09-07 19:18:40 +020098 MGCP_REQUEST("AUEP", handle_audit_endpoint, "AuditEndpoint")
Philipp Maier87bd9be2017-08-22 16:35:41 +020099 MGCP_REQUEST("CRCX", handle_create_con, "CreateConnection")
100 MGCP_REQUEST("DLCX", handle_delete_con, "DeleteConnection")
101 MGCP_REQUEST("MDCX", handle_modify_con, "ModifiyConnection")
102 MGCP_REQUEST("RQNT", handle_noti_req, "NotificationRequest")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200103
Philipp Maier87bd9be2017-08-22 16:35:41 +0200104 /* SPEC extension */
105 MGCP_REQUEST("RSIP", handle_rsip, "ReSetInProgress")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200106};
107
Philipp Maier87bd9be2017-08-22 16:35:41 +0200108/* Helper function to allocate some memory for responses and retransmissions */
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200109static struct msgb *mgcp_msgb_alloc(void)
110{
111 struct msgb *msg;
112 msg = msgb_alloc_headroom(4096, 128, "MGCP msg");
113 if (!msg)
Philipp Maier87bd9be2017-08-22 16:35:41 +0200114 LOGP(DLMGCP, LOGL_ERROR, "Failed to msgb for MGCP data.\n");
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200115
116 return msg;
117}
118
Philipp Maier87bd9be2017-08-22 16:35:41 +0200119/* Helper function for do_retransmission() and create_resp() */
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200120static struct msgb *do_retransmission(const struct mgcp_endpoint *endp)
121{
122 struct msgb *msg = mgcp_msgb_alloc();
123 if (!msg)
124 return NULL;
125
126 msg->l2h = msgb_put(msg, strlen(endp->last_response));
127 memcpy(msg->l2h, endp->last_response, msgb_l2len(msg));
Philipp Maier87bd9be2017-08-22 16:35:41 +0200128 mgcp_disp_msg(msg->l2h, msgb_l2len(msg), "Retransmitted response");
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200129 return msg;
130}
131
132static struct msgb *create_resp(struct mgcp_endpoint *endp, int code,
133 const char *txt, const char *msg,
134 const char *trans, const char *param,
135 const char *sdp)
136{
137 int len;
138 struct msgb *res;
139
140 res = mgcp_msgb_alloc();
141 if (!res)
142 return NULL;
143
Philipp Maier87bd9be2017-08-22 16:35:41 +0200144 len = snprintf((char *)res->data, 2048, "%d %s%s%s\r\n%s",
145 code, trans, txt, param ? param : "", sdp ? sdp : "");
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200146 if (len < 0) {
147 LOGP(DLMGCP, LOGL_ERROR, "Failed to sprintf MGCP response.\n");
148 msgb_free(res);
149 return NULL;
150 }
151
152 res->l2h = msgb_put(res, len);
153 LOGP(DLMGCP, LOGL_DEBUG, "Generated response: code=%d\n", code);
Philipp Maier87bd9be2017-08-22 16:35:41 +0200154 mgcp_disp_msg(res->l2h, msgb_l2len(res), "Generated response");
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200155
156 /*
157 * Remember the last transmission per endpoint.
158 */
159 if (endp) {
160 struct mgcp_trunk_config *tcfg = endp->tcfg;
161 talloc_free(endp->last_response);
162 talloc_free(endp->last_trans);
163 endp->last_trans = talloc_strdup(tcfg->endpoints, trans);
164 endp->last_response = talloc_strndup(tcfg->endpoints,
Philipp Maier87bd9be2017-08-22 16:35:41 +0200165 (const char *)res->l2h,
166 msgb_l2len(res));
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200167 }
168
169 return res;
170}
171
172static struct msgb *create_ok_resp_with_param(struct mgcp_endpoint *endp,
Philipp Maier87bd9be2017-08-22 16:35:41 +0200173 int code, const char *msg,
174 const char *trans,
175 const char *param)
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200176{
177 return create_resp(endp, code, " OK", msg, trans, param, NULL);
178}
179
180static struct msgb *create_ok_response(struct mgcp_endpoint *endp,
Philipp Maier87bd9be2017-08-22 16:35:41 +0200181 int code, const char *msg,
182 const char *trans)
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200183{
184 return create_ok_resp_with_param(endp, code, msg, trans, NULL);
185}
186
187static struct msgb *create_err_response(struct mgcp_endpoint *endp,
Philipp Maier87bd9be2017-08-22 16:35:41 +0200188 int code, const char *msg,
189 const char *trans)
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200190{
191 return create_resp(endp, code, " FAIL", msg, trans, NULL, NULL);
192}
193
194static int write_response_sdp(struct mgcp_endpoint *endp,
Philipp Maier87bd9be2017-08-22 16:35:41 +0200195 struct mgcp_conn_rtp *conn,
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200196 char *sdp_record, size_t size, const char *addr)
197{
198 const char *fmtp_extra;
199 const char *audio_name;
200 int payload_type;
201 int len;
202 int nchars;
203
Philipp Maier87bd9be2017-08-22 16:35:41 +0200204 if (!conn)
205 return -1;
206
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200207 endp->cfg->get_net_downlink_format_cb(endp, &payload_type,
Philipp Maier87bd9be2017-08-22 16:35:41 +0200208 &audio_name, &fmtp_extra, conn);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200209
210 len = snprintf(sdp_record, size,
Philipp Maier87bd9be2017-08-22 16:35:41 +0200211 "v=0\r\n"
212 "o=- %u 23 IN IP4 %s\r\n"
213 "s=-\r\n"
214 "c=IN IP4 %s\r\n"
215 "t=0 0\r\n", conn->conn->id, addr, addr);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200216
217 if (len < 0 || len >= size)
218 goto buffer_too_small;
219
220 if (payload_type >= 0) {
221 nchars = snprintf(sdp_record + len, size - len,
222 "m=audio %d RTP/AVP %d\r\n",
Philipp Maier87bd9be2017-08-22 16:35:41 +0200223 conn->end.local_port, payload_type);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200224 if (nchars < 0 || nchars >= size - len)
225 goto buffer_too_small;
226
227 len += nchars;
228
229 if (audio_name && endp->tcfg->audio_send_name) {
230 nchars = snprintf(sdp_record + len, size - len,
231 "a=rtpmap:%d %s\r\n",
232 payload_type, audio_name);
233
234 if (nchars < 0 || nchars >= size - len)
235 goto buffer_too_small;
236
237 len += nchars;
238 }
239
240 if (fmtp_extra) {
241 nchars = snprintf(sdp_record + len, size - len,
242 "%s\r\n", fmtp_extra);
243
244 if (nchars < 0 || nchars >= size - len)
245 goto buffer_too_small;
246
247 len += nchars;
248 }
249 }
Philipp Maier87bd9be2017-08-22 16:35:41 +0200250 if (conn->end.packet_duration_ms > 0 && endp->tcfg->audio_send_ptime) {
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200251 nchars = snprintf(sdp_record + len, size - len,
Philipp Maier87bd9be2017-08-22 16:35:41 +0200252 "a=ptime:%u\r\n",
253 conn->end.packet_duration_ms);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200254 if (nchars < 0 || nchars >= size - len)
255 goto buffer_too_small;
256
257 len += nchars;
258 }
259
260 return len;
261
262buffer_too_small:
263 LOGP(DLMGCP, LOGL_ERROR, "SDP buffer too small: %zu (needed %d)\n",
264 size, len);
265 return -1;
266}
267
Philipp Maier87bd9be2017-08-22 16:35:41 +0200268/* Format MGCP response string (with SDP attached) */
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200269static struct msgb *create_response_with_sdp(struct mgcp_endpoint *endp,
Philipp Maier87bd9be2017-08-22 16:35:41 +0200270 struct mgcp_conn_rtp *conn,
271 const char *msg,
272 const char *trans_id)
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200273{
274 const char *addr = endp->cfg->local_ip;
275 char sdp_record[4096];
276 int len;
277 int nchars;
278 char osmux_extension[strlen("\nX-Osmux: 255") + 1];
279
280 if (!addr)
281 addr = mgcp_net_src_addr(endp);
282
Philipp Maier87bd9be2017-08-22 16:35:41 +0200283 if (conn->osmux.state == OSMUX_STATE_NEGOTIATING) {
284 sprintf(osmux_extension, "\nX-Osmux: %u", conn->osmux.cid);
285 conn->osmux.state = OSMUX_STATE_ACTIVATING;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200286 } else {
287 osmux_extension[0] = '\0';
288 }
289
290 len = snprintf(sdp_record, sizeof(sdp_record),
Philipp Maier87bd9be2017-08-22 16:35:41 +0200291 "I: %u%s\n\n", conn->conn->id, osmux_extension);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200292 if (len < 0)
293 return NULL;
294
Philipp Maier87bd9be2017-08-22 16:35:41 +0200295 nchars = write_response_sdp(endp, conn, sdp_record + len,
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200296 sizeof(sdp_record) - len - 1, addr);
297 if (nchars < 0)
298 return NULL;
299
300 len += nchars;
301
302 sdp_record[sizeof(sdp_record) - 1] = '\0';
303
304 return create_resp(endp, 200, " OK", msg, trans_id, NULL, sdp_record);
305}
306
Philipp Maier87bd9be2017-08-22 16:35:41 +0200307/* Send out dummy packet to keep the connection open, if the connection is an
308 * osmux connection, send the dummy packet via OSMUX */
309static void send_dummy(struct mgcp_endpoint *endp, struct mgcp_conn_rtp *conn)
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200310{
Philipp Maier87bd9be2017-08-22 16:35:41 +0200311 if (conn->osmux.state != OSMUX_STATE_DISABLED)
312 osmux_send_dummy(endp, conn);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200313 else
Philipp Maier87bd9be2017-08-22 16:35:41 +0200314 mgcp_send_dummy(endp, conn);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200315}
316
Philipp Maier87bd9be2017-08-22 16:35:41 +0200317/* handle incoming messages:
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200318 * - this can be a command (four letters, space, transaction id)
Philipp Maier87bd9be2017-08-22 16:35:41 +0200319 * - or a response (three numbers, space, transaction id) */
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200320struct msgb *mgcp_handle_message(struct mgcp_config *cfg, struct msgb *msg)
321{
322 struct mgcp_parse_data pdata;
323 int i, code, handled = 0;
324 struct msgb *resp = NULL;
325 char *data;
326
327 if (msgb_l2len(msg) < 4) {
328 LOGP(DLMGCP, LOGL_ERROR, "msg too short: %d\n", msg->len);
329 return NULL;
330 }
331
332 if (mgcp_msg_terminate_nul(msg))
333 return NULL;
334
Philipp Maier87bd9be2017-08-22 16:35:41 +0200335 mgcp_disp_msg(msg->l2h, msgb_l2len(msg), "Received message");
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200336
Philipp Maier87bd9be2017-08-22 16:35:41 +0200337 /* attempt to treat it as a response */
338 if (sscanf((const char *)&msg->l2h[0], "%3d %*s", &code) == 1) {
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200339 LOGP(DLMGCP, LOGL_DEBUG, "Response: Code: %d\n", code);
340 return NULL;
341 }
342
343 msg->l3h = &msg->l2h[4];
344
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200345 /*
346 * Check for a duplicate message and respond.
347 */
348 memset(&pdata, 0, sizeof(pdata));
349 pdata.cfg = cfg;
Philipp Maier87bd9be2017-08-22 16:35:41 +0200350 data = mgcp_strline((char *)msg->l3h, &pdata.save);
351 pdata.found = mgcp_parse_header(&pdata, data);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200352 if (pdata.endp && pdata.trans
Philipp Maier87bd9be2017-08-22 16:35:41 +0200353 && pdata.endp->last_trans
354 && strcmp(pdata.endp->last_trans, pdata.trans) == 0) {
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200355 return do_retransmission(pdata.endp);
356 }
357
358 for (i = 0; i < ARRAY_SIZE(mgcp_requests); ++i) {
Philipp Maier87bd9be2017-08-22 16:35:41 +0200359 if (strncmp
360 (mgcp_requests[i].name, (const char *)&msg->l2h[0],
361 4) == 0) {
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200362 handled = 1;
363 resp = mgcp_requests[i].handle_request(&pdata);
364 break;
365 }
366 }
367
368 if (!handled)
Philipp Maier87bd9be2017-08-22 16:35:41 +0200369 LOGP(DLMGCP, LOGL_NOTICE, "MSG with type: '%.4s' not handled\n",
370 &msg->l2h[0]);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200371
372 return resp;
373}
374
Philipp Maier87bd9be2017-08-22 16:35:41 +0200375/* AUEP command handler, processes the received command */
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200376static struct msgb *handle_audit_endpoint(struct mgcp_parse_data *p)
377{
Philipp Maier87bd9be2017-08-22 16:35:41 +0200378 LOGP(DLMGCP, LOGL_NOTICE, "AUEP: auditing endpoint ...\n");
379
380 if (p->found != 0) {
381 LOGP(DLMGCP, LOGL_ERROR,
382 "AUEP: failed to find the endpoint.\n");
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200383 return create_err_response(NULL, 500, "AUEP", p->trans);
Philipp Maier87bd9be2017-08-22 16:35:41 +0200384 } else
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200385 return create_ok_response(p->endp, 200, "AUEP", p->trans);
386}
387
Philipp Maier87bd9be2017-08-22 16:35:41 +0200388/* Try to find a free port by attemting to bind on it. Also handle the
389 * counter that points on the next free port. Since we have a pointer
390 * to the next free port, binding should work on the first attemt,
391 * neverless, try at least the next 200 ports before giving up */
392static int allocate_port(struct mgcp_endpoint *endp, struct mgcp_conn_rtp *conn)
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200393{
394 int i;
Philipp Maier87bd9be2017-08-22 16:35:41 +0200395 struct mgcp_rtp_end *end;
396 struct mgcp_port_range *range;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200397
Philipp Maier87bd9be2017-08-22 16:35:41 +0200398 OSMO_ASSERT(conn);
399 end = &conn->end;
400 OSMO_ASSERT(end);
401
402 range = &endp->cfg->net_ports;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200403
404 /* attempt to find a port */
405 for (i = 0; i < 200; ++i) {
406 int rc;
407
408 if (range->last_port >= range->range_end)
409 range->last_port = range->range_start;
410
Philipp Maier87bd9be2017-08-22 16:35:41 +0200411 rc = mgcp_bind_net_rtp_port(endp, range->last_port, conn);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200412
413 range->last_port += 2;
414 if (rc == 0) {
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200415 return 0;
416 }
417
418 }
419
Philipp Maier87bd9be2017-08-22 16:35:41 +0200420 LOGP(DLMGCP, LOGL_ERROR,
421 "Allocating a RTP/RTCP port failed 200 times 0x%x.\n",
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200422 ENDPOINT_NUMBER(endp));
423 return -1;
424}
425
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200426/* Set the LCO from a string (see RFC 3435).
Philipp Maier87bd9be2017-08-22 16:35:41 +0200427 * The string is stored in the 'string' field. A NULL string is handled excatlyy
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200428 * like an empty string, the 'string' field is never NULL after this function
429 * has been called. */
430static void set_local_cx_options(void *ctx, struct mgcp_lco *lco,
431 const char *options)
432{
433 char *p_opt, *a_opt;
434 char codec[9];
435
436 talloc_free(lco->string);
437 talloc_free(lco->codec);
438 lco->codec = NULL;
439 lco->pkt_period_min = lco->pkt_period_max = 0;
440 lco->string = talloc_strdup(ctx, options ? options : "");
441
442 p_opt = strstr(lco->string, "p:");
443 if (p_opt && sscanf(p_opt, "p:%d-%d",
444 &lco->pkt_period_min, &lco->pkt_period_max) == 1)
445 lco->pkt_period_max = lco->pkt_period_min;
446
447 a_opt = strstr(lco->string, "a:");
448 if (a_opt && sscanf(a_opt, "a:%8[^,]", codec) == 1)
449 lco->codec = talloc_strdup(ctx, codec);
Philipp Maier87bd9be2017-08-22 16:35:41 +0200450
451 LOGP(DLMGCP, LOGL_DEBUG,
452 "local CX options: lco->pkt_period_max: %i, lco->codec: %s\n",
453 lco->pkt_period_max, lco->codec);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200454}
455
456void mgcp_rtp_end_config(struct mgcp_endpoint *endp, int expect_ssrc_change,
457 struct mgcp_rtp_end *rtp)
458{
459 struct mgcp_trunk_config *tcfg = endp->tcfg;
460
461 int patch_ssrc = expect_ssrc_change && tcfg->force_constant_ssrc;
462
463 rtp->force_aligned_timing = tcfg->force_aligned_timing;
464 rtp->force_constant_ssrc = patch_ssrc ? 1 : 0;
465
466 LOGP(DLMGCP, LOGL_DEBUG,
467 "Configuring RTP endpoint: local port %d%s%s\n",
468 ntohs(rtp->rtp_port),
469 rtp->force_aligned_timing ? ", force constant timing" : "",
470 rtp->force_constant_ssrc ? ", force constant ssrc" : "");
471}
472
473uint32_t mgcp_rtp_packet_duration(struct mgcp_endpoint *endp,
474 struct mgcp_rtp_end *rtp)
475{
476 int f = 0;
477
478 /* Get the number of frames per channel and packet */
479 if (rtp->frames_per_packet)
480 f = rtp->frames_per_packet;
481 else if (rtp->packet_duration_ms && rtp->codec.frame_duration_num) {
482 int den = 1000 * rtp->codec.frame_duration_num;
Philipp Maier87bd9be2017-08-22 16:35:41 +0200483 f = (rtp->packet_duration_ms * rtp->codec.frame_duration_den +
484 den / 2)
485 / den;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200486 }
487
Philipp Maier87bd9be2017-08-22 16:35:41 +0200488 return rtp->codec.rate * f * rtp->codec.frame_duration_num /
489 rtp->codec.frame_duration_den;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200490}
491
492static int mgcp_osmux_setup(struct mgcp_endpoint *endp, const char *line)
493{
494 if (!endp->cfg->osmux_init) {
495 if (osmux_init(OSMUX_ROLE_BSC, endp->cfg) < 0) {
496 LOGP(DLMGCP, LOGL_ERROR, "Cannot init OSMUX\n");
497 return -1;
498 }
499 LOGP(DLMGCP, LOGL_NOTICE, "OSMUX socket has been set up\n");
500 }
501
502 return mgcp_parse_osmux_cid(line);
503}
504
Philipp Maier87bd9be2017-08-22 16:35:41 +0200505/* CRCX command handler, processes the received command */
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200506static struct msgb *handle_create_con(struct mgcp_parse_data *p)
507{
508 struct mgcp_trunk_config *tcfg;
509 struct mgcp_endpoint *endp = p->endp;
510 int error_code = 400;
511
512 const char *local_options = NULL;
513 const char *callid = NULL;
Philipp Maier87bd9be2017-08-22 16:35:41 +0200514 const char *ci = NULL;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200515 const char *mode = NULL;
516 char *line;
517 int have_sdp = 0, osmux_cid = -1;
Philipp Maier87bd9be2017-08-22 16:35:41 +0200518 struct mgcp_conn_rtp *conn = NULL;
519 uint32_t conn_id;
520 char conn_name[512];
521
522 LOGP(DLMGCP, LOGL_NOTICE, "CRCX: creating new connection ...\n");
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200523
524 if (p->found != 0)
525 return create_err_response(NULL, 510, "CRCX", p->trans);
526
527 /* parse CallID C: and LocalParameters L: */
528 for_each_line(line, p->save) {
529 if (!mgcp_check_param(endp, line))
530 continue;
531
532 switch (line[0]) {
533 case 'L':
Philipp Maier87bd9be2017-08-22 16:35:41 +0200534 local_options = (const char *)line + 3;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200535 break;
536 case 'C':
Philipp Maier87bd9be2017-08-22 16:35:41 +0200537 callid = (const char *)line + 3;
538 break;
539 case 'I':
540 ci = (const char *)line + 3;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200541 break;
542 case 'M':
Philipp Maier87bd9be2017-08-22 16:35:41 +0200543 mode = (const char *)line + 3;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200544 break;
545 case 'X':
Philipp Maier87bd9be2017-08-22 16:35:41 +0200546 /* If osmoux is disabled, just skip setting it up */
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200547 if (!p->endp->cfg->osmux)
548 break;
Philipp Maier87bd9be2017-08-22 16:35:41 +0200549 if (strncmp("Osmux: ", line + 2, strlen("Osmux: ")) ==
550 0)
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200551 osmux_cid = mgcp_osmux_setup(endp, line);
552 break;
553 case '\0':
554 have_sdp = 1;
555 goto mgcp_header_done;
556 default:
Philipp Maier87bd9be2017-08-22 16:35:41 +0200557 LOGP(DLMGCP, LOGL_NOTICE,
558 "CRCX: endpoint:%x unhandled option: '%c'/%d\n",
559 ENDPOINT_NUMBER(endp), *line, *line);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200560 break;
561 }
562 }
563
564mgcp_header_done:
565 tcfg = p->endp->tcfg;
566
Philipp Maier87bd9be2017-08-22 16:35:41 +0200567 /* Check parameters */
568 if (!callid) {
569 LOGP(DLMGCP, LOGL_ERROR,
570 "CRCX: endpoint:%x insufficient parameters, missing callid\n",
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200571 ENDPOINT_NUMBER(endp));
572 return create_err_response(endp, 400, "CRCX", p->trans);
573 }
574
Philipp Maier87bd9be2017-08-22 16:35:41 +0200575 if (!mode) {
576 LOGP(DLMGCP, LOGL_ERROR,
577 "CRCX: endpoint:%x insufficient parameters, missing mode\n",
578 ENDPOINT_NUMBER(endp));
579 return create_err_response(endp, 400, "CRCX", p->trans);
580 }
581
582 if (!ci) {
583 LOGP(DLMGCP, LOGL_ERROR,
584 "CRCX: endpoint:%x insufficient parameters, missing connection id\n",
585 ENDPOINT_NUMBER(endp));
586 return create_err_response(endp, 400, "CRCX", p->trans);
587 }
588
589 /* Check if we are able to accept the creation of another connection */
590 if (llist_count(&endp->conns) >= endp->type->max_conns) {
591 LOGP(DLMGCP, LOGL_ERROR,
592 "CRCX: endpoint:%x endpoint full, max. %i connections allowed!\n",
593 endp->type->max_conns, ENDPOINT_NUMBER(endp));
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200594 if (tcfg->force_realloc) {
Philipp Maier87bd9be2017-08-22 16:35:41 +0200595 /* There is no more room for a connection, make some
596 * room by blindly tossing the oldest of the two two
597 * connections */
598 mgcp_conn_free_oldest(endp);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200599 } else {
Philipp Maier87bd9be2017-08-22 16:35:41 +0200600 /* There is no more room for a connection, leave
601 * everything as it is and return with an error */
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200602 return create_err_response(endp, 400, "CRCX", p->trans);
603 }
604 }
605
Philipp Maier87bd9be2017-08-22 16:35:41 +0200606 /* Check if this endpoint already serves a call, if so, check if the
607 * callids match up so that we are sure that this is our call */
608 if (endp->callid && mgcp_verify_call_id(endp, callid)) {
609 LOGP(DLMGCP, LOGL_ERROR,
610 "CRCX: endpoint:%x allready seized by other call (%s)\n",
611 ENDPOINT_NUMBER(endp), endp->callid);
612 if (tcfg->force_realloc)
613 /* This is not our call, toss everything by releasing
614 * the entire endpoint. (rude!) */
615 mgcp_release_endp(endp);
616 else {
617 /* This is not our call, leave everything as it is and
618 * return with an error. */
619 return create_err_response(endp, 400, "CRCX", p->trans);
620 }
621 }
622
623 /* Set the callid, creation of another connection will only be possible
624 * when the callid matches up. (Connections are distinuished by their
625 * connection ids) */
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200626 endp->callid = talloc_strdup(tcfg->endpoints, callid);
627
Philipp Maier87bd9be2017-08-22 16:35:41 +0200628 /* Extract audio codec information */
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200629 set_local_cx_options(endp->tcfg->endpoints, &endp->local_options,
630 local_options);
631
Philipp Maier87bd9be2017-08-22 16:35:41 +0200632 if (mgcp_parse_ci(&conn_id, ci)) {
633 LOGP(DLMGCP, LOGL_ERROR,
634 "CRCX: endpoint:%x insufficient parameters, missing ci (connectionIdentifier)\n",
635 ENDPOINT_NUMBER(endp));
636 return create_err_response(endp, 400, "CRCX", p->trans);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200637 }
638
Philipp Maier87bd9be2017-08-22 16:35:41 +0200639 /* Only accept another connection when the connection ID is different. */
640 if (mgcp_conn_get_rtp(endp, conn_id)) {
641 LOGP(DLMGCP, LOGL_ERROR,
642 "CRCX: endpoint:%x there is already a connection with id %u present!\n",
643 conn_id, ENDPOINT_NUMBER(endp));
644 if (tcfg->force_realloc) {
645 /* Ignore the existing connection by just freeing it */
646 mgcp_conn_free(endp, conn_id);
647 } else {
648 /* There is already a connection with that ID present,
649 * leave everything as it is and return with an error. */
650 return create_err_response(endp, 400, "CRCX", p->trans);
651 }
652 }
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200653
Philipp Maier87bd9be2017-08-22 16:35:41 +0200654 snprintf(conn_name, sizeof(conn_name), "%s-%u", callid, conn_id);
655 mgcp_conn_alloc(NULL, endp, conn_id, MGCP_CONN_TYPE_RTP,
656 conn_name);
657 conn = mgcp_conn_get_rtp(endp, conn_id);
658 if (!conn) {
659 LOGP(DLMGCP, LOGL_ERROR,
660 "CRCX: endpoint:%x unable to allocate RTP connection\n",
661 ENDPOINT_NUMBER(endp));
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200662 goto error2;
663
Philipp Maier87bd9be2017-08-22 16:35:41 +0200664 }
665
666 if (mgcp_parse_conn_mode(mode, endp, conn->conn) != 0) {
667 error_code = 517;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200668 goto error2;
Philipp Maier87bd9be2017-08-22 16:35:41 +0200669 }
670
671 mgcp_rtp_end_config(endp, 0, &conn->end);
672
673 if (allocate_port(endp, conn) != 0) {
674 goto error2;
675 }
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200676
677 /* Annotate Osmux circuit ID and set it to negotiating state until this
Philipp Maier87bd9be2017-08-22 16:35:41 +0200678 * is fully set up from the dummy load. */
679 conn->osmux.state = OSMUX_STATE_DISABLED;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200680 if (osmux_cid >= 0) {
Philipp Maier87bd9be2017-08-22 16:35:41 +0200681 conn->osmux.cid = osmux_cid;
682 conn->osmux.state = OSMUX_STATE_NEGOTIATING;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200683 } else if (endp->cfg->osmux == OSMUX_USAGE_ONLY) {
684 LOGP(DLMGCP, LOGL_ERROR,
Philipp Maier87bd9be2017-08-22 16:35:41 +0200685 "CRCX: endpoint:%x osmux only and no osmux offered\n",
686 ENDPOINT_NUMBER(endp));
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200687 goto error2;
688 }
689
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200690 /* set up RTP media parameters */
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200691 if (have_sdp)
Philipp Maier87bd9be2017-08-22 16:35:41 +0200692 mgcp_parse_sdp_data(endp, &conn->end, p);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200693 else if (endp->local_options.codec)
Philipp Maier87bd9be2017-08-22 16:35:41 +0200694 mgcp_set_audio_info(p->cfg, &conn->end.codec,
695 PTYPE_UNDEFINED, endp->local_options.codec);
696 conn->end.fmtp_extra = talloc_strdup(tcfg->endpoints,
697 tcfg->audio_fmtp_extra);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200698
Philipp Maier87bd9be2017-08-22 16:35:41 +0200699 if (p->cfg->force_ptime) {
700 conn->end.packet_duration_ms = p->cfg->force_ptime;
701 conn->end.force_output_ptime = 1;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200702 }
703
Philipp Maier87bd9be2017-08-22 16:35:41 +0200704 if (setup_rtp_processing(endp, conn) != 0) {
705 LOGP(DLMGCP, LOGL_ERROR,
706 "CRCX: endpoint:%x could not start RTP processing!\n",
707 ENDPOINT_NUMBER(endp));
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200708 goto error2;
Philipp Maier87bd9be2017-08-22 16:35:41 +0200709 }
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200710
711 /* policy CB */
712 if (p->cfg->policy_cb) {
713 int rc;
714 rc = p->cfg->policy_cb(tcfg, ENDPOINT_NUMBER(endp),
Philipp Maier87bd9be2017-08-22 16:35:41 +0200715 MGCP_ENDP_CRCX, p->trans);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200716 switch (rc) {
717 case MGCP_POLICY_REJECT:
Philipp Maier87bd9be2017-08-22 16:35:41 +0200718 LOGP(DLMGCP, LOGL_NOTICE,
719 "CRCX: endpoint:%x CRCX rejected by policy\n",
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200720 ENDPOINT_NUMBER(endp));
721 mgcp_release_endp(endp);
722 return create_err_response(endp, 400, "CRCX", p->trans);
723 break;
724 case MGCP_POLICY_DEFER:
725 /* stop processing */
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200726 return NULL;
727 break;
728 case MGCP_POLICY_CONT:
729 /* just continue */
730 break;
731 }
732 }
733
Philipp Maier87bd9be2017-08-22 16:35:41 +0200734 LOGP(DLMGCP, LOGL_DEBUG,
735 "CRCX: endpoint:%x Creating connection: CI: %u port: %u\n",
736 ENDPOINT_NUMBER(endp), conn->conn->id, conn->end.local_port);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200737 if (p->cfg->change_cb)
738 p->cfg->change_cb(tcfg, ENDPOINT_NUMBER(endp), MGCP_ENDP_CRCX);
739
Philipp Maier87bd9be2017-08-22 16:35:41 +0200740 if (conn->conn->mode & MGCP_CONN_RECV_ONLY
741 && tcfg->keepalive_interval != 0) {
742 send_dummy(endp, conn);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200743 }
744
Philipp Maier87bd9be2017-08-22 16:35:41 +0200745 LOGP(DLMGCP, LOGL_NOTICE,
746 "CRCX: endpoint:%x connection successfully created\n",
747 ENDPOINT_NUMBER(endp));
748 return create_response_with_sdp(endp, conn, "CRCX", p->trans);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200749error2:
750 mgcp_release_endp(endp);
Philipp Maier87bd9be2017-08-22 16:35:41 +0200751 LOGP(DLMGCP, LOGL_NOTICE,
752 "CRCX: endpoint:%x unable to create connection resource error\n",
753 ENDPOINT_NUMBER(endp));
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200754 return create_err_response(endp, error_code, "CRCX", p->trans);
755}
756
Philipp Maier87bd9be2017-08-22 16:35:41 +0200757/* MDCX command handler, processes the received command */
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200758static struct msgb *handle_modify_con(struct mgcp_parse_data *p)
759{
760 struct mgcp_endpoint *endp = p->endp;
761 int error_code = 500;
762 int silent = 0;
763 int have_sdp = 0;
764 char *line;
Philipp Maier87bd9be2017-08-22 16:35:41 +0200765 const char *ci = NULL;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200766 const char *local_options = NULL;
Philipp Maier87bd9be2017-08-22 16:35:41 +0200767 const char *mode = NULL;
768 struct mgcp_conn_rtp *conn = NULL;
769 uint32_t conn_id;
770
771 LOGP(DLMGCP, LOGL_NOTICE, "MDCX: modifying existing connection ...\n");
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200772
773 if (p->found != 0)
774 return create_err_response(NULL, 510, "MDCX", p->trans);
775
Philipp Maier87bd9be2017-08-22 16:35:41 +0200776 if (llist_count(&endp->conns) <= 0) {
777 LOGP(DLMGCP, LOGL_ERROR,
778 "MDCX: endpoint:%x endpoint is not holding a connection.\n",
779 ENDPOINT_NUMBER(endp));
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200780 return create_err_response(endp, 400, "MDCX", p->trans);
781 }
782
783 for_each_line(line, p->save) {
784 if (!mgcp_check_param(endp, line))
785 continue;
786
787 switch (line[0]) {
Philipp Maier87bd9be2017-08-22 16:35:41 +0200788 case 'C':
789 if (mgcp_verify_call_id(endp, line + 3) != 0)
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200790 goto error3;
791 break;
Philipp Maier87bd9be2017-08-22 16:35:41 +0200792 case 'I':
793 ci = (const char *)line + 3;
794 if (mgcp_verify_ci(endp, ci) != 0)
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200795 goto error3;
796 break;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200797 case 'L':
Philipp Maier87bd9be2017-08-22 16:35:41 +0200798 local_options = (const char *)line + 3;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200799 break;
800 case 'M':
Philipp Maier87bd9be2017-08-22 16:35:41 +0200801 mode = (const char *)line + 3;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200802 break;
803 case 'Z':
804 silent = strcmp("noanswer", line + 3) == 0;
805 break;
806 case '\0':
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200807 have_sdp = 1;
Philipp Maier87bd9be2017-08-22 16:35:41 +0200808 goto mgcp_header_done;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200809 break;
810 default:
Philipp Maier87bd9be2017-08-22 16:35:41 +0200811 LOGP(DLMGCP, LOGL_NOTICE,
812 "MDCX: endpoint:%x Unhandled MGCP option: '%c'/%d\n",
813 ENDPOINT_NUMBER(endp), line[0], line[0]);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200814 break;
815 }
816 }
817
Philipp Maier87bd9be2017-08-22 16:35:41 +0200818mgcp_header_done:
819 if (mgcp_parse_ci(&conn_id, ci)) {
820 LOGP(DLMGCP, LOGL_ERROR,
821 "MDCX: endpoint:%x insufficient parameters, missing ci (connectionIdentifier)\n",
822 ENDPOINT_NUMBER(endp));
823 return create_err_response(endp, 400, "MDCX", p->trans);
824 }
825
826 conn = mgcp_conn_get_rtp(endp, conn_id);
827 if (!conn)
828 return create_err_response(endp, 400, "MDCX", p->trans);
829
830 if (mode) {
831 if (mgcp_parse_conn_mode(mode, endp, conn->conn) != 0) {
832 error_code = 517;
833 goto error3;
834 }
835 } else
836 conn->conn->mode = conn->conn->mode_orig;
837
838 if (have_sdp)
839 mgcp_parse_sdp_data(endp, &conn->end, p);
840
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200841 set_local_cx_options(endp->tcfg->endpoints, &endp->local_options,
842 local_options);
843
844 if (!have_sdp && endp->local_options.codec)
Philipp Maier87bd9be2017-08-22 16:35:41 +0200845 mgcp_set_audio_info(p->cfg, &conn->end.codec,
846 PTYPE_UNDEFINED, endp->local_options.codec);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200847
Philipp Maier87bd9be2017-08-22 16:35:41 +0200848 if (setup_rtp_processing(endp, conn) != 0)
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200849 goto error3;
850
Philipp Maier87bd9be2017-08-22 16:35:41 +0200851
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200852 /* policy CB */
853 if (p->cfg->policy_cb) {
854 int rc;
855 rc = p->cfg->policy_cb(endp->tcfg, ENDPOINT_NUMBER(endp),
Philipp Maier87bd9be2017-08-22 16:35:41 +0200856 MGCP_ENDP_MDCX, p->trans);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200857 switch (rc) {
858 case MGCP_POLICY_REJECT:
Philipp Maier87bd9be2017-08-22 16:35:41 +0200859 LOGP(DLMGCP, LOGL_NOTICE,
860 "MDCX: endpoint:%x rejected by policy\n",
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200861 ENDPOINT_NUMBER(endp));
862 if (silent)
863 goto out_silent;
864 return create_err_response(endp, 400, "MDCX", p->trans);
865 break;
866 case MGCP_POLICY_DEFER:
867 /* stop processing */
Philipp Maier87bd9be2017-08-22 16:35:41 +0200868 LOGP(DLMGCP, LOGL_DEBUG,
869 "MDCX: endpoint:%x defered by policy\n",
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200870 ENDPOINT_NUMBER(endp));
871 return NULL;
872 break;
873 case MGCP_POLICY_CONT:
874 /* just continue */
875 break;
876 }
877 }
878
Philipp Maier87bd9be2017-08-22 16:35:41 +0200879 mgcp_rtp_end_config(endp, 1, &conn->end);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200880
881 /* modify */
Philipp Maier87bd9be2017-08-22 16:35:41 +0200882 LOGP(DLMGCP, LOGL_DEBUG,
883 "MDCX: endpoint:%x modified conn:%s\n",
884 ENDPOINT_NUMBER(endp), mgcp_conn_dump(conn->conn));
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200885 if (p->cfg->change_cb)
Philipp Maier87bd9be2017-08-22 16:35:41 +0200886 p->cfg->change_cb(endp->tcfg, ENDPOINT_NUMBER(endp),
887 MGCP_ENDP_MDCX);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200888
Philipp Maier87bd9be2017-08-22 16:35:41 +0200889 if (conn->conn->mode & MGCP_CONN_RECV_ONLY &&
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200890 endp->tcfg->keepalive_interval != 0)
Philipp Maier87bd9be2017-08-22 16:35:41 +0200891 send_dummy(endp, conn);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200892
893 if (silent)
894 goto out_silent;
895
Philipp Maier87bd9be2017-08-22 16:35:41 +0200896 LOGP(DLMGCP, LOGL_NOTICE,
897 "MDCX: endpoint:%x connection successfully modified\n",
898 ENDPOINT_NUMBER(endp));
899 return create_response_with_sdp(endp, conn, "MDCX", p->trans);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200900error3:
901 return create_err_response(endp, error_code, "MDCX", p->trans);
902
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200903out_silent:
Philipp Maier87bd9be2017-08-22 16:35:41 +0200904 LOGP(DLMGCP, LOGL_DEBUG, "MDCX: endpoint:%x silent exit\n",
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200905 ENDPOINT_NUMBER(endp));
906 return NULL;
907}
908
Philipp Maier87bd9be2017-08-22 16:35:41 +0200909/* DLCX command handler, processes the received command */
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200910static struct msgb *handle_delete_con(struct mgcp_parse_data *p)
911{
912 struct mgcp_endpoint *endp = p->endp;
913 int error_code = 400;
914 int silent = 0;
915 char *line;
916 char stats[1048];
Philipp Maier87bd9be2017-08-22 16:35:41 +0200917 const char *ci = NULL;
918 struct mgcp_conn_rtp *conn = NULL;
919 uint32_t conn_id;
920
921 LOGP(DLMGCP, LOGL_NOTICE,
922 "DLCX: endpoint:%x deleting connection ...\n",
923 ENDPOINT_NUMBER(endp));
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200924
925 if (p->found != 0)
926 return create_err_response(NULL, error_code, "DLCX", p->trans);
927
Philipp Maier87bd9be2017-08-22 16:35:41 +0200928 if (llist_count(&endp->conns) <= 0) {
929 LOGP(DLMGCP, LOGL_ERROR,
930 "DLCX: endpoint:%x endpoint is not holding a connection.\n",
931 ENDPOINT_NUMBER(endp));
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200932 return create_err_response(endp, 400, "DLCX", p->trans);
933 }
934
935 for_each_line(line, p->save) {
936 if (!mgcp_check_param(endp, line))
937 continue;
938
939 switch (line[0]) {
940 case 'C':
Philipp Maier87bd9be2017-08-22 16:35:41 +0200941 if (mgcp_verify_call_id(endp, line + 3) != 0)
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200942 goto error3;
943 break;
944 case 'I':
Philipp Maier87bd9be2017-08-22 16:35:41 +0200945 ci = (const char *)line + 3;
946 if (mgcp_verify_ci(endp, ci) != 0)
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200947 goto error3;
948 break;
949 case 'Z':
950 silent = strcmp("noanswer", line + 3) == 0;
951 break;
952 default:
Philipp Maier87bd9be2017-08-22 16:35:41 +0200953 LOGP(DLMGCP, LOGL_NOTICE,
954 "DLCX: endpoint:%x Unhandled MGCP option: '%c'/%d\n",
955 ENDPOINT_NUMBER(endp), line[0], line[0]);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200956 break;
957 }
958 }
959
960 /* policy CB */
961 if (p->cfg->policy_cb) {
962 int rc;
963 rc = p->cfg->policy_cb(endp->tcfg, ENDPOINT_NUMBER(endp),
Philipp Maier87bd9be2017-08-22 16:35:41 +0200964 MGCP_ENDP_DLCX, p->trans);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200965 switch (rc) {
966 case MGCP_POLICY_REJECT:
Philipp Maier87bd9be2017-08-22 16:35:41 +0200967 LOGP(DLMGCP, LOGL_NOTICE,
968 "DLCX: endpoint:%x rejected by policy\n",
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200969 ENDPOINT_NUMBER(endp));
970 if (silent)
971 goto out_silent;
972 return create_err_response(endp, 400, "DLCX", p->trans);
973 break;
974 case MGCP_POLICY_DEFER:
975 /* stop processing */
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200976 return NULL;
977 break;
978 case MGCP_POLICY_CONT:
979 /* just continue */
980 break;
981 }
982 }
983
Philipp Maier87bd9be2017-08-22 16:35:41 +0200984 /* find the connection */
985 if (mgcp_parse_ci(&conn_id, ci)) {
986 LOGP(DLMGCP, LOGL_ERROR,
987 "DLCX: endpoint:%x insufficient parameters, missing ci (connectionIdentifier)\n",
988 ENDPOINT_NUMBER(endp));
989 return create_err_response(endp, 400, "DLCX", p->trans);
990 }
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200991
Philipp Maier87bd9be2017-08-22 16:35:41 +0200992 conn = mgcp_conn_get_rtp(endp, conn_id);
993 if (!conn)
994 goto error3;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200995
Philipp Maier87bd9be2017-08-22 16:35:41 +0200996 /* save the statistics of the current connection */
997 mgcp_format_stats(stats, sizeof(stats), conn->conn);
998
999 /* delete connection */
1000 LOGP(DLMGCP, LOGL_DEBUG, "DLCX: endpoint:%x deleting conn:%s\n",
1001 ENDPOINT_NUMBER(endp), mgcp_conn_dump(conn->conn));
1002 mgcp_conn_free(endp, conn_id);
1003 LOGP(DLMGCP, LOGL_NOTICE,
1004 "DLCX: endpoint:%x connection successfully deleted\n",
1005 ENDPOINT_NUMBER(endp));
1006
1007 /* When all connections are closed, the endpoint will be released
1008 * in order to be ready to be used by another call. */
1009 if (llist_count(&endp->conns) <= 0) {
1010 mgcp_release_endp(endp);
1011 LOGP(DLMGCP, LOGL_DEBUG,
1012 "DLCX: endpoint:%x endpoint released\n",
1013 ENDPOINT_NUMBER(endp));
1014 }
1015
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001016 if (p->cfg->change_cb)
Philipp Maier87bd9be2017-08-22 16:35:41 +02001017 p->cfg->change_cb(endp->tcfg, ENDPOINT_NUMBER(endp),
1018 MGCP_ENDP_DLCX);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001019
1020 if (silent)
1021 goto out_silent;
1022 return create_ok_resp_with_param(endp, 250, "DLCX", p->trans, stats);
1023
1024error3:
1025 return create_err_response(endp, error_code, "DLCX", p->trans);
1026
1027out_silent:
Philipp Maier87bd9be2017-08-22 16:35:41 +02001028 LOGP(DLMGCP, LOGL_DEBUG, "DLCX: endpoint:%x silent exit\n",
1029 ENDPOINT_NUMBER(endp));
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001030 return NULL;
1031}
1032
Philipp Maier87bd9be2017-08-22 16:35:41 +02001033/* RSIP command handler, processes the received command */
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001034static struct msgb *handle_rsip(struct mgcp_parse_data *p)
1035{
Philipp Maier87bd9be2017-08-22 16:35:41 +02001036 /* TODO: Also implement the resetting of a specific endpoint
1037 * to make mgcp_send_reset_ep() work. Currently this will call
1038 * mgcp_rsip_cb() in mgw_main.c, which sets reset_endpoints=1
1039 * to make read_call_agent() reset all endpoints when called
1040 * next time. In order to selectively reset endpoints some
1041 * mechanism to distinguish which endpoint shall be resetted
1042 * is needed */
1043
1044 LOGP(DLMGCP, LOGL_NOTICE, "RSIP: resetting all endpoints ...\n");
1045
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001046 if (p->found != 0) {
Philipp Maier87bd9be2017-08-22 16:35:41 +02001047 LOGP(DLMGCP, LOGL_ERROR,
1048 "RSIP: failed to find the endpoint.\n");
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001049 return NULL;
1050 }
1051
1052 if (p->cfg->reset_cb)
1053 p->cfg->reset_cb(p->endp->tcfg);
1054 return NULL;
1055}
1056
1057static char extract_tone(const char *line)
1058{
1059 const char *str = strstr(line, "D/");
1060 if (!str)
1061 return CHAR_MAX;
1062
1063 return str[2];
1064}
1065
Philipp Maier87bd9be2017-08-22 16:35:41 +02001066/* This can request like DTMF detection and forward, fax detection... it
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001067 * can also request when the notification should be send and such. We don't
Philipp Maier87bd9be2017-08-22 16:35:41 +02001068 * do this right now. */
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001069static struct msgb *handle_noti_req(struct mgcp_parse_data *p)
1070{
1071 int res = 0;
1072 char *line;
1073 char tone = CHAR_MAX;
1074
Philipp Maier87bd9be2017-08-22 16:35:41 +02001075 LOGP(DLMGCP, LOGL_NOTICE, "RQNT: processing request for notification ...\n");
1076
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001077 if (p->found != 0)
1078 return create_err_response(NULL, 400, "RQNT", p->trans);
1079
1080 for_each_line(line, p->save) {
1081 switch (line[0]) {
1082 case 'S':
1083 tone = extract_tone(line);
1084 break;
1085 }
1086 }
1087
1088 /* we didn't see a signal request with a tone */
1089 if (tone == CHAR_MAX)
1090 return create_ok_response(p->endp, 200, "RQNT", p->trans);
1091
1092 if (p->cfg->rqnt_cb)
1093 res = p->cfg->rqnt_cb(p->endp, tone);
1094
1095 return res == 0 ?
Philipp Maier87bd9be2017-08-22 16:35:41 +02001096 create_ok_response(p->endp, 200, "RQNT", p->trans) :
1097 create_err_response(p->endp, res, "RQNT", p->trans);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001098}
1099
Philipp Maier87bd9be2017-08-22 16:35:41 +02001100/* Connection keepalive timer, will take care that dummy packets are send
1101 * regulary, so that NAT connections stay open */
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001102static void mgcp_keepalive_timer_cb(void *_tcfg)
1103{
1104 struct mgcp_trunk_config *tcfg = _tcfg;
Philipp Maier87bd9be2017-08-22 16:35:41 +02001105 struct mgcp_conn *conn;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001106 int i;
Philipp Maier87bd9be2017-08-22 16:35:41 +02001107
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001108 LOGP(DLMGCP, LOGL_DEBUG, "Triggered trunk %d keepalive timer.\n",
1109 tcfg->trunk_nr);
1110
1111 if (tcfg->keepalive_interval <= 0)
1112 return;
1113
Philipp Maier87bd9be2017-08-22 16:35:41 +02001114 /* Send walk over all endpoints and send out dummy packets through
1115 * every connection present on each endpoint */
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001116 for (i = 1; i < tcfg->number_endpoints; ++i) {
1117 struct mgcp_endpoint *endp = &tcfg->endpoints[i];
Philipp Maier87bd9be2017-08-22 16:35:41 +02001118 llist_for_each_entry(conn, &endp->conns, entry) {
1119 if (conn->mode == MGCP_CONN_RECV_ONLY)
1120 send_dummy(endp, &conn->u.rtp);
1121 }
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001122 }
1123
1124 LOGP(DLMGCP, LOGL_DEBUG, "Rescheduling trunk %d keepalive timer.\n",
1125 tcfg->trunk_nr);
Philipp Maier87bd9be2017-08-22 16:35:41 +02001126 osmo_timer_schedule(&tcfg->keepalive_timer, tcfg->keepalive_interval,
1127 0);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001128}
1129
1130void mgcp_trunk_set_keepalive(struct mgcp_trunk_config *tcfg, int interval)
1131{
1132 tcfg->keepalive_interval = interval;
1133 osmo_timer_setup(&tcfg->keepalive_timer, mgcp_keepalive_timer_cb, tcfg);
1134
1135 if (interval <= 0)
1136 osmo_timer_del(&tcfg->keepalive_timer);
1137 else
1138 osmo_timer_schedule(&tcfg->keepalive_timer,
1139 tcfg->keepalive_interval, 0);
1140}
1141
Philipp Maier87bd9be2017-08-22 16:35:41 +02001142/*! allocate configuration with default values.
1143 * (called once at startup by main function) */
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001144struct mgcp_config *mgcp_config_alloc(void)
1145{
1146 struct mgcp_config *cfg;
1147
1148 cfg = talloc_zero(NULL, struct mgcp_config);
1149 if (!cfg) {
1150 LOGP(DLMGCP, LOGL_FATAL, "Failed to allocate config.\n");
1151 return NULL;
1152 }
1153
Philipp Maier87bd9be2017-08-22 16:35:41 +02001154 cfg->net_ports.range_start = RTP_PORT_DEFAULT_RANGE_START;
1155 cfg->net_ports.range_end = RTP_PORT_DEFAULT_RANGE_END;
1156 cfg->net_ports.last_port = cfg->net_ports.range_start;
1157
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001158 cfg->source_port = 2427;
1159 cfg->source_addr = talloc_strdup(cfg, "0.0.0.0");
1160 cfg->osmux_addr = talloc_strdup(cfg, "0.0.0.0");
1161
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001162 cfg->rtp_processing_cb = &mgcp_rtp_processing_default;
1163 cfg->setup_rtp_processing_cb = &mgcp_setup_rtp_processing_default;
1164
1165 cfg->get_net_downlink_format_cb = &mgcp_get_net_downlink_format_default;
1166
1167 /* default trunk handling */
1168 cfg->trunk.cfg = cfg;
1169 cfg->trunk.trunk_nr = 0;
1170 cfg->trunk.trunk_type = MGCP_TRUNK_VIRTUAL;
1171 cfg->trunk.audio_name = talloc_strdup(cfg, "AMR/8000");
1172 cfg->trunk.audio_payload = 126;
1173 cfg->trunk.audio_send_ptime = 1;
1174 cfg->trunk.audio_send_name = 1;
1175 cfg->trunk.omit_rtcp = 0;
1176 mgcp_trunk_set_keepalive(&cfg->trunk, MGCP_KEEPALIVE_ONCE);
1177
1178 INIT_LLIST_HEAD(&cfg->trunks);
1179
1180 return cfg;
1181}
1182
Philipp Maier87bd9be2017-08-22 16:35:41 +02001183/*! allocate configuration with default values.
1184 * (called once at startup by VTY)
1185 * \param[in] cfg mgcp configuration
1186 * \param[in] nr trunk number
1187 * \returns pointer to allocated trunk configuration */
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001188struct mgcp_trunk_config *mgcp_trunk_alloc(struct mgcp_config *cfg, int nr)
1189{
1190 struct mgcp_trunk_config *trunk;
1191
1192 trunk = talloc_zero(cfg, struct mgcp_trunk_config);
1193 if (!trunk) {
1194 LOGP(DLMGCP, LOGL_ERROR, "Failed to allocate.\n");
1195 return NULL;
1196 }
1197
1198 trunk->cfg = cfg;
1199 trunk->trunk_type = MGCP_TRUNK_E1;
1200 trunk->trunk_nr = nr;
1201 trunk->audio_name = talloc_strdup(cfg, "AMR/8000");
1202 trunk->audio_payload = 126;
1203 trunk->audio_send_ptime = 1;
1204 trunk->audio_send_name = 1;
1205 trunk->number_endpoints = 33;
1206 trunk->omit_rtcp = 0;
1207 mgcp_trunk_set_keepalive(trunk, MGCP_KEEPALIVE_ONCE);
1208 llist_add_tail(&trunk->entry, &cfg->trunks);
1209 return trunk;
1210}
1211
Philipp Maier87bd9be2017-08-22 16:35:41 +02001212/*! get trunk configuration by trunk number (index).
1213 * \param[in] cfg mgcp configuration
1214 * \param[in] index trunk number
1215 * \returns pointer to trunk configuration, NULL on error */
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001216struct mgcp_trunk_config *mgcp_trunk_num(struct mgcp_config *cfg, int index)
1217{
1218 struct mgcp_trunk_config *trunk;
1219
1220 llist_for_each_entry(trunk, &cfg->trunks, entry)
Philipp Maier87bd9be2017-08-22 16:35:41 +02001221 if (trunk->trunk_nr == index)
1222 return trunk;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001223
1224 return NULL;
1225}
1226
Philipp Maier87bd9be2017-08-22 16:35:41 +02001227/*! allocate endpoints and set default values.
1228 * (called once at startup by VTY)
1229 * \param[in] tcfg trunk configuration
1230 * \returns 0 on success, -1 on failure */
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001231int mgcp_endpoints_allocate(struct mgcp_trunk_config *tcfg)
1232{
1233 int i;
1234
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001235 tcfg->endpoints = _talloc_zero_array(tcfg->cfg,
Philipp Maier87bd9be2017-08-22 16:35:41 +02001236 sizeof(struct mgcp_endpoint),
1237 tcfg->number_endpoints,
1238 "endpoints");
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001239 if (!tcfg->endpoints)
1240 return -1;
1241
1242 for (i = 0; i < tcfg->number_endpoints; ++i) {
Philipp Maier87bd9be2017-08-22 16:35:41 +02001243 INIT_LLIST_HEAD(&tcfg->endpoints[i].conns);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001244 tcfg->endpoints[i].cfg = tcfg->cfg;
1245 tcfg->endpoints[i].tcfg = tcfg;
Philipp Maier87bd9be2017-08-22 16:35:41 +02001246
1247 /* NOTE: Currently all endpoints are of type RTP, this will
1248 * change when new variations are implemented */
1249 tcfg->endpoints[i].type = &ep_typeset.rtp;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001250 }
1251
1252 return 0;
1253}
1254
Philipp Maier87bd9be2017-08-22 16:35:41 +02001255/*! relase endpoint, all open connections are closed.
1256 * \param[in] endp endpoint to release */
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001257void mgcp_release_endp(struct mgcp_endpoint *endp)
1258{
Philipp Maier87bd9be2017-08-22 16:35:41 +02001259 LOGP(DLMGCP, LOGL_DEBUG, "Releasing endpoint:%x\n",
1260 ENDPOINT_NUMBER(endp));
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001261
Philipp Maier87bd9be2017-08-22 16:35:41 +02001262 /* Normally this function should only be called wehen
1263 * all connections have been removed already. In case
1264 * that there are still connections open (e.g. when
1265 * RSIP is executed), free them all at once. */
1266 mgcp_conn_free_all(endp);
1267
1268 /* Reset endpoint parameters and states */
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001269 talloc_free(endp->callid);
1270 endp->callid = NULL;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001271 talloc_free(endp->local_options.string);
1272 endp->local_options.string = NULL;
1273 talloc_free(endp->local_options.codec);
1274 endp->local_options.codec = NULL;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001275}
1276
1277static int send_agent(struct mgcp_config *cfg, const char *buf, int len)
1278{
1279 return write(cfg->gw_fd.bfd.fd, buf, len);
1280}
1281
Philipp Maier87bd9be2017-08-22 16:35:41 +02001282/*! Reset all endpoints by sending RSIP message to self.
1283 * (called by VTY)
1284 * \param[in] endp trunk endpoint
1285 * \param[in] endpoint number
1286 * \returns 0 on success, -1 on error */
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001287int mgcp_send_reset_all(struct mgcp_config *cfg)
1288{
Philipp Maier87bd9be2017-08-22 16:35:41 +02001289 int rc;
1290
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001291 static const char mgcp_reset[] = {
Philipp Maier87bd9be2017-08-22 16:35:41 +02001292 "RSIP 1 *@mgw MGCP 1.0\r\n"
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001293 };
1294
Philipp Maier87bd9be2017-08-22 16:35:41 +02001295 rc = send_agent(cfg, mgcp_reset, sizeof mgcp_reset - 1);
1296 if (rc <= 0)
1297 return -1;
1298
1299 return 0;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001300}
1301
Philipp Maier87bd9be2017-08-22 16:35:41 +02001302/*! Reset a single endpoint by sending RSIP message to self.
1303 * (called by VTY)
1304 * \param[in] endp trunk endpoint
1305 * \param[in] endpoint number
1306 * \returns 0 on success, -1 on error */
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001307int mgcp_send_reset_ep(struct mgcp_endpoint *endp, int endpoint)
1308{
1309 char buf[128];
1310 int len;
Philipp Maier87bd9be2017-08-22 16:35:41 +02001311 int rc;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001312
1313 len = snprintf(buf, sizeof(buf),
Philipp Maier87bd9be2017-08-22 16:35:41 +02001314 "RSIP 39 %x@mgw MGCP 1.0\r\n", endpoint);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001315 if (len < 0)
Philipp Maier87bd9be2017-08-22 16:35:41 +02001316 return -1;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001317
1318 buf[sizeof(buf) - 1] = '\0';
1319
Philipp Maier87bd9be2017-08-22 16:35:41 +02001320 rc = send_agent(endp->cfg, buf, len);
1321 if (rc <= 0)
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001322 return -1;
1323
Philipp Maier87bd9be2017-08-22 16:35:41 +02001324 return 0;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001325}