diff options
author | Ningyuan Wang | 2016-08-16 15:23:09 -0500 |
---|---|---|
committer | Ningyuan Wang | 2016-08-16 18:07:12 -0500 |
commit | de5d5e65272ec74a9aa59a6727d42a22e70d432c (patch) | |
tree | 4666600a2cf5f30cdf8d0284d688de8286448e41 /net | |
parent | 4aeb818632b7ee0c78ddcd1055494b58fbc10bb4 (diff) | |
download | system-connectivity-wificond-de5d5e65272ec74a9aa59a6727d42a22e70d432c.tar.gz system-connectivity-wificond-de5d5e65272ec74a9aa59a6727d42a22e70d432c.tar.xz system-connectivity-wificond-de5d5e65272ec74a9aa59a6727d42a22e70d432c.zip |
Get SSID from information element
Scan result netlink message doesn't provide SSID directly.
It provides raw information elemnt array, which contains SSID.
This helper function can get SSID from that array.
BUG=30896985
TEST=manul tests
Change-Id: I38f43a3528ddddbdc052333e5d0e15875517c89e
Diffstat (limited to 'net')
-rw-r--r-- | net/netlink_utils.cpp | 37 | ||||
-rw-r--r-- | net/netlink_utils.h | 3 |
2 files changed, 40 insertions, 0 deletions
diff --git a/net/netlink_utils.cpp b/net/netlink_utils.cpp index 1030646..47619bc 100644 --- a/net/netlink_utils.cpp +++ b/net/netlink_utils.cpp | |||
@@ -32,6 +32,11 @@ using std::vector; | |||
32 | 32 | ||
33 | namespace android { | 33 | namespace android { |
34 | namespace wificond { | 34 | namespace wificond { |
35 | namespace { | ||
36 | |||
37 | constexpr uint8_t kElemIdSsid = 0; | ||
38 | |||
39 | } // namespace | ||
35 | 40 | ||
36 | NetlinkUtils::NetlinkUtils(NetlinkManager* netlink_manager) | 41 | NetlinkUtils::NetlinkUtils(NetlinkManager* netlink_manager) |
37 | : netlink_manager_(netlink_manager) { | 42 | : netlink_manager_(netlink_manager) { |
@@ -152,5 +157,37 @@ bool NetlinkUtils::GetInterfaceNameAndIndex(uint32_t wiphy_index, | |||
152 | return false; | 157 | return false; |
153 | } | 158 | } |
154 | 159 | ||
160 | bool NetlinkUtils::GetSSIDFromInfoElement(const vector<uint8_t>& ie, | ||
161 | vector<uint8_t>* ssid) { | ||
162 | // Information elements are stored in 'TLV' format. | ||
163 | // Field: | Type | Length | Value | | ||
164 | // Length: | 1 | 1 | variable | | ||
165 | // Content:| Element ID | Length of the Value field | Element payload | | ||
166 | const uint8_t* end = ie.data() + ie.size(); | ||
167 | const uint8_t* ptr = ie.data(); | ||
168 | // +1 means we must have space for the length field. | ||
169 | while (ptr + 1 < end) { | ||
170 | uint8_t type = *ptr; | ||
171 | uint8_t length = *(ptr + 1); | ||
172 | // Length field is invalid. | ||
173 | if (ptr + 1 + length >= end) { | ||
174 | return false; | ||
175 | } | ||
176 | // SSID element is found. | ||
177 | if (type == kElemIdSsid) { | ||
178 | // SSID is an empty string. | ||
179 | if (length == 0) { | ||
180 | *ssid = vector<uint8_t>(); | ||
181 | } else { | ||
182 | *ssid = vector<uint8_t>(ptr + 2, ptr + length + 2); | ||
183 | } | ||
184 | return true; | ||
185 | } | ||
186 | ptr += 2 + length; | ||
187 | } | ||
188 | return false; | ||
189 | } | ||
190 | |||
191 | |||
155 | } // namespace wificond | 192 | } // namespace wificond |
156 | } // namespace android | 193 | } // namespace android |
diff --git a/net/netlink_utils.h b/net/netlink_utils.h index fa41f60..3629c12 100644 --- a/net/netlink_utils.h +++ b/net/netlink_utils.h | |||
@@ -46,6 +46,9 @@ class NetlinkUtils { | |||
46 | uint32_t* interface_index); | 46 | uint32_t* interface_index); |
47 | 47 | ||
48 | private: | 48 | private: |
49 | bool GetSSIDFromInfoElement(const std::vector<uint8_t>& ie, | ||
50 | std::vector<uint8_t>* ssid); | ||
51 | |||
49 | NetlinkManager* netlink_manager_; | 52 | NetlinkManager* netlink_manager_; |
50 | 53 | ||
51 | DISALLOW_COPY_AND_ASSIGN(NetlinkUtils); | 54 | DISALLOW_COPY_AND_ASSIGN(NetlinkUtils); |