/*	ToString.c - Object to String conversions.
*
*******************************************************************************
* 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 "ToString.h"
#include "mgmtshim.h"
#include "mgmthlc.h"

char * CopyString(char const * const psz)
{
	return _strdup(psz);
}

void FreeString(char /*const*/ * const psz)
{
	free(psz);
}

char const * SuccessToString(BOOL const fSuccess)
{
	return fSuccess ? "SUCCESS" : "FAILURE";
}

char const * ErrorStatusToString(AsnInteger const iaErrorStatus)
{
	static char buffer[4096];
	char const * p = buffer;

	switch (iaErrorStatus)
	{
		case SNMP_ERRORSTATUS_NOERROR:		p = "NOERROR";									break;
		case SNMP_ERRORSTATUS_TOOBIG:		p = "TOOBIG";									break;
		case SNMP_ERRORSTATUS_NOSUCHNAME:	p = "NOSUCHNAME";								break;
		case SNMP_ERRORSTATUS_BADVALUE:		p = "BADVALUE";									break;
		case SNMP_ERRORSTATUS_READONLY:		p = "READONLY";									break;
		case SNMP_ERRORSTATUS_GENERR:		p = "GENERR";									break;

		default:							sprintf(buffer, "UNKNOWN (%d)", iaErrorStatus);	break;
	}

	return p;
}

char const * ObjectTypeToString(Object_t const eObjectType)
{
	static char buffer[4096];
	char const * p = buffer;

	switch (eObjectType)
	{
		case Object_Data:	p = "DATA";										break;
		case Object_List:	p = "LIST";										break;
		case Object_Table:	p = "TABLE";									break;

		default:			sprintf(buffer, "UNKNOWN (%d)", eObjectType);	break;
	}

	return p;
}

char const * RequestToString(BYTE const eType)
{
	static char buffer[4096];
	char const * p = buffer;

	switch (eType)
	{
		case ASN_RFC1157_GETREQUEST:		p = "GET";								break;
		case ASN_RFC1157_SETREQUEST:		p = "SET";								break;
		case ASN_RFC1157_GETNEXTREQUEST:	p = "GETNEXT";							break;

		default:							sprintf(buffer, "UNKNOWN (%d)", eType);	break;
	}

	return p;
}

char const * OidToString(AsnObjectIdentifier const * const poia)
{
	static char buffer[4096];
	size_t i;
	char * pc = buffer;

	for (i = 0; i < poia->idLength; i++)
		pc += sprintf(pc, "%d.", poia->ids[i]);

	if (pc == buffer)
		strcpy(buffer, "[empty]");
	else
		*(pc - 1) = '\0';

	return buffer;
}

char const * MgmtResultToString(uint32 const nResult)
{
	static char buffer[4096];
	char const * p = buffer;

	switch (nResult)
	{
		case MGMT_OK:									p = "MGMT_OK";									break;
		case MGMT_SHIM_ERROR_BAD_COMMAND:				p = "MGMT_SHIM_ERROR_BAD_COMMAND";				break;
		case MGMT_SHIM_ERROR_BAD_DFC:					p = "MGMT_SHIM_ERROR_BAD_DFC";					break;
		case MGMT_SHIM_ERROR_BAD_PARAMETER:				p = "MGMT_SHIM_ERROR_BAD_PARAMETER";			break;
		case MGMT_SHIM_ERROR_BAD_DEVICE:				p = "MGMT_SHIM_ERROR_BAD_DEVICE";				break;
		case MGMT_SHIM_ERROR_OUT_OF_MEMORY:				p = "MGMT_SHIM_ERROR_OUT_OF_MEMORY";			break;
		case MGMT_SHIM_ERROR_UNKNOWN:					p = "MGMT_SHIM_ERROR_UNKNOWN";					break;
		case MGMT_SHIM_ERROR_BAD_PACKET_SIZE:			p = "MGMT_SHIM_ERROR_BAD_PACKET_SIZE";			break;
		case MGMT_SHIM_ERROR_NO_BOARDS:					p = "MGMT_SHIM_ERROR_NO_BOARDS";				break;
		case MGMT_SHIM_ERROR_NOT_INITIALIZED:			p = "MGMT_SHIM_ERROR_NOT_INITIALIZED";			break;
		case MGMT_SHIM_ERROR_OPERATION_TIMEOUT:			p = "MGMT_SHIM_ERROR_OPERATION_TIMEOUT";		break;
		case MGMT_SHIM_ERROR_INTERNAL:					p = "MGMT_SHIM_ERROR_INTERNAL";					break;
		case MGMT_SHIM_ERROR_SERIALIZE_FAIL:			p = "MGMT_SHIM_ERROR_SERIALIZE_FAIL";			break;
		case MGMT_SHIM_ERROR_BOARD_NON_FUNCTIONAL:		p = "MGMT_SHIM_ERROR_BOARD_NON_FUNCTIONAL";		break;
		case MGMT_SHIM_ERROR_NO_MGMT_CHAN:				p = "MGMT_SHIM_ERROR_NO_MGMT_CHAN";				break;
		case MGMT_SHIM_ERROR_REPLY_ORUN:				p = "MGMT_SHIM_ERROR_REPLY_ORUN";				break;
		case MGMT_SHIM_ERROR_NO_SUCH_BOARD:				p = "MGMT_SHIM_ERROR_NO_SUCH_BOARD";			break;
		case MGMT_SHIM_ERROR_NO_SUCH_TRACE:				p = "MGMT_SHIM_ERROR_NO_SUCH_TRACE";			break;
		case MGMT_SHIM_ERROR_DUPLICATE_TRACE_HANDLE:	p = "MGMT_SHIM_ERROR_DUPLICATE_TRACE_HANDLE";	break;
		case MGMT_SHIM_ERROR_CANNOT_OPEN_TRACE_CHAN:	p = "MGMT_SHIM_ERROR_CANNOT_OPEN_TRACE_CHAN";	break;

		default:										sprintf(buffer, "UNKNOWN (%d)", nResult);		break;
	}

	return p;
}

