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