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