Index: channel.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channel.c,v
retrieving revision 1.180
diff -u -r1.180 channel.c
--- channel.c	28 Mar 2005 20:48:24 -0000	1.180
+++ channel.c	31 Mar 2005 05:25:21 -0000
@@ -2013,7 +2013,7 @@
 			}
 			ast_mutex_unlock(&chlock);
 			if (chan->tech->requester)
-				c = chan->tech->requester(type, capabilities, data, cause);
+				c = chan->tech->requester(type, fmt, data, cause);
 			if (c) {
 				if (c->_state == AST_STATE_DOWN) {
 					manager_event(EVENT_FLAG_CALL, "Newchannel",
Index: channels/h323/chan_h323.h
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/h323/chan_h323.h,v
retrieving revision 1.37
diff -u -r1.37 chan_h323.h
--- channels/h323/chan_h323.h	21 Dec 2004 00:07:56 -0000	1.37
+++ channels/h323/chan_h323.h	31 Mar 2005 05:27:11 -0000
@@ -105,8 +105,7 @@
 } call_details_t;
 
 typedef struct rtp_info {
-	const char *addr;
-	unsigned int port;
+	struct sockaddr_in rtp_addr;
 } rtp_info_t;
 
 /* This is a callback prototype function, called pass
Index: channels/h323/ast_h323.h
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/h323/ast_h323.h,v
retrieving revision 1.31
diff -u -r1.31 ast_h323.h
--- channels/h323/ast_h323.h	16 Dec 2004 02:03:19 -0000	1.31
+++ channels/h323/ast_h323.h	31 Mar 2005 06:29:08 -0000
@@ -191,6 +191,10 @@
 
 	PString ast_cid_num;
 	PString ast_cid_name;
+
+private:
+	PIPSocket::Address externalIpAddress;   
+	WORD externalPort;
 };
 
 class MyH323_ExternalRTPChannel : public H323_ExternalRTPChannel {
@@ -202,21 +206,18 @@
 		MyH323Connection & connection,
       		const H323Capability & capability, 
       		Directions direction,              
-      		unsigned sessionID);
+      		unsigned sessionID,
+      		const PIPSocket::Address & ip,
+      		WORD dataPort);
 
 	~MyH323_ExternalRTPChannel();
 
 	/* Overrides */
 	BOOL Start(void);
-	BOOL OnReceivedAckPDU(const H245_H2250LogicalChannelAckParameters & param);
+	//BOOL OnReceivedAckPDU(const H245_H2250LogicalChannelAckParameters & param);
 
 	protected:
 	BYTE payloadCode;
-
-	PIPSocket::Address localIpAddr;
-	PIPSocket::Address remoteIpAddr;
-        WORD localPort;
-        WORD remotePort;
 }; 
 
 /**
Index: channels/h323/ast_h323.cpp
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/h323/ast_h323.cpp,v
retrieving revision 1.69
diff -u -r1.69 ast_h323.cpp
--- channels/h323/ast_h323.cpp	21 Dec 2004 00:07:56 -0000	1.69
+++ channels/h323/ast_h323.cpp	31 Mar 2005 06:29:08 -0000
@@ -862,25 +864,37 @@
 		 					           const H245_H2250LogicalChannelParameters * /*param*/,
 								   RTP_QOS * /*param*/ )
 {
-	return new MyH323_ExternalRTPChannel(*this, capability, dir, sessionID);
+	/* Determine the Local (A side) IP Address and port */
+	struct rtp_info *info = on_external_rtp_create(GetCallReference(), (const char *)GetCallToken()); 
+	if (!info) {
+		cout << "\tERROR: on_external_rtp_create failure" << endl;
+		return NULL;
+	}
+	externalPort = ntohs(info->rtp_addr.sin_port);
+	externalIpAddress = info->rtp_addr.sin_addr;
+	free(info); /* clean up allocated memory */
+	if (externalIpAddress == INADDR_ANY) {
+		/* no valid IP address, determine it by OpenH323 */
+		if (!GetControlChannel().GetLocalAddress().GetIpAddress(externalIpAddress))
+			return NULL;
+	}
+	return new MyH323_ExternalRTPChannel(*this, capability, dir, sessionID, externalIpAddress, externalPort);
 }
 
 /** This callback function is invoked once upon creation of each
   * channel for an H323 session 
   */
 BOOL MyH323Connection::OnStartLogicalChannel(H323Channel & channel)
