• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_CEA.c                                                       *
22 * \brief HCI card emulation A management routines.                            *
23 *                                                                             *
24 *                                                                             *
25 * Project: NFC-FRI-1.1                                                        *
26 *                                                                             *
27 * $Date: Fri Aug 21 18:35:05 2009 $                                           *
28 * $Author: ing04880 $                                                         *
29 * $Revision: 1.13 $                                                           *
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 /*
36 ***************************** Header File Inclusion ****************************
37 */
38 #include <phNfcCompId.h>
39 #include <phNfcHalTypes.h>
40 #include <phHciNfc_Pipe.h>
41 #include <phHciNfc_Emulation.h>
42 #include <phOsalNfc.h>
43 /*
44 ****************************** Macro Definitions *******************************
45 */
46 #if defined (HOST_EMULATION)
47 #include <phHciNfc_CE_B.h>
48 
49 #define CE_B_EVT_NFC_SEND_DATA               0x10U
50 #define CE_B_EVT_NFC_FIELD_ON                0x11U
51 #define CE_B_EVT_NFC_DEACTIVATED             0x12U
52 #define CE_B_EVT_NFC_ACTIVATED               0x13U
53 #define CE_B_EVT_NFC_FIELD_OFF               0x14U
54 
55 /*
56 *************************** Structure and Enumeration ***************************
57 */
58 
59 
60 /*
61 *************************** Static Function Declaration **************************
62 */
63 
64 static
65 NFCSTATUS
66 phHciNfc_Recv_CE_B_Event(
67                              void               *psContext,
68                              void               *pHwRef,
69                              uint8_t            *pEvent,
70 #ifdef ONE_BYTE_LEN
71                              uint8_t            length
72 #else
73                              uint16_t           length
74 #endif
75                        );
76 
77 static
78 NFCSTATUS
79 phHciNfc_Recv_CE_B_Response(
80                              void               *psContext,
81                              void               *pHwRef,
82                              uint8_t            *pResponse,
83 #ifdef ONE_BYTE_LEN
84                              uint8_t            length
85 #else
86                              uint16_t           length
87 #endif
88                        );
89 
90 #if defined (SEND_DATA_EVENT)
91 static
92 NFCSTATUS
93 phHciNfc_CE_B_ProcessData(
94                             phHciNfc_sContext_t     *psHciContext,
95                             void                    *pHwRef,
96                             uint8_t                 *pData,
97                             uint8_t                 length
98                        );
99 #endif /* #if defined (SEND_DATA_EVENT) */
100 
101 /*
102 *************************** Function Definitions ***************************
103 */
104 NFCSTATUS
phHciNfc_CE_B_Init_Resources(phHciNfc_sContext_t * psHciContext)105 phHciNfc_CE_B_Init_Resources(
106                                 phHciNfc_sContext_t     *psHciContext
107                          )
108 {
109     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
110     phHciNfc_CE_B_Info_t        *ps_ce_b_info = NULL;
111     if( NULL == psHciContext )
112     {
113         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
114     }
115     else
116     {
117         if(
118             ( NULL == psHciContext->p_ce_b_info ) &&
119              (phHciNfc_Allocate_Resource((void **)(&ps_ce_b_info),
120             sizeof(phHciNfc_CE_B_Info_t))== NFCSTATUS_SUCCESS)
121           )
122         {
123             psHciContext->p_ce_b_info = ps_ce_b_info;
124             ps_ce_b_info->current_seq = HOST_CE_B_INVALID_SEQ;
125             ps_ce_b_info->next_seq = HOST_CE_B_INVALID_SEQ;
126             ps_ce_b_info->pipe_id = (uint8_t)HCI_UNKNOWN_PIPE_ID;
127         }
128         else
129         {
130             status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INSUFFICIENT_RESOURCES);
131         }
132 
133     }
134     return status;
135 }
136 
137 NFCSTATUS
phHciNfc_CE_B_Initialise(phHciNfc_sContext_t * psHciContext,void * pHwRef)138 phHciNfc_CE_B_Initialise(
139                         phHciNfc_sContext_t     *psHciContext,
140                         void                    *pHwRef
141                         )
142 {
143     NFCSTATUS           status = NFCSTATUS_SUCCESS;
144     static uint8_t      pupi[] = {0, 0, 0, 0};
145     static uint8_t      atqb_info[] = {0x04, 0x00};
146 
147     if ((NULL == psHciContext) || (NULL == pHwRef))
148     {
149         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
150     }
151     else if(NULL == psHciContext->p_ce_b_info)
152     {
153         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
154     }
155     else
156     {
157         phHciNfc_CE_B_Info_t        *ps_ce_b_info = ((phHciNfc_CE_B_Info_t *)
158                                                 psHciContext->p_ce_b_info );
159         phHciNfc_Pipe_Info_t        *ps_pipe_info = NULL;
160 
161         ps_pipe_info =  ps_ce_b_info->p_pipe_info;
162         if(NULL == ps_pipe_info )
163         {
164             status = PHNFCSTVAL(CID_NFC_HCI,
165                                 NFCSTATUS_INVALID_HCI_INFORMATION);
166         }
167         else
168         {
169             switch(ps_ce_b_info->current_seq)
170             {
171                 case HOST_CE_B_PIPE_OPEN:
172                 {
173                     status = phHciNfc_Open_Pipe( psHciContext,
174                                                 pHwRef, ps_pipe_info );
175                     if(status == NFCSTATUS_SUCCESS)
176                     {
177 #if defined (CE_B_CONTINUE_SEQ)
178                         ps_ce_b_info->next_seq = HOST_CE_B_PUPI_SEQ;
179 #else
180                         ps_ce_b_info->next_seq = HOST_CE_B_ENABLE_SEQ;
181 #endif /* #if defined (CE_CONTINUE_SEQ) */
182                         status = NFCSTATUS_PENDING;
183                     }
184                     break;
185                 }
186                 case HOST_CE_B_PUPI_SEQ:
187                 {
188                     /* HOST Card Emulation B PUPI Configuration */
189                     ps_pipe_info->reg_index = HOST_CE_B_ATQB_INDEX;
190 
191                     ps_pipe_info->param_info =(void*)&pupi ;
192                     ps_pipe_info->param_length = sizeof(pupi) ;
193                     status = phHciNfc_Send_Generic_Cmd(psHciContext,pHwRef,
194                                                 ps_pipe_info->pipe.pipe_id,
195                                                 (uint8_t)ANY_SET_PARAMETER);
196                     if(status == NFCSTATUS_PENDING)
197                     {
198                         ps_ce_b_info->next_seq = HOST_CE_B_ATQB_SEQ;
199                     }
200                     break;
201                 }
202                 case HOST_CE_B_ATQB_SEQ:
203                 {
204                     /* HOST Card Emulation B ATQB Configuration */
205                     ps_pipe_info->reg_index = HOST_CE_B_ATQB_INDEX;
206                     /* Configure the ATQA of Host Card Emulation B */
207                     ps_pipe_info->param_info = (void*)atqb_info ;
208                     ps_pipe_info->param_length = sizeof(atqb_info) ;
209                     status = phHciNfc_Send_Generic_Cmd(psHciContext,pHwRef,
210                                                 ps_pipe_info->pipe.pipe_id,
211                                                 (uint8_t)ANY_SET_PARAMETER);
212                     if(status == NFCSTATUS_PENDING)
213                     {
214                         ps_ce_b_info->next_seq = HOST_CE_B_ENABLE_SEQ;
215                     }
216                     break;
217                 }
218                 case HOST_CE_B_ENABLE_SEQ:
219                 {
220                     status = phHciNfc_CE_B_Mode( psHciContext,
221                                             pHwRef, HOST_CE_MODE_ENABLE );
222                     if(status == NFCSTATUS_PENDING)
223                     {
224                         ps_ce_b_info->next_seq = HOST_CE_B_DISABLE_SEQ;
225                         status = NFCSTATUS_SUCCESS;
226                     }
227                     break;
228                 }
229                 default :
230                 {
231                     break;
232                 }
233             }
234         }
235     }
236 
237     return status;
238 }
239 
240 NFCSTATUS
phHciNfc_CE_B_Release(phHciNfc_sContext_t * psHciContext,void * pHwRef)241 phHciNfc_CE_B_Release(
242                         phHciNfc_sContext_t     *psHciContext,
243                         void                    *pHwRef
244                         )
245 {
246     NFCSTATUS       status = NFCSTATUS_SUCCESS;
247     if ((NULL == psHciContext) || (NULL == pHwRef))
248     {
249         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
250     }
251     else if(NULL == psHciContext->p_ce_b_info)
252     {
253         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
254     }
255     else
256     {
257         phHciNfc_CE_B_Info_t        *ps_ce_b_info = ((phHciNfc_CE_B_Info_t *)
258                                                 psHciContext->p_ce_b_info );
259         phHciNfc_Pipe_Info_t        *ps_pipe_info = NULL;
260 
261         ps_pipe_info =  ps_ce_b_info->p_pipe_info;
262         if(NULL == ps_pipe_info )
263         {
264             status = PHNFCSTVAL(CID_NFC_HCI,
265                                 NFCSTATUS_INVALID_HCI_INFORMATION);
266         }
267         else
268         {
269             switch(ps_ce_b_info->current_seq)
270             {
271                 case HOST_CE_B_DISABLE_SEQ:
272                 {
273                     status = phHciNfc_CE_B_Mode( psHciContext,
274                                             pHwRef,  HOST_CE_MODE_DISABLE );
275                     if(status == NFCSTATUS_PENDING)
276                     {
277                         ps_ce_b_info->next_seq = HOST_CE_B_PIPE_CLOSE;
278                     }
279                     break;
280                 }
281                 case HOST_CE_B_PIPE_CLOSE:
282                 {
283                     /* HOST Card Emulation B pipe close sequence */
284                     status = phHciNfc_Close_Pipe( psHciContext,
285                                                 pHwRef, ps_pipe_info );
286                     if(status == NFCSTATUS_SUCCESS)
287                     {
288                         ps_ce_b_info->next_seq = HOST_CE_B_PIPE_DELETE;
289                         status = NFCSTATUS_PENDING;
290                     }
291                     break;
292                 }
293                 case HOST_CE_B_PIPE_DELETE:
294                 {
295                     /* HOST Card Emulation A pipe delete sequence */
296                     status = phHciNfc_Delete_Pipe( psHciContext,
297                                                 pHwRef, ps_pipe_info );
298                     if(status == NFCSTATUS_SUCCESS)
299                     {
300 #if 0
301                         ps_ce_b_info->pipe_id = HCI_UNKNOWN_PIPE_ID;
302                         psHciContext->p_pipe_list[ps_ce_b_info->pipe_id] = NULL;
303                         phOsalNfc_FreeMemory((void *)ps_ce_b_info->p_pipe_info);
304                         ps_ce_b_info->p_pipe_info = NULL;
305 #endif
306                         ps_ce_b_info->next_seq = HOST_CE_B_PIPE_OPEN;
307                     }
308                     break;
309                 }
310                 default :
311                 {
312                     break;
313                 }
314             }
315         }
316     }
317     return status;
318 }
319 
320 
321 
322 NFCSTATUS
phHciNfc_CE_B_Mode(void * psHciHandle,void * pHwRef,uint8_t enable_type)323 phHciNfc_CE_B_Mode(
324                             void        *psHciHandle,
325                             void        *pHwRef,
326                             uint8_t     enable_type
327                   )
328 {
329     NFCSTATUS               status = NFCSTATUS_SUCCESS;
330     static uint8_t          param = 0 ;
331     phHciNfc_sContext_t     *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
332 
333     if((NULL == psHciContext)||(NULL == pHwRef))
334     {
335         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
336     }
337     else if(NULL == psHciContext->p_ce_b_info)
338     {
339         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
340     }
341     else
342     {
343         phHciNfc_CE_B_Info_t     *ps_ce_b_info = (phHciNfc_CE_B_Info_t *)
344                                                 psHciContext->p_ce_b_info ;
345         phHciNfc_Pipe_Info_t     *ps_pipe_info = ps_ce_b_info->p_pipe_info;
346 
347         if (NULL != ps_pipe_info)
348         {
349             ps_pipe_info->reg_index = HOST_CE_B_MODE_INDEX;
350             /* Enable/Disable Host Card Emulation A */
351             param = (uint8_t)enable_type;
352             ps_pipe_info->param_info =(void*)&param ;
353             ps_pipe_info->param_length = sizeof(param) ;
354             status = phHciNfc_Send_Generic_Cmd(psHciContext,pHwRef,
355                                     ps_ce_b_info->pipe_id,(uint8_t)ANY_SET_PARAMETER);
356         }
357         else
358         {
359             status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_HCI_GATE_NOT_SUPPORTED);
360         }
361     }
362     return status;
363 }
364 
365 
366 
367 NFCSTATUS
phHciNfc_CE_B_Get_PipeID(phHciNfc_sContext_t * psHciContext,uint8_t * ppipe_id)368 phHciNfc_CE_B_Get_PipeID(
369                              phHciNfc_sContext_t        *psHciContext,
370                              uint8_t                    *ppipe_id
371                              )
372 {
373     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
374 
375     if( (NULL != psHciContext)
376         && ( NULL != ppipe_id )
377         && ( NULL != psHciContext->p_ce_b_info )
378         )
379     {
380         phHciNfc_CE_B_Info_t     *ps_ce_b_info=NULL;
381         ps_ce_b_info = (phHciNfc_CE_B_Info_t *)
382                         psHciContext->p_ce_b_info ;
383         *ppipe_id =  ps_ce_b_info->pipe_id  ;
384     }
385     else
386     {
387         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
388     }
389     return status;
390 }
391 
392 NFCSTATUS
phHciNfc_CE_B_Update_PipeInfo(phHciNfc_sContext_t * psHciContext,uint8_t pipeID,phHciNfc_Pipe_Info_t * pPipeInfo)393 phHciNfc_CE_B_Update_PipeInfo(
394                                   phHciNfc_sContext_t     *psHciContext,
395                                   uint8_t                 pipeID,
396                                   phHciNfc_Pipe_Info_t    *pPipeInfo
397                                   )
398 {
399     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
400 
401     if( NULL == psHciContext )
402     {
403         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
404     }
405     else if(NULL == psHciContext->p_ce_b_info)
406     {
407         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
408     }
409     else
410     {
411         phHciNfc_CE_B_Info_t         *ps_ce_b_info=NULL;
412         ps_ce_b_info = (phHciNfc_CE_B_Info_t *)
413                         psHciContext->p_ce_b_info ;
414 
415         ps_ce_b_info->current_seq = HOST_CE_B_PIPE_OPEN;
416         ps_ce_b_info->next_seq = HOST_CE_B_PIPE_OPEN;
417         /* Update the pipe_id of the card emulation A Gate o
418             btained from the HCI Response */
419         ps_ce_b_info->pipe_id = pipeID;
420         if (HCI_UNKNOWN_PIPE_ID != pipeID)
421         {
422             ps_ce_b_info->p_pipe_info = pPipeInfo;
423             if (NULL != pPipeInfo)
424             {
425                 /* Update the Response Receive routine of the card
426                     emulation A Gate */
427                 pPipeInfo->recv_resp = &phHciNfc_Recv_CE_B_Response;
428                 /* Update the event Receive routine of the card emulation A Gate */
429                 pPipeInfo->recv_event = &phHciNfc_Recv_CE_B_Event;
430             }
431         }
432         else
433         {
434             ps_ce_b_info->p_pipe_info = NULL;
435         }
436     }
437 
438     return status;
439 }
440 
441 #ifdef CE_B_SEND_EVENT
442 NFCSTATUS
phHciNfc_CE_B_SendData_Event(void * psContext,void * pHwRef,uint8_t * pEvent,uint8_t length)443 phHciNfc_CE_B_SendData_Event(
444                              void               *psContext,
445                              void               *pHwRef,
446                              uint8_t            *pEvent,
447                              uint8_t            length
448                        )
449 {
450     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
451     phHciNfc_sContext_t         *psHciContext =
452                                 (phHciNfc_sContext_t *)psContext ;
453     return status;
454 }
455 #endif /* #ifdef CE_B_SEND_EVENT */
456 
457 static
458 NFCSTATUS
phHciNfc_Recv_CE_B_Response(void * psContext,void * pHwRef,uint8_t * pResponse,uint8_t length)459 phHciNfc_Recv_CE_B_Response(
460                              void               *psContext,
461                              void               *pHwRef,
462                              uint8_t            *pResponse,
463 #ifdef ONE_BYTE_LEN
464                              uint8_t            length
465 #else
466                              uint16_t           length
467 #endif
468                        )
469 {
470     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
471     phHciNfc_sContext_t         *psHciContext =
472                                 (phHciNfc_sContext_t *)psContext ;
473     if( (NULL == psHciContext) || (NULL == pHwRef) || (NULL == pResponse)
474         || (length == 0))
475     {
476         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
477     }
478     else if(NULL == psHciContext->p_ce_b_info)
479     {
480         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
481     }
482     else
483     {
484         phHciNfc_CE_B_Info_t         *ps_ce_b_info=NULL;
485         uint8_t                     prev_cmd = ANY_GET_PARAMETER;
486         ps_ce_b_info = (phHciNfc_CE_B_Info_t *)
487                             psHciContext->p_ce_b_info ;
488         if( NULL == ps_ce_b_info->p_pipe_info)
489         {
490             status = PHNFCSTVAL(CID_NFC_HCI,
491                             NFCSTATUS_INVALID_HCI_SEQUENCE);
492         }
493         else
494         {
495             prev_cmd = ps_ce_b_info->p_pipe_info->prev_msg ;
496             switch(prev_cmd)
497             {
498                 case ANY_GET_PARAMETER:
499                 {
500 #if 0
501                     status = phHciNfc_CE_B_InfoUpdate(psHciContext,
502                                     ps_ce_b_info->p_pipe_info->reg_index,
503                                     &pResponse[HCP_HEADER_LEN],
504                                     (length - HCP_HEADER_LEN));
505 #endif /* #if 0 */
506                     break;
507                 }
508                 case ANY_SET_PARAMETER:
509                 {
510                     HCI_PRINT("CE B Parameter Set \n");
511                     break;
512                 }
513                 case ANY_OPEN_PIPE:
514                 {
515                     HCI_PRINT("CE B open pipe complete\n");
516                     break;
517                 }
518                 case ANY_CLOSE_PIPE:
519                 {
520                     HCI_PRINT("CE B close pipe complete\n");
521                     break;
522                 }
523                 default:
524                 {
525                     status = PHNFCSTVAL(CID_NFC_HCI,
526                                         NFCSTATUS_INVALID_HCI_RESPONSE);
527                     break;
528                 }
529             }
530             if( NFCSTATUS_SUCCESS == status )
531             {
532                 status = phHciNfc_CE_B_Update_Seq(psHciContext,
533                                                     UPDATE_SEQ);
534                 ps_ce_b_info->p_pipe_info->prev_status = NFCSTATUS_SUCCESS;
535             }
536         }
537     }
538     return status;
539 }
540 
541 NFCSTATUS
phHciNfc_CE_B_Update_Seq(phHciNfc_sContext_t * psHciContext,phHciNfc_eSeqType_t seq_type)542 phHciNfc_CE_B_Update_Seq(
543                         phHciNfc_sContext_t     *psHciContext,
544                         phHciNfc_eSeqType_t     seq_type
545                     )
546 {
547     phHciNfc_CE_B_Info_t    *ps_ce_b_info=NULL;
548     NFCSTATUS               status = NFCSTATUS_SUCCESS;
549 
550     if( NULL == psHciContext )
551     {
552         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
553     }
554     else if( NULL == psHciContext->p_ce_b_info )
555     {
556         status = PHNFCSTVAL(CID_NFC_HCI,
557                             NFCSTATUS_FEATURE_NOT_SUPPORTED);
558     }
559     else
560     {
561         ps_ce_b_info = (phHciNfc_CE_B_Info_t *)
562                         psHciContext->p_ce_b_info ;
563         switch(seq_type)
564         {
565             case RESET_SEQ:
566             case INIT_SEQ:
567             {
568                 ps_ce_b_info->next_seq = HOST_CE_B_PIPE_OPEN;
569                 ps_ce_b_info->current_seq = HOST_CE_B_PIPE_OPEN;
570                 break;
571             }
572             case UPDATE_SEQ:
573             {
574                 ps_ce_b_info->current_seq = ps_ce_b_info->next_seq;
575                 break;
576             }
577             case INFO_SEQ:
578             {
579                 break;
580             }
581             case REL_SEQ:
582             {
583                 ps_ce_b_info->next_seq = HOST_CE_B_DISABLE_SEQ;
584                 ps_ce_b_info->current_seq = HOST_CE_B_DISABLE_SEQ;
585                 break;
586             }
587             default:
588             {
589                 break;
590             }
591         }
592     }
593     return status;
594 }
595 
596 
597 static
598 NFCSTATUS
phHciNfc_Recv_CE_B_Event(void * psContext,void * pHwRef,uint8_t * pEvent,uint8_t length)599 phHciNfc_Recv_CE_B_Event(
600                              void               *psContext,
601                              void               *pHwRef,
602                              uint8_t            *pEvent,
603 #ifdef ONE_BYTE_LEN
604                              uint8_t            length
605 #else
606                              uint16_t           length
607 #endif
608                        )
609 {
610     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
611     phHciNfc_sContext_t         *psHciContext =
612                                 (phHciNfc_sContext_t *)psContext ;
613     if( (NULL == psHciContext) || (NULL == pHwRef) || (NULL == pEvent)
614         || (length == 0))
615     {
616         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
617     }
618     else if(NULL == psHciContext->p_ce_b_info)
619     {
620         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
621     }
622     else
623     {
624         phHciNfc_HCP_Packet_t       *p_packet = NULL;
625         phHciNfc_CE_B_Info_t         *ps_ce_b_info=NULL;
626         phHciNfc_HCP_Message_t      *message = NULL;
627         static phHal_sEventInfo_t   event_info;
628         uint8_t                     instruction=0;
629 
630         ps_ce_b_info = (phHciNfc_CE_B_Info_t *)
631                         psHciContext->p_ce_b_info ;
632 
633         /* Variable was set but never used (ARM warning) */
634         PHNFC_UNUSED_VARIABLE(ps_ce_b_info);
635 
636         p_packet = (phHciNfc_HCP_Packet_t *)pEvent;
637         message = &p_packet->msg.message;
638         /* Get the instruction bits from the Message Header */
639         instruction = (uint8_t) GET_BITS8( message->msg_header,
640                                 HCP_MSG_INSTRUCTION_OFFSET,
641                                 HCP_MSG_INSTRUCTION_LEN);
642         psHciContext->host_rf_type = phHal_eISO14443_B_PICC;
643         event_info.eventHost = phHal_eHostController;
644         event_info.eventSource = phHal_eISO14443_B_PICC;
645         switch(instruction)
646         {
647             case CE_B_EVT_NFC_ACTIVATED:
648             {
649                 event_info.eventType = NFC_EVT_ACTIVATED;
650                 /* Notify to the HCI Generic layer To Update the FSM */
651                 break;
652             }
653             case CE_B_EVT_NFC_DEACTIVATED:
654             {
655                 event_info.eventType = NFC_EVT_DEACTIVATED;
656                 HCI_PRINT("CE B Target Deactivated\n");
657                 break;
658             }
659             case CE_B_EVT_NFC_SEND_DATA:
660             {
661 #if defined (SEND_DATA_EVENT)
662                 HCI_PRINT("CE B data is received from the PN544\n");
663                 if(length > HCP_HEADER_LEN)
664                 {
665                     status = phHciNfc_CE_B_ProcessData(
666                                             psHciContext, pHwRef,
667                                             &pEvent[HCP_HEADER_LEN],
668                                             (length - HCP_HEADER_LEN));
669                 }
670                 else
671                 {
672                     status = PHNFCSTVAL(CID_NFC_HCI,
673                                         NFCSTATUS_INVALID_HCI_RESPONSE);
674                 }
675 #endif /* #if defined (SEND_DATA_EVENT) */
676                 break;
677             }
678             case CE_B_EVT_NFC_FIELD_ON:
679             {
680                 HCI_PRINT("CE B field on\n");
681                 event_info.eventType = NFC_EVT_FIELD_ON;
682                 break;
683             }
684             case CE_B_EVT_NFC_FIELD_OFF:
685             {
686                 HCI_PRINT("CE B field off\n");
687                 event_info.eventType = NFC_EVT_FIELD_OFF;
688                 break;
689             }
690             default:
691             {
692                 status = PHNFCSTVAL(CID_NFC_HCI,
693                                     NFCSTATUS_INVALID_HCI_INSTRUCTION);
694                 break;
695             }
696         }
697         if(NFCSTATUS_SUCCESS == status)
698         {
699             phHciNfc_Notify_Event(psHciContext, pHwRef,
700                                     NFC_NOTIFY_EVENT,
701                                     &event_info);
702         }
703     }
704     return status;
705 }
706 
707 #if defined (SEND_DATA_EVENT)
708 static
709 NFCSTATUS
phHciNfc_CE_B_ProcessData(phHciNfc_sContext_t * psHciContext,void * pHwRef,uint8_t * pData,uint8_t length)710 phHciNfc_CE_B_ProcessData(
711                             phHciNfc_sContext_t     *psHciContext,
712                             void                    *pHwRef,
713                             uint8_t                 *pData,
714                             uint8_t                 length
715                        )
716 {
717     NFCSTATUS       status = NFCSTATUS_SUCCESS;
718 
719     static uint8_t  send_data[] = {0x6D, 0x80};
720     status = phHciNfc_CE_B_SendData_Event(
721                              (void *)psHciContext, pHwRef,
722                              send_data, sizeof(send_data));
723     return status;
724 }
725 
726 #endif /* #if defined (SEND_DATA_EVENT) */
727 
728 #endif /* #if defined (HOST_EMULATION) */
729 
730