]> git.saurik.com Git - apple/xnu.git/blob - bsd/netat/adsp_Init.c
57e4b85f8137beb3e03aab47d8463b1114a55bf3
[apple/xnu.git] / bsd / netat / adsp_Init.c
1 /*
2 * Copyright (c) 2006 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 extern atlock_t adspgen_lock;
62
63 /*
64 * InitContinue
65 *
66 * Handle 2nd half of code for dsp init. We could be called directly by
67 * the dsp Init routine, or if a socket has to be opened, we get called
68 * by the completion routine of the dsp open socket.
69 *
70 * INPUTS:
71 * sp The stream we're initing (not yet on list of streams)
72 * pb The user's dsp Init param block
73 * soc The socket we're going to use
74 * OUTPUTS:
75 * none
76 */
77 static void InitContinue(sp, pb) /* (CCBPtr sp, DSPPBPtr pb, int soc) */
78 CCBPtr sp;
79 struct adspcmd *pb;
80 {
81 int s;
82
83 /* Save connection's socket # in CCB */
84 sp->localSocket = pb->socket;
85
86 /*
87 * Link the new ccb onto queue. Must be done with interrupts off.
88 */
89 ATDISABLE(s, adspgen_lock);
90 qAddToEnd(AT_ADSP_STREAMS, sp); /* Put on linked list of connections */
91 ATENABLE(s, adspgen_lock);
92 return;
93 }
94
95 /*
96 * dspInit
97 *
98 * Create and initialize a connection end. return ccbRefNum so that client can
99 * reference this ccb in later calls. The caller provides a pointer to
100 * ccb which belongs to adsp until the connection end is removed.
101 *
102 * If we have to open a socket, we'll have to do an async open socket, and
103 * finish up in the completion routine
104 *
105 * INPUTS:
106 * --> ccbPtr Pointer to connection control block
107 * --> adspcmdPtr Pointer to user request block
108 *
109 * OUTPUTS:
110 * <-- ccbRefNum refnum assigned to this connection.
111 *
112 * ERRORS:
113 * EADDRINUSE or 0
114 */
115 int adspInit(sp, ap) /* (DSPPBPtr pb) */
116 CCBPtr sp;
117 struct adspcmd *ap;
118 {
119 /*
120 * Set connection end defaults
121 */
122 sp->badSeqMax = 3; /* # of out-of-sequence packets received */
123 /* until a retransmit advice packet is sent */
124 sp->probeInterval = 6 * 30; /* 30 second probe interval */
125 sp->rtmtInterval = 6 * 5; /* Just a guess --- 5 seconds */
126 sp->sendBlocking = 16;
127 sp->sendInterval = 6;
128 sp->badSeqMax = 3; /* This is the default */
129
130 sp->ProbeTimer.type = kProbeTimerType;
131 sp->FlushTimer.type = kFlushTimerType;
132 sp->RetryTimer.type = kRetryTimerType;
133 sp->AttnTimer.type = kAttnTimerType;
134 sp->ResetTimer.type = kResetTimerType;
135
136 if (ap->csCode == dspInit) { /* Only do this if not connection Listener */
137 /*
138 * Initialize send and receive queue. Make sure they are the
139 * right size
140 */
141 sp->rbuflen = RecvQSize;
142 sp->rbuf_mb = 0;
143 sp->sbuflen = SendQSize;
144 sp->sbuf_mb = 0;
145 sp->csbuf_mb = 0;
146
147 /*
148 * Initialize send and receive defaults
149 */
150
151 sp->attn_mb = 0;
152 sp->state = sClosed; /* Set state for connection end */
153 /* end dspInit */
154 } else {
155
156 /* dspCLInit */
157 sp->state = sListening; /* Set state for conn end */
158 } /* end dspCLInit */
159 /*
160 * User opens the socket, so continue with the init stuff
161 */
162 InitContinue(sp, ap);
163 return(0);
164 }
165
166
167 /*
168 * AdspBad
169 *
170 *
171 * INPUTS:
172 * --> ap Parameter block
173 *
174 */
175 int AdspBad(ap) /* (DSPPBPtr pb) */
176 struct adspcmd *ap;
177 {
178 dPrintf(D_M_ADSP, D_L_ERROR,
179 ("Hey! Do you have the right AuthToolbox?"));
180 ap->ioResult = controlErr; /* Unknown csCode in the param block */
181 return EINVAL;
182 }