1/* 2 * Copyright (C) 2010-2014 NXP Semiconductors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16#ifndef _PHNXPNCIHAL_H_ 17#define _PHNXPNCIHAL_H_ 18 19#include <hardware/nfc.h> 20#include <phNxpNciHal_utils.h> 21 22/********************* Definitions and structures *****************************/ 23#define MAX_RETRY_COUNT 5 24#define NCI_MAX_DATA_LEN 300 25#define NCI_POLL_DURATION 500 26#define HAL_NFC_ENABLE_I2C_FRAGMENTATION_EVT 0x07 27#undef P2P_PRIO_LOGIC_HAL_IMP 28 29typedef void (phNxpNciHal_control_granted_callback_t)(); 30 31/* NCI Data */ 32typedef struct nci_data 33{ 34 uint16_t len; 35 uint8_t p_data[NCI_MAX_DATA_LEN]; 36} nci_data_t; 37 38typedef enum 39{ 40 HAL_STATUS_OPEN = 0, 41 HAL_STATUS_CLOSE 42} phNxpNci_HalStatus; 43 44/* Macros to enable and disable extensions */ 45#define HAL_ENABLE_EXT() (nxpncihal_ctrl.hal_ext_enabled = 1) 46#define HAL_DISABLE_EXT() (nxpncihal_ctrl.hal_ext_enabled = 0) 47 48/* NCI Control structure */ 49typedef struct phNxpNciHal_Control 50{ 51 phNxpNci_HalStatus halStatus; /* Indicate if hal is open or closed */ 52 pthread_t client_thread; /* Integration thread handle */ 53 uint8_t thread_running; /* Thread running if set to 1, else set to 0 */ 54 phLibNfc_sConfig_t gDrvCfg; /* Driver config data */ 55 56 /* Rx data */ 57 uint8_t *p_rx_data; 58 uint16_t rx_data_len; 59 60 /* libnfc-nci callbacks */ 61 nfc_stack_callback_t *p_nfc_stack_cback; 62 nfc_stack_data_callback_t *p_nfc_stack_data_cback; 63 64 /* control granted callback */ 65 phNxpNciHal_control_granted_callback_t *p_control_granted_cback; 66 67 /* HAL open status */ 68 bool_t hal_open_status; 69 70 /* HAL extensions */ 71 uint8_t hal_ext_enabled; 72 73 /* Waiting semaphore */ 74 phNxpNciHal_Sem_t ext_cb_data; 75 76 uint16_t cmd_len; 77 uint8_t p_cmd_data[NCI_MAX_DATA_LEN]; 78 uint16_t rsp_len; 79 uint8_t p_rsp_data[NCI_MAX_DATA_LEN]; 80 81 /* retry count used to force download */ 82 uint16_t retry_cnt; 83 uint8_t read_retry_cnt; 84} phNxpNciHal_Control_t; 85 86typedef struct phNxpNciClock{ 87 bool_t isClockSet; 88 uint8_t p_rx_data[20]; 89 bool_t issetConfig; 90}phNxpNciClock_t; 91 92typedef struct phNxpNciRfSetting{ 93 bool_t isGetRfSetting; 94 uint8_t p_rx_data[20]; 95}phNxpNciRfSetting_t; 96 97typedef struct phNxpNciMwEepromArea { 98 bool_t isGetEepromArea; 99 uint8_t p_rx_data[32]; 100} phNxpNciMwEepromArea_t; 101 102typedef enum { 103 NFC_FORUM_PROFILE, 104 EMV_CO_PROFILE, 105 INVALID_PROFILe 106}phNxpNciProfile_t; 107/* NXP Poll Profile control structure */ 108typedef struct phNxpNciProfile_Control 109{ 110 phNxpNciProfile_t profile_type; 111 uint8_t bClkSrcVal; /* Holds the System clock source read from config file */ 112 uint8_t bClkFreqVal; /* Holds the System clock frequency read from config file */ 113 uint8_t bTimeout; /* Holds the Timeout Value */ 114} phNxpNciProfile_Control_t; 115 116/* Internal messages to handle callbacks */ 117#define NCI_HAL_OPEN_CPLT_MSG 0x411 118#define NCI_HAL_CLOSE_CPLT_MSG 0x412 119#define NCI_HAL_POST_INIT_CPLT_MSG 0x413 120#define NCI_HAL_PRE_DISCOVER_CPLT_MSG 0x414 121#define NCI_HAL_ERROR_MSG 0x415 122#define NCI_HAL_RX_MSG 0xF01 123 124#define NCIHAL_CMD_CODE_LEN_BYTE_OFFSET (2U) 125#define NCIHAL_CMD_CODE_BYTE_LEN (3U) 126 127/******************** NCI HAL exposed functions *******************************/ 128 129void phNxpNciHal_request_control (void); 130void phNxpNciHal_release_control (void); 131int phNxpNciHal_write_unlocked (uint16_t data_len, const uint8_t *p_data); 132#if(NFC_NXP_CHIP_TYPE == PN548C2) 133NFCSTATUS phNxpNciHal_core_reset_recovery (); 134void phNxpNciHal_discovery_cmd_ext (uint8_t *p_cmd_data, uint16_t cmd_len); 135#endif 136#endif /* _PHNXPNCIHAL_H_ */ 137