FreeCalypso > hg > themwi-system-sw
annotate mgw/pstn2gsm.c @ 192:f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 17 Mar 2023 13:45:31 -0800 |
parents | c985c33baeac |
children | cf1ba5d65188 |
rev | line source |
---|---|
95
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * In this module we implement our RTP gateway function |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * in the PSTN to GSM direction. |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <sys/types.h> |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <sys/socket.h> |
127
f062c32a5116
mgw: implement DTMF
Mychaela Falconia <falcon@freecalypso.org>
parents:
102
diff
changeset
|
8 #include <sys/time.h> |
95
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <netinet/in.h> |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <stdio.h> |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <stdint.h> |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <stdlib.h> |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include <string.h> |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #include <strings.h> |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 #include <syslog.h> |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 #include <unistd.h> |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 #include <gsm.h> /* libgsm dependency */ |
174
c985c33baeac
mgw: support EFR by way of libgsmefr
Mychaela Falconia <falcon@freecalypso.org>
parents:
127
diff
changeset
|
18 #include <gsm_efr.h> |
95
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 #include "../include/tmgw_ctrl.h" |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 #include "../include/tmgw_const.h" |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 #include "struct.h" |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 #include "select.h" |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 #include "int_defs.h" |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 extern uint16_t pcmu_decode_table[256]; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 extern uint16_t pcma_decode_table[256]; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 #define ERR_WRONG_UDP_SRC 0x0001 |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 #define ERR_BAD_RTP_PACKET 0x0002 |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 #define ERR_SSRC_CHANGE 0x0004 |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 #define ERR_SEQ_BREAK 0x0008 |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 #define ERR_TSTAMP_BREAK 0x0010 |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 void |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 pstn2gsm_rtp_in(in_fd, ep) |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 struct endpoint *ep; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 { |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 struct rtp_packet pkt; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 struct sockaddr_in sin_from; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 socklen_t addrlen; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 uint16_t *pcm_dec_table; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 int16_t seq_delta; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 int32_t ts_delta; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 int16_t pcm_samples[SAMPLES_PER_FRAME]; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 unsigned n; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 int rc, m_out; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 addrlen = sizeof(struct sockaddr_in); |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 rc = recvfrom(in_fd, &pkt, sizeof pkt, 0, |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 (struct sockaddr *) &sin_from, &addrlen); |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 if (rc < 0) |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 return; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 if (sin_from.sin_addr.s_addr != ep->rtp_pstn.remote_addr.sin_addr.s_addr |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 || sin_from.sin_port != ep->rtp_pstn.remote_addr.sin_port) { |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 if (!(ep->p2g_err_flags & ERR_WRONG_UDP_SRC)) { |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 syslog(LOG_ERR, |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 "PSTN RTP ep got UDP packet from wrong source"); |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 ep->p2g_err_flags |= ERR_WRONG_UDP_SRC; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 } |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 return; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 } |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 if (rc != RTP_PACKET_SIZE_PSTN) { |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 bad_rtp_pkt: if (!(ep->p2g_err_flags & ERR_BAD_RTP_PACKET)) { |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 syslog(LOG_ERR, "Rx bad RTP packet on PSTN side"); |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 ep->p2g_err_flags |= ERR_BAD_RTP_PACKET; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 } |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 return; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 } |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 if (pkt.v_p_x_cc != 0x80) |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 goto bad_rtp_pkt; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 switch (pkt.m_pt & 0x7F) { |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 case PSTN_CODEC_PCMU: |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 pcm_dec_table = pcmu_decode_table; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 break; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 case PSTN_CODEC_PCMA: |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 pcm_dec_table = pcma_decode_table; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 break; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 default: |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 goto bad_rtp_pkt; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 } |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 if (ep->p2g_state && pkt.ssrc != ep->p2g_ssrc) { |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 if (!(ep->p2g_err_flags & ERR_SSRC_CHANGE)) { |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 syslog(LOG_ERR, "PSTN RTP stream changed SSRC"); |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 ep->p2g_err_flags |= ERR_SSRC_CHANGE; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 } |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 ep->p2g_state = 0; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 } |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 if (ep->p2g_state) { |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 seq_delta = ntohs(pkt.seq) - ep->p2g_last_seq; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 ts_delta = ntohl(pkt.tstamp) - ep->p2g_last_ts; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 if (seq_delta <= 0) |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 return; /* discard old or duplicate */ |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 if (seq_delta != 1) { |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 if (!(ep->p2g_err_flags & ERR_SEQ_BREAK)) { |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 syslog(LOG_ERR, "PSTN RTP stream seq break"); |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 ep->p2g_err_flags |= ERR_SEQ_BREAK; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 } |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 m_out = 1; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 } else if (ts_delta != SAMPLES_PER_FRAME) { |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 if (!(ep->p2g_err_flags & ERR_TSTAMP_BREAK)) { |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 syslog(LOG_ERR, "PSTN RTP stream tstamp break"); |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 ep->p2g_err_flags |= ERR_TSTAMP_BREAK; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 } |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 m_out = 1; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 } else |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 m_out = 0; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 } else |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 m_out = 1; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 ep->p2g_state = 1; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 ep->p2g_ssrc = pkt.ssrc; |
96
f24bbfd23c9d
mgw p2g: outgoing seq numbers, forwarding control
Mychaela Falconia <falcon@freecalypso.org>
parents:
95
diff
changeset
|
111 ep->p2g_last_ts = ntohl(pkt.tstamp); |
f24bbfd23c9d
mgw p2g: outgoing seq numbers, forwarding control
Mychaela Falconia <falcon@freecalypso.org>
parents:
95
diff
changeset
|
112 ep->p2g_last_seq = ntohs(pkt.seq); |
95
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 /* actual transcoding and forwarding */ |
97
9aed16c30622
mgw p2g: set M bit when restarting forwarding after no-forward
Mychaela Falconia <falcon@freecalypso.org>
parents:
96
diff
changeset
|
114 if (!(ep->fwd_mode & TMGW_FWD_ENABLE_PSTN2GSM)) { |
9aed16c30622
mgw p2g: set M bit when restarting forwarding after no-forward
Mychaela Falconia <falcon@freecalypso.org>
parents:
96
diff
changeset
|
115 ep->p2g_drop_flag = 1; |
96
f24bbfd23c9d
mgw p2g: outgoing seq numbers, forwarding control
Mychaela Falconia <falcon@freecalypso.org>
parents:
95
diff
changeset
|
116 return; |
97
9aed16c30622
mgw p2g: set M bit when restarting forwarding after no-forward
Mychaela Falconia <falcon@freecalypso.org>
parents:
96
diff
changeset
|
117 } |
9aed16c30622
mgw p2g: set M bit when restarting forwarding after no-forward
Mychaela Falconia <falcon@freecalypso.org>
parents:
96
diff
changeset
|
118 if (ep->p2g_drop_flag) { |
9aed16c30622
mgw p2g: set M bit when restarting forwarding after no-forward
Mychaela Falconia <falcon@freecalypso.org>
parents:
96
diff
changeset
|
119 ep->p2g_drop_flag = 0; |
9aed16c30622
mgw p2g: set M bit when restarting forwarding after no-forward
Mychaela Falconia <falcon@freecalypso.org>
parents:
96
diff
changeset
|
120 m_out = 1; |
9aed16c30622
mgw p2g: set M bit when restarting forwarding after no-forward
Mychaela Falconia <falcon@freecalypso.org>
parents:
96
diff
changeset
|
121 } |
95
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 for (n = 0; n < SAMPLES_PER_FRAME; n++) |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 pcm_samples[n] = pcm_dec_table[pkt.payload[n]]; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 pkt.m_pt = ep->gsm_payload_type; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 if (m_out) |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 pkt.m_pt |= 0x80; |
96
f24bbfd23c9d
mgw p2g: outgoing seq numbers, forwarding control
Mychaela Falconia <falcon@freecalypso.org>
parents:
95
diff
changeset
|
127 pkt.seq = htons(++ep->p2g_out_seq); |
95
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 switch (ep->gsm_payload_msg_type) { |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 case GSM_TCHF_FRAME: |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 gsm_encode(ep->gsm_encoder_state, pcm_samples, pkt.payload); |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 break; |
174
c985c33baeac
mgw: support EFR by way of libgsmefr
Mychaela Falconia <falcon@freecalypso.org>
parents:
127
diff
changeset
|
132 case GSM_TCHF_FRAME_EFR: |
c985c33baeac
mgw: support EFR by way of libgsmefr
Mychaela Falconia <falcon@freecalypso.org>
parents:
127
diff
changeset
|
133 EFR_encode_frame(ep->gsm_encoder_state, pcm_samples, |
c985c33baeac
mgw: support EFR by way of libgsmefr
Mychaela Falconia <falcon@freecalypso.org>
parents:
127
diff
changeset
|
134 pkt.payload, (int *) 0, (int *) 0); |
c985c33baeac
mgw: support EFR by way of libgsmefr
Mychaela Falconia <falcon@freecalypso.org>
parents:
127
diff
changeset
|
135 break; |
95
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 } |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 addrlen = sizeof(struct sockaddr_in); |
100
1579ec0e9fb9
mgw internal code: set GSM side RTP packet size in one place
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
138 sendto(ep->rtp_gsm.rtp_fd, &pkt, ep->gsm_rtp_pkt_size, 0, |
95
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 (struct sockaddr *) &ep->rtp_gsm.remote_addr, addrlen); |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 } |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 pstn2gsm_init(ep) |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 struct endpoint *ep; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 { |
102
d26d97974c8a
mgw p2g init: fix bug in forwarding re-enable scenario
Mychaela Falconia <falcon@freecalypso.org>
parents:
100
diff
changeset
|
145 if (ep->gsm_encoder_state) |
d26d97974c8a
mgw p2g init: fix bug in forwarding re-enable scenario
Mychaela Falconia <falcon@freecalypso.org>
parents:
100
diff
changeset
|
146 return TMGW_RESP_OK; |
95
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
147 switch (ep->gsm_payload_msg_type) { |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
148 case GSM_TCHF_FRAME: |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 ep->gsm_encoder_state = gsm_create(); |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
150 if (!ep->gsm_encoder_state) |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
151 return TMGW_RESP_ERR_RSRC; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 break; |
174
c985c33baeac
mgw: support EFR by way of libgsmefr
Mychaela Falconia <falcon@freecalypso.org>
parents:
127
diff
changeset
|
153 case GSM_TCHF_FRAME_EFR: |
c985c33baeac
mgw: support EFR by way of libgsmefr
Mychaela Falconia <falcon@freecalypso.org>
parents:
127
diff
changeset
|
154 ep->gsm_encoder_state = EFR_encoder_create(0); |
c985c33baeac
mgw: support EFR by way of libgsmefr
Mychaela Falconia <falcon@freecalypso.org>
parents:
127
diff
changeset
|
155 if (!ep->gsm_encoder_state) |
c985c33baeac
mgw: support EFR by way of libgsmefr
Mychaela Falconia <falcon@freecalypso.org>
parents:
127
diff
changeset
|
156 return TMGW_RESP_ERR_RSRC; |
c985c33baeac
mgw: support EFR by way of libgsmefr
Mychaela Falconia <falcon@freecalypso.org>
parents:
127
diff
changeset
|
157 break; |
95
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
158 } |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
159 select_handlers[ep->rtp_pstn.rtp_fd] = pstn2gsm_rtp_in; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
160 return TMGW_RESP_OK; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
161 } |