comparison mgw/mdcx.c @ 99:738be11ac432

mgw internal code: simplify MDCX error handling
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 26 Sep 2022 13:42:46 -0800
parents f280328e7e2e
children 1579ec0e9fb9
comparison
equal deleted inserted replaced
98:423610bb2c9e 99:738be11ac432
15 #include "../include/tmgw_const.h" 15 #include "../include/tmgw_const.h"
16 #include "struct.h" 16 #include "struct.h"
17 17
18 extern struct endpoint *find_ep_by_id(); 18 extern struct endpoint *find_ep_by_id();
19 19
20 mdcx_operation(ep, req, resp) 20 mdcx_operation(ep, req)
21 struct endpoint *ep; 21 struct endpoint *ep;
22 struct tmgw_ctrl_req *req; 22 struct tmgw_ctrl_req *req;
23 struct tmgw_ctrl_resp *resp;
24 { 23 {
25 int rc; 24 int rc;
26 25
27 if (req->setup_mask & TMGW_CTRL_MASK_GSM_CONN) { 26 if (req->setup_mask & TMGW_CTRL_MASK_GSM_CONN) {
28 if (ep->ep_type != TMGW_EP_TYPE_GATEWAY) { 27 if (ep->ep_type != TMGW_EP_TYPE_GATEWAY)
29 resp->res = TMGW_RESP_ERR_PROT; 28 return TMGW_RESP_ERR_PROT;
30 return(-1); 29 if (req->gsm_addr.ss_family != AF_INET)
31 } 30 return TMGW_RESP_ERR_PARAM;
32 if (req->gsm_addr.ss_family != AF_INET) { 31 if (req->gsm_payload_type > 0x7F)
33 resp->res = TMGW_RESP_ERR_PARAM; 32 return TMGW_RESP_ERR_PARAM;
34 return(-1);
35 }
36 if (req->gsm_payload_type > 0x7F) {
37 resp->res = TMGW_RESP_ERR_PARAM;
38 return(-1);
39 }
40 switch (req->gsm_payload_msg_type) { 33 switch (req->gsm_payload_msg_type) {
41 case GSM_TCHF_FRAME: 34 case GSM_TCHF_FRAME:
42 break; 35 break;
43 case GSM_TCHF_FRAME_EFR: 36 case GSM_TCHF_FRAME_EFR:
44 case GSM_TCHH_FRAME: 37 case GSM_TCHH_FRAME:
45 case GSM_TCH_FRAME_AMR: 38 case GSM_TCH_FRAME_AMR:
46 resp->res = TMGW_RESP_ERR_NOTSUP; 39 return TMGW_RESP_ERR_NOTSUP;
47 return(-1);
48 default: 40 default:
49 resp->res = TMGW_RESP_ERR_PARAM; 41 return TMGW_RESP_ERR_PARAM;
50 return(-1);
51 } 42 }
52 if (ep->gsm_payload_msg_type && 43 if (ep->gsm_payload_msg_type &&
53 ep->gsm_payload_msg_type != req->gsm_payload_msg_type) { 44 ep->gsm_payload_msg_type != req->gsm_payload_msg_type)
54 resp->res = TMGW_RESP_ERR_PROT; 45 return TMGW_RESP_ERR_PROT;
55 return(-1);
56 }
57 bcopy(&req->gsm_addr, &ep->rtp_gsm.remote_addr, 46 bcopy(&req->gsm_addr, &ep->rtp_gsm.remote_addr,
58 sizeof(struct sockaddr_in)); 47 sizeof(struct sockaddr_in));
59 ep->gsm_payload_type = req->gsm_payload_type; 48 ep->gsm_payload_type = req->gsm_payload_type;
60 ep->gsm_payload_msg_type = req->gsm_payload_msg_type; 49 ep->gsm_payload_msg_type = req->gsm_payload_msg_type;
61 } 50 }
62 if (req->setup_mask & TMGW_CTRL_MASK_PSTN_CONN) { 51 if (req->setup_mask & TMGW_CTRL_MASK_PSTN_CONN) {
63 if (ep->ep_type != TMGW_EP_TYPE_GATEWAY) { 52 if (ep->ep_type != TMGW_EP_TYPE_GATEWAY)
64 resp->res = TMGW_RESP_ERR_PROT; 53 return TMGW_RESP_ERR_PROT;
65 return(-1); 54 if (req->pstn_addr.ss_family != AF_INET)
66 } 55 return TMGW_RESP_ERR_PARAM;
67 if (req->pstn_addr.ss_family != AF_INET) {
68 resp->res = TMGW_RESP_ERR_PARAM;
69 return(-1);
70 }
71 switch (req->pstn_payload_type) { 56 switch (req->pstn_payload_type) {
72 case PSTN_CODEC_PCMU: 57 case PSTN_CODEC_PCMU:
73 case PSTN_CODEC_PCMA: 58 case PSTN_CODEC_PCMA:
74 break; 59 break;
75 default: 60 default:
76 resp->res = TMGW_RESP_ERR_PARAM; 61 return TMGW_RESP_ERR_PARAM;
77 return(-1);
78 } 62 }
79 bcopy(&req->pstn_addr, &ep->rtp_pstn.remote_addr, 63 bcopy(&req->pstn_addr, &ep->rtp_pstn.remote_addr,
80 sizeof(struct sockaddr_in)); 64 sizeof(struct sockaddr_in));
81 ep->pstn_payload_type = req->pstn_payload_type; 65 ep->pstn_payload_type = req->pstn_payload_type;
82 } 66 }
83 if (req->setup_mask & TMGW_CTRL_MASK_FWD_MODE) { 67 if (req->setup_mask & TMGW_CTRL_MASK_FWD_MODE) {
84 if (ep->ep_type != TMGW_EP_TYPE_GATEWAY || 68 if (ep->ep_type != TMGW_EP_TYPE_GATEWAY ||
85 ep->rtp_gsm.remote_addr.sin_family != AF_INET || 69 ep->rtp_gsm.remote_addr.sin_family != AF_INET ||
86 ep->rtp_pstn.remote_addr.sin_family != AF_INET) { 70 ep->rtp_pstn.remote_addr.sin_family != AF_INET)
87 resp->res = TMGW_RESP_ERR_PROT; 71 return TMGW_RESP_ERR_PROT;
88 return(-1);
89 }
90 if ((req->fwd_mode & TMGW_FWD_ENABLE_PSTN2GSM) && 72 if ((req->fwd_mode & TMGW_FWD_ENABLE_PSTN2GSM) &&
91 !(ep->fwd_mode & TMGW_FWD_ENABLE_PSTN2GSM)) { 73 !(ep->fwd_mode & TMGW_FWD_ENABLE_PSTN2GSM)) {
92 rc = pstn2gsm_init(ep); 74 rc = pstn2gsm_init(ep);
93 if (rc != TMGW_RESP_OK) { 75 if (rc != TMGW_RESP_OK)
94 resp->res = rc; 76 return rc;
95 return(-1);
96 }
97 } 77 }
98 ep->fwd_mode = req->fwd_mode; 78 ep->fwd_mode = req->fwd_mode;
99 } 79 }
100 return(0); 80 return TMGW_RESP_OK;
101 } 81 }
102 82
103 void 83 void
104 process_mdcx(conn, req, resp) 84 process_mdcx(conn, req, resp)
105 struct ctrl_conn *conn; 85 struct ctrl_conn *conn;
112 ep = find_ep_by_id(conn, req->ep_id); 92 ep = find_ep_by_id(conn, req->ep_id);
113 if (!ep) { 93 if (!ep) {
114 resp->res = TMGW_RESP_ERR_PROT; 94 resp->res = TMGW_RESP_ERR_PROT;
115 return; 95 return;
116 } 96 }
117 rc = mdcx_operation(ep, req, resp); 97 resp->res = mdcx_operation(ep, req);
118 if (rc == 0)
119 resp->res = TMGW_RESP_OK;
120 } 98 }