0
|
1 |
/*
|
|
2 |
* Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
* Frame Check Sequence checksums (FCS) for 16 and 32 bits.
|
|
17 |
*
|
|
18 |
* The 16-bit version uses a 512-byte table (2 bytes * 256 elements)
|
|
19 |
* and the 32-bit version uses a 1024-byte table (4 bytes * 256 elements)
|
|
20 |
*
|
|
21 |
* Serial-based HDLC-like framing (RFC 1662) for use with the
|
|
22 |
* CWDS serial protocol.
|
|
23 |
*
|
|
24 |
* Serial data is transmitted using an HDLC-like framing convention.
|
|
25 |
* Byte-oriented streams are transmitted with a starting frame byte
|
|
26 |
* and also followed by an ending frame byte and a checksum (FCS).
|
|
27 |
*
|
|
28 |
* Errors can be detected with high probability using the FCS.
|
|
29 |
* While this is not intended to be used in an environment that
|
|
30 |
* generates a large number of errors, nevertheless it can be
|
|
31 |
* useful to help ensure that packets arrive with a high degree of
|
|
32 |
* certainty and to allow data to be dropped and still allow
|
|
33 |
* continuous data.
|
|
34 |
*
|
|
35 |
* Sender and receiver can be resynchronized with the receipt of a new
|
|
36 |
* framing byte.
|
|
37 |
*
|
|
38 |
*
|
|
39 |
* Frame Format
|
|
40 |
*
|
|
41 |
* The general frame format specified in RFC 1662 is described as:
|
|
42 |
*
|
|
43 |
* +----------+----------+----------+
|
|
44 |
* | Flag | Address | Control |
|
|
45 |
* | 01111110 | 11111111 | 00000011 |
|
|
46 |
* +----------+----------+----------+
|
|
47 |
* +----------+-------------+---------+
|
|
48 |
* | Protocol | Information | Padding |
|
|
49 |
* | 8/16 bits| * | * |
|
|
50 |
* +----------+-------------+---------+
|
|
51 |
* +----------+----------+-----------------
|
|
52 |
* | FCS | Flag | Inter-frame Fill
|
|
53 |
* |16/32 bits| 01111110 | or next Address
|
|
54 |
* +----------+----------+-----------------
|
|
55 |
*
|
|
56 |
* The routines in this file use a subset and are not negotiated;
|
|
57 |
* they are simply assumed. These are:
|
|
58 |
*
|
|
59 |
* Address and Control Field Compression is always ON.
|
|
60 |
* Protocol Field Compression is always ON.
|
|
61 |
* Protocol value is implied, but undefined.
|
|
62 |
* Padding is OFF.
|
|
63 |
* MRU is 1500 bytes.
|
|
64 |
* FCS is 32 bits.
|
|
65 |
* Trailing Flag is always transmitted.
|
|
66 |
*
|
|
67 |
*
|
|
68 |
* The resulting frame format is:
|
|
69 |
*
|
|
70 |
* +----------+
|
|
71 |
* | Flag |
|
|
72 |
* | 01111110 |
|
|
73 |
* +----------+
|
|
74 |
* +-------------+
|
|
75 |
* | Information |
|
|
76 |
* | * |
|
|
77 |
* +-------------+
|
|
78 |
* +----------+----------+-----------------
|
|
79 |
* | FCS | Flag | Inter-frame Fill
|
|
80 |
* |16/32 bits| 01111110 | or next Address
|
|
81 |
* +----------+----------+-----------------
|
|
82 |
*
|
|
83 |
* Macros & Typedefs
|
|
84 |
*
|
|
85 |
* FCSBITSIZE
|
|
86 |
*
|
|
87 |
* This header file must first define FCSBITSIZE to be either one of:
|
|
88 |
* FCS16 or FCS32. These control the definitions for the rest of the header
|
|
89 |
* file and the underlying tables. Selecting FCS16 will cause the header
|
|
90 |
* file to define 16-bit types, table, and functions for calculating the
|
|
91 |
* 16-bit FCS. Selecting FCS32 is identical, except it uses 32-bit FCS values.
|
|
92 |
*
|
|
93 |
* FCS16 will use 512 bytes (2 bytes * 256 entries) of constant data space.
|
|
94 |
* FCS32 will use 1024 bytes.
|
|
95 |
*
|
|
96 |
* FCSType
|
|
97 |
*
|
|
98 |
* The 16- or 32-bit type used for the FCS register and datum.
|
|
99 |
*
|
|
100 |
* PPPINITFCS
|
|
101 |
*
|
|
102 |
* Initialize the FCS register with this value.
|
|
103 |
*
|
|
104 |
* PPPGOODFCS
|
|
105 |
*
|
|
106 |
* On the receiver side, after the FCS compute function is applied
|
|
107 |
* to all data bytes plus the two or four FCS bytes, the correct FCS
|
|
108 |
* value will be PPPGOODFCS, a constant.
|
|
109 |
*
|
|
110 |
* PPPCOMPFCS
|
|
111 |
*
|
|
112 |
*
|
|
113 |
* REFERENCES
|
|
114 |
*
|
|
115 |
* [RFC1662.94] Simpson, W., Editor, "PPP in HDLC-like Framing,"
|
|
116 |
* STD 51, RFC 1662, Daydreamer, July 1994.
|
|
117 |
*
|
|
118 |
*/
|
|
119 |
|
|
120 |
|
|
121 |
#ifndef TRK_SERFRAME_H
|
|
122 |
#define TRK_SERFRAME_H
|
|
123 |
|
|
124 |
#define FCS8 0 /* SCM: Added for simple 8-bit checksums */
|
|
125 |
#define FCS16 1
|
|
126 |
#define FCS32 2
|
|
127 |
|
|
128 |
#define FCSBITSIZE FCS8 /* define as either FCS8, FCS16 or FCS32 */
|
|
129 |
|
|
130 |
|
|
131 |
#if FCSBITSIZE == FCS8
|
|
132 |
|
|
133 |
/*
|
|
134 |
* Definitions for 8-bit simple Frame Check Sequences
|
|
135 |
*/
|
|
136 |
|
|
137 |
typedef unsigned char FCSType; /* 8-bit type */
|
|
138 |
|
|
139 |
#define PPPINITFCS8 0x00 /* Initial FCS value */
|
|
140 |
#define PPPGOODFCS8 0xFF /* Good final FCS value */
|
|
141 |
|
|
142 |
#define PPPINITFCS PPPINITFCS8
|
|
143 |
#define PPPGOODFCS PPPGOODFCS8
|
|
144 |
#define PPPCOMPFCS 0xFF /* complement FCS value */
|
|
145 |
|
|
146 |
#ifdef __cplusplus
|
|
147 |
inline FCSType PPPFCS(FCSType fcs, unsigned char c)
|
|
148 |
{
|
|
149 |
return (fcs + c);
|
|
150 |
}
|
|
151 |
|
|
152 |
#else
|
|
153 |
#define PPPFCS(fcs, c) (fcs + c)
|
|
154 |
#endif
|
|
155 |
|
|
156 |
|
|
157 |
#elif FCSBITSIZE == FCS16
|
|
158 |
|
|
159 |
/*
|
|
160 |
* Definitions for 16-bit Frame Check Sequences
|
|
161 |
*/
|
|
162 |
|
|
163 |
typedef unsigned short FCSType; /* 16-bit type */
|
|
164 |
/* extern FCSType fcstab[]; */
|
|
165 |
extern const FCSType fcstab[256];
|
|
166 |
|
|
167 |
#define PPPINITFCS16 0xffff /* Initial FCS value */
|
|
168 |
#define PPPGOODFCS16 0xf0b8 /* Good final FCS value */
|
|
169 |
|
|
170 |
#define PPPINITFCS PPPINITFCS16
|
|
171 |
#define PPPGOODFCS PPPGOODFCS16
|
|
172 |
#define PPPCOMPFCS 0xffff /* complement FCS value */
|
|
173 |
|
|
174 |
#if __cplusplus
|
|
175 |
inline FCSType PPPFCS(FCSType fcs, unsigned char c)
|
|
176 |
{
|
|
177 |
return (((fcs) >> 8) ^ fcstab[((fcs) ^ (c)) & 0xff]);
|
|
178 |
}
|
|
179 |
|
|
180 |
#else
|
|
181 |
#define PPPFCS(fcs, c) (((fcs) >> 8) ^ fcstab[((fcs) ^ (c)) & 0xff])
|
|
182 |
#endif
|
|
183 |
|
|
184 |
#elif FCSBITSIZE == FCS32
|
|
185 |
|
|
186 |
/*
|
|
187 |
* Definitions for 32-bit Frame Check Sequences
|
|
188 |
*/
|
|
189 |
|
|
190 |
typedef unsigned long FCSType; /* 32-bit FCS */
|
|
191 |
/* extern FCSType fcstab_32[]; */
|
|
192 |
extern const FCSType fcstab_32[256];
|
|
193 |
|
|
194 |
#define PPPINITFCS32 0xffffffff /* Initial FCS value */
|
|
195 |
#define PPPGOODFCS32 0xdebb20e3 /* Good final FCS value */
|
|
196 |
|
|
197 |
#define PPPINITFCS PPPINITFCS32
|
|
198 |
#define PPPGOODFCS PPPGOODFCS32
|
|
199 |
#define PPPCOMPFCS 0xffffffff /* complement FCS value */
|
|
200 |
|
|
201 |
#if __cplusplus
|
|
202 |
inline FCSType PPPFCS(FCSType fcs, unsigned char c)
|
|
203 |
{
|
|
204 |
return (((fcs) >> 8) ^ fcstab_32[((fcs) ^ (c)) & 0xff]);
|
|
205 |
}
|
|
206 |
#else
|
|
207 |
#define PPPFCS(fcs, c) (((fcs) >> 8) ^ fcstab_32[((fcs) ^ (c)) & 0xff])
|
|
208 |
#endif
|
|
209 |
|
|
210 |
#endif
|
|
211 |
|
|
212 |
|
|
213 |
/****************************************************************************/
|
|
214 |
/*
|
|
215 |
* Constants used for framing serial data
|
|
216 |
*/
|
|
217 |
/****************************************************************************/
|
|
218 |
|
|
219 |
#define PPP_UI 0x03 /* Unnumbered Information */
|
|
220 |
#define PPP_FLAG 0x7e /* Flag Sequence */
|
|
221 |
#define PPP_ESCAPE 0x7d /* Asynchronous Control Escape */
|
|
222 |
#define PPP_TRANS 0x20 /* Asynchronous transparency modifier */
|
|
223 |
|
|
224 |
#define MAXFRAMESIZE 0x1000 /* maximum unframed/unescaped data size */
|
|
225 |
|
|
226 |
#endif /* ndef TRK_SERFRAME_H */
|