FreeCalypso > hg > themwi-system-sw
annotate mgw/pstn2gsm.c @ 240:c7a3ba56c636
themwi-short-dial: fix bug in printf arguments
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 14 Aug 2023 15:37:59 -0800 |
parents | 0047c4c08d9e |
children |
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> |
198
cf1ba5d65188
mgw: start using project-global rtp_defs.h
Mychaela Falconia <falcon@freecalypso.org>
parents:
174
diff
changeset
|
19 #include "../include/rtp_defs.h" |
95
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 #include "../include/tmgw_ctrl.h" |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 #include "../include/tmgw_const.h" |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 #include "struct.h" |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 #include "select.h" |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 #include "int_defs.h" |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 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
|
27 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
|
28 |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 #define ERR_WRONG_UDP_SRC 0x0001 |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 #define ERR_BAD_RTP_PACKET 0x0002 |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 #define ERR_SSRC_CHANGE 0x0004 |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 #define ERR_SEQ_BREAK 0x0008 |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 #define ERR_TSTAMP_BREAK 0x0010 |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 void |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 pstn2gsm_rtp_in(in_fd, ep) |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 struct endpoint *ep; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 { |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 struct rtp_packet pkt; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 struct sockaddr_in sin_from; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 socklen_t addrlen; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 uint16_t *pcm_dec_table; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 int16_t seq_delta; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 int32_t ts_delta; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 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
|
46 unsigned n; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 int rc, m_out; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 addrlen = sizeof(struct sockaddr_in); |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 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
|
51 (struct sockaddr *) &sin_from, &addrlen); |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 if (rc < 0) |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 return; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 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
|
55 || 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
|
56 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
|
57 syslog(LOG_ERR, |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 "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
|
59 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
|
60 } |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 return; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 } |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 if (rc != RTP_PACKET_SIZE_PSTN) { |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 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
|
65 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
|
66 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
|
67 } |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 return; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 } |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 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
|
71 goto bad_rtp_pkt; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 switch (pkt.m_pt & 0x7F) { |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 case PSTN_CODEC_PCMU: |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 pcm_dec_table = pcmu_decode_table; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 break; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 case PSTN_CODEC_PCMA: |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 pcm_dec_table = pcma_decode_table; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 break; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 default: |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 goto bad_rtp_pkt; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 } |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 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
|
83 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
|
84 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
|
85 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
|
86 } |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 ep->p2g_state = 0; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 } |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 if (ep->p2g_state) { |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 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
|
91 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
|
92 if (seq_delta <= 0) |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 return; /* discard old or duplicate */ |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 if (seq_delta != 1) { |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 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
|
96 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
|
97 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
|
98 } |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 m_out = 1; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 } 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
|
101 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
|
102 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
|
103 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
|
104 } |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 m_out = 1; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 } else |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 m_out = 0; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 } else |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 m_out = 1; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 ep->p2g_state = 1; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 ep->p2g_ssrc = pkt.ssrc; |
96
f24bbfd23c9d
mgw p2g: outgoing seq numbers, forwarding control
Mychaela Falconia <falcon@freecalypso.org>
parents:
95
diff
changeset
|
112 ep->p2g_last_ts = ntohl(pkt.tstamp); |
f24bbfd23c9d
mgw p2g: outgoing seq numbers, forwarding control
Mychaela Falconia <falcon@freecalypso.org>
parents:
95
diff
changeset
|
113 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
|
114 /* 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
|
115 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
|
116 ep->p2g_drop_flag = 1; |
96
f24bbfd23c9d
mgw p2g: outgoing seq numbers, forwarding control
Mychaela Falconia <falcon@freecalypso.org>
parents:
95
diff
changeset
|
117 return; |
97
9aed16c30622
mgw p2g: set M bit when restarting forwarding after no-forward
Mychaela Falconia <falcon@freecalypso.org>
parents:
96
diff
changeset
|
118 } |
9aed16c30622
mgw p2g: set M bit when restarting forwarding after no-forward
Mychaela Falconia <falcon@freecalypso.org>
parents:
96
diff
changeset
|
119 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
|
120 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
|
121 m_out = 1; |
9aed16c30622
mgw p2g: set M bit when restarting forwarding after no-forward
Mychaela Falconia <falcon@freecalypso.org>
parents:
96
diff
changeset
|
122 } |
95
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 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
|
124 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
|
125 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
|
126 if (m_out) |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 pkt.m_pt |= 0x80; |
96
f24bbfd23c9d
mgw p2g: outgoing seq numbers, forwarding control
Mychaela Falconia <falcon@freecalypso.org>
parents:
95
diff
changeset
|
128 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
|
129 switch (ep->gsm_payload_msg_type) { |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 case GSM_TCHF_FRAME: |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 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
|
132 break; |
174
c985c33baeac
mgw: support EFR by way of libgsmefr
Mychaela Falconia <falcon@freecalypso.org>
parents:
127
diff
changeset
|
133 case GSM_TCHF_FRAME_EFR: |
c985c33baeac
mgw: support EFR by way of libgsmefr
Mychaela Falconia <falcon@freecalypso.org>
parents:
127
diff
changeset
|
134 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
|
135 pkt.payload, (int *) 0, (int *) 0); |
c985c33baeac
mgw: support EFR by way of libgsmefr
Mychaela Falconia <falcon@freecalypso.org>
parents:
127
diff
changeset
|
136 break; |
95
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 } |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 addrlen = sizeof(struct sockaddr_in); |
205
0047c4c08d9e
mgw: accept the new TRAUlike RTP format
Mychaela Falconia <falcon@freecalypso.org>
parents:
198
diff
changeset
|
139 sendto(ep->rtp_gsm.rtp_fd, &pkt, |
0047c4c08d9e
mgw: accept the new TRAUlike RTP format
Mychaela Falconia <falcon@freecalypso.org>
parents:
198
diff
changeset
|
140 RTP_PACKET_HDR_SIZE + ep->gsm_payload_len, 0, |
95
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 (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
|
142 } |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 pstn2gsm_init(ep) |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
145 struct endpoint *ep; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 { |
102
d26d97974c8a
mgw p2g init: fix bug in forwarding re-enable scenario
Mychaela Falconia <falcon@freecalypso.org>
parents:
100
diff
changeset
|
147 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
|
148 return TMGW_RESP_OK; |
95
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 switch (ep->gsm_payload_msg_type) { |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
150 case GSM_TCHF_FRAME: |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
151 ep->gsm_encoder_state = gsm_create(); |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 if (!ep->gsm_encoder_state) |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
153 return TMGW_RESP_ERR_RSRC; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
154 break; |
174
c985c33baeac
mgw: support EFR by way of libgsmefr
Mychaela Falconia <falcon@freecalypso.org>
parents:
127
diff
changeset
|
155 case GSM_TCHF_FRAME_EFR: |
c985c33baeac
mgw: support EFR by way of libgsmefr
Mychaela Falconia <falcon@freecalypso.org>
parents:
127
diff
changeset
|
156 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
|
157 if (!ep->gsm_encoder_state) |
c985c33baeac
mgw: support EFR by way of libgsmefr
Mychaela Falconia <falcon@freecalypso.org>
parents:
127
diff
changeset
|
158 return TMGW_RESP_ERR_RSRC; |
c985c33baeac
mgw: support EFR by way of libgsmefr
Mychaela Falconia <falcon@freecalypso.org>
parents:
127
diff
changeset
|
159 break; |
95
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
160 } |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
161 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
|
162 return TMGW_RESP_OK; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
163 } |