]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netat/adsp_RxAttn.c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
28 * From v01.12 06/12/90 mbs
29 * Modified, April 9, 1997 by Tuyen Nguyen for MacOSX.
32 #include <sys/errno.h>
33 #include <sys/types.h>
34 #include <sys/param.h>
35 #include <machine/spl.h>
36 #include <sys/systm.h>
37 #include <sys/kernel.h>
39 #include <sys/filedesc.h>
40 #include <sys/fcntl.h>
42 #include <sys/socket.h>
45 #include <netat/sysglue.h>
46 #include <netat/appletalk.h>
47 #include <netat/at_pcb.h>
48 #include <netat/debug.h>
49 #include <netat/adsp.h>
50 #include <netat/adsp_internal.h>
53 * Used to search down queue of sessions for a session that matches
54 * sender and source connection ID
60 } MATCH_SENDER
, *MATCH_SENDERPtr
;
67 static boolean
MatchSender(sp
, m
) /* (CCBPtr sp, MATCH_SENDERPtr m) */
72 if (sp
->state
!= sOpen
&& sp
->state
!= sClosing
)
75 if (sp
->remCID
!= m
->srcCID
)
78 if (sp
->remoteAddress
.a
.node
!= m
->addr
.a
.node
)
80 if (sp
->remoteAddress
.a
.socket
!= m
->addr
.a
.socket
)
82 if (sp
->remoteAddress
.a
.net
&& m
->addr
.a
.net
&&
83 (sp
->remoteAddress
.a
.net
!= m
->addr
.a
.net
))
93 * Given an ADSP Packet, find the stream it is associated with.
95 * This should only be used for ADSP Packets that could be received
96 * by an OPEN connection.
99 * Pointer to ADSP header & address of sender
101 * Pointer to stream if found, else 0
103 CCBPtr
FindSender(f
, a
) /* (ADSP_FRAMEPtr f, AddrUnion a) */
110 m
.srcCID
= UAS_VALUE(f
->CID
);
111 return (CCBPtr
)qfind_m(AT_ADSP_STREAMS
, &m
, (ProcPtr
)MatchSender
);
117 * We just got an Attention Packet.
118 * See if it came from anybody we know.
119 * Then check to see if it is an attention data packet or acknowledgement
121 * Interrupts are masked OFF at this point.
125 * Pointer to ADSP header,
126 * Length of header plus data
128 * Returns 1 if packet was ignored
130 int RXAttention(sp
, mp
, f
, len
) /* (CCBPtr sp, ADSP_FRAMEPtr f, word len) */
140 if (UAS_VALUE(f
->pktRecvWdw
)) /* This field must be 0 in attn pkts */
143 if ((f
->descriptor
==
144 (char)(ADSP_ATTENTION_BIT
| ADSP_ACK_REQ_BIT
)) && /* Attention Data */
145 ((sp
->userFlags
& eAttention
) == 0)) /* & he read the previous */
147 diff
= netdw(UAL_VALUE(f
->pktFirstByteSeq
)) - sp
->attnRecvSeq
;
148 if (diff
> 0) /* Hey, he missed one */
151 if (diff
== 0) /* This is the one we expected */
153 len
-= ADSP_FRAME_LEN
; /* remove adsp header */
154 if (len
< 2) /* Poorly formed attn packet */
156 sp
->attnCode
= (f
->data
[0] << 8) + f
->data
[1]; /* Save attn code */
158 offset
= ((unsigned char *)&f
->data
[2]) - (unsigned char *)gbuf_rptr(mp
);
159 gbuf_rinc(mp
,offset
);
160 sp
->attnPtr
= (unsigned char *)gbuf_rptr(mp
);
161 mp
= 0; /* mp has been queued don't free it */
163 /* Interrupts are off here, or otherwise we have to do
164 * these three operations automically.
166 sp
->attnSize
= len
- 2; /* Tell user how many bytes */
168 /* Set flag saying we got attn message */
169 sp
->userFlags
|= eAttention
;
170 UrgentUser(sp
); /* Notify user */
171 /* BEFORE sending acknowledge */
174 sp
->sendAttnAck
= 1; /* send attention ack for dupl. &
180 * Interrupts are OFF here, otherwise we have to do this atomically
182 /* Check to see if this acknowledges anything */
183 if ((sp
->attnSendSeq
+ 1) == netdw(UAL_VALUE(f
->pktNextRecvSeq
))) {
185 if ((pb
= sp
->sapb
) == 0) { /* We never sent data ? !!! */
191 sp
->sapb
= (struct adspcmd
*)pb
->qLink
; /* Unlink from queue */
194 RemoveTimerElem(&adspGlobal
.fastTimers
, &sp
->AttnTimer
);
197 if (gbuf_cont(pb
->mp
)) {
198 gbuf_freem(gbuf_cont(pb
->mp
)); /* free the data */
199 gbuf_cont(pb
->mp
) = 0;
201 completepb(sp
, pb
); /* Done with the send attention */
203 if (sp
->sapb
) { /* Another send attention pending? */
204 sp
->sendAttnData
= 1;
207 if (sp
->state
== sClosing
) /* this ack may allow us to close... */