acnet_h

// $Id: acnet.h,v 1.106 2016/03/04 15:27:10 neswold Exp $
/*
**	Copyright 1993-2016, Fermi Research Alliance, LLC.  All rights reserved.
*/
/******************************************************************************/
/* acnet.h
**  
**	prototypes and defined constants for argument values for
**	ACNET routines
**
*/
/******************************************************************************/

#ifndef ACNETH_DEFINED				/* do this only once */
#define	ACNETH_DEFINED

#pragma GCC diagnostic warning "-Wdeprecated-declarations"

// These symbols will help us port the code to several Unix operating systems that we use. We're trying to keep the
// conditional code to a minimum. All maintainers should try to find the most portable solution before resorting to
// platform-specific solutions. (NOTE: At this point, no effort has been done to get it to compile on SunOS.)

#define	Linux_Target	1
#define	Darwin_Target	2
#define	NetBSD_Target	3
#define	FreeBSD_Target	4
#define	SunOS_Target	5

// If target is not defined then the best assumption is Linux

#if !defined(THIS_TARGET)
    #define THIS_TARGET	Linux_Target
#endif

// Get the endianess of the the hardware

#include <inttypes.h>
#include <sys/types.h>
#if THIS_TARGET == SunOS_Target
    #include <sys/byteorder.h>

    #define BIG_ENDIAN    1234
    #define LITTLE_ENDIAN 4321

    #if defined(_BIG_ENDIAN)
        #define BYTE_ORDER BIG_ENDIAN
    #elif defined(_LITTLE_ENDIAN)
        #define BYTE_ORDER LITTLE_ENDIAN
    #endif
#elif (!defined(BYTE_ORDER) || !defined(BIG_ENDIAN))
    #include <endian.h>
#endif

#if !defined(BYTE_ORDER) || !defined(BIG_ENDIAN)
    #error Missing important endian-defining symbols -- compilation halted.
#endif

#if BYTE_ORDER == BIG_ENDIAN

inline uint16_t htoas(uint16_t v) throw()
{
    return (v >> 8) | (v << 8);
}

inline uint32_t htoal(uint32_t v) throw()
{
    return (v >> 24) | ((v >> 8) & 0xff00) | ((v << 8) & 0xff0000) | (v << 24);
}

inline uint16_t atohs(uint16_t v) throw()
{
    return (v >> 8) | (v << 8);
}

inline uint32_t atohl(uint32_t v) throw()
{
    return (v >> 24) | ((v >> 8) & 0xff00) | ((v << 8) & 0xff0000) | (v << 24);
}

#else

#define htoas(v) ((uint16_t) (v))
#define htoal(v) ((uint32_t) (v))
#define atohs(v) ((uint16_t) (v))
#define atohl(v) ((uint32_t) (v))

#endif

#define UTI_VERSION		(0x0800)

#define TRUNK_NODE(t, n)	(trunknode_t)(((trunknode_t)(t) << 8) | ((trunknode_t)(n) & 0xff))

typedef uint16_t reqid_t;
typedef uint16_t rpyid_t;
typedef uint8_t acnet_taskid_t;
typedef int32_t taskhandle_t;
typedef int32_t rad50_t;
typedef int16_t trunknode_t;

#define	ACNET_FLG_CHK	0x400
#define	ACNET_FLG_CAN	0x200
#define	ACNET_FLG_NBW	0x100

#define	ACNET_FLG_TYPE	0xe
#define	ACNET_FLG_USM	0x0
#define	ACNET_FLG_REQ	0x2
#define	ACNET_FLG_RPY	0x4

#define	ACNET_FLG_MLT	0x1

#define	NODE(a)		((uint8_t) (a))
#define	TRUNK(a)	((uint8_t) ((a) >> 8))

struct AcnetHeader {
    uint16_t flags;
    uint16_t status;
    uint8_t sTrunk;
    uint8_t sNode;
    uint8_t cTrunk;
    uint8_t cNode;
    uint32_t svrTaskName;
    uint16_t clntTaskId;
    uint16_t msgId;
    uint16_t msgLen;
    uint8_t msg[];

 private:
    enum HdrTypes { USM = 0x0, REQ = 0x2, RPY = 0x4,
		    TYP = 0xe, CAN = 0x200, MLT = 0x1 };

 public:
    AcnetHeader();
    AcnetHeader(uint16_t, uint16_t, uint16_t, uint16_t, uint32_t, uint16_t, uint16_t, uint16_t);

    bool isUSM() const { return (atohs(flags) & (TYP | CAN)) == USM; }
    bool isCancel() const { return (atohs(flags) & (TYP | CAN)) == (USM | CAN); }
    bool isRequest() const { return (atohs(flags) & TYP) == REQ; }
    bool isReply() const { return (atohs(flags) & TYP) == RPY; }
    bool isMultSet() const
    {
	return (atohs(flags) & MLT) && ((atohs(flags) & TYP) == REQ || (atohs(flags) & TYP) == RPY);
    }
} __attribute__((packed));

