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