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_Connection.h
     19  * \brief
     20  *
     21  * Project: NFC-FRI
     22  *
     23  */
     24 #ifndef PHFRINFC_LLCP_TRANSPORT_CONNECTION_H
     25 #define PHFRINFC_LLCP_TRANSPORT_CONNECTION_H
     26 /*include files*/
     27 #include <phNfcTypes.h>
     28 #include <phNfcStatus.h>
     29 #include <phFriNfc.h>
     30 
     31 #include <phFriNfc_Llcp.h>
     32 
     33 
     34 void Handle_ConnectionOriented_IncommingFrame(phFriNfc_LlcpTransport_t      *pLlcpTransport,
     35                                               phNfc_sData_t                 *psData,
     36                                               uint8_t                       dsap,
     37                                               uint8_t                       ptype,
     38                                               uint8_t                       ssap);
     39 
     40 /**
     41 * \ingroup grp_lib_nfc
     42 * \brief <b>Get the local options of a socket</b>.
     43 *
     44 * This function returns the local options (maximum packet size and receive window size) used
     45 * for a given connection-oriented socket. This function shall not be used with connectionless
     46 * sockets.
     47 *
     48 * \param[out] pLlcpSocket           A pointer to a phFriNfc_LlcpTransport_Socket_t.
     49 * \param[in]  psLocalOptions        A pointer to be filled with the local options of the socket.
     50 *
     51 * \retval NFCSTATUS_SUCCESS                  Operation successful.
     52 * \retval NFCSTATUS_INVALID_PARAMETER        One or more of the supplied parameters
     53 *                                            could not be properly interpreted.
     54 * \retval NFCSTATUS_INVALID_STATE            The socket is not in a valid state, or not of
     55 *                                            a valid type to perform the requsted operation.
     56 * \retval NFCSTATUS_NOT_INITIALISED          Indicates stack is not yet initialized.
     57 * \retval NFCSTATUS_SHUTDOWN                 Shutdown in progress.
     58 * \retval NFCSTATUS_FAILED                   Operation failed.
     59 */
     60 NFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_SocketGetLocalOptions(phFriNfc_LlcpTransport_Socket_t  *pLlcpSocket,
     61                                                                           phLibNfc_Llcp_sSocketOptions_t   *psLocalOptions);
     62 
     63 /**
     64 * \ingroup grp_lib_nfc
     65 * \brief <b>Get the local options of a socket</b>.
     66 *
     67 * This function returns the remote options (maximum packet size and receive window size) used
     68 * for a given connection-oriented socket. This function shall not be used with connectionless
     69 * sockets.
     70 *
     71 * \param[out] pLlcpSocket           A pointer to a phFriNfc_LlcpTransport_Socket_t.
     72 * \param[in]  psRemoteOptions       A pointer to be filled with the remote options of the socket.
     73 *
     74 * \retval NFCSTATUS_SUCCESS                  Operation successful.
     75 * \retval NFCSTATUS_INVALID_PARAMETER        One or more of the supplied parameters
     76 *                                            could not be properly interpreted.
     77 * \retval NFCSTATUS_INVALID_STATE            The socket is not in a valid state, or not of
     78 *                                            a valid type to perform the requsted operation.
     79 * \retval NFCSTATUS_NOT_INITIALISED          Indicates stack is not yet initialized.
     80 * \retval NFCSTATUS_SHUTDOWN                 Shutdown in progress.
     81 * \retval NFCSTATUS_FAILED                   Operation failed.
     82 */
     83 NFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_SocketGetRemoteOptions(phFriNfc_LlcpTransport_Socket_t*   pLlcpSocket,
     84                                                                            phLibNfc_Llcp_sSocketOptions_t*    psRemoteOptions);
     85 
     86 /**
     87 * \ingroup grp_fri_nfc
     88 * \brief <b>Close a socket on a LLCP-connected device</b>.
     89 *
     90 * This function closes a LLCP socket previously created using phFriNfc_LlcpTransport_Socket.
     91 * If the socket was connected, it is first disconnected, and then closed.
     92 *
     93 * \param[in]  pLlcpSocket                    A pointer to a phFriNfc_LlcpTransport_Socket_t.
     94 
     95 * \retval NFCSTATUS_SUCCESS                  Operation successful.
     96 * \retval NFCSTATUS_INVALID_PARAMETER        One or more of the supplied parameters
     97 *                                            could not be properly interpreted.
     98 * \retval NFCSTATUS_FAILED                   Operation failed.
     99 */
    100 NFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_Close(phFriNfc_LlcpTransport_Socket_t*   pLlcpSocket);
    101 
    102 /**
    103 * \ingroup grp_fri_nfc
    104 * \brief <b>Listen for incoming connection requests on a socket</b>.
    105 *
    106 * This function switches a socket into a listening state and registers a callback on
    107 * incoming connection requests. In this state, the socket is not able to communicate
    108 * directly. The listening state is only available for connection-oriented sockets
    109 * which are still not connected. The socket keeps listening until it is closed, and
    110 * thus can trigger several times the pListen_Cb callback.
    111 *
    112 *
    113 * \param[in]  pLlcpSocket        A pointer to a phFriNfc_LlcpTransport_Socket_t.
    114 * \param[in]  psServiceName      A pointer to a Service Name
    115 * \param[in]  pListen_Cb         The callback to be called each time the
    116 *                                socket receive a connection request.
    117 * \param[in]  pContext           Upper layer context to be returned in
    118 *                                the callback.
    119 *
    120 * \retval NFCSTATUS_SUCCESS                  Operation successful.
    121 * \retval NFCSTATUS_INVALID_PARAMETER        One or more of the supplied parameters
    122 *                                            could not be properly interpreted.
    123 * \retval NFCSTATUS_INVALID_STATE            The socket is not in a valid state to switch
    124 *                                            to listening state.
    125 * \retval NFCSTATUS_FAILED                   Operation failed.
    126 */
    127 NFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_Listen(phFriNfc_LlcpTransport_Socket_t*          pLlcpSocket,
    128                                                            phNfc_sData_t                             *psServiceName,
    129                                                            pphFriNfc_LlcpTransportSocketListenCb_t   pListen_Cb,
    130                                                            void*                                     pContext);
    131 
    132 
    133 /**
    134 * \ingroup grp_fri_nfc
    135 * \brief <b>Accept an incoming connection request for a socket</b>.
    136 *
    137 * This functions allows the client to accept an incoming connection request.
    138 * It must be used with the socket provided within the listen callback. The socket
    139 * is implicitly switched to the connected state when the function is called.
    140 *
    141 * \param[in]  pLlcpSocket           A pointer to a phFriNfc_LlcpTransport_Socket_t.
    142 * \param[in]  psOptions             The options to be used with the socket.
    143 * \param[in]  psWorkingBuffer       A working buffer to be used by the library.
    144 * \param[in]  pErr_Cb               The callback to be called each time the accepted socket
    145 *                                   is in error.
    146 * \param[in]  pAccept_RspCb         The callback to be called when the Accept operation is completed
    147 * \param[in]  pContext              Upper layer context to be returned in the callback.
    148 *
    149 * \retval NFCSTATUS_SUCCESS                  Operation successful.
    150 * \retval NFCSTATUS_INVALID_PARAMETER        One or more of the supplied parameters
    151 *                                            could not be properly interpreted.
    152 * \retval NFCSTATUS_BUFFER_TOO_SMALL         The working buffer is too small for the MIU and RW
    153 *                                            declared in the options.
    154 * \retval NFCSTATUS_FAILED                   Operation failed.
    155 */
    156 NFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_Accept(phFriNfc_LlcpTransport_Socket_t*             pLlcpSocket,
    157                                                            phFriNfc_LlcpTransport_sSocketOptions_t*     psOptions,
    158                                                            phNfc_sData_t*                               psWorkingBuffer,
    159                                                            pphFriNfc_LlcpTransportSocketErrCb_t         pErr_Cb,
    160                                                            pphFriNfc_LlcpTransportSocketAcceptCb_t      pAccept_RspCb,
    161                                                            void*                                        pContext);
    162 
    163 
    164  /**
    165 * \ingroup grp_fri_nfc
    166 * \brief <b>Reject an incoming connection request for a socket</b>.
    167 *
    168 * This functions allows the client to reject an incoming connection request.
    169 * It must be used with the socket provided within the listen callback. The socket
    170 * is implicitly closed when the function is called.
    171 *
    172 * \param[in]  pLlcpSocket           A pointer to a phFriNfc_LlcpTransport_Socket_t.
    173 * \param[in]  pReject_RspCb         The callback to be called when the Reject operation is completed
    174 * \param[in]  pContext              Upper layer context to be returned in the callback.
    175 *
    176 * \retval NFCSTATUS_SUCCESS                  Operation successful.
    177 * \retval NFCSTATUS_INVALID_PARAMETER        One or more of the supplied parameters
    178 *                                            could not be properly interpreted.
    179 * \retval NFCSTATUS_FAILED                   Operation failed.
    180 */
    181 NFCSTATUS phLibNfc_LlcpTransport_ConnectionOriented_Reject( phFriNfc_LlcpTransport_Socket_t*           pLlcpSocket,
    182                                                             pphFriNfc_LlcpTransportSocketRejectCb_t   pReject_RspCb,
    183                                                             void                                      *pContext);
    184 
    185 /**
    186 * \ingroup grp_fri_nfc
    187 * \brief <b>Try to establish connection with a socket on a remote SAP</b>.
    188 *
    189 * This function tries to connect to a given SAP on the remote peer. If the
    190 * socket is not bound to a local SAP, it is implicitly bound to a free SAP.
    191 *
    192 * \param[in]  pLlcpSocket        A pointer to a phFriNfc_LlcpTransport_Socket_t.
    193 * \param[in]  nSap               The destination SAP to connect to.
    194 * \param[in]  psUri              The URI corresponding to the destination SAP to connect to.
    195 * \param[in]  pConnect_RspCb     The callback to be called when the connection
    196 *                                operation is completed.
    197 * \param[in]  pContext           Upper layer context to be returned in
    198 *                                the callback.
    199 *
    200 * \retval NFCSTATUS_SUCCESS                  Operation successful.
    201 * \retval NFCSTATUS_INVALID_PARAMETER        One or more of the supplied parameters
    202 *                                            could not be properly interpreted.
    203 * \retval NFCSTATUS_PENDING                  Connection operation is in progress,
    204 *                                            pConnect_RspCb will be called upon completion.
    205 * \retval NFCSTATUS_INVALID_STATE            The socket is not in a valid state, or not of
    206 *                                            a valid type to perform the requsted operation.
    207 * \retval NFCSTATUS_FAILED                   Operation failed.
    208 */
    209 NFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_Connect( phFriNfc_LlcpTransport_Socket_t*           pLlcpSocket,
    210                                                              uint8_t                                    nSap,
    211                                                              phNfc_sData_t*                             psUri,
    212                                                              pphFriNfc_LlcpTransportSocketConnectCb_t   pConnect_RspCb,
    213                                                              void*                                      pContext);
    214 
    215 /**
    216 * \ingroup grp_lib_nfc
    217 * \brief <b>Disconnect a currently connected socket</b>.
    218 *
    219 * This function initiates the disconnection of a previously connected socket.
    220 *
    221 * \param[in]  pLlcpSocket        A pointer to a phFriNfc_LlcpTransport_Socket_t.
    222 * \param[in]  pDisconnect_RspCb  The callback to be called when the
    223 *                                operation is completed.
    224 * \param[in]  pContext           Upper layer context to be returned in
    225 *                                the callback.
    226 *
    227 * \retval NFCSTATUS_SUCCESS                  Operation successful.
    228 * \retval NFCSTATUS_INVALID_PARAMETER        One or more of the supplied parameters
    229 *                                            could not be properly interpreted.
    230 * \retval NFCSTATUS_PENDING                  Disconnection operation is in progress,
    231 *                                            pDisconnect_RspCb will be called upon completion.
    232 * \retval NFCSTATUS_INVALID_STATE            The socket is not in a valid state, or not of
    233 *                                            a valid type to perform the requsted operation.
    234 * \retval NFCSTATUS_NOT_INITIALISED          Indicates stack is not yet initialized.
    235 * \retval NFCSTATUS_SHUTDOWN                 Shutdown in progress.
    236 * \retval NFCSTATUS_FAILED                   Operation failed.
    237 */
    238 NFCSTATUS phLibNfc_LlcpTransport_ConnectionOriented_Disconnect(phFriNfc_LlcpTransport_Socket_t*           pLlcpSocket,
    239                                                                pphLibNfc_LlcpSocketDisconnectCb_t         pDisconnect_RspCb,
    240                                                                void*                                      pContext);
    241 
    242 /**
    243 * \ingroup grp_fri_nfc
    244 * \brief <b>Send data on a socket</b>.
    245 *
    246 * This function is used to write data on a socket. This function
    247 * can only be called on a connection-oriented socket which is already
    248 * in a connected state.
    249 *
    250 *
    251 * \param[in]  pLlcpSocket        A pointer to a phFriNfc_LlcpTransport_Socket_t.
    252 * \param[in]  psBuffer           The buffer containing the data to send.
    253 * \param[in]  pSend_RspCb        The callback to be called when the
    254 *                                operation is completed.
    255 * \param[in]  pContext           Upper layer context to be returned in
    256 *                                the callback.
    257 *
    258 * \retval NFCSTATUS_SUCCESS                  Operation successful.
    259 * \retval NFCSTATUS_INVALID_PARAMETER        One or more of the supplied parameters
    260 *                                            could not be properly interpreted.
    261 * \retval NFCSTATUS_PENDING                  Reception operation is in progress,
    262 *                                            pSend_RspCb will be called upon completion.
    263 * \retval NFCSTATUS_INVALID_STATE            The socket is not in a valid state, or not of
    264 *                                            a valid type to perform the requsted operation.
    265 * \retval NFCSTATUS_FAILED                   Operation failed.
    266 */
    267 NFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_Send(phFriNfc_LlcpTransport_Socket_t*             pLlcpSocket,
    268                                                          phNfc_sData_t*                               psBuffer,
    269                                                          pphFriNfc_LlcpTransportSocketSendCb_t        pSend_RspCb,
    270                                                          void*                                        pContext);
    271 
    272  /**
    273 * \ingroup grp_fri_nfc
    274 * \brief <b>Read data on a socket</b>.
    275 *
    276 * This function is used to read data from a socket. It reads at most the
    277 * size of the reception buffer, but can also return less bytes if less bytes
    278 * are available. If no data is available, the function will be pending until
    279 * more data comes, and the response will be sent by the callback. This function
    280 * can only be called on a connection-oriented socket.
    281 *
    282 *
    283 * \param[in]  pLlcpSocket        A pointer to a phFriNfc_LlcpTransport_Socket_t.
    284 * \param[in]  psBuffer           The buffer receiving the data.
    285 * \param[in]  pRecv_RspCb        The callback to be called when the
    286 *                                operation is completed.
    287 * \param[in]  pContext           Upper layer context to be returned in
    288 *                                the callback.
    289 *
    290 * \retval NFCSTATUS_SUCCESS                  Operation successful.
    291 * \retval NFCSTATUS_INVALID_PARAMETER        One or more of the supplied parameters
    292 *                                            could not be properly interpreted.
    293 * \retval NFCSTATUS_PENDING                  Reception operation is in progress,
    294 *                                            pRecv_RspCb will be called upon completion.
    295 * \retval NFCSTATUS_INVALID_STATE            The socket is not in a valid state, or not of
    296 *                                            a valid type to perform the requsted operation.
    297 * \retval NFCSTATUS_FAILED                   Operation failed.
    298 */
    299 NFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_Recv( phFriNfc_LlcpTransport_Socket_t*             pLlcpSocket,
    300                                                           phNfc_sData_t*                               psBuffer,
    301                                                           pphFriNfc_LlcpTransportSocketRecvCb_t        pRecv_RspCb,
    302                                                           void*                                        pContext);
    303 #endif /* PHFRINFC_LLCP_TRANSPORT_CONNECTION_H */