Added missing build dependency
[opal/cbnco.git] / src / t120 / t120proto.cxx
blobf428a98b2d26cd6a2db5ebb5643a7821a029d61f
1 /*
2 * t120proto.cxx
4 * T.120 protocol handler
6 * Open Phone Abstraction Library
8 * Copyright (c) 1998-2000 Equivalence Pty. Ltd.
10 * The contents of this file are subject to the Mozilla Public License
11 * Version 1.0 (the "License"); you may not use this file except in
12 * compliance with the License. You may obtain a copy of the License at
13 * http://www.mozilla.org/MPL/
15 * Software distributed under the License is distributed on an "AS IS"
16 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17 * the License for the specific language governing rights and limitations
18 * under the License.
20 * The Original Code is Open H323 Library.
22 * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
24 * Contributor(s): ______________________________________.
26 * $Log$
27 * Revision 2.7 2005/02/21 12:20:07 rjongbloed
28 * Added new "options list" to the OpalMediaFormat class.
30 * Revision 2.6 2002/11/10 11:33:20 robertj
31 * Updated to OpenH323 v1.10.3
33 * Revision 2.5 2002/09/04 06:01:49 robertj
34 * Updated to OpenH323 v1.9.6
36 * Revision 2.4 2002/02/11 09:32:13 robertj
37 * Updated to openH323 v1.8.0
39 * Revision 2.3 2002/01/22 05:22:19 robertj
40 * Added RTP encoding name string to media format database.
41 * Changed time units to clock rate in Hz.
43 * Revision 2.2 2001/08/01 05:05:49 robertj
44 * Major changes to H.323 capabilities, uses OpalMediaFormat for base name.
46 * Revision 2.1 2001/07/30 01:07:52 robertj
47 * Post first check in fix ups.
49 * Revision 2.0 2001/07/27 15:48:25 robertj
50 * Conversion of OpenH323 to Open Phone Abstraction Library (OPAL)
52 * Revision 1.4 2002/09/03 06:04:11 robertj
53 * Added globally accessible functions for media format name.
55 * Revision 1.3 2002/08/05 10:03:48 robertj
56 * Cosmetic changes to normalise the usage of pragma interface/implementation.
58 * Revision 1.2 2002/02/01 01:47:34 robertj
59 * Some more fixes for T.120 channel establishment, more to do!
61 * Revision 1.1 2001/07/17 04:44:32 robertj
62 * Partial implementation of T.120 and T.38 logical channels.
66 #include <ptlib.h>
68 #ifdef __GNUC__
69 #pragma implementation "t120proto.h"
70 #endif
72 #include <t120/t120proto.h>
74 #include <h323/transaddr.h>
75 #include <t120/x224.h>
76 #include <asn/mcs.h>
79 class T120_X224 : public X224 {
80 PCLASSINFO(T120_X224, X224);
81 public:
82 BOOL Read(H323Transport & transport);
83 BOOL Write(H323Transport & transport);
87 class T120ConnectPDU : public MCS_ConnectMCSPDU {
88 PCLASSINFO(T120ConnectPDU, MCS_ConnectMCSPDU);
89 public:
90 BOOL Read(H323Transport & transport);
91 BOOL Write(H323Transport & transport);
92 protected:
93 T120_X224 x224;
97 const OpalMediaFormat OpalT120(
98 OPAL_T120,
99 OpalMediaFormat::DefaultDataSessionID,
100 RTP_DataFrame::IllegalPayloadType,
101 "t120",
102 FALSE, // No jitter for data
103 825000, // 100's bits/sec
109 #define new PNEW
112 /////////////////////////////////////////////////////////////////////////////
114 BOOL T120_X224::Read(H323Transport & transport)
116 PBYTEArray rawData;
118 if (!transport.ReadPDU(rawData)) {
119 PTRACE(1, "T120\tRead of X224 failed: " << transport.GetErrorText());
120 return FALSE;
123 if (Decode(rawData)) {
124 PTRACE(1, "T120\tDecode of PDU failed:\n " << setprecision(2) << *this);
125 return FALSE;
128 PTRACE(4, "T120\tRead X224 PDU:\n " << setprecision(2) << *this);
129 return TRUE;
133 BOOL T120_X224::Write(H323Transport & transport)
135 PBYTEArray rawData;
137 PTRACE(4, "T120\tWrite X224 PDU:\n " << setprecision(2) << *this);
139 if (!Encode(rawData)) {
140 PTRACE(1, "T120\tEncode of PDU failed:\n " << setprecision(2) << *this);
141 return FALSE;
144 if (!transport.WritePDU(rawData)) {
145 PTRACE(1, "T120\tWrite X224 PDU failed: " << transport.GetErrorText());
146 return FALSE;
149 return TRUE;
153 /////////////////////////////////////////////////////////////////////////////
155 BOOL T120ConnectPDU::Read(H323Transport & transport)
157 if (!x224.Read(transport))
158 return FALSE;
160 // An X224 Data PDU...
161 if (x224.GetCode() != X224::DataPDU) {
162 PTRACE(1, "T120\tX224 must be data PDU");
163 return FALSE;
166 // ... contains the T120 MCS PDU
167 PBER_Stream ber = x224.GetData();
168 if (!Decode(ber)) {
169 PTRACE(1, "T120\tDecode of PDU failed:\n " << setprecision(2) << *this);
170 return FALSE;
173 PTRACE(4, "T120\tReceived MCS Connect PDU:\n " << setprecision(2) << *this);
174 return TRUE;
178 BOOL T120ConnectPDU::Write(H323Transport & transport)
180 PTRACE(4, "T120\tSending MCS Connect PDU:\n " << setprecision(2) << *this);
182 PBER_Stream ber;
183 Encode(ber);
184 ber.CompleteEncoding();
185 x224.BuildData(ber);
186 return x224.Write(transport);
190 /////////////////////////////////////////////////////////////////////////////
192 OpalT120Protocol::OpalT120Protocol()
197 BOOL OpalT120Protocol::Originate(H323Transport & transport)
199 PTRACE(3, "T120\tOriginate, sending X224 CONNECT-REQUEST");
201 T120_X224 x224;
202 x224.BuildConnectRequest();
203 if (!x224.Write(transport))
204 return FALSE;
206 transport.SetReadTimeout(10000); // Wait 10 seconds for reply
207 if (!x224.Read(transport))
208 return FALSE;
210 if (x224.GetCode() != X224::ConnectConfirm) {
211 PTRACE(1, "T120\tPDU was not X224 CONNECT-CONFIRM");
212 return FALSE;
215 T120ConnectPDU pdu;
216 while (pdu.Read(transport)) {
217 if (!HandleConnect(pdu))
218 return TRUE;
221 return FALSE;
225 BOOL OpalT120Protocol::Answer(H323Transport & transport)
227 PTRACE(3, "T120\tAnswer, awaiting X224 CONNECT-REQUEST");
229 T120_X224 x224;
230 transport.SetReadTimeout(60000); // Wait 60 seconds for reply
232 do {
233 if (!x224.Read(transport))
234 return FALSE;
235 } while (x224.GetCode() != X224::ConnectRequest);
237 x224.BuildConnectConfirm();
238 if (!x224.Write(transport))
239 return FALSE;
241 T120ConnectPDU pdu;
242 while (pdu.Read(transport)) {
243 if (!HandleConnect(pdu))
244 return TRUE;
247 return FALSE;
251 BOOL OpalT120Protocol::HandleConnect(const MCS_ConnectMCSPDU & /*pdu*/)
253 return TRUE;
257 BOOL OpalT120Protocol::HandleDomain(const MCS_DomainMCSPDU & /*pdu*/)
259 return TRUE;
263 /////////////////////////////////////////////////////////////////////////////