4 * OpenH323 Channel Driver for ASTERISK PBX.
6 * For The NuFone Network
8 * This code has been derived from code created by
9 * Michael Manousos and Mark Spencer
11 * This file is part of the chan_h323 driver for Asterisk
13 * chan_h323 is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * chan_h323 is distributed WITHOUT ANY WARRANTY; without even
19 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 /* PWlib Required Components */
32 #define MAJOR_VERSION 0
33 #define MINOR_VERSION 1
34 #define BUILD_TYPE ReleaseCode
35 #define BUILD_NUMBER 0
37 /** Counter for the number of connections */
41 int mode = H323_DTMF_RFC2833;
43 /** Options for connections creation */
45 BOOL noH245Tunnelling;
46 BOOL noSilenceSuppression;
49 * We assume that only one endPoint should exist.
50 * The application cannot run the h323_end_point_create() more than once
51 * FIXME: Singleton this, for safety
53 MyH323EndPoint *endPoint = NULL;
55 /** PWLib entry point */
56 MyProcess *localProcess = NULL;
59 H323ListenerTCP *tcpListener;
61 MyProcess::MyProcess(): PProcess("The NuFone Network's", "H.323 Channel Driver for Asterisk",
62 MAJOR_VERSION, MINOR_VERSION, BUILD_TYPE, BUILD_NUMBER)
67 MyProcess::~MyProcess()
69 cout << " == PWLib proces going down." << endl;
74 void MyProcess::Main()
76 cout << " == Creating H.323 Endpoint" << endl;
77 endPoint = new MyH323EndPoint();
78 PTrace::Initialise(0, NULL, PTrace::Timestamp | PTrace::Thread | PTrace::FileAndLine);
81 ClearCallThread::ClearCallThread(const char *tc) : PThread(10000, PThread::NoAutoDeleteThread)
87 ClearCallThread::~ClearCallThread()
90 cout << " == ClearCall thread going down." << endl;
94 void ClearCallThread::Main()
96 endPoint->ClearCall(token);
101 #define H323_NAME OPAL_G7231_6k3"{sw}"
103 H323_REGISTER_CAPABILITY(H323_G7231Capability, H323_NAME);
105 H323_G7231Capability::H323_G7231Capability(BOOL annexA_)
106 : H323AudioCapability(7, 4)
111 PObject::Comparison H323_G7231Capability::Compare(const PObject & obj) const
113 Comparison result = H323AudioCapability::Compare(obj);
114 if (result != EqualTo)
117 PINDEX otherAnnexA = ((const H323_G7231Capability &)obj).annexA;
118 if (annexA < otherAnnexA)
120 if (annexA > otherAnnexA)
125 PObject * H323_G7231Capability::Clone() const
127 return new H323_G7231Capability(*this);
131 PString H323_G7231Capability::GetFormatName() const
137 unsigned H323_G7231Capability::GetSubType() const
139 return H245_AudioCapability::e_g7231;
143 BOOL H323_G7231Capability::OnSendingPDU(H245_AudioCapability & cap,
144 unsigned packetSize) const
146 cap.SetTag(H245_AudioCapability::e_g7231);
148 H245_AudioCapability_g7231 & g7231 = cap;
149 g7231.m_maxAl_sduAudioFrames = packetSize;
150 g7231.m_silenceSuppression = annexA;
156 BOOL H323_G7231Capability::OnReceivedPDU(const H245_AudioCapability & cap,
157 unsigned & packetSize)
159 if (cap.GetTag() != H245_AudioCapability::e_g7231)
162 const H245_AudioCapability_g7231 & g7231 = cap;
163 packetSize = g7231.m_maxAl_sduAudioFrames;
164 annexA = g7231.m_silenceSuppression;
170 H323Codec * H323_G7231Capability::CreateCodec(H323Codec::Direction direction) const
176 * The fullAddress parameter is used directly in the MakeCall method so
177 * the General form for the fullAddress argument is :
178 * [alias@][transport$]host[:port]
179 * default values: alias = the same value as host.
183 int MyH323EndPoint::MakeCall(const PString & dest, PString & token,
184 unsigned int *callReference, unsigned int port)
187 MyH323Connection * connection;
189 /* Determine whether we are using a gatekeeper or not. */
190 if (GetGatekeeper() != NULL) {
193 cout << " -- Making call to " << fullAddress << " using gatekeeper." << endl;
195 fullAddress = dest; /* host */
197 cout << " -- Making call to " << fullAddress << "." << endl;
200 if (!(connection = (MyH323Connection *)H323EndPoint::MakeCallLocked(fullAddress, token))) {
202 cout << "Error making call to \"" << fullAddress << '"' << endl;
206 *callReference = connection->GetCallReference();
207 connection->Unlock();
210 cout << " -- " << GetLocalUserName() << " is calling host " << fullAddress << endl;
211 cout << " -- " << "Call token is " << (const char *)token << endl;
212 cout << " -- Call reference is " << *callReference << endl;
217 void MyH323EndPoint::SetEndpointTypeInfo( H225_EndpointType & info ) const
219 H323EndPoint::SetEndpointTypeInfo(info);
220 info.m_gateway.IncludeOptionalField(H225_GatewayInfo::e_protocol);
221 info.m_gateway.m_protocol.SetSize(1);
222 H225_SupportedProtocols &protocol=info.m_gateway.m_protocol[0];
223 protocol.SetTag(H225_SupportedProtocols::e_voice);
224 PINDEX as=SupportedPrefixes.GetSize();
225 ((H225_VoiceCaps &)protocol).m_supportedPrefixes.SetSize(as);
226 for (PINDEX p=0; p<as; p++) {
227 H323SetAliasAddress(SupportedPrefixes[p], ((H225_VoiceCaps &)protocol).m_supportedPrefixes[p].m_prefix);
231 void MyH323EndPoint::SetGateway(void)
233 terminalType = e_GatewayOnly;
236 H323Capabilities MyH323EndPoint::GetCapabilities(void)
241 BOOL MyH323EndPoint::ClearCall(const PString & token)
244 cout << " -- ClearCall: Request to clear call with token " << token << endl;
245 return H323EndPoint::ClearCall(token);
248 void MyH323EndPoint::SendUserTone(const PString &token, char tone)
250 H323Connection *connection = NULL;
252 connection = FindConnectionWithLock(token);
253 if (connection != NULL) {
254 connection->SendUserInputTone(tone, 500);
255 connection->Unlock();
259 void MyH323EndPoint::OnClosedLogicalChannel(H323Connection & connection, const H323Channel & channel)
263 cout << " channelsOpen = " << channelsOpen << endl;
264 H323EndPoint::OnClosedLogicalChannel(connection, channel);
267 void MyH323EndPoint::OnConnectionEstablished(H323Connection & connection, const PString & estCallToken)
270 cout << " -- Connection Established with \"" << connection.GetRemotePartyName() << "\"" << endl;
271 on_connection_established(connection.GetCallReference());
274 /** OnConnectionCleared callback function is called upon the dropping of an established
277 void MyH323EndPoint::OnConnectionCleared(H323Connection & connection, const PString & clearedCallToken)
279 PString remoteName = connection.GetRemotePartyName();
283 cd.call_reference = connection.GetCallReference();
284 cd.call_token = (const char *)connection.GetCallToken();
285 cd.call_source_aliases = (const char *)connection.GetRemotePartyName();
287 /* Convert complex strings */
289 if ((s = strchr(cd.call_source_aliases, ' ')) != NULL)
292 /* Invoke the PBX application registered callback */
293 on_connection_cleared(cd);
295 switch (connection.GetCallEndReason()) {
296 case H323Connection::EndedByCallForwarded :
298 cout << " -- " << remoteName << " has forwarded the call" << endl;
300 case H323Connection::EndedByRemoteUser :
302 cout << " -- " << remoteName << " has cleared the call" << endl;
304 case H323Connection::EndedByCallerAbort :
306 cout << " -- " << remoteName << " has stopped calling" << endl;
308 case H323Connection::EndedByRefusal :
310 cout << " -- " << remoteName << " did not accept your call" << endl;
312 case H323Connection::EndedByRemoteBusy :
314 cout << " -- " << remoteName << " was busy" << endl;
316 case H323Connection::EndedByRemoteCongestion :
318 cout << " -- Congested link to " << remoteName << endl;
320 case H323Connection::EndedByNoAnswer :
322 cout << " -- " << remoteName << " did not answer your call" << endl;
324 case H323Connection::EndedByTransportFail :
326 cout << " -- Call with " << remoteName << " ended abnormally" << endl;
328 case H323Connection::EndedByCapabilityExchange :
330 cout << " -- Could not find common codec with " << remoteName << endl;
332 case H323Connection::EndedByNoAccept :
334 cout << " -- Did not accept incoming call from " << remoteName << endl;
336 case H323Connection::EndedByAnswerDenied :
338 cout << " -- Refused incoming call from " << remoteName << endl;
340 case H323Connection::EndedByNoUser :
342 cout << " -- Remote endpoint could not find user: " << remoteName << endl;
344 case H323Connection::EndedByNoBandwidth :
346 cout << " -- Call to " << remoteName << " aborted, insufficient bandwidth." << endl;
348 case H323Connection::EndedByUnreachable :
350 cout << " -- " << remoteName << " could not be reached." << endl;
352 case H323Connection::EndedByHostOffline :
354 cout << " -- " << remoteName << " is not online." << endl;
356 case H323Connection::EndedByNoEndPoint :
358 cout << " -- No phone running for " << remoteName << endl;
360 case H323Connection::EndedByConnectFail :
362 cout << " -- Transport error calling " << remoteName << endl;
366 cout << " -- Call with " << remoteName << " completed" << endl;
368 if(connection.IsEstablished())
370 cout << " -- Call duration " << setprecision(0) << setw(5) << (PTime() - connection.GetConnectionStartTime()) << endl;
374 H323Connection * MyH323EndPoint::CreateConnection(unsigned callReference, void *outbound)
376 unsigned options = 0;
379 options |= H323Connection::FastStartOptionDisable;
381 if (noH245Tunnelling)
382 options |= H323Connection::H245TunnelingOptionDisable;
384 return new MyH323Connection(*this, callReference, options);
388 /* MyH323Connection */
389 MyH323Connection::MyH323Connection(MyH323EndPoint & ep,
390 unsigned callReference,
396 remoteIpAddress = 0; // IP Address of remote endpoint
397 remotePort = 0; // remote endpoint Data port (control is dataPort+1)
400 cout << " == New H.323 Connection created." << endl;
404 MyH323Connection::~MyH323Connection()
407 cout << " == H.323 Connection deleted." << endl;
411 H323Connection::AnswerCallResponse MyH323Connection::OnAnswerCall(const PString & caller,
412 const H323SignalPDU & /*setupPDU*/,
413 H323SignalPDU & /*connectPDU*/)
415 /* The call will be answered later with "AnsweringCall()" function.
417 return H323Connection::AnswerCallAlertWithMedia;
420 BOOL MyH323Connection::OnAlerting(const H323SignalPDU & /*alertingPDU*/, const PString & username)
424 cout << " -- Ringing phone for \"" << username << "\"" << endl;
428 BOOL MyH323Connection::OnReceivedSignalSetup(const H323SignalPDU & setupPDU)
432 cout << " -- Received SETUP message..." << endl;
438 PString sourceAliases;
442 PIPSocket::Address Ip;
445 sourceAliases = setupPDU.GetSourceAliases();
446 destAliases = setupPDU.GetDestinationAlias();
449 setupPDU.GetSourceE164(sourceE164);
451 setupPDU.GetDestinationE164(destE164);
453 /* Convert complex strings */
454 // FIXME: deal more than one source alias
456 if ((s = strchr(sourceAliases, ' ')) != NULL)
458 if ((s = strchr(sourceAliases, '\t')) != NULL)
461 if ((s1 = strchr(destAliases, ' ')) != NULL)
463 if ((s1 = strchr(destAliases, '\t')) != NULL)
466 GetSignallingChannel()->GetRemoteAddress().GetIpAndPort(Ip, sourcePort);
468 sourceIp = Ip.AsString();
470 cd.call_reference = GetCallReference();
471 cd.call_token = (const char *)GetCallToken();
472 cd.call_source_aliases = (const char *)sourceAliases;
473 cd.call_dest_alias = (const char *)destAliases;
474 cd.call_source_e164 = (const char *)sourceE164;
475 cd.call_dest_e164 = (const char *)destE164;
476 cd.sourceIp = (const char *)sourceIp;
478 /* Notify Asterisk of the request */
479 int res = on_incoming_call(cd);
483 cout << " -- Call Failed" << endl;
487 return H323Connection::OnReceivedSignalSetup(setupPDU);
490 BOOL MyH323Connection::OnSendSignalSetup(H323SignalPDU & setupPDU)
495 cout << " -- Sending SETUP message" << endl;
497 sourceAliases = setupPDU.GetSourceAliases();
498 destAliases = setupPDU.GetDestinationAlias();
501 setupPDU.GetSourceE164(sourceE164);
503 setupPDU.GetDestinationE164(destE164);
505 /* Convert complex strings */
506 // FIXME: deal more than one source alias
508 if ((s = strchr(sourceAliases, ' ')) != NULL)
510 if ((s = strchr(sourceAliases, '\t')) != NULL)
513 if ((s1 = strchr(destAliases, ' ')) != NULL)
515 if ((s1 = strchr(destAliases, '\t')) != NULL)
518 cd.call_reference = GetCallReference();
519 cd.call_token = (const char *)GetCallToken();
520 cd.call_source_aliases = (const char *)sourceAliases;
521 cd.call_dest_alias = (const char *)destAliases;
522 cd.call_source_e164 = (const char *)sourceE164;
523 cd.call_dest_e164 = (const char *)destE164;
525 int res = on_outgoing_call(cd);
529 cout << " -- Call Failed" << endl;
533 return H323Connection::OnSendSignalSetup(setupPDU);
536 BOOL MyH323Connection::OnSendReleaseComplete(H323SignalPDU & releaseCompletePDU)
539 cout << " -- Sending RELEASE COMPLETE" << endl;
540 return H323Connection::OnSendReleaseComplete(releaseCompletePDU);
543 BOOL MyH323Connection::OnReceivedFacility(const H323SignalPDU & pdu)
546 cout << " -- Received Facility message... " << endl;
547 return H323Connection::OnReceivedFacility(pdu);
550 void MyH323Connection::OnReceivedReleaseComplete(const H323SignalPDU & pdu)
553 cout << " -- Received RELEASE COMPLETE message..." << endl;
554 return H323Connection::OnReceivedReleaseComplete(pdu);
558 BOOL MyH323Connection::OnClosingLogicalChannel(H323Channel & channel)
561 cout << " -- Closing logical channel..." << endl;
562 return H323Connection::OnClosingLogicalChannel(channel);
566 void MyH323Connection::SendUserInputTone(char tone, unsigned duration)
569 cout << " -- Sending user input tone (" << tone << ") to remote" << endl;
571 on_send_digit(GetCallReference(), tone);
573 H323Connection::SendUserInputTone(tone, duration);
576 void MyH323Connection::OnUserInputTone(char tone, unsigned duration, unsigned logicalChannel, unsigned rtpTimestamp)
578 if (mode == H323_DTMF_INBAND) {
580 cout << " -- Received user input tone (" << tone << ") from remote" << endl;
581 on_send_digit(GetCallReference(), tone);
583 H323Connection::OnUserInputTone(tone, duration, logicalChannel, rtpTimestamp);
586 void MyH323Connection::OnUserInputString(const PString &value)
588 if (mode == H323_DTMF_RFC2833) {
590 cout << " -- Received user input string (" << value << ") from remote." << endl;
591 on_send_digit(GetCallReference(), value[0]);
595 H323Channel * MyH323Connection::CreateRealTimeLogicalChannel(const H323Capability & capability,
596 H323Channel::Directions dir,
598 const H245_H2250LogicalChannelParameters * /*param*/)
602 /* Establish the Local (A side) IP Address */
603 GetControlChannel().GetLocalAddress().GetIpAndPort(externalIpAddress, port);
605 /* Notify Asterisk of the request and get the port */
606 externalPort = on_create_connection(GetCallReference());
609 cout << " =*= In CreateRealTimeLogicalChannel for call " << GetCallReference() << endl;
610 cout << " -- externalIpAddress: " << externalIpAddress << endl;
611 cout << " -- externalPort: " << externalPort << endl;
612 cout << " -- Direction: " << dir << endl;
615 return new H323_ExternalRTPChannel(*this, capability, dir, sessionID, externalIpAddress, externalPort);
618 /** This callback function is invoked once upon creation of each
619 * channel for an H323 session
621 BOOL MyH323Connection::OnStartLogicalChannel(H323Channel & channel)
624 cout << " -- Started logical channel: ";
625 cout << ((channel.GetDirection()==H323Channel::IsTransmitter)?"sending ":((channel.GetDirection()==H323Channel::IsReceiver)?"receiving ":" "));
626 cout << (const char *)(channel.GetCapability()).GetFormatName() << endl;
628 // adjust the count of channels we have open
631 cout << " -- channelsOpen = " << channelsOpen << endl;
633 H323_ExternalRTPChannel & external = (H323_ExternalRTPChannel &)channel;
634 external.GetRemoteAddress(remoteIpAddress, remotePort);
637 cout << " -- remoteIpAddress: " << remoteIpAddress << endl;
638 cout << " -- remotePort: " << remotePort << endl;
639 cout << " -- ExternalIpAddress: " << externalIpAddress << endl;
640 cout << " -- ExternalPort: " << externalPort << endl;
642 /* Notify Asterisk of remote RTP information */
643 on_start_logical_channel(GetCallReference(), (const char *)remoteIpAddress.AsString(), remotePort);
649 MyGatekeeperServer::MyGatekeeperServer(MyH323EndPoint & ep)
650 : H323GatekeeperServer(ep),
656 BOOL MyGatekeeperServer::Initialise()
660 PWaitAndSignal mutex(reconfigurationMutex);
662 SetGatekeeperIdentifier("TESTIES");
664 // Interfaces to listen on
665 H323TransportAddressArray interfaces;
666 interfaces.Append(new H323TransportAddress(0.0.0.0);
667 AddListeners(interfaces);
677 /** IMPLEMENTATION OF C FUNCTIONS */
680 * The extern "C" directive takes care for
681 * the ANSI-C representation of linkable symbols
685 int end_point_exist(void)
693 void h323_end_point_create(void)
696 localProcess = new MyProcess();
697 localProcess->Main();
700 void h323_gk_urq(void)
702 if (!end_point_exist()) {
703 cout << " ERROR: [h323_gk_urq] No Endpoint, this is bad" << endl;
707 endPoint->RemoveGatekeeper();
710 void h323_end_process(void)
715 void h323_debug(int flag, unsigned level)
718 PTrace:: SetLevel(level);
720 PTrace:: SetLevel(0);
723 /** Installs the callback functions on behalf of the PBX application */
724 void h323_callback_register(setup_incoming_cb ifunc,
725 setup_outbound_cb sfunc,
726 on_connection_cb confunc,
727 start_logchan_cb lfunc,
729 con_established_cb efunc,
732 on_incoming_call = ifunc;
733 on_outgoing_call = sfunc;
734 on_create_connection = confunc;
735 on_start_logical_channel = lfunc;
736 on_connection_cleared = clfunc;
737 on_connection_established = efunc;
738 on_send_digit = dfunc;
742 * Add capability to the capability table of the end point.
744 int h323_set_capability(int cap, int dtmfMode)
750 if (!end_point_exist()) {
751 cout << " ERROR: [h323_set_capablity] No Endpoint, this is bad" << endl;
756 if (dtmfMode == H323_DTMF_INBAND)
757 endPoint->SetSendUserInputMode(H323Connection::SendUserInputAsTone);
759 endPoint->SetSendUserInputMode(H323Connection::SendUserInputAsInlineRFC2833);
762 /* Hardcode this for now (Someone tell me if T.38 works now
763 or provide me with some debug so we can make this work */
765 // endPoint->SetCapability(0, 0, new H323_T38Capability(H323_T38Capability::e_UDP));
767 if (cap & AST_FORMAT_SPEEX) {
768 /* Not real sure if Asterisk acutally supports all
769 of the various different bit rates so add them
770 all and figure it out later*/
772 endPoint->SetCapability(0, 0, new SpeexNarrow2AudioCapability());
773 endPoint->SetCapability(0, 0, new SpeexNarrow3AudioCapability());
774 endPoint->SetCapability(0, 0, new SpeexNarrow4AudioCapability());
775 endPoint->SetCapability(0, 0, new SpeexNarrow5AudioCapability());
776 endPoint->SetCapability(0, 0, new SpeexNarrow6AudioCapability());
779 if (cap & AST_FORMAT_G729A) {
780 H323_G729ACapability *g729aCap;
781 endPoint->SetCapability(0, 0, g729aCap = new H323_G729ACapability);
784 if (cap & AST_FORMAT_G723_1) {
785 H323_G7231Capability *g7231Cap;
786 endPoint->SetCapability(0, 0, g7231Cap = new H323_G7231Capability);
789 if (cap & AST_FORMAT_GSM) {
790 H323_GSM0610Capability *gsmCap;
791 endPoint->SetCapability(0, 0, gsmCap = new H323_GSM0610Capability);
792 gsmCap->SetTxFramesInPacket(gsmFrames);
795 if (cap & AST_FORMAT_ULAW) {
797 H323_G711Capability *g711uCap;
798 endPoint->SetCapability(0, 0, g711uCap = new H323_G711Capability(H323_G711Capability::muLaw));
799 g711uCap->SetTxFramesInPacket(g711Frames);
802 if (cap & AST_FORMAT_ALAW) {
803 H323_G711Capability *g711aCap;
804 endPoint->SetCapability(0, 0, g711aCap = new H323_G711Capability(H323_G711Capability::ALaw));
805 g711aCap->SetTxFramesInPacket(g711Frames);
811 /** Start the H.323 listener */
812 int h323_start_listener(int listenPort, struct sockaddr_in bindaddr)
815 if (!end_point_exist()) {
816 cout << "ERROR: [h323_start_listener] No Endpoint, this is bad!" << endl;
820 PIPSocket::Address interfaceAddress(bindaddr.sin_addr);
825 tcpListener = new H323ListenerTCP(*endPoint, interfaceAddress, (WORD)listenPort);
827 if (!endPoint->StartListener(tcpListener)) {
828 cout << "ERROR: Could not open H.323 listener port on " << ((H323ListenerTCP *) tcpListener)->GetListenerPort() << endl;
834 // cout << " == H.323 listener started on " << ((H323ListenerTCP *) tcpListener)->GetTransportAddress() << endl;
835 cout << " == H.323 listener started" << endl;
841 int h323_set_alias(struct oh323_alias *alias)
845 PString h323id(alias->name);
846 PString e164(alias->e164);
848 if (!end_point_exist()) {
849 cout << "ERROR: [h323_set_alias] No Endpoint, this is bad!" << endl;
853 cout << " == Adding alias \"" << h323id << "\" to endpoint" << endl;
854 endPoint->AddAliasName(h323id);
856 endPoint->RemoveAliasName(localProcess->GetUserName());
858 if (!e164.IsEmpty()) {
859 cout << " == Adding E.164 \"" << e164 << "\" to endpoint" << endl;
860 endPoint->AddAliasName(e164);
862 if (strlen(alias->prefix)) {
864 num = strsep(&p, ",");
866 cout << " == Adding Prefix \"" << num << "\" to endpoint" << endl;
867 endPoint->SupportedPrefixes += PString(num);
868 endPoint->SetGateway();
869 num = strsep(&p, ",");
877 void h323_set_id(char *id)
882 cout << " == Using " << h323id << " as our H.323ID for this call" << endl;
886 endPoint->SetLocalUserName(h323id);
889 /** Establish Gatekeeper communiations, if so configured,
890 * register aliases for the H.323 endpoint to respond to.
892 int h323_set_gk(int gatekeeper_discover, char *gatekeeper, char *secret)
894 PString gkName = PString(gatekeeper);
895 PString pass = PString(secret);
897 if (!end_point_exist()) {
898 cout << "ERROR: [h323_set_gk] No Endpoint, this is bad!" << endl;
903 cout << "Error: Gatekeeper cannot be NULL" << endl;
907 if (strlen(secret)) {
908 endPoint->SetGatekeeperPassword(pass);
912 if (gatekeeper_discover) {
913 /* discover the gk using multicast */
914 if (endPoint->DiscoverGatekeeper(new H323TransportUDP(*endPoint))) {
915 cout << " == Using " << (endPoint->GetGatekeeper())->GetName() << " as our Gatekeeper." << endl;
917 cout << " *** Could not find a gatekeeper." << endl;
921 /* Gatekeeper operations */
922 H323TransportUDP *rasChannel = new H323TransportUDP(*endPoint);
925 cout << " *** No RAS Channel, this is bad" << endl;
928 if (endPoint->SetGatekeeper(gkName, rasChannel)) {
929 cout << " == Using " << (endPoint->GetGatekeeper())->GetName() << " as our Gatekeeper." << endl;
931 cout << " *** Error registering with gatekeeper \"" << gkName << "\". " << endl;
933 /* XXX Maybe we should fire a new thread to attempt to re-register later and not kill asterisk here? */
943 /** Send a DTMF tone over the H323Connection with the
946 void h323_send_tone(const char *call_token, char tone)
948 if (!end_point_exist()) {
949 cout << "ERROR: [h323_send_tone] No Endpoint, this is bad!" << endl;
953 PString token = PString(call_token);
954 endPoint->SendUserTone(token, tone);
957 /** Make a call to the remote endpoint.
959 int h323_make_call(char *host, call_details_t *cd, call_options_t call_options)
964 if (!end_point_exist()) {
970 res = endPoint->MakeCall(dest, token, &cd->call_reference, call_options.port);
971 memcpy((char *)(cd->call_token), (const unsigned char *)token, token.GetLength());
976 int h323_clear_call(const char *call_token)
978 if (!end_point_exist()) {
982 ClearCallThread *clearCallThread = new ClearCallThread(call_token);
983 clearCallThread->WaitForTermination();
988 /** This function tells the h.323 stack to either
989 answer or deny an incoming call */
990 int h323_answering_call(const char *token, int busy)
992 const PString currentToken(token);
994 H323Connection * connection;
996 connection = endPoint->FindConnectionWithLock(currentToken);
998 if (connection == NULL) {
999 cout << "No connection found for " << token << endl;
1004 connection->AnsweringCall(H323Connection::AnswerCallNow);
1005 connection->Unlock();
1008 connection->AnsweringCall(H323Connection::AnswerCallDenied);
1009 connection->Unlock();
1016 int h323_show_codec(int fd, int argc, char *argv[])
1018 cout << "Allowed Codecs:\n\t" << setprecision(2) << endPoint->GetCapabilities() << endl;
1024 /* alas, this doesn't work :( */
1025 void h323_native_bridge(const char *token, char *them, char *us)
1027 H323Channel *channel;
1028 H323Connection *connection = endPoint->FindConnectionWithLock(token);
1031 cout << "ERROR: No connection active.\n";
1035 connection->Unlock();
1036 channel = connection->FindChannel(RTP_Session::DefaultAudioSessionID, TRUE);
1037 H323_ExternalRTPChannel *external = (H323_ExternalRTPChannel *)channel;
1038 external->SetExternalAddress(them, us); // data (RTP), control (Asterisk)