mirror of
https://github.com/meshtastic/firmware.git
synced 2025-09-17 15:56:49 +00:00
Compare commits
2 Commits
fadcbd597f
...
fcfb197571
Author | SHA1 | Date | |
---|---|---|---|
![]() |
fcfb197571 | ||
![]() |
dd7140b7a1 |
@ -314,14 +314,28 @@ void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address, uint8_t asize)
|
||||
break;
|
||||
case INA3221_ADDR:
|
||||
registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0xFE), 2);
|
||||
LOG_DEBUG("Register MFG_UID: 0x%x", registerValue);
|
||||
LOG_DEBUG("Register MFG_UID FE: 0x%x", registerValue);
|
||||
if (registerValue == 0x5449) {
|
||||
LOG_INFO("INA3221 sensor found at address 0x%x", (uint8_t)addr.address);
|
||||
type = INA3221;
|
||||
} else {
|
||||
/* check the first 2 bytes of the 6 byte response register
|
||||
LARK FW 1.0 should return:
|
||||
RESPONSE_STATUS STATUS_SUCCESS (0x53)
|
||||
RESPONSE_CMD CMD_GET_VERSION (0x05)
|
||||
RESPONSE_LEN_L 0x02
|
||||
RESPONSE_LEN_H 0x00
|
||||
RESPONSE_PAYLOAD 0x01
|
||||
RESPONSE_PAYLOAD+1 0x00
|
||||
*/
|
||||
registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0x05), 2);
|
||||
LOG_DEBUG("Register MFG_UID 05: 0x%x", registerValue);
|
||||
if (registerValue == 0x5305) {
|
||||
LOG_INFO("DFRobot Lark weather station found at address 0x%x", (uint8_t)addr.address);
|
||||
type = DFROBOT_LARK;
|
||||
}
|
||||
// else: probably a RAK12500/UBLOX GPS on I2C
|
||||
}
|
||||
break;
|
||||
case MCP9808_ADDR:
|
||||
// We need to check for STK8BAXX first, since register 0x07 is new data flag for the z-axis and can produce some
|
||||
|
@ -61,6 +61,16 @@ meshtastic_LocalConfig config;
|
||||
meshtastic_LocalModuleConfig moduleConfig;
|
||||
meshtastic_ChannelFile channelFile;
|
||||
|
||||
#ifdef USERPREFS_USE_ADMIN_KEY_0
|
||||
static unsigned char userprefs_admin_key_0[] = USERPREFS_USE_ADMIN_KEY_0;
|
||||
#endif
|
||||
#ifdef USERPREFS_USE_ADMIN_KEY_1
|
||||
static unsigned char userprefs_admin_key_1[] = USERPREFS_USE_ADMIN_KEY_1;
|
||||
#endif
|
||||
#ifdef USERPREFS_USE_ADMIN_KEY_2
|
||||
static unsigned char userprefs_admin_key_2[] = USERPREFS_USE_ADMIN_KEY_2;
|
||||
#endif
|
||||
|
||||
bool meshtastic_DeviceState_callback(pb_istream_t *istream, pb_ostream_t *ostream, const pb_field_iter_t *field)
|
||||
{
|
||||
if (ostream) {
|
||||
@ -406,32 +416,37 @@ void NodeDB::installDefaultConfig(bool preserveKey = false)
|
||||
#else
|
||||
config.lora.ignore_mqtt = false;
|
||||
#endif
|
||||
#ifdef USERPREFS_USE_ADMIN_KEY
|
||||
// Initialize admin_key_count to zero
|
||||
byte numAdminKeys = 0;
|
||||
|
||||
#ifdef USERPREFS_USE_ADMIN_KEY_0
|
||||
// Check if USERPREFS_ADMIN_KEY_0 is non-empty
|
||||
if (sizeof(USERPREFS_ADMIN_KEY_0) > 0) {
|
||||
memcpy(config.security.admin_key[numAdminKeys].bytes, USERPREFS_ADMIN_KEY_0, 32);
|
||||
config.security.admin_key[numAdminKeys].size = 32;
|
||||
if (sizeof(userprefs_admin_key_0) > 0) {
|
||||
memcpy(config.security.admin_key[0].bytes, userprefs_admin_key_0, 32);
|
||||
config.security.admin_key[0].size = 32;
|
||||
numAdminKeys++;
|
||||
}
|
||||
|
||||
// Check if USERPREFS_ADMIN_KEY_1 is non-empty
|
||||
if (sizeof(USERPREFS_ADMIN_KEY_1) > 0) {
|
||||
memcpy(config.security.admin_key[numAdminKeys].bytes, USERPREFS_ADMIN_KEY_1, 32);
|
||||
config.security.admin_key[numAdminKeys].size = 32;
|
||||
numAdminKeys++;
|
||||
}
|
||||
|
||||
// Check if USERPREFS_ADMIN_KEY_2 is non-empty
|
||||
if (sizeof(USERPREFS_ADMIN_KEY_2) > 0) {
|
||||
memcpy(config.security.admin_key[config.security.admin_key_count].bytes, USERPREFS_ADMIN_KEY_2, 32);
|
||||
config.security.admin_key[config.security.admin_key_count].size = 32;
|
||||
numAdminKeys++;
|
||||
}
|
||||
config.security.admin_key_count = numAdminKeys;
|
||||
#endif
|
||||
|
||||
#ifdef USERPREFS_USE_ADMIN_KEY_1
|
||||
// Check if USERPREFS_ADMIN_KEY_1 is non-empty
|
||||
if (sizeof(userprefs_admin_key_1) > 0) {
|
||||
memcpy(config.security.admin_key[1].bytes, userprefs_admin_key_1, 32);
|
||||
config.security.admin_key[1].size = 32;
|
||||
numAdminKeys++;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef USERPREFS_USE_ADMIN_KEY_2
|
||||
// Check if USERPREFS_ADMIN_KEY_2 is non-empty
|
||||
if (sizeof(userprefs_admin_key_2) > 0) {
|
||||
memcpy(config.security.admin_key[2].bytes, userprefs_admin_key_2, 32);
|
||||
config.security.admin_key[2].size = 32;
|
||||
numAdminKeys++;
|
||||
}
|
||||
#endif
|
||||
config.security.admin_key_count = numAdminKeys;
|
||||
|
||||
if (shouldPreserveKey) {
|
||||
config.security.private_key.size = 32;
|
||||
memcpy(config.security.private_key.bytes, private_key_temp, config.security.private_key.size);
|
||||
@ -888,6 +903,54 @@ void NodeDB::loadFromDisk()
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure we load hard coded admin keys even when the configuration file has none.
|
||||
// Initialize admin_key_count to zero
|
||||
byte numAdminKeys = 0;
|
||||
uint16_t sum = 0;
|
||||
#ifdef USERPREFS_USE_ADMIN_KEY_0
|
||||
for (uint8_t b = 0; b < 32; b++) {
|
||||
sum += config.security.admin_key[0].bytes[b];
|
||||
}
|
||||
if (sum == 0) {
|
||||
numAdminKeys += 1;
|
||||
LOG_INFO("Admin 0 key zero. Loading hard coded key from user preferences.");
|
||||
memcpy(config.security.admin_key[0].bytes, userprefs_admin_key_0, 32);
|
||||
config.security.admin_key[0].size = 32;
|
||||
config.security.admin_key_count = numAdminKeys;
|
||||
saveToDisk(SEGMENT_CONFIG);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef USERPREFS_USE_ADMIN_KEY_1
|
||||
sum = 0;
|
||||
for (uint8_t b = 0; b < 32; b++) {
|
||||
sum += config.security.admin_key[1].bytes[b];
|
||||
}
|
||||
if (sum == 0) {
|
||||
numAdminKeys += 1;
|
||||
LOG_INFO("Admin 1 key zero. Loading hard coded key from user preferences.");
|
||||
memcpy(config.security.admin_key[1].bytes, userprefs_admin_key_1, 32);
|
||||
config.security.admin_key[1].size = 32;
|
||||
config.security.admin_key_count = numAdminKeys;
|
||||
saveToDisk(SEGMENT_CONFIG);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef USERPREFS_USE_ADMIN_KEY_2
|
||||
sum = 0;
|
||||
for (uint8_t b = 0; b < 32; b++) {
|
||||
sum += config.security.admin_key[2].bytes[b];
|
||||
}
|
||||
if (sum == 0) {
|
||||
numAdminKeys += 1;
|
||||
LOG_INFO("Admin 2 key zero. Loading hard coded key from user preferences.");
|
||||
memcpy(config.security.admin_key[2].bytes, userprefs_admin_key_2, 32);
|
||||
config.security.admin_key[2].size = 32;
|
||||
config.security.admin_key_count = numAdminKeys;
|
||||
saveToDisk(SEGMENT_CONFIG);
|
||||
}
|
||||
#endif
|
||||
|
||||
state = loadProto(moduleConfigFileName, meshtastic_LocalModuleConfig_size, sizeof(meshtastic_LocalModuleConfig),
|
||||
&meshtastic_LocalModuleConfig_msg, &moduleConfig);
|
||||
if (state != LoadFileResult::LOAD_SUCCESS) {
|
||||
|
15
userPrefs.h
15
userPrefs.h
@ -72,16 +72,17 @@ static unsigned char icon_bits[] = {
|
||||
/*
|
||||
* PKI Admin keys.
|
||||
* If a Admin key is set with '{};'
|
||||
* then it will be ignored, a PKI key must have a size of 32.
|
||||
* then it will be ignored, a PKI key must have a size of 32 byte.
|
||||
*/
|
||||
/*
|
||||
#define USERPREFS_USE_ADMIN_KEY 1
|
||||
static unsigned char USERPREFS_ADMIN_KEY_0[] = {0xcd, 0xc0, 0xb4, 0x3c, 0x53, 0x24, 0xdf, 0x13, 0xca, 0x5a, 0xa6,
|
||||
0x0c, 0x0d, 0xec, 0x85, 0x5a, 0x4c, 0xf6, 0x1a, 0x96, 0x04, 0x1a,
|
||||
0x3e, 0xfc, 0xbb, 0x8e, 0x33, 0x71, 0xe5, 0xfc, 0xff, 0x3c};
|
||||
static unsigned char USERPREFS_ADMIN_KEY_1[] = {};
|
||||
static unsigned char USERPREFS_ADMIN_KEY_2[] = {};
|
||||
#define USERPREFS_USE_ADMIN_KEY_0 \
|
||||
{ \
|
||||
0xcd, 0xc0, 0xb4, 0x3c, 0x53, 0x24, 0xdf, 0x13, 0xca, 0x5a, 0xa6, 0x0c, 0x0d, 0xec, 0x85, 0x5a, 0x4c, 0xf6, 0x1a, 0x96, \
|
||||
0x04, 0x1a, 0x3e, 0xfc, 0xbb, 0x8e, 0x33, 0x71, 0xe5, 0xfc, 0xff, 0x3c \
|
||||
};
|
||||
*/
|
||||
// #define USERPREFS_USE_ADMIN_KEY_1 {};
|
||||
// #define USERPREFS_USE_ADMIN_KEY_2 {};
|
||||
|
||||
/*
|
||||
* USERPREF_FIXED_GPS_LAT and USERPREF_FIXED_GPS_LON must be set, USERPREF_FIXED_GPS_ALT is optional
|
||||
|
Loading…
Reference in New Issue
Block a user