Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 1 | // Copyright (c) 2012 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 |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 6 | // Nl80211MessageFactory's ability to create specific message types and it |
| 7 | // tests the various Nl80211Message types' ability to parse those |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 8 | // messages. |
| 9 | |
| 10 | // This file tests the public interface to Config80211. |
| 11 | |
| 12 | #include "shill/config80211.h" |
| 13 | |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 14 | #include <net/if.h> |
| 15 | #include <netlink/attr.h> |
| 16 | #include <netlink/genl/genl.h> |
| 17 | #include <netlink/msg.h> |
| 18 | #include <netlink/netlink.h> |
| 19 | |
Wade Guthrie | b1ec860 | 2012-10-18 17:26:14 -0700 | [diff] [blame] | 20 | #include <list> |
| 21 | #include <string> |
| 22 | #include <vector> |
| 23 | |
| 24 | #include <base/bind.h> |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 25 | #include <gmock/gmock.h> |
| 26 | #include <gtest/gtest.h> |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 27 | |
Wade Guthrie | b1ec860 | 2012-10-18 17:26:14 -0700 | [diff] [blame] | 28 | #include "shill/mock_callback80211_object.h" |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 29 | #include "shill/mock_nl80211_socket.h" |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 30 | #include "shill/nl80211_attribute.h" |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 31 | #include "shill/nl80211_message.h" |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 32 | #include "shill/nl80211_socket.h" |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 33 | |
| 34 | using base::Bind; |
| 35 | using base::Unretained; |
repo sync | 12cca80 | 2012-12-19 17:34:22 -0800 | [diff] [blame] | 36 | using base::WeakPtr; |
Wade Guthrie | b1ec860 | 2012-10-18 17:26:14 -0700 | [diff] [blame] | 37 | using std::list; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 38 | using std::string; |
| 39 | using std::vector; |
| 40 | using testing::_; |
Wade Guthrie | 5d3d6de | 2012-11-02 11:08:34 -0700 | [diff] [blame] | 41 | using testing::Invoke; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 42 | using testing::Return; |
| 43 | using testing::Test; |
| 44 | |
| 45 | namespace shill { |
| 46 | |
| 47 | namespace { |
| 48 | |
| 49 | // These data blocks have been collected by shill using Config80211 while, |
| 50 | // simultaneously (and manually) comparing shill output with that of the 'iw' |
| 51 | // code from which it was derived. The test strings represent the raw packet |
| 52 | // data coming from the kernel. The comments above each of these strings is |
| 53 | // the markup that "iw" outputs for ech of these packets. |
| 54 | |
| 55 | // These constants are consistent throughout the packets, below. |
| 56 | |
| 57 | const uint32_t kExpectedIfIndex = 4; |
repo sync | 1538d44 | 2012-12-20 15:24:35 -0800 | [diff] [blame] | 58 | const uint32_t kExpectedWifi = 0; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 59 | const char kExpectedMacAddress[] = "c0:3f:0e:77:e8:7f"; |
| 60 | |
| 61 | |
| 62 | // wlan0 (phy #0): scan started |
| 63 | |
| 64 | const uint32_t kScanFrequencyTrigger[] = { |
| 65 | 2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, |
| 66 | 2452, 2457, 2462, 2467, 2472, 2484, 5180, 5200, |
| 67 | 5220, 5240, 5260, 5280, 5300, 5320, 5500, 5520, |
| 68 | 5540, 5560, 5580, 5600, 5620, 5640, 5660, 5680, |
| 69 | 5700, 5745, 5765, 5785, 5805, 5825 |
| 70 | }; |
| 71 | |
| 72 | const unsigned char kNL80211_CMD_TRIGGER_SCAN[] = { |
| 73 | 0x68, 0x01, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, |
| 74 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 75 | 0x21, 0x01, 0x00, 0x00, 0x08, 0x00, 0x01, 0x00, |
| 76 | 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x03, 0x00, |
| 77 | 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x2d, 0x00, |
| 78 | 0x04, 0x00, 0x00, 0x00, 0x34, 0x01, 0x2c, 0x00, |
| 79 | 0x08, 0x00, 0x00, 0x00, 0x6c, 0x09, 0x00, 0x00, |
| 80 | 0x08, 0x00, 0x01, 0x00, 0x71, 0x09, 0x00, 0x00, |
| 81 | 0x08, 0x00, 0x02, 0x00, 0x76, 0x09, 0x00, 0x00, |
| 82 | 0x08, 0x00, 0x03, 0x00, 0x7b, 0x09, 0x00, 0x00, |
| 83 | 0x08, 0x00, 0x04, 0x00, 0x80, 0x09, 0x00, 0x00, |
| 84 | 0x08, 0x00, 0x05, 0x00, 0x85, 0x09, 0x00, 0x00, |
| 85 | 0x08, 0x00, 0x06, 0x00, 0x8a, 0x09, 0x00, 0x00, |
| 86 | 0x08, 0x00, 0x07, 0x00, 0x8f, 0x09, 0x00, 0x00, |
| 87 | 0x08, 0x00, 0x08, 0x00, 0x94, 0x09, 0x00, 0x00, |
| 88 | 0x08, 0x00, 0x09, 0x00, 0x99, 0x09, 0x00, 0x00, |
| 89 | 0x08, 0x00, 0x0a, 0x00, 0x9e, 0x09, 0x00, 0x00, |
| 90 | 0x08, 0x00, 0x0b, 0x00, 0xa3, 0x09, 0x00, 0x00, |
| 91 | 0x08, 0x00, 0x0c, 0x00, 0xa8, 0x09, 0x00, 0x00, |
| 92 | 0x08, 0x00, 0x0d, 0x00, 0xb4, 0x09, 0x00, 0x00, |
| 93 | 0x08, 0x00, 0x0e, 0x00, 0x3c, 0x14, 0x00, 0x00, |
| 94 | 0x08, 0x00, 0x0f, 0x00, 0x50, 0x14, 0x00, 0x00, |
| 95 | 0x08, 0x00, 0x10, 0x00, 0x64, 0x14, 0x00, 0x00, |
| 96 | 0x08, 0x00, 0x11, 0x00, 0x78, 0x14, 0x00, 0x00, |
| 97 | 0x08, 0x00, 0x12, 0x00, 0x8c, 0x14, 0x00, 0x00, |
| 98 | 0x08, 0x00, 0x13, 0x00, 0xa0, 0x14, 0x00, 0x00, |
| 99 | 0x08, 0x00, 0x14, 0x00, 0xb4, 0x14, 0x00, 0x00, |
| 100 | 0x08, 0x00, 0x15, 0x00, 0xc8, 0x14, 0x00, 0x00, |
| 101 | 0x08, 0x00, 0x16, 0x00, 0x7c, 0x15, 0x00, 0x00, |
| 102 | 0x08, 0x00, 0x17, 0x00, 0x90, 0x15, 0x00, 0x00, |
| 103 | 0x08, 0x00, 0x18, 0x00, 0xa4, 0x15, 0x00, 0x00, |
| 104 | 0x08, 0x00, 0x19, 0x00, 0xb8, 0x15, 0x00, 0x00, |
| 105 | 0x08, 0x00, 0x1a, 0x00, 0xcc, 0x15, 0x00, 0x00, |
| 106 | 0x08, 0x00, 0x1b, 0x00, 0xe0, 0x15, 0x00, 0x00, |
| 107 | 0x08, 0x00, 0x1c, 0x00, 0xf4, 0x15, 0x00, 0x00, |
| 108 | 0x08, 0x00, 0x1d, 0x00, 0x08, 0x16, 0x00, 0x00, |
| 109 | 0x08, 0x00, 0x1e, 0x00, 0x1c, 0x16, 0x00, 0x00, |
| 110 | 0x08, 0x00, 0x1f, 0x00, 0x30, 0x16, 0x00, 0x00, |
| 111 | 0x08, 0x00, 0x20, 0x00, 0x44, 0x16, 0x00, 0x00, |
| 112 | 0x08, 0x00, 0x21, 0x00, 0x71, 0x16, 0x00, 0x00, |
| 113 | 0x08, 0x00, 0x22, 0x00, 0x85, 0x16, 0x00, 0x00, |
| 114 | 0x08, 0x00, 0x23, 0x00, 0x99, 0x16, 0x00, 0x00, |
| 115 | 0x08, 0x00, 0x24, 0x00, 0xad, 0x16, 0x00, 0x00, |
| 116 | 0x08, 0x00, 0x25, 0x00, 0xc1, 0x16, 0x00, 0x00, |
| 117 | 0x08, 0x00, 0x73, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 118 | }; |
| 119 | |
| 120 | |
| 121 | // wlan0 (phy #0): scan finished: 2412 2417 2422 2427 2432 2437 2442 2447 2452 |
| 122 | // 2457 2462 2467 2472 2484 5180 5200 5220 5240 5260 5280 5300 5320 5500 5520 |
| 123 | // 5540 5560 5580 5600 5620 5640 5660 5680 5700 5745 5765 5785 5805 5825, "" |
| 124 | |
| 125 | const uint32_t kScanFrequencyResults[] = { |
| 126 | 2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, |
| 127 | 2452, 2457, 2462, 2467, 2472, 2484, 5180, 5200, |
| 128 | 5220, 5240, 5260, 5280, 5300, 5320, 5500, 5520, |
| 129 | 5540, 5560, 5580, 5600, 5620, 5640, 5660, 5680, |
| 130 | 5700, 5745, 5765, 5785, 5805, 5825 |
| 131 | }; |
| 132 | |
| 133 | const unsigned char kNL80211_CMD_NEW_SCAN_RESULTS[] = { |
| 134 | 0x68, 0x01, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, |
| 135 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 136 | 0x22, 0x01, 0x00, 0x00, 0x08, 0x00, 0x01, 0x00, |
| 137 | 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x03, 0x00, |
| 138 | 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x2d, 0x00, |
| 139 | 0x04, 0x00, 0x00, 0x00, 0x34, 0x01, 0x2c, 0x00, |
| 140 | 0x08, 0x00, 0x00, 0x00, 0x6c, 0x09, 0x00, 0x00, |
| 141 | 0x08, 0x00, 0x01, 0x00, 0x71, 0x09, 0x00, 0x00, |
| 142 | 0x08, 0x00, 0x02, 0x00, 0x76, 0x09, 0x00, 0x00, |
| 143 | 0x08, 0x00, 0x03, 0x00, 0x7b, 0x09, 0x00, 0x00, |
| 144 | 0x08, 0x00, 0x04, 0x00, 0x80, 0x09, 0x00, 0x00, |
| 145 | 0x08, 0x00, 0x05, 0x00, 0x85, 0x09, 0x00, 0x00, |
| 146 | 0x08, 0x00, 0x06, 0x00, 0x8a, 0x09, 0x00, 0x00, |
| 147 | 0x08, 0x00, 0x07, 0x00, 0x8f, 0x09, 0x00, 0x00, |
| 148 | 0x08, 0x00, 0x08, 0x00, 0x94, 0x09, 0x00, 0x00, |
| 149 | 0x08, 0x00, 0x09, 0x00, 0x99, 0x09, 0x00, 0x00, |
| 150 | 0x08, 0x00, 0x0a, 0x00, 0x9e, 0x09, 0x00, 0x00, |
| 151 | 0x08, 0x00, 0x0b, 0x00, 0xa3, 0x09, 0x00, 0x00, |
| 152 | 0x08, 0x00, 0x0c, 0x00, 0xa8, 0x09, 0x00, 0x00, |
| 153 | 0x08, 0x00, 0x0d, 0x00, 0xb4, 0x09, 0x00, 0x00, |
| 154 | 0x08, 0x00, 0x0e, 0x00, 0x3c, 0x14, 0x00, 0x00, |
| 155 | 0x08, 0x00, 0x0f, 0x00, 0x50, 0x14, 0x00, 0x00, |
| 156 | 0x08, 0x00, 0x10, 0x00, 0x64, 0x14, 0x00, 0x00, |
| 157 | 0x08, 0x00, 0x11, 0x00, 0x78, 0x14, 0x00, 0x00, |
| 158 | 0x08, 0x00, 0x12, 0x00, 0x8c, 0x14, 0x00, 0x00, |
| 159 | 0x08, 0x00, 0x13, 0x00, 0xa0, 0x14, 0x00, 0x00, |
| 160 | 0x08, 0x00, 0x14, 0x00, 0xb4, 0x14, 0x00, 0x00, |
| 161 | 0x08, 0x00, 0x15, 0x00, 0xc8, 0x14, 0x00, 0x00, |
| 162 | 0x08, 0x00, 0x16, 0x00, 0x7c, 0x15, 0x00, 0x00, |
| 163 | 0x08, 0x00, 0x17, 0x00, 0x90, 0x15, 0x00, 0x00, |
| 164 | 0x08, 0x00, 0x18, 0x00, 0xa4, 0x15, 0x00, 0x00, |
| 165 | 0x08, 0x00, 0x19, 0x00, 0xb8, 0x15, 0x00, 0x00, |
| 166 | 0x08, 0x00, 0x1a, 0x00, 0xcc, 0x15, 0x00, 0x00, |
| 167 | 0x08, 0x00, 0x1b, 0x00, 0xe0, 0x15, 0x00, 0x00, |
| 168 | 0x08, 0x00, 0x1c, 0x00, 0xf4, 0x15, 0x00, 0x00, |
| 169 | 0x08, 0x00, 0x1d, 0x00, 0x08, 0x16, 0x00, 0x00, |
| 170 | 0x08, 0x00, 0x1e, 0x00, 0x1c, 0x16, 0x00, 0x00, |
| 171 | 0x08, 0x00, 0x1f, 0x00, 0x30, 0x16, 0x00, 0x00, |
| 172 | 0x08, 0x00, 0x20, 0x00, 0x44, 0x16, 0x00, 0x00, |
| 173 | 0x08, 0x00, 0x21, 0x00, 0x71, 0x16, 0x00, 0x00, |
| 174 | 0x08, 0x00, 0x22, 0x00, 0x85, 0x16, 0x00, 0x00, |
| 175 | 0x08, 0x00, 0x23, 0x00, 0x99, 0x16, 0x00, 0x00, |
| 176 | 0x08, 0x00, 0x24, 0x00, 0xad, 0x16, 0x00, 0x00, |
| 177 | 0x08, 0x00, 0x25, 0x00, 0xc1, 0x16, 0x00, 0x00, |
| 178 | 0x08, 0x00, 0x73, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 179 | }; |
| 180 | |
| 181 | |
| 182 | // wlan0: new station c0:3f:0e:77:e8:7f |
| 183 | |
| 184 | const uint32_t kNewStationExpectedGeneration = 275; |
| 185 | |
| 186 | const unsigned char kNL80211_CMD_NEW_STATION[] = { |
| 187 | 0x34, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, |
| 188 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 189 | 0x13, 0x01, 0x00, 0x00, 0x08, 0x00, 0x03, 0x00, |
| 190 | 0x04, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x06, 0x00, |
| 191 | 0xc0, 0x3f, 0x0e, 0x77, 0xe8, 0x7f, 0x00, 0x00, |
| 192 | 0x08, 0x00, 0x2e, 0x00, 0x13, 0x01, 0x00, 0x00, |
| 193 | 0x04, 0x00, 0x15, 0x00, |
| 194 | }; |
| 195 | |
| 196 | |
| 197 | // wlan0 (phy #0): auth c0:3f:0e:77:e8:7f -> 48:5d:60:77:2d:cf status: 0: |
| 198 | // Successful [frame: b0 00 3a 01 48 5d 60 77 2d cf c0 3f 0e 77 e8 7f c0 |
| 199 | // 3f 0e 77 e8 7f 30 07 00 00 02 00 00 00] |
| 200 | |
| 201 | const unsigned char kAuthenticateFrame[] = { |
| 202 | 0xb0, 0x00, 0x3a, 0x01, 0x48, 0x5d, 0x60, 0x77, |
| 203 | 0x2d, 0xcf, 0xc0, 0x3f, 0x0e, 0x77, 0xe8, 0x7f, |
| 204 | 0xc0, 0x3f, 0x0e, 0x77, 0xe8, 0x7f, 0x30, 0x07, |
| 205 | 0x00, 0x00, 0x02, 0x00, 0x00, 0x00 |
| 206 | }; |
| 207 | |
| 208 | const unsigned char kNL80211_CMD_AUTHENTICATE[] = { |
| 209 | 0x48, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, |
| 210 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 211 | 0x25, 0x01, 0x00, 0x00, 0x08, 0x00, 0x01, 0x00, |
| 212 | 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x03, 0x00, |
| 213 | 0x04, 0x00, 0x00, 0x00, 0x22, 0x00, 0x33, 0x00, |
| 214 | 0xb0, 0x00, 0x3a, 0x01, 0x48, 0x5d, 0x60, 0x77, |
| 215 | 0x2d, 0xcf, 0xc0, 0x3f, 0x0e, 0x77, 0xe8, 0x7f, |
| 216 | 0xc0, 0x3f, 0x0e, 0x77, 0xe8, 0x7f, 0x30, 0x07, |
| 217 | 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 218 | }; |
| 219 | |
| 220 | |
| 221 | // wlan0 (phy #0): assoc c0:3f:0e:77:e8:7f -> 48:5d:60:77:2d:cf status: 0: |
| 222 | // Successful [frame: 10 00 3a 01 48 5d 60 77 2d cf c0 3f 0e 77 e8 7f c0 3f 0e |
| 223 | // 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 |
| 224 | // 60 6c] |
| 225 | |
| 226 | const unsigned char kAssociateFrame[] = { |
| 227 | 0x10, 0x00, 0x3a, 0x01, 0x48, 0x5d, 0x60, 0x77, |
| 228 | 0x2d, 0xcf, 0xc0, 0x3f, 0x0e, 0x77, 0xe8, 0x7f, |
| 229 | 0xc0, 0x3f, 0x0e, 0x77, 0xe8, 0x7f, 0x40, 0x07, |
| 230 | 0x01, 0x04, 0x00, 0x00, 0x01, 0xc0, 0x01, 0x08, |
| 231 | 0x82, 0x84, 0x8b, 0x96, 0x0c, 0x12, 0x18, 0x24, |
| 232 | 0x32, 0x04, 0x30, 0x48, 0x60, 0x6c |
| 233 | }; |
| 234 | |
| 235 | const unsigned char kNL80211_CMD_ASSOCIATE[] = { |
| 236 | 0x58, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, |
| 237 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 238 | 0x26, 0x01, 0x00, 0x00, 0x08, 0x00, 0x01, 0x00, |
| 239 | 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x03, 0x00, |
| 240 | 0x04, 0x00, 0x00, 0x00, 0x32, 0x00, 0x33, 0x00, |
| 241 | 0x10, 0x00, 0x3a, 0x01, 0x48, 0x5d, 0x60, 0x77, |
| 242 | 0x2d, 0xcf, 0xc0, 0x3f, 0x0e, 0x77, 0xe8, 0x7f, |
| 243 | 0xc0, 0x3f, 0x0e, 0x77, 0xe8, 0x7f, 0x40, 0x07, |
| 244 | 0x01, 0x04, 0x00, 0x00, 0x01, 0xc0, 0x01, 0x08, |
| 245 | 0x82, 0x84, 0x8b, 0x96, 0x0c, 0x12, 0x18, 0x24, |
| 246 | 0x32, 0x04, 0x30, 0x48, 0x60, 0x6c, 0x00, 0x00, |
| 247 | }; |
| 248 | |
| 249 | |
| 250 | // wlan0 (phy #0): connected to c0:3f:0e:77:e8:7f |
| 251 | |
| 252 | const uint16_t kExpectedConnectStatus = 0; |
| 253 | |
| 254 | const unsigned char kNL80211_CMD_CONNECT[] = { |
| 255 | 0x4c, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, |
| 256 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 257 | 0x2e, 0x01, 0x00, 0x00, 0x08, 0x00, 0x01, 0x00, |
| 258 | 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x03, 0x00, |
| 259 | 0x04, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x06, 0x00, |
| 260 | 0xc0, 0x3f, 0x0e, 0x77, 0xe8, 0x7f, 0x00, 0x00, |
| 261 | 0x06, 0x00, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 262 | 0x14, 0x00, 0x4e, 0x00, 0x01, 0x08, 0x82, 0x84, |
| 263 | 0x8b, 0x96, 0x0c, 0x12, 0x18, 0x24, 0x32, 0x04, |
| 264 | 0x30, 0x48, 0x60, 0x6c, |
| 265 | }; |
| 266 | |
| 267 | |
| 268 | // wlan0 (phy #0): deauth c0:3f:0e:77:e8:7f -> ff:ff:ff:ff:ff:ff reason 2: |
| 269 | // Previous authentication no longer valid [frame: c0 00 00 00 ff ff ff ff |
| 270 | // ff ff c0 3f 0e 77 e8 7f c0 3f 0e 77 e8 7f c0 0e 02 00] |
| 271 | |
| 272 | const unsigned char kDeauthenticateFrame[] = { |
Wade Guthrie | b1ec860 | 2012-10-18 17:26:14 -0700 | [diff] [blame] | 273 | 0xc0, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, |
| 274 | 0xff, 0xff, 0xc0, 0x3f, 0x0e, 0x77, 0xe8, 0x7f, |
| 275 | 0xc0, 0x3f, 0x0e, 0x77, 0xe8, 0x7f, 0xc0, 0x0e, |
| 276 | 0x02, 0x00 |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 277 | }; |
| 278 | |
| 279 | const unsigned char kNL80211_CMD_DEAUTHENTICATE[] = { |
| 280 | 0x44, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, |
| 281 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 282 | 0x27, 0x01, 0x00, 0x00, 0x08, 0x00, 0x01, 0x00, |
| 283 | 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x03, 0x00, |
| 284 | 0x04, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x33, 0x00, |
| 285 | 0xc0, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, |
| 286 | 0xff, 0xff, 0xc0, 0x3f, 0x0e, 0x77, 0xe8, 0x7f, |
| 287 | 0xc0, 0x3f, 0x0e, 0x77, 0xe8, 0x7f, 0xc0, 0x0e, |
| 288 | 0x02, 0x00, 0x00, 0x00, |
| 289 | }; |
| 290 | |
| 291 | |
| 292 | // wlan0 (phy #0): disconnected (by AP) reason: 2: Previous authentication no |
| 293 | // longer valid |
| 294 | |
| 295 | const uint16_t kExpectedDisconnectReason = 2; |
| 296 | |
| 297 | const unsigned char kNL80211_CMD_DISCONNECT[] = { |
| 298 | 0x30, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, |
| 299 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 300 | 0x30, 0x01, 0x00, 0x00, 0x08, 0x00, 0x01, 0x00, |
| 301 | 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x03, 0x00, |
| 302 | 0x04, 0x00, 0x00, 0x00, 0x06, 0x00, 0x36, 0x00, |
| 303 | 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x47, 0x00, |
| 304 | }; |
| 305 | |
| 306 | |
| 307 | // wlan0 (phy #0): connection quality monitor event: peer c0:3f:0e:77:e8:7f |
| 308 | // didn't ACK 50 packets |
| 309 | |
| 310 | const uint32_t kExpectedCqmNotAcked = 50; |
| 311 | |
| 312 | const unsigned char kNL80211_CMD_NOTIFY_CQM[] = { |
| 313 | 0x3c, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, |
| 314 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 315 | 0x40, 0x01, 0x00, 0x00, 0x08, 0x00, 0x01, 0x00, |
| 316 | 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x03, 0x00, |
| 317 | 0x04, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x06, 0x00, |
| 318 | 0xc0, 0x3f, 0x0e, 0x77, 0xe8, 0x7f, 0x00, 0x00, |
| 319 | 0x0c, 0x00, 0x5e, 0x00, 0x08, 0x00, 0x04, 0x00, |
| 320 | 0x32, 0x00, 0x00, 0x00, |
| 321 | }; |
| 322 | |
| 323 | |
| 324 | // wlan0 (phy #0): disassoc 48:5d:60:77:2d:cf -> c0:3f:0e:77:e8:7f reason 3: |
| 325 | // Deauthenticated because sending station is [frame: a0 00 00 00 c0 3f 0e |
| 326 | // 77 e8 7f 48 5d 60 77 2d cf c0 3f 0e 77 e8 7f 00 00 03 00] |
| 327 | |
| 328 | const unsigned char kDisassociateFrame[] = { |
| 329 | 0xa0, 0x00, 0x00, 0x00, 0xc0, 0x3f, 0x0e, 0x77, |
| 330 | 0xe8, 0x7f, 0x48, 0x5d, 0x60, 0x77, 0x2d, 0xcf, |
| 331 | 0xc0, 0x3f, 0x0e, 0x77, 0xe8, 0x7f, 0x00, 0x00, |
| 332 | 0x03, 0x00 |
| 333 | }; |
| 334 | |
| 335 | const unsigned char kNL80211_CMD_DISASSOCIATE[] = { |
| 336 | 0x44, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, |
| 337 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 338 | 0x28, 0x01, 0x00, 0x00, 0x08, 0x00, 0x01, 0x00, |
| 339 | 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x03, 0x00, |
| 340 | 0x04, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x33, 0x00, |
| 341 | 0xa0, 0x00, 0x00, 0x00, 0xc0, 0x3f, 0x0e, 0x77, |
| 342 | 0xe8, 0x7f, 0x48, 0x5d, 0x60, 0x77, 0x2d, 0xcf, |
| 343 | 0xc0, 0x3f, 0x0e, 0x77, 0xe8, 0x7f, 0x00, 0x00, |
| 344 | 0x03, 0x00, 0x00, 0x00, |
| 345 | }; |
| 346 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 347 | const char kGetFamilyCommandString[] = "CTRL_CMD_GETFAMILY"; |
| 348 | |
Wade Guthrie | b1ec860 | 2012-10-18 17:26:14 -0700 | [diff] [blame] | 349 | } // namespace |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 350 | |
| 351 | bool MockNl80211Socket::SendMessage(Nl80211Message *message) { |
| 352 | if (!message) { |
| 353 | LOG(ERROR) << "Null |message|"; |
| 354 | return false; |
Christopher Wiley | 393b93f | 2012-11-08 17:30:58 -0800 | [diff] [blame] | 355 | } |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 356 | return true; |
| 357 | } |
| 358 | |
| 359 | uint32_t MockNl80211Socket::GetSequenceNumber() { |
| 360 | // Sequence number 0 is reserved for broadcast messages from the kernel. |
| 361 | if (++sequence_number_ == 0) |
| 362 | ++sequence_number_; |
| 363 | return sequence_number_; |
Christopher Wiley | 393b93f | 2012-11-08 17:30:58 -0800 | [diff] [blame] | 364 | } |
Wade Guthrie | 5d3d6de | 2012-11-02 11:08:34 -0700 | [diff] [blame] | 365 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 366 | class Config80211Test : public Test { |
| 367 | public: |
| 368 | Config80211Test() : config80211_(Config80211::GetInstance()) {} |
Han Shen | 4afba20 | 2012-12-17 08:48:35 -0800 | [diff] [blame] | 369 | ~Config80211Test() { |
| 370 | // Config80211 is a singleton, the sock_ field *MUST* be cleared |
| 371 | // before "Config80211Test::socket_" gets invalidated, otherwise |
| 372 | // later tests will refer to a corrupted memory. |
| 373 | config80211_->sock_ = NULL; |
| 374 | } |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 375 | void SetupConfig80211Object() { |
| 376 | EXPECT_NE(config80211_, reinterpret_cast<Config80211 *>(NULL)); |
| 377 | config80211_->sock_ = &socket_; |
| 378 | EXPECT_TRUE(config80211_->Init(reinterpret_cast<EventDispatcher *>(NULL))); |
Wade Guthrie | d615361 | 2012-08-23 11:36:14 -0700 | [diff] [blame] | 379 | config80211_->Reset(); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | Config80211 *config80211_; |
| 383 | MockNl80211Socket socket_; |
| 384 | }; |
| 385 | |
| 386 | class TestCallbackObject { |
| 387 | public: |
| 388 | TestCallbackObject() : callback_(Bind(&TestCallbackObject::MessageHandler, |
| 389 | Unretained(this))) { } |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 390 | void MessageHandler(const Nl80211Message &msg) { |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 391 | } |
| 392 | const Config80211::Callback &GetCallback() const { return callback_; } |
| 393 | |
| 394 | private: |
| 395 | Config80211::Callback callback_; |
| 396 | }; |
| 397 | |
Wade Guthrie | b1ec860 | 2012-10-18 17:26:14 -0700 | [diff] [blame] | 398 | // Checks a config80211 parameter to make sure it contains |callback_arg| |
| 399 | // in its list of broadcast callbacks. |
| 400 | MATCHER_P(ContainsCallback, callback_arg, "") { |
| 401 | if (arg == reinterpret_cast<void *>(NULL)) { |
| 402 | LOG(WARNING) << "NULL parameter"; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 403 | return false; |
Wade Guthrie | b1ec860 | 2012-10-18 17:26:14 -0700 | [diff] [blame] | 404 | } |
| 405 | const Config80211 *config80211 = static_cast<Config80211 *>(arg); |
| 406 | const Config80211::Callback callback = |
| 407 | static_cast<const Config80211::Callback>(callback_arg); |
| 408 | |
| 409 | return config80211->FindBroadcastCallback(callback); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | TEST_F(Config80211Test, AddLinkTest) { |
| 413 | SetupConfig80211Object(); |
| 414 | |
Wade Guthrie | b1ec860 | 2012-10-18 17:26:14 -0700 | [diff] [blame] | 415 | // Create a broadcast callback. |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 416 | TestCallbackObject callback_object; |
| 417 | |
Wade Guthrie | d615361 | 2012-08-23 11:36:14 -0700 | [diff] [blame] | 418 | // Install the callback and subscribe to events using it, wifi down |
Wade Guthrie | b1ec860 | 2012-10-18 17:26:14 -0700 | [diff] [blame] | 419 | // (shouldn't actually send the subscription request until wifi comes up). |
Wade Guthrie | d615361 | 2012-08-23 11:36:14 -0700 | [diff] [blame] | 420 | EXPECT_CALL(socket_, AddGroupMembership(_)).Times(0); |
Wade Guthrie | d615361 | 2012-08-23 11:36:14 -0700 | [diff] [blame] | 421 | |
Wade Guthrie | b1ec860 | 2012-10-18 17:26:14 -0700 | [diff] [blame] | 422 | EXPECT_TRUE(config80211_->AddBroadcastCallback( |
| 423 | callback_object.GetCallback())); |
Wade Guthrie | d615361 | 2012-08-23 11:36:14 -0700 | [diff] [blame] | 424 | Config80211::EventType scan_event = Config80211::kEventTypeScan; |
| 425 | string scan_event_string; |
| 426 | EXPECT_TRUE(Config80211::GetEventTypeString(scan_event, &scan_event_string)); |
| 427 | EXPECT_TRUE(config80211_->SubscribeToEvents(scan_event)); |
| 428 | |
| 429 | // Wifi up, should subscribe to events. |
| 430 | EXPECT_CALL(socket_, AddGroupMembership(scan_event_string)) |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 431 | .WillOnce(Return(true)); |
Wade Guthrie | d615361 | 2012-08-23 11:36:14 -0700 | [diff] [blame] | 432 | config80211_->SetWifiState(Config80211::kWifiUp); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 433 | |
Wade Guthrie | d615361 | 2012-08-23 11:36:14 -0700 | [diff] [blame] | 434 | // Second subscribe, same event (should do nothing). |
| 435 | EXPECT_CALL(socket_, AddGroupMembership(_)).Times(0); |
Wade Guthrie | d615361 | 2012-08-23 11:36:14 -0700 | [diff] [blame] | 436 | EXPECT_TRUE(config80211_->SubscribeToEvents(scan_event)); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 437 | |
Wade Guthrie | d615361 | 2012-08-23 11:36:14 -0700 | [diff] [blame] | 438 | // Bring the wifi back down. |
| 439 | config80211_->SetWifiState(Config80211::kWifiDown); |
| 440 | |
| 441 | // Subscribe to a new event with the wifi down (should still do nothing). |
| 442 | Config80211::EventType mlme_event = Config80211::kEventTypeMlme; |
| 443 | string mlme_event_string; |
| 444 | EXPECT_TRUE(Config80211::GetEventTypeString(mlme_event, &mlme_event_string)); |
| 445 | EXPECT_TRUE(config80211_->SubscribeToEvents(mlme_event)); |
| 446 | |
| 447 | // Wifi up (again), should subscribe to the original scan event and the new |
| 448 | // mlme event. |
| 449 | EXPECT_CALL(socket_, AddGroupMembership(scan_event_string)) |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 450 | .WillOnce(Return(true)); |
Wade Guthrie | d615361 | 2012-08-23 11:36:14 -0700 | [diff] [blame] | 451 | EXPECT_CALL(socket_, AddGroupMembership(mlme_event_string)) |
| 452 | .WillOnce(Return(true)); |
Wade Guthrie | d615361 | 2012-08-23 11:36:14 -0700 | [diff] [blame] | 453 | config80211_->SetWifiState(Config80211::kWifiUp); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 454 | } |
| 455 | |
Wade Guthrie | 5d3d6de | 2012-11-02 11:08:34 -0700 | [diff] [blame] | 456 | TEST_F(Config80211Test, BroadcastCallbackTest) { |
| 457 | SetupConfig80211Object(); |
| 458 | |
| 459 | nlmsghdr *message = const_cast<nlmsghdr *>( |
| 460 | reinterpret_cast<const nlmsghdr *>(kNL80211_CMD_DISCONNECT)); |
| 461 | |
Christopher Wiley | fe34be0 | 2012-11-12 16:02:46 -0800 | [diff] [blame] | 462 | MockCallback80211 callback1; |
| 463 | MockCallback80211 callback2; |
Wade Guthrie | 5d3d6de | 2012-11-02 11:08:34 -0700 | [diff] [blame] | 464 | |
| 465 | // Simple, 1 callback, case. |
| 466 | EXPECT_CALL(callback1, Config80211MessageCallback(_)).Times(1); |
Christopher Wiley | fe34be0 | 2012-11-12 16:02:46 -0800 | [diff] [blame] | 467 | callback1.InstallAsBroadcastCallback(); |
Wade Guthrie | 5d3d6de | 2012-11-02 11:08:34 -0700 | [diff] [blame] | 468 | config80211_->OnNlMessageReceived(message); |
| 469 | |
| 470 | // Add a second callback. |
| 471 | EXPECT_CALL(callback1, Config80211MessageCallback(_)).Times(1); |
| 472 | EXPECT_CALL(callback2, Config80211MessageCallback(_)).Times(1); |
| 473 | EXPECT_TRUE(callback2.InstallAsBroadcastCallback()); |
| 474 | config80211_->OnNlMessageReceived(message); |
| 475 | |
| 476 | // Verify that a callback can't be added twice. |
| 477 | EXPECT_CALL(callback1, Config80211MessageCallback(_)).Times(1); |
| 478 | EXPECT_CALL(callback2, Config80211MessageCallback(_)).Times(1); |
| 479 | EXPECT_FALSE(callback1.InstallAsBroadcastCallback()); |
| 480 | config80211_->OnNlMessageReceived(message); |
| 481 | |
| 482 | // Check that we can remove a callback. |
| 483 | EXPECT_CALL(callback1, Config80211MessageCallback(_)).Times(0); |
| 484 | EXPECT_CALL(callback2, Config80211MessageCallback(_)).Times(1); |
| 485 | EXPECT_TRUE(callback1.DeinstallAsCallback()); |
| 486 | config80211_->OnNlMessageReceived(message); |
| 487 | |
| 488 | // Check that re-adding the callback goes smoothly. |
| 489 | EXPECT_CALL(callback1, Config80211MessageCallback(_)).Times(1); |
| 490 | EXPECT_CALL(callback2, Config80211MessageCallback(_)).Times(1); |
| 491 | EXPECT_TRUE(callback1.InstallAsBroadcastCallback()); |
| 492 | config80211_->OnNlMessageReceived(message); |
| 493 | |
| 494 | // Check that ClearBroadcastCallbacks works. |
| 495 | config80211_->ClearBroadcastCallbacks(); |
| 496 | EXPECT_CALL(callback1, Config80211MessageCallback(_)).Times(0); |
| 497 | EXPECT_CALL(callback2, Config80211MessageCallback(_)).Times(0); |
| 498 | config80211_->OnNlMessageReceived(message); |
| 499 | } |
| 500 | |
| 501 | TEST_F(Config80211Test, MessageCallbackTest) { |
| 502 | // Setup. |
| 503 | SetupConfig80211Object(); |
| 504 | |
Christopher Wiley | fe34be0 | 2012-11-12 16:02:46 -0800 | [diff] [blame] | 505 | MockCallback80211 callback_broadcast; |
Wade Guthrie | 5d3d6de | 2012-11-02 11:08:34 -0700 | [diff] [blame] | 506 | EXPECT_TRUE(callback_broadcast.InstallAsBroadcastCallback()); |
| 507 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 508 | Nl80211Message sent_message_1(CTRL_CMD_GETFAMILY, kGetFamilyCommandString); |
Christopher Wiley | fe34be0 | 2012-11-12 16:02:46 -0800 | [diff] [blame] | 509 | MockCallback80211 callback_sent_1; |
Wade Guthrie | 5d3d6de | 2012-11-02 11:08:34 -0700 | [diff] [blame] | 510 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 511 | Nl80211Message sent_message_2(CTRL_CMD_GETFAMILY, kGetFamilyCommandString); |
Christopher Wiley | fe34be0 | 2012-11-12 16:02:46 -0800 | [diff] [blame] | 512 | MockCallback80211 callback_sent_2; |
Wade Guthrie | 5d3d6de | 2012-11-02 11:08:34 -0700 | [diff] [blame] | 513 | |
| 514 | // Set up the received message as a response to sent_message_1. |
| 515 | scoped_array<unsigned char> message_memory( |
| 516 | new unsigned char[sizeof(kNL80211_CMD_DISCONNECT)]); |
| 517 | memcpy(message_memory.get(), kNL80211_CMD_DISCONNECT, |
| 518 | sizeof(kNL80211_CMD_DISCONNECT)); |
| 519 | nlmsghdr *received_message = |
| 520 | reinterpret_cast<nlmsghdr *>(message_memory.get()); |
Wade Guthrie | 5d3d6de | 2012-11-02 11:08:34 -0700 | [diff] [blame] | 521 | |
| 522 | // Now, we can start the actual test... |
| 523 | |
| 524 | // Verify that generic callback gets called for a message when no |
| 525 | // message-specific callback has been installed. |
| 526 | EXPECT_CALL(callback_broadcast, Config80211MessageCallback(_)).Times(1); |
| 527 | config80211_->OnNlMessageReceived(received_message); |
| 528 | |
Christopher Wiley | 393b93f | 2012-11-08 17:30:58 -0800 | [diff] [blame] | 529 | // Send the message and give our callback. Verify that we get called back. |
| 530 | EXPECT_TRUE(config80211_->SendMessage(&sent_message_1, |
Christopher Wiley | fe34be0 | 2012-11-12 16:02:46 -0800 | [diff] [blame] | 531 | callback_sent_1.callback())); |
Christopher Wiley | 393b93f | 2012-11-08 17:30:58 -0800 | [diff] [blame] | 532 | // Make it appear that this message is in response to our sent message. |
| 533 | received_message->nlmsg_seq = socket_.GetLastSequenceNumber(); |
Wade Guthrie | 5d3d6de | 2012-11-02 11:08:34 -0700 | [diff] [blame] | 534 | EXPECT_CALL(callback_sent_1, Config80211MessageCallback(_)).Times(1); |
| 535 | config80211_->OnNlMessageReceived(received_message); |
| 536 | |
| 537 | // Verify that broadcast callback is called for the message after the |
| 538 | // message-specific callback is called once. |
| 539 | EXPECT_CALL(callback_broadcast, Config80211MessageCallback(_)).Times(1); |
| 540 | config80211_->OnNlMessageReceived(received_message); |
| 541 | |
| 542 | // Install and then uninstall message-specific callback; verify broadcast |
| 543 | // callback is called on message receipt. |
Christopher Wiley | 393b93f | 2012-11-08 17:30:58 -0800 | [diff] [blame] | 544 | EXPECT_TRUE(config80211_->SendMessage(&sent_message_1, |
Christopher Wiley | fe34be0 | 2012-11-12 16:02:46 -0800 | [diff] [blame] | 545 | callback_sent_1.callback())); |
Christopher Wiley | 393b93f | 2012-11-08 17:30:58 -0800 | [diff] [blame] | 546 | received_message->nlmsg_seq = socket_.GetLastSequenceNumber(); |
| 547 | EXPECT_TRUE(config80211_->RemoveMessageCallback(sent_message_1)); |
Wade Guthrie | 5d3d6de | 2012-11-02 11:08:34 -0700 | [diff] [blame] | 548 | EXPECT_CALL(callback_broadcast, Config80211MessageCallback(_)).Times(1); |
| 549 | config80211_->OnNlMessageReceived(received_message); |
| 550 | |
| 551 | // Install callback for different message; verify that broadcast callback is |
| 552 | // called for _this_ message. |
Christopher Wiley | 393b93f | 2012-11-08 17:30:58 -0800 | [diff] [blame] | 553 | EXPECT_TRUE(config80211_->SendMessage(&sent_message_2, |
Christopher Wiley | fe34be0 | 2012-11-12 16:02:46 -0800 | [diff] [blame] | 554 | callback_sent_2.callback())); |
Wade Guthrie | 5d3d6de | 2012-11-02 11:08:34 -0700 | [diff] [blame] | 555 | EXPECT_CALL(callback_broadcast, Config80211MessageCallback(_)).Times(1); |
| 556 | config80211_->OnNlMessageReceived(received_message); |
| 557 | |
| 558 | // Change the ID for the message to that of the second callback; verify that |
| 559 | // the appropriate callback is called for _that_ message. |
Christopher Wiley | 393b93f | 2012-11-08 17:30:58 -0800 | [diff] [blame] | 560 | received_message->nlmsg_seq = socket_.GetLastSequenceNumber(); |
Wade Guthrie | 5d3d6de | 2012-11-02 11:08:34 -0700 | [diff] [blame] | 561 | EXPECT_CALL(callback_sent_2, Config80211MessageCallback(_)).Times(1); |
| 562 | config80211_->OnNlMessageReceived(received_message); |
| 563 | } |
| 564 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 565 | TEST_F(Config80211Test, NL80211_CMD_TRIGGER_SCAN) { |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 566 | Nl80211Message *message = Nl80211MessageFactory::CreateMessage( |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 567 | const_cast<nlmsghdr *>( |
| 568 | reinterpret_cast<const nlmsghdr *>(kNL80211_CMD_TRIGGER_SCAN))); |
| 569 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 570 | EXPECT_NE(message, reinterpret_cast<Nl80211Message *>(NULL)); |
Christopher Wiley | 764538d | 2012-11-09 10:58:23 -0800 | [diff] [blame] | 571 | EXPECT_EQ(message->message_type(), NL80211_CMD_TRIGGER_SCAN); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 572 | |
| 573 | { |
repo sync | d316eb7 | 2012-12-10 15:48:47 -0800 | [diff] [blame] | 574 | uint32_t value; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 575 | EXPECT_TRUE(message->attributes().GetU32AttributeValue(NL80211_ATTR_WIPHY, |
| 576 | &value)); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 577 | EXPECT_EQ(value, kExpectedWifi); |
| 578 | } |
| 579 | |
| 580 | { |
| 581 | uint32_t value; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 582 | EXPECT_TRUE(message->attributes().GetU32AttributeValue(NL80211_ATTR_IFINDEX, |
| 583 | &value)); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 584 | EXPECT_EQ(value, kExpectedIfIndex); |
| 585 | } |
| 586 | |
| 587 | // Make sure the scan frequencies in the attribute are the ones we expect. |
| 588 | { |
| 589 | vector<uint32_t>list; |
| 590 | EXPECT_TRUE(message->GetScanFrequenciesAttribute( |
| 591 | NL80211_ATTR_SCAN_FREQUENCIES, &list)); |
| 592 | EXPECT_EQ(arraysize(kScanFrequencyTrigger), list.size()); |
| 593 | int i = 0; |
| 594 | vector<uint32_t>::const_iterator j = list.begin(); |
| 595 | while (j != list.end()) { |
| 596 | EXPECT_EQ(kScanFrequencyTrigger[i], *j); |
| 597 | ++i; |
| 598 | ++j; |
| 599 | } |
| 600 | } |
| 601 | |
| 602 | { |
| 603 | vector<string> ssids; |
| 604 | EXPECT_TRUE(message->GetScanSsidsAttribute(NL80211_ATTR_SCAN_SSIDS, |
| 605 | &ssids)); |
| 606 | EXPECT_EQ(ssids.size(), 1); |
| 607 | EXPECT_EQ(ssids[0].compare(""), 0); // Expect a single, empty SSID. |
| 608 | } |
| 609 | |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 610 | EXPECT_TRUE(message->attributes().IsFlagAttributeTrue( |
| 611 | NL80211_ATTR_SUPPORT_MESH_AUTH)); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | TEST_F(Config80211Test, NL80211_CMD_NEW_SCAN_RESULTS) { |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 615 | Nl80211Message *message = Nl80211MessageFactory::CreateMessage( |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 616 | const_cast<nlmsghdr *>( |
| 617 | reinterpret_cast<const nlmsghdr *>(kNL80211_CMD_NEW_SCAN_RESULTS))); |
| 618 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 619 | EXPECT_NE(message, reinterpret_cast<Nl80211Message *>(NULL)); |
Christopher Wiley | 764538d | 2012-11-09 10:58:23 -0800 | [diff] [blame] | 620 | EXPECT_EQ(message->message_type(), NL80211_CMD_NEW_SCAN_RESULTS); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 621 | |
| 622 | { |
repo sync | d316eb7 | 2012-12-10 15:48:47 -0800 | [diff] [blame] | 623 | uint32_t value; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 624 | EXPECT_TRUE(message->attributes().GetU32AttributeValue(NL80211_ATTR_WIPHY, |
| 625 | &value)); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 626 | EXPECT_EQ(value, kExpectedWifi); |
| 627 | } |
| 628 | |
| 629 | { |
| 630 | uint32_t value; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 631 | EXPECT_TRUE(message->attributes().GetU32AttributeValue(NL80211_ATTR_IFINDEX, |
| 632 | &value)); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 633 | EXPECT_EQ(value, kExpectedIfIndex); |
| 634 | } |
| 635 | |
| 636 | // Make sure the scan frequencies in the attribute are the ones we expect. |
| 637 | { |
| 638 | vector<uint32_t>list; |
| 639 | EXPECT_TRUE(message->GetScanFrequenciesAttribute( |
| 640 | NL80211_ATTR_SCAN_FREQUENCIES, &list)); |
| 641 | EXPECT_EQ(arraysize(kScanFrequencyResults), list.size()); |
| 642 | int i = 0; |
| 643 | vector<uint32_t>::const_iterator j = list.begin(); |
| 644 | while (j != list.end()) { |
| 645 | EXPECT_EQ(kScanFrequencyResults[i], *j); |
| 646 | ++i; |
| 647 | ++j; |
| 648 | } |
| 649 | } |
| 650 | |
| 651 | { |
| 652 | vector<string> ssids; |
| 653 | EXPECT_TRUE(message->GetScanSsidsAttribute(NL80211_ATTR_SCAN_SSIDS, |
| 654 | &ssids)); |
| 655 | EXPECT_EQ(ssids.size(), 1); |
| 656 | EXPECT_EQ(ssids[0].compare(""), 0); // Expect a single, empty SSID. |
| 657 | } |
| 658 | |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 659 | EXPECT_TRUE(message->attributes().IsFlagAttributeTrue( |
| 660 | NL80211_ATTR_SUPPORT_MESH_AUTH)); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | TEST_F(Config80211Test, NL80211_CMD_NEW_STATION) { |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 664 | Nl80211Message *message = Nl80211MessageFactory::CreateMessage( |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 665 | const_cast<nlmsghdr *>( |
| 666 | reinterpret_cast<const nlmsghdr *>(kNL80211_CMD_NEW_STATION))); |
| 667 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 668 | EXPECT_NE(message, reinterpret_cast<Nl80211Message *>(NULL)); |
Christopher Wiley | 764538d | 2012-11-09 10:58:23 -0800 | [diff] [blame] | 669 | EXPECT_EQ(message->message_type(), NL80211_CMD_NEW_STATION); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 670 | |
| 671 | { |
| 672 | uint32_t value; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 673 | EXPECT_TRUE(message->attributes().GetU32AttributeValue(NL80211_ATTR_IFINDEX, |
| 674 | &value)); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 675 | EXPECT_EQ(value, kExpectedIfIndex); |
| 676 | } |
| 677 | |
| 678 | { |
| 679 | string value; |
| 680 | EXPECT_TRUE(message->GetMacAttributeString(NL80211_ATTR_MAC, &value)); |
| 681 | EXPECT_EQ(strncmp(value.c_str(), kExpectedMacAddress, value.length()), 0); |
| 682 | } |
| 683 | |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 684 | // TODO(wdg): Look at nested values of NL80211_ATTR_STA_INFO. |
| 685 | { |
repo sync | 12cca80 | 2012-12-19 17:34:22 -0800 | [diff] [blame] | 686 | WeakPtr<AttributeList> nested; |
| 687 | EXPECT_TRUE(message->attributes().GetNestedAttributeValue( |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 688 | NL80211_ATTR_STA_INFO, &nested)); |
| 689 | } |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 690 | |
| 691 | { |
| 692 | uint32_t value; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 693 | EXPECT_TRUE(message->attributes().GetU32AttributeValue( |
| 694 | NL80211_ATTR_GENERATION, &value)); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 695 | EXPECT_EQ(value, kNewStationExpectedGeneration); |
| 696 | } |
| 697 | } |
| 698 | |
| 699 | TEST_F(Config80211Test, NL80211_CMD_AUTHENTICATE) { |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 700 | Nl80211Message *message = Nl80211MessageFactory::CreateMessage( |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 701 | const_cast<nlmsghdr *>( |
| 702 | reinterpret_cast<const nlmsghdr *>(kNL80211_CMD_AUTHENTICATE))); |
| 703 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 704 | EXPECT_NE(message, reinterpret_cast<Nl80211Message *>(NULL)); |
Christopher Wiley | 764538d | 2012-11-09 10:58:23 -0800 | [diff] [blame] | 705 | EXPECT_EQ(message->message_type(), NL80211_CMD_AUTHENTICATE); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 706 | |
| 707 | { |
repo sync | d316eb7 | 2012-12-10 15:48:47 -0800 | [diff] [blame] | 708 | uint32_t value; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 709 | EXPECT_TRUE(message->attributes().GetU32AttributeValue(NL80211_ATTR_WIPHY, |
| 710 | &value)); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 711 | EXPECT_EQ(value, kExpectedWifi); |
| 712 | } |
| 713 | |
| 714 | { |
| 715 | uint32_t value; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 716 | EXPECT_TRUE(message->attributes().GetU32AttributeValue(NL80211_ATTR_IFINDEX, |
| 717 | &value)); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 718 | EXPECT_EQ(value, kExpectedIfIndex); |
| 719 | } |
| 720 | |
| 721 | { |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 722 | ByteString rawdata; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 723 | EXPECT_TRUE(message->attributes().GetRawAttributeValue(NL80211_ATTR_FRAME, |
| 724 | &rawdata)); |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 725 | EXPECT_FALSE(rawdata.IsEmpty()); |
| 726 | Nl80211Frame frame(rawdata); |
| 727 | Nl80211Frame expected_frame(ByteString(kAuthenticateFrame, |
| 728 | sizeof(kAuthenticateFrame))); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 729 | EXPECT_TRUE(frame.IsEqual(expected_frame)); |
| 730 | } |
| 731 | } |
| 732 | |
| 733 | TEST_F(Config80211Test, NL80211_CMD_ASSOCIATE) { |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 734 | Nl80211Message *message = Nl80211MessageFactory::CreateMessage( |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 735 | const_cast<nlmsghdr *>( |
| 736 | reinterpret_cast<const nlmsghdr *>(kNL80211_CMD_ASSOCIATE))); |
| 737 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 738 | EXPECT_NE(message, reinterpret_cast<Nl80211Message *>(NULL)); |
Christopher Wiley | 764538d | 2012-11-09 10:58:23 -0800 | [diff] [blame] | 739 | EXPECT_EQ(message->message_type(), NL80211_CMD_ASSOCIATE); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 740 | |
| 741 | { |
repo sync | d316eb7 | 2012-12-10 15:48:47 -0800 | [diff] [blame] | 742 | uint32_t value; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 743 | EXPECT_TRUE(message->attributes().GetU32AttributeValue(NL80211_ATTR_WIPHY, |
| 744 | &value)); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 745 | EXPECT_EQ(value, kExpectedWifi); |
| 746 | } |
| 747 | |
| 748 | { |
| 749 | uint32_t value; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 750 | EXPECT_TRUE(message->attributes().GetU32AttributeValue(NL80211_ATTR_IFINDEX, |
| 751 | &value)); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 752 | EXPECT_EQ(value, kExpectedIfIndex); |
| 753 | } |
| 754 | |
| 755 | { |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 756 | ByteString rawdata; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 757 | EXPECT_TRUE(message->attributes().GetRawAttributeValue(NL80211_ATTR_FRAME, |
| 758 | &rawdata)); |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 759 | EXPECT_FALSE(rawdata.IsEmpty()); |
| 760 | Nl80211Frame frame(rawdata); |
| 761 | Nl80211Frame expected_frame(ByteString(kAssociateFrame, |
| 762 | sizeof(kAssociateFrame))); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 763 | EXPECT_TRUE(frame.IsEqual(expected_frame)); |
| 764 | } |
| 765 | } |
| 766 | |
| 767 | TEST_F(Config80211Test, NL80211_CMD_CONNECT) { |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 768 | Nl80211Message *message = Nl80211MessageFactory::CreateMessage( |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 769 | const_cast<nlmsghdr *>( |
| 770 | reinterpret_cast<const nlmsghdr *>(kNL80211_CMD_CONNECT))); |
| 771 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 772 | EXPECT_NE(message, reinterpret_cast<Nl80211Message *>(NULL)); |
Christopher Wiley | 764538d | 2012-11-09 10:58:23 -0800 | [diff] [blame] | 773 | EXPECT_EQ(message->message_type(), NL80211_CMD_CONNECT); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 774 | |
| 775 | { |
repo sync | d316eb7 | 2012-12-10 15:48:47 -0800 | [diff] [blame] | 776 | uint32_t value; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 777 | EXPECT_TRUE(message->attributes().GetU32AttributeValue(NL80211_ATTR_WIPHY, |
| 778 | &value)); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 779 | EXPECT_EQ(value, kExpectedWifi); |
| 780 | } |
| 781 | |
| 782 | { |
| 783 | uint32_t value; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 784 | EXPECT_TRUE(message->attributes().GetU32AttributeValue(NL80211_ATTR_IFINDEX, |
| 785 | &value)); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 786 | EXPECT_EQ(value, kExpectedIfIndex); |
| 787 | } |
| 788 | |
| 789 | { |
| 790 | string value; |
| 791 | EXPECT_TRUE(message->GetMacAttributeString(NL80211_ATTR_MAC, &value)); |
| 792 | EXPECT_EQ(strncmp(value.c_str(), kExpectedMacAddress, value.length()), 0); |
| 793 | } |
| 794 | |
| 795 | { |
| 796 | uint16_t value; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 797 | EXPECT_TRUE(message->attributes().GetU16AttributeValue( |
| 798 | NL80211_ATTR_STATUS_CODE, &value)); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 799 | EXPECT_EQ(value, kExpectedConnectStatus); |
| 800 | } |
| 801 | |
| 802 | // TODO(wdg): Need to check the value of this attribute. |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 803 | { |
| 804 | ByteString rawdata; |
| 805 | EXPECT_TRUE(message->attributes().GetRawAttributeValue(NL80211_ATTR_RESP_IE, |
| 806 | &rawdata)); |
| 807 | } |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 808 | } |
| 809 | |
| 810 | TEST_F(Config80211Test, NL80211_CMD_DEAUTHENTICATE) { |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 811 | Nl80211Message *message = Nl80211MessageFactory::CreateMessage( |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 812 | const_cast<nlmsghdr *>( |
| 813 | reinterpret_cast<const nlmsghdr *>(kNL80211_CMD_DEAUTHENTICATE))); |
| 814 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 815 | EXPECT_NE(message, reinterpret_cast<Nl80211Message *>(NULL)); |
Christopher Wiley | 764538d | 2012-11-09 10:58:23 -0800 | [diff] [blame] | 816 | EXPECT_EQ(message->message_type(), NL80211_CMD_DEAUTHENTICATE); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 817 | |
| 818 | { |
repo sync | d316eb7 | 2012-12-10 15:48:47 -0800 | [diff] [blame] | 819 | uint32_t value; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 820 | EXPECT_TRUE(message->attributes().GetU32AttributeValue(NL80211_ATTR_WIPHY, |
| 821 | &value)); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 822 | EXPECT_EQ(value, kExpectedWifi); |
| 823 | } |
| 824 | |
| 825 | { |
| 826 | uint32_t value; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 827 | EXPECT_TRUE(message->attributes().GetU32AttributeValue(NL80211_ATTR_IFINDEX, |
| 828 | &value)); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 829 | EXPECT_EQ(value, kExpectedIfIndex); |
| 830 | } |
| 831 | |
| 832 | { |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 833 | ByteString rawdata; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 834 | EXPECT_TRUE(message->attributes().GetRawAttributeValue(NL80211_ATTR_FRAME, |
| 835 | &rawdata)); |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 836 | EXPECT_FALSE(rawdata.IsEmpty()); |
| 837 | Nl80211Frame frame(rawdata); |
| 838 | Nl80211Frame expected_frame(ByteString(kDeauthenticateFrame, |
| 839 | sizeof(kDeauthenticateFrame))); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 840 | EXPECT_TRUE(frame.IsEqual(expected_frame)); |
| 841 | } |
| 842 | } |
| 843 | |
| 844 | TEST_F(Config80211Test, NL80211_CMD_DISCONNECT) { |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 845 | Nl80211Message *message = Nl80211MessageFactory::CreateMessage( |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 846 | const_cast<nlmsghdr *>( |
| 847 | reinterpret_cast<const nlmsghdr *>(kNL80211_CMD_DISCONNECT))); |
| 848 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 849 | EXPECT_NE(message, reinterpret_cast<Nl80211Message *>(NULL)); |
Christopher Wiley | 764538d | 2012-11-09 10:58:23 -0800 | [diff] [blame] | 850 | EXPECT_EQ(message->message_type(), NL80211_CMD_DISCONNECT); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 851 | |
| 852 | { |
repo sync | d316eb7 | 2012-12-10 15:48:47 -0800 | [diff] [blame] | 853 | uint32_t value; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 854 | EXPECT_TRUE(message->attributes().GetU32AttributeValue(NL80211_ATTR_WIPHY, |
| 855 | &value)); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 856 | EXPECT_EQ(value, kExpectedWifi); |
| 857 | } |
| 858 | |
| 859 | { |
| 860 | uint32_t value; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 861 | EXPECT_TRUE(message->attributes().GetU32AttributeValue(NL80211_ATTR_IFINDEX, |
| 862 | &value)); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 863 | EXPECT_EQ(value, kExpectedIfIndex); |
| 864 | } |
| 865 | |
| 866 | { |
| 867 | uint16_t value; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 868 | EXPECT_TRUE(message->attributes().GetU16AttributeValue( |
| 869 | NL80211_ATTR_REASON_CODE, &value)); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 870 | EXPECT_EQ(value, kExpectedDisconnectReason); |
| 871 | } |
| 872 | |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 873 | EXPECT_TRUE(message->attributes().IsFlagAttributeTrue( |
| 874 | NL80211_ATTR_DISCONNECTED_BY_AP)); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 875 | } |
| 876 | |
| 877 | TEST_F(Config80211Test, NL80211_CMD_NOTIFY_CQM) { |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 878 | Nl80211Message *message = Nl80211MessageFactory::CreateMessage( |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 879 | const_cast<nlmsghdr *>( |
| 880 | reinterpret_cast<const nlmsghdr *>(kNL80211_CMD_NOTIFY_CQM))); |
| 881 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 882 | EXPECT_NE(message, reinterpret_cast<Nl80211Message *>(NULL)); |
Christopher Wiley | 764538d | 2012-11-09 10:58:23 -0800 | [diff] [blame] | 883 | EXPECT_EQ(message->message_type(), NL80211_CMD_NOTIFY_CQM); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 884 | |
| 885 | |
| 886 | { |
repo sync | d316eb7 | 2012-12-10 15:48:47 -0800 | [diff] [blame] | 887 | uint32_t value; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 888 | EXPECT_TRUE(message->attributes().GetU32AttributeValue(NL80211_ATTR_WIPHY, |
| 889 | &value)); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 890 | EXPECT_EQ(value, kExpectedWifi); |
| 891 | } |
| 892 | |
| 893 | { |
| 894 | uint32_t value; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 895 | EXPECT_TRUE(message->attributes().GetU32AttributeValue(NL80211_ATTR_IFINDEX, |
| 896 | &value)); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 897 | EXPECT_EQ(value, kExpectedIfIndex); |
| 898 | } |
| 899 | |
| 900 | { |
| 901 | string value; |
| 902 | EXPECT_TRUE(message->GetMacAttributeString(NL80211_ATTR_MAC, &value)); |
| 903 | EXPECT_EQ(strncmp(value.c_str(), kExpectedMacAddress, value.length()), 0); |
| 904 | } |
| 905 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 906 | { |
repo sync | 12cca80 | 2012-12-19 17:34:22 -0800 | [diff] [blame] | 907 | WeakPtr<AttributeList> nested; |
| 908 | EXPECT_TRUE(message->attributes().GetNestedAttributeValue(NL80211_ATTR_CQM, |
| 909 | &nested)); |
Wade Guthrie | 3af8b4d | 2013-01-10 08:39:30 -0800 | [diff] [blame^] | 910 | uint32_t threshold_event; |
| 911 | EXPECT_FALSE(nested->GetU32AttributeValue( |
| 912 | NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, &threshold_event)); |
repo sync | 12cca80 | 2012-12-19 17:34:22 -0800 | [diff] [blame] | 913 | uint32_t pkt_loss_event; |
| 914 | EXPECT_TRUE(nested->GetU32AttributeValue( |
| 915 | NL80211_ATTR_CQM_PKT_LOSS_EVENT, &pkt_loss_event)); |
| 916 | EXPECT_EQ(pkt_loss_event, kExpectedCqmNotAcked); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 917 | } |
| 918 | } |
| 919 | |
| 920 | TEST_F(Config80211Test, NL80211_CMD_DISASSOCIATE) { |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 921 | Nl80211Message *message = Nl80211MessageFactory::CreateMessage( |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 922 | const_cast<nlmsghdr *>( |
| 923 | reinterpret_cast<const nlmsghdr *>(kNL80211_CMD_DISASSOCIATE))); |
| 924 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 925 | EXPECT_NE(message, reinterpret_cast<Nl80211Message *>(NULL)); |
Christopher Wiley | 764538d | 2012-11-09 10:58:23 -0800 | [diff] [blame] | 926 | EXPECT_EQ(message->message_type(), NL80211_CMD_DISASSOCIATE); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 927 | |
| 928 | |
| 929 | { |
repo sync | d316eb7 | 2012-12-10 15:48:47 -0800 | [diff] [blame] | 930 | uint32_t value; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 931 | EXPECT_TRUE(message->attributes().GetU32AttributeValue(NL80211_ATTR_WIPHY, |
| 932 | &value)); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 933 | EXPECT_EQ(value, kExpectedWifi); |
| 934 | } |
| 935 | |
| 936 | { |
| 937 | uint32_t value; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 938 | EXPECT_TRUE(message->attributes().GetU32AttributeValue(NL80211_ATTR_IFINDEX, |
| 939 | &value)); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 940 | EXPECT_EQ(value, kExpectedIfIndex); |
| 941 | } |
| 942 | |
| 943 | { |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 944 | ByteString rawdata; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 945 | EXPECT_TRUE(message->attributes().GetRawAttributeValue(NL80211_ATTR_FRAME, |
| 946 | &rawdata)); |
Wade Guthrie | 8343f7f | 2012-12-04 13:52:32 -0800 | [diff] [blame] | 947 | EXPECT_FALSE(rawdata.IsEmpty()); |
| 948 | Nl80211Frame frame(rawdata); |
| 949 | Nl80211Frame expected_frame(ByteString(kDisassociateFrame, |
| 950 | sizeof(kDisassociateFrame))); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 951 | EXPECT_TRUE(frame.IsEqual(expected_frame)); |
| 952 | } |
| 953 | } |
| 954 | |
| 955 | } // namespace shill |