ST / M24SR

Dependencies:   ST_INTERFACES

Dependents:   X_NUCLEO_NFC01A1

Fork of M24SR by ST Expansion SW Team

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers m24sr_def.h Source File

m24sr_def.h

00001 /**
00002  ******************************************************************************
00003  * @file    m24sr.h
00004  * @author  MMY Application Team
00005  * @version V2.0.0
00006  * @date    28 Apr 2017
00007  * @brief   This file provides a set of functions needed to manage M24SR
00008  ******************************************************************************
00009  * @attention
00010  *
00011  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
00012  *
00013  * Licensed under MMY-ST Liberty SW License Agreement V2, (the "License");
00014  * You may not use this file except in compliance with the License.
00015  * You may obtain a copy of the License at:
00016  *
00017  *        http://www.st.com/software_license_agreement_liberty_v2
00018  *
00019  * Unless required by applicable law or agreed to in writing, software
00020  * distributed under the License is distributed on an "AS IS" BASIS,
00021  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00022  * See the License for the specific language governing permissions and
00023  * limitations under the License.
00024  *
00025  ******************************************************************************
00026  */
00027 
00028 /* Define to prevent recursive inclusion -------------------------------------*/
00029 #ifndef __DRV_M24SR_H
00030 #define __DRV_M24SR_H
00031 
00032 /* Includes ------------------------------------------------------------------*/
00033 #include "Nfc.h"
00034 
00035 #ifdef __cplusplus
00036 extern "C" {
00037 #endif
00038 
00039 /** @addtogroup M24SR_Driver
00040  * @{
00041  */
00042 
00043 /** @addtogroup drv_M24SR
00044  * @{
00045  */
00046 
00047 /* Exported types ------------------------------------------------------------*/
00048 
00049 /**
00050  * @brief  APDU-Header command structure
00051  */
00052 typedef struct {
00053     uint8_t CLA; /* Command class */
00054     uint8_t INS; /* Operation code */
00055     uint8_t P1; /* Selection Mode */
00056     uint8_t P2; /* Selection Option */
00057 } C_APDU_Header;
00058 
00059 /**
00060  * @brief  APDU-Body command structure
00061  */
00062 typedef struct {
00063     uint8_t LC; /* Data field length */
00064     const uint8_t *pData; /* Command parameters */
00065     uint8_t LE; /* Expected length of data to be returned */
00066 } C_APDU_Body;
00067 
00068 /**
00069  * @brief  APDU Command structure
00070  */
00071 typedef struct {
00072     C_APDU_Header Header;
00073     C_APDU_Body Body;
00074 } C_APDU;
00075 
00076 /**
00077  * @brief  SC response structure
00078  */
00079 typedef struct {
00080     uint8_t *pData; /* Data returned from the card */ // pointer on the transceiver buffer = ReaderRecBuf[CR95HF_DATA_OFFSET ];
00081     uint8_t SW1; /* Command Processing status */
00082     uint8_t SW2; /* Command Processing qualification */
00083 } R_APDU;
00084 
00085 /**
00086  * @brief  GPO mode structure
00087  */
00088 typedef enum {
00089     RF_GPO = 0, I2C_GPO = 1
00090 } M24SR_GPO_MODE;
00091 
00092 typedef enum {
00093     M24SR_WAITINGTIME_POLLING,
00094     M24SR_INTERRUPT_GPO
00095 } M24SR_WAITINGTIME_MGMT;
00096 
00097 /* Exported constants --------------------------------------------------------*/
00098 
00099 /** @defgroup lib_M24SR_Exported_Constants
00100  * @{
00101  */
00102 
00103 /* ---------------------- status code ----------------------------------------*/
00104 #define UB_STATUS_OFFSET                                        4
00105 #define LB_STATUS_OFFSET                                    3
00106 #define I_AM_M24SR                ((uint8_t)0xB4)
00107 #define I_AM_M24SR_AUTOMOTIVE                ((uint8_t)0xBC)
00108 
00109 #define M24SR_NBBYTE_INVALID                                0xFFFE
00110 
00111 /** @defgroup drv_M24SR_File_Identifier
00112  * @{
00113  */
00114 #define SYSTEM_FILE_ID_BYTES {0xE1,0x01}
00115 #define CC_FILE_ID_BYTES {0xE1,0x03}
00116 #define NDEF_FILE_ID                        0x0001   
00117 /**
00118  * @}
00119  */
00120 
00121 /** @defgroup drv_M24SR_Password_Management
00122  * @{
00123  */
00124 #define READ_PWD                                0x0001
00125 #define WRITE_PWD                               0x0002
00126 #define I2C_PWD                                 0x0003
00127 
00128 /*-------------------------- Verify command answer ----------------------------*/
00129 /**
00130  * @}
00131  */
00132 
00133 /** @defgroup drv_M24SR_Command_Management
00134  * @{
00135  */
00136 
00137 /* special M24SR command ----------------------------------------------------------------------*/
00138 #define M24SR_OPENSESSION_COMMAND {0x26}
00139 #define M24SR_KILLSESSION_COMMAND {0x52}
00140 
00141 /* APDU Command: class list -------------------------------------------*/
00142 #define C_APDU_CLA_DEFAULT    0x00
00143 #define C_APDU_CLA_ST                   0xA2
00144 
00145 /*------------------------ Data Area Management Commands ---------------------*/
00146 #define C_APDU_SELECT_FILE     0xA4
00147 #define C_APDU_GET_RESPONCE    0xC0
00148 #define C_APDU_STATUS          0xF2
00149 #define C_APDU_UPDATE_BINARY   0xD6
00150 #define C_APDU_READ_BINARY     0xB0
00151 #define C_APDU_WRITE_BINARY    0xD0
00152 #define C_APDU_UPDATE_RECORD   0xDC
00153 #define C_APDU_READ_RECORD     0xB2
00154 
00155 /*-------------------------- Safety Management Commands ----------------------*/
00156 #define C_APDU_VERIFY          0x20
00157 #define C_APDU_CHANGE          0x24
00158 #define C_APDU_DISABLE         0x26
00159 #define C_APDU_ENABLE          0x28
00160 
00161 /*-------------------------- Gpio Management Commands ------------------------*/
00162 #define C_APDU_INTERRUPT       0xD6
00163 
00164 /*  Length  ----------------------------------------------------------------------------------*/
00165 #define M24SR_STATUS_NBBYTE                                             2
00166 #define M24SR_CRC_NBBYTE                                                    2
00167 #define M24SR_STATUSRESPONSE_NBBYTE                             5
00168 #define M24SR_DESELECTREQUEST_COMMAND   {0xC2,0xE0,0xB4}
00169 #define M24SR_DESELECTRESPONSE_NBBYTE                           3
00170 #define M24SR_WATINGTIMEEXTRESPONSE_NBBYTE              4
00171 #define M24SR_PASSWORD_NBBYTE                                           0x10
00172 #define M24SR_SELECTAPPLICATION_COMMAND {0xD2,0x76,0x00,0x00,0x85,0x01,0x01}
00173 /*  Command structure   ------------------------------------------------------------------------*/
00174 #define M24SR_CMDSTRUCT_SELECTAPPLICATION                   0x01FF
00175 #define M24SR_CMDSTRUCT_SELECTCCFILE                            0x017F
00176 #define M24SR_CMDSTRUCT_SELECTNDEFFILE                      0x017F
00177 #define M24SR_CMDSTRUCT_READBINARY                              0x019F
00178 #define M24SR_CMDSTRUCT_UPDATEBINARY                            0x017F
00179 #define M24SR_CMDSTRUCT_VERIFYBINARYWOPWD                   0x013F
00180 #define M24SR_CMDSTRUCT_VERIFYBINARYWITHPWD             0x017F
00181 #define M24SR_CMDSTRUCT_CHANGEREFDATA                           0x017F
00182 #define M24SR_CMDSTRUCT_ENABLEVERIFREQ                      0x011F
00183 #define M24SR_CMDSTRUCT_DISABLEVERIFREQ                     0x011F
00184 #define M24SR_CMDSTRUCT_SENDINTERRUPT                           0x013F
00185 #define M24SR_CMDSTRUCT_GPOSTATE                                    0x017F
00186 
00187 /*  Command structure Mask -------------------------------------------------------------------*/
00188 #define M24SR_PCB_NEEDED                0x0001      /* PCB byte present or not */
00189 #define M24SR_CLA_NEEDED                0x0002      /* CLA byte present or not */
00190 #define M24SR_INS_NEEDED                0x0004      /* Operation code present or not*/ 
00191 #define M24SR_P1_NEEDED                 0x0008      /* Selection Mode  present or not*/
00192 #define M24SR_P2_NEEDED                 0x0010      /* Selection Option present or not*/
00193 #define M24SR_LC_NEEDED                 0x0020      /* Data field length byte present or not */
00194 #define M24SR_DATA_NEEDED               0x0040      /* Data present or not */
00195 #define M24SR_LE_NEEDED                 0x0080      /* Expected length present or not */
00196 #define M24SR_CRC_NEEDED                0x0100      /* 2 CRC bytes present  or not */
00197 
00198 #define M24SR_DID_NEEDED                0x08            /* DID byte present or not */
00199 
00200 /**
00201  * @}
00202  */
00203 
00204 /*  Offset  ----------------------------------------------------------------------------------*/
00205 #define M24SR_OFFSET_PCB                                                    0
00206 #define M24SR_OFFSET_CLASS                                              1
00207 #define M24SR_OFFSET_INS                                                    2
00208 #define M24SR_OFFSET_P1                                                     3
00209 
00210 /*  mask    ------------------------------------------------------------------------------------*/
00211 #define M24SR_MASK_BLOCK                                                    0xC0
00212 #define M24SR_MASK_IBLOCK                                                   0x00
00213 #define M24SR_MASK_RBLOCK                                                   0x80
00214 #define M24SR_MASK_SBLOCK                                                   0xC0
00215 
00216 /**
00217  * @}
00218  */
00219 
00220 /**
00221  * @}
00222  */
00223 
00224 /* Exported macro ------------------------------------------------------------*/
00225 
00226 /** @brief Get Most Significant Byte
00227  * @param  val: number where MSB must be extracted
00228  * @retval MSB
00229  */
00230 #define GETMSB(val)         ( (uint8_t) ((val & 0xFF00 )>>8) ) 
00231 
00232 /** @brief Get Least Significant Byte
00233  * @param  val: number where LSB must be extracted
00234  * @retval LSB
00235  */
00236 #define GETLSB(val)         ( (uint8_t) (val & 0x00FF )) 
00237 
00238 /** @brief Used to toggle the block number by adding 0 or 1 to default block number value
00239  * @param  val: number to know if incrementation is needed
00240  * @retval  0 or 1 if incrementation needed
00241  */
00242 #define TOGGLE(val)         ((val != 0x00)? 0x00 : 0x01)
00243 
00244 typedef struct {
00245     C_APDU command;
00246     //static R_APDU                         Response;
00247     uint8_t dataBuffer[0xFF];
00248     uint8_t uM24SRbuffer[0xFF];
00249     uint8_t uDIDbyte;
00250 } M24SR_DrvDataTypeDef;
00251 
00252 typedef void* M24SR_InitTypeDef;
00253 
00254 extern NFC_t M24SR_IO_Init(void *handle);
00255 extern NFC_t M24SR_IO_IsAnswerReady(void *handle);
00256 extern NFC_t M24SR_IO_SendI2Ccommand(void *handle, uint8_t NbByte,
00257         uint8_t *pBuffer);
00258 extern NFC_t M24SR_IO_ReceiveI2Cresponse(void *handle,
00259         uint8_t NbByte, uint8_t *pBuffer);
00260 extern NFC_t M24SR_IO_PollI2C(void *handle);
00261 //extern void M24SR_IO_GPO_ReadPin(void *handle, GPIO_PinState *pPinState);
00262 //extern void M24SR_IO_RFDIS_WritePin(void *handle, GPIO_PinState PinState);
00263 extern void M24SR_IO_GPO_ReadPin(void *handle, uint8_t *pPinState);
00264 extern void M24SR_IO_RFDIS_WritePin(void *handle, uint8_t PinState);
00265 //extern void M24SR_IO_SetI2CSynchroMode(void *handle,
00266 //      M24SR_WAITINGTIME_MGMT mode);
00267 
00268 /**
00269  * @}
00270  */
00271 
00272 /**
00273  * @}
00274  */
00275 
00276 #ifdef __cplusplus
00277 }
00278 #endif
00279 
00280 #endif /* __DRV_M24SR_H */
00281 
00282 /******************* (C) COPYRIGHT 2013 STMicroelectronics *****END OF FILE****/