/*****************************************************************************
 * Copyright (c) 1990-2000 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
 *
 *****************************************************************************/

static const char pam_snmp_c_rcsid[] = "@(#) " "$Id: pam_snmp.c,v 1.30 2000/06/13 22:04:01 jamesp Exp $";

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#if defined PLATFORM_WINDOWS
#include <windows.h>
#endif

#if defined PLATFORM_NETWARE
#include <nwservst.h>
#endif

#include "pam_snmp.h"
#include "span.h"
#include "dbgprintf.h"


enum ValueTypes
{
	VT_UINT32, VT_UINT16, VT_UINT8, VT_ADAPTER, VT_PORT, VT_CHANNEL, VT_TEXT
};

typedef struct RESPONSE_CONTROL
{
	UCHAR *Name;
	enum ValueTypes ValueType;
	int ValueLength;				/* only used for text types (zero means null terminated variable length string) */
	void *Value;
}
ResponseControl;

/*-----------------------------------------------------------------------------------------------*/


static get_mgmt_shim_ver_response_t ManagementShimVersionResponse;
static get_mgmt_board_no_response_t ManagementBoardCountResponse;
static get_mgmt_board_info_response_t ManagementBoardInfoResponse;
static get_mgmt_drv_vers_response_t ManagementDriverVersionsResponse;

static get_adapter_state_response_t AdapterStateResponse;
static get_adapter_info_response_t AdapterInfoResponse;
static get_modem_nationality_response_t ModemNationalityResponse;
static get_mgmt_protocol_ver_response_t ManagementProtocolVersionResponse;

static get_ds1_config_response_t DS1ConfigurationResponse;
static get_ds1_ext_config_response_t DS1ExtendedConfigurationResponse;
static get_ds1_status_response_t DS1StatusResponse;
static get_ds1_ext_status_response_t DS1ExtendedStatusResponse;
static get_ds1_ct1_sig_status_response_t DS1CT1SignalStatusResponse;
static get_all_ds1_ct1_sig_status_response_t DS1AllCT1SignalStatusResponse;

static get_bri_config_response_t BRIConfigurationResponse;
static get_bri_status_response_t BRIStatusResponse;

static get_serial_config_response_t SerialConfigurationResponse;
static get_serial_test_config_response_t SerialTestConfigurationResponse;
static get_serial_status_response_t SerialStatusResponse;
static get_serial_test_status_response_t SerialTestStatusResponse;
static get_serial_ext_config_response_t SerialExtendedConfigurationResponse;
static get_serial_ext_status_response_t SerialExtendedStatusResponse;

static get_call_status_response_t CallStatusResponse;
static get_all_call_status_response_t CallAllStatusResponse;

static get_modem_config_response_t ModemConfigurationResponse;
static get_modem_status_response_t ModemStatusResponse;
static get_modem_ext_config_response_t ModemExtendedConfigurationResponse;
static get_modem_ext_status_response_t ModemExtendedStatusResponse;

static get_dchan_ext_config_response_t DChannelExtendedConfigurationResponse;
static get_dchan_ext_status_response_t DChannelExtendedStatusResponse;

static get_bchan_status_response_t BChannelStatusResponse;
static get_bchan_ext_config_response_t BChannelExtendedConfigurationResponse;
static get_bchan_ext_status_response_t BChannelExtendedStatusResponse;

static get_serial_channel_test_mode_response_t SerialTestChannelModeResponse;


static uint32 my_pamagent_version = 0x00010008;
static uint32 my_mgmt_protocol_version = MGMT_PROTOCOL_VERSION_VALUE;

ResponseControl AgentInformation[] =
{
	{(UCHAR *)"MESSAGE", VT_TEXT, 0, (void *)"AGENT_INFORMATION"},
	{(UCHAR *)"NAME", VT_TEXT, 0, "Digi PortAssist Manager Communication Agent"},
	{(UCHAR *)"VERSION", VT_UINT32, (int)0, &my_pamagent_version},
	{(UCHAR *)"BUILD_DATE", VT_TEXT, (int)0, __DATE__},
	{(UCHAR *)"BUILD_TIME", VT_TEXT, (int)0, __TIME__},
	{(UCHAR *)"MANAGEMENT_CHANNEL_REV", VT_UINT32, (int)0, &my_mgmt_protocol_version},
	/* more added by function */
	{(UCHAR *)NULL, VT_UINT32, (int)0, NULL}
};


ResponseControl ManagementShimVersion[] =
{
	{(UCHAR *)"MESSAGE", VT_TEXT, 0, "MANAGEMENT_SHIM_VERSION"},
	{(UCHAR *)"VERSION", VT_UINT32, 0, &ManagementShimVersionResponse.ver},
	{(UCHAR *)NULL, VT_UINT32, 0, NULL}
};

ResponseControl ManagementBoardCount[] =
{
	{(UCHAR *)"MESSAGE", VT_TEXT, 0, "MANAGEMENT_BOARD_COUNT"},
	{(UCHAR *)"BOARD_COUNT", VT_UINT32, 0, &ManagementBoardCountResponse.NumberOfBoards},
	{(UCHAR *)NULL, VT_UINT32, 0, NULL}};

ResponseControl ManagementBoardInfo[] =
{
	{(UCHAR *)"MESSAGE", VT_TEXT, 0, "MANAGEMENT_BOARD_INFO"},
	{(UCHAR *)"ADAPTER", VT_ADAPTER, 0, NULL},
	{(UCHAR *)"BOARD_NUMBER", VT_UINT32, 0, &ManagementBoardInfoResponse.BoardInfo.BoardNo},
	{(UCHAR *)"BOARD_ID", VT_UINT32, 0, &ManagementBoardInfoResponse.BoardInfo.BrdId},
	{(UCHAR *)"BOARD_TYPE", VT_UINT32, 0, &ManagementBoardInfoResponse.BoardInfo.BoardType},
	{(UCHAR *)"TOTAL_CHANNELS", VT_UINT32, 0, &ManagementBoardInfoResponse.BoardInfo.TotalChannels},
	{(UCHAR *)"TOTAL_PORTS", VT_UINT32, 0, &ManagementBoardInfoResponse.BoardInfo.TotalPorts},
	{(UCHAR *)NULL, VT_UINT32, 0, NULL}};

ResponseControl ManagementDriverVersions[] =
{
	{(UCHAR *)"MESSAGE", VT_TEXT, 0, "MANAGEMENT_DRIVER_VERSIONS"},
	{(UCHAR *)"DRIVER_COUNT", VT_UINT32, 0, &ManagementDriverVersionsResponse.versions.driverCount},
	/* more added by function */
	{(UCHAR *)NULL, VT_UINT32, 0, NULL}};


ResponseControl AdapterState[] =
{
	{(UCHAR *)"MESSAGE", VT_TEXT, 0, "ADAPTER_STATE"},
	{(UCHAR *)"ADAPTER", VT_ADAPTER, 0, NULL},
	{(UCHAR *)"MEMORY_USAGE", VT_UINT32, 0, &AdapterStateResponse.state.memory_usage},
	{(UCHAR *)"CPU_USAGE", VT_UINT32, 0, &AdapterStateResponse.state.cpu_usage},
	{(UCHAR *)"HOST_TO_ADAPTER_COUNT", VT_UINT32, 0, &AdapterStateResponse.state.dxb_h2a_count},
	{(UCHAR *)"ADAPTER_TO_HOST_COUNT", VT_UINT32, 0, &AdapterStateResponse.state.dxb_a2h_count},
	{(UCHAR *)"RUNNING_SECONDS", VT_UINT32, 0, &AdapterStateResponse.state.uptime.seconds},
	{(UCHAR *)"RUNNING_MILLISECONDS", VT_UINT32, 0, &AdapterStateResponse.state.uptime.mseconds},
	{(UCHAR *)NULL, VT_UINT32, 0, NULL}};

ResponseControl AdapterInfo[] =
{
	{(UCHAR *)"MESSAGE", VT_TEXT, 0, "ADAPTER_INFO"},
	{(UCHAR *)"ADAPTER", VT_ADAPTER, 0, NULL},
	{(UCHAR *)"BOARD_TYPE", VT_UINT32, 0, &AdapterInfoResponse.info.board_type},
	{(UCHAR *)"PORT_COUNT", VT_UINT32, 0, &AdapterInfoResponse.info.port_count},
	{(UCHAR *)"CHANNELS_PER_PORT", VT_UINT32, 0, &AdapterInfoResponse.info.channels_per_port},
	{(UCHAR *)"MEMORY_SIZE", VT_UINT32, 0, &AdapterInfoResponse.info.memory_size},
	{(UCHAR *)"FEP_VERSION", VT_UINT32, 0, &AdapterInfoResponse.info.fep_version},
	{(UCHAR *)"CSC_VERSION", VT_UINT32, 0, &AdapterInfoResponse.info.csc_version},
	{(UCHAR *)"PUMP_VERSION", VT_UINT32, 0, &AdapterInfoResponse.info.pump_version},
	{(UCHAR *)"MAIN_BOARD_REVISION", VT_UINT32, 0, &AdapterInfoResponse.info.main_board_revision},
	{(UCHAR *)"MAIN_BOARD_SERIAL", VT_TEXT, SN_MAX, &AdapterInfoResponse.info.main_board_serial},
	{(UCHAR *)"DAUGHTER_CARD_REVISION", VT_UINT32, 0, &AdapterInfoResponse.info.daughter_card_revision},
	{(UCHAR *)"DAUGHTER_CARD_SERIAL", VT_TEXT, SN_MAX, &AdapterInfoResponse.info.daughter_card_serial},
	{(UCHAR *)"PART_NUMBER", VT_TEXT, PN_MAX, &AdapterInfoResponse.info.part_number},
	{(UCHAR *)NULL, VT_UINT32, 0, NULL}};

ResponseControl ModemNationality[] =
{
	{(UCHAR *)"MESSAGE", VT_TEXT, 0, "MODEM_NATIONALITY"},
	{(UCHAR *)"ADAPTER", VT_ADAPTER, 0, NULL},
	{(UCHAR *)"COUNTRY_CODE", VT_UINT32, 0, &ModemNationalityResponse.country_code},
	{(UCHAR *)NULL, VT_UINT32, 0, NULL}};

ResponseControl ManagementProtocolVersion[] =
{
	{(UCHAR *)"MESSAGE", VT_TEXT, 0, "MANAGEMENT_PROTOCOL_VERSION"},
	{(UCHAR *)"ADAPTER", VT_ADAPTER, 0, NULL},
	{(UCHAR *)"VERSION", VT_UINT32, 0, &ManagementProtocolVersionResponse.mgmt_protocol_version},
	{(UCHAR *)NULL, VT_UINT32, 0, NULL}};


ResponseControl DS1Configuration[] =
{
	{(UCHAR *)"MESSAGE", VT_TEXT, 0, "DS1_CONFIGURATION"},
	{(UCHAR *)"ADAPTER", VT_ADAPTER, 0, NULL},
	{(UCHAR *)"PORT", VT_PORT, 0, NULL},
	{(UCHAR *)"CODING", VT_UINT32, 0, &DS1ConfigurationResponse.config.coding},
	{(UCHAR *)"FRAMING", VT_UINT32, 0, &DS1ConfigurationResponse.config.framing},
	{(UCHAR *)"IF_TYPE", VT_UINT32, 0, &DS1ConfigurationResponse.config.if_type},
	{(UCHAR *)"LONG_HAUL_LINE_BUILD_OUT", VT_UINT32, 0, &DS1ConfigurationResponse.config.long_haul_lbo},
	{(UCHAR *)"SHORT_HAUL_LENGTH", VT_UINT32, 0, &DS1ConfigurationResponse.config.short_haul_len},
	{(UCHAR *)"SIGNALING", VT_UINT32, 0, &DS1ConfigurationResponse.config.signalling},
	{(UCHAR *)"WINK_DIGITS", VT_UINT32, 0, &DS1ConfigurationResponse.config.wink_digits},
	{(UCHAR *)"CLOCKING", VT_UINT32, 0, &DS1ConfigurationResponse.config.clocking},
	{(UCHAR *)"JITTER_ATTENUATION", VT_UINT32, 0, &DS1ConfigurationResponse.config.jitter_atten},
	{(UCHAR *)"EQ_GAIN_LIMIT", VT_UINT32, 0, &DS1ConfigurationResponse.config.eq_gain_limit},
	{(UCHAR *)"LEASED_MASK", VT_UINT32, 0, &DS1ConfigurationResponse.config.leased_mask},
	{(UCHAR *)"NFAS", VT_UINT32, 0, &DS1ConfigurationResponse.config.nfas_master_port},
	{(UCHAR *)NULL, VT_UINT32, 0, NULL}};

ResponseControl DS1ExtendedConfiguration[] =
{
	{(UCHAR *)"MESSAGE", VT_TEXT, 0, "DS1_EXTENDED_CONFIGURATION"},
	{(UCHAR *)"ADAPTER", VT_ADAPTER, 0, NULL},
	{(UCHAR *)"PORT", VT_PORT, 0, NULL},
	{(UCHAR *)"TRANSMIT_SPECIAL", VT_UINT32, 0, &DS1ExtendedConfigurationResponse.config.tx_special},
	{(UCHAR *)"AUTO_CONFIGURATION", VT_UINT32, 0, &DS1ExtendedConfigurationResponse.config.auto_config},
	{(UCHAR *)"LOOPBACK", VT_UINT32, 0, &DS1ExtendedConfigurationResponse.config.loopback},
	{(UCHAR *)NULL, VT_UINT32, 0, NULL}};

