]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netat/adsp_Open.c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_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 License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
30 * From v01.20 08/23/90 Mike Shoemaker for MacOS
31 * Modified for MP, 1996 by Tuyen Nguyen
32 * Modified, April 9, 1997 by Tuyen Nguyen for MacOSX.
35 #include <sys/errno.h>
36 #include <sys/types.h>
37 #include <sys/param.h>
38 #include <machine/spl.h>
39 #include <sys/systm.h>
40 #include <sys/kernel.h>
42 #include <sys/filedesc.h>
43 #include <sys/fcntl.h>
45 #include <sys/socket.h>
46 #include <sys/socketvar.h>
49 #include <netat/sysglue.h>
50 #include <netat/appletalk.h>
51 #include <netat/at_pcb.h>
52 #include <netat/debug.h>
53 #include <netat/adsp.h>
54 #include <netat/adsp_internal.h>
60 * Create a unique connection ID.
65 * unique connection ID
67 unsigned short NextCID()
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 if (queue
== (CCBPtr
)NULL
)
89 static byte xlateStateTbl
[4] = /* The value to be given to the CCB's state. */
90 { /* indexed by ocMode */
91 sOpening
, /* ocRequest */
92 sPassive
, /* ocPassive */
93 sOpening
, /* ocAccept */
94 sOpen
/* ocEstablish */
96 static byte xlateOpenTbl
[4] = /* Value to use for open state. */
97 { /* indexed by ocMode */
98 O_STATE_OPENWAIT
, /* ocRequest */
99 O_STATE_LISTEN
, /* ocPassive */
100 O_STATE_ESTABLISHED
, /* ocAccept */
101 O_STATE_OPEN
/* ocEstablish */
108 * --> ccbRefNum refnum of connection end
109 * --> remoteCID connection id of remote connection end
110 * --> remoteAddress internet address of remote connection end
111 * --> filterAddress filter for incoming open connection requests
112 * --> sendSeq initial send sequence number to use
113 * --> sendWindow initial size of remote end's receive buffer
114 * --> recvSeq initial receive sequence number to use
115 * --> attnSendSeq initial attention send sequence number
116 * --> attnRecvSeq initial receive sequence number
117 * --> ocMode connection opening mode
118 * --> ocMaximum maximum retries of open connection request
121 * <-- localCID connection identifier of this connection end
122 * <-- remoteCID connection id of remote connection end
129 * errRefNum bad connection refnum
130 * errState connection end must be closed
131 * errOpening open connection attempt failed
132 * errAborted request aborted by a remove or close call
134 int adspOpen(sp
, pb
) /* (DSPPBPtr pb) */
136 register struct adspcmd
*pb
;
138 extern int adsp_pidM
[];
144 pb
->ioResult
= errRefNum
; /* Unknown refnum */
148 if ((sp
->state
!= sClosed
) ||
149 (sp
->removing
)) { /* The CCB must be closed */
150 pb
->ioResult
= errState
;
154 ocMode
= pb
->u
.openParams
.ocMode
; /* get a local copy of open mode */
155 if (ocMode
== ocRequest
)
156 adsp_pidM
[pb
->socket
] = 0;
159 * Save parameters. Fill in defaults if zero
161 if (pb
->u
.openParams
.ocInterval
)
162 sp
->openInterval
= pb
->u
.openParams
.ocInterval
;
164 sp
->openInterval
= ocIntervalDefault
;
166 if (pb
->u
.openParams
.ocMaximum
)
167 sp
->openRetrys
= pb
->u
.openParams
.ocMaximum
;
169 sp
->openRetrys
= ocMaximumDefault
;
171 sp
->remoteAddress
= *((AddrUnionPtr
)&pb
->u
.openParams
.remoteAddress
);
172 /* Not used for passive */
174 * Clear out send/receive buffers.
176 if (sp
->sbuf_mb
) { /* clear the send queue */
177 gbuf_freel(sp
->sbuf_mb
);
181 gbuf_freem(sp
->csbuf_mb
);
184 if (sp
->rbuf_mb
) { /* clear the receive queue */
185 gbuf_freel(sp
->rbuf_mb
);
189 gbuf_freem(sp
->crbuf_mb
);
193 sp
->rData
= 0; /* Flag both buffers as empty */
195 sp
->recvQPending
= 0; /* No bytes in receive queue */
198 * Clear all of those pesky flags
203 sp
->sendAttnData
= 0;
209 * Reset round-trip timers
211 sp
->roundTrip
= sp
->rtmtInterval
;
215 * Reset stuff for retransmit advice packet
219 * Reset flow control variables
221 sp
->pktSendMax
= 1; /* Slow start says we should set this to 1 */
229 * Copy required information out of parameter block
231 if (ocMode
== ocAccept
|| ocMode
== ocEstablish
) {
232 sp
->remCID
= pb
->u
.openParams
.remoteCID
;
233 sp
->sendSeq
= sp
->firstRtmtSeq
= pb
->u
.openParams
.sendSeq
;
234 sp
->sendWdwSeq
= sp
->sendSeq
+ pb
->u
.openParams
.sendWindow
;
235 sp
->attnSendSeq
= pb
->u
.openParams
.attnSendSeq
;
236 } else { /* accept or establish */
243 if (ocMode
== ocEstablish
) { /* Only set these if establish mode */
244 sp
->recvSeq
= pb
->u
.openParams
.recvSeq
;
245 sp
->attnRecvSeq
= pb
->u
.openParams
.attnRecvSeq
;
246 UAS_ASSIGN_HTON(sp
->f
.CID
, sp
->locCID
); /* Preset the CID in the ADSP header */
247 /* This is done elsewhere for all other modes */
248 InsertTimerElem(&adspGlobal
.slowTimers
, &sp
->ProbeTimer
,
250 } else { /* establish */
251 /* All other modes need a CID assigned */
252 sp
->locCID
= NextCID();
258 * Now set the state variables for this CCB.
261 sp
->openState
= xlateOpenTbl
[ocMode
-ocRequest
];
262 sp
->state
= xlateStateTbl
[ocMode
-ocRequest
];
264 if (ocMode
== ocEstablish
) { /* For establish call, we're done */
266 adspioc_ack(0, pb
->ioc
, pb
->gref
);
270 pb
->qLink
= 0; /* Clear link field before putting on queue */
271 mp
= gbuf_copym(pb
->mp
); /* Save parameter block to match later */
274 pb
->ioResult
= errDSPQueueSize
;
277 pb
->ioResult
= 1; /* not open -> not done */
278 adspioc_ack(0, pb
->ioc
, pb
->gref
); /* release user */
279 sp
->opb
= (struct adspcmd
*)gbuf_rptr(mp
);
280 sp
->opb
->ioc
= 0; /* unlink saved pb from ioctl block */
284 * For request & accept, need to send a packet
286 if ((ocMode
== ocRequest
) || (ocMode
== ocAccept
)) {
287 sp
->sendCtl
|= (1 << (ocMode
== ocRequest
?
288 ADSP_CTL_OREQ
: ADSP_CTL_OREQACK
));
295 register struct adspcmd
*pb
;
297 return pb
->u
.openParams
.ocMode
;