gap_utils.c 3.8 KB

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