OPAL  Version 3.12.9
q922.h
Go to the documentation of this file.
1 /*
2  * q922.h
3  *
4  * Q.922 PDU implementation for the OpenH323 Project.
5  *
6  * Copyright (c) 2006 Network for Educational Technology, ETH Zurich.
7  * Written by Hannes Friederich.
8  *
9  * The contents of this file are subject to the Mozilla Public License
10  * Version 1.0 (the "License"); you may not use this file except in
11  * compliance with the License. You may obtain a copy of the License at
12  * http://www.mozilla.org/MPL/
13  *
14  * Software distributed under the License is distributed on an "AS IS"
15  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
16  * the License for the specific language governing rights and limitations
17  * under the License.
18  *
19  * Contributor(s): ______________________________________.
20  *
21  * $Revision: 21346 $
22  * $Author: hfriederich $
23  * $Date: 2008-10-16 09:21:15 +1100 (Thu, 16 Oct 2008) $
24  */
25 
26 #ifndef OPAL_H224_Q922_H
27 #define OPAL_H224_Q922_H
28 
29 #ifdef P_USE_PRAGMA
30 #pragma interface
31 #endif
32 
33 #ifndef _PTLIB_H
34 #include <ptlib.h>
35 #endif
36 
37 #include <opal/buildopts.h>
38 
39 #define Q922_HEADER_SIZE 3
40 
41 class Q922_Frame : public PBYTEArray
42 {
43  PCLASSINFO(Q922_Frame, PBYTEArray);
44 
45 public:
46 
47  Q922_Frame(PINDEX informationFieldSize = 260);
48  ~Q922_Frame();
49 
50  BYTE GetHighOrderAddressOctet() const { return theArray[0]; }
51  BYTE GetLowOrderAddressOctet() const { return theArray[1]; }
52  void SetHighOrderAddressOctet(BYTE octet) { theArray[0] = octet; }
53  void SetLowOrderAddressOctet(BYTE octet) { theArray[1] = octet; }
54 
55  BYTE GetControlFieldOctet() const { return theArray[2]; }
56  void SetControlFieldOctet(BYTE octet) { theArray[2] = octet; }
57 
58  BYTE *GetInformationFieldPtr() const { return (BYTE *)(theArray + Q922_HEADER_SIZE); }
59 
60  PINDEX GetInformationFieldSize() const { return informationFieldSize; }
61  void SetInformationFieldSize(PINDEX size);
62 
66  PBoolean DecodeAnnexQ(const BYTE *buffer, PINDEX size);
67 
70  PINDEX GetAnnexQEncodedSize() const;
71 
75  PBoolean EncodeAnnexQ(BYTE *buffer, PINDEX & size) const;
76 
80  PBoolean DecodeHDLC(const BYTE *data, PINDEX size);
81 
85  PINDEX GetHDLCEncodedSize() const;
86 
90  PBoolean EncodeHDLC(BYTE *buffer, PINDEX & size) const;
91 
99  PBoolean EncodeHDLC(BYTE *buffer, PINDEX & size, BYTE & bitPosition) const;
100 
101 protected:
102 
104 
105 private:
106 
107  // for HDLC mode
108  inline PBoolean FindFlagEnd(const BYTE *buffer, PINDEX bufferSize, PINDEX & octetIndex, BYTE & bitIndex);
109  inline BYTE DecodeOctet(const BYTE *buffer, BYTE *destination, PINDEX & octetIndex, BYTE & bitIndex, BYTE & onesCounter);
110  inline BYTE DecodeBit(const BYTE *buffer, PINDEX & octetIndex, BYTE & bitIndex);
111 
112  inline void EncodeOctet(BYTE octet, BYTE *buffer, PINDEX & octetIndex, BYTE & bitIndex, BYTE & onesCounter) const;
113  inline void EncodeOctetNoEscape(BYTE octet, BYTE *buffer, PINDEX & octetIndex, BYTE & bitIndex) const;
114  inline void EncodeBit(BYTE bit, BYTE *buffer, PINDEX & octetIndex, BYTE & bitIndex) const;
115 
116  inline WORD CalculateFCS(const BYTE*data, PINDEX length) const;
117 };
118 
119 #endif // OPAL_H224_Q922_H
120