⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 config.c

📁 telcobridges tone develop
💻 C
📖 第 1 页 / 共 3 页
字号:
/*--------------------------------------------------------------------------------------------------------------------------------
 |
 |	Project:    	VoiceLink TB640 sample (tone)
 |
 |	Filename:   	config.c
 |
 |	Copyright:  	TelcoBridges 2002-2003, All Rights Reserved
 |
 |	Description:	This file contains the utility function(s) to retrieve/set the configuration of the on-board trunks
 |
 |	Notes:      	Tabs = 4
 |
 *-------------------------------------------------------------------------------------------------------------------------------
 |
 |	Revision:   	$Revision: 1.12 $
 |
 *------------------------------------------------------------------------------------------------------------------------------*/


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Includes
 *------------------------------------------------------------------------------------------------------------------------------*/

/* local includes */
#include "structures.h"

/*--------------------------------------------------------------------------------------------------------------------------------
 |  Forward declarations
 *------------------------------------------------------------------------------------------------------------------------------*/


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Defines
 *------------------------------------------------------------------------------------------------------------------------------*/


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Types
 *------------------------------------------------------------------------------------------------------------------------------*/


 /*--------------------------------------------------------------------------------------------------------------------------------
 |  Versioning
 *------------------------------------------------------------------------------------------------------------------------------*/
#ifdef WIN32
	/*@unused@*/ static char g_szFileVersion [] = "$Revision: 1.12 $";
#endif


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Global variables
 *------------------------------------------------------------------------------------------------------------------------------*/
TB640_TONE_TRUNK_INFO					g_aTrunkInfo [TB640_TONE_MAX_NB_TRUNK]				= {{0}};
TBX_UINT								g_unNbAllocatedTrunks								= 0;
TBX_UINT								g_unMaxAllowedTrunksE1								= 0;
TBX_UINT								g_unMaxAllowedTrunksT1								= 0;



/*--------------------------------------------------------------------------------------------------------------------------------
 |  Macros
 *------------------------------------------------------------------------------------------------------------------------------*/


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Function Prototypes
 *------------------------------------------------------------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------------------------------------------------------------
 |  Implementation
 *------------------------------------------------------------------------------------------------------------------------------*/


