/* If the ACK number matches the expected block number, and there are more data pending, send the next block. Otherwise tell the caller that we are done. */
EFI_STATUS Mtftp4WrqHandleAck(IN MTFTP4_PROTOCOL *Instance, IN EFI_MTFTP4_PACKET *Packet, IN UINT32 Len, OUT BOOLEAN *Completed)
/* If the ACK number matches the expected block number, and there are more data pending, send the next block. Otherwise tell the caller that we are done. */
EFI_STATUS Mtftp4WrqHandleAck(IN MTFTP4_PROTOCOL *Instance, IN EFI_MTFTP4_PACKET *Packet, IN UINT32 Len, OUT BOOLEAN *Completed)
{
  UINT16  AckNum;
  INTN    Expected;
  UINT64  BlockCounter;
  *Completed = FALSE;
  AckNum     = NTOHS (Packet->Ack.Block[0]);
  Expected   = Mtftp4GetNextBlockNum (&Instance->Blocks);
  ASSERT (Expected >= 0);
  if (Expected != AckNum) {
    return EFI_SUCCESS;
  }
  Mtftp4RemoveBlockNum (&Instance->Blocks, AckNum, *Completed, &BlockCounter);
  Expected = Mtftp4GetNextBlockNum (&Instance->Blocks);
  if (Expected < 0) {
    if (Instance->LastBlock == AckNum) {
      ASSERT (Instance->LastBlock >= 1);
      *Completed = TRUE;
      return EFI_SUCCESS;
    } else {
      Mtftp4SendError (
        Instance,
        EFI_MTFTP4_ERRORCODE_REQUEST_DENIED,
        (UINT8 *)"Block number rolls back, not supported, try blksize option"
        );
      return EFI_TFTP_ERROR;
    }
  }
  return Mtftp4WrqSendBlock (Instance, (UINT16)Expected);
}