callsignValidationTest

This commit is contained in:
richonguzman 2024-06-07 17:29:55 -04:00
parent a8e1a48d62
commit 397a94cc47
5 changed files with 116 additions and 62 deletions

View File

@ -194,7 +194,8 @@ namespace APRS_IS_Utils {
if (packet != "") {
if ((packet.substring(0, 3) == "\x3c\xff\x01") && (packet.indexOf("TCPIP") == -1) && (packet.indexOf("NOGATE") == -1) && (packet.indexOf("RFONLY") == -1)) {
Sender = packet.substring(3, packet.indexOf(">"));
if (Sender != Config.callsign) { // avoid listening yourself by digirepeating
if (Sender != Config.callsign && Utils::checkValidCallsign(Sender)) {
//if (Sender != Config.callsign) { // avoid listening yourself by digirepeating
if (STATION_Utils::check25SegBuffer(Sender, packet.substring(packet.indexOf(":")+2))) {
STATION_Utils::updateLastHeard(Sender);
Utils::typeOfPacket(packet.substring(3), 0); // LoRa-APRS
@ -230,8 +231,9 @@ namespace APRS_IS_Utils {
void processAPRSISPacket(const String& packet) {
String Sender, AddresseeAndMessage, Addressee, receivedMessage;
if (!packet.startsWith("#")) {
if (Config.aprs_is.messagesToRF && packet.indexOf("::") > 0) {
Sender = packet.substring(0, packet.indexOf(">"));
if (Utils::checkValidCallsign(Sender)) {
if (Config.aprs_is.messagesToRF && packet.indexOf("::") > 0) {
AddresseeAndMessage = packet.substring(packet.indexOf("::") + 2);
Addressee = AddresseeAndMessage.substring(0, AddresseeAndMessage.indexOf(":"));
Addressee.trim();
@ -280,8 +282,8 @@ namespace APRS_IS_Utils {
}
} else {
Utils::print("Received Message from APRS-IS : " + packet);
if (STATION_Utils::wasHeard(Addressee)) {
if (STATION_Utils::wasHeard(Addressee) && Utils::checkValidCallsign(Addressee)) {
//if (STATION_Utils::wasHeard(Addressee)) {
STATION_Utils::addToOutputPacketBuffer(buildPacketToTx(packet, 1));
display_toggle(true);
lastScreenOn = millis();
@ -298,6 +300,7 @@ namespace APRS_IS_Utils {
}
}
}
}
void listenAPRSIS() {
#ifdef ESP32_DIY_LoRa_A7670

View File

@ -62,7 +62,8 @@ namespace DIGI_Utils {
if (packet != "") {
if ((packet.substring(0, 3) == "\x3c\xff\x01") && (packet.indexOf("NOGATE") == -1)) {
Sender = packet.substring(3, packet.indexOf(">"));
if (Sender != Config.callsign) {
if (Sender != Config.callsign && Utils::checkValidCallsign(Sender)) {
//if (Sender != Config.callsign) {
if (STATION_Utils::check25SegBuffer(Sender, packet.substring(packet.indexOf(":") + 2))) {
STATION_Utils::updateLastHeard(Sender);
Utils::typeOfPacket(packet.substring(3), 2); // Digi

View File

@ -2,6 +2,8 @@
#include <WiFi.h>
#include "configuration.h"
#include "gps_utils.h"
#include "display.h"
#include "utils.h"
extern Configuration Config;
extern WiFiClient espClient;
@ -52,6 +54,10 @@ namespace GPS_Utils {
}
void generateBeacons() {
if (!Utils::checkValidCallsign(Config.callsign)) {
show_display("- ERROR -", "CALLSIGN = NOT VALID!", " Use SSID 0-15", " Or Valid Callsign", 0);
while (true) {}
}
String beaconPacket = Config.callsign;
beaconPacket += ">APLRG1";
if (Config.beacon.path != "") {

View File

@ -325,4 +325,47 @@ namespace Utils {
}
}
bool checkValidCallsign(const String& callsign) {
String cleanCallsign;
if (callsign.indexOf("-")) {
cleanCallsign = callsign.substring(0, callsign.indexOf("-"));
String ssid = callsign.substring(callsign.indexOf("-") + 1);
int ssidInt = ssid.toInt();
if (ssidInt == 0 && ssid != "0") {
return false;
} else if (ssidInt < 0 || ssidInt >= 15) {
return false;
}
} else {
cleanCallsign = callsign;
}
if (cleanCallsign.length() < 4 || cleanCallsign.length() > 6) {
return false;
}
if (isDigit(cleanCallsign[1]) && cleanCallsign.length() < 6) {
cleanCallsign = " " + cleanCallsign; // ANAA --> _ANAA
}
if (!isAlpha(cleanCallsign[1]) && !isDigit(cleanCallsign[2]) && !isAlpha(cleanCallsign[3])) {
return false;
}
if (cleanCallsign.length() == 5 && !isAlpha(cleanCallsign[4])) {
return false;
}
if (cleanCallsign.length() == 6 && (!isAlpha(cleanCallsign[4]) || !isAlpha(cleanCallsign[5]))) {
return false;
}
/* ABCDEFG - XX
0 A = _ or alpha num
1 B = alpha
2 C = num
3 D = alpha
4 E = _ or alpha
5 F = _ or alpha
XX = 0 - 15
*/
return true;
}
}

View File

@ -26,6 +26,7 @@ namespace Utils {
void checkRebootMode();
void checkRebootTime();
void checkSleepByLowBatteryVoltage(uint8_t mode);
bool checkValidCallsign(const String& callsign);
}