2014-04-29 12:26:51 +00:00
|
|
|
/*
|
2019-06-17 18:27:55 +00:00
|
|
|
* This file is part of the Trezor project, https://trezor.io/
|
2014-04-29 12:26:51 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2014 Pavol Rusnak <stick@satoshilabs.com>
|
|
|
|
*
|
|
|
|
* This library is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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 Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __FSM_H__
|
|
|
|
#define __FSM_H__
|
|
|
|
|
2022-01-26 18:58:17 +00:00
|
|
|
#include "coins.h"
|
2018-07-10 14:58:00 +00:00
|
|
|
#include "messages-bitcoin.pb.h"
|
|
|
|
#include "messages-crypto.pb.h"
|
|
|
|
#include "messages-debug.pb.h"
|
|
|
|
#include "messages-ethereum.pb.h"
|
|
|
|
#include "messages-management.pb.h"
|
|
|
|
#include "messages-nem.pb.h"
|
2018-08-27 15:20:29 +00:00
|
|
|
#include "messages-stellar.pb.h"
|
2014-04-29 12:26:51 +00:00
|
|
|
|
2022-12-22 12:27:21 +00:00
|
|
|
// CoinJoin fee rate multiplier.
|
|
|
|
#define FEE_RATE_DECIMALS (1000000)
|
|
|
|
|
2014-04-29 12:26:51 +00:00
|
|
|
// message functions
|
|
|
|
|
|
|
|
void fsm_sendSuccess(const char *text);
|
2017-12-11 18:15:31 +00:00
|
|
|
|
|
|
|
#if DEBUG_LINK
|
2019-03-29 16:10:31 +00:00
|
|
|
void fsm_sendFailureDebug(FailureType code, const char *text,
|
|
|
|
const char *source);
|
2017-12-11 18:15:31 +00:00
|
|
|
|
2019-03-29 16:10:31 +00:00
|
|
|
#define fsm_sendFailure(code, text) \
|
|
|
|
fsm_sendFailureDebug((code), (text), __FILE__ ":" VERSTR(__LINE__) ":")
|
2017-12-11 18:15:31 +00:00
|
|
|
#else
|
2018-08-27 17:06:11 +00:00
|
|
|
void fsm_sendFailure(FailureType code, const char *text);
|
2017-12-11 18:15:31 +00:00
|
|
|
#endif
|
2014-04-29 12:26:51 +00:00
|
|
|
|
2018-09-14 12:40:29 +00:00
|
|
|
// void fsm_msgPinMatrixAck(const PinMatrixAck *msg); // tiny
|
|
|
|
// void fsm_msgButtonAck(const ButtonAck *msg); // tiny
|
|
|
|
// void fsm_msgPassphraseAck(const PassphraseAck *msg); // tiny
|
|
|
|
|
|
|
|
// common
|
|
|
|
void fsm_msgInitialize(const Initialize *msg);
|
|
|
|
void fsm_msgGetFeatures(const GetFeatures *msg);
|
|
|
|
void fsm_msgPing(const Ping *msg);
|
|
|
|
void fsm_msgChangePin(const ChangePin *msg);
|
2019-10-23 17:20:08 +00:00
|
|
|
void fsm_msgChangeWipeCode(const ChangeWipeCode *msg);
|
2018-09-14 12:40:29 +00:00
|
|
|
void fsm_msgWipeDevice(const WipeDevice *msg);
|
|
|
|
void fsm_msgGetEntropy(const GetEntropy *msg);
|
2019-10-03 13:41:45 +00:00
|
|
|
#if DEBUG_LINK
|
2018-09-14 12:40:29 +00:00
|
|
|
void fsm_msgLoadDevice(const LoadDevice *msg);
|
2019-10-03 13:41:45 +00:00
|
|
|
#endif
|
2018-09-14 12:40:29 +00:00
|
|
|
void fsm_msgResetDevice(const ResetDevice *msg);
|
|
|
|
void fsm_msgEntropyAck(const EntropyAck *msg);
|
|
|
|
void fsm_msgBackupDevice(const BackupDevice *msg);
|
|
|
|
void fsm_msgCancel(const Cancel *msg);
|
2020-04-21 13:33:46 +00:00
|
|
|
void fsm_msgLockDevice(const LockDevice *msg);
|
|
|
|
void fsm_msgEndSession(const EndSession *msg);
|
2018-09-14 12:40:29 +00:00
|
|
|
void fsm_msgApplySettings(const ApplySettings *msg);
|
|
|
|
void fsm_msgApplyFlags(const ApplyFlags *msg);
|
|
|
|
void fsm_msgRecoveryDevice(const RecoveryDevice *msg);
|
|
|
|
void fsm_msgWordAck(const WordAck *msg);
|
|
|
|
void fsm_msgSetU2FCounter(const SetU2FCounter *msg);
|
2019-11-12 15:47:50 +00:00
|
|
|
void fsm_msgGetNextU2FCounter(void);
|
2022-04-26 17:41:29 +00:00
|
|
|
void fsm_msgGetFirmwareHash(const GetFirmwareHash *msg);
|
2022-12-23 17:09:20 +00:00
|
|
|
void fsm_msgSetBusy(const SetBusy *msg);
|
2018-09-14 12:40:29 +00:00
|
|
|
|
|
|
|
// coin
|
|
|
|
void fsm_msgGetPublicKey(const GetPublicKey *msg);
|
|
|
|
void fsm_msgSignTx(const SignTx *msg);
|
2019-03-29 16:10:31 +00:00
|
|
|
void fsm_msgTxAck(
|
|
|
|
TxAck *msg); // not const because we mutate input/output scripts
|
2018-09-14 12:40:29 +00:00
|
|
|
void fsm_msgGetAddress(const GetAddress *msg);
|
|
|
|
void fsm_msgSignMessage(const SignMessage *msg);
|
|
|
|
void fsm_msgVerifyMessage(const VerifyMessage *msg);
|
2022-12-16 09:38:08 +00:00
|
|
|
void fsm_msgGetOwnershipId(const GetOwnershipId *msg);
|
|
|
|
void fsm_msgGetOwnershipProof(const GetOwnershipProof *msg);
|
2022-12-22 12:27:21 +00:00
|
|
|
void fsm_msgAuthorizeCoinJoin(const AuthorizeCoinJoin *msg);
|
|
|
|
void fsm_msgCancelAuthorization(const CancelAuthorization *msg);
|
2023-01-02 19:10:23 +00:00
|
|
|
void fsm_msgDoPreauthorized(const DoPreauthorized *msg);
|
2022-12-27 15:37:38 +00:00
|
|
|
void fsm_msgUnlockPath(const UnlockPath *msg);
|
2018-09-14 12:40:29 +00:00
|
|
|
|
|
|
|
// crypto
|
2019-02-04 13:25:13 +00:00
|
|
|
void fsm_msgCipherKeyValue(const CipherKeyValue *msg);
|
2018-09-14 12:40:29 +00:00
|
|
|
void fsm_msgSignIdentity(const SignIdentity *msg);
|
|
|
|
void fsm_msgGetECDHSessionKey(const GetECDHSessionKey *msg);
|
|
|
|
void fsm_msgCosiCommit(const CosiCommit *msg);
|
|
|
|
void fsm_msgCosiSign(const CosiSign *msg);
|
2022-09-06 14:05:39 +00:00
|
|
|
void fsm_clearCosiNonce(void);
|
2018-09-14 12:40:29 +00:00
|
|
|
|
|
|
|
// debug
|
2014-04-29 12:26:51 +00:00
|
|
|
#if DEBUG_LINK
|
2018-09-14 12:40:29 +00:00
|
|
|
// void fsm_msgDebugLinkDecision(const DebugLinkDecision *msg); // tiny
|
|
|
|
void fsm_msgDebugLinkGetState(const DebugLinkGetState *msg);
|
|
|
|
void fsm_msgDebugLinkStop(const DebugLinkStop *msg);
|
|
|
|
void fsm_msgDebugLinkMemoryWrite(const DebugLinkMemoryWrite *msg);
|
|
|
|
void fsm_msgDebugLinkMemoryRead(const DebugLinkMemoryRead *msg);
|
|
|
|
void fsm_msgDebugLinkFlashErase(const DebugLinkFlashErase *msg);
|
2022-02-09 15:47:54 +00:00
|
|
|
void fsm_msgDebugLinkReseedRandom(const DebugLinkReseedRandom *msg);
|
2014-04-29 12:26:51 +00:00
|
|
|
#endif
|
|
|
|
|
2018-09-14 12:40:29 +00:00
|
|
|
// ethereum
|
|
|
|
void fsm_msgEthereumGetAddress(const EthereumGetAddress *msg);
|
2019-01-14 15:27:59 +00:00
|
|
|
void fsm_msgEthereumGetPublicKey(const EthereumGetPublicKey *msg);
|
2021-10-21 15:23:59 +00:00
|
|
|
void fsm_msgEthereumSignTx(const EthereumSignTx *msg);
|
2021-08-10 08:56:13 +00:00
|
|
|
void fsm_msgEthereumSignTxEIP1559(const EthereumSignTxEIP1559 *msg);
|
2018-09-14 12:40:29 +00:00
|
|
|
void fsm_msgEthereumTxAck(const EthereumTxAck *msg);
|
|
|
|
void fsm_msgEthereumSignMessage(const EthereumSignMessage *msg);
|
|
|
|
void fsm_msgEthereumVerifyMessage(const EthereumVerifyMessage *msg);
|
2021-11-29 23:37:23 +00:00
|
|
|
void fsm_msgEthereumSignTypedHash(const EthereumSignTypedHash *msg);
|
2018-09-14 12:40:29 +00:00
|
|
|
|
|
|
|
// nem
|
2019-03-29 16:10:31 +00:00
|
|
|
void fsm_msgNEMGetAddress(
|
|
|
|
NEMGetAddress *msg); // not const because we mutate msg->network
|
|
|
|
void fsm_msgNEMSignTx(
|
|
|
|
NEMSignTx *msg); // not const because we mutate msg->network
|
|
|
|
void fsm_msgNEMDecryptMessage(
|
|
|
|
NEMDecryptMessage *msg); // not const because we mutate msg->payload
|
2018-09-14 12:40:29 +00:00
|
|
|
|
|
|
|
// stellar
|
|
|
|
void fsm_msgStellarGetAddress(const StellarGetAddress *msg);
|
|
|
|
void fsm_msgStellarSignTx(const StellarSignTx *msg);
|
|
|
|
void fsm_msgStellarPaymentOp(const StellarPaymentOp *msg);
|
|
|
|
void fsm_msgStellarCreateAccountOp(const StellarCreateAccountOp *msg);
|
2021-10-07 01:58:52 +00:00
|
|
|
void fsm_msgStellarPathPaymentStrictReceiveOp(
|
|
|
|
const StellarPathPaymentStrictReceiveOp *msg);
|
2021-10-07 14:06:08 +00:00
|
|
|
void fsm_msgStellarPathPaymentStrictSendOp(
|
|
|
|
const StellarPathPaymentStrictSendOp *msg);
|
2021-10-07 03:48:45 +00:00
|
|
|
void fsm_msgStellarManageBuyOfferOp(const StellarManageBuyOfferOp *msg);
|
2021-10-07 01:58:52 +00:00
|
|
|
void fsm_msgStellarManageSellOfferOp(const StellarManageSellOfferOp *msg);
|
2021-10-07 23:33:09 +00:00
|
|
|
void fsm_msgStellarCreatePassiveSellOfferOp(
|
|
|
|
const StellarCreatePassiveSellOfferOp *msg);
|
2018-09-14 12:40:29 +00:00
|
|
|
void fsm_msgStellarSetOptionsOp(const StellarSetOptionsOp *msg);
|
|
|
|
void fsm_msgStellarChangeTrustOp(const StellarChangeTrustOp *msg);
|
|
|
|
void fsm_msgStellarAllowTrustOp(const StellarAllowTrustOp *msg);
|
|
|
|
void fsm_msgStellarAccountMergeOp(const StellarAccountMergeOp *msg);
|
|
|
|
void fsm_msgStellarManageDataOp(const StellarManageDataOp *msg);
|
|
|
|
void fsm_msgStellarBumpSequenceOp(const StellarBumpSequenceOp *msg);
|
|
|
|
|
2021-02-25 11:54:29 +00:00
|
|
|
void fsm_msgRebootToBootloader(void);
|
|
|
|
|
2021-11-07 20:02:49 +00:00
|
|
|
bool fsm_layoutSignMessage(const uint8_t *msg, uint32_t len);
|
|
|
|
bool fsm_layoutVerifyMessage(const uint8_t *msg, uint32_t len);
|
|
|
|
|
2022-01-26 17:45:45 +00:00
|
|
|
bool fsm_layoutPathWarning(void);
|
2022-01-26 18:58:17 +00:00
|
|
|
bool fsm_checkCoinPath(const CoinInfo *coin, InputScriptType script_type,
|
|
|
|
uint32_t address_n_count, const uint32_t *address_n,
|
2022-12-30 22:20:33 +00:00
|
|
|
bool has_multisig, MessageType message_type,
|
|
|
|
bool show_warning);
|
2022-01-26 17:45:45 +00:00
|
|
|
|
2022-12-21 16:29:53 +00:00
|
|
|
bool fsm_getOwnershipId(uint8_t *script_pubkey, size_t script_pubkey_size,
|
|
|
|
uint8_t ownership_id[32]);
|
|
|
|
|
2022-02-17 16:16:42 +00:00
|
|
|
void fsm_abortWorkflows(void);
|
2023-01-02 19:25:37 +00:00
|
|
|
void fsm_postMsgCleanup(MessageType message_type);
|
2022-02-17 16:16:42 +00:00
|
|
|
|
2014-04-29 12:26:51 +00:00
|
|
|
#endif
|