Upgrade bluez5_37 :Merge the code from private
[platform/upstream/bluez.git] / unit / test-eir.c
1 /*
2  *
3  *  BlueZ - Bluetooth protocol stack for Linux
4  *
5  *  Copyright (C) 2011  Intel Corporation
6  *
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21  *
22  */
23
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27
28 #include <stdbool.h>
29
30 #include <glib.h>
31
32 #include "lib/bluetooth.h"
33 #include "lib/hci.h"
34 #include "lib/sdp.h"
35 #include "src/shared/tester.h"
36 #include "src/shared/util.h"
37 #include "src/eir.h"
38
39 struct test_data {
40         const void *eir_data;
41         size_t eir_size;
42         unsigned int flags;
43         const char *name;
44         bool name_complete;
45         int8_t tx_power;
46         const char **uuid;
47 };
48
49 static const unsigned char macbookair_data[] = {
50                 0x17, 0x09, 0x4d, 0x61, 0x72, 0x63, 0x65, 0x6c,
51                 0xe2, 0x80, 0x99, 0x73, 0x20, 0x4d, 0x61, 0x63,
52                 0x42, 0x6f, 0x6f, 0x6b, 0x20, 0x41, 0x69, 0x72,
53                 0x11, 0x03, 0x12, 0x11, 0x0c, 0x11, 0x0a, 0x11,
54                 0x1f, 0x11, 0x01, 0x11, 0x00, 0x10, 0x0a, 0x11,
55                 0x17, 0x11, 0x11, 0xff, 0x4c, 0x00, 0x01, 0x4d,
56                 0x61, 0x63, 0x42, 0x6f, 0x6f, 0x6b, 0x41, 0x69,
57                 0x72, 0x33, 0x2c, 0x31, 0x00, 0x00, 0x00, 0x00,
58                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
59                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
60                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
61                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
62                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
63                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
64                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
65                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
66                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
67                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
68                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
69                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
70                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
71                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
72                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
73                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
74                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
75                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
76                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
77                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
78                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
79                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
80 };
81
82 static const char *macbookair_uuid[] = {
83                 "00001112-0000-1000-8000-00805f9b34fb",
84                 "0000110c-0000-1000-8000-00805f9b34fb",
85                 "0000110a-0000-1000-8000-00805f9b34fb",
86                 "0000111f-0000-1000-8000-00805f9b34fb",
87                 "00001101-0000-1000-8000-00805f9b34fb",
88                 "00001000-0000-1000-8000-00805f9b34fb",
89                 "0000110a-0000-1000-8000-00805f9b34fb",
90                 "00001117-0000-1000-8000-00805f9b34fb",
91                 NULL
92 };
93
94 static const struct test_data macbookair_test = {
95         .eir_data = macbookair_data,
96         .eir_size = sizeof(macbookair_data),
97         .name = "Marcel’s MacBook Air",
98         .name_complete = true,
99         .tx_power = 127,
100         .uuid = macbookair_uuid,
101 };
102
103 static const unsigned char iphone5_data[] = {
104                 0x14, 0x09, 0x4d, 0x61, 0x72, 0x63, 0x65, 0x6c,
105                 0xe2, 0x80, 0x99, 0x73, 0x20, 0x69, 0x50, 0x68,
106                 0x6f, 0x6e, 0x65, 0x20, 0x35, 0x0f, 0x03, 0x00,
107                 0x12, 0x1f, 0x11, 0x2f, 0x11, 0x0a, 0x11, 0x0c,
108                 0x11, 0x16, 0x11, 0x32, 0x11, 0x01, 0x05, 0x11,
109                 0x07, 0xfe, 0xca, 0xca, 0xde, 0xaf, 0xde, 0xca,
110                 0xde, 0xde, 0xfa, 0xca, 0xde, 0x00, 0x00, 0x00,
111                 0x00, 0x27, 0xff, 0x00, 0x4c, 0x02, 0x24, 0x02,
112                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
113                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
114                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
115                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
116                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
117                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
118                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
119                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
120                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
121                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
122                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
123                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
124                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
125                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
126                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
127                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
128                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
129                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
130                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
131                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
132                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
133                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
134 };
135
136 static const char *iphone5_uuid[] = {
137                 "00001200-0000-1000-8000-00805f9b34fb",
138                 "0000111f-0000-1000-8000-00805f9b34fb",
139                 "0000112f-0000-1000-8000-00805f9b34fb",
140                 "0000110a-0000-1000-8000-00805f9b34fb",
141                 "0000110c-0000-1000-8000-00805f9b34fb",
142                 "00001116-0000-1000-8000-00805f9b34fb",
143                 "00001132-0000-1000-8000-00805f9b34fb",
144                 "00000000-deca-fade-deca-deafdecacafe",
145                 NULL
146 };
147
148 static const struct test_data iphone5_test = {
149         .eir_data = iphone5_data,
150         .eir_size = sizeof(iphone5_data),
151         .name = "Marcel’s iPhone 5",
152         .name_complete = true,
153         .tx_power = 127,
154         .uuid = iphone5_uuid,
155 };
156
157 static const unsigned char ipadmini_data[] = {
158                 0x13, 0x09, 0x4d, 0x61, 0x72, 0x63, 0x65, 0x6c,
159                 0x27, 0x73, 0x20, 0x69, 0x50, 0x61, 0x64, 0x20,
160                 0x6d, 0x69, 0x6e, 0x69, 0x0b, 0x03, 0x00, 0x12,
161                 0x1f, 0x11, 0x0a, 0x11, 0x0c, 0x11, 0x32, 0x11,
162                 0x01, 0x05, 0x11, 0x07, 0xfe, 0xca, 0xca, 0xde,
163                 0xaf, 0xde, 0xca, 0xde, 0xde, 0xfa, 0xca, 0xde,
164                 0x00, 0x00, 0x00, 0x00, 0x27, 0xff, 0x00, 0x4c,
165                 0x02, 0x24, 0x02, 0x0c, 0x00, 0x00, 0x00, 0x00,
166                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
167                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
168                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
169                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
170                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
171                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
172                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
173                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
174                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
175                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
176                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
177                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
178                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
179                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
180                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
181                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
182                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
183                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
184                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
185                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
186                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
187                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
188 };
189
190 static const char *ipadmini_uuid[] = {
191                 "00001200-0000-1000-8000-00805f9b34fb",
192                 "0000111f-0000-1000-8000-00805f9b34fb",
193                 "0000110a-0000-1000-8000-00805f9b34fb",
194                 "0000110c-0000-1000-8000-00805f9b34fb",
195                 "00001132-0000-1000-8000-00805f9b34fb",
196                 "00000000-deca-fade-deca-deafdecacafe",
197                 NULL
198 };
199
200 static const struct test_data ipadmini_test = {
201         .eir_data = ipadmini_data,
202         .eir_size = sizeof(ipadmini_data),
203         .name = "Marcel's iPad mini",
204         .name_complete = true,
205         .tx_power = 127,
206         .uuid = ipadmini_uuid,
207 };
208
209 static const unsigned char gigaset_sl400h_data[] = {
210                 0x0b, 0x03, 0x01, 0x11, 0x05, 0x11, 0x12, 0x11,
211                 0x03, 0x12, 0x1f, 0x11, 0x10, 0x09, 0x4d, 0x61,
212                 0x72, 0x63, 0x65, 0x6c, 0x27, 0x73, 0x20, 0x53,
213                 0x4c, 0x34, 0x30, 0x30, 0x48, 0x00, 0x00, 0x00,
214                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
215                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
216                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
217                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
218                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
219                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
220                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
221                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
222                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
223                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
224                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
225                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
226                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
227                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
228                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
229                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
230                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
231                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
232                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
233                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
234                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
235                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
236                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
237                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
238                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
239                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
240 };
241
242 static const char *gigaset_sl400h_uuid[] = {
243                 "00001101-0000-1000-8000-00805f9b34fb",
244                 "00001105-0000-1000-8000-00805f9b34fb",
245                 "00001112-0000-1000-8000-00805f9b34fb",
246                 "00001203-0000-1000-8000-00805f9b34fb",
247                 "0000111f-0000-1000-8000-00805f9b34fb",
248                 NULL
249 };
250
251 static const struct test_data gigaset_sl400h_test = {
252         .eir_data = gigaset_sl400h_data,
253         .eir_size = sizeof(gigaset_sl400h_data),
254         .name = "Marcel's SL400H",
255         .name_complete = true,
256         .tx_power = 127,
257         .uuid = gigaset_sl400h_uuid,
258 };
259
260 static const unsigned char gigaset_sl910_data[] = {
261                 0x0b, 0x03, 0x01, 0x11, 0x05, 0x11, 0x12, 0x11,
262                 0x03, 0x12, 0x1f, 0x11, 0x0f, 0x09, 0x4d, 0x61,
263                 0x72, 0x63, 0x65, 0x6c, 0x27, 0x73, 0x20, 0x53,
264                 0x4c, 0x39, 0x31, 0x30, 0x00, 0x00, 0x00, 0x00,
265                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
266                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
267                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
268                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
269                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
270                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
271                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
272                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
273                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
274                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
275                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
276                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
277                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
278                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
279                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
280                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
281                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
282                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
283                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
284                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
285                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
286                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
287                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
288                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
289                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
290                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
291 };
292
293 static const char *gigaset_sl910_uuid[] = {
294                 "00001101-0000-1000-8000-00805f9b34fb",
295                 "00001105-0000-1000-8000-00805f9b34fb",
296                 "00001112-0000-1000-8000-00805f9b34fb",
297                 "00001203-0000-1000-8000-00805f9b34fb",
298                 "0000111f-0000-1000-8000-00805f9b34fb",
299                 NULL
300 };
301
302 static const struct test_data gigaset_sl910_test = {
303         .eir_data = gigaset_sl910_data,
304         .eir_size = sizeof(gigaset_sl910_data),
305         .name = "Marcel's SL910",
306         .name_complete = true,
307         .tx_power = 127,
308         .uuid = gigaset_sl910_uuid,
309 };
310
311 static const unsigned char nokia_bh907_data[] = {
312                 0x16, 0x09, 0x4e, 0x6f, 0x6b, 0x69, 0x61, 0x20,
313                 0x52, 0x65, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e,
314                 0x20, 0x42, 0x48, 0x2d, 0x39, 0x30, 0x37, 0x02,
315                 0x0a, 0x04, 0x0f, 0x02, 0x0d, 0x11, 0x0b, 0x11,
316                 0x0e, 0x11, 0x0f, 0x11, 0x1e, 0x11, 0x08, 0x11,
317                 0x31, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
318                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
319                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
320                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
321                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
322                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
323                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
324                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
325                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
326                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
327                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
328                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
329                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
330                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
331                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
332                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
333                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
334                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
335                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
336                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
337                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
338                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
339                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
340                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
341                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
342 };
343
344 static const char *nokia_bh907_uuid[] = {
345                 "0000110d-0000-1000-8000-00805f9b34fb",
346                 "0000110b-0000-1000-8000-00805f9b34fb",
347                 "0000110e-0000-1000-8000-00805f9b34fb",
348                 "0000110f-0000-1000-8000-00805f9b34fb",
349                 "0000111e-0000-1000-8000-00805f9b34fb",
350                 "00001108-0000-1000-8000-00805f9b34fb",
351                 "00001131-0000-1000-8000-00805f9b34fb",
352                 NULL
353 };
354
355 static const struct test_data nokia_bh907_test = {
356         .eir_data = nokia_bh907_data,
357         .eir_size = sizeof(nokia_bh907_data),
358         .name = "Nokia Reaction BH-907",
359         .name_complete = true,
360         .tx_power = 4,
361         .uuid = nokia_bh907_uuid,
362 };
363
364 static const unsigned char fuelband_data[] = {
365                 0x0f, 0x09, 0x4e, 0x69, 0x6b, 0x65, 0x2b, 0x20,
366                 0x46, 0x75, 0x65, 0x6c, 0x42, 0x61, 0x6e, 0x64,
367                 0x11, 0x07, 0x00, 0x00, 0x00, 0x00, 0xde, 0xca,
368                 0xfa, 0xde, 0xde, 0xca, 0xde, 0xaf, 0xde, 0xca,
369                 0xca, 0xff, 0x02, 0x0a, 0x00, 0x00, 0x00, 0x00,
370                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
371                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
372                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
373                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
374                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
375                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
376                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
377                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
378                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
379                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
380                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
381                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
382                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
383                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
384                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
385                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
386                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
387                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
388                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
389                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
390                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
391                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
392                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
393                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
394                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
395 };
396
397 static const char *fuelband_uuid[] = {
398                 "ffcacade-afde-cade-defa-cade00000000",
399                 NULL
400 };
401
402 static const struct test_data fuelband_test = {
403         .eir_data = fuelband_data,
404         .eir_size = sizeof(fuelband_data),
405         .name = "Nike+ FuelBand",
406         .name_complete = true,
407         .tx_power = 0,
408         .uuid = fuelband_uuid,
409 };
410
411 static const unsigned char bluesc_data[] = {
412                 0x02, 0x01, 0x06, 0x03, 0x02, 0x16, 0x18, 0x12,
413                 0x09, 0x57, 0x61, 0x68, 0x6f, 0x6f, 0x20, 0x42,
414                 0x6c, 0x75, 0x65, 0x53, 0x43, 0x20, 0x76, 0x31,
415                 0x2e, 0x34,
416 };
417
418 static const char *bluesc_uuid[] = {
419                 "00001816-0000-1000-8000-00805f9b34fb",
420                 NULL
421 };
422
423 static const struct test_data bluesc_test = {
424         .eir_data = bluesc_data,
425         .eir_size = sizeof(bluesc_data),
426         .flags = 0x06,
427         .name = "Wahoo BlueSC v1.4",
428         .name_complete = true,
429         .tx_power = 127,
430         .uuid = bluesc_uuid,
431 };
432
433 static const unsigned char wahoo_scale_data[] = {
434                 0x02, 0x01, 0x06, 0x03, 0x02, 0x01, 0x19, 0x11,
435                 0x09, 0x57, 0x61, 0x68, 0x6f, 0x6f, 0x20, 0x53,
436                 0x63, 0x61, 0x6c, 0x65, 0x20, 0x76, 0x31, 0x2e,
437                 0x33, 0x05, 0xff, 0x00, 0x00, 0x00, 0x9c,
438 };
439
440 static const char *wahoo_scale_uuid[] = {
441                 "00001901-0000-1000-8000-00805f9b34fb",
442                 NULL
443 };
444
445 static const struct test_data wahoo_scale_test = {
446         .eir_data = wahoo_scale_data,
447         .eir_size = sizeof(wahoo_scale_data),
448         .flags = 0x06,
449         .name = "Wahoo Scale v1.3",
450         .name_complete = true,
451         .tx_power = 127,
452         .uuid = wahoo_scale_uuid,
453 };
454
455 static const unsigned char mio_alpha_data[] = {
456                 0x02, 0x01, 0x06, 0x03, 0x02, 0x0d, 0x18, 0x06,
457                 0x09, 0x41, 0x4c, 0x50, 0x48, 0x41,
458 };
459
460 static const char *mio_alpha_uuid[] = {
461                 "0000180d-0000-1000-8000-00805f9b34fb",
462                 NULL
463 };
464
465 static const struct test_data mio_alpha_test = {
466         .eir_data = mio_alpha_data,
467         .eir_size = sizeof(mio_alpha_data),
468         .flags = 0x06,
469         .name = "ALPHA",
470         .name_complete = true,
471         .tx_power = 127,
472         .uuid = mio_alpha_uuid,
473 };
474
475 static const unsigned char cookoo_data[] = {
476                 0x02, 0x01, 0x05, 0x05, 0x02, 0x02, 0x18, 0x0a,
477                 0x18, 0x0d, 0x09, 0x43, 0x4f, 0x4f, 0x4b, 0x4f,
478                 0x4f, 0x20, 0x77, 0x61, 0x74, 0x63, 0x68,
479 };
480
481 static const char *cookoo_uuid[] = {
482                 "00001802-0000-1000-8000-00805f9b34fb",
483                 "0000180a-0000-1000-8000-00805f9b34fb",
484                 NULL
485 };
486
487 static const struct test_data cookoo_test = {
488         .eir_data = cookoo_data,
489         .eir_size = sizeof(cookoo_data),
490         .flags = 0x05,
491         .name = "COOKOO watch",
492         .name_complete = true,
493         .tx_power = 127,
494         .uuid = cookoo_uuid,
495 };
496
497 static const unsigned char citizen_adv_data[] = {
498                 0x02, 0x01, 0x05, 0x05, 0x12, 0x7f, 0x01, 0x8f,
499                 0x01, 0x14, 0x09, 0x45, 0x63, 0x6f, 0x2d, 0x44,
500                 0x72, 0x69, 0x76, 0x65, 0x20, 0x50, 0x72, 0x6f,
501                 0x78, 0x69, 0x6d, 0x69, 0x74, 0x79,
502 };
503
504 static const struct test_data citizen_adv_test = {
505         .eir_data = citizen_adv_data,
506         .eir_size = sizeof(citizen_adv_data),
507         .flags = 0x05,
508         .name = "Eco-Drive Proximity",
509         .name_complete = true,
510         .tx_power = 127,
511 };
512
513 static const unsigned char citizen_scan_data[] = {
514                 0x02, 0x0a, 0x00, 0x11, 0x07, 0x1b, 0xc5, 0xd5,
515                 0xa5, 0x02, 0x00, 0x46, 0x9a, 0xe1, 0x11, 0xb7,
516                 0x8d, 0x60, 0xb4, 0x45, 0x2d,
517 };
518
519 static const char *citizen_scan_uuid[] = {
520                 "2d45b460-8db7-11e1-9a46-0002a5d5c51b",
521                 NULL
522 };
523
524 static const struct test_data citizen_scan_test = {
525         .eir_data = citizen_scan_data,
526         .eir_size = sizeof(citizen_scan_data),
527         .tx_power = 0,
528         .uuid = citizen_scan_uuid,
529 };
530
531 static void test_basic(const void *data)
532 {
533         struct eir_data eir;
534         unsigned char buf[HCI_MAX_EIR_LENGTH];
535
536         memset(buf, 0, sizeof(buf));
537         memset(&eir, 0, sizeof(eir));
538
539         eir_parse(&eir, buf, HCI_MAX_EIR_LENGTH);
540         g_assert(eir.services == NULL);
541         g_assert(eir.name == NULL);
542
543         eir_data_free(&eir);
544
545         tester_test_passed();
546 }
547
548 static void print_debug(const char *str, void *user_data)
549 {
550         char *prefix = user_data;
551
552         tester_debug("%s%s", prefix, str);
553 }
554
555 static void test_parsing(gconstpointer data)
556 {
557         const struct test_data *test = data;
558         struct eir_data eir;
559         GSList *list;
560
561         memset(&eir, 0, sizeof(eir));
562
563         eir_parse(&eir, test->eir_data, test->eir_size);
564
565         tester_debug("Flags: %d", eir.flags);
566         tester_debug("Name: %s", eir.name);
567         tester_debug("TX power: %d", eir.tx_power);
568
569         for (list = eir.services; list; list = list->next) {
570                 char *uuid_str = list->data;
571
572                 tester_debug("UUID: %s", uuid_str);
573         }
574
575         g_assert_cmpint(eir.flags, ==, test->flags);
576
577         if (test->name) {
578                 g_assert_cmpstr(eir.name, ==, test->name);
579                 g_assert(eir.name_complete == test->name_complete);
580         } else {
581                 g_assert(eir.name == NULL);
582         }
583
584         g_assert(eir.tx_power == test->tx_power);
585
586         if (test->uuid) {
587                 GSList *list;
588                 int n = 0;
589
590                 for (list = eir.services; list; list = list->next, n++) {
591                         char *uuid_str = list->data;
592                         g_assert(test->uuid[n]);
593                         g_assert_cmpstr(test->uuid[n], ==, uuid_str);
594                 }
595         } else {
596                 g_assert(eir.services == NULL);
597         }
598
599         for (list = eir.msd_list; list; list = list->next) {
600                 struct eir_msd *msd = list->data;
601
602                 tester_debug("Manufacturer ID: 0x%04x", msd->company);
603                 util_hexdump(' ', msd->data, msd->data_len, print_debug,
604                                                         "Manufacturer Data:");
605         }
606
607         for (list = eir.sd_list; list; list = list->next) {
608                 struct eir_sd *sd = list->data;
609
610                 tester_debug("Service UUID: %s", sd->uuid);
611                 util_hexdump(' ', sd->data, sd->data_len, print_debug,
612                                                         "Service Data:");
613         }
614
615         eir_data_free(&eir);
616
617         tester_test_passed();
618 }
619
620 static const unsigned char gigaset_gtag_data[] = {
621                 0x02, 0x01, 0x06, 0x0d, 0xff, 0x80, 0x01, 0x02,
622                 0x15, 0x12, 0x34, 0x80, 0x91, 0xd0, 0xf2, 0xbb,
623                 0xc5, 0x03, 0x02, 0x0f, 0x18, 0x00, 0x00, 0x00,
624                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
625 };
626
627 static const char *gigaset_gtag_uuid[] = {
628                 "0000180f-0000-1000-8000-00805f9b34fb",
629                 NULL
630 };
631
632 static const struct test_data gigaset_gtag_test = {
633         .eir_data = gigaset_gtag_data,
634         .eir_size = sizeof(gigaset_gtag_data),
635         .flags = 0x06,
636         .tx_power = 127,
637         .uuid = gigaset_gtag_uuid,
638 };
639
640 static const char *uri_beacon_uuid[] = {
641                 "0000fed8-0000-1000-8000-00805f9b34fb",
642                 NULL
643 };
644
645 static const unsigned char uri_beacon_data[] = {
646                 0x03, 0x03, 0xd8, 0xfe, 0x0c, 0x16, 0xd8, 0xfe, 0x00,
647                 0x20, 0x00, 'b', 'l', 'u', 'e', 'z', 0x08
648 };
649
650 static const struct test_data uri_beacon_test = {
651         .eir_data = uri_beacon_data,
652         .eir_size = sizeof(uri_beacon_data),
653         .tx_power = 127,
654         .uuid = uri_beacon_uuid,
655 };
656
657 int main(int argc, char *argv[])
658 {
659         tester_init(&argc, &argv);
660
661         tester_add("/eir/basic", NULL, NULL, test_basic, NULL);
662
663         tester_add("/eir/macbookair", &macbookair_test, NULL, test_parsing,
664                                                                         NULL);
665         tester_add("/eir/iphone5", &iphone5_test, NULL, test_parsing, NULL);
666         tester_add("/eir/ipadmini", &ipadmini_test, NULL, test_parsing, NULL);
667         tester_add("/eir/sl400h", &gigaset_sl400h_test, NULL, test_parsing,
668                                                                         NULL);
669         tester_add("/eir/sl910", &gigaset_sl910_test, NULL, test_parsing, NULL);
670         tester_add("/eir/bh907", &nokia_bh907_test, NULL, test_parsing, NULL);
671         tester_add("/eir/fuelband", &fuelband_test, NULL, test_parsing, NULL);
672         tester_add("/ad/bluesc", &bluesc_test, NULL, test_parsing, NULL);
673         tester_add("/ad/wahooscale", &wahoo_scale_test, NULL, test_parsing,
674                                                                         NULL);
675         tester_add("/ad/mioalpha", &mio_alpha_test, NULL, test_parsing, NULL);
676         tester_add("/ad/cookoo", &cookoo_test, NULL, test_parsing, NULL);
677         tester_add("/ad/citizen1", &citizen_adv_test, NULL, test_parsing, NULL);
678         tester_add("/ad/citizen2", &citizen_scan_test, NULL, test_parsing,
679                                                                         NULL);
680         tester_add("ad/g-tag", &gigaset_gtag_test, NULL, test_parsing, NULL);
681         tester_add("ad/uri-beacon", &uri_beacon_test, NULL, test_parsing, NULL);
682
683         return tester_run();
684 }