FreeCalypso > hg > themwi-system-sw
comparison sip-out/mgw_ops.c @ 154:e54b0a9e322f
beginning of themwi-sip-out
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 11 Oct 2022 23:04:01 -0800 |
parents | sip-in/mgw_ops.c@0ecbc3dc8f93 |
children |
comparison
equal
deleted
inserted
replaced
153:99fd4ae573ae | 154:e54b0a9e322f |
---|---|
1 /* | |
2 * In this module we implement all transactions from themwi-sip-out | |
3 * toward themwi-mgw. | |
4 */ | |
5 | |
6 #include <sys/types.h> | |
7 #include <sys/socket.h> | |
8 #include <sys/time.h> | |
9 #include <netinet/in.h> | |
10 #include <stdio.h> | |
11 #include <stdint.h> | |
12 #include <stdlib.h> | |
13 #include <string.h> | |
14 #include <strings.h> | |
15 #include <syslog.h> | |
16 #include "../include/tmgw_ctrl.h" | |
17 #include "../include/tmgw_const.h" | |
18 #include "../include/out_routes.h" | |
19 #include "call.h" | |
20 | |
21 extern struct call *call_list; | |
22 | |
23 struct call * | |
24 find_call_with_mgw_xact(xact_id) | |
25 uint32_t xact_id; | |
26 { | |
27 struct call *call; | |
28 | |
29 for (call = call_list; call; call = call->next) | |
30 if (call->mgw_xact && call->mgw_xact_id == xact_id) | |
31 return call; | |
32 return 0; | |
33 } | |
34 | |
35 uint32_t | |
36 get_new_tmgw_xact_id() | |
37 { | |
38 static uint32_t next_xact_id; | |
39 | |
40 for (;;) { | |
41 next_xact_id++; | |
42 if (!find_call_with_mgw_xact(next_xact_id)) | |
43 return next_xact_id; | |
44 } | |
45 } | |
46 | |
47 void | |
48 tmgw_send_crcx(call) | |
49 struct call *call; | |
50 { | |
51 struct tmgw_ctrl_req req; | |
52 | |
53 bzero(&req, sizeof req); | |
54 req.opcode = TMGW_CTRL_OP_CRCX; | |
55 req.transact_ref = get_new_tmgw_xact_id(); | |
56 req.ep_id = TMGW_EP_TYPE_GATEWAY; | |
57 req.setup_mask = TMGW_CTRL_MASK_GSM_CONN; | |
58 bcopy(&call->gsm_rtp_osmo, &req.gsm_addr, | |
59 sizeof(struct sockaddr_storage)); | |
60 req.gsm_payload_type = call->gsm_payload_type; | |
61 req.gsm_payload_msg_type = call->gsm_payload_msg_type; | |
62 send_req_to_tmgw(&req); | |
63 call->mgw_xact = TMGW_CTRL_OP_CRCX; | |
64 call->mgw_xact_id = req.transact_ref; | |
65 } | |
66 | |
67 void | |
68 tmgw_send_mdcx_connect(call, ibt) | |
69 struct call *call; | |
70 { | |
71 struct tmgw_ctrl_req req; | |
72 | |
73 bzero(&req, sizeof req); | |
74 req.opcode = TMGW_CTRL_OP_MDCX; | |
75 req.transact_ref = get_new_tmgw_xact_id(); | |
76 req.ep_id = call->mgw_ep_id; | |
77 req.setup_mask = TMGW_CTRL_MASK_PSTN_CONN | TMGW_CTRL_MASK_FWD_MODE; | |
78 bcopy(&call->pstn_rtp_remote, &req.pstn_addr, | |
79 sizeof(struct sockaddr_in)); | |
80 req.pstn_payload_type = | |
81 call->use_pcma ? PSTN_CODEC_PCMA : PSTN_CODEC_PCMU; | |
82 req.fwd_mode = ibt ? TMGW_FWD_MODE_RECVONLY : TMGW_FWD_MODE_SENDRECV; | |
83 send_req_to_tmgw(&req); | |
84 call->mgw_state = ibt ? MGW_STATE_MDCX_IBT : MGW_STATE_MDCX_CONN; | |
85 call->mgw_xact = TMGW_CTRL_OP_MDCX; | |
86 call->mgw_xact_id = req.transact_ref; | |
87 } | |
88 | |
89 void | |
90 tmgw_send_mdcx_hold(call) | |
91 struct call *call; | |
92 { | |
93 struct tmgw_ctrl_req req; | |
94 | |
95 bzero(&req, sizeof req); | |
96 req.opcode = TMGW_CTRL_OP_MDCX; | |
97 req.transact_ref = get_new_tmgw_xact_id(); | |
98 req.ep_id = call->mgw_ep_id; | |
99 req.setup_mask = TMGW_CTRL_MASK_FWD_MODE; | |
100 req.fwd_mode = TMGW_FWD_MODE_INACTIVE; | |
101 send_req_to_tmgw(&req); | |
102 call->mgw_state = MGW_STATE_MDCX_HOLD; | |
103 call->mgw_xact = TMGW_CTRL_OP_MDCX; | |
104 call->mgw_xact_id = req.transact_ref; | |
105 } | |
106 | |
107 void | |
108 tmgw_send_mdcx_retrieve(call) | |
109 struct call *call; | |
110 { | |
111 struct tmgw_ctrl_req req; | |
112 | |
113 bzero(&req, sizeof req); | |
114 req.opcode = TMGW_CTRL_OP_MDCX; | |
115 req.transact_ref = get_new_tmgw_xact_id(); | |
116 req.ep_id = call->mgw_ep_id; | |
117 req.setup_mask = TMGW_CTRL_MASK_FWD_MODE; | |
118 req.fwd_mode = TMGW_FWD_MODE_SENDRECV; | |
119 send_req_to_tmgw(&req); | |
120 call->mgw_state = MGW_STATE_MDCX_RETR; | |
121 call->mgw_xact = TMGW_CTRL_OP_MDCX; | |
122 call->mgw_xact_id = req.transact_ref; | |
123 } | |
124 | |
125 void | |
126 tmgw_send_dlcx(call) | |
127 struct call *call; | |
128 { | |
129 struct tmgw_ctrl_req req; | |
130 | |
131 bzero(&req, sizeof req); | |
132 req.opcode = TMGW_CTRL_OP_DLCX; | |
133 req.transact_ref = get_new_tmgw_xact_id(); | |
134 req.ep_id = call->mgw_ep_id; | |
135 send_req_to_tmgw(&req); | |
136 call->mgw_state = MGW_STATE_DELETING; | |
137 call->mgw_xact = TMGW_CTRL_OP_DLCX; | |
138 call->mgw_xact_id = req.transact_ref; | |
139 } | |
140 | |
141 void | |
142 tmgw_send_dtmf_start(call) | |
143 struct call *call; | |
144 { | |
145 struct tmgw_ctrl_req req; | |
146 | |
147 bzero(&req, sizeof req); | |
148 req.opcode = TMGW_CTRL_OP_DTMF_START; | |
149 req.transact_ref = get_new_tmgw_xact_id(); | |
150 req.ep_id = call->mgw_ep_id; | |
151 req.fwd_mode = call->dtmf_digit; | |
152 send_req_to_tmgw(&req); | |
153 call->mgw_state = MGW_STATE_DTMF_OP; | |
154 call->mgw_xact = TMGW_CTRL_OP_DTMF_START; | |
155 call->mgw_xact_id = req.transact_ref; | |
156 } | |
157 | |
158 void | |
159 tmgw_send_dtmf_stop(call) | |
160 struct call *call; | |
161 { | |
162 struct tmgw_ctrl_req req; | |
163 | |
164 bzero(&req, sizeof req); | |
165 req.opcode = TMGW_CTRL_OP_DTMF_STOP; | |
166 req.transact_ref = get_new_tmgw_xact_id(); | |
167 req.ep_id = call->mgw_ep_id; | |
168 send_req_to_tmgw(&req); | |
169 call->mgw_state = MGW_STATE_DTMF_OP; | |
170 call->mgw_xact = TMGW_CTRL_OP_DTMF_STOP; | |
171 call->mgw_xact_id = req.transact_ref; | |
172 } |