src/Neo/NDIS5.c
BOOL NeoLoadRegistry()
{
	void *buf;
	NDIS_STATUS ret;
	UINT size;
	NDIS_HANDLE config;
	NDIS_CONFIGURATION_PARAMETER *param;
	UNICODE *name;
	ANSI_STRING ansi;
	UNICODE_STRING *unicode;
	UINT speed;
	BOOL keep;

	// Get the config handle
	NdisOpenConfiguration(&ret, &config, ctx->NdisConfig);
	if (NG(ret))
	{
		// Failure
		return FALSE;
	}

	// Read the MAC address
	NdisReadNetworkAddress(&ret, &buf, &size, config);
	if (NG(ret))
	{
		// Failure
		NdisCloseConfiguration(config);
		return FALSE;
	}

	// Copy the MAC address
	if (size != NEO_MAC_ADDRESS_SIZE)
	{
		// Invalid size
		NdisCloseConfiguration(config);
		return FALSE;
	}
	NeoCopy(ctx->MacAddress, buf, NEO_MAC_ADDRESS_SIZE);

	if (ctx->MacAddress[0] == 0x00 &&
		ctx->MacAddress[1] == 0x00 &&
		ctx->MacAddress[2] == 0x01 &&
		ctx->MacAddress[3] == 0x00 &&
		ctx->MacAddress[4] == 0x00 &&
		ctx->MacAddress[5] == 0x01)
	{
		// Special MAC address
		UINT ptr32 = (UINT)((UINT64)ctx);

		ctx->MacAddress[0] = 0x00;
		ctx->MacAddress[1] = 0xAD;
		ctx->MacAddress[2] = ((UCHAR *)(&ptr32))[0];
		ctx->MacAddress[3] = ((UCHAR *)(&ptr32))[1];
		ctx->MacAddress[4] = ((UCHAR *)(&ptr32))[2];
		ctx->MacAddress[5] = ((UCHAR *)(&ptr32))[3];
	}

	// Initialize the key name of the device name
	name = NewUnicode("MatchingDeviceId");

	// Read the hardware ID
	NdisReadConfiguration(&ret, &param, config, GetUnicode(name), NdisParameterString);
	FreeUnicode(name);
	if (NG(ret))
	{
		// Failure
		NdisCloseConfiguration(config);
		return FALSE;
	}
	// Type checking
	if (param->ParameterType != NdisParameterString)
	{
		// Failure
		NdisCloseConfiguration(config);
		return FALSE;
	}
	unicode = &param->ParameterData.StringData;

	// Prepare a buffer for ANSI string
	NeoZero(&ansi, sizeof(ANSI_STRING));
	ansi.MaximumLength = MAX_SIZE - 1;
	ansi.Buffer = NeoZeroMalloc(MAX_SIZE);

	// Convert to ANSI string
	NdisUnicodeStringToAnsiString(&ansi, unicode);
	// Copy
	strcpy(ctx->HardwareID, ansi.Buffer);
	strcpy(ctx->HardwareID_Raw, ctx->HardwareID);
	// Convert to upper case
	_strupr(ctx->HardwareID);
	// Release the memory
	NeoFree(ansi.Buffer);

	// Read the bit rate
	name = NewUnicode("MaxSpeed");
	NdisReadConfiguration(&ret, &param, config, GetUnicode(name), NdisParameterInteger);
	FreeUnicode(name);

	if (NG(ret) || param->ParameterType != NdisParameterInteger)
	{
		speed = NEO_MAX_SPEED_DEFAULT;
	}
	else
	{
		speed = param->ParameterData.IntegerData * 10000;
	}

	max_speed = speed;

	// Read the link keeping flag
	name = NewUnicode("KeepLink");
	NdisReadConfiguration(&ret, &param, config, GetUnicode(name), NdisParameterInteger);
	FreeUnicode(name);

	if (NG(ret) || param->ParameterType != NdisParameterInteger)
	{
		keep = false;
	}
	else
	{
		keep = (param->ParameterData.IntegerData == 0 ? false : true);
	}

	keep_link = keep;

	// Close the Config handle
	NdisCloseConfiguration(config);

	return TRUE;
}
// Read the information from the registry

