A Discrete-Event Network Simulator
API
ssid.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2006 INRIA
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  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 
21 #include "ssid.h"
22 
23 namespace ns3 {
24 
26 {
27  m_length = 0;
28  for (uint8_t i = 0; i < 33; i++)
29  {
30  m_ssid[i] = 0;
31  }
32 }
33 
34 Ssid::Ssid (std::string s)
35 {
36  NS_ASSERT (s.size () < 32);
37  const char *ssid = s.c_str ();
38  uint8_t len = 0;
39  while (*ssid != 0 && len < 32)
40  {
41  m_ssid[len] = *ssid;
42  ssid++;
43  len++;
44  }
45  NS_ASSERT (len <= 32);
46  m_length = len;
47  while (len < 33)
48  {
49  m_ssid[len] = 0;
50  len++;
51  }
52 }
53 
54 Ssid::Ssid (char const ssid[32], uint8_t length)
55 {
56  NS_ASSERT (length <= 32);
57  uint8_t len = 0;
58  while (len < length)
59  {
60  m_ssid[len] = ssid[len];
61  len++;
62  }
63  m_length = length;
64  while (len < 33)
65  {
66  m_ssid[len] = 0;
67  len++;
68  }
69 }
70 
71 bool
72 Ssid::IsEqual (const Ssid& o) const
73 {
74  uint8_t i = 0;
75  while (i < 32
76  && m_ssid[i] == o.m_ssid[i]
77  && m_ssid[i] != 0)
78  {
79  i++;
80  }
81  if (m_ssid[i] != o.m_ssid[i])
82  {
83  return false;
84  }
85  return true;
86 }
87 
88 bool
89 Ssid::IsBroadcast (void) const
90 {
91  if (m_ssid[0] == 0)
92  {
93  return true;
94  }
95  return false;
96 }
97 
98 char *
99 Ssid::PeekString (void) const
100 {
101  //It is safe to return a pointer to the buffer because it is
102  //guaranteed to be zero-terminated.
103  return (char *)m_ssid;
104 }
105 
108 {
109  return IE_SSID;
110 }
111 
112 uint8_t
114 {
115  return m_length;
116 }
117 
118 void
120 {
121  NS_ASSERT (m_length <= 32);
122  start.Write (m_ssid, m_length);
123 }
124 
125 uint8_t
127  uint8_t length)
128 {
129  m_length = length;
130  NS_ASSERT (m_length <= 32);
131  start.Read (m_ssid, m_length);
132  return length;
133 }
134 
136 
145 std::ostream &
146 operator << (std::ostream &os, const Ssid &ssid)
147 {
148  os << ssid.PeekString ();
149  return os;
150 }
151 
160 std::istream &operator >> (std::istream &is, Ssid &ssid)
161 {
162  std::string str;
163  is >> str;
164  ssid = Ssid (str.c_str ());
165  return is;
166 }
167 
168 } //namespace ns3
std::istream & operator>>(std::istream &is, Angles &a)
initialize a struct Angles from input
Definition: angles.cc:48
uint8_t m_ssid[33]
Raw SSID value.
Definition: ssid.h:110
#define ATTRIBUTE_HELPER_CPP(type)
Define the attribute value, accessor and checkers for class type.
def start()
Definition: core.py:1790
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
bool IsBroadcast(void) const
Check if the SSID is broadcast.
Definition: ssid.cc:89
bool IsEqual(const Ssid &o) const
Check if the two SSIDs are equal.
Definition: ssid.cc:72
Ssid()
Definition: ssid.cc:25
iterator in a Buffer instance
Definition: buffer.h:98
uint8_t GetInformationFieldSize() const
Get the information field size.
Definition: ssid.cc:113
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
Definition: angles.cc:42
char * PeekString(void) const
Peek the SSID.
Definition: ssid.cc:99
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SerializeInformationField(Buffer::Iterator start) const
Get the information field size.
Definition: ssid.cc:119
tuple ssid
Definition: third.py:93
void Read(uint8_t *buffer, uint32_t size)
Definition: buffer.cc:1126
The IEEE 802.11 SSID Information Element.
Definition: ssid.h:35
#define IE_SSID
Here we have definition of all Information Element IDs in IEEE 802.11-2007.
WifiInformationElementId ElementId() const
Get the ElementID.
Definition: ssid.cc:107
void Write(uint8_t const *buffer, uint32_t size)
Definition: buffer.cc:956
uint8_t WifiInformationElementId
This type is used to represent an Information Element ID.
uint8_t m_length
Length of the SSID.
Definition: ssid.h:111
uint8_t DeserializeInformationField(Buffer::Iterator start, uint8_t length)
Get the information field size.
Definition: ssid.cc:126