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

📄 k_vxdemo.c

📁 vxworks demo 有问题写信给我
💻 C
📖 第 1 页 / 共 2 页
字号:
/* k_vxdemo.c - VxWorks Demo MIB interface to target System *//* Copyright 1984-1993 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01a,12oct93,jag  written*//*DESCRIPTIONThis module contains the necessary routines to interface the SNMP agent withthe WRS Demo MIB extension definition.  The MIB is defined in concise MIB format in the file vxdemomib.my.  This file is the input to the MIB compiler which generates the following:  The data structures that need to be addedto the SNMP agent to support the new MIB extension; The necessary header files; The functions headers (or stubs optional) that need be written to support theMIB extension.The software that needs to be written to support the MIB extension is dividedin two layers.  The first layer is called "v_" and the second layer is called"k_".  The corresponding layers in the vxWorks demo MIB are v_vxdemo.c and k_vxdemo.c.  The functionality of each layer is described in the correspondingmodule.The SNMP agent is responsible for the communication protocol, proper encapsulation of the MIB variables, validation of OIDs and the invokation ofthe "v_" routines.  The "v_" layer validates the value and operation of theMIB variable and calls the respective "k_" routine.  The "k_" routine does theactual operation on the variable.The groups in the vxWorks Demo MIB sysconfig, systasks, sysmemory and sysnfs.Each have a set of "v_" and "k_" routines that support the group.  On a pergroup and tables within a group the k_groupID_get and k_groupID_set routinesneed to be provided.The k_ logic provides a set of routines on a per group bases.  The k_groupID_getroutine reads all the MIB variables in the group into a structure generatedby the MIB compiler and returns a pointer to it.  The k_groupID_set routine ispassed the structure generated by the MIB compiler, with a valid vectorfield structure, and the request type (ADD_MODIFY or DELETE).  The MIBvariables in the group are updated accordingly.  The set routine only needsto be provided for variables that can be modified.  The structures generatedby the compiler which are used to transfer data between the v_ and k_ layerare machine dependent.  Data structures that are returned by the k_groupID_getroutines must be static, furthermore a special considerantion must be observedwhen ASCII strings correnspond to MIB variables.  ASCII strings must be returned in octect structures.  Octet structures contain pointers to characterarrays, the result is that Octet structures and character arrays must bedeclared static as well.  The linkage of this structures is done at initialization time.*//* includes */#include <vxWorks.h>#include <stdio.h>#include <string.h>#include <snmp.h>#include <snmpuser.h>#include <diag.h>#include <remLib.h>#include <taskLib.h>#include <symLib.h>#include <nfsLib.h>#include <semLib.h>#include <dllLib.h>#include <string.h>#include <a_out.h>#include <sysSymTbl.h>#include <symbol.h>#include <iosLib.h>#include <private/taskLibP.h>    /* Task Status Definitions */#include <snmpd.h>#include <nfsDrv.h>#include <memLib.h>#include <taskHookLib.h>#define STATIC  /* defines */#define  MAXTASKS	500   /* Assume Maximum # of tasks in the system */#define  MAXNFS	        200   /* Assume Maximum # of files systems mounted */#define  DISPLAY_STR_SZ 255/* globals *//* Static variables used for the system configuration group get routine. */static sysconfig_t   sysVariables;		/* MIB Generated Structure */static OctetString   sNameOctet;                /* Referenced by sysVariables */static unsigned char userName  [DISPLAY_STR_SZ]; /* Referenced by sNameOctet */static OctetString   sPasswOctet;		/* Referenced by sysVariables */static unsigned char userPassw [DISPLAY_STR_SZ]; /* Referenced by sPasswOctet *//* Static variables used for the task table group get routine. */static taskEntry_t    taskEntryVars;	       /* MIB Generated Structure */static OctetString    tNameOctet;	       /* Referenced by taskEntryVars */static char           tName  [DISPLAY_STR_SZ]; /* Referenced by tNameOctet */static OctetString    tMainOctet;	       /* Referenced by taskEntryVars */static char           tMain  [DISPLAY_STR_SZ]; /* Referenced by tMainOctet *//* Internal variables used by the task support routines */STATIC int           taskIdList [MAXTASKS];   /* List of task Ids */STATIC int           numTasks;		      /* Number of tasks in the list *//* Static variables used for the system memory group get routine. */static sysmemory_t    memVars;		/* MIB Generated Structure *//* Static variables used for the NFS group get routine. */static sysnfs_t    nfsVars;		/* MIB Generated Structure *//* Static variables used for the NFS table group get routine. */static nfsEntry_t     nfsEntryVars;	/* MIB Generated Structure */static OctetString    nHostNameOctet;	/* Referenced by nfsEntryVars */					/* Referenced by nHostNameOctet */static char           HostName        [DISPLAY_STR_SZ];static OctetString    nHostFileOctet;	/* Referenced by nfsEntryVars */					/* Referenced by nHostFileOctet */static char           HostFileSysName [DISPLAY_STR_SZ];static OctetString    nLocalFileOctet;	/* Referenced by nfsEntryVars */					/* Referenced by nLocalFileOctet */static char           LocalFileSysName [DISPLAY_STR_SZ];/* Internal variables used by the NFS table support routines */STATIC unsigned long  nfsHandles [MAXNFS];   /* List of NFS handles */STATIC int            numMounted;            /* Number of handles in the list *//********************************************************************************* vxDemoDeleteHook -  Task Delete Hook** This routine is invoked by vxWorks each time a task is deleted in the system.* At the time the task is deleted a trap is sent to the SNMP Manager.** RETURNS: N/A* * SEE ALSO: N/A*/void vxDemoDeleteHook	(	WIND_TCB *pTcb	)	{	OID 	    * pObject;	 /* Ptr to Object ID */	static OID    inst;	 /* Table entry index to return to agent */	static unsigned long    		     oidbuff;    /* OID buffer for inst variable */	static long   taskId;    /* Buffer for the Task ID */	taskId = (long) pTcb;	 /* Task ID is the address of the TCB */	inst.length = 1;	 /* Format Table Index information */	inst.oid_ptr = &oidbuff;	inst.oid_ptr [0] = taskId;				 /* Get the Object ID */    	pObject = MakeOIDFromDot ("taskId");				 /* Send SNMP Trap */	do_trap (ENTERPRISE_TRAP, 1, MakeVarBindWithValue (pObject, &inst, 		 INTEGER_TYPE, &taskId), MakeOIDFromDot("vxTaskDeleted"));	}/********************************************************************************* k_vxdemo_initialize -  Initialize all the module structures.** Link the MIB structures with their corresponding Octet structures and * character arrays.  The code used to generate the specified trap in the* vxdemo.my is enabled here.* This routine must be invoked by the SNMP agent before the* MIB variables can be accessed.** RETURNS: OK.  If resources were to be allocated it could return ERROR.* * SEE ALSO: N/A*/int k_vxdemo_initialize    (    )    {    /* Link MIB structures with corresponding Octet structures */    sysVariables.sysUserName                    = &sNameOctet;    sysVariables.sysUserName->octet_ptr         = userName;    sysVariables.sysUserPassw                   = &sPasswOctet;    sysVariables.sysUserPassw->octet_ptr        = userPassw;    taskEntryVars.taskName         	        = &tNameOctet;    taskEntryVars.taskName->octet_ptr           = tName;    taskEntryVars.taskMain         	        = &tMainOctet;    taskEntryVars.taskMain->octet_ptr           = tMain;    nfsEntryVars.nfsHostName 		        = &nHostNameOctet;    nfsEntryVars.nfsHostName->octet_ptr	        = HostName;    nfsEntryVars.nfsHostFileSysName  		= &nHostFileOctet;    nfsEntryVars.nfsHostFileSysName->octet_ptr 	= HostFileSysName;    nfsEntryVars.nfsLocalFileSysName            = &nLocalFileOctet;    nfsEntryVars.nfsLocalFileSysName->octet_ptr = LocalFileSysName;    /* Set up task Delete Hook */    if (taskDeleteHookAdd ((FUNCPTR) vxDemoDeleteHook) == ERROR)	printf ("vxDemoDeleteHook fail installation. SNMP Trap not enable\n");    return (OK);    }/********************************************************************************* k_vxdemo_terminate -  Free all resource allocated by this service.** This routine frees all the resources that have been allocated by the MIB * service.  In this routine the task hook intalled at initialization* is removed.** RETURNS: OK, unless it failes in deallocating a resource.* * SEE ALSO: N/A*/int k_vxdemo_terminate    (    )    {    taskDeleteHookDelete ((FUNCPTR) vxDemoDeleteHook);    return (OK);    }/********************************************************************************* k_sysconfig_get -  Read the sysconfig group variables.** Access the vxWorks variables and copies their value into the MIB generated* structure.** RETURNS: Pointer to a sysconfig structure.* * SEE ALSO: remCurIdGet.*/sysconfig_t * k_sysconfig_get     (    int           id,    ContextInfo * contextInfo,    int           reqVar    )    {    sysVariables.sysState = D_sysState_system_running;  /* System is Running */    remCurIdGet (userName, userPassw);   /* Get data from vxWorks */    sysVariables.sysUserName->length     = strlen (userName);    sysVariables.sysUserPassw->length    = strlen (userPassw);    SET_ALL_VALID(sysVariables.valid);   /* Set all variable to valid */    return (&sysVariables);    }/********************************************************************************* snmpReboot -  print reboot message and issue vxWorks reboot command.** This routine is spawned as a task by the SNMP agent.  Its job is to print* a message to the system console, and issue the vxWork's reboot command.** RETURNS: N/A** SEE ALSO: taskDelay and reboot.*/void snmpReboot ()    {    printf("\007\007SNMP System Reboot Command in progress\n");    taskDelay (200);	/* Wait 200 ticks before Reboot */    reboot (0);		/* Reboot System */    }/********************************************************************************* k_sysconfig_set -  Set a sysconfig group variable to the requested value.** This routine checks that the variable to be set has been marked valid by* v_ code.   The corresponding action or setting of the variable is taken.** RETURNS: Successful = NO_ERROR. Failed =  GEN_ERROR* * SEE ALSO: taskSpawn, remCurIdGet, and remCurIdSet.*/int k_sysconfig_set     (    sysconfig_t * sysVarToSet,    ContextInfo * contextInfo,    int           state    )    {    /*  Check the valid vector to determine which variable is to be modified. */    if (VALID(I_sysState, sysVarToSet->valid)) 	{	if (sysVarToSet->sysState == D_sysState_system_reboot)	    {	    if (taskSpawn ((char *)NULL, 150, VX_NO_STACK_FILL, 1024, 			   (FUNCPTR) snmpReboot, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)			   == ERROR)		return (GEN_ERROR);	    }	return (NO_ERROR);	}    else 	if (VALID(I_sysUserName, sysVarToSet->valid)) 	    {	    remCurIdGet (userName, userPassw);      /* Get data from vxWorks */	    (void) strncpy (userName, 			    (char *) sysVarToSet->sysUserName->octet_ptr,			    (int) sysVarToSet->sysUserName->length);	    userName [sysVarToSet->sysUserName->length] = '\0';	    remCurIdSet (userName, userPassw);      /* Set data from vxWorks */	    return (NO_ERROR);	    }	else 	    if (VALID(I_sysUserPassw, sysVarToSet->valid)) 		{		remCurIdGet (userName, userPassw);  /* Get data from vxWorks */		(void) strncpy (userPassw, 				(char *)sysVarToSet->sysUserPassw->octet_ptr,				(int) sysVarToSet->sysUserPassw->length);		userPassw [sysVarToSet->sysUserPassw->length] = '\0';		remCurIdSet (userName, userPassw);  /* Set data from vxWorks */		return (NO_ERROR);		}    return (GEN_ERROR);    }/********************************************************************************* intComp -  Compare two integer values.** This routine compares integer value 1 agains integer value 2.** RETURNS: 0 if v1 == v2, < 0 if v1 < v2 and > 0 if v1 > v2* * SEE ALSO: N/A*/int intComp     (    const void * pValue1,    const void * pValue2    )    {    return (*((int *)pValue1) - *((int *)pValue2));    }/********************************************************************************* k_taskEntry_get -  Returns the task information for the requested task.** This routine read the task table from the system and returns the information* corresponding to the requested task.   The request for the task can still* fail if the task is no longer executing in the system.** RETURNS: Pointer to a taskEtnry structure.* * SEE ALSO: taskIdListGet, taskInfoGet, taskIdVerify and symFindByValueAndType.*/taskEntry_t * k_taskEntry_get     (    int            reqId,         /* SNMP PDU ID used for catching */    ContextInfo  * contextInfo,    int	           reqVar,    int            searchType,    /* Request for EXACT or NEXT */    long           taskId    )    {    int             ix;                 /* General Index */    SYM_TYPE        stype;		/* Symbol Type */    TASK_DESC       td;                 /* Task Descriptor */    /*      * The catching startegy is described in several steps here. First if the     * search type is EXACT the catch can be checked righ away since the task     * ID has been specified.  In the case of a NEXT the ID is not know in     * advace and some work need to be done before the catch can be checked.     */    if (searchType == NEXT)			/* get the next request */	{	/* get tasks in the system and sort them by taskId */	numTasks = taskIdListGet (taskIdList, MAXTASKS);	qsort ((void *) taskIdList, numTasks, sizeof (long), intComp);	/* find the next task greater than the one passed in */	for (ix = 0 ; ix < numTasks ; ix++)	    {	     if ((taskIdList [ix] > taskId) && 		 (taskInfoGet (taskIdList [ix], &td) == OK))		break;	    }	if (ix >= numTasks)	    return ((taskEntry_t *)NULL);   	/* no more tasks */	taskId = taskIdList [ix];	}     else	{	if (taskInfoGet (taskId, &td) == ERROR)	    return ((taskEntry_t *)NULL);       /* Task ID no longer valid */	}    /* Fill the Task Entry information */    taskEntryVars.taskId           	= taskId;    strcpy (tName, td.td_name);    taskEntryVars.taskName->length     = strlen (tName);    symFindByValueAndType (sysSymTbl, (int)td.td_entry, tMain, 

⌨️ 快捷键说明

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