tester-avrcp.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. // SPDX-License-Identifier: Apache-2.0
  2. /*
  3. * Copyright (C) 2014 Intel Corporation
  4. *
  5. */
  6. #define _GNU_SOURCE
  7. #include <stdbool.h>
  8. #include "emulator/bthost.h"
  9. #include "src/shared/util.h"
  10. #include "src/shared/tester.h"
  11. #include "src/shared/queue.h"
  12. #include "lib/bluetooth.h"
  13. #include "android/utils.h"
  14. #include "tester-main.h"
  15. static struct queue *list;
  16. #define AVRCP_GET_ELEMENT_ATTRIBUTES 0x20
  17. #define AVRCP_GET_PLAY_STATUS 0x30
  18. #define AVRCP_REGISTER_NOTIFICATION 0x31
  19. #define sdp_rsp_pdu 0x07, \
  20. 0x00, 0x00, \
  21. 0x00, 0x7f, \
  22. 0x00, 0x7c, \
  23. 0x36, 0x00, 0x79, 0x36, 0x00, 0x3b, 0x09, 0x00, 0x00, \
  24. 0x0a, 0x00, 0x01, 0x00, 0x04, 0x09, 0x00, 0x01, 0x35, \
  25. 0x06, 0x19, 0x11, 0x0e, 0x19, 0x11, 0x0f, 0x09, 0x00, \
  26. 0x04, 0x35, 0x10, 0x35, 0x06, 0x19, 0x01, 0x00, 0x09, \
  27. 0x00, 0x17, 0x35, 0x06, 0x19, 0x00, 0x17, 0x09, 0x01, \
  28. 0x03, 0x09, 0x00, 0x09, 0x35, 0x08, 0x35, 0x06, 0x19, \
  29. 0x11, 0x0e, 0x09, 0x01, 0x00, 0x09, 0x03, 0x11, 0x09, \
  30. 0x00, 0x01, 0x36, 0x00, 0x38, 0x09, 0x00, 0x00, 0x0a, \
  31. 0x00, 0x01, 0x00, 0x05, 0x09, 0x00, 0x01, 0x35, 0x03, \
  32. 0x19, 0x11, 0x0c, 0x09, 0x00, 0x04, 0x35, 0x10, 0x35, \
  33. 0x06, 0x19, 0x01, 0x00, 0x09, 0x00, 0x17, 0x35, 0x06, \
  34. 0x19, 0x00, 0x17, 0x09, 0x01, 0x03, 0x09, 0x00, 0x09, \
  35. 0x35, 0x08, 0x35, 0x06, 0x19, 0x11, 0x0e, 0x09, 0x01, \
  36. 0x04, 0x09, 0x03, 0x11, 0x09, 0x00, 0x02, \
  37. 0x00
  38. static const struct pdu_set sdp_pdus[] = {
  39. { end_pdu, raw_pdu(sdp_rsp_pdu) },
  40. { end_pdu, end_pdu },
  41. };
  42. static struct emu_l2cap_cid_data sdp_data = {
  43. .pdu = sdp_pdus,
  44. .is_sdp = TRUE,
  45. };
  46. #define req_dsc 0x00, 0x01
  47. #define rsp_dsc 0x02, 0x01, 0x04, 0x08
  48. #define req_get 0x10, 0x02, 0x04
  49. #define rsp_get 0x12, 0x02, 0x01, 0x00, 0x07, 0x06, 0x00, \
  50. 0x00, 0xff, 0xff, 0x02, 0x40
  51. #define req_cfg 0x20, 0x03, 0x04, 0x04, 0x01, 0x00, 0x07, \
  52. 0x06, 0x00, 0x00, 0x21, 0x15, 0x02, \
  53. 0x40
  54. #define rsp_cfg 0x22, 0x03
  55. #define req_open 0x30, 0x06, 0x04
  56. #define rsp_open 0x32, 0x06
  57. #define req_close 0x40, 0x08, 0x04
  58. #define rsp_close 0x42, 0x08
  59. #define req_start 0x40, 0x07, 0x04
  60. #define rsp_start 0x42, 0x07
  61. #define req_suspend 0x50, 0x09, 0x04
  62. #define rsp_suspend 0x52, 0x09
  63. #define req_play_status 0x00, 0x11, 0x0e, 0x01, 0x48, 0x00, 0x00, 0x19, 0x58, \
  64. 0x30, 0x00, 0x00, 0x00
  65. #define rsp_play_status 0x02, 0x11, 0x0e, 0x0c, 0x48, 0x00, 0x00, 0x19, 0x58, \
  66. 0x30, 0x00, 0x00, 0x09, 0xbb, 0xbb, 0xbb, 0xbb, 0xaa, \
  67. 0xaa, 0xaa, 0xaa, 0x00
  68. #define req_track_notif 0x00, 0x11, 0x0e, 0x03, 0x48, 0x00, 0x00, 0x19, 0x58, \
  69. 0x31, 0x00, 0x00, 0x05, 0x02, 0x00, 0x00, 0x00, 0x00
  70. #define rsp_track_notif 0x00, 0x11, 0x0e, 0x0F, 0x48, 0x00, 0x00, 0x19, 0x58, \
  71. 0x31, 0x00, 0x00, 0x09, 0x02, 0xFF, 0xFF, 0xFF, 0xFF, \
  72. 0xFF, 0xFF, 0xFF, 0xFF
  73. #define req_position_notif 0x00, 0x11, 0x0e, 0x03, 0x48, 0x00, 0x00, 0x19, \
  74. 0x58, 0x31, 0x00, 0x00, 0x05, 0x05, 0x00, \
  75. 0x00, 0x00, 0x00
  76. #define rsp_position_notif 0x00, 0x11, 0x0e, 0x0F, 0x48, 0x00, 0x00, 0x19, \
  77. 0x58, 0x31, 0x00, 0x00, 0x04, 0x05, 0xFF, \
  78. 0xFF, 0xFF, 0xFF
  79. #define req_status_notif 0x00, 0x11, 0x0e, 0x03, 0x48, 0x00, 0x00, 0x19, \
  80. 0x58, 0x31, 0x00, 0x00, 0x05, 0x01, 0x00, \
  81. 0x00, 0x00, 0x00
  82. #define rsp_status_notif 0x00, 0x11, 0x0e, 0x0D, 0x48, 0x00, 0x00, 0x19, \
  83. 0x58, 0x31, 0x00, 0x00, 0x01, 0x01, 0x00
  84. #define req_ele_attr 0x00, 0x11, 0x0e, 0x01, 0x48, 0x00, 0x00, 0x19, 0x58, \
  85. 0x20, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x00, 0x00, \
  86. 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x07
  87. #define rsp_ele_attr 0x02, 0x11, 0x0e, 0x0c, 0x48, 0x00, 0x00, 0x19, 0x58, \
  88. 0x20, 0x00, 0x00, 0x2a, 0x02, 0x00, 0x00, 0x00, 0x01, \
  89. 0x00, 0x6a, 0x00, 0x13, 0x47, 0x69, 0x76, 0x65, 0x20, \
  90. 0x50, 0x65, 0x61, 0x63, 0x65, 0x20, 0x61, 0x20, 0x43, \
  91. 0x68, 0x61, 0x6e, 0x63, 0x65, 0x00, 0x00, 0x00, 0x07, \
  92. 0x00, 0x6a, 0x00, 0x06, 0x31, 0x30, 0x33, 0x30, 0x30, \
  93. 0x30
  94. static const struct pdu_set pdus[] = {
  95. { raw_pdu(req_dsc), raw_pdu(rsp_dsc) },
  96. { raw_pdu(req_get), raw_pdu(rsp_get) },
  97. { raw_pdu(req_cfg), raw_pdu(rsp_cfg) },
  98. { raw_pdu(req_open), raw_pdu(rsp_open) },
  99. { raw_pdu(req_close), raw_pdu(rsp_close) },
  100. { raw_pdu(req_start), raw_pdu(rsp_start) },
  101. { raw_pdu(req_suspend), raw_pdu(rsp_suspend) },
  102. { end_pdu, end_pdu },
  103. };
  104. static struct emu_l2cap_cid_data a2dp_data = {
  105. .pdu = pdus,
  106. };
  107. static struct emu_l2cap_cid_data avrcp_data;
  108. static btrc_element_attr_val_t ele_attrs[2] = {
  109. {
  110. .attr_id = BTRC_MEDIA_ATTR_TITLE,
  111. .text = {0x47, 0x69, 0x76, 0x65, 0x20, 0x50, 0x65, 0x61, 0x63, 0x65,
  112. 0x20, 0x61, 0x20, 0x43, 0x68, 0x61, 0x6e, 0x63, 0x65}
  113. },
  114. {
  115. .attr_id = BTRC_MEDIA_ATTR_PLAYING_TIME,
  116. .text = {0x31, 0x30, 0x33, 0x30, 0x30, 0x30}
  117. }
  118. };
  119. static btrc_element_attr_val_t exp_attrs[2];
  120. static void print_avrcp(const char *str, void *user_data)
  121. {
  122. tester_debug("avrcp: %s", str);
  123. }
  124. static void avrcp_cid_hook_cb(const void *data, uint16_t len, void *user_data)
  125. {
  126. struct step *step;
  127. uint8_t pdu, event;
  128. util_hexdump('>', data, len, print_avrcp, NULL);
  129. pdu = ((uint8_t *) data)[9];
  130. switch (pdu) {
  131. case AVRCP_GET_PLAY_STATUS:
  132. step = g_new0(struct step, 1);
  133. step->callback = CB_AVRCP_PLAY_STATUS_RSP;
  134. step->callback_result.song_length = get_be32(data + 13);
  135. step->callback_result.song_position = get_be32(data + 17);
  136. step->callback_result.play_status = ((uint8_t *) data)[21];
  137. schedule_callback_verification(step);
  138. break;
  139. case AVRCP_REGISTER_NOTIFICATION:
  140. event = ((uint8_t *) data)[13];
  141. switch (event) {
  142. case 0x01:
  143. step = g_new0(struct step, 1);
  144. step->callback = CB_AVRCP_REG_NOTIF_RSP;
  145. step->callback_result.play_status =
  146. ((uint8_t *) data)[14];
  147. schedule_callback_verification(step);
  148. break;
  149. case 0x02:
  150. step = g_new0(struct step, 1);
  151. step->callback = CB_AVRCP_REG_NOTIF_RSP;
  152. step->callback_result.rc_index = get_be64(data + 14);
  153. schedule_callback_verification(step);
  154. break;
  155. case 0x05:
  156. step = g_new0(struct step, 1);
  157. step->callback = CB_AVRCP_REG_NOTIF_RSP;
  158. step->callback_result.song_position =
  159. get_be32(data + 14);
  160. schedule_callback_verification(step);
  161. break;
  162. }
  163. break;
  164. case AVRCP_GET_ELEMENT_ATTRIBUTES:
  165. step = g_new0(struct step, 1);
  166. step->callback = CB_AVRCP_GET_ATTR_RSP;
  167. step->callback_result.num_of_attrs = ((uint8_t *) data)[13];
  168. memset(exp_attrs, 0, 2 * sizeof(btrc_element_attr_val_t));
  169. exp_attrs[0].attr_id = get_be16(data + 16);
  170. memcpy(exp_attrs[0].text, data + 22, 19);
  171. exp_attrs[1].attr_id = get_be16(data + 43);
  172. memcpy(exp_attrs[1].text, data + 49, 6);
  173. step->callback_result.attrs = exp_attrs;
  174. schedule_callback_verification(step);
  175. break;
  176. }
  177. }
  178. static void avrcp_connect_request_cb(uint16_t handle, uint16_t cid,
  179. void *user_data)
  180. {
  181. struct test_data *data = tester_get_data();
  182. struct bthost *bthost = hciemu_client_get_host(data->hciemu);
  183. struct emu_l2cap_cid_data *cid_data = user_data;
  184. cid_data->handle = handle;
  185. cid_data->cid = cid;
  186. bthost_add_cid_hook(bthost, handle, cid, avrcp_cid_hook_cb, cid_data);
  187. }
  188. static struct emu_set_l2cap_data avrcp_setup_data = {
  189. .psm = 23,
  190. .func = avrcp_connect_request_cb,
  191. .user_data = &avrcp_data,
  192. };
  193. static void a2dp_connect_request_cb(uint16_t handle, uint16_t cid,
  194. void *user_data)
  195. {
  196. struct emu_l2cap_cid_data *cid_data = user_data;
  197. if (cid_data->handle)
  198. return;
  199. cid_data->handle = handle;
  200. cid_data->cid = cid;
  201. avrcp_data.handle = handle;
  202. avrcp_data.cid = cid;
  203. tester_handle_l2cap_data_exchange(cid_data);
  204. }
  205. static struct emu_set_l2cap_data a2dp_setup_data = {
  206. .psm = 25,
  207. .func = a2dp_connect_request_cb,
  208. .user_data = &a2dp_data,
  209. };
  210. static struct emu_set_l2cap_data sdp_setup_data = {
  211. .psm = 1,
  212. .func = tester_generic_connect_cb,
  213. .user_data = &sdp_data,
  214. };
  215. static void avrcp_connect_action(void)
  216. {
  217. struct test_data *data = tester_get_data();
  218. const uint8_t *addr = hciemu_get_client_bdaddr(data->hciemu);
  219. struct step *step = g_new0(struct step, 1);
  220. bt_bdaddr_t bdaddr;
  221. sdp_data.handle = 0;
  222. sdp_data.cid = 0;
  223. a2dp_data.handle = 0;
  224. a2dp_data.cid = 0;
  225. avrcp_data.handle = 0;
  226. avrcp_data.cid = 0;
  227. bdaddr2android((const bdaddr_t *) addr, &bdaddr);
  228. step->action_status = data->if_a2dp->connect(&bdaddr);
  229. schedule_action_verification(step);
  230. }
  231. static void avrcp_disconnect_action(void)
  232. {
  233. struct test_data *data = tester_get_data();
  234. const uint8_t *addr = hciemu_get_client_bdaddr(data->hciemu);
  235. struct step *step = g_new0(struct step, 1);
  236. bt_bdaddr_t bdaddr;
  237. bdaddr2android((const bdaddr_t *) addr, &bdaddr);
  238. step->action_status = data->if_a2dp->disconnect(&bdaddr);
  239. schedule_action_verification(step);
  240. }
  241. static void avrcp_get_play_status_req(void)
  242. {
  243. struct test_data *data = tester_get_data();
  244. struct bthost *bthost = hciemu_client_get_host(data->hciemu);
  245. const struct iovec pdu = raw_pdu(req_play_status);
  246. struct step *step = g_new0(struct step, 1);
  247. bthost_send_cid_v(bthost, avrcp_data.handle, avrcp_data.cid, &pdu, 1);
  248. step->action_status = BT_STATUS_SUCCESS;
  249. schedule_action_verification(step);
  250. }
  251. static void avrcp_get_play_status_rsp(void)
  252. {
  253. struct test_data *data = tester_get_data();
  254. struct step *step = g_new0(struct step, 1);
  255. step->action_status = data->if_avrcp->get_play_status_rsp(0x00,
  256. 0xbbbbbbbb, 0xaaaaaaaa);
  257. schedule_action_verification(step);
  258. }
  259. static void avrcp_reg_notif_track_changed_req(void)
  260. {
  261. struct test_data *data = tester_get_data();
  262. struct bthost *bthost = hciemu_client_get_host(data->hciemu);
  263. const struct iovec pdu = raw_pdu(req_track_notif);
  264. struct step *step = g_new0(struct step, 1);
  265. bthost_send_cid_v(bthost, avrcp_data.handle, avrcp_data.cid, &pdu, 1);
  266. step->action_status = BT_STATUS_SUCCESS;
  267. schedule_action_verification(step);
  268. }
  269. static void avrcp_reg_notif_track_changed_rsp(void)
  270. {
  271. struct test_data *data = tester_get_data();
  272. struct step *step = g_new0(struct step, 1);
  273. uint64_t track;
  274. btrc_register_notification_t reg;
  275. track = 0xffffffffffffffff;
  276. memcpy(reg.track, &track, sizeof(btrc_uid_t));
  277. step->action_status = data->if_avrcp->register_notification_rsp(
  278. BTRC_EVT_TRACK_CHANGE,
  279. BTRC_NOTIFICATION_TYPE_INTERIM, &reg);
  280. schedule_action_verification(step);
  281. }
  282. static void avrcp_reg_notif_play_position_changed_req(void)
  283. {
  284. struct test_data *data = tester_get_data();
  285. struct bthost *bthost = hciemu_client_get_host(data->hciemu);
  286. const struct iovec pdu = raw_pdu(req_position_notif);
  287. struct step *step = g_new0(struct step, 1);
  288. bthost_send_cid_v(bthost, avrcp_data.handle, avrcp_data.cid, &pdu, 1);
  289. step->action_status = BT_STATUS_SUCCESS;
  290. schedule_action_verification(step);
  291. }
  292. static void avrcp_reg_notif_play_position_changed_rsp(void)
  293. {
  294. struct test_data *data = tester_get_data();
  295. struct step *step = g_new0(struct step, 1);
  296. btrc_register_notification_t reg;
  297. reg.song_pos = 0xffffffff;
  298. step->action_status = data->if_avrcp->register_notification_rsp(
  299. BTRC_EVT_PLAY_POS_CHANGED,
  300. BTRC_NOTIFICATION_TYPE_INTERIM, &reg);
  301. schedule_action_verification(step);
  302. }
  303. static void avrcp_reg_notif_play_status_changed_req(void)
  304. {
  305. struct test_data *data = tester_get_data();
  306. struct bthost *bthost = hciemu_client_get_host(data->hciemu);
  307. const struct iovec pdu = raw_pdu(req_status_notif);
  308. struct step *step = g_new0(struct step, 1);
  309. bthost_send_cid_v(bthost, avrcp_data.handle, avrcp_data.cid, &pdu, 1);
  310. step->action_status = BT_STATUS_SUCCESS;
  311. schedule_action_verification(step);
  312. }
  313. static void avrcp_reg_notif_play_status_changed_rsp(void)
  314. {
  315. struct test_data *data = tester_get_data();
  316. struct step *step = g_new0(struct step, 1);
  317. btrc_register_notification_t reg;
  318. reg.play_status = BTRC_PLAYSTATE_STOPPED;
  319. step->action_status = data->if_avrcp->register_notification_rsp(
  320. BTRC_EVT_PLAY_STATUS_CHANGED,
  321. BTRC_NOTIFICATION_TYPE_CHANGED, &reg);
  322. schedule_action_verification(step);
  323. }
  324. static void avrcp_get_element_attributes_req(void)
  325. {
  326. struct test_data *data = tester_get_data();
  327. struct bthost *bthost = hciemu_client_get_host(data->hciemu);
  328. const struct iovec pdu = raw_pdu(req_ele_attr);
  329. struct step *step = g_new0(struct step, 1);
  330. bthost_send_cid_v(bthost, avrcp_data.handle, avrcp_data.cid, &pdu, 1);
  331. step->action_status = BT_STATUS_SUCCESS;
  332. schedule_action_verification(step);
  333. }
  334. static void avrcp_get_element_attributes_rsp(void)
  335. {
  336. struct test_data *data = tester_get_data();
  337. struct step *step = g_new0(struct step, 1);
  338. step->action_status = data->if_avrcp->get_element_attr_rsp(2,
  339. ele_attrs);
  340. schedule_action_verification(step);
  341. }
  342. static struct test_case test_cases[] = {
  343. TEST_CASE_BREDRLE("AVRCP Init",
  344. ACTION_SUCCESS(dummy_action, NULL),
  345. ),
  346. TEST_CASE_BREDRLE("AVRCP Connect - Success",
  347. ACTION_SUCCESS(bluetooth_enable_action, NULL),
  348. CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_ON),
  349. ACTION_SUCCESS(emu_setup_powered_remote_action, NULL),
  350. ACTION_SUCCESS(emu_set_ssp_mode_action, NULL),
  351. ACTION_SUCCESS(set_default_ssp_request_handler, NULL),
  352. ACTION_SUCCESS(emu_add_l2cap_server_action, &sdp_setup_data),
  353. ACTION_SUCCESS(emu_add_l2cap_server_action, &a2dp_setup_data),
  354. ACTION_SUCCESS(emu_add_l2cap_server_action, &avrcp_setup_data),
  355. ACTION_SUCCESS(avrcp_connect_action, NULL),
  356. CALLBACK_AV_CONN_STATE(CB_A2DP_CONN_STATE,
  357. BTAV_CONNECTION_STATE_CONNECTING),
  358. CALLBACK_AV_CONN_STATE(CB_A2DP_CONN_STATE,
  359. BTAV_CONNECTION_STATE_CONNECTED),
  360. ACTION_SUCCESS(bluetooth_disable_action, NULL),
  361. CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_OFF),
  362. ),
  363. TEST_CASE_BREDRLE("AVRCP Disconnect - Success",
  364. ACTION_SUCCESS(bluetooth_enable_action, NULL),
  365. CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_ON),
  366. ACTION_SUCCESS(emu_setup_powered_remote_action, NULL),
  367. ACTION_SUCCESS(emu_set_ssp_mode_action, NULL),
  368. ACTION_SUCCESS(set_default_ssp_request_handler, NULL),
  369. ACTION_SUCCESS(emu_add_l2cap_server_action, &sdp_setup_data),
  370. ACTION_SUCCESS(emu_add_l2cap_server_action, &a2dp_setup_data),
  371. ACTION_SUCCESS(emu_add_l2cap_server_action, &avrcp_setup_data),
  372. ACTION_SUCCESS(avrcp_connect_action, NULL),
  373. CALLBACK_AV_CONN_STATE(CB_A2DP_CONN_STATE,
  374. BTAV_CONNECTION_STATE_CONNECTING),
  375. CALLBACK_AV_CONN_STATE(CB_A2DP_CONN_STATE,
  376. BTAV_CONNECTION_STATE_CONNECTED),
  377. ACTION_SUCCESS(avrcp_disconnect_action, NULL),
  378. CALLBACK_AV_CONN_STATE(CB_A2DP_CONN_STATE,
  379. BTAV_CONNECTION_STATE_DISCONNECTING),
  380. CALLBACK_AV_CONN_STATE(CB_A2DP_CONN_STATE,
  381. BTAV_CONNECTION_STATE_DISCONNECTED),
  382. ACTION_SUCCESS(bluetooth_disable_action, NULL),
  383. CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_OFF),
  384. ),
  385. TEST_CASE_BREDRLE("AVRCP GetPlayStatus - Success",
  386. ACTION_SUCCESS(bluetooth_enable_action, NULL),
  387. CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_ON),
  388. ACTION_SUCCESS(emu_setup_powered_remote_action, NULL),
  389. ACTION_SUCCESS(emu_set_ssp_mode_action, NULL),
  390. ACTION_SUCCESS(set_default_ssp_request_handler, NULL),
  391. ACTION_SUCCESS(emu_add_l2cap_server_action, &sdp_setup_data),
  392. ACTION_SUCCESS(emu_add_l2cap_server_action, &a2dp_setup_data),
  393. ACTION_SUCCESS(emu_add_l2cap_server_action, &avrcp_setup_data),
  394. ACTION_SUCCESS(avrcp_connect_action, NULL),
  395. CALLBACK_AV_CONN_STATE(CB_A2DP_CONN_STATE,
  396. BTAV_CONNECTION_STATE_CONNECTING),
  397. CALLBACK_AV_CONN_STATE(CB_A2DP_CONN_STATE,
  398. BTAV_CONNECTION_STATE_CONNECTED),
  399. ACTION_SUCCESS(avrcp_get_play_status_req, NULL),
  400. CALLBACK(CB_AVRCP_PLAY_STATUS_REQ),
  401. ACTION_SUCCESS(avrcp_get_play_status_rsp, NULL),
  402. CALLBACK_RC_PLAY_STATUS(CB_AVRCP_PLAY_STATUS_RSP, 0xbbbbbbbb,
  403. 0xaaaaaaaa, 0x00),
  404. ACTION_SUCCESS(bluetooth_disable_action, NULL),
  405. CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_OFF),
  406. ),
  407. TEST_CASE_BREDRLE("AVRCP RegNotifTrackChanged - Success",
  408. ACTION_SUCCESS(bluetooth_enable_action, NULL),
  409. CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_ON),
  410. ACTION_SUCCESS(emu_setup_powered_remote_action, NULL),
  411. ACTION_SUCCESS(emu_set_ssp_mode_action, NULL),
  412. ACTION_SUCCESS(set_default_ssp_request_handler, NULL),
  413. ACTION_SUCCESS(emu_add_l2cap_server_action, &sdp_setup_data),
  414. ACTION_SUCCESS(emu_add_l2cap_server_action, &a2dp_setup_data),
  415. ACTION_SUCCESS(emu_add_l2cap_server_action, &avrcp_setup_data),
  416. ACTION_SUCCESS(avrcp_connect_action, NULL),
  417. CALLBACK_AV_CONN_STATE(CB_A2DP_CONN_STATE,
  418. BTAV_CONNECTION_STATE_CONNECTING),
  419. CALLBACK_AV_CONN_STATE(CB_A2DP_CONN_STATE,
  420. BTAV_CONNECTION_STATE_CONNECTED),
  421. ACTION_SUCCESS(avrcp_reg_notif_track_changed_req, NULL),
  422. CALLBACK(CB_AVRCP_REG_NOTIF_REQ),
  423. ACTION_SUCCESS(avrcp_reg_notif_track_changed_rsp, NULL),
  424. CALLBACK_RC_REG_NOTIF_TRACK_CHANGED(CB_AVRCP_REG_NOTIF_RSP,
  425. 0xffffffffffffffff),
  426. ACTION_SUCCESS(bluetooth_disable_action, NULL),
  427. CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_OFF),
  428. ),
  429. TEST_CASE_BREDRLE("AVRCP RegNotifPlayPositionChanged - Success",
  430. ACTION_SUCCESS(bluetooth_enable_action, NULL),
  431. CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_ON),
  432. ACTION_SUCCESS(emu_setup_powered_remote_action, NULL),
  433. ACTION_SUCCESS(emu_set_ssp_mode_action, NULL),
  434. ACTION_SUCCESS(set_default_ssp_request_handler, NULL),
  435. ACTION_SUCCESS(emu_add_l2cap_server_action, &sdp_setup_data),
  436. ACTION_SUCCESS(emu_add_l2cap_server_action, &a2dp_setup_data),
  437. ACTION_SUCCESS(emu_add_l2cap_server_action, &avrcp_setup_data),
  438. ACTION_SUCCESS(avrcp_connect_action, NULL),
  439. CALLBACK_AV_CONN_STATE(CB_A2DP_CONN_STATE,
  440. BTAV_CONNECTION_STATE_CONNECTING),
  441. CALLBACK_AV_CONN_STATE(CB_A2DP_CONN_STATE,
  442. BTAV_CONNECTION_STATE_CONNECTED),
  443. ACTION_SUCCESS(avrcp_reg_notif_play_position_changed_req, NULL),
  444. CALLBACK(CB_AVRCP_REG_NOTIF_REQ),
  445. ACTION_SUCCESS(avrcp_reg_notif_play_position_changed_rsp, NULL),
  446. CALLBACK_RC_REG_NOTIF_POSITION_CHANGED(CB_AVRCP_REG_NOTIF_RSP,
  447. 0xffffffff),
  448. ACTION_SUCCESS(bluetooth_disable_action, NULL),
  449. CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_OFF),
  450. ),
  451. TEST_CASE_BREDRLE("AVRCP RegNotifPlayStatusChanged - Success",
  452. ACTION_SUCCESS(bluetooth_enable_action, NULL),
  453. CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_ON),
  454. ACTION_SUCCESS(emu_setup_powered_remote_action, NULL),
  455. ACTION_SUCCESS(emu_set_ssp_mode_action, NULL),
  456. ACTION_SUCCESS(set_default_ssp_request_handler, NULL),
  457. ACTION_SUCCESS(emu_add_l2cap_server_action, &sdp_setup_data),
  458. ACTION_SUCCESS(emu_add_l2cap_server_action, &a2dp_setup_data),
  459. ACTION_SUCCESS(emu_add_l2cap_server_action, &avrcp_setup_data),
  460. ACTION_SUCCESS(avrcp_connect_action, NULL),
  461. CALLBACK_AV_CONN_STATE(CB_A2DP_CONN_STATE,
  462. BTAV_CONNECTION_STATE_CONNECTING),
  463. CALLBACK_AV_CONN_STATE(CB_A2DP_CONN_STATE,
  464. BTAV_CONNECTION_STATE_CONNECTED),
  465. ACTION_SUCCESS(avrcp_reg_notif_play_status_changed_req, NULL),
  466. CALLBACK(CB_AVRCP_REG_NOTIF_REQ),
  467. ACTION_SUCCESS(avrcp_reg_notif_play_status_changed_rsp, NULL),
  468. CALLBACK_RC_REG_NOTIF_STATUS_CHANGED(CB_AVRCP_REG_NOTIF_RSP,
  469. 0x00),
  470. ACTION_SUCCESS(bluetooth_disable_action, NULL),
  471. CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_OFF),
  472. ),
  473. TEST_CASE_BREDRLE("AVRCP GetElementAttributes - Success",
  474. ACTION_SUCCESS(bluetooth_enable_action, NULL),
  475. CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_ON),
  476. ACTION_SUCCESS(emu_setup_powered_remote_action, NULL),
  477. ACTION_SUCCESS(emu_set_ssp_mode_action, NULL),
  478. ACTION_SUCCESS(set_default_ssp_request_handler, NULL),
  479. ACTION_SUCCESS(emu_add_l2cap_server_action, &sdp_setup_data),
  480. ACTION_SUCCESS(emu_add_l2cap_server_action, &a2dp_setup_data),
  481. ACTION_SUCCESS(emu_add_l2cap_server_action, &avrcp_setup_data),
  482. ACTION_SUCCESS(avrcp_connect_action, NULL),
  483. CALLBACK_AV_CONN_STATE(CB_A2DP_CONN_STATE,
  484. BTAV_CONNECTION_STATE_CONNECTING),
  485. CALLBACK_AV_CONN_STATE(CB_A2DP_CONN_STATE,
  486. BTAV_CONNECTION_STATE_CONNECTED),
  487. ACTION_SUCCESS(avrcp_get_element_attributes_req, NULL),
  488. CALLBACK(CB_AVRCP_GET_ATTR_REQ),
  489. ACTION_SUCCESS(avrcp_get_element_attributes_rsp, NULL),
  490. CALLBACK_RC_GET_ELEMENT_ATTRIBUTES(CB_AVRCP_GET_ATTR_RSP, 2,
  491. ele_attrs),
  492. ACTION_SUCCESS(bluetooth_disable_action, NULL),
  493. CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_OFF),
  494. ),
  495. };
  496. struct queue *get_avrcp_tests(void)
  497. {
  498. uint16_t i = 0;
  499. list = queue_new();
  500. for (; i < sizeof(test_cases) / sizeof(test_cases[0]); ++i)
  501. queue_push_tail(list, &test_cases[i]);
  502. return list;
  503. }
  504. void remove_avrcp_tests(void)
  505. {
  506. queue_destroy(list, NULL);
  507. }