/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  GetMaxAllowedTrunks	:	Retrieve the maximum number of allowed E1 trunks.
 |
 |  in_hLib         :	Handle to the TBX library returned by TBXOpenLib()
 |  in_hAdapter     :	Handle to an adapter that was previously selected and attached to by SelectAdapter()
 |	in_fE1			:	E1 or T1 ?
 |
 |  Note			:	The adapter must support E1 configuration.
 |
 |  Return          :	TBX_RESULT_OK
 |						TBX_RESULT_FAIL
 |						or others
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT
GetMaxAllowedTrunks (
  IN		TBX_LIB_HANDLE			in_hLib,
  IN		TBX_ADAPTER_HANDLE		in_hAdapter,
  IN		TBX_BOOL				in_fE1)
{
	PTB640_MSG_ADAPTER_CFG_GET				pMsgCfgGet;
	PTB640_RSP_ADAPTER_CFG_GET				pRspCfgGet;
	TBX_FILTER_HANDLE						hFilter;
	TBX_MSG_HANDLE							hMsg;
	TBX_RESULT_API							apiResult;
	TBX_UINT32								iCount;

	/* Initialize local variables */
	pMsgCfgGet = NULL;
	pRspCfgGet = NULL;

	/* Get a message buffer */
	apiResult = TBXGetMsg (in_hLib, sizeof(*pMsgCfgGet), &hMsg);
	if (TBX_RESULT_SUCCESS (apiResult))
	{
		/* Clear the buffer..  Not necessary but helps debugging.  If used, must be done BEFORE setting the message header fields */
		memset (TBX_MSG_PAYLOAD_POINTER (hMsg), 0, TBX_MSG_PAYLOAD_MAX_LENGTH_GET (hMsg));

		/* Set the message header */
		TBX_FORMAT_MSG_HEADER (
		  hMsg,
		  TB640_MSG_ID_ADAPTER_CFG_GET,
		  TBX_MSG_TYPE_REQUEST,
		  sizeof(*pMsgCfgGet),
		  in_hAdapter,
		  0x12345678,
		  0x12345679);

		/* Fill the request */
		pMsgCfgGet = (PTB640_MSG_ADAPTER_CFG_GET) TBX_MSG_PAYLOAD_POINTER (hMsg);
		pMsgCfgGet->Request.un32MsgVersion = 1;

		/* Send the request */
		apiResult = TBXSendMsg (in_hLib, hMsg, &hFilter);
		hMsg = TBX_HANDLE_INVALID;
		if (TBX_RESULT_SUCCESS (apiResult))
		{
			pMsgCfgGet = NULL;

			/* Wait for the response synchronously */
			apiResult = TBXReceiveMsg (in_hLib, hFilter, TB640_TONE_RECEIVE_TIMEOUT_MSEC, &hMsg);
			if (TBX_RESULT_SUCCESS (apiResult))
			{
				/* We got the response */
				pMsgCfgGet = (PTB640_MSG_ADAPTER_CFG_GET) TBX_MSG_PAYLOAD_POINTER (hMsg);
				pRspCfgGet = &(pMsgCfgGet->Response);

				/* Search the feature list for the "E1" feature */
				for (iCount=0; iCount<pRspCfgGet->un32FeatureCount; iCount++)
				{
					if (in_fE1)
					{
						if (pRspCfgGet->aFeatures [iCount].FeatureType == TBX_FEATURE_TYPE_TRUNK_E1)
						{
							/* Check the maximum number of allowed E1s */
							g_unMaxAllowedTrunksE1 = pRspCfgGet->aFeatures [iCount].un32LicensedFeatureCount;
							break;
						}
					}
					else
					{
						if (pRspCfgGet->aFeatures [iCount].FeatureType == TBX_FEATURE_TYPE_TRUNK_T1)
						{
							/* Check the maximum number of allowed T1s */
							g_unMaxAllowedTrunksT1 = pRspCfgGet->aFeatures [iCount].un32LicensedFeatureCount;
							break;
						}
					}
				}
			}
		}

		/* Release the filter */
		if (hFilter != (TBX_FILTER_HANDLE)TBX_HANDLE_INVALID)
		{
			TBXDestroyMsgFilter (in_hLib, hFilter);
			hFilter = TBX_HANDLE_INVALID;
		}
	}

	/* Free the message buffer */
	if (hMsg != TBX_HANDLE_INVALID)
	{
		/* Free the message */
		TBXReleaseMsg (in_hLib, hMsg);
		hMsg = TBX_HANDLE_INVALID;
	}

	return apiResult;
}



