Home | History | Annotate | Download | only in src
      1 /*
      2  * Copyright (C) 2010 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 
     17 
     18 /**
     19 * \file phHal4Nfc_Internal.h
     20 * \brief HAL callback Function Prototypes
     21 *
     22 *  The HAL4.0 Internal header file
     23 *
     24 * Project: NFC-FRI-1.1 / HAL4.0
     25 *
     26 * $Date: Mon May 31 11:43:42 2010 $
     27 * $Author: ing07385 $
     28 * $Revision: 1.40 $
     29 * $Aliases: NFC_FRI1.1_WK1023_R35_1 $
     30 *
     31 */
     32 
     33 /*@{*/
     34 #ifndef PHHAL4NFC_INTERNAL_H
     35 #define PHHAL4NFC_INTERNAL_H
     36 /*@}*/
     37 
     38 #include <phHciNfc.h>
     39 
     40 /**
     41 *  \name HAL4
     42 *
     43 * File: \ref phHal4Nfc_Internal.h
     44 *
     45 */
     46 
     47 /*@{*/
     48 #define PH_HAL4NFC_INTERNAL_FILEREVISION "$Revision: 1.40 $" /**< \ingroup grp_file_attributes */
     49 #define PH_HAL4NFC_INTERNAL_FILEALIASES  "$Aliases: NFC_FRI1.1_WK1023_R35_1 $"     /**< \ingroup grp_file_attributes */
     50 /*@}*/
     51 
     52 /* -----------------Include files ---------------------------------------*/
     53 
     54 /* ---------------- Macros ----------------------------------------------*/
     55 #define LLCP_DISCON_CHANGES
     56 #define PH_HAL4NFC_TRANSCEIVE_TIMEOUT        30000  /**<Transceive operation
     57                                                         on any target should be
     58                                                         completed within this
     59                                                         interval.Else the
     60                                                         operation is timed out*/
     61 
     62 #define   PH_HAL4NFC_TGT_MERGE_ADDRESS          0x988BU
     63 #define   PH_HAL4NFC_TGT_MERGE_SAK                0x00U
     64 
     65 
     66 /*---------------- Hal4 Internal Data Structures -------------------------*/
     67 /**HAL4 states*/
     68 typedef enum{
     69     eHal4StateClosed = 0x00,  /**<closed state*/
     70     eHal4StateSelfTestMode, /**<Self test mode*/
     71     eHal4StateOpenAndReady ,/**<Fully initialised*/
     72     eHal4StateConfiguring ,  /**<configuration ongoing,transient state*/
     73     eHal4StateTargetDiscovered,/**<target discovered*/
     74     eHal4StateTargetActivate,/**<state during a select or reactivate*/
     75     eHal4StateEmulation,/**<Emulation state*/
     76     eHal4StateTargetConnected,/**<Connected state*/
     77     eHal4StateTransaction,/**<configuration ongoing,transient state*/
     78     eHal4StatePresenceCheck,/**<Presence Check state*/
     79     eHal4StateInvalid
     80 } phHal4Nfc_Hal4state_t;
     81 
     82 
     83 /**Global Pointer to hardware reference used in timer callbacks to get the
     84    context pointer*/
     85 extern phHal_sHwReference_t *gpphHal4Nfc_Hwref;
     86 
     87 /**Context info for HAL4 transceive*/
     88 typedef struct phHal4Nfc_TrcvCtxtInfo{
     89     /*Upper layer's Transceive callback*/
     90     pphHal4Nfc_TransceiveCallback_t  pUpperTranceiveCb;
     91      /*Upper layer's Send callback*/
     92     pphHal4Nfc_SendCallback_t        pP2PSendCb;
     93      /*Upper layer's receive callback*/
     94     pphHal4Nfc_ReceiveCallback_t     pP2PRecvCb;
     95     /**Flag to check if a P2P Send is ongoing when target release is issued by
     96        the upper layer.If this flag is set ,then a remote device disconnect call
     97        will be deferred*/
     98     uint8_t                          P2P_Send_In_Progress;
     99     /*Data structure to provide transceive info to Hci*/
    100     phHciNfc_XchgInfo_t              XchangeInfo;
    101     /*sData pointer to point to upper layer's send data*/
    102     phNfc_sData_t                   *psUpperSendData;
    103     /*Maintains the offset of number of bytes sent in one go ,so that the
    104       remaining bytes can be sent during the next transceive*/
    105     uint32_t                         NumberOfBytesSent;
    106     /*Number of bytes received during a P2p receive*/
    107     uint32_t                         P2PRecvLength;
    108     /*sData pointer to point to upper layer's recv data*/
    109     phNfc_sData_t                   *psUpperRecvData;
    110     /*structure to hold data received from lower layer*/
    111     phNfc_sData_t                    sLowerRecvData;
    112     /*Offset for Lower Recv Data buffer*/
    113     uint32_t                         LowerRecvBufferOffset;
    114     /*Holds the status of the RecvDataBuffer:
    115     NFCSTATUS_SUCCESS:Receive data buffer is complete with data & P2P receive has
    116                       not yet been called
    117     NFCSTATUS_PENDING:RecvDataBuffer is yet to receive the data from lower layer
    118     */
    119     NFCSTATUS                        RecvDataBufferStatus;
    120     /*Transaction timer ,currently used only for P2P receive on target*/
    121     uint32_t                         TransactionTimerId;
    122 }phHal4Nfc_TrcvCtxtInfo_t,*pphHal4Nfc_TrcvCtxtInfo_t;
    123 
    124 
    125 /**Context info for HAL4 Device discovery feature*/
    126 typedef struct phHal4Nfc_ADDCtxtInfo{
    127     /*total number of devices discovered*/
    128     uint8_t                          nbr_of_devices;
    129     /*smx_discovery*/
    130     uint8_t                          smx_discovery;
    131     /*Most recently used ADD configuration*/
    132     phHal_sADD_Cfg_t                 sADDCfg;
    133     /*Most recently used Poll configuration*/
    134     phHal_sPollDevInfo_t             sCurrentPollConfig;
    135     /*Set when Poll Configured and reset when polling is disabled.*/
    136     uint8_t                          IsPollConfigured;
    137 }phHal4Nfc_ADDCtxtInfo_t,*pphHal4Nfc_ADDCtxtInfo_t;
    138 
    139 /**Context info for HAL4 connect/disconnect*/
    140 typedef struct phHal4Nfc_TargetConnectInfo{
    141     /*connect callback*/
    142     pphHal4Nfc_ConnectCallback_t     pUpperConnectCb;
    143     /*Disconnect callback*/
    144     pphHal4Nfc_DiscntCallback_t      pUpperDisconnectCb;
    145     /*used when a release call is pending in HAL*/
    146     phHal_eReleaseType_t             ReleaseType;
    147     /*Points to Remote device info of a connected device*/
    148     phHal_sRemoteDevInformation_t   *psConnectedDevice;
    149     /*Emulation state Activated/Deactivated*/
    150     phHal_Event_t                    EmulationState;
    151     /*Presence check callback*/
    152     pphHal4Nfc_GenCallback_t         pPresenceChkCb;
    153 }phHal4Nfc_TargetConnectInfo_t,*pphHal4Nfc_TargetConnectInfo_t;
    154 
    155 /**Context info for HAL4 connect & disconnect*/
    156 typedef struct phHal4Nfc_UpperLayerInfo{
    157     /*Upper layer Context for discovery call*/
    158     void                            *DiscoveryCtxt;
    159     /*Upper layer Context for P2P discovery call*/
    160     void                            *P2PDiscoveryCtxt;
    161     /**Context and function pointer for default event handler registered
    162       by upper layer during initialization*/
    163     void                            *DefaultListenerCtxt;
    164     /*Default event handler*/
    165     pphHal4Nfc_Notification_t        pDefaultEventHandler;
    166     /**Upper layer has to register this listener for receiving info about
    167         discovered tags*/
    168     pphHal4Nfc_Notification_t        pTagDiscoveryNotification;
    169     /**Upper layer has to register this  listener for receiving info about
    170         discovered P2P devices*/
    171     pphHal4Nfc_Notification_t        pP2PNotification;
    172     /*Event Notification Context*/
    173     void                            *EventNotificationCtxt;
    174     /**Notification handler for emulation and other events*/
    175     pphHal4Nfc_Notification_t        pEventNotification;
    176     /**Upper layer's Config discovery/Emulation callback registry*/
    177     pphHal4Nfc_GenCallback_t         pConfigCallback;
    178     void                            *psUpperLayerCtxt;
    179     void                            *psUpperLayerDisconnectCtxt;
    180 #ifdef LLCP_DISCON_CHANGES
    181     void                            *psUpperLayerCfgDiscCtxt;
    182 #endif /* #ifdef LLCP_DISCON_CHANGES */
    183      /**Upper layer's Open Callback registry*/
    184     pphHal4Nfc_GenCallback_t         pUpperOpenCb;
    185     /**Upper layer's Close Callback registry */
    186     pphHal4Nfc_GenCallback_t         pUpperCloseCb;
    187     /*Ioctl out param pointer ,points to buffer provided by upper layer during
    188       a ioctl call*/
    189     phNfc_sData_t                   *pIoctlOutParam;
    190     /*Ioctl callback*/
    191     pphHal4Nfc_IoctlCallback_t       pUpperIoctlCb;
    192 }phHal4Nfc_UpperLayerInfo_t;
    193 
    194 /**Context structure for HAL4.0*/
    195 typedef struct phHal4Nfc_Hal4Ctxt{
    196     /**Hci handle obtained in Hci_Init*/
    197     void                            *psHciHandle;
    198     /**Layer configuration*/
    199     pphNfcLayer_sCfg_t               pHal4Nfc_LayerCfg;
    200     /**Device capabilities*/
    201     phHal_sDeviceCapabilities_t      Hal4Nfc_DevCaps;
    202     /*Current state of HAL4.Updated generally in callbacks*/
    203     phHal4Nfc_Hal4state_t            Hal4CurrentState;
    204     /*Next state of HAL.Updated during calls*/
    205     phHal4Nfc_Hal4state_t            Hal4NextState;
    206     /**Info related to upper layer*/
    207     phHal4Nfc_UpperLayerInfo_t       sUpperLayerInfo;
    208      /*ADD context info*/
    209     pphHal4Nfc_ADDCtxtInfo_t         psADDCtxtInfo;
    210     /*union for different configurations ,used in a config_parameters()call*/
    211     phHal_uConfig_t                  uConfig;
    212      /*Event info*/
    213     phHal_sEventInfo_t              *psEventInfo;
    214     /*Select sector flag*/
    215     uint8_t                          SelectSectorFlag;
    216     /**List of pointers to remote device information for all discovered
    217        targets*/
    218     phHal_sRemoteDevInformation_t   *rem_dev_list[MAX_REMOTE_DEVICES];
    219     /*Transceive context info*/
    220     pphHal4Nfc_TrcvCtxtInfo_t        psTrcvCtxtInfo;
    221     /*Connect context info*/
    222     phHal4Nfc_TargetConnectInfo_t    sTgtConnectInfo;
    223     /*Last called Ioctl_type*/
    224     uint32_t                         Ioctl_Type;
    225 #ifdef IGNORE_EVT_PROTECTED
    226     /*used to ignore multiple Protected events*/
    227     uint8_t                          Ignore_Event_Protected;
    228 #endif/*#ifdef IGNORE_EVT_PROTECTED*/
    229 }phHal4Nfc_Hal4Ctxt_t;
    230 
    231 
    232 /*---------------- Function Prototypes ----------------------------------------------*/
    233 
    234 /*Callback completion routine for Connect*/
    235 extern void phHal4Nfc_ConnectComplete(
    236                                       phHal4Nfc_Hal4Ctxt_t  *Hal4Ctxt,
    237                                       void *pInfo
    238                                       );
    239 
    240 /*Callback completion routine for Disconnect*/
    241 extern void phHal4Nfc_DisconnectComplete(
    242                             phHal4Nfc_Hal4Ctxt_t  *Hal4Ctxt,
    243                             void *pInfo
    244                             );
    245 
    246 /*Callback completion routine for Transceive*/
    247 extern void phHal4Nfc_TransceiveComplete(
    248                         phHal4Nfc_Hal4Ctxt_t  *Hal4Ctxt,
    249                         void *pInfo
    250                         );
    251 
    252 /*Callback completion routine for Presence check*/
    253 extern void phHal4Nfc_PresenceChkComplete(
    254                         phHal4Nfc_Hal4Ctxt_t  *Hal4Ctxt,
    255                         void *pInfo
    256                         );
    257 
    258 /*Configuration completion routine*/
    259 extern void phHal4Nfc_ConfigureComplete(
    260                                         phHal4Nfc_Hal4Ctxt_t  *Hal4Ctxt,
    261                                         void *pInfo,
    262                                         uint8_t type
    263                                         );
    264 
    265 
    266 /*Callback completion routine for ADD*/
    267 extern void phHal4Nfc_TargetDiscoveryComplete(
    268                             phHal4Nfc_Hal4Ctxt_t  *Hal4Ctxt,
    269                             void *pInfo
    270                             );
    271 
    272 /*Event handler routine for Emulation*/
    273 extern void phHal4Nfc_HandleEmulationEvent(
    274                         phHal4Nfc_Hal4Ctxt_t  *Hal4Ctxt,
    275                         void *pInfo
    276                         );
    277 
    278 /*Callback completion routine for NFCIP1 Receive*/
    279 extern void phHal4Nfc_RecvCompleteHandler(phHal4Nfc_Hal4Ctxt_t  *Hal4Ctxt,void *pInfo);
    280 
    281 /*Callback completion routine for Send*/
    282 extern void phHal4Nfc_SendCompleteHandler(phHal4Nfc_Hal4Ctxt_t  *Hal4Ctxt,void *pInfo);
    283 
    284 /*Callback completion routine for P2P Activate Event received from HCI*/
    285 extern void phHal4Nfc_P2PActivateComplete(
    286                     phHal4Nfc_Hal4Ctxt_t  *Hal4Ctxt,
    287                     void *pInfo
    288                     );
    289 /*Callback completion routine for P2P Deactivate Event received from HCI*/
    290 extern void phHal4Nfc_HandleP2PDeActivate(
    291                         phHal4Nfc_Hal4Ctxt_t  *Hal4Ctxt,
    292                         void *pInfo
    293                         );
    294 
    295 /*Callback completion routine for reactivate target*/
    296 extern void phHal4Nfc_ReactivationComplete(
    297                         phHal4Nfc_Hal4Ctxt_t  *Hal4Ctxt,
    298                         void *pInfo
    299                         );
    300 
    301 /**Execute Hal4 Disconnect*/
    302 extern NFCSTATUS phHal4Nfc_Disconnect_Execute(
    303                             phHal_sHwReference_t  *psHwReference
    304                             );
    305 
    306 /**Handle transceive timeout*/
    307 #ifdef TRANSACTION_TIMER
    308 extern void phHal4Nfc_TrcvTimeoutHandler(uint32_t TrcvTimerId);
    309 #endif /*TRANSACTION_TIMER*/
    310 
    311 #endif/*PHHAL4NFC_INTERNAL_H*/
    312 
    313 
    314