2 * Copyright (C) 2010 NXP Semiconductors
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
18 * \file phFriNfc_Llcp.h
\r
19 * \brief NFC LLCP core
\r
25 #ifndef PHFRINFC_LLCP_H
\r
26 #define PHFRINFC_LLCP_H
\r
29 #include <phNfcTypes.h>
\r
30 #include <phNfcLlcpTypes.h>
\r
31 #include <phNfcStatus.h>
\r
32 #include <phFriNfc.h>
\r
34 #include <phFriNfc_LlcpMac.h>
\r
37 * \name NFC Forum Logical Link Control Protocol
\r
39 * File: \ref phFriNfc_Llcp.h
\r
44 /** \defgroup grp_fri_nfc_llcp NFC Forum Logical Link Control Protocol Component
\r
50 /*=========== DEBUG MACROS ===========*/
\r
52 /* LLCP TRACE Macros */
\r
53 #if defined(LLCP_TRACE)
\r
54 #include <phOsalNfc.h>
\r
56 extern char phOsalNfc_DbgTraceBuffer[];
\r
57 #define LLCP_MAX_TRACE_BUFFER 150
\r
58 #define LLCP_PRINT( str ) phOsalNfc_DbgString(str)
\r
59 #define LLCP_DEBUG(str, arg) \
\r
61 snprintf(phOsalNfc_DbgTraceBuffer,LLCP_MAX_TRACE_BUFFER,str,arg); \
\r
62 phOsalNfc_DbgString(phOsalNfc_DbgTraceBuffer); \
\r
64 #define LLCP_PRINT_BUFFER(msg,buf,len) \
\r
66 snprintf(phOsalNfc_DbgTraceBuffer,LLCP_MAX_TRACE_BUFFER,"\n\t %s:",msg); \
\r
67 phOsalNfc_DbgString(phOsalNfc_DbgTraceBuffer); \
\r
68 phOsalNfc_DbgTrace(buf,len); \
\r
69 phOsalNfc_DbgString("\r"); \
\r
72 #define LLCP_PRINT( str )
\r
73 #define LLCP_DEBUG(str, arg)
\r
74 #define LLCP_PRINT_BUFFER(msg,buf,len)
\r
78 /*=========== CONSTANTS ===========*/
\r
81 * \name LLCP local protocol version.
\r
85 #define PHFRINFC_LLCP_VERSION_MAJOR 0x01 /**< Major number of local LLCP version.*/
\r
86 #define PHFRINFC_LLCP_VERSION_MINOR 0x00 /**< Minor number of local LLCP version.*/
\r
87 #define PHFRINFC_LLCP_VERSION ((PHFRINFC_LLCP_VERSION_MAJOR << 4) | PHFRINFC_LLCP_VERSION_MINOR) /**< Local LLCP version.*/
\r
91 * \name LLCP packet types.
\r
95 #define PHFRINFC_LLCP_PTYPE_SYMM 0x00 /**< Symmetry.*/
\r
96 #define PHFRINFC_LLCP_PTYPE_PAX 0x01 /**< PArameter Exchange.*/
\r
97 #define PHFRINFC_LLCP_PTYPE_AGF 0x02 /**< AGgregated Frame.*/
\r
98 #define PHFRINFC_LLCP_PTYPE_UI 0x03 /**< Unnumbered Information.*/
\r
99 #define PHFRINFC_LLCP_PTYPE_CONNECT 0x04 /**< Connect.*/
\r
100 #define PHFRINFC_LLCP_PTYPE_DISC 0x05 /**< Didconnect.*/
\r
101 #define PHFRINFC_LLCP_PTYPE_CC 0x06 /**< Connection Complete.*/
\r
102 #define PHFRINFC_LLCP_PTYPE_DM 0x07 /**< Disconnected Mode.*/
\r
103 #define PHFRINFC_LLCP_PTYPE_FRMR 0x08 /**< FRaMe Reject.*/
\r
104 #define PHFRINFC_LLCP_PTYPE_RESERVED1 0x09 /**< Reserved.*/
\r
105 #define PHFRINFC_LLCP_PTYPE_RESERVED2 0x0A /**< Reserved.*/
\r
106 #define PHFRINFC_LLCP_PTYPE_RESERVED3 0x0B /**< Reserved.*/
\r
107 #define PHFRINFC_LLCP_PTYPE_I 0x0C /**< Information.*/
\r
108 #define PHFRINFC_LLCP_PTYPE_RR 0x0D /**< Receive Ready.*/
\r
109 #define PHFRINFC_LLCP_PTYPE_RNR 0x0E /**< Receive Not Ready.*/
\r
110 #define PHFRINFC_LLCP_PTYPE_RESERVED4 0x0F /**< Reserved.*/
\r
114 * \name LLCP well-known SAPs.
\r
118 #define PHFRINFC_LLCP_SAP_LINK 0x00 /**< Link SAP.*/
\r
119 #define PHFRINFC_LLCP_SAP_SDP 0x01 /**< Service Discovery Protocol SAP.*/
\r
120 #define PHFRINFC_LLCP_SAP_WKS_FIRST 0x02 /**< Other Well-Known Services defined by the NFC Forum.*/
\r
121 #define PHFRINFC_LLCP_SAP_SDP_ADVERTISED_FIRST 0x10 /**< First SAP number from SDP-avertised SAP range.*/
\r
122 #define PHFRINFC_LLCP_SAP_SDP_UNADVERTISED_FIRST 0x20 /**< First SAP number from SDP-unavertised SAP range.*/
\r
123 #define PHFRINFC_LLCP_SAP_NUMBER 0x40 /**< Number of possible SAP values (also first invalid value).*/
\r
124 #define PHFRINFC_LLCP_SAP_DEFAULT 0xFF /**< Default number when a socket is created or reset */
\r
128 * \name Length value for DM opCode
\r
132 #define PHFRINFC_LLCP_DM_LENGTH 0x01 /**< Length value for DM opCode */
\r
138 * \name Masks used with parameters value.
\r
142 #define PHFRINFC_LLCP_TLV_MIUX_MASK 0x07FF /**< \internal Mask to apply to MIUX TLV Value.*/
\r
143 #define PHFRINFC_LLCP_TLV_WKS_MASK 0x0001 /**< \internal Minimal bits to be set in WKS TLV Value.*/
\r
144 #define PHFRINFC_LLCP_TLV_RW_MASK 0x0F /**< \internal Mask to apply to RW TLV Value.*/
\r
145 #define PHFRINFC_LLCP_TLV_OPT_MASK 0x03 /**< \internal Mask to apply to OPT TLV Value.*/
\r
150 * \name Type codes for parameters in TLV.
\r
154 #define PHFRINFC_LLCP_TLV_TYPE_VERSION 0x01 /**< \internal VERSION parameter Type code.*/
\r
155 #define PHFRINFC_LLCP_TLV_TYPE_MIUX 0x02 /**< \internal MIUX parameter Type code.*/
\r
156 #define PHFRINFC_LLCP_TLV_TYPE_WKS 0x03 /**< \internal WKS parameter Type code.*/
\r
157 #define PHFRINFC_LLCP_TLV_TYPE_LTO 0x04 /**< \internal LTO parameter Type code.*/
\r
158 #define PHFRINFC_LLCP_TLV_TYPE_RW 0x05 /**< \internal RW parameter Type code.*/
\r
159 #define PHFRINFC_LLCP_TLV_TYPE_SN 0x06 /**< \internal SN parameter Type code.*/
\r
160 #define PHFRINFC_LLCP_TLV_TYPE_OPT 0x07 /**< \internal OPT parameter Type code.*/
\r
165 * \name Fixed Value length for parameters in TLV.
\r
169 #define PHFRINFC_LLCP_TLV_LENGTH_HEADER 2 /**< \internal Fixed length of Type and Length fields in TLV.*/
\r
170 #define PHFRINFC_LLCP_TLV_LENGTH_VERSION 1 /**< \internal Fixed length of VERSION parameter Value.*/
\r
171 #define PHFRINFC_LLCP_TLV_LENGTH_MIUX 2 /**< \internal Fixed length of MIUX parameter Value.*/
\r
172 #define PHFRINFC_LLCP_TLV_LENGTH_WKS 2 /**< \internal Fixed length of WKS parameter Value.*/
\r
173 #define PHFRINFC_LLCP_TLV_LENGTH_LTO 1 /**< \internal Fixed length of LTO parameter Value.*/
\r
174 #define PHFRINFC_LLCP_TLV_LENGTH_RW 1 /**< \internal Fixed length of RW parameter Value.*/
\r
175 #define PHFRINFC_LLCP_TLV_LENGTH_OPT 1 /**< \internal Fixed length of OPT parameter Value.*/
\r
179 * \name LLCP packet field sizes.
\r
183 #define PHFRINFC_LLCP_PACKET_HEADER_SIZE 2 /**< Size of the general packet header (DSAP+PTYPE+SSAP).*/
\r
184 #define PHFRINFC_LLCP_PACKET_SEQUENCE_SIZE 1 /**< Size of the sequence field, if present.*/
\r
185 #define PHFRINFC_LLCP_PACKET_MAX_SIZE (PHFRINFC_LLCP_PACKET_HEADER_SIZE + \
\r
186 PHFRINFC_LLCP_PACKET_SEQUENCE_SIZE + \
\r
187 PHFRINFC_LLCP_MIU_DEFAULT + \
\r
188 PHFRINFC_LLCP_TLV_MIUX_MASK) /**< Maximum size of a packet */
\r
191 /*========== MACROS ===========*/
\r
193 #define CHECK_SEND_RW(socket) ( (((socket)->socket_VS - (socket)->socket_VSA) % 16) < (socket)->remoteRW )
\r
195 /*========== ENUMERATES ===========*/
\r
197 typedef phFriNfc_LlcpMac_ePeerType_t phFriNfc_Llcp_eRole_t;
\r
199 typedef phFriNfc_LlcpMac_eLinkStatus_t phFriNfc_Llcp_eLinkStatus_t;
\r
201 /*========== CALLBACKS ===========*/
\r
203 typedef void (*phFriNfc_Llcp_Check_CB_t) (
\r
208 typedef void (*phFriNfc_Llcp_LinkStatus_CB_t) (
\r
210 phFriNfc_Llcp_eLinkStatus_t eLinkStatus
\r
213 typedef void (*phFriNfc_Llcp_Send_CB_t) (
\r
218 typedef void (*phFriNfc_Llcp_Recv_CB_t) (
\r
220 phNfc_sData_t *psData,
\r
224 /*========== STRUCTURES ===========*/
\r
226 typedef struct phFriNfc_Llcp_sPacketHeader
\r
228 /**< The destination service access point*/
\r
231 /**< The packet type*/
\r
232 unsigned ptype : 4;
\r
234 /**< The source service access point*/
\r
237 } phFriNfc_Llcp_sPacketHeader_t;
\r
239 typedef struct phFriNfc_Llcp_sPacketSequence
\r
241 /**< Sequence number for sending*/
\r
244 /**< Sequence number for reception*/
\r
247 } phFriNfc_Llcp_sPacketSequence_t;
\r
249 typedef struct phFriNfc_Llcp_sSendOperation
\r
251 /**< Sequence number for sending*/
\r
252 phFriNfc_Llcp_sPacketHeader_t *psHeader;
\r
254 /**< Sequence number for sending*/
\r
255 phFriNfc_Llcp_sPacketSequence_t *psSequence;
\r
257 /**< Sequence number for sending*/
\r
258 phNfc_sData_t *psInfo;
\r
260 /**< Sequence number for sending*/
\r
261 phFriNfc_Llcp_Send_CB_t pfSend_CB;
\r
263 /**< Sequence number for sending*/
\r
266 } phFriNfc_Llcp_sSendOperation_t;
\r
268 typedef struct phFriNfc_Llcp_sRecvOperation
\r
270 /**< Sequence number for sending*/
\r
273 /**< Sequence number for sending*/
\r
274 phNfc_sData_t *psBuffer;
\r
276 /**< Sequence number for sending*/
\r
277 phFriNfc_Llcp_Recv_CB_t pfRecv_CB;
\r
279 /**< Sequence number for sending*/
\r
282 } phFriNfc_Llcp_sRecvOperation_t;
\r
284 typedef struct phFriNfc_Llcp
\r
286 /**< The current state*/
\r
289 /**< MAC mapping instance*/
\r
290 phFriNfc_LlcpMac_t MAC;
\r
292 /**< Local LLC role*/
\r
293 phFriNfc_LlcpMac_ePeerType_t eRole;
\r
295 /**< Local link parameters*/
\r
296 phFriNfc_Llcp_sLinkParameters_t sLocalParams;
\r
298 /**< Remote link parameters*/
\r
299 phFriNfc_Llcp_sLinkParameters_t sRemoteParams;
\r
301 /**< Negociated protocol version (major number on MSB, minor on LSB)*/
\r
304 /**< Internal reception buffer, its size may vary during time but not exceed nRxBufferSize*/
\r
305 phNfc_sData_t sRxBuffer;
\r
307 /**< Actual size of reception buffer*/
\r
308 uint16_t nRxBufferLength;
\r
310 /**< Internal emission buffer, its size may vary during time but not exceed nTxBufferSize*/
\r
311 phNfc_sData_t sTxBuffer;
\r
313 /**< Actual size of emission buffer*/
\r
314 uint16_t nTxBufferLength;
\r
316 /**< Callback function for link status notification*/
\r
317 phFriNfc_Llcp_LinkStatus_CB_t pfLink_CB;
\r
319 /**< Callback context for link status notification*/
\r
320 void *pLinkContext;
\r
322 /**< Callback function for compliance checking*/
\r
323 phFriNfc_Llcp_Check_CB_t pfChk_CB;
\r
325 /**< Callback context for compliance checking*/
\r
328 /**< Symmetry timer*/
\r
329 uint32_t hSymmTimer;
\r
331 /**< Control frames buffer*/
\r
332 uint8_t pCtrlTxBuffer[10];
\r
334 /**< Control frames buffer size*/
\r
335 uint8_t pCtrlTxBufferLength;
\r
337 /**< DISC packet send pending flag*/
\r
338 bool_t bDiscPendingFlag;
\r
340 /**< FRMR packet send pending flag*/
\r
341 bool_t bFrmrPendingFlag;
\r
343 /**< Header of pending FRMR packet*/
\r
344 phFriNfc_Llcp_sPacketHeader_t sFrmrHeader;
\r
346 /**< Info field of pending FRMR packet*/
\r
347 uint8_t pFrmrInfo[4];
\r
349 /**< Send callback*/
\r
350 phFriNfc_Llcp_Send_CB_t pfSendCB;
\r
352 /**< Send callback*/
\r
353 void *pSendContext;
\r
355 /**< Pending send header*/
\r
356 phFriNfc_Llcp_sPacketHeader_t *psSendHeader;
\r
358 /**< Pending send sequence*/
\r
359 phFriNfc_Llcp_sPacketSequence_t *psSendSequence;
\r
361 /**< Pending send info*/
\r
362 phNfc_sData_t *psSendInfo;
\r
364 /**< Receive callback*/
\r
365 phFriNfc_Llcp_Recv_CB_t pfRecvCB;
\r
367 /**< Receive callback*/
\r
368 void *pRecvContext;
\r
372 /*========== UNIONS ===========*/
\r
375 /*========== FUNCTIONS ===========*/
\r
380 NFCSTATUS phFriNfc_Llcp_EncodeLinkParams( phNfc_sData_t *psRawBuffer,
\r
381 phFriNfc_Llcp_sLinkParameters_t *psLinkParams,
\r
382 uint8_t nVersion );
\r
388 NFCSTATUS phFriNfc_Llcp_Reset( phFriNfc_Llcp_t *Llcp,
\r
390 phFriNfc_Llcp_sLinkParameters_t *psLinkParams,
\r
392 uint16_t nRxBufferLength,
\r
394 uint16_t nTxBufferLength,
\r
395 phFriNfc_Llcp_LinkStatus_CB_t pfLink_CB,
\r
401 NFCSTATUS phFriNfc_Llcp_ChkLlcp( phFriNfc_Llcp_t *Llcp,
\r
402 phHal_sRemoteDevInformation_t *psRemoteDevInfo,
\r
403 phFriNfc_Llcp_Check_CB_t pfCheck_CB,
\r
409 NFCSTATUS phFriNfc_Llcp_Activate( phFriNfc_Llcp_t *Llcp );
\r
414 NFCSTATUS phFriNfc_Llcp_Deactivate( phFriNfc_Llcp_t *Llcp );
\r
419 NFCSTATUS phFriNfc_Llcp_GetLocalInfo( phFriNfc_Llcp_t *Llcp,
\r
420 phFriNfc_Llcp_sLinkParameters_t *pParams );
\r
425 NFCSTATUS phFriNfc_Llcp_GetRemoteInfo( phFriNfc_Llcp_t *Llcp,
\r
426 phFriNfc_Llcp_sLinkParameters_t *pParams );
\r
431 NFCSTATUS phFriNfc_Llcp_Send( phFriNfc_Llcp_t *Llcp,
\r
432 phFriNfc_Llcp_sPacketHeader_t *psHeader,
\r
433 phFriNfc_Llcp_sPacketSequence_t *psSequence,
\r
434 phNfc_sData_t *psInfo,
\r
435 phFriNfc_Llcp_Send_CB_t pfSend_CB,
\r
441 NFCSTATUS phFriNfc_Llcp_Recv( phFriNfc_Llcp_t *Llcp,
\r
442 phFriNfc_Llcp_Recv_CB_t pfRecv_CB,
\r
446 #endif /* PHFRINFC_LLCP_H */
\r