#ident "$Id: lmi.h,v 1.1 1995/04/13 15:35:51 garyp Exp $"
/*****************************************************************************
 * Copyright (c) 1988-95 Digi International Inc., All Rights Reserved
 * 
 * This  software  contains  proprietary  and  confidential   information   of
 * Digi International  Inc.   By  accepting  transfer  of this copy, Recipient
 * agrees to retain this software in  confidence,  to  prevent  disclosure  to
 * others,  and  to make no  use of this software other than that for which it
 * was delivered.  This is an unpublished copyright work  Digi   International
 * Inc.    Except   as   permitted   by  federal  law,  17 USC 117, copying is
 * strictly prohibited.
 * 
 * Digi  International  Inc.  CONFIDENTIAL  -   (Digi    International    Inc.
 * Confidential  when   combined   with   the   aggregated  modules  for  this
 * product) OBJECT CODE ONLY SOURCE MATERIALS
 * 
 * (C) COPYRIGHT Digi International Inc. 1995
 * 
 * All Rights Reserved
 * 
 * US   Government   Users   Restricted   Rights   -   Use,   duplication   or
 * disclosure  restricted by GSA ADP Schedule Contract with Digi International
 * Inc.
 * 
 *****************************************************************************/

/*
 * Copyright (c) 1993 Spider Systems Limited
 *
 * This Source Code is furnished under Licence, and may not be
 * copied or distributed without express written agreement.
 *
 * All rights reserved.  Made in Scotland.
 *
 * Authors: Angus Grossart
 *
 * lmi.h of snet module
 *
 * SpiderISDN
 * Release 3.0.0 94/12/20
 * 
 * SpiderISDN Release 3 - Official Release.
 */

/* 
 * lmi.h - common header for LMI user
 * ==================================
 * This header file contains all the definitions necessary for the use of the
 * Lower MIB Interface.
 *
 */

#ifndef _SYS_SNET_LMI_
#define _SYS_SNET_LMI_

/*****************************************************************/
/* The following defines the LMI primitive operations available. */
/*****************************************************************/

extern lmi_create();  /* create one or more objects   */
extern lmi_delete();  /* delete one or more objects   */
extern lmi_get();     /* gets one or more attributes  */
extern lmi_set();     /* sets one or more attributes  */
extern lmi_event();   /* polls for any pending events */
extern lmi_link();    /* link two drivers             */
extern lmi_ulink();   /* unlink two drivers           */
extern lmi_open();    /* open a driver                */
extern lmi_close();   /* close a driver               */
extern lmi_push();    /* push a module                */
extern lmi_pop();     /* pop a module                 */
extern lmi_flush();   /* flush a driver               */

/* Generally used boolean manifest constants and type */
#define	bool_t	int

extern bool_t lmsi_debug; /* set to 1 to enable debug information */
extern bool_t lmi_einfo; /* set to 1 to enable error information */

#define LMI_INFO(x)		{printf("INFO::");printf(x); printf("\n"); }
#define LMI_EINFO(x)		{if (lmi_einfo) printf("ERROR::%s\n",x); }
#define LMI_EINFOV(x)		{if (lmi_einfo) {printf("ERROR::");printf x;} }

/*************************************************************************/
/*     The following are the LMI primitive operations available          */
/*************************************************************************/

typedef	int	attid_t;
typedef	int	classid_t;
typedef	char	octet_t;


/* 
 * The following structures define the ATTRIBUTE, LENGTH and VALUE tuples used
 * to encapsulate a managed object attribute information.
 */
typedef struct avl {
	attid_t	att;/* the attribute identification */
	int	len;/* attribute values length      */
	int	err;/* the returned avl error code  */
	octet_t	val[1];/* an arbitrary complex value   */
        } avl_t;


/* The size of the fixed part of the avl_t type is defined below */

#define FIXED_AVL_SIZE	(sizeof(attid_t) + sizeof(int) + sizeof(int))



/* The following structure characterises all object instances of a any 
 * object class.
 * This object instance contains a primary key for identification and
 * possibly some characteristic attributes.
 */
