/* Adds a new Connection to the Server Session Context */ phnpSnep_Fri_ServerConnection_t *phnpSnep_Fri_ContextMgmt_AddServerConnection( phnpSnep_Fri_DataParams_t *pDataParams, ph_NfcHandle ServerHandle) { uint8_t count=0; phnpSnep_Fri_ServerConnection_t *pConnection = NULL; phnpSnep_Fri_ServerSession_t *pServerConnContext = NULL; pServerConnContext = phnpSnep_Fri_ContextMgmt_GetServerSessionContext( pDataParams, ServerHandle); if ((NULL != pServerConnContext ) && ( PHNPSNEP_FRI_MAX_SNEP_SERVER_CONN > pServerConnContext->CurrentConnCnt)) { for (count = 0;count < PHNPSNEP_FRI_MAX_SNEP_SERVER_CONN;count++) { if (NULL != pServerConnContext->pServerConnection[count]) { pServerConnContext->CurrentConnCnt++; pConnection = pServerConnContext->pServerConnection[count]; pConnection->pSnepDataParamsContext = pDataParams; /* To access the pDataParams in the callback function */ break; }/* No Else */ } }/* No Else */ return pConnection; }
/* Removes all Connections from a Server Session Context */ phStatus_t phnpSnep_Fri_ContextMgmt_RemoveAllServerConnections( phnpSnep_Fri_DataParams_t *pDataParams, ph_NfcHandle ServerHandle) { phStatus_t status = PH_ERR_NOT_REGISTERED; uint8_t count=0; phnpSnep_Fri_ServerSession_t *pServerSession = NULL; pServerSession = phnpSnep_Fri_ContextMgmt_GetServerSessionContext( pDataParams, ServerHandle ); if ((NULL != pServerSession) && (0 != pServerSession->CurrentConnCnt)) { for (count = 0;count < PHNPSNEP_FRI_MAX_SNEP_SERVER_CONN;count++) { if (NULL != pServerSession->pServerConnection[count]) { status = PH_ERR_SUCCESS; pServerSession->CurrentConnCnt--; }/* No Else */ } } else { status = PH_ERR_INVALID_PARAMETER; } return status; }
phStatus_t phnpSnep_Fri_Server_Accept( phnpSnep_Fri_DataParams_t *pDataParams, phNfc_sData_t *pDataInbox, phlnLlcp_Fri_Transport_sSocketOptions_t *pSockOps, ph_NfcHandle ServerHandle, ph_NfcHandle ConnHandle, pphnpSnep_Fri_Put_ntf_t pPutNtfCb, pphnpSnep_Fri_Get_ntf_t pGetNtfCb, void *pContext ) { phStatus_t status; phnpSnep_Fri_ServerConnection_t *pServerConn = NULL; phnpSnep_Fri_ServerSession_t *pServerSession = NULL; if (NULL == pDataInbox || NULL == pSockOps || PHNPSNEP_FRI_MIN_MIU_VAL > pSockOps->miu) { return PH_ERR_INVALID_PARAMETER; } pServerConn = (phnpSnep_Fri_ServerConnection_t *) phnpSnep_Fri_ContextMgmt_AddServerConnection( pDataParams, ServerHandle); pServerSession = phnpSnep_Fri_ContextMgmt_GetServerSessionContext( pDataParams, ServerHandle); if (NULL != pServerConn) { if( pDataInbox->buffer != NULL ) { pServerConn->iInboxSize = pDataInbox->length; if( phnpSnep_Fri_Server_Default == pServerSession->SnepServerType && PHNPSNEP_FRI_MIN_INBOX_SIZE > pServerConn->iInboxSize) { return PH_ERR_INVALID_PARAMETER; } } else { return PH_ERR_INVALID_PARAMETER; } pServerConn->hSnepServerConnHandle = ConnHandle; pServerConn->pDataInbox = pDataInbox; pServerConn->pPutNtfCb = pPutNtfCb; pServerConn->pGetNtfCb = pGetNtfCb; pServerConn->pConnectionContext = pContext; if( pDataInbox != NULL ) { pServerConn->iInboxSize = pDataInbox->length; } pServerConn->iMiu = pSockOps->miu; pServerConn->ServerConnectionState = phnpSnep_Fri_Server_Uninitialized; pServerConn->SnepServerVersion = PHNPSNEP_FRI_VERSION; if (NULL != pServerConn->responseDataContext.pChunkingBuffer) { if (NULL != pServerConn->responseDataContext.pChunkingBuffer->buffer) { pServerConn->responseDataContext.pChunkingBuffer->length = pSockOps->miu; } else { return PH_ERR_INSUFFICIENT_RESOURCES; } } else { return PH_ERR_INSUFFICIENT_RESOURCES; } if (NULL != pServerConn->pConnWorkingBuffer->buffer) { status = phlnLlcp_Transport_Accept( pDataParams->plnLlcpDataParams, (phlnLlcp_Fri_Transport_Socket_t *)ConnHandle, pSockOps, pServerConn->pConnWorkingBuffer, &phnpSnep_Fri_Llcp_AcceptSocketErr_Cb, &phnpSnep_Fri_Llcp_AcceptSocket_Cb, (void*)pServerConn); } else { status = PH_ERR_INSUFFICIENT_RESOURCES; } } else { status = PH_ERR_INSUFFICIENT_RESOURCES; } return status; }