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> |
Philipp Maier | 8970c49 | 2017-10-11 13:33:42 +0200 | [diff] [blame] | 42 | #include <osmocom/mgcp/mgcp_sdp.h> |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 43 | |
| 44 | struct mgcp_request { |
| 45 | char *name; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 46 | struct msgb *(*handle_request) (struct mgcp_parse_data * data); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 47 | char *debug_name; |
| 48 | }; |
| 49 | |
| 50 | #define MGCP_REQUEST(NAME, REQ, DEBUG_NAME) \ |
| 51 | { .name = NAME, .handle_request = REQ, .debug_name = DEBUG_NAME }, |
| 52 | |
| 53 | static struct msgb *handle_audit_endpoint(struct mgcp_parse_data *data); |
| 54 | static struct msgb *handle_create_con(struct mgcp_parse_data *data); |
| 55 | static struct msgb *handle_delete_con(struct mgcp_parse_data *data); |
| 56 | static struct msgb *handle_modify_con(struct mgcp_parse_data *data); |
| 57 | static struct msgb *handle_rsip(struct mgcp_parse_data *data); |
| 58 | static struct msgb *handle_noti_req(struct mgcp_parse_data *data); |
| 59 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 60 | /* Initalize transcoder */ |
| 61 | static int setup_rtp_processing(struct mgcp_endpoint *endp, |
| 62 | struct mgcp_conn_rtp *conn) |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 63 | { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 64 | struct mgcp_config *cfg = endp->cfg; |
| 65 | struct mgcp_conn_rtp *conn_src = NULL; |
| 66 | struct mgcp_conn_rtp *conn_dst = conn; |
| 67 | struct mgcp_conn *_conn; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 68 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 69 | if (conn->type != MGCP_RTP_DEFAULT) { |
| 70 | LOGP(DLMGCP, LOGL_NOTICE, |
| 71 | "endpoint:%x RTP-setup: Endpoint is not configured as RTP default, stopping here!\n", |
| 72 | ENDPOINT_NUMBER(endp)); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 73 | return 0; |
| 74 | } |
| 75 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 76 | if (conn->conn->mode == MGCP_CONN_LOOPBACK) { |
| 77 | LOGP(DLMGCP, LOGL_NOTICE, |
| 78 | "endpoint:%x RTP-setup: Endpoint is in loopback mode, stopping here!\n", |
| 79 | ENDPOINT_NUMBER(endp)); |
| 80 | return 0; |
| 81 | } |
| 82 | |
| 83 | /* Find the "sister" connection */ |
| 84 | llist_for_each_entry(_conn, &endp->conns, entry) { |
| 85 | if (_conn->id != conn->conn->id) { |
| 86 | conn_src = &_conn->u.rtp; |
| 87 | break; |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | return cfg->setup_rtp_processing_cb(endp, &conn_dst->end, |
| 92 | &conn_src->end); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 93 | } |
| 94 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 95 | /* array of function pointers for handling various |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 96 | * messages. In the future this might be binary sorted |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 97 | * for performance reasons. */ |
| 98 | static const struct mgcp_request mgcp_requests[] = { |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 99 | MGCP_REQUEST("AUEP", handle_audit_endpoint, "AuditEndpoint") |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 100 | MGCP_REQUEST("CRCX", handle_create_con, "CreateConnection") |
| 101 | MGCP_REQUEST("DLCX", handle_delete_con, "DeleteConnection") |
| 102 | MGCP_REQUEST("MDCX", handle_modify_con, "ModifiyConnection") |
| 103 | MGCP_REQUEST("RQNT", handle_noti_req, "NotificationRequest") |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 104 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 105 | /* SPEC extension */ |
| 106 | MGCP_REQUEST("RSIP", handle_rsip, "ReSetInProgress") |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 107 | }; |
| 108 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 109 | /* Helper function to allocate some memory for responses and retransmissions */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 110 | static struct msgb *mgcp_msgb_alloc(void) |
| 111 | { |
| 112 | struct msgb *msg; |
| 113 | msg = msgb_alloc_headroom(4096, 128, "MGCP msg"); |
| 114 | if (!msg) |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 115 | LOGP(DLMGCP, LOGL_ERROR, "Failed to msgb for MGCP data.\n"); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 116 | |
| 117 | return msg; |
| 118 | } |
| 119 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 120 | /* Helper function for do_retransmission() and create_resp() */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 121 | static struct msgb *do_retransmission(const struct mgcp_endpoint *endp) |
| 122 | { |
| 123 | struct msgb *msg = mgcp_msgb_alloc(); |
| 124 | if (!msg) |
| 125 | return NULL; |
| 126 | |
| 127 | msg->l2h = msgb_put(msg, strlen(endp->last_response)); |
| 128 | memcpy(msg->l2h, endp->last_response, msgb_l2len(msg)); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 129 | mgcp_disp_msg(msg->l2h, msgb_l2len(msg), "Retransmitted response"); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 130 | return msg; |
| 131 | } |
| 132 | |
| 133 | static struct msgb *create_resp(struct mgcp_endpoint *endp, int code, |
| 134 | const char *txt, const char *msg, |
| 135 | const char *trans, const char *param, |
| 136 | const char *sdp) |
| 137 | { |
| 138 | int len; |
| 139 | struct msgb *res; |
| 140 | |
| 141 | res = mgcp_msgb_alloc(); |
| 142 | if (!res) |
| 143 | return NULL; |
| 144 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 145 | len = snprintf((char *)res->data, 2048, "%d %s%s%s\r\n%s", |
| 146 | code, trans, txt, param ? param : "", sdp ? sdp : ""); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 147 | if (len < 0) { |
| 148 | LOGP(DLMGCP, LOGL_ERROR, "Failed to sprintf MGCP response.\n"); |
| 149 | msgb_free(res); |
| 150 | return NULL; |
| 151 | } |
| 152 | |
| 153 | res->l2h = msgb_put(res, len); |
| 154 | LOGP(DLMGCP, LOGL_DEBUG, "Generated response: code=%d\n", code); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 155 | mgcp_disp_msg(res->l2h, msgb_l2len(res), "Generated response"); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 156 | |
| 157 | /* |
| 158 | * Remember the last transmission per endpoint. |
| 159 | */ |
| 160 | if (endp) { |
| 161 | struct mgcp_trunk_config *tcfg = endp->tcfg; |
| 162 | talloc_free(endp->last_response); |
| 163 | talloc_free(endp->last_trans); |
| 164 | endp->last_trans = talloc_strdup(tcfg->endpoints, trans); |
| 165 | endp->last_response = talloc_strndup(tcfg->endpoints, |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 166 | (const char *)res->l2h, |
| 167 | msgb_l2len(res)); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | return res; |
| 171 | } |
| 172 | |
| 173 | static struct msgb *create_ok_resp_with_param(struct mgcp_endpoint *endp, |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 174 | int code, const char *msg, |
| 175 | const char *trans, |
| 176 | const char *param) |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 177 | { |
| 178 | return create_resp(endp, code, " OK", msg, trans, param, NULL); |
| 179 | } |
| 180 | |
| 181 | static struct msgb *create_ok_response(struct mgcp_endpoint *endp, |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 182 | int code, const char *msg, |
| 183 | const char *trans) |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 184 | { |
| 185 | return create_ok_resp_with_param(endp, code, msg, trans, NULL); |
| 186 | } |
| 187 | |
| 188 | static struct msgb *create_err_response(struct mgcp_endpoint *endp, |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 189 | int code, const char *msg, |
| 190 | const char *trans) |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 191 | { |
| 192 | return create_resp(endp, code, " FAIL", msg, trans, NULL, NULL); |
| 193 | } |
| 194 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 195 | /* Format MGCP response string (with SDP attached) */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 196 | static struct msgb *create_response_with_sdp(struct mgcp_endpoint *endp, |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 197 | struct mgcp_conn_rtp *conn, |
| 198 | const char *msg, |
| 199 | const char *trans_id) |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 200 | { |
| 201 | const char *addr = endp->cfg->local_ip; |
Philipp Maier | 8970c49 | 2017-10-11 13:33:42 +0200 | [diff] [blame] | 202 | struct msgb *sdp; |
| 203 | int rc; |
| 204 | struct msgb *result; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 205 | char osmux_extension[strlen("\nX-Osmux: 255") + 1]; |
Philipp Maier | 1cb1e38 | 2017-11-02 17:16:04 +0100 | [diff] [blame] | 206 | char local_ip_addr[INET_ADDRSTRLEN]; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 207 | |
Philipp Maier | 8970c49 | 2017-10-11 13:33:42 +0200 | [diff] [blame] | 208 | sdp = msgb_alloc_headroom(4096, 128, "sdp record"); |
| 209 | if (!sdp) |
| 210 | return NULL; |
| 211 | |
Philipp Maier | 1cb1e38 | 2017-11-02 17:16:04 +0100 | [diff] [blame] | 212 | if (!addr) { |
| 213 | mgcp_get_local_addr(local_ip_addr, conn); |
| 214 | addr = local_ip_addr; |
| 215 | } |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 216 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 217 | if (conn->osmux.state == OSMUX_STATE_NEGOTIATING) { |
| 218 | sprintf(osmux_extension, "\nX-Osmux: %u", conn->osmux.cid); |
| 219 | conn->osmux.state = OSMUX_STATE_ACTIVATING; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 220 | } else { |
| 221 | osmux_extension[0] = '\0'; |
| 222 | } |
| 223 | |
Philipp Maier | 8970c49 | 2017-10-11 13:33:42 +0200 | [diff] [blame] | 224 | rc = msgb_printf(sdp, "I: %u%s\n\n", conn->conn->id, osmux_extension); |
| 225 | if (rc < 0) |
| 226 | goto error; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 227 | |
Philipp Maier | 8970c49 | 2017-10-11 13:33:42 +0200 | [diff] [blame] | 228 | rc = mgcp_write_response_sdp(endp, conn, sdp, addr); |
| 229 | if (rc < 0) |
| 230 | goto error; |
| 231 | result = create_resp(endp, 200, " OK", msg, trans_id, NULL, (char*) sdp->data); |
| 232 | msgb_free(sdp); |
| 233 | return result; |
| 234 | error: |
| 235 | msgb_free(sdp); |
| 236 | return NULL; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 237 | } |
| 238 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 239 | /* Send out dummy packet to keep the connection open, if the connection is an |
| 240 | * osmux connection, send the dummy packet via OSMUX */ |
| 241 | 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] | 242 | { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 243 | if (conn->osmux.state != OSMUX_STATE_DISABLED) |
| 244 | osmux_send_dummy(endp, conn); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 245 | else |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 246 | mgcp_send_dummy(endp, conn); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 247 | } |
| 248 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 249 | /* handle incoming messages: |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 250 | * - this can be a command (four letters, space, transaction id) |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 251 | * - or a response (three numbers, space, transaction id) */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 252 | struct msgb *mgcp_handle_message(struct mgcp_config *cfg, struct msgb *msg) |
| 253 | { |
| 254 | struct mgcp_parse_data pdata; |
| 255 | int i, code, handled = 0; |
| 256 | struct msgb *resp = NULL; |
| 257 | char *data; |
| 258 | |
| 259 | if (msgb_l2len(msg) < 4) { |
| 260 | LOGP(DLMGCP, LOGL_ERROR, "msg too short: %d\n", msg->len); |
| 261 | return NULL; |
| 262 | } |
| 263 | |
| 264 | if (mgcp_msg_terminate_nul(msg)) |
| 265 | return NULL; |
| 266 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 267 | mgcp_disp_msg(msg->l2h, msgb_l2len(msg), "Received message"); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 268 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 269 | /* attempt to treat it as a response */ |
| 270 | if (sscanf((const char *)&msg->l2h[0], "%3d %*s", &code) == 1) { |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 271 | LOGP(DLMGCP, LOGL_DEBUG, "Response: Code: %d\n", code); |
| 272 | return NULL; |
| 273 | } |
| 274 | |
| 275 | msg->l3h = &msg->l2h[4]; |
| 276 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 277 | /* |
| 278 | * Check for a duplicate message and respond. |
| 279 | */ |
| 280 | memset(&pdata, 0, sizeof(pdata)); |
| 281 | pdata.cfg = cfg; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 282 | data = mgcp_strline((char *)msg->l3h, &pdata.save); |
| 283 | pdata.found = mgcp_parse_header(&pdata, data); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 284 | if (pdata.endp && pdata.trans |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 285 | && pdata.endp->last_trans |
| 286 | && strcmp(pdata.endp->last_trans, pdata.trans) == 0) { |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 287 | return do_retransmission(pdata.endp); |
| 288 | } |
| 289 | |
| 290 | for (i = 0; i < ARRAY_SIZE(mgcp_requests); ++i) { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 291 | if (strncmp |
| 292 | (mgcp_requests[i].name, (const char *)&msg->l2h[0], |
| 293 | 4) == 0) { |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 294 | handled = 1; |
| 295 | resp = mgcp_requests[i].handle_request(&pdata); |
| 296 | break; |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | if (!handled) |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 301 | LOGP(DLMGCP, LOGL_NOTICE, "MSG with type: '%.4s' not handled\n", |
| 302 | &msg->l2h[0]); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 303 | |
| 304 | return resp; |
| 305 | } |
| 306 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 307 | /* AUEP command handler, processes the received command */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 308 | static struct msgb *handle_audit_endpoint(struct mgcp_parse_data *p) |
| 309 | { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 310 | LOGP(DLMGCP, LOGL_NOTICE, "AUEP: auditing endpoint ...\n"); |
| 311 | |
| 312 | if (p->found != 0) { |
| 313 | LOGP(DLMGCP, LOGL_ERROR, |
| 314 | "AUEP: failed to find the endpoint.\n"); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 315 | return create_err_response(NULL, 500, "AUEP", p->trans); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 316 | } else |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 317 | return create_ok_response(p->endp, 200, "AUEP", p->trans); |
| 318 | } |
| 319 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 320 | /* Try to find a free port by attemting to bind on it. Also handle the |
| 321 | * counter that points on the next free port. Since we have a pointer |
| 322 | * to the next free port, binding should work on the first attemt, |
| 323 | * neverless, try at least the next 200 ports before giving up */ |
| 324 | 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] | 325 | { |
| 326 | int i; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 327 | struct mgcp_rtp_end *end; |
| 328 | struct mgcp_port_range *range; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 329 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 330 | OSMO_ASSERT(conn); |
| 331 | end = &conn->end; |
| 332 | OSMO_ASSERT(end); |
| 333 | |
| 334 | range = &endp->cfg->net_ports; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 335 | |
| 336 | /* attempt to find a port */ |
| 337 | for (i = 0; i < 200; ++i) { |
| 338 | int rc; |
| 339 | |
| 340 | if (range->last_port >= range->range_end) |
| 341 | range->last_port = range->range_start; |
| 342 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 343 | rc = mgcp_bind_net_rtp_port(endp, range->last_port, conn); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 344 | |
| 345 | range->last_port += 2; |
| 346 | if (rc == 0) { |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 347 | return 0; |
| 348 | } |
| 349 | |
| 350 | } |
| 351 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 352 | LOGP(DLMGCP, LOGL_ERROR, |
| 353 | "Allocating a RTP/RTCP port failed 200 times 0x%x.\n", |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 354 | ENDPOINT_NUMBER(endp)); |
| 355 | return -1; |
| 356 | } |
| 357 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 358 | /* Set the LCO from a string (see RFC 3435). |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 359 | * 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] | 360 | * like an empty string, the 'string' field is never NULL after this function |
| 361 | * has been called. */ |
| 362 | static void set_local_cx_options(void *ctx, struct mgcp_lco *lco, |
| 363 | const char *options) |
| 364 | { |
| 365 | char *p_opt, *a_opt; |
| 366 | char codec[9]; |
| 367 | |
| 368 | talloc_free(lco->string); |
| 369 | talloc_free(lco->codec); |
| 370 | lco->codec = NULL; |
| 371 | lco->pkt_period_min = lco->pkt_period_max = 0; |
| 372 | lco->string = talloc_strdup(ctx, options ? options : ""); |
| 373 | |
| 374 | p_opt = strstr(lco->string, "p:"); |
| 375 | if (p_opt && sscanf(p_opt, "p:%d-%d", |
| 376 | &lco->pkt_period_min, &lco->pkt_period_max) == 1) |
| 377 | lco->pkt_period_max = lco->pkt_period_min; |
| 378 | |
| 379 | a_opt = strstr(lco->string, "a:"); |
| 380 | if (a_opt && sscanf(a_opt, "a:%8[^,]", codec) == 1) |
| 381 | lco->codec = talloc_strdup(ctx, codec); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 382 | |
| 383 | LOGP(DLMGCP, LOGL_DEBUG, |
| 384 | "local CX options: lco->pkt_period_max: %i, lco->codec: %s\n", |
| 385 | lco->pkt_period_max, lco->codec); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | void mgcp_rtp_end_config(struct mgcp_endpoint *endp, int expect_ssrc_change, |
| 389 | struct mgcp_rtp_end *rtp) |
| 390 | { |
| 391 | struct mgcp_trunk_config *tcfg = endp->tcfg; |
| 392 | |
| 393 | int patch_ssrc = expect_ssrc_change && tcfg->force_constant_ssrc; |
| 394 | |
| 395 | rtp->force_aligned_timing = tcfg->force_aligned_timing; |
| 396 | rtp->force_constant_ssrc = patch_ssrc ? 1 : 0; |
| 397 | |
| 398 | LOGP(DLMGCP, LOGL_DEBUG, |
| 399 | "Configuring RTP endpoint: local port %d%s%s\n", |
| 400 | ntohs(rtp->rtp_port), |
| 401 | rtp->force_aligned_timing ? ", force constant timing" : "", |
| 402 | rtp->force_constant_ssrc ? ", force constant ssrc" : ""); |
| 403 | } |
| 404 | |
| 405 | uint32_t mgcp_rtp_packet_duration(struct mgcp_endpoint *endp, |
| 406 | struct mgcp_rtp_end *rtp) |
| 407 | { |
| 408 | int f = 0; |
| 409 | |
| 410 | /* Get the number of frames per channel and packet */ |
| 411 | if (rtp->frames_per_packet) |
| 412 | f = rtp->frames_per_packet; |
| 413 | else if (rtp->packet_duration_ms && rtp->codec.frame_duration_num) { |
| 414 | int den = 1000 * rtp->codec.frame_duration_num; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 415 | f = (rtp->packet_duration_ms * rtp->codec.frame_duration_den + |
| 416 | den / 2) |
| 417 | / den; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 418 | } |
| 419 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 420 | return rtp->codec.rate * f * rtp->codec.frame_duration_num / |
| 421 | rtp->codec.frame_duration_den; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | static int mgcp_osmux_setup(struct mgcp_endpoint *endp, const char *line) |
| 425 | { |
| 426 | if (!endp->cfg->osmux_init) { |
| 427 | if (osmux_init(OSMUX_ROLE_BSC, endp->cfg) < 0) { |
| 428 | LOGP(DLMGCP, LOGL_ERROR, "Cannot init OSMUX\n"); |
| 429 | return -1; |
| 430 | } |
| 431 | LOGP(DLMGCP, LOGL_NOTICE, "OSMUX socket has been set up\n"); |
| 432 | } |
| 433 | |
| 434 | return mgcp_parse_osmux_cid(line); |
| 435 | } |
| 436 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 437 | /* CRCX command handler, processes the received command */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 438 | static struct msgb *handle_create_con(struct mgcp_parse_data *p) |
| 439 | { |
| 440 | struct mgcp_trunk_config *tcfg; |
| 441 | struct mgcp_endpoint *endp = p->endp; |
| 442 | int error_code = 400; |
| 443 | |
| 444 | const char *local_options = NULL; |
| 445 | const char *callid = NULL; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 446 | const char *ci = NULL; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 447 | const char *mode = NULL; |
| 448 | char *line; |
| 449 | int have_sdp = 0, osmux_cid = -1; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 450 | struct mgcp_conn_rtp *conn = NULL; |
| 451 | uint32_t conn_id; |
| 452 | char conn_name[512]; |
| 453 | |
| 454 | LOGP(DLMGCP, LOGL_NOTICE, "CRCX: creating new connection ...\n"); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 455 | |
| 456 | if (p->found != 0) |
| 457 | return create_err_response(NULL, 510, "CRCX", p->trans); |
| 458 | |
| 459 | /* parse CallID C: and LocalParameters L: */ |
| 460 | for_each_line(line, p->save) { |
| 461 | if (!mgcp_check_param(endp, line)) |
| 462 | continue; |
| 463 | |
| 464 | switch (line[0]) { |
| 465 | case 'L': |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 466 | local_options = (const char *)line + 3; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 467 | break; |
| 468 | case 'C': |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 469 | callid = (const char *)line + 3; |
| 470 | break; |
| 471 | case 'I': |
| 472 | ci = (const char *)line + 3; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 473 | break; |
| 474 | case 'M': |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 475 | mode = (const char *)line + 3; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 476 | break; |
| 477 | case 'X': |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 478 | /* If osmoux is disabled, just skip setting it up */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 479 | if (!p->endp->cfg->osmux) |
| 480 | break; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 481 | if (strncmp("Osmux: ", line + 2, strlen("Osmux: ")) == |
| 482 | 0) |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 483 | osmux_cid = mgcp_osmux_setup(endp, line); |
| 484 | break; |
| 485 | case '\0': |
| 486 | have_sdp = 1; |
| 487 | goto mgcp_header_done; |
| 488 | default: |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 489 | LOGP(DLMGCP, LOGL_NOTICE, |
| 490 | "CRCX: endpoint:%x unhandled option: '%c'/%d\n", |
| 491 | ENDPOINT_NUMBER(endp), *line, *line); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 492 | break; |
| 493 | } |
| 494 | } |
| 495 | |
| 496 | mgcp_header_done: |
| 497 | tcfg = p->endp->tcfg; |
| 498 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 499 | /* Check parameters */ |
| 500 | if (!callid) { |
| 501 | LOGP(DLMGCP, LOGL_ERROR, |
| 502 | "CRCX: endpoint:%x insufficient parameters, missing callid\n", |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 503 | ENDPOINT_NUMBER(endp)); |
| 504 | return create_err_response(endp, 400, "CRCX", p->trans); |
| 505 | } |
| 506 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 507 | if (!mode) { |
| 508 | LOGP(DLMGCP, LOGL_ERROR, |
| 509 | "CRCX: endpoint:%x insufficient parameters, missing mode\n", |
| 510 | ENDPOINT_NUMBER(endp)); |
| 511 | return create_err_response(endp, 400, "CRCX", p->trans); |
| 512 | } |
| 513 | |
| 514 | if (!ci) { |
| 515 | LOGP(DLMGCP, LOGL_ERROR, |
| 516 | "CRCX: endpoint:%x insufficient parameters, missing connection id\n", |
| 517 | ENDPOINT_NUMBER(endp)); |
| 518 | return create_err_response(endp, 400, "CRCX", p->trans); |
| 519 | } |
| 520 | |
| 521 | /* Check if we are able to accept the creation of another connection */ |
| 522 | if (llist_count(&endp->conns) >= endp->type->max_conns) { |
| 523 | LOGP(DLMGCP, LOGL_ERROR, |
| 524 | "CRCX: endpoint:%x endpoint full, max. %i connections allowed!\n", |
| 525 | endp->type->max_conns, ENDPOINT_NUMBER(endp)); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 526 | if (tcfg->force_realloc) { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 527 | /* There is no more room for a connection, make some |
| 528 | * room by blindly tossing the oldest of the two two |
| 529 | * connections */ |
| 530 | mgcp_conn_free_oldest(endp); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 531 | } else { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 532 | /* There is no more room for a connection, leave |
| 533 | * everything as it is and return with an error */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 534 | return create_err_response(endp, 400, "CRCX", p->trans); |
| 535 | } |
| 536 | } |
| 537 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 538 | /* Check if this endpoint already serves a call, if so, check if the |
| 539 | * callids match up so that we are sure that this is our call */ |
| 540 | if (endp->callid && mgcp_verify_call_id(endp, callid)) { |
| 541 | LOGP(DLMGCP, LOGL_ERROR, |
| 542 | "CRCX: endpoint:%x allready seized by other call (%s)\n", |
| 543 | ENDPOINT_NUMBER(endp), endp->callid); |
| 544 | if (tcfg->force_realloc) |
| 545 | /* This is not our call, toss everything by releasing |
| 546 | * the entire endpoint. (rude!) */ |
| 547 | mgcp_release_endp(endp); |
| 548 | else { |
| 549 | /* This is not our call, leave everything as it is and |
| 550 | * return with an error. */ |
| 551 | return create_err_response(endp, 400, "CRCX", p->trans); |
| 552 | } |
| 553 | } |
| 554 | |
| 555 | /* Set the callid, creation of another connection will only be possible |
| 556 | * when the callid matches up. (Connections are distinuished by their |
| 557 | * connection ids) */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 558 | endp->callid = talloc_strdup(tcfg->endpoints, callid); |
| 559 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 560 | /* Extract audio codec information */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 561 | set_local_cx_options(endp->tcfg->endpoints, &endp->local_options, |
| 562 | local_options); |
| 563 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 564 | if (mgcp_parse_ci(&conn_id, ci)) { |
| 565 | LOGP(DLMGCP, LOGL_ERROR, |
| 566 | "CRCX: endpoint:%x insufficient parameters, missing ci (connectionIdentifier)\n", |
| 567 | ENDPOINT_NUMBER(endp)); |
| 568 | return create_err_response(endp, 400, "CRCX", p->trans); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 569 | } |
| 570 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 571 | /* Only accept another connection when the connection ID is different. */ |
| 572 | if (mgcp_conn_get_rtp(endp, conn_id)) { |
| 573 | LOGP(DLMGCP, LOGL_ERROR, |
| 574 | "CRCX: endpoint:%x there is already a connection with id %u present!\n", |
| 575 | conn_id, ENDPOINT_NUMBER(endp)); |
| 576 | if (tcfg->force_realloc) { |
| 577 | /* Ignore the existing connection by just freeing it */ |
| 578 | mgcp_conn_free(endp, conn_id); |
| 579 | } else { |
| 580 | /* There is already a connection with that ID present, |
| 581 | * leave everything as it is and return with an error. */ |
| 582 | return create_err_response(endp, 400, "CRCX", p->trans); |
| 583 | } |
| 584 | } |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 585 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 586 | snprintf(conn_name, sizeof(conn_name), "%s-%u", callid, conn_id); |
| 587 | mgcp_conn_alloc(NULL, endp, conn_id, MGCP_CONN_TYPE_RTP, |
| 588 | conn_name); |
| 589 | conn = mgcp_conn_get_rtp(endp, conn_id); |
| 590 | if (!conn) { |
| 591 | LOGP(DLMGCP, LOGL_ERROR, |
| 592 | "CRCX: endpoint:%x unable to allocate RTP connection\n", |
| 593 | ENDPOINT_NUMBER(endp)); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 594 | goto error2; |
| 595 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | if (mgcp_parse_conn_mode(mode, endp, conn->conn) != 0) { |
| 599 | error_code = 517; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 600 | goto error2; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 601 | } |
| 602 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 603 | /* Annotate Osmux circuit ID and set it to negotiating state until this |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 604 | * is fully set up from the dummy load. */ |
| 605 | conn->osmux.state = OSMUX_STATE_DISABLED; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 606 | if (osmux_cid >= 0) { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 607 | conn->osmux.cid = osmux_cid; |
| 608 | conn->osmux.state = OSMUX_STATE_NEGOTIATING; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 609 | } else if (endp->cfg->osmux == OSMUX_USAGE_ONLY) { |
| 610 | LOGP(DLMGCP, LOGL_ERROR, |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 611 | "CRCX: endpoint:%x osmux only and no osmux offered\n", |
| 612 | ENDPOINT_NUMBER(endp)); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 613 | goto error2; |
| 614 | } |
| 615 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 616 | /* set up RTP media parameters */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 617 | if (have_sdp) |
Philipp Maier | 8970c49 | 2017-10-11 13:33:42 +0200 | [diff] [blame] | 618 | mgcp_parse_sdp_data(endp, conn, p); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 619 | else if (endp->local_options.codec) |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 620 | mgcp_set_audio_info(p->cfg, &conn->end.codec, |
| 621 | PTYPE_UNDEFINED, endp->local_options.codec); |
| 622 | conn->end.fmtp_extra = talloc_strdup(tcfg->endpoints, |
| 623 | tcfg->audio_fmtp_extra); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 624 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 625 | if (p->cfg->force_ptime) { |
| 626 | conn->end.packet_duration_ms = p->cfg->force_ptime; |
| 627 | conn->end.force_output_ptime = 1; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 628 | } |
| 629 | |
Philipp Maier | 1cb1e38 | 2017-11-02 17:16:04 +0100 | [diff] [blame] | 630 | mgcp_rtp_end_config(endp, 0, &conn->end); |
| 631 | |
| 632 | if (allocate_port(endp, conn) != 0) { |
| 633 | goto error2; |
| 634 | } |
| 635 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 636 | if (setup_rtp_processing(endp, conn) != 0) { |
| 637 | LOGP(DLMGCP, LOGL_ERROR, |
| 638 | "CRCX: endpoint:%x could not start RTP processing!\n", |
| 639 | ENDPOINT_NUMBER(endp)); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 640 | goto error2; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 641 | } |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 642 | |
| 643 | /* policy CB */ |
| 644 | if (p->cfg->policy_cb) { |
| 645 | int rc; |
| 646 | rc = p->cfg->policy_cb(tcfg, ENDPOINT_NUMBER(endp), |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 647 | MGCP_ENDP_CRCX, p->trans); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 648 | switch (rc) { |
| 649 | case MGCP_POLICY_REJECT: |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 650 | LOGP(DLMGCP, LOGL_NOTICE, |
| 651 | "CRCX: endpoint:%x CRCX rejected by policy\n", |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 652 | ENDPOINT_NUMBER(endp)); |
| 653 | mgcp_release_endp(endp); |
| 654 | return create_err_response(endp, 400, "CRCX", p->trans); |
| 655 | break; |
| 656 | case MGCP_POLICY_DEFER: |
| 657 | /* stop processing */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 658 | return NULL; |
| 659 | break; |
| 660 | case MGCP_POLICY_CONT: |
| 661 | /* just continue */ |
| 662 | break; |
| 663 | } |
| 664 | } |
| 665 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 666 | LOGP(DLMGCP, LOGL_DEBUG, |
| 667 | "CRCX: endpoint:%x Creating connection: CI: %u port: %u\n", |
| 668 | ENDPOINT_NUMBER(endp), conn->conn->id, conn->end.local_port); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 669 | if (p->cfg->change_cb) |
| 670 | p->cfg->change_cb(tcfg, ENDPOINT_NUMBER(endp), MGCP_ENDP_CRCX); |
| 671 | |
Philipp Maier | e726d4f | 2017-11-01 10:41:34 +0100 | [diff] [blame] | 672 | /* Send dummy packet, see also comments in mgcp_keepalive_timer_cb() */ |
| 673 | OSMO_ASSERT(tcfg->keepalive_interval >= MGCP_KEEPALIVE_ONCE); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 674 | if (conn->conn->mode & MGCP_CONN_RECV_ONLY |
Philipp Maier | e726d4f | 2017-11-01 10:41:34 +0100 | [diff] [blame] | 675 | && tcfg->keepalive_interval != MGCP_KEEPALIVE_NEVER) |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 676 | send_dummy(endp, conn); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 677 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 678 | LOGP(DLMGCP, LOGL_NOTICE, |
| 679 | "CRCX: endpoint:%x connection successfully created\n", |
| 680 | ENDPOINT_NUMBER(endp)); |
| 681 | return create_response_with_sdp(endp, conn, "CRCX", p->trans); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 682 | error2: |
| 683 | mgcp_release_endp(endp); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 684 | LOGP(DLMGCP, LOGL_NOTICE, |
| 685 | "CRCX: endpoint:%x unable to create connection resource error\n", |
| 686 | ENDPOINT_NUMBER(endp)); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 687 | return create_err_response(endp, error_code, "CRCX", p->trans); |
| 688 | } |
| 689 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 690 | /* MDCX command handler, processes the received command */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 691 | static struct msgb *handle_modify_con(struct mgcp_parse_data *p) |
| 692 | { |
| 693 | struct mgcp_endpoint *endp = p->endp; |
| 694 | int error_code = 500; |
| 695 | int silent = 0; |
| 696 | int have_sdp = 0; |
| 697 | char *line; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 698 | const char *ci = NULL; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 699 | const char *local_options = NULL; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 700 | const char *mode = NULL; |
| 701 | struct mgcp_conn_rtp *conn = NULL; |
| 702 | uint32_t conn_id; |
| 703 | |
| 704 | LOGP(DLMGCP, LOGL_NOTICE, "MDCX: modifying existing connection ...\n"); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 705 | |
| 706 | if (p->found != 0) |
| 707 | return create_err_response(NULL, 510, "MDCX", p->trans); |
| 708 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 709 | if (llist_count(&endp->conns) <= 0) { |
| 710 | LOGP(DLMGCP, LOGL_ERROR, |
| 711 | "MDCX: endpoint:%x endpoint is not holding a connection.\n", |
| 712 | ENDPOINT_NUMBER(endp)); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 713 | return create_err_response(endp, 400, "MDCX", p->trans); |
| 714 | } |
| 715 | |
| 716 | for_each_line(line, p->save) { |
| 717 | if (!mgcp_check_param(endp, line)) |
| 718 | continue; |
| 719 | |
| 720 | switch (line[0]) { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 721 | case 'C': |
| 722 | if (mgcp_verify_call_id(endp, line + 3) != 0) |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 723 | goto error3; |
| 724 | break; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 725 | case 'I': |
| 726 | ci = (const char *)line + 3; |
| 727 | if (mgcp_verify_ci(endp, ci) != 0) |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 728 | goto error3; |
| 729 | break; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 730 | case 'L': |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 731 | local_options = (const char *)line + 3; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 732 | break; |
| 733 | case 'M': |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 734 | mode = (const char *)line + 3; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 735 | break; |
| 736 | case 'Z': |
| 737 | silent = strcmp("noanswer", line + 3) == 0; |
| 738 | break; |
| 739 | case '\0': |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 740 | have_sdp = 1; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 741 | goto mgcp_header_done; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 742 | break; |
| 743 | default: |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 744 | LOGP(DLMGCP, LOGL_NOTICE, |
| 745 | "MDCX: endpoint:%x Unhandled MGCP option: '%c'/%d\n", |
| 746 | ENDPOINT_NUMBER(endp), line[0], line[0]); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 747 | break; |
| 748 | } |
| 749 | } |
| 750 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 751 | mgcp_header_done: |
| 752 | if (mgcp_parse_ci(&conn_id, ci)) { |
| 753 | LOGP(DLMGCP, LOGL_ERROR, |
| 754 | "MDCX: endpoint:%x insufficient parameters, missing ci (connectionIdentifier)\n", |
| 755 | ENDPOINT_NUMBER(endp)); |
| 756 | return create_err_response(endp, 400, "MDCX", p->trans); |
| 757 | } |
| 758 | |
| 759 | conn = mgcp_conn_get_rtp(endp, conn_id); |
| 760 | if (!conn) |
| 761 | return create_err_response(endp, 400, "MDCX", p->trans); |
| 762 | |
| 763 | if (mode) { |
| 764 | if (mgcp_parse_conn_mode(mode, endp, conn->conn) != 0) { |
| 765 | error_code = 517; |
| 766 | goto error3; |
| 767 | } |
| 768 | } else |
| 769 | conn->conn->mode = conn->conn->mode_orig; |
| 770 | |
| 771 | if (have_sdp) |
Philipp Maier | 8970c49 | 2017-10-11 13:33:42 +0200 | [diff] [blame] | 772 | mgcp_parse_sdp_data(endp, conn, p); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 773 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 774 | set_local_cx_options(endp->tcfg->endpoints, &endp->local_options, |
| 775 | local_options); |
| 776 | |
| 777 | if (!have_sdp && endp->local_options.codec) |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 778 | mgcp_set_audio_info(p->cfg, &conn->end.codec, |
| 779 | PTYPE_UNDEFINED, endp->local_options.codec); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 780 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 781 | if (setup_rtp_processing(endp, conn) != 0) |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 782 | goto error3; |
| 783 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 784 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 785 | /* policy CB */ |
| 786 | if (p->cfg->policy_cb) { |
| 787 | int rc; |
| 788 | rc = p->cfg->policy_cb(endp->tcfg, ENDPOINT_NUMBER(endp), |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 789 | MGCP_ENDP_MDCX, p->trans); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 790 | switch (rc) { |
| 791 | case MGCP_POLICY_REJECT: |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 792 | LOGP(DLMGCP, LOGL_NOTICE, |
| 793 | "MDCX: endpoint:%x rejected by policy\n", |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 794 | ENDPOINT_NUMBER(endp)); |
| 795 | if (silent) |
| 796 | goto out_silent; |
| 797 | return create_err_response(endp, 400, "MDCX", p->trans); |
| 798 | break; |
| 799 | case MGCP_POLICY_DEFER: |
| 800 | /* stop processing */ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 801 | LOGP(DLMGCP, LOGL_DEBUG, |
| 802 | "MDCX: endpoint:%x defered by policy\n", |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 803 | ENDPOINT_NUMBER(endp)); |
| 804 | return NULL; |
| 805 | break; |
| 806 | case MGCP_POLICY_CONT: |
| 807 | /* just continue */ |
| 808 | break; |
| 809 | } |
| 810 | } |
| 811 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 812 | mgcp_rtp_end_config(endp, 1, &conn->end); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 813 | |
| 814 | /* modify */ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 815 | LOGP(DLMGCP, LOGL_DEBUG, |
| 816 | "MDCX: endpoint:%x modified conn:%s\n", |
| 817 | ENDPOINT_NUMBER(endp), mgcp_conn_dump(conn->conn)); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 818 | if (p->cfg->change_cb) |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 819 | p->cfg->change_cb(endp->tcfg, ENDPOINT_NUMBER(endp), |
| 820 | MGCP_ENDP_MDCX); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 821 | |
Philipp Maier | e726d4f | 2017-11-01 10:41:34 +0100 | [diff] [blame] | 822 | /* Send dummy packet, see also comments in mgcp_keepalive_timer_cb() */ |
| 823 | OSMO_ASSERT(endp->tcfg->keepalive_interval >= MGCP_KEEPALIVE_ONCE); |
| 824 | if (conn->conn->mode & MGCP_CONN_RECV_ONLY |
| 825 | && endp->tcfg->keepalive_interval != MGCP_KEEPALIVE_NEVER) |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 826 | send_dummy(endp, conn); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 827 | |
| 828 | if (silent) |
| 829 | goto out_silent; |
| 830 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 831 | LOGP(DLMGCP, LOGL_NOTICE, |
| 832 | "MDCX: endpoint:%x connection successfully modified\n", |
| 833 | ENDPOINT_NUMBER(endp)); |
| 834 | return create_response_with_sdp(endp, conn, "MDCX", p->trans); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 835 | error3: |
| 836 | return create_err_response(endp, error_code, "MDCX", p->trans); |
| 837 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 838 | out_silent: |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 839 | LOGP(DLMGCP, LOGL_DEBUG, "MDCX: endpoint:%x silent exit\n", |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 840 | ENDPOINT_NUMBER(endp)); |
| 841 | return NULL; |
| 842 | } |
| 843 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 844 | /* DLCX command handler, processes the received command */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 845 | static struct msgb *handle_delete_con(struct mgcp_parse_data *p) |
| 846 | { |
| 847 | struct mgcp_endpoint *endp = p->endp; |
| 848 | int error_code = 400; |
| 849 | int silent = 0; |
| 850 | char *line; |
| 851 | char stats[1048]; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 852 | const char *ci = NULL; |
| 853 | struct mgcp_conn_rtp *conn = NULL; |
| 854 | uint32_t conn_id; |
| 855 | |
Neels Hofmeyr | 653c4ff | 2017-11-10 01:41:45 +0100 | [diff] [blame] | 856 | if (p->found != 0) |
| 857 | return create_err_response(NULL, error_code, "DLCX", p->trans); |
| 858 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 859 | LOGP(DLMGCP, LOGL_NOTICE, |
| 860 | "DLCX: endpoint:%x deleting connection ...\n", |
| 861 | ENDPOINT_NUMBER(endp)); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 862 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 863 | if (llist_count(&endp->conns) <= 0) { |
| 864 | LOGP(DLMGCP, LOGL_ERROR, |
| 865 | "DLCX: endpoint:%x endpoint is not holding a connection.\n", |
| 866 | ENDPOINT_NUMBER(endp)); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 867 | return create_err_response(endp, 400, "DLCX", p->trans); |
| 868 | } |
| 869 | |
| 870 | for_each_line(line, p->save) { |
| 871 | if (!mgcp_check_param(endp, line)) |
| 872 | continue; |
| 873 | |
| 874 | switch (line[0]) { |
| 875 | case 'C': |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 876 | if (mgcp_verify_call_id(endp, line + 3) != 0) |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 877 | goto error3; |
| 878 | break; |
| 879 | case 'I': |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 880 | ci = (const char *)line + 3; |
| 881 | if (mgcp_verify_ci(endp, ci) != 0) |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 882 | goto error3; |
| 883 | break; |
| 884 | case 'Z': |
| 885 | silent = strcmp("noanswer", line + 3) == 0; |
| 886 | break; |
| 887 | default: |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 888 | LOGP(DLMGCP, LOGL_NOTICE, |
| 889 | "DLCX: endpoint:%x Unhandled MGCP option: '%c'/%d\n", |
| 890 | ENDPOINT_NUMBER(endp), line[0], line[0]); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 891 | break; |
| 892 | } |
| 893 | } |
| 894 | |
| 895 | /* policy CB */ |
| 896 | if (p->cfg->policy_cb) { |
| 897 | int rc; |
| 898 | rc = p->cfg->policy_cb(endp->tcfg, ENDPOINT_NUMBER(endp), |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 899 | MGCP_ENDP_DLCX, p->trans); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 900 | switch (rc) { |
| 901 | case MGCP_POLICY_REJECT: |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 902 | LOGP(DLMGCP, LOGL_NOTICE, |
| 903 | "DLCX: endpoint:%x rejected by policy\n", |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 904 | ENDPOINT_NUMBER(endp)); |
| 905 | if (silent) |
| 906 | goto out_silent; |
| 907 | return create_err_response(endp, 400, "DLCX", p->trans); |
| 908 | break; |
| 909 | case MGCP_POLICY_DEFER: |
| 910 | /* stop processing */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 911 | return NULL; |
| 912 | break; |
| 913 | case MGCP_POLICY_CONT: |
| 914 | /* just continue */ |
| 915 | break; |
| 916 | } |
| 917 | } |
| 918 | |
Philipp Maier | f4c0e37 | 2017-10-11 16:06:45 +0200 | [diff] [blame] | 919 | /* When no connection id is supplied, we will interpret this as a |
| 920 | * wildcarded DLCX and drop all connections at once. (See also |
| 921 | * RFC3435 Section F.7) */ |
| 922 | if (!ci) { |
| 923 | LOGP(DLMGCP, LOGL_NOTICE, |
| 924 | "DLCX: endpoint:%x missing ci (connectionIdentifier), will remove all connections at once\n", |
| 925 | ENDPOINT_NUMBER(endp)); |
| 926 | |
| 927 | mgcp_release_endp(endp); |
| 928 | |
| 929 | /* Note: In this case we do not return any statistics, |
| 930 | * as we assume that the client is not interested in |
| 931 | * this case. */ |
| 932 | return create_ok_response(endp, 200, "DLCX", p->trans); |
| 933 | } |
| 934 | |
| 935 | /* Parse the connection id */ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 936 | if (mgcp_parse_ci(&conn_id, ci)) { |
| 937 | LOGP(DLMGCP, LOGL_ERROR, |
Philipp Maier | f4c0e37 | 2017-10-11 16:06:45 +0200 | [diff] [blame] | 938 | "DLCX: endpoint:%x insufficient parameters, invalid ci (connectionIdentifier)\n", |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 939 | ENDPOINT_NUMBER(endp)); |
| 940 | return create_err_response(endp, 400, "DLCX", p->trans); |
| 941 | } |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 942 | |
Philipp Maier | f4c0e37 | 2017-10-11 16:06:45 +0200 | [diff] [blame] | 943 | /* Find the connection */ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 944 | conn = mgcp_conn_get_rtp(endp, conn_id); |
| 945 | if (!conn) |
| 946 | goto error3; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 947 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 948 | /* save the statistics of the current connection */ |
| 949 | mgcp_format_stats(stats, sizeof(stats), conn->conn); |
| 950 | |
| 951 | /* delete connection */ |
| 952 | LOGP(DLMGCP, LOGL_DEBUG, "DLCX: endpoint:%x deleting conn:%s\n", |
| 953 | ENDPOINT_NUMBER(endp), mgcp_conn_dump(conn->conn)); |
| 954 | mgcp_conn_free(endp, conn_id); |
| 955 | LOGP(DLMGCP, LOGL_NOTICE, |
| 956 | "DLCX: endpoint:%x connection successfully deleted\n", |
| 957 | ENDPOINT_NUMBER(endp)); |
| 958 | |
| 959 | /* When all connections are closed, the endpoint will be released |
| 960 | * in order to be ready to be used by another call. */ |
| 961 | if (llist_count(&endp->conns) <= 0) { |
| 962 | mgcp_release_endp(endp); |
| 963 | LOGP(DLMGCP, LOGL_DEBUG, |
| 964 | "DLCX: endpoint:%x endpoint released\n", |
| 965 | ENDPOINT_NUMBER(endp)); |
| 966 | } |
| 967 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 968 | if (p->cfg->change_cb) |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 969 | p->cfg->change_cb(endp->tcfg, ENDPOINT_NUMBER(endp), |
| 970 | MGCP_ENDP_DLCX); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 971 | |
| 972 | if (silent) |
| 973 | goto out_silent; |
| 974 | return create_ok_resp_with_param(endp, 250, "DLCX", p->trans, stats); |
| 975 | |
| 976 | error3: |
| 977 | return create_err_response(endp, error_code, "DLCX", p->trans); |
| 978 | |
| 979 | out_silent: |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 980 | LOGP(DLMGCP, LOGL_DEBUG, "DLCX: endpoint:%x silent exit\n", |
| 981 | ENDPOINT_NUMBER(endp)); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 982 | return NULL; |
| 983 | } |
| 984 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 985 | /* RSIP command handler, processes the received command */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 986 | static struct msgb *handle_rsip(struct mgcp_parse_data *p) |
| 987 | { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 988 | /* TODO: Also implement the resetting of a specific endpoint |
| 989 | * to make mgcp_send_reset_ep() work. Currently this will call |
| 990 | * mgcp_rsip_cb() in mgw_main.c, which sets reset_endpoints=1 |
| 991 | * to make read_call_agent() reset all endpoints when called |
| 992 | * next time. In order to selectively reset endpoints some |
| 993 | * mechanism to distinguish which endpoint shall be resetted |
| 994 | * is needed */ |
| 995 | |
| 996 | LOGP(DLMGCP, LOGL_NOTICE, "RSIP: resetting all endpoints ...\n"); |
| 997 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 998 | if (p->found != 0) { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 999 | LOGP(DLMGCP, LOGL_ERROR, |
| 1000 | "RSIP: failed to find the endpoint.\n"); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1001 | return NULL; |
| 1002 | } |
| 1003 | |
| 1004 | if (p->cfg->reset_cb) |
| 1005 | p->cfg->reset_cb(p->endp->tcfg); |
| 1006 | return NULL; |
| 1007 | } |
| 1008 | |
| 1009 | static char extract_tone(const char *line) |
| 1010 | { |
| 1011 | const char *str = strstr(line, "D/"); |
| 1012 | if (!str) |
| 1013 | return CHAR_MAX; |
| 1014 | |
| 1015 | return str[2]; |
| 1016 | } |
| 1017 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1018 | /* This can request like DTMF detection and forward, fax detection... it |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1019 | * 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] | 1020 | * do this right now. */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1021 | static struct msgb *handle_noti_req(struct mgcp_parse_data *p) |
| 1022 | { |
| 1023 | int res = 0; |
| 1024 | char *line; |
| 1025 | char tone = CHAR_MAX; |
| 1026 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1027 | LOGP(DLMGCP, LOGL_NOTICE, "RQNT: processing request for notification ...\n"); |
| 1028 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1029 | if (p->found != 0) |
| 1030 | return create_err_response(NULL, 400, "RQNT", p->trans); |
| 1031 | |
| 1032 | for_each_line(line, p->save) { |
| 1033 | switch (line[0]) { |
| 1034 | case 'S': |
| 1035 | tone = extract_tone(line); |
| 1036 | break; |
| 1037 | } |
| 1038 | } |
| 1039 | |
| 1040 | /* we didn't see a signal request with a tone */ |
| 1041 | if (tone == CHAR_MAX) |
| 1042 | return create_ok_response(p->endp, 200, "RQNT", p->trans); |
| 1043 | |
| 1044 | if (p->cfg->rqnt_cb) |
| 1045 | res = p->cfg->rqnt_cb(p->endp, tone); |
| 1046 | |
| 1047 | return res == 0 ? |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1048 | create_ok_response(p->endp, 200, "RQNT", p->trans) : |
| 1049 | create_err_response(p->endp, res, "RQNT", p->trans); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1050 | } |
| 1051 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1052 | /* Connection keepalive timer, will take care that dummy packets are send |
| 1053 | * regulary, so that NAT connections stay open */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1054 | static void mgcp_keepalive_timer_cb(void *_tcfg) |
| 1055 | { |
| 1056 | struct mgcp_trunk_config *tcfg = _tcfg; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1057 | struct mgcp_conn *conn; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1058 | int i; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1059 | |
Philipp Maier | e726d4f | 2017-11-01 10:41:34 +0100 | [diff] [blame] | 1060 | LOGP(DLMGCP, LOGL_DEBUG, "triggered trunk %d keepalive timer\n", |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1061 | tcfg->trunk_nr); |
| 1062 | |
Philipp Maier | e726d4f | 2017-11-01 10:41:34 +0100 | [diff] [blame] | 1063 | /* Do not accept invalid configuration values |
| 1064 | * valid is MGCP_KEEPALIVE_NEVER, MGCP_KEEPALIVE_ONCE and |
| 1065 | * values greater 0 */ |
| 1066 | OSMO_ASSERT(tcfg->keepalive_interval >= MGCP_KEEPALIVE_ONCE); |
| 1067 | |
| 1068 | /* The dummy packet functionality has been disabled, we will exit |
| 1069 | * immediately, no further timer is scheduled, which means we will no |
| 1070 | * longer send dummy packets even when we did before */ |
| 1071 | if (tcfg->keepalive_interval == MGCP_KEEPALIVE_NEVER) |
| 1072 | return; |
| 1073 | |
| 1074 | /* In cases where only one dummy packet is sent, we do not need |
| 1075 | * the timer since the functions that handle the CRCX and MDCX are |
| 1076 | * triggering the sending of the dummy packet. So we behave like in |
| 1077 | * the MGCP_KEEPALIVE_NEVER case */ |
| 1078 | if (tcfg->keepalive_interval == MGCP_KEEPALIVE_ONCE) |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1079 | return; |
| 1080 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1081 | /* Send walk over all endpoints and send out dummy packets through |
| 1082 | * every connection present on each endpoint */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1083 | for (i = 1; i < tcfg->number_endpoints; ++i) { |
| 1084 | struct mgcp_endpoint *endp = &tcfg->endpoints[i]; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1085 | llist_for_each_entry(conn, &endp->conns, entry) { |
| 1086 | if (conn->mode == MGCP_CONN_RECV_ONLY) |
| 1087 | send_dummy(endp, &conn->u.rtp); |
| 1088 | } |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1089 | } |
| 1090 | |
Philipp Maier | e726d4f | 2017-11-01 10:41:34 +0100 | [diff] [blame] | 1091 | /* Schedule the keepalive timer for the next round */ |
| 1092 | LOGP(DLMGCP, LOGL_DEBUG, "rescheduling trunk %d keepalive timer\n", |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1093 | tcfg->trunk_nr); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1094 | osmo_timer_schedule(&tcfg->keepalive_timer, tcfg->keepalive_interval, |
| 1095 | 0); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1096 | } |
| 1097 | |
| 1098 | void mgcp_trunk_set_keepalive(struct mgcp_trunk_config *tcfg, int interval) |
| 1099 | { |
| 1100 | tcfg->keepalive_interval = interval; |
| 1101 | osmo_timer_setup(&tcfg->keepalive_timer, mgcp_keepalive_timer_cb, tcfg); |
| 1102 | |
| 1103 | if (interval <= 0) |
| 1104 | osmo_timer_del(&tcfg->keepalive_timer); |
| 1105 | else |
| 1106 | osmo_timer_schedule(&tcfg->keepalive_timer, |
| 1107 | tcfg->keepalive_interval, 0); |
| 1108 | } |
| 1109 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1110 | /*! allocate configuration with default values. |
| 1111 | * (called once at startup by main function) */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1112 | struct mgcp_config *mgcp_config_alloc(void) |
| 1113 | { |
| 1114 | struct mgcp_config *cfg; |
| 1115 | |
| 1116 | cfg = talloc_zero(NULL, struct mgcp_config); |
| 1117 | if (!cfg) { |
| 1118 | LOGP(DLMGCP, LOGL_FATAL, "Failed to allocate config.\n"); |
| 1119 | return NULL; |
| 1120 | } |
| 1121 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1122 | cfg->net_ports.range_start = RTP_PORT_DEFAULT_RANGE_START; |
| 1123 | cfg->net_ports.range_end = RTP_PORT_DEFAULT_RANGE_END; |
| 1124 | cfg->net_ports.last_port = cfg->net_ports.range_start; |
| 1125 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1126 | cfg->source_port = 2427; |
| 1127 | cfg->source_addr = talloc_strdup(cfg, "0.0.0.0"); |
| 1128 | cfg->osmux_addr = talloc_strdup(cfg, "0.0.0.0"); |
| 1129 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1130 | cfg->rtp_processing_cb = &mgcp_rtp_processing_default; |
| 1131 | cfg->setup_rtp_processing_cb = &mgcp_setup_rtp_processing_default; |
| 1132 | |
| 1133 | cfg->get_net_downlink_format_cb = &mgcp_get_net_downlink_format_default; |
| 1134 | |
| 1135 | /* default trunk handling */ |
| 1136 | cfg->trunk.cfg = cfg; |
| 1137 | cfg->trunk.trunk_nr = 0; |
| 1138 | cfg->trunk.trunk_type = MGCP_TRUNK_VIRTUAL; |
| 1139 | cfg->trunk.audio_name = talloc_strdup(cfg, "AMR/8000"); |
| 1140 | cfg->trunk.audio_payload = 126; |
| 1141 | cfg->trunk.audio_send_ptime = 1; |
| 1142 | cfg->trunk.audio_send_name = 1; |
| 1143 | cfg->trunk.omit_rtcp = 0; |
| 1144 | mgcp_trunk_set_keepalive(&cfg->trunk, MGCP_KEEPALIVE_ONCE); |
| 1145 | |
| 1146 | INIT_LLIST_HEAD(&cfg->trunks); |
| 1147 | |
| 1148 | return cfg; |
| 1149 | } |
| 1150 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1151 | /*! allocate configuration with default values. |
| 1152 | * (called once at startup by VTY) |
| 1153 | * \param[in] cfg mgcp configuration |
| 1154 | * \param[in] nr trunk number |
| 1155 | * \returns pointer to allocated trunk configuration */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1156 | struct mgcp_trunk_config *mgcp_trunk_alloc(struct mgcp_config *cfg, int nr) |
| 1157 | { |
| 1158 | struct mgcp_trunk_config *trunk; |
| 1159 | |
| 1160 | trunk = talloc_zero(cfg, struct mgcp_trunk_config); |
| 1161 | if (!trunk) { |
| 1162 | LOGP(DLMGCP, LOGL_ERROR, "Failed to allocate.\n"); |
| 1163 | return NULL; |
| 1164 | } |
| 1165 | |
| 1166 | trunk->cfg = cfg; |
| 1167 | trunk->trunk_type = MGCP_TRUNK_E1; |
| 1168 | trunk->trunk_nr = nr; |
| 1169 | trunk->audio_name = talloc_strdup(cfg, "AMR/8000"); |
| 1170 | trunk->audio_payload = 126; |
| 1171 | trunk->audio_send_ptime = 1; |
| 1172 | trunk->audio_send_name = 1; |
| 1173 | trunk->number_endpoints = 33; |
| 1174 | trunk->omit_rtcp = 0; |
| 1175 | mgcp_trunk_set_keepalive(trunk, MGCP_KEEPALIVE_ONCE); |
| 1176 | llist_add_tail(&trunk->entry, &cfg->trunks); |
| 1177 | return trunk; |
| 1178 | } |
| 1179 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1180 | /*! get trunk configuration by trunk number (index). |
| 1181 | * \param[in] cfg mgcp configuration |
| 1182 | * \param[in] index trunk number |
| 1183 | * \returns pointer to trunk configuration, NULL on error */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1184 | struct mgcp_trunk_config *mgcp_trunk_num(struct mgcp_config *cfg, int index) |
| 1185 | { |
| 1186 | struct mgcp_trunk_config *trunk; |
| 1187 | |
| 1188 | llist_for_each_entry(trunk, &cfg->trunks, entry) |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1189 | if (trunk->trunk_nr == index) |
| 1190 | return trunk; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1191 | |
| 1192 | return NULL; |
| 1193 | } |
| 1194 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1195 | /*! allocate endpoints and set default values. |
| 1196 | * (called once at startup by VTY) |
| 1197 | * \param[in] tcfg trunk configuration |
| 1198 | * \returns 0 on success, -1 on failure */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1199 | int mgcp_endpoints_allocate(struct mgcp_trunk_config *tcfg) |
| 1200 | { |
| 1201 | int i; |
| 1202 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1203 | tcfg->endpoints = _talloc_zero_array(tcfg->cfg, |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1204 | sizeof(struct mgcp_endpoint), |
| 1205 | tcfg->number_endpoints, |
| 1206 | "endpoints"); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1207 | if (!tcfg->endpoints) |
| 1208 | return -1; |
| 1209 | |
| 1210 | for (i = 0; i < tcfg->number_endpoints; ++i) { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1211 | INIT_LLIST_HEAD(&tcfg->endpoints[i].conns); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1212 | tcfg->endpoints[i].cfg = tcfg->cfg; |
| 1213 | tcfg->endpoints[i].tcfg = tcfg; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1214 | |
| 1215 | /* NOTE: Currently all endpoints are of type RTP, this will |
| 1216 | * change when new variations are implemented */ |
| 1217 | tcfg->endpoints[i].type = &ep_typeset.rtp; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1218 | } |
| 1219 | |
| 1220 | return 0; |
| 1221 | } |
| 1222 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1223 | /*! relase endpoint, all open connections are closed. |
| 1224 | * \param[in] endp endpoint to release */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1225 | void mgcp_release_endp(struct mgcp_endpoint *endp) |
| 1226 | { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1227 | LOGP(DLMGCP, LOGL_DEBUG, "Releasing endpoint:%x\n", |
| 1228 | ENDPOINT_NUMBER(endp)); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1229 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1230 | /* Normally this function should only be called wehen |
| 1231 | * all connections have been removed already. In case |
| 1232 | * that there are still connections open (e.g. when |
| 1233 | * RSIP is executed), free them all at once. */ |
| 1234 | mgcp_conn_free_all(endp); |
| 1235 | |
| 1236 | /* Reset endpoint parameters and states */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1237 | talloc_free(endp->callid); |
| 1238 | endp->callid = NULL; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1239 | talloc_free(endp->local_options.string); |
| 1240 | endp->local_options.string = NULL; |
| 1241 | talloc_free(endp->local_options.codec); |
| 1242 | endp->local_options.codec = NULL; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1243 | } |
| 1244 | |
| 1245 | static int send_agent(struct mgcp_config *cfg, const char *buf, int len) |
| 1246 | { |
| 1247 | return write(cfg->gw_fd.bfd.fd, buf, len); |
| 1248 | } |
| 1249 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1250 | /*! Reset all endpoints by sending RSIP message to self. |
| 1251 | * (called by VTY) |
| 1252 | * \param[in] endp trunk endpoint |
| 1253 | * \param[in] endpoint number |
| 1254 | * \returns 0 on success, -1 on error */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1255 | int mgcp_send_reset_all(struct mgcp_config *cfg) |
| 1256 | { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1257 | int rc; |
| 1258 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1259 | static const char mgcp_reset[] = { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1260 | "RSIP 1 *@mgw MGCP 1.0\r\n" |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1261 | }; |
| 1262 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1263 | rc = send_agent(cfg, mgcp_reset, sizeof mgcp_reset - 1); |
| 1264 | if (rc <= 0) |
| 1265 | return -1; |
| 1266 | |
| 1267 | return 0; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1268 | } |
| 1269 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1270 | /*! Reset a single endpoint by sending RSIP message to self. |
| 1271 | * (called by VTY) |
| 1272 | * \param[in] endp trunk endpoint |
| 1273 | * \param[in] endpoint number |
| 1274 | * \returns 0 on success, -1 on error */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1275 | int mgcp_send_reset_ep(struct mgcp_endpoint *endp, int endpoint) |
| 1276 | { |
| 1277 | char buf[128]; |
| 1278 | int len; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1279 | int rc; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1280 | |
| 1281 | len = snprintf(buf, sizeof(buf), |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1282 | "RSIP 39 %x@mgw MGCP 1.0\r\n", endpoint); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1283 | if (len < 0) |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1284 | return -1; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1285 | |
| 1286 | buf[sizeof(buf) - 1] = '\0'; |
| 1287 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1288 | rc = send_agent(endp->cfg, buf, len); |
| 1289 | if (rc <= 0) |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1290 | return -1; |
| 1291 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1292 | return 0; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1293 | } |