tester-hdp.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. // SPDX-License-Identifier: Apache-2.0
  2. /*
  3. * Copyright (C) 2014 Intel Corporation
  4. *
  5. */
  6. #define _GNU_SOURCE
  7. #include <stdlib.h>
  8. #include <stdbool.h>
  9. #include "emulator/bthost.h"
  10. #include "lib/bluetooth.h"
  11. #include "android/utils.h"
  12. #include "src/shared/tester.h"
  13. #include "src/shared/queue.h"
  14. #include "tester-main.h"
  15. typedef enum {
  16. HDP_APP_SINK_RELIABLE,
  17. HDP_APP_SINK_STREAM,
  18. HDP_APP_SOURCE_RELIABLE,
  19. HDP_APP_SOURCE_STREAM,
  20. } hdp_app_reg_type;
  21. #define hdp_rsp_pdu 0x07, \
  22. 0x00, 0x00, \
  23. 0x01, 0xc8, \
  24. 0x01, 0xc5, \
  25. 0x36, 0x01, 0xc2, 0x36, 0x01, 0xbf, 0x09, 0x00, 0x00, \
  26. 0x0a, 0x00, 0x01, 0x00, 0x00, 0x09, 0x00, 0x01, 0x35, \
  27. 0x03, 0x19, 0x14, 0x01, 0x09, 0x00, 0x04, 0x35, 0x10, \
  28. 0x35, 0x06, 0x19, 0x01, 0x00, 0x09, 0x10, 0x01, 0x35, \
  29. 0x06, 0x19, 0x00, 0x1e, 0x09, 0x01, 0x00, 0x09, 0x00, \
  30. 0x09, 0x35, 0x08, 0x35, 0x06, 0x19, 0x14, 0x00, 0x09, \
  31. 0x01, 0x01, 0x09, 0x00, 0x0d, 0x35, 0x0f, 0x35, 0x0d, \
  32. 0x35, 0x06, 0x19, 0x01, 0x00, 0x09, 0x10, 0x03, 0x35, \
  33. 0x03, 0x19, 0x00, 0x1f, 0x09, 0x01, 0x00, 0x25, 0x03, \
  34. 0x48, 0x44, 0x50, 0x09, 0x01, 0x01, 0x25, 0x28, 0x43, \
  35. 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x2c, 0x20, 0x64, \
  36. 0x69, 0x73, 0x70, 0x6c, 0x61, 0x79, 0x2c, 0x20, 0x61, \
  37. 0x6e, 0x64, 0x20, 0x72, 0x65, 0x8b, 0x6c, 0x61, 0x79, \
  38. 0x20, 0x68, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x20, 0x64, \
  39. 0x61, 0x74, 0x61, 0x09, 0x01, 0x02, 0x25, 0x0d, 0x42, \
  40. 0x4c, 0x55, 0x45, 0x54, 0x4f, 0x4f, 0x54, 0x48, 0x20, \
  41. 0x53, 0x49, 0x47, 0x09, 0x02, 0x00, 0x36, 0x01, 0x22, \
  42. 0x35, 0x18, 0x08, 0x01, 0x09, 0x10, 0x04, 0x08, 0x00, \
  43. 0x25, 0x0f, 0x50, 0x75, 0x6c, 0x73, 0x65, 0x20, 0x4f, \
  44. 0x78, 0x69, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x0d, 0x35, \
  45. 0x20, 0x08, 0x02, 0x09, 0x10, 0x07, 0x08, 0x00, 0x25, \
  46. 0x17, 0x42, 0x6c, 0x6f, 0x6f, 0x64, 0x20, 0x50, 0x72, \
  47. 0x65, 0x73, 0x73, 0x75, 0x72, 0x65, 0x20, 0x4d, 0x6f, \
  48. 0x6e, 0x69, 0x74, 0x6f, 0x72, 0x0d, 0x35, 0x1a, 0x08, \
  49. 0x03, 0x09, 0x10, 0x08, 0x08, 0x00, 0x25, 0x11, 0x42, \
  50. 0x6f, 0x64, 0x79, 0x20, 0x54, 0x68, 0x65, 0x72, 0x6d, \
  51. 0x6f, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x0d, 0x35, 0x1e, \
  52. 0x08, 0x04, 0x09, 0x10, 0x0f, 0x08, 0x00, 0x25, 0x15, \
  53. 0x42, 0x6f, 0x64, 0x79, 0x20, 0x57, 0x65, 0x69, 0x67, \
  54. 0x68, 0x74, 0x20, 0x53, 0x63, 0x61, 0x6c, 0x65, 0x09, \
  55. 0x09, 0x09, 0x0d, 0x35, 0x17, 0x08, 0x05, 0x09, 0x10, \
  56. 0x11, 0x08, 0x00, 0x25, 0x0e, 0x47, 0x6c, 0x75, 0x63, \
  57. 0x6f, 0x73, 0x65, 0x20, 0x4d, 0x65, 0x74, 0x65, 0x72, \
  58. 0x0d, 0x35, 0x18, 0x08, 0x06, 0x09, 0x10, 0x04, 0x08, \
  59. 0x01, 0x25, 0x0f, 0x50, 0x75, 0x6c, 0x73, 0x65, 0x20, \
  60. 0x4f, 0x78, 0x69, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x0d, \
  61. 0x35, 0x20, 0x08, 0x07, 0x09, 0x10, 0x07, 0x08, 0x01, \
  62. 0x25, 0x17, 0x42, 0x6c, 0x6f, 0x6f, 0x64, 0x20, 0x50, \
  63. 0x72, 0x65, 0x73, 0x73, 0x75, 0x72, 0x65, 0x20, 0x4d, \
  64. 0x6f, 0x6e, 0x69, 0x74, 0x6f, 0x72, 0x0d, 0x35, 0x1a, \
  65. 0x08, 0x08, 0x09, 0x10, 0x08, 0x08, 0x01, 0x25, 0x11, \
  66. 0x42, 0x6f, 0x64, 0x79, 0x20, 0x54, 0x68, 0x65, 0x72, \
  67. 0x6d, 0x6f, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x0d, 0x35, \
  68. 0x1e, 0x08, 0x09, 0x09, 0x10, 0x0f, 0x08, 0x01, 0x25, \
  69. 0x15, 0x42, 0x6f, 0x64, 0x79, 0x20, 0x57, 0x65, 0x69, \
  70. 0x67, 0x68, 0x74, 0x20, 0x53, 0x63, 0x61, 0x6c, 0x65, \
  71. 0x09, 0x09, 0x09, 0x0d, 0x35, 0x17, 0x08, 0x0a, 0x09, \
  72. 0x10, 0x11, 0x08, 0x01, 0x25, 0x0e, 0x47, 0x6c, 0x75, \
  73. 0x63, 0x6f, 0x73, 0x65, 0x20, 0x4d, 0x65, 0x74, 0x65, \
  74. 0x72, 0x0d, 0x09, 0x03, 0x01, 0x08, 0x01, 0x09, 0x03, \
  75. 0x02, 0x08, 0x00, \
  76. 0x00
  77. static const struct pdu_set sdp_pdus[] = {
  78. { end_pdu, raw_pdu(hdp_rsp_pdu) },
  79. { end_pdu, end_pdu },
  80. };
  81. static struct emu_l2cap_cid_data sdp_cid_data = {
  82. .pdu = sdp_pdus,
  83. .is_sdp = TRUE,
  84. };
  85. static struct emu_l2cap_cid_data ctrl_cid_data;
  86. static struct emu_l2cap_cid_data data_cid_data;
  87. static struct queue *list; /* List of hdp test cases */
  88. static bthl_reg_param_t *create_app(hdp_app_reg_type type)
  89. {
  90. bthl_reg_param_t *reg;
  91. bthl_mdep_cfg_t mdep1, mdep2;
  92. reg = malloc(sizeof(bthl_reg_param_t));
  93. reg->application_name = "bluez-android";
  94. reg->provider_name = "Bluez";
  95. reg->srv_name = "bluez-hdp";
  96. reg->srv_desp = "health-device-profile";
  97. mdep1.data_type = 4100;
  98. mdep1.mdep_description = "pulse-oximeter";
  99. mdep2.data_type = 4100;
  100. mdep2.mdep_description = "pulse-oximeter";
  101. switch (type) {
  102. case HDP_APP_SINK_RELIABLE:
  103. reg->number_of_mdeps = 1;
  104. mdep1.mdep_role = BTHL_MDEP_ROLE_SINK;
  105. mdep1.channel_type = BTHL_CHANNEL_TYPE_RELIABLE;
  106. reg->mdep_cfg = malloc(reg->number_of_mdeps *
  107. sizeof(bthl_mdep_cfg_t));
  108. reg->mdep_cfg[0] = mdep1;
  109. break;
  110. case HDP_APP_SINK_STREAM:
  111. reg->number_of_mdeps = 2;
  112. mdep1.mdep_role = BTHL_MDEP_ROLE_SINK;
  113. mdep1.channel_type = BTHL_CHANNEL_TYPE_RELIABLE;
  114. mdep2.mdep_role = BTHL_MDEP_ROLE_SINK;
  115. mdep2.channel_type = BTHL_CHANNEL_TYPE_STREAMING;
  116. reg->mdep_cfg = malloc(reg->number_of_mdeps *
  117. sizeof(bthl_mdep_cfg_t));
  118. reg->mdep_cfg[0] = mdep1;
  119. reg->mdep_cfg[1] = mdep2;
  120. break;
  121. case HDP_APP_SOURCE_RELIABLE:
  122. reg->number_of_mdeps = 1;
  123. mdep1.mdep_role = BTHL_MDEP_ROLE_SOURCE;
  124. mdep1.channel_type = BTHL_CHANNEL_TYPE_RELIABLE;
  125. reg->mdep_cfg = malloc(reg->number_of_mdeps *
  126. sizeof(bthl_mdep_cfg_t));
  127. reg->mdep_cfg[0] = mdep1;
  128. break;
  129. case HDP_APP_SOURCE_STREAM:
  130. reg->number_of_mdeps = 2;
  131. mdep1.mdep_role = BTHL_MDEP_ROLE_SOURCE;
  132. mdep1.channel_type = BTHL_CHANNEL_TYPE_RELIABLE;
  133. mdep2.mdep_role = BTHL_MDEP_ROLE_SOURCE;
  134. mdep2.channel_type = BTHL_CHANNEL_TYPE_STREAMING;
  135. reg->mdep_cfg = malloc(reg->number_of_mdeps *
  136. sizeof(bthl_mdep_cfg_t));
  137. reg->mdep_cfg[0] = mdep1;
  138. reg->mdep_cfg[1] = mdep2;
  139. break;
  140. }
  141. return reg;
  142. }
  143. static void hdp_register_sink_reliable_app_action(void)
  144. {
  145. struct test_data *data = tester_get_data();
  146. struct step *step = g_new0(struct step, 1);
  147. int app_id = 0;
  148. bthl_reg_param_t *reg;
  149. reg = create_app(HDP_APP_SINK_RELIABLE);
  150. step->action_status = data->if_hdp->register_application(reg, &app_id);
  151. schedule_action_verification(step);
  152. free(reg->mdep_cfg);
  153. free(reg);
  154. }
  155. static void hdp_register_sink_stream_app_action(void)
  156. {
  157. struct test_data *data = tester_get_data();
  158. struct step *step = g_new0(struct step, 1);
  159. int app_id = 0;
  160. bthl_reg_param_t *reg;
  161. reg = create_app(HDP_APP_SINK_STREAM);
  162. step->action_status = data->if_hdp->register_application(reg, &app_id);
  163. schedule_action_verification(step);
  164. free(reg->mdep_cfg);
  165. free(reg);
  166. }
  167. static void hdp_register_source_reliable_app_action(void)
  168. {
  169. struct test_data *data = tester_get_data();
  170. struct step *step = g_new0(struct step, 1);
  171. int app_id = 0;
  172. bthl_reg_param_t *reg;
  173. reg = create_app(HDP_APP_SOURCE_RELIABLE);
  174. step->action_status = data->if_hdp->register_application(reg, &app_id);
  175. schedule_action_verification(step);
  176. free(reg->mdep_cfg);
  177. free(reg);
  178. }
  179. static void hdp_register_source_stream_app_action(void)
  180. {
  181. struct test_data *data = tester_get_data();
  182. struct step *step = g_new0(struct step, 1);
  183. int app_id = 0;
  184. bthl_reg_param_t *reg;
  185. reg = create_app(HDP_APP_SOURCE_STREAM);
  186. step->action_status = data->if_hdp->register_application(reg, &app_id);
  187. schedule_action_verification(step);
  188. free(reg->mdep_cfg);
  189. free(reg);
  190. }
  191. static void hdp_unregister_app_action(void)
  192. {
  193. struct test_data *data = tester_get_data();
  194. struct step *step = g_new0(struct step, 1);
  195. step->action_status = data->if_hdp->unregister_application(1);
  196. schedule_action_verification(step);
  197. }
  198. static void mcap_ctrl_cid_hook_cb(const void *data, uint16_t len,
  199. void *user_data)
  200. {
  201. struct test_data *t_data = tester_get_data();
  202. struct bthost *bthost = hciemu_client_get_host(t_data->hciemu);
  203. struct emu_l2cap_cid_data *cid_data = user_data;
  204. uint8_t crt_rsp[5], del_rsp[4], config;
  205. uint8_t opcode = ((uint8_t *) data)[0];
  206. static bool reliable = false;
  207. switch (opcode) {
  208. case 0x01: /* MD_CREATE_MDL_REQ */
  209. crt_rsp[0] = 0x02; /* MD_CREATE_MDL_RSP */
  210. crt_rsp[1] = 0x00; /* Response code - Success */
  211. crt_rsp[2] = ((uint8_t *) data)[1]; /* mdlid */
  212. crt_rsp[3] = ((uint8_t *) data)[2];
  213. config = ((uint8_t *) data)[4];
  214. if (config == 0x00) {
  215. if (!reliable) {
  216. crt_rsp[4] = 0x01;
  217. reliable = true;
  218. } else {
  219. crt_rsp[4] = 0x02;
  220. reliable = false;
  221. }
  222. } else {
  223. crt_rsp[4] = config;
  224. }
  225. bthost_send_cid(bthost, cid_data->handle,
  226. cid_data->cid,
  227. crt_rsp, sizeof(crt_rsp));
  228. break;
  229. case 0x03: /* MD_RECONNECT_MDL_REQ */
  230. case 0x05: /* MD_ABORT_MDL_REQ */
  231. break;
  232. case 0x07: /* MD_DELETE_MDL_REQ */
  233. del_rsp[0] = 0x08; /* MD_DELETE_MDL_RSP */
  234. del_rsp[1] = 0x00; /* Response code - Success */
  235. del_rsp[2] = ((uint8_t *) data)[1]; /* mdlid */
  236. del_rsp[3] = ((uint8_t *) data)[2];
  237. bthost_send_cid(bthost, cid_data->handle,
  238. cid_data->cid,
  239. del_rsp, sizeof(del_rsp));
  240. break;
  241. }
  242. }
  243. static void mcap_ctrl_connect_cb(uint16_t handle, uint16_t cid, void *user_data)
  244. {
  245. struct test_data *data = tester_get_data();
  246. struct bthost *bthost = hciemu_client_get_host(data->hciemu);
  247. struct emu_l2cap_cid_data *cid_data = user_data;
  248. cid_data->handle = handle;
  249. cid_data->cid = cid;
  250. bthost_add_cid_hook(bthost, handle, cid, mcap_ctrl_cid_hook_cb,
  251. cid_data);
  252. }
  253. /* Emulate SDP (PSM = 1) */
  254. static struct emu_set_l2cap_data l2cap_setup_sdp_data = {
  255. .psm = 1,
  256. .func = tester_generic_connect_cb,
  257. .user_data = &sdp_cid_data,
  258. };
  259. /* Emulate Control Channel (PSM = 0x1001) */
  260. static struct emu_set_l2cap_data l2cap_setup_cc_data = {
  261. .psm = 0x1001,
  262. .func = mcap_ctrl_connect_cb,
  263. .user_data = &ctrl_cid_data,
  264. };
  265. /* Emulate Data Channel (PSM = 0x1003) */
  266. static struct emu_set_l2cap_data l2cap_setup_dc_data = {
  267. .psm = 0x1003,
  268. .func = tester_generic_connect_cb,
  269. .user_data = &data_cid_data,
  270. };
  271. static void hdp_connect_source_reliable_action(void)
  272. {
  273. struct test_data *data = tester_get_data();
  274. const uint8_t *hid_addr = hciemu_get_client_bdaddr(data->hciemu);
  275. struct step *step = g_new0(struct step, 1);
  276. bt_bdaddr_t bdaddr;
  277. int app_id, channel_id, mdep_cfg_index;
  278. bdaddr2android((const bdaddr_t *) hid_addr, &bdaddr);
  279. app_id = 1;
  280. mdep_cfg_index = 0;
  281. channel_id = 0;
  282. step->action_status = data->if_hdp->connect_channel(app_id, &bdaddr,
  283. mdep_cfg_index, &channel_id);
  284. schedule_action_verification(step);
  285. }
  286. static void hdp_destroy_source_reliable_action(void)
  287. {
  288. struct test_data *data = tester_get_data();
  289. struct step *step = g_new0(struct step, 1);
  290. step->action_status = data->if_hdp->destroy_channel(1);
  291. schedule_action_verification(step);
  292. }
  293. static void hdp_connect_sink_reliable_action(void)
  294. {
  295. struct test_data *data = tester_get_data();
  296. const uint8_t *hid_addr = hciemu_get_client_bdaddr(data->hciemu);
  297. struct step *step = g_new0(struct step, 1);
  298. bt_bdaddr_t bdaddr;
  299. int app_id, channel_id, mdep_cfg_index;
  300. bdaddr2android((const bdaddr_t *) hid_addr, &bdaddr);
  301. app_id = 1;
  302. mdep_cfg_index = 0;
  303. channel_id = 0;
  304. step->action_status = data->if_hdp->connect_channel(app_id, &bdaddr,
  305. mdep_cfg_index, &channel_id);
  306. schedule_action_verification(step);
  307. }
  308. static void hdp_connect_sink_stream_action(void)
  309. {
  310. struct test_data *data = tester_get_data();
  311. const uint8_t *hid_addr = hciemu_get_client_bdaddr(data->hciemu);
  312. struct step *step = g_new0(struct step, 1);
  313. bt_bdaddr_t bdaddr;
  314. int app_id, channel_id, mdep_cfg_index;
  315. bdaddr2android((const bdaddr_t *) hid_addr, &bdaddr);
  316. app_id = 1;
  317. mdep_cfg_index = 1;
  318. channel_id = 0;
  319. step->action_status = data->if_hdp->connect_channel(app_id, &bdaddr,
  320. mdep_cfg_index, &channel_id);
  321. schedule_action_verification(step);
  322. }
  323. static void hdp_destroy_sink_reliable_action(void)
  324. {
  325. struct test_data *data = tester_get_data();
  326. struct step *step = g_new0(struct step, 1);
  327. step->action_status = data->if_hdp->destroy_channel(1);
  328. schedule_action_verification(step);
  329. }
  330. static void hdp_destroy_sink_stream_action(void)
  331. {
  332. struct test_data *data = tester_get_data();
  333. struct step *step = g_new0(struct step, 1);
  334. step->action_status = data->if_hdp->destroy_channel(2);
  335. schedule_action_verification(step);
  336. }
  337. static struct test_case test_cases[] = {
  338. TEST_CASE_BREDRLE("HDP Init",
  339. ACTION_SUCCESS(dummy_action, NULL),
  340. ),
  341. TEST_CASE_BREDRLE("HDP Register Sink Reliable Application",
  342. ACTION_SUCCESS(hdp_register_sink_reliable_app_action, NULL),
  343. CALLBACK_HDP_APP_REG_STATE(CB_HDP_APP_REG_STATE, 1,
  344. BTHL_APP_REG_STATE_REG_SUCCESS),
  345. ),
  346. TEST_CASE_BREDRLE("HDP Register Sink Stream Application",
  347. ACTION_SUCCESS(hdp_register_sink_stream_app_action, NULL),
  348. CALLBACK_HDP_APP_REG_STATE(CB_HDP_APP_REG_STATE, 1,
  349. BTHL_APP_REG_STATE_REG_SUCCESS),
  350. ),
  351. TEST_CASE_BREDRLE("HDP Register Source Reliable Application",
  352. ACTION_SUCCESS(hdp_register_source_reliable_app_action, NULL),
  353. CALLBACK_HDP_APP_REG_STATE(CB_HDP_APP_REG_STATE, 1,
  354. BTHL_APP_REG_STATE_REG_SUCCESS),
  355. ),
  356. TEST_CASE_BREDRLE("HDP Register Source Stream Application",
  357. ACTION_SUCCESS(hdp_register_source_stream_app_action, NULL),
  358. CALLBACK_HDP_APP_REG_STATE(CB_HDP_APP_REG_STATE, 1,
  359. BTHL_APP_REG_STATE_REG_SUCCESS),
  360. ),
  361. TEST_CASE_BREDRLE("HDP Unegister Application",
  362. ACTION_SUCCESS(hdp_register_source_stream_app_action, NULL),
  363. CALLBACK_HDP_APP_REG_STATE(CB_HDP_APP_REG_STATE, 1,
  364. BTHL_APP_REG_STATE_REG_SUCCESS),
  365. ACTION_SUCCESS(hdp_unregister_app_action, NULL),
  366. CALLBACK_HDP_APP_REG_STATE(CB_HDP_APP_REG_STATE, 1,
  367. BTHL_APP_REG_STATE_DEREG_SUCCESS),
  368. ),
  369. TEST_CASE_BREDRLE("HDP Connect Source Reliable Channel",
  370. ACTION_SUCCESS(set_default_ssp_request_handler, NULL),
  371. ACTION_SUCCESS(bluetooth_enable_action, NULL),
  372. CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_ON),
  373. ACTION_SUCCESS(emu_setup_powered_remote_action, NULL),
  374. ACTION_SUCCESS(emu_set_ssp_mode_action, NULL),
  375. ACTION_SUCCESS(emu_add_l2cap_server_action,
  376. &l2cap_setup_sdp_data),
  377. ACTION_SUCCESS(emu_add_l2cap_server_action,
  378. &l2cap_setup_cc_data),
  379. ACTION_SUCCESS(emu_add_l2cap_server_action,
  380. &l2cap_setup_dc_data),
  381. ACTION_SUCCESS(hdp_register_source_reliable_app_action, NULL),
  382. CALLBACK_HDP_APP_REG_STATE(CB_HDP_APP_REG_STATE, 1,
  383. BTHL_APP_REG_STATE_REG_SUCCESS),
  384. ACTION_SUCCESS(hdp_connect_source_reliable_action, NULL),
  385. CALLBACK_HDP_CHANNEL_STATE(CB_HDP_CHANNEL_STATE, 1, 1, 0,
  386. BTHL_CONN_STATE_CONNECTING),
  387. CALLBACK_HDP_CHANNEL_STATE(CB_HDP_CHANNEL_STATE, 1, 1, 0,
  388. BTHL_CONN_STATE_CONNECTED),
  389. ),
  390. TEST_CASE_BREDRLE("HDP Destroy Source Reliable Channel",
  391. ACTION_SUCCESS(set_default_ssp_request_handler, NULL),
  392. ACTION_SUCCESS(bluetooth_enable_action, NULL),
  393. CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_ON),
  394. ACTION_SUCCESS(emu_setup_powered_remote_action, NULL),
  395. ACTION_SUCCESS(emu_set_ssp_mode_action, NULL),
  396. ACTION_SUCCESS(emu_add_l2cap_server_action,
  397. &l2cap_setup_sdp_data),
  398. ACTION_SUCCESS(emu_add_l2cap_server_action,
  399. &l2cap_setup_cc_data),
  400. ACTION_SUCCESS(emu_add_l2cap_server_action,
  401. &l2cap_setup_dc_data),
  402. ACTION_SUCCESS(hdp_register_source_reliable_app_action, NULL),
  403. CALLBACK_HDP_APP_REG_STATE(CB_HDP_APP_REG_STATE, 1,
  404. BTHL_APP_REG_STATE_REG_SUCCESS),
  405. ACTION_SUCCESS(hdp_connect_source_reliable_action, NULL),
  406. CALLBACK_HDP_CHANNEL_STATE(CB_HDP_CHANNEL_STATE, 1, 1, 0,
  407. BTHL_CONN_STATE_CONNECTING),
  408. CALLBACK_HDP_CHANNEL_STATE(CB_HDP_CHANNEL_STATE, 1, 1, 0,
  409. BTHL_CONN_STATE_CONNECTED),
  410. ACTION_SUCCESS(hdp_destroy_source_reliable_action, NULL),
  411. CALLBACK_HDP_CHANNEL_STATE(CB_HDP_CHANNEL_STATE, 1, 1, 0,
  412. BTHL_CONN_STATE_DESTROYED),
  413. ),
  414. TEST_CASE_BREDRLE("HDP Connect Sink Streaming Channel",
  415. ACTION_SUCCESS(set_default_ssp_request_handler, NULL),
  416. ACTION_SUCCESS(bluetooth_enable_action, NULL),
  417. CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_ON),
  418. ACTION_SUCCESS(emu_setup_powered_remote_action, NULL),
  419. ACTION_SUCCESS(emu_set_ssp_mode_action, NULL),
  420. ACTION_SUCCESS(emu_add_l2cap_server_action,
  421. &l2cap_setup_sdp_data),
  422. ACTION_SUCCESS(emu_add_l2cap_server_action,
  423. &l2cap_setup_cc_data),
  424. ACTION_SUCCESS(emu_add_l2cap_server_action,
  425. &l2cap_setup_dc_data),
  426. ACTION_SUCCESS(hdp_register_sink_stream_app_action, NULL),
  427. CALLBACK_HDP_APP_REG_STATE(CB_HDP_APP_REG_STATE, 1,
  428. BTHL_APP_REG_STATE_REG_SUCCESS),
  429. ACTION_SUCCESS(hdp_connect_sink_reliable_action, NULL),
  430. CALLBACK_HDP_CHANNEL_STATE(CB_HDP_CHANNEL_STATE, 1, 1, 0,
  431. BTHL_CONN_STATE_CONNECTING),
  432. CALLBACK_HDP_CHANNEL_STATE(CB_HDP_CHANNEL_STATE, 1, 1, 0,
  433. BTHL_CONN_STATE_CONNECTED),
  434. ACTION_SUCCESS(hdp_connect_sink_stream_action, NULL),
  435. CALLBACK_HDP_CHANNEL_STATE(CB_HDP_CHANNEL_STATE, 1, 2, 1,
  436. BTHL_CONN_STATE_CONNECTED),
  437. ),
  438. TEST_CASE_BREDRLE("HDP Destroy Sink Streaming Channel",
  439. ACTION_SUCCESS(set_default_ssp_request_handler, NULL),
  440. ACTION_SUCCESS(bluetooth_enable_action, NULL),
  441. CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_ON),
  442. ACTION_SUCCESS(emu_setup_powered_remote_action, NULL),
  443. ACTION_SUCCESS(emu_set_ssp_mode_action, NULL),
  444. ACTION_SUCCESS(emu_add_l2cap_server_action,
  445. &l2cap_setup_sdp_data),
  446. ACTION_SUCCESS(emu_add_l2cap_server_action,
  447. &l2cap_setup_cc_data),
  448. ACTION_SUCCESS(emu_add_l2cap_server_action,
  449. &l2cap_setup_dc_data),
  450. ACTION_SUCCESS(hdp_register_sink_stream_app_action, NULL),
  451. CALLBACK_HDP_APP_REG_STATE(CB_HDP_APP_REG_STATE, 1,
  452. BTHL_APP_REG_STATE_REG_SUCCESS),
  453. ACTION_SUCCESS(hdp_connect_sink_reliable_action, NULL),
  454. CALLBACK_HDP_CHANNEL_STATE(CB_HDP_CHANNEL_STATE, 1, 1, 0,
  455. BTHL_CONN_STATE_CONNECTING),
  456. CALLBACK_HDP_CHANNEL_STATE(CB_HDP_CHANNEL_STATE, 1, 1, 0,
  457. BTHL_CONN_STATE_CONNECTED),
  458. ACTION_SUCCESS(hdp_connect_sink_stream_action, NULL),
  459. CALLBACK_HDP_CHANNEL_STATE(CB_HDP_CHANNEL_STATE, 1, 2, 1,
  460. BTHL_CONN_STATE_CONNECTED),
  461. ACTION_SUCCESS(hdp_destroy_sink_reliable_action, NULL),
  462. CALLBACK_HDP_CHANNEL_STATE(CB_HDP_CHANNEL_STATE, 1, 1, 0,
  463. BTHL_CONN_STATE_DESTROYED),
  464. ACTION_SUCCESS(hdp_destroy_sink_stream_action, NULL),
  465. CALLBACK_HDP_CHANNEL_STATE(CB_HDP_CHANNEL_STATE, 1, 2, 1,
  466. BTHL_CONN_STATE_DESTROYED),
  467. ),
  468. };
  469. struct queue *get_hdp_tests(void)
  470. {
  471. uint16_t i = 0;
  472. list = queue_new();
  473. for (; i < sizeof(test_cases) / sizeof(test_cases[0]); ++i)
  474. queue_push_tail(list, &test_cases[i]);
  475. return list;
  476. }
  477. void remove_hdp_tests(void)
  478. {
  479. queue_destroy(list, NULL);
  480. }