#ifndef _NETAT_ATP_H_
#define _NETAT_ATP_H_
#include <sys/appleapiopts.h>
#ifdef __APPLE_API_OBSOLETE
#define ATP_CMD_TREQ 0x01
#define ATP_CMD_TRESP 0x02
#define ATP_CMD_TREL 0x03
#define ATP_DEF_RETRIES 8
#define ATP_DEF_INTERVAL 2
#define ATP_TRESP_MAX 8
#define ATP_HDR_SIZE 8
#define ATP_DATA_SIZE 578
#define ATP_ASYNCH_REQ 1
#define ATP_ASYNCH_RESP 2
#define ATP_XO_DEF_REL_TIME 0
#define ATP_XO_30SEC 0
#define ATP_XO_1MIN 1
#define ATP_XO_2MIN 2
#define ATP_XO_4MIN 3
#define ATP_XO_8MIN 4
typedef struct {
unsigned cmd : 2,
xo : 1,
eom : 1,
sts : 1,
xo_relt : 3;
u_char bitmap;
ua_short tid;
ua_long user_bytes;
u_char data[ATP_DATA_SIZE];
} at_atp_t;
#define ATP_ATP_HDR(c) ((at_atp_t *)(&((at_ddp_t *)(c))->data[0]))
#define TOTAL_ATP_HDR_SIZE (ATP_HDR_SIZE+DDP_X_HDR_SIZE)
#define ATP_CLEAR_CONTROL(c) (*(char *)(c) = 0)
#define ATP_INFINITE_RETRIES 0xffffffff
struct atp_set_default {
u_int def_retries;
u_int def_rate;
struct atpBDS *def_bdsp;
u_int def_BDSlen;
};
struct atp_result {
u_short count;
u_short hdr;
u_short offset[8];
u_short len[8];
};
struct atpBDS {
ua_short bdsBuffSz;
ua_long bdsBuffAddr;
ua_short bdsDataSz;
unsigned char bdsUserData[4];
};
typedef struct {
u_short at_atpreq_type;
at_inet_t at_atpreq_to;
u_char at_atpreq_treq_user_bytes[4];
u_char *at_atpreq_treq_data;
u_short at_atpreq_treq_length;
u_char at_atpreq_treq_bitmap;
u_char at_atpreq_xo;
u_char at_atpreq_xo_relt;
u_short at_atpreq_retry_timeout;
u_short at_atpreq_maximum_retries;
u_char at_atpreq_tresp_user_bytes[ATP_TRESP_MAX][4];
u_char *at_atpreq_tresp_data[ATP_TRESP_MAX];
u_short at_atpreq_tresp_lengths[ATP_TRESP_MAX];
u_long at_atpreq_debug[4];
u_short at_atpreq_tid;
u_char at_atpreq_tresp_bitmap;
u_char at_atpreq_tresp_eom_seqno;
u_char at_atpreq_got_trel;
} at_atpreq;
#define AT_ATP_CANCEL_REQUEST (('|'<<8)|1)
#define AT_ATP_ISSUE_REQUEST (('|'<<8)|2)
#define AT_ATP_ISSUE_REQUEST_DEF (('|'<<8)|3)
#define AT_ATP_ISSUE_REQUEST_DEF_NOTE (('|'<<8)|4)
#define AT_ATP_ISSUE_REQUEST_NOTE (('|'<<8)|5)
#define AT_ATP_GET_POLL (('|'<<8)|6)
#define AT_ATP_RELEASE_RESPONSE (('|'<<8)|7)
#define AT_ATP_REQUEST_COMPLETE (('|'<<8)|8)
#define AT_ATP_SEND_FULL_RESPONSE (('|'<<8)|9)
#define AT_ATP_BIND_REQ (('|'<<8)|10)
#define AT_ATP_GET_CHANID (('|'<<8)|11)
#define AT_ATP_PEEK (('|'<<8)|12)
#define AT_ATP_ISSUE_REQUEST_TICKLE (('|'<<8)|13)
#define R16(x) UAS_VALUE(x)
#define W16(x,v) UAS_ASSIGN(x, v)
#define C16(x,v) UAS_UAS(x, v)
#define ATP_SENDREQUEST 0
#define ATP_GETRESPONSE 1
#define ATP_SENDRESPONSE 2
#define ATP_GETREQUEST 3
#ifdef KERNEL_PRIVATE
#define AT_DDP_HDR(m) ((at_ddp_t *)(gbuf_rptr(m)))
#define AT_ATP_HDR(m) ((at_atp_t *)(&((at_ddp_t *)(gbuf_rptr(m)))->data[0]))
#ifdef ATP_DECLARE
unsigned char atp_mask [] = {
0x01, 0x02, 0x04, 0x08,
0x10, 0x20, 0x40, 0x80,
};
unsigned char atp_lomask [] = {
0x00, 0x01, 0x03, 0x07,
0x0f, 0x1f, 0x3f, 0x7f,
0xff
};
#else
extern unsigned char atp_mask [];
extern unsigned char atp_lomask [];
#endif
#define ATP_Q_ENTER(hdr, object, entry) { \
if ((hdr).head) { \
(hdr).head->entry.prev = (object); \
(object)->entry.next = (hdr).head; \
} else { \
(hdr).tail = (object); \
(object)->entry.next = NULL; \
} \
(object)->entry.prev = NULL; \
(hdr).head = (object); \
}
#define ATP_Q_APPEND(hdr, object, entry) { \
if ((hdr).head) { \
(hdr).tail->entry.next = (object); \
(object)->entry.prev = (hdr).tail; \
} else { \
(hdr).head = (object); \
(object)->entry.prev = NULL; \
} \
(object)->entry.next = NULL; \
(hdr).tail = (object); \
}
#define ATP_Q_REMOVE(hdr, object, entry) { \
if ((object)->entry.prev) { \
(object)->entry.prev->entry.next = (object)->entry.next;\
} else { \
(hdr).head = (object)->entry.next; \
} \
if ((object)->entry.next) { \
(object)->entry.next->entry.prev = (object)->entry.prev;\
} else { \
(hdr).tail = (object)->entry.prev; \
} \
}
struct atp_rcb_qhead {
struct atp_rcb *head;
struct atp_rcb *tail;
};
struct atp_rcb_q {
struct atp_rcb *prev;
struct atp_rcb *next;
};
struct atp_trans_qhead {
struct atp_trans *head;
struct atp_trans *tail;
};
struct atp_trans_q {
struct atp_trans *prev;
struct atp_trans *next;
};
struct atp_socket {
u_short net;
at_node node;
at_socket socket;
};
struct atp_trans {
struct atp_trans_q tr_list;
struct atp_state *tr_queue;
gbuf_t *tr_xmt;
gbuf_t *tr_rcv[8];
unsigned int tr_retry;
unsigned int tr_timeout;
char tr_state;
char tr_rsp_wait;
char filler[2];
unsigned char tr_xo;
unsigned char tr_bitmap;
unsigned short tr_tid;
struct atp_socket tr_socket;
struct atp_trans_q tr_snd_wait;
at_socket tr_local_socket;
at_node tr_local_node;
at_net tr_local_net;
gbuf_t *tr_bdsp;
unsigned int tr_tmo_delta;
void (*tr_tmo_func)();
struct atp_trans *tr_tmo_next;
struct atp_trans *tr_tmo_prev;
atlock_t tr_lock;
atevent_t tr_event;
};
#define TRANS_TIMEOUT 0
#define TRANS_REQUEST 1
#define TRANS_RELEASE 2
#define TRANS_DONE 3
#define TRANS_FAILED 4
#define TRANS_ABORTING 5
struct atp_rcb {
struct atp_rcb_q rc_list;
struct atp_rcb_q rc_tlist;
struct atp_state *rc_queue;
gbuf_t *rc_xmt;
gbuf_t *rc_ioctl;
char rc_snd[8];
int rc_pktcnt;
short rc_state;
unsigned char rc_xo;
at_node rc_local_node;
at_net rc_local_net;
short rc_rep_waiting;
int rc_timestamp;
unsigned char rc_bitmap;
unsigned char rc_not_sent_bitmap;
unsigned short rc_tid;
struct atp_socket rc_socket;
};
#define RCB_UNQUEUED 0
#define RCB_RESPONDING 2
#define RCB_RESPONSE_FULL 3
#define RCB_RELEASED 4
#define RCB_PENDING 5
#define RCB_NOTIFIED 6
#define RCB_SENDING 7
struct atp_state {
gref_t *atp_gref;
int atp_pid;
gbuf_t *atp_msgq;
unsigned char dflag;
unsigned char filler;
short atp_socket_no;
short atp_flags;
struct atp_trans_qhead atp_trans_wait;
struct atp_state *atp_trans_waiting;
unsigned int atp_retry;
unsigned int atp_timeout;
struct atp_state *atp_rcb_waiting;
struct atp_rcb_qhead atp_rcb;
struct atp_rcb_qhead atp_attached;
atlock_t atp_lock;
atevent_t atp_event;
atlock_t atp_delay_lock;
atevent_t atp_delay_event;
};
#define ATP_CLOSING 0x08
#define NATP_RCB 512
#define NATP_STATE 192
#ifdef ATP_DECLARE
struct atp_trans *atp_trans_free_list = NULL;
struct atp_rcb *atp_rcb_free_list = NULL;
struct atp_state *atp_free_list = NULL;
struct atp_trans_qhead atp_trans_abort;
struct atp_rcb* atp_rcb_data = NULL;
struct atp_state* atp_state_data=NULL;
#else
extern struct atp_trans *atp_trans_free_list;
extern struct atp_rcb *atp_rcb_free_list;
extern struct atp_state *atp_free_list;
extern struct atp_rcb* atp_rcb_data;
extern struct atp_state* atp_state_data;
extern struct atp_trans_qhead atp_trans_abort;
extern void atp_req_timeout();
extern void atp_rcb_timer();
extern void atp_x_done();
extern struct atp_rcb *atp_rcb_alloc();
extern struct atp_trans *atp_trans_alloc();
#endif
void atp_send_req(gref_t *, gbuf_t *);
void atp_drop_req(gref_t *, gbuf_t *);
void atp_send_rsp(gref_t *, gbuf_t *, int);
void atp_wput(gref_t *, gbuf_t *);
void atp_rput(gref_t *, gbuf_t *);
void atp_retry_req(void *);
void atp_stop(gbuf_t *, int);
void atp_cancel_req(gref_t *, unsigned short);
int atp_open(gref_t *, int);
int atp_bind(gref_t *, unsigned int, unsigned char *);
int atp_close(gref_t *, int);
gbuf_t *atp_build_release(struct atp_trans *);
void atp_req_timeout(struct atp_trans *);
void atp_free(struct atp_trans *);
void atp_x_done(struct atp_trans *);
void atp_send(struct atp_trans *);
void atp_rsp_ind(struct atp_trans *, gbuf_t *);
void atp_trans_free(struct atp_trans *);
void atp_reply(struct atp_rcb *);
void atp_rcb_free(struct atp_rcb *);
void atp_send_replies(struct atp_state *, struct atp_rcb *);
void atp_dequeue_atp(struct atp_state *);
int atp_iocack(struct atp_state *, gbuf_t *);
void atp_req_ind(struct atp_state *, gbuf_t *);
int atp_iocnak(struct atp_state *, gbuf_t *, int);
void atp_trp_timer(void *, int);
void atp_timout(void (*func)(), struct atp_trans *, int);
void atp_untimout(void (*func)(), struct atp_trans *);
int atp_tid(struct atp_state *);
#endif
#endif
#endif