Skip to content

Commit b6110ee

Browse files
author
Scott Powell
committed
* new req/resp (after login): REQ_TYPE_GET_OWNER_INFO (includes firmware-ver)
* ANON_REQ_TYPE_OWNER, firmware-ver removed (security exploit) * ANON_REQ_TYPE_BASIC, formware-ver removed, just remote clock + some 'feature' bits * CTL_TYPE_NODE_DISCOVER_REQ now ingored if 'repeat off' has been set
1 parent 4e4f6d9 commit b6110ee

File tree

4 files changed

+32
-18
lines changed

4 files changed

+32
-18
lines changed

examples/simple_repeater/MyMesh.cpp

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,13 @@
4848
#define REQ_TYPE_GET_TELEMETRY_DATA 0x03
4949
#define REQ_TYPE_GET_ACCESS_LIST 0x05
5050
#define REQ_TYPE_GET_NEIGHBOURS 0x06
51+
#define REQ_TYPE_GET_OWNER_INFO 0x07
5152

5253
#define RESP_SERVER_LOGIN_OK 0 // response to ANON_REQ
5354

5455
#define ANON_REQ_TYPE_REGIONS 0x01
55-
#define ANON_REQ_TYPE_VER_OWNER 0x02
56-
#define ANON_REQ_TYPE_VER 0x03
56+
#define ANON_REQ_TYPE_OWNER 0x02
57+
#define ANON_REQ_TYPE_BASIC 0x03 // just remote clock
5758

5859
#define CLI_REPLY_DELAY_MILLIS 600
5960

@@ -159,7 +160,7 @@ uint8_t MyMesh::handleAnonRegionsReq(const mesh::Identity& sender, uint32_t send
159160
return 0;
160161
}
161162

