system/bt
Revision | 0f54d697b7fb9ac62bc3f5ce0a001495ad97377a (tree) |
---|---|
Zeit | 2017-05-24 11:03:53 |
Autor | Jack He <siyuanh@goog...> |
Commiter | Jack He |
MCAP: Fix bugs in MCAP stack
* Fix error response message for clock sync opcodes
* Fix error response message for CREATE_MDL opcode
* Fix logging in the MCAP stack
Bug: 37867299
Test: make, PTS MCAP test
Change-Id: I7a37ac04806bca20d732357f00b4761577b4be19
(cherry picked from commit b3a8dc2ece90770b41f4bc0555fabb2742093176)
@@ -154,7 +154,6 @@ void mca_ccb_snd_req(tMCA_CCB* p_ccb, tMCA_CCB_EVT* p_data) { | ||
154 | 154 | void mca_ccb_snd_rsp(tMCA_CCB* p_ccb, tMCA_CCB_EVT* p_data) { |
155 | 155 | tMCA_CCB_MSG* p_msg = (tMCA_CCB_MSG*)p_data; |
156 | 156 | uint8_t *p, *p_start; |
157 | - bool chk_mdl = false; | |
158 | 157 | BT_HDR* p_pkt = (BT_HDR*)osi_malloc(MCA_CTRL_MTU); |
159 | 158 | |
160 | 159 | MCA_TRACE_DEBUG("%s cong=%d req=%d", __func__, p_ccb->cong, p_msg->op_code); |
@@ -165,25 +164,28 @@ void mca_ccb_snd_rsp(tMCA_CCB* p_ccb, tMCA_CCB_EVT* p_data) { | ||
165 | 164 | *p++ = p_msg->op_code; |
166 | 165 | *p++ = p_msg->rsp_code; |
167 | 166 | UINT16_TO_BE_STREAM(p, p_msg->mdl_id); |
168 | - if (p_msg->op_code == MCA_OP_MDL_CREATE_RSP) { | |
169 | - *p++ = p_msg->param; | |
170 | - chk_mdl = true; | |
171 | - } else if (p_msg->op_code == MCA_OP_MDL_RECONNECT_RSP) { | |
172 | - chk_mdl = true; | |
167 | + // Only add extra parameters for MCA_RSP_SUCCESS message | |
168 | + if (p_msg->rsp_code == MCA_RSP_SUCCESS) { | |
169 | + // Append MDL configuration parameters | |
170 | + if (p_msg->op_code == MCA_OP_MDL_CREATE_RSP) { | |
171 | + *p++ = p_msg->param; | |
172 | + } | |
173 | + // Check MDL | |
174 | + if (p_msg->op_code == MCA_OP_MDL_CREATE_RSP || | |
175 | + p_msg->op_code == MCA_OP_MDL_RECONNECT_RSP) { | |
176 | + mca_dcb_by_hdl(p_msg->dcb_idx); | |
177 | + BTM_SetSecurityLevel(false, "", BTM_SEC_SERVICE_MCAP_DATA, | |
178 | + p_ccb->sec_mask, p_ccb->p_rcb->reg.data_psm, | |
179 | + BTM_SEC_PROTO_MCA, p_msg->dcb_idx); | |
180 | + p_ccb->status = MCA_CCB_STAT_PENDING; | |
181 | + /* set p_tx_req to block API_REQ/API_RSP before DL is up */ | |
182 | + osi_free_and_reset((void**)&p_ccb->p_tx_req); | |
183 | + p_ccb->p_tx_req = p_ccb->p_rx_msg; | |
184 | + p_ccb->p_rx_msg = NULL; | |
185 | + p_ccb->p_tx_req->dcb_idx = p_msg->dcb_idx; | |
186 | + } | |
173 | 187 | } |
174 | 188 | |
175 | - if (chk_mdl && p_msg->rsp_code == MCA_RSP_SUCCESS) { | |
176 | - mca_dcb_by_hdl(p_msg->dcb_idx); | |
177 | - BTM_SetSecurityLevel(false, "", BTM_SEC_SERVICE_MCAP_DATA, p_ccb->sec_mask, | |
178 | - p_ccb->p_rcb->reg.data_psm, BTM_SEC_PROTO_MCA, | |
179 | - p_msg->dcb_idx); | |
180 | - p_ccb->status = MCA_CCB_STAT_PENDING; | |
181 | - /* set p_tx_req to block API_REQ/API_RSP before DL is up */ | |
182 | - osi_free_and_reset((void**)&p_ccb->p_tx_req); | |
183 | - p_ccb->p_tx_req = p_ccb->p_rx_msg; | |
184 | - p_ccb->p_rx_msg = NULL; | |
185 | - p_ccb->p_tx_req->dcb_idx = p_msg->dcb_idx; | |
186 | - } | |
187 | 189 | osi_free_and_reset((void**)&p_ccb->p_rx_msg); |
188 | 190 | p_pkt->len = p - p_start; |
189 | 191 | L2CA_DataWrite(p_ccb->lcid, p_pkt); |
@@ -324,7 +326,8 @@ void mca_ccb_hdl_req(tMCA_CCB* p_ccb, tMCA_CCB_EVT* p_data) { | ||
324 | 326 | evt_data.create_ind.cfg = *p++; |
325 | 327 | p_rx_msg->mdep_id = evt_data.create_ind.dep_id; |
326 | 328 | if (!mca_is_valid_dep_id(p_ccb->p_rcb, p_rx_msg->mdep_id)) { |
327 | - MCA_TRACE_ERROR("not a valid local mdep id"); | |
329 | + MCA_TRACE_ERROR("%s: Invalid local MDEP ID %d", __func__, | |
330 | + p_rx_msg->mdep_id); | |
328 | 331 | reject_code = MCA_RSP_BAD_MDEP; |
329 | 332 | } else if (mca_ccb_uses_mdl_id(p_ccb, evt_data.hdr.mdl_id)) { |
330 | 333 | MCA_TRACE_DEBUG("the mdl_id is currently used in the CL(create)"); |
@@ -332,7 +335,8 @@ void mca_ccb_hdl_req(tMCA_CCB* p_ccb, tMCA_CCB_EVT* p_data) { | ||
332 | 335 | } else { |
333 | 336 | /* check if this dep still have MDL available */ |
334 | 337 | if (mca_dep_free_mdl(p_ccb, evt_data.create_ind.dep_id) == 0) { |
335 | - MCA_TRACE_ERROR("the mdep is currently using max_mdl"); | |
338 | + MCA_TRACE_ERROR("%s: MAX_MDL is used by MDEP %d", __func__, | |
339 | + evt_data.create_ind.dep_id); | |
336 | 340 | reject_code = MCA_RSP_MDEP_BUSY; |
337 | 341 | } |
338 | 342 | } |
@@ -340,7 +344,8 @@ void mca_ccb_hdl_req(tMCA_CCB* p_ccb, tMCA_CCB_EVT* p_data) { | ||
340 | 344 | |
341 | 345 | case MCA_OP_MDL_RECONNECT_REQ: |
342 | 346 | if (mca_ccb_uses_mdl_id(p_ccb, evt_data.hdr.mdl_id)) { |
343 | - MCA_TRACE_ERROR("the mdl_id is currently used in the CL(reconn)"); | |
347 | + MCA_TRACE_ERROR("%s: MDL_ID %d busy, in CL(reconn)", __func__, | |
348 | + evt_data.hdr.mdl_id); | |
344 | 349 | reject_code = MCA_RSP_MDL_BUSY; |
345 | 350 | } |
346 | 351 | break; |
@@ -367,17 +372,41 @@ void mca_ccb_hdl_req(tMCA_CCB* p_ccb, tMCA_CCB_EVT* p_data) { | ||
367 | 372 | p = p_start = (uint8_t*)(p_buf + 1) + L2CAP_MIN_OFFSET; |
368 | 373 | *p++ = reject_opcode; |
369 | 374 | *p++ = reject_code; |
370 | - UINT16_TO_BE_STREAM(p, evt_data.hdr.mdl_id); | |
371 | - /* | |
372 | - if (((*p_start) == MCA_OP_MDL_CREATE_RSP) && (reject_code == | |
373 | - MCA_RSP_SUCCESS)) | |
374 | - { | |
375 | - *p++ = evt_data.create_ind.cfg; | |
376 | - } | |
377 | - */ | |
378 | - | |
379 | - p_buf->len = p - p_start; | |
380 | - L2CA_DataWrite(p_ccb->lcid, p_buf); | |
375 | + bool valid_response = true; | |
376 | + switch (reject_opcode) { | |
377 | + // Fill in the rest of standard opcode response packet with mdl_id | |
378 | + case MCA_OP_ERROR_RSP: | |
379 | + case MCA_OP_MDL_CREATE_RSP: | |
380 | + case MCA_OP_MDL_RECONNECT_RSP: | |
381 | + case MCA_OP_MDL_ABORT_RSP: | |
382 | + case MCA_OP_MDL_DELETE_RSP: | |
383 | + UINT16_TO_BE_STREAM(p, evt_data.hdr.mdl_id); | |
384 | + break; | |
385 | + // Fill in the rest of clock sync opcode response packet with 0 | |
386 | + case MCA_OP_SYNC_CAP_RSP: | |
387 | + // Page 37/58 MCAP V1.0 Spec: Total length (9) - 2 = 7 | |
388 | + memset(p, 0, 7); | |
389 | + p += 7; | |
390 | + break; | |
391 | + case MCA_OP_SYNC_SET_RSP: | |
392 | + // Page 39/58 MCAP V1.0 Spec: Total length (16) - 2 = 14 | |
393 | + memset(p, 0, 14); | |
394 | + p += 14; | |
395 | + break; | |
396 | + default: | |
397 | + MCA_TRACE_ERROR("%s: reject_opcode 0x%02x not recognized", __func__, | |
398 | + reject_opcode); | |
399 | + valid_response = false; | |
400 | + break; | |
401 | + } | |
402 | + if (valid_response) { | |
403 | + p_buf->len = p - p_start; | |
404 | + MCA_TRACE_ERROR("%s: reject_opcode=0x%02x, reject_code=0x%02x, length=%d", | |
405 | + __func__, reject_opcode, reject_code, p_buf->len); | |
406 | + L2CA_DataWrite(p_ccb->lcid, p_buf); | |
407 | + } else { | |
408 | + osi_free(p_buf); | |
409 | + } | |
381 | 410 | } |
382 | 411 | |
383 | 412 | if (reject_code == MCA_RSP_SUCCESS) { |
@@ -406,7 +406,7 @@ void mca_tc_data_ind(tMCA_TC_TBL* p_tbl, BT_HDR* p_buf) { | ||
406 | 406 | uint8_t* p; |
407 | 407 | uint8_t rej_rsp_code = MCA_RSP_SUCCESS; |
408 | 408 | |
409 | - MCA_TRACE_DEBUG("%s() - tcid: %d, cb_idx: %d", __func__, p_tbl->tcid, | |
409 | + MCA_TRACE_DEBUG("%s: tcid: %d, cb_idx: %d", __func__, p_tbl->tcid, | |
410 | 410 | p_tbl->cb_idx); |
411 | 411 | |
412 | 412 | /* if control channel, handle control message */ |
@@ -419,17 +419,17 @@ void mca_tc_data_ind(tMCA_TC_TBL* p_tbl, BT_HDR* p_buf) { | ||
419 | 419 | |
420 | 420 | if (*p < MCA_NUM_STANDARD_OPCODE) { |
421 | 421 | if (p_buf->len != mca_std_msg_len[*p]) { |
422 | - MCA_TRACE_ERROR("$s() - opcode: %d required len: %d, got len: %d", | |
422 | + MCA_TRACE_ERROR("%s: opcode 0x%02x required len: %d, got len: %d", | |
423 | 423 | __func__, *p, mca_std_msg_len[*p], p_buf->len); |
424 | 424 | rej_rsp_code = MCA_RSP_BAD_PARAM; |
425 | 425 | } |
426 | 426 | } else if ((*p >= MCA_FIRST_SYNC_OP) && (*p <= MCA_LAST_SYNC_OP)) { |
427 | - MCA_TRACE_ERROR("%s() - unsupported SYNC opcode: %d len:%d", __func__, | |
427 | + MCA_TRACE_ERROR("%s: unsupported SYNC opcode: 0x%02x len:%d", __func__, | |
428 | 428 | *p, p_buf->len); |
429 | 429 | /* reject unsupported request */ |
430 | 430 | rej_rsp_code = MCA_RSP_NO_SUPPORT; |
431 | 431 | } else { |
432 | - MCA_TRACE_ERROR("%s() - bad opcode: %d len:%d", __func__, *p, | |
432 | + MCA_TRACE_ERROR("%s: bad opcode: 0x%02x len:%d", __func__, *p, | |
433 | 433 | p_buf->len); |
434 | 434 | /* reject unsupported request */ |
435 | 435 | rej_rsp_code = MCA_RSP_BAD_OPCODE; |