Api.c 36 KB

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