manager.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. *
  4. * BlueZ - Bluetooth protocol stack for Linux
  5. *
  6. * Copyright (C) 2004-2010 Marcel Holtmann <marcel@holtmann.org>
  7. *
  8. *
  9. */
  10. #ifdef HAVE_CONFIG_H
  11. #include <config.h>
  12. #endif
  13. #include <errno.h>
  14. #include <stdbool.h>
  15. #include "lib/bluetooth.h"
  16. #include "lib/sdp.h"
  17. #include "lib/sdp_lib.h"
  18. #include "lib/uuid.h"
  19. #include "src/log.h"
  20. #include "src/plugin.h"
  21. #include "src/adapter.h"
  22. #include "src/device.h"
  23. #include "src/profile.h"
  24. #include "src/service.h"
  25. #include "device.h"
  26. #include "server.h"
  27. static int hid_server_probe(struct btd_profile *p, struct btd_adapter *adapter)
  28. {
  29. return server_start(btd_adapter_get_address(adapter));
  30. }
  31. static void hid_server_remove(struct btd_profile *p,
  32. struct btd_adapter *adapter)
  33. {
  34. server_stop(btd_adapter_get_address(adapter));
  35. }
  36. static struct btd_profile input_profile = {
  37. .name = "input-hid",
  38. .local_uuid = HID_UUID,
  39. .remote_uuid = HID_UUID,
  40. .auto_connect = true,
  41. .connect = input_device_connect,
  42. .disconnect = input_device_disconnect,
  43. .device_probe = input_device_register,
  44. .device_remove = input_device_unregister,
  45. .adapter_probe = hid_server_probe,
  46. .adapter_remove = hid_server_remove,
  47. };
  48. static GKeyFile *load_config_file(const char *file)
  49. {
  50. GKeyFile *keyfile;
  51. GError *err = NULL;
  52. keyfile = g_key_file_new();
  53. if (!g_key_file_load_from_file(keyfile, file, 0, &err)) {
  54. if (!g_error_matches(err, G_FILE_ERROR, G_FILE_ERROR_NOENT))
  55. error("Parsing %s failed: %s", file, err->message);
  56. g_error_free(err);
  57. g_key_file_free(keyfile);
  58. return NULL;
  59. }
  60. return keyfile;
  61. }
  62. static int input_init(void)
  63. {
  64. GKeyFile *config;
  65. GError *err = NULL;
  66. config = load_config_file(CONFIGDIR "/input.conf");
  67. if (config) {
  68. int idle_timeout;
  69. gboolean uhid_enabled, classic_bonded_only, auto_sec;
  70. idle_timeout = g_key_file_get_integer(config, "General",
  71. "IdleTimeout", &err);
  72. if (!err) {
  73. DBG("input.conf: IdleTimeout=%d", idle_timeout);
  74. input_set_idle_timeout(idle_timeout * 60);
  75. } else
  76. g_clear_error(&err);
  77. uhid_enabled = g_key_file_get_boolean(config, "General",
  78. "UserspaceHID", &err);
  79. if (!err) {
  80. DBG("input.conf: UserspaceHID=%s", uhid_enabled ?
  81. "true" : "false");
  82. input_enable_userspace_hid(uhid_enabled);
  83. } else
  84. g_clear_error(&err);
  85. classic_bonded_only = g_key_file_get_boolean(config, "General",
  86. "ClassicBondedOnly", &err);
  87. if (!err) {
  88. DBG("input.conf: ClassicBondedOnly=%s",
  89. classic_bonded_only ? "true" : "false");
  90. input_set_classic_bonded_only(classic_bonded_only);
  91. } else
  92. g_clear_error(&err);
  93. auto_sec = g_key_file_get_boolean(config, "General",
  94. "LEAutoSecurity", &err);
  95. if (!err) {
  96. DBG("input.conf: LEAutoSecurity=%s",
  97. auto_sec ? "true" : "false");
  98. input_set_auto_sec(auto_sec);
  99. } else
  100. g_clear_error(&err);
  101. }
  102. btd_profile_register(&input_profile);
  103. if (config)
  104. g_key_file_free(config);
  105. return 0;
  106. }
  107. static void input_exit(void)
  108. {
  109. btd_profile_unregister(&input_profile);
  110. }
  111. BLUETOOTH_PLUGIN_DEFINE(input, VERSION, BLUETOOTH_PLUGIN_PRIORITY_DEFAULT,
  112. input_init, input_exit)