bta_dm_api.c 94 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669
  1. /******************************************************************************
  2. *
  3. * Copyright (C) 2003-2014 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 is the API implementation file for the BTA device manager.
  21. *
  22. ******************************************************************************/
  23. #include "bta/bta_sys.h"
  24. #include "bta/bta_api.h"
  25. #include "bta_dm_int.h"
  26. #include "bta_sys_int.h"
  27. #include "stack/btm_api.h"
  28. #include "btm_int.h"
  29. #include <string.h>
  30. #include "bta/utl.h"
  31. #include "osi/allocator.h"
  32. /*****************************************************************************
  33. ** Constants
  34. *****************************************************************************/
  35. static const tBTA_SYS_REG bta_dm_reg = {
  36. bta_dm_sm_execute,
  37. bta_dm_sm_disable
  38. };
  39. static const tBTA_SYS_REG bta_dm_search_reg = {
  40. bta_dm_search_sm_execute,
  41. bta_dm_search_sm_disable
  42. };
  43. /*******************************************************************************
  44. **
  45. ** Function BTA_EnableBluetooth
  46. **
  47. ** Description Enables bluetooth service. This function must be
  48. ** called before any other functions in the BTA API are called.
  49. **
  50. **
  51. ** Returns tBTA_STATUS
  52. **
  53. *******************************************************************************/
  54. tBTA_STATUS BTA_EnableBluetooth(tBTA_DM_SEC_CBACK *p_cback)
  55. {
  56. tBTA_DM_API_ENABLE *p_msg;
  57. /* Bluetooth disabling is in progress */
  58. if (bta_dm_cb.disabling) {
  59. return BTA_FAILURE;
  60. }
  61. memset(&bta_dm_cb, 0, sizeof(bta_dm_cb));
  62. bta_sys_register (BTA_ID_DM, &bta_dm_reg );
  63. bta_sys_register (BTA_ID_DM_SEARCH, &bta_dm_search_reg );
  64. /* if UUID list is not provided as static data */
  65. bta_sys_eir_register(bta_dm_eir_update_uuid);
  66. if ((p_msg = (tBTA_DM_API_ENABLE *) osi_malloc(sizeof(tBTA_DM_API_ENABLE))) != NULL) {
  67. p_msg->hdr.event = BTA_DM_API_ENABLE_EVT;
  68. p_msg->p_sec_cback = p_cback;
  69. bta_sys_sendmsg(p_msg);
  70. return BTA_SUCCESS;
  71. }
  72. return BTA_FAILURE;
  73. }
  74. /*******************************************************************************
  75. **
  76. ** Function BTA_DisableBluetooth
  77. **
  78. ** Description Disables bluetooth service. This function is called when
  79. ** the application no longer needs bluetooth service
  80. **
  81. ** Returns void
  82. **
  83. *******************************************************************************/
  84. tBTA_STATUS BTA_DisableBluetooth(void)
  85. {
  86. BT_HDR *p_msg;
  87. if ((p_msg = (BT_HDR *) osi_malloc(sizeof(BT_HDR))) != NULL) {
  88. p_msg->event = BTA_DM_API_DISABLE_EVT;
  89. bta_sys_sendmsg(p_msg);
  90. } else {
  91. return BTA_FAILURE;
  92. }
  93. return BTA_SUCCESS;
  94. }
  95. /*******************************************************************************
  96. **
  97. ** Function BTA_EnableTestMode
  98. **
  99. ** Description Enables bluetooth device under test mode
  100. **
  101. **
  102. ** Returns tBTA_STATUS
  103. **
  104. *******************************************************************************/
  105. tBTA_STATUS BTA_EnableTestMode(void)
  106. {
  107. BT_HDR *p_msg;
  108. APPL_TRACE_API("BTA_EnableTestMode");
  109. if ((p_msg = (BT_HDR *) osi_malloc(sizeof(BT_HDR))) != NULL) {
  110. p_msg->event = BTA_DM_API_ENABLE_TEST_MODE_EVT;
  111. bta_sys_sendmsg(p_msg);
  112. return BTA_SUCCESS;
  113. }
  114. return BTA_FAILURE;
  115. }
  116. /*******************************************************************************
  117. **
  118. ** Function BTA_DisableTestMode
  119. **
  120. ** Description Disable bluetooth device under test mode
  121. **
  122. **
  123. ** Returns None
  124. **
  125. *******************************************************************************/
  126. void BTA_DisableTestMode(void)
  127. {
  128. BT_HDR *p_msg;
  129. APPL_TRACE_API("BTA_DisableTestMode");
  130. if ((p_msg = (BT_HDR *) osi_malloc(sizeof(BT_HDR))) != NULL) {
  131. p_msg->event = BTA_DM_API_DISABLE_TEST_MODE_EVT;
  132. bta_sys_sendmsg(p_msg);
  133. }
  134. }
  135. /*******************************************************************************
  136. **
  137. ** Function BTA_DmSetDeviceName
  138. **
  139. ** Description This function sets the Bluetooth name of local device
  140. **
  141. **
  142. ** Returns void
  143. **
  144. *******************************************************************************/
  145. void BTA_DmSetDeviceName(const char *p_name)
  146. {
  147. tBTA_DM_API_SET_NAME *p_msg;
  148. if ((p_msg = (tBTA_DM_API_SET_NAME *) osi_malloc(sizeof(tBTA_DM_API_SET_NAME))) != NULL) {
  149. p_msg->hdr.event = BTA_DM_API_SET_NAME_EVT;
  150. /* truncate the name if needed */
  151. BCM_STRNCPY_S((char *)p_msg->name, p_name, BD_NAME_LEN - 1);
  152. p_msg->name[BD_NAME_LEN - 1] = 0;
  153. bta_sys_sendmsg(p_msg);
  154. }
  155. }
  156. void BTA_DmConfigEir(tBTA_DM_EIR_CONF *eir_config)
  157. {
  158. tBTA_DM_API_CONFIG_EIR *p_msg;
  159. UINT8 eir_manufac_spec_len = eir_config->bta_dm_eir_manufac_spec_len;
  160. UINT8 eir_url_len = eir_config->bta_dm_eir_url_len;
  161. if (eir_manufac_spec_len > HCI_EXT_INQ_RESPONSE_LEN) {
  162. APPL_TRACE_WARNING ("%s: Manufacturer data is too long(%d), cut it to %d\n",
  163. __func__, eir_manufac_spec_len, HCI_EXT_INQ_RESPONSE_LEN);
  164. eir_manufac_spec_len = HCI_EXT_INQ_RESPONSE_LEN;
  165. }
  166. if (eir_url_len > HCI_EXT_INQ_RESPONSE_LEN) {
  167. APPL_TRACE_WARNING ("%s: URL is too long(%d), cut it to %d\n",
  168. __func__, eir_url_len, HCI_EXT_INQ_RESPONSE_LEN);
  169. eir_url_len = HCI_EXT_INQ_RESPONSE_LEN;
  170. }
  171. if ((p_msg = (tBTA_DM_API_CONFIG_EIR *) osi_malloc(sizeof(tBTA_DM_API_CONFIG_EIR) + eir_manufac_spec_len + eir_url_len)) != NULL) {
  172. p_msg->hdr.event = BTA_DM_API_CONFIG_EIR_EVT;
  173. p_msg->eir_fec_required = eir_config->bta_dm_eir_fec_required;
  174. p_msg->eir_included_tx_power = eir_config->bta_dm_eir_included_tx_power;
  175. p_msg->eir_included_uuid = eir_config->bta_dm_eir_included_uuid;
  176. p_msg->eir_flags = eir_config->bta_dm_eir_flags;
  177. p_msg->eir_manufac_spec_len = eir_manufac_spec_len;
  178. p_msg->eir_manufac_spec = p_msg->data;
  179. p_msg->eir_url_len = eir_url_len;
  180. p_msg->eir_url = p_msg->data + eir_manufac_spec_len;
  181. if (eir_manufac_spec_len > 0) {
  182. memcpy(p_msg->eir_manufac_spec, eir_config->bta_dm_eir_manufac_spec, eir_manufac_spec_len);
  183. }
  184. if (eir_url_len > 0) {
  185. memcpy(p_msg->eir_url, eir_config->bta_dm_eir_url, eir_url_len);
  186. }
  187. bta_sys_sendmsg(p_msg);
  188. }
  189. }
  190. #if (CLASSIC_BT_INCLUDED == TRUE)
  191. /*******************************************************************************
  192. **
  193. ** Function BTA_DmSetAfhChannels
  194. **
  195. ** Description This function sets the AFH channels
  196. **
  197. **
  198. ** Returns void
  199. **
  200. *******************************************************************************/
  201. void BTA_DmSetAfhChannels(const uint8_t *channels, tBTA_CMPL_CB *set_afh_cb)
  202. {
  203. tBTA_DM_API_SET_AFH_CHANNELS *p_msg;
  204. if ((p_msg = (tBTA_DM_API_SET_AFH_CHANNELS *) osi_malloc(sizeof(tBTA_DM_API_SET_AFH_CHANNELS))) != NULL) {
  205. p_msg->hdr.event = BTA_DM_API_SET_AFH_CHANNELS_EVT;
  206. p_msg->set_afh_cb = set_afh_cb;
  207. memcpy(p_msg->channels, channels, AFH_CHANNELS_LEN);
  208. bta_sys_sendmsg(p_msg);
  209. }
  210. }
  211. #endif /// CLASSIC_BT_INCLUDED == TRUE
  212. #if (SDP_INCLUDED == TRUE)
  213. /*******************************************************************************
  214. **
  215. ** Function BTA_DmGetRemoteName
  216. **
  217. ** Description This function gets the peer device's Bluetooth name.
  218. **
  219. **
  220. ** Returns void
  221. **
  222. *******************************************************************************/
  223. void BTA_DmGetRemoteName(BD_ADDR remote_addr, tBTA_CMPL_CB *rmt_name_cb)
  224. {
  225. tBTA_DM_API_GET_REMOTE_NAME *p_msg;
  226. if ((p_msg = (tBTA_DM_API_GET_REMOTE_NAME *) osi_malloc(sizeof(tBTA_DM_API_GET_REMOTE_NAME))) != NULL) {
  227. p_msg->hdr.event = BTA_DM_API_GET_REMOTE_NAME_EVT;
  228. p_msg->rmt_name_cb = rmt_name_cb;
  229. bdcpy(p_msg->rmt_addr, remote_addr);
  230. bta_sys_sendmsg(p_msg);
  231. }
  232. }
  233. #endif
  234. #if (BLE_INCLUDED == TRUE)
  235. /*******************************************************************************
  236. **
  237. ** Function BTA_DmBleSetChannels
  238. **
  239. ** Description This function sets BLE channels
  240. **
  241. **
  242. ** Returns void
  243. **
  244. *******************************************************************************/
  245. void BTA_DmBleSetChannels(const uint8_t *channels, tBTA_CMPL_CB *set_channels_cb)
  246. {
  247. tBTA_DM_API_BLE_SET_CHANNELS *p_msg;
  248. if ((p_msg = (tBTA_DM_API_BLE_SET_CHANNELS *) osi_malloc(sizeof(tBTA_DM_API_BLE_SET_CHANNELS))) != NULL) {
  249. p_msg->hdr.event = BTA_DM_API_BLE_SET_CHANNELS_EVT;
  250. p_msg->set_channels_cb = set_channels_cb;
  251. memcpy(p_msg->channels, channels, BLE_CHANNELS_LEN);
  252. bta_sys_sendmsg(p_msg);
  253. }
  254. }
  255. void BTA_DmUpdateWhiteList(BOOLEAN add_remove, BD_ADDR remote_addr, tBLE_ADDR_TYPE addr_type, tBTA_ADD_WHITELIST_CBACK *add_wl_cb)
  256. {
  257. tBTA_DM_API_UPDATE_WHITE_LIST *p_msg;
  258. if ((p_msg = (tBTA_DM_API_UPDATE_WHITE_LIST *)osi_malloc(sizeof(tBTA_DM_API_UPDATE_WHITE_LIST))) != NULL) {
  259. p_msg->hdr.event = BTA_DM_API_UPDATE_WHITE_LIST_EVT;
  260. p_msg->add_remove = add_remove;
  261. p_msg->addr_type = addr_type;
  262. p_msg->add_wl_cb = add_wl_cb;
  263. memcpy(p_msg->remote_addr, remote_addr, sizeof(BD_ADDR));
  264. bta_sys_sendmsg(p_msg);
  265. }
  266. }
  267. void BTA_DmBleReadAdvTxPower(tBTA_CMPL_CB *cmpl_cb)
  268. {
  269. tBTA_DM_API_READ_ADV_TX_POWER *p_msg;
  270. if ((p_msg = (tBTA_DM_API_READ_ADV_TX_POWER *)osi_malloc(sizeof(tBTA_DM_API_READ_ADV_TX_POWER))) != NULL) {
  271. p_msg->hdr.event = BTA_DM_API_BLE_READ_ADV_TX_POWER_EVT;
  272. p_msg->read_tx_power_cb = cmpl_cb;
  273. bta_sys_sendmsg(p_msg);
  274. }
  275. }
  276. #endif ///BLE_INCLUDED == TRUE
  277. void BTA_DmReadRSSI(BD_ADDR remote_addr, tBTA_TRANSPORT transport, tBTA_CMPL_CB *cmpl_cb)
  278. {
  279. tBTA_DM_API_READ_RSSI *p_msg;
  280. if ((p_msg = (tBTA_DM_API_READ_RSSI *)osi_malloc(sizeof(tBTA_DM_API_READ_RSSI))) != NULL) {
  281. p_msg->hdr.event = BTA_DM_API_READ_RSSI_EVT;
  282. memcpy(p_msg->remote_addr, remote_addr, sizeof(BD_ADDR));
  283. p_msg->transport = transport;
  284. p_msg->read_rssi_cb = cmpl_cb;
  285. bta_sys_sendmsg(p_msg);
  286. }
  287. }
  288. /*******************************************************************************
  289. **
  290. ** Function BTA_DmSetVisibility
  291. **
  292. ** Description This function sets the Bluetooth connectable,
  293. ** discoverable, pairable and conn paired only modes of local device
  294. **
  295. **
  296. ** Returns void
  297. **
  298. *******************************************************************************/
  299. void BTA_DmSetVisibility(tBTA_DM_DISC disc_mode, tBTA_DM_CONN conn_mode, UINT8 pairable_mode, UINT8 conn_filter )
  300. {
  301. tBTA_DM_API_SET_VISIBILITY *p_msg;
  302. if ((p_msg = (tBTA_DM_API_SET_VISIBILITY *) osi_malloc(sizeof(tBTA_DM_API_SET_VISIBILITY))) != NULL) {
  303. p_msg->hdr.event = BTA_DM_API_SET_VISIBILITY_EVT;
  304. p_msg->disc_mode = disc_mode;
  305. p_msg->conn_mode = conn_mode;
  306. p_msg->pair_mode = pairable_mode;
  307. p_msg->conn_paired_only = conn_filter;
  308. bta_sys_sendmsg(p_msg);
  309. }
  310. }
  311. /*******************************************************************************
  312. **
  313. ** Function BTA_DmSearch
  314. **
  315. ** Description This function searches for peer Bluetooth devices. It performs
  316. ** an inquiry and gets the remote name for devices. Service
  317. ** discovery is done if services is non zero
  318. **
  319. **
  320. ** Returns void
  321. **
  322. *******************************************************************************/
  323. void BTA_DmSearch(tBTA_DM_INQ *p_dm_inq, tBTA_SERVICE_MASK services, tBTA_DM_SEARCH_CBACK *p_cback)
  324. {
  325. tBTA_DM_API_SEARCH *p_msg;
  326. if ((p_msg = (tBTA_DM_API_SEARCH *) osi_malloc(sizeof(tBTA_DM_API_SEARCH))) != NULL) {
  327. memset(p_msg, 0, sizeof(tBTA_DM_API_SEARCH));
  328. p_msg->hdr.event = BTA_DM_API_SEARCH_EVT;
  329. memcpy(&p_msg->inq_params, p_dm_inq, sizeof(tBTA_DM_INQ));
  330. p_msg->services = services;
  331. p_msg->p_cback = p_cback;
  332. p_msg->rs_res = BTA_DM_RS_NONE;
  333. bta_sys_sendmsg(p_msg);
  334. }
  335. }
  336. /*******************************************************************************
  337. **
  338. ** Function BTA_DmSearchCancel
  339. **
  340. ** Description This function cancels a search initiated by BTA_DmSearch
  341. **
  342. **
  343. ** Returns void
  344. **
  345. *******************************************************************************/
  346. void BTA_DmSearchCancel(void)
  347. {
  348. BT_HDR *p_msg;
  349. if ((p_msg = (BT_HDR *) osi_malloc(sizeof(BT_HDR))) != NULL) {
  350. p_msg->event = BTA_DM_API_SEARCH_CANCEL_EVT;
  351. bta_sys_sendmsg(p_msg);
  352. }
  353. }
  354. #if (SDP_INCLUDED == TRUE)
  355. /*******************************************************************************
  356. **
  357. ** Function BTA_DmDiscover
  358. **
  359. ** Description This function does service discovery for services of a
  360. ** peer device
  361. **
  362. **
  363. ** Returns void
  364. **
  365. *******************************************************************************/
  366. void BTA_DmDiscover(BD_ADDR bd_addr, tBTA_SERVICE_MASK services,
  367. tBTA_DM_SEARCH_CBACK *p_cback, BOOLEAN sdp_search)
  368. {
  369. tBTA_DM_API_DISCOVER *p_msg;
  370. if ((p_msg = (tBTA_DM_API_DISCOVER *) osi_malloc(sizeof(tBTA_DM_API_DISCOVER))) != NULL) {
  371. memset(p_msg, 0, sizeof(tBTA_DM_API_DISCOVER));
  372. p_msg->hdr.event = BTA_DM_API_DISCOVER_EVT;
  373. bdcpy(p_msg->bd_addr, bd_addr);
  374. p_msg->services = services;
  375. p_msg->p_cback = p_cback;
  376. p_msg->sdp_search = sdp_search;
  377. bta_sys_sendmsg(p_msg);
  378. }
  379. }
  380. /*******************************************************************************
  381. **
  382. ** Function BTA_DmDiscoverUUID
  383. **
  384. ** Description This function does service discovery for services of a
  385. ** peer device
  386. **
  387. **
  388. ** Returns void
  389. **
  390. *******************************************************************************/
  391. void BTA_DmDiscoverUUID(BD_ADDR bd_addr, tSDP_UUID *uuid,
  392. tBTA_DM_SEARCH_CBACK *p_cback, BOOLEAN sdp_search)
  393. {
  394. tBTA_DM_API_DISCOVER *p_msg;
  395. if ((p_msg = (tBTA_DM_API_DISCOVER *) osi_malloc(sizeof(tBTA_DM_API_DISCOVER))) != NULL) {
  396. p_msg->hdr.event = BTA_DM_API_DISCOVER_EVT;
  397. bdcpy(p_msg->bd_addr, bd_addr);
  398. p_msg->services = BTA_USER_SERVICE_MASK; //Not exposed at API level
  399. p_msg->p_cback = p_cback;
  400. p_msg->sdp_search = sdp_search;
  401. #if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE
  402. p_msg->num_uuid = 0;
  403. p_msg->p_uuid = NULL;
  404. #endif
  405. memcpy( &p_msg->uuid, uuid, sizeof(tSDP_UUID) );
  406. bta_sys_sendmsg(p_msg);
  407. }
  408. }
  409. #endif ///SDP_INCLUDED == TRUE
  410. /*******************************************************************************
  411. **
  412. ** Function BTA_DmBond
  413. **
  414. ** Description This function initiates a bonding procedure with a peer
  415. ** device
  416. **
  417. **
  418. ** Returns void
  419. **
  420. *******************************************************************************/
  421. #if (SMP_INCLUDED == TRUE)
  422. void BTA_DmBond(BD_ADDR bd_addr)
  423. {
  424. tBTA_DM_API_BOND *p_msg;
  425. p_msg = (tBTA_DM_API_BOND *) osi_malloc(sizeof(tBTA_DM_API_BOND));
  426. if (p_msg != NULL) {
  427. p_msg->hdr.event = BTA_DM_API_BOND_EVT;
  428. bdcpy(p_msg->bd_addr, bd_addr);
  429. p_msg->transport = BTA_TRANSPORT_UNKNOWN;
  430. bta_sys_sendmsg(p_msg);
  431. }
  432. }
  433. /*******************************************************************************
  434. **
  435. ** Function BTA_DmBondByTransports
  436. **
  437. ** Description This function initiates a bonding procedure with a peer
  438. ** device
  439. **
  440. **
  441. ** Returns void
  442. **
  443. *******************************************************************************/
  444. void BTA_DmBondByTransport(BD_ADDR bd_addr, tBTA_TRANSPORT transport)
  445. {
  446. tBTA_DM_API_BOND *p_msg;
  447. if ((p_msg = (tBTA_DM_API_BOND *) osi_malloc(sizeof(tBTA_DM_API_BOND))) != NULL) {
  448. p_msg->hdr.event = BTA_DM_API_BOND_EVT;
  449. bdcpy(p_msg->bd_addr, bd_addr);
  450. p_msg->transport = transport;
  451. bta_sys_sendmsg(p_msg);
  452. }
  453. }
  454. /*******************************************************************************
  455. **
  456. ** Function BTA_DmBondCancel
  457. **
  458. ** Description This function cancels the bonding procedure with a peer
  459. ** device
  460. **
  461. **
  462. ** Returns void
  463. **
  464. *******************************************************************************/
  465. void BTA_DmBondCancel(BD_ADDR bd_addr)
  466. {
  467. tBTA_DM_API_BOND_CANCEL *p_msg;
  468. if ((p_msg = (tBTA_DM_API_BOND_CANCEL *) osi_malloc(sizeof(tBTA_DM_API_BOND_CANCEL))) != NULL) {
  469. p_msg->hdr.event = BTA_DM_API_BOND_CANCEL_EVT;
  470. bdcpy(p_msg->bd_addr, bd_addr);
  471. bta_sys_sendmsg(p_msg);
  472. }
  473. }
  474. #endif ///SMP_INCLUDED == TRUE
  475. #if (CLASSIC_BT_INCLUDED == TRUE)
  476. /*******************************************************************************
  477. **
  478. ** Function BTA_DMSetPinType
  479. **
  480. ** Description This function set pin type as BTM_PIN_TYPE_FIXED or BTM_PIN_TYPE_VARIABLE
  481. **
  482. **
  483. ** Returns void
  484. **
  485. *******************************************************************************/
  486. void BTA_DMSetPinType (UINT8 pin_type, UINT8 *pin_code, UINT8 pin_code_len)
  487. {
  488. tBTA_DM_API_SET_PIN_TYPE *p_msg;
  489. if ((p_msg = (tBTA_DM_API_SET_PIN_TYPE *) osi_malloc(sizeof(tBTA_DM_API_SET_PIN_TYPE))) != NULL) {
  490. p_msg->hdr.event = BTA_DM_API_SET_PIN_TYPE_EVT;
  491. p_msg->pin_type = pin_type;
  492. p_msg->pin_len = pin_code_len;
  493. memcpy(p_msg->p_pin, pin_code, pin_code_len);
  494. bta_sys_sendmsg(p_msg);
  495. }
  496. }
  497. /*******************************************************************************
  498. **
  499. ** Function BTA_DmPinReply
  500. **
  501. ** Description This function provides a pincode for a remote device when
  502. ** one is requested by DM through BTA_DM_PIN_REQ_EVT
  503. **
  504. **
  505. ** Returns void
  506. **
  507. *******************************************************************************/
  508. void BTA_DmPinReply(BD_ADDR bd_addr, BOOLEAN accept, UINT8 pin_len, UINT8 *p_pin)
  509. {
  510. tBTA_DM_API_PIN_REPLY *p_msg;
  511. if ((p_msg = (tBTA_DM_API_PIN_REPLY *) osi_malloc(sizeof(tBTA_DM_API_PIN_REPLY))) != NULL) {
  512. p_msg->hdr.event = BTA_DM_API_PIN_REPLY_EVT;
  513. bdcpy(p_msg->bd_addr, bd_addr);
  514. p_msg->accept = accept;
  515. if (accept) {
  516. p_msg->pin_len = pin_len;
  517. memcpy(p_msg->p_pin, p_pin, pin_len);
  518. }
  519. bta_sys_sendmsg(p_msg);
  520. }
  521. }
  522. #endif ///CLASSIC_BT_INCLUDED == TRUE
  523. #if (BTM_OOB_INCLUDED == TRUE && SMP_INCLUDED == TRUE)
  524. /*******************************************************************************
  525. **
  526. ** Function BTA_DmLocalOob
  527. **
  528. ** Description This function retrieves the OOB data from local controller.
  529. ** The result is reported by:
  530. ** - bta_dm_co_loc_oob_ext() if device supports secure
  531. ** connections (SC)
  532. ** - bta_dm_co_loc_oob() if device doesn't support SC
  533. **
  534. ** Returns void
  535. **
  536. *******************************************************************************/
  537. void BTA_DmLocalOob(void)
  538. {
  539. tBTA_DM_API_LOC_OOB *p_msg;
  540. if ((p_msg = (tBTA_DM_API_LOC_OOB *) osi_malloc(sizeof(tBTA_DM_API_LOC_OOB))) != NULL) {
  541. p_msg->hdr.event = BTA_DM_API_LOC_OOB_EVT;
  542. bta_sys_sendmsg(p_msg);
  543. }
  544. }
  545. /*******************************************************************************
  546. **
  547. ** Function BTA_DmOobReply
  548. **
  549. ** This function is called to provide the OOB data for
  550. ** SMP in response to BTM_LE_OOB_REQ_EVT
  551. **
  552. ** Parameters: bd_addr - Address of the peer device
  553. ** len - length of simple pairing Randomizer C
  554. ** p_value - simple pairing Randomizer C.
  555. **
  556. ** Returns void
  557. **
  558. *******************************************************************************/
  559. void BTA_DmOobReply(BD_ADDR bd_addr, UINT8 len, UINT8 *p_value)
  560. {
  561. tBTA_DM_API_OOB_REPLY *p_msg;
  562. if ((p_msg = (tBTA_DM_API_OOB_REPLY *) osi_malloc(sizeof(tBTA_DM_API_OOB_REPLY))) != NULL) {
  563. p_msg->hdr.event = BTA_DM_API_OOB_REPLY_EVT;
  564. if(p_value == NULL || len > BT_OCTET16_LEN) {
  565. return;
  566. }
  567. memcpy(p_msg->bd_addr, bd_addr, BD_ADDR_LEN);
  568. p_msg->len = len;
  569. memcpy(p_msg->value, p_value, len);
  570. bta_sys_sendmsg(p_msg);
  571. }
  572. }
  573. #endif /* BTM_OOB_INCLUDED */
  574. /*******************************************************************************
  575. **
  576. ** Function BTA_DmConfirm
  577. **
  578. ** Description This function accepts or rejects the numerical value of the
  579. ** Simple Pairing process on BTA_DM_SP_CFM_REQ_EVT
  580. **
  581. ** Returns void
  582. **
  583. *******************************************************************************/
  584. #if (SMP_INCLUDED == TRUE)
  585. void BTA_DmConfirm(BD_ADDR bd_addr, BOOLEAN accept)
  586. {
  587. tBTA_DM_API_CONFIRM *p_msg;
  588. if ((p_msg = (tBTA_DM_API_CONFIRM *) osi_malloc(sizeof(tBTA_DM_API_CONFIRM))) != NULL) {
  589. p_msg->hdr.event = BTA_DM_API_CONFIRM_EVT;
  590. bdcpy(p_msg->bd_addr, bd_addr);
  591. p_msg->accept = accept;
  592. bta_sys_sendmsg(p_msg);
  593. }
  594. }
  595. /*******************************************************************************
  596. **
  597. ** Function BTA_DmPasskeyReqReply
  598. **
  599. ** Description This function is called to provide the passkey for
  600. ** Simple Pairing in response to BTA_DM_SP_KEY_REQ_EVT
  601. **
  602. ** Returns void
  603. **
  604. *******************************************************************************/
  605. #if (BT_SSP_INCLUDED == TRUE)
  606. void BTA_DmPasskeyReqReply(BOOLEAN accept, BD_ADDR bd_addr, UINT32 passkey)
  607. {
  608. tBTA_DM_API_KEY_REQ *p_msg;
  609. if ((p_msg = (tBTA_DM_API_KEY_REQ *) osi_malloc(sizeof(tBTA_DM_API_KEY_REQ))) != NULL) {
  610. p_msg->hdr.event = BTA_DM_API_KEY_REQ_EVT;
  611. bdcpy(p_msg->bd_addr, bd_addr);
  612. p_msg->accept = accept;
  613. p_msg->passkey = passkey;
  614. bta_sys_sendmsg(p_msg);
  615. }
  616. }
  617. #endif ///BT_SSP_INCLUDED == TRUE
  618. #endif ///SMP_INCLUDED == TRUE
  619. /*******************************************************************************
  620. **
  621. ** Function BTA_DmAddDevice
  622. **
  623. ** Description This function adds a device to the security database list of
  624. ** peer device
  625. **
  626. **
  627. ** Returns void
  628. **
  629. *******************************************************************************/
  630. void BTA_DmAddDevice(BD_ADDR bd_addr, DEV_CLASS dev_class, LINK_KEY link_key,
  631. tBTA_SERVICE_MASK trusted_mask, BOOLEAN is_trusted,
  632. UINT8 key_type, tBTA_IO_CAP io_cap, UINT8 pin_length,
  633. UINT8 sc_support)
  634. {
  635. tBTA_DM_API_ADD_DEVICE *p_msg;
  636. if ((p_msg = (tBTA_DM_API_ADD_DEVICE *) osi_malloc(sizeof(tBTA_DM_API_ADD_DEVICE))) != NULL) {
  637. memset (p_msg, 0, sizeof(tBTA_DM_API_ADD_DEVICE));
  638. p_msg->hdr.event = BTA_DM_API_ADD_DEVICE_EVT;
  639. bdcpy(p_msg->bd_addr, bd_addr);
  640. p_msg->tm = trusted_mask;
  641. p_msg->is_trusted = is_trusted;
  642. p_msg->io_cap = io_cap;
  643. p_msg->sc_support = sc_support;
  644. if (link_key) {
  645. p_msg->link_key_known = TRUE;
  646. p_msg->key_type = key_type;
  647. memcpy(p_msg->link_key, link_key, LINK_KEY_LEN);
  648. }
  649. /* Load device class if specified */
  650. if (dev_class) {
  651. p_msg->dc_known = TRUE;
  652. memcpy (p_msg->dc, dev_class, DEV_CLASS_LEN);
  653. }
  654. memset (p_msg->bd_name, 0, BD_NAME_LEN + 1);
  655. memset (p_msg->features, 0, sizeof (p_msg->features));
  656. p_msg->pin_length = pin_length;
  657. bta_sys_sendmsg(p_msg);
  658. }
  659. }
  660. /*******************************************************************************
  661. **
  662. ** Function BTA_DmRemoveDevice
  663. **
  664. ** Description This function removes a device fromthe security database list of
  665. ** peer device. It manages unpairing even while connected.
  666. **
  667. **
  668. ** Returns void
  669. **
  670. *******************************************************************************/
  671. tBTA_STATUS BTA_DmRemoveDevice(BD_ADDR bd_addr, tBT_TRANSPORT transport)
  672. {
  673. tBTA_DM_API_REMOVE_DEVICE *p_msg;
  674. if ((p_msg = (tBTA_DM_API_REMOVE_DEVICE *) osi_malloc(sizeof(tBTA_DM_API_REMOVE_DEVICE))) != NULL) {
  675. memset (p_msg, 0, sizeof(tBTA_DM_API_REMOVE_DEVICE));
  676. p_msg->hdr.event = BTA_DM_API_REMOVE_DEVICE_EVT;
  677. bdcpy(p_msg->bd_addr, bd_addr);
  678. p_msg->transport = transport;
  679. bta_sys_sendmsg(p_msg);
  680. } else {
  681. return BTA_FAILURE;
  682. }
  683. return BTA_SUCCESS;
  684. }
  685. // #endif ///SMP_INCLUDED == TRUE
  686. /*******************************************************************************
  687. **
  688. ** Function BTA_GetEirService
  689. **
  690. ** Description This function is called to get BTA service mask from EIR.
  691. **
  692. ** Parameters p_eir - pointer of EIR significant part
  693. ** p_services - return the BTA service mask
  694. **
  695. ** Returns None
  696. **
  697. *******************************************************************************/
  698. extern const UINT16 bta_service_id_to_uuid_lkup_tbl [];
  699. void BTA_GetEirService( UINT8 *p_eir, tBTA_SERVICE_MASK *p_services )
  700. {
  701. UINT8 xx, yy;
  702. UINT8 num_uuid, max_num_uuid = 32;
  703. UINT8 uuid_list[32 * LEN_UUID_16];
  704. UINT16 *p_uuid16 = (UINT16 *)uuid_list;
  705. tBTA_SERVICE_MASK mask;
  706. BTM_GetEirUuidList( p_eir, LEN_UUID_16, &num_uuid, uuid_list, max_num_uuid);
  707. for ( xx = 0; xx < num_uuid; xx++ ) {
  708. mask = 1;
  709. for ( yy = 0; yy < BTA_MAX_SERVICE_ID; yy++ ) {
  710. if ( *(p_uuid16 + xx) == bta_service_id_to_uuid_lkup_tbl[yy] ) {
  711. *p_services |= mask;
  712. break;
  713. }
  714. mask <<= 1;
  715. }
  716. /* for HSP v1.2 only device */
  717. if (*(p_uuid16 + xx) == UUID_SERVCLASS_HEADSET_HS) {
  718. *p_services |= BTA_HSP_SERVICE_MASK;
  719. }
  720. if (*(p_uuid16 + xx) == UUID_SERVCLASS_HDP_SOURCE) {
  721. *p_services |= BTA_HL_SERVICE_MASK;
  722. }
  723. if (*(p_uuid16 + xx) == UUID_SERVCLASS_HDP_SINK) {
  724. *p_services |= BTA_HL_SERVICE_MASK;
  725. }
  726. }
  727. }
  728. /*******************************************************************************
  729. **
  730. ** Function BTA_DmGetConnectionState
  731. **
  732. ** Description Returns whether the remote device is currently connected.
  733. **
  734. ** Returns 0 if the device is NOT connected.
  735. **
  736. *******************************************************************************/
  737. UINT16 BTA_DmGetConnectionState( BD_ADDR bd_addr )
  738. {
  739. tBTA_DM_PEER_DEVICE *p_dev = bta_dm_find_peer_device(bd_addr);
  740. return (p_dev && p_dev->conn_state == BTA_DM_CONNECTED);
  741. }
  742. #if (SDP_INCLUDED == TRUE)
  743. /*******************************************************************************
  744. ** Device Identification (DI) Server Functions
  745. *******************************************************************************/
  746. /*******************************************************************************
  747. **
  748. ** Function BTA_DmSetLocalDiRecord
  749. **
  750. ** Description This function adds a DI record to the local SDP database.
  751. **
  752. ** Returns BTA_SUCCESS if record set successfully, otherwise error code.
  753. **
  754. *******************************************************************************/
  755. tBTA_STATUS BTA_DmSetLocalDiRecord( tBTA_DI_RECORD *p_device_info,
  756. UINT32 *p_handle )
  757. {
  758. tBTA_STATUS status = BTA_FAILURE;
  759. if (bta_dm_di_cb.di_num < BTA_DI_NUM_MAX) {
  760. if (SDP_SetLocalDiRecord((tSDP_DI_RECORD *)p_device_info, p_handle) == SDP_SUCCESS) {
  761. if (!p_device_info->primary_record) {
  762. bta_dm_di_cb.di_handle[bta_dm_di_cb.di_num] = *p_handle;
  763. bta_dm_di_cb.di_num ++;
  764. }
  765. bta_sys_add_uuid(UUID_SERVCLASS_PNP_INFORMATION);
  766. status = BTA_SUCCESS;
  767. }
  768. }
  769. return status;
  770. }
  771. #endif ///SDP_INCLUDED == TRUE
  772. /*******************************************************************************
  773. **
  774. ** Function bta_dmexecutecallback
  775. **
  776. ** Description This function will request BTA to execute a call back in the context of BTU task
  777. ** This API was named in lower case because it is only intended
  778. ** for the internal customers(like BTIF).
  779. **
  780. ** Returns void
  781. **
  782. *******************************************************************************/
  783. void bta_dmexecutecallback (tBTA_DM_EXEC_CBACK *p_callback, void *p_param)
  784. {
  785. tBTA_DM_API_EXECUTE_CBACK *p_msg;
  786. if ((p_msg = (tBTA_DM_API_EXECUTE_CBACK *) osi_malloc(sizeof(tBTA_DM_API_EXECUTE_CBACK))) != NULL) {
  787. p_msg->hdr.event = BTA_DM_API_EXECUTE_CBACK_EVT;
  788. p_msg->p_param = p_param;
  789. p_msg->p_exec_cback = p_callback;
  790. bta_sys_sendmsg(p_msg);
  791. }
  792. }
  793. /*******************************************************************************
  794. **
  795. ** Function BTA_DmAddBleKey
  796. **
  797. ** Description Add/modify LE device information. This function will be
  798. ** normally called during host startup to restore all required
  799. ** information stored in the NVRAM.
  800. **
  801. ** Parameters: bd_addr - BD address of the peer
  802. ** p_le_key - LE key values.
  803. ** key_type - LE SMP key type.
  804. **
  805. ** Returns BTA_SUCCESS if successful
  806. ** BTA_FAIL if operation failed.
  807. **
  808. *******************************************************************************/
  809. #if BLE_INCLUDED == TRUE
  810. #if SMP_INCLUDED == TRUE
  811. void BTA_DmAddBleKey (BD_ADDR bd_addr, tBTA_LE_KEY_VALUE *p_le_key, tBTA_LE_KEY_TYPE key_type)
  812. {
  813. tBTA_DM_API_ADD_BLEKEY *p_msg;
  814. if ((p_msg = (tBTA_DM_API_ADD_BLEKEY *) osi_malloc(sizeof(tBTA_DM_API_ADD_BLEKEY))) != NULL) {
  815. memset (p_msg, 0, sizeof(tBTA_DM_API_ADD_BLEKEY));
  816. p_msg->hdr.event = BTA_DM_API_ADD_BLEKEY_EVT;
  817. p_msg->key_type = key_type;
  818. bdcpy(p_msg->bd_addr, bd_addr);
  819. memcpy(&p_msg->blekey, p_le_key, sizeof(tBTA_LE_KEY_VALUE));
  820. bta_sys_sendmsg(p_msg);
  821. }
  822. }
  823. /*******************************************************************************
  824. **
  825. ** Function BTA_DmAddBleDevice
  826. **
  827. ** Description Add a BLE device. This function will be normally called
  828. ** during host startup to restore all required information
  829. ** for a LE device stored in the NVRAM.
  830. **
  831. ** Parameters: bd_addr - BD address of the peer
  832. ** dev_type - Remote device's device type.
  833. ** auth_mode - auth mode
  834. ** addr_type - LE device address type.
  835. **
  836. ** Returns void
  837. **
  838. *******************************************************************************/
  839. void BTA_DmAddBleDevice(BD_ADDR bd_addr, tBLE_ADDR_TYPE addr_type, int auth_mode, tBT_DEVICE_TYPE dev_type)
  840. {
  841. tBTA_DM_API_ADD_BLE_DEVICE *p_msg;
  842. if ((p_msg = (tBTA_DM_API_ADD_BLE_DEVICE *) osi_malloc(sizeof(tBTA_DM_API_ADD_BLE_DEVICE))) != NULL) {
  843. memset (p_msg, 0, sizeof(tBTA_DM_API_ADD_BLE_DEVICE));
  844. p_msg->hdr.event = BTA_DM_API_ADD_BLEDEVICE_EVT;
  845. bdcpy(p_msg->bd_addr, bd_addr);
  846. p_msg->addr_type = addr_type;
  847. p_msg->auth_mode = auth_mode;
  848. p_msg->dev_type = dev_type;
  849. bta_sys_sendmsg(p_msg);
  850. }
  851. }
  852. /*******************************************************************************
  853. **
  854. ** Function BTA_DmBlePasskeyReply
  855. **
  856. ** Description Send BLE SMP passkey reply.
  857. **
  858. ** Parameters: bd_addr - BD address of the peer
  859. ** accept - passkey entry sucessful or declined.
  860. ** passkey - passkey value, must be a 6 digit number,
  861. ** can be lead by 0.
  862. **
  863. ** Returns void
  864. **
  865. *******************************************************************************/
  866. void BTA_DmBlePasskeyReply(BD_ADDR bd_addr, BOOLEAN accept, UINT32 passkey)
  867. {
  868. tBTA_DM_API_PASSKEY_REPLY *p_msg;
  869. if ((p_msg = (tBTA_DM_API_PASSKEY_REPLY *) osi_malloc(sizeof(tBTA_DM_API_PASSKEY_REPLY))) != NULL) {
  870. memset(p_msg, 0, sizeof(tBTA_DM_API_PASSKEY_REPLY));
  871. p_msg->hdr.event = BTA_DM_API_BLE_PASSKEY_REPLY_EVT;
  872. bdcpy(p_msg->bd_addr, bd_addr);
  873. p_msg->accept = accept;
  874. if (accept) {
  875. p_msg->passkey = passkey;
  876. }
  877. bta_sys_sendmsg(p_msg);
  878. }
  879. }
  880. void BTA_DmBleSetStaticPasskey(bool add, uint32_t passkey)
  881. {
  882. tBTA_DM_API_SET_DEFAULT_PASSKEY *p_msg;
  883. if ((p_msg = (tBTA_DM_API_SET_DEFAULT_PASSKEY *) osi_malloc(sizeof(tBTA_DM_API_SET_DEFAULT_PASSKEY))) != NULL) {
  884. memset(p_msg, 0, sizeof(tBTA_DM_API_SET_DEFAULT_PASSKEY));
  885. p_msg->hdr.event = BTA_DM_API_BLE_SET_STATIC_PASSKEY_EVT;
  886. p_msg->add = add;
  887. p_msg->static_passkey = passkey;
  888. bta_sys_sendmsg(p_msg);
  889. }
  890. }
  891. /*******************************************************************************
  892. **
  893. ** Function BTA_DmBleConfirmReply
  894. **
  895. ** Description Send BLE SMP SC user confirmation reply.
  896. **
  897. ** Parameters: bd_addr - BD address of the peer
  898. ** accept - numbers to compare are the same or different.
  899. **
  900. ** Returns void
  901. **
  902. *******************************************************************************/
  903. void BTA_DmBleConfirmReply(BD_ADDR bd_addr, BOOLEAN accept)
  904. {
  905. tBTA_DM_API_CONFIRM *p_msg = (tBTA_DM_API_CONFIRM *)osi_malloc(sizeof(tBTA_DM_API_CONFIRM));
  906. if (p_msg != NULL) {
  907. memset(p_msg, 0, sizeof(tBTA_DM_API_CONFIRM));
  908. p_msg->hdr.event = BTA_DM_API_BLE_CONFIRM_REPLY_EVT;
  909. bdcpy(p_msg->bd_addr, bd_addr);
  910. p_msg->accept = accept;
  911. bta_sys_sendmsg(p_msg);
  912. }
  913. }
  914. /*******************************************************************************
  915. **
  916. ** Function BTA_DmBleSecurityGrant
  917. **
  918. ** Description Grant security request access.
  919. **
  920. ** Parameters: bd_addr - BD address of the peer
  921. ** res - security grant status.
  922. **
  923. ** Returns void
  924. **
  925. *******************************************************************************/
  926. void BTA_DmBleSecurityGrant(BD_ADDR bd_addr, tBTA_DM_BLE_SEC_GRANT res)
  927. {
  928. tBTA_DM_API_BLE_SEC_GRANT *p_msg;
  929. if ((p_msg = (tBTA_DM_API_BLE_SEC_GRANT *) osi_malloc(sizeof(tBTA_DM_API_BLE_SEC_GRANT))) != NULL) {
  930. memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_SEC_GRANT));
  931. p_msg->hdr.event = BTA_DM_API_BLE_SEC_GRANT_EVT;
  932. bdcpy(p_msg->bd_addr, bd_addr);
  933. p_msg->res = res;
  934. bta_sys_sendmsg(p_msg);
  935. }
  936. }
  937. #endif ///SMP_INCLUDED == TRUE
  938. /*******************************************************************************
  939. **
  940. ** Function BTA_DmSetBlePrefConnParams
  941. **
  942. ** Description This function is called to set the preferred connection
  943. ** parameters when default connection parameter is not desired.
  944. **
  945. ** Parameters: bd_addr - BD address of the peripheral
  946. ** scan_interval - scan interval
  947. ** scan_window - scan window
  948. ** min_conn_int - minimum preferred connection interval
  949. ** max_conn_int - maximum preferred connection interval
  950. ** slave_latency - preferred slave latency
  951. ** supervision_tout - preferred supervision timeout
  952. **
  953. **
  954. ** Returns void
  955. **
  956. *******************************************************************************/
  957. void BTA_DmSetBlePrefConnParams(BD_ADDR bd_addr,
  958. UINT16 min_conn_int, UINT16 max_conn_int,
  959. UINT16 slave_latency, UINT16 supervision_tout )
  960. {
  961. #if BLE_INCLUDED == TRUE
  962. tBTA_DM_API_BLE_CONN_PARAMS *p_msg;
  963. if ((p_msg = (tBTA_DM_API_BLE_CONN_PARAMS *) osi_malloc(sizeof(tBTA_DM_API_BLE_CONN_PARAMS))) != NULL) {
  964. memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_CONN_PARAMS));
  965. p_msg->hdr.event = BTA_DM_API_BLE_CONN_PARAM_EVT;
  966. memcpy(p_msg->peer_bda, bd_addr, BD_ADDR_LEN);
  967. p_msg->conn_int_max = max_conn_int;
  968. p_msg->conn_int_min = min_conn_int;
  969. p_msg->slave_latency = slave_latency;
  970. p_msg->supervision_tout = supervision_tout;
  971. bta_sys_sendmsg(p_msg);
  972. }
  973. #endif
  974. }
  975. /*******************************************************************************
  976. **
  977. ** Function BTA_DmSetBleConnScanParams
  978. **
  979. ** Description This function is called to set scan parameters used in
  980. ** BLE connection request
  981. **
  982. ** Parameters: scan_interval - scan interval
  983. ** scan_window - scan window
  984. **
  985. ** Returns void
  986. **
  987. *******************************************************************************/
  988. void BTA_DmSetBleConnScanParams(UINT32 scan_interval, UINT32 scan_window)
  989. {
  990. tBTA_DM_API_BLE_SCAN_PARAMS *p_msg;
  991. if ((p_msg = (tBTA_DM_API_BLE_SCAN_PARAMS *)osi_malloc(sizeof(tBTA_DM_API_BLE_SCAN_PARAMS))) != NULL) {
  992. memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_SCAN_PARAMS));
  993. p_msg->hdr.event = BTA_DM_API_BLE_CONN_SCAN_PARAM_EVT;
  994. p_msg->scan_int = scan_interval;
  995. p_msg->scan_window = scan_window;
  996. bta_sys_sendmsg(p_msg);
  997. }
  998. }
  999. /*******************************************************************************
  1000. **
  1001. ** Function BTA_DmSetBleScanParams
  1002. **
  1003. ** Description This function is called to set scan parameters
  1004. **
  1005. ** Parameters: client_if - Client IF
  1006. ** scan_interval - scan interval
  1007. ** scan_window - scan window
  1008. ** scan_mode - scan mode
  1009. ** scan_param_setup_status_cback - Set scan param status callback
  1010. **
  1011. ** Returns void
  1012. **
  1013. *******************************************************************************/
  1014. void BTA_DmSetBleScanParams(tGATT_IF client_if, UINT32 scan_interval,
  1015. UINT32 scan_window, tBLE_SCAN_MODE scan_mode,
  1016. tBLE_SCAN_PARAM_SETUP_CBACK scan_param_setup_cback)
  1017. {
  1018. tBTA_DM_API_BLE_SCAN_PARAMS *p_msg;
  1019. if ((p_msg = (tBTA_DM_API_BLE_SCAN_PARAMS *)osi_malloc(sizeof(tBTA_DM_API_BLE_SCAN_PARAMS))) != NULL) {
  1020. memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_SCAN_PARAMS));
  1021. p_msg->hdr.event = BTA_DM_API_BLE_SCAN_PARAM_EVT;
  1022. p_msg->client_if = client_if;
  1023. p_msg->scan_int = scan_interval;
  1024. p_msg->scan_window = scan_window;
  1025. p_msg->scan_mode = scan_mode;
  1026. p_msg->scan_param_setup_cback = scan_param_setup_cback;
  1027. bta_sys_sendmsg(p_msg);
  1028. }
  1029. }
  1030. /*******************************************************************************
  1031. **
  1032. ** Function BTA_DmSetBleScanFilterParams
  1033. **
  1034. ** Description This function is called to set scan parameters
  1035. **
  1036. ** Parameters: client_if - Client IF
  1037. ** scan_interval - scan interval
  1038. ** scan_window - scan window
  1039. ** scan_mode - scan mode
  1040. ** scan_duplicate_filter - scan duplicate filter
  1041. ** scan_param_setup_status_cback - Set scan param status callback
  1042. **
  1043. ** Returns void
  1044. **
  1045. *******************************************************************************/
  1046. void BTA_DmSetBleScanFilterParams(tGATT_IF client_if, UINT32 scan_interval,
  1047. UINT32 scan_window, tBLE_SCAN_MODE scan_mode, UINT8 scan_fil_poilcy,
  1048. UINT8 addr_type_own, UINT8 scan_duplicate_filter, tBLE_SCAN_PARAM_SETUP_CBACK scan_param_setup_cback)
  1049. {
  1050. tBTA_DM_API_BLE_SCAN_FILTER_PARAMS *p_msg;
  1051. if ((p_msg = (tBTA_DM_API_BLE_SCAN_FILTER_PARAMS *)osi_malloc(sizeof(tBTA_DM_API_BLE_SCAN_FILTER_PARAMS))) != NULL) {
  1052. memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_SCAN_FILTER_PARAMS));
  1053. p_msg->hdr.event = BTA_DM_API_BLE_SCAN_FIL_PARAM_EVT;
  1054. p_msg->client_if = client_if;
  1055. p_msg->scan_int = scan_interval;
  1056. p_msg->scan_window = scan_window;
  1057. p_msg->scan_mode = scan_mode;
  1058. p_msg->addr_type_own = addr_type_own;
  1059. p_msg->scan_duplicate_filter = scan_duplicate_filter;
  1060. p_msg->scan_filter_policy = scan_fil_poilcy;
  1061. p_msg->scan_param_setup_cback = scan_param_setup_cback;
  1062. bta_sys_sendmsg(p_msg);
  1063. }
  1064. }
  1065. /*******************************************************************************
  1066. **
  1067. ** Function BTA_DmSetBleAdvParams
  1068. **
  1069. ** Description This function sets the advertising parameters BLE functionality.
  1070. ** It is to be called when device act in peripheral or broadcaster
  1071. ** role.
  1072. **
  1073. **
  1074. ** Returns void
  1075. **
  1076. *******************************************************************************/
  1077. void BTA_DmSetBleAdvParams (UINT16 adv_int_min, UINT16 adv_int_max,
  1078. tBLE_BD_ADDR *p_dir_bda)
  1079. {
  1080. #if BLE_INCLUDED == TRUE
  1081. tBTA_DM_API_BLE_ADV_PARAMS *p_msg;
  1082. APPL_TRACE_API ("BTA_DmSetBleAdvParam: %d, %d\n", adv_int_min, adv_int_max);
  1083. if ((p_msg = (tBTA_DM_API_BLE_ADV_PARAMS *) osi_malloc(sizeof(tBTA_DM_API_BLE_ADV_PARAMS)
  1084. + sizeof(tBLE_BD_ADDR))) != NULL) {
  1085. memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_ADV_PARAMS) + sizeof(tBLE_BD_ADDR));
  1086. p_msg->hdr.event = BTA_DM_API_BLE_ADV_PARAM_EVT;
  1087. p_msg->adv_int_min = adv_int_min;
  1088. p_msg->adv_int_max = adv_int_max;
  1089. if (p_dir_bda != NULL) {
  1090. p_msg->p_dir_bda = (tBLE_BD_ADDR *)(p_msg + 1);
  1091. memcpy(p_msg->p_dir_bda, p_dir_bda, sizeof(tBLE_BD_ADDR));
  1092. }
  1093. bta_sys_sendmsg(p_msg);
  1094. }
  1095. #endif
  1096. }
  1097. void BTA_DmSetBleAdvParamsAll (UINT16 adv_int_min, UINT16 adv_int_max,
  1098. UINT8 adv_type, tBLE_ADDR_TYPE addr_type_own,
  1099. tBTM_BLE_ADV_CHNL_MAP chnl_map, tBTM_BLE_AFP adv_fil_pol,
  1100. tBLE_BD_ADDR *p_dir_bda, tBTA_START_ADV_CMPL_CBACK p_start_adv_cb)
  1101. {
  1102. #if BLE_INCLUDED == TRUE
  1103. tBTA_DM_API_BLE_ADV_PARAMS_ALL *p_msg;
  1104. APPL_TRACE_API ("BTA_DmSetBleAdvParamsAll: %d, %d\n", adv_int_min, adv_int_max);
  1105. APPL_TRACE_API ("adv_type = %d, addr_type_own = %d, chnl_map = %d, adv_fil_pol = %d\n",
  1106. adv_type, addr_type_own, chnl_map, adv_fil_pol);
  1107. if ((p_msg = (tBTA_DM_API_BLE_ADV_PARAMS_ALL *) osi_malloc(sizeof(tBTA_DM_API_BLE_ADV_PARAMS_ALL)
  1108. + sizeof(tBLE_BD_ADDR))) != NULL) {
  1109. memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_ADV_PARAMS_ALL));
  1110. p_msg->hdr.event = BTA_DM_API_BLE_ADV_PARAM_All_EVT;
  1111. p_msg->adv_int_min = adv_int_min;
  1112. p_msg->adv_int_max = adv_int_max;
  1113. p_msg->adv_type = adv_type;
  1114. p_msg->addr_type_own = addr_type_own;
  1115. p_msg->channel_map = chnl_map;
  1116. p_msg->adv_filter_policy = adv_fil_pol;
  1117. p_msg->p_start_adv_cback = p_start_adv_cb;
  1118. if (p_dir_bda != NULL) {
  1119. p_msg->p_dir_bda = (tBLE_BD_ADDR *)(p_msg + 1);
  1120. memcpy(p_msg->p_dir_bda, p_dir_bda, sizeof(tBLE_BD_ADDR));
  1121. }
  1122. bta_sys_sendmsg(p_msg);
  1123. }
  1124. #endif
  1125. }
  1126. #endif ///BLE_INCLUDED == TRUE
  1127. /*******************************************************************************
  1128. ** BLE ADV data management API
  1129. ********************************************************************************/
  1130. #if BLE_INCLUDED == TRUE
  1131. /*******************************************************************************
  1132. **
  1133. ** Function BTA_DmBleSetAdvConfig
  1134. **
  1135. ** Description This function is called to override the BTA default ADV parameters.
  1136. **
  1137. ** Parameters data_mask: adv data mask.
  1138. ** p_adv_cfg: Pointer to User defined ADV data structure. This
  1139. ** memory space can not be freed until p_adv_data_cback
  1140. ** is received.
  1141. ** p_adv_data_cback: set adv data complete callback.
  1142. **
  1143. ** Returns None
  1144. **
  1145. *******************************************************************************/
  1146. void BTA_DmBleSetAdvConfig (tBTA_BLE_AD_MASK data_mask, tBTA_BLE_ADV_DATA *p_adv_cfg,
  1147. tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback)
  1148. {
  1149. tBTA_DM_API_SET_ADV_CONFIG *p_msg;
  1150. if ((p_msg = (tBTA_DM_API_SET_ADV_CONFIG *)
  1151. osi_malloc(sizeof(tBTA_DM_API_SET_ADV_CONFIG))) != NULL) {
  1152. p_msg->hdr.event = BTA_DM_API_BLE_SET_ADV_CONFIG_EVT;
  1153. p_msg->data_mask = data_mask;
  1154. p_msg->p_adv_data_cback = p_adv_data_cback;
  1155. p_msg->p_adv_cfg = p_adv_cfg;
  1156. bta_sys_sendmsg(p_msg);
  1157. }
  1158. }
  1159. /*******************************************************************************
  1160. **
  1161. ** Function BTA_DmBleSetAdvConfigRaw
  1162. **
  1163. ** Description This function is called to set raw Advertising data
  1164. **
  1165. ** Parameters p_raw_adv : raw advertising data.
  1166. ** raw_adv_len : raw advertising data length.
  1167. ** p_adv_data_cback : set adv data complete callback.
  1168. **
  1169. ** Returns None
  1170. **
  1171. *******************************************************************************/
  1172. void BTA_DmBleSetAdvConfigRaw (UINT8 *p_raw_adv, UINT32 raw_adv_len,
  1173. tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback)
  1174. {
  1175. tBTA_DM_API_SET_ADV_CONFIG_RAW *p_msg;
  1176. if ((p_msg = (tBTA_DM_API_SET_ADV_CONFIG_RAW *)
  1177. osi_malloc(sizeof(tBTA_DM_API_SET_ADV_CONFIG_RAW) + raw_adv_len)) != NULL) {
  1178. p_msg->hdr.event = BTA_DM_API_BLE_SET_ADV_CONFIG_RAW_EVT;
  1179. p_msg->p_adv_data_cback = p_adv_data_cback;
  1180. p_msg->p_raw_adv = (UINT8 *)(p_msg + 1);
  1181. memcpy(p_msg->p_raw_adv, p_raw_adv, raw_adv_len);
  1182. p_msg->raw_adv_len = raw_adv_len;
  1183. bta_sys_sendmsg(p_msg);
  1184. }
  1185. }
  1186. /*******************************************************************************
  1187. **
  1188. ** Function BTA_DmBleSetLongAdv
  1189. **
  1190. ** Description This function is called to set long Advertising data
  1191. **
  1192. ** Parameters adv_data : long advertising data.
  1193. ** adv_data_len : long advertising data length.
  1194. ** p_adv_data_cback : set long adv data complete callback.
  1195. **
  1196. ** Returns None
  1197. **
  1198. *******************************************************************************/
  1199. void BTA_DmBleSetLongAdv (UINT8 *adv_data, UINT32 adv_data_len,
  1200. tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback)
  1201. {
  1202. tBTA_DM_API_SET_LONG_ADV *p_msg;
  1203. if ((p_msg = (tBTA_DM_API_SET_LONG_ADV *)
  1204. osi_malloc(sizeof(tBTA_DM_API_SET_LONG_ADV))) != NULL) {
  1205. p_msg->hdr.event = BTA_DM_API_BLE_SET_LONG_ADV_EVT;
  1206. p_msg->p_adv_data_cback = p_adv_data_cback;
  1207. p_msg->adv_data = adv_data;
  1208. p_msg->adv_data_len = adv_data_len;
  1209. bta_sys_sendmsg(p_msg);
  1210. }
  1211. }
  1212. /*******************************************************************************
  1213. **
  1214. ** Function BTA_DmBleSetScanRsp
  1215. **
  1216. ** Description This function is called to override the BTA scan response.
  1217. **
  1218. ** Parameters Pointer to User defined ADV data structure
  1219. **
  1220. ** Returns None
  1221. **
  1222. *******************************************************************************/
  1223. extern void BTA_DmBleSetScanRsp (tBTA_BLE_AD_MASK data_mask, tBTA_BLE_ADV_DATA *p_adv_cfg,
  1224. tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback)
  1225. {
  1226. tBTA_DM_API_SET_ADV_CONFIG *p_msg;
  1227. if ((p_msg = (tBTA_DM_API_SET_ADV_CONFIG *)
  1228. osi_malloc(sizeof(tBTA_DM_API_SET_ADV_CONFIG))) != NULL) {
  1229. p_msg->hdr.event = BTA_DM_API_BLE_SET_SCAN_RSP_EVT;
  1230. p_msg->data_mask = data_mask;
  1231. p_msg->p_adv_data_cback = p_adv_data_cback;
  1232. p_msg->p_adv_cfg = p_adv_cfg;
  1233. bta_sys_sendmsg(p_msg);
  1234. }
  1235. }
  1236. /*******************************************************************************
  1237. **
  1238. ** Function BTA_DmBleSetScanRspRaw
  1239. **
  1240. ** Description This function is called to set raw scan response data
  1241. **
  1242. ** Parameters p_raw_scan_rsp : raw scan_rspertising data.
  1243. ** raw_scan_rsp_len : raw scan_rspertising data length.
  1244. ** p_scan_rsp_data_cback : set scan_rsp data complete callback.
  1245. **
  1246. ** Returns None
  1247. **
  1248. *******************************************************************************/
  1249. void BTA_DmBleSetScanRspRaw (UINT8 *p_raw_scan_rsp, UINT32 raw_scan_rsp_len,
  1250. tBTA_SET_ADV_DATA_CMPL_CBACK *p_scan_rsp_data_cback)
  1251. {
  1252. tBTA_DM_API_SET_ADV_CONFIG_RAW *p_msg;
  1253. if ((p_msg = (tBTA_DM_API_SET_ADV_CONFIG_RAW *)
  1254. osi_malloc(sizeof(tBTA_DM_API_SET_ADV_CONFIG_RAW) + raw_scan_rsp_len)) != NULL) {
  1255. p_msg->hdr.event = BTA_DM_API_BLE_SET_SCAN_RSP_RAW_EVT;
  1256. p_msg->p_adv_data_cback = p_scan_rsp_data_cback;
  1257. p_msg->p_raw_adv = (UINT8 *)(p_msg + 1);
  1258. memcpy(p_msg->p_raw_adv, p_raw_scan_rsp, raw_scan_rsp_len);
  1259. p_msg->raw_adv_len = raw_scan_rsp_len;
  1260. bta_sys_sendmsg(p_msg);
  1261. }
  1262. }
  1263. /*******************************************************************************
  1264. **
  1265. ** Function BTA_DmUpdateDuplicateExceptionalList
  1266. **
  1267. ** Description This function is called to update duplicate scan exceptional list
  1268. **
  1269. ** Parameters subcode : add, remove or clean duplicate scan exceptional list.
  1270. ** type : device info type.
  1271. ** device_info: device info
  1272. ** p_update_duplicate_ignore_list_cback : update complete callback.
  1273. **
  1274. ** Returns None
  1275. **
  1276. *******************************************************************************/
  1277. void BTA_DmUpdateDuplicateExceptionalList(UINT8 subcode, UINT32 type, BD_ADDR device_info, tBTA_UPDATE_DUPLICATE_EXCEPTIONAL_LIST_CMPL_CBACK p_update_duplicate_exceptional_list_cback)
  1278. {
  1279. tBTA_DM_API_UPDATE_DUPLICATE_EXCEPTIONAL_LIST *p_msg;
  1280. if ((p_msg = (tBTA_DM_API_UPDATE_DUPLICATE_EXCEPTIONAL_LIST *)osi_malloc(sizeof(tBTA_DM_API_UPDATE_DUPLICATE_EXCEPTIONAL_LIST))) != NULL) {
  1281. p_msg->hdr.event = BTA_DM_API_UPDATE_DUPLICATE_EXCEPTIONAL_LIST_EVT;
  1282. p_msg->subcode = subcode;
  1283. p_msg->type = type;
  1284. p_msg->exceptional_list_cb = p_update_duplicate_exceptional_list_cback;
  1285. memcpy(p_msg->device_info, device_info, sizeof(BD_ADDR));
  1286. bta_sys_sendmsg(p_msg);
  1287. }
  1288. }
  1289. /*******************************************************************************
  1290. **
  1291. ** Function BTA_DmBleSetStorageParams
  1292. **
  1293. ** Description This function is called to override the BTA scan response.
  1294. **
  1295. ** Parameters batch_scan_full_max -Max storage space (in %) allocated to full scanning
  1296. ** batch_scan_trunc_max -Max storage space (in %) allocated to truncated scanning
  1297. ** batch_scan_notify_threshold -Setup notification level based on total space
  1298. ** p_setup_cback - Setup callback pointer
  1299. ** p_thres_cback - Threshold callback pointer
  1300. ** p_rep_cback - Reports callback pointer
  1301. ** ref_value - Ref value
  1302. **
  1303. ** Returns None
  1304. **
  1305. *******************************************************************************/
  1306. extern void BTA_DmBleSetStorageParams(UINT8 batch_scan_full_max,
  1307. UINT8 batch_scan_trunc_max,
  1308. UINT8 batch_scan_notify_threshold,
  1309. tBTA_BLE_SCAN_SETUP_CBACK *p_setup_cback,
  1310. tBTA_BLE_SCAN_THRESHOLD_CBACK *p_thres_cback,
  1311. tBTA_BLE_SCAN_REP_CBACK *p_rep_cback,
  1312. tBTA_DM_BLE_REF_VALUE ref_value)
  1313. {
  1314. tBTA_DM_API_SET_STORAGE_CONFIG *p_msg;
  1315. bta_dm_cb.p_setup_cback = p_setup_cback;
  1316. if ((p_msg = (tBTA_DM_API_SET_STORAGE_CONFIG *)
  1317. osi_malloc(sizeof(tBTA_DM_API_SET_STORAGE_CONFIG))) != NULL) {
  1318. p_msg->hdr.event = BTA_DM_API_BLE_SETUP_STORAGE_EVT;
  1319. p_msg->p_setup_cback = bta_ble_scan_setup_cb;
  1320. p_msg->p_thres_cback = p_thres_cback;
  1321. p_msg->p_read_rep_cback = p_rep_cback;
  1322. p_msg->ref_value = ref_value;
  1323. p_msg->batch_scan_full_max = batch_scan_full_max;
  1324. p_msg->batch_scan_trunc_max = batch_scan_trunc_max;
  1325. p_msg->batch_scan_notify_threshold = batch_scan_notify_threshold;
  1326. bta_sys_sendmsg(p_msg);
  1327. }
  1328. }
  1329. /*******************************************************************************
  1330. **
  1331. ** Function BTA_DmBleEnableBatchScan
  1332. **
  1333. ** Description This function is called to enable the batch scan
  1334. **
  1335. ** Parameters scan_mode -Batch scan mode
  1336. ** scan_interval - Scan interval
  1337. ** scan_window - Scan window
  1338. ** discard_rule -Discard rules
  1339. ** addr_type - Address type
  1340. ** ref_value - Reference value
  1341. **
  1342. ** Returns None
  1343. **
  1344. *******************************************************************************/
  1345. extern void BTA_DmBleEnableBatchScan(tBTA_BLE_BATCH_SCAN_MODE scan_mode,
  1346. UINT32 scan_interval, UINT32 scan_window,
  1347. tBTA_BLE_DISCARD_RULE discard_rule,
  1348. tBLE_ADDR_TYPE addr_type,
  1349. tBTA_DM_BLE_REF_VALUE ref_value)
  1350. {
  1351. tBTA_DM_API_ENABLE_SCAN *p_msg;
  1352. if ((p_msg = (tBTA_DM_API_ENABLE_SCAN *) osi_malloc(sizeof(tBTA_DM_API_ENABLE_SCAN))) != NULL) {
  1353. p_msg->hdr.event = BTA_DM_API_BLE_ENABLE_BATCH_SCAN_EVT;
  1354. p_msg->scan_mode = scan_mode;
  1355. p_msg->scan_int = scan_interval;
  1356. p_msg->scan_window = scan_window;
  1357. p_msg->discard_rule = discard_rule;
  1358. p_msg->addr_type = addr_type;
  1359. p_msg->ref_value = ref_value;
  1360. bta_sys_sendmsg(p_msg);
  1361. }
  1362. }
  1363. /*******************************************************************************
  1364. **
  1365. ** Function BTA_DmBleDisableBatchScan
  1366. **
  1367. ** Description This function is called to disable the batch scan
  1368. **
  1369. ** Parameters ref_value - Reference value
  1370. **
  1371. ** Returns None
  1372. **
  1373. *******************************************************************************/
  1374. extern void BTA_DmBleDisableBatchScan(tBTA_DM_BLE_REF_VALUE ref_value)
  1375. {
  1376. tBTA_DM_API_DISABLE_SCAN *p_msg;
  1377. if ((p_msg = (tBTA_DM_API_DISABLE_SCAN *)
  1378. osi_malloc(sizeof(tBTA_DM_API_DISABLE_SCAN))) != NULL) {
  1379. p_msg->hdr.event = BTA_DM_API_BLE_DISABLE_BATCH_SCAN_EVT;
  1380. p_msg->ref_value = ref_value;
  1381. bta_sys_sendmsg(p_msg);
  1382. }
  1383. }
  1384. /*******************************************************************************
  1385. **
  1386. ** Function BTA_DmBleReadScanReports
  1387. **
  1388. ** Description This function is called to read scan reports
  1389. **
  1390. ** Parameters scan_type -Batch scan mode
  1391. ** ref_value - Reference value
  1392. **
  1393. ** Returns None
  1394. **
  1395. *******************************************************************************/
  1396. extern void BTA_DmBleReadScanReports(tBTA_BLE_BATCH_SCAN_MODE scan_type,
  1397. tBTA_DM_BLE_REF_VALUE ref_value)
  1398. {
  1399. tBTA_DM_API_READ_SCAN_REPORTS *p_msg;
  1400. if ((p_msg = (tBTA_DM_API_READ_SCAN_REPORTS *)
  1401. osi_malloc(sizeof(tBTA_DM_API_READ_SCAN_REPORTS))) != NULL) {
  1402. p_msg->hdr.event = BTA_DM_API_BLE_READ_SCAN_REPORTS_EVT;
  1403. p_msg->scan_type = scan_type;
  1404. p_msg->ref_value = ref_value;
  1405. bta_sys_sendmsg(p_msg);
  1406. }
  1407. }
  1408. /*******************************************************************************
  1409. **
  1410. ** Function BTA_DmBleTrackAdvertiser
  1411. **
  1412. ** Description This function is called to track advertiser
  1413. **
  1414. ** Parameters ref_value - Reference value
  1415. ** p_track_adv_cback - Track ADV callback
  1416. **
  1417. ** Returns None
  1418. **
  1419. *******************************************************************************/
  1420. extern void BTA_DmBleTrackAdvertiser(tBTA_DM_BLE_REF_VALUE ref_value,
  1421. tBTA_BLE_TRACK_ADV_CBACK *p_track_adv_cback)
  1422. {
  1423. tBTA_DM_API_TRACK_ADVERTISER *p_msg;
  1424. if ((p_msg = (tBTA_DM_API_TRACK_ADVERTISER *)
  1425. osi_malloc(sizeof(tBTA_DM_API_TRACK_ADVERTISER))) != NULL) {
  1426. p_msg->hdr.event = BTA_DM_API_BLE_TRACK_ADVERTISER_EVT;
  1427. p_msg->p_track_adv_cback = p_track_adv_cback;
  1428. p_msg->ref_value = ref_value;
  1429. bta_sys_sendmsg(p_msg);
  1430. }
  1431. }
  1432. #endif
  1433. /*******************************************************************************
  1434. ** BLE ADV data management API
  1435. ********************************************************************************/
  1436. #if BLE_INCLUDED == TRUE
  1437. /*******************************************************************************
  1438. **
  1439. ** Function BTA_DmBleBroadcast
  1440. **
  1441. ** Description This function starts or stops LE broadcasting.
  1442. **
  1443. ** Parameters start: start or stop broadcast.
  1444. **
  1445. ** Returns None
  1446. **
  1447. *******************************************************************************/
  1448. extern void BTA_DmBleBroadcast (BOOLEAN start, tBTA_START_STOP_ADV_CMPL_CBACK *p_start_stop_adv_cb)
  1449. {
  1450. tBTA_DM_API_BLE_OBSERVE *p_msg;
  1451. APPL_TRACE_API("BTA_DmBleBroadcast: start = %d \n", start);
  1452. if ((p_msg = (tBTA_DM_API_BLE_OBSERVE *) osi_malloc(sizeof(tBTA_DM_API_BLE_OBSERVE))) != NULL) {
  1453. memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_OBSERVE));
  1454. p_msg->hdr.event = BTA_DM_API_BLE_BROADCAST_EVT;
  1455. p_msg->start = start;
  1456. if (start == FALSE){
  1457. p_msg->p_stop_adv_cback= p_start_stop_adv_cb;
  1458. }
  1459. bta_sys_sendmsg(p_msg);
  1460. }
  1461. }
  1462. #endif
  1463. /*******************************************************************************
  1464. **
  1465. ** Function BTA_DmBleSetBgConnType
  1466. **
  1467. ** Description This function is called to set BLE connectable mode for a
  1468. ** peripheral device.
  1469. **
  1470. ** Parameters bg_conn_type: it can be auto connection, or selective connection.
  1471. ** p_select_cback: callback function when selective connection procedure
  1472. ** is being used.
  1473. **
  1474. ** Returns void
  1475. **
  1476. *******************************************************************************/
  1477. void BTA_DmBleSetBgConnType(tBTA_DM_BLE_CONN_TYPE bg_conn_type, tBTA_DM_BLE_SEL_CBACK *p_select_cback)
  1478. {
  1479. #if BLE_INCLUDED == TRUE
  1480. tBTA_DM_API_BLE_SET_BG_CONN_TYPE *p_msg;
  1481. if ((p_msg = (tBTA_DM_API_BLE_SET_BG_CONN_TYPE *) osi_malloc(sizeof(tBTA_DM_API_BLE_SET_BG_CONN_TYPE))) != NULL) {
  1482. memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_SET_BG_CONN_TYPE));
  1483. p_msg->hdr.event = BTA_DM_API_BLE_SET_BG_CONN_TYPE;
  1484. p_msg->bg_conn_type = bg_conn_type;
  1485. p_msg->p_select_cback = p_select_cback;
  1486. bta_sys_sendmsg(p_msg);
  1487. }
  1488. #endif
  1489. }
  1490. /*******************************************************************************
  1491. **
  1492. ** Function bta_dm_discover_send_msg
  1493. **
  1494. ** Description This function send discover message to BTA task.
  1495. **
  1496. ** Returns void
  1497. **
  1498. *******************************************************************************/
  1499. #if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE && SDP_INCLUDED == TRUE
  1500. static void bta_dm_discover_send_msg(BD_ADDR bd_addr, tBTA_SERVICE_MASK_EXT *p_services,
  1501. tBTA_DM_SEARCH_CBACK *p_cback, BOOLEAN sdp_search,
  1502. tBTA_TRANSPORT transport)
  1503. {
  1504. tBTA_DM_API_DISCOVER *p_msg;
  1505. UINT16 len = p_services ? (sizeof(tBTA_DM_API_DISCOVER) +
  1506. sizeof(tBT_UUID) * p_services->num_uuid) :
  1507. sizeof(tBTA_DM_API_DISCOVER);
  1508. if ((p_msg = (tBTA_DM_API_DISCOVER *) osi_malloc(len)) != NULL) {
  1509. memset(p_msg, 0, len);
  1510. p_msg->hdr.event = BTA_DM_API_DISCOVER_EVT;
  1511. bdcpy(p_msg->bd_addr, bd_addr);
  1512. p_msg->p_cback = p_cback;
  1513. p_msg->sdp_search = sdp_search;
  1514. p_msg->transport = transport;
  1515. if (p_services != NULL) {
  1516. #if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE
  1517. p_msg->services = p_services->srvc_mask;
  1518. p_msg->num_uuid = p_services->num_uuid;
  1519. if (p_services->num_uuid != 0) {
  1520. p_msg->p_uuid = (tBT_UUID *)(p_msg + 1);
  1521. memcpy(p_msg->p_uuid, p_services->p_uuid, sizeof(tBT_UUID) * p_services->num_uuid);
  1522. }
  1523. #endif
  1524. }
  1525. bta_sys_sendmsg(p_msg);
  1526. }
  1527. }
  1528. #endif
  1529. /*******************************************************************************
  1530. **
  1531. ** Function BTA_DmDiscoverByTransport
  1532. **
  1533. ** Description This function does service discovery on particular transport
  1534. ** for services of a
  1535. ** peer device. When services.num_uuid is 0, it indicates all
  1536. ** GATT based services are to be searched; otherwise a list of
  1537. ** UUID of interested services should be provided through
  1538. ** p_services->p_uuid.
  1539. **
  1540. **
  1541. **
  1542. ** Returns void
  1543. **
  1544. *******************************************************************************/
  1545. void BTA_DmDiscoverByTransport(BD_ADDR bd_addr, tBTA_SERVICE_MASK_EXT *p_services,
  1546. tBTA_DM_SEARCH_CBACK *p_cback, BOOLEAN sdp_search,
  1547. tBTA_TRANSPORT transport)
  1548. {
  1549. #if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE && SDP_INCLUDED == TRUE
  1550. bta_dm_discover_send_msg(bd_addr, p_services, p_cback, sdp_search, transport);
  1551. #endif
  1552. }
  1553. /*******************************************************************************
  1554. **
  1555. ** Function BTA_DmDiscoverExt
  1556. **
  1557. ** Description This function does service discovery for services of a
  1558. ** peer device. When services.num_uuid is 0, it indicates all
  1559. ** GATT based services are to be searched; other wise a list of
  1560. ** UUID of interested services should be provided through
  1561. ** p_services->p_uuid.
  1562. **
  1563. **
  1564. **
  1565. ** Returns void
  1566. **
  1567. *******************************************************************************/
  1568. void BTA_DmDiscoverExt(BD_ADDR bd_addr, tBTA_SERVICE_MASK_EXT *p_services,
  1569. tBTA_DM_SEARCH_CBACK *p_cback, BOOLEAN sdp_search)
  1570. {
  1571. #if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE && SDP_INCLUDED == TRUE
  1572. bta_dm_discover_send_msg(bd_addr, p_services, p_cback, sdp_search, BTA_TRANSPORT_UNKNOWN);
  1573. #endif
  1574. }
  1575. /*******************************************************************************
  1576. **
  1577. ** Function BTA_DmSearchExt
  1578. **
  1579. ** Description This function searches for peer Bluetooth devices. It performs
  1580. ** an inquiry and gets the remote name for devices. Service
  1581. ** discovery is done if services is non zero
  1582. **
  1583. ** Parameters p_dm_inq: inquiry conditions
  1584. ** p_services: if service is not empty, service discovery will be done.
  1585. ** for all GATT based service condition, put num_uuid, and
  1586. ** p_uuid is the pointer to the list of UUID values.
  1587. ** p_cback: callback functino when search is completed.
  1588. **
  1589. **
  1590. **
  1591. ** Returns void
  1592. **
  1593. *******************************************************************************/
  1594. void BTA_DmSearchExt(tBTA_DM_INQ *p_dm_inq, tBTA_SERVICE_MASK_EXT *p_services, tBTA_DM_SEARCH_CBACK *p_cback)
  1595. {
  1596. #if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE
  1597. tBTA_DM_API_SEARCH *p_msg;
  1598. UINT16 len = p_services ? (sizeof(tBTA_DM_API_SEARCH) + sizeof(tBT_UUID) * p_services->num_uuid) :
  1599. sizeof(tBTA_DM_API_SEARCH);
  1600. if ((p_msg = (tBTA_DM_API_SEARCH *) osi_malloc(len)) != NULL) {
  1601. memset(p_msg, 0, len);
  1602. p_msg->hdr.event = BTA_DM_API_SEARCH_EVT;
  1603. memcpy(&p_msg->inq_params, p_dm_inq, sizeof(tBTA_DM_INQ));
  1604. p_msg->p_cback = p_cback;
  1605. p_msg->rs_res = BTA_DM_RS_NONE;
  1606. if (p_services != NULL) {
  1607. p_msg->services = p_services->srvc_mask;
  1608. p_msg->num_uuid = p_services->num_uuid;
  1609. if (p_services->num_uuid != 0) {
  1610. p_msg->p_uuid = (tBT_UUID *)(p_msg + 1);
  1611. memcpy(p_msg->p_uuid, p_services->p_uuid, sizeof(tBT_UUID) * p_services->num_uuid);
  1612. } else {
  1613. p_msg->p_uuid = NULL;
  1614. }
  1615. }
  1616. bta_sys_sendmsg(p_msg);
  1617. }
  1618. #else
  1619. UNUSED(p_dm_inq);
  1620. UNUSED(p_services);
  1621. UNUSED(p_cback);
  1622. #endif
  1623. }
  1624. /*******************************************************************************
  1625. **
  1626. ** Function BTA_DmBleUpdateConnectionParam
  1627. **
  1628. ** Description Update connection parameters, can only be used when connection is up.
  1629. **
  1630. ** Parameters: bd_addr - BD address of the peer
  1631. ** min_int - minimum connection interval, [0x0004~ 0x4000]
  1632. ** max_int - maximum connection interval, [0x0004~ 0x4000]
  1633. ** latency - slave latency [0 ~ 500]
  1634. ** timeout - supervision timeout [0x000a ~ 0xc80]
  1635. **
  1636. ** Returns void
  1637. **
  1638. *******************************************************************************/
  1639. void BTA_DmBleUpdateConnectionParam(BD_ADDR bd_addr, UINT16 min_int,
  1640. UINT16 max_int, UINT16 latency,
  1641. UINT16 timeout)
  1642. {
  1643. #if BLE_INCLUDED == TRUE
  1644. tBTA_DM_API_UPDATE_CONN_PARAM *p_msg;
  1645. p_msg = (tBTA_DM_API_UPDATE_CONN_PARAM *) osi_malloc(sizeof(tBTA_DM_API_UPDATE_CONN_PARAM));
  1646. if (p_msg != NULL) {
  1647. memset(p_msg, 0, sizeof(tBTA_DM_API_UPDATE_CONN_PARAM));
  1648. p_msg->hdr.event = BTA_DM_API_UPDATE_CONN_PARAM_EVT;
  1649. bdcpy(p_msg->bd_addr, bd_addr);
  1650. p_msg->min_int = min_int;
  1651. p_msg->max_int = max_int;
  1652. p_msg->latency = latency;
  1653. p_msg->timeout = timeout;
  1654. bta_sys_sendmsg(p_msg);
  1655. }
  1656. #endif
  1657. }
  1658. #if BLE_INCLUDED == TRUE
  1659. /*******************************************************************************
  1660. **
  1661. ** Function BTA_DmBleConfigLocalPrivacy
  1662. **
  1663. ** Description Enable/disable privacy on the local device
  1664. **
  1665. ** Parameters: privacy_enable - enable/disabe privacy on remote device.
  1666. **
  1667. ** Returns void
  1668. **
  1669. *******************************************************************************/
  1670. void BTA_DmBleConfigLocalPrivacy(BOOLEAN privacy_enable, tBTA_SET_LOCAL_PRIVACY_CBACK *set_local_privacy_cback)
  1671. {
  1672. ///This function used the irk to generate the resolve address
  1673. #if BLE_INCLUDED == TRUE && BLE_PRIVACY_SPT == TRUE
  1674. tBTA_DM_API_LOCAL_PRIVACY *p_msg;
  1675. if ((p_msg = (tBTA_DM_API_LOCAL_PRIVACY *) osi_malloc(sizeof(tBTA_DM_API_ENABLE_PRIVACY))) != NULL) {
  1676. memset (p_msg, 0, sizeof(tBTA_DM_API_LOCAL_PRIVACY));
  1677. p_msg->hdr.event = BTA_DM_API_LOCAL_PRIVACY_EVT;
  1678. p_msg->privacy_enable = privacy_enable;
  1679. p_msg->set_local_privacy_cback = set_local_privacy_cback;
  1680. bta_sys_sendmsg(p_msg);
  1681. }
  1682. #else
  1683. UNUSED (privacy_enable);
  1684. #endif
  1685. }
  1686. /*******************************************************************************
  1687. **
  1688. ** Function BTA_DmBleConfigLocalIcon
  1689. **
  1690. ** Description set gap local icon
  1691. **
  1692. ** Parameters: icon - appearance value.
  1693. **
  1694. ** Returns void
  1695. **
  1696. *******************************************************************************/
  1697. void BTA_DmBleConfigLocalIcon(uint16_t icon)
  1698. {
  1699. tBTA_DM_API_LOCAL_ICON *p_msg;
  1700. if ((p_msg = (tBTA_DM_API_LOCAL_ICON *) osi_malloc(sizeof(tBTA_DM_API_LOCAL_ICON))) != NULL) {
  1701. memset (p_msg, 0, sizeof(tBTA_DM_API_LOCAL_ICON));
  1702. p_msg->hdr.event = BTA_DM_API_LOCAL_ICON_EVT;
  1703. p_msg->icon = icon;
  1704. bta_sys_sendmsg(p_msg);
  1705. }
  1706. }
  1707. /*******************************************************************************
  1708. **
  1709. ** Function BTA_BleEnableAdvInstance
  1710. **
  1711. ** Description This function enable a Multi-ADV instance with the specififed
  1712. ** adv parameters
  1713. **
  1714. ** Parameters p_params: pointer to the adv parameter structure.
  1715. ** p_cback: callback function associated to this adv instance.
  1716. ** p_ref: reference data pointer to this adv instance.
  1717. **
  1718. ** Returns BTA_SUCCESS if command started successfully; otherwise failure.
  1719. **
  1720. *******************************************************************************/
  1721. void BTA_BleEnableAdvInstance (tBTA_BLE_ADV_PARAMS *p_params,
  1722. tBTA_BLE_MULTI_ADV_CBACK *p_cback,
  1723. void *p_ref)
  1724. {
  1725. ///This function just used for vendor debug
  1726. tBTA_DM_API_BLE_MULTI_ADV_ENB *p_msg;
  1727. UINT16 len = sizeof(tBTA_BLE_ADV_PARAMS) + sizeof(tBTA_DM_API_BLE_MULTI_ADV_ENB);
  1728. APPL_TRACE_API ("BTA_BleEnableAdvInstance");
  1729. if ((p_msg = (tBTA_DM_API_BLE_MULTI_ADV_ENB *) osi_malloc(len)) != NULL) {
  1730. memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_MULTI_ADV_ENB));
  1731. p_msg->hdr.event = BTA_DM_API_BLE_MULTI_ADV_ENB_EVT;
  1732. p_msg->p_cback = (void *)p_cback;
  1733. if (p_params != NULL) {
  1734. p_msg->p_params = (void *)(p_msg + 1);
  1735. memcpy(p_msg->p_params, p_params, sizeof(tBTA_BLE_ADV_PARAMS));
  1736. }
  1737. p_msg->p_ref = p_ref;
  1738. bta_sys_sendmsg(p_msg);
  1739. }
  1740. }
  1741. /*******************************************************************************
  1742. **
  1743. ** Function BTA_BleUpdateAdvInstParam
  1744. **
  1745. ** Description This function update a Multi-ADV instance with the specififed
  1746. ** adv parameters.
  1747. **
  1748. ** Parameters inst_id: Adv instance to update the parameter.
  1749. ** p_params: pointer to the adv parameter structure.
  1750. **
  1751. ** Returns BTA_SUCCESS if command started successfully; otherwise failure.
  1752. **
  1753. *******************************************************************************/
  1754. void BTA_BleUpdateAdvInstParam (UINT8 inst_id, tBTA_BLE_ADV_PARAMS *p_params)
  1755. {
  1756. ///This function just used for vendor debug
  1757. tBTA_DM_API_BLE_MULTI_ADV_PARAM *p_msg;
  1758. UINT16 len = sizeof(tBTA_BLE_ADV_PARAMS) + sizeof(tBTA_DM_API_BLE_MULTI_ADV_PARAM);
  1759. APPL_TRACE_API ("BTA_BleUpdateAdvInstParam");
  1760. if ((p_msg = (tBTA_DM_API_BLE_MULTI_ADV_PARAM *) osi_malloc(len)) != NULL) {
  1761. memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_MULTI_ADV_PARAM));
  1762. p_msg->hdr.event = BTA_DM_API_BLE_MULTI_ADV_PARAM_UPD_EVT;
  1763. p_msg->inst_id = inst_id;
  1764. p_msg->p_params = (void *)(p_msg + 1);
  1765. memcpy(p_msg->p_params, p_params, sizeof(tBTA_BLE_ADV_PARAMS));
  1766. bta_sys_sendmsg(p_msg);
  1767. }
  1768. }
  1769. /*******************************************************************************
  1770. **
  1771. ** Function BTA_BleCfgAdvInstData
  1772. **
  1773. ** Description This function configure a Multi-ADV instance with the specififed
  1774. ** adv data or scan response data.
  1775. **
  1776. ** Parameter inst_id: Adv instance to configure the adv data or scan response.
  1777. ** is_scan_rsp: is the data scan response or adv data.
  1778. ** data_mask: adv data type as bit mask.
  1779. ** p_data: pointer to the ADV data structure tBTA_BLE_ADV_DATA. This
  1780. ** memory space can not be freed until BTA_BLE_MULTI_ADV_DATA_EVT
  1781. ** is sent to application.
  1782. **
  1783. ** Returns BTA_SUCCESS if command started successfully; otherwise failure.
  1784. **
  1785. *******************************************************************************/
  1786. void BTA_BleCfgAdvInstData (UINT8 inst_id, BOOLEAN is_scan_rsp,
  1787. tBTA_BLE_AD_MASK data_mask,
  1788. tBTA_BLE_ADV_DATA *p_data)
  1789. {
  1790. ///This function just used for vendor debug
  1791. tBTA_DM_API_BLE_MULTI_ADV_DATA *p_msg;
  1792. UINT16 len = sizeof(tBTA_DM_API_BLE_MULTI_ADV_DATA) ;
  1793. APPL_TRACE_API ("BTA_BleCfgAdvInstData");
  1794. if ((p_msg = (tBTA_DM_API_BLE_MULTI_ADV_DATA *) osi_malloc(len)) != NULL) {
  1795. memset(p_msg, 0, len);
  1796. p_msg->hdr.event = BTA_DM_API_BLE_MULTI_ADV_DATA_EVT;
  1797. p_msg->inst_id = inst_id;
  1798. p_msg->is_scan_rsp = is_scan_rsp;
  1799. p_msg->data_mask = data_mask;
  1800. p_msg->p_data = p_data;
  1801. bta_sys_sendmsg(p_msg);
  1802. }
  1803. }
  1804. /*******************************************************************************
  1805. **
  1806. ** Function BTA_BleDisableAdvInstance
  1807. **
  1808. ** Description This function disable a Multi-ADV instance.
  1809. **
  1810. ** Parameter inst_id: instance ID to disable.
  1811. **
  1812. ** Returns BTA_SUCCESS if command started successfully; otherwise failure.
  1813. **
  1814. *******************************************************************************/
  1815. void BTA_BleDisableAdvInstance (UINT8 inst_id) //this function just used for vendor debug
  1816. {
  1817. tBTA_DM_API_BLE_MULTI_ADV_DISABLE *p_msg;
  1818. APPL_TRACE_API ("BTA_BleDisableAdvInstance: %d", inst_id);
  1819. if ((p_msg = (tBTA_DM_API_BLE_MULTI_ADV_DISABLE *)
  1820. osi_malloc(sizeof(tBTA_DM_API_BLE_MULTI_ADV_DISABLE))) != NULL) {
  1821. memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_MULTI_ADV_DISABLE));
  1822. p_msg->hdr.event = BTA_DM_API_BLE_MULTI_ADV_DISABLE_EVT;
  1823. p_msg->inst_id = inst_id;
  1824. bta_sys_sendmsg(p_msg);
  1825. }
  1826. }
  1827. /*******************************************************************************
  1828. **
  1829. ** Function BTA_DmBleCfgFilterCondition
  1830. **
  1831. ** Description This function is called to configure the adv data payload filter
  1832. ** condition.
  1833. **
  1834. ** Parameters action: to read/write/clear
  1835. ** cond_type: filter condition type
  1836. ** filt_index - Filter index
  1837. ** p_cond: filter condition parameter
  1838. ** p_cmpl_back - Command completed callback
  1839. ** ref_value - Reference value
  1840. **
  1841. ** Returns void
  1842. **
  1843. *******************************************************************************/
  1844. void BTA_DmBleCfgFilterCondition(tBTA_DM_BLE_SCAN_COND_OP action,
  1845. tBTA_DM_BLE_PF_COND_TYPE cond_type,
  1846. tBTA_DM_BLE_PF_FILT_INDEX filt_index,
  1847. tBTA_DM_BLE_PF_COND_PARAM *p_cond,
  1848. tBTA_DM_BLE_PF_CFG_CBACK *p_cmpl_cback,
  1849. tBTA_DM_BLE_REF_VALUE ref_value)
  1850. {
  1851. #if BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE
  1852. tBTA_DM_API_CFG_FILTER_COND *p_msg;
  1853. APPL_TRACE_API ("BTA_DmBleCfgFilterCondition: %d, %d", action, cond_type);
  1854. UINT16 len = sizeof(tBTA_DM_API_CFG_FILTER_COND) +
  1855. sizeof(tBTA_DM_BLE_PF_COND_PARAM);
  1856. UINT8 *p;
  1857. if (NULL != p_cond) {
  1858. switch (cond_type) {
  1859. case BTA_DM_BLE_PF_SRVC_DATA_PATTERN:
  1860. case BTA_DM_BLE_PF_MANU_DATA:
  1861. /* Length of pattern and pattern mask and other elements in */
  1862. /* tBTA_DM_BLE_PF_MANU_COND */
  1863. len += ((p_cond->manu_data.data_len) * 2) +
  1864. sizeof(UINT16) + sizeof(UINT16) + sizeof(UINT8);
  1865. break;
  1866. case BTA_DM_BLE_PF_LOCAL_NAME:
  1867. len += ((p_cond->local_name.data_len) + sizeof(UINT8));
  1868. break;
  1869. case BTM_BLE_PF_SRVC_UUID:
  1870. case BTM_BLE_PF_SRVC_SOL_UUID:
  1871. len += sizeof(tBLE_BD_ADDR) + sizeof(tBTA_DM_BLE_PF_COND_MASK);
  1872. break;
  1873. default:
  1874. break;
  1875. }
  1876. }
  1877. if ((p_msg = (tBTA_DM_API_CFG_FILTER_COND *) osi_malloc(len)) != NULL) {
  1878. memset (p_msg, 0, len);
  1879. p_msg->hdr.event = BTA_DM_API_CFG_FILTER_COND_EVT;
  1880. p_msg->action = action;
  1881. p_msg->cond_type = cond_type;
  1882. p_msg->filt_index = filt_index;
  1883. p_msg->p_filt_cfg_cback = p_cmpl_cback;
  1884. p_msg->ref_value = ref_value;
  1885. if (p_cond) {
  1886. p_msg->p_cond_param = (tBTA_DM_BLE_PF_COND_PARAM *)(p_msg + 1);
  1887. memcpy(p_msg->p_cond_param, p_cond, sizeof(tBTA_DM_BLE_PF_COND_PARAM));
  1888. p = (UINT8 *)(p_msg->p_cond_param + 1);
  1889. if (cond_type == BTA_DM_BLE_PF_SRVC_DATA_PATTERN ||
  1890. cond_type == BTA_DM_BLE_PF_MANU_DATA) {
  1891. p_msg->p_cond_param->manu_data.p_pattern = p;
  1892. p_msg->p_cond_param->manu_data.data_len = p_cond->manu_data.data_len;
  1893. memcpy(p_msg->p_cond_param->manu_data.p_pattern, p_cond->manu_data.p_pattern,
  1894. p_cond->manu_data.data_len);
  1895. p += p_cond->manu_data.data_len;
  1896. if (cond_type == BTA_DM_BLE_PF_MANU_DATA) {
  1897. p_msg->p_cond_param->manu_data.company_id_mask =
  1898. p_cond->manu_data.company_id_mask;
  1899. if ( p_cond->manu_data.p_pattern_mask != NULL) {
  1900. p_msg->p_cond_param->manu_data.p_pattern_mask = p;
  1901. memcpy(p_msg->p_cond_param->manu_data.p_pattern_mask,
  1902. p_cond->manu_data.p_pattern_mask, p_cond->manu_data.data_len);
  1903. }
  1904. }
  1905. } else if (cond_type == BTA_DM_BLE_PF_LOCAL_NAME) {
  1906. p_msg->p_cond_param->local_name.p_data = p;
  1907. p_msg->p_cond_param->local_name.data_len =
  1908. p_cond->local_name.data_len;
  1909. memcpy(p_msg->p_cond_param->local_name.p_data,
  1910. p_cond->local_name.p_data, p_cond->local_name.data_len);
  1911. } else if ((cond_type == BTM_BLE_PF_SRVC_UUID
  1912. || cond_type == BTM_BLE_PF_SRVC_SOL_UUID)) {
  1913. if (p_cond->srvc_uuid.p_target_addr != NULL) {
  1914. p_msg->p_cond_param->srvc_uuid.p_target_addr = (tBLE_BD_ADDR *)(p);
  1915. p_msg->p_cond_param->srvc_uuid.p_target_addr->type =
  1916. p_cond->srvc_uuid.p_target_addr->type;
  1917. memcpy(p_msg->p_cond_param->srvc_uuid.p_target_addr->bda,
  1918. p_cond->srvc_uuid.p_target_addr->bda, BD_ADDR_LEN);
  1919. p = (UINT8 *)( p_msg->p_cond_param->srvc_uuid.p_target_addr + 1);
  1920. }
  1921. if (p_cond->srvc_uuid.p_uuid_mask) {
  1922. p_msg->p_cond_param->srvc_uuid.p_uuid_mask = (tBTA_DM_BLE_PF_COND_MASK *)p;
  1923. memcpy(p_msg->p_cond_param->srvc_uuid.p_uuid_mask,
  1924. p_cond->srvc_uuid.p_uuid_mask, sizeof(tBTA_DM_BLE_PF_COND_MASK));
  1925. }
  1926. }
  1927. }
  1928. bta_sys_sendmsg(p_msg);
  1929. }
  1930. #else
  1931. UNUSED(action);
  1932. UNUSED(cond_type);
  1933. UNUSED(filt_index);
  1934. UNUSED(p_cond);
  1935. UNUSED(p_cmpl_cback);
  1936. UNUSED(ref_value);
  1937. #endif
  1938. }
  1939. /*******************************************************************************
  1940. **
  1941. ** Function BTA_DmBleScanFilterSetup
  1942. **
  1943. ** Description This function is called to setup the adv data payload filter param
  1944. **
  1945. ** Parameters p_target: enable the filter condition on a target device; if NULL
  1946. ** filt_index - Filter index
  1947. ** p_filt_params -Filter parameters
  1948. ** ref_value - Reference value
  1949. ** action - Add, delete or clear
  1950. ** p_cmpl_back - Command completed callback
  1951. **
  1952. ** Returns void
  1953. **
  1954. *******************************************************************************/
  1955. void BTA_DmBleScanFilterSetup(UINT8 action, tBTA_DM_BLE_PF_FILT_INDEX filt_index,
  1956. tBTA_DM_BLE_PF_FILT_PARAMS *p_filt_params,
  1957. tBLE_BD_ADDR *p_target,
  1958. tBTA_DM_BLE_PF_PARAM_CBACK *p_cmpl_cback,
  1959. tBTA_DM_BLE_REF_VALUE ref_value)
  1960. {
  1961. #if BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE
  1962. tBTA_DM_API_SCAN_FILTER_PARAM_SETUP *p_msg;
  1963. APPL_TRACE_API ("BTA_DmBleScanFilterSetup: %d", action);
  1964. UINT16 len = sizeof(tBTA_DM_API_SCAN_FILTER_PARAM_SETUP) + sizeof(tBLE_BD_ADDR);
  1965. if ((p_msg = (tBTA_DM_API_SCAN_FILTER_PARAM_SETUP *) osi_malloc(len)) != NULL) {
  1966. memset (p_msg, 0, len);
  1967. p_msg->hdr.event = BTA_DM_API_SCAN_FILTER_SETUP_EVT;
  1968. p_msg->action = action;
  1969. p_msg->filt_index = filt_index;
  1970. if (p_filt_params) {
  1971. memcpy(&p_msg->filt_params, p_filt_params, sizeof(tBTA_DM_BLE_PF_FILT_PARAMS));
  1972. }
  1973. p_msg->p_filt_param_cback = p_cmpl_cback;
  1974. p_msg->ref_value = ref_value;
  1975. if (p_target) {
  1976. p_msg->p_target = (tBLE_BD_ADDR *)(p_msg + 1);
  1977. memcpy(p_msg->p_target, p_target, sizeof(tBLE_BD_ADDR));
  1978. }
  1979. bta_sys_sendmsg(p_msg);
  1980. }
  1981. #else
  1982. UNUSED(action);
  1983. UNUSED(filt_index);
  1984. UNUSED(p_filt_params);
  1985. UNUSED(p_target);
  1986. UNUSED(p_cmpl_cback);
  1987. UNUSED(ref_value);
  1988. #endif
  1989. }
  1990. /*******************************************************************************
  1991. **
  1992. ** Function BTA_DmBleGetEnergyInfo
  1993. **
  1994. ** Description This function is called to obtain the energy info
  1995. **
  1996. ** Parameters p_cmpl_cback - Command complete callback
  1997. **
  1998. ** Returns void
  1999. **
  2000. *******************************************************************************/
  2001. void BTA_DmBleGetEnergyInfo(tBTA_BLE_ENERGY_INFO_CBACK *p_cmpl_cback)
  2002. {
  2003. tBTA_DM_API_ENERGY_INFO *p_msg;
  2004. APPL_TRACE_API ("BTA_DmBleGetEnergyInfo");
  2005. UINT16 len = sizeof(tBTA_DM_API_ENERGY_INFO) + sizeof(tBLE_BD_ADDR);
  2006. if ((p_msg = (tBTA_DM_API_ENERGY_INFO *) osi_malloc(len)) != NULL) {
  2007. memset (p_msg, 0, len);
  2008. p_msg->hdr.event = BTA_DM_API_BLE_ENERGY_INFO_EVT;
  2009. p_msg->p_energy_info_cback = p_cmpl_cback;
  2010. bta_sys_sendmsg(p_msg);
  2011. }
  2012. }
  2013. /*******************************************************************************
  2014. **
  2015. ** Function BTA_DmEnableScanFilter
  2016. **
  2017. ** Description This function is called to enable the adv data payload filter
  2018. **
  2019. ** Parameters action - enable or disable the APCF feature
  2020. ** p_cmpl_cback - Command completed callback
  2021. ** ref_value - Reference value
  2022. **
  2023. ** Returns void
  2024. **
  2025. *******************************************************************************/
  2026. void BTA_DmEnableScanFilter(UINT8 action, tBTA_DM_BLE_PF_STATUS_CBACK *p_cmpl_cback,
  2027. tBTA_DM_BLE_REF_VALUE ref_value)
  2028. {
  2029. #if BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE
  2030. tBTA_DM_API_ENABLE_SCAN_FILTER *p_msg;
  2031. APPL_TRACE_API ("BTA_DmEnableScanFilter: %d\n", action);
  2032. UINT16 len = sizeof(tBTA_DM_API_ENABLE_SCAN_FILTER) + sizeof(tBLE_BD_ADDR);
  2033. if ((p_msg = (tBTA_DM_API_ENABLE_SCAN_FILTER *) osi_malloc(len)) != NULL) {
  2034. memset (p_msg, 0, len);
  2035. p_msg->hdr.event = BTA_DM_API_SCAN_FILTER_ENABLE_EVT;
  2036. p_msg->action = action;
  2037. p_msg->ref_value = ref_value;
  2038. p_msg->p_filt_status_cback = p_cmpl_cback;
  2039. bta_sys_sendmsg(p_msg);
  2040. }
  2041. #else
  2042. UNUSED(action);
  2043. UNUSED(p_cmpl_cback);
  2044. UNUSED(ref_value);
  2045. #endif
  2046. }
  2047. /*******************************************************************************
  2048. **
  2049. ** Function BTA_DmBleUpdateConnectionParams
  2050. **
  2051. ** Description Update connection parameters, can only be used when connection is up.
  2052. **
  2053. ** Parameters: bd_addr - BD address of the peer
  2054. ** min_int - minimum connection interval, [0x0004~ 0x4000]
  2055. ** max_int - maximum connection interval, [0x0004~ 0x4000]
  2056. ** latency - slave latency [0 ~ 500]
  2057. ** timeout - supervision timeout [0x000a ~ 0xc80]
  2058. **
  2059. ** Returns void
  2060. **
  2061. *******************************************************************************/
  2062. void BTA_DmBleUpdateConnectionParams(BD_ADDR bd_addr, UINT16 min_int, UINT16 max_int,
  2063. UINT16 latency, UINT16 timeout)
  2064. {
  2065. tBTA_DM_API_UPDATE_CONN_PARAM *p_msg;
  2066. if ((p_msg = (tBTA_DM_API_UPDATE_CONN_PARAM *) osi_malloc(sizeof(tBTA_DM_API_UPDATE_CONN_PARAM))) != NULL) {
  2067. memset (p_msg, 0, sizeof(tBTA_DM_API_UPDATE_CONN_PARAM));
  2068. p_msg->hdr.event = BTA_DM_API_UPDATE_CONN_PARAM_EVT;
  2069. bdcpy(p_msg->bd_addr, bd_addr);
  2070. p_msg->min_int = min_int;
  2071. p_msg->max_int = max_int;
  2072. p_msg->latency = latency;
  2073. p_msg->timeout = timeout;
  2074. bta_sys_sendmsg(p_msg);
  2075. }
  2076. }
  2077. /*******************************************************************************
  2078. **
  2079. ** Function BTA_DmBleDisconnect
  2080. **
  2081. ** Description Disconnect the ble connection, can only be used when connection is up.
  2082. **
  2083. ** Parameters: bd_addr - BD address of the peer
  2084. **
  2085. ** Returns void
  2086. **
  2087. *******************************************************************************/
  2088. void BTA_DmBleDisconnect(BD_ADDR bd_addr)
  2089. {
  2090. tBTA_DM_API_BLE_DISCONNECT *p_msg;
  2091. if ((p_msg = (tBTA_DM_API_BLE_DISCONNECT *) osi_malloc(sizeof(tBTA_DM_API_BLE_DISCONNECT))) != NULL) {
  2092. memset (p_msg, 0, sizeof(tBTA_DM_API_BLE_DISCONNECT));
  2093. p_msg->hdr.event = BTA_DM_API_BLE_DISCONNECT_EVT;
  2094. bdcpy(p_msg->remote_bda, bd_addr);
  2095. bta_sys_sendmsg(p_msg);
  2096. }
  2097. }
  2098. /*******************************************************************************
  2099. **
  2100. ** Function BTA_DmBleSetDataLength
  2101. **
  2102. ** Description This function is to set maximum LE data packet size
  2103. **
  2104. ** Returns void
  2105. **
  2106. **
  2107. *******************************************************************************/
  2108. void BTA_DmBleSetDataLength(BD_ADDR remote_device, UINT16 tx_data_length, tBTA_SET_PKT_DATA_LENGTH_CBACK *p_set_pkt_data_cback)
  2109. {
  2110. tBTA_DM_API_BLE_SET_DATA_LENGTH *p_msg;
  2111. if ((p_msg = (tBTA_DM_API_BLE_SET_DATA_LENGTH *)osi_malloc(sizeof(tBTA_DM_API_BLE_SET_DATA_LENGTH)))
  2112. != NULL) {
  2113. bdcpy(p_msg->remote_bda, remote_device);
  2114. p_msg->hdr.event = BTA_DM_API_SET_DATA_LENGTH_EVT;
  2115. p_msg->tx_data_length = tx_data_length;
  2116. p_msg->p_set_pkt_data_cback = p_set_pkt_data_cback;
  2117. bta_sys_sendmsg(p_msg);
  2118. }
  2119. }
  2120. #endif
  2121. /*******************************************************************************
  2122. **
  2123. ** Function BTA_DmSetEncryption
  2124. **
  2125. ** Description This function is called to ensure that connection is
  2126. ** encrypted. Should be called only on an open connection.
  2127. ** Typically only needed for connections that first want to
  2128. ** bring up unencrypted links, then later encrypt them.
  2129. **
  2130. ** Parameters: bd_addr - Address of the peer device
  2131. ** transport - transport of the link to be encruypted
  2132. ** p_callback - Pointer to callback function to indicat the
  2133. ** link encryption status
  2134. ** sec_act - This is the security action to indicate
  2135. ** what kind of BLE security level is required for
  2136. ** the BLE link if the BLE is supported
  2137. ** Note: This parameter is ignored for the BR/EDR link
  2138. ** or the BLE is not supported
  2139. **
  2140. ** Returns void
  2141. **
  2142. *******************************************************************************/
  2143. #if (SMP_INCLUDED == TRUE)
  2144. void BTA_DmSetEncryption(BD_ADDR bd_addr, tBTA_TRANSPORT transport, tBTA_DM_ENCRYPT_CBACK *p_callback,
  2145. tBTA_DM_BLE_SEC_ACT sec_act)
  2146. {
  2147. tBTA_DM_API_SET_ENCRYPTION *p_msg;
  2148. APPL_TRACE_API("BTA_DmSetEncryption"); //todo
  2149. if ((p_msg = (tBTA_DM_API_SET_ENCRYPTION *) osi_malloc(sizeof(tBTA_DM_API_SET_ENCRYPTION))) != NULL) {
  2150. memset(p_msg, 0, sizeof(tBTA_DM_API_SET_ENCRYPTION));
  2151. p_msg->hdr.event = BTA_DM_API_SET_ENCRYPTION_EVT;
  2152. memcpy(p_msg->bd_addr, bd_addr, BD_ADDR_LEN);
  2153. p_msg->transport = transport;
  2154. p_msg->p_callback = p_callback;
  2155. p_msg->sec_act = sec_act;
  2156. bta_sys_sendmsg(p_msg);
  2157. }
  2158. }
  2159. #endif ///SMP_INCLUDED == TRUE
  2160. /*******************************************************************************
  2161. **
  2162. ** Function BTA_DmCloseACL
  2163. **
  2164. ** Description This function force to close an ACL connection and remove the
  2165. ** device from the security database list of known devices.
  2166. **
  2167. ** Parameters: bd_addr - Address of the peer device
  2168. ** remove_dev - remove device or not after link down
  2169. **
  2170. ** Returns void
  2171. **
  2172. *******************************************************************************/
  2173. void BTA_DmCloseACL(BD_ADDR bd_addr, BOOLEAN remove_dev, tBTA_TRANSPORT transport)
  2174. {
  2175. tBTA_DM_API_REMOVE_ACL *p_msg;
  2176. APPL_TRACE_API("BTA_DmCloseACL");
  2177. if ((p_msg = (tBTA_DM_API_REMOVE_ACL *) osi_malloc(sizeof(tBTA_DM_API_REMOVE_ACL))) != NULL) {
  2178. memset(p_msg, 0, sizeof(tBTA_DM_API_REMOVE_ACL));
  2179. p_msg->hdr.event = BTA_DM_API_REMOVE_ACL_EVT;
  2180. memcpy(p_msg->bd_addr, bd_addr, BD_ADDR_LEN);
  2181. p_msg->remove_dev = remove_dev;
  2182. p_msg->transport = transport;
  2183. bta_sys_sendmsg(p_msg);
  2184. }
  2185. }
  2186. #if BLE_INCLUDED == TRUE
  2187. /*******************************************************************************
  2188. **
  2189. ** Function BTA_DmBleObserve
  2190. **
  2191. ** Description This procedure keep the device listening for advertising
  2192. ** events from a broadcast device.
  2193. **
  2194. ** Parameters start: start or stop observe.
  2195. **
  2196. ** Returns void
  2197. **
  2198. ** Returns void.
  2199. **
  2200. *******************************************************************************/
  2201. extern void BTA_DmBleObserve(BOOLEAN start, UINT32 duration,
  2202. tBTA_DM_SEARCH_CBACK *p_results_cb,
  2203. tBTA_START_STOP_SCAN_CMPL_CBACK *p_start_stop_scan_cb)
  2204. {
  2205. tBTA_DM_API_BLE_OBSERVE *p_msg;
  2206. APPL_TRACE_API("BTA_DmBleObserve:start = %d ", start);
  2207. if ((p_msg = (tBTA_DM_API_BLE_OBSERVE *) osi_malloc(sizeof(tBTA_DM_API_BLE_OBSERVE))) != NULL) {
  2208. memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_OBSERVE));
  2209. p_msg->hdr.event = BTA_DM_API_BLE_OBSERVE_EVT;
  2210. p_msg->start = start;
  2211. p_msg->duration = duration;
  2212. p_msg->p_cback = p_results_cb;
  2213. if (start){
  2214. p_msg->p_start_scan_cback = p_start_stop_scan_cb;
  2215. }
  2216. else {
  2217. p_msg->p_stop_scan_cback = p_start_stop_scan_cb;
  2218. }
  2219. bta_sys_sendmsg(p_msg);
  2220. }
  2221. }
  2222. /*******************************************************************************
  2223. **
  2224. ** Function BTA_DmBleScan
  2225. **
  2226. ** Description This procedure keep the device listening for advertising
  2227. ** events from a broadcast device.
  2228. **
  2229. ** Parameters start: start or stop scan.
  2230. **
  2231. ** Returns void
  2232. **
  2233. ** Returns void.
  2234. **
  2235. *******************************************************************************/
  2236. extern void BTA_DmBleScan(BOOLEAN start, UINT32 duration,
  2237. tBTA_DM_SEARCH_CBACK *p_results_cb,
  2238. tBTA_START_STOP_SCAN_CMPL_CBACK *p_start_stop_scan_cb)
  2239. {
  2240. tBTA_DM_API_BLE_SCAN *p_msg;
  2241. APPL_TRACE_API("BTA_DmBleScan:start = %d ", start);
  2242. if ((p_msg = (tBTA_DM_API_BLE_SCAN *) osi_malloc(sizeof(tBTA_DM_API_BLE_SCAN))) != NULL) {
  2243. memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_SCAN));
  2244. p_msg->hdr.event = BTA_DM_API_BLE_SCAN_EVT;
  2245. p_msg->start = start;
  2246. p_msg->duration = duration;
  2247. p_msg->p_cback = p_results_cb;
  2248. if (start){
  2249. p_msg->p_start_scan_cback = p_start_stop_scan_cb;
  2250. }
  2251. else {
  2252. p_msg->p_stop_scan_cback = p_start_stop_scan_cb;
  2253. }
  2254. bta_sys_sendmsg(p_msg);
  2255. }
  2256. }
  2257. /*******************************************************************************
  2258. **
  2259. ** Function BTA_DmBleStopAdvertising
  2260. **
  2261. ** Description This function set the random address for the APP
  2262. **
  2263. ** Parameters void
  2264. **
  2265. ** Returns void
  2266. **
  2267. **
  2268. *******************************************************************************/
  2269. extern void BTA_DmBleStopAdvertising(void)
  2270. {
  2271. BT_HDR *p_msg;
  2272. APPL_TRACE_API("BTA_DmBleStopAdvertising\n");
  2273. if ((p_msg = (BT_HDR *) osi_malloc(sizeof(BT_HDR))) != NULL) {
  2274. memset(p_msg, 0, sizeof(BT_HDR));
  2275. p_msg->event = BTA_DM_API_BLE_STOP_ADV_EVT;
  2276. bta_sys_sendmsg(p_msg);
  2277. }
  2278. }
  2279. /*******************************************************************************
  2280. **
  2281. ** Function BTA_DmSetRandAddress
  2282. **
  2283. ** Description This function set the random address for the APP
  2284. **
  2285. ** Parameters rand_addr: the random address whith should be setting
  2286. ** p_set_rand_addr_cback: complete callback
  2287. ** Returns void
  2288. **
  2289. **
  2290. *******************************************************************************/
  2291. extern void BTA_DmSetRandAddress(BD_ADDR rand_addr, tBTA_SET_RAND_ADDR_CBACK *p_set_rand_addr_cback)
  2292. {
  2293. tBTA_DM_APT_SET_DEV_ADDR *p_msg;
  2294. APPL_TRACE_API("set the random address ");
  2295. if ((p_msg = (tBTA_DM_APT_SET_DEV_ADDR *) osi_malloc(sizeof(tBTA_DM_APT_SET_DEV_ADDR))) != NULL) {
  2296. memset(p_msg, 0, sizeof(tBTA_DM_APT_SET_DEV_ADDR));
  2297. memcpy(p_msg->address, rand_addr, BD_ADDR_LEN);
  2298. p_msg->hdr.event = BTA_DM_API_SET_RAND_ADDR_EVT;
  2299. p_msg->addr_type = BLE_ADDR_RANDOM;
  2300. p_msg->p_set_rand_addr_cback = p_set_rand_addr_cback;
  2301. //start sent the msg to the bta system control moudle
  2302. bta_sys_sendmsg(p_msg);
  2303. }
  2304. }
  2305. void BTA_DmClearRandAddress(void)
  2306. {
  2307. tBTA_DM_APT_CLEAR_ADDR *p_msg;
  2308. if ((p_msg = (tBTA_DM_APT_CLEAR_ADDR *) osi_malloc(sizeof(tBTA_DM_APT_CLEAR_ADDR))) != NULL) {
  2309. memset(p_msg, 0, sizeof(tBTA_DM_APT_CLEAR_ADDR));
  2310. p_msg->hdr.event = BTA_DM_API_CLEAR_RAND_ADDR_EVT;
  2311. bta_sys_sendmsg(p_msg);
  2312. }
  2313. }
  2314. /*******************************************************************************
  2315. **
  2316. ** Function BTA_VendorInit
  2317. **
  2318. ** Description This function initializes vendor specific
  2319. **
  2320. ** Returns void
  2321. **
  2322. *******************************************************************************/
  2323. void BTA_VendorInit (void)
  2324. {
  2325. APPL_TRACE_API("BTA_VendorInit");
  2326. }
  2327. /*******************************************************************************
  2328. **
  2329. ** Function BTA_VendorCleanup
  2330. **
  2331. ** Description This function frees up Broadcom specific VS specific dynamic memory
  2332. **
  2333. ** Returns void
  2334. **
  2335. *******************************************************************************/
  2336. void BTA_VendorCleanup (void)
  2337. {
  2338. tBTM_BLE_VSC_CB cmn_ble_vsc_cb;
  2339. BTM_BleGetVendorCapabilities(&cmn_ble_vsc_cb);
  2340. #if (BLE_INCLUDED == TRUE && BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE)
  2341. btm_ble_adv_filter_cleanup(); // when BLE_VND_INCLUDED is false, this function will be ignore, so move it out of "if"
  2342. #if 0 //by TH, comment out temporarily
  2343. if (cmn_ble_vsc_cb.max_filter > 0) {
  2344. btm_ble_adv_filter_cleanup();
  2345. #if BLE_PRIVACY_SPT == TRUE
  2346. btm_ble_resolving_list_cleanup ();
  2347. #endif
  2348. }
  2349. #endif
  2350. if (cmn_ble_vsc_cb.tot_scan_results_strg > 0) {
  2351. btm_ble_batchscan_cleanup();
  2352. }
  2353. #endif
  2354. btm_ble_multi_adv_cleanup();
  2355. }
  2356. #endif