annotate mgw/dtmf_ctrl.c @ 191:6ac96217c442

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