Skip to content

Commit 5475043

Browse files
author
Scott Powell
committed
* new ANON_REQ_TYPE_VER_OWNER
* CommonCLI: new "get/set owner.info ..."
1 parent 5cc44dd commit 5475043

File tree

4 files changed

+51
-5
lines changed

4 files changed

+51
-5
lines changed

examples/simple_repeater/MyMesh.cpp

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#define RESP_SERVER_LOGIN_OK 0 // response to ANON_REQ
5353

5454
#define ANON_REQ_TYPE_REGIONS 0x01
55+
#define ANON_REQ_TYPE_VER_OWNER 0x02
5556

5657
#define CLI_REPLY_DELAY_MILLIS 600
5758

@@ -142,7 +143,7 @@ uint8_t MyMesh::handleLoginReq(const mesh::Identity& sender, const uint8_t* secr
142143
}
143144

144145
uint8_t MyMesh::handleAnonRegionsReq(const mesh::Identity& sender, uint32_t sender_timestamp, const uint8_t* data) {
145-
if (regions_limiter.allow(rtc_clock.getCurrentTime())) {
146+
if (anon_limiter.allow(rtc_clock.getCurrentTime())) {
146147
// request data has: {reply-path-len}{reply-path}
147148
reply_path_len = *data++ & 0x3F;
148149
memcpy(reply_path, data, reply_path_len);
@@ -159,6 +160,26 @@ uint8_t MyMesh::handleAnonRegionsReq(const mesh::Identity& sender, uint32_t send
159160
return 0;
160161
}
161162

163+
uint8_t MyMesh::handleAnonVerOwnerReq(const mesh::Identity& sender, uint32_t sender_timestamp, const uint8_t* data) {
164+
if (anon_limiter.allow(rtc_clock.getCurrentTime())) {
165+
// request data has: {reply-path-len}{reply-path}
166+
reply_path_len = *data++ & 0x3F;
167+
memcpy(reply_path, data, reply_path_len);
168+
// data += reply_path_len;
169+
// other params??
170+
171+
memcpy(reply_data, &sender_timestamp, 4); // prefix with sender_timestamp, like a tag
172+
173+
uint32_t now = getRTCClock()->getCurrentTime();
174+
memcpy(&reply_data[4], &now, 4); // include our clock (for easy clock sync, if this is a trusted node)
175+
176+
sprintf((char *) &reply_data[8], "%s,%s", FIRMWARE_VERSION, _prefs.owner_info);
177+
178+
return 8 + strlen((char *) &reply_data[8]); // reply length
179+
}
180+
return 0;
181+
}
182+
162183
int MyMesh::handleRequest(ClientInfo *sender, uint32_t sender_timestamp, uint8_t *payload, size_t payload_len) {
163184
// uint32_t now = getRTCClock()->getCurrentTimeUnique();
164185
// memcpy(reply_data, &now, 4); // response packets always prefixed with timestamp
@@ -474,6 +495,8 @@ void MyMesh::onAnonDataRecv(mesh::Packet *packet, const uint8_t *secret, const m
474495
reply_len = handleLoginReq(sender, secret, timestamp, &data[4], packet->isRouteFlood());
475496
} else if (data[4] == ANON_REQ_TYPE_REGIONS && packet->isRouteDirect()) {
476497
reply_len = handleAnonRegionsReq(sender, timestamp, &data[5]);
498+
} else if (data[4] == ANON_REQ_TYPE_VER_OWNER && packet->isRouteDirect()) {
499+
reply_len = handleAnonVerOwnerReq(sender, timestamp, &data[5]);
477500
} else {
478501
reply_len = 0; // unknown/invalid request type
479502
}
@@ -694,7 +717,7 @@ MyMesh::MyMesh(mesh::MainBoard &board, mesh::Radio &radio, mesh::MillisecondCloc
694717
: mesh::Mesh(radio, ms, rng, rtc, *new StaticPoolPacketManager(32), tables),
695718
_cli(board, rtc, sensors, &_prefs, this), telemetry(MAX_PACKET_PAYLOAD - 4), region_map(key_store), temp_map(key_store),
696719
discover_limiter(4, 120), // max 4 every 2 minutes
697-
regions_limiter(4, 180) // max 4 every 3 minutes
720+
anon_limiter(4, 180) // max 4 every 3 minutes
698721
#if defined(WITH_RS232_BRIDGE)
699722
, bridge(&_prefs, WITH_RS232_BRIDGE, _mgr, &rtc)
700723
#endif

examples/simple_repeater/MyMesh.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
9595
RegionMap region_map, temp_map;
9696
RegionEntry* load_stack[8];
9797
RegionEntry* recv_pkt_region;
98-
RateLimiter discover_limiter, regions_limiter;
98+
RateLimiter discover_limiter, anon_limiter;
9999
bool region_load_active;
100100
unsigned long dirty_contacts_expiry;
101101
#if MAX_NEIGHBOURS
@@ -117,6 +117,7 @@ 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);
120121
int handleRequest(ClientInfo* sender, uint32_t sender_timestamp, uint8_t* payload, size_t payload_len);
121122
mesh::Packet* createSelfAdvert();
122123

src/helpers/CommonCLI.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ void CommonCLI::loadPrefsInt(FILESYSTEM* fs, const char* filename) {
7272
file.read((uint8_t *)&_prefs->advert_loc_policy, sizeof (_prefs->advert_loc_policy)); // 161
7373
file.read((uint8_t *)&_prefs->discovery_mod_timestamp, sizeof(_prefs->discovery_mod_timestamp)); // 162
7474
file.read((uint8_t *)&_prefs->adc_multiplier, sizeof(_prefs->adc_multiplier)); // 166
75-
// 170
75+
file.read((uint8_t *)_prefs->owner_info, sizeof(_prefs->owner_info)); // 170
76+
// 290
7677

7778
// sanitise bad pref values
7879
_prefs->rx_delay_base = constrain(_prefs->rx_delay_base, 0, 20.0f);
@@ -155,7 +156,8 @@ void CommonCLI::savePrefs(FILESYSTEM* fs) {
155156
file.write((uint8_t *)&_prefs->advert_loc_policy, sizeof(_prefs->advert_loc_policy)); // 161
156157
file.write((uint8_t *)&_prefs->discovery_mod_timestamp, sizeof(_prefs->discovery_mod_timestamp)); // 162
157158
file.write((uint8_t *)&_prefs->adc_multiplier, sizeof(_prefs->adc_multiplier)); // 166
158-
// 170
159+
file.write((uint8_t *)_prefs->owner_info, sizeof(_prefs->owner_info)); // 170
160+
// 290
159161

160162
file.close();
161163
}
@@ -301,6 +303,15 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch
301303
sprintf(reply, "> %d", (uint32_t)_prefs->flood_max);
302304
} else if (memcmp(config, "direct.txdelay", 14) == 0) {
303305
sprintf(reply, "> %s", StrHelper::ftoa(_prefs->direct_tx_delay_factor));
306+
} else if (memcmp(config, "owner.info", 10) == 0) {
307+
*reply++ = '>';
308+
*reply++ = ' ';
309+
const char* sp = _prefs->owner_info;
310+
while (*sp) {
311+
*reply++ = (*sp == '\n') ? '|' : *sp; // translate newline back to orig '|'
312+
sp++;
313+
}
314+
*reply = 0; // set null terminator
304315
} else if (memcmp(config, "tx", 2) == 0 && (config[2] == 0 || config[2] == ' ')) {
305316
sprintf(reply, "> %d", (uint32_t) _prefs->tx_power_dbm);
306317
} else if (memcmp(config, "freq", 4) == 0) {
@@ -479,6 +490,16 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch
479490
} else {
480491
strcpy(reply, "Error, cannot be negative");
481492
}
493+
} else if (memcmp(config, "owner.info ", 11) == 0) {
494+
config += 11;
495+
char *dp = _prefs->owner_info;
496+
while (*config && dp - _prefs->owner_info < sizeof(_prefs->owner_info)-1) {
497+
*dp++ = (*config == '|') ? '\n' : *config; // translate '|' to newline chars
498+
config++;
499+
}
500+
*dp = 0;
501+
savePrefs();
502+
strcpy(reply, "OK");
482503
} else if (memcmp(config, "tx ", 3) == 0) {
483504
_prefs->tx_power_dbm = atoi(&config[3]);
484505
savePrefs();

src/helpers/CommonCLI.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ struct NodePrefs { // persisted to file
5050
uint8_t advert_loc_policy;
5151
uint32_t discovery_mod_timestamp;
5252
float adc_multiplier;
53+
char owner_info[120];
5354
};
5455

5556
class CommonCLICallbacks {

0 commit comments

Comments
 (0)