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