Functions for accessing M24SR device.

Dependents:   Nucleo_NFC_Example I2C_NFC_Master Print_Entire_Nucleo_NFC01A1_Memory

Fork of lib_M24SR by Enrico Gregoratto

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers m24sr.h Source File

m24sr.h

00001 /**
00002   ******************************************************************************
00003   * @file    drv_M24SR.h
00004   * @author  MMY Application Team
00005   * @version V4.5.0
00006   * @date    08-May-2013
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 #ifdef __cplusplus
00033  extern "C" {
00034 #endif
00035 
00036 /* Includes ------------------------------------------------------------------*/
00037 #include "drv_I2C_M24SR.h"
00038 
00039      
00040 /* ---------------------- macro function -------------------------------------*/     
00041 #define GETMSB(val)         ( (uint8_t) ((val & 0xFF00 )>>8) ) 
00042 #define GETLSB(val)         ( (uint8_t) (val & 0x00FF )) 
00043 
00044 #define TOGGLE(val)         ((val != 0x00)? 0x00 : 0x01)
00045  
00046 /* ---------------------- status code ----------------------------------------*/
00047 #define M24SR_ACTION_COMPLETED                          0x9000
00048 #define UB_STATUS_OFFSET                                        4
00049 #define LB_STATUS_OFFSET                                    3
00050 
00051 #define M24SR_NBBYTE_INVALID                                0xFFFE
00052       
00053 /*-------------------------- File Identifier ---------------------------------*/     
00054 #define SYSTEM_FILE_ID                  0xE101   
00055 #define CC_FILE_ID                          0xE103
00056 #define NDEF_FILE_ID                        0x0001   
00057     
00058 /*-------------------------- Password Management -----------------------------*/
00059 #define READ_PWD                                0x0001
00060 #define WRITE_PWD                               0x0002
00061 #define I2C_PWD                                 0x0003
00062 
00063 /*-------------------------- Verify command answer ----------------------------*/
00064 #define M24SR_PWD_NOT_NEEDED                                0x9000
00065 #define M24SR_PWD_NEEDED                                        0x6300
00066 
00067 #define M24SR_PWD_CORRECT                                       0x9000
00068 
00069 
00070      
00071      
00072 /* special M24SR command ----------------------------------------------------------------------*/    
00073 #define M24SR_OPENSESSION                                                   0x26
00074 #define M24SR_KILLSESSION                                                   0x52
00075  
00076 /*  Length  ----------------------------------------------------------------------------------*/
00077 #define M24SR_STATUS_NBBYTE                                             2
00078 #define M24SR_CRC_NBBYTE                                                    2
00079 #define M24SR_STATUSRESPONSE_NBBYTE                             5
00080 #define M24SR_DESELECTREQUEST_NBBYTE                            3
00081 #define M24SR_DESELECTRESPONSE_NBBYTE                           3
00082 #define M24SR_WATINGTIMEEXTRESPONSE_NBBYTE              4
00083 #define M24SR_PASSWORD_NBBYTE                                           0x10
00084 
00085 /*  Command structure   ------------------------------------------------------------------------*/
00086 #define M24SR_CMDSTRUCT_SELECTAPPLICATION                   0x01FF
00087 #define M24SR_CMDSTRUCT_SELECTCCFILE                            0x017F
00088 #define M24SR_CMDSTRUCT_SELECTNDEFFILE                      0x017F
00089 #define M24SR_CMDSTRUCT_READBINARY                              0x019F
00090 #define M24SR_CMDSTRUCT_UPDATEBINARY                            0x017F
00091 #define M24SR_CMDSTRUCT_VERIFYBINARYWOPWD                   0x013F
00092 #define M24SR_CMDSTRUCT_VERIFYBINARYWITHPWD             0x017F
00093 #define M24SR_CMDSTRUCT_CHANGEREFDATA                           0x017F
00094 #define M24SR_CMDSTRUCT_ENABLEVERIFREQ                      0x011F
00095 #define M24SR_CMDSTRUCT_DISABLEVERIFREQ                     0x011F
00096 #define M24SR_CMDSTRUCT_SENDINTERRUPT                           0x013F
00097 #define M24SR_CMDSTRUCT_GPOSTATE                                    0x017F
00098 
00099 /*  Command structure Mask -------------------------------------------------------------------*/
00100 #define M24SR_PCB_NEEDED                0x0001      /* PCB byte present or not */
00101 #define M24SR_CLA_NEEDED                0x0002      /* CLA byte present or not */
00102 #define M24SR_INS_NEEDED                0x0004      /* Operation code present or not*/ 
00103 #define M24SR_P1_NEEDED                 0x0008      /* Selection Mode  present or not*/
00104 #define M24SR_P2_NEEDED                 0x0010      /* Selection Option present or not*/
00105 #define M24SR_LC_NEEDED                 0x0020      /* Data field length byte present or not */
00106 #define M24SR_DATA_NEEDED               0x0040      /* Data present or not */
00107 #define M24SR_LE_NEEDED                 0x0080      /* Expected length present or not */
00108 #define M24SR_CRC_NEEDED                0x0100      /* 2 CRC bytes present  or not */
00109 
00110 #define M24SR_DID_NEEDED                0x08            /* DID byte present or not */
00111 
00112 /*  Offset  ----------------------------------------------------------------------------------*/
00113 #define M24SR_OFFSET_PCB                                                    0
00114 #define M24SR_OFFSET_CLASS                                              1
00115 #define M24SR_OFFSET_INS                                                    2
00116 #define M24SR_OFFSET_P1                                                     3
00117 
00118 
00119 /*  mask    ------------------------------------------------------------------------------------*/
00120 #define M24SR_MASK_BLOCK                                                    0xC0
00121 #define M24SR_MASK_IBLOCK                                                   0x00
00122 #define M24SR_MASK_RBLOCK                                                   0x80
00123 #define M24SR_MASK_SBLOCK                                                   0xC0
00124 
00125 
00126 /* APDU Command: class list -------------------------------------------*/
00127 #define C_APDU_CLA_DEFAULT    0x00
00128 #define C_APDU_CLA_ST                   0xA2
00129 
00130 /*------------------------ Data Area Management Commands ---------------------*/
00131 #define C_APDU_SELECT_FILE     0xA4
00132 #define C_APDU_GET_RESPONCE    0xC0
00133 #define C_APDU_STATUS          0xF2
00134 #define C_APDU_UPDATE_BINARY   0xD6
00135 #define C_APDU_READ_BINARY     0xB0
00136 #define C_APDU_WRITE_BINARY    0xD0
00137 #define C_APDU_UPDATE_RECORD   0xDC
00138 #define C_APDU_READ_RECORD     0xB2
00139 
00140 /*-------------------------- Safety Management Commands ----------------------*/
00141 #define C_APDU_VERIFY          0x20
00142 #define C_APDU_CHANGE          0x24
00143 #define C_APDU_DISABLE         0x26
00144 #define C_APDU_ENABLE          0x28
00145 
00146 /*-------------------------- Gpio Management Commands ------------------------*/
00147 #define C_APDU_INTERRUPT       0xD6
00148 
00149 
00150 /* APDU-Header command structure ---------------------------------------------*/
00151 typedef struct
00152 {
00153   uint8_t CLA;  /* Command class */
00154   uint8_t INS;  /* Operation code */
00155   uint8_t P1;   /* Selection Mode */
00156   uint8_t P2;   /* Selection Option */
00157 } C_APDU_Header;
00158 
00159 /* APDU-Body command structure -----------------------------------------------*/
00160 typedef struct 
00161 {
00162   uint8_t LC;                               /* Data field length */ 
00163   uint8_t *pData ;                          /* Command parameters */ 
00164   uint8_t LE;                               /* Expected length of data to be returned */
00165 } C_APDU_Body;
00166 
00167 /* APDU Command structure ----------------------------------------------------*/
00168 typedef struct
00169 {
00170   C_APDU_Header Header;
00171   C_APDU_Body Body;
00172 } C_APDU;
00173 
00174 /* SC response structure -----------------------------------------------------*/
00175 typedef struct
00176 {
00177   uint8_t *pData ;  /* Data returned from the card */ // pointer on the transceiver buffer = ReaderRecBuf[CR95HF_DATA_OFFSET ];
00178   uint8_t SW1;                               /* Command Processing status */
00179   uint8_t SW2;                                  /* Command Processing qualification */
00180 } R_APDU;
00181 
00182 /* GPO mode structure -------------------------------------------------------*/
00183 typedef enum{
00184     RF_GPO= 0,
00185     I2C_GPO
00186 }M24SR_GPO_MODE;
00187 
00188 /* GPO state structure -------------------------------------------------------*/
00189 typedef enum{
00190     HIGH_IMPEDANCE= 0,
00191     SESSION_OPENED,
00192     WIP,
00193     I2C_ANSWER_READY,
00194     INTERRUPT,
00195     STATE_CONTROL
00196 }M24SR_GPO_MGMT;
00197 
00198 
00199 /*  public function --------------------------------------------------------------------------*/
00200 
00201 void     M24SR_Init                                                     ( void );
00202 uint16_t M24SR_GetSession                                       ( void );
00203 uint16_t M24SR_KillSession                                      ( void );
00204 uint16_t M24SR_Deselect                                             ( void );
00205 uint16_t M24SR_SelectApplication                            ( void );
00206 uint16_t M24SR_SelectCCfile                                     ( void );
00207 uint16_t M24SR_SelectNDEFfile                               ( uc16 NDEFfileId );
00208 uint16_t M24SR_SelectSystemfile                             ( void );
00209 uint16_t M24SR_ReadBinary                                       ( uc16 Offset, uc8 NbByteToRead, uint8_t *pBufferRead );
00210 uint16_t M24SR_STReadBinary                                     ( uc16 Offset, uc8 NbByteToRead, uint8_t *pBufferRead );
00211 uint16_t M24SR_UpdateBinary                                     ( uc16 Offset, uc8 NbByteToWrite, uc8 *pDataToWrite );
00212 uint16_t M24SR_Verify                                               ( uc16 uPwdId, uc8 NbPwdByte, uc8 *pPwd );
00213 uint16_t M24SR_ChangeReferenceData                      ( uc16 uPwdId, uc8 *pPwd );
00214 uint16_t M24SR_EnableVerificationRequirement    ( uc16 uReadOrWrite );
00215 uint16_t M24SR_DisableVerificationRequirement ( uc16 uReadOrWrite );
00216 uint16_t M24SR_EnablePermanentState                 ( uc16 uReadOrWrite  );
00217 uint16_t M24SR_DisablePermanentState                    ( uc16 uReadOrWrite  );
00218 uint16_t M24SR_SendInterrupt                                    ( void  );
00219 uint16_t M24SR_StateControl                                     ( uc8 uSetOrReset );
00220 uint16_t M24SR_ManageI2CGPO                                     ( uc8 GPO_I2Cconfig);
00221 uint16_t M24SR_ManageRFGPO                                      ( uc8 GPO_RFconfig);
00222 void         M24SR_RFConfig                                             ( uc8 OnOffChoice);
00223 
00224 #ifdef __cplusplus
00225 }
00226 #endif
00227 
00228 #endif /* __DRV_M24SR_H */
00229 
00230 
00231 
00232 
00233 /******************* (C) COPYRIGHT 2013 STMicroelectronics *****END OF FILE****/