162-
uint8_t MyMesh::handleAnonVerOwnerReq(const mesh::Identity& sender, uint32_t sender_timestamp, const uint8_t* data) {
163+
uint8_t MyMesh::handleAnonOwnerReq(const mesh::Identity& sender, uint32_t sender_timestamp, const uint8_t* data) {
163164
if (anon_limiter.allow(rtc_clock.getCurrentTime())) {
164165
// request data has: {reply-path-len}{reply-path}
165166
reply_path_len = *data++ & 0x3F;
@@ -169,14 +170,14 @@ uint8_t MyMesh::handleAnonVerOwnerReq(const mesh::Identity& sender, uint32_t sen
169170
memcpy(reply_data, &sender_timestamp, 4); // prefix with sender_timestamp, like a tag
170171
uint32_t now = getRTCClock()->getCurrentTime();
171172
memcpy(&reply_data[4], &now, 4); // include our clock (for easy clock sync, and packet hash uniqueness)
172-
sprintf((char *) &reply_data[8], "%s\n%s\n%s", FIRMWARE_VERSION, _prefs.node_name, _prefs.owner_info);
173+
sprintf((char *) &reply_data[8], "%s\n%s", _prefs.node_name, _prefs.owner_info);
173174

174175
return 8 + strlen((char *) &reply_data[8]); // reply length
175176
}
176177
return 0;
177178
}
178179

179-
uint8_t MyMesh::handleAnonVerReq(const mesh::Identity& sender, uint32_t sender_timestamp, const uint8_t* data) {
180+
uint8_t MyMesh::handleAnonClockReq(const mesh::Identity& sender, uint32_t sender_timestamp, const uint8_t* data) {
180181
if (anon_limiter.allow(rtc_clock.getCurrentTime())) {
181182
// request data has: {reply-path-len}{reply-path}
182183
reply_path_len = *data++ & 0x3F;
@@ -186,9 +187,16 @@ uint8_t MyMesh::handleAnonVerReq(const mesh::Identity& sender, uint32_t sender_t
186187
memcpy(reply_data, &sender_timestamp, 4); // prefix with sender_timestamp, like a tag
187188
uint32_t now = getRTCClock()->getCurrentTime();
188189
memcpy(&reply_data[4], &now, 4); // include our clock (for easy clock sync, and packet hash uniqueness)
189-
strcpy((char *) &reply_data[8], FIRMWARE_VERSION);
190-
191-
return 8 + strlen((char *) &reply_data[8]); // reply length
190+
reply_data[8] = 0; // features
191+
#ifdef WITH_RS232_BRIDGE
192+
reply_data[8] |= 0x01; // is bridge, type UART
193+
#elif WITH_ESPNOW_BRIDGE
194+
reply_data[8] |= 0x03; // is bridge, type ESP-NOW
195+
#endif
196+
if (_prefs.disable_fwd) { // is this repeater currently disabled
197+
reply_data[8] |= 0x80; // is disabled
198+
}
199+
return 9; // reply length
192200
}
193201
return 0;
194202
}
@@ -350,6 +358,9 @@ int MyMesh::handleRequest(ClientInfo *sender, uint32_t sender_timestamp, uint8_t
350358

351359
return reply_offset;
352360
}
361+
} else if (payload[0] == REQ_TYPE_GET_OWNER_INFO) {
362+
sprintf((char *) &reply_data[4], "%s\n%s", FIRMWARE_VERSION, _prefs.owner_info);
363+
return 4 + strlen((char *) &reply_data[4]);
353364
}
354365
return 0; // unknown command
355366
}
@@ -508,10 +519,10 @@ void MyMesh::onAnonDataRecv(mesh::Packet *packet, const uint8_t *secret, const m
508519
reply_len = handleLoginReq(sender, secret, timestamp, &data[4], packet->isRouteFlood());
509520
} else if (data[4] == ANON_REQ_TYPE_REGIONS && packet->isRouteDirect()) {
510521
reply_len = handleAnonRegionsReq(sender, timestamp, &data[5]);
511-
} else if (data[4] == ANON_REQ_TYPE_VER_OWNER && packet->isRouteDirect()) {
512-
reply_len = handleAnonVerOwnerReq(sender, timestamp, &data[5]);
513-
} else if (data[4] == ANON_REQ_TYPE_VER && packet->isRouteDirect()) {
514-
reply_len = handleAnonVerReq(sender, timestamp, &data[5]);
522+
} else if (data[4] == ANON_REQ_TYPE_OWNER && packet->isRouteDirect()) {
523+
reply_len = handleAnonOwnerReq(sender, timestamp, &data[5]);
524+
} else if (data[4] == ANON_REQ_TYPE_BASIC && packet->isRouteDirect()) {
525+
reply_len = handleAnonClockReq(sender, timestamp, &data[5]);
515526
} else {
516527
reply_len = 0; // unknown/invalid request type
517528
}
@@ -700,7 +711,9 @@ bool MyMesh::onPeerPathRecv(mesh::Packet *packet, int sender_idx, const uint8_t
700711

701712
void MyMesh::onControlDataRecv(mesh::Packet* packet) {
702713
uint8_t type = packet->payload[0] & 0xF0; // just test upper 4 bits
703-
if (type == CTL_TYPE_NODE_DISCOVER_REQ && packet->payload_len >= 6 && discover_limiter.allow(rtc_clock.getCurrentTime())) {
714+
if (type == CTL_TYPE_NODE_DISCOVER_REQ && packet->payload_len >= 6
715+
&& !_prefs.disable_fwd && discover_limiter.allow(rtc_clock.getCurrentTime())
716+
) {
704717
int i = 1;
705718
uint8_t filter = packet->payload[i++];
706719
uint32_t tag;

examples/simple_repeater/MyMesh.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
117117
void putNeighbour(const mesh::Identity& id, uint32_t timestamp, float snr);
118118
uint8_t handleLoginReq(const mesh::Identity& sender, const uint8_t* secret, uint32_t sender_timestamp, const uint8_t* data, bool is_flood);
119119
uint8_t handleAnonRegionsReq(const mesh::Identity& sender, uint32_t sender_timestamp, const uint8_t* data);
120-
uint8_t handleAnonVerOwnerReq(const mesh::Identity& sender, uint32_t sender_timestamp, const uint8_t* data);
121-
uint8_t handleAnonVerReq(const mesh::Identity& sender, uint32_t sender_timestamp, const uint8_t* data);
120+
uint8_t handleAnonOwnerReq(const mesh::Identity& sender, uint32_t sender_timestamp, const uint8_t* data);
121+
uint8_t handleAnonClockReq(const mesh::Identity& sender, uint32_t sender_timestamp, const uint8_t* data);
122122
int handleRequest(ClientInfo* sender, uint32_t sender_timestamp, uint8_t* payload, size_t payload_len);
123123
mesh::Packet* createSelfAdvert();
124124

src/helpers/RegionMap.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ RegionMap::RegionMap(TransportKeyStore& store) : _store(&store) {
99
strcpy(wildcard.name, "*");
1010
}
1111

12-
bool RegionMap::is_name_char(char c) {
13-
return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '-' || c == '.' || c == '_' || c == '#';
12+
bool RegionMap::is_name_char(uint8_t c) {
13+
// accept all alpha-num or accented characters, but exclude most punctuation chars
14+
return c == '-' || c == '#' || (c >= '0' && c <= '9') || c >= 'A';
1415
}
1516

1617
static File openWrite(FILESYSTEM* _fs, const char* filename) {

src/helpers/RegionMap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class RegionMap {
3030
public:
3131
RegionMap(TransportKeyStore& store);
3232

33-
static bool is_name_char(char c);
33+
static bool is_name_char(uint8_t c);
3434

3535
bool load(FILESYSTEM* _fs, const char* path=NULL);
3636
bool save(FILESYSTEM* _fs, const char* path=NULL);

0 commit comments

Comments
 (0)