2 * Copyright (C) 2010 NXP Semiconductors
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * =========================================================================== *
21 * \file phHciNfc_NfcIPMgmt.c *
22 * \brief HCI NFCIP-1 management routines. *
25 * Project: NFC-FRI-1.1 *
27 * $Date: Tue Jun 8 09:32:31 2010 $ *
28 * $Author: ing04880 $ *
30 * $Aliases: NFC_FRI1.1_WK1023_R35_1 $
32 * =========================================================================== *
36 ***************************** Header File Inclusion ****************************
38 #include <phNfcCompId.h>
39 #include <phNfcHalTypes.h>
40 #include <phHciNfc_Pipe.h>
41 #include <phHciNfc_RFReader.h>
42 #include <phHciNfc_Emulation.h>
43 #include <phOsalNfc.h>
45 #if defined (ENABLE_P2P)
46 #include <phHciNfc_NfcIPMgmt.h>
48 ****************************** Macro Definitions *******************************
51 #define NFCIP_RF_NO_ERROR 0x00U
52 #define NFCIP_STATUS_MAX_VALUE 0x01U
54 /* Read and write to the below registry for initiator and target */
55 #define NXP_NFCIP_MODE 0x01U
56 #define NXP_NFCIP_ATR_REQ 0x02U
57 #define NXP_NFCIP_ATR_RES 0x03U
58 #define NXP_NFCIP_PSL1 0x04U
59 #define NXP_NFCIP_PSL2 0x05U
60 #define NXP_NFCIP_DID 0x06U
61 #define NXP_NFCIP_NAD 0x07U
62 #define NXP_NFCIP_OPTIONS 0x08U
63 #define NXP_NFCIP_STATUS 0x09U
64 #define NXP_NFCIP_NFCID3I 0x0AU
65 #define NXP_NFCIP_NFCID3T 0x0BU
66 #define NXP_NFCIP_PARAM 0x0CU
67 #define NXP_NFCIP_MERGE 0x0DU
70 #define NXP_NFCIP_ATTREQUEST 0x12U
71 #define NXP_NFCI_CONTINUE_ACTIVATION 0x13U
74 #define NXP_EVT_NFC_SND_DATA 0x01U
75 #define NXP_EVT_NFC_ACTIVATED 0x02U
76 #define NXP_EVT_NFC_DEACTIVATED 0x03U
77 #define NXP_EVT_NFC_RCV_DATA 0x04U
78 #define NXP_EVT_NFC_CONTINUE_MI 0x05U
80 #define NFCIP_DATE_RATE_FACTOR 0x40U
81 #define NFCIP_DATE_RATE_SHIFT 0x06U
82 #define NFCIP_DATA_RATE_CALC(val) \
83 ((((uint8_t)(val) >> NFCIP_DATE_RATE_SHIFT) + \
84 0x01U) * NFCIP_DATE_RATE_FACTOR)
85 #define NFCIP_COMM_INITIATOR_SHIFT 0x03
86 #define NFCIP_COMM_FACTOR 0x03
88 *************************** Structure and Enumeration ***************************
92 *************************** Static Function Declaration **************************
96 phHciNfc_NfcIP_InfoUpdate(
97 phHciNfc_sContext_t *psHciContext,
105 phHciNfc_NfcIP_RecvData(
106 phHciNfc_sContext_t *psHciContext,
118 phHciNfc_Recv_NfcIP_Response(
119 phHciNfc_sContext_t *psHciContext,
120 phHciNfc_Pipe_Info_t *ppipe_info,
131 phHciNfc_Recv_NfcIP_Event(
132 phHciNfc_sContext_t *psHciContext,
144 phHciNfc_Recv_Initiator_Event(
157 phHciNfc_Recv_Target_Event(
170 phHciNfc_Recv_Initiator_Response(
183 phHciNfc_Recv_Target_Response(
194 *************************** Function Definitions ***************************
198 phHciNfc_Initiator_Init_Resources(
199 phHciNfc_sContext_t *psHciContext
202 NFCSTATUS status = NFCSTATUS_SUCCESS;
203 phHciNfc_NfcIP_Info_t *p_init_info=NULL;
204 if( NULL == psHciContext )
206 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
210 if (NULL != psHciContext->p_nfcip_info)
212 status = NFCSTATUS_SUCCESS;
214 else if(( NULL == psHciContext->p_nfcip_info ) &&
215 (phHciNfc_Allocate_Resource((void **)(&p_init_info),
216 sizeof(phHciNfc_NfcIP_Info_t))== NFCSTATUS_SUCCESS)
219 psHciContext->p_nfcip_info = p_init_info;
220 p_init_info->nfcip_type = NFCIP_INVALID;
221 p_init_info->current_seq = NFCIP_INVALID_SEQUENCE;
222 p_init_info->next_seq = NFCIP_INVALID_SEQUENCE;
223 p_init_info->p_init_pipe_info = NULL;
224 p_init_info->p_tgt_pipe_info = NULL;
228 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INSUFFICIENT_RESOURCES);
236 phHciNfc_Initiator_Get_PipeID(
237 phHciNfc_sContext_t *psHciContext,
241 NFCSTATUS status = NFCSTATUS_SUCCESS;
242 if( (NULL != psHciContext)
243 && ( NULL != ppipe_id )
244 && ( NULL != psHciContext->p_nfcip_info )
247 phHciNfc_NfcIP_Info_t *p_init_info=NULL;
248 p_init_info = (phHciNfc_NfcIP_Info_t *)
249 psHciContext->p_nfcip_info ;
250 *ppipe_id = p_init_info->p_init_pipe_info->pipe.pipe_id ;
254 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
260 phHciNfc_Initiator_Update_PipeInfo(
261 phHciNfc_sContext_t *psHciContext,
263 phHciNfc_Pipe_Info_t *pPipeInfo
266 NFCSTATUS status = NFCSTATUS_SUCCESS;
267 if( NULL == psHciContext )
269 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
271 else if(NULL == psHciContext->p_nfcip_info)
273 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
277 phHciNfc_NfcIP_Info_t *p_init_info=NULL;
278 p_init_info = (phHciNfc_NfcIP_Info_t *)
279 psHciContext->p_nfcip_info ;
280 /* Update the pipe_id of the NFCIP-1 initiator Gate obtained from
282 p_init_info->p_init_pipe_info = pPipeInfo;
283 p_init_info->p_init_pipe_info->pipe.pipe_id = pipeID;
284 /* Update the Response Receive routine of the NFCIP-1 initiator Gate */
285 pPipeInfo->recv_resp = &phHciNfc_Recv_Initiator_Response;
286 /* Update the event Receive routine of the NFCIP-1 initiator Gate */
287 pPipeInfo->recv_event = &phHciNfc_Recv_Initiator_Event;
293 phHciNfc_NfcIP_Presence_Check(
294 phHciNfc_sContext_t *psHciContext,
298 NFCSTATUS status = NFCSTATUS_SUCCESS;
300 if( (NULL == psHciContext) || (NULL == pHwRef) )
302 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
304 else if((NULL == psHciContext->p_nfcip_info) ||
306 ((phHciNfc_NfcIP_Info_t *)(psHciContext->p_nfcip_info))->nfcip_type))
308 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
312 phHciNfc_NfcIP_Info_t *p_nfcipinfo=NULL;
313 phHciNfc_Pipe_Info_t *p_pipe_info=NULL;
315 p_nfcipinfo = (phHciNfc_NfcIP_Info_t *)
316 psHciContext->p_nfcip_info ;
317 p_pipe_info = ((NFCIP_INITIATOR == p_nfcipinfo->nfcip_type)?
318 p_nfcipinfo->p_init_pipe_info :
319 p_nfcipinfo->p_tgt_pipe_info);
321 if(NULL == p_pipe_info )
323 status = PHNFCSTVAL(CID_NFC_HCI,
324 NFCSTATUS_INVALID_HCI_INFORMATION);
328 phHciNfc_HCP_Packet_t *hcp_packet = NULL;
329 uint16_t length = HCP_HEADER_LEN;
332 pipeid = p_pipe_info->pipe.pipe_id;
333 psHciContext->tx_total = 0 ;
334 hcp_packet = (phHciNfc_HCP_Packet_t *) psHciContext->send_buffer;
335 /* Construct the HCP Frame */
336 phHciNfc_Build_HCPFrame(hcp_packet,(uint8_t)HCP_CHAINBIT_DEFAULT,
337 (uint8_t) pipeid, (uint8_t)HCP_MSG_TYPE_COMMAND,
338 (uint8_t)NXP_NFCIP_ATTREQUEST);
340 p_pipe_info->sent_msg_type = (uint8_t)HCP_MSG_TYPE_COMMAND;
341 p_pipe_info->prev_msg = (uint8_t)NXP_NFCIP_ATTREQUEST;
342 psHciContext->tx_total = length;
343 psHciContext->response_pending = (uint8_t)TRUE;
345 /* Send the Constructed HCP packet to the lower layer */
346 status = phHciNfc_Send_HCP( psHciContext, pHwRef);
347 p_pipe_info->prev_status = status;
355 phHciNfc_Recv_Initiator_Response(
366 NFCSTATUS status = NFCSTATUS_SUCCESS;
367 phHciNfc_sContext_t *psHciContext =
368 (phHciNfc_sContext_t *)pContext ;
370 if( (NULL == psHciContext) || (NULL == pHwRef) || (NULL == pResponse)
373 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
375 else if(NULL == psHciContext->p_nfcip_info)
377 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
381 phHciNfc_NfcIP_Info_t *p_nfcip_info=NULL;
382 phHciNfc_Pipe_Info_t *p_pipe_info = NULL;
384 p_nfcip_info = (phHciNfc_NfcIP_Info_t *)
385 psHciContext->p_nfcip_info ;
386 p_pipe_info = p_nfcip_info->p_init_pipe_info;
387 if( NULL == p_pipe_info)
389 status = PHNFCSTVAL(CID_NFC_HCI,
390 NFCSTATUS_INVALID_HCI_INFORMATION);
394 status = phHciNfc_Recv_NfcIP_Response(psHciContext,
395 p_pipe_info, pResponse,
397 if (NFCSTATUS_SUCCESS == status)
399 status = phHciNfc_ReaderMgmt_Update_Sequence(psHciContext,
409 phHciNfc_Recv_Initiator_Event(
420 NFCSTATUS status = NFCSTATUS_SUCCESS;
421 phHciNfc_sContext_t *psHciContext =
422 (phHciNfc_sContext_t *)psContext ;
423 if( (NULL == psHciContext) || (NULL == pHwRef) || (NULL == pEvent)
426 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
428 else if(NULL == psHciContext->p_nfcip_info)
430 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
434 phHciNfc_HCP_Packet_t *p_packet = NULL;
435 phHciNfc_NfcIP_Info_t *p_nfcip_info=NULL;
436 phHciNfc_HCP_Message_t *message = NULL;
437 uint8_t instruction=0;
439 p_nfcip_info = (phHciNfc_NfcIP_Info_t *)
440 psHciContext->p_nfcip_info ;
441 p_packet = (phHciNfc_HCP_Packet_t *)pEvent;
442 message = &p_packet->msg.message;
443 /* Get the instruction bits from the Message Header */
444 instruction = (uint8_t) GET_BITS8( message->msg_header,
445 HCP_MSG_INSTRUCTION_OFFSET, HCP_MSG_INSTRUCTION_LEN);
446 if (NXP_EVT_NFC_ACTIVATED == instruction)
448 p_nfcip_info->nfcip_type = NFCIP_INITIATOR;
449 psHciContext->host_rf_type = phHal_eNfcIP1_Initiator;
450 p_nfcip_info->rem_nfcip_tgt_info.RemDevType = phHal_eNfcIP1_Target;
453 status = phHciNfc_Recv_NfcIP_Event(psHciContext,
454 pHwRef, pEvent, length);
460 phHciNfc_Target_Init_Resources(
461 phHciNfc_sContext_t *psHciContext
464 NFCSTATUS status = NFCSTATUS_SUCCESS;
465 phHciNfc_NfcIP_Info_t *p_target_info=NULL;
466 if( NULL == psHciContext )
468 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
472 if (NULL != psHciContext->p_nfcip_info)
474 status = NFCSTATUS_SUCCESS;
477 ( NULL == psHciContext->p_nfcip_info ) &&
478 (phHciNfc_Allocate_Resource((void **)(&p_target_info),
479 sizeof(phHciNfc_NfcIP_Info_t))== NFCSTATUS_SUCCESS)
482 psHciContext->p_nfcip_info = p_target_info;
483 p_target_info->nfcip_type = NFCIP_INVALID;
484 p_target_info->current_seq = NFCIP_INVALID_SEQUENCE;
485 p_target_info->next_seq = NFCIP_INVALID_SEQUENCE;
486 p_target_info->p_tgt_pipe_info = NULL;
487 p_target_info->p_tgt_pipe_info = NULL;
491 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INSUFFICIENT_RESOURCES);
499 phHciNfc_Target_Get_PipeID(
500 phHciNfc_sContext_t *psHciContext,
504 NFCSTATUS status = NFCSTATUS_SUCCESS;
505 if( (NULL != psHciContext)
506 && ( NULL != ppipe_id )
507 && ( NULL != psHciContext->p_nfcip_info )
510 phHciNfc_NfcIP_Info_t *p_target_info=NULL;
511 p_target_info = (phHciNfc_NfcIP_Info_t *)
512 psHciContext->p_nfcip_info ;
513 *ppipe_id = p_target_info->p_tgt_pipe_info->pipe.pipe_id;
517 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
523 phHciNfc_Target_Update_PipeInfo(
524 phHciNfc_sContext_t *psHciContext,
526 phHciNfc_Pipe_Info_t *pPipeInfo
529 NFCSTATUS status = NFCSTATUS_SUCCESS;
530 if( NULL == psHciContext )
532 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
534 else if(NULL == psHciContext->p_nfcip_info)
536 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
540 phHciNfc_NfcIP_Info_t *p_target_info=NULL;
541 p_target_info = (phHciNfc_NfcIP_Info_t *)
542 psHciContext->p_nfcip_info ;
543 /* Update the pipe_id of the NFCIP-1 target Gate obtained from
545 p_target_info->p_tgt_pipe_info = pPipeInfo;
546 p_target_info->p_tgt_pipe_info->pipe.pipe_id = pipeID;
547 /* Update the Response Receive routine of the NFCIP-1 target Gate */
548 pPipeInfo->recv_resp = &phHciNfc_Recv_Target_Response;
549 /* Update the event Receive routine of the NFCIP-1 target Gate */
550 pPipeInfo->recv_event = &phHciNfc_Recv_Target_Event;
557 phHciNfc_Recv_Target_Response(
568 NFCSTATUS status = NFCSTATUS_SUCCESS;
569 phHciNfc_sContext_t *psHciContext =
570 (phHciNfc_sContext_t *)pContext ;
572 if( (NULL == psHciContext) || (NULL == pHwRef) || (NULL == pResponse)
575 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
577 else if(NULL == psHciContext->p_nfcip_info)
579 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
583 phHciNfc_NfcIP_Info_t *p_nfcip_info=NULL;
584 phHciNfc_Pipe_Info_t *p_pipe_info = NULL;
586 p_nfcip_info = (phHciNfc_NfcIP_Info_t *)
587 psHciContext->p_nfcip_info ;
588 p_pipe_info = p_nfcip_info->p_tgt_pipe_info;
589 if( NULL == p_pipe_info)
591 status = PHNFCSTVAL(CID_NFC_HCI,
592 NFCSTATUS_INVALID_HCI_INFORMATION);
596 status = phHciNfc_Recv_NfcIP_Response(psHciContext,
597 p_pipe_info, pResponse,
599 if (NFCSTATUS_SUCCESS == status)
601 status = phHciNfc_EmuMgmt_Update_Seq(psHciContext,
611 phHciNfc_Recv_Target_Event(
622 NFCSTATUS status = NFCSTATUS_SUCCESS;
623 phHciNfc_sContext_t *psHciContext =
624 (phHciNfc_sContext_t *)psContext ;
625 if( (NULL == psHciContext) || (NULL == pHwRef) || (NULL == pEvent)
628 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
630 else if(NULL == psHciContext->p_nfcip_info)
632 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
636 phHciNfc_HCP_Packet_t *p_packet = NULL;
637 phHciNfc_NfcIP_Info_t *p_nfcip_info=NULL;
638 phHciNfc_HCP_Message_t *message = NULL;
639 uint8_t instruction=0;
641 p_nfcip_info = (phHciNfc_NfcIP_Info_t *)psHciContext->p_nfcip_info ;
642 p_packet = (phHciNfc_HCP_Packet_t *)pEvent;
643 message = &p_packet->msg.message;
644 /* Get the instruction bits from the Message Header */
645 instruction = (uint8_t) GET_BITS8( message->msg_header,
646 HCP_MSG_INSTRUCTION_OFFSET, HCP_MSG_INSTRUCTION_LEN);
647 if (NXP_EVT_NFC_ACTIVATED == instruction)
649 p_nfcip_info->nfcip_type = NFCIP_TARGET;
650 psHciContext->host_rf_type = phHal_eNfcIP1_Target;
651 p_nfcip_info->rem_nfcip_tgt_info.RemDevType =
652 phHal_eNfcIP1_Initiator;
654 status = phHciNfc_Recv_NfcIP_Event(psHciContext,
655 pHwRef, pEvent, length);
662 phHciNfc_Recv_NfcIP_Response(
663 phHciNfc_sContext_t *psHciContext,
664 phHciNfc_Pipe_Info_t *ppipe_info,
673 NFCSTATUS status = NFCSTATUS_SUCCESS;
674 phHciNfc_NfcIP_Info_t *p_nfcipinfo=NULL;
675 uint8_t prev_cmd = ANY_GET_PARAMETER;
677 p_nfcipinfo = (phHciNfc_NfcIP_Info_t *)
678 psHciContext->p_nfcip_info ;
679 prev_cmd = ppipe_info->prev_msg ;
684 HCI_PRINT("NFCIP-1 NFCIP open pipe complete\n");
685 p_nfcipinfo->next_seq = NFCIP_NFCID3I;
690 HCI_PRINT("NFCIP-1 NFCIP close pipe complete\n");
691 p_nfcipinfo->next_seq = NFCIP_NFCID3I;
694 case ANY_GET_PARAMETER:
696 HCI_PRINT("NFCIP-1 NFCIP get parameter complete\n");
697 if (length >= HCP_HEADER_LEN)
699 status = phHciNfc_NfcIP_InfoUpdate(psHciContext,
700 ppipe_info->reg_index,
701 &pResponse[HCP_HEADER_LEN],
702 (uint8_t)(length - HCP_HEADER_LEN));
706 status = PHNFCSTVAL(CID_NFC_HCI,
707 NFCSTATUS_INVALID_HCI_RESPONSE);
711 case ANY_SET_PARAMETER:
713 HCI_PRINT("NFCIP-1 NFCIP Parameter Set \n");
714 p_nfcipinfo->next_seq = NFCIP_NFCID3I;
717 case NXP_NFCI_CONTINUE_ACTIVATION:
718 case NXP_NFCIP_ATTREQUEST:
720 p_nfcipinfo->next_seq = NFCIP_NFCID3I;
725 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_RESPONSE);
730 if( NFCSTATUS_SUCCESS == status )
732 ppipe_info->prev_status = NFCSTATUS_SUCCESS;
733 p_nfcipinfo->current_seq = p_nfcipinfo->next_seq;
740 phHciNfc_Recv_NfcIP_Event(
741 phHciNfc_sContext_t *psHciContext,
751 NFCSTATUS status = NFCSTATUS_SUCCESS;
752 phHciNfc_HCP_Packet_t *p_packet = NULL;
753 phHciNfc_NfcIP_Info_t *p_nfcipinfo=NULL;
754 phHciNfc_HCP_Message_t *message = NULL;
755 phNfc_sCompletionInfo_t pCompInfo;
756 uint8_t instruction=0;
759 p_nfcipinfo = (phHciNfc_NfcIP_Info_t *)
760 psHciContext->p_nfcip_info ;
761 p_packet = (phHciNfc_HCP_Packet_t *)pEvent;
762 message = &p_packet->msg.message;
763 /* Get the instruction bits from the Message Header */
764 instruction = (uint8_t) GET_BITS8( message->msg_header,
765 HCP_MSG_INSTRUCTION_OFFSET, HCP_MSG_INSTRUCTION_LEN);
769 case NXP_EVT_NFC_ACTIVATED:
771 HCI_PRINT("NFCIP-1 device discovered\n");
773 if (NFCIP_INITIATOR == p_nfcipinfo->nfcip_type)
775 pCompInfo.info = &(p_nfcipinfo->rem_nfcip_tgt_info);
776 type = NFC_NOTIFY_TARGET_DISCOVERED;
780 type = NFC_NOTIFY_DEVICE_ACTIVATED;
783 if(length > HCP_HEADER_LEN)
785 HCI_DEBUG("NfcIP-1 activation mode : %d\n", pEvent[HCP_HEADER_LEN]);
786 /* Mode indicates in which mode the current activation
790 p_nfcipinfo->activation_mode = pEvent[HCP_HEADER_LEN];
792 pCompInfo.status = NFCSTATUS_SUCCESS;
793 /* Notify to the HCI Generic layer To Update the FSM */
794 phHciNfc_Notify_Event(psHciContext, pHwRef,
798 case NXP_EVT_NFC_DEACTIVATED:
800 static phHal_sEventInfo_t event_info;
802 event_info.eventHost = phHal_eHostController;
803 event_info.eventType = NFC_EVT_DEACTIVATED;
804 p_nfcipinfo->activation_mode = FALSE;
805 if (NFCIP_INITIATOR == p_nfcipinfo->nfcip_type)
807 p_nfcipinfo->rem_nfcip_tgt_info.RemDevType =
808 phHal_eNfcIP1_Target;
809 event_info.eventSource = phHal_eNfcIP1_Initiator;
813 p_nfcipinfo->rem_nfcip_tgt_info.RemDevType =
814 phHal_eNfcIP1_Initiator;
815 event_info.eventSource = phHal_eNfcIP1_Target;
817 /* Reset the sequence */
818 p_nfcipinfo->current_seq = NFCIP_NFCID3I;
819 p_nfcipinfo->next_seq = NFCIP_NFCID3I;
821 HCI_PRINT("NFCIP-1 Target Deactivated\n");
822 phHciNfc_Notify_Event(psHciContext, pHwRef,
823 NFC_NOTIFY_DEVICE_DEACTIVATED,
827 case NXP_EVT_NFC_RCV_DATA:
829 status = phHciNfc_NfcIP_RecvData(psHciContext,
831 &pEvent[HCP_HEADER_LEN],
832 (length - HCP_HEADER_LEN));
835 case NXP_EVT_NFC_CONTINUE_MI:
837 /* psHciContext->response_pending = FALSE; */
838 psHciContext->event_pending = FALSE;
843 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
853 phHciNfc_NfcIP_RecvData(
854 phHciNfc_sContext_t *psHciContext,
864 NFCSTATUS status = NFCSTATUS_SUCCESS;
867 if( (NULL == psHciContext)
869 || (NULL == pResponse)
872 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
876 phNfc_sTransactionInfo_t transInfo;
877 phHciNfc_NfcIP_Info_t *p_nfcipinfo = NULL;
880 p_nfcipinfo = (phHciNfc_NfcIP_Info_t *)
881 psHciContext->p_nfcip_info;
882 HCI_PRINT("NFCIP-1 received bytes :");
883 if (NFCIP_RF_NO_ERROR == pResponse[index])
885 HCI_PRINT_BUFFER("device ", &pResponse[index], (length - index));
886 transInfo.status = NFCSTATUS_SUCCESS;
888 if (TRUE == pResponse[index])
890 /* Update the more information bit to the upper layer */
891 transInfo.status = NFCSTATUS_MORE_INFORMATION;
896 transInfo.buffer = &pResponse[index];
897 transInfo.length = (length - index);
898 type = (uint8_t)NFC_NOTIFY_RECV_EVENT;
902 HCI_PRINT("NFCIP-1 receive RF ERROR ");
903 p_nfcipinfo->activation_mode = FALSE;
904 type = (uint8_t)NFC_NOTIFY_RECV_EVENT;
905 transInfo.status = NFCSTATUS_RF_TIMEOUT;
906 transInfo.buffer = NULL;
907 transInfo.length = 0;
909 status = NFCSTATUS_PENDING;
910 /* Event NXP_EVT_NFC_RCV_DATA: so give received data to
912 phHciNfc_Notify_Event(psHciContext, pHwRef,
920 phHciNfc_NfcIP_Send_Data (
921 phHciNfc_sContext_t *psHciContext,
923 phHciNfc_XchgInfo_t *sData
926 NFCSTATUS status = NFCSTATUS_SUCCESS;
928 if( (NULL == psHciContext) || (NULL == pHwRef) || (NULL == sData) ||
929 (NULL == sData->tx_buffer) || (0 == sData->tx_length))
931 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
933 else if((NULL == psHciContext->p_nfcip_info) ||
935 ((phHciNfc_NfcIP_Info_t *)(psHciContext->p_nfcip_info))->nfcip_type))
937 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
941 phHciNfc_NfcIP_Info_t *p_nfcipinfo=NULL;
942 phHciNfc_Pipe_Info_t *p_pipe_info=NULL;
944 p_nfcipinfo = (phHciNfc_NfcIP_Info_t *)
945 psHciContext->p_nfcip_info ;
946 p_pipe_info = ((NFCIP_INITIATOR == p_nfcipinfo->nfcip_type)?
947 p_nfcipinfo->p_init_pipe_info :
948 p_nfcipinfo->p_tgt_pipe_info);
950 if(NULL == p_pipe_info )
952 status = PHNFCSTVAL(CID_NFC_HCI,
953 NFCSTATUS_INVALID_HCI_INFORMATION);
957 phHciNfc_HCP_Packet_t *hcp_packet = NULL;
958 phHciNfc_HCP_Message_t *hcp_message = NULL;
959 uint16_t length = HCP_HEADER_LEN;
963 HCI_PRINT_BUFFER("HCI NFCIP-1 Send Data: ", sData->tx_buffer, sData->tx_length);
965 psHciContext->tx_total = 0 ;
966 pipeid = p_pipe_info->pipe.pipe_id;
967 hcp_packet = (phHciNfc_HCP_Packet_t *) psHciContext->send_buffer;
968 hcp_message = &(hcp_packet->msg.message);
969 hcp_message->payload[i] = sData->params.nfc_info.more_info;
972 /* Construct the HCP Frame */
973 phHciNfc_Build_HCPFrame(hcp_packet,(uint8_t)HCP_CHAINBIT_DEFAULT,
974 (uint8_t) pipeid, (uint8_t)HCP_MSG_TYPE_EVENT,
975 (uint8_t)NXP_EVT_NFC_SND_DATA);
977 phHciNfc_Append_HCPFrame((uint8_t *)hcp_message->payload,
978 i, (uint8_t *)sData->tx_buffer,
979 (uint8_t)sData->tx_length);
981 length =(uint16_t)(length + i + sData->tx_length);
983 p_pipe_info->sent_msg_type = (uint8_t)HCP_MSG_TYPE_EVENT;
984 p_pipe_info->prev_msg = NXP_EVT_NFC_SND_DATA;
985 psHciContext->tx_total = length;
986 /* Send the Constructed HCP packet to the lower layer */
987 status = phHciNfc_Send_HCP( psHciContext, pHwRef);
988 #if !defined (ENABLE_CONTINUE_MI)
989 if ((TRUE == sData->params.nfc_info.more_info) &&
990 (NFCSTATUS_PENDING == status))
992 /* If more information bit is set, then wait for the event
993 NXP_EVT_NFC_CONTINUE_MI */
994 /* psHciContext->response_pending = TRUE; */
995 psHciContext->event_pending = TRUE;
997 #endif /* #if defined (ENABLE_CONTINUE_MI) */
998 p_pipe_info->prev_status = status;
1005 phHciNfc_NfcIP_Info_Sequence (
1006 phHciNfc_sContext_t *psHciContext,
1011 #endif /* #ifdef NOTIFY_REQD */
1014 NFCSTATUS status = NFCSTATUS_SUCCESS;
1016 if( (NULL == psHciContext)
1020 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1022 else if((NULL == psHciContext->p_nfcip_info) ||
1024 ((phHciNfc_NfcIP_Info_t *)(psHciContext->p_nfcip_info))->
1027 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
1031 phHciNfc_NfcIP_Info_t *p_nfcipinfo=NULL;
1032 phHciNfc_Pipe_Info_t *p_pipe_info=NULL;
1034 p_nfcipinfo = (phHciNfc_NfcIP_Info_t *)
1035 psHciContext->p_nfcip_info ;
1036 p_pipe_info = ((NFCIP_INITIATOR == p_nfcipinfo->nfcip_type)?
1037 p_nfcipinfo->p_init_pipe_info:
1038 p_nfcipinfo->p_tgt_pipe_info);
1039 if(NULL == p_pipe_info )
1041 status = PHNFCSTVAL(CID_NFC_HCI,
1042 NFCSTATUS_INVALID_HCI_INFORMATION);
1046 switch(p_nfcipinfo->current_seq)
1050 p_pipe_info->reg_index = (uint8_t)NXP_NFCIP_NFCID3I;
1051 /* Fill the data buffer and send the command to the
1054 phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef,
1055 p_pipe_info->pipe.pipe_id,
1057 if(NFCSTATUS_PENDING == status )
1059 p_nfcipinfo->next_seq = NFCIP_NFCID3T;
1065 p_pipe_info->reg_index = (uint8_t)NXP_NFCIP_NFCID3T;
1066 /* Fill the data buffer and send the command to the
1069 phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef,
1070 p_pipe_info->pipe.pipe_id,
1072 if(NFCSTATUS_PENDING == status )
1074 p_nfcipinfo->next_seq = NFCIP_PARAM;
1080 p_pipe_info->reg_index = (uint8_t)NXP_NFCIP_PARAM;
1081 /* Fill the data buffer and send the command to the
1084 phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef,
1085 p_pipe_info->pipe.pipe_id,
1087 if(NFCSTATUS_PENDING == status )
1089 p_nfcipinfo->next_seq = NFCIP_ATR_INFO;
1093 case NFCIP_ATR_INFO:
1095 p_pipe_info->reg_index = (uint8_t)((NFCIP_INITIATOR ==
1096 p_nfcipinfo->nfcip_type)?
1100 phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef,
1101 p_pipe_info->pipe.pipe_id,
1104 if(NFCSTATUS_PENDING == status )
1106 p_nfcipinfo->next_seq = NFCIP_STATUS;
1112 p_pipe_info->reg_index = (uint8_t)NXP_NFCIP_STATUS;
1113 /* Fill the data buffer and send the command to the
1116 phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef,
1117 p_pipe_info->pipe.pipe_id,
1119 if(NFCSTATUS_PENDING == status )
1122 if(FALSE == notify_reqd)
1123 #else /* #ifdef NOTIFY_REQD */
1124 if (NULL != psHciContext->p_target_info)
1125 #endif /* #ifdef NOTIFY_REQD */
1127 p_nfcipinfo->next_seq = NFCIP_NFCID3I;
1128 status = NFCSTATUS_SUCCESS;
1132 p_nfcipinfo->next_seq = NFCIP_END_SEQUENCE;
1137 case NFCIP_END_SEQUENCE:
1139 phHal_uRemoteDevInfo_t *rem_nfcipinfo = NULL;
1141 if (NULL != psHciContext->p_target_info)
1143 /* This is given to user */
1145 &(psHciContext->p_target_info->RemoteDevInfo);
1150 &(p_nfcipinfo->rem_nfcip_tgt_info.RemoteDevInfo);
1153 /* Update maximum frame length */
1154 rem_nfcipinfo->NfcIP_Info.MaxFrameLength =
1155 p_nfcipinfo->max_frame_len;
1157 p_nfcipinfo->current_seq = NFCIP_NFCID3I;
1158 p_nfcipinfo->next_seq = NFCIP_NFCID3I;
1160 rem_nfcipinfo->NfcIP_Info.Nfcip_Active =
1161 p_nfcipinfo->activation_mode;
1164 if (NFCIP_INITIATOR == p_nfcipinfo->nfcip_type)
1166 phNfc_sCompletionInfo_t CompInfo;
1168 p_nfcipinfo->rem_nfcip_tgt_info.RemDevType =
1169 phHal_eNfcIP1_Target;
1171 /* Update initiator speed */
1172 rem_nfcipinfo->NfcIP_Info.Nfcip_Datarate =
1173 (phHalNfc_eDataRate_t)
1174 (p_nfcipinfo->initiator_speed);
1177 /* Update ATR info */
1178 rem_nfcipinfo->NfcIP_Info.ATRInfo_Length =
1179 p_nfcipinfo->atr_res_length;
1181 (void *)rem_nfcipinfo->NfcIP_Info.ATRInfo,
1182 (void *)p_nfcipinfo->atr_res_info,
1183 rem_nfcipinfo->NfcIP_Info.ATRInfo_Length);
1186 rem_nfcipinfo->NfcIP_Info.NFCID_Length =
1187 p_nfcipinfo->nfcid3i_length;
1189 (void *)rem_nfcipinfo->NfcIP_Info.NFCID,
1190 (void *)p_nfcipinfo->nfcid3i,
1191 rem_nfcipinfo->NfcIP_Info.NFCID_Length);
1193 CompInfo.status = status = NFCSTATUS_SUCCESS;
1194 if (NULL != psHciContext->p_target_info)
1196 CompInfo.info = &(psHciContext->p_target_info);
1200 CompInfo.info = &(p_nfcipinfo->rem_nfcip_tgt_info);
1202 /* Notify to the upper layer */
1203 phHciNfc_Tag_Notify(psHciContext, pHwRef,
1204 NFC_NOTIFY_TARGET_DISCOVERED,
1209 static phHal_sEventInfo_t event_info;
1211 p_nfcipinfo->rem_nfcip_tgt_info.RemDevType =
1212 phHal_eNfcIP1_Initiator;
1214 /* Update target speed */
1215 rem_nfcipinfo->NfcIP_Info.Nfcip_Datarate =
1216 (phHalNfc_eDataRate_t)
1217 (p_nfcipinfo->target_speed);
1218 /* Update ATR info */
1219 rem_nfcipinfo->NfcIP_Info.ATRInfo_Length =
1220 p_nfcipinfo->atr_req_length;
1222 (void *)rem_nfcipinfo->NfcIP_Info.ATRInfo,
1223 (void *)p_nfcipinfo->atr_req_info,
1224 rem_nfcipinfo->NfcIP_Info.ATRInfo_Length);
1227 rem_nfcipinfo->NfcIP_Info.NFCID_Length =
1228 p_nfcipinfo->nfcid3t_length;
1230 (void *)rem_nfcipinfo->NfcIP_Info.NFCID,
1231 (void *)p_nfcipinfo->nfcid3t,
1232 rem_nfcipinfo->NfcIP_Info.NFCID_Length);
1234 event_info.eventHost = phHal_eHostController;
1235 event_info.eventType = NFC_EVT_ACTIVATED;
1236 event_info.eventSource = phHal_eNfcIP1_Target;
1237 event_info.eventInfo.pRemoteDevInfo =
1238 &(p_nfcipinfo->rem_nfcip_tgt_info);
1240 phHciNfc_Target_Select_Notify((void *)psHciContext,
1249 status = PHNFCSTVAL(CID_NFC_HCI,
1250 NFCSTATUS_INVALID_HCI_RESPONSE);
1261 phHciNfc_NfcIP_InfoUpdate(
1262 phHciNfc_sContext_t *psHciContext,
1268 NFCSTATUS status = NFCSTATUS_SUCCESS;
1269 phHciNfc_NfcIP_Info_t *p_nfcipinfo = NULL;
1270 phHal_sNfcIPInfo_t *p_rem_nfcipinfo = NULL;
1272 p_nfcipinfo = (phHciNfc_NfcIP_Info_t *)(psHciContext->p_nfcip_info );
1273 p_rem_nfcipinfo = &(p_nfcipinfo->rem_nfcip_tgt_info.RemoteDevInfo.NfcIP_Info);
1278 case NXP_NFCIP_ATR_RES:
1280 if (reg_length <= NFCIP_ATR_MAX_LENGTH)
1282 /* Remote device info provided by the user */
1284 HCI_PRINT_BUFFER("\tNFCIP ATR_RES", reg_value, reg_length);
1286 p_rem_nfcipinfo->ATRInfo_Length =
1287 p_nfcipinfo->atr_res_length = reg_length;
1289 (void)memcpy((void *)p_rem_nfcipinfo->ATRInfo,
1291 p_rem_nfcipinfo->ATRInfo_Length);
1293 (void)memcpy((void *)p_nfcipinfo->atr_res_info,
1295 p_nfcipinfo->atr_res_length);
1296 if (NULL != psHciContext->p_target_info)
1298 phHal_sNfcIPInfo_t *p_remtgt_info = NULL;
1299 /* This is given to user */
1301 &(psHciContext->p_target_info->RemoteDevInfo.NfcIP_Info);
1302 p_remtgt_info->ATRInfo_Length = reg_length;
1303 (void)memcpy((void *)p_remtgt_info->ATRInfo,
1305 p_remtgt_info->ATRInfo_Length);
1310 status = PHNFCSTVAL(CID_NFC_HCI,
1311 NFCSTATUS_INVALID_HCI_RESPONSE);
1315 case NXP_NFCIP_STATUS:
1317 if (sizeof(*reg_value) == reg_length)
1318 #ifdef STATUS_BUFFER_CHECK
1319 && (*reg_value <= NFCIP_STATUS_MAX_VALUE))
1320 #endif /* #ifdef STATUS_ERROR */
1322 HCI_PRINT_BUFFER("\tNFCIP STATUS", reg_value, reg_length);
1323 p_nfcipinfo->linkstatus = *reg_value;
1327 status = PHNFCSTVAL(CID_NFC_HCI,
1328 NFCSTATUS_INVALID_HCI_RESPONSE);
1332 case NXP_NFCIP_NFCID3I:
1334 if (reg_length <= NFCIP_NFCID_LENGTH)
1336 HCI_PRINT_BUFFER("\tNFCIP NFCID3I", reg_value, reg_length);
1337 p_nfcipinfo->nfcid3i_length =
1338 p_rem_nfcipinfo->NFCID_Length = reg_length;
1339 (void)memcpy((void *)p_rem_nfcipinfo->NFCID,
1341 p_rem_nfcipinfo->NFCID_Length);
1342 (void)memcpy((void *)p_nfcipinfo->nfcid3i,
1345 if ((NULL != psHciContext->p_target_info) &&
1346 (NFCIP_INITIATOR == p_nfcipinfo->nfcip_type))
1348 phHal_sNfcIPInfo_t *p_remtgt_info = NULL;
1349 /* This is given to user */
1351 &(psHciContext->p_target_info->RemoteDevInfo.NfcIP_Info);
1352 p_remtgt_info->NFCID_Length = reg_length;
1353 (void)memcpy((void *)p_remtgt_info->NFCID,
1355 p_remtgt_info->NFCID_Length);
1360 status = PHNFCSTVAL(CID_NFC_HCI,
1361 NFCSTATUS_INVALID_HCI_RESPONSE);
1365 case NXP_NFCIP_NFCID3T:
1367 if (reg_length <= NFCIP_NFCID_LENGTH)
1369 HCI_PRINT_BUFFER("\tNFCIP NFCID3T", reg_value, reg_length);
1370 p_nfcipinfo->nfcid3t_length =
1371 p_rem_nfcipinfo->NFCID_Length = reg_length;
1372 (void)memcpy((void *)p_rem_nfcipinfo->NFCID,
1374 p_rem_nfcipinfo->NFCID_Length);
1375 (void)memcpy((void *)p_nfcipinfo->nfcid3t,
1378 if ((NULL != psHciContext->p_target_info) &&
1379 (NFCIP_TARGET == p_nfcipinfo->nfcip_type))
1381 phHal_sNfcIPInfo_t *p_remtgt_info = NULL;
1382 /* This is given to user */
1384 &(psHciContext->p_target_info->RemoteDevInfo.NfcIP_Info);
1385 p_remtgt_info->NFCID_Length = reg_length;
1386 (void)memcpy((void *)p_remtgt_info->NFCID,
1388 p_remtgt_info->NFCID_Length);
1393 status = PHNFCSTVAL(CID_NFC_HCI,
1394 NFCSTATUS_INVALID_HCI_RESPONSE);
1398 case NXP_NFCIP_PARAM:
1400 if (sizeof(*reg_value) == reg_length)
1402 HCI_PRINT_BUFFER("\tNFCIP PARAMS", reg_value, reg_length);
1403 p_nfcipinfo->initiator_speed = (phHciNfc_eP2PSpeed_t)
1404 ((*reg_value >> NFCIP_COMM_INITIATOR_SHIFT)
1405 & NFCIP_COMM_FACTOR);
1406 p_nfcipinfo->target_speed = (phHciNfc_eP2PSpeed_t)
1407 (*reg_value & NFCIP_COMM_FACTOR);
1408 p_nfcipinfo->max_frame_len = NFCIP_DATA_RATE_CALC(*reg_value);
1410 if (NULL != psHciContext->p_target_info)
1412 phHal_sNfcIPInfo_t *p_remtgt_info = NULL;
1413 /* This is given to user */
1415 &(psHciContext->p_target_info->RemoteDevInfo.NfcIP_Info);
1416 p_remtgt_info->MaxFrameLength = p_nfcipinfo->max_frame_len;
1417 p_remtgt_info->Nfcip_Datarate = (phHalNfc_eDataRate_t)
1418 p_nfcipinfo->initiator_speed;
1423 status = PHNFCSTVAL(CID_NFC_HCI,
1424 NFCSTATUS_INVALID_HCI_RESPONSE);
1428 case NXP_NFCIP_MODE:
1430 if (sizeof(*reg_value) == reg_length)
1432 HCI_PRINT_BUFFER("\tNFCIP MODE", reg_value, reg_length);
1433 p_nfcipinfo->nfcip_mode = *reg_value;
1437 status = PHNFCSTVAL(CID_NFC_HCI,
1438 NFCSTATUS_INVALID_HCI_RESPONSE);
1442 case NXP_NFCIP_ATR_REQ:
1444 if (reg_length <= NFCIP_ATR_MAX_LENGTH)
1446 HCI_PRINT_BUFFER("\tNFCIP ATR_REQ", reg_value, reg_length);
1447 p_rem_nfcipinfo->ATRInfo_Length =
1448 p_nfcipinfo->atr_req_length = reg_length;
1449 (void)memcpy((void *)p_rem_nfcipinfo->ATRInfo,
1451 p_rem_nfcipinfo->ATRInfo_Length);
1452 (void)memcpy((void *)p_nfcipinfo->atr_req_info,
1454 p_nfcipinfo->atr_req_length);
1455 if (NULL != psHciContext->p_target_info)
1457 phHal_sNfcIPInfo_t *p_remtgt_info = NULL;
1458 /* This is given to user */
1460 &(psHciContext->p_target_info->RemoteDevInfo.NfcIP_Info);
1461 p_remtgt_info->NFCID_Length = reg_length;
1462 (void)memcpy((void *)p_remtgt_info->ATRInfo,
1464 p_remtgt_info->ATRInfo_Length);
1469 status = PHNFCSTVAL(CID_NFC_HCI,
1470 NFCSTATUS_INVALID_HCI_RESPONSE);
1474 case NXP_NFCIP_PSL1:
1476 if (sizeof(*reg_value) == reg_length)
1478 HCI_PRINT_BUFFER("\tNFCIP PSL1", reg_value, reg_length);
1479 p_nfcipinfo->psl1 = *reg_value;
1483 status = PHNFCSTVAL(CID_NFC_HCI,
1484 NFCSTATUS_INVALID_HCI_RESPONSE);
1488 case NXP_NFCIP_PSL2:
1490 if (sizeof(*reg_value) == reg_length)
1492 HCI_PRINT_BUFFER("\tNFCIP PSL2", reg_value, reg_length);
1493 p_nfcipinfo->psl2 = *reg_value;
1497 status = PHNFCSTVAL(CID_NFC_HCI,
1498 NFCSTATUS_INVALID_HCI_RESPONSE);
1504 if (sizeof(*reg_value) == reg_length)
1506 HCI_PRINT_BUFFER("\tNFCIP DID", reg_value, reg_length);
1507 p_nfcipinfo->did = *reg_value;
1511 status = PHNFCSTVAL(CID_NFC_HCI,
1512 NFCSTATUS_INVALID_HCI_RESPONSE);
1518 if (sizeof(*reg_value) == reg_length)
1520 HCI_PRINT_BUFFER("\tNFCIP NAD", reg_value, reg_length);
1521 p_nfcipinfo->nad = *reg_value;
1525 status = PHNFCSTVAL(CID_NFC_HCI,
1526 NFCSTATUS_INVALID_HCI_RESPONSE);
1530 case NXP_NFCIP_OPTIONS:
1532 if (sizeof(*reg_value) == reg_length)
1534 HCI_PRINT_BUFFER("\tNFCIP OPTIONS", reg_value, reg_length);
1535 p_nfcipinfo->options = *reg_value;
1539 status = PHNFCSTVAL(CID_NFC_HCI,
1540 NFCSTATUS_INVALID_HCI_RESPONSE);
1546 status = PHNFCSTVAL(CID_NFC_HCI,
1547 NFCSTATUS_INVALID_HCI_RESPONSE);
1556 phHciNfc_NfcIP_SetMode(
1557 phHciNfc_sContext_t *psHciContext,
1559 phHciNfc_eNfcIPType_t nfciptype,
1563 NFCSTATUS status = NFCSTATUS_SUCCESS;
1565 if( (NULL == psHciContext) || (NULL == pHwRef) ||
1566 (nfcip_mode > (uint8_t)NFCIP_MODE_ALL))
1568 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1570 else if (NFCIP_INVALID == nfciptype)
1572 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION);
1574 else if(NULL == psHciContext->p_nfcip_info)
1576 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
1580 phHciNfc_NfcIP_Info_t *p_nfcipinfo=NULL;
1581 phHciNfc_Pipe_Info_t *p_pipe_info=NULL;
1584 p_nfcipinfo = (phHciNfc_NfcIP_Info_t *)
1585 psHciContext->p_nfcip_info ;
1586 p_pipe_info = ((NFCIP_INITIATOR == nfciptype)?
1587 p_nfcipinfo->p_init_pipe_info:
1588 p_nfcipinfo->p_tgt_pipe_info);
1590 if(NULL == p_pipe_info )
1592 status = PHNFCSTVAL(CID_NFC_HCI,
1593 NFCSTATUS_INVALID_HCI_INFORMATION);
1597 pipeid = p_pipe_info->pipe.pipe_id ;
1598 p_pipe_info->reg_index = (uint8_t)NXP_NFCIP_MODE;
1600 p_pipe_info->param_info = &nfcip_mode;
1601 p_pipe_info->param_length = sizeof(uint8_t);
1602 status = phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef,
1603 pipeid, (uint8_t)ANY_SET_PARAMETER);
1610 phHciNfc_NfcIP_SetNAD(
1611 phHciNfc_sContext_t *psHciContext,
1613 phHciNfc_eNfcIPType_t nfciptype,
1617 NFCSTATUS status = NFCSTATUS_SUCCESS;
1619 if( (NULL == psHciContext) || (NULL == pHwRef))
1621 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1623 else if (NFCIP_INVALID == nfciptype)
1625 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION);
1627 else if(NULL == psHciContext->p_nfcip_info)
1629 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
1633 phHciNfc_NfcIP_Info_t *p_nfcipinfo=NULL;
1634 phHciNfc_Pipe_Info_t *p_pipe_info=NULL;
1637 p_nfcipinfo = (phHciNfc_NfcIP_Info_t *)
1638 psHciContext->p_nfcip_info ;
1639 p_pipe_info = ((NFCIP_INITIATOR == nfciptype)?
1640 p_nfcipinfo->p_init_pipe_info:
1641 p_nfcipinfo->p_tgt_pipe_info);
1643 if(NULL == p_pipe_info )
1645 status = PHNFCSTVAL(CID_NFC_HCI,
1646 NFCSTATUS_INVALID_HCI_INFORMATION);
1650 pipeid = p_pipe_info->pipe.pipe_id ;
1651 p_pipe_info->reg_index = (uint8_t)NXP_NFCIP_NAD;
1653 p_pipe_info->param_info = &nad;
1654 p_pipe_info->param_length = sizeof(uint8_t);
1655 status = phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef,
1656 pipeid, (uint8_t)ANY_SET_PARAMETER);
1663 phHciNfc_NfcIP_SetDID(
1664 phHciNfc_sContext_t *psHciContext,
1669 NFCSTATUS status = NFCSTATUS_SUCCESS;
1671 if( (NULL == psHciContext) || (NULL == pHwRef))
1673 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1675 else if(NULL == psHciContext->p_nfcip_info)
1677 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
1681 phHciNfc_NfcIP_Info_t *p_nfcipinfo=NULL;
1682 phHciNfc_Pipe_Info_t *p_pipe_info=NULL;
1685 p_nfcipinfo = (phHciNfc_NfcIP_Info_t *)
1686 psHciContext->p_nfcip_info ;
1687 p_pipe_info = p_nfcipinfo->p_init_pipe_info;
1689 if(NULL == p_pipe_info )
1691 status = PHNFCSTVAL(CID_NFC_HCI,
1692 NFCSTATUS_INVALID_HCI_INFORMATION);
1696 pipeid = p_pipe_info->pipe.pipe_id ;
1697 p_pipe_info->reg_index = (uint8_t)NXP_NFCIP_DID;
1699 p_pipe_info->param_info = &did;
1700 p_pipe_info->param_length = sizeof(uint8_t);
1701 status = phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef,
1702 pipeid, (uint8_t)ANY_SET_PARAMETER);
1709 phHciNfc_NfcIP_SetOptions(
1710 phHciNfc_sContext_t *psHciContext,
1712 phHciNfc_eNfcIPType_t nfciptype,
1713 uint8_t nfcip_options
1716 NFCSTATUS status = NFCSTATUS_SUCCESS;
1718 if( (NULL == psHciContext) || (NULL == pHwRef))
1720 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1722 else if (NFCIP_INVALID == nfciptype)
1724 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION);
1726 else if(NULL == psHciContext->p_nfcip_info)
1728 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
1732 phHciNfc_NfcIP_Info_t *p_nfcipinfo=NULL;
1733 phHciNfc_Pipe_Info_t *p_pipe_info=NULL;
1736 p_nfcipinfo = (phHciNfc_NfcIP_Info_t *)
1737 psHciContext->p_nfcip_info ;
1738 p_pipe_info = ((NFCIP_INITIATOR == p_nfcipinfo->nfcip_type)?
1739 p_nfcipinfo->p_init_pipe_info:
1740 p_nfcipinfo->p_tgt_pipe_info);
1741 pipeid = p_pipe_info->pipe.pipe_id ;
1742 p_pipe_info->reg_index = (uint8_t)NXP_NFCIP_OPTIONS;
1744 p_pipe_info->param_info = &nfcip_options;
1745 p_pipe_info->param_length = sizeof(uint8_t);
1746 status = phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef,
1747 pipeid, (uint8_t)ANY_SET_PARAMETER);
1753 phHciNfc_NfcIP_SetATRInfo(
1754 phHciNfc_sContext_t *psHciContext,
1756 phHciNfc_eNfcIPType_t nfciptype,
1757 phHal_sNfcIPCfg_t *atr_info
1760 NFCSTATUS status = NFCSTATUS_SUCCESS;
1762 if( (NULL == psHciContext) || (NULL == pHwRef) || (NULL == atr_info) ||
1763 (atr_info->generalBytesLength > NFCIP_ATR_MAX_LENGTH))
1765 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1767 else if (NFCIP_INVALID == nfciptype)
1769 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION);
1771 else if(NULL == psHciContext->p_nfcip_info)
1773 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
1777 phHciNfc_NfcIP_Info_t *p_nfcipinfo=NULL;
1778 phHciNfc_Pipe_Info_t *p_pipe_info=NULL;
1781 p_nfcipinfo = (phHciNfc_NfcIP_Info_t *)
1782 psHciContext->p_nfcip_info ;
1783 p_pipe_info = ((NFCIP_INITIATOR == nfciptype)?
1784 p_nfcipinfo->p_init_pipe_info:
1785 p_nfcipinfo->p_tgt_pipe_info);
1787 if(NULL == p_pipe_info )
1789 status = PHNFCSTVAL(CID_NFC_HCI,
1790 NFCSTATUS_INVALID_HCI_INFORMATION);
1794 pipeid = p_pipe_info->pipe.pipe_id ;
1795 p_pipe_info->reg_index = (uint8_t)((NFCIP_INITIATOR == nfciptype)?
1799 p_pipe_info->param_info = atr_info->generalBytes;
1800 p_pipe_info->param_length = (uint8_t)
1801 atr_info->generalBytesLength;
1802 status = phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef,
1803 pipeid, (uint8_t)ANY_SET_PARAMETER);
1810 phHciNfc_NfcIP_SetPSL1(
1811 phHciNfc_sContext_t *psHciContext,
1816 NFCSTATUS status = NFCSTATUS_SUCCESS;
1818 if( (NULL == psHciContext) || (NULL == pHwRef))
1820 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1822 else if(NULL == psHciContext->p_nfcip_info)
1824 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
1828 phHciNfc_NfcIP_Info_t *p_nfcipinfo=NULL;
1829 phHciNfc_Pipe_Info_t *p_pipe_info=NULL;
1832 p_nfcipinfo = (phHciNfc_NfcIP_Info_t *)
1833 psHciContext->p_nfcip_info ;
1834 p_pipe_info = p_nfcipinfo->p_init_pipe_info;
1836 if(NULL == p_pipe_info )
1838 status = PHNFCSTVAL(CID_NFC_HCI,
1839 NFCSTATUS_INVALID_HCI_INFORMATION);
1843 pipeid = p_pipe_info->pipe.pipe_id ;
1844 p_pipe_info->reg_index = (uint8_t)NXP_NFCIP_PSL1;
1846 p_pipe_info->param_info = &psl1;
1847 p_pipe_info->param_length = sizeof(uint8_t);
1848 status = phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef,
1849 pipeid, (uint8_t)ANY_SET_PARAMETER);
1856 phHciNfc_NfcIP_SetPSL2(
1857 phHciNfc_sContext_t *psHciContext,
1862 NFCSTATUS status = NFCSTATUS_SUCCESS;
1864 if( (NULL == psHciContext) || (NULL == pHwRef))
1866 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1868 else if(NULL == psHciContext->p_nfcip_info)
1870 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
1874 phHciNfc_NfcIP_Info_t *p_nfcipinfo=NULL;
1875 phHciNfc_Pipe_Info_t *p_pipe_info=NULL;
1878 p_nfcipinfo = (phHciNfc_NfcIP_Info_t *)
1879 psHciContext->p_nfcip_info ;
1880 p_pipe_info = p_nfcipinfo->p_init_pipe_info;
1882 if(NULL == p_pipe_info )
1884 status = PHNFCSTVAL(CID_NFC_HCI,
1885 NFCSTATUS_INVALID_HCI_INFORMATION);
1889 pipeid = p_pipe_info->pipe.pipe_id ;
1890 p_pipe_info->reg_index = (uint8_t)NXP_NFCIP_PSL2;
1892 p_pipe_info->param_info = &psl2;
1893 p_pipe_info->param_length = sizeof(uint8_t);
1894 status = phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef,
1895 pipeid, (uint8_t)ANY_SET_PARAMETER);
1902 phHciNfc_NfcIP_GetStatus(
1903 phHciNfc_sContext_t *psHciContext,
1905 phHciNfc_eNfcIPType_t nfciptype
1908 NFCSTATUS status = NFCSTATUS_SUCCESS;
1910 if( (NULL == psHciContext) || (NULL == pHwRef))
1912 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1914 else if (NFCIP_INVALID == nfciptype)
1916 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION);
1918 else if(NULL == psHciContext->p_nfcip_info)
1920 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
1924 phHciNfc_NfcIP_Info_t *p_nfcipinfo=NULL;
1925 phHciNfc_Pipe_Info_t *p_pipe_info=NULL;
1928 p_nfcipinfo = (phHciNfc_NfcIP_Info_t *)
1929 psHciContext->p_nfcip_info ;
1930 p_pipe_info = ((NFCIP_INITIATOR == nfciptype)?
1931 p_nfcipinfo->p_init_pipe_info :
1932 p_nfcipinfo->p_tgt_pipe_info);
1933 if(NULL == p_pipe_info )
1935 status = PHNFCSTVAL(CID_NFC_HCI,
1936 NFCSTATUS_INVALID_HCI_INFORMATION);
1940 pipeid = p_pipe_info->pipe.pipe_id ;
1941 p_pipe_info->reg_index = (uint8_t)NXP_NFCIP_STATUS;
1943 status = phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef,
1944 pipeid, (uint8_t)ANY_GET_PARAMETER);
1951 phHciNfc_NfcIP_GetParam(
1952 phHciNfc_sContext_t *psHciContext,
1954 phHciNfc_eNfcIPType_t nfciptype
1957 NFCSTATUS status = NFCSTATUS_SUCCESS;
1959 if( (NULL == psHciContext) || (NULL == pHwRef))
1961 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1963 else if (NFCIP_INVALID == nfciptype)
1965 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION);
1967 else if(NULL == psHciContext->p_nfcip_info)
1969 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
1973 phHciNfc_NfcIP_Info_t *p_nfcipinfo=NULL;
1974 phHciNfc_Pipe_Info_t *p_pipe_info=NULL;
1977 p_nfcipinfo = (phHciNfc_NfcIP_Info_t *)
1978 psHciContext->p_nfcip_info ;
1979 p_pipe_info = ((NFCIP_INITIATOR == nfciptype)?
1980 p_nfcipinfo->p_init_pipe_info :
1981 p_nfcipinfo->p_tgt_pipe_info);
1982 if(NULL == p_pipe_info )
1984 status = PHNFCSTVAL(CID_NFC_HCI,
1985 NFCSTATUS_INVALID_HCI_INFORMATION);
1989 pipeid = p_pipe_info->pipe.pipe_id ;
1990 p_pipe_info->reg_index = (uint8_t)NXP_NFCIP_PARAM;
1992 status = phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef,
1993 pipeid, (uint8_t)ANY_GET_PARAMETER);
2000 phHciNfc_Initiator_Cont_Activate (
2001 phHciNfc_sContext_t *psHciContext,
2005 NFCSTATUS status = NFCSTATUS_SUCCESS;
2007 if( (NULL == psHciContext) || (NULL == pHwRef) )
2009 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
2011 else if(NULL == psHciContext->p_nfcip_info)
2013 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
2017 phHciNfc_NfcIP_Info_t *p_nfcipinfo = NULL;
2018 phHciNfc_Pipe_Info_t *p_pipe_info=NULL;
2020 p_nfcipinfo = (phHciNfc_NfcIP_Info_t *)
2021 psHciContext->p_nfcip_info ;
2022 p_nfcipinfo->nfcip_type = NFCIP_INITIATOR;
2023 psHciContext->host_rf_type = phHal_eNfcIP1_Initiator;
2024 p_pipe_info = p_nfcipinfo->p_init_pipe_info;
2025 if(NULL == p_pipe_info )
2027 status = PHNFCSTVAL(CID_NFC_HCI,
2028 NFCSTATUS_INVALID_HCI_INFORMATION);
2032 phHciNfc_HCP_Packet_t *hcp_packet = NULL;
2033 uint16_t length = HCP_HEADER_LEN;
2036 pipeid = p_pipe_info->pipe.pipe_id;
2037 psHciContext->tx_total = 0 ;
2038 hcp_packet = (phHciNfc_HCP_Packet_t *) psHciContext->send_buffer;
2039 /* Construct the HCP Frame */
2040 phHciNfc_Build_HCPFrame(hcp_packet,(uint8_t)HCP_CHAINBIT_DEFAULT,
2041 (uint8_t) pipeid, (uint8_t)HCP_MSG_TYPE_COMMAND,
2042 (uint8_t)NXP_NFCI_CONTINUE_ACTIVATION);
2044 p_pipe_info->sent_msg_type = (uint8_t)HCP_MSG_TYPE_COMMAND;
2045 p_pipe_info->prev_msg = (uint8_t)NXP_NFCI_CONTINUE_ACTIVATION;
2046 psHciContext->tx_total = length;
2047 psHciContext->response_pending = (uint8_t)TRUE;
2049 /* Send the Constructed HCP packet to the lower layer */
2050 status = phHciNfc_Send_HCP( psHciContext, pHwRef);
2051 p_pipe_info->prev_status = status;
2059 phHciNfc_NfcIP_GetATRInfo (
2060 phHciNfc_sContext_t *psHciContext,
2062 phHciNfc_eNfcIPType_t nfciptype
2065 NFCSTATUS status = NFCSTATUS_SUCCESS;
2067 if( (NULL == psHciContext)
2068 || (NULL == pHwRef))
2070 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
2072 else if (NFCIP_INVALID == nfciptype)
2074 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION);
2076 else if(NULL == psHciContext->p_nfcip_info)
2078 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
2082 phHciNfc_NfcIP_Info_t *p_nfcipinfo=NULL;
2083 phHciNfc_Pipe_Info_t *p_pipe_info=NULL;
2086 p_nfcipinfo = (phHciNfc_NfcIP_Info_t *)
2087 psHciContext->p_nfcip_info ;
2089 p_pipe_info = ((NFCIP_INITIATOR == nfciptype)?
2090 p_nfcipinfo->p_init_pipe_info :
2091 p_nfcipinfo->p_tgt_pipe_info);
2093 if(NULL == p_pipe_info )
2095 status = PHNFCSTVAL(CID_NFC_HCI,
2096 NFCSTATUS_INVALID_HCI_INFORMATION);
2100 p_pipe_info->reg_index = (uint8_t)((NFCIP_INITIATOR == nfciptype)?
2103 pipeid = p_pipe_info->pipe.pipe_id ;
2104 /* Fill the data buffer and send the command to the
2107 phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef,
2108 pipeid, (uint8_t)ANY_GET_PARAMETER);
2115 phHciNfc_NfcIP_SetMergeSak(
2116 phHciNfc_sContext_t *psHciContext,
2121 NFCSTATUS status = NFCSTATUS_SUCCESS;
2123 if( (NULL == psHciContext) || (NULL == pHwRef) ||
2124 (sak_value > (uint8_t)TRUE))
2126 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
2128 else if(NULL == psHciContext->p_nfcip_info)
2130 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
2134 phHciNfc_NfcIP_Info_t *ps_nfcipinfo=NULL;
2135 phHciNfc_Pipe_Info_t *ps_pipe_info=NULL;
2138 ps_nfcipinfo = (phHciNfc_NfcIP_Info_t *)
2139 psHciContext->p_nfcip_info ;
2140 ps_pipe_info = ps_nfcipinfo->p_tgt_pipe_info;
2142 if(NULL == ps_pipe_info )
2144 status = PHNFCSTVAL(CID_NFC_HCI,
2145 NFCSTATUS_INVALID_HCI_INFORMATION);
2149 pipeid = ps_pipe_info->pipe.pipe_id ;
2150 ps_pipe_info->reg_index = (uint8_t)NXP_NFCIP_MERGE;
2152 ps_pipe_info->param_info = &sak_value;
2153 ps_pipe_info->param_length = sizeof(uint8_t);
2154 status = phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef,
2155 pipeid, (uint8_t)ANY_SET_PARAMETER);
2161 #endif /* #if defined (ENABLE_P2P) */