]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netat/adsp_RxAttn.c
c4792ddb6629a2473e8d381b398506d00916ee93
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
25 * From v01.12 06/12/90 mbs
26 * Modified, April 9, 1997 by Tuyen Nguyen for MacOSX.
29 #include <sys/errno.h>
30 #include <sys/types.h>
31 #include <sys/param.h>
32 #include <machine/spl.h>
33 #include <sys/systm.h>
34 #include <sys/kernel.h>
36 #include <sys/filedesc.h>
37 #include <sys/fcntl.h>
39 #include <sys/socket.h>
42 #include <netat/sysglue.h>
43 #include <netat/appletalk.h>
44 #include <netat/at_pcb.h>
45 #include <netat/debug.h>
46 #include <netat/adsp.h>
47 #include <netat/adsp_internal.h>
50 * Used to search down queue of sessions for a session that matches
51 * sender and source connection ID
57 } MATCH_SENDER
, *MATCH_SENDERPtr
;
64 static boolean
MatchSender(sp
, m
) /* (CCBPtr sp, MATCH_SENDERPtr m) */
69 if (sp
->state
!= sOpen
&& sp
->state
!= sClosing
)
72 if (sp
->remCID
!= m
->srcCID
)
75 if (sp
->remoteAddress
.a
.node
!= m
->addr
.a
.node
)
77 if (sp
->remoteAddress
.a
.socket
!= m
->addr
.a
.socket
)
79 if (sp
->remoteAddress
.a
.net
&& m
->addr
.a
.net
&&
80 (sp
->remoteAddress
.a
.net
!= m
->addr
.a
.net
))
90 * Given an ADSP Packet, find the stream it is associated with.
92 * This should only be used for ADSP Packets that could be received
93 * by an OPEN connection.
96 * Pointer to ADSP header & address of sender
98 * Pointer to stream if found, else 0
100 CCBPtr
FindSender(f
, a
) /* (ADSP_FRAMEPtr f, AddrUnion a) */
107 m
.srcCID
= UAS_VALUE_NTOH(f
->CID
);
108 return (CCBPtr
)qfind_m(AT_ADSP_STREAMS
, &m
, (ProcPtr
)MatchSender
);
114 * We just got an Attention Packet.
115 * See if it came from anybody we know.
116 * Then check to see if it is an attention data packet or acknowledgement
118 * Interrupts are masked OFF at this point.
122 * Pointer to ADSP header,
123 * Length of header plus data
125 * Returns 1 if packet was ignored
127 int RXAttention(sp
, mp
, f
, len
) /* (CCBPtr sp, ADSP_FRAMEPtr f, word len) */
137 if (UAS_VALUE(f
->pktRecvWdw
)) /* This field must be 0 in attn pkts */
140 if ((f
->descriptor
==
141 (char)(ADSP_ATTENTION_BIT
| ADSP_ACK_REQ_BIT
)) && /* Attention Data */
142 ((sp
->userFlags
& eAttention
) == 0)) /* & he read the previous */
144 diff
= UAL_VALUE_NTOH(f
->pktFirstByteSeq
) - sp
->attnRecvSeq
;
145 if (diff
> 0) /* Hey, he missed one */
148 if (diff
== 0) /* This is the one we expected */
150 len
-= ADSP_FRAME_LEN
; /* remove adsp header */
151 if (len
< 2) /* Poorly formed attn packet */
153 sp
->attnCode
= (f
->data
[0] << 8) + f
->data
[1]; /* Save attn code */
155 offset
= ((unsigned char *)&f
->data
[2]) - (unsigned char *)gbuf_rptr(mp
);
156 gbuf_rinc(mp
,offset
);
157 sp
->attnPtr
= (unsigned char *)gbuf_rptr(mp
);
158 mp
= 0; /* mp has been queued don't free it */
160 /* Interrupts are off here, or otherwise we have to do
161 * these three operations automically.
163 sp
->attnSize
= len
- 2; /* Tell user how many bytes */
165 /* Set flag saying we got attn message */
166 sp
->userFlags
|= eAttention
;
167 UrgentUser(sp
); /* Notify user */
168 /* BEFORE sending acknowledge */
171 sp
->sendAttnAck
= 1; /* send attention ack for dupl. &
177 * Interrupts are OFF here, otherwise we have to do this atomically
179 /* Check to see if this acknowledges anything */
180 if ((sp
->attnSendSeq
+ 1) == UAL_VALUE_NTOH(f
->pktNextRecvSeq
)) {
182 if ((pb
= sp
->sapb
) == 0) { /* We never sent data ? !!! */
188 sp
->sapb
= (struct adspcmd
*)pb
->qLink
; /* Unlink from queue */
191 RemoveTimerElem(&adspGlobal
.fastTimers
, &sp
->AttnTimer
);
194 if (gbuf_cont(pb
->mp
)) {
195 gbuf_freem(gbuf_cont(pb
->mp
)); /* free the data */
196 gbuf_cont(pb
->mp
) = 0;
198 completepb(sp
, pb
); /* Done with the send attention */
200 if (sp
->sapb
) { /* Another send attention pending? */
201 sp
->sendAttnData
= 1;
204 if (sp
->state
== sClosing
) /* this ack may allow us to close... */