obu-firmware builds against the vanetza-idf C-ITS library, which until now came from the colleague's microbu-esp32c5 tree beside the repository and was not tracked here, so a clone of this repository could not build the firmware it ships. The library alone is now part of obu-firmware, as obu-firmware/external/vanetza-idf: their external/vanetza-idf at commit cf4b99f, unchanged (9775 files; see its PROVENANCE.md). CMake takes it from there by default; -DVANETZA_IDF_DIR still points the build elsewhere. The rest of the colleague's tree (their own VAM firmware, PKI tooling, station-link Python tools, the V2X2MAP bridge) stays out of this repository and gitignored; nothing is pushed to their repository. NOTES.md, docs/06, TODO.md and the pcap verifier's usage line point at the new location.
104 lines
3.8 KiB
C++
104 lines
3.8 KiB
C++
#include <vanetza/asn1/security_profile.hpp>
|
|
#include VANETZA_ASN1_SECURITY_HEADER(CircularRegion.h)
|
|
#include VANETZA_ASN1_SECURITY_HEADER(PolygonalRegion.h)
|
|
#include VANETZA_ASN1_SECURITY_HEADER(RectangularRegion.h)
|
|
#include VANETZA_ASN1_SECURITY_HEADER(SequenceOfRectangularRegion.h)
|
|
#include VANETZA_ASN1_SECURITY_HEADER(TwoDLocation.h)
|
|
#include <vanetza/common/position_fix.hpp>
|
|
#include <vanetza/security/v3/boost_geometry.hpp>
|
|
#include <vanetza/security/v3/distance.hpp>
|
|
#include <vanetza/security/v3/geometry.hpp>
|
|
#include <boost/geometry/algorithms/within.hpp>
|
|
#include <boost/units/cmath.hpp>
|
|
|
|
namespace vanetza
|
|
{
|
|
namespace security
|
|
{
|
|
namespace v3
|
|
{
|
|
|
|
bool is_valid(const asn1::TwoDLocation& location)
|
|
{
|
|
return location.latitude >= Vanetza_Security_NinetyDegreeInt_min &&
|
|
location.latitude <= Vanetza_Security_NinetyDegreeInt_max &&
|
|
location.longitude >= Vanetza_Security_OneEightyDegreeInt_min &&
|
|
location.longitude <= Vanetza_Security_OneEightyDegreeInt_max;
|
|
}
|
|
|
|
bool is_inside(const PositionFix& location, const asn1::CircularRegion& region)
|
|
{
|
|
if (is_valid(region.center) && region.radius >= 0) {
|
|
return distance(location, region.center) <= region.radius * units::si::meter;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
bool is_inside(const PositionFix& location, const asn1::SequenceOfRectangularRegion& regions)
|
|
{
|
|
for (int i = 0; i < regions.list.count; ++i) {
|
|
if (regions.list.array[i] != nullptr && is_inside(location, *regions.list.array[i])) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
bool is_inside(const PositionFix& location, const asn1::RectangularRegion& region)
|
|
{
|
|
const bool location_valid = isfinite(location.latitude) && isfinite(location.longitude);
|
|
const bool region_valid = is_valid(region.northWest) && is_valid(region.southEast);
|
|
if (location_valid && region_valid) {
|
|
if (region.northWest.latitude <= region.southEast.latitude) {
|
|
// north-west is equal or south of south-east: invalid region
|
|
return false;
|
|
} else if (region.northWest.longitude == region.southEast.longitude) {
|
|
// equal longitudes are invalid
|
|
return false;
|
|
} else {
|
|
static constexpr long scale_90deg = Vanetza_Security_NinetyDegreeInt_max / 90;
|
|
static constexpr long scale_180deg = Vanetza_Security_OneEightyDegreeInt_max / 180;
|
|
Vanetza_Security_NinetyDegreeInt_t loc_lat = location.latitude / units::degree * scale_90deg;
|
|
Vanetza_Security_OneEightyDegreeInt_t loc_lon = location.longitude / units::degree * scale_180deg;
|
|
|
|
if (loc_lat >= region.southEast.latitude && loc_lat <= region.northWest.latitude) {
|
|
if (region.northWest.longitude < region.southEast.longitude) {
|
|
return loc_lon >= region.northWest.longitude && loc_lon <= region.southEast.longitude;
|
|
} else {
|
|
return loc_lon >= region.northWest.longitude || loc_lon <= region.southEast.longitude;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
bool is_inside(const asn1::TwoDLocation* location, const asn1::PolygonalRegion* region)
|
|
{
|
|
if (region && location) {
|
|
PolygonalRegionRingAdapter polygonal_region(*region);
|
|
auto point = make_model(*location);
|
|
return boost::geometry::within(point, polygonal_region);
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
bool is_inside(const PositionFix& location, const asn1::PolygonalRegion& region)
|
|
{
|
|
if (isfinite(location.latitude) && isfinite(location.longitude)) {
|
|
PolygonalRegionRingAdapter polygonal_region(region);
|
|
auto point = make_model(location);
|
|
return boost::geometry::within(point, polygonal_region);
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
} // namespace v3
|
|
} // namespace security
|
|
} // namespace vanetza
|