app_main.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* main.c - Application main entry point */
  2. /*
  3. * Copyright (c) 2015-2016 Intel Corporation
  4. *
  5. * SPDX-License-Identifier: Apache-2.0
  6. */
  7. #include "services/bas.h"
  8. #include "services/dis.h"
  9. #include <errno.h>
  10. #include <stddef.h>
  11. #include <string.h>
  12. #include "base/byteorder.h"
  13. #include "base/types.h"
  14. #include <bluetooth/bluetooth.h>
  15. #include <bluetooth/conn.h>
  16. #include <bluetooth/gatt.h>
  17. #include <bluetooth/hci.h>
  18. #include <bluetooth/uuid.h>
  19. #include <logging/bt_log_impl.h>
  20. static const struct bt_data ad[] = {
  21. BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
  22. BT_DATA_BYTES(BT_DATA_UUID16_ALL, BT_UUID_16_ENCODE(BT_UUID_DIS_VAL)),
  23. };
  24. static void connected(struct bt_conn *conn, uint8_t err)
  25. {
  26. if (err)
  27. {
  28. printk("Connection failed (err 0x%02x)\n", err);
  29. }
  30. else
  31. {
  32. printk("Connected\n");
  33. }
  34. }
  35. static void disconnected(struct bt_conn *conn, uint8_t reason)
  36. {
  37. printk("Disconnected (reason 0x%02x)\n", reason);
  38. }
  39. static struct bt_conn_cb conn_callbacks = {
  40. .connected = connected,
  41. .disconnected = disconnected,
  42. };
  43. void bt_ready(int err)
  44. {
  45. if (err)
  46. {
  47. printk("Bluetooth init failed (err %d)\n", err);
  48. return;
  49. }
  50. printk("Bluetooth initialized\n");
  51. extern struct bt_gatt_service_static _1_gatt_svc;
  52. extern struct bt_gatt_service_static _2_gap_svc;
  53. bt_gatt_service_init(3, _1_gatt_svc, _2_gap_svc, dis_svc);
  54. bt_conn_cb_register(&conn_callbacks);
  55. #if defined(CONFIG_BT_FIXED_PASSKEY)
  56. bt_passkey_set(1234);
  57. #endif
  58. err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, ad, ARRAY_SIZE(ad), NULL, 0);
  59. if (err)
  60. {
  61. printk("Advertising failed to start (err %d)\n", err);
  62. return;
  63. }
  64. printk("Advertising successfully started\n");
  65. }
  66. void app_polling_work(void)
  67. {
  68. }