Пример #1
0
/* Retreives a Server Session matching the given Handle */
phnpSnep_Fri_ServerSession_t *phnpSnep_Fri_ContextMgmt_GetServerSessionByConnection( phnpSnep_Fri_DataParams_t  *pDataParams,
                                                                                    ph_NfcHandle                 ConnHandle)
{
    uint8_t count_srv=0, count_con=0;
    phnpSnep_Fri_ServerSession_t   *pServerSession = NULL;
    phnpSnep_Fri_ServerContext_t   *pServerContext = NULL;

    pServerContext = phnpSnep_Fri_ContextMgmt_GetServerContext( pDataParams );

    if ((NULL != pServerContext) && (0 != pServerContext->CurrentServerCnt))
    {
        for (count_srv = 0; count_srv < PHNPSNEP_FRI_MAX_SNEP_SERVER_CNT; count_srv++)
        {
            pServerSession = pServerContext->pServerSession[count_srv];

            if ((NULL != pServerSession) && (0 != pServerSession->CurrentConnCnt))
            {
                for (count_con = 0; count_con < PHNPSNEP_FRI_MAX_SNEP_SERVER_CONN; count_con++)
                {
                    if (NULL != pServerSession->pServerConnection[count_con])
                    {
                        if (ConnHandle == pServerSession->pServerConnection[count_con]->hSnepServerConnHandle)
                        {
                            return pServerSession;
                        } /* No Else */
                    } /* No Else */
                }
            } /* No Else */
        }
    } /* No Else */

    return pServerSession;
}
Пример #2
0
/* Retrieves a Server Session matching the given Handle */
phnpSnep_Fri_ServerSession_t *phnpSnep_Fri_ContextMgmt_GetServerSessionContext( phnpSnep_Fri_DataParams_t   *pDataParams,
                                                                               ph_NfcHandle                  ServerHandle)
{
    uint8_t   count;
    phnpSnep_Fri_ServerSession_t   *pSession = NULL;
    phnpSnep_Fri_ServerContext_t   *pServerContext = NULL;

    pServerContext = phnpSnep_Fri_ContextMgmt_GetServerContext( pDataParams );

    if ((NULL != pServerContext) && (0 != pServerContext->CurrentServerCnt))
    {
        for (count = 0; count < PHNPSNEP_FRI_MAX_SNEP_SERVER_CNT; count++)
        {
            if (NULL != pServerContext->pServerSession[count])
            {
                if (ServerHandle == pServerContext->pServerSession[count]->hSnepServerHandle)
                {
                    pSession = pServerContext->pServerSession[count];
                    break;
                } /* No Else */
            } /* No Else */
        }
    }/* No Else */

    return pSession;
}
Пример #3
0
/* Removes a Connection from the Server Session Context */
phStatus_t phnpSnep_Fri_ContextMgmt_RemoveOneServerConnection( phnpSnep_Fri_DataParams_t   *pDataParams,
                                                              ph_NfcHandle                  ConnHandle)
{

    phStatus_t  status = PH_ERR_NOT_REGISTERED;
    uint8_t     count_srv=0, count_con=0;
    phnpSnep_Fri_ServerConnection_t     *pConnection = NULL;
    phnpSnep_Fri_ServerSession_t        *pServerSession = NULL;
    phnpSnep_Fri_ServerContext_t        *pServerContext = NULL;

    pServerContext = phnpSnep_Fri_ContextMgmt_GetServerContext( pDataParams );

    if ((NULL != pServerContext) && (0 != pServerContext->CurrentServerCnt))
    {
        for (count_srv = 0; count_srv < PHNPSNEP_FRI_MAX_SNEP_SERVER_CNT; count_srv++)
        {
            pServerSession = pServerContext->pServerSession[count_srv];
            if ((NULL != pServerSession) &&
                (0 != pServerSession->CurrentConnCnt))
            {
                for (count_con = 0; count_con < PHNPSNEP_FRI_MAX_SNEP_SERVER_CONN; count_con++)
                {
                    if (NULL != pServerSession->pServerConnection[count_con])
                    {
                        if (ConnHandle == pServerSession->pServerConnection[count_con]->hSnepServerConnHandle)
                        {
                            status = PH_ERR_SUCCESS;
                            pServerSession->CurrentConnCnt--;
                            break;
                        } /* No Else */
                    } /* No Else */
                }
            } /* No Else */
            if (NULL != pConnection)
            {
                break;
            } /* No Else */
        }
    }
    else
    {
        status = PH_ERR_INVALID_PARAMETER;
    }

    return status;
}
Пример #4
0
phStatus_t phnpSnep_Fri_Server_DeInit( phnpSnep_Fri_DataParams_t    *pDataParams,
                                       ph_NfcHandle                  ServerHandle )
{

    phStatus_t    status = PH_ERR_SUCCESS;
    phnpSnep_Fri_ServerContext_t    *pServerContext = NULL;

    /* Context should not be allocated if already NULL */
    pServerContext = phnpSnep_Fri_ContextMgmt_GetServerContext( pDataParams );

    if (NULL != pServerContext)
    {
        status=phnpSnep_Fri_ContextMgmt_RemoveServerSession( pDataParams,
                                                             ServerHandle );
    }
    else
    {
        status = PH_ERR_NOT_INITIALISED;
    }
    return status;
}
Пример #5
0
/* Adds a new Server to the Server Context If returns NULL add session failed */
phnpSnep_Fri_ServerSession_t *phnpSnep_Fri_ContextMgmt_AddServerSession( phnpSnep_Fri_DataParams_t      *pDataParams,
                                                                        phnpSnep_Fri_ServerSession_t    *pServerSession )
{
    uint8_t        count =0;
    phnpSnep_Fri_ServerContext_t     *pServerContext = NULL;

    pServerContext = phnpSnep_Fri_ContextMgmt_GetServerContext( pDataParams );

    if ((NULL != pServerContext) && (PHNPSNEP_FRI_MAX_SNEP_SERVER_CNT > pServerContext->CurrentServerCnt))
    {
        for (count = 0;count < PHNPSNEP_FRI_MAX_SNEP_SERVER_CNT;count++)
        {
            if (NULL != pServerSession)
            {
                pServerContext->pServerSession[count] = pServerSession;
                pServerContext->CurrentServerCnt++;
                break;
            }/* No Else */
        }
    }/* No Else */
    return pServerContext->pServerSession[count];
}
Пример #6
0
/* Removes a Server from the Server Context */
phStatus_t phnpSnep_Fri_ContextMgmt_RemoveServerSession( phnpSnep_Fri_DataParams_t    *pDataParams,
                                                        ph_NfcHandle                   ServerHandle)
{

    phStatus_t   status = PH_ERR_FAILED;
    uint8_t      count=0;
    phnpSnep_Fri_ServerContext_t   *pServerContext = NULL;

    pServerContext = phnpSnep_Fri_ContextMgmt_GetServerContext( pDataParams );

    if (NULL != pServerContext)
    {
        for (count = 0; count < PHNPSNEP_FRI_MAX_SNEP_SERVER_CNT; count++)
        {
            if (NULL != pServerContext->pServerSession[count])
            {
                if (ServerHandle == pServerContext->pServerSession[count]->hSnepServerHandle)
                {
                    if (0 != pServerContext->pServerSession[count]->CurrentConnCnt)
                    {
                        status = phnpSnep_Fri_ContextMgmt_RemoveAllServerConnections( pDataParams,
                                                                                       ServerHandle);
                    }
                    else
                    {
                        status = PH_ERR_SUCCESS;
                    }
                    status = PH_ERR_SUCCESS;
                    pServerContext->CurrentServerCnt--;

                    break;
                } /* No Else */
            } /* No Else */
        }
    }/* No Else */
    return status;
}
Пример #7
0
phStatus_t phnpSnep_Fri_Server_Init( phnpSnep_Fri_DataParams_t     *pDataParams,
                                    phnpSnep_Fri_Config_t          *pConfigInfo,
                                    pphnpSnep_Fri_ConnectCB_t       pConnCb,
                                    ph_NfcHandle                   *pServerHandle,
                                    phnpSnep_Fri_ServerSession_t   *pServer,
                                    void                           *pContext)
{

    phStatus_t                      status;
    phNfc_sData_t                   ServerName = { gphnpSnep_Fri_Snep_DefaultServerName, PHNPSNEP_FRI_DEFAULT_SERVER_NAME_LEN };
    phnpSnep_Fri_ServerSession_t   *pServerSession = NULL;
    phnpSnep_Fri_ServerContext_t   *pServerContext = NULL;

    PH_ASSERT_NULL(pServerSession);

    if (NULL == pConfigInfo ||
        NULL == pConnCb ||
        NULL == pServerHandle ||
        PHNPSNEP_FRI_MIN_MIU_VAL > pConfigInfo->sOptions.miu)
    {
        return PH_ERR_INVALID_PARAMETER;
    }

    pServerContext = phnpSnep_Fri_ContextMgmt_GetServerContext( pDataParams );

    if (NULL != pServerContext)
    {
        pServerSession = phnpSnep_Fri_ContextMgmt_AddServerSession( pDataParams,
                                                                    pServer );

        if (NULL != pServerSession)
        {
            if (NULL != pServerSession->pWorkingBuffer->buffer)
            {
                /*Create LLCP Socket*/
                status = phlnLlcp_Transport_Socket( pDataParams->plnLlcpDataParams,
                                                    phlnLlcp_Fri_Transport_eConnectionOriented,
                                                    &pConfigInfo->sOptions,
                                                    pServerSession->pWorkingBuffer,
                                                   (phlnLlcp_Fri_Transport_Socket_t **) &pServerSession->hSnepServerHandle,
                                                    &phnpSnep_Fri_Llcp_SocketErr_Cb,
                                                    (void *)pServerSession
                                                   );
            }
            else
            {
                status = PH_ERR_INSUFFICIENT_RESOURCES;
            }
        }
        else
        {
            status = PH_ERR_INSUFFICIENT_RESOURCES;
        }
    }
    else
    {
        status = PH_ERR_INSUFFICIENT_RESOURCES;
    }

    if (PH_ERR_SUCCESS == status)
    {
        if (phnpSnep_Fri_Server_Default == pConfigInfo->SnepServerType)
        {
            pServerSession->SnepServerSap = PHNPSNEP_FRI_DEFAULT_SERVER_SAP;
            /* Bind Socket */
            status = phlnLlcp_Transport_Bind( pDataParams->plnLlcpDataParams,
                                              (phlnLlcp_Fri_Transport_Socket_t *) pServerSession->hSnepServerHandle,
                                              pServerSession->SnepServerSap,
                                              &ServerName
                                            );
        }
        else
        {
            /*@TODO Server sap should be dynamically selected for non default server
            * Currently there is a limitation of one default and one non default server */
            pServerSession->SnepServerSap = PHNPSNEP_FRI_NON_DEFAULT_SERVER_SAP;
            /* Bind Socket */
            status = phlnLlcp_Transport_Bind( pDataParams->plnLlcpDataParams,
                                              (phlnLlcp_Fri_Transport_Socket_t *) pServerSession->hSnepServerHandle,
                                              pServerSession->SnepServerSap,
                                              pConfigInfo->SnepServerName
                                            );
        }
    }

    if (PH_ERR_SUCCESS == status)
    {
        if ( phnpSnep_Fri_Server_Default == pConfigInfo->SnepServerType &&
            NULL == pConfigInfo->SnepServerName)
        {
            status = phlnLlcp_Transport_Listen( pDataParams->plnLlcpDataParams,
                                                (phlnLlcp_Fri_Transport_Socket_t *) pServerSession->hSnepServerHandle,
                                               (phlnLlcp_Fri_TransportSocketListenCb_t) &phnpSnep_Fri_Llcp_ListenSocket_Cb,
                                                (void*)pServerSession
                                              );

            pServerSession->SnepServerType = phnpSnep_Fri_Server_Default;
        }
        else if ( phnpSnep_Fri_Server_NonDefault == pConfigInfo->SnepServerType &&
            NULL != pConfigInfo->SnepServerName)
        {
            status = phlnLlcp_Transport_Listen( pDataParams->plnLlcpDataParams,
                                                (phlnLlcp_Fri_Transport_Socket_t *) pServerSession->hSnepServerHandle,
                                               (phlnLlcp_Fri_TransportSocketListenCb_t) &phnpSnep_Fri_Llcp_ListenSocket_Cb,
                                                (void*)pServerSession
                                               );
            pServerSession->SnepServerType = phnpSnep_Fri_Server_NonDefault;
        }
        else
        {
            status = PH_ERR_INVALID_PARAMETER;
        }

        if (PH_ERR_SUCCESS == status)
        {
            pServerSession->pConnectionCb = pConnCb;
            pServerSession->Server_state = phnpSnep_Fri_Server_Initialized;
            *pServerHandle = pServerSession->hSnepServerHandle;
            pServerSession->pListenContext = pContext;
            pServerSession->SnepServerVersion =PHNPSNEP_FRI_VERSION;
        }
    }
    else
    {
        /*@TODO Deallocate the Server Session and Server Context */
    }

    return status;
}