Skip to content

Commit

Permalink
legacy packet validation
Browse files Browse the repository at this point in the history
  • Loading branch information
roema committed Oct 29, 2021
1 parent a870a91 commit 15f215f
Show file tree
Hide file tree
Showing 26 changed files with 504 additions and 312 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ RF position packets AES128 encrypted
* install latest Arduino IDE
* git clone https://github.com/roema/Open-Glider-Network-Groundstation.git --recursive
* make sure the arduino ide is using the correct libraries.
* **take a look at pictures folder for arduino configuration***


## Installation
* git clone --recursive https://github.com/roema/Open-Glider-Network-Groundstation.git
* Install arduino ide
- make sure you are using the correct librarys
* ~~Install ESP32 Filesystem Uploader~~
* Compile and upload Sketch and files (.css and .html)
* Connect to OGN Wifi AP and configure
* You can update you installation http://you-ogn-ground-ip/update
Expand Down
32 changes: 2 additions & 30 deletions ognbase/APRS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,34 +95,6 @@ static short AprsPasscode(const char* theCall)
return hash & 0x7fff;
}

static long double toRadians(const long double degree)
{
long double one_deg = (M_PI) / 180;
return one_deg * degree;
}

static long double distance(long double lat1, long double long1, long double lat2, long double long2)
{
lat1 = toRadians(lat1);
long1 = toRadians(long1);
lat2 = toRadians(lat2);
long2 = toRadians(long2);

long double dlong = long2 - long1;
long double dlat = lat2 - lat1;

long double ans = pow(sin(dlat / 2), 2) +
cos(lat1) * cos(lat2) *
pow(sin(dlong / 2), 2);

ans = 2 * asin(sqrt(ans));

long double R = 6371;
ans = ans * R;

return ans * 1000;
}

static bool OGN_APRS_Connect()
{
if (SoC->WiFi_connect_TCP(ogn_server.c_str(), ogn_port))
Expand Down Expand Up @@ -221,7 +193,7 @@ void OGN_APRS_Export()
if (Container[i].addr && (this_moment - Container[i].timestamp) <= EXPORT_EXPIRATION_TIME && Container[i].distance < ogn_range * 1000)
{

if(!isPacketValid(Container[i].addr, Container[i].latitude, Container[i].longitude, Container[i].speed, Container[i].timestamp) && testmode_enable){
if(!isPacketValid(Container[i].addr, Container[i].latitude, Container[i].longitude, Container[i].speed, Container[i].timestamp)){
break;
}

Expand Down Expand Up @@ -429,7 +401,7 @@ int OGN_APRS_Register(ufo_t* this_aircraft)

void OGN_APRS_KeepAlive()
{
String KeepAlivePacket = "#keepalive\n\n";
String KeepAlivePacket = "#keepalive\n";
Logger_send_udp(&KeepAlivePacket);
SoC->WiFi_transmit_TCP(KeepAlivePacket);
}
Expand Down
9 changes: 9 additions & 0 deletions ognbase/Log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "SoC.h"
#include "Log.h"
#include "EEPROM.h"
#include "PNET.h"
#include "global.h"


Expand All @@ -30,6 +31,14 @@ void Logger_send_udp(String* buf)
byte debug_msg[debug_len];
buf->getBytes(debug_msg, debug_len);
SoC->WiFi_transmit_UDP_debug(ogn_debugport, debug_msg, debug_len);

if(remotelogs_enable){
char *encrypted;
size_t encrypted_len;
//PNETencrypt(debug_msg, debug_len, &encrypted, &encrypted_len);
//SoC->WiFi_transmit_UDP(remotelogs_server.c_str(), remotelogs_port, (byte*)encrypted, encrypted_len);
//free(encrypted);
}
}
}

Expand Down
79 changes: 40 additions & 39 deletions ognbase/Log.h
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
/*
* Log.h
* Copyright (C) 2019-2020 Linar Yusupov
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef LOGHELPER_H
#define LOGHELPER_H

#include "SoftRF.h"

void Logger_send_udp(String *);

#if LOGGER_IS_ENABLED

#include <FS.h>

extern File LogFile;
void Logger_setup(void);

void Logger_loop(void);

void Logger_fini(void);

#endif /* LOGGER_IS_ENABLED */

#endif /* LOGHELPER_H */
/*
* Log.h
* Copyright (C) 2019-2020 Linar Yusupov
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef LOGHELPER_H
#define LOGHELPER_H

#include "SoftRF.h"

void Logger_send_udp(String *);
void Logger_send_enc_udp(String *);

#if LOGGER_IS_ENABLED

#include <FS.h>

extern File LogFile;
void Logger_setup(void);

void Logger_loop(void);

void Logger_fini(void);

#endif /* LOGGER_IS_ENABLED */

#endif /* LOGHELPER_H */
20 changes: 9 additions & 11 deletions ognbase/OLED.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,19 @@ byte OLED_setup()

void OLED_write(char* text, short x, short y, bool clear)
{
if (display_init)
{
display.displayOn();
if (clear)
display.clear();
display.drawString(x, y, text);
display.display();
}
if (!display_enabled){return;}

display.displayOn();
if (clear)
display.clear();
display.drawString(x, y, text);
display.display();
}

void OLED_disable()
{
if (!display_enabled){return;}

display.clear();
display.displayOff();
display_enabled = false;
Expand Down Expand Up @@ -322,6 +323,3 @@ void OLED_info(bool ntp)
}
}
}

