20 #include <boost/algorithm/string/predicate.hpp> 32 prefix_ senf::emu::detail::EmulatedWLANInterfaceNet::EmulatedWLANInterfaceNet()
33 : receiveFilter_(self()), transmitFilter_(self()),
34 beaconGenerator_(self()),
35 receiveInput(receiveFilter_.input),
36 receiveOutput(receiveFilter_.output), transmitInput (transmitFilter_.input),
37 transmitOutput(transmitFilter_.output)
46 boost::uint32_t
const wlanMagic (0x574c414eu);
50 :
Base(receiveOutput, transmitInput), modulationId_(0),
51 power_(0), mode_(ADHOC), dev_(
"NetEMU-WLAN")
53 ppi::connect(receiverJack, receiveInput);
54 ppi::connect(transmitOutput, transmitterJack);
55 ppi::connect(beaconGenerator_, transmitFilter_.beaconInput);
66 namespace senf {
namespace emu {
76 namespace kw = console::kw;
77 namespace fty = console::factory;
78 consoleDir().add(
"beaconInterval", fty::Command(
80 .arg(
"interval",
"Beacon interval for emulated interfaces",
81 kw::parser=senf::parseClockServiceInterval)
82 .doc(
"Get/set the Beacon interval.\n" 83 "An interval of 0 disables the sending of beacons") );
84 consoleDir().add(
"beaconInterval", fty::Command(
86 .formatter(senf::formatClockServiceInterval) );
89 .arg(
"mode",
"ADHOC, STA or AP")
90 .doc(
"Get/set the mode of a WLAN interface") );
93 consoleDir().add(
"registerModulation", fty::Command(
95 .arg(
"type",
"'mcs' or 'legacy'")
96 .arg(
"args",
"if type is mcs, args can be \n 'all' for all mcs indexes,\n" 97 " a range like '1-10' for all indexes in that range, or\n" 98 " a list of indexes like '(1 4 6 10)'\n" 99 "if type is legacy, args can be \n 'all' for all legacy rates, or\n" 100 " a list of rates like '(360, 540)")
101 .doc(
"register modulations") );
118 return modulationId_;
121 prefix_ std::string
const & senf::emu::EmulatedWLANInterface::v_device()
133 prefix_ int senf::emu::EmulatedWLANInterface::v_txPower()
139 prefix_ void senf::emu::EmulatedWLANInterface::v_txPower(
int power)
147 if (modulationId_ == 0)
152 prefix_ void senf::emu::EmulatedWLANInterface::registerVHTModulation(
unsigned vhtMcsIndex,
unsigned streams,
unsigned bandwidth,
bool shortGI)
158 prefix_ void senf::emu::EmulatedWLANInterface::registerHTModulation(
unsigned mcsIndex)
167 prefix_ void senf::emu::EmulatedWLANInterface::registerLegacyModulation(
unsigned rate)
174 #define catch_bad_lexical_cast(arg) \ 175 catch (boost::bad_lexical_cast &) { \ 176 throw console::SyntaxErrorException("argument syntax error: ") << arg; \ 181 if (args.size() != 1 or not boost::algorithm::iequals(args[0],
"all"))
186 for (
unsigned i=0; i<8; ++i) {
187 if (mcsInfo.rate[i] == 0)
194 if (args.size() == 1) {
195 if (boost::algorithm::iequals(args[0],
"all")) {
203 std::string::size_type p = args[0].find(
'-');
204 if (p != std::string::npos) {
206 unsigned start (boost::lexical_cast<unsigned>(args[0].substr(0, p)));
207 unsigned end (boost::lexical_cast<unsigned>(args[0].substr(p+1)));
208 for (
unsigned i=start; i<=end; ++i)
209 registerHTModulation(i);
214 registerHTModulation(boost::lexical_cast<unsigned>(args[0]));
218 for (std::string index : args) {
220 registerHTModulation(boost::lexical_cast<unsigned>(index));
226 if (args.size() == 1 && boost::algorithm::iequals(args[0],
"all")) {
229 registerLegacyModulation( info.rate);
233 registerLegacyModulation( info.rate);
237 for (std::string rate : args) {
239 registerLegacyModulation( boost::lexical_cast<unsigned>(rate));
250 #undef catch_bad_lexical_cast 257 prefix_ senf::emu::detail::EmulatedWLANReceiveFilter::
261 route(input, output);
262 input.onRequest(&EmulatedWLANReceiveFilter::request);
265 prefix_ void senf::emu::detail::EmulatedWLANReceiveFilter::request()
281 if (iface_.annotationMode())
296 prefix_ senf::emu::detail::EmulatedWLANTransmitFilter::
300 route(input, output);
301 route(beaconInput,output);
302 input.onRequest(&EmulatedWLANTransmitFilter::request);
303 beaconInput.onRequest(&EmulatedWLANTransmitFilter::beaconRequest);
306 prefix_ void senf::emu::detail::EmulatedWLANTransmitFilter::request()
309 e->source() = iface_.id();
315 prefix_ void senf::emu::detail::EmulatedWLANTransmitFilter::beaconRequest()
326 prefix_ senf::emu::detail::EmulatedWLANBeaconGenerator::
335 route(timer_,output);
339 prefix_ void senf::emu::detail::EmulatedWLANBeaconGenerator::init()
341 registerEvent( timer_, &EmulatedWLANBeaconGenerator::tick );
346 p->ssidIE().value() <<
"NetEMU";
348 beacon_ = WLANPacket_MgtFrame::createBefore(p);
350 beacon_->sequenceNumber(0u);
357 timer_.enabled(
false);
362 timer_.interval(interval);
366 senf::emu::detail::EmulatedWLANBeaconGenerator::beaconInterval()
368 return timer_.interval().first;
371 prefix_ void senf::emu::detail::EmulatedWLANBeaconGenerator::tick()
376 beacon_->sourceAddress() = iface_.id();
377 beacon_->sequenceNumber(beacon_->sequenceNumber()+1);
379 beacon_.finalizeAll();
380 output(beacon_.clone());
config::time_type clock_type
#define SENF_MEMBINDFNP(ret, cls, fn, args)
static SENF_CLOCKSERVICE_CONSTEXPR int64_type in_milliseconds(clock_type const &v)
static ConcretePacket createBefore(Packet const &packet)
ModulationParameter::id_t parameterIdByMCS_HT(unsigned htMcsIndex, unsigned bandwidth, bool shortGI) const
void registerModulation(ModulationParameter::id_t id)
static constexpr unsigned NUM_HT_INDEX
static SENF_CLOCKSERVICE_CONSTEXPR clock_type seconds(int64_type const &v)
static MACAddress from_string(std::string const &s)
ConcretePacket< WLANBeaconPacketType > WLANBeaconPacket
SENF_CONSOLE_REGISTER_ENUM_MEMBER(DVBModulationParameter, fec_rate_t,(FEC_NONE)(FEC_1_2)(FEC_2_3)(FEC_3_4)(FEC_4_5)(FEC_5_6)(FEC_6_7)(FEC_7_8)(FEC_8_9)(FEC_AUTO)(FEC_3_5)(FEC_9_10))
EthernetPacket prependAnnotationsPacket(Packet const &pkt, MACAddress const &src_=senf::MACAddress::None, MACAddress const &dst_=senf::MACAddress::Broadcast)
WLANPacket_MgtFrameType::packet WLANPacket_MgtFrame
static std::vector< LegacyModulationInfo > getLegacyModulationInfosOFDM()
ModulationParameter::id_t parameterIdByMCS_VHT(unsigned vhtMcsIndex, unsigned streams, unsigned bandwidth, bool shortGI) const
static SENF_CLOCKSERVICE_CONSTEXPR clock_type milliseconds(int64_type const &v)
static SENF_CLOCKSERVICE_CONSTEXPR int64_type in_nanoseconds(clock_type const &v)
console::ScopedDirectory & consoleDir()
static std::vector< LegacyModulationInfo > getLegacyModulationInfos11b()
static std::uint8_t toHTIndex(std::uint8_t index, std::uint8_t streams)
EmulatedWLANInterface public header.
WLANModulationParameter const & findModulationById(ModulationParameter::id_t id) const
static std::vector< Info > getInfos()
static constexpr unsigned NUM_VHT_INDEX
static WLANModulationParameterRegistry & instance()
MACAddress uniqueMAC(boost::uint32_t magic)
Get pseudo-random but unique MACAddress.
#define catch_bad_lexical_cast(arg)
ConcretePacket< EthernetPacketType > EthernetPacket
AnnotationsPacket public header.
static MACAddress const Broadcast
static unsigned fromBandwidthIndex(std::uint8_t bandwidthIndex)
void registerModulation(ModulationParameter::id_t id)
register modulation configuration