blob: 93b9a0466d8990cee0fd0f77ce28971a3f743bfc [file] [log] [blame]
Wade Guthrie12f113a2013-03-12 17:15:46 -07001// Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// This file provides tests for individual messages. It tests
6// NetlinkMessageFactory's ability to create specific message types and it
7// tests the various NetlinkMessage types' ability to parse those
8// messages.
9
10// This file tests the public interface to NetlinkMessage.
11
12#include "shill/nl80211_message.h"
13
14#include <string>
15#include <vector>
16
Wade Guthrie40d992c2013-04-19 11:10:11 -070017#include <base/stringprintf.h>
Wade Guthrie12f113a2013-03-12 17:15:46 -070018#include <gmock/gmock.h>
19#include <gtest/gtest.h>
20
Wade Guthrie40d992c2013-04-19 11:10:11 -070021#include "shill/mock_log.h"
Wade Guthrie12f113a2013-03-12 17:15:46 -070022#include "shill/mock_netlink_socket.h"
23#include "shill/netlink_attribute.h"
24#include "shill/refptr_types.h"
25
26using base::Bind;
Wade Guthrie40d992c2013-04-19 11:10:11 -070027using base::StringPrintf;
Wade Guthrie12f113a2013-03-12 17:15:46 -070028using base::Unretained;
29using std::string;
30using std::vector;
31using testing::_;
Wade Guthrie40d992c2013-04-19 11:10:11 -070032using testing::EndsWith;
Wade Guthrie12f113a2013-03-12 17:15:46 -070033using testing::Invoke;
34using testing::Return;
35using testing::Test;
36
37namespace shill {
38
39namespace {
40
Wade Guthriebb9fca22013-04-10 17:21:42 -070041// These data blocks have been collected by shill using NetlinkManager while,
Wade Guthrie12f113a2013-03-12 17:15:46 -070042// simultaneously (and manually) comparing shill output with that of the 'iw'
43// code from which it was derived. The test strings represent the raw packet
44// data coming from the kernel. The comments above each of these strings is
45// the markup that "iw" outputs for ech of these packets.
46
47// These constants are consistent throughout the packets, below.
48
49const uint32_t kExpectedIfIndex = 4;
50const uint32_t kWiPhy = 0;
51const uint16_t kNl80211FamilyId = 0x13;
52const char kExpectedMacAddress[] = "c0:3f:0e:77:e8:7f";
53
54const uint8_t kMacAddressBytes[] = {
55 0xc0, 0x3f, 0x0e, 0x77, 0xe8, 0x7f
56};
57
58const uint8_t kAssignedRespIeBytes[] = {
59 0x01, 0x08, 0x82, 0x84,
60 0x8b, 0x96, 0x0c, 0x12,
61 0x18, 0x24, 0x32, 0x04,
62 0x30, 0x48, 0x60, 0x6c
63};
64
65
66// wlan0 (phy #0): scan started
67
68const uint32_t kScanFrequencyTrigger[] = {
69 2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447,
70 2452, 2457, 2462, 2467, 2472, 2484, 5180, 5200,
71 5220, 5240, 5260, 5280, 5300, 5320, 5500, 5520,
72 5540, 5560, 5580, 5600, 5620, 5640, 5660, 5680,
73 5700, 5745, 5765, 5785, 5805, 5825
74};
75
76const unsigned char kNL80211_CMD_TRIGGER_SCAN[] = {
77 0x68, 0x01, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00,
78 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
79 0x21, 0x01, 0x00, 0x00, 0x08, 0x00, 0x01, 0x00,
80 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x03, 0x00,
81 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x2d, 0x00,
82 0x04, 0x00, 0x00, 0x00, 0x34, 0x01, 0x2c, 0x00,
83 0x08, 0x00, 0x00, 0x00, 0x6c, 0x09, 0x00, 0x00,
84 0x08, 0x00, 0x01, 0x00, 0x71, 0x09, 0x00, 0x00,
85 0x08, 0x00, 0x02, 0x00, 0x76, 0x09, 0x00, 0x00,
86 0x08, 0x00, 0x03, 0x00, 0x7b, 0x09, 0x00, 0x00,
87 0x08, 0x00, 0x04, 0x00, 0x80, 0x09, 0x00, 0x00,
88 0x08, 0x00, 0x05, 0x00, 0x85, 0x09, 0x00, 0x00,
89 0x08, 0x00, 0x06, 0x00, 0x8a, 0x09, 0x00, 0x00,
90 0x08, 0x00, 0x07, 0x00, 0x8f, 0x09, 0x00, 0x00,
91 0x08, 0x00, 0x08, 0x00, 0x94, 0x09, 0x00, 0x00,
92 0x08, 0x00, 0x09, 0x00, 0x99, 0x09, 0x00, 0x00,
93 0x08, 0x00, 0x0a, 0x00, 0x9e, 0x09, 0x00, 0x00,
94 0x08, 0x00, 0x0b, 0x00, 0xa3, 0x09, 0x00, 0x00,
95 0x08, 0x00, 0x0c, 0x00, 0xa8, 0x09, 0x00, 0x00,
96 0x08, 0x00, 0x0d, 0x00, 0xb4, 0x09, 0x00, 0x00,
97 0x08, 0x00, 0x0e, 0x00, 0x3c, 0x14, 0x00, 0x00,
98 0x08, 0x00, 0x0f, 0x00, 0x50, 0x14, 0x00, 0x00,
99 0x08, 0x00, 0x10, 0x00, 0x64, 0x14, 0x00, 0x00,
100 0x08, 0x00, 0x11, 0x00, 0x78, 0x14, 0x00, 0x00,
101 0x08, 0x00, 0x12, 0x00, 0x8c, 0x14, 0x00, 0x00,
102 0x08, 0x00, 0x13, 0x00, 0xa0, 0x14, 0x00, 0x00,
103 0x08, 0x00, 0x14, 0x00, 0xb4, 0x14, 0x00, 0x00,
104 0x08, 0x00, 0x15, 0x00, 0xc8, 0x14, 0x00, 0x00,
105 0x08, 0x00, 0x16, 0x00, 0x7c, 0x15, 0x00, 0x00,
106 0x08, 0x00, 0x17, 0x00, 0x90, 0x15, 0x00, 0x00,
107 0x08, 0x00, 0x18, 0x00, 0xa4, 0x15, 0x00, 0x00,
108 0x08, 0x00, 0x19, 0x00, 0xb8, 0x15, 0x00, 0x00,
109 0x08, 0x00, 0x1a, 0x00, 0xcc, 0x15, 0x00, 0x00,
110 0x08, 0x00, 0x1b, 0x00, 0xe0, 0x15, 0x00, 0x00,
111 0x08, 0x00, 0x1c, 0x00, 0xf4, 0x15, 0x00, 0x00,
112 0x08, 0x00, 0x1d, 0x00, 0x08, 0x16, 0x00, 0x00,
113 0x08, 0x00, 0x1e, 0x00, 0x1c, 0x16, 0x00, 0x00,
114 0x08, 0x00, 0x1f, 0x00, 0x30, 0x16, 0x00, 0x00,
115 0x08, 0x00, 0x20, 0x00, 0x44, 0x16, 0x00, 0x00,
116 0x08, 0x00, 0x21, 0x00, 0x71, 0x16, 0x00, 0x00,
117 0x08, 0x00, 0x22, 0x00, 0x85, 0x16, 0x00, 0x00,
118 0x08, 0x00, 0x23, 0x00, 0x99, 0x16, 0x00, 0x00,
119 0x08, 0x00, 0x24, 0x00, 0xad, 0x16, 0x00, 0x00,
120 0x08, 0x00, 0x25, 0x00, 0xc1, 0x16, 0x00, 0x00,
121 0x08, 0x00, 0x73, 0x00, 0x00, 0x00, 0x00, 0x00,
122};
123
124
125// wlan0 (phy #0): scan finished: 2412 2417 2422 2427 2432 2437 2442 2447 2452
126// 2457 2462 2467 2472 2484 5180 5200 5220 5240 5260 5280 5300 5320 5500 5520
127// 5540 5560 5580 5600 5620 5640 5660 5680 5700 5745 5765 5785 5805 5825, ""
128
129const uint32_t kScanFrequencyResults[] = {
130 2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447,
131 2452, 2457, 2462, 2467, 2472, 2484, 5180, 5200,
132 5220, 5240, 5260, 5280, 5300, 5320, 5500, 5520,
133 5540, 5560, 5580, 5600, 5620, 5640, 5660, 5680,
134 5700, 5745, 5765, 5785, 5805, 5825
135};
136
137const unsigned char kNL80211_CMD_NEW_SCAN_RESULTS[] = {
138 0x68, 0x01, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00,
139 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
140 0x22, 0x01, 0x00, 0x00, 0x08, 0x00, 0x01, 0x00,
141 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x03, 0x00,
142 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x2d, 0x00,
143 0x04, 0x00, 0x00, 0x00, 0x34, 0x01, 0x2c, 0x00,
144 0x08, 0x00, 0x00, 0x00, 0x6c, 0x09, 0x00, 0x00,
145 0x08, 0x00, 0x01, 0x00, 0x71, 0x09, 0x00, 0x00,
146 0x08, 0x00, 0x02, 0x00, 0x76, 0x09, 0x00, 0x00,
147 0x08, 0x00, 0x03, 0x00, 0x7b, 0x09, 0x00, 0x00,
148 0x08, 0x00, 0x04, 0x00, 0x80, 0x09, 0x00, 0x00,
149 0x08, 0x00, 0x05, 0x00, 0x85, 0x09, 0x00, 0x00,
150 0x08, 0x00, 0x06, 0x00, 0x8a, 0x09, 0x00, 0x00,
151 0x08, 0x00, 0x07, 0x00, 0x8f, 0x09, 0x00, 0x00,
152 0x08, 0x00, 0x08, 0x00, 0x94, 0x09, 0x00, 0x00,
153 0x08, 0x00, 0x09, 0x00, 0x99, 0x09, 0x00, 0x00,
154 0x08, 0x00, 0x0a, 0x00, 0x9e, 0x09, 0x00, 0x00,
155 0x08, 0x00, 0x0b, 0x00, 0xa3, 0x09, 0x00, 0x00,
156 0x08, 0x00, 0x0c, 0x00, 0xa8, 0x09, 0x00, 0x00,
157 0x08, 0x00, 0x0d, 0x00, 0xb4, 0x09, 0x00, 0x00,
158 0x08, 0x00, 0x0e, 0x00, 0x3c, 0x14, 0x00, 0x00,
159 0x08, 0x00, 0x0f, 0x00, 0x50, 0x14, 0x00, 0x00,
160 0x08, 0x00, 0x10, 0x00, 0x64, 0x14, 0x00, 0x00,
161 0x08, 0x00, 0x11, 0x00, 0x78, 0x14, 0x00, 0x00,
162 0x08, 0x00, 0x12, 0x00, 0x8c, 0x14, 0x00, 0x00,
163 0x08, 0x00, 0x13, 0x00, 0xa0, 0x14, 0x00, 0x00,
164 0x08, 0x00, 0x14, 0x00, 0xb4, 0x14, 0x00, 0x00,
165 0x08, 0x00, 0x15, 0x00, 0xc8, 0x14, 0x00, 0x00,
166 0x08, 0x00, 0x16, 0x00, 0x7c, 0x15, 0x00, 0x00,
167 0x08, 0x00, 0x17, 0x00, 0x90, 0x15, 0x00, 0x00,
168 0x08, 0x00, 0x18, 0x00, 0xa4, 0x15, 0x00, 0x00,
169 0x08, 0x00, 0x19, 0x00, 0xb8, 0x15, 0x00, 0x00,
170 0x08, 0x00, 0x1a, 0x00, 0xcc, 0x15, 0x00, 0x00,
171 0x08, 0x00, 0x1b, 0x00, 0xe0, 0x15, 0x00, 0x00,
172 0x08, 0x00, 0x1c, 0x00, 0xf4, 0x15, 0x00, 0x00,
173 0x08, 0x00, 0x1d, 0x00, 0x08, 0x16, 0x00, 0x00,
174 0x08, 0x00, 0x1e, 0x00, 0x1c, 0x16, 0x00, 0x00,
175 0x08, 0x00, 0x1f, 0x00, 0x30, 0x16, 0x00, 0x00,
176 0x08, 0x00, 0x20, 0x00, 0x44, 0x16, 0x00, 0x00,
177 0x08, 0x00, 0x21, 0x00, 0x71, 0x16, 0x00, 0x00,
178 0x08, 0x00, 0x22, 0x00, 0x85, 0x16, 0x00, 0x00,
179 0x08, 0x00, 0x23, 0x00, 0x99, 0x16, 0x00, 0x00,
180 0x08, 0x00, 0x24, 0x00, 0xad, 0x16, 0x00, 0x00,
181 0x08, 0x00, 0x25, 0x00, 0xc1, 0x16, 0x00, 0x00,
182 0x08, 0x00, 0x73, 0x00, 0x00, 0x00, 0x00, 0x00,
183};
184
185
186// wlan0: new station c0:3f:0e:77:e8:7f
187
188const uint32_t kNewStationExpectedGeneration = 275;
189
190const unsigned char kNL80211_CMD_NEW_STATION[] = {
191 0x34, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00,
192 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
193 0x13, 0x01, 0x00, 0x00, 0x08, 0x00, 0x03, 0x00,
194 0x04, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x06, 0x00,
195 0xc0, 0x3f, 0x0e, 0x77, 0xe8, 0x7f, 0x00, 0x00,
196 0x08, 0x00, 0x2e, 0x00, 0x13, 0x01, 0x00, 0x00,
197 0x04, 0x00, 0x15, 0x00,
198};
199
200
201// wlan0 (phy #0): auth c0:3f:0e:77:e8:7f -> 48:5d:60:77:2d:cf status: 0:
202// Successful [frame: b0 00 3a 01 48 5d 60 77 2d cf c0 3f 0e 77 e8 7f c0
203// 3f 0e 77 e8 7f 30 07 00 00 02 00 00 00]
204
205const unsigned char kAuthenticateFrame[] = {
206 0xb0, 0x00, 0x3a, 0x01, 0x48, 0x5d, 0x60, 0x77,
207 0x2d, 0xcf, 0xc0, 0x3f, 0x0e, 0x77, 0xe8, 0x7f,
208 0xc0, 0x3f, 0x0e, 0x77, 0xe8, 0x7f, 0x30, 0x07,
209 0x00, 0x00, 0x02, 0x00, 0x00, 0x00
210};
211
212const unsigned char kNL80211_CMD_AUTHENTICATE[] = {
213 0x48, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00,
214 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
215 0x25, 0x01, 0x00, 0x00, 0x08, 0x00, 0x01, 0x00,
216 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x03, 0x00,
217 0x04, 0x00, 0x00, 0x00, 0x22, 0x00, 0x33, 0x00,
218 0xb0, 0x00, 0x3a, 0x01, 0x48, 0x5d, 0x60, 0x77,
219 0x2d, 0xcf, 0xc0, 0x3f, 0x0e, 0x77, 0xe8, 0x7f,
220 0xc0, 0x3f, 0x0e, 0x77, 0xe8, 0x7f, 0x30, 0x07,
221 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
222};
223
224
225// wlan0 (phy #0): assoc c0:3f:0e:77:e8:7f -> 48:5d:60:77:2d:cf status: 0:
226// Successful [frame: 10 00 3a 01 48 5d 60 77 2d cf c0 3f 0e 77 e8 7f c0 3f 0e
227// 77 e8 7f 40 07 01 04 00 00 01 c0 01 08 82 84 8b 96 0c 12 18 24 32 04 30 48
228// 60 6c]
229
230const unsigned char kAssociateFrame[] = {
231 0x10, 0x00, 0x3a, 0x01, 0x48, 0x5d, 0x60, 0x77,
232 0x2d, 0xcf, 0xc0, 0x3f, 0x0e, 0x77, 0xe8, 0x7f,
233 0xc0, 0x3f, 0x0e, 0x77, 0xe8, 0x7f, 0x40, 0x07,
234 0x01, 0x04, 0x00, 0x00, 0x01, 0xc0, 0x01, 0x08,
235 0x82, 0x84, 0x8b, 0x96, 0x0c, 0x12, 0x18, 0x24,
236 0x32, 0x04, 0x30, 0x48, 0x60, 0x6c
237};
238
239const unsigned char kNL80211_CMD_ASSOCIATE[] = {
240 0x58, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00,
241 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
242 0x26, 0x01, 0x00, 0x00, 0x08, 0x00, 0x01, 0x00,
243 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x03, 0x00,
244 0x04, 0x00, 0x00, 0x00, 0x32, 0x00, 0x33, 0x00,
245 0x10, 0x00, 0x3a, 0x01, 0x48, 0x5d, 0x60, 0x77,
246 0x2d, 0xcf, 0xc0, 0x3f, 0x0e, 0x77, 0xe8, 0x7f,
247 0xc0, 0x3f, 0x0e, 0x77, 0xe8, 0x7f, 0x40, 0x07,
248 0x01, 0x04, 0x00, 0x00, 0x01, 0xc0, 0x01, 0x08,
249 0x82, 0x84, 0x8b, 0x96, 0x0c, 0x12, 0x18, 0x24,
250 0x32, 0x04, 0x30, 0x48, 0x60, 0x6c, 0x00, 0x00,
251};
252
253
254// wlan0 (phy #0): connected to c0:3f:0e:77:e8:7f
255
256const uint16_t kExpectedConnectStatus = 0;
257
258const unsigned char kNL80211_CMD_CONNECT[] = {
259 0x4c, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00,
260 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
261 0x2e, 0x01, 0x00, 0x00, 0x08, 0x00, 0x01, 0x00,
262 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x03, 0x00,
263 0x04, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x06, 0x00,
264 0xc0, 0x3f, 0x0e, 0x77, 0xe8, 0x7f, 0x00, 0x00,
265 0x06, 0x00, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00,
266 0x14, 0x00, 0x4e, 0x00, 0x01, 0x08, 0x82, 0x84,
267 0x8b, 0x96, 0x0c, 0x12, 0x18, 0x24, 0x32, 0x04,
268 0x30, 0x48, 0x60, 0x6c,
269};
270
271
272// wlan0 (phy #0): deauth c0:3f:0e:77:e8:7f -> ff:ff:ff:ff:ff:ff reason 2:
273// Previous authentication no longer valid [frame: c0 00 00 00 ff ff ff ff
274// ff ff c0 3f 0e 77 e8 7f c0 3f 0e 77 e8 7f c0 0e 02 00]
275
276const unsigned char kDeauthenticateFrame[] = {
277 0xc0, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
278 0xff, 0xff, 0xc0, 0x3f, 0x0e, 0x77, 0xe8, 0x7f,
279 0xc0, 0x3f, 0x0e, 0x77, 0xe8, 0x7f, 0xc0, 0x0e,
280 0x02, 0x00
281};
282
283const unsigned char kNL80211_CMD_DEAUTHENTICATE[] = {
284 0x44, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00,
285 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
286 0x27, 0x01, 0x00, 0x00, 0x08, 0x00, 0x01, 0x00,
287 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x03, 0x00,
288 0x04, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x33, 0x00,
289 0xc0, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
290 0xff, 0xff, 0xc0, 0x3f, 0x0e, 0x77, 0xe8, 0x7f,
291 0xc0, 0x3f, 0x0e, 0x77, 0xe8, 0x7f, 0xc0, 0x0e,
292 0x02, 0x00, 0x00, 0x00,
293};
294
295
296// wlan0 (phy #0): disconnected (by AP) reason: 2: Previous authentication no
297// longer valid
298
299const uint16_t kExpectedDisconnectReason = 2;
300
301const unsigned char kNL80211_CMD_DISCONNECT[] = {
302 0x30, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00,
303 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
304 0x30, 0x01, 0x00, 0x00, 0x08, 0x00, 0x01, 0x00,
305 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x03, 0x00,
306 0x04, 0x00, 0x00, 0x00, 0x06, 0x00, 0x36, 0x00,
307 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x47, 0x00,
308};
309
310
311// wlan0 (phy #0): connection quality monitor event: peer c0:3f:0e:77:e8:7f
312// didn't ACK 50 packets
313
314const uint32_t kExpectedCqmNotAcked = 50;
315
316const unsigned char kNL80211_CMD_NOTIFY_CQM[] = {
317 0x3c, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00,
318 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
319 0x40, 0x01, 0x00, 0x00, 0x08, 0x00, 0x01, 0x00,
320 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x03, 0x00,
321 0x04, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x06, 0x00,
322 0xc0, 0x3f, 0x0e, 0x77, 0xe8, 0x7f, 0x00, 0x00,
323 0x0c, 0x00, 0x5e, 0x00, 0x08, 0x00, 0x04, 0x00,
324 0x32, 0x00, 0x00, 0x00,
325};
326
327
328// wlan0 (phy #0): disassoc 48:5d:60:77:2d:cf -> c0:3f:0e:77:e8:7f reason 3:
329// Deauthenticated because sending station is [frame: a0 00 00 00 c0 3f 0e
330// 77 e8 7f 48 5d 60 77 2d cf c0 3f 0e 77 e8 7f 00 00 03 00]
331
332const unsigned char kDisassociateFrame[] = {
333 0xa0, 0x00, 0x00, 0x00, 0xc0, 0x3f, 0x0e, 0x77,
334 0xe8, 0x7f, 0x48, 0x5d, 0x60, 0x77, 0x2d, 0xcf,
335 0xc0, 0x3f, 0x0e, 0x77, 0xe8, 0x7f, 0x00, 0x00,
336 0x03, 0x00
337};
338
339const unsigned char kNL80211_CMD_DISASSOCIATE[] = {
340 0x44, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00,
341 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
342 0x28, 0x01, 0x00, 0x00, 0x08, 0x00, 0x01, 0x00,
343 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x03, 0x00,
344 0x04, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x33, 0x00,
345 0xa0, 0x00, 0x00, 0x00, 0xc0, 0x3f, 0x0e, 0x77,
346 0xe8, 0x7f, 0x48, 0x5d, 0x60, 0x77, 0x2d, 0xcf,
347 0xc0, 0x3f, 0x0e, 0x77, 0xe8, 0x7f, 0x00, 0x00,
348 0x03, 0x00, 0x00, 0x00,
349};
350
Wade Guthrie40d992c2013-04-19 11:10:11 -0700351// This is just a NL80211_CMD_NEW_STATION message with the command changed to
352// 0xfe (which is, intentionally, not a supported command).
353
354const unsigned char kCmdNL80211_CMD_UNKNOWN = 0xfe;
355const unsigned char kNL80211_CMD_UNKNOWN[] = {
356 0x34, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00,
357 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
358 0xfe, 0x01, 0x00, 0x00, 0x08, 0x00, 0x03, 0x00,
359 0x04, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x06, 0x00,
360 0xc0, 0x3f, 0x0e, 0x77, 0xe8, 0x7f, 0x00, 0x00,
361 0x08, 0x00, 0x2e, 0x00, 0x13, 0x01, 0x00, 0x00,
362 0x04, 0x00, 0x15, 0x00,
363};
364
Wade Guthrie12f113a2013-03-12 17:15:46 -0700365const char kGetFamilyCommandString[] = "CTRL_CMD_GETFAMILY";
366
367} // namespace
368
369class NetlinkMessageTest : public Test {
370 public:
371 NetlinkMessageTest() {
372 message_factory_.AddFactoryMethod(
373 kNl80211FamilyId, Bind(&Nl80211Message::CreateMessage));
374 Nl80211Message::SetMessageType(kNl80211FamilyId);
375 }
376
377 protected:
378 NetlinkMessageFactory message_factory_;
379};
380
381TEST_F(NetlinkMessageTest, Parse_NL80211_CMD_TRIGGER_SCAN) {
382 NetlinkMessage *netlink_message =
383 message_factory_.CreateMessage(const_cast<nlmsghdr *>(
384 reinterpret_cast<const nlmsghdr *>(kNL80211_CMD_TRIGGER_SCAN)));
385
386 EXPECT_NE(reinterpret_cast<NetlinkMessage *>(NULL), netlink_message);
387 EXPECT_EQ(kNl80211FamilyId, netlink_message->message_type());
388 // The follwing is legal if the message_type is kNl80211FamilyId.
389 Nl80211Message *message = reinterpret_cast<Nl80211Message *>(netlink_message);
390
391 EXPECT_EQ(NL80211_CMD_TRIGGER_SCAN, message->command());
392
393 {
394 uint32_t value;
395 EXPECT_TRUE(message->const_attributes()->GetU32AttributeValue(
396 NL80211_ATTR_WIPHY, &value));
397 EXPECT_EQ(kWiPhy, value);
398 }
399
400 {
401 uint32_t value;
402 EXPECT_TRUE(message->const_attributes()->GetU32AttributeValue(
403 NL80211_ATTR_IFINDEX, &value));
404 EXPECT_EQ(kExpectedIfIndex, value);
405 }
406
407 // Make sure the scan frequencies in the attribute are the ones we expect.
408 {
409 vector<uint32_t>list;
410 EXPECT_TRUE(message->GetScanFrequenciesAttribute(
411 NL80211_ATTR_SCAN_FREQUENCIES, &list));
412 EXPECT_EQ(list.size(), arraysize(kScanFrequencyTrigger));
413 int i = 0;
414 vector<uint32_t>::const_iterator j = list.begin();
415 while (j != list.end()) {
416 EXPECT_EQ(kScanFrequencyTrigger[i], *j);
417 ++i;
418 ++j;
419 }
420 }
421
422 {
423 vector<string> ssids;
424 EXPECT_TRUE(message->GetScanSsidsAttribute(NL80211_ATTR_SCAN_SSIDS,
425 &ssids));
426 EXPECT_EQ(1, ssids.size());
427 EXPECT_EQ(0, ssids[0].compare("")); // Expect a single, empty SSID.
428 }
429
430 EXPECT_TRUE(message->const_attributes()->IsFlagAttributeTrue(
431 NL80211_ATTR_SUPPORT_MESH_AUTH));
432}
433
434TEST_F(NetlinkMessageTest, Parse_NL80211_CMD_NEW_SCAN_RESULTS) {
435 NetlinkMessage *netlink_message =
436 message_factory_.CreateMessage(const_cast<nlmsghdr *>(
437 reinterpret_cast<const nlmsghdr *>(kNL80211_CMD_NEW_SCAN_RESULTS)));
438
439 EXPECT_NE(reinterpret_cast<NetlinkMessage *>(NULL), netlink_message);
440 EXPECT_EQ(kNl80211FamilyId, netlink_message->message_type());
441 // The follwing is legal if the message_type is kNl80211FamilyId.
442 Nl80211Message *message = reinterpret_cast<Nl80211Message *>(netlink_message);
443
444 EXPECT_EQ(NL80211_CMD_NEW_SCAN_RESULTS, message->command());
445
446 {
447 uint32_t value;
448 EXPECT_TRUE(message->const_attributes()->GetU32AttributeValue(
449 NL80211_ATTR_WIPHY, &value));
450 EXPECT_EQ(kWiPhy, value);
451 }
452
453 {
454 uint32_t value;
455 EXPECT_TRUE(message->const_attributes()->GetU32AttributeValue(
456 NL80211_ATTR_IFINDEX, &value));
457 EXPECT_EQ(kExpectedIfIndex, value);
458 }
459
460 // Make sure the scan frequencies in the attribute are the ones we expect.
461 {
462 vector<uint32_t>list;
463 EXPECT_TRUE(message->GetScanFrequenciesAttribute(
464 NL80211_ATTR_SCAN_FREQUENCIES, &list));
465 EXPECT_EQ(arraysize(kScanFrequencyResults), list.size());
466 int i = 0;
467 vector<uint32_t>::const_iterator j = list.begin();
468 while (j != list.end()) {
469 EXPECT_EQ(kScanFrequencyResults[i], *j);
470 ++i;
471 ++j;
472 }
473 }
474
475 {
476 vector<string> ssids;
477 EXPECT_TRUE(message->GetScanSsidsAttribute(NL80211_ATTR_SCAN_SSIDS,
478 &ssids));
479 EXPECT_EQ(1, ssids.size());
480 EXPECT_EQ(0, ssids[0].compare("")); // Expect a single, empty SSID.
481 }
482
483 EXPECT_TRUE(message->const_attributes()->IsFlagAttributeTrue(
484 NL80211_ATTR_SUPPORT_MESH_AUTH));
485}
486
487TEST_F(NetlinkMessageTest, Parse_NL80211_CMD_NEW_STATION) {
488 NetlinkMessage *netlink_message =
489 message_factory_.CreateMessage(const_cast<nlmsghdr *>(
490 reinterpret_cast<const nlmsghdr *>(kNL80211_CMD_NEW_STATION)));
491
492 EXPECT_NE(reinterpret_cast<NetlinkMessage *>(NULL), netlink_message);
493 EXPECT_EQ(kNl80211FamilyId, netlink_message->message_type());
494 // The follwing is legal if the message_type is kNl80211FamilyId.
495 Nl80211Message *message = reinterpret_cast<Nl80211Message *>(netlink_message);
496 EXPECT_EQ(NL80211_CMD_NEW_STATION, message->command());
497
498 {
499 uint32_t value;
500 EXPECT_TRUE(message->const_attributes()->GetU32AttributeValue(
501 NL80211_ATTR_IFINDEX, &value));
502 EXPECT_EQ(kExpectedIfIndex, value);
503 }
504
505 {
506 string value;
507 EXPECT_TRUE(message->GetMacAttributeString(NL80211_ATTR_MAC, &value));
508 EXPECT_EQ(0, strncmp(value.c_str(), kExpectedMacAddress, value.length()));
509 }
510
511 {
512 AttributeListConstRefPtr nested;
513 EXPECT_TRUE(message->const_attributes()->ConstGetNestedAttributeList(
514 NL80211_ATTR_STA_INFO, &nested));
515 }
516
517 {
518 uint32_t value;
519 EXPECT_TRUE(message->const_attributes()->GetU32AttributeValue(
520 NL80211_ATTR_GENERATION, &value));
521 EXPECT_EQ(kNewStationExpectedGeneration, value);
522 }
523}
524
525TEST_F(NetlinkMessageTest, Parse_NL80211_CMD_AUTHENTICATE) {
526 NetlinkMessage *netlink_message =
527 message_factory_.CreateMessage(const_cast<nlmsghdr *>(
528 reinterpret_cast<const nlmsghdr *>(kNL80211_CMD_AUTHENTICATE)));
529
530 EXPECT_NE(reinterpret_cast<NetlinkMessage *>(NULL), netlink_message);
531 EXPECT_EQ(kNl80211FamilyId, netlink_message->message_type());
532 // The follwing is legal if the message_type is kNl80211FamilyId.
533 Nl80211Message *message = reinterpret_cast<Nl80211Message *>(netlink_message);
534 EXPECT_EQ(NL80211_CMD_AUTHENTICATE, message->command());
535
536 {
537 uint32_t value;
538 EXPECT_TRUE(message->const_attributes()->GetU32AttributeValue(
539 NL80211_ATTR_WIPHY, &value));
540 EXPECT_EQ(kWiPhy, value);
541 }
542
543 {
544 uint32_t value;
545 EXPECT_TRUE(message->const_attributes()->GetU32AttributeValue(
546 NL80211_ATTR_IFINDEX, &value));
547 EXPECT_EQ(kExpectedIfIndex, value);
548 }
549
550 {
551 ByteString rawdata;
552 EXPECT_TRUE(message->const_attributes()->GetRawAttributeValue(
553 NL80211_ATTR_FRAME, &rawdata));
554 EXPECT_FALSE(rawdata.IsEmpty());
555 Nl80211Frame frame(rawdata);
556 Nl80211Frame expected_frame(ByteString(kAuthenticateFrame,
557 sizeof(kAuthenticateFrame)));
558 EXPECT_TRUE(frame.IsEqual(expected_frame));
559 }
560}
561
562TEST_F(NetlinkMessageTest, Parse_NL80211_CMD_ASSOCIATE) {
563 NetlinkMessage *netlink_message =
564 message_factory_.CreateMessage(const_cast<nlmsghdr *>(
565 reinterpret_cast<const nlmsghdr *>(kNL80211_CMD_ASSOCIATE)));
566
567 EXPECT_NE(reinterpret_cast<NetlinkMessage *>(NULL), netlink_message);
568 EXPECT_EQ(kNl80211FamilyId, netlink_message->message_type());
569 // The follwing is legal if the message_type is kNl80211FamilyId.
570 Nl80211Message *message = reinterpret_cast<Nl80211Message *>(netlink_message);
571 EXPECT_EQ(NL80211_CMD_ASSOCIATE, message->command());
572
573 {
574 uint32_t value;
575 EXPECT_TRUE(message->const_attributes()->GetU32AttributeValue(
576 NL80211_ATTR_WIPHY, &value));
577 EXPECT_EQ(kWiPhy, value);
578 }
579
580 {
581 uint32_t value;
582 EXPECT_TRUE(message->const_attributes()->GetU32AttributeValue(
583 NL80211_ATTR_IFINDEX, &value));
584 EXPECT_EQ(kExpectedIfIndex, value);
585 }
586
587 {
588 ByteString rawdata;
589 EXPECT_TRUE(message->const_attributes()->GetRawAttributeValue(
590 NL80211_ATTR_FRAME, &rawdata));
591 EXPECT_FALSE(rawdata.IsEmpty());
592 Nl80211Frame frame(rawdata);
593 Nl80211Frame expected_frame(ByteString(kAssociateFrame,
594 sizeof(kAssociateFrame)));
595 EXPECT_TRUE(frame.IsEqual(expected_frame));
596 }
597}
598
599TEST_F(NetlinkMessageTest, Parse_NL80211_CMD_CONNECT) {
600 NetlinkMessage *netlink_message =
601 message_factory_.CreateMessage(const_cast<nlmsghdr *>(
602 reinterpret_cast<const nlmsghdr *>(kNL80211_CMD_CONNECT)));
603
604 EXPECT_NE(reinterpret_cast<NetlinkMessage *>(NULL), netlink_message);
605 EXPECT_EQ(kNl80211FamilyId, netlink_message->message_type());
606 // The follwing is legal if the message_type is kNl80211FamilyId.
607 Nl80211Message *message = reinterpret_cast<Nl80211Message *>(netlink_message);
608 EXPECT_EQ(NL80211_CMD_CONNECT, message->command());
609
610 {
611 uint32_t value;
612 EXPECT_TRUE(message->const_attributes()->GetU32AttributeValue(
613 NL80211_ATTR_WIPHY, &value));
614 EXPECT_EQ(kWiPhy, value);
615 }
616
617 {
618 uint32_t value;
619 EXPECT_TRUE(message->const_attributes()->GetU32AttributeValue(
620 NL80211_ATTR_IFINDEX, &value));
621 EXPECT_EQ(kExpectedIfIndex, value);
622 }
623
624 {
625 string value;
626 EXPECT_TRUE(message->GetMacAttributeString(NL80211_ATTR_MAC, &value));
627 EXPECT_EQ(0, strncmp(value.c_str(), kExpectedMacAddress, value.length()));
628 }
629
630 {
631 uint16_t value;
632 EXPECT_TRUE(message->const_attributes()->GetU16AttributeValue(
633 NL80211_ATTR_STATUS_CODE, &value));
634 EXPECT_EQ(kExpectedConnectStatus, value);
635 }
636
637 // TODO(wdg): Need to check the value of this attribute.
638 {
639 ByteString rawdata;
640 EXPECT_TRUE(message->const_attributes()->GetRawAttributeValue(
641 NL80211_ATTR_RESP_IE, &rawdata));
642 }
643}
644
645TEST_F(NetlinkMessageTest, Build_NL80211_CMD_CONNECT) {
646 // Build the message that is found in kNL80211_CMD_CONNECT.
647 ConnectMessage message;
648 EXPECT_TRUE(message.attributes()->CreateAttribute(NL80211_ATTR_WIPHY,
649 Bind(&NetlinkAttribute::NewNl80211AttributeFromId)));
650 EXPECT_TRUE(message.attributes()->SetU32AttributeValue(NL80211_ATTR_WIPHY,
651 kWiPhy));
652
653 EXPECT_TRUE(message.attributes()->CreateAttribute(NL80211_ATTR_IFINDEX,
654 Bind(&NetlinkAttribute::NewNl80211AttributeFromId)));
655 EXPECT_TRUE(message.attributes()->SetU32AttributeValue(
656 NL80211_ATTR_IFINDEX, kExpectedIfIndex));
657
658 EXPECT_TRUE(message.attributes()->CreateAttribute(NL80211_ATTR_MAC,
659 Bind(&NetlinkAttribute::NewNl80211AttributeFromId)));
660 EXPECT_TRUE(message.attributes()->SetRawAttributeValue(NL80211_ATTR_MAC,
661 ByteString(kMacAddressBytes, arraysize(kMacAddressBytes))));
662
Wade Guthrie35cb4b92013-04-19 10:46:11 -0700663 // In the middle, let's try adding an attribute without populating it.
664 EXPECT_TRUE(message.attributes()->CreateAttribute(NL80211_ATTR_REG_TYPE,
665 Bind(&NetlinkAttribute::NewNl80211AttributeFromId)));
666
Wade Guthrie12f113a2013-03-12 17:15:46 -0700667 EXPECT_TRUE(message.attributes()->CreateAttribute(NL80211_ATTR_STATUS_CODE,
668 Bind(&NetlinkAttribute::NewNl80211AttributeFromId)));
669 EXPECT_TRUE(message.attributes()->SetU16AttributeValue(
670 NL80211_ATTR_STATUS_CODE, kExpectedConnectStatus));
671
672 EXPECT_TRUE(message.attributes()->CreateAttribute(NL80211_ATTR_RESP_IE,
673 Bind(&NetlinkAttribute::NewNl80211AttributeFromId)));
674 EXPECT_TRUE(message.attributes()->SetRawAttributeValue(NL80211_ATTR_RESP_IE,
675 ByteString(kAssignedRespIeBytes, arraysize(kAssignedRespIeBytes))));
676
677 // Encode the message to a ByteString and remove all the run-specific
678 // values.
679 static const uint32_t kArbitrarySequenceNumber = 42;
680 ByteString message_bytes = message.Encode(kArbitrarySequenceNumber);
681 nlmsghdr *header = reinterpret_cast<nlmsghdr *>(message_bytes.GetData());
682 header->nlmsg_flags = 0; // Overwrite with known values.
683 header->nlmsg_seq = 0;
684 header->nlmsg_pid = 0;
685
686 // Verify that the messages are equal.
687 EXPECT_TRUE(message_bytes.Equals(
688 ByteString(kNL80211_CMD_CONNECT, arraysize(kNL80211_CMD_CONNECT))));
689}
690
691
692TEST_F(NetlinkMessageTest, Parse_NL80211_CMD_DEAUTHENTICATE) {
693 NetlinkMessage *netlink_message =
694 message_factory_.CreateMessage(const_cast<nlmsghdr *>(
695 reinterpret_cast<const nlmsghdr *>(kNL80211_CMD_DEAUTHENTICATE)));
696
697 EXPECT_NE(reinterpret_cast<NetlinkMessage *>(NULL), netlink_message);
698 EXPECT_EQ(kNl80211FamilyId, netlink_message->message_type());
699 // The follwing is legal if the message_type is kNl80211FamilyId.
700 Nl80211Message *message = reinterpret_cast<Nl80211Message *>(netlink_message);
701 EXPECT_EQ(NL80211_CMD_DEAUTHENTICATE, message->command());
702
703 {
704 uint32_t value;
705 EXPECT_TRUE(message->const_attributes()->GetU32AttributeValue(
706 NL80211_ATTR_WIPHY, &value));
707 EXPECT_EQ(kWiPhy, value);
708 }
709
710 {
711 uint32_t value;
712 EXPECT_TRUE(message->const_attributes()->GetU32AttributeValue(
713 NL80211_ATTR_IFINDEX, &value));
714 EXPECT_EQ(kExpectedIfIndex, value);
715 }
716
717 {
718 ByteString rawdata;
719 EXPECT_TRUE(message->const_attributes()->GetRawAttributeValue(
720 NL80211_ATTR_FRAME, &rawdata));
721 EXPECT_FALSE(rawdata.IsEmpty());
722 Nl80211Frame frame(rawdata);
723 Nl80211Frame expected_frame(ByteString(kDeauthenticateFrame,
724 sizeof(kDeauthenticateFrame)));
725 EXPECT_TRUE(frame.IsEqual(expected_frame));
726 }
727}
728
729TEST_F(NetlinkMessageTest, Parse_NL80211_CMD_DISCONNECT) {
730 NetlinkMessage *netlink_message =
731 message_factory_.CreateMessage(const_cast<nlmsghdr *>(
732 reinterpret_cast<const nlmsghdr *>(kNL80211_CMD_DISCONNECT)));
733
734 EXPECT_NE(reinterpret_cast<NetlinkMessage *>(NULL), netlink_message);
735 EXPECT_EQ(kNl80211FamilyId, netlink_message->message_type());
736 // The follwing is legal if the message_type is kNl80211FamilyId.
737 Nl80211Message *message = reinterpret_cast<Nl80211Message *>(netlink_message);
738 EXPECT_EQ(NL80211_CMD_DISCONNECT, message->command());
739
740 {
741 uint32_t value;
742 EXPECT_TRUE(message->const_attributes()->GetU32AttributeValue(
743 NL80211_ATTR_WIPHY, &value));
744 EXPECT_EQ(kWiPhy, value);
745 }
746
747 {
748 uint32_t value;
749 EXPECT_TRUE(message->const_attributes()->GetU32AttributeValue(
750 NL80211_ATTR_IFINDEX, &value));
751 EXPECT_EQ(kExpectedIfIndex, value);
752 }
753
754 {
755 uint16_t value;
756 EXPECT_TRUE(message->const_attributes()->GetU16AttributeValue(
757 NL80211_ATTR_REASON_CODE, &value));
758 EXPECT_EQ(kExpectedDisconnectReason, value);
759 }
760
761 EXPECT_TRUE(message->const_attributes()->IsFlagAttributeTrue(
762 NL80211_ATTR_DISCONNECTED_BY_AP));
763}
764
765TEST_F(NetlinkMessageTest, Parse_NL80211_CMD_NOTIFY_CQM) {
766 NetlinkMessage *netlink_message =
767 message_factory_.CreateMessage(const_cast<nlmsghdr *>(
768 reinterpret_cast<const nlmsghdr *>(kNL80211_CMD_NOTIFY_CQM)));
769
770 EXPECT_NE(reinterpret_cast<NetlinkMessage *>(NULL), netlink_message);
771 EXPECT_EQ(kNl80211FamilyId, netlink_message->message_type());
772 // The follwing is legal if the message_type is kNl80211FamilyId.
773 Nl80211Message *message = reinterpret_cast<Nl80211Message *>(netlink_message);
774 EXPECT_EQ(NL80211_CMD_NOTIFY_CQM, message->command());
775
776 {
777 uint32_t value;
778 EXPECT_TRUE(message->const_attributes()->GetU32AttributeValue(
779 NL80211_ATTR_WIPHY, &value));
780 EXPECT_EQ(kWiPhy, value);
781 }
782
783 {
784 uint32_t value;
785 EXPECT_TRUE(message->const_attributes()->GetU32AttributeValue(
786 NL80211_ATTR_IFINDEX, &value));
787 EXPECT_EQ(kExpectedIfIndex, value);
788 }
789
790 {
791 string value;
792 EXPECT_TRUE(message->GetMacAttributeString(NL80211_ATTR_MAC, &value));
793 EXPECT_EQ(0, strncmp(value.c_str(), kExpectedMacAddress, value.length()));
794 }
795
796 {
797 AttributeListConstRefPtr nested;
798 EXPECT_TRUE(message->const_attributes()->ConstGetNestedAttributeList(
799 NL80211_ATTR_CQM, &nested));
800 uint32_t threshold_event;
801 EXPECT_FALSE(nested->GetU32AttributeValue(
802 NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, &threshold_event));
803 uint32_t pkt_loss_event;
804 EXPECT_TRUE(nested->GetU32AttributeValue(
805 NL80211_ATTR_CQM_PKT_LOSS_EVENT, &pkt_loss_event));
806 EXPECT_EQ(kExpectedCqmNotAcked, pkt_loss_event);
807 }
808}
809
810TEST_F(NetlinkMessageTest, Parse_NL80211_CMD_DISASSOCIATE) {
811 NetlinkMessage *netlink_message =
812 message_factory_.CreateMessage(const_cast<nlmsghdr *>(
813 reinterpret_cast<const nlmsghdr *>(kNL80211_CMD_DISASSOCIATE)));
814
815 EXPECT_NE(reinterpret_cast<NetlinkMessage *>(NULL), netlink_message);
816 EXPECT_EQ(kNl80211FamilyId, netlink_message->message_type());
817 // The follwing is legal if the message_type is kNl80211FamilyId.
818 Nl80211Message *message = reinterpret_cast<Nl80211Message *>(netlink_message);
819 EXPECT_EQ(NL80211_CMD_DISASSOCIATE, message->command());
820
821
822 {
823 uint32_t value;
824 EXPECT_TRUE(message->const_attributes()->GetU32AttributeValue(
825 NL80211_ATTR_WIPHY, &value));
826 EXPECT_EQ(kWiPhy, value);
827 }
828
829 {
830 uint32_t value;
831 EXPECT_TRUE(message->const_attributes()->GetU32AttributeValue(
832 NL80211_ATTR_IFINDEX, &value));
833 EXPECT_EQ(kExpectedIfIndex, value);
834 }
835
836 {
837 ByteString rawdata;
838 EXPECT_TRUE(message->const_attributes()->GetRawAttributeValue(
839 NL80211_ATTR_FRAME, &rawdata));
840 EXPECT_FALSE(rawdata.IsEmpty());
841 Nl80211Frame frame(rawdata);
842 Nl80211Frame expected_frame(ByteString(kDisassociateFrame,
843 sizeof(kDisassociateFrame)));
844 EXPECT_TRUE(frame.IsEqual(expected_frame));
845 }
846}
847
Wade Guthrie40d992c2013-04-19 11:10:11 -0700848// This test is to ensure that an unknown nl80211 message generates an
849// Nl80211UnknownMessage with all Nl80211 parts.
850TEST_F(NetlinkMessageTest, Parse_NL80211_CMD_UNKNOWN) {
851 ScopedMockLog log;
852 string logmessage = StringPrintf(
853 "Unknown/unhandled netlink nl80211 message 0x%02x",
854 kCmdNL80211_CMD_UNKNOWN);
855 EXPECT_CALL(log, Log(logging::LOG_WARNING, _, EndsWith(logmessage.c_str())));
856 NetlinkMessage *netlink_message =
857 message_factory_.CreateMessage(
858 reinterpret_cast<const nlmsghdr *>(kNL80211_CMD_UNKNOWN));
859 ASSERT_NE(reinterpret_cast<NetlinkMessage *>(NULL), netlink_message);
860 EXPECT_EQ(kNl80211FamilyId, netlink_message->message_type());
861 // The follwing is legal if the message_type is kNl80211FamilyId.
862 Nl80211Message *message = dynamic_cast<Nl80211Message *>(netlink_message);
863 EXPECT_EQ(kCmdNL80211_CMD_UNKNOWN, message->command());
864}
865
Wade Guthrie12f113a2013-03-12 17:15:46 -0700866} // namespace shill