A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ssid.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2006 INRIA
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
7 */
8
9#include "ssid.h"
10
11namespace ns3
12{
13
15{
16 m_length = 0;
17 for (uint8_t i = 0; i < 33; i++)
18 {
19 m_ssid[i] = 0;
20 }
21}
22
23Ssid::Ssid(std::string s)
24{
25 NS_ASSERT(s.size() <= 32);
26 const char* ssid = s.c_str();
27 uint8_t len = 0;
28 while (*ssid != 0 && len < 32)
29 {
30 m_ssid[len] = *ssid;
31 ssid++;
32 len++;
33 }
34 NS_ASSERT(len <= 32);
35 m_length = len;
36 while (len < 33)
37 {
38 m_ssid[len] = 0;
39 len++;
40 }
41}
42
43void
44Ssid::Print(std::ostream& os) const
45{
46 os << "ssid=" << PeekString();
47}
48
49bool
50Ssid::IsEqual(const Ssid& o) const
51{
52 uint8_t i = 0;
53 while (i < 32 && m_ssid[i] == o.m_ssid[i] && m_ssid[i] != 0)
54 {
55 i++;
56 }
57 return m_ssid[i] == o.m_ssid[i];
58}
59
60bool
62{
63 return m_ssid[0] == 0;
64}
65
66char*
68{
69 // It is safe to return a pointer to the buffer because it is
70 // guaranteed to be zero-terminated.
71 return (char*)m_ssid;
72}
73
76{
77 return IE_SSID;
78}
79
80uint16_t
82{
83 return m_length;
84}
85
86void
88{
89 NS_ASSERT(m_length <= 32);
90 start.Write(m_ssid, m_length);
91}
92
93uint16_t
95{
96 m_length = length;
97 NS_ASSERT(m_length <= 32);
98 start.Read(m_ssid, m_length);
99 return length;
100}
101
103
104std::istream&
105operator>>(std::istream& is, Ssid& ssid)
106{
107 std::string str;
108 is >> str;
109 ssid = Ssid(str);
110 return is;
111}
112
113} // namespace ns3
iterator in a Buffer instance
Definition buffer.h:89
The IEEE 802.11 SSID Information Element.
Definition ssid.h:25
uint16_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:81
bool IsEqual(const Ssid &o) const
Check if the two SSIDs are equal.
Definition ssid.cc:50
uint8_t m_length
Length of the SSID.
Definition ssid.h:72
WifiInformationElementId ElementId() const override
Get the wifi information element ID.
Definition ssid.cc:75
char * PeekString() const
Peek the SSID.
Definition ssid.cc:67
bool IsBroadcast() const
Check if the SSID is broadcast.
Definition ssid.cc:61
void Print(std::ostream &os) const override
Generate human-readable form of IE.
Definition ssid.cc:44
uint8_t m_ssid[33]
Raw SSID value.
Definition ssid.h:71
uint16_t DeserializeInformationField(Buffer::Iterator start, uint16_t length) override
Deserialize information (i.e., the body of the IE, not including the Element ID and length octets)
Definition ssid.cc:94
Ssid()
Create SSID with broadcast SSID.
Definition ssid.cc:14
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:87
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#define ATTRIBUTE_HELPER_CPP(type)
Define the attribute value, accessor and checkers for class type
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::istream & operator>>(std::istream &is, Angles &a)
Definition angles.cc:172
uint8_t WifiInformationElementId
This type is used to represent an Information Element ID.
#define IE_SSID
Here we have definition of all Information Element IDs in IEEE 802.11-2007.