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_LlcpMac.c
19 * \brief NFC LLCP MAC Mappings For Different RF Technologies.
20 *
21 * Project: NFC-FRI
22 *
23 */
24
25
26 /*include files*/
27 #include <phFriNfc_LlcpMac.h>
28 #include <phFriNfc_LlcpMacNfcip.h>
29 #include <phLibNfcStatus.h>
30 #include <phLibNfc.h>
31 #include <phLibNfc_Internal.h>
32
phFriNfc_LlcpMac_Reset(phFriNfc_LlcpMac_t * LlcpMac,void * LowerDevice,phFriNfc_LlcpMac_LinkStatus_CB_t LinkStatus_Cb,void * pContext)33 NFCSTATUS phFriNfc_LlcpMac_Reset (phFriNfc_LlcpMac_t *LlcpMac,
34 void *LowerDevice,
35 phFriNfc_LlcpMac_LinkStatus_CB_t LinkStatus_Cb,
36 void *pContext)
37 {
38 NFCSTATUS status = NFCSTATUS_SUCCESS;
39 /* Store the Linkstatus callback function of the upper layer */
40 LlcpMac->LinkStatus_Cb = LinkStatus_Cb;
41
42 /* Store a pointer to the upper layer context */
43 LlcpMac->LinkStatus_Context = pContext;
44
45 /* Set the LinkStatus variable to the default state */
46 LlcpMac->LinkState = phFriNfc_LlcpMac_eLinkDefault;
47
48 /* Store a pointer to the lower layer */
49 LlcpMac->LowerDevice = LowerDevice;
50
51 LlcpMac->psRemoteDevInfo = NULL;
52 LlcpMac->PeerRemoteDevType = 0;
53 LlcpMac->MacType = 0;
54 LlcpMac->MacReceive_Cb = NULL;
55 LlcpMac->MacSend_Cb = NULL;
56 LlcpMac->psSendBuffer = NULL;
57 LlcpMac->RecvPending = 0;
58 LlcpMac->SendPending = 0;
59
60 return status;
61 }
62
phFriNfc_LlcpMac_ChkLlcp(phFriNfc_LlcpMac_t * LlcpMac,phHal_sRemoteDevInformation_t * psRemoteDevInfo,phFriNfc_LlcpMac_Chk_CB_t ChkLlcpMac_Cb,void * pContext)63 NFCSTATUS phFriNfc_LlcpMac_ChkLlcp (phFriNfc_LlcpMac_t *LlcpMac,
64 phHal_sRemoteDevInformation_t *psRemoteDevInfo,
65 phFriNfc_LlcpMac_Chk_CB_t ChkLlcpMac_Cb,
66 void *pContext)
67 {
68 NFCSTATUS status = NFCSTATUS_SUCCESS;
69 if (NULL == LlcpMac || NULL == psRemoteDevInfo)
70 {
71 status = PHNFCSTVAL(CID_FRI_NFC_LLCP_MAC, NFCSTATUS_INVALID_PARAMETER);
72 }
73 else
74 {
75 /* Store the Remote Device info received from Device Discovery */
76 LlcpMac->psRemoteDevInfo = psRemoteDevInfo;
77
78 if(LlcpMac->psRemoteDevInfo->RemDevType == phHal_eNfcIP1_Initiator)
79 {
80 /* Set the PeerRemoteDevType variable to the Target type */
81 LlcpMac->PeerRemoteDevType = phFriNfc_LlcpMac_ePeerTypeTarget;
82 }
83 else if(LlcpMac->psRemoteDevInfo->RemDevType == phHal_eNfcIP1_Target)
84 {
85 /* Set the PeerRemoteDevType variable to the Initiator type */
86 LlcpMac->PeerRemoteDevType = phFriNfc_LlcpMac_ePeerTypeInitiator;
87 }
88
89 switch(LlcpMac->psRemoteDevInfo->RemDevType)
90 {
91 case phHal_eNfcIP1_Initiator:
92 case phHal_eNfcIP1_Target:
93 {
94 /* Set the MAC mapping type detected */
95 LlcpMac->MacType = phFriNfc_LlcpMac_eTypeNfcip;
96
97 /* Register the lower layer to the MAC mapping component */
98 status = phFriNfc_LlcpMac_Nfcip_Register (LlcpMac);
99 if(status == NFCSTATUS_SUCCESS)
100 {
101 status = LlcpMac->LlcpMacInterface.chk(LlcpMac,ChkLlcpMac_Cb,pContext);
102 }
103 else
104 {
105 status = PHNFCSTVAL(CID_FRI_NFC_LLCP_MAC, NFCSTATUS_FAILED);
106 }
107 }break;
108 default:
109 {
110 status = PHNFCSTVAL(CID_FRI_NFC_LLCP_MAC, NFCSTATUS_INVALID_DEVICE);
111 }break;
112 }
113 }
114
115 return status;
116 }
117
phFriNfc_LlcpMac_Activate(phFriNfc_LlcpMac_t * LlcpMac)118 NFCSTATUS phFriNfc_LlcpMac_Activate (phFriNfc_LlcpMac_t *LlcpMac)
119 {
120 NFCSTATUS status = NFCSTATUS_SUCCESS;
121
122 if(LlcpMac->LlcpMacInterface.activate == NULL)
123 {
124 status = PHNFCSTVAL(CID_FRI_NFC_LLCP_MAC, NFCSTATUS_INVALID_PARAMETER);
125 }
126 else
127 {
128 status = LlcpMac->LlcpMacInterface.activate(LlcpMac);
129 }
130 return status;
131 }
132
phFriNfc_LlcpMac_Deactivate(phFriNfc_LlcpMac_t * LlcpMac)133 NFCSTATUS phFriNfc_LlcpMac_Deactivate (phFriNfc_LlcpMac_t *LlcpMac)
134 {
135 NFCSTATUS status = NFCSTATUS_SUCCESS;
136 if(LlcpMac->LlcpMacInterface.deactivate == NULL)
137 {
138 status = PHNFCSTVAL(CID_FRI_NFC_LLCP_MAC, NFCSTATUS_INVALID_PARAMETER);
139 }
140 else
141 {
142 status = LlcpMac->LlcpMacInterface.deactivate(LlcpMac);
143 }
144 return status;
145 }
146
phFriNfc_LlcpMac_Send(phFriNfc_LlcpMac_t * LlcpMac,phNfc_sData_t * psData,phFriNfc_LlcpMac_Send_CB_t LlcpMacSend_Cb,void * pContext)147 NFCSTATUS phFriNfc_LlcpMac_Send (phFriNfc_LlcpMac_t *LlcpMac,
148 phNfc_sData_t *psData,
149 phFriNfc_LlcpMac_Send_CB_t LlcpMacSend_Cb,
150 void *pContext)
151 {
152 NFCSTATUS status = NFCSTATUS_SUCCESS;
153
154 if(NULL== LlcpMac->LlcpMacInterface.send || NULL==psData || NULL==LlcpMacSend_Cb || NULL==pContext)
155 {
156 status = PHNFCSTVAL(CID_FRI_NFC_LLCP_MAC, NFCSTATUS_INVALID_PARAMETER);
157 }
158 else
159 {
160 status = LlcpMac->LlcpMacInterface.send(LlcpMac,psData,LlcpMacSend_Cb,pContext);
161 }
162 return status;
163 }
164
phFriNfc_LlcpMac_Receive(phFriNfc_LlcpMac_t * LlcpMac,phNfc_sData_t * psData,phFriNfc_LlcpMac_Reveive_CB_t ReceiveLlcpMac_Cb,void * pContext)165 NFCSTATUS phFriNfc_LlcpMac_Receive (phFriNfc_LlcpMac_t *LlcpMac,
166 phNfc_sData_t *psData,
167 phFriNfc_LlcpMac_Reveive_CB_t ReceiveLlcpMac_Cb,
168 void *pContext)
169 {
170 NFCSTATUS status = NFCSTATUS_SUCCESS;
171
172 if(LlcpMac->LlcpMacInterface.receive == NULL || NULL==psData || NULL==ReceiveLlcpMac_Cb || NULL==pContext)
173 {
174 status = PHNFCSTVAL(CID_FRI_NFC_LLCP_MAC, NFCSTATUS_INVALID_PARAMETER);
175 }
176 else
177 {
178 status = LlcpMac->LlcpMacInterface.receive(LlcpMac,psData,ReceiveLlcpMac_Cb,pContext);
179 }
180 return status;
181
182 }
183
184
185