mirror of
https://github.com/meshtastic/firmware.git
synced 2026-11-07 23:04:49 -05:00
36ca64af164e3af771b1ae5e9380fcd5cee03280
A phone can already reach a node's phone API over BLE, but it cannot be a node on the mesh through that link: the phone API carries commands and FromRadio state, not mesh frames. This adds a second GATT service, the mesh-peer service, on which a client library (node-transport-ble-gatt) exchanges whole encrypted MeshPackets with the node - the SIG Mesh "GATT proxy" role. The node stays the GATT server; the phone is a central that subscribes to the mesh characteristic and writes fragments to it. BLEGattMeshHandler is the platform-neutral half and holds everything the client library speaks, so the native suite covers it: the fragment framing ([version][id][index][total][payload], one ATT value per fragment), bounded reassembly (per-peer in-flight limit, per-table peer limit, expiry, so a hostile writer cannot fill memory), the ingress guards shared with the UDP transport (no sender, our own node number, out-of-range hop counts, local-only flags cleared), a relay exclusion so a packet is never written back to the peer that delivered it unless that peer originated it (the echo is its only implicit ack on a point-to-point bearer), the HELLO link-control frame that names a node on its GATT links so a node reached both ways can elect one link, and a liveness probe for a link this node dialled. No platform here dials yet, so the probe and shed hooks keep their base-class defaults; the dial-out half is a later change. It registers as a PostEncode transport, gated on ProtocolFlags.BLE_GATT_PEER, and tags its arrivals TRANSPORT_BLE_GATT. NRF52BLEGattMesh is the Bluefruit half: the service and characteristic, CCCD tracking (a link becomes a mesh peer when it subscribes), a write queue from Bluefruit's callback task to the main-task pump, per-connection MTU chunking, and re-arming the connectable advertisement while a peripheral slot is free, which Bluefruit only does by itself once no link is left. Bluefruit.begin(2, 0): two peripheral links, the phone and one mesh peer, no central. NRF52Bluetooth has to stop assuming one link. The phone is whichever link uses the phone API, not the most recent connect, so notePhoneLink() learns it from the first phone-API access and only that link's drop closes the phone session; fromNum and logRadio notify that handle explicitly rather than Bluefruit's default. The mesh-peer UUID rides in the scan response in place of the TX power entry, since S140 has one advertising set. The nanopb enums come from the protobufs branch this submodule now points at; nothing under src/mesh/generated/ is committed, the regen workflow supplies it once that PR merges (bin/regen-protos.sh locally until then). Native tests in test_ble_gatt_mesh, built by the portduino env's new HAS_BLE_GATT_MESH flag: framing and its bounds, reassembly, every ingress guard, per-peer fragmentation, the relay exclusion and its originator exception, the bounded TX ring and busy-stack retry, the greeting, the election, and the probe timings.
Overview
This repository contains the official device firmware for Meshtastic, an open-source LoRa mesh networking project designed for long-range, low-power communication without relying on internet or cellular infrastructure. The firmware supports various hardware platforms, including ESP32, nRF52, RP2040/RP2350, and Linux-based devices.
Meshtastic enables text messaging, location sharing, and telemetry over a decentralized mesh network, making it ideal for outdoor adventures, emergency preparedness, and remote operations.
Get Started
- 🔧 Building Instructions - Learn how to compile the firmware from source.
- ⚡ Flashing Instructions - Install or update the firmware on your device.
Join our community and help improve Meshtastic! 🚀
Stats
Languages
C++
73.6%
C
21.7%
Python
2.6%
Shell
1.5%
Batchfile
0.2%
Other
0.2%
