/****************************************************************
 ****************************************************************
 **                                                            **
 **    (C)Copyright 2005-2006, American Megatrends Inc.        **
 **                                                            **
 **            All Rights Reserved.                            **
 **                                                            **
 **        6145-F, Northbelt Parkway, Norcross,                **
 **                                                            **
 **        Georgia - 30071, USA. Phone-(770)-246-8600.         **
 **                                                            **
 ****************************************************************
 ****************************************************************/
/*****************************************************************
 *
 * Firewall.c
 * Firewall Commands Handler
 *
 * Author: Basavaraj Astekar <basavaraja@ami.com>
 *       : Bakka Ravinder Reddy <bakkar@ami.com>
 *
 *****************************************************************/

#include "Firewall.h"
#include "MsgHndlrTask.h"
#include "Support.h"
#include "com_IPMIDefs.h"
#include "com_IPMI_Firewall.h"

/* Reserved bit macro definitions */
#define RESERVED_BITS_GETNETFNSUP                       0xF0 //(BIT7 | BIT6 | BIT5 |BIT4)

#define RESERVED_BITS_GETCMDSUP_CH                      0xF0 //(BIT7 | BIT6 | BIT5 |BIT4)
#define RESERVED_BITS_GETCMDSUP_LUN                     0xFC //(BIT7 | BIT6 | BIT5 | BIT4 | BIT3 | BIT2)
#define RESERVED_BITS_GETCMDSUP_NETFUN					0x80 //BIT7 \BIT6 (11 and 10 are reserved as per IPMI spec)

#define RESERVED_BITS_GETSUBFNSUP_CH                    0xF0 //(BIT7 | BIT6 | BIT5 | BIT4)
#define RESERVED_BITS_GETSUBFNSUP_NETFN                 0xC0 //(BIT7 | BIT6)
#define RESERVED_BITS_GETSUBFNSUP_LUN                   0xFC //(BIT7 | BIT6 | BIT5 | BIT4 | BIT3 | BIT2)

#define RESERVED_BITS_GETCFGCMDS_CH                     0xF0 //(BIT7 | BIT6 | BIT5 |BIT4)
#define RESERVED_BITS_GETCFGCMDS_LUN                    0xFC //(BIT7 | BIT6 | BIT5 | BIT4 | BIT3 | BIT2)
#define RESERVED_BITS_GETCFGCMDS_NETFUN					0x80 //BIT7 \BIT6 (11 and 10 are reserved as per IPMI spec)

#define RESERVED_BITS_GETCFGSUBFNS_CH                   0xF0 //(BIT7 | BIT6 | BIT5 |BIT4)
#define RESERVED_BITS_GETCFGSUBFNS_NETFN                0xC0 //(BIT7 | BIT6)
#define RESERVED_BITS_GETCFGSUBFNS_LUN                  0xFC //(BIT7 | BIT6 | BIT5 | BIT4 | BIT3 | BIT2)

#define RESERVED_BITS_SETCMDEN_CH                       0xF0 //(BIT7 | BIT6 | BIT5 |BIT4)
#define RESERVED_BITS_SETCMDEN_LUN                      0xFC //(BIT7 | BIT6 | BIT5 | BIT4 | BIT3 | BIT2)
#define RESERVED_BITS_SETCMDEN_NETFUN                	0x80 //BIT7 \BIT6 (11 and 10 are reserved as per IPMI spec)

#define RESERVED_BITS_GETCMDEN_CH                       0xF0 //(BIT7 | BIT6 | BIT5 |BIT4)
#define RESERVED_BITS_GETCMDEN_LUN                      0xFC //(BIT7 | BIT6 | BIT5 | BIT4 | BIT3 | BIT2)
#define RESERVED_BITS_GETCMDEN_NETFUN                	0x80 //BIT7 \BIT6 (11 and 10 are reserved as per IPMI spec)

#define RESERVED_BITS_SETSUBFNEN_CH                     0xF0 //(BIT7 | BIT6 | BIT5 | BIT4)
#define RESERVED_BITS_SETSUBFNEN_NETFN                  0xC0 //(BIT7 | BIT6)
#define RESERVED_BITS_SETSUBFNEN_LUN                    0xFC //(BIT7 | BIT6 | BIT5 | BIT4 | BIT3 | BIT2)

