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