Lines Matching refs:Llcp
19 * \brief NFC LLCP core
39 #define PHFRINFC_LLCP_STATE_CHECKED 1 /**< \internal The tag has been checked for LLCP compliance.*/
87 static NFCSTATUS phFriNfc_Llcp_HandleIncomingPacket( phFriNfc_Llcp_t *Llcp,
89 static void phFriNfc_Llcp_ResetLTO( phFriNfc_Llcp_t *Llcp );
90 static NFCSTATUS phFriNfc_Llcp_InternalSend( phFriNfc_Llcp_t *Llcp,
94 static bool_t phFriNfc_Llcp_HandlePendingSend ( phFriNfc_Llcp_t *Llcp );
150 static NFCSTATUS phFriNfc_Llcp_InternalDeactivate( phFriNfc_Llcp_t *Llcp )
154 if ((Llcp->state == PHFRINFC_LLCP_STATE_OPERATION_RECV) ||
155 (Llcp->state == PHFRINFC_LLCP_STATE_OPERATION_SEND) ||
156 (Llcp->state == PHFRINFC_LLCP_STATE_PAX) ||
157 (Llcp->state == PHFRINFC_LLCP_STATE_ACTIVATION))
160 Llcp->state = PHFRINFC_LLCP_STATE_DEACTIVATION;
163 phOsalNfc_Timer_Stop(Llcp->hSymmTimer);
165 Llcp->psSendHeader = NULL;
166 Llcp->psSendSequence = NULL;
168 if (Llcp->psSendInfo != NULL)
170 phFriNfc_Llcp_Deallocate(Llcp->psSendInfo);
171 Llcp->psSendInfo = NULL;
173 if (Llcp->pfSendCB != NULL)
176 pfSendCB = Llcp->pfSendCB;
177 pSendContext = Llcp->pSendContext;
179 Llcp->pfSendCB = NULL;
180 Llcp->pSendContext = NULL;
186 Llcp->pfLink_CB(Llcp->pLinkContext, phFriNfc_LlcpMac_eLinkDeactivated);
189 return phFriNfc_LlcpMac_Deactivate(&Llcp->MAC);
196 static NFCSTATUS phFriNfc_Llcp_SendSymm( phFriNfc_Llcp_t *Llcp )
203 return phFriNfc_Llcp_InternalSend(Llcp, &sHeader, NULL, NULL);
207 static NFCSTATUS phFriNfc_Llcp_SendPax( phFriNfc_Llcp_t *Llcp, phFriNfc_Llcp_sLinkParameters_t *psLinkParams)
225 if (Llcp->state != PHFRINFC_LLCP_STATE_OPERATION_SEND)
231 return phFriNfc_Llcp_InternalSend(Llcp, &sHeader, NULL, &sParamsTLV);
242 static NFCSTATUS phFriNfc_Llcp_SendDisconnect( phFriNfc_Llcp_t *Llcp )
247 if (Llcp->state != PHFRINFC_LLCP_STATE_OPERATION_SEND)
253 return phFriNfc_Llcp_InternalSend(Llcp, &sHeader, NULL, NULL);
258 Llcp->bDiscPendingFlag = TRUE;
266 phFriNfc_Llcp_t *Llcp = (phFriNfc_Llcp_t*)pContext;
271 if (Llcp->state == PHFRINFC_LLCP_STATE_OPERATION_RECV)
274 phFriNfc_Llcp_InternalDeactivate(Llcp);
276 else if (Llcp->state == PHFRINFC_LLCP_STATE_OPERATION_SEND)
279 phFriNfc_Llcp_SendSymm(Llcp);
288 static NFCSTATUS phFriNfc_Llcp_HandleAggregatedPacket( phFriNfc_Llcp_t *Llcp,
344 status = phFriNfc_Llcp_HandleIncomingPacket(Llcp, &sCurrentInfo);
520 static NFCSTATUS phFriNfc_Llcp_InternalActivate( phFriNfc_Llcp_t *Llcp,
549 Llcp->version = negociatedVersion;
550 memcpy(&Llcp->sRemoteParams, &sRemoteParams, sizeof(phFriNfc_Llcp_sLinkParameters_t));
553 if (Llcp->nTxBufferLength < (Llcp->sRemoteParams.miu + nMaxHeaderSize))
555 Llcp->sRemoteParams.miu = Llcp->nTxBufferLength - nMaxHeaderSize;
560 phFriNfc_Llcp_ResetLTO(Llcp);
567 Llcp->pfLink_CB(Llcp->pLinkContext, phFriNfc_LlcpMac_eLinkActivated);
574 static NFCSTATUS phFriNfc_Llcp_HandleMACLinkActivated( phFriNfc_Llcp_t *Llcp,
580 Llcp->hSymmTimer = phOsalNfc_Timer_Create();
581 if (Llcp->hSymmTimer == PH_OSALNFC_INVALID_TIMER_ID)
591 Llcp->state = PHFRINFC_LLCP_STATE_PAX;
593 Llcp->sRemoteParams.miu = PHFRINFC_LLCP_MIU_DEFAULT;
595 if (Llcp->eRole == phFriNfc_LlcpMac_ePeerTypeInitiator)
598 status = phFriNfc_Llcp_SendPax(Llcp, &Llcp->sLocalParams);
604 status = phFriNfc_Llcp_InternalActivate(Llcp, psParamsTLV);
610 Llcp->sRxBuffer.length = Llcp->nRxBufferLength;
611 phFriNfc_LlcpMac_Receive(&Llcp->MAC, &Llcp->sRxBuffer, phFriNfc_Llcp_Receive_CB, Llcp);
618 static void phFriNfc_Llcp_HandleMACLinkDeactivated( phFriNfc_Llcp_t *Llcp )
620 uint8_t state = Llcp->state;
623 if (Llcp->hSymmTimer != PH_OSALNFC_INVALID_TIMER_ID)
625 phOsalNfc_Timer_Delete(Llcp->hSymmTimer);
629 Llcp->state = PHFRINFC_LLCP_STATE_RESET_INIT;
641 Llcp->pfLink_CB(Llcp->pLinkContext, phFriNfc_LlcpMac_eLinkDeactivated);
652 phFriNfc_Llcp_t *Llcp = (phFriNfc_Llcp_t*)pContext;
655 Llcp->state = PHFRINFC_LLCP_STATE_CHECKED;
658 Llcp->pfChk_CB(Llcp->pChkContext, status);
669 phFriNfc_Llcp_t *Llcp = (phFriNfc_Llcp_t*)pContext;
672 Llcp->eRole = PeerRemoteDevType;
680 status = phFriNfc_Llcp_HandleMACLinkActivated(Llcp, psParamsTLV);
684 status = phFriNfc_Llcp_InternalDeactivate(Llcp);
691 phFriNfc_Llcp_HandleMACLinkDeactivated(Llcp);
702 static void phFriNfc_Llcp_ResetLTO( phFriNfc_Llcp_t *Llcp )
708 phOsalNfc_Timer_Stop(Llcp->hSymmTimer);
712 if (Llcp->state == PHFRINFC_LLCP_STATE_OPERATION_RECV)
714 Llcp->state = PHFRINFC_LLCP_STATE_OPERATION_SEND;
716 else if (Llcp->state == PHFRINFC_LLCP_STATE_OPERATION_SEND)
718 Llcp->state = PHFRINFC_LLCP_STATE_OPERATION_RECV;
720 else if (Llcp->state != PHFRINFC_LLCP_STATE_DEACTIVATION &&
721 Llcp->state != PHFRINFC_LLCP_STATE_RESET_INIT)
725 if (Llcp->eRole == phFriNfc_LlcpMac_ePeerTypeInitiator)
727 Llcp->state = PHFRINFC_LLCP_STATE_OPERATION_SEND;
731 Llcp->state = PHFRINFC_LLCP_STATE_OPERATION_RECV;
737 if (Llcp->state == PHFRINFC_LLCP_STATE_OPERATION_RECV)
740 nDuration = Llcp->sRemoteParams.lto * 10;
758 nDuration = (Llcp->sLocalParams.lto * 10) / 2;
762 LLCP_DEBUG("Starting LLCP timer with duration %d", nDuration);
766 Llcp->hSymmTimer,
769 Llcp);
773 static NFCSTATUS phFriNfc_Llcp_HandleLinkPacket( phFriNfc_Llcp_t *Llcp,
795 result = phFriNfc_Llcp_HandleAggregatedPacket(Llcp, psPacket);
806 result = phFriNfc_Llcp_InternalDeactivate(Llcp);
836 static NFCSTATUS phFriNfc_Llcp_HandleTransportPacket( phFriNfc_Llcp_t *Llcp,
845 if (Llcp->pfRecvCB != NULL)
848 pfRecvCB = Llcp->pfRecvCB;
849 pContext = Llcp->pRecvContext;
851 Llcp->pfRecvCB = NULL;
852 Llcp->pRecvContext = NULL;
861 static bool_t phFriNfc_Llcp_HandlePendingSend ( phFriNfc_Llcp_t *Llcp )
872 if (Llcp->bDiscPendingFlag == TRUE)
881 Llcp->bDiscPendingFlag = FALSE;
884 else if (Llcp->bFrmrPendingFlag == TRUE)
887 sInfoBuffer.buffer = Llcp->pFrmrInfo;
888 sInfoBuffer.length = sizeof(Llcp->pFrmrInfo);
890 psSendHeader = &Llcp->sFrmrHeader;
893 Llcp->bFrmrPendingFlag = FALSE;
896 else if (Llcp->pfSendCB != NULL)
899 psSendHeader = Llcp->psSendHeader;
900 psSendSequence = Llcp->psSendSequence;
901 psSendInfo = Llcp->psSendInfo;
903 Llcp->psSendHeader = NULL;
904 Llcp->psSendSequence = NULL;
905 Llcp->psSendInfo = NULL;
912 result = phFriNfc_Llcp_InternalSend(Llcp, psSendHeader, psSendSequence, psSendInfo);
916 phFriNfc_Llcp_InternalDeactivate(Llcp);
919 } else if (Llcp->pfSendCB == NULL) {
922 phFriNfc_Llcp_SendSymm(Llcp);
935 static NFCSTATUS phFriNfc_Llcp_HandleIncomingPacket( phFriNfc_Llcp_t *Llcp,
948 status = phFriNfc_Llcp_HandleLinkPacket(Llcp, psPacket);
958 status = phFriNfc_Llcp_HandleTransportPacket(Llcp, psPacket);
969 phFriNfc_Llcp_t *Llcp = (phFriNfc_Llcp_t*)pContext;
974 if ((status != NFCSTATUS_SUCCESS) || (Llcp->bDiscPendingFlag == TRUE))
976 LLCP_DEBUG("\nReceived LLCP packet error - status = 0x%04x", status);
978 Llcp->bDiscPendingFlag = FALSE;
980 phFriNfc_Llcp_InternalDeactivate(Llcp);
989 LLCP_PRINT_BUFFER("\nReceived LLCP packet :", psData->buffer, psData->length);
998 switch(Llcp->state)
1007 result = phFriNfc_Llcp_InternalActivate(Llcp, psData+PHFRINFC_LLCP_PACKET_HEADER_SIZE);
1009 if (Llcp->eRole == phFriNfc_LlcpMac_ePeerTypeTarget)
1012 result = phFriNfc_Llcp_SendPax(Llcp, &Llcp->sLocalParams);
1027 phFriNfc_Llcp_ResetLTO(Llcp);
1029 result = phFriNfc_Llcp_HandleIncomingPacket(Llcp, psData);
1036 phFriNfc_Llcp_HandlePendingSend(Llcp);
1047 Llcp->sRxBuffer.length = Llcp->nRxBufferLength;
1048 phFriNfc_LlcpMac_Receive(&Llcp->MAC, &Llcp->sRxBuffer, phFriNfc_Llcp_Receive_CB, Llcp
1056 phFriNfc_Llcp_t *Llcp = (phFriNfc_Llcp_t*)pContext;
1061 /* NOTE: if Llcp->psSendHeader is not NULL, this means that the send operation is still not initiated */
1062 if (Llcp->psSendHeader == NULL)
1064 if (Llcp->pfSendCB != NULL)
1067 pfSendCB = Llcp->pfSendCB;
1068 pSendContext = Llcp->pSendContext;
1070 Llcp->pfSendCB = NULL;
1071 Llcp->pSendContext = NULL;
1081 phFriNfc_Llcp_InternalDeactivate(Llcp);
1086 static NFCSTATUS phFriNfc_Llcp_InternalSend( phFriNfc_Llcp_t *Llcp,
1092 phNfc_sData_t *psRawPacket = &Llcp->sTxBuffer; /* Use internal Tx buffer */
1095 phFriNfc_Llcp_ResetLTO(Llcp);
1112 LLCP_PRINT_BUFFER("\nSending LLCP packet :", psRawPacket->buffer, psRawPacket->length);
1121 &Llcp->MAC,
1124 Llcp );
1231 NFCSTATUS phFriNfc_Llcp_Reset( phFriNfc_Llcp_t *Llcp,
1246 if ((Llcp == NULL) || (LowerDevice == NULL) || (pfLink_CB == NULL) ||
1272 memset(Llcp, 0x00, sizeof(phFriNfc_Llcp_t));
1275 result = phFriNfc_LlcpMac_Reset(&Llcp->MAC, LowerDevice, phFriNfc_Llcp_LinkStatus_CB, Llcp);
1281 Llcp->sRxBuffer.buffer = pRxBuffer;
1282 Llcp->sRxBuffer.length = nRxBufferLength;
1283 Llcp->nRxBufferLength = nRxBufferLength;
1284 Llcp->sTxBuffer.buffer = pTxBuffer;
1285 Llcp->sTxBuffer.length = nTxBufferLength;
1286 Llcp->nTxBufferLength = nTxBufferLength;
1289 Llcp->pfLink_CB = pfLink_CB;
1290 Llcp->pLinkContext = pContext;
1293 memcpy(&Llcp->sLocalParams, psLinkParams, sizeof(phFriNfc_Llcp_sLinkParameters_t));
1299 NFCSTATUS phFriNfc_Llcp_ChkLlcp( phFriNfc_Llcp_t *Llcp,
1305 if ( (Llcp == NULL) || (psRemoteDevInfo == NULL) || (pfCheck_CB == NULL) )
1311 if( Llcp->state != PHFRINFC_LLCP_STATE_RESET_INIT ) {
1316 Llcp->pfChk_CB = pfCheck_CB;
1317 Llcp->pChkContext = pContext;
1320 return phFriNfc_LlcpMac_ChkLlcp(&Llcp->MAC, psRemoteDevInfo, phFriNfc_Llcp_ChkLlcp_CB, (void*)Llcp);
1324 NFCSTATUS phFriNfc_Llcp_Activate( phFriNfc_Llcp_t *Llcp )
1327 if (Llcp == NULL)
1333 if( Llcp->state != PHFRINFC_LLCP_STATE_CHECKED ) {
1338 Llcp->state = PHFRINFC_LLCP_STATE_ACTIVATION;
1341 Llcp->psSendHeader = NULL;
1342 Llcp->psSendSequence = NULL;
1345 return phFriNfc_LlcpMac_Activate(&Llcp->MAC);
1349 NFCSTATUS phFriNfc_Llcp_Deactivate( phFriNfc_Llcp_t *Llcp )
1354 if (Llcp == NULL)
1360 if( (Llcp->state != PHFRINFC_LLCP_STATE_OPERATION_RECV) &&
1361 (Llcp->state != PHFRINFC_LLCP_STATE_OPERATION_SEND) ) {
1366 status = phFriNfc_Llcp_SendDisconnect(Llcp);
1374 return phFriNfc_Llcp_InternalDeactivate(Llcp);
1378 NFCSTATUS phFriNfc_Llcp_GetLocalInfo( phFriNfc_Llcp_t *Llcp,
1382 if ((Llcp == NULL) || (pParams == NULL))
1388 memcpy(pParams, &Llcp->sLocalParams, sizeof(phFriNfc_Llcp_sLinkParameters_t));
1394 NFCSTATUS phFriNfc_Llcp_GetRemoteInfo( phFriNfc_Llcp_t *Llcp,
1398 if ((Llcp == NULL) || (pParams == NULL))
1404 memcpy(pParams, &Llcp->sRemoteParams, sizeof(phFriNfc_Llcp_sLinkParameters_t));
1410 NFCSTATUS phFriNfc_Llcp_Send( phFriNfc_Llcp_t *Llcp,
1419 if ((Llcp == NULL) || (psHeader == NULL) || (pfSend_CB == NULL))
1425 if (Llcp->pfSendCB != NULL)
1432 Llcp->pfSendCB = pfSend_CB;
1433 Llcp->pSendContext = pContext;
1435 if (Llcp->state == PHFRINFC_LLCP_STATE_OPERATION_SEND)
1438 result = phFriNfc_Llcp_InternalSend(Llcp, psHeader, psSequence, psInfo);
1440 else if (Llcp->state == PHFRINFC_LLCP_STATE_OPERATION_RECV)
1443 Llcp->psSendHeader = psHeader;
1444 Llcp->psSendSequence = psSequence;
1445 Llcp->psSendInfo = phFriNfc_Llcp_AllocateAndCopy(psInfo);
1455 Llcp->pfSendCB = NULL;
1461 NFCSTATUS phFriNfc_Llcp_Recv( phFriNfc_Llcp_t *Llcp,
1468 if ((Llcp == NULL) || (pfRecv_CB == NULL))
1474 if (Llcp->pfRecvCB != NULL)
1481 Llcp->pfRecvCB = pfRecv_CB;
1482 Llcp->pRecvContext = pContext;