FreeBSD/Linux Kernel Cross Reference
sys/netncp/ncp_rq.h
1 /*
2 * Copyright (c) 1999, 2000, 2001 Boris Popov
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Boris Popov.
16 * 4. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
32 * $FreeBSD: releng/5.2/sys/netncp/ncp_rq.h 111577 2003-02-26 21:25:55Z fjoe $
33 */
34 #ifndef _NETNCP_NCP_RQ_H_
35 #define _NETNCP_NCP_RQ_H_
36
37 #include <machine/endian.h>
38
39 #define getb(buf,ofs) (((const u_int8_t *)(buf))[ofs])
40 #define setb(buf,ofs,val) (((u_int8_t*)(buf))[ofs])=val
41 #define getbw(buf,ofs) ((u_int16_t)(getb(buf,ofs)))
42
43 #if (BYTE_ORDER == LITTLE_ENDIAN)
44
45 #define getwle(buf,ofs) (*((u_int16_t*)(&((u_int8_t*)(buf))[ofs])))
46 #define getdle(buf,ofs) (*((u_int32_t*)(&((u_int8_t*)(buf))[ofs])))
47 #define getwbe(buf,ofs) (ntohs(getwle(buf,ofs)))
48 #define getdbe(buf,ofs) (ntohl(getdle(buf,ofs)))
49
50 #define setwle(buf,ofs,val) getwle(buf,ofs)=val
51 #define setwbe(buf,ofs,val) getwle(buf,ofs)=htons(val)
52 #define setdle(buf,ofs,val) getdle(buf,ofs)=val
53 #define setdbe(buf,ofs,val) getdle(buf,ofs)=htonl(val)
54
55 #else
56 #error "Macros for Big-Endians are incomplete"
57 #define getwle(buf,ofs) ((u_int16_t)(getb(buf, ofs) | (getb(buf, ofs + 1) << 8)))
58 #define getdle(buf,ofs) ((u_int32_t)(getb(buf, ofs) | \
59 (getb(buf, ofs + 1) << 8) | \
60 (getb(buf, ofs + 2) << 16) | \
61 (getb(buf, ofs + 3) << 24)))
62 #define getwbe(buf,ofs) (*((u_int16_t*)(&((u_int8_t*)(buf))[ofs])))
63 #define getdbe(buf,ofs) (*((u_int32_t*)(&((u_int8_t*)(buf))[ofs])))
64 /*
65 #define setwle(buf,ofs,val) getwle(buf,ofs)=val
66 #define setdle(buf,ofs,val) getdle(buf,ofs)=val
67 */
68 #define setwbe(buf,ofs,val) getwle(buf,ofs)=val
69 #define setdbe(buf,ofs,val) getdle(buf,ofs)=val
70 /*
71 #define htoles(x) ((u_int16_t)(x))
72 #define letohs(x) ((u_int16_t)(x))
73 #define htolel(x) ((u_int32_t)(x))
74 #define letohl(x) ((u_int32_t)(x))
75 */
76 #endif
77
78
79 #ifdef _KERNEL
80
81 #include <sys/mchain.h>
82
83 #define NCPR_ALLOCED 0x0001 /* request structure was allocated */
84 #define NCPR_DONTFREEONERR 0x0002 /* do not free structure on error */
85
86 /*
87 * Structure to prepare ncp request and receive reply
88 */
89 struct ncp_rq {
90 int nr_flags;
91 struct mbchain rq;
92 struct mdchain rp;
93 int nr_minrplen; /* minimal rp size (-1 if not known) */
94 int nr_rpsize; /* reply size minus ncp header */
95 int nr_cc; /* completion code */
96 int nr_cs; /* connection state */
97 struct thread * nr_td; /* thread that did rq */
98 struct ucred * nr_cred; /* user that did rq */
99 int rexmit;
100 struct ncp_conn*nr_conn; /* back link */
101 };
102
103 int ncp_rq_alloc(u_int8_t fn, struct ncp_conn *ncp, struct thread *td,
104 struct ucred *cred, struct ncp_rq **rqpp);
105 int ncp_rq_alloc_any(u_int32_t ptype, u_int8_t fn, struct ncp_conn *ncp,
106 struct thread *td, struct ucred *cred, struct ncp_rq **rqpp);
107 int ncp_rq_alloc_subfn(u_int8_t fn, u_int8_t subfn, struct ncp_conn *ncp,
108 struct thread *td, struct ucred *cred, struct ncp_rq **rqpp);
109 int ncp_rq_init_any(struct ncp_rq *rqp, u_int32_t ptype, u_int8_t fn,
110 struct ncp_conn *ncp,
111 struct thread *td, struct ucred *cred);
112 void ncp_rq_done(struct ncp_rq *rqp);
113 int ncp_request(struct ncp_rq *rqp);
114 int ncp_request_int(struct ncp_rq *rqp);
115
116 struct ncp_nlstables;
117
118 int ncp_rq_pathstring(struct ncp_rq *rqp, int size, const char *name, struct ncp_nlstables*);
119 int ncp_rq_dbase_path(struct ncp_rq *, u_int8_t vol_num,
120 u_int32_t dir_base, int namelen, u_char *name, struct ncp_nlstables *nt);
121 int ncp_rq_pstring(struct ncp_rq *rqp, const char *s);
122
123 void ncp_sign_init(const char *logindata, char *sign_root);
124
125 #else /* ifdef _KERNEL */
126
127 #define DECLARE_RQ struct ncp_buf conn1, *conn=&conn1
128
129 #define ncp_add_byte(conn,x) (conn)->packet[(conn)->rqsize++]=x
130
131 struct ncp_buf;
132
133 __BEGIN_DECLS
134
135 void ncp_init_request(struct ncp_buf *);
136 void ncp_init_request_s(struct ncp_buf *, int);
137 void ncp_add_word_lh(struct ncp_buf *, u_int16_t);
138 void ncp_add_dword_lh(struct ncp_buf *, u_int32_t);
139 void ncp_add_word_hl(struct ncp_buf *, u_int16_t);
140 void ncp_add_dword_hl(struct ncp_buf *, u_int32_t);
141 void ncp_add_mem(struct ncp_buf *, const void *, int);
142 void ncp_add_mem_nls(struct ncp_buf *, const void *, int);
143 void ncp_add_pstring(struct ncp_buf *, const char *);
144 void ncp_add_handle_path(struct ncp_buf *, nuint32, nuint32, int, const char *);
145
146 #define ncp_reply_data(conn,offset) ((conn)->packet+offset)
147 #define ncp_reply_byte(conn,offset) (*(u_int8_t*)(ncp_reply_data(conn, offset)))
148
149 u_int16_t ncp_reply_word_hl(struct ncp_buf *, int);
150 u_int16_t ncp_reply_word_lh(struct ncp_buf *, int);
151 u_int32_t ncp_reply_dword_hl(struct ncp_buf *, int);
152 u_int32_t ncp_reply_dword_lh(struct ncp_buf *, int);
153
154 static __inline void
155 ConvertToNWfromDWORD(u_int32_t sfd, ncp_fh *fh) {
156 fh->val1 = (fh->val.val32 = sfd);
157 return;
158 }
159
160 __END_DECLS
161
162 #endif /* ifdef _KERNEL */
163
164 #endif /* !_NETNCP_NCP_RQ_H_ */
Cache object: f33480d751b77bbaf09b4fe6e4d3a90b
|