@@ -617,6 +617,38 @@ bool SensorMesh::handleIncomingMsg(ClientInfo& from, uint32_t timestamp, uint8_t
617617 return false ;
618618}
619619
620+ #define CTL_TYPE_NODE_DISCOVER_REQ 0x80
621+ #define CTL_TYPE_NODE_DISCOVER_RESP 0x90
622+
623+ void SensorMesh::onControlDataRecv (mesh::Packet* packet) {
624+ uint8_t type = packet->payload [0 ] & 0xF0 ; // just test upper 4 bits
625+ if (type == CTL_TYPE_NODE_DISCOVER_REQ && packet->payload_len >= 6 ) {
626+ // TODO: apply rate limiting to these!
627+ int i = 1 ;
628+ uint8_t filter = packet->payload [i++];
629+ uint32_t tag;
630+ memcpy (&tag, &packet->payload [i], 4 ); i += 4 ;
631+ uint32_t since;
632+ if (packet->payload_len >= i+4 ) { // optional since field
633+ memcpy (&since, &packet->payload [i], 4 ); i += 4 ;
634+ } else {
635+ since = 0 ;
636+ }
637+
638+ if ((filter & (1 << ADV_TYPE_SENSOR)) != 0 && _prefs.discovery_mod_timestamp >= since) {
639+ uint8_t data[6 + PUB_KEY_SIZE];
640+ data[0 ] = CTL_TYPE_NODE_DISCOVER_RESP | ADV_TYPE_SENSOR; // low 4-bits for node type
641+ data[1 ] = packet->_snr ; // let sender know the inbound SNR ( x 4)
642+ memcpy (&data[2 ], &tag, 4 ); // include tag from request, for client to match to
643+ memcpy (&data[6 ], self_id.pub_key , PUB_KEY_SIZE);
644+ auto resp = createControlData (data, sizeof (data));
645+ if (resp) {
646+ sendZeroHop (resp, getRetransmitDelay (resp)); // apply random delay, as multiple nodes can respond to this
647+ }
648+ }
649+ }
650+ }
651+
620652bool SensorMesh::onPeerPathRecv (mesh::Packet* packet, int sender_idx, const uint8_t * secret, uint8_t * path, uint8_t path_len, uint8_t extra_type, uint8_t * extra, uint8_t extra_len) {
621653 int i = matching_peer_indexes[sender_idx];
622654 if (i < 0 || i >= acl.getNumClients ()) {
0 commit comments