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