2022-01-06 09:19:46 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// See LICENSE.txt for the text of the license.
|
|
|
|
//-----------------------------------------------------------------------------
|
2018-07-04 18:19:04 +08:00
|
|
|
#ifndef __I2C_H
|
|
|
|
#define __I2C_H
|
|
|
|
|
2019-08-08 22:57:33 +08:00
|
|
|
#include "common.h"
|
2021-04-08 15:34:11 +08:00
|
|
|
#include "pm3_cmd.h"
|
2018-07-04 18:19:04 +08:00
|
|
|
|
2019-03-10 02:19:50 +08:00
|
|
|
#define I2C_DEVICE_ADDRESS_BOOT 0xB0
|
|
|
|
#define I2C_DEVICE_ADDRESS_MAIN 0xC0
|
2018-07-04 18:19:04 +08:00
|
|
|
|
2019-03-10 02:19:50 +08:00
|
|
|
#define I2C_DEVICE_CMD_GENERATE_ATR 0x01
|
|
|
|
#define I2C_DEVICE_CMD_SEND 0x02
|
|
|
|
#define I2C_DEVICE_CMD_READ 0x03
|
|
|
|
#define I2C_DEVICE_CMD_SETBAUD 0x04
|
|
|
|
#define I2C_DEVICE_CMD_SIM_CLC 0x05
|
|
|
|
#define I2C_DEVICE_CMD_GETVERSION 0x06
|
|
|
|
#define I2C_DEVICE_CMD_SEND_T0 0x07
|
2018-07-04 18:19:04 +08:00
|
|
|
|
2023-10-01 19:05:08 +08:00
|
|
|
// The SIM module v4 supports up to 384 bytes for the length.
|
|
|
|
#define ISO7816_MAX_FRAME 270
|
|
|
|
|
|
|
|
// 8051 speaks with smart card.
|
|
|
|
// 1000*50*3.07 = 153.5ms
|
|
|
|
// 1 byte transfer == 1ms with max frame being 256 bytes
|
|
|
|
#define SIM_WAIT_DELAY 88000 // about 270ms delay // 109773 -- about 337.7ms delay
|
|
|
|
|
|
|
|
|
2018-11-14 22:07:04 +08:00
|
|
|
void I2C_recovery(void);
|
2022-12-09 14:40:41 +08:00
|
|
|
void I2C_init(bool has_ticks);
|
2018-07-04 18:19:04 +08:00
|
|
|
void I2C_Reset(void);
|
|
|
|
void I2C_SetResetStatus(uint8_t LineRST, uint8_t LineSCK, uint8_t LineSDA);
|
|
|
|
|
|
|
|
void I2C_Reset_EnterMainProgram(void);
|
|
|
|
void I2C_Reset_EnterBootloader(void);
|
|
|
|
|
2018-07-07 18:42:33 +08:00
|
|
|
bool I2C_WriteCmd(uint8_t device_cmd, uint8_t device_address);
|
2018-07-07 02:14:55 +08:00
|
|
|
|
2018-07-04 21:29:27 +08:00
|
|
|
bool I2C_WriteByte(uint8_t data, uint8_t device_cmd, uint8_t device_address);
|
2023-08-15 12:45:21 +08:00
|
|
|
bool I2C_BufferWrite(const uint8_t *data, uint16_t len, uint8_t device_cmd, uint8_t device_address);
|
2022-12-05 04:31:06 +08:00
|
|
|
int16_t I2C_BufferRead(uint8_t *data, uint16_t len, uint8_t device_cmd, uint8_t device_address);
|
2018-07-04 18:19:04 +08:00
|
|
|
|
2018-07-05 16:48:24 +08:00
|
|
|
// for firmware
|
2018-08-13 03:54:31 +08:00
|
|
|
int16_t I2C_ReadFW(uint8_t *data, uint8_t len, uint8_t msb, uint8_t lsb, uint8_t device_address);
|
2023-08-15 12:45:21 +08:00
|
|
|
bool I2C_WriteFW(const uint8_t *data, uint8_t len, uint8_t msb, uint8_t lsb, uint8_t device_address);
|
2018-07-05 16:48:24 +08:00
|
|
|
|
2023-09-17 00:38:53 +08:00
|
|
|
bool sc_rx_bytes(uint8_t *dest, uint16_t *destlen, uint32_t wait);
|
2018-07-06 17:16:46 +08:00
|
|
|
//
|
2020-08-03 23:38:18 +08:00
|
|
|
bool GetATR(smart_card_atr_t *card_ptr, bool verbose);
|
2018-07-06 17:16:46 +08:00
|
|
|
|
2018-07-05 22:32:10 +08:00
|
|
|
// generice functions
|
|
|
|
void SmartCardAtr(void);
|
2023-08-15 12:45:21 +08:00
|
|
|
void SmartCardRaw(const smart_card_raw_t *p);
|
2018-07-05 22:32:10 +08:00
|
|
|
void SmartCardUpgrade(uint64_t arg0);
|
2018-07-06 06:24:04 +08:00
|
|
|
void SmartCardSetBaud(uint64_t arg0);
|
|
|
|
void SmartCardSetClock(uint64_t arg0);
|
2018-07-04 21:29:27 +08:00
|
|
|
void I2C_print_status(void);
|
2019-05-03 15:04:28 +08:00
|
|
|
int I2C_get_version(uint8_t *maj, uint8_t *min);
|
2019-08-08 22:57:33 +08:00
|
|
|
|
2019-03-12 07:12:26 +08:00
|
|
|
#endif
|