ResponseControl DS1Status[] =
{
	{(UCHAR *)"MESSAGE", VT_TEXT, 0, "DS1_STATUS"},
	{(UCHAR *)"ADAPTER", VT_ADAPTER, 0, NULL},
	{(UCHAR *)"PORT", VT_PORT, 0, NULL},
	{(UCHAR *)"RECEIVE_SPECIAL", VT_UINT32, 0, &DS1StatusResponse.status.rx_special},
	{(UCHAR *)"ALARM", VT_UINT32, 0, &DS1StatusResponse.status.alarm},
	{(UCHAR *)"LOOPBACK", VT_UINT32, 0, &DS1StatusResponse.status.loopback},
	{(UCHAR *)NULL, VT_UINT32, 0, NULL}};

ResponseControl DS1ExtendedStatus[] =
{
	{(UCHAR *)"MESSAGE", VT_TEXT, 0, "DS1_EXTENDED_STATUS"},
	{(UCHAR *)"ADAPTER", VT_ADAPTER, 0, NULL},
	{(UCHAR *)"PORT", VT_PORT, 0, NULL},
	{(UCHAR *)"ERROR_SECONDS", VT_UINT32, 0, &DS1ExtendedStatusResponse.status.errored_seconds},
	{(UCHAR *)"UNAVAILABLE_SECONDS", VT_UINT32, 0, &DS1ExtendedStatusResponse.status.unavailable_seconds},
	{(UCHAR *)"BURSTY_SECONDS", VT_UINT32, 0, &DS1ExtendedStatusResponse.status.bursty_seconds},
	{(UCHAR *)"SEVERE_SECONDS", VT_UINT32, 0, &DS1ExtendedStatusResponse.status.severe_seconds},
	{(UCHAR *)"SEVERE_FRAMING_SECONDS", VT_UINT32, 0, &DS1ExtendedStatusResponse.status.severe_framing_seconds},
	{(UCHAR *)"CONTROLLED_SLIP_SECONDS", VT_UINT32, 0, &DS1ExtendedStatusResponse.status.controlled_slip_seconds},
	{(UCHAR *)"LOSS_OF_FRAME_FAILURE", VT_UINT32, 0, &DS1ExtendedStatusResponse.status.loss_of_frame_count},
	{(UCHAR *)"DEGRADED_MINUTES", VT_UINT32, 0, &DS1ExtendedStatusResponse.status.degraded_minutes},
	{(UCHAR *)"LINE_ERRORED_SECONDS", VT_UINT32, 0, &DS1ExtendedStatusResponse.status.line_errored_seconds},
	{(UCHAR *)"LINE_CODE_VIOLATIONS", VT_UINT32, 0, &DS1ExtendedStatusResponse.status.line_code_violations},
	{(UCHAR *)"CRC_ERROR", VT_UINT32, 0, &DS1ExtendedStatusResponse.status.crc_error_count},
	{(UCHAR *)NULL, VT_UINT32, 0, NULL}};

ResponseControl DS1CT1SignalStatus[] =
{
	{(UCHAR *)"MESSAGE", VT_TEXT, 0, "DS1_CT1_SIGNAL_STATUS"},
	{(UCHAR *)"ADAPTER", VT_ADAPTER, 0, NULL},
	{(UCHAR *)"PORT", VT_PORT, 0, NULL},
	{(UCHAR *)"CHANNEL", VT_CHANNEL, 0, NULL},
	{(UCHAR *)"TRANSMIT_SIGNAL_BITS", VT_UINT8, 0, &DS1CT1SignalStatusResponse.signal.tx_signal_bits},
	{(UCHAR *)"RECEIVE_SIGNAL_BITS", VT_UINT8, 0, &DS1CT1SignalStatusResponse.signal.rx_signal_bits},
	{(UCHAR *)"SIGNAL_STATE", VT_UINT8, 0, &DS1CT1SignalStatusResponse.signal.state},
	{(UCHAR *)"PAD", VT_UINT8, 0, &DS1CT1SignalStatusResponse.signal.pad},
	{(UCHAR *)NULL, VT_UINT32, 0, NULL}};

uint32 CT1Count = CT1_SIG_MAX;
ResponseControl DS1AllCT1SignalStatus[] =
{
	{(UCHAR *)"MESSAGE", VT_TEXT, 0, "DS1_ALL_CT1_SIGNAL_STATUS"},
	{(UCHAR *)"ADAPTER", VT_ADAPTER, 0, NULL},
	{(UCHAR *)"PORT", VT_PORT, 0, NULL},
	{(UCHAR *)"MAX_COUNT", VT_UINT32, 0, &CT1Count,},
	/* more added by function */
	{(UCHAR *)NULL, VT_UINT32, 0, NULL}};


static uint32 BRICount = MSN_MAX;
ResponseControl BRIConfiguration[] =
{
	{(UCHAR *)"MESSAGE", VT_TEXT, 0, "BRI_CONFIGURATION"},
	{(UCHAR *)"ADAPTER", VT_ADAPTER, 0, NULL},
	{(UCHAR *)"PORT", VT_PORT, 0, NULL},
	{(UCHAR *)"SWITCH_TYPE", VT_UINT32, 0, &BRIConfigurationResponse.config.switch_type},
	{(UCHAR *)"AUTO_SPID", VT_UINT32, 0, &BRIConfigurationResponse.config.auto_spid},
	{(UCHAR *)"LEASED_MASK", VT_UINT32, 0, &BRIConfigurationResponse.config.leased_mask},
	{(UCHAR *)"DIRECTORY_COUNT", VT_UINT32, 0, &BRIConfigurationResponse.config.dir_count},
	{(UCHAR *)"MULTIPLE_SUBSCRIBER_NUMBER", VT_UINT32, 0, &BRIConfigurationResponse.config.msn},
	{(UCHAR *)"AUTO_ALERT", VT_UINT32, 0, &BRIConfigurationResponse.config.autoalert},
	{(UCHAR *)"MAX_COUNT", VT_UINT32, 0, &BRICount,},
	/* more added by function */
	{(UCHAR *)NULL, VT_UINT32, 0, NULL}};

ResponseControl BRIStatus[] =
{
	{(UCHAR *)"MESSAGE", VT_TEXT, 0, "BRI_STATUS"},
	{(UCHAR *)"ADAPTER", VT_ADAPTER, 0, NULL},
	{(UCHAR *)"PORT", VT_PORT, 0, NULL},
	{(UCHAR *)"POWER", VT_UINT32, 0, &BRIStatusResponse.status.power},
	{(UCHAR *)"ACTIVATION_STATE", VT_UINT32, 0, &BRIStatusResponse.status.activation_state},
	{(UCHAR *)"RECEIVE_INFO_STATE", VT_UINT32, 0, &BRIStatusResponse.status.rx_info_state},
	{(UCHAR *)"TRANSMIT_INFO_STATE", VT_UINT32, 0, &BRIStatusResponse.status.tx_info_state},
	{(UCHAR *)"LOSS_OF_SYNC", VT_UINT32, 0, &BRIStatusResponse.status.loss_of_sync},
	{(UCHAR *)"COLLISIONS", VT_UINT32, 0, &BRIStatusResponse.status.collisions},
	{(UCHAR *)"SPID_COUNT", VT_UINT32, 0, &BRIStatusResponse.status.spid_count},
	/* more added by function */
	{(UCHAR *)NULL, VT_UINT32, 0, NULL}};


ResponseControl SerialConfiguration[] =
{
	{(UCHAR *)"MESSAGE", VT_TEXT, 0, "SERIAL_CONFIGURATION"},
	{(UCHAR *)"ADAPTER", VT_ADAPTER, 0, NULL},
	{(UCHAR *)"CHANNEL", VT_CHANNEL, 0, NULL},
	{(UCHAR *)"PORT_TYPE", VT_UINT32, 0, &SerialConfigurationResponse.config.port_type},
	{(UCHAR *)"CLOCK_SOURCE", VT_UINT32, 0, &SerialConfigurationResponse.config.clock_source},
	{(UCHAR *)"ALTERNATE_PIN", VT_UINT32, 0, &SerialConfigurationResponse.config.alt_pin},
	{(UCHAR *)NULL, VT_UINT32, 0, NULL}};

ResponseControl SerialTestConfiguration[] =
{
	{(UCHAR *)"MESSAGE", VT_TEXT, 0, "SERIAL_TEST_CONFIGURATION"},
	{(UCHAR *)"ADAPTER", VT_ADAPTER, 0, NULL},
	{(UCHAR *)"CHANNEL", VT_CHANNEL, 0, NULL},
	{(UCHAR *)"PORT_TYPE", VT_UINT32, 0, &SerialTestConfigurationResponse.cf.port_type},
	{(UCHAR *)"CLOCK_SOURCE", VT_UINT32, 0, &SerialTestConfigurationResponse.cf.clock_source},
	{(UCHAR *)"ALTERNATE_PIN", VT_UINT32, 0, &SerialTestConfigurationResponse.cf.alt_pin},
	{(UCHAR *)NULL, VT_UINT32, 0, NULL}};

ResponseControl SerialStatus[] =
{
	{(UCHAR *)"MESSAGE", VT_TEXT, 0, "SERIAL_STATUS"},
	{(UCHAR *)"ADAPTER", VT_ADAPTER, 0, NULL},
	{(UCHAR *)"CHANNEL", VT_CHANNEL, 0, NULL},
	{(UCHAR *)"PORT_STATE", VT_UINT32, 0, &SerialStatusResponse.status.port_state},
	{(UCHAR *)"FRAME_MODE", VT_UINT32, 0, &SerialStatusResponse.status.frame_mode},
	{(UCHAR *)"IN_SPEED", VT_UINT32, 0, &SerialStatusResponse.status.in_speed},
	{(UCHAR *)"OUT_SPEED", VT_UINT32, 0, &SerialStatusResponse.status.out_speed},
	{(UCHAR *)"AUTO_BAUD", VT_UINT32, 0, &SerialStatusResponse.status.autobaud},
	{(UCHAR *)"DATA_BITS", VT_UINT32, 0, &SerialStatusResponse.status.data_bits},
	{(UCHAR *)"STOP_BITS", VT_UINT32, 0, &SerialStatusResponse.status.stop_bits},
	{(UCHAR *)"PARITY", VT_UINT32, 0, &SerialStatusResponse.status.parity},
	/* more added by function */
	{(UCHAR *)NULL, VT_UINT32, 0, NULL}};

ResponseControl SerialTestStatus[] =
{
	{(UCHAR *)"MESSAGE", VT_TEXT, 0, "SERIAL_TEST_STATUS"},
	{(UCHAR *)"ADAPTER", VT_ADAPTER, 0, NULL},
	{(UCHAR *)"CHANNEL", VT_CHANNEL, 0, NULL},
	{(UCHAR *)"PORT_STATE", VT_UINT32, 0, &SerialTestStatusResponse.st.port_state},
	{(UCHAR *)"FRAME_MODE", VT_UINT32, 0, &SerialTestStatusResponse.st.frame_mode},
	{(UCHAR *)"IN_SPEED", VT_UINT32, 0, &SerialTestStatusResponse.st.in_speed},
	{(UCHAR *)"OUT_SPEED", VT_UINT32, 0, &SerialTestStatusResponse.st.out_speed},
	{(UCHAR *)"AUTO_BAUD", VT_UINT32, 0, &SerialTestStatusResponse.st.autobaud},
	{(UCHAR *)"DATA_BITS", VT_UINT32, 0, &SerialTestStatusResponse.st.data_bits},
	{(UCHAR *)"STOP_BITS", VT_UINT32, 0, &SerialTestStatusResponse.st.stop_bits},
	{(UCHAR *)"PARITY", VT_UINT32, 0, &SerialTestStatusResponse.st.parity},
	/* more added by function */
	{(UCHAR *)NULL, VT_UINT32, 0, NULL}};

ResponseControl SerialExtendedConfiguration[] =
{
	{(UCHAR *)"MESSAGE", VT_TEXT, 0, "SERIAL_EXTENDED_CONFIGURATION"},
	{(UCHAR *)"ADAPTER", VT_ADAPTER, 0, NULL},
	{(UCHAR *)"CHANNEL", VT_CHANNEL, 0, NULL},
	{(UCHAR *)"UNPAUSE_RX", VT_UINT32, 0, &SerialExtendedConfigurationResponse.config.unpause_rx},
	{(UCHAR *)"UNPAUSE_TX", VT_UINT32, 0, &SerialExtendedConfigurationResponse.config.unpause_tx},
#if defined(SERIAL_PORT_RESET)
	{(UCHAR *)"RESET", VT_UINT32, 0, &SerialExtendedConfigurationResponse.config.reset},
#endif
	{(UCHAR *)NULL, VT_UINT32, 0, NULL}};

