mirror of
https://github.com/meshtastic/firmware.git
synced 2025-04-26 18:09:04 +00:00
allow passing even encrypted packets through the plugins
This commit is contained in:
parent
50a69d77e6
commit
3cd64bb8b5
@ -70,7 +70,8 @@ void MeshPlugin::callPlugins(const MeshPacket &mp)
|
|||||||
// DEBUG_MSG("In call plugins\n");
|
// DEBUG_MSG("In call plugins\n");
|
||||||
bool pluginFound = false;
|
bool pluginFound = false;
|
||||||
|
|
||||||
assert(mp.which_payloadVariant == MeshPacket_decoded_tag); // I think we are guarnteed the packet is decoded by this point?
|
// We now allow **encrypted** packets to pass through the plugins
|
||||||
|
bool isDecoded = mp.which_payloadVariant == MeshPacket_decoded_tag;
|
||||||
|
|
||||||
currentReply = NULL; // No reply yet
|
currentReply = NULL; // No reply yet
|
||||||
|
|
||||||
@ -82,19 +83,19 @@ void MeshPlugin::callPlugins(const MeshPacket &mp)
|
|||||||
|
|
||||||
pi.currentRequest = ∓
|
pi.currentRequest = ∓
|
||||||
|
|
||||||
/// received channel
|
|
||||||
auto ch = channels.getByIndex(mp.channel);
|
|
||||||
assert(ch.has_settings);
|
|
||||||
|
|
||||||
/// We only call plugins that are interested in the packet (and the message is destined to us or we are promiscious)
|
/// We only call plugins that are interested in the packet (and the message is destined to us or we are promiscious)
|
||||||
bool wantsPacket = (pi.isPromiscuous || toUs) && pi.wantPacket(&mp);
|
bool wantsPacket = (isDecoded || pi.encryptedOk) && (pi.isPromiscuous || toUs) && pi.wantPacket(&mp);
|
||||||
|
|
||||||
if (wantsPacket) {
|
if (wantsPacket) {
|
||||||
// DEBUG_MSG("Plugin %s wantsPacket=%d\n", pi.name, wantsPacket);
|
// DEBUG_MSG("Plugin %s wantsPacket=%d\n", pi.name, wantsPacket);
|
||||||
pluginFound = true;
|
pluginFound = true;
|
||||||
|
|
||||||
|
/// received channel (or NULL if not decoded)
|
||||||
|
Channel *ch = isDecoded ? &channels.getByIndex(mp.channel) : NULL;
|
||||||
|
|
||||||
/// Is the channel this packet arrived on acceptable? (security check)
|
/// Is the channel this packet arrived on acceptable? (security check)
|
||||||
bool rxChannelOk = !pi.boundChannel || (mp.from == 0) || (strcmp(ch.settings.name, pi.boundChannel) == 0);
|
/// Note: we can't know channel names for encrypted packets, so those are NEVER sent to boundChannel plugins
|
||||||
|
bool rxChannelOk = !pi.boundChannel || (ch && ((mp.from == 0) || (strcmp(ch->settings.name, pi.boundChannel) == 0)));
|
||||||
|
|
||||||
if (!rxChannelOk) {
|
if (!rxChannelOk) {
|
||||||
// no one should have already replied!
|
// no one should have already replied!
|
||||||
|
@ -42,12 +42,16 @@ class MeshPlugin
|
|||||||
protected:
|
protected:
|
||||||
const char *name;
|
const char *name;
|
||||||
|
|
||||||
/* Most plugins only care about packets that are destined for their node (i.e. broadcasts or has their node as the specific
|
/** Most plugins only care about packets that are destined for their node (i.e. broadcasts or has their node as the specific
|
||||||
recipient) But some plugs might want to 'sniff' packets that are merely being routed (passing through the current node). Those
|
recipient) But some plugs might want to 'sniff' packets that are merely being routed (passing through the current node). Those
|
||||||
plugins can set this to true and their handleReceived() will be called for every packet.
|
plugins can set this to true and their handleReceived() will be called for every packet.
|
||||||
*/
|
*/
|
||||||
bool isPromiscuous = false;
|
bool isPromiscuous = false;
|
||||||
|
|
||||||
|
/** Most plugins only understand decrypted packets. For plugins that also want to see encrypted packets, they should set this
|
||||||
|
* flag */
|
||||||
|
bool encryptedOk = false;
|
||||||
|
|
||||||
/** If a bound channel name is set, we will only accept received packets that come in on that channel.
|
/** If a bound channel name is set, we will only accept received packets that come in on that channel.
|
||||||
* A special exception (FIXME, not sure if this is a good idea) - packets that arrive on the local interface
|
* A special exception (FIXME, not sure if this is a good idea) - packets that arrive on the local interface
|
||||||
* are allowed on any channel (this lets the local user do anything).
|
* are allowed on any channel (this lets the local user do anything).
|
||||||
|
@ -22,7 +22,6 @@ template <class T> class ProtobufPlugin : protected SinglePortPlugin
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle a received message, the data field in the message is already decoded and is provided
|
* Handle a received message, the data field in the message is already decoded and is provided
|
||||||
*
|
*
|
||||||
@ -58,11 +57,12 @@ template <class T> class ProtobufPlugin : protected SinglePortPlugin
|
|||||||
// it would be better to update even if the message was destined to others.
|
// it would be better to update even if the message was destined to others.
|
||||||
|
|
||||||
auto &p = mp.decoded;
|
auto &p = mp.decoded;
|
||||||
DEBUG_MSG("Received %s from=0x%0x, id=0x%x, portnum=%d, payloadlen=%d\n", name, mp.from, mp.id, p.portnum, p.payload.size);
|
DEBUG_MSG("Received %s from=0x%0x, id=0x%x, portnum=%d, payloadlen=%d\n", name, mp.from, mp.id, p.portnum,
|
||||||
|
p.payload.size);
|
||||||
|
|
||||||
T scratch;
|
T scratch;
|
||||||
T *decoded = NULL;
|
T *decoded = NULL;
|
||||||
if(mp.decoded.portnum == ourPortNum) {
|
if (mp.which_payloadVariant == MeshPacket_decoded_tag && mp.decoded.portnum == ourPortNum) {
|
||||||
memset(&scratch, 0, sizeof(scratch));
|
memset(&scratch, 0, sizeof(scratch));
|
||||||
if (pb_decode_from_bytes(p.payload.bytes, p.payload.size, fields, &scratch))
|
if (pb_decode_from_bytes(p.payload.bytes, p.payload.size, fields, &scratch))
|
||||||
decoded = &scratch;
|
decoded = &scratch;
|
||||||
|
@ -304,13 +304,12 @@ void Router::handleReceived(MeshPacket *p)
|
|||||||
if (decoded) {
|
if (decoded) {
|
||||||
// parsing was successful, queue for our recipient
|
// parsing was successful, queue for our recipient
|
||||||
printPacket("handleReceived", p);
|
printPacket("handleReceived", p);
|
||||||
|
|
||||||
// call any promiscious plugins here, make a (non promisiocous) plugin for forwarding messages to phone api
|
|
||||||
// sniffReceived(p);
|
|
||||||
MeshPlugin::callPlugins(*p);
|
|
||||||
} else {
|
} else {
|
||||||
DEBUG_MSG("packet decoding failed\n");
|
printPacket("packet decoding failed (no PSK?)", p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// call plugins here
|
||||||
|
MeshPlugin::callPlugins(*p);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Router::perhapsHandleReceived(MeshPacket *p)
|
void Router::perhapsHandleReceived(MeshPacket *p)
|
||||||
|
Loading…
Reference in New Issue
Block a user