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
23namespace 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
34Ssid::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
54bool
55Ssid::IsEqual (const Ssid& o) const
56{
57 uint8_t i = 0;
58 while (i < 32
59 && m_ssid[i] == o.m_ssid[i]
60 && m_ssid[i] != 0)
61 {
62 i++;
63 }
64 if (m_ssid[i] != o.m_ssid[i])
65 {
66 return false;
67 }
68 return true;
69}
70
71bool
73{
74 if (m_ssid[0] == 0)
75 {
76 return true;
77 }
78 return false;
79}
80
81char *
82Ssid::PeekString (void) const
83{
84 //It is safe to return a pointer to the buffer because it is
85 //guaranteed to be zero-terminated.
86 return (char *)m_ssid;
87}
88
91{
92 return IE_SSID;
93}
94
95uint8_t
97{
98 return m_length;
99}
100
101void
103{
104 NS_ASSERT (m_length <= 32);
105 start.Write (m_ssid, m_length);
106}
107
108uint8_t
110 uint8_t length)
111{
112 m_length = length;
113 NS_ASSERT (m_length <= 32);
114 start.Read (m_ssid, m_length);
115 return length;
116}
117
119
120std::ostream &
121operator << (std::ostream &os, const Ssid &ssid)
122{
123 os << ssid.PeekString ();
124 return os;
125}
126
127std::istream &
128operator >> (std::istream &is, Ssid &ssid)
129{
130 std::string str;
131 is >> str;
132 ssid = Ssid (str.c_str ());
133 return is;
134}
135
136} //namespace ns3
iterator in a Buffer instance
Definition: buffer.h:99
The IEEE 802.11 SSID Information Element.
Definition: ssid.h:36
bool IsEqual(const Ssid &o) const
Check if the two SSIDs are equal.
Definition: ssid.cc:55
uint8_t m_length
Length of the SSID.
Definition: ssid.h:83
WifiInformationElementId ElementId() const override
Get the wifi information element ID.
Definition: ssid.cc:90
char * PeekString(void) const
Peek the SSID.
Definition: ssid.cc:82
uint8_t DeserializeInformationField(Buffer::Iterator start, uint8_t length) override
Deserialize information (i.e., the body of the IE, not including the Element ID and length octets)
Definition: ssid.cc:109
uint8_t GetInformationFieldSize() const override
Length of serialized information (i.e., the length of the body of the IE, not including the Element I...
Definition: ssid.cc:96
uint8_t m_ssid[33]
Raw SSID value.
Definition: ssid.h:82
Ssid()
Create SSID with broadcast SSID.
Definition: ssid.cc:25
bool IsBroadcast(void) const
Check if the SSID is broadcast.
Definition: ssid.cc:72
void SerializeInformationField(Buffer::Iterator start) const override
Serialize information (i.e., the body of the IE, not including the Element ID and length octets)
Definition: ssid.cc:102
#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
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:139
ATTRIBUTE_HELPER_CPP(Length)
std::istream & operator>>(std::istream &is, Angles &a)
Definition: angles.cc:162
uint8_t WifiInformationElementId
This type is used to represent an Information Element ID.
ssid
Definition: third.py:97
def start()
Definition: core.py:1853
#define IE_SSID
Here we have definition of all Information Element IDs in IEEE 802.11-2007.