Skip to content

Commit 8f75b28

Browse files
authored
Merge branch 'master' into overheard-hoptimisation
2 parents d97d046 + f39a9c5 commit 8f75b28

23 files changed

+862
-568
lines changed

.github/workflows/build_docker.yml

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Build Docker
2+
3+
on: workflow_call
4+
5+
permissions:
6+
contents: write
7+
packages: write
8+
9+
jobs:
10+
build-native:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Install libs needed for native build
14+
shell: bash
15+
run: |
16+
sudo apt-get update --fix-missing
17+
sudo apt-get install -y libbluetooth-dev libgpiod-dev libyaml-cpp-dev openssl libssl-dev libulfius-dev liborcania-dev libusb-1.0-0-dev
18+
19+
- name: Checkout code
20+
uses: actions/checkout@v4
21+
with:
22+
submodules: recursive
23+
ref: ${{github.event.pull_request.head.ref}}
24+
repository: ${{github.event.pull_request.head.repo.full_name}}
25+
26+
- name: Upgrade python tools
27+
shell: bash
28+
run: |
29+
python -m pip install --upgrade pip
30+
pip install -U platformio adafruit-nrfutil
31+
pip install -U meshtastic --pre
32+
33+
- name: Upgrade platformio
34+
shell: bash
35+
run: |
36+
pio upgrade
37+
38+
- name: Build Native
39+
run: bin/build-native.sh
40+
41+
- name: Get release version string
42+
run: echo "version=$(./bin/buildinfo.py long)" >> $GITHUB_OUTPUT
43+
id: version
44+
45+
- name: Docker login
46+
if: ${{ github.event_name != 'pull_request_target' && github.event_name != 'pull_request' }}
47+
uses: docker/login-action@v3
48+
with:
49+
username: meshtastic
50+
password: ${{ secrets.DOCKER_FIRMWARE_TOKEN }}
51+
52+
- name: Docker setup
53+
if: ${{ github.event_name != 'pull_request_target' && github.event_name != 'pull_request' }}
54+
uses: docker/setup-buildx-action@v3
55+
56+
- name: Docker build and push tagged versions
57+
if: ${{ github.event_name == 'workflow_dispatch' }}
58+
uses: docker/build-push-action@v6
59+
with:
60+
context: .
61+
file: ./Dockerfile
62+
push: true
63+
tags: meshtastic/meshtasticd:${{ steps.version.outputs.version }}
64+
65+
- name: Docker build and push
66+
if: ${{ github.ref == 'refs/heads/master' && github.event_name != 'pull_request_target' && github.event_name != 'pull_request' }}
67+
uses: docker/build-push-action@v6
68+
with:
69+
context: .
70+
file: ./Dockerfile
71+
push: true
72+
tags: meshtastic/meshtasticd:latest

.github/workflows/build_native.yml

-31
Original file line numberDiff line numberDiff line change
@@ -50,34 +50,3 @@ jobs:
5050
path: |
5151
release/meshtasticd_linux_x86_64
5252
bin/config-dist.yaml
53-
54-
- name: Docker login
55-
if: ${{ github.event_name != 'pull_request_target' && github.event_name != 'pull_request' }}
56-
run: |
57-
echo ${{ secrets.DOCKER_FIRMWARE_TOKEN }} | docker login -u meshtastic --password-stdin
58-
continue-on-error: true
59-
60-
- name: Docker setup
61-
if: ${{ github.event_name != 'pull_request_target' && github.event_name != 'pull_request' }}
62-
continue-on-error: true
63-
uses: docker/setup-buildx-action@v3
64-
65-
- name: Docker build and push tagged versions
66-
if: ${{ github.event_name == 'workflow_dispatch' }}
67-
continue-on-error: true
68-
uses: docker/build-push-action@v6
69-
with:
70-
context: .
71-
file: ./Dockerfile
72-
push: true
73-
tags: meshtastic/device-simulator:${{ steps.version.outputs.version }}
74-
75-
- name: Docker build and push
76-
if: ${{ github.ref == 'refs/heads/master' && github.event_name != 'pull_request_target' && github.event_name != 'pull_request' }}
77-
continue-on-error: true
78-
uses: docker/build-push-action@v6
79-
with:
80-
context: .
81-
file: ./Dockerfile
82-
push: true
83-
tags: meshtastic/device-simulator:latest

