gap_utils.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. #if (CLASSIC_BT_INCLUDED == TRUE)
  23. /*******************************************************************************
  24. **
  25. ** Function gap_allocate_cb
  26. **
  27. ** Description Look through the GAP Control Blocks for a free one.
  28. **
  29. ** Returns Pointer to the control block or NULL if not found
  30. **
  31. *******************************************************************************/
  32. tGAP_INFO *gap_allocate_cb (void)
  33. {
  34. tGAP_INFO *p_cb = &gap_cb.blk[0];
  35. UINT8 x;
  36. for (x = 0; x < GAP_MAX_BLOCKS; x++, p_cb++) {
  37. if (!p_cb->in_use) {
  38. memset (p_cb, 0, sizeof (tGAP_INFO));
  39. p_cb->in_use = TRUE;
  40. p_cb->index = x;
  41. p_cb->p_data = (void *)NULL;
  42. return (p_cb);
  43. }
  44. }
  45. /* If here, no free control blocks found */
  46. return (NULL);
  47. }
  48. /*******************************************************************************
  49. **
  50. ** Function gap_free_cb
  51. **
  52. ** Description Release GAP control block.
  53. **
  54. ** Returns Pointer to the control block or NULL if not found
  55. **
  56. *******************************************************************************/
  57. void gap_free_cb (tGAP_INFO *p_cb)
  58. {
  59. if (p_cb) {
  60. p_cb->gap_cback = NULL;
  61. p_cb->in_use = FALSE;
  62. }
  63. }
  64. /*******************************************************************************
  65. **
  66. ** Function gap_is_service_busy
  67. **
  68. ** Description Look through the GAP Control Blocks that are in use
  69. ** and check to see if the event waiting for is the command
  70. ** requested.
  71. **
  72. ** Returns TRUE if already in use
  73. ** FALSE if not busy
  74. **
  75. *******************************************************************************/
  76. BOOLEAN gap_is_service_busy (UINT16 request)
  77. {
  78. tGAP_INFO *p_cb = &gap_cb.blk[0];
  79. UINT8 x;
  80. for (x = 0; x < GAP_MAX_BLOCKS; x++, p_cb++) {
  81. if (p_cb->in_use && p_cb->event == request) {
  82. return (TRUE);
  83. }
  84. }
  85. /* If here, service is not busy */
  86. return (FALSE);
  87. }
  88. /*******************************************************************************
  89. **
  90. ** Function gap_convert_btm_status
  91. **
  92. ** Description Converts a BTM error status into a GAP error status
  93. **
  94. **
  95. ** Returns GAP_UNKNOWN_BTM_STATUS is returned if not recognized
  96. **
  97. *******************************************************************************/
  98. UINT16 gap_convert_btm_status (tBTM_STATUS btm_status)
  99. {
  100. switch (btm_status) {
  101. case BTM_SUCCESS:
  102. return (BT_PASS);
  103. case BTM_CMD_STARTED:
  104. return (GAP_CMD_INITIATED);
  105. case BTM_BUSY:
  106. return (GAP_ERR_BUSY);
  107. case BTM_MODE_UNSUPPORTED:
  108. case BTM_ILLEGAL_VALUE:
  109. return (GAP_ERR_ILL_PARM);
  110. case BTM_WRONG_MODE:
  111. return (GAP_DEVICE_NOT_UP);
  112. case BTM_UNKNOWN_ADDR:
  113. return (GAP_BAD_BD_ADDR);
  114. case BTM_DEVICE_TIMEOUT:
  115. return (GAP_ERR_TIMEOUT);
  116. default:
  117. return (GAP_ERR_PROCESSING);
  118. }
  119. }
  120. #endif ///CLASSIC_BT_INCLUDED == TRUE