static char sccsid
[] = "@(#)pk0.c 5.1 (Berkeley) 7/2/83";
char next
[8] ={ 1,2,3,4,5,6,7,0}; /* packet sequence numbers */
char mask
[8] ={ 1,2,4,010,020,040,0100,0200 };
struct pack
*pklines
[NPLINES
];
* Here are a couple of strange variables (rti!trt).
* pkactive is only incremented in pkopen.
* perhaps it should be decremented in pkclose?
* And pkdebug is set in gio.c but never used.
* receive control messages
register struct pack
*pk
;
fprintf(stderr
, "not cntl\n");
fprintf(stderr
, "%o ",c
);
pk
->p_xsize
= pksizes
[val
];
pk
->p_bits
= DTOM(pk
->p_xsize
);
if (pk
->p_state
& LIVE
) {
if ((pk
->p_state
& INITa
)==0) {
if ((pk
->p_state
&INITab
)==INITab
) {
if (val
==0 && pk
->p_state
&LIVE
) {
fprintf(stderr
, "alloc change not implemented\n");
fprintf(stderr
, "srj not implemented\n");
pk
->p_state
= DOWN
+RCLOSE
;
register struct pack
*pk
;
char m
, cntl
, *p
, imask
, **bp
;
int bad
,accept
,skip
,s
,t
,h
,cc
;
while ((imask
=pk
->p_imap
) == 0 && pk
->p_rcount
==0) {
SLEEP(&pk
->p_pr
, PKIPRI
);
* determine input window in m.
t
= (~(-1<<(int)(pk
->p_rwindow
))) <<x
;
* mark newly accepted input buffers
if ((imask
& mask
[x
]) == 0)
if (((cntl
=pk
->p_is
[x
])&0200)==0) {
bp
= (char **)pk
->p_ib
[x
];
*bp
= (char *)pk
->p_ipool
;
pk
->p_is
[x
] = ~(B_COPY
+B_MARK
);
sum
= (unsigned)chksum(pk
->p_ib
[x
], pk
->p_rsize
) ^ (unsigned)(cntl
&0377);
if (pk
->p_is
[seq
] & (B_COPY
| B_MARK
)) {
pk
->p_ib
[x
] = pk
->p_ib
[seq
];
pk
->p_is
[x
] = pk
->p_is
[seq
];
pk
->p_is
[seq
] = B_MARK
+B_SHORT
;
cc
= (unsigned)*p
++ & 0377;
pk
->p_isum
[seq
] = pk
->p_rsize
- cc
;
* scan window again turning marked buffers into
* COPY buffers and looking for missing sequence
for(x
=next
[pk
->p_pr
],t
=h
= -1; m
& mask
[x
]; x
= next
[x
]) {
if (pk
->p_is
[x
] & B_MARK
)
if (pk->p_is[x] & B_COPY) {
if (pk
->p_is
[x
] & B_COPY
) {
bp
= (char **)pk
->p_ib
[x
];
*bp
= (char *)pk
->p_ipool
;
register struct pack
*pk
;
cc
= MIN(pk
->p_isum
[x
], UCOUNT
);
if (pk
->p_isum
[x
] == 0) {
bp
= (char **)pk
->p_ib
[x
];
*bp
= (char *)pk
->p_ipool
;
register struct pack
*pk
;
if (pk
->p_state
&DOWN
|| !pk
->p_state
&LIVE
) {
while (pk
->p_xcount
>=pk
->p_swindow
) {
while (pk
->p_os
[x
]!=B_NULL
) {
cp
= pk
->p_ob
[x
] = GETEPACK
;
if ((int)UCOUNT
< pk
->p_xsize
) {
pk
->p_osum
[x
] = chksum(pk
->p_ob
[x
], pk
->p_xsize
);
pk
->p_os
[x
] = B_READY
+partial
;
register struct pack
*pk
;
for(x
=pk
->p_ps
; x
!=pk
->p_rpr
; ) {
if (pk
->p_os
[x
]&B_SENT
) {
FREEPACK(pk
->p_ob
[x
], pk
->p_bits
);
register struct pack
*pk
;
if (pk
->p_obusy
++ || OBUSY
) {
* find seq number and buffer state
pk
->p_nxtps
= next
[pk
->p_rpr
];
* Send control packet if indicated
if (pk
->p_msg
& ~M_RR
|| !(bstate
&B_READY
) ) {
x
+= pksize(pk
->p_rsize
);
* Don't send data packets if line is marked dead.
* Start transmission (or retransmission) of data packets.
if (bstate
& (B_READY
|B_SENT
)) {
x
= 0200+pk
->p_pr
+(seq
<<3);
* enable timeout if there's nothing to send
* and transmission buffers are languishing
* releasing space and turning off line discipline
register struct pack
*pk
;
while (pk
->p_xcount
&& pk
->p_state
&LIVE
) {
if (pk
->p_state
&(RCLOSE
+DOWN
) || ++i
> 2)
* try to exchange CLOSE messages
while ((pk
->p_state
&RCLOSE
)==0 && i
<2) {
SLEEP(&pk
->p_ps
, PKOPRI
);
rbits
= DTOM(pk
->p_rsize
);
if (pk
->p_os
[i
]!=B_NULL
) {
FREEPACK(pk
->p_ob
[i
],pk
->p_bits
);
if (pk
->p_is
[i
]!=B_NULL
) {
FREEPACK(pk
->p_ib
[i
],rbits
);
while (pk
->p_ipool
!= NULL
) {
pk
->p_ipool
= (char **)*bp
;
if (rcheck
!= pk
->p_rwindow
) {
fprintf(stderr
, "r short %d want %d\n",rcheck
,pk
->p_rwindow
);
fprintf(stderr
, "rcount = %d\n",pk
->p_rcount
);
fprintf(stderr
, "xcount = %d\n",pk
->p_xcount
);
FREEPACK((caddr_t
)pk
, npbits
);
register struct pack
*pk
;
pk
->p_ps
= pk
->p_pr
= pk
->p_rpr
= 0;
register unsigned sum
, t
;
sum
+= (unsigned)*s
++ & 0377;
if ((sum
&0xffff) <= (t
&0xffff)) {
register struct pack
*pk
;