Annotation of Net2/netccitt/hd_timer.c, revision 1.1.1.2

1.1       root        1: /*
                      2:  * Copyright (c) University of British Columbia, 1984
                      3:  * Copyright (c) 1990 The Regents of the University of California.
                      4:  * All rights reserved.
                      5:  *
                      6:  * This code is derived from software contributed to Berkeley by
                      7:  * the Laboratory for Computation Vision and the Computer Science Department
                      8:  * of the University of British Columbia.
                      9:  *
                     10:  * Redistribution and use in source and binary forms, with or without
                     11:  * modification, are permitted provided that the following conditions
                     12:  * are met:
                     13:  * 1. Redistributions of source code must retain the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer.
                     15:  * 2. Redistributions in binary form must reproduce the above copyright
                     16:  *    notice, this list of conditions and the following disclaimer in the
                     17:  *    documentation and/or other materials provided with the distribution.
                     18:  * 3. All advertising materials mentioning features or use of this software
                     19:  *    must display the following acknowledgement:
                     20:  *     This product includes software developed by the University of
                     21:  *     California, Berkeley and its contributors.
                     22:  * 4. Neither the name of the University nor the names of its contributors
                     23:  *    may be used to endorse or promote products derived from this software
                     24:  *    without specific prior written permission.
                     25:  *
                     26:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     27:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     28:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     29:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     30:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     31:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     32:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     33:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     34:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     35:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     36:  * SUCH DAMAGE.
                     37:  *
1.1.1.2 ! root       38:  *     from: @(#)hd_timer.c    7.4 (Berkeley) 5/29/91
        !            39:  *     hd_timer.c,v 1.2 1993/05/20 04:12:09 cgd Exp
1.1       root       40:  */
                     41: 
                     42: #include "param.h"
                     43: #include "systm.h"
                     44: #include "mbuf.h"
                     45: #include "domain.h"
                     46: #include "socket.h"
                     47: #include "protosw.h"
                     48: #include "errno.h"
                     49: #include "time.h"
                     50: #include "kernel.h"
                     51: 
                     52: #include "../net/if.h"
                     53: 
                     54: #include "hdlc.h"
                     55: #include "hd_var.h"
                     56: #include "x25.h"
                     57: 
                     58: /*
                     59:  * these can be patched with adb if the
                     60:  * default values are inappropriate
                     61:  */
                     62: 
                     63: int    hd_t1 = T1;
                     64: int    hd_t3 = T3;
                     65: int    hd_n2 = N2;
                     66: 
                     67: /*
                     68:  *  HDLC TIMER 
                     69:  *
                     70:  *  This routine is called every 500ms by the kernel. Decrement timer by this
                     71:  *  amount - if expired then process the event.
                     72:  */
                     73: 
                     74: hd_timer ()
                     75: {
                     76:        register struct hdcb *hdp;
                     77:        register int s = splimp ();
                     78: 
                     79:        for (hdp = hdcbhead; hdp; hdp = hdp->hd_next) {
                     80:                if (hdp->hd_rrtimer && (--hdp->hd_rrtimer == 0)) {
                     81:                        if (hdp->hd_lasttxnr != hdp->hd_vr)
                     82:                                hd_writeinternal (hdp, RR, POLLOFF);
                     83:                }
                     84: 
                     85:                if (!(hdp->hd_timer && --hdp->hd_timer == 0))
                     86:                        continue;
                     87: 
                     88:                switch (hdp->hd_state) {
                     89:                case INIT: 
                     90:                case DISC_SENT:
                     91:                        hd_writeinternal (hdp, DISC, POLLON);
                     92:                        break;
                     93: 
                     94:                case ABM: 
                     95:                        if (hdp->hd_lastrxnr != hdp->hd_vs) {   /* XXX */
                     96:                                hdp->hd_timeouts++;
                     97:                                hd_resend_iframe (hdp);
                     98:                        }
                     99:                        break;
                    100: 
                    101:                case WAIT_SABM: 
                    102:                        hd_writeinternal (hdp, FRMR, POLLOFF);
                    103:                        if (++hdp->hd_retxcnt == hd_n2) {
                    104:                                hdp->hd_retxcnt = 0;
                    105:                                hd_writeinternal (hdp, SABM, POLLOFF);
                    106:                                hdp->hd_state = WAIT_UA;
                    107:                        }
                    108:                        break;
                    109: 
                    110:                case DM_SENT: 
                    111:                        if (++hdp->hd_retxcnt == hd_n2) {
                    112:                                /* Notify the packet level. */
                    113:                                (void) pk_ctlinput (PRC_LINKDOWN, hdp->hd_pkp);
                    114:                                hdp->hd_retxcnt = 0;
                    115:                                hdp->hd_state = SABM_SENT;
                    116:                                hd_writeinternal (hdp, SABM, POLLOFF);
                    117:                        } else
                    118:                                hd_writeinternal (hdp, DM, POLLOFF);
                    119:                        break;
                    120: 
                    121:                case WAIT_UA: 
                    122:                        if (++hdp->hd_retxcnt == hd_n2) {
                    123:                                hdp->hd_retxcnt = 0;
                    124:                                hd_writeinternal (hdp, DM, POLLOFF);
                    125:                                hdp->hd_state = DM_SENT;
                    126:                        } else
                    127:                                hd_writeinternal (hdp, SABM, POLLOFF);
                    128:                        break;
                    129: 
                    130:                case SABM_SENT: 
                    131:                        /* Do this indefinitely. */
                    132:                        hd_writeinternal (hdp, SABM, POLLON);
                    133:                        break;
                    134: 
                    135:                case DISCONNECTED:
                    136:                        /*
                    137:                         * Poll the interface driver flags waiting
                    138:                         * for the IFF_UP bit to come on.
                    139:                         */
                    140:                        if (hdp->hd_ifp->if_flags & IFF_UP)
                    141:                                hdp->hd_state = INIT;
                    142: 
                    143:                }
                    144:                SET_TIMER (hdp);
                    145:        }
                    146: 
                    147:        splx (s);
                    148: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.