/*	Topology.c - Topological functions used globally.
*
*******************************************************************************
* Copyright (c) 1996-97 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 copyright work  Digi   International *
* Inc.    Except   as   permitted   by  federal  law,  17 USC 117, copying is *
* strictly prohibited.                                                        *
*                                                                             *
* Digi  International  Inc.  CONFIDENTIAL  -   (Digi    International    Inc. *
* Confidential  when   combined   with   the   aggregated  modules  for  this *
* product) OBJECT CODE ONLY SOURCE MATERIALS                                  *
*                                                                             *
* (C) COPYRIGHT Digi International Inc. 1996-97                               *
*                                                                             *
* All Rights Reserved                                                         *
*                                                                             *
* US   Government   Users   Restricted   Rights   -   Use,   duplication   or *
* disclosure  restricted by GSA ADP Schedule Contract with Digi International *
* Inc.                                                                        *
*                                                                             *
*******************************************************************************
*
*/

#include "DS_RAS.h"
#include "Topology.h"
#include "Cache.h"
#include "mgmtshim.h"
#include "mgmthlc.h"
#include "triglbl.h"

size_t AdapterCount(void)
{
	static CacheObject_t const co = { SHIM(MGMT_BOARD_NO) };
	static CacheValue_t const cv =
	{
		offsetof(get_mgmt_board_no_response_t, NumberOfBoards),
		sizeof elementof(get_mgmt_board_no_response_t, NumberOfBoards),
		ASN_INTEGER
	};

	int cAdapters = 0;
	AsnAny aaAdapters;
	AsnInteger iaErrorStatus;

	if (!ReadCachedObject(&co, &cv, &aaAdapters, &iaErrorStatus))
		goto Error;

	if (iaErrorStatus != SNMP_ERRORSTATUS_NOERROR)
		goto Error;

	cAdapters = aaAdapters.asnValue.number;

Error:

	return cAdapters;
}

size_t DriverCount(size_t const iAdapter)
{
	static CacheObject_t const co = { SHIM(MGMT_DRV_VERS) };
	static CacheValue_t const cv =
	{
		offsetof(mgmt_drv_vers_t, driverCount),
		sizeof elementof(mgmt_drv_vers_t, driverCount),
		ASN_INTEGER
	};

	int cDrivers = 0;
	AsnAny aaDrivers;
	AsnInteger aaErrorStatus;

	if (!ReadCachedObject(&co, &cv, &aaDrivers, &aaErrorStatus))
		goto Error;

	if (aaErrorStatus != SNMP_ERRORSTATUS_NOERROR)
		goto Error;

	cDrivers = aaDrivers.asnValue.number;

Error:

	return cDrivers;
}

size_t Ds1Count(size_t const iAdapter)
{
	static CacheObject_t co = { SHIM(MGMT_BOARD_INFO) };
	static CacheValue_t const cv =
	{
		offsetof(mgmt_board_info_t, BoardType),
		sizeof elementof(mgmt_board_info_t, BoardType),
		ASN_INTEGER
	};
	int cDs1s = 0;
	AsnAny aaType;
	AsnInteger aaErrorStatus;

	co.iBoard = iAdapter;

	if (!ReadCachedObject(&co, &cv, &aaType, &aaErrorStatus))
		goto Error;

	if (aaErrorStatus != SNMP_ERRORSTATUS_NOERROR)
		goto Error;

	switch (aaType.asnValue.number)
	{
		case POST_TYPE_HOUSTON_T1:
		case POST_TYPE_HOUSTON_E1:
		{
			static CacheObject_t co = { ADAPTER_INFO };
			static CacheValue_t const cv =
			{
				offsetof(adapter_info_t, port_count),
				sizeof elementof(adapter_info_t, port_count),
				ASN_INTEGER
			};
			AsnAny aaPorts;

			co.iBoard = iAdapter;
			if (!ReadCachedObject(&co, &cv, &aaPorts, &aaErrorStatus))
				goto Error;

			if (aaErrorStatus != SNMP_ERRORSTATUS_NOERROR)
				goto Error;

			cDs1s = aaPorts.asnValue.number;
			break;
		}
	}

Error:

	return cDs1s;
}

dxb_uint32 GetDs1InterfaceType(size_t const iAdapter, size_t const iPort)
{
	static CacheObject_t co = { DS1_CONFIG };
	static CacheValue_t const cv =
	{
		offsetof(ds1_config_t, if_type),
		sizeof elementof(ds1_config_t, if_type),
		ASN_INTEGER
	};
	dxb_uint32 eInterfaceType = 0;
	AsnAny aaInterfaceType;
	AsnInteger iaErrorStatus;

	co.iBoard = iAdapter;
	co.iGeneric1 = iPort;
	if (!ReadCachedObject(&co, &cv, &aaInterfaceType, &iaErrorStatus))
		goto Error;

	if (iaErrorStatus != SNMP_ERRORSTATUS_NOERROR)
		goto Error;

	eInterfaceType = aaInterfaceType.asnValue.number;
	
Error:

	return eInterfaceType;
}

dxb_uint32 GetDs1Signalling(size_t const iAdapter, size_t const iPort)
{
	static CacheObject_t co = { DS1_CONFIG };
	static CacheValue_t const cv =
	{
		offsetof(ds1_config_t, signalling),
		sizeof elementof(ds1_config_t, signalling),
		ASN_INTEGER
	};
	dxb_uint32 eSignalling = 0;
	AsnAny aaSignalling;
	AsnInteger iaErrorStatus;

	co.iBoard = iAdapter;
	co.iGeneric1 = iPort;
	if (!ReadCachedObject(&co, &cv, &aaSignalling, &iaErrorStatus))
		goto Error;

	if (iaErrorStatus != SNMP_ERRORSTATUS_NOERROR)
		goto Error;

	eSignalling = aaSignalling.asnValue.number;
	
Error:

	return eSignalling;
}
