main.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. /*
  2. * bmc_app application main code.
  3. */
  4. #include <stdio.h>
  5. #include <stdint.h>
  6. #include <sys/prctl.h>
  7. #include <semaphore.h>
  8. #include <pthread.h>
  9. #include <stdlib.h>
  10. //#include <fcntl.h>
  11. #include "linux/fcntl.h"
  12. #include <signal.h>
  13. #include <sys/time.h>
  14. #include "com_BmcType.h"
  15. #include "com_IPMIDefs.h"
  16. #include "com_Message.h"
  17. #include "BmcType.h"
  18. #include "main.h"
  19. #include "Session.h"
  20. #include "LANIfc.h"
  21. #include "UDSIfc.h"
  22. #include "IPMBIfc.h"
  23. #include "MsgHndlrTask.h"
  24. #include "ChassisTimerTask.h"
  25. #include "TimerTask.h"
  26. #include "CM_LIB.h"
  27. #include "stm32f429xx.h"
  28. #include "com_gpio.h"
  29. #include "hal_interface_api.h"
  30. #include "com_BMCCfg.h"
  31. #include "PendActionTask.h"
  32. #include "Api.h"
  33. #include "driver.h"
  34. #include "sensor_tbl.h"
  35. #include "com_IPMI_SDRRecord.h"
  36. #include "AuthLicense.h"
  37. /* gloabl varible */
  38. BMCInfo_t g_BMCInfo;
  39. pthread_t gThreadIDs[256];
  40. uint8_t gThreadIndex = 0;
  41. uint8_t gChassisIPMBAddr[BLADE_NUMBERS] = {0x82, 0x84, 0x86, 0x88, 0x8A, 0x8C,
  42. 0x8E, 0x90, 0x92, 0x94};
  43. SensorHistoryInfo_T gSensorHistoryInfo[SENSOR_NUMBERS];
  44. FanInfo_T gFanInfo[FAN_NUMBERS] = {
  45. /* Index | name | mode | level | speed */
  46. {0, {"Fan1"}, 0, 0, 0 },
  47. {1, {"Fan2"}, 0, 0, 0 },
  48. {2, {"Fan3"}, 0, 0, 0 },
  49. {3, {"Fan4"}, 0, 0, 0 },
  50. };
  51. BladeStatus_T gBladeStatus[BLADE_NUMBERS] = {
  52. /* present | healthStatus | name | slotID | pwrStatus */
  53. { 0, 0, "---", 0, 0},
  54. { 0, 0, "---", 0, 0},
  55. { 0, 0, "---", 0, 0},
  56. { 0, 0, "---", 0, 0},
  57. { 0, 0, "---", 0, 0},
  58. { 0, 0, "---", 0, 0},
  59. { 0, 0, "---", 0, 0},
  60. { 0, 0, "---", 0, 0},
  61. { 0, 0, "---", 0, 0},
  62. { 0, 0, "---", 0, 0},
  63. };
  64. //void *test_thread(void *var);
  65. //uint8_t test_flag = 0;
  66. static int tmp_fd;
  67. void main(void)
  68. {
  69. // if(0 != cm_Auth_Encrp_Init(1, 1, TRUE))
  70. // {
  71. // printf("Initialize AT88SC0104C failed!\n");
  72. // sleep(1);
  73. // return;
  74. // }
  75. // printf("cm_Auth_Encrp_Init ok\n");
  76. // #if 0
  77. // if(0 != cm_Auth_Encrp_Personal(1, 1))
  78. // {
  79. // printf("Personal AT88SC0104C failed!\n");
  80. // sleep(1);
  81. // return ;
  82. // }
  83. // #endif
  84. // if(0 != test_cryptomem())
  85. // {
  86. // while(1)
  87. // {
  88. // printf("Illegal Board!\n");
  89. // sleep(3);
  90. // }
  91. // }
  92. //检查软件授权
  93. if(CheckLicense() != 0)
  94. {
  95. system("killall -9 damon.sh");
  96. exit(0);
  97. }
  98. PlatformInit();
  99. Init_IPMI_FRU_SDR_SEL();
  100. Init_SessionTbl();
  101. InitTimerTaskTbl();
  102. InitChannelTab();
  103. pthread_mutex_init(&api_bridge_mutex, NULL);
  104. pthread_mutex_init(&Flash_Mutex, NULL);
  105. //初始化系统时间
  106. system("date -s 2020.05.12-00:00:00");
  107. //Initialize IP
  108. char cmdStr[100];
  109. LanInfo_T *pSetLanInfo = &g_BMCInfo.IpmiConfig.LanInfo[0];
  110. // //down
  111. // sprintf(cmdStr, "ifconfig %s down", pSetLanInfo->EthName);
  112. // printf("%s\n", cmdStr);
  113. // system(cmdStr);
  114. // //set mac
  115. // sprintf(cmdStr, "ifconfig %s hw ether %02x:%02x:%02x:%02x:%02x:%02x",
  116. // pSetLanInfo->EthName, pSetLanInfo->MACAddr[0], pSetLanInfo->MACAddr[1],
  117. // pSetLanInfo->MACAddr[2], pSetLanInfo->MACAddr[3],
  118. // pSetLanInfo->MACAddr[4], pSetLanInfo->MACAddr[5]);
  119. // printf("%s\n", cmdStr);
  120. // system(cmdStr);
  121. //ip, broadcast, netmask
  122. sprintf(cmdStr, "ifconfig eth0 %d.%d.%d.%d broadcast %d.%d.%d.%d netmask %d.%d.%d.%d up",
  123. pSetLanInfo->IPAddr[0], pSetLanInfo->IPAddr[1],
  124. pSetLanInfo->IPAddr[2], pSetLanInfo->IPAddr[3], pSetLanInfo->BroadCast[0],
  125. pSetLanInfo->BroadCast[1], pSetLanInfo->BroadCast[2], pSetLanInfo->BroadCast[3],
  126. pSetLanInfo->NetMask[0], pSetLanInfo->NetMask[1], pSetLanInfo->NetMask[2],
  127. pSetLanInfo->NetMask[3]);
  128. printf("%s\n", cmdStr);
  129. system(cmdStr);
  130. printf("\tChassisID %#02x, SlotID %#02x\r\n", g_BMCInfo.ChassisID, g_BMCInfo.SlotID);
  131. if(g_BMCInfo.IpmiConfig.PrimaryIPMBSupport)
  132. {
  133. printf("\tPrimaryIPMBBus: %d, channel %d, Addr %#02x\n", g_BMCInfo.IpmiConfig.PrimaryIPMBBus,
  134. PRIMARY_IPMB_CHANNEL, g_BMCInfo.PrimaryIPMBAddr);
  135. }
  136. if(g_BMCInfo.IpmiConfig.SecondaryIPMBSupport)
  137. {
  138. printf("\tSecondaryIPMBBus %d, Channel %d, Addr %#02x\n", g_BMCInfo.IpmiConfig.SecondaryIPMBBus,
  139. SECONDARY_IPMB_CHANNEL, g_BMCInfo.SecondaryIPMBAddr);
  140. }
  141. /* Create TimerTask */
  142. signal(SIGALRM, TimerTask);
  143. struct itimerval new_value;
  144. new_value.it_value.tv_sec = 0;
  145. new_value.it_value.tv_usec = 1;
  146. new_value.it_interval.tv_sec = 1;
  147. new_value.it_interval.tv_usec = 0;
  148. setitimer(ITIMER_REAL, &new_value, NULL);
  149. //create BRIDGE_QUEUE
  150. if(-1 != access(BRIDGE_QUEUE, F_OK))
  151. {
  152. remove(BRIDGE_QUEUE);
  153. }
  154. if(0 != mkfifo (BRIDGE_QUEUE, 0777))
  155. {
  156. printf("%s: Create %s fifo failed! \n", __FUNCTION__, BRIDGE_QUEUE);
  157. }
  158. /* Create MsgHndlr Task */
  159. gThreadIndex++;
  160. if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,MsgHndlrTask,NULL))
  161. {
  162. printf("%s: Create MsgHndlrTask thread failed!\n", __FUNCTION__);
  163. }
  164. /* Create ChassisTimerTask */
  165. gThreadIndex++;
  166. if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,ChassisTimerTask,NULL))
  167. {
  168. printf("%s: Create ChassisTimerTask thread failed!\n", __FUNCTION__);
  169. }
  170. /* Create SensorMonitorTask */
  171. gThreadIndex++;
  172. if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,SensorMonitorTask,NULL))
  173. {
  174. printf("%s: Create SensorMonitorTask thread failed!\n", __FUNCTION__);
  175. }
  176. /* Create UDS interface */
  177. gThreadIndex++;
  178. if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,UDSIfcTask,NULL))
  179. {
  180. printf("%s: Create UDSIfcTask thread failed!\n", __FUNCTION__);
  181. }
  182. /* Create LAN interface */
  183. gThreadIndex++;
  184. if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,LANIfcTask,NULL))
  185. {
  186. printf("%s: Create LANIfcTask thread failed!\n", __FUNCTION__);
  187. }
  188. /* Create IPMB interface */
  189. uint8_t primaryIpmbSelect = 0; //primary
  190. gThreadIndex++;
  191. if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,IPMBIfcTask,&primaryIpmbSelect))
  192. {
  193. printf("%s: Create LANIfcTask thread failed!\n", __FUNCTION__);
  194. }
  195. uint8_t secondaryIpmbSelect = 1; //secondary
  196. gThreadIndex++;
  197. if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,IPMBIfcTask,&secondaryIpmbSelect))
  198. {
  199. printf("%s: Create LANIfcTask thread failed!\n", __FUNCTION__);
  200. }
  201. /* Create PendActionTask */
  202. gThreadIndex++;
  203. if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,PendActionTask,NULL))
  204. {
  205. printf("%s: Create PendActionTask thread failed!\n", __FUNCTION__);
  206. }
  207. /* Create Update FPGA thread */
  208. /* Create UDS interface */
  209. /* Create UDS interface */
  210. /* Create UDS interface */
  211. // pthread_mutex_init(&mutex,NULL);
  212. // tmp_fd = open("/dev/i2c2", O_RDWR);;
  213. // uint8_t buf[7] = {0x20, 0xb8, 0x8, 0x20, 0x4, 0x1, 0xdb };
  214. // gThreadIndex++;
  215. // pthread_create(&gThreadIDs[gThreadIndex],NULL,test_thread,NULL);
  216. /* 看门狗,10s无喂狗就复位 */
  217. // int fd_iwdg = open("/dev/iwdg", O_RDWR);
  218. // ioctl(fd_iwdg, START_IWATCHDOG, NULL); //打开看狗
  219. while(1) //在这里实现各线程的健康状态检测,发现出错的线程就重启它。
  220. {
  221. // //喂看门狗
  222. // if(ioctl(fd_iwdg, FEED_WATCHDOG, NULL) != 0)
  223. // {
  224. // printf("---> Feed watchdog failed\n");
  225. // }
  226. sleep(10);
  227. }
  228. }
  229. // void *test_thread(void *var)
  230. // {
  231. // uint8_t len, i;
  232. // uint8_t recvBuf[100];
  233. // printf("---> test_thread start...\n");
  234. // stm32_i2c_set_addr(tmp_fd, 0x44);
  235. // uint8_t buf[7] = {0x20, 0xb8, 0x8, 0x20, 0x4, 0x1, 0xdb };
  236. // while(1)
  237. // {
  238. // pthread_mutex_lock(&mutex);
  239. // pthread_mutex_unlock(&mutex);
  240. // len = 0;
  241. // len = stm32_i2c_slave_recv(tmp_fd, recvBuf);
  242. // if(len > 0)
  243. // {
  244. // printf("Recv: ");
  245. // for(i=0;i<len; i++)
  246. // printf("%#x ", recvBuf[i]);
  247. // printf("\n");
  248. // test_flag = 1;
  249. // //sleep(1);
  250. // // if(0 != stm32_i2c_master_write(tmp_fd, buf[0], &buf[1], 6))
  251. // // {
  252. // // printf("---> Send ipmb error!\n");
  253. // // }
  254. // // else
  255. // // printf("---> send ipmb ok\n");
  256. // }
  257. // }
  258. // }