bta_hl_main.cc 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869
  1. /******************************************************************************
  2. *
  3. * Copyright 1998-2012 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. /******************************************************************************
  19. *
  20. * This file contains the HeaLth device profile main functions and state
  21. * machine.
  22. *
  23. ******************************************************************************/
  24. #include <string.h>
  25. #include "bt_target.h"
  26. #if (HL_INCLUDED == TRUE)
  27. #include "bt_common.h"
  28. #include "bta_hl_api.h"
  29. #include "bta_hl_int.h"
  30. #include "l2c_api.h"
  31. #include "mca_defs.h"
  32. #include "osi/include/osi.h"
  33. #include "utl.h"
  34. #if (BTA_HL_DEBUG == TRUE)
  35. static const char* bta_hl_cch_state_code(tBTA_HL_CCH_STATE state_code);
  36. static const char* bta_hl_dch_state_code(tBTA_HL_DCH_STATE state_code);
  37. #endif
  38. extern uint16_t L2CA_AllocateRandomPsm(void);
  39. extern uint16_t L2CA_AllocatePsm(void);
  40. /*****************************************************************************
  41. * DCH State Table
  42. ****************************************************************************/
  43. /*****************************************************************************
  44. * Constants and types
  45. ****************************************************************************/
  46. /* state machine action enumeration list for DCH */
  47. /* The order of this enumeration must be the same as bta_hl_dch_act_tbl[] */
  48. enum {
  49. BTA_HL_DCH_MCA_CREATE,
  50. BTA_HL_DCH_MCA_CREATE_CFM,
  51. BTA_HL_DCH_MCA_CREATE_IND,
  52. BTA_HL_DCH_MCA_OPEN_CFM,
  53. BTA_HL_DCH_MCA_OPEN_IND,
  54. BTA_HL_DCH_MCA_CLOSE,
  55. BTA_HL_DCH_MCA_CLOSE_CFM,
  56. BTA_HL_DCH_MCA_CLOSE_IND,
  57. BTA_HL_DCH_CLOSE_CMPL,
  58. BTA_HL_DCH_MCA_RCV_DATA,
  59. BTA_HL_DCH_SDP_INIT,
  60. BTA_HL_DCH_MCA_RECONNECT,
  61. BTA_HL_DCH_MCA_RECONNECT_IND,
  62. BTA_HL_DCH_MCA_RECONNECT_CFM,
  63. BTA_HL_DCH_CLOSE_ECHO_TEST,
  64. BTA_HL_DCH_CREATE_RSP,
  65. BTA_HL_DCH_MCA_ABORT,
  66. BTA_HL_DCH_MCA_ABORT_IND,
  67. BTA_HL_DCH_MCA_ABORT_CFM,
  68. BTA_HL_DCH_MCA_CONG_CHANGE,
  69. BTA_HL_DCH_SDP_FAIL,
  70. BTA_HL_DCH_SEND_DATA,
  71. BTA_HL_DCH_CI_GET_TX_DATA,
  72. BTA_HL_DCH_CI_PUT_RX_DATA,
  73. BTA_HL_DCH_CI_GET_ECHO_DATA,
  74. BTA_HL_DCH_ECHO_TEST,
  75. BTA_HL_DCH_CI_PUT_ECHO_DATA,
  76. BTA_HL_DCH_IGNORE
  77. };
  78. typedef void (*tBTA_HL_DCH_ACTION)(uint8_t app_idx, uint8_t mcl_idx,
  79. uint8_t mdl_idx, tBTA_HL_DATA* p_data);
  80. static const tBTA_HL_DCH_ACTION bta_hl_dch_action[] = {
  81. bta_hl_dch_mca_create, bta_hl_dch_mca_create_cfm,
  82. bta_hl_dch_mca_create_ind, bta_hl_dch_mca_open_cfm,
  83. bta_hl_dch_mca_open_ind, bta_hl_dch_mca_close,
  84. bta_hl_dch_mca_close_cfm, bta_hl_dch_mca_close_ind,
  85. bta_hl_dch_close_cmpl, bta_hl_dch_mca_rcv_data,
  86. bta_hl_dch_sdp_init, bta_hl_dch_mca_reconnect,
  87. bta_hl_dch_mca_reconnect_ind, bta_hl_dch_mca_reconnect_cfm,
  88. bta_hl_dch_close_echo_test, bta_hl_dch_create_rsp,
  89. bta_hl_dch_mca_abort, bta_hl_dch_mca_abort_ind,
  90. bta_hl_dch_mca_abort_cfm, bta_hl_dch_mca_cong_change,
  91. bta_hl_dch_sdp_fail, bta_hl_dch_send_data,
  92. bta_hl_dch_ci_get_tx_data, bta_hl_dch_ci_put_rx_data,
  93. bta_hl_dch_ci_get_echo_data, bta_hl_dch_echo_test,
  94. bta_hl_dch_ci_put_echo_data,
  95. };
  96. /* state table information */
  97. #define BTA_HL_DCH_ACTIONS 1 /* number of actions */
  98. #define BTA_HL_DCH_ACTION_COL 0 /* position of action */
  99. #define BTA_HL_DCH_NEXT_STATE 1 /* position of next state */
  100. #define BTA_HL_DCH_NUM_COLS 2 /* number of columns in state tables */
  101. /* state table for idle state */
  102. static const uint8_t bta_hl_dch_st_idle[][BTA_HL_DCH_NUM_COLS] = {
  103. /* Event Action 1 Next
  104. state */
  105. /* BTA_HL_DCH_SDP_INIT_EVT */ {BTA_HL_DCH_SDP_INIT,
  106. BTA_HL_DCH_OPENING_ST},
  107. /* BTA_HL_DCH_OPEN_EVT */ {BTA_HL_DCH_MCA_CREATE,
  108. BTA_HL_DCH_OPENING_ST},
  109. /* BTA_HL_MCA_CREATE_IND_EVT */ {BTA_HL_DCH_MCA_CREATE_IND,
  110. BTA_HL_DCH_OPENING_ST},
  111. /* BTA_HL_MCA_CREATE_CFM_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST},
  112. /* BTA_HL_MCA_OPEN_IND_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST},
  113. /* BTA_HL_MCA_OPEN_CFM_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST},
  114. /* BTA_HL_DCH_CLOSE_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST},
  115. /* BTA_HL_MCA_CLOSE_IND_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST},
  116. /* BTA_HL_MCA_CLOSE_CFM_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST},
  117. /* BTA_HL_API_SEND_DATA_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST},
  118. /* BTA_HL_MCA_RCV_DATA_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST},
  119. /* BTA_HL_DCH_CLOSE_CMPL_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST},
  120. /* BTA_HL_DCH_RECONNECT_EVT */ {BTA_HL_DCH_MCA_RECONNECT,
  121. BTA_HL_DCH_OPENING_ST},
  122. /* BTA_HL_DCH_SDP_FAIL_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST},
  123. /* BTA_HL_MCA_RECONNECT_IND_EVT*/ {BTA_HL_DCH_MCA_RECONNECT_IND,
  124. BTA_HL_DCH_OPENING_ST},
  125. /* BTA_HL_MCA_RECONNECT_CFM_EVT*/ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST},
  126. /* BTA_HL_DCH_CLOSE_ECHO_TEST_EVT*/ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST},
  127. /* BTA_HL_API_DCH_CREATE_RSP_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST},
  128. /* BTA_HL_DCH_ABORT_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST},
  129. /* BTA_HL_MCA_ABORT_IND_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST},
  130. /* BTA_HL_MCA_ABORT_CFM_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST},
  131. /* BTA_HL_MCA_CONG_CHG_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST},
  132. /* BTA_HL_CI_GET_TX_DATA_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST},
  133. /* BTA_HL_CI_PUT_RX_DATA_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST},
  134. /* BTA_HL_CI_GET_ECHO_DATA_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST},
  135. /* BTA_HL_DCH_ECHO_TEST_EVT */ {BTA_HL_DCH_ECHO_TEST,
  136. BTA_HL_DCH_OPENING_ST},
  137. /* BTA_HL_CI_PUT_ECHO_DATA_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST}};
  138. /* state table for opening state */
  139. static const uint8_t bta_hl_dch_st_opening[][BTA_HL_DCH_NUM_COLS] = {
  140. /* Event Action 1 Next
  141. state */
  142. /* BTA_HL_DCH_SDP_INIT_EVT */ {BTA_HL_DCH_SDP_INIT,
  143. BTA_HL_DCH_OPENING_ST},
  144. /* BTA_HL_DCH_OPEN_EVT */ {BTA_HL_DCH_MCA_CREATE,
  145. BTA_HL_DCH_OPENING_ST},
  146. /* BTA_HL_MCA_CREATE_IND_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPENING_ST},
  147. /* BTA_HL_MCA_CREATE_CFM_EVT */ {BTA_HL_DCH_MCA_CREATE_CFM,
  148. BTA_HL_DCH_OPENING_ST},
  149. /* BTA_HL_MCA_OPEN_IND_EVT */ {BTA_HL_DCH_MCA_OPEN_IND,
  150. BTA_HL_DCH_OPEN_ST},
  151. /* BTA_HL_MCA_OPEN_CFM_EVT */ {BTA_HL_DCH_MCA_OPEN_CFM,
  152. BTA_HL_DCH_OPEN_ST},
  153. /* BTA_HL_DCH_CLOSE_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPENING_ST},
  154. /* BTA_HL_MCA_CLOSE_IND_EVT */ {BTA_HL_DCH_MCA_CLOSE_IND,
  155. BTA_HL_DCH_CLOSING_ST},
  156. /* BTA_HL_MCA_CLOSE_CFM_EVT */ {BTA_HL_DCH_MCA_CLOSE_CFM,
  157. BTA_HL_DCH_CLOSING_ST},
  158. /* BTA_HL_API_SEND_DATA_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST},
  159. /* BTA_HL_MCA_RCV_DATA_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST},
  160. /* BTA_HL_DCH_CLOSE_CMPL_EVT */ {BTA_HL_DCH_CLOSE_CMPL, BTA_HL_DCH_IDLE_ST},
  161. /* BTA_HL_DCH_RECONNECT_EVT */ {BTA_HL_DCH_MCA_RECONNECT,
  162. BTA_HL_DCH_OPENING_ST},
  163. /* BTA_HL_DCH_SDP_FAIL_EVT */ {BTA_HL_DCH_SDP_FAIL,
  164. BTA_HL_DCH_CLOSING_ST},
  165. /* BTA_HL_MCA_RECONNECT_IND_EVT*/ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST},
  166. /* BTA_HL_MCA_RECONNECT_CFM_EVT*/ {BTA_HL_DCH_MCA_RECONNECT_CFM,
  167. BTA_HL_DCH_OPENING_ST},
  168. /* BTA_HL_DCH_CLOSE_ECHO_TEST_EVT*/ {BTA_HL_DCH_IGNORE,
  169. BTA_HL_DCH_OPENING_ST},
  170. /* BTA_HL_API_DCH_CREATE_RSP_EVT */ {BTA_HL_DCH_CREATE_RSP,
  171. BTA_HL_DCH_OPENING_ST},
  172. /* BTA_HL_DCH_ABORT_EVT */ {BTA_HL_DCH_MCA_ABORT, BTA_HL_DCH_OPENING_ST},
  173. /* BTA_HL_MCA_ABORT_IND_EVT */ {BTA_HL_DCH_MCA_ABORT_IND,
  174. BTA_HL_DCH_OPENING_ST},
  175. /* BTA_HL_MCA_ABORT_CFM_EVT */ {BTA_HL_DCH_MCA_ABORT_CFM,
  176. BTA_HL_DCH_OPENING_ST},
  177. /* BTA_HL_MCA_CONG_CHG_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPENING_ST},
  178. /* BTA_HL_CI_GET_TX_DATA_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPENING_ST},
  179. /* BTA_HL_CI_PUT_RX_DATA_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPENING_ST},
  180. /* BTA_HL_CI_GET_ECHO_DATA_EVT */ {BTA_HL_DCH_CI_GET_ECHO_DATA,
  181. BTA_HL_DCH_OPENING_ST},
  182. /* BTA_HL_DCH_ECHO_TEST_EVT */ {BTA_HL_DCH_ECHO_TEST,
  183. BTA_HL_DCH_OPENING_ST},
  184. /* BTA_HL_CI_PUT_ECHO_DATA_EVT */ {BTA_HL_DCH_IGNORE,
  185. BTA_HL_DCH_OPENING_ST}};
  186. /* state table for open state */
  187. static const uint8_t bta_hl_dch_st_open[][BTA_HL_DCH_NUM_COLS] = {
  188. /* Event Action 1 Next
  189. state */
  190. /* BTA_HL_DCH_SDP_INIT_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST},
  191. /* BTA_HL_DCH_OPEN_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST},
  192. /* BTA_HL_MCA_CREATE_IND_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST},
  193. /* BTA_HL_MCA_CREATE_CFM_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST},
  194. /* BTA_HL_MCA_OPEN_IND_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST},
  195. /* BTA_HL_MCA_OPEN_CFM_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST},
  196. /* BTA_HL_DCH_CLOSE_EVT */ {BTA_HL_DCH_MCA_CLOSE,
  197. BTA_HL_DCH_CLOSING_ST},
  198. /* BTA_HL_MCA_CLOSE_IND_EVT */ {BTA_HL_DCH_MCA_CLOSE_IND,
  199. BTA_HL_DCH_CLOSING_ST},
  200. /* BTA_HL_MCA_CLOSE_CFM_EVT */ {BTA_HL_DCH_MCA_CLOSE_CFM,
  201. BTA_HL_DCH_CLOSING_ST},
  202. /* BTA_HL_API_SEND_DATA_EVT */ {BTA_HL_DCH_SEND_DATA, BTA_HL_DCH_OPEN_ST},
  203. /* BTA_HL_MCA_RCV_DATA_EVT */ {BTA_HL_DCH_MCA_RCV_DATA,
  204. BTA_HL_DCH_OPEN_ST},
  205. /* BTA_HL_DCH_CLOSE_CMPL_EVT */ {BTA_HL_DCH_CLOSE_CMPL, BTA_HL_DCH_IDLE_ST},
  206. /* BTA_HL_DCH_RECONNECT_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST},
  207. /* BTA_HL_DCH_SDP_FAIL_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST},
  208. /* BTA_HL_MCA_RECONNECT_IND_EVT*/ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST},
  209. /* BTA_HL_MCA_RECONNECT_CFM_EVT*/ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST},
  210. /* BTA_HL_DCH_CLOSE_ECHO_TEST_EVT*/ {BTA_HL_DCH_CLOSE_ECHO_TEST,
  211. BTA_HL_DCH_CLOSING_ST},
  212. /* BTA_HL_API_DCH_CREATE_RSP_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST},
  213. /* BTA_HL_DCH_ABORT_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST},
  214. /* BTA_HL_MCA_ABORT_IND_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST},
  215. /* BTA_HL_DCH_ABORT_CFM_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST},
  216. /* BTA_HL_MCA_CONG_CHG_EVT */ {BTA_HL_DCH_MCA_CONG_CHANGE,
  217. BTA_HL_DCH_OPEN_ST},
  218. /* BTA_HL_CI_GET_TX_DATA_EVT */ {BTA_HL_DCH_CI_GET_TX_DATA,
  219. BTA_HL_DCH_OPEN_ST},
  220. /* BTA_HL_CI_PUT_RX_DATA_EVT */ {BTA_HL_DCH_CI_PUT_RX_DATA,
  221. BTA_HL_DCH_OPEN_ST},
  222. /* BTA_HL_CI_GET_ECHO_DATA_EVT */ {BTA_HL_DCH_CI_GET_ECHO_DATA,
  223. BTA_HL_DCH_OPEN_ST},
  224. /* BTA_HL_DCH_ECHO_TEST_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST},
  225. /* BTA_HL_CI_PUT_ECHO_DATA_EVT */ {BTA_HL_DCH_CI_PUT_ECHO_DATA,
  226. BTA_HL_DCH_OPEN_ST}};
  227. /* state table for closing state */
  228. static const uint8_t bta_hl_dch_st_closing[][BTA_HL_DCH_NUM_COLS] = {
  229. /* Event Action 1 Next state */
  230. /* BTA_HL_DCH_SDP_INIT_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST},
  231. /* BTA_HL_DCH_OPEN_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST},
  232. /* BTA_HL_MCA_CREATE_IND_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST},
  233. /* BTA_HL_MCA_CREATE_CFM_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST},
  234. /* BTA_HL_MCA_OPEN_IND_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST},
  235. /* BTA_HL_MCA_OPEN_CFM_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST},
  236. /* BTA_HL_DCH_CLOSE_EVT */ {BTA_HL_DCH_MCA_CLOSE,
  237. BTA_HL_DCH_CLOSING_ST},
  238. /* BTA_HL_MCA_CLOSE_IND_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST},
  239. /* BTA_HL_MCA_CLOSE_CFM_EVT */ {BTA_HL_DCH_MCA_CLOSE_CFM,
  240. BTA_HL_DCH_CLOSING_ST},
  241. /* BTA_HL_API_SEND_DATA_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST},
  242. /* BTA_HL_MCA_RCV_DATA_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST},
  243. /* BTA_HL_DCH_CLOSE_CMPL_EVT */ {BTA_HL_DCH_CLOSE_CMPL, BTA_HL_DCH_IDLE_ST},
  244. /* BTA_HL_DCH_RECONNECT_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST},
  245. /* BTA_HL_DCH_SDP_FAIL_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST},
  246. /* BTA_HL_MCA_RECONNECT_IND_EVT*/ {BTA_HL_DCH_IGNORE,
  247. BTA_HL_DCH_CLOSING_ST},
  248. /* BTA_HL_MCA_RECONNECT_CFM_EVT*/ {BTA_HL_DCH_IGNORE,
  249. BTA_HL_DCH_CLOSING_ST},
  250. /* BTA_HL_DCH_CLOSE_ECHO_TEST_EVT*/ {BTA_HL_DCH_IGNORE,
  251. BTA_HL_DCH_CLOSING_ST},
  252. /* BTA_HL_API_DCH_CREATE_RSP_EVT */ {BTA_HL_DCH_IGNORE,
  253. BTA_HL_DCH_CLOSING_ST},
  254. /* BTA_HL_DCH_ABORT_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST},
  255. /* BTA_HL_MCA_ABORT_IND_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST},
  256. /* BTA_HL_DCH_ABORT_CFM_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST},
  257. /* BTA_HL_MCA_CONG_CHG_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST},
  258. /* BTA_HL_CI_GET_TX_DATA_EVT */ {BTA_HL_DCH_CI_GET_TX_DATA,
  259. BTA_HL_DCH_CLOSING_ST},
  260. /* BTA_HL_CI_PUT_RX_DATA_EVT */ {BTA_HL_DCH_CI_PUT_RX_DATA,
  261. BTA_HL_DCH_CLOSING_ST},
  262. /* BTA_HL_CI_GET_ECHO_DATA_EVT */ {BTA_HL_DCH_CI_GET_ECHO_DATA,
  263. BTA_HL_DCH_CLOSING_ST},
  264. /* BTA_HL_DCH_ECHO_TEST_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST},
  265. /* BTA_HL_CI_PUT_ECHO_DATA_EVT */ {BTA_HL_DCH_CI_PUT_ECHO_DATA,
  266. BTA_HL_DCH_CLOSING_ST}};
  267. /* type for state table */
  268. typedef const uint8_t (*tBTA_HL_DCH_ST_TBL)[BTA_HL_DCH_NUM_COLS];
  269. /* state table */
  270. const tBTA_HL_DCH_ST_TBL bta_hl_dch_st_tbl[] = {
  271. bta_hl_dch_st_idle, bta_hl_dch_st_opening, bta_hl_dch_st_open,
  272. bta_hl_dch_st_closing};
  273. /*****************************************************************************
  274. * CCH State Table
  275. ****************************************************************************/
  276. /*****************************************************************************
  277. * Constants and types
  278. ****************************************************************************/
  279. /* state machine action enumeration list for CCH */
  280. enum {
  281. BTA_HL_CCH_SDP_INIT,
  282. BTA_HL_CCH_MCA_OPEN,
  283. BTA_HL_CCH_MCA_CLOSE,
  284. BTA_HL_CCH_CLOSE_CMPL,
  285. BTA_HL_CCH_MCA_CONNECT,
  286. BTA_HL_CCH_MCA_DISCONNECT,
  287. BTA_HL_CCH_MCA_RSP_TOUT,
  288. BTA_HL_CCH_MCA_DISC_OPEN,
  289. BTA_HL_CCH_IGNORE
  290. };
  291. /* type for action functions */
  292. typedef void (*tBTA_HL_CCH_ACTION)(uint8_t app_idx, uint8_t mcl_idx,
  293. tBTA_HL_DATA* p_data);
  294. /* action function list for MAS */
  295. const tBTA_HL_CCH_ACTION bta_hl_cch_action[] = {
  296. bta_hl_cch_sdp_init, bta_hl_cch_mca_open, bta_hl_cch_mca_close,
  297. bta_hl_cch_close_cmpl, bta_hl_cch_mca_connect, bta_hl_cch_mca_disconnect,
  298. bta_hl_cch_mca_rsp_tout, bta_hl_cch_mca_disc_open};
  299. /* state table information */
  300. #define BTA_HL_CCH_ACTIONS 1 /* number of actions */
  301. #define BTA_HL_CCH_NEXT_STATE 1 /* position of next state */
  302. #define BTA_HL_CCH_NUM_COLS 2 /* number of columns in state tables */
  303. /* state table for MAS idle state */
  304. static const uint8_t bta_hl_cch_st_idle[][BTA_HL_CCH_NUM_COLS] = {
  305. /* Event Action 1 Next state */
  306. /* BTA_HL_CCH_OPEN_EVT */ {BTA_HL_CCH_SDP_INIT,
  307. BTA_HL_CCH_OPENING_ST},
  308. /* BTA_HL_CCH_SDP_OK_EVT */ {BTA_HL_CCH_IGNORE, BTA_HL_CCH_IDLE_ST},
  309. /* BTA_HL_CCH_SDP_FAIL_EVT */ {BTA_HL_CCH_IGNORE, BTA_HL_CCH_IDLE_ST},
  310. /* BTA_HL_MCA_CONNECT_IND_EVT */ {BTA_HL_CCH_MCA_CONNECT,
  311. BTA_HL_CCH_OPEN_ST},
  312. /* BTA_HL_MCA_DISCONNECT_IND_EVT */ {BTA_HL_CCH_IGNORE, BTA_HL_CCH_IDLE_ST},
  313. /* BTA_HL_CCH_CLOSE_EVT */ {BTA_HL_CCH_IGNORE, BTA_HL_CCH_IDLE_ST},
  314. /* BTA_HL_CCH_CLOSE_CMPL_EVT */ {BTA_HL_CCH_IGNORE, BTA_HL_CCH_IDLE_ST},
  315. /* BTA_HL_CCH_CLOSE_CMPL_EVT */ {BTA_HL_CCH_IGNORE,
  316. BTA_HL_CCH_IDLE_ST}};
  317. /* state table for obex/rfcomm connection state */
  318. static const uint8_t bta_hl_cch_st_opening[][BTA_HL_CCH_NUM_COLS] = {
  319. /* Event Action 1 Next state */
  320. /* BTA_HL_CCH_OPEN_EVT */ {BTA_HL_CCH_IGNORE,
  321. BTA_HL_CCH_OPENING_ST},
  322. /* BTA_HL_CCH_SDP_OK_EVT */ {BTA_HL_CCH_MCA_OPEN,
  323. BTA_HL_CCH_OPENING_ST},
  324. /* BTA_HL_CCH_SDP_FAIL_EVT */ {BTA_HL_CCH_CLOSE_CMPL,
  325. BTA_HL_CCH_IDLE_ST},
  326. /* BTA_HL_MCA_CONNECT_IND_EVT */ {BTA_HL_CCH_MCA_CONNECT,
  327. BTA_HL_CCH_OPEN_ST},
  328. /* BTA_HL_MCA_DISCONNECT_IND_EVT */ {BTA_HL_CCH_MCA_DISCONNECT,
  329. BTA_HL_CCH_CLOSING_ST},
  330. /* BTA_HL_CCH_CLOSE_EVT */ {BTA_HL_CCH_MCA_CLOSE,
  331. BTA_HL_CCH_CLOSING_ST},
  332. /* BTA_HL_CCH_CLOSE_CMPL_EVT */ {BTA_HL_CCH_CLOSE_CMPL,
  333. BTA_HL_CCH_IDLE_ST},
  334. /* BTA_HL_MCA_RSP_TOUT_IND_EVT */ {BTA_HL_CCH_MCA_RSP_TOUT,
  335. BTA_HL_CCH_CLOSING_ST}};
  336. /* state table for open state */
  337. static const uint8_t bta_hl_cch_st_open[][BTA_HL_CCH_NUM_COLS] = {
  338. /* Event Action 1 Next state */
  339. /* BTA_HL_CCH_OPEN_EVT */ {BTA_HL_CCH_IGNORE, BTA_HL_CCH_OPEN_ST},
  340. /* BTA_HL_CCH_SDP_OK_EVT */ {BTA_HL_CCH_IGNORE, BTA_HL_CCH_OPEN_ST},
  341. /* BTA_HL_CCH_SDP_FAIL_EVT */ {BTA_HL_CCH_IGNORE, BTA_HL_CCH_OPEN_ST},
  342. /* BTA_HL_MCA_CONNECT_IND_EVT */ {BTA_HL_CCH_IGNORE, BTA_HL_CCH_OPEN_ST},
  343. /* BTA_HL_MCA_DISCONNECT_IND_EVT */ {BTA_HL_CCH_MCA_DISCONNECT,
  344. BTA_HL_CCH_CLOSING_ST},
  345. /* BTA_HL_CCH_CLOSE_EVT */ {BTA_HL_CCH_MCA_CLOSE,
  346. BTA_HL_CCH_CLOSING_ST},
  347. /* BTA_HL_CCH_CLOSE_CMPL_EVT */ {BTA_HL_CCH_IGNORE, BTA_HL_CCH_OPEN_ST},
  348. /* BTA_HL_MCA_RSP_TOUT_IND_EVT */ {BTA_HL_CCH_MCA_RSP_TOUT,
  349. BTA_HL_CCH_CLOSING_ST}};
  350. /* state table for closing state */
  351. static const uint8_t bta_hl_cch_st_closing[][BTA_HL_CCH_NUM_COLS] = {
  352. /* Event Action 1 Next state */
  353. /* BTA_HL_CCH_OPEN_EVT */ {BTA_HL_CCH_IGNORE,
  354. BTA_HL_CCH_CLOSING_ST},
  355. /* BTA_HL_CCH_SDP_OK_EVT */ {BTA_HL_CCH_CLOSE_CMPL,
  356. BTA_HL_CCH_IDLE_ST},
  357. /* BTA_HL_CCH_SDP_FAIL_EVT */ {BTA_HL_CCH_CLOSE_CMPL,
  358. BTA_HL_CCH_IDLE_ST},
  359. /* BTA_HL_MCA_CONNECT_IND_EVT */ {BTA_HL_CCH_MCA_DISC_OPEN,
  360. BTA_HL_CCH_CLOSING_ST},
  361. /* BTA_HL_MCA_DISCONNECT_IND_EVT */ {BTA_HL_CCH_MCA_DISCONNECT,
  362. BTA_HL_CCH_CLOSING_ST},
  363. /* BTA_HL_CCH_CLOSE_EVT */ {BTA_HL_CCH_MCA_CLOSE,
  364. BTA_HL_CCH_CLOSING_ST},
  365. /* BTA_HL_CCH_CLOSE_CMPL_EVT */ {BTA_HL_CCH_CLOSE_CMPL,
  366. BTA_HL_CCH_IDLE_ST},
  367. /* BTA_HL_MCA_RSP_TOUT_IND_EVT */ {BTA_HL_CCH_IGNORE,
  368. BTA_HL_CCH_CLOSING_ST}};
  369. /* type for state table CCH */
  370. typedef const uint8_t (*tBTA_HL_CCH_ST_TBL)[BTA_HL_CCH_NUM_COLS];
  371. /* MAS state table */
  372. const tBTA_HL_CCH_ST_TBL bta_hl_cch_st_tbl[] = {
  373. bta_hl_cch_st_idle, bta_hl_cch_st_opening, bta_hl_cch_st_open,
  374. bta_hl_cch_st_closing};
  375. /*****************************************************************************
  376. * Global data
  377. ****************************************************************************/
  378. /* HL control block */
  379. tBTA_HL_CB bta_hl_cb;
  380. /*******************************************************************************
  381. *
  382. * Function bta_hl_cch_sm_execute
  383. *
  384. * Description State machine event handling function for CCH
  385. *
  386. * Returns void
  387. *
  388. ******************************************************************************/
  389. void bta_hl_cch_sm_execute(uint8_t app_idx, uint8_t mcl_idx, uint16_t event,
  390. tBTA_HL_DATA* p_data) {
  391. tBTA_HL_CCH_ST_TBL state_table;
  392. uint8_t action;
  393. int i;
  394. tBTA_HL_MCL_CB* p_cb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
  395. #if (BTA_HL_DEBUG == TRUE)
  396. tBTA_HL_CCH_STATE in_state = p_cb->cch_state;
  397. uint16_t cur_evt = event;
  398. APPL_TRACE_DEBUG("HDP CCH Event Handler: State 0x%02x [%s], Event [%s]",
  399. in_state, bta_hl_cch_state_code(in_state),
  400. bta_hl_evt_code(cur_evt));
  401. #endif
  402. /* look up the state table for the current state */
  403. state_table = bta_hl_cch_st_tbl[p_cb->cch_state];
  404. event &= 0x00FF;
  405. /* set next state */
  406. p_cb->cch_state = state_table[event][BTA_HL_CCH_NEXT_STATE];
  407. for (i = 0; i < BTA_HL_CCH_ACTIONS; i++) {
  408. action = state_table[event][i];
  409. if (action != BTA_HL_CCH_IGNORE) {
  410. (*bta_hl_cch_action[action])(app_idx, mcl_idx, p_data);
  411. } else {
  412. /* discard HDP data */
  413. bta_hl_discard_data(p_data->hdr.event, p_data);
  414. break;
  415. }
  416. }
  417. #if (BTA_HL_DEBUG == TRUE)
  418. if (in_state != p_cb->cch_state) {
  419. APPL_TRACE_DEBUG("HL CCH State Change: [%s] -> [%s] after [%s]",
  420. bta_hl_cch_state_code(in_state),
  421. bta_hl_cch_state_code(p_cb->cch_state),
  422. bta_hl_evt_code(cur_evt));
  423. }
  424. #endif
  425. }
  426. /*******************************************************************************
  427. *
  428. * Function bta_hl_dch_sm_execute
  429. *
  430. * Description State machine event handling function for DCH
  431. *
  432. * Returns void
  433. *
  434. ******************************************************************************/
  435. void bta_hl_dch_sm_execute(uint8_t app_idx, uint8_t mcl_idx, uint8_t mdl_idx,
  436. uint16_t event, tBTA_HL_DATA* p_data) {
  437. tBTA_HL_DCH_ST_TBL state_table;
  438. uint8_t action;
  439. int i;
  440. tBTA_HL_MDL_CB* p_cb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
  441. #if (BTA_HL_DEBUG == TRUE)
  442. tBTA_HL_DCH_STATE in_state = p_cb->dch_state;
  443. uint16_t cur_evt = event;
  444. APPL_TRACE_DEBUG("HDP DCH Event Handler: State 0x%02x [%s], Event [%s]",
  445. in_state, bta_hl_dch_state_code(in_state),
  446. bta_hl_evt_code(cur_evt));
  447. #endif
  448. /* look up the state table for the current state */
  449. state_table = bta_hl_dch_st_tbl[p_cb->dch_state];
  450. event -= BTA_HL_DCH_EVT_MIN;
  451. /* set next state */
  452. p_cb->dch_state = state_table[event][BTA_HL_DCH_NEXT_STATE];
  453. for (i = 0; i < BTA_HL_DCH_ACTIONS; i++) {
  454. action = state_table[event][i];
  455. if (action != BTA_HL_DCH_IGNORE) {
  456. (*bta_hl_dch_action[action])(app_idx, mcl_idx, mdl_idx, p_data);
  457. } else {
  458. /* discard mas data */
  459. bta_hl_discard_data(p_data->hdr.event, p_data);
  460. break;
  461. }
  462. }
  463. #if (BTA_HL_DEBUG == TRUE)
  464. if (in_state != p_cb->dch_state) {
  465. APPL_TRACE_DEBUG("HL DCH State Change: [%s] -> [%s] after [%s]",
  466. bta_hl_dch_state_code(in_state),
  467. bta_hl_dch_state_code(p_cb->dch_state),
  468. bta_hl_evt_code(cur_evt));
  469. }
  470. #endif
  471. }
  472. /*******************************************************************************
  473. *
  474. * Function bta_hl_api_enable
  475. *
  476. * Description Process the API enable request to enable the HL subsystem
  477. *
  478. * Returns void
  479. *
  480. ******************************************************************************/
  481. static void bta_hl_api_enable(tBTA_HL_CB* p_cb, tBTA_HL_DATA* p_data) {
  482. tBTA_HL_CTRL evt_data;
  483. /* If already enabled then reject this request */
  484. if (p_cb->enable) {
  485. APPL_TRACE_ERROR("HL is already enabled");
  486. evt_data.enable_cfm.status = BTA_HL_STATUS_FAIL;
  487. if (p_data->api_enable.p_cback)
  488. p_data->api_enable.p_cback(BTA_HL_CTRL_ENABLE_CFM_EVT,
  489. (tBTA_HL_CTRL*)&evt_data);
  490. return;
  491. }
  492. /* Done with checking. now perform the enable oepration*/
  493. /* initialize control block */
  494. memset(p_cb, 0, sizeof(tBTA_HL_CB));
  495. p_cb->enable = true;
  496. p_cb->p_ctrl_cback = p_data->api_enable.p_cback;
  497. evt_data.enable_cfm.status = BTA_HL_STATUS_OK;
  498. if (p_data->api_enable.p_cback)
  499. p_data->api_enable.p_cback(BTA_HL_CTRL_ENABLE_CFM_EVT,
  500. (tBTA_HL_CTRL*)&evt_data);
  501. }
  502. /*******************************************************************************
  503. *
  504. * Function bta_hl_api_disable
  505. *
  506. * Description Process the API disable request to disable the HL subsystem
  507. *
  508. * Returns void
  509. *
  510. ******************************************************************************/
  511. static void bta_hl_api_disable(tBTA_HL_CB* p_cb, tBTA_HL_DATA* p_data) {
  512. tBTA_HL_CTRL evt_data;
  513. tBTA_HL_STATUS status = BTA_HL_STATUS_OK;
  514. if (p_cb->enable) {
  515. p_cb->disabling = true;
  516. bta_hl_check_disable(p_data);
  517. } else {
  518. status = BTA_HL_STATUS_FAIL;
  519. evt_data.disable_cfm.status = status;
  520. if (p_cb->p_ctrl_cback)
  521. p_cb->p_ctrl_cback(BTA_HL_CTRL_DISABLE_CFM_EVT, (tBTA_HL_CTRL*)&evt_data);
  522. }
  523. #if (BTA_HL_DEBUG == TRUE)
  524. if (status != BTA_HL_STATUS_OK) {
  525. APPL_TRACE_DEBUG("bta_hl_api_disable status =%s",
  526. bta_hl_status_code(status));
  527. }
  528. #endif
  529. }
  530. /*******************************************************************************
  531. *
  532. * Function bta_hl_api_update
  533. *
  534. * Description Process the API registration request to register an HDP
  535. * application
  536. *
  537. * Returns void
  538. *
  539. ******************************************************************************/
  540. static void bta_hl_api_update(tBTA_HL_CB* p_cb, tBTA_HL_DATA* p_data) {
  541. tBTA_HL evt_data;
  542. tBTA_HL_APP_CB* p_acb = BTA_HL_GET_APP_CB_PTR(0);
  543. tBTA_HL_STATUS status = BTA_HL_STATUS_FAIL;
  544. APPL_TRACE_DEBUG("bta_hl_api_update");
  545. if (p_cb->enable) {
  546. status = bta_hl_app_update(p_data->api_update.app_id,
  547. p_data->api_update.is_register);
  548. if (!p_data->api_update.is_register) {
  549. APPL_TRACE_DEBUG("Deregister");
  550. memset(&evt_data, 0, sizeof(tBTA_HL));
  551. evt_data.dereg_cfm.status = status;
  552. evt_data.dereg_cfm.app_id = p_data->api_update.app_id;
  553. if (status == BTA_HL_STATUS_OK)
  554. evt_data.dereg_cfm.app_handle = p_acb->app_handle;
  555. if (p_acb->p_cback) {
  556. p_acb->p_cback(BTA_HL_DEREGISTER_CFM_EVT, (tBTA_HL*)&evt_data);
  557. }
  558. return;
  559. }
  560. }
  561. if (status != BTA_HL_STATUS_OK) {
  562. if ((status != BTA_HL_STATUS_DUPLICATE_APP_ID) &&
  563. (status != BTA_HL_STATUS_NO_RESOURCE)) {
  564. if (p_acb) memset(p_acb, 0, sizeof(tBTA_HL_APP_CB));
  565. }
  566. }
  567. #if (BTA_HL_DEBUG == TRUE)
  568. if (status != BTA_HL_STATUS_OK) {
  569. APPL_TRACE_DEBUG("bta_hl_api_register status =%s",
  570. bta_hl_status_code(status));
  571. }
  572. #endif
  573. memset(&evt_data, 0, sizeof(tBTA_HL));
  574. evt_data.reg_cfm.status = status;
  575. evt_data.reg_cfm.app_id = p_data->api_update.app_id;
  576. if (status == BTA_HL_STATUS_OK)
  577. evt_data.reg_cfm.app_handle = p_acb->app_handle;
  578. if (p_data->api_reg.p_cback) {
  579. p_data->api_reg.p_cback(BTA_HL_REGISTER_CFM_EVT, (tBTA_HL*)&evt_data);
  580. }
  581. if (status == BTA_HL_STATUS_OK) {
  582. evt_data.sdp_info_ind.app_handle = p_acb->app_handle;
  583. evt_data.sdp_info_ind.ctrl_psm = p_acb->ctrl_psm;
  584. evt_data.sdp_info_ind.data_psm = p_acb->data_psm;
  585. evt_data.sdp_info_ind.data_x_spec = BTA_HL_SDP_IEEE_11073_20601;
  586. evt_data.sdp_info_ind.mcap_sup_procs = BTA_HL_MCAP_SUP_PROC_MASK;
  587. if (p_data->api_reg.p_cback) {
  588. p_data->api_reg.p_cback(BTA_HL_SDP_INFO_IND_EVT, (tBTA_HL*)&evt_data);
  589. }
  590. }
  591. }
  592. /*******************************************************************************
  593. *
  594. * Function bta_hl_api_register
  595. *
  596. * Description Process the API registration request to register an HDP
  597. * application
  598. *
  599. * Returns void
  600. *
  601. ******************************************************************************/
  602. static void bta_hl_api_register(tBTA_HL_CB* p_cb, tBTA_HL_DATA* p_data) {
  603. tBTA_HL evt_data;
  604. uint8_t app_idx;
  605. tBTA_HL_APP_CB* p_acb = NULL;
  606. tBTA_HL_STATUS status = BTA_HL_STATUS_FAIL;
  607. if (p_cb->enable) {
  608. if (!bta_hl_is_a_duplicate_id(p_data->api_reg.app_id)) {
  609. if (bta_hl_find_avail_app_idx(&app_idx)) {
  610. p_acb = BTA_HL_GET_APP_CB_PTR(app_idx);
  611. p_acb->in_use = true;
  612. p_acb->app_id = p_data->api_reg.app_id;
  613. p_acb->p_cback = p_data->api_reg.p_cback;
  614. p_acb->sec_mask = p_data->api_reg.sec_mask;
  615. p_acb->dev_type = p_data->api_reg.dev_type;
  616. strlcpy(p_acb->srv_name, p_data->api_reg.srv_name,
  617. sizeof(p_acb->srv_name));
  618. strlcpy(p_acb->srv_desp, p_data->api_reg.srv_desp,
  619. sizeof(p_acb->srv_desp));
  620. strlcpy(p_acb->provider_name, p_data->api_reg.provider_name,
  621. sizeof(p_acb->provider_name));
  622. bta_hl_cb.p_alloc_psm = L2CA_AllocatePSM;
  623. p_acb->ctrl_psm = bta_hl_cb.p_alloc_psm();
  624. p_acb->data_psm = bta_hl_cb.p_alloc_psm();
  625. p_acb->p_mcap_cback = bta_hl_mcap_ctrl_cback;
  626. status = bta_hl_app_registration(app_idx);
  627. } else {
  628. status = BTA_HL_STATUS_NO_RESOURCE;
  629. }
  630. } else {
  631. status = BTA_HL_STATUS_DUPLICATE_APP_ID;
  632. }
  633. }
  634. if (status != BTA_HL_STATUS_OK) {
  635. if ((status != BTA_HL_STATUS_DUPLICATE_APP_ID) &&
  636. (status != BTA_HL_STATUS_NO_RESOURCE)) {
  637. if (p_acb) memset(p_acb, 0, sizeof(tBTA_HL_APP_CB));
  638. }
  639. }
  640. #if (BTA_HL_DEBUG == TRUE)
  641. if (status != BTA_HL_STATUS_OK) {
  642. APPL_TRACE_DEBUG("bta_hl_api_register status =%s",
  643. bta_hl_status_code(status));
  644. }
  645. #endif
  646. memset(&evt_data, 0, sizeof(tBTA_HL));
  647. evt_data.reg_cfm.status = status;
  648. evt_data.reg_cfm.app_id = p_data->api_reg.app_id;
  649. if (status == BTA_HL_STATUS_OK)
  650. evt_data.reg_cfm.app_handle = p_acb->app_handle;
  651. if (p_data->api_reg.p_cback) {
  652. p_data->api_reg.p_cback(BTA_HL_REGISTER_CFM_EVT, (tBTA_HL*)&evt_data);
  653. }
  654. if (status == BTA_HL_STATUS_OK) {
  655. evt_data.sdp_info_ind.app_handle = p_acb->app_handle;
  656. evt_data.sdp_info_ind.ctrl_psm = p_acb->ctrl_psm;
  657. evt_data.sdp_info_ind.data_psm = p_acb->data_psm;
  658. evt_data.sdp_info_ind.data_x_spec = BTA_HL_SDP_IEEE_11073_20601;
  659. evt_data.sdp_info_ind.mcap_sup_procs = BTA_HL_MCAP_SUP_PROC_MASK;
  660. if (p_data->api_reg.p_cback) {
  661. p_data->api_reg.p_cback(BTA_HL_SDP_INFO_IND_EVT, (tBTA_HL*)&evt_data);
  662. }
  663. }
  664. }
  665. /*******************************************************************************
  666. *
  667. * Function bta_hl_api_deregister
  668. *
  669. * Description Process the API de-registration request
  670. *
  671. * Returns void
  672. *
  673. ******************************************************************************/
  674. static void bta_hl_api_deregister(UNUSED_ATTR tBTA_HL_CB* p_cb,
  675. tBTA_HL_DATA* p_data) {
  676. uint8_t app_idx;
  677. tBTA_HL_APP_CB* p_acb;
  678. if (bta_hl_find_app_idx_using_handle(p_data->api_dereg.app_handle,
  679. &app_idx)) {
  680. p_acb = BTA_HL_GET_APP_CB_PTR(app_idx);
  681. p_acb->deregistering = true;
  682. bta_hl_check_deregistration(app_idx, p_data);
  683. } else {
  684. APPL_TRACE_ERROR("Invalid app_handle=%d", p_data->api_dereg.app_handle);
  685. }
  686. }
  687. /*******************************************************************************
  688. *
  689. * Function bta_hl_api_cch_open
  690. *
  691. * Description Process the API CCH open request
  692. *
  693. * Returns void
  694. *
  695. ******************************************************************************/
  696. static void bta_hl_api_cch_open(UNUSED_ATTR tBTA_HL_CB* p_cb,
  697. tBTA_HL_DATA* p_data) {
  698. tBTA_HL evt_data;
  699. tBTA_HL_STATUS status = BTA_HL_STATUS_OK;
  700. uint8_t app_idx, mcl_idx;
  701. tBTA_HL_APP_CB* p_acb;
  702. tBTA_HL_MCL_CB* p_mcb;
  703. if (bta_hl_find_app_idx_using_handle(p_data->api_cch_open.app_handle,
  704. &app_idx)) {
  705. if (!bta_hl_find_mcl_idx(app_idx, p_data->api_cch_open.bd_addr, &mcl_idx)) {
  706. if (bta_hl_find_avail_mcl_idx(app_idx, &mcl_idx)) {
  707. p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
  708. p_mcb->in_use = true;
  709. p_mcb->req_ctrl_psm = p_data->api_cch_open.ctrl_psm;
  710. p_mcb->sec_mask = p_data->api_cch_open.sec_mask;
  711. p_mcb->bd_addr = p_data->api_cch_open.bd_addr;
  712. p_mcb->cch_oper = BTA_HL_CCH_OP_LOCAL_OPEN;
  713. } else {
  714. status = BTA_HL_STATUS_NO_RESOURCE;
  715. }
  716. } else {
  717. /* Only one MCL per BD_ADDR */
  718. status = BTA_HL_STATUS_DUPLICATE_CCH_OPEN;
  719. APPL_TRACE_DEBUG("bta_hl_api_cch_open: CCH already open: status =%d",
  720. status)
  721. p_acb = BTA_HL_GET_APP_CB_PTR(app_idx);
  722. p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
  723. if (p_acb->p_cback) {
  724. bta_hl_build_cch_open_cfm(&evt_data, p_data->api_cch_open.app_id,
  725. p_data->api_cch_open.app_handle,
  726. p_mcb->mcl_handle,
  727. p_data->api_cch_open.bd_addr, status);
  728. p_acb->p_cback(BTA_HL_CCH_OPEN_CFM_EVT, (tBTA_HL*)&evt_data);
  729. } else {
  730. APPL_TRACE_ERROR("bta_hl_api_cch_open Null Callback");
  731. }
  732. return;
  733. }
  734. } else {
  735. status = BTA_HL_STATUS_INVALID_APP_HANDLE;
  736. }
  737. #if (BTA_HL_DEBUG == TRUE)
  738. if (status != BTA_HL_STATUS_OK) {
  739. APPL_TRACE_DEBUG("bta_hl_api_cch_open status =%s",
  740. bta_hl_status_code(status));
  741. }
  742. #endif
  743. switch (status) {
  744. case BTA_HL_STATUS_OK:
  745. bta_hl_cch_sm_execute(app_idx, mcl_idx, BTA_HL_CCH_OPEN_EVT, p_data);
  746. break;
  747. case BTA_HL_STATUS_NO_RESOURCE:
  748. case BTA_HL_STATUS_FAIL:
  749. p_acb = BTA_HL_GET_APP_CB_PTR(app_idx);
  750. if (p_acb->p_cback) {
  751. bta_hl_build_cch_open_cfm(&evt_data, p_data->api_cch_open.app_id,
  752. p_data->api_cch_open.app_handle, 0,
  753. p_data->api_cch_open.bd_addr, status);
  754. p_acb->p_cback(BTA_HL_CCH_OPEN_CFM_EVT, (tBTA_HL*)&evt_data);
  755. } else {
  756. APPL_TRACE_ERROR("bta_hl_api_cch_open Null Callback");
  757. }
  758. break;
  759. default:
  760. APPL_TRACE_ERROR("status code=%d", status);
  761. break;
  762. }
  763. }
  764. /*******************************************************************************
  765. *
  766. * Function bta_hl_api_cch_close
  767. *
  768. * Description Process the API CCH close request
  769. *
  770. * Returns void
  771. *
  772. ******************************************************************************/
  773. static void bta_hl_api_cch_close(UNUSED_ATTR tBTA_HL_CB* p_cb,
  774. tBTA_HL_DATA* p_data) {
  775. tBTA_HL evt_data;
  776. tBTA_HL_STATUS status = BTA_HL_STATUS_OK;
  777. uint8_t app_idx, mcl_idx;
  778. tBTA_HL_APP_CB* p_acb;
  779. tBTA_HL_MCL_CB* p_mcb;
  780. if (bta_hl_find_mcl_idx_using_handle(p_data->api_cch_close.mcl_handle,
  781. &app_idx, &mcl_idx)) {
  782. p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
  783. p_mcb->cch_oper = BTA_HL_CCH_OP_LOCAL_CLOSE;
  784. } else {
  785. status = BTA_HL_STATUS_INVALID_MCL_HANDLE;
  786. }
  787. #if (BTA_HL_DEBUG == TRUE)
  788. if (status != BTA_HL_STATUS_OK) {
  789. APPL_TRACE_DEBUG("bta_hl_api_cch_close status =%s",
  790. bta_hl_status_code(status));
  791. }
  792. #endif
  793. switch (status) {
  794. case BTA_HL_STATUS_OK:
  795. bta_hl_check_cch_close(app_idx, mcl_idx, p_data, true);
  796. break;
  797. case BTA_HL_STATUS_INVALID_MCL_HANDLE:
  798. p_acb = BTA_HL_GET_APP_CB_PTR(app_idx);
  799. if (p_acb->p_cback) {
  800. bta_hl_build_cch_close_cfm(&evt_data, p_acb->app_handle,
  801. p_data->api_cch_close.mcl_handle, status);
  802. p_acb->p_cback(BTA_HL_CCH_CLOSE_CFM_EVT, (tBTA_HL*)&evt_data);
  803. } else {
  804. APPL_TRACE_ERROR("bta_hl_api_cch_close Null Callback");
  805. }
  806. break;
  807. default:
  808. APPL_TRACE_ERROR("status code=%d", status);
  809. break;
  810. }
  811. }
  812. /*******************************************************************************
  813. *
  814. * Function bta_hl_api_dch_open
  815. *
  816. * Description Process the API DCH open request
  817. *
  818. * Returns void
  819. *
  820. ******************************************************************************/
  821. static void bta_hl_api_dch_open(UNUSED_ATTR tBTA_HL_CB* p_cb,
  822. tBTA_HL_DATA* p_data) {
  823. tBTA_HL evt_data;
  824. tBTA_HL_STATUS status = BTA_HL_STATUS_OK;
  825. uint8_t app_idx, mcl_idx, mdl_idx;
  826. tBTA_HL_APP_CB* p_acb;
  827. tBTA_HL_MCL_CB* p_mcb = NULL;
  828. tBTA_HL_MDL_CB* p_dcb;
  829. tBTA_HL_MDEP_CFG* p_mdep_cfg;
  830. uint8_t mdep_cfg_idx;
  831. if (bta_hl_find_mcl_idx_using_handle(p_data->api_dch_open.mcl_handle,
  832. &app_idx, &mcl_idx)) {
  833. p_acb = BTA_HL_GET_APP_CB_PTR(app_idx);
  834. p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
  835. APPL_TRACE_DEBUG(
  836. "bta_hl_api_dch_open: app_ix=%d, mcl_idx=%d, cch_state=%d, "
  837. "mcl_handle=%d",
  838. app_idx, mcl_idx, p_mcb->cch_state, p_data->api_dch_open.mcl_handle);
  839. if (p_mcb->cch_state == BTA_HL_CCH_OPEN_ST) {
  840. if (bta_hl_find_avail_mdl_idx(app_idx, mcl_idx, &mdl_idx)) {
  841. p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
  842. if (bta_hl_find_mdep_cfg_idx(
  843. app_idx, p_data->api_dch_open.local_mdep_id, &mdep_cfg_idx)) {
  844. if (mdep_cfg_idx &&
  845. (p_acb->sup_feature.mdep[mdep_cfg_idx].mdep_cfg.mdep_role ==
  846. BTA_HL_MDEP_ROLE_SINK)) {
  847. p_data->api_dch_open.local_cfg = BTA_HL_DCH_CFG_NO_PREF;
  848. }
  849. status = bta_hl_chk_local_cfg(app_idx, mcl_idx, mdep_cfg_idx,
  850. p_data->api_dch_open.local_cfg);
  851. if (status == BTA_HL_STATUS_OK) {
  852. if (p_data->api_dch_open.local_mdep_id !=
  853. BTA_HL_ECHO_TEST_MDEP_ID) {
  854. if (bta_hl_set_ctrl_psm_for_dch(app_idx, mcl_idx, mdl_idx,
  855. p_data->api_dch_open.ctrl_psm)) {
  856. p_mdep_cfg = BTA_HL_GET_MDEP_CFG_PTR(app_idx, mdep_cfg_idx);
  857. p_dcb->in_use = true;
  858. p_dcb->dch_oper = BTA_HL_DCH_OP_LOCAL_OPEN;
  859. p_dcb->sec_mask = p_data->api_dch_open.sec_mask;
  860. p_dcb->local_mdep_id = p_data->api_dch_open.local_mdep_id;
  861. p_dcb->peer_mdep_id = p_data->api_dch_open.peer_mdep_id;
  862. if (p_mdep_cfg->mdep_role == BTA_HL_MDEP_ROLE_SINK) {
  863. p_dcb->peer_mdep_role = BTA_HL_MDEP_ROLE_SOURCE;
  864. } else {
  865. p_dcb->peer_mdep_role = BTA_HL_MDEP_ROLE_SINK;
  866. }
  867. p_dcb->local_mdep_cfg_idx = mdep_cfg_idx;
  868. p_dcb->local_cfg = p_data->api_dch_open.local_cfg;
  869. bta_hl_find_rxtx_apdu_size(app_idx, mdep_cfg_idx,
  870. &p_dcb->max_rx_apdu_size,
  871. &p_dcb->max_tx_apdu_size);
  872. p_dcb->mdl_id =
  873. bta_hl_allocate_mdl_id(app_idx, mcl_idx, mdl_idx);
  874. p_dcb->mdl_cfg_idx_included = false;
  875. } else {
  876. status = BTA_HL_STATUS_INVALID_CTRL_PSM;
  877. }
  878. } else {
  879. status = BTA_HL_STATUS_INVALID_LOCAL_MDEP_ID;
  880. }
  881. }
  882. } else {
  883. status = BTA_HL_STATUS_INVALID_LOCAL_MDEP_ID;
  884. }
  885. } else {
  886. status = BTA_HL_STATUS_NO_RESOURCE;
  887. }
  888. } else {
  889. status = BTA_HL_STATUS_NO_CCH;
  890. }
  891. } else {
  892. status = BTA_HL_STATUS_INVALID_MCL_HANDLE;
  893. }
  894. #if (BTA_HL_DEBUG == TRUE)
  895. if (status != BTA_HL_STATUS_OK) {
  896. APPL_TRACE_DEBUG("bta_hl_api_dch_open status =%s",
  897. bta_hl_status_code(status));
  898. }
  899. #endif
  900. switch (status) {
  901. case BTA_HL_STATUS_OK:
  902. if (p_mcb->sdp.num_recs) {
  903. bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_OPEN_EVT,
  904. p_data);
  905. } else {
  906. bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx,
  907. BTA_HL_DCH_SDP_INIT_EVT, p_data);
  908. }
  909. break;
  910. case BTA_HL_STATUS_INVALID_DCH_CFG:
  911. case BTA_HL_STATUS_NO_FIRST_RELIABLE:
  912. case BTA_HL_STATUS_NO_CCH:
  913. case BTA_HL_STATUS_NO_RESOURCE:
  914. case BTA_HL_STATUS_FAIL:
  915. case BTA_HL_STATUS_INVALID_LOCAL_MDEP_ID:
  916. case BTA_HL_STATUS_INVALID_CTRL_PSM:
  917. p_acb = BTA_HL_GET_APP_CB_PTR(app_idx);
  918. if (p_acb->p_cback) {
  919. bta_hl_build_dch_open_cfm(
  920. &evt_data, p_acb->app_handle, p_data->api_dch_open.mcl_handle,
  921. BTA_HL_INVALID_MDL_HANDLE, 0, 0, 0, 0, 0, status);
  922. p_acb->p_cback(BTA_HL_DCH_OPEN_CFM_EVT, (tBTA_HL*)&evt_data);
  923. } else {
  924. APPL_TRACE_ERROR("bta_hl_api_dch_open Null Callback");
  925. }
  926. break;
  927. default:
  928. APPL_TRACE_ERROR("Status code=%d", status);
  929. break;
  930. }
  931. }
  932. /*******************************************************************************
  933. *
  934. * Function bta_hl_api_dch_close
  935. *
  936. * Description Process the API DCH close request
  937. *
  938. * Returns void
  939. *
  940. ******************************************************************************/
  941. static void bta_hl_api_dch_close(UNUSED_ATTR tBTA_HL_CB* p_cb,
  942. tBTA_HL_DATA* p_data) {
  943. tBTA_HL evt_data;
  944. tBTA_HL_STATUS status = BTA_HL_STATUS_OK;
  945. uint8_t app_idx, mcl_idx, mdl_idx;
  946. tBTA_HL_APP_CB* p_acb;
  947. tBTA_HL_MCL_CB* p_mcb;
  948. tBTA_HL_MDL_CB* p_dcb;
  949. if (bta_hl_find_mdl_idx_using_handle(p_data->api_dch_close.mdl_handle,
  950. &app_idx, &mcl_idx, &mdl_idx)) {
  951. p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
  952. if (p_dcb->dch_state != BTA_HL_DCH_OPEN_ST) {
  953. status = BTA_HL_STATUS_FAIL;
  954. }
  955. } else {
  956. status = BTA_HL_STATUS_INVALID_MDL_HANDLE;
  957. }
  958. #if (BTA_HL_DEBUG == TRUE)
  959. if (status != BTA_HL_STATUS_OK) {
  960. APPL_TRACE_DEBUG("bta_hl_api_dch_close status =%s",
  961. bta_hl_status_code(status));
  962. }
  963. #endif
  964. switch (status) {
  965. case BTA_HL_STATUS_OK:
  966. bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_EVT,
  967. p_data);
  968. break;
  969. case BTA_HL_STATUS_FAIL:
  970. p_acb = BTA_HL_GET_APP_CB_PTR(app_idx);
  971. if (p_acb->p_cback) {
  972. p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
  973. bta_hl_build_dch_close_cfm(&evt_data, p_acb->app_handle,
  974. p_mcb->mcl_handle,
  975. p_data->api_dch_close.mdl_handle, status);
  976. p_acb->p_cback(BTA_HL_DCH_CLOSE_CFM_EVT, (tBTA_HL*)&evt_data);
  977. } else {
  978. APPL_TRACE_ERROR("bta_hl_api_dch_close Null Callback");
  979. }
  980. break;
  981. default:
  982. APPL_TRACE_ERROR("Status code=%d", status);
  983. break;
  984. }
  985. }
  986. /*******************************************************************************
  987. *
  988. * Function bta_hl_api_dch_reconnect
  989. *
  990. * Description Process the API DCH reconnect request
  991. *
  992. * Returns void
  993. *
  994. ******************************************************************************/
  995. static void bta_hl_api_dch_reconnect(UNUSED_ATTR tBTA_HL_CB* p_cb,
  996. tBTA_HL_DATA* p_data) {
  997. tBTA_HL evt_data;
  998. tBTA_HL_STATUS status = BTA_HL_STATUS_OK;
  999. uint8_t app_idx, mcl_idx, mdl_idx;
  1000. tBTA_HL_APP_CB* p_acb;
  1001. tBTA_HL_MCL_CB* p_mcb = NULL;
  1002. tBTA_HL_MDL_CB* p_dcb;
  1003. uint8_t mdep_cfg_idx;
  1004. uint8_t mdl_cfg_idx;
  1005. tBTA_HL_MDEP_CFG* p_mdep_cfg;
  1006. if (bta_hl_find_mcl_idx_using_handle(p_data->api_dch_reconnect.mcl_handle,
  1007. &app_idx, &mcl_idx)) {
  1008. p_acb = BTA_HL_GET_APP_CB_PTR(app_idx);
  1009. p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
  1010. if (p_mcb->cch_state == BTA_HL_CCH_OPEN_ST) {
  1011. if (bta_hl_find_avail_mdl_idx(app_idx, mcl_idx, &mdl_idx)) {
  1012. p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
  1013. if (bta_hl_validate_reconnect_params(app_idx, mcl_idx,
  1014. &(p_data->api_dch_reconnect),
  1015. &mdep_cfg_idx, &mdl_cfg_idx)) {
  1016. if (!bta_hl_is_the_first_reliable_existed(app_idx, mcl_idx) &&
  1017. (p_acb->mdl_cfg[mdl_cfg_idx].dch_mode !=
  1018. BTA_HL_DCH_MODE_RELIABLE)) {
  1019. status = BTA_HL_STATUS_NO_FIRST_RELIABLE;
  1020. } else {
  1021. if (bta_hl_set_ctrl_psm_for_dch(app_idx, mcl_idx, mdl_idx,
  1022. p_data->api_dch_open.ctrl_psm)) {
  1023. p_dcb->in_use = true;
  1024. p_dcb->dch_oper = BTA_HL_DCH_OP_LOCAL_RECONNECT;
  1025. p_dcb->sec_mask = (BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT);
  1026. p_dcb->local_mdep_id = p_acb->mdl_cfg[mdl_cfg_idx].local_mdep_id;
  1027. p_dcb->local_mdep_cfg_idx = mdep_cfg_idx;
  1028. p_dcb->local_cfg = BTA_HL_DCH_CFG_UNKNOWN;
  1029. p_dcb->mdl_id = p_data->api_dch_reconnect.mdl_id;
  1030. p_dcb->mdl_cfg_idx_included = true;
  1031. p_dcb->mdl_cfg_idx = mdl_cfg_idx;
  1032. p_dcb->dch_mode = p_acb->mdl_cfg[mdl_cfg_idx].dch_mode;
  1033. p_mdep_cfg = BTA_HL_GET_MDEP_CFG_PTR(app_idx, mdep_cfg_idx);
  1034. if (p_mdep_cfg->mdep_role == BTA_HL_MDEP_ROLE_SINK) {
  1035. p_dcb->peer_mdep_role = BTA_HL_MDEP_ROLE_SOURCE;
  1036. APPL_TRACE_DEBUG("peer mdep role = SOURCE ");
  1037. } else {
  1038. p_dcb->peer_mdep_role = BTA_HL_MDEP_ROLE_SINK;
  1039. APPL_TRACE_DEBUG("peer mdep role = SINK ");
  1040. }
  1041. bta_hl_find_rxtx_apdu_size(app_idx, mdep_cfg_idx,
  1042. &p_dcb->max_rx_apdu_size,
  1043. &p_dcb->max_tx_apdu_size);
  1044. } else {
  1045. status = BTA_HL_STATUS_INVALID_CTRL_PSM;
  1046. }
  1047. }
  1048. } else {
  1049. status = BTA_HL_STATUS_INVALID_RECONNECT_CFG;
  1050. }
  1051. } else {
  1052. status = BTA_HL_STATUS_NO_RESOURCE;
  1053. }
  1054. } else {
  1055. status = BTA_HL_STATUS_NO_CCH;
  1056. }
  1057. } else {
  1058. status = BTA_HL_STATUS_INVALID_MCL_HANDLE;
  1059. }
  1060. #if (BTA_HL_DEBUG == TRUE)
  1061. if (status != BTA_HL_STATUS_OK) {
  1062. APPL_TRACE_DEBUG("bta_hl_api_dch_reconnect status=%s",
  1063. bta_hl_status_code(status));
  1064. }
  1065. #endif
  1066. switch (status) {
  1067. case BTA_HL_STATUS_OK:
  1068. if (p_mcb->sdp.num_recs) {
  1069. bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx,
  1070. BTA_HL_DCH_RECONNECT_EVT, p_data);
  1071. } else {
  1072. bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx,
  1073. BTA_HL_DCH_SDP_INIT_EVT, p_data);
  1074. }
  1075. break;
  1076. case BTA_HL_STATUS_INVALID_RECONNECT_CFG:
  1077. case BTA_HL_STATUS_NO_FIRST_RELIABLE:
  1078. case BTA_HL_STATUS_NO_CCH:
  1079. case BTA_HL_STATUS_NO_RESOURCE:
  1080. p_acb = BTA_HL_GET_APP_CB_PTR(app_idx);
  1081. if (p_acb->p_cback) {
  1082. bta_hl_build_dch_open_cfm(
  1083. &evt_data, p_acb->app_handle, p_data->api_dch_reconnect.mcl_handle,
  1084. BTA_HL_INVALID_MDL_HANDLE, 0, p_data->api_dch_reconnect.mdl_id, 0,
  1085. 0, 0, status);
  1086. p_acb->p_cback(BTA_HL_DCH_RECONNECT_CFM_EVT, (tBTA_HL*)&evt_data);
  1087. } else {
  1088. APPL_TRACE_ERROR("bta_hl_api_dch_reconnect Null Callback");
  1089. }
  1090. break;
  1091. default:
  1092. APPL_TRACE_ERROR("Status code=%d", status);
  1093. break;
  1094. }
  1095. }
  1096. /*******************************************************************************
  1097. *
  1098. * Function bta_hl_api_dch_echo_test
  1099. *
  1100. * Description Process the API Echo test request
  1101. *
  1102. * Returns void
  1103. *
  1104. ******************************************************************************/
  1105. static void bta_hl_api_dch_echo_test(UNUSED_ATTR tBTA_HL_CB* p_cb,
  1106. tBTA_HL_DATA* p_data) {
  1107. tBTA_HL evt_data;
  1108. tBTA_HL_STATUS status = BTA_HL_STATUS_OK;
  1109. uint8_t app_idx, mcl_idx, mdl_idx;
  1110. tBTA_HL_APP_CB* p_acb;
  1111. tBTA_HL_MCL_CB* p_mcb = NULL;
  1112. tBTA_HL_MDL_CB* p_dcb;
  1113. tBTA_HL_ECHO_CFG* p_echo_cfg;
  1114. if (bta_hl_find_mcl_idx_using_handle(p_data->api_dch_echo_test.mcl_handle,
  1115. &app_idx, &mcl_idx)) {
  1116. p_acb = BTA_HL_GET_APP_CB_PTR(app_idx);
  1117. p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
  1118. if (p_mcb->cch_state == BTA_HL_CCH_OPEN_ST) {
  1119. if (!p_mcb->echo_test) {
  1120. if (bta_hl_find_avail_mdl_idx(app_idx, mcl_idx, &mdl_idx)) {
  1121. p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
  1122. if ((p_data->api_dch_echo_test.local_cfg ==
  1123. BTA_HL_DCH_CFG_RELIABLE) ||
  1124. (p_data->api_dch_echo_test.local_cfg ==
  1125. BTA_HL_DCH_CFG_STREAMING)) {
  1126. bool fcs_use =
  1127. (bool)(p_dcb->chnl_cfg.fcs & BTA_HL_MCA_FCS_USE_MASK);
  1128. p_dcb->p_echo_tx_pkt =
  1129. bta_hl_get_buf(p_data->api_dch_echo_test.pkt_size, fcs_use);
  1130. if (p_dcb->p_echo_tx_pkt != NULL) {
  1131. if (bta_hl_set_ctrl_psm_for_dch(app_idx, mcl_idx, mdl_idx,
  1132. p_data->api_dch_open.ctrl_psm)) {
  1133. p_dcb->in_use = true;
  1134. p_dcb->dch_oper = BTA_HL_DCH_OP_LOCAL_OPEN;
  1135. p_dcb->sec_mask = (BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT);
  1136. p_dcb->local_mdep_cfg_idx = BTA_HL_ECHO_TEST_MDEP_CFG_IDX;
  1137. p_dcb->local_cfg = p_data->api_dch_echo_test.local_cfg;
  1138. p_dcb->local_mdep_id = BTA_HL_ECHO_TEST_MDEP_ID;
  1139. p_dcb->peer_mdep_id = BTA_HL_ECHO_TEST_MDEP_ID;
  1140. p_dcb->mdl_id =
  1141. bta_hl_allocate_mdl_id(app_idx, mcl_idx, mdl_idx);
  1142. p_dcb->mdl_cfg_idx_included = false;
  1143. p_echo_cfg = BTA_HL_GET_ECHO_CFG_PTR(app_idx);
  1144. p_dcb->max_rx_apdu_size = p_echo_cfg->max_rx_apdu_size;
  1145. p_dcb->max_tx_apdu_size = p_echo_cfg->max_tx_apdu_size;
  1146. p_mcb->echo_test = true;
  1147. p_mcb->echo_mdl_idx = mdl_idx;
  1148. } else {
  1149. status = BTA_HL_STATUS_INVALID_CTRL_PSM;
  1150. }
  1151. } else {
  1152. status = BTA_HL_STATUS_NO_RESOURCE;
  1153. }
  1154. } else {
  1155. status = BTA_HL_STATUS_INVALID_DCH_CFG;
  1156. }
  1157. } else {
  1158. status = BTA_HL_STATUS_NO_RESOURCE;
  1159. }
  1160. } else {
  1161. status = BTA_HL_STATUS_ECHO_TEST_BUSY;
  1162. }
  1163. } else {
  1164. status = BTA_HL_STATUS_NO_CCH;
  1165. }
  1166. } else {
  1167. status = BTA_HL_STATUS_NO_MCL;
  1168. }
  1169. #if (BTA_HL_DEBUG == TRUE)
  1170. if (status != BTA_HL_STATUS_OK) {
  1171. APPL_TRACE_DEBUG("bta_hl_api_dch_echo_test status=%s",
  1172. bta_hl_status_code(status));
  1173. }
  1174. #endif
  1175. switch (status) {
  1176. case BTA_HL_STATUS_OK:
  1177. if (p_mcb->sdp.num_recs) {
  1178. bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx,
  1179. BTA_HL_DCH_ECHO_TEST_EVT, p_data);
  1180. } else {
  1181. bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx,
  1182. BTA_HL_DCH_SDP_INIT_EVT, p_data);
  1183. }
  1184. break;
  1185. case BTA_HL_STATUS_ECHO_TEST_BUSY:
  1186. case BTA_HL_STATUS_NO_RESOURCE:
  1187. case BTA_HL_STATUS_INVALID_DCH_CFG:
  1188. p_acb = BTA_HL_GET_APP_CB_PTR(app_idx);
  1189. if (p_acb->p_cback) {
  1190. bta_hl_build_echo_test_cfm(&evt_data, p_acb->app_handle,
  1191. p_mcb->mcl_handle, status);
  1192. p_acb->p_cback(BTA_HL_DCH_ECHO_TEST_CFM_EVT, (tBTA_HL*)&evt_data);
  1193. } else {
  1194. APPL_TRACE_ERROR("bta_hl_api_dch_echo_test Null Callback");
  1195. }
  1196. break;
  1197. default:
  1198. APPL_TRACE_ERROR("Status code=%s", status);
  1199. break;
  1200. }
  1201. }
  1202. /*******************************************************************************
  1203. *
  1204. * Function bta_hl_api_sdp_query
  1205. *
  1206. * Description Process the API SDP query request
  1207. *
  1208. * Returns void
  1209. *
  1210. ******************************************************************************/
  1211. static void bta_hl_api_sdp_query(UNUSED_ATTR tBTA_HL_CB* p_cb,
  1212. tBTA_HL_DATA* p_data) {
  1213. tBTA_HL evt_data;
  1214. tBTA_HL_STATUS status = BTA_HL_STATUS_OK;
  1215. uint8_t app_idx, mcl_idx;
  1216. tBTA_HL_APP_CB* p_acb;
  1217. tBTA_HL_MCL_CB* p_mcb;
  1218. if (bta_hl_find_app_idx_using_handle(p_data->api_sdp_query.app_handle,
  1219. &app_idx)) {
  1220. if (!bta_hl_find_mcl_idx(app_idx, p_data->api_sdp_query.bd_addr,
  1221. &mcl_idx)) {
  1222. if (bta_hl_find_avail_mcl_idx(app_idx, &mcl_idx)) {
  1223. p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
  1224. p_mcb->in_use = true;
  1225. p_mcb->bd_addr = p_data->api_sdp_query.bd_addr;
  1226. APPL_TRACE_DEBUG(
  1227. "bta_hl_api_sdp_query p_mcb->app_id %d app_idx %d mcl_idx %d",
  1228. p_mcb->app_id, app_idx, mcl_idx);
  1229. p_mcb->app_id = p_data->api_sdp_query.app_id;
  1230. p_mcb->sdp_oper = BTA_HL_SDP_OP_SDP_QUERY_NEW;
  1231. } else {
  1232. status = BTA_HL_STATUS_NO_RESOURCE;
  1233. }
  1234. } else {
  1235. p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
  1236. p_mcb->app_id = p_data->api_sdp_query.app_id;
  1237. if (p_mcb->sdp_oper != BTA_HL_SDP_OP_NONE) {
  1238. status = BTA_HL_STATUS_SDP_NO_RESOURCE;
  1239. } else {
  1240. p_mcb->sdp_oper = BTA_HL_SDP_OP_SDP_QUERY_CURRENT;
  1241. }
  1242. }
  1243. } else {
  1244. status = BTA_HL_STATUS_INVALID_APP_HANDLE;
  1245. }
  1246. if (status == BTA_HL_STATUS_OK) {
  1247. status = bta_hl_init_sdp(p_mcb->sdp_oper, app_idx, mcl_idx, 0xFF);
  1248. if ((status != BTA_HL_STATUS_OK) &&
  1249. (p_mcb->sdp_oper == BTA_HL_SDP_OP_SDP_QUERY_NEW)) {
  1250. memset(p_mcb, 0, sizeof(tBTA_HL_MCL_CB));
  1251. }
  1252. }
  1253. #if (BTA_HL_DEBUG == TRUE)
  1254. if (status != BTA_HL_STATUS_OK) {
  1255. APPL_TRACE_DEBUG("bta_hl_api_sdp_query status=%s",
  1256. bta_hl_status_code(status));
  1257. }
  1258. #endif
  1259. switch (status) {
  1260. case BTA_HL_STATUS_NO_RESOURCE:
  1261. case BTA_HL_STATUS_FAIL:
  1262. case BTA_HL_STATUS_SDP_NO_RESOURCE:
  1263. p_acb = BTA_HL_GET_APP_CB_PTR(app_idx);
  1264. if (p_acb->p_cback) {
  1265. bta_hl_build_sdp_query_cfm(&evt_data, p_data->api_sdp_query.app_id,
  1266. p_data->api_sdp_query.app_handle,
  1267. p_data->api_sdp_query.bd_addr, NULL, status);
  1268. p_acb->p_cback(BTA_HL_SDP_QUERY_CFM_EVT, (tBTA_HL*)&evt_data);
  1269. } else {
  1270. APPL_TRACE_ERROR("bta_hl_api_sdp_query Null Callback");
  1271. }
  1272. break;
  1273. case BTA_HL_STATUS_OK:
  1274. break;
  1275. default:
  1276. APPL_TRACE_ERROR("Status code=%d", status);
  1277. break;
  1278. }
  1279. }
  1280. /*******************************************************************************
  1281. *
  1282. * Function bta_hl_sdp_query_results
  1283. *
  1284. * Description Process the SDP query results
  1285. *
  1286. * Returns void
  1287. *
  1288. ******************************************************************************/
  1289. static void bta_hl_sdp_query_results(UNUSED_ATTR tBTA_HL_CB* p_cb,
  1290. tBTA_HL_DATA* p_data) {
  1291. tBTA_HL evt_data;
  1292. tBTA_HL_STATUS status = BTA_HL_STATUS_OK;
  1293. uint8_t app_idx = p_data->cch_sdp.app_idx;
  1294. uint8_t mcl_idx = p_data->cch_sdp.mcl_idx;
  1295. tBTA_HL_APP_CB* p_acb = BTA_HL_GET_APP_CB_PTR(app_idx);
  1296. tBTA_HL_MCL_CB* p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
  1297. tBTA_HL_SDP* p_sdp = NULL;
  1298. uint16_t event;
  1299. event = p_data->hdr.event;
  1300. if (event == BTA_HL_SDP_QUERY_OK_EVT) {
  1301. // this is freed in btif_hl_proc_sdp_query_cfm
  1302. p_sdp = (tBTA_HL_SDP*)osi_malloc(sizeof(tBTA_HL_SDP));
  1303. memcpy(p_sdp, &p_mcb->sdp, sizeof(tBTA_HL_SDP));
  1304. } else {
  1305. status = BTA_HL_STATUS_SDP_FAIL;
  1306. }
  1307. #if (BTA_HL_DEBUG == TRUE)
  1308. if (status != BTA_HL_STATUS_OK) {
  1309. APPL_TRACE_DEBUG("bta_hl_sdp_query_results status=%s",
  1310. bta_hl_status_code(status));
  1311. }
  1312. #endif
  1313. APPL_TRACE_DEBUG(
  1314. "bta_hl_sdp_query_results p_mcb->app_id %d app_idx %d mcl_idx %d",
  1315. p_mcb->app_id, app_idx, mcl_idx);
  1316. bta_hl_build_sdp_query_cfm(&evt_data, p_mcb->app_id, p_acb->app_handle,
  1317. p_mcb->bd_addr, p_sdp, status);
  1318. p_acb->p_cback(BTA_HL_SDP_QUERY_CFM_EVT, (tBTA_HL*)&evt_data);
  1319. if (p_data->cch_sdp.release_mcl_cb) {
  1320. memset(p_mcb, 0, sizeof(tBTA_HL_MCL_CB));
  1321. } else {
  1322. if (p_mcb->close_pending)
  1323. bta_hl_check_cch_close(app_idx, mcl_idx, p_data, true);
  1324. if (!p_mcb->ctrl_psm) {
  1325. /* Control channel acceptor: do not store the SDP records */
  1326. memset(&p_mcb->sdp, 0, sizeof(tBTA_HL_SDP));
  1327. }
  1328. }
  1329. }
  1330. /*******************************************************************************
  1331. *
  1332. * Function bta_hl_api_delete_mdl
  1333. *
  1334. * Description Process the API DELETE MDL request
  1335. *
  1336. * Returns void
  1337. *
  1338. ******************************************************************************/
  1339. static void bta_hl_api_delete_mdl(UNUSED_ATTR tBTA_HL_CB* p_cb,
  1340. tBTA_HL_DATA* p_data) {
  1341. tBTA_HL evt_data;
  1342. tBTA_HL_STATUS status = BTA_HL_STATUS_OK;
  1343. uint8_t app_idx, mcl_idx;
  1344. tBTA_HL_APP_CB* p_acb;
  1345. tBTA_HL_MCL_CB* p_mcb;
  1346. if (bta_hl_find_mcl_idx_using_handle(p_data->api_delete_mdl.mcl_handle,
  1347. &app_idx, &mcl_idx)) {
  1348. if (bta_hl_is_mdl_value_valid(p_data->api_delete_mdl.mdl_id)) {
  1349. p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
  1350. if (bta_hl_is_mdl_exsit_in_mcl(app_idx, p_mcb->bd_addr,
  1351. p_data->api_delete_mdl.mdl_id)) {
  1352. p_mcb->delete_mdl.mcl_handle = p_data->api_delete_mdl.mcl_handle;
  1353. p_mcb->delete_mdl.mdl_id = p_data->api_delete_mdl.mdl_id;
  1354. p_mcb->delete_mdl.delete_req_pending = true;
  1355. if (MCA_Delete((tMCA_CL)p_mcb->mcl_handle,
  1356. p_data->api_delete_mdl.mdl_id) != MCA_SUCCESS) {
  1357. status = BTA_HL_STATUS_FAIL;
  1358. memset(&p_mcb->delete_mdl, 0, sizeof(tBTA_HL_DELETE_MDL));
  1359. }
  1360. } else {
  1361. status = BTA_HL_STATUS_NO_MDL_ID_FOUND;
  1362. }
  1363. } else {
  1364. status = BTA_HL_STATUS_INVALID_MDL_ID;
  1365. }
  1366. } else {
  1367. status = BTA_HL_STATUS_INVALID_MCL_HANDLE;
  1368. }
  1369. #if (BTA_HL_DEBUG == TRUE)
  1370. if (status != BTA_HL_STATUS_OK) {
  1371. APPL_TRACE_DEBUG("bta_hl_api_delete_mdl status=%s",
  1372. bta_hl_status_code(status));
  1373. }
  1374. #endif
  1375. switch (status) {
  1376. case BTA_HL_STATUS_OK:
  1377. break;
  1378. case BTA_HL_STATUS_FAIL:
  1379. case BTA_HL_STATUS_NO_MDL_ID_FOUND:
  1380. case BTA_HL_STATUS_INVALID_MDL_ID:
  1381. p_acb = BTA_HL_GET_APP_CB_PTR(app_idx);
  1382. if (p_acb->p_cback) {
  1383. bta_hl_build_delete_mdl_cfm(&evt_data, p_acb->app_handle,
  1384. p_data->api_delete_mdl.mcl_handle,
  1385. p_data->api_delete_mdl.mdl_id, status);
  1386. p_acb->p_cback(BTA_HL_DELETE_MDL_CFM_EVT, (tBTA_HL*)&evt_data);
  1387. } else {
  1388. APPL_TRACE_ERROR("bta_hl_api_delete_mdl Null Callback");
  1389. }
  1390. break;
  1391. default:
  1392. APPL_TRACE_ERROR("status code =%d", status);
  1393. break;
  1394. }
  1395. }
  1396. /*******************************************************************************
  1397. *
  1398. * Function bta_hl_mca_delete_mdl_cfm
  1399. *
  1400. * Description Process the DELETE MDL confirmation event
  1401. *
  1402. * Returns void
  1403. *
  1404. ******************************************************************************/
  1405. static void bta_hl_mca_delete_mdl_cfm(UNUSED_ATTR tBTA_HL_CB* p_cb,
  1406. tBTA_HL_DATA* p_data) {
  1407. tBTA_HL evt_data;
  1408. tBTA_HL_STATUS status = BTA_HL_STATUS_OK;
  1409. uint8_t app_idx, mcl_idx;
  1410. tMCA_RSP_EVT* p_delete_cfm = &p_data->mca_evt.mca_data.delete_cfm;
  1411. tBTA_HL_MCL_CB* p_mcb;
  1412. bool send_cfm_evt = true;
  1413. tBTA_HL_APP_CB* p_acb;
  1414. if (bta_hl_find_mcl_idx_using_handle(p_data->mca_evt.mcl_handle, &app_idx,
  1415. &mcl_idx)) {
  1416. p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
  1417. if (p_mcb->delete_mdl.delete_req_pending) {
  1418. if (p_delete_cfm->rsp_code == MCA_RSP_SUCCESS) {
  1419. if (!bta_hl_delete_mdl_cfg(app_idx, p_mcb->bd_addr,
  1420. p_delete_cfm->mdl_id)) {
  1421. status = BTA_HL_STATUS_FAIL;
  1422. }
  1423. } else {
  1424. status = BTA_HL_STATUS_FAIL;
  1425. }
  1426. memset(&p_mcb->delete_mdl, 0, sizeof(tBTA_HL_DELETE_MDL));
  1427. } else {
  1428. send_cfm_evt = false;
  1429. }
  1430. } else {
  1431. send_cfm_evt = false;
  1432. }
  1433. #if (BTA_HL_DEBUG == TRUE)
  1434. if (status != BTA_HL_STATUS_OK) {
  1435. APPL_TRACE_DEBUG("bta_hl_api_delete_mdl status=%s",
  1436. bta_hl_status_code(status));
  1437. }
  1438. #endif
  1439. if (send_cfm_evt) {
  1440. p_acb = BTA_HL_GET_APP_CB_PTR(app_idx);
  1441. if (p_acb->p_cback) {
  1442. bta_hl_build_delete_mdl_cfm(&evt_data, p_acb->app_handle,
  1443. p_mcb->mcl_handle, p_delete_cfm->mdl_id,
  1444. status);
  1445. p_acb->p_cback(BTA_HL_DELETE_MDL_CFM_EVT, (tBTA_HL*)&evt_data);
  1446. } else {
  1447. APPL_TRACE_ERROR("bta_hl_mca_delete_mdl_cfm Null Callback");
  1448. }
  1449. }
  1450. }
  1451. /*******************************************************************************
  1452. *
  1453. * Function bta_hl_mca_delete_mdl_ind
  1454. *
  1455. * Description Process the DELETE MDL indication event
  1456. *
  1457. * Returns void
  1458. *
  1459. ******************************************************************************/
  1460. static void bta_hl_mca_delete_mdl_ind(UNUSED_ATTR tBTA_HL_CB* p_cb,
  1461. tBTA_HL_DATA* p_data) {
  1462. tBTA_HL evt_data;
  1463. uint8_t app_idx, mcl_idx, mdl_idx;
  1464. tMCA_EVT_HDR* p_delete_ind = &p_data->mca_evt.mca_data.delete_ind;
  1465. tBTA_HL_MCL_CB* p_mcb;
  1466. tBTA_HL_MDL_CB* p_dcb;
  1467. bool send_ind_evt = false;
  1468. tBTA_HL_APP_CB* p_acb;
  1469. if (bta_hl_find_mcl_idx_using_handle(p_data->mca_evt.mcl_handle, &app_idx,
  1470. &mcl_idx)) {
  1471. p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
  1472. if (bta_hl_find_mdl_idx(app_idx, mcl_idx, p_delete_ind->mdl_id, &mdl_idx)) {
  1473. p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
  1474. p_dcb->dch_oper = BTA_HL_DCH_OP_REMOTE_DELETE;
  1475. }
  1476. if (bta_hl_delete_mdl_cfg(app_idx, p_mcb->bd_addr, p_delete_ind->mdl_id)) {
  1477. send_ind_evt = true;
  1478. }
  1479. }
  1480. #if (BTA_HL_DEBUG == TRUE)
  1481. if (!send_ind_evt) {
  1482. APPL_TRACE_DEBUG("bta_hl_mca_delete_mdl_ind is_send_ind_evt =%d",
  1483. send_ind_evt);
  1484. }
  1485. #endif
  1486. if (send_ind_evt) {
  1487. p_acb = BTA_HL_GET_APP_CB_PTR(app_idx);
  1488. if (p_acb->p_cback) {
  1489. evt_data.delete_mdl_ind.mcl_handle = p_mcb->mcl_handle;
  1490. evt_data.delete_mdl_ind.app_handle = p_acb->app_handle;
  1491. evt_data.delete_mdl_ind.mdl_id = p_delete_ind->mdl_id;
  1492. p_acb->p_cback(BTA_HL_DELETE_MDL_IND_EVT, (tBTA_HL*)&evt_data);
  1493. } else {
  1494. APPL_TRACE_ERROR("bta_hl_mca_delete_mdl_ind Null Callback");
  1495. }
  1496. }
  1497. }
  1498. /*******************************************************************************
  1499. *
  1500. * Function bta_hl_api_dch_abort
  1501. *
  1502. * Description Process the API DCH abort request
  1503. *
  1504. * Returns void
  1505. *
  1506. ******************************************************************************/
  1507. static void bta_hl_api_dch_abort(UNUSED_ATTR tBTA_HL_CB* p_cb,
  1508. tBTA_HL_DATA* p_data) {
  1509. tBTA_HL_STATUS status = BTA_HL_STATUS_OK;
  1510. uint8_t app_idx, mcl_idx, mdl_idx;
  1511. tBTA_HL_APP_CB* p_acb;
  1512. tBTA_HL_MCL_CB* p_mcb;
  1513. tBTA_HL_MDL_CB* p_dcb;
  1514. tBTA_HL evt_data;
  1515. if (bta_hl_find_mcl_idx_using_handle(p_data->api_dch_abort.mcl_handle,
  1516. &app_idx, &mcl_idx)) {
  1517. if (!bta_hl_find_dch_setup_mdl_idx(app_idx, mcl_idx, &mdl_idx)) {
  1518. status = BTA_HL_STATUS_NO_MDL_ID_FOUND;
  1519. } else {
  1520. p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
  1521. if (p_dcb->abort_oper) {
  1522. /* abort already in progress*/
  1523. status = BTA_HL_STATUS_FAIL;
  1524. } else {
  1525. p_dcb->abort_oper = BTA_HL_ABORT_LOCAL_MASK;
  1526. }
  1527. }
  1528. } else {
  1529. status = BTA_HL_STATUS_INVALID_MCL_HANDLE;
  1530. }
  1531. #if (BTA_HL_DEBUG == TRUE)
  1532. if (status != BTA_HL_STATUS_OK) {
  1533. APPL_TRACE_DEBUG("bta_hl_api_dch_abort status=%s",
  1534. bta_hl_status_code(status));
  1535. }
  1536. #endif
  1537. switch (status) {
  1538. case BTA_HL_STATUS_OK:
  1539. bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_ABORT_EVT,
  1540. p_data);
  1541. break;
  1542. case BTA_HL_STATUS_NO_MDL_ID_FOUND:
  1543. case BTA_HL_STATUS_FAIL:
  1544. p_acb = BTA_HL_GET_APP_CB_PTR(app_idx);
  1545. if (p_acb->p_cback) {
  1546. p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
  1547. bta_hl_build_abort_cfm(&evt_data,
  1548. p_acb->app_handle, p_mcb->mcl_handle,
  1549. BTA_HL_STATUS_FAIL);
  1550. p_acb->p_cback(BTA_HL_DCH_ABORT_CFM_EVT, (tBTA_HL*)&evt_data);
  1551. } else {
  1552. APPL_TRACE_ERROR("bta_hl_api_dch_abort Null Callback");
  1553. }
  1554. break;
  1555. default:
  1556. APPL_TRACE_ERROR("Status code=%d", status);
  1557. break;
  1558. }
  1559. }
  1560. /*******************************************************************************
  1561. *
  1562. * Function bta_hl_hdl_event
  1563. *
  1564. * Description HL main event handling function.
  1565. *
  1566. * Returns void
  1567. *
  1568. ******************************************************************************/
  1569. bool bta_hl_hdl_event(BT_HDR* p_msg) {
  1570. uint8_t app_idx, mcl_idx, mdl_idx;
  1571. bool success = true;
  1572. #if (BTA_HL_DEBUG == TRUE)
  1573. APPL_TRACE_DEBUG("BTA HL Event Handler: Event [%s]",
  1574. bta_hl_evt_code(p_msg->event));
  1575. #endif
  1576. switch (p_msg->event) {
  1577. case BTA_HL_API_ENABLE_EVT:
  1578. bta_hl_api_enable(&bta_hl_cb, (tBTA_HL_DATA*)p_msg);
  1579. break;
  1580. case BTA_HL_API_DISABLE_EVT:
  1581. bta_hl_api_disable(&bta_hl_cb, (tBTA_HL_DATA*)p_msg);
  1582. break;
  1583. case BTA_HL_API_UPDATE_EVT:
  1584. bta_hl_api_update(&bta_hl_cb, (tBTA_HL_DATA*)p_msg);
  1585. break;
  1586. case BTA_HL_API_REGISTER_EVT:
  1587. bta_hl_api_register(&bta_hl_cb, (tBTA_HL_DATA*)p_msg);
  1588. break;
  1589. case BTA_HL_API_DEREGISTER_EVT:
  1590. bta_hl_api_deregister(&bta_hl_cb, (tBTA_HL_DATA*)p_msg);
  1591. break;
  1592. case BTA_HL_API_CCH_OPEN_EVT:
  1593. bta_hl_api_cch_open(&bta_hl_cb, (tBTA_HL_DATA*)p_msg);
  1594. break;
  1595. case BTA_HL_API_CCH_CLOSE_EVT:
  1596. bta_hl_api_cch_close(&bta_hl_cb, (tBTA_HL_DATA*)p_msg);
  1597. break;
  1598. case BTA_HL_API_DCH_OPEN_EVT:
  1599. bta_hl_api_dch_open(&bta_hl_cb, (tBTA_HL_DATA*)p_msg);
  1600. break;
  1601. case BTA_HL_API_DCH_CLOSE_EVT:
  1602. bta_hl_api_dch_close(&bta_hl_cb, (tBTA_HL_DATA*)p_msg);
  1603. break;
  1604. case BTA_HL_API_DELETE_MDL_EVT:
  1605. bta_hl_api_delete_mdl(&bta_hl_cb, (tBTA_HL_DATA*)p_msg);
  1606. break;
  1607. case BTA_HL_API_DCH_RECONNECT_EVT:
  1608. bta_hl_api_dch_reconnect(&bta_hl_cb, (tBTA_HL_DATA*)p_msg);
  1609. break;
  1610. case BTA_HL_API_DCH_ECHO_TEST_EVT:
  1611. bta_hl_api_dch_echo_test(&bta_hl_cb, (tBTA_HL_DATA*)p_msg);
  1612. break;
  1613. case BTA_HL_API_SDP_QUERY_EVT:
  1614. bta_hl_api_sdp_query(&bta_hl_cb, (tBTA_HL_DATA*)p_msg);
  1615. break;
  1616. case BTA_HL_MCA_DELETE_CFM_EVT:
  1617. bta_hl_mca_delete_mdl_cfm(&bta_hl_cb, (tBTA_HL_DATA*)p_msg);
  1618. break;
  1619. case BTA_HL_MCA_DELETE_IND_EVT:
  1620. bta_hl_mca_delete_mdl_ind(&bta_hl_cb, (tBTA_HL_DATA*)p_msg);
  1621. break;
  1622. case BTA_HL_SDP_QUERY_OK_EVT:
  1623. case BTA_HL_SDP_QUERY_FAIL_EVT:
  1624. bta_hl_sdp_query_results(&bta_hl_cb, (tBTA_HL_DATA*)p_msg);
  1625. break;
  1626. case BTA_HL_API_DCH_ABORT_EVT:
  1627. bta_hl_api_dch_abort(&bta_hl_cb, (tBTA_HL_DATA*)p_msg);
  1628. break;
  1629. default:
  1630. if (p_msg->event < BTA_HL_DCH_EVT_MIN) {
  1631. if (bta_hl_find_cch_cb_indexes((tBTA_HL_DATA*)p_msg, &app_idx,
  1632. &mcl_idx)) {
  1633. bta_hl_cch_sm_execute(app_idx, mcl_idx, p_msg->event,
  1634. (tBTA_HL_DATA*)p_msg);
  1635. } else {
  1636. #if (BTA_HL_DEBUG == TRUE)
  1637. APPL_TRACE_ERROR(
  1638. "unable to find control block indexes for CCH: [event=%s]",
  1639. bta_hl_evt_code(p_msg->event));
  1640. #else
  1641. APPL_TRACE_ERROR(
  1642. "unable to find control block indexes for CCH: [event=%d]",
  1643. p_msg->event);
  1644. #endif
  1645. success = false;
  1646. }
  1647. } else {
  1648. if (bta_hl_find_dch_cb_indexes((tBTA_HL_DATA*)p_msg, &app_idx, &mcl_idx,
  1649. &mdl_idx)) {
  1650. bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, p_msg->event,
  1651. (tBTA_HL_DATA*)p_msg);
  1652. } else {
  1653. #if (BTA_HL_DEBUG == TRUE)
  1654. APPL_TRACE_ERROR(
  1655. "unable to find control block indexes for DCH : [event=%s]",
  1656. bta_hl_evt_code(p_msg->event));
  1657. #else
  1658. APPL_TRACE_ERROR(
  1659. "unable to find control block indexes for DCH: [event=%d]",
  1660. p_msg->event);
  1661. #endif
  1662. success = false;
  1663. }
  1664. }
  1665. break;
  1666. }
  1667. return (success);
  1668. }
  1669. /*****************************************************************************
  1670. * Debug Functions
  1671. ****************************************************************************/
  1672. #if (BTA_HL_DEBUG == TRUE)
  1673. /*******************************************************************************
  1674. *
  1675. * Function bta_hl_cch_state_code
  1676. *
  1677. * Description Map CCH state code to the corresponding state string
  1678. *
  1679. * Returns string pointer for the associated state name
  1680. *
  1681. ******************************************************************************/
  1682. static const char* bta_hl_cch_state_code(tBTA_HL_CCH_STATE state_code) {
  1683. switch (state_code) {
  1684. case BTA_HL_CCH_IDLE_ST:
  1685. return "BTA_HL_CCH_IDLE_ST";
  1686. case BTA_HL_CCH_OPENING_ST:
  1687. return "BTA_HL_CCH_OPENING_ST";
  1688. case BTA_HL_CCH_OPEN_ST:
  1689. return "BTA_HL_CCH_OPEN_ST";
  1690. case BTA_HL_CCH_CLOSING_ST:
  1691. return "BTA_HL_CCH_CLOSING_ST";
  1692. default:
  1693. return "Unknown CCH state code";
  1694. }
  1695. }
  1696. /*******************************************************************************
  1697. *
  1698. * Function bta_hl_dch_state_code
  1699. *
  1700. * Description Map DCH state code to the corresponding state string
  1701. *
  1702. * Returns string pointer for the associated state name
  1703. *
  1704. ******************************************************************************/
  1705. static const char* bta_hl_dch_state_code(tBTA_HL_DCH_STATE state_code) {
  1706. switch (state_code) {
  1707. case BTA_HL_DCH_IDLE_ST:
  1708. return "BTA_HL_DCH_IDLE_ST";
  1709. case BTA_HL_DCH_OPENING_ST:
  1710. return "BTA_HL_DCH_OPENING_ST";
  1711. case BTA_HL_DCH_OPEN_ST:
  1712. return "BTA_HL_DCH_OPEN_ST";
  1713. case BTA_HL_DCH_CLOSING_ST:
  1714. return "BTA_HL_DCH_CLOSING_ST";
  1715. default:
  1716. return "Unknown DCH state code";
  1717. }
  1718. }
  1719. #endif /* Debug Functions */
  1720. #endif /* HL_INCLUDED */