ResponseControl SerialExtendedStatus[] =
{
	{(UCHAR *)"MESSAGE", VT_TEXT, 0, "SERIAL_EXTENDED_STATUS"},
	{(UCHAR *)"ADAPTER", VT_ADAPTER, 0, NULL},
	{(UCHAR *)"CHANNEL", VT_CHANNEL, 0, NULL},
	{(UCHAR *)"TRANSMITTED_BYTES", VT_UINT32, 0, &SerialExtendedStatusResponse.status.tx_bytes},
	{(UCHAR *)"RECEIVED_BYTES", VT_UINT32, 0, &SerialExtendedStatusResponse.status.rx_bytes},
	{(UCHAR *)"TRANSMITTED_FRAMES", VT_UINT32, 0, &SerialExtendedStatusResponse.status.tx_frames},
	{(UCHAR *)"RECEIVED_FRAMES", VT_UINT32, 0, &SerialExtendedStatusResponse.status.rx_frames},
	{(UCHAR *)"RECEIVED_BAD_FRAMES", VT_UINT32, 0, &SerialExtendedStatusResponse.status.rx_bad_frames},
	{(UCHAR *)"RECEIVED_SHORT_FRAMES", VT_UINT32, 0, &SerialExtendedStatusResponse.status.rx_short_frames},
	{(UCHAR *)"RECEIVED_LONG_FRAMES", VT_UINT32, 0, &SerialExtendedStatusResponse.status.rx_long_frames},
	{(UCHAR *)"RECEIVED_ABORTS", VT_UINT32, 0, &SerialExtendedStatusResponse.status.rx_aborts},
	{(UCHAR *)"RECEIVED_OVERRUNS", VT_UINT32, 0, &SerialExtendedStatusResponse.status.rx_overruns},
	{(UCHAR *)"RECEIVED_CRC_ERRORS", VT_UINT32, 0, &SerialExtendedStatusResponse.status.rx_crc_errors},
	{(UCHAR *)"RECEIVED_BUFFER_OVERFLOWS", VT_UINT32, 0, &SerialExtendedStatusResponse.status.rx_buffer_overflows},
	{(UCHAR *)"TRANSMITTED_UNDERRUNS", VT_UINT32, 0, &SerialExtendedStatusResponse.status.tx_underruns},
	{(UCHAR *)"INTERRUPTED_FRAMES", VT_UINT32, 0, &SerialExtendedStatusResponse.status.interrupted_frames},
	{(UCHAR *)"RECEIVED_BREAKS", VT_UINT32, 0, &SerialExtendedStatusResponse.status.breaks_received},
	{(UCHAR *)"PARITY_ERRORS", VT_UINT32, 0, &SerialExtendedStatusResponse.status.parity_errs},
	{(UCHAR *)"FRAMING_ERRORS", VT_UINT32, 0, &SerialExtendedStatusResponse.status.framing_errs},
	{(UCHAR *)"OVERRUN_ERRORS", VT_UINT32, 0, &SerialExtendedStatusResponse.status.overrun_errs},
	{(UCHAR *)"TRANSMITTED_ACCM", VT_UINT32, 0, &SerialExtendedStatusResponse.status.txaccm},
	{(UCHAR *)"RECEIVED_ACCM", VT_UINT32, 0, &SerialExtendedStatusResponse.status.rxaccm},
	{(UCHAR *)NULL, VT_UINT32, 0, NULL}};


ResponseControl CallStatus[] =
{
	{(UCHAR *)"MESSAGE", VT_TEXT, 0, "CALL_STATUS"},
	{(UCHAR *)"ADAPTER", VT_ADAPTER, 0, NULL},
	{(UCHAR *)"PORT", VT_PORT, 0, NULL},
	{(UCHAR *)"CHANNEL", VT_CHANNEL, 0, NULL},
	{(UCHAR *)"CALL_STATE", VT_UINT32, 0, &CallStatusResponse.status.call_state},
	{(UCHAR *)"CALL_TYPE", VT_UINT32, 0, &CallStatusResponse.status.call_type},
	{(UCHAR *)"INDEX", VT_UINT32, 0, &CallStatusResponse.status.index},
	{(UCHAR *)"TIME_SLOT", VT_UINT32, 0, &CallStatusResponse.status.timeslot},
	{(UCHAR *)NULL, VT_UINT32, 0, NULL}};

ResponseControl CallAllStatus[] =
{
	{(UCHAR *)"MESSAGE", VT_TEXT, 0, "CALL_ALL_STATUS"},
	{(UCHAR *)"ADAPTER", VT_ADAPTER, 0, NULL},
	{(UCHAR *)"PORT", VT_PORT, 0, NULL},
	{(UCHAR *)"STAT_COUNT", VT_UINT32, 0, &CallAllStatusResponse.count},
	/* more added by function */
	{(UCHAR *)NULL, VT_UINT32, 0, NULL}};


ResponseControl ModemConfiguration[] =
{
	{(UCHAR *)"MESSAGE", VT_TEXT, 0, "MODEM_CONFIGURATION"},
	{(UCHAR *)"ADAPTER", VT_ADAPTER, 0, NULL},
	{(UCHAR *)"CHANNEL", VT_CHANNEL, 0, NULL},
	{(UCHAR *)"ANSWER_RINGS", VT_UINT32, 0, &ModemConfigurationResponse.config.answer_rings},
	{(UCHAR *)"CALLER_ID_ENABLE", VT_UINT32, 0, &ModemConfigurationResponse.config.clid_enable},
	{(UCHAR *)"MAXIMUM_RATE", VT_UINT32, 0, &ModemConfigurationResponse.config.max_rate},
	{(UCHAR *)"MINIMUM_RATE", VT_UINT32, 0, &ModemConfigurationResponse.config.min_rate},
	{(UCHAR *)"HANGUP", VT_UINT32, 0, &ModemConfigurationResponse.config.hangup},
	{(UCHAR *)"RESET", VT_UINT32, 0, &ModemConfigurationResponse.config.reset},
	{(UCHAR *)NULL, VT_UINT32, 0, NULL}};

ResponseControl ModemStatus[] =
{
	{(UCHAR *)"MESSAGE", VT_TEXT, 0, "MODEM_STATUS"},
	{(UCHAR *)"ADAPTER", VT_ADAPTER, 0, NULL},
	{(UCHAR *)"CHANNEL", VT_CHANNEL, 0, NULL},
	{(UCHAR *)"MODE", VT_UINT32, 0, &ModemStatusResponse.status.mode},
	{(UCHAR *)"DTE_TRANSMIT_RATE", VT_UINT32, 0, &ModemStatusResponse.status.dte_tx_rate},
	{(UCHAR *)"DTE_RECEIVE_RATE", VT_UINT32, 0, &ModemStatusResponse.status.dte_rx_rate},
	{(UCHAR *)"PORT", VT_UINT32, 0, &ModemStatusResponse.status.port},
	{(UCHAR *)"INDEX", VT_UINT32, 0, &ModemStatusResponse.status.index},
	{(UCHAR *)"CONNECT_TIME", VT_UINT32, 0, &ModemStatusResponse.status.connect_time},
	{(UCHAR *)"INITIAL_TRANSMIT_RATE", VT_UINT32, 0, &ModemStatusResponse.status.initial_tx_rate},
	{(UCHAR *)"INITIAL_RECEIVE_RATE", VT_UINT32, 0, &ModemStatusResponse.status.initial_rx_rate},
	{(UCHAR *)"CURRENT_TRANSMIT_RATE", VT_UINT32, 0, &ModemStatusResponse.status.current_tx_rate},
	{(UCHAR *)"CURRENT_RECEIVE_RATE", VT_UINT32, 0, &ModemStatusResponse.status.current_rx_rate},
	{(UCHAR *)"MODULATION", VT_UINT32, 0, &ModemStatusResponse.status.modulation},
	{(UCHAR *)"COMPRESSION", VT_UINT32, 0, &ModemStatusResponse.status.compression},
	{(UCHAR *)"ERROR_CORRECTION", VT_UINT32, 0, &ModemStatusResponse.status.error_correction},
	{(UCHAR *)"PAGE_NUMBER", VT_UINT32, 0, &ModemStatusResponse.status.page_number},
	{(UCHAR *)"LAST_DISCONNECT", VT_UINT32, 0, &ModemStatusResponse.status.last_disconnect},
	{(UCHAR *)"CALLER_ID", VT_TEXT, CLID_MAX, &ModemStatusResponse.status.clid},
	{(UCHAR *)"LOCAL_NUMBER", VT_TEXT, DN_MAX, &ModemStatusResponse.status.local_dn},
	{(UCHAR *)"REMOTE_NUMBER", VT_TEXT, DN_MAX, &ModemStatusResponse.status.remote_dn},
	{(UCHAR *)NULL, VT_UINT32, 0, NULL}};

ResponseControl ModemExtendedConfiguration[] =
{
	{(UCHAR *)"MESSAGE", VT_TEXT, 0, "MODEM_EXTENDED_CONFIGURATION"},
	{(UCHAR *)"ADAPTER", VT_ADAPTER, 0, NULL},
	{(UCHAR *)"CHANNEL", VT_CHANNEL, 0, NULL},
	{(UCHAR *)"BUSY_OUT", VT_UINT32, 0, &ModemExtendedConfigurationResponse.config.busy_out},
	{(UCHAR *)"LEASED_LINE", VT_UINT32, 0, &ModemExtendedConfigurationResponse.config.leased_line},
	{(UCHAR *)"TRANSMITTED_AUDIO_LEVEL", VT_UINT32, 0, &ModemExtendedConfigurationResponse.config.audio_level_tx},
	{(UCHAR *)"RECEIVED_AUDIO_LEVEL", VT_UINT32, 0, &ModemExtendedConfigurationResponse.config.audio_level_rx},
	{(UCHAR *)NULL, VT_UINT32, 0, NULL}};

ResponseControl ModemExtendedStatus[] =
{
	{(UCHAR *)"MESSAGE", VT_TEXT, 0, "MODEM_EXTENDED_STATUS"},
	{(UCHAR *)"ADAPTER", VT_ADAPTER, 0, NULL},
	{(UCHAR *)"CHANNEL", VT_CHANNEL, 0, NULL},
	{(UCHAR *)"TX_SYMBOL_RATE", VT_UINT32, 0, &ModemExtendedStatusResponse.status.tx_symbol_rate		/* rate in symbols per second */ },
	{(UCHAR *)"RX_SYMBOL_RATE", VT_UINT32, 0, &ModemExtendedStatusResponse.status.rx_symbol_rate		/* rate in symbols per second */ },
	{(UCHAR *)"ESTIMATED_SNR", VT_UINT32, 0, &ModemExtendedStatusResponse.status.estimated_snr	/* singal/noise ratio in dB */ },
	{(UCHAR *)"ESTIMATED_RTT", VT_UINT32, 0, &ModemExtendedStatusResponse.status.estimated_rtt	/* round trip time in ms */ },
	{(UCHAR *)"TX_SIGNAL_LEVEL", VT_UINT32, 0, &ModemExtendedStatusResponse.status.tx_signal_level	/* signal level in dBm */ },
	{(UCHAR *)"RX_SIGNAL_LEVEL", VT_UINT32, 0, &ModemExtendedStatusResponse.status.rx_signal_level	/* signal level in dBm */ },
	{(UCHAR *)"LOCAL_RETRAINS", VT_UINT32, 0, &ModemExtendedStatusResponse.status.local_retrains		/* count of retrains */ },
	{(UCHAR *)"REMOTE_RETRAINS", VT_UINT32, 0, &ModemExtendedStatusResponse.status.remote_retrains	/* count of retrains */ },
	{(UCHAR *)"MANUAL_RETRAINS", VT_UINT32, 0, &ModemExtendedStatusResponse.status.manual_retrains	/* count of retrains from overrides */ },
	{(UCHAR *)"LOCAL_RENEGOTIATIONS", VT_UINT32, 0, &ModemExtendedStatusResponse.status.local_renegotiations		/* count of renegotiations */ },
	{(UCHAR *)"REMOTE_RENEGOTIATIONS", VT_UINT32, 0, &ModemExtendedStatusResponse.status.remote_renegotiations	/* count of renegotiations */ },
	{(UCHAR *)"TX_FRAMES", VT_UINT32, 0, &ModemExtendedStatusResponse.status.tx_frames	/* count of all (mnp/lapm/data) frames */ },
	{(UCHAR *)"RX_FRAMES", VT_UINT32, 0, &ModemExtendedStatusResponse.status.rx_frames	/* count of all (mnp/lapm/data) frames */ },
	{(UCHAR *)"RX_FRAME_ERRORS", VT_UINT32, 0, &ModemExtendedStatusResponse.status.rx_frame_errors	/* count of all rx frame errors */ },
	{(UCHAR *)"TX_DATA_FRAMES", VT_UINT32, 0, &ModemExtendedStatusResponse.status.tx_data_frames		/* count of data frames */ },
	{(UCHAR *)"TX_DATA_FRAME_RETRANSMITS", VT_UINT32, 0, &ModemExtendedStatusResponse.status.tx_data_frame_retransmits	/* count of data frames */ },
	{(UCHAR *)"RX_DATA_FRAMES", VT_UINT32, 0, &ModemExtendedStatusResponse.status.rx_data_frames		/* count of data frames */ },
	{(UCHAR *)"RX_DATA_FRAME_ERRORS", VT_UINT32, 0, &ModemExtendedStatusResponse.status.rx_data_frame_errors		/* count of data frame errors */ },
	{(UCHAR *)"TX_DATA_BYTES", VT_UINT32, 0, &ModemExtendedStatusResponse.status.tx_data_bytes	/* count of data bytes */ },
	{(UCHAR *)"RX_DATA_BYTES", VT_UINT32, 0, &ModemExtendedStatusResponse.status.rx_data_bytes	/* count of data bytes */ },
	{(UCHAR *)"TX_COMPRESSED_DATA_BYTES", VT_UINT32, 0, &ModemExtendedStatusResponse.status.tx_compressed_data_bytes	/* count after compression */ },
	{(UCHAR *)"RX_COMPRESSED_DATA_BYTES", VT_UINT32, 0, &ModemExtendedStatusResponse.status.rx_compressed_data_bytes	/* count after compression */ },
	{(UCHAR *)"LINE_QUALITY", VT_UINT32, 0, &ModemExtendedStatusResponse.status.line_quality	/* relative value (mean_square_error) */ },
	{(UCHAR *)"RBS_PATTERN", VT_UINT32, 0, &ModemExtendedStatusResponse.status.rbs_pattern		/* robbed bit signalling pattern */ },
	{(UCHAR *)"DATA_RATE_DROP", VT_UINT32, 0, &ModemExtendedStatusResponse.status.data_rate_dropped		/* loss in Kbs from rbs/dgtl pad */ },
	{(UCHAR *)"DIGITAL_PAD", VT_UINT32, 0, &ModemExtendedStatusResponse.status.digital_pad		/* digital pad in dB */ },
	{(UCHAR *)"DICTIONARY_SIZE", VT_UINT32, 0, &ModemExtendedStatusResponse.status.dictionary_size	/* size of compression dictionary */ },
	{(UCHAR *)"MAX_STRING_LENGTH", VT_UINT32, 0, &ModemExtendedStatusResponse.status.max_string_length		/* compression string length */ },
	{(UCHAR *)NULL, VT_UINT32, 0, NULL}};


