00001 /* 00002 * 00003 * 00004 * Inter Asterisk Exchange 2 00005 * 00006 * A class to describe the node we are talking to. 00007 * 00008 * Open Phone Abstraction Library (OPAL) 00009 * 00010 * Copyright (c) 2005 Indranet Technologies Ltd. 00011 * 00012 * The contents of this file are subject to the Mozilla Public License 00013 * Version 1.0 (the "License"); you may not use this file except in 00014 * compliance with the License. You may obtain a copy of the License at 00015 * http://www.mozilla.org/MPL/ 00016 * 00017 * Software distributed under the License is distributed on an "AS IS" 00018 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 00019 * the License for the specific language governing rights and limitations 00020 * under the License. 00021 * 00022 * The Original Code is Open Phone Abstraction Library. 00023 * 00024 * The Initial Developer of the Original Code is Indranet Technologies Ltd. 00025 * 00026 * The author of this code is Derek J Smithies 00027 * 00028 * $Log: remote.h,v $ 00029 * Revision 1.8 2007/04/19 06:17:21 csoutheren 00030 * Fixes for precompiled headers with gcc 00031 * 00032 * Revision 1.7 2007/01/23 02:08:25 dereksmithies 00033 * Handle Vnak frames correctly. handle iseqno and oseqno correctly. 00034 * 00035 * Revision 1.6 2006/08/09 03:46:40 dereksmithies 00036 * Add ability to register to a remote Asterisk box. The iaxProcessor class is split 00037 * into a callProcessor and a regProcessor class. 00038 * Big thanks to Stephen Cook, (sitiveni@gmail.com) for this work. 00039 * 00040 * Revision 1.5 2005/08/28 23:51:29 dereksmithies 00041 * Improve test for massaging timestamps in fullframes. Thanks to Adrian Sietsma 00042 * 00043 * Revision 1.4 2005/08/26 03:07:38 dereksmithies 00044 * Change naming convention, so all class names contain the string "IAX2" 00045 * 00046 * Revision 1.3 2005/08/24 13:06:18 rjongbloed 00047 * Added configuration define for AEC encryption 00048 * 00049 * Revision 1.2 2005/08/24 01:38:38 dereksmithies 00050 * Add encryption, iax2 style. Numerous tidy ups. Use the label iax2, not iax 00051 * 00052 * Revision 1.1 2005/07/30 07:01:32 csoutheren 00053 * Added implementation of IAX2 (Inter Asterisk Exchange 2) protocol 00054 * Thanks to Derek Smithies of Indranet Technologies Ltd. for 00055 * writing and contributing this code 00056 * 00057 * 00058 * 00059 * 00060 */ 00061 00062 #ifndef REMOTE_H 00063 #define REMOTE_H 00064 00065 #ifndef _PTLIB_H 00066 #include <ptlib.h> 00067 #endif 00068 00069 #include <opal/buildopts.h> 00070 00071 #include <ptlib/sockets.h> 00072 00073 #if OPAL_PTLIB_SSL_AES 00074 #include <openssl/aes.h> 00075 #endif 00076 00077 #ifdef P_USE_PRAGMA 00078 #pragma interface 00079 #endif 00080 00081 class IAX2FullFrame; 00082 00083 00086 class IAX2Remote : public PObject 00087 { 00088 PCLASSINFO(IAX2Remote, PObject); 00089 00090 public: 00091 00093 IAX2Remote(); 00094 00095 virtual ~IAX2Remote() { }; 00096 00099 PINDEX DestCallNumber() { return destCallNumber; } 00100 00104 PINDEX SourceCallNumber() { return sourceCallNumber; } 00105 00107 virtual void PrintOn(ostream & strm) const; 00108 00110 enum { 00111 callNumberUndefined = 0xffff 00112 }; 00113 00115 PIPSocket::Address RemoteAddress() { return remoteAddress; } 00116 00120 PString BuildConnectionTokenId(); 00121 00123 PString BuildOurConnectionTokenId(); 00124 00126 PINDEX RemotePort() { return remotePort; } 00127 00129 void Assign(IAX2Remote &); 00130 00132 void SetRemoteAddress(PIPSocket::Address &newVal) { remoteAddress = newVal; } 00133 00135 void SetRemoteAddress(int newVal) { remoteAddress = newVal; } 00136 00138 void SetRemotePort (PINDEX newVal) { remotePort = newVal; } 00139 00141 void SetSourceCallNumber(PINDEX newVal) { sourceCallNumber = newVal; } 00142 00144 void SetDestCallNumber(PINDEX newVal) { destCallNumber = newVal; } 00145 00149 PBoolean operator == (IAX2Remote & other); 00150 00153 PBoolean operator *= (IAX2Remote & other); 00154 00155 00157 PBoolean operator != (IAX2Remote & other); 00158 00159 00160 protected: 00162 PINDEX sourceCallNumber; 00163 00165 PINDEX destCallNumber; 00166 00168 PIPSocket::Address remoteAddress; 00169 00171 PINDEX remotePort; 00172 00173 }; 00174 00176 00185 class IAX2FrameIdValue : public PObject 00186 { 00187 PCLASSINFO(IAX2FrameIdValue, PObject); 00188 public: 00190 IAX2FrameIdValue (PINDEX timeStamp, PINDEX seqVal); 00191 00193 IAX2FrameIdValue (PINDEX val); 00194 00196 PINDEX GetTimeStamp() const; 00197 00199 PINDEX GetSequenceVal() const; 00200 00204 PINDEX GetPlainSequence() const; 00205 00207 virtual void PrintOn(ostream & strm) const; 00208 00211 virtual Comparison Compare(const PObject & obj) const; 00212 00213 protected: 00214 00217 PUInt64 value; 00218 }; 00219 00221 00226 PDECLARE_SORTED_LIST(IAX2PacketIdList, IAX2FrameIdValue) 00227 #ifdef DOC_PLUS_PLUS 00228 class IAX2PacketIdList : public PSortedList 00229 { 00230 #endif 00231 00234 PBoolean Contains(IAX2FrameIdValue &src); 00235 00238 PINDEX GetFirstValue(); 00239 00241 void AppendNewFrame(IAX2FullFrame &src); 00242 00244 virtual void PrintOn(ostream & strm) const; 00245 00246 protected: 00252 void RemoveOldContiguousValues(); 00253 }; 00254 00256 00257 class IAX2SequenceNumbers 00258 { 00259 public: 00263 enum IncomingOrder { 00264 InSequence, 00265 SkippedFrame, 00266 RepeatedFrame 00267 }; 00268 00269 00270 00272 IAX2SequenceNumbers() 00273 { ZeroAllValues(); }; 00274 00276 virtual ~IAX2SequenceNumbers() { } 00277 00279 void ZeroAllValues(); 00280 00282 PINDEX InSeqNo(); 00283 00285 PINDEX OutSeqNo(); 00286 00289 PBoolean IsSequenceNosZero(); 00290 00292 void SetInSeqNo(PINDEX newVal); 00293 00295 void SetOutSeqNo(PINDEX newVal); 00296 00299 void SetInOutSeqNo(PINDEX inVal, PINDEX outVal); 00300 00303 void SetAckSequenceInfo(IAX2SequenceNumbers & other); 00304 00306 PBoolean operator !=(IAX2SequenceNumbers &other); 00307 00309 PBoolean operator ==(IAX2SequenceNumbers &other); 00310 00312 void MassageSequenceForSending(IAX2FullFrame &src /*<!src will be transmitted to the remote node */ 00313 ); 00314 00318 void WrapAroundFrameSequence(IAX2SequenceNumbers & src); 00319 00323 IncomingOrder IncomingMessageInOrder 00324 (IAX2FullFrame &src /*<!frame to be compared with current data base.*/ ); 00325 00327 void CopyContents(IAX2SequenceNumbers &src); 00328 00330 PString AsString() const; 00331 00333 virtual void PrintOn(ostream & strm) const; 00334 00337 PBoolean IsFirstReply() { return (inSeqNo == 1) && (outSeqNo == 0); } 00338 00340 void AddWrapAroundValue(PINDEX newOffset); 00341 00342 00343 protected: 00344 00346 enum sequenceDefines { 00347 minSpacing = 3 00348 }; 00349 00351 PINDEX inSeqNo; 00352 00354 PINDEX outSeqNo; 00355 00357 PMutex mutex; 00358 00360 PINDEX lastSentTimeStamp; 00361 00363 IAX2PacketIdList receivedLog; 00364 }; 00365 00367 00368 class IAX2Encryption : public PObject 00369 { 00370 PCLASSINFO(IAX2Encryption, PObject); 00371 public: 00373 IAX2Encryption(); 00374 00376 void SetEncryptionOn (PBoolean newState = PTrue); 00377 00379 void SetEncryptionKey(PString & newKey); 00380 00382 void SetChallengeKey(PString & newKey); 00383 00385 const PString & EncryptionKey() const; 00386 00388 const PString & ChallengeKey() const; 00389 00391 PBoolean IsEncrypted() const; 00392 00393 #if OPAL_PTLIB_SSL_AES 00394 00395 AES_KEY *AesEncryptKey(); 00396 00398 AES_KEY *AesDecryptKey(); 00399 #endif 00400 00401 protected: 00404 void CalculateAesKeys(); 00405 00407 PString encryptionKey; 00408 00410 PString challengeKey; 00411 00413 PBoolean encryptionEnabled; 00414 00415 #if OPAL_PTLIB_SSL_AES 00416 00417 AES_KEY aesEncryptKey; 00418 00420 AES_KEY aesDecryptKey; 00421 #endif 00422 }; 00423 00425 00426 #endif 00427 00428 /* The comment below is magic for those who use emacs to edit this file. */ 00429 /* With the comment below, the tab key does auto indent to 4 spaces. */ 00430 00431 /* 00432 * Local Variables: 00433 * mode:c 00434 * c-basic-offset:2 00435 * End: 00436 */ 00437