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 "int_defs.h"
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 #include "dtmf_defs.h"
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 extern struct endpoint *find_ep_by_id();
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 extern struct dtmf_desc dtmf_table[];
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 void
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 process_dtmf_start(conn, req, resp)
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 struct ctrl_conn *conn;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 struct tmgw_ctrl_req *req;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 struct tmgw_ctrl_resp *resp;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 {
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 struct endpoint *ep;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 struct dtmf_desc *desc;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 ep = find_ep_by_id(conn, req->ep_id);
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 if (!ep) {
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 protocol_err: resp->res = TMGW_RESP_ERR_PROT;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 return;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 }
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 if (ep->ep_type != TMGW_EP_TYPE_GATEWAY)
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 goto protocol_err;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 if (!(ep->fwd_mode & TMGW_FWD_ENABLE_GSM2PSTN))
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 goto protocol_err;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 for (desc = dtmf_table; desc->digit; desc++)
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 if (desc->digit == req->fwd_mode)
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 break;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 if (!desc->digit) {
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 resp->res = TMGW_RESP_ERR_PARAM;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 return;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 }
|
170
a6eb2de277f6
mgw: massive simplification for continuous RTP stream from BTS
Mychaela Falconia <falcon@freecalypso.org>
diff
changeset
|
51 if (ep->dtmf_sample_ptr) {
|
127
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 resp->res = TMGW_RESP_ERR_BUSY;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 return;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 }
|
170
a6eb2de277f6
mgw: massive simplification for continuous RTP stream from BTS
Mychaela Falconia <falcon@freecalypso.org>
diff
changeset
|
55 /* start it */
|
a6eb2de277f6
mgw: massive simplification for continuous RTP stream from BTS
Mychaela Falconia <falcon@freecalypso.org>
diff
changeset
|
56 ep->dtmf_sample_ptr = desc->samples;
|
127
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 ep->dtmf_frames_sent = 0;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 /* return success */
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 resp->res = TMGW_RESP_OK;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 }
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 void
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 process_dtmf_stop(conn, req, resp)
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 struct ctrl_conn *conn;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 struct tmgw_ctrl_req *req;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 struct tmgw_ctrl_resp *resp;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 {
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 struct endpoint *ep;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 ep = find_ep_by_id(conn, req->ep_id);
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 if (!ep) {
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 protocol_err: resp->res = TMGW_RESP_ERR_PROT;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 return;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 }
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 if (ep->ep_type != TMGW_EP_TYPE_GATEWAY)
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 goto protocol_err;
|
170
a6eb2de277f6
mgw: massive simplification for continuous RTP stream from BTS
Mychaela Falconia <falcon@freecalypso.org>
diff
changeset
|
77 ep->dtmf_sample_ptr = 0;
|
127
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 resp->res = TMGW_RESP_OK;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 }
|