ResponseControl DChannelExtendedConfiguration[] =
{
	{(UCHAR *)"MESSAGE", VT_TEXT, 0, "D_CHANNEL_EXTENDED_CONFIGURATION"},
	{(UCHAR *)"ADAPTER", VT_ADAPTER, 0, NULL},
	{(UCHAR *)"PORT", VT_PORT, 0, NULL},
	{(UCHAR *)"MODE", VT_UINT32, 0, &DChannelExtendedConfigurationResponse.config.mode},
	{(UCHAR *)"ADDRESS_TYPE", VT_UINT32, 0, &DChannelExtendedConfigurationResponse.config.address_type},
	{(UCHAR *)"NUMBERING_PLAN", VT_UINT32, 0, &DChannelExtendedConfigurationResponse.config.numbering_plan},
	{(UCHAR *)"SUB_ADDRESS_TYPE", VT_UINT32, 0, &DChannelExtendedConfigurationResponse.config.subaddress_type},
	{(UCHAR *)NULL, VT_UINT32, 0, NULL}};

ResponseControl DChannelExtendedStatus[] =
{
	{(UCHAR *)"MESSAGE", VT_TEXT, 0, "D_CHANNEL_EXTENDED_STATUS"},
	{(UCHAR *)"ADAPTER", VT_ADAPTER, 0, NULL},
	{(UCHAR *)"PORT", VT_PORT, 0, NULL},
	{(UCHAR *)"TEI_COUNT", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.tei_count},
	/* more added by function */
	{(UCHAR *)"LAPD_RR_RX_CMD", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.lapd.RR_rx_cmd},
	{(UCHAR *)"LAPD_RR_RX_RSP", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.lapd.RR_rx_rsp},
	{(UCHAR *)"LAPD_RR_TX_CMD", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.lapd.RR_tx_cmd},
	{(UCHAR *)"LAPD_RR_TX_RSP", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.lapd.RR_tx_rsp},
	{(UCHAR *)"LAPD_RR_TX_CMD_P", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.lapd.RR_tx_cmd_p},
	{(UCHAR *)"LAPD_RNR_RX_CMD", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.lapd.RNR_rx_cmd},
	{(UCHAR *)"LAPD_RNR_RX_RSP", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.lapd.RNR_rx_rsp},
	{(UCHAR *)"LAPD_RNR_TX_CMD", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.lapd.RNR_tx_cmd},
	{(UCHAR *)"LAPD_RNR_TX_RSP", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.lapd.RNR_tx_rsp},
	{(UCHAR *)"LAPD_RNR_TX_CMD_P", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.lapd.RNR_tx_cmd_p},
	{(UCHAR *)"LAPD_REJ_RX_CMD", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.lapd.REJ_rx_cmd},
	{(UCHAR *)"LAPD_REJ_RX_RSP", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.lapd.REJ_rx_rsp},
	{(UCHAR *)"LAPD_REJ_TX_CMD", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.lapd.REJ_tx_cmd},
	{(UCHAR *)"LAPD_REJ_TX_RSP", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.lapd.REJ_tx_rsp},
	{(UCHAR *)"LAPD_REJ_TX_CMD_P", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.lapd.REJ_tx_cmd_p},
	{(UCHAR *)"LAPD_I_TX_CMD", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.lapd.I_tx_cmd},
	{(UCHAR *)"LAPD_I_RX_CMD", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.lapd.I_rx_cmd},
	{(UCHAR *)"LAPD_SABME_RX_CMD", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.lapd.SABME_rx_cmd},
	{(UCHAR *)"LAPD_SABME_TX_CMD", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.lapd.SABME_tx_cmd},
	{(UCHAR *)"LAPD_DISC_RX_CMD", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.lapd.DISC_rx_cmd},
	{(UCHAR *)"LAPD_DISC_TX_CMD", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.lapd.DISC_tx_cmd},
	{(UCHAR *)"LAPD_UA_RX_RSP", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.lapd.UA_rx_rsp},
	{(UCHAR *)"LAPD_UA_TX_RSP", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.lapd.UA_tx_rsp},
	{(UCHAR *)"LAPD_DM_RX_RSP", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.lapd.DM_rx_rsp},
	{(UCHAR *)"LAPD_DM_TX_RSP", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.lapd.DM_tx_rsp},
	{(UCHAR *)"LAPD_UI_RX_CMD", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.lapd.UI_rx_cmd},
	{(UCHAR *)"LAPD_UI_TX_CMD", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.lapd.UI_tx_cmd},
	{(UCHAR *)"LAPD_FRMR_RX_RSP", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.lapd.FRMR_rx_rsp},
	{(UCHAR *)"LAPD_FRMR_TX_RSP", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.lapd.FRMR_tx_rsp},
	{(UCHAR *)"LAPD_XID_RX_CMD", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.lapd.XID_rx_cmd},
	{(UCHAR *)"LAPD_XID_RX_RSP", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.lapd.XID_rx_rsp},
	{(UCHAR *)"LAPD_XID_TX_CMD", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.lapd.XID_tx_cmd},
	{(UCHAR *)"LAPD_XID_TX_RSP", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.lapd.XID_tx_rsp},
	{(UCHAR *)"LAPD_RX_BADLEN", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.lapd.rx_badlen},
	{(UCHAR *)"LAPD_RX_UNKNOWN", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.lapd.rx_unknown},
	{(UCHAR *)"LAPD_RX_BAD", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.lapd.rx_bad},
	{(UCHAR *)"LAPD_RX_DUD", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.lapd.rx_dud},
	{(UCHAR *)"LAPD_RX_IGN", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.lapd.rx_ign},
	{(UCHAR *)"LAPD_TX_RTR", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.lapd.tx_rtr},
	{(UCHAR *)"LAPD_TX_IGN", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.lapd.tx_ign},
	{(UCHAR *)"LAPD_T200_EXP", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.lapd.T200_exp},
	{(UCHAR *)"LAPD_T200_N200_EXP", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.lapd.T200_N200_exp},
	{(UCHAR *)"LAPD_RX_MGMT_DUD", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.lapd.rx_mgmt_dud},
	{(UCHAR *)"LAPD_RX_MGMT_BADLEN", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.lapd.rx_mgmt_badlen},
	{(UCHAR *)"LAPD_RX_MGMT_IGN", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.lapd.rx_mgmt_ign},
	{(UCHAR *)"LAPD_RX_MGMT_UNKNOWN", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.lapd.rx_mgmt_unknown},
	{(UCHAR *)"LAPD_RX_TEI_ASSIGNED", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.lapd.rx_tei_assigned},
	{(UCHAR *)"LAPD_RX_TEI_DENIED", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.lapd.rx_tei_denied},
	{(UCHAR *)"LAPD_RX_TEI_CHECK", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.lapd.rx_tei_check},
	{(UCHAR *)"LAPD_RX_TEI_REMOVE", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.lapd.rx_tei_remove},
	{(UCHAR *)"HDLC_TX_BYTES", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.hdlc.tx_bytes},
	{(UCHAR *)"HDLC_RX_BYTES", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.hdlc.rx_bytes},
	{(UCHAR *)"HDLC_TX_FRAMES", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.hdlc.tx_frames},
	{(UCHAR *)"HDLC_RX_FRAMES", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.hdlc.rx_frames},
	{(UCHAR *)"HDLC_RX_BAD_FRAMES", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.hdlc.rx_bad_frames},
	{(UCHAR *)"HDLC_RX_SHORT_FRAMES", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.hdlc.rx_short_frames},
	{(UCHAR *)"HDLC_RX_LONG_FRAMES", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.hdlc.rx_long_frames},
	{(UCHAR *)"HDLC_RX_ABORTS", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.hdlc.rx_aborts},
	{(UCHAR *)"HDLC_RX_OVERRUNS", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.hdlc.rx_overruns},
	{(UCHAR *)"HDLC_RX_CRC_ERROR", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.hdlc.rx_crc_errors},
	{(UCHAR *)"HDLC_RX_BUFFER_OVERFLOWS", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.hdlc.rx_buffer_overflows},
	{(UCHAR *)"HDLC_TX_UNDERRUNS", VT_UINT32, 0, &DChannelExtendedStatusResponse.status.hdlc.tx_underruns},
	{(UCHAR *)NULL, VT_UINT32, 0, NULL}};


ResponseControl BChannelStatus[] =
{
	{(UCHAR *)"MESSAGE", VT_TEXT, 0, "B_CHANNEL_STATUS"},
	{(UCHAR *)"ADAPTER", VT_ADAPTER, 0, NULL},
	{(UCHAR *)"CHANNEL", VT_CHANNEL, 0, NULL},
	{(UCHAR *)"MODE", VT_UINT32, 0, &BChannelStatusResponse.status.mode},
	{(UCHAR *)"DTE_TRANSMIT_RATE", VT_UINT32, 0, &BChannelStatusResponse.status.dte_tx_rate},
	{(UCHAR *)"DTE_RECEIVE_RATE", VT_UINT32, 0, &BChannelStatusResponse.status.dte_rx_rate},
	{(UCHAR *)"PORT", VT_UINT32, 0, &BChannelStatusResponse.status.port},
	{(UCHAR *)"INDEX", VT_UINT32, 0, &BChannelStatusResponse.status.index},
	{(UCHAR *)"CONNECT_TIME", VT_UINT32, 0, &BChannelStatusResponse.status.connect_time},
	{(UCHAR *)"CHANNEL_RATE", VT_UINT32, 0, &BChannelStatusResponse.status.channel_rate},
	{(UCHAR *)"COMPRESSION", VT_UINT32, 0, &BChannelStatusResponse.status.compression},
	{(UCHAR *)"LAST_DISCONNECT", VT_UINT32, 0, &BChannelStatusResponse.status.last_disconnect},
	{(UCHAR *)"LOCAL_NUMBER", VT_TEXT, DN_MAX, &BChannelStatusResponse.status.local_dn},
	{(UCHAR *)"REMOTE_NUMBER", VT_TEXT, DN_MAX, &BChannelStatusResponse.status.remote_dn},
	{(UCHAR *)NULL, VT_UINT32, 0, NULL}};

ResponseControl BChannelExtendedConfiguration[] =
{
	{(UCHAR *)"MESSAGE", VT_TEXT, 0, "B_CHANNEL_EXTENDED_CONFIGURATION"},
	{(UCHAR *)"ADAPTER", VT_ADAPTER, 0, NULL},
	{(UCHAR *)"CHANNEL", VT_CHANNEL, 0, NULL},
	{(UCHAR *)"HANG_UP", VT_UINT32, 0, &BChannelExtendedConfigurationResponse.config.hangup},
	{(UCHAR *)"CAUSE_CODE", VT_UINT32, 0, &BChannelExtendedConfigurationResponse.config.cause_code},
	{(UCHAR *)NULL, VT_UINT32, 0, NULL}};

