#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/socket.h>
#include <fcntl.h>
#include <net/if.h>
#include <netinet/in.h>
#include <sys/ioctl.h>

#include "main.h"
#include "Api.h"
#include "SDRRecord.h"
#include "SELRecord.h"
#include "SEL.h"
#include "MsgHndlr.h"


int InitSdrConfig(void)
{
	printf("Init SDR Config...\r\n");
	g_BMCInfo.SDRConfig.SDRError	=	0;
	g_BMCInfo.SDRConfig.UpdatingSDR	=	FALSE;
	g_BMCInfo.SDRConfig.UpdatingChannel	=	0;
	g_BMCInfo.SDRConfig.TrackPOffset	=	0;
	g_BMCInfo.SDRConfig.TrackRecID		=	0;
	g_BMCInfo.SDRConfig.ReservationID	=	0;
	g_BMCInfo.SDRConfig.IPMB_Seqnum		=	0;
	g_BMCInfo.SDRConfig.PartAddbytes	=	0;
	g_BMCInfo.SDRConfig.LatestRecordID	=	0;
	g_BMCInfo.SDRConfig.NumMarkedRecords	=	0;
	g_BMCInfo.SDRConfig.SDRRAM			=	(SDRRepository_T*)g_BMCInfo.pSDR;
	
	g_BMCInfo.SDRConfig.RepositoryInfo.Version	=	0x51;
	g_BMCInfo.SDRConfig.RepositoryInfo.RecCt	=	((SDRRepository_T*)g_BMCInfo.SDRConfig.SDRRAM)->NumRecords;
	g_BMCInfo.SDRConfig.RepositoryInfo.FreeSpace	=	0xffff;
	g_BMCInfo.SDRConfig.RepositoryInfo.AddTimeStamp	=	0;
	g_BMCInfo.SDRConfig.RepositoryInfo.EraseTimeStamp	=	0;
	g_BMCInfo.SDRConfig.RepositoryInfo.OpSupport	=	0x23;
	
	//TODO:
	g_BMCInfo.SDRConfig.RepositoryAllocInfo.NumAllocUnits	=	MAX_SENSOR_NUMBERS+1;
	g_BMCInfo.SDRConfig.RepositoryAllocInfo.AllocUnitSize	=	SDR_ALLOC_UNIT_SIZE;
	g_BMCInfo.SDRConfig.RepositoryAllocInfo.NumFreeAllocUnits	=	MAX_SENSOR_NUMBERS - SENSOR_NUMBERS;
	g_BMCInfo.SDRConfig.RepositoryAllocInfo.LargestFreeBlock	=	SDR_MAX_RECORD_SIZE;
	g_BMCInfo.SDRConfig.RepositoryAllocInfo.MaxRecSize	=	SDR_MAX_RECORD_SIZE;	//Maximum record size in allocation units

	return 0;
}

int InitSelConfig(void)
{
	printf("InitSelConfig...\n");
	g_BMCInfo.SELConfig.SelReservationID = 0;;
    g_BMCInfo.SELConfig.LastEvtTS		=	0;
    g_BMCInfo.SELConfig.PartialAddRecordID	=	0;
    g_BMCInfo.SELConfig.PartialAddRecOffset	=	0;
    g_BMCInfo.SELConfig.PartialAdd		=	0;
    g_BMCInfo.SELConfig.SenMonSELFlag	=	0;
    g_BMCInfo.SELConfig.MaxSELRecord	=	MAX_SEL_RECORD;
//    g_BMCInfo.SELConfig.RsrvIDCancelled	=	FALSE;
    g_BMCInfo.SELConfig.SELOverFlow		=	FALSE;
    g_BMCInfo.SELConfig.selalmostfull	=	0;

	
//	SELEventRecord_T  SelPartialAddRecord;
//    g_BMCInfo.SELConfig.SELEventMsg [16];
	return 0;
    
}

