summaryrefslogtreecommitdiff
path: root/cesar/maximus/common/types/phy_types.h
blob: 9eab2d93c0bf156dc9e2c01c47ca2d0fd23ee85d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#ifndef maximus_common_types_phy_types_h
#define maximus_common_types_phy_types_h
/* Maximus project {{{
 *
 * Copyright (C) 2012 MStar Semiconductor
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    maximus/common/types/phy_types.h
 * \ingroup maximus_common_types
 *
 */

#include "maximus/common/types/sci_types.h"

#include "mac/common/defs.h" // for 'MAC_PB520_BYTES'
#include "mac/common/timings.h"

#include <stdint.h> // for 'uint8_t', 'uint16_t' and 'uint32_t' types

#define PHY_VERSION 0x02
#define PHY_PB_MAX_NB MAC_MAX_PB_PER_MPDU
#define PHY_MSG_MAX_NB_PER_MPDU 2

/** Length of PB header and ICV in bytes. */
#define PHY_PB_HDR_SIZE 4
#define PHY_ICV_SIZE    4

/** Ratio by which number of bits is multiplied depending on fecrate. */
#define PHY_FEC_RATE_1_2_RATIO      2
#define PHY_FEC_RATE_16_21_RATIO    (21 / 16)

/** Macro to convert number of bytes to number of bits. */
#define PHY_BYTES_TO_BITS(nb_bytes) ((nb_bytes) * 8)

/** Offset of PB measeurement fields. */
#define PHY_PB_MEAS_HALFIT_OFFSET   16
#define PHY_PB_MEAS_CRC_ERR_OFFSET  21

// Phy_Header.flags
//
typedef uint16_t Phy_Flags;
#define PHY_FLAG_NONE           0x0000
#define PHY_FLAG_ENCRYPTED      0x0001 // If set, PHY SCI msg is encrypted
#define PHY_FLAG_CRC_OK         0x0002 // If set, CRC is correct
#define PHY_FLAG_PB512          0x0004 // PB512 if set, PB128 if none
#define PHY_FLAG_WRONG_PREAMBLE 0x0008 // If set, PHY SCI msg is a wrong preamble
#define PHY_FLAG_MAX (PHY_FLAG_ENCRYPTED + PHY_FLAG_CRC_OK + PHY_FLAG_PB512 + PHY_FLAG_WRONG_PREAMBLE)

struct Phy_Header
{
    uint8_t version;
    uint8_t type;
    uint8_t mpdu_format; // delimiter type that indicates PHY SCI msg format in case of PHY_TYPE_MPDU_PAYLOAD
    uint8_t pb_nb; // if PB size is set to 128 octets, there is only one PB
    uint8_t msg_nb; // total number of messages needed to transmit the MPDU (in case of PHY_TYPE_MPDU_PAYLOAD)
    uint8_t fc_mode; // phy_fc_mode_t
    uint8_t short_ppdu; // bool
    uint8_t mod; // phy_mod_t
    uint8_t fecrate; // phy_fecrate_t
    uint8_t gil; // phy_gil_t
    uint8_t tonemap_index;
    uint8_t reserved;
    uint16_t tx_id; // unique ID incremented for each transmission
    uint16_t flags;
    uint32_t symbol_nb; // uint
    uint32_t iv[3];
    uint32_t nek[4];
    uint32_t pb_measurement[MAC_MAX_PB_PER_MPDU]; // 32 bits per PB for:
    // ber (Bit Error Rate) -> 16 bits
    // halfit -> 5 bits
    // crc_error -> 1 bit
    uint32_t pb_header[MAC_MAX_PB_PER_MPDU]; // 4 octets per PB
} __attribute__ ((__packed__));

// Phy_Header.type
//
enum Phy_Type
{
    PHY_TYPE_NONE = 0x00,
    PHY_TYPE_PREAMBLE = 0x01,         // PHY SCI msg data are empty
    PHY_TYPE_FC_HYBRID_MODE = 0x02,   // PHY SCI msg data contain HP1.0.1 Frame Control (25 bits => on 4 octets) and AV Frame Control (128 bits)
    PHY_TYPE_FC_AV_ONLY_MODE = 0x03,  // PHY SCI msg data only contain AV Frame Control (128 bits)
    PHY_TYPE_PRS = 0x04,              // PHY SCI msg data contain PRS0 or PRS1 symbol (on 1 octet)
    PHY_TYPE_MPDU_PAYLOAD = 0x05,     // PHY SCI msg data only contain MPDU payload ('nb_of_pbs' PBs of 128 or 512 octets depending on PHY_FLAG_PB512)
    PHY_TYPE_TONEMASK = 0x06,         // PHY SCI msg data contain 'uint carrier_nb' and the tonemask (uses 1 block)
    PHY_TYPE_TONEMAP = 0x07,          // PHY SCI msg data contain tonemap (uses 2 blocks)
    PHY_TYPE_NOISE = 0x08,            // PHY SCI msg data contain 'uint16_t frequency_noise[PHY_CARRIER_NB]' and 'uint16_t time_noise[MAC_MAX_SYMB_PER_MPDU]'
    PHY_TYPE_RX = 0x09,               // PHY SCI msg data contain the source station ID of the expected transmission
    PHY_TYPE_ZERO_CROSS = 0x0A,       // PHY SCI msg data are empty
    PHY_TYPE_NB
};

// Phy_Header.mpdu_format
//
enum Phy_Mpdu_Format
{
    PHY_MPDU_FORMAT_NONE = 0x00,
    PHY_MPDU_FORMAT_BEACON = 0x01,  // Beacon => Long MPDU
    PHY_MPDU_FORMAT_SOF = 0x02,     // Start Of Frame => Long MPDU
    PHY_MPDU_FORMAT_SACK = 0x03,    // Selective ACKnowledgement => Short MPDU (i.e. there is no payload)
    PHY_MPDU_FORMAT_RTS_CTS = 0x04, // Request To Send / Clear To Send => Short MPDU (i.e. there is no payload)
    PHY_MPDU_FORMAT_SOUND = 0x05,   // Sound => Long MPDU
    PHY_MPDU_FORMAT_RSOF = 0x06,    // Reverse Start Of Frame => Long MPDU
    PHY_MPDU_FORMAT_NB
};

#endif // maximus_common_types_phy_types_h