Ejemplo n.º 1
0
Archivo: att.c Proyecto: 13hoop/limo
//
// MARK: ATT_READ_BLOB_REQUEST 0x0c
//
static uint16_t handle_read_blob_request2(uint8_t * response_buffer, uint16_t response_buffer_size, uint16_t handle, uint16_t value_offset){
    printf("ATT_READ_BLOB_REQUEST: handle %04x, offset %u\n", handle, value_offset);

    att_iterator_t it;
    int ok = att_find_handle(&it, handle);
    if (!ok){
        return setup_error_atribute_not_found(response_buffer, ATT_READ_BLOB_REQUEST, handle);
    }
    
    att_update_value_len(&it);

    if (value_offset >= it.value_len){
        return setup_error_invalid_offset(response_buffer, ATT_READ_BLOB_REQUEST, handle);
    }
    
    // limit data
    uint16_t offset   = 1;
    if (offset + it.value_len - value_offset > response_buffer_size) {
        it.value_len = response_buffer_size - 1 + value_offset;
    }
    
    // store
    uint16_t bytes_copied = att_copy_value(&it, value_offset, response_buffer + offset, it.value_len - value_offset);
    offset += bytes_copied;
    
    response_buffer[0] = ATT_READ_BLOB_RESPONSE;
    return offset;
}
Ejemplo n.º 2
0
//
// MARK: ATT_READ_BLOB_REQUEST 0x0c
//
static uint16_t handle_read_blob_request2(att_connection_t * att_connection, uint8_t * response_buffer, uint16_t response_buffer_size, uint16_t handle, uint16_t value_offset){
    log_info("ATT_READ_BLOB_REQUEST: handle %04x, offset %u", handle, value_offset);
    uint8_t request_type = ATT_READ_BLOB_REQUEST;

    att_iterator_t it;
    int ok = att_find_handle(&it, handle);
    if (!ok){
        return setup_error_invalid_handle(response_buffer, request_type, handle);
    }
    
    // check if handle can be read
    if ((it.flags & ATT_PROPERTY_READ) == 0) {
        return setup_error_read_not_permitted(response_buffer, request_type, handle);
    }

    // check security requirements
    uint8_t error_code = att_validate_security(att_connection, &it);
    if (error_code) {
        return setup_error(response_buffer, request_type, handle, error_code);
    }

    att_update_value_len(&it, att_connection->con_handle);

    if (value_offset > it.value_len){
        return setup_error_invalid_offset(response_buffer, request_type, handle);
    }
    
    // limit data
    uint16_t offset   = 1;
    if (offset + it.value_len - value_offset > response_buffer_size) {
        it.value_len = response_buffer_size - 1 + value_offset;
    }
    
    // store
    uint16_t bytes_copied = att_copy_value(&it, value_offset, response_buffer + offset, it.value_len - value_offset, att_connection->con_handle);
    offset += bytes_copied;
    
    response_buffer[0] = ATT_READ_BLOB_RESPONSE;
    return offset;
}