ResponseControl BChannelExtendedStatus[] =
{
	{(UCHAR *)"MESSAGE", VT_TEXT, 0, "B_CHANNEL_EXTENDED_STATUS"},
	{(UCHAR *)"ADAPTER", VT_ADAPTER, 0, NULL},
	{(UCHAR *)"CHANNEL", VT_CHANNEL, 0, NULL},
	{(UCHAR *)"TRANSMITTED_BYTES", VT_UINT32, 0, &BChannelExtendedStatusResponse.status.hdlc.tx_bytes},
	{(UCHAR *)"RECEIVED_BYTES", VT_UINT32, 0, &BChannelExtendedStatusResponse.status.hdlc.rx_bytes},
	{(UCHAR *)"TRANSMITTED_FRAMES", VT_UINT32, 0, &BChannelExtendedStatusResponse.status.hdlc.tx_frames},
	{(UCHAR *)"RECEIVED_FRAMES", VT_UINT32, 0, &BChannelExtendedStatusResponse.status.hdlc.rx_frames},
	{(UCHAR *)"RECEIVED_BAD_FRAMES", VT_UINT32, 0, &BChannelExtendedStatusResponse.status.hdlc.rx_bad_frames},
	{(UCHAR *)"RECEIVED_SHORT_FRAMES", VT_UINT32, 0, &BChannelExtendedStatusResponse.status.hdlc.rx_short_frames},
	{(UCHAR *)"RECEIVED_LONG_FRAMES", VT_UINT32, 0, &BChannelExtendedStatusResponse.status.hdlc.rx_long_frames},
	{(UCHAR *)"RECEIVED_ABORTS", VT_UINT32, 0, &BChannelExtendedStatusResponse.status.hdlc.rx_aborts},
	{(UCHAR *)"RECEIVED_OVERRUNS", VT_UINT32, 0, &BChannelExtendedStatusResponse.status.hdlc.rx_overruns},
	{(UCHAR *)"RECEIVED_CRC_ERRORS", VT_UINT32, 0, &BChannelExtendedStatusResponse.status.hdlc.rx_crc_errors},
	{(UCHAR *)"RECEIVED_BUFFER_OVERFLOWS", VT_UINT32, 0, &BChannelExtendedStatusResponse.status.hdlc.rx_buffer_overflows},
	{(UCHAR *)"TRANSMITTED_UNDERRUNS", VT_UINT32, 0, &BChannelExtendedStatusResponse.status.hdlc.tx_underruns},
	{(UCHAR *)NULL, VT_UINT32, 0, NULL}};

ResponseControl SystemStatus[] =
{
	{(UCHAR *)"MESSAGE", VT_TEXT, 0, "SYSTEM_STATUS"},
	{(UCHAR *)"STATUS", VT_TEXT, 0, "OK"},
	{(UCHAR *)"HOST_OS", VT_TEXT, 0, "FOO"},
	{(UCHAR *)"CONFIGURED_ADAPTER_COUNT", VT_UINT32, 0, &ManagementBoardCountResponse.NumberOfBoards},
	{(UCHAR *)NULL, VT_UINT32, 0, NULL}};

ResponseControl AllChannelInfos[] =
{
	{(UCHAR *)"MESSAGE", VT_TEXT, 0, "ALL_CHANNEL_INFOS"},
	{(UCHAR *)"ADAPTER_NUMBER", VT_ADAPTER, 0, NULL},
	{(UCHAR *)"TYPE", VT_UINT32, 0, &AdapterInfoResponse.info.board_type},
	{(UCHAR *)"PORT_COUNT", VT_UINT32, 0, &AdapterInfoResponse.info.port_count},
	{(UCHAR *)"CHANNELS_PER_PORT", VT_UINT32, 0, &AdapterInfoResponse.info.channels_per_port},
	/* more added by function */
	{(UCHAR *)NULL, VT_UINT32, 0, NULL}};

ResponseControl AllSerialSummaries[] =
{
	{(UCHAR *)"MESSAGE", VT_TEXT, 0, "ALL_SERIAL_SUMMARIES"},
	{(UCHAR *)"ADAPTER_NUMBER", VT_ADAPTER, 0, NULL},
	{(UCHAR *)"TYPE", VT_UINT32, 0, &AdapterInfoResponse.info.board_type},
	/* more added by function */
	{(UCHAR *)NULL, VT_UINT32, 0, NULL}};

ResponseControl AllSerialDetails[] =
{
	{(UCHAR *)"MESSAGE", VT_TEXT, 0, "ALL_SERIAL_DETAILS"},
	{(UCHAR *)"ADAPTER_NUMBER", VT_ADAPTER, 0, NULL},
	{(UCHAR *)"TYPE", VT_UINT32, 0, &AdapterInfoResponse.info.board_type},
	/* more added by function */
	{(UCHAR *)NULL, VT_UINT32, 0, NULL}};

ResponseControl SerialTestChannelMode[] =
{
	{(UCHAR *)"MESSAGE", VT_TEXT, 0, "SERIAL_CHANNEL_TEST_MODE"},
	{(UCHAR *)"ADAPTER", VT_ADAPTER, 0, NULL},
	{(UCHAR *)"CHANNEL", VT_CHANNEL, 0, NULL},
	{(UCHAR *)"MODE", VT_UINT32, 0, &SerialTestChannelModeResponse.mode.mode},
	{(UCHAR *)"FAIL", VT_UINT32, 0, &SerialTestChannelModeResponse.mode.fail},
	{(UCHAR *)"GOOD", VT_UINT32, 0, &SerialTestChannelModeResponse.mode.good},
	{(UCHAR *)NULL, VT_UINT32, 0, NULL}};


/*-----------------------------------------------------------------------------------------------*/


static UCHAR *InsertElementBreak(UCHAR * Buffer)
{
	Buffer += strlen((char *)Buffer);
	strcpy((char *)Buffer, " ");
	return (Buffer + strlen((char *)Buffer));
}


static UCHAR * FindClosingBracket(UCHAR * Buffer)
{
	UCHAR * pb = Buffer + strlen((char *)Buffer);
	while ((pb != Buffer) && (*pb != ']'))
		pb--;
	return pb;
}


static UCHAR * ReplaceClosingBracketWithElementBreak(UCHAR * Buffer)
{
	UCHAR * pb = FindClosingBracket(Buffer);
	*pb = '\0';
	pb = InsertElementBreak(pb);
	return pb;
}


static UCHAR *AppendString(UCHAR * Buffer, UCHAR * String)
{
	Buffer += strlen((char *)Buffer);
	strcpy((char *)Buffer, (char *)String);
	return (Buffer + strlen((char *)Buffer));
}


static UCHAR *AppendStringQuoted(UCHAR * Buffer, UCHAR * String)
{
	Buffer = AppendString(Buffer, (UCHAR *)"\"");
	Buffer = AppendString(Buffer, (UCHAR *)String);
	return (AppendString(Buffer, (UCHAR *)"\""));
}


static UCHAR *AppendStringPair(UCHAR * Buffer, UCHAR * Name, UCHAR * Value)
{
	Buffer = AppendString(Buffer, (UCHAR *)Name);
	Buffer = AppendString(Buffer, (UCHAR *)"=");
	Buffer = AppendStringQuoted(Buffer, (UCHAR *)Value);
	return (InsertElementBreak(Buffer));
}


static UCHAR *AppendUINT32(UCHAR * Buffer, uint32 Value)
{
	UCHAR string[32];

	sprintf((char *)string, "%lu", Value);
	return (AppendString(Buffer, string));
}


static UCHAR *AppendUINT32Quoted(UCHAR * Buffer, uint32 Value)
{
	UCHAR string[32];

	sprintf((char *)string, "%lu", Value);
	return (AppendStringQuoted(Buffer, string));
}


static UCHAR *AppendStringPairUINT32(UCHAR * Buffer, UCHAR * Name, uint32 Value)
{
	UCHAR string[32];

	sprintf((char *)string, "%lu", Value);
	return (AppendStringPair(Buffer, Name, string));
}


static BOOL parse_uint32(uchar * source, uchar * param, uint32 * result)
{
	if ((source = (uchar *)strstr((char *)source, (char *)param)) != NULL)
	{
		source += strlen((char *)param);
		*result = atol((char *)source);
		return TRUE;
	}

	return FALSE;
}


static BOOL parse_uint8(uchar * source, uchar * param, uint8 * result)
{
	uint32 u32 = 0;
	if (parse_uint32(source, param, &u32))
	{
		*result = (uint8)u32;
		return TRUE;
	}

	return FALSE;
}


void BuildResponseElement(UCHAR * ResultBuffer, ResponseControl * Control, uint32 Adapter, uint32 Port, uint32 Channel)
{
	UCHAR *bp;
	int length;

	switch (Control->ValueType)
	{
		case VT_UINT32:
			sprintf((char *)ResultBuffer, "%s=\"%lu\"", Control->Name, *((uint32 *) Control->Value));
			break;
		case VT_UINT16:
			sprintf((char *)ResultBuffer, "%s=\"%u\"", Control->Name, *((uint16 *) Control->Value));
			break;
		case VT_UINT8:
			sprintf((char *)ResultBuffer, "%s=\"%u\"", Control->Name, *((UCHAR *) Control->Value));
			break;
		case VT_ADAPTER:
			sprintf((char *)ResultBuffer, "%s=\"%lu\"", Control->Name, Adapter);
			break;
		case VT_PORT:
			sprintf((char *)ResultBuffer, "%s=\"%lu\"", Control->Name, Port);
			break;
		case VT_CHANNEL:
			sprintf((char *)ResultBuffer, "%s=\"%lu\"", Control->Name, Channel);
			break;
		case VT_TEXT:
			if ((length = Control->ValueLength) == 0)
				sprintf((char *)ResultBuffer, "%s=\"%s\"", Control->Name, ((UCHAR *) Control->Value));
			else
			{
				sprintf((char *)ResultBuffer, "%s=\"", Control->Name);
				ResultBuffer += strlen((char *)ResultBuffer);

				bp = (UCHAR *) Control->Value;
				while (length-- && *bp)
					*(ResultBuffer++) = *(bp++);
				sprintf((char *)ResultBuffer, "\"");
			}
			break;
		default:
			sprintf((char *)ResultBuffer, "%s=\"Undefined type\"", Control->Name);
			break;
	}
}


BOOL BuildResponseString(UCHAR * ResultBuffer, ResponseControl * Control, uint32 Adapter, uint32 Port, uint32 Channel, BOOL QueryResult)
{
	UCHAR *rbuf = ResultBuffer;

	strcpy((char *)rbuf, "[");
	rbuf += strlen((char *)rbuf);

	if (!QueryResult)
	{
		uint32 error = GetMgmtLastError();
		UCHAR *bp = NULL;

		BuildResponseElement(rbuf, Control, Adapter, Port, Channel);

		rbuf += strlen((char *)rbuf);
		sprintf((char *)rbuf, " ADAPTER=\"%lu\" PORT=\"%lu\" CHANNEL=\"%lu\" ERROR=\"%lu\" ERROR_STRING=\"", Adapter, Port, Channel, error);

		switch (error)
		{
			case MGMT_OK:
				bp = (UCHAR *)"OK\"";
				break;

			case MGMT_SHIM_ERROR_BAD_COMMAND:
				bp = (UCHAR *)"BAD COMMAND\"";
				break;

			case MGMT_SHIM_ERROR_BAD_DFC:							bp = (UCHAR *)"BAD DFC\"";							break;
			case MGMT_SHIM_ERROR_BAD_PARAMETER:					bp = (UCHAR *)"BAD PARAMETER\"";					break;
			case MGMT_SHIM_ERROR_BAD_DEVICE:						bp = (UCHAR *)"BAD DEVICE\"";						break;
			case MGMT_SHIM_ERROR_OUT_OF_MEMORY:					bp = (UCHAR *)"OUT OF MEMORY\"";					break;
			case MGMT_SHIM_ERROR_UNKNOWN:							bp = (UCHAR *)"UNKNOWN\"";							break;
			case MGMT_SHIM_ERROR_BAD_PACKET_SIZE:				bp = (UCHAR *)"BAD PACKET SIZE\"";				break;
			case MGMT_SHIM_ERROR_NO_BOARDS:						bp = (UCHAR *)"NO BOARDS\"";						break;
			case MGMT_SHIM_ERROR_NOT_INITIALIZED:				bp = (UCHAR *)"NOT INITIALIZED\"";				break;
			case MGMT_SHIM_ERROR_OPERATION_TIMEOUT:			bp = (UCHAR *)"OPERATION TIMEOUT\"";			break;
			case MGMT_SHIM_ERROR_INTERNAL:						bp = (UCHAR *)"INTERNAL ERROR\"";				break;
			case MGMT_SHIM_ERROR_SERIALIZE_FAIL:				bp = (UCHAR *)"SERIALIZE FAIL\"";				break;
			case MGMT_SHIM_ERROR_BOARD_NON_FUNCTIONAL:		bp = (UCHAR *)"BOARD NON FUNCTIONAL\"";		break;
			case MGMT_SHIM_ERROR_NO_MGMT_CHAN:					bp = (UCHAR *)"NO MANAGEMENT CHANNEL\"";		break;
			case MGMT_SHIM_ERROR_REPLY_ORUN:						bp = (UCHAR *)"REPLY OVERRUN\"";					break;
			case MGMT_SHIM_ERROR_NO_SUCH_BOARD:					bp = (UCHAR *)"NO SUCH BOARD\"";					break;
			case MGMT_SHIM_ERROR_NO_SUCH_TRACE:					bp = (UCHAR *)"NO SUCH TRACE\"";					break;
			case MGMT_SHIM_ERROR_DUPLICATE_TRACE_HANDLE:		bp = (UCHAR *)"DUPLICATE TRACE HANDLE\"";		break;
			case MGMT_SHIM_ERROR_CANNOT_OPEN_TRACE_CHAN:		bp = (UCHAR *)"CANNOT OPEN TRACE CHANNEL\"";	break;

			case MGMT_PAM_ERROR_UNABLETOLOADSHIM:				bp = (UCHAR *)"UNABLE TO LOAD SHIM\"";			break;
			case MGMT_PAM_ERROR_INVALIDSHIMVERSION:			bp = (UCHAR *)"INVALID SHIM VERSION\"";		break;

			default:														bp = (UCHAR *)"UNKNOWN ERROR CODE\"";			break;
		}
		strcat((char *)rbuf, (char *)bp);
	}
	else
	{
		while (Control->Name != NULL)
		{
			BuildResponseElement(rbuf, Control, Adapter, Port, Channel);

			Control++;

			if (Control->Name != NULL)
				InsertElementBreak(rbuf + strlen((char *)rbuf));

			rbuf += strlen((char *)rbuf);
		}
	}

	strcat((char *)rbuf, "]");

	return QueryResult;
}