/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  BuildAllocatedTrunkList	:	Retrieve the list of trunks that are already configured on this adapter.
 |
 |  in_hLib         :	Handle to the TBX library returned by TBXOpenLib()
 |  in_hAdapter     :	Handle to an adapter that was previously selected and attached to by SelectAdapter()
 |	in_fVerbose		:	Verbose display or not
 |
 |  Note			:	Allocated trunks must be in 'active' state for the application to work properly.
 |
 |  Return          :	TBX_RESULT_OK
 |						TBX_RESULT_FAIL
 |						or others
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT
BuildAllocatedTrunkList (
  IN		TBX_LIB_HANDLE			in_hLib,
  IN		TBX_ADAPTER_HANDLE		in_hAdapter,
  IN		TBX_BOOL				in_fVerbose)
{
	PTB640_MSG_TRUNK_OP_GET_LIST			pMsgGetList;
	PTB640_RSP_TRUNK_OP_GET_LIST			pRspGetList;
	TBX_FILTER_HANDLE						hFilter;
	TBX_MSG_HANDLE							hMsg;
	TBX_RESULT								result;
	TBX_RESULT_API							apiResult;
	TBX_UINT32								un32Trunk;

	/* Initialize local variables */
	pMsgGetList = NULL;
	pRspGetList = NULL;
	hMsg = TBX_HANDLE_INVALID;
	result = TBX_RESULT_OK;
	apiResult = TBX_RESULT_API_OK;
	hFilter = (TBX_FILTER_HANDLE)TBX_HANDLE_INVALID;

	/* Reset global variable */
	g_unNbAllocatedTrunks = 0;
	memset (g_aTrunkInfo, 0, sizeof(g_aTrunkInfo));

	/* Get a message buffer */
	apiResult = TBXGetMsg (in_hLib, sizeof(*pMsgGetList), &hMsg);
	if (TBX_RESULT_SUCCESS (apiResult))
	{
		/* Clear the buffer..  Not necessary but helps debugging.  If used, must be done BEFORE setting the message header fields */
		memset (TBX_MSG_PAYLOAD_POINTER (hMsg), 0, TBX_MSG_PAYLOAD_MAX_LENGTH_GET (hMsg));

		/* Set the message header */
		TBX_FORMAT_MSG_HEADER (
		  hMsg,
		  TB640_MSG_ID_TRUNK_OP_GET_LIST,
		  TBX_MSG_TYPE_REQUEST,
		  sizeof(*pMsgGetList),
		  in_hAdapter,
		  0x12345678,
		  0x12345678);

		/* Fill the request */
		pMsgGetList = (PTB640_MSG_TRUNK_OP_GET_LIST) TBX_MSG_PAYLOAD_POINTER (hMsg);
		pMsgGetList->Request.un32MsgVersion = 1;

		/* Send the request */
		apiResult = TBXSendMsg (in_hLib, hMsg, &hFilter);
		hMsg = TBX_HANDLE_INVALID;
		if (TBX_RESULT_SUCCESS (apiResult))
		{
			pMsgGetList = NULL;

			/* Wait for the response synchronously */
			apiResult = TBXReceiveMsg (in_hLib, hFilter, TB640_TONE_RECEIVE_TIMEOUT_MSEC, &hMsg);
			if (TBX_RESULT_SUCCESS (apiResult))
			{
				/* We got the response */
				pMsgGetList = (PTB640_MSG_TRUNK_OP_GET_LIST) TBX_MSG_PAYLOAD_POINTER (hMsg);
				pRspGetList = &(pMsgGetList->Response);

				if (TBX_RESULT_SUCCESS (pRspGetList->Result))
				{
					/* Here's the number of currently allocated trunks */
					g_unNbAllocatedTrunks = pRspGetList->un32TrunkCount;

					/* Copy the handles */
					for( un32Trunk = 0; un32Trunk < g_unNbAllocatedTrunks; un32Trunk++ )
					{
						TBX_UINT32	un32TrunkNo;
						/* Retrieve the trunk number */
						result = RetrieveTrunkConfiguration(
							in_hLib,
							in_hAdapter,
							pRspGetList->ahTrunk [un32Trunk],
							in_fVerbose,
							&un32TrunkNo );

						if (TBX_RESULT_SUCCESS (result) && TBX_RESULT_SUCCESS (pRspGetList->Result))
						{
							/* Copy trunk handle */
							g_aTrunkInfo [ un32TrunkNo ].hTrunk = pRspGetList->ahTrunk [un32Trunk];

							/* Retrive the trunk state */
							RetrieveTrunkState( in_hLib, in_hAdapter, un32TrunkNo, in_fVerbose );
						}
					}
				}
				else
				{
					/* We got an error code from the adapter */
					result = pRspGetList->Result;
				}

			}
		}

		/* Release the filter */
		if (hFilter != (TBX_FILTER_HANDLE)TBX_HANDLE_INVALID)
		{
			TBXDestroyMsgFilter (in_hLib, hFilter);
			hFilter = TBX_HANDLE_INVALID;
		}
	}

	/* Free the message buffer */
	if (hMsg != TBX_HANDLE_INVALID)
	{
		/* Free the message */
		TBXReleaseMsg (in_hLib, hMsg);
		hMsg = TBX_HANDLE_INVALID;
	}

	/* Propagate an error result */
	if (TBX_RESULT_FAILURE (apiResult))
	{
		result = apiResult;
	}

	return result;
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  RetrieveTrunkConfiguration:	Retrieve the configuration of a trunk
 |
 |  in_hLib         :	Handle to the TBX library returned by TBXOpenLib()
 |  in_hAdapter     :	Handle to an adapter that was previously selected and attached to by SelectAdapter()
 |	in_hTrunk		:	Trunk to retrieve its configuration
 |	in_fVerbose		:	Verbose
 |	out_pun32TrunkNo;	Trunk number that corresponds to this handle
 |
 |  Note			:	Allocated trunks must be in 'active' state for the application to work properly.
 |
 |  Return          :	TBX_RESULT_OK
 |						TBX_RESULT_FAIL
 |						or others
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT
RetrieveTrunkConfiguration (
  IN		TBX_LIB_HANDLE			in_hLib,
  IN		TBX_ADAPTER_HANDLE		in_hAdapter,
  IN		TB640_TRUNK_HANDLE		in_hTrunk,
  IN		TBX_BOOL				in_fVerbose,
  OUT		PTBX_UINT32				out_pun32TrunkNo )
{
	PTB640_MSG_TRUNK_OP_GET_PARAMS			pMsgGetParam;
	PTB640_REQ_TRUNK_OP_GET_PARAMS			pReqGetParam;
	PTB640_RSP_TRUNK_OP_GET_PARAMS			pRspGetParam;
	TBX_FILTER_HANDLE						hFilter;
	TBX_MSG_HANDLE							hMsg;
	TBX_RESULT								result;
	TBX_RESULT_API							apiResult;

	/* Initialize local variables */
	pMsgGetParam = NULL;
	pReqGetParam = NULL;
	pRspGetParam = NULL;
	hMsg = TBX_HANDLE_INVALID;
	result = TBX_RESULT_OK;
	apiResult = TBX_RESULT_API_OK;
	hFilter = (TBX_FILTER_HANDLE)TBX_HANDLE_INVALID;

	/* Display progress */
	if( in_fVerbose )
	{
		fprintf (stdout, "Retrieving trunk configuration...\n" );
	}

	/* Get a message buffer */
	apiResult = TBXGetMsg (in_hLib, sizeof(*pMsgGetParam), &hMsg);
	if (TBX_RESULT_SUCCESS (apiResult))
	{
		/* Clear the buffer..  Not necessary but helps debugging.  If used, must be done BEFORE setting the message header fields */
		memset (TBX_MSG_PAYLOAD_POINTER (hMsg), 0, TBX_MSG_PAYLOAD_MAX_LENGTH_GET (hMsg));

		/* Set the message header */
		TBX_FORMAT_MSG_HEADER (
		  hMsg,
		  TB640_MSG_ID_TRUNK_OP_GET_PARAMS,
		  TBX_MSG_TYPE_REQUEST,
		  sizeof(*pMsgGetParam),
		  in_hAdapter,
		  0,
		  0);

		/* Fill the request */
		pMsgGetParam = (PTB640_MSG_TRUNK_OP_GET_PARAMS) TBX_MSG_PAYLOAD_POINTER (hMsg);
		pReqGetParam = (PTB640_REQ_TRUNK_OP_GET_PARAMS)&pMsgGetParam->Request;
		pReqGetParam->un32MsgVersion = 1;
		pReqGetParam->hTrunk = in_hTrunk;

		/* Send the request */
		apiResult = TBXSendMsg (in_hLib, hMsg, &hFilter);
		hMsg = TBX_HANDLE_INVALID;
		if (TBX_RESULT_SUCCESS (apiResult))
		{
			pMsgGetParam = NULL;
		}
	}

	/* Free the message buffer */
	if (hMsg != TBX_HANDLE_INVALID)
	{
		/* Free the message */
		TBXReleaseMsg (in_hLib, hMsg);
		hMsg = TBX_HANDLE_INVALID;
	}

	if (TBX_RESULT_SUCCESS (result))
	{
		/* Wait for the response synchronously */
		apiResult = TBXReceiveMsg (in_hLib, hFilter, TB640_TONE_RECEIVE_TIMEOUT_MSEC, &hMsg);
		if (TBX_RESULT_SUCCESS (apiResult))
		{
			/* Make sure we have received a proper response */
			if (TBX_MSG_ID_GET(hMsg) == TB640_MSG_ID_TRUNK_OP_GET_PARAMS)
			{
				/* We got the response */
				pMsgGetParam = (PTB640_MSG_TRUNK_OP_GET_PARAMS) TBX_MSG_PAYLOAD_POINTER (hMsg);
				pRspGetParam = (PTB640_RSP_TRUNK_OP_GET_PARAMS)&pMsgGetParam->Response;

				/* Was the configuration successful ? */
				if (TBX_RESULT_SUCCESS (pRspGetParam->Result))
				{
					/* Return the trunk number */
					if( out_pun32TrunkNo ) *out_pun32TrunkNo = pRspGetParam->un32Trunk;
					if( pRspGetParam->un32Trunk > 64 )
					{
						pRspGetParam->un32Trunk = 0;
					}

					/* Get the number of 64kbps timeslot according to the type of interface */
					if (pRspGetParam->TrunkCfg.Type == TB640_TRUNK_TYPE_E1 )

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -