src/devices/wifi/supported-rates.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Wed, 24 Oct 2007 20:00:30 +0200
changeset 2025 db1dcbab649f
parent 2018 ef299bf6c930
child 2026 db34213ef8b8
permissions -rw-r--r--
fix coding style
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1936
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     2
/*
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     3
 * Copyright (c) 2006 INRIA
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     4
 *
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as 
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     7
 * published by the Free Software Foundation;
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     8
 *
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    12
 * GNU General Public License for more details.
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    13
 *
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    17
 *
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    18
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    19
 */
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    20
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    21
#include "supported-rates.h"
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    22
#include "ns3/assert.h"
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    23
1938
f7e9802ea8e3 add serialization/deserialization support to Ssid/SupportedRates
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1936
diff changeset
    24
#define ELEMENT_ID (1)
f7e9802ea8e3 add serialization/deserialization support to Ssid/SupportedRates
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1936
diff changeset
    25
1936
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    26
namespace ns3 {
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    27
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    28
SupportedRates::SupportedRates ()
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    29
  : m_nRates (0)
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    30
{}
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    31
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    32
void 
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    33
SupportedRates::AddSupportedRate (uint32_t bs)
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    34
{
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    35
  NS_ASSERT (m_nRates < 8);
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    36
  m_rates[m_nRates] = bs/500000;
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    37
  m_nRates++;
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    38
}
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    39
void 
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    40
SupportedRates::SetBasicRate (uint32_t bs)
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    41
{
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    42
  uint8_t rate = bs / 500000;
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    43
  for (uint8_t i = 0; i < m_nRates; i++)
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    44
    {
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    45
      if (rate == m_rates[i])
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    46
        {
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    47
          m_rates[i] |= 0x80;
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    48
          return;
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    49
        }
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    50
    }
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    51
  AddSupportedRate (bs);
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    52
  SetBasicRate (bs);
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    53
}
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    54
bool 
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    55
SupportedRates::IsBasicRate (uint32_t bs) const
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    56
{
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    57
  uint8_t rate = bs / 500000;
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    58
  for (uint8_t i = 0; i < m_nRates; i++)
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    59
    {
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    60
      if (rate == m_rates[i] && 
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    61
          m_rates[i] & 0x80)
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    62
        {
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    63
          return true;
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    64
        }
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    65
    }
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    66
  return false;
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    67
}
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    68
bool 
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    69
SupportedRates::IsSupportedRate (uint32_t bs) const
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    70
{
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    71
  uint8_t rate = bs / 500000;
2025
db1dcbab649f fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2018
diff changeset
    72
  for (uint8_t i = 0; i < m_nRates; i++) 
db1dcbab649f fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2018
diff changeset
    73
    {
db1dcbab649f fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2018
diff changeset
    74
      if (rate == m_rates[i]) 
db1dcbab649f fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2018
diff changeset
    75
        {
db1dcbab649f fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2018
diff changeset
    76
          return true;
db1dcbab649f fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2018
diff changeset
    77
        }
1936
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    78
    }
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    79
  return false;
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    80
}
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    81
uint8_t 
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    82
SupportedRates::GetNRates (void) const
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    83
{
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    84
  return m_nRates;
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    85
}
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    86
uint32_t 
2013
4a5335c67eac add printing support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1938
diff changeset
    87
SupportedRates::GetRate (uint8_t i) const
4a5335c67eac add printing support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1938
diff changeset
    88
{
4a5335c67eac add printing support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1938
diff changeset
    89
  return m_rates[i] * 500000;
4a5335c67eac add printing support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1938
diff changeset
    90
}
4a5335c67eac add printing support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1938
diff changeset
    91
uint32_t 
1936
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    92
SupportedRates::GetSerializedSize (void) const
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    93
{
1938
f7e9802ea8e3 add serialization/deserialization support to Ssid/SupportedRates
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1936
diff changeset
    94
  return m_nRates + 1 + 1;
1936
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    95
}
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    96
Buffer::Iterator 
1938
f7e9802ea8e3 add serialization/deserialization support to Ssid/SupportedRates
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1936
diff changeset
    97
SupportedRates::Serialize (Buffer::Iterator start) const
1936
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    98
{
1938
f7e9802ea8e3 add serialization/deserialization support to Ssid/SupportedRates
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1936
diff changeset
    99
  start.WriteU8 (ELEMENT_ID);
1936
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   100
  start.WriteU8 (m_nRates);
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   101
  start.Write (m_rates, m_nRates);
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   102
  return start;
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   103
}
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   104
Buffer::Iterator 
1938
f7e9802ea8e3 add serialization/deserialization support to Ssid/SupportedRates
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1936
diff changeset
   105
SupportedRates::Deserialize (Buffer::Iterator start)
1936
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   106
{
1938
f7e9802ea8e3 add serialization/deserialization support to Ssid/SupportedRates
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1936
diff changeset
   107
  uint8_t elementId = start.ReadU8 ();
f7e9802ea8e3 add serialization/deserialization support to Ssid/SupportedRates
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1936
diff changeset
   108
  NS_ASSERT (elementId == ELEMENT_ID);
1936
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   109
  m_nRates = start.ReadU8 ();
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   110
  NS_ASSERT (m_nRates <= 8);
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   111
  start.Read (m_rates, m_nRates);
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   112
  return start;
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   113
}
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   114
2013
4a5335c67eac add printing support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1938
diff changeset
   115
std::ostream &operator << (std::ostream &os, const SupportedRates &rates)
4a5335c67eac add printing support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1938
diff changeset
   116
{
2018
ef299bf6c930 improve slightly the SupportedRates print output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2013
diff changeset
   117
  os << "[";
2013
4a5335c67eac add printing support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1938
diff changeset
   118
  for (uint8_t i = 0; i < rates.GetNRates (); i++)
4a5335c67eac add printing support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1938
diff changeset
   119
    {
4a5335c67eac add printing support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1938
diff changeset
   120
      uint32_t rate = rates.GetRate (i);
4a5335c67eac add printing support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1938
diff changeset
   121
      os << rate << "mbs";
4a5335c67eac add printing support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1938
diff changeset
   122
      if (i < rates.GetNRates () - 1)
4a5335c67eac add printing support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1938
diff changeset
   123
        {
4a5335c67eac add printing support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1938
diff changeset
   124
          os << " ";
4a5335c67eac add printing support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1938
diff changeset
   125
        }
4a5335c67eac add printing support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1938
diff changeset
   126
    }
2018
ef299bf6c930 improve slightly the SupportedRates print output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2013
diff changeset
   127
  os << "]";
2013
4a5335c67eac add printing support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1938
diff changeset
   128
  return os;
4a5335c67eac add printing support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1938
diff changeset
   129
}
4a5335c67eac add printing support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1938
diff changeset
   130
1936
61d6404e66d8 add SupportedRates to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   131
} // namespace ns3