.github/workflows/main_matrix.yml

+5
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ jobs:
137137
package-native:
138138
uses: ./.github/workflows/package_amd64.yml
139139

140+
build-docker:
141+
if: ${{ github.event_name == 'workflow_dispatch' }}
142+
uses: ./.github/workflows/build_docker.yml
143+
secrets: inherit
144+
140145
after-checks:
141146
runs-on: ubuntu-latest
142147
if: ${{ github.event_name != 'workflow_dispatch' }}

arch/portduino/portduino.ini

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ lib_deps =
2626
${radiolib_base.lib_deps}
2727
rweather/Crypto@^0.4.0
2828
https://github.com/lovyan03/LovyanGFX.git#1401c28a47646fe00538d487adcb2eb3c72de805
29+
https://github.com/pine64/libch341-spi-userspace#8695637adeabf5abf5601d8e82cb0ba19ce9ec46
2930

3031
build_flags =
3132
${arduino_base.build_flags}
@@ -36,4 +37,4 @@ build_flags =
3637
-lstdc++fs
3738
-lbluetooth
3839
-lgpiod
39-
-lyaml-cpp
40+
-lyaml-cpp

bin/config-dist.yaml

-9
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,6 @@ Lora:
1212
# IRQ: 17
1313
# Reset: 22
1414

15-
# Module: sx1262 # pinedio
16-
# CS: 0
17-
# IRQ: 10
18-
# Busy: 11
19-
# DIO2_AS_RF_SWITCH: true
20-
# spidev: spidev0.1
21-
2215
# Module: RF95 # Adafruit RFM9x
2316
# Reset: 25
2417
# CS: 7
@@ -50,8 +43,6 @@ Lora:
5043
# TXen: x # TX and RX enable pins
5144
# RXen: x
5245

53-
# ch341_quirk: true # Uncomment this to use the chunked SPI transfer that seems to fix the ch341
54-
5546
# spiSpeed: 2000000
5647

5748
### Set gpio chip to use in /dev/. Defaults to 0.

bin/config.d/lora-meshstick-1262.yaml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Lora:
2+
Module: sx1262
3+
CS: 0
4+
IRQ: 6
5+
Reset: 2
6+
Busy: 4
7+
spidev: ch341
8+
DIO3_TCXO_VOLTAGE: true
9+
# USB_Serialnum: 12345678
10+
USB_PID: 0x5512
11+
USB_VID: 0x1A86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Lora:
2+
Module: sx1262
3+
CS: 0
4+
IRQ: 10
5+
spidev: ch341

src/detect/ScanI2C.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ class ScanI2C
6363
MAX30102,
6464
TPS65233,
6565
MPR121KB,
66-
CGRADSENS
66+
CGRADSENS,
67+
INA226
6768
} DeviceType;
6869

6970
// typedef uint8_t DeviceAddress;
@@ -127,4 +128,4 @@ class ScanI2C
127128

128129
private:
129130
bool shouldSuppressScreen = false;
130-
};
131+
};

