1 /* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2010 CTTC
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
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, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  *
18  * Authors: Nicola Baldo <nbaldo@cttc.es>
19  *          Ghada Badawy <gbadawy@gmail.com>
20  */
21 
22 #ifndef WIFI_TX_VECTOR_H
23 #define WIFI_TX_VECTOR_H
24 
25 #include <list>
26 #include "wifi-mode.h"
27 #include "wifi-phy-common.h"
28 #include "ns3/he-ru.h"
29 
30 namespace ns3 {
31 
32 /// HE MU specific user transmission parameters.
33 struct HeMuUserInfo
34 {
35   HeRu::RuSpec ru; ///< RU specification
36   WifiMode mcs;    ///< MCS
37   uint8_t nss;     ///< number of spatial streams
38 };
39 
40 /**
41  * This class mimics the TXVECTOR which is to be
42  * passed to the PHY in order to define the parameters which are to be
43  * used for a transmission. See IEEE 802.11-2016 16.2.5 "Transmit PHY",
44  * and also 8.3.4.1 "PHY SAP peer-to-peer service primitive
45  * parameters".
46  *
47  * If this class is constructed with the constructor that takes no
48  * arguments, then the client must explicitly set the mode and
49  * transmit power level parameters before using them.  Default
50  * member initializers are provided for the other parameters, to
51  * conform to a non-MIMO/long guard configuration, although these
52  * may also be explicitly set after object construction.
53  *
54  * When used in a infrastructure context, WifiTxVector values should be
55  * drawn from WifiRemoteStationManager parameters since rate adaptation
56  * is responsible for picking the mode, number of streams, etc., but in
57  * the case in which there is no such manager (e.g. mesh), the client
58  * still needs to initialize at least the mode and transmit power level
59  * appropriately.
60  *
61  * \note the above reference is valid for the DSSS PHY only (clause
62  * 16). TXVECTOR is defined also for the other PHYs, however they
63  * don't include the TXPWRLVL explicitly in the TXVECTOR. This is
64  * somewhat strange, since all PHYs actually have a
65  * PMD_TXPWRLVL.request primitive. We decide to include the power
66  * level in WifiTxVector for all PHYs, since it serves better our
67  * purposes, and furthermore it seems close to the way real devices
68  * work (e.g., madwifi).
69  */
70 class WifiTxVector
71 {
72 public:
73   /// map of HE MU specific user info paramters indexed by STA-ID
74   typedef std::map <uint16_t /* staId */, HeMuUserInfo /* HE MU specific user info */> HeMuUserInfoMap;
75 
76   WifiTxVector ();
77   ~WifiTxVector ();
78   /**
79    * Create a TXVECTOR with the given parameters.
80    *
81    * \param mode WifiMode
82    * \param powerLevel transmission power level
83    * \param preamble preamble type
84    * \param guardInterval the guard interval duration in nanoseconds
85    * \param nTx the number of TX antennas
86    * \param nss the number of spatial STBC streams (NSS)
87    * \param ness the number of extension spatial streams (NESS)
88    * \param channelWidth the channel width in MHz
89    * \param aggregation enable or disable MPDU aggregation
90    * \param stbc enable or disable STBC
91    * \param ldpc enable or disable LDPC (BCC is used otherwise)
92    * \param bssColor the BSS color
93    * \param length the LENGTH field of the L-SIG
94    */
95   WifiTxVector (WifiMode mode,
96                 uint8_t powerLevel,
97                 WifiPreamble preamble,
98                 uint16_t guardInterval,
99                 uint8_t nTx,
100                 uint8_t nss,
101                 uint8_t ness,
102                 uint16_t channelWidth,
103                 bool aggregation,
104                 bool stbc = false,
105                 bool ldpc = false,
106                 uint8_t bssColor = 0,
107                 uint16_t length = 0);
108   /**
109    * Copy constructor
110    * \param txVector the TXVECTOR to copy
111    */
112   WifiTxVector (const WifiTxVector& txVector);
113 
114   /**
115    * \returns whether mode has been initialized
116    */
117   bool GetModeInitialized (void) const;
118   /**
119    * If this TX vector is associated with an SU PPDU, return the selected
120    * payload transmission mode. If this TX vector is associated with an
121    * MU PPDU, return the transmission mode (MCS) selected for the transmission
122    * to the station identified by the given STA-ID.
123    *
124    * \param staId the station ID for MU
125    * \returns the selected payload transmission mode
126    */
127   WifiMode GetMode (uint16_t staId = SU_STA_ID) const;
128   /**
129    * Sets the selected payload transmission mode
130    *
131    * \param mode the payload WifiMode
132    */
133   void SetMode (WifiMode mode);
134   /**
135    * Sets the selected payload transmission mode for a given STA ID (for MU only)
136    *
137    * \param mode
138    * \param staId the station ID for MU
139    */
140   void SetMode (WifiMode mode, uint16_t staId);
141 
142   /**
143    * Get the modulation class specified by this TXVECTOR.
144    *
145    * \return the Modulation Class specified by this TXVECTOR
146    */
147   WifiModulationClass GetModulationClass (void) const;
148 
149   /**
150    * \returns the transmission power level
151    */
152   uint8_t GetTxPowerLevel (void) const;
153   /**
154    * Sets the selected transmission power level
155    *
156    * \param powerlevel the transmission power level
157    */
158   void SetTxPowerLevel (uint8_t powerlevel);
159   /**
160    * \returns the preamble type
161    */
162   WifiPreamble GetPreambleType (void) const;
163   /**
164    * Sets the preamble type
165    *
166    * \param preamble the preamble type
167    */
168   void SetPreambleType (WifiPreamble preamble);
169   /**
170    * \returns the channel width (in MHz)
171    */
172   uint16_t GetChannelWidth (void) const;
173   /**
174    * Sets the selected channelWidth (in MHz)
175    *
176    * \param channelWidth the channel width (in MHz)
177    */
178   void SetChannelWidth (uint16_t channelWidth);
179   /**
180    * \returns the guard interval duration (in nanoseconds)
181    */
182   uint16_t GetGuardInterval (void) const;
183   /**
184   * Sets the guard interval duration (in nanoseconds)
185   *
186   * \param guardInterval the guard interval duration (in nanoseconds)
187   */
188   void SetGuardInterval (uint16_t guardInterval);
189   /**
190    * \returns the number of TX antennas
191    */
192   uint8_t GetNTx (void) const;
193   /**
194    * Sets the number of TX antennas
195    *
196    * \param nTx the number of TX antennas
197    */
198   void SetNTx (uint8_t nTx);
199   /**
200    * If this TX vector is associated with an SU PPDU, return the number of
201    * spatial streams. If this TX vector is associated with an MU PPDU,
202    * return the number of spatial streams for the transmission to the station
203    * identified by the given STA-ID.
204    *
205    * \param staId the station ID for MU
206    * \returns the number of spatial streams
207    */
208   uint8_t GetNss (uint16_t staId = SU_STA_ID) const;
209   /**
210    * \returns the maximum number of Nss (namely if MU)
211    */
212   uint8_t GetNssMax (void) const;
213   /**
214    * Sets the number of Nss
215    *
216    * \param nss the number of spatial streams
217    */
218   void SetNss (uint8_t nss);
219   /**
220    * Sets the number of Nss for MU
221    *
222    * \param nss the number of spatial streams
223    * \param staId the station ID for MU
224    */
225   void SetNss (uint8_t nss, uint16_t staId);
226   /**
227    * \returns the number of extended spatial streams
228    */
229   uint8_t GetNess (void) const;
230   /**
231    * Sets the Ness number
232    *
233    * \param ness the number of extended spatial streams
234    */
235   void SetNess (uint8_t ness);
236   /**
237    * Checks whether the PSDU contains A-MPDU.
238    *  \returns true if this PSDU has A-MPDU aggregation,
239    *           false otherwise.
240    */
241   bool IsAggregation (void) const;
242   /**
243    * Sets if PSDU contains A-MPDU.
244    *
245    * \param aggregation whether the PSDU contains A-MPDU or not.
246    */
247   void SetAggregation (bool aggregation);
248   /**
249    * Check if STBC is used or not
250    *
251    * \returns true if STBC is used,
252    *           false otherwise
253    */
254   bool IsStbc (void) const;
255   /**
256    * Sets if STBC is being used
257    *
258    * \param stbc enable or disable STBC
259    */
260   void SetStbc (bool stbc);
261   /**
262    * Check if LDPC FEC coding is used or not
263    *
264    * \returns true if LDPC is used,
265    *          false if BCC is used
266    */
267   bool IsLdpc (void) const;
268   /**
269    * Sets if LDPC FEC coding is being used
270    *
271    * \param ldpc enable or disable LDPC
272    */
273   void SetLdpc (bool ldpc);
274   /**
275    * Set the BSS color
276    * \param color the BSS color
277    */
278   void SetBssColor (uint8_t color);
279   /**
280    * Get the BSS color
281    * \return the BSS color
282    */
283   uint8_t GetBssColor (void) const;
284   /**
285    * Set the LENGTH field of the L-SIG
286    * \param length the LENGTH field of the L-SIG
287    */
288   void SetLength (uint16_t length);
289   /**
290    * Get the LENGTH field of the L-SIG
291    * \return the LENGTH field of the L-SIG
292    */
293   uint16_t GetLength (void) const;
294   /**
295    * The standard disallows certain combinations of WifiMode, number of
296    * spatial streams, and channel widths.  This method can be used to
297    * check whether this WifiTxVector contains an invalid combination.
298    *
299    * \return true if the WifiTxVector parameters are allowed by the standard
300    */
301   bool IsValid (void) const;
302    /**
303    * Return true if this TX vector is used for a multi-user transmission.
304    *
305    * \return true if this TX vector is used for a multi-user transmission
306    */
307   bool IsMu (void) const;
308    /**
309    * Return true if this TX vector is used for a downlink multi-user transmission.
310    *
311    * \return true if this TX vector is used for a downlink multi-user transmission
312    */
313   bool IsDlMu (void) const;
314    /**
315    * Return true if this TX vector is used for an uplink multi-user transmission.
316    *
317    * \return true if this TX vector is used for an uplink multi-user transmission
318    */
319   bool IsUlMu (void) const;
320   /**
321     * Get the RU specification for the STA-ID.
322     * This is applicable only for MU.
323     *
324     * \param staId the station ID
325     * \return the RU specification for the STA-ID
326     */
327    HeRu::RuSpec GetRu (uint16_t staId) const;
328    /**
329     * Set the RU specification for the STA-ID.
330     * This is applicable only for MU.
331     *
332     * \param ru the RU specification
333     * \param staId the station ID
334     */
335    void SetRu (HeRu::RuSpec ru, uint16_t staId);
336    /**
337     * Get the HE MU user-specific transmission information for the given STA-ID.
338     * This is applicable only for HE MU.
339     *
340     * \param staId the station ID
341     * \return the HE MU user-specific transmission information for the given STA-ID
342     */
343    HeMuUserInfo GetHeMuUserInfo (uint16_t staId) const;
344    /**
345     * Set the HE MU user-specific transmission information for the given STA-ID.
346     * This is applicable only for HE MU.
347     *
348     * \param staId the station ID
349     * \param userInfo the HE MU user-specific transmission information
350     */
351    void SetHeMuUserInfo (uint16_t staId, HeMuUserInfo userInfo);
352    /**
353     * Get a const reference to the map HE MU user-specific transmission information indexed by STA-ID.
354     * This is applicable only for HE MU.
355     *
356     * \return a const reference to the map of HE MU user-specific information indexed by STA-ID
357     */
358    const HeMuUserInfoMap& GetHeMuUserInfoMap (void) const;
359    /**
360     * Get a reference to the map HE MU user-specific transmission information indexed by STA-ID.
361     * This is applicable only for HE MU.
362     *
363     * \return a reference to the map of HE MU user-specific information indexed by STA-ID
364     */
365    HeMuUserInfoMap& GetHeMuUserInfoMap (void);
366    /**
367     * Get the number of RUs per HE-SIG-B content channel.
368     * This is applicable only for MU. MU-MIMO (i.e. multiple stations
369     * per RU) is not supported yet.
370     * See section 27.3.10.8.3 of IEEE 802.11ax draft 4.0.
371     *
372     * \return a pair containing the number of RUs in each HE-SIG-B content channel (resp. 1 and 2)
373     */
374    std::pair<std::size_t, std::size_t> GetNumRusPerHeSigBContentChannel (void) const;
375 
376 
377 private:
378   WifiMode m_mode;               /**< The DATARATE parameter in Table 15-4.
379                                  It is the value that will be passed
380                                  to PMD_RATE.request */
381   uint8_t  m_txPowerLevel;       /**< The TXPWR_LEVEL parameter in Table 15-4.
382                                  It is the value that will be passed
383                                  to PMD_TXPWRLVL.request */
384   WifiPreamble m_preamble;       /**< preamble */
385   uint16_t m_channelWidth;       /**< channel width in MHz */
386   uint16_t m_guardInterval;      /**< guard interval duration in nanoseconds */
387   uint8_t  m_nTx;                /**< number of TX antennas */
388   uint8_t  m_nss;                /**< number of spatial streams */
389   uint8_t  m_ness;               /**< number of spatial streams in beamforming */
390   bool     m_aggregation;        /**< Flag whether the PSDU contains A-MPDU. */
391   bool     m_stbc;               /**< STBC used or not */
392   bool     m_ldpc;               /**< LDPC FEC coding if true, BCC otherwise*/
393   uint8_t  m_bssColor;           /**< BSS color */
394   uint16_t m_length;             /**< LENGTH field of the L-SIG */
395 
396   bool     m_modeInitialized;         /**< Internal initialization flag */
397 
398   //MU information
399   HeMuUserInfoMap m_muUserInfos; /**< HE MU specific per-user information
400                                       indexed by station ID (STA-ID) corresponding
401                                       to the 11 LSBs of the AID of the recipient STA
402                                       This list shall be used only for HE MU */
403 };
404 
405 /**
406  * Serialize WifiTxVector to the given ostream.
407  *
408  * \param os the output stream
409  * \param v the WifiTxVector to stringify
410  *
411  * \return ouput stream
412  */
413 std::ostream & operator << (std::ostream & os,const WifiTxVector &v);
414 
415 } //namespace ns3
416 
417 #endif /* WIFI_TX_VECTOR_H */
418