avdt_scb_act.cc 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576
  1. /******************************************************************************
  2. *
  3. * Copyright 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 the action functions associated with the stream
  21. * control block state machine.
  22. *
  23. ******************************************************************************/
  24. #include <cutils/log.h>
  25. #include <string.h>
  26. #include "a2dp_codec_api.h"
  27. #include "avdt_api.h"
  28. #include "avdt_int.h"
  29. #include "avdtc_api.h"
  30. #include "bt_common.h"
  31. #include "bt_target.h"
  32. #include "bt_types.h"
  33. #include "bt_utils.h"
  34. #include "btu.h"
  35. #include "osi/include/osi.h"
  36. /* This table is used to lookup the callback event that matches a particular
  37. * state machine API request event. Note that state machine API request
  38. * events are at the beginning of the event list starting at zero, thus
  39. * allowing for this table.
  40. */
  41. const uint8_t avdt_scb_cback_evt[] = {
  42. 0, /* API_REMOVE_EVT (no event) */
  43. AVDT_WRITE_CFM_EVT, /* API_WRITE_REQ_EVT */
  44. 0, /* API_GETCONFIG_REQ_EVT (no event) */
  45. 0, /* API_DELAY_RPT_REQ_EVT (no event) */
  46. AVDT_OPEN_CFM_EVT, /* API_SETCONFIG_REQ_EVT */
  47. AVDT_OPEN_CFM_EVT, /* API_OPEN_REQ_EVT */
  48. AVDT_CLOSE_CFM_EVT, /* API_CLOSE_REQ_EVT */
  49. AVDT_RECONFIG_CFM_EVT, /* API_RECONFIG_REQ_EVT */
  50. AVDT_SECURITY_CFM_EVT, /* API_SECURITY_REQ_EVT */
  51. 0 /* API_ABORT_REQ_EVT (no event) */
  52. };
  53. /*******************************************************************************
  54. *
  55. * Function avdt_scb_gen_ssrc
  56. *
  57. * Description This function generates a SSRC number unique to the stream.
  58. *
  59. * Returns SSRC value.
  60. *
  61. ******************************************************************************/
  62. uint32_t avdt_scb_gen_ssrc(AvdtpScb* p_scb) {
  63. /* combine the value of the media type and codec type of the SCB */
  64. return ((uint32_t)(p_scb->stream_config.cfg.codec_info[1] |
  65. p_scb->stream_config.cfg.codec_info[2]));
  66. }
  67. /*******************************************************************************
  68. *
  69. * Function avdt_scb_hdl_abort_cmd
  70. *
  71. * Description This function sends the SCB an AVDT_SCB_API_ABORT_RSP_EVT
  72. * to initiate sending of an abort response message.
  73. *
  74. * Returns Nothing.
  75. *
  76. ******************************************************************************/
  77. void avdt_scb_hdl_abort_cmd(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data) {
  78. p_scb->role = AVDT_CLOSE_ACP;
  79. avdt_scb_event(p_scb, AVDT_SCB_API_ABORT_RSP_EVT, p_data);
  80. }
  81. /*******************************************************************************
  82. *
  83. * Function avdt_scb_hdl_abort_rsp
  84. *
  85. * Description This function is an empty function; it serves as a
  86. * placeholder for a conformance API action function.
  87. *
  88. * Returns Nothing.
  89. *
  90. ******************************************************************************/
  91. void avdt_scb_hdl_abort_rsp(UNUSED_ATTR AvdtpScb* p_scb,
  92. UNUSED_ATTR tAVDT_SCB_EVT* p_data) {
  93. return;
  94. }
  95. /*******************************************************************************
  96. *
  97. * Function avdt_scb_hdl_close_cmd
  98. *
  99. * Description This function sends the SCB an AVDT_SCB_API_CLOSE_RSP_EVT
  100. * to initiate sending of a close response message.
  101. *
  102. * Returns Nothing.
  103. *
  104. ******************************************************************************/
  105. void avdt_scb_hdl_close_cmd(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data) {
  106. p_scb->role = AVDT_CLOSE_ACP;
  107. avdt_scb_event(p_scb, AVDT_SCB_API_CLOSE_RSP_EVT, p_data);
  108. }
  109. /*******************************************************************************
  110. *
  111. * Function avdt_scb_hdl_close_rsp
  112. *
  113. * Description This function sets the close_code variable to the error
  114. * code returned in the close response.
  115. *
  116. * Returns Nothing.
  117. *
  118. ******************************************************************************/
  119. void avdt_scb_hdl_close_rsp(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data) {
  120. p_scb->close_code = p_data->msg.hdr.err_code;
  121. }
  122. /*******************************************************************************
  123. *
  124. * Function avdt_scb_hdl_getconfig_cmd
  125. *
  126. * Description This function retrieves the configuration parameters of
  127. * the SCB and sends the SCB an AVDT_SCB_API_GETCONFIG_RSP_EVT
  128. * to initiate sending of a get configuration response message.
  129. *
  130. * Returns Nothing.
  131. *
  132. ******************************************************************************/
  133. void avdt_scb_hdl_getconfig_cmd(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data) {
  134. p_data->msg.svccap.p_cfg = &p_scb->curr_cfg;
  135. avdt_scb_event(p_scb, AVDT_SCB_API_GETCONFIG_RSP_EVT, p_data);
  136. }
  137. /*******************************************************************************
  138. *
  139. * Function avdt_scb_hdl_getconfig_rsp
  140. *
  141. * Description This function is an empty function; it serves as a
  142. * placeholder for a conformance API action function.
  143. *
  144. * Returns Nothing.
  145. *
  146. ******************************************************************************/
  147. void avdt_scb_hdl_getconfig_rsp(UNUSED_ATTR AvdtpScb* p_scb,
  148. UNUSED_ATTR tAVDT_SCB_EVT* p_data) {
  149. return;
  150. }
  151. /*******************************************************************************
  152. *
  153. * Function avdt_scb_hdl_open_cmd
  154. *
  155. * Description This function sends the SCB an AVDT_SCB_API_OPEN_RSP_EVT
  156. * to initiate sending of an open response message.
  157. *
  158. * Returns Nothing.
  159. *
  160. ******************************************************************************/
  161. void avdt_scb_hdl_open_cmd(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data) {
  162. avdt_scb_event(p_scb, AVDT_SCB_API_OPEN_RSP_EVT, p_data);
  163. }
  164. /*******************************************************************************
  165. *
  166. * Function avdt_scb_hdl_open_rej
  167. *
  168. * Description This function calls the application callback function
  169. * indicating the open request has failed. It initializes
  170. * certain SCB variables and sends a AVDT_CCB_UL_CLOSE_EVT
  171. * to the CCB.
  172. *
  173. * Returns Nothing.
  174. *
  175. ******************************************************************************/
  176. void avdt_scb_hdl_open_rej(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data) {
  177. /* do exactly same as setconfig reject */
  178. avdt_scb_hdl_setconfig_rej(p_scb, p_data);
  179. }
  180. /*******************************************************************************
  181. *
  182. * Function avdt_scb_hdl_open_rsp
  183. *
  184. * Description This function calls avdt_ad_open_req() to initiate
  185. * connection of the transport channel for this stream.
  186. *
  187. * Returns Nothing.
  188. *
  189. ******************************************************************************/
  190. void avdt_scb_hdl_open_rsp(AvdtpScb* p_scb, UNUSED_ATTR tAVDT_SCB_EVT* p_data) {
  191. /* initiate opening of trans channels for this SEID */
  192. p_scb->role = AVDT_OPEN_INT;
  193. avdt_ad_open_req(AVDT_CHAN_MEDIA, p_scb->p_ccb, p_scb, AVDT_INT);
  194. /* start tc connect timer */
  195. alarm_set_on_mloop(p_scb->transport_channel_timer,
  196. AVDT_SCB_TC_CONN_TIMEOUT_MS,
  197. avdt_scb_transport_channel_timer_timeout, p_scb);
  198. }
  199. /*******************************************************************************
  200. *
  201. * Function avdt_scb_hdl_pkt_no_frag
  202. *
  203. * Description
  204. *
  205. * Returns Nothing.
  206. *
  207. ******************************************************************************/
  208. void avdt_scb_hdl_pkt_no_frag(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data) {
  209. uint8_t *p, *p_start;
  210. uint8_t o_v, o_p, o_x, o_cc;
  211. uint8_t m_pt;
  212. uint8_t marker;
  213. uint16_t seq;
  214. uint32_t time_stamp;
  215. uint16_t offset;
  216. uint16_t ex_len;
  217. uint8_t pad_len = 0;
  218. uint16_t len = p_data->p_pkt->len;
  219. p = p_start = (uint8_t*)(p_data->p_pkt + 1) + p_data->p_pkt->offset;
  220. /* parse media packet header */
  221. offset = 12;
  222. // AVDT_MSG_PRS_OCTET1(1) + AVDT_MSG_PRS_M_PT(1) + UINT16(2) + UINT32(4) + 4
  223. if (offset > len) goto length_error;
  224. AVDT_MSG_PRS_OCTET1(p, o_v, o_p, o_x, o_cc);
  225. AVDT_MSG_PRS_M_PT(p, m_pt, marker);
  226. BE_STREAM_TO_UINT16(seq, p);
  227. BE_STREAM_TO_UINT32(time_stamp, p);
  228. p += 4;
  229. /* skip over any csrc's in packet */
  230. offset += o_cc * 4;
  231. p += o_cc * 4;
  232. /* check for and skip over extension header */
  233. if (o_x) {
  234. offset += 4;
  235. if (offset > len) goto length_error;
  236. p += 2;
  237. BE_STREAM_TO_UINT16(ex_len, p);
  238. offset += ex_len * 4;
  239. p += ex_len * 4;
  240. }
  241. /* adjust length for any padding at end of packet */
  242. if (o_p) {
  243. /* padding length in last byte of packet */
  244. pad_len = *(p_start + p_data->p_pkt->len);
  245. }
  246. /* do sanity check */
  247. if ((offset > p_data->p_pkt->len) ||
  248. ((pad_len + offset) > p_data->p_pkt->len)) {
  249. AVDT_TRACE_WARNING("Got bad media packet");
  250. osi_free_and_reset((void**)&p_data->p_pkt);
  251. }
  252. /* adjust offset and length and send it up */
  253. else {
  254. p_data->p_pkt->len -= (offset + pad_len);
  255. p_data->p_pkt->offset += offset;
  256. if (p_scb->stream_config.p_sink_data_cback != NULL) {
  257. /* report sequence number */
  258. p_data->p_pkt->layer_specific = seq;
  259. (*p_scb->stream_config.p_sink_data_cback)(
  260. avdt_scb_to_hdl(p_scb), p_data->p_pkt, time_stamp,
  261. (uint8_t)(m_pt | (marker << 7)));
  262. } else {
  263. osi_free_and_reset((void**)&p_data->p_pkt);
  264. }
  265. }
  266. return;
  267. length_error:
  268. android_errorWriteLog(0x534e4554, "111450156");
  269. AVDT_TRACE_WARNING("%s: hdl packet length %d too short: must be at least %d",
  270. __func__, len, offset);
  271. osi_free_and_reset((void**)&p_data->p_pkt);
  272. }
  273. /*******************************************************************************
  274. *
  275. * Function avdt_scb_hdl_report
  276. *
  277. * Description
  278. *
  279. * Returns Nothing.
  280. *
  281. ******************************************************************************/
  282. uint8_t* avdt_scb_hdl_report(AvdtpScb* p_scb, uint8_t* p, uint16_t len) {
  283. uint16_t result = AVDT_SUCCESS;
  284. uint8_t* p_start = p;
  285. uint32_t ssrc;
  286. uint8_t o_v, o_p, o_cc;
  287. uint16_t min_len = 0;
  288. AVDT_REPORT_TYPE pt;
  289. tAVDT_REPORT_DATA report;
  290. AVDT_TRACE_DEBUG("%s", __func__);
  291. if (p_scb->stream_config.p_report_cback) {
  292. /* parse report packet header */
  293. min_len += 8;
  294. if (min_len > len) {
  295. android_errorWriteLog(0x534e4554, "111450156");
  296. AVDT_TRACE_WARNING(
  297. "%s: hdl packet length %d too short: must be at least %d", __func__,
  298. len, min_len);
  299. goto avdt_scb_hdl_report_exit;
  300. }
  301. AVDT_MSG_PRS_RPT_OCTET1(p, o_v, o_p, o_cc);
  302. pt = *p++;
  303. p += 2;
  304. BE_STREAM_TO_UINT32(ssrc, p);
  305. switch (pt) {
  306. case AVDT_RTCP_PT_SR: /* the packet type - SR (Sender Report) */
  307. min_len += 20;
  308. if (min_len > len) {
  309. android_errorWriteLog(0x534e4554, "111450156");
  310. AVDT_TRACE_WARNING(
  311. "%s: hdl packet length %d too short: must be at least %d",
  312. __func__, len, min_len);
  313. goto avdt_scb_hdl_report_exit;
  314. }
  315. BE_STREAM_TO_UINT32(report.sr.ntp_sec, p);
  316. BE_STREAM_TO_UINT32(report.sr.ntp_frac, p);
  317. BE_STREAM_TO_UINT32(report.sr.rtp_time, p);
  318. BE_STREAM_TO_UINT32(report.sr.pkt_count, p);
  319. BE_STREAM_TO_UINT32(report.sr.octet_count, p);
  320. break;
  321. case AVDT_RTCP_PT_RR: /* the packet type - RR (Receiver Report) */
  322. min_len += 20;
  323. if (min_len > len) {
  324. android_errorWriteLog(0x534e4554, "111450156");
  325. AVDT_TRACE_WARNING(
  326. "%s: hdl packet length %d too short: must be at least %d",
  327. __func__, len, min_len);
  328. goto avdt_scb_hdl_report_exit;
  329. }
  330. report.rr.frag_lost = *p;
  331. BE_STREAM_TO_UINT32(report.rr.packet_lost, p);
  332. report.rr.packet_lost &= 0xFFFFFF;
  333. BE_STREAM_TO_UINT32(report.rr.seq_num_rcvd, p);
  334. BE_STREAM_TO_UINT32(report.rr.jitter, p);
  335. BE_STREAM_TO_UINT32(report.rr.lsr, p);
  336. BE_STREAM_TO_UINT32(report.rr.dlsr, p);
  337. break;
  338. case AVDT_RTCP_PT_SDES: /* the packet type - SDES (Source Description) */
  339. uint8_t sdes_type;
  340. min_len += 1;
  341. if (min_len > len) {
  342. android_errorWriteLog(0x534e4554, "111450156");
  343. AVDT_TRACE_WARNING(
  344. "%s: hdl packet length %d too short: must be at least %d",
  345. __func__, len, min_len);
  346. goto avdt_scb_hdl_report_exit;
  347. }
  348. BE_STREAM_TO_UINT8(sdes_type, p);
  349. if (sdes_type == AVDT_RTCP_SDES_CNAME) {
  350. uint8_t name_length;
  351. min_len += 1;
  352. if (min_len > len) {
  353. android_errorWriteLog(0x534e4554, "111450156");
  354. AVDT_TRACE_WARNING(
  355. "%s: hdl packet length %d too short: must be at least %d",
  356. __func__, len, min_len);
  357. goto avdt_scb_hdl_report_exit;
  358. }
  359. BE_STREAM_TO_UINT8(name_length, p);
  360. if (name_length > len - 2 || name_length > AVDT_MAX_CNAME_SIZE) {
  361. result = AVDT_BAD_PARAMS;
  362. } else {
  363. BE_STREAM_TO_ARRAY(p, &(report.cname[0]), name_length);
  364. }
  365. } else {
  366. if (min_len + 1 > len) {
  367. android_errorWriteLog(0x534e4554, "111450156");
  368. AVDT_TRACE_WARNING(
  369. "%s: hdl packet length %d too short: must be at least %d",
  370. __func__, len, min_len);
  371. goto avdt_scb_hdl_report_exit;
  372. }
  373. AVDT_TRACE_WARNING(" - SDES SSRC=0x%08x sc=%d %d len=%d %s", ssrc,
  374. o_cc, *p, *(p + 1), p + 2);
  375. result = AVDT_BUSY;
  376. }
  377. break;
  378. default:
  379. AVDT_TRACE_ERROR("Bad Report pkt - packet type: %d", pt);
  380. result = AVDT_BAD_PARAMS;
  381. }
  382. if (result == AVDT_SUCCESS)
  383. (*p_scb->stream_config.p_report_cback)(avdt_scb_to_hdl(p_scb), pt,
  384. &report);
  385. }
  386. avdt_scb_hdl_report_exit:
  387. p_start += len;
  388. return p_start;
  389. }
  390. /*******************************************************************************
  391. *
  392. * Function avdt_scb_hdl_pkt
  393. *
  394. * Description
  395. *
  396. * Returns Nothing.
  397. *
  398. ******************************************************************************/
  399. void avdt_scb_hdl_pkt(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data) {
  400. if (p_data->p_pkt->layer_specific == AVDT_CHAN_REPORT) {
  401. uint8_t* p = (uint8_t*)(p_data->p_pkt + 1) + p_data->p_pkt->offset;
  402. avdt_scb_hdl_report(p_scb, p, p_data->p_pkt->len);
  403. osi_free_and_reset((void**)&p_data->p_pkt);
  404. } else {
  405. avdt_scb_hdl_pkt_no_frag(p_scb, p_data);
  406. }
  407. }
  408. /*******************************************************************************
  409. *
  410. * Function avdt_scb_drop_pkt
  411. *
  412. * Description Drop an incoming media packet. This function is called if
  413. * a media packet is received in any state besides streaming.
  414. *
  415. * Returns Nothing.
  416. *
  417. ******************************************************************************/
  418. void avdt_scb_drop_pkt(UNUSED_ATTR AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data) {
  419. AVDT_TRACE_ERROR("%s dropped incoming media packet", __func__);
  420. osi_free_and_reset((void**)&p_data->p_pkt);
  421. }
  422. /*******************************************************************************
  423. *
  424. * Function avdt_scb_hdl_reconfig_cmd
  425. *
  426. * Description This function calls the application callback function
  427. * with a reconfiguration indication.
  428. *
  429. * Returns Nothing.
  430. *
  431. ******************************************************************************/
  432. void avdt_scb_hdl_reconfig_cmd(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data) {
  433. /* if command not supported */
  434. if (p_scb->stream_config.nsc_mask & AvdtpStreamConfig::AVDT_NSC_RECONFIG) {
  435. /* send reject */
  436. p_data->msg.hdr.err_code = AVDT_ERR_NSC;
  437. p_data->msg.hdr.err_param = 0;
  438. avdt_scb_event(p_scb, AVDT_SCB_API_RECONFIG_RSP_EVT, p_data);
  439. } else {
  440. /* store requested configuration */
  441. p_scb->req_cfg = *p_data->msg.reconfig_cmd.p_cfg;
  442. /* call application callback */
  443. (*p_scb->stream_config.p_avdt_ctrl_cback)(
  444. avdt_scb_to_hdl(p_scb), RawAddress::kEmpty, AVDT_RECONFIG_IND_EVT,
  445. (tAVDT_CTRL*)&p_data->msg.reconfig_cmd, p_scb->stream_config.scb_index);
  446. }
  447. }
  448. /*******************************************************************************
  449. *
  450. * Function avdt_scb_hdl_reconfig_rsp
  451. *
  452. * Description This function calls the application callback function
  453. * with a reconfiguration confirm.
  454. *
  455. * Returns Nothing.
  456. *
  457. ******************************************************************************/
  458. void avdt_scb_hdl_reconfig_rsp(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data) {
  459. if (p_data->msg.hdr.err_code == 0) {
  460. /* store new configuration */
  461. if (p_scb->req_cfg.num_codec > 0) {
  462. p_scb->curr_cfg.num_codec = p_scb->req_cfg.num_codec;
  463. memcpy(p_scb->curr_cfg.codec_info, p_scb->req_cfg.codec_info,
  464. AVDT_CODEC_SIZE);
  465. }
  466. if (p_scb->req_cfg.num_protect > 0) {
  467. p_scb->curr_cfg.num_protect = p_scb->req_cfg.num_protect;
  468. memcpy(p_scb->curr_cfg.protect_info, p_scb->req_cfg.protect_info,
  469. AVDT_PROTECT_SIZE);
  470. }
  471. }
  472. p_data->msg.svccap.p_cfg = &p_scb->curr_cfg;
  473. /* call application callback */
  474. (*p_scb->stream_config.p_avdt_ctrl_cback)(
  475. avdt_scb_to_hdl(p_scb), RawAddress::kEmpty, AVDT_RECONFIG_CFM_EVT,
  476. (tAVDT_CTRL*)&p_data->msg.svccap, p_scb->stream_config.scb_index);
  477. }
  478. /*******************************************************************************
  479. *
  480. * Function avdt_scb_hdl_security_cmd
  481. *
  482. * Description This function calls the application callback with a
  483. * security indication.
  484. *
  485. * Returns Nothing.
  486. *
  487. ******************************************************************************/
  488. void avdt_scb_hdl_security_cmd(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data) {
  489. /* if command not supported */
  490. if (p_scb->stream_config.nsc_mask & AvdtpStreamConfig::AVDT_NSC_SECURITY) {
  491. /* send reject */
  492. p_data->msg.hdr.err_code = AVDT_ERR_NSC;
  493. avdt_scb_event(p_scb, AVDT_SCB_API_SECURITY_RSP_EVT, p_data);
  494. } else {
  495. /* call application callback */
  496. (*p_scb->stream_config.p_avdt_ctrl_cback)(
  497. avdt_scb_to_hdl(p_scb), RawAddress::kEmpty, AVDT_SECURITY_IND_EVT,
  498. (tAVDT_CTRL*)&p_data->msg.security_cmd, p_scb->stream_config.scb_index);
  499. }
  500. }
  501. /*******************************************************************************
  502. *
  503. * Function avdt_scb_hdl_security_rsp
  504. *
  505. * Description This function calls the application callback with a
  506. * security confirm.
  507. *
  508. * Returns Nothing.
  509. *
  510. ******************************************************************************/
  511. void avdt_scb_hdl_security_rsp(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data) {
  512. /* call application callback */
  513. (*p_scb->stream_config.p_avdt_ctrl_cback)(
  514. avdt_scb_to_hdl(p_scb), RawAddress::kEmpty, AVDT_SECURITY_CFM_EVT,
  515. (tAVDT_CTRL*)&p_data->msg.security_cmd, p_scb->stream_config.scb_index);
  516. }
  517. /*******************************************************************************
  518. *
  519. * Function avdt_scb_hdl_setconfig_cmd
  520. *
  521. * Description This function marks the SCB as in use and copies the
  522. * configuration and peer SEID to the SCB. It then calls
  523. * the application callback with a configuration indication.
  524. *
  525. * Returns Nothing.
  526. *
  527. ******************************************************************************/
  528. void avdt_scb_hdl_setconfig_cmd(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data) {
  529. AVDT_TRACE_DEBUG("%s: p_scb->in_use=%d p_avdt_scb=%p scb_index=%d", __func__,
  530. p_scb->in_use, p_scb, p_scb->stream_config.scb_index);
  531. if (!p_scb->in_use) {
  532. AVDT_TRACE_DEBUG(
  533. "%s: codec: %s", __func__,
  534. A2DP_CodecInfoString(p_scb->stream_config.cfg.codec_info).c_str());
  535. AVDT_TRACE_DEBUG(
  536. "%s: codec: %s", __func__,
  537. A2DP_CodecInfoString(p_data->msg.config_cmd.p_cfg->codec_info).c_str());
  538. AvdtpSepConfig* p_cfg = p_data->msg.config_cmd.p_cfg;
  539. if (A2DP_GetCodecType(p_scb->stream_config.cfg.codec_info) ==
  540. A2DP_GetCodecType(p_cfg->codec_info)) {
  541. /* copy info to scb */
  542. AvdtpCcb* p_ccb = avdt_ccb_by_idx(p_data->msg.config_cmd.hdr.ccb_idx);
  543. if (p_scb->p_ccb != p_ccb) {
  544. AVDT_TRACE_ERROR(
  545. "%s: mismatch in AVDTP SCB/CCB state: (p_scb->p_ccb=%p != "
  546. "p_ccb=%p): "
  547. "p_scb=%p scb_handle=%d ccb_idx=%d",
  548. __func__, p_scb->p_ccb, p_ccb, p_scb, p_scb->ScbHandle(),
  549. p_data->msg.config_cmd.hdr.ccb_idx);
  550. avdt_scb_rej_not_in_use(p_scb, p_data);
  551. return;
  552. }
  553. /* set sep as in use */
  554. p_scb->in_use = true;
  555. p_scb->peer_seid = p_data->msg.config_cmd.int_seid;
  556. p_scb->req_cfg = *p_cfg;
  557. /* call app callback */
  558. /* handle of scb- which is same as sep handle of bta_av_cb.p_scb*/
  559. (*p_scb->stream_config.p_avdt_ctrl_cback)(
  560. avdt_scb_to_hdl(p_scb),
  561. p_scb->p_ccb ? p_scb->p_ccb->peer_addr : RawAddress::kEmpty,
  562. AVDT_CONFIG_IND_EVT, (tAVDT_CTRL*)&p_data->msg.config_cmd,
  563. p_scb->stream_config.scb_index);
  564. } else {
  565. p_data->msg.hdr.err_code = AVDT_ERR_UNSUP_CFG;
  566. p_data->msg.hdr.err_param = 0;
  567. avdt_msg_send_rej(avdt_ccb_by_idx(p_data->msg.hdr.ccb_idx),
  568. p_data->msg.hdr.sig_id, &p_data->msg);
  569. }
  570. } else {
  571. AVDT_TRACE_DEBUG("%s: calling avdt_scb_rej_in_use()", __func__);
  572. avdt_scb_rej_in_use(p_scb, p_data);
  573. }
  574. }
  575. /*******************************************************************************
  576. *
  577. * Function avdt_scb_hdl_setconfig_rej
  578. *
  579. * Description This function marks the SCB as not in use and calls the
  580. * application callback with an open confirm indicating
  581. * failure.
  582. *
  583. * Returns Nothing.
  584. *
  585. ******************************************************************************/
  586. void avdt_scb_hdl_setconfig_rej(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data) {
  587. /* clear scb variables */
  588. avdt_scb_clr_vars(p_scb, p_data);
  589. /* tell ccb we're done with signaling channel */
  590. avdt_ccb_event(avdt_ccb_by_idx(p_data->msg.hdr.ccb_idx),
  591. AVDT_CCB_UL_CLOSE_EVT, NULL);
  592. /* call application callback */
  593. (*p_scb->stream_config.p_avdt_ctrl_cback)(
  594. avdt_scb_to_hdl(p_scb), RawAddress::kEmpty, AVDT_OPEN_CFM_EVT,
  595. (tAVDT_CTRL*)&p_data->msg.hdr, p_scb->stream_config.scb_index);
  596. }
  597. /*******************************************************************************
  598. *
  599. * Function avdt_scb_hdl_setconfig_rsp
  600. *
  601. * Description This function sends the SCB an AVDT_SCB_API_OPEN_REQ_EVT
  602. * to initiate sending of an open command message.
  603. *
  604. * Returns Nothing.
  605. *
  606. ******************************************************************************/
  607. void avdt_scb_hdl_setconfig_rsp(AvdtpScb* p_scb,
  608. UNUSED_ATTR tAVDT_SCB_EVT* p_data) {
  609. tAVDT_EVT_HDR single;
  610. if (p_scb->p_ccb != NULL) {
  611. /* save configuration */
  612. p_scb->curr_cfg = p_scb->req_cfg;
  613. /* initiate open */
  614. single.seid = p_scb->peer_seid;
  615. tAVDT_SCB_EVT avdt_scb_evt;
  616. avdt_scb_evt.msg.single = single;
  617. avdt_scb_event(p_scb, AVDT_SCB_API_OPEN_REQ_EVT, &avdt_scb_evt);
  618. }
  619. }
  620. /*******************************************************************************
  621. *
  622. * Function avdt_scb_hdl_start_cmd
  623. *
  624. * Description This function calls the application callback with a
  625. * start indication.
  626. *
  627. * Returns Nothing.
  628. *
  629. ******************************************************************************/
  630. void avdt_scb_hdl_start_cmd(AvdtpScb* p_scb,
  631. UNUSED_ATTR tAVDT_SCB_EVT* p_data) {
  632. (*p_scb->stream_config.p_avdt_ctrl_cback)(
  633. avdt_scb_to_hdl(p_scb),
  634. p_scb->p_ccb ? p_scb->p_ccb->peer_addr : RawAddress::kEmpty,
  635. AVDT_START_IND_EVT, NULL, p_scb->stream_config.scb_index);
  636. }
  637. /*******************************************************************************
  638. *
  639. * Function avdt_scb_hdl_start_rsp
  640. *
  641. * Description This function calls the application callback with a
  642. * start confirm.
  643. *
  644. * Returns Nothing.
  645. *
  646. ******************************************************************************/
  647. void avdt_scb_hdl_start_rsp(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data) {
  648. (*p_scb->stream_config.p_avdt_ctrl_cback)(
  649. avdt_scb_to_hdl(p_scb),
  650. p_scb->p_ccb ? p_scb->p_ccb->peer_addr : RawAddress::kEmpty,
  651. AVDT_START_CFM_EVT, (tAVDT_CTRL*)&p_data->msg.hdr,
  652. p_scb->stream_config.scb_index);
  653. }
  654. /*******************************************************************************
  655. *
  656. * Function avdt_scb_hdl_suspend_cmd
  657. *
  658. * Description This function calls the application callback with a suspend
  659. * indication.
  660. *
  661. * Returns Nothing.
  662. *
  663. ******************************************************************************/
  664. void avdt_scb_hdl_suspend_cmd(AvdtpScb* p_scb,
  665. UNUSED_ATTR tAVDT_SCB_EVT* p_data) {
  666. (*p_scb->stream_config.p_avdt_ctrl_cback)(
  667. avdt_scb_to_hdl(p_scb),
  668. p_scb->p_ccb ? p_scb->p_ccb->peer_addr : RawAddress::kEmpty,
  669. AVDT_SUSPEND_IND_EVT, NULL, p_scb->stream_config.scb_index);
  670. }
  671. /*******************************************************************************
  672. *
  673. * Function avdt_scb_hdl_suspend_rsp
  674. *
  675. * Description This function calls the application callback with a suspend
  676. * confirm.
  677. *
  678. * Returns Nothing.
  679. *
  680. ******************************************************************************/
  681. void avdt_scb_hdl_suspend_rsp(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data) {
  682. (*p_scb->stream_config.p_avdt_ctrl_cback)(
  683. avdt_scb_to_hdl(p_scb),
  684. p_scb->p_ccb ? p_scb->p_ccb->peer_addr : RawAddress::kEmpty,
  685. AVDT_SUSPEND_CFM_EVT, (tAVDT_CTRL*)&p_data->msg.hdr,
  686. p_scb->stream_config.scb_index);
  687. }
  688. /*******************************************************************************
  689. *
  690. * Function avdt_scb_hdl_tc_close
  691. *
  692. * Description This function is called when the transport channel is
  693. * closed. It marks the SCB as not in use and
  694. * initializes certain SCB parameters. It then sends
  695. * an AVDT_CCB_UL_CLOSE_EVT to the CCB if the SCB
  696. * initiated the close. It then checks to see if the SCB
  697. * is to be removed. If it is it deallocates the SCB.
  698. * Finally, it calls the application callback with a close
  699. * indication.
  700. *
  701. * Returns Nothing.
  702. *
  703. ******************************************************************************/
  704. void avdt_scb_hdl_tc_close(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data) {
  705. uint8_t hdl = avdt_scb_to_hdl(p_scb);
  706. tAVDT_CTRL_CBACK* p_avdt_ctrl_cback = p_scb->stream_config.p_avdt_ctrl_cback;
  707. tAVDT_CTRL avdt_ctrl;
  708. uint8_t event;
  709. AvdtpCcb* p_ccb = p_scb->p_ccb;
  710. RawAddress remote_addr = p_ccb->peer_addr;
  711. uint8_t scb_index = p_scb->stream_config.scb_index;
  712. /* set up hdr */
  713. avdt_ctrl.hdr.err_code = p_scb->close_code;
  714. /* clear sep variables */
  715. avdt_scb_clr_vars(p_scb, p_data);
  716. p_scb->media_seq = 0;
  717. p_scb->cong = false;
  718. /* free pkt we're holding, if any */
  719. osi_free_and_reset((void**)&p_scb->p_pkt);
  720. alarm_cancel(p_scb->transport_channel_timer);
  721. if ((p_scb->role == AVDT_CLOSE_INT) || (p_scb->role == AVDT_OPEN_INT)) {
  722. /* tell ccb we're done with signaling channel */
  723. avdt_ccb_event(p_ccb, AVDT_CCB_UL_CLOSE_EVT, NULL);
  724. }
  725. event =
  726. (p_scb->role == AVDT_CLOSE_INT) ? AVDT_CLOSE_CFM_EVT : AVDT_CLOSE_IND_EVT;
  727. p_scb->role = AVDT_CLOSE_ACP;
  728. if (p_scb->remove) {
  729. avdt_scb_dealloc(p_scb, NULL);
  730. }
  731. /* call app callback */
  732. (*p_avdt_ctrl_cback)(hdl, remote_addr, event, &avdt_ctrl, scb_index);
  733. }
  734. /*******************************************************************************
  735. *
  736. * Function avdt_scb_snd_delay_rpt_req
  737. *
  738. * Description This function calls the application callback with a delay
  739. * report.
  740. *
  741. * Returns Nothing.
  742. *
  743. ******************************************************************************/
  744. void avdt_scb_snd_delay_rpt_req(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data) {
  745. avdt_msg_send_cmd(p_scb->p_ccb, p_scb, AVDT_SIG_DELAY_RPT,
  746. (tAVDT_MSG*)&p_data->apidelay);
  747. }
  748. /*******************************************************************************
  749. *
  750. * Function avdt_scb_hdl_delay_rpt_cmd
  751. *
  752. * Description This function calls the application callback with a delay
  753. * report.
  754. *
  755. * Returns Nothing.
  756. *
  757. ******************************************************************************/
  758. void avdt_scb_hdl_delay_rpt_cmd(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data) {
  759. (*p_scb->stream_config.p_avdt_ctrl_cback)(
  760. avdt_scb_to_hdl(p_scb),
  761. p_scb->p_ccb ? p_scb->p_ccb->peer_addr : RawAddress::kEmpty,
  762. AVDT_DELAY_REPORT_EVT, (tAVDT_CTRL*)&p_data->msg.hdr,
  763. p_scb->stream_config.scb_index);
  764. if (p_scb->p_ccb)
  765. avdt_msg_send_rsp(p_scb->p_ccb, AVDT_SIG_DELAY_RPT, &p_data->msg);
  766. else
  767. avdt_scb_rej_not_in_use(p_scb, p_data);
  768. }
  769. /*******************************************************************************
  770. *
  771. * Function avdt_scb_hdl_delay_rpt_rsp
  772. *
  773. * Description This function calls the application callback with a delay
  774. * report.
  775. *
  776. * Returns Nothing.
  777. *
  778. ******************************************************************************/
  779. void avdt_scb_hdl_delay_rpt_rsp(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data) {
  780. (*p_scb->stream_config.p_avdt_ctrl_cback)(
  781. avdt_scb_to_hdl(p_scb),
  782. p_scb->p_ccb ? p_scb->p_ccb->peer_addr : RawAddress::kEmpty,
  783. AVDT_DELAY_REPORT_CFM_EVT, (tAVDT_CTRL*)&p_data->msg.hdr,
  784. p_scb->stream_config.scb_index);
  785. }
  786. /*******************************************************************************
  787. *
  788. * Function avdt_scb_hdl_tc_close_sto
  789. *
  790. * Description This function is called when a channel is closed in OPEN
  791. * state. Check the channel type and process accordingly.
  792. *
  793. * Returns Nothing.
  794. *
  795. ******************************************************************************/
  796. void avdt_scb_hdl_tc_close_sto(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data) {
  797. tAVDT_CTRL avdt_ctrl;
  798. /* AVDT_CHAN_SIG does not visit this action */
  799. if (p_data && p_data->close.type != AVDT_CHAN_MEDIA) {
  800. /* it's reporting or recovery channel,
  801. * the channel close in open state means the peer does not support it */
  802. if (p_data->close.old_tc_state == AVDT_AD_ST_OPEN) {
  803. avdt_ctrl.hdr.err_code = 0;
  804. avdt_ctrl.hdr.err_param = 0;
  805. /* call app callback */
  806. (*p_scb->stream_config.p_avdt_ctrl_cback)(
  807. avdt_scb_to_hdl(p_scb),
  808. p_scb->p_ccb ? p_scb->p_ccb->peer_addr : RawAddress::kEmpty,
  809. AVDT_REPORT_DISCONN_EVT, &avdt_ctrl, p_scb->stream_config.scb_index);
  810. }
  811. } else {
  812. /* must be in OPEN state. need to go back to idle */
  813. avdt_scb_event(p_scb, AVDT_SCB_MSG_ABORT_RSP_EVT, NULL);
  814. avdt_scb_hdl_tc_close(p_scb, p_data);
  815. }
  816. }
  817. /*******************************************************************************
  818. *
  819. * Function avdt_scb_hdl_tc_open
  820. *
  821. * Description This function is called when the transport channel is
  822. * opened while in the opening state. It calls the
  823. * application callback with an open indication or open
  824. * confirm depending on who initiated the open procedure.
  825. *
  826. * Returns Nothing.
  827. *
  828. ******************************************************************************/
  829. void avdt_scb_hdl_tc_open(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data) {
  830. uint8_t event;
  831. uint8_t role;
  832. alarm_cancel(p_scb->transport_channel_timer);
  833. event =
  834. (p_scb->role == AVDT_OPEN_INT) ? AVDT_OPEN_CFM_EVT : AVDT_OPEN_IND_EVT;
  835. p_data->open.hdr.err_code = 0;
  836. AVDT_TRACE_DEBUG("%s: psc_mask: cfg: 0x%x, req:0x%x, cur: 0x%x", __func__,
  837. p_scb->stream_config.cfg.psc_mask, p_scb->req_cfg.psc_mask,
  838. p_scb->curr_cfg.psc_mask);
  839. if (p_scb->curr_cfg.psc_mask & AVDT_PSC_REPORT) {
  840. /* open the reporting channel, if both devices support it */
  841. role = (p_scb->role == AVDT_OPEN_INT) ? AVDT_INT : AVDT_ACP;
  842. avdt_ad_open_req(AVDT_CHAN_REPORT, p_scb->p_ccb, p_scb, role);
  843. }
  844. /* call app callback */
  845. (*p_scb->stream_config.p_avdt_ctrl_cback)(
  846. avdt_scb_to_hdl(p_scb),
  847. p_scb->p_ccb ? p_scb->p_ccb->peer_addr : RawAddress::kEmpty, event,
  848. (tAVDT_CTRL*)&p_data->open, p_scb->stream_config.scb_index);
  849. }
  850. /*******************************************************************************
  851. *
  852. * Function avdt_scb_hdl_tc_open_sto
  853. *
  854. * Description This function is called when the transport channel is
  855. * opened while in the opening state. It calls the
  856. * application callback with an open indication or open
  857. * confirm depending on who initiated the open procedure.
  858. *
  859. * Returns Nothing.
  860. *
  861. ******************************************************************************/
  862. void avdt_scb_hdl_tc_open_sto(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data) {
  863. tAVDT_CTRL avdt_ctrl;
  864. /* open reporting channel here, when it is implemented */
  865. /* call app callback */
  866. if (p_data->open.hdr.err_code == AVDT_CHAN_REPORT) {
  867. avdt_ctrl.hdr.err_code = 0;
  868. avdt_ctrl.hdr.err_param = 1;
  869. (*p_scb->stream_config.p_avdt_ctrl_cback)(
  870. avdt_scb_to_hdl(p_scb),
  871. p_scb->p_ccb ? p_scb->p_ccb->peer_addr : RawAddress::kEmpty,
  872. AVDT_REPORT_CONN_EVT, &avdt_ctrl, p_scb->stream_config.scb_index);
  873. }
  874. }
  875. /*******************************************************************************
  876. *
  877. * Function avdt_scb_hdl_write_req
  878. *
  879. * Description This function frees the media packet currently stored in
  880. * the SCB, if any. Then it builds a new media packet from
  881. * with the passed in buffer and stores it in the SCB.
  882. *
  883. * Returns Nothing.
  884. *
  885. ******************************************************************************/
  886. void avdt_scb_hdl_write_req(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data) {
  887. uint8_t* p;
  888. uint32_t ssrc;
  889. bool add_rtp_header = !(p_data->apiwrite.opt & AVDT_DATA_OPT_NO_RTP);
  890. /* free packet we're holding, if any; to be replaced with new */
  891. if (p_scb->p_pkt != NULL) {
  892. /* this shouldn't be happening */
  893. AVDT_TRACE_WARNING("Dropped media packet; congested");
  894. }
  895. osi_free_and_reset((void**)&p_scb->p_pkt);
  896. /* Recompute only if the RTP header wasn't disabled by the API */
  897. if (add_rtp_header) {
  898. bool is_content_protection = (p_scb->curr_cfg.num_protect > 0);
  899. add_rtp_header =
  900. A2DP_UsesRtpHeader(is_content_protection, p_scb->curr_cfg.codec_info);
  901. }
  902. /* Build a media packet, and add an RTP header if required. */
  903. if (add_rtp_header) {
  904. ssrc = avdt_scb_gen_ssrc(p_scb);
  905. p_data->apiwrite.p_buf->len += AVDT_MEDIA_HDR_SIZE;
  906. p_data->apiwrite.p_buf->offset -= AVDT_MEDIA_HDR_SIZE;
  907. p_scb->media_seq++;
  908. p = (uint8_t*)(p_data->apiwrite.p_buf + 1) + p_data->apiwrite.p_buf->offset;
  909. UINT8_TO_BE_STREAM(p, AVDT_MEDIA_OCTET1);
  910. UINT8_TO_BE_STREAM(p, p_data->apiwrite.m_pt);
  911. UINT16_TO_BE_STREAM(p, p_scb->media_seq);
  912. UINT32_TO_BE_STREAM(p, p_data->apiwrite.time_stamp);
  913. UINT32_TO_BE_STREAM(p, ssrc);
  914. }
  915. /* store it */
  916. p_scb->p_pkt = p_data->apiwrite.p_buf;
  917. }
  918. /*******************************************************************************
  919. *
  920. * Function avdt_scb_snd_abort_req
  921. *
  922. * Description This function sends an abort command message.
  923. *
  924. * Returns Nothing.
  925. *
  926. ******************************************************************************/
  927. void avdt_scb_snd_abort_req(AvdtpScb* p_scb,
  928. UNUSED_ATTR tAVDT_SCB_EVT* p_data) {
  929. tAVDT_EVT_HDR hdr;
  930. AVDT_TRACE_DEBUG("%s: p_scb->p_ccb=%p", __func__, p_scb->p_ccb);
  931. if (p_scb->p_ccb != NULL) {
  932. p_scb->role = AVDT_CLOSE_INT;
  933. hdr.seid = p_scb->peer_seid;
  934. tAVDT_MSG avdt_msg;
  935. avdt_msg.hdr = hdr;
  936. avdt_msg_send_cmd(p_scb->p_ccb, p_scb, AVDT_SIG_ABORT, &avdt_msg);
  937. }
  938. }
  939. /*******************************************************************************
  940. *
  941. * Function avdt_scb_snd_abort_rsp
  942. *
  943. * Description This function sends an abort response message.
  944. *
  945. * Returns Nothing.
  946. *
  947. ******************************************************************************/
  948. void avdt_scb_snd_abort_rsp(UNUSED_ATTR AvdtpScb* p_scb,
  949. tAVDT_SCB_EVT* p_data) {
  950. avdt_msg_send_rsp(avdt_ccb_by_idx(p_data->msg.hdr.ccb_idx), AVDT_SIG_ABORT,
  951. &p_data->msg);
  952. }
  953. /*******************************************************************************
  954. *
  955. * Function avdt_scb_snd_close_req
  956. *
  957. * Description This function sends a close command message.
  958. *
  959. * Returns Nothing.
  960. *
  961. ******************************************************************************/
  962. void avdt_scb_snd_close_req(AvdtpScb* p_scb,
  963. UNUSED_ATTR tAVDT_SCB_EVT* p_data) {
  964. tAVDT_EVT_HDR hdr;
  965. p_scb->role = AVDT_CLOSE_INT;
  966. hdr.seid = p_scb->peer_seid;
  967. tAVDT_MSG avdt_msg;
  968. avdt_msg.hdr = hdr;
  969. avdt_msg_send_cmd(p_scb->p_ccb, p_scb, AVDT_SIG_CLOSE, &avdt_msg);
  970. }
  971. /*******************************************************************************
  972. *
  973. * Function avdt_scb_snd_stream_close
  974. *
  975. * Description This function sends a close command message.
  976. *
  977. * Returns Nothing.
  978. *
  979. ******************************************************************************/
  980. void avdt_scb_snd_stream_close(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data) {
  981. osi_free_and_reset((void**)&p_scb->p_pkt);
  982. avdt_scb_snd_close_req(p_scb, p_data);
  983. }
  984. /*******************************************************************************
  985. *
  986. * Function avdt_scb_snd_close_rsp
  987. *
  988. * Description This function sends a close response message.
  989. *
  990. * Returns Nothing.
  991. *
  992. ******************************************************************************/
  993. void avdt_scb_snd_close_rsp(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data) {
  994. avdt_msg_send_rsp(p_scb->p_ccb, AVDT_SIG_CLOSE, &p_data->msg);
  995. }
  996. /*******************************************************************************
  997. *
  998. * Function avdt_scb_snd_getconfig_req
  999. *
  1000. * Description This function sends a get configuration command message.
  1001. *
  1002. * Returns Nothing.
  1003. *
  1004. ******************************************************************************/
  1005. void avdt_scb_snd_getconfig_req(AvdtpScb* p_scb,
  1006. UNUSED_ATTR tAVDT_SCB_EVT* p_data) {
  1007. tAVDT_EVT_HDR hdr;
  1008. hdr.seid = p_scb->peer_seid;
  1009. tAVDT_MSG avdt_msg;
  1010. avdt_msg.hdr = hdr;
  1011. avdt_msg_send_cmd(p_scb->p_ccb, p_scb, AVDT_SIG_GETCONFIG, &avdt_msg);
  1012. }
  1013. /*******************************************************************************
  1014. *
  1015. * Function avdt_scb_snd_getconfig_rsp
  1016. *
  1017. * Description This function sends a get configuration response message.
  1018. *
  1019. * Returns Nothing.
  1020. *
  1021. ******************************************************************************/
  1022. void avdt_scb_snd_getconfig_rsp(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data) {
  1023. avdt_msg_send_rsp(p_scb->p_ccb, AVDT_SIG_GETCONFIG, &p_data->msg);
  1024. }
  1025. /*******************************************************************************
  1026. *
  1027. * Function avdt_scb_snd_open_req
  1028. *
  1029. * Description This function sends an open command message.
  1030. *
  1031. * Returns Nothing.
  1032. *
  1033. ******************************************************************************/
  1034. void avdt_scb_snd_open_req(AvdtpScb* p_scb, UNUSED_ATTR tAVDT_SCB_EVT* p_data) {
  1035. tAVDT_EVT_HDR hdr;
  1036. hdr.seid = p_scb->peer_seid;
  1037. tAVDT_MSG avdt_msg;
  1038. avdt_msg.hdr = hdr;
  1039. avdt_msg_send_cmd(p_scb->p_ccb, p_scb, AVDT_SIG_OPEN, &avdt_msg);
  1040. }
  1041. /*******************************************************************************
  1042. *
  1043. * Function avdt_scb_snd_open_rsp
  1044. *
  1045. * Description This function sends an open response message. It also
  1046. * calls avdt_ad_open_req() to accept a transport channel
  1047. * connection.
  1048. *
  1049. * Returns Nothing.
  1050. *
  1051. ******************************************************************************/
  1052. void avdt_scb_snd_open_rsp(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data) {
  1053. /* notify adaption that we're waiting for transport channel open */
  1054. p_scb->role = AVDT_OPEN_ACP;
  1055. avdt_ad_open_req(AVDT_CHAN_MEDIA, p_scb->p_ccb, p_scb, AVDT_ACP);
  1056. /* send response */
  1057. avdt_msg_send_rsp(p_scb->p_ccb, AVDT_SIG_OPEN, &p_data->msg);
  1058. alarm_set_on_mloop(p_scb->transport_channel_timer,
  1059. AVDT_SCB_TC_CONN_TIMEOUT_MS,
  1060. avdt_scb_transport_channel_timer_timeout, p_scb);
  1061. }
  1062. /*******************************************************************************
  1063. *
  1064. * Function avdt_scb_snd_reconfig_req
  1065. *
  1066. * Description This function stores the configuration parameters in the
  1067. * SCB and sends a reconfiguration command message.
  1068. *
  1069. * Returns Nothing.
  1070. *
  1071. ******************************************************************************/
  1072. void avdt_scb_snd_reconfig_req(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data) {
  1073. AVDT_TRACE_DEBUG("%s: p_scb->peer_seid=%d p_data->msg.hdr.seid=%d", __func__,
  1074. p_scb->peer_seid, p_data->msg.hdr.seid);
  1075. AVDT_TRACE_DEBUG(
  1076. "%s: codec: %s", __func__,
  1077. A2DP_CodecInfoString(p_data->msg.config_cmd.p_cfg->codec_info).c_str());
  1078. p_scb->req_cfg = *p_data->msg.config_cmd.p_cfg;
  1079. p_data->msg.hdr.seid = p_scb->peer_seid;
  1080. avdt_msg_send_cmd(p_scb->p_ccb, p_scb, AVDT_SIG_RECONFIG, &p_data->msg);
  1081. }
  1082. /*******************************************************************************
  1083. *
  1084. * Function avdt_scb_snd_reconfig_rsp
  1085. *
  1086. * Description This function stores the configuration parameters in the
  1087. * SCB and sends a reconfiguration response message.
  1088. *
  1089. * Returns Nothing.
  1090. *
  1091. ******************************************************************************/
  1092. void avdt_scb_snd_reconfig_rsp(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data) {
  1093. if (p_data->msg.hdr.err_code == 0) {
  1094. /* store new configuration */
  1095. if (p_scb->req_cfg.num_codec > 0) {
  1096. p_scb->curr_cfg.num_codec = p_scb->req_cfg.num_codec;
  1097. memcpy(p_scb->curr_cfg.codec_info, p_scb->req_cfg.codec_info,
  1098. AVDT_CODEC_SIZE);
  1099. }
  1100. if (p_scb->req_cfg.num_protect > 0) {
  1101. p_scb->curr_cfg.num_protect = p_scb->req_cfg.num_protect;
  1102. memcpy(p_scb->curr_cfg.protect_info, p_scb->req_cfg.protect_info,
  1103. AVDT_PROTECT_SIZE);
  1104. }
  1105. /* send response */
  1106. avdt_msg_send_rsp(p_scb->p_ccb, AVDT_SIG_RECONFIG, &p_data->msg);
  1107. } else {
  1108. /* send reject */
  1109. avdt_msg_send_rej(p_scb->p_ccb, AVDT_SIG_RECONFIG, &p_data->msg);
  1110. }
  1111. }
  1112. /*******************************************************************************
  1113. *
  1114. * Function avdt_scb_snd_security_req
  1115. *
  1116. * Description This function sends a security command message.
  1117. *
  1118. * Returns Nothing.
  1119. *
  1120. ******************************************************************************/
  1121. void avdt_scb_snd_security_req(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data) {
  1122. p_data->msg.hdr.seid = p_scb->peer_seid;
  1123. avdt_msg_send_cmd(p_scb->p_ccb, p_scb, AVDT_SIG_SECURITY, &p_data->msg);
  1124. }
  1125. /*******************************************************************************
  1126. *
  1127. * Function avdt_scb_snd_security_rsp
  1128. *
  1129. * Description This function sends a security response message.
  1130. *
  1131. * Returns Nothing.
  1132. *
  1133. ******************************************************************************/
  1134. void avdt_scb_snd_security_rsp(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data) {
  1135. if (p_data->msg.hdr.err_code == 0) {
  1136. avdt_msg_send_rsp(p_scb->p_ccb, AVDT_SIG_SECURITY, &p_data->msg);
  1137. } else {
  1138. avdt_msg_send_rej(p_scb->p_ccb, AVDT_SIG_SECURITY, &p_data->msg);
  1139. }
  1140. }
  1141. /*******************************************************************************
  1142. *
  1143. * Function avdt_scb_snd_setconfig_rej
  1144. *
  1145. * Description This function marks the SCB as not in use and sends a
  1146. * set configuration reject message.
  1147. *
  1148. * Returns Nothing.
  1149. *
  1150. ******************************************************************************/
  1151. void avdt_scb_snd_setconfig_rej(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data) {
  1152. if (p_scb->p_ccb != NULL) {
  1153. avdt_msg_send_rej(p_scb->p_ccb, AVDT_SIG_SETCONFIG, &p_data->msg);
  1154. /* clear scb variables */
  1155. avdt_scb_clr_vars(p_scb, p_data);
  1156. }
  1157. }
  1158. /*******************************************************************************
  1159. *
  1160. * Function avdt_scb_snd_setconfig_req
  1161. *
  1162. * Description This function marks the SCB as in use and copies the
  1163. * configuration parameters to the SCB. Then the function
  1164. * sends a set configuration command message and initiates
  1165. * opening of the signaling channel.
  1166. *
  1167. * Returns Nothing.
  1168. *
  1169. ******************************************************************************/
  1170. void avdt_scb_snd_setconfig_req(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data) {
  1171. AvdtpSepConfig *p_req, *p_cfg;
  1172. AVDT_TRACE_DEBUG(
  1173. "%s: codec: %s", __func__,
  1174. A2DP_CodecInfoString(p_data->msg.config_cmd.p_cfg->codec_info).c_str());
  1175. /* copy API parameters to scb, set scb as in use */
  1176. AvdtpCcb* p_ccb = avdt_ccb_by_idx(p_data->msg.config_cmd.hdr.ccb_idx);
  1177. if (p_scb->p_ccb != p_ccb) {
  1178. AVDT_TRACE_ERROR(
  1179. "%s: mismatch in AVDTP SCB/CCB state: (p_scb->p_ccb=%p != p_ccb=%p): "
  1180. "p_scb=%p scb_handle=%d ccb_idx=%d",
  1181. __func__, p_scb->p_ccb, p_ccb, p_scb, p_scb->ScbHandle(),
  1182. p_data->msg.config_cmd.hdr.ccb_idx);
  1183. avdt_scb_rej_not_in_use(p_scb, p_data);
  1184. return;
  1185. }
  1186. p_scb->in_use = true;
  1187. p_scb->peer_seid = p_data->msg.config_cmd.hdr.seid;
  1188. p_req = p_data->msg.config_cmd.p_cfg;
  1189. p_cfg = &p_scb->stream_config.cfg;
  1190. p_scb->req_cfg = *p_data->msg.config_cmd.p_cfg;
  1191. avdt_msg_send_cmd(p_scb->p_ccb, p_scb, AVDT_SIG_SETCONFIG, &p_data->msg);
  1192. /* tell ccb to open channel */
  1193. avdt_ccb_event(p_scb->p_ccb, AVDT_CCB_UL_OPEN_EVT, NULL);
  1194. }
  1195. /*******************************************************************************
  1196. *
  1197. * Function avdt_scb_snd_setconfig_rsp
  1198. *
  1199. * Description This function copies the requested configuration into the
  1200. * current configuration and sends a set configuration
  1201. * response message.
  1202. *
  1203. * Returns Nothing.
  1204. *
  1205. ******************************************************************************/
  1206. void avdt_scb_snd_setconfig_rsp(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data) {
  1207. if (p_scb->p_ccb != NULL) {
  1208. p_scb->curr_cfg = p_scb->req_cfg;
  1209. avdt_msg_send_rsp(p_scb->p_ccb, AVDT_SIG_SETCONFIG, &p_data->msg);
  1210. }
  1211. }
  1212. /*******************************************************************************
  1213. *
  1214. * Function avdt_scb_snd_tc_close
  1215. *
  1216. * Description This function calls avdt_ad_close_req() to close the
  1217. * transport channel for this SCB.
  1218. *
  1219. * Returns Nothing.
  1220. *
  1221. ******************************************************************************/
  1222. void avdt_scb_snd_tc_close(AvdtpScb* p_scb, UNUSED_ATTR tAVDT_SCB_EVT* p_data) {
  1223. if (p_scb->curr_cfg.psc_mask & AVDT_PSC_REPORT)
  1224. avdt_ad_close_req(AVDT_CHAN_REPORT, p_scb->p_ccb, p_scb);
  1225. avdt_ad_close_req(AVDT_CHAN_MEDIA, p_scb->p_ccb, p_scb);
  1226. }
  1227. /*******************************************************************************
  1228. *
  1229. * Function avdt_scb_cb_err
  1230. *
  1231. * Description This function calls the application callback function
  1232. * indicating an error.
  1233. *
  1234. * Returns Nothing.
  1235. *
  1236. ******************************************************************************/
  1237. void avdt_scb_cb_err(AvdtpScb* p_scb, UNUSED_ATTR tAVDT_SCB_EVT* p_data) {
  1238. tAVDT_CTRL avdt_ctrl;
  1239. /* set error code and parameter */
  1240. avdt_ctrl.hdr.err_code = AVDT_ERR_BAD_STATE;
  1241. avdt_ctrl.hdr.err_param = 0;
  1242. /* call callback, using lookup table to get callback event */
  1243. (*p_scb->stream_config.p_avdt_ctrl_cback)(
  1244. avdt_scb_to_hdl(p_scb), RawAddress::kEmpty,
  1245. avdt_scb_cback_evt[p_scb->curr_evt], &avdt_ctrl,
  1246. p_scb->stream_config.scb_index);
  1247. }
  1248. /*******************************************************************************
  1249. *
  1250. * Function avdt_scb_cong_state
  1251. *
  1252. * Description This function sets the congestion state of the SCB media
  1253. * transport channel.
  1254. *
  1255. * Returns Nothing.
  1256. *
  1257. ******************************************************************************/
  1258. void avdt_scb_cong_state(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data) {
  1259. p_scb->cong = p_data->llcong;
  1260. }
  1261. /*******************************************************************************
  1262. *
  1263. * Function avdt_scb_rej_state
  1264. *
  1265. * Description This function sends a reject message to the peer indicating
  1266. * incorrect state for the received command message.
  1267. *
  1268. * Returns Nothing.
  1269. *
  1270. ******************************************************************************/
  1271. void avdt_scb_rej_state(UNUSED_ATTR AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data) {
  1272. p_data->msg.hdr.err_code = AVDT_ERR_BAD_STATE;
  1273. p_data->msg.hdr.err_param = 0;
  1274. avdt_msg_send_rej(avdt_ccb_by_idx(p_data->msg.hdr.ccb_idx),
  1275. p_data->msg.hdr.sig_id, &p_data->msg);
  1276. }
  1277. /*******************************************************************************
  1278. *
  1279. * Function avdt_scb_rej_in_use
  1280. *
  1281. * Description This function sends a reject message to the peer indicating
  1282. * the stream is in use.
  1283. *
  1284. * Returns Nothing.
  1285. *
  1286. ******************************************************************************/
  1287. void avdt_scb_rej_in_use(UNUSED_ATTR AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data) {
  1288. p_data->msg.hdr.err_code = AVDT_ERR_IN_USE;
  1289. p_data->msg.hdr.err_param = 0;
  1290. avdt_msg_send_rej(avdt_ccb_by_idx(p_data->msg.hdr.ccb_idx),
  1291. p_data->msg.hdr.sig_id, &p_data->msg);
  1292. }
  1293. /*******************************************************************************
  1294. *
  1295. * Function avdt_scb_rej_not_in_use
  1296. *
  1297. * Description This function sends a reject message to the peer indicating
  1298. * the stream is in use.
  1299. *
  1300. * Returns Nothing.
  1301. *
  1302. ******************************************************************************/
  1303. void avdt_scb_rej_not_in_use(UNUSED_ATTR AvdtpScb* p_scb,
  1304. tAVDT_SCB_EVT* p_data) {
  1305. p_data->msg.hdr.err_code = AVDT_ERR_NOT_IN_USE;
  1306. p_data->msg.hdr.err_param = 0;
  1307. avdt_msg_send_rej(avdt_ccb_by_idx(p_data->msg.hdr.ccb_idx),
  1308. p_data->msg.hdr.sig_id, &p_data->msg);
  1309. }
  1310. /*******************************************************************************
  1311. *
  1312. * Function avdt_scb_set_remove
  1313. *
  1314. * Description This function marks an SCB to be removed.
  1315. *
  1316. * Returns Nothing.
  1317. *
  1318. ******************************************************************************/
  1319. void avdt_scb_set_remove(AvdtpScb* p_scb, UNUSED_ATTR tAVDT_SCB_EVT* p_data) {
  1320. p_scb->remove = true;
  1321. }
  1322. /*******************************************************************************
  1323. *
  1324. * Function avdt_scb_free_pkt
  1325. *
  1326. * Description This function frees the media packet passed in.
  1327. *
  1328. * Returns Nothing.
  1329. *
  1330. ******************************************************************************/
  1331. void avdt_scb_free_pkt(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data) {
  1332. tAVDT_CTRL avdt_ctrl;
  1333. /* set error code and parameter */
  1334. avdt_ctrl.hdr.err_code = AVDT_ERR_BAD_STATE;
  1335. avdt_ctrl.hdr.err_param = 0;
  1336. osi_free_and_reset((void**)&p_data->apiwrite.p_buf);
  1337. AVDT_TRACE_WARNING("Dropped media packet");
  1338. /* we need to call callback to keep data flow going */
  1339. (*p_scb->stream_config.p_avdt_ctrl_cback)(
  1340. avdt_scb_to_hdl(p_scb), RawAddress::kEmpty, AVDT_WRITE_CFM_EVT,
  1341. &avdt_ctrl, p_scb->stream_config.scb_index);
  1342. }
  1343. /*******************************************************************************
  1344. *
  1345. * Function avdt_scb_clr_pkt
  1346. *
  1347. * Description This function frees the media packet stored in the SCB.
  1348. *
  1349. * Returns Nothing.
  1350. *
  1351. ******************************************************************************/
  1352. void avdt_scb_clr_pkt(AvdtpScb* p_scb, UNUSED_ATTR tAVDT_SCB_EVT* p_data) {
  1353. tAVDT_CTRL avdt_ctrl;
  1354. AvdtpCcb* p_ccb;
  1355. uint8_t tcid;
  1356. uint16_t lcid;
  1357. /* set error code and parameter */
  1358. avdt_ctrl.hdr.err_code = AVDT_ERR_BAD_STATE;
  1359. avdt_ctrl.hdr.err_param = 0;
  1360. /* flush the media data queued at L2CAP */
  1361. p_ccb = p_scb->p_ccb;
  1362. if (p_ccb != NULL) {
  1363. /* get tcid from type, scb */
  1364. tcid = avdt_ad_type_to_tcid(AVDT_CHAN_MEDIA, p_scb);
  1365. lcid = avdtp_cb.ad.rt_tbl[avdt_ccb_to_idx(p_ccb)][tcid].lcid;
  1366. L2CA_FlushChannel(lcid, L2CAP_FLUSH_CHANS_ALL);
  1367. }
  1368. if (p_scb->p_pkt != NULL) {
  1369. osi_free_and_reset((void**)&p_scb->p_pkt);
  1370. AVDT_TRACE_DEBUG("Dropped stored media packet");
  1371. /* we need to call callback to keep data flow going */
  1372. (*p_scb->stream_config.p_avdt_ctrl_cback)(
  1373. avdt_scb_to_hdl(p_scb), RawAddress::kEmpty, AVDT_WRITE_CFM_EVT,
  1374. &avdt_ctrl, p_scb->stream_config.scb_index);
  1375. }
  1376. }
  1377. /*******************************************************************************
  1378. *
  1379. * Function avdt_scb_chk_snd_pkt
  1380. *
  1381. * Description This function checks if the SCB is congested, and if not
  1382. * congested it sends a stored media packet, if any. After it
  1383. * sends the packet it calls the application callback function
  1384. * with a write confirm.
  1385. *
  1386. * Returns Nothing.
  1387. *
  1388. ******************************************************************************/
  1389. void avdt_scb_chk_snd_pkt(AvdtpScb* p_scb, UNUSED_ATTR tAVDT_SCB_EVT* p_data) {
  1390. tAVDT_CTRL avdt_ctrl;
  1391. BT_HDR* p_pkt;
  1392. avdt_ctrl.hdr.err_code = 0;
  1393. if (!p_scb->cong) {
  1394. if (p_scb->p_pkt != NULL) {
  1395. p_pkt = p_scb->p_pkt;
  1396. p_scb->p_pkt = NULL;
  1397. avdt_ad_write_req(AVDT_CHAN_MEDIA, p_scb->p_ccb, p_scb, p_pkt);
  1398. (*p_scb->stream_config.p_avdt_ctrl_cback)(
  1399. avdt_scb_to_hdl(p_scb), RawAddress::kEmpty, AVDT_WRITE_CFM_EVT,
  1400. &avdt_ctrl, p_scb->stream_config.scb_index);
  1401. }
  1402. }
  1403. }
  1404. /*******************************************************************************
  1405. *
  1406. * Function avdt_scb_transport_channel_timer
  1407. *
  1408. * Description This function is called to start a timer when the peer
  1409. * initiates closing of the stream. The timer verifies that
  1410. * the peer disconnects the transport channel.
  1411. *
  1412. * Returns Nothing.
  1413. *
  1414. ******************************************************************************/
  1415. void avdt_scb_transport_channel_timer(AvdtpScb* p_scb,
  1416. UNUSED_ATTR tAVDT_SCB_EVT* p_data) {
  1417. alarm_set_on_mloop(p_scb->transport_channel_timer,
  1418. AVDT_SCB_TC_DISC_TIMEOUT_MS,
  1419. avdt_scb_transport_channel_timer_timeout, p_scb);
  1420. }
  1421. /*******************************************************************************
  1422. *
  1423. * Function avdt_scb_clr_vars
  1424. *
  1425. * Description This function initializes certain SCB variables.
  1426. *
  1427. * Returns Nothing.
  1428. *
  1429. ******************************************************************************/
  1430. void avdt_scb_clr_vars(AvdtpScb* p_scb, UNUSED_ATTR tAVDT_SCB_EVT* p_data) {
  1431. p_scb->in_use = false;
  1432. p_scb->peer_seid = 0;
  1433. }