int PlatformInit(void)
{
	uint8_t PrimaryIPMBBusNum, SecondaryIPMBBusNum;
	printf("Init Platform...\r\n");

	// //hardware init
	// GPIO_InitTypeDef GPIO_InitStruct;
	// GPIO_InitStruct.Pin = GA0_PIN | GA1_PIN | GA2_PIN | GA3_PIN | GA4_PIN | RACKID2_PIN;
	// GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
	// GPIO_InitStruct.Pull = GPIO_NOPULL;
	// GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
	// stm32_gpio_init(GPIOH, &GPIO_InitStruct);

	// GPIO_InitStruct.Pin = GAP_PIN | RACKID1_PIN | RACKID3_PIN | RACKID4_PIN | RACKID5_PIN;
	// stm32_gpio_init(GPIOI, &GPIO_InitStruct);




	g_BMCInfo.SelfTestByte 	=	0;
	g_BMCInfo.SlotID		=	PDK_GetSlotID();
	g_BMCInfo.ChassisID		=	PDK_GetChassisID();

	g_BMCInfo.ChassisIdentify		=	FALSE;
	g_BMCInfo.PowerGoodFlag =  	1;
	
	//init DevGUID
	g_BMCInfo.DeviceGUID[0]	=	0x01;
	g_BMCInfo.DeviceGUID[1]	=	0x01;
	g_BMCInfo.DeviceGUID[2]	=	0x01;
	g_BMCInfo.DeviceGUID[3]	=	0x01;
	g_BMCInfo.DeviceGUID[4]	=	0x01;
	g_BMCInfo.DeviceGUID[5]	=	0x01;
	g_BMCInfo.DeviceGUID[6]	=	0x01;
	g_BMCInfo.DeviceGUID[7]	=	0x01;
	g_BMCInfo.DeviceGUID[8]	=	0x01;
	g_BMCInfo.DeviceGUID[9]	=	0x01;
	g_BMCInfo.DeviceGUID[10]	=	0x01;
	g_BMCInfo.DeviceGUID[11]	=	0x01;
	g_BMCInfo.DeviceGUID[12]	=	0x01;
	g_BMCInfo.DeviceGUID[13]	=	0x01;
	g_BMCInfo.DeviceGUID[14]	=	0x01;
	g_BMCInfo.DeviceGUID[15]	=	0x01;
	
	g_BMCInfo.FwMajorVer		=	FW_VERSION_MAJOR;
	g_BMCInfo.FwMinorVer		=	FW_VERSION_MINOR;
	g_BMCInfo.SendMsgSeqNum				=	0;
	
	// g_BMCInfo.OemFlags.BladeWorkMode			=	BLADE_IPMC;
	// g_BMCInfo.OemFlags.chassisManageFnEnable	=	0;
	// g_BMCInfo.OemFlags.thisBladeIndex			=	0;
	// g_BMCInfo.OemFlags.bladeStatus				=	1;	//0: not present, 1: normal, 2: error, others: reserved.
	
	g_BMCInfo.HealthLevel		=	SENSOR_STATUS_NORMAL;
	g_BMCInfo.SensorSharedMem.SensorTick=	0;	
	g_BMCInfo.SenConfig.PowerOnTick		=	0;
	g_BMCInfo.SenConfig.SysResetTick	=	0;
	g_BMCInfo.CurTimerTick				=	0;
	g_BMCInfo.CurTimerSecond			=	0;
	g_BMCInfo.BootValidMinutes			=	0;
	
		
	return 0;
}

int InitTimerTaskTbl(void)
{
	printf("InitTimerTaskTbl...\n");
	g_BMCInfo.TimerTaskTblSize = 2;
    memcpy(g_BMCInfo.TimerTaskTbl, m_TimerTaskTbl, sizeof(TimerTaskTbl_T)*g_BMCInfo.TimerTaskTblSize);
}