#define RESERVED_BITS_GETSUBFNEN_CH                     0xF0 //(BIT7 | BIT6 | BIT5 | BIT4)
#define RESERVED_BITS_GETSUBFNEN_NETFN                  0xC0 //(BIT7 | BIT6)
#define RESERVED_BITS_GETSUBFNEN_LUN                    0xFC //(BIT7 | BIT6 | BIT5 | BIT4 | BIT3 | BIT2)

#define RESERVED_BITS_GETOEMNETFNIANASUPPORT_CH         0xF0 //(BIT7 | BIT6 | BIT5 | BIT4)
#define RESERVED_BITS_GETOEMNETFNIANASUPPORT_NETFN      0xC0 //(BIT7 | BIT6)
#define RESERVED_BITS_GETOEMNETFNIANASUPPORT_LISTINDEX  0xC0 //(BIT7 | BIT6)
#if IPM_DEVICE == 1

//static int GetRequiredLength (uint8_t NetFn, uint8_t CmdReqSize);
//static int ValidateFFNetFnData (uint8_t NetFn, NetFnParams_T* pNetFnParams ,BMCInfo_t *pBMCInfo);
/*** Local Macro definitions ***/
#define LUN_NO_CMD_SUPPORT          0x00
#define LUN_NO_RESTRICTION_SUPPORT  0x01
#define LUN_RESTRICTION_SUPPORT     0x02

#define LUN_00                      LUN_RESTRICTION_SUPPORT
#define LUN_01                      LUN_NO_CMD_SUPPORT << 2
#define LUN_10                      LUN_NO_CMD_SUPPORT << 4
#define LUN_11                      LUN_NO_CMD_SUPPORT << 6

#define DMTF_DEFINING_BODY    0x01

//Group Extension codes
#define GROUPEXTNCODE_PICMG     0x00
#define GROUPEXTNCODE_DMTF      0x01
#define GROUPEXTNCODE_SSI       0x02
#define GROUPEXTNCODE_VSO       0x03
#define GROUPEXTNCODE_DCMI      0xDC
#define Max_GROUPEXTNCODE        5


/* Add IANA No's to the Array */
IANA_T m_IANAList[] = {			/* LS byte first */
   {{0xFF,0xFF,0xFF}}, /* Reserved Oem IANA */
#ifdef IANA_OEM_LIST
   IANA_OEM_LIST
#endif   
};
uint8_t GroupExtnCode[Max_GROUPEXTNCODE]={
    GROUPEXTNCODE_PICMG,
    GROUPEXTNCODE_DMTF,
    GROUPEXTNCODE_SSI,
    GROUPEXTNCODE_VSO,
    GROUPEXTNCODE_DCMI,
    };


#if GET_NETFN_SUP != UNIMPLEMENTED
/*---------------------------------------
 * GetNetFnSup
 *---------------------------------------*/
int
GetNetFnSup ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
{
    printf("GetNetFnSup not implement\r\n");
        *pRes = CC_INV_CMD;
        return sizeof(*pRes);
}
#endif  /* GET_NETFN_SUP != UNIMPLEMENTED */


#if GET_CMD_SUP != UNIMPLEMENTED
/*---------------------------------------
 * GetCmdSup
 *---------------------------------------*/
int
GetCmdSup ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
{
   printf("GetCmdSup not implement\r\n");
        *pRes = CC_INV_CMD;
        return sizeof(*pRes);
}
#endif  /* GET_CMD_SUP != UNIMPLEMENTED */


#if GET_SUBFN_SUP != UNIMPLEMENTED
/*---------------------------------------
 * GetSubFnSup
 *---------------------------------------*/
int
GetSubFnSup ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
{
     printf("GetSubFnSup not implement\r\n");
        *pRes = CC_INV_CMD;
        return sizeof(*pRes);
}
#endif  /* GET_SUBFN_SUP != UNIMPLEMENTED */


#if GET_CONFIG_CMDS != UNIMPLEMENTED
/*---------------------------------------
 * GetConfigCmds
 *---------------------------------------*/
int
GetConfigCmds ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
{
     printf("GetConfigCmds not implement\r\n");
        *pRes = CC_INV_CMD;
        return sizeof(*pRes);
}
#endif  /* GET_CONFIG_CMDS != UNIMPLEMENTED */


#if GET_CONFIG_SUB_FNS != UNIMPLEMENTED
/*---------------------------------------
 * GetConfigSubFns
 *---------------------------------------*/
int
GetConfigSubFns ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
{
	printf("GetConfigSubFns not implement\r\n");
        *pRes = CC_INV_CMD;
        return sizeof(*pRes);
}
#endif  /* GET_CONFIG_SUB_FNS != UNIMPLEMENTED */