char const * CacheTypeToString(uint16 const eType)
{
	static char buffer[4096];
	char const * p = buffer;

	switch (eType)
	{
		case SHIM(MGMT_BOARD_NO):		p = "SHIM(MGMT_BOARD_NO)";				break;
		case SHIM(MGMT_BOARD_INFO):		p = "SHIM(MGMT_BOARD_INFO)";			break;
		case SHIM(MGMT_SHIM_VER):		p = "SHIM(MGMT_SHIM_VER)";				break;
		case SHIM(MGMT_STOP_TRC):		p = "SHIM(MGMT_STOP_TRC)";				break;
		case SHIM(MGMT_DRV_VERS):		p = "SHIM(MGMT_DRV_VERS)";				break;

		case ADAPTER_INFO:				p = "ADAPTER_INFO";						break;
		case ADAPTER_STATE:				p = "ADAPTER_STATE";					break;
		case MODEM_NATIONALITY:			p = "MODEM_NATIONALITY";				break;
		case MGMT_PROTOCOL_VERSION:		p = "MGMT_PROTOCOL_VERSION";			break;

		case DS1_CONFIG:				p = "DS1_CONFIG";						break;
		case DS1_EXT_CONFIG:			p = "DS1_EXT_CONFIG";					break;
		case DS1_STATUS:				p = "DS1_STATUS";						break;
		case DS1_EXT_STATUS:			p = "DS1_EXT_STATUS";					break;
		case DS1_CT1_SIG_STATUS:		p = "DS1_CT1_SIG_STATUS";				break;
		case DS1_ALL_CT1_SIG_STATUS:	p = "DS1_ALL_CT1_SIG_STATUS";			break;

		case BRI_CONFIG:				p = "BRI_CONFIG";						break;
		case BRI_STATUS:				p = "BRI_STATUS";						break;

		case CALL_STATUS:				p = "CALL_STATUS";						break;
		case ALL_CALL_STATUS:			p = "ALL_CALL_STATUS";					break;

		case MODEM_CONFIG:				p = "MODEM_CONFIG";						break;
		case MODEM_STATUS:				p = "MODEM_STATUS";						break;
		case MODEM_EXT_CONFIG:			p = "MODEM_EXT_CONFIG";					break;
		case MODEM_EXT_STATUS:			p = "MODEM_EXT_STATUS";					break;
		case MODEM_TX_DATA:				p = "MODEM_TX_DATA";					break;
		case MODEM_RX_DATA:				p = "MODEM_RX_DATA";					break;

		case DCHAN_EXT_CONFIG:			p = "DCHAN_EXT_CONFIG";					break;
		case DCHAN_EXT_STATUS:			p = "DCHAN_EXT_STATUS";					break;
		case DCHAN_TX_DATA:				p = "DCHAN_TX_DATA";					break;
		case DCHAN_RX_DATA:				p = "DCHAN_RX_DATA";					break;
		case DCHAN_RXTX_DATA:			p = "DCHAN_RXTX_DATA";					break;

		case BCHAN_STATUS:				p = "BCHAN_STATUS";						break;
		case BCHAN_EXT_CONFIG:			p = "BCHAN_EXT_CONFIG";					break;
		case BCHAN_EXT_STATUS:			p = "BCHAN_EXT_STATUS";					break;
		case BCHAN_TX_DATA:				p = "BCHAN_TX_DATA";					break;
		case BCHAN_RX_DATA:				p = "BCHAN_RX_DATA";					break;

		case SERIAL_STATUS:				p = "SERIAL_STATUS";					break;
		case SERIAL_EXT_CONFIG:			p = "SERIAL_EXT_CONFIG";				break;
		case SERIAL_EXT_STATUS:			p = "SERIAL_EXT_STATUS";				break;
		case SERIAL_TX_DATA:			p = "SERIAL_TX_DATA";					break;
		case SERIAL_RX_DATA:			p = "SERIAL_RX_DATA";					break;
		case SERIAL_CONFIG:				p = "SERIAL_CONFIG";					break;

		default:						sprintf(buffer, "UNKNOWN (%d)", eType);	break;
	}

	return p;
}