int Init_SessionTbl(void)
{
	printf("Init_SessionTbl...\n");
	g_BMCInfo.SessionHandle 					=	0;
	g_BMCInfo.UDSSessionHandle 					=	0;

	g_BMCInfo.IpmiConfig.MaxSession				= 	10;
	g_BMCInfo.IpmiConfig.SessionTimeOut			= 	10;	//10s
	g_BMCInfo.IpmiConfig.SendMsgTimeout			=	10;	//10s
	
	/*Allocating Memory to hold session Table informations */
    g_BMCInfo.SessionTblInfo.SessionTbl = (SessionInfo_T *) malloc(sizeof(SessionInfo_T)*( g_BMCInfo.IpmiConfig.MaxSession + 1));
    if(g_BMCInfo.SessionTblInfo.SessionTbl == NULL)
    {
        printf("Error in allocating memory for SessionTbl \n");
        return 1;
    }
    g_BMCInfo.SessionTblInfo.Count = 0;
    /*Initialize the Session Table memory */
    memset(g_BMCInfo.SessionTblInfo.SessionTbl,0,sizeof(SessionInfo_T)*(g_BMCInfo.IpmiConfig.MaxSession + 1));

    /*Allocating Memory to hold UDS session Table informations */
    g_BMCInfo.UDSSessionTblInfo.UDSSessionTbl = (UDSSessionTbl_T *) malloc(sizeof(UDSSessionTbl_T)*(g_BMCInfo.IpmiConfig.MaxSession + 1));
    if(g_BMCInfo.UDSSessionTblInfo.UDSSessionTbl == NULL)
    {
        printf("Error in allocating memory for SessionTbl \n");
        return 1;
    }
    g_BMCInfo.UDSSessionTblInfo.SessionCount = 0;
    /*Initialize the UDS Session Table memory */
    memset(g_BMCInfo.UDSSessionTblInfo.UDSSessionTbl,0,sizeof(UDSSessionTbl_T)*(g_BMCInfo.IpmiConfig.MaxSession + 1));
}

