www.pudn.com > Firewall_PNE_3_3.zip > fwNvIfLib.c, change:2009-03-16,size:4474b


/* fwNvIfLib.c - firewall non volatile storage interface library */

/* Copyright 2004-2005 Wind River Systems, Inc. */
#include "copyright_wrs.h"

/*
modification history
--------------------
01d,09sep05,svk  Correct typo in function header, reformat parameter comments
01c,13jul04,myz  move common header files to fw.h
01b,30jan04,myz  public structure name changes
01a,16dec03,myz  written.
*/

/*
DESCRIPTION

This library provides the Firewall common Non-Volatile(NV) storage interface.
The user must call the fwNvFuncsInstall() to populate this interface with 
a set of hardware specific routines. 

*/

#include "fw.h"

/* LOCAL definitions */

typedef struct {
    FW_NV_GET_FUNC_PTR    pNvGetFunc;
    FW_NV_SET_FUNC_PTR    pNvSetFunc;
    FW_NV_CLOSE_FUNC_PTR  pNvCloseFunc;
    BOOL              installed;
    } FW_NV_IF_FUNCS;

/* LOCAL data */

LOCAL FW_NV_IF_FUNCS nvIfFuncs = {NULL,NULL,NULL,FALSE};

/******************************************************************************
*
* fwNvInstalled - check whether hardware specific NV storage routines installed
*
* This routine check whether hardware specific NV storage routines are installed
* RETURNS: TRUE installed or FALSE not installed
*/

BOOL fwNvInstalled (void)
    {
    return (nvIfFuncs.installed);
    }

/******************************************************************************
*
* fwNvFuncsInstall - install hardware specific NV storage interface 
*
* This routine installs the hardware specific NV storage get, set and close
* functions. These hardware specific routines must perform the functions 
* specified by the fwNvParamGet(), fwNvParamSet() and fwNvParamClose().
* The close function is optional.
* 
* RETURNS: N/A
*
*/

void fwNvFuncsInstall
    (
    FW_NV_GET_FUNC_PTR    pNvGetFunc,  /* hardware specific get function */
    FW_NV_SET_FUNC_PTR    pNvSetFunc,  /* hardware specific set function */
    FW_NV_CLOSE_FUNC_PTR  pNvCloseFunc /* hardware specific close function */
    )
    {
    nvIfFuncs.pNvGetFunc = pNvGetFunc; 
    nvIfFuncs.pNvSetFunc = pNvSetFunc; 
    nvIfFuncs.pNvCloseFunc = pNvCloseFunc; 

    nvIfFuncs.installed = TRUE;
    }

/******************************************************************************
*
* fwNvParamGet - retrieve the parameter block from NV storage
*
* This routine reads the entire parameter block identified by pParamsId into 
* the user supplied buffer pointed to by pParamsBuf.
*
* RETURNS: The actual length of retrieved data, or 0 if fails
*/

int fwNvParamGet
    (
    char * pParamsId,    /* parameter block ID, 0 terminated less than or */
                         /* equal 8 byte(including 0 character) string */
    char * pParamsBuf,   /* buffer to store the parameters */
    int    len,          /* length of the buffer */
    int    offset        /* offset from the start of the storage */
    )
    {
    int rLen = 0;

    if (nvIfFuncs.pNvGetFunc)  
       rLen = (*nvIfFuncs.pNvGetFunc)(pParamsId,pParamsBuf,len,offset); 

    return rLen;
    }

/******************************************************************************
*
* fwNvParamSet - set the parameter block to NV storage
*
* This routine writes the entire parameter block pointed to by pParams to the 
* NV storage identified by parameter block ID pParamsId.   
*
* RETURNS: The actual written length, or 0 if fails
*
*/

int fwNvParamSet
    (
    char * pParamsId, /* parameter block ID, 0 terminated less than or */
                      /* equal 8 byte(including 0 character) string */
    char * pParams,   /* parameter block for storing */
    int    len,       /* length of the parameter block */
    int    offset     /* offset from the start of the storage */
    )
    {
    int wLen = 0;

    if (nvIfFuncs.pNvSetFunc)  
       wLen = (*nvIfFuncs.pNvSetFunc)(pParamsId,pParams,len,offset); 

    return wLen;
    }

/******************************************************************************
*
* fwNvParamClose - close a NV storage identified by the pParamsId 
*
* This routine closes a specific NV storage area identified by the pParamsId
* parameter.  
*
* RETURNS: OK or ERROR 
*/

int fwNvParamClose 
    (
    char * pParamsId    /* parameter block ID, 0 terminated less than or */
                        /* equal 8 byte(including 0 character) string */
    )
    {
    if (nvIfFuncs.pNvCloseFunc)
        {
        (*nvIfFuncs.pNvCloseFunc)(pParamsId);
        return OK;
        }
    else
        return ERROR;
    }