A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 #include "ssid.h"
21 #include "ns3/assert.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 Ssid::Ssid (std::string s)
34 {
35  NS_ASSERT (s.size () < 32);
36  const char *ssid = s.c_str ();
37  uint8_t len = 0;
38  while (*ssid != 0 && len < 32)
39  {
40  m_ssid[len] = *ssid;
41  ssid++;
42  len++;
43  }
44  NS_ASSERT (len <= 32);
45  m_length = len;
46  while (len < 33)
47  {
48  m_ssid[len] = 0;
49  len++;
50  }
51 }
52 Ssid::Ssid (char const ssid[32], uint8_t length)
53 {
54  NS_ASSERT (length <= 32);
55  uint8_t len = 0;
56  while (len < length)
57  {
58  m_ssid[len] = ssid[len];
59  len++;
60  }
61  m_length = length;
62  while (len < 33)
63  {
64  m_ssid[len] = 0;
65  len++;
66  }
67 }
68 bool
69 Ssid::IsEqual (const Ssid& o) const
70 {
71  uint8_t i = 0;
72  while (i < 32
73  && m_ssid[i] == o.m_ssid[i]
74  && m_ssid[i] != 0)
75  {
76  i++;
77  }
78  if (m_ssid[i] != o.m_ssid[i])
79  {
80  return false;
81  }
82  return true;
83 }
84 bool
85 Ssid::IsBroadcast (void) const
86 {
87  if (m_ssid[0] == 0)
88  {
89  return true;
90  }
91  return false;
92 }
93 
94 char *
95 Ssid::PeekString (void) const
96 {
97  // it is safe to return a pointer to the buffer because it is
98  // guaranteed to be zero-terminated.
99  return (char *)m_ssid;
100 }
101 
104 {
105  return IE_SSID;
106 }
107 
108 uint8_t
110 {
111  return m_length;
112 }
113 
114 void
116 {
117  NS_ASSERT (m_length <= 32);
118  start.Write (m_ssid, m_length);
119 }
120 uint8_t
122  uint8_t length)
123 {
124  m_length = length;
125  NS_ASSERT (m_length <= 32);
126  start.Read (m_ssid, m_length);
127  return length;
128 }
129 
131 
139 std::ostream &
140 operator << (std::ostream &os, const Ssid &ssid)
141 {
142  os << ssid.PeekString ();
143  return os;
144 }
145 
153 std::istream &operator >> (std::istream &is, Ssid &ssid)
154 {
155  std::string str;
156  is >> str;
157  ssid = Ssid (str.c_str ());
158  return is;
159 }
160 
161 
162 } // namespace ns3
std::istream & operator>>(std::istream &is, Angles &a)
initialize a struct Angles from input
Definition: angles.cc:49
uint8_t m_ssid[33]
Raw SSID value.
Definition: ssid.h:84
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:61
bool IsBroadcast(void) const
Check if the SSID is broadcast.
Definition: ssid.cc:85
bool IsEqual(const Ssid &o) const
Check if the two SSIDs are equal.
Definition: ssid.cc:69
Ssid()
Definition: ssid.cc:25
iterator in a Buffer instance
Definition: buffer.h:98
Ptr< SampleEmitter > s
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:109
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
Definition: angles.cc:43
char * PeekString(void) const
Peek the SSID.
Definition: ssid.cc:95
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:115
void Read(uint8_t *buffer, uint32_t size)
Definition: buffer.cc:1152
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
Own unique Element ID.
Definition: ssid.cc:103
void Write(uint8_t const *buffer, uint32_t size)
Definition: buffer.cc:982
uint8_t WifiInformationElementId
This type is used to represent an Information Element ID.
ATTRIBUTE_HELPER_CPP(ObjectFactory)
uint8_t m_length
Length of the SSID.
Definition: ssid.h:85
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:121