mirror of
https://github.com/meshtastic/firmware.git
synced 2025-08-17 18:53:30 +00:00
begin restricting admin ops to the admin channel
This commit is contained in:
parent
68781492ad
commit
959b540c02
@ -1,4 +1,5 @@
|
|||||||
#include "MeshPlugin.h"
|
#include "MeshPlugin.h"
|
||||||
|
#include "Channels.h"
|
||||||
#include "MeshService.h"
|
#include "MeshService.h"
|
||||||
#include "NodeDB.h"
|
#include "NodeDB.h"
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
@ -46,8 +47,15 @@ void MeshPlugin::callPlugins(const MeshPacket &mp)
|
|||||||
|
|
||||||
pi.currentRequest = ∓
|
pi.currentRequest = ∓
|
||||||
|
|
||||||
// We only call plugins that are interested in the packet (and the message is destined to us or we are promiscious)
|
/// received channel
|
||||||
bool wantsPacket = (pi.isPromiscuous || toUs) && pi.wantPacket(&mp);
|
auto ch = channels.getByIndex(mp.channel);
|
||||||
|
assert(ch.has_settings);
|
||||||
|
|
||||||
|
/// Is the channel this packet arrived on acceptable? (security check)
|
||||||
|
bool rxChannelOk = !pi.boundChannel || (mp.from == 0) || (strcmp(ch.settings.name, pi.boundChannel) == 0);
|
||||||
|
|
||||||
|
/// We only call plugins that are interested in the packet (and the message is destined to us or we are promiscious)
|
||||||
|
bool wantsPacket = rxChannelOk && (pi.isPromiscuous || toUs) && pi.wantPacket(&mp);
|
||||||
// DEBUG_MSG("Plugin %s wantsPacket=%d\n", pi.name, wantsPacket);
|
// DEBUG_MSG("Plugin %s wantsPacket=%d\n", pi.name, wantsPacket);
|
||||||
if (wantsPacket) {
|
if (wantsPacket) {
|
||||||
pluginFound = true;
|
pluginFound = true;
|
||||||
@ -109,6 +117,7 @@ void setReplyTo(MeshPacket *p, const MeshPacket &to)
|
|||||||
{
|
{
|
||||||
assert(p->which_payloadVariant == MeshPacket_decoded_tag); // Should already be set by now
|
assert(p->which_payloadVariant == MeshPacket_decoded_tag); // Should already be set by now
|
||||||
p->to = getFrom(&to);
|
p->to = getFrom(&to);
|
||||||
|
p->channel = to.channel; // Use the same channel that the request came in on
|
||||||
|
|
||||||
// No need for an ack if we are just delivering locally (it just generates an ignored ack)
|
// No need for an ack if we are just delivering locally (it just generates an ignored ack)
|
||||||
p->want_ack = (to.from != 0) ? to.want_ack : false;
|
p->want_ack = (to.from != 0) ? to.want_ack : false;
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "mesh/MeshTypes.h"
|
#include "mesh/MeshTypes.h"
|
||||||
#include <vector>
|
|
||||||
#include <OLEDDisplay.h>
|
#include <OLEDDisplay.h>
|
||||||
#include <OLEDDisplayUi.h>
|
#include <OLEDDisplayUi.h>
|
||||||
|
#include <vector>
|
||||||
/** A baseclass for any mesh "plugin".
|
/** A baseclass for any mesh "plugin".
|
||||||
*
|
*
|
||||||
* A plugin allows you to add new features to meshtastic device code, without needing to know messaging details.
|
* A plugin allows you to add new features to meshtastic device code, without needing to know messaging details.
|
||||||
@ -37,12 +37,20 @@ 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 recipient)
|
/* Most plugins only care about packets that are destined for their node (i.e. broadcasts or has their node as the specific
|
||||||
But some plugs might want to 'sniff' packets that are merely being routed (passing through the current node). Those plugins can set this to
|
recipient) But some plugs might want to 'sniff' packets that are merely being routed (passing through the current node). Those
|
||||||
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;
|
||||||
|
|
||||||
|
/** 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
|
||||||
|
* are allowed on any channel (this lets the local user do anything).
|
||||||
|
*
|
||||||
|
* We will send responses on the same channel that the request arrived on.
|
||||||
|
*/
|
||||||
|
const char *boundChannel = NULL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If this plugin is currently handling a request currentRequest will be preset
|
* If this plugin is currently handling a request currentRequest will be preset
|
||||||
* to the packet with the request. This is mostly useful for reply handlers.
|
* to the packet with the request. This is mostly useful for reply handlers.
|
||||||
@ -78,10 +86,7 @@ class MeshPlugin
|
|||||||
*/
|
*/
|
||||||
virtual bool wantUIFrame() { return false; }
|
virtual bool wantUIFrame() { return false; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If any of the current chain of plugins has already sent a reply, it will be here. This is useful to allow
|
* If any of the current chain of plugins has already sent a reply, it will be here. This is useful to allow
|
||||||
* the RoutingPlugin to avoid sending redundant acks
|
* the RoutingPlugin to avoid sending redundant acks
|
||||||
|
@ -8,7 +8,8 @@
|
|||||||
|
|
||||||
AdminPlugin *adminPlugin;
|
AdminPlugin *adminPlugin;
|
||||||
|
|
||||||
void AdminPlugin::handleGetChannel(const MeshPacket &req, uint32_t channelIndex) {
|
void AdminPlugin::handleGetChannel(const MeshPacket &req, uint32_t channelIndex)
|
||||||
|
{
|
||||||
if (req.decoded.want_response) {
|
if (req.decoded.want_response) {
|
||||||
// We create the reply here
|
// We create the reply here
|
||||||
AdminMessage r = AdminMessage_init_default;
|
AdminMessage r = AdminMessage_init_default;
|
||||||
@ -121,5 +122,6 @@ MeshPacket *AdminPlugin::allocReply()
|
|||||||
|
|
||||||
AdminPlugin::AdminPlugin() : ProtobufPlugin("Admin", PortNum_ADMIN_APP, AdminMessage_fields)
|
AdminPlugin::AdminPlugin() : ProtobufPlugin("Admin", PortNum_ADMIN_APP, AdminMessage_fields)
|
||||||
{
|
{
|
||||||
// FIXME, restrict to the admin channel for rx
|
// restrict to the admin channel for rx
|
||||||
|
boundChannel = "admin";
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user