const char FirstPowerOnStr[] = "First power on the bmc";
int Init_IPMI_FRU_SDR_SEL(void)
{
	int i;
	uint32_t	sdrSize =
		sizeof(SDRRepository_T) + sizeof(HdrMgmtCtrlrDevLocator_T) + sizeof(HdrFullSensorRec_T)*SENSOR_NUMBERS;
	uint32_t	selSize = sizeof(SELRepository_T) + sizeof(SELRec_T)*MAX_SEL_RECORD ;	
	uint8_t*	pSDR = NULL;
	uint8_t*	pSEL = NULL;
	
	
	g_BMCInfo.pSDR = malloc(sdrSize);
	if((g_BMCInfo.pSDR == NULL) && (sdrSize != 0))
	{
		printf("g_BMCInfo.pSDR Malloc failed!\r\n");
	}
	g_BMCInfo.pSEL = malloc(selSize);
	if((g_BMCInfo.pSEL == NULL) && (selSize != 0))
	{
		printf("g_BMCInfo.pSEL Malloc failed!\r\n");
	}
	
//	FLASH_GetIPMI(&g_BMCInfo.IpmiConfig);
//	if(strncmp(g_BMCInfo.IpmiConfig.FirstPowerOnStr, FirstPowerOnStr, sizeof(FirstPowerOnStr)) != 0)
	if(1)
	{
		//first power on
		printf("BMC first power on!\r\n");
		/************************** Init IPMI ******************************/
		memcpy(g_BMCInfo.IpmiConfig.FirstPowerOnStr, FirstPowerOnStr, sizeof(FirstPowerOnStr));
		
		g_BMCInfo.IpmiConfig.SerialIfcSupport		=	SERIAL_IFC_SUPPORT;
		g_BMCInfo.IpmiConfig.SerialTerminalSupport	=	SERIAL_TERMINAL_SUPPORT;
		g_BMCInfo.IpmiConfig.LANIfcSupport			=	LAN_IFC_SUPPORT;
		g_BMCInfo.IpmiConfig.SYSIfcSupport			=	SYS_IFC_SUPPORT;
		g_BMCInfo.IpmiConfig.GrpExtnSupport 		= 	GROUP_EXTERN_SUPPORT;
		g_BMCInfo.IpmiConfig.UDSIfcSupport			=	UDS_IFC_SUPPORT;
		g_BMCInfo.IpmiConfig.ChassisTimerInterval	=	CHASSIS_TIMER_INTERVAL;	
		g_BMCInfo.IpmiConfig.PowerCycleInterval		=	PWR_CYCLE_INTERVAL;
		g_BMCInfo.IpmiConfig.FanControlInterval		=	FAN_CONTROL_INTERVAL;		
		g_BMCInfo.IpmiConfig.RearmSetSensorThreshold	=	REARM_SET_SENSOR_THRESHOLD;
		g_BMCInfo.IpmiConfig.SELTimeUTCOffset		=	8*60;
		
		//IPMB
		g_BMCInfo.IpmiConfig.PrimaryIPMBSupport		=	PRIMARY_IPMB_SUPPORT;
		g_BMCInfo.IpmiConfig.SecondaryIPMBSupport	=	SECONDARY_IPMB_SUPPORT;
		g_BMCInfo.IpmiConfig.PrimaryIPMBBus 		= 	PRIMARY_IPMB_BUS;
		g_BMCInfo.IpmiConfig.SecondaryIPMBBus 		= 	SECONDARY_IPMB_BUS;
		g_BMCInfo.IpmiConfig.PrimaryIPMBAddr 		= 	PRIMARY_IPMB_ADDR;
		g_BMCInfo.IpmiConfig.SecondaryIPMBAddr 		= 	SECONDARY_IPMB_ADDR;
		
				
		//Init FRU
		memcpy(&g_BMCInfo.FRU, &Default_FRUData, sizeof(OemFRUData_T));
		
		/************************ Init SDR *************************************/
		pSDR = g_BMCInfo.pSDR;
		//init SDR repository header
		((SDRRepository_T*)pSDR)->Signature[0]	=	0x00;
		((SDRRepository_T*)pSDR)->Signature[1]	=	0x11;
		((SDRRepository_T*)pSDR)->Signature[2]	=	0x22;
		((SDRRepository_T*)pSDR)->Signature[3]	=	0x33;
		
		((SDRRepository_T*)pSDR)->NumRecords		=	SENSOR_NUMBERS + 1;
		((SDRRepository_T*)pSDR)->Size			=	sdrSize;
		((SDRRepository_T*)pSDR)->AddTimeStamp	=	0;
		((SDRRepository_T*)pSDR)->EraseTimeStamp	=	0;
		//init MgmtCtrlrDevLocator SDR
		pSDR	+= sizeof(SDRRepository_T);
		((HdrMgmtCtrlrDevLocator_T*)pSDR)->Valid	=	1;
		((HdrMgmtCtrlrDevLocator_T*)pSDR)->Len	=	sizeof(HdrMgmtCtrlrDevLocator_T); 
		memcpy(&(((HdrMgmtCtrlrDevLocator_T*)pSDR)->MgmtCtrlrDevLocator), &bmc_sdr, sizeof(MgmtCtrlrDevLocator_T));
		//init FullSensorRec SDR
		pSDR	+= sizeof(HdrMgmtCtrlrDevLocator_T);
		for(i=0;i<SENSOR_NUMBERS;i++)
		{
			((HdrFullSensorRec_T*)pSDR)->Valid	=	1;
			((HdrFullSensorRec_T*)pSDR)->Len	=	sizeof(HdrFullSensorRec_T); 
			memcpy(&(((HdrFullSensorRec_T*)pSDR)->FullSensorRec), &full_sdr_tbl[i], sizeof(FullSensorRec_T));
			pSDR	+= sizeof(HdrFullSensorRec_T);
		}
		
		/******************************* Init SEL *************************************/
		pSEL = g_BMCInfo.pSEL;
		((SELRepository_T*)pSEL)->Signature[0] 	= 0x00;
		((SELRepository_T*)pSEL)->Signature[1] 	= 0x11;
		((SELRepository_T*)pSEL)->Signature[2] 	= 0x22;
		((SELRepository_T*)pSEL)->Signature[3] 	= 0x33;
		((SELRepository_T*)pSEL)->NumRecords	= 0;
		((SELRepository_T*)pSEL)->Padding		= 0;
		((SELRepository_T*)pSEL)->AddTimeStamp	= 0;
		((SELRepository_T*)pSEL)->EraseTimeStamp = 0;
		((SELRepository_T*)pSEL)->FirstRecID	= 0;
		((SELRepository_T*)pSEL)->LastRecID		= 0;
		((SELRepository_T*)pSEL)->SELIndex		= 0;
		
		((SELRepository_T*)pSEL)->SELRecord		= (SELRec_T*)(pSEL + sizeof(SELRepository_T));
		
		UpdateFlash();
	}
	else
	{
		// //Init FRU
		// FLASH_GetFRU(&g_BMCInfo.FRU);
		
		// //Init SDR
		// FLASH_GetSDR(g_BMCInfo.pSDR, sdrSize);
		
		// //Init SEL
		// FLASH_GetSEL(g_BMCInfo.pSEL, selSize);
	}
	
	return 0;
}

