Esempio n. 1
0
VOID
NdisConvertStringToAtmAddress(
	OUT	PNDIS_STATUS			Status,
	IN	PNDIS_STRING			String,
	OUT	PATM_ADDRESS			AtmAddress
	)
/*++

Routine Description:


Arguments:

	Status - Returns the status of the request.

	String - String representation of the atm address.

	*	Format defined in Section 5.4,
	*		"Example Master File Format" in ATM95-1532R4 ATM Name System:
	*
	*	AESA format: a string of hexadecimal digits, with '.' characters for punctuation, e.g.
	*
	*		39.246f.00.0e7c9c.0312.0001.0001.000012345678.00
	*
	*	E164 format: A '+' character followed by a string of
	*		decimal digits, with '.' chars for punctuation, e.g.:
	*
	*			+358.400.1234567

	AtmAddress - The converted Atm address is returned here.

Return Value:

	None.

--*/
{
	USHORT			i, j, NumDigits;
	PWSTR			p, q;
	UNICODE_STRING	Us;
	ANSI_STRING		As;

	//
	// Start off by stripping the punctuation characters from the string. We do this in place.
	//
	for (i = NumDigits = 0, j = String->Length/sizeof(WCHAR), p = q = String->Buffer;
		 (i < j) && (*p != 0);
		 i++, p++)
	{
		if ((*p == ATM_ADDR_BLANK_CHAR) ||
			(*p == ATM_ADDR_PUNCTUATION_CHAR))
		{
			continue;
		}
		*q++ = *p;
		NumDigits ++;
	}

	//
	// Look at the first character to determine if the address is E.164 or NSAP
	//
	p = String->Buffer;
	if (*p == ATM_ADDR_E164_START_CHAR)
	{
		p ++;
		NumDigits --;
		if ((NumDigits == 0) || (NumDigits > ATM_ADDRESS_LENGTH))
		{
			*Status = NDIS_STATUS_INVALID_LENGTH;
			return;
		}
		AtmAddress->AddressType = ATM_E164;
		AtmAddress->NumberOfDigits = NumDigits;
	}
	else
	{
		if (NumDigits != 2*ATM_ADDRESS_LENGTH)
		{
			*Status = NDIS_STATUS_INVALID_LENGTH;
			return;
		}
		AtmAddress->AddressType = ATM_NSAP;
		AtmAddress->NumberOfDigits = NumDigits/sizeof(WCHAR);
	}

	//
	// Convert the address to Ansi now
	//
	Us.Buffer = p;
	Us.Length = Us.MaximumLength = NumDigits*sizeof(WCHAR);
	As.Buffer = ALLOC_FROM_POOL(NumDigits + 1, NDIS_TAG_CO);
	As.Length = 0;
    As.MaximumLength = NumDigits + 1;
	if (As.Buffer == NULL)
	{
		*Status = NDIS_STATUS_RESOURCES;
		return;
	}

	*Status = NdisUnicodeStringToAnsiString(&As, &Us);
	if (*Status != STATUS_SUCCESS)
	{
		FREE_POOL(As.Buffer);
		*Status = NDIS_STATUS_FAILURE;
		return;
	}

	//
	//  Now get the bytes into the destination ATM Address structure.
	//
	if (AtmAddress->AddressType == ATM_E164)
	{
		//
		//  We just need to copy in the digits in ANSI form.
		//
		NdisMoveMemory(AtmAddress->Address, As.Buffer, NumDigits);
	}
	else
	{
		//
		//  This is in NSAP form. We need to pack the hex digits.
		//
		UCHAR			xxString[3];
		ULONG			val;

		xxString[2] = 0;
		for (i = 0; i < ATM_ADDRESS_LENGTH; i++)
		{
			xxString[0] = As.Buffer[i*2];
			xxString[1] = As.Buffer[i*2+1];
			*Status = CHAR_TO_INT(xxString, 16, &val);
			if (*Status != STATUS_SUCCESS)
			{
				FREE_POOL(As.Buffer);
				*Status = NDIS_STATUS_FAILURE;
				return;
			}
			AtmAddress->Address[i] = (UCHAR)val;
		}
	}

	FREE_POOL(As.Buffer);
	*Status = NDIS_STATUS_SUCCESS;
}
Esempio n. 2
0
// Read the information from the registry
BOOL NeoLoadRegistory()
{
	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;
}