Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: rudimentary BLE support #3501

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion common/protob/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
check: messages.pb messages-binance.pb messages-bitcoin.pb messages-bootloader.pb messages-cardano.pb messages-common.pb messages-crypto.pb messages-debug.pb messages-ethereum.pb messages-management.pb messages-monero.pb messages-nem.pb messages-ripple.pb messages-stellar.pb messages-tezos.pb messages-eos.pb
check: messages.pb messages-binance.pb messages-bitcoin.pb messages-ble.pb messages-bootloader.pb messages-cardano.pb messages-common.pb messages-crypto.pb messages-debug.pb messages-ethereum.pb messages-management.pb messages-monero.pb messages-nem.pb messages-ripple.pb messages-stellar.pb messages-tezos.pb messages-eos.pb

%.pb: %.proto
protoc -I/usr/include -I. $< -o $@
Expand Down
4 changes: 2 additions & 2 deletions common/protob/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
prefix = EXPECTED_PREFIX_RE.search(fn).group(1).capitalize()
if prefix in ("Bitcoin", "Bootloader", "Common", "Crypto", "Management"):
continue
if prefix == "Nem":
prefix = "NEM"
if prefix in ("Nem", "Ble"):
prefix = prefix.upper()
elif prefix == "Webauthn":
prefix = "WebAuthn"
for line in f:
Expand Down
100 changes: 100 additions & 0 deletions common/protob/messages-ble.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
syntax = "proto2";
package hw.trezor.messages.ble;

// Sugar for easier handling in Java
option java_package = "com.satoshilabs.trezor.lib.protobuf";
option java_outer_classname = "TrezorMessageBLE";

option (include_in_bitcoin_only) = true;

import "messages.proto";


/**
* Request: initializes upload of a new ble firmware im
* @start
* @next BLEUploadFirmwareNextChunk
* @next Failure
*/
message BLEUploadFirmwareInit {
required bytes init_data = 1;
required uint32 binsize = 2;
}


/**
* Response: Requests next chunk of a new ble firmware im
* @next BLEUploadFirmwareChunk
*/
message BLEUploadFirmwareNextChunk {
}

/**
* Request: sends next chunk of a new ble firmware im
* @next BLEUploadFirmwareNextChunk
* @next Success
* @next Failure
*/
message BLEUploadFirmwareChunk {
required bytes data = 1;
}


/**
* Request: erases all BLE bonds
* @start
* @next Success
* @next Failure
*/
message BLEEraseBonds {
}


/**
* Request: disconnect
* @start
* @next Success
* @next Failure
*/
message BLEDisconnect {
}



/**
* Request: initiates new pairing request
* @start
* @next BLEAuthKey
* @next Failure
*/
message BLEPairingRequest {
}

/**
* Request: confirms pairing request with auth key entered on the device
* @end
*/
message BLEAuthKey {
required bytes key = 1;
}


/**
* Request: initiates repairing request
* @start
* @next Success
* @next Failure
*/
message BLERepairRequest {
}


