Skip to content

Commit fe85e64

Browse files
committed
Add get_fec and get_radio into wfb_tx_cmd
1 parent 050f03b commit fe85e64

File tree

5 files changed

+310
-64
lines changed

5 files changed

+310
-64
lines changed

src/tx.cpp

Lines changed: 86 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ void RawSocketTransmitter::set_mark(uint32_t idx)
205205

206206

207207
RawSocketTransmitter::RawSocketTransmitter(int k, int n, const string &keypair, uint64_t epoch, uint32_t channel_id, uint32_t fec_delay,
208-
vector<tags_item_t> &tags, const vector<string> &wlans, vector<uint8_t> &radiotap_header,
208+
vector<tags_item_t> &tags, const vector<string> &wlans, radiotap_header_t &radiotap_header,
209209
uint8_t frame_type, bool use_qdisc, uint32_t fwmark) : \
210210
Transmitter(k, n, keypair, epoch, channel_id, fec_delay, tags),
211211
channel_id(channel_id),
@@ -284,8 +284,8 @@ void RawSocketTransmitter::inject_packet(const uint8_t *buf, size_t size)
284284
struct iovec iov[3] = \
285285
{
286286
// radiotap header
287-
{ .iov_base = (void*)&radiotap_header[0],
288-
.iov_len = radiotap_header.size()
287+
{ .iov_base = (void*)&radiotap_header.header[0],
288+
.iov_len = radiotap_header.header.size()
289289
},
290290
// ieee80211 header
291291
{ .iov_base = (void*)ieee_hdr,
@@ -580,8 +580,8 @@ void data_source(shared_ptr<Transmitter> &t, vector<int> &rx_fd, int control_fd,
580580

581581
for(;;)
582582
{
583-
cmd_req_t req;
584-
cmd_resp_t resp;
583+
cmd_req_t req = {};
584+
cmd_resp_t resp = {};
585585
ssize_t rsize;
586586
struct sockaddr_in from_addr;
587587
socklen_t addr_size = sizeof(from_addr);
@@ -604,7 +604,7 @@ void data_source(shared_ptr<Transmitter> &t, vector<int> &rx_fd, int control_fd,
604604
if (rsize != offsetof(cmd_req_t, u) + sizeof(req.u.cmd_set_fec))
605605
{
606606
resp.rc = htonl(EINVAL);
607-
sendto(fd, &resp, sizeof(resp), MSG_DONTWAIT, (sockaddr*)&from_addr, addr_size);
607+
sendto(fd, &resp, offsetof(cmd_resp_t, u), MSG_DONTWAIT, (sockaddr*)&from_addr, addr_size);
608608
continue;
609609
}
610610

@@ -614,7 +614,7 @@ void data_source(shared_ptr<Transmitter> &t, vector<int> &rx_fd, int control_fd,
614614
if(!(fec_k <= fec_n && fec_k >=1 && fec_n >= 1 && fec_n < 256))
615615
{
616616
resp.rc = htonl(EINVAL);
617-
sendto(fd, &resp, sizeof(resp), MSG_DONTWAIT, (sockaddr*)&from_addr, addr_size);
617+
sendto(fd, &resp, offsetof(cmd_resp_t, u), MSG_DONTWAIT, (sockaddr*)&from_addr, addr_size);
618618
fprintf(stderr, "Rejecting new FEC settings");
619619
continue;
620620
}
@@ -630,7 +630,7 @@ void data_source(shared_ptr<Transmitter> &t, vector<int> &rx_fd, int control_fd,
630630
t->send_session_key();
631631
}
632632

633-
sendto(fd, &resp, sizeof(resp), MSG_DONTWAIT, (sockaddr*)&from_addr, addr_size);
633+
sendto(fd, &resp, offsetof(cmd_resp_t, u), MSG_DONTWAIT, (sockaddr*)&from_addr, addr_size);
634634
fprintf(stderr, "Session restarted with FEC %d/%d\n", fec_k, fec_n);
635635
}
636636
break;
@@ -640,7 +640,7 @@ void data_source(shared_ptr<Transmitter> &t, vector<int> &rx_fd, int control_fd,
640640
if (rsize != offsetof(cmd_req_t, u) + sizeof(req.u.cmd_set_radio))
641641
{
642642
resp.rc = htonl(EINVAL);
643-
sendto(fd, &resp, sizeof(resp), MSG_DONTWAIT, (sockaddr*)&from_addr, addr_size);
643+
sendto(fd, &resp, offsetof(cmd_resp_t, u), MSG_DONTWAIT, (sockaddr*)&from_addr, addr_size);
644644
continue;
645645
}
646646

@@ -658,12 +658,12 @@ void data_source(shared_ptr<Transmitter> &t, vector<int> &rx_fd, int control_fd,
658658
catch(runtime_error &e)
659659
{
660660
resp.rc = htonl(EINVAL);
661-
sendto(fd, &resp, sizeof(resp), MSG_DONTWAIT, (sockaddr*)&from_addr, addr_size);
661+
sendto(fd, &resp, offsetof(cmd_resp_t, u), MSG_DONTWAIT, (sockaddr*)&from_addr, addr_size);
662662
fprintf(stderr, "Rejecting new radiotap header: %s\n", e.what());
663663
continue;
664664
}
665665

666-
sendto(fd, &resp, sizeof(resp), MSG_DONTWAIT, (sockaddr*)&from_addr, addr_size);
666+
sendto(fd, &resp, offsetof(cmd_resp_t, u), MSG_DONTWAIT, (sockaddr*)&from_addr, addr_size);
667667
fprintf(stderr,
668668
"Radiotap updated with stbc=%d, ldpc=%d, short_gi=%d, bandwidth=%d, mcs_index=%d, vht_mode=%d, vht_nss=%d\n",
669669
req.u.cmd_set_radio.stbc,
@@ -676,10 +676,53 @@ void data_source(shared_ptr<Transmitter> &t, vector<int> &rx_fd, int control_fd,
676676
}
677677
break;
678678

679+
case CMD_GET_FEC:
680+
{
681+
int fec_k = 0, fec_n = 0;
682+
683+
if (rsize != offsetof(cmd_req_t, u))
684+
{
685+
resp.rc = htonl(EINVAL);
686+
sendto(fd, &resp, offsetof(cmd_resp_t, u), MSG_DONTWAIT, (sockaddr*)&from_addr, addr_size);
687+
continue;
688+
}
689+
690+
t->get_fec(fec_k, fec_n);
691+
692+
resp.u.cmd_get_fec.k = fec_k;
693+
resp.u.cmd_get_fec.n = fec_n;
694+
695+
sendto(fd, &resp, offsetof(cmd_resp_t, u) + sizeof(resp.u.cmd_get_fec), MSG_DONTWAIT, (sockaddr*)&from_addr, addr_size);
696+
}
697+
break;
698+
699+
case CMD_GET_RADIO:
700+
{
701+
if (rsize != offsetof(cmd_req_t, u))
702+
{
703+
resp.rc = htonl(EINVAL);
704+
sendto(fd, &resp, offsetof(cmd_resp_t, u), MSG_DONTWAIT, (sockaddr*)&from_addr, addr_size);
705+
continue;
706+
}
707+
708+
radiotap_header_t hdr = t->get_radiotap_header();
709+
710+
resp.u.cmd_get_radio.stbc = hdr.stbc;
711+
resp.u.cmd_get_radio.ldpc = hdr.ldpc;
712+
resp.u.cmd_get_radio.short_gi = hdr.short_gi;
713+
resp.u.cmd_get_radio.bandwidth = hdr.bandwidth;
714+
resp.u.cmd_get_radio.mcs_index = hdr.mcs_index;
715+
resp.u.cmd_get_radio.vht_mode = hdr.vht_mode;
716+
resp.u.cmd_get_radio.vht_nss = hdr.vht_nss;
717+
718+
sendto(fd, &resp, offsetof(cmd_resp_t, u) + sizeof(resp.u.cmd_get_radio), MSG_DONTWAIT, (sockaddr*)&from_addr, addr_size);
719+
}
720+
break;
721+
679722
default:
680723
{
681724
resp.rc = htonl(ENOTSUP);
682-
sendto(fd, &resp, sizeof(resp), MSG_DONTWAIT, (sockaddr*)&from_addr, addr_size);
725+
sendto(fd, &resp, offsetof(cmd_resp_t, u), MSG_DONTWAIT, (sockaddr*)&from_addr, addr_size);
683726
continue;
684727
}
685728
break;
@@ -790,15 +833,24 @@ void data_source(shared_ptr<Transmitter> &t, vector<int> &rx_fd, int control_fd,
790833
}
791834

792835

793-
vector<uint8_t> init_radiotap_header(uint8_t stbc,
794-
bool ldpc,
795-
bool short_gi,
796-
uint8_t bandwidth,
797-
uint8_t mcs_index,
798-
bool vht_mode,
799-
uint8_t vht_nss)
836+
radiotap_header_t init_radiotap_header(uint8_t stbc,
837+
bool ldpc,
838+
bool short_gi,
839+
uint8_t bandwidth,
840+
uint8_t mcs_index,
841+
bool vht_mode,
842+
uint8_t vht_nss)
800843
{
801-
vector<uint8_t> radiotap_header;
844+
radiotap_header_t res = {
845+
.header = {},
846+
.stbc = stbc,
847+
.ldpc = ldpc,
848+
.short_gi = short_gi,
849+
.bandwidth = bandwidth,
850+
.mcs_index = mcs_index,
851+
.vht_mode = vht_mode,
852+
.vht_nss = vht_nss,
853+
};
802854

803855
if (!vht_mode)
804856
{
@@ -847,17 +899,17 @@ vector<uint8_t> init_radiotap_header(uint8_t stbc,
847899
flags |= IEEE80211_RADIOTAP_MCS_FEC_LDPC;
848900
}
849901

850-
copy(radiotap_header_ht, radiotap_header_ht + sizeof(radiotap_header_ht), back_inserter(radiotap_header));
902+
copy(radiotap_header_ht, radiotap_header_ht + sizeof(radiotap_header_ht), back_inserter(res.header));
851903

852-
radiotap_header[MCS_FLAGS_OFF] = flags;
853-
radiotap_header[MCS_IDX_OFF] = mcs_index;
904+
res.header[MCS_FLAGS_OFF] = flags;
905+
res.header[MCS_IDX_OFF] = mcs_index;
854906
}
855907
else
856908
{
857909
// Set flags in VHT radiotap header
858910
uint8_t flags = 0;
859911

860-
copy(radiotap_header_vht, radiotap_header_vht + sizeof(radiotap_header_vht), back_inserter(radiotap_header));
912+
copy(radiotap_header_vht, radiotap_header_vht + sizeof(radiotap_header_vht), back_inserter(res.header));
861913

862914
if (short_gi)
863915
{
@@ -872,35 +924,35 @@ vector<uint8_t> init_radiotap_header(uint8_t stbc,
872924
switch(bandwidth)
873925
{
874926
case 10:
875-
radiotap_header[VHT_BW_OFF] = IEEE80211_RADIOTAP_VHT_BW_20M;
927+
res.header[VHT_BW_OFF] = IEEE80211_RADIOTAP_VHT_BW_20M;
876928
break;
877929
case 20:
878-
radiotap_header[VHT_BW_OFF] = IEEE80211_RADIOTAP_VHT_BW_20M;
930+
res.header[VHT_BW_OFF] = IEEE80211_RADIOTAP_VHT_BW_20M;
879931
break;
880932
case 40:
881-
radiotap_header[VHT_BW_OFF] = IEEE80211_RADIOTAP_VHT_BW_40M;
933+
res.header[VHT_BW_OFF] = IEEE80211_RADIOTAP_VHT_BW_40M;
882934
break;
883935
case 80:
884-
radiotap_header[VHT_BW_OFF] = IEEE80211_RADIOTAP_VHT_BW_80M;
936+
res.header[VHT_BW_OFF] = IEEE80211_RADIOTAP_VHT_BW_80M;
885937
break;
886938
case 160:
887-
radiotap_header[VHT_BW_OFF] = IEEE80211_RADIOTAP_VHT_BW_160M;
939+
res.header[VHT_BW_OFF] = IEEE80211_RADIOTAP_VHT_BW_160M;
888940
break;
889941
default:
890942
throw runtime_error(string_format("Unsupported VHT bandwidth: %d", bandwidth));
891943
}
892944

893945
if (ldpc)
894946
{
895-
radiotap_header[VHT_CODING_OFF] = IEEE80211_RADIOTAP_VHT_CODING_LDPC_USER0;
947+
res.header[VHT_CODING_OFF] = IEEE80211_RADIOTAP_VHT_CODING_LDPC_USER0;
896948
}
897949

898-
radiotap_header[VHT_FLAGS_OFF] = flags;
899-
radiotap_header[VHT_MCSNSS0_OFF] |= ((mcs_index << IEEE80211_RADIOTAP_VHT_MCS_SHIFT) & IEEE80211_RADIOTAP_VHT_MCS_MASK);
900-
radiotap_header[VHT_MCSNSS0_OFF] |= ((vht_nss << IEEE80211_RADIOTAP_VHT_NSS_SHIFT) & IEEE80211_RADIOTAP_VHT_NSS_MASK);
950+
res.header[VHT_FLAGS_OFF] = flags;
951+
res.header[VHT_MCSNSS0_OFF] |= ((mcs_index << IEEE80211_RADIOTAP_VHT_MCS_SHIFT) & IEEE80211_RADIOTAP_VHT_MCS_MASK);
952+
res.header[VHT_MCSNSS0_OFF] |= ((vht_nss << IEEE80211_RADIOTAP_VHT_NSS_SHIFT) & IEEE80211_RADIOTAP_VHT_NSS_MASK);
901953
}
902954

903-
return radiotap_header;
955+
return res;
904956
}
905957

906958

src/tx.hpp

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,19 @@ typedef struct {
3939
} tags_item_t;
4040

4141

42+
typedef struct {
43+
std::vector<uint8_t> header;
44+
45+
// header info
46+
uint8_t stbc;
47+
bool ldpc;
48+
bool short_gi;
49+
uint8_t bandwidth;
50+
uint8_t mcs_index;
51+
bool vht_mode;
52+
uint8_t vht_nss;
53+
} radiotap_header_t;
54+
4255
class Transmitter
4356
{
4457
public:
@@ -47,9 +60,11 @@ class Transmitter
4760
bool send_packet(const uint8_t *buf, size_t size, uint8_t flags);
4861
void send_session_key(void);
4962
void init_session(int k, int n);
63+
void get_fec(int &k, int &n) { k = fec_k; n = fec_n; }
5064
virtual void select_output(int idx) = 0;
5165
virtual void dump_stats(FILE *fp, uint64_t ts, uint32_t &injected_packets, uint32_t &dropped_packets, uint32_t &injected_bytes) = 0;
52-
virtual void update_radiotap_header(std::vector<uint8_t> &radiotap_header) {}
66+
virtual void update_radiotap_header(radiotap_header_t &radiotap_header) = 0;
67+
virtual radiotap_header_t get_radiotap_header(void) = 0;
5368
protected:
5469
virtual void inject_packet(const uint8_t *buf, size_t size) = 0;
5570
virtual void set_mark(uint32_t idx) = 0;
@@ -124,7 +139,7 @@ class RawSocketTransmitter : public Transmitter
124139
{
125140
public:
126141
RawSocketTransmitter(int k, int n, const std::string &keypair, uint64_t epoch, uint32_t channel_id, uint32_t fec_delay, std::vector<tags_item_t> &tags,
127-
const std::vector<std::string> &wlans, std::vector<uint8_t> &radiotap_header,
142+
const std::vector<std::string> &wlans, radiotap_header_t &radiotap_header,
128143
uint8_t frame_type, bool use_qdisc, uint32_t fwmark);
129144
virtual ~RawSocketTransmitter();
130145
virtual void select_output(int idx)
@@ -139,11 +154,16 @@ class RawSocketTransmitter : public Transmitter
139154
}
140155
}
141156
virtual void dump_stats(FILE *fp, uint64_t ts, uint32_t &injected_packets, uint32_t &dropped_packets, uint32_t &injected_bytes);
142-
virtual void update_radiotap_header(std::vector<uint8_t> &radiotap_header)
157+
virtual void update_radiotap_header(radiotap_header_t &radiotap_header)
143158
{
144159
this->radiotap_header = radiotap_header;
145160
}
146161

162+
virtual radiotap_header_t get_radiotap_header(void)
163+
{
164+
return radiotap_header;
165+
}
166+
147167
private:
148168
virtual void inject_packet(const uint8_t *buf, size_t size);
149169
virtual void set_mark(uint32_t idx);
@@ -152,7 +172,7 @@ class RawSocketTransmitter : public Transmitter
152172
uint16_t ieee80211_seq;
153173
std::vector<int> sockfds;
154174
tx_antenna_stat_t antenna_stat;
155-
std::vector<uint8_t> radiotap_header;
175+
radiotap_header_t radiotap_header;
156176
const uint8_t frame_type;
157177
const bool use_qdisc;
158178
const uint32_t fwmark;
@@ -164,7 +184,7 @@ class UdpTransmitter : public Transmitter
164184
public:
165185
UdpTransmitter(int k, int n, const std::string &keypair, const std::string &client_addr, int base_port, uint64_t epoch, uint32_t channel_id,
166186
uint32_t fec_delay, std::vector<tags_item_t> &tags, bool use_qdisc, uint32_t fwmark): \
167-
Transmitter(k, n, keypair, epoch, channel_id, fec_delay, tags), base_port(base_port), use_qdisc(use_qdisc), fwmark(fwmark)
187+
Transmitter(k, n, keypair, epoch, channel_id, fec_delay, tags), radiotap_header({}), base_port(base_port), use_qdisc(use_qdisc), fwmark(fwmark)
168188
{
169189
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
170190
if (sockfd < 0) throw std::runtime_error(string_format("Error opening socket: %s", strerror(errno)));
@@ -202,6 +222,17 @@ class UdpTransmitter : public Transmitter
202222
}
203223
}
204224

225+
virtual void update_radiotap_header(radiotap_header_t &radiotap_header)
226+
{
227+
this->radiotap_header = radiotap_header;
228+
}
229+
230+
virtual radiotap_header_t get_radiotap_header(void)
231+
{
232+
return radiotap_header;
233+
}
234+
235+
205236
private:
206237
virtual void inject_packet(const uint8_t *buf, size_t size)
207238
{
@@ -235,17 +266,18 @@ class UdpTransmitter : public Transmitter
235266
sendmsg(sockfd, &msghdr, MSG_DONTWAIT);
236267
}
237268

269+
radiotap_header_t radiotap_header;
238270
int sockfd;
239271
int base_port;
240272
struct sockaddr_in saddr;
241273
const bool use_qdisc;
242274
const uint32_t fwmark;
243275
};
244276

245-
std::vector<uint8_t> init_radiotap_header(uint8_t stbc,
246-
bool ldpc,
247-
bool short_gi,
248-
uint8_t bandwidth,
249-
uint8_t mcs_index,
250-
bool vht_mode,
251-
uint8_t vht_nss);
277+
radiotap_header_t init_radiotap_header(uint8_t stbc,
278+
bool ldpc,
279+
bool short_gi,
280+
uint8_t bandwidth,
281+
uint8_t mcs_index,
282+
bool vht_mode,
283+
uint8_t vht_nss);

0 commit comments

Comments
 (0)