⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tae_sa.c

📁 wm PNE 3.3 source code, running at more than vxworks6.x version.
💻 C
📖 第 1 页 / 共 2 页
字号:
/* tae_sa.c  - Subagent for Tornado AE  device management *//* *  Copyright 2001-2005 Wind River Systems, Inc. *  All rights reserved.  Provided under license only. *  Distribution or other use of this software is only *  permitted pursuant to the terms of a license agreement *  from Wind River Systems (and is otherwise prohibited). *  Refer to that license agreement for terms of use. */#include <copyright_wrs.h>/*modification history-------------------------01c,19apr05,job  update copyright notices01b,03dec03,job  update copyright information01a,08Jan2001,tneale Created for TAE subagent*//* * $Log: tae_sa.c,v $ * Revision 1.5  2003/01/15 14:05:18  josh * directory structure shifting * * Revision 1.4  2001/12/06 18:27:13  josh * fix include paths for tae_sa.h * * Revision 1.3  2001/11/06 21:50:54  josh * second (and hopefully final) pass of new path hacking * * Revision 1.2  2001/11/06 21:20:41  josh * revised new path hacking * * Revision 1.1.1.1  2001/11/05 17:47:50  tneale * Tornado shuffle * * Revision 1.2.4.1  2001/11/02 17:19:36  meister * added dynamic config init * * Revision 1.2  2001/04/16 19:38:44  josh * merging the kingfisher branch onto the trunk * * Revision 1.1.2.2  2001/03/12 22:11:36  tneale * Updated copyright * * Revision 1.1.2.1  2001/02/09 22:48:17  tneale * TAE Subagent.  Uses AgentX to provide support for non-kernel device management. * * *//* Includes */#include <vxWorks.h>#include <sys/socket.h>#include <sys/types.h>#include <netinet/in.h>#include <stdio.h>#include <stdlib.h>#include <taskLib.h>#include <taskHookLib.h>#include <sysLib.h>#include <msgQLib.h>#include <tickLib.h>#include <wdLib.h>#include <semLib.h>#include <sockLib.h>#include <inetLib.h>#include <wrn/wm/snmp/engine/snmp.h>#include <wrn/wm/snmp/engine/agentx.h>#include <wrn/wm/snmp/engine/buffer.h>#include <wrn/wm/snmp/engine/asn1conf.h>#include <wrn/wm/snmp/engine/etimer.h>#include <wrn/wm/snmp/engine/vxcmpnts.h>#include <wrn/wm/snmp/vxagent/tae_sa.h>#if INSTALL_COMMON_DYNAMIC_COMP_CONFIG#include <wrn/wm/common/dyncfg.h>void taeSaDyncfgInit (void);unsigned int snmpdInstalledComponentsValue = 0;SEM_ID snmpdConfigMutex;void initSnmpd (void){  envoy_dyncfg_init ();  snmpdConfigMutex = semBCreate (SEM_Q_PRIORITY, SEM_FULL);  semTake (snmpdConfigMutex,WAIT_FOREVER);  snmpdInstalledComponentsValue = (SNMPD_CORE_COMPONENT |                                    /* SNMPD_AGENTX_MASTER_COMPONENT |*/                                   SNMPD_AGENTX_SUBAGENT_COMPONENT);  semGive (snmpdConfigMutex);} #endif/* Defines */#define TIMER_PRI        200#define TIMER_STK       4096#define SUBAGENT_PRI     151#define SUBAGENT_STK    5000#define TAE_SA_ERROR       1       /* error messages */#define TAE_SA_WARN        2       /* warning messages */#define TAE_SA_INFO        3       /* information messages */#define TAE_SA_DEFAULT_TRACELEVEL   1/* Locals */LOCAL int                tae_sa_socket;LOCAL unsigned char      tae_sa_buf[2048];LOCAL bits32_t           tae_sa_packet_id        = 1;LOCAL char              *tae_sa_context          = 0;LOCAL bits8_t            tae_sa_ndc              = 0;LOCAL bits32_t           tae_sa_session_id       = 0;LOCAL bits8_t            tae_sa_timeout          = 1;LOCAL bits8_t            tae_sa_priority         = 128;LOCAL bits8_t            tae_sa_byte_order       = 0;LOCAL int                tae_sa_trace_level;LOCAL WDOG_ID            tae_sa_wdid;LOCAL SEM_ID             tae_sa_sid;LOCAL ENVOY_AX_SA_SB_T   tae_sa_sasb;struct Timer_Block {unsigned long   when;void          (*what)();};LOCAL struct Timer_Block timerBlock;typedef struct tae_sa_foo_s {    bits16_t             ref_count;    ENVOY_AX_CHUNK_T     chunk;    char                *dest_name;    bits8_t              op;    boolean_t            open_done;} tae_sa_foo_t;LOCAL tae_sa_foo_t       tae_sa_myfoo;/* Globals */MIBNODE_T	mib_root_node; /* really just a dummy to satisfy the linker *//* forward declarations */LOCAL void tae_sa_log (int level, char * pString);LOCAL STATUS io_init (void);LOCAL int sa_init (void);LOCAL void sa_main (void);LOCAL STATUS tae_sa_init (int lvl);LOCAL void timerTask (void);LOCAL STATUS subagentTask (void);void  taeSaAdmin(ptr_t cookie, ptr_t pkt);void  taeSaAdd(ptr_t cookie);void  taeSaFree(ptr_t cookie, int foobar);int   taeSaSend(ptr_t cookie, ptr_t ax_pkt, ptr_t vblist, ALENGTH_T need);/* protos for user-routines */  OBJ_ID_T * get_mib_registration_subtrees (void);  MIBNODE_T * get_mib_root_node (void);  int initialize_mib (void);/*  * These snmp hook functions are provided  * for link compatibility with the standard * envoy object files. */void snmpHookPrivRelease (SNMP_PKT_T *pkt)    { }int  snmpHookSetPduValidate (SNMP_PKT_T *pkt) { return (0); }int  snmpHookPreSet (SNMP_PKT_T *pkt)         { return (0); }int  snmpHookPostSet (SNMP_PKT_T *pkt)        { return (0); }int  snmpHookSetFailed (SNMP_PKT_T *pkt)      { return (0); } /********************************************************************************* usrTaeSaInit - Start up the TAE Subagent daemon.  ** RETURNS: OK (always)*/void usrTaeSaInit (void)    {    tae_sa_init (TAE_SA_DEFAULT_TRACELEVEL);    }/********************************************************************************* envoy_ax_sa_mib_root_node - Get the root for the current MIB** RETURNS: OK (always)*/int envoy_ax_sa_mib_root_node (ptr_t cookie, SNMP_PKT_T *pktp)    {    pktp->mib_root = get_mib_root_node ();    return (0);    }/********************************************************************************* envoy_now - return the number of clock ticks elapsed since the timer was set** Call this function to find out the number of clock ticks elapsed since* the timer was set.** RETURNS: Elapsed time, in ticks.**/bits32_t envoy_now (void)    {    bits32_t    timeticks = 0;    ulong_t     clkRate = sysClkRateGet ();    timeticks = (tickGet() * 1000) / clkRate;    return (timeticks);    }/********************************************************************************* envoy_call_timer - execute the specified function when the timer expires** This routine executes the <what> function after <when> ticks have elapsed.* This function is used internally to respond when the interval between the* test and set of a "test and set" exceeds the timeout specified by <when>.** RETURNS: N/A**/ void envoy_call_timer(bits32_t when, void (*what)())    {    unsigned long when_in_ticks;/* Convert  "when" from milliseconds to ticks: */    when_in_ticks = (sysClkRateGet()*when);    if (when_in_ticks < 1000L)        when_in_ticks = 1L;    else        when_in_ticks /= 1000L;/* Set the timerBlock */    timerBlock.what = what;    timerBlock.when = when_in_ticks; /* time in ticks *//* Start the timeout */    wdSemStart (tae_sa_wdid, when_in_ticks, tae_sa_sid);    }/********************************************************************************* Completion Routines - Call backs sent to the handler function** ADMIN - taeSaAdmin* ADD   - taeSaAdd* ERROR - taeSaFree* SEND  - taeSaSend** RETURNS: N/A**/ void taeSaAdmin(ptr_t cookie, ptr_t pkt)    {    ENVOY_AX_PKT_T *ax_pkt = (ENVOY_AX_PKT_T *)pkt;    if (ax_pkt->type == ENVOY_AX_RESPONSE)        {        if (ax_pkt->error_stat)            {            tae_sa_log (TAE_SA_ERROR, "axSubAdmin: error received from master\n");            }        else            {            if (tae_sa_myfoo.op == ENVOY_AX_OPEN)                {                tae_sa_session_id = ax_pkt->session_id;                tae_sa_myfoo.open_done = 1;                }            }        tae_sa_myfoo.op = 0;        }    return;    }      void taeSaAdd(ptr_t cookie)    {       tae_sa_myfoo.ref_count++;    }         void taeSaFree(ptr_t cookie, int foobar)    {       tae_sa_myfoo.ref_count--;    }    int taeSaSend(ptr_t     cookie,              ptr_t     ax_pkt,              ptr_t     vblist,              ALENGTH_T need)    {    bits8_t *pkt;    EBUFFER_T ebuff;     EBufferInitialize(&ebuff);    if ((pkt = SNMP_memory_alloc(need)) == (bits8_t *) 0)        return 1;     EBufferSetup(BFL_IS_STATIC, &ebuff, pkt, need);    if (envoy_ax_pkt_encode(ax_pkt, vblist, &ebuff, need))        {        SNMP_memory_free(pkt);        return(1);        }     if (send(tae_sa_socket, pkt, need, 0) == -1)        tae_sa_log (TAE_SA_ERROR, "send error!\n");    SNMP_memory_free(pkt);    return(0);    }/******************************************************************************** snmpdMemoryAlloc - allocate memory for the SNMP agent** This routine allocates memory for the SNMP agent. The required size* of the block is passed in <size>.* This memory must be deallocated later with snmpdMemoryFree().** RETURNS: a pointer to the allocated buffer on success, otherwise NULL.** SEE ALSO: snmpdMemoryFree()*/void *   snmpdMemoryAlloc    (    size_t  size            /* size of memory to be allocated */    )    {    return ((char*) malloc (size));    }/******************************************************************************** snmpdMemoryFree - free memory allocated by the SNMP agent** This routine deallocates memory which was previously allocated by the* SNMP agent with snmpdMemoryAlloc().** RETURNS: N/A** SEE ALSO: snmpdMemoryAlloc()*/  void   snmpdMemoryFree    (    void *    pBuf    /* buffer to free */    )    {    free (pBuf);    } /************************************************************************ * timerTask:   a looping task that handles timer issues in a non-ISR   * *              context.                                                * * RETURNS: nothing                                                     * ************************************************************************/LOCAL void timerTask(void)    {    unsigned long when_in_ticks = 0;    void (*fn_ptr)(void) = 0;    while (1)        {    /* Wait for timeout: */        if (semTake (tae_sa_sid, WAIT_FOREVER) == ERROR)            tae_sa_log (TAE_SA_ERROR, "Error taking timer semaphore\n");    /* Get "what" */        ENVOY_SNMP_GET_WRITE_LOCK(SNMP_TimerLock);        when_in_ticks = timerBlock.when ;        fn_ptr = timerBlock.what;        ENVOY_SNMP_RELEASE_WRITE_LOCK(SNMP_TimerLock);    /* Call "what" */        (*fn_ptr)();        }    }/********************************************************************************* tae_sa_log - log messages from the AgentX subagent** This routine logs messages generated by the SNMP agent.  Messages are* sent to the standard console.  If <level> is less than or equal to* SNMP_TRACE_LEVEL (defined in the configuration header file), the* message is printed, otherwise* it is ignored. The value of <level> must be one of 1, 2, or 3.** RETURNS: N/A**/ LOCAL void tae_sa_log    (    int       level,  /* level of this message */    char *    pString  /* message string */    )    {    if (tae_sa_trace_level >= level)        {        printf ("TAE Subagent: %s",  pString);        }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -