bt_keys.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /****************************************************************************
  2. * wireless/bluetooth/bt_keys.h
  3. * Bluetooth key handling
  4. *
  5. * Copyright (C) 2018 Gregory Nutt. All rights reserved.
  6. * Author: Gregory Nutt <gnutt@nuttx.org>
  7. *
  8. * Ported from the Intel/Zephyr arduino101_firmware_source-v1.tar package
  9. * where the code was released with a compatible 3-clause BSD license:
  10. *
  11. * Copyright (c) 2016, Intel Corporation
  12. * All rights reserved.
  13. *
  14. * Redistribution and use in source and binary forms, with or without
  15. * modification, are permitted provided that the following conditions are
  16. * met:
  17. *
  18. * 1. Redistributions of source code must retain the above copyright notice,
  19. * this list of conditions and the following disclaimer.
  20. *
  21. * 2. Redistributions in binary form must reproduce the above copyright
  22. * notice, this list of conditions and the following disclaimer in the
  23. * documentation and/or other materials provided with the distribution.
  24. *
  25. * 3. Neither the name of the copyright holder nor the names of its
  26. * contributors may be used to endorse or promote products derived from
  27. * this software without specific prior written permission.
  28. *
  29. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  30. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  31. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  32. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  33. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  34. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  35. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS
  36. * ; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  37. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  38. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  39. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  40. *
  41. ****************************************************************************/
  42. /****************************************************************************
  43. * Included Files
  44. ****************************************************************************/
  45. #include <nuttx/config.h>
  46. /****************************************************************************
  47. * Public Types
  48. ****************************************************************************/
  49. enum
  50. {
  51. BT_KEYS_SLAVE_LTK = (1 << 0),
  52. BT_KEYS_IRK = (1 << 1),
  53. BT_KEYS_LTK = (1 << 2),
  54. BT_KEYS_LOCAL_CSRK = (1 << 3),
  55. BT_KEYS_REMOTE_CSRK = (1 << 4),
  56. BT_KEYS_ALL = (BT_KEYS_SLAVE_LTK | BT_KEYS_IRK | BT_KEYS_LTK |
  57. BT_KEYS_LOCAL_CSRK | BT_KEYS_REMOTE_CSRK),
  58. };
  59. struct bt_ltk_s
  60. {
  61. uint64_t rand;
  62. uint16_t ediv;
  63. uint8_t val[16];
  64. FAR struct bt_keys_s *next;
  65. };
  66. struct bt_irk_s
  67. {
  68. uint8_t val[16];
  69. bt_addr_t rpa;
  70. FAR struct bt_keys_s *next;
  71. };
  72. struct bt_csrk_s
  73. {
  74. uint8_t val[16];
  75. uint32_t cnt;
  76. FAR struct bt_keys_s *next;
  77. };
  78. struct bt_keys_s
  79. {
  80. bt_addr_le_t addr;
  81. int keys;
  82. struct bt_ltk_s slave_ltk;
  83. struct bt_ltk_s ltk;
  84. struct bt_irk_s irk;
  85. struct bt_csrk_s local_csrk;
  86. struct bt_csrk_s remote_csrk;
  87. };
  88. /****************************************************************************
  89. * Public Function Prototypes
  90. ****************************************************************************/
  91. FAR struct bt_keys_s *bt_keys_get_addr(FAR const bt_addr_le_t *addr);
  92. FAR struct bt_keys_s *bt_keys_get_type(int type,
  93. FAR const bt_addr_le_t *addr);
  94. void bt_keys_add_type(FAR struct bt_keys_s *keys, int type);
  95. void bt_keys_clear(FAR struct bt_keys_s *keys, int type);
  96. FAR struct bt_keys_s *bt_keys_find(int type, FAR const bt_addr_le_t *addr);
  97. FAR struct bt_keys_s *bt_keys_find_irk(FAR const bt_addr_le_t *addr);