📄 miniport.cpp
字号:
IN ULONG cbBuf,
OUT PULONG lpcbRead,
OUT PULONG lpcbNeeded
)
{
IRMiniport * pMiniport = (IRMiniport *)hContext;
NDIS_STATUS status = NDIS_STATUS_SUCCESS;
ASSERT(lpvBuf != NULL);
ASSERT(lpcbRead != NULL);
ASSERT(lpcbNeeded != NULL);
DEBUGMSG(ZONE_SETINFO,
(TEXT("+MiniportSetInformation(0x%.8X, 0x%.8X, 0x%.8x, %d, ")
TEXT("0x%.8X, 0x%.8X)\r\n"),
hContext, Oid, lpvBuf, cbBuf, lpcbRead, lpcbNeeded)
);
//
// Set defaults.
//
*lpcbRead = sizeof(UINT);
*lpcbNeeded = 0;
switch (Oid)
{
//
// Generic OIDs.
//
case OID_GEN_CURRENT_PACKET_FILTER:
DEBUGMSG(ZONE_SETINFO, (TEXT("Set: OID_GEN_CURRENT_PACKET_FILTER\r\n")));
break;
case OID_GEN_CURRENT_LOOKAHEAD:
DEBUGMSG(ZONE_SETINFO, (TEXT("Set: OID_GEN_CURRENT_LOOKAHEAD\r\n")));
// This is only a suggestion from the protocol.
// We always indicate the entire frame at once. Ignore this.
break;
case OID_GEN_PROTOCOL_OPTIONS:
DEBUGMSG(ZONE_SETINFO, (TEXT("Set: OID_GEN_PROTOCOL_OPTIONS\r\n")));
// Flags to help out the miniport. Ignore.
break;
//
// IrDA OIDs.
//
//
// This changes the link speed after the current transmitions is performed.
// This new link speed applies to all packets send after this call.
//
// Looking at the CEPC NSC driver it seems that we don't have to create
// a worker thread.
//
case OID_IRDA_LINK_SPEED:
DEBUGMSG(ZONE_SETINFO, (TEXT("Set: OID_IRDA_LINK_SPEED\r\n")));
status = pMiniport->ChangeBaudRate( *(UINT *)lpvBuf);
break;
case OID_IRDA_MEDIA_BUSY:
DEBUGMSG(ZONE_SETINFO, (TEXT("Set: OID_IRDA_MEDIA_BUSY\r\n")));
pMiniport->m_fMediaBusy = FALSE;
break;
//
// This API allows the IRDA driver to share the hardware with
// the serial port. This feature I don't currently support.
//
// Resources are always acquired in this driver.
//
case OID_IRDA_REACQUIRE_HW_RESOURCES:
DEBUGMSG(ZONE_SETINFO, (TEXT("Set: OID_IRDA_REACQUIRE_HW_RESOURCES\r\n")));
break;
//
// Unsupported IrDA OIDs.
//
case OID_IRDA_RELEASE_HW_RESOURCES:
DEBUGMSG(ZONE_SETINFO, (TEXT("Set: OID_IRDA_REACQUIRE_HW_RESOURCES\r\n")));
*lpcbRead = 0;
*lpcbNeeded = 0;
status = NDIS_STATUS_NOT_SUPPORTED;
break;
case OID_IRDA_RATE_SNIFF:
case OID_IRDA_UNICAST_LIST:
case OID_IRDA_MAX_UNICAST_LIST_SIZE:
*lpcbRead = 0;
*lpcbNeeded = 0;
status = NDIS_STATUS_NOT_SUPPORTED;
break;
// Many query only OIDs -> invalid set OIDs.
default:
*lpcbRead = 0;
*lpcbNeeded = 0;
status = NDIS_STATUS_INVALID_OID;
break;
}
DEBUGMSG(ZONE_SETINFO,
(TEXT("-MiniportSetInformation [status = 0x%.8X, %dL]")
TEXT(" *lpcbWritten = %d, *lpcbNeeded = %d.\r\n"),
status, status, *lpcbRead, *lpcbNeeded)
);
return (status);
}
//****************************************************************************
// MiniportReset
//****************************************************************************
// Resets the miniports software/hardware state.
//
// Arguments:
//
// lpfAddressingReset - Points to a variable that MiniportReset sets to
// TRUE if the NDIS library should call
// MiniportSetInformation to restore addressing
// information to the current values.
//
// hContext - Pointer to IR device context.
//
// Returns:
//
// NDIS_STATUS Code.
//
//
//
// Success - NDIS_STATUS_SUCCESS.
// NDIS_STATUS_PENDING
//
// Failure - NDIS_STATUS_NOT_RESETTABLE
// NDIS_STATUS_RESET_IN_PROGRESS
// NDIS_STATUS_SOFT_ERRORS
// NDIS_STATUS_HARD_ERRORS
//
NDIS_STATUS MiniportReset
(
OUT PBOOLEAN lpfAddressingReset,
IN NDIS_HANDLE hContext
)
{
IRMiniport * pMiniport = (IRMiniport *)hContext;
NDIS_STATUS status = NDIS_STATUS_SUCCESS;
BOOL fRestartDevice = FALSE;
PRX_BUFFER pRxBuf;
DEBUGMSG(ZONE_INIT,
(TEXT("+MiniportReset(0x%.8X, 0x%.8X)\r\n"),
lpfAddressingReset, hContext));
//
// Acquire the critical section.
//
EnterCriticalSection( &pMiniport->m_ListCriticalSection);
//
// Change the baud rate to 9600.
//
pMiniport->ChangeBaudRate(9600);
//
// Initialize the recieve buffer list.
//
pMiniport->m_ReceivePacketList.Reset();
//
// Clear out the list of transmit buffers.
//
while(pMiniport->m_SendPacketList.RemoveNextPacket());
//
// Get the first free item.
//
pRxBuf = pMiniport->m_ReceivePacketList.GetFree();
//
// Clear out the SIR state machine.
// Set the next buffer location.
//
pMiniport->m_SirState.SetNextBuffer(pRxBuf);
pMiniport->m_SirState.ClearStats();
//
// Release the critical section.
//
LeaveCriticalSection( &pMiniport->m_ListCriticalSection);
DEBUGMSG(ZONE_INIT, (TEXT("-MiniportReset [0x%.8X]\r\n"), status));
return(status);
}
//****************************************************************************
// MiniportSend
//****************************************************************************
// Send a packet to the serial port.
//
// Arguments:
//
// hContext - Pointer to the current IR_DEVICE object.
//
// pNdisPacket - NDIS packet to send.
//
// Flags - Any flags set by the protocol. (This is protocol specific).
//
// Returns:
//
// NDIS_STATUS_PENDING - This is generally what we should return. We will
// call NdisMSendComplete when the data is actually
// sent.
//
// NDIS_STATUS_FAILURE - The packet was invalid.
//
// Comments:
//
// We will need to put this write packet on a queue if there is another
// packet pending completion.
//
NDIS_STATUS MiniportSend
(
IN NDIS_HANDLE hContext,
IN PNDIS_PACKET pNdisPacket,
IN UINT Flags
)
{
DEBUGMSG(ZONE_INIT,
(TEXT("+MiniportSend(0x%.8X, 0x%.8X, 0x%.8X)\r\n"),
(ULONG)hContext, (ULONG)pNdisPacket, (ULONG)Flags));
ASSERT(hContext);
ASSERT(pNdisPacket);
IRMiniport * pIrMiniport = (IRMiniport *)hContext;
//
// Enter the critcal section to protect the list.
//
EnterCriticalSection( &pIrMiniport->m_ListCriticalSection);
//
// Add the Packet to the list.
//
pIrMiniport->m_SendPacketList.AddPendingPacket(pNdisPacket);
//
// If there are no packets on the IR stack, set it up.
//
pIrMiniport->GetNextSirPacket();
//
// leave the critcal section to protect the list.
//
LeaveCriticalSection( &pIrMiniport->m_ListCriticalSection);
DEBUGMSG(ZONE_INIT, (TEXT("-MiniportSend [0x%.8X]\r\n"), NDIS_STATUS_PENDING));
return(NDIS_STATUS_PENDING);
}
//****************************************************************************
// MiniportReturnPacket
//****************************************************************************
// Protocol is returning ownership of a receive packet to the miniport.
//
// Arguments:
//
// pMiniport - Pointer to the device context.
//
// pNdisPacket - Pointer to the returned NDIS packet.
//
//
VOID MiniportReturnPacket
(
IN NDIS_HANDLE hMiniportAdapterContext,
IN PNDIS_PACKET pNdisPacket
)
{
IRMiniport * pIrMiniport = (IRMiniport *)hMiniportAdapterContext;
PRX_BUFFER pRxBuf;
DEBUGMSG(ZONE_RECV,
(TEXT("+MiniportReturnPacket(0x%.8X, 0x%.8X)\r\n"),
hMiniportAdapterContext, pNdisPacket)
);
//
// Find buffer on pending queue.
//
pRxBuf = pIrMiniport->m_ReceivePacketList.RemovePendingBuffer(pNdisPacket);
//
// We put it on the queue, it should be there now!!
//
ASSERT(pRxBuf != NULL);
//
// Return buffer to free queue.
//
pIrMiniport->m_ReceivePacketList.ReturnBuffer(pRxBuf);
DEBUGMSG(ZONE_RECV, (TEXT("-MiniportReturnPacket\r\n")));
}
//****************************************************************************
// IRMiniport::ChangeBaudRate
//****************************************************************************
// This waits for all the packets to be transmitted. Then the baud rate is
// changed.
//
//
NDIS_STATUS IRMiniport::ChangeBaudRate( ULONG ulBaudRate)
{
ULONG ulNumberOfTries;
BOOL bExit;
NDIS_STATUS ulStatus;
//
// If we are already at the currect baud rate, just return.
//
if(ulBaudRate == GetCurrentBaudRate())
{
return NDIS_STATUS_SUCCESS;
}
//
// Check to make sure that the baud rate is supported.
//
if(!BaudRateSupported(ulBaudRate))
{
return NDIS_STATUS_FAILURE;
}
//
// Set the Status to the default value.
//
ulStatus = NDIS_STATUS_SUCCESS;
//
// Enter the critcal section to protect the list.
//
EnterCriticalSection( &m_ListCriticalSection);
if(!m_pSIRTransmitNDisPacket)
{
//
// Set the New Baud Rate.
//
ulStatus = SetHWBaudRate(ulBaudRate);
}
else
{
m_ulNextBaudRate = ulBaudRate;
}
//
// Leave the critcal section to protect the list.
//
LeaveCriticalSection( &m_ListCriticalSection);
return ulStatus;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -