phFriNfc_LlcpTransport.c revision c2866714540bec65af19240e95a10d3090df0cf9
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.c
195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \brief
205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *
215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * Project: NFC-FRI
225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *
235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */
245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*include files*/
26cf5cd1520ea32d2b65712a36a105f396df07345cSylvain Fonteneau#include <phOsalNfc.h>
275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phLibNfcStatus.h>
285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phLibNfc.h>
295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phNfcLlcpTypes.h>
305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phFriNfc_Llcp.h>
315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phFriNfc_LlcpTransport.h>
325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phFriNfc_LlcpTransport_Connectionless.h>
335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phFriNfc_LlcpTransport_Connection.h>
345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/* TODO: comment function Transport recv CB */
375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic void phFriNfc_LlcpTransport__Recv_CB(void            *pContext,
385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                            phNfc_sData_t   *psData,
395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                            NFCSTATUS        status)
405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   phFriNfc_Llcp_sPacketHeader_t   sLlcpLocalHeader;
425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   uint8_t   dsap;
435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   uint8_t   ptype;
445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   uint8_t   ssap;
455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   phFriNfc_LlcpTransport_t* pLlcpTransport = (phFriNfc_LlcpTransport_t*)pContext;
475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   if(status != NFCSTATUS_SUCCESS)
495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      pLlcpTransport->LinkStatusError = TRUE;
515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else
535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      phFriNfc_Llcp_Buffer2Header( psData->buffer,0x00, &sLlcpLocalHeader);
555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      dsap  = (uint8_t)sLlcpLocalHeader.dsap;
575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      ptype = (uint8_t)sLlcpLocalHeader.ptype;
585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      ssap  = (uint8_t)sLlcpLocalHeader.ssap;
595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      /* Update the length value (without the header length) */
615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      psData->length = psData->length - PHFRINFC_LLCP_PACKET_HEADER_SIZE;
625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      /* Update the buffer pointer */
645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      psData->buffer = psData->buffer + PHFRINFC_LLCP_PACKET_HEADER_SIZE;
655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      switch(ptype)
675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      {
685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      /* Connectionless */
695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      case PHFRINFC_LLCP_PTYPE_UI:
705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         {
715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            Handle_Connectionless_IncommingFrame(pLlcpTransport,
725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                 psData,
735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                 dsap,
745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                 ssap);
755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         }break;
765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      /* Connection oriented */
785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      /* NOTE: forward reserved PTYPE to enable FRMR sending */
795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      case PHFRINFC_LLCP_PTYPE_CONNECT:
805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      case PHFRINFC_LLCP_PTYPE_CC:
815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      case PHFRINFC_LLCP_PTYPE_DISC:
825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      case PHFRINFC_LLCP_PTYPE_DM:
835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      case PHFRINFC_LLCP_PTYPE_I:
845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      case PHFRINFC_LLCP_PTYPE_RR:
855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      case PHFRINFC_LLCP_PTYPE_RNR:
865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      case PHFRINFC_LLCP_PTYPE_FRMR:
875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      case PHFRINFC_LLCP_PTYPE_RESERVED1:
885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      case PHFRINFC_LLCP_PTYPE_RESERVED2:
895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      case PHFRINFC_LLCP_PTYPE_RESERVED3:
905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      case PHFRINFC_LLCP_PTYPE_RESERVED4:
915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         {
925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            Handle_ConnectionOriented_IncommingFrame(pLlcpTransport,
935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                     psData,
945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                     dsap,
955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                     ptype,
965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                     ssap);
975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         }break;
985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      default:
995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         {
1005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         }break;
1025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      }
1035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      /*Restart the Receive Loop */
1055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status  = phFriNfc_Llcp_Recv(pLlcpTransport->pLlcp,
1065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                   phFriNfc_LlcpTransport__Recv_CB,
1075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                   pLlcpTransport);
1085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
1095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
1105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/* TODO: comment function Transport reset */
1135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS phFriNfc_LlcpTransport_Reset (phFriNfc_LlcpTransport_t      *pLlcpTransport,
1145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                        phFriNfc_Llcp_t               *pLlcp)
1155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
1165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   NFCSTATUS status = NFCSTATUS_SUCCESS;
1175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   uint8_t i;
1185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   /* Check for NULL pointers */
1205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   if(pLlcpTransport == NULL || pLlcp == NULL)
1215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
1225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
1235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
1245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else
1255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
1265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      /* Reset Transport structure */
1275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      pLlcpTransport->pLlcp            = pLlcp;
1285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      pLlcpTransport->LinkStatusError  = FALSE;
1295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      pLlcpTransport->bSendPending     = FALSE;
1305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      pLlcpTransport->bRecvPending     = FALSE;
1315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      pLlcpTransport->bDmPending       = FALSE;
1325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      pLlcpTransport->bFrmrPending     = FALSE;
1335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      pLlcpTransport->socketIndex      = FALSE;
1345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      pLlcpTransport->LinkStatusError  = 0;
1355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      /* Reset all the socket info in the table */
1385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      for(i=0;i<PHFRINFC_LLCP_NB_SOCKET_MAX;i++)
1395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      {
1405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         pLlcpTransport->pSocketTable[i].eSocket_State                  = phFriNfc_LlcpTransportSocket_eSocketDefault;
1415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         pLlcpTransport->pSocketTable[i].eSocket_Type                   = phFriNfc_LlcpTransport_eDefaultType;
1425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         pLlcpTransport->pSocketTable[i].index                          = i;
1435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         pLlcpTransport->pSocketTable[i].pContext                       = NULL;
1445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         pLlcpTransport->pSocketTable[i].pListenContext                 = NULL;
1455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         pLlcpTransport->pSocketTable[i].pAcceptContext                 = NULL;
1465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         pLlcpTransport->pSocketTable[i].pRejectContext                 = NULL;
1475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         pLlcpTransport->pSocketTable[i].pConnectContext                = NULL;
1485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         pLlcpTransport->pSocketTable[i].pDisonnectContext              = NULL;
1495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         pLlcpTransport->pSocketTable[i].pSendContext                   = NULL;
1505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         pLlcpTransport->pSocketTable[i].pRecvContext                   = NULL;
1515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         pLlcpTransport->pSocketTable[i].pSocketErrCb                   = NULL;
1525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         pLlcpTransport->pSocketTable[i].bufferLinearLength             = 0;
1535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         pLlcpTransport->pSocketTable[i].bufferSendMaxLength            = 0;
1545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         pLlcpTransport->pSocketTable[i].bufferRwMaxLength              = 0;
1555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         pLlcpTransport->pSocketTable[i].ReceiverBusyCondition          = FALSE;
1565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         pLlcpTransport->pSocketTable[i].RemoteBusyConditionInfo        = FALSE;
1575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         pLlcpTransport->pSocketTable[i].socket_sSap                    = PHFRINFC_LLCP_SAP_DEFAULT;
1585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         pLlcpTransport->pSocketTable[i].socket_dSap                    = PHFRINFC_LLCP_SAP_DEFAULT;
1595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         pLlcpTransport->pSocketTable[i].bSocketRecvPending             = FALSE;
1605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         pLlcpTransport->pSocketTable[i].bSocketSendPending             = FALSE;
1615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         pLlcpTransport->pSocketTable[i].bSocketListenPending           = FALSE;
1625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         pLlcpTransport->pSocketTable[i].bSocketDiscPending             = FALSE;
1635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         pLlcpTransport->pSocketTable[i].bSocketConnectPending          = FALSE;
1645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         pLlcpTransport->pSocketTable[i].bSocketAcceptPending           = FALSE;
1655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         pLlcpTransport->pSocketTable[i].bSocketRRPending               = FALSE;
1665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         pLlcpTransport->pSocketTable[i].bSocketRNRPending              = FALSE;
1675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         pLlcpTransport->pSocketTable[i].psTransport                    = pLlcpTransport;
1685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         pLlcpTransport->pSocketTable[i].pfSocketSend_Cb                = NULL;
1695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         pLlcpTransport->pSocketTable[i].pfSocketRecv_Cb                = NULL;
1705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         pLlcpTransport->pSocketTable[i].pfSocketRecvFrom_Cb            = NULL;
1715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         pLlcpTransport->pSocketTable[i].pfSocketListen_Cb              = NULL;
1725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         pLlcpTransport->pSocketTable[i].pfSocketConnect_Cb             = NULL;
1735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         pLlcpTransport->pSocketTable[i].pfSocketDisconnect_Cb          = NULL;
1745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         pLlcpTransport->pSocketTable[i].socket_VS                      = 0;
1755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         pLlcpTransport->pSocketTable[i].socket_VSA                     = 0;
1765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         pLlcpTransport->pSocketTable[i].socket_VR                      = 0;
1775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         pLlcpTransport->pSocketTable[i].socket_VRA                     = 0;
1785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         pLlcpTransport->pSocketTable[i].remoteRW                       = 0;
1795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         pLlcpTransport->pSocketTable[i].localRW                        = 0;
1805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         pLlcpTransport->pSocketTable[i].remoteMIU                      = 0;
1815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         pLlcpTransport->pSocketTable[i].localMIUX                      = 0;
1825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         pLlcpTransport->pSocketTable[i].index                          = 0;
1835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         pLlcpTransport->pSocketTable[i].indexRwRead                    = 0;
1845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         pLlcpTransport->pSocketTable[i].indexRwWrite                   = 0;
185cf5cd1520ea32d2b65712a36a105f396df07345cSylvain Fonteneau
186c2866714540bec65af19240e95a10d3090df0cf9Sylvain Fonteneau         memset(&pLlcpTransport->pSocketTable[i].sSocketOption, 0x00, sizeof(phFriNfc_LlcpTransport_sSocketOptions_t));
187c2866714540bec65af19240e95a10d3090df0cf9Sylvain Fonteneau
188cf5cd1520ea32d2b65712a36a105f396df07345cSylvain Fonteneau         if (pLlcpTransport->pSocketTable[i].sServiceName.buffer != NULL) {
189cf5cd1520ea32d2b65712a36a105f396df07345cSylvain Fonteneau            phOsalNfc_FreeMemory(pLlcpTransport->pSocketTable[i].sServiceName.buffer);
190cf5cd1520ea32d2b65712a36a105f396df07345cSylvain Fonteneau         }
191cf5cd1520ea32d2b65712a36a105f396df07345cSylvain Fonteneau         pLlcpTransport->pSocketTable[i].sServiceName.buffer = NULL;
192cf5cd1520ea32d2b65712a36a105f396df07345cSylvain Fonteneau         pLlcpTransport->pSocketTable[i].sServiceName.length = 0;
1935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      }
1945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      /* Start The Receive Loop */
1965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status  = phFriNfc_Llcp_Recv(pLlcpTransport->pLlcp,
1975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                   phFriNfc_LlcpTransport__Recv_CB,
1985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                   pLlcpTransport);
1995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
2005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   return status;
2015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
2025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
2035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/**
2045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \ingroup grp_lib_nfc
2055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \brief <b>Get the local options of a socket</b>.
2065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
2075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* This function returns the local options (maximum packet size and receive window size) used
2085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* for a given connection-oriented socket. This function shall not be used with connectionless
2095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* sockets.
2105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
2115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[out] pLlcpSocket           A pointer to a phFriNfc_LlcpTransport_Socket_t.
2125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in]  psLocalOptions        A pointer to be filled with the local options of the socket.
2135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
2145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_SUCCESS                  Operation successful.
2155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_INVALID_PARAMETER        One or more of the supplied parameters
2165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                            could not be properly interpreted.
2175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_INVALID_STATE            The socket is not in a valid state, or not of
2185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                            a valid type to perform the requsted operation.
2195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_NOT_INITIALISED          Indicates stack is not yet initialized.
2205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_SHUTDOWN                 Shutdown in progress.
2215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_FAILED                   Operation failed.
2225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/
2235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS phFriNfc_LlcpTransport_SocketGetLocalOptions(phFriNfc_LlcpTransport_Socket_t  *pLlcpSocket,
2245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                       phLibNfc_Llcp_sSocketOptions_t   *psLocalOptions)
2255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
2265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   NFCSTATUS status = NFCSTATUS_SUCCESS;
2275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
2285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   /* Check for NULL pointers */
2295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   if (pLlcpSocket == NULL || psLocalOptions == NULL)
2305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
2315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
2325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
2335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   /*  Test the socket type */
2345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else if(pLlcpSocket->eSocket_Type != phFriNfc_LlcpTransport_eConnectionOriented)
2355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
2365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
2375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
2385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   /*  Test the socket state */
2395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else if(pLlcpSocket->eSocket_State == phFriNfc_LlcpTransportSocket_eSocketDefault)
2405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
2415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_STATE);
2425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
2435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else
2445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
2455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly     status = phFriNfc_LlcpTransport_ConnectionOriented_SocketGetLocalOptions(pLlcpSocket,
2465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                                              psLocalOptions);
2475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
2485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
2495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   return status;
2505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
2515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
2525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
2535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/**
2545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \ingroup grp_lib_nfc
2555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \brief <b>Get the local options of a socket</b>.
2565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
2575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* This function returns the remote options (maximum packet size and receive window size) used
2585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* for a given connection-oriented socket. This function shall not be used with connectionless
2595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* sockets.
2605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
2615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[out] pLlcpSocket           A pointer to a phFriNfc_LlcpTransport_Socket_t.
2625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in]  psRemoteOptions       A pointer to be filled with the remote options of the socket.
2635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
2645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_SUCCESS                  Operation successful.
2655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_INVALID_PARAMETER        One or more of the supplied parameters
2665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                            could not be properly interpreted.
2675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_INVALID_STATE            The socket is not in a valid state, or not of
2685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                            a valid type to perform the requsted operation.
2695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_NOT_INITIALISED          Indicates stack is not yet initialized.
2705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_SHUTDOWN                 Shutdown in progress.
2715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_FAILED                   Operation failed.
2725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/
2735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS phFriNfc_LlcpTransport_SocketGetRemoteOptions(phFriNfc_LlcpTransport_Socket_t*   pLlcpSocket,
2745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                        phLibNfc_Llcp_sSocketOptions_t*    psRemoteOptions)
2755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
2765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   NFCSTATUS status = NFCSTATUS_SUCCESS;
2775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
2785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   /* Check for NULL pointers */
2795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   if (pLlcpSocket == NULL || psRemoteOptions == NULL)
2805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
2815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
2825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
2835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   /*  Test the socket type */
2845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else if(pLlcpSocket->eSocket_Type != phFriNfc_LlcpTransport_eConnectionOriented)
2855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
2865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
2875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
2885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   /*  Test the socket state */
2895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else if(pLlcpSocket->eSocket_State != phFriNfc_LlcpTransportSocket_eSocketConnected)
2905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
2915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_STATE);
2925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
2935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else
2945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
2955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = phFriNfc_LlcpTransport_ConnectionOriented_SocketGetRemoteOptions(pLlcpSocket,
2965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                                                psRemoteOptions);
2975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
2985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
2995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   return status;
3005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
3015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
3025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /**
3035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \ingroup grp_fri_nfc
3045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \brief <b>Create a socket on a LLCP-connected device</b>.
3055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
3065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* This function creates a socket for a given LLCP link. Sockets can be of two types :
3075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* connection-oriented and connectionless. If the socket is connection-oriented, the caller
3085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* must provide a working buffer to the socket in order to handle incoming data. This buffer
3095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* must be large enough to fit the receive window (RW * MIU), the remaining space being
3105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* used as a linear buffer to store incoming data as a stream. Data will be readable later
3115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* using the phLibNfc_LlcpTransport_Recv function.
3125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* The options and working buffer are not required if the socket is used as a listening socket,
3135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* since it cannot be directly used for communication.
3145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
3155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in]  pLlcpSocketTable      A pointer to a table of PHFRINFC_LLCP_NB_SOCKET_DEFAULT sockets.
3165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in]  eType                 The socket type.
3175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in]  psOptions             The options to be used with the socket.
3185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in]  psWorkingBuffer       A working buffer to be used by the library.
3195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[out] pLlcpSocket           A pointer on the socket to be filled with a
3205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                    socket found on the socket table.
3215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in]  pErr_Cb               The callback to be called each time the socket
3225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                   is in error.
3235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in]  pContext              Upper layer context to be returned in the callback.
3245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
3255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_SUCCESS                  Operation successful.
3265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_INVALID_PARAMETER        One or more of the supplied parameters
3275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                            could not be properly interpreted.
3285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_BUFFER_TOO_SMALL         The working buffer is too small for the MIU and RW
3295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                            declared in the options.
3305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_INSUFFICIENT_RESOURCES   No more socket handle available.
3315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_FAILED                   Operation failed.
3325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* */
3335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS phFriNfc_LlcpTransport_Socket(phFriNfc_LlcpTransport_t                  *pLlcpTransport,
3345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                        phFriNfc_LlcpTransport_eSocketType_t      eType,
3355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                        phFriNfc_LlcpTransport_sSocketOptions_t   *psOptions,
3365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                        phNfc_sData_t                             *psWorkingBuffer,
3375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                        phFriNfc_LlcpTransport_Socket_t           **pLlcpSocket,
3385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                        pphFriNfc_LlcpTransportSocketErrCb_t      pErr_Cb,
3395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                        void                                      *pContext)
3405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
3415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   NFCSTATUS status = NFCSTATUS_SUCCESS;
3425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   phFriNfc_Llcp_sLinkParameters_t  LlcpLinkParamInfo;
3435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   uint8_t index=0;
3445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   uint8_t cpt;
3455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
3465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   /* Check for NULL pointers */
3475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   if (((NULL == psOptions) && (eType != phFriNfc_LlcpTransport_eConnectionLess)) || ((psWorkingBuffer == NULL) && (eType != phFriNfc_LlcpTransport_eConnectionLess)) || pLlcpSocket == NULL || pErr_Cb == NULL || pContext == NULL || pLlcpTransport == NULL)
3485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
3495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
3505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      return status;
3515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
3525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   /*  Test the socket type*/
3535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else if(eType != phFriNfc_LlcpTransport_eConnectionOriented && eType != phFriNfc_LlcpTransport_eConnectionLess)
3545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
3555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
3565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      return status;
3575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
3585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
3595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   /* Get the local parameters of the LLCP Link */
3605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   status = phFriNfc_Llcp_GetLocalInfo(pLlcpTransport->pLlcp,&LlcpLinkParamInfo);
3615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   if(status != NFCSTATUS_SUCCESS)
3625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
3635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_FAILED);
3645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
3655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else
3665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
3675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      /* Search a socket free in the Socket Table*/
3685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      do
3695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      {
3705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         if(pLlcpTransport->pSocketTable[index].eSocket_State == phFriNfc_LlcpTransportSocket_eSocketDefault)
3715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         {
3725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* Set the socket pointer to socket of the table */
3735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            *pLlcpSocket = &pLlcpTransport->pSocketTable[index];
3745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
3755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* Store the socket info in the socket pointer */
3765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            pLlcpTransport->pSocketTable[index].eSocket_Type     = eType;
3775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            pLlcpTransport->pSocketTable[index].pSocketErrCb     = pErr_Cb;
3785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
3795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* Store the context of the upper layer */
3805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            pLlcpTransport->pSocketTable[index].pContext   = pContext;
3815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
3825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* Set the pointers to the different working buffers */
3835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if(pLlcpTransport->pSocketTable[index].eSocket_Type != phFriNfc_LlcpTransport_eConnectionLess)
3845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
3855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly               /* Test the socket options */
3865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly               if((psOptions->rw > PHFRINFC_LLCP_RW_MAX) && (eType == phFriNfc_LlcpTransport_eConnectionOriented))
3875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly               {
3885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                  status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
3895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly               }
3905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly               /* Set socket options */
391c2866714540bec65af19240e95a10d3090df0cf9Sylvain Fonteneau               memcpy(&pLlcpTransport->pSocketTable[index].sSocketOption, psOptions, sizeof(phFriNfc_LlcpTransport_sSocketOptions_t));
3925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
3935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly               /* Set socket local params (MIUX & RW) */
394c2866714540bec65af19240e95a10d3090df0cf9Sylvain Fonteneau               pLlcpTransport->pSocketTable[index].localMIUX = (pLlcpTransport->pSocketTable[index].sSocketOption.miu - PHFRINFC_LLCP_MIU_DEFAULT) & PHFRINFC_LLCP_TLV_MIUX_MASK;
395c2866714540bec65af19240e95a10d3090df0cf9Sylvain Fonteneau               pLlcpTransport->pSocketTable[index].localRW   = pLlcpTransport->pSocketTable[index].sSocketOption.rw & PHFRINFC_LLCP_TLV_RW_MASK;
3965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
3975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly               /* Set the Max length for the Send and Receive Window Buffer */
398c2866714540bec65af19240e95a10d3090df0cf9Sylvain Fonteneau               pLlcpTransport->pSocketTable[index].bufferSendMaxLength   = pLlcpTransport->pSocketTable[index].sSocketOption.miu;
399c2866714540bec65af19240e95a10d3090df0cf9Sylvain Fonteneau               pLlcpTransport->pSocketTable[index].bufferRwMaxLength     = pLlcpTransport->pSocketTable[index].sSocketOption.miu * ((pLlcpTransport->pSocketTable[index].sSocketOption.rw & PHFRINFC_LLCP_TLV_RW_MASK));
4005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly               pLlcpTransport->pSocketTable[index].bufferLinearLength    = psWorkingBuffer->length - pLlcpTransport->pSocketTable[index].bufferSendMaxLength - pLlcpTransport->pSocketTable[index].bufferRwMaxLength;
4015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
4025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly               /* Test the connection oriented buffers length */
4035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly               if((pLlcpTransport->pSocketTable[index].bufferSendMaxLength + pLlcpTransport->pSocketTable[index].bufferRwMaxLength) > psWorkingBuffer->length
4045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                   || ((pLlcpTransport->pSocketTable[index].bufferLinearLength < PHFRINFC_LLCP_MIU_DEFAULT) && (pLlcpTransport->pSocketTable[index].bufferLinearLength != 0)))
4055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly               {
4065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                  status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_BUFFER_TOO_SMALL);
4075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                  return status;
4085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly               }
4095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
4105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly               /* Set the pointer and the length for the Receive Window Buffer */
4115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly               for(cpt=0;cpt<pLlcpTransport->pSocketTable[index].localRW;cpt++)
4125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly               {
413c2866714540bec65af19240e95a10d3090df0cf9Sylvain Fonteneau                  pLlcpTransport->pSocketTable[index].sSocketRwBufferTable[cpt].buffer = psWorkingBuffer->buffer + (cpt*pLlcpTransport->pSocketTable[index].sSocketOption.miu);
4145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                  pLlcpTransport->pSocketTable[index].sSocketRwBufferTable[cpt].length = 0;
4155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly               }
4165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
4175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly               /* Set the pointer and the length for the Send Buffer */
4185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly               pLlcpTransport->pSocketTable[index].sSocketSendBuffer.buffer     = psWorkingBuffer->buffer + pLlcpTransport->pSocketTable[index].bufferRwMaxLength;
4195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly               pLlcpTransport->pSocketTable[index].sSocketSendBuffer.length     = pLlcpTransport->pSocketTable[index].bufferSendMaxLength;
4205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
4215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly               /** Set the pointer and the length for the Linear Buffer */
4225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly               pLlcpTransport->pSocketTable[index].sSocketLinearBuffer.buffer   = psWorkingBuffer->buffer + pLlcpTransport->pSocketTable[index].bufferRwMaxLength + pLlcpTransport->pSocketTable[index].bufferSendMaxLength;
4235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly               pLlcpTransport->pSocketTable[index].sSocketLinearBuffer.length   = pLlcpTransport->pSocketTable[index].bufferLinearLength;
4245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
4255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly               if(pLlcpTransport->pSocketTable[index].sSocketLinearBuffer.length != 0)
4265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly               {
4275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                  /* Init Cyclic Fifo */
4285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                  phFriNfc_Llcp_CyclicFifoInit(&pLlcpTransport->pSocketTable[index].sCyclicFifoBuffer,
4295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                               pLlcpTransport->pSocketTable[index].sSocketLinearBuffer.buffer,
4305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                               pLlcpTransport->pSocketTable[index].sSocketLinearBuffer.length);
4315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly               }
4325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
4335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* Store index of the socket */
4345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            pLlcpTransport->pSocketTable[index].index = index;
4355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
4365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* Set the socket into created state */
4375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            pLlcpTransport->pSocketTable[index].eSocket_State = phFriNfc_LlcpTransportSocket_eSocketCreated;
4385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            return status;
4395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         }
4405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         else
4415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         {
4425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            index++;
4435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         }
4445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      }while(index<PHFRINFC_LLCP_NB_SOCKET_MAX);
4455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
4465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INSUFFICIENT_RESOURCES);
4475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
4485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   return status;
4495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
4505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
4515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/**
4525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \ingroup grp_fri_nfc
4535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \brief <b>Close a socket on a LLCP-connected device</b>.
4545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
4555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* This function closes a LLCP socket previously created using phFriNfc_LlcpTransport_Socket.
4565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* If the socket was connected, it is first disconnected, and then closed.
4575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
4585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in]  pLlcpSocket                    A pointer to a phFriNfc_LlcpTransport_Socket_t.
4595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
4605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_SUCCESS                  Operation successful.
4615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_INVALID_PARAMETER        One or more of the supplied parameters
4625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                            could not be properly interpreted.
4635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_FAILED                   Operation failed.
4645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/
4655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS phFriNfc_LlcpTransport_Close(phFriNfc_LlcpTransport_Socket_t*   pLlcpSocket)
4665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
4675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   NFCSTATUS status = NFCSTATUS_SUCCESS;
4685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
4695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   /* Check for NULL pointers */
4705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   if( pLlcpSocket == NULL)
4715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
4725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
4735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
4745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else if(pLlcpSocket->eSocket_Type == phFriNfc_LlcpTransport_eConnectionOriented)
4755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
4765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = phFriNfc_LlcpTransport_ConnectionOriented_Close(pLlcpSocket);
4775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
4785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else if(pLlcpSocket->eSocket_Type ==  phFriNfc_LlcpTransport_eConnectionLess)
4795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
4805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = phFriNfc_LlcpTransport_Connectionless_Close(pLlcpSocket);
4815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
4825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else
4835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
4845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
4855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
4865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
4875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   return status;
4885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
4895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
4905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/**
4915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \ingroup grp_fri_nfc
4925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \brief <b>Bind a socket to a local SAP</b>.
4935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
4945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* This function binds the socket to a local Service Access Point.
4955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
4965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[out] pLlcpSocket           A pointer to a phFriNfc_LlcpTransport_Socket_t.
4975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in]  pConfigInfo           A port number for a specific socket
4985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
4995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_SUCCESS                  Operation successful.
5005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_INVALID_PARAMETER        One or more of the supplied parameters
5015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                            could not be properly interpreted.
5025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_INVALID_STATE            The socket is not in a valid state, or not of
5035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                            a valid type to perform the requsted operation.
5045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_ALREADY_REGISTERED       The selected SAP is already bound to another
5055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                             socket.
5065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_FAILED                   Operation failed.
5075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/
5085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
5095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS phFriNfc_LlcpTransport_Bind(phFriNfc_LlcpTransport_Socket_t    *pLlcpSocket,
5105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                      uint8_t                            nSap)
5115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
5125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   NFCSTATUS status = NFCSTATUS_SUCCESS;
5135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   uint8_t i;
5145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
5155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   /* Check for NULL pointers */
5165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   if(pLlcpSocket == NULL)
5175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
5185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
5195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
5205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else if(pLlcpSocket->eSocket_State != phFriNfc_LlcpTransportSocket_eSocketCreated)
5215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
5225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_STATE);
5235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
5245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else if(nSap<2 || nSap>63)
5255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
5265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
5275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
5285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else
5295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
5305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      /* Test if the nSap it is useb by another socket */
5315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      for(i=0;i<PHFRINFC_LLCP_NB_SOCKET_MAX;i++)
5325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      {
5335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         if((pLlcpSocket->psTransport->pSocketTable[i].socket_sSap == nSap)
5345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            && (pLlcpSocket->psTransport->pSocketTable[i].eSocket_Type == pLlcpSocket->eSocket_Type))
5355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         {
5365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            return status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_ALREADY_REGISTERED);
5375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         }
5385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      }
5395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      /* Set the nSap value of the socket */
5405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      pLlcpSocket->socket_sSap = nSap;
5415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      /* Set the socket state */
5425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      pLlcpSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketBound;
5435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
5445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   return status;
5455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
5465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
5475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*********************************************/
5485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*           ConnectionOriented              */
5495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*********************************************/
5505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
5515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/**
5525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \ingroup grp_fri_nfc
5535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \brief <b>Listen for incoming connection requests on a socket</b>.
5545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
5555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* This function switches a socket into a listening state and registers a callback on
5565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* incoming connection requests. In this state, the socket is not able to communicate
5575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* directly. The listening state is only available for connection-oriented sockets
5585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* which are still not connected. The socket keeps listening until it is closed, and
5595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* thus can trigger several times the pListen_Cb callback.
5605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
5615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
5625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in]  pLlcpSocket        A pointer to a phFriNfc_LlcpTransport_Socket_t.
5635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in]  psServiceName      A pointer to Service Name
5645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in]  pListen_Cb         The callback to be called each time the
5655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                socket receive a connection request.
5665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in]  pContext           Upper layer context to be returned in
5675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                the callback.
5685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
5695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_SUCCESS                  Operation successful.
5705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_INVALID_PARAMETER        One or more of the supplied parameters
5715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                            could not be properly interpreted.
5725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_INVALID_STATE            The socket is not in a valid state to switch
5735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                            to listening state.
5745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_FAILED                   Operation failed.
5755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/
5765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS phFriNfc_LlcpTransport_Listen(phFriNfc_LlcpTransport_Socket_t*          pLlcpSocket,
5775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                        phNfc_sData_t                             *psServiceName,
5785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                        pphFriNfc_LlcpTransportSocketListenCb_t   pListen_Cb,
5795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                        void*                                     pContext)
5805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
5815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   NFCSTATUS status = NFCSTATUS_SUCCESS;
5825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
5835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   /* Check for NULL pointers */
5845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   if(pLlcpSocket == NULL || pListen_Cb == NULL|| pContext == NULL || psServiceName == NULL)
5855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
5865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
5875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
5885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   /* Check for socket state */
5895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else if(pLlcpSocket->eSocket_State != phFriNfc_LlcpTransportSocket_eSocketBound)
5905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
5915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_STATE);
5925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
5935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   /* Check for socket type */
5945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else if(pLlcpSocket->eSocket_Type != phFriNfc_LlcpTransport_eConnectionOriented)
5955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
5965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
5975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
5985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   /* Test if a listen is not pending with this socket */
5995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else if(pLlcpSocket->bSocketListenPending)
6005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
6015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
6025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
6035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   /* Test the length of the SN */
6045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else if(psServiceName->length > PHFRINFC_LLCP_SN_MAX_LENGTH)
6055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
6065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         return status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
6075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
6085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else
6095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
6105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = phFriNfc_LlcpTransport_ConnectionOriented_Listen(pLlcpSocket,
6115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                                psServiceName,
6125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                                pListen_Cb,
6135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                                pContext);
6145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
6155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   return status;
6165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
6175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
6185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/**
6195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \ingroup grp_fri_nfc
6205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \brief <b>Accept an incoming connection request for a socket</b>.
6215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
6225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* This functions allows the client to accept an incoming connection request.
6235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* It must be used with the socket provided within the listen callback. The socket
6245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* is implicitly switched to the connected state when the function is called.
6255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
6265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in]  pLlcpSocket           A pointer to a phFriNfc_LlcpTransport_Socket_t.
6275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in]  psOptions             The options to be used with the socket.
6285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in]  psWorkingBuffer       A working buffer to be used by the library.
6295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in]  pErr_Cb               The callback to be called each time the accepted socket
6305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                   is in error.
6315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in]  pContext              Upper layer context to be returned in the callback.
6325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
6335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_SUCCESS                  Operation successful.
6345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_INVALID_PARAMETER        One or more of the supplied parameters
6355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                            could not be properly interpreted.
6365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_BUFFER_TOO_SMALL         The working buffer is too small for the MIU and RW
6375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                            declared in the options.
6385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_FAILED                   Operation failed.
6395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/
6405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS phFriNfc_LlcpTransport_Accept(phFriNfc_LlcpTransport_Socket_t*             pLlcpSocket,
6415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                        phFriNfc_LlcpTransport_sSocketOptions_t*     psOptions,
6425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                        phNfc_sData_t*                               psWorkingBuffer,
6435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                        pphFriNfc_LlcpTransportSocketErrCb_t         pErr_Cb,
6445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                        pphFriNfc_LlcpTransportSocketAcceptCb_t      pAccept_RspCb,
6455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                        void*                                        pContext)
6465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
6475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   NFCSTATUS status = NFCSTATUS_SUCCESS;
6485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
6495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   /* Check for NULL pointers */
6505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   if(pLlcpSocket == NULL || psOptions == NULL || psWorkingBuffer == NULL || pErr_Cb == NULL || pContext == NULL)
6515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
6525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
6535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      /* Call the CB */
6545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      pAccept_RspCb(pContext,status);
6555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
6565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   /* Check for socket state */
6575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else if(pLlcpSocket->eSocket_State != phFriNfc_LlcpTransportSocket_eSocketBound)
6585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
6595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_STATE);
6605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      /* Call the CB */
6615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      pAccept_RspCb(pContext,status);
6625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
6635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   /* Check for socket type */
6645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else if(pLlcpSocket->eSocket_Type != phFriNfc_LlcpTransport_eConnectionOriented)
6655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
6665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
6675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      /* Call the CB */
6685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      pAccept_RspCb(pContext,status);
6695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
6705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   /* Test the socket options */
6715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else if(psOptions->rw > PHFRINFC_LLCP_RW_MAX)
6725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
6735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      /* Call the callback */
6745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      pAccept_RspCb(pContext,status);
6755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
6765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
6775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
6785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   /* Set the Max length for the Send and Receive Window Buffer */
6795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   pLlcpSocket->bufferSendMaxLength   = psOptions->miu;
6805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   pLlcpSocket->bufferRwMaxLength     = psOptions->miu * ((psOptions->rw & PHFRINFC_LLCP_TLV_RW_MASK));
6815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   pLlcpSocket->bufferLinearLength    = psWorkingBuffer->length - pLlcpSocket->bufferSendMaxLength - pLlcpSocket->bufferRwMaxLength;
6825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
6835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   /* Test the buffers length */
6845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   if((pLlcpSocket->bufferSendMaxLength + pLlcpSocket->bufferRwMaxLength) > psWorkingBuffer->length
6855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly       || ((pLlcpSocket->bufferLinearLength < PHFRINFC_LLCP_MIU_DEFAULT)  && (pLlcpSocket->bufferLinearLength != 0)))
6865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
6875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly       /* Call the callback */
6885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      pAccept_RspCb(pContext,status);
6895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_BUFFER_TOO_SMALL);
6905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
6915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else
6925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
6935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      pLlcpSocket->psTransport->socketIndex = pLlcpSocket->index;
6945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
6955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status  = phFriNfc_LlcpTransport_ConnectionOriented_Accept(pLlcpSocket,
6965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                                 psOptions,
6975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                                 psWorkingBuffer,
6985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                                 pErr_Cb,
6995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                                 pAccept_RspCb,
7005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                                 pContext);
7015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
7025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   return status;
7035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
7045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
7055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /**
7065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \ingroup grp_fri_nfc
7075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \brief <b>Reject an incoming connection request for a socket</b>.
7085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
7095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* This functions allows the client to reject an incoming connection request.
7105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* It must be used with the socket provided within the listen callback. The socket
7115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* is implicitly closed when the function is called.
7125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
7135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in]  pLlcpSocket           A pointer to a phFriNfc_LlcpTransport_Socket_t.
7145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in]  pReject_RspCb         The callback to be call when the Reject operation is completed
7155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in]  pContext              Upper layer context to be returned in the callback.
7165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
7175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_SUCCESS                  Operation successful.
7185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_INVALID_PARAMETER        One or more of the supplied parameters
7195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                            could not be properly interpreted.
7205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_FAILED                   Operation failed.
7215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/
7225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS phFriNfc_LlcpTransport_Reject( phFriNfc_LlcpTransport_Socket_t*           pLlcpSocket,
7235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                          pphFriNfc_LlcpTransportSocketRejectCb_t   pReject_RspCb,
7245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                          void                                      *pContext)
7255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
7265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   NFCSTATUS status = NFCSTATUS_SUCCESS;
7275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
7285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   /* Check for NULL pointers */
7295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   if(pLlcpSocket == NULL)
7305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
7315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
7325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      /* Call the CB */
7335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      pReject_RspCb(pContext,status);
7345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
7355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   /* Check for socket state */
7365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else if(pLlcpSocket->eSocket_State != phFriNfc_LlcpTransportSocket_eSocketBound)
7375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
7385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_STATE);
7395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      /* Call the CB */
7405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      pReject_RspCb(pContext,status);
7415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
7425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   /* Check for socket type */
7435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else if(pLlcpSocket->eSocket_Type != phFriNfc_LlcpTransport_eConnectionOriented)
7445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
7455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
7465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      /* Call the CB */
7475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      pReject_RspCb(pContext,status);
7485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
7495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else
7505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
7515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = phLibNfc_LlcpTransport_ConnectionOriented_Reject(pLlcpSocket,
7525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                                pReject_RspCb,
7535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                                pContext);
7545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
7555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
7565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   return status;
7575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
7585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
7595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/**
7605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \ingroup grp_fri_nfc
7615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \brief <b>Try to establish connection with a socket on a remote SAP</b>.
7625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
7635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* This function tries to connect to a given SAP on the remote peer. If the
7645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* socket is not bound to a local SAP, it is implicitly bound to a free SAP.
7655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
7665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in]  pLlcpSocket        A pointer to a phFriNfc_LlcpTransport_Socket_t.
7675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in]  nSap               The destination SAP to connect to.
7685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in]  pConnect_RspCb     The callback to be called when the connection
7695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                operation is completed.
7705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in]  pContext           Upper layer context to be returned in
7715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                the callback.
7725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
7735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_SUCCESS                  Operation successful.
7745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_INVALID_PARAMETER        One or more of the supplied parameters
7755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                            could not be properly interpreted.
7765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_PENDING                  Connection operation is in progress,
7775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                            pConnect_RspCb will be called upon completion.
7785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_INVALID_STATE            The socket is not in a valid state, or not of
7795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                            a valid type to perform the requsted operation.
7805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_FAILED                   Operation failed.
7815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/
7825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS phFriNfc_LlcpTransport_Connect( phFriNfc_LlcpTransport_Socket_t*           pLlcpSocket,
7835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                          uint8_t                                    nSap,
7845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                          pphFriNfc_LlcpTransportSocketConnectCb_t   pConnect_RspCb,
7855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                          void*                                      pContext)
7865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
7875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   NFCSTATUS status = NFCSTATUS_SUCCESS;
7885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   uint8_t i;
7895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
7905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      /* Check for NULL pointers */
7915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   if(pLlcpSocket == NULL || pConnect_RspCb == NULL || pContext == NULL)
7925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
7935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
7945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      /* Call the CB */
7955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      pConnect_RspCb(pContext,FALSE,status);
7965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
7975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   /* Test the port number value */
7985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else if(nSap<02 || nSap>63)
7995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
8005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
8015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      /* Call the CB */
8025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      pConnect_RspCb(pContext,FALSE,status);
8035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
8045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   /* Test if the socket is a connectionOriented socket */
8055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else if(pLlcpSocket->eSocket_Type != phFriNfc_LlcpTransport_eConnectionOriented)
8065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
8075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
8085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      /* Call the CB */
8095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      pConnect_RspCb(pContext,FALSE,status);
8105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
8115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
8125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   /* Test if the socket is not in connecting or connected state*/
8135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else if(pLlcpSocket->eSocket_State != phFriNfc_LlcpTransportSocket_eSocketCreated && pLlcpSocket->eSocket_State != phFriNfc_LlcpTransportSocket_eSocketBound)
8145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
8155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_STATE);
8165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      /* Call the CB */
8175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      pConnect_RspCb(pContext,FALSE,status);
8185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
8195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else
8205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
8215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      if(pLlcpSocket->eSocket_State != phFriNfc_LlcpTransportSocket_eSocketBound)
8225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      {
8235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         /* Bind with a sSap Free */
8245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         pLlcpSocket->socket_sSap = 32;
8255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
8265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         for(i=0;i<PHFRINFC_LLCP_NB_SOCKET_MAX;i++)
8275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         {
8285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if(pLlcpSocket->socket_sSap == pLlcpSocket->psTransport->pSocketTable[i].socket_sSap)
8295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
8305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly               pLlcpSocket->socket_sSap++;
8315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
8325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         }
8335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      }
8345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      pLlcpSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketBound;
8355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
8365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = phFriNfc_LlcpTransport_ConnectionOriented_Connect(pLlcpSocket,
8375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                                 nSap,
8385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                                 NULL,
8395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                                 pConnect_RspCb,
8405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                                 pContext);
8415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
8425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
8435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   return status;
8445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
8455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
8465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/**
8475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \ingroup grp_fri_nfc
8485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \brief <b>Try to establish connection with a socket on a remote service, given its URI</b>.
8495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
8505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* This function tries to connect to a SAP designated by an URI. If the
8515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* socket is not bound to a local SAP, it is implicitly bound to a free SAP.
8525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
8535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in]  pLlcpSocket           A pointer to a phFriNfc_LlcpTransport_Socket_t.
8545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in]  psUri              The URI corresponding to the destination SAP to connect to.
8555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in]  pConnect_RspCb     The callback to be called when the connection
8565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                operation is completed.
8575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in]  pContext           Upper layer context to be returned in
8585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                the callback.
8595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
8605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_SUCCESS                  Operation successful.
8615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_INVALID_PARAMETER        One or more of the supplied parameters
8625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                            could not be properly interpreted.
8635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_PENDING                  Connection operation is in progress,
8645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                            pConnect_RspCb will be called upon completion.
8655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_INVALID_STATE            The socket is not in a valid state, or not of
8665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                            a valid type to perform the requsted operation.
8675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_NOT_INITIALISED          Indicates stack is not yet initialized.
8685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_SHUTDOWN                 Shutdown in progress.
8695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_FAILED                   Operation failed.
8705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/
8715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS phFriNfc_LlcpTransport_ConnectByUri(phFriNfc_LlcpTransport_Socket_t*           pLlcpSocket,
8725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                              phNfc_sData_t*                             psUri,
8735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                              pphFriNfc_LlcpTransportSocketConnectCb_t   pConnect_RspCb,
8745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                              void*                                      pContext)
8755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
8765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   NFCSTATUS status = NFCSTATUS_SUCCESS;
8775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   uint8_t i;
8785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
8795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   /* Check for NULL pointers */
8805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   if(pLlcpSocket == NULL || pConnect_RspCb == NULL || pContext == NULL)
8815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
8825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
8835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      /* Call the CB */
8845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      pConnect_RspCb(pContext,FALSE,status);
8855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
8865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   /* Test if the socket is a connectionOriented socket */
8875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else if(pLlcpSocket->eSocket_Type != phFriNfc_LlcpTransport_eConnectionOriented)
8885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
8895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
8905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      /* Call the CB */
8915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      pConnect_RspCb(pContext,FALSE,status);
8925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
8935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   /* Test if the socket is not in connect pending or connected state*/
8945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else if(pLlcpSocket->eSocket_State == phFriNfc_LlcpTransportSocket_eSocketConnecting || pLlcpSocket->eSocket_State == phFriNfc_LlcpTransportSocket_eSocketConnected)
8955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
8965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
8975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      /* Call the CB */
8985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      pConnect_RspCb(pContext,FALSE,status);
8995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
9005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   /* Test the length of the SN */
9015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else if(psUri->length > PHFRINFC_LLCP_SN_MAX_LENGTH)
9025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
9035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         return status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
9045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
9055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else
9065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
9075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      if(pLlcpSocket->eSocket_State != phFriNfc_LlcpTransportSocket_eSocketBound)
9085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      {
9095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         /* Bind with a sSap Free */
9105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         pLlcpSocket->socket_sSap = 32;
9115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
9125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         for(i=0;i<PHFRINFC_LLCP_NB_SOCKET_MAX;i++)
9135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         {
9145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if(pLlcpSocket->socket_sSap == pLlcpSocket->psTransport->pSocketTable[i].socket_sSap)
9155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
9165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly               pLlcpSocket->socket_sSap++;
9175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
9185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         }
9195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      }
9205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = phFriNfc_LlcpTransport_ConnectionOriented_Connect(pLlcpSocket,
9215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                                 PHFRINFC_LLCP_SAP_DEFAULT,
9225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                                 psUri,
9235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                                 pConnect_RspCb,
9245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                                 pContext);
9255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
9265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
9275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   return status;
9285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
9295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
9305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/**
9315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \ingroup grp_lib_nfc
9325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \brief <b>Disconnect a currently connected socket</b>.
9335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
9345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* This function initiates the disconnection of a previously connected socket.
9355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
9365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in]  pLlcpSocket        A pointer to a phFriNfc_LlcpTransport_Socket_t.
9375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in]  pDisconnect_RspCb  The callback to be called when the
9385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                operation is completed.
9395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in]  pContext           Upper layer context to be returned in
9405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                the callback.
9415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
9425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_SUCCESS                  Operation successful.
9435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_INVALID_PARAMETER        One or more of the supplied parameters
9445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                            could not be properly interpreted.
9455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_PENDING                  Disconnection operation is in progress,
9465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                            pDisconnect_RspCb will be called upon completion.
9475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_INVALID_STATE            The socket is not in a valid state, or not of
9485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                            a valid type to perform the requsted operation.
9495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_NOT_INITIALISED          Indicates stack is not yet initialized.
9505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_SHUTDOWN                 Shutdown in progress.
9515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_FAILED                   Operation failed.
9525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/
9535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS phFriNfc_LlcpTransport_Disconnect(phFriNfc_LlcpTransport_Socket_t*           pLlcpSocket,
9545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                            pphLibNfc_LlcpSocketDisconnectCb_t         pDisconnect_RspCb,
9555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                            void*                                      pContext)
9565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
9575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   NFCSTATUS status = NFCSTATUS_SUCCESS;
9585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
9595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   /* Check for NULL pointers */
9605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   if(pLlcpSocket == NULL || pDisconnect_RspCb == NULL || pContext == NULL)
9615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
9625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
9635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      /* Call the CB */
9645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      pDisconnect_RspCb(pContext,status);
9655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
9665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   /* Test if the socket is a connectionOriented socket */
9675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else if(pLlcpSocket->eSocket_Type != phFriNfc_LlcpTransport_eConnectionOriented)
9685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
9695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly       status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
9705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      /* Call the CB */
9715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      pDisconnect_RspCb(pContext,status);
9725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
9735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   /* Test if the socket is connected  state*/
9745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else if(pLlcpSocket->eSocket_State != phFriNfc_LlcpTransportSocket_eSocketConnected)
9755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
9765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly       status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
9775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      /* Call the CB */
9785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      pDisconnect_RspCb(pContext,status);
9795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
9805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else
9815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
9825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = phLibNfc_LlcpTransport_ConnectionOriented_Disconnect(pLlcpSocket,
9835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                                    pDisconnect_RspCb,
9845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                                    pContext);
9855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
9865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
9875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   return status;
9885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
9895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
9905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/**
9915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \ingroup grp_fri_nfc
9925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \brief <b>Send data on a socket</b>.
9935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
9945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* This function is used to write data on a socket. This function
9955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* can only be called on a connection-oriented socket which is already
9965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* in a connected state.
9975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
9985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
9995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in]  pLlcpSocket        A pointer to a phFriNfc_LlcpTransport_Socket_t.
10005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in]  psBuffer           The buffer containing the data to send.
10015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in]  pSend_RspCb        The callback to be called when the
10025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                operation is completed.
10035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in]  pContext           Upper layer context to be returned in
10045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                the callback.
10055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
10065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_SUCCESS                  Operation successful.
10075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_INVALID_PARAMETER        One or more of the supplied parameters
10085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                            could not be properly interpreted.
10095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_PENDING                  Reception operation is in progress,
10105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                            pSend_RspCb will be called upon completion.
10115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_INVALID_STATE            The socket is not in a valid state, or not of
10125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                            a valid type to perform the requsted operation.
10135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_FAILED                   Operation failed.
10145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/
10155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS phFriNfc_LlcpTransport_Send(phFriNfc_LlcpTransport_Socket_t*             pLlcpSocket,
10165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                      phNfc_sData_t*                               psBuffer,
10175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                      pphFriNfc_LlcpTransportSocketSendCb_t        pSend_RspCb,
10185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                      void*                                        pContext)
10195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
10205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   NFCSTATUS status = NFCSTATUS_SUCCESS;
10215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
10225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   /* Check for NULL pointers */
10235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   if(pLlcpSocket == NULL || psBuffer == NULL || pSend_RspCb == NULL || pContext == NULL)
10245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
10255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
10265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      /* Call the CB */
10275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      pSend_RspCb(pContext,status);
10285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
10295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   /* Test if the socket is a connectionOriented socket */
10305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else if(pLlcpSocket->eSocket_Type != phFriNfc_LlcpTransport_eConnectionOriented)
10315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
10325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
10335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      /* Call the CB */
10345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      pSend_RspCb(pContext,status);
10355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
10365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   /* Test if the socket is in connected state */
10375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else if(pLlcpSocket->eSocket_State != phFriNfc_LlcpTransportSocket_eSocketConnected)
10385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
10395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_STATE);
10405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      /* Call the CB */
10415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      pSend_RspCb(pContext,status);
10425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
10435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   /* Test the length of the buffer */
10445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else if(psBuffer->length > pLlcpSocket->remoteMIU )
10455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
10465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
10475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      /* Call the CB */
10485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      pSend_RspCb(pContext,status);
10495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
10505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   /* Test if a send is pending */
10515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else if(pLlcpSocket->bSocketSendPending == TRUE)
10525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
10535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_REJECTED);
10545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      /* Call the CB */
10555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      pSend_RspCb(pContext,status);
10565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
10575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else
10585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
10595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = phFriNfc_LlcpTransport_ConnectionOriented_Send(pLlcpSocket,
10605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                              psBuffer,
10615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                              pSend_RspCb,
10625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                              pContext);
10635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
10645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
10655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   return status;
10665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
10675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
10685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /**
10695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \ingroup grp_fri_nfc
10705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \brief <b>Read data on a socket</b>.
10715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
10725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* This function is used to read data from a socket. It reads at most the
10735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* size of the reception buffer, but can also return less bytes if less bytes
10745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* are available. If no data is available, the function will be pending until
10755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* more data comes, and the response will be sent by the callback. This function
10765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* can only be called on a connection-oriented socket.
10775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
10785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
10795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in]  pLlcpSocket        A pointer to a phFriNfc_LlcpTransport_Socket_t.
10805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in]  psBuffer           The buffer receiving the data.
10815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in]  pRecv_RspCb        The callback to be called when the
10825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                operation is completed.
10835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in]  pContext           Upper layer context to be returned in
10845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                the callback.
10855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
10865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_SUCCESS                  Operation successful.
10875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_INVALID_PARAMETER        One or more of the supplied parameters
10885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                            could not be properly interpreted.
10895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_PENDING                  Reception operation is in progress,
10905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                            pRecv_RspCb will be called upon completion.
10915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_INVALID_STATE            The socket is not in a valid state, or not of
10925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                            a valid type to perform the requsted operation.
10935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_FAILED                   Operation failed.
10945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/
10955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS phFriNfc_LlcpTransport_Recv( phFriNfc_LlcpTransport_Socket_t*             pLlcpSocket,
10965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                       phNfc_sData_t*                               psBuffer,
10975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                       pphFriNfc_LlcpTransportSocketRecvCb_t        pRecv_RspCb,
10985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                       void*                                        pContext)
10995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
11005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   NFCSTATUS status = NFCSTATUS_SUCCESS;
11015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
11025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
11035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   /* Check for NULL pointers */
11045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   if(pLlcpSocket == NULL || psBuffer == NULL || pRecv_RspCb == NULL || pContext == NULL)
11055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
11065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
11075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      /* Call the CB */
11085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      pRecv_RspCb(pContext,status);
11095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
11105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   /* Test if the socket is a connectionOriented socket */
11115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else if(pLlcpSocket->eSocket_Type != phFriNfc_LlcpTransport_eConnectionOriented)
11125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
11135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
11145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      /* Call the CB */
11155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      pRecv_RspCb(pContext,status);
11165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
11175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   /* Test if the socket is in connected state */
11185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else if(pLlcpSocket->eSocket_State != phFriNfc_LlcpTransportSocket_eSocketConnected)
11195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
11205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
11215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      /* Call the CB */
11225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      pRecv_RspCb(pContext,status);
11235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
11245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   /* Test if a receive is pending */
11255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else if(pLlcpSocket->bSocketRecvPending == TRUE)
11265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
11275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_REJECTED);
11285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      /* Call the CB */
11295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      pRecv_RspCb(pContext,status);
11305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
11315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else
11325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
11335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = phFriNfc_LlcpTransport_ConnectionOriented_Recv(pLlcpSocket,
11345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                              psBuffer,
11355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                              pRecv_RspCb,
11365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                              pContext);
11375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
11385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
11395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
11405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   return status;
11415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
11425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
11435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*****************************************/
11445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*           ConnectionLess              */
11455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*****************************************/
11465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
11475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/**
11485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \ingroup grp_fri_nfc
11495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \brief <b>Send data on a socket to a given destination SAP</b>.
11505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
11515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* This function is used to write data on a socket to a given destination SAP.
11525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* This function can only be called on a connectionless socket.
11535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
11545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
11555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in]  pLlcpSocket        A pointer to a LlcpSocket created.
11565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in]  nSap               The destination SAP.
11575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in]  psBuffer           The buffer containing the data to send.
11585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in]  pSend_RspCb        The callback to be called when the
11595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                operation is completed.
11605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in]  pContext           Upper layer context to be returned in
11615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                the callback.
11625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
11635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_SUCCESS                  Operation successful.
11645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_INVALID_PARAMETER        One or more of the supplied parameters
11655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                            could not be properly interpreted.
11665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_PENDING                  Reception operation is in progress,
11675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                            pSend_RspCb will be called upon completion.
11685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_INVALID_STATE            The socket is not in a valid state, or not of
11695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                            a valid type to perform the requsted operation.
11705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_FAILED                   Operation failed.
11715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/
11725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS phFriNfc_LlcpTransport_SendTo( phFriNfc_LlcpTransport_Socket_t             *pLlcpSocket,
11735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                         uint8_t                                     nSap,
11745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                         phNfc_sData_t                               *psBuffer,
11755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                         pphFriNfc_LlcpTransportSocketSendCb_t       pSend_RspCb,
11765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                         void*                                       pContext)
11775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
11785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   NFCSTATUS status = NFCSTATUS_SUCCESS;
11795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   phFriNfc_Llcp_sLinkParameters_t  LlcpRemoteLinkParamInfo;
11805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
11815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
11825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   if(pLlcpSocket == NULL || psBuffer == NULL || pSend_RspCb == NULL || pContext == NULL)
11835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
11845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
11855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      pSend_RspCb(pContext,status);
11865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
11875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   /* Test the port number value */
11885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else if(nSap<2 || nSap>63)
11895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
11905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
11915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      pSend_RspCb(pContext,status);
11925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      return status;
11935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
11945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   /* Test if the socket is a connectionless socket */
11955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else if(pLlcpSocket->eSocket_Type != phFriNfc_LlcpTransport_eConnectionLess)
11965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
11975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly       status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
11985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly       pSend_RspCb(pContext,status);
11995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly       return status;
12005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
12015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   /* Test if the socket is in an updated state */
12025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else if(pLlcpSocket->eSocket_State != phFriNfc_LlcpTransportSocket_eSocketBound)
12035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
12045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_STATE);
12055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      pSend_RspCb(pContext,status);
12065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      return status;
12075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
12085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   /* Get the local parameters of the LLCP Link */
12095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   status = phFriNfc_Llcp_GetRemoteInfo(pLlcpSocket->psTransport->pLlcp,&LlcpRemoteLinkParamInfo);
12105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   if(status != NFCSTATUS_SUCCESS)
12115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
12125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_FAILED);
12135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
12145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   /* Test the length of the socket buffer for ConnectionLess mode*/
12155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else if(psBuffer->length > LlcpRemoteLinkParamInfo.miu)
12165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
12175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
12185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      pSend_RspCb(pContext,status);
12195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
12205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   /* Test if the link is in error state */
12215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else if(pLlcpSocket->psTransport->LinkStatusError)
12225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
12235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_REJECTED);
12245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      pSend_RspCb(pContext,status);
12255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
12265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else
12275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
12285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = phFriNfc_LlcpTransport_Connectionless_SendTo(pLlcpSocket,
12295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                            nSap,
12305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                            psBuffer,
12315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                            pSend_RspCb,
12325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                            pContext);
12335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
12345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   return status;
12355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
12365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
12375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
12385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /**
12395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \ingroup grp_lib_nfc
12405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \brief <b>Read data on a socket and get the source SAP</b>.
12415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
12425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* This function is the same as phLibNfc_Llcp_Recv, except that the callback includes
12435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* the source SAP. This functions can only be called on a connectionless socket.
12445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
12455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
12465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in]  pLlcpSocket        A pointer to a LlcpSocket created.
12475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in]  psBuffer           The buffer receiving the data.
12485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in]  pRecv_RspCb        The callback to be called when the
12495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                operation is completed.
12505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \param[in]  pContext           Upper layer context to be returned in
12515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                the callback.
12525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*
12535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_SUCCESS                  Operation successful.
12545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_INVALID_PARAMETER        One or more of the supplied parameters
12555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                            could not be properly interpreted.
12565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_PENDING                  Reception operation is in progress,
12575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                            pRecv_RspCb will be called upon completion.
12585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_INVALID_STATE            The socket is not in a valid state, or not of
12595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                            a valid type to perform the requsted operation.
12605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_NOT_INITIALISED          Indicates stack is not yet initialized.
12615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_SHUTDOWN                 Shutdown in progress.
12625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval NFCSTATUS_FAILED                   Operation failed.
12635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/
12645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS phFriNfc_LlcpTransport_RecvFrom( phFriNfc_LlcpTransport_Socket_t                   *pLlcpSocket,
12655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                           phNfc_sData_t*                                    psBuffer,
12665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                           pphFriNfc_LlcpTransportSocketRecvFromCb_t         pRecv_Cb,
12675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                           void*                                             pContext)
12685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
12695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   NFCSTATUS status = NFCSTATUS_SUCCESS;
12705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   if(pLlcpSocket == NULL || psBuffer == NULL || pRecv_Cb == NULL || pContext == NULL)
12715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
12725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
12735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      pRecv_Cb(pContext,0x00,status);
12745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
12755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   /* Test if the socket is a connectionless socket */
12765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else if(pLlcpSocket->eSocket_Type != phFriNfc_LlcpTransport_eConnectionLess)
12775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
12785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly       status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
12795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly       pRecv_Cb(pContext,0x00,status);
12805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
12815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   /* Test if the socket is in an updated state */
12825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else if(pLlcpSocket->eSocket_State != phFriNfc_LlcpTransportSocket_eSocketBound)
12835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
12845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_STATE);
12855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      pRecv_Cb(pContext,0x00,status);
12865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
12875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   else
12885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   {
12895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      if(pLlcpSocket->bSocketRecvPending)
12905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      {
12915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_REJECTED);
12925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         pRecv_Cb(pContext,0x00,status);
12935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      }
12945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      else
12955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      {
12965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly         status = phLibNfc_LlcpTransport_Connectionless_RecvFrom(pLlcpSocket,
12975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                                 psBuffer,
12985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                                 pRecv_Cb,
12995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                                 pContext);
13005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      }
13015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   }
13025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly   return status;
13035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
1304