2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
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
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
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.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
30 #ifndef _NETAT_ADSP_INTERNAL_H_
31 #define _NETAT_ADSP_INTERNAL_H_
33 #include <sys/types.h>
35 #ifdef __APPLE_API_OBSOLETE
38 /* from h/adsp_portab.h */
40 /* TypeDefs for the basic data bytes. */
42 typedef unsigned char byte
, *bytePtr
;
50 typedef unsigned char boolean
;
52 typedef unsigned short word
;
54 typedef unsigned int dword
;
56 #define BYTE_AT(x) (*((byte PTR)(x)))
57 #define WORD_AT(x) (*((word PTR)(x)))
58 #define DWORD_AT(x) (*((dword PTR)(x)))
60 #define high(x) ((byte)((x) >> 8))
61 #define low(x) ((byte)(x))
62 #define hlword(h, l) (((byte)(l)) | (((byte)(h)) << 8))
66 * On a Mac, there is no need to byte-swap data on the network, so
67 * these macros do nothing
75 at_net network
; /* network number */
76 byte nodeid
; /* node number */
77 byte socket
; /* socket number */
78 } AddrBlk
, *AddrBlkPtr
;
83 } AddrUnion
, *AddrUnionPtr
;
87 /* from h/adsp_internal.h */
92 * Default Behavior for ADSP
94 #define ocIntervalDefault 6
95 #define ocMaximumDefault 10
96 #define probeIntervalDefault 180
99 * MACROS for comparing 32-bit sequence numbers
101 #define GT(x,y) (((long)(x-y)) > (long) 0)
102 #define LT(x,y) (((long)(x-y)) < (long) 0)
103 #define GTE(x,y) (((long)(x-y)) >= (long) 0)
104 #define LTE(x,y) (((long)(x-y)) <= (long) 0)
105 #define BETWEEN(x,y,z) (LTE(x,y) && LTE(y,z))
108 * Use the kernel tick counter for SysTicks.
111 #define SysTicks() lbolt
114 * Timer element used for handling timings
116 typedef struct timerelem
{
117 struct timerelem
*link
;
120 unsigned onQ
:1; /* Bit-fields are faster than booleans */
123 typedef TimerElem
*TimerElemPtr
;
126 * For AppleTalk Phase 2 event queue
130 unsigned short qType
;
134 typedef LAPEventElem
*LAPEventElemPtr
;
137 * The Event types we're passed when an AppleTalk transition occurs
139 #define AOpenTransition 0
140 #define ACloseTransition 2
141 #define ANetworkTransition 5
144 * The element we're passed when a NetworkTransaction event occurs
146 typedef struct TNetworkTransition
{
147 Ptr
private; /* pointer used internally by NetShare */
148 ProcPtr netValidProc
; /* pointer to the network valid procedure */
149 } TNetworkTransition
, *TPNetworkTransition
;
151 typedef long (*NetworkTransitionProcPtr
)(TPNetworkTransition nettrans
,
152 unsigned long thenet
);
154 * This is the connection control block
157 /*---These fields may not change order or size-----------*/
159 struct ccb
*ccbLink
; /* link to next ccb */
160 unsigned short state
; /* state of the connection end */
161 unsigned char userFlags
; /* flags for unsolicited connection events */
162 unsigned char localSocket
; /* socket number of this connection end */
163 AddrUnion remoteAddress
; /* internet address of remote end */
164 unsigned short attnCode
; /* attention code received */
165 unsigned short attnSize
; /* size of received attention data */
166 unsigned char *attnPtr
; /* ptr to received attention data */
167 unsigned short recvQPending
; /* # bytes in receive queue %%% */
168 /*------------------------------------------------------ */
170 struct adspcmd
*opb
; /* Outstanding open/close/remove/listens */
171 struct adspcmd
*spb
; /* Outstanding Sends */
172 struct adspcmd
*sapb
; /* Outstanding Send Attentions */
173 struct adspcmd
*frpb
; /* Outstanding Forward Resets */
174 struct adspcmd
*rpb
; /* Outstanding Read Requests */
176 struct ccb
*otccbLink
; /* link to next ccb */
177 int pid
; /* Process ID for CCB owner */
179 unsigned short remCID
; /* Remote Connection ID */
180 unsigned short locCID
; /* Local Connection ID */
181 int sendSeq
; /* Seq number of next char to send to remote */
182 int firstRtmtSeq
; /* oldest seq # in local send queue */
183 int sendWdwSeq
; /* Seq # of last char remote has bfr for */
184 int recvSeq
; /* Seq of # of next char expected from rmte */
185 int recvWdw
; /* # of bytes local end has buffer space for */
186 int attnSendSeq
; /* Seq # of next attn pkt to send to remote */
187 int attnRecvSeq
; /* Seq # of next packet local end expects */
188 int maxSendSeq
; /* Highest seq # we ever sent on connection */
190 /* These must be in the first 255 bytes of the CCB */
191 TimerElem ProbeTimer
; /* Timer element for probes (and open) */
192 TimerElem FlushTimer
; /* Timer element for flushing data */
193 TimerElem RetryTimer
; /* Timer element for retransmissions */
194 TimerElem AttnTimer
; /* Timer element for attention packets */
195 TimerElem ResetTimer
; /* Timer element for forward resets */
197 short openInterval
; /* Interval between open connection packets */
198 short probeInterval
; /* Interval between probes */
199 short sendInterval
; /* Interval before automatic flush */
200 short rtmtInterval
; /* Rexmit interval (dynamically determined) */
202 short sendCtl
; /* Send control message bits */
203 short sendBlocking
; /* Flush unsent data if > than sendBlocking */
204 short openRetrys
; /* # of retrys for Connect & Accept */
205 short rbuflen
; /* Total size of receive buffer */
206 short sbuflen
; /* Total size of receive buffer */
209 char badSeqMax
; /* retransmit advice send threshold */
210 char badSeqCnt
; /* # of of out-of-order packets received */
211 char useCheckSum
; /* true to use DDP checksums */
212 char openState
; /* Used for opening a connection (see below) */
214 gbuf_t
*rbuf_mb
; /* message block for the recv buffer */
216 gbuf_t
*sbuf_mb
; /* message block for the send buffer */
218 gbuf_t
*attn_mb
; /* message block for the attention buffer */
219 gbuf_t
*deferred_mb
; /* message block deferred for later processing */
222 char ioDone
; /* flag for when the adsp header is busy */
224 char probeCntr
; /* # of probes we can miss (counts down) */
225 char pktSendMax
; /* Max # of packets to send without an ack */
226 char pktSendCnt
; /* # of packets sent so far */
228 int sendStamp
; /* Time of last ackRequest */
229 int timerSeq
; /* Seq # of char corresponding to above time stamp */
230 short roundTrip
; /* Average Round-Trip time (in 6ths of a second) */
231 short deviation
; /* deviation from roundTrip time */
233 unsigned sData
:1; /* There's data in the send queue */
234 unsigned waitingAck
:1; /* We're waiting for an ack packet */
235 unsigned rData
:1; /* There's data in the receive queue */
236 unsigned resentData
:1; /* True when we resend data due to timeout */
237 unsigned sendDataAck
:1; /* True if he requested an ack */
238 unsigned sendAttnAck
:1; /* Must send attn acknowlege */
239 unsigned sendAttnData
:1; /* Must send attn data */
240 unsigned callSend
:1; /* Must call CheckSend() */
241 unsigned rbufFull
:1; /* We've closed our receive window. */
242 unsigned noXmitFlow
:1; /* True stops incrementing # of xmit
243 * packets to send in a row after receiving
245 unsigned secureCCB
:1; /* True if this is a secure connection */
246 unsigned removing
:1; /* There is a dspRemove pending */
247 unsigned writeFlush
:1; /* Flush send queue even if # bytes to
248 * send is less than send blocking. */
249 unsigned delay
:1; /* do not complete commands until user
250 * *** NO LONGER USED IN KERNEL *** */
251 ADSP_FRAME f
; /* Used to send every packet */
252 ADSP_OPEN_DATA of
; /* Holds the data for the open exchange */
253 gref_t
*gref
; /* The queue associated with the CCB */
259 * Change order and die !!! --- See the receive open packet code
261 #define O_STATE_NOTHING 0 /* Not opening */
262 #define O_STATE_LISTEN 1 /* Listening for open request */
263 #define O_STATE_OPENWAIT 2 /* Sent Req, waiting for Ack to open
265 #define O_STATE_ESTABLISHED 3 /* Got Req, send Req+Ack,waiting Ack */
266 #define O_STATE_OPEN 4 /* Connection is open */
269 * These bits are used in the sendCtl field to indicate what needs to be sent
271 #define B_CTL_PROBE 0x0001
272 #define B_CTL_OREQ 0x0002
273 #define B_CTL_OACK 0x0004
274 #define B_CTL_OREQACK 0x0008
275 #define B_CTL_ODENY 0x0010
276 #define B_CTL_CLOSE 0x0020
277 #define B_CTL_FRESET 0x0040
278 #define B_CTL_FRESETACK 0x0080
279 #define B_CTL_RETRANSMIT 0x0100
282 #define kProbeTimerType offsetof(CCB, ProbeTimer)
283 #define kFlushTimerType offsetof(CCB, FlushTimer)
284 #define kRetryTimerType offsetof(CCB, RetryTimer)
285 #define kAttnTimerType offsetof(CCB, AttnTimer)
286 #define kResetTimerType offsetof(CCB, ResetTimer)
289 * Used to manage the send receive queue
292 short len
; /* # of bytes in this fragment */
293 char flags
; /* See #define's below */
297 #define HDR_LEN 3 /* Yes, I know it really is 4 bytes long... */
303 #define F_ENCRYPTED 0x20 /* %%% Needed ??? */
304 #define F_LAST 0x40 /* This is last block in buffer */
307 /* %%% Are these two used anymore? */
308 #define sbufPtr(y) (&sp->sbuf[((y) < sp->sbuflen) ? (y) : ((y) - sp->sbuflen)])
309 #define rbufPtr(y) (&sp->rbuf[((y) < sp->rbuflen) ? (y) : ((y) - sp->rbuflen)])
313 /* fron h/adsp_supp.h */
315 void CallUserRoutine(CCBPtr sp
); /* (CCB FPTR sp); */
319 * Add queue element to end of queue. Pass Address of ptr to
320 * 1st element of queue
321 int qAddToEnd(struct qlink **qhead, struct qlink *qelem);
323 /* (void FPTR FPTR qhead, void FPTR qelem); */
326 * Hunt down a linked list of queue elements looking for an element with
327 * 'data' at 'offset' bytes into the queue element.
329 void *qfind_b(void *qhead
, word offset
, word data
);
330 void *qfind_w(void *qhead
, word offset
, word data
);
331 void *qfind_p(void *qhead
, word offset
, void *ptr
);
332 void *qfind_o(void *qhead
, word offset
, void *ptr
);
333 void *qfind_m(CCBPtr qhead
, void *match
, ProcPtr compare_fnx
);
337 * Routines to handle sorted timer queues
339 void InsertTimerElem(TimerElemPtr
*qhead
, TimerElemPtr t
, int val
);
340 void RemoveTimerElem(TimerElemPtr
*qhead
, TimerElemPtr t
);
341 void TimerQueueTick(TimerElemPtr
*qhead
);
343 /* from h/adsp_global.h */
346 void *ccbList
; /* Ptr to list of connection control blocks */
348 TimerElemPtr slowTimers
; /* The probe timer list */
349 TimerElemPtr fastTimers
; /* The fast timer list */
351 unsigned short lastCID
; /* Last connection ID assigned */
352 char inTimer
; /* We're inside timer routine */
355 extern GLOBAL adspGlobal
;
357 /* Address of ptr to list of ccb's */
358 #define AT_ADSP_STREAMS ((CCB **)&(adspGlobal.ccbList))
360 #endif /* KERNEL_PRIVATE */
361 #endif /* __APPLE_API_OBSOLETE */
363 #endif /* _NETAT_ADSP_INTERNAL_H_ */