2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
29 * (C) COPYRIGHT Apple Computer, Inc. 1992-1996
34 /* Definitions for ATP protocol and streams module, per
35 * AppleTalk Transaction Protocol documentation from
36 * `Inside AppleTalk', July 14, 1986.
40 * Copyright (c) 1988, 1989 Apple Computer, Inc.
42 * The information contained herein is subject to change without
43 * notice and should not be construed as a commitment by Apple
44 * Computer, Inc. Apple Computer, Inc. assumes no responsibility
45 * for any errors that may appear.
47 * Confidential and Proprietary to Apple Computer, Inc.
52 #include <sys/appleapiopts.h>
54 /* ATP function codes */
56 #define ATP_CMD_TREQ 0x01 /* TRequest packet */
57 #define ATP_CMD_TRESP 0x02 /* TResponse packet */
58 #define ATP_CMD_TREL 0x03 /* TRelease packet */
60 /* Miscellaneous definitions */
62 #define ATP_DEF_RETRIES 8 /* Default for maximum retry count */
63 #define ATP_DEF_INTERVAL 2 /* Default for retry interval in seconds */
65 #define ATP_TRESP_MAX 8 /* Maximum number of Tresp pkts */
67 #define ATP_HDR_SIZE 8 /* Size of the ATP header */
68 #define ATP_DATA_SIZE 578 /* Maximum size of the ATP data area */
70 /* Consts for asynch support */
71 #define ATP_ASYNCH_REQ 1
72 #define ATP_ASYNCH_RESP 2
74 /* Timer values for XO release timers */
75 #define ATP_XO_DEF_REL_TIME 0
76 #define ATP_XO_30SEC 0
91 u_char data
[ATP_DATA_SIZE
];
94 #define ATP_ATP_HDR(c) ((at_atp_t *)(&((at_ddp_t *)(c))->data[0]))
96 #define TOTAL_ATP_HDR_SIZE (ATP_HDR_SIZE+DDP_X_HDR_SIZE)
97 #define ATP_CLEAR_CONTROL(c) (*(char *)(c) = 0)
99 /* ATP ioctl interface */
101 /* Structure for the atp_set_default call */
103 #define ATP_INFINITE_RETRIES 0xffffffff /* means retry forever
104 * in the def_retries field
107 struct atp_set_default
{
108 u_int def_retries
; /* number of retries for a request */
109 u_int def_rate
; /* retry rate (in seconds/100) NB: the
110 * system may not be able to resolve
111 * delays of 100th of a second but will
112 * instead make a 'best effort'
114 struct atpBDS
*def_bdsp
; /* BDS structure associated with this req */
115 u_int def_BDSlen
; /* size of BDS structure */
119 /* Return header from requests */
122 u_short count
; /* the number of packets */
123 u_short hdr
; /* offset to header in buffer */
124 u_short offset
[8]; /* offset to the Nth packet in the buffer */
125 u_short len
[8]; /* length of the Nth packet */
132 unsigned char bdsUserData
[4];
137 u_short at_atpreq_type
;
138 at_inet_t at_atpreq_to
;
139 u_char at_atpreq_treq_user_bytes
[4];
140 u_char
*at_atpreq_treq_data
;
141 u_short at_atpreq_treq_length
;
142 u_char at_atpreq_treq_bitmap
;
144 u_char at_atpreq_xo_relt
;
145 u_short at_atpreq_retry_timeout
;
146 u_short at_atpreq_maximum_retries
;
147 u_char at_atpreq_tresp_user_bytes
[ATP_TRESP_MAX
][4];
148 u_char
*at_atpreq_tresp_data
[ATP_TRESP_MAX
];
149 u_short at_atpreq_tresp_lengths
[ATP_TRESP_MAX
];
150 u_long at_atpreq_debug
[4];
151 u_short at_atpreq_tid
;
152 u_char at_atpreq_tresp_bitmap
;
153 u_char at_atpreq_tresp_eom_seqno
;
154 u_char at_atpreq_got_trel
;
158 /* The ATP module ioctl commands */
160 #define AT_ATP_CANCEL_REQUEST (('|'<<8)|1)
161 #define AT_ATP_ISSUE_REQUEST (('|'<<8)|2) /* ALO */
162 #define AT_ATP_ISSUE_REQUEST_DEF (('|'<<8)|3) /* XO */
163 #define AT_ATP_ISSUE_REQUEST_DEF_NOTE (('|'<<8)|4) /* XO & nowait -- not needed*/
164 #define AT_ATP_ISSUE_REQUEST_NOTE (('|'<<8)|5) /* ALO & nowait */
165 #define AT_ATP_GET_POLL (('|'<<8)|6)
166 #define AT_ATP_RELEASE_RESPONSE (('|'<<8)|7)
167 #define AT_ATP_REQUEST_COMPLETE (('|'<<8)|8)
168 #define AT_ATP_SEND_FULL_RESPONSE (('|'<<8)|9) /* not used */
169 #define AT_ATP_BIND_REQ (('|'<<8)|10)
170 #define AT_ATP_GET_CHANID (('|'<<8)|11)
171 #define AT_ATP_PEEK (('|'<<8)|12)
172 #define AT_ATP_ISSUE_REQUEST_TICKLE (('|'<<8)|13) /* ALO & nowait */
174 /* These macros don't really depend here, but since they're used only by the
175 * old ATP and old PAP, they're put here. Unisoft PAP includes this file.
177 #define R16(x) UAS_VALUE(x)
178 #define W16(x,v) UAS_ASSIGN(x, v)
179 #define C16(x,v) UAS_UAS(x, v)
182 * these are the dispatch codes for
183 * the new atp_control system call
185 #define ATP_SENDREQUEST 0
186 #define ATP_GETRESPONSE 1
187 #define ATP_SENDRESPONSE 2
188 #define ATP_GETREQUEST 3
191 #ifdef __APPLE_API_PRIVATE
195 * Stuff for accessing protocol headers
197 #define AT_DDP_HDR(m) ((at_ddp_t *)(gbuf_rptr(m)))
198 #define AT_ATP_HDR(m) ((at_atp_t *)(&((at_ddp_t *)(gbuf_rptr(m)))->data[0]))
201 * Masks for accessing/manipulating the bitmap field in atp headers
205 unsigned char atp_mask
[] = {
206 0x01, 0x02, 0x04, 0x08,
207 0x10, 0x20, 0x40, 0x80,
210 unsigned char atp_lomask
[] = {
211 0x00, 0x01, 0x03, 0x07,
212 0x0f, 0x1f, 0x3f, 0x7f,
216 extern unsigned char atp_mask
[];
217 extern unsigned char atp_lomask
[];
218 #endif /* ATP_DECLARE */
221 * doubly linked queue types and primitives
224 #define ATP_Q_ENTER(hdr, object, entry) { \
226 (hdr).head->entry.prev = (object); \
227 (object)->entry.next = (hdr).head; \
229 (hdr).tail = (object); \
230 (object)->entry.next = NULL; \
232 (object)->entry.prev = NULL; \
233 (hdr).head = (object); \
236 #define ATP_Q_APPEND(hdr, object, entry) { \
238 (hdr).tail->entry.next = (object); \
239 (object)->entry.prev = (hdr).tail; \
241 (hdr).head = (object); \
242 (object)->entry.prev = NULL; \
244 (object)->entry.next = NULL; \
245 (hdr).tail = (object); \
248 #define ATP_Q_REMOVE(hdr, object, entry) { \
249 if ((object)->entry.prev) { \
250 (object)->entry.prev->entry.next = (object)->entry.next;\
252 (hdr).head = (object)->entry.next; \
254 if ((object)->entry.next) { \
255 (object)->entry.next->entry.prev = (object)->entry.prev;\
257 (hdr).tail = (object)->entry.prev; \
261 struct atp_rcb_qhead
{
262 struct atp_rcb
*head
;
263 struct atp_rcb
*tail
;
267 struct atp_rcb
*prev
;
268 struct atp_rcb
*next
;
271 struct atp_trans_qhead
{
272 struct atp_trans
*head
;
273 struct atp_trans
*tail
;
277 struct atp_trans
*prev
;
278 struct atp_trans
*next
;
282 * Locally saved remote node address
292 * transaction control block (local context at requester end)
296 struct atp_trans_q tr_list
; /* trans list */
297 struct atp_state
*tr_queue
; /* state data structure */
298 gbuf_t
*tr_xmt
; /* message being sent */
299 gbuf_t
*tr_rcv
[8]; /* message being rcvd */
300 unsigned int tr_retry
; /* # retries left */
301 unsigned int tr_timeout
; /* timer interval */
302 char tr_state
; /* current state */
303 char tr_rsp_wait
; /* waiting for transaction response */
305 unsigned char tr_xo
; /* execute once transaction */
306 unsigned char tr_bitmap
; /* requested bitmask */
307 unsigned short tr_tid
; /* transaction id */
308 struct atp_socket tr_socket
; /* the remote socket id */
309 struct atp_trans_q tr_snd_wait
; /* list of transactions waiting
310 for space to send a msg */
311 at_socket tr_local_socket
;
312 at_node tr_local_node
;
314 gbuf_t
*tr_bdsp
; /* bds structure pointer */
315 unsigned int tr_tmo_delta
;
316 void (*tr_tmo_func
)();
317 struct atp_trans
*tr_tmo_next
;
318 struct atp_trans
*tr_tmo_prev
;
323 #define TRANS_TIMEOUT 0 /* waiting for a reply */
324 #define TRANS_REQUEST 1 /* waiting to send a request */
325 #define TRANS_RELEASE 2 /* waiting to send a release */
326 #define TRANS_DONE 3 /* done - waiting for poll to complete */
327 #define TRANS_FAILED 4 /* done - waiting for poll to report failure */
328 #define TRANS_ABORTING 5 /* waiting on atp_trans_abort list for thread to wakeup */
331 * reply control block (local context at repling end)
335 struct atp_rcb_q rc_list
; /* rcb list */
336 struct atp_rcb_q rc_tlist
;
337 struct atp_state
*rc_queue
; /* state data structure */
338 gbuf_t
*rc_xmt
; /* replys being sent */
339 gbuf_t
*rc_ioctl
; /* waiting ioctl */
340 char rc_snd
[8]; /* replys actually to be sent */
341 int rc_pktcnt
; /* no of pkts in this trans */
342 short rc_state
; /* current state */
343 unsigned char rc_xo
; /* execute once transaction */
344 at_node rc_local_node
;
346 short rc_rep_waiting
; /* in the reply wait list */
347 int rc_timestamp
; /* reply timer */
348 unsigned char rc_bitmap
; /* replied bitmask */
349 unsigned char rc_not_sent_bitmap
; /* replied bitmask */
350 unsigned short rc_tid
; /* transaction id */
351 struct atp_socket rc_socket
; /* the remote socket id */
354 #define RCB_UNQUEUED 0 /* newly allocated, not q'd */
355 #define RCB_RESPONDING 2 /* waiting all of response from process*/
356 #define RCB_RESPONSE_FULL 3 /* got all of response */
357 #define RCB_RELEASED 4 /* got our release */
358 #define RCB_PENDING 5 /* a no wait rcb is full */
359 #define RCB_NOTIFIED 6
360 #define RCB_SENDING 7 /* we're currently xmitting this trans */
363 * socket state (per module data structure)
367 gref_t
*atp_gref
; /* must be the first entry */
368 int atp_pid
; /* process id, must be the second entry */
369 gbuf_t
*atp_msgq
; /* data msg, must be the third entry */
370 unsigned char dflag
; /* structure flag, must be the fourth entry */
371 unsigned char filler
;
373 short atp_flags
; /* general flags */
374 struct atp_trans_qhead atp_trans_wait
; /* pending transaction list */
375 struct atp_state
*atp_trans_waiting
; /* list of atps waiting for a
377 unsigned int atp_retry
; /* retry count */
378 unsigned int atp_timeout
; /* retry timeout */
379 struct atp_state
*atp_rcb_waiting
;
380 struct atp_rcb_qhead atp_rcb
; /* active rcbs */
381 struct atp_rcb_qhead atp_attached
; /* rcb's waiting to be read */
384 atlock_t atp_delay_lock
;
385 atevent_t atp_delay_event
;
390 * atp_state flag definitions
392 #define ATP_CLOSING 0x08 /* atp stream in process of closing */
396 * tcb/rcb/state allocation queues
400 * Size defines; must be outside following #ifdef to permit
401 * debugging code to reference independent of ATP_DECLARE
403 #define NATP_RCB 512 /* the number of ATP RCBs at once */
404 #define NATP_STATE 192 /* the number of ATP sockets open at once */
405 /* note: I made NATP_STATE == NSOCKETS */
408 struct atp_trans
*atp_trans_free_list
= NULL
; /* free transactions */
409 struct atp_rcb
*atp_rcb_free_list
= NULL
; /* free rcbs */
410 struct atp_state
*atp_free_list
= NULL
; /* free atp states */
411 struct atp_trans_qhead atp_trans_abort
; /* aborted trans list */
412 struct atp_rcb
* atp_rcb_data
= NULL
;
413 struct atp_state
* atp_state_data
=NULL
;
417 extern struct atp_trans
*atp_trans_free_list
; /* free transactions */
418 extern struct atp_rcb
*atp_rcb_free_list
; /* free rcbs */
419 extern struct atp_state
*atp_free_list
; /* free atp states */
420 extern struct atp_rcb
* atp_rcb_data
;
421 extern struct atp_state
* atp_state_data
;
422 extern struct atp_trans_qhead atp_trans_abort
; /* aborting trans list */
424 extern void atp_req_timeout();
425 extern void atp_rcb_timer();
426 extern void atp_x_done();
427 extern struct atp_rcb
*atp_rcb_alloc();
428 extern struct atp_trans
*atp_trans_alloc();
429 #endif /* ATP_DECLARE */
432 void atp_send_req(gref_t
*, gbuf_t
*);
433 void atp_drop_req(gref_t
*, gbuf_t
*);
434 void atp_send_rsp(gref_t
*, gbuf_t
*, int);
435 void atp_wput(gref_t
*, gbuf_t
*);
436 void atp_rput(gref_t
*, gbuf_t
*);
437 void atp_retry_req(gbuf_t
*);
438 void atp_stop(gbuf_t
*, int);
439 void atp_cancel_req(gref_t
*, unsigned short);
440 int atp_open(gref_t
*, int);
441 int atp_bind(gref_t
*, unsigned int, unsigned char *);
442 int atp_close(gref_t
*, int);
443 gbuf_t
*atp_build_release(struct atp_trans
*);
444 void atp_req_timeout(struct atp_trans
*);
445 void atp_free(struct atp_trans
*);
446 void atp_x_done(struct atp_trans
*);
447 void atp_send(struct atp_trans
*);
448 void atp_rsp_ind(struct atp_trans
*, gbuf_t
*);
449 void atp_trans_free(struct atp_trans
*);
450 void atp_reply(struct atp_rcb
*);
451 void atp_rcb_free(struct atp_rcb
*);
452 void atp_send_replies(struct atp_state
*, struct atp_rcb
*);
453 void atp_dequeue_atp(struct atp_state
*);
454 int atp_iocack(struct atp_state
*, gbuf_t
*);
455 void atp_req_ind(struct atp_state
*, gbuf_t
*);
456 int atp_iocnak(struct atp_state
*, gbuf_t
*, int);
457 void atp_trp_timer(void *, int);
458 void atp_timout(void (*func
)(), struct atp_trans
*, int);
459 void atp_untimout(void (*func
)(), struct atp_trans
*);
460 int atp_tid(struct atp_state
*);
462 #endif /* __APPLE_API_PRIVATE */
464 #endif /* _NETAT_ATP_H_ */