00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145 #ifndef __OPAL_H323NEG_H
00146 #define __OPAL_H323NEG_H
00147
00148 #ifdef P_USE_PRAGMA
00149 #pragma interface
00150 #endif
00151
00152
00153 #include "h323pdu.h"
00154 #include "channels.h"
00155
00156
00157
00159
00162 class H245Negotiator : public PObject
00163 {
00164 PCLASSINFO(H245Negotiator, PObject);
00165
00166 public:
00167 H245Negotiator(H323EndPoint & endpoint, H323Connection & connection);
00168
00169 protected:
00170 PDECLARE_NOTIFIER(PTimer, H245Negotiator, HandleTimeout);
00171
00172 H323EndPoint & endpoint;
00173 H323Connection & connection;
00174 PTimer replyTimer;
00175 PMutex mutex;
00176 };
00177
00178
00181 class H245NegMasterSlaveDetermination : public H245Negotiator
00182 {
00183 PCLASSINFO(H245NegMasterSlaveDetermination, H245Negotiator);
00184
00185 public:
00186 H245NegMasterSlaveDetermination(H323EndPoint & endpoint, H323Connection & connection);
00187
00188 BOOL Start(BOOL renegotiate);
00189 void Stop();
00190 BOOL HandleIncoming(const H245_MasterSlaveDetermination & pdu);
00191 BOOL HandleAck(const H245_MasterSlaveDeterminationAck & pdu);
00192 BOOL HandleReject(const H245_MasterSlaveDeterminationReject & pdu);
00193 BOOL HandleRelease(const H245_MasterSlaveDeterminationRelease & pdu);
00194 void HandleTimeout(PTimer &, INT);
00195
00196 BOOL IsMaster() const { return status == e_DeterminedMaster; }
00197 BOOL IsDetermined() const { return state == e_Idle && status != e_Indeterminate; }
00198
00199 protected:
00200 BOOL Restart();
00201
00202 enum States {
00203 e_Idle, e_Outgoing, e_Incoming,
00204 e_NumStates
00205 } state;
00206 #if PTRACING
00207 static const char * const StateNames[e_NumStates];
00208 friend ostream & operator<<(ostream & o, States s) { return o << StateNames[s]; }
00209 #endif
00210
00211 DWORD determinationNumber;
00212 unsigned retryCount;
00213
00214 enum MasterSlaveStatus {
00215 e_Indeterminate, e_DeterminedMaster, e_DeterminedSlave,
00216 e_NumStatuses
00217 } status;
00218 #if PTRACING
00219 static const char * const StatusNames[e_NumStatuses];
00220 friend ostream & operator<<(ostream & o , MasterSlaveStatus s) { return o << StatusNames[s]; }
00221 #endif
00222 };
00223
00224
00227 class H245NegTerminalCapabilitySet : public H245Negotiator
00228 {
00229 PCLASSINFO(H245NegTerminalCapabilitySet, H245Negotiator);
00230
00231 public:
00232 H245NegTerminalCapabilitySet(H323EndPoint & endpoint, H323Connection & connection);
00233
00234 BOOL Start(BOOL renegotiate, BOOL empty = FALSE);
00235 void Stop();
00236 BOOL HandleIncoming(const H245_TerminalCapabilitySet & pdu);
00237 BOOL HandleAck(const H245_TerminalCapabilitySetAck & pdu);
00238 BOOL HandleReject(const H245_TerminalCapabilitySetReject & pdu);
00239 BOOL HandleRelease(const H245_TerminalCapabilitySetRelease & pdu);
00240 void HandleTimeout(PTimer &, INT);
00241
00242 BOOL HasSentCapabilities() const { return state == e_Sent; }
00243 BOOL HasReceivedCapabilities() const { return receivedCapabilites; }
00244
00245 protected:
00246 enum States {
00247 e_Idle, e_InProgress, e_Sent,
00248 e_NumStates
00249 } state;
00250 #if PTRACING
00251 static const char * const StateNames[e_NumStates];
00252 friend ostream & operator<<(ostream & o, States s) { return o << StateNames[s]; }
00253 #endif
00254
00255 unsigned inSequenceNumber;
00256 unsigned outSequenceNumber;
00257
00258 BOOL receivedCapabilites;
00259 };
00260
00261
00264 class H245NegLogicalChannel : public H245Negotiator
00265 {
00266 PCLASSINFO(H245NegLogicalChannel, H245Negotiator);
00267
00268 public:
00269 H245NegLogicalChannel(H323EndPoint & endpoint,
00270 H323Connection & connection,
00271 const H323ChannelNumber & channelNumber);
00272 H245NegLogicalChannel(H323EndPoint & endpoint,
00273 H323Connection & connection,
00274 H323Channel & channel);
00275 ~H245NegLogicalChannel();
00276
00277 virtual BOOL Open(
00278 const H323Capability & capability,
00279 unsigned sessionID,
00280 unsigned replacementFor = 0,
00281 unsigned roleLabel = 0
00282 );
00283 virtual BOOL Close();
00284 virtual BOOL HandleOpen(const H245_OpenLogicalChannel & pdu);
00285 virtual BOOL HandleOpenAck(const H245_OpenLogicalChannelAck & pdu);
00286 virtual BOOL HandleOpenConfirm(const H245_OpenLogicalChannelConfirm & pdu);
00287 virtual BOOL HandleReject(const H245_OpenLogicalChannelReject & pdu);
00288 virtual BOOL HandleClose(const H245_CloseLogicalChannel & pdu);
00289 virtual BOOL HandleCloseAck(const H245_CloseLogicalChannelAck & pdu);
00290 virtual BOOL HandleRequestClose(const H245_RequestChannelClose & pdu);
00291 virtual BOOL HandleRequestCloseAck(const H245_RequestChannelCloseAck & pdu);
00292 virtual BOOL HandleRequestCloseReject(const H245_RequestChannelCloseReject & pdu);
00293 virtual BOOL HandleRequestCloseRelease(const H245_RequestChannelCloseRelease & pdu);
00294 virtual void HandleTimeout(PTimer &, INT);
00295
00296 H323Channel * GetChannel();
00297
00298
00299 protected:
00300 virtual BOOL OpenWhileLocked(
00301 const H323Capability & capability,
00302 unsigned sessionID,
00303 unsigned replacementFor = 0,
00304 unsigned roleLabel = 0
00305 );
00306 virtual BOOL CloseWhileLocked();
00307 virtual void Release();
00308
00309
00310 H323Channel * channel;
00311
00312 H323ChannelNumber channelNumber;
00313
00314 enum States {
00315 e_Released,
00316 e_AwaitingEstablishment,
00317 e_Established,
00318 e_AwaitingRelease,
00319 e_AwaitingConfirmation,
00320 e_AwaitingResponse,
00321 e_NumStates
00322 } state;
00323 #if PTRACING
00324 static const char * const StateNames[e_NumStates];
00325 friend ostream & operator<<(ostream & o, States s) { return o << StateNames[s]; }
00326 #endif
00327
00328
00329 friend class H245NegLogicalChannels;
00330 };
00331
00332
00333 PDICTIONARY(H245LogicalChannelDict, H323ChannelNumber, H245NegLogicalChannel);
00334
00337 class H245NegLogicalChannels : public H245Negotiator
00338 {
00339 PCLASSINFO(H245NegLogicalChannels, H245Negotiator);
00340
00341 public:
00342 H245NegLogicalChannels(H323EndPoint & endpoint, H323Connection & connection);
00343
00344 virtual void Add(H323Channel & channel);
00345
00346 virtual BOOL Open(
00347 const H323Capability & capability,
00348 unsigned sessionID,
00349 unsigned replacementFor = 0
00350 );
00351
00352 virtual BOOL Open(
00353 const H323Capability & capability,
00354 unsigned sessionID,
00355 H323ChannelNumber & channelnumber,
00356 unsigned replacementFor = 0,
00357 unsigned roleLabel = 0
00358 );
00359
00360 virtual BOOL Close(unsigned channelNumber, BOOL fromRemote);
00361 virtual BOOL HandleOpen(const H245_OpenLogicalChannel & pdu);
00362 virtual BOOL HandleOpenAck(const H245_OpenLogicalChannelAck & pdu);
00363 virtual BOOL HandleOpenConfirm(const H245_OpenLogicalChannelConfirm & pdu);
00364 virtual BOOL HandleReject(const H245_OpenLogicalChannelReject & pdu);
00365 virtual BOOL HandleClose(const H245_CloseLogicalChannel & pdu);
00366 virtual BOOL HandleCloseAck(const H245_CloseLogicalChannelAck & pdu);
00367 virtual BOOL HandleRequestClose(const H245_RequestChannelClose & pdu);
00368 virtual BOOL HandleRequestCloseAck(const H245_RequestChannelCloseAck & pdu);
00369 virtual BOOL HandleRequestCloseReject(const H245_RequestChannelCloseReject & pdu);
00370 virtual BOOL HandleRequestCloseRelease(const H245_RequestChannelCloseRelease & pdu);
00371
00372 H323ChannelNumber GetNextChannelNumber();
00373 PINDEX GetSize() const { return channels.GetSize(); }
00374 H323Channel * GetChannelAt(PINDEX i);
00375 H323Channel * FindChannel(unsigned channelNumber, BOOL fromRemote);
00376 H245NegLogicalChannel & GetNegLogicalChannelAt(PINDEX i);
00377 H245NegLogicalChannel * FindNegLogicalChannel(unsigned channelNumber, BOOL fromRemote);
00378 H323Channel * FindChannelBySession(unsigned rtpSessionId, BOOL fromRemote);
00379 void RemoveAll();
00380
00381 protected:
00382 H323ChannelNumber lastChannelNumber;
00383 H245LogicalChannelDict channels;
00384 };
00385
00386
00389 class H245NegRequestMode : public H245Negotiator
00390 {
00391 PCLASSINFO(H245NegRequestMode, H245Negotiator);
00392
00393 public:
00394 H245NegRequestMode(H323EndPoint & endpoint, H323Connection & connection);
00395
00396 virtual BOOL StartRequest(const PString & newModes);
00397 virtual BOOL StartRequest(const H245_ArrayOf_ModeDescription & newModes);
00398 virtual BOOL HandleRequest(const H245_RequestMode & pdu);
00399 virtual BOOL HandleAck(const H245_RequestModeAck & pdu);
00400 virtual BOOL HandleReject(const H245_RequestModeReject & pdu);
00401 virtual BOOL HandleRelease(const H245_RequestModeRelease & pdu);
00402 virtual void HandleTimeout(PTimer &, INT);
00403
00404 protected:
00405 BOOL awaitingResponse;
00406 unsigned inSequenceNumber;
00407 unsigned outSequenceNumber;
00408 };
00409
00410
00413 class H245NegRoundTripDelay : public H245Negotiator
00414 {
00415 PCLASSINFO(H245NegRoundTripDelay, H245Negotiator);
00416
00417 public:
00418 H245NegRoundTripDelay(H323EndPoint & endpoint, H323Connection & connection);
00419
00420 BOOL StartRequest();
00421 BOOL HandleRequest(const H245_RoundTripDelayRequest & pdu);
00422 BOOL HandleResponse(const H245_RoundTripDelayResponse & pdu);
00423 void HandleTimeout(PTimer &, INT);
00424
00425 PTimeInterval GetRoundTripDelay() const { return roundTripTime; }
00426 BOOL IsRemoteOffline() const { return retryCount == 0; }
00427
00428 protected:
00429 BOOL awaitingResponse;
00430 unsigned sequenceNumber;
00431 PTimeInterval tripStartTime;
00432 PTimeInterval roundTripTime;
00433 unsigned retryCount;
00434 };
00435
00436
00437 #endif // __OPAL_H323NEG_H
00438
00439