summaryrefslogtreecommitdiff
path: root/net/asterisk10/files/dtmf_debug.diff
blob: 81205d40dd46cfc5df25c9730c524efb30608cc8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
--- channels/chan_sip.c.orig	2008-03-18 16:42:59.000000000 +0200
+++ channels/chan_sip.c	2008-03-18 17:08:34.000000000 +0200
@@ -3768,6 +3768,7 @@
 		ast_log(LOG_WARNING, "old channel wasn't %p but was %p\n", oldchan, p->owner);
 	else {
 		p->owner = newchan;
+		ast_rtp_set_chan_name(p->rtp, newchan->name);
 		ret = 0;
 	}
 	if (option_debug > 2)
@@ -4032,6 +4035,7 @@
 	if (i->rtp) {
 		tmp->fds[0] = ast_rtp_fd(i->rtp);
 		tmp->fds[1] = ast_rtcp_fd(i->rtp);
+		ast_rtp_set_chan_id(i->rtp, i->callid);
 	}
 	if (needvideo && i->vrtp) {
 		tmp->fds[2] = ast_rtp_fd(i->vrtp);
@@ -4059,6 +4063,8 @@
 	if (!ast_strlen_zero(i->language))
 		ast_string_field_set(tmp, language, i->language);
 	i->owner = tmp;
+	ast_rtp_set_chan_name(i->rtp, tmp->name);
+
 	ast_module_ref(ast_module_info->self);
 	ast_copy_string(tmp->context, i->context, sizeof(tmp->context));
 	/*Since it is valid to have extensions in the dialplan that have unescaped characters in them
@@ -4479,8 +4485,10 @@
 	build_via(p);
 	if (!callid)
 		build_callid_pvt(p);
-	else
+	else {
 		ast_string_field_set(p, callid, callid);
+		ast_rtp_set_chan_id(p->rtp, p->callid);
+	}
 	/* Assign default music on hold class */
 	ast_string_field_set(p, mohinterpret, default_mohinterpret);
 	ast_string_field_set(p, mohsuggest, default_mohsuggest);
--- include/asterisk/rtp.h.orig	2008-03-18 13:35:42.000000000 +0200
+++ include/asterisk/rtp.h	2008-03-18 13:35:58.000000000 +0200
@@ -251,6 +251,9 @@
 
 int ast_rtp_codec_getformat(int pt);
 
+void ast_rtp_set_chan_name(struct ast_rtp *, const char *);
+void ast_rtp_set_chan_id(struct ast_rtp *, const char *);
+
 /*! \brief Set rtp timeout */
 void ast_rtp_set_rtptimeout(struct ast_rtp *rtp, int timeout);
 /*! \brief Set rtp hold timeout */
--- main/rtp.c.orig	2008-04-08 14:53:18.000000000 +0300
+++ main/rtp.c	2008-04-08 14:54:14.000000000 +0300
@@ -81,6 +81,7 @@
 static int rtpstart;			/*!< First port for RTP sessions (set in rtp.conf) */
 static int rtpend;			/*!< Last port for RTP sessions (set in rtp.conf) */
 static int rtpdebug;			/*!< Are we debugging? */
+static int rtpdebugdtmf;		/*!< Are we debugging DTMFs? */
 static int rtcpdebug;			/*!< Are we debugging RTCP? */
 static int rtcpstats;			/*!< Are we debugging RTCP? */
 static int rtcpinterval = RTCP_DEFAULT_INTERVALMS; /*!< Time between rtcp reports in millisecs */
@@ -168,6 +169,8 @@
 	struct ast_codec_pref pref;
 	struct ast_rtp *bridged;        /*!< Who we are Packet bridged to */
 	int set_marker_bit:1;           /*!< Whether to set the marker bit or not */
+	char chan_name[100];
+	char chan_id[100];
 };
 
 /* Forward declarations */
@@ -669,8 +672,8 @@
 	struct ast_frame *f = NULL;
 	event = ntohl(*((unsigned int *)(data)));
 	event &= 0x001F;