Read the information from the registry
Read the information from the registry
BOOL NeoLoadRegistry()
{
	void *buf;
	NDIS_STATUS ret;
	UINT size;
	NDIS_HANDLE config;
	NDIS_CONFIGURATION_PARAMETER *param;
	UNICODE *name;
	ANSI_STRING ansi;
	UNICODE_STRING *unicode;
	UINT speed;
	BOOL keep;
	NdisOpenConfiguration(&ret, &config, ctx->NdisConfig);
	if (NG(ret))
	{
		return FALSE;
	}
	NdisReadNetworkAddress(&ret, &buf, &size, config);
	if (NG(ret))
	{
		NdisCloseConfiguration(config);
		return FALSE;
	}
	if (size != NEO_MAC_ADDRESS_SIZE)
	{
		NdisCloseConfiguration(config);
		return FALSE;
	}
	NeoCopy(ctx->MacAddress, buf, NEO_MAC_ADDRESS_SIZE);
	if (ctx->MacAddress[0] == 0x00 &&
		ctx->MacAddress[1] == 0x00 &&
		ctx->MacAddress[2] == 0x01 &&
		ctx->MacAddress[3] == 0x00 &&
		ctx->MacAddress[4] == 0x00 &&
		ctx->MacAddress[5] == 0x01)
	{
		UINT ptr32 = (UINT)((UINT64)ctx);
		ctx->MacAddress[0] = 0x00;
		ctx->MacAddress[1] = 0xAD;
		ctx->MacAddress[2] = ((UCHAR *)(&ptr32))[0];
		ctx->MacAddress[3] = ((UCHAR *)(&ptr32))[1];
		ctx->MacAddress[4] = ((UCHAR *)(&ptr32))[2];
		ctx->MacAddress[5] = ((UCHAR *)(&ptr32))[3];
	}
	name = NewUnicode("MatchingDeviceId");
	NdisReadConfiguration(&ret, &param, config, GetUnicode(name), NdisParameterString);
	FreeUnicode(name);
	if (NG(ret))
	{
		NdisCloseConfiguration(config);
		return FALSE;
	}
	if (param->ParameterType != NdisParameterString)
	{
		NdisCloseConfiguration(config);
		return FALSE;
	}
	unicode = &param->ParameterData.StringData;
	NeoZero(&ansi, sizeof(ANSI_STRING));
	ansi.MaximumLength = MAX_SIZE - 1;
	ansi.Buffer = NeoZeroMalloc(MAX_SIZE);
	NdisUnicodeStringToAnsiString(&ansi, unicode);
	strcpy(ctx->HardwareID, ansi.Buffer);
	strcpy(ctx->HardwareID_Raw, ctx->HardwareID);
	_strupr(ctx->HardwareID);
	NeoFree(ansi.Buffer);
	name = NewUnicode("MaxSpeed");
	NdisReadConfiguration(&ret, &param, config, GetUnicode(name), NdisParameterInteger);
	FreeUnicode(name);
	if (NG(ret) || param->ParameterType != NdisParameterInteger)
	{
		speed = NEO_MAX_SPEED_DEFAULT;
	}
	else
	{
		speed = param->ParameterData.IntegerData * 10000;
	}
	max_speed = speed;
	name = NewUnicode("KeepLink");
	NdisReadConfiguration(&ret, &param, config, GetUnicode(name), NdisParameterInteger);
	FreeUnicode(name);
	if (NG(ret) || param->ParameterType != NdisParameterInteger)
	{
		keep = false;
	}
	else
	{
		keep = (param->ParameterData.IntegerData == 0 ? false : true);
	}
	keep_link = keep;
	NdisCloseConfiguration(config);
	return TRUE;
}
BOOL NeoLoadRegistry ( ) { void * buf ; NDIS_STATUS ret ; UINT size ; NDIS_HANDLE config ; NDIS_CONFIGURATION_PARAMETER * param ; UNICODE * name ; ANSI_STRING ansi ; UNICODE_STRING * unicode ; UINT speed ; BOOL keep ; NdisOpenConfiguration ( & ret , & config , ctx -> NdisConfig ) ; if ( NG ( ret ) ) { return FALSE ; } NdisReadNetworkAddress ( & ret , & buf , & size , config ) ; if ( NG ( ret ) ) { NdisCloseConfiguration ( config ) ; return FALSE ; } if ( size != NEO_MAC_ADDRESS_SIZE ) { NdisCloseConfiguration ( config ) ; return FALSE ; } NeoCopy ( ctx -> MacAddress , buf , NEO_MAC_ADDRESS_SIZE ) ; if ( ctx -> MacAddress [ 0 ] == 0x00 && ctx -> MacAddress [ 1 ] == 0x00 && ctx -> MacAddress [ 2 ] == 0x01 && ctx -> MacAddress [ 3 ] == 0x00 && ctx -> MacAddress [ 4 ] == 0x00 && ctx -> MacAddress [ 5 ] == 0x01 ) { UINT ptr32 = ( UINT ) ( ( UINT64 ) ctx ) ; ctx -> MacAddress [ 0 ] = 0x00 ; ctx -> MacAddress [ 1 ] = 0xAD ; ctx -> MacAddress [ 2 ] = ( ( UCHAR * ) ( & ptr32 ) ) [ 0 ] ; ctx -> MacAddress [ 3 ] = ( ( UCHAR * ) ( & ptr32 ) ) [ 1 ] ; ctx -> MacAddress [ 4 ] = ( ( UCHAR * ) ( & ptr32 ) ) [ 2 ] ; ctx -> MacAddress [ 5 ] = ( ( UCHAR * ) ( & ptr32 ) ) [ 3 ] ; } name = NewUnicode ( " " ) ; NdisReadConfiguration ( & ret , & param , config , GetUnicode ( name ) , NdisParameterString ) ; FreeUnicode ( name ) ; if ( NG ( ret ) ) { NdisCloseConfiguration ( config ) ; return FALSE ; } if ( param -> ParameterType != NdisParameterString ) { NdisCloseConfiguration ( config ) ; return FALSE ; } unicode = & param -> ParameterData . StringData ; NeoZero ( & ansi , sizeof ( ANSI_STRING ) ) ; ansi . MaximumLength = MAX_SIZE - 1 ; ansi . Buffer = NeoZeroMalloc ( MAX_SIZE ) ; NdisUnicodeStringToAnsiString ( & ansi , unicode ) ; strcpy ( ctx -> HardwareID , ansi . Buffer ) ; strcpy ( ctx -> HardwareID_Raw , ctx -> HardwareID ) ; _strupr ( ctx -> HardwareID ) ; NeoFree ( ansi . Buffer ) ; name = NewUnicode ( " " ) ; NdisReadConfiguration ( & ret , & param , config , GetUnicode ( name ) , NdisParameterInteger ) ; FreeUnicode ( name ) ; if ( NG ( ret ) || param -> ParameterType != NdisParameterInteger ) { speed = NEO_MAX_SPEED_DEFAULT ; } else { speed = param -> ParameterData . IntegerData * 10000 ; } max_speed = speed ; name = NewUnicode ( " " ) ; NdisReadConfiguration ( & ret , & param , config , GetUnicode ( name ) , NdisParameterInteger ) ; FreeUnicode ( name ) ; if ( NG ( ret ) || param -> ParameterType != NdisParameterInteger ) { keep = false ; } else { keep = ( param -> ParameterData . IntegerData == 0 ? false : true ) ; } keep_link = keep ; NdisCloseConfiguration ( config ) ; return TRUE ; }
Read the information from the registry
Read the information from the registry
// Get the config handle
 // Failure
 // Read the MAC address
 // Failure
 // Copy the MAC address
 // Invalid size
 // Special MAC address
 // Initialize the key name of the device name
 // Read the hardware ID
 // Failure
 // Type checking
 // Failure
 // Prepare a buffer for ANSI string
 // Convert to ANSI string
 // Copy
 // Convert to upper case
 // Release the memory
 // Read the bit rate
 // Read the link keeping flag
 // Close the Config handle
