Api.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192
  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->body, EventMsg, size);
  386. LockedAddSELEntry(SelReq, sizeof (SELEventRecord_T), SelRes);
  387. return 0;
  388. }
  389. /*
  390. EventMsg共6个字节。
  391. */
  392. int PostOemEventMessage (uint8_t *EventMsg)
  393. {
  394. uint8_t SelReq [sizeof(SELEventRecord_T)];
  395. uint8_t SelRes [sizeof(AddSELRes_T)];
  396. SELEventRecord_T* SelRecord = ( SELEventRecord_T*) SelReq;
  397. SelRecord->hdr.Type = 0xC0; //storlead oem event Record ID
  398. SelRecord->hdr.TimeStamp = GetSysTime ();
  399. SelRecord->body.oemEventRecord.ManufacturerID[0] = 0x30;
  400. SelRecord->body.oemEventRecord.ManufacturerID[1] = 0x30;
  401. SelRecord->body.oemEventRecord.ManufacturerID[2] = 0x0f;
  402. memcpy (SelRecord->body.oemEventRecord.OEMDefined, EventMsg, 6);
  403. LockedAddSELEntry(SelReq, sizeof (SELEventRecord_T), SelRes);
  404. return 0;
  405. }
  406. uint8_t PDK_GetSlotID(void)
  407. {
  408. uint8_t SlotID = 0;
  409. // uint8_t check = 0;
  410. if(stm32_gpio_read(GA0_PORT, GA0_PIN) == GPIO_PIN_RESET)
  411. SlotID |= 0x01;
  412. if(stm32_gpio_read(GA1_PORT, GA1_PIN) == GPIO_PIN_RESET)
  413. SlotID |= 0x02;
  414. if(stm32_gpio_read(GA2_PORT, GA2_PIN) == GPIO_PIN_RESET)
  415. SlotID |= 0x04;
  416. if(stm32_gpio_read(GA3_PORT, GA3_PIN) == GPIO_PIN_RESET)
  417. SlotID |= 0x08;
  418. if(stm32_gpio_read(GA4_PORT, GA4_PIN) == GPIO_PIN_RESET)
  419. SlotID |= 0x10;
  420. // if(stm32_gpio_read(GAP_PORT, GAP_PIN) == GPIO_PIN_RESET)
  421. // SlotID |= 0x20;
  422. // int i;
  423. // for(i=0;i<6;i++)
  424. // check ^= (SlotID>>i)&0x01;
  425. // if(check == 0)
  426. // printf("Slot ID check error! GAP = %#x, GA[4:0] = %#x.\n", (SlotID>>5), (SlotID&0x1f));
  427. // return SlotID&0x1f;
  428. return SlotID;
  429. }
  430. uint8_t PDK_GetChassisID(void)
  431. {
  432. uint8_t ChassisID = 0;
  433. // if(stm32_gpio_read(RACKID0_PORT, RACKID0_PIN) == GPIO_PIN_SET)
  434. // ChassisID |= 0x01;
  435. // if(stm32_gpio_read(RACKID1_PORT, RACKID1_PIN) == GPIO_PIN_SET)
  436. // ChassisID |= 0x02;
  437. // if(stm32_gpio_read(RACKID2_PORT, RACKID2_PIN) == GPIO_PIN_SET)
  438. // ChassisID |= 0x04;
  439. // if(stm32_gpio_read(RACKID3_PORT, RACKID3_PIN) == GPIO_PIN_SET)
  440. // ChassisID |= 0x08;
  441. // if(stm32_gpio_read(RACKID4_PORT, RACKID4_PIN) == GPIO_PIN_SET)
  442. // ChassisID |= 0x10;
  443. // if(stm32_gpio_read(RACKID5_PORT, RACKID5_PIN) == GPIO_PIN_SET)
  444. // ChassisID |= 0x20;
  445. return ChassisID;
  446. }
  447. int PDK_PowerOffChassis(void)
  448. {
  449. printf("Api power off chassis\n");
  450. uint8_t EventMsg[6];
  451. EventMsg[0] = 1; //命令类1
  452. EventMsg[1] = 2; //命令,chassis
  453. EventMsg[2] = 2; //power off
  454. EventMsg[3] = 2; //命令来源:BMC CMD
  455. EventMsg[4] = 0; //Reserve
  456. EventMsg[5] = 0; //Reserve
  457. PostOemEventMessage (EventMsg);
  458. g_BMCInfo.PowerGoodFlag = 0;
  459. printf("Not support power control!\n");
  460. return 0;
  461. }
  462. int PDK_PowerOnChassis(void)
  463. {
  464. printf("power on chassis\n");
  465. uint8_t EventMsg[6];
  466. EventMsg[0] = 1; //命令类1
  467. EventMsg[1] = 2; //命令,chassis
  468. EventMsg[2] = 1; //power on
  469. EventMsg[3] = 2; //命令来源:BMC CMD
  470. EventMsg[4] = 0; //Reserve
  471. EventMsg[5] = 0; //Reserve
  472. PostOemEventMessage (EventMsg);
  473. g_BMCInfo.PowerGoodFlag = 1;
  474. printf("Not support power control!\n");
  475. }
  476. int PDK_SoftOffChassis(void)
  477. {
  478. //printf("soft off chassis\n");
  479. g_BMCInfo.PowerGoodFlag = 0;
  480. printf("Not support power control!\n");
  481. }
  482. int PDK_GetPowerStatus(void)
  483. {
  484. //TODO:
  485. // if(g_BMCInfo.PowerGoodFlag != retval)
  486. // {
  487. // uint8_t EventMsg[6];
  488. // EventMsg[0] = 2; //命令类2
  489. // EventMsg[1] = 1; //命令,power good
  490. // if(retval == 0) //power down
  491. // EventMsg[2] = 0; //power goes down
  492. // else
  493. // EventMsg[2] = 1; //power goes up
  494. // EventMsg[3] = 0; //命令来源:BMC CMD
  495. // EventMsg[4] = 0; //Reserve
  496. // EventMsg[5] = 0; //Reserve
  497. // PostOemEventMessage (EventMsg);
  498. // }
  499. return 1;
  500. }
  501. int PDK_PowerCycleChassis(void)
  502. {
  503. //printf("power cycle chassis\n");
  504. // uint8_t EventMsg[6];
  505. // EventMsg[0] = 1; //命令类1
  506. // EventMsg[1] = 2; //命令,chassis
  507. // EventMsg[2] = 4; //power cycle
  508. // EventMsg[3] = 2; //命令来源:BMC CMD
  509. // EventMsg[4] = 0; //Reserve
  510. // EventMsg[5] = 0; //Reserve
  511. // PostOemEventMessage (EventMsg);
  512. printf("Not support power control!\n");
  513. return 0;
  514. }
  515. int PDK_ResetChassis(void)
  516. {
  517. //printf("power reset chassis\n");
  518. // uint8_t EventMsg[6];
  519. // EventMsg[0] = 1; //命令类1
  520. // EventMsg[1] = 2; //命令,chassis
  521. // EventMsg[2] = 3; //reset
  522. // EventMsg[3] = 2; //命令来源:BMC CMD
  523. // EventMsg[4] = 0; //Reserve
  524. // EventMsg[5] = 0; //Reserve
  525. // PostOemEventMessage (EventMsg);
  526. printf("Not support power control!\n");
  527. return 0;
  528. }
  529. int PDK_DiagInterruptChassis(void)
  530. {
  531. printf("power diag chassis\n");
  532. }
  533. int PDK_FanControl(void)
  534. {
  535. ;
  536. }
  537. //设置IP地址
  538. /*
  539. * 函数名称 : int setip(char *ip)
  540. * 函数功能 : 设置系统IP地址
  541. * 参 数 :
  542. *char *ip :设置的IP地址,以点分十进制的字符串方式表示,如“192.168.0.5”
  543. * 返 回 值 : 0 : 成功 ; -1 : 失败
  544. */
  545. int setip(char *ip)
  546. {
  547. struct ifreq temp;
  548. struct sockaddr_in *addr;
  549. int fd = 0;
  550. int ret = -1;
  551. strcpy(temp.ifr_name, "eth0");
  552. if((fd=socket(AF_INET, SOCK_STREAM, 0))<0)
  553. {
  554. return -1;
  555. }
  556. addr = (struct sockaddr_in *)&(temp.ifr_addr);
  557. addr->sin_family = AF_INET;
  558. addr->sin_addr.s_addr = inet_addr(ip);
  559. ret = ioctl(fd, SIOCSIFADDR, &temp);
  560. close(fd);
  561. if(ret < 0)
  562. return -1;
  563. return 0;
  564. }
  565. //获取IP地址
  566. /*
  567. * 函数名称 : char * getip(char *ip_buf)
  568. * 函数功能 : 获取系統IP地址
  569. * 参 数 :
  570. *char *ip_buf :用来存放IP地址的内存空间
  571. * 返 回 值 : ip_buf : 存放IP地址的内存地址
  572. */
  573. char* getip(char *ip_buf)
  574. {
  575. struct ifreq temp;
  576. struct sockaddr_in *myaddr;
  577. int fd = 0;
  578. int ret = -1;
  579. strcpy(temp.ifr_name, "eth0");
  580. if((fd=socket(AF_INET, SOCK_STREAM, 0))<0)
  581. {
  582. return NULL;
  583. }
  584. ret = ioctl(fd, SIOCGIFADDR, &temp);
  585. close(fd);
  586. if(ret < 0)
  587. return NULL;
  588. myaddr = (struct sockaddr_in *)&(temp.ifr_addr);
  589. strcpy(ip_buf, (char*)inet_ntoa(myaddr->sin_addr));
  590. return ip_buf;
  591. }
  592. char* getnetmask(char *netmask_buf)
  593. {
  594. struct ifreq temp;
  595. struct sockaddr_in *myaddr;
  596. int fd = 0;
  597. int ret = -1;
  598. strcpy(temp.ifr_name, "eth0");
  599. if((fd=socket(AF_INET, SOCK_STREAM, 0))<0)
  600. {
  601. return NULL;
  602. }
  603. ret = ioctl(fd, SIOCGIFNETMASK, &temp);
  604. close(fd);
  605. if(ret < 0)
  606. return NULL;
  607. myaddr = (struct sockaddr_in *)&(temp.ifr_addr);
  608. strcpy(netmask_buf, (char*)inet_ntoa(myaddr->sin_addr));
  609. return netmask_buf;
  610. }
  611. char* getbroadcast(char *broadcast_buf)
  612. {
  613. struct ifreq temp;
  614. struct sockaddr_in *myaddr;
  615. int fd = 0;
  616. int ret = -1;
  617. strcpy(temp.ifr_name, "eth0");
  618. if((fd=socket(AF_INET, SOCK_STREAM, 0))<0)
  619. {
  620. return NULL;
  621. }
  622. ret = ioctl(fd, SIOCGIFBRDADDR, &temp);
  623. close(fd);
  624. if(ret < 0)
  625. return NULL;
  626. myaddr = (struct sockaddr_in *)&(temp.ifr_addr);
  627. strcpy(broadcast_buf, (char*)inet_ntoa(myaddr->sin_addr));
  628. return broadcast_buf;
  629. }
  630. char* getmac(char *mac_buf)
  631. {
  632. struct ifreq temp;
  633. struct sockaddr_in *myaddr;
  634. int fd = 0;
  635. int ret = -1;
  636. strcpy(temp.ifr_name, "eth0");
  637. if((fd=socket(AF_INET, SOCK_STREAM, 0))<0)
  638. {
  639. return NULL;
  640. }
  641. if(ioctl(fd,SIOCGIFHWADDR,&temp)<0)
  642. {
  643. printf("Get mac address ioctl fail!\n");
  644. }
  645. else
  646. {
  647. sprintf(mac_buf, "%02x:%02x:%02x:%02x:%02x:%02x\n",
  648. (unsigned char)temp.ifr_hwaddr.sa_data[0],
  649. (unsigned char)temp.ifr_hwaddr.sa_data[1],
  650. (unsigned char)temp.ifr_hwaddr.sa_data[2],
  651. (unsigned char)temp.ifr_hwaddr.sa_data[3],
  652. (unsigned char)temp.ifr_hwaddr.sa_data[4],
  653. (unsigned char)temp.ifr_hwaddr.sa_data[5]);
  654. }
  655. close(fd);
  656. return mac_buf;
  657. }
  658. int getSensorHistory(uint8_t sensorNum, uint8_t *phistoryBuf)
  659. {
  660. int i =0;
  661. for(i=0;i<SENSOR_NUMBERS;i++)
  662. {
  663. if(gSensorHistoryInfo[i].SensorNum == sensorNum)
  664. {
  665. memcpy(phistoryBuf, gSensorHistoryInfo[i].History, HISTORY_DATA_SIZE);
  666. return 0;
  667. }
  668. }
  669. if(i >= SENSOR_NUMBERS)
  670. {
  671. printf("Warning: Can't find sensorNum!\n");
  672. return -1;
  673. }
  674. }
  675. pthread_mutex_t api_bridge_mutex;
  676. int API_BridgeInternal(MsgPkt_T* pReqPkt, MsgPkt_T* pResPkt, uint8_t DestAddr, int Channel)
  677. {
  678. IPMIMsgHdr_T* pReqMsgHdr;
  679. IPMIMsgHdr_T* pResMsgHdr;
  680. uint8_t SeqNum = g_BMCInfo.SendMsgSeqNum;
  681. int RetVal;
  682. int fd_BridgeQue;
  683. uint8_t PBTbl;
  684. pthread_mutex_lock(&api_bridge_mutex);
  685. fd_BridgeQue = open (BRIDGE_QUEUE, O_RDWR);
  686. if(-1 == fd_BridgeQue)
  687. {
  688. printf("%s: Open %s fifo failed! \n", __FUNCTION__, BRIDGE_QUEUE);
  689. close(fd_BridgeQue);
  690. pthread_mutex_unlock(&api_bridge_mutex);
  691. return -1;
  692. }
  693. if(NULL != pReqPkt)
  694. {
  695. memcpy(&(pReqPkt->Data[sizeof(IPMIMsgHdr_T)]), pReqPkt->Data, pReqPkt->Size);
  696. pReqPkt->Size += sizeof(IPMIMsgHdr_T);
  697. pReqMsgHdr = (IPMIMsgHdr_T*)pReqPkt->Data;
  698. }
  699. else
  700. {
  701. printf("Warning: Message Packet to be bridged is NULL\r\n");
  702. close(fd_BridgeQue);
  703. pthread_mutex_unlock(&api_bridge_mutex);
  704. return -1;
  705. }
  706. if(NULL != pResPkt)
  707. {
  708. pResMsgHdr = (IPMIMsgHdr_T*)pResPkt->Data;
  709. }
  710. else
  711. {
  712. printf("Warning: Message Packet to be bridged is NULL\r\n");
  713. close(fd_BridgeQue);
  714. pthread_mutex_unlock(&api_bridge_mutex);
  715. return -1;
  716. }
  717. /* Format IPMI message header */
  718. pReqMsgHdr->ResAddr = DestAddr;
  719. pReqMsgHdr->NetFnLUN = pReqPkt->NetFnLUN;
  720. pReqMsgHdr->ChkSum = ~(pReqMsgHdr->ResAddr + pReqMsgHdr->NetFnLUN) + 1;
  721. if(Channel == PRIMARY_IPMB_CHANNEL)
  722. {
  723. pReqMsgHdr->ReqAddr = g_BMCInfo.PrimaryIPMBAddr; //PRIMARY_IPMB_ADDR;
  724. }
  725. else if(Channel == SECONDARY_IPMB_CHANNEL)
  726. {
  727. pReqMsgHdr->ReqAddr = g_BMCInfo.SecondaryIPMBAddr; //PRIMARY_IPMB_ADDR;
  728. }
  729. else
  730. {
  731. printf ("Warning: Invalid IPMB Channel: %d\r\n", Channel);
  732. pthread_mutex_unlock(&api_bridge_mutex);
  733. close(fd_BridgeQue);
  734. return -1;
  735. }
  736. pResPkt->NetFnLUN = pReqPkt->NetFnLUN + 0x40;
  737. pResPkt->Cmd = pReqPkt->Cmd;
  738. pReqMsgHdr->Cmd = pReqPkt->Cmd;
  739. pResMsgHdr->ResAddr = pReqMsgHdr->ReqAddr;
  740. pResMsgHdr->ChkSum = ~(pResMsgHdr->ResAddr + pResMsgHdr->NetFnLUN) + 1;
  741. pResMsgHdr->ReqAddr = pReqMsgHdr->ResAddr;
  742. pResMsgHdr->RqSeqLUN = pReqMsgHdr->RqSeqLUN;
  743. pResMsgHdr->Cmd = pReqMsgHdr->Cmd;
  744. PBTbl = (Channel == SECONDARY_IPMB_CHANNEL) ? SECONDARY_PB_TBL : PRIMARY_PB_TBL ;
  745. /* Store in the table for response tracking */
  746. while(TRUE)
  747. {
  748. if (FALSE == m_PendingBridgedResTbl[PBTbl][SeqNum].Used)
  749. {
  750. m_PendingBridgedResTbl[PBTbl][SeqNum].TimeOut = DEFAULT_TIMEOUT;
  751. m_PendingBridgedResTbl[PBTbl][SeqNum].ChannelNum = pReqPkt->Channel;
  752. m_PendingBridgedResTbl[PBTbl][SeqNum].OriginSrc = ORIGIN_INT_REQ;
  753. g_BMCInfo.SendMsgSeqNum = SeqNum;
  754. // printf("g_BMCInfo.SendMsgSeqNum %d\n", g_BMCInfo.SendMsgSeqNum);
  755. /* Format Sequence Number */
  756. pReqMsgHdr->RqSeqLUN = ((g_BMCInfo.SendMsgSeqNum) << 2) & 0xFC;
  757. pResMsgHdr->RqSeqLUN = pReqMsgHdr->RqSeqLUN + 0x40;
  758. memcpy (&m_PendingBridgedResTbl[PBTbl][SeqNum].ReqMsgHdr, pReqMsgHdr, sizeof (IPMIMsgHdr_T));
  759. memcpy (&m_PendingBridgedResTbl[PBTbl][SeqNum].ResMsgHdr, pResMsgHdr, sizeof (IPMIMsgHdr_T));
  760. m_PendingBridgedResTbl[PBTbl][SeqNum].DestQ = fd_BridgeQue;
  761. /* Store Session ID for final response to the origin for KCS*/
  762. //m_PendingBridgedResTbl[SeqNum].SrcSessionID = pReqPkt->SessionID;
  763. m_PendingBridgedResTbl[PBTbl][SeqNum].Used = TRUE;
  764. //printf( "---> oemApi.c: Bridged message added index = %d.\n", SeqNum );
  765. break;
  766. }
  767. else
  768. {
  769. SeqNum = (SeqNum + 1) & 0x3F;
  770. if(SeqNum == g_BMCInfo.SendMsgSeqNum)
  771. {
  772. printf ("Warning: Pending Bridge Response Table is full \n");
  773. close(fd_BridgeQue);
  774. pthread_mutex_unlock(&api_bridge_mutex);
  775. return -1;
  776. }
  777. }
  778. }
  779. /* Format message packet */
  780. pReqPkt->Channel = Channel;
  781. pReqPkt->Param = PARAM_BRIDGE;
  782. /* Recalculate the checksum */
  783. pReqPkt->Data [pReqPkt->Size] = CalculateCheckSum2 (pReqPkt->Data, pReqPkt->Size);
  784. pReqPkt->Size++;
  785. if(Channel == PRIMARY_IPMB_CHANNEL)
  786. {
  787. pReqPkt->SrcQ = gFd_PrimaryIpmbIfcQ;
  788. }
  789. else if(Channel == SECONDARY_IPMB_CHANNEL)
  790. {
  791. pReqPkt->SrcQ = gFd_SecondaryIpmbIfcQ;
  792. }
  793. else
  794. {
  795. printf("Warning: Invalid Channel %d\n", Channel);
  796. close(fd_BridgeQue);
  797. pthread_mutex_unlock(&api_bridge_mutex);
  798. return -1;
  799. }
  800. /* Post Message to the bridge queue */
  801. if(0 != PostMsg(pReqPkt->SrcQ, pReqPkt) )
  802. {
  803. printf ("Warning: oemApi.c : Error posting message to Queue %p \n", pReqPkt->SrcQ);
  804. close(fd_BridgeQue);
  805. pthread_mutex_unlock(&api_bridge_mutex);
  806. return -1;
  807. }
  808. m_PendingBridgedResTbl[PBTbl][SeqNum].ResDataOk = 1;
  809. RetVal = GetMsg (fd_BridgeQue, pResPkt, 3); //3s
  810. // int i;
  811. // printf("Bridge recv: ");
  812. // for(i=0;i<pResPkt->Size;i++)
  813. // {
  814. // printf("%#x ", pResPkt->Data[i]);
  815. // }
  816. // printf("\n");
  817. //remove(BRIDGE_QUEUE);
  818. close(fd_BridgeQue);
  819. pthread_mutex_unlock(&api_bridge_mutex);
  820. if(RetVal != 0)
  821. {
  822. return -1;
  823. }
  824. memcpy(pResPkt->Data, &(pResPkt->Data[sizeof(IPMIMsgHdr_T)]), pResPkt->Size - sizeof(IPMIMsgHdr_T)-1);
  825. pResPkt->Size = pResPkt->Size - sizeof(IPMIMsgHdr_T)-1; //remove header & checksum2
  826. return 0;
  827. }
  828. /***************** Flash 保存非易失数据 *******************/
  829. int FlushSDRToFlash()
  830. {
  831. uint32_t writeLen = 0;
  832. uint32_t offset = 0;
  833. uint32_t sdrSize =
  834. sizeof(SDRRepository_T) + sizeof(HdrMgmtCtrlrDevLocator_T) + sizeof(HdrFullSensorRec_T)*SENSOR_NUMBERS;
  835. pthread_mutex_lock(&Flash_Mutex);
  836. while(sdrSize > 0)
  837. {
  838. if(sdrSize > 4*1024)
  839. writeLen = 4*1024;
  840. else
  841. writeLen = sdrSize;
  842. sf_sector_erase(5, SDR_FLASH_ADDR+offset);
  843. sf_write(5, SDR_FLASH_ADDR+offset, g_BMCInfo.pSDR+offset, writeLen);
  844. offset += writeLen;
  845. sdrSize -= writeLen;
  846. }
  847. pthread_mutex_unlock(&Flash_Mutex);
  848. return 0;
  849. }
  850. int GetSDRFromFlash()
  851. {
  852. uint32_t sdrSize =
  853. sizeof(SDRRepository_T) + sizeof(HdrMgmtCtrlrDevLocator_T) + sizeof(HdrFullSensorRec_T)*SENSOR_NUMBERS;
  854. pthread_mutex_lock(&Flash_Mutex);
  855. sf_read(5, SDR_FLASH_ADDR, g_BMCInfo.pSDR, sdrSize);
  856. pthread_mutex_unlock(&Flash_Mutex);
  857. return 0;
  858. }
  859. int FlushSELToFlash()
  860. {
  861. uint32_t writeLen = 0;
  862. uint32_t offset = 0;
  863. uint32_t selSize = sizeof(SELRepository_T) + sizeof(SELRec_T)*MAX_SEL_RECORD ;
  864. pthread_mutex_lock(&Flash_Mutex);
  865. while(selSize > 0)
  866. {
  867. if(selSize > 4*1024)
  868. writeLen = 4*1024;
  869. else
  870. writeLen = selSize;
  871. sf_sector_erase(5, SEL_FLASH_ADDR+offset);
  872. sf_write(5, SEL_FLASH_ADDR+offset, g_BMCInfo.pSEL+offset, writeLen);
  873. offset += writeLen;
  874. selSize -= writeLen;
  875. }
  876. pthread_mutex_unlock(&Flash_Mutex);
  877. return 0;
  878. }
  879. int GetSELFromFlash()
  880. {
  881. uint32_t selSize = sizeof(SELRepository_T) + sizeof(SELRec_T)*MAX_SEL_RECORD ;
  882. pthread_mutex_lock(&Flash_Mutex);
  883. sf_read(5, SEL_FLASH_ADDR, g_BMCInfo.pSEL, selSize);
  884. pthread_mutex_unlock(&Flash_Mutex);
  885. return 0;
  886. }
  887. int FlushIPMIToFlash()
  888. {
  889. uint32_t writeLen = 0;
  890. uint32_t offset = 0;
  891. uint32_t ipmiSize = sizeof(IPMIConfig_T);
  892. pthread_mutex_lock(&Flash_Mutex);
  893. while(ipmiSize > 0)
  894. {
  895. if(ipmiSize > 4*1024)
  896. writeLen = 4*1024;
  897. else
  898. writeLen = ipmiSize;
  899. sf_sector_erase(5, IPMI_CFG_FLASH_ADDR+offset);
  900. sf_write(5, IPMI_CFG_FLASH_ADDR+offset, ((uint8_t*)&g_BMCInfo.IpmiConfig)+offset, writeLen);
  901. offset += writeLen;
  902. ipmiSize -= writeLen;
  903. }
  904. pthread_mutex_unlock(&Flash_Mutex);
  905. return 0;
  906. }
  907. int GetIPMIFromFlash()
  908. {
  909. uint32_t ipmiSize = sizeof(IPMIConfig_T);
  910. pthread_mutex_lock(&Flash_Mutex);
  911. sf_read(5, IPMI_CFG_FLASH_ADDR, (uint8_t*)&g_BMCInfo.IpmiConfig, ipmiSize);
  912. pthread_mutex_unlock(&Flash_Mutex);
  913. return 0;
  914. }
  915. int FlushFRUToFlash()
  916. {
  917. uint32_t fruSize = sizeof(OemFRUData_T);
  918. pthread_mutex_lock(&Flash_Mutex);
  919. sf_sector_erase(5, FRU_FLASH_ADDR);
  920. sf_write(5, FRU_FLASH_ADDR, (uint8_t*)&g_BMCInfo.FRU, fruSize);
  921. pthread_mutex_unlock(&Flash_Mutex);
  922. return 0;
  923. }
  924. int GetFRUFromFlash()
  925. {
  926. uint32_t fruSize = sizeof(OemFRUData_T);
  927. pthread_mutex_lock(&Flash_Mutex);
  928. sf_read(5, FRU_FLASH_ADDR, (uint8_t*)&g_BMCInfo.FRU, fruSize);
  929. pthread_mutex_unlock(&Flash_Mutex);
  930. return 0;
  931. }
  932. int FlushSensorHistoryToFlash()
  933. {
  934. uint32_t writeLen = 0;
  935. uint32_t offset = 0;
  936. uint32_t sensorSize = SENSOR_NUMBERS*sizeof(SensorHistoryInfo_T);
  937. pthread_mutex_lock(&Flash_Mutex);
  938. while(sensorSize > 0)
  939. {
  940. if(sensorSize > 4*1024)
  941. writeLen = 4*1024;
  942. else
  943. writeLen = sensorSize;
  944. sf_sector_erase(5, SENSOR_HISTORY_FLASH_ADDR+offset);
  945. sf_write(5, SENSOR_HISTORY_FLASH_ADDR+offset, ((uint8_t*)gSensorHistoryInfo)+offset, writeLen);
  946. offset += writeLen;
  947. sensorSize -= writeLen;
  948. }
  949. pthread_mutex_unlock(&Flash_Mutex);
  950. return 0;
  951. }
  952. int GetSensorHistoryFromFlash()
  953. {
  954. uint32_t sensorSize = SENSOR_NUMBERS*sizeof(SensorHistoryInfo_T);
  955. pthread_mutex_lock(&Flash_Mutex);
  956. sf_read(5, SENSOR_HISTORY_FLASH_ADDR, (uint8_t*)gSensorHistoryInfo, sensorSize);
  957. pthread_mutex_unlock(&Flash_Mutex);
  958. return 0;
  959. }
  960. int FlushUserInfoTbl(void)
  961. {
  962. pthread_mutex_lock(&Flash_Mutex);
  963. sf_sector_erase(5, USERTBL_FLASH_ADDR);
  964. sf_write(5, USERTBL_FLASH_ADDR, (uint8_t*)g_BMCInfo.UserInfoTbl, sizeof(UserInfo_T)*MAX_USER_NUM);
  965. pthread_mutex_unlock(&Flash_Mutex);
  966. return 0;
  967. }
  968. int UpdateUserInfoTble(void)
  969. {
  970. pthread_mutex_lock(&Flash_Mutex);
  971. sf_read(5, USERTBL_FLASH_ADDR, (uint8_t*)g_BMCInfo.UserInfoTbl, sizeof(UserInfo_T)*MAX_USER_NUM);
  972. pthread_mutex_unlock(&Flash_Mutex);
  973. return 0;
  974. }
  975. int UpdateFlash(void)
  976. {
  977. FlushSDRToFlash();
  978. FlushSELToFlash();
  979. FlushIPMIToFlash();
  980. FlushFRUToFlash();
  981. return 0;
  982. }
  983. int InitChannelTab(void)
  984. {
  985. int i;
  986. //primary IPMB channel
  987. g_BMCInfo.ChannelTab[0].ChannelNumber = 0;
  988. g_BMCInfo.ChannelTab[0].ChannelProtocol = 1;//Used for IPMB, serial/modem Basic Mode, and LAN.reference IPMIv2.0 Table 6-2
  989. g_BMCInfo.ChannelTab[0].ChannelMedium = 1; //IPMB, reference IPMIv2.0 Table 6-3
  990. g_BMCInfo.ChannelTab[0].SessionSupport = 0; //session less
  991. g_BMCInfo.ChannelTab[0].ActiveSession = 0;
  992. g_BMCInfo.ChannelTab[0].ProtocolVendorId[0] = 0x12;
  993. g_BMCInfo.ChannelTab[0].ProtocolVendorId[1] = 0x34;
  994. g_BMCInfo.ChannelTab[0].ProtocolVendorId[2] = 0x56;
  995. g_BMCInfo.ChannelTab[0].AuxiliaryInfo[0] = 0xff;
  996. g_BMCInfo.ChannelTab[0].AuxiliaryInfo[1] = 0xff;
  997. //LAN chennel
  998. g_BMCInfo.ChannelTab[1].ChannelNumber = 1;
  999. g_BMCInfo.ChannelTab[1].ChannelProtocol = 1;//Used for IPMB, serial/modem Basic Mode, and LAN.reference IPMIv2.0 Table 6-2
  1000. g_BMCInfo.ChannelTab[1].ChannelMedium = 4; //802.3 LAN, reference IPMIv2.0 Table 6-3
  1001. g_BMCInfo.ChannelTab[1].SessionSupport = 2; //muti session
  1002. g_BMCInfo.ChannelTab[1].ActiveSession = 0;
  1003. g_BMCInfo.ChannelTab[1].ProtocolVendorId[0] = 0x12;
  1004. g_BMCInfo.ChannelTab[1].ProtocolVendorId[1] = 0x34;
  1005. g_BMCInfo.ChannelTab[1].ProtocolVendorId[2] = 0x56;
  1006. g_BMCInfo.ChannelTab[1].AuxiliaryInfo[0] = 0xff;
  1007. g_BMCInfo.ChannelTab[1].AuxiliaryInfo[1] = 0xff;
  1008. //Secondary IPMB channel
  1009. g_BMCInfo.ChannelTab[2].ChannelNumber = 6;
  1010. g_BMCInfo.ChannelTab[2].ChannelProtocol = 1;//Used for IPMB, serial/modem Basic Mode, and LAN.reference IPMIv2.0 Table 6-2
  1011. g_BMCInfo.ChannelTab[2].ChannelMedium = 1; //IPMB, reference IPMIv2.0 Table 6-3
  1012. g_BMCInfo.ChannelTab[2].SessionSupport = 0; //session less
  1013. g_BMCInfo.ChannelTab[2].ActiveSession = 0;
  1014. g_BMCInfo.ChannelTab[2].ProtocolVendorId[0] = 0x12;
  1015. g_BMCInfo.ChannelTab[2].ProtocolVendorId[1] = 0x34;
  1016. g_BMCInfo.ChannelTab[2].ProtocolVendorId[2] = 0x56;
  1017. g_BMCInfo.ChannelTab[2].AuxiliaryInfo[0] = 0xff;
  1018. g_BMCInfo.ChannelTab[2].AuxiliaryInfo[1] = 0xff;
  1019. for(i=3;i<15;i++)
  1020. {
  1021. g_BMCInfo.ChannelTab[i].ChannelNumber = 0xf;
  1022. }
  1023. }
  1024. ChannelInfo_T* getChannelInfo(uint8_t ChannelNum)
  1025. {
  1026. int i;
  1027. for(i=0;i<15;i++)
  1028. {
  1029. if(g_BMCInfo.ChannelTab[i].ChannelNumber == ChannelNum)
  1030. {
  1031. return (ChannelInfo_T*)&g_BMCInfo.ChannelTab[i];
  1032. }
  1033. }
  1034. return NULL;
  1035. }