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