tester-map-client.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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/tester.h"
  10. #include "src/shared/queue.h"
  11. #include "tester-main.h"
  12. static struct queue *list = NULL; /* List of map client test cases */
  13. #define INST0_ID 0
  14. #define INST1_ID 1
  15. #define sdp_rsp_pdu 0x07, \
  16. 0x00, 0x00, \
  17. 0x00, 0xb5, \
  18. 0x00, 0xb2, \
  19. 0x35, 0xb0, 0x36, 0x00, 0x56, 0x09, 0x00, 0x00, 0x0a, \
  20. 0x00, 0x01, 0x00, 0x09, 0x09, 0x00, 0x01, 0x35, 0x03, \
  21. 0x19, 0x11, 0x32, 0x09, 0x00, 0x04, 0x35, 0x11, 0x35, \
  22. 0x03, 0x19, 0x01, 0x00, 0x35, 0x05, 0x19, 0x00, 0x03, \
  23. 0x08, 0x04, 0x35, 0x03, 0x19, 0x00, 0x08, 0x09, 0x00, \
  24. 0x05, 0x35, 0x03, 0x19, 0x10, 0x02, 0x09, 0x00, 0x09, \
  25. 0x35, 0x08, 0x35, 0x06, 0x19, 0x11, 0x34, 0x09, 0x01, \
  26. 0x01, 0x09, 0x01, 0x00, 0x25, 0x0c, 0x4d, 0x41, 0x50, \
  27. 0x20, 0x53, 0x4d, 0x53, 0x2f, 0x4d, 0x4d, 0x53, 0x00, \
  28. 0x09, 0x03, 0x15, 0x08, 0x00, 0x09, 0x03, 0x16, 0x08, \
  29. 0x0e, 0x36, 0x00, 0x54, 0x09, 0x00, 0x00, 0x0a, 0x00, \
  30. 0x01, 0x00, 0x0a, 0x09, 0x00, 0x01, 0x35, 0x03, 0x19, \
  31. 0x11, 0x32, 0x09, 0x00, 0x04, 0x35, 0x11, 0x35, 0x03, \
  32. 0x19, 0x01, 0x00, 0x35, 0x05, 0x19, 0x00, 0x03, 0x08, \
  33. 0x05, 0x35, 0x03, 0x19, 0x00, 0x08, 0x09, 0x00, 0x05, \
  34. 0x35, 0x03, 0x19, 0x10, 0x02, 0x09, 0x00, 0x09, 0x35, \
  35. 0x08, 0x35, 0x06, 0x19, 0x11, 0x34, 0x09, 0x01, 0x01, \
  36. 0x09, 0x01, 0x00, 0x25, 0x0a, 0x4d, 0x41, 0x50, 0x20, \
  37. 0x45, 0x4d, 0x41, 0x49, 0x4c, 0x00, 0x09, 0x03, 0x15, \
  38. 0x08, 0x01, 0x09, 0x03, 0x16, 0x08, 0x01, \
  39. 0x00
  40. static const struct pdu_set pdus[] = {
  41. { end_pdu, raw_pdu(sdp_rsp_pdu) },
  42. { end_pdu, end_pdu },
  43. };
  44. static struct emu_l2cap_cid_data cid_data = {
  45. .pdu = pdus,
  46. };
  47. static bt_bdaddr_t emu_remote_bdaddr_val = {
  48. .address = { 0x00, 0xaa, 0x01, 0x01, 0x00, 0x00 },
  49. };
  50. static struct emu_set_l2cap_data l2cap_sdp_setup_data = {
  51. .psm = 1,
  52. .func = tester_generic_connect_cb,
  53. .user_data = &cid_data,
  54. };
  55. /* TODO define all parameters according to specification document */
  56. static btmce_mas_instance_t remote_map_inst_sms_mms_email_val[] = {
  57. { INST0_ID, 4, 14, "MAP SMS/MMS" },
  58. { INST1_ID, 5, 1, "MAP EMAIL" },
  59. };
  60. static void map_client_cid_hook_cb(const void *data, uint16_t len,
  61. void *user_data)
  62. {
  63. /* TODO extend if needed */
  64. }
  65. static void map_client_conn_cb(uint16_t handle, void *user_data)
  66. {
  67. struct test_data *data = tester_get_data();
  68. struct bthost *bthost = hciemu_client_get_host(data->hciemu);
  69. tester_print("New connection with handle 0x%04x", handle);
  70. if (data->hciemu_type == HCIEMU_TYPE_BREDR) {
  71. tester_warn("Not handled device type.");
  72. return;
  73. }
  74. cid_data.cid = 0x0040;
  75. cid_data.handle = handle;
  76. bthost_add_cid_hook(bthost, handle, cid_data.cid,
  77. map_client_cid_hook_cb, &cid_data);
  78. }
  79. static void map_client_get_instances_action(void)
  80. {
  81. struct test_data *data = tester_get_data();
  82. struct step *current_data_step = queue_peek_head(data->steps);
  83. bt_bdaddr_t *bd_addr = current_data_step->set_data;
  84. struct step *step = g_new0(struct step, 1);
  85. step->action_status =
  86. data->if_map_client->get_remote_mas_instances(bd_addr);
  87. schedule_action_verification(step);
  88. }
  89. static struct test_case test_cases[] = {
  90. TEST_CASE_BREDRLE("MAP Client Init", ACTION_SUCCESS(dummy_action, NULL),
  91. ),
  92. TEST_CASE_BREDRLE("MAP Client - Get mas instances success",
  93. ACTION_SUCCESS(bluetooth_enable_action, NULL),
  94. CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_ON),
  95. ACTION_SUCCESS(emu_setup_powered_remote_action, NULL),
  96. ACTION_SUCCESS(emu_add_l2cap_server_action,
  97. &l2cap_sdp_setup_data),
  98. ACTION_SUCCESS(emu_set_connect_cb_action, map_client_conn_cb),
  99. ACTION_SUCCESS(map_client_get_instances_action,
  100. &emu_remote_bdaddr_val),
  101. CALLBACK_MAP_CLIENT_REMOTE_MAS_INSTANCE(BT_STATUS_SUCCESS, NULL,
  102. 2, remote_map_inst_sms_mms_email_val),
  103. ACTION_SUCCESS(bluetooth_disable_action, NULL),
  104. CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_OFF),
  105. ),
  106. };
  107. struct queue *get_map_client_tests(void)
  108. {
  109. uint16_t i = 0;
  110. list = queue_new();
  111. for (; i < sizeof(test_cases) / sizeof(test_cases[0]); ++i)
  112. queue_push_tail(list, &test_cases[i]);
  113. return list;
  114. }
  115. void remove_map_client_tests(void)
  116. {
  117. queue_destroy(list, NULL);
  118. }