[asterisk-commits] branch oej/zfonepassthrough r22158 - /team/oej/zfonepassthrough/rtp.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Sat Apr 22 20:38:34 MST 2006


Author: oej
Date: Sat Apr 22 22:38:33 2006
New Revision: 22158

URL: http://svn.digium.com/view/asterisk?rev=22158&view=rev
Log:
Add STUN recognition (from airplane above Japan :-) )

Modified:
    team/oej/zfonepassthrough/rtp.c

Modified: team/oej/zfonepassthrough/rtp.c
URL: http://svn.digium.com/view/asterisk/team/oej/zfonepassthrough/rtp.c?rev=22158&r1=22157&r2=22158&view=diff
==============================================================================
--- team/oej/zfonepassthrough/rtp.c (original)
+++ team/oej/zfonepassthrough/rtp.c Sat Apr 22 22:38:33 2006
@@ -428,6 +428,7 @@
 	int padding;
 	int mark;
 	int ext;
+	int stunrequest = 0;
 	int x;
 	char iabuf[INET_ADDRSTRLEN];
 	unsigned int timestamp;
@@ -439,9 +440,6 @@
 	/* Cache where the header will go */
 	res = recvfrom(rtp->s, rtp->rawdata + AST_FRIENDLY_OFFSET, sizeof(rtp->rawdata) - AST_FRIENDLY_OFFSET,
 					0, (struct sockaddr *)&sin, &len);
-
-
-	rtpheader = (unsigned int *)(rtp->rawdata + AST_FRIENDLY_OFFSET);
 	if (res < 0) {
 		if (errno != EAGAIN)
 			ast_log(LOG_WARNING, "RTP Read error: %s\n", strerror(errno));
@@ -453,9 +451,9 @@
 		ast_log(LOG_WARNING, "RTP Read too short\n");
 		return &ast_null_frame;
 	}
-
-	/* Ignore if the other side hasn't been given an address
-	   yet.  */
+	rtpheader = (unsigned int *)(rtp->rawdata + AST_FRIENDLY_OFFSET);
+
+	/* Ignore if the other side hasn't been given an address yet.  */
 	if (!rtp->them.sin_addr.s_addr || !rtp->them.sin_port)
 		return &ast_null_frame;
 
@@ -476,7 +474,45 @@
 
 	/* Check RTP version */
 	version = (seqno & 0xC0000000) >> 30;
-	if (version != 2)
+	switch (version) {
+	case 2:		/* RTP packet */
+		break;
+	case 0:
+	case 1:	/* STUN packet */
+		stunrequest = seqno  >> 16; 
+		if (option_debug > 2 || rtpdebug) {
+			char *type;
+			switch stunrequest {	/* We are only likely to get requests at this time */
+			case 0x0001:
+				type = "Binding Request";
+				break;
+			case 0x0101:
+				type = "Binding Response";
+					break;
+			case 0x0111:
+				type = "Binding Error Response";
+				break;
+			case 0x0002:
+				type = "Shared Secret Request";
+				break;
+			case 0x0102:
+				type = "Shared Secret Response";
+				break;
+			case 0x0112:
+				type = "Shared Secret Error Response";
+				break;
+			default:
+				type = "Unknown packet in RTP stream";
+				break;
+			}
+			if (stunrequest)
+				ast_log(LOG_DEBUG, "Got STUN packet on RTP channel : %s (Not handled by Asterisk)\n", type);
+			else 
+				ast_log(LOG_DBEUG, "Unknown packet in RTP stream. Ignoring\n");
+		}
+			
+	}
+	if (version !=2)	/* Not an RTP packet */
 		return &ast_null_frame;
 	
 	payloadtype = (seqno & 0x7f0000) >> 16;
@@ -496,11 +532,13 @@
 		/* RTP Extension present */
 		hdrlen += 4;
 		hdrlen += (ntohl(rtpheader[3]) & 0xffff) << 2;
-		profile = (ntohl(rtpheader[3]) & 0xffff0000) >> 16;
-		if (profile == 0x505a)
-			ast_log(LOG_DEBUG, "Found Zfone extension in RTP stream - zrtp (not yet supported)\n");
-		else
-			ast_log(LOG_DEBUG, "Found RTP Extension %x\n", profile);
+		if (option_debug) {
+			profile = (ntohl(rtpheader[3]) & 0xffff0000) >> 16;
+			if (profile == 0x505a)
+				ast_log(LOG_DEBUG, "Found Zfone extension in RTP stream - zrtp (not yet supported)\n");
+			else
+				ast_log(LOG_DEBUG, "Found RTP Extension %x\n", profile);
+		}
 
 		
 	}
@@ -796,7 +834,7 @@
 	return 1;
 }
 
-/*! \brief  Make a note of a RTP paymoad type that was seen in a SDP "m=" line.
+/*! \brief  Make a note of a RTP payload type that was seen in a SDP "m=" line.
  * By default, use the well-known value for this type (although it may 
  * still be set to a different value by a subsequent "a=rtpmap:" line)
  */



More information about the asterisk-commits mailing list