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