Api.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129
  1. #include <stdint.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #include <unistd.h>
  6. #include <sys/socket.h>
  7. #include <fcntl.h>
  8. #include <net/if.h>
  9. #include <netinet/in.h>
  10. #include <sys/ioctl.h>
  11. #include "main.h"
  12. #include "Api.h"
  13. #include "SDRRecord.h"
  14. #include "SELRecord.h"
  15. #include "SEL.h"
  16. #include "MsgHndlr.h"
  17. pthread_mutex_t Flash_Mutex;
  18. int PlatformInit(void)
  19. {
  20. uint8_t PrimaryIPMBBusNum, SecondaryIPMBBusNum;
  21. printf("Init Platform...\r\n");
  22. //hardware init
  23. //槽位号识别
  24. GPIO_InitTypeDef GPIO_InitStruct;
  25. GPIO_InitStruct.Pin = GA0_PIN | GA1_PIN | GA2_PIN | GA3_PIN | GA4_PIN | RACKID2_PIN;
  26. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  27. GPIO_InitStruct.Pull = GPIO_NOPULL;
  28. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  29. stm32_gpio_init(GPIOH, &GPIO_InitStruct);
  30. GPIO_InitStruct.Pin = GAP_PIN | RACKID1_PIN | RACKID3_PIN | RACKID4_PIN | RACKID5_PIN;
  31. stm32_gpio_init(GPIOI, &GPIO_InitStruct);
  32. //LED灯 D2
  33. GPIO_InitStruct.Pin = GPIO1_PIN;
  34. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  35. GPIO_InitStruct.Pull = GPIO_NOPULL;
  36. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  37. stm32_gpio_write(IDENTIFY_PORT, IDENTIFY_PIN, GPIO_PIN_RESET);
  38. stm32_gpio_init(GPIO1_PORT, &GPIO_InitStruct);
  39. g_BMCInfo.SelfTestByte = 0;
  40. g_BMCInfo.SlotID = PDK_GetSlotID();
  41. g_BMCInfo.ChassisID = PDK_GetChassisID();
  42. //机箱及刀片信息
  43. g_BMCInfo.ChassisIdentify = FALSE;
  44. g_BMCInfo.ChassisIdentifyForce = FALSE;
  45. g_BMCInfo.ChassisIdentifyTimeout = 0;
  46. g_BMCInfo.PowerGoodFlag = 1;
  47. g_BMCInfo.BladeManageEn = 0;
  48. g_BMCInfo.BladeHealthSta = 1;
  49. memset(g_BMCInfo.BladeName, 0, 31);
  50. sprintf(g_BMCInfo.BladeName, "板卡%d", g_BMCInfo.SlotID);
  51. switch(g_BMCInfo.SlotID)
  52. {
  53. case 0x1:
  54. g_BMCInfo.IndexInChassis = 0;
  55. break;
  56. case 0x2:
  57. g_BMCInfo.IndexInChassis = 1;
  58. break;
  59. case 0x3:
  60. g_BMCInfo.IndexInChassis = 2;
  61. break;
  62. case 0x4:
  63. g_BMCInfo.IndexInChassis = 3;
  64. break;
  65. case 0x5:
  66. g_BMCInfo.IndexInChassis = 4;
  67. break;
  68. case 0x6:
  69. g_BMCInfo.IndexInChassis = 5;
  70. break;
  71. case 0x7:
  72. g_BMCInfo.IndexInChassis = 6;
  73. break;
  74. case 0x8:
  75. g_BMCInfo.IndexInChassis = 7;
  76. break;
  77. case 0x9:
  78. g_BMCInfo.IndexInChassis = 8;
  79. break;
  80. case 0xA:
  81. g_BMCInfo.IndexInChassis = 9;
  82. break;
  83. default:
  84. printf("\n\n\nWarning: Invalid SlotID %#x\n\n\n", g_BMCInfo.SlotID);
  85. g_BMCInfo.IndexInChassis = 0xff;
  86. break;
  87. }
  88. if(g_BMCInfo.SlotID == 1)
  89. {
  90. g_BMCInfo.isChMC = 1;
  91. //IPMB地址
  92. g_BMCInfo.PrimaryIPMBAddr = 0x20;
  93. g_BMCInfo.SecondaryIPMBAddr = 0x20;
  94. if(g_BMCInfo.IndexInChassis < BLADE_NUMBERS)
  95. {
  96. gChassisIPMBAddr[g_BMCInfo.IndexInChassis] = 0x20;
  97. }
  98. }
  99. else
  100. {
  101. g_BMCInfo.isChMC = 0;
  102. //IPMB地址
  103. g_BMCInfo.PrimaryIPMBAddr = (0x40+(g_BMCInfo.SlotID&0x1F))<<1;
  104. g_BMCInfo.SecondaryIPMBAddr = (0x40+(g_BMCInfo.SlotID&0x1F))<<1;
  105. }
  106. //init DevGUID
  107. g_BMCInfo.DeviceGUID[0] = 0x01;
  108. g_BMCInfo.DeviceGUID[1] = 0x01;
  109. g_BMCInfo.DeviceGUID[2] = 0x01;
  110. g_BMCInfo.DeviceGUID[3] = 0x01;
  111. g_BMCInfo.DeviceGUID[4] = 0x01;
  112. g_BMCInfo.DeviceGUID[5] = 0x01;
  113. g_BMCInfo.DeviceGUID[6] = 0x01;
  114. g_BMCInfo.DeviceGUID[7] = 0x01;
  115. g_BMCInfo.DeviceGUID[8] = 0x01;
  116. g_BMCInfo.DeviceGUID[9] = 0x01;
  117. g_BMCInfo.DeviceGUID[10] = 0x01;
  118. g_BMCInfo.DeviceGUID[11] = 0x01;
  119. g_BMCInfo.DeviceGUID[12] = 0x01;
  120. g_BMCInfo.DeviceGUID[13] = 0x01;
  121. g_BMCInfo.DeviceGUID[14] = 0x01;
  122. g_BMCInfo.DeviceGUID[15] = 0x01;
  123. g_BMCInfo.FwMajorVer = FW_VERSION_MAJOR;
  124. g_BMCInfo.FwMinorVer = FW_VERSION_MINOR;
  125. g_BMCInfo.SendMsgSeqNum = 0;
  126. // g_BMCInfo.OemFlags.BladeWorkMode = BLADE_IPMC;
  127. // g_BMCInfo.OemFlags.chassisManageFnEnable = 0;
  128. // g_BMCInfo.OemFlags.thisBladeIndex = 0;
  129. // g_BMCInfo.OemFlags.bladeStatus = 1; //0: not present, 1: normal, 2: error, others: reserved.
  130. g_BMCInfo.HealthLevel = SENSOR_STATUS_NORMAL;
  131. g_BMCInfo.SensorSharedMem.SensorTick= 0;
  132. g_BMCInfo.SenConfig.PowerOnTick = 0;
  133. g_BMCInfo.SenConfig.SysResetTick = 0;
  134. g_BMCInfo.CurTimerTick = 0;
  135. g_BMCInfo.CurTimerSecond = 0;
  136. g_BMCInfo.BootValidMinutes = 0;
  137. g_BMCInfo.m_Lan_SetInProgress = 0;
  138. return 0;
  139. }
  140. int InitTimerTaskTbl(void)
  141. {
  142. printf("InitTimerTaskTbl...\n");
  143. g_BMCInfo.TimerTaskTblSize = 2;
  144. memcpy(g_BMCInfo.TimerTaskTbl, m_TimerTaskTbl, sizeof(TimerTaskTbl_T)*g_BMCInfo.TimerTaskTblSize);
  145. }
  146. int Init_SessionTbl(void)
  147. {
  148. printf("Init_SessionTbl...\n");
  149. g_BMCInfo.SessionHandle = 0;
  150. g_BMCInfo.UDSSessionHandle = 0;
  151. g_BMCInfo.IpmiConfig.MaxSession = 10;
  152. g_BMCInfo.IpmiConfig.SessionTimeOut = 10; //10s
  153. g_BMCInfo.IpmiConfig.SendMsgTimeout = 10; //10s
  154. /*Allocating Memory to hold session Table informations */
  155. g_BMCInfo.SessionTblInfo.SessionTbl = (SessionInfo_T *) malloc(sizeof(SessionInfo_T)*( g_BMCInfo.IpmiConfig.MaxSession + 1));
  156. if(g_BMCInfo.SessionTblInfo.SessionTbl == NULL)
  157. {
  158. printf("Error in allocating memory for SessionTbl \n");
  159. return 1;
  160. }
  161. g_BMCInfo.SessionTblInfo.Count = 0;
  162. /*Initialize the Session Table memory */
  163. memset(g_BMCInfo.SessionTblInfo.SessionTbl,0,sizeof(SessionInfo_T)*(g_BMCInfo.IpmiConfig.MaxSession + 1));
  164. /*Allocating Memory to hold UDS session Table informations */
  165. g_BMCInfo.UDSSessionTblInfo.UDSSessionTbl = (UDSSessionTbl_T *) malloc(sizeof(UDSSessionTbl_T)*(g_BMCInfo.IpmiConfig.MaxSession + 1));
  166. if(g_BMCInfo.UDSSessionTblInfo.UDSSessionTbl == NULL)
  167. {
  168. printf("Error in allocating memory for SessionTbl \n");
  169. return 1;
  170. }
  171. g_BMCInfo.UDSSessionTblInfo.SessionCount = 0;
  172. /*Initialize the UDS Session Table memory */
  173. memset(g_BMCInfo.UDSSessionTblInfo.UDSSessionTbl,0,sizeof(UDSSessionTbl_T)*(g_BMCInfo.IpmiConfig.MaxSession + 1));
  174. }
  175. const char FirstPowerOnStr[] = "First power on the bmc";
  176. int Init_IPMI_FRU_SDR_SEL(void)
  177. {
  178. int i;
  179. uint32_t sdrSize =
  180. sizeof(SDRRepository_T) + sizeof(HdrMgmtCtrlrDevLocator_T) + sizeof(HdrFullSensorRec_T)*SENSOR_NUMBERS;
  181. uint32_t selSize = sizeof(SELRepository_T) + sizeof(SELRec_T)*MAX_SEL_RECORD ;
  182. uint8_t* pSDR = NULL;
  183. uint8_t* pSEL = NULL;
  184. g_BMCInfo.pSDR = malloc(sdrSize);
  185. if((g_BMCInfo.pSDR == NULL) && (sdrSize != 0))
  186. {
  187. printf("g_BMCInfo.pSDR Malloc failed!\r\n");
  188. }
  189. g_BMCInfo.pSEL = malloc(selSize);
  190. if((g_BMCInfo.pSEL == NULL) && (selSize != 0))
  191. {
  192. printf("g_BMCInfo.pSEL Malloc failed!\r\n");
  193. }
  194. GetIPMIFromFlash();
  195. if(strncmp(g_BMCInfo.IpmiConfig.FirstPowerOnStr, FirstPowerOnStr, sizeof(FirstPowerOnStr)) != 0)
  196. // if(1)
  197. {
  198. //first power on
  199. printf("\n\n*** BMC first power on! ***\n\n");
  200. /************************** Init IPMI ******************************/
  201. memcpy(g_BMCInfo.IpmiConfig.FirstPowerOnStr, FirstPowerOnStr, sizeof(FirstPowerOnStr));
  202. g_BMCInfo.IpmiConfig.SerialIfcSupport = SERIAL_IFC_SUPPORT;
  203. g_BMCInfo.IpmiConfig.SerialTerminalSupport = SERIAL_TERMINAL_SUPPORT;
  204. g_BMCInfo.IpmiConfig.LANIfcSupport = LAN_IFC_SUPPORT;
  205. g_BMCInfo.IpmiConfig.SYSIfcSupport = SYS_IFC_SUPPORT;
  206. g_BMCInfo.IpmiConfig.GrpExtnSupport = GROUP_EXTERN_SUPPORT;
  207. g_BMCInfo.IpmiConfig.UDSIfcSupport = UDS_IFC_SUPPORT;
  208. g_BMCInfo.IpmiConfig.ChassisTimerInterval = CHASSIS_TIMER_INTERVAL;
  209. g_BMCInfo.IpmiConfig.PowerCycleInterval = PWR_CYCLE_INTERVAL;
  210. g_BMCInfo.IpmiConfig.FanControlInterval = FAN_CONTROL_INTERVAL;
  211. g_BMCInfo.IpmiConfig.RearmSetSensorThreshold = REARM_SET_SENSOR_THRESHOLD;
  212. g_BMCInfo.IpmiConfig.SELTimeUTCOffset = 8*60;
  213. //IPMB
  214. g_BMCInfo.IpmiConfig.PrimaryIPMBSupport = PRIMARY_IPMB_SUPPORT;
  215. g_BMCInfo.IpmiConfig.SecondaryIPMBSupport = SECONDARY_IPMB_SUPPORT;
  216. g_BMCInfo.IpmiConfig.PrimaryIPMBBus = PRIMARY_IPMB_BUS;
  217. g_BMCInfo.IpmiConfig.SecondaryIPMBBus = SECONDARY_IPMB_BUS;
  218. //Init FRU
  219. memcpy(&g_BMCInfo.FRU, &Default_FRUData, sizeof(OemFRUData_T));
  220. /************************ Init SDR *************************************/
  221. pSDR = g_BMCInfo.pSDR;
  222. //init SDR repository header
  223. ((SDRRepository_T*)pSDR)->Signature[0] = 0x00;
  224. ((SDRRepository_T*)pSDR)->Signature[1] = 0x11;
  225. ((SDRRepository_T*)pSDR)->Signature[2] = 0x22;
  226. ((SDRRepository_T*)pSDR)->Signature[3] = 0x33;
  227. ((SDRRepository_T*)pSDR)->NumRecords = SENSOR_NUMBERS + 1;
  228. ((SDRRepository_T*)pSDR)->Size = sdrSize;
  229. ((SDRRepository_T*)pSDR)->AddTimeStamp = 0;
  230. ((SDRRepository_T*)pSDR)->EraseTimeStamp = 0;
  231. //init MgmtCtrlrDevLocator SDR
  232. pSDR += sizeof(SDRRepository_T);
  233. ((HdrMgmtCtrlrDevLocator_T*)pSDR)->Valid = 1;
  234. ((HdrMgmtCtrlrDevLocator_T*)pSDR)->Len = sizeof(HdrMgmtCtrlrDevLocator_T);
  235. memcpy(&(((HdrMgmtCtrlrDevLocator_T*)pSDR)->MgmtCtrlrDevLocator), &bmc_sdr, sizeof(MgmtCtrlrDevLocator_T));
  236. //init FullSensorRec SDR
  237. pSDR += sizeof(HdrMgmtCtrlrDevLocator_T);
  238. for(i=0;i<SENSOR_NUMBERS;i++)
  239. {
  240. ((HdrFullSensorRec_T*)pSDR)->Valid = 1;
  241. ((HdrFullSensorRec_T*)pSDR)->Len = sizeof(HdrFullSensorRec_T);
  242. memcpy(&(((HdrFullSensorRec_T*)pSDR)->FullSensorRec), &full_sdr_tbl[i], sizeof(FullSensorRec_T));
  243. pSDR += sizeof(HdrFullSensorRec_T);
  244. }
  245. /******************************* Init SEL *************************************/
  246. pSEL = g_BMCInfo.pSEL;
  247. ((SELRepository_T*)pSEL)->Signature[0] = 0x00;
  248. ((SELRepository_T*)pSEL)->Signature[1] = 0x11;
  249. ((SELRepository_T*)pSEL)->Signature[2] = 0x22;
  250. ((SELRepository_T*)pSEL)->Signature[3] = 0x33;
  251. ((SELRepository_T*)pSEL)->NumRecords = 0;
  252. ((SELRepository_T*)pSEL)->Padding = 0;
  253. ((SELRepository_T*)pSEL)->AddTimeStamp = 0;
  254. ((SELRepository_T*)pSEL)->EraseTimeStamp = 0;
  255. ((SELRepository_T*)pSEL)->FirstRecID = 0;
  256. ((SELRepository_T*)pSEL)->LastRecID = 0;
  257. ((SELRepository_T*)pSEL)->SELIndex = 0;
  258. ((SELRepository_T*)pSEL)->SELRecord = (SELRec_T*)(pSEL + sizeof(SELRepository_T));
  259. g_BMCInfo.IpmiConfig.SELConfig.SelReservationID = 0;;
  260. g_BMCInfo.IpmiConfig.SELConfig.LastEvtTS = 0;
  261. g_BMCInfo.IpmiConfig.SELConfig.PartialAddRecordID = 0;
  262. g_BMCInfo.IpmiConfig.SELConfig.PartialAddRecOffset = 0;
  263. g_BMCInfo.IpmiConfig.SELConfig.PartialAdd = 0;
  264. g_BMCInfo.IpmiConfig.SELConfig.SenMonSELFlag = 0;
  265. g_BMCInfo.IpmiConfig.SELConfig.MaxSELRecord = MAX_SEL_RECORD;
  266. // g_BMCInfo.SELConfig.RsrvIDCancelled = FALSE;
  267. g_BMCInfo.IpmiConfig.SELConfig.SELOverFlow = FALSE;
  268. g_BMCInfo.IpmiConfig.SELConfig.selalmostfull = 0;
  269. memset(g_BMCInfo.UserInfoTbl, 0x0, sizeof(UserInfo_T)*MAX_USER_NUM);
  270. g_BMCInfo.UserInfoTbl[2].UserId = 3;
  271. strcpy(g_BMCInfo.UserInfoTbl[2].UserName, "admin");
  272. strcpy(g_BMCInfo.UserInfoTbl[2].UserPassword, "admin");
  273. g_BMCInfo.UserInfoTbl[2].UserStatus = TRUE;
  274. g_BMCInfo.CurrentNoUser = 1;
  275. g_BMCInfo.pUserInfo = NULL;
  276. /************** Sensor History ****************/
  277. memset(gSensorHistoryInfo, 0, sizeof(SensorHistoryInfo_T)*SENSOR_NUMBERS);
  278. FlushSensorHistoryToFlash();
  279. /************** Lan info ********************/
  280. //LAN地址
  281. LanInfo_T *pSetLanInfo = &g_BMCInfo.IpmiConfig.LanInfo[0];
  282. pSetLanInfo->IPAddr[0] = 192;
  283. pSetLanInfo->IPAddr[1] = 168;
  284. pSetLanInfo->IPAddr[2] = 1; //网段
  285. pSetLanInfo->IPAddr[3] = 120+g_BMCInfo.SlotID;
  286. pSetLanInfo->BroadCast[0] = 192;
  287. pSetLanInfo->BroadCast[1] = 168;
  288. pSetLanInfo->BroadCast[2] = 1; //网段
  289. pSetLanInfo->BroadCast[3] = 255;
  290. pSetLanInfo->NetMask[0] = 255;
  291. pSetLanInfo->NetMask[1] = 255;
  292. pSetLanInfo->NetMask[2] = 255;
  293. pSetLanInfo->NetMask[3] = 0;
  294. pSetLanInfo->DefaultGW[0] = pSetLanInfo->IPAddr[0];
  295. pSetLanInfo->DefaultGW[1] = pSetLanInfo->IPAddr[1];
  296. pSetLanInfo->DefaultGW[2] = pSetLanInfo->IPAddr[2];
  297. pSetLanInfo->DefaultGW[3] = 1;
  298. pSetLanInfo->MACAddr[0] = 0; //no default mac
  299. pSetLanInfo->MACAddr[1] = 0;
  300. pSetLanInfo->MACAddr[2] = 0;
  301. pSetLanInfo->MACAddr[3] = 0;
  302. pSetLanInfo->MACAddr[4] = 0;
  303. pSetLanInfo->MACAddr[5] = 0;
  304. FlushUserInfoTbl();
  305. UpdateFlash();
  306. }
  307. else
  308. {
  309. //Init FRU
  310. GetFRUFromFlash();
  311. //Init SDR
  312. GetSDRFromFlash();
  313. //Init SEL
  314. GetSELFromFlash();
  315. ((SELRepository_T*)g_BMCInfo.pSEL)->SELRecord = (SELRec_T*)(g_BMCInfo.pSEL + sizeof(SELRepository_T));
  316. g_BMCInfo.IpmiConfig.SELConfig.SelReservationID = 0;;
  317. g_BMCInfo.IpmiConfig.SELConfig.LastEvtTS = 0;
  318. g_BMCInfo.IpmiConfig.SELConfig.PartialAddRecordID = 0;
  319. g_BMCInfo.IpmiConfig.SELConfig.PartialAddRecOffset = 0;
  320. g_BMCInfo.IpmiConfig.SELConfig.PartialAdd = 0;
  321. g_BMCInfo.IpmiConfig.SELConfig.SenMonSELFlag = 0;
  322. g_BMCInfo.IpmiConfig.SELConfig.MaxSELRecord = MAX_SEL_RECORD;
  323. // g_BMCInfo.SELConfig.RsrvIDCancelled = FALSE;
  324. g_BMCInfo.IpmiConfig.SELConfig.SELOverFlow = FALSE;
  325. g_BMCInfo.IpmiConfig.SELConfig.selalmostfull = 0;
  326. //Init SensorHistory
  327. GetSensorHistoryFromFlash();
  328. UpdateUserInfoTble();
  329. g_BMCInfo.CurrentNoUser = 0;
  330. for(i=0;i<MAX_USER_NUM;i++)
  331. {
  332. if((g_BMCInfo.UserInfoTbl[i].UserId != 0) && (g_BMCInfo.UserInfoTbl[i].UserStatus == TRUE))
  333. g_BMCInfo.CurrentNoUser++;
  334. }
  335. g_BMCInfo.pUserInfo = NULL;
  336. }
  337. g_BMCInfo.IpmiConfig.SDRConfig.UpdatingSDR = FALSE;
  338. g_BMCInfo.IpmiConfig.SDRConfig.UpdatingChannel = 0;
  339. g_BMCInfo.IpmiConfig.SDRConfig.TrackPOffset = 0;
  340. g_BMCInfo.IpmiConfig.SDRConfig.TrackRecID = 0;
  341. g_BMCInfo.IpmiConfig.SDRConfig.IPMB_Seqnum = 0;
  342. g_BMCInfo.IpmiConfig.SDRConfig.PartAddbytes = 0;
  343. g_BMCInfo.IpmiConfig.SDRConfig.LatestRecordID = 0;
  344. g_BMCInfo.IpmiConfig.SDRConfig.NumMarkedRecords = 0;
  345. g_BMCInfo.IpmiConfig.SDRConfig.RepositoryInfo.Version = 0x51;
  346. g_BMCInfo.IpmiConfig.SDRConfig.RepositoryInfo.FreeSpace = 0xffff;
  347. g_BMCInfo.IpmiConfig.SDRConfig.RepositoryInfo.AddTimeStamp = 0;
  348. g_BMCInfo.IpmiConfig.SDRConfig.RepositoryInfo.EraseTimeStamp = 0;
  349. g_BMCInfo.IpmiConfig.SDRConfig.RepositoryInfo.OpSupport = 0x23;
  350. g_BMCInfo.IpmiConfig.SDRConfig.RepositoryAllocInfo.NumAllocUnits = MAX_SENSOR_NUMBERS+1;
  351. g_BMCInfo.IpmiConfig.SDRConfig.RepositoryAllocInfo.AllocUnitSize = SDR_ALLOC_UNIT_SIZE;
  352. g_BMCInfo.IpmiConfig.SDRConfig.RepositoryAllocInfo.NumFreeAllocUnits = MAX_SENSOR_NUMBERS - SENSOR_NUMBERS;
  353. g_BMCInfo.IpmiConfig.SDRConfig.RepositoryAllocInfo.LargestFreeBlock = SDR_MAX_RECORD_SIZE;
  354. g_BMCInfo.IpmiConfig.SDRConfig.RepositoryAllocInfo.MaxRecSize = SDR_MAX_RECORD_SIZE; //Maximum record size in allocation units
  355. g_BMCInfo.IpmiConfig.SDRConfig.SDRRAM = (SDRRepository_T*)g_BMCInfo.pSDR;
  356. g_BMCInfo.IpmiConfig.SDRConfig.RepositoryInfo.RecCt = ((SDRRepository_T*)g_BMCInfo.IpmiConfig.SDRConfig.SDRRAM)->NumRecords;
  357. g_BMCInfo.IpmiConfig.SDRConfig.SDRError = 0;
  358. g_BMCInfo.IpmiConfig.SDRConfig.ReservationID = 0;
  359. return 0;
  360. }
  361. int SetSysTime(uint32_t *timeSecond)
  362. {
  363. time_t tt;
  364. tt = *timeSecond;
  365. stime(&tt); //TODO:注意时区
  366. return 0;
  367. }
  368. long int GetSysTime(void)
  369. {
  370. time_t tt;
  371. time(&tt);
  372. //TODO: 注意时区
  373. //tt += 8*60*60; UTC+8
  374. return tt;
  375. }
  376. int PostEventMessage (uint8_t *EventMsg,uint8_t size)
  377. {
  378. uint8_t SelReq [sizeof(SELEventRecord_T)];
  379. uint8_t SelRes [sizeof(AddSELRes_T)];
  380. SELEventRecord_T* SelRecord = ( SELEventRecord_T*) SelReq;
  381. SelRecord->hdr.Type = 0x02;
  382. SelRecord->hdr.TimeStamp = GetSysTime ();
  383. memcpy (SelRecord->GenID, EventMsg, size);
  384. LockedAddSELEntry(SelReq, sizeof (SELEventRecord_T), SelRes);
  385. return 0;
  386. }
  387. uint8_t PDK_GetSlotID(void)
  388. {
  389. uint8_t SlotID = 0;
  390. // uint8_t check = 0;
  391. if(stm32_gpio_read(GA0_PORT, GA0_PIN) == GPIO_PIN_RESET)
  392. SlotID |= 0x01;
  393. if(stm32_gpio_read(GA1_PORT, GA1_PIN) == GPIO_PIN_RESET)
  394. SlotID |= 0x02;
  395. if(stm32_gpio_read(GA2_PORT, GA2_PIN) == GPIO_PIN_RESET)
  396. SlotID |= 0x04;
  397. if(stm32_gpio_read(GA3_PORT, GA3_PIN) == GPIO_PIN_RESET)
  398. SlotID |= 0x08;
  399. if(stm32_gpio_read(GA4_PORT, GA4_PIN) == GPIO_PIN_RESET)
  400. SlotID |= 0x10;
  401. // if(stm32_gpio_read(GAP_PORT, GAP_PIN) == GPIO_PIN_RESET)
  402. // SlotID |= 0x20;
  403. // int i;
  404. // for(i=0;i<6;i++)
  405. // check ^= (SlotID>>i)&0x01;
  406. // if(check == 0)
  407. // printf("Slot ID check error! GAP = %#x, GA[4:0] = %#x.\n", (SlotID>>5), (SlotID&0x1f));
  408. // return SlotID&0x1f;
  409. return SlotID;
  410. }
  411. uint8_t PDK_GetChassisID(void)
  412. {
  413. uint8_t ChassisID = 0;
  414. // if(stm32_gpio_read(RACKID0_PORT, RACKID0_PIN) == GPIO_PIN_SET)
  415. // ChassisID |= 0x01;
  416. // if(stm32_gpio_read(RACKID1_PORT, RACKID1_PIN) == GPIO_PIN_SET)
  417. // ChassisID |= 0x02;
  418. // if(stm32_gpio_read(RACKID2_PORT, RACKID2_PIN) == GPIO_PIN_SET)
  419. // ChassisID |= 0x04;
  420. // if(stm32_gpio_read(RACKID3_PORT, RACKID3_PIN) == GPIO_PIN_SET)
  421. // ChassisID |= 0x08;
  422. // if(stm32_gpio_read(RACKID4_PORT, RACKID4_PIN) == GPIO_PIN_SET)
  423. // ChassisID |= 0x10;
  424. // if(stm32_gpio_read(RACKID5_PORT, RACKID5_PIN) == GPIO_PIN_SET)
  425. // ChassisID |= 0x20;
  426. return ChassisID;
  427. }
  428. int PDK_PowerOffChassis(void)
  429. {
  430. //printf("Api power off chassis\n");
  431. g_BMCInfo.PowerGoodFlag = 0;
  432. printf("Not support power control!\n");
  433. return 0;
  434. }
  435. int PDK_PowerOnChassis(void)
  436. {
  437. //printf("power on chassis\n");
  438. g_BMCInfo.PowerGoodFlag = 1;
  439. printf("Not support power control!\n");
  440. }
  441. int PDK_SoftOffChassis(void)
  442. {
  443. //printf("soft off chassis\n");
  444. g_BMCInfo.PowerGoodFlag = 0;
  445. printf("Not support power control!\n");
  446. }
  447. int PDK_GetPowerStatus(void)
  448. {
  449. //TODO:
  450. return 1;
  451. }
  452. int PDK_PowerCycleChassis(void)
  453. {
  454. //printf("power cycle chassis\n");
  455. printf("Not support power control!\n");
  456. return 0;
  457. }
  458. int PDK_ResetChassis(void)
  459. {
  460. //printf("power reset chassis\n");
  461. printf("Not support power control!\n");
  462. return 0;
  463. }
  464. int PDK_DiagInterruptChassis(void)
  465. {
  466. printf("power diag chassis\n");
  467. }
  468. int PDK_FanControl(void)
  469. {
  470. ;
  471. }
  472. //设置IP地址
  473. /*
  474. * 函数名称 : int setip(char *ip)
  475. * 函数功能 : 设置系统IP地址
  476. * 参 数 :
  477. *char *ip :设置的IP地址,以点分十进制的字符串方式表示,如“192.168.0.5”
  478. * 返 回 值 : 0 : 成功 ; -1 : 失败
  479. */
  480. int setip(char *ip)
  481. {
  482. struct ifreq temp;
  483. struct sockaddr_in *addr;
  484. int fd = 0;
  485. int ret = -1;
  486. strcpy(temp.ifr_name, "eth0");
  487. if((fd=socket(AF_INET, SOCK_STREAM, 0))<0)
  488. {
  489. return -1;
  490. }
  491. addr = (struct sockaddr_in *)&(temp.ifr_addr);
  492. addr->sin_family = AF_INET;
  493. addr->sin_addr.s_addr = inet_addr(ip);
  494. ret = ioctl(fd, SIOCSIFADDR, &temp);
  495. close(fd);
  496. if(ret < 0)
  497. return -1;
  498. return 0;
  499. }
  500. //获取IP地址
  501. /*
  502. * 函数名称 : char * getip(char *ip_buf)
  503. * 函数功能 : 获取系統IP地址
  504. * 参 数 :
  505. *char *ip_buf :用来存放IP地址的内存空间
  506. * 返 回 值 : ip_buf : 存放IP地址的内存地址
  507. */
  508. char* getip(char *ip_buf)
  509. {
  510. struct ifreq temp;
  511. struct sockaddr_in *myaddr;
  512. int fd = 0;
  513. int ret = -1;
  514. strcpy(temp.ifr_name, "eth0");
  515. if((fd=socket(AF_INET, SOCK_STREAM, 0))<0)
  516. {
  517. return NULL;
  518. }
  519. ret = ioctl(fd, SIOCGIFADDR, &temp);
  520. close(fd);
  521. if(ret < 0)
  522. return NULL;
  523. myaddr = (struct sockaddr_in *)&(temp.ifr_addr);
  524. strcpy(ip_buf, (char*)inet_ntoa(myaddr->sin_addr));
  525. return ip_buf;
  526. }
  527. char* getnetmask(char *netmask_buf)
  528. {
  529. struct ifreq temp;
  530. struct sockaddr_in *myaddr;
  531. int fd = 0;
  532. int ret = -1;
  533. strcpy(temp.ifr_name, "eth0");
  534. if((fd=socket(AF_INET, SOCK_STREAM, 0))<0)
  535. {
  536. return NULL;
  537. }
  538. ret = ioctl(fd, SIOCGIFNETMASK, &temp);
  539. close(fd);
  540. if(ret < 0)
  541. return NULL;
  542. myaddr = (struct sockaddr_in *)&(temp.ifr_addr);
  543. strcpy(netmask_buf, (char*)inet_ntoa(myaddr->sin_addr));
  544. return netmask_buf;
  545. }
  546. char* getbroadcast(char *broadcast_buf)
  547. {
  548. struct ifreq temp;
  549. struct sockaddr_in *myaddr;
  550. int fd = 0;
  551. int ret = -1;
  552. strcpy(temp.ifr_name, "eth0");
  553. if((fd=socket(AF_INET, SOCK_STREAM, 0))<0)
  554. {
  555. return NULL;
  556. }
  557. ret = ioctl(fd, SIOCGIFBRDADDR, &temp);
  558. close(fd);
  559. if(ret < 0)
  560. return NULL;
  561. myaddr = (struct sockaddr_in *)&(temp.ifr_addr);
  562. strcpy(broadcast_buf, (char*)inet_ntoa(myaddr->sin_addr));
  563. return broadcast_buf;
  564. }
  565. char* getmac(char *mac_buf)
  566. {
  567. struct ifreq temp;
  568. struct sockaddr_in *myaddr;
  569. int fd = 0;
  570. int ret = -1;
  571. strcpy(temp.ifr_name, "eth0");
  572. if((fd=socket(AF_INET, SOCK_STREAM, 0))<0)
  573. {
  574. return NULL;
  575. }
  576. if(ioctl(fd,SIOCGIFHWADDR,&temp)<0)
  577. {
  578. printf("Get mac address ioctl fail!\n");
  579. }
  580. else
  581. {
  582. sprintf(mac_buf, "%02x:%02x:%02x:%02x:%02x:%02x\n",
  583. (unsigned char)temp.ifr_hwaddr.sa_data[0],
  584. (unsigned char)temp.ifr_hwaddr.sa_data[1],
  585. (unsigned char)temp.ifr_hwaddr.sa_data[2],
  586. (unsigned char)temp.ifr_hwaddr.sa_data[3],
  587. (unsigned char)temp.ifr_hwaddr.sa_data[4],
  588. (unsigned char)temp.ifr_hwaddr.sa_data[5]);
  589. }
  590. close(fd);
  591. return mac_buf;
  592. }
  593. int getSensorHistory(uint8_t sensorNum, uint8_t *phistoryBuf)
  594. {
  595. int i =0;
  596. for(i=0;i<SENSOR_NUMBERS;i++)
  597. {
  598. if(gSensorHistoryInfo[i].SensorNum == sensorNum)
  599. {
  600. memcpy(phistoryBuf, gSensorHistoryInfo[i].History, HISTORY_DATA_SIZE);
  601. return 0;
  602. }
  603. }
  604. if(i >= SENSOR_NUMBERS)
  605. {
  606. printf("Warning: Can't find sensorNum!\n");
  607. return -1;
  608. }
  609. }
  610. pthread_mutex_t api_bridge_mutex;
  611. int API_BridgeInternal(MsgPkt_T* pReqPkt, MsgPkt_T* pResPkt, uint8_t DestAddr, int Channel)
  612. {
  613. IPMIMsgHdr_T* pReqMsgHdr;
  614. IPMIMsgHdr_T* pResMsgHdr;
  615. uint8_t SeqNum = g_BMCInfo.SendMsgSeqNum;
  616. int RetVal;
  617. int fd_BridgeQue;
  618. uint8_t PBTbl;
  619. pthread_mutex_lock(&api_bridge_mutex);
  620. //create BRIDGE_QUEUE
  621. if(-1 != access(BRIDGE_QUEUE, F_OK))
  622. {
  623. remove(BRIDGE_QUEUE);
  624. }
  625. if(0 != mkfifo (BRIDGE_QUEUE, 0777))
  626. {
  627. printf("%s: Create %s fifo failed! \n", __FUNCTION__, BRIDGE_QUEUE);
  628. pthread_mutex_unlock(&api_bridge_mutex);
  629. return -1;
  630. }
  631. fd_BridgeQue = open (BRIDGE_QUEUE, O_RDWR);
  632. if(-1 == fd_BridgeQue)
  633. {
  634. printf("%s: Open %s fifo failed! \n", __FUNCTION__, BRIDGE_QUEUE);
  635. pthread_mutex_unlock(&api_bridge_mutex);
  636. return -1;
  637. }
  638. if(NULL != pReqPkt)
  639. {
  640. memcpy(&(pReqPkt->Data[sizeof(IPMIMsgHdr_T)]), pReqPkt->Data, pReqPkt->Size);
  641. pReqPkt->Size += sizeof(IPMIMsgHdr_T);
  642. pReqMsgHdr = (IPMIMsgHdr_T*)pReqPkt->Data;
  643. }
  644. else
  645. {
  646. printf("Warning: Message Packet to be bridged is NULL\r\n");
  647. remove(BRIDGE_QUEUE);
  648. pthread_mutex_unlock(&api_bridge_mutex);
  649. return -1;
  650. }
  651. if(NULL != pResPkt)
  652. {
  653. pResMsgHdr = (IPMIMsgHdr_T*)pResPkt->Data;
  654. }
  655. else
  656. {
  657. printf("Warning: Message Packet to be bridged is NULL\r\n");
  658. remove(BRIDGE_QUEUE);
  659. pthread_mutex_unlock(&api_bridge_mutex);
  660. return -1;
  661. }
  662. /* Format IPMI message header */
  663. pReqMsgHdr->ResAddr = DestAddr;
  664. pReqMsgHdr->NetFnLUN = pReqPkt->NetFnLUN;
  665. pReqMsgHdr->ChkSum = ~(pReqMsgHdr->ResAddr + pReqMsgHdr->NetFnLUN) + 1;
  666. if(Channel == PRIMARY_IPMB_CHANNEL)
  667. {
  668. pReqMsgHdr->ReqAddr = g_BMCInfo.PrimaryIPMBAddr; //PRIMARY_IPMB_ADDR;
  669. }
  670. else if(Channel == SECONDARY_IPMB_CHANNEL)
  671. {
  672. pReqMsgHdr->ReqAddr = g_BMCInfo.SecondaryIPMBAddr; //PRIMARY_IPMB_ADDR;
  673. }
  674. else
  675. {
  676. printf ("Warning: Invalid IPMB Channel: %d\r\n", Channel);
  677. remove(BRIDGE_QUEUE);
  678. pthread_mutex_unlock(&api_bridge_mutex);
  679. return -1;
  680. }
  681. pResPkt->NetFnLUN = pReqPkt->NetFnLUN + 0x40;
  682. pResPkt->Cmd = pReqPkt->Cmd;
  683. pReqMsgHdr->Cmd = pReqPkt->Cmd;
  684. pResMsgHdr->ResAddr = pReqMsgHdr->ReqAddr;
  685. pResMsgHdr->ChkSum = ~(pResMsgHdr->ResAddr + pResMsgHdr->NetFnLUN) + 1;
  686. pResMsgHdr->ReqAddr = pReqMsgHdr->ResAddr;
  687. pResMsgHdr->RqSeqLUN = pReqMsgHdr->RqSeqLUN;
  688. pResMsgHdr->Cmd = pReqMsgHdr->Cmd;
  689. PBTbl = (Channel == SECONDARY_IPMB_CHANNEL) ? SECONDARY_PB_TBL : PRIMARY_PB_TBL ;
  690. /* Store in the table for response tracking */
  691. while(TRUE)
  692. {
  693. if (FALSE == m_PendingBridgedResTbl[PBTbl][SeqNum].Used)
  694. {
  695. m_PendingBridgedResTbl[PBTbl][SeqNum].TimeOut = DEFAULT_TIMEOUT;
  696. m_PendingBridgedResTbl[PBTbl][SeqNum].ChannelNum = pReqPkt->Channel;
  697. m_PendingBridgedResTbl[PBTbl][SeqNum].OriginSrc = ORIGIN_INT_REQ;
  698. g_BMCInfo.SendMsgSeqNum = SeqNum;
  699. // printf("g_BMCInfo.SendMsgSeqNum %d\n", g_BMCInfo.SendMsgSeqNum);
  700. /* Format Sequence Number */
  701. pReqMsgHdr->RqSeqLUN = ((g_BMCInfo.SendMsgSeqNum) << 2) & 0xFC;
  702. pResMsgHdr->RqSeqLUN = pReqMsgHdr->RqSeqLUN + 0x40;
  703. memcpy (&m_PendingBridgedResTbl[PBTbl][SeqNum].ReqMsgHdr, pReqMsgHdr, sizeof (IPMIMsgHdr_T));
  704. memcpy (&m_PendingBridgedResTbl[PBTbl][SeqNum].ResMsgHdr, pResMsgHdr, sizeof (IPMIMsgHdr_T));
  705. m_PendingBridgedResTbl[PBTbl][SeqNum].DestQ = fd_BridgeQue;
  706. /* Store Session ID for final response to the origin for KCS*/
  707. //m_PendingBridgedResTbl[SeqNum].SrcSessionID = pReqPkt->SessionID;
  708. m_PendingBridgedResTbl[PBTbl][SeqNum].Used = TRUE;
  709. //printf( "---> oemApi.c: Bridged message added index = %d.\n", SeqNum );
  710. break;
  711. }
  712. else
  713. {
  714. SeqNum = (SeqNum + 1) & 0x3F;
  715. if(SeqNum == g_BMCInfo.SendMsgSeqNum)
  716. {
  717. printf ("Warning: Pending Bridge Response Table is full \n");
  718. remove(BRIDGE_QUEUE);
  719. pthread_mutex_unlock(&api_bridge_mutex);
  720. return -1;
  721. }
  722. }
  723. }
  724. /* Format message packet */
  725. pReqPkt->Channel = Channel;
  726. pReqPkt->Param = PARAM_BRIDGE;
  727. /* Recalculate the checksum */
  728. pReqPkt->Data [pReqPkt->Size] = CalculateCheckSum2 (pReqPkt->Data, pReqPkt->Size);
  729. pReqPkt->Size++;
  730. if(Channel == PRIMARY_IPMB_CHANNEL)
  731. {
  732. pReqPkt->SrcQ = gFd_PrimaryIpmbIfcQ;
  733. }
  734. else if(Channel == SECONDARY_IPMB_CHANNEL)
  735. {
  736. pReqPkt->SrcQ = gFd_SecondaryIpmbIfcQ;
  737. }
  738. else
  739. {
  740. printf("Warning: Invalid Channel %d\n", Channel);
  741. remove(BRIDGE_QUEUE);
  742. pthread_mutex_unlock(&api_bridge_mutex);
  743. return -1;
  744. }
  745. /* Post Message to the bridge queue */
  746. if(0 != PostMsg(pReqPkt->SrcQ, pReqPkt) )
  747. {
  748. printf ("Warning: oemApi.c : Error posting message to Queue %p \n", pReqPkt->SrcQ);
  749. remove(BRIDGE_QUEUE);
  750. pthread_mutex_unlock(&api_bridge_mutex);
  751. return -1;
  752. }
  753. m_PendingBridgedResTbl[PBTbl][SeqNum].ResDataOk = 1;
  754. RetVal = GetMsg (fd_BridgeQue, pResPkt, 5000); //3s
  755. // int i;
  756. // printf("Bridge recv: ");
  757. // for(i=0;i<pResPkt->Size;i++)
  758. // {
  759. // printf("%#x ", pResPkt->Data[i]);
  760. // }
  761. // printf("\n");
  762. remove(BRIDGE_QUEUE);
  763. pthread_mutex_unlock(&api_bridge_mutex);
  764. if(RetVal != 0)
  765. {
  766. return -1;
  767. }
  768. memcpy(pResPkt->Data, &(pResPkt->Data[sizeof(IPMIMsgHdr_T)]), pResPkt->Size - sizeof(IPMIMsgHdr_T)-1);
  769. pResPkt->Size = pResPkt->Size - sizeof(IPMIMsgHdr_T)-1; //remove header & checksum2
  770. return 0;
  771. }
  772. /***************** Flash 保存非易失数据 *******************/
  773. int FlushSDRToFlash()
  774. {
  775. uint32_t writeLen = 0;
  776. uint32_t offset = 0;
  777. uint32_t sdrSize =
  778. sizeof(SDRRepository_T) + sizeof(HdrMgmtCtrlrDevLocator_T) + sizeof(HdrFullSensorRec_T)*SENSOR_NUMBERS;
  779. pthread_mutex_lock(&Flash_Mutex);
  780. while(sdrSize > 0)
  781. {
  782. if(sdrSize > 4*1024)
  783. writeLen = 4*1024;
  784. else
  785. writeLen = sdrSize;
  786. sf_sector_erase(5, SDR_FLASH_ADDR+offset);
  787. sf_write(5, SDR_FLASH_ADDR+offset, g_BMCInfo.pSDR+offset, writeLen);
  788. offset += writeLen;
  789. sdrSize -= writeLen;
  790. }
  791. pthread_mutex_unlock(&Flash_Mutex);
  792. return 0;
  793. }
  794. int GetSDRFromFlash()
  795. {
  796. uint32_t sdrSize =
  797. sizeof(SDRRepository_T) + sizeof(HdrMgmtCtrlrDevLocator_T) + sizeof(HdrFullSensorRec_T)*SENSOR_NUMBERS;
  798. pthread_mutex_lock(&Flash_Mutex);
  799. sf_read(5, SDR_FLASH_ADDR, g_BMCInfo.pSDR, sdrSize);
  800. pthread_mutex_unlock(&Flash_Mutex);
  801. return 0;
  802. }
  803. int FlushSELToFlash()
  804. {
  805. uint32_t writeLen = 0;
  806. uint32_t offset = 0;
  807. uint32_t selSize = sizeof(SELRepository_T) + sizeof(SELRec_T)*MAX_SEL_RECORD ;
  808. pthread_mutex_lock(&Flash_Mutex);
  809. while(selSize > 0)
  810. {
  811. if(selSize > 4*1024)
  812. writeLen = 4*1024;
  813. else
  814. writeLen = selSize;
  815. sf_sector_erase(5, SEL_FLASH_ADDR+offset);
  816. sf_write(5, SEL_FLASH_ADDR+offset, g_BMCInfo.pSEL+offset, writeLen);
  817. offset += writeLen;
  818. selSize -= writeLen;
  819. }
  820. pthread_mutex_unlock(&Flash_Mutex);
  821. return 0;
  822. }
  823. int GetSELFromFlash()
  824. {
  825. uint32_t selSize = sizeof(SELRepository_T) + sizeof(SELRec_T)*MAX_SEL_RECORD ;
  826. pthread_mutex_lock(&Flash_Mutex);
  827. sf_read(5, SEL_FLASH_ADDR, g_BMCInfo.pSEL, selSize);
  828. pthread_mutex_unlock(&Flash_Mutex);
  829. return 0;
  830. }
  831. int FlushIPMIToFlash()
  832. {
  833. uint32_t writeLen = 0;
  834. uint32_t offset = 0;
  835. uint32_t ipmiSize = sizeof(IPMIConfig_T);
  836. pthread_mutex_lock(&Flash_Mutex);
  837. while(ipmiSize > 0)
  838. {
  839. if(ipmiSize > 4*1024)
  840. writeLen = 4*1024;
  841. else
  842. writeLen = ipmiSize;
  843. sf_sector_erase(5, IPMI_CFG_FLASH_ADDR+offset);
  844. sf_write(5, IPMI_CFG_FLASH_ADDR+offset, ((uint8_t*)&g_BMCInfo.IpmiConfig)+offset, writeLen);
  845. offset += writeLen;
  846. ipmiSize -= writeLen;
  847. }
  848. pthread_mutex_unlock(&Flash_Mutex);
  849. return 0;
  850. }
  851. int GetIPMIFromFlash()
  852. {
  853. uint32_t ipmiSize = sizeof(IPMIConfig_T);
  854. pthread_mutex_lock(&Flash_Mutex);
  855. sf_read(5, IPMI_CFG_FLASH_ADDR, (uint8_t*)&g_BMCInfo.IpmiConfig, ipmiSize);
  856. pthread_mutex_unlock(&Flash_Mutex);
  857. return 0;
  858. }
  859. int FlushFRUToFlash()
  860. {
  861. uint32_t fruSize = sizeof(OemFRUData_T);
  862. pthread_mutex_lock(&Flash_Mutex);
  863. sf_sector_erase(5, FRU_FLASH_ADDR);
  864. sf_write(5, FRU_FLASH_ADDR, (uint8_t*)&g_BMCInfo.FRU, fruSize);
  865. pthread_mutex_unlock(&Flash_Mutex);
  866. return 0;
  867. }
  868. int GetFRUFromFlash()
  869. {
  870. uint32_t fruSize = sizeof(OemFRUData_T);
  871. pthread_mutex_lock(&Flash_Mutex);
  872. sf_read(5, FRU_FLASH_ADDR, (uint8_t*)&g_BMCInfo.FRU, fruSize);
  873. pthread_mutex_unlock(&Flash_Mutex);
  874. return 0;
  875. }
  876. int FlushSensorHistoryToFlash()
  877. {
  878. uint32_t writeLen = 0;
  879. uint32_t offset = 0;
  880. uint32_t sensorSize = SENSOR_NUMBERS*sizeof(SensorHistoryInfo_T);
  881. pthread_mutex_lock(&Flash_Mutex);
  882. while(sensorSize > 0)
  883. {
  884. if(sensorSize > 4*1024)
  885. writeLen = 4*1024;
  886. else
  887. writeLen = sensorSize;
  888. sf_sector_erase(5, SENSOR_HISTORY_FLASH_ADDR+offset);
  889. sf_write(5, SENSOR_HISTORY_FLASH_ADDR+offset, ((uint8_t*)gSensorHistoryInfo)+offset, writeLen);
  890. offset += writeLen;
  891. sensorSize -= writeLen;
  892. }
  893. pthread_mutex_unlock(&Flash_Mutex);
  894. return 0;
  895. }
  896. int GetSensorHistoryFromFlash()
  897. {
  898. uint32_t sensorSize = SENSOR_NUMBERS*sizeof(SensorHistoryInfo_T);
  899. pthread_mutex_lock(&Flash_Mutex);
  900. sf_read(5, SENSOR_HISTORY_FLASH_ADDR, (uint8_t*)gSensorHistoryInfo, sensorSize);
  901. pthread_mutex_unlock(&Flash_Mutex);
  902. return 0;
  903. }
  904. int FlushUserInfoTbl(void)
  905. {
  906. pthread_mutex_lock(&Flash_Mutex);
  907. sf_sector_erase(5, USERTBL_FLASH_ADDR);
  908. sf_write(5, USERTBL_FLASH_ADDR, (uint8_t*)g_BMCInfo.UserInfoTbl, sizeof(UserInfo_T)*MAX_USER_NUM);
  909. pthread_mutex_unlock(&Flash_Mutex);
  910. return 0;
  911. }
  912. int UpdateUserInfoTble(void)
  913. {
  914. pthread_mutex_lock(&Flash_Mutex);
  915. sf_read(5, USERTBL_FLASH_ADDR, (uint8_t*)g_BMCInfo.UserInfoTbl, sizeof(UserInfo_T)*MAX_USER_NUM);
  916. pthread_mutex_unlock(&Flash_Mutex);
  917. return 0;
  918. }
  919. int UpdateFlash(void)
  920. {
  921. FlushSDRToFlash();
  922. FlushSELToFlash();
  923. FlushIPMIToFlash();
  924. FlushFRUToFlash();
  925. return 0;
  926. }
  927. int InitChannelTab(void)
  928. {
  929. int i;
  930. //primary IPMB channel
  931. g_BMCInfo.ChannelTab[0].ChannelNumber = 0;
  932. g_BMCInfo.ChannelTab[0].ChannelProtocol = 1;//Used for IPMB, serial/modem Basic Mode, and LAN.reference IPMIv2.0 Table 6-2
  933. g_BMCInfo.ChannelTab[0].ChannelMedium = 1; //IPMB, reference IPMIv2.0 Table 6-3
  934. g_BMCInfo.ChannelTab[0].SessionSupport = 0; //session less
  935. g_BMCInfo.ChannelTab[0].ActiveSession = 0;
  936. g_BMCInfo.ChannelTab[0].ProtocolVendorId[0] = 0x12;
  937. g_BMCInfo.ChannelTab[0].ProtocolVendorId[1] = 0x34;
  938. g_BMCInfo.ChannelTab[0].ProtocolVendorId[2] = 0x56;
  939. g_BMCInfo.ChannelTab[0].AuxiliaryInfo[0] = 0xff;
  940. g_BMCInfo.ChannelTab[0].AuxiliaryInfo[1] = 0xff;
  941. //LAN chennel
  942. g_BMCInfo.ChannelTab[1].ChannelNumber = 1;
  943. g_BMCInfo.ChannelTab[1].ChannelProtocol = 1;//Used for IPMB, serial/modem Basic Mode, and LAN.reference IPMIv2.0 Table 6-2
  944. g_BMCInfo.ChannelTab[1].ChannelMedium = 4; //802.3 LAN, reference IPMIv2.0 Table 6-3
  945. g_BMCInfo.ChannelTab[1].SessionSupport = 2; //muti session
  946. g_BMCInfo.ChannelTab[1].ActiveSession = 0;
  947. g_BMCInfo.ChannelTab[1].ProtocolVendorId[0] = 0x12;
  948. g_BMCInfo.ChannelTab[1].ProtocolVendorId[1] = 0x34;
  949. g_BMCInfo.ChannelTab[1].ProtocolVendorId[2] = 0x56;
  950. g_BMCInfo.ChannelTab[1].AuxiliaryInfo[0] = 0xff;
  951. g_BMCInfo.ChannelTab[1].AuxiliaryInfo[1] = 0xff;
  952. //Secondary IPMB channel
  953. g_BMCInfo.ChannelTab[2].ChannelNumber = 6;
  954. g_BMCInfo.ChannelTab[2].ChannelProtocol = 1;//Used for IPMB, serial/modem Basic Mode, and LAN.reference IPMIv2.0 Table 6-2
  955. g_BMCInfo.ChannelTab[2].ChannelMedium = 1; //IPMB, reference IPMIv2.0 Table 6-3
  956. g_BMCInfo.ChannelTab[2].SessionSupport = 0; //session less
  957. g_BMCInfo.ChannelTab[2].ActiveSession = 0;
  958. g_BMCInfo.ChannelTab[2].ProtocolVendorId[0] = 0x12;
  959. g_BMCInfo.ChannelTab[2].ProtocolVendorId[1] = 0x34;
  960. g_BMCInfo.ChannelTab[2].ProtocolVendorId[2] = 0x56;
  961. g_BMCInfo.ChannelTab[2].AuxiliaryInfo[0] = 0xff;
  962. g_BMCInfo.ChannelTab[2].AuxiliaryInfo[1] = 0xff;
  963. for(i=3;i<15;i++)
  964. {
  965. g_BMCInfo.ChannelTab[i].ChannelNumber = 0xf;
  966. }
  967. }
  968. ChannelInfo_T* getChannelInfo(uint8_t ChannelNum)
  969. {
  970. int i;
  971. for(i=0;i<15;i++)
  972. {
  973. if(g_BMCInfo.ChannelTab[i].ChannelNumber == ChannelNum)
  974. {
  975. return (ChannelInfo_T*)&g_BMCInfo.ChannelTab[i];
  976. }
  977. }
  978. return NULL;
  979. }