annotate mgw/mdcx.c @ 100:1579ec0e9fb9

mgw internal code: set GSM side RTP packet size in one place and also set payload magic value for use by GSM->PSTN code
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 26 Sep 2022 13:57:20 -0800
parents 738be11ac432
children 3b3f07b112f3
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>
38
020ba624bdd8 mgw source: #include <stdlib.h> in files using tmgw_ctrl.h
Mychaela Falconia <falcon@freecalypso.org>
parents: 34
diff changeset
9 #include <stdint.h>
32
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdlib.h>
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <string.h>
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <strings.h>
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <syslog.h>
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include "../include/tmgw_ctrl.h"
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include "../include/tmgw_const.h"
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 #include "struct.h"
100
1579ec0e9fb9 mgw internal code: set GSM side RTP packet size in one place
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
17 #include "int_defs.h"
32
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 extern struct endpoint *find_ep_by_id();
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20
100
1579ec0e9fb9 mgw internal code: set GSM side RTP packet size in one place
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
21 static void
1579ec0e9fb9 mgw internal code: set GSM side RTP packet size in one place
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
22 gsm_vars_init(ep)
1579ec0e9fb9 mgw internal code: set GSM side RTP packet size in one place
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
23 struct endpoint *ep;
1579ec0e9fb9 mgw internal code: set GSM side RTP packet size in one place
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
24 {
1579ec0e9fb9 mgw internal code: set GSM side RTP packet size in one place
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
25 switch (ep->gsm_payload_msg_type) {
1579ec0e9fb9 mgw internal code: set GSM side RTP packet size in one place
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
26 case GSM_TCHF_FRAME:
1579ec0e9fb9 mgw internal code: set GSM side RTP packet size in one place
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
27 ep->gsm_rtp_pkt_size = RTP_PACKET_SIZE_GSM_FR;
1579ec0e9fb9 mgw internal code: set GSM side RTP packet size in one place
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
28 ep->gsm_payload_magic = 0xD0;
1579ec0e9fb9 mgw internal code: set GSM side RTP packet size in one place
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
29 return;
1579ec0e9fb9 mgw internal code: set GSM side RTP packet size in one place
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
30 case GSM_TCHF_FRAME_EFR:
1579ec0e9fb9 mgw internal code: set GSM side RTP packet size in one place
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
31 ep->gsm_rtp_pkt_size = RTP_PACKET_SIZE_GSM_EFR;
1579ec0e9fb9 mgw internal code: set GSM side RTP packet size in one place
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
32 ep->gsm_payload_magic = 0xC0;
1579ec0e9fb9 mgw internal code: set GSM side RTP packet size in one place
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
33 return;
1579ec0e9fb9 mgw internal code: set GSM side RTP packet size in one place
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
34 }
1579ec0e9fb9 mgw internal code: set GSM side RTP packet size in one place
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
35 }
1579ec0e9fb9 mgw internal code: set GSM side RTP packet size in one place
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
36
99
738be11ac432 mgw internal code: simplify MDCX error handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 95
diff changeset
37 mdcx_operation(ep, req)
32
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 struct endpoint *ep;
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 struct tmgw_ctrl_req *req;
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 {
95
f280328e7e2e themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents: 38
diff changeset
41 int rc;
f280328e7e2e themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents: 38
diff changeset
42
32
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 if (req->setup_mask & TMGW_CTRL_MASK_GSM_CONN) {
99
738be11ac432 mgw internal code: simplify MDCX error handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 95
diff changeset
44 if (ep->ep_type != TMGW_EP_TYPE_GATEWAY)
738be11ac432 mgw internal code: simplify MDCX error handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 95
diff changeset
45 return TMGW_RESP_ERR_PROT;
738be11ac432 mgw internal code: simplify MDCX error handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 95
diff changeset
46 if (req->gsm_addr.ss_family != AF_INET)
738be11ac432 mgw internal code: simplify MDCX error handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 95
diff changeset
47 return TMGW_RESP_ERR_PARAM;
738be11ac432 mgw internal code: simplify MDCX error handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 95
diff changeset
48 if (req->gsm_payload_type > 0x7F)
738be11ac432 mgw internal code: simplify MDCX error handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 95
diff changeset
49 return TMGW_RESP_ERR_PARAM;
34
7dae2bae56a1 themwi-mgw: implement MDCX parameter validation
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
50 switch (req->gsm_payload_msg_type) {
7dae2bae56a1 themwi-mgw: implement MDCX parameter validation
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
51 case GSM_TCHF_FRAME:
7dae2bae56a1 themwi-mgw: implement MDCX parameter validation
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
52 break;
7dae2bae56a1 themwi-mgw: implement MDCX parameter validation
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
53 case GSM_TCHF_FRAME_EFR:
7dae2bae56a1 themwi-mgw: implement MDCX parameter validation
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
54 case GSM_TCHH_FRAME:
7dae2bae56a1 themwi-mgw: implement MDCX parameter validation
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
55 case GSM_TCH_FRAME_AMR:
99
738be11ac432 mgw internal code: simplify MDCX error handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 95
diff changeset
56 return TMGW_RESP_ERR_NOTSUP;
34
7dae2bae56a1 themwi-mgw: implement MDCX parameter validation
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
57 default:
99
738be11ac432 mgw internal code: simplify MDCX error handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 95
diff changeset
58 return TMGW_RESP_ERR_PARAM;
34
7dae2bae56a1 themwi-mgw: implement MDCX parameter validation
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
59 }
95
f280328e7e2e themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents: 38
diff changeset
60 if (ep->gsm_payload_msg_type &&
99
738be11ac432 mgw internal code: simplify MDCX error handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 95
diff changeset
61 ep->gsm_payload_msg_type != req->gsm_payload_msg_type)
738be11ac432 mgw internal code: simplify MDCX error handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 95
diff changeset
62 return TMGW_RESP_ERR_PROT;
32
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 bcopy(&req->gsm_addr, &ep->rtp_gsm.remote_addr,
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 sizeof(struct sockaddr_in));
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 ep->gsm_payload_type = req->gsm_payload_type;
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 ep->gsm_payload_msg_type = req->gsm_payload_msg_type;
100
1579ec0e9fb9 mgw internal code: set GSM side RTP packet size in one place
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
67 gsm_vars_init(ep);
32
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 }
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 if (req->setup_mask & TMGW_CTRL_MASK_PSTN_CONN) {
99
738be11ac432 mgw internal code: simplify MDCX error handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 95
diff changeset
70 if (ep->ep_type != TMGW_EP_TYPE_GATEWAY)
738be11ac432 mgw internal code: simplify MDCX error handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 95
diff changeset
71 return TMGW_RESP_ERR_PROT;
738be11ac432 mgw internal code: simplify MDCX error handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 95
diff changeset
72 if (req->pstn_addr.ss_family != AF_INET)
738be11ac432 mgw internal code: simplify MDCX error handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 95
diff changeset
73 return TMGW_RESP_ERR_PARAM;
34
7dae2bae56a1 themwi-mgw: implement MDCX parameter validation
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
74 switch (req->pstn_payload_type) {
7dae2bae56a1 themwi-mgw: implement MDCX parameter validation
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
75 case PSTN_CODEC_PCMU:
7dae2bae56a1 themwi-mgw: implement MDCX parameter validation
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
76 case PSTN_CODEC_PCMA:
7dae2bae56a1 themwi-mgw: implement MDCX parameter validation
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
77 break;
7dae2bae56a1 themwi-mgw: implement MDCX parameter validation
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
78 default:
99
738be11ac432 mgw internal code: simplify MDCX error handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 95
diff changeset
79 return TMGW_RESP_ERR_PARAM;
34
7dae2bae56a1 themwi-mgw: implement MDCX parameter validation
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
80 }
32
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 bcopy(&req->pstn_addr, &ep->rtp_pstn.remote_addr,
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 sizeof(struct sockaddr_in));
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 ep->pstn_payload_type = req->pstn_payload_type;
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 }
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 if (req->setup_mask & TMGW_CTRL_MASK_FWD_MODE) {
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 if (ep->ep_type != TMGW_EP_TYPE_GATEWAY ||
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 ep->rtp_gsm.remote_addr.sin_family != AF_INET ||
99
738be11ac432 mgw internal code: simplify MDCX error handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 95
diff changeset
88 ep->rtp_pstn.remote_addr.sin_family != AF_INET)
738be11ac432 mgw internal code: simplify MDCX error handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 95
diff changeset
89 return TMGW_RESP_ERR_PROT;
95
f280328e7e2e themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents: 38
diff changeset
90 if ((req->fwd_mode & TMGW_FWD_ENABLE_PSTN2GSM) &&
f280328e7e2e themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents: 38
diff changeset
91 !(ep->fwd_mode & TMGW_FWD_ENABLE_PSTN2GSM)) {
f280328e7e2e themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents: 38
diff changeset
92 rc = pstn2gsm_init(ep);
99
738be11ac432 mgw internal code: simplify MDCX error handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 95
diff changeset
93 if (rc != TMGW_RESP_OK)
738be11ac432 mgw internal code: simplify MDCX error handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 95
diff changeset
94 return rc;
95
f280328e7e2e themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents: 38
diff changeset
95 }
32
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 ep->fwd_mode = req->fwd_mode;
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 }
99
738be11ac432 mgw internal code: simplify MDCX error handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 95
diff changeset
98 return TMGW_RESP_OK;
32
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 }
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 void
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 process_mdcx(conn, req, resp)
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 struct ctrl_conn *conn;
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 struct tmgw_ctrl_req *req;
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 struct tmgw_ctrl_resp *resp;
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 {
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 struct endpoint *ep;
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 int rc;
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 ep = find_ep_by_id(conn, req->ep_id);
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 if (!ep) {
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 resp->res = TMGW_RESP_ERR_PROT;
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 return;
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 }
99
738be11ac432 mgw internal code: simplify MDCX error handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 95
diff changeset
115 resp->res = mdcx_operation(ep, req);
32
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 }