FreeCalypso > hg > themwi-system-sw
annotate 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 |
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" |
b3f74df7b808
beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 |
b3f74df7b808
beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 extern struct endpoint *find_ep_by_id(); |
b3f74df7b808
beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 |
99
738be11ac432
mgw internal code: simplify MDCX error handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
95
diff
changeset
|
20 mdcx_operation(ep, req) |
32
b3f74df7b808
beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 struct endpoint *ep; |
b3f74df7b808
beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 struct tmgw_ctrl_req *req; |
b3f74df7b808
beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 { |
95
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
38
diff
changeset
|
24 int rc; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
38
diff
changeset
|
25 |
32
b3f74df7b808
beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 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
|
27 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
|
28 return TMGW_RESP_ERR_PROT; |
738be11ac432
mgw internal code: simplify MDCX error handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
95
diff
changeset
|
29 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
|
30 return TMGW_RESP_ERR_PARAM; |
738be11ac432
mgw internal code: simplify MDCX error handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
95
diff
changeset
|
31 if (req->gsm_payload_type > 0x7F) |
738be11ac432
mgw internal code: simplify MDCX error handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
95
diff
changeset
|
32 return TMGW_RESP_ERR_PARAM; |
34
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: |
99
738be11ac432
mgw internal code: simplify MDCX error handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
95
diff
changeset
|
39 return TMGW_RESP_ERR_NOTSUP; |
34
7dae2bae56a1
themwi-mgw: implement MDCX parameter validation
Mychaela Falconia <falcon@freecalypso.org>
parents:
32
diff
changeset
|
40 default: |
99
738be11ac432
mgw internal code: simplify MDCX error handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
95
diff
changeset
|
41 return TMGW_RESP_ERR_PARAM; |
34
7dae2bae56a1
themwi-mgw: implement MDCX parameter validation
Mychaela Falconia <falcon@freecalypso.org>
parents:
32
diff
changeset
|
42 } |
95
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
38
diff
changeset
|
43 if (ep->gsm_payload_msg_type && |
99
738be11ac432
mgw internal code: simplify MDCX error handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
95
diff
changeset
|
44 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
|
45 return TMGW_RESP_ERR_PROT; |
32
b3f74df7b808
beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 bcopy(&req->gsm_addr, &ep->rtp_gsm.remote_addr, |
b3f74df7b808
beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 sizeof(struct sockaddr_in)); |
b3f74df7b808
beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 ep->gsm_payload_type = req->gsm_payload_type; |
b3f74df7b808
beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 ep->gsm_payload_msg_type = req->gsm_payload_msg_type; |
b3f74df7b808
beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 } |
b3f74df7b808
beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 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
|
52 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
|
53 return TMGW_RESP_ERR_PROT; |
738be11ac432
mgw internal code: simplify MDCX error handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
95
diff
changeset
|
54 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
|
55 return TMGW_RESP_ERR_PARAM; |
34
7dae2bae56a1
themwi-mgw: implement MDCX parameter validation
Mychaela Falconia <falcon@freecalypso.org>
parents:
32
diff
changeset
|
56 switch (req->pstn_payload_type) { |
7dae2bae56a1
themwi-mgw: implement MDCX parameter validation
Mychaela Falconia <falcon@freecalypso.org>
parents:
32
diff
changeset
|
57 case PSTN_CODEC_PCMU: |
7dae2bae56a1
themwi-mgw: implement MDCX parameter validation
Mychaela Falconia <falcon@freecalypso.org>
parents:
32
diff
changeset
|
58 case PSTN_CODEC_PCMA: |
7dae2bae56a1
themwi-mgw: implement MDCX parameter validation
Mychaela Falconia <falcon@freecalypso.org>
parents:
32
diff
changeset
|
59 break; |
7dae2bae56a1
themwi-mgw: implement MDCX parameter validation
Mychaela Falconia <falcon@freecalypso.org>
parents:
32
diff
changeset
|
60 default: |
99
738be11ac432
mgw internal code: simplify MDCX error handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
95
diff
changeset
|
61 return TMGW_RESP_ERR_PARAM; |
34
7dae2bae56a1
themwi-mgw: implement MDCX parameter validation
Mychaela Falconia <falcon@freecalypso.org>
parents:
32
diff
changeset
|
62 } |
32
b3f74df7b808
beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 bcopy(&req->pstn_addr, &ep->rtp_pstn.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->pstn_payload_type = req->pstn_payload_type; |
b3f74df7b808
beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 } |
b3f74df7b808
beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 if (req->setup_mask & TMGW_CTRL_MASK_FWD_MODE) { |
b3f74df7b808
beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 if (ep->ep_type != TMGW_EP_TYPE_GATEWAY || |
b3f74df7b808
beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 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
|
70 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
|
71 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
|
72 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
|
73 !(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
|
74 rc = pstn2gsm_init(ep); |
99
738be11ac432
mgw internal code: simplify MDCX error handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
95
diff
changeset
|
75 if (rc != TMGW_RESP_OK) |
738be11ac432
mgw internal code: simplify MDCX error handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
95
diff
changeset
|
76 return rc; |
95
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
38
diff
changeset
|
77 } |
32
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 } |
99
738be11ac432
mgw internal code: simplify MDCX error handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
95
diff
changeset
|
80 return TMGW_RESP_OK; |
32
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 } |
99
738be11ac432
mgw internal code: simplify MDCX error handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
95
diff
changeset
|
97 resp->res = mdcx_operation(ep, req); |
32
b3f74df7b808
beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 } |