/*++
*******************************************************************************
* 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:

   dxbwan.c

Abstract:

   Wan specific initialization routines.

Author:

   Michael Zarns

--*/
#include "digidxb.h"
#pragma hdrstop 	// Stop precomiled header generation

#include "wan_control.h"
#include "wanreg.h"


NTSTATUS
dxbWanInit(
	IN PDXB_DEVICE_EXTENSION pExt )
/*++

Description:

	Initialize the WAN layer on the adapter.  This should be done first, before 
	building the protocol stacks.  Simply opens and closes the WAN0 device.

Parameters:

	pExt
		Device extension defining the adapter 

Return Value:

	STATUS_SUCCESS or failure status

--*/
{
	HANDLE hStream;
	ULONG Error;
	NTSTATUS Status;

	ASSERT( pExt->hDsDevice != NULL );
	Status = DsOpen( pExt->hDsDevice, "WAN0", NULL, NULL, 0, &hStream, &Error );
	if ( NT_SUCCESS( Status ) )
		(void)DsClose( hStream );
	return Status;
}



NTSTATUS
dxbWanTune(
	IN PDXB_DEVICE_EXTENSION pExt, 
	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;
	struct wan_tnioc SetTune = {0};
	ULONG Error;
	HANDLE hStream;

	SRAPRINT2(DIGIINITLOUD, SRA_MED_LEVEL, 
                  ( "DXB!dxbWanTune: device %S, Snid 0x%x\n", pExt->Name.Buffer, 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;

	SRAPRINT2(DIGICONFIG, SRA_MED_LEVEL, 
                  ( "DXB: 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) );

	Status = DsOpen( pExt->hDsDevice, "WANS", NULL, NULL, 0, &hStream, &Error );
	if ( NT_ERROR( Status ) )
		goto Exit;

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

	(void)DsClose( hStream );

Exit:
	SRAPRINT2(DIGIINITLOUD, SRA_MED_LEVEL, 
                  ( "DXB!dxbWanTune: Leave, Status 0x%x\n", Status ) );
	return Status;
}
