15d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/* 25d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * Copyright (C) 2010 NXP Semiconductors 35d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * 45d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * Licensed under the Apache License, Version 2.0 (the "License"); 55d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * you may not use this file except in compliance with the License. 65d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * You may obtain a copy of the License at 75d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * 85d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * http://www.apache.org/licenses/LICENSE-2.0 95d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * 105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * Unless required by applicable law or agreed to in writing, software 115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * distributed under the License is distributed on an "AS IS" BASIS, 125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * See the License for the specific language governing permissions and 145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * limitations under the License. 155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */ 165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/** 185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \file phFriNfc_LlcpTransport_Connection.c 195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \brief 205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * 215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * Project: NFC-FRI 225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * 235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */ 245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*include files*/ 257c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen#define LOG_TAG "NFC" 267c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen#include <cutils/log.h> 27cf5cd1520ea32d2b65712a36a105f396df07345cSylvain Fonteneau#include <phOsalNfc.h> 285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phLibNfcStatus.h> 295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phLibNfc.h> 305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phNfcLlcpTypes.h> 315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phFriNfc_LlcpTransport.h> 325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phFriNfc_LlcpTransport_Connection.h> 335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phFriNfc_Llcp.h> 345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phFriNfc_LlcpUtils.h> 355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/* Function definition */ 375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic NFCSTATUS phFriNfc_Llcp_Send_ReceiveReady_Frame(phFriNfc_LlcpTransport_Socket_t* pLlcpSocket); 385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic NFCSTATUS phFriNfc_Llcp_Send_ReceiveNotReady_Frame(phFriNfc_LlcpTransport_Socket_t* pLlcpSocket); 395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 4060d8ea84bfbf2dabd0e851edd812f89d42043c1aSylvain Fonteneaustatic NFCSTATUS static_performSendInfo(phFriNfc_LlcpTransport_Socket_t * psLlcpSocket); 415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/********** End Function definition ***********/ 425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/* TODO: comment functionphFriNfc_LlcpTransport_ConnectionOriented_SendLlcp_CB */ 445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic void phFriNfc_LlcpTransport_ConnectionOriented_SendLlcp_CB(void* pContext, 457c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen uint8_t socketIndex, 465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS status) 475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phFriNfc_LlcpTransport_t *psTransport; 495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phFriNfc_LlcpTransport_Socket_t psTempLlcpSocket; 505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phFriNfc_LlcpTransport_Socket_t *psLocalLlcpSocket = NULL; 515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phNfc_sData_t sFrmrBuffer; 525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t index; 535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t socketFound = FALSE; 54fb709589632b4962b88113346316ec53a574258bSylvain Fonteneau NFCSTATUS result; 555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Get Send CB context */ 565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psTransport = (phFriNfc_LlcpTransport_t*)pContext; 575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(status == NFCSTATUS_SUCCESS) 595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test the socket */ 617c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen switch(psTransport->pSocketTable[socketIndex].eSocket_State) 625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case phFriNfc_LlcpTransportSocket_eSocketAccepted: 645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Set socket state to Connected */ 667c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen psTransport->pSocketTable[socketIndex].eSocket_State = phFriNfc_LlcpTransportSocket_eSocketConnected; 675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Call the Accept Callback */ 687c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen psTransport->pSocketTable[socketIndex].pfSocketAccept_Cb(psTransport->pSocketTable[socketIndex].pAcceptContext,status); 697c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen psTransport->pSocketTable[socketIndex].pfSocketAccept_Cb = NULL; 707c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen psTransport->pSocketTable[socketIndex].pAcceptContext = NULL; 715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly }break; 725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case phFriNfc_LlcpTransportSocket_eSocketRejected: 745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Store the Llcp socket in a local Llcp socket */ 767c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen psTempLlcpSocket = psTransport->pSocketTable[socketIndex]; 775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Reset the socket and set the socket state to default */ 797c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen result = phFriNfc_LlcpTransport_Close(&psTransport->pSocketTable[socketIndex]); 805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Call the Reject Callback */ 825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psTempLlcpSocket.pfSocketSend_Cb(psTempLlcpSocket.pRejectContext,status); 83b2c5ac1e2d4dda413c4b3a66dc8a186e1dc5f6c4Sylvain Fonteneau psTempLlcpSocket.pfSocketSend_Cb = NULL; 845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly }break; 855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case phFriNfc_LlcpTransportSocket_eSocketConnected: 875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 887c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen if(!psTransport->pSocketTable[socketIndex].bSocketSendPending && psTransport->pSocketTable[socketIndex].pfSocketSend_Cb != NULL) 895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 907c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen psTransport->pSocketTable[socketIndex].pfSocketSend_Cb(psTransport->pSocketTable[socketIndex].pSendContext,status); 917c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen psTransport->pSocketTable[socketIndex].pfSocketSend_Cb = NULL; 925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly }break; 94955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi default: 95955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi /* Nothing to do */ 96955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi break; 975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 98955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi } 99955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi else 100955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi { 101955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi /* Send CB error */ 1027c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen if(!psTransport->pSocketTable[socketIndex].bSocketSendPending && psTransport->pSocketTable[socketIndex].pfSocketSend_Cb != NULL) 1035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 1047c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen psTransport->pSocketTable[socketIndex].pfSocketSend_Cb(psTransport->pSocketTable[socketIndex].pSendContext,status); 1057c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen psTransport->pSocketTable[socketIndex].pfSocketSend_Cb = NULL; 106955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi } 107955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi } 108955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi} 1095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 1105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 111955a8efe369ece977e4757f0ae37b3931169125bSunil JogiNFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_HandlePendingOperations(phFriNfc_LlcpTransport_Socket_t *pSocket) 112955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi{ 113955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi NFCSTATUS result = NFCSTATUS_FAILED; 114955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi phFriNfc_LlcpTransport_t *psTransport = pSocket->psTransport; 115955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi /* I FRAME */ 116955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi if(pSocket->bSocketSendPending == TRUE) 117955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi { 118955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi /* Test the RW window */ 119955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi if(CHECK_SEND_RW(pSocket)) 1205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 1217c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen if (!testAndSetSendPending(psTransport)) { 1227c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen result = static_performSendInfo(pSocket); 1237c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen if (result != NFCSTATUS_SUCCESS && result != NFCSTATUS_PENDING) { 1247c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen clearSendPending(psTransport); 1257c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen } 1267c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen } 127955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi } 128955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi } 129955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi /* RR FRAME */ 130955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi else if(pSocket->bSocketRRPending == TRUE) 131955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi { 132955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi /* Reset RR pending */ 133955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi pSocket->bSocketRRPending = FALSE; 1345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 135955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi /* Send RR Frame */ 136955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi result = phFriNfc_Llcp_Send_ReceiveReady_Frame(pSocket); 137955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi } 138955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi /* RNR Frame */ 139955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi else if(pSocket->bSocketRNRPending == TRUE) 140955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi { 141955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi /* Reset RNR pending */ 142955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi pSocket->bSocketRNRPending = FALSE; 1435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 144955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi /* Send RNR Frame */ 145955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi result = phFriNfc_Llcp_Send_ReceiveNotReady_Frame(pSocket); 146955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi } 147955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi /* CC Frame */ 148955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi else if(pSocket->bSocketAcceptPending == TRUE) 149955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi { 1507c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen if (!testAndSetSendPending(psTransport)) 1517c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen { 1527c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen /* Reset Accept pending */ 1537c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen pSocket->bSocketAcceptPending = FALSE; 1545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 1557c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen /* Fill the psLlcpHeader stuture with the DSAP,CC PTYPE and the SSAP */ 1567c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen pSocket->sLlcpHeader.dsap = pSocket->socket_dSap; 1577c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen pSocket->sLlcpHeader.ptype = PHFRINFC_LLCP_PTYPE_CC; 1587c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen pSocket->sLlcpHeader.ssap = pSocket->socket_sSap; 1595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 1607c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen /* Set the socket state to accepted */ 1617c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen pSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketAccepted; 1625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 1637c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen /* Send a CC Frame */ 1647c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen result = phFriNfc_LlcpTransport_LinkSend(psTransport, 165955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi &pSocket->sLlcpHeader, 166955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi NULL, 167955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi &pSocket->sSocketSendBuffer, 168955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi phFriNfc_LlcpTransport_ConnectionOriented_SendLlcp_CB, 1697c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen pSocket->index, 170955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi psTransport); 1717c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen 1727c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen if (result != NFCSTATUS_SUCCESS && result != NFCSTATUS_PENDING) { 1737c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen clearSendPending(psTransport); 1747c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen } 1757c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen } 176955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi } 177955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi /* CONNECT FRAME */ 178955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi else if(pSocket->bSocketConnectPending == TRUE) 179955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi { 1807c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen if (!testAndSetSendPending(psTransport)) 1817c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen { 1827c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen /* Reset Accept pending */ 1837c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen pSocket->bSocketConnectPending = FALSE; 1845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 1857c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen /* Set the socket in connecting state */ 1867c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen pSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketConnecting; 1875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 1887c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen /* send CONNECT */ 1897c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen result = phFriNfc_LlcpTransport_LinkSend(psTransport, 190955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi &pSocket->sLlcpHeader, 191955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi NULL, 192955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi &pSocket->sSocketSendBuffer, 193955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi phFriNfc_LlcpTransport_ConnectionOriented_SendLlcp_CB, 1947c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen pSocket->index, 195955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi psTransport); 1967c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen 1977c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen if (result != NFCSTATUS_SUCCESS && result != NFCSTATUS_PENDING) { 1987c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen clearSendPending(psTransport); 1997c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen } 2007c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen } 2015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 202955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi /* DISC FRAME */ 203955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi else if(pSocket->bSocketDiscPending == TRUE) 2045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 2057c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen if (!testAndSetSendPending(psTransport)) 2067c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen { 2077c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen /* Reset Disc Pending */ 2087c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen pSocket->bSocketDiscPending = FALSE; 209955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi 2107c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen /* Set the socket in connecting state */ 2117c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen pSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketDisconnecting; 212955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi 2137c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen /* Send DISC */ 2147c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen result = phFriNfc_LlcpTransport_LinkSend(psTransport, 215955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi &pSocket->sLlcpHeader, 216955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi NULL, 217955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi &pSocket->sSocketSendBuffer, 218955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi phFriNfc_LlcpTransport_ConnectionOriented_SendLlcp_CB, 2197c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen pSocket->index, 220955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi psTransport); 221955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi 2227c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen if (result != NFCSTATUS_SUCCESS && result != NFCSTATUS_PENDING) { 2237c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen clearSendPending(psTransport); 2247c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen } 2257c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen /* Call ErrCB due to a DISC */ 2267c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen pSocket->pSocketErrCb(pSocket->pContext, PHFRINFC_LLCP_ERR_DISCONNECTED); 2277c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen } 2285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 229955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi return result; 2305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 2315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 23260d8ea84bfbf2dabd0e851edd812f89d42043c1aSylvain Fonteneaustatic NFCSTATUS static_performSendInfo(phFriNfc_LlcpTransport_Socket_t * psLlcpSocket) 23360d8ea84bfbf2dabd0e851edd812f89d42043c1aSylvain Fonteneau{ 23460d8ea84bfbf2dabd0e851edd812f89d42043c1aSylvain Fonteneau phFriNfc_LlcpTransport_t *psTransport = psLlcpSocket->psTransport; 23560d8ea84bfbf2dabd0e851edd812f89d42043c1aSylvain Fonteneau NFCSTATUS status; 23660d8ea84bfbf2dabd0e851edd812f89d42043c1aSylvain Fonteneau 23760d8ea84bfbf2dabd0e851edd812f89d42043c1aSylvain Fonteneau /* Set the Header */ 23860d8ea84bfbf2dabd0e851edd812f89d42043c1aSylvain Fonteneau psLlcpSocket->sLlcpHeader.dsap = psLlcpSocket->socket_dSap; 23960d8ea84bfbf2dabd0e851edd812f89d42043c1aSylvain Fonteneau psLlcpSocket->sLlcpHeader.ptype = PHFRINFC_LLCP_PTYPE_I; 24060d8ea84bfbf2dabd0e851edd812f89d42043c1aSylvain Fonteneau psLlcpSocket->sLlcpHeader.ssap = psLlcpSocket->socket_sSap; 24160d8ea84bfbf2dabd0e851edd812f89d42043c1aSylvain Fonteneau 24260d8ea84bfbf2dabd0e851edd812f89d42043c1aSylvain Fonteneau /* Set Sequence Numbers */ 24360d8ea84bfbf2dabd0e851edd812f89d42043c1aSylvain Fonteneau psLlcpSocket->sSequence.ns = psLlcpSocket->socket_VS; 24460d8ea84bfbf2dabd0e851edd812f89d42043c1aSylvain Fonteneau psLlcpSocket->sSequence.nr = psLlcpSocket->socket_VR; 24560d8ea84bfbf2dabd0e851edd812f89d42043c1aSylvain Fonteneau 24660d8ea84bfbf2dabd0e851edd812f89d42043c1aSylvain Fonteneau /* Update the VRA */ 24760d8ea84bfbf2dabd0e851edd812f89d42043c1aSylvain Fonteneau psLlcpSocket->socket_VRA = psLlcpSocket->socket_VR; 24860d8ea84bfbf2dabd0e851edd812f89d42043c1aSylvain Fonteneau 24960d8ea84bfbf2dabd0e851edd812f89d42043c1aSylvain Fonteneau 25060d8ea84bfbf2dabd0e851edd812f89d42043c1aSylvain Fonteneau /* Send I_PDU */ 251955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi status = phFriNfc_LlcpTransport_LinkSend(psTransport, 25260d8ea84bfbf2dabd0e851edd812f89d42043c1aSylvain Fonteneau &psLlcpSocket->sLlcpHeader, 25360d8ea84bfbf2dabd0e851edd812f89d42043c1aSylvain Fonteneau &psLlcpSocket->sSequence, 25460d8ea84bfbf2dabd0e851edd812f89d42043c1aSylvain Fonteneau &psLlcpSocket->sSocketSendBuffer, 25560d8ea84bfbf2dabd0e851edd812f89d42043c1aSylvain Fonteneau phFriNfc_LlcpTransport_ConnectionOriented_SendLlcp_CB, 2567c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen psLlcpSocket->index, 257955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi psLlcpSocket->psTransport); 2587c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen if (status == NFCSTATUS_SUCCESS || status == NFCSTATUS_PENDING) { 2597c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen /* Update VS */ 2607c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen psLlcpSocket->socket_VS = (psLlcpSocket->socket_VS+1)%16; 26160d8ea84bfbf2dabd0e851edd812f89d42043c1aSylvain Fonteneau 2627c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen /* Reset Send Pending */ 2637c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen psLlcpSocket->bSocketSendPending = FALSE; 2647c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen } 265955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi 26660d8ea84bfbf2dabd0e851edd812f89d42043c1aSylvain Fonteneau return status; 26760d8ea84bfbf2dabd0e851edd812f89d42043c1aSylvain Fonteneau} 26860d8ea84bfbf2dabd0e851edd812f89d42043c1aSylvain Fonteneau 2691c75e8952d88d81c5f04826f69ca22d14bb5683bSylvain Fonteneaustatic void phFriNfc_LlcpTransport_ConnectionOriented_Abort(phFriNfc_LlcpTransport_Socket_t * pLlcpSocket) 2701c75e8952d88d81c5f04826f69ca22d14bb5683bSylvain Fonteneau{ 2711c75e8952d88d81c5f04826f69ca22d14bb5683bSylvain Fonteneau if (pLlcpSocket->pfSocketSend_Cb != NULL) 2721c75e8952d88d81c5f04826f69ca22d14bb5683bSylvain Fonteneau { 2731c75e8952d88d81c5f04826f69ca22d14bb5683bSylvain Fonteneau pLlcpSocket->pfSocketSend_Cb(pLlcpSocket->pSendContext, NFCSTATUS_ABORTED); 2741c75e8952d88d81c5f04826f69ca22d14bb5683bSylvain Fonteneau pLlcpSocket->pfSocketSend_Cb = NULL; 2751c75e8952d88d81c5f04826f69ca22d14bb5683bSylvain Fonteneau } 2761c75e8952d88d81c5f04826f69ca22d14bb5683bSylvain Fonteneau pLlcpSocket->pSendContext = NULL; 2771c75e8952d88d81c5f04826f69ca22d14bb5683bSylvain Fonteneau if (pLlcpSocket->pfSocketRecv_Cb != NULL) 2781c75e8952d88d81c5f04826f69ca22d14bb5683bSylvain Fonteneau { 2791c75e8952d88d81c5f04826f69ca22d14bb5683bSylvain Fonteneau pLlcpSocket->pfSocketRecv_Cb(pLlcpSocket->pRecvContext, NFCSTATUS_ABORTED); 2801c75e8952d88d81c5f04826f69ca22d14bb5683bSylvain Fonteneau pLlcpSocket->pfSocketRecv_Cb = NULL; 2811c75e8952d88d81c5f04826f69ca22d14bb5683bSylvain Fonteneau } 2821c75e8952d88d81c5f04826f69ca22d14bb5683bSylvain Fonteneau pLlcpSocket->pRecvContext = NULL; 2831c75e8952d88d81c5f04826f69ca22d14bb5683bSylvain Fonteneau if (pLlcpSocket->pfSocketAccept_Cb != NULL) 2841c75e8952d88d81c5f04826f69ca22d14bb5683bSylvain Fonteneau { 2851c75e8952d88d81c5f04826f69ca22d14bb5683bSylvain Fonteneau pLlcpSocket->pfSocketAccept_Cb(pLlcpSocket->pAcceptContext, NFCSTATUS_ABORTED); 2861c75e8952d88d81c5f04826f69ca22d14bb5683bSylvain Fonteneau pLlcpSocket->pfSocketAccept_Cb = NULL; 2871c75e8952d88d81c5f04826f69ca22d14bb5683bSylvain Fonteneau } 2881c75e8952d88d81c5f04826f69ca22d14bb5683bSylvain Fonteneau pLlcpSocket->pAcceptContext = NULL; 2891c75e8952d88d81c5f04826f69ca22d14bb5683bSylvain Fonteneau if (pLlcpSocket->pfSocketConnect_Cb != NULL) 2901c75e8952d88d81c5f04826f69ca22d14bb5683bSylvain Fonteneau { 2911c75e8952d88d81c5f04826f69ca22d14bb5683bSylvain Fonteneau pLlcpSocket->pfSocketConnect_Cb(pLlcpSocket->pConnectContext, 0, NFCSTATUS_ABORTED); 2921c75e8952d88d81c5f04826f69ca22d14bb5683bSylvain Fonteneau pLlcpSocket->pfSocketConnect_Cb = NULL; 2931c75e8952d88d81c5f04826f69ca22d14bb5683bSylvain Fonteneau } 2941c75e8952d88d81c5f04826f69ca22d14bb5683bSylvain Fonteneau pLlcpSocket->pConnectContext = NULL; 2951c75e8952d88d81c5f04826f69ca22d14bb5683bSylvain Fonteneau if (pLlcpSocket->pfSocketDisconnect_Cb != NULL) 2961c75e8952d88d81c5f04826f69ca22d14bb5683bSylvain Fonteneau { 297837efc3194a03beaaa32b370c63a9270ed9664d8Martijn Coenen pLlcpSocket->pfSocketDisconnect_Cb(pLlcpSocket->pDisconnectContext, NFCSTATUS_ABORTED); 2981c75e8952d88d81c5f04826f69ca22d14bb5683bSylvain Fonteneau pLlcpSocket->pfSocketDisconnect_Cb = NULL; 2991c75e8952d88d81c5f04826f69ca22d14bb5683bSylvain Fonteneau } 300837efc3194a03beaaa32b370c63a9270ed9664d8Martijn Coenen pLlcpSocket->pDisconnectContext = NULL; 3011c75e8952d88d81c5f04826f69ca22d14bb5683bSylvain Fonteneau 3021c75e8952d88d81c5f04826f69ca22d14bb5683bSylvain Fonteneau pLlcpSocket->pfSocketRecvFrom_Cb = NULL; 303f546a14a4509e1814bfd94fc76cdfa2252dc455cArnaud Ferir pLlcpSocket->pfSocketListen_Cb = NULL; 304f546a14a4509e1814bfd94fc76cdfa2252dc455cArnaud Ferir pLlcpSocket->pListenContext = NULL; 3051c75e8952d88d81c5f04826f69ca22d14bb5683bSylvain Fonteneau} 3061c75e8952d88d81c5f04826f69ca22d14bb5683bSylvain Fonteneau 3075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 3085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic NFCSTATUS phFriNfc_Llcp_Send_ReceiveReady_Frame(phFriNfc_LlcpTransport_Socket_t* pLlcpSocket) 3095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 3105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS status = NFCSTATUS_SUCCESS; 3115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 3125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test if a send is pending */ 3137c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen if(testAndSetSendPending(pLlcpSocket->psTransport)) 3145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 3155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->bSocketRRPending = TRUE; 3165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly status = NFCSTATUS_PENDING; 3175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 3185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 3195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 3205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Set the header of the RR frame */ 3215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->sLlcpHeader.dsap = pLlcpSocket->socket_dSap; 3225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->sLlcpHeader.ptype = PHFRINFC_LLCP_PTYPE_RR; 3235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->sLlcpHeader.ssap = pLlcpSocket->socket_sSap; 3245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 3255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Set sequence number for RR Frame */ 3265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->sSequence.ns = 0; 3275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->sSequence.nr = pLlcpSocket->socket_VR; 3285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 3295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Update VRA */ 3305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->socket_VRA = (uint8_t)pLlcpSocket->sSequence.nr; 3315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 3325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Send RR frame */ 333955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi status = phFriNfc_LlcpTransport_LinkSend(pLlcpSocket->psTransport, 3345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly &pLlcpSocket->sLlcpHeader, 3355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly &pLlcpSocket->sSequence, 3365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NULL, 3375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phFriNfc_LlcpTransport_ConnectionOriented_SendLlcp_CB, 3387c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen pLlcpSocket->index, 3395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->psTransport); 3407c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen if (status != NFCSTATUS_SUCCESS && status != NFCSTATUS_PENDING) { 3417c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen clearSendPending(pLlcpSocket->psTransport); 3427c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen } 3435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 3445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 3455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return status; 3465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 3475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 3485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic NFCSTATUS phFriNfc_Llcp_Send_ReceiveNotReady_Frame(phFriNfc_LlcpTransport_Socket_t* pLlcpSocket) 3495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 3505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS status = NFCSTATUS_SUCCESS; 3515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 3525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 3535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test if a send is pending */ 3547c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen if(testAndSetSendPending(pLlcpSocket->psTransport)) 3555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 3565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->bSocketRNRPending = TRUE; 3575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly status = NFCSTATUS_PENDING; 3585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 3595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 3605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 3615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Set the header of the RNR frame */ 3625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->sLlcpHeader.dsap = pLlcpSocket->socket_dSap; 3635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->sLlcpHeader.ptype = PHFRINFC_LLCP_PTYPE_RNR; 3645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->sLlcpHeader.ssap = pLlcpSocket->socket_sSap; 3655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 3665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Set sequence number for RNR Frame */ 3675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->sSequence.ns = 0x00; 3685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->sSequence.nr = pLlcpSocket->socket_VR; 3695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 3705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Update VRA */ 3715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->socket_VRA = (uint8_t)pLlcpSocket->sSequence.nr; 3725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 3735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Send RNR frame */ 374955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi status = phFriNfc_LlcpTransport_LinkSend(pLlcpSocket->psTransport, 3755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly &pLlcpSocket->sLlcpHeader, 3765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly &pLlcpSocket->sSequence, 3775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NULL, 3785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phFriNfc_LlcpTransport_ConnectionOriented_SendLlcp_CB, 3797c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen pLlcpSocket->index, 3805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->psTransport); 3817c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen if (status != NFCSTATUS_SUCCESS && status != NFCSTATUS_PENDING) { 3827c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen clearSendPending(pLlcpSocket->psTransport); 3837c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen } 3845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 3855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return status; 3865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 3875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 3885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic NFCSTATUS phFriNfc_Llcp_GetSocket_Params(phNfc_sData_t *psParamsTLV, 3895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phNfc_sData_t *psServiceName, 3905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t *pRemoteRW_Size, 3915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint16_t *pRemoteMIU) 3925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 3935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS status = NFCSTATUS_SUCCESS; 3945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phNfc_sData_t sValueBuffer; 3955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint32_t offset = 0; 3965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t type; 3975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 3985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Check for NULL pointers */ 3995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if ((psParamsTLV == NULL) || (pRemoteRW_Size == NULL) || (pRemoteMIU == NULL)) 4005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 4015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return PHNFCSTVAL(CID_FRI_NFC_LLCP, NFCSTATUS_INVALID_PARAMETER); 4025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 4035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 4045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 4055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Decode TLV */ 4065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly while (offset < psParamsTLV->length) 4075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 4085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly status = phFriNfc_Llcp_DecodeTLV(psParamsTLV, &offset, &type,&sValueBuffer); 4095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if (status != NFCSTATUS_SUCCESS) 4105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 4115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Error: Ill-formed TLV */ 4125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return status; 4135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 4145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly switch(type) 4155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 4165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case PHFRINFC_LLCP_TLV_TYPE_SN: 4175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 4185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test if a SN is present in the TLV */ 4195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(sValueBuffer.length == 0) 4205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 4215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Error : Ill-formed SN parameter TLV */ 42246dbed4e11700226e9b43ca17e5ad6f3d192bf63Sylvain Fonteneau break; 4235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 4245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Get the Service Name */ 4255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *psServiceName = sValueBuffer; 4265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly }break; 4275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 4285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case PHFRINFC_LLCP_TLV_TYPE_RW: 4295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 4305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Check length */ 4315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if (sValueBuffer.length != PHFRINFC_LLCP_TLV_LENGTH_RW) 4325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 4335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Error : Ill-formed MIUX parameter TLV */ 43446dbed4e11700226e9b43ca17e5ad6f3d192bf63Sylvain Fonteneau break; 4355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 4365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *pRemoteRW_Size = sValueBuffer.buffer[0]; 4375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly }break; 4385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 4395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case PHFRINFC_LLCP_TLV_TYPE_MIUX: 4405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 4415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Check length */ 4425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if (sValueBuffer.length != PHFRINFC_LLCP_TLV_LENGTH_MIUX) 4435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 4445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Error : Ill-formed MIUX parameter TLV */ 44546dbed4e11700226e9b43ca17e5ad6f3d192bf63Sylvain Fonteneau break; 4465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 4475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *pRemoteMIU = PHFRINFC_LLCP_MIU_DEFAULT + (((sValueBuffer.buffer[0] << 8) | sValueBuffer.buffer[1]) & PHFRINFC_LLCP_TLV_MIUX_MASK); 4485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly }break; 44946dbed4e11700226e9b43ca17e5ad6f3d192bf63Sylvain Fonteneau 45046dbed4e11700226e9b43ca17e5ad6f3d192bf63Sylvain Fonteneau default: 45146dbed4e11700226e9b43ca17e5ad6f3d192bf63Sylvain Fonteneau { 45246dbed4e11700226e9b43ca17e5ad6f3d192bf63Sylvain Fonteneau /* Error : Unknown type */ 45346dbed4e11700226e9b43ca17e5ad6f3d192bf63Sylvain Fonteneau break; 45446dbed4e11700226e9b43ca17e5ad6f3d192bf63Sylvain Fonteneau } 4555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 4565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 4575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 4585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return status; 4595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 4605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 4615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 4625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/* TODO: comment function Handle_ConnectFrame */ 4635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic void Handle_ConnectionFrame(phFriNfc_LlcpTransport_t *psTransport, 4645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phNfc_sData_t *psData, 4655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t dsap, 4665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t ssap) 4675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 4685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS status = NFCSTATUS_SUCCESS; 4695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 4705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t index; 4715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t socketFound = FALSE; 4725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phFriNfc_LlcpTransport_Socket_t *pLlcpSocket = NULL; 4735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phFriNfc_LlcpTransport_Socket_t *psLocalLlcpSocket = NULL; 4745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pphFriNfc_LlcpTransportSocketListenCb_t pListen_Cb = NULL; 4755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly void *pListenContext = NULL; 4765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 4775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phNfc_sData_t sServiceName; 4785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t remoteRW = PHFRINFC_LLCP_RW_DEFAULT; 4795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint16_t remoteMIU = PHFRINFC_LLCP_MIU_DEFAULT; 4805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 4815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly status = phFriNfc_Llcp_GetSocket_Params(psData, 4825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly &sServiceName, 4835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly &remoteRW, 4845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly &remoteMIU); 4855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 4865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(status != NFCSTATUS_SUCCESS) 4875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 4885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Incorrect TLV */ 4895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* send FRMR */ 490955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi status = phFriNfc_LlcpTransport_SendFrameReject(psTransport, 491955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi dsap, 492ce7e8806d59161969589c46abbef8ed1436cea8fSunil Jogi PHFRINFC_LLCP_PTYPE_CONNECT, 493ce7e8806d59161969589c46abbef8ed1436cea8fSunil Jogi ssap, 494955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi 0x00, 495955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi 0x00, 496955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi 0x00, 497955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi 0x00, 498955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi 0x00, 499955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi 0x00, 500955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi 0x00, 501955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi 0x00, 502955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi 0x00); 5035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 5045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 5055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 5065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(dsap == PHFRINFC_LLCP_SAP_SDP) 5075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 5085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Search a socket with the SN */ 5095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly for(index=0;index<PHFRINFC_LLCP_NB_SOCKET_MAX;index++) 5105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 5115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test if the socket is in Listen state and if its SN is the good one */ 5125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(psTransport->pSocketTable[index].bSocketListenPending 513cf5cd1520ea32d2b65712a36a105f396df07345cSylvain Fonteneau && (sServiceName.length == psTransport->pSocketTable[index].sServiceName.length) 514cf5cd1520ea32d2b65712a36a105f396df07345cSylvain Fonteneau && !memcmp(sServiceName.buffer,psTransport->pSocketTable[index].sServiceName.buffer,sServiceName.length)) 5155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 5165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* socket with the SN found */ 5175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly socketFound = TRUE; 5185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 5195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psLocalLlcpSocket = &psTransport->pSocketTable[index]; 5205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 5215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Get the new ssap number, it is the ssap number of the socket found */ 5225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly dsap = psLocalLlcpSocket->socket_sSap; 5235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Get the ListenCB of the socket */ 5245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pListen_Cb = psLocalLlcpSocket->pfSocketListen_Cb; 5255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pListenContext = psLocalLlcpSocket->pListenContext; 5265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 5275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 5285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 5295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 5305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 5315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 5325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Search a socket with the DSAP */ 5335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly for(index=0;index<PHFRINFC_LLCP_NB_SOCKET_MAX;index++) 5345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 5355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test if the socket is in Listen state and if its port number is the good one */ 5365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(psTransport->pSocketTable[index].bSocketListenPending && psTransport->pSocketTable[index].socket_sSap == dsap) 5375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 5385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* socket with the SN found */ 5395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly socketFound = TRUE; 5405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 5415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psLocalLlcpSocket = &psTransport->pSocketTable[index]; 5425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 5435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Get the Listen CB and the Context of the socket */ 5445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pListen_Cb = psLocalLlcpSocket->pfSocketListen_Cb; 5455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pListenContext = psLocalLlcpSocket->pListenContext; 5465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 5475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 5485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 5495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 5505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 5515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 5525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test if a socket has beeen found */ 5535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(socketFound) 5545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 5555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Reset the FLAG socketFound*/ 5565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly socketFound = FALSE; 5575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 5585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Search a socket free and no socket connect on this DSAP*/ 5595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly for(index=0;index<PHFRINFC_LLCP_NB_SOCKET_MAX;index++) 5605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 5615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(psTransport->pSocketTable[index].eSocket_State == phFriNfc_LlcpTransportSocket_eSocketDefault && socketFound != TRUE) 5625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 5635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly socketFound = TRUE; 5645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 5655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psTransport->pSocketTable[index].index = index; 5665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 5675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Create a communication socket */ 5685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket = &psTransport->pSocketTable[index]; 5695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 5705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Set the communication option of the Remote Socket */ 5715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->remoteMIU = remoteMIU; 5725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->remoteRW = remoteRW; 5735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 5745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Set SSAP/DSAP of the new socket created for the communication with the remote */ 5755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->socket_dSap = ssap; 5765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->socket_sSap = dsap; 5775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 5785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Set the state and the type of the new socket */ 5795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketBound; 5805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->eSocket_Type = phFriNfc_LlcpTransport_eConnectionOriented; 5815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 5825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 5835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else if(((psTransport->pSocketTable[index].eSocket_State == phFriNfc_LlcpTransportSocket_eSocketConnected) 5845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly || (psTransport->pSocketTable[index].eSocket_State == phFriNfc_LlcpTransportSocket_eSocketAccepted)) 5855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly && ((psTransport->pSocketTable[index].socket_sSap == ssap)&&(psTransport->pSocketTable[index].socket_dSap == dsap))) 5865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 5875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 5885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly socketFound = FALSE; 5895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 5905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(pLlcpSocket != NULL) 5915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 5925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Reset Socket Information */ 5935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->remoteMIU = 0; 5945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->remoteRW = 0; 5955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 5965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Set SSAP/DSAP of the new socket created for the communication with the remote */ 5975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->socket_dSap = 0; 5985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->socket_sSap = 0; 5995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 6005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Set the state and the type of the new socket */ 6015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketDefault; 6025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->eSocket_Type = phFriNfc_LlcpTransport_eDefaultType; 6035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 6045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 6055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 6065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 6075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 6085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 6095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 6105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test if a socket has been found */ 6115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(socketFound) 6125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 6135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Call the Listen CB */ 6145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pListen_Cb(pListenContext,pLlcpSocket); 6155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 6165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 6175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 6185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* No more socket are available */ 6195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Send a DM (0x21) */ 620955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi status = phFriNfc_LlcpTransport_SendDisconnectMode (psTransport, 621955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi ssap, 622955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi dsap, 623955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi PHFRINFC_LLCP_DM_OPCODE_SOCKET_NOT_AVAILABLE); 6245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 6255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 6265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 6275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 6285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Service Name not found or Port number not found */ 6295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Send a DM (0x02) */ 630955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi status = phFriNfc_LlcpTransport_SendDisconnectMode (psTransport, 631955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi ssap, 632955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi dsap, 633955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi PHFRINFC_LLCP_DM_OPCODE_SAP_NOT_FOUND); 6345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 6355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 6365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 6375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/* TODO: comment function Handle_ConnectFrame */ 6385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic void Handle_ConnectionCompleteFrame(phFriNfc_LlcpTransport_t *psTransport, 6395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phNfc_sData_t *psData, 6405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t dsap, 6415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t ssap) 6425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 6435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS status = NFCSTATUS_SUCCESS; 6445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t index; 6455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t remoteRW = PHFRINFC_LLCP_RW_DEFAULT; 6465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint16_t remoteMIU = PHFRINFC_LLCP_MIU_DEFAULT; 6475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t socketFound = FALSE; 6485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phFriNfc_LlcpTransport_Socket_t* psLocalLlcpSocket = NULL; 6495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 6505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly status = phFriNfc_Llcp_GetSocket_Params(psData, 6515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NULL, 6525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly &remoteRW, 6535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly &remoteMIU); 6545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 6555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(status != NFCSTATUS_SUCCESS) 6565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 6575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Incorrect TLV */ 6585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* send FRMR */ 659955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi status = phFriNfc_LlcpTransport_SendFrameReject(psTransport, 660955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi dsap, 661ce7e8806d59161969589c46abbef8ed1436cea8fSunil Jogi PHFRINFC_LLCP_PTYPE_CC, 662ce7e8806d59161969589c46abbef8ed1436cea8fSunil Jogi ssap, 663955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi 0x00, 664955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi 0x00, 665955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi 0x00, 666955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi 0x00, 667955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi 0x00, 668955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi 0x00, 669955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi 0x00, 670955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi 0x00, 671955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi 0x00); 6725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 6735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 6745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 6755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Search a socket in connecting state and with the good SSAP */ 6765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly for(index=0;index<PHFRINFC_LLCP_NB_SOCKET_MAX;index++) 6775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 6785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test if the socket is in Connecting state and if its SSAP number is the good one */ 6795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(psTransport->pSocketTable[index].eSocket_State == phFriNfc_LlcpTransportSocket_eSocketConnecting 6805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly && psTransport->pSocketTable[index].socket_sSap == dsap) 6815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 6825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* socket with the SN found */ 6835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly socketFound = TRUE; 6845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 6855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Update the DSAP value with the incomming Socket sSap */ 6865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psTransport->pSocketTable[index].socket_dSap = ssap; 6875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 6885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Store a pointer to the socket found */ 6895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psLocalLlcpSocket = &psTransport->pSocketTable[index]; 6905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 6915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 6925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 6935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test if a socket has been found */ 6945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(socketFound) 6955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 6965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Set the socket state to connected */ 6975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psLocalLlcpSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketConnected; 6985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 6995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Reset the socket_VS,socket_VR,socket_VSA and socket_VRA variables */ 7005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psLocalLlcpSocket->socket_VR = 0; 7015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psLocalLlcpSocket->socket_VRA = 0; 7025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psLocalLlcpSocket->socket_VS = 0; 7035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psLocalLlcpSocket->socket_VSA = 0; 7045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 7055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Store the Remote parameters (MIU,RW) */ 7065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psLocalLlcpSocket->remoteMIU = remoteMIU; 7075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psLocalLlcpSocket->remoteRW = remoteRW; 7085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 7091c75e8952d88d81c5f04826f69ca22d14bb5683bSylvain Fonteneau /* Call the Connect CB and reset callback info */ 7105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psLocalLlcpSocket->pfSocketConnect_Cb(psLocalLlcpSocket->pConnectContext,0x00,NFCSTATUS_SUCCESS); 7111c75e8952d88d81c5f04826f69ca22d14bb5683bSylvain Fonteneau psLocalLlcpSocket->pfSocketConnect_Cb = NULL; 7121c75e8952d88d81c5f04826f69ca22d14bb5683bSylvain Fonteneau psLocalLlcpSocket->pConnectContext = NULL; 7135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 7145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 7155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 7165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* No socket Active */ 7175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* CC Frame not handled */ 7185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 7195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 7205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 7215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 7225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/* TODO: comment function Handle_DisconnectFrame */ 7235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic void Handle_DisconnectFrame(phFriNfc_LlcpTransport_t *psTransport, 7245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t dsap, 7255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t ssap) 7265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 7275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS status = NFCSTATUS_SUCCESS; 7285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t index; 7295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t socketFound = FALSE; 7305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phFriNfc_LlcpTransport_Socket_t* psLocalLlcpSocket = NULL; 7315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 7325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Search a socket in connected state and the good SSAP */ 7335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly for(index=0;index<PHFRINFC_LLCP_NB_SOCKET_MAX;index++) 7345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 7355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test if the socket is in Connected state and if its SSAP number is the good one */ 7365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(psTransport->pSocketTable[index].eSocket_State == phFriNfc_LlcpTransportSocket_eSocketConnected 7375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly && psTransport->pSocketTable[index].socket_sSap == dsap) 7385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 7395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* socket found */ 7405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly socketFound = TRUE; 7415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 7425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Store a pointer to the socket found */ 7435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psLocalLlcpSocket = &psTransport->pSocketTable[index]; 7445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 7455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 7465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 7475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 7485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test if a socket has been found */ 7495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(socketFound) 7505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 7515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test if a send IFRAME is pending with this socket */ 7525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if((psLocalLlcpSocket->bSocketSendPending == TRUE) || (psLocalLlcpSocket->bSocketRecvPending == TRUE)) 7535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 7545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Call the send CB, a disconnect abort the send request */ 7555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if (psLocalLlcpSocket->pfSocketSend_Cb != NULL && psLocalLlcpSocket->bSocketSendPending == TRUE) 7565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 7575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Copy CB + context in local variables */ 7585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pphFriNfc_LlcpTransportSocketSendCb_t pfSendCb = psLocalLlcpSocket->pfSocketSend_Cb; 7595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly void* pSendContext = psLocalLlcpSocket->pSendContext; 7605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Reset CB + context */ 7615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psLocalLlcpSocket->pfSocketSend_Cb = NULL; 7625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psLocalLlcpSocket->pSendContext = NULL; 7635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Perform callback */ 7645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pfSendCb(pSendContext, NFCSTATUS_FAILED); 7655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 7665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Call the send CB, a disconnect abort the receive request */ 7675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if (psLocalLlcpSocket->pfSocketRecv_Cb != NULL && psLocalLlcpSocket->bSocketRecvPending == TRUE) 7685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 7695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Copy CB + context in local variables */ 7705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pphFriNfc_LlcpTransportSocketRecvCb_t pfRecvCb = psLocalLlcpSocket->pfSocketRecv_Cb; 7715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly void* pRecvContext = psLocalLlcpSocket->pRecvContext; 7725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Reset CB + context */ 7735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psLocalLlcpSocket->pfSocketRecv_Cb = NULL; 7745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psLocalLlcpSocket->pRecvContext = NULL; 7755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Perform callback */ 7765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pfRecvCb(pRecvContext, NFCSTATUS_FAILED); 7775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 7785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psLocalLlcpSocket->bSocketRecvPending = FALSE; 7795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psLocalLlcpSocket->bSocketSendPending = FALSE; 7805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 7815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 782955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi /* Update the socket state */ 783955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi psLocalLlcpSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketDisconnecting; 7845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 785955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi /* Send a DM*/ 786955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi /* TODO: use a socket internal flag to save */ 787955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi status = phFriNfc_LlcpTransport_SendDisconnectMode(psTransport, 788955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi ssap, 789955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi dsap, 790955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi PHFRINFC_LLCP_DM_OPCODE_DISCONNECTED); 7915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 792955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi /* Call ErrCB due to a DISC */ 793955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi psTransport->pSocketTable[index].pSocketErrCb(psTransport->pSocketTable[index].pContext, PHFRINFC_LLCP_ERR_DISCONNECTED); 7945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 7955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 7965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 7975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* No socket Active */ 7985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* DISC Frame not handled */ 7995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 8005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 8015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 8025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/* TODO: comment function Handle_ConnectFrame */ 8035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic void Handle_DisconnetModeFrame(phFriNfc_LlcpTransport_t *psTransport, 8045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phNfc_sData_t *psData, 8055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t dsap, 8065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t ssap) 8075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 8085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS status = NFCSTATUS_SUCCESS; 8095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t index; 8105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t socketFound = FALSE; 8115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t dmOpCode; 8125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phFriNfc_LlcpTransport_Socket_t *psLocalLlcpSocket = NULL; 8135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 8145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test if the DM buffer is correct */ 8155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(psData->length != PHFRINFC_LLCP_DM_LENGTH) 8165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 8175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* send FRMR */ 818955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi status = phFriNfc_LlcpTransport_SendFrameReject(psTransport, 819955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi dsap, 820ce7e8806d59161969589c46abbef8ed1436cea8fSunil Jogi PHFRINFC_LLCP_PTYPE_DM, 821ce7e8806d59161969589c46abbef8ed1436cea8fSunil Jogi ssap, 822955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi 0x00, 823955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi 0x00, 824955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi 0x00, 825955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi 0x00, 826955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi 0x00, 827955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi 0x00, 828955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi 0x00, 829955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi 0x00, 830955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi 0x00); 8315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 8325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 8335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 8345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Search a socket waiting for a DM (Disconnecting State) */ 8355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly for(index=0;index<PHFRINFC_LLCP_NB_SOCKET_MAX;index++) 8365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 8375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test if the socket is in Disconnecting or connecting state and if its SSAP number is the good one */ 8385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if((psTransport->pSocketTable[index].eSocket_State == phFriNfc_LlcpTransportSocket_eSocketDisconnecting 8395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly || psTransport->pSocketTable[index].eSocket_State == phFriNfc_LlcpTransportSocket_eSocketConnecting) 8405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly && psTransport->pSocketTable[index].socket_sSap == dsap) 8415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 8425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* socket found */ 8435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly socketFound = TRUE; 8445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 8455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Store a pointer to the socket found */ 8465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psLocalLlcpSocket = &psTransport->pSocketTable[index]; 8475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 8485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 8495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 8505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 8515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test if a socket has been found */ 8525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(socketFound) 8535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 8545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Set dmOpcode */ 8555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly dmOpCode = psData->buffer[0]; 8565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 8575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly switch(dmOpCode) 8585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 8595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case PHFRINFC_LLCP_DM_OPCODE_DISCONNECTED: 8605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 8615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Set the socket state to disconnected */ 8625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psLocalLlcpSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketCreated; 8635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 8645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Call Disconnect CB */ 8655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if (psLocalLlcpSocket->pfSocketDisconnect_Cb != NULL) 8665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 867837efc3194a03beaaa32b370c63a9270ed9664d8Martijn Coenen psLocalLlcpSocket->pfSocketDisconnect_Cb(psLocalLlcpSocket->pDisconnectContext,NFCSTATUS_SUCCESS); 868b2c5ac1e2d4dda413c4b3a66dc8a186e1dc5f6c4Sylvain Fonteneau psLocalLlcpSocket->pfSocketDisconnect_Cb = NULL; 8695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 8705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 8715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly }break; 8725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 8735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case PHFRINFC_LLCP_DM_OPCODE_CONNECT_REJECTED: 8745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case PHFRINFC_LLCP_DM_OPCODE_CONNECT_NOT_ACCEPTED: 8755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case PHFRINFC_LLCP_DM_OPCODE_SAP_NOT_ACTIVE: 8765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case PHFRINFC_LLCP_DM_OPCODE_SAP_NOT_FOUND: 8775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case PHFRINFC_LLCP_DM_OPCODE_SOCKET_NOT_AVAILABLE: 8785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 8795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Set the socket state to bound */ 8805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psLocalLlcpSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketCreated; 8815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(psLocalLlcpSocket->pfSocketConnect_Cb != NULL) 8825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 8835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Call Connect CB */ 8845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psLocalLlcpSocket->pfSocketConnect_Cb(psLocalLlcpSocket->pConnectContext,dmOpCode,NFCSTATUS_FAILED); 885b2c5ac1e2d4dda413c4b3a66dc8a186e1dc5f6c4Sylvain Fonteneau psLocalLlcpSocket->pfSocketConnect_Cb = NULL; 8865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 8875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly }break; 8885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 8895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 8905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 8915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 8925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 8935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/* TODO: comment function Handle_Receive_IFrame */ 8945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic void Handle_Receive_IFrame(phFriNfc_LlcpTransport_t *psTransport, 8955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phNfc_sData_t *psData, 8965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t dsap, 8975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t ssap) 8985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 8995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS status = NFCSTATUS_SUCCESS; 9005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 9015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phFriNfc_LlcpTransport_Socket_t* psLocalLlcpSocket = NULL; 9025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phFriNfc_Llcp_sPacketSequence_t sLlcpLocalSequence; 9035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 904955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi uint32_t dataLengthAvailable = 0; 9055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint32_t dataLengthWrite = 0; 9065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t index; 9075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t socketFound = FALSE; 9085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t WFlag = 0; 9095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t IFlag = 0; 9105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t RFlag = 0; 9115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t SFlag = 0; 9125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t nr_val; 9135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint32_t offset = 0; 9145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint32_t rw_offset; 9155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 9165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Get NS and NR Value of the I Frame*/ 9175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phFriNfc_Llcp_Buffer2Sequence( psData->buffer, offset, &sLlcpLocalSequence); 9185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 9195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 9205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Update the buffer pointer */ 9215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psData->buffer = psData->buffer + PHFRINFC_LLCP_PACKET_SEQUENCE_SIZE; 9225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 9235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Update the length value (without the header length) */ 9245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psData->length = psData->length - PHFRINFC_LLCP_PACKET_SEQUENCE_SIZE; 9255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 9265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Search a socket waiting for an I FRAME (Connected State) */ 9275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly for(index=0;index<PHFRINFC_LLCP_NB_SOCKET_MAX;index++) 9285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 9295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test if the socket is in connected state and if its SSAP and DSAP are valid */ 9305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(( (psTransport->pSocketTable[index].eSocket_State == phFriNfc_LlcpTransportSocket_eSocketConnected) 9315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly || (psTransport->pSocketTable[index].eSocket_State == phFriNfc_LlcpTransportSocket_eSocketAccepted)) 9325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly && psTransport->pSocketTable[index].socket_sSap == dsap 9335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly && psTransport->pSocketTable[index].socket_dSap == ssap) 9345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 9355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* socket found */ 9365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly socketFound = TRUE; 9375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 9385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Store a pointer to the socket found */ 9395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psLocalLlcpSocket = &psTransport->pSocketTable[index]; 9405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 9415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 9425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 9435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 9445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test if a socket has been found */ 9455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(socketFound) 9465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 9475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test NS */ 9485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*if(sLlcpLocalSequence.ns != psLocalLlcpSocket->socket_VR) 9495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 9505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly SFlag = TRUE; 9515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly }*/ 9525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 9535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Calculate offset of current frame in RW, and check validity */ 9545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(sLlcpLocalSequence.ns >= psLocalLlcpSocket->socket_VRA) 9555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 9565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly rw_offset = sLlcpLocalSequence.ns - psLocalLlcpSocket->socket_VRA; 9575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 9585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 9595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 9605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly rw_offset = 16 - (psLocalLlcpSocket->socket_VRA - sLlcpLocalSequence.ns); 9615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 9625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(rw_offset >= psLocalLlcpSocket->localRW) 9635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 9645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* FRMR 0x01 */ 9655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly SFlag = TRUE; 9665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 9675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 9685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Check Info length */ 9695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(psData->length > (uint32_t)(psLocalLlcpSocket->localMIUX + PHFRINFC_LLCP_MIU_DEFAULT)) 9705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 9715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly IFlag = TRUE; 9725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 9735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 9745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 9755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test NR */ 9765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly nr_val = (uint8_t)sLlcpLocalSequence.nr; 9775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly do 9785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 9795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(nr_val == psLocalLlcpSocket->socket_VS) 9805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 9815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 9825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 9835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 9845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly nr_val = (nr_val+1)%16; 9855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 9865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(nr_val == psLocalLlcpSocket->socket_VSA) 9875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 9885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* FRMR 0x02 */ 9895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly RFlag = TRUE; 9905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 9915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 9925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly }while(nr_val != sLlcpLocalSequence.nr); 9935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 9945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 9955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if( WFlag != 0 || IFlag != 0 || RFlag != 0 || SFlag != 0) 9965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 9975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Send FRMR */ 998955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi status = phFriNfc_LlcpTransport_SendFrameReject(psTransport, 999955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi dsap, 1000ce7e8806d59161969589c46abbef8ed1436cea8fSunil Jogi PHFRINFC_LLCP_PTYPE_I, 1001ce7e8806d59161969589c46abbef8ed1436cea8fSunil Jogi ssap, 1002955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi &sLlcpLocalSequence, 1003955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi WFlag, 1004955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi IFlag, 1005955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi RFlag, 1006955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi SFlag, 1007955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi psLocalLlcpSocket->socket_VS, 1008955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi psLocalLlcpSocket->socket_VSA, 1009955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi psLocalLlcpSocket->socket_VR, 1010955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi psLocalLlcpSocket->socket_VRA); 10115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 10125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 10135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 10145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 101549adea74868aa2bac7b3f0a1c82be9d956d3a86eSunil Jogi /* Update VSA */ 101649adea74868aa2bac7b3f0a1c82be9d956d3a86eSunil Jogi psLocalLlcpSocket->socket_VSA = (uint8_t)sLlcpLocalSequence.nr; 101749adea74868aa2bac7b3f0a1c82be9d956d3a86eSunil Jogi 10185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test if the Linear Buffer length is null */ 10195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(psLocalLlcpSocket->bufferLinearLength == 0) 10205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 10215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test if a Receive is pending and RW empty */ 10225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(psLocalLlcpSocket->bSocketRecvPending == TRUE && (psLocalLlcpSocket->indexRwWrite == psLocalLlcpSocket->indexRwRead)) 10235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 10245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Reset Flag */ 102500485a32cdb11d9773d9800aa374f16560a9d41eSunil Jogi psLocalLlcpSocket->bSocketRecvPending = FALSE; 10265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 10275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Save I_FRAME into the Receive Buffer */ 10285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly memcpy(psLocalLlcpSocket->sSocketRecvBuffer->buffer,psData->buffer,psData->length); 10295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psLocalLlcpSocket->sSocketRecvBuffer->length = psData->length; 10305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 10315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Update VR */ 10325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psLocalLlcpSocket->socket_VR = (psLocalLlcpSocket->socket_VR+1)%16; 10335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 10345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Call the Receive CB */ 10355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psLocalLlcpSocket->pfSocketRecv_Cb(psLocalLlcpSocket->pRecvContext, NFCSTATUS_SUCCESS); 1036b2c5ac1e2d4dda413c4b3a66dc8a186e1dc5f6c4Sylvain Fonteneau psLocalLlcpSocket->pfSocketRecv_Cb = NULL; 10375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 10385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test if a send is pending with this socket */ 10398608ad938da280b895e3bb71435d6fe34c589219Sylvain Fonteneau if(psLocalLlcpSocket->bSocketSendPending == TRUE && CHECK_SEND_RW(psLocalLlcpSocket)) 10405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 10415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test if a send is pending at LLC layer */ 10427c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen if(!testAndSetSendPending(psLocalLlcpSocket->psTransport)) 10435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 104460d8ea84bfbf2dabd0e851edd812f89d42043c1aSylvain Fonteneau status = static_performSendInfo(psLocalLlcpSocket); 10457c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen if (status != NFCSTATUS_SUCCESS && status != NFCSTATUS_PENDING) { 10467c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen clearSendPending(psTransport); 10477c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen } 10485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 10495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 10505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 10515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 10525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* RR */ 10535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly status = phFriNfc_Llcp_Send_ReceiveReady_Frame(psLocalLlcpSocket); 10545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 10555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 10565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 10575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 10585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test if RW is full */ 10595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if((psLocalLlcpSocket->indexRwWrite - psLocalLlcpSocket->indexRwRead)<psLocalLlcpSocket->localRW) 10605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 10615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(psLocalLlcpSocket->sSocketRwBufferTable[(psLocalLlcpSocket->indexRwWrite%psLocalLlcpSocket->localRW)].length == 0) 10625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 10635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Save I_FRAME into the RW Buffers */ 10645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly memcpy(psLocalLlcpSocket->sSocketRwBufferTable[(psLocalLlcpSocket->indexRwWrite%psLocalLlcpSocket->localRW)].buffer,psData->buffer,psData->length); 10655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psLocalLlcpSocket->sSocketRwBufferTable[(psLocalLlcpSocket->indexRwWrite%psLocalLlcpSocket->localRW)].length = psData->length; 10665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 10675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(psLocalLlcpSocket->ReceiverBusyCondition != TRUE) 10685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 10695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Receiver Busy condition */ 10705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psLocalLlcpSocket->ReceiverBusyCondition = TRUE; 10715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 10725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Send RNR */ 10735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly status = phFriNfc_Llcp_Send_ReceiveNotReady_Frame(psLocalLlcpSocket); 10745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 10755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Update the RW write index */ 10765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psLocalLlcpSocket->indexRwWrite++; 10775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 10785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 10795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 10805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 10815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 10825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 10835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Copy the buffer into the RW buffer */ 10845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly memcpy(psLocalLlcpSocket->sSocketRwBufferTable[(psLocalLlcpSocket->indexRwWrite%psLocalLlcpSocket->localRW)].buffer,psData->buffer,psData->length); 10855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 10865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Update the length */ 10875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psLocalLlcpSocket->sSocketRwBufferTable[(psLocalLlcpSocket->indexRwWrite%psLocalLlcpSocket->localRW)].length = psData->length; 10885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 10895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test the length of the available place in the linear buffer */ 10905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly dataLengthAvailable = phFriNfc_Llcp_CyclicFifoAvailable(&psLocalLlcpSocket->sCyclicFifoBuffer); 10915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 10925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(dataLengthAvailable >= psLocalLlcpSocket->sSocketRwBufferTable[(psLocalLlcpSocket->indexRwWrite%psLocalLlcpSocket->localRW)].length) 10935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 10945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Store Data into the linear buffer */ 10955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly dataLengthWrite = phFriNfc_Llcp_CyclicFifoWrite(&psLocalLlcpSocket->sCyclicFifoBuffer, 10965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psLocalLlcpSocket->sSocketRwBufferTable[(psLocalLlcpSocket->indexRwWrite%psLocalLlcpSocket->localRW)].buffer, 10975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psLocalLlcpSocket->sSocketRwBufferTable[(psLocalLlcpSocket->indexRwWrite%psLocalLlcpSocket->localRW)].length); 10985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 10995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Update VR */ 11005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psLocalLlcpSocket->socket_VR = (psLocalLlcpSocket->socket_VR+1)%16; 11015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 11025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Update the length */ 11035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psLocalLlcpSocket->sSocketRwBufferTable[(psLocalLlcpSocket->indexRwWrite%psLocalLlcpSocket->localRW)].length = 0x00; 11045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 11055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test if a Receive Pending*/ 11065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(psLocalLlcpSocket->bSocketRecvPending == TRUE) 11075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 11085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Reset Flag */ 11095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psLocalLlcpSocket->bSocketRecvPending = FALSE; 11105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 11115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phFriNfc_LlcpTransport_ConnectionOriented_Recv(psLocalLlcpSocket, 11125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psLocalLlcpSocket->sSocketRecvBuffer, 11135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psLocalLlcpSocket->pfSocketRecv_Cb, 11145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psLocalLlcpSocket->pRecvContext); 11155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 11165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 11175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test if a send is pending with this socket */ 11188608ad938da280b895e3bb71435d6fe34c589219Sylvain Fonteneau if((psLocalLlcpSocket->bSocketSendPending == TRUE) && CHECK_SEND_RW(psLocalLlcpSocket)) 11195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 11205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test if a send is pending at LLC layer */ 11217c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen if(!testAndSetSendPending(psLocalLlcpSocket->psTransport)) 11225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 112360d8ea84bfbf2dabd0e851edd812f89d42043c1aSylvain Fonteneau status = static_performSendInfo(psLocalLlcpSocket); 11247c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen if (status != NFCSTATUS_SUCCESS && status != NFCSTATUS_PENDING) { 11257c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen clearSendPending(psTransport); 11267c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen } 11275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 11285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 11295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 11305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 11315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* RR */ 11325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly status = phFriNfc_Llcp_Send_ReceiveReady_Frame(psLocalLlcpSocket); 11335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 11345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 11355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 11365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 11375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(psLocalLlcpSocket->ReceiverBusyCondition != TRUE) 11385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 11395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Receiver Busy condition */ 11405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psLocalLlcpSocket->ReceiverBusyCondition = TRUE; 11415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 11425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Send RNR */ 11435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly status = phFriNfc_Llcp_Send_ReceiveNotReady_Frame(psLocalLlcpSocket); 11445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 11455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 11465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Update the RW write index */ 11475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psLocalLlcpSocket->indexRwWrite++; 11485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 11495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 11505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 11515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 11525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 11535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 11545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* No active socket*/ 11555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* I FRAME not Handled */ 11565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 11575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 11585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 11595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic void Handle_ReceiveReady_Frame(phFriNfc_LlcpTransport_t *psTransport, 11605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phNfc_sData_t *psData, 11615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t dsap, 11625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t ssap) 11635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 11645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS status = NFCSTATUS_SUCCESS; 11655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t index; 11665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t socketFound = FALSE; 11675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t WFlag = 0; 11685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t IFlag = 0; 11695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t RFlag = 0; 11705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t SFlag = 0; 11715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint32_t offset = 0; 11725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t nr_val; 11735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 11745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phFriNfc_LlcpTransport_Socket_t* psLocalLlcpSocket = NULL; 11755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phFriNfc_Llcp_sPacketSequence_t sLlcpLocalSequence; 11765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 11775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Get NS and NR Value of the I Frame*/ 11785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phFriNfc_Llcp_Buffer2Sequence( psData->buffer, offset, &sLlcpLocalSequence); 11795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 11805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Search a socket waiting for an RR FRAME (Connected State) */ 11815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly for(index=0;index<PHFRINFC_LLCP_NB_SOCKET_MAX;index++) 11825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 11835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test if the socket is in connected state and if its SSAP and DSAP are valid */ 11845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(psTransport->pSocketTable[index].eSocket_State == phFriNfc_LlcpTransportSocket_eSocketConnected 11855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly && psTransport->pSocketTable[index].socket_sSap == dsap 11865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly && psTransport->pSocketTable[index].socket_dSap == ssap) 11875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 11885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* socket found */ 11895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly socketFound = TRUE; 11905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 11915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Store a pointer to the socket found */ 11925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psLocalLlcpSocket = &psTransport->pSocketTable[index]; 11935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psLocalLlcpSocket->index = psTransport->pSocketTable[index].index; 11945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 11955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 11965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 11975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 11985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test if a socket has been found */ 11995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(socketFound) 12005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 12015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test NR */ 12025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly nr_val = (uint8_t)sLlcpLocalSequence.nr; 12035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly do 12045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 12055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(nr_val == psLocalLlcpSocket->socket_VS) 12065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 12075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 12085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 12095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 12105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly nr_val = (nr_val+1)%16; 12115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 12125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(nr_val == psLocalLlcpSocket->socket_VSA) 12135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 12145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly RFlag = TRUE; 12155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 12165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 12175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 12185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly }while(nr_val != sLlcpLocalSequence.nr); 12195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 12205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 12215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test if Info field present */ 12225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(psData->length > 1) 12235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 12245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly WFlag = TRUE; 12255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly IFlag = TRUE; 12265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 12275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 12285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if (WFlag || IFlag || RFlag || SFlag) 12295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 12305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Send FRMR */ 1231955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi status = phFriNfc_LlcpTransport_SendFrameReject(psTransport, 1232ce7e8806d59161969589c46abbef8ed1436cea8fSunil Jogi dsap, PHFRINFC_LLCP_PTYPE_RR, ssap, 1233955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi &sLlcpLocalSequence, 1234955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi WFlag, IFlag, RFlag, SFlag, 1235955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi psLocalLlcpSocket->socket_VS, 1236955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi psLocalLlcpSocket->socket_VSA, 1237955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi psLocalLlcpSocket->socket_VR, 1238955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi psLocalLlcpSocket->socket_VRA); 12395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 12405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 12415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 12425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test Receiver Busy condition */ 12435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(psLocalLlcpSocket->RemoteBusyConditionInfo == TRUE) 12445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 12455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Notify the upper layer */ 12465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psLocalLlcpSocket->pSocketErrCb(psLocalLlcpSocket->pContext,PHFRINFC_LLCP_ERR_NOT_BUSY_CONDITION); 12475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psLocalLlcpSocket->RemoteBusyConditionInfo = FALSE; 12485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 12495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Update VSA */ 12505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psLocalLlcpSocket->socket_VSA = (uint8_t)sLlcpLocalSequence.nr; 12515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 12525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test if a send is pendind */ 12535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(psLocalLlcpSocket->bSocketSendPending == TRUE) 12545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 12555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test the RW window */ 12568608ad938da280b895e3bb71435d6fe34c589219Sylvain Fonteneau if(CHECK_SEND_RW(psLocalLlcpSocket)) 12575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 12585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test if a send is pending at LLC layer */ 12597c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen if(!testAndSetSendPending(psLocalLlcpSocket->psTransport)) 12605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 126160d8ea84bfbf2dabd0e851edd812f89d42043c1aSylvain Fonteneau status = static_performSendInfo(psLocalLlcpSocket); 12627c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen if (status != NFCSTATUS_SUCCESS && status != NFCSTATUS_PENDING) { 12637c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen clearSendPending(psTransport); 12647c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen } 12655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 12665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 12675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 12685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 12695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 12705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 12715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 12725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* No active socket*/ 12735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* RR Frame not handled*/ 12745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 12755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 12765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 12775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic void Handle_ReceiveNotReady_Frame(phFriNfc_LlcpTransport_t *psTransport, 12785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phNfc_sData_t *psData, 12795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t dsap, 12805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t ssap) 12815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 12825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS status = NFCSTATUS_SUCCESS; 12835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t index; 12845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t socketFound = FALSE; 12855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly bool_t bWFlag = 0; 12865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly bool_t bIFlag = 0; 12875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly bool_t bRFlag = 0; 12885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly bool_t bSFlag = 0; 12895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint32_t offset = 0; 12905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t nr_val; 12915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 12925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phFriNfc_LlcpTransport_Socket_t* psLocalLlcpSocket = NULL; 12935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phFriNfc_Llcp_sPacketSequence_t sLlcpLocalSequence; 12945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 12955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Get NS and NR Value of the I Frame*/ 12965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phFriNfc_Llcp_Buffer2Sequence( psData->buffer, offset, &sLlcpLocalSequence); 12975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 12985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Search a socket waiting for an RNR FRAME (Connected State) */ 12995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly for(index=0;index<PHFRINFC_LLCP_NB_SOCKET_MAX;index++) 13005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 13015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test if the socket is in connected state and if its SSAP and DSAP are valid */ 13025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(psTransport->pSocketTable[index].eSocket_State == phFriNfc_LlcpTransportSocket_eSocketConnected 13035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly && psTransport->pSocketTable[index].socket_sSap == dsap 13045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly && psTransport->pSocketTable[index].socket_dSap == ssap) 13055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 13065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* socket found */ 13075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly socketFound = TRUE; 13085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 13095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Store a pointer to the socket found */ 13105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psLocalLlcpSocket = &psTransport->pSocketTable[index]; 13115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 13125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 13135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 13145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 13155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test if a socket has been found */ 13165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(socketFound) 13175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 13185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test NR */ 13195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly nr_val = (uint8_t)sLlcpLocalSequence.nr; 13205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly do 13215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 13225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 13235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(nr_val == psLocalLlcpSocket->socket_VS) 13245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 13255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 13265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 13275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 13285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly nr_val = (nr_val+1)%16; 13295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 13305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(nr_val == psLocalLlcpSocket->socket_VSA) 13315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 13325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* FRMR 0x02 */ 13335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly bRFlag = TRUE; 13345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 13355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 13365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly }while(nr_val != sLlcpLocalSequence.nr); 13375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 13385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test if Info field present */ 13395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(psData->length > 1) 13405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 13415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Send FRMR */ 13425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly bWFlag = TRUE; 13435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly bIFlag = TRUE; 13445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 13455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 13465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if( bWFlag != 0 || bIFlag != 0 || bRFlag != 0 || bSFlag != 0) 13475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 13485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Send FRMR */ 1349955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi status = phFriNfc_LlcpTransport_SendFrameReject(psTransport, 1350ce7e8806d59161969589c46abbef8ed1436cea8fSunil Jogi dsap, PHFRINFC_LLCP_PTYPE_RNR, ssap, 1351955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi &sLlcpLocalSequence, 1352955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi bWFlag, bIFlag, bRFlag, bSFlag, 1353955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi psLocalLlcpSocket->socket_VS, 1354955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi psLocalLlcpSocket->socket_VSA, 1355955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi psLocalLlcpSocket->socket_VR, 1356955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi psLocalLlcpSocket->socket_VRA); 13575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 13585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 13595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 13605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Notify the upper layer */ 13615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psLocalLlcpSocket->pSocketErrCb(psTransport->pSocketTable[index].pContext,PHFRINFC_LLCP_ERR_BUSY_CONDITION); 13625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psLocalLlcpSocket->RemoteBusyConditionInfo = TRUE; 13635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 13645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Update VSA */ 13655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psLocalLlcpSocket->socket_VSA = (uint8_t)sLlcpLocalSequence.nr; 13665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 13675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test if a send is pendind */ 13688608ad938da280b895e3bb71435d6fe34c589219Sylvain Fonteneau if(psLocalLlcpSocket->bSocketSendPending == TRUE && CHECK_SEND_RW(psLocalLlcpSocket)) 13695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 13705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test if a send is pending at LLC layer */ 13717c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen if(!testAndSetSendPending(psLocalLlcpSocket->psTransport)) 13725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 137360d8ea84bfbf2dabd0e851edd812f89d42043c1aSylvain Fonteneau status = static_performSendInfo(psLocalLlcpSocket); 13747c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen if (status != NFCSTATUS_SUCCESS && status != NFCSTATUS_PENDING) { 13757c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen clearSendPending(psTransport); 13767c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen } 13775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 13785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 13795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 13805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 13815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 13825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 13835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* No active socket*/ 13845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* RNR Frame not handled*/ 13855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 13865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 13875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 13885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic void Handle_FrameReject_Frame(phFriNfc_LlcpTransport_t *psTransport, 13895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t dsap, 13905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t ssap) 13915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 13925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS status = NFCSTATUS_SUCCESS; 13935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t index; 13945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t socketFound = FALSE; 13955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 13965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Search a socket waiting for a FRAME */ 13975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly for(index=0;index<PHFRINFC_LLCP_NB_SOCKET_MAX;index++) 13985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 13995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test if the socket is in connected state and if its SSAP and DSAP are valid */ 14005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(psTransport->pSocketTable[index].socket_sSap == dsap 14015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly && psTransport->pSocketTable[index].socket_dSap == ssap) 14025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 14035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* socket found */ 14045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly socketFound = TRUE; 14055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly break; 14065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 14075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 14085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 14095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test if a socket has been found */ 14105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(socketFound) 14115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 14125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Set socket state to disconnected */ 14135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psTransport->pSocketTable[index].eSocket_State = phFriNfc_LlcpTransportSocket_eSocketDisconnected; 14145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 14155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Call ErrCB due to a FRMR*/ 14165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psTransport->pSocketTable[index].pSocketErrCb( psTransport->pSocketTable[index].pContext,PHFRINFC_LLCP_ERR_FRAME_REJECTED); 14175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 14185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Close the socket */ 14195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly status = phFriNfc_LlcpTransport_ConnectionOriented_Close(&psTransport->pSocketTable[index]); 14205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 14215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 14225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 14235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* No active socket*/ 14245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* FRMR Frame not handled*/ 14255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 14265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 14275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 14285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/* TODO: comment function Handle_ConnectionOriented_IncommingFrame */ 14295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellyvoid Handle_ConnectionOriented_IncommingFrame(phFriNfc_LlcpTransport_t *psTransport, 14305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phNfc_sData_t *psData, 14315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t dsap, 14325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t ptype, 14335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t ssap) 14345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 14355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phFriNfc_Llcp_sPacketSequence_t sSequence = {0,0}; 14365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 14375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly switch(ptype) 14385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 14395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case PHFRINFC_LLCP_PTYPE_CONNECT: 14405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 14415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Handle_ConnectionFrame(psTransport, 14425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psData, 14435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly dsap, 14445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ssap); 14455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly }break; 14465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 14475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case PHFRINFC_LLCP_PTYPE_DISC: 14485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 14495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Handle_DisconnectFrame(psTransport, 14505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly dsap, 14515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ssap); 14525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly }break; 14535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 14545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case PHFRINFC_LLCP_PTYPE_CC: 14555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 14565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Handle_ConnectionCompleteFrame(psTransport, 14575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psData, 14585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly dsap, 14595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ssap); 14605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly }break; 14615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 14625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case PHFRINFC_LLCP_PTYPE_DM: 14635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 14645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Handle_DisconnetModeFrame(psTransport, 14655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psData, 14665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly dsap, 14675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ssap); 14685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly }break; 14695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 14705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case PHFRINFC_LLCP_PTYPE_FRMR: 14715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 14725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Handle_FrameReject_Frame(psTransport, 14735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly dsap, 14745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ssap); 14755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly }break; 14765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 14775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case PHFRINFC_LLCP_PTYPE_I: 14785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 14795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Handle_Receive_IFrame(psTransport, 14805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psData, 14815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly dsap, 14825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ssap); 14835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly }break; 14845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 14855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case PHFRINFC_LLCP_PTYPE_RR: 14865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 14875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Handle_ReceiveReady_Frame(psTransport, 14885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psData, 14895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly dsap, 14905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ssap); 14915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly }break; 14925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 14935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case PHFRINFC_LLCP_PTYPE_RNR: 14945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 14955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly Handle_ReceiveNotReady_Frame(psTransport, 14965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psData, 14975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly dsap, 14985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly ssap); 14995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly }break; 15005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 15015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case PHFRINFC_LLCP_PTYPE_RESERVED1: 15025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case PHFRINFC_LLCP_PTYPE_RESERVED2: 15035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly case PHFRINFC_LLCP_PTYPE_RESERVED3: 15045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 1505955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi phFriNfc_LlcpTransport_SendFrameReject( psTransport, 1506955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi dsap, ptype, ssap, 1507955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi &sSequence, 1508955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi TRUE, FALSE, FALSE, FALSE, 1509955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi 0, 0, 0, 0); 15105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly }break; 15115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 15125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 15135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 15145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/** 15155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \ingroup grp_lib_nfc 15165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \brief <b>Get the local options of a socket</b>. 15175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* 15185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* This function returns the local options (maximum packet size and receive window size) used 15195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* for a given connection-oriented socket. This function shall not be used with connectionless 15205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* sockets. 15215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* 15225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[out] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t. 15235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in] psLocalOptions A pointer to be filled with the local options of the socket. 15245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* 15255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_SUCCESS Operation successful. 15265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters 15275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* could not be properly interpreted. 15285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_INVALID_STATE The socket is not in a valid state, or not of 15295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* a valid type to perform the requsted operation. 15305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_NOT_INITIALISED Indicates stack is not yet initialized. 15315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_SHUTDOWN Shutdown in progress. 15325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_FAILED Operation failed. 15335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/ 15345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_SocketGetLocalOptions(phFriNfc_LlcpTransport_Socket_t *pLlcpSocket, 15355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phLibNfc_Llcp_sSocketOptions_t *psLocalOptions) 15365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 15375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS status = NFCSTATUS_SUCCESS; 15385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 15395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Get Local MIUX */ 1540c2866714540bec65af19240e95a10d3090df0cf9Sylvain Fonteneau psLocalOptions->miu = pLlcpSocket->sSocketOption.miu; 15415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 15425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Get Local Receive Window */ 1543c2866714540bec65af19240e95a10d3090df0cf9Sylvain Fonteneau psLocalOptions->rw = pLlcpSocket->sSocketOption.rw; 15445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 15455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return status; 15465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 15475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 15485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/** 15495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \ingroup grp_lib_nfc 15505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \brief <b>Get the local options of a socket</b>. 15515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* 15525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* This function returns the remote options (maximum packet size and receive window size) used 15535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* for a given connection-oriented socket. This function shall not be used with connectionless 15545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* sockets. 15555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* 15565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[out] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t. 15575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in] psRemoteOptions A pointer to be filled with the remote options of the socket. 15585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* 15595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_SUCCESS Operation successful. 15605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters 15615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* could not be properly interpreted. 15625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_INVALID_STATE The socket is not in a valid state, or not of 15635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* a valid type to perform the requsted operation. 15645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_NOT_INITIALISED Indicates stack is not yet initialized. 15655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_SHUTDOWN Shutdown in progress. 15665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_FAILED Operation failed. 15675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/ 15685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_SocketGetRemoteOptions(phFriNfc_LlcpTransport_Socket_t* pLlcpSocket, 15695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phLibNfc_Llcp_sSocketOptions_t* psRemoteOptions) 15705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 15715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS status = NFCSTATUS_SUCCESS; 15725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 15735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Get Remote MIUX */ 15745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psRemoteOptions->miu = pLlcpSocket->remoteMIU; 15755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 15765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Get Remote Receive Window */ 15775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psRemoteOptions->rw = pLlcpSocket->remoteRW; 15785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 15795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return status; 15805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 15815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 15825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 15835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/** 15845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \ingroup grp_fri_nfc 15855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \brief <b>Listen for incoming connection requests on a socket</b>. 15865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* 15875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* This function switches a socket into a listening state and registers a callback on 15885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* incoming connection requests. In this state, the socket is not able to communicate 15895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* directly. The listening state is only available for connection-oriented sockets 15905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* which are still not connected. The socket keeps listening until it is closed, and 15915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* thus can trigger several times the pListen_Cb callback. 15925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* 15935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* 15945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t. 15955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in] pListen_Cb The callback to be called each time the 15965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* socket receive a connection request. 15975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in] pContext Upper layer context to be returned in 15985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* the callback. 15995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* 16005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_SUCCESS Operation successful. 16015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters 16025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* could not be properly interpreted. 16035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_INVALID_STATE The socket is not in a valid state to switch 16045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* to listening state. 16055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_FAILED Operation failed. 16065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/ 16075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_Listen(phFriNfc_LlcpTransport_Socket_t* pLlcpSocket, 16085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pphFriNfc_LlcpTransportSocketListenCb_t pListen_Cb, 16095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly void* pContext) 16105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 16115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS status = NFCSTATUS_SUCCESS; 16125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t index; 16135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 16145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Store the listen callback */ 16155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->pfSocketListen_Cb = pListen_Cb; 16165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 16175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* store the context */ 16185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->pListenContext = pContext; 16195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 16205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Set RecvPending to TRUE */ 16215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->bSocketListenPending = TRUE; 16225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 16235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Set the socket state*/ 16245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketRegistered; 16255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 16265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return status; 16275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 16285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 16295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/** 16305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \ingroup grp_fri_nfc 16315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \brief <b>Accept an incoming connection request for a socket</b>. 16325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* 16335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* This functions allows the client to accept an incoming connection request. 16345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* It must be used with the socket provided within the listen callback. The socket 16355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* is implicitly switched to the connected state when the function is called. 16365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* 16375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t. 16385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in] psOptions The options to be used with the socket. 16395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in] psWorkingBuffer A working buffer to be used by the library. 16405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in] pErr_Cb The callback to be called each time the accepted socket 16415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* is in error. 16425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in] pAccept_RspCb The callback to be called when the Accept operation is completed 16435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in] pContext Upper layer context to be returned in the callback. 16445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* 16455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_SUCCESS Operation successful. 16465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters 16475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* could not be properly interpreted. 16485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_BUFFER_TOO_SMALL The working buffer is too small for the MIU and RW 16495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* declared in the options. 16505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_FAILED Operation failed. 16515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/ 16525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_Accept(phFriNfc_LlcpTransport_Socket_t* pLlcpSocket, 16535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phFriNfc_LlcpTransport_sSocketOptions_t* psOptions, 16545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phNfc_sData_t* psWorkingBuffer, 16555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pphFriNfc_LlcpTransportSocketErrCb_t pErr_Cb, 16565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pphFriNfc_LlcpTransportSocketAcceptCb_t pAccept_RspCb, 16575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly void* pContext) 16585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 16595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 16605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS status = NFCSTATUS_SUCCESS; 16615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 16625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint32_t offset = 0; 1663e1c9fcfb918da43ab24f95c9341da3b6bf3b1250Jeff Hamilton uint8_t miux[2]; 16645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t i; 16655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Store the options in the socket */ 1666c2866714540bec65af19240e95a10d3090df0cf9Sylvain Fonteneau memcpy(&pLlcpSocket->sSocketOption, psOptions, sizeof(phFriNfc_LlcpTransport_sSocketOptions_t)); 16675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 16685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Set socket local params (MIUX & RW) */ 1669c2866714540bec65af19240e95a10d3090df0cf9Sylvain Fonteneau pLlcpSocket ->localMIUX = (pLlcpSocket->sSocketOption.miu - PHFRINFC_LLCP_MIU_DEFAULT) & PHFRINFC_LLCP_TLV_MIUX_MASK; 1670c2866714540bec65af19240e95a10d3090df0cf9Sylvain Fonteneau pLlcpSocket ->localRW = pLlcpSocket->sSocketOption.rw & PHFRINFC_LLCP_TLV_RW_MASK; 16715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 16725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Set the pointer and the length for the Receive Window Buffer */ 16735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly for(i=0;i<pLlcpSocket->localRW;i++) 16745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 1675c2866714540bec65af19240e95a10d3090df0cf9Sylvain Fonteneau pLlcpSocket->sSocketRwBufferTable[i].buffer = psWorkingBuffer->buffer + (i*pLlcpSocket->sSocketOption.miu); 16765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->sSocketRwBufferTable[i].length = 0; 16775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 16785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 16795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Set the pointer and the length for the Send Buffer */ 16805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->sSocketSendBuffer.buffer = psWorkingBuffer->buffer + pLlcpSocket->bufferRwMaxLength; 16815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->sSocketSendBuffer.length = pLlcpSocket->bufferSendMaxLength; 16825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 16835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Set the pointer and the length for the Linear Buffer */ 16845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->sSocketLinearBuffer.buffer = psWorkingBuffer->buffer + pLlcpSocket->bufferRwMaxLength + pLlcpSocket->bufferSendMaxLength; 16855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->sSocketLinearBuffer.length = pLlcpSocket->bufferLinearLength; 16865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 16875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(pLlcpSocket->sSocketLinearBuffer.length != 0) 16885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 16895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Init Cyclic Fifo */ 16905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phFriNfc_Llcp_CyclicFifoInit(&pLlcpSocket->sCyclicFifoBuffer, 16915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->sSocketLinearBuffer.buffer, 16925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->sSocketLinearBuffer.length); 16935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 16945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 16955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->pSocketErrCb = pErr_Cb; 16965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->pContext = pContext; 16975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 16985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* store the pointer to the Accept callback */ 16995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->pfSocketAccept_Cb = pAccept_RspCb; 17005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->pAcceptContext = pContext; 17015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 17025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Reset the socket_VS,socket_VR,socket_VSA and socket_VRA variables */ 17035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->socket_VR = 0; 17045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->socket_VRA = 0; 17055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->socket_VS = 0; 17065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->socket_VSA = 0; 17075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 17085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* MIUX */ 17095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(pLlcpSocket->localMIUX != PHFRINFC_LLCP_MIUX_DEFAULT) 17105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 17115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Encode MIUX value */ 1712e1c9fcfb918da43ab24f95c9341da3b6bf3b1250Jeff Hamilton phFriNfc_Llcp_EncodeMIUX(pLlcpSocket->localMIUX, 1713e1c9fcfb918da43ab24f95c9341da3b6bf3b1250Jeff Hamilton miux); 17145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 17155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Encode MIUX in TLV format */ 17165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly status = phFriNfc_Llcp_EncodeTLV(&pLlcpSocket->sSocketSendBuffer, 17175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly &offset, 17185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly PHFRINFC_LLCP_TLV_TYPE_MIUX, 17195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly PHFRINFC_LLCP_TLV_LENGTH_MIUX, 1720e1c9fcfb918da43ab24f95c9341da3b6bf3b1250Jeff Hamilton miux); 17215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(status != NFCSTATUS_SUCCESS) 17225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 17235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Call the CB */ 17245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_FAILED); 172528235f8b29ef8cc368dd132080245778cdf704ccArnaud Ferir goto clean_and_return; 17265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 17275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 17285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 172928235f8b29ef8cc368dd132080245778cdf704ccArnaud Ferir /* Receive Window */ 1730c2866714540bec65af19240e95a10d3090df0cf9Sylvain Fonteneau if(pLlcpSocket->sSocketOption.rw != PHFRINFC_LLCP_RW_DEFAULT) 17315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 17325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Encode RW value */ 1733c2866714540bec65af19240e95a10d3090df0cf9Sylvain Fonteneau phFriNfc_Llcp_EncodeRW(&pLlcpSocket->sSocketOption.rw); 17345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 17355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Encode RW in TLV format */ 17365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly status = phFriNfc_Llcp_EncodeTLV(&pLlcpSocket->sSocketSendBuffer, 17375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly &offset, 17385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly PHFRINFC_LLCP_TLV_TYPE_RW, 17395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly PHFRINFC_LLCP_TLV_LENGTH_RW, 1740c2866714540bec65af19240e95a10d3090df0cf9Sylvain Fonteneau &pLlcpSocket->sSocketOption.rw); 17415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(status != NFCSTATUS_SUCCESS) 17425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 17435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Call the CB */ 17445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_FAILED); 174528235f8b29ef8cc368dd132080245778cdf704ccArnaud Ferir goto clean_and_return; 17465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 17475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 17485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 17495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 17505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test if a send is pending */ 17517c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen if(testAndSetSendPending(pLlcpSocket->psTransport)) 17525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 17535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->bSocketAcceptPending = TRUE; 17545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 17555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Update Send Buffer length value */ 17565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->sSocketSendBuffer.length = offset; 17575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 17585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly status = NFCSTATUS_PENDING; 17595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 17605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 17615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 17625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Fill the psLlcpHeader stuture with the DSAP,CC PTYPE and the SSAP */ 17635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->sLlcpHeader.dsap = pLlcpSocket->socket_dSap; 17645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->sLlcpHeader.ptype = PHFRINFC_LLCP_PTYPE_CC; 17655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->sLlcpHeader.ssap = pLlcpSocket->socket_sSap; 17665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 17675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Set the socket state to accepted */ 17685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketAccepted; 17695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 17705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Update Send Buffer length value */ 17715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->sSocketSendBuffer.length = offset; 17725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 17735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Send a CC Frame */ 1774955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi status = phFriNfc_LlcpTransport_LinkSend(pLlcpSocket->psTransport, 17755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly &pLlcpSocket->sLlcpHeader, 17765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NULL, 17775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly &pLlcpSocket->sSocketSendBuffer, 17785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phFriNfc_LlcpTransport_ConnectionOriented_SendLlcp_CB, 17797c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen pLlcpSocket->index, 17805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->psTransport); 17817c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen if (status != NFCSTATUS_SUCCESS && status != NFCSTATUS_PENDING) { 17827c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen clearSendPending(pLlcpSocket->psTransport); 17837c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen } 17845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 178528235f8b29ef8cc368dd132080245778cdf704ccArnaud Ferir 178628235f8b29ef8cc368dd132080245778cdf704ccArnaud Ferirclean_and_return: 178728235f8b29ef8cc368dd132080245778cdf704ccArnaud Ferir if(status != NFCSTATUS_PENDING) 178828235f8b29ef8cc368dd132080245778cdf704ccArnaud Ferir { 178928235f8b29ef8cc368dd132080245778cdf704ccArnaud Ferir LLCP_PRINT("Release Accept callback"); 179028235f8b29ef8cc368dd132080245778cdf704ccArnaud Ferir pLlcpSocket->pfSocketAccept_Cb = NULL; 179128235f8b29ef8cc368dd132080245778cdf704ccArnaud Ferir pLlcpSocket->pAcceptContext = NULL; 179228235f8b29ef8cc368dd132080245778cdf704ccArnaud Ferir } 179328235f8b29ef8cc368dd132080245778cdf704ccArnaud Ferir 17945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return status; 17955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 17965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 17975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /** 17985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \ingroup grp_fri_nfc 17995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \brief <b>Reject an incoming connection request for a socket</b>. 18005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* 18015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* This functions allows the client to reject an incoming connection request. 18025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* It must be used with the socket provided within the listen callback. The socket 18035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* is implicitly closed when the function is called. 18045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* 18055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t. 18065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* 18075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_SUCCESS Operation successful. 18085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters 18095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* could not be properly interpreted. 18105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_FAILED Operation failed. 18115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/ 18125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS phLibNfc_LlcpTransport_ConnectionOriented_Reject( phFriNfc_LlcpTransport_Socket_t* pLlcpSocket, 18135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pphFriNfc_LlcpTransportSocketRejectCb_t pReject_RspCb, 18145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly void *pContext) 18155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 18165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS status = NFCSTATUS_SUCCESS; 18175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 18185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Set the state of the socket */ 18195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketRejected; 18205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 18215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Store the Reject callback */ 18225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->pfSocketSend_Cb = pReject_RspCb; 18235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->pRejectContext = pContext; 18245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 18255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Send a DM*/ 1826955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi status = phFriNfc_LlcpTransport_SendDisconnectMode(pLlcpSocket->psTransport, 1827955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi pLlcpSocket->socket_dSap, 1828955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi pLlcpSocket->socket_sSap, 1829955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi PHFRINFC_LLCP_DM_OPCODE_CONNECT_REJECTED); 18305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 18315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return status; 18325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 18335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 18345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/** 18355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \ingroup grp_fri_nfc 18365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \brief <b>Try to establish connection with a socket on a remote SAP</b>. 18375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* 18385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* This function tries to connect to a given SAP on the remote peer. If the 18395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* socket is not bound to a local SAP, it is implicitly bound to a free SAP. 18405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* 18415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t. 18425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in] nSap The destination SAP to connect to. 18435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in] psUri The URI corresponding to the destination SAP to connect to. 18445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in] pConnect_RspCb The callback to be called when the connection 18455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* operation is completed. 18465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in] pContext Upper layer context to be returned in 18475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* the callback. 18485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* 18495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_SUCCESS Operation successful. 18505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters 18515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* could not be properly interpreted. 18525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_PENDING Connection operation is in progress, 18535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* pConnect_RspCb will be called upon completion. 18545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_INVALID_STATE The socket is not in a valid state, or not of 18555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* a valid type to perform the requsted operation. 18565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_FAILED Operation failed. 18575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/ 18585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_Connect( phFriNfc_LlcpTransport_Socket_t* pLlcpSocket, 18595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint8_t nSap, 18605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phNfc_sData_t* psUri, 18615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pphFriNfc_LlcpTransportSocketConnectCb_t pConnect_RspCb, 18625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly void* pContext) 18635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 18645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS status = NFCSTATUS_SUCCESS; 18655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint32_t offset = 0; 1866e1c9fcfb918da43ab24f95c9341da3b6bf3b1250Jeff Hamilton uint8_t miux[2]; 18675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 18685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test if a nSap is present */ 18695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(nSap != PHFRINFC_LLCP_SAP_DEFAULT) 18705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 18715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Set DSAP port number with the nSap value */ 18725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->socket_dSap = nSap; 18735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 18745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 18755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 18765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Set DSAP port number with the SDP port number */ 18775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->socket_dSap = PHFRINFC_LLCP_SAP_SDP; 18785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 18795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 18805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Store the Connect callback and context */ 18815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->pfSocketConnect_Cb = pConnect_RspCb; 18825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->pConnectContext = pContext; 18835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 18845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Set the socket Header */ 18855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->sLlcpHeader.dsap = pLlcpSocket->socket_dSap; 18865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->sLlcpHeader.ptype = PHFRINFC_LLCP_PTYPE_CONNECT; 18875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->sLlcpHeader.ssap = pLlcpSocket->socket_sSap; 18885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 18895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* MIUX */ 18905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(pLlcpSocket->localMIUX != PHFRINFC_LLCP_MIUX_DEFAULT) 18915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 18925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Encode MIUX value */ 1893e1c9fcfb918da43ab24f95c9341da3b6bf3b1250Jeff Hamilton phFriNfc_Llcp_EncodeMIUX(pLlcpSocket->localMIUX, 1894e1c9fcfb918da43ab24f95c9341da3b6bf3b1250Jeff Hamilton miux); 18955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 18965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Encode MIUX in TLV format */ 18975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly status = phFriNfc_Llcp_EncodeTLV(&pLlcpSocket->sSocketSendBuffer, 18985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly &offset, 18995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly PHFRINFC_LLCP_TLV_TYPE_MIUX, 19005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly PHFRINFC_LLCP_TLV_LENGTH_MIUX, 1901e1c9fcfb918da43ab24f95c9341da3b6bf3b1250Jeff Hamilton miux); 19025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(status != NFCSTATUS_SUCCESS) 19035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 190428235f8b29ef8cc368dd132080245778cdf704ccArnaud Ferir status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_FAILED); 190528235f8b29ef8cc368dd132080245778cdf704ccArnaud Ferir goto clean_and_return; 19065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 19075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 19085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 190928235f8b29ef8cc368dd132080245778cdf704ccArnaud Ferir /* Receive Window */ 1910c2866714540bec65af19240e95a10d3090df0cf9Sylvain Fonteneau if(pLlcpSocket->sSocketOption.rw != PHFRINFC_LLCP_RW_DEFAULT) 19115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 19125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Encode RW value */ 1913c2866714540bec65af19240e95a10d3090df0cf9Sylvain Fonteneau phFriNfc_Llcp_EncodeRW(&pLlcpSocket->sSocketOption.rw); 19145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 19155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Encode RW in TLV format */ 19165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly status = phFriNfc_Llcp_EncodeTLV(&pLlcpSocket->sSocketSendBuffer, 19175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly &offset, 19185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly PHFRINFC_LLCP_TLV_TYPE_RW, 19195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly PHFRINFC_LLCP_TLV_LENGTH_RW, 1920c2866714540bec65af19240e95a10d3090df0cf9Sylvain Fonteneau &pLlcpSocket->sSocketOption.rw); 19215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(status != NFCSTATUS_SUCCESS) 19225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 19235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_FAILED); 192428235f8b29ef8cc368dd132080245778cdf704ccArnaud Ferir goto clean_and_return; 19255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 19265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 19275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 19285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test if a Service Name is present */ 19295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(psUri != NULL) 19305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 19315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Encode SN in TLV format */ 19325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly status = phFriNfc_Llcp_EncodeTLV(&pLlcpSocket->sSocketSendBuffer, 19335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly &offset, 19345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly PHFRINFC_LLCP_TLV_TYPE_SN, 19355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly (uint8_t)psUri->length, 19365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psUri->buffer); 19375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(status != NFCSTATUS_SUCCESS) 19385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 19395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_FAILED); 194028235f8b29ef8cc368dd132080245778cdf704ccArnaud Ferir goto clean_and_return; 19415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 19425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 19435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 194428235f8b29ef8cc368dd132080245778cdf704ccArnaud Ferir /* Test if a send is pending */ 19457c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen if(testAndSetSendPending(pLlcpSocket->psTransport)) 19465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 19475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->bSocketConnectPending = TRUE; 19485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 19495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Update Send Buffer length value */ 19505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->sSocketSendBuffer.length = offset; 19515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 19525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly status = NFCSTATUS_PENDING; 19535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 19545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 19555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 19565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Update Send Buffer length value */ 19575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->sSocketSendBuffer.length = offset; 19585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 19595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Set the socket in connecting state */ 19605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketConnecting; 19615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 1962955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi status = phFriNfc_LlcpTransport_LinkSend(pLlcpSocket->psTransport, 19635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly &pLlcpSocket->sLlcpHeader, 19645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NULL, 19655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly &pLlcpSocket->sSocketSendBuffer, 19665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phFriNfc_LlcpTransport_ConnectionOriented_SendLlcp_CB, 19677c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen pLlcpSocket->index, 19685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->psTransport); 19697c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen if (status != NFCSTATUS_SUCCESS && status != NFCSTATUS_PENDING) { 19707c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen clearSendPending(pLlcpSocket->psTransport); 19717c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen } 19725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 19735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 197428235f8b29ef8cc368dd132080245778cdf704ccArnaud Ferirclean_and_return: 197528235f8b29ef8cc368dd132080245778cdf704ccArnaud Ferir if(status != NFCSTATUS_PENDING) 197628235f8b29ef8cc368dd132080245778cdf704ccArnaud Ferir { 197728235f8b29ef8cc368dd132080245778cdf704ccArnaud Ferir LLCP_PRINT("Release Connect callback"); 197828235f8b29ef8cc368dd132080245778cdf704ccArnaud Ferir pLlcpSocket->pfSocketConnect_Cb = NULL; 197928235f8b29ef8cc368dd132080245778cdf704ccArnaud Ferir pLlcpSocket->pConnectContext = NULL; 198028235f8b29ef8cc368dd132080245778cdf704ccArnaud Ferir } 198128235f8b29ef8cc368dd132080245778cdf704ccArnaud Ferir 19825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return status; 19835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 19845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 19855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 19865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/** 19875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \ingroup grp_lib_nfc 19885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \brief <b>Disconnect a currently connected socket</b>. 19895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* 19905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* This function initiates the disconnection of a previously connected socket. 19915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* 19925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t. 19935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in] pDisconnect_RspCb The callback to be called when the 19945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* operation is completed. 19955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in] pContext Upper layer context to be returned in 19965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* the callback. 19975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* 19985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_SUCCESS Operation successful. 19995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters 20005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* could not be properly interpreted. 20015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_PENDING Disconnection operation is in progress, 20025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* pDisconnect_RspCb will be called upon completion. 20035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_INVALID_STATE The socket is not in a valid state, or not of 20045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* a valid type to perform the requsted operation. 20055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_NOT_INITIALISED Indicates stack is not yet initialized. 20065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_SHUTDOWN Shutdown in progress. 20075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_FAILED Operation failed. 20085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/ 20095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS phLibNfc_LlcpTransport_ConnectionOriented_Disconnect(phFriNfc_LlcpTransport_Socket_t* pLlcpSocket, 20105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pphLibNfc_LlcpSocketDisconnectCb_t pDisconnect_RspCb, 20115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly void* pContext) 20125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 20135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS status = NFCSTATUS_SUCCESS; 20145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 20155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Store the Disconnect callback and context*/ 20165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->pfSocketDisconnect_Cb = pDisconnect_RspCb; 2017837efc3194a03beaaa32b370c63a9270ed9664d8Martijn Coenen pLlcpSocket->pDisconnectContext = pContext; 20185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 20198a4742c9dfa8010c06e5c746ab739ed71ba327bdSylvain Fonteneau /* Set the socket in connecting state */ 20208a4742c9dfa8010c06e5c746ab739ed71ba327bdSylvain Fonteneau pLlcpSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketDisconnecting; 20218a4742c9dfa8010c06e5c746ab739ed71ba327bdSylvain Fonteneau 20225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test if a send IFRAME is pending with this socket */ 20235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if((pLlcpSocket->bSocketSendPending == TRUE) || (pLlcpSocket->bSocketRecvPending == TRUE)) 20245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 20255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->bSocketSendPending = FALSE; 20265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->bSocketRecvPending = FALSE; 20275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 20285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Call the send CB, a disconnect abort the send request */ 20295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if (pLlcpSocket->pfSocketSend_Cb != NULL) 20305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 20315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Copy CB + context in local variables */ 20325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pphFriNfc_LlcpTransportSocketSendCb_t pfSendCb = pLlcpSocket->pfSocketSend_Cb; 20335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly void* pSendContext = pLlcpSocket->pSendContext; 20345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Reset CB + context */ 20355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->pfSocketSend_Cb = NULL; 20365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->pSendContext = NULL; 20375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Perform callback */ 20385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pfSendCb(pSendContext, NFCSTATUS_FAILED); 20395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 20405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Call the send CB, a disconnect abort the receive request */ 20415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if (pLlcpSocket->pfSocketRecv_Cb != NULL) 20425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 20435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Copy CB + context in local variables */ 20445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pphFriNfc_LlcpTransportSocketRecvCb_t pfRecvCb = pLlcpSocket->pfSocketRecv_Cb; 20455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly void* pRecvContext = pLlcpSocket->pRecvContext; 20465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Reset CB + context */ 20475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->pfSocketRecv_Cb = NULL; 20485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->pRecvContext = NULL; 20495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Perform callback */ 20505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pfRecvCb(pRecvContext, NFCSTATUS_FAILED); 20515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 20525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 20535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 20545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test if a send is pending */ 20557c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen if( testAndSetSendPending(pLlcpSocket->psTransport)) 20565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 20575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->bSocketDiscPending = TRUE; 20585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly status = NFCSTATUS_PENDING; 20595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 20605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 20615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 20623cbab5882f6d89a52068a3fa72a7223971d6b7fdMartijn Coenen /* Set the socket Header */ 20633cbab5882f6d89a52068a3fa72a7223971d6b7fdMartijn Coenen pLlcpSocket->sLlcpHeader.dsap = pLlcpSocket->socket_dSap; 20643cbab5882f6d89a52068a3fa72a7223971d6b7fdMartijn Coenen pLlcpSocket->sLlcpHeader.ptype = PHFRINFC_LLCP_PTYPE_DISC; 20653cbab5882f6d89a52068a3fa72a7223971d6b7fdMartijn Coenen pLlcpSocket->sLlcpHeader.ssap = pLlcpSocket->socket_sSap; 20663cbab5882f6d89a52068a3fa72a7223971d6b7fdMartijn Coenen 2067955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi status = phFriNfc_LlcpTransport_LinkSend(pLlcpSocket->psTransport, 20685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly &pLlcpSocket->sLlcpHeader, 20695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NULL, 20705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NULL, 20715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phFriNfc_LlcpTransport_ConnectionOriented_SendLlcp_CB, 20727c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen pLlcpSocket->index, 20735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->psTransport); 20747c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen if(status != NFCSTATUS_SUCCESS && status != NFCSTATUS_PENDING) 207528235f8b29ef8cc368dd132080245778cdf704ccArnaud Ferir { 20767c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen clearSendPending(pLlcpSocket->psTransport); 207728235f8b29ef8cc368dd132080245778cdf704ccArnaud Ferir LLCP_PRINT("Release Disconnect callback"); 2078837efc3194a03beaaa32b370c63a9270ed9664d8Martijn Coenen pLlcpSocket->pfSocketDisconnect_Cb = NULL; 2079837efc3194a03beaaa32b370c63a9270ed9664d8Martijn Coenen pLlcpSocket->pDisconnectContext = NULL; 208028235f8b29ef8cc368dd132080245778cdf704ccArnaud Ferir } 20815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 208228235f8b29ef8cc368dd132080245778cdf704ccArnaud Ferir 20835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return status; 20845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 20855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 20865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/* TODO: comment function phFriNfc_LlcpTransport_Connectionless_SendTo_CB */ 20875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic void phFriNfc_LlcpTransport_ConnectionOriented_DisconnectClose_CB(void* pContext, 20885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS status) 20895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 20905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phFriNfc_LlcpTransport_Socket_t *pLlcpSocket = (phFriNfc_LlcpTransport_Socket_t*)pContext; 20915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 20925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(status == NFCSTATUS_SUCCESS) 20935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 20945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Reset the pointer to the socket closed */ 20955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketDefault; 20965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->eSocket_Type = phFriNfc_LlcpTransport_eDefaultType; 20975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->pContext = NULL; 20985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->pSocketErrCb = NULL; 20995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->socket_sSap = PHFRINFC_LLCP_SAP_DEFAULT; 21005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->socket_dSap = PHFRINFC_LLCP_SAP_DEFAULT; 21015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->bSocketRecvPending = FALSE; 21025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->bSocketSendPending = FALSE; 21035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->bSocketListenPending = FALSE; 21045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->bSocketDiscPending = FALSE; 21055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->socket_VS = 0; 21065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->socket_VSA = 0; 21075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->socket_VR = 0; 21085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->socket_VRA = 0; 2109c2866714540bec65af19240e95a10d3090df0cf9Sylvain Fonteneau 2110ffdbd5c4c6574af205d7bb657c9aec025db6e8acSunil Jogi pLlcpSocket->indexRwRead = 0; 2111ffdbd5c4c6574af205d7bb657c9aec025db6e8acSunil Jogi pLlcpSocket->indexRwWrite = 0; 2112ffdbd5c4c6574af205d7bb657c9aec025db6e8acSunil Jogi 21131c75e8952d88d81c5f04826f69ca22d14bb5683bSylvain Fonteneau phFriNfc_LlcpTransport_ConnectionOriented_Abort(pLlcpSocket); 21141c75e8952d88d81c5f04826f69ca22d14bb5683bSylvain Fonteneau 2115c2866714540bec65af19240e95a10d3090df0cf9Sylvain Fonteneau memset(&pLlcpSocket->sSocketOption, 0x00, sizeof(phFriNfc_LlcpTransport_sSocketOptions_t)); 2116c2866714540bec65af19240e95a10d3090df0cf9Sylvain Fonteneau 2117cf5cd1520ea32d2b65712a36a105f396df07345cSylvain Fonteneau if (pLlcpSocket->sServiceName.buffer != NULL) { 2118cf5cd1520ea32d2b65712a36a105f396df07345cSylvain Fonteneau phOsalNfc_FreeMemory(pLlcpSocket->sServiceName.buffer); 2119cf5cd1520ea32d2b65712a36a105f396df07345cSylvain Fonteneau } 2120cf5cd1520ea32d2b65712a36a105f396df07345cSylvain Fonteneau pLlcpSocket->sServiceName.buffer = NULL; 2121cf5cd1520ea32d2b65712a36a105f396df07345cSylvain Fonteneau pLlcpSocket->sServiceName.length = 0; 21225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 21235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 21245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 21255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Disconnect close Error */ 21265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 21275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 21285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 21295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/** 21305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \ingroup grp_fri_nfc 21315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \brief <b>Close a socket on a LLCP-connected device</b>. 21325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* 21335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* This function closes a LLCP socket previously created using phFriNfc_LlcpTransport_Socket. 21345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* If the socket was connected, it is first disconnected, and then closed. 21355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* 21365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t. 21375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 21385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_SUCCESS Operation successful. 21395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters 21405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* could not be properly interpreted. 21415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_FAILED Operation failed. 21425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/ 21435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_Close(phFriNfc_LlcpTransport_Socket_t* pLlcpSocket) 21445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 21455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS status = NFCSTATUS_SUCCESS; 21465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 21475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(pLlcpSocket->eSocket_State == phFriNfc_LlcpTransportSocket_eSocketConnected) 21485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 21495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly status = phLibNfc_LlcpTransport_ConnectionOriented_Disconnect(pLlcpSocket, 21505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phFriNfc_LlcpTransport_ConnectionOriented_DisconnectClose_CB, 21515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket); 21525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 21535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 21545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 21551c75e8952d88d81c5f04826f69ca22d14bb5683bSylvain Fonteneau LLCP_PRINT("Socket not connected, no need to disconnect"); 21565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Reset the pointer to the socket closed */ 21575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketDefault; 21585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->eSocket_Type = phFriNfc_LlcpTransport_eDefaultType; 21595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->pContext = NULL; 21605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->pSocketErrCb = NULL; 21615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->socket_sSap = PHFRINFC_LLCP_SAP_DEFAULT; 21625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->socket_dSap = PHFRINFC_LLCP_SAP_DEFAULT; 21635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->bSocketRecvPending = FALSE; 21645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->bSocketSendPending = FALSE; 21655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->bSocketListenPending = FALSE; 21665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->bSocketDiscPending = FALSE; 21675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->RemoteBusyConditionInfo = FALSE; 21685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->ReceiverBusyCondition = FALSE; 21695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->socket_VS = 0; 21705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->socket_VSA = 0; 21715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->socket_VR = 0; 21725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->socket_VRA = 0; 2173cf5cd1520ea32d2b65712a36a105f396df07345cSylvain Fonteneau 2174ffdbd5c4c6574af205d7bb657c9aec025db6e8acSunil Jogi pLlcpSocket->indexRwRead = 0; 2175ffdbd5c4c6574af205d7bb657c9aec025db6e8acSunil Jogi pLlcpSocket->indexRwWrite = 0; 2176ffdbd5c4c6574af205d7bb657c9aec025db6e8acSunil Jogi 21771c75e8952d88d81c5f04826f69ca22d14bb5683bSylvain Fonteneau phFriNfc_LlcpTransport_ConnectionOriented_Abort(pLlcpSocket); 21781c75e8952d88d81c5f04826f69ca22d14bb5683bSylvain Fonteneau 2179c2866714540bec65af19240e95a10d3090df0cf9Sylvain Fonteneau memset(&pLlcpSocket->sSocketOption, 0x00, sizeof(phFriNfc_LlcpTransport_sSocketOptions_t)); 2180c2866714540bec65af19240e95a10d3090df0cf9Sylvain Fonteneau 2181cf5cd1520ea32d2b65712a36a105f396df07345cSylvain Fonteneau if (pLlcpSocket->sServiceName.buffer != NULL) { 2182cf5cd1520ea32d2b65712a36a105f396df07345cSylvain Fonteneau phOsalNfc_FreeMemory(pLlcpSocket->sServiceName.buffer); 2183cf5cd1520ea32d2b65712a36a105f396df07345cSylvain Fonteneau } 2184cf5cd1520ea32d2b65712a36a105f396df07345cSylvain Fonteneau pLlcpSocket->sServiceName.buffer = NULL; 2185cf5cd1520ea32d2b65712a36a105f396df07345cSylvain Fonteneau pLlcpSocket->sServiceName.length = 0; 21865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 21875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return NFCSTATUS_SUCCESS; 21885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 21895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 21905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 21915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/** 21925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \ingroup grp_fri_nfc 21935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \brief <b>Send data on a socket</b>. 21945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* 21955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* This function is used to write data on a socket. This function 21965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* can only be called on a connection-oriented socket which is already 21975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* in a connected state. 21985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* 21995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* 22005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t. 22015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in] psBuffer The buffer containing the data to send. 22025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in] pSend_RspCb The callback to be called when the 22035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* operation is completed. 22045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in] pContext Upper layer context to be returned in 22055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* the callback. 22065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* 22075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_SUCCESS Operation successful. 22085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters 22095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* could not be properly interpreted. 22105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_PENDING Reception operation is in progress, 22115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* pSend_RspCb will be called upon completion. 22125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_INVALID_STATE The socket is not in a valid state, or not of 22135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* a valid type to perform the requsted operation. 22145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_FAILED Operation failed. 22155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/ 22165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_Send(phFriNfc_LlcpTransport_Socket_t* pLlcpSocket, 22175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phNfc_sData_t* psBuffer, 22185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pphFriNfc_LlcpTransportSocketSendCb_t pSend_RspCb, 22195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly void* pContext) 22205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 22215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS status = NFCSTATUS_SUCCESS; 22225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 22235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 22245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test the RW window */ 22258608ad938da280b895e3bb71435d6fe34c589219Sylvain Fonteneau if(!CHECK_SEND_RW(pLlcpSocket)) 22265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 22275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Store the Send CB and context */ 22285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->pfSocketSend_Cb = pSend_RspCb; 22295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->pSendContext = pContext; 22305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 22315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Set Send pending */ 22325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->bSocketSendPending = TRUE; 22335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 22345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Store send buffer pointer */ 22355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->sSocketSendBuffer = *psBuffer; 22365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 2237a3af9c908f5c50e2405169015c86a1b667b42490Arnaud Ferir /* Set status */ 2238a3af9c908f5c50e2405169015c86a1b667b42490Arnaud Ferir status = NFCSTATUS_PENDING; 22395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 22405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 22415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 224260d8ea84bfbf2dabd0e851edd812f89d42043c1aSylvain Fonteneau /* Store send buffer pointer */ 224360d8ea84bfbf2dabd0e851edd812f89d42043c1aSylvain Fonteneau pLlcpSocket->sSocketSendBuffer = *psBuffer; 224460d8ea84bfbf2dabd0e851edd812f89d42043c1aSylvain Fonteneau 224560d8ea84bfbf2dabd0e851edd812f89d42043c1aSylvain Fonteneau /* Store the Send CB and context */ 224660d8ea84bfbf2dabd0e851edd812f89d42043c1aSylvain Fonteneau pLlcpSocket->pfSocketSend_Cb = pSend_RspCb; 224760d8ea84bfbf2dabd0e851edd812f89d42043c1aSylvain Fonteneau pLlcpSocket->pSendContext = pContext; 224860d8ea84bfbf2dabd0e851edd812f89d42043c1aSylvain Fonteneau 22495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test if a send is pending */ 22507c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen if(testAndSetSendPending(pLlcpSocket->psTransport)) 22515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 22525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Set Send pending */ 22535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->bSocketSendPending = TRUE; 22545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 22555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Set status */ 22565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly status = NFCSTATUS_PENDING; 22575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 22585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 22595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 2260955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi /* Store the Send CB and context */ 2261955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi pLlcpSocket->pfSocketSend_Cb = pSend_RspCb; 2262955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi pLlcpSocket->pSendContext = pContext; 2263955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi 226460d8ea84bfbf2dabd0e851edd812f89d42043c1aSylvain Fonteneau status = static_performSendInfo(pLlcpSocket); 2265955a8efe369ece977e4757f0ae37b3931169125bSunil Jogi 22667c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen if(status != NFCSTATUS_SUCCESS && status != NFCSTATUS_PENDING) 226728235f8b29ef8cc368dd132080245778cdf704ccArnaud Ferir { 22687c4b4fadb66959c50c170182847886e83393eebfMartijn Coenen clearSendPending(pLlcpSocket->psTransport); 226928235f8b29ef8cc368dd132080245778cdf704ccArnaud Ferir LLCP_PRINT("Release Send callback"); 227028235f8b29ef8cc368dd132080245778cdf704ccArnaud Ferir pLlcpSocket->pfSocketSend_Cb = NULL; 227128235f8b29ef8cc368dd132080245778cdf704ccArnaud Ferir pLlcpSocket->pSendContext = NULL; 227228235f8b29ef8cc368dd132080245778cdf704ccArnaud Ferir } 22735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 22745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 22755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 22765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return status; 22775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 22785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 22795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 22805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /** 22815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \ingroup grp_fri_nfc 22825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \brief <b>Read data on a socket</b>. 22835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* 22845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* This function is used to read data from a socket. It reads at most the 22855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* size of the reception buffer, but can also return less bytes if less bytes 22865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* are available. If no data is available, the function will be pending until 22875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* more data comes, and the response will be sent by the callback. This function 22885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* can only be called on a connection-oriented socket. 22895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* 22905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* 22915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t. 22925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in] psBuffer The buffer receiving the data. 22935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in] pRecv_RspCb The callback to be called when the 22945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* operation is completed. 22955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in] pContext Upper layer context to be returned in 22965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* the callback. 22975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* 22985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_SUCCESS Operation successful. 22995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters 23005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* could not be properly interpreted. 23015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_PENDING Reception operation is in progress, 23025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* pRecv_RspCb will be called upon completion. 23035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_INVALID_STATE The socket is not in a valid state, or not of 23045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* a valid type to perform the requsted operation. 23055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_FAILED Operation failed. 23065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/ 23075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_Recv( phFriNfc_LlcpTransport_Socket_t* pLlcpSocket, 23085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phNfc_sData_t* psBuffer, 23095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pphFriNfc_LlcpTransportSocketRecvCb_t pRecv_RspCb, 23105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly void* pContext) 23115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 23125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS status = NFCSTATUS_SUCCESS; 23135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint32_t dataLengthStored = 0; 23145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint32_t dataLengthAvailable = 0; 23155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint32_t dataLengthRead = 0; 23165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly uint32_t dataLengthWrite = 0; 23175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly bool_t dataBufferized = FALSE; 23185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 23195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test if the WorkingBuffer Length is null */ 23205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(pLlcpSocket->bufferLinearLength == 0) 23215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 232204f25b3ab4ed13edb3ffc8e7354bca9f7bc60b44Sylvain Fonteneau if (pLlcpSocket->eSocket_State != phFriNfc_LlcpTransportSocket_eSocketConnected) 232304f25b3ab4ed13edb3ffc8e7354bca9f7bc60b44Sylvain Fonteneau { 2324a3af9c908f5c50e2405169015c86a1b667b42490Arnaud Ferir return NFCSTATUS_FAILED; 232504f25b3ab4ed13edb3ffc8e7354bca9f7bc60b44Sylvain Fonteneau } 232604f25b3ab4ed13edb3ffc8e7354bca9f7bc60b44Sylvain Fonteneau 23275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test If data is present in the RW Buffer */ 23285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(pLlcpSocket->indexRwRead != pLlcpSocket->indexRwWrite) 23295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 23305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(pLlcpSocket->sSocketRwBufferTable[(pLlcpSocket->indexRwRead%pLlcpSocket->localRW)].length != 0) 23315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 23325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Save I_FRAME into the Receive Buffer */ 23335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly memcpy(psBuffer->buffer,pLlcpSocket->sSocketRwBufferTable[(pLlcpSocket->indexRwRead%pLlcpSocket->localRW)].buffer,pLlcpSocket->sSocketRwBufferTable[(pLlcpSocket->indexRwRead%pLlcpSocket->localRW)].length); 23345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psBuffer->length = pLlcpSocket->sSocketRwBufferTable[(pLlcpSocket->indexRwRead%pLlcpSocket->localRW)].length; 23355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 23365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly dataBufferized = TRUE; 23375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 23385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Update VR */ 23395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->socket_VR = (pLlcpSocket->socket_VR+1)%16; 23405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 23415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Update RW Buffer length */ 23425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->sSocketRwBufferTable[(pLlcpSocket->indexRwRead%pLlcpSocket->localRW)].length = 0; 23435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 23445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Update Value Rw Read Index*/ 23455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->indexRwRead++; 23465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 23475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 23485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 23495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(dataBufferized == TRUE) 23505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 23515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Call the Receive CB */ 23525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pRecv_RspCb(pContext,NFCSTATUS_SUCCESS); 23535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 23545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(pLlcpSocket->ReceiverBusyCondition == TRUE) 23555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 23565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Reset the ReceiverBusyCondition Flag */ 23575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->ReceiverBusyCondition = FALSE; 23585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* RR */ 2359a3af9c908f5c50e2405169015c86a1b667b42490Arnaud Ferir /* TODO: report status? */ 23605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phFriNfc_Llcp_Send_ReceiveReady_Frame(pLlcpSocket); 23615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 23625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 23635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 23645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 23655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Set Receive pending */ 23665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->bSocketRecvPending = TRUE; 23675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 23685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Store the buffer pointer */ 23695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->sSocketRecvBuffer = psBuffer; 23705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 23715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Store the Recv CB and context */ 23725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->pfSocketRecv_Cb = pRecv_RspCb; 23735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->pRecvContext = pContext; 23745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 23755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Set status */ 23765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly status = NFCSTATUS_PENDING; 23775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 23785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 23795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 23805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 23815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test if data is present in the linear buffer*/ 23825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly dataLengthStored = phFriNfc_Llcp_CyclicFifoUsage(&pLlcpSocket->sCyclicFifoBuffer); 23835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 23845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(dataLengthStored != 0) 23855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 23865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(psBuffer->length > dataLengthStored) 23875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 23885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psBuffer->length = dataLengthStored; 23895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 23905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 23915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Read data from the linear buffer */ 23925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly dataLengthRead = phFriNfc_Llcp_CyclicFifoFifoRead(&pLlcpSocket->sCyclicFifoBuffer, 23935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psBuffer->buffer, 23945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly psBuffer->length); 23955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 23965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(dataLengthRead != 0) 23975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 23985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test If data is present in the RW Buffer */ 2399379262748505107b88ec92675529063789e44da6Sylvain Fonteneau while(pLlcpSocket->indexRwRead != pLlcpSocket->indexRwWrite) 24005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 2401379262748505107b88ec92675529063789e44da6Sylvain Fonteneau /* Get the data length available in the linear buffer */ 2402379262748505107b88ec92675529063789e44da6Sylvain Fonteneau dataLengthAvailable = phFriNfc_Llcp_CyclicFifoAvailable(&pLlcpSocket->sCyclicFifoBuffer); 2403379262748505107b88ec92675529063789e44da6Sylvain Fonteneau 2404379262748505107b88ec92675529063789e44da6Sylvain Fonteneau /* Exit if not enough memory available in linear buffer */ 2405379262748505107b88ec92675529063789e44da6Sylvain Fonteneau if(dataLengthAvailable < pLlcpSocket->sSocketRwBufferTable[(pLlcpSocket->indexRwRead%pLlcpSocket->localRW)].length) 24065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 2407379262748505107b88ec92675529063789e44da6Sylvain Fonteneau break; 2408379262748505107b88ec92675529063789e44da6Sylvain Fonteneau } 24095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 2410379262748505107b88ec92675529063789e44da6Sylvain Fonteneau /* Write data into the linear buffer */ 2411379262748505107b88ec92675529063789e44da6Sylvain Fonteneau dataLengthWrite = phFriNfc_Llcp_CyclicFifoWrite(&pLlcpSocket->sCyclicFifoBuffer, 2412379262748505107b88ec92675529063789e44da6Sylvain Fonteneau pLlcpSocket->sSocketRwBufferTable[(pLlcpSocket->indexRwRead%pLlcpSocket->localRW)].buffer, 2413379262748505107b88ec92675529063789e44da6Sylvain Fonteneau pLlcpSocket->sSocketRwBufferTable[(pLlcpSocket->indexRwRead%pLlcpSocket->localRW)].length); 2414379262748505107b88ec92675529063789e44da6Sylvain Fonteneau /* Update VR */ 2415379262748505107b88ec92675529063789e44da6Sylvain Fonteneau pLlcpSocket->socket_VR = (pLlcpSocket->socket_VR+1)%16; 24165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 2417379262748505107b88ec92675529063789e44da6Sylvain Fonteneau /* Set flag bufferized to TRUE */ 2418379262748505107b88ec92675529063789e44da6Sylvain Fonteneau dataBufferized = TRUE; 24195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 2420379262748505107b88ec92675529063789e44da6Sylvain Fonteneau /* Update RW Buffer length */ 2421379262748505107b88ec92675529063789e44da6Sylvain Fonteneau pLlcpSocket->sSocketRwBufferTable[(pLlcpSocket->indexRwRead%pLlcpSocket->localRW)].length = 0; 24225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 2423379262748505107b88ec92675529063789e44da6Sylvain Fonteneau /* Update Value Rw Read Index*/ 2424379262748505107b88ec92675529063789e44da6Sylvain Fonteneau pLlcpSocket->indexRwRead++; 24255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 24265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 24275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Test if data has been bufferized after a read access */ 24285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if(dataBufferized == TRUE) 24295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 24305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Get the data length available in the linear buffer */ 24315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly dataLengthAvailable = phFriNfc_Llcp_CyclicFifoAvailable(&pLlcpSocket->sCyclicFifoBuffer); 2432c2866714540bec65af19240e95a10d3090df0cf9Sylvain Fonteneau if((dataLengthAvailable >= pLlcpSocket->sSocketOption.miu) && (pLlcpSocket->ReceiverBusyCondition == TRUE)) 24335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 24345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Reset the ReceiverBusyCondition Flag */ 24355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pLlcpSocket->ReceiverBusyCondition = FALSE; 24365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* RR */ 2437a3af9c908f5c50e2405169015c86a1b667b42490Arnaud Ferir /* TODO: report status? */ 24385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phFriNfc_Llcp_Send_ReceiveReady_Frame(pLlcpSocket); 24395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 24405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 24415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 24425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Call the Receive CB */ 24435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pRecv_RspCb(pContext,NFCSTATUS_SUCCESS); 24445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 24455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 24465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 24475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /* Call the Receive CB */ 2448a3af9c908f5c50e2405169015c86a1b667b42490Arnaud Ferir status = NFCSTATUS_FAILED; 24495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 24505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 24515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 24525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 245304f25b3ab4ed13edb3ffc8e7354bca9f7bc60b44Sylvain Fonteneau if (pLlcpSocket->eSocket_State != phFriNfc_LlcpTransportSocket_eSocketConnected) 245404f25b3ab4ed13edb3ffc8e7354bca9f7bc60b44Sylvain Fonteneau { 2455a3af9c908f5c50e2405169015c86a1b667b42490Arnaud Ferir status = NFCSTATUS_FAILED; 245604f25b3ab4ed13edb3ffc8e7354bca9f7bc60b44Sylvain Fonteneau } 2457a3af9c908f5c50e2405169015c86a1b667b42490Arnaud Ferir else 2458a3af9c908f5c50e2405169015c86a1b667b42490Arnaud Ferir { 2459a3af9c908f5c50e2405169015c86a1b667b42490Arnaud Ferir /* Set Receive pending */ 2460a3af9c908f5c50e2405169015c86a1b667b42490Arnaud Ferir pLlcpSocket->bSocketRecvPending = TRUE; 246104f25b3ab4ed13edb3ffc8e7354bca9f7bc60b44Sylvain Fonteneau 2462a3af9c908f5c50e2405169015c86a1b667b42490Arnaud Ferir /* Store the buffer pointer */ 2463a3af9c908f5c50e2405169015c86a1b667b42490Arnaud Ferir pLlcpSocket->sSocketRecvBuffer = psBuffer; 24645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 2465a3af9c908f5c50e2405169015c86a1b667b42490Arnaud Ferir /* Store the Recv CB and context */ 2466a3af9c908f5c50e2405169015c86a1b667b42490Arnaud Ferir pLlcpSocket->pfSocketRecv_Cb = pRecv_RspCb; 2467a3af9c908f5c50e2405169015c86a1b667b42490Arnaud Ferir pLlcpSocket->pRecvContext = pContext; 24685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 2469a3af9c908f5c50e2405169015c86a1b667b42490Arnaud Ferir /* Set status */ 2470a3af9c908f5c50e2405169015c86a1b667b42490Arnaud Ferir status = NFCSTATUS_PENDING; 2471a3af9c908f5c50e2405169015c86a1b667b42490Arnaud Ferir } 24725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 24735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 24745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 247528235f8b29ef8cc368dd132080245778cdf704ccArnaud Ferir if(status != NFCSTATUS_PENDING) 247628235f8b29ef8cc368dd132080245778cdf704ccArnaud Ferir { 247728235f8b29ef8cc368dd132080245778cdf704ccArnaud Ferir /* Note: The receive callback must be released to avoid being called at abort */ 247828235f8b29ef8cc368dd132080245778cdf704ccArnaud Ferir LLCP_PRINT("Release Receive callback"); 247928235f8b29ef8cc368dd132080245778cdf704ccArnaud Ferir pLlcpSocket->pfSocketRecv_Cb = NULL; 248028235f8b29ef8cc368dd132080245778cdf704ccArnaud Ferir pLlcpSocket->pRecvContext = NULL; 248128235f8b29ef8cc368dd132080245778cdf704ccArnaud Ferir } 248228235f8b29ef8cc368dd132080245778cdf704ccArnaud Ferir 24835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return status; 24845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 24855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 24865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 2487