phHciNfc_DevMgmt.c revision 6dd948323de0f31b413c9f19a905f1c145c9c456
10ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong/*
20ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong * Copyright (C) 2010 NXP Semiconductors
30ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong *
40ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong * Licensed under the Apache License, Version 2.0 (the "License");
50ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong * you may not use this file except in compliance with the License.
60ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong * You may obtain a copy of the License at
70ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong *
80ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong *      http://www.apache.org/licenses/LICENSE-2.0
90ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong *
100ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong * Unless required by applicable law or agreed to in writing, software
110ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong * distributed under the License is distributed on an "AS IS" BASIS,
120ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
130ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong * See the License for the specific language governing permissions and
140ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong * limitations under the License.
150ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong */
160ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong
170ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong
180ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong/*!
190ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong* =========================================================================== *
200ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong*                                                                             *
210ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong*                                                                             *
220ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong* \file  phHciNfc_DevMgmt.c                                                   *
230ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong* \brief HCI PN544 Device Management Gate Routines.                           *
240ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong*                                                                             *
250ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong*                                                                             *
260ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong* Project: NFC-FRI-1.1                                                        *
270ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong*                                                                             *
280ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong* $Date: Fri Mar 12 10:21:54 2010 $                                           *
290ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong* $Author: ing04880 $                                                         *
300ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong* $Revision: 1.29 $                                                            *
310ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong* $Aliases: NFC_FRI1.1_WK1007_R33_3,NFC_FRI1.1_WK1007_R33_4,NFC_FRI1.1_WK1017_PREP1,NFC_FRI1.1_WK1017_R34_1,NFC_FRI1.1_WK1017_R34_2,NFC_FRI1.1_WK1023_R35_1 $                                                                *
320ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong*                                                                             *
330ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong* =========================================================================== *
340ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong*/
350ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong
360ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong/*
370ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong***************************** Header File Inclusion ****************************
380ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong*/
390ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#include <phNfcConfig.h>
400ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#include <phNfcCompId.h>
410ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#include <phHciNfc_Pipe.h>
420ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#include <phHciNfc_DevMgmt.h>
430ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#include <phHciNfc_Emulation.h>
440ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#include <phOsalNfc.h>
450ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong
460ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong/*
470ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong****************************** Macro Definitions *******************************
480ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong*/
490ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong
500ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong/*  Commands for System Management module */
510ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#define NXP_RF_CHECK_SETTINGS   0x10U
520ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#define NXP_RF_UPDATE_SETTINGS  0x11U
530ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong
540ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong/* Self Test Commands */
550ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#define NXP_SELF_TEST_ANTENNA   0x20U
560ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#define NXP_SELF_TEST_SWP       0x21U
570ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#define NXP_SELF_TEST_NFCWI     0x22U
580ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#define NXP_SELF_TEST_PRBS      0x25U
590ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong
600ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong/* System Management propreitary control */
610ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#define NXP_DBG_READ            0x3EU
620ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#define NXP_DBG_WRITE           0x3FU
630ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong
640ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong/* System Management Events */
650ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#define NXP_EVT_SET_AUTONOMOUS   0x01U
660ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#define NXP_EVT_CLF_WAKEUP       0x02U
670ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong
680ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong/* System Management Information Events */
690ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#define NXP_EVT_INFO_TXLDO_OVERCUR   0x10U
700ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#define NXP_EVT_INFO_PMUVCC          0x11U
710ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#define NXP_EVT_INFO_EXT_RF_FIELD    0x12U
720ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#define NXP_EVT_INFO_MEM_VIOLATION   0x13U
730ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#define NXP_EVT_INFO_TEMP_OVERHEAT   0x14U
740ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#define NXP_EVT_INFO_LLC_ERROR       0x15U
750ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong
760ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#define NFC_DEV_TXLDO_MASK           0x03U
770ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong
780ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong
790ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong/*
800ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong*************************** Structure and Enumeration ***************************
810ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong*/
820ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong
830ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong
840ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong/** \defgroup grp_hci_nfc HCI PN544 Device Management Component
850ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong *
860ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong *
870ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong */
880ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong
890ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kongtypedef enum phHciNfc_DevMgmt_Seq{
900ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong    DEV_MGMT_PIPE_OPEN      = 0x00U,
910ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong    DEV_MGMT_SET_PWR_STATUS,
920ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong    DEV_MGMT_SET_INFO_EVT,
930ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong    DEV_MGMT_GET_EEPROM_INFO,
940ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong    DEV_MGMT_GPIO_PDIR,
950ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong    DEV_MGMT_GPIO_PEN,
960ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong    DEV_MGMT_TX_LDO,
970ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong    DEV_MGMT_IFC_TO_RX_H,
980ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong    DEV_MGMT_IFC_TO_RX_L,
990ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong    DEV_MGMT_IFC_TO_TX_H,
1000ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong    DEV_MGMT_IFC_TO_TX_L,
1010ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong    DEV_MGMT_ANAIRQ_CONF,
1020ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong    DEV_MGMT_PMOS_MOD,
1030ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong    DEV_MGMT_CLK_REQ,
1040ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong    DEV_MGMT_INPUT_CLK,
1050ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong    DEV_MGMT_UICC_PWR_REQUEST,
1060ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong    DEV_MGMT_ACTIVE_GUARD_TO,
1070ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong    DEV_MGMT_MAX_ACT_TO_LOW,
1080ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong    DEV_MGMT_MAX_ACT_TO_HIGH,
1090ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong    DEV_MGMT_UICC_CE_A_ACCESS,
1100ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong    DEV_MGMT_UICC_CE_B_ACCESS,
1110ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong    DEV_MGMT_UICC_CE_BP_ACCESS,
1120ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong    DEV_MGMT_UICC_CE_F_ACCESS,
1130ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong    DEV_MGMT_UICC_RD_A_ACCESS,
1140ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong    DEV_MGMT_UICC_RD_B_ACCESS,
1150ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong    DEV_MGMT_UICC_BIT_RATE,
1160ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong    DEV_MGMT_UICC_RX_ERR_CNT,
1170ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong    DEV_MGMT_UICC_TX_ERR_CNT,
1180ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong    DEV_MGMT_LLC_GRD_TO_H,
1190ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong    DEV_MGMT_LLC_GRD_TO_L,
1200ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong    DEV_MGMT_LLC_ACK_TO_H,
1210ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong    DEV_MGMT_LLC_ACK_TO_L,
1220ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong    DEV_MGMT_FELICA_RC,
1230ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong    DEV_MGMT_EVT_AUTONOMOUS,
1240ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong    DEV_MGMT_PIPE_CLOSE
1250ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong} phHciNfc_DevMgmt_Seq_t;
1260ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong
1270ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong
1280ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kongtypedef struct phHciNfc_DevMgmt_Info{
1290ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong    phHciNfc_DevMgmt_Seq_t  current_seq;
1300ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong    phHciNfc_DevMgmt_Seq_t  next_seq;
131    phHciNfc_Pipe_Info_t    *p_pipe_info;
132    uint8_t                 test_status;
133    uint8_t                 value;
134    uint8_t                 rf_status;
135    uint8_t                 pmuvcc_status;
136    uint8_t                 overheat_status;
137    uint8_t                 *p_val;
138    uint8_t                 eeprom_crc;
139    phNfc_sData_t           test_result;
140
141} phHciNfc_DevMgmt_Info_t;
142
143
144/*
145*************************** Static Function Declaration **************************
146*/
147
148static
149NFCSTATUS
150phHciNfc_DevMgmt_InfoUpdate(
151                                phHciNfc_sContext_t     *psHciContext,
152                                phHal_sHwReference_t    *pHwRef,
153                                uint8_t                 index,
154                                uint8_t                 *reg_value,
155                                uint8_t                 reg_length
156                         );
157
158static
159NFCSTATUS
160phHciNfc_Recv_DevMgmt_Response(
161                        void                *psHciContext,
162                        void                *pHwRef,
163                        uint8_t             *pResponse,
164#ifdef ONE_BYTE_LEN
165                        uint8_t             length
166#else
167                        uint16_t            length
168#endif
169                       );
170
171static
172NFCSTATUS
173phHciNfc_Recv_DevMgmt_Event(
174                        void                *psContext,
175                        void                *pHwRef,
176                        uint8_t             *pEvent,
177#ifdef ONE_BYTE_LEN
178                        uint8_t             length
179#else
180                        uint16_t            length
181#endif
182                    );
183
184
185static
186NFCSTATUS
187phHciNfc_Send_DevMgmt_Command (
188                            phHciNfc_sContext_t *psHciContext,
189                            void                *pHwRef,
190                            uint8_t             pipe_id,
191                            uint8_t             cmd
192                );
193
194static
195 NFCSTATUS
196 phHciNfc_Send_DevMgmt_Event (
197                                phHciNfc_sContext_t *psHciContext,
198                                void                *pHwRef,
199                                uint8_t             pipe_id,
200                                uint8_t             event
201                    );
202
203/*
204*************************** Function Definitions ***************************
205*/
206
207
208NFCSTATUS
209phHciNfc_DevMgmt_Init_Resources(
210                           phHciNfc_sContext_t  *psHciContext
211                          )
212{
213    NFCSTATUS                   status = NFCSTATUS_SUCCESS;
214    phHciNfc_DevMgmt_Info_t          *p_device_mgmt_info=NULL;
215
216    if( NULL == psHciContext )
217    {
218        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
219    }
220    else
221    {
222        if(( NULL == psHciContext->p_device_mgmt_info ) &&
223             (phHciNfc_Allocate_Resource((void **)(&p_device_mgmt_info),
224            sizeof(phHciNfc_DevMgmt_Info_t))== NFCSTATUS_SUCCESS))
225        {
226            psHciContext->p_device_mgmt_info = p_device_mgmt_info;
227            p_device_mgmt_info->current_seq = DEV_MGMT_PIPE_OPEN;
228            p_device_mgmt_info->next_seq = DEV_MGMT_PIPE_OPEN;
229            p_device_mgmt_info->p_pipe_info = NULL;
230        }
231        else
232        {
233            status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INSUFFICIENT_RESOURCES);
234        }
235    }
236    return status;
237}
238
239
240NFCSTATUS
241phHciNfc_DevMgmt_Get_PipeID(
242                            phHciNfc_sContext_t        *psHciContext,
243                            uint8_t                    *ppipe_id
244                            )
245{
246    NFCSTATUS                   status = NFCSTATUS_SUCCESS;
247
248    if( (NULL != psHciContext)
249        && ( NULL != ppipe_id )
250        && ( NULL != psHciContext->p_device_mgmt_info )
251        )
252    {
253        phHciNfc_Pipe_Info_t     *p_pipe_info = NULL;
254        p_pipe_info = ((phHciNfc_DevMgmt_Info_t *)
255            psHciContext->p_device_mgmt_info)->p_pipe_info ;
256        if (NULL != p_pipe_info)
257        {
258            *ppipe_id = p_pipe_info->pipe.pipe_id ;
259        }
260        else
261        {
262            *ppipe_id = (uint8_t)HCI_UNKNOWN_PIPE_ID;
263        }
264
265    }
266    else
267    {
268        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION);
269    }
270    return status;
271}
272
273
274NFCSTATUS
275phHciNfc_DevMgmt_Get_Test_Result(
276                                phHciNfc_sContext_t        *psHciContext,
277                                phNfc_sData_t              *p_test_result
278                            )
279{
280    NFCSTATUS                   status = NFCSTATUS_SUCCESS;
281
282    if( (NULL != psHciContext)
283        && ( NULL != p_test_result )
284        && ( NULL != psHciContext->p_device_mgmt_info )
285        )
286    {
287        phHciNfc_DevMgmt_Info_t *p_device_mgmt_info=NULL;
288        p_device_mgmt_info = (phHciNfc_DevMgmt_Info_t *)
289                                psHciContext->p_device_mgmt_info ;
290        p_test_result->buffer = p_device_mgmt_info->test_result.buffer;
291        p_test_result->length = p_device_mgmt_info->test_result.length;
292
293    }
294    else
295    {
296        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION);
297    }
298
299    return status;
300}
301
302
303NFCSTATUS
304phHciNfc_DevMgmt_Set_Test_Result(
305                                phHciNfc_sContext_t        *psHciContext,
306                                uint8_t                    test_status
307                            )
308{
309    NFCSTATUS                   status = NFCSTATUS_SUCCESS;
310
311    if( (NULL != psHciContext)
312        && ( NULL != psHciContext->p_device_mgmt_info )
313        )
314    {
315        phHciNfc_DevMgmt_Info_t *p_device_mgmt_info=NULL;
316        p_device_mgmt_info = (phHciNfc_DevMgmt_Info_t *)
317                                psHciContext->p_device_mgmt_info ;
318        p_device_mgmt_info->test_status = test_status;
319
320    }
321    else
322    {
323        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION);
324    }
325
326    return status;
327}
328
329
330
331NFCSTATUS
332phHciNfc_DevMgmt_Update_PipeInfo(
333                                  phHciNfc_sContext_t     *psHciContext,
334                                  uint8_t                 pipeID,
335                                  phHciNfc_Pipe_Info_t    *pPipeInfo
336                           )
337{
338    NFCSTATUS                   status = NFCSTATUS_SUCCESS;
339
340    if( NULL == psHciContext )
341    {
342        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
343    }
344    else if(NULL == psHciContext->p_device_mgmt_info)
345    {
346        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
347    }
348    else
349    {
350        phHciNfc_DevMgmt_Info_t *p_device_mgmt_info=NULL;
351        p_device_mgmt_info = (phHciNfc_DevMgmt_Info_t *)
352                                psHciContext->p_device_mgmt_info ;
353        /* Update the pipe_info of the Device Management Gate obtained
354         * from HCI Response */
355        p_device_mgmt_info->p_pipe_info = pPipeInfo;
356        if (( NULL != pPipeInfo)
357            && ((uint8_t)HCI_UNKNOWN_PIPE_ID != pipeID)
358            )
359        {
360            /* Update the Response Receive routine of the Device
361             * Managment Gate */
362            pPipeInfo->recv_resp = &phHciNfc_Recv_DevMgmt_Response;
363            pPipeInfo->recv_event = &phHciNfc_Recv_DevMgmt_Event;
364        }
365    }
366
367    return status;
368}
369
370
371 NFCSTATUS
372 phHciNfc_DevMgmt_Configure (
373                                phHciNfc_sContext_t *psHciContext,
374                                void                *pHwRef,
375                                uint16_t            address,
376                                uint8_t             value
377                    )
378{
379    NFCSTATUS                   status = NFCSTATUS_SUCCESS;
380    phHciNfc_Pipe_Info_t        *p_pipe_info = NULL;
381    uint8_t                     pipe_id = (uint8_t)HCI_UNKNOWN_PIPE_ID;
382    uint8_t                     i=0;
383    uint8_t                     params[5];
384
385    if( (NULL == psHciContext) || (NULL == pHwRef) )
386    {
387      status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
388    }
389    else if(  NULL == psHciContext->p_device_mgmt_info )
390    {
391        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION);
392    }
393    else
394    {
395        p_pipe_info = ((phHciNfc_DevMgmt_Info_t *)
396                       psHciContext->p_device_mgmt_info)->p_pipe_info ;
397
398        if(NULL == p_pipe_info )
399        {
400            status = PHNFCSTVAL(CID_NFC_HCI,
401                            NFCSTATUS_INVALID_HCI_SEQUENCE);
402        }
403        else
404        {
405            pipe_id = p_pipe_info->pipe.pipe_id ;
406            params[i++] = 0x00;
407            params[i++] = (uint8_t)(address >> BYTE_SIZE);
408            params[i++] = (uint8_t)address;
409            params[i++] = value;
410            p_pipe_info->param_info = &params;
411            p_pipe_info->param_length = i ;
412            status = phHciNfc_Send_DevMgmt_Command( psHciContext, pHwRef,
413                                                pipe_id, (uint8_t)NXP_DBG_WRITE );
414        }
415    }
416    return status;
417}
418
419
420 NFCSTATUS
421 phHciNfc_DevMgmt_Get_Info (
422                                phHciNfc_sContext_t *psHciContext,
423                                void                *pHwRef,
424                                uint16_t            address,
425                                uint8_t             *p_val
426                    )
427{
428    NFCSTATUS                   status = NFCSTATUS_SUCCESS;
429    phHciNfc_Pipe_Info_t        *p_pipe_info = NULL;
430    uint8_t                     pipe_id = (uint8_t)HCI_UNKNOWN_PIPE_ID;
431    uint8_t                     i=0;
432    uint8_t                     params[5];
433
434    if( (NULL == psHciContext) || (NULL == pHwRef) )
435    {
436      status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
437    }
438    else if(  NULL == psHciContext->p_device_mgmt_info )
439    {
440        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION);
441    }
442    else
443    {
444        p_pipe_info = ((phHciNfc_DevMgmt_Info_t *)
445                       psHciContext->p_device_mgmt_info)->p_pipe_info ;
446
447        if(NULL == p_pipe_info )
448        {
449            status = PHNFCSTVAL(CID_NFC_HCI,
450                            NFCSTATUS_INVALID_HCI_SEQUENCE);
451        }
452        else
453        {
454            ((phHciNfc_DevMgmt_Info_t *)
455                    psHciContext->p_device_mgmt_info)->p_val = p_val;
456            pipe_id = p_pipe_info->pipe.pipe_id ;
457            params[i++] = 0x00;
458            params[i++] = (uint8_t)(address >> BYTE_SIZE);
459            params[i++] = (uint8_t) address;
460            p_pipe_info->param_info = &params;
461            p_pipe_info->param_length = i ;
462            status = phHciNfc_Send_DevMgmt_Command( psHciContext, pHwRef,
463                                            pipe_id, (uint8_t)NXP_DBG_READ );
464        }
465    }
466    return status;
467
468}
469
470/*!
471 * \brief Initialisation of PN544 Device Managment Gate.
472 *
473 * This function initialses the PN544 Device Management gate and
474 * populates the PN544 Device Management Information Structure
475 *
476 */
477
478NFCSTATUS
479phHciNfc_DevMgmt_Initialise(
480                                phHciNfc_sContext_t     *psHciContext,
481                                void                    *pHwRef
482                         )
483{
484    NFCSTATUS                       status = NFCSTATUS_SUCCESS;
485    phHciNfc_Pipe_Info_t            *p_pipe_info = NULL;
486    phHciNfc_DevMgmt_Info_t         *p_device_mgmt_info=NULL;
487    static uint8_t                   config = 0x10;
488
489    if( ( NULL == psHciContext )
490        || (NULL == pHwRef )
491        )
492    {
493        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
494    }
495    else if (NULL == psHciContext->p_device_mgmt_info)
496    {
497        status = PHNFCSTVAL(CID_NFC_HCI,
498                    NFCSTATUS_INVALID_HCI_INFORMATION);
499    }/* End of the PN544 Device Info Memory Check */
500    else
501    {
502        p_device_mgmt_info = (phHciNfc_DevMgmt_Info_t *)
503                                psHciContext->p_device_mgmt_info ;
504        p_pipe_info = p_device_mgmt_info->p_pipe_info;
505
506        if (NULL == p_pipe_info)
507        {
508            status = PHNFCSTVAL(CID_NFC_HCI,
509                            NFCSTATUS_INVALID_HCI_SEQUENCE);
510        }
511        else
512        {
513            switch(p_device_mgmt_info->current_seq )
514            {
515                /* PN544 Device Mgmt pipe open sequence */
516                case DEV_MGMT_PIPE_OPEN:
517                {
518                    status = phHciNfc_Open_Pipe( psHciContext,
519                                                    pHwRef, p_pipe_info );
520                    if(status == NFCSTATUS_SUCCESS)
521                    {
522                        p_device_mgmt_info->next_seq =
523                                    DEV_MGMT_FELICA_RC;
524                        status = NFCSTATUS_PENDING;
525                    }
526                    break;
527                }
528                case DEV_MGMT_GET_EEPROM_INFO:
529                {
530                    p_pipe_info->reg_index = DEVICE_INFO_EEPROM_INDEX;
531                    status = phHciNfc_Send_Generic_Cmd( psHciContext,
532                            pHwRef, (uint8_t)p_pipe_info->pipe.pipe_id,
533                                (uint8_t)ANY_GET_PARAMETER);
534                    if(NFCSTATUS_PENDING == status )
535                    {
536#if  ( NXP_NFC_IFC_TIMEOUT & 0x01 )
537                        p_device_mgmt_info->next_seq =
538                                                DEV_MGMT_IFC_TO_TX_H;
539#else
540                        p_device_mgmt_info->next_seq =
541                                        DEV_MGMT_TX_LDO;
542#endif /* #if  ( NXP_NFC_IFC_TIMEOUT & 0x01 ) */
543                    }
544                    break;
545                }
546                case DEV_MGMT_GPIO_PDIR:
547                {
548                    config = 0x00;
549                    status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef,
550                            NFC_ADDRESS_GPIO_PDIR , config );
551                    if(NFCSTATUS_PENDING == status )
552                    {
553                        p_device_mgmt_info->next_seq =
554                                                DEV_MGMT_GPIO_PEN;
555                    }
556                    break;
557                }
558                case DEV_MGMT_GPIO_PEN:
559                {
560                    config = NXP_NFC_GPIO_MASK(NXP_DOWNLOAD_GPIO)| 0x03 ;
561                    status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef,
562                            NFC_ADDRESS_GPIO_PEN , config );
563                    if(NFCSTATUS_PENDING == status )
564                    {
565#if  ( NXP_NFC_IFC_TIMEOUT & 0x01 )
566                        p_device_mgmt_info->next_seq =
567                                                DEV_MGMT_IFC_TO_TX_H;
568#else
569                        p_device_mgmt_info->next_seq =
570                                                DEV_MGMT_TX_LDO;
571#endif /* #if  ( NXP_NFC_IFC_TIMEOUT & 0x01 ) */
572                    }
573                    break;
574                }
575                case DEV_MGMT_FELICA_RC:
576                {
577                    config = 0x00;
578                    status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef,
579                                 NFC_FELICA_RC_ADDR , config );
580                    if(NFCSTATUS_PENDING == status )
581                    {
582
583                        if ((HCI_SELF_TEST == psHciContext->init_mode )
584                            || (HCI_NFC_DEVICE_TEST == psHciContext->init_mode ))
585                        {
586                            p_device_mgmt_info->next_seq =
587                                   DEV_MGMT_GPIO_PDIR;
588                        }
589                        else
590                        {
591                            p_device_mgmt_info->next_seq =
592                                   DEV_MGMT_GET_EEPROM_INFO;
593                        }
594                    }
595                    break;
596                }
597
598#if  ( NXP_NFC_IFC_TIMEOUT & 0x01 )
599
600                case DEV_MGMT_IFC_TO_TX_H:
601                {
602                    config =  (uint8_t)
603                        ( NXP_NFC_IFC_CONFIG_DEFAULT >> BYTE_SIZE ) /* 0x03 */;
604                    status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef,
605                        NFC_ADDRESS_IFC_TO_TX_H , config );
606                    if(NFCSTATUS_PENDING == status )
607                    {
608                        p_device_mgmt_info->next_seq =
609                                                DEV_MGMT_IFC_TO_TX_L;
610                    }
611                    break;
612                }
613                case DEV_MGMT_IFC_TO_TX_L:
614                {
615                    config = (uint8_t)
616                        ( NXP_NFC_IFC_CONFIG_DEFAULT & BYTE_MASK ) /* 0xE8 */;
617                    status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef,
618                            NFC_ADDRESS_IFC_TO_TX_L , config );
619                    if(NFCSTATUS_PENDING == status )
620                    {
621#if  ( NXP_NFC_IFC_TIMEOUT & 0x02 )
622                        p_device_mgmt_info->next_seq =
623                                                DEV_MGMT_IFC_TO_RX_H;
624#else
625                        p_device_mgmt_info->next_seq =
626                                                DEV_MGMT_TX_LDO;
627#endif /* #if  ( NXP_NFC_IFC_TIMEOUT & 0x02 ) */
628                    }
629                    break;
630                }
631                case DEV_MGMT_IFC_TO_RX_H:
632                {
633                    config = 0x10;
634                    status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef,
635                            NFC_ADDRESS_IFC_TO_RX_H , config );
636                    if(NFCSTATUS_PENDING == status )
637                    {
638                        p_device_mgmt_info->next_seq =
639                                                DEV_MGMT_IFC_TO_RX_L;
640                    }
641                    break;
642                }
643                case DEV_MGMT_IFC_TO_RX_L:
644                {
645                    config = 0x1E;
646                    status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef,
647                            NFC_ADDRESS_IFC_TO_RX_L , config );
648                    if(NFCSTATUS_PENDING == status )
649                    {
650                        p_device_mgmt_info->next_seq =
651                                                DEV_MGMT_TX_LDO;
652                    }
653                    break;
654                }
655
656#endif /* #if  ( NXP_NFC_IFC_TIMEOUT & 0x01 ) */
657                case DEV_MGMT_TX_LDO:
658                {
659#if ( NXP_HAL_VERIFY_EEPROM_CRC & 0x01U )
660                    if (0 != p_device_mgmt_info->eeprom_crc)
661                    {
662                        status = NFCSTATUS_FAILED;
663                    }
664                    else
665#endif
666                    {
667                       config = (NFC_DEV_HWCONF_DEFAULT |
668                                    (NXP_DEFAULT_TX_LDO & NFC_DEV_TXLDO_MASK));
669                       status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef,
670                            NFC_ADDRESS_HW_CONF , config );
671                       if(NFCSTATUS_PENDING == status )
672                       {
673#if ( SW_TYPE_RF_TUNING_BF & 0x01)
674                           p_device_mgmt_info->next_seq = DEV_MGMT_ANAIRQ_CONF;
675#else
676                           p_device_mgmt_info->next_seq = DEV_MGMT_CLK_REQ;
677#endif
678                           /* status = NFCSTATUS_SUCCESS; */
679                       }
680                    }
681                    break;
682                }
683#if ( SW_TYPE_RF_TUNING_BF & 0x01)
684                /* The Analogue IRQ Configuartion */
685                case DEV_MGMT_ANAIRQ_CONF:
686                {
687                    config = 0x04;
688                    status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef,
689                            NFC_ADDRESS_ANAIRQ_CONF , config );
690                    if(NFCSTATUS_PENDING == status )
691                    {
692                        p_device_mgmt_info->next_seq =
693                                                DEV_MGMT_PMOS_MOD;
694                        /* status = NFCSTATUS_SUCCESS; */
695                    }
696                    break;
697                }
698                /* The PMOS Modulation Index */
699                case DEV_MGMT_PMOS_MOD:
700                {
701                    config = NFC_DEV_PMOS_MOD_DEFAULT;
702                    status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef,
703                            NFC_ADDRESS_PMOS_MOD , config );
704                    if(NFCSTATUS_PENDING == status )
705                    {
706                        p_device_mgmt_info->next_seq =
707                                                DEV_MGMT_CLK_REQ;
708                        /* status = NFCSTATUS_SUCCESS; */
709                    }
710                    break;
711                }
712#endif /* #if ( SW_TYPE_RF_TUNING_BF & 0x01) */
713                case DEV_MGMT_CLK_REQ:
714                {
715                    config = ((phHal_sHwConfig_t *)
716                                    psHciContext->p_config_params)->clk_req ;
717                    status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef,
718                            NFC_ADDRESS_CLK_REQ , config );
719                    if(NFCSTATUS_PENDING == status )
720                    {
721                        p_device_mgmt_info->next_seq =
722                                                DEV_MGMT_INPUT_CLK;
723                        /* status = NFCSTATUS_SUCCESS; */
724                    }
725                    break;
726                }
727                case DEV_MGMT_INPUT_CLK:
728                {
729                    config = ((phHal_sHwConfig_t *)
730                                    psHciContext->p_config_params)->input_clk;
731                    status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef,
732                            NFC_ADDRESS_CLK_INPUT , config );
733                    if(NFCSTATUS_PENDING == status )
734                    {
735                        p_device_mgmt_info->next_seq =
736                                                DEV_MGMT_UICC_PWR_REQUEST;
737                    }
738                    break;
739                }
740                case DEV_MGMT_UICC_PWR_REQUEST:
741                {
742                    config = NXP_UICC_PWR_REQUEST;
743                    status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef,
744                            NFC_ADDRESS_SWP_PWR_REQ , config );
745                    if(NFCSTATUS_PENDING == status )
746                    {
747                        p_device_mgmt_info->next_seq =
748                                                DEV_MGMT_UICC_RD_A_ACCESS;
749                    }
750                    break;
751                }
752                case DEV_MGMT_UICC_RD_A_ACCESS:
753                {
754#if ( NXP_UICC_RD_RIGHTS & 0x01 )
755                    config = (uint8_t) phHciNfc_RFReaderAGate;
756#else
757                    config = 0xFFU;
758#endif /* #if ( NXP_UICC_RD_RIGHTS & 0x01 ) */
759                    status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef,
760                            NFC_ADDRESS_UICC_RD_A_ACCESS , config );
761                    if(NFCSTATUS_PENDING == status )
762                    {
763                        p_device_mgmt_info->next_seq =
764                                                DEV_MGMT_UICC_RD_B_ACCESS;
765                    }
766                    break;
767                }
768                case DEV_MGMT_UICC_RD_B_ACCESS:
769                {
770#if ( NXP_UICC_RD_RIGHTS & 0x02 )
771                    config = (uint8_t) phHciNfc_RFReaderBGate;
772#else
773                    config = 0xFFU;
774#endif /* #if ( NXP_UICC_RD_RIGHTS & 0x02 ) */
775                    status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef,
776                            NFC_ADDRESS_UICC_RD_B_ACCESS , config );
777                    if(NFCSTATUS_PENDING == status )
778                    {
779                        p_device_mgmt_info->next_seq =
780                                                DEV_MGMT_UICC_CE_A_ACCESS;
781                    }
782                    break;
783                }
784                case DEV_MGMT_UICC_CE_A_ACCESS:
785                {
786#if defined(HOST_EMULATION) || ( NXP_UICC_CE_RIGHTS & 0x01 )
787                    config = (uint8_t) phHciNfc_CETypeAGate;
788#else
789                    config = 0xFFU;
790#endif /* #if ( NXP_UICC_CE_RIGHTS & 0x01 ) */
791                    status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef,
792                            NFC_ADDRESS_UICC_CE_A_ACCESS , config );
793                    if(NFCSTATUS_PENDING == status )
794                    {
795                        p_device_mgmt_info->next_seq =
796                                                DEV_MGMT_UICC_CE_B_ACCESS;
797                    }
798                    break;
799                }
800                case DEV_MGMT_UICC_CE_B_ACCESS:
801                {
802#if defined(HOST_EMULATION) || ( NXP_UICC_CE_RIGHTS & 0x02 )
803                    config = (uint8_t) phHciNfc_CETypeBGate;
804#else
805                    config = 0xFFU;
806#endif /* #if ( NXP_UICC_CE_RIGHTS & 0x02 ) */
807                    status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef,
808                            NFC_ADDRESS_UICC_CE_B_ACCESS , config );
809                    if(NFCSTATUS_PENDING == status )
810                    {
811                        p_device_mgmt_info->next_seq =
812                                                DEV_MGMT_UICC_CE_BP_ACCESS;
813                    }
814                    break;
815                }
816                case DEV_MGMT_UICC_CE_BP_ACCESS:
817                {
818#if defined(HOST_EMULATION) || ( NXP_UICC_CE_RIGHTS & 0x04 )
819                    config = (uint8_t) phHciNfc_CETypeBPrimeGate;
820#else
821                    config = 0xFFU;
822#endif /* #if ( NXP_UICC_CE_RIGHTS & 0x04 ) */
823                    status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef,
824                            NFC_ADDRESS_UICC_CE_BP_ACCESS , config );
825                    if(NFCSTATUS_PENDING == status )
826                    {
827                        p_device_mgmt_info->next_seq =
828                                                DEV_MGMT_UICC_CE_F_ACCESS;
829                    }
830                    break;
831                }
832                case DEV_MGMT_UICC_CE_F_ACCESS:
833                {
834#if defined(HOST_EMULATION) || ( NXP_UICC_CE_RIGHTS & 0x08 )
835                    config = (uint8_t) phHciNfc_CETypeFGate;
836#else
837                    config = 0xFFU;
838#endif /* #if ( NXP_UICC_CE_RIGHTS & 0x08 ) */
839                    status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef,
840                            NFC_ADDRESS_UICC_CE_F_ACCESS , config );
841                    if(NFCSTATUS_PENDING == status )
842                    {
843                        p_device_mgmt_info->next_seq =
844                                                DEV_MGMT_UICC_BIT_RATE;
845                    }
846                    break;
847                }
848                case DEV_MGMT_UICC_BIT_RATE:
849                {
850                    config = NXP_UICC_BIT_RATE;
851                    status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef,
852                            NFC_ADDRESS_SWP_BITRATE , config );
853                    if(NFCSTATUS_PENDING == status )
854                    {
855#if defined (CFG_PWR_STATUS)
856                        p_device_mgmt_info->next_seq =
857                                                DEV_MGMT_SET_PWR_STATUS;
858#else
859                        p_device_mgmt_info->next_seq =
860                                                DEV_MGMT_SET_INFO_EVT;
861#endif
862                    }
863                    break;
864                }
865#ifdef CFG_PWR_STATUS
866                case DEV_MGMT_SET_PWR_STATUS:
867                {
868                    config = NXP_SYSTEM_PWR_STATUS;
869                    status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef,
870                            NFC_ADDRESS_PWR_STATUS , config );
871                    if(NFCSTATUS_PENDING == status )
872                    {
873                        p_device_mgmt_info->next_seq =
874                                                DEV_MGMT_SET_INFO_EVT;
875                    }
876                    break;
877                }
878#endif
879                case DEV_MGMT_SET_INFO_EVT:
880                {
881                    config = NXP_SYSTEM_EVT_INFO;
882                    status = phHciNfc_Set_Param(psHciContext, pHwRef,
883                                    p_pipe_info, DEVICE_INFO_EVT_INDEX,
884                                    (uint8_t *)&config, sizeof(config) );
885                    if(NFCSTATUS_PENDING == status )
886                    {
887#if  ( HOST_LINK_TIMEOUT & 0x01 )
888                        p_device_mgmt_info->next_seq =
889                                                DEV_MGMT_LLC_GRD_TO_H;
890#else
891                        p_device_mgmt_info->next_seq =
892                                                DEV_MGMT_EVT_AUTONOMOUS;
893                        status = NFCSTATUS_SUCCESS;
894#endif /* #if ( HOST_LINK_TIMEOUT & 0x01 ) */
895                    }
896                    break;
897                }
898#if  ( HOST_LINK_TIMEOUT & 0x01 )
899
900                case DEV_MGMT_LLC_GRD_TO_H:
901                {
902                    config =(uint8_t)
903                        ( NXP_NFC_LINK_GRD_CFG_DEFAULT >> BYTE_SIZE ) /* 0x00 */;
904                    status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef,
905                            NFC_ADDRESS_LLC_GRD_TO_H , config );
906                    if(NFCSTATUS_PENDING == status )
907                    {
908                        p_device_mgmt_info->next_seq =
909                                                DEV_MGMT_LLC_GRD_TO_L;
910                    }
911                    break;
912                }
913                case DEV_MGMT_LLC_GRD_TO_L:
914                {
915                    config = (uint8_t)
916                        ( NXP_NFC_LINK_GRD_CFG_DEFAULT & BYTE_MASK ) /* 0x32 */;
917                    status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef,
918                            NFC_ADDRESS_LLC_GRD_TO_L , config );
919                    if(NFCSTATUS_PENDING == status )
920                    {
921#if  ( HOST_LINK_TIMEOUT & 0x02 )
922                        p_device_mgmt_info->next_seq =
923                                                DEV_MGMT_LLC_ACK_TO_H;
924#else
925                        p_device_mgmt_info->next_seq =
926                                                DEV_MGMT_EVT_AUTONOMOUS;
927                        status = NFCSTATUS_SUCCESS;
928#endif /* #if ( HOST_LINK_TIMEOUT & 0x02 ) */
929                    }
930                    break;
931                }
932                case DEV_MGMT_LLC_ACK_TO_H:
933                {
934                    config = (uint8_t)
935                        ( NXP_NFC_LINK_ACK_CFG_DEFAULT >> BYTE_SIZE )/* 0x00 */;
936                    status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef,
937                            NFC_ADDRESS_LLC_ACK_TO_H , config );
938                    if(NFCSTATUS_PENDING == status )
939                    {
940                        p_device_mgmt_info->next_seq =
941                                                DEV_MGMT_LLC_ACK_TO_L;
942                    }
943                    break;
944                }
945                case DEV_MGMT_LLC_ACK_TO_L:
946                {
947                    config = (uint8_t)
948                        ( NXP_NFC_LINK_ACK_CFG_DEFAULT & BYTE_MASK ) /* 0x00 */;;
949                    status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef,
950                            NFC_ADDRESS_LLC_ACK_TO_L , config );
951                    if(NFCSTATUS_PENDING == status )
952                    {
953                        p_device_mgmt_info->next_seq =
954                                                DEV_MGMT_EVT_AUTONOMOUS;
955                        status = NFCSTATUS_SUCCESS;
956                    }
957                    break;
958                }
959
960#endif /* #if ( HOST_LINK_TIMEOUT & 0x01 ) */
961                default:
962                {
963                    status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_SEQUENCE);
964                    break;
965                }
966
967            }/* End of the Sequence Switch */
968        }
969
970    } /* End of Null Context Check */
971
972    return status;
973}
974
975/*!
976 * \brief Releases the resources allocated the PN544 Device Management.
977 *
978 * This function Releases the resources allocated the PN544 Device Management
979 * and resets the hardware to the reset state.
980 */
981
982NFCSTATUS
983phHciNfc_DevMgmt_Release(
984                                phHciNfc_sContext_t     *psHciContext,
985                                void                    *pHwRef
986                             )
987{
988    NFCSTATUS                           status = NFCSTATUS_SUCCESS;
989    phHciNfc_Pipe_Info_t                *p_pipe_info = NULL;
990    phHciNfc_DevMgmt_Info_t         *p_device_mgmt_info=NULL;
991
992    if( (NULL == psHciContext) || (NULL == pHwRef) )
993    {
994      status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
995    }
996    else
997    {
998        if( NULL != psHciContext->p_device_mgmt_info )
999        {
1000            p_device_mgmt_info = (phHciNfc_DevMgmt_Info_t *)
1001                                psHciContext->p_device_mgmt_info ;
1002            switch(p_device_mgmt_info->current_seq)
1003            {
1004
1005                /* PN544 Device pipe close sequence */
1006                case DEV_MGMT_EVT_AUTONOMOUS:
1007                {
1008                    p_pipe_info = p_device_mgmt_info->p_pipe_info;
1009
1010                    p_pipe_info->param_info = NULL;
1011                    p_pipe_info->param_length = HCP_ZERO_LEN;
1012
1013                    status = phHciNfc_Send_DevMgmt_Event(psHciContext, pHwRef,
1014                                p_pipe_info->pipe.pipe_id, NXP_EVT_SET_AUTONOMOUS);
1015                    if(status == NFCSTATUS_PENDING)
1016                    {
1017                        p_device_mgmt_info->next_seq = DEV_MGMT_PIPE_OPEN;
1018                        status = NFCSTATUS_SUCCESS;
1019                    }
1020                    break;
1021                }
1022                /* PN544 Device pipe close sequence */
1023                case DEV_MGMT_PIPE_CLOSE:
1024                {
1025                    p_pipe_info = p_device_mgmt_info->p_pipe_info;
1026
1027                    status = phHciNfc_Close_Pipe( psHciContext,
1028                                                        pHwRef, p_pipe_info );
1029                    if(status == NFCSTATUS_SUCCESS)
1030                    {
1031                        p_device_mgmt_info->next_seq = DEV_MGMT_PIPE_OPEN;
1032                        /* status = NFCSTATUS_PENDING; */
1033                    }
1034                    break;
1035                }
1036                default:
1037                {
1038                    status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_SEQUENCE);
1039                    break;
1040                }
1041
1042            }/* End of the Sequence Switch */
1043
1044        }/* End of the PN544 Device Info Memory Check */
1045
1046    } /* End of Null Context Check */
1047
1048    return status;
1049}
1050
1051NFCSTATUS
1052phHciNfc_DevMgmt_Update_Sequence(
1053                                phHciNfc_sContext_t     *psHciContext,
1054                                phHciNfc_eSeqType_t     DevMgmt_seq
1055                             )
1056{
1057    NFCSTATUS                   status = NFCSTATUS_SUCCESS;
1058    phHciNfc_DevMgmt_Info_t          *p_device_mgmt_info=NULL;
1059    if( NULL == psHciContext )
1060    {
1061        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1062    }
1063    else if ( NULL == psHciContext->p_device_mgmt_info )
1064    {
1065        status = PHNFCSTVAL(CID_NFC_HCI,
1066                        NFCSTATUS_INVALID_HCI_INFORMATION);
1067    }
1068    else
1069    {
1070        p_device_mgmt_info = (phHciNfc_DevMgmt_Info_t *)
1071                            psHciContext->p_device_mgmt_info ;
1072        switch(DevMgmt_seq)
1073        {
1074            case RESET_SEQ:
1075            case INIT_SEQ:
1076            {
1077                p_device_mgmt_info->current_seq = DEV_MGMT_PIPE_OPEN;
1078                p_device_mgmt_info->next_seq = DEV_MGMT_PIPE_OPEN ;
1079                break;
1080            }
1081            case UPDATE_SEQ:
1082            {
1083                p_device_mgmt_info->current_seq = p_device_mgmt_info->next_seq;
1084
1085                break;
1086            }
1087            case REL_SEQ:
1088            {
1089                p_device_mgmt_info->current_seq = DEV_MGMT_EVT_AUTONOMOUS;
1090                p_device_mgmt_info->next_seq = DEV_MGMT_EVT_AUTONOMOUS ;
1091                break;
1092            }
1093            default:
1094            {
1095                break;
1096            }
1097        }/* End of Update Sequence Switch */
1098    }
1099    return status;
1100
1101}
1102
1103
1104
1105/*!
1106 * \brief Perform the System Management Tests
1107 * provided by the corresponding peripheral device.
1108 *
1109 * This function performs the System Management Tests provided by the NFC
1110 * Peripheral device.
1111 */
1112
1113NFCSTATUS
1114phHciNfc_DevMgmt_Test(
1115                    void                            *psContext,
1116                    void                            *pHwRef,
1117                    uint8_t                         test_type,
1118                    phNfc_sData_t                   *test_param
1119                 )
1120{
1121    phHciNfc_sContext_t         *psHciContext =
1122                                    (phHciNfc_sContext_t *)psContext ;
1123    NFCSTATUS                   status = NFCSTATUS_SUCCESS;
1124    phHciNfc_Pipe_Info_t        *p_pipe_info = NULL;
1125    uint8_t                     pipe_id = (uint8_t)HCI_UNKNOWN_PIPE_ID;
1126
1127    if( (NULL == psHciContext) || (NULL == pHwRef) )
1128    {
1129      status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1130    }
1131    else if(  NULL == psHciContext->p_device_mgmt_info )
1132    {
1133        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION);
1134    }
1135    else
1136    {
1137        phHciNfc_DevMgmt_Info_t *p_device_mgmt_info = (phHciNfc_DevMgmt_Info_t *)
1138                                        psHciContext->p_device_mgmt_info ;
1139        p_pipe_info = ((phHciNfc_DevMgmt_Info_t *)
1140                       psHciContext->p_device_mgmt_info)->p_pipe_info ;
1141        switch(test_type)
1142        {
1143            case NXP_SELF_TEST_ANTENNA:
1144            case NXP_SELF_TEST_SWP:
1145            case NXP_SELF_TEST_PRBS:
1146            /* case NXP_SELF_TEST_NFCWI: */
1147            {
1148                if (NULL != p_pipe_info)
1149                {
1150                    pipe_id = p_pipe_info->pipe.pipe_id ;
1151                    if ( NULL != test_param )
1152                    {
1153                        p_pipe_info->param_info = test_param->buffer;
1154                        p_pipe_info->param_length = (uint8_t)test_param->length;
1155                    }
1156                    p_device_mgmt_info->test_result.buffer = NULL;
1157                    p_device_mgmt_info->test_result.length = 0;
1158                    status =
1159                        phHciNfc_Send_DevMgmt_Command( psHciContext, pHwRef,
1160                            pipe_id, (uint8_t)test_type );
1161                }
1162                else
1163                {
1164                    status = PHNFCSTVAL(CID_NFC_HCI,
1165                                        NFCSTATUS_INVALID_HCI_INFORMATION);
1166                }
1167                break;
1168            }
1169            default:
1170            {
1171                status = PHNFCSTVAL(CID_NFC_HCI,
1172                            NFCSTATUS_FEATURE_NOT_SUPPORTED);
1173                break;
1174            }
1175        }
1176
1177    }
1178    return status;
1179}
1180
1181
1182/*!
1183 * \brief Receives the HCI Response from the corresponding peripheral device.
1184 *
1185 * This function receives the HCI Command Response from the connected NFC
1186 * Peripheral device.
1187 */
1188static
1189NFCSTATUS
1190phHciNfc_Recv_DevMgmt_Response(
1191                        void                *psContext,
1192                        void                *pHwRef,
1193                        uint8_t             *pResponse,
1194#ifdef ONE_BYTE_LEN
1195                        uint8_t             length
1196#else
1197                        uint16_t            length
1198#endif
1199                    )
1200{
1201    phHciNfc_sContext_t         *psHciContext =
1202                                    (phHciNfc_sContext_t *)psContext ;
1203    phHciNfc_DevMgmt_Info_t *p_device_mgmt_info=NULL;
1204    NFCSTATUS                   status = NFCSTATUS_SUCCESS;
1205    uint8_t                     prev_cmd = ANY_GET_PARAMETER;
1206
1207    if( (NULL == psHciContext) || (NULL == pHwRef) )
1208    {
1209      status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1210    }
1211    else if(  NULL == psHciContext->p_device_mgmt_info )
1212    {
1213        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
1214    }
1215    else
1216    {
1217        p_device_mgmt_info = (phHciNfc_DevMgmt_Info_t *)
1218                            psHciContext->p_device_mgmt_info ;
1219        prev_cmd = p_device_mgmt_info->p_pipe_info->prev_msg ;
1220        switch(prev_cmd)
1221        {
1222            case ANY_GET_PARAMETER:
1223            {
1224                status = phHciNfc_DevMgmt_InfoUpdate(psHciContext,
1225                            (phHal_sHwReference_t *)pHwRef,
1226                            p_device_mgmt_info->p_pipe_info->reg_index,
1227                            &pResponse[HCP_HEADER_LEN],
1228                                (uint8_t)(length - HCP_HEADER_LEN));
1229                break;
1230            }
1231            case ANY_SET_PARAMETER:
1232            {
1233                break;
1234            }
1235            case ANY_OPEN_PIPE:
1236            {
1237                break;
1238            }
1239            case ANY_CLOSE_PIPE:
1240            {
1241                phOsalNfc_FreeMemory(p_device_mgmt_info->p_pipe_info);
1242                p_device_mgmt_info->p_pipe_info = NULL;
1243                psHciContext->p_pipe_list[PIPETYPE_STATIC_LINK] = NULL;
1244                break;
1245            }
1246            case NXP_DBG_READ:
1247            /* fall through */
1248            case NXP_DBG_WRITE:
1249            {
1250                if( NULL != p_device_mgmt_info->p_val )
1251                {
1252                    *p_device_mgmt_info->p_val = (uint8_t)( length > HCP_HEADER_LEN ) ?
1253                                        pResponse[HCP_HEADER_LEN]: 0;
1254                    p_device_mgmt_info->p_val = NULL;
1255                }
1256                break;
1257            }
1258            /* Self Test Commands */
1259            case NXP_SELF_TEST_ANTENNA:
1260            case NXP_SELF_TEST_SWP:
1261            case NXP_SELF_TEST_NFCWI:
1262            case NXP_SELF_TEST_PRBS:
1263            {
1264                p_device_mgmt_info->test_status = (uint8_t) ( length > HCP_HEADER_LEN ) ?
1265                                    pResponse[HCP_HEADER_LEN]: 0;
1266                p_device_mgmt_info->test_result.buffer = (uint8_t)( length > HCP_HEADER_LEN ) ?
1267                                    &pResponse[HCP_HEADER_LEN]: NULL;
1268                p_device_mgmt_info->test_result.length = ( length - HCP_HEADER_LEN );
1269                break;
1270            }
1271            default:
1272            {
1273                status = PHNFCSTVAL(CID_NFC_HCI,
1274                                        NFCSTATUS_INVALID_HCI_RESPONSE);
1275                break;
1276            }
1277        }
1278        if( NFCSTATUS_SUCCESS == status )
1279        {
1280            if( NULL != p_device_mgmt_info->p_pipe_info)
1281            {
1282                p_device_mgmt_info->p_pipe_info->prev_status = NFCSTATUS_SUCCESS;
1283            }
1284            p_device_mgmt_info->current_seq = p_device_mgmt_info->next_seq;
1285        }
1286
1287    }
1288    return status;
1289}
1290
1291/*!
1292 * \brief Receives the HCI Event from the corresponding peripheral device.
1293 *
1294 * This function receives the HCI Event from the connected NFC
1295 * Peripheral device.
1296 */
1297
1298static
1299NFCSTATUS
1300phHciNfc_Recv_DevMgmt_Event(
1301                        void                *psContext,
1302                        void                *pHwRef,
1303                        uint8_t             *pEvent,
1304#ifdef ONE_BYTE_LEN
1305                        uint8_t             length
1306#else
1307                        uint16_t            length
1308#endif
1309                    )
1310{
1311    phHciNfc_sContext_t         *psHciContext =
1312                                    (phHciNfc_sContext_t *)psContext ;
1313    phHciNfc_DevMgmt_Info_t     *p_device_mgmt_info=NULL;
1314    phHciNfc_HCP_Packet_t       *hcp_packet = NULL;
1315    phHciNfc_HCP_Message_t      *hcp_message = NULL;
1316    NFCSTATUS                   status = NFCSTATUS_SUCCESS;
1317    phHal_sEventInfo_t          event_info;
1318    uint8_t                     event = (uint8_t) HCP_MSG_INSTRUCTION_INVALID;
1319
1320    if( (NULL == psHciContext) || (NULL == pHwRef) )
1321    {
1322      status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1323    }
1324    else if(  NULL == psHciContext->p_device_mgmt_info )
1325    {
1326        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
1327    }
1328    else
1329    {
1330        p_device_mgmt_info = (phHciNfc_DevMgmt_Info_t *)
1331                            psHciContext->p_device_mgmt_info ;
1332        hcp_packet = (phHciNfc_HCP_Packet_t *)pEvent;
1333        hcp_message = &hcp_packet->msg.message;
1334
1335        /* Get the Event instruction bits from the Message Header */
1336        event = (uint8_t) GET_BITS8( hcp_message->msg_header,
1337            HCP_MSG_INSTRUCTION_OFFSET, HCP_MSG_INSTRUCTION_LEN);
1338        event_info.eventHost = phHal_eHostController ;
1339        event_info.eventSource = phHal_ePCD_DevType;
1340
1341        switch(event)
1342        {
1343            /* Information Events */
1344            case NXP_EVT_INFO_TXLDO_OVERCUR:
1345            {
1346                event_info.eventType = NFC_INFO_TXLDO_OVERCUR;
1347                break;
1348            }
1349            case NXP_EVT_INFO_PMUVCC:
1350            {
1351                p_device_mgmt_info->pmuvcc_status = (uint8_t) ( length > HCP_HEADER_LEN ) ?
1352                                    pEvent[HCP_HEADER_LEN]: 0;
1353                break;
1354            }
1355            case NXP_EVT_INFO_EXT_RF_FIELD:
1356            {
1357                event_info.eventSource = phHal_ePICC_DevType ;
1358                p_device_mgmt_info->rf_status = (uint8_t) ( length > HCP_HEADER_LEN ) ?
1359                                    pEvent[HCP_HEADER_LEN]: 0;
1360#ifdef EVT_INFO_EXT_EVT_DIRECT
1361                event_info.eventType = ( CE_EVT_NFC_FIELD_ON ==
1362                                (p_device_mgmt_info->rf_status & 0x1FU))?
1363                                    NFC_EVT_FIELD_ON : NFC_EVT_FIELD_OFF;
1364#else
1365                event_info.eventType = (TRUE == p_device_mgmt_info->rf_status)?
1366                                    NFC_EVT_FIELD_ON : NFC_EVT_FIELD_OFF;
1367#endif
1368                break;
1369            }
1370            case NXP_EVT_INFO_MEM_VIOLATION:
1371            {
1372                event_info.eventType = NFC_INFO_MEM_VIOLATION;
1373                LOGW("Your NFC controller is kinda hosed, take it to npelly@ to fix");
1374                break;
1375            }
1376            case NXP_EVT_INFO_TEMP_OVERHEAT:
1377            {
1378                p_device_mgmt_info->overheat_status = (uint8_t)( length > HCP_HEADER_LEN ) ?
1379                                    pEvent[HCP_HEADER_LEN]: 0;
1380                event_info.eventType = NFC_INFO_TEMP_OVERHEAT;
1381                event_info.eventInfo.overheat_status =
1382                                    p_device_mgmt_info->overheat_status;
1383                break;
1384            }
1385            case NXP_EVT_INFO_LLC_ERROR:
1386            {
1387                event_info.eventType = NFC_INFO_LLC_ERROR;
1388                break;
1389            }
1390            default:
1391            {
1392                status = PHNFCSTVAL(CID_NFC_HCI,
1393                                        NFCSTATUS_INVALID_HCI_RESPONSE);
1394                break;
1395            }
1396        }
1397        if( NFCSTATUS_SUCCESS == status )
1398        {
1399            if( NULL != p_device_mgmt_info->p_pipe_info)
1400            {
1401                p_device_mgmt_info->p_pipe_info->prev_status =
1402                                                    NFCSTATUS_SUCCESS;
1403            }
1404            p_device_mgmt_info->current_seq =
1405                                        p_device_mgmt_info->next_seq;
1406            phHciNfc_Notify_Event(psHciContext, pHwRef,
1407                                        NFC_NOTIFY_EVENT, &event_info);
1408        }
1409    }
1410    return status;
1411}
1412
1413
1414static
1415NFCSTATUS
1416phHciNfc_DevMgmt_InfoUpdate(
1417                                phHciNfc_sContext_t     *psHciContext,
1418                                phHal_sHwReference_t    *pHwRef,
1419                                uint8_t                 index,
1420                                uint8_t                 *reg_value,
1421                                uint8_t                 reg_length
1422                          )
1423{
1424    phHciNfc_DevMgmt_Info_t *p_device_mgmt_info=NULL;
1425    NFCSTATUS               status = NFCSTATUS_SUCCESS;
1426    uint8_t                 i=0;
1427
1428    PHNFC_UNUSED_VARIABLE(pHwRef);
1429    if( (NULL == psHciContext)
1430        || (NULL == reg_value)
1431        || (reg_length == 0)
1432      )
1433    {
1434        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1435    }
1436    else if ( NULL == psHciContext->p_device_mgmt_info )
1437    {
1438        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION);
1439    }
1440    else
1441    {
1442        p_device_mgmt_info = (phHciNfc_DevMgmt_Info_t *)
1443                                psHciContext->p_device_mgmt_info ;
1444
1445        switch(index)
1446        {
1447            case DEVICE_INFO_EEPROM_INDEX:
1448            {
1449                p_device_mgmt_info->eeprom_crc = reg_value[i];
1450                break;
1451            }
1452            default:
1453            {
1454                break;
1455            }
1456        }
1457
1458    } /* End of Context and the PN544 Device information validity check */
1459
1460    return status;
1461}
1462
1463
1464
1465/*!
1466 * \brief Sends the RF Settings HCI Additonal Commands to the connected
1467 * reader device.
1468 *
1469 * This function Sends the RF Settings HCI Command frames in the HCP packet
1470 * format to the connected reader device.
1471 */
1472static
1473 NFCSTATUS
1474 phHciNfc_Send_DevMgmt_Command (
1475                                phHciNfc_sContext_t *psHciContext,
1476                                void                *pHwRef,
1477                                uint8_t             pipe_id,
1478                                uint8_t             cmd
1479                    )
1480 {
1481    phHciNfc_HCP_Packet_t   *hcp_packet = NULL;
1482    phHciNfc_HCP_Message_t  *hcp_message = NULL;
1483    phHciNfc_Pipe_Info_t    *p_pipe_info = NULL;
1484    uint8_t                 length=0;
1485    uint8_t                 i = 0;
1486    NFCSTATUS               status = NFCSTATUS_SUCCESS;
1487
1488    if( (NULL == psHciContext)
1489        || ( pipe_id > PHHCINFC_MAX_PIPE)
1490        ||(NULL == psHciContext->p_pipe_list[pipe_id])
1491      )
1492    {
1493        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1494        HCI_DEBUG("%s: Invalid Arguments passed \n",
1495                                                "phHciNfc_Send_DevMgmt_Command");
1496    }
1497    else
1498    {
1499        p_pipe_info = (phHciNfc_Pipe_Info_t *)
1500                                psHciContext->p_pipe_list[pipe_id];
1501        psHciContext->tx_total = 0 ;
1502        length +=  HCP_HEADER_LEN ;
1503        switch( cmd )
1504        {
1505            /* Self Test Commands */
1506            case NXP_SELF_TEST_ANTENNA:
1507            case NXP_SELF_TEST_SWP:
1508            case NXP_SELF_TEST_NFCWI:
1509            case NXP_SELF_TEST_PRBS:
1510            /* Internal Properietary Commands */
1511            case NXP_DBG_READ:
1512            case NXP_DBG_WRITE:
1513            {
1514
1515                hcp_packet = (phHciNfc_HCP_Packet_t *) psHciContext->send_buffer;
1516                /* Construct the HCP Frame */
1517                phHciNfc_Build_HCPFrame(hcp_packet,HCP_CHAINBIT_DEFAULT,
1518                                        (uint8_t) pipe_id, HCP_MSG_TYPE_COMMAND, cmd);
1519                hcp_message = &(hcp_packet->msg.message);
1520                /* Append the RF Setting Parameter also the optional Value */
1521                phHciNfc_Append_HCPFrame((uint8_t *)hcp_message->payload,
1522                                            i, p_pipe_info->param_info,
1523                                            p_pipe_info->param_length);
1524                length =(uint8_t)(length + i + p_pipe_info->param_length);
1525                break;
1526            }
1527            default:
1528            {
1529                status = PHNFCSTVAL( CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED );
1530                HCI_DEBUG("%s: Statement Should Not Occur \n",
1531                                                "phHciNfc_Send_DevMgmt_Command");
1532                break;
1533            }
1534        }
1535        if( NFCSTATUS_SUCCESS == status )
1536        {
1537            p_pipe_info->sent_msg_type = HCP_MSG_TYPE_COMMAND;
1538            p_pipe_info->prev_msg = cmd;
1539            psHciContext->tx_total = length;
1540            psHciContext->response_pending = TRUE ;
1541
1542            /* Send the Constructed HCP packet to the lower layer */
1543            status = phHciNfc_Send_HCP( psHciContext, pHwRef );
1544            p_pipe_info->prev_status = NFCSTATUS_PENDING;
1545        }
1546    }
1547
1548    return status;
1549}
1550
1551
1552
1553/*!
1554 * \brief Sends the RF Settings HCI Additonal Events to the connected
1555 * reader device.
1556 *
1557 * This function Sends the RF Settings HCI Events frames in the HCP packet
1558 * format to the connected reader device.
1559 */
1560
1561static
1562 NFCSTATUS
1563 phHciNfc_Send_DevMgmt_Event (
1564                                phHciNfc_sContext_t *psHciContext,
1565                                void                *pHwRef,
1566                                uint8_t             pipe_id,
1567                                uint8_t             event
1568                    )
1569 {
1570    phHciNfc_HCP_Packet_t   *hcp_packet = NULL;
1571    phHciNfc_HCP_Message_t  *hcp_message = NULL;
1572    phHciNfc_Pipe_Info_t    *p_pipe_info = NULL;
1573    uint8_t                 length=0;
1574    uint8_t                 i = 0;
1575    NFCSTATUS               status = NFCSTATUS_SUCCESS;
1576
1577    if( (NULL == psHciContext)
1578        || ( pipe_id > PHHCINFC_MAX_PIPE)
1579        ||(NULL == psHciContext->p_pipe_list[pipe_id])
1580      )
1581    {
1582        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1583        HCI_DEBUG("%s: Invalid Arguments passed \n",
1584                                                "phHciNfc_Send_DevMgmt_Event");
1585    }
1586    else
1587    {
1588        p_pipe_info = (phHciNfc_Pipe_Info_t *)
1589                                psHciContext->p_pipe_list[pipe_id];
1590        psHciContext->tx_total = 0 ;
1591        length +=  HCP_HEADER_LEN ;
1592        if( NXP_EVT_SET_AUTONOMOUS == event )
1593        {
1594
1595            hcp_packet = (phHciNfc_HCP_Packet_t *) psHciContext->send_buffer;
1596            /* Construct the HCP Frame */
1597            phHciNfc_Build_HCPFrame(hcp_packet,HCP_CHAINBIT_DEFAULT,
1598                                    (uint8_t) pipe_id, HCP_MSG_TYPE_EVENT, event);
1599            hcp_message = &(hcp_packet->msg.message);
1600            /* Append the RF Setting Parameter also the optional Value */
1601            phHciNfc_Append_HCPFrame((uint8_t *)hcp_message->payload,
1602                                        i, p_pipe_info->param_info,
1603                                        p_pipe_info->param_length);
1604            length =(uint8_t)(length + i + p_pipe_info->param_length);
1605        }
1606        else
1607        {
1608            status = PHNFCSTVAL( CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED );
1609            HCI_DEBUG("%s: Statement Should Not Occur \n",
1610                                            "phHciNfc_Send_DevMgmt_Event");
1611        }
1612        if( NFCSTATUS_SUCCESS == status )
1613        {
1614            p_pipe_info->sent_msg_type = HCP_MSG_TYPE_EVENT;
1615            p_pipe_info->prev_msg = event;
1616            psHciContext->tx_total = length;
1617
1618            /* Send the Constructed HCP packet to the lower layer */
1619            status = phHciNfc_Send_HCP( psHciContext, pHwRef );
1620            p_pipe_info->prev_status = NFCSTATUS_PENDING;
1621        }
1622    }
1623
1624    return status;
1625}
1626
1627
1628
1629
1630
1631