Api.c 33 KB

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