]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netat/adsp_Open.c
ddbfde5cb203055c3a0d03607a7a5120ae786d44
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_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
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
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
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.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
32 * From v01.20 08/23/90 Mike Shoemaker for MacOS
33 * Modified for MP, 1996 by Tuyen Nguyen
34 * Modified, April 9, 1997 by Tuyen Nguyen for MacOSX.
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>
44 #include <sys/filedesc.h>
45 #include <sys/fcntl.h>
47 #include <sys/socket.h>
48 #include <sys/socketvar.h>
51 #include <netat/sysglue.h>
52 #include <netat/appletalk.h>
53 #include <netat/at_pcb.h>
54 #include <netat/debug.h>
55 #include <netat/adsp.h>
56 #include <netat/adsp_internal.h>
62 * Create a unique connection ID.
67 * unique connection ID
69 unsigned short NextCID()
75 num
= ++adspGlobal
.lastCID
;
76 /* qfind_w below is in 68K assembly */
77 /* point to the first element */
78 queue
= (CCB
*)AT_ADSP_STREAMS
;
81 if (queue
->locCID
== num
)
83 queue
= queue
->ccbLink
;
85 if (queue
== (CCBPtr
)NULL
)
91 static byte xlateStateTbl
[4] = /* The value to be given to the CCB's state. */
92 { /* indexed by ocMode */
93 sOpening
, /* ocRequest */
94 sPassive
, /* ocPassive */
95 sOpening
, /* ocAccept */
96 sOpen
/* ocEstablish */
98 static byte xlateOpenTbl
[4] = /* Value to use for open state. */
99 { /* indexed by ocMode */
100 O_STATE_OPENWAIT
, /* ocRequest */
101 O_STATE_LISTEN
, /* ocPassive */
102 O_STATE_ESTABLISHED
, /* ocAccept */
103 O_STATE_OPEN
/* ocEstablish */
110 * --> ccbRefNum refnum of connection end
111 * --> remoteCID connection id of remote connection end
112 * --> remoteAddress internet address of remote connection end
113 * --> filterAddress filter for incoming open connection requests
114 * --> sendSeq initial send sequence number to use
115 * --> sendWindow initial size of remote end's receive buffer
116 * --> recvSeq initial receive sequence number to use
117 * --> attnSendSeq initial attention send sequence number
118 * --> attnRecvSeq initial receive sequence number
119 * --> ocMode connection opening mode
120 * --> ocMaximum maximum retries of open connection request
123 * <-- localCID connection identifier of this connection end
124 * <-- remoteCID connection id of remote connection end
131 * errRefNum bad connection refnum
132 * errState connection end must be closed
133 * errOpening open connection attempt failed
134 * errAborted request aborted by a remove or close call
136 int adspOpen(sp
, pb
) /* (DSPPBPtr pb) */
138 register struct adspcmd
*pb
;
140 extern int adsp_pidM
[];
146 pb
->ioResult
= errRefNum
; /* Unknown refnum */
150 if ((sp
->state
!= sClosed
) ||
151 (sp
->removing
)) { /* The CCB must be closed */
152 pb
->ioResult
= errState
;
156 ocMode
= pb
->u
.openParams
.ocMode
; /* get a local copy of open mode */
157 if (ocMode
== ocRequest
)
158 adsp_pidM
[pb
->socket
] = 0;
161 * Save parameters. Fill in defaults if zero
163 if (pb
->u
.openParams
.ocInterval
)
164 sp
->openInterval
= pb
->u
.openParams
.ocInterval
;
166 sp
->openInterval
= ocIntervalDefault
;
168 if (pb
->u
.openParams
.ocMaximum
)
169 sp
->openRetrys
= pb
->u
.openParams
.ocMaximum
;
171 sp
->openRetrys
= ocMaximumDefault
;
173 sp
->remoteAddress
= *((AddrUnionPtr
)&pb
->u
.openParams
.remoteAddress
);
174 /* Not used for passive */
176 * Clear out send/receive buffers.
178 if (sp
->sbuf_mb
) { /* clear the send queue */
179 gbuf_freel(sp
->sbuf_mb
);
183 gbuf_freem(sp
->csbuf_mb
);
186 if (sp
->rbuf_mb
) { /* clear the receive queue */
187 gbuf_freel(sp
->rbuf_mb
);
191 gbuf_freem(sp
->crbuf_mb
);
195 sp
->rData
= 0; /* Flag both buffers as empty */
197 sp
->recvQPending
= 0; /* No bytes in receive queue */
200 * Clear all of those pesky flags
205 sp
->sendAttnData
= 0;
211 * Reset round-trip timers
213 sp
->roundTrip
= sp
->rtmtInterval
;
217 * Reset stuff for retransmit advice packet
221 * Reset flow control variables
223 sp
->pktSendMax
= 1; /* Slow start says we should set this to 1 */
231 * Copy required information out of parameter block
233 if (ocMode
== ocAccept
|| ocMode
== ocEstablish
) {
234 sp
->remCID
= pb
->u
.openParams
.remoteCID
;
235 sp
->sendSeq
= sp
->firstRtmtSeq
= pb
->u
.openParams
.sendSeq
;
236 sp
->sendWdwSeq
= sp
->sendSeq
+ pb
->u
.openParams
.sendWindow
;
237 sp
->attnSendSeq
= pb
->u
.openParams
.attnSendSeq
;
238 } else { /* accept or establish */
245 if (ocMode
== ocEstablish
) { /* Only set these if establish mode */
246 sp
->recvSeq
= pb
->u
.openParams
.recvSeq
;
247 sp
->attnRecvSeq
= pb
->u
.openParams
.attnRecvSeq
;
248 UAS_ASSIGN_HTON(sp
->f
.CID
, sp
->locCID
); /* Preset the CID in the ADSP header */
249 /* This is done elsewhere for all other modes */
250 InsertTimerElem(&adspGlobal
.slowTimers
, &sp
->ProbeTimer
,
252 } else { /* establish */
253 /* All other modes need a CID assigned */
254 sp
->locCID
= NextCID();
260 * Now set the state variables for this CCB.
263 sp
->openState
= xlateOpenTbl
[ocMode
-ocRequest
];
264 sp
->state
= xlateStateTbl
[ocMode
-ocRequest
];
266 if (ocMode
== ocEstablish
) { /* For establish call, we're done */
268 adspioc_ack(0, pb
->ioc
, pb
->gref
);
272 pb
->qLink
= 0; /* Clear link field before putting on queue */
273 mp
= gbuf_copym(pb
->mp
); /* Save parameter block to match later */
276 pb
->ioResult
= errDSPQueueSize
;
279 pb
->ioResult
= 1; /* not open -> not done */
280 adspioc_ack(0, pb
->ioc
, pb
->gref
); /* release user */
281 sp
->opb
= (struct adspcmd
*)gbuf_rptr(mp
);
282 sp
->opb
->ioc
= 0; /* unlink saved pb from ioctl block */
286 * For request & accept, need to send a packet
288 if ((ocMode
== ocRequest
) || (ocMode
== ocAccept
)) {
289 sp
->sendCtl
|= (1 << (ocMode
== ocRequest
?
290 ADSP_CTL_OREQ
: ADSP_CTL_OREQACK
));
297 register struct adspcmd
*pb
;
299 return pb
->u
.openParams
.ocMode
;