diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2022-10-30 18:12:02 +0100 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2022-10-30 18:12:02 +0100 |
commit | 1f3c9b4ae26ce1d46d954d509b83b8684ada5625 (patch) | |
tree | 260b922ec4d5d153cc6db745e27931cfd464472f /src/plugins/imb/imbapi.c | |
parent | 8fcf0ba6f182918bd584bb80bf0b8998acad26a8 (diff) | |
parent | 8b758ee941f4c1ffea0532caa74b1fcd8101d1d8 (diff) |
Merge branch 'release/debian/1.8.19-1'debian/1.8.19-1
Diffstat (limited to 'src/plugins/imb/imbapi.c')
-rw-r--r-- | src/plugins/imb/imbapi.c | 201 |
1 files changed, 66 insertions, 135 deletions
diff --git a/src/plugins/imb/imbapi.c b/src/plugins/imb/imbapi.c index 34c9c82..b27486d 100644 --- a/src/plugins/imb/imbapi.c +++ b/src/plugins/imb/imbapi.c @@ -60,11 +60,12 @@ #include "imbapi.h" #include <sys/socket.h> +#include <ipmitool/helper.h> #include <ipmitool/log.h> #ifdef SCO_UW # define NO_MACRO_ARGS 1 -# define __FUNCTION__ "func" +# define __func__ "func" # define IMB_DEVICE "/dev/instru/mismic" #else # define IMB_DEVICE "/dev/imb" @@ -117,7 +118,7 @@ open_imb(void) OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - if (hDevice == NULL || hDevice == INVALID_HANDLE_VALUE) { + if (!hDevice || INVALID_HANDLE_VALUE == hDevice) { return 0; } /* Detect the IPMI version for processing requests later. This @@ -170,7 +171,7 @@ open_imb(void) if (hDevice1 != 0) { return 1; } - lprintf(LOG_DEBUG, "%s: opening the driver", __FUNCTION__); + lprintf(LOG_DEBUG, "%s: opening the driver", __func__); /* printf("open_imb: " "IOCTL_IMB_SEND_MESSAGE =%x \n" "IOCTL_IMB_GET_ASYNC_MSG=%x \n" "IOCTL_IMB_MAP_MEMORY = %x \n" "IOCTL_IMB_UNMAP_MEMORY= %x \n" @@ -192,7 +193,7 @@ open_imb(void) if (fDriverTyp != 0) { /* not 1st time */ sprintf(buf,"%s %s: open(%s) failed", - __FILE__, __FUNCTION__, IMB_DEVICE); + __FILE__, __func__, IMB_DEVICE); perror(buf); } return 0; @@ -212,14 +213,14 @@ open_imb(void) requestData.data = NULL; requestData.dataLength = 0; respLength = 16; - lprintf(LOG_DEBUG, "%s: opened driver, getting IPMI version", __FUNCTION__); + lprintf(LOG_DEBUG, "%s: opened driver, getting IPMI version", __func__); if (((my_ret_code = SendTimedImbpRequest(&requestData, (DWORD)400, respBuffer, (int *)&respLength, &completionCode)) != ACCESN_OK) || (completionCode != 0)) { printf("%s: SendTimedImbpRequest error. Ret = %d CC = 0x%X\n", - __FUNCTION__, my_ret_code, completionCode); + __func__, my_ret_code, completionCode); close(hDevice1); hDevice1 = 0; return 0; @@ -233,7 +234,7 @@ open_imb(void) IpmiVersion = IPMI_10_VERSION; } } - lprintf(LOG_DEBUG, "%s: IPMI version 0x%x", __FUNCTION__, + lprintf(LOG_DEBUG, "%s: IPMI version 0x%x", __func__, IpmiVersion); return 1; } /* end open_imb() */ @@ -281,11 +282,11 @@ ipmi_close_ia(void) * @lpcbBytesReturned, address of actual bytes of output * @lpoOverlapped address of overlapped struct * - * returns - FALSE for fail and TRUE for success. Same as standarad NTOS call as + * returns - FALSE for fail and TRUE for success. Same as standard NTOS call as * it also sets Ntstatus.status. */ static BOOL -DeviceIoControl(HANDLE dummey_hDevice, DWORD dwIoControlCode, LPVOID +DeviceIoControl(HANDLE __UNUSED__(dummey_hDevice), DWORD dwIoControlCode, LPVOID lpvInBuffer, DWORD cbInBuffer, LPVOID lpvOutBuffer, DWORD cbOutBuffer, LPDWORD lpcbBytesReturned, LPOVERLAPPED lpoOverlapped) @@ -298,7 +299,7 @@ DeviceIoControl(HANDLE dummey_hDevice, DWORD dwIoControlCode, LPVOID if (rc == 0) { return FALSE; } - lprintf(LOG_DEBUG, "%s: ioctl cmd = 0x%lx", __FUNCTION__, + lprintf(LOG_DEBUG, "%s: ioctl cmd = 0x%lx", __func__, dwIoControlCode); lprintf(LOG_DEBUG, "cbInBuffer %d cbOutBuffer %d", cbInBuffer, cbOutBuffer); @@ -312,23 +313,23 @@ DeviceIoControl(HANDLE dummey_hDevice, DWORD dwIoControlCode, LPVOID s.cbOutBuffer = cbOutBuffer; s.lpcbBytesReturned = lpcbBytesReturned; s.lpoOverlapped = lpoOverlapped; - /* dummy place holder. Linux IMB driver doesnt return status or info + /* dummy place holder. Linux IMB driver doesn't return status or info * via it */ s.ntstatus = (LPVOID)&NTstatus; if ((ioctl_status = ioctl(hDevice1, dwIoControlCode,&s)) < 0) { lprintf(LOG_DEBUG, "%s %s: ioctl cmd = 0x%x failed", - __FILE__, __FUNCTION__, dwIoControlCode); + __FILE__, __func__, dwIoControlCode); return FALSE; } lprintf(LOG_DEBUG, "%s: ioctl_status %d bytes returned = %d", - __FUNCTION__, ioctl_status, *lpcbBytesReturned); + __func__, ioctl_status, *lpcbBytesReturned); if (ioctl_status == STATUS_SUCCESS) { - lprintf(LOG_DEBUG, "%s returning true", __FUNCTION__); + lprintf(LOG_DEBUG, "%s returning true", __func__); return (TRUE); } else { - lprintf(LOG_DEBUG, "%s returning false", __FUNCTION__); + lprintf(LOG_DEBUG, "%s returning false", __func__); return (FALSE); } } @@ -341,12 +342,12 @@ StartAsyncMesgPoll() DWORD retLength; BOOL status; lprintf(LOG_DEBUG, "%s: DeviceIoControl cmd = %x", - __FUNCTION__, IOCTL_IMB_POLL_ASYNC); + __func__, IOCTL_IMB_POLL_ASYNC); status = DeviceIoControl(hDevice, IOCTL_IMB_POLL_ASYNC, NULL, 0, NULL, 0, &retLength, 0); - lprintf(LOG_DEBUG, "%s: DeviceIoControl status = %d", __FUNCTION__, + lprintf(LOG_DEBUG, "%s: DeviceIoControl status = %d", __func__, status); if (status == TRUE) { return ACCESN_OK; @@ -407,7 +408,7 @@ SendTimedI2cRequest(I2CREQUESTDATA *reqPtr, int timeOut, BYTE *respDataPtr, status = DeviceIoControl(hDevice, IOCTL_IMB_SEND_MESSAGE, requestData, sizeof(requestData), &responseData, sizeof(responseData), &respLength, NULL); - lprintf(LOG_DEBUG, "%s: DeviceIoControl status = %d", __FUNCTION__, + lprintf(LOG_DEBUG, "%s: DeviceIoControl status = %d", __func__, status); if (status != TRUE) { DWORD error; @@ -434,7 +435,7 @@ SendTimedI2cRequest(I2CREQUESTDATA *reqPtr, int timeOut, BYTE *respDataPtr, * @responseDataLen * @timeOut - how long to wait, in mSec units * - * retruns - OK else error status code + * returns - OK else error status code */ ACCESN_STATUS SendTimedEmpMessageResponse (ImbPacket *ptr, char *responseDataBuf, @@ -498,7 +499,7 @@ SendTimedEmpMessageResponse (ImbPacket *ptr, char *responseDataBuf, status = DeviceIoControl(hDevice, IOCTL_IMB_SEND_MESSAGE, requestData, sizeof(requestData), responseData, sizeof(responseData), &respLength, NULL); - lprintf(LOG_DEBUG, "%s: DeviceIoControl status = %d", __FUNCTION__, + lprintf(LOG_DEBUG, "%s: DeviceIoControl status = %d", __func__, status); if ((status != TRUE) || (respLength != 1) || (responseData[0] != 0)) { return ACCESN_ERROR; @@ -514,7 +515,7 @@ SendTimedEmpMessageResponse (ImbPacket *ptr, char *responseDataBuf, * @timeOut - how long to wait, in mSec units * @sessionHandle - This is introduced in IPMI1.5,this is required to be sent in * sendd message command as a parameter, which is then used by BMC - * to identify the correct DPC session to send the mesage to. + * to identify the correct DPC session to send the message to. * @channelNumber - There are 3 different channels on which DPC communication * goes on: * * Emp - 1 @@ -591,7 +592,7 @@ SendTimedEmpMessageResponse_Ex (ImbPacket *ptr, char *responseDataBuf, int req->req.data[i++] = ((ptr->seqLn & 0xfc) | (ptr->nfLn & 0x3)); /* The next byte is the command like get software ID(00). */ req->req.data[i++] = ptr->cmd; - /* after the cmd the data, which is sent by DPC & is retrived using the + /* after the cmd the data, which is sent by DPC & is retrieved using the * get message earlier is sent back to DPC. */ for (j = 0; j < responseDataLen; ++j, ++i) { @@ -626,7 +627,7 @@ SendTimedEmpMessageResponse_Ex (ImbPacket *ptr, char *responseDataBuf, int sizeof(requestData), responseData, sizeof(responseData), &respLength, NULL); - lprintf(LOG_DEBUG, "%s: DeviceIoControl status = %d", __FUNCTION__, + lprintf(LOG_DEBUG, "%s: DeviceIoControl status = %d", __func__, status); if ((status != TRUE) || (respLength != 1) || (responseData[0] != 0)) { return ACCESN_ERROR; @@ -711,7 +712,7 @@ SendTimedLanMessageResponse(ImbPacket *ptr, char *responseDataBuf, sizeof(requestData), responseData, sizeof(responseData), &respLength, NULL); - lprintf(LOG_DEBUG, "%s: DeviceIoControl status = %d", __FUNCTION__, + lprintf(LOG_DEBUG, "%s: DeviceIoControl status = %d", __func__, status); if ((status != TRUE) || (respLength != 1) || (responseData[0] != 0)) { return ACCESN_ERROR; @@ -728,7 +729,7 @@ SendTimedLanMessageResponse(ImbPacket *ptr, char *responseDataBuf, * @timeOut - how long to wait, in mSec units * @sessionHandle - This is introduced in IPMI1.5,this is required to be sent in * send message command as a parameter,which is then used by BMC to identify the - * correct DPC session to send the mesage to. + * correct DPC session to send the message to. * @channelNumber - There are 3 different channels on which DPC communication * goes on: * * Emp - 1 @@ -806,7 +807,7 @@ SendTimedLanMessageResponse_Ex(ImbPacket *ptr, char *responseDataBuf, int req->req.data[i++] = ((ptr->seqLn & 0xfc) | (ptr->nfLn & 0x3)); /* The next byte is the command like get software ID(00). */ req->req.data[i++] = ptr->cmd; - /* After the cmd the data ,which is sent by DPC & is retrived using the + /* After the cmd the data ,which is sent by DPC & is retrieved using the * get message earlier is sent back to DPC. */ for (j = 0; j < responseDataLen; ++j, ++i) { @@ -839,7 +840,7 @@ SendTimedLanMessageResponse_Ex(ImbPacket *ptr, char *responseDataBuf, int status = DeviceIoControl(hDevice, IOCTL_IMB_SEND_MESSAGE, requestData, sizeof(requestData), responseData, sizeof(responseData), &respLength, NULL); - lprintf(LOG_DEBUG, "%s: DeviceIoControl status = %d", __FUNCTION__, + lprintf(LOG_DEBUG, "%s: DeviceIoControl status = %d", __func__, status); if ((status != TRUE) || (respLength != 1) || (responseData[0] != 0)) { return ACCESN_ERROR; @@ -882,7 +883,7 @@ SendTimedImbpRequest(IMBPREQUESTDATA *reqPtr, int timeOut, BYTE *respDataPtr, /* convert to uSec units */ req->timeOut = timeOut * 1000; lprintf(LOG_DEBUG, "%s: rsSa 0x%x cmd 0x%x netFn 0x%x rsLun 0x%x", - __FUNCTION__, req->req.rsSa, req->req.cmd, + __func__, req->req.rsSa, req->req.cmd, req->req.netFn, req->req.rsLun); status = DeviceIoControl(hDevice, IOCTL_IMB_SEND_MESSAGE, requestData, @@ -890,11 +891,11 @@ SendTimedImbpRequest(IMBPREQUESTDATA *reqPtr, int timeOut, BYTE *respDataPtr, sizeof(responseData), &respLength, NULL); lprintf(LOG_DEBUG, "%s: DeviceIoControl returned status = %d", - __FUNCTION__, status); + __func__, status); #ifdef DBG_IPMI /* TODO */ printf("%s: rsSa %x cmd %x netFn %x lun %x, status=%d, cc=%x, rlen=%d\n", - __FUNCTION__, req->req.rsSa, req->req.cmd, + __func__, req->req.rsSa, req->req.cmd, req->req.netFn, req->req.rsLun, status, resp->cCode, respLength); #endif @@ -949,7 +950,7 @@ SendAsyncImbpRequest(IMBPREQUESTDATA *reqPtr, BYTE *seqNo) sizeof(requestData), &responseData, sizeof(responseData), &respLength, NULL); - lprintf(LOG_DEBUG, "%s: DeviceIoControl status = %d", __FUNCTION__, + lprintf(LOG_DEBUG, "%s: DeviceIoControl status = %d", __func__, status); if (status != TRUE) { DWORD error; @@ -979,82 +980,12 @@ ACCESN_STATUS GetAsyncImbpMessage (ImbPacket *msgPtr, DWORD *msgLen, DWORD timeOut, ImbAsyncSeq *seqNo, DWORD channelNumber) { - BOOL status; - BYTE responseData[MAX_ASYNC_RESP_SIZE]; - BYTE lun; - ImbAsyncResponse *resp = (ImbAsyncResponse *)responseData; - DWORD respLength = sizeof(responseData); - ImbAsyncRequest req; - - while (1) { - if ((msgPtr == NULL) || (msgLen == NULL) || ( seqNo == NULL)) { - return ACCESN_ERROR; - } - /* convert to uSec units */ - req.timeOut = timeOut * 1000; - req.lastSeq = *seqNo; - - status = DeviceIoControl(hDevice, IOCTL_IMB_GET_ASYNC_MSG, &req, - sizeof(req), &responseData, - sizeof(responseData), &respLength, NULL); - - lprintf(LOG_DEBUG, "%s: DeviceIoControl status = %d", - __FUNCTION__, status); - if (status != TRUE) { - DWORD error = GetLastError(); - /* handle "msg not available" specially. it is different - * from a random old error. - */ - switch (error) { - case IMB_MSG_NOT_AVAILABLE: - return ACCESN_END_OF_DATA; - break; - default: - return ACCESN_ERROR; - break; - } - } else if (respLength < MIN_ASYNC_RESP_SIZE) { - return ACCESN_ERROR; - } - respLength -= MIN_ASYNC_RESP_SIZE; - - if (*msgLen < respLength) { - return ACCESN_ERROR; - } - - /* same code as in NT section */ - if (IpmiVersion == IPMI_09_VERSION) { - switch (channelNumber) { - case IPMB_CHANNEL: - lun = IPMB_LUN; - break; - case EMP_CHANNEL: - lun = EMP_LUN; - break; - default: - lun = RESERVED_LUN; - break; - } - if ((lun == RESERVED_LUN) - || (lun != ((((ImbPacket *)(resp->data))->nfLn) & 0x3 ))) { - *seqNo = resp->thisSeq; - continue; - } - memcpy(msgPtr, resp->data, respLength); - *msgLen = respLength; - } else { - /* it is version 1.0 or better */ - if (resp->data[0] != (BYTE)channelNumber) { - *seqNo = resp->thisSeq; - continue; - } - memcpy(msgPtr, &(resp->data[1]), (respLength - 1)); - *msgLen = respLength - 1; - } - /* give the caller his sequence number */ - *seqNo = resp->thisSeq; - return ACCESN_OK; - } + /* This function does exactly the same as GetAsuncImbpMessage_Ex(), + * but doesn't return session handle and privilege + */ + return GetAsyncImbpMessage_Ex(msgPtr, msgLen, timeOut, + seqNo, channelNumber, + NULL, NULL); } /* GetAsyncImbpMessage_Ex - gets the next available async message with a message @@ -1084,7 +1015,7 @@ GetAsyncImbpMessage_Ex(ImbPacket *msgPtr, DWORD *msgLen, DWORD timeOut, ImbAsyncRequest req; while (1) { - if ((msgPtr == NULL) || (msgLen == NULL) || ( seqNo == NULL)) { + if (!msgPtr || !msgLen || !seqNo) { return ACCESN_ERROR; } @@ -1096,7 +1027,7 @@ GetAsyncImbpMessage_Ex(ImbPacket *msgPtr, DWORD *msgLen, DWORD timeOut, sizeof(responseData), &respLength, NULL); lprintf(LOG_DEBUG, "%s: DeviceIoControl status = %d", - __FUNCTION__, status); + __func__, status); if (status != TRUE) { DWORD error = GetLastError(); /* handle "msg not available" specially. it is @@ -1110,12 +1041,12 @@ GetAsyncImbpMessage_Ex(ImbPacket *msgPtr, DWORD *msgLen, DWORD timeOut, return ACCESN_ERROR; break; } - } - if (respLength < MIN_ASYNC_RESP_SIZE) { + } else if (respLength < MIN_ASYNC_RESP_SIZE) { return ACCESN_ERROR; } respLength -= MIN_ASYNC_RESP_SIZE; + if (*msgLen < respLength) { return ACCESN_ERROR; } @@ -1143,26 +1074,26 @@ GetAsyncImbpMessage_Ex(ImbPacket *msgPtr, DWORD *msgLen, DWORD timeOut, memcpy(msgPtr, resp->data, respLength); *msgLen = respLength; } else { - if ((sessionHandle ==NULL) || (privilege ==NULL)) { - return ACCESN_ERROR; + /* it is version 1.0 or better */ + if ((resp->data[0] & 0x0f) != (BYTE)channelNumber) { + *seqNo = resp->thisSeq; + continue; } /* With the new IPMI version the get message command * returns the channel number along with the - * privileges.The 1st 4 bits of the second byte of the + * privileges. The 1st 4 bits of the second byte of the * response data for get message command represent the * channel number & the last 4 bits are the privileges. */ - *privilege = (resp->data[0] & 0xf0)>> 4; - if ((resp->data[0] & 0x0f) != (BYTE)channelNumber) { - *seqNo = resp->thisSeq; - continue; + if (sessionHandle && privilege) { + *privilege = (resp->data[0] & 0xf0) >> 4; + /* The get message command according to IPMI 1.5 spec + * now even returns the session handle. This is required + * to be captured as it is required as request data for + * send message command. + */ + *sessionHandle = resp->data[1]; } - /* The get message command according to IPMI 1.5 spec - * now even returns the session handle.This is required - * to be captured as it is required as request data for - * send message command. - */ - *sessionHandle = resp->data[1]; memcpy(msgPtr, &(resp->data[2]), (respLength - 1)); *msgLen = respLength - 1; } @@ -1194,7 +1125,7 @@ IsAsyncMessageAvailable(unsigned int eventId) status = DeviceIoControl(hDevice, IOCTL_IMB_CHECK_EVENT, &AsyncEventHandle, sizeof(HANDLE), &dummy, sizeof(int), (LPDWORD)&respLength, NULL); - lprintf(LOG_DEBUG, "%s: DeviceIoControl status = %d", __FUNCTION__, + lprintf(LOG_DEBUG, "%s: DeviceIoControl status = %d", __func__, status); if (status != TRUE) { return ACCESN_ERROR; @@ -1220,13 +1151,13 @@ RegisterForImbAsyncMessageNotification(unsigned int *handleId) DWORD respLength ; int dummy; /*allow only one app to register */ - if ((handleId == NULL ) || (AsyncEventHandle)) { + if (!handleId || AsyncEventHandle) { return ACCESN_ERROR; } status = DeviceIoControl(hDevice, IOCTL_IMB_REGISTER_ASYNC_OBJ, &dummy, sizeof(int), &AsyncEventHandle, (DWORD)sizeof(HANDLE), (LPDWORD)&respLength, NULL); - lprintf(LOG_DEBUG, "%s: DeviceIoControl status = %d", __FUNCTION__, + lprintf(LOG_DEBUG, "%s: DeviceIoControl status = %d", __func__, status); if ((respLength != sizeof(int)) || (status != TRUE)) { return ACCESN_ERROR; @@ -1265,7 +1196,7 @@ UnRegisterForImbAsyncMessageNotification(unsigned int handleId, int iFlag) status = DeviceIoControl(hDevice, IOCTL_IMB_DEREGISTER_ASYNC_OBJ, &AsyncEventHandle, (DWORD)sizeof(HANDLE ), &dummy, (DWORD)sizeof(int), (LPDWORD)&respLength, NULL ); - lprintf(LOG_DEBUG, "%s: DeviceIoControl status = %d", __FUNCTION__, + lprintf(LOG_DEBUG, "%s: DeviceIoControl status = %d", __func__, status); if (status != TRUE) { return ACCESN_ERROR; @@ -1295,7 +1226,7 @@ SetShutDownCode(int delayTime, int code) cmd.delayTime = delayTime; status = DeviceIoControl(hDevice, IOCTL_IMB_SHUTDOWN_CODE, &cmd, sizeof(cmd), NULL, 0, &retLength, NULL); - lprintf(LOG_DEBUG, "%s: DeviceIoControl status = %d", __FUNCTION__, + lprintf(LOG_DEBUG, "%s: DeviceIoControl status = %d", __func__, status); if (status == TRUE) { return ACCESN_OK; @@ -1402,7 +1333,7 @@ MapPhysicalMemory(int startAddress, int addressLength, int *virtualAddress) if ((fd = open("/dev/mem", O_RDONLY)) < 0) { char buf[128]; sprintf(buf,"%s %s: open(%s) failed", - __FILE__, __FUNCTION__, IMB_DEVICE); + __FILE__, __func__, IMB_DEVICE); perror(buf); return ACCESN_ERROR; } @@ -1413,12 +1344,12 @@ MapPhysicalMemory(int startAddress, int addressLength, int *virtualAddress) if ((startvAddress = mmap(0, length, PROT_READ, MAP_SHARED, fd, startpAddress)) == MAP_FAILED) { char buf[128]; - sprintf(buf, "%s %s: mmap failed", __FILE__, __FUNCTION__); + sprintf(buf, "%s %s: mmap failed", __FILE__, __func__); perror(buf); close(fd); return ACCESN_ERROR; } - lprintf(LOG_DEBUG, "%s: mmap of 0x%x success", __FUNCTION__, + lprintf(LOG_DEBUG, "%s: mmap of 0x%x success", __func__, startpAddress); #ifdef LINUX_DEBUG_MAX for (int i = 0; i < length; i++) { @@ -1451,15 +1382,15 @@ UnmapPhysicalMemory(int virtualAddress, int Length) diff = ((unsigned int)virtualAddress) % pagesize; virtualAddress -= diff; Length += diff; - lprintf(LOG_DEBUG, "%s: calling munmap(0x%x,%d)", __FUNCTION__, + lprintf(LOG_DEBUG, "%s: calling munmap(0x%x,%d)", __func__, virtualAddress,Length); if (munmap(&virtualAddress, Length) != 0) { char buf[128]; - sprintf(buf, "%s %s: munmap failed", __FILE__, __FUNCTION__); + sprintf(buf, "%s %s: munmap failed", __FILE__, __func__); perror(buf); return ACCESN_ERROR; } - lprintf(LOG_DEBUG, "%s: munmap(0x%x,%d) success", __FUNCTION__, + lprintf(LOG_DEBUG, "%s: munmap(0x%x,%d) success", __func__, virtualAddress, Length); return ACCESN_OK; } |