AMIBiosCode.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /****************************************************************
  2. ****************************************************************
  3. ** **
  4. ** (C)Copyright 2010-2011, American Megatrends Inc. **
  5. ** **
  6. ** All Rights Reserved. **
  7. ** **
  8. ** 5555 Oakbrook Pkwy, Building 200, Norcross, **
  9. ** **
  10. ** Georgia 30093, USA. Phone-(770)-246-8600. **
  11. ** **
  12. ****************************************************************
  13. ****************************************************************/
  14. /*****************************************************************
  15. *
  16. * AMIBiosCode.c
  17. *
  18. *
  19. * Author: Gokulakannan. S <gokulakannans@amiindia.co.in>
  20. *****************************************************************/
  21. #include <stdio.h>
  22. #include <unistd.h>
  23. #include <sys/stat.h>
  24. #include <fcntl.h>
  25. #include <string.h>
  26. #include <errno.h>
  27. #include <dlfcn.h>
  28. #include "Support.h"
  29. #include "dbgout.h"
  30. #include "PMConfig.h"
  31. #include "NVRData.h"
  32. #include "NVRAccess.h"
  33. #include "IPMIDefs.h"
  34. #include "SharedMem.h"
  35. #include "IPMI_AMIBiosCode.h"
  36. #include "AMIBiosCode.h"
  37. #if AMI_GET_BIOS_CODE != UNIMPLEMENTED
  38. static INT8U
  39. ReadBiosCodes(int nCode, unsigned char *pCode, int *pLen)
  40. {
  41. void *pHandle = NULL;
  42. int (*pGetBiosCode) ( unsigned char *, int );
  43. pHandle = dlopen("/usr/local/lib/libsnoop.so", RTLD_NOW);
  44. if (pHandle == NULL)
  45. {
  46. return CC_INV_CMD;
  47. }
  48. if (nCode == CURRENT)
  49. {
  50. pGetBiosCode = dlsym(pHandle, "ReadCurrentBiosCode");
  51. }
  52. else if (nCode == PREVIOUS)
  53. {
  54. pGetBiosCode = dlsym(pHandle, "ReadPreviousBiosCode");
  55. }
  56. else
  57. {
  58. dlclose (pHandle);
  59. return CC_INV_DATA_FIELD;
  60. }
  61. if (pGetBiosCode == NULL)
  62. {
  63. dlclose (pHandle);
  64. return CC_INV_CMD;
  65. }
  66. (*pLen) = pGetBiosCode(pCode, MAX_SIZE);
  67. /* Check whether the driver returned a INT number*/
  68. if ((*pLen) == -1)
  69. {
  70. TDBG("No Bios Codes Found \n");
  71. (*pLen) = 0;
  72. dlclose (pHandle);
  73. return OEMCC_FILE_ERR;
  74. }
  75. #if 0
  76. printf("Bios Codes :\n");
  77. for(i=0;i<(*pLen);i++)
  78. {
  79. printf("%02X ", pCode[i]);
  80. if ((i>0) && (((i+1)%16)==0))
  81. printf("\n");
  82. }
  83. printf("\n");
  84. #endif
  85. dlclose (pHandle);
  86. return CC_NORMAL;
  87. }
  88. /**
  89. * @fn AMIGetBiosCode
  90. * @brief Set the SOL Status.
  91. * @param[in] pReq - pointer to the request.
  92. * @param[in] ReqLen - Length of the request.
  93. * @param[out] pRes - pointer to the result.
  94. * @retval CC_NORMAL, on success,
  95. * CC_INV_DATA_FIELD, if invalid data in the request.
  96. */
  97. int
  98. AMIGetBiosCode (_NEAR_ INT8U* pReq, INT32U ReqLen, _NEAR_ INT8U* pRes, int BMCInst)
  99. {
  100. AMIGetBiosCodeReq_T* pAMIGetBiosCodeReq = ( AMIGetBiosCodeReq_T* ) pReq;
  101. AMIGetBiosCodeRes_T* pAMIGetBiosCodeRes = ( AMIGetBiosCodeRes_T* ) pRes;
  102. int nLen = 0;
  103. memset (pAMIGetBiosCodeRes, 0x00, sizeof (AMIGetBiosCodeRes_T));
  104. pAMIGetBiosCodeRes->CompletionCode = ReadBiosCodes(pAMIGetBiosCodeReq->Command, pAMIGetBiosCodeRes->BiosCode, &nLen);
  105. // Length of the bioscode including the completion code.
  106. return (nLen + 1);
  107. }
  108. #endif