#define	ACNET_HEADER_SIZE	18		/* size of an ACNET header */

#define	ACNET_PTP_PACKET_SIZE	65506		/* maximum number of bytes in a peer to peer ACNET packet (must allow 28 bytes for IP headers) */

#define	ACNET_PTP_USER_PACKET_SIZE	(65506 - ACNET_HEADER_SIZE)	/* maximum number of user bytes in a peer to peer ACNET packet (must allow 18 bytes for ACNET header) */

#define	ACNET_PACKET_SIZE	(8192+128+ACNET_HEADER_SIZE)	/* maximum number of
								 * bytes in an ACNET
								 * packet */
#define	ACNET_USER_PACKET_SIZE	(8192+128)	/* maximum number of
						 * user bytes in an
						 * ACNET packet */

#define	ACNET_PORT		6801		/* ACNET port number
						 * (UDP) */

#define	ACNET_MIN_TRUNK		9		/* minimum IP trunk
						 * number */
#define	ACNET_MAX_TRUNK		14		/* maximum IP trunk
						 * number */
#define	ACNET_MIN_NODE		1		/* minimum IP node
						 * number */
#define	ACNET_MAX_NODE		255		/* maximum IP node
						 * number */
/******************************************************************************/
/* 
**	defined constants for argument values
*/
/******************************************************************************/

/*
**  acnet_callback_init ...
*/
#define	ACNET_CALLBACK_ACNET	1			/* ACNET */
#define	ACNET_CALLBACK_DATAPOOL	2			/* DPM */
#define	ACNET_CALLBACK_DATABASE	3			/* DBM */
#define	ACNET_CALLBACK_FSHARE	4			/* Filesharing */
#define	ACNET_CALLBACK_INTYPE	5			/* Console Environment */
#define	ACNET_CALLBACK_TV	6			/* TV */
#define	ACNET_CALLBACK_LX	7			/* LX */
#define	ACNET_CALLBACK_DIO	8			/* DIO */
#define	ACNET_CALLBACK_FM	9			/* File Manager */
#define	ACNET_CALLBACK_WMNGR	10			/* Window Manager */
#define	ACNET_CALLBACK_WNLIB	11			/* WNLIB graphics */
#define	ACNET_CALLBACK_SCRIPT	12			/* scripting */
#define	ACNET_CALLBACK_CMU	13			/* Console Message Utility */
#define	ACNET_CALLBACK_MEMORY	14			/* memory management */
#define	ACNET_CALLBACK_LOGGER	15			/* Datalogger/Lumberjack */
#define	ACNET_CALLBACK_SR	16			/* save/restore */
#define	ACNET_CALLBACK_SRMNGR	17			/* SR Manager */
#define	ACNET_CALLBACK_GASLIB	18			/* GAS library */
#define	ACNET_CALLBACK_FRIGLIB	19			/* Friglib */
#define	ACNET_CALLBACK_CAMACLIB	20			/* CAMAC I/O */
#define	ACNET_CALLBACK_GPIBLIB	21			/* GPIB library */
#define	ACNET_CALLBACK_SEQUENCE	22			/* sequencing */
#define	ACNET_CALLBACK_ERROR	23			/* error handling */
#define	ACNET_CALLBACK_PROCINFO	24			/* general process information */
#define	ACNET_CALLBACK_APPLICAT	25			/* application specific */
#define	ACNET_CALLBACK_ACNETAPI	26			/* high level ACNET API */
#define	ACNET_CALLBACK_LOCK	27			/* lock facility */
#define	ACNET_CALLBACK_REMVAL	28			/* remote value facility */
#define	ACNET_CALLBACK_REMPGM	29			/* REMote ProGraM facility */
#define	ACNET_CALLBACK_APPDS	30			/* APPlication Data Storage facility */
#define	ACNET_CALLBACK_FSM	31			/* States changes */
#define	ACNET_CALLBACK_WHK	32			/* DAQ Redirection changes */
#define	ACNET_CALLBACK_ACL	33			/* ACL */
#define	ACNET_CALLBACK_IDXFILE	34			/* indexed files */
#define	ACNET_CALLBACK_FLATFILE	35			/* flat files */
#define	ACNET_CALLBACK_UTILITY	36			/* utility functions */
#define	ACNET_CALLBACK_WEBLOG	37			/* web log support */
#define	ACNET_CALLBACK_SCOPE	38			/* scope support */
#define	ACNET_CALLBACK_MAX	38			/* maximum valid type code */