char const * MgmtCommandToString(uint16 const nCommand)
{
	static char buffer[4096];
	char const * p = buffer;

	switch (nCommand)
	{
		case GET_MGMT_BOARD_NO:				p = "GET_MGMT_BOARD_NO";					break;
		case GET_MGMT_BOARD_INFO:			p = "GET_MGMT_BOARD_INFO";					break;
		case GET_MGMT_SHIM_VER:				p = "GET_MGMT_SHIM_VER";					break;
		case SET_MGMT_STOP_TRC:				p = "SET_MGMT_STOP_TRC";					break;
		case GET_MGMT_DRV_VERS:				p = "GET_MGMT_DRV_VERS";					break;

		case GET_MGMT_PROTOCOL_VERSION:		p = "GET_MGMT_PROTOCOL_VERSION";			break;
		case GET_ADAPTER_INFO:				p = "GET_ADAPTER_INFO";						break;
		case GET_ADAPTER_STATE:				p = "GET_ADAPTER_STATE";					break;
		case GET_MODEM_NATIONALITY:			p = "GET_MODEM_NATIONALITY";				break;
		case SET_MODEM_NATIONALITY:			p = "SET_MODEM_NATIONALITY";				break;

		case GET_DS1_CONFIG:				p = "GET_DS1_CONFIG";						break;
		case SET_DS1_CONFIG:				p = "SET_DS1_CONFIG";						break;
		case SET_DS1_CONFIG_TRC:			p = "SET_DS1_CONFIG_TRC";					break;
		case GET_DS1_CONFIG_TRC:			p = "GET_DS1_CONFIG_TRC";					break;
		case GET_DS1_EXT_CONFIG:			p = "GET_DS1_EXT_CONFIG";					break;
		case SET_DS1_EXT_CONFIG:			p = "SET_DS1_EXT_CONFIG";					break;
		case SET_DS1_EXT_CONFIG_TRC:		p = "SET_DS1_EXT_CONFIG_TRC";				break;
		case GET_DS1_EXT_CONFIG_TRC:		p = "GET_DS1_EXT_CONFIG_TRC";				break;
		case GET_DS1_STATUS:				p = "GET_DS1_STATUS";						break;
		case SET_DS1_STATUS_TRC:			p = "SET_DS1_STATUS_TRC";					break;
		case GET_DS1_STATUS_TRC:			p = "GET_DS1_STATUS_TRC";					break;
		case GET_DS1_EXT_STATUS:			p = "GET_DS1_EXT_STATUS";					break;
		case SET_DS1_EXT_STATUS_TRC:		p = "SET_DS1_EXT_STATUS_TRC";				break;
		case GET_DS1_EXT_STATUS_TRC:		p = "GET_DS1_EXT_STATUS_TRC";				break;
		case GET_DS1_CT1_SIG_STATUS:		p = "GET_DS1_CT1_SIG_STATUS";				break;
		case GET_DS1_ALL_CT1_SIG_STATUS:	p = "GET_DS1_ALL_CT1_SIG_STATUS";			break;

		case GET_BRI_CONFIG:				p = "GET_BRI_CONFIG";						break;
		case SET_BRI_CONFIG:				p = "SET_BRI_CONFIG";						break;
		case GET_BRI_STATUS:				p = "GET_BRI_STATUS";						break;
		case GET_BRI_CONFIG_TRC:			p = "GET_BRI_CONFIG_TRC";					break;
		case SET_BRI_CONFIG_TRC:			p = "SET_BRI_CONFIG_TRC";					break;
		case GET_BRI_STATUS_TRC:			p = "GET_BRI_STATUS_TRC";					break;
		case SET_BRI_STATUS_TRC:			p = "SET_BRI_STATUS_TRC";					break;

		case GET_SERIAL_CONFIG:				p = "GET_SERIAL_CONFIG";					break;
		case SET_SERIAL_CONFIG:				p = "SET_SERIAL_CONFIG";					break;
		case GET_SERIAL_STATUS:				p = "GET_SERIAL_STATUS";					break;
		case GET_SERIAL_EXT_CONFIG:			p = "GET_SERIAL_EXT_CONFIG";				break;
		case SET_SERIAL_EXT_CONFIG:			p = "SET_SERIAL_EXT_CONFIG";				break;
		case GET_SERIAL_EXT_STATUS:			p = "GET_SERIAL_EXT_STATUS";				break;
		case GET_SERIAL_CONFIG_TRC:			p = "GET_SERIAL_CONFIG_TRC";				break;
		case SET_SERIAL_CONFIG_TRC:			p = "SET_SERIAL_CONFIG_TRC";				break;
		case GET_SERIAL_STATUS_TRC:			p = "GET_SERIAL_STATUS_TRC";				break;
		case SET_SERIAL_STATUS_TRC:			p = "SET_SERIAL_STATUS_TRC";				break;
		case GET_SERIAL_EXT_CONFIG_TRC:		p = "GET_SERIAL_EXT_CONFIG_TRC";			break;
		case SET_SERIAL_EXT_CONFIG_TRC:		p = "SET_SERIAL_EXT_CONFIG_TRC";			break;
		case GET_SERIAL_EXT_STATUS_TRC:		p = "GET_SERIAL_EXT_STATUS_TRC";			break;
		case SET_SERIAL_EXT_STATUS_TRC:		p = "SET_SERIAL_EXT_STATUS_TRC";			break;
		case GET_SERIAL_TX_DATA_TRC:		p = "GET_SERIAL_TX_DATA_TRC";				break;
		case SET_SERIAL_TX_DATA_TRC:		p = "SET_SERIAL_TX_DATA_TRC";				break;
		case GET_SERIAL_RX_DATA_TRC:		p = "GET_SERIAL_RX_DATA_TRC";				break;
		case SET_SERIAL_RX_DATA_TRC:		p = "SET_SERIAL_RX_DATA_TRC";				break;

		case GET_CALL_STATUS:				p = "GET_CALL_STATUS";						break;
		case GET_CALL_STATUS_TRC:			p = "GET_CALL_STATUS_TRC";					break;
		case SET_CALL_STATUS_TRC:			p = "SET_CALL_STATUS_TRC";					break;
		case GET_ALL_CALL_STATUS:			p = "GET_ALL_CALL_STATUS";					break;

		case GET_MODEM_CONFIG:				p = "GET_MODEM_CONFIG";						break;
		case SET_MODEM_CONFIG:				p = "SET_MODEM_CONFIG";						break;
		case GET_MODEM_CONFIG_TRC:			p = "GET_MODEM_CONFIG_TRC";					break;
		case SET_MODEM_CONFIG_TRC:			p = "SET_MODEM_CONFIG_TRC";					break;
		case GET_MODEM_STATUS:				p = "GET_MODEM_STATUS";						break;
		case GET_MODEM_STATUS_TRC:			p = "GET_MODEM_STATUS_TRC";					break;
		case SET_MODEM_STATUS_TRC:			p = "SET_MODEM_STATUS_TRC";					break;
		case GET_MODEM_EXT_CONFIG:			p = "GET_MODEM_EXT_CONFIG";					break;
		case SET_MODEM_EXT_CONFIG:			p = "SET_MODEM_EXT_CONFIG";					break;
		case GET_MODEM_EXT_CONFIG_TRC:		p = "GET_MODEM_EXT_CONFIG_TRC";				break;
		case SET_MODEM_EXT_CONFIG_TRC:		p = "SET_MODEM_EXT_CONFIG_TRC";				break;
		case GET_MODEM_EXT_STATUS:			p = "GET_MODEM_EXT_STATUS";					break;
		case GET_MODEM_EXT_STATUS_TRC:		p = "GET_MODEM_EXT_STATUS_TRC";				break;
		case SET_MODEM_EXT_STATUS_TRC:		p = "SET_MODEM_EXT_STATUS_TRC";				break;

		case GET_DCHAN_EXT_CONFIG:			p = "GET_DCHAN_EXT_CONFIG";					break;
		case SET_DCHAN_EXT_CONFIG:			p = "SET_DCHAN_EXT_CONFIG";					break;
		case GET_DCHAN_EXT_CONFIG_TRC:		p = "GET_DCHAN_EXT_CONFIG_TRC";				break;
		case SET_DCHAN_EXT_CONFIG_TRC:		p = "SET_DCHAN_EXT_CONFIG_TRC";				break;
		case GET_DCHAN_EXT_STATUS:			p = "GET_DCHAN_EXT_STATUS";					break;
		case GET_DCHAN_EXT_STATUS_TRC:		p = "GET_DCHAN_EXT_STATUS_TRC";				break;
		case SET_DCHAN_EXT_STATUS_TRC:		p = "SET_DCHAN_EXT_STATUS_TRC";				break;
		case GET_DCHAN_DATA_TRC:			p = "GET_DCHAN_DATA_TRC";					break;
		case SET_DCHAN_DATA_TRC:			p = "SET_DCHAN_DATA_TRC";					break;
		case GET_DCHAN_TX_DATA_TRC:			p = "GET_DCHAN_TX_DATA_TRC";				break;
		case SET_DCHAN_TX_DATA_TRC:			p = "SET_DCHAN_TX_DATA_TRC";				break;
		case GET_DCHAN_RX_DATA_TRC:			p = "GET_DCHAN_RX_DATA_TRC";				break;
		case SET_DCHAN_RX_DATA_TRC:			p = "SET_DCHAN_RX_DATA_TRC";				break;

		case GET_BCHAN_STATUS:				p = "GET_BCHAN_STATUS";						break;
		case GET_BCHAN_STATUS_TRC:			p = "GET_BCHAN_STATUS_TRC";					break;
		case SET_BCHAN_STATUS_TRC:			p = "SET_BCHAN_STATUS_TRC";					break;
		case GET_BCHAN_EXT_CONFIG:			p = "GET_BCHAN_EXT_CONFIG";					break;
		case SET_BCHAN_EXT_CONFIG:			p = "SET_BCHAN_EXT_CONFIG";					break;
		case GET_BCHAN_EXT_CONFIG_TRC:		p = "GET_BCHAN_EXT_CONFIG_TRC";				break;
		case SET_BCHAN_EXT_CONFIG_TRC:		p = "SET_BCHAN_EXT_CONFIG_TRC";				break;
		case GET_BCHAN_EXT_STATUS:			p = "GET_BCHAN_EXT_STATUS";					break;
		case GET_BCHAN_EXT_STATUS_TRC:		p = "GET_BCHAN_EXT_STATUS_TRC";				break;
		case SET_BCHAN_EXT_STATUS_TRC:		p = "SET_BCHAN_EXT_STATUS_TRC";				break;
		case GET_BCHAN_TX_DATA_TRC:			p = "GET_BCHAN_TX_DATA_TRC";				break;
		case SET_BCHAN_TX_DATA_TRC:			p = "SET_BCHAN_TX_DATA_TRC";				break;
		case GET_BCHAN_RX_DATA_TRC:			p = "GET_BCHAN_RX_DATA_TRC";				break;
		case SET_BCHAN_RX_DATA_TRC:			p = "SET_BCHAN_RX_DATA_TRC";				break;

		default:							sprintf(buffer, "UNKNOWN (%d)", nCommand);	break;
	}

	return p;
}

char const * UnsignedToString(unsigned n)
{
	static char buffer[4096];

	sprintf(buffer, "%u", n);

	return buffer;
}

char const * RawBytesToString(void const * const pv, size_t const cb)
{
	static char buffer[4096];
	char * pc = buffer;
	BYTE const * const pb = pv;
	size_t i;

	pc += sprintf(pc, "\n  Length: %u", cb);

	if (pv == NULL)
	{
		pc += sprintf(pc, " Pointer: NULL");
	}
	else
	{
		for (i = 0; i < cb; i++)
		{
			if ((i % 8) == 0)
				pc += sprintf(pc, "\n%-6X:", i);

			pc += sprintf(pc, " %02X", pb[i]);
		}
	}

	pc += sprintf(pc, "\n");

	return buffer;
}

