/*++
*******************************************************************************
* Copyright (c) 1990-98 Digi International Inc., All Rights Reserved				*
* 																										*
* This software contains proprietary and confidential information of Digi		*
* International Inc.  By accepting transfer of this copy, Recipient agrees		*
* to retain this software in confidence, to prevent disclosure to others,		*
* and to make no use of this software other than that for which it was			*
* delivered.  This is an unpublished copyrighted work of Digi International	*
* Inc.  Except as permitted by federal law, 17 USC 117, copying is strictly	*
* prohibited.																						*
* 																										*
* Restricted Rights Legend																		*
*																										*
* Use, duplication, or disclosure by the Government is subject to					*
* restrictions set forth in sub-paragraph (c)(1)(ii) of The Rights in			*
* Technical Data and Computer Software clause at DFARS 252.227-7031 or			*
* subparagraphs (c)(1) and (2) of the Commercial Computer Software -				*
* Restricted Rights at 48 CFR 52.227-19, as applicable.						*
*																			
* Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343		*
*																										*
*******************************************************************************

Module Name:

   sohwan.c

Abstract:

   Wan specific initialization routines.

Author:

   Jeff Romatoski

--*/
#include "digisoh.h"
#include "sohwan.h"

#if !NT5_BUILD
#ifdef ALLOC_PRAGMA
#pragma alloc_text(INIT,SohWanTune)
#endif
#endif


NTSTATUS
SohWanTune(
	IN PSOH_DEV_EXT		pDevExt,
	IN HANDLE           hKeyPort, 
	IN ULONG			Snid
	)
/*++

Description:

	Configure (or Tune) the wan driver on the specified port.  Read wan configuration 
	from registry and send it down to the adapter.

Parameters:

	pExt
		Device extension defining the adapter being configured

	hKeyPort
		Handle to Registry key containing config params for the port

	Snid
		SubNetwork ID.  Identifies the port being configured

Return Value:

	STATUS_SUCCESS, or failure status.

--*/
{
	NTSTATUS	Status;
	HANDLE		hKeyWan;
	HANDLE		hWanStream;
	struct wan_tnioc SetTune = {0};
	ULONG		Error;

	DigiDump( DIGIINIT, ( "SOH!SohWanTune: Snid 0x%x\n", Snid ) );

	Status = DigiRegOpenSubkey( &hKeyWan, hKeyPort, DXB_REGKEY_WAN );
	if ( NT_ERROR( Status ) )
		goto Exit;

	SetTune.lli_type = LI_WANTUNE;
	SetTune.lli_snid = Snid;

	DigiRegQueryDword( hKeyWan, DXB_REGVAL_WAN_OPTIONS, &SetTune.wan_tune.WAN_options,
	                  DigiRegFlagOptional, DXB_REGVAL_WAN_OPTIONS_DEFAULT );
	DigiRegQueryDword( hKeyWan, DXB_REGVAL_WAN_MAXFRAME, &SetTune.wan_tune.WAN_hd.WAN_maxframe,
	                  DigiRegFlagOptional, DXB_REGVAL_WAN_MAXFRAME_DEFAULT );
	DigiRegQueryDword( hKeyWan, DXB_REGVAL_WAN_BAUD, &SetTune.wan_tune.WAN_hd.WAN_baud,
	                   DigiRegFlagOptional, DXB_REGVAL_WAN_BAUD_DEFAULT );
	DigiRegQueryDword( hKeyWan, DXB_REGVAL_WAN_INTERFACE, &SetTune.wan_tune.WAN_hd.WAN_interface,
	                  DigiRegFlagOptional, DXB_REGVAL_WAN_INTERFACE_DEFAULT );
 
	SetTune.wan_tune.WAN_hd.WAN_cpdef.WAN_cptype = WAN_NONE;

	DigiDump( DIGIINIT, ( "SOH: Wan tune, Snid 0x%x:\n"
	                       "   lli_type                             = 0x%x\n"
	                       "   lli_snid                             = 0x%x\n"
	                       "   wan_tune.WAN_options                 = 0x%x\n"
	                       "   wan_tune.WAN_hd.WAN_maxframe         = 0x%x\n"
	                       "   wan_tune.WAN_hd.WAN_baud             = 0x%x\n"
	                       "   wan_tune.WAN_hd.WAN_interface        = 0x%x\n"
	                       "   wan_tune.WAN_hd.WAN_cpdef.WAN_cptype = 0x%x\n"
	                       "   wan_tune.WAN_hd.WAN_hdplx            = 0x%x\n", 
	                       Snid,
	                       SetTune.lli_type,
	                       SetTune.lli_snid,
	                       SetTune.wan_tune.WAN_options,
	                       SetTune.wan_tune.WAN_hd.WAN_maxframe,
	                       SetTune.wan_tune.WAN_hd.WAN_baud,
	                       SetTune.wan_tune.WAN_hd.WAN_interface,
	                       SetTune.wan_tune.WAN_hd.WAN_cpdef.WAN_cptype,
	                       SetTune.wan_tune.WAN_hd.WAN_hdplx) );
	
	if ( NT_ERROR( Status ) )
		goto Exit;

	Status = DsOpen( gSohRuntimeEnv.hDevice, "XWAN", NULL, NULL, 0, &hWanStream, &Error );
	if ( NT_ERROR( Status ) )
		goto Exit;

	Status = DsIoctl( hWanStream, W_SETTUNE, &SetTune, sizeof SetTune, &Error );

	(void)DsClose( hWanStream );


Exit:
	DigiDump( DIGIINIT, ( "SOH!SohWanTune: Leave, Status 0x%x\n", Status ) );
	return Status;
}
