]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netat/adsp_RxAttn.c
54f112a6a1d299a865c268746cea2e0c02145b4f
2 * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
33 * From v01.12 06/12/90 mbs
34 * Modified, April 9, 1997 by Tuyen Nguyen for MacOSX.
37 #include <sys/errno.h>
38 #include <sys/types.h>
39 #include <sys/param.h>
40 #include <machine/spl.h>
41 #include <sys/systm.h>
42 #include <sys/kernel.h>
44 #include <sys/filedesc.h>
45 #include <sys/fcntl.h>
47 #include <sys/socket.h>
50 #include <netat/sysglue.h>
51 #include <netat/appletalk.h>
52 #include <netat/at_pcb.h>
53 #include <netat/debug.h>
54 #include <netat/adsp.h>
55 #include <netat/adsp_internal.h>
58 * Used to search down queue of sessions for a session that matches
59 * sender and source connection ID
65 } MATCH_SENDER
, *MATCH_SENDERPtr
;
72 static boolean
MatchSender(sp
, m
) /* (CCBPtr sp, MATCH_SENDERPtr m) */
77 if (sp
->state
!= sOpen
&& sp
->state
!= sClosing
)
80 if (sp
->remCID
!= m
->srcCID
)
83 if (sp
->remoteAddress
.a
.node
!= m
->addr
.a
.node
)
85 if (sp
->remoteAddress
.a
.socket
!= m
->addr
.a
.socket
)
87 if (sp
->remoteAddress
.a
.net
&& m
->addr
.a
.net
&&
88 (sp
->remoteAddress
.a
.net
!= m
->addr
.a
.net
))
98 * Given an ADSP Packet, find the stream it is associated with.
100 * This should only be used for ADSP Packets that could be received
101 * by an OPEN connection.
104 * Pointer to ADSP header & address of sender
106 * Pointer to stream if found, else 0
108 CCBPtr
FindSender(f
, a
) /* (ADSP_FRAMEPtr f, AddrUnion a) */
115 m
.srcCID
= UAS_VALUE(f
->CID
);
116 return (CCBPtr
)qfind_m(AT_ADSP_STREAMS
, &m
, (ProcPtr
)MatchSender
);
122 * We just got an Attention Packet.
123 * See if it came from anybody we know.
124 * Then check to see if it is an attention data packet or acknowledgement
126 * Interrupts are masked OFF at this point.
130 * Pointer to ADSP header,
131 * Length of header plus data
133 * Returns 1 if packet was ignored
135 int RXAttention(sp
, mp
, f
, len
) /* (CCBPtr sp, ADSP_FRAMEPtr f, word len) */
145 if (UAS_VALUE(f
->pktRecvWdw
)) /* This field must be 0 in attn pkts */
148 if ((f
->descriptor
==
149 (char)(ADSP_ATTENTION_BIT
| ADSP_ACK_REQ_BIT
)) && /* Attention Data */
150 ((sp
->userFlags
& eAttention
) == 0)) /* & he read the previous */
152 diff
= netdw(UAL_VALUE(f
->pktFirstByteSeq
)) - sp
->attnRecvSeq
;
153 if (diff
> 0) /* Hey, he missed one */
156 if (diff
== 0) /* This is the one we expected */
158 len
-= ADSP_FRAME_LEN
; /* remove adsp header */
159 if (len
< 2) /* Poorly formed attn packet */
161 sp
->attnCode
= (f
->data
[0] << 8) + f
->data
[1]; /* Save attn code */
163 offset
= ((unsigned char *)&f
->data
[2]) - (unsigned char *)gbuf_rptr(mp
);
164 gbuf_rinc(mp
,offset
);
165 sp
->attnPtr
= (unsigned char *)gbuf_rptr(mp
);
166 mp
= 0; /* mp has been queued don't free it */
168 /* Interrupts are off here, or otherwise we have to do
169 * these three operations automically.
171 sp
->attnSize
= len
- 2; /* Tell user how many bytes */
173 /* Set flag saying we got attn message */
174 sp
->userFlags
|= eAttention
;
175 UrgentUser(sp
); /* Notify user */
176 /* BEFORE sending acknowledge */
179 sp
->sendAttnAck
= 1; /* send attention ack for dupl. &
185 * Interrupts are OFF here, otherwise we have to do this atomically
187 /* Check to see if this acknowledges anything */
188 if ((sp
->attnSendSeq
+ 1) == netdw(UAL_VALUE(f
->pktNextRecvSeq
))) {
190 if ((pb
= sp
->sapb
) == 0) { /* We never sent data ? !!! */
196 sp
->sapb
= (struct adspcmd
*)pb
->qLink
; /* Unlink from queue */
199 RemoveTimerElem(&adspGlobal
.fastTimers
, &sp
->AttnTimer
);
202 if (gbuf_cont(pb
->mp
)) {
203 gbuf_freem(gbuf_cont(pb
->mp
)); /* free the data */
204 gbuf_cont(pb
->mp
) = 0;
206 completepb(sp
, pb
); /* Done with the send attention */
208 if (sp
->sapb
) { /* Another send attention pending? */
209 sp
->sendAttnData
= 1;
212 if (sp
->state
== sClosing
) /* this ack may allow us to close... */