gap_api.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /******************************************************************************
  2. *
  3. * Copyright (C) 2009-2013 Broadcom Corporation
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at:
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. ******************************************************************************/
  18. #include <string.h>
  19. #include "common/bt_target.h"
  20. //#include "bt_utils.h"
  21. #include "gap_int.h"
  22. #include "osi/allocator.h"
  23. #if GAP_DYNAMIC_MEMORY == FALSE
  24. tGAP_CB gap_cb;
  25. #else
  26. tGAP_CB *gap_cb_ptr;
  27. #endif
  28. /*******************************************************************************
  29. **
  30. ** Function GAP_SetTraceLevel
  31. **
  32. ** Description This function sets the trace level for GAP. If called with
  33. ** a value of 0xFF, it simply returns the current trace level.
  34. **
  35. ** Returns The new or current trace level
  36. **
  37. *******************************************************************************/
  38. UINT8 GAP_SetTraceLevel (UINT8 new_level)
  39. {
  40. if (new_level != 0xFF) {
  41. gap_cb.trace_level = new_level;
  42. }
  43. return (gap_cb.trace_level);
  44. }
  45. /*******************************************************************************
  46. **
  47. ** Function GAP_Init
  48. **
  49. ** Description Initializes the control blocks used by GAP.
  50. **
  51. ** This routine should not be called except once per
  52. ** stack invocation.
  53. **
  54. ** Returns status
  55. **
  56. *******************************************************************************/
  57. bt_status_t GAP_Init(void)
  58. {
  59. #if GAP_DYNAMIC_MEMORY == TRUE
  60. gap_cb_ptr = (tGAP_CB *)osi_malloc(sizeof(tGAP_CB));
  61. if (!gap_cb_ptr) {
  62. return BT_STATUS_NOMEM;
  63. }
  64. #endif
  65. memset (&gap_cb, 0, sizeof (tGAP_CB));
  66. #if defined(GAP_INITIAL_TRACE_LEVEL)
  67. gap_cb.trace_level = GAP_INITIAL_TRACE_LEVEL;
  68. #else
  69. gap_cb.trace_level = BT_TRACE_LEVEL_NONE; /* No traces */
  70. #endif
  71. #if GAP_CONN_INCLUDED == TRUE
  72. gap_conn_init();
  73. #endif
  74. #if BLE_INCLUDED == TRUE && GATTS_INCLUDED == TRUE
  75. gap_attr_db_init();
  76. #endif
  77. return BT_STATUS_SUCCESS;
  78. }
  79. /*******************************************************************************
  80. **
  81. ** Function GAP_Deinit
  82. **
  83. ** Description This function is called to deinitialize the control block
  84. ** for this layer.
  85. **
  86. ** Returns void
  87. **
  88. *******************************************************************************/
  89. void GAP_Deinit(void)
  90. {
  91. #if GAP_DYNAMIC_MEMORY == TRUE
  92. if (gap_cb_ptr) {
  93. osi_free(gap_cb_ptr);
  94. gap_cb_ptr = NULL;
  95. }
  96. #endif
  97. }