]> git.saurik.com Git - apple/xnu.git/blob - bsd/netat/adsp_Init.c
420c8e3f3aade8de4f4624a375940d268a3784f5
[apple/xnu.git] / bsd / netat / adsp_Init.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
5 *
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
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
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.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30 /*
31 * Copyright (c) 1990, 1996-1998 Apple Computer, Inc.
32 * All Rights Reserved.
33 */
34
35 /* dspInit.c
36 *
37 * From Mike Shoemaker v01.20 06/29/90 mbs
38 * Modified for MP, 1996 by Tuyen Nguyen
39 * Modified, April 9, 1997 by Tuyen Nguyen for MacOSX.
40 */
41 #include <sys/errno.h>
42 #include <sys/types.h>
43 #include <sys/param.h>
44 #include <machine/spl.h>
45 #include <sys/systm.h>
46 #include <sys/kernel.h>
47 #include <sys/proc.h>
48 #include <sys/filedesc.h>
49 #include <sys/fcntl.h>
50 #include <sys/mbuf.h>
51 #include <sys/socket.h>
52 #include <sys/time.h>
53
54 #include <netat/sysglue.h>
55 #include <netat/appletalk.h>
56 #include <netat/at_pcb.h>
57 #include <netat/debug.h>
58 #include <netat/adsp.h>
59 #include <netat/adsp_internal.h>
60
61
62 /*
63 * InitContinue
64 *
65 * Handle 2nd half of code for dsp init. We could be called directly by
66 * the dsp Init routine, or if a socket has to be opened, we get called
67 * by the completion routine of the dsp open socket.
68 *
69 * INPUTS:
70 * sp The stream we're initing (not yet on list of streams)
71 * pb The user's dsp Init param block
72 * soc The socket we're going to use
73 * OUTPUTS:
74 * none
75 */
76 static void InitContinue(sp, pb) /* (CCBPtr sp, DSPPBPtr pb, int soc) */
77 CCBPtr sp;
78 struct adspcmd *pb;
79 {
80
81 /* Save connection's socket # in CCB */
82 sp->localSocket = pb->socket;
83
84 /*
85 * Link the new ccb onto queue. Must be done with interrupts off.
86 */
87 qAddToEnd(AT_ADSP_STREAMS, sp); /* Put on linked list of connections */
88 return;
89 }
90
91 /*
92 * dspInit
93 *
94 * Create and initialize a connection end. return ccbRefNum so that client can
95 * reference this ccb in later calls. The caller provides a pointer to
96 * ccb which belongs to adsp until the connection end is removed.
97 *
98 * If we have to open a socket, we'll have to do an async open socket, and
99 * finish up in the completion routine
100 *
101 * INPUTS:
102 * --> ccbPtr Pointer to connection control block
103 * --> adspcmdPtr Pointer to user request block
104 *
105 * OUTPUTS:
106 * <-- ccbRefNum refnum assigned to this connection.
107 *
108 * ERRORS:
109 * EADDRINUSE or 0
110 */
111 int adspInit(sp, ap) /* (DSPPBPtr pb) */
112 CCBPtr sp;
113 struct adspcmd *ap;
114 {
115 /*
116 * Set connection end defaults
117 */
118 sp->badSeqMax = 3; /* # of out-of-sequence packets received */
119 /* until a retransmit advice packet is sent */
120 sp->probeInterval = 6 * 30; /* 30 second probe interval */
121 sp->rtmtInterval = 6 * 5; /* Just a guess --- 5 seconds */
122 sp->sendBlocking = 16;
123 sp->sendInterval = 6;
124 sp->badSeqMax = 3; /* This is the default */
125
126 sp->ProbeTimer.type = kProbeTimerType;
127 sp->FlushTimer.type = kFlushTimerType;
128 sp->RetryTimer.type = kRetryTimerType;
129 sp->AttnTimer.type = kAttnTimerType;
130 sp->ResetTimer.type = kResetTimerType;
131
132 if (ap->csCode == dspInit) { /* Only do this if not connection Listener */
133 /*
134 * Initialize send and receive queue. Make sure they are the
135 * right size
136 */
137 sp->rbuflen = RecvQSize;
138 sp->rbuf_mb = 0;
139 sp->sbuflen = SendQSize;
140 sp->sbuf_mb = 0;
141 sp->csbuf_mb = 0;
142
143 /*
144 * Initialize send and receive defaults
145 */
146
147 sp->attn_mb = 0;
148 sp->state = sClosed; /* Set state for connection end */
149 /* end dspInit */
150 } else {
151
152 /* dspCLInit */
153 sp->state = sListening; /* Set state for conn end */
154 } /* end dspCLInit */
155 /*
156 * User opens the socket, so continue with the init stuff
157 */
158 InitContinue(sp, ap);
159 return(0);
160 }
161
162
163 /*
164 * AdspBad
165 *
166 *
167 * INPUTS:
168 * --> ap Parameter block
169 *
170 */
171 int AdspBad(ap) /* (DSPPBPtr pb) */
172 struct adspcmd *ap;
173 {
174 dPrintf(D_M_ADSP, D_L_ERROR,
175 ("Hey! Do you have the right AuthToolbox?"));
176 ap->ioResult = controlErr; /* Unknown csCode in the param block */
177 return EINVAL;
178 }