annotate mgw/gsm2pstn.c @ 123:a36b731bfef9

sip-manual-out: implement sending BYE and CANCEL
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 29 Sep 2022 17:21:11 -0800
parents 3b3f07b112f3
children f062c32a5116
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
103
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * In this module we implement our RTP gateway function
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * in the GSM to PSTN direction.
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/types.h>
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <sys/socket.h>
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <netinet/in.h>
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdio.h>
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdint.h>
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <stdlib.h>
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <string.h>
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <strings.h>
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include <syslog.h>
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include <unistd.h>
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 #include <gsm.h> /* libgsm dependency */
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 #include "../include/tmgw_ctrl.h"
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 #include "../include/tmgw_const.h"
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 #include "struct.h"
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 #include "select.h"
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 #include "int_defs.h"
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 #define ERR_WRONG_UDP_SRC 0x0001
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 #define ERR_BAD_RTP_PACKET 0x0002
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 #define ERR_SSRC_CHANGE 0x0004
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 #define ERR_SEQ_BREAK 0x0008
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 #define ERR_TSTAMP_BREAK 0x0010
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 void
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 gsm2pstn_rtp_in(in_fd, ep)
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 struct endpoint *ep;
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 {
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 struct rtp_packet pkt;
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 struct sockaddr_in sin_from;
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 socklen_t addrlen;
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 int16_t seq_delta;
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 int32_t ts_delta;
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 int16_t pcm_samples[SAMPLES_PER_FRAME];
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 int rc, m_out;
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 addrlen = sizeof(struct sockaddr_in);
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 rc = recvfrom(in_fd, &pkt, sizeof pkt, 0,
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 (struct sockaddr *) &sin_from, &addrlen);
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 if (rc < 0)
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 return;
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 if (sin_from.sin_addr.s_addr != ep->rtp_gsm.remote_addr.sin_addr.s_addr
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 || sin_from.sin_port != ep->rtp_gsm.remote_addr.sin_port) {
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 if (!(ep->g2p_err_flags & ERR_WRONG_UDP_SRC)) {
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 syslog(LOG_ERR,
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 "GSM RTP ep got UDP packet from wrong source");
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 ep->g2p_err_flags |= ERR_WRONG_UDP_SRC;
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 }
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 return;
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 }
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 if (rc != ep->gsm_rtp_pkt_size) {
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 bad_rtp_pkt: if (!(ep->g2p_err_flags & ERR_BAD_RTP_PACKET)) {
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 syslog(LOG_ERR, "Rx bad RTP packet on GSM side");
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 ep->g2p_err_flags |= ERR_BAD_RTP_PACKET;
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 }
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 return;
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 }
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 if (pkt.v_p_x_cc != 0x80)
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 goto bad_rtp_pkt;
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 if ((pkt.m_pt & 0x7F) != ep->gsm_payload_type)
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 goto bad_rtp_pkt;
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 if ((pkt.payload[0] & 0xF0) != ep->gsm_payload_magic)
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 goto bad_rtp_pkt;
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 if (ep->g2p_state && pkt.ssrc != ep->g2p_ssrc) {
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 if (!(ep->g2p_err_flags & ERR_SSRC_CHANGE)) {
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 syslog(LOG_ERR, "GSM RTP stream changed SSRC");
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 ep->g2p_err_flags |= ERR_SSRC_CHANGE;
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 }
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 ep->g2p_state = 0;
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 }
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 if (ep->g2p_state) {
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 seq_delta = ntohs(pkt.seq) - ep->g2p_last_seq;
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 ts_delta = ntohl(pkt.tstamp) - ep->g2p_last_ts;
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 if (seq_delta <= 0)
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 return; /* discard old or duplicate */
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 if (seq_delta != 1) {
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 if (!(ep->g2p_err_flags & ERR_SEQ_BREAK)) {
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 syslog(LOG_ERR, "GSM RTP stream seq break");
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 ep->g2p_err_flags |= ERR_SEQ_BREAK;
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 }
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 m_out = 1;
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 } else {
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 if (ts_delta == SAMPLES_PER_FRAME)
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 m_out = 0;
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 else if (ts_delta > 0 &&
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 ts_delta % SAMPLES_PER_FRAME == 0)
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 m_out = 1;
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 else {
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 if (!(ep->g2p_err_flags & ERR_TSTAMP_BREAK)) {
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 syslog(LOG_ERR,
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 "GSM RTP stream tstamp break");
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 ep->g2p_err_flags |= ERR_TSTAMP_BREAK;
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 }
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 m_out = 1;
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 }
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 }
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 } else
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 m_out = 1;
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 ep->g2p_state = 1;
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 ep->g2p_ssrc = pkt.ssrc;
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 ep->g2p_last_ts = ntohl(pkt.tstamp);
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 ep->g2p_last_seq = ntohs(pkt.seq);
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 /* actual transcoding and forwarding */
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 if (!(ep->fwd_mode & TMGW_FWD_ENABLE_GSM2PSTN)) {
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 ep->g2p_drop_flag = 1;
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 return;
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 }
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 if (ep->g2p_drop_flag) {
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 ep->g2p_drop_flag = 0;
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 m_out = 1;
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 }
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 switch (ep->gsm_payload_msg_type) {
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 case GSM_TCHF_FRAME:
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 gsm_decode(ep->gsm_decoder_state, pkt.payload, pcm_samples);
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 break;
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 }
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 pkt.m_pt = ep->pstn_payload_type;
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 if (m_out)
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 pkt.m_pt |= 0x80;
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 pkt.seq = htons(++ep->g2p_out_seq);
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 g711_encode_frame(pcm_samples, pkt.payload, ep->pstn_payload_type);
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 addrlen = sizeof(struct sockaddr_in);
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 sendto(ep->rtp_pstn.rtp_fd, &pkt, RTP_PACKET_SIZE_PSTN, 0,
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 (struct sockaddr *) &ep->rtp_pstn.remote_addr, addrlen);
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 }
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 gsm2pstn_init(ep)
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 struct endpoint *ep;
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 {
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 if (ep->gsm_decoder_state)
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 return TMGW_RESP_OK;
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 switch (ep->gsm_payload_msg_type) {
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 case GSM_TCHF_FRAME:
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 ep->gsm_decoder_state = gsm_create();
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 if (!ep->gsm_decoder_state)
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 return TMGW_RESP_ERR_RSRC;
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 break;
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 }
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 select_handlers[ep->rtp_gsm.rtp_fd] = gsm2pstn_rtp_in;
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 return TMGW_RESP_OK;
3b3f07b112f3 mgw: implement GSM to PSTN forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 }