Mag Card

>w## Notice > * please include the header file "bwsdk_api.h" when you need to use Mag Card `#include "bwsdk_api.h"` >i## data structure ``` /** * @brief Track TAG of magcard */ typedef enum { TAG_MAGCARD_TRKVIEW = 0x00, TAG_MAGCARD_TRKERR, TAG_MAGCARD_TRACK1, TAG_MAGCARD_TRACK2, TAG_MAGCARD_TRACK3, } TagTrack_t; ///< The maximum allowed is: track1 = 79; track2 = 40; track3 = 107. #define MAG_TRACK1_SIZE 80 #define MAG_TRACK2_SIZE 48 #define MAG_TRACK3_SIZE 112 #define MAG_TRACK1_MASK (1<<0) ///< bitmask of TRACK1 #define MAG_TRACK2_MASK (1<<1) ///< bitmask of TRACK2 #define MAG_TRACK3_MASK (1<<2) ///< bitmask of TRACK3 #define MAG_TRACKV_MASK (1<<3) ///< bitmask of TRACKView /** * @brief Track infomation of magcard */ typedef struct { unsigned char ucNr; ///< count of tracks with data unsigned char ucTrackMask; ///< bismasks of tracks with data. Refer to MAG_TRACKx_MASK unsigned char aucTrack1[MAG_TRACK1_SIZE]; ///< Track 1 string unsigned char aucTrack2[MAG_TRACK2_SIZE]; ///< Track 2 string unsigned char aucTrack3[MAG_TRACK3_SIZE]; ///< Track 3 string unsigned char aucTrkView[MAG_TRACK2_SIZE]; ///< Track view string } MagTrack_T; /** * @brief Encrypted track infomation of magcard */ typedef struct { unsigned char ucNr; ///< count of tracks with data unsigned char ucTrackMask; ///< bismasks of tracks with data. Refer to MAG_TRACKx_MASK unsigned char ucTrk1Len; ///< Length of track 1 data unsigned char ucTrk2Len; ///< Length of track 1 data unsigned char ucTrk3Len; ///< Length of track 1 data unsigned char ucTrkVLen; ///< Length of track view unsigned char aucTrack1[MAG_TRACK1_SIZE]; ///< track 1 data unsigned char aucTrack2[MAG_TRACK2_SIZE]; ///< track 1 data unsigned char aucTrack3[MAG_TRACK3_SIZE]; ///< track 1 data unsigned char aucTrackView[MAG_TRACK2_SIZE]; ///< track 2 string } MagEncryptTrack_T; ``` >i## MagCardOpenRev ### Prototype `int MagCardOpenRev(void);` ### Function * open MagCard module ### Parameter |Name|Type|description| |-|-|-| |none||| ### Retval |Value|Type|Description| |-|-|-| |=0|int|success| |<0|int|fail| >i## MagCardReadRev ### Prototype `int MagCardReadRev(MagTrack_T *pstTracks);` ### Function * Read magcard data ### Parameter |Name|Type|description| |-|-|-| |pstTracks|MagTrack_T *|return MagCard tracks data| ### Retval |Value|Type|Description| |-|-|-| |=0|int|success| |<0|int|fail| >i## PedMagCardEncryptReadRev ### Prototype `int PedMagCardEncryptReadRev(int iTtkIdx, int iMode, MagEncryptTrack_T *pstTracks);` ### Function * Read encrypted magcard data ### Parameter |Name|Type|description| |-|-|-| |iTtkIdx|int|TTK index| |iMode|int|mode of encrypt:0x00: ECB mode, padding by 0x00; 0x01: CBC mode, padding by 0x00; 0x02: CNCUP mode| |pstTracks|MagEncryptTrack_T *|return encrypted MagCard tracks data| ### Retval |Value|Type|Description| |-|-|-| |=0|int|success| |<0|int|fail| >i## MagCardCloseRev ### Prototype `int MagCardCloseRev(void);` ### Function * Close MagCard module ### Parameter |Name|Type|description| |-|-|-| |none||| ### Retval |Value|Type|Description| |-|-|-| |=0|int|success| |<0|int|fail| >s## Example ``` int iRet = 0; MagTrack_T magTrack; MagEncryptTrack_T magEncryptTrack; iRet = MagCardOpenRev(); if (!iRet) { memset(&magTrack, 0, sizeof(MagTrack_T)); iRet = MagCardReadRev(&magTrack); ///< or you need to encrypt the data /* memset(&magEncryptTrack, 0, sizeof(MagEncryptTrack_T)); iRet = PedMagCardEncryptReadRev(0x03, 0x00, &magEncryptTrack); */ if (!iRet) { logger_serial_dump_buff("track data:", &magTrack, sizeof(MagTrack_T)); } MagCardCloseRev(); } return iRet; ```