Merge pull request #2593 from Akury83/master
[RRG-proxmark3.git] / armsrc / i2c.h
blob3b45c6d7dcbce57f12de14b90cce6ab8d9644c06
1 //-----------------------------------------------------------------------------
2 // Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // See LICENSE.txt for the text of the license.
15 //-----------------------------------------------------------------------------
16 #ifndef __I2C_H
17 #define __I2C_H
19 #include "common.h"
20 #include "pm3_cmd.h"
22 #define I2C_DEVICE_ADDRESS_BOOT 0xB0
23 #define I2C_DEVICE_ADDRESS_MAIN 0xC0
25 #define I2C_DEVICE_CMD_GENERATE_ATR 0x01
26 #define I2C_DEVICE_CMD_SEND 0x02
27 #define I2C_DEVICE_CMD_READ 0x03
28 #define I2C_DEVICE_CMD_SETBAUD 0x04
29 #define I2C_DEVICE_CMD_SIM_CLC 0x05
30 #define I2C_DEVICE_CMD_GETVERSION 0x06
31 #define I2C_DEVICE_CMD_SEND_T0 0x07
33 // The SIM module v4 supports up to 384 bytes for the length.
34 #define ISO7816_MAX_FRAME 270
36 // 8051 speaks with smart card.
37 // 1000*50*3.07 = 153.5ms
38 // 1 byte transfer == 1ms with max frame being 256 bytes
39 #define SIM_WAIT_DELAY 88000 // about 270ms delay // 109773 -- about 337.7ms delay
42 void I2C_recovery(void);
43 void I2C_init(bool has_ticks);
44 void I2C_Reset(void);
45 void I2C_SetResetStatus(uint8_t LineRST, uint8_t LineSCK, uint8_t LineSDA);
47 void I2C_Reset_EnterMainProgram(void);
48 void I2C_Reset_EnterBootloader(void);
50 bool I2C_WriteCmd(uint8_t device_cmd, uint8_t device_address);
52 bool I2C_WriteByte(uint8_t data, uint8_t device_cmd, uint8_t device_address);
53 bool I2C_BufferWrite(const uint8_t *data, uint16_t len, uint8_t device_cmd, uint8_t device_address);
54 int16_t I2C_BufferRead(uint8_t *data, uint16_t len, uint8_t device_cmd, uint8_t device_address);
56 // for firmware
57 int16_t I2C_ReadFW(uint8_t *data, uint8_t len, uint8_t msb, uint8_t lsb, uint8_t device_address);
58 bool I2C_WriteFW(const uint8_t *data, uint8_t len, uint8_t msb, uint8_t lsb, uint8_t device_address);
60 bool sc_rx_bytes(uint8_t *dest, uint16_t *destlen, uint32_t wait);
62 bool GetATR(smart_card_atr_t *card_ptr, bool verbose);
64 // generice functions
65 void SmartCardAtr(void);
66 void SmartCardRaw(const smart_card_raw_t *p);
67 void SmartCardUpgrade(uint64_t arg0);
68 void SmartCardSetBaud(uint64_t arg0);
69 void SmartCardSetClock(uint64_t arg0);
70 void I2C_print_status(void);
71 int I2C_get_version(uint8_t *major, uint8_t *minor);
73 #endif