/*
**  net_info_access ...
*/
#define	ACNET_INFO_COM_BASE	0			/* retrieve pointer to NETCOMMON base */
#define	ACNET_INFO_PROCESS_ID	1			/* retrieve process ID */
#define	ACNET_INFO_TASK_ID	2			/* retrieve logical task ID */
#define	ACNET_INFO_TASK_NAME	3			/* retrieve network task name */
#define	ACNET_INFO_UTI_VERSION	5			/* retrieve UTI version */
#define	ACNET_INFO_COM_VERSION	6			/* retrieve NETCOMMON version */
#define	ACNET_INFO_LOCAL_NODE	7			/* retrieve default local logical node number */
#define	ACNET_INFO_LOCAL_TRUNK	9			/* retrieve default local trunk number */
#define	ACNET_INFO_HANDLE	11			/* retrieve current ACNET handle */
#define ACNET_INFO_CHECK_RUM	12			/* check if RUM name exists */

/*
**  acnet_get_reply ...
*/
#define	ACNET_NEXT_REPLY	0			/* retrieve next reply */
#define	ACNET_ANY_REPLY		65535			/* retrieve any reply */

#define	ACNET_CANREQ		65535			/* cancel request */

/*
**  acnet_node_name ...
*/
#define	ACNET_TRANS_TO_NAME	0			/* translate from node to name */
#define	ACNET_TRANS_TO_NODE	1			/* translate from name to node */

/*
**  acnet_wait ...
*/
#define	ACNET_NO_MESSAGE	0			/* no message received */
#define	ACNET_REQUEST_RECEIVED	1			/* ACNET request received */
#define	ACNET_REPLY_RECEIVED	2			/* ACNET reply received */


/******************************************************************************/
/* 
**	data structures for use with ACNET routines
*/
/******************************************************************************/

#define	UAB_M_CANCEL		0x80			/* request being cancelled flag bit */
#define	UAB_M_MSGTYPE		0x0E			/* message type field */
#define	UAB_M_MULTRPY		0x01			/* multiple reply flag bit */
#define	UAB_M_TOOLONG		0x40			/* message truncation flag bit */
#define	UAB_M_1STPKT		0x80			/* 1st packet reply AST indicator */

#define	UAB_K_REPLY		4			/* reply message type */
#define	UAB_K_REQUEST		2			/* request message type */
#define	UAB_K_USM		0			/* unsolicited special message type (USM) */

#define ACNET_MSG_IS_USM(uab)     (((uab)->uab_r_flags.uab_b_flags&UAB_M_MSGTYPE)==UAB_K_USM)
#define ACNET_MSG_IS_REQUEST(uab) (((uab)->uab_r_flags.uab_b_flags&UAB_M_MSGTYPE)==UAB_K_REQUEST)
#define ACNET_MSG_IS_REPLY(uab)   (((uab)->uab_r_flags.uab_b_flags&UAB_M_MSGTYPE)==UAB_K_REPLY)

#define	UAB_S_MSGTYPE		3			/* size of message type field */

/*
  Flags for replies, returned in reply UAB's or by CHECK_REPLY/WAIT_REPLY.
*/
struct UAB_REPLY_FLAGS
    {
    unsigned	uab_v_multrpy : 1;
    unsigned : 5;
    unsigned	uab_v_toolong : 1;
    unsigned	uab_v_1stpkt : 1;
    } __attribute__((packed));

/*
  Flags for requests, returned in request UAB's or by
  CHECK_REQUEST/WAIT_REQUEST.
*/
struct UAB_REQUEST_FLAGS
    {
    unsigned	uab_v_multrpy : 1;
    unsigned	uab_v_msgtype : UAB_S_MSGTYPE;
    unsigned : 2;
    unsigned	uab_v_toolong : 1;
    unsigned	uab_v_cancel : 1;
    } __attribute__((packed));

#define	UAB_K_LENGTH		20			/* length of UAB in bytes */
#define	UAB_K_EXTLEN		24			/* length of extended UAB in bytes */

/*
  Definitions for use in Reply AST's only
*/
typedef struct UAB_REPLY
    {
    unsigned short	uab_w_reqid;			/* request identification */
    short	uab_w_rpylen;				/* reply length (in words) */
    char	*uab_l_rpyadr;				/* address of reply buffer */
    unsigned char	uab_b_rpysts;			/* reply status byte */
    union
	{
	unsigned char	uab_b_flags;			/* byte of bit flags */
	struct UAB_REPLY_FLAGS	uab_z_rpyflgs;
	} __attribute__((packed)) uab_r_flags;
    short	uab_w_rpysts;				/* ACNET global reply status */
    unsigned : 32;					/* spares */
    unsigned : 32;
    } __attribute__((packed)) uab_reply_t;

