mirror of
https://github.com/ipmitool/ipmitool.git
synced 2025-05-10 18:47:22 +00:00
imb: Refactoring: remove duplicate code
Merge GetAsyncImbpMessage() and GetAsyncImbpMessage_Ex() functions as they share 95% of the code. Make the former call the latter(). Signed-off-by: Alexander Amelkin <alexander@amelkin.msk.ru>
This commit is contained in:
parent
9ecfb762bd
commit
f3ef88724f
@ -979,82 +979,12 @@ ACCESN_STATUS
|
|||||||
GetAsyncImbpMessage (ImbPacket *msgPtr, DWORD *msgLen, DWORD timeOut,
|
GetAsyncImbpMessage (ImbPacket *msgPtr, DWORD *msgLen, DWORD timeOut,
|
||||||
ImbAsyncSeq *seqNo, DWORD channelNumber)
|
ImbAsyncSeq *seqNo, DWORD channelNumber)
|
||||||
{
|
{
|
||||||
BOOL status;
|
/* This function does exactly the same as GetAsuncImbpMessage_Ex(),
|
||||||
BYTE responseData[MAX_ASYNC_RESP_SIZE];
|
* but doesn't return session handle and privilege
|
||||||
BYTE lun;
|
*/
|
||||||
ImbAsyncResponse *resp = (ImbAsyncResponse *)responseData;
|
return GetAsyncImbpMessage_Ex(msgPtr, msgLen, timeOut,
|
||||||
DWORD respLength = sizeof(responseData);
|
seqNo, channelNumber,
|
||||||
ImbAsyncRequest req;
|
NULL, NULL);
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* GetAsyncImbpMessage_Ex - gets the next available async message with a message
|
/* GetAsyncImbpMessage_Ex - gets the next available async message with a message
|
||||||
@ -1110,12 +1040,12 @@ GetAsyncImbpMessage_Ex(ImbPacket *msgPtr, DWORD *msgLen, DWORD timeOut,
|
|||||||
return ACCESN_ERROR;
|
return ACCESN_ERROR;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
} else if (respLength < MIN_ASYNC_RESP_SIZE) {
|
||||||
if (respLength < MIN_ASYNC_RESP_SIZE) {
|
|
||||||
return ACCESN_ERROR;
|
return ACCESN_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
respLength -= MIN_ASYNC_RESP_SIZE;
|
respLength -= MIN_ASYNC_RESP_SIZE;
|
||||||
|
|
||||||
if (*msgLen < respLength) {
|
if (*msgLen < respLength) {
|
||||||
return ACCESN_ERROR;
|
return ACCESN_ERROR;
|
||||||
}
|
}
|
||||||
@ -1143,26 +1073,26 @@ GetAsyncImbpMessage_Ex(ImbPacket *msgPtr, DWORD *msgLen, DWORD timeOut,
|
|||||||
memcpy(msgPtr, resp->data, respLength);
|
memcpy(msgPtr, resp->data, respLength);
|
||||||
*msgLen = respLength;
|
*msgLen = respLength;
|
||||||
} else {
|
} else {
|
||||||
if ((sessionHandle ==NULL) || (privilege ==NULL)) {
|
/* it is version 1.0 or better */
|
||||||
return ACCESN_ERROR;
|
|
||||||
}
|
|
||||||
/* 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
|
|
||||||
* 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) {
|
if ((resp->data[0] & 0x0f) != (BYTE)channelNumber) {
|
||||||
*seqNo = resp->thisSeq;
|
*seqNo = resp->thisSeq;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/* The get message command according to IPMI 1.5 spec
|
/* With the new IPMI version the get message command
|
||||||
* now even returns the session handle.This is required
|
* returns the channel number along with the
|
||||||
* to be captured as it is required as request data for
|
* privileges. The 1st 4 bits of the second byte of the
|
||||||
* send message command.
|
* response data for get message command represent the
|
||||||
|
* channel number & the last 4 bits are the privileges.
|
||||||
*/
|
*/
|
||||||
*sessionHandle = resp->data[1];
|
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];
|
||||||
|
}
|
||||||
memcpy(msgPtr, &(resp->data[2]), (respLength - 1));
|
memcpy(msgPtr, &(resp->data[2]), (respLength - 1));
|
||||||
*msgLen = respLength - 1;
|
*msgLen = respLength - 1;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user