Initial import from FreeBSD RELENG_4:
[dragonfly.git] / sys / net / i4b / layer2 / i4b_lme.c
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_lme.c - layer management entity
28  *      -------------------------------------
29  *
30  *      $Id: i4b_lme.c,v 1.15 2000/08/24 11:48:58 hm Exp $ 
31  *
32  * $FreeBSD: src/sys/i4b/layer2/i4b_lme.c,v 1.6.2.1 2001/08/10 14:08:41 obrien Exp $
33  *
34  *      last edit-date: [Mon May 29 16:55:12 2000]
35  *
36  *---------------------------------------------------------------------------*/
37
38 #ifdef __FreeBSD__
39 #include "i4bq921.h"
40 #else
41 #define NI4BQ921        1
42 #endif
43 #if NI4BQ921 > 0
44
45 #include <sys/param.h>
46 #include <sys/systm.h>
47 #include <sys/socket.h>
48 #include <net/if.h>
49
50 #if defined(__NetBSD__) && __NetBSD_Version__ >= 104230000
51 #include <sys/callout.h>
52 #endif
53
54 #ifdef __FreeBSD__
55 #include <machine/i4b_debug.h>
56 #else
57 #include <i4b/i4b_debug.h>
58 #include <i4b/i4b_ioctl.h>
59 #endif
60
61
62 #include <i4b/layer2/i4b_l2.h>
63
64 /*---------------------------------------------------------------------------*
65  *      mdl assign indication handler
66  *---------------------------------------------------------------------------*/
67 void
68 i4b_mdl_assign_ind(l2_softc_t *l2sc)
69 {
70         NDBGL2(L2_PRIM, "unit %d", l2sc->unit);
71         
72         i4b_l1_activate(l2sc);
73         
74         if(l2sc->tei_valid == TEI_VALID)
75         {
76                 l2sc->T202func = (void(*)(void*))i4b_tei_verify;
77                 l2sc->N202 = N202DEF;
78                 i4b_tei_verify(l2sc);
79         }
80         else
81         {
82                 l2sc->T202func = (void(*)(void*))i4b_tei_assign;
83                 l2sc->N202 = N202DEF;
84                 i4b_tei_assign(l2sc);
85         }               
86 }
87
88 /*---------------------------------------------------------------------------*
89  *      i4b_mdl_error_ind handler (Q.921 01/94 pp 156)
90  *---------------------------------------------------------------------------*/
91 void
92 i4b_mdl_error_ind(l2_softc_t *l2sc, char *where, int errorcode)
93 {
94 #if DO_I4B_DEBUG
95         static char *error_text[] = {
96                 "MDL_ERR_A: rx'd unsolicited response - supervisory (F=1)",
97                 "MDL_ERR_B: rx'd unsolicited response - DM (F=1)",
98                 "MDL_ERR_C: rx'd unsolicited response - UA (F=1)",
99                 "MDL_ERR_D: rx'd unsolicited response - UA (F=0)",
100                 "MDL_ERR_E: rx'd unsolicited response - DM (F=0)",
101                 "MDL_ERR_F: peer initiated re-establishment - SABME",
102                 "MDL_ERR_G: unsuccessful transmission N200times - SABME",
103                 "MDL_ERR_H: unsuccessful transmission N200times - DIS",
104                 "MDL_ERR_I: unsuccessful transmission N200times - Status ENQ",
105                 "MDL_ERR_J: other error - N(R) error",
106                 "MDL_ERR_K: other error - rx'd FRMR response",
107                 "MDL_ERR_L: other error - rx'd undefined frame",
108                 "MDL_ERR_M: other error - receipt of I field not permitted",
109                 "MDL_ERR_N: other error - rx'd frame with wrong size",
110                 "MDL_ERR_O: other error - N201 error",
111                 "MDL_ERR_MAX: i4b_mdl_error_ind called with wrong parameter!!!"
112         };
113 #endif
114
115         if(errorcode > MDL_ERR_MAX)
116                 errorcode = MDL_ERR_MAX;
117                 
118         NDBGL2(L2_ERROR, "unit = %d, location = %s", l2sc->unit, where);
119         NDBGL2(L2_ERROR, "error = %s", error_text[errorcode]);
120
121         switch(errorcode)
122         {       
123                 case MDL_ERR_A:
124                 case MDL_ERR_B:
125                         break;
126
127                 case MDL_ERR_C:
128                 case MDL_ERR_D:
129                         i4b_tei_verify(l2sc);
130                         break;
131
132                 case MDL_ERR_E:
133                 case MDL_ERR_F:
134                         break;
135
136                 case MDL_ERR_G:
137                 case MDL_ERR_H:
138                         i4b_tei_verify(l2sc);
139                         break;
140
141                 case MDL_ERR_I:
142                 case MDL_ERR_J:
143                 case MDL_ERR_K:
144                 case MDL_ERR_L:
145                 case MDL_ERR_M:
146                 case MDL_ERR_N:
147                 case MDL_ERR_O:
148                         break;
149
150                 default:
151                         break;
152         }
153 }
154  
155 #endif /* NI4BQ921 > 0 */