📄 h323pdu.cxx
字号:
/* * h323pdu.cxx * * H.323 PDU definitions * * Open H323 Library * * Copyright (c) 1998-2000 Equivalence Pty. Ltd. * * The contents of this file are subject to the Mozilla Public License * Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See * the License for the specific language governing rights and limitations * under the License. * * The Original Code is Open H323 Library. * * The Initial Developer of the Original Code is Equivalence Pty. Ltd. * * Portions of this code were written with the assisance of funding from * Vovida Networks, Inc. http://www.vovida.com. * * Contributor(s): ______________________________________. * * $Log: h323pdu.cxx,v $ * Revision 1.61 2000/07/15 09:51:41 robertj * Changed adding of Q.931 party numbers to only occur in SETUP. * * Revision 1.60 2000/07/13 12:29:49 robertj * Added some more cause codes on release complete, * * Revision 1.59 2000/07/12 10:20:43 robertj * Fixed incorrect tag code in H.245 ModeChange reject PDU. * * Revision 1.58 2000/07/09 15:21:11 robertj * Changed reference to the word "field" to be more correct IE or "Information Element" * Fixed return value of Q.931/H.225 PDU read so returns TRUE if no H.225 data in the * User-User IE. Just flag it as empty and continue processing PDU's. * * Revision 1.57 2000/06/21 23:59:44 robertj * Fixed copy/paste error setting Q.931 display name to incorrect value. * * Revision 1.56 2000/06/21 08:07:47 robertj * Added cause/reason to release complete PDU, where relevent. * * Revision 1.55 2000/06/07 05:48:06 robertj * Added call forwarding. * * Revision 1.54 2000/05/25 01:59:05 robertj * Fixed bugs in calculation of GlLobally Uniqie ID according to DCE/H.225 rules. * * Revision 1.53 2000/05/23 11:32:37 robertj * Rewrite of capability table to combine 2 structures into one and move functionality into that class * allowing some normalisation of usage across several applications. * Changed H323Connection so gets a copy of capabilities instead of using endponts, allows adjustments * to be done depending on the remote client application. * * Revision 1.52 2000/05/15 08:38:59 robertj * Removed addition of calling/called party number field in Q.931 if there isn't one. * * Revision 1.51 2000/05/09 12:19:31 robertj * Added ability to get and set "distinctive ring" Q.931 functionality. * * Revision 1.50 2000/05/08 14:07:35 robertj * Improved the provision and detection of calling and caller numbers, aliases and hostnames. * * Revision 1.49 2000/05/08 05:06:27 robertj * Fixed bug in H.245 close logical channel timeout, thanks XuPeili. * * Revision 1.48 2000/05/02 04:32:27 robertj * Fixed copyright notice comment. * * Revision 1.47 2000/04/14 17:29:43 robertj * Fixed display of error message on timeout when timeouts are not errors. * * Revision 1.46 2000/04/10 20:39:18 robertj * Added support for more sophisticated DTMF and hook flash user indication. * Added function to extract E164 address from Q.931/H.225 PDU. * * Revision 1.45 2000/03/29 04:42:19 robertj * Improved some trace logging messages. * * Revision 1.44 2000/03/25 02:01:07 robertj * Added adjustable caller name on connection by connection basis. * * Revision 1.43 2000/03/21 01:08:10 robertj * Fixed incorrect call reference code being used in originated call. * * Revision 1.42 2000/02/17 12:07:43 robertj * Used ne wPWLib random number generator after finding major problem in MSVC rand(). * * Revision 1.41 1999/12/23 22:47:09 robertj * Added calling party number field. * * Revision 1.40 1999/12/11 02:21:00 robertj * Added ability to have multiple aliases on local endpoint. * * Revision 1.39 1999/11/16 13:21:38 robertj * Removed extraneous error trace when doing asynchronous answer call. * * Revision 1.38 1999/11/15 14:11:29 robertj * Fixed trace output stream being put back after setting hex/fillchar modes. * * Revision 1.37 1999/11/10 23:30:20 robertj * Fixed unexpected closing of transport on PDU read error. * * Revision 1.36 1999/11/01 00:48:31 robertj * Added assert for illegal condition in capabilities, must have set if have table. * * Revision 1.35 1999/10/30 23:48:21 robertj * Fixed incorrect PDU type for H225 RAS location request. * * Revision 1.34 1999/10/29 03:35:06 robertj * Fixed setting of unique ID using fake MAC address from Win32 PPP device. * * Revision 1.33 1999/09/21 14:09:49 robertj * Removed warnings when no tracing enabled. * * Revision 1.32 1999/09/10 09:03:01 robertj * Used new GetInterfaceTable() function to get ethernet address for UniqueID * * Revision 1.31 1999/09/10 03:36:48 robertj * Added simple Q.931 Status response to Q.931 Status Enquiry * * Revision 1.30 1999/08/31 12:34:19 robertj * Added gatekeeper support. * * Revision 1.29 1999/08/31 11:37:30 robertj * Fixed problem with apparently randomly losing signalling channel. * * Revision 1.28 1999/08/25 05:08:14 robertj * File fission (critical mass reached). * * Revision 1.27 1999/08/13 06:34:38 robertj * Fixed problem in CallPartyNumber Q.931 encoding. * Added field name display to Q.931 protocol. * * Revision 1.26 1999/08/10 13:14:15 robertj * Added Q.931 Called Number field if have "phone number" style destination addres. * * Revision 1.25 1999/08/10 11:38:03 robertj * Changed population of setup UUIE destinationAddress if can be IA5 string. * * Revision 1.24 1999/07/26 05:10:30 robertj * Fixed yet another race condition on connection termination. * * Revision 1.23 1999/07/16 14:03:52 robertj * Fixed bug in Master/Slave negotiation that can cause looping. * * Revision 1.22 1999/07/16 06:15:59 robertj * Corrected semantics for tunnelled master/slave determination in fast start. * * Revision 1.21 1999/07/16 02:15:30 robertj * Fixed more tunneling problems. * * Revision 1.20 1999/07/15 14:45:36 robertj * Added propagation of codec open error to shut down logical channel. * Fixed control channel start up bug introduced with tunnelling. * * Revision 1.19 1999/07/15 09:08:04 robertj * Added extra debugging for if have PDU decoding error. * * Revision 1.18 1999/07/15 09:04:31 robertj * Fixed some fast start bugs * * Revision 1.17 1999/07/10 02:51:36 robertj * Added mutexing in H245 procedures. Also fixed MSD state bug. * * Revision 1.16 1999/07/09 06:09:50 robertj * Major implementation. An ENORMOUS amount of stuff added everywhere. * * Revision 1.15 1999/06/25 10:25:35 robertj * Added maintentance of callIdentifier variable in H.225 channel. * * Revision 1.14 1999/06/22 13:45:40 robertj * Fixed conferenceIdentifier generation algorithm to bas as in spec. * * Revision 1.13 1999/06/19 15:18:38 robertj * Fixed bug in MasterSlaveDeterminationAck pdu has incorrect master/slave state. * * Revision 1.12 1999/06/14 15:08:40 robertj * Added GSM codec class frame work (still no actual codec). * * Revision 1.11 1999/06/14 06:39:08 robertj * Fixed problem with getting transmit flag to channel from PDU negotiator * * Revision 1.10 1999/06/14 05:15:56 robertj * Changes for using RTP sessions correctly in H323 Logical Channel context * * Revision 1.9 1999/06/13 12:41:14 robertj * Implement logical channel transmitter. * Fixed H245 connect on receiving call. * * Revision 1.8 1999/06/09 05:26:19 robertj * Major restructuring of classes. * * Revision 1.7 1999/06/06 06:06:36 robertj * Changes for new ASN compiler and v2 protocol ASN files. * * Revision 1.6 1999/04/26 06:20:22 robertj * Fixed bugs in protocol * * Revision 1.5 1999/04/26 06:14:47 craigs * Initial implementation for RTP decoding and lots of stuff * As a whole, these changes are called "First Noise" * * Revision 1.4 1999/02/23 11:04:28 robertj * Added capability to make outgoing call. * * Revision 1.3 1999/02/06 09:23:39 robertj * BeOS port * * Revision 1.2 1999/01/16 02:34:57 robertj * GNU compiler compatibility. * * Revision 1.1 1999/01/16 01:30:54 robertj * Initial revision * */#include <ptlib.h>#include <ptclib/random.h>#include "h323pdu.h"#define new PNEWconst char H225_ProtocolID[] = "0.0.8.2250.0.2";const char H245_ProtocolID[] = "0.0.8.245.0.3";///////////////////////////////////////////////////////////////////////////////void H323SetAliasAddresses(const PStringList & names, H225_ArrayOf_AliasAddress & aliases){ aliases.SetSize(names.GetSize()); for (PINDEX i = 0; i < names.GetSize(); i++) H323SetAliasAddress(names[i], aliases[i]);}void H323SetAliasAddress(const PString & name, H225_AliasAddress & alias){ alias.SetTag(H225_AliasAddress::e_e164); PASN_IA5String & ia5 = (PASN_IA5String &)alias; ia5 = name; if (name == (PString)ia5) return; // Could not encode it as a phone number, so do it as a full string. alias.SetTag(H225_AliasAddress::e_h323_ID); (PASN_BMPString &)alias = name;}static BOOL IsE164(const PString & str){ return strspn(str, "1234567890*#") == strlen(str);}///////////////////////////////////////////////////////////////////////////////H323GloballyUniqueID::H323GloballyUniqueID(){ SetSize(16); //Time of UTC in 0.1 microseconds since 15 Oct 1582. static const PInt64 DaysToJan1970 = (365*(1970-1583) // Days in years + (1970-1583)/4 // Leap days - 3 // Allow for 1700, 1800, 1900 not leap years + 31 // Days in December 1583 + 30 // Days in November 1583 + 16); // Days from 15th October PInt64 timestamp = (time(NULL) + DaysToJan1970*60*60*24)*10000000; theArray[0] = (BYTE)(timestamp&0xff); theArray[1] = (BYTE)((timestamp>>8)&0xff); theArray[2] = (BYTE)((timestamp>>16)&0xff); theArray[3] = (BYTE)((timestamp>>24)&0xff); theArray[4] = (BYTE)((timestamp>>32)&0xff); theArray[5] = (BYTE)((timestamp>>40)&0xff); theArray[6] = (BYTE)((timestamp>>48)&0xff); theArray[7] = (BYTE)(((timestamp>>56)&0x0f) + 0x10); // Version number is 1 static WORD clockSequence = (WORD)PRandom::Number(); static PInt64 lastTimestamp = 0; if (lastTimestamp < timestamp) lastTimestamp = timestamp; else clockSequence++; theArray[8] = (BYTE)(((clockSequence>>8)&0x3f) | 0x80); // DCE compatible GUID theArray[9] = (BYTE)clockSequence; PIPSocket::InterfaceTable interfaces; if (PIPSocket::GetInterfaceTable(interfaces)) { for (PINDEX i = 0; i < interfaces.GetSize(); i++) { PString macAddrStr = interfaces[i].GetMACAddress(); if (!macAddrStr && macAddrStr != "44-45-53-54-00-00") { /* not Win32 PPP device */ PEthSocket::Address macAddress = macAddrStr; if (macAddress != PEthSocket::Address("")) { memcpy(theArray+10, macAddress.b, 6); return; } } } } PRandom rand; theArray[10] = (BYTE)(rand|0x80); theArray[11] = (BYTE)rand; theArray[12] = (BYTE)rand; theArray[13] = (BYTE)rand; theArray[14] = (BYTE)rand; theArray[15] = (BYTE)rand;}H323GloballyUniqueID::H323GloballyUniqueID(const PASN_OctetString & newId) : PBYTEArray(newId){ PAssert(GetSize() == 16, PInvalidParameter);}PString H323GloballyUniqueID::AsString() const{ PStringStream strm; PrintOn(strm); return strm;}void H323GloballyUniqueID::PrintOn(ostream & strm) const{ char fillchar = strm.fill(); strm << hex << setfill('0') << setw(2) << theArray[0] << setw(2) << theArray[1] << setw(2) << theArray[2] << setw(2) << theArray[3] << '-' << setw(2) << theArray[4] << setw(2) << theArray[5] << '-' << setw(2) << theArray[6] << setw(2) << theArray[7] << '-' << setw(2) << theArray[8] << setw(2) << theArray[9] << '-' << setw(2) << theArray[10] << setw(2) << theArray[11] << setw(2) << theArray[12] << setw(2) << theArray[13] << setw(2) << theArray[14] << setw(2) << theArray[15] << dec << setfill(fillchar);}///////////////////////////////////////////////////////////////////////////////H323SignalPDU::H323SignalPDU(){}H225_Facility_UUIE * H323SignalPDU::BuildFacility(const H323Connection & connection, BOOL empty){ q931pdu.BuildFacility(connection.GetCallReference(), connection.HadAnsweredCall()); if (empty) { m_h323_uu_pdu.m_h323_message_body.SetTag(H225_H323_UU_PDU_h323_message_body::e_empty); return NULL; } m_h323_uu_pdu.m_h323_message_body.SetTag(H225_H323_UU_PDU_h323_message_body::e_facility); H225_Facility_UUIE & fac = m_h323_uu_pdu.m_h323_message_body; fac.m_protocolIdentifier.SetValue(H225_ProtocolID); fac.IncludeOptionalField(H225_Facility_UUIE::e_callIdentifier); fac.m_callIdentifier.m_guid = connection.GetCallIdentifier(); return &fac;}H225_CallProceeding_UUIE & H323SignalPDU::BuildCallProceeding(const H323Connection & connection){ q931pdu.BuildCallProceeding(connection.GetCallReference()); SetQ931Fields(connection); m_h323_uu_pdu.m_h323_message_body.SetTag(H225_H323_UU_PDU_h323_message_body::e_callProceeding); H225_CallProceeding_UUIE & proceeding = m_h323_uu_pdu.m_h323_message_body; proceeding.m_protocolIdentifier.SetValue(H225_ProtocolID); proceeding.m_callIdentifier.m_guid = connection.GetCallIdentifier(); connection.GetEndPoint().SetEndpointTypeInfo(proceeding.m_destinationInfo); return proceeding;}H225_Alerting_UUIE & H323SignalPDU::BuildAlerting(const H323Connection & connection){ q931pdu.BuildAlerting(connection.GetCallReference()); SetQ931Fields(connection); m_h323_uu_pdu.m_h323_message_body.SetTag(H225_H323_UU_PDU_h323_message_body::e_alerting); H225_Alerting_UUIE & alerting = m_h323_uu_pdu.m_h323_message_body; alerting.m_protocolIdentifier.SetValue(H225_ProtocolID); alerting.m_callIdentifier.m_guid = connection.GetCallIdentifier(); connection.GetEndPoint().SetEndpointTypeInfo(alerting.m_destinationInfo); return alerting;}H225_ReleaseComplete_UUIE & H323SignalPDU::BuildReleaseComplete(const H323Connection & connection){ q931pdu.BuildReleaseComplete(connection.GetCallReference(), connection.HadAnsweredCall()); m_h323_uu_pdu.m_h323_message_body.SetTag(H225_H323_UU_PDU_h323_message_body::e_releaseComplete); H225_ReleaseComplete_UUIE & release = m_h323_uu_pdu.m_h323_message_body; release.m_protocolIdentifier.SetValue(H225_ProtocolID); release.m_callIdentifier.m_guid = connection.GetCallIdentifier();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -