📄 irfir.cpp
字号:
*BytesWritten = sizeof(v_rgSupportedOids);
NdisMoveMemory(InformationBuffer, (PVOID)v_rgSupportedOids, sizeof(v_rgSupportedOids));
*BytesNeeded = 0;
break;
case OID_GEN_VENDOR_DRIVER_VERSION:
DEBUGMSG(ZONE_QUERYINFO, (TEXT("IrFir: IrFirQueryInformation(OID_GEN_VENDOR_DRIVER_VERSION)\r\n")));
*(UINT *)InformationBuffer = VENDOR_DRIVER_VERSION;
*BytesWritten = sizeof(UINT);
*BytesNeeded = 0;
break;
case OID_IRDA_RECEIVING:
DEBUGMSG(ZONE_QUERYINFO, (TEXT("IrFir: IrFirQueryInformation(OID_IRDA_RECEIVING)\r\n")));
*(UINT *)InformationBuffer = (UINT)thisDev->nowReceiving;
*BytesWritten = sizeof(UINT);
*BytesNeeded = 0;
break;
case OID_IRDA_MAX_RECEIVE_WINDOW_SIZE:
DEBUGMSG(ZONE_QUERYINFO, (TEXT("IrFir: IrFirQueryInformation(OID_IRDA_MAX_RECEIVE_WINDOW_SIZE)\r\n")));
*(UINT *)InformationBuffer = MAXIMUM_RCV_PACKETS;
*BytesWritten = sizeof(UINT);
*BytesNeeded = 0;
break;
case OID_IRDA_SUPPORTED_SPEEDS:
DEBUGMSG(ZONE_QUERYINFO, (TEXT("IrFir: IrFirQueryInformation(OID_IRDA_SUPPORTED_SPEEDS)\r\n")));
speeds = CURRENT_SUPPORTED_SPEEDS & ALL_IRDA_SPEEDS;
*BytesWritten = 0;
for (i = 0, infoPtr = (PUINT)InformationBuffer; (i < NUM_BAUDRATES) && speeds &&
(InformationBufferLength >= sizeof(UINT)); i++)
{
if (supportedBaudRateTable[i].ndisCode & speeds)
{
*infoPtr++ = supportedBaudRateTable[i].bitsPerSec;
InformationBufferLength -= sizeof(UINT);
*BytesWritten += sizeof(UINT);
speeds &= ~supportedBaudRateTable[i].ndisCode;
DEBUGMSG(ZONE_QUERYINFO, (TEXT("IrFir: - supporting speed %d bps\r\n"), supportedBaudRateTable[i].bitsPerSec));
}
}
// We ran out of room in InformationBuffer.
// Count the remaining number of bits set in speeds
// to figure out the number of remaining bytes needed.
if (speeds)
{
for (*BytesNeeded = 0; speeds; *BytesNeeded += sizeof(UINT))
speeds &= (speeds - 1); //This instruction clears the lowest set bit in speeds
*BytesWritten = 0;
result = NDIS_STATUS_INVALID_LENGTH;
}
else
{
result = NDIS_STATUS_SUCCESS;
*BytesNeeded = 0;
}
break;
case OID_IRDA_LINK_SPEED:
DEBUGMSG(ZONE_QUERYINFO, (TEXT("IrFir: IrFirQueryInformation(OID_IRDA_LINK_SPEED, %d)\r\n"),thisDev->linkSpeedInfo->bitsPerSec));
if (thisDev->linkSpeedInfo)
*(UINT *)InformationBuffer = thisDev->linkSpeedInfo->bitsPerSec;
else
*(UINT *)InformationBuffer = DEFAULT_BAUD_RATE;
*BytesWritten = sizeof(UINT);
*BytesNeeded = 0;
break;
case OID_IRDA_MEDIA_BUSY:
DEBUGMSG(ZONE_QUERYINFO, (TEXT("IrFir: IrFirQueryInformation(OID_IRDA_MEDIA_BUSY)\r\n")));
*(UINT *)InformationBuffer = (UINT)thisDev->mediaBusy;
*BytesWritten = sizeof(UINT);
*BytesNeeded = 0;
break;
case OID_IRDA_RELEASE_HW_RESOURCES:
DEBUGMSG(ZONE_QUERYINFO, (TEXT("IrFir: IrFirQueryInformation(OID_IRDA_RELEASE_HW_RESOURCES)\r\n")));
if (thisDev->resourcesReleased == TRUE)
{
*BytesWritten = 0;
result = NDIS_STATUS_FAILURE;
DEBUGMSG(ZONE_QUERYINFO, (TEXT("IrFir: FIRI Query: resources already released!!!\r\n")));
}
else
{
HANDLE hRelThread;
DWORD dwRelThreadId;
*BytesWritten = sizeof(UINT);
hRelThread = CreateThread(NULL, 0, ReleaseAdapterResources, thisDev, 0, &dwRelThreadId);
if (hRelThread == NULL)
result = NDIS_STATUS_RESOURCES;
else
{
CloseHandle(hRelThread);
result = NDIS_STATUS_PENDING;
}
}
break;
case OID_GEN_MAXIMUM_LOOKAHEAD:
DEBUGMSG(ZONE_QUERYINFO, (TEXT("IrFir: IrFirQueryInformation(OID_GEN_MAXIMUM_LOOKAHEAD)\r\n")));
*(UINT *)InformationBuffer = MAXIMUM_LOOKAHEAD;
*BytesWritten = sizeof(UINT);
*BytesNeeded = 0;
break;
case OID_GEN_MAC_OPTIONS:
DEBUGMSG(ZONE_QUERYINFO, (TEXT("IrFir: IrFirQueryInformation(OID_GEN_MAC_OPTIONS)\r\n")));
*(UINT *)InformationBuffer = NDIS_MAC_OPTION_COPY_LOOKAHEAD_DATA | NDIS_MAC_OPTION_TRANSFERS_NOT_PEND;
*BytesWritten = sizeof(UINT);
*BytesNeeded = 0;
break;
case OID_GEN_MAXIMUM_SEND_PACKETS:
DEBUGMSG(ZONE_QUERYINFO, (TEXT("IrFir: IrFirQueryInformation(OID_GEN_MAXIMUM_SEND_PACKETS)\r\n")));
*(UINT *)InformationBuffer = MAXIMUM_SEND_PACKETS;
*BytesWritten = sizeof(UINT);
*BytesNeeded = 0;
break;
case OID_IRDA_TURNAROUND_TIME:
// Indicate the amount of time that the transceiver needs
// to recuperate after a send.
DEBUGMSG(ZONE_QUERYINFO, (TEXT("IrFir: IrFirQueryInformation(OID_IRDA_TURNAROUND_TIME)\r\n")));
*(UINT *)InformationBuffer = DEFAULT_TURNAROUND_TIME;
*BytesWritten = sizeof(UINT);
*BytesNeeded = 0;
break;
case OID_IRDA_EXTRA_RCV_BOFS:
// Pass back the number of _extra_ BOFs to be prepended
// to packets sent to this unit at 115.2 baud, the
// maximum Slow IR speed. This will be scaled for other
// speed according to the table in the
// 'Infrared Extensions to NDIS' spec.
DEBUGMSG(ZONE_QUERYINFO, (TEXT("IrFir: IrFirQueryInformation(OID_IRDA_EXTRA_RCV_BOFS)\r\n")));
*(UINT *)InformationBuffer = DEFAULT_EXTRA_BOF_REQUIRED;
*BytesWritten = sizeof(UINT);
*BytesNeeded = 0;
break;
case OID_GEN_CURRENT_PACKET_FILTER:
DEBUGMSG(ZONE_QUERYINFO, (TEXT("IrFir: IrFirQueryInformation(OID_GEN_CURRENT_PACKET_FILTER)\r\n")));
*(UINT *)InformationBuffer = NDIS_PACKET_TYPE_PROMISCUOUS;
*BytesWritten = sizeof(UINT);
*BytesNeeded = 0;
break;
case OID_GEN_MAXIMUM_FRAME_SIZE:
DEBUGMSG(ZONE_QUERYINFO, (TEXT("IrFir: IrFirQueryInformation(OID_GEN_MAXIMUM_FRAME_SIZE)\r\n")));
*(UINT *)InformationBuffer = MAX_IR_FRAME_SIZE;
*BytesWritten = sizeof(UINT);
*BytesNeeded = 0;
break;
case OID_IRDA_UNICAST_LIST:
DEBUGMSG(ZONE_QUERYINFO, (TEXT("IrFir: IrFirQueryInformation(OID_IRDA_UNICAST_LIST)\r\n")));
case OID_IRDA_MAX_UNICAST_LIST_SIZE:
DEBUGMSG(ZONE_QUERYINFO, (TEXT("IrFir: IrFirQueryInformation(OID_IRDA_MAX_UNICAST_LIST_SIZE)\r\n")));
case OID_IRDA_RATE_SNIFF:
DEBUGMSG(ZONE_QUERYINFO, (TEXT("IrFir: IrFirQueryInformation(OID_IRDA_RATE_SNIFF)\r\n")));
// Power management OID's
case OID_PNP_CAPABILITIES:
DEBUGMSG(ZONE_QUERYINFO, (TEXT("IrFir: IrFirQueryInformation(OID_PNP_CAPABILITIES)\r\n")));
// Advertise our powermanagement capabilities
// we return by telling wake up is not supported, since Mx31 BSP supports only D0 and D4.
FirPMCapabilities.Flags = 0 ;
FirPMCapabilities.WakeUpCapabilities.MinMagicPacketWakeUp = NdisDeviceStateUnspecified;
FirPMCapabilities.WakeUpCapabilities.MinPatternWakeUp = NdisDeviceStateUnspecified;
FirPMCapabilities.WakeUpCapabilities.MinLinkChangeWakeUp = NdisDeviceStateUnspecified;
InformationBufferLength = sizeof (FirPMCapabilities);
InformationBuffer = (PVOID)&FirPMCapabilities;
*BytesWritten = sizeof(NDIS_PNP_CAPABILITIES);
*BytesNeeded = 0;
result = NDIS_STATUS_SUCCESS;
break;
case OID_PNP_QUERY_POWER:
DEBUGMSG(ZONE_QUERYINFO, (TEXT("IrFir: IrFirQueryInformation(OID_PNP_QUERY_POWER)\r\n")));
DEVICE_POWER_STATE DevicePowerState;
DevicePowerState = *(PDEVICE_POWER_STATE)InformationBuffer;
DEBUGMSG (ZONE_QUERYINFO,
(TEXT("IrFir: IrFirQueryInformation OID_PNP_QUERY_POWER for [%s].\r\n"),
(DevicePowerState == NdisDeviceStateD0) ? TEXT("NdisDeviceStateD0"):
(DevicePowerState == NdisDeviceStateD1) ? TEXT("NdisDeviceStateD1"):
(DevicePowerState == NdisDeviceStateD2) ? TEXT("NdisDeviceStateD2"):
(DevicePowerState == NdisDeviceStateD3) ? TEXT("NdisDeviceStateD3"):
TEXT("UNKNOWN")));
*BytesWritten = 0;
*BytesNeeded = 0;
result = NDIS_STATUS_SUCCESS;
break;
default:
DEBUGMSG(ZONE_QUERYINFO, (TEXT("IrFir: IrFirQueryInformation(0x%x), unsupported OID\r\n"), Oid));
result = NDIS_STATUS_NOT_SUPPORTED;
break;
}
NdisReleaseSpinLock(&thisDev->Lock);
}
else
{
*BytesNeeded = sizeof(UINT) - InformationBufferLength;
*BytesWritten = 0;
result = NDIS_STATUS_INVALID_LENGTH;
}
DEBUGMSG(ZONE_QUERYINFO, (TEXT("IrFir: IrFirQueryInformation succeeded (info <- %d)\r\n"), *(UINT *)InformationBuffer));
return result;
}
//-----------------------------------------------------------------------------
//
// Function: IrFirReset
//
// This function retrieves the current
// properties of the communications device.
//
// Parameters:
// AddressingReset
// [in] .
// MiniportAdapterContext
// [in] .
//
// Returns:
// This function returns status of reset.
//
//-----------------------------------------------------------------------------
NDIS_STATUS IrFirReset( PBOOLEAN AddressingReset, NDIS_HANDLE MiniportAdapterContext )
{
pFirDevice_t dev, thisDev = (pFirDevice_t)MiniportAdapterContext;
DEBUGMSG(ZONE_FUNCTION, (TEXT("IrFir: IrFirReset(0x%x)\r\n"), (UINT)MiniportAdapterContext));
// Verify that the context is not bogus.
// I've seen bad contexts getting passed in when the system gets corrupted.
for (dev = gFirstFirDevice; dev && (dev != thisDev); dev = dev->next);
if (!dev)
{
DEBUGMSG(ZONE_WARN, (TEXT("IrFir: Bad context in IrFirReset\r\n")));
return NDIS_STATUS_FAILURE;
}
NdisAcquireSpinLock(&thisDev->Lock);
thisDev->IR_VTbl->m_pReleaseAdapterResources(thisDev);
//thisDev->linkSpeedInfo->bitsPerSec = thisDev->newSpeed; // make sure we are resuming from last break point
thisDev->IR_VTbl->m_pAcquireAdapterResources(thisDev);
thisDev->IR_VTbl->m_pSetupRecv(thisDev);
NdisReleaseSpinLock(&thisDev->Lock);
*AddressingReset = TRUE;
DEBUGMSG(ZONE_FUNCTION, (TEXT("IrFir: IrFirReset done.\r\n")));
return NDIS_STATUS_SUCCESS;
}
//-----------------------------------------------------------------------------
//
// Function: IrFirSend
//
// This function Transmits a packet onto the medium..
//
// Parameters:
// MiniportAdapterContext
// [in] .
// Packet
// [in] .
// Flags
// [in] .
//
// Returns:
// This function returns the status of sending the packet.
//
//-----------------------------------------------------------------------------
NDIS_STATUS IrFirSend( IN NDIS_HANDLE MiniportAdapterContext, IN PNDIS_PACKET Packet, IN UINT Flags )
{
NDIS_STATUS stat;
pFirDevice_t thisDev = (pFirDevice_t)MiniportAdapterContext;
DEBUGMSG(ZONE_FUNCTION, (TEXT("IrFir: +IrFirSend(0x%x, packet = 0x%x)\r\n"), (UINT)MiniportAdapterContext, Packet));
// If we have temporarily lost access to the hardware, don't queue up any sends.
// return failure until we regain access to the hw.
NdisAcquireSpinLock(&thisDev->Lock);
if (thisDev->resourcesReleased)
{
NdisReleaseSpinLock(&thisDev->Lock);
ASSERT(FALSE);
return (NDIS_STATUS_FAILURE);
}
stat = thisDev->IR_VTbl->m_pSendPacket(thisDev, Packet);
NdisReleaseSpinLock(&thisDev->Lock);
DEBUGMSG(ZONE_FUNCTION, (TEXT("IrFir: -IrFirSend [%s]\r\n"), DBG_NDIS_RESULT_STR(stat)));
return (stat);
}
//-----------------------------------------------------------------------------
//
// Function: IrFirSetInformation
//
// This function allows other layers of the network software (e.g., a transport driver) to control
// the miniport driver by changing information that the miniport driver maintains in its OIDs,
// such as the packet filters or multicast addresses.
//
// Parameters:
// MiniportAdapterContext
// [in] .
// Oid
// [in] .
// InformationBuffer
// [in] .
// InformationBufferLength
// [in] .
// BytesRead
// [in] .
// BytesNeeded
// [in] .
//
// Returns:
// This function returns status of the action.
//
//-----------------------------------------------------------------------------
NDIS_STATUS IrFirSetInformation( IN NDIS_HANDLE MiniportAdapterContext, IN NDIS_OID Oid, IN PVOID InformationBuffer,
IN ULONG InformationBufferLength, OUT PULONG BytesRead, OUT PULONG BytesNeeded )
{
NDIS_STATUS result = NDIS_STATUS_SUCCESS;
pFirDevice_t thisDev = (pFirDevice_t)MiniportAdapterContext;
NDIS_DEVICE_POWER_STATE NewPowerState; // Power state
DEBUGMSG(ZONE_SETINFO, (TEXT("IrFir: +IrFirSetInformation(%d)\r\n"), Oid));
if (InformationBufferLength >= sizeof(UINT))
{
UINT info;
*BytesRead = sizeof(UINT);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -