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.5 2005/08/28 23:51:29 dereksmithies 00030 * Improve test for massaging timestamps in fullframes. Thanks to Adrian Sietsma 00031 * 00032 * Revision 1.4 2005/08/26 03:07:38 dereksmithies 00033 * Change naming convention, so all class names contain the string "IAX2" 00034 * 00035 * Revision 1.3 2005/08/24 13:06:18 rjongbloed 00036 * Added configuration define for AEC encryption 00037 * 00038 * Revision 1.2 2005/08/24 01:38:38 dereksmithies 00039 * Add encryption, iax2 style. Numerous tidy ups. Use the label iax2, not iax 00040 * 00041 * Revision 1.1 2005/07/30 07:01:32 csoutheren 00042 * Added implementation of IAX2 (Inter Asterisk Exchange 2) protocol 00043 * Thanks to Derek Smithies of Indranet Technologies Ltd. for 00044 * writing and contributing this code 00045 * 00046 * 00047 * 00048 * 00049 */ 00050 00051 #ifndef REMOTE_H 00052 #define REMOTE_H 00053 00054 #include <ptlib.h> 00055 #include <ptlib/sockets.h> 00056 00057 #if P_SSL_AES 00058 #include <openssl/aes.h> 00059 #endif 00060 00061 #ifdef P_USE_PRAGMA 00062 #pragma interface 00063 #endif 00064 00065 class IAX2FullFrame; 00066 00067 00070 class IAX2Remote : public PObject 00071 { 00072 PCLASSINFO(IAX2Remote, PObject); 00073 00074 public: 00075 00077 IAX2Remote(); 00078 00079 virtual ~IAX2Remote() { }; 00080 00083 PINDEX DestCallNumber() { return destCallNumber; } 00084 00088 PINDEX SourceCallNumber() { return sourceCallNumber; } 00089 00091 virtual void PrintOn(ostream & strm) const; 00092 00094 enum { 00095 callNumberUndefined = 0xffff 00096 }; 00097 00099 PIPSocket::Address RemoteAddress() { return remoteAddress; } 00100 00102 PINDEX RemotePort() { return remotePort; } 00103 00105 void Assign(IAX2Remote &); 00106 00108 void SetRemoteAddress(PIPSocket::Address &newVal) { remoteAddress = newVal; } 00109 00111 void SetRemoteAddress(int newVal) { remoteAddress = newVal; } 00112 00114 void SetRemotePort (PINDEX newVal) { remotePort = newVal; } 00115 00117 void SetSourceCallNumber(PINDEX newVal) { sourceCallNumber = newVal; } 00118 00120 void SetDestCallNumber(PINDEX newVal) { destCallNumber = newVal; } 00121 00125 BOOL operator == (IAX2Remote & other); 00126 00129 BOOL operator *= (IAX2Remote & other); 00130 00131 00133 BOOL operator != (IAX2Remote & other); 00134 00135 00136 protected: 00138 PINDEX sourceCallNumber; 00139 00141 PINDEX destCallNumber; 00142 00144 PIPSocket::Address remoteAddress; 00145 00147 PINDEX remotePort; 00148 00149 }; 00150 00152 00161 class IAX2FrameIdValue : public PObject 00162 { 00163 PCLASSINFO(IAX2FrameIdValue, PObject); 00164 public: 00166 IAX2FrameIdValue (PINDEX timeStamp, PINDEX seqVal); 00167 00169 IAX2FrameIdValue (PINDEX val); 00170 00172 PINDEX GetTimeStamp() const; 00173 00175 PINDEX GetSequenceVal() const; 00176 00180 PINDEX GetPlainSequence() const; 00181 00183 virtual void PrintOn(ostream & strm) const; 00184 00187 virtual Comparison Compare(const PObject & obj) const; 00188 00189 protected: 00190 00193 PUInt64 value; 00194 }; 00195 00197 00202 PDECLARE_SORTED_LIST(IAX2PacketIdList, IAX2FrameIdValue) 00203 #ifdef DOC_PLUS_PLUS 00204 class IAX2PacketIdList : public PSortedList 00205 { 00206 #endif 00207 00210 BOOL Contains(IAX2FrameIdValue &src); 00211 00214 PINDEX GetFirstValue(); 00215 00217 void AppendNewFrame(IAX2FullFrame &src); 00218 00220 virtual void PrintOn(ostream & strm) const; 00221 00222 protected: 00228 void RemoveOldContiguousValues(); 00229 }; 00230 00232 00233 class IAX2SequenceNumbers 00234 { 00235 public: 00237 IAX2SequenceNumbers() 00238 { ZeroAllValues(); }; 00239 00241 virtual ~IAX2SequenceNumbers() { } 00242 00244 void ZeroAllValues(); 00245 00247 PINDEX InSeqNo(); 00248 00250 PINDEX OutSeqNo(); 00251 00254 BOOL IsSequenceNosZero(); 00255 00257 void SetInSeqNo(PINDEX newVal); 00258 00260 void SetOutSeqNo(PINDEX newVal); 00261 00264 void SetInOutSeqNo(PINDEX inVal, PINDEX outVal); 00265 00268 void SetAckSequenceInfo(IAX2SequenceNumbers & other); 00269 00271 BOOL operator !=(IAX2SequenceNumbers &other); 00272 00274 BOOL operator ==(IAX2SequenceNumbers &other); 00275 00277 void MassageSequenceForSending(IAX2FullFrame &src /*<!src will be transmitted to the remote node */ 00278 ); 00279 00283 void WrapAroundFrameSequence(IAX2SequenceNumbers & src); 00284 00287 BOOL IncomingMessageIsOk(IAX2FullFrame &src /*<!frame to be compared with current data base.*/ ); 00288 00290 void CopyContents(IAX2SequenceNumbers &src); 00291 00293 PString AsString() const; 00294 00296 virtual void PrintOn(ostream & strm) const; 00297 00300 BOOL IsFirstReply() { return (inSeqNo == 1) && (outSeqNo == 0); } 00301 00303 void AddWrapAroundValue(PINDEX newOffset); 00304 00305 protected: 00306 00308 enum sequenceDefines { 00309 minSpacing = 3 00310 }; 00311 00313 PINDEX inSeqNo; 00314 00316 PINDEX outSeqNo; 00317 00319 PMutex mutex; 00320 00322 PINDEX lastSentTimeStamp; 00323 00325 IAX2PacketIdList receivedLog; 00326 }; 00327 00329 00330 class IAX2Encryption : public PObject 00331 { 00332 PCLASSINFO(IAX2Encryption, PObject); 00333 public: 00335 IAX2Encryption(); 00336 00338 void SetEncryptionOn (BOOL newState = TRUE); 00339 00341 void SetEncryptionKey(PString & newKey); 00342 00344 void SetChallengeKey(PString & newKey); 00345 00347 const PString & EncryptionKey() const; 00348 00350 const PString & ChallengeKey() const; 00351 00353 const BOOL IsEncrypted() const; 00354 00355 #if P_SSL_AES 00356 00357 AES_KEY *AesEncryptKey(); 00358 00360 AES_KEY *AesDecryptKey(); 00361 #endif 00362 00363 protected: 00366 void CalculateAesKeys(); 00367 00369 PString encryptionKey; 00370 00372 PString challengeKey; 00373 00375 BOOL encryptionEnabled; 00376 00377 #if P_SSL_AES 00378 00379 AES_KEY aesEncryptKey; 00380 00382 AES_KEY aesDecryptKey; 00383 #endif 00384 }; 00385 00387 00388 #endif 00389 00390 /* The comment below is magic for those who use emacs to edit this file. */ 00391 /* With the comment below, the tab key does auto indent to 4 spaces. */ 00392 00393 /* 00394 * Local Variables: 00395 * mode:c 00396 * c-file-style:linux 00397 * c-basic-offset:2 00398 * End: 00399 */ 00400