void OLED_status()
{}
103 changes: 55 additions & 48 deletions ognbase/PVALID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,58 +32,53 @@ bool isPacketValid(uint32_t addr, double lat1, double lon1, double speed, time_t

/*V0.1.0-24*/

if (!testmode_enable){
return true;
}


for(uint8_t i=0;i<MAX_TRACKING_OBJECTS;i++){
for (uint8_t i = 0; i < MAX_TRACKING_OBJECTS; i++) {
msg = "checking database: ";
msg += String(ac[i].addr, HEX);
msg += " CNT: ";
msg += String(ac[i].pkt_counter);
Logger_send_udp(&msg);
}
for(uint8_t i=0; i<MAX_TRACKING_OBJECTS;i++){
Logger_send_udp(&msg);
}
for (uint8_t i = 0; i < MAX_TRACKING_OBJECTS; i++) {

if (addr == ac[i].addr) {

if(addr == ac[i].addr){

msg = "ADDR found in database..";
Logger_send_udp(&msg);

int dist = distance(lat1, lon1, ac[i].latitude, ac[i].longitude);

msg = "Transmitted distance: ";
msg += dist;
Logger_send_udp(&msg);

int calcdist = calcMaxDistance(speed, timestamp - ac[i].timestamp);
if(dist > calcdist){
if (dist > calcdist) {

msg = "Max calculated distance: ";
msg += calcdist;
Logger_send_udp(&msg);
Logger_send_udp(&msg);

msg = "Packet seems to be invalid";
Logger_send_udp(&msg);

cleanUpPacket(i);
shiftPackets();
return false;
}
else{
else {

msg = "Max calculated distance: ";
msg += calcdist;
Logger_send_udp(&msg);
Logger_send_udp(&msg);


uint8_t cnt = ac[i].pkt_counter + 1;

msg = "Packet seems to be valid - counter: ";
msg += cnt;
Logger_send_udp(&msg);
Logger_send_udp(&msg);

cleanUpPacket(i);
shiftPackets();
appendPacket(addr, lat1, lon1, timestamp, cnt);
Expand All @@ -95,53 +90,65 @@ bool isPacketValid(uint32_t addr, double lat1, double lon1, double speed, time_t
Logger_send_udp(&msg);
shiftPackets();
appendPacket(addr, lat1, lon1, timestamp, 0);
return(false);
return (false);
}


static int distance(double lat1, double lon1, double lat2, double lon2) {
double theta, dist;
double r = 6378137.0;

if ((lat1 == lat2) && (lon1 == lon2)) {
return 0;
}
else {
theta = lon1 - lon2;
dist = sin(deg2rad(lat1)) * sin(deg2rad(lat2)) + cos(deg2rad(lat1)) * cos(deg2rad(lat2)) * cos(deg2rad(theta));
dist = acos(dist);
dist = rad2deg(dist);
dist = dist * 60 * 1.1515;
dist = dist * 1.609344;
}

return (int)(dist);
lat1 = deg2rad(lat1);
lon1 = deg2rad(lon1);
lat2 = deg2rad(lat2);
lon2 = deg2rad(lon2);

double dlat = lat2 - lat1;
double dlon = lon2 - lon1;

double dist = 2 * r * asin(sqrt(pow(sin(dlat / 2), 2) + cos(lat1) * cos(lat2) * pow(sin(dlon / 2), 2)));

return (int)(dist); //distance in meter
}
}

static int calcMaxDistance(double speed, time_t time_diff) {
return (int)((speed / 3.6 * time_diff) * 2 );
}

static bool appendPacket(uint32_t addr, double lat, double lon, time_t timestamp, uint8_t cnt){
ac[MAX_TRACKING_OBJECTS-1].timestamp = timestamp;
ac[MAX_TRACKING_OBJECTS-1].addr = addr;
ac[MAX_TRACKING_OBJECTS-1].latitude = lat;
ac[MAX_TRACKING_OBJECTS-1].longitude = lon;
ac[MAX_TRACKING_OBJECTS-1].pkt_counter = cnt;
int speed_ms = speed / 3.6;
// 20% more than calculated
return (int)((speed * time_diff) * 1.2 );
}

static bool appendPacket(uint32_t addr, double lat, double lon, time_t timestamp, uint8_t cnt) {
ac[MAX_TRACKING_OBJECTS - 1].timestamp = timestamp;
ac[MAX_TRACKING_OBJECTS - 1].addr = addr;
ac[MAX_TRACKING_OBJECTS - 1].latitude = lat;
ac[MAX_TRACKING_OBJECTS - 1].longitude = lon;
ac[MAX_TRACKING_OBJECTS - 1].pkt_counter = cnt;
}

static void shiftPackets(void){
for(uint8_t i=0; i<MAX_TRACKING_OBJECTS-1; i++){
ac[i].timestamp = ac[i+1].timestamp;
ac[i].addr = ac[i+1].addr;
ac[i].latitude = ac[i+1].latitude;
ac[i].longitude = ac[i+1].longitude;
ac[i].pkt_counter = ac[i+1].pkt_counter;
static void shiftPackets(void) {
for (uint8_t i = 0; i < MAX_TRACKING_OBJECTS - 1; i++) {
ac[i].timestamp = ac[i + 1].timestamp;
ac[i].addr = ac[i + 1].addr;
ac[i].latitude = ac[i + 1].latitude;
ac[i].longitude = ac[i + 1].longitude;
ac[i].pkt_counter = ac[i + 1].pkt_counter;
}
}

static void cleanUpPacket(uint8_t index){
static void cleanUpPacket(uint8_t index) {
ac[index].addr = 0x00000000;
}

static void cleanUpArray() {

}

static double deg2rad(double deg) {
return (deg * pi / 180);
}
Expand Down
10 changes: 1 addition & 9 deletions ognbase/Platform_ESP32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "SoC.h"

#include "EEPROM.h"
#include "PNET.h"
#include "RF.h"
#include "WiFi.h"

Expand Down Expand Up @@ -627,15 +628,6 @@ static void ESP32_WiFi_transmit_UDP_debug(int port, byte* buf, size_t size)
switch (mode)
{
case WIFI_STA:
if(remotelogs_enable){
IPAddress rem_logger;
if (rem_logger.fromString(remotelogs_server)) {
Uni_Udp.begin(localPort);
Uni_Udp.beginPacket(rem_logger, remotelogs_port);
Uni_Udp.write(buf, size);
Uni_Udp.endPacket();
}
}
ClientIP = WiFi.gatewayIP();
ClientIP[3] = 200;
Uni_Udp.begin(localPort);
Expand Down
Loading

0 comments on commit 15f215f

Please sign in to comment.