/*
  Definitions for use in Request AST's only
*/
typedef struct UAB_REQUEST
    {
    unsigned short	uab_w_rpyid;			/* reply identification */
    short	uab_w_reqlen;				/* request length (in words) */
    char	*uab_l_reqadr;				/* address of receive buffer */
    unsigned char	uab_b_reqsts;			/* request status */
    union
	{
	unsigned char	uab_b_flags;			/* byte of bit flags */
	struct UAB_REQUEST_FLAGS	uab_z_reqflgs;
	} __attribute__((packed)) uab_r_flags;
    unsigned char	uab_b_d_node;			/* destination logical node */
    unsigned char	uab_b_d_tskid;			/* destination task id */
    unsigned short	uab_w_rrqid;			/* source request identification */
    unsigned char	uab_b_s_node;			/* source logical node */
    unsigned char	uab_b_s_tskid;			/* source task id */
    unsigned : 16;					/* spares */
    unsigned char	uab_b_d_lan;			/* destination LAN id (trunk) */
    unsigned char	uab_b_s_lan;			/* source LAN id (trunk) */
    unsigned int	uab_l_tasknm;			/* destination task name */
    } __attribute__((packed)) uab_request_t;

/*
  Request Option Flag Definitions
*/
#define	REQ_M_NORMAL		0x00			/* no special options selected */
#define	REQ_M_MULTRPY		0x01			/* multiple reply request */
#define	REQ_M_NOBSYWT		0x02			/* don't queue to busy task */
#define	REQ_M_FCPAST		0x04			/* enable first packet reply AST */
#define	REQ_M_USM		0x08			/* UnSolicited Message */

struct UAB_REQUEST_OPTION_FLAGS
    {
    unsigned	req_v_multrpy : 1;
    unsigned	req_v_nobsywt : 1;
    unsigned	req_v_fcpast : 1;
    unsigned : 5;
    };

/*
  Reply Option Flag Definitions
*/
#define	RPY_M_NORMAL		0			/* terminate multiple reply request */
#define	RPY_M_ENDMULT		0x02			/* terminate multiple reply request */
#define	RPY_M_LOCKED		0x04			/* don't unlock recv buffer */

struct UAB_REPLY_OPTION_FLAGS
    {
    unsigned : 1;
    unsigned	rpy_v_endmult : 1;
    unsigned	rpy_v_locked : 1;
    unsigned : 5;
    };


/******************************************************************************/
/* 
**	returned status definitions for ACNET routines
*/
/******************************************************************************/

#define	NET__PENDING		0			/* pending */
#define	NET__BUGCHECK		0x08018014		/* internal network error */
#define	NET__DISCONING		0x080180C8		/* task being disconnected */
#define	NET__ENDMLTRPY		0x0801800B		/* final reply of mult-rpy request */
#define	NET__ILLACNCOD		0x0801801C		/* illegal ACNET typecode */
#define	NET__INCWRTPWD		0x08018024		/* incorrect password */
#define	NET__IOERROR		0x0801808A		/* unspecified I/O error */
#define	NET__NOBUFFER		0x08018092		/* no free buffer slots */
#define	NET__NOBUFR		0x0801802C		/* no buffer address */
#define	NET__NOCTLBLK		0x0801809A		/* no free control blocks */
#define	NET__NODEDOWN		0x080180A2		/* destination node is down */
#define	NET__NOMEMRMT		0x080180AA		/* no memory at remote node */
#define	NET__NOMSG		0x08018034		/* no message given */
#define	NET__NORPYBUF		0x0801803C		/* no reply buffer given */
#define	NET__NOSUCHREQ		0x08018044		/* no such request found */
#define	NET__NOTALLLCK		0x08018054		/* not all of NETCOMMON locked */
#define	NET__NOTALLMAP		0x0801804C		/* not all of NETCOMMOM mapped */
#define	NET__NOTBLKOWN		0x08018120		/* not req/rpy control block owner */
#define	NET__NOTCNCT		0x0801805C		/* not connected to network */
#define	NET__NOTREQID		0x08018064		/* not a request ID code */
#define	NET__NOTRPYID		0x0801806C		/* not a reply ID code */
#define	NET__NOTRUM		0x08018074		/* not RUM-connected */
#define	NET__REQPKTERR		0x080180D0		/* request packet assembly error */
#define	NET__REQTBLFUL		0x080180D8		/* request/reply table full */
#define	NET__REQTRUNC		0x080180E0		/* request message truncated */
#define	NET__RPYPKTERR		0x080180F0		/* reply packet assembly error */
#define	NET__RPYTBLFUL		0x080180E8		/* no table room for reply */
#define	NET__RPYTRUNC		0x080180F8		/* reply message truncated */
#define	NET__RUMLSTFUL		0x080180B2		/* RUM list is full */
#define	NET__RUMNAMEXI		0x080180BA		/* RUM name already exists */
#define	NET__SUPSINFO		0x08018113		/* software support reply code */
#define	NET__SYSERR		0x080180C2		/* system service error */
#define	NET__TASKBUSY		0x08018100		/* destination task busy */
#define	NET__TOOLONG		0x0801807C		/* message is too int */
#define	NET__TSKLSTFUL		0x08018084		/* network task list full */
#define	NET__TSKQFUL		0x08018108		/* destination task queue full */
#define	NET__USRINFO		0x0801811B		/* user software reply code */
#define	NET__NODTABFUL		0x08018128		/* node translation table full */
#define	NET__LOCKSTUK		0x08018134		/* interlock bit stuck ON */
#define	NET__HANLSTFUL		0x08018138		/* cannot connect - handle list full */
#define	NET__NOSUCHHAN		0x08018140		/* no such handle found */
#define	NET__ASTACTIVE		0x08018148		/* function not supported AST level */


