Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1 | /* 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 Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 36 | #include <osmocom/mgcp/mgcp.h> |
Neels Hofmeyr | 6779354 | 2017-09-08 04:25:16 +0200 | [diff] [blame^] | 37 | #include <osmocom/mgcp/mgcp_common.h> |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 38 | #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 Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 42 | |
| 43 | struct mgcp_request { |
| 44 | char *name; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 45 | struct msgb *(*handle_request) (struct mgcp_parse_data * data); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 46 | char *debug_name; |
| 47 | }; |
| 48 | |
| 49 | #define MGCP_REQUEST(NAME, REQ, DEBUG_NAME) \ |
| 50 | { .name = NAME, .handle_request = REQ, .debug_name = DEBUG_NAME }, |
| 51 | |
| 52 | static struct msgb *handle_audit_endpoint(struct mgcp_parse_data *data); |
| 53 | static struct msgb *handle_create_con(struct mgcp_parse_data *data); |
| 54 | static struct msgb *handle_delete_con(struct mgcp_parse_data *data); |
| 55 | static struct msgb *handle_modify_con(struct mgcp_parse_data *data); |
| 56 | static struct msgb *handle_rsip(struct mgcp_parse_data *data); |
| 57 | static struct msgb *handle_noti_req(struct mgcp_parse_data *data); |
| 58 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 59 | /* Initalize transcoder */ |
| 60 | static int setup_rtp_processing(struct mgcp_endpoint *endp, |
| 61 | struct mgcp_conn_rtp *conn) |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 62 | { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 63 | 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 Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 67 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 68 | 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 Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 72 | return 0; |
| 73 | } |
| 74 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 75 | 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 Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 92 | } |
| 93 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 94 | /* array of function pointers for handling various |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 95 | * messages. In the future this might be binary sorted |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 96 | * for performance reasons. */ |
| 97 | static const struct mgcp_request mgcp_requests[] = { |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 98 | MGCP_REQUEST("AUEP", handle_audit_endpoint, "AuditEndpoint") |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 99 | 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 Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 103 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 104 | /* SPEC extension */ |
| 105 | MGCP_REQUEST("RSIP", handle_rsip, "ReSetInProgress") |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 106 | }; |
| 107 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 108 | /* Helper function to allocate some memory for responses and retransmissions */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 109 | static struct msgb *mgcp_msgb_alloc(void) |
| 110 | { |
| 111 | struct msgb *msg; |
| 112 | msg = msgb_alloc_headroom(4096, 128, "MGCP msg"); |
| 113 | if (!msg) |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 114 | LOGP(DLMGCP, LOGL_ERROR, "Failed to msgb for MGCP data.\n"); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 115 | |
| 116 | return msg; |
| 117 | } |
| 118 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 119 | /* Helper function for do_retransmission() and create_resp() */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 120 | static 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 Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 128 | mgcp_disp_msg(msg->l2h, msgb_l2len(msg), "Retransmitted response"); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 129 | return msg; |
| 130 | } |
| 131 | |
| 132 | static 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 Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 144 | len = snprintf((char *)res->data, 2048, "%d %s%s%s\r\n%s", |
| 145 | code, trans, txt, param ? param : "", sdp ? sdp : ""); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 146 | 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 Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 154 | mgcp_disp_msg(res->l2h, msgb_l2len(res), "Generated response"); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 155 | |
| 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 Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 165 | (const char *)res->l2h, |
| 166 | msgb_l2len(res)); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | return res; |
| 170 | } |
| 171 | |
| 172 | static struct msgb *create_ok_resp_with_param(struct mgcp_endpoint *endp, |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 173 | int code, const char *msg, |
| 174 | const char *trans, |
| 175 | const char *param) |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 176 | { |
| 177 | return create_resp(endp, code, " OK", msg, trans, param, NULL); |
| 178 | } |
| 179 | |
| 180 | static struct msgb *create_ok_response(struct mgcp_endpoint *endp, |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 181 | int code, const char *msg, |
| 182 | const char *trans) |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 183 | { |
| 184 | return create_ok_resp_with_param(endp, code, msg, trans, NULL); |
| 185 | } |
| 186 | |
| 187 | static struct msgb *create_err_response(struct mgcp_endpoint *endp, |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 188 | int code, const char *msg, |
| 189 | const char *trans) |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 190 | { |
| 191 | return create_resp(endp, code, " FAIL", msg, trans, NULL, NULL); |
| 192 | } |
| 193 | |
| 194 | static int write_response_sdp(struct mgcp_endpoint *endp, |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 195 | struct mgcp_conn_rtp *conn, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 196 | 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 Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 204 | if (!conn) |
| 205 | return -1; |
| 206 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 207 | endp->cfg->get_net_downlink_format_cb(endp, &payload_type, |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 208 | &audio_name, &fmtp_extra, conn); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 209 | |
| 210 | len = snprintf(sdp_record, size, |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 211 | "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 Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 216 | |
| 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 Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 223 | conn->end.local_port, payload_type); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 224 | 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 Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 250 | if (conn->end.packet_duration_ms > 0 && endp->tcfg->audio_send_ptime) { |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 251 | nchars = snprintf(sdp_record + len, size - len, |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 252 | "a=ptime:%u\r\n", |
| 253 | conn->end.packet_duration_ms); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 254 | if (nchars < 0 || nchars >= size - len) |
| 255 | goto buffer_too_small; |
| 256 | |
| 257 | len += nchars; |
| 258 | } |
| 259 | |
| 260 | return len; |
| 261 | |
| 262 | buffer_too_small: |
| 263 | LOGP(DLMGCP, LOGL_ERROR, "SDP buffer too small: %zu (needed %d)\n", |
| 264 | size, len); |
| 265 | return -1; |
| 266 | } |
| 267 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 268 | /* Format MGCP response string (with SDP attached) */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 269 | static struct msgb *create_response_with_sdp(struct mgcp_endpoint *endp, |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 270 | struct mgcp_conn_rtp *conn, |
| 271 | const char *msg, |
| 272 | const char *trans_id) |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 273 | { |
| 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 Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 283 | 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 Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 286 | } else { |
| 287 | osmux_extension[0] = '\0'; |
| 288 | } |
| 289 | |
| 290 | len = snprintf(sdp_record, sizeof(sdp_record), |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 291 | "I: %u%s\n\n", conn->conn->id, osmux_extension); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 292 | if (len < 0) |
| 293 | return NULL; |
| 294 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 295 | nchars = write_response_sdp(endp, conn, sdp_record + len, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 296 | 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 Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 307 | /* Send out dummy packet to keep the connection open, if the connection is an |
| 308 | * osmux connection, send the dummy packet via OSMUX */ |
| 309 | static void send_dummy(struct mgcp_endpoint *endp, struct mgcp_conn_rtp *conn) |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 310 | { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 311 | if (conn->osmux.state != OSMUX_STATE_DISABLED) |
| 312 | osmux_send_dummy(endp, conn); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 313 | else |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 314 | mgcp_send_dummy(endp, conn); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 315 | } |
| 316 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 317 | /* handle incoming messages: |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 318 | * - this can be a command (four letters, space, transaction id) |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 319 | * - or a response (three numbers, space, transaction id) */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 320 | struct 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 Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 335 | mgcp_disp_msg(msg->l2h, msgb_l2len(msg), "Received message"); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 336 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 337 | /* attempt to treat it as a response */ |
| 338 | if (sscanf((const char *)&msg->l2h[0], "%3d %*s", &code) == 1) { |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 339 | LOGP(DLMGCP, LOGL_DEBUG, "Response: Code: %d\n", code); |
| 340 | return NULL; |
| 341 | } |
| 342 | |
| 343 | msg->l3h = &msg->l2h[4]; |
| 344 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 345 | /* |
| 346 | * Check for a duplicate message and respond. |
| 347 | */ |
| 348 | memset(&pdata, 0, sizeof(pdata)); |
| 349 | pdata.cfg = cfg; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 350 | data = mgcp_strline((char *)msg->l3h, &pdata.save); |
| 351 | pdata.found = mgcp_parse_header(&pdata, data); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 352 | if (pdata.endp && pdata.trans |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 353 | && pdata.endp->last_trans |
| 354 | && strcmp(pdata.endp->last_trans, pdata.trans) == 0) { |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 355 | return do_retransmission(pdata.endp); |
| 356 | } |
| 357 | |
| 358 | for (i = 0; i < ARRAY_SIZE(mgcp_requests); ++i) { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 359 | if (strncmp |
| 360 | (mgcp_requests[i].name, (const char *)&msg->l2h[0], |
| 361 | 4) == 0) { |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 362 | handled = 1; |
| 363 | resp = mgcp_requests[i].handle_request(&pdata); |
| 364 | break; |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | if (!handled) |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 369 | LOGP(DLMGCP, LOGL_NOTICE, "MSG with type: '%.4s' not handled\n", |
| 370 | &msg->l2h[0]); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 371 | |
| 372 | return resp; |
| 373 | } |
| 374 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 375 | /* AUEP command handler, processes the received command */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 376 | static struct msgb *handle_audit_endpoint(struct mgcp_parse_data *p) |
| 377 | { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 378 | 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 Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 383 | return create_err_response(NULL, 500, "AUEP", p->trans); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 384 | } else |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 385 | return create_ok_response(p->endp, 200, "AUEP", p->trans); |
| 386 | } |
| 387 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 388 | /* 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 */ |
| 392 | static int allocate_port(struct mgcp_endpoint *endp, struct mgcp_conn_rtp *conn) |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 393 | { |
| 394 | int i; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 395 | struct mgcp_rtp_end *end; |
| 396 | struct mgcp_port_range *range; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 397 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 398 | OSMO_ASSERT(conn); |
| 399 | end = &conn->end; |
| 400 | OSMO_ASSERT(end); |
| 401 | |
| 402 | range = &endp->cfg->net_ports; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 403 | |
| 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 Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 411 | rc = mgcp_bind_net_rtp_port(endp, range->last_port, conn); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 412 | |
| 413 | range->last_port += 2; |
| 414 | if (rc == 0) { |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 415 | return 0; |
| 416 | } |
| 417 | |
| 418 | } |
| 419 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 420 | LOGP(DLMGCP, LOGL_ERROR, |
| 421 | "Allocating a RTP/RTCP port failed 200 times 0x%x.\n", |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 422 | ENDPOINT_NUMBER(endp)); |
| 423 | return -1; |
| 424 | } |
| 425 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 426 | /* Set the LCO from a string (see RFC 3435). |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 427 | * The string is stored in the 'string' field. A NULL string is handled excatlyy |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 428 | * like an empty string, the 'string' field is never NULL after this function |
| 429 | * has been called. */ |
| 430 | static 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 Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 450 | |
| 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 Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | void 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 | |
| 473 | uint32_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 Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 483 | f = (rtp->packet_duration_ms * rtp->codec.frame_duration_den + |
| 484 | den / 2) |
| 485 | / den; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 486 | } |
| 487 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 488 | return rtp->codec.rate * f * rtp->codec.frame_duration_num / |
| 489 | rtp->codec.frame_duration_den; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | static 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 Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 505 | /* CRCX command handler, processes the received command */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 506 | static 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 Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 514 | const char *ci = NULL; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 515 | const char *mode = NULL; |
| 516 | char *line; |
| 517 | int have_sdp = 0, osmux_cid = -1; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 518 | 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 Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 523 | |
| 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 Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 534 | local_options = (const char *)line + 3; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 535 | break; |
| 536 | case 'C': |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 537 | callid = (const char *)line + 3; |
| 538 | break; |
| 539 | case 'I': |
| 540 | ci = (const char *)line + 3; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 541 | break; |
| 542 | case 'M': |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 543 | mode = (const char *)line + 3; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 544 | break; |
| 545 | case 'X': |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 546 | /* If osmoux is disabled, just skip setting it up */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 547 | if (!p->endp->cfg->osmux) |
| 548 | break; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 549 | if (strncmp("Osmux: ", line + 2, strlen("Osmux: ")) == |
| 550 | 0) |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 551 | osmux_cid = mgcp_osmux_setup(endp, line); |
| 552 | break; |
| 553 | case '\0': |
| 554 | have_sdp = 1; |
| 555 | goto mgcp_header_done; |
| 556 | default: |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 557 | LOGP(DLMGCP, LOGL_NOTICE, |
| 558 | "CRCX: endpoint:%x unhandled option: '%c'/%d\n", |
| 559 | ENDPOINT_NUMBER(endp), *line, *line); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 560 | break; |
| 561 | } |
| 562 | } |
| 563 | |
| 564 | mgcp_header_done: |
| 565 | tcfg = p->endp->tcfg; |
| 566 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 567 | /* Check parameters */ |
| 568 | if (!callid) { |
| 569 | LOGP(DLMGCP, LOGL_ERROR, |
| 570 | "CRCX: endpoint:%x insufficient parameters, missing callid\n", |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 571 | ENDPOINT_NUMBER(endp)); |
| 572 | return create_err_response(endp, 400, "CRCX", p->trans); |
| 573 | } |
| 574 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 575 | 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 Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 594 | if (tcfg->force_realloc) { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 595 | /* 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 Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 599 | } else { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 600 | /* There is no more room for a connection, leave |
| 601 | * everything as it is and return with an error */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 602 | return create_err_response(endp, 400, "CRCX", p->trans); |
| 603 | } |
| 604 | } |
| 605 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 606 | /* 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 Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 626 | endp->callid = talloc_strdup(tcfg->endpoints, callid); |
| 627 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 628 | /* Extract audio codec information */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 629 | set_local_cx_options(endp->tcfg->endpoints, &endp->local_options, |
| 630 | local_options); |
| 631 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 632 | 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 Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 637 | } |
| 638 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 639 | /* 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 Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 653 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 654 | 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 Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 662 | goto error2; |
| 663 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 664 | } |
| 665 | |
| 666 | if (mgcp_parse_conn_mode(mode, endp, conn->conn) != 0) { |
| 667 | error_code = 517; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 668 | goto error2; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 669 | } |
| 670 | |
| 671 | mgcp_rtp_end_config(endp, 0, &conn->end); |
| 672 | |
| 673 | if (allocate_port(endp, conn) != 0) { |
| 674 | goto error2; |
| 675 | } |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 676 | |
| 677 | /* Annotate Osmux circuit ID and set it to negotiating state until this |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 678 | * is fully set up from the dummy load. */ |
| 679 | conn->osmux.state = OSMUX_STATE_DISABLED; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 680 | if (osmux_cid >= 0) { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 681 | conn->osmux.cid = osmux_cid; |
| 682 | conn->osmux.state = OSMUX_STATE_NEGOTIATING; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 683 | } else if (endp->cfg->osmux == OSMUX_USAGE_ONLY) { |
| 684 | LOGP(DLMGCP, LOGL_ERROR, |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 685 | "CRCX: endpoint:%x osmux only and no osmux offered\n", |
| 686 | ENDPOINT_NUMBER(endp)); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 687 | goto error2; |
| 688 | } |
| 689 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 690 | /* set up RTP media parameters */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 691 | if (have_sdp) |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 692 | mgcp_parse_sdp_data(endp, &conn->end, p); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 693 | else if (endp->local_options.codec) |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 694 | 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 Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 698 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 699 | if (p->cfg->force_ptime) { |
| 700 | conn->end.packet_duration_ms = p->cfg->force_ptime; |
| 701 | conn->end.force_output_ptime = 1; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 702 | } |
| 703 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 704 | 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 Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 708 | goto error2; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 709 | } |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 710 | |
| 711 | /* policy CB */ |
| 712 | if (p->cfg->policy_cb) { |
| 713 | int rc; |
| 714 | rc = p->cfg->policy_cb(tcfg, ENDPOINT_NUMBER(endp), |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 715 | MGCP_ENDP_CRCX, p->trans); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 716 | switch (rc) { |
| 717 | case MGCP_POLICY_REJECT: |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 718 | LOGP(DLMGCP, LOGL_NOTICE, |
| 719 | "CRCX: endpoint:%x CRCX rejected by policy\n", |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 720 | 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 Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 726 | return NULL; |
| 727 | break; |
| 728 | case MGCP_POLICY_CONT: |
| 729 | /* just continue */ |
| 730 | break; |
| 731 | } |
| 732 | } |
| 733 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 734 | 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 Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 737 | if (p->cfg->change_cb) |
| 738 | p->cfg->change_cb(tcfg, ENDPOINT_NUMBER(endp), MGCP_ENDP_CRCX); |
| 739 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 740 | if (conn->conn->mode & MGCP_CONN_RECV_ONLY |
| 741 | && tcfg->keepalive_interval != 0) { |
| 742 | send_dummy(endp, conn); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 743 | } |
| 744 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 745 | 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 Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 749 | error2: |
| 750 | mgcp_release_endp(endp); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 751 | LOGP(DLMGCP, LOGL_NOTICE, |
| 752 | "CRCX: endpoint:%x unable to create connection resource error\n", |
| 753 | ENDPOINT_NUMBER(endp)); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 754 | return create_err_response(endp, error_code, "CRCX", p->trans); |
| 755 | } |
| 756 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 757 | /* MDCX command handler, processes the received command */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 758 | static 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 Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 765 | const char *ci = NULL; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 766 | const char *local_options = NULL; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 767 | 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 Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 772 | |
| 773 | if (p->found != 0) |
| 774 | return create_err_response(NULL, 510, "MDCX", p->trans); |
| 775 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 776 | 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 Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 780 | 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 Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 788 | case 'C': |
| 789 | if (mgcp_verify_call_id(endp, line + 3) != 0) |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 790 | goto error3; |
| 791 | break; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 792 | case 'I': |
| 793 | ci = (const char *)line + 3; |
| 794 | if (mgcp_verify_ci(endp, ci) != 0) |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 795 | goto error3; |
| 796 | break; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 797 | case 'L': |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 798 | local_options = (const char *)line + 3; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 799 | break; |
| 800 | case 'M': |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 801 | mode = (const char *)line + 3; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 802 | break; |
| 803 | case 'Z': |
| 804 | silent = strcmp("noanswer", line + 3) == 0; |
| 805 | break; |
| 806 | case '\0': |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 807 | have_sdp = 1; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 808 | goto mgcp_header_done; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 809 | break; |
| 810 | default: |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 811 | LOGP(DLMGCP, LOGL_NOTICE, |
| 812 | "MDCX: endpoint:%x Unhandled MGCP option: '%c'/%d\n", |
| 813 | ENDPOINT_NUMBER(endp), line[0], line[0]); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 814 | break; |
| 815 | } |
| 816 | } |
| 817 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 818 | mgcp_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 Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 841 | set_local_cx_options(endp->tcfg->endpoints, &endp->local_options, |
| 842 | local_options); |
| 843 | |
| 844 | if (!have_sdp && endp->local_options.codec) |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 845 | mgcp_set_audio_info(p->cfg, &conn->end.codec, |
| 846 | PTYPE_UNDEFINED, endp->local_options.codec); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 847 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 848 | if (setup_rtp_processing(endp, conn) != 0) |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 849 | goto error3; |
| 850 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 851 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 852 | /* policy CB */ |
| 853 | if (p->cfg->policy_cb) { |
| 854 | int rc; |
| 855 | rc = p->cfg->policy_cb(endp->tcfg, ENDPOINT_NUMBER(endp), |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 856 | MGCP_ENDP_MDCX, p->trans); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 857 | switch (rc) { |
| 858 | case MGCP_POLICY_REJECT: |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 859 | LOGP(DLMGCP, LOGL_NOTICE, |
| 860 | "MDCX: endpoint:%x rejected by policy\n", |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 861 | 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 Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 868 | LOGP(DLMGCP, LOGL_DEBUG, |
| 869 | "MDCX: endpoint:%x defered by policy\n", |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 870 | ENDPOINT_NUMBER(endp)); |
| 871 | return NULL; |
| 872 | break; |
| 873 | case MGCP_POLICY_CONT: |
| 874 | /* just continue */ |
| 875 | break; |
| 876 | } |
| 877 | } |
| 878 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 879 | mgcp_rtp_end_config(endp, 1, &conn->end); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 880 | |
| 881 | /* modify */ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 882 | LOGP(DLMGCP, LOGL_DEBUG, |
| 883 | "MDCX: endpoint:%x modified conn:%s\n", |
| 884 | ENDPOINT_NUMBER(endp), mgcp_conn_dump(conn->conn)); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 885 | if (p->cfg->change_cb) |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 886 | p->cfg->change_cb(endp->tcfg, ENDPOINT_NUMBER(endp), |
| 887 | MGCP_ENDP_MDCX); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 888 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 889 | if (conn->conn->mode & MGCP_CONN_RECV_ONLY && |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 890 | endp->tcfg->keepalive_interval != 0) |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 891 | send_dummy(endp, conn); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 892 | |
| 893 | if (silent) |
| 894 | goto out_silent; |
| 895 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 896 | 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 Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 900 | error3: |
| 901 | return create_err_response(endp, error_code, "MDCX", p->trans); |
| 902 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 903 | out_silent: |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 904 | LOGP(DLMGCP, LOGL_DEBUG, "MDCX: endpoint:%x silent exit\n", |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 905 | ENDPOINT_NUMBER(endp)); |
| 906 | return NULL; |
| 907 | } |
| 908 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 909 | /* DLCX command handler, processes the received command */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 910 | static 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 Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 917 | 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 Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 924 | |
| 925 | if (p->found != 0) |
| 926 | return create_err_response(NULL, error_code, "DLCX", p->trans); |
| 927 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 928 | 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 Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 932 | 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 Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 941 | if (mgcp_verify_call_id(endp, line + 3) != 0) |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 942 | goto error3; |
| 943 | break; |
| 944 | case 'I': |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 945 | ci = (const char *)line + 3; |
| 946 | if (mgcp_verify_ci(endp, ci) != 0) |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 947 | goto error3; |
| 948 | break; |
| 949 | case 'Z': |
| 950 | silent = strcmp("noanswer", line + 3) == 0; |
| 951 | break; |
| 952 | default: |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 953 | LOGP(DLMGCP, LOGL_NOTICE, |
| 954 | "DLCX: endpoint:%x Unhandled MGCP option: '%c'/%d\n", |
| 955 | ENDPOINT_NUMBER(endp), line[0], line[0]); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 956 | 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 Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 964 | MGCP_ENDP_DLCX, p->trans); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 965 | switch (rc) { |
| 966 | case MGCP_POLICY_REJECT: |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 967 | LOGP(DLMGCP, LOGL_NOTICE, |
| 968 | "DLCX: endpoint:%x rejected by policy\n", |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 969 | 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 Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 976 | return NULL; |
| 977 | break; |
| 978 | case MGCP_POLICY_CONT: |
| 979 | /* just continue */ |
| 980 | break; |
| 981 | } |
| 982 | } |
| 983 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 984 | /* 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 Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 991 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 992 | conn = mgcp_conn_get_rtp(endp, conn_id); |
| 993 | if (!conn) |
| 994 | goto error3; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 995 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 996 | /* 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 Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1016 | if (p->cfg->change_cb) |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1017 | p->cfg->change_cb(endp->tcfg, ENDPOINT_NUMBER(endp), |
| 1018 | MGCP_ENDP_DLCX); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1019 | |
| 1020 | if (silent) |
| 1021 | goto out_silent; |
| 1022 | return create_ok_resp_with_param(endp, 250, "DLCX", p->trans, stats); |
| 1023 | |
| 1024 | error3: |
| 1025 | return create_err_response(endp, error_code, "DLCX", p->trans); |
| 1026 | |
| 1027 | out_silent: |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1028 | LOGP(DLMGCP, LOGL_DEBUG, "DLCX: endpoint:%x silent exit\n", |
| 1029 | ENDPOINT_NUMBER(endp)); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1030 | return NULL; |
| 1031 | } |
| 1032 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1033 | /* RSIP command handler, processes the received command */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1034 | static struct msgb *handle_rsip(struct mgcp_parse_data *p) |
| 1035 | { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1036 | /* 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 Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1046 | if (p->found != 0) { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1047 | LOGP(DLMGCP, LOGL_ERROR, |
| 1048 | "RSIP: failed to find the endpoint.\n"); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1049 | return NULL; |
| 1050 | } |
| 1051 | |
| 1052 | if (p->cfg->reset_cb) |
| 1053 | p->cfg->reset_cb(p->endp->tcfg); |
| 1054 | return NULL; |
| 1055 | } |
| 1056 | |
| 1057 | static 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 Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1066 | /* This can request like DTMF detection and forward, fax detection... it |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1067 | * can also request when the notification should be send and such. We don't |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1068 | * do this right now. */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1069 | static 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 Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1075 | LOGP(DLMGCP, LOGL_NOTICE, "RQNT: processing request for notification ...\n"); |
| 1076 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1077 | 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 Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1096 | create_ok_response(p->endp, 200, "RQNT", p->trans) : |
| 1097 | create_err_response(p->endp, res, "RQNT", p->trans); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1098 | } |
| 1099 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1100 | /* Connection keepalive timer, will take care that dummy packets are send |
| 1101 | * regulary, so that NAT connections stay open */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1102 | static void mgcp_keepalive_timer_cb(void *_tcfg) |
| 1103 | { |
| 1104 | struct mgcp_trunk_config *tcfg = _tcfg; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1105 | struct mgcp_conn *conn; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1106 | int i; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1107 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1108 | 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 Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1114 | /* Send walk over all endpoints and send out dummy packets through |
| 1115 | * every connection present on each endpoint */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1116 | for (i = 1; i < tcfg->number_endpoints; ++i) { |
| 1117 | struct mgcp_endpoint *endp = &tcfg->endpoints[i]; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1118 | 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 Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1122 | } |
| 1123 | |
| 1124 | LOGP(DLMGCP, LOGL_DEBUG, "Rescheduling trunk %d keepalive timer.\n", |
| 1125 | tcfg->trunk_nr); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1126 | osmo_timer_schedule(&tcfg->keepalive_timer, tcfg->keepalive_interval, |
| 1127 | 0); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1128 | } |
| 1129 | |
| 1130 | void 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 Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1142 | /*! allocate configuration with default values. |
| 1143 | * (called once at startup by main function) */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1144 | struct 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 Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1154 | 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 Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1158 | 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 Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1162 | 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 Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1183 | /*! 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 Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1188 | struct 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 Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1212 | /*! 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 Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1216 | struct 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 Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1221 | if (trunk->trunk_nr == index) |
| 1222 | return trunk; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1223 | |
| 1224 | return NULL; |
| 1225 | } |
| 1226 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1227 | /*! 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 Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1231 | int mgcp_endpoints_allocate(struct mgcp_trunk_config *tcfg) |
| 1232 | { |
| 1233 | int i; |
| 1234 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1235 | tcfg->endpoints = _talloc_zero_array(tcfg->cfg, |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1236 | sizeof(struct mgcp_endpoint), |
| 1237 | tcfg->number_endpoints, |
| 1238 | "endpoints"); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1239 | if (!tcfg->endpoints) |
| 1240 | return -1; |
| 1241 | |
| 1242 | for (i = 0; i < tcfg->number_endpoints; ++i) { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1243 | INIT_LLIST_HEAD(&tcfg->endpoints[i].conns); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1244 | tcfg->endpoints[i].cfg = tcfg->cfg; |
| 1245 | tcfg->endpoints[i].tcfg = tcfg; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1246 | |
| 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 Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1250 | } |
| 1251 | |
| 1252 | return 0; |
| 1253 | } |
| 1254 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1255 | /*! relase endpoint, all open connections are closed. |
| 1256 | * \param[in] endp endpoint to release */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1257 | void mgcp_release_endp(struct mgcp_endpoint *endp) |
| 1258 | { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1259 | LOGP(DLMGCP, LOGL_DEBUG, "Releasing endpoint:%x\n", |
| 1260 | ENDPOINT_NUMBER(endp)); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1261 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1262 | /* 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 Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1269 | talloc_free(endp->callid); |
| 1270 | endp->callid = NULL; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1271 | 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 Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1275 | } |
| 1276 | |
| 1277 | static 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 Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1282 | /*! 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 Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1287 | int mgcp_send_reset_all(struct mgcp_config *cfg) |
| 1288 | { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1289 | int rc; |
| 1290 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1291 | static const char mgcp_reset[] = { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1292 | "RSIP 1 *@mgw MGCP 1.0\r\n" |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1293 | }; |
| 1294 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1295 | rc = send_agent(cfg, mgcp_reset, sizeof mgcp_reset - 1); |
| 1296 | if (rc <= 0) |
| 1297 | return -1; |
| 1298 | |
| 1299 | return 0; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1300 | } |
| 1301 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1302 | /*! 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 Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1307 | int mgcp_send_reset_ep(struct mgcp_endpoint *endp, int endpoint) |
| 1308 | { |
| 1309 | char buf[128]; |
| 1310 | int len; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1311 | int rc; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1312 | |
| 1313 | len = snprintf(buf, sizeof(buf), |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1314 | "RSIP 39 %x@mgw MGCP 1.0\r\n", endpoint); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1315 | if (len < 0) |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1316 | return -1; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1317 | |
| 1318 | buf[sizeof(buf) - 1] = '\0'; |
| 1319 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1320 | rc = send_agent(endp->cfg, buf, len); |
| 1321 | if (rc <= 0) |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1322 | return -1; |
| 1323 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1324 | return 0; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1325 | } |