📄 ha.c
字号:
*out_phMsg = hMsg;
/* Erase the payload */
memset (TBX_MSG_PAYLOAD_POINTER(hMsg), 0, TBX_MSG_PAYLOAD_LENGTH_GET(hMsg));
/* Format the message header */
TBX_FORMAT_MSG_HEADER ( \
hMsg, \
un32MsgId, \
TBX_MSG_TYPE_REQUEST, \
un32MsgSize, \
pAdapterInfo->hAdapter, \
0, \
0);
/* Retrieve the pointers */
pGetListMsg = (PTBX_VOID)TBX_MSG_PAYLOAD_POINTER(hMsg);
pGetParamsMsg = (PTBX_VOID)TBX_MSG_PAYLOAD_POINTER(hMsg);
pGetStatesMsg = (PTBX_VOID)TBX_MSG_PAYLOAD_POINTER(hMsg);
/* Find which message to send */
switch (in_QueryType)
{
case TB640_ISDN_QUERY_TYPE_LIST:
pGetListMsg->Request.un32MsgVersion = 1;
break;
case TB640_ISDN_QUERY_TYPE_PARAMS:
pGetParamsMsg->Request.un32MsgVersion = 1;
pGetParamsMsg->Request.hTrunk = hTrunk;
break;
case TB640_ISDN_QUERY_TYPE_STATES:
pGetParamsMsg->Request.un32MsgVersion = 1;
pGetParamsMsg->Request.hTrunk = hTrunk;
break;
default:
TBX_EXIT_ERROR (TBX_RESULT_INVALID_PARAM, 0, "Unknown query type");
}
/* End of the code (skip to cleanup) */
TBX_EXIT_SUCCESS (TBX_RESULT_OK);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Error handling section
*--------------------------------------------------------------------------------------------------------------------------*/
ERROR_HANDLING
{
/* Print error message */
TB640_ISDN_LOG (TRACE_LEVEL_ALWAYS, "%s (Result = 0x%08X, %s, line %d)\n", TBX_ERROR_DESCRIPTION, TBX_ERROR_RESULT, __FILE__, TBX_ERROR_LINE);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Cleanup section
*--------------------------------------------------------------------------------------------------------------------------*/
CLEANUP
{
}
RETURN;
}
/*-------------------------------------------------------------------------------------------------------------------------------
|
| TB640IsdnAdapterTrunkRetrievedInfo: This function is called by the automatic query function when the params and the state
| of a particular trunks has been retrieved.
|
| in_pvAppContext : User-defined context
| in_un32UserContext: User context (not used)
| in_hEntity : Handle of the trunk
| in_pMsgGetParams: Pointer to the get params response message
| in_pMsgGetState : Pointer to the get states response message
|
| Note : This function will fail if it detects an mismatch between our stored configuration and what was found
| on the adapter.
|
| Return : TBX_RESULT_OK
| TBX_RESULT_FAIL
|
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT TB640IsdnAdapterTrunkRetrievedInfo (
IN PTBX_VOID in_pvAppContext,
IN TBX_UINT32 in_un32UserContext,
IN TBX_UINT32 in_hEntity,
IN PTBX_VOID in_pMsgGetParams,
IN PTBX_VOID in_pMsgGetState)
{
TBX_RESULT result;
TBX_UINT32 un32AdapterIdx;
TBX_UINT32 un32OpLibIdx;
PTB640_ISDN_ADAPTER_INFO pAdapterInfo;
TB640_TRUNK_HANDLE hTrunk = (TB640_TRUNK_HANDLE)in_hEntity;
PTB640_RSP_TRUNK_OP_GET_PARAMS pGetParamsMsg = in_pMsgGetParams;
PTB640_RSP_PMALARMMGR_STATES_GET pGetStatesMsg = in_pMsgGetState;
PTB640_ISDN_TRUNK_INFO pTrunkInfo;
/*---------------------------------------------------------------------------------------------------------------------------
| Code section
*--------------------------------------------------------------------------------------------------------------------------*/
CODE
{
/* Initialize local variables */
/* Retrieve the adapter index and operation lib index */
TB640_ISDN_RETRIEVE_APP_CONTEXT (in_pvAppContext, un32AdapterIdx, un32OpLibIdx);
pAdapterInfo = &(g_AppContext->ahAdapterInfo [un32AdapterIdx]);
/* Validate both return values */
if TBX_RESULT_FAILURE(pGetParamsMsg->Result)
{
TBX_EXIT_ERROR (pGetParamsMsg->Result, 0, "get_params refused");
}
if TBX_RESULT_FAILURE(pGetStatesMsg->Result)
{
TBX_EXIT_ERROR (pGetStatesMsg->Result, 0, "get_states refused");
}
/* Validate the trunk number */
if (pGetParamsMsg->un32Trunk >= TB640_ISDN_MAX_SUPPORTED_TRUNKS_PER_ADAPTER)
{
/* Got an invalid value */
TBX_EXIT_ERROR (TBX_RESULT_INVALID_PARAM, 0, "Invalid trunk number retrieved");
}
/* Retrieve the trunk structure */
pTrunkInfo = &(pAdapterInfo->aTrunkInfo [pGetParamsMsg->un32Trunk]);
/* Check if we 'own' this trunk */
if (pTrunkInfo->TrunkConfiguration.Type == (TB640_TRUNK_TYPE)NULL)
{
/* No, then we have nothing to do*/
TBX_EXIT_SUCCESS (TBX_RESULT_OK);
}
/* Validate the configuration of the trunk with our local structure */
if (memcmp(&(pTrunkInfo->TrunkConfiguration), &(pGetParamsMsg->TrunkCfg), sizeof(pGetParamsMsg->TrunkCfg)) != 0)
{
/* Got an incompatible value */
TB640_ISDN_LOG (TRACE_LEVEL_3, "Detected a conflicting configuration for trunk %d (adapter %s)\n", pGetParamsMsg->un32Trunk, pAdapterInfo->szAdapterName);
TBX_EXIT_ERROR (TBX_RESULT_INVALID_PARAM, 0, "Detected a conflicting configuration");
}
/* Remember the new handle */
pTrunkInfo->hTrunk = hTrunk;
/* Re-insert into the hash table */
TBXHashInsert (pAdapterInfo->hTrunkHash, (TBX_HASH_KEY)hTrunk, pTrunkInfo);
/* Update the framing status */
if ((pGetStatesMsg->States.Alarm &
(TB640_PMALARMMGR_ALARM_FAILURE_LOS | TB640_PMALARMMGR_ALARM_FAILURE_LOF |
TB640_PMALARMMGR_ALARM_FAILURE_AIS | TB640_PMALARMMGR_ALARM_FAILURE_RAI)) != 0)
{
pTrunkInfo->aResourceInfo [0].Statistics.State = TB640_ISDN_TRUNK_RESOURCE_STATE_FRAMING_DOWN;
}
else
{
pTrunkInfo->aResourceInfo [0].Statistics.State = TB640_ISDN_TRUNK_RESOURCE_STATE_FRAMING_UP;
}
/* Update the D-channel status */
if (pTrunkInfo->TrunkConfiguration.Type == TB640_TRUNK_TYPE_E1)
{
pTrunkInfo->aResourceInfo [16].Statistics.State = TB640_ISDN_TRUNK_RESOURCE_STATE_LINK_DOWN;
}
else
{
pTrunkInfo->aResourceInfo [24].Statistics.State = TB640_ISDN_TRUNK_RESOURCE_STATE_LINK_DOWN;
}
/* Resync the trunk resource */
result = TB640IsdnAdapterResyncTrunkRes (in_pvAppContext, hTrunk);
if TBX_RESULT_FAILURE(result)
{
TBX_EXIT_ERROR (result, 0, "Unable to resync trunk resources");
}
/* End of the code (skip to cleanup) */
TBX_EXIT_SUCCESS (TBX_RESULT_OK);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Error handling section
*--------------------------------------------------------------------------------------------------------------------------*/
ERROR_HANDLING
{
/* Print error message */
TB640_ISDN_LOG (TRACE_LEVEL_ALWAYS, "%s (Result = 0x%08X, %s, line %d)\n", TBX_ERROR_DESCRIPTION, TBX_ERROR_RESULT, __FILE__, TBX_ERROR_LINE);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Cleanup section
*--------------------------------------------------------------------------------------------------------------------------*/
CLEANUP
{
}
RETURN;
}
/*-------------------------------------------------------------------------------------------------------------------------------
|
| TB640IsdnAdapterResyncTrunk: This function is called to re-sync the handle and states of trunks. If handles are not
| found, it means the board has been either rebooted or cleared. In that case, we will
| re-allocate the resource.
|
| in_pvAppContext : User-defined context
|
| Note : This function will fail if the configuration found on the board does not correspond to what was
| supposed to be there.
|
| Return : No return value
|
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT TB640IsdnAdapterResyncTrunk (
IN PTBX_VOID in_pvAppContext)
{
TBX_UINT32 un32AdapterIdx;
TBX_UINT32 un32OpLibIdx;
PTB640_ISDN_ADAPTER_INFO pAdapterInfo;
TBX_RESULT result;
/*---------------------------------------------------------------------------------------------------------------------------
| Code section
*--------------------------------------------------------------------------------------------------------------------------*/
CODE
{
/* Initialize local variables */
/* Retrieve the adapter index and operation lib index */
TB640_ISDN_RETRIEVE_APP_CONTEXT (in_pvAppContext, un32AdapterIdx, un32OpLibIdx);
pAdapterInfo = &(g_AppContext->ahAdapterInfo [un32AdapterIdx]);
/* Get the list, params and states of trunks loaded in the structure */
result = TB640IsdnAdapterQueryInfo (in_pvAppContext, 0, TB640IsdnAdapterTrunkQueryInfo, TB640IsdnAdapterTrunkRetrievedInfo);
if (TBX_RESULT_FAILURE (result))
{
TBX_EXIT_ERROR(result, 0, "Unable to resync trunks");
}
/* Allocate missing trunks */
TB640IsdnAllocateTrunks (un32AdapterIdx, un32AdapterIdx+1);
/* Activate trunks */
TB640IsdnActivateTrunks (un32AdapterIdx, un32AdapterIdx+1);
/* End of the code (skip to cleanup) */
TBX_EXIT_SUCCESS (TBX_RESULT_OK);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Error handling section
*--------------------------------------------------------------------------------------------------------------------------*/
ERROR_HANDLING
{
/* Print error message */
TB640_ISDN_LOG (TRACE_LEVEL_ALWAYS, "%s (Result = 0x%08X, %s, line %d)\n", TBX_ERROR_DESCRIPTION, TBX_ERROR_RESULT, __FILE__, TBX_ERROR_LINE);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Cleanup section
*--------------------------------------------------------------------------------------------------------------------------*/
CLEANUP
{
}
RETURN;
}
/*-------------------------------------------------------------------------------------------------------------------------------
| CTbus resource resync functions
*------------------------------------------------------------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------------------------------------------------------------
|
| TB640IsdnAdapterCtbusQueryInfo: This function is called by the automatic query function to gather the list, params and
| states of all ctbus resources. This function allocates and formats proper messaging
|
| in_pvAppContext : User-defined context
| in_un32UserContext: User context (not used)
| in_QueryType : Query type (list, get params or get states)
| in_hEntity : Handle of the trunk in case of "get params" or "get states"
| out_phMsg : Pointer to a variable that will hold the allocated message
|
| Note : ~
|
| Return : TBX_RESULT_OK
| TBX_RESULT_FAIL
|
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT TB640IsdnAdapterCtbusQueryInfo (
IN PTBX_VOID in_pvAppContext,
IN TBX_UINT32 in_un32UserContext,
IN TB640_ISDN_QUERY_TYPE in_QueryType,
IN TBX_UINT32 in_hEntity,
OUT PTBX_MSG_HANDLE out_phMsg)
{
TBX_UINT32 un32AdapterIdx;
TBX_UINT32 un32OpLibIdx;
TBX_UINT32 un32MsgSize;
TBX_UINT32 un32MsgId;
TBX_RESULT result;
TBX_MSG_HANDLE hMsg;
PTB640_ISDN_ADAPTER_INFO pAdapterInfo;
PTB640_MSG_CTBUS_RES_GET_LIST pGetListMsg;
PTB640_MSG_CTBUS_RES_GET_PARAMS pGetParamsMsg;
TB640_RESOURCE_HANDLE hCtbusRes = (TB640_RESOURCE_HANDLE)in_hEntity;
/*---------------------------------------------------------------------------------------------------------------------------
| Code section
*--------------------------------------------------------------------------------------------------------------------------*/
CODE
{
/* Initialize local variables */
/* Retrieve the adapter index and operation lib index */
TB640_ISDN_RETRIEVE_APP_CONTEXT (in_pvAppContext, un32AdapterIdx, un32OpLibIdx);
pAdapterInfo = &(g_AppContext->ahAdapterInfo [un32AdapterIdx]);
/* Find which message to send */
switch (in_QueryType)
{
case TB640_ISDN_QUERY_TYPE_LIST:
un32MsgSize = sizeof(*pGetListMsg); un32MsgId = TB640_MSG_ID_CTBUS_RES_GET_LIST; break;
case TB640_ISDN_QUERY_TYPE_PARAMS:
un32MsgSize = sizeof(*pGetParamsMsg); un32MsgId = TB640_MSG_ID_CTBUS_RES_GET_PARAMS; break;
case TB640_ISDN_QUERY_TYPE_STATES:
un32MsgSize = 0; un32MsgId = 0; break;
default:
TBX_EXIT_ERROR (TBX_RESULT_INVALID_PA
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -