ANSC_STATUS
BbhmDiagipOpen
    (
        ANSC_HANDLE                 hThisObject
    )
{
    ANSC_STATUS                     returnStatus = ANSC_STATUS_SUCCESS;
    PBBHM_DIAG_IP_PING_OBJECT       pMyObject    = (PBBHM_DIAG_IP_PING_OBJECT       )hThisObject;
    PBBHM_IP_PING_PROPERTY          pProperty    = (PBBHM_IP_PING_PROPERTY          )&pMyObject->Property;
    PBBHM_IP_PING_TDO_OBJECT        pStateTimer  = (PBBHM_IP_PING_TDO_OBJECT        )pMyObject->hStateTimer;
    PBBHM_IP_PING_SINK_OBJECT       pSink        = NULL;
    PANSC_XSOCKET_OBJECT            pSocket      = NULL;
    ULONG                           i            = 0;

    if ( pMyObject->bActive )
    {
        return  ANSC_STATUS_SUCCESS;
    }

    if ( pProperty->Status == BBHM_IP_PING_STATUS_RUNNING )
    {
        return  ANSC_STATUS_FAILURE;
    }

    pSink = (PBBHM_IP_PING_SINK_OBJECT)BbhmDiagipSinkCreate((ANSC_HANDLE)pMyObject);

    if ( !pSink )
    {
        return  ANSC_STATUS_FAILURE;
    }

    pSocket =
        (PANSC_XSOCKET_OBJECT)AnscCreateXsocket
            (
                pMyObject->hContainerContext,
                (ANSC_HANDLE)pMyObject,
                (ANSC_HANDLE)NULL
            );

    if ( !pSocket )
    {
        pSink->Remove((ANSC_HANDLE)pSink);

        return  ANSC_STATUS_FAILURE;
    }
    else
    {
        pSink->SetXsocket((ANSC_HANDLE)pSink, (ANSC_HANDLE)pSocket);
    }

    pMyObject->hSinkObject    = pSink;

    pMyObject->ResetPropertyCounter((ANSC_HANDLE)pMyObject);

    pMyObject->bActive = TRUE;

    return  returnStatus;

}
ANSC_STATUS
BbhmDiagipClose
    (
        ANSC_HANDLE                 hThisObject
    )
{
    ANSC_STATUS                     returnStatus = ANSC_STATUS_SUCCESS;
    PBBHM_DIAG_IP_PING_OBJECT       pMyObject    = (PBBHM_DIAG_IP_PING_OBJECT     )hThisObject;
    PBBHM_IP_PING_PROPERTY          pProperty    = (PBBHM_IP_PING_PROPERTY        )&pMyObject->Property;
    PBBHM_IP_PING_TDO_OBJECT        pStateTimer  = (PBBHM_IP_PING_TDO_OBJECT      )pMyObject->hStateTimer;
    PBBHM_IP_PING_SINK_OBJECT       pSink        = (PBBHM_IP_PING_SINK_OBJECT     )pMyObject->hSinkObject;
    PSINGLE_LINK_ENTRY              pSLinkEntry  = NULL;
    PBBHM_IP_PING_ECHO_ENTRY        pEchoEntry   = NULL;
    ULONG                           i            = 0;

    if ( !pMyObject->bActive )
    {
        return  ANSC_STATUS_SUCCESS;
    }

    if ( pSink )
    {
        pSink->Detach((ANSC_HANDLE)pSink);
        pSink->Remove((ANSC_HANDLE)pSink);
        pMyObject->hSinkObject = NULL;
    }

    AnscAcquireLock(&pMyObject->EchoTableLock);

    for ( i = 0; i < MAX_ECHO_TABLE_SIZE; i ++ )
    {
        pSLinkEntry = AnscSListPopEntry(&pMyObject->EchoTable[i]);

        while ( pSLinkEntry )
        {
            pEchoEntry  = ACCESS_BBHM_IP_PING_ECHO_ENTRY(pSLinkEntry);
            pSLinkEntry = AnscSListPopEntry(&pMyObject->EchoTable[i]);

            AnscFreeMemory(pEchoEntry);
        }
    }

    AnscReleaseLock(&pMyObject->EchoTableLock);

    pMyObject->bActive = FALSE;

    return  returnStatus;
}