2 * Copyright (C) 2010 NXP Semiconductors
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * \file phFriNfc_LlcpMac.c
19 * \brief NFC LLCP MAC Mappings For Different RF Technologies.
27 #include <phFriNfc_LlcpMac.h>
28 #include <phFriNfc_LlcpMacNfcip.h>
29 #include <phLibNfcStatus.h>
31 #include <phLibNfc_Internal.h>
33 NFCSTATUS phFriNfc_LlcpMac_Reset (phFriNfc_LlcpMac_t *LlcpMac,
35 phFriNfc_LlcpMac_LinkStatus_CB_t LinkStatus_Cb,
38 NFCSTATUS status = NFCSTATUS_SUCCESS;
39 /* Store the Linkstatus callback function of the upper layer */
40 LlcpMac->LinkStatus_Cb = LinkStatus_Cb;
42 /* Store a pointer to the upper layer context */
43 LlcpMac->LinkStatus_Context = pContext;
45 /* Set the LinkStatus variable to the default state */
46 LlcpMac->LinkState = phFriNfc_LlcpMac_eLinkDefault;
48 /* Store a pointer to the lower layer */
49 LlcpMac->LowerDevice = LowerDevice;
51 LlcpMac->psRemoteDevInfo = NULL;
52 LlcpMac->PeerRemoteDevType = 0;
54 LlcpMac->MacReceive_Cb = NULL;
55 LlcpMac->MacSend_Cb = NULL;
56 LlcpMac->psSendBuffer = NULL;
57 LlcpMac->RecvPending = 0;
58 LlcpMac->SendPending = 0;
63 NFCSTATUS phFriNfc_LlcpMac_ChkLlcp (phFriNfc_LlcpMac_t *LlcpMac,
64 phHal_sRemoteDevInformation_t *psRemoteDevInfo,
65 phFriNfc_LlcpMac_Chk_CB_t ChkLlcpMac_Cb,
68 NFCSTATUS status = NFCSTATUS_SUCCESS;
69 if (NULL == LlcpMac || NULL == psRemoteDevInfo)
71 status = PHNFCSTVAL(CID_FRI_NFC_LLCP_MAC, NFCSTATUS_INVALID_PARAMETER);
75 /* Store the Remote Device info received from Device Discovery */
76 LlcpMac->psRemoteDevInfo = psRemoteDevInfo;
78 if(LlcpMac->psRemoteDevInfo->RemDevType == phHal_eNfcIP1_Initiator)
80 /* Set the PeerRemoteDevType variable to the Target type */
81 LlcpMac->PeerRemoteDevType = phFriNfc_LlcpMac_ePeerTypeTarget;
83 else if(LlcpMac->psRemoteDevInfo->RemDevType == phHal_eNfcIP1_Target)
85 /* Set the PeerRemoteDevType variable to the Initiator type */
86 LlcpMac->PeerRemoteDevType = phFriNfc_LlcpMac_ePeerTypeInitiator;
89 switch(LlcpMac->psRemoteDevInfo->RemDevType)
91 case phHal_eNfcIP1_Initiator:
92 case phHal_eNfcIP1_Target:
94 /* Set the MAC mapping type detected */
95 LlcpMac->MacType = phFriNfc_LlcpMac_eTypeNfcip;
97 /* Register the lower layer to the MAC mapping component */
98 status = phFriNfc_LlcpMac_Nfcip_Register (LlcpMac);
99 if(status == NFCSTATUS_SUCCESS)
101 status = LlcpMac->LlcpMacInterface.chk(LlcpMac,ChkLlcpMac_Cb,pContext);
105 status = PHNFCSTVAL(CID_FRI_NFC_LLCP_MAC, NFCSTATUS_FAILED);
110 status = PHNFCSTVAL(CID_FRI_NFC_LLCP_MAC, NFCSTATUS_INVALID_DEVICE);
118 NFCSTATUS phFriNfc_LlcpMac_Activate (phFriNfc_LlcpMac_t *LlcpMac)
120 NFCSTATUS status = NFCSTATUS_SUCCESS;
122 if(LlcpMac->LlcpMacInterface.activate == NULL)
124 status = PHNFCSTVAL(CID_FRI_NFC_LLCP_MAC, NFCSTATUS_INVALID_PARAMETER);
128 status = LlcpMac->LlcpMacInterface.activate(LlcpMac);
133 NFCSTATUS phFriNfc_LlcpMac_Deactivate (phFriNfc_LlcpMac_t *LlcpMac)
135 NFCSTATUS status = NFCSTATUS_SUCCESS;
136 if(LlcpMac->LlcpMacInterface.deactivate == NULL)
138 status = PHNFCSTVAL(CID_FRI_NFC_LLCP_MAC, NFCSTATUS_INVALID_PARAMETER);
142 status = LlcpMac->LlcpMacInterface.deactivate(LlcpMac);
147 NFCSTATUS phFriNfc_LlcpMac_Send (phFriNfc_LlcpMac_t *LlcpMac,
148 phNfc_sData_t *psData,
149 phFriNfc_LlcpMac_Send_CB_t LlcpMacSend_Cb,
152 NFCSTATUS status = NFCSTATUS_SUCCESS;
154 if(NULL== LlcpMac->LlcpMacInterface.send || NULL==psData || NULL==LlcpMacSend_Cb || NULL==pContext)
156 status = PHNFCSTVAL(CID_FRI_NFC_LLCP_MAC, NFCSTATUS_INVALID_PARAMETER);
160 status = LlcpMac->LlcpMacInterface.send(LlcpMac,psData,LlcpMacSend_Cb,pContext);
165 NFCSTATUS phFriNfc_LlcpMac_Receive (phFriNfc_LlcpMac_t *LlcpMac,
166 phNfc_sData_t *psData,
167 phFriNfc_LlcpMac_Reveive_CB_t ReceiveLlcpMac_Cb,
170 NFCSTATUS status = NFCSTATUS_SUCCESS;
172 if(LlcpMac->LlcpMacInterface.receive == NULL || NULL==psData || NULL==ReceiveLlcpMac_Cb || NULL==pContext)
174 status = PHNFCSTVAL(CID_FRI_NFC_LLCP_MAC, NFCSTATUS_INVALID_PARAMETER);
178 status = LlcpMac->LlcpMacInterface.receive(LlcpMac,psData,ReceiveLlcpMac_Cb,pContext);