First add
[adaptation/devices/nfc-plugin-nxp.git] / src / phHciNfc_Emulation.c
1 /*\r
2  * Copyright (C) 2010 NXP Semiconductors\r
3  *\r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *\r
8  *      http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  */\r
16 \r
17 /*!\r
18 * =========================================================================== *\r
19 *                                                                             *\r
20 *                                                                             *\r
21 * \file  phHciNfc_Emulation.c                                                 *\r
22 * \brief HCI Emulation management routines.                              *\r
23 *                                                                             *\r
24 *                                                                             *\r
25 * Project: NFC-FRI-1.1                                                        *\r
26 *                                                                             *\r
27 * $Date: Tue Jun  8 09:30:37 2010 $                                           *\r
28 * $Author: ing04880 $                                                         *\r
29 * $Revision: 1.52 $                                                           *\r
30 * $Aliases: NFC_FRI1.1_WK1023_R35_1 $\r
31 *                                                                             *\r
32 * =========================================================================== *\r
33 */\r
34 \r
35 /*\r
36 ***************************** Header File Inclusion ****************************\r
37 */\r
38 #include <phNfcConfig.h>\r
39 #include <phNfcCompId.h>\r
40 #include <phNfcHalTypes.h>\r
41 #include <phHciNfc_Pipe.h>\r
42 #include <phHciNfc_Emulation.h>\r
43 #include <phHciNfc_WI.h>\r
44 #include <phHciNfc_SWP.h>\r
45 #ifdef ENABLE_P2P\r
46 #include <phHciNfc_NfcIPMgmt.h>\r
47 #endif\r
48 #ifdef HOST_EMULATION\r
49 #include <phHciNfc_CE_A.h>\r
50 #include <phHciNfc_CE_B.h>\r
51 #endif\r
52 #include <phOsalNfc.h>\r
53 /*\r
54 ****************************** Macro Definitions *******************************\r
55 */\r
56 \r
57 \r
58 \r
59 /*\r
60 *************************** Structure and Enumeration ***************************\r
61 */\r
62 \r
63 /** \defgroup grp_hci_nfc HCI Emulation Management Component\r
64 *\r
65 *\r
66 */\r
67 \r
68 typedef enum phHciNfc_EmulationMgmt_Seq{\r
69     NFCIP_TARGET_PIPE_OPEN  = 0x00U,\r
70     NFCIP_TARGET_MODE_CONFIG,\r
71     NFCIP_TARGET_MERGE_SAK,\r
72     NFCIP_TARGET_PIPE_CLOSE,\r
73 \r
74     HOST_CE_A_INIT,\r
75     HOST_CE_A_RELEASE,\r
76 \r
77     HOST_CE_B_INIT,\r
78     HOST_CE_B_RELEASE,\r
79 \r
80     WI_PIPE_OPEN,\r
81     WI_ENABLE_EMULATION,\r
82     WI_DEFAULT_EMULATION,\r
83     WI_DISABLE_EMULATION,\r
84 \r
85     WI_ENABLE_NOTIFICATION,\r
86     WI_DISABLE_NOTIFICATION,\r
87 \r
88     WI_SWITCH_WIRED_MODE,\r
89     WI_SWITCH_DEFAULT_MODE,\r
90 \r
91     WI_PIPE_CLOSE,\r
92 \r
93     SWP_PIPE_OPEN,\r
94     SWP_ENABLE_EMULATION,\r
95     SWP_DEFAULT_EMULATION,\r
96     SWP_DETECTION,\r
97     SWP_DISABLE_EMULATION,\r
98     SWP_GET_BIT_RATE,\r
99     SWP_PIPE_CLOSE,\r
100 \r
101     CONFIG_DEFAULT_EMULATION,\r
102 \r
103     END_EMULATION_SEQ\r
104 } phHciNfc_EmulationMgmt_Seq_t;\r
105 \r
106 typedef struct phHciNfc_EmulationMgmt_Info{\r
107     phHal_eEmulationType_t          se_default;\r
108     uint8_t                         smx_powerless;\r
109     uint8_t                         uicc_enable;\r
110     uint8_t                         uicc_powerless;\r
111     uint8_t                         uicc_id;\r
112     /* Application ID of the UICC Transaction performed */\r
113     uint8_t                         uicc_aid[MAX_AID_LEN];\r
114     uint8_t                         uicc_param[MAX_UICC_PARAM_LEN];\r
115     uint8_t                         uicc_param_len;\r
116     phHciNfc_Pipe_Info_t            *p_uicc_pipe_info;\r
117     phHciNfc_EmulationMgmt_Seq_t    emulation_cur_seq;\r
118     phHciNfc_EmulationMgmt_Seq_t    emulation_next_seq;\r
119 \r
120 \r
121 } phHciNfc_EmulationMgmt_Info_t;\r
122 \r
123 \r
124 /*\r
125 *************************** Static Function Declaration **************************\r
126 */\r
127 \r
128 static\r
129 NFCSTATUS\r
130 phHciNfc_Recv_Uicc_Cmd (\r
131                         void                *psContext,\r
132                         void                *pHwRef,\r
133                         uint8_t             *pCmd,\r
134 #ifdef ONE_BYTE_LEN\r
135                         uint8_t             length\r
136 #else\r
137                         uint16_t            length\r
138 #endif\r
139                      );\r
140 \r
141 static\r
142 NFCSTATUS\r
143 phHciNfc_Recv_Uicc_Event (\r
144                         void                *psContext,\r
145                         void                *pHwRef,\r
146                         uint8_t             *pEvent,\r
147 #ifdef ONE_BYTE_LEN\r
148                         uint8_t             length\r
149 #else\r
150                         uint16_t            length\r
151 #endif\r
152                      );\r
153 \r
154 \r
155 /*\r
156 *************************** Function Definitions ***************************\r
157 */\r
158 \r
159 void\r
160 phHciNfc_Uicc_Connectivity(\r
161                             phHciNfc_sContext_t     *psHciContext,\r
162                             void                    *pHwRef\r
163                         )\r
164 {\r
165     NFCSTATUS                       status = NFCSTATUS_SUCCESS;\r
166     phHciNfc_Pipe_Info_t            *pPipeInfo = NULL;\r
167     phHciNfc_EmulationMgmt_Info_t   *p_emulation_mgmt_info = NULL;\r
168 \r
169     if( NULL != psHciContext->p_emulation_mgmt_info )\r
170     {\r
171         p_emulation_mgmt_info = (phHciNfc_EmulationMgmt_Info_t *)\r
172                             psHciContext->p_emulation_mgmt_info ;\r
173         pPipeInfo = psHciContext->p_pipe_list[NXP_PIPE_CONNECTIVITY];\r
174         if( (TRUE == ((phHal_sHwReference_t *)pHwRef)->uicc_connected)\r
175             && (NULL == pPipeInfo))\r
176         {\r
177             status = phHciNfc_Allocate_Resource((void **)&pPipeInfo,\r
178                                                 sizeof(phHciNfc_Pipe_Info_t));\r
179             if((NULL != pPipeInfo)\r
180                 && (NFCSTATUS_SUCCESS == status))\r
181             {\r
182                 /* The Source Host is the UICC Host */\r
183                 pPipeInfo->pipe.source.host_id = \r
184                                     (uint8_t) phHciNfc_UICCHostID;\r
185                 /* The Source Gate is same as the Destination Gate */\r
186                 pPipeInfo->pipe.source.gate_id  = \r
187                                     (uint8_t)   phHciNfc_ConnectivityGate;\r
188                 /* The Destination Host is the Terminal Host */\r
189                 pPipeInfo->pipe.dest.host_id =  \r
190                                     (uint8_t) phHciNfc_TerminalHostID;\r
191                 /* The Source Gate is same as the Destination Gate */\r
192                 pPipeInfo->pipe.dest.gate_id    = \r
193                                     (uint8_t) phHciNfc_ConnectivityGate;\r
194                 /* The Pipe ID is Hardcoded to Connectivity */\r
195                 pPipeInfo->pipe.pipe_id = (uint8_t) NXP_PIPE_CONNECTIVITY;\r
196 \r
197 \r
198                 status = phHciNfc_Uicc_Update_PipeInfo(psHciContext,\r
199                                         NXP_PIPE_CONNECTIVITY, pPipeInfo);\r
200                 if (NFCSTATUS_SUCCESS == status)\r
201                 {\r
202                     psHciContext->p_pipe_list[NXP_PIPE_CONNECTIVITY] = pPipeInfo;\r
203                     p_emulation_mgmt_info->uicc_enable = TRUE;\r
204                 }\r
205                 else\r
206                 {\r
207                     (void)phOsalNfc_FreeMemory(pPipeInfo);\r
208                 }\r
209             }\r
210         }\r
211     }\r
212   return;\r
213 }\r
214 \r
215 /*!\r
216  * \brief Get the pipe_id of Connectivity Managment Gate.\r
217  *\r
218  * This function Get the pipe_id of Connectivity Managment Gate.\r
219  * \r
220  */\r
221 \r
222 \r
223 NFCSTATUS\r
224 phHciNfc_Uicc_Get_PipeID(\r
225                             phHciNfc_sContext_t     *psHciContext,\r
226                             uint8_t                 *ppipe_id\r
227                         )\r
228 {\r
229     NFCSTATUS                   status = NFCSTATUS_SUCCESS;\r
230     phHciNfc_EmulationMgmt_Info_t   *p_emulation_mgmt_info = NULL;\r
231     if( (NULL != psHciContext)\r
232         && ( NULL != ppipe_id )\r
233         && ( NULL != psHciContext->p_emulation_mgmt_info ) \r
234       )\r
235     {\r
236         p_emulation_mgmt_info = (phHciNfc_EmulationMgmt_Info_t *)\r
237                             psHciContext->p_emulation_mgmt_info ;\r
238         *ppipe_id =  p_emulation_mgmt_info->uicc_id  ;\r
239     }\r
240     else \r
241     {\r
242         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);\r
243     }\r
244     return status;\r
245 }\r
246 \r
247 \r
248 /* Function to Update the  Pipe Information */\r
249 NFCSTATUS\r
250 phHciNfc_Uicc_Update_PipeInfo(\r
251                                 phHciNfc_sContext_t     *psHciContext,\r
252                                 uint8_t                 pipe_id,\r
253                                 phHciNfc_Pipe_Info_t    *pPipeInfo\r
254                         )\r
255 {\r
256     phHciNfc_EmulationMgmt_Info_t   *p_emulation_mgmt_info=NULL;\r
257     NFCSTATUS                       status = NFCSTATUS_SUCCESS;\r
258 \r
259     if( NULL == psHciContext )\r
260     {\r
261         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);\r
262     }\r
263     else if ( NULL == psHciContext->p_emulation_mgmt_info )\r
264     {\r
265         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION);\r
266     }\r
267     else\r
268     {\r
269         p_emulation_mgmt_info = (phHciNfc_EmulationMgmt_Info_t *)\r
270                                 psHciContext->p_emulation_mgmt_info ;\r
271         /* Update the pipe_id of the Connectivity Gate \r
272          * obtained from the HCI Response */\r
273         p_emulation_mgmt_info->uicc_id = pipe_id;\r
274         p_emulation_mgmt_info->p_uicc_pipe_info = pPipeInfo;\r
275         if ( NULL != pPipeInfo)\r
276         {\r
277             /* Update the Response Receive routine of the Connectivity Gate */\r
278             /* pPipeInfo->recv_resp = phHciNfc_Recv_Uicc_Response; */\r
279             pPipeInfo->recv_cmd = &phHciNfc_Recv_Uicc_Cmd;\r
280             pPipeInfo->recv_event = &phHciNfc_Recv_Uicc_Event;\r
281         }\r
282     }\r
283 \r
284     return status;\r
285 }\r
286 \r
287 \r
288 /*!\r
289 * \brief Updates the Sequence of Emulation Managment Gate.\r
290 *\r
291 * This function Resets/Updates the sequence of the Emulation Management\r
292 * gate.\r
293\r
294 */\r
295 \r
296 \r
297 NFCSTATUS\r
298 phHciNfc_EmuMgmt_Update_Seq(\r
299                                 phHciNfc_sContext_t     *psHciContext,\r
300                                 phHciNfc_eSeqType_t     seq_type\r
301                         )\r
302 {\r
303     phHciNfc_EmulationMgmt_Info_t   *p_emulation_mgmt_info=NULL;\r
304     NFCSTATUS                       status = NFCSTATUS_SUCCESS;\r
305     if( NULL == psHciContext )\r
306     {\r
307         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);\r
308     }\r
309     else\r
310     {\r
311         if( NULL == psHciContext->p_emulation_mgmt_info )\r
312         {\r
313             status = PHNFCSTVAL(CID_NFC_HCI, \r
314                 NFCSTATUS_INVALID_HCI_INFORMATION);\r
315         }\r
316         else\r
317         {\r
318             p_emulation_mgmt_info = (phHciNfc_EmulationMgmt_Info_t *)\r
319                 psHciContext->p_emulation_mgmt_info ;\r
320             switch(seq_type)\r
321             {\r
322                 case RESET_SEQ:\r
323                 case INIT_SEQ:\r
324                 {\r
325 #ifdef ENABLE_P2P\r
326                     p_emulation_mgmt_info->emulation_cur_seq = NFCIP_TARGET_PIPE_OPEN;\r
327 #else\r
328                     p_emulation_mgmt_info->emulation_cur_seq = WI_PIPE_OPEN;\r
329 #endif\r
330                     p_emulation_mgmt_info->emulation_next_seq = END_EMULATION_SEQ ;\r
331                     break;\r
332                 }\r
333                 case UPDATE_SEQ:\r
334                 {\r
335                     p_emulation_mgmt_info->emulation_cur_seq = \r
336                         p_emulation_mgmt_info->emulation_next_seq;\r
337                     break;\r
338                 }\r
339                 case INFO_SEQ:\r
340                 {\r
341                     p_emulation_mgmt_info->emulation_cur_seq = SWP_ENABLE_EMULATION;\r
342                     p_emulation_mgmt_info->emulation_next_seq = END_EMULATION_SEQ ;\r
343                     break;\r
344                 }\r
345                 case REL_SEQ:\r
346                 {\r
347                     p_emulation_mgmt_info->emulation_cur_seq = WI_DISABLE_EMULATION;\r
348                     p_emulation_mgmt_info->emulation_next_seq = END_EMULATION_SEQ ;\r
349                     break;\r
350                 }\r
351                 default:\r
352                 {\r
353                     break;\r
354                 }\r
355             }\r
356         }\r
357     }\r
358 \r
359     return status;\r
360 }\r
361 \r
362 \r
363 /*!\r
364 * \brief Initialisation of RF Emulation Gates.\r
365 *\r
366 * This function initialses the RF Emulation Management and \r
367 * populates the Reader Management Information Structure\r
368\r
369 */\r
370 \r
371 \r
372 NFCSTATUS\r
373 phHciNfc_EmuMgmt_Initialise(\r
374                                phHciNfc_sContext_t      *psHciContext,\r
375                                void                 *pHwRef\r
376                            )\r
377 {\r
378     NFCSTATUS                       status = NFCSTATUS_SUCCESS;\r
379     phHciNfc_Pipe_Info_t            *p_pipe_info = NULL;\r
380     phHciNfc_EmulationMgmt_Info_t   *p_emulation_mgmt_info=NULL;\r
381 \r
382     if( NULL == psHciContext )\r
383     {\r
384         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);\r
385     }\r
386     else\r
387     {\r
388 \r
389         if( ( NULL == psHciContext->p_emulation_mgmt_info )\r
390             && (phHciNfc_Allocate_Resource((void **)(&p_emulation_mgmt_info),\r
391             sizeof(phHciNfc_EmulationMgmt_Info_t))== NFCSTATUS_SUCCESS)\r
392             )\r
393         {\r
394             psHciContext->p_emulation_mgmt_info = p_emulation_mgmt_info;\r
395 #ifdef ENABLE_P2P\r
396             p_emulation_mgmt_info->emulation_cur_seq = NFCIP_TARGET_PIPE_OPEN;\r
397 #else\r
398             p_emulation_mgmt_info->emulation_cur_seq = WI_PIPE_OPEN;\r
399 #endif\r
400             p_emulation_mgmt_info->emulation_next_seq = END_EMULATION_SEQ;\r
401             p_emulation_mgmt_info->uicc_id  = (uint8_t)HCI_UNKNOWN_PIPE_ID;\r
402         }\r
403         else\r
404         {\r
405             p_emulation_mgmt_info = (phHciNfc_EmulationMgmt_Info_t *)\r
406                 psHciContext->p_emulation_mgmt_info ;\r
407         }\r
408 \r
409         if( NULL == psHciContext->p_emulation_mgmt_info )\r
410         {\r
411             status = PHNFCSTVAL(CID_NFC_HCI, \r
412                 NFCSTATUS_INSUFFICIENT_RESOURCES);\r
413         }\r
414 #ifdef ESTABLISH_SESSION\r
415         else if(( hciMode_Session == psHciContext->hci_mode )\r
416             && (NFCIP_TARGET_PIPE_OPEN == p_emulation_mgmt_info->emulation_cur_seq )\r
417             )\r
418         {\r
419             status = NFCSTATUS_SUCCESS;\r
420         }\r
421 #endif\r
422         else\r
423         {\r
424             switch(p_emulation_mgmt_info->emulation_cur_seq )\r
425             {\r
426 #ifdef ENABLE_P2P\r
427                 /* NFCIP Target Open sequence */\r
428                 case NFCIP_TARGET_PIPE_OPEN:\r
429                 {\r
430                     p_pipe_info = ((phHciNfc_NfcIP_Info_t *)\r
431                         psHciContext->p_nfcip_info)->p_tgt_pipe_info;\r
432                     if(NULL == p_pipe_info )\r
433                     {\r
434                         status = PHNFCSTVAL(CID_NFC_HCI, \r
435                                     NFCSTATUS_INVALID_HCI_INFORMATION);\r
436                     }\r
437                     else\r
438                     {\r
439                         status = phHciNfc_Open_Pipe( psHciContext,\r
440                             pHwRef, p_pipe_info );\r
441                         if(status == NFCSTATUS_SUCCESS)\r
442                         {\r
443                             p_emulation_mgmt_info->emulation_next_seq =\r
444                                                     NFCIP_TARGET_MODE_CONFIG;\r
445                             status = NFCSTATUS_PENDING;\r
446                         }\r
447                     }\r
448                     break;\r
449                 }\r
450                 /* NFCIP Target Mode Config sequence */\r
451                 case NFCIP_TARGET_MODE_CONFIG:\r
452                 {\r
453 #define NFCIP_ACTIVE_SHIFT      0x03U\r
454 #define NFCIP_PASSIVE_MASK      0x07U\r
455                     uint8_t mode = ( NXP_NFCIP_ACTIVE_DEFAULT << NFCIP_ACTIVE_SHIFT ) |\r
456                                                                         ( DEFAULT_NFCIP_TARGET_MODE_SUPPORT & NFCIP_PASSIVE_MASK );\r
457                     status = phHciNfc_NfcIP_SetMode( psHciContext, pHwRef,\r
458                                                 NFCIP_TARGET, mode);\r
459                     if(status == NFCSTATUS_PENDING )\r
460                     {\r
461 #ifdef TGT_MERGE_SAK\r
462                         p_emulation_mgmt_info->emulation_next_seq =\r
463                                             NFCIP_TARGET_MERGE_SAK;\r
464 #else\r
465                         p_emulation_mgmt_info->emulation_next_seq =\r
466                                             WI_PIPE_OPEN;\r
467 #endif /* #ifdef TGT_MERGE_SAK */\r
468                         /* status = NFCSTATUS_SUCCESS; */\r
469                     }\r
470                     break;\r
471                 }\r
472 #ifdef TGT_MERGE_SAK\r
473                 /* NFCIP Target SAK Merge sequence */\r
474                 case NFCIP_TARGET_MERGE_SAK:\r
475                 {\r
476                     status = phHciNfc_NfcIP_SetMergeSak( psHciContext, pHwRef,\r
477                                                 TRUE );\r
478                     if(status == NFCSTATUS_PENDING )\r
479                     {\r
480                         p_emulation_mgmt_info->emulation_next_seq =\r
481                                             WI_PIPE_OPEN;\r
482                         /* status = NFCSTATUS_SUCCESS; */\r
483                     }\r
484                     break;\r
485                 }\r
486 #endif /* #ifdef TGT_MERGE_SAK */\r
487 #endif /* #ifdef ENABLE_P2P */\r
488                 /* Secure Element WI pipe open sequence */\r
489                 case WI_PIPE_OPEN:\r
490                 {\r
491                     p_pipe_info = ((phHciNfc_WI_Info_t *)\r
492                         psHciContext->p_wi_info)->p_pipe_info;\r
493                     if(NULL == p_pipe_info )\r
494                     {\r
495                         status = PHNFCSTVAL(CID_NFC_HCI, \r
496                                 NFCSTATUS_INVALID_HCI_INFORMATION);\r
497                     }\r
498                     else\r
499                     {\r
500                         status = phHciNfc_Open_Pipe( psHciContext,\r
501                                             pHwRef, p_pipe_info );\r
502                         if(status == NFCSTATUS_SUCCESS)\r
503                         {\r
504 #ifdef DISABLE_WI_NOTIFICATION\r
505                             p_emulation_mgmt_info->emulation_next_seq = \r
506                                                             SWP_PIPE_OPEN;\r
507 #else\r
508                             p_emulation_mgmt_info->emulation_next_seq = \r
509                                                             WI_ENABLE_NOTIFICATION;\r
510 #endif\r
511                             status = NFCSTATUS_PENDING;\r
512                         }\r
513                     }\r
514                     break;\r
515                 }\r
516                 /* Enable the SmartMx Notifications through WI */\r
517                 case WI_ENABLE_NOTIFICATION:\r
518                 {\r
519                     p_pipe_info = ((phHciNfc_WI_Info_t *)\r
520                                 psHciContext->p_wi_info)->p_pipe_info;\r
521                     if(NULL == p_pipe_info )\r
522                     {\r
523                         status = PHNFCSTVAL(CID_NFC_HCI, \r
524                                 NFCSTATUS_INVALID_HCI_INFORMATION);\r
525                     }\r
526                     else\r
527                     {\r
528                         status = phHciNfc_WI_Configure_Notifications( \r
529                                     psHciContext, pHwRef, eEnableEvents );\r
530                         if(status == NFCSTATUS_PENDING)\r
531                         {\r
532                             p_emulation_mgmt_info->emulation_next_seq = \r
533                                                                 SWP_PIPE_OPEN;\r
534                         }\r
535                     }\r
536                     break;\r
537                 }\r
538                 /* Enable the SmartMx Emulation by Default through WI */\r
539                 case WI_ENABLE_EMULATION:\r
540                 {\r
541                     p_pipe_info = ((phHciNfc_WI_Info_t *)\r
542                                 psHciContext->p_wi_info)->p_pipe_info;\r
543                     if(NULL == p_pipe_info )\r
544                     {\r
545                         status = PHNFCSTVAL(CID_NFC_HCI, \r
546                                 NFCSTATUS_INVALID_HCI_INFORMATION);\r
547                     }\r
548                     else\r
549                     {\r
550                         status = phHciNfc_WI_Configure_Default( psHciContext,\r
551                             pHwRef, TRUE );\r
552                         if(status == NFCSTATUS_PENDING)\r
553                         {\r
554                             p_emulation_mgmt_info->emulation_next_seq = \r
555                                                     SWP_PIPE_OPEN;\r
556                         }\r
557                     }\r
558                     break;\r
559                 }\r
560                 /* SWP pipe open sequence */\r
561                 case SWP_PIPE_OPEN:\r
562                 {\r
563                     p_pipe_info = ((phHciNfc_SWP_Info_t *)\r
564                         psHciContext->p_swp_info)->p_pipe_info;\r
565                     if(NULL == p_pipe_info )\r
566                     {\r
567                         status = PHNFCSTVAL(CID_NFC_HCI, \r
568                                 NFCSTATUS_INVALID_HCI_INFORMATION);\r
569                     }\r
570                     else\r
571                     {\r
572                         status = phHciNfc_Open_Pipe( psHciContext,\r
573                             pHwRef, p_pipe_info );\r
574                         if(status == NFCSTATUS_SUCCESS)\r
575                         {\r
576                             p_emulation_mgmt_info->emulation_next_seq = \r
577                                                             SWP_ENABLE_EMULATION;\r
578 #ifndef ESTABLISH_SESSION\r
579                             status = NFCSTATUS_PENDING;\r
580 #endif\r
581                         }\r
582                     }\r
583                     break;\r
584                 }\r
585                 /* Enable the UICC Emulation through SWP */\r
586                 case SWP_ENABLE_EMULATION:\r
587                 {\r
588                     p_pipe_info = ((phHciNfc_SWP_Info_t *)\r
589                         psHciContext->p_swp_info)->p_pipe_info;\r
590                     if(NULL == p_pipe_info )\r
591                     {\r
592                         status = PHNFCSTVAL(CID_NFC_HCI, \r
593                                 NFCSTATUS_INVALID_HCI_INFORMATION);\r
594                     }\r
595                     else\r
596                     {\r
597 #ifdef SWP_EVENT_USAGE\r
598                     status = phHciNfc_SWP_Configure_Mode( psHciContext, pHwRef, \r
599                         UICC_SWITCH_MODE_ON );\r
600                        /* UICC_SWITCH_MODE_DEFAULT */\r
601 #else\r
602                         status = phHciNfc_SWP_Configure_Default( psHciContext,\r
603                             pHwRef,   TRUE );\r
604 #endif\r
605                         if(status == NFCSTATUS_PENDING)\r
606                         {\r
607                             p_emulation_mgmt_info->emulation_next_seq = \r
608                                                     SWP_DETECTION;\r
609                             /* status = NFCSTATUS_SUCCESS; */\r
610                         }\r
611                     }\r
612                     break;\r
613                 }\r
614                 /* Disable the UICC Emulation through SWP */\r
615                 case SWP_DETECTION:\r
616                 {\r
617                     p_pipe_info = ((phHciNfc_SWP_Info_t *)\r
618                         psHciContext->p_swp_info)->p_pipe_info;\r
619                     if(NULL == p_pipe_info )\r
620                     {\r
621                         status = PHNFCSTVAL(CID_NFC_HCI, \r
622                                 NFCSTATUS_INVALID_HCI_INFORMATION);\r
623                         break;\r
624                     }\r
625                     else\r
626                     {\r
627                         status = phHciNfc_Uicc_Connect_Status(\r
628                                                     psHciContext, pHwRef );\r
629                         if(status == NFCSTATUS_SUCCESS)\r
630                         {\r
631                             uint8_t uicc_connect = ((phHciNfc_SWP_Info_t *)\r
632                                             psHciContext->p_swp_info)->uicc_status;\r
633                             if(UICC_CONNECTED == uicc_connect)\r
634                             {\r
635 #ifdef SWP_EVENT_USAGE\r
636                                 p_emulation_mgmt_info->emulation_next_seq = \r
637                                                     SWP_DISABLE_EMULATION;\r
638 #else\r
639                                 p_emulation_mgmt_info->emulation_next_seq = \r
640                                                     WI_DISABLE_EMULATION;\r
641 #endif\r
642                                 ((phHal_sHwReference_t  *)\r
643                                         pHwRef)->uicc_connected = TRUE;\r
644                                 status = NFCSTATUS_PENDING;\r
645                             }\r
646                             else\r
647                             {\r
648                                 status = phHciNfc_SWP_Configure_Mode( psHciContext,\r
649                                                 pHwRef,   UICC_SWITCH_MODE_DEFAULT );\r
650                                 (NFCSTATUS_PENDING == status)?\r
651                                     (p_emulation_mgmt_info->emulation_next_seq = \r
652                                     WI_DISABLE_EMULATION):\r
653                                     (p_emulation_mgmt_info->emulation_next_seq = \r
654                                         SWP_DETECTION);\r
655                                 break;\r
656                             }\r
657                         }\r
658                         else\r
659                         {\r
660                             break;\r
661                         }\r
662                     }\r
663                 }\r
664                 /* fall through */\r
665                 /* Disable the SmartMx Emulation through WI */\r
666                 case WI_DISABLE_EMULATION:\r
667                 {\r
668                     p_pipe_info = ((phHciNfc_WI_Info_t *)\r
669                                 psHciContext->p_wi_info)->p_pipe_info;\r
670                     if(NULL == p_pipe_info )\r
671                     {\r
672                         status = PHNFCSTVAL(CID_NFC_HCI, \r
673                                 NFCSTATUS_INVALID_HCI_INFORMATION);\r
674                     }\r
675                     else\r
676                     {\r
677                         status = phHciNfc_WI_Configure_Mode( psHciContext,\r
678                             pHwRef, eSmartMx_Default );\r
679                         if(status == NFCSTATUS_PENDING)\r
680                         {\r
681                             p_emulation_mgmt_info->emulation_next_seq = \r
682                                                     SWP_DISABLE_EMULATION;\r
683                             status = NFCSTATUS_SUCCESS;\r
684                         }\r
685                     }\r
686                     break;\r
687                 }\r
688 #ifndef SWP_EVENT_USAGE\r
689                 /* fall through */\r
690                 /* Get the UICC Baud Rate Status */\r
691                 case SWP_GET_BIT_RATE:\r
692                 {\r
693                     p_pipe_info = ((phHciNfc_SWP_Info_t *)\r
694                         psHciContext->p_swp_info)->p_pipe_info;\r
695                     if(NULL == p_pipe_info )\r
696                     {\r
697                         status = PHNFCSTVAL(CID_NFC_HCI, \r
698                                 NFCSTATUS_INVALID_HCI_INFORMATION);\r
699                     }\r
700                     else\r
701                     {\r
702                         status = phHciNfc_SWP_Get_Bitrate(\r
703                                                     psHciContext, pHwRef );\r
704                         if(status == NFCSTATUS_PENDING)\r
705                         {\r
706                             p_emulation_mgmt_info->emulation_next_seq = \r
707                                                     SWP_DISABLE_EMULATION;\r
708                             status = NFCSTATUS_SUCCESS;\r
709                         }\r
710                     }\r
711                     break;\r
712                 }\r
713 #endif\r
714                 /* fall through */\r
715                 /* Disable the UICC Emulation through SWP */\r
716                 case SWP_DISABLE_EMULATION:\r
717                 {\r
718                     p_pipe_info = ((phHciNfc_SWP_Info_t *)\r
719                         psHciContext->p_swp_info)->p_pipe_info;\r
720                     if(NULL == p_pipe_info )\r
721                     {\r
722                         status = PHNFCSTVAL(CID_NFC_HCI, \r
723                                 NFCSTATUS_INVALID_HCI_INFORMATION);\r
724                     }\r
725                     else\r
726                     {\r
727                         status = phHciNfc_SWP_Configure_Mode( psHciContext,\r
728                             pHwRef,   UICC_SWITCH_MODE_DEFAULT );\r
729                         if(status == NFCSTATUS_PENDING)\r
730                         {\r
731                             p_emulation_mgmt_info->emulation_next_seq = \r
732                                                     WI_DISABLE_EMULATION;\r
733                             /* Disable WI Emulation for Previous Wired \r
734                              * Mode Set */\r
735                             /* status = NFCSTATUS_SUCCESS; */\r
736                         }\r
737                     }\r
738                     break;\r
739                 }\r
740                 default:\r
741                 {\r
742                     status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_SEQUENCE);\r
743                     break;\r
744                 }\r
745 \r
746             }/* End of the Sequence Switch */\r
747 \r
748         }/* End of the Reader Info Memory Check */\r
749 \r
750     } /* End of Null Context Check */\r
751 \r
752     return status;\r
753 }\r
754 \r
755 /*!\r
756 * \brief Connection Routine for the Uicc.\r
757 *\r
758 * This function tries to enable and initialise the UICC connected \r
759 * through SWP.\r
760\r
761 */\r
762 \r
763 \r
764 NFCSTATUS\r
765 phHciNfc_Uicc_Connect_Status(\r
766                                phHciNfc_sContext_t  *psHciContext,\r
767                                void                 *pHwRef\r
768                       )\r
769 {\r
770     NFCSTATUS                       status = NFCSTATUS_SUCCESS;\r
771     /* phHciNfc_Pipe_Info_t         *p_pipe_info = NULL; */\r
772     /* phHciNfc_EmulationMgmt_Info_t    *p_emulation_mgmt_info=NULL; */\r
773     static uint32_t                  uicc_connection_retry = 0;\r
774 \r
775     if( NULL == psHciContext )\r
776     {\r
777         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);\r
778     }\r
779     else\r
780     {\r
781         phHciNfc_SWP_Status_t uicc_status = \r
782             ((phHciNfc_SWP_Info_t *)\r
783             psHciContext->p_swp_info)->uicc_status;\r
784         if(uicc_connection_retry == 0)\r
785         {\r
786 #ifdef UICC_STATUS_DELAY\r
787             for( ;uicc_connection_retry < UICC_STATUS_DELAY_COUNT; \r
788                             uicc_connection_retry ++ );\r
789             uicc_connection_retry = 0;\r
790 #endif\r
791             status = phHciNfc_SWP_Get_Status(\r
792                                 psHciContext, pHwRef );\r
793             if (NFCSTATUS_PENDING == status)\r
794             {\r
795                 uicc_connection_retry++;\r
796             }\r
797         }\r
798         else\r
799         {\r
800             switch(uicc_status)\r
801             {\r
802                 case UICC_CONNECTION_ONGOING:\r
803                 case UICC_DISCONNECTION_ONGOING:\r
804                 case UICC_NOT_CONNECTED:\r
805                 {\r
806                     if(uicc_connection_retry < \r
807                                     UICC_MAX_CONNECT_RETRY)\r
808                     {\r
809                         status = phHciNfc_SWP_Get_Status(\r
810                                             psHciContext, pHwRef );\r
811                         if (NFCSTATUS_PENDING == status)\r
812                         {\r
813                             uicc_connection_retry++;\r
814                         }\r
815                     }\r
816                     break;\r
817                 }\r
818                 case UICC_CONNECTED:\r
819                 {\r
820                     break;\r
821                 }\r
822                 case UICC_CONNECTION_LOST:\r
823                 case UICC_CONNECTION_FAILED:\r
824                 default:\r
825                 {\r
826                     uicc_connection_retry = 0;\r
827                     break;\r
828                 }\r
829             } /* End of the Status Switch */\r
830         }\r
831 \r
832         if( NFCSTATUS_PENDING != status )\r
833         {\r
834             uicc_connection_retry = 0;\r
835             /* Error Scenario due to SWP Disable Config */\r
836         }\r
837 \r
838     } /* End of Null Context Check */\r
839 \r
840     return status;\r
841 }\r
842 \r
843 /*!\r
844 * \brief Release of RF Emulation Gate Configuration.\r
845 *\r
846 * This function initialses the RF Emulation Management and \r
847 * populates the Reader Management Information Structure\r
848\r
849 */\r
850 \r
851 \r
852 NFCSTATUS\r
853 phHciNfc_EmuMgmt_Release(\r
854                                phHciNfc_sContext_t      *psHciContext,\r
855                                void                 *pHwRef\r
856                            )\r
857 {\r
858     NFCSTATUS                       status = NFCSTATUS_SUCCESS;\r
859     phHciNfc_Pipe_Info_t            *p_pipe_info = NULL;\r
860     phHciNfc_EmulationMgmt_Info_t   *p_emulation_mgmt_info=NULL;\r
861 \r
862     if( NULL == psHciContext )\r
863     {\r
864         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);\r
865     }\r
866     else\r
867     {\r
868 \r
869         p_emulation_mgmt_info = (phHciNfc_EmulationMgmt_Info_t *)\r
870             psHciContext->p_emulation_mgmt_info ;\r
871 \r
872         if( NULL == psHciContext->p_emulation_mgmt_info )\r
873         {\r
874             status = PHNFCSTVAL(CID_NFC_HCI, \r
875                 NFCSTATUS_INSUFFICIENT_RESOURCES);\r
876         }\r
877         else\r
878         {\r
879             switch(p_emulation_mgmt_info->emulation_cur_seq )\r
880             {\r
881                 /* Enable/Disable the SmartMx Emulation through WI\r
882                  * After the power down\r
883                  */\r
884                 /* Enable the SmartMx Emulation by Default through WI */\r
885                 case WI_DEFAULT_EMULATION:\r
886                 {\r
887                     p_pipe_info = ((phHciNfc_WI_Info_t *)\r
888                                 psHciContext->p_wi_info)->p_pipe_info;\r
889                     if(NULL == p_pipe_info )\r
890                     {\r
891                         status = PHNFCSTVAL(CID_NFC_HCI, \r
892                                 NFCSTATUS_INVALID_HCI_INFORMATION);\r
893                     }\r
894                     else\r
895                     {\r
896                         status = phHciNfc_WI_Configure_Default( psHciContext,\r
897                             pHwRef, p_emulation_mgmt_info->smx_powerless );\r
898                         if(status == NFCSTATUS_PENDING)\r
899                         {\r
900                             p_emulation_mgmt_info->emulation_next_seq = \r
901                                                     WI_DISABLE_EMULATION;\r
902                         }\r
903                     }\r
904                     break;\r
905                 }\r
906                 /* SmartMx In Default Mode */\r
907                 case WI_DISABLE_EMULATION:\r
908                 {\r
909                     p_pipe_info = ((phHciNfc_WI_Info_t *)\r
910                                 psHciContext->p_wi_info)->p_pipe_info;\r
911                     if(NULL == p_pipe_info )\r
912                     {\r
913                         status = PHNFCSTVAL(CID_NFC_HCI, \r
914                                 NFCSTATUS_INVALID_HCI_INFORMATION);\r
915                     }\r
916                     else\r
917                     {\r
918                         status = phHciNfc_WI_Configure_Mode( psHciContext,\r
919                             pHwRef, eSmartMx_Default );\r
920                         if(status == NFCSTATUS_SUCCESS )\r
921                         {\r
922                             p_emulation_mgmt_info->emulation_next_seq = \r
923                                                         SWP_DISABLE_EMULATION;\r
924                             status = phHciNfc_EmuMgmt_Update_Seq(psHciContext, \r
925                                                                 UPDATE_SEQ);\r
926                             /* status = NFCSTATUS_PENDING; */\r
927                         }\r
928                     }\r
929                     break;\r
930                 }\r
931                 /* Enable/Disable the UICC Emulation through SWP\r
932                  * After the power down\r
933                  */\r
934                 /* Enable the UICC Emulation by Default through SWP */\r
935                 case SWP_DEFAULT_EMULATION:\r
936                 {\r
937                     p_pipe_info = ((phHciNfc_SWP_Info_t *)\r
938                         psHciContext->p_swp_info)->p_pipe_info;\r
939                     if(NULL == p_pipe_info )\r
940                     {\r
941                         status = PHNFCSTVAL(CID_NFC_HCI, \r
942                                 NFCSTATUS_INVALID_HCI_INFORMATION);\r
943                     }\r
944                     else\r
945                     {\r
946                         status = phHciNfc_SWP_Configure_Default( psHciContext,\r
947                             pHwRef, p_emulation_mgmt_info->uicc_powerless );\r
948                         if(status == NFCSTATUS_PENDING)\r
949                         {\r
950                             p_emulation_mgmt_info->emulation_next_seq = \r
951                                                             SWP_DISABLE_EMULATION;\r
952                             /* status = NFCSTATUS_SUCCESS; */\r
953                         }\r
954                     }\r
955                     break;\r
956                 }\r
957                 /* Disable the UICC Emulation through SWP */\r
958                 case SWP_DISABLE_EMULATION:\r
959                 {\r
960                     p_pipe_info = ((phHciNfc_SWP_Info_t *)\r
961                         psHciContext->p_swp_info)->p_pipe_info;\r
962                     if(NULL == p_pipe_info )\r
963                     {\r
964                         status = PHNFCSTVAL(CID_NFC_HCI, \r
965                                 NFCSTATUS_INVALID_HCI_INFORMATION);\r
966                     }\r
967                     else\r
968                     {\r
969                         status = phHciNfc_SWP_Configure_Mode( psHciContext,\r
970                             pHwRef, UICC_SWITCH_MODE_DEFAULT );\r
971                         if(status == NFCSTATUS_PENDING)\r
972                         {\r
973                             p_emulation_mgmt_info->emulation_next_seq = \r
974                                                 CONFIG_DEFAULT_EMULATION;\r
975                             status = phHciNfc_EmuMgmt_Update_Seq(psHciContext, \r
976                                                                 UPDATE_SEQ);\r
977                             status = NFCSTATUS_SUCCESS;\r
978                         }\r
979                     }\r
980                     break;\r
981                 }\r
982                 /* Configure the Default Secure Element Emulation */\r
983                 case CONFIG_DEFAULT_EMULATION:\r
984                 {\r
985 #if 0\r
986                     if(NULL == p_pipe_info )\r
987                     {\r
988                         status = PHNFCSTVAL(CID_NFC_HCI, \r
989                                 NFCSTATUS_INVALID_HCI_INFORMATION);\r
990                     }\r
991                     else\r
992                     {\r
993                         /* status = phHciNfc_DevMgmt_Configure( psHciContext,\r
994                             pHwRef, , ); */\r
995                         if(status == NFCSTATUS_PENDING)\r
996                         {\r
997                             p_emulation_mgmt_info->emulation_next_seq = \r
998                                                             END_EMULATION_SEQ;\r
999                             status = phHciNfc_EmuMgmt_Update_Seq(psHciContext, \r
1000                                                                 UPDATE_SEQ);\r
1001                             status = NFCSTATUS_SUCCESS;\r
1002                         }\r
1003                     }\r
1004 #endif\r
1005                     break;\r
1006                 }\r
1007                 default:\r
1008                 {\r
1009                     status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_SEQUENCE);\r
1010                     break;\r
1011                 }\r
1012 \r
1013             }/* End of the Sequence Switch */\r
1014 \r
1015         }/* End of the Reader Info Memory Check */\r
1016 \r
1017     } /* End of Null Context Check */\r
1018 \r
1019     return status;\r
1020 }\r
1021 \r
1022 #if 0\r
1023 NFCSTATUS\r
1024 phHciNfc_Emulation_Start (\r
1025                         phHciNfc_sContext_t     *psHciContext,\r
1026                         void                    *pHwRef\r
1027                         )\r
1028 {\r
1029     NFCSTATUS                       status = NFCSTATUS_SUCCESS;\r
1030 \r
1031     return status;\r
1032 }\r
1033 #endif\r
1034 \r
1035 NFCSTATUS\r
1036 phHciNfc_Emulation_Cfg (\r
1037                         phHciNfc_sContext_t     *psHciContext,\r
1038                         void                    *pHwRef,\r
1039                         phHciNfc_eConfigType_t  cfg_type\r
1040                        )\r
1041 {\r
1042     NFCSTATUS                       status = NFCSTATUS_SUCCESS;\r
1043     phHciNfc_EmulationMgmt_Info_t   *p_emulation_mgmt_info=NULL;\r
1044     phHal_sEmulationCfg_t           *p_emulation_cfg = NULL;\r
1045 \r
1046     if( (NULL == psHciContext) || (NULL == pHwRef) )\r
1047     {\r
1048         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);\r
1049     }\r
1050     else if ( ( NULL == psHciContext->p_emulation_mgmt_info )\r
1051              || ( NULL == psHciContext->p_config_params ) )\r
1052     {\r
1053         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION);\r
1054     }\r
1055     else\r
1056     {\r
1057         p_emulation_mgmt_info = (phHciNfc_EmulationMgmt_Info_t *)\r
1058             psHciContext->p_emulation_mgmt_info ;\r
1059         p_emulation_cfg = psHciContext->p_config_params;\r
1060         switch(cfg_type)\r
1061         {\r
1062             case SMX_WI_CFG:\r
1063             {\r
1064                 phHal_sSmartMX_Cfg_t   *smx_config = \r
1065                                         &p_emulation_cfg->config.smartMxCfg;\r
1066                 p_emulation_mgmt_info->smx_powerless = \r
1067                                         (uint8_t)(FALSE != smx_config->lowPowerMode );\r
1068                 status = phHciNfc_WI_Configure_Default( psHciContext, pHwRef, \r
1069                                                 smx_config->enableEmulation );\r
1070                 break;\r
1071             }\r
1072             case UICC_SWP_CFG:\r
1073             {\r
1074 #ifdef SWP_CFG_SEQ\r
1075                 phHal_sUiccEmuCfg_t   *uicc_config = \r
1076                                     &p_emulation_cfg->config.uiccEmuCfg;\r
1077                 p_emulation_mgmt_info->uicc_powerless = \r
1078                                         (uint8_t)(FALSE != uicc_config->lowPowerMode );\r
1079                 {\r
1080 #ifdef SWP_EVENT_USAGE\r
1081                     status = phHciNfc_SWP_Configure_Mode( psHciContext, pHwRef, \r
1082                         ((TRUE == uicc_config->enableUicc)? /* UICC_SWITCH_MODE_DEFAULT */\r
1083                         UICC_SWITCH_MODE_ON :UICC_SWITCH_MODE_OFF));\r
1084 #else\r
1085                     status = phHciNfc_SWP_Configure_Default( psHciContext, pHwRef, \r
1086                                                 uicc_config->enableUicc );\r
1087 #endif\r
1088                 }\r
1089 #else\r
1090                 status = phHciNfc_SWP_Config_Sequence( psHciContext, \r
1091                                                         pHwRef, p_emulation_cfg);\r
1092 #endif\r
1093                 break;\r
1094             }\r
1095             case SWP_EVT_CFG:\r
1096             {\r
1097                 phHal_sUiccEmuCfg_t   *uicc_config = \r
1098                                     &p_emulation_cfg->config.uiccEmuCfg;\r
1099                 p_emulation_mgmt_info->uicc_powerless = \r
1100                                         (uint8_t)(FALSE != uicc_config->lowPowerMode );\r
1101                 {\r
1102                     status = phHciNfc_SWP_Configure_Mode( psHciContext, pHwRef, \r
1103                         ((TRUE == uicc_config->enableUicc)? /* UICC_SWITCH_MODE_DEFAULT */\r
1104                         UICC_SWITCH_MODE_ON :UICC_SWITCH_MODE_DEFAULT));\r
1105                 }\r
1106                 break;\r
1107             }\r
1108 #ifdef HOST_EMULATION\r
1109             case NFC_CE_A_CFG:\r
1110             {\r
1111                 phHal_sHostEmuCfg_A_t *host_ce_a_cfg = \r
1112                         &p_emulation_cfg->config.hostEmuCfg_A;\r
1113                 if(host_ce_a_cfg->enableEmulation == TRUE )\r
1114                 {\r
1115                     status = phHciNfc_CE_A_Initialise( psHciContext, pHwRef); \r
1116                 }\r
1117                 else\r
1118                 {\r
1119                     status = phHciNfc_CE_A_Release( psHciContext, pHwRef);\r
1120                 }\r
1121                 break;\r
1122             }\r
1123             case NFC_CE_B_CFG:\r
1124             {\r
1125                 phHal_sHostEmuCfg_B_t *host_ce_b_cfg = \r
1126                         &p_emulation_cfg->config.hostEmuCfg_B;\r
1127                 if(host_ce_b_cfg->enableEmulation == TRUE )\r
1128                 {\r
1129                     status = phHciNfc_CE_B_Initialise( psHciContext, pHwRef); \r
1130                 }\r
1131                 else\r
1132                 {\r
1133                     status = phHciNfc_CE_B_Release( psHciContext, pHwRef);\r
1134                 }\r
1135                 break;\r
1136             }\r
1137 #endif\r
1138             /* case INVALID_CFG:\r
1139             case POLL_LOOP_CFG: */\r
1140             default:\r
1141             {\r
1142                 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION);\r
1143                 break;\r
1144             }\r
1145 \r
1146         } /* End of the Configuration Switch */\r
1147     }\r
1148 \r
1149     return status;\r
1150 }\r
1151 \r
1152 \r
1153 static\r
1154 NFCSTATUS\r
1155 phHciNfc_Recv_Uicc_Cmd (\r
1156                         void                *psContext,\r
1157                         void                *pHwRef,\r
1158                         uint8_t             *pCmd,\r
1159 #ifdef ONE_BYTE_LEN\r
1160                         uint8_t             length\r
1161 #else\r
1162                         uint16_t            length\r
1163 #endif\r
1164                      )\r
1165 {\r
1166     uint8_t                     pipe_id = (uint8_t) HCI_UNKNOWN_PIPE_ID;\r
1167     uint8_t                     cmd = (uint8_t) HCP_MSG_INSTRUCTION_INVALID;\r
1168     uint8_t                     response = (uint8_t) ANY_OK;\r
1169     NFCSTATUS                   status = NFCSTATUS_SUCCESS;\r
1170     phHciNfc_sContext_t         *psHciContext = \r
1171                                     (phHciNfc_sContext_t *)psContext ;\r
1172     phHciNfc_HCP_Packet_t       *hcp_packet = NULL;\r
1173     phHciNfc_HCP_Message_t      *hcp_message = NULL;\r
1174     phHciNfc_Pipe_Info_t            *p_pipe_info = NULL;\r
1175     phHciNfc_EmulationMgmt_Info_t   *p_emulation_mgmt_info=NULL;\r
1176 \r
1177     if( (NULL == psHciContext) \r
1178         || (NULL == pHwRef) \r
1179         || (HCP_HEADER_LEN > length ) \r
1180       )\r
1181     {\r
1182       status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);\r
1183     }\r
1184     else\r
1185     {\r
1186         hcp_packet = (phHciNfc_HCP_Packet_t *)pCmd;\r
1187         hcp_message = &hcp_packet->msg.message;\r
1188         p_emulation_mgmt_info = psHciContext->p_emulation_mgmt_info;\r
1189 \r
1190         /* Get the Command instruction bits from the Message Header */\r
1191         cmd = (uint8_t) GET_BITS8( hcp_message->msg_header,\r
1192             HCP_MSG_INSTRUCTION_OFFSET, HCP_MSG_INSTRUCTION_LEN);\r
1193         pipe_id = p_emulation_mgmt_info->uicc_id;\r
1194         p_pipe_info = psHciContext->p_pipe_list[pipe_id];\r
1195 \r
1196         switch( cmd )\r
1197         {\r
1198             /* These are Commands are sent from the UICC Controller */\r
1199             case ANY_OPEN_PIPE:\r
1200             {\r
1201                 p_emulation_mgmt_info->uicc_enable = TRUE ;\r
1202                 break;\r
1203             }\r
1204             case ANY_CLOSE_PIPE:\r
1205             {\r
1206                 if(TRUE != p_emulation_mgmt_info->uicc_enable)\r
1207                 {\r
1208                     response = ANY_E_PIPE_NOT_OPENED;\r
1209                     /* status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FAILED); */\r
1210                 }\r
1211                 else\r
1212                 {\r
1213                     p_emulation_mgmt_info->uicc_enable = FALSE;\r
1214                 }\r
1215                 break;\r
1216             }\r
1217             case ANY_SET_PARAMETER:\r
1218             case ANY_GET_PARAMETER:\r
1219             case PRO_HOST_REQUEST:\r
1220             {\r
1221                 response = ANY_E_CMD_NOT_SUPPORTED;\r
1222                 /* status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_COMMAND_NOT_SUPPORTED);*/\r
1223                 break;\r
1224             }\r
1225             default:\r
1226             {\r
1227                 response = ANY_E_NOK;\r
1228                 /* status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_COMMAND); */\r
1229                 break;\r
1230             }\r
1231         }\r
1232         hcp_packet = (phHciNfc_HCP_Packet_t *) psHciContext->send_buffer;\r
1233         phHciNfc_Build_HCPFrame(hcp_packet,HCP_CHAINBIT_DEFAULT,\r
1234                                 pipe_id, HCP_MSG_TYPE_RESPONSE, response );\r
1235         psHciContext->tx_total = HCP_HEADER_LEN;\r
1236         status = phHciNfc_Send_HCP( (void *)psHciContext, (void *)pHwRef );\r
1237 \r
1238         p_pipe_info->recv_msg_type = HCP_MSG_TYPE_COMMAND;\r
1239         p_pipe_info->sent_msg_type = HCP_MSG_TYPE_RESPONSE;\r
1240         p_pipe_info->prev_msg = response ;\r
1241         p_pipe_info->prev_status = status;\r
1242         status = NFCSTATUS_SUCCESS;\r
1243 \r
1244     }\r
1245     return status;\r
1246 }\r
1247 \r
1248 static\r
1249 NFCSTATUS\r
1250 phHciNfc_Recv_Uicc_Event (\r
1251                         void                *psContext,\r
1252                         void                *pHwRef,\r
1253                         uint8_t             *pEvent,\r
1254 #ifdef ONE_BYTE_LEN\r
1255                         uint8_t             length\r
1256 #else\r
1257                         uint16_t            length\r
1258 #endif\r
1259                      )\r
1260 {\r
1261     uint8_t                     event = (uint8_t) HCP_MSG_INSTRUCTION_INVALID;\r
1262     uint32_t                     i = 0;\r
1263     NFCSTATUS                   status = NFCSTATUS_SUCCESS;\r
1264     phHciNfc_sContext_t         *psHciContext = \r
1265                                     (phHciNfc_sContext_t *)psContext ;\r
1266     phHciNfc_HCP_Packet_t           *hcp_packet = NULL;\r
1267     phHciNfc_HCP_Message_t          *hcp_message = NULL;\r
1268     phHal_sEventInfo_t              event_info;\r
1269     phHciNfc_EmulationMgmt_Info_t   *p_emulation_mgmt_info = \r
1270                                         psHciContext->p_emulation_mgmt_info ;\r
1271     \r
1272 \r
1273     if( (NULL == p_emulation_mgmt_info) \r
1274          || ( TRUE !=  p_emulation_mgmt_info->uicc_enable)\r
1275        )\r
1276     {\r
1277         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);\r
1278     }\r
1279     else\r
1280     {\r
1281         hcp_packet = (phHciNfc_HCP_Packet_t *)pEvent;\r
1282         hcp_message = &hcp_packet->msg.message;\r
1283 \r
1284         /* Get the Event instruction bits from the Message Header */\r
1285         event = (uint8_t) GET_BITS8( hcp_message->msg_header,\r
1286             HCP_MSG_INSTRUCTION_OFFSET, HCP_MSG_INSTRUCTION_LEN);\r
1287         event_info.eventHost = phHal_eUICCHost ;\r
1288         event_info.eventSource = phHal_ePICC_DevType ;\r
1289 \r
1290         switch( event )\r
1291         {\r
1292             case EVT_END_OF_TRANSACTION:\r
1293             {\r
1294                 event_info.eventType = NFC_EVT_END_OF_TRANSACTION;\r
1295                 break;\r
1296             }\r
1297             case EVT_TRANSACTION:\r
1298             {\r
1299                if(length > HCP_HEADER_LEN + TRANSACTION_MIN_LEN)\r
1300                {\r
1301                     event_info.eventType = NFC_EVT_TRANSACTION;\r
1302 \r
1303                     for(;i<(length-HCP_HEADER_LEN);)\r
1304                     {\r
1305                         switch (hcp_message->payload[i])\r
1306                         {\r
1307                             case TRANSACTION_AID:\r
1308                             {\r
1309                                 /* AID LENGTH INDEX */\r
1310                                 i++;\r
1311                                 /* Fill the event_info.eventInfo.aid \r
1312                                 * Structure with the Received Transaction AID.\r
1313                                 */\r
1314                                 event_info.eventInfo.aid.length = \r
1315                                                             hcp_message->payload[i++];\r
1316                                 (void) memcpy((void *)p_emulation_mgmt_info->uicc_aid,\r
1317                                         &(hcp_message->payload[i]),\r
1318                                                 event_info.eventInfo.aid.length );\r
1319                                 event_info.eventInfo.aid.buffer = (uint8_t *)\r
1320                                                 p_emulation_mgmt_info->uicc_aid;\r
1321                                 i = i + event_info.eventInfo.aid.length;\r
1322                                 break;\r
1323                             }\r
1324                             case TRANSACTION_PARAM:\r
1325                             {\r
1326                                 /* Parameter Length Index */\r
1327                                 i++;\r
1328                                 /* Fill the event_info.eventInfo.param \r
1329                                 * Structure with the Received Parameter.\r
1330                                 */\r
1331                                 p_emulation_mgmt_info->uicc_param_len = \r
1332                                                             hcp_message->payload[i++];\r
1333                                 (void) memcpy((void *)p_emulation_mgmt_info->uicc_param,\r
1334                                         &(hcp_message->payload[i]),\r
1335                                                 p_emulation_mgmt_info->uicc_param_len );\r
1336                                 event_info.eventInfo.uicc_info.param.length = \r
1337                                                 p_emulation_mgmt_info->uicc_param_len;\r
1338                                 event_info.eventInfo.uicc_info.param.buffer = (uint8_t *)\r
1339                                                 p_emulation_mgmt_info->uicc_param;\r
1340                                 i = i + event_info.eventInfo.uicc_info.param.length;\r
1341                                 break;\r
1342                             }\r
1343                             default:\r
1344                             {\r
1345 \r
1346                                 status = PHNFCSTVAL( CID_NFC_HCI,\r
1347                                                     NFCSTATUS_FEATURE_NOT_SUPPORTED );\r
1348                                 i = length;\r
1349                                 HCI_DEBUG("%s: Statement Should Not Occur \n",\r
1350                                                         "phHciNfc_Recv_Uicc_Event");\r
1351                                 break;\r
1352                             }\r
1353                         } /* End of Transaction Switch */\r
1354                     }\r
1355                }\r
1356                break;\r
1357             }\r
1358             case EVT_CONNECTIVITY:\r
1359             {\r
1360                 event_info.eventType = NFC_EVT_CONNECTIVITY;\r
1361                 break;\r
1362             }\r
1363             case EVT_OPERATION_ENDED:\r
1364             {\r
1365                 event_info.eventType = NFC_EVT_OPERATION_ENDED;\r
1366                 break;\r
1367             }\r
1368             default:\r
1369             {\r
1370                 status = PHNFCSTVAL( CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED );\r
1371                 HCI_DEBUG("%s: Statement Should Not Occur \n","phHciNfc_Recv_Uicc_Event");\r
1372                 break;\r
1373             }\r
1374         }\r
1375         if ( NFCSTATUS_SUCCESS == status )\r
1376         {\r
1377             phHciNfc_Notify_Event( psHciContext, pHwRef, \r
1378                     NFC_NOTIFY_EVENT, (void *)&event_info );\r
1379         }\r
1380     }\r
1381     return status;\r
1382 }\r
1383 \r
1384 \r