diff options
Diffstat (limited to 'sys/i4b/layer2')
-rw-r--r-- | sys/i4b/layer2/i4b_iframe.c | 270 | ||||
-rw-r--r-- | sys/i4b/layer2/i4b_l2.c | 385 | ||||
-rw-r--r-- | sys/i4b/layer2/i4b_l2.h | 351 | ||||
-rw-r--r-- | sys/i4b/layer2/i4b_l2fsm.c | 1578 | ||||
-rw-r--r-- | sys/i4b/layer2/i4b_l2fsm.h | 82 | ||||
-rw-r--r-- | sys/i4b/layer2/i4b_l2timer.c | 232 | ||||
-rw-r--r-- | sys/i4b/layer2/i4b_lme.c | 135 | ||||
-rw-r--r-- | sys/i4b/layer2/i4b_mbuf.c | 217 | ||||
-rw-r--r-- | sys/i4b/layer2/i4b_sframe.c | 207 | ||||
-rw-r--r-- | sys/i4b/layer2/i4b_tei.c | 278 | ||||
-rw-r--r-- | sys/i4b/layer2/i4b_uframe.c | 277 | ||||
-rw-r--r-- | sys/i4b/layer2/i4b_util.c | 305 |
12 files changed, 0 insertions, 4317 deletions
diff --git a/sys/i4b/layer2/i4b_iframe.c b/sys/i4b/layer2/i4b_iframe.c deleted file mode 100644 index a670582..0000000 --- a/sys/i4b/layer2/i4b_iframe.c +++ /dev/null @@ -1,270 +0,0 @@ -/*- - * Copyright (c) 1997, 2002 Hellmuth Michaelis. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/*--------------------------------------------------------------------------- - * - * i4b_iframe.c - i frame handling routines - * ------------------------------------------ - * last edit-date: [Sat Mar 9 16:07:21 2002] - * - *---------------------------------------------------------------------------*/ - -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - -#include <sys/param.h> -#include <sys/kernel.h> -#include <sys/systm.h> -#include <sys/mbuf.h> -#include <sys/socket.h> -#include <net/if.h> - -#include <i4b/include/i4b_debug.h> -#include <i4b/include/i4b_trace.h> - -#include <i4b/include/i4b_global.h> -#include <i4b/include/i4b_l1l2.h> -#include <i4b/include/i4b_l2l3.h> -#include <i4b/include/i4b_mbuf.h> - -#include <i4b/layer2/i4b_l2.h> -#include <i4b/layer2/i4b_l2fsm.h> - -/*---------------------------------------------------------------------------* - * process i frame - * implements the routine "I COMMAND" Q.921 03/93 pp 68 and pp 77 - *---------------------------------------------------------------------------*/ -void -i4b_rxd_i_frame(int unit, struct mbuf *m) -{ - l2_softc_t *l2sc = &l2_softc[unit]; - u_char *ptr = m->m_data; - int nr; - int ns; - int p; - CRIT_VAR; - - if(!((l2sc->tei_valid == TEI_VALID) && - (l2sc->tei == GETTEI(*(ptr+OFF_TEI))))) - { - i4b_Dfreembuf(m); - return; - } - - if((l2sc->Q921_state != ST_MULTIFR) && (l2sc->Q921_state != ST_TIMREC)) - { - i4b_Dfreembuf(m); - NDBGL2(L2_I_ERR, "ERROR, state != (MF || TR)!"); - return; - } - - CRIT_BEG; - - l2sc->stat.rx_i++; /* update frame count */ - - nr = GETINR(*(ptr + OFF_INR)); - ns = GETINS(*(ptr + OFF_INS)); - p = GETIP(*(ptr + OFF_INR)); - - i4b_rxd_ack(l2sc, nr); /* last packet ack */ - - if(l2sc->own_busy) /* own receiver busy ? */ - { - i4b_Dfreembuf(m); /* yes, discard information */ - - if(p == 1) /* P bit == 1 ? */ - { - i4b_tx_rnr_response(l2sc, p); /* yes, tx RNR */ - l2sc->ack_pend = 0; /* clear ACK pending */ - } - } - else /* own receiver ready */ - { - if(ns == l2sc->vr) /* expected sequence number ? */ - { - M128INC(l2sc->vr); /* yes, update */ - - l2sc->rej_excpt = 0; /* clr reject exception */ - - m_adj(m, I_HDR_LEN); /* strip i frame header */ - - l2sc->iframe_sent = 0; /* reset i acked already */ - - DL_Data_Ind(l2sc->unit, m); /* pass data up */ - - if(!l2sc->iframe_sent) - { - i4b_tx_rr_response(l2sc, p); /* yes, tx RR */ - l2sc->ack_pend = 0; /* clr ACK pending */ - } - } - else /* ERROR, sequence number NOT expected */ - { - i4b_Dfreembuf(m); /* discard information */ - - if(l2sc->rej_excpt == 1) /* already exception ? */ - { - if(p == 1) /* immediate response ? */ - { - i4b_tx_rr_response(l2sc, p); /* yes, tx RR */ - l2sc->ack_pend = 0; /* clr ack pend */ - } - } - else /* not in exception cond */ - { - l2sc->rej_excpt = 1; /* set exception */ - i4b_tx_rej_response(l2sc, p); /* tx REJ */ - l2sc->ack_pend = 0; /* clr ack pending */ - } - } - } - - /* sequence number ranges as expected ? */ - - if(i4b_l2_nr_ok(nr, l2sc->va, l2sc->vs)) - { - if(l2sc->Q921_state == ST_TIMREC) - { - l2sc->va = nr; - - CRIT_END; - - return; - } - - if(l2sc->peer_busy) /* yes, other side busy ? */ - { - l2sc->va = nr; /* yes, update ack count */ - } - else /* other side ready */ - { - if(nr == l2sc->vs) /* count expected ? */ - { - l2sc->va = nr; /* update ack */ - i4b_T200_stop(l2sc); - i4b_T203_restart(l2sc); - } - else - { - if(nr != l2sc->va) - { - l2sc->va = nr; - i4b_T200_restart(l2sc); - } - } - } - } - else - { - i4b_nr_error_recovery(l2sc); /* sequence error */ - l2sc->Q921_state = ST_AW_EST; - } - - CRIT_END; -} - -/*---------------------------------------------------------------------------* - * internal I FRAME QUEUED UP routine (Q.921 03/93 p 61) - *---------------------------------------------------------------------------*/ -void -i4b_i_frame_queued_up(l2_softc_t *l2sc) -{ - struct mbuf *m; - u_char *ptr; - CRIT_VAR; - - CRIT_BEG; - - if((l2sc->peer_busy) || (l2sc->vs == ((l2sc->va + MAX_K_VALUE) & 127))) - { - if(l2sc->peer_busy) - { - NDBGL2(L2_I_MSG, "regen IFQUP, cause: peer busy!"); - } - - if(l2sc->vs == ((l2sc->va + MAX_K_VALUE) & 127)) - { - NDBGL2(L2_I_MSG, "regen IFQUP, cause: vs=va+k!"); - } - - /* - * XXX see: Q.921, page 36, 5.6.1 ".. may retransmit an I - * frame ...", shall we retransmit the last i frame ? - */ - - if(!(IF_QEMPTY(&l2sc->i_queue))) - { - NDBGL2(L2_I_MSG, "re-scheduling IFQU call!"); - START_TIMER(l2sc->IFQU_callout, i4b_i_frame_queued_up, l2sc, IFQU_DLY); - } - CRIT_END; - return; - } - - IF_DEQUEUE(&l2sc->i_queue, m); /* fetch next frame to tx */ - - if(!m) - { - NDBGL2(L2_I_ERR, "ERROR, mbuf NULL after IF_DEQUEUE"); - CRIT_END; - return; - } - - ptr = m->m_data; - - PUTSAPI(SAPI_CCP, CR_CMD_TO_NT, *(ptr + OFF_SAPI)); - PUTTEI(l2sc->tei, *(ptr + OFF_TEI)); - - *(ptr + OFF_INS) = (l2sc->vs << 1) & 0xfe; /* bit 0 = 0 */ - *(ptr + OFF_INR) = (l2sc->vr << 1) & 0xfe; /* P bit = 0 */ - - l2sc->stat.tx_i++; /* update frame counter */ - - PH_Data_Req(l2sc->unit, m, MBUF_DONTFREE); /* free'd when ack'd ! */ - - l2sc->iframe_sent = 1; /* in case we ack an I frame with another I frame */ - - if(l2sc->ua_num != UA_EMPTY) /* failsafe */ - { - NDBGL2(L2_I_ERR, "ERROR, l2sc->ua_num: %d != UA_EMPTY", l2sc->ua_num); - i4b_print_l2var(l2sc); - i4b_Dfreembuf(l2sc->ua_frame); - } - - l2sc->ua_frame = m; /* save unacked frame */ - l2sc->ua_num = l2sc->vs; /* save frame number */ - - M128INC(l2sc->vs); - - l2sc->ack_pend = 0; - - CRIT_END; - - if(l2sc->T200 == TIMER_IDLE) - { - i4b_T203_stop(l2sc); - i4b_T200_start(l2sc); - } -} diff --git a/sys/i4b/layer2/i4b_l2.c b/sys/i4b/layer2/i4b_l2.c deleted file mode 100644 index f752ba6..0000000 --- a/sys/i4b/layer2/i4b_l2.c +++ /dev/null @@ -1,385 +0,0 @@ -/*- - * Copyright (c) 1997, 2002 Hellmuth Michaelis. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/*--------------------------------------------------------------------------- - * - * i4b_l2.c - ISDN layer 2 (Q.921) - * ------------------------------- - * last edit-date: [Sat Mar 9 16:11:14 2002] - * - *---------------------------------------------------------------------------*/ - -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - -#include <sys/param.h> -#include <sys/systm.h> -#include <sys/mbuf.h> -#include <sys/socket.h> -#include <net/if.h> - -#include <i4b/include/i4b_debug.h> - -#include <i4b/include/i4b_l1l2.h> -#include <i4b/include/i4b_l2l3.h> -#include <i4b/include/i4b_mbuf.h> -#include <i4b/include/i4b_global.h> - -#include <i4b/layer2/i4b_l2.h> -#include <i4b/layer2/i4b_l2fsm.h> - -int i4b_dl_establish_ind(int); -int i4b_dl_establish_cnf(int); -int i4b_dl_release_ind(int); -int i4b_dl_release_cnf(int); -int i4b_dl_data_ind(int, struct mbuf *); -int i4b_dl_unit_data_ind(int, struct mbuf *); - -static int i4b_mdl_command_req(int, int, void *); - -/* from layer 2 */ - -extern int i4b_mdl_status_ind(int, int, int); - -/* this layers debug level */ - -unsigned int i4b_l2_debug = L2_DEBUG_DEFAULT; - -struct i4b_l2l3_func i4b_l2l3_func = { - - /* Layer 2 --> Layer 3 */ - - (int (*)(int)) i4b_dl_establish_ind, - (int (*)(int)) i4b_dl_establish_cnf, - (int (*)(int)) i4b_dl_release_ind, - (int (*)(int)) i4b_dl_release_cnf, - (int (*)(int, struct mbuf *)) i4b_dl_data_ind, - (int (*)(int, struct mbuf *)) i4b_dl_unit_data_ind, - - /* Layer 3 --> Layer 2 */ - - (int (*)(int)) i4b_dl_establish_req, - (int (*)(int)) i4b_dl_release_req, - (int (*)(int, struct mbuf *)) i4b_dl_data_req, - (int (*)(int, struct mbuf *)) i4b_dl_unit_data_req, - - /* Layer 2 --> Layer 3 management */ - - (int (*)(int, int, int)) i4b_mdl_status_ind, - - /* Layer 3 --> Layer 2 management */ - - (int (*)(int, int, void *)) i4b_mdl_command_req -}; - -/*---------------------------------------------------------------------------* - * DL_ESTABLISH_REQ from layer 3 - *---------------------------------------------------------------------------*/ -int i4b_dl_establish_req(int unit) -{ - l2_softc_t *l2sc = &l2_softc[unit]; - - NDBGL2(L2_PRIM, "unit %d",unit); - i4b_l1_activate(l2sc); - i4b_next_l2state(l2sc, EV_DLESTRQ); - return(0); -} - -/*---------------------------------------------------------------------------* - * DL_RELEASE_REQ from layer 3 - *---------------------------------------------------------------------------*/ -int i4b_dl_release_req(int unit) -{ - l2_softc_t *l2sc = &l2_softc[unit]; - - NDBGL2(L2_PRIM, "unit %d",unit); - i4b_next_l2state(l2sc, EV_DLRELRQ); - return(0); -} - -/*---------------------------------------------------------------------------* - * DL UNIT DATA REQUEST from Layer 3 - *---------------------------------------------------------------------------*/ -int i4b_dl_unit_data_req(int unit, struct mbuf *m) -{ -#ifdef NOTDEF - NDBGL2(L2_PRIM, "unit %d",unit); -#endif - return(0); -} - -/*---------------------------------------------------------------------------* - * DL DATA REQUEST from Layer 3 - *---------------------------------------------------------------------------*/ -int i4b_dl_data_req(int unit, struct mbuf *m) -{ - l2_softc_t *l2sc = &l2_softc[unit]; - -#ifdef NOTDEF - NDBGL2(L2_PRIM, "unit %d",unit); -#endif - switch(l2sc->Q921_state) - { - case ST_AW_EST: - case ST_MULTIFR: - case ST_TIMREC: - - if(_IF_QFULL(&l2sc->i_queue)) - { - NDBGL2(L2_ERROR, "i_queue full!!"); - i4b_Dfreembuf(m); - } - else - { - CRIT_VAR; - - CRIT_BEG; - IF_ENQUEUE(&l2sc->i_queue, m); - CRIT_END; - - i4b_i_frame_queued_up(l2sc); - } - break; - - default: - NDBGL2(L2_ERROR, "unit %d ERROR in state [%s], freeing mbuf", unit, i4b_print_l2state(l2sc)); - i4b_Dfreembuf(m); - break; - } - return(0); -} - -/*---------------------------------------------------------------------------* - * i4b_ph_activate_ind - link activation indication from layer 1 - *---------------------------------------------------------------------------*/ -int -i4b_ph_activate_ind(int unit) -{ - l2_softc_t *l2sc = &l2_softc[unit]; - - NDBGL1(L1_PRIM, "unit %d",unit); - l2sc->ph_active = PH_ACTIVE; - return(0); -} - -/*---------------------------------------------------------------------------* - * i4b_ph_deactivate_ind - link deactivation indication from layer 1 - *---------------------------------------------------------------------------*/ -int -i4b_ph_deactivate_ind(int unit) -{ - l2_softc_t *l2sc = &l2_softc[unit]; - - NDBGL1(L1_PRIM, "unit %d",unit); - l2sc->ph_active = PH_INACTIVE; - return(0); -} - - -/*---------------------------------------------------------------------------* - * i4b_l2_unit_init - place layer 2 unit into known state - *---------------------------------------------------------------------------*/ -static void -i4b_l2_unit_init(int unit) -{ - l2_softc_t *l2sc = &l2_softc[unit]; - CRIT_VAR; - - CRIT_BEG; - l2sc->Q921_state = ST_TEI_UNAS; - l2sc->tei_valid = TEI_INVALID; - l2sc->vr = 0; - l2sc->vs = 0; - l2sc->va = 0; - l2sc->ack_pend = 0; - l2sc->rej_excpt = 0; - l2sc->peer_busy = 0; - l2sc->own_busy = 0; - l2sc->l3initiated = 0; - - l2sc->rxd_CR = 0; - l2sc->rxd_PF = 0; - l2sc->rxd_NR = 0; - l2sc->RC = 0; - l2sc->iframe_sent = 0; - - l2sc->postfsmfunc = NULL; - - if(l2sc->ua_num != UA_EMPTY) - { - i4b_Dfreembuf(l2sc->ua_frame); - l2sc->ua_num = UA_EMPTY; - l2sc->ua_frame = NULL; - } - - i4b_T200_stop(l2sc); - i4b_T202_stop(l2sc); - i4b_T203_stop(l2sc); - - CRIT_END; -} - -/*---------------------------------------------------------------------------* - * i4b_mph_status_ind - status indication upward - *---------------------------------------------------------------------------*/ -int -i4b_mph_status_ind(int unit, int status, int parm) -{ - l2_softc_t *l2sc = &l2_softc[unit]; - CRIT_VAR; - int sendup = 1; - - CRIT_BEG; - - NDBGL1(L1_PRIM, "unit %d, status=%d, parm=%d", unit, status, parm); - - switch(status) - { - case STI_ATTACH: - l2sc->unit = unit; - l2sc->i_queue.ifq_maxlen = IQUEUE_MAXLEN; - - if(!mtx_initialized(&l2sc->i_queue.ifq_mtx)) - mtx_init(&l2sc->i_queue.ifq_mtx, "i4b_l2sc", NULL, MTX_DEF); - - l2sc->ua_frame = NULL; - bzero(&l2sc->stat, sizeof(lapdstat_t)); - i4b_l2_unit_init(unit); - - /* initialize the callout handles for timeout routines */ - callout_handle_init(&l2sc->T200_callout); - callout_handle_init(&l2sc->T202_callout); - callout_handle_init(&l2sc->T203_callout); - callout_handle_init(&l2sc->IFQU_callout); - break; - - case STI_L1STAT: /* state of layer 1 */ - break; - - case STI_PDEACT: /* Timer 4 expired */ -/*XXX*/ if((l2sc->Q921_state >= ST_AW_EST) && - (l2sc->Q921_state <= ST_TIMREC)) - { - NDBGL2(L2_ERROR, "unit %d, persistent deactivation!", unit); - i4b_l2_unit_init(unit); - } - else - { - sendup = 0; - } - break; - - case STI_NOL1ACC: - i4b_l2_unit_init(unit); - NDBGL2(L2_ERROR, "unit %d, cannot access S0 bus!", unit); - break; - - default: - NDBGL2(L2_ERROR, "ERROR, unit %d, unknown status message!", unit); - break; - } - - if(sendup) - MDL_Status_Ind(unit, status, parm); /* send up to layer 3 */ - - CRIT_END; - - return(0); -} - -/*---------------------------------------------------------------------------* - * MDL_COMMAND_REQ from layer 3 - *---------------------------------------------------------------------------*/ -static int -i4b_mdl_command_req(int unit, int command, void * parm) -{ - NDBGL2(L2_PRIM, "unit %d, command=%d, parm=%d", unit, command, (unsigned int)parm); - - switch(command) - { - case CMR_DOPEN: - i4b_l2_unit_init(unit); - break; - } - - MPH_Command_Req(unit, command, parm); - - return(0); -} - -/*---------------------------------------------------------------------------* - * i4b_ph_data_ind - process a rx'd frame got from layer 1 - *---------------------------------------------------------------------------*/ -int -i4b_ph_data_ind(int unit, struct mbuf *m) -{ - l2_softc_t *l2sc = &l2_softc[unit]; -#ifdef NOTDEF - NDBGL1(L1_PRIM, "unit %d", unit); -#endif - u_char *ptr = m->m_data; - - if ( (*(ptr + OFF_CNTL) & 0x01) == 0 ) - { - if(m->m_len < 4) /* 6 oct - 2 chksum oct */ - { - l2sc->stat.err_rx_len++; - NDBGL2(L2_ERROR, "ERROR, I-frame < 6 octetts!"); - i4b_Dfreembuf(m); - return(0); - } - i4b_rxd_i_frame(unit, m); - } - else if ( (*(ptr + OFF_CNTL) & 0x03) == 0x01 ) - { - if(m->m_len < 4) /* 6 oct - 2 chksum oct */ - { - l2sc->stat.err_rx_len++; - NDBGL2(L2_ERROR, "ERROR, S-frame < 6 octetts!"); - i4b_Dfreembuf(m); - return(0); - } - i4b_rxd_s_frame(unit, m); - } - else if ( (*(ptr + OFF_CNTL) & 0x03) == 0x03 ) - { - if(m->m_len < 3) /* 5 oct - 2 chksum oct */ - { - l2sc->stat.err_rx_len++; - NDBGL2(L2_ERROR, "ERROR, U-frame < 5 octetts!"); - i4b_Dfreembuf(m); - return(0); - } - i4b_rxd_u_frame(unit, m); - } - else - { - l2sc->stat.err_rx_badf++; - NDBGL2(L2_ERROR, "ERROR, bad frame rx'd - "); - i4b_print_frame(m->m_len, m->m_data); - i4b_Dfreembuf(m); - } - return(0); -} diff --git a/sys/i4b/layer2/i4b_l2.h b/sys/i4b/layer2/i4b_l2.h deleted file mode 100644 index cb44c93..0000000 --- a/sys/i4b/layer2/i4b_l2.h +++ /dev/null @@ -1,351 +0,0 @@ -/*- - * Copyright (c) 1997, 2002 Hellmuth Michaelis. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/*--------------------------------------------------------------------------- - * - * i4b_l2.h - ISDN layer 2 (Q.921) definitions - * --------------------------------------------- - * - * $FreeBSD$ - * - * last edit-date: [Sat Mar 9 16:12:20 2002] - * - *---------------------------------------------------------------------------*/ - -#ifndef _I4B_L2_H_ -#define _I4B_L2_H_ - -typedef struct { - int unit; /* unit number this entry is for */ - - int Q921_state; /* state according to Q.921 */ - - u_char last_ril; /* last reference number from TEI management */ - u_char last_rih; - - int tei_valid; /* tei is valid flag */ -#define TEI_INVALID 0 -#define TEI_VALID 1 - int tei; /* tei, if tei flag valid */ - - int ph_active; /* Layer 1 active flag */ -#define PH_INACTIVE 0 /* layer 1 inactive */ -#define PH_ACTIVEPEND 1 /* already tried to activate */ -#define PH_ACTIVE 2 /* layer 1 active */ - - int T200; /* Multiframe timeout timer */ - int T201; /* min time between TEI ID check */ - int T202; /* min time between TEI ID Req messages */ - int N202; /* TEI ID Req tx counter */ - void(*T202func)(void *);/* function to be called when T202 expires */ - int T203; /* max line idle time */ - - struct callout_handle T200_callout; - struct callout_handle T202_callout; - struct callout_handle T203_callout; - struct callout_handle IFQU_callout; - -/* - * i4b_iframe.c, i4b_i_frame_queued_up(): value of IFQU_DLY - * some experimentation Gary did showed a minimal value of (hz/20) was - * possible to let this work, Gary suggested using (hz/10) but i settled - * down to using (hz/5) for now (-hm). - */ -#define IFQU_DLY (hz/5) /* reschedule I-FRAME-QUEUED-UP 0.2 sec */ - - int vr; /* receive sequence frame counter */ - int vs; /* transmit sequence frame counter */ - int va; /* acknowledge sequence frame counter */ - - int ack_pend; /* acknowledge pending */ - int rej_excpt; /* reject exception */ - int peer_busy; /* peer receiver busy */ - int own_busy; /* own receiver busy */ - int l3initiated; /* layer 3 initiated */ - - struct ifqueue i_queue; /* queue of outgoing i frames */ -#define IQUEUE_MAXLEN 20 - - /* this implementation only supports a k-value of 1 !!! */ - struct mbuf *ua_frame; /* last unacked frame */ - int ua_num; /* last unacked frame number */ -#define UA_EMPTY (-1) /* ua_frame is unused */ - - int rxd_CR; /* received Command Response bit */ - int rxd_PF; /* received Poll/Final bit */ - int rxd_NR; /* received N(R) field */ - int RC; /* Retry Counter */ - - int iframe_sent; /* check if i frame acked by another i frame */ - - int (*postfsmfunc)(int);/* function to be called at fsm exit */ - int postfsmarg; /* argument for above function */ - - /* statistics */ - - lapdstat_t stat; /* lapd protocol statistics */ - -} l2_softc_t; - -extern l2_softc_t l2_softc[]; - -/* Q.912 system parameters (Q.921 03/93 pp 43) */ - -#define MAX_K_VALUE 1 /* BRI - # of outstanding frames */ - -#define N200 3 /* max no of retransmissions */ -#define N201DEF 260 /* max no of octetts in information field */ -#define N202DEF 3 /* max no of TEI ID Request message transmissions */ - -#define T200DEF (hz*1) /* default T200 timer value = 1 second */ -#define T201DEF T200DEF /* default T201 timer value = T200DEF */ -#define T202DEF (hz*2) /* default T202 timer value = 2 seconds */ -#define T203DEF (hz*10) /* default T203 timer value = 10 seconds*/ - -/* modulo 128 operations */ - -#define M128INC(v) (v)++; \ - if((v)>127) \ - { \ - v = 0; \ - } - -#define M128DEC(v) (v)--; \ - if((v)<0) \ - { \ - v = 127;\ - } - -/* P-bit values */ - -typedef enum { - P0, - P1 -} pbit_t; - -/* F-bit values */ - -typedef enum { - F0, - F1 -} fbit_t; - -/* CR-bit values to NT */ - -typedef enum { - CR_CMD_TO_NT, - CR_RSP_TO_NT -} crbit_to_nt_t; - -/* CR-bit values from NT */ - -typedef enum { - CR_RSP_FROM_NT, - CR_CMD_FROM_NT -} crbit_from_nt_t; - -/* address field - octett 2 */ - -#define OFF_SAPI 0 /* SAPI offset, HDLC flag is eaten by L1 */ -#define SAPI_CCP 0 /* SAPI = 0 - call control procedures */ -#define SAPI_X25 16 /* SAPI = 16 - X.25 packet procedures */ -#define SAPI_L2M 63 /* SAPI = 63 - Layer 2 management procedures */ - -/* extract and insert macros for SAPI octett */ - -#define GETSAPI(octett) (((octett) >> 2) & 0x3f) -#define PUTSAPI(sapi,cr,octett) ((octett) = (((sapi << 2) & 0xfc) | ((cr & 0x01) << 1))) -#define GETCR(octett) (((octett) >> 1) & 0x01) -#define GETEA(octett) ((octett) & 0x01) - -/* address field - octett 3 */ - -#define OFF_TEI 1 /* TEI offset */ -#define GETTEI(octett) (((octett) >> 1) & 0x7f) -#define PUTTEI(tei, octett) ((octett) = ((((tei) << 1) & 0xfe)) | 0x01) -#define GROUP_TEI 127 /* broadcast TEI for LME */ - -/* control field - octett 4 */ - -#define OFF_CNTL 2 /* 1st byte of control field */ - -/* S frames */ - -#define S_FRAME_LEN 4 /* lenght of a U-frame */ -#define OFF_SRCR 2 /* 1st byte of control field, */ - /* R-commands and R-responses */ -#define OFF_SNR 3 /* 2nd byte of control field, N(R) and PF */ -#define SPFBIT 0x01 /* poll/final bit mask */ -#define SPBITSET SPFBIT -#define SFBITSET SPFBIT -#define GETSNR(octett) (((octett) >> 1) & 0x7f) -#define GETSPF(octett) ((octett) & SPFBIT) -#define RR 0x01 /* RR and bit 0 set */ -#define RNR 0x05 /* RNR and bit 0 set */ -#define REJ 0x09 /* REJ and bit 0 set */ - -/* U frames */ - -#define UI_HDR_LEN 3 /* length of UI header in front of L3 frame */ -#define U_FRAME_LEN 3 /* lenght of a U-frame */ -#define UPFBIT 0x10 /* poll/final bit mask */ -#define UPBITSET UPFBIT -#define UFBITSET UPFBIT -#define GETUPF(octett) (((octett) >> 4) & 0x01) - -/* commands/responses with pf bit set to 0 */ - -#define SABME 0x6f -#define DM 0x0f -#define UI 0x03 -#define DISC 0x43 -#define UA 0x63 -#define FRMR 0x87 -#define XID 0xaf - -/* control field - octett 3 */ - -#define OFF_MEI 3 /* 2nd byte of control field */ - -/* control field - octett 4,5 */ - -#define OFF_RIL 4 /* Ri low byte */ -#define OFF_RIH 5 /* Ri high byte */ - -/* control field - octett 6 */ - -#define OFF_MT 6 /* Message Type */ -#define OFF_AI 7 /* Action Indicator */ -#define GET_TEIFROMAI(octett) (((octett) >> 1) & 0x7f) - -/* I frame */ - -#define I_HDR_LEN 4 /* length of I header in front of L3 frame */ -#define OFF_INS 2 /* transmit sequence number */ -#define OFF_INR 3 /* receive sequence number */ -#define IPFBIT 0x01 /* poll/final bit mask */ -#define IPBITSET 0x01 -#define GETINR(octett) (((octett) >> 1) & 0x7f) -#define GETINS(octett) (((octett) >> 1) & 0x7f) -#define GETIP(octett) ((octett) & IPFBIT) - -/* structure of a TEI management frame */ - -#define TEI_MGMT_FRM_LEN 8 /* frame length */ -#define TEIM_SAPIO 0x00 /* SAPI, CR, EA */ -#define TEIM_TEIO 0x01 /* TEI, EA */ -#define TEIM_UIO 0x02 /* frame type = UI = 0x03 */ -#define TEIM_MEIO 0x03 /* management entity id = 0x0f */ -#define MEI 0x0f -#define TEIM_RILO 0x04 /* reference number, low */ -#define TEIM_RIHO 0x05 /* reference number, high */ -#define TEIM_MTO 0x06 /* message type */ -#define MT_ID_REQEST 0x01 -#define MT_ID_ASSIGN 0x02 -#define MT_ID_DENY 0x03 -#define MT_ID_CHK_REQ 0x04 -#define MT_ID_CHK_RSP 0x05 -#define MT_ID_REMOVE 0x06 -#define MT_ID_VERIFY 0x07 -#define TEIM_AIO 0x07 /* action indicator */ - -/* i4b_mdl_error_ind codes */ - -enum MDL_ERROR_CODES { - MDL_ERR_A, - MDL_ERR_B, - MDL_ERR_C, - MDL_ERR_D, - MDL_ERR_E, - MDL_ERR_F, - MDL_ERR_G, - MDL_ERR_H, - MDL_ERR_I, - MDL_ERR_J, - MDL_ERR_K, - MDL_ERR_L, - MDL_ERR_M, - MDL_ERR_N, - MDL_ERR_O, - MDL_ERR_MAX -}; - -/* forward decl */ - -extern void i4b_acknowledge_pending ( l2_softc_t *l2sc ); -extern struct mbuf * i4b_build_s_frame ( l2_softc_t *l2sc, crbit_to_nt_t crbit, pbit_t pbit, u_char type ); -extern struct mbuf * i4b_build_u_frame ( l2_softc_t *l2sc, crbit_to_nt_t crbit, pbit_t pbit, u_char type ); -extern void i4b_clear_exception_conditions ( l2_softc_t *l2sc ); -extern int i4b_dl_data_req ( int unit, struct mbuf *m ); -extern int i4b_dl_establish_req ( int unit ); -extern int i4b_dl_release_req ( int unit ); -extern int i4b_dl_unit_data_req ( int unit, struct mbuf *m ); -extern void i4b_enquiry_response ( l2_softc_t *l2sc ); -extern void i4b_establish_data_link ( l2_softc_t *l2sc ); -extern void i4b_invoke_retransmission ( l2_softc_t *l2sc, int nr ); -extern void i4b_i_frame_queued_up ( l2_softc_t *l2sc ); -extern void i4b_l1_activate ( l2_softc_t *l2sc ); -extern int i4b_l2_nr_ok ( int nr, int va, int vs ); -extern void i4b_make_rand_ri ( l2_softc_t *l2sc ); -extern void i4b_mdl_assign_ind ( l2_softc_t *l2sc ); -extern void i4b_mdl_error_ind ( l2_softc_t *l2sc, char *where, int errorcode ); -extern int i4b_mph_status_ind ( int unit, int status, int parm ); -extern void i4b_next_l2state ( l2_softc_t *l2sc, int event ); -extern void i4b_nr_error_recovery ( l2_softc_t *l2sc ); -extern int i4b_ph_activate_ind ( int unit ); -extern int i4b_ph_deactivate_ind ( int unit ); -extern int i4b_ph_data_ind ( int unit, struct mbuf *m ); -extern void i4b_print_frame ( int len, u_char *buf ); -extern char *i4b_print_l2state ( l2_softc_t *l2sc ); -extern void i4b_print_l2var ( l2_softc_t *l2sc ); -extern void i4b_rxd_ack(l2_softc_t *l2sc, int nr); -extern void i4b_rxd_i_frame ( int unit, struct mbuf *m ); -extern void i4b_rxd_s_frame ( int unit, struct mbuf *m ); -extern void i4b_rxd_u_frame ( int unit, struct mbuf *m ); -extern void i4b_T200_restart ( l2_softc_t *l2sc ); -extern void i4b_T200_start ( l2_softc_t *l2sc ); -extern void i4b_T200_stop ( l2_softc_t *l2sc ); -extern void i4b_T202_start ( l2_softc_t *l2sc ); -extern void i4b_T202_stop ( l2_softc_t *l2sc ); -extern void i4b_T203_restart ( l2_softc_t *l2sc ); -extern void i4b_T203_start ( l2_softc_t *l2sc ); -extern void i4b_T203_stop ( l2_softc_t *l2sc ); -extern void i4b_tei_assign ( l2_softc_t *l2sc ); -extern void i4b_tei_chkresp ( l2_softc_t *l2sc ); -extern void i4b_tei_rxframe ( int unit, struct mbuf *m ); -extern void i4b_tei_verify ( l2_softc_t *l2sc ); -extern void i4b_transmit_enquire ( l2_softc_t *l2sc ); -extern void i4b_tx_disc ( l2_softc_t *l2sc, pbit_t pbit ); -extern void i4b_tx_dm ( l2_softc_t *l2sc, fbit_t fbit ); -extern void i4b_tx_frmr ( l2_softc_t *l2sc, fbit_t fbit ); -extern void i4b_tx_rej_response ( l2_softc_t *l2sc, fbit_t fbit ); -extern void i4b_tx_rnr_command ( l2_softc_t *l2sc, pbit_t pbit ); -extern void i4b_tx_rnr_response ( l2_softc_t *l2sc, fbit_t fbit ); -extern void i4b_tx_rr_command ( l2_softc_t *l2sc, pbit_t pbit ); -extern void i4b_tx_rr_response ( l2_softc_t *l2sc, fbit_t fbit ); -extern void i4b_tx_sabme ( l2_softc_t *l2sc, pbit_t pbit ); -extern void i4b_tx_ua ( l2_softc_t *l2sc, fbit_t fbit ); - -#endif /* _I4B_L2_H_ */ diff --git a/sys/i4b/layer2/i4b_l2fsm.c b/sys/i4b/layer2/i4b_l2fsm.c deleted file mode 100644 index 8e2721b..0000000 --- a/sys/i4b/layer2/i4b_l2fsm.c +++ /dev/null @@ -1,1578 +0,0 @@ -/*- - * Copyright (c) 1997, 2002 Hellmuth Michaelis. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/*--------------------------------------------------------------------------- - * - * i4b_l2fsm.c - layer 2 FSM - * ------------------------- - * last edit-date: [Sat Mar 9 16:14:07 2002] - * - *---------------------------------------------------------------------------*/ - -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - -#include <sys/param.h> -#include <sys/systm.h> -#include <sys/socket.h> -#include <net/if.h> - -#include <i4b/include/i4b_debug.h> -#include <i4b/include/i4b_ioctl.h> - -#include <i4b/include/i4b_global.h> -#include <i4b/include/i4b_l2l3.h> -#include <i4b/include/i4b_mbuf.h> - -#include <i4b/layer2/i4b_l2.h> -#include <i4b/layer2/i4b_l2fsm.h> - -l2_softc_t l2_softc[MAXL1UNITS]; - -#if DO_I4B_DEBUG -static char *l2state_text[N_STATES] = { - "ST_TEI_UNAS", - "ST_ASG_AW_TEI", - "ST_EST_AW_TEI", - "ST_TEI_ASGD", - - "ST_AW_EST", - "ST_AW_REL", - "ST_MULTIFR", - "ST_TIMREC", - - "ST_SUBSET", - "Illegal State" -}; - -static char *l2event_text[N_EVENTS] = { - "EV_DLESTRQ", - "EV_DLUDTRQ", - "EV_MDASGRQ", - "EV_MDERRRS", - "EV_PSDEACT", - "EV_MDREMRQ", - "EV_RXSABME", - "EV_RXDISC", - "EV_RXUA", - "EV_RXDM", - "EV_T200EXP", - "EV_DLDATRQ", - "EV_DLRELRQ", - "EV_T203EXP", - "EV_OWNBUSY", - "EV_OWNRDY", - "EV_RXRR", - "EV_RXREJ", - "EV_RXRNR", - "EV_RXFRMR", - "Illegal Event" -}; -#endif - -static void F_TU01(l2_softc_t *); -static void F_TU03(l2_softc_t *); - -static void F_TA03(l2_softc_t *); -static void F_TA04(l2_softc_t *); -static void F_TA05(l2_softc_t *); - -static void F_TE03(l2_softc_t *); -static void F_TE04(l2_softc_t *); -static void F_TE05(l2_softc_t *); - -static void F_T01(l2_softc_t *); -static void F_T05(l2_softc_t *); -static void F_T06(l2_softc_t *); -static void F_T07(l2_softc_t *); -static void F_T08(l2_softc_t *); -static void F_T09(l2_softc_t *); -static void F_T10(l2_softc_t *); -static void F_T13(l2_softc_t *); - -static void F_AE01(l2_softc_t *); -static void F_AE05(l2_softc_t *); -static void F_AE06(l2_softc_t *); -static void F_AE07(l2_softc_t *); -static void F_AE08(l2_softc_t *); -static void F_AE09(l2_softc_t *); -static void F_AE10(l2_softc_t *); -static void F_AE11(l2_softc_t *); -static void F_AE12(l2_softc_t *); - -static void F_AR05(l2_softc_t *); -static void F_AR06(l2_softc_t *); -static void F_AR07(l2_softc_t *); -static void F_AR08(l2_softc_t *); -static void F_AR09(l2_softc_t *); -static void F_AR10(l2_softc_t *); -static void F_AR11(l2_softc_t *); - -static void F_MF01(l2_softc_t *); -static void F_MF05(l2_softc_t *); -static void F_MF06(l2_softc_t *); -static void F_MF07(l2_softc_t *); -static void F_MF08(l2_softc_t *); -static void F_MF09(l2_softc_t *); -static void F_MF10(l2_softc_t *); -static void F_MF11(l2_softc_t *); -static void F_MF12(l2_softc_t *); -static void F_MF13(l2_softc_t *); -static void F_MF14(l2_softc_t *); -static void F_MF15(l2_softc_t *); -static void F_MF16(l2_softc_t *); -static void F_MF17(l2_softc_t *); -static void F_MF18(l2_softc_t *); -static void F_MF19(l2_softc_t *); -static void F_MF20(l2_softc_t *); - -static void F_TR01(l2_softc_t *); -static void F_TR05(l2_softc_t *); -static void F_TR06(l2_softc_t *); -static void F_TR07(l2_softc_t *); -static void F_TR08(l2_softc_t *); -static void F_TR09(l2_softc_t *); -static void F_TR10(l2_softc_t *); -static void F_TR11(l2_softc_t *); -static void F_TR12(l2_softc_t *); -static void F_TR13(l2_softc_t *); -static void F_TR15(l2_softc_t *); -static void F_TR16(l2_softc_t *); -static void F_TR17(l2_softc_t *); -static void F_TR18(l2_softc_t *); -static void F_TR19(l2_softc_t *); -static void F_TR20(l2_softc_t *); -static void F_ILL(l2_softc_t *); -static void F_NCNA(l2_softc_t *); - -/*---------------------------------------------------------------------------* - * FSM illegal state default action - *---------------------------------------------------------------------------*/ -static void -F_ILL(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_ERR, "FSM function F_ILL executing"); -} - -/*---------------------------------------------------------------------------* - * FSM No change, No action - *---------------------------------------------------------------------------*/ -static void -F_NCNA(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_NCNA executing"); -} - -/*---------------------------------------------------------------------------* - * layer 2 state transition table - *---------------------------------------------------------------------------*/ -struct l2state_tab { - void (*func)(l2_softc_t *); /* function to execute */ - int newstate; /* next state */ -} l2state_tab[N_EVENTS][N_STATES] = { - -/* STATE: ST_TEI_UNAS, ST_ASG_AW_TEI, ST_EST_AW_TEI, ST_TEI_ASGD, ST_AW_EST, ST_AW_REL, ST_MULTIFR, ST_TIMREC, ST_SUBSET, ILLEGAL STATE */ -/* -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ -/*EV_DLESTRQ*/{ {F_TU01, ST_EST_AW_TEI}, {F_NCNA, ST_EST_AW_TEI}, {F_ILL, ST_ILL}, {F_T01, ST_AW_EST}, {F_AE01, ST_AW_EST}, {F_ILL, ST_ILL}, {F_MF01, ST_AW_EST}, {F_TR01, ST_AW_EST}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL} }, -/*EV_DLUDTRQ*/{ {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL} }, -/*EV_MDASGRQ*/{ {F_TU03, ST_TEI_ASGD}, {F_TA03, ST_TEI_ASGD}, {F_TE03, ST_AW_EST}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL} }, -/*EV_MDERRRS*/{ {F_ILL, ST_ILL}, {F_TA04, ST_TEI_UNAS}, {F_TE04, ST_TEI_UNAS}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL} }, -/*EV_PSDEACT*/{ {F_ILL, ST_ILL}, {F_TA05, ST_TEI_UNAS}, {F_TE05, ST_TEI_UNAS}, {F_T05, ST_TEI_ASGD}, {F_AE05, ST_TEI_ASGD}, {F_AR05, ST_TEI_ASGD}, {F_MF05, ST_TEI_ASGD}, {F_TR05, ST_TEI_ASGD}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL} }, -/*EV_MDREMRQ*/{ {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_T06, ST_TEI_UNAS}, {F_AE06, ST_TEI_UNAS}, {F_AR06, ST_TEI_UNAS}, {F_MF06, ST_TEI_UNAS}, {F_TR06, ST_TEI_UNAS}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL} }, -/*EV_RXSABME*/{ {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_T07, ST_SUBSET}, {F_AE07, ST_AW_EST}, {F_AR07, ST_AW_REL}, {F_MF07, ST_MULTIFR}, {F_TR07, ST_MULTIFR}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL} }, -/*EV_RXDISC */{ {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_T08, ST_TEI_ASGD}, {F_AE08, ST_AW_EST}, {F_AR08, ST_AW_REL}, {F_MF08, ST_TEI_ASGD}, {F_TR08, ST_TEI_ASGD}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL} }, -/*EV_RXUA */{ {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_T09, ST_TEI_ASGD}, {F_AE09, ST_SUBSET}, {F_AR09, ST_SUBSET}, {F_MF09, ST_MULTIFR}, {F_TR09, ST_TIMREC}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL} }, -/*EV_RXDM */{ {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_T10, ST_SUBSET}, {F_AE10, ST_SUBSET}, {F_AR10, ST_SUBSET}, {F_MF10, ST_SUBSET}, {F_TR10, ST_AW_EST}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL} }, -/*EV_T200EXP*/{ {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_AE11, ST_SUBSET}, {F_AR11, ST_SUBSET}, {F_MF11, ST_TIMREC}, {F_TR11, ST_SUBSET}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL} }, -/*EV_DLDATRQ*/{ {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_AE12, ST_AW_EST}, {F_ILL, ST_ILL}, {F_MF12, ST_MULTIFR}, {F_TR12, ST_TIMREC}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL} }, -/*EV_DLRELRQ*/{ {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_T13, ST_TEI_ASGD}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_MF13, ST_AW_REL}, {F_TR13, ST_AW_REL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL} }, -/*EV_T203EXP*/{ {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_MF14, ST_TIMREC}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL} }, -/*EV_OWNBUSY*/{ {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_MF15, ST_MULTIFR}, {F_TR15, ST_TIMREC}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL} }, -/*EV_OWNRDY */{ {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_MF16, ST_MULTIFR}, {F_TR16, ST_TIMREC}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL} }, -/*EV_RXRR */{ {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_MF17, ST_SUBSET}, {F_TR17, ST_SUBSET}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL} }, -/*EV_RXREJ */{ {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_MF18, ST_SUBSET}, {F_TR18, ST_SUBSET}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL} }, -/*EV_RXRNR */{ {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_MF19, ST_SUBSET}, {F_TR19, ST_SUBSET}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL} }, -/*EV_RXFRMR */{ {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_MF20, ST_AW_EST}, {F_TR20, ST_AW_EST}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL} }, -/*EV_ILL */{ {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL}, {F_ILL, ST_ILL} } -}; - -/*---------------------------------------------------------------------------* - * event handler, executes function and sets new state - *---------------------------------------------------------------------------*/ -void i4b_next_l2state(l2_softc_t *l2sc, int event) -{ - int currstate, newstate; - int (*savpostfsmfunc)(int) = NULL; - - /* check event number */ - if(event >= N_EVENTS) - panic("i4b_l2fsm.c: event >= N_EVENTS\n"); - - /* get current state and check it */ - if((currstate = l2sc->Q921_state) >= N_STATES) /* failsafe */ - panic("i4b_l2fsm.c: currstate >= N_STATES\n"); - - /* get new state and check it */ - if((newstate = l2state_tab[event][currstate].newstate) >= N_STATES) - panic("i4b_l2fsm.c: newstate >= N_STATES\n"); - - - if(newstate != ST_SUBSET) - { /* state function does NOT set new state */ - NDBGL2(L2_F_MSG, "FSM event [%s]: [%s/%d => %s/%d]", - l2event_text[event], - l2state_text[currstate], currstate, - l2state_text[newstate], newstate); - } - - /* execute state transition function */ - (*l2state_tab[event][currstate].func)(l2sc); - - if(newstate == ST_SUBSET) - { /* state function DOES set new state */ - NDBGL2(L2_F_MSG, "FSM S-event [%s]: [%s => %s]", l2event_text[event], - l2state_text[currstate], - l2state_text[l2sc->Q921_state]); - } - - /* check for illegal new state */ - - if(newstate == ST_ILL) - { - newstate = currstate; - NDBGL2(L2_F_ERR, "FSM illegal state, state = %s, event = %s!", - l2state_text[currstate], - l2event_text[event]); - } - - /* check if state machine function has to set new state */ - - if(newstate != ST_SUBSET) - l2sc->Q921_state = newstate; /* no, we set new state */ - - if(l2sc->postfsmfunc != NULL) - { - NDBGL2(L2_F_MSG, "FSM executing postfsmfunc!"); - /* try to avoid an endless loop */ - savpostfsmfunc = l2sc->postfsmfunc; - l2sc->postfsmfunc = NULL; - (*savpostfsmfunc)(l2sc->postfsmarg); - } -} - -#if DO_I4B_DEBUG -/*---------------------------------------------------------------------------* - * return pointer to current state description - *---------------------------------------------------------------------------*/ -char *i4b_print_l2state(l2_softc_t *l2sc) -{ - return((char *) l2state_text[l2sc->Q921_state]); -} -#endif - -/*---------------------------------------------------------------------------* - * FSM state ST_TEI_UNAS event dl establish request - *---------------------------------------------------------------------------*/ -static void -F_TU01(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_TU01 executing"); - i4b_mdl_assign_ind(l2sc); -} - -/*---------------------------------------------------------------------------* - * FSM state ST_TEI_UNAS event mdl assign request - *---------------------------------------------------------------------------*/ -static void -F_TU03(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_TU03 executing"); -} - -/*---------------------------------------------------------------------------* - * FSM state ST_ASG_AW_TEI event mdl assign request - *---------------------------------------------------------------------------*/ -static void -F_TA03(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_TA03 executing"); -} - -/*---------------------------------------------------------------------------* - * FSM state ST_ASG_AW_TEI event mdl error response - *---------------------------------------------------------------------------*/ -static void -F_TA04(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_TA04 executing"); -} - -/*---------------------------------------------------------------------------* - * FSM state ST_ASG_AW_TEI event persistent deactivation - *---------------------------------------------------------------------------*/ -static void -F_TA05(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_TA05 executing"); -} - -/*---------------------------------------------------------------------------* - * FSM state ST_EST_AW_TEI event mdl assign request - *---------------------------------------------------------------------------*/ -static void -F_TE03(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_TE03 executing"); - i4b_establish_data_link(l2sc); - l2sc->l3initiated = 1; -} - -/*---------------------------------------------------------------------------* - * FSM state ST_EST_AW_TEI event mdl error response - *---------------------------------------------------------------------------*/ -static void -F_TE04(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_TE04 executing"); - l2sc->postfsmarg = l2sc->unit; - l2sc->postfsmfunc = DL_Rel_Ind_A; -} - -/*---------------------------------------------------------------------------* - * FSM state ST_EST_AW_TEI event persistent deactivation - *---------------------------------------------------------------------------*/ -static void -F_TE05(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_TE05 executing"); - l2sc->postfsmarg = l2sc->unit; - l2sc->postfsmfunc = DL_Rel_Ind_A; -} - -/*---------------------------------------------------------------------------* - * FSM state ST_TEI_ASGD event dl establish request - *---------------------------------------------------------------------------*/ -static void -F_T01(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_T01 executing"); - i4b_establish_data_link(l2sc); - l2sc->l3initiated = 1; -} - -/*---------------------------------------------------------------------------* - * FSM state ST_TEI_ASGD event persistent deactivation - *---------------------------------------------------------------------------*/ -static void -F_T05(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_T05 executing"); -} - -/*---------------------------------------------------------------------------* - * FSM state ST_TEI_ASGD event mdl remove request - *---------------------------------------------------------------------------*/ -static void -F_T06(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_T06 executing"); -/*XXX*/ i4b_mdl_assign_ind(l2sc); -} - -/*---------------------------------------------------------------------------* - * FSM state ST_TEI_ASGD event rx'd SABME - *---------------------------------------------------------------------------*/ -static void -F_T07(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_T07 executing"); - -/* XXX */ -#ifdef NOTDEF - if(NOT able to establish) - { - i4b_tx_dm(l2sc, l2sc->rxd_PF); - l2sc->Q921_state = ST_TEI_ASGD; - return; - } -#endif - - i4b_clear_exception_conditions(l2sc); - - MDL_Status_Ind(l2sc->unit, STI_L2STAT, LAYER_ACTIVE); - - i4b_tx_ua(l2sc, l2sc->rxd_PF); - - l2sc->vs = 0; - l2sc->va = 0; - l2sc->vr = 0; - - l2sc->postfsmarg = l2sc->unit; - l2sc->postfsmfunc = DL_Est_Ind_A; - - i4b_T203_start(l2sc); - - l2sc->Q921_state = ST_MULTIFR; -} - -/*---------------------------------------------------------------------------* - * FSM state ST_TEI_ASGD event rx'd DISC - *---------------------------------------------------------------------------*/ -static void -F_T08(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_T08 executing"); - MDL_Status_Ind(l2sc->unit, STI_L2STAT, LAYER_IDLE); - i4b_tx_ua(l2sc, l2sc->rxd_PF); -} - -/*---------------------------------------------------------------------------* - * FSM state ST_TEI_ASGD event rx'd UA - *---------------------------------------------------------------------------*/ -static void -F_T09(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_T09 executing"); - i4b_mdl_error_ind(l2sc, "F_T09", MDL_ERR_C); - i4b_mdl_error_ind(l2sc, "F_T09", MDL_ERR_D); -} - -/*---------------------------------------------------------------------------* - * FSM state ST_TEI_ASGD event rx'd DM - *---------------------------------------------------------------------------*/ -static void -F_T10(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_T10 executing"); - - if(l2sc->rxd_PF) - { - l2sc->Q921_state = ST_TEI_ASGD; - } - else - { -#ifdef NOTDEF - if(NOT able_to_etablish) - { - l2sc->Q921_state = ST_TEI_ASGD; - return; - } -#endif - i4b_establish_data_link(l2sc); - - l2sc->l3initiated = 1; - - l2sc->Q921_state = ST_AW_EST; - } -} - -/*---------------------------------------------------------------------------* - * FSM state ST_TEI_ASGD event dl release request - *---------------------------------------------------------------------------*/ -static void -F_T13(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_T13 executing"); - l2sc->postfsmarg = l2sc->unit; - l2sc->postfsmfunc = DL_Rel_Cnf_A; -} - -/*---------------------------------------------------------------------------* - * FSM state ST_AW_EST event dl establish request - *---------------------------------------------------------------------------*/ -static void -F_AE01(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_AE01 executing"); - - i4b_Dcleanifq(&l2sc->i_queue); - - l2sc->l3initiated = 1; -} - -/*---------------------------------------------------------------------------* - * FSM state ST_AW_EST event persistent deactivation - *---------------------------------------------------------------------------*/ -static void -F_AE05(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_AE05 executing"); - - i4b_Dcleanifq(&l2sc->i_queue); - - l2sc->postfsmarg = l2sc->unit; - l2sc->postfsmfunc = DL_Rel_Ind_A; - - i4b_T200_stop(l2sc); -} - -/*---------------------------------------------------------------------------* - * FSM state ST_AW_EST event mdl remove request - *---------------------------------------------------------------------------*/ -static void -F_AE06(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_AE06 executing"); - - i4b_Dcleanifq(&l2sc->i_queue); - - l2sc->postfsmarg = l2sc->unit; - l2sc->postfsmfunc = DL_Rel_Ind_A; - - i4b_T200_stop(l2sc); - -/*XXX*/ i4b_mdl_assign_ind(l2sc); -} - -/*---------------------------------------------------------------------------* - * FSM state ST_AW_EST event rx'd SABME - *---------------------------------------------------------------------------*/ -static void -F_AE07(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_AE07 executing"); - MDL_Status_Ind(l2sc->unit, STI_L2STAT, LAYER_ACTIVE); - i4b_tx_ua(l2sc, l2sc->rxd_PF); -} - -/*---------------------------------------------------------------------------* - * FSM state ST_AW_EST event rx'd DISC - *---------------------------------------------------------------------------*/ -static void -F_AE08(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_AE08 executing"); - i4b_tx_dm(l2sc, l2sc->rxd_PF); -} - -/*---------------------------------------------------------------------------* - * FSM state ST_AW_EST event rx'd UA - *---------------------------------------------------------------------------*/ -static void -F_AE09(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_AE09 executing"); - - if(l2sc->rxd_PF == 0) - { - i4b_mdl_error_ind(l2sc, "F_AE09", MDL_ERR_D); - l2sc->Q921_state = ST_AW_EST; - } - else - { - if(l2sc->l3initiated) - { - l2sc->l3initiated = 0; - l2sc->vr = 0; - l2sc->postfsmarg = l2sc->unit; - l2sc->postfsmfunc = DL_Est_Cnf_A; - } - else - { - if(l2sc->vs != l2sc->va) - { - i4b_Dcleanifq(&l2sc->i_queue); - l2sc->postfsmarg = l2sc->unit; - l2sc->postfsmfunc = DL_Est_Ind_A; - } - } - - MDL_Status_Ind(l2sc->unit, STI_L2STAT, LAYER_ACTIVE); - - i4b_T200_stop(l2sc); - i4b_T203_start(l2sc); - - l2sc->vs = 0; - l2sc->va = 0; - - l2sc->Q921_state = ST_MULTIFR; - } -} - -/*---------------------------------------------------------------------------* - * FSM state ST_AW_EST event rx'd DM - *---------------------------------------------------------------------------*/ -static void -F_AE10(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_AE10 executing"); - - if(l2sc->rxd_PF == 0) - { - l2sc->Q921_state = ST_AW_EST; - } - else - { - i4b_Dcleanifq(&l2sc->i_queue); - - l2sc->postfsmarg = l2sc->unit; - l2sc->postfsmfunc = DL_Rel_Ind_A; - - i4b_T200_stop(l2sc); - - l2sc->Q921_state = ST_TEI_ASGD; - } -} - -/*---------------------------------------------------------------------------* - * FSM state ST_AW_EST event T200 expiry - *---------------------------------------------------------------------------*/ -static void -F_AE11(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_AE11 executing"); - - if(l2sc->RC >= N200) - { - i4b_Dcleanifq(&l2sc->i_queue); - - i4b_mdl_error_ind(l2sc, "F_AE11", MDL_ERR_G); - - l2sc->postfsmarg = l2sc->unit; - l2sc->postfsmfunc = DL_Rel_Ind_A; - - l2sc->Q921_state = ST_TEI_ASGD; - } - else - { - l2sc->RC++; - - i4b_tx_sabme(l2sc, P1); - - i4b_T200_start(l2sc); - - l2sc->Q921_state = ST_AW_EST; - } -} - -/*---------------------------------------------------------------------------* - * FSM state ST_AW_EST event dl data request - *---------------------------------------------------------------------------*/ -static void -F_AE12(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_AE12 executing"); - - if(l2sc->l3initiated == 0) - { - i4b_i_frame_queued_up(l2sc); - } -} - -/*---------------------------------------------------------------------------* - * FSM state ST_AW_REL event persistent deactivation - *---------------------------------------------------------------------------*/ -static void -F_AR05(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_AR05 executing"); - - l2sc->postfsmarg = l2sc->unit; - l2sc->postfsmfunc = DL_Rel_Cnf_A; - - i4b_T200_stop(l2sc); -} - -/*---------------------------------------------------------------------------* - * FSM state ST_AW_REL event mdl remove request - *---------------------------------------------------------------------------*/ -static void -F_AR06(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_AR06 executing"); - - l2sc->postfsmarg = l2sc->unit; - l2sc->postfsmfunc = DL_Rel_Cnf_A; - - i4b_T200_stop(l2sc); - -/*XXX*/ i4b_mdl_assign_ind(l2sc); -} - -/*---------------------------------------------------------------------------* - * FSM state ST_AW_REL event rx'd SABME - *---------------------------------------------------------------------------*/ -static void -F_AR07(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_AR07 executing"); - i4b_tx_dm(l2sc, l2sc->rxd_PF); -} - -/*---------------------------------------------------------------------------* - * FSM state ST_AW_REL event rx'd DISC - *---------------------------------------------------------------------------*/ -static void -F_AR08(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_AR08 executing"); - MDL_Status_Ind(l2sc->unit, STI_L2STAT, LAYER_IDLE); - i4b_tx_ua(l2sc, l2sc->rxd_PF); -} - -/*---------------------------------------------------------------------------* - * FSM state ST_AW_REL event rx'd UA - *---------------------------------------------------------------------------*/ -static void -F_AR09(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_AR09 executing"); - - if(l2sc->rxd_PF) - { - l2sc->postfsmarg = l2sc->unit; - l2sc->postfsmfunc = DL_Rel_Cnf_A; - - i4b_T200_stop(l2sc); - - l2sc->Q921_state = ST_TEI_ASGD; - } - else - { - i4b_mdl_error_ind(l2sc, "F_AR09", MDL_ERR_D); - - l2sc->Q921_state = ST_AW_REL; - } -} - -/*---------------------------------------------------------------------------* - * FSM state ST_AW_REL event rx'd DM - *---------------------------------------------------------------------------*/ -static void -F_AR10(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_AR10 executing"); - - if(l2sc->rxd_PF) - { - l2sc->postfsmarg = l2sc->unit; - l2sc->postfsmfunc = DL_Rel_Cnf_A; - - i4b_T200_stop(l2sc); - - l2sc->Q921_state = ST_TEI_ASGD; - } - else - { - l2sc->Q921_state = ST_AW_REL; - } -} - -/*---------------------------------------------------------------------------* - * FSM state ST_AW_REL event T200 expiry - *---------------------------------------------------------------------------*/ -static void -F_AR11(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_AR11 executing"); - - if(l2sc->RC >= N200) - { - i4b_mdl_error_ind(l2sc, "F_AR11", MDL_ERR_H); - - l2sc->postfsmarg = l2sc->unit; - l2sc->postfsmfunc = DL_Rel_Cnf_A; - - l2sc->Q921_state = ST_TEI_ASGD; - } - else - { - l2sc->RC++; - - i4b_tx_disc(l2sc, P1); - - i4b_T200_start(l2sc); - - l2sc->Q921_state = ST_AW_REL; - } -} - -/*---------------------------------------------------------------------------* - * FSM state ST_MULTIFR event dl establish request - *---------------------------------------------------------------------------*/ -static void -F_MF01(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_MF01 executing"); - - i4b_Dcleanifq(&l2sc->i_queue); - - i4b_establish_data_link(l2sc); - - l2sc->l3initiated = 1; -} - -/*---------------------------------------------------------------------------* - * FSM state ST_MULTIFR event persistent deactivation - *---------------------------------------------------------------------------*/ -static void -F_MF05(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_MF05 executing"); - - i4b_Dcleanifq(&l2sc->i_queue); - - l2sc->postfsmarg = l2sc->unit; - l2sc->postfsmfunc = DL_Rel_Ind_A; - - i4b_T200_stop(l2sc); - i4b_T203_stop(l2sc); -} - -/*---------------------------------------------------------------------------* - * FSM state ST_MULTIFR event mdl remove request - *---------------------------------------------------------------------------*/ -static void -F_MF06(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_MF06 executing"); - - i4b_Dcleanifq(&l2sc->i_queue); - - l2sc->postfsmarg = l2sc->unit; - l2sc->postfsmfunc = DL_Rel_Ind_A; - - i4b_T200_stop(l2sc); - i4b_T203_stop(l2sc); - -/*XXX*/ i4b_mdl_assign_ind(l2sc); -} - -/*---------------------------------------------------------------------------* - * FSM state ST_MULTIFR event rx'd SABME - *---------------------------------------------------------------------------*/ -static void -F_MF07(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_MF07 executing"); - - i4b_clear_exception_conditions(l2sc); - - MDL_Status_Ind(l2sc->unit, STI_L2STAT, LAYER_ACTIVE); - - i4b_tx_ua(l2sc, l2sc->rxd_PF); - - i4b_mdl_error_ind(l2sc, "F_MF07", MDL_ERR_F); - - if(l2sc->vs != l2sc->va) - { - i4b_Dcleanifq(&l2sc->i_queue); - - l2sc->postfsmarg = l2sc->unit; - l2sc->postfsmfunc = DL_Est_Ind_A; - } - - i4b_T200_stop(l2sc); - i4b_T203_start(l2sc); - - l2sc->vs = 0; - l2sc->va = 0; - l2sc->vr = 0; -} - -/*---------------------------------------------------------------------------* - * FSM state ST_MULTIFR event rx'd DISC - *---------------------------------------------------------------------------*/ -static void -F_MF08(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_MF08 executing"); - - i4b_Dcleanifq(&l2sc->i_queue); - MDL_Status_Ind(l2sc->unit, STI_L2STAT, LAYER_IDLE); - i4b_tx_ua(l2sc, l2sc->rxd_PF); - - l2sc->postfsmarg = l2sc->unit; - l2sc->postfsmfunc = DL_Rel_Ind_A; - - i4b_T200_stop(l2sc); - i4b_T203_stop(l2sc); -} - -/*---------------------------------------------------------------------------* - * FSM state ST_MULTIFR event rx'd UA - *---------------------------------------------------------------------------*/ -static void -F_MF09(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_MF09 executing"); - if(l2sc->rxd_PF) - i4b_mdl_error_ind(l2sc, "F_MF09", MDL_ERR_C); - else - i4b_mdl_error_ind(l2sc, "F_MF09", MDL_ERR_D); -} - -/*---------------------------------------------------------------------------* - * FSM state ST_MULTIFR event rx'd DM - *---------------------------------------------------------------------------*/ -static void -F_MF10(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_MF10 executing"); - - if(l2sc->rxd_PF) - { - i4b_mdl_error_ind(l2sc, "F_MF10", MDL_ERR_B); - - l2sc->Q921_state = ST_MULTIFR; - } - else - { - i4b_mdl_error_ind(l2sc, "F_MF10", MDL_ERR_E); - - i4b_establish_data_link(l2sc); - - l2sc->l3initiated = 0; - - l2sc->Q921_state = ST_AW_EST; - } -} - -/*---------------------------------------------------------------------------* - * FSM state ST_MULTIFR event T200 expiry - *---------------------------------------------------------------------------*/ -static void -F_MF11(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_MF11 executing"); - - l2sc->RC = 0; - - i4b_transmit_enquire(l2sc); - - l2sc->RC++; -} - -/*---------------------------------------------------------------------------* - * FSM state ST_MULTIFR event dl data request - *---------------------------------------------------------------------------*/ -static void -F_MF12(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_MF12 executing"); - - i4b_i_frame_queued_up(l2sc); -} - -/*---------------------------------------------------------------------------* - * FSM state ST_MULTIFR event dl release request - *---------------------------------------------------------------------------*/ -static void -F_MF13(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_MF13 executing"); - - i4b_Dcleanifq(&l2sc->i_queue); - - l2sc->RC = 0; - - i4b_tx_disc(l2sc, P1); - - i4b_T203_stop(l2sc); - i4b_T200_restart(l2sc); -} - -/*---------------------------------------------------------------------------* - * FSM state ST_MULTIFR event T203 expiry - *---------------------------------------------------------------------------*/ -static void -F_MF14(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_MF14 executing"); - - i4b_transmit_enquire(l2sc); - - l2sc->RC = 0; -} - -/*---------------------------------------------------------------------------* - * FSM state ST_MULTIFR event set own rx busy - *---------------------------------------------------------------------------*/ -static void -F_MF15(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_MF15 executing"); - - if(l2sc->own_busy == 0) - { - l2sc->own_busy = 1; - - i4b_tx_rnr_response(l2sc, F0); /* wrong in Q.921 03/93 p 64 */ - - l2sc->ack_pend = 0; - } -} - -/*---------------------------------------------------------------------------* - * FSM state ST_MULTIFR event clear own rx busy - *---------------------------------------------------------------------------*/ -static void -F_MF16(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_MF16 executing"); - - if(l2sc->own_busy != 0) - { - l2sc->own_busy = 0; - - i4b_tx_rr_response(l2sc, F0); /* wrong in Q.921 03/93 p 64 */ - - l2sc->ack_pend = 0; - } -} - -/*---------------------------------------------------------------------------* - * FSM state ST_MULTIFR event rx'd RR - *---------------------------------------------------------------------------*/ -static void -F_MF17(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_MF17 executing"); - - l2sc->peer_busy = 0; - - if(l2sc->rxd_CR == CR_CMD_FROM_NT) - { - if(l2sc->rxd_PF == 1) - { - i4b_enquiry_response(l2sc); - } - } - else - { - if(l2sc->rxd_PF == 1) - { - i4b_mdl_error_ind(l2sc, "F_MF17", MDL_ERR_A); - } - } - - if(i4b_l2_nr_ok(l2sc->rxd_NR, l2sc->va, l2sc->vs)) - { - if(l2sc->rxd_NR == l2sc->vs) - { - l2sc->va = l2sc->rxd_NR; - i4b_T200_stop(l2sc); - i4b_T203_restart(l2sc); - } - else if(l2sc->rxd_NR != l2sc->va) - { - l2sc->va = l2sc->rxd_NR; - i4b_T200_restart(l2sc); - } - l2sc->Q921_state = ST_MULTIFR; - } - else - { - i4b_nr_error_recovery(l2sc); - l2sc->Q921_state = ST_AW_EST; - } -} - -/*---------------------------------------------------------------------------* - * FSM state ST_MULTIFR event rx'd REJ - *---------------------------------------------------------------------------*/ -static void -F_MF18(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_MF18 executing"); - - l2sc->peer_busy = 0; - - if(l2sc->rxd_CR == CR_CMD_FROM_NT) - { - if(l2sc->rxd_PF == 1) - { - i4b_enquiry_response(l2sc); - } - } - else - { - if(l2sc->rxd_PF == 1) - { - i4b_mdl_error_ind(l2sc, "F_MF18", MDL_ERR_A); - } - } - - if(i4b_l2_nr_ok(l2sc->rxd_NR, l2sc->va, l2sc->vs)) - { - l2sc->va = l2sc->rxd_NR; - i4b_T200_stop(l2sc); - i4b_T203_start(l2sc); - i4b_invoke_retransmission(l2sc, l2sc->rxd_NR); - l2sc->Q921_state = ST_MULTIFR; - } - else - { - i4b_nr_error_recovery(l2sc); - l2sc->Q921_state = ST_AW_EST; - } -} - -/*---------------------------------------------------------------------------* - * FSM state ST_MULTIFR event rx'd RNR - *---------------------------------------------------------------------------*/ -static void -F_MF19(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_MF19 executing"); - - l2sc->peer_busy = 1; - - if(l2sc->rxd_CR == CR_CMD_FROM_NT) - { - if(l2sc->rxd_PF == 1) - { - i4b_enquiry_response(l2sc); - } - } - else - { - if(l2sc->rxd_PF == 1) - { - i4b_mdl_error_ind(l2sc, "F_MF19", MDL_ERR_A); - } - } - - if(i4b_l2_nr_ok(l2sc->rxd_NR, l2sc->va, l2sc->vs)) - { - l2sc->va = l2sc->rxd_NR; - i4b_T203_stop(l2sc); - i4b_T200_restart(l2sc); - l2sc->Q921_state = ST_MULTIFR; - } - else - { - i4b_nr_error_recovery(l2sc); - l2sc->Q921_state = ST_AW_EST; - } -} - -/*---------------------------------------------------------------------------* - * FSM state ST_MULTIFR event rx'd FRMR - *---------------------------------------------------------------------------*/ -static void -F_MF20(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_MF20 executing"); - - i4b_mdl_error_ind(l2sc, "F_MF20", MDL_ERR_K); - - i4b_establish_data_link(l2sc); - - l2sc->l3initiated = 0; -} - -/*---------------------------------------------------------------------------* - * FSM state ST_TIMREC event dl establish request - *---------------------------------------------------------------------------*/ -static void -F_TR01(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_TR01 executing"); - - i4b_Dcleanifq(&l2sc->i_queue); - - i4b_establish_data_link(l2sc); - - l2sc->l3initiated = 1; -} - -/*---------------------------------------------------------------------------* - * FSM state ST_TIMREC event persistent deactivation - *---------------------------------------------------------------------------*/ -static void -F_TR05(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_TR05 executing"); - - i4b_Dcleanifq(&l2sc->i_queue); - - l2sc->postfsmarg = l2sc->unit; - l2sc->postfsmfunc = DL_Rel_Ind_A; - - i4b_T200_stop(l2sc); -} - -/*---------------------------------------------------------------------------* - * FSM state ST_TIMREC event mdl remove request - *---------------------------------------------------------------------------*/ -static void -F_TR06(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_TR06 executing"); - - i4b_Dcleanifq(&l2sc->i_queue); - - l2sc->postfsmarg = l2sc->unit; - l2sc->postfsmfunc = DL_Rel_Ind_A; - - i4b_T200_stop(l2sc); - -/*XXX*/ i4b_mdl_assign_ind(l2sc); -} - -/*---------------------------------------------------------------------------* - * FSM state ST_TIMREC event rx'd SABME - *---------------------------------------------------------------------------*/ -static void -F_TR07(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_TR07 executing"); - - i4b_clear_exception_conditions(l2sc); - - MDL_Status_Ind(l2sc->unit, STI_L2STAT, LAYER_ACTIVE); - - i4b_tx_ua(l2sc, l2sc->rxd_PF); - - i4b_mdl_error_ind(l2sc, "F_TR07", MDL_ERR_F); - - if(l2sc->vs != l2sc->va) - { - i4b_Dcleanifq(&l2sc->i_queue); - - l2sc->postfsmarg = l2sc->unit; - l2sc->postfsmfunc = DL_Est_Ind_A; - } - - i4b_T200_stop(l2sc); - i4b_T203_start(l2sc); - - l2sc->vs = 0; - l2sc->va = 0; - l2sc->vr = 0; -} - -/*---------------------------------------------------------------------------* - * FSM state ST_TIMREC event rx'd DISC - *---------------------------------------------------------------------------*/ -static void -F_TR08(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_TR08 executing"); - - i4b_Dcleanifq(&l2sc->i_queue); - MDL_Status_Ind(l2sc->unit, STI_L2STAT, LAYER_IDLE); - i4b_tx_ua(l2sc, l2sc->rxd_PF); - - l2sc->postfsmarg = l2sc->unit; - l2sc->postfsmfunc = DL_Rel_Ind_A; - - i4b_T200_stop(l2sc); -} - -/*---------------------------------------------------------------------------* - * FSM state ST_TIMREC event rx'd UA - *---------------------------------------------------------------------------*/ -static void -F_TR09(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_TR09 executing"); - if(l2sc->rxd_PF) - i4b_mdl_error_ind(l2sc, "F_TR09", MDL_ERR_C); - else - i4b_mdl_error_ind(l2sc, "F_TR09", MDL_ERR_D); -} - -/*---------------------------------------------------------------------------* - * FSM state ST_TIMREC event rx'd DM - *---------------------------------------------------------------------------*/ -static void -F_TR10(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_TR10 executing"); - - if(l2sc->rxd_PF) - { - i4b_mdl_error_ind(l2sc, "F_TR10", MDL_ERR_B); - } - else - { - i4b_mdl_error_ind(l2sc, "F_TR10", MDL_ERR_E); - } - - i4b_establish_data_link(l2sc); - - l2sc->l3initiated = 0; -} - -/*---------------------------------------------------------------------------* - * FSM state ST_TIMREC event T200 expiry - *---------------------------------------------------------------------------*/ -static void -F_TR11(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_TR11 executing"); - - if(l2sc->RC >= N200) - { - i4b_mdl_error_ind(l2sc, "F_TR11", MDL_ERR_I); - - i4b_establish_data_link(l2sc); - - l2sc->l3initiated = 0; - - l2sc->Q921_state = ST_AW_EST; - } - else - { - i4b_transmit_enquire(l2sc); - - l2sc->RC++; - - l2sc->Q921_state = ST_TIMREC; - } -} - -/*---------------------------------------------------------------------------* - * FSM state ST_TIMREC event dl data request - *---------------------------------------------------------------------------*/ -static void -F_TR12(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_TR12 executing"); - - i4b_i_frame_queued_up(l2sc); -} - -/*---------------------------------------------------------------------------* - * FSM state ST_TIMREC event dl release request - *---------------------------------------------------------------------------*/ -static void -F_TR13(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_TR13 executing"); - - i4b_Dcleanifq(&l2sc->i_queue); - - l2sc->RC = 0; - - i4b_tx_disc(l2sc, P1); - - i4b_T200_restart(l2sc); -} - -/*---------------------------------------------------------------------------* - * FSM state ST_TIMREC event set own rx busy - *---------------------------------------------------------------------------*/ -static void -F_TR15(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_TR15 executing"); - - if(l2sc->own_busy == 0) - { - l2sc->own_busy = 1; - - i4b_tx_rnr_response(l2sc, F0); - - l2sc->ack_pend = 0; - } -} - -/*---------------------------------------------------------------------------* - * FSM state ST_TIMREC event clear own rx busy - *---------------------------------------------------------------------------*/ -static void -F_TR16(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_TR16 executing"); - - if(l2sc->own_busy != 0) - { - l2sc->own_busy = 0; - - i4b_tx_rr_response(l2sc, F0); /* this is wrong */ - /* in Q.921 03/93 p 74 ! */ - l2sc->ack_pend = 0; - } -} - -/*---------------------------------------------------------------------------* - * FSM state ST_TIMREC event rx'd RR - *---------------------------------------------------------------------------*/ -static void -F_TR17(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_TR17 executing"); - - l2sc->peer_busy = 0; - - if(l2sc->rxd_CR == CR_CMD_FROM_NT) - { - if(l2sc->rxd_PF == 1) - { - i4b_enquiry_response(l2sc); - } - } - else - { - if(l2sc->rxd_PF == 1) - { - if(i4b_l2_nr_ok(l2sc->rxd_NR, l2sc->va, l2sc->vs)) - { - l2sc->va = l2sc->rxd_NR; - i4b_T200_stop(l2sc); - i4b_T203_start(l2sc); - i4b_invoke_retransmission(l2sc, l2sc->rxd_NR); - l2sc->Q921_state = ST_MULTIFR; - return; - } - else - { - i4b_nr_error_recovery(l2sc); - l2sc->Q921_state = ST_AW_EST; - return; - } - } - } - - if(i4b_l2_nr_ok(l2sc->rxd_NR, l2sc->va, l2sc->vs)) - { - l2sc->va = l2sc->rxd_NR; - l2sc->Q921_state = ST_TIMREC; - } - else - { - i4b_nr_error_recovery(l2sc); - l2sc->Q921_state = ST_AW_EST; - } -} - -/*---------------------------------------------------------------------------* - * FSM state ST_TIMREC event - *---------------------------------------------------------------------------*/ -static void -F_TR18(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_TR18 executing"); - - l2sc->peer_busy = 0; - - if(l2sc->rxd_CR == CR_CMD_FROM_NT) - { - if(l2sc->rxd_PF == 1) - { - i4b_enquiry_response(l2sc); - } - } - else - { - if(l2sc->rxd_PF == 1) - { - if(i4b_l2_nr_ok(l2sc->rxd_NR, l2sc->va, l2sc->vs)) - { - l2sc->va = l2sc->rxd_NR; - i4b_T200_stop(l2sc); - i4b_T203_start(l2sc); - i4b_invoke_retransmission(l2sc, l2sc->rxd_NR); - l2sc->Q921_state = ST_MULTIFR; - return; - } - else - { - i4b_nr_error_recovery(l2sc); - l2sc->Q921_state = ST_AW_EST; - return; - } - } - } - - if(i4b_l2_nr_ok(l2sc->rxd_NR, l2sc->va, l2sc->vs)) - { - l2sc->va = l2sc->rxd_NR; - l2sc->Q921_state = ST_TIMREC; - } - else - { - i4b_nr_error_recovery(l2sc); - l2sc->Q921_state = ST_AW_EST; - } -} - -/*---------------------------------------------------------------------------* - * FSM state ST_TIMREC event rx'd RNR - *---------------------------------------------------------------------------*/ -static void -F_TR19(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_TR19 executing"); - - l2sc->peer_busy = 0; - - if(l2sc->rxd_CR == CR_CMD_FROM_NT) - { - if(l2sc->rxd_PF == 1) - { - i4b_enquiry_response(l2sc); - } - } - else - { - if(l2sc->rxd_PF == 1) - { - if(i4b_l2_nr_ok(l2sc->rxd_NR, l2sc->va, l2sc->vs)) - { - l2sc->va = l2sc->rxd_NR; - i4b_T200_restart(l2sc); - i4b_invoke_retransmission(l2sc, l2sc->rxd_NR); - l2sc->Q921_state = ST_MULTIFR; - return; - } - else - { - i4b_nr_error_recovery(l2sc); - l2sc->Q921_state = ST_AW_EST; - return; - } - } - } - - if(i4b_l2_nr_ok(l2sc->rxd_NR, l2sc->va, l2sc->vs)) - { - l2sc->va = l2sc->rxd_NR; - l2sc->Q921_state = ST_TIMREC; - } - else - { - i4b_nr_error_recovery(l2sc); - l2sc->Q921_state = ST_AW_EST; - } -} - -/*---------------------------------------------------------------------------* - * FSM state ST_TIMREC event rx'd FRMR - *---------------------------------------------------------------------------*/ -static void -F_TR20(l2_softc_t *l2sc) -{ - NDBGL2(L2_F_MSG, "FSM function F_TR20 executing"); - - i4b_mdl_error_ind(l2sc, "F_TR20", MDL_ERR_K); - - i4b_establish_data_link(l2sc); - - l2sc->l3initiated = 0; -} diff --git a/sys/i4b/layer2/i4b_l2fsm.h b/sys/i4b/layer2/i4b_l2fsm.h deleted file mode 100644 index fe47089..0000000 --- a/sys/i4b/layer2/i4b_l2fsm.h +++ /dev/null @@ -1,82 +0,0 @@ -/*- - * Copyright (c) 1997, 2002 Hellmuth Michaelis. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/*--------------------------------------------------------------------------- - * - * i4b_l2fsm.h - layer 2 FSM - * ------------------------- - * - * $FreeBSD$ - * - * last edit-date: [Sat Mar 9 17:47:53 2002] - * - *---------------------------------------------------------------------------*/ - -#ifndef _I4B_L2FSM_H_ -#define _I4B_L2FSM_H_ - -enum Q921_states { - ST_TEI_UNAS, /* TEI unassigned */ - ST_ASG_AW_TEI, /* assign awaiting TEI */ - ST_EST_AW_TEI, /* establish awaiting TEI */ - ST_TEI_ASGD, /* TEI assigned */ - - ST_AW_EST, /* awaiting establishment */ - ST_AW_REL, /* awaiting release */ - ST_MULTIFR, /* multiple frame established */ - ST_TIMREC, /* timer recovery */ - - ST_SUBSET, /* SUBroutine SETs new state */ - ST_ILL, /* illegal state */ - N_STATES /* number of states */ -}; - -enum Q921_events { - EV_DLESTRQ, /* dl establish req */ - EV_DLUDTRQ, /* dl unit data req */ - EV_MDASGRQ, /* mdl assign req */ - EV_MDERRRS, /* mdl error response */ - EV_PSDEACT, /* persistent deactivation */ - EV_MDREMRQ, /* mdl remove req */ - EV_RXSABME, /* rx'd SABME */ - EV_RXDISC, /* rx'd DISC */ - EV_RXUA, /* rx'd UA */ - EV_RXDM, /* rx'd DM */ - EV_T200EXP, /* T200 expired */ - EV_DLDATRQ, /* dl data req */ - EV_DLRELRQ, /* dl release req */ - EV_T203EXP, /* T203 expired */ - EV_OWNBUSY, /* set own rx busy */ - EV_OWNRDY, /* clear own rx busy */ - EV_RXRR, /* rx'd RR */ - EV_RXREJ, /* rx'd REJ */ - EV_RXRNR, /* rx'd RNR */ - EV_RXFRMR, /* rx'd FRMR */ - - EV_ILL, /* Illegal */ - N_EVENTS -}; - -#endif /* _I4B_L2FSM_H_ */ diff --git a/sys/i4b/layer2/i4b_l2timer.c b/sys/i4b/layer2/i4b_l2timer.c deleted file mode 100644 index b129619..0000000 --- a/sys/i4b/layer2/i4b_l2timer.c +++ /dev/null @@ -1,232 +0,0 @@ -/*- - * Copyright (c) 1997, 2002 Hellmuth Michaelis. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/*--------------------------------------------------------------------------- - * - * i4b_l2timer.c - layer 2 timer handling - * -------------------------------------- - * last edit-date: [Sat Mar 9 17:48:58 2002] - * - *---------------------------------------------------------------------------*/ - -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - -#include <sys/param.h> -#include <sys/kernel.h> -#include <sys/systm.h> -#include <sys/socket.h> -#include <net/if.h> - -#include <i4b/include/i4b_debug.h> - -#include <i4b/include/i4b_global.h> - -#include <i4b/layer2/i4b_l2.h> -#include <i4b/layer2/i4b_l2fsm.h> - -/*---------------------------------------------------------------------------* - * Q.921 timer T200 timeout function - *---------------------------------------------------------------------------*/ -static void -i4b_T200_timeout(l2_softc_t *l2sc) -{ - NDBGL2(L2_T_ERR, "unit %d, RC = %d", l2sc->unit, l2sc->RC); - i4b_next_l2state(l2sc, EV_T200EXP); -} - -/*---------------------------------------------------------------------------* - * Q.921 timer T200 start - *---------------------------------------------------------------------------*/ -void -i4b_T200_start(l2_softc_t *l2sc) -{ - if(l2sc->T200 == TIMER_ACTIVE) - return; - - NDBGL2(L2_T_MSG, "unit %d", l2sc->unit); - l2sc->T200 = TIMER_ACTIVE; - - START_TIMER(l2sc->T200_callout, i4b_T200_timeout, l2sc, T200DEF); -} - -/*---------------------------------------------------------------------------* - * Q.921 timer T200 stop - *---------------------------------------------------------------------------*/ -void -i4b_T200_stop(l2_softc_t *l2sc) -{ - CRIT_VAR; - CRIT_BEG; - if(l2sc->T200 != TIMER_IDLE) - { - STOP_TIMER(l2sc->T200_callout, i4b_T200_timeout, l2sc); - l2sc->T200 = TIMER_IDLE; - } - CRIT_END; - NDBGL2(L2_T_MSG, "unit %d", l2sc->unit); -} - -/*---------------------------------------------------------------------------* - * Q.921 timer T200 restart - *---------------------------------------------------------------------------*/ -void -i4b_T200_restart(l2_softc_t *l2sc) -{ - CRIT_VAR; - CRIT_BEG; - if(l2sc->T200 != TIMER_IDLE) - { - STOP_TIMER(l2sc->T200_callout, i4b_T200_timeout, l2sc); - } - else - { - l2sc->T200 = TIMER_ACTIVE; - } - - START_TIMER(l2sc->T200_callout, i4b_T200_timeout, l2sc, T200DEF); - CRIT_END; - NDBGL2(L2_T_MSG, "unit %d", l2sc->unit); -} - -/*---------------------------------------------------------------------------* - * Q.921 timer T202 timeout function - *---------------------------------------------------------------------------*/ -static void -i4b_T202_timeout(l2_softc_t *l2sc) -{ - NDBGL2(L2_T_ERR, "unit %d, N202 = %d", l2sc->unit, l2sc->N202); - - if(--(l2sc->N202)) - { - (*l2sc->T202func)(l2sc); - } -} - -/*---------------------------------------------------------------------------* - * Q.921 timer T202 start - *---------------------------------------------------------------------------*/ -void -i4b_T202_start(l2_softc_t *l2sc) -{ - if (l2sc->N202 == TIMER_ACTIVE) - return; - - NDBGL2(L2_T_MSG, "unit %d", l2sc->unit); - l2sc->N202 = N202DEF; - l2sc->T202 = TIMER_ACTIVE; - - START_TIMER(l2sc->T202_callout, i4b_T202_timeout, l2sc, T202DEF); -} - -/*---------------------------------------------------------------------------* - * Q.921 timer T202 stop - *---------------------------------------------------------------------------*/ -void -i4b_T202_stop(l2_softc_t *l2sc) -{ - CRIT_VAR; - CRIT_BEG; - if(l2sc->T202 != TIMER_IDLE) - { - STOP_TIMER(l2sc->T202_callout, i4b_T202_timeout, l2sc); - l2sc->T202 = TIMER_IDLE; - } - CRIT_END; - NDBGL2(L2_T_MSG, "unit %d", l2sc->unit); -} - -/*---------------------------------------------------------------------------* - * Q.921 timer T203 timeout function - *---------------------------------------------------------------------------*/ -#if defined(I4B_T203_ACTIVE) && I4B_T203_ACTIVE -static void -i4b_T203_timeout(l2_softc_t *l2sc) -{ - NDBGL2(L2_T_ERR, "unit %d", l2sc->unit); - i4b_next_l2state(l2sc, EV_T203EXP); -} -#endif - -/*---------------------------------------------------------------------------* - * Q.921 timer T203 start - *---------------------------------------------------------------------------*/ -void -i4b_T203_start(l2_softc_t *l2sc) -{ -#if defined(I4B_T203_ACTIVE) && I4B_T203_ACTIVE - if (l2sc->T203 == TIMER_ACTIVE) - return; - - NDBGL2(L2_T_MSG, "unit %d", l2sc->unit); - l2sc->T203 = TIMER_ACTIVE; - - START_TIMER(l2sc->T203_callout, i4b_T203_timeout, l2sc, T203DEF); -#endif -} - -/*---------------------------------------------------------------------------* - * Q.921 timer T203 stop - *---------------------------------------------------------------------------*/ -void -i4b_T203_stop(l2_softc_t *l2sc) -{ -#if defined(I4B_T203_ACTIVE) && I4B_T203_ACTIVE - CRIT_VAR; - CRIT_BEG; - if(l2sc->T203 != TIMER_IDLE) - { - STOP_TIMER(l2sc->T203_callout, i4b_T203_timeout, l2sc); - l2sc->T203 = TIMER_IDLE; - } - CRIT_END; - NDBGL2(L2_T_MSG, "unit %d", l2sc->unit); -#endif -} - -/*---------------------------------------------------------------------------* - * Q.921 timer T203 restart - *---------------------------------------------------------------------------*/ -void -i4b_T203_restart(l2_softc_t *l2sc) -{ -#if defined(I4B_T203_ACTIVE) && I4B_T203_ACTIVE - CRIT_VAR; - CRIT_BEG; - - if(l2sc->T203 != TIMER_IDLE) - { - STOP_TIMER(l2sc->T203_callout, i4b_T203_timerout, l2sc); - } - else - { - l2sc->T203 = TIMER_ACTIVE; - } - - START_TIMER(l2sc->T203_callout, i4b_T203_timerout, l2sc, T203DEF); - CRIT_END; - NDBGL2(L2_T_MSG, "unit %d", l2sc->unit); -#endif -} diff --git a/sys/i4b/layer2/i4b_lme.c b/sys/i4b/layer2/i4b_lme.c deleted file mode 100644 index 19d45ea..0000000 --- a/sys/i4b/layer2/i4b_lme.c +++ /dev/null @@ -1,135 +0,0 @@ -/*- - * Copyright (c) 1997, 2002 Hellmuth Michaelis. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/*--------------------------------------------------------------------------- - * - * i4b_lme.c - layer management entity - * ------------------------------------- - * last edit-date: [Sat Mar 9 17:49:42 2002] - * - *---------------------------------------------------------------------------*/ - -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - -#include <sys/param.h> -#include <sys/systm.h> -#include <sys/socket.h> -#include <net/if.h> - -#include <i4b/include/i4b_debug.h> - -#include <i4b/layer2/i4b_l2.h> - -/*---------------------------------------------------------------------------* - * mdl assign indication handler - *---------------------------------------------------------------------------*/ -void -i4b_mdl_assign_ind(l2_softc_t *l2sc) -{ - NDBGL2(L2_PRIM, "unit %d", l2sc->unit); - - i4b_l1_activate(l2sc); - - if(l2sc->tei_valid == TEI_VALID) - { - l2sc->T202func = (void(*)(void*))i4b_tei_verify; - l2sc->N202 = N202DEF; - i4b_tei_verify(l2sc); - } - else - { - l2sc->T202func = (void(*)(void*))i4b_tei_assign; - l2sc->N202 = N202DEF; - i4b_tei_assign(l2sc); - } -} - -/*---------------------------------------------------------------------------* - * i4b_mdl_error_ind handler (Q.921 01/94 pp 156) - *---------------------------------------------------------------------------*/ -void -i4b_mdl_error_ind(l2_softc_t *l2sc, char *where, int errorcode) -{ -#if DO_I4B_DEBUG - static char *error_text[] = { - "MDL_ERR_A: rx'd unsolicited response - supervisory (F=1)", - "MDL_ERR_B: rx'd unsolicited response - DM (F=1)", - "MDL_ERR_C: rx'd unsolicited response - UA (F=1)", - "MDL_ERR_D: rx'd unsolicited response - UA (F=0)", - "MDL_ERR_E: rx'd unsolicited response - DM (F=0)", - "MDL_ERR_F: peer initiated re-establishment - SABME", - "MDL_ERR_G: unsuccessful transmission N200times - SABME", - "MDL_ERR_H: unsuccessful transmission N200times - DIS", - "MDL_ERR_I: unsuccessful transmission N200times - Status ENQ", - "MDL_ERR_J: other error - N(R) error", - "MDL_ERR_K: other error - rx'd FRMR response", - "MDL_ERR_L: other error - rx'd undefined frame", - "MDL_ERR_M: other error - receipt of I field not permitted", - "MDL_ERR_N: other error - rx'd frame with wrong size", - "MDL_ERR_O: other error - N201 error", - "MDL_ERR_MAX: i4b_mdl_error_ind called with wrong parameter!!!" - }; -#endif - - if(errorcode > MDL_ERR_MAX) - errorcode = MDL_ERR_MAX; - - NDBGL2(L2_ERROR, "unit = %d, location = %s", l2sc->unit, where); - NDBGL2(L2_ERROR, "error = %s", error_text[errorcode]); - - switch(errorcode) - { - case MDL_ERR_A: - case MDL_ERR_B: - break; - - case MDL_ERR_C: - case MDL_ERR_D: - i4b_tei_verify(l2sc); - break; - - case MDL_ERR_E: - case MDL_ERR_F: - break; - - case MDL_ERR_G: - case MDL_ERR_H: - i4b_tei_verify(l2sc); - break; - - case MDL_ERR_I: - case MDL_ERR_J: - case MDL_ERR_K: - case MDL_ERR_L: - case MDL_ERR_M: - case MDL_ERR_N: - case MDL_ERR_O: - break; - - default: - break; - } -} diff --git a/sys/i4b/layer2/i4b_mbuf.c b/sys/i4b/layer2/i4b_mbuf.c deleted file mode 100644 index 9bc0b68..0000000 --- a/sys/i4b/layer2/i4b_mbuf.c +++ /dev/null @@ -1,217 +0,0 @@ -/*- - * Copyright (c) 1997, 2002 Hellmuth Michaelis. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/*--------------------------------------------------------------------------- - * - * i4b - mbuf handling support routines - * ------------------------------------ - * last edit-date: [Sat Mar 9 17:51:22 2002] - * - *---------------------------------------------------------------------------*/ - -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - -#include <sys/param.h> -#include <sys/systm.h> -#include <sys/mbuf.h> -#include <sys/socket.h> -#include <net/if.h> - -#include <i4b/include/i4b_mbuf.h> - -#define I4B_MBUF_DEBUG -#undef I4B_MBUF_TYPE_DEBUG - -#ifdef I4B_MBUF_TYPE_DEBUG - -#define MT_DCHAN 42 -#define MT_BCHAN 43 - -#define MT_I4B_D MT_DCHAN -#define MT_I4B_B MT_BCHAN - -#else /* ! I4B_MBUF_TYPE_DEBUG */ - -#define MT_I4B_D MT_DATA -#define MT_I4B_B MT_DATA - -#endif /* I4B_MBUF_TYPE_DEBUG */ - -/*---------------------------------------------------------------------------* - * allocate D-channel mbuf space - *---------------------------------------------------------------------------*/ -struct mbuf* -i4b_Dgetmbuf(int len) -{ - struct mbuf *m; - - if(len > MCLBYTES) /* if length > max extension size */ - { - -#ifdef I4B_MBUF_DEBUG - printf("i4b_getmbuf: error - len(%d) > MCLBYTES(%d)\n", - len, MCLBYTES); -#endif - - return(NULL); - } - - MGETHDR(m, M_DONTWAIT, MT_I4B_D); /* get mbuf with pkthdr */ - - /* did we actually get the mbuf ? */ - - if(!m) - { - -#ifdef I4B_MBUF_DEBUG - printf("i4b_getbuf: error - MGETHDR failed!\n"); -#endif - - return(NULL); - } - - if(len >= MHLEN) - { - MCLGET(m, M_DONTWAIT); - - if(!(m->m_flags & M_EXT)) - { - m_freem(m); - -#ifdef I4B_MBUF_DEBUG - printf("i4b_getbuf: error - MCLGET failed, len(%d)\n", len); -#endif - - return (NULL); - } - } - - m->m_len = len; - - return(m); -} - -/*---------------------------------------------------------------------------* - * free a D-channel mbuf - *---------------------------------------------------------------------------*/ -void -i4b_Dfreembuf(struct mbuf *m) -{ - if(m) - m_freem(m); -} - -/*---------------------------------------------------------------------------* - * clear a D-channel ifqueue from data - *---------------------------------------------------------------------------*/ -void -i4b_Dcleanifq(struct ifqueue *ifq) -{ - int x = splimp(); - - IF_DRAIN(ifq); - - splx(x); -} - -/*---------------------------------------------------------------------------* - * allocate B-channel mbuf space - *---------------------------------------------------------------------------*/ -struct mbuf* -i4b_Bgetmbuf(int len) -{ - struct mbuf *m; - - if(len > MCLBYTES) /* if length > max extension size */ - { - -#ifdef I4B_MBUF_DEBUG - printf("i4b_getmbuf: error - len(%d) > MCLBYTES(%d)\n", - len, MCLBYTES); -#endif - - return(NULL); - } - - MGETHDR(m, M_DONTWAIT, MT_I4B_B); /* get mbuf with pkthdr */ - - /* did we actually get the mbuf ? */ - - if(!m) - { - -#ifdef I4B_MBUF_DEBUG - printf("i4b_getbuf: error - MGETHDR failed!\n"); -#endif - - return(NULL); - } - - if(len >= MHLEN) - { - MCLGET(m, M_DONTWAIT); - - if(!(m->m_flags & M_EXT)) - { - m_freem(m); - -#ifdef I4B_MBUF_DEBUG - printf("i4b_getbuf: error - MCLGET failed, len(%d)\n", len); -#endif - - return (NULL); - } - } - - m->m_len = len; - - return(m); -} - -/*---------------------------------------------------------------------------* - * free a B-channel mbuf - *---------------------------------------------------------------------------*/ -void -i4b_Bfreembuf(struct mbuf *m) -{ - if(m) - m_freem(m); -} - -/*---------------------------------------------------------------------------* - * clear a B-channel ifqueue from data - *---------------------------------------------------------------------------*/ -void -i4b_Bcleanifq(struct ifqueue *ifq) -{ - int x = splimp(); - - IF_DRAIN(ifq); - - splx(x); -} - -/* EOF */ diff --git a/sys/i4b/layer2/i4b_sframe.c b/sys/i4b/layer2/i4b_sframe.c deleted file mode 100644 index afe59eb..0000000 --- a/sys/i4b/layer2/i4b_sframe.c +++ /dev/null @@ -1,207 +0,0 @@ -/*- - * Copyright (c) 1997, 2002 Hellmuth Michaelis. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/*--------------------------------------------------------------------------- - * - * i4b_sframe.c - s frame handling routines - * ---------------------------------------- - * last edit-date: [Sat Mar 9 17:52:06 2002] - * - *---------------------------------------------------------------------------*/ - -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - -#include <sys/param.h> -#include <sys/systm.h> -#include <sys/mbuf.h> -#include <sys/socket.h> -#include <net/if.h> - -#include <i4b/include/i4b_debug.h> - -#include <i4b/include/i4b_l1l2.h> -#include <i4b/include/i4b_mbuf.h> - -#include <i4b/layer2/i4b_l2.h> -#include <i4b/layer2/i4b_l2fsm.h> - -/*---------------------------------------------------------------------------* - * process s frame - *---------------------------------------------------------------------------*/ -void -i4b_rxd_s_frame(int unit, struct mbuf *m) -{ - l2_softc_t *l2sc = &l2_softc[unit]; - u_char *ptr = m->m_data; - - if(!((l2sc->tei_valid == TEI_VALID) && - (l2sc->tei == GETTEI(*(ptr+OFF_TEI))))) - { - i4b_Dfreembuf(m); - return; - } - - l2sc->rxd_CR = GETCR(*(ptr + OFF_SAPI)); - l2sc->rxd_PF = GETSPF(*(ptr + OFF_SNR)); - l2sc->rxd_NR = GETSNR(*(ptr + OFF_SNR)); - - i4b_rxd_ack(l2sc, l2sc->rxd_NR); - - switch(*(ptr + OFF_SRCR)) - { - case RR: - l2sc->stat.rx_rr++; /* update statistics */ - NDBGL2(L2_S_MSG, "rx'd RR, N(R) = %d", l2sc->rxd_NR); - i4b_next_l2state(l2sc, EV_RXRR); - break; - - case RNR: - l2sc->stat.rx_rnr++; /* update statistics */ - NDBGL2(L2_S_MSG, "rx'd RNR, N(R) = %d", l2sc->rxd_NR); - i4b_next_l2state(l2sc, EV_RXRNR); - break; - - case REJ: - l2sc->stat.rx_rej++; /* update statistics */ - NDBGL2(L2_S_MSG, "rx'd REJ, N(R) = %d", l2sc->rxd_NR); - i4b_next_l2state(l2sc, EV_RXREJ); - break; - - default: - l2sc->stat.err_rx_bads++; /* update statistics */ - NDBGL2(L2_S_ERR, "ERROR, unknown code, frame = "); - i4b_print_frame(m->m_len, m->m_data); - break; - } - i4b_Dfreembuf(m); -} - -/*---------------------------------------------------------------------------* - * transmit RR command - *---------------------------------------------------------------------------*/ -void -i4b_tx_rr_command(l2_softc_t *l2sc, pbit_t pbit) -{ - struct mbuf *m; - - NDBGL2(L2_S_MSG, "tx RR, unit = %d", l2sc->unit); - - m = i4b_build_s_frame(l2sc, CR_CMD_TO_NT, pbit, RR); - - PH_Data_Req(l2sc->unit, m, MBUF_FREE); - - l2sc->stat.tx_rr++; /* update statistics */ -} - -/*---------------------------------------------------------------------------* - * transmit RR response - *---------------------------------------------------------------------------*/ -void -i4b_tx_rr_response(l2_softc_t *l2sc, fbit_t fbit) -{ - struct mbuf *m; - - NDBGL2(L2_S_MSG, "tx RR, unit = %d", l2sc->unit); - - m = i4b_build_s_frame(l2sc, CR_RSP_TO_NT, fbit, RR); - - PH_Data_Req(l2sc->unit, m, MBUF_FREE); - - l2sc->stat.tx_rr++; /* update statistics */ -} - -/*---------------------------------------------------------------------------* - * transmit RNR command - *---------------------------------------------------------------------------*/ -void -i4b_tx_rnr_command(l2_softc_t *l2sc, pbit_t pbit) -{ - struct mbuf *m; - - NDBGL2(L2_S_MSG, "tx RNR, unit = %d", l2sc->unit); - - m = i4b_build_s_frame(l2sc, CR_CMD_TO_NT, pbit, RNR); - - PH_Data_Req(l2sc->unit, m, MBUF_FREE); - - l2sc->stat.tx_rnr++; /* update statistics */ -} - -/*---------------------------------------------------------------------------* - * transmit RNR response - *---------------------------------------------------------------------------*/ -void -i4b_tx_rnr_response(l2_softc_t *l2sc, fbit_t fbit) -{ - struct mbuf *m; - - NDBGL2(L2_S_MSG, "tx RNR, unit = %d", l2sc->unit); - - m = i4b_build_s_frame(l2sc, CR_RSP_TO_NT, fbit, RNR); - - PH_Data_Req(l2sc->unit, m, MBUF_FREE); - - l2sc->stat.tx_rnr++; /* update statistics */ -} - -/*---------------------------------------------------------------------------* - * transmit REJ response - *---------------------------------------------------------------------------*/ -void -i4b_tx_rej_response(l2_softc_t *l2sc, fbit_t fbit) -{ - struct mbuf *m; - - NDBGL2(L2_S_MSG, "tx REJ, unit = %d", l2sc->unit); - - m = i4b_build_s_frame(l2sc, CR_RSP_TO_NT, fbit, REJ); - - PH_Data_Req(l2sc->unit, m, MBUF_FREE); - - l2sc->stat.tx_rej++; /* update statistics */ -} - -/*---------------------------------------------------------------------------* - * build S-frame for sending - *---------------------------------------------------------------------------*/ -struct mbuf * -i4b_build_s_frame(l2_softc_t *l2sc, crbit_to_nt_t crbit, pbit_t pbit, u_char type) -{ - struct mbuf *m; - - if((m = i4b_Dgetmbuf(S_FRAME_LEN)) == NULL) - return(NULL); - - PUTSAPI(SAPI_CCP, crbit, m->m_data[OFF_SAPI]); - - PUTTEI(l2sc->tei, m->m_data[OFF_TEI]); - - m->m_data[OFF_SRCR] = type; - - m->m_data[OFF_SNR] = (l2sc->vr << 1) | (pbit & 0x01); - - return(m); -} diff --git a/sys/i4b/layer2/i4b_tei.c b/sys/i4b/layer2/i4b_tei.c deleted file mode 100644 index 0e55bc2..0000000 --- a/sys/i4b/layer2/i4b_tei.c +++ /dev/null @@ -1,278 +0,0 @@ -/*- - * Copyright (c) 1997, 2002 Hellmuth Michaelis. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/*--------------------------------------------------------------------------- - * - * i4b_tei.c - tei handling procedures - * ----------------------------------- - * last edit-date: [Sat Mar 9 17:53:27 2002] - * - *---------------------------------------------------------------------------*/ - -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - -#include <sys/param.h> -#include <sys/systm.h> -#include <sys/syslog.h> -#include <sys/mbuf.h> -#include <sys/socket.h> -#include <net/if.h> - -#include <i4b/include/i4b_debug.h> - -#include <i4b/include/i4b_global.h> -#include <i4b/include/i4b_l1l2.h> -#include <i4b/include/i4b_l2l3.h> -#include <i4b/include/i4b_mbuf.h> - -#include <i4b/layer2/i4b_l2.h> -#include <i4b/layer2/i4b_l2fsm.h> - -/*---------------------------------------------------------------------------* - * handle a received TEI management frame - *---------------------------------------------------------------------------*/ -void -i4b_tei_rxframe(int unit, struct mbuf *m) -{ - l2_softc_t *l2sc = &l2_softc[unit]; - u_char *ptr = m->m_data; - - switch(*(ptr + OFF_MT)) - { - case MT_ID_ASSIGN: - if( (*(ptr + OFF_RIL) == l2sc->last_ril) && - (*(ptr + OFF_RIH) == l2sc->last_rih)) - { - l2sc->tei = GET_TEIFROMAI(*(ptr+OFF_AI)); - l2sc->tei_valid = TEI_VALID; - - if(l2sc->T202 == TIMER_ACTIVE) - i4b_T202_stop(l2sc); - - MDL_Status_Ind(l2sc->unit, STI_TEIASG, l2sc->tei); - - log(LOG_INFO, "i4b: unit %d, assigned TEI = %d = 0x%02x\n", l2sc->unit, l2sc->tei, l2sc->tei); - - NDBGL2(L2_TEI_MSG, "TEI ID Assign - TEI = %d", l2sc->tei); - - i4b_next_l2state(l2sc, EV_MDASGRQ); - } - break; - - case MT_ID_DENY: - if( (*(ptr + OFF_RIL) == l2sc->last_ril) && - (*(ptr + OFF_RIH) == l2sc->last_rih)) - { - l2sc->tei_valid = TEI_INVALID; - l2sc->tei = GET_TEIFROMAI(*(ptr+OFF_AI)); - - if(l2sc->tei == GROUP_TEI) - { - log(LOG_WARNING, "i4b: unit %d, denied TEI, no TEI values available from exchange!\n", l2sc->unit); - NDBGL2(L2_TEI_ERR, "TEI ID Denied, No TEI values available from exchange!"); - } - else - { - log(LOG_WARNING, "i4b: unit %d, denied TEI = %d = 0x%02x\n", l2sc->unit, l2sc->tei, l2sc->tei); - NDBGL2(L2_TEI_ERR, "TEI ID Denied - TEI = %d", l2sc->tei); - } - MDL_Status_Ind(l2sc->unit, STI_TEIASG, -1); - i4b_next_l2state(l2sc, EV_MDERRRS); - } - break; - - case MT_ID_CHK_REQ: - if( (l2sc->tei_valid == TEI_VALID) && - ( (l2sc->tei == GET_TEIFROMAI(*(ptr+OFF_AI))) || - (GROUP_TEI == GET_TEIFROMAI(*(ptr+OFF_AI))) )) - { - static int lasttei = -1; - - if(l2sc->tei != lasttei) - { - NDBGL2(L2_TEI_MSG, "TEI ID Check Req - TEI = %d", l2sc->tei); - lasttei = l2sc->tei; - } - - if(l2sc->T202 == TIMER_ACTIVE) - i4b_T202_stop(l2sc); - i4b_tei_chkresp(l2sc); - } - break; - - case MT_ID_REMOVE: - if( (l2sc->tei_valid == TEI_VALID) && - ( (l2sc->tei == GET_TEIFROMAI(*(ptr+OFF_AI))) || - (l2sc->tei == GET_TEIFROMAI(*(ptr+OFF_AI))))) - { - l2sc->tei_valid = TEI_INVALID; - l2sc->tei = GET_TEIFROMAI(*(ptr+OFF_AI)); - - log(LOG_INFO, "i4b: unit %d, removed TEI = %d = 0x%02x\n", l2sc->unit, l2sc->tei, l2sc->tei); - NDBGL2(L2_TEI_MSG, "TEI ID Remove - TEI = %d", l2sc->tei); - MDL_Status_Ind(l2sc->unit, STI_TEIASG, -1); - i4b_next_l2state(l2sc, EV_MDREMRQ); - } - break; - - default: - NDBGL2(L2_TEI_ERR, "UNKNOWN TEI MGMT Frame, type = 0x%x", *(ptr + OFF_MT)); - i4b_print_frame(m->m_len, m->m_data); - break; - } - i4b_Dfreembuf(m); -} - -/*---------------------------------------------------------------------------* - * allocate and fill up a TEI management frame for sending - *---------------------------------------------------------------------------*/ -static struct mbuf * -build_tei_mgmt_frame(l2_softc_t *l2sc, unsigned char type) -{ - struct mbuf *m; - - if((m = i4b_Dgetmbuf(TEI_MGMT_FRM_LEN)) == NULL) - return(NULL); - - m->m_data[TEIM_SAPIO] = 0xfc; /* SAPI = 63, CR = 0, EA = 0 */ - m->m_data[TEIM_TEIO] = 0xff; /* TEI = 127, EA = 1 */ - m->m_data[TEIM_UIO] = UI; /* UI */ - m->m_data[TEIM_MEIO] = MEI; /* MEI */ - m->m_data[TEIM_MTO] = type; /* message type */ - - switch(type) - { - case MT_ID_REQEST: - i4b_make_rand_ri(l2sc); - m->m_data[TEIM_RILO] = l2sc->last_ril; - m->m_data[TEIM_RIHO] = l2sc->last_rih; - m->m_data[TEIM_AIO] = (GROUP_TEI << 1) | 0x01; - break; - - case MT_ID_CHK_RSP: - i4b_make_rand_ri(l2sc); - m->m_data[TEIM_RILO] = l2sc->last_ril; - m->m_data[TEIM_RIHO] = l2sc->last_rih; - m->m_data[TEIM_AIO] = (l2sc->tei << 1) | 0x01; - break; - - case MT_ID_VERIFY: - m->m_data[TEIM_RILO] = 0; - m->m_data[TEIM_RIHO] = 0; - m->m_data[TEIM_AIO] = (l2sc->tei << 1) | 0x01; - break; - - default: - i4b_Dfreembuf(m); - panic("build_tei_mgmt_frame: invalid type"); - break; - } - l2sc->stat.tx_tei++; - return(m); -} - -/*---------------------------------------------------------------------------* - * i4b_tei_assign - TEI assignment procedure (Q.921, 5.3.2, pp 24) - * T202func and N202 _MUST_ be set prior to calling this function ! - *---------------------------------------------------------------------------*/ -void -i4b_tei_assign(l2_softc_t *l2sc) -{ - struct mbuf *m; - - NDBGL2(L2_TEI_MSG, "tx TEI ID_Request"); - - m = build_tei_mgmt_frame(l2sc, MT_ID_REQEST); - - if(m == NULL) - panic("i4b_tei_assign: no mbuf"); - - i4b_T202_start(l2sc); - - PH_Data_Req(l2sc->unit, m, MBUF_FREE); -} - -/*---------------------------------------------------------------------------* - * i4b_tei_assign - TEI verify procedure (Q.921, 5.3.5, pp 29) - * T202func and N202 _MUST_ be set prior to calling this function ! - *---------------------------------------------------------------------------*/ -void -i4b_tei_verify(l2_softc_t *l2sc) -{ - struct mbuf *m; - - NDBGL2(L2_TEI_MSG, "tx TEI ID_Verify"); - - m = build_tei_mgmt_frame(l2sc, MT_ID_VERIFY); - - if(m == NULL) - panic("i4b_tei_verify: no mbuf"); - - i4b_T202_start(l2sc); - - PH_Data_Req(l2sc->unit, m, MBUF_FREE); -} - -/*---------------------------------------------------------------------------* - * i4b_tei_chkresp - TEI check response procedure (Q.921, 5.3.5, pp 29) - *---------------------------------------------------------------------------*/ -void -i4b_tei_chkresp(l2_softc_t *l2sc) -{ - struct mbuf *m; - static int lasttei = 0; - - if(l2sc->tei != lasttei) - { - lasttei = l2sc->tei; - NDBGL2(L2_TEI_MSG, "tx TEI ID_Check_Response"); - } - - m = build_tei_mgmt_frame(l2sc, MT_ID_CHK_RSP); - - if(m == NULL) - panic("i4b_tei_chkresp: no mbuf"); - - PH_Data_Req(l2sc->unit, m, MBUF_FREE); -} - -/*---------------------------------------------------------------------------* - * generate some 16 bit "random" number used for TEI mgmt Ri field - *---------------------------------------------------------------------------*/ -void -i4b_make_rand_ri(l2_softc_t *l2sc) -{ - u_short val; - -#ifdef RANDOMDEV - read_random((char *)&val, sizeof(val)); -#else - val = (u_short)random(); -#endif /* RANDOMDEV */ - - l2sc->last_rih = (val >> 8) & 0x00ff; - l2sc->last_ril = val & 0x00ff; -} diff --git a/sys/i4b/layer2/i4b_uframe.c b/sys/i4b/layer2/i4b_uframe.c deleted file mode 100644 index 55331a0..0000000 --- a/sys/i4b/layer2/i4b_uframe.c +++ /dev/null @@ -1,277 +0,0 @@ -/*- - * Copyright (c) 1997, 2002 Hellmuth Michaelis. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/*--------------------------------------------------------------------------- - * - * i4b_uframe.c - routines for handling U-frames - * ----------------------------------------------- - * last edit-date: [Sat Mar 9 17:54:08 2002] - * - *---------------------------------------------------------------------------*/ - -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - -#include <sys/param.h> -#include <sys/systm.h> -#include <sys/mbuf.h> -#include <sys/socket.h> -#include <net/if.h> - -#include <i4b/include/i4b_debug.h> - -#include <i4b/include/i4b_l1l2.h> -#include <i4b/include/i4b_l2l3.h> -#include <i4b/include/i4b_mbuf.h> - -#include <i4b/layer2/i4b_l2.h> -#include <i4b/layer2/i4b_l2fsm.h> - -/*---------------------------------------------------------------------------* - * process a received U-frame - *---------------------------------------------------------------------------*/ -void -i4b_rxd_u_frame(int unit, struct mbuf *m) -{ - l2_softc_t *l2sc = &l2_softc[unit]; - u_char *ptr = m->m_data; - - int sapi = GETSAPI(*(ptr + OFF_SAPI)); - int tei = GETTEI(*(ptr + OFF_TEI)); - int pfbit = GETUPF(*(ptr + OFF_CNTL)); - - switch(*(ptr + OFF_CNTL) & ~UPFBIT) - { - /* commands */ - - case SABME: - if((l2sc->tei_valid == TEI_VALID) && - (l2sc->tei == GETTEI(*(ptr+OFF_TEI)))) - { - l2sc->stat.rx_sabme++; - NDBGL2(L2_U_MSG, "SABME, sapi = %d, tei = %d", sapi, tei); - l2sc->rxd_PF = pfbit; - i4b_next_l2state(l2sc, EV_RXSABME); - } - i4b_Dfreembuf(m); - break; - - case UI: - if(sapi == SAPI_L2M && - tei == GROUP_TEI && - *(ptr + OFF_MEI) == MEI) - { - /* layer 2 management (SAPI = 63) */ - l2sc->stat.rx_tei++; - i4b_tei_rxframe(unit, m); - } - else if(sapi == SAPI_CCP && tei == GROUP_TEI) - { - /* call control (SAPI = 0) */ - l2sc->stat.rx_ui++; - /* strip ui header */ - m_adj(m, UI_HDR_LEN); - /* to upper layer */ - DL_Unit_Data_Ind(unit, m); - } - else - { - l2sc->stat.err_rx_badui++; - NDBGL2(L2_U_ERR, "unknown UI frame!"); - i4b_Dfreembuf(m); - } - break; - - case DISC: - if((l2sc->tei_valid == TEI_VALID) && - (l2sc->tei == GETTEI(*(ptr+OFF_TEI)))) - { - l2sc->stat.rx_disc++; - NDBGL2(L2_U_MSG, "DISC, sapi = %d, tei = %d", sapi, tei); - l2sc->rxd_PF = pfbit; - i4b_next_l2state(l2sc, EV_RXDISC); - } - i4b_Dfreembuf(m); - break; - - case XID: - if((l2sc->tei_valid == TEI_VALID) && - (l2sc->tei == GETTEI(*(ptr+OFF_TEI)))) - { - l2sc->stat.rx_xid++; - NDBGL2(L2_U_MSG, "XID, sapi = %d, tei = %d", sapi, tei); - } - i4b_Dfreembuf(m); - break; - - /* responses */ - - case DM: - if((l2sc->tei_valid == TEI_VALID) && - (l2sc->tei == GETTEI(*(ptr+OFF_TEI)))) - { - l2sc->stat.rx_dm++; - NDBGL2(L2_U_MSG, "DM, sapi = %d, tei = %d", sapi, tei); - i4b_print_frame(m->m_len, m->m_data); - l2sc->rxd_PF = pfbit; - i4b_next_l2state(l2sc, EV_RXDM); - } - i4b_Dfreembuf(m); - break; - - case UA: - if((l2sc->tei_valid == TEI_VALID) && - (l2sc->tei == GETTEI(*(ptr+OFF_TEI)))) - { - l2sc->stat.rx_ua++; - NDBGL2(L2_U_MSG, "UA, sapi = %d, tei = %d", sapi, tei); - l2sc->rxd_PF = pfbit; - i4b_next_l2state(l2sc, EV_RXUA); - } - i4b_Dfreembuf(m); - break; - - case FRMR: - if((l2sc->tei_valid == TEI_VALID) && - (l2sc->tei == GETTEI(*(ptr+OFF_TEI)))) - { - l2sc->stat.rx_frmr++; - NDBGL2(L2_U_MSG, "FRMR, sapi = %d, tei = %d", sapi, tei); - l2sc->rxd_PF = pfbit; - i4b_next_l2state(l2sc, EV_RXFRMR); - } - i4b_Dfreembuf(m); - break; - - default: - if((l2sc->tei_valid == TEI_VALID) && - (l2sc->tei == GETTEI(*(ptr+OFF_TEI)))) - { - NDBGL2(L2_U_ERR, "UNKNOWN TYPE ERROR, sapi = %d, tei = %d, frame = ", sapi, tei); - i4b_print_frame(m->m_len, m->m_data); - } - else - { - NDBGL2(L2_U_ERR, "not mine - UNKNOWN TYPE ERROR, sapi = %d, tei = %d, frame = ", sapi, tei); - i4b_print_frame(m->m_len, m->m_data); - } - l2sc->stat.err_rx_badui++; - i4b_Dfreembuf(m); - break; - } -} - -/*---------------------------------------------------------------------------* - * build U-frame for sending - *---------------------------------------------------------------------------*/ -struct mbuf * -i4b_build_u_frame(l2_softc_t *l2sc, crbit_to_nt_t crbit, pbit_t pbit, u_char type) -{ - struct mbuf *m; - - if((m = i4b_Dgetmbuf(U_FRAME_LEN)) == NULL) - return(NULL); - - PUTSAPI(SAPI_CCP, crbit, m->m_data[OFF_SAPI]); - - PUTTEI(l2sc->tei, m->m_data[OFF_TEI]); - - if(pbit) - m->m_data[OFF_CNTL] = type | UPBITSET; - else - m->m_data[OFF_CNTL] = type & ~UPBITSET; - - return(m); -} - -/*---------------------------------------------------------------------------* - * transmit SABME command - *---------------------------------------------------------------------------*/ -void -i4b_tx_sabme(l2_softc_t *l2sc, pbit_t pbit) -{ - struct mbuf *m; - - l2sc->stat.tx_sabme++; - NDBGL2(L2_U_MSG, "tx SABME, tei = %d", l2sc->tei); - m = i4b_build_u_frame(l2sc, CR_CMD_TO_NT, pbit, SABME); - PH_Data_Req(l2sc->unit, m, MBUF_FREE); -} - -/*---------------------------------------------------------------------------* - * transmit DM response - *---------------------------------------------------------------------------*/ -void -i4b_tx_dm(l2_softc_t *l2sc, fbit_t fbit) -{ - struct mbuf *m; - - l2sc->stat.tx_dm++; - NDBGL2(L2_U_MSG, "tx DM, tei = %d", l2sc->tei); - m = i4b_build_u_frame(l2sc, CR_RSP_TO_NT, fbit, DM); - PH_Data_Req(l2sc->unit, m, MBUF_FREE); -} - -/*---------------------------------------------------------------------------* - * transmit DISC command - *---------------------------------------------------------------------------*/ -void -i4b_tx_disc(l2_softc_t *l2sc, pbit_t pbit) -{ - struct mbuf *m; - - l2sc->stat.tx_disc++; - NDBGL2(L2_U_MSG, "tx DISC, tei = %d", l2sc->tei); - m = i4b_build_u_frame(l2sc, CR_CMD_TO_NT, pbit, DISC); - PH_Data_Req(l2sc->unit, m, MBUF_FREE); -} - -/*---------------------------------------------------------------------------* - * transmit UA response - *---------------------------------------------------------------------------*/ -void -i4b_tx_ua(l2_softc_t *l2sc, fbit_t fbit) -{ - struct mbuf *m; - - l2sc->stat.tx_ua++; - NDBGL2(L2_U_MSG, "tx UA, tei = %d", l2sc->tei); - m = i4b_build_u_frame(l2sc, CR_RSP_TO_NT, fbit, UA); - PH_Data_Req(l2sc->unit, m, MBUF_FREE); -} - -/*---------------------------------------------------------------------------* - * transmit FRMR response - *---------------------------------------------------------------------------*/ -void -i4b_tx_frmr(l2_softc_t *l2sc, fbit_t fbit) -{ - struct mbuf *m; - - l2sc->stat.tx_frmr++; - NDBGL2(L2_U_MSG, "tx FRMR, tei = %d", l2sc->tei); - m = i4b_build_u_frame(l2sc, CR_RSP_TO_NT, fbit, FRMR); - PH_Data_Req(l2sc->unit, m, MBUF_FREE); -} diff --git a/sys/i4b/layer2/i4b_util.c b/sys/i4b/layer2/i4b_util.c deleted file mode 100644 index 9121648..0000000 --- a/sys/i4b/layer2/i4b_util.c +++ /dev/null @@ -1,305 +0,0 @@ -/*- - * Copyright (c) 1997, 2002 Hellmuth Michaelis. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/*--------------------------------------------------------------------------- - * - * i4b_util.c - layer 2 utility routines - * ------------------------------------- - * last edit-date: [Sat Mar 9 17:55:03 2002] - * - *---------------------------------------------------------------------------*/ - -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - -#include <sys/param.h> -#include <sys/systm.h> -#include <sys/mbuf.h> -#include <sys/socket.h> -#include <net/if.h> - -#include <i4b/include/i4b_debug.h> - -#include <i4b/include/i4b_global.h> -#include <i4b/include/i4b_l1l2.h> -#include <i4b/include/i4b_mbuf.h> - -#include <i4b/layer2/i4b_l2.h> - -/*---------------------------------------------------------------------------* - * routine ESTABLISH DATA LINK (Q.921 03/93 page 83) - *---------------------------------------------------------------------------*/ -void -i4b_establish_data_link(l2_softc_t *l2sc) -{ - i4b_l1_activate(l2sc); - - i4b_clear_exception_conditions(l2sc); - - l2sc->RC = 0; - - i4b_tx_sabme(l2sc, P1); - - i4b_T200_restart(l2sc); - - i4b_T203_stop(l2sc); -} - -/*---------------------------------------------------------------------------* - * routine CLEAR EXCEPTION CONDITIONS (Q.921 03/93 page 83) - *---------------------------------------------------------------------------*/ -void -i4b_clear_exception_conditions(l2_softc_t *l2sc) -{ - CRIT_VAR; - - CRIT_BEG; - -/*XXX -------------------------------------------------------------- */ -/*XXX is this really appropriate here or should it moved elsewhere ? */ - - i4b_Dcleanifq(&l2sc->i_queue); - - if(l2sc->ua_num != UA_EMPTY) - { - i4b_Dfreembuf(l2sc->ua_frame); - l2sc->ua_num = UA_EMPTY; - } -/*XXX -------------------------------------------------------------- */ - - l2sc->peer_busy = 0; - - l2sc->rej_excpt = 0; - - l2sc->own_busy = 0; - - l2sc->ack_pend = 0; - - CRIT_END; -} - -/*---------------------------------------------------------------------------* - * routine TRANSMIT ENQUIRE (Q.921 03/93 page 83) - *---------------------------------------------------------------------------*/ -void -i4b_transmit_enquire(l2_softc_t *l2sc) -{ - if(l2sc->own_busy) - i4b_tx_rnr_command(l2sc, P1); - else - i4b_tx_rr_command(l2sc, P1); - - l2sc->ack_pend = 0; - - i4b_T200_start(l2sc); -} - -/*---------------------------------------------------------------------------* - * routine NR ERROR RECOVERY (Q.921 03/93 page 83) - *---------------------------------------------------------------------------*/ -void -i4b_nr_error_recovery(l2_softc_t *l2sc) -{ - i4b_mdl_error_ind(l2sc, "i4b_nr_error_recovery", MDL_ERR_J); - - i4b_establish_data_link(l2sc); - - l2sc->l3initiated = 0; -} - -/*---------------------------------------------------------------------------* - * routine ENQUIRY RESPONSE (Q.921 03/93 page 84) - *---------------------------------------------------------------------------*/ -void -i4b_enquiry_response(l2_softc_t *l2sc) -{ - if(l2sc->own_busy) - i4b_tx_rnr_response(l2sc, F1); - else - i4b_tx_rr_response(l2sc, F1); - - l2sc->ack_pend = 0; -} - -/*---------------------------------------------------------------------------* - * routine INVOKE RETRANSMISSION (Q.921 03/93 page 84) - *---------------------------------------------------------------------------*/ -void -i4b_invoke_retransmission(l2_softc_t *l2sc, int nr) -{ - CRIT_VAR; - - CRIT_BEG; - - NDBGL2(L2_ERROR, "nr = %d", nr ); - - while(l2sc->vs != nr) - { - NDBGL2(L2_ERROR, "nr(%d) != vs(%d)", nr, l2sc->vs); - - M128DEC(l2sc->vs); - -/* XXXXXXXXXXXXXXXXX */ - - if((l2sc->ua_num != UA_EMPTY) && (l2sc->vs == l2sc->ua_num)) - { - if(_IF_QFULL(&l2sc->i_queue)) - { - NDBGL2(L2_ERROR, "ERROR, I-queue full!"); - } - else - { - IF_ENQUEUE(&l2sc->i_queue, l2sc->ua_frame); - l2sc->ua_num = UA_EMPTY; - } - } - else - { - NDBGL2(L2_ERROR, "ERROR, l2sc->vs = %d, l2sc->ua_num = %d ",l2sc->vs, l2sc->ua_num); - } - -/* XXXXXXXXXXXXXXXXX */ - - i4b_i_frame_queued_up(l2sc); - } - - CRIT_END; -} - -/*---------------------------------------------------------------------------* - * routine ACKNOWLEDGE PENDING (Q.921 03/93 p 70) - *---------------------------------------------------------------------------*/ -void -i4b_acknowledge_pending(l2_softc_t *l2sc) -{ - if(l2sc->ack_pend) - { - l2sc->ack_pend = 0; - i4b_tx_rr_response(l2sc, F0); - } -} - -/*---------------------------------------------------------------------------* - * i4b_print_frame - just print the hex contents of a frame - *---------------------------------------------------------------------------*/ -void -i4b_print_frame(int len, u_char *buf) -{ -#if DO_I4B_DEBUG - int i; - - if (!(i4b_l2_debug & L2_ERROR)) /* XXXXXXXXXXXXXXXXXXXXX */ - return; - - for(i = 0; i < len; i++) - printf(" 0x%x", buf[i]); - printf("\n"); -#endif -} - -/*---------------------------------------------------------------------------* - * i4b_print_l2var - print some l2softc vars - *---------------------------------------------------------------------------*/ -void -i4b_print_l2var(l2_softc_t *l2sc) -{ - NDBGL2(L2_ERROR, "unit%d V(R)=%d, V(S)=%d, V(A)=%d,ACKP=%d,PBSY=%d,OBSY=%d", - l2sc->unit, - l2sc->vr, - l2sc->vs, - l2sc->va, - l2sc->ack_pend, - l2sc->peer_busy, - l2sc->own_busy); -} - -/*---------------------------------------------------------------------------* - * got s or i frame, check if valid ack for last sent frame - *---------------------------------------------------------------------------*/ -void -i4b_rxd_ack(l2_softc_t *l2sc, int nr) -{ - -#ifdef NOTDEF - NDBGL2(L2_ERROR, "N(R)=%d, UA=%d, V(R)=%d, V(S)=%d, V(A)=%d", - nr, - l2sc->ua_num, - l2sc->vr, - l2sc->vs, - l2sc->va); -#endif - - if(l2sc->ua_num != UA_EMPTY) - { - CRIT_VAR; - - CRIT_BEG; - - M128DEC(nr); - - if(l2sc->ua_num != nr) - NDBGL2(L2_ERROR, "((N(R)-1)=%d) != (UA=%d) !!!", nr, l2sc->ua_num); - - i4b_Dfreembuf(l2sc->ua_frame); - l2sc->ua_num = UA_EMPTY; - - CRIT_END; - } -} - -/*---------------------------------------------------------------------------* - * if not already active, activate layer 1 - *---------------------------------------------------------------------------*/ -void -i4b_l1_activate(l2_softc_t *l2sc) -{ - if(l2sc->ph_active == PH_INACTIVE) - { - l2sc->ph_active = PH_ACTIVEPEND; - PH_Act_Req(l2sc->unit); - } -}; - -/*---------------------------------------------------------------------------* - * check for v(a) <= n(r) <= v(s) - * nr = receive sequence frame counter, va = acknowledge sequence frame - * counter and vs = transmit sequence frame counter - *---------------------------------------------------------------------------*/ -int -i4b_l2_nr_ok(int nr, int va, int vs) -{ - if((va > nr) && ((nr != 0) || (va != 127))) - { - NDBGL2(L2_ERROR, "ERROR, va = %d, nr = %d, vs = %d [1]", va, nr, vs); - return 0; /* fail */ - } - - if((nr > vs) && ((vs != 0) || (nr != 127))) - { - NDBGL2(L2_ERROR, "ERROR, va = %d, nr = %d, vs = %d [2]", va, nr, vs); - return 0; /* fail */ - } - return 1; /* good */ -} |