/******************************************************************************/
/*
**	prototypes for ACNET routines
*/
/******************************************************************************/

typedef	int (*uab_callback_t)(uab_request_t *at);
typedef	int (*uab_rplyback_t)(uab_reply_t *at);

#ifdef __cplusplus
extern "C" {
#endif

int acnet_accept_requests(char *task, char *node_name=(char *) 0);
int acnet_callback_init(short typecode, void (*tc_handler)(),
			void *user_arg, int ast_flag);
void acnet_callback_flush(void);
int acnet_callback_handle(char const *handle, char const *node_name=(char *) 0);
int acnet_callback_handle_return(int *node=(int *) 0);
int acnet_cancel_request(char *task, unsigned short request_id);
int acnet_check_if_handle_is_available(char const *net_handle,
				       char const *node_name=(char *) 0);
int acnet_connect(char const *task, char const *node_name=(char *) 0);
int acnet_current_handle(char *net_handle);
int acnet_current_rum_handle(char *net_handle);
int acnet_default_connect(char *connect_name, char *node_name=(char *) 0);
int acnet_default_connect_name(char *connect_name);
int acnet_disconnect(char const *handle);
int acnet_get_active_handles(int *num_handles, char **handles=(char **) 0,
			     int **is_rum=(int **) 0);
uab_reply_t *acnet_getnext_reply(unsigned short reqid, short usrto,
				 int *status);
uab_request_t *acnet_getnext_request(char *handle);
uab_reply_t *acnet_get_reply(char *task, unsigned short *request_id,
			     unsigned short timeout, int *ret_status);
uab_request_t *acnet_get_request(char *task, unsigned short timeout,
				 int *ret_status);
int acnet_is_rum_handle(char *net_handle);
int acnet_node_name(short *node, char *name, int operation);
int acnet_receive_requests(char const *handle, uab_callback_t usrast,
			   uab_callback_t cancel_ast=(uab_callback_t) 0,
			   char const *node_name=(char *) 0);
int acnet_reply(char *task, unsigned short reply_id,
		void *reply_buffer, unsigned int reply_length,
		unsigned short reply_flags, short reply_status);
int acnet_request(char const *task, short to_node, char const *to_task,
		  void const *request_buffer, unsigned int request_length,
		  unsigned short request_flags, unsigned short *request_id);
int acnet_request_multrpy(short to_node, int to_task, void *reqbuf, int reqlen,
  			  uab_rplyback_t rpyast, unsigned short *reqid);
int acnet_request_wait(char *task, short dest_node,
		       char *dest_task, void *request_buffer,
		       unsigned int request_length, void *reply_buffer,
		       unsigned int reply_length, unsigned short timeout,
		       int *bytes_returned);
int acnet_send_reply(unsigned short id, void *reply, unsigned int reply_len,
		     short add_flag);
int acnet_set_handle(char *net_handle, char *prev_handle);
int acnet_task_get_ids_c(char *task_name, int node, int *task_id,
			 int *process_id=(int *) 0);
int acnet_usm_request(char const *task, short to_node, char const *to_task,
		      void const *request_buffer, unsigned int request_length);
int acnet_wait(char *task, unsigned short timeout);
int	jradix50(char const*string);
int	net_alt_node(short node, short *alt_node);
int	net_rpysts_test(short *reply_status);
  int	net_set_option(char option, int new_value) __attribute__((deprecated));
short	net_sts16(int *status);
int	net_trn_node(short node, int *name);
int	net_trn_nodename(char *name, short *lan_id);
int	net_trn_nodename_desc(char *name, short *lan_id,
			      unsigned char *node_type, unsigned short *nchar);

int	net_info_access(char itemcode, int datum = 0);
int	net_trn_node_desc(short node, int *rad50_name, unsigned char *node_type,
			  unsigned short *node_char, short *nextnode = 0 );


short	ntcan(reqid_t *request_id);
short	ntcnct(taskhandle_t *task_name = 0);
short   ntcreq(rpyid_t *reply_id, int16_t *message_length = 0, int16_t *node = 0,
	       char *flag = 0, reqid_t *request_id = 0, int16_t *srcadr = 0);
short	ntcrpy(reqid_t *request_id, uint16_t *return_length = 0,
	       char *flags = 0, int16_t *status = 0);
short	ntdcnt(void);
short	ntgtid(trunknode_t *node, taskhandle_t *task_name, acnet_taskid_t *task_id);
short	ntgtnm(trunknode_t *node, acnet_taskid_t *task_id, taskhandle_t *task_name);
short	ntrreq(void *reqbuf = 0, int16_t *reqmxl = 0, char *efn = 0, void (*usrast)(uab_request_t*) = 0);
short	ntrrpy(reqid_t *request_id, void *reply_buf = 0,
               int16_t *rpymxl = 0, char *efn = 0, void (*usrast)(uab_reply_t*) = 0);
short	ntsend(trunknode_t *node, taskhandle_t *task_name, void const *message, int16_t *message_len);
short	ntsreq(trunknode_t *node, taskhandle_t *task_name, int16_t *request_flags,
	       void const *request_buffer, int16_t *request_length,
	       reqid_t *request_id, void *reply_buffer,
	       int16_t *reply_length, char *efn = 0, void (*usrast)(uab_reply_t*) = 0);
short	ntsrpy(rpyid_t const *reply_id, int16_t *reply_flag = 0,
	       void const *reply_buffer = 0, int16_t *reply_length = 0, int16_t *reply_status = 0);
short	ntsrr(trunknode_t *node, taskhandle_t *task_name, void *request_buffer,
	      int16_t *request_length, void *reply_buffer, int16_t *reply_length,
	      char *event_flag, int16_t *timeout = 0, int16_t *retries = 0, 
	      int16_t *reply_msg_len = 0);
short	ntstat(int16_t *reply_status);
short	ntwreq(rpyid_t *reply_id, int16_t *msg_length = 0,
	       trunknode_t *node = 0, int16_t *flags = 0, reqid_t *request_id = 0,
	       char *source = 0);
short	ntwrpy(reqid_t *request_id, uint16_t *reply_length = 0,
	       char *reply_flags = 0, int16_t *reply_status = 0, uint16_t timeout = 0);


int	ntv_connect(taskhandle_t task_name = 0, rad50_t virtual_node_name = 0);
int	ntv_disconnect();
int	ntv_disconnect_task(taskhandle_t);
int	ntv_cancel_request(reqid_t* request_id);
int 	ntv_check_reply(reqid_t* request_id, uint16_t *return_length = 0,
			char *flags = 0, int16_t *status = 0);
int	ntv_check_request(rpyid_t *reply_id, int16_t *message_len = 0, 
			  trunknode_t *node = 0, char *flag = 0, reqid_t *request_id = 0, 
			  int16_t *srcadr = 0, trunknode_t *cNode = 0,
			  char const *handle=(char *) 0);

int	ntv_get_taskid(trunknode_t node, taskhandle_t task_name, acnet_taskid_t *task_id);
int	ntv_get_taskname(trunknode_t node, acnet_taskid_t task_id, taskhandle_t *task_name);
int	ntv_handle(taskhandle_t handle, taskhandle_t *old_handle = 0) __attribute__((deprecated));
int	ntv_current_handle(taskhandle_t *currentHandle);
int	ntv_lcl_retry(int32_t status);
int 	ntv_receive_reply(reqid_t *request_id, void *reply_buf = 0,
			  int16_t rpymxl = 0, char efn = 0, void (*usrast)(uab_reply_t*) = (void (*)(uab_reply_t*)) -1);
int 	ntv_receive_request(void *reqbuf = 0, int16_t reqmxl = 0, char efn = 0, 
			    void (*usrast)(uab_request_t*) = (void (*)(uab_request_t*)) -1,
			    char const *handle=(char *) 0);
int	ntv_rmt_retry(int32_t status);
int	ntv_send(trunknode_t node, taskhandle_t task_name, void const *message, int16_t length);
int	ntv_send_reply(rpyid_t const* reply_id, int16_t reply_flag,
		       void const *reply_buffer, int16_t reply_length,
		       int16_t reply_status = 0);
int	ntv_send_request(trunknode_t node, taskhandle_t task_name, int16_t request_flag,
			 void const *request_buffer, int16_t request_length,
			 reqid_t *request_id, void* reply_buffer,
			 int16_t reply_length, char efn = 0, void (*usrast)(uab_reply_t*) = 0);
int	ntv_status(int16_t status);
short	ntv_sts16(int32_t status);
int	ntv_sts32(int16_t status);
int	ntv_wait_reply(reqid_t *request_id, uint16_t *reply_length = 0,
		       char *reply_flags = 0, int16_t *reply_status = 0, uint16_t timeout = 0);
int	ntv_wait_request(rpyid_t *reply_id, int16_t *msg_length = 0,
			 trunknode_t *node = 0, char *flags = 0, reqid_t *request_id = 0,
			 char *source = 0, trunknode_t *cNode = 0, uint16_t timeout = 0);
int32_t ntv_default_node(trunknode_t* node);

int32_t ntv_node_lookup(char const*, trunknode_t*);
int32_t ntv_name_lookup(trunknode_t, char* = 0, uint32_t = 0);
int32_t ntv_add_node(trunknode_t, uint32_t, char const* const, uint32_t = 0);
int32_t ntv_set_forwarding_task(taskhandle_t);

int	rad50_to_ascii(int *rad50_name, char *ascii_name);

#ifdef __cplusplus
}
#endif


