mirror of
https://github.com/gnss-sdr/gnss-sdr
synced 2025-01-18 21:23:02 +00:00
[TAS-199] Add TagVerification test. Bugfix for verify_tag and osnma_helper.
This commit is contained in:
parent
059e5e98d8
commit
f11eb5b421
@ -873,6 +873,7 @@ void osnma_msg_receiver::process_mack_message()
|
||||
if (ret || d_flag_debug){
|
||||
for(std::size_t i = 0; i < mack->tag_and_info.size(); ++i)
|
||||
{
|
||||
// add tags of current mack to the verification queue
|
||||
auto& tag = mack->tag_and_info[i];
|
||||
Tag t(tag, mack->TOW, mack->WN, mack->PRNa, i + 2); // tag0 (mack header) has CTR1, so first tag of MTI has CTR = 2.
|
||||
d_tags_awaiting_verify.insert(std::pair(mack->TOW, t));
|
||||
@ -1002,7 +1003,7 @@ bool osnma_msg_receiver::verify_tag(Tag& tag)
|
||||
std::vector<uint8_t> m;
|
||||
m.push_back(static_cast<uint8_t>(tag.PRN_d));
|
||||
m.push_back(static_cast<uint8_t>(tag.PRNa));
|
||||
uint32_t GST = d_helper->compute_gst(tag.TOW, tag.WN);
|
||||
uint32_t GST = d_helper->compute_gst( tag.WN,tag.TOW);
|
||||
std::vector<uint8_t> GST_uint8 = d_helper->gst_to_uint8(GST);
|
||||
m.insert(m.end(),GST_uint8.begin(),GST_uint8.end());
|
||||
m.push_back(tag.CTR);
|
||||
@ -1012,8 +1013,8 @@ bool osnma_msg_receiver::verify_tag(Tag& tag)
|
||||
m.push_back(two_bits_nmas);
|
||||
|
||||
// convert std::string to vector<uint8_t>
|
||||
std::string ephemeris_iono_vector_2 = d_satellite_nav_data[tag.TOW][tag.PRNa].ephemeris_iono_vector_2;
|
||||
std::vector<uint8_t> ephemeris_iono_vector_2_bytes(ephemeris_iono_vector_2.begin(), ephemeris_iono_vector_2.end());
|
||||
std::string ephemeris_iono_vector_2 = d_satellite_nav_data[tag.PRNa][tag.TOW].ephemeris_iono_vector_2;
|
||||
std::vector<uint8_t> ephemeris_iono_vector_2_bytes = d_helper->bytes(ephemeris_iono_vector_2);
|
||||
|
||||
// Convert and add ephemeris_iono_vector_2 into the vector
|
||||
for (uint8_t byte : ephemeris_iono_vector_2_bytes) {
|
||||
@ -1205,7 +1206,8 @@ void osnma_msg_receiver::control_tags_awaiting_verify_size()
|
||||
/**
|
||||
* @brief Verifies the MACSEQ of a received MACK_message.
|
||||
*
|
||||
* \details checks for each tag in the retrieved mack message if its flexible (MACSEQ) or not (MACSEQ/MACLT depending on configuration param. (TODO)
|
||||
* \details checks for each tag in the retrieved mack message if its flexible (MACSEQ) or not (MACSEQ/MACLT depending on configuration param, and
|
||||
* verifies according to Eqs. 20, 21 SIS ICD.
|
||||
* @param message The MACK_message to verify.
|
||||
* @return True if the MACSEQ is valid, false otherwise.
|
||||
*/
|
||||
@ -1218,7 +1220,7 @@ bool osnma_msg_receiver::verify_macseq(const MACK_message& mack)
|
||||
std::vector<std::string> sq2{};
|
||||
std::vector<std::string> applicable_sequence;
|
||||
const auto it = OSNMA_TABLE_16.find(d_osnma_data.d_dsm_kroot_message.maclt);
|
||||
// TODO as per RG example appears that the seq. q shall also be validated ageints either next or former Sf (depending on GST)
|
||||
// TODO as per RG example appears that the seq. q shall also be validated against either next or former Sf (depending on GST)
|
||||
if (it != OSNMA_TABLE_16.cend())
|
||||
{
|
||||
sq1 = it->second.sequence1;
|
||||
|
@ -122,6 +122,7 @@ private:
|
||||
|
||||
FRIEND_TEST(OsnmaMsgReceiverTest, TeslaKeyVerification);
|
||||
FRIEND_TEST(OsnmaMsgReceiverTest, OsnmaTestVectorsSimulation);
|
||||
FRIEND_TEST(OsnmaMsgReceiverTest, TagVerification);
|
||||
};
|
||||
|
||||
|
||||
|
@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
#include "osnma_helper.h"
|
||||
#include <bitset>
|
||||
|
||||
uint32_t Osnma_Helper::compute_gst(uint32_t WN, uint32_t TOW) const
|
||||
{
|
||||
@ -24,11 +25,32 @@ uint32_t Osnma_Helper::compute_gst(uint32_t WN, uint32_t TOW) const
|
||||
|
||||
std::vector<uint8_t> Osnma_Helper::gst_to_uint8(uint32_t GST) const
|
||||
{
|
||||
std::vector<uint8_t> res(4);
|
||||
std::vector<uint8_t> res;
|
||||
|
||||
res[1] = static_cast<uint8_t>((GST & 0xFF000000) >> 24);
|
||||
res[2] = static_cast<uint8_t>((GST & 0x00FF0000) >> 16);
|
||||
res[3] = static_cast<uint8_t>((GST & 0x0000FF00) >> 8);
|
||||
res[4] = static_cast<uint8_t>(GST & 0x000000FF);
|
||||
res.push_back(static_cast<uint8_t>((GST & 0xFF000000) >> 24));
|
||||
res.push_back(static_cast<uint8_t>((GST & 0x00FF0000) >> 16));
|
||||
res.push_back(static_cast<uint8_t>((GST & 0x0000FF00) >> 8));
|
||||
res.push_back(static_cast<uint8_t>(GST & 0x000000FF));
|
||||
return res;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> Osnma_Helper::bytes(const std::string& binaryString) {
|
||||
std::vector<uint8_t> bytes;
|
||||
|
||||
// Determine the size of the padding needed.
|
||||
size_t padding_size = binaryString.size() % 8;
|
||||
|
||||
std::string padded_binary = binaryString;
|
||||
|
||||
if (padding_size != 0) {
|
||||
padding_size = 8 - padding_size; // Compute padding size
|
||||
padded_binary.append(padding_size, '0'); // Append zeros to the binary string
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < padded_binary.size(); i += 8) {
|
||||
uint8_t byte = std::bitset<8>(padded_binary.substr(i, 8)).to_ulong();
|
||||
bytes.push_back(byte);
|
||||
}
|
||||
|
||||
return bytes;
|
||||
}
|
@ -19,6 +19,7 @@
|
||||
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
class Osnma_Helper
|
||||
{
|
||||
@ -27,6 +28,7 @@ public:
|
||||
~Osnma_Helper() = default;
|
||||
uint32_t compute_gst(uint32_t WN, uint32_t TOW) const;
|
||||
std::vector<uint8_t> gst_to_uint8(uint32_t GST) const;
|
||||
std::vector<uint8_t> bytes(const std::string& binaryString);
|
||||
};
|
||||
|
||||
|
||||
|
@ -78,7 +78,6 @@ Concurrent_Map<Gps_Acq_Assist> global_gps_acq_assist_map;
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
#if USE_GLOG_AND_GFLAGS
|
||||
gflags::ParseCommandLineFlags(&argc, &argv, true);
|
||||
try
|
||||
{
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
|
@ -58,6 +58,7 @@ public:
|
||||
|
||||
TEST_F(OsnmaMsgReceiverTest, TeslaKeyVerification) {
|
||||
// Arrange
|
||||
// ----------
|
||||
osnma->d_tesla_key_verified = false;
|
||||
osnma->d_osnma_data.d_dsm_kroot_message.kroot = {0x5B, 0xF8, 0xC9, 0xCB, 0xFC, 0xF7, 0x04, 0x22, 0x08, 0x14, 0x75, 0xFD, 0x44, 0x5D, 0xF0, 0xFF}; // Kroot, TOW 345570 GST_0 - 30
|
||||
osnma->d_osnma_data.d_dsm_kroot_message.ks = 4; // TABLE 10 --> 128 bits
|
||||
@ -75,6 +76,7 @@ TEST_F(OsnmaMsgReceiverTest, TeslaKeyVerification) {
|
||||
|
||||
|
||||
// Act
|
||||
// ----------
|
||||
bool result = osnma->verify_tesla_key(key, TOW);
|
||||
|
||||
|
||||
@ -82,7 +84,8 @@ TEST_F(OsnmaMsgReceiverTest, TeslaKeyVerification) {
|
||||
|
||||
|
||||
// Assert
|
||||
ASSERT_TRUE(result); // Adjust this according to what you expect
|
||||
// ----------
|
||||
ASSERT_TRUE(result);
|
||||
|
||||
}
|
||||
|
||||
@ -342,7 +345,6 @@ std::vector<uint8_t> OsnmaMsgReceiverTest::extract_page_bytes(const TestVector&
|
||||
|
||||
return extracted_bytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets the time based on the given input.
|
||||
*
|
||||
@ -374,7 +376,6 @@ void OsnmaMsgReceiverTest::set_time(std::tm& input)
|
||||
|
||||
|
||||
}
|
||||
|
||||
void OsnmaMsgReceiverTest::initializeGoogleLog()
|
||||
{
|
||||
google::InitGoogleLogging(log_name.c_str());
|
||||
@ -416,4 +417,53 @@ void OsnmaMsgReceiverTest::initializeGoogleLog()
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TEST_F(OsnmaMsgReceiverTest, TagVerification) {
|
||||
// Arrange
|
||||
// ----------
|
||||
osnma->d_tesla_key_verified = false;
|
||||
osnma->d_osnma_data.d_dsm_kroot_message.kroot = {0x5B, 0xF8, 0xC9, 0xCB, 0xFC, 0xF7, 0x04, 0x22, 0x08, 0x14, 0x75, 0xFD, 0x44, 0x5D, 0xF0, 0xFF}; // Kroot, TOW 345570 GST_0 - 30
|
||||
osnma->d_osnma_data.d_dsm_kroot_message.ks = 4; // TABLE 10 --> 128 bits
|
||||
osnma->d_osnma_data.d_dsm_kroot_message.alpha = 0x610BDF26D77B;
|
||||
// local_time_verification would do this operation. TODO - eliminate duplication.
|
||||
osnma->d_GST_SIS = (1248 & 0x00000FFF) << 20 | (345630 & 0x000FFFFF);
|
||||
osnma->d_GST_0 = ((1248 & 0x00000FFF) << 20 | (345600 & 0x000FFFFF)); // applicable time (GST_Kroot + 30)
|
||||
osnma->d_receiver_time = osnma->d_GST_0 + 30 * std::floor((osnma->d_GST_SIS - osnma->d_GST_0) / 30); // Eq. 3 R.G.//345630;
|
||||
|
||||
osnma->d_tesla_keys.insert((std::pair<uint32_t, std::vector<uint8_t>>(345600,{0xEF, 0xF9, 0x99, 0x04, 0x0E, 0x19, 0xB5, 0x70, 0x83, 0x50, 0x60, 0xBE, 0xBD, 0x23, 0xED, 0x92}))); // K1, not needed, just for reference.
|
||||
std::vector<uint8_t> key = {0x2D, 0xC3, 0xA3, 0xCD, 0xB1, 0x17, 0xFA, 0xAD, 0xB8, 0x3B, 0x5F, 0x0B, 0x6F, 0xEA, 0x88, 0xEB}; // K2
|
||||
|
||||
|
||||
uint32_t TOW = 345630;
|
||||
uint32_t WN = 1248;
|
||||
uint32_t PRNa = 0;
|
||||
uint8_t CTR = 2;
|
||||
|
||||
osnma->d_osnma_data.d_dsm_kroot_message.ts = 0x00;
|
||||
osnma->d_tesla_keys[TOW] = {0xEF, 0xF9};
|
||||
osnma->d_osnma_data.d_dsm_kroot_message.mf = 0x00;
|
||||
osnma->d_satellite_nav_data[PRNa][TOW].ephemeris_iono_vector_2 = "";
|
||||
osnma->d_osnma_data.d_nma_header.nmas = 0b00000010;
|
||||
|
||||
MACK_tag_and_info MTI;
|
||||
MTI.tag = 0x00;
|
||||
MTI.tag_info.PRN_d = 0;
|
||||
MTI.tag_info.ADKD = 0;
|
||||
MTI.tag_info.cop = 0;
|
||||
Tag t(MTI, TOW, WN, PRNa, CTR);
|
||||
|
||||
// Act
|
||||
// ----------
|
||||
bool result = osnma->verify_tag(t);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Assert
|
||||
// ----------
|
||||
ASSERT_TRUE(result);
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user