Annotation of kernel/bsd/netccitt/hd_timer.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

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