/******************************************************************************/
/*
**	equivalent name definitions
*/
/******************************************************************************/

#define	ACNET_ACCEPT_REQUESTS		acnet_accept_requests
#define	ACNET_CALLBACK_INIT		acnet_callback_init
#define	ACNET_CALLBACK_FLUSH		acnet_callback_flush
#define	ACNET_CALLBACK_HANDLE		acnet_callback_handle
#define	ACNET_CANCEL_REQUEST		acnet_cancel_request
#define	ACNET_CONNECT			acnet_connect
#define	ACNET_CURRENT_RUM_HANDLE	acnet_current_rum_handle
#define	ACNET_DEFAULT_CONNECT		acnet_default_connect
#define	ACNET_DEFAULT_CONNECT_NAME	acnet_default_connect_name
#define	ACNET_DISCONNECT		acnet_disconnect
#define	ACNET_GET_ACTIVE_HANDLES	acnet_get_active_handles
#define	ACNET_GETNEXT_REPLY		acnet_getnext_reply
#define	ACNET_GETNEXT_REQUEST		acnet_getnext_request
#define	ACNET_GET_REPLY			acnet_get_reply
#define	ACNET_GET_REQUEST		acnet_get_request
#define	ACNET_IS_RUM_HANDLE		acnet_is_rum_handle
#define	ACNET_NODE_NAME			acnet_node_name
#define	ACNET_RECEIVE_REQUESTS		acnet_receive_requests
#define	ACNET_REPLY			acnet_reply
#define	ACNET_REQUEST			acnet_request
#define	ACNET_REQUEST_MULTRPY		acnet_request_multrpy
#define	ACNET_REQUEST_WAIT		acnet_request_wait
#define	ACNET_SEND_REPLY		acnet_send_reply
#define	ACNET_SET_HANDLE		acnet_set_handle
#define	ACNET_WAIT			acnet_wait
#define	JRADIX50			jradix50
#define	NET_ALT_NODE			net_alt_node
#define	NET_INFO_ACCESS			net_info_access
#define	NET_RPYSTS_TEST			net_rpysts_test
#define	NET_SET_OPTION			net_set_option
#define	NET_STS16			net_sts16
#define NET_TRN_NODENAME		net_trn_nodename
#define	NET_TRN_NODENAME_DESC		net_trn_nodename_desc
#define	NET_TRN_NODE_DESC		net_trn_node_desc
#define	NTCAN				ntcan
#define	NTCNCT				ntcnct
#define	NTCREQ				ntcreq
#define	NTCRPY				ntcrpy
#define	NTDCNT				ntdcnt
#define	NTGTID				ntgtid
#define	NTGTNM				ntgtnm
#define	NTRREQ				ntrreq
#define	NTRRPY				ntrrpy
#define	NTSEND				ntsend
#define	NTSREQ				ntsreq
#define	NTSRPY				ntsrpy
#define	NTSRR				ntsrr
#define	NTSTAT				ntstat
#define	NTV_CANCEL_REQUEST		ntv_cancel_request
#define	NTV_CHECK_REPLY			ntv_check_reply
#define	NTV_CHECK_REQUEST		ntv_check_request
#define	NTV_CONNECT			ntv_connect
#define	NTV_DISCONNECT			ntv_disconnect
#define	NTV_GET_TASKID			ntv_get_taskid
#define	NTV_GET_TASKNAME		ntv_get_taskname
#define	NTV_HANDLE			ntv_handle
#define	NTV_LCL_RETRY			ntv_lcl_retry
#define	NTV_RECEIVE_REPLY		ntv_receive_reply
#define	NTV_RECEIVE_REQUEST		ntv_receive_request
#define	NTV_RMT_RETRY			ntv_rmt_retry
#define	NTV_SEND			ntv_send
#define	NTV_SEND_REPLY			ntv_send_reply
#define	NTV_SEND_REQUEST		ntv_send_request
#define	NTV_STATUS			ntv_status
#define	NTV_STS16			ntv_sts16
#define	NTV_STS32			ntv_sts32
#define	NTV_WAIT_REPLY			ntv_wait_reply
#define	NTV_WAIT_REQUEST		ntv_wait_request
#define	NTWREQ				ntwreq
#define	NTWRPY				ntwrpy
#define	RAD50_TO_ASCII			rad50_to_ascii


