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_ISO15693.c                                                 *
22* \brief HCI ISO-15693 management routines.                                     *
23*                                                                             *
24*                                                                             *
25* Project: NFC-FRI-1.1                                                        *
26*                                                                             *
27* $Date: Thu Feb 11 18:54:47 2010 $                                           *
28* $Author: ing04880 $                                                         *
29* $Revision: 1.7 $                                                           *
30* $Aliases:  $
31*                                                                             *
32* =========================================================================== *
33*/
34
35/*
36***************************** Header File Inclusion ****************************
37*/
38#include <phNfcCompId.h>
39#include <phHciNfc_Pipe.h>
40#include <phHciNfc_RFReader.h>
41#include <phOsalNfc.h>
42
43#if defined (TYPE_ISO15693)
44#include <phHciNfc_ISO15693.h>
45
46/*
47****************************** Macro Definitions *******************************
48*/
49#define ISO_15693_INVENTORY_INDEX               0x01U
50#define ISO_15693_AFI_INDEX                     0x02U
51
52#define ISO_15693_INVENTORY_LENGTH              0x0AU
53#define ISO_15693_AFI_LENGTH                    0x01U
54
55#define ISO_15693_SINGLE_TAG_FOUND              0x00U
56#define ISO_15693_MULTIPLE_TAGS_FOUND           0x03U
57
58/*
59*************************** Structure and Enumeration ***************************
60*/
61
62/*
63*************************** Static Function Declaration **************************
64*/
65
66static
67NFCSTATUS
68phHciNfc_ISO15693_InfoUpdate(
69                                phHciNfc_sContext_t     *psHciContext,
70                                uint8_t                 index,
71                                uint8_t                 *reg_value,
72                                uint8_t                 reg_length
73                         );
74
75static
76NFCSTATUS
77phHciNfc_Recv_ISO15693_Response(
78                        void                *psContext,
79                        void                *pHwRef,
80                        uint8_t             *pResponse,
81#ifdef ONE_BYTE_LEN
82                        uint8_t             length
83#else
84                        uint16_t            length
85#endif
86                       );
87
88static
89NFCSTATUS
90phHciNfc_Recv_ISO15693_Event(
91                             void               *psContext,
92                             void               *pHwRef,
93                             uint8_t            *pEvent,
94#ifdef ONE_BYTE_LEN
95                             uint8_t            length
96#else
97                             uint16_t           length
98#endif
99                       );
100
101/*
102*************************** Function Definitions ***************************
103*/
104
105NFCSTATUS
106phHciNfc_ISO15693_Init_Resources(
107                                  phHciNfc_sContext_t     *psHciContext
108                                  )
109{
110    NFCSTATUS                   status = NFCSTATUS_SUCCESS;
111    phHciNfc_ISO15693_Info_t    *ps_15693_info=NULL;
112    if( NULL == psHciContext )
113    {
114        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
115    }
116    else
117    {
118        if (NULL != psHciContext->p_iso_15693_info)
119        {
120            status = NFCSTATUS_SUCCESS;
121        }
122        else if(( NULL == psHciContext->p_iso_15693_info ) &&
123            (phHciNfc_Allocate_Resource((void **)(&ps_15693_info),
124            sizeof(phHciNfc_ISO15693_Info_t))== NFCSTATUS_SUCCESS)
125            )
126        {
127            psHciContext->p_iso_15693_info = ps_15693_info;
128            ps_15693_info->current_seq = ISO15693_INVENTORY;
129            ps_15693_info->next_seq = ISO15693_INVENTORY;
130            ps_15693_info->ps_15693_pipe_info = NULL;
131        }
132        else
133        {
134            status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INSUFFICIENT_RESOURCES);
135        }
136
137    }
138    return status;
139}
140
141
142NFCSTATUS
143phHciNfc_ISO15693_Get_PipeID(
144                              phHciNfc_sContext_t     *psHciContext,
145                              uint8_t                 *ppipe_id
146                              )
147{
148    NFCSTATUS       status = NFCSTATUS_SUCCESS;
149    if( (NULL != psHciContext)
150        && ( NULL != ppipe_id )
151        && ( NULL != psHciContext->p_iso_15693_info )
152        )
153    {
154        phHciNfc_ISO15693_Info_t     *ps_15693_info = NULL;
155        ps_15693_info = (phHciNfc_ISO15693_Info_t *)
156                            psHciContext->p_iso_15693_info ;
157        *ppipe_id =  ps_15693_info->ps_15693_pipe_info->pipe.pipe_id;
158    }
159    else
160    {
161        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
162    }
163    return status;
164}
165
166
167NFCSTATUS
168phHciNfc_ISO15693_Update_PipeInfo(
169                                   phHciNfc_sContext_t     *psHciContext,
170                                   uint8_t                 pipeID,
171                                   phHciNfc_Pipe_Info_t    *pPipeInfo
172                                   )
173{
174    NFCSTATUS       status = NFCSTATUS_SUCCESS;
175    if((NULL == psHciContext) || (NULL == pPipeInfo))
176    {
177        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
178    }
179    else if(NULL == psHciContext->p_iso_15693_info)
180    {
181        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
182    }
183    else
184    {
185        phHciNfc_ISO15693_Info_t       *ps_15693_info = NULL;
186        ps_15693_info = (phHciNfc_ISO15693_Info_t *)
187                        psHciContext->p_iso_15693_info ;
188
189        /* Update the pipe_id of the ISO15693 Gate obtained from
190        the HCI Response */
191        ps_15693_info->ps_15693_pipe_info = pPipeInfo;
192        ps_15693_info->pipe_id = pipeID;
193        ps_15693_info->ps_15693_pipe_info->pipe.pipe_id = pipeID;
194        /* Update the Response Receive routine of the ISO15693 Gate */
195        pPipeInfo->recv_resp = &phHciNfc_Recv_ISO15693_Response;
196        /* Update the event Receive routine of the ISO15693 Gate */
197        pPipeInfo->recv_event = &phHciNfc_Recv_ISO15693_Event;
198    }
199    return status;
200}
201
202
203NFCSTATUS
204phHciNfc_ISO15693_Update_Info(
205                             phHciNfc_sContext_t        *psHciContext,
206                             uint8_t                    infotype,
207                             void                       *iso_15693_info
208                             )
209{
210    NFCSTATUS                   status = NFCSTATUS_SUCCESS;
211
212    if (NULL == psHciContext)
213    {
214        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
215    }
216    else if(NULL == psHciContext->p_iso_15693_info)
217    {
218        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
219    }
220    else
221    {
222        phHciNfc_ISO15693_Info_t     *ps_15693_info = NULL;
223        ps_15693_info = (phHciNfc_ISO15693_Info_t *)
224                        psHciContext->p_iso_15693_info;
225
226        switch(infotype)
227        {
228            case HCI_ISO_15693_ENABLE:
229            {
230                if (NULL != iso_15693_info)
231                {
232                    ps_15693_info->enable_iso_15693_gate =
233                                    *((uint8_t *)iso_15693_info);
234                }
235                break;
236            }
237            case HCI_ISO_15693_INFO_SEQ:
238            {
239                ps_15693_info->current_seq = ISO15693_INVENTORY;
240                ps_15693_info->next_seq = ISO15693_INVENTORY;
241                break;
242            }
243            default:
244            {
245                status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
246                break;
247            }
248        }
249    }
250    return status;
251}
252
253
254NFCSTATUS
255phHciNfc_ISO15693_Info_Sequence (
256                       void             *psHciHandle,
257                       void             *pHwRef
258                       )
259{
260    NFCSTATUS               status = NFCSTATUS_SUCCESS;
261    phHciNfc_sContext_t     *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
262    if( (NULL == psHciContext)
263        || (NULL == pHwRef)
264      )
265    {
266      status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
267    }
268    else if((NULL == psHciContext->p_iso_15693_info) ||
269        (HCI_ISO_15693_ENABLE !=
270        ((phHciNfc_ISO15693_Info_t *)(psHciContext->p_iso_15693_info))->
271        enable_iso_15693_gate))
272    {
273        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
274    }
275    else
276    {
277        phHciNfc_ISO15693_Info_t    *ps_15693_info = NULL;
278        phHciNfc_Pipe_Info_t        *ps_pipe_info = NULL;
279        uint8_t                     pipeid = 0;
280
281        ps_15693_info = (phHciNfc_ISO15693_Info_t *)
282                                psHciContext->p_iso_15693_info;
283        ps_pipe_info = ps_15693_info->ps_15693_pipe_info;
284
285        if(NULL == ps_pipe_info )
286        {
287            status = PHNFCSTVAL(CID_NFC_HCI,
288                                NFCSTATUS_INVALID_HCI_SEQUENCE);
289        }
290        else
291        {
292            switch(ps_15693_info->current_seq)
293            {
294                case ISO15693_INVENTORY:
295                {
296                    ps_pipe_info->reg_index = ISO_15693_INVENTORY_INDEX;
297                    pipeid = ps_pipe_info->pipe.pipe_id ;
298                    /* Fill the data buffer and send the command to the
299                            device */
300                    status =
301                        phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef,
302                                pipeid, (uint8_t)ANY_GET_PARAMETER);
303                    if(NFCSTATUS_PENDING == status )
304                    {
305                        ps_15693_info->next_seq = ISO15693_AFI;
306                    }
307                    break;
308                }
309                case ISO15693_AFI:
310                {
311                    ps_pipe_info->reg_index = ISO_15693_AFI_INDEX;
312                    pipeid = ps_pipe_info->pipe.pipe_id ;
313                    /* Fill the data buffer and send the command to the
314                            device */
315                    status =
316                        phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef,
317                                pipeid, (uint8_t)ANY_GET_PARAMETER);
318                    if(NFCSTATUS_PENDING == status )
319                    {
320                        ps_15693_info->next_seq = ISO15693_END_SEQUENCE;
321                    }
322                    break;
323                }
324                case ISO15693_END_SEQUENCE:
325                {
326                    phNfc_sCompletionInfo_t     CompInfo;
327                    if (ISO_15693_MULTIPLE_TAGS_FOUND ==
328                        ps_15693_info->multiple_tgts_found)
329                    {
330                        CompInfo.status = NFCSTATUS_MULTIPLE_TAGS;
331                    }
332                    else
333                    {
334                        CompInfo.status = NFCSTATUS_SUCCESS;
335                    }
336
337                    CompInfo.info = &(ps_15693_info->iso15693_info);
338
339                    ps_15693_info->iso15693_info.RemDevType =
340                                    phHal_eISO15693_PICC;
341                    ps_15693_info->current_seq = ISO15693_INVENTORY;
342                    ps_15693_info->next_seq = ISO15693_INVENTORY;
343                    status = NFCSTATUS_SUCCESS;
344                    /* Notify to the upper layer */
345                    phHciNfc_Tag_Notify(psHciContext, pHwRef,
346                                    NFC_NOTIFY_TARGET_DISCOVERED,
347                                    &CompInfo);
348                    break;
349                }
350                default:
351                {
352                    status = PHNFCSTVAL(CID_NFC_HCI,
353                                        NFCSTATUS_INVALID_HCI_RESPONSE);
354                    break;
355                }
356            }
357        }
358    }
359    return status;
360}
361
362static
363NFCSTATUS
364phHciNfc_ISO15693_InfoUpdate(
365                                phHciNfc_sContext_t     *psHciContext,
366                                uint8_t                 index,
367                                uint8_t                 *reg_value,
368                                uint8_t                 reg_length
369                         )
370{
371    NFCSTATUS                   status = NFCSTATUS_SUCCESS;
372    phHciNfc_ISO15693_Info_t    *ps_15693_info = NULL;
373    uint8_t                     i = 0;
374
375    ps_15693_info = (phHciNfc_ISO15693_Info_t *)
376                    (psHciContext->p_iso_15693_info);
377
378
379    switch(index)
380    {
381        case ISO_15693_INVENTORY_INDEX:
382        {
383            if (ISO_15693_INVENTORY_LENGTH == reg_length)
384            {
385                ps_15693_info->iso15693_info.RemoteDevInfo
386                    .Iso15693_Info.Flags = *(reg_value + i );
387                i++;
388                ps_15693_info->iso15693_info.RemoteDevInfo
389                    .Iso15693_Info.Dsfid = *(reg_value + i );
390                i++;
391                (void)memcpy(ps_15693_info->iso15693_info.
392                     RemoteDevInfo.Iso15693_Info.Uid,
393                       (reg_value+i), (reg_length - i ));
394                ps_15693_info->iso15693_info.RemoteDevInfo
395                                    .Iso15693_Info.UidLength = ( reg_length - i );
396                HCI_PRINT_BUFFER("\tISO 15693 inventory", reg_value, reg_length);
397            }
398            else
399            {
400                status = PHNFCSTVAL(CID_NFC_HCI,
401                                    NFCSTATUS_INVALID_HCI_RESPONSE);
402            }
403            break;
404        }
405        case ISO_15693_AFI_INDEX:
406        {
407            if (ISO_15693_AFI_LENGTH == reg_length)
408            {
409                ps_15693_info->iso15693_info.RemoteDevInfo
410                                    .Iso15693_Info.Afi = *(reg_value + i );
411                HCI_PRINT_BUFFER("\tISO 15693 AFI", reg_value, reg_length);
412            }
413            else
414            {
415                status = PHNFCSTVAL(CID_NFC_HCI,
416                                    NFCSTATUS_INVALID_HCI_RESPONSE);
417            }
418            break;
419        }
420        default:
421        {
422            status = PHNFCSTVAL(CID_NFC_HCI,
423                                NFCSTATUS_INVALID_HCI_RESPONSE);
424            break;
425        }
426    }
427    return status;
428}
429
430
431static
432NFCSTATUS
433phHciNfc_Recv_ISO15693_Response(
434                        void                *psContext,
435                        void                *pHwRef,
436                        uint8_t             *pResponse,
437#ifdef ONE_BYTE_LEN
438                        uint8_t             length
439#else
440                        uint16_t            length
441#endif
442                       )
443{
444    NFCSTATUS                   status = NFCSTATUS_SUCCESS;
445    phHciNfc_sContext_t         *psHciContext =
446                                (phHciNfc_sContext_t *)psContext ;
447
448
449    if( (NULL == psHciContext) || (NULL == pHwRef) || (NULL == pResponse)
450        || (0 == length))
451    {
452      status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
453    }
454    else if(NULL == psHciContext->p_iso_15693_info)
455    {
456        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
457    }
458    else
459    {
460        phHciNfc_ISO15693_Info_t    *ps_15693_info = NULL;
461        phHciNfc_Pipe_Info_t        *ps_pipe_info = NULL;
462        uint8_t                     prev_cmd = ANY_GET_PARAMETER;
463
464        ps_15693_info = (phHciNfc_ISO15693_Info_t *)
465                            psHciContext->p_iso_15693_info;
466
467        ps_pipe_info = ps_15693_info->ps_15693_pipe_info;
468        if( NULL == ps_pipe_info)
469        {
470            status = PHNFCSTVAL(CID_NFC_HCI,
471                                NFCSTATUS_INVALID_HCI_SEQUENCE);
472        }
473        else
474        {
475            prev_cmd = ps_pipe_info->prev_msg ;
476            switch(prev_cmd)
477            {
478                case ANY_GET_PARAMETER:
479                {
480                    status = phHciNfc_ISO15693_InfoUpdate(psHciContext,
481                                    ps_pipe_info->reg_index,
482                                    &pResponse[HCP_HEADER_LEN],
483                                    (uint8_t)(length - HCP_HEADER_LEN));
484#if 0
485                    status = phHciNfc_ReaderMgmt_Update_Sequence(psHciContext,
486                                                                UPDATE_SEQ);
487#endif /* #if 0 */
488                    break;
489                }
490                case ANY_SET_PARAMETER:
491                {
492                    HCI_PRINT("ISO 15693 Parameter Set \n");
493                    status = phHciNfc_ReaderMgmt_Update_Sequence(psHciContext,
494                                                    UPDATE_SEQ);
495                    ps_15693_info->next_seq = ISO15693_INVENTORY;
496                    break;
497                }
498                case ANY_OPEN_PIPE:
499                {
500                    HCI_PRINT("ISO 15693 open pipe complete\n");
501                    status = phHciNfc_ReaderMgmt_Update_Sequence(psHciContext,
502                                                    UPDATE_SEQ);
503                    ps_15693_info->next_seq = ISO15693_INVENTORY;
504                    break;
505                }
506                case ANY_CLOSE_PIPE:
507                {
508                    HCI_PRINT("ISO 15693 close pipe complete\n");
509                    status = phHciNfc_ReaderMgmt_Update_Sequence(psHciContext,
510                                                    UPDATE_SEQ);
511                    break;
512                }
513
514                case NXP_ISO15693_CMD:
515                {
516                    if (length >= HCP_HEADER_LEN)
517                    {
518                        HCI_PRINT("ISO 15693 packet received \n");
519                        /* Copy buffer to the receive buffer */
520                        phHciNfc_Append_HCPFrame(psHciContext->recv_buffer,
521                            0, pResponse, length);
522                        psHciContext->rx_total = length;
523                        psHciContext->rx_index = HCP_HEADER_LEN;
524                        HCI_PRINT_BUFFER("ISO 15693 Bytes received",
525                                                        pResponse, length);
526                    }
527                    else
528                    {
529                        status = PHNFCSTVAL(CID_NFC_HCI,
530                                        NFCSTATUS_INVALID_HCI_RESPONSE);
531                    }
532                    break;
533                }
534                default:
535                {
536                    status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_RESPONSE);
537                    break;
538                }
539            }/* End of switch(prev_cmd) */
540
541            if( NFCSTATUS_SUCCESS == status )
542            {
543                ps_pipe_info->prev_status = NFCSTATUS_SUCCESS;
544                ps_15693_info->current_seq = ps_15693_info->next_seq;
545            }
546        }
547    }
548    return status;
549}
550
551static
552NFCSTATUS
553phHciNfc_Recv_ISO15693_Event(
554                             void               *psContext,
555                             void               *pHwRef,
556                             uint8_t            *pEvent,
557#ifdef ONE_BYTE_LEN
558                             uint8_t            length
559#else
560                             uint16_t           length
561#endif
562                       )
563{
564    NFCSTATUS                   status = NFCSTATUS_SUCCESS;
565    phHciNfc_sContext_t         *psHciContext =
566                                (phHciNfc_sContext_t *)psContext ;
567    if( (NULL == psHciContext) || (NULL == pHwRef) || (NULL == pEvent)
568        || (length == 0))
569    {
570        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
571    }
572    else if((NULL == psHciContext->p_iso_15693_info) ||
573        (HCI_ISO_15693_ENABLE !=
574        ((phHciNfc_ISO15693_Info_t *)(psHciContext->p_iso_15693_info))->
575        enable_iso_15693_gate))
576    {
577        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
578    }
579    else
580    {
581        phHciNfc_HCP_Packet_t       *p_packet = NULL;
582        phHciNfc_ISO15693_Info_t    *ps_15693_info=NULL;
583        phHciNfc_HCP_Message_t      *message = NULL;
584        uint8_t                     instruction=0,
585                                    i = 0;
586
587        ps_15693_info = (phHciNfc_ISO15693_Info_t *)
588                        psHciContext->p_iso_15693_info;
589        p_packet = (phHciNfc_HCP_Packet_t *)pEvent;
590        message = &p_packet->msg.message;
591        /* Get the instruction bits from the Message Header */
592        instruction = (uint8_t) GET_BITS8( message->msg_header,
593                HCP_MSG_INSTRUCTION_OFFSET, HCP_MSG_INSTRUCTION_LEN);
594
595        if ((EVT_TARGET_DISCOVERED == instruction)
596            && ((ISO_15693_MULTIPLE_TAGS_FOUND == message->payload[i])
597                || (ISO_15693_SINGLE_TAG_FOUND == message->payload[i]))
598          )
599        {
600            phNfc_sCompletionInfo_t pCompInfo;
601
602/* #define NFC_ISO_15693_MULTIPLE_TAGS_SUPPORT 0x00 */
603#if (NFC_ISO_15693_MULTIPLE_TAGS_SUPPORT >= 0x01)
604
605            if (ISO_15693_MULTIPLE_TAGS_FOUND == message->payload[i])
606            {
607                ps_15693_info->multiple_tgts_found = ISO_15693_MULTIPLE_TAGS_FOUND;
608                pCompInfo.status = NFCSTATUS_MULTIPLE_TAGS;
609            }
610            else
611#endif /* #if (NFC_ISO_15693_MULTIPLE_TAGS_SUPPORT <= 0x01) */
612            {
613                ps_15693_info->multiple_tgts_found = FALSE;
614                pCompInfo.status = NFCSTATUS_SUCCESS;
615            }
616            /* CompInfo.info = &(ps_15693_info->iso15693_info); */
617
618            psHciContext->host_rf_type = phHal_eISO15693_PCD;
619            ps_15693_info->iso15693_info.RemDevType = phHal_eISO15693_PICC;
620            ps_15693_info->current_seq = ISO15693_INVENTORY;
621            /* Notify to the HCI Generic layer To Update the FSM */
622            phHciNfc_Notify_Event(psHciContext, pHwRef,
623                                    NFC_NOTIFY_TARGET_DISCOVERED,
624                                    &pCompInfo);
625
626        }
627        else
628        {
629            status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_RESPONSE);
630        }
631    }
632    return status;
633}
634
635NFCSTATUS
636phHciNfc_Send_ISO15693_Command(
637                              phHciNfc_sContext_t   *psHciContext,
638                              void                  *pHwRef,
639                              uint8_t               pipe_id,
640                              uint8_t               cmd
641                              )
642{
643    NFCSTATUS                   status = NFCSTATUS_SUCCESS;
644
645    if( (NULL == psHciContext) || (NULL == pHwRef) )
646    {
647        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
648    }
649    else if((NULL == psHciContext->p_iso_15693_info) ||
650        (HCI_ISO_15693_ENABLE !=
651        ((phHciNfc_ISO15693_Info_t *)(psHciContext->p_iso_15693_info))->
652        enable_iso_15693_gate) ||
653        (HCI_UNKNOWN_PIPE_ID ==
654        ((phHciNfc_ISO15693_Info_t *)(psHciContext->p_iso_15693_info))->
655        pipe_id) ||
656        (pipe_id !=
657        ((phHciNfc_ISO15693_Info_t *)(psHciContext->p_iso_15693_info))->
658        pipe_id))
659    {
660        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
661    }
662    else
663    {
664        phHciNfc_ISO15693_Info_t    *ps_15693_info=NULL;
665        phHciNfc_Pipe_Info_t        *ps_pipe_info=NULL;
666        phHciNfc_HCP_Packet_t       *hcp_packet = NULL;
667        phHciNfc_HCP_Message_t      *hcp_message = NULL;
668        uint8_t                     i = 0;
669        uint16_t                    length = HCP_HEADER_LEN;
670
671        ps_15693_info = (phHciNfc_ISO15693_Info_t *)
672                            psHciContext->p_iso_15693_info ;
673        ps_pipe_info = ps_15693_info->ps_15693_pipe_info;
674        if(NULL == ps_pipe_info )
675        {
676            status = PHNFCSTVAL(CID_NFC_HCI,
677                        NFCSTATUS_INVALID_HCI_SEQUENCE);
678        }
679        else
680        {
681            psHciContext->tx_total = 0 ;
682            hcp_packet = (phHciNfc_HCP_Packet_t *) psHciContext->send_buffer;
683            /* Construct the HCP Frame */
684            if (NXP_ISO15693_CMD == cmd)
685            {
686                phHciNfc_Build_HCPFrame(hcp_packet,HCP_CHAINBIT_DEFAULT,
687                                (uint8_t) pipe_id, HCP_MSG_TYPE_COMMAND, cmd);
688                hcp_message = &(hcp_packet->msg.message);
689
690#if 0
691                /* Command */
692                hcp_message->payload[i++] =
693                                psHciContext->p_xchg_info->params.tag_info.cmd_type ;
694                    /* Address */
695                hcp_message->payload[i++] =
696                                psHciContext->p_xchg_info->params.tag_info.addr ;
697#endif /* #if 0 */
698                phHciNfc_Append_HCPFrame((uint8_t *)hcp_message->payload,
699                    i, (uint8_t *)ps_pipe_info->param_info,
700                    ps_pipe_info->param_length);
701                length =(uint16_t)(length + i + ps_pipe_info->param_length);
702
703                ps_pipe_info->sent_msg_type = (uint8_t)HCP_MSG_TYPE_COMMAND;
704                ps_pipe_info->prev_msg = cmd;
705                psHciContext->tx_total = length;
706                psHciContext->response_pending = TRUE;
707
708                /* Send the Constructed HCP packet to the lower layer */
709                status = phHciNfc_Send_HCP( psHciContext, pHwRef);
710                ps_pipe_info->prev_status = status;
711            }
712        }
713    }
714    return status;
715}
716
717NFCSTATUS
718phHciNfc_ISO15693_Set_AFI(
719                               void         *psContext,
720                               void         *pHwRef,
721                               uint8_t      afi_value
722                               )
723{
724    NFCSTATUS                   status = NFCSTATUS_SUCCESS;
725    phHciNfc_sContext_t         *psHciContext =
726                                (phHciNfc_sContext_t *)psContext ;
727
728    if( (NULL == psHciContext) || (NULL == pHwRef))
729    {
730        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
731    }
732    else if((NULL == psHciContext->p_iso_15693_info) ||
733        (HCI_ISO_15693_ENABLE !=
734        ((phHciNfc_ISO15693_Info_t *)(psHciContext->p_iso_15693_info))->
735        enable_iso_15693_gate))
736    {
737        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
738    }
739    else
740    {
741        phHciNfc_ISO15693_Info_t    *ps_15693_info = NULL;
742        phHciNfc_Pipe_Info_t        *ps_pipe_info = NULL;
743        uint8_t                     pipeid = 0;
744
745        ps_15693_info = (phHciNfc_ISO15693_Info_t *)
746                            psHciContext->p_iso_15693_info ;
747        ps_pipe_info = ps_15693_info->ps_15693_pipe_info;
748
749        if( NULL == ps_pipe_info)
750        {
751            status = PHNFCSTVAL(CID_NFC_HCI,
752                                NFCSTATUS_INVALID_HCI_SEQUENCE);
753        }
754        else
755        {
756            ps_pipe_info->reg_index = ISO_15693_AFI_INDEX;
757            ps_pipe_info->param_info = &afi_value;
758            ps_pipe_info->param_length = sizeof(afi_value);
759            pipeid = ps_pipe_info->pipe.pipe_id ;
760            status = phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef,
761                                        pipeid, (uint8_t)ANY_SET_PARAMETER);
762        }
763    }
764    return status;
765}
766
767#endif /* #if defined (TYPE_ISO15693) */
768
769
770