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