2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_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 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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 #ifndef _NETAT_ADSP_INTERNAL_H_
29 #define _NETAT_ADSP_INTERNAL_H_
31 #include <sys/types.h>
33 #ifdef __APPLE_API_OBSOLETE
36 /* from h/adsp_portab.h */
38 /* TypeDefs for the basic data bytes. */
40 typedef unsigned char byte
, *bytePtr
;
48 typedef unsigned char boolean
;
50 typedef unsigned short word
;
52 typedef unsigned int dword
;
54 #define BYTE_AT(x) (*((byte PTR)(x)))
55 #define WORD_AT(x) (*((word PTR)(x)))
56 #define DWORD_AT(x) (*((dword PTR)(x)))
58 #define high(x) ((byte)((x) >> 8))
59 #define low(x) ((byte)(x))
60 #define hlword(h, l) (((byte)(l)) | (((byte)(h)) << 8))
64 * On a Mac, there is no need to byte-swap data on the network, so
65 * these macros do nothing
73 at_net network
; /* network number */
74 byte nodeid
; /* node number */
75 byte socket
; /* socket number */
76 } AddrBlk
, *AddrBlkPtr
;
81 } AddrUnion
, *AddrUnionPtr
;
85 /* from h/adsp_internal.h */
90 * Default Behavior for ADSP
92 #define ocIntervalDefault 6
93 #define ocMaximumDefault 10
94 #define probeIntervalDefault 180
97 * MACROS for comparing 32-bit sequence numbers
99 #define GT(x,y) (((long)(x-y)) > (long) 0)
100 #define LT(x,y) (((long)(x-y)) < (long) 0)
101 #define GTE(x,y) (((long)(x-y)) >= (long) 0)
102 #define LTE(x,y) (((long)(x-y)) <= (long) 0)
103 #define BETWEEN(x,y,z) (LTE(x,y) && LTE(y,z))
106 * Use the kernel tick counter for SysTicks.
109 #define SysTicks() lbolt
112 * Timer element used for handling timings
114 typedef struct timerelem
{
115 struct timerelem
*link
;
118 unsigned onQ
:1; /* Bit-fields are faster than booleans */
121 typedef TimerElem
*TimerElemPtr
;
124 * For AppleTalk Phase 2 event queue
128 unsigned short qType
;
132 typedef LAPEventElem
*LAPEventElemPtr
;
135 * The Event types we're passed when an AppleTalk transition occurs
137 #define AOpenTransition 0
138 #define ACloseTransition 2
139 #define ANetworkTransition 5
142 * The element we're passed when a NetworkTransaction event occurs
144 typedef struct TNetworkTransition
{
145 Ptr
private; /* pointer used internally by NetShare */
146 ProcPtr netValidProc
; /* pointer to the network valid procedure */
147 } TNetworkTransition
, *TPNetworkTransition
;
149 typedef long (*NetworkTransitionProcPtr
)(TPNetworkTransition nettrans
,
150 unsigned long thenet
);
152 * This is the connection control block
155 /*---These fields may not change order or size-----------*/
157 struct ccb
*ccbLink
; /* link to next ccb */
158 unsigned short state
; /* state of the connection end */
159 unsigned char userFlags
; /* flags for unsolicited connection events */
160 unsigned char localSocket
; /* socket number of this connection end */
161 AddrUnion remoteAddress
; /* internet address of remote end */
162 unsigned short attnCode
; /* attention code received */
163 unsigned short attnSize
; /* size of received attention data */
164 unsigned char *attnPtr
; /* ptr to received attention data */
165 unsigned short recvQPending
; /* # bytes in receive queue %%% */
166 /*------------------------------------------------------ */
168 struct adspcmd
*opb
; /* Outstanding open/close/remove/listens */
169 struct adspcmd
*spb
; /* Outstanding Sends */
170 struct adspcmd
*sapb
; /* Outstanding Send Attentions */
171 struct adspcmd
*frpb
; /* Outstanding Forward Resets */
172 struct adspcmd
*rpb
; /* Outstanding Read Requests */
174 struct ccb
*otccbLink
; /* link to next ccb */
175 int pid
; /* Process ID for CCB owner */
177 unsigned short remCID
; /* Remote Connection ID */
178 unsigned short locCID
; /* Local Connection ID */
179 int sendSeq
; /* Seq number of next char to send to remote */
180 int firstRtmtSeq
; /* oldest seq # in local send queue */
181 int sendWdwSeq
; /* Seq # of last char remote has bfr for */
182 int recvSeq
; /* Seq of # of next char expected from rmte */
183 int recvWdw
; /* # of bytes local end has buffer space for */
184 int attnSendSeq
; /* Seq # of next attn pkt to send to remote */
185 int attnRecvSeq
; /* Seq # of next packet local end expects */
186 int maxSendSeq
; /* Highest seq # we ever sent on connection */
188 /* These must be in the first 255 bytes of the CCB */
189 TimerElem ProbeTimer
; /* Timer element for probes (and open) */
190 TimerElem FlushTimer
; /* Timer element for flushing data */
191 TimerElem RetryTimer
; /* Timer element for retransmissions */
192 TimerElem AttnTimer
; /* Timer element for attention packets */
193 TimerElem ResetTimer
; /* Timer element for forward resets */
195 short openInterval
; /* Interval between open connection packets */
196 short probeInterval
; /* Interval between probes */
197 short sendInterval
; /* Interval before automatic flush */
198 short rtmtInterval
; /* Rexmit interval (dynamically determined) */
200 short sendCtl
; /* Send control message bits */
201 short sendBlocking
; /* Flush unsent data if > than sendBlocking */
202 short openRetrys
; /* # of retrys for Connect & Accept */
203 short rbuflen
; /* Total size of receive buffer */
204 short sbuflen
; /* Total size of receive buffer */
207 char badSeqMax
; /* retransmit advice send threshold */
208 char badSeqCnt
; /* # of of out-of-order packets received */
209 char useCheckSum
; /* true to use DDP checksums */
210 char openState
; /* Used for opening a connection (see below) */
212 gbuf_t
*rbuf_mb
; /* message block for the recv buffer */
214 gbuf_t
*sbuf_mb
; /* message block for the send buffer */
216 gbuf_t
*attn_mb
; /* message block for the attention buffer */
217 gbuf_t
*deferred_mb
; /* message block deferred for later processing */
220 char ioDone
; /* flag for when the adsp header is busy */
222 char probeCntr
; /* # of probes we can miss (counts down) */
223 char pktSendMax
; /* Max # of packets to send without an ack */
224 char pktSendCnt
; /* # of packets sent so far */
226 int sendStamp
; /* Time of last ackRequest */
227 int timerSeq
; /* Seq # of char corresponding to above time stamp */
228 short roundTrip
; /* Average Round-Trip time (in 6ths of a second) */
229 short deviation
; /* deviation from roundTrip time */
231 unsigned sData
:1; /* There's data in the send queue */
232 unsigned waitingAck
:1; /* We're waiting for an ack packet */
233 unsigned rData
:1; /* There's data in the receive queue */
234 unsigned resentData
:1; /* True when we resend data due to timeout */
235 unsigned sendDataAck
:1; /* True if he requested an ack */
236 unsigned sendAttnAck
:1; /* Must send attn acknowlege */
237 unsigned sendAttnData
:1; /* Must send attn data */
238 unsigned callSend
:1; /* Must call CheckSend() */
239 unsigned rbufFull
:1; /* We've closed our receive window. */
240 unsigned noXmitFlow
:1; /* True stops incrementing # of xmit
241 * packets to send in a row after receiving
243 unsigned secureCCB
:1; /* True if this is a secure connection */
244 unsigned removing
:1; /* There is a dspRemove pending */
245 unsigned writeFlush
:1; /* Flush send queue even if # bytes to
246 * send is less than send blocking. */
247 unsigned delay
:1; /* do not complete commands until user
248 * *** NO LONGER USED IN KERNEL *** */
249 ADSP_FRAME f
; /* Used to send every packet */
250 ADSP_OPEN_DATA of
; /* Holds the data for the open exchange */
251 gref_t
*gref
; /* The queue associated with the CCB */
257 * Change order and die !!! --- See the receive open packet code
259 #define O_STATE_NOTHING 0 /* Not opening */
260 #define O_STATE_LISTEN 1 /* Listening for open request */
261 #define O_STATE_OPENWAIT 2 /* Sent Req, waiting for Ack to open
263 #define O_STATE_ESTABLISHED 3 /* Got Req, send Req+Ack,waiting Ack */
264 #define O_STATE_OPEN 4 /* Connection is open */
267 * These bits are used in the sendCtl field to indicate what needs to be sent
269 #define B_CTL_PROBE 0x0001
270 #define B_CTL_OREQ 0x0002
271 #define B_CTL_OACK 0x0004
272 #define B_CTL_OREQACK 0x0008
273 #define B_CTL_ODENY 0x0010
274 #define B_CTL_CLOSE 0x0020
275 #define B_CTL_FRESET 0x0040
276 #define B_CTL_FRESETACK 0x0080
277 #define B_CTL_RETRANSMIT 0x0100
280 #define kProbeTimerType offsetof(CCB, ProbeTimer)
281 #define kFlushTimerType offsetof(CCB, FlushTimer)
282 #define kRetryTimerType offsetof(CCB, RetryTimer)
283 #define kAttnTimerType offsetof(CCB, AttnTimer)
284 #define kResetTimerType offsetof(CCB, ResetTimer)
287 * Used to manage the send receive queue
290 short len
; /* # of bytes in this fragment */
291 char flags
; /* See #define's below */
295 #define HDR_LEN 3 /* Yes, I know it really is 4 bytes long... */
301 #define F_ENCRYPTED 0x20 /* %%% Needed ??? */
302 #define F_LAST 0x40 /* This is last block in buffer */
305 /* %%% Are these two used anymore? */
306 #define sbufPtr(y) (&sp->sbuf[((y) < sp->sbuflen) ? (y) : ((y) - sp->sbuflen)])
307 #define rbufPtr(y) (&sp->rbuf[((y) < sp->rbuflen) ? (y) : ((y) - sp->rbuflen)])
311 /* fron h/adsp_supp.h */
313 void CallUserRoutine(CCBPtr sp
); /* (CCB FPTR sp); */
317 * Add queue element to end of queue. Pass Address of ptr to
318 * 1st element of queue
319 int qAddToEnd(struct qlink **qhead, struct qlink *qelem);
321 /* (void FPTR FPTR qhead, void FPTR qelem); */
324 * Hunt down a linked list of queue elements looking for an element with
325 * 'data' at 'offset' bytes into the queue element.
327 void *qfind_b(void *qhead
, word offset
, word data
);
328 void *qfind_w(void *qhead
, word offset
, word data
);
329 void *qfind_p(void *qhead
, word offset
, void *ptr
);
330 void *qfind_o(void *qhead
, word offset
, void *ptr
);
331 void *qfind_m(CCBPtr qhead
, void *match
, ProcPtr compare_fnx
);
335 * Routines to handle sorted timer queues
337 void InsertTimerElem(TimerElemPtr
*qhead
, TimerElemPtr t
, int val
);
338 void RemoveTimerElem(TimerElemPtr
*qhead
, TimerElemPtr t
);
339 void TimerQueueTick(TimerElemPtr
*qhead
);
341 /* from h/adsp_global.h */
344 void *ccbList
; /* Ptr to list of connection control blocks */
346 TimerElemPtr slowTimers
; /* The probe timer list */
347 TimerElemPtr fastTimers
; /* The fast timer list */
349 unsigned short lastCID
; /* Last connection ID assigned */
350 char inTimer
; /* We're inside timer routine */
353 extern GLOBAL adspGlobal
;
355 /* Address of ptr to list of ccb's */
356 #define AT_ADSP_STREAMS ((CCB **)&(adspGlobal.ccbList))
358 void CheckSend(CCBPtr
);
361 struct qlink
*qlinkp
;
364 int qAddToEnd(struct qlink
**, struct qlink
*);
366 void adspioc_ack(int, gbuf_t
*, gref_t
*);
367 int CalcRecvWdw(CCBPtr
);
368 int calcRecvQ(CCBPtr
);
369 int CalcSendQFree(CCBPtr
);
370 int adsp_sendddp(CCBPtr
, gbuf_t
*, int, AddrUnion
*, int);
371 int CheckReadQueue(CCBPtr
);
372 int CheckOkToClose(CCBPtr
);
374 int RXData(CCBPtr
, gbuf_t
*, ADSP_FRAMEPtr
, int);
375 int RXFResetAck(CCBPtr
, ADSP_FRAMEPtr
);
377 void CheckRecvSeq(CCBPtr
, ADSP_FRAMEPtr
);
378 int RXFReset(CCBPtr
, ADSP_FRAMEPtr
);
379 int RXAttention(CCBPtr
, gbuf_t
*, ADSP_FRAMEPtr
, int);
380 CCBPtr
FindSender(ADSP_FRAMEPtr
, AddrUnion
);
381 void DoClose(CCBPtr
, int, int);
382 void completepb(CCBPtr
, struct adspcmd
*);
383 int adspReadAttention(CCBPtr
, struct adspcmd
*);
384 int adspMode(struct adspcmd
*);
385 int CompleteQueue(struct adspcmd
**, int);
387 void CleanupGlobals(void);
388 void InitGlobals(void);
389 void TimerStop(void);
390 void TimerTick(void);
392 void SndMsgUp(gref_t
*, gbuf_t
*);
393 int adspDeassignSocket(CCBPtr
);
394 unsigned char adspAssignSocket(gref_t
*gref
, int);
395 int adspWriteHandler(gref_t
*, gbuf_t
*);
396 int adspReadHandler(gref_t
*, gbuf_t
*);
398 int adsp_wput(gref_t
*gref
, gbuf_t
*m
);
399 int adspRelease(gref_t
*);
400 int adsp_close(gref_t
*);
401 int adspAllocateCCB(gref_t
*);
403 void NotifyUser(CCBPtr
);
404 void UrgentUser(CCBPtr
);
406 unsigned short NextCID(void);
408 #endif /* KERNEL_PRIVATE */
409 #endif /* __APPLE_API_OBSOLETE */
411 #endif /* _NETAT_ADSP_INTERNAL_H_ */