1 /*-
2  * Copyright (c) 1999 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  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  * $FreeBSD: stable/9/sys/netncp/ncp_ncp.h 206361 2010-04-07 16:50:38Z joel $
27  */
28 #ifndef _NETNCP_NCP_NCP_H_
29 #define _NETNCP_NCP_NCP_H_
30 
31 #define NCP_ALLOC_SLOT		0x1111
32 #define NCP_REQUEST		0x2222
33 #define NCP_REPLY		0x3333
34 #define NCP_FREE_SLOT		0x5555
35 #define	NCP_PACKET_BURST	0x7777
36 #define NCP_POSITIVE_ACK	0x9999
37 
38 /*
39  * Bits for connection state field in ncp_rphdr
40  */
41 #define	NCP_CS_BAD_CONN		0x01	/* no such connection */
42 #define	NCP_CS_NO_SLOTS		0x04	/* no connection slots available */
43 #define	NCP_CS_SERVER_DOWN	0x10	/* server in down state */
44 #define	NCP_CS_HAVE_BROADCAST	0x40	/* server holds broadcast for us */
45 
46 #define NCP_RETRY_COUNT		5
47 #define	NCP_RETRY_TIMEOUT	10
48 #define	NCP_RESTORE_COUNT	2	/* how many times try to restore per
49 					 * single request, should be an _even_ */
50 
51 struct ncp_rqhdr {
52 	u_int16_t type;
53 	u_int8_t  seq;
54 	u_int8_t  conn_low;
55 	u_int8_t  task;
56 	u_int8_t  conn_high;
57 	u_int8_t  fn;
58 	u_int8_t  data[0];
59 } __packed;
60 
61 
62 struct ncp_rphdr {
63 	u_int16_t	type;
64 	u_int8_t	seq;
65 	u_int8_t	conn_low;
66 	u_int8_t	task;
67 	u_int8_t	conn_high;
68 	u_int8_t	completion_code;
69 	u_int8_t	connection_state;
70 	u_int8_t	data[0];
71 }__packed;
72 
73 #define	BFL_ABT		0x04
74 #define	BFL_EOB		0x10
75 #define	BFL_SYS		0x80
76 
77 #define	BOP_READ	1L
78 #define	BOP_WRITE	2L
79 
80 #define	BERR_NONE	0
81 #define	BERR_INIT	1
82 #define	BERR_IO		2
83 #define	BERR_NODATA	3
84 #define	BERR_WRITE	4
85 
86 struct ncp_bursthdr {
87 	u_short	bh_type;
88 	u_char	bh_flags;
89 	u_char	bh_streamtype;
90 	u_long	bh_srcid;
91 	u_long	bh_dstid;
92 	u_long	bh_seq;			/* HL */
93 	u_long	bh_send_delay;		/* HL */
94 	u_short	bh_bseq;		/* HL */
95 	u_short	bh_aseq;		/* HL */
96 	u_long	bh_blen;		/* HL */
97 	u_long	bh_dofs;		/* HL */
98 	u_short	bh_dlen;		/* HL */
99 	u_short	bh_misfrags;		/* HL */
100 } __packed;
101 
102 struct ncp_conn;
103 struct ncp_conn_args;
104 struct ncp_rq;
105 struct ucred;
106 
107 int  ncp_ncp_connect(struct ncp_conn *conn);
108 int  ncp_ncp_disconnect(struct ncp_conn *conn);
109 int  ncp_negotiate_buffersize(struct ncp_conn *conn, int size, int *target);
110 int  ncp_renegotiate_connparam(struct ncp_conn *conn, int buffsize,
111 	u_int8_t in_options);
112 int  ncp_get_bindery_object_id(struct ncp_conn *conn,
113 		u_int16_t object_type, char *object_name,
114 		struct ncp_bindery_object *target,
115 		struct thread *td,struct ucred *cred);
116 int  ncp_get_encryption_key(struct ncp_conn *conn, char *target);
117 int  ncp_login_encrypted(struct ncp_conn *conn,
118 	struct ncp_bindery_object *object,
119 	const u_char *key, const u_char *passwd,
120 	struct thread *td, struct ucred *cred);
121 int ncp_login_unencrypted(struct ncp_conn *conn, u_int16_t object_type,
122 	const char *object_name, const u_char *passwd,
123 	struct thread *td, struct ucred *cred);
124 int  ncp_read(struct ncp_conn *conn, ncp_fh *file, struct uio *uiop, struct ucred *cred);
125 int  ncp_write(struct ncp_conn *conn, ncp_fh *file, struct uio *uiop, struct ucred *cred);
126 
127 #endif /* _NCP_NCP_H_ */
128