📄 config.c
字号:
{
/* Get a message buffer */
apiResult = TBXGetMsg (in_hLib, sizeof(*pMsgTrunkFree), &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_FREE,
TBX_MSG_TYPE_REQUEST,
sizeof(*pMsgTrunkFree),
in_hAdapter,
in_un32TrunkToFree,
in_un32TrunkToFree);
/* Fill the request */
pMsgTrunkFree = (PTB640_MSG_TRUNK_OP_FREE) TBX_MSG_PAYLOAD_POINTER (hMsg);
pReqTrunkFree = (PTB640_REQ_TRUNK_OP_FREE)&pMsgTrunkFree->Request;
pReqTrunkFree->un32MsgVersion = 1;
pReqTrunkFree->hTrunk = g_aTrunkInfo [in_un32TrunkToFree].hTrunk;
/* Send the request */
apiResult = TBXSendMsg (in_hLib, hMsg, &hFilter);
hMsg = TBX_HANDLE_INVALID;
if (TBX_RESULT_SUCCESS (apiResult))
{
pMsgTrunkFree = NULL;
}
}
/* Free the message buffer */
if (hMsg != TBX_HANDLE_INVALID)
{
/* Free the message */
TBXReleaseMsg (in_hLib, hMsg);
hMsg = TBX_HANDLE_INVALID;
}
/* 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_FREE)
{
/* Retrieve the index into our array */
if( (TBX_UINT32)TBX_MSG_USER_CONTEXT1_GET (hMsg) == in_un32TrunkToFree )
{
/* We got the response */
pMsgTrunkFree = (PTB640_MSG_TRUNK_OP_FREE) TBX_MSG_PAYLOAD_POINTER (hMsg);
pRspTrunkFree = (PTB640_RSP_TRUNK_OP_FREE)&pMsgTrunkFree->Response;
/* Was the configuration successful ? */
if (TBX_RESULT_SUCCESS (pRspTrunkFree->Result))
{
/* The trunk was freed */
g_aTrunkInfo [in_un32TrunkToFree].hTrunk = (TB640_TRUNK_HANDLE)TBX_HANDLE_INVALID;
g_aTrunkInfo [in_un32TrunkToFree].unNb64KbpsTimeslotAvailable = 0;
g_aTrunkInfo [in_un32TrunkToFree].fAllocated = TBX_FALSE;
}
else
{
/* We received an error */
result = pRspTrunkFree->Result;
}
}
else
{
/* error */
result = TBX_RESULT_API_INCOMPLETE;
}
}
/* 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;
}
if( out_pfTrunkFreed ) *out_pfTrunkFreed = fTrunkFreed;
/* Release the filter */
if (hFilter != (TBX_FILTER_HANDLE)TBX_HANDLE_INVALID)
{
TBXDestroyMsgFilter (in_hLib, hFilter);
hFilter = TBX_HANDLE_INVALID;
}
}
/* Was there an error along in the process ? */
if (TBX_RESULT_FAILURE (result))
{
ValidateErrorCode (result, in_hAdapter, in_hLib);
}
return result;
}
/*-------------------------------------------------------------------------------------------------------------------------------
|
| SetDefaultTrunkConfiguration: Configure all trunks as E1s regardless of their actual configuration.
|
| 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_un32TrunkNb : Trunk number to configure
| in_fE1 : E1 or T1 ?
|
| Note : The adapter must support E1 configuration.
|
| Return : TBX_RESULT_OK
| TBX_RESULT_FAIL
| or others
|
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT
SetDefaultTrunkConfiguration (
IN TBX_LIB_HANDLE in_hLib,
IN TBX_ADAPTER_HANDLE in_hAdapter,
IN TBX_UINT32 in_un32TrunkNb,
IN TBX_BOOL in_fE1)
{
PTB640_MSG_TRUNK_OP_ALLOC pMsgTrunkAlloc;
PTB640_REQ_TRUNK_OP_ALLOC pReqTrunkAlloc;
PTB640_RSP_TRUNK_OP_ALLOC pRspTrunkAlloc;
PTB640_MSG_TRUNK_OP_ACTIVE pMsgActive;
PTB640_RSP_TRUNK_OP_ACTIVE pRspActive;
PTB640_REQ_TRUNK_OP_ACTIVE pReqActive;
PTB640_TRUNK_CFG pTrunkCfg;
PTB640_E1_CFG pE1Cfg;
PTB640_T1_CFG pT1Cfg;
TBX_FILTER_HANDLE hFilter;
TBX_MSG_HANDLE hMsg;
TBX_RESULT result;
TBX_RESULT_API apiResult;
/* Initialize local variables */
pMsgTrunkAlloc = NULL;
pReqTrunkAlloc = NULL;
pRspTrunkAlloc = NULL;
pMsgActive = NULL;
pRspActive = NULL;
pReqActive = NULL;
pTrunkCfg = NULL;
pE1Cfg = NULL;
hMsg = TBX_HANDLE_INVALID;
result = TBX_RESULT_OK;
apiResult = TBX_RESULT_API_OK;
hFilter = (TBX_FILTER_HANDLE)TBX_HANDLE_INVALID;
/* Display progress */
fprintf (stdout, "Setting trunk %d to default %s configuration...\n",
(int)in_un32TrunkNb,
((in_fE1)?"E1":"T1"));
/* Get the adapter's information (E1 or T1 max count) */
result = GetMaxAllowedTrunks( in_hLib, in_hAdapter, in_fE1 );
/* The default configuration requires E1 capabilities */
if (TBX_RESULT_SUCCESS (result))
{
if (in_fE1)
{
if (g_unMaxAllowedTrunksE1 == 0)
{
fprintf (stdout, "No E1 trunks can be allocated on the adapter.\n" );
result = TBX_RESULT_FAIL;
}
}
else
{
if (g_unMaxAllowedTrunksT1 == 0)
{
fprintf (stdout, "No T1 trunks can be allocated on the adapter.\n" );
result = TBX_RESULT_FAIL;
}
}
}
/* Configure the E1/T1 port */
if (TBX_RESULT_SUCCESS (result))
{
/* Alloc. selected trunk to T1 or E1 */
apiResult = TBXGetMsg (in_hLib, sizeof(*pMsgTrunkAlloc), &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_ALLOC,
TBX_MSG_TYPE_REQUEST,
sizeof(*pMsgTrunkAlloc),
in_hAdapter,
in_un32TrunkNb,
in_un32TrunkNb);
/* Fill the request */
pMsgTrunkAlloc = (PTB640_MSG_TRUNK_OP_ALLOC) TBX_MSG_PAYLOAD_POINTER (hMsg);
pReqTrunkAlloc = (PTB640_REQ_TRUNK_OP_ALLOC)&pMsgTrunkAlloc->Request;
pReqTrunkAlloc->un32MsgVersion = 1;
pReqTrunkAlloc->un32Trunk = in_un32TrunkNb;
#if defined( SOLARIS8 ) || defined( LINUX )
pReqTrunkAlloc->un64UserContext1 = 0xabcd12345678ll;
pReqTrunkAlloc->un64UserContext2 = 0xabcd12345679ll;
#else
pReqTrunkAlloc->un64UserContext1 = 0xabcd12345678;
pReqTrunkAlloc->un64UserContext2 = 0xabcd12345679;
#endif
if (in_fE1)
{
/* Configure to E1, MultiFrame with CRC, HDB3, short, non-loop'ed time, idle code to 0x7F */
pTrunkCfg = &pReqTrunkAlloc->TrunkCfg;
pTrunkCfg->un32StructVersion = 1;
pTrunkCfg->Type = TB640_TRUNK_TYPE_E1;
pE1Cfg = &pTrunkCfg->Cfg.E1;
pE1Cfg->Framing = TB640_E1_FRAMING_AUTO;
pE1Cfg->Encoding = TB640_E1_LINE_ENCODING_HDB3;
pE1Cfg->Termination = TB640_E1_LINE_TERMINATION_SHORT;
pE1Cfg->fLoopTime = TBX_FALSE;
pE1Cfg->byIdleCode = 0x7F;
}
else
{
/* Configure to T1, ESF, B8ZS, non-loop'ed time, idle code to 0x7F */
pTrunkCfg = &pReqTrunkAlloc->TrunkCfg;
pTrunkCfg->un32StructVersion = 1;
pTrunkCfg->Type = TB640_TRUNK_TYPE_T1;
pT1Cfg = &pTrunkCfg->Cfg.T1;
pT1Cfg->Framing = TB640_T1_FRAMING_ESF;
pT1Cfg->Encoding = TB640_T1_LINE_ENCODING_B8ZS;
pT1Cfg->Termination = TB640_T1_LINE_TERMINATION_SHORT;
pT1Cfg->fLoopTime = TBX_FALSE;
pT1Cfg->byIdleCode = 0x7F;
}
/* Send the request */
apiResult = TBXSendMsg (in_hLib, hMsg, &hFilter);
if (TBX_RESULT_SUCCESS (apiResult))
{
pMsgTrunkAlloc = NULL;
}
}
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_ALLOC)
{
/* We got the response */
pMsgTrunkAlloc = (PTB640_MSG_TRUNK_OP_ALLOC) TBX_MSG_PAYLOAD_POINTER (hMsg);
pRspTrunkAlloc = (PTB640_RSP_TRUNK_OP_ALLOC)&pMsgTrunkAlloc->Response;
/* Retrieve the index into our array */
if( (TBX_UINT32)TBX_MSG_USER_CONTEXT1_GET (hMsg) == in_un32TrunkNb )
{
/* Was the configuration successful ? */
if (TBX_RESULT_SUCCESS (pRspTrunkAlloc->Result))
{
/* Save the handle */
g_aTrunkInfo [in_un32TrunkNb].hTrunk = pRspTrunkAlloc->hTrunk;
if (in_fE1)
{
g_aTrunkInfo [in_un32TrunkNb].unNb64KbpsTimeslotAvailable = 31; /* Clear-channel E1 */
}
else
{
g_aTrunkInfo [in_un32TrunkNb].unNb64KbpsTimeslotAvailable = 24; /* Clear-channel T1 */
}
g_aTrunkInfo [in_un32TrunkNb].fAllocated = TBX_TRUE; /* We allocated it */
}
}
else
{
/* Error */
}
}
/* Free the message buffer */
if (hMsg != TBX_HANDLE_INVALID)
{
/* Free the message */
TBXReleaseMsg (in_hLib, hMsg);
hMsg = TBX_HANDLE_INVALID;
}
}
/* Release the filter */
if (hFilter != (TBX_FILTER_HANDLE)TBX_HANDLE_INVALID)
{
TBXDestroyMsgFilter (in_hLib, hFilter);
hFilter = TBX_HANDLE_INVALID;
}
}
/* Propagate an error result */
if (TBX_RESULT_FAILURE (apiResult))
{
result = apiResult;
}
}
/* Activate trunk */
if (TBX_RESULT_SUCCESS (result))
{
/* Display progress */
fprintf (stdout, "Activating trunk...\n" );
if (TBX_RESULT_SUCCESS (result))
{
/* Activate selected E1 trunk */
/* Get a message buffer */
apiResult = TBXGetMsg (in_hLib, sizeof(*pMsgActive), &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_ACTIVE,
TBX_MSG_TYPE_REQUEST,
sizeof(*pMsgActive),
in_hAdapter,
in_un32TrunkNb,
in_un32TrunkNb);
/* Fill the request */
pMsgActive = (PTB640_MSG_TRUNK_OP_ACTIVE) TBX_MSG_PAYLOAD_POINTER (hMsg);
pReqActive = (PTB640_REQ_TRUNK_OP_ACTIVE)&pMsgActive->Request;
pReqActive->un32MsgVersion = 1;
pReqActive->hTrunk = g_aTrunkInfo [in_un32TrunkNb].hTrunk;
/* Send the request */
apiResult = TBXSendMsg (in_hLib, hMsg, &hFilter);
hMsg = TBX_HANDLE_INVALID;
if (TBX_RESULT_SUCCESS (apiResult))
{
pMsgActive = 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_ACTIVE)
{
/* We got the response */
pMsgActive = (PTB640_MSG_TRUNK_OP_ACTIVE) TBX_MSG_PAYLOAD_POINTER (hMsg);
pRspActive = (PTB640_RSP_TRUNK_OP_ACTIVE)&pMsgActive->Response;
/* Retrieve the index into our array */
if( (TBX_UINT32)TBX_MSG_USER_CONTEXT1_GET (hMsg) == in_un32TrunkNb )
{
/* Was the configuration successful ? */
if (TBX_RESULT_SUCCESS (pRspActive->Result))
{
/* Save the new state */
g_aTrunkInfo [in_un32TrunkNb].fActivated = TBX_TRUE;
}
}
else
{
/* Error */
}
}
/* 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;
}
}
/* Release the filter */
if (hFilter != (TBX_FILTER_HANDLE)TBX_HANDLE_INVALID)
{
TBXDestroyMsgFilter (in_hLib, hFilter);
hFilter = TBX_HANDLE_INVALID;
}
/* Was there an error along in the process ? */
if (TBX_RESULT_FAILURE (result))
{
ValidateErrorCode (result, in_hAdapter, in_hLib);
}
return result;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -