]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netat/adsp_RxAttn.c
2c398c82d86c74d00bb0fe54acb032028100141a
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_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 License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
31 * From v01.12 06/12/90 mbs
32 * Modified, April 9, 1997 by Tuyen Nguyen for MacOSX.
35 #include <sys/errno.h>
36 #include <sys/types.h>
37 #include <sys/param.h>
38 #include <machine/spl.h>
39 #include <sys/systm.h>
40 #include <sys/kernel.h>
42 #include <sys/filedesc.h>
43 #include <sys/fcntl.h>
45 #include <sys/socket.h>
48 #include <netat/sysglue.h>
49 #include <netat/appletalk.h>
50 #include <netat/at_pcb.h>
51 #include <netat/debug.h>
52 #include <netat/adsp.h>
53 #include <netat/adsp_internal.h>
56 * Used to search down queue of sessions for a session that matches
57 * sender and source connection ID
63 } MATCH_SENDER
, *MATCH_SENDERPtr
;
70 static boolean
MatchSender(sp
, m
) /* (CCBPtr sp, MATCH_SENDERPtr m) */
75 if (sp
->state
!= sOpen
&& sp
->state
!= sClosing
)
78 if (sp
->remCID
!= m
->srcCID
)
81 if (sp
->remoteAddress
.a
.node
!= m
->addr
.a
.node
)
83 if (sp
->remoteAddress
.a
.socket
!= m
->addr
.a
.socket
)
85 if (sp
->remoteAddress
.a
.net
&& m
->addr
.a
.net
&&
86 (sp
->remoteAddress
.a
.net
!= m
->addr
.a
.net
))
96 * Given an ADSP Packet, find the stream it is associated with.
98 * This should only be used for ADSP Packets that could be received
99 * by an OPEN connection.
102 * Pointer to ADSP header & address of sender
104 * Pointer to stream if found, else 0
106 CCBPtr
FindSender(f
, a
) /* (ADSP_FRAMEPtr f, AddrUnion a) */
113 m
.srcCID
= UAS_VALUE(f
->CID
);
114 return (CCBPtr
)qfind_m(AT_ADSP_STREAMS
, &m
, (ProcPtr
)MatchSender
);
120 * We just got an Attention Packet.
121 * See if it came from anybody we know.
122 * Then check to see if it is an attention data packet or acknowledgement
124 * Interrupts are masked OFF at this point.
128 * Pointer to ADSP header,
129 * Length of header plus data
131 * Returns 1 if packet was ignored
133 int RXAttention(sp
, mp
, f
, len
) /* (CCBPtr sp, ADSP_FRAMEPtr f, word len) */
143 if (UAS_VALUE(f
->pktRecvWdw
)) /* This field must be 0 in attn pkts */
146 if ((f
->descriptor
==
147 (char)(ADSP_ATTENTION_BIT
| ADSP_ACK_REQ_BIT
)) && /* Attention Data */
148 ((sp
->userFlags
& eAttention
) == 0)) /* & he read the previous */
150 diff
= netdw(UAL_VALUE(f
->pktFirstByteSeq
)) - sp
->attnRecvSeq
;
151 if (diff
> 0) /* Hey, he missed one */
154 if (diff
== 0) /* This is the one we expected */
156 len
-= ADSP_FRAME_LEN
; /* remove adsp header */
157 if (len
< 2) /* Poorly formed attn packet */
159 sp
->attnCode
= (f
->data
[0] << 8) + f
->data
[1]; /* Save attn code */
161 offset
= ((unsigned char *)&f
->data
[2]) - (unsigned char *)gbuf_rptr(mp
);
162 gbuf_rinc(mp
,offset
);
163 sp
->attnPtr
= (unsigned char *)gbuf_rptr(mp
);
164 mp
= 0; /* mp has been queued don't free it */
166 /* Interrupts are off here, or otherwise we have to do
167 * these three operations automically.
169 sp
->attnSize
= len
- 2; /* Tell user how many bytes */
171 /* Set flag saying we got attn message */
172 sp
->userFlags
|= eAttention
;
173 UrgentUser(sp
); /* Notify user */
174 /* BEFORE sending acknowledge */
177 sp
->sendAttnAck
= 1; /* send attention ack for dupl. &
183 * Interrupts are OFF here, otherwise we have to do this atomically
185 /* Check to see if this acknowledges anything */
186 if ((sp
->attnSendSeq
+ 1) == netdw(UAL_VALUE(f
->pktNextRecvSeq
))) {
188 if ((pb
= sp
->sapb
) == 0) { /* We never sent data ? !!! */
194 sp
->sapb
= (struct adspcmd
*)pb
->qLink
; /* Unlink from queue */
197 RemoveTimerElem(&adspGlobal
.fastTimers
, &sp
->AttnTimer
);
200 if (gbuf_cont(pb
->mp
)) {
201 gbuf_freem(gbuf_cont(pb
->mp
)); /* free the data */
202 gbuf_cont(pb
->mp
) = 0;
204 completepb(sp
, pb
); /* Done with the send attention */
206 if (sp
->sapb
) { /* Another send attention pending? */
207 sp
->sendAttnData
= 1;
210 if (sp
->state
== sClosing
) /* this ack may allow us to close... */