1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
/*
* Copyright 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define PACKET_TESTING
#include "l2cap/l2cap_packets.h"
#include <gtest/gtest.h>
#include <forward_list>
#include <memory>
#include "os/log.h"
#include "packet/bit_inserter.h"
#include "packet/raw_builder.h"
using bluetooth::packet::BitInserter;
using bluetooth::packet::RawBuilder;
using std::vector;
namespace bluetooth {
namespace l2cap {
std::vector<uint8_t> extended_information_start_frame = {
0x0B, /* First size byte */
0x00, /* Second size byte */
0xc1, /* First ChannelId byte */
0xc2, /**/
0x4A, /* 0x12 ReqSeq, Final, IFrame */
0xD0, /* 0x13 ReqSeq */
0x89, /* 0x21 TxSeq sar = START */
0x8C, /* 0x23 TxSeq */
0x10, /* first length byte */
0x11, /**/
0x01, /* first payload byte */
0x02, 0x03, 0x04, 0x05,
};
DEFINE_AND_INSTANTIATE_ExtendedInformationStartFrameReflectionTest(extended_information_start_frame);
std::vector<uint8_t> i_frame_with_fcs = {0x0E, 0x00, 0x40, 0x00, 0x02, 0x00, 0x00, 0x01, 0x02,
0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x38, 0x61};
DEFINE_AND_INSTANTIATE_StandardInformationFrameWithFcsReflectionTest(i_frame_with_fcs);
std::vector<uint8_t> rr_frame_with_fcs = {0x04, 0x00, 0x40, 0x00, 0x01, 0x01, 0xD4, 0x14};
DEFINE_AND_INSTANTIATE_StandardSupervisoryFrameWithFcsReflectionTest(rr_frame_with_fcs);
std::vector<uint8_t> g_frame = {0x03, 0x00, 0x02, 0x00, 0x01, 0x02, 0x03};
DEFINE_AND_INSTANTIATE_GroupFrameReflectionTest(g_frame);
std::vector<uint8_t> config_mtu_request = {0x04, 0x05, 0x08, 0x00, 0x41, 0x00, 0x00, 0x00, 0x01, 0x02, 0xa0, 0x02};
DEFINE_AND_INSTANTIATE_ConfigurationRequestReflectionTest(config_mtu_request);
std::vector<uint8_t> config_request_one_defined_option = {0x04, 0x05, 0x08, 0x00, 0x41, 0x00,
0x00, 0x00, 0x01, 0x02, 0x12, 0x34};
std::vector<uint8_t> config_request_two_defined_options = {0x04, 0x05, 0x0c, 0x00, 0x41, 0x00, 0x00, 0x00,
0x01, 0x02, 0x12, 0x34, 0x02, 0x02, 0x56, 0x78};
std::vector<uint8_t> config_request_two_undefined_options = {0x04, 0x05, 0x0e, 0x00, 0x41, 0x00, 0x00, 0x00, 0x7f,
0x02, 0x01, 0x00, 0x7e, 0x04, 0x11, 0x11, 0x00, 0x00};
std::vector<uint8_t> config_request_hint_one_defined_option = {0x04, 0x05, 0x08, 0x00, 0x41, 0x00,
0x00, 0x00, 0x81, 0x02, 0x12, 0x34};
std::vector<uint8_t> config_request_hint_two_undefined_options = {0x04, 0x05, 0x0c, 0x00, 0x41, 0x00, 0x00, 0x00,
0x90, 0x02, 0x01, 0x00, 0x91, 0x02, 0x11, 0x11};
TEST(L2capPacketsTest, testConfigRequestOptions) {
{
std::shared_ptr<std::vector<uint8_t>> view_bytes =
std::make_shared<std::vector<uint8_t>>(config_request_one_defined_option);
PacketView<kLittleEndian> packet_bytes_view(view_bytes);
auto view = ConfigurationRequestView::Create(ControlView::Create(packet_bytes_view));
ASSERT_TRUE(view.IsValid());
ASSERT_EQ(1ul, view.GetConfig().size());
}
{
std::shared_ptr<std::vector<uint8_t>> view_bytes =
std::make_shared<std::vector<uint8_t>>(config_request_two_defined_options);
PacketView<kLittleEndian> packet_bytes_view(view_bytes);
auto view = ConfigurationRequestView::Create(ControlView::Create(packet_bytes_view));
ASSERT_TRUE(view.IsValid());
ASSERT_EQ(2ul, view.GetConfig().size());
}
{
std::shared_ptr<std::vector<uint8_t>> view_bytes =
std::make_shared<std::vector<uint8_t>>(config_request_two_undefined_options);
PacketView<kLittleEndian> packet_bytes_view(view_bytes);
auto view = ConfigurationRequestView::Create(ControlView::Create(packet_bytes_view));
ASSERT_TRUE(view.IsValid());
ASSERT_EQ(2ul, view.GetConfig().size());
}
{
std::shared_ptr<std::vector<uint8_t>> view_bytes =
std::make_shared<std::vector<uint8_t>>(config_request_hint_one_defined_option);
PacketView<kLittleEndian> packet_bytes_view(view_bytes);
auto view = ConfigurationRequestView::Create(ControlView::Create(packet_bytes_view));
ASSERT_TRUE(view.IsValid());
ASSERT_EQ(1ul, view.GetConfig().size());
}
{
std::shared_ptr<std::vector<uint8_t>> view_bytes =
std::make_shared<std::vector<uint8_t>>(config_request_hint_two_undefined_options);
PacketView<kLittleEndian> packet_bytes_view(view_bytes);
auto view = ConfigurationRequestView::Create(ControlView::Create(packet_bytes_view));
ASSERT_TRUE(view.IsValid());
ASSERT_EQ(2ul, view.GetConfig().size());
}
}
DEFINE_ConfigurationRequestReflectionFuzzTest();
TEST(L2capFuzzRegressions, ConfigurationRequestFuzz_5691566077247488) {
uint8_t bluetooth_gd_fuzz_test_5691566077247488[] = {
0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
RunConfigurationRequestReflectionFuzzTest(bluetooth_gd_fuzz_test_5691566077247488,
sizeof(bluetooth_gd_fuzz_test_5691566077247488));
}
TEST(L2capFuzzRegressions, ConfigurationRequestFuzz_5747922062802944) {
uint8_t bluetooth_gd_fuzz_test_5747922062802944[] = {
0x04, 0x02, 0x02, 0x7f, 0x3f, 0x7f, 0x3f, 0x7e, 0x7f,
};
RunConfigurationRequestReflectionFuzzTest(bluetooth_gd_fuzz_test_5747922062802944,
sizeof(bluetooth_gd_fuzz_test_5747922062802944));
}
TEST(L2capFuzzRegressions, ConfigurationRequestFuzz_5202709231697920) {
uint8_t bluetooth_gd_fuzz_test_5747922062802944[] = {
0x04, 0x01, 0x45, 0x45, 0x05, 0x01, 0x01, 0x45, 0x05, 0x01,
};
RunConfigurationRequestReflectionFuzzTest(bluetooth_gd_fuzz_test_5747922062802944,
sizeof(bluetooth_gd_fuzz_test_5747922062802944));
}
} // namespace l2cap
} // namespace bluetooth
|