1*41588Ssklower /* Copyright (c) University of British Columbia, 1984 */ 2*41588Ssklower 3*41588Ssklower #include "../h/param.h" 4*41588Ssklower #include "../h/systm.h" 5*41588Ssklower #include "../h/mbuf.h" 6*41588Ssklower #include "../h/domain.h" 7*41588Ssklower #include "../h/socket.h" 8*41588Ssklower #include "../h/protosw.h" 9*41588Ssklower #include "../h/errno.h" 10*41588Ssklower #include "../h/time.h" 11*41588Ssklower #include "../h/kernel.h" 12*41588Ssklower 13*41588Ssklower #include "../net/if.h" 14*41588Ssklower 15*41588Ssklower #include "../netccitt/hdlc.h" 16*41588Ssklower #include "../netccitt/hd_var.h" 17*41588Ssklower #include "../netccitt/x25.h" 18*41588Ssklower 19*41588Ssklower /* 20*41588Ssklower * these can be patched with adb if the 21*41588Ssklower * default values are inappropriate 22*41588Ssklower */ 23*41588Ssklower 24*41588Ssklower int hd_t1 = T1; 25*41588Ssklower int hd_t3 = T3; 26*41588Ssklower int hd_n2 = N2; 27*41588Ssklower 28*41588Ssklower /* 29*41588Ssklower * HDLC TIMER 30*41588Ssklower * 31*41588Ssklower * This routine is called every 500ms by the kernel. Decrement timer by this 32*41588Ssklower * amount - if expired then process the event. 33*41588Ssklower */ 34*41588Ssklower 35*41588Ssklower hd_timer () 36*41588Ssklower { 37*41588Ssklower register struct hdcb *hdp; 38*41588Ssklower register int s = splimp (); 39*41588Ssklower 40*41588Ssklower for (hdp = hdcbhead; hdp; hdp = hdp->hd_next) { 41*41588Ssklower if (hdp->hd_rrtimer && (--hdp->hd_rrtimer == 0)) { 42*41588Ssklower if (hdp->hd_lasttxnr != hdp->hd_vr) 43*41588Ssklower hd_writeinternal (hdp, RR, POLLOFF); 44*41588Ssklower } 45*41588Ssklower 46*41588Ssklower if (!(hdp->hd_timer && --hdp->hd_timer == 0)) 47*41588Ssklower continue; 48*41588Ssklower 49*41588Ssklower switch (hdp->hd_state) { 50*41588Ssklower case INIT: 51*41588Ssklower case DISC_SENT: 52*41588Ssklower hd_writeinternal (hdp, DISC, POLLON); 53*41588Ssklower break; 54*41588Ssklower 55*41588Ssklower case ABM: 56*41588Ssklower if (hdp->hd_lastrxnr != hdp->hd_vs) { /* XXX */ 57*41588Ssklower hdp->hd_timeouts++; 58*41588Ssklower hd_resend_iframe (hdp); 59*41588Ssklower } 60*41588Ssklower break; 61*41588Ssklower 62*41588Ssklower case WAIT_SABM: 63*41588Ssklower hd_writeinternal (hdp, FRMR, POLLOFF); 64*41588Ssklower if (++hdp->hd_retxcnt == hd_n2) { 65*41588Ssklower hdp->hd_retxcnt = 0; 66*41588Ssklower hd_writeinternal (hdp, SABM, POLLOFF); 67*41588Ssklower hdp->hd_state = WAIT_UA; 68*41588Ssklower } 69*41588Ssklower break; 70*41588Ssklower 71*41588Ssklower case DM_SENT: 72*41588Ssklower if (++hdp->hd_retxcnt == hd_n2) { 73*41588Ssklower /* Notify the packet level. */ 74*41588Ssklower (void) pk_ctlinput (PRC_LINKDOWN, hdp->hd_xcp); 75*41588Ssklower hdp->hd_retxcnt = 0; 76*41588Ssklower hdp->hd_state = SABM_SENT; 77*41588Ssklower hd_writeinternal (hdp, SABM, POLLOFF); 78*41588Ssklower } else 79*41588Ssklower hd_writeinternal (hdp, DM, POLLOFF); 80*41588Ssklower break; 81*41588Ssklower 82*41588Ssklower case WAIT_UA: 83*41588Ssklower if (++hdp->hd_retxcnt == hd_n2) { 84*41588Ssklower hdp->hd_retxcnt = 0; 85*41588Ssklower hd_writeinternal (hdp, DM, POLLOFF); 86*41588Ssklower hdp->hd_state = DM_SENT; 87*41588Ssklower } else 88*41588Ssklower hd_writeinternal (hdp, SABM, POLLOFF); 89*41588Ssklower break; 90*41588Ssklower 91*41588Ssklower case SABM_SENT: 92*41588Ssklower /* Do this indefinitely. */ 93*41588Ssklower hd_writeinternal (hdp, SABM, POLLON); 94*41588Ssklower break; 95*41588Ssklower 96*41588Ssklower case DISCONNECTED: 97*41588Ssklower /* 98*41588Ssklower * Poll the interface driver flags waiting 99*41588Ssklower * for the IFF_UP bit to come on. 100*41588Ssklower */ 101*41588Ssklower if (hdp->hd_ifp->if_flags & IFF_UP) 102*41588Ssklower hdp->hd_state = INIT; 103*41588Ssklower 104*41588Ssklower } 105*41588Ssklower SET_TIMER (hdp); 106*41588Ssklower } 107*41588Ssklower 108*41588Ssklower splx (s); 109*41588Ssklower } 110