annotate mgw/mdcx.c @ 37:a065b4a62a8a

themwi-test-mtc: drain stdin when we receive input meant to request user disconnect
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 10 Jul 2022 00:32:38 -0800
parents 7dae2bae56a1
children 020ba624bdd8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
32
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * In this module we implement our MDCX operation.
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/socket.h>
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <netinet/in.h>
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdio.h>
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdlib.h>
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <string.h>
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <strings.h>
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <syslog.h>
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include "../include/tmgw_ctrl.h"
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include "../include/tmgw_const.h"
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include "struct.h"
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 extern struct endpoint *find_ep_by_id();
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 mdcx_operation(ep, req, resp)
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 struct endpoint *ep;
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 struct tmgw_ctrl_req *req;
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 struct tmgw_ctrl_resp *resp;
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 {
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 if (req->setup_mask & TMGW_CTRL_MASK_GSM_CONN) {
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 if (ep->ep_type != TMGW_EP_TYPE_GATEWAY) {
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 resp->res = TMGW_RESP_ERR_PROT;
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 return(-1);
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 }
34
7dae2bae56a1 themwi-mgw: implement MDCX parameter validation
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
29 if (req->gsm_addr.ss_family != AF_INET) {
7dae2bae56a1 themwi-mgw: implement MDCX parameter validation
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
30 resp->res = TMGW_RESP_ERR_PARAM;
7dae2bae56a1 themwi-mgw: implement MDCX parameter validation
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
31 return(-1);
7dae2bae56a1 themwi-mgw: implement MDCX parameter validation
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
32 }
7dae2bae56a1 themwi-mgw: implement MDCX parameter validation
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
33 switch (req->gsm_payload_msg_type) {
7dae2bae56a1 themwi-mgw: implement MDCX parameter validation
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
34 case GSM_TCHF_FRAME:
7dae2bae56a1 themwi-mgw: implement MDCX parameter validation
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
35 break;
7dae2bae56a1 themwi-mgw: implement MDCX parameter validation
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
36 case GSM_TCHF_FRAME_EFR:
7dae2bae56a1 themwi-mgw: implement MDCX parameter validation
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
37 case GSM_TCHH_FRAME:
7dae2bae56a1 themwi-mgw: implement MDCX parameter validation
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
38 case GSM_TCH_FRAME_AMR:
7dae2bae56a1 themwi-mgw: implement MDCX parameter validation
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
39 resp->res = TMGW_RESP_ERR_NOTSUP;
7dae2bae56a1 themwi-mgw: implement MDCX parameter validation
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
40 return(-1);
7dae2bae56a1 themwi-mgw: implement MDCX parameter validation
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
41 default:
7dae2bae56a1 themwi-mgw: implement MDCX parameter validation
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
42 resp->res = TMGW_RESP_ERR_PARAM;
7dae2bae56a1 themwi-mgw: implement MDCX parameter validation
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
43 return(-1);
7dae2bae56a1 themwi-mgw: implement MDCX parameter validation
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
44 }
32
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 bcopy(&req->gsm_addr, &ep->rtp_gsm.remote_addr,
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 sizeof(struct sockaddr_in));
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 ep->gsm_payload_type = req->gsm_payload_type;
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 ep->gsm_payload_msg_type = req->gsm_payload_msg_type;
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 }
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 if (req->setup_mask & TMGW_CTRL_MASK_PSTN_CONN) {
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 if (ep->ep_type != TMGW_EP_TYPE_GATEWAY) {
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 resp->res = TMGW_RESP_ERR_PROT;
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 return(-1);
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 }
34
7dae2bae56a1 themwi-mgw: implement MDCX parameter validation
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
55 if (req->pstn_addr.ss_family != AF_INET) {
7dae2bae56a1 themwi-mgw: implement MDCX parameter validation
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
56 resp->res = TMGW_RESP_ERR_PARAM;
7dae2bae56a1 themwi-mgw: implement MDCX parameter validation
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
57 return(-1);
7dae2bae56a1 themwi-mgw: implement MDCX parameter validation
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
58 }
7dae2bae56a1 themwi-mgw: implement MDCX parameter validation
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
59 switch (req->pstn_payload_type) {
7dae2bae56a1 themwi-mgw: implement MDCX parameter validation
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
60 case PSTN_CODEC_PCMU:
7dae2bae56a1 themwi-mgw: implement MDCX parameter validation
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
61 case PSTN_CODEC_PCMA:
7dae2bae56a1 themwi-mgw: implement MDCX parameter validation
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
62 break;
7dae2bae56a1 themwi-mgw: implement MDCX parameter validation
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
63 default:
7dae2bae56a1 themwi-mgw: implement MDCX parameter validation
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
64 resp->res = TMGW_RESP_ERR_PARAM;
7dae2bae56a1 themwi-mgw: implement MDCX parameter validation
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
65 return(-1);
7dae2bae56a1 themwi-mgw: implement MDCX parameter validation
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
66 }
32
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 bcopy(&req->pstn_addr, &ep->rtp_pstn.remote_addr,
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 sizeof(struct sockaddr_in));
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 ep->pstn_payload_type = req->pstn_payload_type;
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 }
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 if (req->setup_mask & TMGW_CTRL_MASK_FWD_MODE) {
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 if (ep->ep_type != TMGW_EP_TYPE_GATEWAY ||
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 ep->rtp_gsm.remote_addr.sin_family != AF_INET ||
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 ep->rtp_pstn.remote_addr.sin_family != AF_INET) {
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 resp->res = TMGW_RESP_ERR_PROT;
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 return(-1);
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 }
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 ep->fwd_mode = req->fwd_mode;
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 }
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 return(0);
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 }
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 void
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 process_mdcx(conn, req, resp)
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 struct ctrl_conn *conn;
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 struct tmgw_ctrl_req *req;
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 struct tmgw_ctrl_resp *resp;
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 {
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 struct endpoint *ep;
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 int rc;
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 ep = find_ep_by_id(conn, req->ep_id);
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 if (!ep) {
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 resp->res = TMGW_RESP_ERR_PROT;
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 return;
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 }
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 rc = mdcx_operation(ep, req, resp);
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 if (rc == 0)
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 resp->res = TMGW_RESP_OK;
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 }