/*******************************************************************************
**++
**  FACILITY:  wacnet
**
**      Wacnet provides forwarding of a single USM to several registered
**	tasks on the same node.  It is initialzied from, and part of, the
**	AUXNETPROCESS process.
**	
**  ABSTRACT:
**
**	Wacnet forwards USMs to local tasks that have registered
**	with it.  It prefixes the USM with a typecode and name; that
**	were specified by the receiving task when it registered.
**
**	A task sends a USM to the WACNET task on a desired node with
**	a header on the message of type 'wa_head_t' (typecode WA_NET_SEND).
**
**	A receiving task must have allowed reception of Wacnet USMs
**	by a previous request to the local WACNET task using a request
**	of type 'wa_open_t' (typecode WA_NET_OPEN).  Wacnet will reply
**	with a 2-byte ACNET error-code.  When registering you give
**	your Wacnet name and a typecode.  This typecode will be in
**	your message header when Wacnet forwards USMs to you.
**
**	Wacnet will deliver the message to the registered user, with
**	a header on the original message of type 'wa_head_t'.
**
**  AUTHORS:  R Joshel
**
**  MODIFICATION HISTORY:
**
**	20 May 94	R Joshel	Created
**	14 Oct 94	G Johnson	Remove WA_NET_DUMP function
**	08 Dec 94	R Joshel	Re-work with no wild-cards; new types
**--
**/
/******************************************************************************/
#define	WA_NET_OPEN	1	/* network request: open for Wacnet USMs */
#define	WA_NET_SEND	2	/* network request: send a Wacnet USM */
#define WA_NET_STATS	3	/* network request: Wacnet statistics */
#define	WA_NET_BEAT	4	/* network request: Wacnet heartbeat */

