1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-13 19:18:56 +00:00
trezor-firmware/micropython/bootloader/messages.c

63 lines
1.7 KiB
C
Raw Normal View History

2017-04-15 15:44:19 +00:00
#include <assert.h>
#include <string.h>
#include "usb.h"
#include "version.h"
2017-04-15 15:44:19 +00:00
#include "protobuf.h"
#include "messages.h"
2017-04-15 15:44:19 +00:00
void send_msg_Success(int iface)
{
2017-04-15 15:44:19 +00:00
// response: Success message (id 2), payload len 0
PB_CTX ctx;
pb_start(&ctx, 2);
2017-04-16 15:37:39 +00:00
pb_end(&ctx);
usb_hid_write_blocking(iface, ctx.buf, ctx.pos, 1);
}
2017-04-15 15:44:19 +00:00
void send_msg_Failure(int iface)
{
2017-04-15 15:44:19 +00:00
// response: Failure message (id 3), payload len 2
// - code = 99 (Failure_FirmwareError)
PB_CTX ctx;
pb_start(&ctx, 3);
2017-04-16 15:37:39 +00:00
pb_add_varint(&ctx, 1, 99);
pb_end(&ctx);
usb_hid_write_blocking(iface, ctx.buf, ctx.pos, 1);
}
2017-04-15 15:44:19 +00:00
void send_msg_Features(int iface, bool firmware_present)
{
2017-04-15 15:44:19 +00:00
// response: Features message (id 17), payload len 22
// - vendor = "trezor.io"
// - major_version = VERSION_MAJOR
// - minor_version = VERSION_MINOR
// - patch_version = VERSION_PATCH
// - bootloader_mode = True
// - firmware_present = True/False
PB_CTX ctx;
pb_start(&ctx, 17);
2017-04-16 15:37:39 +00:00
pb_add_string(&ctx, 1, "trezor.io");
pb_add_varint(&ctx, 2, VERSION_MAJOR);
pb_add_varint(&ctx, 3, VERSION_MINOR);
pb_add_varint(&ctx, 4, VERSION_PATCH);
pb_add_bool(&ctx, 5, true);
pb_add_bool(&ctx, 18, firmware_present);
pb_end(&ctx);
usb_hid_write_blocking(iface, ctx.buf, ctx.pos, 1);
2017-04-15 15:44:19 +00:00
}
void send_msg_FirmwareRequest(int iface, uint32_t offset, uint32_t length)
{
// response: FirmwareRequest message (id 8), payload len X
// - offset = offset
// - length = length
PB_CTX ctx;
pb_start(&ctx, 8);
2017-04-16 15:37:39 +00:00
pb_add_varint(&ctx, 1, offset);
pb_add_varint(&ctx, 2, length);
pb_end(&ctx);
usb_hid_write_blocking(iface, ctx.buf, ctx.pos, 1);
2017-04-15 15:44:19 +00:00
}