/******************************************************************************* ** ** Function gatt_process_prep_write_rsp ** ** Description This function is called to handle the read response ** ** ** Returns void ** *******************************************************************************/ void gatt_process_prep_write_rsp (tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb, UINT8 op_code, UINT16 len, UINT8 *p_data) { tGATT_VALUE value = {0}; UINT8 *p= p_data; GATT_TRACE_ERROR2("value resp op_code = %s len = %d", gatt_dbg_op_name(op_code), len); STREAM_TO_UINT16 (value.handle, p); STREAM_TO_UINT16 (value.offset, p); value.len = len - 4; memcpy (value.value, p, value.len); if (p_clcb->op_subtype == GATT_WRITE_PREPARE) { p_clcb->status = GATT_SUCCESS; /* application should verify handle offset and value are matched or not */ gatt_end_operation(p_clcb, p_clcb->status, &value); } else if (p_clcb->op_subtype == GATT_WRITE ) { if (!gatt_check_write_long_terminate(p_tcb, p_clcb, &value)) gatt_send_prepare_write(p_tcb, p_clcb); } }
/******************************************************************************* ** ** Function gatt_send_srv_chg_ind ** ** Description This function is called to send a service chnaged indication to ** the specified bd address ** ** Returns void ** *******************************************************************************/ void gatt_send_srv_chg_ind (BD_ADDR peer_bda) { UINT8 handle_range[GATT_SIZE_OF_SRV_CHG_HNDL_RANGE]; UINT8 *p = handle_range; UINT16 conn_id; GATT_TRACE_DEBUG0("gatt_send_srv_chg_ind"); if (gatt_cb.handle_of_h_r) { if ((conn_id = gatt_profile_find_conn_id_by_bd_addr(peer_bda)) != GATT_INVALID_CONN_ID) { UINT16_TO_STREAM (p, 1); UINT16_TO_STREAM (p, 0xFFFF); GATTS_HandleValueIndication (conn_id, gatt_cb.handle_of_h_r, GATT_SIZE_OF_SRV_CHG_HNDL_RANGE, handle_range); } else { GATT_TRACE_ERROR2("Unable to find conn_id for %08x%04x ", (peer_bda[0]<<24)+(peer_bda[1]<<16)+(peer_bda[2]<<8)+peer_bda[3], (peer_bda[4]<<8)+peer_bda[5] ); } } }
/******************************************************************************* ** ** Function gatt_process_read_rsp ** ** Description This function is called to handle the read BLOB response ** ** ** Returns void ** *******************************************************************************/ void gatt_process_read_rsp(tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb, UINT8 op_code, UINT16 len, UINT8 *p_data) { UINT16 offset = p_clcb->counter; UINT8 * p= p_data; if (p_clcb->operation == GATTC_OPTYPE_READ) { if (p_clcb->op_subtype != GATT_READ_BY_HANDLE) { p_clcb->counter = len; gatt_end_operation(p_clcb, GATT_SUCCESS, (void *)p); } else { /* allocate GKI buffer holding up long attribute value */ if (!p_clcb->p_attr_buf) p_clcb->p_attr_buf = (UINT8 *)GKI_getbuf(GATT_MAX_ATTR_LEN); /* copy attrobute value into cb buffer */ if (p_clcb->p_attr_buf && offset < GATT_MAX_ATTR_LEN) { if ((len + offset) > GATT_MAX_ATTR_LEN) len = GATT_MAX_ATTR_LEN - offset; p_clcb->counter += len; memcpy(p_clcb->p_attr_buf + offset, p, len); /* send next request if needed */ if (len == (p_tcb->payload_size - 1) && /* full packet for read or read blob rsp */ len + offset < GATT_MAX_ATTR_LEN) { GATT_TRACE_DEBUG3("full pkt issue read blob for remianing bytes old offset=%d len=%d new offset=%d", offset, len, p_clcb->counter); gatt_act_read(p_clcb, p_clcb->counter); } else /* end of request, send callback */ { gatt_end_operation(p_clcb, GATT_SUCCESS, (void *)p_clcb->p_attr_buf); } } else /* exception, should not happen */ { GATT_TRACE_ERROR2("attr offset = %d p_attr_buf = %d ", offset, p_clcb->p_attr_buf); gatt_end_operation(p_clcb, GATT_NO_RESOURCES, (void *)p_clcb->p_attr_buf); } } } else { if (p_clcb->operation == GATTC_OPTYPE_DISCOVERY && p_clcb->op_subtype == GATT_DISC_INC_SRVC && p_clcb->read_uuid128.wait_for_read_rsp ) { p_clcb->s_handle = p_clcb->read_uuid128.next_disc_start_hdl; p_clcb->read_uuid128.wait_for_read_rsp = FALSE; if (len == LEN_UUID_128) { memcpy(p_clcb->read_uuid128.result.value.incl_service.service_type.uu.uuid128, p, len); p_clcb->read_uuid128.result.value.incl_service.service_type.len = LEN_UUID_128; if ( p_clcb->p_reg->app_cb.p_disc_res_cb) (*p_clcb->p_reg->app_cb.p_disc_res_cb)(p_clcb->conn_id, p_clcb->op_subtype, &p_clcb->read_uuid128.result); gatt_act_discovery(p_clcb) ; } else { gatt_end_operation(p_clcb, GATT_INVALID_PDU, (void *)p); } } } }