int Init_UserInfoTbl(void)
{
	int i;
	if(1)	//first power on
	{
		memset(g_BMCInfo.UserInfoTbl, 0x0, sizeof(UserInfo_T)*MAX_USER_NUM);
		g_BMCInfo.UserInfoTbl[2].UserId = 3;
		strcpy(g_BMCInfo.UserInfoTbl[2].UserName, "admin");
		strcpy(g_BMCInfo.UserInfoTbl[2].UserPassword, "admin");
		g_BMCInfo.UserInfoTbl[2].UserStatus = TRUE;

		g_BMCInfo.CurrentNoUser = 1;
		g_BMCInfo.pUserInfo = NULL;
		FlushUserInfoTbl();
	}
	else
	{
		UpdateUserInfoTble();
		g_BMCInfo.CurrentNoUser = 0;
		for(i=0;i<MAX_USER_NUM;i++)
		{
			if((g_BMCInfo.UserInfoTbl[i].UserId != 0) && (g_BMCInfo.UserInfoTbl[i].UserStatus == TRUE))
				g_BMCInfo.CurrentNoUser++;
		}
		g_BMCInfo.pUserInfo = NULL;
	}
}



int UpdateFlash(void)
{
	//TODO:
	return 0;
}

int SetSysTime(uint32_t *timeSecond)
{
	g_BMCInfo.SELTimeSecond = *timeSecond;
	return 0;
}

int GetSysTime(void)
{
	return g_BMCInfo.SELTimeSecond;
}

int PostEventMessage (uint8_t *EventMsg,uint8_t size)
{
	uint8_t             SelReq [sizeof(SELEventRecord_T)];
	uint8_t             SelRes [sizeof(AddSELRes_T)];
	SELEventRecord_T*   SelRecord = ( SELEventRecord_T*) SelReq;

	SelRecord->hdr.Type = 0x02;
	SelRecord->hdr.TimeStamp = GetSysTime ();
	memcpy (SelRecord->GenID, EventMsg, size);
	
	LockedAddSELEntry(SelReq, sizeof (SELEventRecord_T), SelRes);

	return 0;
}

uint8_t PDK_GetSlotID(void)
{
	uint8_t SlotID = 0;
	uint8_t check = 0;

	if(stm32_gpio_read(GA0_PORT, GA0_PIN) == GPIO_PIN_RESET)
		SlotID |= 0x01;
	if(stm32_gpio_read(GA1_PORT, GA1_PIN) == GPIO_PIN_RESET)
		SlotID |= 0x02;
	if(stm32_gpio_read(GA2_PORT, GA2_PIN) == GPIO_PIN_RESET)
		SlotID |= 0x04;
	if(stm32_gpio_read(GA3_PORT, GA3_PIN) == GPIO_PIN_RESET)
		SlotID |= 0x08;
	if(stm32_gpio_read(GA4_PORT, GA4_PIN) == GPIO_PIN_RESET)
		SlotID |= 0x10;

	if(stm32_gpio_read(GAP_PORT, GAP_PIN) == GPIO_PIN_RESET)
		SlotID |= 0x20;

	int i;
	for(i=0;i<6;i++)
		check ^= (SlotID>>i)&0x01;

	if(check == 0)
		printf("Slot ID check error! GAP = %#x, GA[4:0] = %#x.\n", (SlotID>>5), (SlotID&0x1f));

	return SlotID&0x1f;
}

uint8_t PDK_GetChassisID(void)
{
	uint8_t ChassisID = 0;
	if(stm32_gpio_read(RACKID0_PORT, RACKID0_PIN) == GPIO_PIN_SET)
		ChassisID |= 0x01;
	if(stm32_gpio_read(RACKID1_PORT, RACKID1_PIN) == GPIO_PIN_SET)
		ChassisID |= 0x02;
	if(stm32_gpio_read(RACKID2_PORT, RACKID2_PIN) == GPIO_PIN_SET)
		ChassisID |= 0x04;
	if(stm32_gpio_read(RACKID3_PORT, RACKID3_PIN) == GPIO_PIN_SET)
		ChassisID |= 0x08;
	if(stm32_gpio_read(RACKID4_PORT, RACKID4_PIN) == GPIO_PIN_SET)
		ChassisID |= 0x10;
	if(stm32_gpio_read(RACKID5_PORT, RACKID5_PIN) == GPIO_PIN_SET)
		ChassisID |= 0x20;

	return ChassisID;
}