-	if (option_debug > 2 || rtpdebug)
-		ast_log(LOG_DEBUG, "Cisco DTMF Digit: %08x (len = %d)\n", event, len);
+	if (option_debug > 2 || rtpdebug || rtpdebugdtmf)
+		ast_log(LOG_DEBUG, "Channel: %s %s Cisco DTMF packet: %08x (len = %d)\n", rtp->chan_name, rtp->chan_id, event, len);
 	if (event < 10) {
 		resp = '0' + event;
 	} else if (event < 11) {
@@ -684,12 +687,24 @@
 	}
 	if (rtp->resp && (rtp->resp != resp)) {
 		f = send_dtmf(rtp, AST_FRAME_DTMF_END);
+		ast_log(LOG_DEBUG, "Channel: %s %s Cisco DTMF event: %c\n", rtp->chan_name, rtp->chan_id, rtp->resp);
 	}
 	rtp->resp = resp;
 	rtp->dtmfcount = dtmftimeout;
 	return f;
 }
 
+void ast_rtp_set_chan_id(struct ast_rtp *rtp, const char *chan_id) {
+	if (rtp == NULL || chan_id == NULL)
+		return;
+	snprintf(rtp->chan_id, sizeof(rtp->chan_id), "%s", chan_id);
+}
+
+void ast_rtp_set_chan_name(struct ast_rtp *rtp, const char *chan_name) {
+	if (rtp == NULL || chan_name == NULL)
+		return;
+	snprintf(rtp->chan_name, sizeof(rtp->chan_name), "%s", chan_name);
+}
 /*! 
  * \brief Process RTP DTMF and events according to RFC 2833.
  * 
@@ -1051,6 +1066,10 @@
 	struct rtpPayloadType rtpPT;
 	int reconstruct = ntohl(rtpheader[0]);
 
+	/* If we are listening for DTMF - then feed all packets into the core  to keep the RTP stream consistent when relaying DTMFs */
+	if (ast_test_flag(rtp, FLAG_P2P_NEED_DTMF))
+		return -1;
+
 	/* Get fields from packet */
 	payload = (reconstruct & 0x7f0000) >> 16;
 	mark = (((reconstruct & 0x800000) >> 23) != 0);
@@ -1062,10 +1081,6 @@
 	if (!bridged->current_RTP_PT[payload].code)
 		return -1;
 
-	/* If the payload is DTMF, and we are listening for DTMF - then feed it into the core */
-	if (ast_test_flag(rtp, FLAG_P2P_NEED_DTMF) && !rtpPT.isAstFormat && rtpPT.code == AST_RTP_DTMF)
-		return -1;
-
 	/* Otherwise adjust bridged payload to match */
 	bridged_payload = ast_rtp_lookup_code(bridged, rtpPT.isAstFormat, rtpPT.code);
 
@@ -1254,11 +1269,12 @@
 		/* This is special in-band data that's not one of our codecs */
 		if (rtpPT.code == AST_RTP_DTMF) {
 			/* It's special -- rfc2833 process it */
-			if (rtp_debug_test_addr(&sin)) {
+			if (rtp_debug_test_addr(&sin) || rtpdebugdtmf) {
 				unsigned char *data;
 				unsigned int event;
 				unsigned int event_end;
 				unsigned int duration;
+
 				data = rtp->rawdata + AST_FRIENDLY_OFFSET + hdrlen;
 				event = ntohl(*((unsigned int *)(data)));
 				event >>= 24;
@@ -1267,9 +1283,12 @@
 				event_end >>= 24;
 				duration = ntohl(*((unsigned int *)(data)));
 				duration &= 0xFFFF;
-				ast_verbose("Got  RTP RFC2833 from   %s:%u (type %-2.2d, seq %-6.6u, ts %-6.6u, len %-6.6u, mark %d, event %08x, end %d, duration %-5.5d) \n", ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port), payloadtype, seqno, timestamp, res - hdrlen, (mark?1:0), event, ((event_end & 0x80)?1:0), duration);
+
+				ast_verbose("Channel: %s %s Got RTP RFC2833 from %s:%u to %s:%u (type %-2.2d, seq %-6.6u, ts %-6.6u, len %-6.6u, mark %d, event %08x, end %d, duration %-5.5d)\n", rtp->chan_name, rtp->chan_id, ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port), ast_inet_ntoa(rtp->us.sin_addr), ntohs(rtp->us.sin_port), payloadtype, seqno, timestamp, res - hdrlen, (mark?1:0), event, ((event_end & 0x80)?1:0), duration);
 			}
 			f = process_rfc2833(rtp, rtp->rawdata + AST_FRIENDLY_OFFSET + hdrlen, res - hdrlen, seqno, timestamp);
