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  hHciNfc_PipeMgmt.c                                                   *
22* \brief HCI Pipe Management Routines.                                        *
23*                                                                             *
24*                                                                             *
25* Project: NFC-FRI-1.1                                                        *
26*                                                                             *
27* $Date: Tue Aug 18 10:12:39 2009 $                                           *
28* $Author: ing04880 $                                                         *
29* $Revision: 1.42 $                                                           *
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/*
37***************************** Header File Inclusion ****************************
38*/
39
40#include <phNfcConfig.h>
41#include <phNfcCompId.h>
42#include <phHciNfc_Pipe.h>
43#include <phOsalNfc.h>
44#include <phHciNfc_AdminMgmt.h>
45#include <phHciNfc_LinkMgmt.h>
46#include <phHciNfc_IDMgmt.h>
47#include <phHciNfc_DevMgmt.h>
48#include <phHciNfc_PollingLoop.h>
49#include <phHciNfc_RFReader.h>
50#include <phHciNfc_RFReaderA.h>
51#ifdef TYPE_B
52#include <phHciNfc_RFReaderB.h>
53#endif
54#ifdef TYPE_FELICA
55#include <phHciNfc_Felica.h>
56#endif
57#ifdef TYPE_JEWEL
58#include <phHciNfc_Jewel.h>
59#endif
60#ifdef TYPE_ISO15693
61#include <phHciNfc_ISO15693.h>
62#endif
63#ifdef ENABLE_P2P
64#include <phHciNfc_NfcIPMgmt.h>
65#endif
66#ifdef HOST_EMULATION
67#include <phHciNfc_CE_A.h>
68#include <phHciNfc_CE_B.h>
69#endif
70#include <phHciNfc_WI.h>
71#include <phHciNfc_SWP.h>
72
73/*
74****************************** Macro Definitions *******************************
75*/
76
77/*
78*************************** Structure and Enumeration ***************************
79*/
80static phHciNfc_GateID_t host_gate_list[] = {
81        phHciNfc_IdentityMgmtGate,
82        phHciNfc_PN544MgmtGate,
83        phHciNfc_PollingLoopGate,
84        phHciNfc_RFReaderAGate,
85#ifdef TYPE_B
86        phHciNfc_RFReaderBGate,
87#endif
88
89#ifdef TYPE_FELICA
90        phHciNfc_RFReaderFGate,
91#endif
92
93#ifdef TYPE_JEWEL
94        phHciNfc_JewelReaderGate,
95#endif
96
97#ifdef TYPE_ISO15693
98        phHciNfc_ISO15693Gate,
99#endif
100
101#ifdef ENABLE_P2P
102        phHciNfc_NFCIP1InitRFGate,
103        phHciNfc_NFCIP1TargetRFGate,
104#endif
105        phHciNfc_NfcWIMgmtGate,
106        phHciNfc_SwpMgmtGate,
107#if defined(HOST_EMULATION) && ( NXP_UICC_CE_RIGHTS < 0x01 )
108        phHciNfc_CETypeAGate,
109        phHciNfc_CETypeBGate,
110#endif
111        phHciNfc_UnknownGate
112};
113
114/*
115*************************** Static Function Declaration **************************
116*/
117
118static
119NFCSTATUS
120phHciNfc_Create_Pipe(
121                        phHciNfc_sContext_t     *psHciContext,
122                        void                    *pHwRef,
123                        phHciNfc_Gate_Info_t    *destination,
124                        phHciNfc_Pipe_Info_t    **ppPipeHandle
125                    );
126
127
128/*
129*************************** Function Definitions ***************************
130*/
131
132
133/*!
134 * \brief Creation of the Pipe
135 *
136 * This function creates the pipe between a source host's gate and destination
137 * host's gate
138 *
139 */
140
141static
142NFCSTATUS
143phHciNfc_Create_Pipe(
144                        phHciNfc_sContext_t     *psHciContext,
145                        void                    *pHwRef,
146                        phHciNfc_Gate_Info_t    *destination,
147                        phHciNfc_Pipe_Info_t    **ppPipeHandle
148                    )
149{
150    NFCSTATUS       status = NFCSTATUS_SUCCESS;
151
152    *ppPipeHandle = (phHciNfc_Pipe_Info_t *)
153                        phOsalNfc_GetMemory( sizeof(phHciNfc_Pipe_Info_t) );
154
155    if(NULL != *ppPipeHandle)
156    {
157        /* The Source Host is the Terminal Host */
158        (*ppPipeHandle)->pipe.source.host_id    = (uint8_t) phHciNfc_TerminalHostID;
159
160        /* The Source Gate is same as the Destination Gate */
161        (*ppPipeHandle)->pipe.source.gate_id    =
162                                ((phHciNfc_Gate_Info_t *)destination)->gate_id;
163        (*ppPipeHandle)->pipe.dest.host_id =
164                                ((phHciNfc_Gate_Info_t *)destination)->host_id;
165        (*ppPipeHandle)->pipe.dest.gate_id  =
166                                ((phHciNfc_Gate_Info_t *)destination)->gate_id;
167
168        /* if( hciMode_Override == psHciContext->hci_mode ) */
169        {
170            /* The Pipe ID is unknown until it is assigned */
171            (*ppPipeHandle)->pipe.pipe_id   = (uint8_t) HCI_UNKNOWN_PIPE_ID;
172
173            status = phHciNfc_Send_Admin_Cmd( psHciContext, pHwRef,
174                                        ADM_CREATE_PIPE, (PIPEINFO_SIZE-1)
175                                                    ,*ppPipeHandle );
176        }
177    }
178    else
179    {
180        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INSUFFICIENT_RESOURCES);
181    }
182    return status;
183}
184
185
186NFCSTATUS
187phHciNfc_Update_Pipe(
188                        phHciNfc_sContext_t     *psHciContext,
189                        void                    *pHwRef,
190                        phHciNfc_PipeMgmt_Seq_t *p_pipe_seq
191                    )
192{
193    static uint8_t pipe_index = HCI_DYNAMIC_PIPE_ID;
194    phHciNfc_Pipe_Info_t  *p_pipe_info = NULL;
195    NFCSTATUS       status = NFCSTATUS_SUCCESS;
196
197
198    for (pipe_index = 0;
199            (pipe_index +  HCI_DYNAMIC_PIPE_ID) <=
200                (uint8_t)(sizeof(host_gate_list)/sizeof(phHciNfc_GateID_t) );
201                    pipe_index++)
202    {
203        status = phHciNfc_Allocate_Resource((void **)&p_pipe_info,
204                                            sizeof(phHciNfc_Pipe_Info_t));
205
206        if( (NFCSTATUS_SUCCESS == status)
207            && (NULL != p_pipe_info))
208        {
209            /* The Source Host is the Terminal Host */
210            p_pipe_info->pipe.source.host_id  = (uint8_t) phHciNfc_TerminalHostID;
211
212            /* The Source Gate is same as the Destination Gate */
213            p_pipe_info->pipe.source.gate_id    =
214                                    host_gate_list[pipe_index];
215            p_pipe_info->pipe.dest.host_id =
216                                    phHciNfc_HostControllerID;
217            p_pipe_info->pipe.dest.gate_id  =
218                                    host_gate_list[pipe_index];
219            /* The Pipe ID is unknown until it is assigned */
220            p_pipe_info->pipe.pipe_id   = (uint8_t) HCI_UNKNOWN_PIPE_ID;
221
222            /* Initialise the Resources for the particular Gate */
223
224            status = phHciNfc_Create_All_Pipes(psHciContext,
225                                            pHwRef, p_pipe_seq );
226
227            if( NFCSTATUS_SUCCESS == status )
228            {
229                uint8_t pipe_id = (uint8_t)(pipe_index + HCI_DYNAMIC_PIPE_ID);
230                status = phHciNfc_Update_PipeInfo( psHciContext, p_pipe_seq ,
231                                        pipe_id, p_pipe_info );
232                if( NFCSTATUS_SUCCESS == status )
233                {
234                    p_pipe_info->pipe.pipe_id = pipe_id;
235                    psHciContext->p_pipe_list[pipe_id] = p_pipe_info;
236                }
237                else
238                {
239                    phOsalNfc_FreeMemory(p_pipe_info);
240                }
241                p_pipe_info = NULL;
242            }
243            else
244            {
245                phOsalNfc_FreeMemory(p_pipe_info);
246                p_pipe_info = NULL;
247            }
248        }
249        else
250        {
251            status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INSUFFICIENT_RESOURCES);
252        }
253    }
254
255    if( NFCSTATUS_SUCCESS == status )
256    {
257        status = phHciNfc_LinkMgmt_Initialise( psHciContext,pHwRef );
258        if(NFCSTATUS_SUCCESS == status)
259        {
260            status = phHciNfc_ReaderMgmt_Initialise( psHciContext,pHwRef );
261        }
262        if(NFCSTATUS_SUCCESS == status)
263        {
264            status = phHciNfc_EmuMgmt_Initialise( psHciContext,pHwRef );
265        }
266    }
267
268    return status;
269}
270
271
272/*!
273 * \brief Deletion of the Pipe
274 *
275 * This function Deletes a pipe created between a terminal host's gate and
276 *  destination host's gate
277 *
278 */
279
280NFCSTATUS
281phHciNfc_Delete_Pipe(
282                        phHciNfc_sContext_t     *psHciContext,
283                        void                    *pHwRef,
284                        phHciNfc_Pipe_Info_t    *pPipeHandle
285                    )
286{
287    NFCSTATUS       status=NFCSTATUS_SUCCESS;
288    NFCSTATUS       cmd_status = NFCSTATUS_SUCCESS;
289
290    if( (NULL == psHciContext)
291        || (NULL == pHwRef)
292        || (NULL == pPipeHandle)
293     )
294    {
295      status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
296    }
297    else
298    {
299        cmd_status = phHciNfc_Send_Admin_Cmd( psHciContext, pHwRef,
300                            ADM_DELETE_PIPE, PIPEID_LEN, pPipeHandle );
301        status = ( (cmd_status == NFCSTATUS_PENDING)?
302                                        NFCSTATUS_SUCCESS : cmd_status);
303    }
304
305    return status;
306}
307
308#ifdef HOST_EMULATION
309
310NFCSTATUS
311phHciNfc_CE_Pipes_OP(
312                                phHciNfc_sContext_t             *psHciContext,
313                                void                            *pHwRef,
314                                phHciNfc_PipeMgmt_Seq_t         *p_pipe_seq
315                             )
316{
317    NFCSTATUS                   status = NFCSTATUS_SUCCESS;
318    phHciNfc_Pipe_Info_t        *p_pipe_info = NULL;
319    /* uint8_t                      pipe_id = (uint8_t) HCI_UNKNOWN_PIPE_ID; */
320
321    if( (NULL == psHciContext) || (NULL == pHwRef) )
322    {
323      status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
324    }
325    else
326    {
327        switch( *p_pipe_seq )
328        {
329            case PIPE_CARD_A_CREATE:
330            {
331                phHciNfc_Gate_Info_t        id_dest;
332
333                id_dest.host_id = (uint8_t)phHciNfc_HostControllerID;
334                id_dest.gate_id = (uint8_t)phHciNfc_CETypeAGate;
335
336                status = phHciNfc_CE_A_Init_Resources ( psHciContext );
337                if(status == NFCSTATUS_SUCCESS)
338                {
339                    status = phHciNfc_Create_Pipe( psHciContext, pHwRef,
340                                &id_dest, &p_pipe_info);
341                    status = ((NFCSTATUS_PENDING == status )?
342                                        NFCSTATUS_SUCCESS : status);
343                }
344                break;
345            }
346            case PIPE_CARD_B_CREATE:
347            {
348                phHciNfc_Gate_Info_t        id_dest;
349
350                id_dest.host_id = (uint8_t)phHciNfc_HostControllerID;
351                id_dest.gate_id = (uint8_t)phHciNfc_CETypeBGate;
352
353                status = phHciNfc_CE_B_Init_Resources ( psHciContext );
354                if(status == NFCSTATUS_SUCCESS)
355                {
356                    status = phHciNfc_Create_Pipe( psHciContext, pHwRef,
357                                &id_dest, &p_pipe_info);
358                    status = ((NFCSTATUS_PENDING == status )?
359                                        NFCSTATUS_SUCCESS : status);
360                }
361                break;
362            }
363#if 0
364            case PIPE_CARD_F_CREATE:
365            {
366                phHciNfc_Gate_Info_t        id_dest;
367
368                id_dest.host_id = (uint8_t)phHciNfc_HostControllerID;
369                id_dest.gate_id = (uint8_t)phHciNfc_CETypeFGate;
370
371                /* status = phHciNfc_Card_Emulation_Init (psHciContext , TYPE_F); */
372                if(status == NFCSTATUS_SUCCESS)
373                {
374                    status = phHciNfc_Create_Pipe( psHciContext, pHwRef,
375                                &id_dest, &p_pipe_info);
376                     /* status = ((NFCSTATUS_PENDING == status )?
377                                        NFCSTATUS_SUCCESS : status); */
378                }
379                break;
380            }
381            case PIPE_CARD_A_DELETE:
382            {
383                status = phHciNfc_CE_A_Get_PipeID( psHciContext, &pipe_id );
384                p_pipe_info = psHciContext->p_pipe_list[pipe_id];
385                if(status == NFCSTATUS_SUCCESS)
386                {
387                    status = phHciNfc_Delete_Pipe( psHciContext, pHwRef,
388                                p_pipe_info);
389                    status = ((NFCSTATUS_PENDING == status )?
390                                        NFCSTATUS_SUCCESS : status);
391                }
392                break;
393            }
394            case PIPE_CARD_B_DELETE:
395            {
396                status = phHciNfc_CE_B_Get_PipeID( psHciContext, &pipe_id );
397                p_pipe_info = psHciContext->p_pipe_list[pipe_id];
398                if(status == NFCSTATUS_SUCCESS)
399                {
400                    status = phHciNfc_Delete_Pipe( psHciContext, pHwRef,
401                                p_pipe_info);
402                    status = ((NFCSTATUS_PENDING == status )?
403                                        NFCSTATUS_SUCCESS : status);
404                }
405                break;
406            }
407#endif
408            /* case PIPE_MGMT_END : */
409            default:
410            {
411                status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_SEQUENCE);
412                break;
413            }
414        }
415    }
416
417    return status;
418}
419#endif
420
421
422/*!
423 * \brief Creates the Pipes of all the Supported Gates .
424 *
425 * This function Creates the pipes for all the supported gates
426 */
427
428NFCSTATUS
429phHciNfc_Create_All_Pipes(
430                                phHciNfc_sContext_t             *psHciContext,
431                                void                            *pHwRef,
432                                phHciNfc_PipeMgmt_Seq_t         *p_pipe_seq
433                             )
434{
435    NFCSTATUS                           status = NFCSTATUS_SUCCESS;
436    phHciNfc_Pipe_Info_t                *p_pipe_info = NULL;
437
438    if( (NULL == psHciContext) || (NULL == pHwRef)
439        || (NULL == p_pipe_seq) )
440    {
441      status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
442    }
443    else
444    {
445
446        switch( *p_pipe_seq )
447        {
448            /* Admin pipe close sequence */
449            case PIPE_IDMGMT_CREATE:
450            {
451                phHciNfc_Gate_Info_t        id_dest;
452
453                id_dest.host_id = (uint8_t)phHciNfc_HostControllerID;
454                id_dest.gate_id = (uint8_t)phHciNfc_IdentityMgmtGate;
455
456                status = phHciNfc_IDMgmt_Init_Resources (psHciContext);
457                if((status == NFCSTATUS_SUCCESS)
458#ifdef ESTABLISH_SESSION
459                    && (hciMode_Session != psHciContext->hci_mode)
460#endif
461                    )
462                {
463                    status = phHciNfc_Create_Pipe( psHciContext, pHwRef,
464                                &id_dest, &p_pipe_info);
465                    /* status = ((NFCSTATUS_PENDING == status )?
466                                        NFCSTATUS_SUCCESS : status); */
467                }
468                break;
469            }
470            case PIPE_PN544MGMT_CREATE:
471            {
472                phHciNfc_Gate_Info_t        id_dest;
473
474                id_dest.host_id = (uint8_t)phHciNfc_HostControllerID;
475                id_dest.gate_id = (uint8_t)phHciNfc_PN544MgmtGate;
476
477                status = phHciNfc_DevMgmt_Init_Resources (psHciContext);
478                if((status == NFCSTATUS_SUCCESS)
479#ifdef ESTABLISH_SESSION
480                    && (hciMode_Session != psHciContext->hci_mode)
481#endif
482                    )
483                {
484                    status = phHciNfc_Create_Pipe( psHciContext, pHwRef,
485                                &id_dest, &p_pipe_info);
486                    if(HCI_SELF_TEST == psHciContext->init_mode)
487                    {
488                        status = ((NFCSTATUS_PENDING == status )?
489                                        NFCSTATUS_SUCCESS : status);
490                    }
491                }
492                break;
493            }
494            case PIPE_POLLINGLOOP_CREATE:
495            {
496                phHciNfc_Gate_Info_t        id_dest;
497
498                id_dest.host_id = (uint8_t)phHciNfc_HostControllerID;
499                id_dest.gate_id = (uint8_t)phHciNfc_PollingLoopGate;
500
501                status = phHciNfc_PollLoop_Init_Resources (psHciContext);
502                if((status == NFCSTATUS_SUCCESS)
503#ifdef ESTABLISH_SESSION
504                    && (hciMode_Session != psHciContext->hci_mode)
505#endif
506                    )
507                {
508                    status = phHciNfc_Create_Pipe( psHciContext, pHwRef,
509                                &id_dest, &p_pipe_info);
510                    /* status = ((NFCSTATUS_PENDING == status )?
511                                        NFCSTATUS_SUCCESS : status); */
512                }
513                break;
514            }
515            case PIPE_READER_A_CREATE:
516            {
517                phHciNfc_Gate_Info_t        id_dest;
518
519                id_dest.host_id = (uint8_t)phHciNfc_HostControllerID;
520                id_dest.gate_id = (uint8_t)phHciNfc_RFReaderAGate;
521
522                status = phHciNfc_ReaderA_Init_Resources (psHciContext);
523                if((status == NFCSTATUS_SUCCESS)
524#ifdef ESTABLISH_SESSION
525                    && (hciMode_Session != psHciContext->hci_mode)
526#endif
527                    )
528                {
529                    status = phHciNfc_Create_Pipe( psHciContext, pHwRef,
530                                &id_dest, &p_pipe_info);
531                    /* status = ((NFCSTATUS_PENDING == status )?
532                                        NFCSTATUS_SUCCESS : status); */
533                }
534                break;
535            }
536#ifdef TYPE_B
537            case PIPE_READER_B_CREATE:
538            {
539                phHciNfc_Gate_Info_t        id_dest;
540
541                id_dest.host_id = (uint8_t)phHciNfc_HostControllerID;
542                id_dest.gate_id = (uint8_t)phHciNfc_RFReaderBGate;
543
544                status = phHciNfc_ReaderB_Init_Resources (psHciContext);
545                if((status == NFCSTATUS_SUCCESS)
546#ifdef ESTABLISH_SESSION
547                    && (hciMode_Session != psHciContext->hci_mode)
548#endif
549                    )
550                {
551                    status = phHciNfc_Create_Pipe( psHciContext, pHwRef,
552                                &id_dest, &p_pipe_info);
553                    /* status = ((NFCSTATUS_PENDING == status )?
554                                        NFCSTATUS_SUCCESS : status); */
555                }
556                break;
557            }
558/* #ifdef TYPE_B*/
559#endif
560#ifdef TYPE_FELICA
561            case PIPE_READER_F_CREATE:
562            {
563                phHciNfc_Gate_Info_t        id_dest;
564
565                id_dest.host_id = (uint8_t)phHciNfc_HostControllerID;
566                id_dest.gate_id = (uint8_t)phHciNfc_RFReaderFGate;
567
568                status = phHciNfc_Felica_Init_Resources (psHciContext);
569                if((status == NFCSTATUS_SUCCESS)
570#ifdef ESTABLISH_SESSION
571                    && (hciMode_Session != psHciContext->hci_mode)
572#endif
573                    )
574                {
575                    status = phHciNfc_Create_Pipe( psHciContext, pHwRef,
576                                &id_dest, &p_pipe_info);
577                    /* status = ((NFCSTATUS_PENDING == status )?
578                                        NFCSTATUS_SUCCESS : status); */
579                }
580                break;
581            }
582#endif
583#ifdef TYPE_JEWEL
584            case PIPE_READER_JWL_CREATE:
585            {
586                phHciNfc_Gate_Info_t        id_dest;
587
588                id_dest.host_id = (uint8_t)phHciNfc_HostControllerID;
589                id_dest.gate_id = (uint8_t)phHciNfc_JewelReaderGate;
590
591                status = phHciNfc_Jewel_Init_Resources (psHciContext);
592                if((status == NFCSTATUS_SUCCESS)
593#ifdef ESTABLISH_SESSION
594                    && (hciMode_Session != psHciContext->hci_mode)
595#endif
596                    )
597                {
598                    status = phHciNfc_Create_Pipe( psHciContext, pHwRef,
599                                &id_dest, &p_pipe_info);
600                    /* status = ((NFCSTATUS_PENDING == status )?
601                                        NFCSTATUS_SUCCESS : status); */
602                }
603                break;
604            }
605#endif /* #ifdef TYPE_JEWEL */
606#ifdef TYPE_ISO15693
607            case PIPE_READER_ISO15693_CREATE:
608            {
609                phHciNfc_Gate_Info_t        id_dest;
610
611                id_dest.host_id = (uint8_t)phHciNfc_HostControllerID;
612                id_dest.gate_id = (uint8_t)phHciNfc_ISO15693Gate;
613
614                status = phHciNfc_ISO15693_Init_Resources (psHciContext);
615                if((status == NFCSTATUS_SUCCESS)
616#ifdef ESTABLISH_SESSION
617                    && (hciMode_Session != psHciContext->hci_mode)
618#endif
619                    )
620                {
621                    status = phHciNfc_Create_Pipe( psHciContext, pHwRef,
622                                &id_dest, &p_pipe_info);
623                    /* status = ((NFCSTATUS_PENDING == status )?
624                                        NFCSTATUS_SUCCESS : status); */
625                }
626                break;
627            }
628#endif /* #ifdef TYPE_ISO15693 */
629            case PIPE_NFC_INITIATOR_CREATE:
630            {
631                phHciNfc_Gate_Info_t        id_dest;
632
633                id_dest.host_id = (uint8_t)phHciNfc_HostControllerID;
634                id_dest.gate_id = (uint8_t)phHciNfc_NFCIP1InitRFGate;
635#ifdef ENABLE_P2P
636                status = phHciNfc_Initiator_Init_Resources (psHciContext);
637                if((status == NFCSTATUS_SUCCESS)
638#ifdef ESTABLISH_SESSION
639                    && (hciMode_Session != psHciContext->hci_mode)
640#endif
641                    )
642                {
643                    status = phHciNfc_Create_Pipe( psHciContext, pHwRef,
644                                &id_dest, &p_pipe_info);
645                    /* status = ((NFCSTATUS_PENDING == status )?
646                                        NFCSTATUS_SUCCESS : status); */
647                }
648#endif
649                break;
650            }
651            case PIPE_NFC_TARGET_CREATE:
652            {
653                phHciNfc_Gate_Info_t        id_dest;
654
655                id_dest.host_id = (uint8_t)phHciNfc_HostControllerID;
656                id_dest.gate_id = (uint8_t)phHciNfc_NFCIP1TargetRFGate;
657
658#ifdef ENABLE_P2P
659                status = phHciNfc_Target_Init_Resources (psHciContext);
660                if((status == NFCSTATUS_SUCCESS)
661#ifdef ESTABLISH_SESSION
662                    && (hciMode_Session != psHciContext->hci_mode)
663#endif
664                    )
665                {
666                    status = phHciNfc_Create_Pipe( psHciContext, pHwRef,
667                                &id_dest, &p_pipe_info);
668                    /* status = ((NFCSTATUS_PENDING == status )?
669                                        NFCSTATUS_SUCCESS : status); */
670                }
671#endif
672                break;
673            }
674            case PIPE_WI_CREATE:
675            {
676                phHciNfc_Gate_Info_t        id_dest;
677
678                id_dest.host_id = (uint8_t)phHciNfc_HostControllerID;
679                id_dest.gate_id = (uint8_t)phHciNfc_NfcWIMgmtGate;
680
681                status = phHciNfc_WI_Init_Resources ( psHciContext );
682                if((status == NFCSTATUS_SUCCESS)
683#ifdef ESTABLISH_SESSION
684                    && (hciMode_Session != psHciContext->hci_mode)
685#endif
686                    )
687                {
688                    status = phHciNfc_Create_Pipe( psHciContext, pHwRef,
689                                &id_dest, &p_pipe_info);
690                     /* status = ((NFCSTATUS_PENDING == status )?
691                                        NFCSTATUS_SUCCESS : status); */
692                }
693                break;
694            }
695            case PIPE_SWP_CREATE:
696            {
697                phHciNfc_Gate_Info_t        id_dest;
698
699                id_dest.host_id = (uint8_t)phHciNfc_HostControllerID;
700                id_dest.gate_id = (uint8_t)phHciNfc_SwpMgmtGate;
701
702                status = phHciNfc_SWP_Init_Resources ( psHciContext );
703
704                if((status == NFCSTATUS_SUCCESS)
705#ifdef ESTABLISH_SESSION
706                    && (hciMode_Session != psHciContext->hci_mode)
707#endif
708                    )
709                {
710                    status = phHciNfc_Create_Pipe( psHciContext, pHwRef,
711                                &id_dest, &p_pipe_info);
712                    status = ((NFCSTATUS_PENDING == status )?
713                                        NFCSTATUS_SUCCESS : status);
714                }
715                break;
716            }
717            /* case PIPE_MGMT_END : */
718            default:
719            {
720                status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_SEQUENCE);
721                break;
722            }
723
724        } /* End of Pipe Seq Switch */
725
726    } /* End of Null Check for the Context */
727
728    return status;
729}
730
731/*!
732 * \brief Deletes the Pipes of all the Supported Gates .
733 *
734 * This function Deletes the pipes for all the supported gates
735 */
736
737NFCSTATUS
738phHciNfc_Delete_All_Pipes(
739                                phHciNfc_sContext_t             *psHciContext,
740                                void                            *pHwRef,
741                                phHciNfc_PipeMgmt_Seq_t         pipeSeq
742                             )
743{
744    NFCSTATUS                           status = NFCSTATUS_SUCCESS;
745    phHciNfc_Pipe_Info_t                *p_pipe_info = NULL;
746    uint8_t                             length = 0;
747
748    if( (NULL == psHciContext) || (NULL == pHwRef) )
749    {
750      status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
751    }
752    else
753    {
754        /* pipeSeq = PIPE_DELETE_ALL; */
755
756        if ( PIPE_DELETE_ALL == pipeSeq )
757        {
758            /* Admin pipe close sequence */
759            p_pipe_info = psHciContext->p_pipe_list[PIPETYPE_STATIC_ADMIN];
760            status = phHciNfc_Send_Admin_Cmd( psHciContext,
761                                    pHwRef, ADM_CLEAR_ALL_PIPE,
762                                        length, p_pipe_info);
763            status = ((NFCSTATUS_PENDING == status)?
764                                NFCSTATUS_SUCCESS : status);
765        }
766        else
767        {
768            status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_SEQUENCE);
769        }
770
771
772    } /* End of Null Check for the Context */
773
774    return status;
775}
776
777
778
779NFCSTATUS
780phHciNfc_Update_PipeInfo(
781                                phHciNfc_sContext_t             *psHciContext,
782                                phHciNfc_PipeMgmt_Seq_t         *pPipeSeq,
783                                uint8_t                         pipe_id,
784                                phHciNfc_Pipe_Info_t            *pPipeInfo
785                      )
786{
787    phHciNfc_GateID_t           gate_id = phHciNfc_UnknownGate;
788    NFCSTATUS                   status = NFCSTATUS_SUCCESS;
789
790    if(
791        (NULL == psHciContext) || (NULL == pPipeSeq)
792        || ( NULL == pPipeInfo )
793      )
794    {
795        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
796    }
797    else
798    {
799        gate_id = (phHciNfc_GateID_t )pPipeInfo->pipe.dest.gate_id ;
800        switch( gate_id )
801        {
802            /* Identity Management Pipe Creation */
803            case phHciNfc_IdentityMgmtGate:
804            {
805                status = phHciNfc_IDMgmt_Update_PipeInfo(psHciContext,
806                            pipe_id, pPipeInfo);
807                if(NFCSTATUS_SUCCESS == status)
808                {
809                    *pPipeSeq = PIPE_PN544MGMT_CREATE;
810                }
811                break;
812            }
813            case  phHciNfc_PN544MgmtGate:
814            {
815                status = phHciNfc_DevMgmt_Update_PipeInfo(psHciContext,
816                            pipe_id, pPipeInfo);
817                if(NFCSTATUS_SUCCESS == status)
818                {
819                    *pPipeSeq = ( HCI_SELF_TEST != psHciContext->init_mode )?
820                                PIPE_POLLINGLOOP_CREATE:PIPE_DELETE_ALL;
821                }
822                break;
823            }
824            case  phHciNfc_PollingLoopGate:
825            {
826                status = phHciNfc_PollLoop_Update_PipeInfo(psHciContext,
827                            pipe_id, pPipeInfo);
828                if(NFCSTATUS_SUCCESS == status)
829                {
830                    *pPipeSeq = PIPE_READER_A_CREATE;
831                }
832                break;
833            }
834            case  phHciNfc_RFReaderAGate:
835            {
836                status = phHciNfc_ReaderA_Update_PipeInfo(psHciContext,
837                            pipe_id, pPipeInfo);
838                if(NFCSTATUS_SUCCESS == status)
839                {
840
841#if defined (TYPE_B)
842                    *pPipeSeq = PIPE_READER_B_CREATE;
843/* #if defined (TYPE_B) */
844#elif defined (TYPE_FELICA)
845                    *pPipeSeq = PIPE_READER_F_CREATE;
846/* #if defined (TYPE_FELICA) */
847#elif defined (TYPE_JEWEL)
848                    *pPipeSeq = PIPE_READER_JWL_CREATE;
849/* #if defined (TYPE_JEWEL) */
850#elif defined (TYPE_ISO15693)
851                    *pPipeSeq = PIPE_READER_ISO15693_CREATE;
852/* #if defined (TYPE_ISO15693) */
853#elif  defined(ENABLE_P2P)
854                    *pPipeSeq = PIPE_NFC_INITIATOR_CREATE;
855/* #if defined(ENABLE_P2P) */
856 /*lint -e{91} suppress "Line exceeds"*/
857#elif !defined(TYPE_B) && !defined(TYPE_FELICA) && !defined(TYPE_JEWEL) && !defined(TYPE_ISO15693) && !defined(ENABLE_P2P)
858                    *pPipeSeq = PIPE_WI_CREATE;
859#endif
860                }
861                break;
862            }
863#ifdef TYPE_B
864            case  phHciNfc_RFReaderBGate:
865            {
866                status = phHciNfc_ReaderB_Update_PipeInfo(psHciContext,
867                            pipe_id, pPipeInfo);
868                if(NFCSTATUS_SUCCESS == status)
869                {
870#if defined (TYPE_FELICA)
871                    *pPipeSeq = PIPE_READER_F_CREATE;
872/* #if defined (TYPE_FELICA) */
873#elif defined (TYPE_JEWEL)
874                    *pPipeSeq = PIPE_READER_JWL_CREATE;
875/* #if defined (TYPE_JEWEL) */
876#elif defined (TYPE_ISO15693)
877                    *pPipeSeq = PIPE_READER_ISO15693_CREATE;
878/* #if defined (TYPE_ISO15693) */
879#elif  defined(ENABLE_P2P)
880                    *pPipeSeq = PIPE_NFC_INITIATOR_CREATE;
881/* #if defined(ENABLE_P2P) */
882 /*lint -e{91} suppress "Line exceeds"*/
883#elif !defined(TYPE_FELICA) && !defined(TYPE_JEWEL) && !defined(TYPE_ISO15693) && !defined(ENABLE_P2P)
884                    *pPipeSeq = PIPE_WI_CREATE;
885#endif
886                }
887                break;
888            }
889#endif
890#ifdef TYPE_FELICA
891            case  phHciNfc_RFReaderFGate:
892            {
893                status = phHciNfc_Felica_Update_PipeInfo(psHciContext,
894                            pipe_id, pPipeInfo);
895                if(NFCSTATUS_SUCCESS == status)
896                {
897#if defined (TYPE_JEWEL)
898                    *pPipeSeq = PIPE_READER_JWL_CREATE;
899/* #if defined (TYPE_JEWEL) */
900#elif defined (TYPE_ISO15693)
901                    *pPipeSeq = PIPE_READER_ISO15693_CREATE;
902/* #if defined (TYPE_ISO15693) */
903#elif  defined(ENABLE_P2P)
904                    *pPipeSeq = PIPE_NFC_INITIATOR_CREATE;
905/* #if defined(ENABLE_P2P) */
906#elif !defined(TYPE_JEWEL) && !defined(TYPE_ISO15693) && !defined(ENABLE_P2P)
907                    *pPipeSeq = PIPE_WI_CREATE;
908#endif
909                }
910                break;
911            }
912#endif
913#ifdef TYPE_JEWEL
914            case  phHciNfc_JewelReaderGate:
915            {
916                status = phHciNfc_Jewel_Update_PipeInfo(psHciContext,
917                            pipe_id, pPipeInfo);
918                if(NFCSTATUS_SUCCESS == status)
919                {
920#if defined (TYPE_ISO15693)
921                    *pPipeSeq = PIPE_READER_ISO15693_CREATE;
922/* #if defined (TYPE_ISO15693) */
923#elif  defined(ENABLE_P2P)
924                    *pPipeSeq = PIPE_NFC_INITIATOR_CREATE;
925/* #if defined(ENABLE_P2P) */
926#elif !defined(TYPE_ISO15693) && !defined(ENABLE_P2P)
927                    *pPipeSeq = PIPE_WI_CREATE;
928#endif
929                }
930                break;
931            }
932#endif /* #ifdef TYPE_JEWEL */
933#if defined (TYPE_ISO15693)
934            case  phHciNfc_ISO15693Gate:
935            {
936                status = phHciNfc_ISO15693_Update_PipeInfo(psHciContext,
937                            pipe_id, pPipeInfo);
938                if(NFCSTATUS_SUCCESS == status)
939                {
940
941#ifdef ENABLE_P2P
942                    *pPipeSeq = PIPE_NFC_INITIATOR_CREATE;
943#else
944                    *pPipeSeq = PIPE_WI_CREATE;
945#endif /* #ifdef ENABLE_P2P */
946                }
947                break;
948            }
949#endif /* #if defined (TYPE_ISO15693) */
950            case  phHciNfc_NFCIP1InitRFGate:
951            {
952#ifdef ENABLE_P2P
953                status = phHciNfc_Initiator_Update_PipeInfo(psHciContext,
954                            pipe_id, pPipeInfo);
955                if(NFCSTATUS_SUCCESS == status)
956                {
957                    *pPipeSeq = PIPE_NFC_TARGET_CREATE;
958                }
959#endif
960                break;
961            }
962            case  phHciNfc_NFCIP1TargetRFGate:
963            {
964#ifdef ENABLE_P2P
965                status = phHciNfc_Target_Update_PipeInfo(psHciContext,
966                            pipe_id, pPipeInfo);
967                if(NFCSTATUS_SUCCESS == status)
968                {
969                    *pPipeSeq = PIPE_WI_CREATE;
970                }
971#endif
972                break;
973            }
974            case  phHciNfc_NfcWIMgmtGate:
975            {
976                status = phHciNfc_WI_Update_PipeInfo(psHciContext,
977                            pipe_id, pPipeInfo);
978                if(NFCSTATUS_SUCCESS == status)
979                {
980                    *pPipeSeq = PIPE_SWP_CREATE;
981                }
982                break;
983            }
984            case  phHciNfc_SwpMgmtGate:
985            {
986                status = phHciNfc_SWP_Update_PipeInfo(psHciContext,
987                            pipe_id, pPipeInfo);
988                if(NFCSTATUS_SUCCESS == status)
989                {
990                    *pPipeSeq = PIPE_DELETE_ALL;
991                }
992                break;
993            }
994            case phHciNfc_ConnectivityGate:
995            {
996                status = phHciNfc_Uicc_Update_PipeInfo(psHciContext,
997                                pipe_id, pPipeInfo);
998                break;
999            }
1000#ifdef HOST_EMULATION
1001            case phHciNfc_CETypeAGate:
1002            {
1003                status = phHciNfc_CE_A_Update_PipeInfo(psHciContext,
1004                                pipe_id, pPipeInfo);
1005                if(NFCSTATUS_SUCCESS == status)
1006                {
1007                    *pPipeSeq = PIPE_CARD_B_CREATE;
1008                }
1009                break;
1010            }
1011            case phHciNfc_CETypeBGate:
1012            {
1013                status = phHciNfc_CE_B_Update_PipeInfo(psHciContext,
1014                                pipe_id, pPipeInfo);
1015                if(NFCSTATUS_SUCCESS == status)
1016                {
1017                    *pPipeSeq = PIPE_DELETE_ALL;
1018                }
1019                break;
1020            }
1021#endif
1022            case phHciNfc_UnknownGate:
1023            default:
1024            {
1025                status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_HCI_GATE_NOT_SUPPORTED );
1026                break;
1027            }
1028            /*End of the default Switch Case */
1029
1030        } /*End of the Index Switch */
1031    } /* End of Context and the Identity information validity check */
1032
1033    return status;
1034}
1035
1036
1037/*!
1038 * \brief Opening the Pipe
1039 *
1040 * This function opens the the pipe created between a terminal host's gate and
1041 *  destination host's gate
1042 *
1043 */
1044
1045NFCSTATUS
1046phHciNfc_Open_Pipe(
1047                        phHciNfc_sContext_t     *psHciContext,
1048                        void                    *pHwRef,
1049                        phHciNfc_Pipe_Info_t    *pPipeHandle
1050                    )
1051{
1052    uint8_t                 pipe_id = (uint8_t) HCI_UNKNOWN_PIPE_ID;
1053    NFCSTATUS               status = NFCSTATUS_SUCCESS;
1054    NFCSTATUS               cmd_status = NFCSTATUS_SUCCESS;
1055
1056    if( (NULL == psHciContext)
1057        || ( NULL == pHwRef )
1058        || ( NULL == pPipeHandle )
1059      )
1060    {
1061        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1062    }
1063    else
1064    {
1065        /* Obtain the pipe_id from the pipe_handle */
1066        pipe_id = pPipeHandle->pipe.pipe_id;
1067
1068        if ( pipe_id <= PHHCINFC_MAX_PIPE)
1069        {
1070            cmd_status = phHciNfc_Send_Generic_Cmd( psHciContext,pHwRef,
1071                                    pipe_id, ANY_OPEN_PIPE);
1072            status = ( (cmd_status == NFCSTATUS_PENDING)?
1073                                        NFCSTATUS_SUCCESS : cmd_status);
1074        }
1075    }
1076    return status;
1077}
1078
1079
1080/*!
1081 * \brief Closing the Pipe
1082 *
1083 * This function Closes the the pipe created between a terminal host's gate and
1084 *  destination host's gate
1085 *
1086 */
1087
1088NFCSTATUS
1089phHciNfc_Close_Pipe(
1090                        phHciNfc_sContext_t     *psHciContext,
1091                        void                    *pHwRef,
1092                        phHciNfc_Pipe_Info_t    *pPipeHandle
1093                    )
1094{
1095    uint8_t                 pipe_id = (uint8_t) HCI_UNKNOWN_PIPE_ID;
1096    NFCSTATUS               status = NFCSTATUS_SUCCESS;
1097    NFCSTATUS               cmd_status = NFCSTATUS_SUCCESS;
1098
1099    if( (NULL == psHciContext)
1100        || ( NULL == pHwRef )
1101        || ( NULL == pPipeHandle )
1102      )
1103    {
1104        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1105    }
1106    else
1107    {
1108        /* Obtain the pipe_id from the pipe_handle */
1109        pipe_id = pPipeHandle->pipe.pipe_id;
1110
1111        if( (uint8_t)HCI_UNKNOWN_PIPE_ID > pipe_id)
1112        {
1113            cmd_status = phHciNfc_Send_Generic_Cmd(
1114                                        psHciContext, pHwRef, pipe_id,
1115                                        ANY_CLOSE_PIPE );
1116
1117            status = ((cmd_status == NFCSTATUS_PENDING)?
1118                                NFCSTATUS_SUCCESS : cmd_status);
1119        }
1120    }
1121    return status;
1122}
1123