Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / sys / net / i4b / layer2 / i4b_l2.h
1 /*
2  * Copyright (c) 1997, 2000 Hellmuth Michaelis. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23  * SUCH DAMAGE.
24  *
25  *---------------------------------------------------------------------------
26  *
27  *      i4b_l2.h - ISDN layer 2 (Q.921) definitions
28  *      ---------------------------------------------
29  *
30  *      $Id: i4b_l2.h,v 1.23 2000/08/24 11:48:58 hm Exp $ 
31  *
32  * $FreeBSD: src/sys/i4b/layer2/i4b_l2.h,v 1.6.2.1 2001/08/10 14:08:41 obrien Exp $
33  * $DragonFly: src/sys/net/i4b/layer2/i4b_l2.h,v 1.2 2003/06/17 04:28:40 dillon Exp $
34  *
35  *      last edit-date: [Sat Mar 18 10:28:22 2000]
36  *
37  *---------------------------------------------------------------------------*/
38
39 #ifndef _I4B_L2_H_
40 #define _I4B_L2_H_
41
42 typedef struct {
43         int     unit;           /* unit number this entry is for */
44
45         int     Q921_state;     /* state according to Q.921 */
46
47         u_char  last_ril;       /* last reference number from TEI management */
48         u_char  last_rih;
49
50         int     tei_valid;      /* tei is valid flag */
51 #define TEI_INVALID     0
52 #define TEI_VALID       1       
53         int     tei;            /* tei, if tei flag valid */
54
55         int     ph_active;      /* Layer 1 active flag */
56 #define PH_INACTIVE     0       /* layer 1 inactive */
57 #define PH_ACTIVEPEND   1       /* already tried to activate */
58 #define PH_ACTIVE       2       /* layer 1 active */
59
60         int     T200;           /* Multiframe timeout timer */
61         int     T201;           /* min time between TEI ID check */
62         int     T202;           /* min time between TEI ID Req messages */
63         int     N202;           /* TEI ID Req tx counter */
64         void(*T202func)(void *);/* function to be called when T202 expires */
65         int     T203;           /* max line idle time */
66
67 #if defined(__FreeBSD__)
68         struct  callout_handle T200_callout;
69         struct  callout_handle T202_callout;
70         struct  callout_handle T203_callout;
71         struct  callout_handle IFQU_callout;    
72 #endif
73 #if defined(__NetBSD__) && __NetBSD_Version__ >= 104230000
74         struct  callout T200_callout;
75         struct  callout T202_callout;
76         struct  callout T203_callout;
77         struct  callout IFQU_callout;   
78 #endif
79
80 /*
81  * i4b_iframe.c, i4b_i_frame_queued_up(): value of IFQU_DLY
82  * some experimentation Gary did showed a minimal value of (hz/20) was
83  * possible to let this work, Gary suggested using (hz/10) but i settled
84  * down to using (hz/5) for now (-hm).
85  */
86 #define IFQU_DLY (hz/5)         /* reschedule I-FRAME-QUEUED-UP 0.2 sec */
87
88         int     vr;             /* receive sequence frame counter */
89         int     vs;             /* transmit sequence frame counter */
90         int     va;             /* acknowledge sequence frame counter */
91
92         int     ack_pend;       /* acknowledge pending */
93         int     rej_excpt;      /* reject exception */
94         int     peer_busy;      /* peer receiver busy */
95         int     own_busy;       /* own receiver busy */
96         int     l3initiated;    /* layer 3 initiated */
97
98         struct ifqueue i_queue; /* queue of outgoing i frames */
99 #define IQUEUE_MAXLEN   20
100
101         /* this implementation only supports a k-value of 1 !!! */
102         struct mbuf *ua_frame;  /* last unacked frame */
103         int     ua_num;         /* last unacked frame number */
104 #define UA_EMPTY (-1)           /* ua_frame is unused   */      
105
106         int     rxd_CR;         /* received Command Response bit */
107         int     rxd_PF;         /* received Poll/Final bit */
108         int     rxd_NR;         /* received N(R) field */
109         int     RC;             /* Retry Counter */
110
111         int     iframe_sent;    /* check if i frame acked by another i frame */
112         
113         int (*postfsmfunc)(int);/* function to be called at fsm exit */
114         int     postfsmarg;     /* argument for above function */
115
116         /* statistics */
117
118         lapdstat_t      stat;   /* lapd protocol statistics */
119
120 } l2_softc_t;
121
122 extern l2_softc_t l2_softc[];
123
124 /* Q.912 system parameters (Q.921 03/93 pp 43) */
125
126 #define MAX_K_VALUE     1       /* BRI - # of outstanding frames        */
127
128 #define N200    3               /* max no of retransmissions */
129 #define N201DEF 260             /* max no of octetts in information field */
130 #define N202DEF 3               /* max no of TEI ID Request message transmissions */
131
132 #define T200DEF (hz*1)          /* default T200 timer value = 1 second  */
133 #define T201DEF T200DEF         /* default T201 timer value = T200DEF   */
134 #define T202DEF (hz*2)          /* default T202 timer value = 2 seconds */
135 #define T203DEF (hz*10)         /* default T203 timer value = 10 seconds*/
136
137 /* modulo 128 operations */
138
139 #define M128INC(v)      (v)++;          \
140                         if((v)>127)     \
141                         {               \
142                                 v = 0;  \
143                         }
144                         
145 #define M128DEC(v)      (v)--;          \
146                         if((v)<0)       \
147                         {               \
148                                 v = 127;\
149                         }
150                         
151 /* P-bit values */
152
153 typedef enum {
154         P0,
155         P1
156 } pbit_t;
157
158 /* F-bit values */
159
160 typedef enum {
161         F0,
162         F1
163 } fbit_t;
164
165 /* CR-bit values to NT */
166
167 typedef enum {
168         CR_CMD_TO_NT,
169         CR_RSP_TO_NT
170 } crbit_to_nt_t;
171
172 /* CR-bit values from NT */
173
174 typedef enum {
175         CR_RSP_FROM_NT,
176         CR_CMD_FROM_NT
177 } crbit_from_nt_t;
178
179 /* address field - octett 2 */
180
181 #define OFF_SAPI        0       /* SAPI offset, HDLC flag is eaten by L1 */
182 #define SAPI_CCP        0       /* SAPI = 0 - call control procedures */
183 #define SAPI_X25        16      /* SAPI = 16 - X.25 packet procedures */
184 #define SAPI_L2M        63      /* SAPI = 63 - Layer 2 management procedures */
185
186 /* extract and insert macros for SAPI octett */
187
188 #define GETSAPI(octett)         (((octett) >> 2) & 0x3f)
189 #define PUTSAPI(sapi,cr,octett) ((octett) = (((sapi << 2) & 0xfc) | ((cr & 0x01) << 1)))
190 #define GETCR(octett)           (((octett) >> 1) & 0x01)
191 #define GETEA(octett)           ((octett) & 0x01)
192
193 /* address field - octett 3 */
194
195 #define OFF_TEI         1       /* TEI offset */
196 #define GETTEI(octett) (((octett) >> 1) & 0x7f)
197 #define PUTTEI(tei, octett) ((octett) = ((((tei) << 1) & 0xfe)) | 0x01) 
198 #define GROUP_TEI       127     /* broadcast TEI for LME */
199
200 /* control field - octett 4 */
201
202 #define OFF_CNTL        2       /* 1st byte of control field */
203
204 /* S frames */
205
206 #define S_FRAME_LEN     4       /* lenght of a U-frame */
207 #define OFF_SRCR        2       /* 1st byte of control field,   */
208                                 /* R-commands and R-responses   */
209 #define OFF_SNR         3       /* 2nd byte of control field, N(R) and PF */
210 #define SPFBIT          0x01    /* poll/final bit mask */
211 #define SPBITSET        SPFBIT
212 #define SFBITSET        SPFBIT
213 #define GETSNR(octett) (((octett) >> 1) & 0x7f)
214 #define GETSPF(octett) ((octett) & SPFBIT)
215 #define RR              0x01    /* RR and bit 0 set */
216 #define RNR             0x05    /* RNR and bit 0 set */
217 #define REJ             0x09    /* REJ and bit 0 set */
218
219 /* U frames */
220
221 #define UI_HDR_LEN      3       /* length of UI header in front of L3 frame */
222 #define U_FRAME_LEN     3       /* lenght of a U-frame */
223 #define UPFBIT          0x10    /* poll/final bit mask */
224 #define UPBITSET        UPFBIT
225 #define UFBITSET        UPFBIT
226 #define GETUPF(octett) (((octett) >> 4) & 0x01)
227
228 /* commands/responses with pf bit set to 0 */
229
230 #define SABME           0x6f
231 #define DM              0x0f
232 #define UI              0x03
233 #define DISC            0x43
234 #define UA              0x63
235 #define FRMR            0x87
236 #define XID             0xaf
237
238 /* control field - octett 3 */
239
240 #define OFF_MEI         3       /* 2nd byte of control field */
241
242 /* control field - octett 4,5 */
243
244 #define OFF_RIL         4       /* Ri low byte */
245 #define OFF_RIH         5       /* Ri high byte */
246
247 /* control field - octett 6 */
248
249 #define OFF_MT          6       /* Message Type */
250 #define OFF_AI          7       /* Action Indicator  */
251 #define GET_TEIFROMAI(octett) (((octett) >> 1) & 0x7f)
252
253 /* I frame */
254
255 #define I_HDR_LEN       4       /* length of I header in front of L3 frame */
256 #define OFF_INS         2       /* transmit sequence number */
257 #define OFF_INR         3       /* receive sequence number */
258 #define IPFBIT          0x01    /* poll/final bit mask */
259 #define IPBITSET        0x01
260 #define GETINR(octett)  (((octett) >> 1) & 0x7f)
261 #define GETINS(octett)  (((octett) >> 1) & 0x7f)
262 #define GETIP(octett)   ((octett) & IPFBIT)
263
264 /* structure of a TEI management frame */
265
266 #define TEI_MGMT_FRM_LEN   8            /* frame length */
267 #define TEIM_SAPIO      0x00            /* SAPI, CR, EA */
268 #define TEIM_TEIO       0x01            /* TEI, EA */
269 #define TEIM_UIO        0x02            /* frame type = UI = 0x03 */
270 #define TEIM_MEIO       0x03            /* management entity id = 0x0f */
271 #define         MEI     0x0f    
272 #define TEIM_RILO       0x04            /* reference number, low  */
273 #define TEIM_RIHO       0x05            /* reference number, high */
274 #define TEIM_MTO        0x06            /* message type */
275 #define         MT_ID_REQEST    0x01
276 #define         MT_ID_ASSIGN    0x02
277 #define         MT_ID_DENY      0x03
278 #define         MT_ID_CHK_REQ   0x04
279 #define         MT_ID_CHK_RSP   0x05
280 #define         MT_ID_REMOVE    0x06
281 #define         MT_ID_VERIFY    0x07
282 #define TEIM_AIO        0x07            /* action indicator */
283
284 /* i4b_mdl_error_ind codes */
285
286 enum MDL_ERROR_CODES {
287         MDL_ERR_A,
288         MDL_ERR_B,
289         MDL_ERR_C,
290         MDL_ERR_D,
291         MDL_ERR_E,
292         MDL_ERR_F,
293         MDL_ERR_G,
294         MDL_ERR_H,
295         MDL_ERR_I,
296         MDL_ERR_J,
297         MDL_ERR_K,
298         MDL_ERR_L,
299         MDL_ERR_M,
300         MDL_ERR_N,
301         MDL_ERR_O,
302         MDL_ERR_MAX     
303 };
304
305 /* forward decl */
306
307 extern void i4b_acknowledge_pending ( l2_softc_t *l2sc );
308 extern struct mbuf * i4b_build_s_frame ( l2_softc_t *l2sc, crbit_to_nt_t crbit, pbit_t pbit, u_char type );
309 extern struct mbuf * i4b_build_u_frame ( l2_softc_t *l2sc, crbit_to_nt_t crbit, pbit_t pbit, u_char type );
310 extern void i4b_clear_exception_conditions ( l2_softc_t *l2sc );
311 extern int i4b_dl_data_req ( int unit, struct mbuf *m );
312 extern int i4b_dl_establish_req ( int unit );
313 extern int i4b_dl_release_req ( int unit );
314 extern int i4b_dl_unit_data_req ( int unit, struct mbuf *m );
315 extern void i4b_enquiry_response ( l2_softc_t *l2sc );
316 extern void i4b_establish_data_link ( l2_softc_t *l2sc );
317 extern void i4b_invoke_retransmission ( l2_softc_t *l2sc, int nr );
318 extern void i4b_i_frame_queued_up ( l2_softc_t *l2sc );
319 extern void i4b_l1_activate ( l2_softc_t *l2sc );
320 extern int i4b_l2_nr_ok ( int nr, int va, int vs );
321 extern void i4b_make_rand_ri ( l2_softc_t *l2sc );
322 extern void i4b_mdl_assign_ind ( l2_softc_t *l2sc );
323 extern void i4b_mdl_error_ind ( l2_softc_t *l2sc, char *where, int errorcode );
324 extern int i4b_mph_status_ind ( int unit, int status, int parm );
325 extern void i4b_next_l2state ( l2_softc_t *l2sc, int event );
326 extern void i4b_nr_error_recovery ( l2_softc_t *l2sc );
327 extern int i4b_ph_activate_ind ( int unit );
328 extern int i4b_ph_deactivate_ind ( int unit );
329 extern int i4b_ph_data_ind ( int unit, struct mbuf *m );
330 extern void i4b_print_frame ( int len, u_char *buf );
331 extern char *i4b_print_l2state ( l2_softc_t *l2sc );
332 extern void i4b_print_l2var ( l2_softc_t *l2sc );
333 extern void i4b_rxd_ack(l2_softc_t *l2sc, int nr);
334 extern void i4b_rxd_i_frame ( int unit, struct mbuf *m );
335 extern void i4b_rxd_s_frame ( int unit, struct mbuf *m );
336 extern void i4b_rxd_u_frame ( int unit, struct mbuf *m );
337 extern void i4b_T200_restart ( l2_softc_t *l2sc );
338 extern void i4b_T200_start ( l2_softc_t *l2sc );
339 extern void i4b_T200_stop ( l2_softc_t *l2sc );
340 extern void i4b_T202_start ( l2_softc_t *l2sc );
341 extern void i4b_T202_stop ( l2_softc_t *l2sc );
342 extern void i4b_T203_restart ( l2_softc_t *l2sc );
343 extern void i4b_T203_start ( l2_softc_t *l2sc );
344 extern void i4b_T203_stop ( l2_softc_t *l2sc );
345 extern void i4b_tei_assign ( l2_softc_t *l2sc );
346 extern void i4b_tei_chkresp ( l2_softc_t *l2sc );
347 extern void i4b_tei_rxframe ( int unit, struct mbuf *m );
348 extern void i4b_tei_verify ( l2_softc_t *l2sc );
349 extern void i4b_transmit_enquire ( l2_softc_t *l2sc );
350 extern void i4b_tx_disc ( l2_softc_t *l2sc, pbit_t pbit );
351 extern void i4b_tx_dm ( l2_softc_t *l2sc, fbit_t fbit );
352 extern void i4b_tx_frmr ( l2_softc_t *l2sc, fbit_t fbit );
353 extern void i4b_tx_rej_response ( l2_softc_t *l2sc, fbit_t fbit );
354 extern void i4b_tx_rnr_command ( l2_softc_t *l2sc, pbit_t pbit );
355 extern void i4b_tx_rnr_response ( l2_softc_t *l2sc, fbit_t fbit );
356 extern void i4b_tx_rr_command ( l2_softc_t *l2sc, pbit_t pbit );
357 extern void i4b_tx_rr_response ( l2_softc_t *l2sc, fbit_t fbit );
358 extern void i4b_tx_sabme ( l2_softc_t *l2sc, pbit_t pbit );
359 extern void i4b_tx_ua ( l2_softc_t *l2sc, fbit_t fbit );
360
361 #endif /* _I4B_L2_H_ */