typedef	struct	/* Wacnet USM header */
  {
  short	tc;		/* typecode */
  int	r50name;	/* rad50 Wacnet name */
  } __attribute__((packed)) wa_head_t;

struct mc_usm_header_t {
    short typeCode;
    int32_t mcServiceName;
} __attribute__((packed));

typedef	struct 	/* Request to allow Wacnet USMs */
  {
  short	wtc;		/* Wacnet typecode: WA_NET_OPEN */
  int 	r50hand;	/* forward Wacnet USMs to this rad50 task */
  short	tc;		/* in forwarded USM header: typecode */
  int	r50name;	/* in forwarded USM header: rad50 Wacnet name */
  } wa_open_t;

typedef	struct	/* Wacnet task statistics (private use) */
  {
  unsigned int	st_started;	/* start time() */
  unsigned int	st_timenow;	/* time now time() */
  unsigned int	st_totnet;	/* # of network transaction */
  unsigned int	st_neterr;	/* # of network errors */
  unsigned int	st_totopn;	/* # of open client requests */
  unsigned int	st_usmin;	/* # of wild-card USMs in */
  unsigned int	st_usmout;	/* # of wild-card USMs out */
  } wa_stats_t;

/*
**  following definitions are used for a DBNEWS multicast
*/

#define	NEW_DBNEWS			1

#define	DBNEWS_DISPLAY_NAME_LEN		64	/* length of a display name in a dbnews report */

struct dbnews_t			/* description of a device edit */
{
    int di;			/* device index edited */
    unsigned short trnode; 	/* trunk/node where modification was made */
#ifdef NEW_DBNEWS
    unsigned long long promask;	/* property mask: see dbprops.h (bit set means property was added/modified/deleted) */
    unsigned long long edtmask;	/* edit mask: see dbprops.h (bit set means property was added/modified) (bit clear means property was deleted) */
#else
    unsigned int promask;	/* property mask: see dbprops.h (bit set means property was added/modified/deleted) */
    unsigned int edtmask;	/* edit mask: see dbprops.h (bit set means property was added/modified) (bit clear means property was deleted) */
#endif
    unsigned long long flags;	/* special modification flags (DBNEWS_FLAG_xxx) */
};

struct mc_add_listener_t {
    uint32_t handle;		// Task handle to deliver multicast USM to
    short typeCode;		// User supplied type code
};

#ifdef __cplusplus
extern "C" {
#endif

int dbnews_register(char const* taskname);
int dbnews_check(void const* u_mess, size_t n, int* numof,
		 dbnews_t const** edtlst, int *console_user_id=(int *) NULL,
		 char *display_name=(char *) NULL,
		 int max_name_length=0);
void dbnews(dbnews_t* this_one, char const* device_name = "",
	    int console_user_id=0, char const *display_name="");

#ifdef __cplusplus
}
#endif

#endif

// Local Variables:
// mode:c++
// End: