Api.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  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. int InitSdrConfig(void)
  18. {
  19. printf("Init SDR Config...\r\n");
  20. g_BMCInfo.SDRConfig.SDRError = 0;
  21. g_BMCInfo.SDRConfig.UpdatingSDR = FALSE;
  22. g_BMCInfo.SDRConfig.UpdatingChannel = 0;
  23. g_BMCInfo.SDRConfig.TrackPOffset = 0;
  24. g_BMCInfo.SDRConfig.TrackRecID = 0;
  25. g_BMCInfo.SDRConfig.ReservationID = 0;
  26. g_BMCInfo.SDRConfig.IPMB_Seqnum = 0;
  27. g_BMCInfo.SDRConfig.PartAddbytes = 0;
  28. g_BMCInfo.SDRConfig.LatestRecordID = 0;
  29. g_BMCInfo.SDRConfig.NumMarkedRecords = 0;
  30. g_BMCInfo.SDRConfig.SDRRAM = (SDRRepository_T*)g_BMCInfo.pSDR;
  31. g_BMCInfo.SDRConfig.RepositoryInfo.Version = 0x51;
  32. g_BMCInfo.SDRConfig.RepositoryInfo.RecCt = ((SDRRepository_T*)g_BMCInfo.SDRConfig.SDRRAM)->NumRecords;
  33. g_BMCInfo.SDRConfig.RepositoryInfo.FreeSpace = 0xffff;
  34. g_BMCInfo.SDRConfig.RepositoryInfo.AddTimeStamp = 0;
  35. g_BMCInfo.SDRConfig.RepositoryInfo.EraseTimeStamp = 0;
  36. g_BMCInfo.SDRConfig.RepositoryInfo.OpSupport = 0x23;
  37. //TODO:
  38. g_BMCInfo.SDRConfig.RepositoryAllocInfo.NumAllocUnits = MAX_SENSOR_NUMBERS+1;
  39. g_BMCInfo.SDRConfig.RepositoryAllocInfo.AllocUnitSize = SDR_ALLOC_UNIT_SIZE;
  40. g_BMCInfo.SDRConfig.RepositoryAllocInfo.NumFreeAllocUnits = MAX_SENSOR_NUMBERS - SENSOR_NUMBERS;
  41. g_BMCInfo.SDRConfig.RepositoryAllocInfo.LargestFreeBlock = SDR_MAX_RECORD_SIZE;
  42. g_BMCInfo.SDRConfig.RepositoryAllocInfo.MaxRecSize = SDR_MAX_RECORD_SIZE; //Maximum record size in allocation units
  43. return 0;
  44. }
  45. int InitSelConfig(void)
  46. {
  47. printf("InitSelConfig...\n");
  48. g_BMCInfo.SELConfig.SelReservationID = 0;;
  49. g_BMCInfo.SELConfig.LastEvtTS = 0;
  50. g_BMCInfo.SELConfig.PartialAddRecordID = 0;
  51. g_BMCInfo.SELConfig.PartialAddRecOffset = 0;
  52. g_BMCInfo.SELConfig.PartialAdd = 0;
  53. g_BMCInfo.SELConfig.SenMonSELFlag = 0;
  54. g_BMCInfo.SELConfig.MaxSELRecord = MAX_SEL_RECORD;
  55. // g_BMCInfo.SELConfig.RsrvIDCancelled = FALSE;
  56. g_BMCInfo.SELConfig.SELOverFlow = FALSE;
  57. g_BMCInfo.SELConfig.selalmostfull = 0;
  58. // SELEventRecord_T SelPartialAddRecord;
  59. // g_BMCInfo.SELConfig.SELEventMsg [16];
  60. return 0;
  61. }
  62. int PlatformInit(void)
  63. {
  64. uint8_t PrimaryIPMBBusNum, SecondaryIPMBBusNum;
  65. printf("Init Platform...\r\n");
  66. // //hardware init
  67. // GPIO_InitTypeDef GPIO_InitStruct;
  68. // GPIO_InitStruct.Pin = GA0_PIN | GA1_PIN | GA2_PIN | GA3_PIN | GA4_PIN | RACKID2_PIN;
  69. // GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  70. // GPIO_InitStruct.Pull = GPIO_NOPULL;
  71. // GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  72. // stm32_gpio_init(GPIOH, &GPIO_InitStruct);
  73. // GPIO_InitStruct.Pin = GAP_PIN | RACKID1_PIN | RACKID3_PIN | RACKID4_PIN | RACKID5_PIN;
  74. // stm32_gpio_init(GPIOI, &GPIO_InitStruct);
  75. g_BMCInfo.SelfTestByte = 0;
  76. g_BMCInfo.SlotID = PDK_GetSlotID();
  77. g_BMCInfo.ChassisID = PDK_GetChassisID();
  78. //机箱及刀片信息
  79. g_BMCInfo.ChassisIdentify = FALSE;
  80. g_BMCInfo.PowerGoodFlag = 1;
  81. g_BMCInfo.BladeManageEn = 0;
  82. g_BMCInfo.isChMC = 0;
  83. g_BMCInfo.IndexInChassis = 1;
  84. gBladeStatus[g_BMCInfo.IndexInChassis].slotID = g_BMCInfo.SlotID;
  85. //init DevGUID
  86. g_BMCInfo.DeviceGUID[0] = 0x01;
  87. g_BMCInfo.DeviceGUID[1] = 0x01;
  88. g_BMCInfo.DeviceGUID[2] = 0x01;
  89. g_BMCInfo.DeviceGUID[3] = 0x01;
  90. g_BMCInfo.DeviceGUID[4] = 0x01;
  91. g_BMCInfo.DeviceGUID[5] = 0x01;
  92. g_BMCInfo.DeviceGUID[6] = 0x01;
  93. g_BMCInfo.DeviceGUID[7] = 0x01;
  94. g_BMCInfo.DeviceGUID[8] = 0x01;
  95. g_BMCInfo.DeviceGUID[9] = 0x01;
  96. g_BMCInfo.DeviceGUID[10] = 0x01;
  97. g_BMCInfo.DeviceGUID[11] = 0x01;
  98. g_BMCInfo.DeviceGUID[12] = 0x01;
  99. g_BMCInfo.DeviceGUID[13] = 0x01;
  100. g_BMCInfo.DeviceGUID[14] = 0x01;
  101. g_BMCInfo.DeviceGUID[15] = 0x01;
  102. g_BMCInfo.FwMajorVer = FW_VERSION_MAJOR;
  103. g_BMCInfo.FwMinorVer = FW_VERSION_MINOR;
  104. g_BMCInfo.SendMsgSeqNum = 0;
  105. // g_BMCInfo.OemFlags.BladeWorkMode = BLADE_IPMC;
  106. // g_BMCInfo.OemFlags.chassisManageFnEnable = 0;
  107. // g_BMCInfo.OemFlags.thisBladeIndex = 0;
  108. // g_BMCInfo.OemFlags.bladeStatus = 1; //0: not present, 1: normal, 2: error, others: reserved.
  109. g_BMCInfo.HealthLevel = SENSOR_STATUS_NORMAL;
  110. g_BMCInfo.SensorSharedMem.SensorTick= 0;
  111. g_BMCInfo.SenConfig.PowerOnTick = 0;
  112. g_BMCInfo.SenConfig.SysResetTick = 0;
  113. g_BMCInfo.CurTimerTick = 0;
  114. g_BMCInfo.CurTimerSecond = 0;
  115. g_BMCInfo.BootValidMinutes = 0;
  116. g_BMCInfo.m_Lan_SetInProgress = 0;
  117. return 0;
  118. }
  119. int InitTimerTaskTbl(void)
  120. {
  121. printf("InitTimerTaskTbl...\n");
  122. g_BMCInfo.TimerTaskTblSize = 2;
  123. memcpy(g_BMCInfo.TimerTaskTbl, m_TimerTaskTbl, sizeof(TimerTaskTbl_T)*g_BMCInfo.TimerTaskTblSize);
  124. }
  125. int Init_SessionTbl(void)
  126. {
  127. printf("Init_SessionTbl...\n");
  128. g_BMCInfo.SessionHandle = 0;
  129. g_BMCInfo.UDSSessionHandle = 0;
  130. g_BMCInfo.IpmiConfig.MaxSession = 10;
  131. g_BMCInfo.IpmiConfig.SessionTimeOut = 10; //10s
  132. g_BMCInfo.IpmiConfig.SendMsgTimeout = 10; //10s
  133. /*Allocating Memory to hold session Table informations */
  134. g_BMCInfo.SessionTblInfo.SessionTbl = (SessionInfo_T *) malloc(sizeof(SessionInfo_T)*( g_BMCInfo.IpmiConfig.MaxSession + 1));
  135. if(g_BMCInfo.SessionTblInfo.SessionTbl == NULL)
  136. {
  137. printf("Error in allocating memory for SessionTbl \n");
  138. return 1;
  139. }
  140. g_BMCInfo.SessionTblInfo.Count = 0;
  141. /*Initialize the Session Table memory */
  142. memset(g_BMCInfo.SessionTblInfo.SessionTbl,0,sizeof(SessionInfo_T)*(g_BMCInfo.IpmiConfig.MaxSession + 1));
  143. /*Allocating Memory to hold UDS session Table informations */
  144. g_BMCInfo.UDSSessionTblInfo.UDSSessionTbl = (UDSSessionTbl_T *) malloc(sizeof(UDSSessionTbl_T)*(g_BMCInfo.IpmiConfig.MaxSession + 1));
  145. if(g_BMCInfo.UDSSessionTblInfo.UDSSessionTbl == NULL)
  146. {
  147. printf("Error in allocating memory for SessionTbl \n");
  148. return 1;
  149. }
  150. g_BMCInfo.UDSSessionTblInfo.SessionCount = 0;
  151. /*Initialize the UDS Session Table memory */
  152. memset(g_BMCInfo.UDSSessionTblInfo.UDSSessionTbl,0,sizeof(UDSSessionTbl_T)*(g_BMCInfo.IpmiConfig.MaxSession + 1));
  153. }
  154. const char FirstPowerOnStr[] = "First power on the bmc";
  155. int Init_IPMI_FRU_SDR_SEL(void)
  156. {
  157. int i;
  158. uint32_t sdrSize =
  159. sizeof(SDRRepository_T) + sizeof(HdrMgmtCtrlrDevLocator_T) + sizeof(HdrFullSensorRec_T)*SENSOR_NUMBERS;
  160. uint32_t selSize = sizeof(SELRepository_T) + sizeof(SELRec_T)*MAX_SEL_RECORD ;
  161. uint8_t* pSDR = NULL;
  162. uint8_t* pSEL = NULL;
  163. g_BMCInfo.pSDR = malloc(sdrSize);
  164. if((g_BMCInfo.pSDR == NULL) && (sdrSize != 0))
  165. {
  166. printf("g_BMCInfo.pSDR Malloc failed!\r\n");
  167. }
  168. g_BMCInfo.pSEL = malloc(selSize);
  169. if((g_BMCInfo.pSEL == NULL) && (selSize != 0))
  170. {
  171. printf("g_BMCInfo.pSEL Malloc failed!\r\n");
  172. }
  173. // FLASH_GetIPMI(&g_BMCInfo.IpmiConfig);
  174. // if(strncmp(g_BMCInfo.IpmiConfig.FirstPowerOnStr, FirstPowerOnStr, sizeof(FirstPowerOnStr)) != 0)
  175. if(1)
  176. {
  177. //first power on
  178. printf("BMC first power on!\r\n");
  179. /************************** Init IPMI ******************************/
  180. memcpy(g_BMCInfo.IpmiConfig.FirstPowerOnStr, FirstPowerOnStr, sizeof(FirstPowerOnStr));
  181. g_BMCInfo.IpmiConfig.SerialIfcSupport = SERIAL_IFC_SUPPORT;
  182. g_BMCInfo.IpmiConfig.SerialTerminalSupport = SERIAL_TERMINAL_SUPPORT;
  183. g_BMCInfo.IpmiConfig.LANIfcSupport = LAN_IFC_SUPPORT;
  184. g_BMCInfo.IpmiConfig.SYSIfcSupport = SYS_IFC_SUPPORT;
  185. g_BMCInfo.IpmiConfig.GrpExtnSupport = GROUP_EXTERN_SUPPORT;
  186. g_BMCInfo.IpmiConfig.UDSIfcSupport = UDS_IFC_SUPPORT;
  187. g_BMCInfo.IpmiConfig.ChassisTimerInterval = CHASSIS_TIMER_INTERVAL;
  188. g_BMCInfo.IpmiConfig.PowerCycleInterval = PWR_CYCLE_INTERVAL;
  189. g_BMCInfo.IpmiConfig.FanControlInterval = FAN_CONTROL_INTERVAL;
  190. g_BMCInfo.IpmiConfig.RearmSetSensorThreshold = REARM_SET_SENSOR_THRESHOLD;
  191. g_BMCInfo.IpmiConfig.SELTimeUTCOffset = 8*60;
  192. //IPMB
  193. g_BMCInfo.IpmiConfig.PrimaryIPMBSupport = PRIMARY_IPMB_SUPPORT;
  194. g_BMCInfo.IpmiConfig.SecondaryIPMBSupport = SECONDARY_IPMB_SUPPORT;
  195. g_BMCInfo.IpmiConfig.PrimaryIPMBBus = PRIMARY_IPMB_BUS;
  196. g_BMCInfo.IpmiConfig.SecondaryIPMBBus = SECONDARY_IPMB_BUS;
  197. g_BMCInfo.IpmiConfig.PrimaryIPMBAddr = PRIMARY_IPMB_ADDR;
  198. g_BMCInfo.IpmiConfig.SecondaryIPMBAddr = SECONDARY_IPMB_ADDR;
  199. //LAN
  200. strcpy(g_BMCInfo.IpmiConfig.LanInfo[0].EthName, "eth0");
  201. g_BMCInfo.IpmiConfig.LanInfo[0].IPAddrSrc = 0x01; //static
  202. g_BMCInfo.IpmiConfig.LanInfo[0].IPAddr[0] = 192;
  203. g_BMCInfo.IpmiConfig.LanInfo[0].IPAddr[1] = 168;
  204. g_BMCInfo.IpmiConfig.LanInfo[0].IPAddr[2] = 0;
  205. g_BMCInfo.IpmiConfig.LanInfo[0].IPAddr[3] = 208;
  206. g_BMCInfo.IpmiConfig.LanInfo[0].BroadCast[0] = 192;
  207. g_BMCInfo.IpmiConfig.LanInfo[0].BroadCast[1] = 168;
  208. g_BMCInfo.IpmiConfig.LanInfo[0].BroadCast[2] = 0;
  209. g_BMCInfo.IpmiConfig.LanInfo[0].BroadCast[3] = 255;
  210. g_BMCInfo.IpmiConfig.LanInfo[0].NetMask[0] = 255;
  211. g_BMCInfo.IpmiConfig.LanInfo[0].NetMask[1] = 255;
  212. g_BMCInfo.IpmiConfig.LanInfo[0].NetMask[2] = 255;
  213. g_BMCInfo.IpmiConfig.LanInfo[0].NetMask[3] = 0;
  214. g_BMCInfo.IpmiConfig.LanInfo[0].DefaultGW[0] = 192;
  215. g_BMCInfo.IpmiConfig.LanInfo[0].DefaultGW[1] = 168;
  216. g_BMCInfo.IpmiConfig.LanInfo[0].DefaultGW[2] = 0;
  217. g_BMCInfo.IpmiConfig.LanInfo[0].DefaultGW[3] = 1;
  218. g_BMCInfo.IpmiConfig.LanInfo[0].MACAddr[0] = 0xC0;
  219. g_BMCInfo.IpmiConfig.LanInfo[0].MACAddr[1] = 0xB1;
  220. g_BMCInfo.IpmiConfig.LanInfo[0].MACAddr[2] = 0x3C;
  221. g_BMCInfo.IpmiConfig.LanInfo[0].MACAddr[3] = 0x88;
  222. g_BMCInfo.IpmiConfig.LanInfo[0].MACAddr[4] = 0x88;
  223. g_BMCInfo.IpmiConfig.LanInfo[0].MACAddr[5] = 0x85;
  224. //Init FRU
  225. memcpy(&g_BMCInfo.FRU, &Default_FRUData, sizeof(OemFRUData_T));
  226. /************************ Init SDR *************************************/
  227. pSDR = g_BMCInfo.pSDR;
  228. //init SDR repository header
  229. ((SDRRepository_T*)pSDR)->Signature[0] = 0x00;
  230. ((SDRRepository_T*)pSDR)->Signature[1] = 0x11;
  231. ((SDRRepository_T*)pSDR)->Signature[2] = 0x22;
  232. ((SDRRepository_T*)pSDR)->Signature[3] = 0x33;
  233. ((SDRRepository_T*)pSDR)->NumRecords = SENSOR_NUMBERS + 1;
  234. ((SDRRepository_T*)pSDR)->Size = sdrSize;
  235. ((SDRRepository_T*)pSDR)->AddTimeStamp = 0;
  236. ((SDRRepository_T*)pSDR)->EraseTimeStamp = 0;
  237. //init MgmtCtrlrDevLocator SDR
  238. pSDR += sizeof(SDRRepository_T);
  239. ((HdrMgmtCtrlrDevLocator_T*)pSDR)->Valid = 1;
  240. ((HdrMgmtCtrlrDevLocator_T*)pSDR)->Len = sizeof(HdrMgmtCtrlrDevLocator_T);
  241. memcpy(&(((HdrMgmtCtrlrDevLocator_T*)pSDR)->MgmtCtrlrDevLocator), &bmc_sdr, sizeof(MgmtCtrlrDevLocator_T));
  242. //init FullSensorRec SDR
  243. pSDR += sizeof(HdrMgmtCtrlrDevLocator_T);
  244. for(i=0;i<SENSOR_NUMBERS;i++)
  245. {
  246. ((HdrFullSensorRec_T*)pSDR)->Valid = 1;
  247. ((HdrFullSensorRec_T*)pSDR)->Len = sizeof(HdrFullSensorRec_T);
  248. memcpy(&(((HdrFullSensorRec_T*)pSDR)->FullSensorRec), &full_sdr_tbl[i], sizeof(FullSensorRec_T));
  249. pSDR += sizeof(HdrFullSensorRec_T);
  250. }
  251. /******************************* Init SEL *************************************/
  252. pSEL = g_BMCInfo.pSEL;
  253. ((SELRepository_T*)pSEL)->Signature[0] = 0x00;
  254. ((SELRepository_T*)pSEL)->Signature[1] = 0x11;
  255. ((SELRepository_T*)pSEL)->Signature[2] = 0x22;
  256. ((SELRepository_T*)pSEL)->Signature[3] = 0x33;
  257. ((SELRepository_T*)pSEL)->NumRecords = 0;
  258. ((SELRepository_T*)pSEL)->Padding = 0;
  259. ((SELRepository_T*)pSEL)->AddTimeStamp = 0;
  260. ((SELRepository_T*)pSEL)->EraseTimeStamp = 0;
  261. ((SELRepository_T*)pSEL)->FirstRecID = 0;
  262. ((SELRepository_T*)pSEL)->LastRecID = 0;
  263. ((SELRepository_T*)pSEL)->SELIndex = 0;
  264. ((SELRepository_T*)pSEL)->SELRecord = (SELRec_T*)(pSEL + sizeof(SELRepository_T));
  265. UpdateFlash();
  266. }
  267. else
  268. {
  269. // //Init FRU
  270. // FLASH_GetFRU(&g_BMCInfo.FRU);
  271. // //Init SDR
  272. // FLASH_GetSDR(g_BMCInfo.pSDR, sdrSize);
  273. // //Init SEL
  274. // FLASH_GetSEL(g_BMCInfo.pSEL, selSize);
  275. }
  276. return 0;
  277. }
  278. int Init_UserInfoTbl(void)
  279. {
  280. int i;
  281. if(1) //first power on
  282. {
  283. memset(g_BMCInfo.UserInfoTbl, 0x0, sizeof(UserInfo_T)*MAX_USER_NUM);
  284. g_BMCInfo.UserInfoTbl[2].UserId = 3;
  285. strcpy(g_BMCInfo.UserInfoTbl[2].UserName, "admin");
  286. strcpy(g_BMCInfo.UserInfoTbl[2].UserPassword, "admin");
  287. g_BMCInfo.UserInfoTbl[2].UserStatus = TRUE;
  288. g_BMCInfo.CurrentNoUser = 1;
  289. g_BMCInfo.pUserInfo = NULL;
  290. FlushUserInfoTbl();
  291. }
  292. else
  293. {
  294. UpdateUserInfoTble();
  295. g_BMCInfo.CurrentNoUser = 0;
  296. for(i=0;i<MAX_USER_NUM;i++)
  297. {
  298. if((g_BMCInfo.UserInfoTbl[i].UserId != 0) && (g_BMCInfo.UserInfoTbl[i].UserStatus == TRUE))
  299. g_BMCInfo.CurrentNoUser++;
  300. }
  301. g_BMCInfo.pUserInfo = NULL;
  302. }
  303. }
  304. int UpdateFlash(void)
  305. {
  306. //TODO:
  307. return 0;
  308. }
  309. int SetSysTime(uint32_t *timeSecond)
  310. {
  311. time_t tt;
  312. tt = *timeSecond;
  313. stime(&tt); //TODO:注意时区
  314. return 0;
  315. }
  316. long int GetSysTime(void)
  317. {
  318. time_t tt;
  319. time(&tt);
  320. //TODO: 注意时区
  321. //tt += 8*60*60; UTC+8
  322. return tt;
  323. }
  324. int PostEventMessage (uint8_t *EventMsg,uint8_t size)
  325. {
  326. uint8_t SelReq [sizeof(SELEventRecord_T)];
  327. uint8_t SelRes [sizeof(AddSELRes_T)];
  328. SELEventRecord_T* SelRecord = ( SELEventRecord_T*) SelReq;
  329. SelRecord->hdr.Type = 0x02;
  330. SelRecord->hdr.TimeStamp = GetSysTime ();
  331. memcpy (SelRecord->GenID, EventMsg, size);
  332. LockedAddSELEntry(SelReq, sizeof (SELEventRecord_T), SelRes);
  333. return 0;
  334. }
  335. uint8_t PDK_GetSlotID(void)
  336. {
  337. // uint8_t SlotID = 0;
  338. // uint8_t check = 0;
  339. // if(stm32_gpio_read(GA0_PORT, GA0_PIN) == GPIO_PIN_RESET)
  340. // SlotID |= 0x01;
  341. // if(stm32_gpio_read(GA1_PORT, GA1_PIN) == GPIO_PIN_RESET)
  342. // SlotID |= 0x02;
  343. // if(stm32_gpio_read(GA2_PORT, GA2_PIN) == GPIO_PIN_RESET)
  344. // SlotID |= 0x04;
  345. // if(stm32_gpio_read(GA3_PORT, GA3_PIN) == GPIO_PIN_RESET)
  346. // SlotID |= 0x08;
  347. // if(stm32_gpio_read(GA4_PORT, GA4_PIN) == GPIO_PIN_RESET)
  348. // SlotID |= 0x10;
  349. // if(stm32_gpio_read(GAP_PORT, GAP_PIN) == GPIO_PIN_RESET)
  350. // SlotID |= 0x20;
  351. // int i;
  352. // for(i=0;i<6;i++)
  353. // check ^= (SlotID>>i)&0x01;
  354. // if(check == 0)
  355. // printf("Slot ID check error! GAP = %#x, GA[4:0] = %#x.\n", (SlotID>>5), (SlotID&0x1f));
  356. // return SlotID&0x1f;
  357. return 2;
  358. }
  359. uint8_t PDK_GetChassisID(void)
  360. {
  361. uint8_t ChassisID = 0;
  362. if(stm32_gpio_read(RACKID0_PORT, RACKID0_PIN) == GPIO_PIN_SET)
  363. ChassisID |= 0x01;
  364. if(stm32_gpio_read(RACKID1_PORT, RACKID1_PIN) == GPIO_PIN_SET)
  365. ChassisID |= 0x02;
  366. if(stm32_gpio_read(RACKID2_PORT, RACKID2_PIN) == GPIO_PIN_SET)
  367. ChassisID |= 0x04;
  368. if(stm32_gpio_read(RACKID3_PORT, RACKID3_PIN) == GPIO_PIN_SET)
  369. ChassisID |= 0x08;
  370. if(stm32_gpio_read(RACKID4_PORT, RACKID4_PIN) == GPIO_PIN_SET)
  371. ChassisID |= 0x10;
  372. if(stm32_gpio_read(RACKID5_PORT, RACKID5_PIN) == GPIO_PIN_SET)
  373. ChassisID |= 0x20;
  374. return ChassisID;
  375. }
  376. int PDK_PowerOffChassis(void)
  377. {
  378. printf("Api power off chassis\n");
  379. g_BMCInfo.PowerGoodFlag = 0;
  380. }
  381. int PDK_PowerOnChassis(void)
  382. {
  383. printf("power on chassis\n");
  384. g_BMCInfo.PowerGoodFlag = 1;
  385. }
  386. int PDK_SoftOffChassis(void)
  387. {
  388. printf("soft off chassis\n");
  389. g_BMCInfo.PowerGoodFlag = 0;
  390. }
  391. int PDK_PowerCycleChassis(void)
  392. {
  393. printf("power cycle chassis\n");
  394. }
  395. int PDK_ResetChassis(void)
  396. {
  397. printf("power reset chassis\n");
  398. }
  399. int PDK_DiagInterruptChassis(void)
  400. {
  401. printf("power diag chassis\n");
  402. }
  403. int PDK_FanControl(void)
  404. {
  405. ;
  406. }
  407. //设置IP地址
  408. /*
  409. * 函数名称 : int setip(char *ip)
  410. * 函数功能 : 设置系统IP地址
  411. * 参 数 :
  412. *char *ip :设置的IP地址,以点分十进制的字符串方式表示,如“192.168.0.5”
  413. * 返 回 值 : 0 : 成功 ; -1 : 失败
  414. */
  415. int setip(char *ip)
  416. {
  417. struct ifreq temp;
  418. struct sockaddr_in *addr;
  419. int fd = 0;
  420. int ret = -1;
  421. strcpy(temp.ifr_name, "eth0");
  422. if((fd=socket(AF_INET, SOCK_STREAM, 0))<0)
  423. {
  424. return -1;
  425. }
  426. addr = (struct sockaddr_in *)&(temp.ifr_addr);
  427. addr->sin_family = AF_INET;
  428. addr->sin_addr.s_addr = inet_addr(ip);
  429. ret = ioctl(fd, SIOCSIFADDR, &temp);
  430. close(fd);
  431. if(ret < 0)
  432. return -1;
  433. return 0;
  434. }
  435. //获取IP地址
  436. /*
  437. * 函数名称 : char * getip(char *ip_buf)
  438. * 函数功能 : 获取系統IP地址
  439. * 参 数 :
  440. *char *ip_buf :用来存放IP地址的内存空间
  441. * 返 回 值 : ip_buf : 存放IP地址的内存地址
  442. */
  443. char* getip(char *ip_buf)
  444. {
  445. struct ifreq temp;
  446. struct sockaddr_in *myaddr;
  447. int fd = 0;
  448. int ret = -1;
  449. strcpy(temp.ifr_name, "eth0");
  450. if((fd=socket(AF_INET, SOCK_STREAM, 0))<0)
  451. {
  452. return NULL;
  453. }
  454. ret = ioctl(fd, SIOCGIFADDR, &temp);
  455. close(fd);
  456. if(ret < 0)
  457. return NULL;
  458. myaddr = (struct sockaddr_in *)&(temp.ifr_addr);
  459. strcpy(ip_buf, (char*)inet_ntoa(myaddr->sin_addr));
  460. return ip_buf;
  461. }
  462. char* getnetmask(char *netmask_buf)
  463. {
  464. struct ifreq temp;
  465. struct sockaddr_in *myaddr;
  466. int fd = 0;
  467. int ret = -1;
  468. strcpy(temp.ifr_name, "eth0");
  469. if((fd=socket(AF_INET, SOCK_STREAM, 0))<0)
  470. {
  471. return NULL;
  472. }
  473. ret = ioctl(fd, SIOCGIFNETMASK, &temp);
  474. close(fd);
  475. if(ret < 0)
  476. return NULL;
  477. myaddr = (struct sockaddr_in *)&(temp.ifr_addr);
  478. strcpy(netmask_buf, (char*)inet_ntoa(myaddr->sin_addr));
  479. return netmask_buf;
  480. }
  481. char* getmac(char *mac_buf)
  482. {
  483. struct ifreq temp;
  484. struct sockaddr_in *myaddr;
  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 NULL;
  491. }
  492. if(ioctl(fd,SIOCGIFHWADDR,&temp)<0)
  493. {
  494. printf("Get mac address ioctl fail!\n");
  495. }
  496. else
  497. {
  498. sprintf(mac_buf, "%02x:%02x:%02x:%02x:%02x:%02x\n",
  499. (unsigned char)temp.ifr_hwaddr.sa_data[0],
  500. (unsigned char)temp.ifr_hwaddr.sa_data[1],
  501. (unsigned char)temp.ifr_hwaddr.sa_data[2],
  502. (unsigned char)temp.ifr_hwaddr.sa_data[3],
  503. (unsigned char)temp.ifr_hwaddr.sa_data[4],
  504. (unsigned char)temp.ifr_hwaddr.sa_data[5]);
  505. }
  506. close(fd);
  507. return mac_buf;
  508. }
  509. int FlushUserInfoTbl(void)
  510. {
  511. // sf_sector_erase(5, USERTBL_FLASH_ADDR);
  512. // sf_write(5, USERTBL_FLASH_ADDR, (uint8_t*)g_BMCInfo.UserInfoTbl, sizeof(UserInfo_T)*MAX_USER_NUM);
  513. return 0;
  514. }
  515. int UpdateUserInfoTble(void)
  516. {
  517. // sf_read(5, USERTBL_FLASH_ADDR, (uint8_t*)g_BMCInfo.UserInfoTbl, sizeof(UserInfo_T)*MAX_USER_NUM);
  518. return 0;
  519. }
  520. int getSensorHistory(uint8_t sensorNum, uint8_t *phistoryBuf)
  521. {
  522. int i =0;
  523. for(i=0;i<SENSOR_NUMBERS;i++)
  524. {
  525. if(gSensorHistoryInfo[i].SensorNum == sensorNum)
  526. {
  527. memcpy(phistoryBuf, gSensorHistoryInfo[i].History, HISTORY_DATA_SIZE);
  528. return 0;
  529. }
  530. }
  531. if(i >= SENSOR_NUMBERS)
  532. {
  533. printf("---> can't find sensorNum!\n");
  534. return -1;
  535. }
  536. }