changeset 34:7dae2bae56a1

themwi-mgw: implement MDCX parameter validation
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 09 Jul 2022 23:17:15 -0800
parents 2b072ad13de6
children db7ed6a55ba4
files include/tmgw_ctrl.h mgw/crcx.c mgw/ctrl_prot.c mgw/mdcx.c
diffstat 4 files changed, 33 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/include/tmgw_ctrl.h	Sat Jul 09 22:52:44 2022 -0800
+++ b/include/tmgw_ctrl.h	Sat Jul 09 23:17:15 2022 -0800
@@ -35,4 +35,6 @@
 #define	TMGW_RESP_OK		0
 #define	TMGW_RESP_ERR_PROT	1
 #define	TMGW_RESP_ERR_RSRC	2
-#define	TMGW_RESP_ERR_UNKNOWN	3
+#define	TMGW_RESP_ERR_OPCODE	3
+#define	TMGW_RESP_ERR_PARAM	4
+#define	TMGW_RESP_ERR_NOTSUP	5
--- a/mgw/crcx.c	Sat Jul 09 22:52:44 2022 -0800
+++ b/mgw/crcx.c	Sat Jul 09 23:17:15 2022 -0800
@@ -108,7 +108,7 @@
 	case TMGW_EP_TYPE_GATEWAY:
 		break;
 	default:
-		resp->res = TMGW_RESP_ERR_PROT;
+		resp->res = TMGW_RESP_ERR_PARAM;
 		return;
 	}
 	ep = malloc(sizeof(struct endpoint));
--- a/mgw/ctrl_prot.c	Sat Jul 09 22:52:44 2022 -0800
+++ b/mgw/ctrl_prot.c	Sat Jul 09 23:17:15 2022 -0800
@@ -59,7 +59,7 @@
 		process_dlcx(conn, &req, &resp);
 		break;
 	default:
-		resp.res = TMGW_RESP_ERR_PROT;
+		resp.res = TMGW_RESP_ERR_OPCODE;
 	}
 	send(fd, &resp, sizeof resp, 0);
 }
--- a/mgw/mdcx.c	Sat Jul 09 22:52:44 2022 -0800
+++ b/mgw/mdcx.c	Sat Jul 09 23:17:15 2022 -0800
@@ -26,6 +26,22 @@
 			resp->res = TMGW_RESP_ERR_PROT;
 			return(-1);
 		}
+		if (req->gsm_addr.ss_family != AF_INET) {
+			resp->res = TMGW_RESP_ERR_PARAM;
+			return(-1);
+		}
+		switch (req->gsm_payload_msg_type) {
+		case GSM_TCHF_FRAME:
+			break;
+		case GSM_TCHF_FRAME_EFR:
+		case GSM_TCHH_FRAME:
+		case GSM_TCH_FRAME_AMR:
+			resp->res = TMGW_RESP_ERR_NOTSUP;
+			return(-1);
+		default:
+			resp->res = TMGW_RESP_ERR_PARAM;
+			return(-1);
+		}
 		bcopy(&req->gsm_addr, &ep->rtp_gsm.remote_addr,
 			sizeof(struct sockaddr_in));
 		ep->gsm_payload_type = req->gsm_payload_type;
@@ -36,6 +52,18 @@
 			resp->res = TMGW_RESP_ERR_PROT;
 			return(-1);
 		}
+		if (req->pstn_addr.ss_family != AF_INET) {
+			resp->res = TMGW_RESP_ERR_PARAM;
+			return(-1);
+		}
+		switch (req->pstn_payload_type) {
+		case PSTN_CODEC_PCMU:
+		case PSTN_CODEC_PCMA:
+			break;
+		default:
+			resp->res = TMGW_RESP_ERR_PARAM;
+			return(-1);
+		}
 		bcopy(&req->pstn_addr, &ep->rtp_pstn.remote_addr,
 			sizeof(struct sockaddr_in));
 		ep->pstn_payload_type = req->pstn_payload_type;