📄 init.c
字号:
ASSERT(IsListEmpty(&Adapter->RecvFreeList));
NdisFreeSpinLock(&Adapter->RecvLock);
//
// Finally free the memory for adapter context.
//
NdisFreeMemory(Adapter, sizeof(MP_ADAPTER), 0);
DEBUGP(MP_TRACE, ("<-- NICFreeAdapter\n"));
}
void NICAttachAdapter(PMP_ADAPTER Adapter)
{
DEBUGP(MP_TRACE, ("--> NICAttachAdapter\n"));
NdisInterlockedInsertTailList(
&GlobalData.AdapterList,
&Adapter->List,
&GlobalData.Lock);
DEBUGP(MP_TRACE, ("<-- NICAttachAdapter\n"));
}
void NICDetachAdapter(PMP_ADAPTER Adapter)
{
DEBUGP(MP_TRACE, ("--> NICDetachAdapter\n"));
NdisAcquireSpinLock(&GlobalData.Lock);
RemoveEntryList(&Adapter->List);
NdisReleaseSpinLock(&GlobalData.Lock);
DEBUGP(MP_TRACE, ("<-- NICDetachAdapter\n"));
}
NDIS_STATUS
NICReadRegParameters(
PMP_ADAPTER Adapter,
NDIS_HANDLE WrapperConfigurationContext)
/*++
Routine Description:
Read device configuration parameters from the registry
Arguments:
Adapter Pointer to our adapter
WrapperConfigurationContext For use by NdisOpenConfiguration
Should be called at IRQL = PASSIVE_LEVEL.
Return Value:
NDIS_STATUS_SUCCESS
NDIS_STATUS_FAILURE
NDIS_STATUS_RESOURCES
--*/
{
NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
NDIS_HANDLE ConfigurationHandle;
PUCHAR NetworkAddress;
UINT Length;
PUCHAR pAddr;
static ULONG g_ulAddress = 0;
DEBUGP(MP_TRACE, ("--> NICReadRegParameters\n"));
//
// Open the registry for this adapter to read advanced
// configuration parameters stored by the INF file.
//
NdisOpenConfiguration(
&Status,
&ConfigurationHandle,
WrapperConfigurationContext);
if(Status != NDIS_STATUS_SUCCESS)
{
DEBUGP(MP_ERROR, ("NdisOpenConfiguration failed\n"));
return NDIS_STATUS_FAILURE;
}
//
// Read all of our configuration parameters using NdisReadConfiguration
// and parse the value.
//
//
// Just for testing purposes, let us make up a dummy mac address.
// In order to avoid conflicts with MAC addresses, it is usually a good
// idea to check the IEEE OUI list (e.g. at
// http://standards.ieee.org/regauth/oui/oui.txt). According to that
// list 00-50-F2 is owned by Microsoft.
//
// An important rule to "generating" MAC addresses is to have the
// "locally administered bit" set in the address, which is bit 0x02 for
// LSB-type networks like Ethernet. Also make sure to never set the
// multicast bit in any MAC address: bit 0x01 in LSB networks.
//
pAddr = (PUCHAR) &g_ulAddress;
++g_ulAddress;
Adapter->PermanentAddress[0] = 0x02;
Adapter->PermanentAddress[1] = 0x50;
Adapter->PermanentAddress[2] = 0xF2;
Adapter->PermanentAddress[3] = 0x00;
Adapter->PermanentAddress[4] = 0x00;
Adapter->PermanentAddress[5] = pAddr[0];
ETH_COPY_NETWORK_ADDRESS(
Adapter->CurrentAddress,
Adapter->PermanentAddress);
//
// Read NetworkAddress registry value and use it as the current address
// if there is a software configurable NetworkAddress specified in
// the registry.
//
NdisReadNetworkAddress(
&Status,
&NetworkAddress,
&Length,
ConfigurationHandle);
if((Status == NDIS_STATUS_SUCCESS) && (Length == ETH_LENGTH_OF_ADDRESS) )
{
if ((ETH_IS_MULTICAST(NetworkAddress)
|| ETH_IS_BROADCAST(NetworkAddress))
|| !ETH_IS_LOCALLY_ADMINISTERED (NetworkAddress))
{
DEBUGP(MP_ERROR,
("Overriding NetworkAddress is invalid - %02x-%02x-%02x-%02x-%02x-%02x\n",
NetworkAddress[0], NetworkAddress[1], NetworkAddress[2],
NetworkAddress[3], NetworkAddress[4], NetworkAddress[5]));
}
else
{
ETH_COPY_NETWORK_ADDRESS(Adapter->CurrentAddress, NetworkAddress);
}
}
DEBUGP(MP_LOUD, ("Permanent Address = %02x-%02x-%02x-%02x-%02x-%02x\n",
Adapter->PermanentAddress[0],
Adapter->PermanentAddress[1],
Adapter->PermanentAddress[2],
Adapter->PermanentAddress[3],
Adapter->PermanentAddress[4],
Adapter->PermanentAddress[5]));
DEBUGP(MP_LOUD, ("Current Address = %02x-%02x-%02x-%02x-%02x-%02x\n",
Adapter->CurrentAddress[0],
Adapter->CurrentAddress[1],
Adapter->CurrentAddress[2],
Adapter->CurrentAddress[3],
Adapter->CurrentAddress[4],
Adapter->CurrentAddress[5]));
Adapter->ulLinkSpeed = NIC_LINK_SPEED;
//
// Close the configuration registry
//
NdisCloseConfiguration(ConfigurationHandle);
DEBUGP(MP_TRACE, ("<-- NICReadRegParameters\n"));
return NDIS_STATUS_SUCCESS;
}
NDIS_STATUS NICInitializeAdapter(
IN PMP_ADAPTER Adapter,
IN NDIS_HANDLE WrapperConfigurationContext
)
/*++
Routine Description:
Query assigned resources and initialize the adapter.
Arguments:
Adapter Pointer to our adapter
Return Value:
NDIS_STATUS_SUCCESS
NDIS_STATUS_ADAPTER_NOT_FOUND
--*/
{
NDIS_STATUS Status = NDIS_STATUS_ADAPTER_NOT_FOUND;
UCHAR resBuf[NIC_RESOURCE_BUF_SIZE];
PNDIS_RESOURCE_LIST resList = (PNDIS_RESOURCE_LIST)resBuf;
UINT bufSize = NIC_RESOURCE_BUF_SIZE;
PCM_PARTIAL_RESOURCE_DESCRIPTOR pResDesc;
ULONG index;
DEBUGP(MP_TRACE, ("---> InitializeAdapter\n"));
do
{
//
// Get the resources assigned by the PNP manager. NDIS gets
// these resources in IRP_MN_START_DEVICE request.
//
NdisMQueryAdapterResources(
&Status,
WrapperConfigurationContext,
resList,
&bufSize);
if (Status == NDIS_STATUS_SUCCESS)
{
for (index=0; index < resList->Count; index++)
{
pResDesc = &resList->PartialDescriptors[index];
switch(pResDesc->Type)
{
case CmResourceTypePort:
DEBUGP(MP_INFO, ("IoBaseAddress = 0x%x\n",
NdisGetPhysicalAddressLow(pResDesc->u.Port.Start)));
DEBUGP(MP_INFO, ("IoRange = x%x\n",
pResDesc->u.Port.Length));
break;
case CmResourceTypeInterrupt:
DEBUGP(MP_INFO, ("InterruptLevel = x%x\n",
pResDesc->u.Interrupt.Level));
break;
case CmResourceTypeMemory:
DEBUGP(MP_INFO, ("MemPhysAddress(Low) = 0x%0x\n",
NdisGetPhysicalAddressLow(pResDesc->u.Memory.Start)));
DEBUGP(MP_INFO, ("MemPhysAddress(High) = 0x%0x\n",
NdisGetPhysicalAddressHigh(pResDesc->u.Memory.Start)));
break;
}
}
}
Status = NDIS_STATUS_SUCCESS;
//
// Map bus-relative IO range to system IO space using
// NdisMRegisterIoPortRange
//
//
// Map bus-relative registers to virtual system-space
// using NdisMMapIoSpace
//
//
// Disable interrupts here as soon as possible
//
//
// Register the interrupt using NdisMRegisterInterrupt
//
//
// Initialize the hardware with mapped resources
//
#ifdef NDIS50_MINIPORT
//
// Register a shutdown handler for NDIS50 or earlier miniports
// For NDIS51 miniports, set AdapterShutdownHandler.
//
NdisMRegisterAdapterShutdownHandler(
Adapter->AdapterHandle,
(PVOID) Adapter,
(ADAPTER_SHUTDOWN_HANDLER) MPShutdown);
#endif
//
// Enable the interrupt
//
} while (FALSE);
DEBUGP(MP_TRACE, ("<--- InitializeAdapter, Status=%x\n", Status));
return Status;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -