Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consti dev #11

Merged
merged 51 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
ea6d4ff
document
Consti10 Aug 7, 2023
cf8bf42
argh well remember 0 counts ;)
Consti10 Aug 7, 2023
e0b9e9d
fix
Consti10 Aug 7, 2023
4a1507a
document
Consti10 Aug 7, 2023
329c86f
document
Consti10 Aug 7, 2023
276a991
add option to debug gaps in stream (interference)
Consti10 Aug 7, 2023
f81336f
add option to debug gaps in stream (interference)
Consti10 Aug 7, 2023
886828a
add option to debug stats per card as string
Consti10 Aug 7, 2023
f0079a8
reset per card stats
Consti10 Aug 7, 2023
65c6886
add dBm for each antenna for each card
Consti10 Aug 8, 2023
e6ff6a9
add dBm for each antenna for each card
Consti10 Aug 8, 2023
90195fd
packet loss - add new class for uint64_t (nonce)
Consti10 Aug 8, 2023
393a17a
packet loss - add new class for uint64_t (nonce)
Consti10 Aug 8, 2023
8155f10
packet loss - add new class for uint64_t (nonce)
Consti10 Aug 8, 2023
4dfbaf1
packet loss - add new class for uint64_t (nonce)
Consti10 Aug 8, 2023
c304959
fix wrong card selected
Consti10 Aug 8, 2023
5ce20c4
exp rssi
Consti10 Aug 8, 2023
2b82344
exp rssi
Consti10 Aug 8, 2023
b9ed528
exp rssi
Consti10 Aug 8, 2023
383ef60
exp rssi
Consti10 Aug 8, 2023
b07fec4
exp rssi
Consti10 Aug 8, 2023
a54d5e8
exp rssi
Consti10 Aug 9, 2023
a12815d
exp rssi
Consti10 Aug 9, 2023
9c17489
we need keypairs from pw at some point
Consti10 Aug 9, 2023
beb030b
we need keypairs from pw at some point
Consti10 Aug 9, 2023
cfd6578
we need keypairs from pw at some point
Consti10 Aug 9, 2023
d8bdc37
exp rssi
Consti10 Aug 9, 2023
15a4afe
exp rssi
Consti10 Aug 9, 2023
1e2981c
exp rssi
Consti10 Aug 9, 2023
0eccaa2
exp rssi
Consti10 Aug 9, 2023
ac5f286
exp rssi
Consti10 Aug 9, 2023
2edd3e7
exp rssi
Consti10 Aug 9, 2023
491db5d
exp rssi
Consti10 Aug 9, 2023
e95becd
exp rssi
Consti10 Aug 9, 2023
be6a98b
exp rssi
Consti10 Aug 9, 2023
847d010
exp rssi
Consti10 Aug 9, 2023
da3351b
add pollute executable
Consti10 Aug 9, 2023
8705d12
signal quality impr
Consti10 Aug 9, 2023
c2b6489
signal quality impr
Consti10 Aug 9, 2023
0907204
signal quality impr
Consti10 Aug 9, 2023
085129f
rtl8812au dbm bug fix
Consti10 Aug 9, 2023
f584076
optimize loss recalculation
Consti10 Aug 9, 2023
c9c3c46
rtl8812au dbm bug fix
Consti10 Aug 9, 2023
be1ed43
fix comp
Consti10 Aug 9, 2023
3802bb7
fix comp
Consti10 Aug 10, 2023
220c377
improve pollution stat
Consti10 Aug 10, 2023
d6fdf75
improve pollution stat
Consti10 Aug 10, 2023
0e9a4a6
always calculate at least one FEC packet (for low blocks)
Consti10 Aug 10, 2023
9209da7
fix tests
Consti10 Aug 10, 2023
283f64d
fix tests
Consti10 Aug 10, 2023
266a0b8
fix tests
Consti10 Aug 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set(CMAKE_CXX_STANDARD 17)

include(WBLib.cmake)

add_executable(wfb_keygen executables/wfb_keygen.c)
add_executable(wfb_keygen executables/wfb_keygen.cpp)
target_link_libraries(wfb_keygen ${WB_TARGET_LINK_LIBRARIES})

add_executable(benchmark executables/benchmark.cpp)
Expand Down Expand Up @@ -36,6 +36,9 @@ target_link_libraries(example_udp ${WB_TARGET_LINK_LIBRARIES})
add_executable(injection_rate_test executables/injection_rate_test.cpp)
target_link_libraries(injection_rate_test ${WB_TARGET_LINK_LIBRARIES})

add_executable(example_pollute executables/example_pollute.cpp)
target_link_libraries(example_pollute ${WB_TARGET_LINK_LIBRARIES})

# When it is a static library, we don't need to install it.
# But if it is a shared library, we need to install it.
#install(TARGETS wifibroadcast DESTINATION lib)
Expand Down
3 changes: 3 additions & 0 deletions WBLib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ target_sources(wifibroadcast PUBLIC
${CMAKE_CURRENT_LIST_DIR}/src/WBStreamRx.cpp
${CMAKE_CURRENT_LIST_DIR}/src/WBStreamTx.cpp
${CMAKE_CURRENT_LIST_DIR}/src/WBTxRx.cpp
${CMAKE_CURRENT_LIST_DIR}/src/Ieee80211Header.hpp
${CMAKE_CURRENT_LIST_DIR}/src/RadiotapHeader.hpp
${CMAKE_CURRENT_LIST_DIR}/src/RSSIAccumulator.hpp
)
target_include_directories(wifibroadcast PUBLIC
${CMAKE_CURRENT_LIST_DIR}/src/HelperSources
Expand Down
3 changes: 3 additions & 0 deletions example_keys/generate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#bin/bash

./../cmake-build-debug/wfb_keygen
8 changes: 5 additions & 3 deletions executables/example_hello.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ int main(int argc, char *const *argv) {
std::cout<<"Running as "<<(is_air ? "Air" : "Ground")<<" on card "<<card<<"\n";

// Create the Tx-RX
std::vector<std::string> cards{card};
std::vector<WBTxRx::WifiCard> cards;
WBTxRx::WifiCard tmp_card{card,1};
cards.push_back(tmp_card);
WBTxRx::Options options_txrx{};
options_txrx.rtl8812au_rssi_fixup= true;
options_txrx.set_direction= true;
Expand Down Expand Up @@ -90,9 +92,9 @@ int main(int argc, char *const *argv) {
lastLog=std::chrono::steady_clock::now();
auto txStats=txrx->get_tx_stats();
auto rxStats=txrx->get_rx_stats();
auto rssi=txrx->get_rx_stats_for_card(0);
auto rx_stats_card0=txrx->get_rx_stats_for_card(0);
std::cout<<txStats<<std::endl;
std::cout<<rxStats<<" RSSI:"<<(int)rssi.rssi_for_wifi_card.last_rssi<<std::endl;
std::cout<<rx_stats_card0<<std::endl;
}
}
}
73 changes: 73 additions & 0 deletions executables/example_pollute.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
//
// Created by consti10 on 09.08.23.
//

#include "../src/WBStreamRx.h"
#include "../src/WBStreamTx.h"
#include "../src/WBTxRx.h"
#include "../src/wifibroadcast-spdlog.h"
#include "RandomBufferPot.hpp"

/**
* Simple demo application that sends out hello messages and listens for hello messages.
* You can run it either on 2 different systems (air unit and ground unit)
* or run it on the same system with 2 different wifi cards for testing.
*
* On success, you should see the air unit talking to the ground unit and vice versa.
*
* NOTE: Card(s) need to be in monitor mode & on match on the selected frequency !
* NOTE: This example is as simple as possible, and therefore doesn't even need to use the WBStreamTX / WBStreamRX pair
*/
int main(int argc, char *const *argv) {
std::string card="wlx244bfeb71c05";
int sleep_time_ms=10; // 100 pps
int opt;
while ((opt = getopt(argc, argv, "w:s:")) != -1) {
switch (opt) {
case 'w':
card = optarg;
break;
case 's':
sleep_time_ms = std::atoi(optarg);
break;
default: /* '?' */
show_usage:
fprintf(stderr,
"Example pollute %s [-w wifi card to use] [-s sleep time bwteen packets, in milliseconds]\n",
argv[0]);
exit(1);
}
}

// Create the Tx-RX
std::vector<WBTxRx::WifiCard> cards;
WBTxRx::WifiCard tmp_card{card,1};
cards.push_back(tmp_card);
WBTxRx::Options options_txrx{};
options_txrx.rtl8812au_rssi_fixup= true;
options_txrx.set_direction= true;
options_txrx.enable_non_openhd_mode= true;

std::shared_ptr<WBTxRx> txrx=std::make_shared<WBTxRx>(cards,options_txrx);
// We do not need receive in this mode
//txrx->start_receiving();
wifibroadcast::log::get_default()->debug("Example pollute {}ms",sleep_time_ms);

auto lastLog=std::chrono::steady_clock::now();
int packet_index=0;
while (true){
auto message=GenericHelper::createRandomDataBuffer(1024);
packet_index++;

txrx->tx_inject_packet(0,(uint8_t*)message.data(),message.size());
// About 100pps
std::this_thread::sleep_for(std::chrono::milliseconds (sleep_time_ms));

const auto elapsed_since_last_log=std::chrono::steady_clock::now()-lastLog;
if(elapsed_since_last_log>std::chrono::seconds(4)){
lastLog=std::chrono::steady_clock::now();
auto txStats=txrx->get_tx_stats();
std::cout<<txStats<<std::endl;
}
}
}
10 changes: 7 additions & 3 deletions executables/example_udp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ int main(int argc, char *const *argv) {
auto console=wifibroadcast::log::create_or_get("main");
console->info("Running as {} on card {}",(is_air ? "Air" : "Ground"),card);

std::vector<std::string> cards{card};
std::vector<WBTxRx::WifiCard> cards;
WBTxRx::WifiCard tmp_card{card,1};
cards.push_back(tmp_card);
WBTxRx::Options options_txrx{};
options_txrx.rtl8812au_rssi_fixup= true;
//options_txrx.set_direction= false;
Expand Down Expand Up @@ -121,9 +123,11 @@ int main(int argc, char *const *argv) {
const auto elapsed_since_last_log=std::chrono::steady_clock::now()-lastLog;
if(elapsed_since_last_log>std::chrono::seconds(1)){
lastLog=std::chrono::steady_clock::now();
auto txStats=txrx->get_tx_stats();
auto rxStats=txrx->get_rx_stats();
auto rssi=txrx->get_rx_stats_for_card(0);
std::cout<<rxStats<<" RSSI:"<<(int)rssi.rssi_for_wifi_card.last_rssi<<std::endl;
auto rx_stats_card0=txrx->get_rx_stats_for_card(0);
std::cout<<txStats<<std::endl;
std::cout<<rx_stats_card0<<std::endl;
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions executables/injection_rate_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,13 @@ int main(int argc, char *const *argv) {
std::cout<<"Running on card "<<card<<"\n";

// Create the Tx-RX
std::vector<std::string> cards{card};
std::vector<WBTxRx::WifiCard> cards;
WBTxRx::WifiCard tmp_card{card,1};
cards.push_back(tmp_card);
WBTxRx::Options options_txrx{};
options_txrx.rtl8812au_rssi_fixup= true;
//options_txrx.set_direction= false;
options_txrx.log_all_received_validated_packets= false;
options_txrx.enable_encryption= false;

std::shared_ptr<WBTxRx> txrx=std::make_shared<WBTxRx>(cards,options_txrx);
// No idea if and what effect stbc and ldpc have on the rate, but openhd enables them if possible by default
Expand Down
8 changes: 5 additions & 3 deletions executables/test_txrx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ int main(int argc, char *const *argv) {
}
}

std::vector<std::string> cards{card};
std::vector<WBTxRx::WifiCard> cards;
WBTxRx::WifiCard tmp_card{card,1};
cards.push_back(tmp_card);
WBTxRx::Options options_txrx{};
options_txrx.rtl8812au_rssi_fixup= true;
//options_txrx.set_direction= false;
Expand Down Expand Up @@ -74,10 +76,10 @@ int main(int argc, char *const *argv) {
lastLog=std::chrono::steady_clock::now();
auto txStats=txrx->get_tx_stats();
auto rxStats=txrx->get_rx_stats();
auto rssi=txrx->get_rx_stats_for_card(0);
auto rx_stats_card0=txrx->get_rx_stats_for_card(0);
std::cout<<txStats<<"\n";
std::cout<<rxStats<<"\n";
std::cout<<"RSSI:"<<(int)rssi.rssi_for_wifi_card.last_rssi<<"\n";
std::cout<<rx_stats_card0<<std::endl;
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions executables/unit_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,10 @@ static void test_fec_stream_random_bs_fs_overhead_dropped(){
// Test encryption+packet validation and packet validation only
static void test_encrypt_decrypt_validate(const bool useGeneratedFiles,bool message_signing_only) {
std::cout << "Using generated keypair (default seed otherwise):" << (useGeneratedFiles ? "y" : "n") << "\n";
std::optional<std::string> encKey = useGeneratedFiles ? std::optional<std::string>("gs.key") : std::nullopt;
std::optional<std::string> decKey = useGeneratedFiles ? std::optional<std::string>("drone.key") : std::nullopt;
const std::string filename_gs="gs.key"; //"../example_keys/gs.key"
const std::string filename_drone="drone.key" //"../example_keys/drone.key"
std::optional<std::string> encKey = useGeneratedFiles ? std::optional<std::string>(filename_gs) : std::nullopt;
std::optional<std::string> decKey = useGeneratedFiles ? std::optional<std::string>(filename_drone) : std::nullopt;
if(message_signing_only){
std::cout<<"Testing message signing\n";
}else{
Expand All @@ -128,8 +130,8 @@ static void test_encrypt_decrypt_validate(const bool useGeneratedFiles,bool mess
// make session key (tx)
encryptor.makeNewSessionKey(sessionKeyPacket.sessionKeyNonce, sessionKeyPacket.sessionKeyData);
// and "receive" session key (rx)
assert(
decryptor.onNewPacketSessionKeyData(sessionKeyPacket.sessionKeyNonce, sessionKeyPacket.sessionKeyData) == true);
assert(decryptor.onNewPacketSessionKeyData(sessionKeyPacket.sessionKeyNonce, sessionKeyPacket.sessionKeyData)
== Decryptor::SESSION_VALID_NEW);
// now encrypt a couple of packets and decrypt them again afterwards
for (uint64_t nonce = 0; nonce < 200; nonce++) {
const auto data = GenericHelper::createRandomDataBuffer(FEC_PACKET_MAX_PAYLOAD_SIZE);
Expand Down
56 changes: 0 additions & 56 deletions executables/wfb_keygen.c

This file was deleted.

28 changes: 28 additions & 0 deletions executables/wfb_keygen.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

// Copyright (C) 2017, 2018 Vasily Evseenko <[email protected]>
// 2020 Constantin Geier

/*
* 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; version 3.
*
* 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, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include "../src/Encryption.hpp"

/**
* Generates a new keypair and saves it to file for later use.
*/
int main(void) {
auto keypair=wbencryption::generate_keypair();
return wbencryption::write_to_file(keypair);
}
60 changes: 55 additions & 5 deletions src/Encryption.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,16 @@ class Decryptor {
std::array<uint8_t, crypto_box_PUBLICKEYBYTES> tx_publickey{};
std::array<uint8_t, crypto_aead_chacha20poly1305_KEYBYTES> session_key{};
public:
// return true if a new session was detected (The same session key can be sent multiple times by the tx)
bool onNewPacketSessionKeyData(const std::array<uint8_t, crypto_box_NONCEBYTES> &sessionKeyNonce,
static constexpr auto SESSION_VALID_NEW=0;
static constexpr auto SESSION_VALID_NOT_NEW=1;
static constexpr auto SESSION_NOT_VALID=-1;
/**
* Returns 0 if the session is a valid session in regards to the key-pairs AND the session is a new session
* Returns 1 if the session is a valid session in regards to the key-pairs but it is not a new session
* Returns -1 if the session is not a valid session in regards to the key-pairs
*
*/
int onNewPacketSessionKeyData(const std::array<uint8_t, crypto_box_NONCEBYTES> &sessionKeyNonce,
const std::array<uint8_t,crypto_aead_chacha20poly1305_KEYBYTES+ crypto_box_MACBYTES> &sessionKeyData) {
std::array<uint8_t, sizeof(session_key)> new_session_key{};
if (crypto_box_open_easy(new_session_key.data(),
Expand All @@ -177,15 +185,15 @@ class Decryptor {
tx_publickey.data(), rx_secretkey.data()) != 0) {
// this basically should just never happen, and is an error
wifibroadcast::log::get_default()->warn("unable to decrypt session key");
return false;
return SESSION_NOT_VALID;
}
if (memcmp(session_key.data(), new_session_key.data(), sizeof(session_key)) != 0) {
// this is NOT an error, the same session key is sent multiple times !
wifibroadcast::log::get_default()->info("Decryptor-New session detected");
session_key = new_session_key;
return true;
return SESSION_VALID_NEW;
}
return false;
return SESSION_VALID_NOT_NEW;
}
/**
* Decrypt (or validate only if encryption is disabled) the given message
Expand Down Expand Up @@ -239,4 +247,46 @@ class Decryptor {
}
};

namespace wbencryption{

struct KeypairData{
unsigned char drone_publickey[crypto_box_PUBLICKEYBYTES];
unsigned char drone_secretkey[crypto_box_SECRETKEYBYTES];
unsigned char gs_publickey[crypto_box_PUBLICKEYBYTES];
unsigned char gs_secretkey[crypto_box_SECRETKEYBYTES];
};

static KeypairData generate_keypair(){
KeypairData ret{};
crypto_box_keypair(ret.drone_publickey, ret.drone_secretkey);
crypto_box_keypair(ret.gs_publickey, ret.gs_secretkey);
return ret;
}

static int write_to_file(const KeypairData& data){
FILE *fp;
if ((fp = fopen("drone.key", "w")) == NULL) {
perror("Unable to save drone.key");
return 1;
}
fwrite(data.drone_secretkey, crypto_box_SECRETKEYBYTES, 1, fp);
fwrite(data.gs_publickey, crypto_box_PUBLICKEYBYTES, 1, fp);
fclose(fp);

fprintf(stderr, "Drone keypair (drone sec + gs pub) saved to drone.key\n");

if ((fp = fopen("gs.key", "w")) == NULL) {
perror("Unable to save gs.key");
return 1;
}

fwrite(data.gs_secretkey, crypto_box_SECRETKEYBYTES, 1, fp);
fwrite(data.drone_publickey, crypto_box_PUBLICKEYBYTES, 1, fp);
fclose(fp);
fprintf(stderr, "GS keypair (gs sec + drone pub) saved to gs.key\n");
return 0;
}

}

#endif //ENCRYPTION_HPP
Loading
Loading