+			if (rtpdebugdtmf && f)
+				ast_verbose("Channel: %s %s Got RFC2833 DTMF event %c of type %s\n", rtp->chan_name, rtp->chan_id, f->subclass, (f->frametype == AST_FRAME_DTMF_BEGIN ? "DTMF BEGIN" : (f->frametype == AST_FRAME_DTMF_END ? "DTMF_END" : "UNKNOWN")));
 		} else if (rtpPT.code == AST_RTP_CISCO_DTMF) {
 			/* It's really special -- process it the Cisco way */
 			if (rtp->lastevent <= seqno || (rtp->lastevent >= 65530 && seqno <= 6)) {
@@ -2198,8 +2217,9 @@
 			ast_log(LOG_ERROR, "RTP Transmission error to %s:%u: %s\n",
 				ast_inet_ntoa(rtp->them.sin_addr),
 				ntohs(rtp->them.sin_port), strerror(errno));
-		if (rtp_debug_test_addr(&rtp->them))
-			ast_verbose("Sent RTP DTMF packet to %s:%u (type %-2.2d, seq %-6.6u, ts %-6.6u, len %-6.6u)\n",
+		if (rtp_debug_test_addr(&rtp->them) || rtpdebugdtmf)
+			ast_verbose("Channel: %s %s Sent RTP DTMF packet to %s:%u (type %-2.2d, seq %-6.6u, ts %-6.6u, len %-6.6u)\n",
+				    rtp->chan_name, rtp->chan_id,
 				    ast_inet_ntoa(rtp->them.sin_addr),
 				    ntohs(rtp->them.sin_port), payload, rtp->seqno, rtp->lastdigitts, res - hdrlen);
 		/* Increment sequence number */
@@ -2242,8 +2262,9 @@
 		ast_log(LOG_ERROR, "RTP Transmission error to %s:%d: %s\n",
 			ast_inet_ntoa(rtp->them.sin_addr),
 			ntohs(rtp->them.sin_port), strerror(errno));
-	if (rtp_debug_test_addr(&rtp->them))
-		ast_verbose("Sent RTP DTMF packet to %s:%u (type %-2.2d, seq %-6.6u, ts %-6.6u, len %-6.6u)\n",
+	if (rtp_debug_test_addr(&rtp->them) || rtpdebugdtmf)
+		ast_verbose("Channel: %s %s Sent RTP DTMF packet to %s:%u (type %-2.2d, seq %-6.6u, ts %-6.6u, len %-6.6u)\n",
+			    rtp->chan_name, rtp->chan_id,
 			    ast_inet_ntoa(rtp->them.sin_addr),
 			    ntohs(rtp->them.sin_port), rtp->send_payload, rtp->seqno, rtp->lastdigitts, res - hdrlen);
 
@@ -3481,6 +3502,16 @@
 	return RESULT_SUCCESS;
 }
 
+static int rtp_do_debug_dtmf(int fd, int argc, char *argv[])
+{
+	if (argc != 3)
+		return RESULT_SHOWUSAGE;
+
+	rtpdebugdtmf = 1;
+	ast_cli(fd, "RTP DTMF debugging enabled\n");
+	return RESULT_SUCCESS;
+}
+
 static int rtp_do_debug(int fd, int argc, char *argv[])
 {
 	if (argc != 2) {
@@ -3541,6 +3572,7 @@
 	if (argc != 3)
 		return RESULT_SHOWUSAGE;
 	rtpdebug = 0;
+	rtpdebugdtmf = 0;
 	ast_cli(fd,"RTP Debugging Disabled\n");
 	return RESULT_SUCCESS;
 }
@@ -3601,7 +3633,7 @@
 }
 
 static char debug_usage[] =
-  "Usage: rtp debug [ip host[:port]]\n"
+  "Usage: rtp debug [ip host[:port] | dtmf]\n"
   "       Enable dumping of all RTP packets to and from host.\n";
 
 static char no_debug_usage[] =
@@ -3676,6 +3708,10 @@
 	rtp_do_debug, "Enable RTP debugging",
 	debug_usage },
 
+	{ { "rtp", "debug", "dtmf", NULL },
+	rtp_do_debug_dtmf, "Enable RTP debugging on DTMFs",
+	debug_usage },
+
 	{ { "rtp", "debug", "off", NULL },
 	rtp_no_debug, "Disable RTP debugging",
 	no_debug_usage, NULL, &cli_rtp_no_debug_deprecated },