avdt_api.c 45 KB

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