Home | History | Annotate | Download | only in hal
      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 
     29 typedef void (phNxpNciHal_control_granted_callback_t)();
     30 
     31 /* NCI Data */
     32 typedef struct nci_data
     33 {
     34     uint16_t len;
     35     uint8_t p_data[NCI_MAX_DATA_LEN];
     36 } nci_data_t;
     37 
     38 typedef 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 */
     49 typedef 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 
     86 typedef struct phNxpNciClock{
     87     bool_t  isClockSet;
     88     uint8_t  p_rx_data[20];
     89     bool_t  issetConfig;
     90 }phNxpNciClock_t;
     91 
     92 typedef struct phNxpNciRfSetting{
     93     bool_t  isGetRfSetting;
     94     uint8_t  p_rx_data[20];
     95 }phNxpNciRfSetting_t;
     96 
     97 
     98 typedef enum {
     99     NFC_FORUM_PROFILE,
    100     EMV_CO_PROFILE,
    101     INVALID_PROFILe
    102 }phNxpNciProfile_t;
    103 /* NXP Poll Profile control structure */
    104 typedef struct phNxpNciProfile_Control
    105 {
    106     phNxpNciProfile_t profile_type;
    107     uint8_t                      bClkSrcVal;     /* Holds the System clock source read from config file */
    108     uint8_t                      bClkFreqVal;    /* Holds the System clock frequency read from config file */
    109     uint8_t                      bTimeout;       /* Holds the Timeout Value */
    110 } phNxpNciProfile_Control_t;
    111 
    112 /* Internal messages to handle callbacks */
    113 #define NCI_HAL_OPEN_CPLT_MSG             0x411
    114 #define NCI_HAL_CLOSE_CPLT_MSG            0x412
    115 #define NCI_HAL_POST_INIT_CPLT_MSG        0x413
    116 #define NCI_HAL_PRE_DISCOVER_CPLT_MSG     0x414
    117 #define NCI_HAL_ERROR_MSG                 0x415
    118 #define NCI_HAL_RX_MSG                    0xF01
    119 
    120 #define NCIHAL_CMD_CODE_LEN_BYTE_OFFSET         (2U)
    121 #define NCIHAL_CMD_CODE_BYTE_LEN                (3U)
    122 
    123 /******************** NCI HAL exposed functions *******************************/
    124 
    125 void phNxpNciHal_request_control (void);
    126 void phNxpNciHal_release_control (void);
    127 int phNxpNciHal_write_unlocked (uint16_t data_len, const uint8_t *p_data);
    128 
    129 #endif /* _PHNXPNCIHAL_H_ */
    130