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