Add an "Append CRC32" block

This commit is contained in:
Nicolas Guillaume
2025-12-22 12:56:00 +01:00
committed by Bastian Bloessl
parent ac55ae7ca1
commit 7e9c132dfb
11 changed files with 262 additions and 3 deletions
+2 -1
View File
@@ -16,5 +16,6 @@ install(FILES
ieee802_11_mapper.block.yml ieee802_11_mapper.block.yml
ieee802_11_parse_mac.block.yml ieee802_11_parse_mac.block.yml
ieee802_11_sync_long.block.yml ieee802_11_sync_long.block.yml
ieee802_11_sync_short.block.yml DESTINATION share/gnuradio/grc/blocks ieee802_11_sync_short.block.yml
ieee802_11_append_crc32.block.yml DESTINATION share/gnuradio/grc/blocks
) )
+26
View File
@@ -0,0 +1,26 @@
id: ieee802_11_append_crc32
label: Append CRC32
category: '[IEEE802.11]'
parameters:
- id: append
label: Append
dtype: bool
default: 'True'
options: ['True', 'False']
option_labels: [Enable, Disable]
inputs:
- domain: message
id: in
outputs:
- domain: message
id: out
optional: true
templates:
imports: import ieee802_11
make: ieee802_11.append_crc32(${append})
file_format: 1
+1 -1
View File
@@ -23,5 +23,5 @@ install(FILES
signal_field.h signal_field.h
sync_long.h sync_long.h
sync_short.h sync_short.h
DESTINATION include/ieee802_11 append_crc32.h DESTINATION include/ieee802_11
) )
+36
View File
@@ -0,0 +1,36 @@
/*
* Copyright (C) 2025 Nicolas Guillaume <nicol@sguillau.me>
*
* 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 INCLUDED_IEEE802_11_APPEND_CRC32_H
#define INCLUDED_IEEE802_11_APPEND_CRC32_H
#include <gnuradio/block.h>
#include <ieee802_11/api.h>
namespace gr {
namespace ieee802_11 {
class IEEE802_11_API append_crc32 : virtual public block
{
public:
typedef std::shared_ptr<append_crc32> sptr;
static sptr make(bool append = true);
};
}
}
#endif
+1
View File
@@ -40,6 +40,7 @@ list(APPEND ieee802_11_sources
sync_short.cc sync_short.cc
utils.cc utils.cc
viterbi_decoder/base.cc viterbi_decoder/base.cc
append_crc32_impl.cc
) )
# use SSE2 optimized viterbi implementation if SSE2 is enabled # use SSE2 optimized viterbi implementation if SSE2 is enabled
+84
View File
@@ -0,0 +1,84 @@
/*
* Copyright (C) 2025 Nicolas Guillaume <nicol@sguillau.me>
*
* 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/>.
*/
#include "append_crc32_impl.h"
#include <gnuradio/block_detail.h>
#include <gnuradio/io_signature.h>
#include <boost/bind/bind.hpp>
#include <boost/crc.hpp>
#include <cstdint>
#include <cstring>
#include <stdexcept>
#include <vector>
using namespace gr::ieee802_11;
append_crc32::sptr append_crc32::make(bool append)
{
return gnuradio::get_initial_sptr(new append_crc32_impl(append));
}
append_crc32_impl::append_crc32_impl(bool append)
: block("append_crc32",
gr::io_signature::make(0, 0, 0),
gr::io_signature::make(0, 0, 0)),
d_append(append)
{
message_port_register_in(pmt::mp("in"));
set_msg_handler(pmt::mp("in"), boost::bind(&append_crc32_impl::handle, this, boost::placeholders::_1));
message_port_register_out(pmt::mp("out"));
}
void append_crc32_impl::handle(pmt::pmt_t msg)
{
if(pmt::is_eof_object(msg))
{
detail().get()->set_done(true);
return;
}
if(!pmt::is_pair(msg))
throw std::invalid_argument("append_crc32 expects PDU pair");
pmt::pmt_t meta = pmt::car(msg);
pmt::pmt_t blob = pmt::cdr(msg);
if(!pmt::is_blob(blob))
throw std::invalid_argument("append_crc32 expects blob payload");
if(!d_append)
{
message_port_pub(pmt::mp("out"), pmt::cons(meta, blob));
return;
}
size_t len = pmt::blob_length(blob);
const uint8_t* data = reinterpret_cast<const uint8_t*>(pmt::blob_data(blob));
boost::crc_32_type result;
result.process_bytes(data, len);
uint32_t crc = result.checksum();
std::vector<uint8_t> out(len + sizeof(uint32_t));
std::memcpy(out.data(), data, len);
std::memcpy(out.data() + len, &crc, sizeof(uint32_t));
pmt::pmt_t out_blob = pmt::make_blob(out.data(), out.size());
message_port_pub(pmt::mp("out"), pmt::cons(meta, out_blob));
}
+40
View File
@@ -0,0 +1,40 @@
/*
* Copyright (C) 2025 Nicolas Guillaume <nicol@sguillau.me>
*
* 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 INCLUDED_IEEE802_11_APPEND_CRC32_IMPL_H
#define INCLUDED_IEEE802_11_APPEND_CRC32_IMPL_H
#include <ieee802_11/append_crc32.h>
#include <pmt/pmt.h>
namespace gr {
namespace ieee802_11 {
class append_crc32_impl : public append_crc32
{
public:
append_crc32_impl(bool append);
private:
void handle(pmt::pmt_t msg);
bool d_append;
};
}
}
#endif
+1 -1
View File
@@ -41,7 +41,7 @@ list(APPEND ieee802_11_python_files
signal_field_python.cc signal_field_python.cc
sync_long_python.cc sync_long_python.cc
sync_short_python.cc sync_short_python.cc
python_bindings.cc) append_crc32_python.cc python_bindings.cc)
GR_PYBIND_MAKE_OOT(ieee802_11 GR_PYBIND_MAKE_OOT(ieee802_11
../.. ../..
+45
View File
@@ -0,0 +1,45 @@
/*
* Copyright 2025 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
*/
/***********************************************************************************/
/* This file is automatically generated using bindtool and can be manually edited */
/* The following lines can be configured to regenerate this file during cmake */
/* If manual edits are made, the following tags should be modified accordingly. */
/* BINDTOOL_GEN_AUTOMATIC(1) */
/* BINDTOOL_USE_PYGCCXML(0) */
/* BINDTOOL_HEADER_FILE(append_crc32.h) */
/* BINDTOOL_HEADER_FILE_HASH(de483541a761081a4686ff1953728f8a) */
/***********************************************************************************/
#include <pybind11/complex.h>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
namespace py = pybind11;
#include <ieee802_11/append_crc32.h>
// pydoc.h is automatically generated in the build directory
#include <append_crc32_pydoc.h>
void bind_append_crc32(py::module& m)
{
using append_crc32 = ::gr::ieee802_11::append_crc32;
py::class_<append_crc32, gr::block, gr::basic_block, std::shared_ptr<append_crc32>>(
m, "append_crc32", D(append_crc32))
.def(py::init(&append_crc32::make),
py::arg("append") = true,
D(append_crc32, make))
;
}
@@ -0,0 +1,24 @@
/*
* Copyright 2025 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
*/
#include "pydoc_macros.h"
#define D(...) DOC(gr, ieee802_11, __VA_ARGS__)
/*
This file contains placeholders for docstrings for the Python bindings.
Do not edit! These were automatically extracted during the binding process
and will be overwritten during the build process
*/
static const char* __doc_gr_ieee802_11_append_crc32 = R"doc()doc";
static const char* __doc_gr_ieee802_11_append_crc32_append_crc32_0 = R"doc()doc";
static const char* __doc_gr_ieee802_11_append_crc32_make = R"doc()doc";
+2
View File
@@ -33,6 +33,7 @@ void bind_parse_mac(py::module& m);
void bind_signal_field(py::module& m); void bind_signal_field(py::module& m);
void bind_sync_long(py::module& m); void bind_sync_long(py::module& m);
void bind_sync_short(py::module& m); void bind_sync_short(py::module& m);
void bind_append_crc32(py::module& m);
// ) END BINDING_FUNCTION_PROTOTYPES // ) END BINDING_FUNCTION_PROTOTYPES
@@ -74,5 +75,6 @@ PYBIND11_MODULE(ieee802_11_python, m)
bind_signal_field(m); bind_signal_field(m);
bind_sync_long(m); bind_sync_long(m);
bind_sync_short(m); bind_sync_short(m);
bind_append_crc32(m);
// ) END BINDING_FUNCTION_CALLS // ) END BINDING_FUNCTION_CALLS
} }