]> arthur.barton.de Git - netatalk.git/blob - include/atalk/atp.h
1d446c2b6f511722308ebe379b1736c5ebfd31ea
[netatalk.git] / include / atalk / atp.h
1 /*
2  * Copyright (c) 1990,1991 Regents of The University of Michigan.
3  * All Rights Reserved.
4  *
5  * Permission to use, copy, modify, and distribute this software and
6  * its documentation for any purpose and without fee is hereby granted,
7  * provided that the above copyright notice appears in all copies and
8  * that both that copyright notice and this permission notice appear
9  * in supporting documentation, and that the name of The University
10  * of Michigan not be used in advertising or publicity pertaining to
11  * distribution of the software without specific, written prior
12  * permission. This software is supplied as is without expressed or
13  * implied warranties of any kind.
14  *
15  *      Research Systems Unix Group
16  *      The University of Michigan
17  *      c/o Mike Clark
18  *      535 W. William Street
19  *      Ann Arbor, Michigan
20  *      +1-313-763-0525
21  *      netatalk@itd.umich.edu
22  */
23
24 #ifndef _ATALK_ATP_H
25 #define _ATALK_ATP_H 1
26  
27 #include <sys/cdefs.h>
28 #include <sys/types.h>
29 #include <sys/time.h>
30 #include <netatalk/at.h>
31 #include <netatalk/endian.h>
32
33 /* ATP packet format
34
35  |----------------|
36  | link header    |
37  |      ...       |
38  |----------------|
39  | DDP header     |
40  |      ...       |
41  |   type = 3     |
42  |----------------|
43  | control info   | --> bits 7,6: function code
44  |----------------|            5: XO bit
45  | bitmap/seq no. |            4: EOM bit
46  |----------------|            3: STS bit
47  | TID (MSB)      |        2,1,0: release timer code (ignored under phase I)
48  |----------------|
49  | TID (LSB)      |
50  |----------------|
51  | user bytes (4) |
52  |----------------|
53  | data (0-578)   |
54  |      ...       |
55  |----------------|
56 */
57 struct atphdr {
58     u_int8_t    atphd_ctrlinfo; /* control information */
59     u_int8_t    atphd_bitmap;   /* bitmap or sequence number */
60     u_int16_t   atphd_tid;      /* transaction id. */
61 };
62
63 /* ATP protocol parameters
64 */
65 #define ATP_MAXDATA     (578+4)         /* maximum ATP data size */
66 #define ATP_BUFSIZ      587             /* maximum packet size */
67 #define ATP_HDRSIZE     5               /* includes DDP type field */
68
69 #define ATP_TRELMASK    0x07            /* mask all but TREL */
70 #define ATP_RELTIME     30              /* base release timer (in secs) */
71
72 #define ATP_TREL30      0x0             /* release time codes */
73 #define ATP_TREL1M      0x1             /* these are passed in flags of */
74 #define ATP_TREL2M      0x2             /* atp_sreq call, and set in the */
75 #define ATP_TREL4M      0x3             /* packet control info. */
76 #define ATP_TREL8M      0x4
77
78 #define ATP_TRIES_INFINITE      -1      /* for atp_sreq, etc */
79
80 struct atpxobuf {
81     u_int16_t           atpxo_tid;
82     struct timeval      atpxo_tv;
83     int                 atpxo_reltime;
84     struct atpbuf       *atpxo_packet[8];
85 };
86
87 struct atpbuf {
88     struct atpbuf       *atpbuf_next;           /* next buffer in chain */
89     short               atpbuf_dlen;            /* data length <= ATP_BUFSIZ */
90     struct sockaddr_at  atpbuf_addr;            /* net address sent/recvd */
91     union {
92         char            atpbuf_data[ ATP_BUFSIZ ];      /* the data */
93         struct atpxobuf atpbuf_xo;                      /* for XO requests */
94     } atpbuf_info;
95 };
96
97 struct atp_handle {
98     int                 atph_socket;            /* ddp socket */
99     struct sockaddr_at  atph_saddr;             /* address */
100     u_int16_t           atph_tid;               /* last tid used */
101     u_int16_t           atph_rtid;              /* last received (rreq) */
102     u_int8_t            atph_rxo;               /* XO flag from last rreq */
103     int                 atph_rreltime;          /* release time (secs) */
104     struct atpbuf       *atph_sent;             /* packets we send (XO) */
105     struct atpbuf       *atph_queue;            /* queue of pending packets */
106     int                 atph_reqtries;          /* retry count for request */
107     int                 atph_reqto;             /* retry timeout for request */
108     int                 atph_rrespcount;        /* expected # of responses */
109     u_int8_t            atph_rbitmap;           /* bitmap for request */
110     struct atpbuf       *atph_reqpkt;           /* last request packet */
111     struct timeval      atph_reqtv;             /* when we last sent request */
112     struct atpbuf       *atph_resppkt[8];       /* response to request */
113 };
114
115 typedef struct atp_handle *ATP;
116
117 #define atp_sockaddr( h )       (&(h)->atph_saddr)
118 #define atp_fileno(x)           ((x)->atph_socket)
119
120 struct sreq_st {
121     char            *atpd_data;         /* request data */
122     int             atpd_dlen;
123     int             atpd_tries;         /* max. retry count */
124     int             atpd_to;            /* retry interval */
125 };
126
127 struct rres_st {
128     struct iovec    *atpd_iov;          /* for response */
129     int             atpd_iovcnt;
130 };
131
132 struct rreq_st {
133     char            *atpd_data;         /* request data */
134     int             atpd_dlen;
135 };
136
137 struct sres_st {
138     struct iovec    *atpd_iov;          /* for response */
139     int             atpd_iovcnt;
140 };
141
142 struct atp_block {
143     struct sockaddr_at  *atp_saddr;             /* from/to address */
144     union {
145         struct sreq_st  sreqdata;
146 #define atp_sreqdata    atp_data.sreqdata.atpd_data
147 #define atp_sreqdlen    atp_data.sreqdata.atpd_dlen
148 #define atp_sreqtries   atp_data.sreqdata.atpd_tries
149 #define atp_sreqto      atp_data.sreqdata.atpd_to
150
151         struct rres_st  rresdata;
152 #define atp_rresiov     atp_data.rresdata.atpd_iov
153 #define atp_rresiovcnt  atp_data.rresdata.atpd_iovcnt
154
155         struct rreq_st  rreqdata;
156 #define atp_rreqdata    atp_data.rreqdata.atpd_data
157 #define atp_rreqdlen    atp_data.rreqdata.atpd_dlen
158
159         struct sres_st  sresdata;
160 #define atp_sresiov     atp_data.sresdata.atpd_iov
161 #define atp_sresiovcnt  atp_data.sresdata.atpd_iovcnt
162     } atp_data;
163     u_int8_t            atp_bitmap;     /* response buffer bitmap */
164 };
165
166
167 /* flags for ATP options (and control byte)
168 */
169 #define ATP_STS         (1<<3)          /* Send Transaction Status */
170 #define ATP_EOM         (1<<4)          /* End Of Message */
171 #define ATP_XO          (1<<5)          /* eXactly Once mode */
172
173 /* function codes
174 */
175 #define ATP_FUNCMASK    (3<<6)          /* mask all but function */
176
177 #define ATP_TREQ        (1<<6)          /* Trans. REQuest */
178 #define ATP_TRESP       (2<<6)          /* Trans. RESPonse */
179 #define ATP_TREL        (3<<6)          /* Trans. RELease */
180
181 extern ATP              atp_open  __P((u_int8_t, 
182                                        const struct at_addr *));
183 extern int              atp_close __P((ATP));
184 extern int              atp_sreq  __P((ATP, struct atp_block *, int, 
185                                        u_int8_t));
186 extern int              atp_rresp __P((ATP, struct atp_block *));
187 extern int              atp_rsel  __P((ATP, struct sockaddr_at *, int));
188 extern int              atp_rreq  __P((ATP, struct atp_block *));
189 extern int              atp_sresp __P((ATP, struct atp_block *));
190
191 #endif