2 * Copyright (c) 1997 Adrian Sun (asun@zoology.washington.edu)
10 #include <sys/types.h>
14 #include <netinet/in.h>
15 #include <atalk/afp.h>
16 #include <atalk/server_child.h>
17 #include <netatalk/endian.h>
19 /* What a DSI packet looks like:
21 |-------------------------------|
22 |flags |command| requestID |
23 |-------------------------------|
24 |error code/enclosed data offset|
25 |-------------------------------|
27 |-------------------------------|
29 |-------------------------------|
31 CONVENTION: anything with a dsi_ prefix is kept in network byte order.
34 /* these need to be kept in sync w/ AFPTRANS_* in <atalk/afp.h>.
35 * convention: AFPTRANS_* = (1 << DSI_*) */
42 #define DSI_BLOCKSIZ 16
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 */
52 #define DSI_CMDSIZ 8192
53 #define DSI_DATASIZ 8192
54 /* child and parent processes might interpret a couple of these
58 struct dsi_block header;
59 struct sockaddr_in server, client;
61 sigset_t sigblockset, oldset;
63 struct itimerval timer, savetimer;
65 u_int32_t attn_quantum, datasize, server_quantum;
66 u_int16_t serverID, clientID;
68 u_int8_t commands[DSI_CMDSIZ], data[DSI_DATASIZ];
70 size_t datalen, cmdlen;
71 size_t read_count, write_count;
72 int asleep; /* client won't reply AFP 0x7a ? */
73 /* inited = initialized?, child = a child?, noreply = send reply? */
74 char child, inited, noreply;
76 int socket, serversock;
78 /* protocol specific open/close, send/receive
79 * send/receive fill in the header and use dsi->commands.
80 * write/read just write/read data */
81 pid_t (*proto_open)(struct DSI *);
82 void (*proto_close)(struct DSI *);
84 /* url registered with slpd */
89 /* buffer for OSX deadlock */
100 #define DSIFL_REQUEST 0x00
101 #define DSIFL_REPLY 0x01
102 #define DSIFL_MAX 0x01
104 /* DSI session options */
105 #define DSIOPT_SERVQUANT 0x00 /* server request quantum */
106 #define DSIOPT_ATTNQUANT 0x01 /* attention quantum */
109 #define DSIFUNC_CLOSE 1 /* DSICloseSession */
110 #define DSIFUNC_CMD 2 /* DSICommand */
111 #define DSIFUNC_STAT 3 /* DSIGetStatus */
112 #define DSIFUNC_OPEN 4 /* DSIOpenSession */
113 #define DSIFUNC_TICKLE 5 /* DSITickle */
114 #define DSIFUNC_WRITE 6 /* DSIWrite */
115 #define DSIFUNC_ATTN 8 /* DSIAttention */
116 #define DSIFUNC_MAX 8 /* largest command */
118 /* DSI Error codes: most of these aren't used. */
119 #define DSIERR_OK 0x0000
120 #define DSIERR_BADVERS 0xfbd6
121 #define DSIERR_BUFSMALL 0xfbd5
122 #define DSIERR_NOSESS 0xfbd4
123 #define DSIERR_NOSERV 0xfbd3
124 #define DSIERR_PARM 0xfbd2
125 #define DSIERR_SERVBUSY 0xfbd1
126 #define DSIERR_SESSCLOS 0xfbd0
127 #define DSIERR_SIZERR 0xfbcf
128 #define DSIERR_TOOMANY 0xfbce
129 #define DSIERR_NOACK 0xfbcd
131 /* server and client quanta */
132 #define DSI_DEFQUANT 2 /* default attention quantum size */
133 #define DSI_SERVQUANT_MAX 0xffffffff /* server quantum */
134 #define DSI_SERVQUANT_MIN 32000 /* minimum server quantum */
135 #define DSI_SERVQUANT_DEF 0x0004A2E0L /* default server quantum */
137 /* default port number */
138 #define DSI_AFPOVERTCP_PORT 548
140 /* basic initialization: dsi_init.c */
141 extern DSI *dsi_init __P((const dsi_proto /*protocol*/,
142 const char * /*program*/,
143 const char * /*host*/, const char * /*address*/,
144 const int /*port*/, const int /*proxy*/,
145 const u_int32_t /* server quantum */));
146 extern void dsi_setstatus __P((DSI *, char *, const size_t));
148 /* in dsi_getsess.c */
149 extern DSI *dsi_getsession __P((DSI *, server_child *, const int));
150 extern void dsi_kill __P((int));
153 /* DSI Commands: individual files */
154 extern void dsi_opensession __P((DSI *));
155 extern int dsi_attention __P((DSI *, AFPUserBytes));
156 extern int dsi_cmdreply __P((DSI *, const int));
157 extern int dsi_tickle __P((DSI *));
158 extern void dsi_getstatus __P((DSI *));
159 extern void dsi_close __P((DSI *));
160 extern void dsi_sleep __P((DSI *, const int ));
162 /* set, unset socket blocking mode */
163 extern int dsi_block __P((DSI *, const int));
165 /* low-level stream commands -- in dsi_stream.c */
166 extern size_t dsi_stream_write __P((DSI *, void *, const size_t, const int mode));
167 extern size_t dsi_stream_read __P((DSI *, void *, const size_t));
168 extern int dsi_stream_send __P((DSI *, void *, size_t));
169 extern int dsi_stream_receive __P((DSI *, void *, const size_t, size_t *));
171 /* client writes -- dsi_write.c */
172 extern size_t dsi_writeinit __P((DSI *, void *, const size_t));
173 extern size_t dsi_write __P((DSI *, void *, const size_t));
174 extern void dsi_writeflush __P((DSI *));
175 #define dsi_wrtreply(a,b) dsi_cmdreply(a,b)
177 /* client reads -- dsi_read.c */
178 extern ssize_t dsi_readinit __P((DSI *, void *, const size_t, const size_t,
180 extern ssize_t dsi_read __P((DSI *, void *, const size_t));
181 extern void dsi_readdone __P((DSI *));
183 /* some useful macros */
184 #define dsi_serverID(x) ((x)->serverID++)
185 #define dsi_send(x) do { \
186 (x)->header.dsi_len = htonl((x)->cmdlen); \
187 dsi_stream_send((x), (x)->commands, (x)->cmdlen); \
189 #define dsi_receive(x) (dsi_stream_receive((x), (x)->commands, \
190 DSI_CMDSIZ, &(x)->cmdlen))
191 #endif /* atalk/dsi.h */