|
|
1.1 root 1: /*
2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3: *
4: * @APPLE_LICENSE_HEADER_START@
5: *
6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7: * Reserved. This file contains Original Code and/or Modifications of
8: * Original Code as defined in and that are subject to the Apple Public
9: * Source License Version 1.1 (the "License"). You may not use this file
10: * except in compliance with the License. Please obtain a copy of the
11: * License at http://www.apple.com/publicsource and read it before using
12: * this file.
13: *
14: * The Original Code and all software distributed under the License are
15: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19: * License for the specific language governing rights and limitations
20: * under the License.
21: *
22: * @APPLE_LICENSE_HEADER_END@
23: */
24:
25:
26: #include <adsp_local.h>
27:
28: /*
29: * RXFReset
30: *
31: * We just got a Forward Reset Packet.
32: *
33: * Called with interrupts OFF
34: *
35: * INPUTS:
36: * stream pointer
37: * Pointer to ADSP header,
38: * OUTPUTS:
39: * Returns 1 if packet was ignored
40: */
41: int RXFReset(sp, f) /* (CCBPtr sp, ADSP_FRAMEPtr f) */
42: CCBPtr sp;
43: ADSP_FRAMEPtr f;
44: {
45: unsigned int pktFirstByteSeq;
46: unsigned int hi;
47: register gbuf_t *mp;
48: register struct adspcmd *pb;
49: int s;
50:
51: ATDISABLE(s, sp->lock);
52: pktFirstByteSeq = netdw(UAL_VALUE(f->pktFirstByteSeq));
53:
54: hi = sp->recvSeq + CalcRecvWdw(sp);
55:
56: /*
57: * Must do this with interrupts OFF
58: */
59: if (BETWEEN(sp->recvSeq, pktFirstByteSeq, hi)) /* Is this acceptable? */
60: {
61: struct adspcmd *qhead;
62:
63: sp->recvSeq = pktFirstByteSeq;
64: while (mp = sp->rbuf_mb) { /* clear the receive queue */
65: sp->rbuf_mb = gbuf_next(mp);
66: gbuf_freem(mp);
67: }
68: if (sp->crbuf_mb) {
69: gbuf_freem(sp->crbuf_mb);
70: sp->crbuf_mb = 0;
71: }
72: sp->rData = 0;
73: sp->rbufFull = 0;
74: sp->userFlags |= eFwdReset; /* Set forward reset received Flag */
75:
76: mp = gbuf_alloc(sizeof(struct adspcmd), PRI_HI);
77: pb = (struct adspcmd *)gbuf_rptr(mp);
78: gbuf_winc(mp,sizeof(struct adspcmd));
79: pb->ioc = 0;
80: pb->mp = mp;
81:
82: pb->csCode = dspReset;
83: pb->ioResult = 0;
84: completepb(sp, pb);
85: sp->userFlags &= ~eFwdReset;
86: }
87:
88: if (LTE(pktFirstByteSeq, hi)) {
89: sp->sendCtl |= B_CTL_FRESETACK; /* Ack it if it's OK, or a duplicate */
90: sp->callSend = 1;
91: }
92:
93: ATENABLE(s, sp->lock);
94: return 0;
95: }
96:
97:
98: /*
99: * RXFResetAck
100: *
101: * We just got a Forward Reset Acknowledgement packet
102: *
103: * Called with interrupts OFF
104: *
105: * INPUTS:
106: * stream pointer
107: * Pointer to ADSP header,
108: * OUTPUTS:
109: * Returns 1 if packet was ignored
110: */
111: int RXFResetAck(sp, f) /* (CCBPtr sp, ADSP_FRAMEPtr f) */
112: CCBPtr sp;
113: ADSP_FRAMEPtr f;
114: {
115: unsigned int PktNextRecvSeq;
116: int s;
117:
118: if (sp->frpb == 0) /* Not expecting frwd reset Ack packet */
119: return 1;
120:
121: ATDISABLE(s, sp->lock);
122: PktNextRecvSeq = netdw(UAL_VALUE(f->pktNextRecvSeq));
123:
124: if (BETWEEN(sp->sendSeq, PktNextRecvSeq, sp->sendWdwSeq+1)) {
125: struct adspcmd *pb;
126:
127: RemoveTimerElem(&adspGlobal.fastTimers, &sp->ResetTimer);
128: /* Remove timer */
129:
130: /*
131: * Interrupts are OFF here while we muck with the linked list
132: */
133: pb = sp->frpb; /* Unlink copy of user's parameter block */
134: sp->frpb = (struct adspcmd *)pb->qLink;
135:
136: pb->ioResult = 0;
137: completepb(sp, pb); /* complete(pb, 0); */
138:
139: if (sp->state == sClosing) /* this ack may allow us to close... */
140: CheckOkToClose(sp);
141:
142: if (sp->frpb) /* Another to send? */
143: {
144: sp->callSend = 1;
145: sp->sendCtl |= B_CTL_FRESET;
146: }
147: }
148:
149: ATENABLE(s, sp->lock);
150: return 0;
151: }
152:
153:
154: /*
155: * dspReset
156: *
157: * INPUTS:
158: * --> ccbRefNum refnum of connection end
159: *
160: * OUTPUTS:
161: * none
162: *
163: * ERRORS:
164: * errRefNum bad connection refnum
165: * errState connection is not open
166: * errAborted request aborted by Remove or Close call
167: */
168: int adspReset(sp, pb) /* (DSPPBPtr pb) */
169: CCBPtr sp;
170: struct adspcmd *pb;
171: {
172: int s;
173: OSErr err;
174: struct adspcmd *qhead;
175: register gbuf_t *mp;
176: register struct adspcmd *rpb;
177:
178: if (sp == 0) {
179: pb->ioResult = errRefNum;
180: return EINVAL;
181: }
182:
183: if (sp->state != sOpen) {
184: pb->ioResult = errState;
185: return EINVAL;
186: }
187:
188: ATDISABLE(s, sp->lock);
189:
190: while (mp = sp->sbuf_mb) { /* clear the send queue */
191: sp->sbuf_mb = gbuf_next(mp);
192: gbuf_freem(mp);
193: }
194: if (sp->csbuf_mb) {
195: gbuf_freem(sp->csbuf_mb);
196: sp->csbuf_mb = 0;
197: }
198: sp->sData = 0;
199: sp->writeFlush = 0;
200: sp->sendCtl |= B_CTL_FRESET;
201:
202: sp->firstRtmtSeq = sp->sendSeq; /* Reset sequence #'s */
203: if (mp = gbuf_copym(pb->mp)) { /* copy the parameter block */
204: adspioc_ack(0, pb->ioc, pb->gref); /* release user */
205: rpb = (struct adspcmd *)gbuf_rptr(mp);
206: rpb->ioc = 0; /* unlink copy */
207: rpb->mp = mp;
208:
209: qAddToEnd(&sp->frpb, rpb);
210: /* Hold on to pb (will be completed when */
211: /* forward reset ack is received). */
212: } else { /* assume it will work... but keep no
213: * bookkeeping for it. yetch! */
214: adspioc_ack(0, pb->ioc, pb->gref);
215: }
216: ATENABLE(s, sp->lock);
217:
218: CheckSend(sp);
219: return STR_IGNORE;
220:
221: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.