/*****************************************************************************************/
/*****************************************************************************************/


#if defined PLATFORM_WINDOWS

static void GetOSNameAndVersion(UCHAR * name, UCHAR * version)
{
	OSVERSIONINFO osvi =	{ sizeof(OSVERSIONINFO), 0 };
	GetVersionEx(&osvi);

	switch (osvi.dwPlatformId)
	{
		// case VER_PLATFORM_WIN32_WINDOWS:		strcpy(name, (dwMinorVersion == 0) ? "Microsoft Windows 95" : "Microsoft Windows 98");		break;
		case VER_PLATFORM_WIN32_NT:			strcpy(name, "Microsoft Windows NT");																		break;
		default:										strcpy(name, "");																									break;
	}

	sprintf(version, "%d.%02d Build %d", osvi.dwMajorVersion, osvi.dwMinorVersion, osvi.dwBuildNumber);
	if (osvi.szCSDVersion[0] != '\0')
	{
		strcat(version, " ("); strcat(version, osvi.szCSDVersion); strcat(version, ")");
	}
}

#elif defined PLATFORM_NETWARE

static void GetOSNameAndVersion(UCHAR * name, UCHAR * version)
{
	GetOSVersionInfoStructure osvi = {0};

	strcpy(name, "Novell Netware");

	SSGetOSVersionInfo((BYTE *) &osvi, sizeof (osvi));
	sprintf(version, "%d.%02d%c", osvi.OSMajorVersion, osvi.OSMinorVersion, ('a' + osvi.OSRevision));
}

#else

#include <unistd.h>
#include <sys/utsname.h>

static void GetOSNameAndVersion(UCHAR * name, UCHAR * version)
{
	struct utsname utsn = {0};
	uname(&utsn);
#if defined(LINUX)
	strcpy((char *)name, utsn.sysname);
	sprintf((char *)version, "%s %s", utsn.release, utsn.version);
#elif defined(SOLARIS)
	/* Try to niceify the stuff we get back from uname(). */
	if (strcmp(utsn.sysname, "SunOS")==0 &&
		(strcmp(utsn.release, "5.5")==0 ||
		 strcmp(utsn.release, "5.5.1")==0 ||
		 strcmp(utsn.release, "5.6")==0 ||
		 strcmp(utsn.release, "5.7")==0 ||
		 strcmp(utsn.release, "5.8")==0 ||
		 strcmp(utsn.release, "5.9")==0)) {
	  strcpy(utsn.sysname, "Solaris");
	  if (strcmp(utsn.release, "5.5")==0) strcpy(utsn.release, "2.5");
	  if (strcmp(utsn.release, "5.5.1")==0) strcpy(utsn.release, "2.5.1");
	  if (strcmp(utsn.release, "5.6")==0) strcpy(utsn.release, "2.6");
	  if (strcmp(utsn.release, "5.7")==0) strcpy(utsn.release, "7");
	  if (strcmp(utsn.release, "5.8")==0) strcpy(utsn.release, "8");
	  if (strcmp(utsn.release, "5.9")==0) strcpy(utsn.release, "9");
	}

	strcpy((char *)name, utsn.sysname);
	sprintf((char *)version, "%s %s",
			utsn.release, /* e.g., "5.8" */
			utsn.version  /* e.g., "Beta_Refresh" */);
#elif defined(PLATFORM_AIX)
	strcpy((char *)name, utsn.sysname);
	sprintf((char *)version, "%s.%s",
	                utsn.version, /* e.g., "4" */
	                utsn.release  /* e.g., "2" */);
#elif defined(PLATFORM_HPUX)
	strcpy((char *)name, utsn.sysname);
	strcpy((char *)version, utsn.release);
#else
	strcpy((char *)name, utsn.sysname);
	strcpy((char *)version, utsn.version);
#endif
}

#endif

static void InsertOSInformationString(UCHAR * cp)
{
	UCHAR name[257];
	UCHAR version[257];

	GetOSNameAndVersion(name, version);

	cp = ReplaceClosingBracketWithElementBreak(cp);
	cp = AppendStringPair(cp, (UCHAR *)"HOST_OS", name);
	cp = AppendStringPair(cp, (UCHAR *)"OS_VERSION", version);
	AppendString(cp, (UCHAR *)"]");
}

BOOL UpdateAgentInfo(UCHAR * pResponseBuffer)
{
	BuildResponseString(pResponseBuffer, &AgentInformation[0], 0, 0, 0, TRUE);
	InsertOSInformationString(pResponseBuffer);
	return TRUE;
}


BOOL UpdateManagementShimVersion(UCHAR * pResponseBuffer, uint32 AdapterNumber)
{
	BuildResponseString(pResponseBuffer, &ManagementShimVersion[0], AdapterNumber, 0, 0,
		GetMgmtShimVersion(&ManagementShimVersionResponse));
	return TRUE;
}


BOOL UpdateManagementBoardCount(UCHAR * pResponseBuffer, uint32 AdapterNumber)
{
	BuildResponseString(pResponseBuffer, &ManagementBoardCount[0], AdapterNumber, 0, 0,
		GetMgmtBoardCount(&ManagementBoardCountResponse));
	return TRUE;
}


BOOL UpdateManagementBoardInfo(UCHAR * pResponseBuffer, uint32 AdapterNumber)
{
	BuildResponseString(pResponseBuffer, &ManagementBoardInfo[0], AdapterNumber, 0, 0,
		GetMgmtBoardInfo(AdapterNumber, &ManagementBoardInfoResponse));
	return TRUE;
}


static void InsertManagementDriverVersionString(UCHAR * cp, uint32 index, mgmt_drv_vers_t * versions)
{
	UCHAR *bp;
	uint32 length;

	cp = ReplaceClosingBracketWithElementBreak(cp);

	cp += sprintf((char *)cp, "DRIVER_%lu=\"%lu\",\"", index, versions->drivers[index].type);

	length = VN_MAX;
	bp = (UCHAR *) versions->drivers[index].name;
	while (length-- && *bp)
		*(cp++) = *(bp++);
	*(cp++) = '\"';
	*(cp++) = ',';

	*(cp++) = '\"';
	length = VN_MAX;
	bp = (UCHAR *) versions->drivers[index].version;
	while (length-- && *bp)
		*(cp++) = *(bp++);
	*(cp++) = '\"';

	*(cp++) = ']';
	*cp = '\0';
}

BOOL UpdateManagementDriverVersions(UCHAR * pResponseBuffer, uint32 AdapterNumber)
{
	if (BuildResponseString(pResponseBuffer, &ManagementDriverVersions[0], AdapterNumber, 0, 0,
			GetMgmtDriverVersions(AdapterNumber, &ManagementDriverVersionsResponse)))
	{
		uint32 i;
		for (i = 0; i < ManagementDriverVersionsResponse.versions.driverCount; i++)
			InsertManagementDriverVersionString(pResponseBuffer, i, &ManagementDriverVersionsResponse.versions);
	}
	return TRUE;
}


//-------------------------------------------------------------


BOOL UpdateAdapterInfo(UCHAR * pResponseBuffer, uint32 AdapterNumber)
{
	BuildResponseString(pResponseBuffer, &AdapterInfo[0], AdapterNumber, 0, 0,
		GetAdapterInfo(AdapterNumber, &AdapterInfoResponse));
	return TRUE;
}


BOOL UpdateAdapterState(UCHAR * pResponseBuffer, uint32 AdapterNumber)
{
	BuildResponseString(pResponseBuffer, &AdapterState[0], AdapterNumber, 0, 0,
		GetAdapterState(AdapterNumber, &AdapterStateResponse));
	return TRUE;
}


BOOL UpdateModemNationality(UCHAR * pResponseBuffer, uint32 AdapterNumber)
{
	BuildResponseString(pResponseBuffer, &ModemNationality[0], AdapterNumber, 0, 0,
		GetModemNationality(AdapterNumber, &ModemNationalityResponse));
	return TRUE;
}


BOOL UpdateManagementProtocolVersion(UCHAR * pResponseBuffer, uint32 AdapterNumber)
{
	BuildResponseString(pResponseBuffer, &ManagementProtocolVersion[0], AdapterNumber, 0, 0,
		GetManagementProtocolVersion(AdapterNumber, &ManagementProtocolVersionResponse));
	return TRUE;
}


//-------------------------------------------------------------


BOOL UpdateDS1Configuration(UCHAR * pResponseBuffer, uint32 AdapterNumber, uint32 Port)
{
	BuildResponseString(pResponseBuffer, &DS1Configuration[0], AdapterNumber, Port, 0,
		GetDS1Configuration(AdapterNumber, Port, &DS1ConfigurationResponse));
	return TRUE;
}


BOOL UpdateDS1ExtendedConfiguration(UCHAR * pResponseBuffer, uint32 AdapterNumber, uint32 Port)
{
	BuildResponseString(pResponseBuffer, &DS1ExtendedConfiguration[0], AdapterNumber, Port, 0,
		GetDS1ExtendedConfiguration(AdapterNumber, Port, &DS1ExtendedConfigurationResponse));
	return TRUE;
}


BOOL UpdateDS1Status(UCHAR * pResponseBuffer, uint32 AdapterNumber, uint32 Port)
{
	BuildResponseString(pResponseBuffer, &DS1Status[0], AdapterNumber, Port, 0,
		GetDS1Status(AdapterNumber, Port, &DS1StatusResponse));
	return TRUE;
}


BOOL UpdateDS1ExtendedStatus(UCHAR * pResponseBuffer, uint32 AdapterNumber, uint32 Port)
{
	BuildResponseString(pResponseBuffer, &DS1ExtendedStatus[0], AdapterNumber, Port, 0,
		GetDS1ExtendedStatus(AdapterNumber, Port, &DS1ExtendedStatusResponse));
	return TRUE;
}


BOOL UpdateDS1CT1SignalStatus(UCHAR * pResponseBuffer, uint32 AdapterNumber, uint32 Port, uint32 Channel)
{
	BuildResponseString(pResponseBuffer, &DS1CT1SignalStatus[0], AdapterNumber, Port, Channel,
		GetDS1CT1SignalStatus(AdapterNumber, Port, Channel, &DS1CT1SignalStatusResponse));
	return TRUE;
}


static void InsertDS1AllCT1SignalStatusString(UCHAR * cp, uint32 index, ds1_ct1_sig_status_t * status)
{
	cp = ReplaceClosingBracketWithElementBreak(cp);
	cp += sprintf((char *)cp, "CT1_%lu=\"%lu\"", index, status->tx_signal_bits);
	cp += sprintf((char *)cp, ",\"%lu\"", index, status->rx_signal_bits);
	cp += sprintf((char *)cp, ",\"%lu\"", index, status->state);
	sprintf((char *)cp, ",\"%lu\"]", index, status->pad);
}

BOOL UpdateDS1AllCT1SignalStatus(UCHAR * pResponseBuffer, uint32 AdapterNumber, uint32 Port)
{
	if (BuildResponseString(pResponseBuffer, &DS1AllCT1SignalStatus[0], AdapterNumber, Port, 0,
			GetDS1AllCT1SignalStatus(AdapterNumber, Port, &DS1AllCT1SignalStatusResponse)))
	{
		uint32 i;
		for (i = 0; i < CT1Count; i++)
			InsertDS1AllCT1SignalStatusString(pResponseBuffer, i, &DS1AllCT1SignalStatusResponse.signals.signal[i]);
	}
	return TRUE;
}


//-------------------------------------------------------------


