]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netat/adsp_Open.c
2441642044d00cd7bd1f38da2b6658821b8031a6
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
27 * From v01.20 08/23/90 Mike Shoemaker for MacOS
28 * Modified for MP, 1996 by Tuyen Nguyen
29 * Modified, April 9, 1997 by Tuyen Nguyen for MacOSX.
32 #include <sys/errno.h>
33 #include <sys/types.h>
34 #include <sys/param.h>
35 #include <machine/spl.h>
36 #include <sys/systm.h>
37 #include <sys/kernel.h>
39 #include <sys/filedesc.h>
40 #include <sys/fcntl.h>
42 #include <sys/socket.h>
43 #include <sys/socketvar.h>
46 #include <netat/sysglue.h>
47 #include <netat/appletalk.h>
48 #include <netat/at_pcb.h>
49 #include <netat/debug.h>
50 #include <netat/adsp.h>
51 #include <netat/adsp_internal.h>
53 extern atlock_t adspgen_lock
;
58 * Create a unique connection ID.
63 * unique connection ID
65 unsigned short NextCID()
72 ATDISABLE(s
, adspgen_lock
); /* Disable interrupts */
73 num
= ++adspGlobal
.lastCID
;
74 /* qfind_w below is in 68K assembly */
75 /* point to the first element */
76 queue
= (CCB
*)AT_ADSP_STREAMS
;
79 if (queue
->locCID
== num
)
81 queue
= queue
->ccbLink
;
83 ATENABLE(s
, adspgen_lock
);
84 if (queue
== (CCBPtr
)NULL
)
90 static byte xlateStateTbl
[4] = /* The value to be given to the CCB's state. */
91 { /* indexed by ocMode */
92 sOpening
, /* ocRequest */
93 sPassive
, /* ocPassive */
94 sOpening
, /* ocAccept */
95 sOpen
/* ocEstablish */
97 static byte xlateOpenTbl
[4] = /* Value to use for open state. */
98 { /* indexed by ocMode */
99 O_STATE_OPENWAIT
, /* ocRequest */
100 O_STATE_LISTEN
, /* ocPassive */
101 O_STATE_ESTABLISHED
, /* ocAccept */
102 O_STATE_OPEN
/* ocEstablish */
109 * --> ccbRefNum refnum of connection end
110 * --> remoteCID connection id of remote connection end
111 * --> remoteAddress internet address of remote connection end
112 * --> filterAddress filter for incoming open connection requests
113 * --> sendSeq initial send sequence number to use
114 * --> sendWindow initial size of remote end's receive buffer
115 * --> recvSeq initial receive sequence number to use
116 * --> attnSendSeq initial attention send sequence number
117 * --> attnRecvSeq initial receive sequence number
118 * --> ocMode connection opening mode
119 * --> ocMaximum maximum retries of open connection request
122 * <-- localCID connection identifier of this connection end
123 * <-- remoteCID connection id of remote connection end
130 * errRefNum bad connection refnum
131 * errState connection end must be closed
132 * errOpening open connection attempt failed
133 * errAborted request aborted by a remove or close call
135 int adspOpen(sp
, pb
) /* (DSPPBPtr pb) */
137 register struct adspcmd
*pb
;
139 extern int adsp_pidM
[];
145 pb
->ioResult
= errRefNum
; /* Unknown refnum */
149 if ((sp
->state
!= sClosed
) ||
150 (sp
->removing
)) { /* The CCB must be closed */
151 pb
->ioResult
= errState
;
155 ocMode
= pb
->u
.openParams
.ocMode
; /* get a local copy of open mode */
156 if (ocMode
== ocRequest
)
157 adsp_pidM
[pb
->socket
] = 0;
160 * Save parameters. Fill in defaults if zero
162 if (pb
->u
.openParams
.ocInterval
)
163 sp
->openInterval
= pb
->u
.openParams
.ocInterval
;
165 sp
->openInterval
= ocIntervalDefault
;
167 if (pb
->u
.openParams
.ocMaximum
)
168 sp
->openRetrys
= pb
->u
.openParams
.ocMaximum
;
170 sp
->openRetrys
= ocMaximumDefault
;
172 sp
->remoteAddress
= *((AddrUnionPtr
)&pb
->u
.openParams
.remoteAddress
);
173 /* Not used for passive */
175 * Clear out send/receive buffers.
177 if (sp
->sbuf_mb
) { /* clear the send queue */
178 gbuf_freel(sp
->sbuf_mb
);
182 gbuf_freem(sp
->csbuf_mb
);
185 if (sp
->rbuf_mb
) { /* clear the receive queue */
186 gbuf_freel(sp
->rbuf_mb
);
190 gbuf_freem(sp
->crbuf_mb
);
194 sp
->rData
= 0; /* Flag both buffers as empty */
196 sp
->recvQPending
= 0; /* No bytes in receive queue */
199 * Clear all of those pesky flags
204 sp
->sendAttnData
= 0;
210 * Reset round-trip timers
212 sp
->roundTrip
= sp
->rtmtInterval
;
216 * Reset stuff for retransmit advice packet
220 * Reset flow control variables
222 sp
->pktSendMax
= 1; /* Slow start says we should set this to 1 */
230 * Copy required information out of parameter block
232 if (ocMode
== ocAccept
|| ocMode
== ocEstablish
) {
233 sp
->remCID
= pb
->u
.openParams
.remoteCID
;
234 sp
->sendSeq
= sp
->firstRtmtSeq
= pb
->u
.openParams
.sendSeq
;
235 sp
->sendWdwSeq
= sp
->sendSeq
+ pb
->u
.openParams
.sendWindow
;
236 sp
->attnSendSeq
= pb
->u
.openParams
.attnSendSeq
;
237 } else { /* accept or establish */
244 if (ocMode
== ocEstablish
) { /* Only set these if establish mode */
245 sp
->recvSeq
= pb
->u
.openParams
.recvSeq
;
246 sp
->attnRecvSeq
= pb
->u
.openParams
.attnRecvSeq
;
247 UAS_ASSIGN(sp
->f
.CID
, sp
->locCID
); /* Preset the CID in the ADSP header */
248 /* This is done elsewhere for all other modes */
249 InsertTimerElem(&adspGlobal
.slowTimers
, &sp
->ProbeTimer
,
251 } else { /* establish */
252 /* All other modes need a CID assigned */
253 sp
->locCID
= NextCID();
259 * Now set the state variables for this CCB.
262 sp
->openState
= xlateOpenTbl
[ocMode
-ocRequest
];
263 sp
->state
= xlateStateTbl
[ocMode
-ocRequest
];
265 if (ocMode
== ocEstablish
) { /* For establish call, we're done */
267 adspioc_ack(0, pb
->ioc
, pb
->gref
);
271 pb
->qLink
= 0; /* Clear link field before putting on queue */
272 mp
= gbuf_copym(pb
->mp
); /* Save parameter block to match later */
275 pb
->ioResult
= errDSPQueueSize
;
278 pb
->ioResult
= 1; /* not open -> not done */
279 adspioc_ack(0, pb
->ioc
, pb
->gref
); /* release user */
280 sp
->opb
= (struct adspcmd
*)gbuf_rptr(mp
);
281 sp
->opb
->ioc
= 0; /* unlink saved pb from ioctl block */
285 * For request & accept, need to send a packet
287 if ((ocMode
== ocRequest
) || (ocMode
== ocAccept
)) {
288 sp
->sendCtl
|= (1 << (ocMode
== ocRequest
?
289 ADSP_CTL_OREQ
: ADSP_CTL_OREQACK
));
296 register struct adspcmd
*pb
;
298 return pb
->u
.openParams
.ocMode
;