bsal_common.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * Copyright (c) 2006-2020, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2020-05-28 Supperthomas the first version
  9. */
  10. #ifndef __BSAL_COMMON_H__
  11. #define __BSAL_COMMON_H__
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. #include <stdint.h>
  16. #define BIT(x) (1<<x)
  17. typedef enum
  18. {
  19. BSAL_RESULT_SUCCESS = 0,
  20. BSAL_RESULT_FAIL = 0xff,
  21. BSAL_SRV_READ_PENDING = 0xf1,
  22. } BSAL_STATUS;
  23. #define BSAL_UUID_TYPE_16BIT 16
  24. #define BSAL_UUID_TYPE_32BIT 32
  25. #define BSAL_UUID_TYPE_128BIT 128
  26. /** 16-bit UUID */
  27. struct bsal_uuid16
  28. {
  29. uint8_t u_type;
  30. uint16_t value;
  31. };
  32. typedef struct bsal_uuid16 bsal_uuid16_t;
  33. /** 32-bit UUID */
  34. struct bsal_uuid32
  35. {
  36. uint8_t u_type;
  37. uint32_t value;
  38. } ;
  39. typedef struct bsal_uuid32 bsal_uuid32_t;
  40. /** 128-bit UUID */
  41. struct bsal_uuid128
  42. {
  43. uint8_t u_type;
  44. uint8_t value[16];
  45. };
  46. typedef struct bsal_uuid128 bsal_uuid128_t;
  47. typedef union
  48. {
  49. uint8_t u_type;
  50. bsal_uuid16_t u16;
  51. bsal_uuid32_t u32;
  52. bsal_uuid128_t u128;
  53. } bsal_uuid_any_t;
  54. #define BSAL_UUID16_INIT(uuid16) \
  55. { \
  56. .u_type = BSAL_UUID_TYPE_16BIT, \
  57. .value = (uuid16), \
  58. }
  59. #define BSAL_UUID32_INIT(uuid32) \
  60. { \
  61. .u_type = BSAL_UUID_TYPE_32BIT, \
  62. .value = (uuid32), \
  63. }
  64. #define BSAL_UUID128_INIT(uuid128...) \
  65. { \
  66. .u_type = BSAL_UUID_TYPE_128BIT, \
  67. .value = { uuid128 }, \
  68. }
  69. #define BSAL_UUID16_DECLARE(uuid16) \
  70. ((bsal_uuid_any_t *) (&(bsal_uuid16_t) BSAL_UUID16_INIT(uuid16)))
  71. #define BSAL_UUID32_DECLARE(uuid32) \
  72. ((bsal_uuid_any_t *) (&(bsal_uuid32_t) BSAL_UUID32_INIT(uuid32)))
  73. #define BSAL_UUID128_DECLARE(uuid128...) \
  74. ((bsal_uuid_any_t *) (&(bsal_uuid128_t) BSAL_UUID128_INIT(uuid128)))
  75. struct bsal_gatt_chr_def
  76. {
  77. bsal_uuid_any_t *uuid;
  78. struct bsal_gatt_dsc_def *descriptors;
  79. uint16_t properties;
  80. uint16_t permission;
  81. uint8_t value_length;
  82. uint16_t *val_handle;
  83. uint32_t bsal_flag; //self define flag for future
  84. };
  85. typedef struct bsal_gatt_chr_def bsal_gatt_chr_def_t;
  86. //SERVICE DEF
  87. struct bsal_gatt_app_srv_def
  88. {
  89. uint16_t type;
  90. bsal_uuid_any_t *uuid;
  91. struct bsal_gatt_app_srv_def **includes;
  92. bsal_gatt_chr_def_t *characteristics;
  93. };
  94. typedef struct bsal_gatt_app_srv_def bsal_gatt_app_srv_def_t;
  95. struct bsal_gatt_dsc_def
  96. {
  97. bsal_uuid_any_t *uuid;
  98. uint8_t att_flags;
  99. uint8_t min_key_size;
  100. };
  101. typedef struct bsal_gatt_dsc_def bsal_gatt_dsc_def_t;
  102. struct bsal_gatt_res
  103. {
  104. uint16_t svcs;
  105. void *srvc_addr;
  106. uint16_t incs;
  107. void *incs_addr;
  108. uint16_t chrs;
  109. void *chrs_addr;
  110. uint16_t dscs;
  111. void *dscs_addr;
  112. uint16_t cccds;
  113. void *cccds_addr;
  114. uint16_t attrs;
  115. };
  116. typedef struct bsal_gatt_res bsal_gatt_res_t;
  117. #define BSAL_MAX_NAME_LENGTH 40
  118. #define BSAL_MAX_ADV_SCAN_DATA_LENGTH 30
  119. #define BSAL_SRV_UUID_GENERAL 0xEEEE
  120. #ifdef __cplusplus
  121. }
  122. #endif
  123. #endif