gatt_sdp.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright (C) 2014 BlueKitchen GmbH
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * 3. Neither the name of the copyright holders nor the names of
  14. * contributors may be used to endorse or promote products derived
  15. * from this software without specific prior written permission.
  16. * 4. Any redistribution, use, or modification is done solely for
  17. * personal benefit and not for any commercial purpose or for
  18. * monetary gain.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
  21. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  23. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
  24. * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  25. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  26. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  27. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  28. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  29. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  30. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31. * SUCH DAMAGE.
  32. *
  33. * Please inquire about commercial licensing options at
  34. * contact@bluekitchen-gmbh.com
  35. *
  36. */
  37. #define BTSTACK_FILE__ "gatt_sdp.c"
  38. /*
  39. * gatt_sdp.c
  40. */
  41. #include "gatt_sdp.h"
  42. #include <string.h>
  43. #include "bluetooth_gatt.h"
  44. #include "bluetooth_psm.h"
  45. #include "bluetooth_sdp.h"
  46. #include "btstack_config.h"
  47. #include "classic/core.h"
  48. #include "classic/sdp_util.h"
  49. #include "l2cap.h"
  50. void gatt_create_sdp_record(uint8_t *service, uint32_t service_record_handle, uint16_t gatt_start_handle, uint16_t gatt_end_handle){
  51. uint8_t* attribute;
  52. de_create_sequence(service);
  53. // 0x0000 "Service Record Handle"
  54. de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_SERVICE_RECORD_HANDLE);
  55. de_add_number(service, DE_UINT, DE_SIZE_32, service_record_handle);
  56. // 0x0001 "Service Class ID List"
  57. de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_SERVICE_CLASS_ID_LIST);
  58. attribute = de_push_sequence(service);
  59. {
  60. de_add_number(attribute, DE_UUID, DE_SIZE_32, ORG_BLUETOOTH_SERVICE_GENERIC_ATTRIBUTE);
  61. }
  62. de_pop_sequence(service, attribute);
  63. // 0x0004 "Protocol Descriptor List"
  64. de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_PROTOCOL_DESCRIPTOR_LIST);
  65. attribute = de_push_sequence(service);
  66. {
  67. uint8_t* l2cap_protocol = de_push_sequence(attribute);
  68. {
  69. de_add_number(l2cap_protocol, DE_UUID, DE_SIZE_16, BLUETOOTH_PROTOCOL_L2CAP);
  70. de_add_number(l2cap_protocol, DE_UINT, DE_SIZE_16, BLUETOOTH_PSM_ATT);
  71. }
  72. de_pop_sequence(attribute, l2cap_protocol);
  73. uint8_t* att_protocol = de_push_sequence(attribute);
  74. {
  75. de_add_number(att_protocol, DE_UUID, DE_SIZE_16, BLUETOOTH_PROTOCOL_ATT);
  76. de_add_number(att_protocol, DE_UINT, DE_SIZE_16, gatt_start_handle);
  77. de_add_number(att_protocol, DE_UINT, DE_SIZE_16, gatt_end_handle);
  78. }
  79. de_pop_sequence(attribute, att_protocol);
  80. }
  81. de_pop_sequence(service, attribute);
  82. // 0x0005 "Public Browse Group"
  83. de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_BROWSE_GROUP_LIST);
  84. attribute = de_push_sequence(service);
  85. {
  86. de_add_number(attribute, DE_UUID, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_PUBLIC_BROWSE_ROOT);
  87. }
  88. de_pop_sequence(service, attribute);
  89. }