/*
 *  Copyright (c) 1996-2007 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 copyrighted work of Digi International
 *  Inc.  Except as permitted by federal law, 17 USC 117, copying is strictly
 *  prohibited.
 *
 *  Restricted Rights Legend
 *
 *  Use, duplication, or disclosure by the Government is subject to
 *  restrictions set forth in sub-paragraph (c)(1)(ii) of The Rights in
 *  Technical Data and Computer Software clause at DFARS 252.227-7031 or
 *  subparagraphs (c)(1) and (2) of the Commercial Computer Software -
 *  Restricted Rights at 48 CFR 52.227-19, as applicable.
 *
 *  Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
 *
*************************************************************************
*  $Name: netos72_branch $
*  $Date: 2007/09/11 21:07:22 $
*  $Source: /cvs_tick/netsilicon_netos2/netos/h/snmp/osdefs.h,v $
*  $Revision: 1.7.26.1 $
**************************************************************************
*  File Description:
    This is the first #include file in every .c module.
    Define your system here by uncommenting a corresponding
    #define and commenting out all others.
**************************************************************************/

#ifndef _OS_DEFS_H_
#define _OS_DEFS_H_
#ifdef __cplusplus
extern "C"
{
#endif


#define FUSION_OS

/***
#define LINUX_OS
***/
/***
#define VXWORKS_OS
***/

/* For Fusion, define the version number                                */
/* #define FUSION_VERSION_5 */
/* #define FUSION_VERSION_6 */

/* The SNMP_ENTERPRISE number is assigned from IANA for your            */
/* enterprise MIB                                                       */
/* #define SNMP_ENTERPRISE     902 */
extern unsigned long SNMP_ENTERPRISE;

/* SNMP_TRAPS_ENABLED enables trap processing. If you do not want trap  */
/* processing, comment out the following line and remove traps.c from   */
/* your build process                                                   */
#define SNMP_TRAPS_ENABLED

#ifdef SNMP_TRAPS_ENABLED
/* SNMP_TRAP_DESTINATION_ADDRESS is the IP address where traps are sent */
/* see osdeps.c                                                         */
/*#define SNMP_TRAP_DESTINATION_ADDRESS 0x0a342033  *//* 10.240.1.3 */
/* customizable fields */
extern unsigned long SNMP_TRAP_DESTINATION_ADDRESS;
extern char SNMP_TRAP_COMMUNITY_STRING[];
extern unsigned long SNMP_TRAP_ENTERPRISE_OID[];
extern char sysdescriptionJD[];
extern unsigned long sysobjectid[];
extern unsigned long sysobjectidJD[];
extern int sysobjectidLen;
extern int sysobjectidJDLen;
extern int SNMP_TRAP_ENTERPRISE_OID_LEN;

/* SNMP_TRAP_VERSION is the format to send trap messages in             */
/* see osdeps.c                                                         */
#define SNMP_TRAP_VERSION   SNMP_VERSION_1
#endif /* SNMP_TRAPS_ENABLED */

/* SNMP_READ_COMMUNITY_STRING and SNMP_WRITE_COMMUNITY_STRING control   */
/* access to data for SNMPv1 and SNMPv2c messages                       */
/*#define SNMP_READ_COMMUNITY_STRING   "public"
#define SNMP_WRITE_COMMUNITY_STRING  "private"*/
extern char SNMP_READ_COMMUNITY_STRING[];
extern char SNMP_WRITE_COMMUNITY_STRING[];

/* size of I/O buffers */
#define SNMP_MSG_SIZE       2048

/* Your system descripton MIB initialization. Each of these strings     */
/* can be up to 255 characters long.                                    */
#define SNMP_VERSION_DESCRIPTION    "Fusion 5.0 SNMP for Fusion TCP/IP"
#define SNMP_SYSTEM_CONTACT         "digi.com"
#define SNMP_SYSTEM_NAME            "Digi International"
#define SNMP_SYSTEM_LOCATION    "11001 Bren Road East, Minnetonka, MN 55343"

/* Enable debugging by defining SNMP_DEBUG                              */
/* Print a binary dump of input and output messages by defining         */
/* SNMP_DEBUG_MSG_DUMP                                                  */
/* #define SNMP_DEBUG */
/* #define SNMP_DEBUG_MSG_DUMP */

/* Is your CPU big or little endian?                                    */
#ifdef NET_OS
#define CPU_IS_BIG_ENDIAN
#elif WIN32
#define CPU_IS_LITTLE_ENDIAN
#endif

/* define SNMP_BIG_STACK to allocate large buffers on the stack. When   */
/*  this is NOT defined, buffers are allocated on the heap              */
/* #define SNMP_BIG_STACK */

#ifdef FUSION_OS
#include "fns_mem.h"
#include "fns_str.h"
#include "fns_heap.h"

#define exit(a)                     /* os_idle() */
/* #define snmp_sendto(a,b,c,d,e,f,g)  fns_sendto(a,b,c,d,e,f,g) */
/* #define snmp_recvfrom(a,b,c,d,e,f,g) fns_recvfrom(a,b,c,d,e,f,g) */

#define SNMP_MALLOC(S)              h_alloc((i32)(S),NULL,1)
#define SNMP_FREE(P)                h_free((i32 *)(P))
#define SNMP_MEMCPY(D,S,L)          fns_memcpy((char*)D,(char*)S,L)
#define SNMP_MEMSET(D,V,L)          fns_memset((char*)D,V,L)
#define SNMP_MEMCMP(X,Y,L)          fns_memcmp((char*)X,(char*)Y,L)
#define SNMP_MEMZERO(D,L)           fns_memset((char*)D,'\0',L)

#define SNMP_STRCPY(D,S)            fns_strcpy((char*)D,(char*)S)
#define SNMP_STRNCPY(D,S,L)         fns_strncpy((char*)D,(char*)S,L)
#define SNMP_STRLEN(X)              fns_strlen((char*)X)
#define SNMP_STRCMP(X,Y)            fns_strcmp((char*)X,(char*)Y)

#ifdef INLINE_SNMP
#include "m.h"
#include "pr.h"
import int      snmp_input(m * mp);
import int      snmp_initialize_agent(void);
import int      snmp_close(struct so_t * sop);
import int      snmp_init(pr_t * prp);
import st       snmp_up(m * mp);
import void     snmp_start(struct netdev *ndp, int x);
#else /* INLINE_SNMP */
void do_snmp_task(void * );
#endif /* INLINE_SNMP */

extern int doSnmpTask(void);

#ifdef SNMP_DEBUG
#define SNMP_DEBUG0(s)                      os_printf(s)
#define SNMP_DEBUG1(s,x)                    os_printf(s,x)
#define SNMP_DEBUG2(s,x,y)                  os_printf(s,x,y)
#define SNMP_DEBUG3(s,x,y,z)                os_printf(s,x,y,z)
#define SNMP_DEBUG4(s,x,y,z,t)              os_printf(s,x,y,z,t)
#define SNMP_DEBUG5(s,x,y,z,t,u)            os_printf(s,x,y,z,t,u)
#define SNMP_DEBUG6(s,x,y,z,t,u,v)          os_printf(s,x,y,z,t,u,v)
    /* dump memory @ M for a length of L */
#define SNMP_DEBUG_DUMP(M,L) \
    { \
        int __l = 0; \
        u_char* __p = (u_char*)M; \
        while (__l < L) \
        { \
            SNMP_DEBUG1("%02x ", *__p++); \
            __l++; \
            if ((__l % 8) == 0) \
                SNMP_DEBUG0("\n"); \
        } \
        SNMP_DEBUG0("\n"); \
    }

#define SNMP_PANIC0(s)              {os_printf(s); exit(-1)}
#define SNMP_PANIC1(s,x)            {os_printf(s,x); exit(-1)}
#define SNMP_PANIC2(s,x,y)          {os_printf(s,x,y); exit(-1)}
#define SNMP_PANIC3(s,x,y,z)        {os_printf(s,x,y,z); exit(-1)}
#define SNMP_PANIC4(s,x,y,z,t)      {os_printf(s,x,y,z,t); exit(-1)}
#define SNMP_PANIC5(s,x,y,z,t,u)    {os_printf(s,x,y,z,t,u); exit(-1)}
#define SNMP_PANIC6(s,x,y,z,t,u,v)  {os_printf(s,x,y,z,t,u,v); exit(-1)}

#else

#define SNMP_DEBUG0(s)
#define SNMP_DEBUG1(s,x)
#define SNMP_DEBUG2(s,x,y)
#define SNMP_DEBUG3(s,x,y,z)
#define SNMP_DEBUG4(s,x,y,z,t)
#define SNMP_DEBUG5(s,x,y,z,t,u)
#define SNMP_DEBUG6(s,x,y,z,t,u,v)
#define SNMP_DEBUG_DUMP(M,L)

#define SNMP_PANIC0(s)
#define SNMP_PANIC1(s,x)
#define SNMP_PANIC2(s,x,y)
#define SNMP_PANIC3(s,x,y,z)
#define SNMP_PANIC4(s,x,y,z,t)
#define SNMP_PANIC5(s,x,y,z,t,u)
#define SNMP_PANIC6(s,x,y,z,t,u,v)

#endif

#endif /* FUSION_OS */

#ifdef LINUX_OS
#define saddr struct sockaddr_in

#ifdef SNMP_DEBUG
#define SNMP_DEBUG0(s)                      printf(s)
#define SNMP_DEBUG1(s,x)                    printf(s,x)
#define SNMP_DEBUG2(s,x,y)                  printf(s,x,y)
#define SNMP_DEBUG3(s,x,y,z)                printf(s,x,y,z)
#define SNMP_DEBUG4(s,x,y,z,t)              printf(s,x,y,z,t)
#define SNMP_DEBUG5(s,x,y,z,t,u)            printf(s,x,y,z,t,u)
#define SNMP_DEBUG6(s,x,y,z,t,u,v)          printf(s,x,y,z,t,u,v)

    /* dump memory @ M for a length of L */
#define SNMP_DEBUG_DUMP(M,L) \
    { \
        int __l = 0; \
        u_char* __p = (u_char*)M; \
        while (__l < L) \
        { \
            SNMP_DEBUG1("%02x ", *__p++); \
            __l++; \
            if ((__l % 8) == 0) \
                SNMP_DEBUG0("\n"); \
        } \
        SNMP_DEBUG0("\n"); \
    }

#else

#define SNMP_DEBUG0(s)
#define SNMP_DEBUG1(s,x)
#define SNMP_DEBUG2(s,x,y)
#define SNMP_DEBUG3(s,x,y,z)
#define SNMP_DEBUG4(s,x,y,z,t)
#define SNMP_DEBUG5(s,x,y,z,t,u)
#define SNMP_DEBUG6(s,x,y,z,t,u,v)
#define SNMP_DEBUG_DUMP(M,L)

#endif  /* SNMP_DEBUG */

#define SNMP_MALLOC(S)          malloc((S))
#define SNMP_FREE(P)            free((char *)(P))

#define SNMP_MEMCPY             memcpy
#define SNMP_MEMSET             memset
#define SNMP_MEMCMP             memcmp
#define SNMP_MEMZERO(a,l)       memset(a,'\0',l)

#define SNMP_STRCPY             strcpy
#define SNMP_STRNCPY            strncpy
#define SNMP_STRLEN             strlen
#define SNMP_STRCMP             strcmp

#define snmp_sendto(a,b,c,d,e,f,g)  sendto(a,b,c,d,e,f)
#define snmp_recvfrom(a,b,c,d,e,f,g)    recvfrom(a,b,c,d,e,f)
#define so_close(a)             close(a)

#endif /* LINUX_OS */

#ifdef SNMP_AGENT_V3

/************************************************************************/
/* SECURITY DEFINITIONS                                                 */
/************************************************************************/
/* Engine ID - See RFC2571                                              */
/* Define the length of your SNMP engine ID                             */
#define SNMP_ENGINEID_LENGTH    11

/* Define your algorithm for computing the SNMP engine ID where E is    */
/*  the address of an engineID (u_char[SNMP_ENGINEID_LENGTH])           */
void snmpEngIDmib_ip(unsigned char* engID);    /* in snmpini.c */
#define SNMP_ENGINEID_ASSIGN(E)     snmpEngIDmib_ip(E)
/* #define SNMP_ENGINEID_ASSIGN(E)     SNMP_STRCPY((char*)E, "Fusion5_0") */

/* Authentication - See RFC2574                                         */
/* SNMP_AUTHENTICATE_MSG parameters must be:                            */
/*  A = u_char* pointer to the message to be authenticated              */
/*  B = u_int   length of the the message pointed to by A               */
/*  C = u_char* pointer to output from authentication routine, buffer   */
/*                  must be at least SNMP_AUTH_DIGEST_LENGTH bytes long */
/*  D = u_char* pointer to the user authentication hash key, must be    */
/*                  SNMP_AUTH_KEY_LENGTH bytes long                     */
/* By default, use MD5 for message authentication                       */
extern int authenticateMsgMD5(unsigned char*, unsigned, unsigned char*,
    unsigned char*);

#define SNMP_AUTHENTICATE_MSG(A, B, C, D)   authenticateMsgMD5(A, B, C, D)
/* length of AUTH code in message                                       */
#define SNMP_AUTH_DIGEST_LENGTH HMACMD5_DIGEST_LENGTH


/* length of PRIV code in message                                       */
#define SNMP_PRIV_DIGEST_LENGTH DES_PROPER_LENGTH
#endif
#ifdef __cplusplus
}
#endif

#endif /* _OS_DEFS_H_ */

