]> git.saurik.com Git - apple/xnu.git/blob - bsd/netat/atp.h
xnu-792.13.8.tar.gz
[apple/xnu.git] / bsd / netat / atp.h
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
5 *
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
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
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.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30 /*
31 *
32 * ORIGINS: 82
33 *
34 * (C) COPYRIGHT Apple Computer, Inc. 1992-1996
35 * All Rights Reserved
36 *
37 */
38
39 /* Definitions for ATP protocol and streams module, per
40 * AppleTalk Transaction Protocol documentation from
41 * `Inside AppleTalk', July 14, 1986.
42 */
43
44 /*
45 * Copyright (c) 1988, 1989 Apple Computer, Inc.
46 *
47 * The information contained herein is subject to change without
48 * notice and should not be construed as a commitment by Apple
49 * Computer, Inc. Apple Computer, Inc. assumes no responsibility
50 * for any errors that may appear.
51 *
52 * Confidential and Proprietary to Apple Computer, Inc.
53 */
54
55 #ifndef _NETAT_ATP_H_
56 #define _NETAT_ATP_H_
57 #include <sys/appleapiopts.h>
58
59 #ifdef __APPLE_API_OBSOLETE
60
61 /* ATP function codes */
62
63 #define ATP_CMD_TREQ 0x01 /* TRequest packet */
64 #define ATP_CMD_TRESP 0x02 /* TResponse packet */
65 #define ATP_CMD_TREL 0x03 /* TRelease packet */
66
67 /* Miscellaneous definitions */
68
69 #define ATP_DEF_RETRIES 8 /* Default for maximum retry count */
70 #define ATP_DEF_INTERVAL 2 /* Default for retry interval in seconds */
71
72 #define ATP_TRESP_MAX 8 /* Maximum number of Tresp pkts */
73
74 #define ATP_HDR_SIZE 8 /* Size of the ATP header */
75 #define ATP_DATA_SIZE 578 /* Maximum size of the ATP data area */
76
77 /* Consts for asynch support */
78 #define ATP_ASYNCH_REQ 1
79 #define ATP_ASYNCH_RESP 2
80
81 /* Timer values for XO release timers */
82 #define ATP_XO_DEF_REL_TIME 0
83 #define ATP_XO_30SEC 0
84 #define ATP_XO_1MIN 1
85 #define ATP_XO_2MIN 2
86 #define ATP_XO_4MIN 3
87 #define ATP_XO_8MIN 4
88
89 typedef struct {
90 #if BYTE_ORDER == BIG_ENDIAN
91 unsigned cmd : 2,
92 xo : 1,
93 eom : 1,
94 sts : 1,
95 xo_relt : 3;
96 #endif
97 #if BYTE_ORDER == LITTLE_ENDIAN
98 unsigned xo_relt : 3,
99 sts : 1,
100 eom : 1,
101 xo : 1,
102 cmd : 2;
103 #endif
104 u_char bitmap;
105 ua_short tid;
106 ua_long user_bytes;
107 u_char data[ATP_DATA_SIZE];
108 } at_atp_t;
109
110 #define ATP_ATP_HDR(c) ((at_atp_t *)(&((at_ddp_t *)(c))->data[0]))
111
112 #define TOTAL_ATP_HDR_SIZE (ATP_HDR_SIZE+DDP_X_HDR_SIZE)
113 #define ATP_CLEAR_CONTROL(c) (*(char *)(c) = 0)
114
115 /* ATP ioctl interface */
116
117 /* Structure for the atp_set_default call */
118
119 #define ATP_INFINITE_RETRIES 0xffffffff /* means retry forever
120 * in the def_retries field
121 */
122
123 struct atp_set_default {
124 u_int def_retries; /* number of retries for a request */
125 u_int def_rate; /* retry rate (in seconds/100) NB: the
126 * system may not be able to resolve
127 * delays of 100th of a second but will
128 * instead make a 'best effort'
129 */
130 struct atpBDS *def_bdsp; /* BDS structure associated with this req */
131 u_int def_BDSlen; /* size of BDS structure */
132 };
133
134
135 /* Return header from requests */
136
137 struct atp_result {
138 u_short count; /* the number of packets */
139 u_short hdr; /* offset to header in buffer */
140 u_short offset[8]; /* offset to the Nth packet in the buffer */
141 u_short len[8]; /* length of the Nth packet */
142 };
143
144 struct atpBDS {
145 ua_short bdsBuffSz;
146 ua_long bdsBuffAddr;
147 ua_short bdsDataSz;
148 unsigned char bdsUserData[4];
149 };
150
151
152 typedef struct {
153 u_short at_atpreq_type;
154 at_inet_t at_atpreq_to;
155 u_char at_atpreq_treq_user_bytes[4];
156 u_char *at_atpreq_treq_data;
157 u_short at_atpreq_treq_length;
158 u_char at_atpreq_treq_bitmap;
159 u_char at_atpreq_xo;
160 u_char at_atpreq_xo_relt;
161 u_short at_atpreq_retry_timeout;
162 u_short at_atpreq_maximum_retries;
163 u_char at_atpreq_tresp_user_bytes[ATP_TRESP_MAX][4];
164 u_char *at_atpreq_tresp_data[ATP_TRESP_MAX];
165 u_short at_atpreq_tresp_lengths[ATP_TRESP_MAX];
166 u_long at_atpreq_debug[4];
167 u_short at_atpreq_tid;
168 u_char at_atpreq_tresp_bitmap;
169 u_char at_atpreq_tresp_eom_seqno;
170 u_char at_atpreq_got_trel;
171 } at_atpreq;
172
173
174 /* The ATP module ioctl commands */
175
176 #define AT_ATP_CANCEL_REQUEST (('|'<<8)|1)
177 #define AT_ATP_ISSUE_REQUEST (('|'<<8)|2) /* ALO */
178 #define AT_ATP_ISSUE_REQUEST_DEF (('|'<<8)|3) /* XO */
179 #define AT_ATP_ISSUE_REQUEST_DEF_NOTE (('|'<<8)|4) /* XO & nowait -- not needed*/
180 #define AT_ATP_ISSUE_REQUEST_NOTE (('|'<<8)|5) /* ALO & nowait */
181 #define AT_ATP_GET_POLL (('|'<<8)|6)
182 #define AT_ATP_RELEASE_RESPONSE (('|'<<8)|7)
183 #define AT_ATP_REQUEST_COMPLETE (('|'<<8)|8)
184 #define AT_ATP_SEND_FULL_RESPONSE (('|'<<8)|9) /* not used */
185 #define AT_ATP_BIND_REQ (('|'<<8)|10)
186 #define AT_ATP_GET_CHANID (('|'<<8)|11)
187 #define AT_ATP_PEEK (('|'<<8)|12)
188 #define AT_ATP_ISSUE_REQUEST_TICKLE (('|'<<8)|13) /* ALO & nowait */
189
190 /* These macros don't really depend here, but since they're used only by the
191 * old ATP and old PAP, they're put here. Unisoft PAP includes this file.
192 */
193 #define R16(x) UAS_VALUE(x)
194 #define W16(x,v) UAS_ASSIGN(x, v)
195 #define C16(x,v) UAS_UAS(x, v)
196
197 /*
198 * these are the dispatch codes for
199 * the new atp_control system call
200 */
201 #define ATP_SENDREQUEST 0
202 #define ATP_GETRESPONSE 1
203 #define ATP_SENDRESPONSE 2
204 #define ATP_GETREQUEST 3
205
206 #ifdef KERNEL_PRIVATE
207
208
209 /*
210 * Stuff for accessing protocol headers
211 */
212 #define AT_DDP_HDR(m) ((at_ddp_t *)(gbuf_rptr(m)))
213 #define AT_ATP_HDR(m) ((at_atp_t *)(&((at_ddp_t *)(gbuf_rptr(m)))->data[0]))
214
215 /*
216 * Masks for accessing/manipulating the bitmap field in atp headers
217 */
218
219 #ifdef ATP_DECLARE
220 unsigned char atp_mask [] = {
221 0x01, 0x02, 0x04, 0x08,
222 0x10, 0x20, 0x40, 0x80,
223 };
224
225 unsigned char atp_lomask [] = {
226 0x00, 0x01, 0x03, 0x07,
227 0x0f, 0x1f, 0x3f, 0x7f,
228 0xff
229 };
230 #else
231 extern unsigned char atp_mask [];
232 extern unsigned char atp_lomask [];
233 #endif /* ATP_DECLARE */
234
235 /*
236 * doubly linked queue types and primitives
237 */
238
239 #define ATP_Q_ENTER(hdr, object, entry) { \
240 if ((hdr).head) { \
241 (hdr).head->entry.prev = (object); \
242 (object)->entry.next = (hdr).head; \
243 } else { \
244 (hdr).tail = (object); \
245 (object)->entry.next = NULL; \
246 } \
247 (object)->entry.prev = NULL; \
248 (hdr).head = (object); \
249 }
250
251 #define ATP_Q_APPEND(hdr, object, entry) { \
252 if ((hdr).head) { \
253 (hdr).tail->entry.next = (object); \
254 (object)->entry.prev = (hdr).tail; \
255 } else { \
256 (hdr).head = (object); \
257 (object)->entry.prev = NULL; \
258 } \
259 (object)->entry.next = NULL; \
260 (hdr).tail = (object); \
261 }
262
263 #define ATP_Q_REMOVE(hdr, object, entry) { \
264 if ((object)->entry.prev) { \
265 (object)->entry.prev->entry.next = (object)->entry.next;\
266 } else { \
267 (hdr).head = (object)->entry.next; \
268 } \
269 if ((object)->entry.next) { \
270 (object)->entry.next->entry.prev = (object)->entry.prev;\
271 } else { \
272 (hdr).tail = (object)->entry.prev; \
273 } \
274 }
275
276 struct atp_rcb_qhead {
277 struct atp_rcb *head;
278 struct atp_rcb *tail;
279 };
280
281 struct atp_rcb_q {
282 struct atp_rcb *prev;
283 struct atp_rcb *next;
284 };
285
286 struct atp_trans_qhead {
287 struct atp_trans *head;
288 struct atp_trans *tail;
289 };
290
291 struct atp_trans_q {
292 struct atp_trans *prev;
293 struct atp_trans *next;
294 };
295
296 /*
297 * Locally saved remote node address
298 */
299
300 struct atp_socket {
301 u_short net;
302 at_node node;
303 at_socket socket;
304 };
305
306 /*
307 * transaction control block (local context at requester end)
308 */
309
310 struct atp_trans {
311 struct atp_trans_q tr_list; /* trans list */
312 struct atp_state *tr_queue; /* state data structure */
313 gbuf_t *tr_xmt; /* message being sent */
314 gbuf_t *tr_rcv[8]; /* message being rcvd */
315 unsigned int tr_retry; /* # retries left */
316 unsigned int tr_timeout; /* timer interval */
317 char tr_state; /* current state */
318 char tr_rsp_wait; /* waiting for transaction response */
319 char filler[2];
320 unsigned char tr_xo; /* execute once transaction */
321 unsigned char tr_bitmap; /* requested bitmask */
322 unsigned short tr_tid; /* transaction id */
323 struct atp_socket tr_socket; /* the remote socket id */
324 struct atp_trans_q tr_snd_wait; /* list of transactions waiting
325 for space to send a msg */
326 at_socket tr_local_socket;
327 at_node tr_local_node;
328 at_net tr_local_net;
329 gbuf_t *tr_bdsp; /* bds structure pointer */
330 unsigned int tr_tmo_delta;
331 void (*tr_tmo_func)();
332 struct atp_trans *tr_tmo_next;
333 struct atp_trans *tr_tmo_prev;
334 atlock_t tr_lock;
335 atevent_t tr_event;
336 };
337
338 #define TRANS_TIMEOUT 0 /* waiting for a reply */
339 #define TRANS_REQUEST 1 /* waiting to send a request */
340 #define TRANS_RELEASE 2 /* waiting to send a release */
341 #define TRANS_DONE 3 /* done - waiting for poll to complete */
342 #define TRANS_FAILED 4 /* done - waiting for poll to report failure */
343 #define TRANS_ABORTING 5 /* waiting on atp_trans_abort list for thread to wakeup */
344
345 /*
346 * reply control block (local context at repling end)
347 */
348
349 struct atp_rcb {
350 struct atp_rcb_q rc_list; /* rcb list */
351 struct atp_rcb_q rc_tlist;
352 struct atp_state *rc_queue; /* state data structure */
353 gbuf_t *rc_xmt; /* replys being sent */
354 gbuf_t *rc_ioctl; /* waiting ioctl */
355 char rc_snd[8]; /* replys actually to be sent */
356 int rc_pktcnt; /* no of pkts in this trans */
357 short rc_state; /* current state */
358 unsigned char rc_xo; /* execute once transaction */
359 at_node rc_local_node;
360 at_net rc_local_net;
361 short rc_rep_waiting; /* in the reply wait list */
362 int rc_timestamp; /* reply timer */
363 unsigned char rc_bitmap; /* replied bitmask */
364 unsigned char rc_not_sent_bitmap; /* replied bitmask */
365 unsigned short rc_tid; /* transaction id */
366 struct atp_socket rc_socket; /* the remote socket id */
367 };
368
369 #define RCB_UNQUEUED 0 /* newly allocated, not q'd */
370 #define RCB_RESPONDING 2 /* waiting all of response from process*/
371 #define RCB_RESPONSE_FULL 3 /* got all of response */
372 #define RCB_RELEASED 4 /* got our release */
373 #define RCB_PENDING 5 /* a no wait rcb is full */
374 #define RCB_NOTIFIED 6
375 #define RCB_SENDING 7 /* we're currently xmitting this trans */
376
377 /*
378 * socket state (per module data structure)
379 */
380
381 struct atp_state {
382 gref_t *atp_gref; /* must be the first entry */
383 int atp_pid; /* process id, must be the second entry */
384 gbuf_t *atp_msgq; /* data msg, must be the third entry */
385 unsigned char dflag; /* structure flag, must be the fourth entry */
386 unsigned char filler;
387 short atp_socket_no;
388 short atp_flags; /* general flags */
389 struct atp_trans_qhead atp_trans_wait; /* pending transaction list */
390 struct atp_state *atp_trans_waiting; /* list of atps waiting for a
391 free transaction */
392 unsigned int atp_retry; /* retry count */
393 unsigned int atp_timeout; /* retry timeout */
394 struct atp_state *atp_rcb_waiting;
395 struct atp_rcb_qhead atp_rcb; /* active rcbs */
396 struct atp_rcb_qhead atp_attached; /* rcb's waiting to be read */
397 atlock_t atp_lock;
398 atevent_t atp_event;
399 atlock_t atp_delay_lock;
400 atevent_t atp_delay_event;
401 };
402
403
404 /*
405 * atp_state flag definitions
406 */
407 #define ATP_CLOSING 0x08 /* atp stream in process of closing */
408
409
410 /*
411 * tcb/rcb/state allocation queues
412 */
413
414 /*
415 * Size defines; must be outside following #ifdef to permit
416 * debugging code to reference independent of ATP_DECLARE
417 */
418 #define NATP_RCB 512 /* the number of ATP RCBs at once */
419 #define NATP_STATE 192 /* the number of ATP sockets open at once */
420 /* note: I made NATP_STATE == NSOCKETS */
421
422 #ifdef ATP_DECLARE
423 struct atp_trans *atp_trans_free_list = NULL; /* free transactions */
424 struct atp_rcb *atp_rcb_free_list = NULL; /* free rcbs */
425 struct atp_state *atp_free_list = NULL; /* free atp states */
426 struct atp_trans_qhead atp_trans_abort; /* aborted trans list */
427 struct atp_rcb* atp_rcb_data = NULL;
428 struct atp_state* atp_state_data=NULL;
429
430
431 #else
432 extern struct atp_trans *atp_trans_free_list; /* free transactions */
433 extern struct atp_rcb *atp_rcb_free_list; /* free rcbs */
434 extern struct atp_state *atp_free_list; /* free atp states */
435 extern struct atp_rcb* atp_rcb_data;
436 extern struct atp_state* atp_state_data;
437 extern struct atp_trans_qhead atp_trans_abort; /* aborting trans list */
438
439 extern void atp_req_timeout();
440 extern void atp_rcb_timer();
441 extern void atp_x_done();
442 extern struct atp_rcb *atp_rcb_alloc();
443 extern struct atp_trans *atp_trans_alloc();
444 #endif /* ATP_DECLARE */
445
446 /* prototypes */
447 void atp_send_req(gref_t *, gbuf_t *);
448 void atp_drop_req(gref_t *, gbuf_t *);
449 void atp_send_rsp(gref_t *, gbuf_t *, int);
450 void atp_wput(gref_t *, gbuf_t *);
451 void atp_rput(gref_t *, gbuf_t *);
452 void atp_retry_req(void *);
453 void atp_stop(gbuf_t *, int);
454 void atp_cancel_req(gref_t *, unsigned short);
455 int atp_open(gref_t *, int);
456 int atp_bind(gref_t *, unsigned int, unsigned char *);
457 int atp_close(gref_t *, int);
458 gbuf_t *atp_build_release(struct atp_trans *);
459 void atp_req_timeout(struct atp_trans *);
460 void atp_free(struct atp_trans *);
461 void atp_x_done(struct atp_trans *);
462 void atp_send(struct atp_trans *);
463 void atp_rsp_ind(struct atp_trans *, gbuf_t *);
464 void atp_trans_free(struct atp_trans *);
465 void atp_reply(struct atp_rcb *);
466 void atp_rcb_free(struct atp_rcb *);
467 void atp_send_replies(struct atp_state *, struct atp_rcb *);
468 void atp_dequeue_atp(struct atp_state *);
469 int atp_iocack(struct atp_state *, gbuf_t *);
470 void atp_req_ind(struct atp_state *, gbuf_t *);
471 int atp_iocnak(struct atp_state *, gbuf_t *, int);
472 void atp_trp_timer(void *, int);
473 void atp_timout(void (*func)(), struct atp_trans *, int);
474 void atp_untimout(void (*func)(), struct atp_trans *);
475 int atp_tid(struct atp_state *);
476
477 #endif /* KERNEL_PRIVATE */
478 #endif /* __APPLE_API_OBSOLETE */
479 #endif /* _NETAT_ATP_H_ */