Skip to content
This repository has been archived by the owner on Dec 28, 2020. It is now read-only.

Commit

Permalink
copy as much as possible from tx_rawsock int WFBHelper namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
Consti10 committed Nov 28, 2020
1 parent 1d37c80 commit 7a6803b
Show file tree
Hide file tree
Showing 12 changed files with 2,794 additions and 7 deletions.
280 changes: 280 additions & 0 deletions WFBTransmitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,286 @@

#include <cstdlib>
#include <cstdint>
#include "fec.h"
#include "openhdlib.h"
#include "wifibroadcast.h"
#include <fcntl.h>
#include <getopt.h>
#include <net/if.h>
#include <netinet/ether.h>
#include <netpacket/packet.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/resource.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <termios.h>
#include <time.h>
#include <unistd.h>

namespace WFBHelper{
// copy paste from tx_rawsock
static u8 u8aRadiotapHeader[] = {
0x00, 0x00, // <-- radiotap version
0x0c, 0x00, // <- radiotap header length
0x04, 0x80, 0x00, 0x00, // <-- radiotap present flags (rate + tx flags)
0x00, // datarate (will be overwritten later in packet_header_init)
0x00, // ??
0x00, 0x00 // ??
};
static u8 u8aRadiotapHeader80211N[] __attribute__((unused)) = {
0x00, 0x00, // <-- radiotap version
0x0d, 0x00, // <- radiotap header length
0x00, 0x80, 0x08, 0x00, // <-- radiotap present flags: RADIOTAP_TX_FLAGS + RADIOTAP_MCS
0x08, 0x00, // RADIOTAP_F_TX_NOACK
0, 0, 0 // bitmap, flags, mcs_index
};
static u8 u8aIeeeHeader_data_short[] = {
0x08, 0x01, 0x00, 0x00, // frame control field (2bytes), duration (2 bytes)
0xff // port = 1st byte of IEEE802.11 RA (mac) must be something odd (wifi hardware determines broadcast/multicast through odd/even check)
};
static u8 u8aIeeeHeader_data[] = {
0x08, 0x02, 0x00, 0x00, // frame control field (2bytes), duration (2 bytes)
0xff, 0x00, 0x00, 0x00, 0x00, 0x00, // port = 1st byte of IEEE802.11 RA (mac) must be something odd (wifi hardware determines broadcast/multicast through odd/even check)
0x13, 0x22, 0x33, 0x44, 0x55, 0x66, // mac
0x13, 0x22, 0x33, 0x44, 0x55, 0x66, // mac
0x00, 0x00 // IEEE802.11 seqnum, (will be overwritten later by Atheros firmware/wifi chip)
};
static u8 u8aIeeeHeader_rts[] = {
0xb4, 0x01, 0x00, 0x00, // frame control field (2 bytes), duration (2 bytes)
0xff, // port = 1st byte of IEEE802.11 RA (mac) must be something odd (wifi hardware determines broadcast/multicast through odd/even check)
};
static int packet_header_init80211N(uint8_t *packet_header, int type, int port) {
u8 *pu8 = packet_header;

int port_encoded = 0;

memcpy(packet_header, u8aRadiotapHeader80211N, sizeof(u8aRadiotapHeader80211N));
pu8 += sizeof(u8aRadiotapHeader80211N);

switch (type) {
case 0: {
/*
* Short DATA frame
*/
fprintf(stderr, "using short DATA frames\n");

port_encoded = (port * 2) + 1;

/*
* First byte of RA mac is the port
*/
u8aIeeeHeader_data_short[4] = port_encoded;

/*
* Copy data short header to pu8
*/
memcpy(pu8, u8aIeeeHeader_data_short, sizeof(u8aIeeeHeader_data_short));
pu8 += sizeof(u8aIeeeHeader_data_short);

break;
}
case 1: {
/*
* Standard DATA frame
*
*/
fprintf(stderr, "using standard DATA frames\n");

port_encoded = (port * 2) + 1;

/*
* First byte of RA mac is the port
*/
u8aIeeeHeader_data[4] = port_encoded;

/*
* Copy data header to pu8
*/
memcpy(pu8, u8aIeeeHeader_data, sizeof(u8aIeeeHeader_data));
pu8 += sizeof(u8aIeeeHeader_data);

break;
}
case 2: {
/*
* RTS frame
*
*/
fprintf(stderr, "using RTS frames\n");

port_encoded = (port * 2) + 1;

/*
* First byte of RA mac is the port
*/
u8aIeeeHeader_rts[4] = port_encoded;

/*
* Copy RTS header to pu8
*/
memcpy(pu8, u8aIeeeHeader_rts, sizeof(u8aIeeeHeader_rts));
pu8 += sizeof(u8aIeeeHeader_rts);

break;
}
default: {
fprintf(stderr, "ERROR: Wrong or no frame type specified (see -t parameter)\n");

exit(1);

break;
}
}

/*
* The length of the header
*/
return pu8 - packet_header;
}
static int packet_header_init(uint8_t *packet_header, int type, int rate, int port) {
u8 *pu8 = packet_header;

int port_encoded = 0;

switch (rate) {
case 1: {
u8aRadiotapHeader[8] = 0x02;
break;
}
case 2: {
u8aRadiotapHeader[8] = 0x04;
break;
}
case 5: {
// 5.5
u8aRadiotapHeader[8] = 0x0b;
break;
}
case 6: {
u8aRadiotapHeader[8] = 0x0c;
break;
}
case 11: {
u8aRadiotapHeader[8] = 0x16;
break;
}
case 12: {
u8aRadiotapHeader[8] = 0x18;
break;
}
case 18: {
u8aRadiotapHeader[8] = 0x24;
break;
}
case 24: {
u8aRadiotapHeader[8] = 0x30;
break;
}
case 36: {
u8aRadiotapHeader[8] = 0x48;
break;
}
case 48: {
u8aRadiotapHeader[8] = 0x60;
break;
}
default: {
fprintf(stderr, "ERROR: Wrong or no data rate specified (see -d parameter)\n");
exit(1);

break;
}
}

memcpy(packet_header, u8aRadiotapHeader, sizeof(u8aRadiotapHeader));
pu8 += sizeof(u8aRadiotapHeader);

switch (type) {
case 0: {
/*
* Short DATA frame
*/
fprintf(stderr, "using short DATA frames\n");

port_encoded = (port * 2) + 1;

/*
* First byte of RA mac is the port
*/
u8aIeeeHeader_data_short[4] = port_encoded;

/*
* Copy data short header to pu8
*/
memcpy(pu8, u8aIeeeHeader_data_short, sizeof(u8aIeeeHeader_data_short));
pu8 += sizeof(u8aIeeeHeader_data_short);


break;
}
case 1: {
/*
* Standard DATA frame
*/
fprintf(stderr, "using standard DATA frames\n");

port_encoded = (port * 2) + 1;

/*
* First byte of RA mac is the port
*/
u8aIeeeHeader_data[4] = port_encoded;

/*
* Copy data header to pu8
*/
memcpy(pu8, u8aIeeeHeader_data, sizeof(u8aIeeeHeader_data));
pu8 += sizeof(u8aIeeeHeader_data);


break;
}
case 2: {
/*
* RTS frame
*/
fprintf(stderr, "using RTS frames\n");

port_encoded = (port * 2) + 1;

/*
* First byte of RA mac is the port
*/
u8aIeeeHeader_rts[4] = port_encoded;

/*
* Copy RTS header to pu8
*/
memcpy(pu8, u8aIeeeHeader_rts, sizeof(u8aIeeeHeader_rts));
pu8 += sizeof(u8aIeeeHeader_rts);


break;
}
default:
fprintf(stderr, "ERROR: Wrong or no frame type specified (see -t parameter)\n");

exit(1);


break;
}

/*
* The length of just the header
*/
return pu8 - packet_header;
}
}