-{    
-	if (h323debug) {
-		cout << "\t-- Started logical channel: ";	
-		cout << ((channel.GetDirection()==H323Channel::IsTransmitter)?"sending ":((channel.GetDirection()==H323Channel::IsReceiver)?"receiving ":" ")); 
-		cout << (const char *)(channel.GetCapability()).GetFormatName() << endl;
-	}
-
+{
 	/* Increase the count of channels we have open */
 	channelsOpen++;
 
+	const H323Capability & capability = channel.GetCapability();
 	if (h323debug) {
-		cout <<  "\t\t-- channelsOpen = " << channelsOpen << endl;
+		cout << "\t-- Started logical channel: "
+		     << ((channel.GetDirection()==H323Channel::IsTransmitter)?"sending ":((channel.GetDirection()==H323Channel::IsReceiver)?"receiving ":" ")) 
+		     << (const char *)capability.GetFormatName()
+		     <<  "\n\t\t-- channelsOpen = " << channelsOpen << endl;
 	}
 	return TRUE;	
 }
@@ -889,25 +903,11 @@
 MyH323_ExternalRTPChannel::MyH323_ExternalRTPChannel(MyH323Connection & connection,
 						     const H323Capability & capability,
                                                      Directions direction,
-                                                     unsigned id)
- : H323_ExternalRTPChannel::H323_ExternalRTPChannel(connection, capability, direction, id)
-{   
-	struct rtp_info *info;
-
-	/* Determine the Local (A side) IP Address and port */
-	info = on_external_rtp_create(connection.GetCallReference(), (const char *)connection.GetCallToken()); 
-	if (!info) {
-		cout << "\tERROR: on_external_rtp_create failure" << endl;
-		return;
-	} else {
-		localIpAddr = info->addr;
-		localPort = info->port;
-		/* tell the H.323 stack  */ 
-		SetExternalAddress(H323TransportAddress(localIpAddr, localPort), H323TransportAddress(localIpAddr, localPort + 1));
-		/* clean up allocated memory */
-		free(info);
-	}
-
+                                                     unsigned id,
+                                                     const PIPSocket::Address & ip,
+                                                     WORD dataPort)
+ : H323_ExternalRTPChannel::H323_ExternalRTPChannel(connection, capability, direction, id, ip, dataPort)
+{
 	/* Get the payload code	*/
 	OpalMediaFormat format(capability.GetFormatName(), FALSE);
 	payloadCode = format.GetPayloadType();
@@ -927,24 +927,30 @@
 		return FALSE;
 	}
 
-	/* Collect the remote information */
-	H323_ExternalRTPChannel::GetRemoteAddress(remoteIpAddr, remotePort);
-
-        if (h323debug) {
-        	cout << "\t\tExternal RTP Session Starting" << endl;
-        	cout << "\t\tRTP channel id " << sessionID << " parameters:" << endl;
-                cout << "\t\t-- remoteIpAddress: " << remoteIpAddr << endl;
-                cout << "\t\t-- remotePort: " << remotePort << endl;
-                cout << "\t\t-- ExternalIpAddress: " <<  localIpAddr << endl;
-                cout << "\t\t-- ExternalPort: " << localPort << endl;
+	if (GetDirection() == IsTransmitter) {
+		PIPSocket::Address remoteIpAddr;
+		WORD remotePort;
+		if (GetRemoteAddress(remoteIpAddr, remotePort)) {
+			if (h323debug) {
+				PIPSocket::Address localIpAddr;
+				WORD localPort;
+				externalMediaAddress.GetIpAndPort(localIpAddr, localPort);
+				cout << "\t\tExternal RTP Session Starting"
+				     << "\n\t\tRTP channel id " << sessionID << " parameters:"
+				     << "\n\t\t-- remoteIpAddress: " << remoteIpAddr
+				     << "\n\t\t-- remotePort: " << remotePort
+				     << "\n\t\t-- ExternalIpAddress: " <<  localIpAddr
+				     << "\n\t\t-- ExternalPort: " << localPort << endl;
+			}
+			/* Notify Asterisk of remote RTP information */
+			on_start_rtp_channel(connection.GetCallReference(), (const char *)remoteIpAddr.AsString(), remotePort, 
+				(const char *)connection.GetCallToken(), (int)payloadCode);
+		}
 	}
-
-	/* Notify Asterisk of remote RTP information */
-	on_start_rtp_channel(connection.GetCallReference(), (const char *)remoteIpAddr.AsString(), remotePort, 
-		(const char *)connection.GetCallToken(), (int)payloadCode);
 	return TRUE;
 }
 
+#if 0
 BOOL MyH323_ExternalRTPChannel::OnReceivedAckPDU(const H245_H2250LogicalChannelAckParameters & param)
 {
 	PIPSocket::Address remoteIpAddress;
@@ -966,6 +972,7 @@
 	}
 	return FALSE;
 }