src/detect/ScanI2CTwoWire.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,16 @@ void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address, uint8_t asize)
250250
registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0xFE), 2);
251251
LOG_DEBUG("Register MFG_UID: 0x%x", registerValue);
252252
if (registerValue == 0x5449) {
253-
logFoundDevice("INA260", (uint8_t)addr.address);
254-
type = INA260;
253+
registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0xFF), 2);
254+
LOG_DEBUG("Register DIE_UID: 0x%x", registerValue);
255+
256+
if (registerValue == 0x2260) {
257+
logFoundDevice("INA226", (uint8_t)addr.address);
258+
type = INA226;
259+
} else {
260+
logFoundDevice("INA260", (uint8_t)addr.address);
261+
type = INA260;
262+
}
255263
} else { // Assume INA219 if INA260 ID is not found
256264
logFoundDevice("INA219", (uint8_t)addr.address);
257265
type = INA219;

src/main.cpp

+31-18
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ NRF52Bluetooth *nrf52Bluetooth = nullptr;
9090
#include "linux/LinuxHardwareI2C.h"
9191
#include "mesh/raspihttp/PiWebServer.h"
9292
#include "platform/portduino/PortduinoGlue.h"
93+
#include "platform/portduino/USBHal.h"
9394
#include <fstream>
9495
#include <iostream>
9596
#include <string>
@@ -213,6 +214,9 @@ static OSThread *powerFSMthread;
213214
static OSThread *ambientLightingThread;
214215

215216
RadioInterface *rIf = NULL;
217+
#ifdef ARCH_PORTDUINO
218+
RadioLibHal *RadioLibHAL = NULL;
219+
#endif
216220

217221
/**
218222
* Some platforms (nrf52) might provide an alterate version that suppresses calling delay from sleep.
@@ -237,6 +241,17 @@ void printInfo()
237241
#ifndef PIO_UNIT_TESTING
238242
void setup()
239243
{
244+
#if defined(T_DECK)
245+
// GPIO10 manages all peripheral power supplies
246+
// Turn on peripheral power immediately after MUC starts.
247+
// If some boards are turned on late, ESP32 will reset due to low voltage.
248+
// ESP32-C3(Keyboard) , MAX98357A(Audio Power Amplifier) ,
249+
// TF Card , Display backlight(AW9364DNR) , AN48841B(Trackball) , ES7210(Decoder)
250+
pinMode(KB_POWERON, OUTPUT);
251+
digitalWrite(KB_POWERON, HIGH);
252+
delay(100);
253+
#endif
254+
240255
concurrency::hasBeenSetup = true;
241256
#if ARCH_PORTDUINO
242257
SPISettings spiSettings(settingsMap[spiSpeed], MSBFIRST, SPI_MODE0);
@@ -409,15 +424,6 @@ void setup()
409424
digitalWrite(AQ_SET_PIN, HIGH);
410425
#endif
411426

412-
#if defined(T_DECK)
413-
// enable keyboard
414-
pinMode(KB_POWERON, OUTPUT);
415-
digitalWrite(KB_POWERON, HIGH);
416-
// There needs to be a delay after power on, give LILYGO-KEYBOARD some startup time
417-
// otherwise keyboard and touch screen will not work
418-
delay(200);
419-
#endif
420-
421427
// Currently only the tbeam has a PMU
422428
// PMU initialization needs to be placed before i2c scanning
423429
power = new Power();
@@ -573,6 +579,7 @@ void setup()
573579
scannerToSensorsMap(i2cScanner, ScanI2C::DeviceType::BMP_3XX, meshtastic_TelemetrySensorType_BMP3XX);
574580
scannerToSensorsMap(i2cScanner, ScanI2C::DeviceType::BMP_085, meshtastic_TelemetrySensorType_BMP085);
575581
scannerToSensorsMap(i2cScanner, ScanI2C::DeviceType::INA260, meshtastic_TelemetrySensorType_INA260);
582+
scannerToSensorsMap(i2cScanner, ScanI2C::DeviceType::INA226, meshtastic_TelemetrySensorType_INA226);
576583
scannerToSensorsMap(i2cScanner, ScanI2C::DeviceType::INA219, meshtastic_TelemetrySensorType_INA219);
577584
scannerToSensorsMap(i2cScanner, ScanI2C::DeviceType::INA3221, meshtastic_TelemetrySensorType_INA3221);
578585
scannerToSensorsMap(i2cScanner, ScanI2C::DeviceType::MAX17048, meshtastic_TelemetrySensorType_MAX17048);
@@ -703,12 +710,16 @@ void setup()
703710
pinMode(LORA_CS, OUTPUT);
704711
digitalWrite(LORA_CS, HIGH);
705712
SPI1.begin(false);
706-
#else // HW_SPI1_DEVICE
713+
#else // HW_SPI1_DEVICE
707714
SPI.setSCK(LORA_SCK);
708715
SPI.setTX(LORA_MOSI);
709716
SPI.setRX(LORA_MISO);
710717
SPI.begin(false);
711-
#endif // HW_SPI1_DEVICE
718+
#endif // HW_SPI1_DEVICE
719+
#elif ARCH_PORTDUINO
720+
if (settingsStrings[spidev] != "ch341") {
721+
SPI.begin();
722+
}
712723
#elif !defined(ARCH_ESP32) // ARCH_RP2040
713724
SPI.begin();
714725
#else
@@ -814,8 +825,11 @@ void setup()
814825
if (settingsMap[use_sx1262]) {
815826
if (!rIf) {
816827
LOG_DEBUG("Activate sx1262 radio on SPI port %s", settingsStrings[spidev].c_str());
817-
LockingArduinoHal *RadioLibHAL =
818-
new LockingArduinoHal(SPI, spiSettings, (settingsMap[ch341Quirk] ? settingsMap[busy] : RADIOLIB_NC));
828+
if (settingsStrings[spidev] == "ch341") {
829+
RadioLibHAL = ch341Hal;
830+
} else {
831+
RadioLibHAL = new LockingArduinoHal(SPI, spiSettings);
832+
}
819833
rIf = new SX1262Interface((LockingArduinoHal *)RadioLibHAL, settingsMap[cs], settingsMap[irq], settingsMap[reset],
820834
settingsMap[busy]);
821835
if (!rIf->init()) {
@@ -829,8 +843,7 @@ void setup()
829843
} else if (settingsMap[use_rf95]) {
830844
if (!rIf) {
831845
LOG_DEBUG("Activate rf95 radio on SPI port %s", settingsStrings[spidev].c_str());
832-
LockingArduinoHal *RadioLibHAL =
833-
new LockingArduinoHal(SPI, spiSettings, (settingsMap[ch341Quirk] ? settingsMap[busy] : RADIOLIB_NC));
846+
RadioLibHAL = new LockingArduinoHal(SPI, spiSettings);
834847
rIf = new RF95Interface((LockingArduinoHal *)RadioLibHAL, settingsMap[cs], settingsMap[irq], settingsMap[reset],
835848
settingsMap[busy]);
836849
if (!rIf->init()) {
@@ -845,7 +858,7 @@ void setup()
845858
} else if (settingsMap[use_sx1280]) {
846859
if (!rIf) {
847860
LOG_DEBUG("Activate sx1280 radio on SPI port %s", settingsStrings[spidev].c_str());
848-
LockingArduinoHal *RadioLibHAL = new LockingArduinoHal(SPI, spiSettings);
861+
RadioLibHAL = new LockingArduinoHal(SPI, spiSettings);
849862
rIf = new SX1280Interface((LockingArduinoHal *)RadioLibHAL, settingsMap[cs], settingsMap[irq], settingsMap[reset],
850863
settingsMap[busy]);
851864
if (!rIf->init()) {
@@ -905,7 +918,7 @@ void setup()
905918
} else if (settingsMap[use_sx1268]) {
906919
if (!rIf) {
907920
LOG_DEBUG("Activate sx1268 radio on SPI port %s", settingsStrings[spidev].c_str());
908-
LockingArduinoHal *RadioLibHAL = new LockingArduinoHal(SPI, spiSettings);
921+
RadioLibHAL = new LockingArduinoHal(SPI, spiSettings);
909922
rIf = new SX1268Interface((LockingArduinoHal *)RadioLibHAL, settingsMap[cs], settingsMap[irq], settingsMap[reset],
910923
settingsMap[busy]);
911924
if (!rIf->init()) {
@@ -1262,4 +1275,4 @@ void loop()
12621275
mainDelay.delay(delayMsec);
12631276
}
12641277
}
1265-
#endif
1278+
#endif

src/mesh/CryptoEngine.cpp

+17-7
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,16 @@ void CryptoEngine::clearKeys()
5858
* Encrypt a packet's payload using a key generated with Curve25519 and SHA256
5959
* for a specific node.
6060
*
61-
* @param bytes is updated in place
61+
* @param toNode The MeshPacket `to` field.
62+
* @param fromNode The MeshPacket `from` field.
63+
* @param remotePublic The remote node's Curve25519 public key.
64+
* @param packetId The MeshPacket `id` field.
65+
* @param numBytes Number of bytes of plaintext in the bytes buffer.
66+
* @param bytes Buffer containing plaintext input.
67+
* @param bytesOut Output buffer to be populated with encrypted ciphertext.
6268
*/
6369
bool CryptoEngine::encryptCurve25519(uint32_t toNode, uint32_t fromNode, meshtastic_UserLite_public_key_t remotePublic,
64-
uint64_t packetNum, size_t numBytes, uint8_t *bytes, uint8_t *bytesOut)
70+
uint64_t packetNum, size_t numBytes, const uint8_t *bytes, uint8_t *bytesOut)
6571
{
6672
uint8_t *auth;
6773
long extraNonceTmp = random();
@@ -93,14 +99,18 @@ bool CryptoEngine::encryptCurve25519(uint32_t toNode, uint32_t fromNode, meshtas
9399
* Decrypt a packet's payload using a key generated with Curve25519 and SHA256
94100
* for a specific node.
95101
*
96-
* @param bytes is updated in place
102+
* @param fromNode The MeshPacket `from` field.
103+
* @param remotePublic The remote node's Curve25519 public key.
104+
* @param packetId The MeshPacket `id` field.
105+
* @param numBytes Number of bytes of ciphertext in the bytes buffer.
106+
* @param bytes Buffer containing ciphertext input.
107+
* @param bytesOut Output buffer to be populated with decrypted plaintext.
97108
*/
98109
bool CryptoEngine::decryptCurve25519(uint32_t fromNode, meshtastic_UserLite_public_key_t remotePublic, uint64_t packetNum,
99-
size_t numBytes, uint8_t *bytes, uint8_t *bytesOut)
110+
size_t numBytes, const uint8_t *bytes, uint8_t *bytesOut)
100111
{
101-
uint8_t *auth; // set to last 8 bytes of text?
102-
uint32_t extraNonce; // pointer was not really used
103-
auth = bytes + numBytes - 12;
112+
const uint8_t *auth = bytes + numBytes - 12; // set to last 8 bytes of text?
113+
uint32_t extraNonce; // pointer was not really used
104114
memcpy(&extraNonce, auth + 8,
105115
sizeof(uint32_t)); // do not use dereference on potential non aligned pointers : (uint32_t *)(auth + 8);
106116
LOG_INFO("Random nonce value: %d", extraNonce);

src/mesh/CryptoEngine.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ class CryptoEngine
4040
void clearKeys();
4141
void setDHPrivateKey(uint8_t *_private_key);
4242
virtual bool encryptCurve25519(uint32_t toNode, uint32_t fromNode, meshtastic_UserLite_public_key_t remotePublic,
43-
uint64_t packetNum, size_t numBytes, uint8_t *bytes, uint8_t *bytesOut);
43+
uint64_t packetNum, size_t numBytes, const uint8_t *bytes, uint8_t *bytesOut);
4444
virtual bool decryptCurve25519(uint32_t fromNode, meshtastic_UserLite_public_key_t remotePublic, uint64_t packetNum,
45-
size_t numBytes, uint8_t *bytes, uint8_t *bytesOut);
45+
size_t numBytes, const uint8_t *bytes, uint8_t *bytesOut);
4646
virtual bool setDHPublicKey(uint8_t *publicKey);
4747
virtual void hash(uint8_t *bytes, size_t numBytes);
4848

0 commit comments

Comments
 (0)