class WFBTransmitter {
public:
Expand Down
8 changes: 8 additions & 0 deletions cmake-build-debug/CMakeFiles/xopenhd.dir/C.includecache
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#IncludeRegexLine: ^[ ]*[#%][ ]*(include|import)[ ]*[<"]([^">]+)([">])

#IncludeRegexScan: ^.*$

#IncludeRegexComplain: ^$

#IncludeRegexTransform:

60 changes: 53 additions & 7 deletions cmake-build-debug/CMakeFiles/xopenhd.dir/CXX.includecache
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ WFBTransmitter.h
/home/consti10/Desktop/XOpenHD/WFBTransmitter.h
iostream
-

/home/consti10/Desktop/XOpenHD/WFBTransmitter.h
cstdlib
-
cstdint
-
fec.h
/home/consti10/Desktop/XOpenHD/fec.h
openhdlib.h
Expand Down Expand Up @@ -49,16 +55,56 @@ time.h
-
unistd.h
-
sys/time.h
-

/home/consti10/Desktop/XOpenHD/WFBTransmitter.h
cstdlib
-
cstdint
-
/home/consti10/Desktop/XOpenHD/fec.h

/home/consti10/Desktop/XOpenHD/main.cpp
iostream
-
fec.h
/home/consti10/Desktop/XOpenHD/fec.h
openhdlib.h
/home/consti10/Desktop/XOpenHD/openhdlib.h
fec.h
/home/consti10/Desktop/XOpenHD/fec.h
openhdlib.h
/home/consti10/Desktop/XOpenHD/openhdlib.h
wifibroadcast.h
/home/consti10/Desktop/XOpenHD/wifibroadcast.h
fcntl.h
-
getopt.h
-
net/if.h
-
netinet/ether.h
-
netpacket/packet.h
-
stdint.h
-
stdio.h
-
stdlib.h
-
string.h
-
sys/ioctl.h
-
sys/resource.h
-
sys/stat.h
-
sys/types.h
-
termios.h
-
time.h
-
unistd.h
-
WFBTransmitter.h
/home/consti10/Desktop/XOpenHD/WFBTransmitter.h

/home/consti10/Desktop/XOpenHD/openhdlib.h
wifibroadcast.h
Expand Down
Binary file not shown.
Binary file added cmake-build-debug/CMakeFiles/xopenhd.dir/fec.c.o
Binary file not shown.
Binary file modified cmake-build-debug/CMakeFiles/xopenhd.dir/main.cpp.o
Binary file not shown.
Binary file added cmake-build-debug/xopenhd
Binary file not shown.
Loading

0 comments on commit 7a6803b

Please sign in to comment.