mirror of
https://github.com/meshtastic/firmware.git
synced 2025-04-25 17:42:48 +00:00
Make ChannelSettings SUPER short for common channels
This commit is contained in:
parent
0cdc1fc959
commit
5cdc2f5142
2
proto
2
proto
@ -1 +1 @@
|
|||||||
Subproject commit d0868e366bc8f8d9b7ed1d1c5a80cac0de9dc956
|
Subproject commit b1e1a54330d1a7f74f097dbf27cdba9cfb739473
|
@ -57,6 +57,13 @@ static uint8_t ourMacAddr[6];
|
|||||||
*/
|
*/
|
||||||
NodeNum displayedNodeNum;
|
NodeNum displayedNodeNum;
|
||||||
|
|
||||||
|
/// A usable (but bigger) version of the channel name in the channelSettings object
|
||||||
|
const char *channelName;
|
||||||
|
|
||||||
|
/// A usable psk - which has been constructed based on the (possibly short psk) in channelSettings
|
||||||
|
static uint8_t activePSK[32];
|
||||||
|
static uint8_t activePSKSize;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate a short suffix used to disambiguate channels that might have the same "name" entered by the human but different PSKs.
|
* Generate a short suffix used to disambiguate channels that might have the same "name" entered by the human but different PSKs.
|
||||||
* The ideas is that the PSK changing should be visible to the user so that they see they probably messed up and that's why they
|
* The ideas is that the PSK changing should be visible to the user so that they see they probably messed up and that's why they
|
||||||
@ -77,10 +84,10 @@ const char *getChannelName()
|
|||||||
static char buf[32];
|
static char buf[32];
|
||||||
|
|
||||||
uint8_t code = 0;
|
uint8_t code = 0;
|
||||||
for (int i = 0; i < channelSettings.psk.size; i++)
|
for (int i = 0; i < activePSKSize; i++)
|
||||||
code ^= channelSettings.psk.bytes[i];
|
code ^= activePSK[i];
|
||||||
|
|
||||||
snprintf(buf, sizeof(buf), "#%s-%c", channelSettings.name, 'A' + (code % 26));
|
snprintf(buf, sizeof(buf), "#%s-%c", channelName, 'A' + (code % 26));
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,13 +117,47 @@ bool NodeDB::resetRadioConfig()
|
|||||||
channelSettings.modem_config = ChannelSettings_ModemConfig_Bw125Cr48Sf4096; // slow and long range
|
channelSettings.modem_config = ChannelSettings_ModemConfig_Bw125Cr48Sf4096; // slow and long range
|
||||||
|
|
||||||
channelSettings.tx_power = 0; // default
|
channelSettings.tx_power = 0; // default
|
||||||
memcpy(&channelSettings.psk.bytes, defaultpsk, sizeof(channelSettings.psk));
|
uint8_t defaultpskIndex = 1;
|
||||||
channelSettings.psk.size = sizeof(defaultpsk);
|
channelSettings.psk.bytes[0] = defaultpskIndex;
|
||||||
strcpy(channelSettings.name, "Default");
|
channelSettings.psk.size = 1;
|
||||||
|
strcpy(channelSettings.name, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert "Default" to our new short representation
|
||||||
|
if(strcmp(channelSettings.name, "Default") == 0)
|
||||||
|
*channelSettings.name = '\0';
|
||||||
|
|
||||||
|
// Convert the short "" representation for Default into a usable string
|
||||||
|
channelName = channelSettings.name;
|
||||||
|
if(!*channelName) // emptystring
|
||||||
|
channelName = "Default";
|
||||||
|
|
||||||
|
// Convert any old usage of the defaultpsk into our new short representation.
|
||||||
|
if(channelSettings.psk.size == sizeof(defaultpsk) &&
|
||||||
|
memcmp(channelSettings.psk.bytes, defaultpsk, sizeof(defaultpsk)) == 0) {
|
||||||
|
*channelSettings.psk.bytes = 1;
|
||||||
|
channelSettings.psk.size = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert the short single byte variants of psk into variant that can be used more generally
|
||||||
|
memcpy(activePSK, channelSettings.psk.bytes, channelSettings.psk.size);
|
||||||
|
activePSKSize = channelSettings.psk.size;
|
||||||
|
if(activePSKSize == 1) {
|
||||||
|
uint8_t pskIndex = activePSK[0];
|
||||||
|
DEBUG_MSG("Expanding short PSK #%d\n", pskIndex);
|
||||||
|
if(pskIndex == 0)
|
||||||
|
activePSKSize = 0; // Turn off encryption
|
||||||
|
else {
|
||||||
|
memcpy(activePSK, defaultpsk, sizeof(defaultpsk));
|
||||||
|
activePSKSize = sizeof(defaultpsk);
|
||||||
|
// Bump up the last byte of PSK as needed
|
||||||
|
uint8_t *last = activePSK + sizeof(defaultpsk) - 1;
|
||||||
|
*last = *last + pskIndex - 1; // index of 1 means no change vs defaultPSK
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tell our crypto engine about the psk
|
// Tell our crypto engine about the psk
|
||||||
crypto->setKey(channelSettings.psk.size, channelSettings.psk.bytes);
|
crypto->setKey(activePSKSize, activePSK);
|
||||||
|
|
||||||
// temp hack for quicker testing
|
// temp hack for quicker testing
|
||||||
// devicestate.no_save = true;
|
// devicestate.no_save = true;
|
||||||
|
@ -13,6 +13,7 @@ extern MyNodeInfo &myNodeInfo;
|
|||||||
extern RadioConfig &radioConfig;
|
extern RadioConfig &radioConfig;
|
||||||
extern ChannelSettings &channelSettings;
|
extern ChannelSettings &channelSettings;
|
||||||
extern User &owner;
|
extern User &owner;
|
||||||
|
extern const char *channelName;
|
||||||
|
|
||||||
/// Given a node, return how many seconds in the past (vs now) that we last heard from it
|
/// Given a node, return how many seconds in the past (vs now) that we last heard from it
|
||||||
uint32_t sinceLastSeen(const NodeInfo *n);
|
uint32_t sinceLastSeen(const NodeInfo *n);
|
||||||
|
@ -262,10 +262,10 @@ void RadioInterface::applyModemConfig()
|
|||||||
|
|
||||||
// If user has manually specified a channel num, then use that, otherwise generate one by hashing the name
|
// If user has manually specified a channel num, then use that, otherwise generate one by hashing the name
|
||||||
int channel_num =
|
int channel_num =
|
||||||
(channelSettings.channel_num ? channelSettings.channel_num - 1 : hash(channelSettings.name)) % myRegion->numChannels;
|
(channelSettings.channel_num ? channelSettings.channel_num - 1 : hash(channelName)) % myRegion->numChannels;
|
||||||
freq = myRegion->freq + myRegion->spacing * channel_num;
|
freq = myRegion->freq + myRegion->spacing * channel_num;
|
||||||
|
|
||||||
DEBUG_MSG("Set radio: name=%s, config=%u, ch=%d, power=%d\n", channelSettings.name, channelSettings.modem_config, channel_num,
|
DEBUG_MSG("Set radio: name=%s, config=%u, ch=%d, power=%d\n", channelName, channelSettings.modem_config, channel_num,
|
||||||
power);
|
power);
|
||||||
DEBUG_MSG("Radio myRegion->freq: %f\n", myRegion->freq);
|
DEBUG_MSG("Radio myRegion->freq: %f\n", myRegion->freq);
|
||||||
DEBUG_MSG("Radio myRegion->spacing: %f\n", myRegion->spacing);
|
DEBUG_MSG("Radio myRegion->spacing: %f\n", myRegion->spacing);
|
||||||
|
Loading…
Reference in New Issue
Block a user