/****************************************************************************** ** ** Function avrc_vendor_msg ** ** Description Compose a VENDOR DEPENDENT command according to p_msg ** ** Input Parameters: ** p_msg: Pointer to VENDOR DEPENDENT message structure. ** ** Output Parameters: ** None. ** ** Returns pointer to a valid GKI buffer if successful. ** NULL if p_msg is NULL. ** ******************************************************************************/ static BT_HDR *avrc_vendor_msg(tAVRC_MSG_VENDOR *p_msg) { BT_HDR *p_cmd; UINT8 *p_data; assert(p_msg != NULL); #if AVRC_METADATA_INCLUDED == TRUE assert(AVRC_META_CMD_BUF_SIZE > (AVRC_MIN_CMD_LEN + p_msg->vendor_len)); if ((p_cmd = (BT_HDR *) osi_malloc(AVRC_META_CMD_BUF_SIZE)) != NULL) #else assert(AVRC_CMD_BUF_SIZE > (AVRC_MIN_CMD_LEN + p_msg->vendor_len)); if ((p_cmd = (BT_HDR *) osi_malloc(AVRC_CMD_BUF_SIZE)) != NULL) #endif { p_cmd->offset = AVCT_MSG_OFFSET; p_data = (UINT8 *)(p_cmd + 1) + p_cmd->offset; *p_data++ = (p_msg->hdr.ctype & AVRC_CTYPE_MASK); *p_data++ = (p_msg->hdr.subunit_type << AVRC_SUBTYPE_SHIFT) | p_msg->hdr.subunit_id; *p_data++ = AVRC_OP_VENDOR; AVRC_CO_ID_TO_BE_STREAM(p_data, p_msg->company_id); if (p_msg->vendor_len && p_msg->p_vendor_data) { memcpy(p_data, p_msg->p_vendor_data, p_msg->vendor_len); } p_cmd->len = (UINT16) (p_data + p_msg->vendor_len - (UINT8 *)(p_cmd + 1) - p_cmd->offset); p_cmd->layer_specific = AVCT_DATA_CTRL; } return p_cmd; }
static void btc_gattc_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src) { tBTA_GATTC *p_dest_data = (tBTA_GATTC *) p_dest; tBTA_GATTC *p_src_data = (tBTA_GATTC *) p_src; if (!p_src_data || !p_dest_data) { return; } // Allocate buffer for request data if necessary switch (msg->act) { case BTA_GATTC_READ_DESCR_EVT: case BTA_GATTC_READ_CHAR_EVT: case BTA_GATTC_READ_MUTIPLE_EVT: { if (p_src_data->read.p_value && p_src_data->read.p_value->p_value) { p_dest_data->read.p_value = (tBTA_GATT_UNFMT *)osi_malloc(sizeof(tBTA_GATT_UNFMT) + p_src_data->read.p_value->len); p_dest_data->read.p_value->p_value = (uint8_t *)(p_dest_data->read.p_value + 1); if (p_dest_data->read.p_value && p_dest_data->read.p_value->p_value) { p_dest_data->read.p_value->len = p_src_data->read.p_value->len; memcpy(p_dest_data->read.p_value->p_value, p_src_data->read.p_value->p_value, p_src_data->read.p_value->len); } else { LOG_ERROR("%s %d no mem\n", __func__, msg->act); } } break; } default: break; } }
/******************************************************************************* ** ** Function avdt_ccb_ret_cmd ** ** Description This function is called to retransmit the currently ** pending command. The retransmission count is incremented. ** If the count reaches the maximum number of retransmissions, ** the event is treated as a response timeout. ** ** ** Returns void. ** *******************************************************************************/ void avdt_ccb_ret_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data) { UINT8 err_code = AVDT_ERR_TIMEOUT; BT_HDR *p_msg; p_ccb->ret_count++; if (p_ccb->ret_count == AVDT_RET_MAX) { /* command failed */ p_ccb->ret_count = 0; avdt_ccb_cmd_fail(p_ccb, (tAVDT_CCB_EVT *) &err_code); /* go to next queued command */ avdt_ccb_snd_cmd(p_ccb, p_data); } else { /* if command pending and we're not congested and not sending a fragment */ if ((!p_ccb->cong) && (p_ccb->p_curr_msg == NULL) && (p_ccb->p_curr_cmd != NULL)) { /* make copy of message in p_curr_cmd and send it */ if ((p_msg = (BT_HDR *) osi_malloc(AVDT_CMD_BUF_SIZE)) != NULL) { memcpy(p_msg, p_ccb->p_curr_cmd, (sizeof(BT_HDR) + p_ccb->p_curr_cmd->offset + p_ccb->p_curr_cmd->len)); avdt_msg_send(p_ccb, p_msg); } } /* restart timer */ btu_start_timer(&p_ccb->timer_entry, BTU_TTYPE_AVDT_CCB_RET, avdt_cb.rcb.ret_tout); } }
/******************************************************************************* ** ** Function btm_init ** ** Description This function is called at BTM startup to allocate the ** control block (if using dynamic memory), and initializes the ** tracing level. It then initializes the various components of ** btm. ** ** Returns void ** *******************************************************************************/ void btm_init (void) { #if BTM_DYNAMIC_MEMORY btm_cb_ptr = (tBTM_CB *)osi_malloc(sizeof(tBTM_CB)); #endif /* #if BTM_DYNAMIC_MEMORY */ /* All fields are cleared; nonzero fields are reinitialized in appropriate function */ memset(&btm_cb, 0, sizeof(tBTM_CB)); btm_cb.page_queue = fixed_queue_new(QUEUE_SIZE_MAX); btm_cb.sec_pending_q = fixed_queue_new(QUEUE_SIZE_MAX); #if defined(BTM_INITIAL_TRACE_LEVEL) btm_cb.trace_level = BTM_INITIAL_TRACE_LEVEL; #else btm_cb.trace_level = BT_TRACE_LEVEL_NONE; #endif /* Initialize BTM component structures */ btm_inq_db_init(); /* Inquiry Database and Structures */ btm_acl_init(); /* ACL Database and Structures */ #if (SMP_INCLUDED == TRUE) btm_sec_init(BTM_SEC_MODE_SP); /* Security Manager Database and Structures */ #endif ///SMP_INCLUDED == TRUE #if BTM_SCO_INCLUDED == TRUE btm_sco_init(); /* SCO Database and Structures (If included) */ #endif btm_dev_init(); /* Device Manager Structures & HCI_Reset */ btm_lock_init(); btm_sem_init(); }
/******************************************************************************* ** ** Function BTA_GATTC_WriteCharDescr ** ** Description This function is called to write descriptor value. ** ** Parameters conn_id - connection ID ** handle - descriptor hadle to write. ** write_type - write type. ** p_value - the value to be written. ** ** Returns None ** *******************************************************************************/ void BTA_GATTC_WriteCharDescr (UINT16 conn_id, UINT16 handle, tBTA_GATTC_WRITE_TYPE write_type, tBTA_GATT_UNFMT *p_data, tBTA_GATT_AUTH_REQ auth_req) { size_t len = sizeof(tBTA_GATTC_API_WRITE); tBTA_GATTC_API_WRITE *p_buf; if (p_data != NULL) { len += p_data->len; } if ((p_buf = (tBTA_GATTC_API_WRITE *) osi_malloc(len)) != NULL) { memset(p_buf, 0, len); p_buf->hdr.event = BTA_GATTC_API_WRITE_EVT; p_buf->hdr.layer_specific = conn_id; p_buf->auth_req = auth_req; p_buf->handle = handle; p_buf->cmpl_evt = BTA_GATTC_WRITE_DESCR_EVT; p_buf->write_type = write_type; if (p_data && p_data->len != 0) { p_buf->p_value = (UINT8 *)(p_buf + 1); p_buf->len = p_data->len; /* pack the descr data */ memcpy(p_buf->p_value, p_data->p_value, p_data->len); } bta_sys_sendmsg(p_buf); } return; }
static char *bta_hf_client_parse_cind_list(char *buffer) { int offset; char *name = osi_malloc(129); UINT32 min, max; UINT32 index = 0; int res; if (name == NULL) { APPL_TRACE_ERROR("No mem %s", __FUNCTION__); return NULL; } while ((res = sscanf(buffer, "(\"%128[^\"]\",(%u%*[-,]%u))%n", name, &min, &max, &offset)) > 2) { bta_hf_client_handle_cind_list_item(name, min, max, index); buffer += offset; index++; if (*buffer != ',') { break; } buffer++; } osi_free(name); if (res > 2) { AT_CHECK_RN(buffer); return buffer; } return NULL; }
/******************************************************************************* ** ** Function BTA_GATTC_PrepareWriteCharDescr ** ** Description This function is called to prepare write a characteristic descriptor value. ** ** Parameters conn_id - connection ID. ** p_char_descr_id - GATT characteritic descriptor ID of the service. ** offset - offset of the write value. ** len: length of the data to be written. ** p_value - the value to be written. ** ** Returns None ** *******************************************************************************/ void BTA_GATTC_PrepareWriteCharDescr (UINT16 conn_id, UINT16 handle, UINT16 offset,tBTA_GATT_UNFMT *p_data, tBTA_GATT_AUTH_REQ auth_req) { tBTA_GATTC_API_WRITE *p_buf; UINT16 len = sizeof(tBTA_GATTC_API_WRITE) + p_data->len; if (p_data != NULL) { len += p_data->len; } if ((p_buf = (tBTA_GATTC_API_WRITE *) osi_malloc(len)) != NULL) { memset(p_buf, 0, len); p_buf->hdr.event = BTA_GATTC_API_WRITE_EVT; p_buf->hdr.layer_specific = conn_id; p_buf->auth_req = auth_req; p_buf->handle = handle; p_buf->write_type = BTA_GATTC_WRITE_PREPARE; p_buf->offset = offset; if (p_data && p_data->len != 0) { p_buf->len = p_data->len; p_buf->p_value = (UINT8 *)(p_buf + 1); /* pack the descr data */ memcpy(p_buf->p_value, p_data->p_value, p_data->len); } bta_sys_sendmsg(p_buf); } return; }
/******************************************************************************* ** ** Function btc_a2dp_sink_enque_buf ** ** Description This function is called by the av_co to fill A2DP Sink Queue ** ** ** Returns size of the queue *******************************************************************************/ UINT8 btc_a2dp_sink_enque_buf(BT_HDR *p_pkt) { tBT_SBC_HDR *p_msg; if (btc_aa_snk_cb.rx_flush == TRUE) { /* Flush enabled, do not enque*/ return fixed_queue_length(btc_aa_snk_cb.RxSbcQ); } if (fixed_queue_length(btc_aa_snk_cb.RxSbcQ) >= MAX_OUTPUT_A2DP_SNK_FRAME_QUEUE_SZ) { APPL_TRACE_WARNING("Pkt dropped\n"); return fixed_queue_length(btc_aa_snk_cb.RxSbcQ); } APPL_TRACE_DEBUG("btc_a2dp_sink_enque_buf + "); /* allocate and Queue this buffer */ if ((p_msg = (tBT_SBC_HDR *) osi_malloc(sizeof(tBT_SBC_HDR) + p_pkt->offset + p_pkt->len)) != NULL) { memcpy(p_msg, p_pkt, (sizeof(BT_HDR) + p_pkt->offset + p_pkt->len)); p_msg->num_frames_to_be_processed = (*((UINT8 *)(p_msg + 1) + p_msg->offset)) & 0x0f; APPL_TRACE_VERBOSE("btc_a2dp_sink_enque_buf %d + \n", p_msg->num_frames_to_be_processed); fixed_queue_enqueue(btc_aa_snk_cb.RxSbcQ, p_msg); btc_a2dp_sink_data_post(BTC_A2DP_SINK_DATA_EVT); } else { /* let caller deal with a failed allocation */ APPL_TRACE_WARNING("btc_a2dp_sink_enque_buf No Buffer left - "); } return fixed_queue_length(btc_aa_snk_cb.RxSbcQ); }
/******************************************************************************* ** ** Function BTA_GATTC_PrepareWrite ** ** Description This function is called to prepare write a characteristic value. ** ** Parameters conn_id - connection ID. ** p_char_id - GATT characteritic ID of the service. ** offset - offset of the write value. ** len: length of the data to be written. ** p_value - the value to be written. ** ** Returns None ** *******************************************************************************/ void BTA_GATTC_PrepareWrite (UINT16 conn_id, UINT16 handle, UINT16 offset, UINT16 len, UINT8 *p_value, tBTA_GATT_AUTH_REQ auth_req) { tBTA_GATTC_API_WRITE *p_buf; if ((p_buf = (tBTA_GATTC_API_WRITE *) osi_malloc((UINT16)(sizeof(tBTA_GATTC_API_WRITE) + len))) != NULL) { memset(p_buf, 0, sizeof(tBTA_GATTC_API_WRITE) + len); p_buf->hdr.event = BTA_GATTC_API_WRITE_EVT; p_buf->hdr.layer_specific = conn_id; p_buf->auth_req = auth_req; p_buf->handle = handle; p_buf->write_type = BTA_GATTC_WRITE_PREPARE; p_buf->offset = offset; p_buf->len = len; if (p_value && len > 0) { p_buf->p_value = (UINT8 *)(p_buf + 1); memcpy(p_buf->p_value, p_value, len); } bta_sys_sendmsg(p_buf); } return; }
void bta_hf_client_send_at_bia(void) { char *buf; int at_len; int i; APPL_TRACE_DEBUG("%s", __FUNCTION__); if (bta_hf_client_cb.scb.peer_version < HFP_VERSION_1_6) { APPL_TRACE_DEBUG("Remote does not Support AT+BIA"); return; } buf = osi_malloc(BTA_HF_CLIENT_AT_MAX_LEN); if (buf == NULL) { APPL_TRACE_ERROR("No mem %s", __FUNCTION__); return; } at_len = snprintf(buf, BTA_HF_CLIENT_AT_MAX_LEN, "AT+BIA="); for (i = 0; i < BTA_HF_CLIENT_AT_INDICATOR_COUNT; i++) { int sup = bta_hf_client_cb.scb.at_cb.indicator_lookup[i] == -1 ? 0 : 1; at_len += snprintf(buf + at_len, BTA_HF_CLIENT_AT_MAX_LEN - at_len, "%u,", sup); } buf[at_len - 1] = '\r'; bta_hf_client_send_at(BTA_HF_CLIENT_AT_BIA, buf, at_len); osi_free(buf); }
static void bta_hf_client_queue_at(tBTA_HF_CLIENT_AT_CMD cmd, const char *buf, UINT16 buf_len) { tBTA_HF_CLIENT_AT_QCMD *new_cmd; APPL_TRACE_DEBUG("%s", __FUNCTION__); if ((new_cmd = (tBTA_HF_CLIENT_AT_QCMD *) osi_malloc(sizeof(tBTA_HF_CLIENT_AT_QCMD))) != NULL) { new_cmd->cmd = cmd; new_cmd->buf_len = buf_len; new_cmd->next = NULL; memcpy(new_cmd->buf, buf, buf_len); if (bta_hf_client_cb.scb.at_cb.queued_cmd != NULL) { tBTA_HF_CLIENT_AT_QCMD *qcmd = bta_hf_client_cb.scb.at_cb.queued_cmd; while (qcmd->next != NULL) { qcmd = qcmd->next; } qcmd->next = new_cmd; } else { bta_hf_client_cb.scb.at_cb.queued_cmd = new_cmd; } } }
void btc_gattc_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src) { btc_ble_gattc_args_t *dst = (btc_ble_gattc_args_t *) p_dest; btc_ble_gattc_args_t *src = (btc_ble_gattc_args_t *)p_src; switch (msg->act) { case BTC_GATTC_ACT_WRITE_CHAR: { dst->write_char.value = (uint8_t *)osi_malloc(src->write_char.value_len); if (dst->write_char.value) { memcpy(dst->write_char.value, src->write_char.value, src->write_char.value_len); } else { BTC_TRACE_ERROR("%s %d no mem\n", __func__, msg->act); } break; } case BTC_GATTC_ACT_WRITE_CHAR_DESCR: { dst->write_descr.value = (uint8_t *)osi_malloc(src->write_descr.value_len); if (dst->write_descr.value) { memcpy(dst->write_descr.value, src->write_descr.value, src->write_descr.value_len); } else { BTC_TRACE_ERROR("%s %d no mem\n", __func__, msg->act); } break; } case BTC_GATTC_ACT_PREPARE_WRITE: { dst->prep_write.value = (uint8_t *)osi_malloc(src->prep_write.value_len); if (dst->prep_write.value) { memcpy(dst->prep_write.value, src->prep_write.value, src->prep_write.value_len); } else { BTC_TRACE_ERROR("%s %d no mem\n", __func__, msg->act); } break; } case BTC_GATTC_ACT_PREPARE_WRITE_CHAR_DESCR: { dst->prep_write_descr.value = (uint8_t *)osi_malloc(src->prep_write_descr.value_len); if (dst->prep_write_descr.value) { memcpy(dst->prep_write_descr.value, src->prep_write_descr.value, src->prep_write_descr.value_len); } else { BTC_TRACE_ERROR("%s %d no mem\n", __func__, msg->act); } break; } default: BTC_TRACE_DEBUG("%s Unhandled deep copy %d\n", __func__, msg->act); break; } }
/****************************************************************************** ** ** MAIN PARSING FUNCTION ** ** *******************************************************************************/ void bta_hf_client_at_parse(char *buf, unsigned int len) { APPL_TRACE_DEBUG("%s offset: %u len: %u", __FUNCTION__, bta_hf_client_cb.scb.at_cb.offset, len); if (len + bta_hf_client_cb.scb.at_cb.offset > BTA_HF_CLIENT_AT_PARSER_MAX_LEN) { unsigned int tmp = bta_hf_client_cb.scb.at_cb.offset; unsigned int space_left = BTA_HF_CLIENT_AT_PARSER_MAX_LEN - bta_hf_client_cb.scb.at_cb.offset; char *tmp_buff = osi_malloc(BTA_HF_CLIENT_AT_PARSER_MAX_LEN); if (tmp_buff == NULL) { APPL_TRACE_ERROR("No mem %s", __FUNCTION__); return; } APPL_TRACE_DEBUG("%s overrun, trying to recover", __FUNCTION__); /* fill up parser buffer */ memcpy(bta_hf_client_cb.scb.at_cb.buf + bta_hf_client_cb.scb.at_cb.offset, buf, space_left); len -= space_left; buf += space_left; bta_hf_client_cb.scb.at_cb.offset += space_left; /* find end of last complete command before proceeding */ while (bta_hf_client_check_at_complete() == FALSE) { if (bta_hf_client_cb.scb.at_cb.offset == 0) { APPL_TRACE_ERROR("HFPClient: AT parser buffer overrun, disconnecting"); bta_hf_client_at_reset(); bta_hf_client_sm_execute(BTA_HF_CLIENT_API_CLOSE_EVT, NULL); osi_free(tmp_buff); return; } bta_hf_client_cb.scb.at_cb.offset--; } /* cut buffer to complete AT event and keep cut data */ tmp += space_left - bta_hf_client_cb.scb.at_cb.offset; memcpy(tmp_buff, bta_hf_client_cb.scb.at_cb.buf + bta_hf_client_cb.scb.at_cb.offset, tmp); bta_hf_client_cb.scb.at_cb.buf[bta_hf_client_cb.scb.at_cb.offset] = '\0'; /* parse */ bta_hf_client_at_parse_start(); bta_hf_client_at_clear_buf(); /* recover cut data */ memcpy(bta_hf_client_cb.scb.at_cb.buf, tmp_buff, tmp); bta_hf_client_cb.scb.at_cb.offset += tmp; osi_free(tmp_buff); } memcpy(bta_hf_client_cb.scb.at_cb.buf + bta_hf_client_cb.scb.at_cb.offset, buf, len); bta_hf_client_cb.scb.at_cb.offset += len; /* If last event is complete, parsing can be started */ if (bta_hf_client_check_at_complete() == TRUE) { bta_hf_client_at_parse_start(); bta_hf_client_at_clear_buf(); } }
/******************************************************************************* ** ** Function sdp_init ** ** Description This function initializes the SDP unit. ** ** Returns void ** *******************************************************************************/ void sdp_init (void) { #if SDP_DYNAMIC_MEMORY sdp_cb_ptr = (tSDP_CB *)osi_malloc(sizeof(tSDP_CB)); #endif /* #if SDP_DYNAMIC_MEMORY */ /* Clears all structures and local SDP database (if Server is enabled) */ memset (&sdp_cb, 0, sizeof (tSDP_CB)); /* Initialize the L2CAP configuration. We only care about MTU and flush */ sdp_cb.l2cap_my_cfg.mtu_present = TRUE; sdp_cb.l2cap_my_cfg.mtu = SDP_MTU_SIZE; sdp_cb.l2cap_my_cfg.flush_to_present = TRUE; sdp_cb.l2cap_my_cfg.flush_to = SDP_FLUSH_TO; sdp_cb.max_attr_list_size = SDP_MTU_SIZE - 16; sdp_cb.max_recs_per_search = SDP_MAX_DISC_SERVER_RECS; #if SDP_SERVER_ENABLED == TRUE /* Register with Security Manager for the specific security level */ if (!BTM_SetSecurityLevel (FALSE, SDP_SERVICE_NAME, BTM_SEC_SERVICE_SDP_SERVER, SDP_SECURITY_LEVEL, SDP_PSM, 0, 0)) { SDP_TRACE_ERROR ("Security Registration Server failed\n"); return; } #endif #if SDP_CLIENT_ENABLED == TRUE /* Register with Security Manager for the specific security level */ if (!BTM_SetSecurityLevel (TRUE, SDP_SERVICE_NAME, BTM_SEC_SERVICE_SDP_SERVER, SDP_SECURITY_LEVEL, SDP_PSM, 0, 0)) { SDP_TRACE_ERROR ("Security Registration for Client failed\n"); return; } #endif #if defined(SDP_INITIAL_TRACE_LEVEL) sdp_cb.trace_level = SDP_INITIAL_TRACE_LEVEL; #else sdp_cb.trace_level = BT_TRACE_LEVEL_NONE; /* No traces */ #endif sdp_cb.reg_info.pL2CA_ConnectInd_Cb = sdp_connect_ind; sdp_cb.reg_info.pL2CA_ConnectCfm_Cb = sdp_connect_cfm; sdp_cb.reg_info.pL2CA_ConnectPnd_Cb = NULL; sdp_cb.reg_info.pL2CA_ConfigInd_Cb = sdp_config_ind; sdp_cb.reg_info.pL2CA_ConfigCfm_Cb = sdp_config_cfm; sdp_cb.reg_info.pL2CA_DisconnectInd_Cb = sdp_disconnect_ind; sdp_cb.reg_info.pL2CA_DisconnectCfm_Cb = sdp_disconnect_cfm; sdp_cb.reg_info.pL2CA_QoSViolationInd_Cb = NULL; sdp_cb.reg_info.pL2CA_DataInd_Cb = sdp_data_ind; sdp_cb.reg_info.pL2CA_CongestionStatus_Cb = NULL; sdp_cb.reg_info.pL2CA_TxComplete_Cb = NULL; /* Now, register with L2CAP */ if (!L2CA_Register (SDP_PSM, &sdp_cb.reg_info)) { SDP_TRACE_ERROR ("SDP Registration failed\n"); } }
/****************************************************************************** ** ** Function avrc_send_continue_frag ** ** Description This function sends a continue response fragment ** ** Returns Nothing. ** ******************************************************************************/ static void avrc_send_continue_frag(UINT8 handle, UINT8 label) { tAVRC_FRAG_CB *p_fcb; BT_HDR *p_pkt_old, *p_pkt; UINT8 *p_old, *p_data; UINT8 cr = AVCT_RSP; tAVRC_RSP rej_rsp; p_fcb = &avrc_cb.fcb[handle]; p_pkt = p_fcb->p_fmsg; AVRC_TRACE_DEBUG("%s handle = %u label = %u len = %d", __func__, handle, label, p_pkt->len); if (p_pkt->len > AVRC_MAX_CTRL_DATA_LEN) { int offset_len = MAX(AVCT_MSG_OFFSET, p_pkt->offset); p_pkt_old = p_fcb->p_fmsg; p_pkt = (BT_HDR *)osi_malloc((UINT16)(AVRC_PACKET_LEN + offset_len + BT_HDR_SIZE)); if (p_pkt) { p_pkt->len = AVRC_MAX_CTRL_DATA_LEN; p_pkt->offset = AVCT_MSG_OFFSET; p_pkt->layer_specific = p_pkt_old->layer_specific; p_pkt->event = p_pkt_old->event; p_old = (UINT8 *)(p_pkt_old + 1) + p_pkt_old->offset; p_data = (UINT8 *)(p_pkt + 1) + p_pkt->offset; memcpy (p_data, p_old, AVRC_MAX_CTRL_DATA_LEN); /* use AVRC continue packet type */ p_data += AVRC_VENDOR_HDR_SIZE; p_data++; /* pdu */ *p_data++ = AVRC_PKT_CONTINUE; /* 4=pdu, pkt_type & len */ UINT16_TO_BE_STREAM(p_data, (AVRC_MAX_CTRL_DATA_LEN - AVRC_VENDOR_HDR_SIZE - 4)); /* prepare the left over for as an end fragment */ avrc_prep_end_frag (handle); } else { /* use the current GKI buffer to send Internal error status */ p_pkt = p_fcb->p_fmsg; p_fcb->p_fmsg = NULL; p_fcb->frag_enabled = FALSE; AVRC_TRACE_ERROR ("AVRC_MsgReq no buffers for fragmentation - send internal error" ); p_data = (UINT8 *)(p_pkt + 1) + p_pkt->offset; *p_data++ = AVRC_PDU_REQUEST_CONTINUATION_RSP; *p_data++ = 0; UINT16_TO_BE_STREAM(p_data, 0); p_pkt->len = 4; rej_rsp.pdu = AVRC_PDU_REQUEST_CONTINUATION_RSP; rej_rsp.status = AVRC_STS_INTERNAL_ERR; AVRC_BldResponse( handle, (tAVRC_RESPONSE *)&rej_rsp, &p_pkt); cr = AVCT_RSP; } } else { /* end fragment. clean the control block */ p_fcb->frag_enabled = FALSE; p_fcb->p_fmsg = NULL; } AVCT_MsgReq( handle, label, cr, p_pkt); }
static void btc_gattc_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src) { tBTA_GATTC *p_dest_data = (tBTA_GATTC *) p_dest; tBTA_GATTC *p_src_data = (tBTA_GATTC *) p_src; if (!p_src_data || !p_dest_data) { return; } // Allocate buffer for request data if necessary switch (msg->act) { case BTA_GATTC_READ_DESCR_EVT: case BTA_GATTC_READ_CHAR_EVT: case BTA_GATTC_READ_MULTIPLE_EVT: { if (p_src_data->read.p_value && p_src_data->read.p_value->p_value) { p_dest_data->read.p_value = (tBTA_GATT_UNFMT *)osi_malloc(sizeof(tBTA_GATT_UNFMT) + p_src_data->read.p_value->len); p_dest_data->read.p_value->p_value = (uint8_t *)(p_dest_data->read.p_value + 1); if (p_dest_data->read.p_value && p_dest_data->read.p_value->p_value) { p_dest_data->read.p_value->len = p_src_data->read.p_value->len; memcpy(p_dest_data->read.p_value->p_value, p_src_data->read.p_value->p_value, p_src_data->read.p_value->len); } else { BTC_TRACE_ERROR("%s %d no mem\n", __func__, msg->act); } } break; } case BTA_GATTC_GET_ADDR_LIST_EVT: { if (p_src_data->get_addr_list.bda_list != NULL) { uint8_t num_addr = p_src_data->get_addr_list.num_addr; p_dest_data->get_addr_list.bda_list = (BD_ADDR *)osi_malloc(sizeof(BD_ADDR) * num_addr); if (p_dest_data->get_addr_list.bda_list) { memcpy(p_dest_data->get_addr_list.bda_list, p_src_data->get_addr_list.bda_list, sizeof(BD_ADDR) * num_addr); } else { BTC_TRACE_ERROR("%s %d no mem\n", __func__, msg->act); } } break; } default: break; } }
/******************************************************************************* ** ** Function BTA_GATTC_AppDeregister ** ** Description This function is called to deregister an application ** from BTA GATTC module. ** ** Parameters client_if - client interface identifier. ** ** Returns None ** *******************************************************************************/ void BTA_GATTC_AppDeregister(tBTA_GATTC_IF client_if) { tBTA_GATTC_API_DEREG *p_buf; if ((p_buf = (tBTA_GATTC_API_DEREG *) osi_malloc(sizeof(tBTA_GATTC_API_DEREG))) != NULL) { p_buf->hdr.event = BTA_GATTC_API_DEREG_EVT; p_buf->client_if = client_if; bta_sys_sendmsg(p_buf); } return; }
void BTA_GATTC_CacheGetAddrList(tBTA_GATTC_IF client_if) { tBTA_GATTC_API_GET_ADDR *p_buf; if ((p_buf = (tBTA_GATTC_API_GET_ADDR *)osi_malloc(sizeof(tBTA_GATTC_API_GET_ADDR))) != NULL) { p_buf->hdr.event = BTA_GATTC_API_CACHE_GET_ADDR_LIST_EVT; p_buf->client_if = client_if; bta_sys_sendmsg(p_buf); } return; }
/******************************************************************************* ** ** Function BTA_GATTC_ConfigureMTU ** ** Description Configure the MTU size in the GATT channel. This can be done ** only once per connection. ** ** Parameters conn_id: connection ID. ** mtu: desired MTU size to use. ** ** Returns void ** *******************************************************************************/ void BTA_GATTC_ConfigureMTU (UINT16 conn_id) { tBTA_GATTC_API_CFG_MTU *p_buf; if ((p_buf = (tBTA_GATTC_API_CFG_MTU *) osi_malloc(sizeof(tBTA_GATTC_API_CFG_MTU))) != NULL) { p_buf->hdr.event = BTA_GATTC_API_CFG_MTU_EVT; p_buf->hdr.layer_specific = conn_id; bta_sys_sendmsg(p_buf); } return; }
/******************************************************************************* ** ** Function BTA_GATTC_Broadcast ** ** Description Start broadcasting (non-connectable advertisements) ** ** Parameters client_if: client interface. ** start: to start or stop listening for connection ** ** Returns void ** *******************************************************************************/ void BTA_GATTC_Broadcast(tBTA_GATTC_IF client_if, BOOLEAN start) { tBTA_GATTC_API_LISTEN *p_buf; if ((p_buf = (tBTA_GATTC_API_LISTEN *) osi_malloc((UINT16)(sizeof(tBTA_GATTC_API_LISTEN) + BD_ADDR_LEN))) != NULL) { p_buf->hdr.event = BTA_GATTC_API_BROADCAST_EVT; p_buf->client_if = client_if; p_buf->start = start; bta_sys_sendmsg(p_buf); } return; }
static void set_module_state(const module_t *module, module_state_t state) { pthread_mutex_lock(&metadata_lock); module_state_t *state_ptr = hash_map_get(metadata, module); if (!state_ptr) { state_ptr = osi_malloc(sizeof(module_state_t)); hash_map_set(metadata, module, state_ptr); } pthread_mutex_unlock(&metadata_lock); *state_ptr = state; }
/******************************************************************************* ** ** Function bta_hf_client_do_disc ** ** Description Do service discovery. ** ** ** Returns void ** *******************************************************************************/ void bta_hf_client_do_disc(void) { tSDP_UUID uuid_list[2]; UINT16 num_uuid = 1; UINT16 attr_list[4]; UINT8 num_attr; BOOLEAN db_inited = FALSE; /* initiator; get proto list and features */ if (bta_hf_client_cb.scb.role == BTA_HF_CLIENT_INT) { attr_list[0] = ATTR_ID_SERVICE_CLASS_ID_LIST; attr_list[1] = ATTR_ID_PROTOCOL_DESC_LIST; attr_list[2] = ATTR_ID_BT_PROFILE_DESC_LIST; attr_list[3] = ATTR_ID_SUPPORTED_FEATURES; num_attr = 4; uuid_list[0].uu.uuid16 = UUID_SERVCLASS_AG_HANDSFREE; } /* acceptor; get features */ else { attr_list[0] = ATTR_ID_SERVICE_CLASS_ID_LIST; attr_list[1] = ATTR_ID_BT_PROFILE_DESC_LIST; attr_list[2] = ATTR_ID_SUPPORTED_FEATURES; num_attr = 3; uuid_list[0].uu.uuid16 = UUID_SERVCLASS_AG_HANDSFREE; } /* allocate buffer for sdp database */ bta_hf_client_cb.scb.p_disc_db = (tSDP_DISCOVERY_DB *) osi_malloc(BT_DEFAULT_BUFFER_SIZE); if (bta_hf_client_cb.scb.p_disc_db) { /* set up service discovery database; attr happens to be attr_list len */ uuid_list[0].len = LEN_UUID_16; uuid_list[1].len = LEN_UUID_16; db_inited = SDP_InitDiscoveryDb(bta_hf_client_cb.scb.p_disc_db, BT_DEFAULT_BUFFER_SIZE, num_uuid, uuid_list, num_attr, attr_list); } if (db_inited) { /*Service discovery not initiated */ db_inited = SDP_ServiceSearchAttributeRequest(bta_hf_client_cb.scb.peer_addr, bta_hf_client_cb.scb.p_disc_db, bta_hf_client_sdp_cback); } if (!db_inited) { /*free discover db */ bta_hf_client_free_db(NULL); /* sent failed event */ bta_hf_client_sm_execute(BTA_HF_CLIENT_DISC_FAIL_EVT, NULL); } }
static void btc_a2dp_sink_ctrl_post(uint32_t sig, void *par) { BtTaskEvt_t *evt = (BtTaskEvt_t *)osi_malloc(sizeof(BtTaskEvt_t)); if (evt == NULL) { return; } evt->sig = sig; evt->par = par; if (xQueueSend(btc_aa_snk_ctrl_queue, &evt, portMAX_DELAY) != pdTRUE) { APPL_TRACE_WARNING("btc_aa_snk_ctrl_queue failed, sig 0x%x\n", sig); } }
/******************************************************************************* ** ** Function BTA_GATTC_Close ** ** Description Close a connection to a GATT server. ** ** Parameters conn_id: connection ID to be closed. ** ** Returns void ** *******************************************************************************/ void BTA_GATTC_Close(UINT16 conn_id) { BT_HDR *p_buf; if ((p_buf = (BT_HDR *) osi_malloc(sizeof(BT_HDR))) != NULL) { p_buf->event = BTA_GATTC_API_CLOSE_EVT; p_buf->layer_specific = conn_id; bta_sys_sendmsg(p_buf); } return; }
/******************************************************************************* ** ** Function bta_gattc_ci_cache_open ** ** Description This function sends an event to indicate server cache open ** completed. ** ** Parameters server_bda - server BDA of this cache. ** status - BTA_GATT_OK if full buffer of data, ** BTA_GATT_FAIL if an error has occurred. ** ** Returns void ** *******************************************************************************/ void bta_gattc_ci_cache_open(BD_ADDR server_bda, UINT16 evt, tBTA_GATT_STATUS status, UINT16 conn_id) { tBTA_GATTC_CI_EVT *p_evt; UNUSED(server_bda); if ((p_evt = (tBTA_GATTC_CI_EVT *) osi_malloc(sizeof(tBTA_GATTC_CI_EVT))) != NULL) { p_evt->hdr.event = evt; p_evt->hdr.layer_specific = conn_id; p_evt->status = status; bta_sys_sendmsg(p_evt); } }
/******************************************************************************* ** ** Function BTA_GATTC_CancelOpen ** ** Description Cancel a direct open connection or remove a background auto connection ** bd address ** ** Parameters client_if: server interface. ** remote_bda: remote device BD address. ** is_direct: direct connection or background auto connection ** ** Returns void ** *******************************************************************************/ void BTA_GATTC_CancelOpen(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, BOOLEAN is_direct) { tBTA_GATTC_API_CANCEL_OPEN *p_buf; if ((p_buf = (tBTA_GATTC_API_CANCEL_OPEN *) osi_malloc(sizeof(tBTA_GATTC_API_CANCEL_OPEN))) != NULL) { p_buf->hdr.event = BTA_GATTC_API_CANCEL_OPEN_EVT; p_buf->client_if = client_if; p_buf->is_direct = is_direct; memcpy(p_buf->remote_bda, remote_bda, BD_ADDR_LEN); bta_sys_sendmsg(p_buf); } return; }
void bta_hf_client_send_at_binp(UINT32 action) { char *buf = osi_malloc(BTA_HF_CLIENT_AT_MAX_LEN); int at_len; if (buf == NULL) { APPL_TRACE_ERROR("No mem %s", __FUNCTION__); return; } at_len = snprintf(buf, BTA_HF_CLIENT_AT_MAX_LEN, "AT+BINP=%u\r", action); bta_hf_client_send_at(BTA_HF_CLIENT_AT_BINP, buf, at_len); osi_free(buf); }
void bta_hf_client_send_at_vts(char code) { char *buf = osi_malloc(BTA_HF_CLIENT_AT_MAX_LEN); int at_len; if (buf == NULL) { APPL_TRACE_ERROR("No mem %s", __FUNCTION__); return; } APPL_TRACE_DEBUG("%s", __FUNCTION__); at_len = snprintf(buf, BTA_HF_CLIENT_AT_MAX_LEN, "AT+VTS=%c\r", code); bta_hf_client_send_at(BTA_HF_CLIENT_AT_VTS, buf, at_len); osi_free(buf); }
/******************************************************************************* ** ** Function BTA_GATTC_Disable ** ** Description This function is called to disable GATTC module ** ** Parameters None. ** ** Returns None ** *******************************************************************************/ void BTA_GATTC_Disable(void) { BT_HDR *p_buf; if (bta_sys_is_register(BTA_ID_GATTC) == FALSE) { APPL_TRACE_WARNING("GATTC Module not enabled/already disabled\n"); return; } if ((p_buf = (BT_HDR *) osi_malloc(sizeof(BT_HDR))) != NULL) { p_buf->event = BTA_GATTC_API_DISABLE_EVT; bta_sys_sendmsg(p_buf); } bta_sys_deregister(BTA_ID_GATTC); }
static void btu_bta_alarm_process(TIMER_LIST_ENT *p_tle) { // call timer callback if (p_tle->p_cback) { (*p_tle->p_cback)(p_tle); } else if (p_tle->event) { BT_HDR *p_msg; if ((p_msg = (BT_HDR *) osi_malloc(sizeof(BT_HDR))) != NULL) { p_msg->event = p_tle->event; p_msg->layer_specific = 0; //osi_free(p_msg); bta_sys_sendmsg(p_msg); } } }