+#endif
 
 /** IMPLEMENTATION OF C FUNCTIONS */
 
Index: channels/chan_h323.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_h323.c,v
retrieving revision 1.107
diff -u -r1.107 chan_h323.c
--- channels/chan_h323.c	4 Apr 2005 15:54:34 -0000	1.107
+++ channels/chan_h323.c	6 Apr 2005 07:20:28 -0000
@@ -566,6 +566,7 @@
 	ast_mutex_lock(&p->lock);
 	if (p->rtp && (p->dtmfmode & H323_DTMF_RFC2833)) {
 		ast_rtp_senddigit(p->rtp, digit);
+		h323_send_tone(p->cd.call_token, digit);
 	}
 	/* If in-band DTMF is desired, send that */
 	if ((p->dtmfmode & H323_DTMF_INBAND)) {
@@ -1195,7 +1196,7 @@
 		return NULL;
 	}
 	/* Assign default capabilities */
-	pvt->capability = capability;
+	pvt->capability = format;
 	pvt->dtmfmode = H323_DTMF_RFC2833;
 
 	strncpy(tmp, dest, sizeof(tmp) - 1);	
@@ -1289,9 +1290,7 @@
 struct rtp_info *external_rtp_create(unsigned call_reference, const char * token)
 {	
 	struct oh323_pvt *pvt;
-	struct sockaddr_in us;
 	struct rtp_info *info;
-       	static char iabuf[INET_ADDRSTRLEN];
 
 	info = (struct rtp_info *)malloc(sizeof(struct rtp_info));
 	if (!info) {
@@ -1305,12 +1304,9 @@
 	}
 	ast_mutex_lock(&pvt->lock);
 	/* figure out our local RTP port and tell the H.323 stack about it */
-	ast_rtp_get_us(pvt->rtp, &us);
+	ast_rtp_get_us(pvt->rtp, &info->rtp_addr);
+	info->rtp_addr.sin_addr = bindaddr.sin_addr; /* hmm... do we need this? */
 	ast_mutex_unlock(&pvt->lock);
-	/* evil hack, until I (or someone?) figures out a better way */
-	info->addr = ast_inet_ntoa(iabuf, sizeof(iabuf), bindaddr.sin_addr);
-	info->port = ntohs(us.sin_port);
-	ast_log(LOG_DEBUG, "Sending RTP 'US' %s:%d\n", info->addr, info->port);
 	return info;
 }
 
@@ -1470,6 +1466,7 @@
 	pvt->cd.call_source_name = strdup(cd.call_source_name);
 	pvt->cd.call_source_e164 = strdup(cd.call_source_e164);
 	pvt->cd.call_dest_e164 = strdup(cd.call_dest_e164);
+	memcpy(&pvt->options, &global_options, sizeof(pvt->options));
 	call_options = &pvt->options;
 
 	if (h323debug) {
Index: channels/Makefile
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/Makefile,v
retrieving revision 1.68
diff -u -r1.68 Makefile
--- channels/Makefile	28 Mar 2005 16:28:00 -0000	1.68
+++ channels/Makefile	31 Mar 2005 06:55:07 -0000
@@ -178,6 +178,9 @@
 chan_vpb.so: chan_vpb.o
 	 $(CXX) $(SOLINK) -o $@ $< -lvpb -lpthread -lm -ldl
 
+h323/libchanh323.a: FORCE
+	@[ -d h323 ] && $(MAKE) -C h323 libchanh323.a
+
 chan_h323.so: chan_h323.o h323/libchanh323.a
 	$(CC) $(SOLINK) -o $@ $< h323/libchanh323.a $(CHANH323LIB) -L$(PWLIBDIR)/lib $(PTLIB) -L$(OPENH323DIR)/lib $(H323LIB) -L/usr/lib -lcrypto -lssl -lexpat
 
@@ -193,6 +196,8 @@
 
 .depend:
 	../mkdep $(CFLAGS) `ls *.c`
+
+FORCE:
 
 env:
 	env
