2 * Copyright (C) 2010 NXP Semiconductors
\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
8 * http://www.apache.org/licenses/LICENSE-2.0
\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
19 * =========================================================================== *
\r
22 * \file phHciNfc_Generic.c *
\r
23 * \brief Generic HCI Source for the HCI Management. *
\r
26 * Project: NFC-FRI-1.1 *
\r
28 * $Date: Tue Jun 8 09:31:49 2010 $ *
\r
29 * $Author: ing04880 $ *
\r
30 * $Revision: 1.108 $ *
\r
31 * $Aliases: NFC_FRI1.1_WK1023_R35_1 $
\r
33 * =========================================================================== *
\r
37 ################################################################################
\r
38 ***************************** Header File Inclusion ****************************
\r
39 ################################################################################
\r
42 #include <phNfcCompId.h>
\r
43 #include <phHciNfc_Sequence.h>
\r
44 #include <phHciNfc_Pipe.h>
\r
45 #include <phHciNfc_AdminMgmt.h>
\r
46 #include <phHciNfc_IDMgmt.h>
\r
47 #include <phHciNfc_LinkMgmt.h>
\r
48 #include <phHciNfc_PollingLoop.h>
\r
49 #include <phHciNfc_RFReader.h>
\r
50 #include <phHciNfc_RFReaderA.h>
\r
51 #include <phOsalNfc.h>
\r
54 ################################################################################
\r
55 ****************************** Macro Definitions *******************************
\r
56 ################################################################################
\r
59 /* HCI timeout value */
\r
60 uint32_t nxp_nfc_hci_response_timeout = NXP_NFC_HCI_TIMEOUT;
\r
63 ################################################################################
\r
64 ************************ Static Variable Definitions ***************************
\r
65 ################################################################################
\r
69 #if (NXP_NFC_HCI_TIMER == 1)
\r
71 #define NXP_HCI_RESPONSE_TIMEOUT (NXP_NFC_HCI_TIMEOUT)
\r
73 #include <phOsalNfc_Timer.h>
\r
74 /** \internal HCI Response Timer to detect the
\r
75 * Stalled HCI Response */
\r
76 static uint32_t hci_resp_timer_id = NXP_INVALID_TIMER_ID;
\r
77 static phHciNfc_sContext_t *gpsHciContext= NULL;
\r
79 #endif /* (NXP_NFC_HCI_TIMER == 1) */
\r
83 ################################################################################
\r
84 ************************* Function Prototype Declaration ***********************
\r
85 ################################################################################
\r
88 #if (NXP_NFC_HCI_TIMER == 1)
\r
92 phHciNfc_Response_Timeout (
\r
93 uint32_t resp_timer_id, void *pContext
\r
96 #endif /* (NXP_NFC_HCI_TIMER == 1) */
\r
99 * \ingroup grp_hci_nfc
\r
101 * The phHciNfc_Send function sends the HCI Commands to the
\r
102 * corresponding peripheral device, described by the HCI Context Structure.
\r
104 * \param[in] psContext psContext is the context of
\r
106 * \param[in] pHwRef pHwRef is the Information of
\r
107 * the Device Interface Link .
\r
108 * \param[in] pdata Pointer to the buffer containing
\r
109 * the command to be sent.
\r
110 * \param[in] length Variable that receives
\r
111 * the number of bytes actually sent.
\r
113 * \retval NFCSTATUS_PENDING Command successfully sent.
\r
114 * \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
\r
115 * could not be interpreted properly.
\r
116 * \retval Other errors Errors related to the lower layers
\r
126 #ifdef ONE_BYTE_LEN
\r
135 phHciNfc_Process_HCP (
\r
136 phHciNfc_sContext_t *psHciContext,
\r
139 #ifdef ONE_BYTE_LEN
\r
149 phHciNfc_Process_Response (
\r
150 phHciNfc_sContext_t *psHciContext,
\r
153 #ifdef ONE_BYTE_LEN
\r
162 phHciNfc_Error_Response (
\r
163 phHciNfc_sContext_t *psHciContext,
\r
166 #ifdef ONE_BYTE_LEN
\r
175 phHciNfc_Process_Event (
\r
176 phHciNfc_sContext_t *psHciContext,
\r
179 #ifdef ONE_BYTE_LEN
\r
189 phHciNfc_Process_Command (
\r
190 phHciNfc_sContext_t *psHciContext,
\r
193 #ifdef ONE_BYTE_LEN
\r
203 phHciNfc_Reset_Pipe_MsgInfo(
\r
204 phHciNfc_Pipe_Info_t *p_pipe_info
\r
209 phHciNfc_Build_HCPMessage(
\r
210 phHciNfc_HCP_Packet_t *hcp_packet,
\r
212 uint8_t instruction
\r
217 phHciNfc_Build_HCPHeader(
\r
218 phHciNfc_HCP_Packet_t *hcp_packet,
\r
223 * \ingroup grp_hci_nfc
\r
225 * The phHciNfc_Receive_HCP function receive the HCI Host Control Packet
\r
226 * Frames from the device.
\r
228 * \param[in] psHciContext psHciContext is the context of
\r
230 * \param[in] pHwRef pHwRef is the Information of
\r
231 * the Device Interface Link .
\r
232 * \param[in] pdata Pointer to the response buffer that
\r
233 * receives the response read.
\r
234 * \param[in] length Variable that receives
\r
235 * the number of bytes read.
\r
237 * \retval NFCSTATUS_PENDING HCP Frame receive pending.
\r
238 * \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
\r
239 * could not be interpreted properly.
\r
240 * \retval Other errors Other related errors
\r
248 phHciNfc_Receive_HCP (
\r
249 phHciNfc_sContext_t *psHciContext,
\r
252 #ifdef ONE_BYTE_LEN
\r
261 ################################################################################
\r
262 ***************************** Function Definitions *****************************
\r
263 ################################################################################
\r
267 #if (NXP_NFC_HCI_TIMER == 1)
\r
271 phHciNfc_Response_Timeout (
\r
272 uint32_t resp_timer_id, void *pContext
\r
275 phNfc_sCompletionInfo_t comp_info = {0,0,0};
\r
277 if ( ( NULL != gpsHciContext)
\r
278 && (resp_timer_id == hci_resp_timer_id ))
\r
280 pphNfcIF_Notification_CB_t p_upper_notify =
\r
281 gpsHciContext->p_upper_notify;
\r
282 void *p_upper_context =
\r
283 gpsHciContext->p_upper_context;
\r
284 phHal_sHwReference_t *pHwRef = gpsHciContext->p_hw_ref;
\r
288 HCI_DEBUG(" HCI TIMEOUT: HCI Response Timeout Occurred in %X Timer\n"
\r
290 /* Stop the Response Timer */
\r
291 phOsalNfc_Timer_Stop( hci_resp_timer_id );
\r
293 comp_info.status = PHNFCSTVAL(CID_NFC_HCI,
\r
294 NFCSTATUS_BOARD_COMMUNICATION_ERROR);
\r
295 /* Roll Back to the Select State */
\r
296 phHciNfc_FSM_Rollback(gpsHciContext);
\r
298 for(i=0;i < PHHCINFC_MAX_PIPE; i++)
\r
300 phHciNfc_Reset_Pipe_MsgInfo(gpsHciContext->p_pipe_list[i]);
\r
303 /* Notify the Error/Success Scenario to the upper layer */
\r
304 phHciNfc_Notify( p_upper_notify, p_upper_context,
\r
305 pHwRef, (uint8_t) NFC_NOTIFY_DEVICE_ERROR, &comp_info );
\r
312 #endif /* (NXP_NFC_HCI_TIMER == 1) */
\r
317 * \brief Allocation of the HCI Interface resources.
\r
319 * This function releases and frees all the resources used by HCI Command and
\r
320 * Response Mechanism
\r
324 phHciNfc_Allocate_Resource (
\r
329 NFCSTATUS status = NFCSTATUS_SUCCESS;
\r
331 *ppBuffer = (void *) phOsalNfc_GetMemory(size);
\r
332 if( *ppBuffer != NULL )
\r
334 (void )memset(((void *)*ppBuffer), 0,
\r
340 status = PHNFCSTVAL(CID_NFC_HCI,
\r
341 NFCSTATUS_INSUFFICIENT_RESOURCES);
\r
349 * \brief Release of the HCI Interface resources.
\r
351 * This function releases and frees all the resources used by HCI Command and
\r
352 * Response Mechanism
\r
355 phHciNfc_Release_Resources (
\r
356 phHciNfc_sContext_t **ppsHciContext
\r
362 #if (NXP_NFC_HCI_TIMER == 1)
\r
364 if ( NXP_INVALID_TIMER_ID != hci_resp_timer_id )
\r
366 /* Stop and Un-Intialise the Response Timer */
\r
367 phOsalNfc_Timer_Stop( hci_resp_timer_id );
\r
368 phOsalNfc_Timer_Delete( hci_resp_timer_id );
\r
369 HCI_DEBUG(" HCI : Timer %X Stopped and Released\n",
\r
370 hci_resp_timer_id);
\r
371 hci_resp_timer_id = NXP_INVALID_TIMER_ID;
\r
373 gpsHciContext = NULL;
\r
375 #endif /* (NXP_NFC_HCI_TIMER == 1) */
\r
378 if(NULL != (*ppsHciContext)->p_admin_info)
\r
380 phOsalNfc_FreeMemory((*ppsHciContext)->p_admin_info);
\r
381 (*ppsHciContext)->p_admin_info = NULL;
\r
383 if(NULL !=(*ppsHciContext)->p_link_mgmt_info)
\r
385 phOsalNfc_FreeMemory((*ppsHciContext)->p_link_mgmt_info);
\r
386 (*ppsHciContext)->p_link_mgmt_info = NULL;
\r
388 if(NULL !=(*ppsHciContext)->p_identity_info)
\r
390 phOsalNfc_FreeMemory((*ppsHciContext)->p_identity_info);
\r
391 (*ppsHciContext)->p_identity_info = NULL;
\r
393 if(NULL !=(*ppsHciContext)->p_device_mgmt_info)
\r
395 phOsalNfc_FreeMemory((*ppsHciContext)->p_device_mgmt_info);
\r
396 (*ppsHciContext)->p_device_mgmt_info = NULL;
\r
398 if(NULL !=(*ppsHciContext)->p_reader_mgmt_info)
\r
400 phOsalNfc_FreeMemory((*ppsHciContext)->p_reader_mgmt_info);
\r
401 (*ppsHciContext)->p_reader_mgmt_info = NULL;
\r
403 if(NULL !=(*ppsHciContext)->p_poll_loop_info)
\r
405 phOsalNfc_FreeMemory((*ppsHciContext)->p_poll_loop_info);
\r
406 (*ppsHciContext)->p_poll_loop_info = NULL;
\r
408 if(NULL !=(*ppsHciContext)->p_reader_a_info)
\r
410 phOsalNfc_FreeMemory((*ppsHciContext)->p_reader_a_info);
\r
411 (*ppsHciContext)->p_reader_a_info = NULL;
\r
414 if(NULL !=(*ppsHciContext)->p_reader_b_info)
\r
416 phOsalNfc_FreeMemory((*ppsHciContext)->p_reader_b_info);
\r
417 (*ppsHciContext)->p_reader_b_info = NULL;
\r
421 if(NULL !=(*ppsHciContext)->p_felica_info)
\r
423 phOsalNfc_FreeMemory((*ppsHciContext)->p_felica_info);
\r
424 (*ppsHciContext)->p_felica_info = NULL;
\r
428 if(NULL !=(*ppsHciContext)->p_jewel_info)
\r
430 phOsalNfc_FreeMemory((*ppsHciContext)->p_jewel_info);
\r
431 (*ppsHciContext)->p_jewel_info = NULL;
\r
434 #ifdef TYPE_ISO15693
\r
435 if(NULL !=(*ppsHciContext)->p_iso_15693_info)
\r
437 phOsalNfc_FreeMemory((*ppsHciContext)->p_iso_15693_info);
\r
438 (*ppsHciContext)->p_iso_15693_info = NULL;
\r
440 #endif /* #ifdef TYPE_ISO15693 */
\r
442 if(NULL !=(*ppsHciContext)->p_nfcip_info)
\r
444 phOsalNfc_FreeMemory((*ppsHciContext)->p_nfcip_info);
\r
445 (*ppsHciContext)->p_nfcip_info = NULL;
\r
448 if(NULL !=(*ppsHciContext)->p_emulation_mgmt_info)
\r
450 phOsalNfc_FreeMemory((*ppsHciContext)->p_emulation_mgmt_info);
\r
451 (*ppsHciContext)->p_emulation_mgmt_info = NULL;
\r
453 if(NULL !=(*ppsHciContext)->p_wi_info)
\r
455 phOsalNfc_FreeMemory((*ppsHciContext)->p_wi_info);
\r
456 (*ppsHciContext)->p_wi_info = NULL;
\r
458 if(NULL !=(*ppsHciContext)->p_swp_info)
\r
460 phOsalNfc_FreeMemory((*ppsHciContext)->p_swp_info);
\r
461 (*ppsHciContext)->p_swp_info = NULL;
\r
463 if(NULL !=(*ppsHciContext)->p_uicc_info)
\r
465 phOsalNfc_FreeMemory((*ppsHciContext)->p_uicc_info);
\r
466 (*ppsHciContext)->p_uicc_info = NULL;
\r
468 #ifdef HOST_EMULATION
\r
469 if(NULL !=(*ppsHciContext)->p_ce_a_info)
\r
471 phOsalNfc_FreeMemory((*ppsHciContext)->p_ce_a_info);
\r
472 (*ppsHciContext)->p_ce_a_info = NULL;
\r
474 if(NULL !=(*ppsHciContext)->p_ce_b_info)
\r
476 phOsalNfc_FreeMemory((*ppsHciContext)->p_ce_b_info);
\r
477 (*ppsHciContext)->p_ce_b_info = NULL;
\r
481 for(i=0;i < PHHCINFC_MAX_PIPE; i++)
\r
483 if(NULL != (*ppsHciContext)->p_pipe_list[i])
\r
485 phOsalNfc_FreeMemory((*ppsHciContext)->p_pipe_list[i]);
\r
490 phOsalNfc_FreeMemory((*ppsHciContext));
\r
491 (*ppsHciContext) = NULL;
\r
498 phHciNfc_Reset_Pipe_MsgInfo(
\r
499 phHciNfc_Pipe_Info_t *p_pipe_info
\r
502 if (p_pipe_info != NULL)
\r
504 p_pipe_info->sent_msg_type = HCP_MSG_TYPE_RESERVED;
\r
505 p_pipe_info->prev_msg = MSG_INSTRUCTION_UNKNWON;
\r
506 p_pipe_info->prev_status = NFCSTATUS_INVALID_HCI_INSTRUCTION;
\r
507 p_pipe_info->param_info = NULL;
\r
508 p_pipe_info->param_length = FALSE ;
\r
515 phHciNfc_Release_Lower(
\r
516 phHciNfc_sContext_t *psHciContext,
\r
520 phNfc_sLowerIF_t *plower_if =
\r
521 &(psHciContext->lower_interface);
\r
522 NFCSTATUS status = NFCSTATUS_SUCCESS;
\r
524 PHNFC_UNUSED_VARIABLE(status);
\r
525 if(NULL != plower_if->release)
\r
527 status = plower_if->release((void *)plower_if->pcontext,
\r
529 (void) memset((void *)plower_if, 0, sizeof(phNfc_sLowerIF_t));
\r
530 HCI_DEBUG(" HCI Releasing the Lower Layer Resources: Status = %02X\n"
\r
540 * \brief Sends the HCI Commands to the corresponding peripheral device.
\r
542 * This function sends the HCI Commands to the connected NFC Pheripheral device
\r
550 #ifdef ONE_BYTE_LEN
\r
557 phHciNfc_sContext_t *psHciContext= (phHciNfc_sContext_t *)psContext;
\r
558 NFCSTATUS status = NFCSTATUS_SUCCESS;
\r
560 phNfc_sLowerIF_t *plower_if = &(psHciContext->lower_interface);
\r
562 if( (NULL != plower_if)
\r
563 && (NULL != plower_if->send)
\r
566 HCI_DEBUG("HCI: In Function: %s \n", __FUNCTION__);
\r
567 HCI_DEBUG("HCI: Response Pending status --> %s \n",
\r
568 (psHciContext->response_pending)?"TRUE":"FALSE");
\r
569 HCI_PRINT_BUFFER("Send Buffer",pdata,length);
\r
570 /* psHciContext->hci_transact_state = NFC_TRANSACT_SEND_IN_PROGRESS; */
\r
572 #if (NXP_NFC_HCI_TIMER == 1)
\r
575 (TRUE != psHciContext->tx_hcp_chaining)
\r
576 && (TRUE == psHciContext->response_pending)
\r
577 && ( NXP_INVALID_TIMER_ID != hci_resp_timer_id )
\r
580 /* Start the HCI Response Timer */
\r
581 phOsalNfc_Timer_Start( hci_resp_timer_id,
\r
582 nxp_nfc_hci_response_timeout, phHciNfc_Response_Timeout, NULL );
\r
583 HCI_DEBUG(" HCI : Timer %X Started \n", hci_resp_timer_id);
\r
586 #endif /* (NXP_NFC_HCI_TIMER == 1) */
\r
588 status = plower_if->send((void *)plower_if->pcontext,
\r
589 (void *)pHwRef, pdata, length);
\r
597 * \brief Receives the HCI Response from the corresponding peripheral device.
\r
599 * This function receives the HCI Command Response to the connected NFC
\r
600 * Pheripheral device.
\r
608 #ifdef ONE_BYTE_LEN
\r
615 phHciNfc_sContext_t *psHciContext= (phHciNfc_sContext_t *)psContext;
\r
616 phNfc_sLowerIF_t *plower_if = NULL ;
\r
617 NFCSTATUS status = NFCSTATUS_SUCCESS;
\r
619 if(NULL == psHciContext )
\r
621 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
\r
625 plower_if = &(psHciContext->lower_interface);
\r
627 if( (NULL != plower_if)
\r
628 && (NULL != plower_if->receive)
\r
631 /* psHciContext->hci_transact_state = NFC_TRANSACT_RECV_IN_PROGRESS; */
\r
632 status = plower_if->receive((void *)plower_if->pcontext,
\r
633 (void *)pHwRef, pdata, length);
\r
641 * \brief Sends the HCP Packet to the lower link layer .
\r
643 * This function Sends the HCI Data in the HCP packet format to the below
\r
648 phHciNfc_Send_HCP (
\r
649 phHciNfc_sContext_t *psHciContext,
\r
653 NFCSTATUS status = NFCSTATUS_SUCCESS;
\r
654 phHciNfc_HCP_Packet_t *tx_data = (phHciNfc_HCP_Packet_t *)
\r
655 psHciContext->send_buffer;
\r
656 /* Skip the HCP Header Byte initially */
\r
657 uint16_t tx_length = psHciContext->tx_total - 1 ;
\r
658 uint16_t hcp_index = HCP_ZERO_LEN;
\r
659 uint8_t pipe_id = (uint8_t) HCI_UNKNOWN_PIPE_ID;
\r
660 static uint8_t chain_bit = HCP_CHAINBIT_DEFAULT;
\r
662 pipe_id = (uint8_t) GET_BITS8( tx_data->hcp_header,
\r
663 HCP_PIPEID_OFFSET, HCP_PIPEID_LEN);
\r
665 /* Fragmentation of the HCP Frames */
\r
666 if ( tx_length > PHHCINFC_MAX_PACKET_DATA )
\r
668 tx_data = &psHciContext->tx_packet;
\r
669 (void)memset((void *)tx_data, FALSE,
\r
670 sizeof(phHciNfc_HCP_Packet_t));
\r
671 if (HCP_CHAINBIT_DEFAULT == chain_bit)
\r
673 /* HCI Chaining Needs to be Done */
\r
674 psHciContext->tx_remain = tx_length;
\r
675 psHciContext->tx_hcp_frgmnt_index = HCP_ZERO_LEN ;
\r
676 chain_bit = HCP_CHAINBIT_BEGIN;
\r
677 /* Increment the Fragment index to skip the HCP Header */
\r
678 psHciContext->tx_hcp_frgmnt_index++;
\r
679 psHciContext->tx_hcp_chaining = TRUE ;
\r
680 tx_length = PHHCINFC_MAX_PACKET_DATA ;
\r
682 else if ( psHciContext->tx_remain > PHHCINFC_MAX_PACKET_DATA )
\r
684 /* Intermediate Chained HCI Frames */
\r
685 tx_length = PHHCINFC_MAX_PACKET_DATA ;
\r
689 /* End of Chaining Reached */
\r
690 chain_bit = HCP_CHAINBIT_END;
\r
691 tx_length = psHciContext->tx_remain ;
\r
692 psHciContext->tx_hcp_chaining = FALSE ;
\r
695 /* Build the HCP Header to have Chaining Enabled */
\r
696 phHciNfc_Build_HCPHeader(tx_data, chain_bit , pipe_id );
\r
698 phHciNfc_Append_HCPFrame((uint8_t *)tx_data->msg.payload, hcp_index,
\r
699 (&psHciContext->send_buffer[psHciContext->tx_hcp_frgmnt_index])
\r
704 /* No Chaining Required */
\r
705 chain_bit = HCP_CHAINBIT_DEFAULT;
\r
707 psHciContext->tx_hcp_chaining = FALSE ;
\r
709 psHciContext->tx_remain = tx_length ;
\r
712 /* Include the Skipped HCP Header Byte */
\r
715 status = phHciNfc_Send ( (void *) psHciContext, pHwRef,
\r
716 (uint8_t *)tx_data, tx_length );
\r
723 * \brief Receives the HCP Packet from the lower link layer .
\r
725 * This function receives the HCI Data in the HCP packet format from the below
\r
730 phHciNfc_Receive_HCP (
\r
731 phHciNfc_sContext_t *psHciContext,
\r
734 #ifdef ONE_BYTE_LEN
\r
741 NFCSTATUS status = NFCSTATUS_SUCCESS;
\r
742 phHciNfc_HCP_Packet_t *packet = NULL;
\r
743 uint8_t chainbit = HCP_CHAINBIT_DEFAULT;
\r
744 uint16_t hcp_index = 0;
\r
746 packet = (phHciNfc_HCP_Packet_t *)pdata;
\r
747 chainbit = (uint8_t) GET_BITS8( packet->hcp_header,
\r
748 HCP_CHAINBIT_OFFSET, HCP_CHAINBIT_LEN);
\r
749 hcp_index = psHciContext->rx_hcp_frgmnt_index;
\r
750 HCI_PRINT_BUFFER("Receive Buffer",((uint8_t *)pdata),length);
\r
751 if (HCP_CHAINBIT_BEGIN == chainbit)
\r
753 /* pdata = (uint8_t *)&psHciContext->rx_packet; */
\r
754 /* De Fragmentation of the Received HCP Frames */
\r
755 /* Subsequent Chaining Frames */
\r
756 if( hcp_index > 0 )
\r
758 /* Copy the obtained fragment and receive the next fragment */
\r
759 phHciNfc_Append_HCPFrame(
\r
760 psHciContext->recv_buffer, hcp_index,
\r
761 (uint8_t *)&pdata[HCP_MESSAGE_LEN],
\r
762 (length - HCP_MESSAGE_LEN) );
\r
763 psHciContext->rx_hcp_frgmnt_index =(uint16_t)
\r
764 (hcp_index + length - HCP_MESSAGE_LEN);
\r
766 /* First Chaining Frame*/
\r
769 psHciContext->rx_hcp_chaining = TRUE ;
\r
770 /* Copy the obtained fragment and receive the next fragment */
\r
771 phHciNfc_Append_HCPFrame(psHciContext->recv_buffer,
\r
772 hcp_index, pdata, length);
\r
773 psHciContext->rx_hcp_frgmnt_index = ( hcp_index + length ) ;
\r
776 status = phHciNfc_Receive ( (void *) psHciContext, pHwRef,
\r
781 if(TRUE == psHciContext->rx_hcp_chaining)
\r
783 /* If the chaining was done earlier */
\r
784 psHciContext->rx_hcp_chaining = FALSE ;
\r
785 /* Copy the Remaining buffer to the RX_BUFFER */
\r
786 phHciNfc_Append_HCPFrame(
\r
787 psHciContext->recv_buffer, hcp_index,
\r
788 (uint8_t *)&pdata[HCP_MESSAGE_LEN],
\r
789 (length - HCP_MESSAGE_LEN) );
\r
790 /* If there is chaining done the return the same data */
\r
791 psHciContext->rx_total =
\r
792 (hcp_index + length - HCP_MESSAGE_LEN);
\r
793 psHciContext->rx_hcp_frgmnt_index = FALSE ;
\r
797 (void) memcpy( psHciContext->recv_buffer, pdata, length);
\r
798 /* If there is no chaining done then return the same data */
\r
799 psHciContext->rx_total = (hcp_index + length);
\r
809 * \brief Receives the HCP Packet from the lower link layer .
\r
811 * This function receives the HCI Data in the HCP packet format from the below
\r
817 phHciNfc_Process_HCP (
\r
818 phHciNfc_sContext_t *psHciContext,
\r
821 #ifdef ONE_BYTE_LEN
\r
828 phHciNfc_HCP_Packet_t *packet = NULL;
\r
829 phHciNfc_HCP_Message_t *message = NULL;
\r
830 NFCSTATUS status = NFCSTATUS_SUCCESS;
\r
831 uint8_t msg_type = 0;
\r
833 if( (NULL == pdata)
\r
834 || ( length < HCP_HEADER_LEN )
\r
837 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
\r
841 status = phHciNfc_Receive_HCP( psHciContext, pHwRef, pdata, length );
\r
842 }/* End of the Valid Data Handling */
\r
844 if( NFCSTATUS_SUCCESS == status )
\r
846 packet = (phHciNfc_HCP_Packet_t *)psHciContext->recv_buffer;
\r
848 #ifdef ONE_BYTE_LEN
\r
851 psHciContext->rx_total ;
\r
852 message = &packet->msg.message;
\r
853 /* HCI_PRINT_BUFFER("Total Receive Buffer",((uint8_t *)pdata),length); */
\r
854 msg_type = (uint8_t) GET_BITS8( message->msg_header,
\r
855 HCP_MSG_TYPE_OFFSET, HCP_MSG_TYPE_LEN);
\r
856 switch ( msg_type )
\r
858 case HCP_MSG_TYPE_RESPONSE:
\r
860 status = phHciNfc_Process_Response( psHciContext,
\r
861 pHwRef, (void *)packet, length );
\r
864 case HCP_MSG_TYPE_EVENT:
\r
866 status = phHciNfc_Process_Event( psHciContext,
\r
867 pHwRef,(void *)packet, length );
\r
870 case HCP_MSG_TYPE_COMMAND:
\r
873 status = phHciNfc_Process_Command( psHciContext,
\r
874 pHwRef, (void *)packet, length );
\r
877 /* case HCP_MSG_TYPE_RESERVED: */
\r
880 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_RESPONSE);
\r
884 }/* End of Receive HCP Status */
\r
891 phHciNfc_Process_Response (
\r
892 phHciNfc_sContext_t *psHciContext,
\r
895 #ifdef ONE_BYTE_LEN
\r
902 phHciNfc_HCP_Packet_t *packet = NULL;
\r
903 phHciNfc_HCP_Message_t *message = NULL;
\r
904 uint8_t instruction=0;
\r
905 uint8_t pipe_id = (uint8_t)HCI_UNKNOWN_PIPE_ID;
\r
906 phHciNfc_Pipe_Info_t *p_pipe_info = NULL;
\r
908 NFCSTATUS status = NFCSTATUS_SUCCESS;
\r
910 packet = (phHciNfc_HCP_Packet_t *)pdata;
\r
911 message = &packet->msg.message;
\r
912 /* Get the instruction bits from the Message Header */
\r
913 instruction = (uint8_t) GET_BITS8( message->msg_header,
\r
914 HCP_MSG_INSTRUCTION_OFFSET, HCP_MSG_INSTRUCTION_LEN);
\r
915 /* Get the Pipe ID from the HCP Header */
\r
916 pipe_id = (uint8_t) GET_BITS8( packet->hcp_header,
\r
917 HCP_PIPEID_OFFSET, HCP_PIPEID_LEN);
\r
919 #if (NXP_NFC_HCI_TIMER == 1)
\r
921 if ( NXP_INVALID_TIMER_ID != hci_resp_timer_id )
\r
923 /* Stop the HCI Response Timer */
\r
924 HCI_DEBUG(" HCI : Timer %X Stopped \n", hci_resp_timer_id);
\r
925 phOsalNfc_Timer_Stop( hci_resp_timer_id );
\r
928 #endif /* (NXP_NFC_HCI_TIMER == 1) */
\r
930 if (pipe_id >= PHHCINFC_MAX_PIPE )
\r
932 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION);
\r
934 else if( ((uint8_t) ANY_OK != instruction)
\r
935 && ( (pipe_id != PIPETYPE_STATIC_ADMIN )
\r
936 && ( ADM_CLEAR_ALL_PIPE != (psHciContext->p_pipe_list[pipe_id])->prev_msg ))
\r
939 status = phHciNfc_Error_Response( psHciContext, pHwRef, pdata, length );
\r
943 p_pipe_info = psHciContext->p_pipe_list[pipe_id];
\r
944 if( ( NULL != p_pipe_info )
\r
945 && ( HCP_MSG_TYPE_COMMAND == p_pipe_info->sent_msg_type )
\r
946 && ( NULL != p_pipe_info->recv_resp )
\r
949 status = psHciContext->p_pipe_list[pipe_id]->recv_resp( psHciContext,
\r
950 pHwRef, pdata, length );
\r
954 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
\r
956 /* There is no Pending Response */
\r
957 psHciContext->response_pending = FALSE ;
\r
958 HCI_DEBUG("HCI: Response Pending status --> FALSE, %s \n",
\r
960 if( NFCSTATUS_SUCCESS == status )
\r
962 phHciNfc_Reset_Pipe_MsgInfo(psHciContext->p_pipe_list[pipe_id]);
\r
963 status = phHciNfc_Resume_Sequence(psHciContext, pHwRef);
\r
965 }/* End of Success Status validation */
\r
968 HCI_DEBUG("HCI: Status --> %X \n", status );
\r
971 } /* End of the Valid Response handling */
\r
978 phHciNfc_Error_Response (
\r
979 phHciNfc_sContext_t *psHciContext,
\r
982 #ifdef ONE_BYTE_LEN
\r
990 phHciNfc_HCP_Packet_t *packet = (phHciNfc_HCP_Packet_t *)pdata;
\r
991 phHciNfc_HCP_Message_t *message = &packet->msg.message;
\r
992 NFCSTATUS status = NFCSTATUS_SUCCESS;
\r
993 uint8_t pipe_id = (uint8_t)HCI_UNKNOWN_PIPE_ID;
\r
994 #if defined(HCI_TRACE) || defined (ERROR_INSTRUCTION)
\r
995 uint8_t instruction = 0;
\r
996 instruction = (uint8_t) GET_BITS8(message->msg_header,
\r
997 HCP_MSG_INSTRUCTION_OFFSET, HCP_MSG_INSTRUCTION_LEN);
\r
1000 /* Get the Pipe ID from the HCP Header */
\r
1001 pipe_id = (uint8_t) GET_BITS8( packet->hcp_header,
\r
1002 HCP_PIPEID_OFFSET, HCP_PIPEID_LEN);
\r
1003 /* Process the Error Response based on the obtained instruction */
\r
1004 #ifdef ERROR_INSTRUCTION
\r
1005 switch(instruction)
\r
1007 case ANY_E_NOT_CONNECTED:
\r
1008 case ANY_E_CMD_PAR_UNKNOWN:
\r
1010 case ANY_E_PIPES_FULL:
\r
1011 case ANY_E_REG_PAR_UNKNOWN:
\r
1012 case ANY_E_PIPE_NOT_OPENED:
\r
1013 case ANY_E_CMD_NOT_SUPPORTED:
\r
1014 case ANY_E_TIMEOUT:
\r
1015 case ANY_E_REG_ACCESS_DENIED:
\r
1016 case ANY_E_PIPE_ACCESS_DENIED:
\r
1018 /* Receive Error Notification to the Upper Layer */
\r
1019 status = PHNFCSTVAL( CID_NFC_HCI, \
\r
1020 message->msg_header);
\r
1021 phHciNfc_Error_Sequence(psHciContext, pHwRef, status , pdata, length );
\r
1022 /* Return Success as the Error Sequence is already handled */
\r
1023 psHciContext->response_pending = FALSE ;
\r
1024 HCI_DEBUG("HCI: Response Pending status --> FALSE, %s \n",
\r
1026 status = NFCSTATUS_SUCCESS;
\r
1029 /* The Statement should not reach this case */
\r
1030 /* case ANY_OK: */
\r
1033 /* status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_RESPONSE); */
\r
1038 status = PHNFCSTVAL( CID_NFC_HCI, message->msg_header);
\r
1039 HCI_DEBUG("HCI Error Response(%u) from the Device \n", instruction);
\r
1040 psHciContext->response_pending = FALSE ;
\r
1041 HCI_DEBUG("HCI: Response Pending status --> FALSE, %s \n",
\r
1043 phHciNfc_Reset_Pipe_MsgInfo(psHciContext->p_pipe_list[pipe_id]);
\r
1044 phHciNfc_Error_Sequence(psHciContext, pHwRef, status , pdata, (uint8_t) length );
\r
1045 /* Return Success as the Error Sequence is already handled */
\r
1046 status = NFCSTATUS_SUCCESS;
\r
1055 phHciNfc_Process_Event (
\r
1056 phHciNfc_sContext_t *psHciContext,
\r
1059 #ifdef ONE_BYTE_LEN
\r
1066 phHciNfc_HCP_Packet_t *packet = NULL;
\r
1067 phHciNfc_HCP_Message_t *message = NULL;
\r
1068 phHciNfc_Pipe_Info_t *p_pipe_info = NULL;
\r
1069 uint8_t instruction=0;
\r
1070 uint8_t pipe_id = (uint8_t)HCI_UNKNOWN_PIPE_ID;
\r
1072 NFCSTATUS status = NFCSTATUS_SUCCESS;
\r
1074 packet = (phHciNfc_HCP_Packet_t *)pdata;
\r
1075 message = &packet->msg.message;
\r
1076 /* Get the instruction bits from the Message Header */
\r
1077 PHNFC_UNUSED_VARIABLE(instruction);
\r
1078 instruction = (uint8_t) GET_BITS8( message->msg_header,
\r
1079 HCP_MSG_INSTRUCTION_OFFSET, HCP_MSG_INSTRUCTION_LEN);
\r
1080 /* Get the Pipe ID from the HCP Header */
\r
1081 pipe_id = (uint8_t) GET_BITS8( packet->hcp_header,
\r
1082 HCP_PIPEID_OFFSET, HCP_PIPEID_LEN);
\r
1084 if (pipe_id >= PHHCINFC_MAX_PIPE )
\r
1086 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION);
\r
1090 p_pipe_info = psHciContext->p_pipe_list[pipe_id];
\r
1093 if( (p_pipe_info != NULL ) )
\r
1095 if( NULL != p_pipe_info->recv_event)
\r
1097 status = p_pipe_info->recv_event( psHciContext, pHwRef,
\r
1102 HCI_DEBUG(" Event Handling Not Supported by the #%u Pipe \n",
\r
1104 status = PHNFCSTVAL(CID_NFC_HCI,
\r
1105 NFCSTATUS_FEATURE_NOT_SUPPORTED);
\r
1110 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
\r
1113 HCI_DEBUG("HCI: In Function: %s \n",
\r
1115 HCI_DEBUG("HCI: Response Pending status --> %s \n",
\r
1116 (psHciContext->response_pending)?"TRUE":"FALSE");
\r
1117 HCI_DEBUG("HCI: Event Pending status --> %s \n",
\r
1118 (psHciContext->event_pending)?"TRUE":"FALSE");
\r
1120 if ((TRUE == psHciContext->response_pending)
\r
1121 || (TRUE == psHciContext->event_pending))
\r
1123 (void)memset(psHciContext->recv_buffer,
\r
1124 FALSE, PHHCINFC_MAX_BUFFERSIZE);
\r
1125 (void)memset((void *)&psHciContext->rx_packet,
\r
1126 FALSE, sizeof(phHciNfc_HCP_Packet_t));
\r
1128 /* Reset the Received Data Index */
\r
1129 psHciContext->rx_index = ZERO;
\r
1130 /* Reset the size of the total response data received */
\r
1131 psHciContext->rx_total = ZERO;
\r
1133 /* psHciContext->hci_transact_state = NFC_TRANSACT_SEND_COMPLETE;*/
\r
1134 /* Receive the Response Packet */
\r
1136 status = phHciNfc_Receive( psHciContext, pHwRef,
\r
1137 (uint8_t *)(&psHciContext->rx_packet),
\r
1138 sizeof(phHciNfc_HCP_Packet_t) );
\r
1140 /* HCI_DEBUG("HCI Lower Layer Send Completion After Receive,\
\r
1141 Status = %02X\n",status); */
\r
1146 /* #define EVENT_NOTIFY */
\r
1147 #ifndef EVENT_NOTIFY
\r
1148 ( NFCSTATUS_SUCCESS == status )
\r
1149 || ( NFCSTATUS_RF_TIMEOUT == status )
\r
1150 || (( NFCSTATUS_MORE_INFORMATION == status )
\r
1152 ((FALSE == psHciContext->event_pending )
\r
1154 && ( pipe_id <= PHHCINFC_MAX_PIPE ))
\r
1157 /* phHciNfc_Reset_Pipe_MsgInfo(psHciContext->p_pipe_list[pipe_id]); */
\r
1158 status = phHciNfc_Resume_Sequence(psHciContext, pHwRef);
\r
1160 }/* End of Success Status validation */
\r
1163 HCI_DEBUG(" HCI: Pipe-ID --> %02X \n", pipe_id);
\r
1164 HCI_DEBUG(" HCI: PROCESS EVENT - Pending/Invalid Status : %X\n", status);
\r
1173 phHciNfc_Process_Command (
\r
1174 phHciNfc_sContext_t *psHciContext,
\r
1177 #ifdef ONE_BYTE_LEN
\r
1184 phHciNfc_HCP_Packet_t *packet = NULL;
\r
1185 phHciNfc_HCP_Message_t *message = NULL;
\r
1186 phHciNfc_Pipe_Info_t *p_pipe_info = NULL;
\r
1187 uint8_t instruction=0;
\r
1188 uint8_t pipe_id = (uint8_t)HCI_UNKNOWN_PIPE_ID;
\r
1190 NFCSTATUS status = NFCSTATUS_SUCCESS;
\r
1192 packet = (phHciNfc_HCP_Packet_t *)pdata;
\r
1193 message = &packet->msg.message;
\r
1194 /* Get the instruction bits from the Message Header */
\r
1195 PHNFC_UNUSED_VARIABLE(instruction);
\r
1197 instruction = (uint8_t) GET_BITS8( message->msg_header,
\r
1198 HCP_MSG_INSTRUCTION_OFFSET, HCP_MSG_INSTRUCTION_LEN);
\r
1199 /* Get the Pipe ID from the HCP Header */
\r
1200 pipe_id = (uint8_t) GET_BITS8( packet->hcp_header,
\r
1201 HCP_PIPEID_OFFSET, HCP_PIPEID_LEN);
\r
1202 if (pipe_id >= PHHCINFC_MAX_PIPE )
\r
1204 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION);
\r
1208 p_pipe_info = psHciContext->p_pipe_list[pipe_id];
\r
1211 if( (p_pipe_info != NULL )
\r
1214 if( NULL != p_pipe_info->recv_cmd)
\r
1216 status = p_pipe_info->recv_cmd( psHciContext, pHwRef,
\r
1221 HCI_DEBUG(" Command Handling Not Supported by the #%u Pipe \n",
\r
1223 status = PHNFCSTVAL(CID_NFC_HCI,
\r
1224 NFCSTATUS_FEATURE_NOT_SUPPORTED);
\r
1229 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
\r
1232 HCI_DEBUG("HCI: In Function: %s \n", __FUNCTION__);
\r
1233 HCI_DEBUG("HCI: Response Pending status --> %s \n",
\r
1234 (psHciContext->response_pending)?"TRUE":"FALSE");
\r
1236 if(( NFCSTATUS_SUCCESS == status )
\r
1237 && (TRUE != psHciContext->response_pending)
\r
1240 /* Reset the Pipe Information Stored in the particular Pipe */
\r
1241 /* phHciNfc_Reset_Pipe_MsgInfo(psHciContext->p_pipe_list[pipe_id]); */
\r
1242 /* Resume the Execution Sequence */
\r
1243 status = phHciNfc_Resume_Sequence(psHciContext, pHwRef);
\r
1245 }/* End of Success Status validation */
\r
1253 phHciNfc_Build_HCPMessage(
\r
1254 phHciNfc_HCP_Packet_t *hcp_packet,
\r
1256 uint8_t instruction
\r
1259 phHciNfc_HCP_Message_t *hcp_message = NULL;
\r
1261 hcp_message = &(hcp_packet->msg.message);
\r
1262 /* Set the type to the provided message type in the HCP Message Header */
\r
1263 hcp_message->msg_header = (uint8_t) SET_BITS8(hcp_message->msg_header,HCP_MSG_TYPE_OFFSET,
\r
1264 HCP_MSG_TYPE_LEN, msg_type);
\r
1265 /* Set the instruction to the kind of instruction in the HCP Message Header */
\r
1266 hcp_message->msg_header = (uint8_t) SET_BITS8(hcp_message->msg_header,HCP_MSG_INSTRUCTION_OFFSET,
\r
1267 HCP_MSG_INSTRUCTION_LEN, instruction);
\r
1268 /* hcp_message->msg_header = hcp_message->msg_header | temp ; */
\r
1275 phHciNfc_Build_HCPHeader(
\r
1276 phHciNfc_HCP_Packet_t *hcp_packet,
\r
1281 /* Set the Chaining bit to the default type */
\r
1282 hcp_packet->hcp_header = (uint8_t) SET_BITS8(hcp_packet->hcp_header,
\r
1283 HCP_CHAINBIT_OFFSET, HCP_CHAINBIT_LEN, chainbit);
\r
1284 /* Populate the Pipe ID to the HCP Header */
\r
1285 hcp_packet->hcp_header = (uint8_t) SET_BITS8(hcp_packet->hcp_header,HCP_PIPEID_OFFSET,
\r
1286 HCP_PIPEID_LEN, pipe_id);
\r
1291 * \brief Builds the HCP Frame Packet.
\r
1293 * This function builds the HCP Frame in the HCP packet format to send to the
\r
1294 * connected reader device.
\r
1298 phHciNfc_Build_HCPFrame (
\r
1299 phHciNfc_HCP_Packet_t *hcp_packet,
\r
1303 uint8_t instruction
\r
1306 /* Fills the HCP Header in the packet */
\r
1307 phHciNfc_Build_HCPHeader( hcp_packet,chainbit,pipe_id );
\r
1308 /* Fills the HCP Message in the packet */
\r
1309 phHciNfc_Build_HCPMessage( hcp_packet,msg_type,instruction );
\r
1313 * \brief Appends the HCP Frame Packet.
\r
1315 * This function Appends the HCP Frame of the HCP packet to complete the
\r
1316 * entire HCP Packet.
\r
1320 phHciNfc_Append_HCPFrame (
\r
1321 /* phHciNfc_sContext_t *psHciContext, */
\r
1322 uint8_t *hcp_data,
\r
1323 uint16_t hcp_index,
\r
1324 uint8_t *src_data,
\r
1328 uint16_t src_index = 0;
\r
1329 if( (NULL != src_data)
\r
1330 /* && (hcp_index >= 0) */
\r
1334 for(src_index=0; src_index < src_len ; src_index++)
\r
1336 hcp_data[hcp_index + src_index] = src_data[src_index];
\r
1344 * \brief Sends the Generic HCI Commands to the connected reader device.
\r
1346 * This function Sends the Generic HCI Command frames in the HCP packet format to the
\r
1347 * connected reader device.
\r
1351 phHciNfc_Send_Generic_Cmd (
\r
1352 phHciNfc_sContext_t *psHciContext,
\r
1358 phHciNfc_HCP_Packet_t *hcp_packet = NULL;
\r
1359 phHciNfc_HCP_Message_t *hcp_message = NULL;
\r
1360 phHciNfc_Pipe_Info_t *p_pipe_info = NULL;
\r
1361 uint16_t length = 0;
\r
1363 NFCSTATUS status = NFCSTATUS_SUCCESS;
\r
1365 if((NULL == psHciContext)
\r
1366 || ( pipe_id > PHHCINFC_MAX_PIPE)
\r
1367 ||(NULL == psHciContext->p_pipe_list[pipe_id])
\r
1370 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
\r
1371 HCI_DEBUG("%s: Invalid Arguments passed \n",
\r
1372 "phHciNfc_Send_Generic_Cmd");
\r
1376 p_pipe_info = (phHciNfc_Pipe_Info_t *)
\r
1377 psHciContext->p_pipe_list[pipe_id];
\r
1378 psHciContext->tx_total = 0 ;
\r
1379 length += HCP_HEADER_LEN ;
\r
1382 case ANY_SET_PARAMETER:
\r
1385 hcp_packet = (phHciNfc_HCP_Packet_t *) psHciContext->send_buffer;
\r
1386 /* Construct the HCP Frame */
\r
1387 phHciNfc_Build_HCPFrame(hcp_packet,HCP_CHAINBIT_DEFAULT,
\r
1388 (uint8_t) pipe_id, HCP_MSG_TYPE_COMMAND, cmd);
\r
1389 hcp_message = &(hcp_packet->msg.message);
\r
1390 hcp_message->payload[i++] = p_pipe_info->reg_index ;
\r
1391 phHciNfc_Append_HCPFrame((uint8_t *)hcp_message->payload,
\r
1392 i, (uint8_t *)p_pipe_info->param_info,
\r
1393 p_pipe_info->param_length);
\r
1394 length =(uint16_t)(length + i + p_pipe_info->param_length);
\r
1397 case ANY_GET_PARAMETER:
\r
1400 hcp_packet = (phHciNfc_HCP_Packet_t *) psHciContext->send_buffer;
\r
1401 /* Construct the HCP Frame */
\r
1402 phHciNfc_Build_HCPFrame(hcp_packet,HCP_CHAINBIT_DEFAULT,
\r
1403 (uint8_t) pipe_id, HCP_MSG_TYPE_COMMAND, cmd);
\r
1404 hcp_message = &(hcp_packet->msg.message);
\r
1405 hcp_message->payload[i++] = p_pipe_info->reg_index ;
\r
1406 length =(uint16_t)(length + i);
\r
1409 case ANY_OPEN_PIPE:
\r
1410 case ANY_CLOSE_PIPE:
\r
1413 hcp_packet = (phHciNfc_HCP_Packet_t *) psHciContext->send_buffer;
\r
1414 /* Construct the HCP Frame */
\r
1415 phHciNfc_Build_HCPFrame(hcp_packet,HCP_CHAINBIT_DEFAULT,
\r
1416 (uint8_t) pipe_id, HCP_MSG_TYPE_COMMAND, cmd);
\r
1421 status = PHNFCSTVAL( CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED );
\r
1422 HCI_DEBUG("%s: Statement Should Not Occur \n","phHciNfc_Send_Generic_Cmd");
\r
1426 if( NFCSTATUS_SUCCESS == status )
\r
1428 p_pipe_info->sent_msg_type = HCP_MSG_TYPE_COMMAND;
\r
1429 p_pipe_info->prev_msg = cmd;
\r
1430 psHciContext->tx_total = length;
\r
1431 psHciContext->response_pending = TRUE ;
\r
1432 /* Send the Constructed HCP packet to the lower layer */
\r
1433 status = phHciNfc_Send_HCP( psHciContext, pHwRef );
\r
1434 p_pipe_info->prev_status = NFCSTATUS_PENDING;
\r
1443 * \brief Sets the parameter of the registers in a particular Pipe.
\r
1445 * This function configures the registers in a particular Pipe.
\r
1449 phHciNfc_Set_Param (
\r
1450 phHciNfc_sContext_t *psHciContext,
\r
1452 phHciNfc_Pipe_Info_t *p_pipe_info,
\r
1453 uint8_t reg_index,
\r
1455 uint16_t param_length
\r
1458 NFCSTATUS status = NFCSTATUS_SUCCESS ;
\r
1460 if( (NULL == p_pipe_info)
\r
1461 || (NULL == p_param)
\r
1462 || (0 == param_length)
\r
1465 status = PHNFCSTVAL( CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION );
\r
1469 p_pipe_info->param_info = (uint8_t *)p_param;
\r
1470 p_pipe_info->param_length = param_length;
\r
1471 p_pipe_info->reg_index = reg_index;
\r
1472 status = phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef,
\r
1473 (uint8_t)p_pipe_info->pipe.pipe_id,
\r
1474 (uint8_t)ANY_SET_PARAMETER);
\r
1475 p_pipe_info->prev_status = status;
\r
1484 * \brief Gets the parameter of the registers in a particular Pipe.
\r
1486 * This function configures the registers in a particular Pipe.
\r
1490 phHciNfc_Get_Param (
\r
1491 phHciNfc_sContext_t *psHciContext,
\r
1493 phHciNfc_Pipe_Info_t *p_pipe_info,
\r
1494 uint8_t reg_index,
\r
1497 NFCSTATUS status = NFCSTATUS_SUCCESS ;
\r
1505 phHciNfc_Send_Complete (
\r
1508 phNfc_sTransactionInfo_t *pInfo
\r
1511 NFCSTATUS status = NFCSTATUS_SUCCESS ;
\r
1512 uint16_t length = 0;
\r
1514 HCI_PRINT("HCI Send Completion....\n");
\r
1515 if ( (NULL != psContext)
\r
1516 && (NULL != pInfo)
\r
1517 && (NULL != pHwRef)
\r
1520 phHciNfc_sContext_t *psHciContext = (phHciNfc_sContext_t *)psContext;
\r
1521 status = pInfo->status ;
\r
1522 length = pInfo->length ;
\r
1523 /* HCI_DEBUG("HCI Lower Layer Send Completion Before Receive,\
\r
1524 Status = %02X\n",status); */
\r
1525 if(status != NFCSTATUS_SUCCESS)
\r
1527 /* Handle the Error Scenario */
\r
1528 (void)memset(psHciContext->send_buffer,
\r
1529 FALSE, PHHCINFC_MAX_BUFFERSIZE);
\r
1530 /* psHciContext->hci_transact_state = NFC_TRANSACT_COMPLETE;*/
\r
1531 phHciNfc_Error_Sequence( psHciContext, pHwRef, status, NULL, 0 );
\r
1535 HCI_DEBUG("HCI Send Completion... Length = %02X\n", length);
\r
1536 /* To complete the send complete with the send
\r
1537 * or receive with chaining.
\r
1539 if( (TRUE == psHciContext->tx_hcp_chaining)
\r
1540 &&( psHciContext->tx_remain > HCP_ZERO_LEN ))
\r
1542 /* Skip the HCP Header Byte Sent */
\r
1543 psHciContext->tx_remain -= length - 1;
\r
1545 /* Skip the HCP Header Byte Sent */
\r
1546 psHciContext->tx_hcp_frgmnt_index += length - 1;
\r
1548 /* Send the Remaining HCP Data Frames */
\r
1549 status = phHciNfc_Send_HCP( psHciContext, pHwRef );
\r
1551 HCI_DEBUG("HCI (Chaining) Send Resume: Status = %02X\n", status);
\r
1553 if( ( NFCSTATUS_SUCCESS != status )
\r
1554 && (NFCSTATUS_PENDING != status )
\r
1557 phHciNfc_Error_Sequence( psHciContext, pHwRef, status, NULL, 0 );
\r
1558 }/* End of the Status check */
\r
1562 psHciContext->tx_total = HCP_ZERO_LEN ;
\r
1563 psHciContext->tx_remain = HCP_ZERO_LEN ;
\r
1564 psHciContext->tx_hcp_frgmnt_index = HCP_ZERO_LEN ;
\r
1565 HCI_DEBUG("HCI: %s: response_pending=%s, event_pending=%s",
\r
1567 (psHciContext->response_pending)?"TRUE":"FALSE",
\r
1568 (psHciContext->event_pending)?"TRUE":"FALSE"
\r
1570 if ((TRUE == psHciContext->response_pending)
\r
1571 || (TRUE == psHciContext->event_pending))
\r
1573 (void) memset(psHciContext->recv_buffer,
\r
1574 FALSE, PHHCINFC_MAX_BUFFERSIZE);
\r
1575 (void) memset((void *)&psHciContext->rx_packet,
\r
1576 FALSE, sizeof(phHciNfc_HCP_Packet_t));
\r
1578 /* Reset the Received Data Index */
\r
1579 psHciContext->rx_index = ZERO;
\r
1580 /* Reset the size of the total response data received */
\r
1581 psHciContext->rx_total = ZERO;
\r
1583 /* psHciContext->hci_transact_state = NFC_TRANSACT_SEND_COMPLETE;*/
\r
1584 /* Receive the Response Packet */
\r
1585 status = phHciNfc_Receive( psHciContext, pHwRef,
\r
1586 (uint8_t *)(&psHciContext->rx_packet),
\r
1587 sizeof(phHciNfc_HCP_Packet_t) );
\r
1589 /* HCI_DEBUG("HCI Lower Layer Send Completion After Receive,\
\r
1590 Status = %02X\n",status); */
\r
1592 if( ( NFCSTATUS_SUCCESS != status )
\r
1593 && (NFCSTATUS_PENDING != status )
\r
1596 phHciNfc_Error_Sequence( psHciContext, pHwRef, status, NULL, 0 );
\r
1597 }/* End of the Status check */
\r
1601 status = phHciNfc_Resume_Sequence(psHciContext, pHwRef );
\r
1605 } /* End of status != Success */
\r
1607 } /* End of Context != NULL */
\r
1612 phHciNfc_Receive_Complete (
\r
1615 phNfc_sTransactionInfo_t *pInfo
\r
1618 NFCSTATUS status = NFCSTATUS_SUCCESS ;
\r
1619 void *pdata = NULL ;
\r
1620 uint16_t length = 0 ;
\r
1622 HCI_PRINT("HCI Receive Completion....\n");
\r
1623 if ( (NULL != psContext)
\r
1624 && (NULL != pInfo)
\r
1625 && (NULL != pHwRef)
\r
1628 phHciNfc_sContext_t *psHciContext = (phHciNfc_sContext_t *)psContext;
\r
1630 status = pInfo->status ;
\r
1631 pdata = pInfo->buffer ;
\r
1632 length = pInfo->length ;
\r
1633 HCI_DEBUG("HCI Lower Layer Receive Completion, Status = %02X\n",status);
\r
1634 if( NFCSTATUS_SUCCESS != status )
\r
1636 /* Handle the Error Scenario */
\r
1637 /* psHciContext->hci_transact_state = NFC_TRANSACT_COMPLETE; */
\r
1638 phHciNfc_Error_Sequence(psHciContext, pHwRef, status , pdata, (uint8_t)length );
\r
1642 /* Receive the remaining Response Packet */
\r
1643 /* psHciContext->hci_transact_state = NFC_TRANSACT_RECV_COMPLETE; */
\r
1644 status = phHciNfc_Process_HCP( psHciContext, pHwRef, pdata,(uint8_t) length );
\r
1645 if( ( NFCSTATUS_SUCCESS != status )
\r
1646 && (NFCSTATUS_PENDING != status )
\r
1649 phHciNfc_Error_Sequence(psHciContext, pHwRef, status , pdata, (uint8_t) length );
\r
1657 pphNfcIF_Notification_CB_t p_upper_notify,
\r
1658 void *p_upper_context,
\r
1664 if( ( NULL != p_upper_notify) )
\r
1666 /* Notify the to the Upper Layer */
\r
1667 (p_upper_notify)(p_upper_context, pHwRef, type, pInfo);
\r
1674 phHciNfc_Tag_Notify(
\r
1675 phHciNfc_sContext_t *psHciContext,
\r
1681 phNfc_sCompletionInfo_t *psCompInfo =
\r
1682 (phNfc_sCompletionInfo_t *)pInfo;
\r
1683 pphNfcIF_Notification_CB_t p_upper_notify = psHciContext->p_upper_notify;
\r
1684 void *pcontext = psHciContext->p_upper_context;
\r
1685 NFCSTATUS status = NFCSTATUS_SUCCESS;
\r
1687 switch( psHciContext->hci_state.next_state )
\r
1689 case hciState_Activate:
\r
1691 /* Roll Back to the Select State */
\r
1692 phHciNfc_FSM_Rollback(psHciContext);
\r
1695 case hciState_Select:
\r
1697 status = phHciNfc_FSM_Complete(psHciContext);
\r
1702 /* Roll Back to the Select State */
\r
1703 phHciNfc_FSM_Rollback(psHciContext);
\r
1709 if(NFCSTATUS_SUCCESS == status )
\r
1711 /* Notify the Tag Events to the Upper layer */
\r
1712 phHciNfc_Notify( p_upper_notify, pcontext , pHwRef,
\r
1713 type, psCompInfo);
\r
1717 phHciNfc_Error_Sequence( psHciContext, pHwRef, status, NULL, 0 );
\r
1723 phHciNfc_Target_Select_Notify(
\r
1724 phHciNfc_sContext_t *psHciContext,
\r
1730 phNfc_sCompletionInfo_t *psCompInfo =
\r
1731 (phNfc_sCompletionInfo_t *)pInfo;
\r
1732 pphNfcIF_Notification_CB_t p_upper_notify = psHciContext->p_upper_notify;
\r
1733 void *pcontext = psHciContext->p_upper_context;
\r
1734 NFCSTATUS status = NFCSTATUS_SUCCESS;
\r
1736 switch( psHciContext->hci_state.next_state )
\r
1738 case hciState_Listen:
\r
1740 /* Roll Back to the Select State */
\r
1741 status = phHciNfc_FSM_Complete(psHciContext);
\r
1744 case hciState_Select:
\r
1746 status = phHciNfc_FSM_Complete(psHciContext);
\r
1751 /* Roll Back to the Select State */
\r
1752 phHciNfc_FSM_Rollback(psHciContext);
\r
1758 if(NFCSTATUS_SUCCESS == status )
\r
1760 /* Notify the Tag Events to the Upper layer */
\r
1761 phHciNfc_Notify( p_upper_notify, pcontext , pHwRef,
\r
1762 type, psCompInfo);
\r
1766 phHciNfc_Error_Sequence( psHciContext, pHwRef, status, NULL, 0 );
\r
1775 phHciNfc_Release_Notify(
\r
1776 phHciNfc_sContext_t *psHciContext,
\r
1782 phNfc_sCompletionInfo_t *psCompInfo =
\r
1783 (phNfc_sCompletionInfo_t *)pInfo;
\r
1784 pphNfcIF_Notification_CB_t p_upper_notify = psHciContext->p_upper_notify;
\r
1785 void *pcontext = psHciContext->p_upper_context;
\r
1786 phHciNfc_Release_Resources( &psHciContext );
\r
1787 /* Notify the Failure to the Upper Layer */
\r
1788 phHciNfc_Notify( p_upper_notify, pcontext , pHwRef,
\r
1789 type, psCompInfo);
\r
1794 phHciNfc_Notify_Event(
\r
1801 NFCSTATUS status = NFCSTATUS_SUCCESS;
\r
1803 if ( (NULL != psContext)
\r
1804 && (NULL != pInfo)
\r
1805 && (NULL != pHwRef)
\r
1808 phHciNfc_sContext_t *psHciContext = (phHciNfc_sContext_t *)psContext;
\r
1810 /* Process based on the Notification type */
\r
1813 case NFC_NOTIFY_INIT_COMPLETED:
\r
1815 phNfc_sCompletionInfo_t *psCompInfo =
\r
1816 (phNfc_sCompletionInfo_t *)pInfo;
\r
1817 if(NFCSTATUS_SUCCESS == psCompInfo->status)
\r
1820 #if (NXP_NFC_HCI_TIMER == 1)
\r
1821 if ( NXP_INVALID_TIMER_ID == hci_resp_timer_id )
\r
1823 /* Create and Intialise the Response Timer */
\r
1824 hci_resp_timer_id = phOsalNfc_Timer_Create( );
\r
1825 HCI_DEBUG(" HCI : Timer %X Created \n",
\r
1826 hci_resp_timer_id);
\r
1830 HCI_DEBUG(" HCI : Timer Already Created, Timer ID : %X\n",
\r
1831 hci_resp_timer_id);
\r
1833 gpsHciContext = psHciContext;
\r
1835 #endif /* (NXP_NFC_HCI_TIMER == 1) */
\r
1837 /* Complete the Initialisation Sequence */
\r
1838 status = phHciNfc_Resume_Sequence(psContext ,pHwRef);
\r
1842 /* Notify the Error Scenario to the Upper Layer */
\r
1843 phHciNfc_Notify(psHciContext->p_upper_notify,
\r
1844 psHciContext->p_upper_context, pHwRef,
\r
1845 NFC_NOTIFY_ERROR, psCompInfo);
\r
1849 case NFC_NOTIFY_INIT_FAILED:
\r
1851 /* Notify the Failure to the Upper Layer */
\r
1852 phHciNfc_Release_Notify( psContext,pHwRef,
\r
1856 case NFC_NOTIFY_RECV_COMPLETED:
\r
1858 /* Receive Completed from the Lower Layer */
\r
1859 phHciNfc_Receive_Complete(psContext,pHwRef,pInfo);
\r
1863 case NFC_NOTIFY_SEND_COMPLETED:
\r
1865 /* Receive Completed from the Lower Layer */
\r
1866 phHciNfc_Send_Complete(psContext,pHwRef,pInfo);
\r
1870 case NFC_NOTIFY_TRANSCEIVE_COMPLETED:
\r
1872 /* TODO: TO handle Both Send and Receive Complete */
\r
1875 case NFC_NOTIFY_TARGET_DISCOVERED:
\r
1877 HCI_PRINT(" PICC Discovery ! Obtain PICC Info .... \n");
\r
1878 /* psHciContext->hci_seq = PL_DURATION_SEQ; */
\r
1879 if ( hciState_Unknown == psHciContext->hci_state.next_state )
\r
1882 status = phHciNfc_FSM_Update ( psHciContext, hciState_Select );
\r
1885 if (NFCSTATUS_SUCCESS != status)
\r
1887 status = phHciNfc_ReaderMgmt_Deselect(
\r
1888 psHciContext, pHwRef, phHal_eISO14443_A_PICC, FALSE);
\r
1893 #ifdef SW_RELEASE_TARGET
\r
1894 /*status = phHciNfc_ReaderMgmt_Deselect(
\r
1895 psHciContext, pHwRef, phHal_eISO14443_A_PICC, FALSE); */
\r
1896 psHciContext->target_release = TRUE;
\r
1898 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_STATE);
\r
1903 /* To Notify the Target Released Notification
\r
1904 * to the Above Layer */
\r
1905 case NFC_NOTIFY_TARGET_RELEASED:
\r
1906 /* To Notify the NFC Secure Element Transaction
\r
1907 * Information to the Above Layer */
\r
1908 /* case NFC_NOTIFY_TRANSACTION: */
\r
1909 /* To Notify the Generic Events To the Upper
\r
1911 case NFC_NOTIFY_EVENT:
\r
1912 /* To Notify the Data Receive Notification
\r
1913 * to the Above Layer */
\r
1914 case NFC_NOTIFY_RECV_EVENT:
\r
1916 phNfc_sCompletionInfo_t *psCompInfo =
\r
1917 (phNfc_sCompletionInfo_t *)pInfo;
\r
1919 if (((TRUE == psHciContext->event_pending) ||
\r
1920 (NFCSTATUS_RF_TIMEOUT == psCompInfo->status))
\r
1921 && ( hciState_Transact == psHciContext->hci_state.next_state))
\r
1923 /* Rollback due to Transmission Error */
\r
1924 phHciNfc_FSM_Rollback(psHciContext);
\r
1926 psHciContext->event_pending = FALSE;
\r
1927 phHciNfc_Notify(psHciContext->p_upper_notify,
\r
1928 psHciContext->p_upper_context, pHwRef,
\r
1932 case NFC_NOTIFY_DEVICE_ACTIVATED:
\r
1934 HCI_PRINT(" Device Activated! Obtaining Remote Reader Info .... \n");
\r
1935 if ( hciState_Unknown == psHciContext->hci_state.next_state )
\r
1937 switch (psHciContext->host_rf_type)
\r
1939 case phHal_eISO14443_A_PCD:
\r
1940 case phHal_eISO14443_B_PCD:
\r
1941 case phHal_eISO14443_BPrime_PCD:
\r
1942 case phHal_eFelica_PCD:
\r
1946 case phHal_eNfcIP1_Initiator:
\r
1947 case phHal_eNfcIP1_Target:
\r
1951 case phHal_eUnknown_DevType:
\r
1954 status = PHNFCSTVAL(CID_NFC_HCI,
\r
1955 NFCSTATUS_INVALID_PARAMETER);
\r
1960 status = phHciNfc_FSM_Update ( psHciContext, hciState_Listen );
\r
1964 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_STATE);
\r
1968 case NFC_NOTIFY_DEVICE_DEACTIVATED:
\r
1970 HCI_PRINT(" Device De-Activated! \n");
\r
1971 if ( hciState_Unknown == psHciContext->hci_state.next_state )
\r
1973 status = phHciNfc_FSM_Update ( psHciContext, hciState_Initialise );
\r
1974 if(NFCSTATUS_SUCCESS == status)
\r
1976 /* Complete to the Select State */
\r
1977 status = phHciNfc_FSM_Complete(psHciContext);
\r
1981 HCI_PRINT(" Device Deactivated.. But Invalid State \n");
\r
1982 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_STATE);
\r
1987 status = phHciNfc_ReaderMgmt_Update_Sequence(
\r
1988 psHciContext, INFO_SEQ );
\r
1990 if(( hciState_Listen == psHciContext->hci_state.next_state)
\r
1991 || (hciState_Transact == psHciContext->hci_state.next_state))
\r
1993 psHciContext->hci_state.next_state = hciState_Initialise;
\r
1994 /* Roll Back to the Default State */
\r
1995 status = phHciNfc_FSM_Complete(psHciContext);
\r
1998 psHciContext->event_pending = FALSE;
\r
1999 phHciNfc_Notify(psHciContext->p_upper_notify,
\r
2000 psHciContext->p_upper_context, pHwRef,
\r
2001 NFC_NOTIFY_EVENT, pInfo);
\r
2004 case NFC_NOTIFY_DEVICE_ERROR:
\r
2006 phNfc_sCompletionInfo_t *psCompInfo =
\r
2007 (phNfc_sCompletionInfo_t *)pInfo;
\r
2009 psCompInfo->status = ( NFCSTATUS_BOARD_COMMUNICATION_ERROR
\r
2010 != PHNFCSTATUS(psCompInfo->status))?
\r
2011 NFCSTATUS_BOARD_COMMUNICATION_ERROR:
\r
2012 psCompInfo->status ;
\r
2014 #if (NXP_NFC_HCI_TIMER == 1)
\r
2016 if ( NXP_INVALID_TIMER_ID != hci_resp_timer_id )
\r
2018 HCI_DEBUG(" HCI : Response Timer Stop, Status:%02X",
\r
2019 psCompInfo->status);
\r
2020 /* Stop and Un-Intialise the Response Timer */
\r
2021 phOsalNfc_Timer_Stop( hci_resp_timer_id );
\r
2024 #endif /* (NXP_NFC_HCI_TIMER == 1) */
\r
2026 phHciNfc_Notify(psHciContext->p_upper_notify,
\r
2027 psHciContext->p_upper_context, pHwRef,
\r
2028 (uint8_t) NFC_NOTIFY_DEVICE_ERROR, pInfo);
\r
2033 case NFC_NOTIFY_ERROR:
\r
2036 phNfc_sCompletionInfo_t *psCompInfo =
\r
2037 (phNfc_sCompletionInfo_t *)pInfo;
\r
2039 #if (NXP_NFC_HCI_TIMER == 1)
\r
2041 if (( NFCSTATUS_BOARD_COMMUNICATION_ERROR == PHNFCSTATUS(psCompInfo->status))
\r
2042 && ( NXP_INVALID_TIMER_ID != hci_resp_timer_id ))
\r
2044 HCI_DEBUG(" HCI : Response Timer Stop, Status:%02X",
\r
2045 psCompInfo->status);
\r
2046 /* Stop the HCI Response Timer */
\r
2047 phOsalNfc_Timer_Stop( hci_resp_timer_id );
\r
2050 #endif /* (NXP_NFC_HCI_TIMER == 1) */
\r
2052 phHciNfc_Error_Sequence( psHciContext, pHwRef,
\r
2053 psCompInfo->status, NULL, 0);
\r
2056 } /* End of Switch */
\r
2057 } /* End of Context != NULL */
\r