phHciNfc_WI.c revision 5d9927ba30ba449badb9f6df0fbeb4d6aedc6e2a
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* =========================================================================== *
19*                                                                             *
20*                                                                             *
21* \file  phHciNfc_WI.c                                                        *
22* \brief HCI WI gate Management Routines.                                     *
23*                                                                             *
24*                                                                             *
25* Project: NFC-FRI-1.1                                                        *
26*                                                                             *
27* $Date: Tue Aug 18 10:22:34 2009 $                                           *
28* $Author: ing04880 $                                                         *
29* $Revision: 1.33 $                                                            *
30* $Aliases: NFC_FRI1.1_WK934_R31_1,NFC_FRI1.1_WK941_PREP1,NFC_FRI1.1_WK941_PREP2,NFC_FRI1.1_WK941_1,NFC_FRI1.1_WK943_R32_1,NFC_FRI1.1_WK949_PREP1,NFC_FRI1.1_WK943_R32_10,NFC_FRI1.1_WK943_R32_13,NFC_FRI1.1_WK943_R32_14,NFC_FRI1.1_WK1007_R33_1,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 $                                                                *                                                                             *
31* =========================================================================== *
32*/
33
34/*
35***************************** Header File Inclusion ****************************
36*/
37#include <phNfcCompId.h>
38#include <phHciNfc_Pipe.h>
39#include <phHciNfc_WI.h>
40#include <phOsalNfc.h>
41#include <phHciNfc_Emulation.h>
42/*
43****************************** Macro Definitions *******************************
44*/
45/*  WI gate specific Events definition */
46#define NXP_EVT_SE_START_OF_TRANSACTION (0x01U)
47#define NXP_EVT_SE_END_OF_TRANSACTION   (0x02U)
48#define NXP_EVT_SE_SWITCH_MODE          (0x03U)
49#define NXP_EVT_SE_TRANSACTION          (0x04U)
50
51/* WI Gate registry Settings */
52/* set default mode mode as virtual mode */
53#define NXP_SE_DEFAULTMODE_INDEX        (0x01)
54#define NXP_SE_EVENTS_INDEX             (0x05)
55
56/* Set Bit 0 and Bit 1 to report Start of transaction and End of transaction*/
57#define WI_ENABLE_EVENTS                (0x07)
58#define WI_VIRTUALMODE                  (0x01)
59#define WI_OFFMODE                      (0x00)
60#define AID_SIZE                        (0x20)
61/****************** Structure and Enumeration ****************************/
62
63
64/****************** Static Function Declaration **************************/
65
66static
67NFCSTATUS
68phHciNfc_Recv_WI_Response(
69                              void  *psContext,
70                              void  *pHwRef,
71                              uint8_t *pResponse,
72#ifdef ONE_BYTE_LEN
73                              uint8_t            length
74#else
75                              uint16_t           length
76#endif
77                         );
78
79static
80NFCSTATUS
81phHciNfc_Recv_WI_Event(
82                        void    *psContext,
83                        void    *pHwRef,
84                        uint8_t *pEvent,
85#ifdef ONE_BYTE_LEN
86                        uint8_t            length
87#else
88                        uint16_t           length
89#endif
90                    );
91
92static
93NFCSTATUS
94phHciNfc_Send_WI_Event(
95                        phHciNfc_sContext_t     *psHciContext,
96                        void                    *pHwRef,
97                        uint8_t                 pipe_id,
98                        uint8_t                 event
99                    );
100
101static
102NFCSTATUS
103phHciNfc_WI_InfoUpdate(
104                            phHciNfc_sContext_t     *psHciContext,
105                            uint8_t                 index,
106                            uint8_t                 *reg_value,
107                            uint8_t                 reg_length
108                            );
109
110
111#if defined (WI_UPDATE_SEQ)
112static
113NFCSTATUS
114phHciNfc_WI_Update_Sequence(
115                                phHciNfc_sContext_t     *psHciContext,
116                                phHciNfc_eSeqType_t     WI_seq
117                         );
118#endif /* #if defined (WI_UPDATE_SEQ) */
119
120/*
121*************************** Function Definitions ***************************
122*/
123
124
125
126NFCSTATUS
127phHciNfc_WI_Init_Resources(
128                           phHciNfc_sContext_t  *psHciContext
129                          )
130{
131    NFCSTATUS                   status = NFCSTATUS_SUCCESS;
132    phHciNfc_WI_Info_t          *p_WI_info=NULL;
133
134    if( NULL == psHciContext )
135    {
136        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
137    }
138    else
139    {
140        if(( NULL == psHciContext->p_wi_info ) &&
141             (phHciNfc_Allocate_Resource((void **)(&p_WI_info),
142            sizeof(phHciNfc_WI_Info_t))== NFCSTATUS_SUCCESS))
143        {
144            psHciContext->p_wi_info = p_WI_info;
145            p_WI_info->current_seq = eWI_PipeOpen;
146            p_WI_info->next_seq = eWI_PipeOpen;
147            p_WI_info->pipe_id = (uint8_t)HCI_UNKNOWN_PIPE_ID;
148        }
149        else
150        {
151            status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INSUFFICIENT_RESOURCES);
152        }
153
154    }
155    return status;
156}
157
158NFCSTATUS
159phHciNfc_WI_Get_PipeID(
160                            phHciNfc_sContext_t        *psHciContext,
161                            uint8_t                    *ppipe_id
162                            )
163{
164    NFCSTATUS                   status = NFCSTATUS_SUCCESS;
165
166    if( (NULL != psHciContext)
167        && ( NULL != ppipe_id )
168        && ( NULL != psHciContext->p_wi_info )
169        )
170    {
171        phHciNfc_WI_Info_t     *p_wi_info=NULL;
172        p_wi_info = (phHciNfc_WI_Info_t *)
173            psHciContext->p_wi_info ;
174        *ppipe_id =  p_wi_info->pipe_id  ;
175    }
176    else
177    {
178        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
179    }
180    return status;
181}
182
183
184NFCSTATUS
185phHciNfc_WI_Update_PipeInfo(
186                                  phHciNfc_sContext_t     *psHciContext,
187                                  uint8_t                 pipeID,
188                                  phHciNfc_Pipe_Info_t    *pPipeInfo
189                           )
190{
191    NFCSTATUS                   status = NFCSTATUS_SUCCESS;
192
193    if( NULL == psHciContext )
194    {
195        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
196    }
197    else if(NULL == psHciContext->p_wi_info)
198    {
199        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
200    }
201    else
202    {
203        phHciNfc_WI_Info_t *p_WI_info=NULL;
204        p_WI_info = (phHciNfc_WI_Info_t *)
205                                psHciContext->p_wi_info ;
206        /* Update the pipe_id of the WI Gate obtained from HCI Response */
207        p_WI_info->pipe_id = pipeID;
208        p_WI_info->p_pipe_info = pPipeInfo;
209        if ( NULL != pPipeInfo)
210        {
211            /* Update the Response Receive routine of the WI Gate */
212            pPipeInfo->recv_resp = &phHciNfc_Recv_WI_Response;
213            /* Update the event Receive routine of the WI Gate */
214            pPipeInfo->recv_event = &phHciNfc_Recv_WI_Event;
215        }
216    }
217
218    return status;
219}
220
221#if defined (WI_UPDATE_SEQ)
222static
223NFCSTATUS
224phHciNfc_WI_Update_Sequence(
225                                phHciNfc_sContext_t     *psHciContext,
226                                phHciNfc_eSeqType_t     WI_seq
227                             )
228{
229    NFCSTATUS                   status = NFCSTATUS_SUCCESS;
230    phHciNfc_WI_Info_t          *p_WI_info=NULL;
231    if( NULL == psHciContext )
232    {
233        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
234    }
235    else if ( NULL == psHciContext->p_wi_info )
236    {
237        status = PHNFCSTVAL(CID_NFC_HCI,
238                        NFCSTATUS_INVALID_HCI_INFORMATION);
239    }
240    else
241    {
242        p_WI_info = (phHciNfc_WI_Info_t *)
243                            psHciContext->p_wi_info ;
244        switch(WI_seq)
245        {
246            case RESET_SEQ:
247            case INIT_SEQ:
248            {
249                p_WI_info->current_seq = eWI_PipeOpen;
250                p_WI_info->next_seq = eWI_SetDefaultMode ;
251            }break;
252            case UPDATE_SEQ:
253            {
254                p_WI_info->current_seq = p_WI_info->next_seq;
255
256            }break;
257            case REL_SEQ:
258            {
259                p_WI_info->current_seq = eWI_PipeOpen;
260                p_WI_info->next_seq = eWI_PipeClose ;
261            }break;
262            default:
263            {
264                break;
265            }
266        }/* End of Update Sequence Switch */
267    }
268    return status;
269
270}
271#endif /* #if defined (WI_UPDATE_SEQ) */
272
273NFCSTATUS
274phHciNfc_WI_Configure_Default(
275                              void                  *psHciHandle,
276                              void                  *pHwRef,
277                              uint8_t               enable_type
278                          )
279{
280    NFCSTATUS               status = NFCSTATUS_SUCCESS;
281    static uint8_t          param = 0;
282    phHciNfc_sContext_t     *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
283
284    if( (NULL == psHciContext)||(NULL == pHwRef))
285    {
286      status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
287    }
288    else if ( NULL == psHciContext->p_wi_info )
289    {
290        status = PHNFCSTVAL(CID_NFC_HCI,
291                        NFCSTATUS_INVALID_HCI_INFORMATION);
292    }
293    else
294    {
295        phHciNfc_WI_Info_t          *p_wi_info=NULL;
296        phHciNfc_Pipe_Info_t        *p_pipe_info=NULL;
297
298        p_wi_info = (phHciNfc_WI_Info_t*)psHciContext->p_wi_info;
299
300        p_pipe_info = p_wi_info->p_pipe_info;
301        if(NULL == p_pipe_info)
302        {
303            status = PHNFCSTVAL(CID_NFC_HCI,
304                            NFCSTATUS_INVALID_HCI_INFORMATION);
305        }
306        else
307        {
308            p_pipe_info->reg_index = NXP_SE_DEFAULTMODE_INDEX;
309            /* Enable/Disable Default Virtual Mode for SmartMx */
310            param = (uint8_t)enable_type;
311            p_pipe_info->param_info =(void*)&param ;
312            p_pipe_info->param_length = sizeof(param) ;
313            status = phHciNfc_Send_Generic_Cmd(psHciContext,pHwRef,
314                                    p_wi_info->pipe_id,(uint8_t)ANY_SET_PARAMETER);
315
316        }/* End of else part*/
317    }
318    return status;
319}
320
321NFCSTATUS
322phHciNfc_WI_Get_Default(
323                              void                  *psHciHandle,
324                              void                  *pHwRef
325                              )
326{
327    NFCSTATUS               status = NFCSTATUS_SUCCESS;
328    phHciNfc_sContext_t     *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
329
330    if( (NULL == psHciContext)||(NULL == pHwRef))
331    {
332        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
333    }
334    else if ( NULL == psHciContext->p_wi_info )
335    {
336        status = PHNFCSTVAL(CID_NFC_HCI,
337                            NFCSTATUS_INVALID_HCI_INFORMATION);
338    }
339    else
340    {
341        phHciNfc_WI_Info_t          *p_wiinfo=NULL;
342        phHciNfc_Pipe_Info_t        *p_pipe_info=NULL;
343
344        p_wiinfo = (phHciNfc_WI_Info_t*)psHciContext->p_wi_info;
345
346        p_pipe_info = p_wiinfo->p_pipe_info;
347        if(NULL == p_pipe_info)
348        {
349            status = PHNFCSTVAL(CID_NFC_HCI,
350                                NFCSTATUS_INVALID_HCI_INFORMATION);
351        }
352        else
353        {
354            p_pipe_info->reg_index = NXP_SE_DEFAULTMODE_INDEX;
355
356            status = phHciNfc_Send_Generic_Cmd(psHciContext,pHwRef,
357                                            p_wiinfo->pipe_id,
358                                            (uint8_t)ANY_GET_PARAMETER);
359
360        }/* End of else part*/
361    }
362    return status;
363}
364
365
366NFCSTATUS
367phHciNfc_WI_Configure_Mode(
368                              void                *psHciHandle,
369                              void                *pHwRef,
370                              phHal_eSmartMX_Mode_t   e_smx_mode
371                          )
372{
373    NFCSTATUS               status = NFCSTATUS_SUCCESS;
374    static uint8_t          param = 0;
375    phHciNfc_sContext_t     *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
376
377    if( (NULL == psHciContext)||(NULL == pHwRef))
378    {
379      status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
380    }
381    else if ( NULL == psHciContext->p_wi_info )
382    {
383        status = PHNFCSTVAL(CID_NFC_HCI,
384                        NFCSTATUS_INVALID_HCI_INFORMATION);
385    }
386    else
387    {
388        phHciNfc_WI_Info_t          *p_wi_info=NULL;
389        phHciNfc_Pipe_Info_t        *p_pipe_info=NULL;
390
391        p_wi_info = (phHciNfc_WI_Info_t*)psHciContext->p_wi_info;
392
393        p_pipe_info = p_wi_info->p_pipe_info;
394        if(NULL == p_pipe_info)
395        {
396            status = PHNFCSTVAL(CID_NFC_HCI,
397                            NFCSTATUS_INVALID_HCI_INFORMATION);
398        }
399        else
400        {
401            /* Switch the Mode of the SmartMx */
402            param = (uint8_t)e_smx_mode;
403            p_pipe_info->param_info =(void*)&param ;
404            p_pipe_info->param_length = sizeof(param) ;
405            status = phHciNfc_Send_WI_Event( psHciContext, pHwRef,
406                                p_wi_info->pipe_id, NXP_EVT_SE_SWITCH_MODE );
407            /* Send the Success Status as this is an event */
408            status = ( (status == NFCSTATUS_PENDING)?
409                                NFCSTATUS_SUCCESS : status);
410
411        }/* End of else part*/
412    }
413    return status;
414}
415
416
417NFCSTATUS
418phHciNfc_WI_Configure_Notifications(
419                                    void        *psHciHandle,
420                                    void        *pHwRef,
421                                    phHciNfc_WI_Events_t eNotification
422                                )
423{
424    NFCSTATUS               status = NFCSTATUS_SUCCESS;
425    static uint8_t          param = 0;
426    phHciNfc_sContext_t     *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
427
428    if( (NULL == psHciContext)||(NULL == pHwRef))
429    {
430      status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
431    }
432    else if ( NULL == psHciContext->p_wi_info )
433    {
434        status = PHNFCSTVAL(CID_NFC_HCI,
435                        NFCSTATUS_INVALID_HCI_INFORMATION);
436    }
437    else
438    {
439        phHciNfc_WI_Info_t          *p_wi_info=NULL;
440        phHciNfc_Pipe_Info_t        *p_pipe_info=NULL;
441
442
443        p_wi_info = (phHciNfc_WI_Info_t*)psHciContext->p_wi_info;
444        p_pipe_info = p_wi_info->p_pipe_info;
445        if(NULL == p_pipe_info)
446        {
447            status = PHNFCSTVAL(CID_NFC_HCI,
448                                NFCSTATUS_INVALID_HCI_INFORMATION);
449        }
450        else
451        {
452            if(eEnableEvents == eNotification)
453            {
454                /* Enable start and end of transaction events*/
455                param = WI_ENABLE_EVENTS;
456            }
457            else
458            {
459                /* Disable Events*/
460                param = FALSE ;
461            }
462            p_pipe_info->reg_index = NXP_SE_EVENTS_INDEX;
463            p_pipe_info->param_info =(void*)&param ;
464            p_pipe_info->param_length = sizeof(param) ;
465
466            status = phHciNfc_Send_Generic_Cmd(psHciContext,pHwRef,
467            p_wi_info->pipe_id,(uint8_t)ANY_SET_PARAMETER);
468        }
469    }
470    return status;
471}
472
473
474/*!
475* \brief Sends WI gate specfic HCI Events to the connected reader device.
476* This function Sends the WI mode specific HCI Event frames in the HCP packet format to the
477* connected reader device.
478*/
479
480static
481NFCSTATUS
482phHciNfc_Send_WI_Event(
483                       phHciNfc_sContext_t      *psHciContext,
484                       void                     *pHwRef,
485                       uint8_t                  pipe_id,
486                       uint8_t                  event
487                       )
488{
489    phHciNfc_HCP_Packet_t   *hcp_packet = NULL;
490    phHciNfc_HCP_Message_t  *hcp_message = NULL;
491    phHciNfc_Pipe_Info_t    *p_pipe_info = NULL;
492    uint8_t                 length = 0;
493    uint8_t                 i=0;
494    NFCSTATUS               status = NFCSTATUS_SUCCESS;
495
496    if( (NULL == psHciContext)
497        || ( pipe_id > PHHCINFC_MAX_PIPE)
498        ||(NULL == psHciContext->p_pipe_list[pipe_id])
499        )
500    {
501        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
502        HCI_DEBUG("%s: Invalid Arguments passed \n",
503            "phHciNfc_Send_WI_Event");
504    }
505    else
506    {
507        p_pipe_info = (phHciNfc_Pipe_Info_t *)
508            psHciContext->p_pipe_list[pipe_id];
509        psHciContext->tx_total = 0 ;
510        length =length+HCP_HEADER_LEN ;
511
512        if( NXP_EVT_SE_SWITCH_MODE == event)
513        {
514            hcp_packet = (phHciNfc_HCP_Packet_t *) psHciContext->send_buffer;
515            /* Construct the HCP Frame */
516            phHciNfc_Build_HCPFrame(hcp_packet,HCP_CHAINBIT_DEFAULT,
517                                    (uint8_t) pipe_id, HCP_MSG_TYPE_EVENT, event);
518            hcp_message = &(hcp_packet->msg.message);
519            phHciNfc_Append_HCPFrame((uint8_t *)hcp_message->payload,
520                                            i, (uint8_t *)p_pipe_info->param_info,
521                                            p_pipe_info->param_length);
522            length =(uint8_t)(length + i + p_pipe_info->param_length);
523        }
524        else
525        {
526            status = PHNFCSTVAL( CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INSTRUCTION );
527            HCI_DEBUG("%s: Invalid Send Event Request \n","phHciNfc_Send_WI_Event");
528        }
529
530        if( NFCSTATUS_SUCCESS == status )
531        {
532            p_pipe_info->sent_msg_type = HCP_MSG_TYPE_EVENT ;
533            p_pipe_info->prev_msg = event ;
534            psHciContext->tx_total = length;
535
536            /* Send the Constructed HCP packet to the lower layer */
537            status = phHciNfc_Send_HCP( psHciContext, pHwRef );
538            p_pipe_info->prev_status = NFCSTATUS_PENDING;
539        }
540    }
541    return status;
542}
543
544static
545NFCSTATUS
546phHciNfc_Recv_WI_Response(
547                          void                *psContext,
548                          void                *pHwRef,
549                          uint8_t             *pResponse,
550#ifdef ONE_BYTE_LEN
551                          uint8_t             length
552#else
553                          uint16_t            length
554#endif
555                          )
556{
557    NFCSTATUS                   status = NFCSTATUS_SUCCESS;
558    phHciNfc_sContext_t         *psHciContext =
559                                (phHciNfc_sContext_t *)psContext;
560
561
562    if( (NULL == psHciContext) || (NULL == pHwRef) || (NULL == pResponse)
563        || (length == 0))
564    {
565        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
566    }
567    else if(NULL == psHciContext->p_wi_info)
568    {
569        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
570    }
571    else
572    {
573        phHciNfc_WI_Info_t     *p_wiinfo=NULL;
574        uint8_t                 prev_cmd = ANY_GET_PARAMETER;
575        p_wiinfo = (phHciNfc_WI_Info_t *)psHciContext->p_wi_info ;
576
577        if( NULL == p_wiinfo->p_pipe_info)
578        {
579            status = PHNFCSTVAL(CID_NFC_HCI,
580                NFCSTATUS_INVALID_HCI_INFORMATION);
581        }
582        else
583        {
584            prev_cmd = p_wiinfo->p_pipe_info->prev_msg ;
585            switch(prev_cmd)
586            {
587                case ANY_GET_PARAMETER:
588                {
589                    if (length > HCP_HEADER_LEN)
590                    {
591                        status = phHciNfc_WI_InfoUpdate (psHciContext,
592                                        p_wiinfo->p_pipe_info->reg_index,
593                                        &pResponse[HCP_HEADER_LEN],
594                                        (uint8_t)(length - HCP_HEADER_LEN));
595                    }
596                    else
597                    {
598                        status = PHNFCSTVAL(CID_NFC_HCI,
599                                            NFCSTATUS_INVALID_HCI_RESPONSE);
600                    }
601                    break;
602                }
603                case ANY_SET_PARAMETER:
604                {
605                    HCI_PRINT("WI Parameter Set \n");
606                    status = phHciNfc_EmuMgmt_Update_Seq(psHciContext,
607                                                        UPDATE_SEQ);
608                    break;
609                }
610                case ANY_OPEN_PIPE:
611                {
612                    HCI_PRINT("WI gate open pipe complete\n");
613                    status = phHciNfc_EmuMgmt_Update_Seq(psHciContext,
614                                                        UPDATE_SEQ);
615                    break;
616                }
617                case ANY_CLOSE_PIPE:
618                {
619                    HCI_PRINT("WI close pipe complete\n");
620                    status = phHciNfc_EmuMgmt_Update_Seq(psHciContext,
621                                                        UPDATE_SEQ);
622                    break;
623                }
624                default:
625                {
626                    status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_RESPONSE);
627                    break;
628                }
629            }
630            if( NFCSTATUS_SUCCESS == status )
631            {
632                p_wiinfo->p_pipe_info->prev_status = NFCSTATUS_SUCCESS;
633                p_wiinfo->current_seq = p_wiinfo->next_seq;
634            }
635        }
636    }
637    return status;
638}
639
640static
641NFCSTATUS
642phHciNfc_Recv_WI_Event(
643                       void               *psContext,
644                       void               *pHwRef,
645                       uint8_t            *pEvent,
646#ifdef ONE_BYTE_LEN
647                       uint8_t             length
648#else
649                       uint16_t            length
650#endif
651                       )
652{
653    NFCSTATUS                   status = NFCSTATUS_SUCCESS;
654    phHal_sEventInfo_t          EventInfo;
655    /* phNfc_sNotificationInfo_t   NotificationInfo; */
656    phHciNfc_sContext_t         *psHciContext =(phHciNfc_sContext_t *)psContext;
657
658
659    if( (NULL == psHciContext) || (NULL == pHwRef) || (NULL == pEvent)
660        || (length == 0))
661    {
662        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
663    }
664    else if(NULL == psHciContext->p_wi_info)
665    {
666        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION);
667    }
668    else
669    {
670        phHciNfc_HCP_Packet_t       *p_packet = NULL;
671        phHciNfc_HCP_Message_t      *message = NULL;
672        phHciNfc_WI_Info_t          *p_wi_info = NULL;
673        uint8_t                     EventType = 0;
674
675        p_wi_info = (phHciNfc_WI_Info_t *)psHciContext->p_wi_info ;
676
677        p_packet = (phHciNfc_HCP_Packet_t *)pEvent;
678        message = &(p_packet->msg.message);
679        /* Get the instruction bits from the Message Header */
680        EventType = (uint8_t) GET_BITS8( message->msg_header,
681            HCP_MSG_INSTRUCTION_OFFSET, HCP_MSG_INSTRUCTION_LEN);
682
683        EventInfo.eventHost = phHal_eHostController;
684        EventInfo.eventSource = phHal_ePICC_DevType;
685        /* Now check for possible Transaction events for reporting */
686        switch(EventType)
687        {
688            case NXP_EVT_SE_START_OF_TRANSACTION:
689            {
690                EventInfo.eventType = NFC_EVT_START_OF_TRANSACTION;
691                break;
692            }
693            case NXP_EVT_SE_END_OF_TRANSACTION:
694            {
695                EventInfo.eventType = NFC_EVT_END_OF_TRANSACTION;
696                break;
697            }
698            case NXP_EVT_SE_TRANSACTION:
699            {
700                EventInfo.eventType = NFC_EVT_TRANSACTION;
701                EventInfo.eventInfo.aid.buffer = (uint8_t *)p_wi_info->aid;
702                /* check for AID data is at least 1 byte is their */
703                if(length > HCP_HEADER_LEN)
704                {
705                    EventInfo.eventInfo.aid.length = length - HCP_HEADER_LEN;
706                    (void) memcpy((void *)p_wi_info->aid,message->payload,
707                                    EventInfo.eventInfo.aid.length );
708                }
709                break;
710            }
711            default:
712            {
713                status = PHNFCSTVAL(CID_NFC_HCI,
714                                NFCSTATUS_INVALID_HCI_INSTRUCTION);
715                break;
716            }
717        }
718        if (NFCSTATUS_SUCCESS == status )
719        {
720            phHciNfc_Notify_Event(  psHciContext, pHwRef,
721            NFC_NOTIFY_EVENT, (void*)&EventInfo);
722        }
723    }
724    return status;
725}
726
727static
728NFCSTATUS
729phHciNfc_WI_InfoUpdate(
730                       phHciNfc_sContext_t     *psHciContext,
731                       uint8_t                 index,
732                       uint8_t                 *reg_value,
733                       uint8_t                 reg_length
734                       )
735{
736    NFCSTATUS               status = NFCSTATUS_SUCCESS;
737    phHciNfc_WI_Info_t      *p_wiinfo = NULL;
738
739    p_wiinfo = psHciContext->p_wi_info;
740
741    if ((NXP_SE_DEFAULTMODE_INDEX == index) &&
742        (sizeof(*reg_value) == reg_length))
743    {
744        p_wiinfo->default_type = *reg_value;
745    }
746    else
747    {
748        status = PHNFCSTVAL(CID_NFC_HCI,
749                            NFCSTATUS_INVALID_HCI_RESPONSE);
750    }
751
752    return status;
753}
754
755