h323neg.h

Go to the documentation of this file.
00001 /*
00002  * h323neg.h
00003  *
00004  * H.323 protocol handler
00005  *
00006  * Open H323 Library
00007  *
00008  * Copyright (c) 1998-2001 Equivalence Pty. Ltd.
00009  *
00010  * The contents of this file are subject to the Mozilla Public License
00011  * Version 1.0 (the "License"); you may not use this file except in
00012  * compliance with the License. You may obtain a copy of the License at
00013  * http://www.mozilla.org/MPL/
00014  *
00015  * Software distributed under the License is distributed on an "AS IS"
00016  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00017  * the License for the specific language governing rights and limitations
00018  * under the License.
00019  *
00020  * The Original Code is Open H323 Library.
00021  *
00022  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
00023  *
00024  * Portions of this code were written with the assisance of funding from
00025  * Vovida Networks, Inc. http://www.vovida.com.
00026  *
00027  * Contributor(s): ______________________________________.
00028  *
00029  * $Log: h323neg.h,v $
00030  * Revision 2.7  2002/11/10 11:33:16  robertj
00031  * Updated to OpenH323 v1.10.3
00032  *
00033  * Revision 2.6  2002/09/16 02:52:34  robertj
00034  * Added #define so can select if #pragma interface/implementation is used on
00035  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00036  *
00037  * Revision 2.5  2002/09/04 06:01:47  robertj
00038  * Updated to OpenH323 v1.9.6
00039  *
00040  * Revision 2.4  2002/07/01 04:56:30  robertj
00041  * Updated to OpenH323 v1.9.1
00042  *
00043  * Revision 2.3  2002/01/14 06:35:57  robertj
00044  * Updated to OpenH323 v1.7.9
00045  *
00046  * Revision 2.2  2001/10/05 00:22:13  robertj
00047  * Updated to PWLib 1.2.0 and OpenH323 1.7.0
00048  *
00049  * Revision 2.1  2001/08/13 05:10:39  robertj
00050  * Updates from OpenH323 v1.6.0 release.
00051  *
00052  * Revision 2.0  2001/07/27 15:48:24  robertj
00053  * Conversion of OpenH323 to Open Phone Abstraction Library (OPAL)
00054  *
00055  * Revision 1.34  2002/09/16 01:14:15  robertj
00056  * Added #define so can select if #pragma interface/implementation is used on
00057  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00058  *
00059  * Revision 1.33  2002/09/03 06:19:36  robertj
00060  * Normalised the multi-include header prevention ifdef/define symbol.
00061  *
00062  * Revision 1.32  2002/08/05 10:03:47  robertj
00063  * Cosmetic changes to normalise the usage of pragma interface/implementation.
00064  *
00065  * Revision 1.31  2002/06/26 08:51:16  robertj
00066  * Fixed deadlock if logical channel is closed via H.245 at exactly same
00067  *   time as being closed locally due to a channel I/O error.
00068  *
00069  * Revision 1.30  2002/05/03 03:08:35  robertj
00070  * Added replacementFor field in OLC when resolving conflicting channels.
00071  *
00072  * Revision 1.29  2002/01/09 00:21:36  robertj
00073  * Changes to support outgoing H.245 RequstModeChange.
00074  *
00075  * Revision 1.28  2002/01/01 23:32:30  craigs
00076  * Added HandleAck and StartRequest implementations for T.38
00077  * thanks to Vyacheslav Frolov
00078  *
00079  * Revision 1.27  2002/01/01 23:21:30  craigs
00080  * Added virtual keyword to many functions
00081  *
00082  * Revision 1.26  2001/09/12 01:54:45  robertj
00083  * Added virtual keyword to function in logical channel management.
00084  *
00085  * Revision 1.25  2001/08/06 03:08:11  robertj
00086  * Fission of h323.h to h323ep.h & h323con.h, h323.h now just includes files.
00087  *
00088  * Revision 1.24  2001/05/30 23:34:54  robertj
00089  * Added functions to send TCS=0 for transmitter side pause.
00090  *
00091  * Revision 1.23  2001/03/16 07:11:38  robertj
00092  * Added logical channel open function version without locking.
00093  *
00094  * Revision 1.22  2001/03/14 22:05:24  robertj
00095  * Changed H245NegLogicalChannel::Release() to be virtual protected rather than private.
00096  *
00097  * Revision 1.21  2001/03/14 03:20:25  robertj
00098  * Fixed possible nested mutex deadlock in logical channel negotiator.
00099  *
00100  * Revision 1.20  2001/03/06 04:44:46  robertj
00101  * Fixed problem where could send capability set twice. This should not be
00102  *   a problem except when talking to another broken stack, eg Cisco routers.
00103  *
00104  * Revision 1.19  2001/02/09 05:16:24  robertj
00105  * Added #pragma interface for GNU C++.
00106  *
00107  * Revision 1.18  2000/08/21 12:37:14  robertj
00108  * Fixed race condition if close call just as slow start media channels are opening, part 2.
00109  *
00110  * Revision 1.17  2000/07/14 08:59:56  robertj
00111  * Fixed race condition in closing connection and explicit close logical channel.
00112  *
00113  * Revision 1.16  2000/07/10 16:00:14  robertj
00114  * Added TCS=0 support.
00115  * Fixed bug where negotiations hang if not fast start and tunnelled but remot does not tunnel.
00116  *
00117  * Revision 1.15  2000/05/22 07:32:51  craigs
00118  * Fixed problem with ohphone silence detection hanging
00119  *
00120  * Revision 1.14  2000/05/16 08:13:32  robertj
00121  * Added function to find channel by session ID, supporting H323Connection::FindChannel() with mutex.
00122  *
00123  * Revision 1.13  2000/05/11 04:16:35  robertj
00124  * Fixed missing timeout (and typo!) in bidirectional open logical channel.
00125  *
00126  * Revision 1.12  2000/05/02 04:32:24  robertj
00127  * Fixed copyright notice comment.
00128  *
00129  * Revision 1.11  2000/04/10 17:50:53  robertj
00130  * Fixed yet another race condition needing mutex in logical channels management class.
00131  *
00132  * Revision 1.10  2000/04/05 03:17:30  robertj
00133  * Added more RTP statistics gathering and H.245 round trip delay calculation.
00134  *
00135  * Revision 1.9  2000/03/25 02:19:50  robertj
00136  * Fixed missing mutex call in some logical channels structure access.
00137  *
00138  * Revision 1.8  1999/11/06 11:58:38  robertj
00139  * Changed clean up to delete logical channels before channel destructor is called.
00140  *
00141  * Revision 1.7  1999/11/06 11:00:08  robertj
00142  * Fixed race condition in explicit channel close and connection close.
00143  *
00144  * Revision 1.6  1999/11/06 05:37:44  robertj
00145  * Complete rewrite of termination of connection to avoid numerous race conditions.
00146  *
00147  * Revision 1.5  1999/10/14 12:05:03  robertj
00148  * Fixed deadlock possibilities in clearing calls.
00149  *
00150  * Revision 1.4  1999/09/21 14:03:03  robertj
00151  * Fixed incorrect PTRACING test
00152  *
00153  * Revision 1.3  1999/09/08 04:05:48  robertj
00154  * Added support for video capabilities & codec, still needs the actual codec itself!
00155  *
00156  * Revision 1.2  1999/08/31 12:34:18  robertj
00157  * Added gatekeeper support.
00158  *
00159  * Revision 1.1  1999/08/25 05:07:49  robertj
00160  * File fission (critical mass reached).
00161  *
00162  */
00163 
00164 #ifndef __OPAL_H323NEG_H
00165 #define __OPAL_H323NEG_H
00166 
00167 #ifdef P_USE_PRAGMA
00168 #pragma interface
00169 #endif
00170 
00171 
00172 #include <h323/h323pdu.h>
00173 #include <h323/channels.h>
00174 
00175 
00176 class H323EndPoint;
00177 class H323Connection;
00178 
00179 
00181 
00184 class H245Negotiator : public PObject
00185 {
00186   PCLASSINFO(H245Negotiator, PObject);
00187 
00188   public:
00189     H245Negotiator(H323EndPoint & endpoint, H323Connection & connection);
00190 
00191   protected:
00192     PDECLARE_NOTIFIER(PTimer, H245Negotiator, HandleTimeout);
00193 
00194     H323EndPoint   & endpoint;
00195     H323Connection & connection;
00196     PTimer           replyTimer;
00197     PMutex           mutex;
00198 };
00199 
00200 
00203 class H245NegMasterSlaveDetermination : public H245Negotiator
00204 {
00205   PCLASSINFO(H245NegMasterSlaveDetermination, H245Negotiator);
00206 
00207   public:
00208     H245NegMasterSlaveDetermination(H323EndPoint & endpoint, H323Connection & connection);
00209 
00210     BOOL Start(BOOL renegotiate);
00211     void Stop();
00212     BOOL HandleIncoming(const H245_MasterSlaveDetermination & pdu);
00213     BOOL HandleAck(const H245_MasterSlaveDeterminationAck & pdu);
00214     BOOL HandleReject(const H245_MasterSlaveDeterminationReject & pdu);
00215     BOOL HandleRelease(const H245_MasterSlaveDeterminationRelease & pdu);
00216     void HandleTimeout(PTimer &, INT);
00217 
00218     BOOL IsMaster() const     { return status == e_DeterminedMaster; }
00219     BOOL IsDetermined() const { return state == e_Idle && status != e_Indeterminate; }
00220 
00221   protected:
00222     BOOL Restart();
00223 
00224     enum States {
00225       e_Idle, e_Outgoing, e_Incoming,
00226       e_NumStates
00227     } state;
00228 #if PTRACING
00229     static const char * const StateNames[e_NumStates];
00230     friend ostream & operator<<(ostream & o, States s) { return o << StateNames[s]; }
00231 #endif
00232 
00233     DWORD    determinationNumber;
00234     unsigned retryCount;
00235 
00236     enum MasterSlaveStatus {
00237       e_Indeterminate, e_DeterminedMaster, e_DeterminedSlave,
00238       e_NumStatuses
00239     } status;
00240 #if PTRACING
00241     static const char * const StatusNames[e_NumStatuses];
00242     friend ostream & operator<<(ostream & o , MasterSlaveStatus s) { return o << StatusNames[s]; }
00243 #endif
00244 };
00245 
00246 
00249 class H245NegTerminalCapabilitySet : public H245Negotiator
00250 {
00251   PCLASSINFO(H245NegTerminalCapabilitySet, H245Negotiator);
00252 
00253   public:
00254     H245NegTerminalCapabilitySet(H323EndPoint & endpoint, H323Connection & connection);
00255 
00256     BOOL Start(BOOL renegotiate, BOOL empty = FALSE);
00257     void Stop();
00258     BOOL HandleIncoming(const H245_TerminalCapabilitySet & pdu);
00259     BOOL HandleAck(const H245_TerminalCapabilitySetAck & pdu);
00260     BOOL HandleReject(const H245_TerminalCapabilitySetReject & pdu);
00261     BOOL HandleRelease(const H245_TerminalCapabilitySetRelease & pdu);
00262     void HandleTimeout(PTimer &, INT);
00263 
00264     BOOL HasSentCapabilities() const { return state == e_Sent; }
00265     BOOL HasReceivedCapabilities() const { return receivedCapabilites; }
00266 
00267   protected:
00268     enum States {
00269       e_Idle, e_InProgress, e_Sent,
00270       e_NumStates
00271     } state;
00272 #if PTRACING
00273     static const char * const StateNames[e_NumStates];
00274     friend ostream & operator<<(ostream & o, States s) { return o << StateNames[s]; }
00275 #endif
00276 
00277     unsigned inSequenceNumber;
00278     unsigned outSequenceNumber;
00279 
00280     BOOL receivedCapabilites;
00281 };
00282 
00283 
00286 class H245NegLogicalChannel : public H245Negotiator
00287 {
00288   PCLASSINFO(H245NegLogicalChannel, H245Negotiator);
00289 
00290   public:
00291     H245NegLogicalChannel(H323EndPoint & endpoint,
00292                           H323Connection & connection,
00293                           const H323ChannelNumber & channelNumber);
00294     H245NegLogicalChannel(H323EndPoint & endpoint,
00295                           H323Connection & connection,
00296                           H323Channel & channel);
00297     ~H245NegLogicalChannel();
00298 
00299     virtual BOOL Open(
00300       const H323Capability & capability,
00301       unsigned sessionID,
00302       unsigned replacementFor = 0
00303     );
00304     virtual BOOL Close();
00305     virtual BOOL HandleOpen(const H245_OpenLogicalChannel & pdu);
00306     virtual BOOL HandleOpenAck(const H245_OpenLogicalChannelAck & pdu);
00307     virtual BOOL HandleOpenConfirm(const H245_OpenLogicalChannelConfirm & pdu);
00308     virtual BOOL HandleReject(const H245_OpenLogicalChannelReject & pdu);
00309     virtual BOOL HandleClose(const H245_CloseLogicalChannel & pdu);
00310     virtual BOOL HandleCloseAck(const H245_CloseLogicalChannelAck & pdu);
00311     virtual BOOL HandleRequestClose(const H245_RequestChannelClose & pdu);
00312     virtual BOOL HandleRequestCloseAck(const H245_RequestChannelCloseAck & pdu);
00313     virtual BOOL HandleRequestCloseReject(const H245_RequestChannelCloseReject & pdu);
00314     virtual BOOL HandleRequestCloseRelease(const H245_RequestChannelCloseRelease & pdu);
00315     virtual void HandleTimeout(PTimer &, INT);
00316 
00317     H323Channel * GetChannel();
00318 
00319 
00320   protected:
00321     virtual BOOL OpenWhileLocked(
00322       const H323Capability & capability,
00323       unsigned sessionID,
00324       unsigned replacementFor = 0
00325     );
00326     virtual BOOL CloseWhileLocked();
00327     virtual void Release();
00328 
00329 
00330     H323Channel * channel;
00331 
00332     H323ChannelNumber channelNumber;
00333 
00334     enum States {
00335       e_Released,
00336       e_AwaitingEstablishment,
00337       e_Established,
00338       e_AwaitingRelease,
00339       e_AwaitingConfirmation,
00340       e_AwaitingResponse,
00341       e_NumStates
00342     } state;
00343 #if PTRACING
00344     static const char * const StateNames[e_NumStates];
00345     friend ostream & operator<<(ostream & o, States s) { return o << StateNames[s]; }
00346 #endif
00347 
00348 
00349   friend class H245NegLogicalChannels;
00350 };
00351 
00352 
00353 PDICTIONARY(H245LogicalChannelDict, H323ChannelNumber, H245NegLogicalChannel);
00354 
00357 class H245NegLogicalChannels : public H245Negotiator
00358 {
00359   PCLASSINFO(H245NegLogicalChannels, H245Negotiator);
00360 
00361   public:
00362     H245NegLogicalChannels(H323EndPoint & endpoint, H323Connection & connection);
00363 
00364     virtual void Add(H323Channel & channel);
00365 
00366     virtual BOOL Open(
00367       const H323Capability & capability,
00368       unsigned sessionID,
00369       unsigned replacementFor = 0
00370     );
00371     virtual BOOL Close(unsigned channelNumber, BOOL fromRemote);
00372     virtual BOOL HandleOpen(const H245_OpenLogicalChannel & pdu);
00373     virtual BOOL HandleOpenAck(const H245_OpenLogicalChannelAck & pdu);
00374     virtual BOOL HandleOpenConfirm(const H245_OpenLogicalChannelConfirm & pdu);
00375     virtual BOOL HandleReject(const H245_OpenLogicalChannelReject & pdu);
00376     virtual BOOL HandleClose(const H245_CloseLogicalChannel & pdu);
00377     virtual BOOL HandleCloseAck(const H245_CloseLogicalChannelAck & pdu);
00378     virtual BOOL HandleRequestClose(const H245_RequestChannelClose & pdu);
00379     virtual BOOL HandleRequestCloseAck(const H245_RequestChannelCloseAck & pdu);
00380     virtual BOOL HandleRequestCloseReject(const H245_RequestChannelCloseReject & pdu);
00381     virtual BOOL HandleRequestCloseRelease(const H245_RequestChannelCloseRelease & pdu);
00382 
00383     H323ChannelNumber GetNextChannelNumber();
00384     PINDEX GetSize() const { return channels.GetSize(); }
00385     H323Channel * GetChannelAt(PINDEX i);
00386     H323Channel * FindChannel(unsigned channelNumber, BOOL fromRemote);
00387     H245NegLogicalChannel & GetNegLogicalChannelAt(PINDEX i);
00388     H245NegLogicalChannel * FindNegLogicalChannel(unsigned channelNumber, BOOL fromRemote);
00389     H323Channel * FindChannelBySession(unsigned rtpSessionId, BOOL fromRemote);
00390     void RemoveAll();
00391 
00392   protected:
00393     H323ChannelNumber      lastChannelNumber;
00394     H245LogicalChannelDict channels;
00395 };
00396 
00397 
00400 class H245NegRequestMode : public H245Negotiator
00401 {
00402   PCLASSINFO(H245NegRequestMode, H245Negotiator);
00403 
00404   public:
00405     H245NegRequestMode(H323EndPoint & endpoint, H323Connection & connection);
00406 
00407     virtual BOOL StartRequest(const PString & newModes);
00408     virtual BOOL StartRequest(const H245_ArrayOf_ModeDescription & newModes);
00409     virtual BOOL HandleRequest(const H245_RequestMode & pdu);
00410     virtual BOOL HandleAck(const H245_RequestModeAck & pdu);
00411     virtual BOOL HandleReject(const H245_RequestModeReject & pdu);
00412     virtual BOOL HandleRelease(const H245_RequestModeRelease & pdu);
00413     virtual void HandleTimeout(PTimer &, INT);
00414 
00415   protected:
00416     BOOL awaitingResponse;
00417     unsigned inSequenceNumber;
00418     unsigned outSequenceNumber;
00419 };
00420 
00421 
00424 class H245NegRoundTripDelay : public H245Negotiator
00425 {
00426   PCLASSINFO(H245NegRoundTripDelay, H245Negotiator);
00427 
00428   public:
00429     H245NegRoundTripDelay(H323EndPoint & endpoint, H323Connection & connection);
00430 
00431     BOOL StartRequest();
00432     BOOL HandleRequest(const H245_RoundTripDelayRequest & pdu);
00433     BOOL HandleResponse(const H245_RoundTripDelayResponse & pdu);
00434     void HandleTimeout(PTimer &, INT);
00435 
00436     PTimeInterval GetRoundTripDelay() const { return roundTripTime; }
00437     BOOL IsRemoteOffline() const { return retryCount == 0; }
00438 
00439   protected:
00440     BOOL          awaitingResponse;
00441     unsigned      sequenceNumber;
00442     PTimeInterval tripStartTime;
00443     PTimeInterval roundTripTime;
00444     unsigned      retryCount;
00445 };
00446 
00447 
00448 #endif // __OPAL_H323NEG_H
00449 
00450 

Generated on Mon Sep 25 16:19:59 2006 for OPAL by  doxygen 1.4.7