/**
* Request: initiates new pairing request with numeric comparison
* @start
* @next Success
* @next Failure
*/
message BLEComparisonRequest {
required bytes key = 1;
}
11 changes: 11 additions & 0 deletions common/protob/messages.proto
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,17 @@ enum MessageType {
MessageType_FirmwareRequest = 8 [(bitcoin_only) = true, (wire_out) = true, (wire_bootloader) = true];
MessageType_SelfTest = 32 [(bitcoin_only) = true, (wire_in) = true, (wire_bootloader) = true];

// BLE
MessageType_BLEUploadFirmwareInit = 8000 [(bitcoin_only) = true, (wire_in) = true];
MessageType_BLEUploadFirmwareNextChunk = 8001 [(bitcoin_only) = true, (wire_out) = true];
MessageType_BLEUploadFirmwareChunk = 8002 [(bitcoin_only) = true, (wire_in) = true];
MessageType_BLEPairingRequest = 8003 [(bitcoin_only) = true, (wire_in) = true];
MessageType_BLEAuthKey = 8004 [(bitcoin_only) = true, (wire_out) = true];
MessageType_BLERepairRequest = 8005 [(bitcoin_only) = true, (wire_in) = true];
MessageType_BLEEraseBonds = 8006 [(bitcoin_only) = true, (wire_in) = true];
MessageType_BLEDisconnect = 8007 [(bitcoin_only) = true, (wire_in) = true];
MessageType_BLEComparisonRequest = 8008 [(bitcoin_only) = true, (wire_in) = true];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The internal messages probably deserve their own wire_... flag.


// Bitcoin
MessageType_GetPublicKey = 11 [(bitcoin_only) = true, (wire_in) = true];
MessageType_PublicKey = 12 [(bitcoin_only) = true, (wire_out) = true];
Expand Down
2 changes: 1 addition & 1 deletion core/SConscript.bootloader
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ if TREZOR_MODEL in ('R', ):
FONT_BOLD='Font_PixelOperator_Bold_8'
FONT_MONO='Font_PixelOperator_Regular_8'
FONT_BIG=None
elif TREZOR_MODEL in ('T', 'DISC1'):
elif TREZOR_MODEL in ('T', 'T3W1', 'DISC1'):
FONT_NORMAL='Font_TTHoves_Regular_21'
FONT_DEMIBOLD=None
FONT_BOLD='Font_TTHoves_Bold_17'
Expand Down
2 changes: 1 addition & 1 deletion core/SConscript.bootloader_ci
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ if TREZOR_MODEL in ('1', 'R'):
FONT_BOLD=None
FONT_MONO='Font_PixelOperatorMono_Regular_8'
FONT_BIG=None
elif TREZOR_MODEL in ('T', ):
elif TREZOR_MODEL in ('T', 'T3W1'):
FONT_NORMAL='Font_Roboto_Regular_20'
FONT_DEMIBOLD=None
FONT_BOLD=None
Expand Down
4 changes: 2 additions & 2 deletions core/SConscript.bootloader_emu
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ if TREZOR_MODEL in ('1', 'R'):
FONT_BOLD='Font_PixelOperator_Bold_8'
FONT_MONO='Font_PixelOperator_Regular_8'
FONT_BIG=None
elif TREZOR_MODEL in ('T', ):
elif TREZOR_MODEL in ('T', 'T3W1'):
FONT_NORMAL='Font_TTHoves_Regular_21'
FONT_DEMIBOLD=None
FONT_BOLD='Font_TTHoves_Bold_17'
Expand Down Expand Up @@ -164,7 +164,7 @@ env.Replace(
env.Replace(
TREZOR_MODEL=TREZOR_MODEL, )

if TREZOR_MODEL in ('T', 'R'):
if TREZOR_MODEL in ('T', 'R', 'T3W1'):
CPU_MODEL = 'STM32F427xx'
elif TREZOR_MODEL in ('DISC1', ):
CPU_MODEL = 'STM32F429xx'
Expand Down
7 changes: 4 additions & 3 deletions core/SConscript.firmware
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ if TREZOR_MODEL in ('1', 'R'):
FONT_BOLD='Font_PixelOperator_Bold_8'
FONT_MONO='Font_PixelOperatorMono_Regular_8'
FONT_BIG='Font_Unifont_Regular_16'
elif TREZOR_MODEL in ('T', 'DISC1'):
elif TREZOR_MODEL in ('T', 'T3W1', 'DISC1'):
FONT_NORMAL='Font_TTHoves_Regular_21'
FONT_DEMIBOLD='Font_TTHoves_DemiBold_21'
FONT_BOLD='Font_TTHoves_Bold_17'
Expand Down Expand Up @@ -386,7 +386,7 @@ env = Environment(ENV=os.environ, CFLAGS=f"{ARGUMENTS.get('CFLAGS', '')} -DPRODU
FEATURES_AVAILABLE = tools.configure_board(TREZOR_MODEL, FEATURES_WANTED, env, CPPDEFINES_HAL, SOURCE_HAL, PATH_HAL)


if TREZOR_MODEL in ('T', 'DISC1'):
if TREZOR_MODEL in ('T', 'T3W1', 'DISC1'):
UI_LAYOUT = 'UI_LAYOUT_TT'
ui_layout_feature = 'model_tt'
elif TREZOR_MODEL in ('1', 'R'):
Expand Down Expand Up @@ -673,6 +673,7 @@ if FROZEN:
bitcoin_only=BITCOIN_ONLY,
backlight='backlight' in FEATURES_AVAILABLE,
optiga='optiga' in FEATURES_AVAILABLE,
ble='ble' in FEATURES_AVAILABLE,
ui_layout=UI_LAYOUT,
)

Expand Down Expand Up @@ -831,7 +832,7 @@ BINARY_NAME += "-dirty" if tools.get_git_modified() else ""
BINARY_NAME += ".bin"


if TREZOR_MODEL in ('T', 'R', 'DISC1'):
if TREZOR_MODEL in ('T', 'R', 'T3W1', 'DISC1'):
action_bin=[
'$OBJCOPY -O binary -j .vendorheader -j .header -j .flash -j .data --pad-to 0x08100000 $SOURCE ${TARGET}.p1',
'$OBJCOPY -O binary -j .flash2 $SOURCE ${TARGET}.p2',
Expand Down
2 changes: 1 addition & 1 deletion core/SConscript.prodtest
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ if TREZOR_MODEL in ('1', 'R'):
FONT_BOLD='Font_PixelOperator_Bold_8'
FONT_MONO=None
FONT_BIG=None
elif TREZOR_MODEL in ('T', ):
elif TREZOR_MODEL in ('T', 'T3W1'):
FONT_NORMAL=None
FONT_DEMIBOLD=None
FONT_BOLD='Font_Roboto_Bold_20'
Expand Down
2 changes: 1 addition & 1 deletion core/SConscript.reflash
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ if TREZOR_MODEL in ('1', 'R'):
FONT_BOLD='Font_PixelOperator_Bold_8'
FONT_MONO=None
FONT_BIG=None
elif TREZOR_MODEL in ('T', ):
elif TREZOR_MODEL in ('T', 'T3W1'):
FONT_NORMAL=None
FONT_DEMIBOLD=None
FONT_BOLD='Font_Roboto_Bold_20'
Expand Down
36 changes: 28 additions & 8 deletions core/SConscript.unix
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import tools
BITCOIN_ONLY = ARGUMENTS.get('BITCOIN_ONLY', '0')
EVERYTHING = BITCOIN_ONLY != '1'
TREZOR_MODEL = ARGUMENTS.get('TREZOR_MODEL', 'T')
DMA2D = TREZOR_MODEL in ('T', )
DMA2D = TREZOR_MODEL in ('T', 'T3W1')
CMAKELISTS = int(ARGUMENTS.get('CMAKELISTS', 0))

if TREZOR_MODEL in ('DISC1', ):
Expand Down Expand Up @@ -42,7 +42,7 @@ if TREZOR_MODEL in ('1', 'R'):
FONT_BOLD='Font_PixelOperator_Bold_8'
FONT_MONO='Font_PixelOperatorMono_Regular_8'
FONT_BIG='Font_Unifont_Regular_16'
elif TREZOR_MODEL in ('T', ):
elif TREZOR_MODEL in ('T', 'T3W1'):
FONT_NORMAL='Font_TTHoves_Regular_21'
FONT_DEMIBOLD='Font_TTHoves_DemiBold_21'
FONT_BOLD='Font_TTHoves_Bold_17'
Expand Down Expand Up @@ -176,7 +176,7 @@ if FEATURE_FLAGS["SECP256K1_ZKP"]:
SOURCE_MOD += [
'embed/extmod/modtrezorio/modtrezorio.c',
]
if TREZOR_MODEL in ('T',):
if TREZOR_MODEL in ('T', 'T3W1'):
SOURCE_MOD += [
'embed/extmod/modtrezorio/ff.c',
'embed/extmod/modtrezorio/ffunicode.c',
Expand Down Expand Up @@ -212,6 +212,10 @@ elif TREZOR_MODEL in ('R', ):
SOURCE_MOD += [
'embed/models/model_T2B1_layout.c',
]
elif TREZOR_MODEL in ('T3W1', ):
SOURCE_MOD += [
'embed/models/model_T3W1_layout.c',
]



Expand Down Expand Up @@ -386,7 +390,8 @@ SOURCE_UNIX = [
'vendor/micropython/ports/unix/input.c',
'vendor/micropython/ports/unix/unix_mphal.c',
]
if TREZOR_MODEL in ('T', 'R'):

if TREZOR_MODEL in ('T', 'R', 'T3W1'):
SOURCE_UNIX += [
'embed/trezorhal/unix/sbu.c',
]
Expand All @@ -396,6 +401,15 @@ if TREZOR_MODEL == 'R':
'embed/trezorhal/unix/optiga.c',
]

if TREZOR_MODEL == 'T3W1':
SOURCE_UNIX += [
'embed/trezorhal/unix/ble.c',
'embed/lib/ble/state.c',
'embed/lib/ble/fwu.c',
'embed/lib/ble/messages.c',
'embed/lib/ble/dfu.c',
]

if DMA2D:
CPPDEFINES_MOD += [
'USE_DMA2D',
Expand Down Expand Up @@ -423,7 +437,7 @@ else:
env = Environment(ENV=os.environ, CFLAGS='%s -DPYOPT=%s -DBITCOIN_ONLY=%s %s' % (ARGUMENTS.get('CFLAGS', ''), PYOPT, BITCOIN_ONLY, STATIC))


if TREZOR_MODEL in ('T',):
if TREZOR_MODEL in ('T', 'T3W1'):
UI_LAYOUT = 'UI_LAYOUT_TT'
ui_layout_feature = 'model_tt'
elif TREZOR_MODEL in ('1', 'R'):
Expand All @@ -432,7 +446,7 @@ elif TREZOR_MODEL in ('1', 'R'):
else:
raise ValueError('Unknown Trezor model')

if TREZOR_MODEL in ('T',):
if TREZOR_MODEL in ('T', 'T3W1'):
SDCARD = True
SOURCE_UNIX += [
'embed/trezorhal/unix/sdcard.c',
Expand Down Expand Up @@ -488,7 +502,7 @@ if ARGUMENTS.get('TREZOR_MEMPERF', '0') == '1':
env.Replace(
TREZOR_MODEL=TREZOR_MODEL, )

if TREZOR_MODEL in ('T', 'R'):
if TREZOR_MODEL in ('T', 'R', 'T3W1'):
CPU_MODEL = 'STM32F427xx'
elif TREZOR_MODEL in ('DISC1', ):
CPU_MODEL = 'STM32F429xx'
Expand Down Expand Up @@ -749,8 +763,9 @@ if FROZEN:
source=SOURCE_PY,
source_dir=SOURCE_PY_DIR,
bitcoin_only=BITCOIN_ONLY,
backlight=TREZOR_MODEL in ('T',),
backlight=TREZOR_MODEL in ('T','T3W1'),
optiga=TREZOR_MODEL in ('R',),
ble=TREZOR_MODEL in ('T3W1',),
ui_layout=UI_LAYOUT,
)

Expand Down Expand Up @@ -799,6 +814,11 @@ def cargo_build():
if TREZOR_MODEL in ('T',):
features.append('touch')
features.append('sd_card')
if TREZOR_MODEL in ('T3W1',):
features.append('touch')
features.append('button')
features.append('sd_card')
features.append('ble')
if TREZOR_MODEL in ('R', '1'):
features.append('button')

Expand Down
Loading
Loading