int PDK_PowerOffChassis(void)
{
	printf("Api power off chassis\n");
	g_BMCInfo.PowerGoodFlag = 0;
}

int PDK_PowerOnChassis(void)
{
	printf("power on chassis\n");
	g_BMCInfo.PowerGoodFlag = 1;
}

int PDK_SoftOffChassis(void)
{
	printf("soft off chassis\n");
	g_BMCInfo.PowerGoodFlag = 0;
}

int PDK_PowerCycleChassis(void)
{
	printf("power cycle chassis\n");
}

int PDK_ResetChassis(void)
{
	printf("power reset chassis\n");
}

int PDK_DiagInterruptChassis(void)
{
	printf("power diag chassis\n");
}

int PDK_FanControl(void)
{
	;
}

//设置IP地址
/*
 * 函数名称 ： int setip(char *ip)
 * 函数功能 ： 设置系统IP地址
 * 参    数 ： 
 *char *ip ：设置的IP地址，以点分十进制的字符串方式表示，如“192.168.0.5” 
 * 返 回 值 ： 0 : 成功 ；  -1 :  失败 
 */
int setip(char *ip)
{
    struct ifreq temp;
    struct sockaddr_in *addr;
    int fd = 0;
    int ret = -1;
    strcpy(temp.ifr_name, "eth0");
    if((fd=socket(AF_INET, SOCK_STREAM, 0))<0)
    {
      return -1;
    }
    addr = (struct sockaddr_in *)&(temp.ifr_addr);
    addr->sin_family = AF_INET;
    addr->sin_addr.s_addr = inet_addr(ip);
    ret = ioctl(fd, SIOCSIFADDR, &temp);
    close(fd);
    if(ret < 0)
       return -1;
    return 0;
}

//获取IP地址
/*
 * 函数名称 ： char * getip(char *ip_buf)
 * 函数功能 ： 获取系統IP地址
 * 参    数 ： 
 *char *ip_buf ：用来存放IP地址的内存空间
 * 返 回 值 ： ip_buf ： 存放IP地址的内存地址
 */
char* getip(char *ip_buf)
{
    struct ifreq temp;
    struct sockaddr_in *myaddr;
    int fd = 0;
    int ret = -1;
    strcpy(temp.ifr_name, "eth0");
    if((fd=socket(AF_INET, SOCK_STREAM, 0))<0)
    {
        return NULL;
    }
    ret = ioctl(fd, SIOCGIFADDR, &temp);
    close(fd);
    if(ret < 0)
        return NULL;
    myaddr = (struct sockaddr_in *)&(temp.ifr_addr);
    strcpy(ip_buf, (char*)inet_ntoa(myaddr->sin_addr));
    return ip_buf;
}

char* getmac(char *mac_buf)
{
    struct ifreq temp;
    struct sockaddr_in *myaddr;
    int fd = 0;
    int ret = -1;
    strcpy(temp.ifr_name, "eth0");
    if((fd=socket(AF_INET, SOCK_STREAM, 0))<0)
    {
        return NULL;
    }
    if(ioctl(fd,SIOCGIFHWADDR,&temp)<0)
    {
        printf("Get mac address ioctl fail!\n");
    }
    else
    {
        sprintf(mac_buf, "%02x:%02x:%02x:%02x:%02x:%02x\n",
                (unsigned char)temp.ifr_hwaddr.sa_data[0],
                (unsigned char)temp.ifr_hwaddr.sa_data[1],
                (unsigned char)temp.ifr_hwaddr.sa_data[2],
                (unsigned char)temp.ifr_hwaddr.sa_data[3],
                (unsigned char)temp.ifr_hwaddr.sa_data[4],
                (unsigned char)temp.ifr_hwaddr.sa_data[5]);
    }
    close(fd);
    return mac_buf;
}

int FlushUserInfoTbl(void)
{
//	sf_sector_erase(5, USERTBL_FLASH_ADDR);
//	sf_write(5, USERTBL_FLASH_ADDR, (uint8_t*)g_BMCInfo.UserInfoTbl, sizeof(UserInfo_T)*MAX_USER_NUM);
	return 0;
}

int UpdateUserInfoTble(void)
{
//	sf_read(5, USERTBL_FLASH_ADDR, (uint8_t*)g_BMCInfo.UserInfoTbl, sizeof(UserInfo_T)*MAX_USER_NUM);
	return 0;
}