// Copyright (C) 2017 Vasily Evseenko // based on wifibroadcast (c)2015 befinitiv /* * 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 2. * * 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. */ #ifndef __WIFIBROADCAST_HPP__ #define __WIFIBROADCAST_HPP__ #include #include #include #include #include #include #include #include #include #include #include #include #include #define MAX_PACKET_SIZE 1510 #define MAX_RX_INTERFACES 8 using namespace std; template string string_format( const std::string& format, Args ... args ) { size_t size = snprintf(nullptr, 0, format.c_str(), args ...) + 1; // Extra space for '\0' unique_ptr buf(new char[ size ]); snprintf(buf.get(), size, format.c_str(), args ...); return string(buf.get(), buf.get() + size - 1); // We don't want the '\0' inside } /* this is the template radiotap header we send packets out with */ static const uint8_t radiotap_header[] = { 0x00, 0x00, // <-- radiotap version 0x0c, 0x00, // <- radiotap header lengt 0x04, 0x80, 0x00, 0x00, // <-- radiotap present flags 0x00, // Rate, offset 0x8 0x00, 0x18, 0x00 }; //the last byte of the mac address is recycled as a port number #define SRC_MAC_LASTBYTE 15 #define DST_MAC_LASTBYTE 21 static uint8_t ieee80211_header[] = { 0x08, 0x01, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x13, 0x22, 0x33, 0x44, 0x55, 0x66, 0x13, 0x22, 0x33, 0x44, 0x55, 0x66, 0x10, 0x86, }; typedef struct { uint8_t block_idx; uint8_t fragment_idx; } __attribute__ ((packed)) wblock_hdr_t; typedef struct { uint32_t seq; uint16_t packet_size; } __attribute__ ((packed)) wpacket_hdr_t; #define MAX_PAYLOAD_SIZE (MAX_PACKET_SIZE - sizeof(radiotap_header) - sizeof(ieee80211_header) - sizeof(wblock_hdr_t) - sizeof(wpacket_hdr_t)) #define MAX_FEC_PAYLOAD (MAX_PACKET_SIZE - sizeof(radiotap_header) - sizeof(ieee80211_header) - sizeof(wblock_hdr_t)) #define MAX_FORWARDER_PACKET_SIZE (MAX_PACKET_SIZE - sizeof(radiotap_header) - sizeof(ieee80211_header)) int open_udp_socket_for_rx(int port); #endif