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