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 #define NCI_VERSION_2_0 0x20 29 #define NCI_VERSION_1_1 0x11 30 #define NCI_VERSION_1_0 0x10 31 #define NCI_VERSION_UNKNOWN 0x00 32 typedef void(phNxpNciHal_control_granted_callback_t)(); 33 34 /*ROM CODE VERSION FW*/ 35 #define FW_MOBILE_ROM_VERSION_PN551 0x10 36 #define FW_MOBILE_ROM_VERSION_PN553 0x11 37 #define FW_MOBILE_ROM_VERSION_PN548AD 0x10 38 #define FW_MOBILE_ROM_VERSION_PN547C2 0x08 39 /* NCI Data */ 40 41 #define NCI_MT_CMD 0x20 42 #define NCI_MT_RSP 0x40 43 #define NCI_MT_NTF 0x60 44 45 #define CORE_RESET_TRIGGER_TYPE_CORE_RESET_CMD_RECEIVED 0x02 46 #define CORE_RESET_TRIGGER_TYPE_POWERED_ON 0x01 47 #define NCI_MSG_CORE_RESET 0x00 48 #define NCI_MSG_CORE_INIT 0x01 49 #define NCI_MT_MASK 0xE0 50 #define NCI_OID_MASK 0x3F 51 typedef struct nci_data { 52 uint16_t len; 53 uint8_t p_data[NCI_MAX_DATA_LEN]; 54 } nci_data_t; 55 56 typedef enum { HAL_STATUS_CLOSE = 0, HAL_STATUS_OPEN } phNxpNci_HalStatus; 57 58 /* Macros to enable and disable extensions */ 59 #define HAL_ENABLE_EXT() (nxpncihal_ctrl.hal_ext_enabled = 1) 60 #define HAL_DISABLE_EXT() (nxpncihal_ctrl.hal_ext_enabled = 0) 61 typedef struct phNxpNciInfo { 62 uint8_t nci_version; 63 bool_t wait_for_ntf; 64 } phNxpNciInfo_t; 65 /* NCI Control structure */ 66 typedef struct phNxpNciHal_Control { 67 phNxpNci_HalStatus halStatus; /* Indicate if hal is open or closed */ 68 pthread_t client_thread; /* Integration thread handle */ 69 uint8_t thread_running; /* Thread running if set to 1, else set to 0 */ 70 phLibNfc_sConfig_t gDrvCfg; /* Driver config data */ 71 72 /* Rx data */ 73 uint8_t* p_rx_data; 74 uint16_t rx_data_len; 75 76 /* libnfc-nci callbacks */ 77 nfc_stack_callback_t* p_nfc_stack_cback; 78 nfc_stack_data_callback_t* p_nfc_stack_data_cback; 79 80 /* control granted callback */ 81 phNxpNciHal_control_granted_callback_t* p_control_granted_cback; 82 83 /* HAL open status */ 84 bool_t hal_open_status; 85 86 /* HAL extensions */ 87 uint8_t hal_ext_enabled; 88 89 /* Waiting semaphore */ 90 phNxpNciHal_Sem_t ext_cb_data; 91 92 uint16_t cmd_len; 93 uint8_t p_cmd_data[NCI_MAX_DATA_LEN]; 94 uint16_t rsp_len; 95 uint8_t p_rsp_data[NCI_MAX_DATA_LEN]; 96 97 /* retry count used to force download */ 98 uint16_t retry_cnt; 99 uint8_t read_retry_cnt; 100 phNxpNciInfo_t nci_info; 101 } phNxpNciHal_Control_t; 102 103 typedef struct phNxpNciClock { 104 bool_t isClockSet; 105 uint8_t p_rx_data[20]; 106 bool_t issetConfig; 107 } phNxpNciClock_t; 108 109 typedef struct phNxpNciRfSetting { 110 bool_t isGetRfSetting; 111 uint8_t p_rx_data[20]; 112 } phNxpNciRfSetting_t; 113 114 typedef struct phNxpNciMwEepromArea { 115 bool_t isGetEepromArea; 116 uint8_t p_rx_data[32]; 117 } phNxpNciMwEepromArea_t; 118 119 typedef enum { 120 NFC_FORUM_PROFILE, 121 EMV_CO_PROFILE, 122 INVALID_PROFILe 123 } phNxpNciProfile_t; 124 /* NXP Poll Profile control structure */ 125 typedef struct phNxpNciProfile_Control { 126 phNxpNciProfile_t profile_type; 127 uint8_t bClkSrcVal; /* Holds the System clock source read from config file */ 128 uint8_t 129 bClkFreqVal; /* Holds the System clock frequency read from config file */ 130 uint8_t bTimeout; /* Holds the Timeout Value */ 131 } phNxpNciProfile_Control_t; 132 133 /* Internal messages to handle callbacks */ 134 #define NCI_HAL_OPEN_CPLT_MSG 0x411 135 #define NCI_HAL_CLOSE_CPLT_MSG 0x412 136 #define NCI_HAL_POST_INIT_CPLT_MSG 0x413 137 #define NCI_HAL_PRE_DISCOVER_CPLT_MSG 0x414 138 #define NCI_HAL_ERROR_MSG 0x415 139 #define NCI_HAL_RX_MSG 0xF01 140 141 #define NCIHAL_CMD_CODE_LEN_BYTE_OFFSET (2U) 142 #define NCIHAL_CMD_CODE_BYTE_LEN (3U) 143 144 /******************** NCI HAL exposed functions *******************************/ 145 146 void phNxpNciHal_request_control(void); 147 void phNxpNciHal_release_control(void); 148 int phNxpNciHal_write_unlocked(uint16_t data_len, const uint8_t* p_data); 149 #if (NFC_NXP_CHIP_TYPE == PN548C2) 150 NFCSTATUS phNxpNciHal_core_reset_recovery(); 151 void phNxpNciHal_discovery_cmd_ext(uint8_t* p_cmd_data, uint16_t cmd_len); 152 #endif 153 #endif /* _PHNXPNCIHAL_H_ */ 154