2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
22 #ifndef _NETAT_ADSP_INTERNAL_H_
23 #define _NETAT_ADSP_INTERNAL_H_
25 #include <sys/types.h>
27 #ifdef __APPLE_API_OBSOLETE
30 /* from h/adsp_portab.h */
32 /* TypeDefs for the basic data bytes. */
34 typedef unsigned char byte
, *bytePtr
;
42 typedef unsigned char boolean
;
44 typedef unsigned short word
;
46 typedef unsigned int dword
;
48 #define BYTE_AT(x) (*((byte PTR)(x)))
49 #define WORD_AT(x) (*((word PTR)(x)))
50 #define DWORD_AT(x) (*((dword PTR)(x)))
52 #define high(x) ((byte)((x) >> 8))
53 #define low(x) ((byte)(x))
54 #define hlword(h, l) (((byte)(l)) | (((byte)(h)) << 8))
58 * On a Mac, there is no need to byte-swap data on the network, so
59 * these macros do nothing
67 at_net network
; /* network number */
68 byte nodeid
; /* node number */
69 byte socket
; /* socket number */
70 } AddrBlk
, *AddrBlkPtr
;
75 } AddrUnion
, *AddrUnionPtr
;
79 /* from h/adsp_internal.h */
84 * Default Behavior for ADSP
86 #define ocIntervalDefault 6
87 #define ocMaximumDefault 10
88 #define probeIntervalDefault 180
91 * MACROS for comparing 32-bit sequence numbers
93 #define GT(x,y) (((long)(x-y)) > (long) 0)
94 #define LT(x,y) (((long)(x-y)) < (long) 0)
95 #define GTE(x,y) (((long)(x-y)) >= (long) 0)
96 #define LTE(x,y) (((long)(x-y)) <= (long) 0)
97 #define BETWEEN(x,y,z) (LTE(x,y) && LTE(y,z))
100 * Use the kernel tick counter for SysTicks.
103 #define SysTicks() lbolt
106 * Timer element used for handling timings
108 typedef struct timerelem
{
109 struct timerelem
*link
;
112 unsigned onQ
:1; /* Bit-fields are faster than booleans */
115 typedef TimerElem
*TimerElemPtr
;
118 * For AppleTalk Phase 2 event queue
122 unsigned short qType
;
126 typedef LAPEventElem
*LAPEventElemPtr
;
129 * The Event types we're passed when an AppleTalk transition occurs
131 #define AOpenTransition 0
132 #define ACloseTransition 2
133 #define ANetworkTransition 5
136 * The element we're passed when a NetworkTransaction event occurs
138 typedef struct TNetworkTransition
{
139 Ptr
private; /* pointer used internally by NetShare */
140 ProcPtr netValidProc
; /* pointer to the network valid procedure */
141 } TNetworkTransition
, *TPNetworkTransition
;
143 typedef long (*NetworkTransitionProcPtr
)(TPNetworkTransition nettrans
,
144 unsigned long thenet
);
146 * This is the connection control block
149 /*---These fields may not change order or size-----------*/
151 struct ccb
*ccbLink
; /* link to next ccb */
152 unsigned short state
; /* state of the connection end */
153 unsigned char userFlags
; /* flags for unsolicited connection events */
154 unsigned char localSocket
; /* socket number of this connection end */
155 AddrUnion remoteAddress
; /* internet address of remote end */
156 unsigned short attnCode
; /* attention code received */
157 unsigned short attnSize
; /* size of received attention data */
158 unsigned char *attnPtr
; /* ptr to received attention data */
159 unsigned short recvQPending
; /* # bytes in receive queue %%% */
160 /*------------------------------------------------------ */
162 struct adspcmd
*opb
; /* Outstanding open/close/remove/listens */
163 struct adspcmd
*spb
; /* Outstanding Sends */
164 struct adspcmd
*sapb
; /* Outstanding Send Attentions */
165 struct adspcmd
*frpb
; /* Outstanding Forward Resets */
166 struct adspcmd
*rpb
; /* Outstanding Read Requests */
168 struct ccb
*otccbLink
; /* link to next ccb */
169 int pid
; /* Process ID for CCB owner */
171 unsigned short remCID
; /* Remote Connection ID */
172 unsigned short locCID
; /* Local Connection ID */
173 int sendSeq
; /* Seq number of next char to send to remote */
174 int firstRtmtSeq
; /* oldest seq # in local send queue */
175 int sendWdwSeq
; /* Seq # of last char remote has bfr for */
176 int recvSeq
; /* Seq of # of next char expected from rmte */
177 int recvWdw
; /* # of bytes local end has buffer space for */
178 int attnSendSeq
; /* Seq # of next attn pkt to send to remote */
179 int attnRecvSeq
; /* Seq # of next packet local end expects */
180 int maxSendSeq
; /* Highest seq # we ever sent on connection */
182 /* These must be in the first 255 bytes of the CCB */
183 TimerElem ProbeTimer
; /* Timer element for probes (and open) */
184 TimerElem FlushTimer
; /* Timer element for flushing data */
185 TimerElem RetryTimer
; /* Timer element for retransmissions */
186 TimerElem AttnTimer
; /* Timer element for attention packets */
187 TimerElem ResetTimer
; /* Timer element for forward resets */
189 short openInterval
; /* Interval between open connection packets */
190 short probeInterval
; /* Interval between probes */
191 short sendInterval
; /* Interval before automatic flush */
192 short rtmtInterval
; /* Rexmit interval (dynamically determined) */
194 short sendCtl
; /* Send control message bits */
195 short sendBlocking
; /* Flush unsent data if > than sendBlocking */
196 short openRetrys
; /* # of retrys for Connect & Accept */
197 short rbuflen
; /* Total size of receive buffer */
198 short sbuflen
; /* Total size of receive buffer */
201 char badSeqMax
; /* retransmit advice send threshold */
202 char badSeqCnt
; /* # of of out-of-order packets received */
203 char useCheckSum
; /* true to use DDP checksums */
204 char openState
; /* Used for opening a connection (see below) */
206 gbuf_t
*rbuf_mb
; /* message block for the recv buffer */
208 gbuf_t
*sbuf_mb
; /* message block for the send buffer */
210 gbuf_t
*attn_mb
; /* message block for the attention buffer */
211 gbuf_t
*deferred_mb
; /* message block deferred for later processing */
214 char ioDone
; /* flag for when the adsp header is busy */
216 char probeCntr
; /* # of probes we can miss (counts down) */
217 char pktSendMax
; /* Max # of packets to send without an ack */
218 char pktSendCnt
; /* # of packets sent so far */
220 int sendStamp
; /* Time of last ackRequest */
221 int timerSeq
; /* Seq # of char corresponding to above time stamp */
222 short roundTrip
; /* Average Round-Trip time (in 6ths of a second) */
223 short deviation
; /* deviation from roundTrip time */
225 unsigned sData
:1; /* There's data in the send queue */
226 unsigned waitingAck
:1; /* We're waiting for an ack packet */
227 unsigned rData
:1; /* There's data in the receive queue */
228 unsigned resentData
:1; /* True when we resend data due to timeout */
229 unsigned sendDataAck
:1; /* True if he requested an ack */
230 unsigned sendAttnAck
:1; /* Must send attn acknowlege */
231 unsigned sendAttnData
:1; /* Must send attn data */
232 unsigned callSend
:1; /* Must call CheckSend() */
233 unsigned rbufFull
:1; /* We've closed our receive window. */
234 unsigned noXmitFlow
:1; /* True stops incrementing # of xmit
235 * packets to send in a row after receiving
237 unsigned secureCCB
:1; /* True if this is a secure connection */
238 unsigned removing
:1; /* There is a dspRemove pending */
239 unsigned writeFlush
:1; /* Flush send queue even if # bytes to
240 * send is less than send blocking. */
241 unsigned delay
:1; /* do not complete commands until user
242 * *** NO LONGER USED IN KERNEL *** */
243 ADSP_FRAME f
; /* Used to send every packet */
244 ADSP_OPEN_DATA of
; /* Holds the data for the open exchange */
245 gref_t
*gref
; /* The queue associated with the CCB */
254 * Change order and die !!! --- See the receive open packet code
256 #define O_STATE_NOTHING 0 /* Not opening */
257 #define O_STATE_LISTEN 1 /* Listening for open request */
258 #define O_STATE_OPENWAIT 2 /* Sent Req, waiting for Ack to open
260 #define O_STATE_ESTABLISHED 3 /* Got Req, send Req+Ack,waiting Ack */
261 #define O_STATE_OPEN 4 /* Connection is open */
264 * These bits are used in the sendCtl field to indicate what needs to be sent
266 #define B_CTL_PROBE 0x0001
267 #define B_CTL_OREQ 0x0002
268 #define B_CTL_OACK 0x0004
269 #define B_CTL_OREQACK 0x0008
270 #define B_CTL_ODENY 0x0010
271 #define B_CTL_CLOSE 0x0020
272 #define B_CTL_FRESET 0x0040
273 #define B_CTL_FRESETACK 0x0080
274 #define B_CTL_RETRANSMIT 0x0100
277 #define kProbeTimerType offsetof(CCB, ProbeTimer)
278 #define kFlushTimerType offsetof(CCB, FlushTimer)
279 #define kRetryTimerType offsetof(CCB, RetryTimer)
280 #define kAttnTimerType offsetof(CCB, AttnTimer)
281 #define kResetTimerType offsetof(CCB, ResetTimer)
284 * Used to manage the send receive queue
287 short len
; /* # of bytes in this fragment */
288 char flags
; /* See #define's below */
292 #define HDR_LEN 3 /* Yes, I know it really is 4 bytes long... */
298 #define F_ENCRYPTED 0x20 /* %%% Needed ??? */
299 #define F_LAST 0x40 /* This is last block in buffer */
302 /* %%% Are these two used anymore? */
303 #define sbufPtr(y) (&sp->sbuf[((y) < sp->sbuflen) ? (y) : ((y) - sp->sbuflen)])
304 #define rbufPtr(y) (&sp->rbuf[((y) < sp->rbuflen) ? (y) : ((y) - sp->rbuflen)])
308 /* fron h/adsp_supp.h */
310 void CallUserRoutine(CCBPtr sp
); /* (CCB FPTR sp); */
314 * Add queue element to end of queue. Pass Address of ptr to
315 * 1st element of queue
316 int qAddToEnd(struct qlink **qhead, struct qlink *qelem);
318 /* (void FPTR FPTR qhead, void FPTR qelem); */
321 * Hunt down a linked list of queue elements looking for an element with
322 * 'data' at 'offset' bytes into the queue element.
324 void *qfind_b(void *qhead
, word offset
, word data
);
325 void *qfind_w(void *qhead
, word offset
, word data
);
326 void *qfind_p(void *qhead
, word offset
, void *ptr
);
327 void *qfind_o(void *qhead
, word offset
, void *ptr
);
328 void *qfind_m(CCBPtr qhead
, void *match
, ProcPtr compare_fnx
);
332 * Routines to handle sorted timer queues
334 void InsertTimerElem(TimerElemPtr
*qhead
, TimerElemPtr t
, int val
);
335 void RemoveTimerElem(TimerElemPtr
*qhead
, TimerElemPtr t
);
336 void TimerQueueTick(TimerElemPtr
*qhead
);
338 /* from h/adsp_global.h */
341 void *ccbList
; /* Ptr to list of connection control blocks */
343 TimerElemPtr slowTimers
; /* The probe timer list */
344 TimerElemPtr fastTimers
; /* The fast timer list */
346 unsigned short lastCID
; /* Last connection ID assigned */
347 char inTimer
; /* We're inside timer routine */
350 extern GLOBAL adspGlobal
;
352 /* Address of ptr to list of ccb's */
353 #define AT_ADSP_STREAMS ((CCB **)&(adspGlobal.ccbList))
355 #endif /* KERNEL_PRIVATE */
356 #endif /* __APPLE_API_OBSOLETE */
358 #endif /* _NETAT_ADSP_INTERNAL_H_ */