Home | History | Annotate | Download | only in src
      1 /*
      2  * Copyright (C) 2010 NXP Semiconductors
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 /**
     18  * \file  phFriNfc_LlcpTransport.h
     19  * \brief
     20  *
     21  * Project: NFC-FRI
     22  *
     23  */
     24 
     25 #ifndef PHFRINFC_LLCP_TRANSPORT_H
     26 #define PHFRINFC_LLCP_TRANSPORT_H
     27 #include <phNfcHalTypes.h>
     28 #include <phNfcLlcpTypes.h>
     29 #include <phNfcTypes.h>
     30 #include <phLibNfcStatus.h>
     31 #include <phFriNfc_Llcp.h>
     32 #include <phFriNfc_LlcpUtils.h>
     33 #ifdef ANDROID
     34 #include <string.h>
     35 #endif
     36 
     37 
     38 typedef uint32_t    phFriNfc_Socket_Handle;
     39 
     40 /**
     41  * \ingroup grp_fri_nfc_llcp_mac
     42  * \brief Declaration of a TRANSPORT type
     43  */
     44 struct phFriNfc_LlcpTransport;
     45 typedef struct phFriNfc_LlcpTransport phFriNfc_LlcpTransport_t;
     46 
     47 struct phFriNfc_LlcpTransport_Socket;
     48 typedef struct phFriNfc_LlcpTransport_Socket phFriNfc_LlcpTransport_Socket_t;
     49 
     50 struct phFriNfc_Llcp_CachedServiceName;
     51 typedef struct phFriNfc_Llcp_CachedServiceName phFriNfc_Llcp_CachedServiceName_t;
     52 
     53 /*========== ENUMERATES ===========*/
     54 
     55 /* Enum reperesents the different LLCP Link status*/
     56 typedef enum phFriNfc_LlcpTransportSocket_eSocketState
     57 {
     58    phFriNfc_LlcpTransportSocket_eSocketDefault,
     59    phFriNfc_LlcpTransportSocket_eSocketCreated,
     60    phFriNfc_LlcpTransportSocket_eSocketBound,
     61    phFriNfc_LlcpTransportSocket_eSocketRegistered,
     62    phFriNfc_LlcpTransportSocket_eSocketConnected,
     63    phFriNfc_LlcpTransportSocket_eSocketConnecting,
     64    phFriNfc_LlcpTransportSocket_eSocketAccepted,
     65    phFriNfc_LlcpTransportSocket_eSocketDisconnected,
     66    phFriNfc_LlcpTransportSocket_eSocketDisconnecting,
     67    phFriNfc_LlcpTransportSocket_eSocketRejected,
     68 }phFriNfc_LlcpTransportSocket_eSocketState_t;
     69 
     70 
     71 
     72 /*========== CALLBACKS ===========*/
     73 
     74 /**
     75 *\ingroup grp_fri_nfc
     76 *
     77 * \brief LLCP socket error notification callback definition
     78 */
     79 typedef void (*pphFriNfc_LlcpTransportSocketErrCb_t) ( void*      pContext,
     80                                                        uint8_t    nErrCode);
     81 
     82 
     83 /**
     84 *\ingroup grp_fri_nfc
     85 *
     86 * \brief LLCP socket listen callback definition
     87 */
     88 typedef void (*pphFriNfc_LlcpTransportSocketListenCb_t) (void*                            pContext,
     89                                                          phFriNfc_LlcpTransport_Socket_t  *IncomingSocket);
     90 
     91 /**
     92 *\ingroup grp_fri_nfc
     93 *
     94 * \brief LLCP socket connect callback definition
     95 */
     96 typedef void (*pphFriNfc_LlcpTransportSocketConnectCb_t)  ( void*        pContext,
     97                                                             uint8_t      nErrCode,
     98                                                             NFCSTATUS    status);
     99 
    100 /**
    101 *\ingroup grp_fri_nfc
    102 *
    103 * \brief LLCP socket disconnect callback definition
    104 */
    105 typedef void (*pphFriNfc_LlcpTransportSocketDisconnectCb_t) (void*        pContext,
    106                                                              NFCSTATUS    status);
    107 
    108 /**
    109 *\ingroup grp_fri_nfc
    110 *
    111 * \brief LLCP socket accept callback definition
    112 */
    113 typedef void (*pphFriNfc_LlcpTransportSocketAcceptCb_t) (void*        pContext,
    114                                                          NFCSTATUS    status);
    115 
    116 /**
    117 *\ingroup grp_fri_nfc
    118 *
    119 * \brief LLCP socket reject callback definition
    120 */
    121 typedef void (*pphFriNfc_LlcpTransportSocketRejectCb_t) (void*        pContext,
    122                                                          NFCSTATUS    status);
    123 
    124 /**
    125 *\ingroup grp_fri_nfc
    126 *
    127 * \brief LLCP socket reception callback definition
    128 */
    129 typedef void (*pphFriNfc_LlcpTransportSocketRecvCb_t) (void*     pContext,
    130                                                        NFCSTATUS status);
    131 
    132 /**
    133 *\ingroup grp_fri_nfc
    134 *
    135 * \brief LLCP socket reception with SSAP callback definition
    136 */
    137 typedef void (*pphFriNfc_LlcpTransportSocketRecvFromCb_t) (void*       pContext,
    138                                                            uint8_t     ssap,
    139                                                            NFCSTATUS   status);
    140 
    141 /**
    142 *\ingroup grp_fri_nfc
    143 *
    144 * \brief LLCP socket emission callback definition
    145 */
    146 typedef void (*pphFriNfc_LlcpTransportSocketSendCb_t) (void*        pContext,
    147                                                        NFCSTATUS    status);
    148 
    149 
    150 /*========== STRUCTURES ===========*/
    151 /**
    152  * \ingroup grp_fri_nfc_llcp_mac
    153  * \brief Declaration of a SOCKET type
    154  */
    155 struct phFriNfc_LlcpTransport_Socket
    156 {
    157    phFriNfc_LlcpTransportSocket_eSocketState_t    eSocket_State;
    158    phFriNfc_LlcpTransport_eSocketType_t           eSocket_Type;
    159    phFriNfc_LlcpTransport_sSocketOptions_t        sSocketOption;
    160    pphFriNfc_LlcpTransportSocketErrCb_t           pSocketErrCb;
    161 
    162    /* Remote and local socket info */
    163    uint8_t                                        socket_sSap;
    164    uint8_t                                        socket_dSap;
    165    // TODO: copy service name (could be deallocated by upper layer)
    166    phNfc_sData_t                                  sServiceName;
    167    uint8_t                                        remoteRW;
    168    uint8_t                                        localRW;
    169    uint16_t                                       remoteMIU;
    170    uint16_t                                       localMIUX;
    171    uint8_t                                        index;
    172 
    173    /* SDP related fields */
    174    uint8_t                                       nTid;
    175 
    176    /* Information Flags */
    177    bool_t                                        bSocketRecvPending;
    178    bool_t                                        bSocketSendPending;
    179    bool_t                                        bSocketListenPending;
    180    bool_t                                        bSocketDiscPending;
    181    bool_t                                        bSocketConnectPending;
    182    bool_t                                        bSocketAcceptPending;
    183    bool_t                                        bSocketRRPending;
    184    bool_t                                        bSocketRNRPending;
    185 
    186    /* Buffers */
    187    phNfc_sData_t                                  sSocketSendBuffer;
    188    phNfc_sData_t                                  sSocketLinearBuffer;
    189    phNfc_sData_t*                                 sSocketRecvBuffer;
    190    uint32_t                                       *receivedLength;
    191    uint32_t                                       bufferLinearLength;
    192    uint32_t                                       bufferSendMaxLength;
    193    uint32_t                                       bufferRwMaxLength;
    194    bool_t                                         ReceiverBusyCondition;
    195    bool_t                                         RemoteBusyConditionInfo;
    196    UTIL_FIFO_BUFFER                               sCyclicFifoBuffer;
    197    uint32_t                                       indexRwRead;
    198    uint32_t                                       indexRwWrite;
    199 
    200    /* Construction Frame */
    201    phFriNfc_Llcp_sPacketHeader_t                  sLlcpHeader;
    202    phFriNfc_Llcp_sPacketSequence_t                sSequence;
    203    uint8_t                                        socket_VS;
    204    uint8_t                                        socket_VSA;
    205    uint8_t                                        socket_VR;
    206    uint8_t                                        socket_VRA;
    207 
    208    /* Callbacks */
    209    pphFriNfc_LlcpTransportSocketAcceptCb_t        pfSocketAccept_Cb;
    210    pphFriNfc_LlcpTransportSocketSendCb_t          pfSocketSend_Cb;
    211    pphFriNfc_LlcpTransportSocketRecvFromCb_t      pfSocketRecvFrom_Cb;
    212    pphFriNfc_LlcpTransportSocketRecvCb_t          pfSocketRecv_Cb;
    213    pphFriNfc_LlcpTransportSocketListenCb_t        pfSocketListen_Cb;
    214    pphFriNfc_LlcpTransportSocketConnectCb_t       pfSocketConnect_Cb;
    215    pphFriNfc_LlcpTransportSocketDisconnectCb_t    pfSocketDisconnect_Cb;
    216 
    217    /* Table of PHFRINFC_LLCP_RW_MAX Receive Windows Buffers */
    218    phNfc_sData_t                                  sSocketRwBufferTable[PHFRINFC_LLCP_RW_MAX];
    219 
    220    /* Pointer a the socket table */
    221    phFriNfc_LlcpTransport_t                       *psTransport;
    222    /* Context */
    223    void                                          *pListenContext;
    224    void                                          *pAcceptContext;
    225    void                                          *pRejectContext;
    226    void                                          *pConnectContext;
    227    void                                          *pDisonnectContext;
    228    void                                          *pSendContext;
    229    void                                          *pRecvContext;
    230    void                                          *pContext;
    231 };
    232 
    233 /**
    234  * \ingroup grp_fri_nfc_llcp_mac
    235  * \brief TODO
    236  */
    237 struct phFriNfc_Llcp_CachedServiceName
    238 {
    239    phNfc_sData_t                         sServiceName;
    240    uint8_t                               nSap;
    241 };
    242 
    243 
    244 /**
    245  * \ingroup grp_fri_nfc_llcp_mac
    246  * \brief Declaration of a TRANSPORT Type with a table of PHFRINFC_LLCP_NB_SOCKET_DEFAULT sockets
    247  *        and a pointer a Llcp layer
    248  */
    249 struct phFriNfc_LlcpTransport
    250 {
    251    phFriNfc_LlcpTransport_Socket_t       pSocketTable[PHFRINFC_LLCP_NB_SOCKET_MAX];
    252    phFriNfc_Llcp_CachedServiceName_t     pCachedServiceNames[PHFRINFC_LLCP_SDP_ADVERTISED_NB];
    253    phFriNfc_Llcp_t                       *pLlcp;
    254    bool_t                                bSendPending;
    255    bool_t                                bRecvPending;
    256    bool_t                                bDmPending;
    257    bool_t                                bFrmrPending;
    258 
    259    phFriNfc_Llcp_Send_CB_t               pfLinkSendCb;
    260    void                                  *pLinkSendContext;
    261 
    262    uint8_t                               socketIndex;
    263 
    264    /**< Info field of pending FRMR packet*/
    265    uint8_t                               FrmrInfoBuffer[4];
    266    phFriNfc_Llcp_sPacketHeader_t         sLlcpHeader;
    267    phFriNfc_Llcp_sPacketSequence_t       sSequence;
    268 
    269   /**< Info field of pending DM packet*/
    270    phFriNfc_Llcp_sPacketHeader_t         sDmHeader;
    271    phNfc_sData_t                         sDmPayload;
    272    uint8_t                               DmInfoBuffer[3];
    273 
    274    uint8_t                               LinkStatusError;
    275 
    276    /**< Service discovery related infos */
    277    phNfc_sData_t                         *psDiscoveryServiceNameList;
    278    uint8_t                               *pnDiscoverySapList;
    279    uint8_t                               nDiscoveryListSize;
    280    uint8_t                               nDiscoveryReqOffset;
    281    uint8_t                               nDiscoveryResOffset;
    282 
    283    uint8_t                               nDiscoveryResTidList[PHFRINFC_LLCP_SNL_RESPONSE_MAX];
    284    uint8_t                               nDiscoveryResSapList[PHFRINFC_LLCP_SNL_RESPONSE_MAX];
    285    uint8_t                               nDiscoveryResListSize;
    286 
    287    uint8_t                               pDiscoveryBuffer[PHFRINFC_LLCP_MIU_DEFAULT];
    288    pphFriNfc_Cr_t                        pfDiscover_Cb;
    289    void                                  *pDiscoverContext;
    290 
    291 };
    292 
    293 /*
    294 ################################################################################
    295 ********************** TRANSPORT Interface Function Prototype  *****************
    296 ################################################################################
    297 */
    298 
    299  /**
    300 * \ingroup grp_fri_nfc
    301 * \brief <b>Create a socket on a LLCP-connected device</b>.
    302 *
    303 */
    304 NFCSTATUS phFriNfc_LlcpTransport_Reset (phFriNfc_LlcpTransport_t      *pLlcpSocketTable,
    305                                         phFriNfc_Llcp_t               *pLlcp);
    306 
    307 
    308 /**
    309 * \ingroup grp_fri_nfc
    310 * \brief <b>Close all existing sockets</b>.
    311 *
    312 */
    313 NFCSTATUS phFriNfc_LlcpTransport_CloseAll (phFriNfc_LlcpTransport_t  *pLlcpSocketTable);
    314 
    315 
    316 /**
    317 * \ingroup grp_fri_nfc
    318 * \brief <b>Used by transport layers to request a send on link layer</b>.
    319 *
    320 */
    321 NFCSTATUS phFriNfc_LlcpTransport_LinkSend( phFriNfc_LlcpTransport_t         *LlcpTransport,
    322                                            phFriNfc_Llcp_sPacketHeader_t    *psHeader,
    323                                            phFriNfc_Llcp_sPacketSequence_t  *psSequence,
    324                                            phNfc_sData_t                    *psInfo,
    325                                            phFriNfc_Llcp_Send_CB_t          pfSend_CB,
    326                                            void                             *pContext );
    327 
    328 
    329 /**
    330 * \ingroup grp_fri_nfc
    331 * \brief <b>Used by transport layers to send a DM frame</b>.
    332 *
    333 *  This function is only used when the DM is not related to a DISC on a socket.
    334 */
    335 NFCSTATUS phFriNfc_LlcpTransport_SendDisconnectMode(phFriNfc_LlcpTransport_t* psTransport,
    336                                                     uint8_t                   dsap,
    337                                                     uint8_t                   ssap,
    338                                                     uint8_t                   dmOpCode);
    339 
    340 /**
    341 * \ingroup grp_fri_nfc
    342 * \brief <b>Used by transport layers to send a FRMR frame</b>.
    343 *
    344 */
    345 NFCSTATUS phFriNfc_LlcpTransport_SendFrameReject(phFriNfc_LlcpTransport_t           *psTransport,
    346                                                  uint8_t                            dsap,
    347                                                  uint8_t                            rejectedPTYPE,
    348                                                  uint8_t                            ssap,
    349                                                  phFriNfc_Llcp_sPacketSequence_t*   sLlcpSequence,
    350                                                  uint8_t                            WFlag,
    351                                                  uint8_t                            IFlag,
    352                                                  uint8_t                            RFlag,
    353                                                  uint8_t                            SFlag,
    354                                                  uint8_t                            vs,
    355                                                  uint8_t                            vsa,
    356                                                  uint8_t                            vr,
    357                                                  uint8_t                            vra);
    358 
    359 /*!
    360 * \ingroup grp_fri_nfc
    361 * \brief <b>Discover remote services SAP using SDP protocol</b>.
    362  */
    363 NFCSTATUS phFriNfc_LlcpTransport_DiscoverServices( phFriNfc_LlcpTransport_t  *pLlcpTransport,
    364                                                    phNfc_sData_t             *psServiceNameList,
    365                                                    uint8_t                   *pnSapList,
    366                                                    uint8_t                   nListSize,
    367                                                    pphFriNfc_Cr_t            pDiscover_Cb,
    368                                                    void                      *pContext );
    369 
    370 /**
    371 * \ingroup grp_lib_nfc
    372 * \brief <b>Get the local options of a socket</b>.
    373 *
    374 * This function returns the local options (maximum packet size and receive window size) used
    375 * for a given connection-oriented socket. This function shall not be used with connectionless
    376 * sockets.
    377 *
    378 * \param[out] pLlcpSocket           A pointer to a phFriNfc_LlcpTransport_Socket_t.
    379 * \param[in]  psLocalOptions        A pointer to be filled with the local options of the socket.
    380 *
    381 * \retval NFCSTATUS_SUCCESS                  Operation successful.
    382 * \retval NFCSTATUS_INVALID_PARAMETER        One or more of the supplied parameters
    383 *                                            could not be properly interpreted.
    384 * \retval NFCSTATUS_INVALID_STATE            The socket is not in a valid state, or not of
    385 *                                            a valid type to perform the requsted operation.
    386 * \retval NFCSTATUS_NOT_INITIALISED          Indicates stack is not yet initialized.
    387 * \retval NFCSTATUS_SHUTDOWN                 Shutdown in progress.
    388 * \retval NFCSTATUS_FAILED                   Operation failed.
    389 */
    390 NFCSTATUS phFriNfc_LlcpTransport_SocketGetLocalOptions(phFriNfc_LlcpTransport_Socket_t  *pLlcpSocket,
    391                                                        phLibNfc_Llcp_sSocketOptions_t   *psLocalOptions);
    392 
    393 
    394 /**
    395 * \ingroup grp_lib_nfc
    396 * \brief <b>Get the local options of a socket</b>.
    397 *
    398 * This function returns the remote options (maximum packet size and receive window size) used
    399 * for a given connection-oriented socket. This function shall not be used with connectionless
    400 * sockets.
    401 *
    402 * \param[out] pLlcpSocket           A pointer to a phFriNfc_LlcpTransport_Socket_t.
    403 * \param[in]  psRemoteOptions       A pointer to be filled with the remote options of the socket.
    404 *
    405 * \retval NFCSTATUS_SUCCESS                  Operation successful.
    406 * \retval NFCSTATUS_INVALID_PARAMETER        One or more of the supplied parameters
    407 *                                            could not be properly interpreted.
    408 * \retval NFCSTATUS_INVALID_STATE            The socket is not in a valid state, or not of
    409 *                                            a valid type to perform the requsted operation.
    410 * \retval NFCSTATUS_NOT_INITIALISED          Indicates stack is not yet initialized.
    411 * \retval NFCSTATUS_SHUTDOWN                 Shutdown in progress.
    412 * \retval NFCSTATUS_FAILED                   Operation failed.
    413 */
    414 NFCSTATUS phFriNfc_LlcpTransport_SocketGetRemoteOptions(phFriNfc_LlcpTransport_Socket_t*   pLlcpSocket,
    415                                                         phLibNfc_Llcp_sSocketOptions_t*    psRemoteOptions);
    416 
    417 
    418  /**
    419 * \ingroup grp_fri_nfc
    420 * \brief <b>Create a socket on a LLCP-connected device</b>.
    421 *
    422 * This function creates a socket for a given LLCP link. Sockets can be of two types :
    423 * connection-oriented and connectionless. If the socket is connection-oriented, the caller
    424 * must provide a working buffer to the socket in order to handle incoming data. This buffer
    425 * must be large enough to fit the receive window (RW * MIU), the remaining space being
    426 * used as a linear buffer to store incoming data as a stream. Data will be readable later
    427 * using the phLibNfc_LlcpTransport_Recv function.
    428 * The options and working buffer are not required if the socket is used as a listening socket,
    429 * since it cannot be directly used for communication.
    430 *
    431 * \param[in]  pLlcpSocketTable      A pointer to a table of PHFRINFC_LLCP_NB_SOCKET_DEFAULT sockets.
    432 * \param[in]  eType                 The socket type.
    433 * \param[in]  psOptions             The options to be used with the socket.
    434 * \param[in]  psWorkingBuffer       A working buffer to be used by the library.
    435 * \param[out] pLlcpSocket           A pointer to a socket pointer to be filled with a
    436                                     socket found on the socket table.
    437 * \param[in]  pErr_Cb               The callback to be called each time the socket
    438 *                                   is in error.
    439 * \param[in]  pContext              Upper layer context to be returned in the callback.
    440 *
    441 * \retval NFCSTATUS_SUCCESS                  Operation successful.
    442 * \retval NFCSTATUS_INVALID_PARAMETER        One or more of the supplied parameters
    443 *                                            could not be properly interpreted.
    444 * \retval NFCSTATUS_BUFFER_TOO_SMALL         The working buffer is too small for the MIU and RW
    445 *                                            declared in the options.
    446 * \retval NFCSTATUS_INSUFFICIENT_RESOURCES   No more socket handle available.
    447 * \retval NFCSTATUS_FAILED                   Operation failed.
    448 * */
    449 NFCSTATUS phFriNfc_LlcpTransport_Socket(phFriNfc_LlcpTransport_t                           *pLlcpSocketTable,
    450                                         phFriNfc_LlcpTransport_eSocketType_t               eType,
    451                                         phFriNfc_LlcpTransport_sSocketOptions_t*           psOptions,
    452                                         phNfc_sData_t*                                     psWorkingBuffer,
    453                                         phFriNfc_LlcpTransport_Socket_t                    **pLlcpSocket,
    454                                         pphFriNfc_LlcpTransportSocketErrCb_t               pErr_Cb,
    455                                         void*                                              pContext);
    456 
    457 /**
    458 * \ingroup grp_fri_nfc
    459 * \brief <b>Close a socket on a LLCP-connected device</b>.
    460 *
    461 * This function closes a LLCP socket previously created using phFriNfc_LlcpTransport_Socket.
    462 * If the socket was connected, it is first disconnected, and then closed.
    463 *
    464 * \param[in]  pLlcpSocket                    A pointer to a phFriNfc_LlcpTransport_Socket_t.
    465 
    466 * \retval NFCSTATUS_SUCCESS                  Operation successful.
    467 * \retval NFCSTATUS_INVALID_PARAMETER        One or more of the supplied parameters
    468 *                                            could not be properly interpreted.
    469 * \retval NFCSTATUS_FAILED                   Operation failed.
    470 */
    471 NFCSTATUS phFriNfc_LlcpTransport_Close(phFriNfc_LlcpTransport_Socket_t*   pLlcpSocket);
    472 
    473 
    474 /**
    475 * \ingroup grp_fri_nfc
    476 * \brief <b>Bind a socket to a local SAP</b>.
    477 *
    478 * This function binds the socket to a local Service Access Point.
    479 *
    480 * \param[out] pLlcpSocket           A pointer to a phFriNfc_LlcpTransport_Socket_t.
    481 * \param[in]  pConfigInfo           A port number for a specific socket
    482 * \param TODO
    483 *
    484 * \retval NFCSTATUS_SUCCESS                  Operation successful.
    485 * \retval NFCSTATUS_INVALID_PARAMETER        One or more of the supplied parameters
    486 *                                            could not be properly interpreted.
    487 * \retval NFCSTATUS_INVALID_STATE            The socket is not in a valid state, or not of
    488 *                                            a valid type to perform the requsted operation.
    489 * \retval NFCSTATUS_ALREADY_REGISTERED       The selected SAP is already bound to another
    490                                              socket.
    491 * \retval NFCSTATUS_FAILED                   Operation failed.
    492 */
    493 NFCSTATUS phFriNfc_LlcpTransport_Bind(phFriNfc_LlcpTransport_Socket_t    *pLlcpSocket,
    494                                       uint8_t                            nSap,
    495                                       phNfc_sData_t                      *psServiceName);
    496 
    497 /**
    498 * \ingroup grp_fri_nfc
    499 * \brief <b>Listen for incoming connection requests on a socket</b>.
    500 *
    501 * This function switches a socket into a listening state and registers a callback on
    502 * incoming connection requests. In this state, the socket is not able to communicate
    503 * directly. The listening state is only available for connection-oriented sockets
    504 * which are still not connected. The socket keeps listening until it is closed, and
    505 * thus can trigger several times the pListen_Cb callback.
    506 *
    507 *
    508 * \param[in]  pLlcpSocket        A pointer to a phFriNfc_LlcpTransport_Socket_t.
    509 * \param[in]  pListen_Cb         The callback to be called each time the
    510 *                                socket receive a connection request.
    511 * \param[in]  pContext           Upper layer context to be returned in
    512 *                                the callback.
    513 *
    514 * \retval NFCSTATUS_SUCCESS                  Operation successful.
    515 * \retval NFCSTATUS_INVALID_PARAMETER        One or more of the supplied parameters
    516 *                                            could not be properly interpreted.
    517 * \retval NFCSTATUS_INVALID_STATE            The socket is not in a valid state to switch
    518 *                                            to listening state.
    519 * \retval NFCSTATUS_FAILED                   Operation failed.
    520 */
    521 NFCSTATUS phFriNfc_LlcpTransport_Listen(phFriNfc_LlcpTransport_Socket_t*          pLlcpSocket,
    522                                         pphFriNfc_LlcpTransportSocketListenCb_t   pListen_Cb,
    523                                         void*                                     pContext);
    524 
    525 /**
    526 * \ingroup grp_fri_nfc
    527 * \brief <b>Accept an incoming connection request for a socket</b>.
    528 *
    529 * This functions allows the client to accept an incoming connection request.
    530 * It must be used with the socket provided within the listen callback. The socket
    531 * is implicitly switched to the connected state when the function is called.
    532 *
    533 * \param[in]  pLlcpSocket           A pointer to a phFriNfc_LlcpTransport_Socket_t.
    534 * \param[in]  psOptions             The options to be used with the socket.
    535 * \param[in]  psWorkingBuffer       A working buffer to be used by the library.
    536 * \param[in]  pErr_Cb               The callback to be called each time the accepted socket
    537 *                                   is in error.
    538 * \param[in]  pAccept_RspCb         The callback to be called when the Accept operation is completed
    539 * \param[in]  pContext              Upper layer context to be returned in the callback.
    540 *
    541 * \retval NFCSTATUS_SUCCESS                  Operation successful.
    542 * \retval NFCSTATUS_INVALID_PARAMETER        One or more of the supplied parameters
    543 *                                            could not be properly interpreted.
    544 * \retval NFCSTATUS_BUFFER_TOO_SMALL         The working buffer is too small for the MIU and RW
    545 *                                            declared in the options.
    546 * \retval NFCSTATUS_FAILED                   Operation failed.
    547 */
    548 NFCSTATUS phFriNfc_LlcpTransport_Accept(phFriNfc_LlcpTransport_Socket_t*             pLlcpSocket,
    549                                         phFriNfc_LlcpTransport_sSocketOptions_t*     psOptions,
    550                                         phNfc_sData_t*                               psWorkingBuffer,
    551                                         pphFriNfc_LlcpTransportSocketErrCb_t         pErr_Cb,
    552                                         pphFriNfc_LlcpTransportSocketAcceptCb_t      pAccept_RspCb,
    553                                         void*                                        pContext);
    554 
    555  /**
    556 * \ingroup grp_fri_nfc
    557 * \brief <b>Reject an incoming connection request for a socket</b>.
    558 *
    559 * This functions allows the client to reject an incoming connection request.
    560 * It must be used with the socket provided within the listen callback. The socket
    561 * is implicitly closed when the function is called.
    562 *
    563 * \param[in]  pLlcpSocket           A pointer to a phFriNfc_LlcpTransport_Socket_t.
    564 * \param[in]  pReject_RspCb         The callback to be called when the Reject operation is completed
    565 * \param[in]  pContext              Upper layer context to be returned in the callback.
    566 *
    567 * \retval NFCSTATUS_SUCCESS                  Operation successful.
    568 * \retval NFCSTATUS_INVALID_PARAMETER        One or more of the supplied parameters
    569 *                                            could not be properly interpreted.
    570 * \retval NFCSTATUS_FAILED                   Operation failed.
    571 */
    572 NFCSTATUS phFriNfc_LlcpTransport_Reject( phFriNfc_LlcpTransport_Socket_t*           pLlcpSocket,
    573                                             pphFriNfc_LlcpTransportSocketRejectCb_t   pReject_RspCb,
    574                                             void                                      *pContext);
    575 /**
    576 * \ingroup grp_fri_nfc
    577 * \brief <b>Try to establish connection with a socket on a remote SAP</b>.
    578 *
    579 * This function tries to connect to a given SAP on the remote peer. If the
    580 * socket is not bound to a local SAP, it is implicitly bound to a free SAP.
    581 *
    582 * \param[in]  pLlcpSocket           A pointer to a phFriNfc_LlcpTransport_Socket_t.
    583 * \param[in]  nSap               The destination SAP to connect to.
    584 * \param[in]  pConnect_RspCb     The callback to be called when the connection
    585 *                                operation is completed.
    586 * \param[in]  pContext           Upper layer context to be returned in
    587 *                                the callback.
    588 *
    589 * \retval NFCSTATUS_SUCCESS                  Operation successful.
    590 * \retval NFCSTATUS_INVALID_PARAMETER        One or more of the supplied parameters
    591 *                                            could not be properly interpreted.
    592 * \retval NFCSTATUS_PENDING                  Connection operation is in progress,
    593 *                                            pConnect_RspCb will be called upon completion.
    594 * \retval NFCSTATUS_INVALID_STATE            The socket is not in a valid state, or not of
    595 *                                            a valid type to perform the requsted operation.
    596 * \retval NFCSTATUS_FAILED                   Operation failed.
    597 */
    598 NFCSTATUS phFriNfc_LlcpTransport_Connect( phFriNfc_LlcpTransport_Socket_t*           pLlcpSocket,
    599                                           uint8_t                                    nSap,
    600                                           pphFriNfc_LlcpTransportSocketConnectCb_t   pConnect_RspCb,
    601                                           void*                                      pContext);
    602 
    603 /**
    604 * \ingroup grp_fri_nfc
    605 * \brief <b>Try to establish connection with a socket on a remote service, given its URI</b>.
    606 *
    607 * This function tries to connect to a SAP designated by an URI. If the
    608 * socket is not bound to a local SAP, it is implicitly bound to a free SAP.
    609 *
    610 * \param[in]  pLlcpSocket        A pointer to a phFriNfc_LlcpTransport_Socket_t.
    611 * \param[in]  psUri              The URI corresponding to the destination SAP to connect to.
    612 * \param[in]  pConnect_RspCb     The callback to be called when the connection
    613 *                                operation is completed.
    614 * \param[in]  pContext           Upper layer context to be returned in
    615 *                                the callback.
    616 *
    617 * \retval NFCSTATUS_SUCCESS                  Operation successful.
    618 * \retval NFCSTATUS_INVALID_PARAMETER        One or more of the supplied parameters
    619 *                                            could not be properly interpreted.
    620 * \retval NFCSTATUS_PENDING                  Connection operation is in progress,
    621 *                                            pConnect_RspCb will be called upon completion.
    622 * \retval NFCSTATUS_INVALID_STATE            The socket is not in a valid state, or not of
    623 *                                            a valid type to perform the requsted operation.
    624 * \retval NFCSTATUS_NOT_INITIALISED          Indicates stack is not yet initialized.
    625 * \retval NFCSTATUS_SHUTDOWN                 Shutdown in progress.
    626 * \retval NFCSTATUS_FAILED                   Operation failed.
    627 */
    628 NFCSTATUS phFriNfc_LlcpTransport_ConnectByUri(phFriNfc_LlcpTransport_Socket_t*           pLlcpSocket,
    629                                               phNfc_sData_t*                            psUri,
    630                                               pphFriNfc_LlcpTransportSocketConnectCb_t   pConnect_RspCb,
    631                                               void*                                     pContext);
    632 
    633 /**
    634 * \ingroup grp_lib_nfc
    635 * \brief <b>Disconnect a currently connected socket</b>.
    636 *
    637 * This function initiates the disconnection of a previously connected socket.
    638 *
    639 * \param[in]  pLlcpSocket        A pointer to a phFriNfc_LlcpTransport_Socket_t.
    640 * \param[in]  pDisconnect_RspCb  The callback to be called when the
    641 *                                operation is completed.
    642 * \param[in]  pContext           Upper layer context to be returned in
    643 *                                the callback.
    644 *
    645 * \retval NFCSTATUS_SUCCESS                  Operation successful.
    646 * \retval NFCSTATUS_INVALID_PARAMETER        One or more of the supplied parameters
    647 *                                            could not be properly interpreted.
    648 * \retval NFCSTATUS_PENDING                  Disconnection operation is in progress,
    649 *                                            pDisconnect_RspCb will be called upon completion.
    650 * \retval NFCSTATUS_INVALID_STATE            The socket is not in a valid state, or not of
    651 *                                            a valid type to perform the requsted operation.
    652 * \retval NFCSTATUS_NOT_INITIALISED          Indicates stack is not yet initialized.
    653 * \retval NFCSTATUS_SHUTDOWN                 Shutdown in progress.
    654 * \retval NFCSTATUS_FAILED                   Operation failed.
    655 */
    656 NFCSTATUS phFriNfc_LlcpTransport_Disconnect(phFriNfc_LlcpTransport_Socket_t*           pLlcpSocket,
    657                                             pphLibNfc_LlcpSocketDisconnectCb_t         pDisconnect_RspCb,
    658                                             void*                                      pContext);
    659 
    660 /**
    661 * \ingroup grp_fri_nfc
    662 * \brief <b>Send data on a socket</b>.
    663 *
    664 * This function is used to write data on a socket. This function
    665 * can only be called on a connection-oriented socket which is already
    666 * in a connected state.
    667 *
    668 *
    669 * \param[in]  hSocket            Socket handle obtained during socket creation.
    670 * \param[in]  psBuffer           The buffer containing the data to send.
    671 * \param[in]  pSend_RspCb        The callback to be called when the
    672 *                                operation is completed.
    673 * \param[in]  pContext           Upper layer context to be returned in
    674 *                                the callback.
    675 *
    676 * \retval NFCSTATUS_SUCCESS                  Operation successful.
    677 * \retval NFCSTATUS_INVALID_PARAMETER        One or more of the supplied parameters
    678 *                                            could not be properly interpreted.
    679 * \retval NFCSTATUS_PENDING                  Reception operation is in progress,
    680 *                                            pSend_RspCb will be called upon completion.
    681 * \retval NFCSTATUS_INVALID_STATE            The socket is not in a valid state, or not of
    682 *                                            a valid type to perform the requsted operation.
    683 * \retval NFCSTATUS_FAILED                   Operation failed.
    684 */
    685 NFCSTATUS phFriNfc_LlcpTransport_Send(phFriNfc_LlcpTransport_Socket_t*             pLlcpSocket,
    686                                       phNfc_sData_t*                               psBuffer,
    687                                       pphFriNfc_LlcpTransportSocketSendCb_t        pSend_RspCb,
    688                                       void*                                        pContext);
    689 
    690 /**
    691 * \ingroup grp_fri_nfc
    692 * \brief <b>Read data on a socket</b>.
    693 *
    694 * This function is used to read data from a socket. It reads at most the
    695 * size of the reception buffer, but can also return less bytes if less bytes
    696 * are available. If no data is available, the function will be pending until
    697 * more data comes, and the response will be sent by the callback. This function
    698 * can only be called on a connection-oriented socket.
    699 *
    700 *
    701 * \param[in]  hSocket            Socket handle obtained during socket creation.
    702 * \param[in]  psBuffer           The buffer receiving the data.
    703 * \param[in]  pRecv_RspCb        The callback to be called when the
    704 *                                operation is completed.
    705 * \param[in]  pContext           Upper layer context to be returned in
    706 *                                the callback.
    707 *
    708 * \retval NFCSTATUS_SUCCESS                  Operation successful.
    709 * \retval NFCSTATUS_INVALID_PARAMETER        One or more of the supplied parameters
    710 *                                            could not be properly interpreted.
    711 * \retval NFCSTATUS_PENDING                  Reception operation is in progress,
    712 *                                            pRecv_RspCb will be called upon completion.
    713 * \retval NFCSTATUS_INVALID_STATE            The socket is not in a valid state, or not of
    714 *                                            a valid type to perform the requsted operation.
    715 * \retval NFCSTATUS_FAILED                   Operation failed.
    716 */
    717 NFCSTATUS phFriNfc_LlcpTransport_Recv( phFriNfc_LlcpTransport_Socket_t*             pLlcpSocket,
    718                                        phNfc_sData_t*                               psBuffer,
    719                                        pphFriNfc_LlcpTransportSocketRecvCb_t        pRecv_RspCb,
    720                                        void*                                        pContext);
    721 
    722 
    723 
    724  /**
    725 * \ingroup grp_lib_nfc
    726 * \brief <b>Read data on a socket and get the source SAP</b>.
    727 *
    728 * This function is the same as phLibNfc_Llcp_Recv, except that the callback includes
    729 * the source SAP. This functions can only be called on a connectionless socket.
    730 *
    731 *
    732 * \param[in]  pLlcpSocket        A pointer to a LlcpSocket created.
    733 * \param[in]  psBuffer           The buffer receiving the data.
    734 * \param[in]  pRecv_RspCb        The callback to be called when the
    735 *                                operation is completed.
    736 * \param[in]  pContext           Upper layer context to be returned in
    737 *                                the callback.
    738 *
    739 * \retval NFCSTATUS_SUCCESS                  Operation successful.
    740 * \retval NFCSTATUS_INVALID_PARAMETER        One or more of the supplied parameters
    741 *                                            could not be properly interpreted.
    742 * \retval NFCSTATUS_PENDING                  Reception operation is in progress,
    743 *                                            pRecv_RspCb will be called upon completion.
    744 * \retval NFCSTATUS_INVALID_STATE            The socket is not in a valid state, or not of
    745 *                                            a valid type to perform the requsted operation.
    746 * \retval NFCSTATUS_NOT_INITIALISED          Indicates stack is not yet initialized.
    747 * \retval NFCSTATUS_SHUTDOWN                 Shutdown in progress.
    748 * \retval NFCSTATUS_FAILED                   Operation failed.
    749 */
    750 NFCSTATUS phFriNfc_LlcpTransport_RecvFrom( phFriNfc_LlcpTransport_Socket_t                   *pLlcpSocket,
    751                                            phNfc_sData_t*                                    psBuffer,
    752                                            pphFriNfc_LlcpTransportSocketRecvFromCb_t         pRecv_Cb,
    753                                            void                                              *pContext);
    754 
    755 /**
    756 * \ingroup grp_fri_nfc
    757 * \brief <b>Send data on a socket to a given destination SAP</b>.
    758 *
    759 * This function is used to write data on a socket to a given destination SAP.
    760 * This function can only be called on a connectionless socket.
    761 *
    762 *
    763 * \param[in]  pLlcpSocket        A pointer to a LlcpSocket created.
    764 * \param[in]  nSap               The destination SAP.
    765 * \param[in]  psBuffer           The buffer containing the data to send.
    766 * \param[in]  pSend_RspCb        The callback to be called when the
    767 *                                operation is completed.
    768 * \param[in]  pContext           Upper layer context to be returned in
    769 *                                the callback.
    770 *
    771 * \retval NFCSTATUS_SUCCESS                  Operation successful.
    772 * \retval NFCSTATUS_INVALID_PARAMETER        One or more of the supplied parameters
    773 *                                            could not be properly interpreted.
    774 * \retval NFCSTATUS_PENDING                  Reception operation is in progress,
    775 *                                            pSend_RspCb will be called upon completion.
    776 * \retval NFCSTATUS_INVALID_STATE            The socket is not in a valid state, or not of
    777 *                                            a valid type to perform the requsted operation.
    778 * \retval NFCSTATUS_NOT_INITIALISED          Indicates stack is not yet initialized.
    779 * \retval NFCSTATUS_SHUTDOWN                 Shutdown in progress.
    780 * \retval NFCSTATUS_FAILED                   Operation failed.
    781 */
    782 NFCSTATUS phFriNfc_LlcpTransport_SendTo( phFriNfc_LlcpTransport_Socket_t             *pLlcpSocket,
    783                                          uint8_t                                     nSap,
    784                                          phNfc_sData_t*                              psBuffer,
    785                                          pphFriNfc_LlcpTransportSocketSendCb_t       pSend_RspCb,
    786                                          void*                                       pContext);
    787 #endif  /*  PHFRINFC_LLCP_TRANSPORT_H    */
    788