OPAL  Version 3.14.3
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: 30608 $
22  * $Author: rjongbloed $
23  * $Date: 2013-10-02 18:15:10 +1000 (Wed, 02 Oct 2013) $
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_config.h>
38 
39 #if OPAL_HAS_H224
40 
41 #define Q922_HEADER_SIZE 3
42 
43 class Q922_Frame : public PBYTEArray
44 {
45  PCLASSINFO(Q922_Frame, PBYTEArray);
46 
47 public:
48 
49  Q922_Frame(PINDEX informationFieldSize = 260);
50  ~Q922_Frame();
51 
52  BYTE GetHighOrderAddressOctet() const { return theArray[0]; }
53  BYTE GetLowOrderAddressOctet() const { return theArray[1]; }
54  void SetHighOrderAddressOctet(BYTE octet) { theArray[0] = octet; }
55  void SetLowOrderAddressOctet(BYTE octet) { theArray[1] = octet; }
56 
57  BYTE GetControlFieldOctet() const { return theArray[2]; }
58  void SetControlFieldOctet(BYTE octet) { theArray[2] = octet; }
59 
60  BYTE *GetInformationFieldPtr() const { return (BYTE *)(theArray + Q922_HEADER_SIZE); }
61 
63  void SetInformationFieldSize(PINDEX size);
64 
68  bool DecodeAnnexQ(const BYTE *buffer, PINDEX size);
69 
72  PINDEX GetAnnexQEncodedSize() const;
73 
77  bool EncodeAnnexQ(BYTE *buffer, PINDEX & size) const;
78 
82  bool DecodeHDLC(const BYTE *data, PINDEX size);
83 
87  PINDEX GetHDLCEncodedSize() const;
88 
92  bool EncodeHDLC(BYTE *buffer, PINDEX & size) const;
93 
101  bool EncodeHDLC(BYTE *buffer, PINDEX & size, PINDEX & bitPosition) const;
102 
103 protected:
104 
106 
107 private:
108 
109  // for HDLC mode
110  inline bool FindFlagEnd(const BYTE *buffer, PINDEX bufferSize, PINDEX & octetIndex, PINDEX & bitIndex);
111  inline BYTE DecodeOctet(const BYTE *buffer, BYTE *destination, PINDEX & octetIndex, PINDEX & bitIndex, PINDEX & onesCounter);
112  inline BYTE DecodeBit(const BYTE *buffer, PINDEX & octetIndex, PINDEX & bitIndex);
113 
114  inline void EncodeOctet(BYTE octet, BYTE *buffer, PINDEX & octetIndex, PINDEX & bitIndex, PINDEX & onesCounter) const;
115  inline void EncodeOctetNoEscape(BYTE octet, BYTE *buffer, PINDEX & octetIndex, PINDEX & bitIndex) const;
116  inline void EncodeBit(BYTE bit, BYTE *buffer, PINDEX & octetIndex, PINDEX & bitIndex) const;
117 
118  inline WORD CalculateFCS(const BYTE*data, PINDEX length) const;
119 };
120 
121 
122 #endif // OPAL_HAS_H224
123 
124 #endif // OPAL_H224_Q922_H