📄 card.c
字号:
/*++
Copyright (c) 1999 SDMC Co., Ltd.
Module Name:
Card.c
Abstract:
This is the main file for the DVB-S fast modem NIC.
This driver conforms to the NDIS 5.0 miniport interface.
The overall structure and much of the code is taken from
the NE2000 driver included in Microsoft NT3.5 DDK.
Environment:
Kernel mode, FSD
Revision History:
28/04/2005 ----- hanney
--*/
#include <ndis.h>
#include "RTSNT_SW.H"
#include "bit.h"
//#include "halMAC.h"
#define NdisMSleep(x) KeStallExecutionProcessor(x)
extern DRIVER_BLOCK RTFast_MiniportBlock;
// Removed by hanney on Apr 28th 2005
/*
#pragma NDIS_PAGEABLE_FUNCTION(ReadCardVersion)
*/
#pragma NDIS_PAGEABLE_FUNCTION(CardInitialize)
/*++
Routine Description:
Initializes the card into a running state.
Arguments:
Adapter - pointer to the adapter block.
Return Value:
TRUE, if all goes well, else FALSE.
--*/
BOOLEAN
CardInitialize(
IN PRTFAST_ADAPTER Adapter
)
{
return(TRUE);
}
#pragma NDIS_PAGEABLE_FUNCTION(CardReadEthernetAddress)
/*++
Routine Description:
Reads in the Ethernet address from the Novell 2000.
Arguments:
Adapter - pointer to the adapter block.
Return Value:
The address is stored in Adapter->PermanentAddress, and StationAddress if it
is currently zero.
--*/
VOID
CardReadEthernetAddress(
IN PRTFAST_ADAPTER Adapter
)
{
// << Prashanth
UNICODE_STRING CastKeyName;
UNICODE_STRING CastValueName[6];
UNICODE_STRING CastValueData;
HANDLE CastKey;
OBJECT_ATTRIBUTES objAttr;
ULONG data;
ULONG dwRet;
int i;
UCHAR strMAC[6];
ULONG regDword;
PKEY_VALUE_PARTIAL_INFORMATION valueInfoP;
ULONG valueInfoLength,returnLength;
// >> Prashanth
///////////////////////
NTSTATUS Status;
HANDLE FileHandle;
OBJECT_ATTRIBUTES FObject;
IO_STATUS_BLOCK IOSB;
UNICODE_STRING FileName;
LARGE_INTEGER NtosFileOffset;
////////////////////////
UINT ii;
//UCHAR Status;
BOOLEAN bRet = FALSE;
for(ii = 0; ii < RTFAST_LENGTH_OF_ADDRESS; ii++)
Adapter->PermanentAddress[ii] = 0x00;
/* Adapter->PermanentAddress[0] = 0x00;
Adapter->PermanentAddress[1] = 0x01;
Adapter->PermanentAddress[2] = 0x4c;
Adapter->PermanentAddress[3] = 0x39;
Adapter->PermanentAddress[4] = 0x00;
Adapter->PermanentAddress[5] = 0xf0;*/
for(ii = 0; ii < RTFAST_LENGTH_OF_ADDRESS; ii++)
Adapter->StationAddress[ii] = Adapter->PermanentAddress[ii];
RtlInitUnicodeString ( &FileName, L"\\SystemRoot\\system32\\drivers\\halMac.ini" );
InitializeObjectAttributes (
&FObject,
&FileName,
OBJ_KERNEL_HANDLE,
NULL,
NULL);
for (ii = 0; ii < 50; ii++)
{
Status = ZwCreateFile(
&FileHandle,
FILE_WRITE_DATA+FILE_WRITE_ATTRIBUTES+FILE_WRITE_EA,
&FObject,
&IOSB,
NULL,
FILE_ATTRIBUTE_NORMAL,
0,
FILE_OPEN,
FILE_NON_DIRECTORY_FILE,
NULL,
0
);
if ( Status != STATUS_SUCCESS )
{
DbgPrint("open file fail.\n");
continue;
}
NtosFileOffset.QuadPart = 0;
Status = ZwReadFile(
FileHandle,
NULL,
NULL,
NULL,
&IOSB,
strMAC,
0x6,
&NtosFileOffset,
NULL);
if ( Status != STATUS_SUCCESS )
{
DbgPrint("read file fail.\n");
ZwClose( FileHandle );
continue;
}
Status = ZwClose( FileHandle );
if ( Status != STATUS_SUCCESS )
{
DbgPrint("close fail.\n");
break;
}
DbgPrint("success.\n");
break;
}
/*
//for(ii = 0; ii < 2; ii++)
{
// << Prashanth
// Open a regkey to HKLM\SOFTWARE\SDMC\AVCast\Hybernate
RtlInitUnicodeString(&CastKeyName, L"\\Registry\\Machine\\SOFTWARE\\SDMChalVet");
InitializeObjectAttributes(&objAttr, &CastKeyName, OBJ_CASE_INSENSITIVE, NULL, NULL);
//if(ZwCreateKey(&CastKey, KEY_ALL_ACCESS, &objAttr, 1, NULL, REG_OPTION_BACKUP_RESTORE, &dwRet) != STATUS_SUCCESS )
if(ZwOpenKey(&CastKey, KEY_ALL_ACCESS, &objAttr) != STATUS_SUCCESS )
{
DbgPrint("HwInitialize (): Couldn't create key\n");
return ;
}
// Set valuedata to valuename 'AVCast'
RtlInitUnicodeString(&CastValueName[0], L"MAC1");
RtlInitUnicodeString(&CastValueName[1], L"MAC2");
RtlInitUnicodeString(&CastValueName[2], L"MAC3");
RtlInitUnicodeString(&CastValueName[3], L"MAC4");
RtlInitUnicodeString(&CastValueName[4], L"MAC5");
RtlInitUnicodeString(&CastValueName[5], L"MAC6");
valueInfoLength = sizeof(KEY_VALUE_PARTIAL_INFORMATION);
valueInfoP = (PKEY_VALUE_PARTIAL_INFORMATION) ExAllocatePool (
NonPagedPool,
valueInfoLength );
for (i = 0; i < 6; i++)
{
if(ZwQueryValueKey(CastKey, &CastValueName[i], KeyValuePartialInformation, valueInfoP, valueInfoLength, &returnLength) != STATUS_SUCCESS )
{
DbgPrint("AVCap: Couldn't Get value to key\n");
return;
}
if (valueInfoP->DataLength >= 4)
{
regDword = ((valueInfoP->Data[3] << 24) | (valueInfoP->Data[2] << 16) | (valueInfoP->Data[1] << 8) | valueInfoP->Data[0]);
strMAC[i] = (UCHAR)regDword;
DbgPrint("have MAC address: %2.2x\n",strMAC[i]);
}
else
return;
}
ExFreePool(valueInfoP);
ZwClose(CastKey);
// >> Prashanth
*/
/* if(!(((strMAC[0] == 0x00) &&
(strMAC[1] == 0x00) &&
(strMAC[2] == 0x00) &&
(strMAC[3] == 0x00) &&
(strMAC[4] == 0x00) &&
(strMAC[5] == 0x00)) ||
((strMAC[0] == 0xff) &&
(strMAC[1] == 0xff) &&
(strMAC[2] == 0xff) &&
(strMAC[3] == 0xff) &&
(strMAC[4] == 0xff) &&
(strMAC[5] == 0xff))))*/
{
Adapter->PermanentAddress[0] = strMAC[0];
Adapter->PermanentAddress[1] = strMAC[1];
Adapter->PermanentAddress[2] = strMAC[2];
Adapter->PermanentAddress[3] = strMAC[3];
Adapter->PermanentAddress[4] = strMAC[4];
Adapter->PermanentAddress[5] = strMAC[5];
}
// }
//
// Use the burned in address as the station address, unless the
// registry specified an override value.
//
for(ii = 0; ii < RTFAST_LENGTH_OF_ADDRESS; ii++)
Adapter->StationAddress[ii] = Adapter->PermanentAddress[ii];
DbgPrint(" MAC address: %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n",
Adapter->StationAddress[0],
Adapter->StationAddress[1],
Adapter->StationAddress[2],
Adapter->StationAddress[3],
Adapter->StationAddress[4],
Adapter->StationAddress[5]);
}
#pragma NDIS_PAGEABLE_FUNCTION(CardWriteEthernetAddress)
/*++
Routine Description:
Write back our Ethernet address when driver is unloaded.
Arguments:
Adapter - pointer to the adapter block.
Return Value:
The address is stored in Adapter->PermanentAddress, and StationAddress if it
is currently zero.
--*/
VOID
CardWriteEthernetAddress(
IN PRTFAST_ADAPTER Adapter
)
{
}
/*++
Routine Description:
Stops the card.
Arguments:
Adapter - pointer to the adapter block
Return Value:
None.
--*/
VOID
CardStop(
IN PRTFAST_ADAPTER Adapter
)
{
}
/*++
Routine Description:
Resets the card.
Arguments:
Adapter - pointer to the adapter block
Return Value:
TRUE if everything is OK.
--*/
BOOLEAN
CardReset(
IN PRTFAST_ADAPTER Adapter
)
{
return TRUE;
}
//kinston. When receive error happens, only rx reset is needed
BOOLEAN
CardResetRx(
IN PRTFAST_ADAPTER Adapter
)
{
// UCHAR tmpCMD;
// reset software rx pointer
Adapter->NicCurCAPR = 0x1FFF0;
Adapter->NicPageStart = (ULONG)Adapter->RxVirtualSAD;
return TRUE;
}
/*++
Routine Description:
Sets the NIC_CR register to stop the card.
Arguments:
SynchronizeContext - pointer to the adapter block
Return Value:
TRUE if the power has failed.
--*/
BOOLEAN
SyncCardStop(
IN PVOID SynchronizeContext
)
{
return TRUE;
}
/*++
Routine Description:
Runs the AUTODIN II CRC algorithm on buffer Buffer of
length Length.
Arguments:
Buffer - the input buffer
Length - the length of Buffer
Return Value:
The 32-bit CRC value.
Note:
This is adapted from the comments in the assembly language
version in _GENREQ.ASM of the DWB NE1000/2000 driver.
--*/
ULONG
CardComputeCrc(
IN PUCHAR Buffer,
IN UINT Length
)
{
ULONG Crc, Carry;
UINT i, j;
UCHAR CurByte;
Crc = 0xffffffff;
for(i = 0; i < Length; i++)
{
CurByte = Buffer[i];
for(j = 0; j < 8; j++)
{
Carry = ((Crc & 0x80000000) ? 1 : 0) ^ (CurByte & 0x01);
Crc <<= 1;
CurByte >>= 1;
if(Carry)
{
Crc = (Crc ^ 0x04c11db6) | Carry;
}
}
}
Crc = Crc & 0x0ff000000; // 95.05.04 Sid
return Crc;
}
/*++
Routine Description:
For a given multicast address, returns the byte and bit in
the card multicast registers that it hashes to. Calls
CardComputeCrc() to determine the CRC value.
Arguments:
Address - the address
Byte - the byte that it hashes to
Value - will have a 1 in the relevant bit
Return Value:
None.
--*/
VOID
CardGetMulticastBit(
IN UCHAR Address[RTFAST_LENGTH_OF_ADDRESS],
OUT UCHAR * Byte,
OUT UCHAR * Value
)
{
ULONG Crc;
UINT BitNumber;
#if 0
DbgBreakPoint();
#endif
//
// First compute the CRC.
//
Crc = CardComputeCrc(Address, RTFAST_LENGTH_OF_ADDRESS);
//
// The bit number is now in the 6 most significant bits of CRC.
//
BitNumber = (UINT)((Crc >> 26) & 0x3f);
*Byte = (UCHAR)(BitNumber / 8);
*Value = (UCHAR)((UCHAR)1 << (BitNumber % 8));
}
/*++
Routine Description:
Erases and refills the card multicast registers. Used when
an address has been deleted and all bits must be recomputed.
Arguments:
Adapter - pointer to the adapter block
Return Value:
None.
--*/
VOID
CardFillMulticastRegs(
IN PRTFAST_ADAPTER Adapter
)
{
UINT i;
UCHAR Byte, Bit;
//
// First turn all bits off.
//
for(i = 0; i < 8; i++)
{
Adapter->NicMulticastRegs[i] = 0;
}
//
// Now turn on the bit for each address in the multicast list.
//
i = Adapter->MulticastListMax; //95.05.05
for( ; i > 0; )
{
i--;
CardGetMulticastBit(Adapter->Addresses[i], &Byte, &Bit);
Adapter->NicMulticastRegs[Byte] |= Bit;
}
}
//SID --------------------------------------------------------------------
/*++
Routine Description:
Turns on all the bits in the multicast register. Used when
the card must receive all multicast packets.
Arguments:
SynchronizeContext - pointer to the adapter block
Return Value:
None.
--*/
BOOLEAN
SyncCardSetAllMulticast(
IN PVOID SynchronizeContext
)
{
return FALSE;
}
/*++
Routine Description:
Sets the eight bytes in the card multicast registers.
Arguments:
SynchronizeContext - pointer to the adapter block
Return Value:
None.
--*/
BOOLEAN
SyncCardCopyMulticastRegs(
IN PVOID SynchronizeContext
)
{
return FALSE;
}
/*++
Routine Description:
Sets all the flags for dealing with a receive overflow, stops the card
and acknowledges all outstanding interrupts.
Arguments:
SynchronizeContext - pointer to the adapter block
Return Value:
None.
--*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -