]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
37839358 A |
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. | |
1c79356b | 11 | * |
37839358 A |
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 | |
1c79356b A |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
37839358 A |
16 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the |
17 | * License for the specific language governing rights and limitations | |
18 | * under the License. | |
1c79356b A |
19 | * |
20 | * @APPLE_LICENSE_HEADER_END@ | |
21 | */ | |
22 | /* dspWrite.c | |
23 | * From Mike Shoemaker v01.13 06/21/90 mbs for MacOS | |
24 | */ | |
25 | /* | |
26 | * Change log: | |
27 | * 06/29/95 - Modified to handle flow control for writing (Tuyen Nguyen) | |
28 | * 09/07/95 - Modified for performance (Tuyen Nguyen) | |
29 | * Modified for MP, 1996 by Tuyen Nguyen | |
30 | * Modified, April 9, 1997 by Tuyen Nguyen for MacOSX. | |
31 | */ | |
32 | ||
33 | #include <sys/errno.h> | |
34 | #include <sys/types.h> | |
35 | #include <sys/param.h> | |
36 | #include <machine/spl.h> | |
37 | #include <sys/systm.h> | |
38 | #include <sys/kernel.h> | |
39 | #include <sys/proc.h> | |
40 | #include <sys/filedesc.h> | |
41 | #include <sys/fcntl.h> | |
42 | #include <sys/mbuf.h> | |
43 | #include <sys/socket.h> | |
44 | ||
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> | |
51 | ||
52 | void completepb(); | |
53 | ||
54 | /* | |
55 | * FillSendQueue | |
56 | * | |
57 | * INPUTS: | |
58 | * sp stream | |
59 | * OUTPUTS: | |
60 | * none | |
61 | */ | |
62 | int FillSendQueue(sp, pb) /* (CCBPtr sp) */ | |
63 | register CCBPtr sp; | |
64 | register struct adspcmd *pb; /* The write PB we're playing with */ | |
65 | { | |
66 | gbuf_t *mb, *nmb; | |
67 | int eom; /* True if should set eom in header */ | |
68 | int cnt; /* # of bytes in this write */ | |
69 | int err = 0; | |
1c79356b A |
70 | |
71 | cnt = pb->u.ioParams.reqCount - pb->u.ioParams.actCount; | |
72 | eom = pb->u.ioParams.eom ? F_EOM : 0; | |
73 | ||
74 | if (cnt == 0 && eom == 0) /* Nothing to do here, complete it */ | |
75 | goto unlink; | |
76 | ||
77 | /* The 1st mbuf in the pb->mp chain (mb) is the adspcmd structure. | |
78 | The 2nd mbuf (nmb) will be the beginning of the data. */ | |
79 | mb = pb->mp; | |
80 | nmb = gbuf_cont(mb); | |
81 | if (gbuf_len(mb) > sizeof(struct adspcmd)) { | |
82 | if ((nmb = gbuf_dupb(mb)) == 0) { | |
83 | gbuf_wset(mb,sizeof(struct adspcmd)); | |
84 | err = errDSPQueueSize; | |
85 | goto unlink; | |
86 | } | |
87 | gbuf_wset(mb,sizeof(struct adspcmd)); | |
88 | gbuf_rinc(nmb,sizeof(struct adspcmd)); | |
89 | gbuf_cont(nmb) = gbuf_cont(mb); | |
90 | } else if (nmb == 0) { | |
91 | if ((nmb = gbuf_alloc(1, PRI_LO)) == 0) { | |
92 | err = errENOBUFS; | |
93 | goto unlink; | |
94 | } | |
95 | } | |
96 | gbuf_cont(mb) = 0; | |
97 | ||
1c79356b A |
98 | sp->sData = 1; /* note that there is data to send */ |
99 | if ((mb = sp->csbuf_mb)) { /* add to the current message */ | |
100 | gbuf_linkb(mb, nmb); | |
101 | } else | |
102 | sp->csbuf_mb = nmb; /* mark the buffer we are currently filling */ | |
103 | if (eom) { | |
104 | if ((mb = sp->sbuf_mb)) { | |
105 | while (gbuf_next(mb)) | |
106 | mb = gbuf_next(mb); | |
107 | gbuf_next(mb) = sp->csbuf_mb; /* add the current item */ | |
108 | } else | |
109 | sp->sbuf_mb = sp->csbuf_mb; | |
110 | sp->csbuf_mb = 0; /* if its done, no current buffer */ | |
111 | } | |
112 | pb->u.ioParams.actCount += cnt; /* Update count field in param blk */ | |
1c79356b A |
113 | |
114 | if (pb->u.ioParams.actCount == pb->u.ioParams.reqCount) { | |
115 | /* Write is complete */ | |
116 | unlink: | |
117 | if (pb->u.ioParams.flush) /* flush the send Q? */ | |
118 | sp->writeFlush = 1; | |
119 | ||
120 | pb->ioResult = err; | |
121 | if (err) | |
122 | atalk_notify(sp->gref, EIO); | |
123 | gbuf_freem(pb->mp); | |
124 | } | |
125 | ||
126 | return 0; | |
127 | } /* FillSendQueue */ | |
128 | ||
129 | /* | |
130 | * dspWrite | |
131 | * | |
132 | * INPUTS: | |
133 | * --> ccbRefNum refnum of connection end | |
134 | * --> reqCount requested number of bytes to write | |
135 | * --> dataPtr pointer to buffer for reading bytes into | |
136 | * --> eom one if end-of-message, zero otherwise | |
137 | * | |
138 | * OUTPUTS: | |
139 | * <-- actCount actual number of bytes written | |
140 | * | |
141 | * ERRORS: | |
142 | * errRefNum bad connection refnum | |
143 | * errState connection is not open | |
144 | * errAborted request aborted by Remove or Close call | |
145 | */ | |
146 | int adspWrite(sp, pb) /* (DSPPBPtr pb) */ | |
147 | CCBPtr sp; | |
148 | struct adspcmd *pb; | |
149 | { | |
1c79356b A |
150 | |
151 | if (sp == 0) { | |
152 | pb->ioResult = errRefNum; | |
153 | return EINVAL; /* no stream, so drop the message */ | |
154 | } | |
155 | ||
1c79356b A |
156 | if (sp->state != sOpen) { /* Not allowed */ |
157 | pb->ioResult = errState; | |
1c79356b A |
158 | atalk_notify(sp->gref, ENOTCONN); |
159 | gbuf_freem(pb->mp); | |
160 | return 0; | |
161 | } | |
162 | ||
163 | pb->u.ioParams.actCount = 0; /* Set # of bytes so far to zero */ | |
1c79356b A |
164 | |
165 | FillSendQueue(sp, pb); /* Copy from write param block to send queue */ | |
166 | ||
167 | CheckSend(sp); /* See if we should send anything */ | |
168 | return 0; | |
169 | } | |
170 | ||
171 | #ifdef notdef | |
172 | int adsp_check = 1; | |
173 | ||
174 | CheckQueue(sp) | |
175 | CCBPtr sp; | |
176 | { | |
177 | register gbuf_t *mp, *tmp; | |
178 | unsigned char current; | |
179 | int current_valid = 0; | |
180 | ||
181 | if (adsp_check == 0) | |
182 | return; | |
183 | if (mp = sp->sbuf_mb) { | |
184 | current = *mp->b_rptr; | |
185 | current_valid = 1; | |
186 | while (mp) { | |
187 | tmp = mp; | |
188 | while (tmp) { | |
189 | current = CheckData(tmp->b_rptr, tmp->b_wptr - tmp->b_rptr, | |
190 | current); | |
191 | tmp = tmp->b_cont; | |
192 | } | |
193 | mp = mp->b_next; | |
194 | } | |
195 | } | |
196 | if (mp = sp->csbuf_mb) { | |
197 | if (current_valid == 0) | |
198 | current = *mp->b_rptr; | |
199 | tmp = mp; | |
200 | while (tmp) { | |
201 | current = CheckData(tmp->b_rptr, tmp->b_wptr - tmp->b_rptr, | |
202 | current); | |
203 | tmp = tmp->b_cont; | |
204 | } | |
205 | } | |
206 | } | |
207 | ||
208 | ||
209 | int adsp_bad_block_count; | |
210 | char *adsp_bad_block; | |
211 | ||
212 | CheckData(block, size, current) | |
213 | char *block; | |
214 | int size; | |
215 | u_char current; | |
216 | { | |
217 | register int anError = 0; | |
218 | register int i; | |
219 | ||
220 | for (i = 0; i < size; i++) { | |
221 | if ((block[i] & 0xff) != (current & 0xff)) { | |
222 | if (!anError) { | |
223 | adsp_bad_block = block; | |
224 | } | |
225 | anError++; | |
226 | } | |
227 | current++; | |
228 | } | |
229 | ||
230 | if (anError) { | |
231 | adsp_bad_block_count++; | |
232 | } | |
233 | return current; | |
234 | } | |
235 | #endif |