BOOL UpdateBRIConfiguration(UCHAR * pResponseBuffer, uint32 AdapterNumber, uint32 Port)
{
	if (BuildResponseString(pResponseBuffer, &BRIConfiguration[0], AdapterNumber, Port, 0,
			GetBRIConfiguration(AdapterNumber, Port, &BRIConfigurationResponse)))
	{
		uint32 i;

		pResponseBuffer = ReplaceClosingBracketWithElementBreak(pResponseBuffer);

		for (i = 0; i < BRICount; i++)
		{
			pResponseBuffer += sprintf((char *)pResponseBuffer, " DIR_%lu=\"%s\",\"%s\",\"%s\"", i,
				BRIConfigurationResponse.config.directory[i].number,
				BRIConfigurationResponse.config.directory[i].sub_address,
				BRIConfigurationResponse.config.directory[i].spid);
		}

		AppendString(pResponseBuffer, (UCHAR *)"]");
	}
	return TRUE;
}

BOOL UpdateBRIStatus(UCHAR * pResponseBuffer, uint32 AdapterNumber, uint32 Port)
{
	if (BuildResponseString(pResponseBuffer, &BRIStatus[0], AdapterNumber, Port, 0,
			GetBRIStatus(AdapterNumber, Port, &BRIStatusResponse)))
	{
		uint32 i;

		pResponseBuffer = ReplaceClosingBracketWithElementBreak(pResponseBuffer);

		for (i = 0; i < BRIStatusResponse.status.spid_count; i++)
			pResponseBuffer += sprintf((char *)pResponseBuffer, " SPID_STATE_%lu=\"%lu\"", i, BRIStatusResponse.status.spid_state[i]);

		AppendString(pResponseBuffer, (UCHAR *)"]");
	}
	return TRUE;
}


//-------------------------------------------------------------


BOOL UpdateSerialConfiguration(UCHAR * pResponseBuffer, uint32 AdapterNumber, uint32 Channel)
{
	BuildResponseString(pResponseBuffer, &SerialConfiguration[0], AdapterNumber, 0, Channel,
		GetSerialConfiguration(AdapterNumber, Channel, &SerialConfigurationResponse));
	return TRUE;
}

static void InsertSerialFlowString(UCHAR * cp, uint8 * flow, UCHAR * name)
{
	cp = ReplaceClosingBracketWithElementBreak(cp);
	sprintf((char *)cp, "%s=\"%u\",\"%u\",\"%u\"]", name, flow[0], flow[1], flow[2]);
}
static void InsertSerialModemString(UCHAR * cp, uint8 * modem)
{
	cp = ReplaceClosingBracketWithElementBreak(cp);

	cp += sprintf((char *)cp, "MODEM_RTS=\"%u\",", modem[0]);
	cp = InsertElementBreak(cp);
	cp += sprintf((char *)cp, "MODEM_CTS=\"%u\",", modem[1]);
	cp = InsertElementBreak(cp);
	cp += sprintf((char *)cp, "MODEM_DTR=\"%u\",", modem[2]);
	cp = InsertElementBreak(cp);
	cp += sprintf((char *)cp, "MODEM_DSR=\"%u\",", modem[3]);
	cp = InsertElementBreak(cp);
	cp += sprintf((char *)cp, "MODEM_RI=\"%u\",", modem[4]);
	cp = InsertElementBreak(cp);
	sprintf((char *)cp, "MODEM_DCD=\"%u\"]", modem[5]);
}

BOOL UpdateSerialStatus(UCHAR * pResponseBuffer, uint32 AdapterNumber, uint32 Channel)
{
	if (BuildResponseString(pResponseBuffer, &SerialStatus[0], AdapterNumber, 0, Channel,
			GetSerialStatus(AdapterNumber, Channel, &SerialStatusResponse)))
	{
		InsertSerialFlowString(pResponseBuffer, &SerialStatusResponse.status.in_flow_type[0], (UCHAR *)"IN_FLOW_TYPE");
		InsertSerialFlowString(pResponseBuffer, &SerialStatusResponse.status.out_flow_type[0], (UCHAR *)"OUT_FLOW_TYPE");
		InsertSerialFlowString(pResponseBuffer, &SerialStatusResponse.status.in_flow_state[0], (UCHAR *)"IN_FLOW_STATE");
		InsertSerialFlowString(pResponseBuffer, &SerialStatusResponse.status.out_flow_state[0], (UCHAR *)"OUT_FLOW_STATE");
		InsertSerialModemString(pResponseBuffer, &SerialStatusResponse.status.mdm_sig_state[0]);
	}
	return TRUE;
}


BOOL UpdateSerialExtendedConfiguration(UCHAR * pResponseBuffer, uint32 AdapterNumber, uint32 Channel)
{
	BuildResponseString(pResponseBuffer, &SerialExtendedConfiguration[0], AdapterNumber, 0, Channel,
		GetSerialExtendedConfiguration(AdapterNumber, Channel, &SerialExtendedConfigurationResponse));
	return TRUE;
}

BOOL AlterSerialExtendedConfiguration(uint32 AdapterNumber, uint32 Channel, uchar * Values)
{
	set_serial_ext_config_request_t set = {0};

	set.channel = Channel;
	if (!parse_uint32(Values, (UCHAR *)"UNPAUSE_RX=\"", &set.config.unpause_rx))
		return FALSE;

	if (!parse_uint32(Values, (UCHAR *)"UNPAUSE_TX=\"", &set.config.unpause_tx))
		return FALSE;

#if defined(SERIAL_PORT_RESET)
	if (!parse_uint32(Values, (UCHAR *)"RESET=\"", &set.config.reset))
		return FALSE;
#endif

	return (SetSerialExtendedConfiguration(AdapterNumber, &set));
}

BOOL UpdateSerialExtendedStatus(UCHAR * pResponseBuffer, uint32 AdapterNumber, uint32 Channel)
{
	BuildResponseString(pResponseBuffer, &SerialExtendedStatus[0], AdapterNumber, 0, Channel,
		GetSerialExtendedStatus(AdapterNumber, Channel, &SerialExtendedStatusResponse));
	return TRUE;
}


//-------------------------------------------------------------


BOOL UpdateCallStatus(UCHAR * pResponseBuffer, uint32 AdapterNumber, uint32 Port, uint32 Channel)
{
	BuildResponseString(pResponseBuffer, &CallStatus[0], AdapterNumber, Port, Channel,
		GetCallStatus(AdapterNumber, Port, Channel, &CallStatusResponse));
	return TRUE;
}


static void InsertCallStatusString(UCHAR * cp, uint32 index, call_status_t * status)
{
	cp = ReplaceClosingBracketWithElementBreak(cp);
	sprintf((char *)cp, "STAT_%lu=\"%lu\",\"%lu\",\"%lu\",\"%lu\"]", index, status->call_state, status->call_type, status->index, status->timeslot);
}

BOOL UpdateAllCallStatus(UCHAR * pResponseBuffer, uint32 AdapterNumber, uint32 Port)
{
	if (BuildResponseString(pResponseBuffer, &CallAllStatus[0], AdapterNumber, Port, 0,
			GetAllCallStatus(AdapterNumber, Port, &CallAllStatusResponse)))
	{
		uint32 i;
		for (i = 0; i < CallAllStatusResponse.count; i++)
			InsertCallStatusString(pResponseBuffer, i, &CallAllStatusResponse.status[i]);
	}
	return TRUE;
}


//-------------------------------------------------------------


BOOL UpdateModemConfiguration(UCHAR * pResponseBuffer, uint32 AdapterNumber, uint32 Channel)
{
	BuildResponseString(pResponseBuffer, &ModemConfiguration[0], AdapterNumber, 0, Channel,
		GetModemConfiguration(AdapterNumber, Channel, &ModemConfigurationResponse));
	return TRUE;
}

BOOL AlterModemConfiguration(uint32 AdapterNumber, uint32 Channel, uchar * Values)
{
	set_modem_config_request_t set = {0};

	set.channel = Channel;
	if (!parse_uint32(Values, (UCHAR *)"HANGUP=\"", &set.config.hangup))
		return FALSE;

	if (!parse_uint32(Values, (UCHAR *)"RESET=\"", &set.config.reset))
		return FALSE;

	return (SetModemConfiguration(AdapterNumber, &set));
}


BOOL UpdateModemStatus(UCHAR * pResponseBuffer, uint32 AdapterNumber, uint32 Channel)
{
	BuildResponseString(pResponseBuffer, &ModemStatus[0], AdapterNumber, 0, Channel,
		GetModemStatus(AdapterNumber, Channel, &ModemStatusResponse));
	return TRUE;
}


BOOL UpdateModemExtendedConfiguration(UCHAR * pResponseBuffer, uint32 AdapterNumber, uint32 Channel)
{
	BuildResponseString(pResponseBuffer, &ModemExtendedConfiguration[0], AdapterNumber, 0, Channel,
		GetModemExtendedConfiguration(AdapterNumber, Channel, &ModemExtendedConfigurationResponse));
	return TRUE;
}


BOOL UpdateModemExtendedStatus(UCHAR * pResponseBuffer, uint32 AdapterNumber, uint32 Channel)
{
	BuildResponseString(pResponseBuffer, &ModemExtendedStatus[0], AdapterNumber, 0, Channel,
		GetModemExtendedStatus(AdapterNumber, Channel, &ModemExtendedStatusResponse));
	return TRUE;
}


//-------------------------------------------------------------


BOOL UpdateDChannelExtendedConfiguration(UCHAR * pResponseBuffer, uint32 AdapterNumber, uint32 Port)
{
	BuildResponseString(pResponseBuffer, &DChannelExtendedConfiguration[0], AdapterNumber, Port, 0,
		GetDChannelExtendedConfiguration(AdapterNumber, Port, &DChannelExtendedConfigurationResponse));
	return TRUE;
}

static void InsertDChannelTEIStateString(UCHAR * cp, uint32 index, uint32 teistate)
{
	cp = ReplaceClosingBracketWithElementBreak(cp);
	sprintf((char *)cp, "TEI_STATE_%lu=\"%lu\"]", index, teistate);
}

BOOL UpdateDChannelExtendedStatus(UCHAR * pResponseBuffer, uint32 AdapterNumber, uint32 Port)
{
	if (BuildResponseString(pResponseBuffer, &DChannelExtendedStatus[0], AdapterNumber, Port, 0,
			GetDChannelExtendedStatus(AdapterNumber, Port, &DChannelExtendedStatusResponse)))
	{
		uint32 i;
		for (i = 0; i < DChannelExtendedStatusResponse.status.tei_count; i++)
			InsertDChannelTEIStateString(pResponseBuffer, i, DChannelExtendedStatusResponse.status.tei_state[i]);
	}
	return TRUE;
}


//-------------------------------------------------------------


BOOL UpdateBChannelStatus(UCHAR * pResponseBuffer, uint32 AdapterNumber, uint32 Channel)
{
	BuildResponseString(pResponseBuffer, &BChannelStatus[0], AdapterNumber, 0, Channel,
		GetBChannelStatus(AdapterNumber, Channel, &BChannelStatusResponse));
	return TRUE;
}


BOOL UpdateBChannelExtendedConfiguration(UCHAR * pResponseBuffer, uint32 AdapterNumber, uint32 Channel)
{
	BuildResponseString(pResponseBuffer, &BChannelExtendedConfiguration[0], AdapterNumber, 0, Channel,
		GetBChannelExtendedConfiguration(AdapterNumber, Channel, &BChannelExtendedConfigurationResponse));
	return TRUE;
}


BOOL AlterBChannelExtendedConfiguration(uint32 AdapterNumber, uint32 Channel, uchar * Values)
{
	set_bchan_ext_config_request_t set = {0};

	set.channel = Channel;
	if (!parse_uint32(Values, (UCHAR *)"HANGUP=\"", &set.config.hangup))
		return FALSE;

	if (!parse_uint32(Values, (UCHAR *)"CAUSECODE=\"", &set.config.cause_code))
		return FALSE;

	return (SetBChannelExtendedConfiguration(AdapterNumber, &set));
}


BOOL UpdateBChannelExtendedStatus(UCHAR * pResponseBuffer, uint32 AdapterNumber, uint32 Channel)
{
	BuildResponseString(pResponseBuffer, &BChannelExtendedStatus[0], AdapterNumber, 0, Channel,
		GetBChannelExtendedStatus(AdapterNumber, Channel, &BChannelExtendedStatusResponse));
	return TRUE;
}


//=============================================================
// -------------------------------------------------------------
// =============================================================


BOOL AlterModemExtendedConfiguration(uint32 AdapterNumber, uint32 Channel, uchar * Values)
{
	set_modem_ext_config_request_t set = {0};

	set.channel = Channel;
	if (!parse_uint32(Values, (UCHAR *)"BUSY_OUT=\"", &set.config.busy_out))
		return FALSE;

	return (SetModemExtendedConfiguration(AdapterNumber, &set));
}


//=============================================================
// -------------------------------------------------------------
// =============================================================


BOOL UpdateSystemStatus(UCHAR * pResponseBuffer)
{
	BuildResponseString(pResponseBuffer, &SystemStatus[0], 0, 0, 0,
		GetMgmtBoardCount(&ManagementBoardCountResponse));
	return TRUE;
}