#if SET_CMD_ENABLES != UNIMPLEMENTED
/*---------------------------------------
 * SetCmdEnables
 *---------------------------------------*/
int
SetCmdEnables ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
{
     printf("SetCmdEnables not implement\r\n");
        *pRes = CC_INV_CMD;
        return sizeof(*pRes);
}
#endif  /* SET_CMD_ENABLES != UNIMPLEMENTED */


#if GET_CMD_ENABLES != UNIMPLEMENTED
/*---------------------------------------
 * GetCmdEnables
 *---------------------------------------*/
int
GetCmdEnables ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
{
    printf("GetCmdEnables not implement\r\n");
        *pRes = CC_INV_CMD;
        return sizeof(*pRes);
}
#endif  /* GET_CMD_ENABLES != UNIMPLEMENTED */


#if SET_SUBFN_ENABLES != UNIMPLEMENTED
/*---------------------------------------
 * SetSubFnEnables
 *---------------------------------------*/
int
SetSubFnEnables ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
{
     printf("SetSubFnEnables not implement\r\n");
        *pRes = CC_INV_CMD;
        return sizeof(*pRes);
}
#endif  /* SET_SUBFN_ENABLES != UNIMPLEMENTED */


#if GET_SUBFN_ENABLES != UNIMPLEMENTED
/*---------------------------------------
 * GetSubFnEnables
 *---------------------------------------*/
int
GetSubFnEnables ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
{
     printf("GetSubFnEnables not implement\r\n");
        *pRes = CC_INV_CMD;
        return sizeof(*pRes);
}

#endif  /* GET_SUBFN_ENABLES != UNIMPLEMENTED */

#if GET_OEM_NETFN_IANA_SUPPORT != UNIMPLEMENTED
/*---------------------------------------
 * GetOEMNetFnIANASupport
 *---------------------------------------*/
int
GetOEMNetFnIANASupport ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes)
{
     printf("GetOEMNetFnIANASupport not implement\r\n");
        *pRes = CC_INV_CMD;
        return sizeof(*pRes);
}

#endif	//GET_OEM_NETFN_IANA_SUPPORT != UNIMPLEMENTED

//static int GetRequiredLength(uint8_t NetFn, uint8_t CmdReqSize)
//{
//    uint8_t    RequiredLength;

//    switch (NetFn)
//    {
//        case NETFN_OEM:
//            RequiredLength = CmdReqSize;
//            break;
//        case NETFN_AMI:
//            RequiredLength = CmdReqSize - sizeof(NetFnParams_T) + 1;
//            break;
//        case NETFN_PICMG:
//            RequiredLength = CmdReqSize - sizeof(NetFnParams_T) + 1;
//            break;
//        default:
//            RequiredLength = CmdReqSize - sizeof(NetFnParams_T);
//            break;
//    }

//    return RequiredLength;
//}

//static int ValidateFFNetFnData (uint8_t NetFn, NetFnParams_T* pNetFnParams , BMCInfo_t *pBMCInfo)
//{
//    uint8_t i;
//    
//    // If NetFn is 0x2C, check for Defining Body code
//    if (NETFN_PICMG == NetFn )
//    {
//        for (i = 0; i < sizeof (pBMCInfo->GroupExtnMsgHndlrTbl) / sizeof (pBMCInfo->GroupExtnMsgHndlrTbl [0]); i++)
//        {
//            if (pBMCInfo->GroupExtnMsgHndlrTbl [i].NetFn == NetFn) 
//                return (pBMCInfo->GroupExtnMsgHndlrTbl [i].GroupExtnCode != pNetFnParams->DefBodyCode);
//        }
//    }
//    else if (NETFN_OEM == NetFn) 	// If NetFn is 0x2E, check for OEM IANA
//    {
//        for (i=0; i <(sizeof(m_IANAList)/ sizeof(m_IANAList[0])); i++)
//        {
//            if (0 == _fmemcmp( pNetFnParams->IANA, m_IANAList[i].IANA, sizeof(IANA_T)))
//            {
//                break;
//            }
//        }

//        if (i >= (sizeof(m_IANAList)/ sizeof(m_IANAList[0])))
//        {
//            // Given IANA in Req is not matching any of the IANA in the IANA list
//            return  1;
//        }
//    }
//    return 0;
//}

#endif  /* IPM_DEVICE */