typedef struct inst {
	classid_t	class;/* the class object identifier	    */
	int		count;/* the number of instance avls      */
	avl_t		list[1];/* an array of attribute avls the first 
				attribute of the list is the primary key */
	} inst_t;

/* The size of the fixed part of the inst_t type is defined below */

#define	FIXED_ID_SIZE		(sizeof(classid_t) + sizeof(int))

#define	FIXED_INST_SIZE 	(FIXED_ID_SIZE + FIXED_AVL_SIZE)



/*************************************************************************/
/*     The following are the LMI AVL primitive operations available      */
/*************************************************************************/
/* the supplied parameter must point to the start of an avl */
#define LMI_ATTRIBUTE(a)	(attid_t*)(a)->rptr 
#define LMI_LENGTH(a)		(*((int*)((octet_t*)(a)->rptr + sizeof(attid_t))))
#define LMI_ERROR(a)		(*((int*)((octet_t*)(a)->rptr + sizeof(attid_t) +sizeof(int))))
#define LMI_VALUE(a)		((octet_t*)(a)->rptr + FIXED_AVL_SIZE)

/* and for accessing the header componets and primary avl given a list */

#define LMI_PRIMARY(a)	(avl_t*)((octet_t*)(a)->rptr + FIXED_ID_SIZE)
#define LMI_COUNT(a)	(*((int*)((octet_t*)(a)->rptr + sizeof(classid_t))))
#define LMI_CLASS(a)	(classid_t*)(a)->rptr 
#define LMI_HAS_DATA(a)	((a)->rptr < (a)->wptr) 

/*
 * The following information structure contains all information necessary 
 * for the fragmentation process of over sized LMI requests.
 */
typedef struct 	frag_info {
	int	headsize; 	/* current header size */	
	octet_t	*headptr; 	/* current header pointer*/
	int	datasize;	/* current data size */
	octet_t	*dataptr;	/* current data pointer*/
	int	avlsleft;	/* AVLS left to be processed */
	octet_t *listptr;	/*roving request list point */
	octet_t	*fragstart;	/*start address of current fragment */ 
	octet_t *segstart;	/*start address of current request segment */
	} frag_info_t;


/* The following information structure charaterises an LMI request */

typedef	struct	list_info	{
	octet_t	*base;	/* the base address of the request */
	int	size;	/* current size of the request list */
	int	limit;	/* size limit (in octets) for request */
	octet_t	*wptr; 	/* write pointer within list - list construction */
	octet_t	*rptr; 	/* read pointer within list */
	} list_info_t;
	
	

/*
 * The following defines a channel identifier structure, this channel may be a
 * user space to kernel STREAMS link or a user space to user space IPC link.
 */

typedef struct chanid 	
{
	int	type;  /* the channel type IPC, STREAMS	*/
	int	desc;  /* the channel (STREAMS/IPC message) descriptor */
	char	*name; /* the STREAMS device pathname */
	int	key;   /* the IPC key value */
	int	semid; /* the IPC semaphore necessary for synchronisation */
} chanid_t;


/* Standard Error codes return by all LMI primitives */

#define	LMI_OK	1 /* Successfull LMI Operation */

#define LMI_ERR	0 /* Unuccessfull LMI Operation */

#define construct_int_AVL(att,val,info) lmi_construct_int_AVL(att,val,info,AVL_REPLACE)
#define construct_str_AVL(att,val,info) lmi_construct_str_AVL(att,val,info,AVL_REPLACE)
#define construct_any_AVL(att,val,size,info) lmi_construct_any_AVL(att,val,size,info,AVL_REPLACE)
#define construct_pk_AVL(val,size,info) lmi_construct_pk_AVL(val,size,info,AVL_OK)
#define construct_dummy_pk_AVL(info) lmi_construct_dummy_pk_AVL(info,AVL_OK)
#define construct_zero_AVL(att,size,info) lmi_construct_zero_AVL(att,size,info,AVL_OK)

#endif
