]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
5d5c5d0d A |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. |
3 | * | |
8ad349bb | 4 | * @APPLE_LICENSE_OSREFERENCE_HEADER_START@ |
1c79356b | 5 | * |
8ad349bb A |
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 | |
14 | * agreement. | |
15 | * | |
16 | * Please obtain a copy of the License at | |
17 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
18 | * file. | |
19 | * | |
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. | |
27 | * | |
28 | * @APPLE_LICENSE_OSREFERENCE_HEADER_END@ | |
1c79356b A |
29 | */ |
30 | /* | |
31 | * RxAttn.c | |
32 | * | |
33 | * From v01.12 06/12/90 mbs | |
34 | * Modified, April 9, 1997 by Tuyen Nguyen for MacOSX. | |
35 | */ | |
36 | ||
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> | |
43 | #include <sys/proc.h> | |
44 | #include <sys/filedesc.h> | |
45 | #include <sys/fcntl.h> | |
46 | #include <sys/mbuf.h> | |
47 | #include <sys/socket.h> | |
48 | #include <sys/time.h> | |
49 | ||
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> | |
56 | ||
57 | /* | |
58 | * Used to search down queue of sessions for a session that matches | |
59 | * sender and source connection ID | |
60 | */ | |
61 | typedef struct | |
62 | { | |
63 | AddrUnion addr; | |
64 | word srcCID; | |
65 | } MATCH_SENDER, *MATCH_SENDERPtr; | |
66 | ||
67 | /* | |
68 | * MatchSender | |
69 | * | |
70 | */ | |
71 | ||
72 | static boolean MatchSender(sp, m) /* (CCBPtr sp, MATCH_SENDERPtr m) */ | |
73 | CCBPtr sp; | |
74 | MATCH_SENDERPtr m; | |
75 | { | |
76 | ||
77 | if (sp->state != sOpen && sp->state != sClosing) | |
78 | return 0; | |
79 | ||
80 | if (sp->remCID != m->srcCID) | |
81 | return 0; | |
82 | ||
83 | if (sp->remoteAddress.a.node != m->addr.a.node) | |
84 | return 0; | |
85 | if (sp->remoteAddress.a.socket != m->addr.a.socket) | |
86 | return 0; | |
87 | if (sp->remoteAddress.a.net && m->addr.a.net && | |
88 | (sp->remoteAddress.a.net != m->addr.a.net)) | |
89 | return 0; | |
90 | ||
91 | return 1; | |
92 | } | |
93 | ||
94 | ||
95 | /* | |
96 | * FindSender | |
97 | * | |
98 | * Given an ADSP Packet, find the stream it is associated with. | |
99 | * | |
100 | * This should only be used for ADSP Packets that could be received | |
101 | * by an OPEN connection. | |
102 | * | |
103 | * INPUTS: | |
104 | * Pointer to ADSP header & address of sender | |
105 | * OUTPUTS: | |
106 | * Pointer to stream if found, else 0 | |
107 | */ | |
108 | CCBPtr FindSender(f, a) /* (ADSP_FRAMEPtr f, AddrUnion a) */ | |
109 | ADSP_FRAMEPtr f; | |
110 | AddrUnion a; | |
111 | { | |
112 | MATCH_SENDER m; | |
113 | ||
114 | m.addr = a; | |
5d5c5d0d | 115 | m.srcCID = UAS_VALUE_NTOH(f->CID); |
1c79356b A |
116 | return (CCBPtr)qfind_m(AT_ADSP_STREAMS, &m, (ProcPtr)MatchSender); |
117 | } | |
118 | ||
119 | /* | |
120 | * RXAttention | |
121 | * | |
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 | |
125 | * | |
126 | * Interrupts are masked OFF at this point. | |
127 | * | |
128 | * INPUTS: | |
129 | * stream pointer | |
130 | * Pointer to ADSP header, | |
131 | * Length of header plus data | |
132 | * OUTPUTS: | |
133 | * Returns 1 if packet was ignored | |
134 | */ | |
135 | int RXAttention(sp, mp, f, len) /* (CCBPtr sp, ADSP_FRAMEPtr f, word len) */ | |
136 | CCBPtr sp; | |
137 | gbuf_t *mp; | |
138 | ADSP_FRAMEPtr f; | |
139 | int len; | |
140 | { | |
141 | int offset; | |
142 | struct adspcmd *pb; | |
143 | long diff; | |
144 | ||
145 | if (UAS_VALUE(f->pktRecvWdw)) /* This field must be 0 in attn pkts */ | |
146 | return 1; | |
147 | ||
148 | if ((f->descriptor == | |
149 | (char)(ADSP_ATTENTION_BIT | ADSP_ACK_REQ_BIT)) && /* Attention Data */ | |
150 | ((sp->userFlags & eAttention) == 0)) /* & he read the previous */ | |
151 | { | |
5d5c5d0d | 152 | diff = UAL_VALUE_NTOH(f->pktFirstByteSeq) - sp->attnRecvSeq; |
1c79356b A |
153 | if (diff > 0) /* Hey, he missed one */ |
154 | return 1; | |
155 | ||
156 | if (diff == 0) /* This is the one we expected */ | |
157 | { | |
158 | len -= ADSP_FRAME_LEN; /* remove adsp header */ | |
159 | if (len < 2) /* Poorly formed attn packet */ | |
160 | return 1; | |
161 | sp->attnCode = (f->data[0] << 8) + f->data[1]; /* Save attn code */ | |
162 | sp->attn_mb = mp; | |
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 */ | |
167 | ||
168 | /* Interrupts are off here, or otherwise we have to do | |
169 | * these three operations automically. | |
170 | */ | |
171 | sp->attnSize = len - 2; /* Tell user how many bytes */ | |
172 | ++sp->attnRecvSeq; | |
173 | /* Set flag saying we got attn message */ | |
174 | sp->userFlags |= eAttention; | |
175 | UrgentUser(sp); /* Notify user */ | |
176 | /* BEFORE sending acknowledge */ | |
177 | } /* in sequence */ | |
178 | ||
179 | sp->sendAttnAck = 1; /* send attention ack for dupl. & | |
180 | * expected data */ | |
181 | sp->callSend = 1; | |
182 | } /* Attn Data */ | |
183 | ||
184 | /* | |
185 | * Interrupts are OFF here, otherwise we have to do this atomically | |
186 | */ | |
187 | /* Check to see if this acknowledges anything */ | |
5d5c5d0d | 188 | if ((sp->attnSendSeq + 1) == UAL_VALUE_NTOH(f->pktNextRecvSeq)) { |
1c79356b A |
189 | sp->attnSendSeq++; |
190 | if ((pb = sp->sapb) == 0) { /* We never sent data ? !!! */ | |
191 | if (mp) | |
192 | gbuf_freem(mp); | |
193 | return 0; | |
194 | } | |
195 | ||
196 | sp->sapb = (struct adspcmd *)pb->qLink; /* Unlink from queue */ | |
197 | ||
198 | /* Remove timer */ | |
199 | RemoveTimerElem(&adspGlobal.fastTimers, &sp->AttnTimer); | |
200 | ||
201 | pb->ioResult = 0; | |
202 | if (gbuf_cont(pb->mp)) { | |
203 | gbuf_freem(gbuf_cont(pb->mp)); /* free the data */ | |
204 | gbuf_cont(pb->mp) = 0; | |
205 | } | |
206 | completepb(sp, pb); /* Done with the send attention */ | |
207 | ||
208 | if (sp->sapb) { /* Another send attention pending? */ | |
209 | sp->sendAttnData = 1; | |
210 | sp->callSend = 1; | |
211 | } else { | |
212 | if (sp->state == sClosing) /* this ack may allow us to close... */ | |
213 | CheckOkToClose(sp); | |
214 | } | |
215 | } | |
216 | if (mp) | |
217 | gbuf_freem(mp); | |
218 | return 0; | |
219 | } |