avdt_api.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303
  1. /******************************************************************************
  2. *
  3. * Copyright (C) 2002-2012 Broadcom Corporation
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at:
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. ******************************************************************************/
  18. /******************************************************************************
  19. *
  20. * This module contains API of the audio/video distribution transport
  21. * protocol.
  22. *
  23. ******************************************************************************/
  24. #include <string.h>
  25. #include "stack/bt_types.h"
  26. #include "common/bt_target.h"
  27. #include "stack/avdt_api.h"
  28. #include "stack/avdtc_api.h"
  29. #include "avdt_int.h"
  30. #include "stack/l2c_api.h"
  31. #include "stack/btm_api.h"
  32. #include "stack/btu.h"
  33. #include "osi/allocator.h"
  34. #if (defined(AVDT_INCLUDED) && AVDT_INCLUDED == TRUE)
  35. /* Control block for AVDT */
  36. #if AVDT_DYNAMIC_MEMORY == FALSE
  37. tAVDT_CB avdt_cb;
  38. #else
  39. tAVDT_CB *avdt_cb_ptr;
  40. #endif
  41. /*******************************************************************************
  42. **
  43. ** Function avdt_process_timeout
  44. **
  45. ** Description This function is called by BTU when an AVDTP timer
  46. ** expires. The function sends a timer event to the
  47. ** appropriate CCB or SCB state machine.
  48. **
  49. ** This function is for use internal to the stack only.
  50. **
  51. **
  52. ** Returns void
  53. **
  54. *******************************************************************************/
  55. void avdt_process_timeout(TIMER_LIST_ENT *p_tle)
  56. {
  57. UINT8 event = 0;
  58. UINT8 err_code = AVDT_ERR_TIMEOUT;
  59. switch (p_tle->event) {
  60. case BTU_TTYPE_AVDT_SCB_DELAY_RPT:
  61. event = AVDT_SCB_DELAY_RPT_RSP_TOUT_EVT;
  62. break;
  63. case BTU_TTYPE_AVDT_CCB_RET:
  64. event = AVDT_CCB_RET_TOUT_EVT + AVDT_CCB_MKR;
  65. break;
  66. case BTU_TTYPE_AVDT_CCB_RSP:
  67. event = AVDT_CCB_RSP_TOUT_EVT + AVDT_CCB_MKR;
  68. break;
  69. case BTU_TTYPE_AVDT_CCB_IDLE:
  70. event = AVDT_CCB_IDLE_TOUT_EVT + AVDT_CCB_MKR;
  71. break;
  72. case BTU_TTYPE_AVDT_SCB_TC:
  73. event = AVDT_SCB_TC_TOUT_EVT;
  74. break;
  75. default:
  76. break;
  77. }
  78. if (event & AVDT_CCB_MKR) {
  79. avdt_ccb_event((tAVDT_CCB *) p_tle->param, (UINT8) (event & ~AVDT_CCB_MKR),
  80. (tAVDT_CCB_EVT *) &err_code);
  81. } else {
  82. avdt_scb_event((tAVDT_SCB *) p_tle->param, event, NULL);
  83. }
  84. }
  85. /*******************************************************************************
  86. **
  87. ** Function AVDT_Register
  88. **
  89. ** Description This is the system level registration function for the
  90. ** AVDTP protocol. This function initializes AVDTP and
  91. ** prepares the protocol stack for its use. This function
  92. ** must be called once by the system or platform using AVDTP
  93. ** before the other functions of the API an be used.
  94. **
  95. **
  96. ** Returns void
  97. **
  98. *******************************************************************************/
  99. void AVDT_Register(tAVDT_REG *p_reg, tAVDT_CTRL_CBACK *p_cback)
  100. {
  101. /* register PSM with L2CAP */
  102. L2CA_Register(AVDT_PSM, (tL2CAP_APPL_INFO *) &avdt_l2c_appl);
  103. /* set security level */
  104. BTM_SetSecurityLevel(TRUE, "", BTM_SEC_SERVICE_AVDTP, p_reg->sec_mask,
  105. AVDT_PSM, BTM_SEC_PROTO_AVDT, AVDT_CHAN_SIG);
  106. BTM_SetSecurityLevel(FALSE, "", BTM_SEC_SERVICE_AVDTP, p_reg->sec_mask,
  107. AVDT_PSM, BTM_SEC_PROTO_AVDT, AVDT_CHAN_SIG);
  108. /* do not use security on the media channel */
  109. BTM_SetSecurityLevel(TRUE, "", BTM_SEC_SERVICE_AVDTP_NOSEC, BTM_SEC_NONE,
  110. AVDT_PSM, BTM_SEC_PROTO_AVDT, AVDT_CHAN_MEDIA);
  111. BTM_SetSecurityLevel(FALSE, "", BTM_SEC_SERVICE_AVDTP_NOSEC, BTM_SEC_NONE,
  112. AVDT_PSM, BTM_SEC_PROTO_AVDT, AVDT_CHAN_MEDIA);
  113. #if AVDT_REPORTING == TRUE
  114. /* do not use security on the reporting channel */
  115. BTM_SetSecurityLevel(TRUE, "", BTM_SEC_SERVICE_AVDTP_NOSEC, BTM_SEC_NONE,
  116. AVDT_PSM, BTM_SEC_PROTO_AVDT, AVDT_CHAN_REPORT);
  117. BTM_SetSecurityLevel(FALSE, "", BTM_SEC_SERVICE_AVDTP_NOSEC, BTM_SEC_NONE,
  118. AVDT_PSM, BTM_SEC_PROTO_AVDT, AVDT_CHAN_REPORT);
  119. #endif
  120. /* initialize AVDTP data structures */
  121. avdt_scb_init();
  122. avdt_ccb_init();
  123. avdt_ad_init();
  124. /* copy registration struct */
  125. memcpy(&avdt_cb.rcb, p_reg, sizeof(tAVDT_REG));
  126. avdt_cb.p_conn_cback = p_cback;
  127. }
  128. /*******************************************************************************
  129. **
  130. ** Function AVDT_Deregister
  131. **
  132. ** Description This function is called to deregister use AVDTP protocol.
  133. ** It is called when AVDTP is no longer being used by any
  134. ** application in the system. Before this function can be
  135. ** called, all streams must be removed with AVDT_RemoveStream().
  136. **
  137. **
  138. ** Returns void
  139. **
  140. *******************************************************************************/
  141. void AVDT_Deregister(void)
  142. {
  143. /* deregister PSM with L2CAP */
  144. L2CA_Deregister(AVDT_PSM);
  145. }
  146. /*******************************************************************************
  147. **
  148. ** Function AVDT_SINK_Activate
  149. **
  150. ** Description Activate SEP of A2DP Sink. In Use parameter is adjusted.
  151. ** In Use will be made false in case of activation. A2DP SRC
  152. ** will receive in_use as false and can open A2DP Sink
  153. ** connection
  154. **
  155. ** Returns void.
  156. **
  157. *******************************************************************************/
  158. void AVDT_SINK_Activate(void)
  159. {
  160. tAVDT_SCB *p_scb = &avdt_cb.scb[0];
  161. int i;
  162. AVDT_TRACE_DEBUG("AVDT_SINK_Activate");
  163. /* for all allocated scbs */
  164. for (i = 0; i < AVDT_NUM_SEPS; i++, p_scb++) {
  165. if ((p_scb->allocated) && (p_scb->cs.tsep == AVDT_TSEP_SNK)) {
  166. AVDT_TRACE_DEBUG("AVDT_SINK_Activate found scb");
  167. p_scb->sink_activated = TRUE;
  168. /* update in_use */
  169. p_scb->in_use = FALSE;
  170. break;
  171. }
  172. }
  173. }
  174. /*******************************************************************************
  175. **
  176. ** Function AVDT_SINK_Deactivate
  177. **
  178. ** Description Deactivate SEP of A2DP Sink. In Use parameter is adjusted.
  179. ** In Use will be made TRUE in case of activation. A2DP SRC
  180. ** will receive in_use as true and will not open A2DP Sink
  181. ** connection
  182. **
  183. ** Returns void.
  184. **
  185. *******************************************************************************/
  186. void AVDT_SINK_Deactivate(void)
  187. {
  188. tAVDT_SCB *p_scb = &avdt_cb.scb[0];
  189. int i;
  190. AVDT_TRACE_DEBUG("AVDT_SINK_Deactivate");
  191. /* for all allocated scbs */
  192. for (i = 0; i < AVDT_NUM_SEPS; i++, p_scb++) {
  193. if ((p_scb->allocated) && (p_scb->cs.tsep == AVDT_TSEP_SNK)) {
  194. AVDT_TRACE_DEBUG("AVDT_SINK_Deactivate, found scb");
  195. p_scb->sink_activated = FALSE;
  196. /* update in_use */
  197. p_scb->in_use = TRUE;
  198. break;
  199. }
  200. }
  201. }
  202. void AVDT_AbortReq(UINT8 handle)
  203. {
  204. AVDT_TRACE_ERROR("%s\n", __func__);
  205. tAVDT_SCB *p_scb = avdt_scb_by_hdl(handle);
  206. if (p_scb != NULL) {
  207. avdt_scb_event(p_scb, AVDT_SCB_API_ABORT_REQ_EVT, NULL);
  208. } else {
  209. AVDT_TRACE_ERROR("%s Improper SCB, can not abort the stream\n", __func__);
  210. }
  211. }
  212. /*******************************************************************************
  213. **
  214. ** Function AVDT_CreateStream
  215. **
  216. ** Description Create a stream endpoint. After a stream endpoint is
  217. ** created an application can initiate a connection between
  218. ** this endpoint and an endpoint on a peer device. In
  219. ** addition, a peer device can discover, get the capabilities,
  220. ** and connect to this endpoint.
  221. **
  222. **
  223. ** Returns AVDT_SUCCESS if successful, otherwise error.
  224. **
  225. *******************************************************************************/
  226. UINT16 AVDT_CreateStream(UINT8 *p_handle, tAVDT_CS *p_cs)
  227. {
  228. UINT16 result = AVDT_SUCCESS;
  229. tAVDT_SCB *p_scb;
  230. /* Verify parameters; if invalid, return failure */
  231. if (((p_cs->cfg.psc_mask & (~AVDT_PSC)) != 0) || (p_cs->p_ctrl_cback == NULL)) {
  232. result = AVDT_BAD_PARAMS;
  233. }
  234. /* Allocate scb; if no scbs, return failure */
  235. else if ((p_scb = avdt_scb_alloc(p_cs)) == NULL) {
  236. result = AVDT_NO_RESOURCES;
  237. } else {
  238. *p_handle = avdt_scb_to_hdl(p_scb);
  239. }
  240. return result;
  241. }
  242. /*******************************************************************************
  243. **
  244. ** Function AVDT_RemoveStream
  245. **
  246. ** Description Remove a stream endpoint. This function is called when
  247. ** the application is no longer using a stream endpoint.
  248. ** If this function is called when the endpoint is connected
  249. ** the connection is closed and then the stream endpoint
  250. ** is removed.
  251. **
  252. **
  253. ** Returns AVDT_SUCCESS if successful, otherwise error.
  254. **
  255. *******************************************************************************/
  256. UINT16 AVDT_RemoveStream(UINT8 handle)
  257. {
  258. UINT16 result = AVDT_SUCCESS;
  259. tAVDT_SCB *p_scb;
  260. /* look up scb */
  261. if ((p_scb = avdt_scb_by_hdl(handle)) == NULL) {
  262. result = AVDT_BAD_HANDLE;
  263. } else {
  264. /* send remove event to scb */
  265. avdt_scb_event(p_scb, AVDT_SCB_API_REMOVE_EVT, NULL);
  266. }
  267. return result;
  268. }
  269. /*******************************************************************************
  270. **
  271. ** Function AVDT_DiscoverReq
  272. **
  273. ** Description This function initiates a connection to the AVDTP service
  274. ** on the peer device, if not already present, and discovers
  275. ** the stream endpoints on the peer device. (Please note
  276. ** that AVDTP discovery is unrelated to SDP discovery).
  277. ** This function can be called at any time regardless of whether
  278. ** there is an AVDTP connection to the peer device.
  279. **
  280. ** When discovery is complete, an AVDT_DISCOVER_CFM_EVT
  281. ** is sent to the application via its callback function.
  282. ** The application must not call AVDT_GetCapReq() or
  283. ** AVDT_DiscoverReq() again to the same device until
  284. ** discovery is complete.
  285. **
  286. ** The memory addressed by sep_info is allocated by the
  287. ** application. This memory is written to by AVDTP as part
  288. ** of the discovery procedure. This memory must remain
  289. ** accessible until the application receives the
  290. ** AVDT_DISCOVER_CFM_EVT.
  291. **
  292. ** Returns AVDT_SUCCESS if successful, otherwise error.
  293. **
  294. *******************************************************************************/
  295. UINT16 AVDT_DiscoverReq(BD_ADDR bd_addr, tAVDT_SEP_INFO *p_sep_info,
  296. UINT8 max_seps, tAVDT_CTRL_CBACK *p_cback)
  297. {
  298. tAVDT_CCB *p_ccb;
  299. UINT16 result = AVDT_SUCCESS;
  300. tAVDT_CCB_EVT evt;
  301. /* find channel control block for this bd addr; if none, allocate one */
  302. if ((p_ccb = avdt_ccb_by_bd(bd_addr)) == NULL) {
  303. if ((p_ccb = avdt_ccb_alloc(bd_addr)) == NULL) {
  304. /* could not allocate channel control block */
  305. result = AVDT_NO_RESOURCES;
  306. }
  307. }
  308. if (result == AVDT_SUCCESS) {
  309. /* make sure no discovery or get capabilities req already in progress */
  310. if (p_ccb->proc_busy) {
  311. result = AVDT_BUSY;
  312. }
  313. /* send event to ccb */
  314. else {
  315. evt.discover.p_sep_info = p_sep_info;
  316. evt.discover.num_seps = max_seps;
  317. evt.discover.p_cback = p_cback;
  318. avdt_ccb_event(p_ccb, AVDT_CCB_API_DISCOVER_REQ_EVT, &evt);
  319. }
  320. }
  321. return result;
  322. }
  323. /*******************************************************************************
  324. **
  325. ** Function avdt_get_cap_req
  326. **
  327. ** Description internal function to serve both AVDT_GetCapReq and
  328. ** AVDT_GetAllCapReq
  329. **
  330. ** Returns AVDT_SUCCESS if successful, otherwise error.
  331. **
  332. *******************************************************************************/
  333. static UINT16 avdt_get_cap_req(BD_ADDR bd_addr, tAVDT_CCB_API_GETCAP *p_evt)
  334. {
  335. tAVDT_CCB *p_ccb = NULL;
  336. UINT16 result = AVDT_SUCCESS;
  337. /* verify SEID */
  338. if ((p_evt->single.seid < AVDT_SEID_MIN) || (p_evt->single.seid > AVDT_SEID_MAX)) {
  339. AVDT_TRACE_ERROR("seid: %d\n", p_evt->single.seid);
  340. result = AVDT_BAD_PARAMS;
  341. }
  342. /* find channel control block for this bd addr; if none, allocate one */
  343. else if ((p_ccb = avdt_ccb_by_bd(bd_addr)) == NULL) {
  344. if ((p_ccb = avdt_ccb_alloc(bd_addr)) == NULL) {
  345. /* could not allocate channel control block */
  346. result = AVDT_NO_RESOURCES;
  347. }
  348. }
  349. if (result == AVDT_SUCCESS) {
  350. /* make sure no discovery or get capabilities req already in progress */
  351. if (p_ccb->proc_busy) {
  352. result = AVDT_BUSY;
  353. }
  354. /* send event to ccb */
  355. else {
  356. avdt_ccb_event(p_ccb, AVDT_CCB_API_GETCAP_REQ_EVT, (tAVDT_CCB_EVT *)p_evt);
  357. }
  358. }
  359. return result;
  360. }
  361. /*******************************************************************************
  362. **
  363. ** Function AVDT_GetCapReq
  364. **
  365. ** Description This function initiates a connection to the AVDTP service
  366. ** on the peer device, if not already present, and gets the
  367. ** capabilities of a stream endpoint on the peer device.
  368. ** This function can be called at any time regardless of
  369. ** whether there is an AVDTP connection to the peer device.
  370. **
  371. ** When the procedure is complete, an AVDT_GETCAP_CFM_EVT is
  372. ** sent to the application via its callback function. The
  373. ** application must not call AVDT_GetCapReq() or
  374. ** AVDT_DiscoverReq() again until the procedure is complete.
  375. **
  376. ** The memory pointed to by p_cfg is allocated by the
  377. ** application. This memory is written to by AVDTP as part
  378. ** of the get capabilities procedure. This memory must
  379. ** remain accessible until the application receives
  380. ** the AVDT_GETCAP_CFM_EVT.
  381. **
  382. ** Returns AVDT_SUCCESS if successful, otherwise error.
  383. **
  384. *******************************************************************************/
  385. UINT16 AVDT_GetCapReq(BD_ADDR bd_addr, UINT8 seid, tAVDT_CFG *p_cfg, tAVDT_CTRL_CBACK *p_cback)
  386. {
  387. tAVDT_CCB_API_GETCAP getcap;
  388. getcap.single.seid = seid;
  389. getcap.single.sig_id = AVDT_SIG_GETCAP;
  390. getcap.p_cfg = p_cfg;
  391. getcap.p_cback = p_cback;
  392. return avdt_get_cap_req (bd_addr, &getcap);
  393. }
  394. /*******************************************************************************
  395. **
  396. ** Function AVDT_GetAllCapReq
  397. **
  398. ** Description This function initiates a connection to the AVDTP service
  399. ** on the peer device, if not already present, and gets the
  400. ** capabilities of a stream endpoint on the peer device.
  401. ** This function can be called at any time regardless of
  402. ** whether there is an AVDTP connection to the peer device.
  403. **
  404. ** When the procedure is complete, an AVDT_GETCAP_CFM_EVT is
  405. ** sent to the application via its callback function. The
  406. ** application must not call AVDT_GetCapReq() or
  407. ** AVDT_DiscoverReq() again until the procedure is complete.
  408. **
  409. ** The memory pointed to by p_cfg is allocated by the
  410. ** application. This memory is written to by AVDTP as part
  411. ** of the get capabilities procedure. This memory must
  412. ** remain accessible until the application receives
  413. ** the AVDT_GETCAP_CFM_EVT.
  414. **
  415. ** Returns AVDT_SUCCESS if successful, otherwise error.
  416. **
  417. *******************************************************************************/
  418. UINT16 AVDT_GetAllCapReq(BD_ADDR bd_addr, UINT8 seid, tAVDT_CFG *p_cfg, tAVDT_CTRL_CBACK *p_cback)
  419. {
  420. tAVDT_CCB_API_GETCAP getcap;
  421. getcap.single.seid = seid;
  422. getcap.single.sig_id = AVDT_SIG_GET_ALLCAP;
  423. getcap.p_cfg = p_cfg;
  424. getcap.p_cback = p_cback;
  425. return avdt_get_cap_req (bd_addr, &getcap);
  426. }
  427. /*******************************************************************************
  428. **
  429. ** Function AVDT_DelayReport
  430. **
  431. ** Description This functions sends a Delay Report to the peer device
  432. ** that is associated with a particular SEID.
  433. ** This function is called by SNK device.
  434. **
  435. ** Returns AVDT_SUCCESS if successful, otherwise error.
  436. **
  437. *******************************************************************************/
  438. UINT16 AVDT_DelayReport(UINT8 handle, UINT8 seid, UINT16 delay)
  439. {
  440. tAVDT_SCB *p_scb;
  441. UINT16 result = AVDT_SUCCESS;
  442. tAVDT_SCB_EVT evt;
  443. UNUSED(seid);
  444. AVDT_TRACE_DEBUG("%s: delay value: 0x%04x\n", __func__, delay);
  445. /* map handle to scb */
  446. if ((p_scb = avdt_scb_by_hdl(handle)) == NULL) {
  447. result = AVDT_BAD_HANDLE;
  448. } else
  449. /* send event to scb */
  450. {
  451. if ((p_scb->cs.tsep == AVDT_TSEP_SNK) && (p_scb->curr_cfg.psc_mask & AVDT_PSC_DELAY_RPT)) {
  452. evt.apidelay.hdr.seid = p_scb->peer_seid;
  453. evt.apidelay.delay = delay;
  454. avdt_scb_event(p_scb, AVDT_SCB_API_DELAY_RPT_REQ_EVT, &evt);
  455. } else {
  456. AVDT_TRACE_WARNING("%s: peer device does not supported\n", __func__);
  457. result = AVDT_BAD_PARAMS;
  458. }
  459. }
  460. return result;
  461. }
  462. /*******************************************************************************
  463. **
  464. ** Function AVDT_OpenReq
  465. **
  466. ** Description This function initiates a connection to the AVDTP service
  467. ** on the peer device, if not already present, and connects
  468. ** to a stream endpoint on a peer device. When the connection
  469. ** is completed, an AVDT_OPEN_CFM_EVT is sent to the
  470. ** application via the control callback function for this handle.
  471. **
  472. ** Returns AVDT_SUCCESS if successful, otherwise error.
  473. **
  474. *******************************************************************************/
  475. UINT16 AVDT_OpenReq(UINT8 handle, BD_ADDR bd_addr, UINT8 seid, tAVDT_CFG *p_cfg)
  476. {
  477. tAVDT_CCB *p_ccb = NULL;
  478. tAVDT_SCB *p_scb = NULL;
  479. UINT16 result = AVDT_SUCCESS;
  480. tAVDT_SCB_EVT evt;
  481. /* verify SEID */
  482. if ((seid < AVDT_SEID_MIN) || (seid > AVDT_SEID_MAX)) {
  483. result = AVDT_BAD_PARAMS;
  484. }
  485. /* map handle to scb */
  486. else if ((p_scb = avdt_scb_by_hdl(handle)) == NULL) {
  487. result = AVDT_BAD_HANDLE;
  488. }
  489. /* find channel control block for this bd addr; if none, allocate one */
  490. else if ((p_ccb = avdt_ccb_by_bd(bd_addr)) == NULL) {
  491. if ((p_ccb = avdt_ccb_alloc(bd_addr)) == NULL) {
  492. /* could not allocate channel control block */
  493. result = AVDT_NO_RESOURCES;
  494. }
  495. }
  496. /* send event to scb */
  497. if (result == AVDT_SUCCESS) {
  498. evt.msg.config_cmd.hdr.seid = seid;
  499. evt.msg.config_cmd.hdr.ccb_idx = avdt_ccb_to_idx(p_ccb);
  500. evt.msg.config_cmd.int_seid = handle;
  501. evt.msg.config_cmd.p_cfg = p_cfg;
  502. avdt_scb_event(p_scb, AVDT_SCB_API_SETCONFIG_REQ_EVT, &evt);
  503. }
  504. return result;
  505. }
  506. /*******************************************************************************
  507. **
  508. ** Function AVDT_ConfigRsp
  509. **
  510. ** Description Respond to a configure request from the peer device. This
  511. ** function must be called if the application receives an
  512. ** AVDT_CONFIG_IND_EVT through its control callback.
  513. **
  514. **
  515. ** Returns AVDT_SUCCESS if successful, otherwise error.
  516. **
  517. *******************************************************************************/
  518. UINT16 AVDT_ConfigRsp(UINT8 handle, UINT8 label, UINT8 error_code, UINT8 category)
  519. {
  520. tAVDT_SCB *p_scb;
  521. tAVDT_SCB_EVT evt;
  522. UINT16 result = AVDT_SUCCESS;
  523. UINT8 event_code;
  524. /* map handle to scb */
  525. if ((p_scb = avdt_scb_by_hdl(handle)) == NULL) {
  526. result = AVDT_BAD_HANDLE;
  527. }
  528. /* handle special case when this function is called but peer has not send
  529. ** a configuration cmd; ignore and return error result
  530. */
  531. else if (!p_scb->in_use) {
  532. result = AVDT_BAD_HANDLE;
  533. }
  534. /* send event to scb */
  535. else {
  536. evt.msg.hdr.err_code = error_code;
  537. evt.msg.hdr.err_param = category;
  538. evt.msg.hdr.label = label;
  539. if (error_code == 0) {
  540. event_code = AVDT_SCB_API_SETCONFIG_RSP_EVT;
  541. } else {
  542. event_code = AVDT_SCB_API_SETCONFIG_REJ_EVT;
  543. }
  544. avdt_scb_event(p_scb, event_code, &evt);
  545. }
  546. return result;
  547. }
  548. /*******************************************************************************
  549. **
  550. ** Function AVDT_StartReq
  551. **
  552. ** Description Start one or more stream endpoints. This initiates the
  553. ** transfer of media packets for the streams. All stream
  554. ** endpoints must previously be opened. When the streams
  555. ** are started, an AVDT_START_CFM_EVT is sent to the
  556. ** application via the control callback function for each stream.
  557. **
  558. **
  559. ** Returns AVDT_SUCCESS if successful, otherwise error.
  560. **
  561. *******************************************************************************/
  562. UINT16 AVDT_StartReq(UINT8 *p_handles, UINT8 num_handles)
  563. {
  564. tAVDT_SCB *p_scb = NULL;
  565. tAVDT_CCB_EVT evt;
  566. UINT16 result = AVDT_SUCCESS;
  567. int i;
  568. if ((num_handles == 0) || (num_handles > AVDT_NUM_SEPS)) {
  569. result = AVDT_BAD_PARAMS;
  570. } else {
  571. /* verify handles */
  572. for (i = 0; i < num_handles; i++) {
  573. if ((p_scb = avdt_scb_by_hdl(p_handles[i])) == NULL) {
  574. result = AVDT_BAD_HANDLE;
  575. break;
  576. }
  577. }
  578. }
  579. if (result == AVDT_SUCCESS) {
  580. if (p_scb->p_ccb == NULL) {
  581. result = AVDT_BAD_HANDLE;
  582. } else {
  583. /* send event to ccb */
  584. memcpy(evt.msg.multi.seid_list, p_handles, num_handles);
  585. evt.msg.multi.num_seps = num_handles;
  586. avdt_ccb_event(p_scb->p_ccb, AVDT_CCB_API_START_REQ_EVT, &evt);
  587. }
  588. }
  589. return result;
  590. }
  591. /*******************************************************************************
  592. **
  593. ** Function AVDT_SuspendReq
  594. **
  595. ** Description Suspend one or more stream endpoints. This suspends the
  596. ** transfer of media packets for the streams. All stream
  597. ** endpoints must previously be open and started. When the
  598. ** streams are suspended, an AVDT_SUSPEND_CFM_EVT is sent to
  599. ** the application via the control callback function for
  600. ** each stream.
  601. **
  602. **
  603. ** Returns AVDT_SUCCESS if successful, otherwise error.
  604. **
  605. *******************************************************************************/
  606. UINT16 AVDT_SuspendReq(UINT8 *p_handles, UINT8 num_handles)
  607. {
  608. tAVDT_SCB *p_scb = NULL;
  609. tAVDT_CCB_EVT evt;
  610. UINT16 result = AVDT_SUCCESS;
  611. int i;
  612. if ((num_handles == 0) || (num_handles > AVDT_NUM_SEPS)) {
  613. result = AVDT_BAD_PARAMS;
  614. } else {
  615. /* verify handles */
  616. for (i = 0; i < num_handles; i++) {
  617. if ((p_scb = avdt_scb_by_hdl(p_handles[i])) == NULL) {
  618. result = AVDT_BAD_HANDLE;
  619. break;
  620. }
  621. }
  622. }
  623. if (result == AVDT_SUCCESS) {
  624. if (p_scb->p_ccb == NULL) {
  625. result = AVDT_BAD_HANDLE;
  626. } else {
  627. /* send event to ccb */
  628. memcpy(evt.msg.multi.seid_list, p_handles, num_handles);
  629. evt.msg.multi.num_seps = num_handles;
  630. avdt_ccb_event(p_scb->p_ccb, AVDT_CCB_API_SUSPEND_REQ_EVT, &evt);
  631. }
  632. }
  633. return result;
  634. }
  635. /*******************************************************************************
  636. **
  637. ** Function AVDT_CloseReq
  638. **
  639. ** Description Close a stream endpoint. This stops the transfer of media
  640. ** packets and closes the transport channel associated with
  641. ** this stream endpoint. When the stream is closed, an
  642. ** AVDT_CLOSE_CFM_EVT is sent to the application via the
  643. ** control callback function for this handle.
  644. **
  645. **
  646. ** Returns AVDT_SUCCESS if successful, otherwise error.
  647. **
  648. *******************************************************************************/
  649. UINT16 AVDT_CloseReq(UINT8 handle)
  650. {
  651. tAVDT_SCB *p_scb;
  652. UINT16 result = AVDT_SUCCESS;
  653. /* map handle to scb */
  654. if ((p_scb = avdt_scb_by_hdl(handle)) == NULL) {
  655. result = AVDT_BAD_HANDLE;
  656. } else
  657. /* send event to scb */
  658. {
  659. avdt_scb_event(p_scb, AVDT_SCB_API_CLOSE_REQ_EVT, NULL);
  660. }
  661. return result;
  662. }
  663. /*******************************************************************************
  664. **
  665. ** Function AVDT_ReconfigReq
  666. **
  667. ** Description Reconfigure a stream endpoint. This allows the application
  668. ** to change the codec or content protection capabilities of
  669. ** a stream endpoint after it has been opened. This function
  670. ** can only be called if the stream is opened but not started
  671. ** or if the stream has been suspended. When the procedure
  672. ** is completed, an AVDT_RECONFIG_CFM_EVT is sent to the
  673. ** application via the control callback function for this handle.
  674. **
  675. **
  676. ** Returns AVDT_SUCCESS if successful, otherwise error.
  677. **
  678. *******************************************************************************/
  679. UINT16 AVDT_ReconfigReq(UINT8 handle, tAVDT_CFG *p_cfg)
  680. {
  681. tAVDT_SCB *p_scb;
  682. UINT16 result = AVDT_SUCCESS;
  683. tAVDT_SCB_EVT evt;
  684. /* map handle to scb */
  685. if ((p_scb = avdt_scb_by_hdl(handle)) == NULL) {
  686. result = AVDT_BAD_HANDLE;
  687. }
  688. /* send event to scb */
  689. else {
  690. /* force psc_mask to zero */
  691. p_cfg->psc_mask = 0;
  692. evt.msg.reconfig_cmd.p_cfg = p_cfg;
  693. avdt_scb_event(p_scb, AVDT_SCB_API_RECONFIG_REQ_EVT, &evt);
  694. }
  695. return result;
  696. }
  697. /*******************************************************************************
  698. **
  699. ** Function AVDT_ReconfigRsp
  700. **
  701. ** Description Respond to a reconfigure request from the peer device.
  702. ** This function must be called if the application receives
  703. ** an AVDT_RECONFIG_IND_EVT through its control callback.
  704. **
  705. **
  706. ** Returns AVDT_SUCCESS if successful, otherwise error.
  707. **
  708. *******************************************************************************/
  709. UINT16 AVDT_ReconfigRsp(UINT8 handle, UINT8 label, UINT8 error_code, UINT8 category)
  710. {
  711. tAVDT_SCB *p_scb;
  712. tAVDT_SCB_EVT evt;
  713. UINT16 result = AVDT_SUCCESS;
  714. /* map handle to scb */
  715. if ((p_scb = avdt_scb_by_hdl(handle)) == NULL) {
  716. result = AVDT_BAD_HANDLE;
  717. }
  718. /* send event to scb */
  719. else {
  720. evt.msg.hdr.err_code = error_code;
  721. evt.msg.hdr.err_param = category;
  722. evt.msg.hdr.label = label;
  723. avdt_scb_event(p_scb, AVDT_SCB_API_RECONFIG_RSP_EVT, &evt);
  724. }
  725. return result;
  726. }
  727. /*******************************************************************************
  728. **
  729. ** Function AVDT_SecurityReq
  730. **
  731. ** Description Send a security request to the peer device. When the
  732. ** security procedure is completed, an AVDT_SECURITY_CFM_EVT
  733. ** is sent to the application via the control callback function
  734. ** for this handle. (Please note that AVDTP security procedures
  735. ** are unrelated to Bluetooth link level security.)
  736. **
  737. **
  738. ** Returns AVDT_SUCCESS if successful, otherwise error.
  739. **
  740. *******************************************************************************/
  741. UINT16 AVDT_SecurityReq(UINT8 handle, UINT8 *p_data, UINT16 len)
  742. {
  743. tAVDT_SCB *p_scb;
  744. UINT16 result = AVDT_SUCCESS;
  745. tAVDT_SCB_EVT evt;
  746. /* map handle to scb */
  747. if ((p_scb = avdt_scb_by_hdl(handle)) == NULL) {
  748. result = AVDT_BAD_HANDLE;
  749. }
  750. /* send event to scb */
  751. else {
  752. evt.msg.security_rsp.p_data = p_data;
  753. evt.msg.security_rsp.len = len;
  754. avdt_scb_event(p_scb, AVDT_SCB_API_SECURITY_REQ_EVT, &evt);
  755. }
  756. return result;
  757. }
  758. /*******************************************************************************
  759. **
  760. ** Function AVDT_SecurityRsp
  761. **
  762. ** Description Respond to a security request from the peer device.
  763. ** This function must be called if the application receives
  764. ** an AVDT_SECURITY_IND_EVT through its control callback.
  765. ** (Please note that AVDTP security procedures are unrelated
  766. ** to Bluetooth link level security.)
  767. **
  768. **
  769. ** Returns AVDT_SUCCESS if successful, otherwise error.
  770. **
  771. *******************************************************************************/
  772. UINT16 AVDT_SecurityRsp(UINT8 handle, UINT8 label, UINT8 error_code,
  773. UINT8 *p_data, UINT16 len)
  774. {
  775. tAVDT_SCB *p_scb;
  776. UINT16 result = AVDT_SUCCESS;
  777. tAVDT_SCB_EVT evt;
  778. /* map handle to scb */
  779. if ((p_scb = avdt_scb_by_hdl(handle)) == NULL) {
  780. result = AVDT_BAD_HANDLE;
  781. }
  782. /* send event to scb */
  783. else {
  784. evt.msg.security_rsp.hdr.err_code = error_code;
  785. evt.msg.security_rsp.hdr.label = label;
  786. evt.msg.security_rsp.p_data = p_data;
  787. evt.msg.security_rsp.len = len;
  788. avdt_scb_event(p_scb, AVDT_SCB_API_SECURITY_RSP_EVT, &evt);
  789. }
  790. return result;
  791. }
  792. /*******************************************************************************
  793. **
  794. ** Function AVDT_WriteReqOpt
  795. **
  796. ** Description Send a media packet to the peer device. The stream must
  797. ** be started before this function is called. Also, this
  798. ** function can only be called if the stream is a SRC.
  799. **
  800. ** When AVDTP has sent the media packet and is ready for the
  801. ** next packet, an AVDT_WRITE_CFM_EVT is sent to the
  802. ** application via the control callback. The application must
  803. ** wait for the AVDT_WRITE_CFM_EVT before it makes the next
  804. ** call to AVDT_WriteReq(). If the applications calls
  805. ** AVDT_WriteReq() before it receives the event the packet
  806. ** will not be sent. The application may make its first call
  807. ** to AVDT_WriteReq() after it receives an AVDT_START_CFM_EVT
  808. ** or AVDT_START_IND_EVT.
  809. **
  810. ** The application passes the packet using the BT_HDR structure.
  811. ** This structure is described in section 2.1. The offset
  812. ** field must be equal to or greater than AVDT_MEDIA_OFFSET
  813. ** (if NO_RTP is specified, L2CAP_MIN_OFFSET can be used).
  814. ** This allows enough space in the buffer for the L2CAP and
  815. ** AVDTP headers.
  816. **
  817. ** The memory pointed to by p_pkt must be a GKI buffer
  818. ** allocated by the application. This buffer will be freed
  819. ** by the protocol stack; the application must not free
  820. ** this buffer.
  821. **
  822. ** The opt parameter allows passing specific options like:
  823. ** - NO_RTP : do not add the RTP header to buffer
  824. **
  825. ** Returns AVDT_SUCCESS if successful, otherwise error.
  826. **
  827. *******************************************************************************/
  828. UINT16 AVDT_WriteReqOpt(UINT8 handle, BT_HDR *p_pkt, UINT32 time_stamp, UINT8 m_pt, tAVDT_DATA_OPT_MASK opt)
  829. {
  830. tAVDT_SCB *p_scb;
  831. tAVDT_SCB_EVT evt;
  832. UINT16 result = AVDT_SUCCESS;
  833. /* map handle to scb */
  834. if ((p_scb = avdt_scb_by_hdl(handle)) == NULL) {
  835. result = AVDT_BAD_HANDLE;
  836. } else {
  837. evt.apiwrite.p_buf = p_pkt;
  838. evt.apiwrite.time_stamp = time_stamp;
  839. evt.apiwrite.m_pt = m_pt;
  840. evt.apiwrite.opt = opt;
  841. avdt_scb_event(p_scb, AVDT_SCB_API_WRITE_REQ_EVT, &evt);
  842. }
  843. return result;
  844. }
  845. /*******************************************************************************
  846. **
  847. ** Function AVDT_WriteReq
  848. **
  849. ** Description Send a media packet to the peer device. The stream must
  850. ** be started before this function is called. Also, this
  851. ** function can only be called if the stream is a SRC.
  852. **
  853. ** When AVDTP has sent the media packet and is ready for the
  854. ** next packet, an AVDT_WRITE_CFM_EVT is sent to the
  855. ** application via the control callback. The application must
  856. ** wait for the AVDT_WRITE_CFM_EVT before it makes the next
  857. ** call to AVDT_WriteReq(). If the applications calls
  858. ** AVDT_WriteReq() before it receives the event the packet
  859. ** will not be sent. The application may make its first call
  860. ** to AVDT_WriteReq() after it receives an AVDT_START_CFM_EVT
  861. ** or AVDT_START_IND_EVT.
  862. **
  863. ** The application passes the packet using the BT_HDR structure.
  864. ** This structure is described in section 2.1. The offset
  865. ** field must be equal to or greater than AVDT_MEDIA_OFFSET.
  866. ** This allows enough space in the buffer for the L2CAP and
  867. ** AVDTP headers.
  868. **
  869. ** The memory pointed to by p_pkt must be a GKI buffer
  870. ** allocated by the application. This buffer will be freed
  871. ** by the protocol stack; the application must not free
  872. ** this buffer.
  873. **
  874. **
  875. ** Returns AVDT_SUCCESS if successful, otherwise error.
  876. **
  877. *******************************************************************************/
  878. UINT16 AVDT_WriteReq(UINT8 handle, BT_HDR *p_pkt, UINT32 time_stamp, UINT8 m_pt)
  879. {
  880. return AVDT_WriteReqOpt(handle, p_pkt, time_stamp, m_pt, AVDT_DATA_OPT_NONE);
  881. }
  882. /*******************************************************************************
  883. **
  884. ** Function AVDT_ConnectReq
  885. **
  886. ** Description This function initiates an AVDTP signaling connection
  887. ** to the peer device. When the connection is completed, an
  888. ** AVDT_CONNECT_IND_EVT is sent to the application via its
  889. ** control callback function. If the connection attempt fails
  890. ** an AVDT_DISCONNECT_IND_EVT is sent. The security mask
  891. ** parameter overrides the outgoing security mask set in
  892. ** AVDT_Register().
  893. **
  894. ** Returns AVDT_SUCCESS if successful, otherwise error.
  895. **
  896. *******************************************************************************/
  897. UINT16 AVDT_ConnectReq(BD_ADDR bd_addr, UINT8 sec_mask, tAVDT_CTRL_CBACK *p_cback)
  898. {
  899. tAVDT_CCB *p_ccb = NULL;
  900. UINT16 result = AVDT_SUCCESS;
  901. tAVDT_CCB_EVT evt;
  902. /* find channel control block for this bd addr; if none, allocate one */
  903. if ((p_ccb = avdt_ccb_by_bd(bd_addr)) == NULL) {
  904. if ((p_ccb = avdt_ccb_alloc(bd_addr)) == NULL) {
  905. /* could not allocate channel control block */
  906. result = AVDT_NO_RESOURCES;
  907. }
  908. } else if (p_ccb->ll_opened == FALSE) {
  909. AVDT_TRACE_WARNING("AVDT_ConnectReq: CCB LL is in the middle of opening");
  910. /* ccb was already allocated for the incoming signalling. */
  911. result = AVDT_BUSY;
  912. }
  913. if (result == AVDT_SUCCESS) {
  914. /* send event to ccb */
  915. evt.connect.p_cback = p_cback;
  916. evt.connect.sec_mask = sec_mask;
  917. avdt_ccb_event(p_ccb, AVDT_CCB_API_CONNECT_REQ_EVT, &evt);
  918. }
  919. return result;
  920. }
  921. /*******************************************************************************
  922. **
  923. ** Function AVDT_DisconnectReq
  924. **
  925. ** Description This function disconnect an AVDTP signaling connection
  926. ** to the peer device. When disconnected an
  927. ** AVDT_DISCONNECT_IND_EVT is sent to the application via its
  928. ** control callback function.
  929. **
  930. ** Returns AVDT_SUCCESS if successful, otherwise error.
  931. **
  932. *******************************************************************************/
  933. UINT16 AVDT_DisconnectReq(BD_ADDR bd_addr, tAVDT_CTRL_CBACK *p_cback)
  934. {
  935. tAVDT_CCB *p_ccb = NULL;
  936. UINT16 result = AVDT_SUCCESS;
  937. tAVDT_CCB_EVT evt;
  938. /* find channel control block for this bd addr; if none, error */
  939. if ((p_ccb = avdt_ccb_by_bd(bd_addr)) == NULL) {
  940. result = AVDT_BAD_PARAMS;
  941. }
  942. if (result == AVDT_SUCCESS) {
  943. /* send event to ccb */
  944. evt.disconnect.p_cback = p_cback;
  945. avdt_ccb_event(p_ccb, AVDT_CCB_API_DISCONNECT_REQ_EVT, &evt);
  946. }
  947. return result;
  948. }
  949. /*******************************************************************************
  950. **
  951. ** Function AVDT_GetL2CapChannel
  952. **
  953. ** Description Get the L2CAP CID used by the handle.
  954. **
  955. ** Returns CID if successful, otherwise 0.
  956. **
  957. *******************************************************************************/
  958. UINT16 AVDT_GetL2CapChannel(UINT8 handle)
  959. {
  960. tAVDT_SCB *p_scb;
  961. tAVDT_CCB *p_ccb;
  962. UINT8 tcid;
  963. UINT16 lcid = 0;
  964. /* map handle to scb */
  965. if (((p_scb = avdt_scb_by_hdl(handle)) != NULL)
  966. && ((p_ccb = p_scb->p_ccb) != NULL)) {
  967. /* get tcid from type, scb */
  968. tcid = avdt_ad_type_to_tcid(AVDT_CHAN_MEDIA, p_scb);
  969. lcid = avdt_cb.ad.rt_tbl[avdt_ccb_to_idx(p_ccb)][tcid].lcid;
  970. }
  971. return (lcid);
  972. }
  973. /*******************************************************************************
  974. **
  975. ** Function AVDT_GetSignalChannel
  976. **
  977. ** Description Get the L2CAP CID used by the signal channel of the given handle.
  978. **
  979. ** Returns CID if successful, otherwise 0.
  980. **
  981. *******************************************************************************/
  982. UINT16 AVDT_GetSignalChannel(UINT8 handle, BD_ADDR bd_addr)
  983. {
  984. tAVDT_SCB *p_scb;
  985. tAVDT_CCB *p_ccb;
  986. UINT8 tcid = 0; /* tcid is always 0 for signal channel */
  987. UINT16 lcid = 0;
  988. /* map handle to scb */
  989. if (((p_scb = avdt_scb_by_hdl(handle)) != NULL)
  990. && ((p_ccb = p_scb->p_ccb) != NULL)) {
  991. lcid = avdt_cb.ad.rt_tbl[avdt_ccb_to_idx(p_ccb)][tcid].lcid;
  992. } else if ((p_ccb = avdt_ccb_by_bd(bd_addr)) != NULL) {
  993. lcid = avdt_cb.ad.rt_tbl[avdt_ccb_to_idx(p_ccb)][tcid].lcid;
  994. }
  995. return (lcid);
  996. }
  997. #if AVDT_MULTIPLEXING == TRUE
  998. /*******************************************************************************
  999. **
  1000. ** Function AVDT_SetMediaBuf
  1001. **
  1002. ** Description Assigns buffer for media packets or forbids using of assigned
  1003. ** buffer if argument p_buf is NULL. This function can only
  1004. ** be called if the stream is a SNK.
  1005. **
  1006. ** AVDTP uses this buffer to reassemble fragmented media packets.
  1007. ** When AVDTP receives a complete media packet, it calls the
  1008. ** p_media_cback assigned by AVDT_CreateStream().
  1009. ** This function can be called during callback to assign a
  1010. ** different buffer for next media packet or can leave the current
  1011. ** buffer for next packet.
  1012. **
  1013. ** Returns AVDT_SUCCESS if successful, otherwise error.
  1014. **
  1015. *******************************************************************************/
  1016. extern UINT16 AVDT_SetMediaBuf(UINT8 handle, UINT8 *p_buf, UINT32 buf_len)
  1017. {
  1018. tAVDT_SCB *p_scb;
  1019. UINT16 result = AVDT_SUCCESS;
  1020. /* map handle to scb */
  1021. if ((p_scb = avdt_scb_by_hdl(handle)) == NULL) {
  1022. result = AVDT_BAD_HANDLE;
  1023. } else {
  1024. if (p_buf && p_scb->cs.p_media_cback == NULL) {
  1025. result = AVDT_NO_RESOURCES;
  1026. } else {
  1027. p_scb->p_media_buf = p_buf;
  1028. p_scb->media_buf_len = buf_len;
  1029. }
  1030. }
  1031. return result;
  1032. }
  1033. #endif
  1034. #if AVDT_REPORTING == TRUE
  1035. /*******************************************************************************
  1036. **
  1037. ** Function AVDT_SendReport
  1038. **
  1039. ** Description
  1040. **
  1041. **
  1042. **
  1043. ** Returns
  1044. **
  1045. *******************************************************************************/
  1046. UINT16 AVDT_SendReport(UINT8 handle, AVDT_REPORT_TYPE type,
  1047. tAVDT_REPORT_DATA *p_data)
  1048. {
  1049. tAVDT_SCB *p_scb;
  1050. UINT16 result = AVDT_BAD_PARAMS;
  1051. BT_HDR *p_pkt;
  1052. tAVDT_TC_TBL *p_tbl;
  1053. UINT8 *p, *plen, *pm1, *p_end;
  1054. #if AVDT_MULTIPLEXING == TRUE
  1055. UINT8 *p_al = NULL, u;
  1056. #endif
  1057. UINT32 ssrc;
  1058. UINT16 len;
  1059. /* map handle to scb && verify parameters */
  1060. if (((p_scb = avdt_scb_by_hdl(handle)) != NULL)
  1061. && (p_scb->p_ccb != NULL)
  1062. && (((type == AVDT_RTCP_PT_SR) && (p_scb->cs.tsep == AVDT_TSEP_SRC)) ||
  1063. ((type == AVDT_RTCP_PT_RR) && (p_scb->cs.tsep == AVDT_TSEP_SNK)) ||
  1064. (type == AVDT_RTCP_PT_SDES)) ) {
  1065. result = AVDT_NO_RESOURCES;
  1066. /* build SR - assume fit in one packet */
  1067. p_tbl = avdt_ad_tc_tbl_by_type(AVDT_CHAN_REPORT, p_scb->p_ccb, p_scb);
  1068. if ((p_tbl->state == AVDT_AD_ST_OPEN) &&
  1069. (p_pkt = (BT_HDR *)osi_malloc(p_tbl->peer_mtu)) != NULL) {
  1070. p_pkt->offset = L2CAP_MIN_OFFSET;
  1071. p = (UINT8 *)(p_pkt + 1) + p_pkt->offset;
  1072. #if AVDT_MULTIPLEXING == TRUE
  1073. if (p_scb->curr_cfg.psc_mask & AVDT_PSC_MUX) {
  1074. /* Adaptation Layer header later */
  1075. p_al = p;
  1076. p += 2;
  1077. }
  1078. #endif
  1079. pm1 = p;
  1080. *p++ = AVDT_MEDIA_OCTET1 | 1;
  1081. *p++ = type;
  1082. /* save the location for length */
  1083. plen = p;
  1084. p += 2;
  1085. ssrc = avdt_scb_gen_ssrc(p_scb);
  1086. UINT32_TO_BE_STREAM(p, ssrc);
  1087. switch (type) {
  1088. case AVDT_RTCP_PT_SR: /* Sender Report */
  1089. *pm1 = AVDT_MEDIA_OCTET1;
  1090. UINT32_TO_BE_STREAM(p, p_data->sr.ntp_sec);
  1091. UINT32_TO_BE_STREAM(p, p_data->sr.ntp_frac);
  1092. UINT32_TO_BE_STREAM(p, p_data->sr.rtp_time);
  1093. UINT32_TO_BE_STREAM(p, p_data->sr.pkt_count);
  1094. UINT32_TO_BE_STREAM(p, p_data->sr.octet_count);
  1095. break;
  1096. case AVDT_RTCP_PT_RR: /* Receiver Report */
  1097. *p++ = p_data->rr.frag_lost;
  1098. AVDT_TRACE_API("packet_lost: %d\n", p_data->rr.packet_lost);
  1099. p_data->rr.packet_lost &= 0xFFFFFF;
  1100. AVDT_TRACE_API("packet_lost: %d\n", p_data->rr.packet_lost);
  1101. UINT24_TO_BE_STREAM(p, p_data->rr.packet_lost);
  1102. UINT32_TO_BE_STREAM(p, p_data->rr.seq_num_rcvd);
  1103. UINT32_TO_BE_STREAM(p, p_data->rr.jitter);
  1104. UINT32_TO_BE_STREAM(p, p_data->rr.lsr);
  1105. UINT32_TO_BE_STREAM(p, p_data->rr.dlsr);
  1106. break;
  1107. case AVDT_RTCP_PT_SDES: /* Source Description */
  1108. *p++ = AVDT_RTCP_SDES_CNAME;
  1109. len = strlen((char *)p_data->cname);
  1110. if (len > AVDT_MAX_CNAME_SIZE) {
  1111. len = AVDT_MAX_CNAME_SIZE;
  1112. }
  1113. *p++ = (UINT8)len;
  1114. BCM_STRNCPY_S((char *)p, (char *)p_data->cname, AVDT_MAX_CNAME_SIZE + 1);
  1115. p += len;
  1116. break;
  1117. }
  1118. p_end = p;
  1119. len = p - pm1 - 1;
  1120. UINT16_TO_BE_STREAM(plen, len);
  1121. #if AVDT_MULTIPLEXING == TRUE
  1122. if (p_scb->curr_cfg.psc_mask & AVDT_PSC_MUX) {
  1123. /* Adaptation Layer header */
  1124. p = p_al;
  1125. len++;
  1126. UINT16_TO_BE_STREAM(p_al, len );
  1127. /* TSID, no-fragment bit and coding of length(9-bit length field) */
  1128. u = *p;
  1129. *p = (p_scb->curr_cfg.mux_tsid_report << 3) | AVDT_ALH_LCODE_9BITM0;
  1130. if (u) {
  1131. *p |= AVDT_ALH_LCODE_9BITM1;
  1132. }
  1133. }
  1134. #endif
  1135. /* set the actual payload length */
  1136. p_pkt->len = p_end - p;
  1137. /* send the packet */
  1138. if (L2CAP_DW_FAILED != avdt_ad_write_req(AVDT_CHAN_REPORT, p_scb->p_ccb, p_scb, p_pkt)) {
  1139. result = AVDT_SUCCESS;
  1140. }
  1141. }
  1142. }
  1143. return result;
  1144. }
  1145. #endif
  1146. /******************************************************************************
  1147. **
  1148. ** Function AVDT_SetTraceLevel
  1149. **
  1150. ** Description Sets the trace level for AVDT. If 0xff is passed, the
  1151. ** current trace level is returned.
  1152. **
  1153. ** Input Parameters:
  1154. ** new_level: The level to set the AVDT tracing to:
  1155. ** 0xff-returns the current setting.
  1156. ** 0-turns off tracing.
  1157. ** >= 1-Errors.
  1158. ** >= 2-Warnings.
  1159. ** >= 3-APIs.
  1160. ** >= 4-Events.
  1161. ** >= 5-Debug.
  1162. **
  1163. ** Returns The new trace level or current trace level if
  1164. ** the input parameter is 0xff.
  1165. **
  1166. ******************************************************************************/
  1167. UINT8 AVDT_SetTraceLevel (UINT8 new_level)
  1168. {
  1169. if (new_level != 0xFF) {
  1170. avdt_cb.trace_level = new_level;
  1171. }
  1172. return (avdt_cb.trace_level);
  1173. }
  1174. /*******************************************************************************
  1175. **
  1176. ** Function AVDT_SetDelayValue
  1177. **
  1178. ** Description Set delay reporting value.
  1179. **
  1180. ** Returns void
  1181. **
  1182. *******************************************************************************/
  1183. void AVDT_SetDelayValue(UINT16 delay_value)
  1184. {
  1185. avdt_cb.delay_value = delay_value;
  1186. }
  1187. /*******************************************************************************
  1188. **
  1189. ** Function AVDT_GetDelayValue
  1190. **
  1191. ** Description Get delay reporting value.
  1192. **
  1193. ** Returns delay value
  1194. **
  1195. *******************************************************************************/
  1196. UINT16 AVDT_GetDelayValue(void)
  1197. {
  1198. return avdt_cb.delay_value;
  1199. }
  1200. #endif /* #if (defined(AVDT_INCLUDED) && AVDT_INCLUDED == TRUE) */