]> arthur.barton.de Git - netatalk.git/blob - include/atalk/dsi.h
support for function 0x7a
[netatalk.git] / include / atalk / dsi.h
1 /*
2  * Copyright (c) 1997 Adrian Sun (asun@zoology.washington.edu)
3  * All rights reserved.
4  */
5
6 #ifndef _ATALK_DSI_H 
7 #define _ATALK_DSI_H
8
9 #include <sys/cdefs.h>
10 #include <sys/types.h>
11 #include <sys/time.h>
12 #include <signal.h>
13
14 #include <netinet/in.h>
15 #include <atalk/afp.h>
16 #include <atalk/server_child.h>
17 #include <netatalk/endian.h>
18
19 /* What a DSI packet looks like:
20  0                               32
21  |-------------------------------|
22  |flags  |command| requestID     |
23  |-------------------------------|
24  |error code/enclosed data offset|
25  |-------------------------------|
26  |total data length              |
27  |-------------------------------|
28  |reserved field                 |
29  |-------------------------------|
30
31  CONVENTION: anything with a dsi_ prefix is kept in network byte order.
32 */
33
34 /* these need to be kept in sync w/ AFPTRANS_* in <atalk/afp.h>. 
35  * convention: AFPTRANS_* = (1 << DSI_*) */
36 typedef enum {
37   DSI_MIN = 1,
38   DSI_TCPIP = 1,
39   DSI_MAX = 1
40 } dsi_proto;
41
42 #define DSI_BLOCKSIZ 16
43 struct dsi_block {
44   u_int8_t dsi_flags;       /* packet type: request or reply */
45   u_int8_t dsi_command;     /* command */
46   u_int16_t dsi_requestID;  /* request ID */
47   u_int32_t dsi_code;       /* error code or data offset */
48   u_int32_t dsi_len;        /* total data length */
49   u_int32_t dsi_reserved;   /* reserved field */
50 };
51
52 #define DSI_CMDSIZ        800
53 #define DSI_DATASIZ       8192
54 /* child and parent processes might interpret a couple of these
55  * differently. */
56 typedef struct DSI {
57   dsi_proto protocol;
58   struct dsi_block header;
59   struct sockaddr_in server, client;
60   sigset_t sigblockset;
61   struct itimerval timer, savetimer;
62   u_int32_t attn_quantum, datasize, server_quantum;
63   u_int16_t serverID, clientID;
64   u_int8_t *status, commands[DSI_CMDSIZ], data[DSI_DATASIZ];
65   int statuslen;
66   unsigned int datalen, cmdlen;
67   size_t read_count, write_count;
68   int asleep; /* client won't reply AFP 0x7a ? */
69   /* inited = initialized?, child = a child?, noreply = send reply? */
70   char child, inited, noreply;
71   const char *program; 
72   int socket, serversock;
73
74   /* protocol specific open/close, send/receive
75    * send/receive fill in the header and use dsi->commands.
76    * write/read just write/read data */
77   pid_t  (*proto_open)(struct DSI *);
78   void   (*proto_close)(struct DSI *);
79 } DSI;
80   
81 /* DSI flags */
82 #define DSIFL_REQUEST    0x00
83 #define DSIFL_REPLY      0x01
84 #define DSIFL_MAX        0x01
85
86 /* DSI session options */
87 #define DSIOPT_SERVQUANT 0x00   /* server request quantum */
88 #define DSIOPT_ATTNQUANT 0x01   /* attention quantum */
89
90 /* DSI Commands */
91 #define DSIFUNC_CLOSE   1       /* DSICloseSession */
92 #define DSIFUNC_CMD     2       /* DSICommand */
93 #define DSIFUNC_STAT    3       /* DSIGetStatus */
94 #define DSIFUNC_OPEN    4       /* DSIOpenSession */
95 #define DSIFUNC_TICKLE  5       /* DSITickle */
96 #define DSIFUNC_WRITE   6       /* DSIWrite */
97 #define DSIFUNC_ATTN    8       /* DSIAttention */
98 #define DSIFUNC_MAX     8       /* largest command */
99
100 /* DSI Error codes: most of these aren't used. */
101 #define DSIERR_OK       0x0000
102 #define DSIERR_BADVERS  0xfbd6
103 #define DSIERR_BUFSMALL 0xfbd5
104 #define DSIERR_NOSESS   0xfbd4
105 #define DSIERR_NOSERV   0xfbd3
106 #define DSIERR_PARM     0xfbd2
107 #define DSIERR_SERVBUSY 0xfbd1
108 #define DSIERR_SESSCLOS 0xfbd0
109 #define DSIERR_SIZERR   0xfbcf
110 #define DSIERR_TOOMANY  0xfbce
111 #define DSIERR_NOACK    0xfbcd
112
113 /* server and client quanta */
114 #define DSI_DEFQUANT        2           /* default attention quantum size */
115 #define DSI_SERVQUANT_MAX   0xffffffffL /* server quantum */
116 #define DSI_SERVQUANT_MIN   0x0004A2E0L /* minimum server quantum */
117 #define DSI_SERVQUANT_DEF   DSI_SERVQUANT_MIN /* default server quantum */
118
119 /* default port number */
120 #define DSI_AFPOVERTCP_PORT 548
121
122 /* basic initialization: dsi_init.c */
123 extern DSI *dsi_init __P((const dsi_proto /*protocol*/,
124                           const char * /*program*/, 
125                           const char * /*host*/, const char * /*address*/,
126                           const int /*port*/, const int /*proxy*/,
127                           const u_int32_t /* server quantum */));
128 extern void dsi_setstatus __P((DSI *, u_int8_t *, const int));
129
130 /* in dsi_getsess.c */
131 extern DSI *dsi_getsession __P((DSI *, server_child *, const int));
132 extern void dsi_kill __P((int));
133
134
135 /* DSI Commands: individual files */
136 extern void dsi_opensession __P((DSI *));
137 extern int  dsi_attention __P((DSI *, AFPUserBytes));
138 extern int  dsi_cmdreply __P((DSI *, const int));
139 extern int dsi_tickle __P((DSI *));
140 extern void dsi_getstatus __P((DSI *));
141 extern void dsi_close __P((DSI *));
142 extern void dsi_sleep __P((DSI *, const int ));
143
144 /* low-level stream commands -- in dsi_stream.c */
145 extern size_t dsi_stream_write __P((DSI *, void *, const size_t));
146 extern size_t dsi_stream_read __P((DSI *, void *, const size_t));
147 extern int dsi_stream_send __P((DSI *, void *, size_t));
148 extern int dsi_stream_receive __P((DSI *, void *, const size_t, size_t *));
149
150 /* client writes -- dsi_write.c */
151 extern size_t dsi_writeinit __P((DSI *, void *, const size_t));
152 extern size_t dsi_write __P((DSI *, void *, const size_t));
153 extern void   dsi_writeflush __P((DSI *));
154 #define dsi_wrtreply(a,b)  dsi_cmdreply(a,b)
155
156 /* client reads -- dsi_read.c */
157 extern ssize_t dsi_readinit __P((DSI *, void *, const size_t, const size_t,
158                                  const int));
159 extern ssize_t dsi_read __P((DSI *, void *, const size_t));
160 extern void dsi_readdone __P((DSI *));
161
162 /* some useful macros */
163 #define dsi_serverID(x)   ((x)->serverID++)
164 #define dsi_send(x)       do { \
165     (x)->header.dsi_len = htonl((x)->cmdlen); \
166     dsi_stream_send((x), (x)->commands, (x)->cmdlen); \
167 } while (0)
168 #define dsi_receive(x)    (dsi_stream_receive((x), (x)->commands, \
169                                               DSI_CMDSIZ, &(x)->cmdlen))
170 #endif /* atalk/dsi.h */