avdt_msg.c 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784
  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 functions for parsing and building AVDTP signaling
  21. * messages. It also contains functions called by the SCB or CCB state
  22. * machines for sending command, response, and reject messages. It also
  23. * contains a function that processes incoming messages and dispatches them
  24. * to the appropriate SCB or CCB.
  25. *
  26. ******************************************************************************/
  27. #include <string.h>
  28. #include "stack/bt_types.h"
  29. #include "common/bt_target.h"
  30. #include "common/bt_defs.h"
  31. #include "stack/avdt_api.h"
  32. #include "stack/avdtc_api.h"
  33. #include "avdt_int.h"
  34. #include "stack/btu.h"
  35. #include "osi/allocator.h"
  36. #if (defined(AVDT_INCLUDED) && AVDT_INCLUDED == TRUE)
  37. /*****************************************************************************
  38. ** constants
  39. *****************************************************************************/
  40. /* mask of all psc values */
  41. #define AVDT_MSG_PSC_MASK (AVDT_PSC_TRANS | AVDT_PSC_REPORT | AVDT_PSC_DELAY_RPT | \
  42. AVDT_PSC_RECOV | AVDT_PSC_HDRCMP | AVDT_PSC_MUX)
  43. #define AVDT_PSC_PROTECT (1<<4) /* Content Protection */
  44. #define AVDT_PSC_CODEC (1<<7) /* codec */
  45. /*****************************************************************************
  46. ** type definitions
  47. *****************************************************************************/
  48. /* type for message building functions */
  49. typedef void (*tAVDT_MSG_BLD)(UINT8 **p, tAVDT_MSG *p_msg);
  50. /* type for message parsing functions */
  51. typedef UINT8 (*tAVDT_MSG_PRS)(tAVDT_MSG *p_msg, UINT8 *p, UINT16 len);
  52. /*****************************************************************************
  53. ** local function declarations
  54. *****************************************************************************/
  55. static void avdt_msg_bld_none(UINT8 **p, tAVDT_MSG *p_msg);
  56. static void avdt_msg_bld_single(UINT8 **p, tAVDT_MSG *p_msg);
  57. static void avdt_msg_bld_setconfig_cmd(UINT8 **p, tAVDT_MSG *p_msg);
  58. static void avdt_msg_bld_reconfig_cmd(UINT8 **p, tAVDT_MSG *p_msg);
  59. static void avdt_msg_bld_multi(UINT8 **p, tAVDT_MSG *p_msg);
  60. static void avdt_msg_bld_security_cmd(UINT8 **p, tAVDT_MSG *p_msg);
  61. static void avdt_msg_bld_discover_rsp(UINT8 **p, tAVDT_MSG *p_msg);
  62. static void avdt_msg_bld_svccap(UINT8 **p, tAVDT_MSG *p_msg);
  63. static void avdt_msg_bld_security_rsp(UINT8 **p, tAVDT_MSG *p_msg);
  64. static void avdt_msg_bld_all_svccap(UINT8 **p, tAVDT_MSG *p_msg);
  65. static void avdt_msg_bld_delay_rpt(UINT8 **p, tAVDT_MSG *p_msg);
  66. static UINT8 avdt_msg_prs_none(tAVDT_MSG *p_msg, UINT8 *p, UINT16 len);
  67. static UINT8 avdt_msg_prs_single(tAVDT_MSG *p_msg, UINT8 *p, UINT16 len);
  68. static UINT8 avdt_msg_prs_setconfig_cmd(tAVDT_MSG *p_msg, UINT8 *p, UINT16 len);
  69. static UINT8 avdt_msg_prs_reconfig_cmd(tAVDT_MSG *p_msg, UINT8 *p, UINT16 len);
  70. static UINT8 avdt_msg_prs_multi(tAVDT_MSG *p_msg, UINT8 *p, UINT16 len);
  71. static UINT8 avdt_msg_prs_security_cmd(tAVDT_MSG *p_msg, UINT8 *p, UINT16 len);
  72. static UINT8 avdt_msg_prs_discover_rsp(tAVDT_MSG *p_msg, UINT8 *p, UINT16 len);
  73. static UINT8 avdt_msg_prs_svccap(tAVDT_MSG *p_msg, UINT8 *p, UINT16 len);
  74. static UINT8 avdt_msg_prs_all_svccap(tAVDT_MSG *p_msg, UINT8 *p, UINT16 len);
  75. static UINT8 avdt_msg_prs_security_rsp(tAVDT_MSG *p_msg, UINT8 *p, UINT16 len);
  76. static UINT8 avdt_msg_prs_delay_rpt (tAVDT_MSG *p_msg, UINT8 *p, UINT16 len);
  77. /*****************************************************************************
  78. ** constants
  79. *****************************************************************************/
  80. /* table of information element minimum lengths used for parsing */
  81. const UINT8 avdt_msg_ie_len_min[] = {
  82. 0, /* unused */
  83. AVDT_LEN_TRANS_MIN, /* media transport */
  84. AVDT_LEN_REPORT_MIN, /* reporting */
  85. AVDT_LEN_RECOV_MIN, /* recovery */
  86. AVDT_LEN_PROTECT_MIN, /* content protection */
  87. AVDT_LEN_HDRCMP_MIN, /* header compression */
  88. AVDT_LEN_MUX_MIN, /* multiplexing */
  89. AVDT_LEN_CODEC_MIN, /* codec */
  90. AVDT_LEN_DELAY_RPT_MIN /* delay report */
  91. };
  92. /* table of information element minimum lengths used for parsing */
  93. const UINT8 avdt_msg_ie_len_max[] = {
  94. 0, /* unused */
  95. AVDT_LEN_TRANS_MAX, /* media transport */
  96. AVDT_LEN_REPORT_MAX, /* reporting */
  97. AVDT_LEN_RECOV_MAX, /* recovery */
  98. AVDT_LEN_PROTECT_MAX, /* content protection */
  99. AVDT_LEN_HDRCMP_MAX, /* header compression */
  100. AVDT_LEN_MUX_MAX, /* multiplexing */
  101. AVDT_LEN_CODEC_MAX, /* codec */
  102. AVDT_LEN_DELAY_RPT_MAX /* delay report */
  103. };
  104. /* table of error codes used when decoding information elements */
  105. const UINT8 avdt_msg_ie_err[] = {
  106. 0, /* unused */
  107. AVDT_ERR_MEDIA_TRANS, /* media transport */
  108. AVDT_ERR_LENGTH, /* reporting */
  109. AVDT_ERR_RECOV_FMT, /* recovery */
  110. AVDT_ERR_CP_FMT, /* content protection */
  111. AVDT_ERR_ROHC_FMT, /* header compression */
  112. AVDT_ERR_MUX_FMT, /* multiplexing */
  113. AVDT_ERR_SERVICE, /* codec */
  114. AVDT_ERR_SERVICE /* delay report ?? */
  115. };
  116. /* table of packet type minimum lengths */
  117. static const UINT8 avdt_msg_pkt_type_len[] = {
  118. AVDT_LEN_TYPE_SINGLE,
  119. AVDT_LEN_TYPE_START,
  120. AVDT_LEN_TYPE_CONT,
  121. AVDT_LEN_TYPE_END
  122. };
  123. /* function table for building command messages */
  124. const tAVDT_MSG_BLD avdt_msg_bld_cmd[] = {
  125. avdt_msg_bld_none, /* discover */
  126. avdt_msg_bld_single, /* get capabilities */
  127. avdt_msg_bld_setconfig_cmd, /* set configuration */
  128. avdt_msg_bld_single, /* get configuration */
  129. avdt_msg_bld_reconfig_cmd, /* reconfigure */
  130. avdt_msg_bld_single, /* open */
  131. avdt_msg_bld_multi, /* start */
  132. avdt_msg_bld_single, /* close */
  133. avdt_msg_bld_multi, /* suspend */
  134. avdt_msg_bld_single, /* abort */
  135. avdt_msg_bld_security_cmd, /* security control */
  136. avdt_msg_bld_single, /* get all capabilities */
  137. avdt_msg_bld_delay_rpt /* delay report */
  138. };
  139. /* function table for building response messages */
  140. const tAVDT_MSG_BLD avdt_msg_bld_rsp[] = {
  141. avdt_msg_bld_discover_rsp, /* discover */
  142. avdt_msg_bld_svccap, /* get capabilities */
  143. avdt_msg_bld_none, /* set configuration */
  144. avdt_msg_bld_all_svccap, /* get configuration */
  145. avdt_msg_bld_none, /* reconfigure */
  146. avdt_msg_bld_none, /* open */
  147. avdt_msg_bld_none, /* start */
  148. avdt_msg_bld_none, /* close */
  149. avdt_msg_bld_none, /* suspend */
  150. avdt_msg_bld_none, /* abort */
  151. avdt_msg_bld_security_rsp, /* security control */
  152. avdt_msg_bld_all_svccap, /* get all capabilities */
  153. avdt_msg_bld_none /* delay report */
  154. };
  155. /* function table for parsing command messages */
  156. const tAVDT_MSG_PRS avdt_msg_prs_cmd[] = {
  157. avdt_msg_prs_none, /* discover */
  158. avdt_msg_prs_single, /* get capabilities */
  159. avdt_msg_prs_setconfig_cmd, /* set configuration */
  160. avdt_msg_prs_single, /* get configuration */
  161. avdt_msg_prs_reconfig_cmd, /* reconfigure */
  162. avdt_msg_prs_single, /* open */
  163. avdt_msg_prs_multi, /* start */
  164. avdt_msg_prs_single, /* close */
  165. avdt_msg_prs_multi, /* suspend */
  166. avdt_msg_prs_single, /* abort */
  167. avdt_msg_prs_security_cmd, /* security control */
  168. avdt_msg_prs_single, /* get all capabilities */
  169. avdt_msg_prs_delay_rpt /* delay report */
  170. };
  171. /* function table for parsing response messages */
  172. const tAVDT_MSG_PRS avdt_msg_prs_rsp[] = {
  173. avdt_msg_prs_discover_rsp, /* discover */
  174. avdt_msg_prs_svccap, /* get capabilities */
  175. avdt_msg_prs_none, /* set configuration */
  176. avdt_msg_prs_all_svccap, /* get configuration */
  177. avdt_msg_prs_none, /* reconfigure */
  178. avdt_msg_prs_none, /* open */
  179. avdt_msg_prs_none, /* start */
  180. avdt_msg_prs_none, /* close */
  181. avdt_msg_prs_none, /* suspend */
  182. avdt_msg_prs_none, /* abort */
  183. avdt_msg_prs_security_rsp, /* security control */
  184. avdt_msg_prs_all_svccap, /* get all capabilities */
  185. avdt_msg_prs_none /* delay report */
  186. };
  187. /* command message-to-event lookup table */
  188. const UINT8 avdt_msg_cmd_2_evt[] = {
  189. AVDT_CCB_MSG_DISCOVER_CMD_EVT + AVDT_CCB_MKR, /* discover */
  190. AVDT_CCB_MSG_GETCAP_CMD_EVT + AVDT_CCB_MKR, /* get capabilities */
  191. AVDT_SCB_MSG_SETCONFIG_CMD_EVT, /* set configuration */
  192. AVDT_SCB_MSG_GETCONFIG_CMD_EVT, /* get configuration */
  193. AVDT_SCB_MSG_RECONFIG_CMD_EVT, /* reconfigure */
  194. AVDT_SCB_MSG_OPEN_CMD_EVT, /* open */
  195. AVDT_CCB_MSG_START_CMD_EVT + AVDT_CCB_MKR, /* start */
  196. AVDT_SCB_MSG_CLOSE_CMD_EVT, /* close */
  197. AVDT_CCB_MSG_SUSPEND_CMD_EVT + AVDT_CCB_MKR, /* suspend */
  198. AVDT_SCB_MSG_ABORT_CMD_EVT, /* abort */
  199. AVDT_SCB_MSG_SECURITY_CMD_EVT, /* security control */
  200. AVDT_CCB_MSG_GETCAP_CMD_EVT + AVDT_CCB_MKR, /* get all capabilities */
  201. AVDT_SCB_MSG_DELAY_RPT_CMD_EVT /* delay report */
  202. };
  203. /* response message-to-event lookup table */
  204. const UINT8 avdt_msg_rsp_2_evt[] = {
  205. AVDT_CCB_MSG_DISCOVER_RSP_EVT + AVDT_CCB_MKR, /* discover */
  206. AVDT_CCB_MSG_GETCAP_RSP_EVT + AVDT_CCB_MKR, /* get capabilities */
  207. AVDT_SCB_MSG_SETCONFIG_RSP_EVT, /* set configuration */
  208. AVDT_SCB_MSG_GETCONFIG_RSP_EVT, /* get configuration */
  209. AVDT_SCB_MSG_RECONFIG_RSP_EVT, /* reconfigure */
  210. AVDT_SCB_MSG_OPEN_RSP_EVT, /* open */
  211. AVDT_CCB_MSG_START_RSP_EVT + AVDT_CCB_MKR, /* start */
  212. AVDT_SCB_MSG_CLOSE_RSP_EVT, /* close */
  213. AVDT_CCB_MSG_SUSPEND_RSP_EVT + AVDT_CCB_MKR, /* suspend */
  214. AVDT_SCB_MSG_ABORT_RSP_EVT, /* abort */
  215. AVDT_SCB_MSG_SECURITY_RSP_EVT, /* security control */
  216. AVDT_CCB_MSG_GETCAP_RSP_EVT + AVDT_CCB_MKR, /* get all capabilities */
  217. AVDT_SCB_MSG_DELAY_RPT_RSP_EVT /* delay report */
  218. };
  219. /* reject message-to-event lookup table */
  220. const UINT8 avdt_msg_rej_2_evt[] = {
  221. AVDT_CCB_MSG_DISCOVER_RSP_EVT + AVDT_CCB_MKR, /* discover */
  222. AVDT_CCB_MSG_GETCAP_RSP_EVT + AVDT_CCB_MKR, /* get capabilities */
  223. AVDT_SCB_MSG_SETCONFIG_REJ_EVT, /* set configuration */
  224. AVDT_SCB_MSG_GETCONFIG_RSP_EVT, /* get configuration */
  225. AVDT_SCB_MSG_RECONFIG_RSP_EVT, /* reconfigure */
  226. AVDT_SCB_MSG_OPEN_REJ_EVT, /* open */
  227. AVDT_CCB_MSG_START_RSP_EVT + AVDT_CCB_MKR, /* start */
  228. AVDT_SCB_MSG_CLOSE_RSP_EVT, /* close */
  229. AVDT_CCB_MSG_SUSPEND_RSP_EVT + AVDT_CCB_MKR, /* suspend */
  230. AVDT_SCB_MSG_ABORT_RSP_EVT, /* abort */
  231. AVDT_SCB_MSG_SECURITY_RSP_EVT, /* security control */
  232. AVDT_CCB_MSG_GETCAP_RSP_EVT + AVDT_CCB_MKR, /* get all capabilities */
  233. 0 /* delay report */
  234. };
  235. /*******************************************************************************
  236. **
  237. ** Function avdt_msg_bld_cfg
  238. **
  239. ** Description This function builds the configuration parameters contained
  240. ** in a command or response message.
  241. **
  242. **
  243. ** Returns void.
  244. **
  245. *******************************************************************************/
  246. static void avdt_msg_bld_cfg(UINT8 **p, tAVDT_CFG *p_cfg)
  247. {
  248. UINT8 len;
  249. /* for now, just build media transport, codec, and content protection, and multiplexing */
  250. /* media transport */
  251. if (p_cfg->psc_mask & AVDT_PSC_TRANS) {
  252. *(*p)++ = AVDT_CAT_TRANS;
  253. *(*p)++ = 0; /* length */
  254. }
  255. #if AVDT_REPORTING == TRUE
  256. /* reporting transport */
  257. if (p_cfg->psc_mask & AVDT_PSC_REPORT) {
  258. *(*p)++ = AVDT_CAT_REPORT;
  259. *(*p)++ = 0; /* length */
  260. }
  261. #endif
  262. /* codec */
  263. if (p_cfg->num_codec != 0) {
  264. *(*p)++ = AVDT_CAT_CODEC;
  265. len = p_cfg->codec_info[0] + 1;
  266. if ( len > AVDT_CODEC_SIZE ) {
  267. len = AVDT_CODEC_SIZE;
  268. }
  269. memcpy(*p, p_cfg->codec_info, len);
  270. *p += len;
  271. }
  272. /* content protection */
  273. if (p_cfg->num_protect != 0) {
  274. *(*p)++ = AVDT_CAT_PROTECT;
  275. len = p_cfg->protect_info[0] + 1;
  276. if ( len > AVDT_PROTECT_SIZE ) {
  277. len = AVDT_PROTECT_SIZE;
  278. }
  279. memcpy(*p, p_cfg->protect_info, len);
  280. *p += len;
  281. }
  282. #if AVDT_MULTIPLEXING == TRUE
  283. /* multiplexing */
  284. if (p_cfg->psc_mask & AVDT_PSC_MUX) {
  285. *(*p)++ = AVDT_CAT_MUX;
  286. /* length */
  287. if (p_cfg->psc_mask & AVDT_PSC_RECOV) {
  288. *(*p)++ = 7; /* frag (1) + media + report + recovery */
  289. } else if (p_cfg->psc_mask & AVDT_PSC_REPORT) {
  290. *(*p)++ = 5; /* frag (1) + media + report */
  291. } else {
  292. *(*p)++ = 3; /* frag (1) + media */
  293. }
  294. /* allow fragmentation */
  295. if (p_cfg->mux_mask & AVDT_MUX_FRAG) {
  296. *(*p)++ = 0x80;
  297. } else {
  298. *(*p)++ = 0;
  299. }
  300. /* media transport session */
  301. *(*p)++ = p_cfg->mux_tsid_media << 3; /* TSID */
  302. *(*p)++ = p_cfg->mux_tcid_media << 3; /* TCID */
  303. if (p_cfg->psc_mask & AVDT_PSC_RECOV) {
  304. /* reporting transport session */
  305. *(*p)++ = p_cfg->mux_tsid_report << 3; /* TSID */
  306. *(*p)++ = p_cfg->mux_tcid_report << 3; /* TCID */
  307. /* recovery transport session */
  308. *(*p)++ = p_cfg->mux_tsid_recov << 3; /* TSID */
  309. *(*p)++ = p_cfg->mux_tcid_recov << 3; /* TCID */
  310. } else if (p_cfg->psc_mask & AVDT_PSC_REPORT) {
  311. /* reporting transport session */
  312. *(*p)++ = p_cfg->mux_tsid_report << 3; /* TSID */
  313. *(*p)++ = p_cfg->mux_tcid_report << 3; /* TCID */
  314. }
  315. }
  316. #endif
  317. /* delay report */
  318. if (p_cfg->psc_mask & AVDT_PSC_DELAY_RPT) {
  319. *(*p)++ = AVDT_CAT_DELAY_RPT;
  320. *(*p)++ = 0; /* length */
  321. }
  322. }
  323. /*******************************************************************************
  324. **
  325. ** Function avdt_msg_bld_none
  326. **
  327. ** Description This message building function builds an empty message.
  328. **
  329. **
  330. ** Returns void.
  331. **
  332. *******************************************************************************/
  333. static void avdt_msg_bld_none(UINT8 **p, tAVDT_MSG *p_msg)
  334. {
  335. UNUSED(p);
  336. UNUSED(p_msg);
  337. return;
  338. }
  339. /*******************************************************************************
  340. **
  341. ** Function avdt_msg_bld_single
  342. **
  343. ** Description This message building function builds a message containing
  344. ** a single SEID.
  345. **
  346. **
  347. ** Returns void.
  348. **
  349. *******************************************************************************/
  350. static void avdt_msg_bld_single(UINT8 **p, tAVDT_MSG *p_msg)
  351. {
  352. AVDT_MSG_BLD_SEID(*p, p_msg->single.seid);
  353. }
  354. /*******************************************************************************
  355. **
  356. ** Function avdt_msg_bld_setconfig_cmd
  357. **
  358. ** Description This message building function builds a set configuration
  359. ** command message.
  360. **
  361. **
  362. ** Returns void.
  363. **
  364. *******************************************************************************/
  365. static void avdt_msg_bld_setconfig_cmd(UINT8 **p, tAVDT_MSG *p_msg)
  366. {
  367. AVDT_MSG_BLD_SEID(*p, p_msg->config_cmd.hdr.seid);
  368. AVDT_MSG_BLD_SEID(*p, p_msg->config_cmd.int_seid);
  369. avdt_msg_bld_cfg(p, p_msg->config_cmd.p_cfg);
  370. }
  371. /*******************************************************************************
  372. **
  373. ** Function avdt_msg_bld_reconfig_cmd
  374. **
  375. ** Description This message building function builds a reconfiguration
  376. ** command message.
  377. **
  378. **
  379. ** Returns void.
  380. **
  381. *******************************************************************************/
  382. static void avdt_msg_bld_reconfig_cmd(UINT8 **p, tAVDT_MSG *p_msg)
  383. {
  384. AVDT_MSG_BLD_SEID(*p, p_msg->reconfig_cmd.hdr.seid);
  385. /* force psc mask zero to build only codec and security */
  386. p_msg->reconfig_cmd.p_cfg->psc_mask = 0;
  387. avdt_msg_bld_cfg(p, p_msg->reconfig_cmd.p_cfg);
  388. }
  389. /*******************************************************************************
  390. **
  391. ** Function avdt_msg_bld_multi
  392. **
  393. ** Description This message building function builds a message containing
  394. ** multiple SEID's.
  395. **
  396. **
  397. ** Returns void.
  398. **
  399. *******************************************************************************/
  400. static void avdt_msg_bld_multi(UINT8 **p, tAVDT_MSG *p_msg)
  401. {
  402. int i;
  403. for (i = 0; i < p_msg->multi.num_seps; i++) {
  404. AVDT_MSG_BLD_SEID(*p, p_msg->multi.seid_list[i]);
  405. }
  406. }
  407. /*******************************************************************************
  408. **
  409. ** Function avdt_msg_bld_security_cmd
  410. **
  411. ** Description This message building function builds a security
  412. ** command message.
  413. **
  414. ** Returns void.
  415. **
  416. *******************************************************************************/
  417. static void avdt_msg_bld_security_cmd(UINT8 **p, tAVDT_MSG *p_msg)
  418. {
  419. AVDT_MSG_BLD_SEID(*p, p_msg->security_cmd.hdr.seid);
  420. memcpy(*p, p_msg->security_cmd.p_data, p_msg->security_cmd.len);
  421. *p += p_msg->security_cmd.len;
  422. }
  423. /*******************************************************************************
  424. **
  425. ** Function avdt_msg_bld_delay_rpt
  426. **
  427. ** Description This message building function builds a delay report
  428. ** command message.
  429. **
  430. ** Returns void.
  431. **
  432. *******************************************************************************/
  433. static void avdt_msg_bld_delay_rpt(UINT8 **p, tAVDT_MSG *p_msg)
  434. {
  435. AVDT_MSG_BLD_SEID(*p, p_msg->delay_rpt_cmd.hdr.seid);
  436. UINT16_TO_BE_STREAM(*p, p_msg->delay_rpt_cmd.delay);
  437. }
  438. /*******************************************************************************
  439. **
  440. ** Function avdt_msg_bld_discover_rsp
  441. **
  442. ** Description This message building function builds a discover
  443. ** response message.
  444. **
  445. **
  446. ** Returns void.
  447. **
  448. *******************************************************************************/
  449. static void avdt_msg_bld_discover_rsp(UINT8 **p, tAVDT_MSG *p_msg)
  450. {
  451. int i;
  452. for (i = 0; i < p_msg->discover_rsp.num_seps; i++) {
  453. /* build discover rsp info */
  454. AVDT_MSG_BLD_DISC(*p, p_msg->discover_rsp.p_sep_info[i].seid,
  455. p_msg->discover_rsp.p_sep_info[i].in_use,
  456. p_msg->discover_rsp.p_sep_info[i].media_type,
  457. p_msg->discover_rsp.p_sep_info[i].tsep);
  458. }
  459. }
  460. /*******************************************************************************
  461. **
  462. ** Function avdt_msg_bld_svccap
  463. **
  464. ** Description This message building function builds a message containing
  465. ** service capabilities parameters.
  466. **
  467. **
  468. ** Returns void.
  469. **
  470. *******************************************************************************/
  471. static void avdt_msg_bld_svccap(UINT8 **p, tAVDT_MSG *p_msg)
  472. {
  473. tAVDT_CFG cfg;
  474. /* make sure the delay report category is not reported */
  475. memcpy (&cfg, p_msg->svccap.p_cfg, sizeof(tAVDT_CFG));
  476. cfg.psc_mask &= ~AVDT_PSC_DELAY_RPT;
  477. avdt_msg_bld_cfg(p, &cfg);
  478. }
  479. /*******************************************************************************
  480. **
  481. ** Function avdt_msg_bld_all_svccap
  482. **
  483. ** Description This message building function builds a message containing
  484. ** service capabilities parameters.
  485. **
  486. **
  487. ** Returns void.
  488. **
  489. *******************************************************************************/
  490. static void avdt_msg_bld_all_svccap(UINT8 **p, tAVDT_MSG *p_msg)
  491. {
  492. avdt_msg_bld_cfg(p, p_msg->svccap.p_cfg);
  493. }
  494. /*******************************************************************************
  495. **
  496. ** Function avdt_msg_bld_security_rsp
  497. **
  498. ** Description This message building function builds a security
  499. ** response message.
  500. **
  501. **
  502. ** Returns void.
  503. **
  504. *******************************************************************************/
  505. static void avdt_msg_bld_security_rsp(UINT8 **p, tAVDT_MSG *p_msg)
  506. {
  507. memcpy(*p, p_msg->security_rsp.p_data, p_msg->security_rsp.len);
  508. *p += p_msg->security_rsp.len;
  509. }
  510. /*******************************************************************************
  511. **
  512. ** Function avdt_msg_prs_cfg
  513. **
  514. ** Description This message parsing function parses the configuration
  515. ** parameters field of a message.
  516. **
  517. **
  518. ** Returns Error code or zero if no error, and element that failed
  519. ** in p_elem.
  520. **
  521. *******************************************************************************/
  522. static UINT8 avdt_msg_prs_cfg(tAVDT_CFG *p_cfg, UINT8 *p, UINT16 len, UINT8 *p_elem, UINT8 sig_id)
  523. {
  524. UINT8 *p_end;
  525. UINT8 elem = 0;
  526. UINT8 elem_len;
  527. UINT8 tmp;
  528. UINT8 err = 0;
  529. UINT8 protect_offset = 0;
  530. if (!p_cfg) {
  531. AVDT_TRACE_ERROR ("not expecting this cfg");
  532. return AVDT_ERR_BAD_STATE;
  533. }
  534. p_cfg->psc_mask = 0;
  535. p_cfg->num_codec = 0;
  536. p_cfg->num_protect = 0;
  537. #if AVDT_MULTIPLEXING == TRUE
  538. p_cfg->mux_mask = 0;
  539. #endif
  540. /* while there is still data to parse */
  541. p_end = p + len;
  542. while ((p < p_end) && (err == 0)) {
  543. /* verify overall length */
  544. if ((p_end - p) < AVDT_LEN_CFG_MIN) {
  545. err = AVDT_ERR_PAYLOAD;
  546. break;
  547. }
  548. /* get and verify info elem id, length */
  549. elem = *p++;
  550. elem_len = *p++;
  551. if ((elem == 0) || (elem > AVDT_CAT_MAX_CUR)) {
  552. /* this may not be really bad.
  553. * It may be a service category that is too new for us.
  554. * allow these to be parsed without reporting an error.
  555. * If this is a "capability" (as in GetCapRsp & GetConfigRsp), this is filtered out.
  556. * If this is a Configuration (as in SetConfigCmd & ReconfigCmd),
  557. * this will be marked as an error in the caller of this function */
  558. if ((sig_id == AVDT_SIG_SETCONFIG) || (sig_id == AVDT_SIG_RECONFIG)) {
  559. /* Cannot accept unknown category. */
  560. err = AVDT_ERR_CATEGORY;
  561. break;
  562. } else { /* GETCAP or GET_ALLCAP */
  563. /* Skip unknown categories. */
  564. p += elem_len;
  565. AVDT_TRACE_DEBUG("skipping unknown service category=%d len: %d\n", elem, elem_len);
  566. continue;
  567. }
  568. }
  569. if ((elem_len > avdt_msg_ie_len_max[elem]) ||
  570. (elem_len < avdt_msg_ie_len_min[elem])) {
  571. err = avdt_msg_ie_err[elem];
  572. break;
  573. }
  574. /* add element to psc mask, but mask out codec or protect */
  575. p_cfg->psc_mask |= (1 << elem);
  576. AVDT_TRACE_DEBUG("elem=%d elem_len: %d psc_mask=0x%x\n", elem, elem_len, p_cfg->psc_mask);
  577. /* parse individual information elements with additional parameters */
  578. switch (elem) {
  579. case AVDT_CAT_RECOV:
  580. p_cfg->recov_type = *p++;
  581. p_cfg->recov_mrws = *p++;
  582. p_cfg->recov_mnmp = *p++;
  583. if (p_cfg->recov_type != AVDT_RECOV_RFC2733) {
  584. err = AVDT_ERR_RECOV_TYPE;
  585. } else if ((p_cfg->recov_mrws < AVDT_RECOV_MRWS_MIN) ||
  586. (p_cfg->recov_mrws > AVDT_RECOV_MRWS_MAX) ||
  587. (p_cfg->recov_mnmp < AVDT_RECOV_MNMP_MIN) ||
  588. (p_cfg->recov_mnmp > AVDT_RECOV_MNMP_MAX)) {
  589. err = AVDT_ERR_RECOV_FMT;
  590. }
  591. break;
  592. case AVDT_CAT_PROTECT:
  593. p_cfg->psc_mask &= ~AVDT_PSC_PROTECT;
  594. if ((elem_len + protect_offset) < AVDT_PROTECT_SIZE) {
  595. p_cfg->num_protect++;
  596. p_cfg->protect_info[protect_offset] = elem_len;
  597. protect_offset++;
  598. memcpy(&p_cfg->protect_info[protect_offset], p, elem_len);
  599. protect_offset += elem_len;
  600. }
  601. p += elem_len;
  602. break;
  603. case AVDT_CAT_HDRCMP:
  604. p_cfg->hdrcmp_mask = *p++;
  605. break;
  606. #if AVDT_MULTIPLEXING == TRUE
  607. case AVDT_CAT_MUX:
  608. /* verify length */
  609. AVDT_TRACE_WARNING("psc_mask=0x%x elem_len=%d\n", p_cfg->psc_mask, elem_len);
  610. if ( ((0 == (p_cfg->psc_mask & (AVDT_PSC_RECOV | AVDT_PSC_REPORT))) && (elem_len != 3))
  611. || (((p_cfg->psc_mask & AVDT_PSC_REPORT) && !(p_cfg->psc_mask & AVDT_PSC_RECOV))
  612. && (elem_len != 5))
  613. || ((!(p_cfg->psc_mask & AVDT_PSC_REPORT) && (p_cfg->psc_mask & AVDT_PSC_RECOV))
  614. && (elem_len != 5))
  615. || (((p_cfg->psc_mask & AVDT_PSC_REPORT) && (p_cfg->psc_mask & AVDT_PSC_RECOV))
  616. && (elem_len != 7)) ) {
  617. err = AVDT_ERR_MUX_FMT;
  618. break;
  619. }
  620. /* parse fragmentation */
  621. p_cfg->mux_mask = *p++ & (UINT8)AVDT_MUX_FRAG;
  622. /* parse TSIDs and TCIDs */
  623. if (--elem_len) {
  624. p_cfg->mux_tsid_media = (*p++) >> 3;
  625. } else {
  626. break;
  627. }
  628. if (--elem_len) {
  629. p_cfg->mux_tcid_media = (*p++) >> 3;
  630. } else {
  631. break;
  632. }
  633. if (--elem_len) {
  634. p_cfg->mux_tsid_report = (*p++) >> 3;
  635. } else {
  636. break;
  637. }
  638. if (--elem_len) {
  639. p_cfg->mux_tcid_report = (*p++) >> 3;
  640. } else {
  641. break;
  642. }
  643. if (--elem_len) {
  644. p_cfg->mux_tsid_recov = (*p++) >> 3;
  645. } else {
  646. break;
  647. }
  648. if (--elem_len) {
  649. p_cfg->mux_tcid_recov = (*p++) >> 3;
  650. } else {
  651. break;
  652. }
  653. break;
  654. #endif
  655. case AVDT_CAT_CODEC:
  656. p_cfg->psc_mask &= ~AVDT_PSC_CODEC;
  657. tmp = elem_len;
  658. if (elem_len >= AVDT_CODEC_SIZE) {
  659. tmp = AVDT_CODEC_SIZE - 1;
  660. }
  661. p_cfg->num_codec++;
  662. p_cfg->codec_info[0] = elem_len;
  663. memcpy(&p_cfg->codec_info[1], p, tmp);
  664. p += elem_len;
  665. break;
  666. case AVDT_CAT_DELAY_RPT:
  667. break;
  668. default:
  669. p += elem_len;
  670. break;
  671. } /* switch */
  672. } /* while ! err, !end*/
  673. *p_elem = elem;
  674. AVDT_TRACE_DEBUG("err=0x%x, elem:0x%x psc_mask=0x%x\n", err, elem, p_cfg->psc_mask);
  675. return err;
  676. }
  677. /*******************************************************************************
  678. **
  679. ** Function avdt_msg_prs_none
  680. **
  681. ** Description This message parsing function parses a message with no parameters.
  682. **
  683. **
  684. ** Returns Error code or zero if no error.
  685. **
  686. *******************************************************************************/
  687. static UINT8 avdt_msg_prs_none(tAVDT_MSG *p_msg, UINT8 *p, UINT16 len)
  688. {
  689. UNUSED(p_msg);
  690. UNUSED(p);
  691. UNUSED(len);
  692. return 0;
  693. }
  694. /*******************************************************************************
  695. **
  696. ** Function avdt_msg_prs_single
  697. **
  698. ** Description This message parsing function parses a message with a
  699. ** single SEID.
  700. **
  701. **
  702. ** Returns Error code or zero if no error.
  703. **
  704. *******************************************************************************/
  705. static UINT8 avdt_msg_prs_single(tAVDT_MSG *p_msg, UINT8 *p, UINT16 len)
  706. {
  707. UINT8 err = 0;
  708. /* verify len */
  709. if (len != AVDT_LEN_SINGLE) {
  710. err = AVDT_ERR_LENGTH;
  711. } else {
  712. AVDT_MSG_PRS_SEID(p, p_msg->single.seid);
  713. if (avdt_scb_by_hdl(p_msg->single.seid) == NULL) {
  714. err = AVDT_ERR_SEID;
  715. }
  716. }
  717. return err;
  718. }
  719. /*******************************************************************************
  720. **
  721. ** Function avdt_msg_prs_setconfig_cmd
  722. **
  723. ** Description This message parsing function parses a set configuration
  724. ** command message.
  725. **
  726. **
  727. ** Returns Error code or zero if no error.
  728. **
  729. *******************************************************************************/
  730. static UINT8 avdt_msg_prs_setconfig_cmd(tAVDT_MSG *p_msg, UINT8 *p, UINT16 len)
  731. {
  732. UINT8 err = 0;
  733. p_msg->hdr.err_param = 0;
  734. /* verify len */
  735. if (len < AVDT_LEN_SETCONFIG_MIN) {
  736. err = AVDT_ERR_LENGTH;
  737. } else {
  738. /* get seids */
  739. AVDT_MSG_PRS_SEID(p, p_msg->config_cmd.hdr.seid);
  740. if (avdt_scb_by_hdl(p_msg->config_cmd.hdr.seid) == NULL) {
  741. err = AVDT_ERR_SEID;
  742. }
  743. AVDT_MSG_PRS_SEID(p, p_msg->config_cmd.int_seid);
  744. if ((p_msg->config_cmd.int_seid < AVDT_SEID_MIN) ||
  745. (p_msg->config_cmd.int_seid > AVDT_SEID_MAX)) {
  746. err = AVDT_ERR_SEID;
  747. }
  748. }
  749. if (!err) {
  750. /* parse configuration parameters */
  751. len -= 2;
  752. err = avdt_msg_prs_cfg(p_msg->config_cmd.p_cfg, p, len, &p_msg->hdr.err_param, AVDT_SIG_SETCONFIG);
  753. if (!err) {
  754. /* verify protocol service capabilities are supported */
  755. if (((p_msg->config_cmd.p_cfg->psc_mask & (~AVDT_PSC)) != 0) ||
  756. (p_msg->config_cmd.p_cfg->num_codec == 0)) {
  757. err = AVDT_ERR_INVALID_CAP;
  758. }
  759. }
  760. }
  761. return err;
  762. }
  763. /*******************************************************************************
  764. **
  765. ** Function avdt_msg_prs_reconfig_cmd
  766. **
  767. ** Description This message parsing function parses a reconfiguration
  768. ** command message.
  769. **
  770. **
  771. ** Returns Error code or zero if no error.
  772. **
  773. *******************************************************************************/
  774. static UINT8 avdt_msg_prs_reconfig_cmd(tAVDT_MSG *p_msg, UINT8 *p, UINT16 len)
  775. {
  776. UINT8 err = 0;
  777. p_msg->hdr.err_param = 0;
  778. /* verify len */
  779. if (len < AVDT_LEN_RECONFIG_MIN) {
  780. err = AVDT_ERR_LENGTH;
  781. } else {
  782. /* get seid */
  783. AVDT_MSG_PRS_SEID(p, p_msg->reconfig_cmd.hdr.seid);
  784. if (avdt_scb_by_hdl(p_msg->reconfig_cmd.hdr.seid) == NULL) {
  785. err = AVDT_ERR_SEID;
  786. } else {
  787. /* parse config parameters */
  788. len--;
  789. err = avdt_msg_prs_cfg(p_msg->config_cmd.p_cfg, p, len, &p_msg->hdr.err_param, AVDT_SIG_RECONFIG);
  790. /* verify no protocol service capabilities in parameters */
  791. if (!err) {
  792. AVDT_TRACE_DEBUG("avdt_msg_prs_reconfig_cmd psc_mask=0x%x/0x%x\n", p_msg->config_cmd.p_cfg->psc_mask, AVDT_MSG_PSC_MASK);
  793. if ((p_msg->config_cmd.p_cfg->psc_mask != 0) ||
  794. (p_msg->config_cmd.p_cfg->num_codec == 0 && p_msg->config_cmd.p_cfg->num_protect == 0)) {
  795. err = AVDT_ERR_INVALID_CAP;
  796. }
  797. }
  798. }
  799. }
  800. return err;
  801. }
  802. /*******************************************************************************
  803. **
  804. ** Function avdt_msg_prs_multi
  805. **
  806. ** Description This message parsing function parses a message containing
  807. ** multiple SEID's.
  808. **
  809. **
  810. ** Returns Error code or zero if no error.
  811. **
  812. *******************************************************************************/
  813. static UINT8 avdt_msg_prs_multi(tAVDT_MSG *p_msg, UINT8 *p, UINT16 len)
  814. {
  815. int i;
  816. UINT8 err = 0;
  817. p_msg->hdr.err_param = 0;
  818. /* verify len */
  819. if (len < AVDT_LEN_MULTI_MIN || (len > AVDT_NUM_SEPS)) {
  820. err = AVDT_ERR_LENGTH;
  821. } else {
  822. /* get and verify all seps */
  823. for (i = 0; i < len; i++) {
  824. AVDT_MSG_PRS_SEID(p, p_msg->multi.seid_list[i]);
  825. if (avdt_scb_by_hdl(p_msg->multi.seid_list[i]) == NULL) {
  826. err = AVDT_ERR_SEID;
  827. p_msg->hdr.err_param = p_msg->multi.seid_list[i];
  828. break;
  829. }
  830. }
  831. p_msg->multi.num_seps = (UINT8)i;
  832. }
  833. return err;
  834. }
  835. /*******************************************************************************
  836. **
  837. ** Function avdt_msg_prs_security_cmd
  838. **
  839. ** Description This message parsing function parses a security
  840. ** command message.
  841. **
  842. **
  843. ** Returns Error code or zero if no error.
  844. **
  845. *******************************************************************************/
  846. static UINT8 avdt_msg_prs_security_cmd(tAVDT_MSG *p_msg, UINT8 *p, UINT16 len)
  847. {
  848. UINT8 err = 0;
  849. /* verify len */
  850. if (len < AVDT_LEN_SECURITY_MIN) {
  851. err = AVDT_ERR_LENGTH;
  852. } else {
  853. /* get seid */
  854. AVDT_MSG_PRS_SEID(p, p_msg->security_cmd.hdr.seid);
  855. if (avdt_scb_by_hdl(p_msg->security_cmd.hdr.seid) == NULL) {
  856. err = AVDT_ERR_SEID;
  857. } else {
  858. p_msg->security_cmd.p_data = p;
  859. p_msg->security_cmd.len = len - 1;
  860. }
  861. }
  862. return err;
  863. }
  864. /*******************************************************************************
  865. **
  866. ** Function avdt_msg_prs_discover_rsp
  867. **
  868. ** Description This message parsing function parses a discover
  869. ** response message.
  870. **
  871. **
  872. ** Returns Error code or zero if no error.
  873. **
  874. *******************************************************************************/
  875. static UINT8 avdt_msg_prs_discover_rsp(tAVDT_MSG *p_msg, UINT8 *p, UINT16 len)
  876. {
  877. int i;
  878. UINT8 err = 0;
  879. /* determine number of seps; seps in msg is len/2, but set to minimum
  880. ** of seps app has supplied memory for and seps in msg
  881. */
  882. if (p_msg->discover_rsp.num_seps > (len / 2)) {
  883. p_msg->discover_rsp.num_seps = (len / 2);
  884. }
  885. /* parse out sep info */
  886. for (i = 0; i < p_msg->discover_rsp.num_seps; i++) {
  887. /* parse discover rsp info */
  888. AVDT_MSG_PRS_DISC(p, p_msg->discover_rsp.p_sep_info[i].seid,
  889. p_msg->discover_rsp.p_sep_info[i].in_use,
  890. p_msg->discover_rsp.p_sep_info[i].media_type,
  891. p_msg->discover_rsp.p_sep_info[i].tsep);
  892. /* verify that seid is valid */
  893. if ((p_msg->discover_rsp.p_sep_info[i].seid < AVDT_SEID_MIN) ||
  894. (p_msg->discover_rsp.p_sep_info[i].seid > AVDT_SEID_MAX)) {
  895. err = AVDT_ERR_SEID;
  896. break;
  897. }
  898. }
  899. return err;
  900. }
  901. /*******************************************************************************
  902. **
  903. ** Function avdt_msg_prs_svccap
  904. **
  905. ** Description This message parsing function parses a message containing
  906. ** service capabilities parameters.
  907. **
  908. **
  909. ** Returns Error code or zero if no error.
  910. **
  911. *******************************************************************************/
  912. static UINT8 avdt_msg_prs_svccap(tAVDT_MSG *p_msg, UINT8 *p, UINT16 len)
  913. {
  914. /* parse parameters */
  915. UINT8 err = avdt_msg_prs_cfg(p_msg->svccap.p_cfg, p, len, &p_msg->hdr.err_param, AVDT_SIG_GETCAP);
  916. if (p_msg->svccap.p_cfg) {
  917. p_msg->svccap.p_cfg->psc_mask &= AVDT_LEG_PSC;
  918. }
  919. return (err);
  920. }
  921. /*******************************************************************************
  922. **
  923. ** Function avdt_msg_prs_all_svccap
  924. **
  925. ** Description This message parsing function parses a message containing
  926. ** service capabilities parameters.
  927. **
  928. **
  929. ** Returns Error code or zero if no error.
  930. **
  931. *******************************************************************************/
  932. static UINT8 avdt_msg_prs_all_svccap(tAVDT_MSG *p_msg, UINT8 *p, UINT16 len)
  933. {
  934. UINT8 err = avdt_msg_prs_cfg(p_msg->svccap.p_cfg, p, len, &p_msg->hdr.err_param, AVDT_SIG_GET_ALLCAP);
  935. if (p_msg->svccap.p_cfg) {
  936. p_msg->svccap.p_cfg->psc_mask &= AVDT_MSG_PSC_MASK;
  937. }
  938. return (err);
  939. }
  940. /*******************************************************************************
  941. **
  942. ** Function avdt_msg_prs_security_rsp
  943. **
  944. ** Description This message parsing function parsing a security
  945. ** response message.
  946. **
  947. **
  948. ** Returns Error code or zero if no error.
  949. **
  950. *******************************************************************************/
  951. static UINT8 avdt_msg_prs_security_rsp(tAVDT_MSG *p_msg, UINT8 *p, UINT16 len)
  952. {
  953. p_msg->security_rsp.p_data = p;
  954. p_msg->security_rsp.len = len;
  955. return 0;
  956. }
  957. /*******************************************************************************
  958. **
  959. ** Function avdt_msg_prs_rej
  960. **
  961. ** Description
  962. **
  963. **
  964. ** Returns Error code or zero if no error.
  965. **
  966. *******************************************************************************/
  967. static UINT8 avdt_msg_prs_rej(tAVDT_MSG *p_msg, UINT8 *p, UINT8 sig)
  968. {
  969. if ((sig == AVDT_SIG_SETCONFIG) || (sig == AVDT_SIG_RECONFIG)) {
  970. p_msg->hdr.err_param = *p++;
  971. p_msg->hdr.err_code = *p;
  972. } else if ((sig == AVDT_SIG_START) || (sig == AVDT_SIG_SUSPEND)) {
  973. AVDT_MSG_PRS_SEID(p, p_msg->hdr.err_param);
  974. p_msg->hdr.err_code = *p;
  975. } else {
  976. p_msg->hdr.err_code = *p;
  977. }
  978. return 0;
  979. }
  980. /*******************************************************************************
  981. **
  982. ** Function avdt_msg_prs_delay_rpt
  983. **
  984. ** Description This message parsing function parses a security
  985. ** command message.
  986. **
  987. **
  988. ** Returns Error code or zero if no error.
  989. **
  990. *******************************************************************************/
  991. static UINT8 avdt_msg_prs_delay_rpt (tAVDT_MSG *p_msg, UINT8 *p, UINT16 len)
  992. {
  993. UINT8 err = 0;
  994. /* verify len */
  995. if (len != AVDT_LEN_DELAY_RPT) {
  996. AVDT_TRACE_WARNING("avdt_msg_prs_delay_rpt expected len: %u got: %u\n", AVDT_LEN_DELAY_RPT, len);
  997. err = AVDT_ERR_LENGTH;
  998. } else {
  999. /* get seid */
  1000. AVDT_MSG_PRS_SEID (p, p_msg->delay_rpt_cmd.hdr.seid);
  1001. if (avdt_scb_by_hdl(p_msg->delay_rpt_cmd.hdr.seid) == NULL) {
  1002. err = AVDT_ERR_SEID;
  1003. } else {
  1004. BE_STREAM_TO_UINT16 (p_msg->delay_rpt_cmd.delay, p);
  1005. AVDT_TRACE_DEBUG("avdt_msg_prs_delay_rpt delay: %u\n", p_msg->delay_rpt_cmd.delay);
  1006. }
  1007. }
  1008. return err;
  1009. }
  1010. /*******************************************************************************
  1011. **
  1012. ** Function avdt_msg_send
  1013. **
  1014. ** Description Send, and if necessary fragment the next message.
  1015. **
  1016. **
  1017. ** Returns Congested state; TRUE if CCB congested, FALSE if not.
  1018. **
  1019. *******************************************************************************/
  1020. BOOLEAN avdt_msg_send(tAVDT_CCB *p_ccb, BT_HDR *p_msg)
  1021. {
  1022. UINT16 curr_msg_len;
  1023. UINT8 pkt_type;
  1024. UINT8 hdr_len;
  1025. tAVDT_TC_TBL *p_tbl;
  1026. BT_HDR *p_buf;
  1027. UINT8 *p;
  1028. UINT8 label;
  1029. UINT8 msg;
  1030. UINT8 sig;
  1031. UINT8 nosp = 0; /* number of subsequent packets */
  1032. /* look up transport channel table entry to get peer mtu */
  1033. p_tbl = avdt_ad_tc_tbl_by_type(AVDT_CHAN_SIG, p_ccb, NULL);
  1034. /* set the current message if there is a message passed in */
  1035. if (p_msg != NULL) {
  1036. p_ccb->p_curr_msg = p_msg;
  1037. }
  1038. /* store copy of curr_msg->len */
  1039. curr_msg_len = p_ccb->p_curr_msg->len;
  1040. /* while not congested and we haven't sent it all */
  1041. while ((!p_ccb->cong) && (p_ccb->p_curr_msg != NULL)) {
  1042. /* check what kind of message we've got here; we are using the offset
  1043. ** to indicate that a message is being fragmented
  1044. */
  1045. /* if message isn't being fragmented and it fits in mtu */
  1046. if ((p_ccb->p_curr_msg->offset == AVDT_MSG_OFFSET) &&
  1047. (p_ccb->p_curr_msg->len <= p_tbl->peer_mtu - AVDT_LEN_TYPE_SINGLE)) {
  1048. pkt_type = AVDT_PKT_TYPE_SINGLE;
  1049. hdr_len = AVDT_LEN_TYPE_SINGLE;
  1050. p_buf = p_ccb->p_curr_msg;
  1051. }
  1052. /* if message isn't being fragmented and it doesn't fit in mtu */
  1053. else if ((p_ccb->p_curr_msg->offset == AVDT_MSG_OFFSET) &&
  1054. (p_ccb->p_curr_msg->len > p_tbl->peer_mtu - AVDT_LEN_TYPE_SINGLE)) {
  1055. pkt_type = AVDT_PKT_TYPE_START;
  1056. hdr_len = AVDT_LEN_TYPE_START;
  1057. nosp = (p_ccb->p_curr_msg->len + AVDT_LEN_TYPE_START - p_tbl->peer_mtu) /
  1058. (p_tbl->peer_mtu - 1) + 2;
  1059. /* get a new buffer for fragment we are sending */
  1060. if ((p_buf = (BT_HDR *) osi_malloc(AVDT_CMD_BUF_SIZE)) == NULL) {
  1061. /* do we even want to try and recover from this? could do so
  1062. by setting retransmission timer */
  1063. return TRUE;
  1064. }
  1065. /* copy portion of data from current message to new buffer */
  1066. p_buf->offset = L2CAP_MIN_OFFSET + hdr_len;
  1067. p_buf->len = p_tbl->peer_mtu - hdr_len;
  1068. memcpy((UINT8 *)(p_buf + 1) + p_buf->offset,
  1069. (UINT8 *)(p_ccb->p_curr_msg + 1) + p_ccb->p_curr_msg->offset, p_buf->len);
  1070. }
  1071. /* if message is being fragmented and remaining bytes don't fit in mtu */
  1072. else if ((p_ccb->p_curr_msg->offset > AVDT_MSG_OFFSET) &&
  1073. (p_ccb->p_curr_msg->len > (p_tbl->peer_mtu - AVDT_LEN_TYPE_CONT))) {
  1074. pkt_type = AVDT_PKT_TYPE_CONT;
  1075. hdr_len = AVDT_LEN_TYPE_CONT;
  1076. /* get a new buffer for fragment we are sending */
  1077. if ((p_buf = (BT_HDR *) osi_malloc(AVDT_CMD_BUF_SIZE)) == NULL) {
  1078. /* do we even want to try and recover from this? could do so
  1079. by setting retransmission timer */
  1080. return TRUE;
  1081. }
  1082. /* copy portion of data from current message to new buffer */
  1083. p_buf->offset = L2CAP_MIN_OFFSET + hdr_len;
  1084. p_buf->len = p_tbl->peer_mtu - hdr_len;
  1085. memcpy((UINT8 *)(p_buf + 1) + p_buf->offset,
  1086. (UINT8 *)(p_ccb->p_curr_msg + 1) + p_ccb->p_curr_msg->offset, p_buf->len);
  1087. }
  1088. /* if message is being fragmented and remaining bytes do fit in mtu */
  1089. else {
  1090. pkt_type = AVDT_PKT_TYPE_END;
  1091. hdr_len = AVDT_LEN_TYPE_END;
  1092. p_buf = p_ccb->p_curr_msg;
  1093. }
  1094. /* label, sig id, msg type are in hdr of p_curr_msg */
  1095. label = AVDT_LAYERSPEC_LABEL(p_ccb->p_curr_msg->layer_specific);
  1096. msg = AVDT_LAYERSPEC_MSG(p_ccb->p_curr_msg->layer_specific);
  1097. sig = (UINT8) p_ccb->p_curr_msg->event;
  1098. AVDT_TRACE_DEBUG("avdt_msg_send label:%d, msg:%d, sig:%d\n", label, msg, sig);
  1099. /* keep track of how much of msg we've sent */
  1100. curr_msg_len -= p_buf->len;
  1101. if (curr_msg_len == 0) {
  1102. /* entire message sent; mark as finished */
  1103. p_ccb->p_curr_msg = NULL;
  1104. /* start timer here for commands */
  1105. if (msg == AVDT_MSG_TYPE_CMD) {
  1106. /* if retransmit timeout set to zero, sig doesn't use retransmit */
  1107. if ((sig == AVDT_SIG_DISCOVER) || (sig == AVDT_SIG_GETCAP) ||
  1108. (sig == AVDT_SIG_SECURITY) || (avdt_cb.rcb.ret_tout == 0)) {
  1109. btu_start_timer(&p_ccb->timer_entry, BTU_TTYPE_AVDT_CCB_RSP, avdt_cb.rcb.sig_tout);
  1110. } else if (sig != AVDT_SIG_DELAY_RPT) {
  1111. btu_start_timer(&p_ccb->timer_entry, BTU_TTYPE_AVDT_CCB_RET, avdt_cb.rcb.ret_tout);
  1112. }
  1113. }
  1114. } else {
  1115. /* message being fragmented and not completely sent */
  1116. p_ccb->p_curr_msg->len -= p_buf->len;
  1117. p_ccb->p_curr_msg->offset += p_buf->len;
  1118. }
  1119. /* set up to build header */
  1120. p_buf->len += hdr_len;
  1121. p_buf->offset -= hdr_len;
  1122. p = (UINT8 *)(p_buf + 1) + p_buf->offset;
  1123. /* build header */
  1124. AVDT_MSG_BLD_HDR(p, label, pkt_type, msg);
  1125. if (pkt_type == AVDT_PKT_TYPE_START) {
  1126. AVDT_MSG_BLD_NOSP(p, nosp);
  1127. }
  1128. if ((pkt_type == AVDT_PKT_TYPE_START) || (pkt_type == AVDT_PKT_TYPE_SINGLE)) {
  1129. AVDT_MSG_BLD_SIG(p, sig);
  1130. }
  1131. /* send msg buffer down */
  1132. avdt_ad_write_req(AVDT_CHAN_SIG, p_ccb, NULL, p_buf);
  1133. }
  1134. return (p_ccb->cong);
  1135. }
  1136. /*******************************************************************************
  1137. **
  1138. ** Function avdt_msg_asmbl
  1139. **
  1140. ** Description Reassemble incoming message.
  1141. **
  1142. **
  1143. ** Returns Pointer to reassembled message; NULL if no message
  1144. ** available.
  1145. **
  1146. *******************************************************************************/
  1147. BT_HDR *avdt_msg_asmbl(tAVDT_CCB *p_ccb, BT_HDR *p_buf)
  1148. {
  1149. UINT8 *p;
  1150. UINT8 pkt_type;
  1151. BT_HDR *p_ret;
  1152. UINT16 buf_len;
  1153. /* parse the message header */
  1154. p = (UINT8 *)(p_buf + 1) + p_buf->offset;
  1155. AVDT_MSG_PRS_PKT_TYPE(p, pkt_type);
  1156. /* quick sanity check on length */
  1157. if (p_buf->len < avdt_msg_pkt_type_len[pkt_type]) {
  1158. osi_free(p_buf);
  1159. AVDT_TRACE_WARNING("Bad length during reassembly");
  1160. p_ret = NULL;
  1161. }
  1162. /* single packet */
  1163. else if (pkt_type == AVDT_PKT_TYPE_SINGLE) {
  1164. /* if reassembly in progress drop message and process new single */
  1165. if (p_ccb->p_rx_msg != NULL) {
  1166. osi_free(p_ccb->p_rx_msg);
  1167. p_ccb->p_rx_msg = NULL;
  1168. AVDT_TRACE_WARNING("Got single during reassembly");
  1169. }
  1170. p_ret = p_buf;
  1171. }
  1172. /* start packet */
  1173. else if (pkt_type == AVDT_PKT_TYPE_START) {
  1174. /* if reassembly in progress drop message and process new single */
  1175. if (p_ccb->p_rx_msg != NULL) {
  1176. osi_free(p_ccb->p_rx_msg);
  1177. p_ccb->p_rx_msg = NULL;
  1178. AVDT_TRACE_WARNING("Got start during reassembly");
  1179. }
  1180. /*
  1181. * Allocate bigger buffer for reassembly. As lower layers are
  1182. * not aware of possible packet size after reassembly, they
  1183. * would have allocated smaller buffer.
  1184. */
  1185. p_ccb->p_rx_msg = (BT_HDR *)osi_malloc(BT_DEFAULT_BUFFER_SIZE);
  1186. memcpy(p_ccb->p_rx_msg, p_buf,
  1187. sizeof(BT_HDR) + p_buf->offset + p_buf->len);
  1188. /* Free original buffer */
  1189. osi_free(p_buf);
  1190. /* update p to point to new buffer */
  1191. p = (UINT8 *)(p_ccb->p_rx_msg + 1) + p_ccb->p_rx_msg->offset;
  1192. /* copy first header byte over nosp */
  1193. *(p + 1) = *p;
  1194. /* set offset to point to where to copy next */
  1195. p_ccb->p_rx_msg->offset += p_ccb->p_rx_msg->len;
  1196. /* adjust length for packet header */
  1197. p_ccb->p_rx_msg->len -= 1;
  1198. p_ret = NULL;
  1199. }
  1200. /* continue or end */
  1201. else {
  1202. /* if no reassembly in progress drop message */
  1203. if (p_ccb->p_rx_msg == NULL) {
  1204. osi_free(p_buf);
  1205. AVDT_TRACE_WARNING("Pkt type=%d out of order\n", pkt_type);
  1206. p_ret = NULL;
  1207. } else {
  1208. /* get size of buffer holding assembled message */
  1209. buf_len = BT_DEFAULT_BUFFER_SIZE - sizeof(BT_HDR);
  1210. /* adjust offset and len of fragment for header byte */
  1211. p_buf->offset += AVDT_LEN_TYPE_CONT;
  1212. p_buf->len -= AVDT_LEN_TYPE_CONT;
  1213. /* verify length */
  1214. if ((p_ccb->p_rx_msg->offset + p_buf->len) > buf_len) {
  1215. /* won't fit; free everything */
  1216. AVDT_TRACE_WARNING("%s: Fragmented message too big!", __func__);
  1217. osi_free(p_ccb->p_rx_msg);
  1218. p_ccb->p_rx_msg = NULL;
  1219. osi_free(p_buf);
  1220. p_ret = NULL;
  1221. } else {
  1222. /* copy contents of p_buf to p_rx_msg */
  1223. memcpy((UINT8 *)(p_ccb->p_rx_msg + 1) + p_ccb->p_rx_msg->offset,
  1224. (UINT8 *)(p_buf + 1) + p_buf->offset, p_buf->len);
  1225. if (pkt_type == AVDT_PKT_TYPE_END) {
  1226. p_ccb->p_rx_msg->offset -= p_ccb->p_rx_msg->len;
  1227. p_ccb->p_rx_msg->len += p_buf->len;
  1228. p_ret = p_ccb->p_rx_msg;
  1229. p_ccb->p_rx_msg = NULL;
  1230. } else {
  1231. p_ccb->p_rx_msg->offset += p_buf->len;
  1232. p_ccb->p_rx_msg->len += p_buf->len;
  1233. p_ret = NULL;
  1234. }
  1235. osi_free(p_buf);
  1236. }
  1237. }
  1238. }
  1239. return p_ret;
  1240. }
  1241. /*******************************************************************************
  1242. **
  1243. ** Function avdt_msg_send_cmd
  1244. **
  1245. ** Description This function is called to send a command message. The
  1246. ** sig_id parameter indicates the message type, p_params
  1247. ** points to the message parameters, if any. It gets a buffer
  1248. ** from the AVDTP command pool, executes the message building
  1249. ** function for this message type. It then queues the message
  1250. ** in the command queue for this CCB.
  1251. **
  1252. **
  1253. ** Returns Nothing.
  1254. **
  1255. *******************************************************************************/
  1256. void avdt_msg_send_cmd(tAVDT_CCB *p_ccb, void *p_scb, UINT8 sig_id, tAVDT_MSG *p_params)
  1257. {
  1258. BT_HDR *p_buf;
  1259. UINT8 *p;
  1260. UINT8 *p_start;
  1261. /* get a buffer */
  1262. p_buf = (BT_HDR *) osi_malloc(AVDT_CMD_BUF_SIZE);
  1263. if (p_buf == NULL) {
  1264. AVDT_TRACE_ERROR("avdt_msg_send_cmd out of buffer!!");
  1265. return;
  1266. }
  1267. /* set up gki buf pointer and offset */
  1268. p_buf->offset = AVDT_MSG_OFFSET;
  1269. p_start = p = (UINT8 *)(p_buf + 1) + p_buf->offset;
  1270. /* execute parameter building function to build message */
  1271. (*avdt_msg_bld_cmd[sig_id - 1])(&p, p_params);
  1272. /* set len */
  1273. p_buf->len = (UINT16) (p - p_start);
  1274. /* now store scb hdls, if any, in buf */
  1275. if (p_scb != NULL) {
  1276. p = (UINT8 *)(p_buf + 1);
  1277. /* for start and suspend, p_scb points to array of handles */
  1278. if ((sig_id == AVDT_SIG_START) || (sig_id == AVDT_SIG_SUSPEND)) {
  1279. memcpy(p, (UINT8 *) p_scb, p_buf->len);
  1280. }
  1281. /* for all others, p_scb points to scb as usual */
  1282. else {
  1283. *p = avdt_scb_to_hdl((tAVDT_SCB *) p_scb);
  1284. }
  1285. }
  1286. /* stash sig, label, and message type in buf */
  1287. p_buf->event = sig_id;
  1288. AVDT_BLD_LAYERSPEC(p_buf->layer_specific, AVDT_MSG_TYPE_CMD, p_ccb->label);
  1289. /* increment label */
  1290. p_ccb->label = (p_ccb->label + 1) % 16;
  1291. /* queue message and trigger ccb to send it */
  1292. fixed_queue_enqueue(p_ccb->cmd_q, p_buf, FIXED_QUEUE_MAX_TIMEOUT);
  1293. avdt_ccb_event(p_ccb, AVDT_CCB_SENDMSG_EVT, NULL);
  1294. }
  1295. /*******************************************************************************
  1296. **
  1297. ** Function avdt_msg_send_rsp
  1298. **
  1299. ** Description This function is called to send a response message. The
  1300. ** sig_id parameter indicates the message type, p_params
  1301. ** points to the message parameters, if any. It gets a buffer
  1302. ** from the AVDTP command pool, executes the message building
  1303. ** function for this message type. It then queues the message
  1304. ** in the response queue for this CCB.
  1305. **
  1306. **
  1307. ** Returns Nothing.
  1308. **
  1309. *******************************************************************************/
  1310. void avdt_msg_send_rsp(tAVDT_CCB *p_ccb, UINT8 sig_id, tAVDT_MSG *p_params)
  1311. {
  1312. BT_HDR *p_buf;
  1313. UINT8 *p;
  1314. UINT8 *p_start;
  1315. /* get a buffer */
  1316. p_buf = (BT_HDR *) osi_malloc(AVDT_CMD_BUF_SIZE);
  1317. if (p_buf == NULL) {
  1318. return;
  1319. }
  1320. /* set up gki buf pointer and offset */
  1321. p_buf->offset = AVDT_MSG_OFFSET;
  1322. p_start = p = (UINT8 *)(p_buf + 1) + p_buf->offset;
  1323. /* execute parameter building function to build message */
  1324. (*avdt_msg_bld_rsp[sig_id - 1])(&p, p_params);
  1325. /* set length */
  1326. p_buf->len = (UINT16) (p - p_start);
  1327. /* stash sig, label, and message type in buf */
  1328. p_buf->event = sig_id;
  1329. AVDT_BLD_LAYERSPEC(p_buf->layer_specific, AVDT_MSG_TYPE_RSP, p_params->hdr.label);
  1330. /* queue message and trigger ccb to send it */
  1331. fixed_queue_enqueue(p_ccb->rsp_q, p_buf, FIXED_QUEUE_MAX_TIMEOUT);
  1332. avdt_ccb_event(p_ccb, AVDT_CCB_SENDMSG_EVT, NULL);
  1333. }
  1334. /*******************************************************************************
  1335. **
  1336. ** Function avdt_msg_send_rej
  1337. **
  1338. ** Description This function is called to send a reject message. The
  1339. ** sig_id parameter indicates the message type. It gets
  1340. ** a buffer from the AVDTP command pool and builds the
  1341. ** message based on the message type and the error code.
  1342. ** It then queues the message in the response queue for
  1343. ** this CCB.
  1344. **
  1345. **
  1346. ** Returns Nothing.
  1347. **
  1348. *******************************************************************************/
  1349. void avdt_msg_send_rej(tAVDT_CCB *p_ccb, UINT8 sig_id, tAVDT_MSG *p_params)
  1350. {
  1351. BT_HDR *p_buf;
  1352. UINT8 *p;
  1353. UINT8 *p_start;
  1354. /* get a buffer */
  1355. p_buf = (BT_HDR *) osi_malloc(AVDT_CMD_BUF_SIZE);
  1356. if (p_buf == NULL) {
  1357. return;
  1358. }
  1359. /* set up gki buf pointer and offset */
  1360. p_buf->offset = AVDT_MSG_OFFSET;
  1361. p_start = p = (UINT8 *)(p_buf + 1) + p_buf->offset;
  1362. /* if sig id included, build into message */
  1363. if (sig_id != AVDT_SIG_NONE) {
  1364. /* if this sig has a parameter, add the parameter */
  1365. if ((sig_id == AVDT_SIG_SETCONFIG) ||
  1366. (sig_id == AVDT_SIG_RECONFIG)) {
  1367. AVDT_MSG_BLD_PARAM(p, p_params->hdr.err_param);
  1368. } else if ((sig_id == AVDT_SIG_START) ||
  1369. (sig_id == AVDT_SIG_SUSPEND)) {
  1370. AVDT_MSG_BLD_SEID(p, p_params->hdr.err_param);
  1371. }
  1372. /* add the error code */
  1373. AVDT_MSG_BLD_ERR(p, p_params->hdr.err_code);
  1374. }
  1375. AVDT_TRACE_DEBUG("avdt_msg_send_rej");
  1376. /* calculate length */
  1377. p_buf->len = (UINT16) (p - p_start);
  1378. /* stash sig, label, and message type in buf */
  1379. p_buf->event = sig_id;
  1380. AVDT_BLD_LAYERSPEC(p_buf->layer_specific, AVDT_MSG_TYPE_REJ, p_params->hdr.label);
  1381. /* queue message and trigger ccb to send it */
  1382. fixed_queue_enqueue(p_ccb->rsp_q, p_buf, FIXED_QUEUE_MAX_TIMEOUT);
  1383. avdt_ccb_event(p_ccb, AVDT_CCB_SENDMSG_EVT, NULL);
  1384. }
  1385. /*******************************************************************************
  1386. **
  1387. ** Function avdt_msg_send_grej
  1388. **
  1389. ** Description This function is called to send a general reject message. The
  1390. ** sig_id parameter indicates the message type. It gets
  1391. ** a buffer from the AVDTP command pool and builds the
  1392. ** message based on the message type and the error code.
  1393. ** It then queues the message in the response queue for
  1394. ** this CCB.
  1395. **
  1396. **
  1397. ** Returns Nothing.
  1398. **
  1399. *******************************************************************************/
  1400. void avdt_msg_send_grej(tAVDT_CCB *p_ccb, UINT8 sig_id, tAVDT_MSG *p_params)
  1401. {
  1402. BT_HDR *p_buf;
  1403. UINT8 *p;
  1404. UINT8 *p_start;
  1405. /* get a buffer */
  1406. p_buf = (BT_HDR *) osi_malloc(AVDT_CMD_BUF_SIZE);
  1407. if (p_buf == NULL) {
  1408. return;
  1409. }
  1410. /* set up gki buf pointer and offset */
  1411. p_buf->offset = AVDT_MSG_OFFSET;
  1412. p_start = p = (UINT8 *)(p_buf + 1) + p_buf->offset;
  1413. /* calculate length */
  1414. p_buf->len = (UINT16) (p - p_start);
  1415. /* stash sig, label, and message type in buf */
  1416. p_buf->event = 0;
  1417. AVDT_BLD_LAYERSPEC(p_buf->layer_specific, 0, p_params->hdr.label);
  1418. AVDT_TRACE_DEBUG("avdt_msg_send_grej");
  1419. /* queue message and trigger ccb to send it */
  1420. fixed_queue_enqueue(p_ccb->rsp_q, p_buf, FIXED_QUEUE_MAX_TIMEOUT);
  1421. avdt_ccb_event(p_ccb, AVDT_CCB_SENDMSG_EVT, NULL);
  1422. }
  1423. /*******************************************************************************
  1424. **
  1425. ** Function avdt_msg_ind
  1426. **
  1427. ** Description This function is called by the adaption layer when an
  1428. ** incoming message is received on the signaling channel.
  1429. ** It parses the message and sends an event to the appropriate
  1430. ** SCB or CCB for the message.
  1431. **
  1432. **
  1433. ** Returns Nothing.
  1434. **
  1435. *******************************************************************************/
  1436. void avdt_msg_ind(tAVDT_CCB *p_ccb, BT_HDR *p_buf)
  1437. {
  1438. tAVDT_SCB *p_scb;
  1439. UINT8 *p;
  1440. BOOLEAN ok = TRUE;
  1441. BOOLEAN handle_rsp = FALSE;
  1442. BOOLEAN gen_rej = FALSE;
  1443. UINT8 label;
  1444. UINT8 pkt_type;
  1445. UINT8 msg_type;
  1446. UINT8 sig = 0;
  1447. tAVDT_MSG msg;
  1448. tAVDT_CFG cfg;
  1449. UINT8 err;
  1450. UINT8 evt = 0;
  1451. UINT8 scb_hdl;
  1452. /* reassemble message; if no message available (we received a fragment) return */
  1453. if ((p_buf = avdt_msg_asmbl(p_ccb, p_buf)) == NULL) {
  1454. return;
  1455. }
  1456. p = (UINT8 *)(p_buf + 1) + p_buf->offset;
  1457. /* parse the message header */
  1458. AVDT_MSG_PRS_HDR(p, label, pkt_type, msg_type);
  1459. UNUSED(pkt_type);
  1460. AVDT_TRACE_DEBUG("msg_type=%d, sig=%d\n", msg_type, sig);
  1461. /* set up label and ccb_idx in message hdr */
  1462. msg.hdr.label = label;
  1463. msg.hdr.ccb_idx = avdt_ccb_to_idx(p_ccb);
  1464. /* verify msg type */
  1465. if (msg_type == AVDT_MSG_TYPE_GRJ) {
  1466. AVDT_TRACE_WARNING("Dropping msg msg_type=%d\n", msg_type);
  1467. ok = FALSE;
  1468. }
  1469. /* check for general reject */
  1470. else if ((msg_type == AVDT_MSG_TYPE_REJ) && (p_buf->len == AVDT_LEN_GEN_REJ)) {
  1471. gen_rej = TRUE;
  1472. if (p_ccb->p_curr_cmd != NULL) {
  1473. msg.hdr.sig_id = sig = (UINT8) p_ccb->p_curr_cmd->event;
  1474. evt = avdt_msg_rej_2_evt[sig - 1];
  1475. msg.hdr.err_code = AVDT_ERR_NSC;
  1476. msg.hdr.err_param = 0;
  1477. }
  1478. } else { /* not a general reject */
  1479. /* get and verify signal */
  1480. AVDT_MSG_PRS_SIG(p, sig);
  1481. msg.hdr.sig_id = sig;
  1482. if ((sig == 0) || (sig > AVDT_SIG_MAX)) {
  1483. AVDT_TRACE_WARNING("Dropping msg sig=%d msg_type:%d\n", sig, msg_type);
  1484. ok = FALSE;
  1485. /* send a general reject */
  1486. if (msg_type == AVDT_MSG_TYPE_CMD) {
  1487. avdt_msg_send_grej(p_ccb, sig, &msg);
  1488. }
  1489. }
  1490. }
  1491. if (ok && !gen_rej) {
  1492. /* skip over header (msg length already verified during reassembly) */
  1493. p_buf->len -= AVDT_LEN_TYPE_SINGLE;
  1494. /* set up to parse message */
  1495. if ((msg_type == AVDT_MSG_TYPE_RSP) && (sig == AVDT_SIG_DISCOVER)) {
  1496. /* parse discover rsp message to struct supplied by app */
  1497. msg.discover_rsp.p_sep_info = (tAVDT_SEP_INFO *) p_ccb->p_proc_data;
  1498. msg.discover_rsp.num_seps = p_ccb->proc_param;
  1499. } else if ((msg_type == AVDT_MSG_TYPE_RSP) &&
  1500. ((sig == AVDT_SIG_GETCAP) || (sig == AVDT_SIG_GET_ALLCAP))) {
  1501. /* parse discover rsp message to struct supplied by app */
  1502. msg.svccap.p_cfg = (tAVDT_CFG *) p_ccb->p_proc_data;
  1503. } else if ((msg_type == AVDT_MSG_TYPE_RSP) && (sig == AVDT_SIG_GETCONFIG)) {
  1504. /* parse get config rsp message to struct allocated locally */
  1505. msg.svccap.p_cfg = &cfg;
  1506. } else if ((msg_type == AVDT_MSG_TYPE_CMD) && (sig == AVDT_SIG_SETCONFIG)) {
  1507. /* parse config cmd message to struct allocated locally */
  1508. msg.config_cmd.p_cfg = &cfg;
  1509. } else if ((msg_type == AVDT_MSG_TYPE_CMD) && (sig == AVDT_SIG_RECONFIG)) {
  1510. /* parse reconfig cmd message to struct allocated locally */
  1511. msg.reconfig_cmd.p_cfg = &cfg;
  1512. }
  1513. /* parse message; while we're at it map message sig to event */
  1514. if (msg_type == AVDT_MSG_TYPE_CMD) {
  1515. msg.hdr.err_code = err = (*avdt_msg_prs_cmd[sig - 1])(&msg, p, p_buf->len);
  1516. evt = avdt_msg_cmd_2_evt[sig - 1];
  1517. } else if (msg_type == AVDT_MSG_TYPE_RSP) {
  1518. msg.hdr.err_code = err = (*avdt_msg_prs_rsp[sig - 1])(&msg, p, p_buf->len);
  1519. evt = avdt_msg_rsp_2_evt[sig - 1];
  1520. } else { /* msg_type == AVDT_MSG_TYPE_REJ */
  1521. err = avdt_msg_prs_rej(&msg, p, sig);
  1522. evt = avdt_msg_rej_2_evt[sig - 1];
  1523. }
  1524. /* if parsing failed */
  1525. if (err != 0) {
  1526. AVDT_TRACE_WARNING("Parsing failed sig=%d err=0x%x\n", sig, err);
  1527. /* if its a rsp or rej, drop it; if its a cmd, send a rej;
  1528. ** note special case for abort; never send abort reject
  1529. */
  1530. ok = FALSE;
  1531. if ((msg_type == AVDT_MSG_TYPE_CMD) && (sig != AVDT_SIG_ABORT)) {
  1532. avdt_msg_send_rej(p_ccb, sig, &msg);
  1533. }
  1534. }
  1535. }
  1536. /* if its a rsp or rej, check sent cmd to see if we're waiting for
  1537. ** the rsp or rej. If we didn't send a cmd for it, drop it. If
  1538. ** it does match a cmd, stop timer for the cmd.
  1539. */
  1540. if (ok) {
  1541. if ((msg_type == AVDT_MSG_TYPE_RSP) || (msg_type == AVDT_MSG_TYPE_REJ)) {
  1542. if ((p_ccb->p_curr_cmd != NULL) &&
  1543. (p_ccb->p_curr_cmd->event == sig) &&
  1544. (AVDT_LAYERSPEC_LABEL(p_ccb->p_curr_cmd->layer_specific) == label)) {
  1545. /* stop timer */
  1546. btu_stop_timer(&p_ccb->timer_entry);
  1547. /* clear retransmission count */
  1548. p_ccb->ret_count = 0;
  1549. /* later in this function handle ccb event */
  1550. handle_rsp = TRUE;
  1551. } else {
  1552. ok = FALSE;
  1553. AVDT_TRACE_WARNING("Cmd not found for rsp sig=%d label=%d\n", sig, label);
  1554. }
  1555. }
  1556. }
  1557. if (ok) {
  1558. /* if it's a ccb event send to ccb */
  1559. if (evt & AVDT_CCB_MKR) {
  1560. avdt_ccb_event(p_ccb, (UINT8)(evt & ~AVDT_CCB_MKR), (tAVDT_CCB_EVT *) &msg);
  1561. }
  1562. /* if it's a scb event */
  1563. else {
  1564. /* Scb events always have a single seid. For cmd, get seid from
  1565. ** message. For rej and rsp, get seid from p_curr_cmd.
  1566. */
  1567. if (msg_type == AVDT_MSG_TYPE_CMD) {
  1568. scb_hdl = msg.single.seid;
  1569. } else {
  1570. scb_hdl = *((UINT8 *)(p_ccb->p_curr_cmd + 1));
  1571. }
  1572. /* Map seid to the scb and send it the event. For cmd, seid has
  1573. ** already been verified by parsing function.
  1574. */
  1575. if (evt && (p_scb = avdt_scb_by_hdl(scb_hdl)) != NULL) {
  1576. avdt_scb_event(p_scb, evt, (tAVDT_SCB_EVT *) &msg);
  1577. }
  1578. }
  1579. }
  1580. /* free message buffer */
  1581. osi_free(p_buf);
  1582. /* if its a rsp or rej, send event to ccb to free associated
  1583. ** cmd msg buffer and handle cmd queue
  1584. */
  1585. if (handle_rsp) {
  1586. avdt_ccb_event(p_ccb, AVDT_CCB_RCVRSP_EVT, NULL);
  1587. }
  1588. }
  1589. #endif /* #if (defined(AVDT_INCLUDED) && AVDT_INCLUDED == TRUE) */