if-rc-ctrl.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // SPDX-License-Identifier: Apache-2.0
  2. /*
  3. * Copyright (C) 2014 Intel Corporation
  4. *
  5. */
  6. #define _GNU_SOURCE
  7. #include <stdio.h>
  8. #include <ctype.h>
  9. #include <string.h>
  10. #include <hardware/bluetooth.h>
  11. #include <hardware/bt_rc.h>
  12. #include "if-main.h"
  13. #include "pollhandler.h"
  14. #include "../hal-utils.h"
  15. const btrc_ctrl_interface_t *if_rc_ctrl = NULL;
  16. static char last_addr[MAX_ADDR_STR_LEN];
  17. static void passthrough_rsp_cb(int id, int key_state)
  18. {
  19. haltest_info("%s: id=%d key_state=%d\n", __func__, id, key_state);
  20. }
  21. static void connection_state_cb(bool state, bt_bdaddr_t *bd_addr)
  22. {
  23. haltest_info("%s: state=%s bd_addr=%s\n", __func__,
  24. state ? "true" : "false",
  25. bt_bdaddr_t2str(bd_addr, last_addr));
  26. }
  27. static btrc_ctrl_callbacks_t rc_ctrl_cbacks = {
  28. .size = sizeof(rc_ctrl_cbacks),
  29. .passthrough_rsp_cb = passthrough_rsp_cb,
  30. .connection_state_cb = connection_state_cb,
  31. };
  32. /* init */
  33. static void init_p(int argc, const char **argv)
  34. {
  35. RETURN_IF_NULL(if_rc_ctrl);
  36. EXEC(if_rc_ctrl->init, &rc_ctrl_cbacks);
  37. }
  38. /* cleanup */
  39. static void cleanup_p(int argc, const char **argv)
  40. {
  41. RETURN_IF_NULL(if_rc_ctrl);
  42. EXECV(if_rc_ctrl->cleanup);
  43. if_rc_ctrl = NULL;
  44. }
  45. /* send_pass_through_cmd */
  46. static void send_pass_through_cmd_c(int argc, const char **argv,
  47. enum_func *enum_func, void **user)
  48. {
  49. if (argc == 3) {
  50. *user = NULL;
  51. *enum_func = enum_devices;
  52. }
  53. }
  54. static void send_pass_through_cmd_p(int argc, const char **argv)
  55. {
  56. bt_bdaddr_t addr;
  57. uint8_t key_code, key_state;
  58. RETURN_IF_NULL(if_rc);
  59. VERIFY_ADDR_ARG(2, &addr);
  60. if (argc < 4) {
  61. haltest_error("No key code specified\n");
  62. return;
  63. }
  64. key_code = (uint8_t) atoi(argv[3]);
  65. if (argc < 5) {
  66. haltest_error("No key state specified\n");
  67. return;
  68. }
  69. key_state = (uint8_t) atoi(argv[4]);
  70. EXEC(if_rc_ctrl->send_pass_through_cmd, &addr, key_code, key_state);
  71. }
  72. static struct method methods[] = {
  73. STD_METHOD(init),
  74. STD_METHODCH(send_pass_through_cmd, "<bd_addr> <key_code> <key_state>"),
  75. STD_METHOD(cleanup),
  76. END_METHOD
  77. };
  78. const struct interface ctrl_rc_if = {
  79. .name = "rc-ctrl",
  80. .methods = methods
  81. };