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