FreeCalypso > hg > themwi-system-sw
annotate mgw/pstn2gsm.c @ 98:423610bb2c9e
sip-in: send MDCX to TMGW to connect the call through
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 25 Sep 2022 20:28:54 -0800 |
parents | 9aed16c30622 |
children | 1579ec0e9fb9 |
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> |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <netinet/in.h> |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdio.h> |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <stdint.h> |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <stdlib.h> |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <string.h> |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include <strings.h> |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #include <syslog.h> |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 #include <unistd.h> |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 #include <gsm.h> /* libgsm dependency */ |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 #include "../include/tmgw_ctrl.h" |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 #include "../include/tmgw_const.h" |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 #include "struct.h" |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 #include "select.h" |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 #include "int_defs.h" |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 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
|
24 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
|
25 |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 #define ERR_WRONG_UDP_SRC 0x0001 |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 #define ERR_BAD_RTP_PACKET 0x0002 |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 #define ERR_SSRC_CHANGE 0x0004 |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 #define ERR_SEQ_BREAK 0x0008 |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 #define ERR_TSTAMP_BREAK 0x0010 |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 void |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 pstn2gsm_rtp_in(in_fd, ep) |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 struct endpoint *ep; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 { |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 struct rtp_packet pkt; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 struct sockaddr_in sin_from; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 socklen_t addrlen; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 uint16_t *pcm_dec_table; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 int16_t seq_delta; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 int32_t ts_delta; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 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
|
43 unsigned n; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 int rc, m_out; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 addrlen = sizeof(struct sockaddr_in); |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 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
|
48 (struct sockaddr *) &sin_from, &addrlen); |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 if (rc < 0) |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 return; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 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
|
52 || 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
|
53 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
|
54 syslog(LOG_ERR, |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 "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
|
56 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 } |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 return; |
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 if (rc != RTP_PACKET_SIZE_PSTN) { |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 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
|
62 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
|
63 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 } |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 return; |
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 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
|
68 goto bad_rtp_pkt; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 switch (pkt.m_pt & 0x7F) { |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 case PSTN_CODEC_PCMU: |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 pcm_dec_table = pcmu_decode_table; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 break; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 case PSTN_CODEC_PCMA: |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 pcm_dec_table = pcma_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 default: |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 goto bad_rtp_pkt; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 } |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 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
|
80 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
|
81 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
|
82 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 } |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 ep->p2g_state = 0; |
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 if (ep->p2g_state) { |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 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
|
88 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
|
89 if (seq_delta <= 0) |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 return; /* discard old or duplicate */ |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 if (seq_delta != 1) { |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 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
|
93 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
|
94 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 } |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 m_out = 1; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 } 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
|
98 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
|
99 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
|
100 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 } |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 m_out = 1; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 } else |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 m_out = 0; |
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 = 1; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 ep->p2g_state = 1; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 ep->p2g_ssrc = pkt.ssrc; |
96
f24bbfd23c9d
mgw p2g: outgoing seq numbers, forwarding control
Mychaela Falconia <falcon@freecalypso.org>
parents:
95
diff
changeset
|
109 ep->p2g_last_ts = ntohl(pkt.tstamp); |
f24bbfd23c9d
mgw p2g: outgoing seq numbers, forwarding control
Mychaela Falconia <falcon@freecalypso.org>
parents:
95
diff
changeset
|
110 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
|
111 /* 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
|
112 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
|
113 ep->p2g_drop_flag = 1; |
96
f24bbfd23c9d
mgw p2g: outgoing seq numbers, forwarding control
Mychaela Falconia <falcon@freecalypso.org>
parents:
95
diff
changeset
|
114 return; |
97
9aed16c30622
mgw p2g: set M bit when restarting forwarding after no-forward
Mychaela Falconia <falcon@freecalypso.org>
parents:
96
diff
changeset
|
115 } |
9aed16c30622
mgw p2g: set M bit when restarting forwarding after no-forward
Mychaela Falconia <falcon@freecalypso.org>
parents:
96
diff
changeset
|
116 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
|
117 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
|
118 m_out = 1; |
9aed16c30622
mgw p2g: set M bit when restarting forwarding after no-forward
Mychaela Falconia <falcon@freecalypso.org>
parents:
96
diff
changeset
|
119 } |
95
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 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
|
121 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
|
122 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
|
123 if (m_out) |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 pkt.m_pt |= 0x80; |
96
f24bbfd23c9d
mgw p2g: outgoing seq numbers, forwarding control
Mychaela Falconia <falcon@freecalypso.org>
parents:
95
diff
changeset
|
125 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
|
126 switch (ep->gsm_payload_msg_type) { |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 case GSM_TCHF_FRAME: |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 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
|
129 n = RTP_PACKET_SIZE_GSM_FR; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 break; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 } |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 addrlen = sizeof(struct sockaddr_in); |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 sendto(ep->rtp_gsm.rtp_fd, &pkt, n, 0, |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 (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
|
135 } |
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 pstn2gsm_init(ep) |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 struct endpoint *ep; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 { |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 switch (ep->gsm_payload_msg_type) { |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 case GSM_TCHF_FRAME: |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 ep->gsm_encoder_state = gsm_create(); |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 if (!ep->gsm_encoder_state) |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 return TMGW_RESP_ERR_RSRC; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
145 break; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 } |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
147 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
|
148 return TMGW_RESP_OK; |
f280328e7e2e
themwi-mgw: initial implementation of PSTN to GSM forwarding
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 } |