127
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /*
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * In this module we implement start/stop control of DTMF generation
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * toward PSTN on GSM-to-PSTN gateway endpoints.
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <sys/types.h>
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <sys/socket.h>
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <sys/time.h>
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <netinet/in.h>
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <stdio.h>
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <stdint.h>
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <stdlib.h>
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include <string.h>
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #include <strings.h>
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 #include <syslog.h>
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 #include "../include/tmgw_ctrl.h"
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 #include "../include/tmgw_const.h"
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 #include "struct.h"
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 #include "dtmf_defs.h"
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 extern struct endpoint *find_ep_by_id();
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 extern struct dtmf_desc dtmf_table[];
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 void
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 process_dtmf_start(conn, req, resp)
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 struct ctrl_conn *conn;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 struct tmgw_ctrl_req *req;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 struct tmgw_ctrl_resp *resp;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 {
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 struct endpoint *ep;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 struct dtmf_desc *desc;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 ep = find_ep_by_id(conn, req->ep_id);
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 if (!ep) {
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 protocol_err: resp->res = TMGW_RESP_ERR_PROT;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 return;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 }
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 if (ep->ep_type != TMGW_EP_TYPE_GATEWAY)
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 goto protocol_err;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 if (!(ep->fwd_mode & TMGW_FWD_ENABLE_GSM2PSTN))
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 goto protocol_err;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 for (desc = dtmf_table; desc->digit; desc++)
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 if (desc->digit == req->fwd_mode)
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 break;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 if (!desc->digit) {
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 resp->res = TMGW_RESP_ERR_PARAM;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 return;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 }
|
170
a6eb2de277f6
mgw: massive simplification for continuous RTP stream from BTS
Mychaela Falconia <falcon@freecalypso.org>
diff
changeset
|
50 if (ep->dtmf_sample_ptr) {
|
127
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 resp->res = TMGW_RESP_ERR_BUSY;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 return;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 }
|
170
a6eb2de277f6
mgw: massive simplification for continuous RTP stream from BTS
Mychaela Falconia <falcon@freecalypso.org>
diff
changeset
|
54 /* start it */
|
a6eb2de277f6
mgw: massive simplification for continuous RTP stream from BTS
Mychaela Falconia <falcon@freecalypso.org>
diff
changeset
|
55 ep->dtmf_sample_ptr = desc->samples;
|
127
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 ep->dtmf_frames_sent = 0;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 /* return success */
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 resp->res = TMGW_RESP_OK;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 }
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 void
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 process_dtmf_stop(conn, req, resp)
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 struct ctrl_conn *conn;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 struct tmgw_ctrl_req *req;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 struct tmgw_ctrl_resp *resp;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 {
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 struct endpoint *ep;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 ep = find_ep_by_id(conn, req->ep_id);
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 if (!ep) {
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 protocol_err: resp->res = TMGW_RESP_ERR_PROT;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 return;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 }
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 if (ep->ep_type != TMGW_EP_TYPE_GATEWAY)
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 goto protocol_err;
|
170
a6eb2de277f6
mgw: massive simplification for continuous RTP stream from BTS
Mychaela Falconia <falcon@freecalypso.org>
diff
changeset
|
76 ep->dtmf_sample_ptr = 0;
|
127
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 resp->res = TMGW_RESP_OK;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 }
|