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

B2CA-1566: Dynamic network management #635

Draft
wants to merge 9 commits into
base: develop
Choose a base branch
from

Conversation

cedelavergne-ledger
Copy link
Contributor

Description

Add feature (new APDU) to inject a network config at runtime.
This configuration is not stored on the device, just used for the running session

Changes include

  • Bugfix (non-breaking change that solves an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (change that is not backwards-compatible and/or changes current functionality)
  • Tests
  • Documentation
  • Other (for changes that might not fit in any category)

src/network.c Outdated
Comment on lines 242 to 405
case TAG_STRUCTURE_VERSION:
if (field_len != 1) {
PRINTF("STRUCTURE_VERSION Size mismatch!\n");
return APDU_RESPONSE_INVALID_DATA;
}
if (g_network_payload.buf[offset] != NETWORK_TLV_VERSION) {
PRINTF("TLV Version mismatch!\n");
return APDU_RESPONSE_INVALID_DATA;
}
break;
case TAG_CHAIN_ID:
// Get Chain ID
if (field_len != sizeof(uint64_t)) {
PRINTF("CHAIN_ID Size mismatch!\n");
return APDU_RESPONSE_INVALID_DATA;
}
DYNAMIC_NETWORK_INFO.chain_id =
u64_from_BE(g_network_payload.buf + offset, field_len);
break;
case TAG_NETWORK_NAME:
// Get Name
if (field_len >= sizeof(DYNAMIC_NETWORK_INFO.name)) {
PRINTF("NETWORK_NAME Size mismatch!\n");
return APDU_RESPONSE_INSUFFICIENT_MEMORY;
}
memmove((void *) DYNAMIC_NETWORK_INFO.name,
g_network_payload.buf + offset,
field_len);
break;
case TAG_NETWORK_TICKER:
// Get Ticker
if (field_len >= sizeof(DYNAMIC_NETWORK_INFO.ticker)) {
PRINTF("NETWORK_TICKER Size mismatch!\n");
return APDU_RESPONSE_INSUFFICIENT_MEMORY;
}
memmove((void *) DYNAMIC_NETWORK_INFO.ticker,
g_network_payload.buf + offset,
field_len);
break;
case TAG_NETWORK_ICON:
// Get Icon
#ifdef HAVE_NBGL
// Image information header:
// - Width (2 Bytes)
// - Height (2 Bytes)
// - BPP (1 Byte)
// - Img buffer size (3 Bytes)
if (field_len < 8) {
PRINTF("NETWORK_ICON header length mismatch (%d)!\n", field_len);
return APDU_RESPONSE_INVALID_DATA;
}
uint32_t img_len = g_network_payload.buf[offset + 5] +
(g_network_payload.buf[offset + 6] << 8) +
(g_network_payload.buf[offset + 7] << 16);
if (field_len != (8 + img_len)) {
PRINTF("NETWORK_ICON length mismatch (%d/%d)!\n", field_len, (8 + img_len));
return APDU_RESPONSE_INVALID_DATA;
}
// Offset 5 to skip the image information header
if ((DYNAMIC_NETWORK_INFO.icon.bitmap = mem_alloc(field_len)) == NULL) {
PRINTF("NETWORK_ICON Size mismatch!\n");
return APDU_RESPONSE_INSUFFICIENT_MEMORY;
}
allocated_size += field_len;
DYNAMIC_NETWORK_INFO.icon.width = U2LE(g_network_payload.buf, offset);
DYNAMIC_NETWORK_INFO.icon.height = U2LE(g_network_payload.buf, offset + 2);
DYNAMIC_NETWORK_INFO.icon.bpp = g_network_payload.buf[offset + 4] >> 4;
DYNAMIC_NETWORK_INFO.icon.isFile = true;
memmove((void *) DYNAMIC_NETWORK_INFO.icon.bitmap,
g_network_payload.buf + offset,
field_len);
#endif
break;
case TAG_SIGNATURE:
// TODO
break;
}
offset += field_len;

Check notice

Code scanning / CodeQL

Long switch case Note

Switch has at least one case that is too long:
TAG_NETWORK_ICON (34 lines)
.
@cedelavergne-ledger cedelavergne-ledger force-pushed the cev/B2CA-1566_networks branch 2 times, most recently from 61a3ea3 to 17acc05 Compare September 16, 2024 09:24
uint64_t chain_id;
} network_info_t;
#define WITH_TAG_SIGNATURE
// #define WITH_TAG_CRC32

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant