diff mgw/mdcx.c @ 32:b3f74df7b808

beginning of themwi-mgw
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 09 Jul 2022 22:51:44 -0800
parents
children 7dae2bae56a1
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mgw/mdcx.c	Sat Jul 09 22:51:44 2022 -0800
@@ -0,0 +1,72 @@
+/*
+ * In this module we implement our MDCX operation.
+ */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include <syslog.h>
+#include "../include/tmgw_ctrl.h"
+#include "../include/tmgw_const.h"
+#include "struct.h"
+
+extern struct endpoint *find_ep_by_id();
+
+mdcx_operation(ep, req, resp)
+	struct endpoint *ep;
+	struct tmgw_ctrl_req *req;
+	struct tmgw_ctrl_resp *resp;
+{
+	if (req->setup_mask & TMGW_CTRL_MASK_GSM_CONN) {
+		if (ep->ep_type != TMGW_EP_TYPE_GATEWAY) {
+			resp->res = TMGW_RESP_ERR_PROT;
+			return(-1);
+		}
+		bcopy(&req->gsm_addr, &ep->rtp_gsm.remote_addr,
+			sizeof(struct sockaddr_in));
+		ep->gsm_payload_type = req->gsm_payload_type;
+		ep->gsm_payload_msg_type = req->gsm_payload_msg_type;
+	}
+	if (req->setup_mask & TMGW_CTRL_MASK_PSTN_CONN) {
+		if (ep->ep_type != TMGW_EP_TYPE_GATEWAY) {
+			resp->res = TMGW_RESP_ERR_PROT;
+			return(-1);
+		}
+		bcopy(&req->pstn_addr, &ep->rtp_pstn.remote_addr,
+			sizeof(struct sockaddr_in));
+		ep->pstn_payload_type = req->pstn_payload_type;
+	}
+	if (req->setup_mask & TMGW_CTRL_MASK_FWD_MODE) {
+		if (ep->ep_type != TMGW_EP_TYPE_GATEWAY ||
+		    ep->rtp_gsm.remote_addr.sin_family != AF_INET ||
+		    ep->rtp_pstn.remote_addr.sin_family != AF_INET) {
+			resp->res = TMGW_RESP_ERR_PROT;
+			return(-1);
+		}
+		ep->fwd_mode = req->fwd_mode;
+	}
+	return(0);
+}
+
+void
+process_mdcx(conn, req, resp)
+	struct ctrl_conn *conn;
+	struct tmgw_ctrl_req *req;
+	struct tmgw_ctrl_resp *resp;
+{
+	struct endpoint *ep;
+	int rc;
+
+	ep = find_ep_by_id(conn, req->ep_id);
+	if (!ep) {
+		resp->res = TMGW_RESP_ERR_PROT;
+		return;
+	}
+	rc = mdcx_operation(ep, req, resp);
+	if (rc == 0)
+		resp->res = TMGW_RESP_OK;
+}