]>
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_LICENSE_HEADER_START@
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.
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
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
24 * From v01.20 08/23/90 Mike Shoemaker for MacOS
25 * Modified for MP, 1996 by Tuyen Nguyen
26 * Modified, April 9, 1997 by Tuyen Nguyen for MacOSX.
29 #include <sys/errno.h>
30 #include <sys/types.h>
31 #include <sys/param.h>
32 #include <machine/spl.h>
33 #include <sys/systm.h>
34 #include <sys/kernel.h>
36 #include <sys/filedesc.h>
37 #include <sys/fcntl.h>
39 #include <sys/socket.h>
40 #include <sys/socketvar.h>
43 #include <netat/sysglue.h>
44 #include <netat/appletalk.h>
45 #include <netat/at_pcb.h>
46 #include <netat/debug.h>
47 #include <netat/adsp.h>
48 #include <netat/adsp_internal.h>
54 * Create a unique connection ID.
59 * unique connection ID
61 unsigned short NextCID()
67 num
= ++adspGlobal
.lastCID
;
68 /* qfind_w below is in 68K assembly */
69 /* point to the first element */
70 queue
= (CCB
*)AT_ADSP_STREAMS
;
73 if (queue
->locCID
== num
)
75 queue
= queue
->ccbLink
;
77 if (queue
== (CCBPtr
)NULL
)
83 static byte xlateStateTbl
[4] = /* The value to be given to the CCB's state. */
84 { /* indexed by ocMode */
85 sOpening
, /* ocRequest */
86 sPassive
, /* ocPassive */
87 sOpening
, /* ocAccept */
88 sOpen
/* ocEstablish */
90 static byte xlateOpenTbl
[4] = /* Value to use for open state. */
91 { /* indexed by ocMode */
92 O_STATE_OPENWAIT
, /* ocRequest */
93 O_STATE_LISTEN
, /* ocPassive */
94 O_STATE_ESTABLISHED
, /* ocAccept */
95 O_STATE_OPEN
/* ocEstablish */
102 * --> ccbRefNum refnum of connection end
103 * --> remoteCID connection id of remote connection end
104 * --> remoteAddress internet address of remote connection end
105 * --> filterAddress filter for incoming open connection requests
106 * --> sendSeq initial send sequence number to use
107 * --> sendWindow initial size of remote end's receive buffer
108 * --> recvSeq initial receive sequence number to use
109 * --> attnSendSeq initial attention send sequence number
110 * --> attnRecvSeq initial receive sequence number
111 * --> ocMode connection opening mode
112 * --> ocMaximum maximum retries of open connection request
115 * <-- localCID connection identifier of this connection end
116 * <-- remoteCID connection id of remote connection end
123 * errRefNum bad connection refnum
124 * errState connection end must be closed
125 * errOpening open connection attempt failed
126 * errAborted request aborted by a remove or close call
128 int adspOpen(sp
, pb
) /* (DSPPBPtr pb) */
130 register struct adspcmd
*pb
;
132 extern int adsp_pidM
[];
138 pb
->ioResult
= errRefNum
; /* Unknown refnum */
142 if ((sp
->state
!= sClosed
) ||
143 (sp
->removing
)) { /* The CCB must be closed */
144 pb
->ioResult
= errState
;
148 ocMode
= pb
->u
.openParams
.ocMode
; /* get a local copy of open mode */
149 if (ocMode
== ocRequest
)
150 adsp_pidM
[pb
->socket
] = 0;
153 * Save parameters. Fill in defaults if zero
155 if (pb
->u
.openParams
.ocInterval
)
156 sp
->openInterval
= pb
->u
.openParams
.ocInterval
;
158 sp
->openInterval
= ocIntervalDefault
;
160 if (pb
->u
.openParams
.ocMaximum
)
161 sp
->openRetrys
= pb
->u
.openParams
.ocMaximum
;
163 sp
->openRetrys
= ocMaximumDefault
;
165 sp
->remoteAddress
= *((AddrUnionPtr
)&pb
->u
.openParams
.remoteAddress
);
166 /* Not used for passive */
168 * Clear out send/receive buffers.
170 if (sp
->sbuf_mb
) { /* clear the send queue */
171 gbuf_freel(sp
->sbuf_mb
);
175 gbuf_freem(sp
->csbuf_mb
);
178 if (sp
->rbuf_mb
) { /* clear the receive queue */
179 gbuf_freel(sp
->rbuf_mb
);
183 gbuf_freem(sp
->crbuf_mb
);
187 sp
->rData
= 0; /* Flag both buffers as empty */
189 sp
->recvQPending
= 0; /* No bytes in receive queue */
192 * Clear all of those pesky flags
197 sp
->sendAttnData
= 0;
203 * Reset round-trip timers
205 sp
->roundTrip
= sp
->rtmtInterval
;
209 * Reset stuff for retransmit advice packet
213 * Reset flow control variables
215 sp
->pktSendMax
= 1; /* Slow start says we should set this to 1 */
223 * Copy required information out of parameter block
225 if (ocMode
== ocAccept
|| ocMode
== ocEstablish
) {
226 sp
->remCID
= pb
->u
.openParams
.remoteCID
;
227 sp
->sendSeq
= sp
->firstRtmtSeq
= pb
->u
.openParams
.sendSeq
;
228 sp
->sendWdwSeq
= sp
->sendSeq
+ pb
->u
.openParams
.sendWindow
;
229 sp
->attnSendSeq
= pb
->u
.openParams
.attnSendSeq
;
230 } else { /* accept or establish */
237 if (ocMode
== ocEstablish
) { /* Only set these if establish mode */
238 sp
->recvSeq
= pb
->u
.openParams
.recvSeq
;
239 sp
->attnRecvSeq
= pb
->u
.openParams
.attnRecvSeq
;
240 UAS_ASSIGN_HTON(sp
->f
.CID
, sp
->locCID
); /* Preset the CID in the ADSP header */
241 /* This is done elsewhere for all other modes */
242 InsertTimerElem(&adspGlobal
.slowTimers
, &sp
->ProbeTimer
,
244 } else { /* establish */
245 /* All other modes need a CID assigned */
246 sp
->locCID
= NextCID();
252 * Now set the state variables for this CCB.
255 sp
->openState
= xlateOpenTbl
[ocMode
-ocRequest
];
256 sp
->state
= xlateStateTbl
[ocMode
-ocRequest
];
258 if (ocMode
== ocEstablish
) { /* For establish call, we're done */
260 adspioc_ack(0, pb
->ioc
, pb
->gref
);
264 pb
->qLink
= 0; /* Clear link field before putting on queue */
265 mp
= gbuf_copym(pb
->mp
); /* Save parameter block to match later */
268 pb
->ioResult
= errDSPQueueSize
;
271 pb
->ioResult
= 1; /* not open -> not done */
272 adspioc_ack(0, pb
->ioc
, pb
->gref
); /* release user */
273 sp
->opb
= (struct adspcmd
*)gbuf_rptr(mp
);
274 sp
->opb
->ioc
= 0; /* unlink saved pb from ioctl block */
278 * For request & accept, need to send a packet
280 if ((ocMode
== ocRequest
) || (ocMode
== ocAccept
)) {
281 sp
->sendCtl
|= (1 << (ocMode
== ocRequest
?
282 ADSP_CTL_OREQ
: ADSP_CTL_OREQACK
));
289 register struct adspcmd
*pb
;
291 return pb
->u
.openParams
.ocMode
;