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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
|
/*
* Copyright (C) 2014 Intel Corporation
*
* 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.
*
*/
#include <stdbool.h>
#include "emulator/bthost.h"
#include "tester-main.h"
#include "android/utils.h"
typedef enum {
HDP_APP_SINK_RELIABLE,
HDP_APP_SINK_STREAM,
HDP_APP_SOURCE_RELIABLE,
HDP_APP_SOURCE_STREAM,
} hdp_app_reg_type;
struct emu_cid_data {
uint16_t sdp_handle;
uint16_t sdp_cid;
uint16_t ctrl_handle;
uint16_t ctrl_cid;
uint16_t data_handle;
uint16_t data_cid;
};
struct emu_cid_data cid_data;
static struct queue *list; /* List of hdp test cases */
static bthl_reg_param_t *create_app(hdp_app_reg_type type)
{
bthl_reg_param_t *reg;
bthl_mdep_cfg_t mdep1, mdep2;
reg = malloc(sizeof(bthl_reg_param_t));
reg->application_name = "bluez-android";
reg->provider_name = "Bluez";
reg->srv_name = "bluez-hdp";
reg->srv_desp = "health-device-profile";
mdep1.data_type = 4100;
mdep1.mdep_description = "pulse-oximeter";
mdep2.data_type = 4100;
mdep2.mdep_description = "pulse-oximeter";
switch (type) {
case HDP_APP_SINK_RELIABLE:
reg->number_of_mdeps = 1;
mdep1.mdep_role = BTHL_MDEP_ROLE_SINK;
mdep1.channel_type = BTHL_CHANNEL_TYPE_RELIABLE;
reg->mdep_cfg = malloc(reg->number_of_mdeps *
sizeof(bthl_mdep_cfg_t));
reg->mdep_cfg[0] = mdep1;
break;
case HDP_APP_SINK_STREAM:
reg->number_of_mdeps = 2;
mdep1.mdep_role = BTHL_MDEP_ROLE_SINK;
mdep1.channel_type = BTHL_CHANNEL_TYPE_RELIABLE;
mdep2.mdep_role = BTHL_MDEP_ROLE_SINK;
mdep2.channel_type = BTHL_CHANNEL_TYPE_STREAMING;
reg->mdep_cfg = malloc(reg->number_of_mdeps *
sizeof(bthl_mdep_cfg_t));
reg->mdep_cfg[0] = mdep1;
reg->mdep_cfg[1] = mdep2;
break;
case HDP_APP_SOURCE_RELIABLE:
reg->number_of_mdeps = 1;
mdep1.mdep_role = BTHL_MDEP_ROLE_SOURCE;
mdep1.channel_type = BTHL_CHANNEL_TYPE_RELIABLE;
reg->mdep_cfg = malloc(reg->number_of_mdeps *
sizeof(bthl_mdep_cfg_t));
reg->mdep_cfg[0] = mdep1;
break;
case HDP_APP_SOURCE_STREAM:
reg->number_of_mdeps = 2;
mdep1.mdep_role = BTHL_MDEP_ROLE_SOURCE;
mdep1.channel_type = BTHL_CHANNEL_TYPE_RELIABLE;
mdep2.mdep_role = BTHL_MDEP_ROLE_SOURCE;
mdep2.channel_type = BTHL_CHANNEL_TYPE_STREAMING;
reg->mdep_cfg = malloc(reg->number_of_mdeps *
sizeof(bthl_mdep_cfg_t));
reg->mdep_cfg[0] = mdep1;
reg->mdep_cfg[1] = mdep2;
break;
}
return reg;
}
static void hdp_register_sink_reliable_app_action(void)
{
struct test_data *data = tester_get_data();
struct step *step = g_new0(struct step, 1);
int app_id = 0;
bthl_reg_param_t *reg;
reg = create_app(HDP_APP_SINK_RELIABLE);
step->action_status = data->if_hdp->register_application(reg, &app_id);
schedule_action_verification(step);
free(reg->mdep_cfg);
free(reg);
}
static void hdp_register_sink_stream_app_action(void)
{
struct test_data *data = tester_get_data();
struct step *step = g_new0(struct step, 1);
int app_id = 0;
bthl_reg_param_t *reg;
reg = create_app(HDP_APP_SINK_STREAM);
step->action_status = data->if_hdp->register_application(reg, &app_id);
schedule_action_verification(step);
free(reg->mdep_cfg);
free(reg);
}
static void hdp_register_source_reliable_app_action(void)
{
struct test_data *data = tester_get_data();
struct step *step = g_new0(struct step, 1);
int app_id = 0;
bthl_reg_param_t *reg;
reg = create_app(HDP_APP_SOURCE_RELIABLE);
step->action_status = data->if_hdp->register_application(reg, &app_id);
schedule_action_verification(step);
free(reg->mdep_cfg);
free(reg);
}
static void hdp_register_source_stream_app_action(void)
{
struct test_data *data = tester_get_data();
struct step *step = g_new0(struct step, 1);
int app_id = 0;
bthl_reg_param_t *reg;
reg = create_app(HDP_APP_SOURCE_STREAM);
step->action_status = data->if_hdp->register_application(reg, &app_id);
schedule_action_verification(step);
free(reg->mdep_cfg);
free(reg);
}
static void hdp_unregister_app_action(void)
{
struct test_data *data = tester_get_data();
struct step *step = g_new0(struct step, 1);
step->action_status = data->if_hdp->unregister_application(1);
schedule_action_verification(step);
}
static uint8_t hdp_rsp_pdu[] = { 0x07, /* PDU id */
0x00, 0x00, /* Transaction id */
0x01, 0xc8, /* Response length */
0x01, 0xc5, /* Attributes length */
0x36, 0x01, 0xc2, 0x36, 0x01, 0xbf, 0x09, 0x00, 0x00,
0x0a, 0x00, 0x01, 0x00, 0x00, 0x09, 0x00, 0x01, 0x35,
0x03, 0x19, 0x14, 0x01, 0x09, 0x00, 0x04, 0x35, 0x10,
0x35, 0x06, 0x19, 0x01, 0x00, 0x09, 0x10, 0x01, 0x35,
0x06, 0x19, 0x00, 0x1e, 0x09, 0x01, 0x00, 0x09, 0x00,
0x09, 0x35, 0x08, 0x35, 0x06, 0x19, 0x14, 0x00, 0x09,
0x01, 0x01, 0x09, 0x00, 0x0d, 0x35, 0x0f, 0x35, 0x0d,
0x35, 0x06, 0x19, 0x01, 0x00, 0x09, 0x10, 0x03, 0x35,
0x03, 0x19, 0x00, 0x1f, 0x09, 0x01, 0x00, 0x25, 0x03,
0x48, 0x44, 0x50, 0x09, 0x01, 0x01, 0x25, 0x28, 0x43,
0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x2c, 0x20, 0x64,
0x69, 0x73, 0x70, 0x6c, 0x61, 0x79, 0x2c, 0x20, 0x61,
0x6e, 0x64, 0x20, 0x72, 0x65, 0x8b, 0x6c, 0x61, 0x79,
0x20, 0x68, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x20, 0x64,
0x61, 0x74, 0x61, 0x09, 0x01, 0x02, 0x25, 0x0d, 0x42,
0x4c, 0x55, 0x45, 0x54, 0x4f, 0x4f, 0x54, 0x48, 0x20,
0x53, 0x49, 0x47, 0x09, 0x02, 0x00, 0x36, 0x01, 0x22,
0x35, 0x18, 0x08, 0x01, 0x09, 0x10, 0x04, 0x08, 0x00,
0x25, 0x0f, 0x50, 0x75, 0x6c, 0x73, 0x65, 0x20, 0x4f,
0x78, 0x69, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x0d, 0x35,
0x20, 0x08, 0x02, 0x09, 0x10, 0x07, 0x08, 0x00, 0x25,
0x17, 0x42, 0x6c, 0x6f, 0x6f, 0x64, 0x20, 0x50, 0x72,
0x65, 0x73, 0x73, 0x75, 0x72, 0x65, 0x20, 0x4d, 0x6f,
0x6e, 0x69, 0x74, 0x6f, 0x72, 0x0d, 0x35, 0x1a, 0x08,
0x03, 0x09, 0x10, 0x08, 0x08, 0x00, 0x25, 0x11, 0x42,
0x6f, 0x64, 0x79, 0x20, 0x54, 0x68, 0x65, 0x72, 0x6d,
0x6f, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x0d, 0x35, 0x1e,
0x08, 0x04, 0x09, 0x10, 0x0f, 0x08, 0x00, 0x25, 0x15,
0x42, 0x6f, 0x64, 0x79, 0x20, 0x57, 0x65, 0x69, 0x67,
0x68, 0x74, 0x20, 0x53, 0x63, 0x61, 0x6c, 0x65, 0x09,
0x09, 0x09, 0x0d, 0x35, 0x17, 0x08, 0x05, 0x09, 0x10,
0x11, 0x08, 0x00, 0x25, 0x0e, 0x47, 0x6c, 0x75, 0x63,
0x6f, 0x73, 0x65, 0x20, 0x4d, 0x65, 0x74, 0x65, 0x72,
0x0d, 0x35, 0x18, 0x08, 0x06, 0x09, 0x10, 0x04, 0x08,
0x01, 0x25, 0x0f, 0x50, 0x75, 0x6c, 0x73, 0x65, 0x20,
0x4f, 0x78, 0x69, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x0d,
0x35, 0x20, 0x08, 0x07, 0x09, 0x10, 0x07, 0x08, 0x01,
0x25, 0x17, 0x42, 0x6c, 0x6f, 0x6f, 0x64, 0x20, 0x50,
0x72, 0x65, 0x73, 0x73, 0x75, 0x72, 0x65, 0x20, 0x4d,
0x6f, 0x6e, 0x69, 0x74, 0x6f, 0x72, 0x0d, 0x35, 0x1a,
0x08, 0x08, 0x09, 0x10, 0x08, 0x08, 0x01, 0x25, 0x11,
0x42, 0x6f, 0x64, 0x79, 0x20, 0x54, 0x68, 0x65, 0x72,
0x6d, 0x6f, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x0d, 0x35,
0x1e, 0x08, 0x09, 0x09, 0x10, 0x0f, 0x08, 0x01, 0x25,
0x15, 0x42, 0x6f, 0x64, 0x79, 0x20, 0x57, 0x65, 0x69,
0x67, 0x68, 0x74, 0x20, 0x53, 0x63, 0x61, 0x6c, 0x65,
0x09, 0x09, 0x09, 0x0d, 0x35, 0x17, 0x08, 0x0a, 0x09,
0x10, 0x11, 0x08, 0x01, 0x25, 0x0e, 0x47, 0x6c, 0x75,
0x63, 0x6f, 0x73, 0x65, 0x20, 0x4d, 0x65, 0x74, 0x65,
0x72, 0x0d, 0x09, 0x03, 0x01, 0x08, 0x01, 0x09, 0x03,
0x02, 0x08, 0x00,
0x00 };
static void hdp_sdp_cid_hook_cb(const void *data, uint16_t len, void *user_data)
{
struct test_data *t_data = tester_get_data();
struct bthost *bthost = hciemu_client_get_host(t_data->hciemu);
struct emu_cid_data *cid_data = user_data;
hdp_rsp_pdu[1] = ((uint8_t *) data)[1];
hdp_rsp_pdu[2] = ((uint8_t *) data)[2];
bthost_send_cid(bthost, cid_data->sdp_handle, cid_data->sdp_cid,
hdp_rsp_pdu, sizeof(hdp_rsp_pdu));
}
static void hdp_sdp_search_cb(uint16_t handle, uint16_t cid, void *user_data)
{
struct test_data *data = tester_get_data();
struct bthost *bthost = hciemu_client_get_host(data->hciemu);
cid_data.sdp_handle = handle;
cid_data.sdp_cid = cid;
bthost_add_cid_hook(bthost, handle, cid, hdp_sdp_cid_hook_cb,
&cid_data);
}
static void mcap_ctrl_cid_hook_cb(const void *data, uint16_t len,
void *user_data)
{
struct test_data *t_data = tester_get_data();
struct bthost *bthost = hciemu_client_get_host(t_data->hciemu);
uint8_t crt_rsp[5], del_rsp[4], config;
uint8_t opcode = ((uint8_t *) data)[0];
static bool reliable = false;
switch (opcode) {
case 0x01: /* MD_CREATE_MDL_REQ */
crt_rsp[0] = 0x02; /* MD_CREATE_MDL_RSP */
crt_rsp[1] = 0x00; /* Response code - Success */
crt_rsp[2] = ((uint8_t *) data)[1]; /* mdlid */
crt_rsp[3] = ((uint8_t *) data)[2];
config = ((uint8_t *) data)[4];
if (config == 0x00) {
if (!reliable) {
crt_rsp[4] = 0x01;
reliable = true;
} else {
crt_rsp[4] = 0x02;
reliable = false;
}
} else {
crt_rsp[4] = config;
}
bthost_send_cid(bthost, cid_data.ctrl_handle,
cid_data.ctrl_cid,
crt_rsp, sizeof(crt_rsp));
break;
case 0x03: /* MD_RECONNECT_MDL_REQ */
case 0x05: /* MD_ABORT_MDL_REQ */
break;
case 0x07: /* MD_DELETE_MDL_REQ */
del_rsp[0] = 0x08; /* MD_DELETE_MDL_RSP */
del_rsp[1] = 0x00; /* Response code - Success */
del_rsp[2] = ((uint8_t *) data)[1]; /* mdlid */
del_rsp[3] = ((uint8_t *) data)[2];
bthost_send_cid(bthost, cid_data.ctrl_handle,
cid_data.ctrl_cid,
del_rsp, sizeof(del_rsp));
break;
}
}
static void mcap_ctrl_connect_cb(uint16_t handle, uint16_t cid, void *user_data)
{
struct test_data *data = tester_get_data();
struct bthost *bthost = hciemu_client_get_host(data->hciemu);
cid_data.ctrl_handle = handle;
cid_data.ctrl_cid = cid;
bthost_add_cid_hook(bthost, handle, cid, mcap_ctrl_cid_hook_cb,
&cid_data);
}
static void mcap_data_cid_hook_cb(const void *data, uint16_t len,
void *user_data)
{
}
static void mcap_data_connect_cb(uint16_t handle, uint16_t cid, void *user_data)
{
struct test_data *data = tester_get_data();
struct bthost *bthost = hciemu_client_get_host(data->hciemu);
cid_data.data_handle = handle;
cid_data.data_cid = cid;
bthost_add_cid_hook(bthost, handle, cid, mcap_data_cid_hook_cb,
&cid_data);
}
/* Emulate SDP (PSM = 1) */
static struct emu_set_l2cap_data l2cap_setup_sdp_data = {
.psm = 1,
.func = hdp_sdp_search_cb,
.user_data = NULL,
};
/* Emulate Control Channel (PSM = 0x1001) */
static struct emu_set_l2cap_data l2cap_setup_cc_data = {
.psm = 0x1001,
.func = mcap_ctrl_connect_cb,
.user_data = NULL,
};
/* Emulate Data Channel (PSM = 0x1003) */
static struct emu_set_l2cap_data l2cap_setup_dc_data = {
.psm = 0x1003,
.func = mcap_data_connect_cb,
.user_data = NULL,
};
static void hdp_connect_source_reliable_action(void)
{
struct test_data *data = tester_get_data();
const uint8_t *hid_addr = hciemu_get_client_bdaddr(data->hciemu);
struct step *step = g_new0(struct step, 1);
bt_bdaddr_t bdaddr;
int app_id, channel_id, mdep_cfg_index;
bdaddr2android((const bdaddr_t *) hid_addr, &bdaddr);
app_id = 1;
mdep_cfg_index = 0;
channel_id = 0;
step->action_status = data->if_hdp->connect_channel(app_id, &bdaddr,
mdep_cfg_index, &channel_id);
schedule_action_verification(step);
}
static struct test_case test_cases[] = {
TEST_CASE_BREDRLE("HDP Init",
ACTION_SUCCESS(dummy_action, NULL),
),
TEST_CASE_BREDRLE("HDP Register Sink Reliable Application",
ACTION_SUCCESS(hdp_register_sink_reliable_app_action, NULL),
CALLBACK_HDP_APP_REG_STATE(CB_HDP_APP_REG_STATE, 1,
BTHL_APP_REG_STATE_REG_SUCCESS),
),
TEST_CASE_BREDRLE("HDP Register Sink Stream Application",
ACTION_SUCCESS(hdp_register_sink_stream_app_action, NULL),
CALLBACK_HDP_APP_REG_STATE(CB_HDP_APP_REG_STATE, 1,
BTHL_APP_REG_STATE_REG_SUCCESS),
),
TEST_CASE_BREDRLE("HDP Register Source Reliable Application",
ACTION_SUCCESS(hdp_register_source_reliable_app_action, NULL),
CALLBACK_HDP_APP_REG_STATE(CB_HDP_APP_REG_STATE, 1,
BTHL_APP_REG_STATE_REG_SUCCESS),
),
TEST_CASE_BREDRLE("HDP Register Source Stream Application",
ACTION_SUCCESS(hdp_register_source_stream_app_action, NULL),
CALLBACK_HDP_APP_REG_STATE(CB_HDP_APP_REG_STATE, 1,
BTHL_APP_REG_STATE_REG_SUCCESS),
),
TEST_CASE_BREDRLE("HDP Unegister Application",
ACTION_SUCCESS(hdp_register_source_stream_app_action, NULL),
CALLBACK_HDP_APP_REG_STATE(CB_HDP_APP_REG_STATE, 1,
BTHL_APP_REG_STATE_REG_SUCCESS),
ACTION_SUCCESS(hdp_unregister_app_action, NULL),
CALLBACK_HDP_APP_REG_STATE(CB_HDP_APP_REG_STATE, 1,
BTHL_APP_REG_STATE_DEREG_SUCCESS),
),
TEST_CASE_BREDRLE("HDP Connect Source Reliable Channel",
ACTION_SUCCESS(bluetooth_enable_action, NULL),
CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_ON),
ACTION_SUCCESS(emu_setup_powered_remote_action, NULL),
ACTION_SUCCESS(emu_set_ssp_mode_action, NULL),
ACTION_SUCCESS(emu_add_l2cap_server_action,
&l2cap_setup_sdp_data),
ACTION_SUCCESS(emu_add_l2cap_server_action,
&l2cap_setup_cc_data),
ACTION_SUCCESS(emu_add_l2cap_server_action,
&l2cap_setup_dc_data),
ACTION_SUCCESS(hdp_register_source_reliable_app_action, NULL),
CALLBACK_HDP_APP_REG_STATE(CB_HDP_APP_REG_STATE, 1,
BTHL_APP_REG_STATE_REG_SUCCESS),
ACTION_SUCCESS(hdp_connect_source_reliable_action, NULL),
CALLBACK_HDP_CHANNEL_STATE(CB_HDP_CHANNEL_STATE, 1, 1, 0,
BTHL_CONN_STATE_CONNECTING),
CALLBACK_HDP_CHANNEL_STATE(CB_HDP_CHANNEL_STATE, 1, 1, 0,
BTHL_CONN_STATE_CONNECTED),
),
};
struct queue *get_hdp_tests(void)
{
uint16_t i = 0;
list = queue_new();
for (; i < sizeof(test_cases) / sizeof(test_cases[0]); ++i)
if (!queue_push_tail(list, &test_cases[i]))
return NULL;
return list;
}
void remove_hdp_tests(void)
{
queue_destroy(list, NULL);
}
|