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 #include "ns3/assert.h"
23 
24 namespace ns3 {
25 
27 {
28  m_length = 0;
29  for (uint8_t i = 0; i < 33; i++)
30  {
31  m_ssid[i] = 0;
32  }
33 }
34 
35 Ssid::Ssid (std::string s)
36 {
37  NS_ASSERT (s.size () < 32);
38  const char *ssid = s.c_str ();
39  uint8_t len = 0;
40  while (*ssid != 0 && len < 32)
41  {
42  m_ssid[len] = *ssid;
43  ssid++;
44  len++;
45  }
46  NS_ASSERT (len <= 32);
47  m_length = len;
48  while (len < 33)
49  {
50  m_ssid[len] = 0;
51  len++;
52  }
53 }
54 
55 Ssid::Ssid (char const ssid[32], uint8_t length)
56 {
57  NS_ASSERT (length <= 32);
58  uint8_t len = 0;
59  while (len < length)
60  {
61  m_ssid[len] = ssid[len];
62  len++;
63  }
64  m_length = length;
65  while (len < 33)
66  {
67  m_ssid[len] = 0;
68  len++;
69  }
70 }
71 
72 bool
73 Ssid::IsEqual (const Ssid& o) const
74 {
75  uint8_t i = 0;
76  while (i < 32
77  && m_ssid[i] == o.m_ssid[i]
78  && m_ssid[i] != 0)
79  {
80  i++;
81  }
82  if (m_ssid[i] != o.m_ssid[i])
83  {
84  return false;
85  }
86  return true;
87 }
88 
89 bool
90 Ssid::IsBroadcast (void) const
91 {
92  if (m_ssid[0] == 0)
93  {
94  return true;
95  }
96  return false;
97 }
98 
99 char *
100 Ssid::PeekString (void) const
101 {
102  //It is safe to return a pointer to the buffer because it is
103  //guaranteed to be zero-terminated.
104  return (char *)m_ssid;
105 }
106 
109 {
110  return IE_SSID;
111 }
112 
113 uint8_t
115 {
116  return m_length;
117 }
118 
119 void
121 {
122  NS_ASSERT (m_length <= 32);
123  start.Write (m_ssid, m_length);
124 }
125 
126 uint8_t
128  uint8_t length)
129 {
130  m_length = length;
131  NS_ASSERT (m_length <= 32);
132  start.Read (m_ssid, m_length);
133  return length;
134 }
135 
137 
146 std::ostream &
147 operator << (std::ostream &os, const Ssid &ssid)
148 {
149  os << ssid.PeekString ();
150  return os;
151 }
152 
161 std::istream &operator >> (std::istream &is, Ssid &ssid)
162 {
163  std::string str;
164  is >> str;
165  ssid = Ssid (str.c_str ());
166  return is;
167 }
168 
169 } //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:88
#define ATTRIBUTE_HELPER_CPP(type)
Define the attribute value, accessor and checkers for class type.
def start()
Definition: core.py:1482
#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:90
bool IsEqual(const Ssid &o) const
Check if the two SSIDs are equal.
Definition: ssid.cc:73
Ssid()
Definition: ssid.cc:26
iterator in a Buffer instance
Definition: buffer.h:98
uint8_t GetInformationFieldSize() const
Length of serialized information (i.e., the length of the body of the IE, not including the Element I...
Definition: ssid.cc:114
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:100
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SerializeInformationField(Buffer::Iterator start) const
Serialize information (i.e., the body of the IE, not including the Element ID and length octets) ...
Definition: ssid.cc:120
tuple ssid
Definition: third.py:93
void Read(uint8_t *buffer, uint32_t size)
Definition: buffer.cc:1123
The IEEE 802.11 SSID Information Element.
Definition: ssid.h:38
#define IE_SSID
Here we have definition of all Information Element IDs in IEEE 802.11-2007.
WifiInformationElementId ElementId() const
Own unique Element ID.
Definition: ssid.cc:108
void Write(uint8_t const *buffer, uint32_t size)
Definition: buffer.cc:953
uint8_t WifiInformationElementId
This type is used to represent an Information Element ID.
uint8_t m_length
Length of the SSID.
Definition: ssid.h:89
uint8_t DeserializeInformationField(Buffer::Iterator start, uint8_t length)
Deserialize information (i.e., the body of the IE, not including the Element ID and length octets) ...
Definition: ssid.cc:127