* packet driver support routines
struct pack
*pklines
[NPLINES
];
* start initial synchronization.
if (++pkactive
>= NPLINES
)
if ((pk
= (struct pack
*) malloc(sizeof (struct pack
))) == NULL
)
pkzero((caddr_t
) pk
, sizeof (struct pack
));
pk
->p_xsize
= pk
->p_rsize
= PACKSIZE
;
pk
->p_rwindow
= pk
->p_swindow
= WINDOWS
;
/* allocate input windows */
for (i
= 0; i
< pk
->p_rwindow
; i
++) {
if ((bp
= (char **) GETEPACK
) == NULL
)
*bp
= (char *) pk
->p_ipool
;
/* start synchronization */
pk
->p_msg
= pk
->p_rmsg
= M_INITA
;
for (i
= 0; i
< NPLINES
; i
++) {
if (pklines
[i
] == NULL
) {
while ((pk
->p_state
& LIVE
) == 0) {
* input framing and block checking.
* frame layout for most devices is:
* S|K|X|Y|C|Z| ... data ... |
* where S == initial synch byte
* K == encoded frame size (indexes pksizes[])
* X, Y == block check bytes
* Z == XOR of header (K^X^Y^C)
* data == 0 or more data bytes
1, 32, 64, 128, 256, 512, 1024, 2048, 4096, 1
* Pseudo-dma byte collection.
if (Conbad
> CONBAD
/* || Ntimeout > NTIMEOUT */)
for (tries
= 0; tries
< GETRIES
; ) {
p
= (caddr_t
) &pk
->p_ihbuf
;
if ((ret
= pkcget(ifn
, p
, 1)) < 0) {
/* set up retransmit or REJ */
if ((pk
->p_state
& LIVE
) == LIVE
)
ret
= pkcget(ifn
, p
, HDRSIZ
- 1);
PKDEBUG(4, "tries = %d\n", tries
);
h
= (struct header
* ) &pk
->p_ihbuf
;
hdchk
= p
[1] ^ p
[2] ^ p
[3] ^ p
[4];
sum
= (unsigned) *p
++ & 0377;
sum
|= (unsigned) *p
<< 8;
PKDEBUG(7, "rec h->cntl %o\n", (unsigned) h
->cntl
);
PKDEBUG(7, "bad header %o,", hdchk
);
PKDEBUG(7, "h->ccntl %o\n", h
->ccntl
);
if (h
->sum
+ h
->cntl
== CHECK
) {
PKDEBUG(7, "state - %o\n", pk
->p_state
);
PKDEBUG(7, "bad header %o\n", h
->cntl
);
if (k
&& pksizes
[k
] == pk
->p_rsize
) {
pk
->p_rpr
= h
->cntl
& MOD8
;
pk
->p_ipool
= (char **) *bp
;
PKDEBUG(7, "bp NULL %s\n", "");
ret
= pkcget(pk
->p_ifn
, (char *) bp
, pk
->p_rsize
);
PKASSERT(ret
!= -1, "PKGETPKT CAN't READ %d", ret
);
pkdata(h
->cntl
, h
->sum
, pk
, (char *) bp
);
register struct pack
*pk
;
if (pk
->p_state
& DRAINO
|| !(pk
->p_state
& LIVE
)) {
for(x
=pk
->p_pr
; x
!=t
; x
= (x
-1)&7) {
*bp
= (char *)pk
->p_ipool
;
pk
->p_ib
[x
] = (char *)bp
;
* Start transmission on output device associated with pk.
* For asynch devices (t_line==1) framing is
* imposed. For devices with framing and crc
* in the driver (t_line==2) the transfer is
* passed on to the driver.
p
= (caddr_t
) &pk
->p_ohbuf
;
*p
++ = hdchk
= pk
->p_lpsize
;
checkword
= pk
->p_osum
[x
] ^ (unsigned)(cntl
&0377);
checkword
= CHECK
- checkword
;
PKDEBUG(7, "send %o\n", (unsigned) cntl
);
p
= (caddr_t
) & pk
->p_ohbuf
;
ret
= write(pk
->p_ofn
, p
, HDRSIZ
);
PKASSERT(ret
== HDRSIZ
, "PKXSTART ret %d", ret
);
char buf
[PACKSIZE
+ HDRSIZ
], *b
;
for (i
= 0, b
= buf
; i
< HDRSIZ
; i
++)
for (i
= 0, p
= pk
->p_ob
[x
]; i
< pk
->p_rsize
; i
++)
GENERROR(buf
, pk
->p_rsize
+ HDRSIZ
);
ret
= write(pk
->p_ofn
, buf
, pk
->p_rsize
+ HDRSIZ
);
PKASSERT(ret
== pk
->p_rsize
+ HDRSIZ
,
pkmove(p1
, p2
, count
, flag
)
for (i
= 0; i
< count
; i
++)
* pkcget(fn, b, n) get n characters from input
* char *b; - buffer for characters
* int fn; - file descriptor
* int n; - requested number of characters
* n - number of characters returned
cgalarm() { longjmp(Getjbuf
, 1); }
PKDEBUG(4, "alarm %d\n", Ntimeout
);
signal(SIGALRM
, cgalarm
);
for (nchars
= 0; nchars
< n
; nchars
+= ret
) {
ret
= read(fn
, b
, n
- nchars
);
PKASSERT(ret
> 0, "PKCGET READ %d", ret
);
if (Errorrate
!= 0 && (rand() % Errorrate
) == 0) {
fprintf(stderr
, "gen err at %o, (%o), ", r
, (unsigned) *(p
+ r
));