BOOL UpdateAllChannelInfos(UCHAR * pResponseBuffer, uint32 AdapterNumber, BOOL getextradata)
{
	if (BuildResponseString(pResponseBuffer, &AllChannelInfos[0], AdapterNumber, 0, 0,
			GetAdapterInfo(AdapterNumber, &AdapterInfoResponse)))
	{
		uint32 port, channel;

		pResponseBuffer = ReplaceClosingBracketWithElementBreak(pResponseBuffer);
		pResponseBuffer = AppendString(pResponseBuffer, (UCHAR *)"CHANNEL_INFO=");

		for (port = 0; port < AdapterInfoResponse.info.port_count; port++)
		{
			GetAllCallStatus(AdapterNumber, port + 1, &CallAllStatusResponse);
			for (channel = 0; channel < CallAllStatusResponse.count; channel++)
			{
				uint32 state = CallAllStatusResponse.status[channel].call_state,
						 type = CallAllStatusResponse.status[channel].call_type,
						 index = CallAllStatusResponse.status[channel].index,
						 time = 0,
						 rx_rate = 0,
						 tx_rate = 0,
						 rx_bytes = 0,
						 tx_bytes = 0,
						 errors = 0,
						 busyout = 0;
						 
#if defined(CALL_BUSIED_OUT) && defined(CALL_INBOUND_BUSIED_OUT) && defined(CALL_OUTBOUND_BUSIED_OUT)
				switch (state)
				{
					case CALL_BUSIED_OUT:
						state = CALL_NEUTRAL;
						busyout = BUSY_OUT_ENABLE_IMMED;
						break;
					case CALL_INBOUND_BUSIED_OUT:
						state = CALL_INBOUND;
						busyout = BUSY_OUT_ENABLE_DELAYED;
						break;
					case CALL_OUTBOUND_BUSIED_OUT:
						state = CALL_OUTBOUND;
						busyout = BUSY_OUT_ENABLE_DELAYED;
						break;
				}
#endif

				if ((state != CALL_NEUTRAL) && getextradata)
				{
					if (type == CALL_BCHAN)
					{
						GetBChannelStatus(AdapterNumber, index, &BChannelStatusResponse);
						time = BChannelStatusResponse.status.connect_time;
						rx_rate = tx_rate = BChannelStatusResponse.status.channel_rate;

						GetBChannelExtendedStatus(AdapterNumber, index, &BChannelExtendedStatusResponse);
						rx_bytes = BChannelExtendedStatusResponse.status.hdlc.rx_bytes;
						tx_bytes = BChannelExtendedStatusResponse.status.hdlc.tx_bytes;
						errors = BChannelExtendedStatusResponse.status.hdlc.rx_crc_errors;
					}
					else if (type == CALL_MODEM)
					{
						GetModemStatus(AdapterNumber, index, &ModemStatusResponse);
						time = ModemStatusResponse.status.connect_time;
						rx_rate = ModemStatusResponse.status.current_rx_rate;
						tx_rate = ModemStatusResponse.status.current_tx_rate;

						GetModemExtendedStatus(AdapterNumber, index, &ModemExtendedStatusResponse);
						rx_bytes = ModemExtendedStatusResponse.status.rx_data_bytes;
						tx_bytes = ModemExtendedStatusResponse.status.tx_data_bytes;
						errors = ModemExtendedStatusResponse.status.rx_data_frame_errors;
					}
				}

				if ((port != 0) || (channel != 0))
					pResponseBuffer = AppendString(pResponseBuffer, (UCHAR *)",");

				pResponseBuffer += sprintf((char *)pResponseBuffer, "\"%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu\"",
					port + 1, channel + 1, state, type, index, time, rx_rate, busyout, tx_rate, rx_bytes, tx_bytes, errors);
			}

			// In case of T1 PRI where we only have 23 BChannels but channels/port = 24,
			// insert an empty entry with state and type both set to 0
			if (CallAllStatusResponse.count != AdapterInfoResponse.info.channels_per_port)
				pResponseBuffer += sprintf((char *)pResponseBuffer, ",\"%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu\"",
					port + 1, channel + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
		}

		pResponseBuffer = InsertElementBreak(pResponseBuffer);
		AppendString(pResponseBuffer, (UCHAR *)"]");
	}

	return TRUE;
}

BOOL UpdateAllSerialSummaries(UCHAR * pResponseBuffer, uint32 AdapterNumber)
{
	if (BuildResponseString(pResponseBuffer, &AllSerialSummaries[0], AdapterNumber, 0, 0,
			GetAdapterInfo(AdapterNumber, &AdapterInfoResponse)))
	{
		uint32 total_channels = (AdapterInfoResponse.info.port_count * AdapterInfoResponse.info.channels_per_port);
		uint32 chan;

		pResponseBuffer = ReplaceClosingBracketWithElementBreak(pResponseBuffer);
		pResponseBuffer = AppendStringPairUINT32(pResponseBuffer, (UCHAR *)"CHANNEL_COUNT", total_channels);
		pResponseBuffer = AppendString(pResponseBuffer, (UCHAR *)"SUMMARIES=");

		for (chan = 0; chan < total_channels; chan++)
		{
			serial_status_t * pss = NULL;

			GetSerialExtendedStatus(AdapterNumber, chan, &SerialExtendedStatusResponse);
			GetSerialTestChannelMode(AdapterNumber, chan, &SerialTestChannelModeResponse);

			if ((SerialTestChannelModeResponse.mode.mode & TEST_MODE) == TEST_MODE)
			{	// in test mode
				GetSerialTestStatus(AdapterNumber, chan, &SerialTestStatusResponse);
				pss = &SerialTestStatusResponse.st;
			}
			else
			{
				GetSerialStatus(AdapterNumber, chan, &SerialStatusResponse);
				pss = &SerialStatusResponse.status;
			}

#define GetFlowState(t, s, i) ((t[i] == SERIAL_FLOW_ENABLED) ? s[i] : 0)

			pResponseBuffer += sprintf((char *)pResponseBuffer, "%s\"%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu\"",
				((chan == 0) ? "" : ","),
				pss->port_state,
				SerialExtendedStatusResponse.status.tx_bytes,
				SerialExtendedStatusResponse.status.rx_bytes,
				pss->mdm_sig_state[SERIAL_SIGNAL_RTS],
				pss->mdm_sig_state[SERIAL_SIGNAL_CTS],
				pss->mdm_sig_state[SERIAL_SIGNAL_DTR],
				pss->mdm_sig_state[SERIAL_SIGNAL_DSR],
				pss->mdm_sig_state[SERIAL_SIGNAL_DCD],
				GetFlowState(pss->in_flow_type, pss->in_flow_state, SERIAL_IN_FLOW_XONXOFF_INDEX),
				GetFlowState(pss->out_flow_type, pss->out_flow_state, SERIAL_OUT_FLOW_XONXOFF_INDEX),
				SerialExtendedStatusResponse.status.parity_errs,
				SerialExtendedStatusResponse.status.overrun_errs,
				SerialExtendedStatusResponse.status.framing_errs,
				SerialTestChannelModeResponse.mode.mode,
				GetFlowState(pss->in_flow_type, pss->in_flow_state, SERIAL_IN_FLOW_RTS_INDEX),
				GetFlowState(pss->in_flow_type, pss->in_flow_state, SERIAL_IN_FLOW_DTR_INDEX),
				GetFlowState(pss->out_flow_type, pss->out_flow_state, SERIAL_OUT_FLOW_CTS_INDEX),
				GetFlowState(pss->out_flow_type, pss->out_flow_state, SERIAL_OUT_FLOW_DSR_INDEX));
		}
		pResponseBuffer = InsertElementBreak(pResponseBuffer);
		AppendString(pResponseBuffer, (UCHAR *)"]");
	}

	return TRUE;
}

BOOL UpdateAllSerialDetails(UCHAR * pResponseBuffer, uint32 AdapterNumber)
{
	if (BuildResponseString(pResponseBuffer, &AllSerialDetails[0], AdapterNumber, 0, 0,
			GetAdapterInfo(AdapterNumber, &AdapterInfoResponse)))
	{
		uint32 total_channels = (AdapterInfoResponse.info.port_count * AdapterInfoResponse.info.channels_per_port);
		uint32 chan;

		pResponseBuffer = ReplaceClosingBracketWithElementBreak(pResponseBuffer);
		pResponseBuffer = AppendStringPairUINT32(pResponseBuffer, (UCHAR *)"CHANNEL_COUNT", total_channels);
		pResponseBuffer = AppendString(pResponseBuffer, (UCHAR *)"DETAILS=");

		for (chan = 0; chan < total_channels; chan++)
		{

			serial_status_t * pss = NULL;
			serial_config_t * psc = NULL;

			GetSerialTestChannelMode(AdapterNumber, chan, &SerialTestChannelModeResponse);

			if ((SerialTestChannelModeResponse.mode.mode & TEST_MODE) == TEST_MODE)
			{	// in test mode
				GetSerialTestStatus(AdapterNumber, chan, &SerialTestStatusResponse);
				pss = &SerialTestStatusResponse.st;

				GetSerialTestConfiguration(AdapterNumber, chan, &SerialTestConfigurationResponse);
				psc = &SerialTestConfigurationResponse.cf;
			}
			else
			{
				GetSerialStatus(AdapterNumber, chan, &SerialStatusResponse);
				pss = &SerialStatusResponse.status;

				GetSerialConfiguration(AdapterNumber, chan, &SerialConfigurationResponse);
				psc = &SerialConfigurationResponse.config;
			}


			pResponseBuffer += sprintf((char *)pResponseBuffer, "%s\"%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu\"",
				((chan == 0) ? "" : ","),
				pss->in_speed,
				pss->data_bits,
				pss->parity,
				pss->stop_bits,
				psc->alt_pin,
				pss->in_flow_type[SERIAL_IN_FLOW_XONXOFF_INDEX],
				pss->in_flow_type[SERIAL_IN_FLOW_RTS_INDEX],
				pss->in_flow_type[SERIAL_IN_FLOW_DTR_INDEX],
				pss->out_flow_type[SERIAL_OUT_FLOW_XONXOFF_INDEX],
				pss->out_flow_type[SERIAL_OUT_FLOW_CTS_INDEX],
				pss->out_flow_type[SERIAL_OUT_FLOW_DSR_INDEX]);
		}
		pResponseBuffer = InsertElementBreak(pResponseBuffer);
		AppendString(pResponseBuffer, (UCHAR *)"]");
	}

	return TRUE;
}

BOOL UpdateSerialTestChannelMode(UCHAR * pResponseBuffer, uint32 AdapterNumber, uint32 Channel)
{
	BuildResponseString(pResponseBuffer, &SerialTestChannelMode[0], AdapterNumber, 0, Channel,
		GetSerialTestChannelMode(AdapterNumber, Channel, &SerialTestChannelModeResponse));
	return TRUE;
}

BOOL AlterSerialTestChannelMode(uint32 AdapterNumber, uint32 Channel, uchar * Values)
{
	set_serial_channel_test_mode_request_t set = {0};

	set.channel = Channel;
	if (!parse_uint32(Values, (UCHAR *)"MODE=\"", &set.mode.mode))
		return FALSE;

	return (SetSerialTestChannelMode(AdapterNumber, &set));
}

BOOL AlterSerialTestStatus(uint32 AdapterNumber, uint32 Channel, uchar * Values)
{
	set_serial_test_status_request_t set = {0};

	set.channel = Channel;

	if (!parse_uint32(Values, (UCHAR *)"BAUDRATE=\"", &set.st.in_speed))
		return FALSE;
	set.st.out_speed = set.st.in_speed;
	if (!parse_uint32(Values, (UCHAR *)"DATA_BITS=\"", &set.st.data_bits))
		return FALSE;
	if (!parse_uint32(Values, (UCHAR *)"STOP_BITS=\"", &set.st.stop_bits))
		return FALSE;
	if (!parse_uint32(Values, (UCHAR *)"PARITY=\"", &set.st.parity))
		return FALSE;
	if (!parse_uint8(Values, (UCHAR *)"XONXOFF_IN=\"", &set.st.in_flow_type[SERIAL_IN_FLOW_XONXOFF_INDEX]))
		return FALSE;
	if (!parse_uint8(Values, (UCHAR *)"RTS=\"", &set.st.in_flow_type[SERIAL_IN_FLOW_RTS_INDEX]))
		return FALSE;
	if (!parse_uint8(Values, (UCHAR *)"DTR=\"", &set.st.in_flow_type[SERIAL_IN_FLOW_DTR_INDEX]))
		return FALSE;
	if (!parse_uint8(Values, (UCHAR *)"XONXOFF_OUT=\"", &set.st.out_flow_type[SERIAL_OUT_FLOW_XONXOFF_INDEX]))
		return FALSE;
	if (!parse_uint8(Values, (UCHAR *)"CTS=\"", &set.st.out_flow_type[SERIAL_OUT_FLOW_CTS_INDEX]))
		return FALSE;
	if (!parse_uint8(Values, (UCHAR *)"DSR=\"", &set.st.out_flow_type[SERIAL_OUT_FLOW_DSR_INDEX]))
		return FALSE;

	return (SetSerialTestStatus(AdapterNumber, &set));
}

BOOL AlterSerialTestConfiguration(uint32 AdapterNumber, uint32 Channel, uchar * Values)
{
	set_serial_test_config_request_t set = {0};

	set.channel = Channel;
	if (!parse_uint32(Values, (UCHAR *)"ALT_PIN=\"", &set.cf.alt_pin))
		return FALSE;

	return (SetSerialTestConfiguration(AdapterNumber, &set));
}
