1139823Simp/*-
270744Sbp * Copyright (c) 1999, 2000, 2001 Boris Popov
352153Sbp * All rights reserved.
452153Sbp *
552153Sbp * Redistribution and use in source and binary forms, with or without
652153Sbp * modification, are permitted provided that the following conditions
752153Sbp * are met:
852153Sbp * 1. Redistributions of source code must retain the above copyright
952153Sbp *    notice, this list of conditions and the following disclaimer.
1052153Sbp * 2. Redistributions in binary form must reproduce the above copyright
1152153Sbp *    notice, this list of conditions and the following disclaimer in the
1252153Sbp *    documentation and/or other materials provided with the distribution.
1352153Sbp *
1452153Sbp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1552153Sbp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1652153Sbp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1752153Sbp * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1852153Sbp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1952153Sbp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2052153Sbp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2152153Sbp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2252153Sbp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2352153Sbp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2452153Sbp * SUCH DAMAGE.
2552153Sbp *
2652153Sbp * $FreeBSD$
2752153Sbp */
2852153Sbp
2952704Sbp#ifndef _NETNCP_NCP_LIB_H_
3052704Sbp#define _NETNCP_NCP_LIB_H_
3152153Sbp
3252153Sbp#define IPX
3352153Sbp#define INET
3452153Sbp
3552153Sbp#include <netncp/ncp.h>
3652153Sbp#include <netncp/ncp_conn.h>
3752153Sbp#include <netncp/ncp_user.h>
3852153Sbp#include <netncp/ncp_rq.h>
3952153Sbp
4052153Sbp#define ncp_printf printf
4152153Sbp
4252153Sbp#define sipx_cnetwork	sipx_addr.x_net.c_net
4352153Sbp#define sipx_node	sipx_addr.x_host.c_host
4452153Sbp#define ipx_netlong(iaddr) (((union ipx_net_u *)(&((iaddr).x_net)))->long_e)
4552153Sbp
4652153Sbp#define	STDPARAM_ARGS	'A':case 'B':case 'C':case 'I':case 'M': \
4752153Sbp		   case 'N':case 'U':case 'R':case 'S':case 'T': \
4852153Sbp		   case 'W':case 'O':case 'P'
4952153Sbp
5070744Sbp#define STDPARAM_OPT	"A:BCI:M:NO:P:U:R:S:T:W:"
5152153Sbp
5252153Sbp#ifndef min
5352153Sbp#define	min(a,b)	(((a)<(b)) ? (a) : (b))
5452153Sbp#endif
5552153Sbp
5652153Sbp
5752153Sbp/*
5852153Sbp * An attempt to do a unified options parser
5952153Sbp */
6052153Sbpenum ncp_argtype {NCA_STR,NCA_INT,NCA_BOOL};
6152153Sbp
6252153Sbpstruct ncp_args;
6352153Sbp
6452153Sbptypedef int ncp_setopt_t (struct ncp_args*);
6552153Sbp
6652153Sbp#define	NAFL_NONE	0x0000
6752153Sbp#define	NAFL_HAVEMIN	0x0001
6852153Sbp#define	NAFL_HAVEMAX	0x0002
6952153Sbp#define	NAFL_MINMAX	NAFL_HAVEMIN | NAFL_HAVEMAX
7052153Sbp
7152153Sbpstruct ncp_args {
7252153Sbp	enum ncp_argtype at;
7352153Sbp	int	opt;	/* command line option */
7452153Sbp	char	*name;	/* rc file equiv */
7552153Sbp	int	flag;	/* NAFL_* */
7652153Sbp	int	ival;	/* int/bool values, or max len for str value */
7752153Sbp	char	*str;	/* string value */
7852153Sbp	int	min;	/* min for ival */
7952153Sbp	int	max;	/* max for ival */
8052153Sbp	ncp_setopt_t *fn;/* call back to validate */
8152153Sbp};
8252153Sbp
8352153Sbptypedef struct {
8452153Sbp  nuint8    day;
8552153Sbp  nuint8    month;
8652153Sbp  nuint16   year;
8752153Sbp} NW_DATE;
8852153Sbp
8952153Sbp/* hours is a nuint16  so that this structure will be the same length as a dword */
9052153Sbptypedef struct {
9152153Sbp  nuint8    seconds;
9252153Sbp  nuint8    minutes;
9352153Sbp  nuint16   hours;
9452153Sbp} NW_TIME;
9552153Sbp
9652153Sbpstruct ncp_bitname {
9752153Sbp	u_int	bn_bit;
98100777Sdwmalone	const char	*bn_name;
9952153Sbp};
10052153Sbp
10152704Sbp__BEGIN_DECLS
10252153Sbp
10352704Sbpint ncp_args_parserc(struct ncp_args *, char *, ncp_setopt_t *);
10452704Sbpint ncp_args_parseopt(struct ncp_args *, int, char *, ncp_setopt_t *);
10552153Sbp
10652704Sbp
10752153Sbpstruct sockaddr_ipx;
10852153Sbpstruct ipx_addr;
10952153Sbpstruct sockaddr;
11052153Sbpstruct ncp_buf;
11152153Sbpstruct rcfile;
11252153Sbp
11352153Sbpint  ncp_initlib(void);
11452704Sbpint  ncp_connect(struct ncp_conn_args *, int *);
11552704Sbpint  ncp_connect_addr(struct sockaddr *, NWCONN_HANDLE *);
11652704Sbpint  ncp_disconnect(int);
11752704Sbpint  ncp_request(int, int, struct ncp_buf *);
11852704Sbpint  ncp_conn_request(int, struct ncp_buf *);
11952704Sbpint  ncp_login(int, const char *, int, const char *);
12052704Sbpint  ncp_conn_scan(struct ncp_conn_loginfo *, int *);
12152153Sbpint  ncp_conn_cnt(void);
12252153Sbpvoid *ncp_conn_list(void);
12352704Sbpint  ncp_conn_getinfo(int, struct ncp_conn_stat *);
12452704Sbpint  ncp_conn_getuser(int, char **);
12552704Sbpint  ncp_conn2ref(int, int *);
12652704Sbpint  ncp_conn_dup(NWCONN_HANDLE, NWCONN_HANDLE *);
12752704Sbpint  ncp_path2conn(char *, int *);
12852704Sbpint  ncp_li_init(struct ncp_conn_loginfo *, int, char *[]);
12952704Sbpvoid ncp_li_done(struct ncp_conn_loginfo *);
13052704Sbpint  ncp_li_login(struct ncp_conn_loginfo *, int *);
13152704Sbpint  ncp_li_readrc(struct ncp_conn_loginfo *);
13252704Sbpint  ncp_li_check(struct ncp_conn_loginfo *);
13352704Sbpint  ncp_li_arg(struct ncp_conn_loginfo *, int, char *);
13452704Sbpint  ncp_li_setserver(struct ncp_conn_loginfo *, const char *);
13552704Sbpint  ncp_li_setuser(struct ncp_conn_loginfo *, char *);
13652704Sbpint  ncp_li_setpassword(struct ncp_conn_loginfo *, const char *);
13752704Sbpint  ncp_conn_setflags(int, u_int16_t, u_int16_t);
13852704Sbpint  ncp_conn_find(char *, char *);
13952704SbpNWCCODE NWRequest(NWCONN_HANDLE, nuint16, nuint16, NW_FRAGMENT *,
14052704Sbp    nuint16, NW_FRAGMENT *);
14152153Sbp
14252153Sbp#define ncp_setpermanent(connHandle,on)	ncp_conn_setflags(connHandle, NCPFL_PERMANENT, (on) ? NCPFL_PERMANENT : 0)
14352153Sbp#define ncp_setprimary(connHandle,on)	ncp_conn_setflags(connHandle, NCPFL_PRIMARY, (on) ? NCPFL_PRIMARY : 0)
14452153Sbp
14552704Sbpint  ncp_find_fileserver(struct ncp_conn_loginfo *, int, char *);
14652704Sbpint  ncp_find_server(struct ncp_conn_loginfo *, int, int, char *);
14752153Sbp
14852153Sbp/* misc rotines */
14952704Sbpchar* ncp_str_upper(char *);
15052153Sbpint  ncp_open_rcfile(void);
15152704Sbpint  ncp_getopt(int, char * const *, const char *);
15252704Sbpvoid NWUnpackDateTime(nuint32, NW_DATE *, NW_TIME *);
15352704Sbpvoid NWUnpackDate(nuint16, NW_DATE *);
15452704Sbpvoid NWUnpackTime(nuint16, NW_TIME *);
15552704Sbptime_t ncp_UnpackDateTime(nuint32);
15652704Sbpint  ncp_GetFileServerDateAndTime(NWCONN_HANDLE, time_t *);
15752704Sbpint  ncp_SetFileServerDateAndTime(NWCONN_HANDLE, time_t *);
15852704SbpNWCCODE NWDownFileServer(NWCONN_HANDLE, int);
15952704SbpNWCCODE NWCloseBindery(NWCONN_HANDLE);
16052704SbpNWCCODE NWOpenBindery(NWCONN_HANDLE);
16152704SbpNWCCODE NWDisableTTS(NWCONN_HANDLE);
16252704SbpNWCCODE NWEnableTTS(NWCONN_HANDLE);
16352704SbpNWCCODE NWDisableFileServerLogin(NWCONN_HANDLE);
16452704SbpNWCCODE NWEnableFileServerLogin(NWCONN_HANDLE);
16581975Skrisvoid ncp_error(const char *, int, ...) __printf0like(1, 3);
16652704Sbpchar *ncp_printb(char *, int, const struct ncp_bitname *);
16752704Sbpvoid nw_keyhash(const u_char *, const u_char *, int, u_char *);
16852704Sbpvoid nw_encrypt(const u_char *, const u_char *, u_char *);
16952704Sbpvoid ipx_print_addr(struct ipx_addr *);
17052153Sbp
17152153Sbp/* bindery calls */
17252704Sbpint  ncp_get_bindery_object_id(NWCONN_HANDLE, u_int16_t, const char *,
17352704Sbp		struct ncp_bindery_object *);
17452704Sbpint  ncp_get_bindery_object_name(NWCONN_HANDLE, u_int32_t,
17552704Sbp		struct ncp_bindery_object *);
17652704Sbpint  ncp_scan_bindery_object(NWCONN_HANDLE, u_int32_t, u_int16_t,
17752704Sbp		char *, struct ncp_bindery_object *);
17852704Sbpint  ncp_read_property_value(NWCONN_HANDLE, int object_type, const char *,
17952704Sbp		int, const char *, struct nw_property *);
18052704Sbpint  ncp_get_encryption_key(NWCONN_HANDLE, char *);
18152704Sbpint  ncp_change_obj_passwd(NWCONN_HANDLE,
18252704Sbp	const struct ncp_bindery_object *, const u_char *,
18352704Sbp	const u_char *, const u_char *);
18452704Sbpint  ncp_keyed_verify_password(NWCONN_HANDLE, char *, char *,
18552704Sbp		struct ncp_bindery_object *);
18652153Sbp
18752153Sbp/* queue calls */
18852704Sbpint  ncp_create_queue_job_and_file(NWCONN_HANDLE, u_int32_t, struct queue_job *);
18952704Sbpint  ncp_close_file_and_start_job(NWCONN_HANDLE, u_int32_t, struct queue_job *);
19052704Sbpint  ncp_attach_to_queue(NWCONN_HANDLE, u_int32_t);
19152704Sbpint  ncp_detach_from_queue(NWCONN_HANDLE, u_int32_t);
19252704Sbpint  ncp_service_queue_job(NWCONN_HANDLE, u_int32_t, u_int16_t,
19352704Sbp		struct queue_job *);
19452704Sbpint  ncp_finish_servicing_job(NWCONN_HANDLE, u_int32_t, u_int32_t, u_int32_t);
19552704Sbpint  ncp_abort_servicing_job(NWCONN_HANDLE, u_int32_t, u_int32_t);
19652704Sbpint  ncp_get_queue_length(NWCONN_HANDLE, u_int32_t, u_int32_t *);
19752704Sbpint  ncp_get_queue_job_ids(NWCONN_HANDLE, u_int32_t, u_int32_t,
19852704Sbp		u_int32_t *, u_int32_t *, u_int32_t []);
19952704Sbpint  ncp_get_queue_job_info(NWCONN_HANDLE, u_int32_t, u_int32_t,
20052704Sbp		struct nw_queue_job_entry *);
20152153Sbp/*
20296755Strhodes * filesystem and volume calls
20352153Sbp */
20452704Sbpint  ncp_read(NWCONN_HANDLE, ncp_fh *, off_t, size_t, char *);
20552704Sbpint  ncp_write(NWCONN_HANDLE, ncp_fh *, off_t, size_t, char *);
20652704Sbpint  ncp_geteinfo(char *, struct nw_entry_info *);
20752704Sbpint  ncp_NSEntryInfo(NWCONN_HANDLE, nuint8, nuint8, nuint32, NW_ENTRY_INFO *);
20852153Sbp
20952704SbpNWCCODE NWGetVolumeName(NWCONN_HANDLE, u_char, char *);
21052153Sbp
21152153Sbp/* misc ncp calls */
21252704Sbpint  ncp_get_file_server_information(NWCONN_HANDLE, struct ncp_file_server_info *);
21352704Sbpint  ncp_get_stations_logged_info(NWCONN_HANDLE, u_int32_t,
21452704Sbp		struct ncp_bindery_object *, time_t *);
21552704Sbpint  ncp_get_internet_address(NWCONN_HANDLE, u_int32_t, struct ipx_addr *,
21652704Sbp		u_int8_t *);
21752704SbpNWCCODE NWGetObjectConnectionNumbers(NWCONN_HANDLE, pnstr8, nuint16,
21852704Sbp		pnuint16, pnuint16, nuint16);
21952153Sbp/*
22052153Sbp * Message broadcast
22152153Sbp */
22252704SbpNWCCODE NWDisableBroadcasts(NWCONN_HANDLE);
22352704SbpNWCCODE	NWEnableBroadcasts(NWCONN_HANDLE);
22452704SbpNWCCODE	NWBroadcastToConsole(NWCONN_HANDLE, pnstr8);
22552704SbpNWCCODE NWSendBroadcastMessage(NWCONN_HANDLE, pnstr8, nuint16, pnuint16, pnuint8);
22652704SbpNWCCODE NWGetBroadcastMessage(NWCONN_HANDLE, pnstr8);
22752153Sbp
22852153Sbp/*
22952153Sbp * RPC calls
23052153Sbp */
23152704SbpNWCCODE	NWSMExecuteNCFFile(NWCONN_HANDLE, pnstr8);
23252704SbpNWCCODE	NWSMLoadNLM(NWCONN_HANDLE, pnstr8);
23352704SbpNWCCODE NWSMUnloadNLM(NWCONN_HANDLE, pnstr8);
23452704SbpNWCCODE NWSMMountVolume(NWCONN_HANDLE, pnstr8, nuint32 *);
23552704SbpNWCCODE NWSMDismountVolumeByName(NWCONN_HANDLE, pnstr8);
23652704SbpNWCCODE NWSMSetDynamicCmdIntValue(NWCONN_HANDLE, pnstr8, nuint32);
23752704SbpNWCCODE NWSMSetDynamicCmdStrValue(NWCONN_HANDLE, pnstr8, pnstr8);
23852153Sbp
23952704Sbp__END_DECLS
24052153Sbp
24152704Sbpextern int ncp_opterr, ncp_optind, ncp_optopt, ncp_optreset;
24252153Sbpextern char *ncp_optarg;
24352153Sbp
24452153Sbpextern struct rcfile *ncp_rc;
24552153Sbpextern int sysentoffset;
24652704Sbp#endif /* _NETNCP_NCP_LIB_H_ */
247