GNU Radio's IEEE802_11 Package
utils.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2013 Bastian Bloessl <bloessl@ccs-labs.org>
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17#ifndef INCLUDED_IEEE802_11_UTILS_H
18#define INCLUDED_IEEE802_11_UTILS_H
19
20#include <gnuradio/config.h>
21#include <ieee802_11/api.h>
22#include <ieee802_11/mapper.h>
23#include <cinttypes>
24#include <iostream>
25
27
28#define MAX_PAYLOAD_SIZE 1500
29#define MAX_PSDU_SIZE (MAX_PAYLOAD_SIZE + 28) // MAC, CRC
30#define MAX_SYM (((16 + 8 * MAX_PSDU_SIZE + 6) / 24) + 1)
31#define MAX_BITS_PER_SYM 288
32#define MAX_ENCODED_BITS ((16 + 8 * MAX_PSDU_SIZE + 6) * 2 + MAX_BITS_PER_SYM)
33
34#define dout d_debug&& std::cout
35#define mylog(...) \
36 do { \
37 if (d_log) { \
38 d_logger->info(__VA_ARGS__); \
39 } \
40 } while (0);
41
42#pragma pack(push, 1)
43struct mac_header {
44 // protocol version, type, subtype, to_ds, from_ds, ...
45 uint16_t frame_control;
46 uint16_t duration;
47 uint8_t addr1[6];
48 uint8_t addr2[6];
49 uint8_t addr3[6];
50 uint16_t seq_nr;
51};
52#pragma pack(pop)
53
54/**
55 * WIFI parameters
56 */
58{
59public:
61
62 // data rate
64 // rate field of the SIGNAL header
66 // number of coded bits per sub carrier
67 int n_bpsc;
68 // number of coded bits per OFDM symbol
69 int n_cbps;
70 // number of data bits per OFDM symbol
71 int n_dbps;
72
73 void print();
74};
75
76/**
77 * packet specific parameters
78 */
80{
81public:
82 frame_param(ofdm_param& ofdm, int psdu_length);
83 // PSDU size in bytes
85 // number of OFDM symbols (17-11)
86 int n_sym;
87 // number of padding bits in the DATA field (17-13)
88 int n_pad;
90 // number of data bits, including service and padding (17-12)
92
93 void print();
94};
95
96/**
97 * Given a payload, generates a MAC data frame (i.e., a PSDU) to be given
98 * to the physical layer for encoding.
99 *
100 * \param msdu the payload for the MAC frame
101 * \param msdu_size the size of the msdu in bytes
102 * \param psdu pointer to a byte array where to store the MAC frame. Memory
103 * will be alloced by the function
104 * \param psdu_size pointer to an integer where the size of the psdu in bytes
105 * will be stored
106 * \param seq sequence number of the frame
107 */
109 const char* msdu, int msdu_size, char** psdu, int* psdu_size, char seq);
110
111void scramble(const char* input, char* out, frame_param& frame, char initial_state);
112
113void reset_tail_bits(char* scrambled_data, frame_param& frame);
114
115void convolutional_encoding(const char* input, char* out, frame_param& frame);
116
117void puncturing(const char* input, char* out, frame_param& frame, ofdm_param& ofdm);
118
119void interleave(const char* input,
120 char* out,
121 frame_param& frame,
122 ofdm_param& ofdm,
123 bool reverse = false);
124
125void split_symbols(const char* input, char* out, frame_param& frame, ofdm_param& ofdm);
126
127void generate_bits(const char* psdu, char* data_bits, frame_param& frame);
128
129#endif /* INCLUDED_IEEE802_11_UTILS_H */
Definition utils.h:80
int n_sym
Definition utils.h:86
int psdu_size
Definition utils.h:84
int n_encoded_bits
Definition utils.h:89
int n_data_bits
Definition utils.h:91
int n_pad
Definition utils.h:88
frame_param(ofdm_param &ofdm, int psdu_length)
void print()
Definition utils.h:58
char rate_field
Definition utils.h:65
int n_bpsc
Definition utils.h:67
ofdm_param(Encoding e)
Encoding encoding
Definition utils.h:63
void print()
int n_cbps
Definition utils.h:69
int n_dbps
Definition utils.h:71
Encoding
Definition mapper.h:27
Definition utils.h:43
uint16_t frame_control
Definition utils.h:45
uint8_t addr3[6]
Definition utils.h:49
uint16_t duration
Definition utils.h:46
uint8_t addr2[6]
Definition utils.h:48
uint8_t addr1[6]
Definition utils.h:47
uint16_t seq_nr
Definition utils.h:50
void reset_tail_bits(char *scrambled_data, frame_param &frame)
void convolutional_encoding(const char *input, char *out, frame_param &frame)
void generate_bits(const char *psdu, char *data_bits, frame_param &frame)
void puncturing(const char *input, char *out, frame_param &frame, ofdm_param &ofdm)
void split_symbols(const char *input, char *out, frame_param &frame, ofdm_param &ofdm)
void interleave(const char *input, char *out, frame_param &frame, ofdm_param &ofdm, bool reverse=false)
void generate_mac_data_frame(const char *msdu, int msdu_size, char **psdu, int *psdu_size, char seq)
void scramble(const char *input, char *out, frame_param &frame, char initial_state)