Api.c 33 KB

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