Esempio n. 1
0
void sdp_query_rfcomm_init(){
    // init
    de_state_init(&de_header_state);
    de_state_init(&sn_de_header_state);
    pdl_state = GET_PROTOCOL_LIST_LENGTH;
    protocol_offset = 0;
    sdp_parser_register_callback(handle_sdp_parser_event);
}
Esempio n. 2
0
void sdp_query_rfcomm_init(void){
    // init
    de_state_init(&de_header_state);
    de_state_init(&sn_de_header_state);
    pdl_state = GET_PROTOCOL_LIST_LENGTH;
    protocol_offset = 0;
    sdp_parser_register_callback(handle_sdp_parser_event);
    sdp_rfcomm_channel_nr = 0;
    sdp_service_name[0] = 0;
}
Esempio n. 3
0
void sdp_parser_init_service_attribute_search(void) {
    // init
    de_state_init(&de_header_state);
    state = GET_RECORD_LENGTH;
    list_offset = 0;
    record_offset = 0;
    record_counter = 0;
}
Esempio n. 4
0
void sdp_parser_init(void) {
    // init
    de_state_init(&de_header_state);
    state = GET_LIST_LENGTH;
    list_offset = 0;
    record_offset = 0;
    record_counter = 0;
}
Esempio n. 5
0
void sdp_parser_init(btstack_packet_handler_t callback){
    // init
    sdp_parser_callback = callback;
    de_state_init(&de_header_state);
    state = GET_LIST_LENGTH;
    list_offset = 0;
    record_offset = 0;
    record_counter = 0;
}
Esempio n. 6
0
void parse(uint8_t eventByte) {
    // count all bytes
    list_offset++;
    record_offset++;

    // log_info(" parse BYTE_RECEIVED %02x", eventByte);
    switch(state) {
    case GET_LIST_LENGTH:
        if (!de_state_size(eventByte, &de_header_state)) break;
        list_offset = de_header_state.de_offset;
        list_size = de_header_state.de_size;
        // log_info("parser: List offset %u, list size %u", list_offset, list_size);

        record_counter = 0;
        state = GET_RECORD_LENGTH;
        break;

    case GET_RECORD_LENGTH:
        // check size
        if (!de_state_size(eventByte, &de_header_state)) break;
        // log_info("parser: Record payload is %d bytes.", de_header_state.de_size);
        record_offset = de_header_state.de_offset;
        record_size = de_header_state.de_size;
        state = GET_ATTRIBUTE_ID_HEADER_LENGTH;
        break;

    case GET_ATTRIBUTE_ID_HEADER_LENGTH:
        if (!de_state_size(eventByte, &de_header_state)) break;
        attribute_id = 0;
        log_info("ID data is stored in %d bytes.", (int) de_header_state.de_size);
        state = GET_ATTRIBUTE_ID;
        break;

    case GET_ATTRIBUTE_ID:
        attribute_id = (attribute_id << 8) | eventByte;
        de_header_state.de_size--;
        if (de_header_state.de_size > 0) break;
        log_info("parser: Attribute ID: %04x.", attribute_id);

        state = GET_ATTRIBUTE_VALUE_LENGTH;
        attribute_bytes_received  = 0;
        attribute_bytes_delivered = 0;
        attribute_value_size      = 0;
        de_state_init(&de_header_state);
        break;

    case GET_ATTRIBUTE_VALUE_LENGTH:
        attribute_bytes_received++;
        {
            sdp_query_attribute_value_event_t attribute_value_event = {
                SDP_QUERY_ATTRIBUTE_VALUE,
                record_counter,
                attribute_id,
                attribute_value_size,
                attribute_bytes_delivered++,
                eventByte
            };
            (*sdp_query_callback)((sdp_query_event_t*)&attribute_value_event);
        }
        if (!de_state_size(eventByte, &de_header_state)) break;

        attribute_value_size = de_header_state.de_size + attribute_bytes_received;

        state = GET_ATTRIBUTE_VALUE;
        break;

    case GET_ATTRIBUTE_VALUE:
        attribute_bytes_received++;
        {
            sdp_query_attribute_value_event_t attribute_value_event = {
                SDP_QUERY_ATTRIBUTE_VALUE,
                record_counter,
                attribute_id,
                attribute_value_size,
                attribute_bytes_delivered++,
                eventByte
            };

            (*sdp_query_callback)((sdp_query_event_t*)&attribute_value_event);
        }
        // log_info("paser: attribute_bytes_received %u, attribute_value_size %u", attribute_bytes_received, attribute_value_size);

        if (attribute_bytes_received < attribute_value_size) break;
        // log_info("parser: Record offset %u, record size %u", record_offset, record_size);
        if (record_offset != record_size) {
            state = GET_ATTRIBUTE_ID_HEADER_LENGTH;
            // log_info("Get next attribute");
            break;
        }
        record_offset = 0;
        // log_info("parser: List offset %u, list size %u", list_offset, list_size);

        if (list_size > 0 && list_offset != list_size) {
            record_counter++;
            state = GET_RECORD_LENGTH;
            log_info("parser: END_OF_RECORD");
            break;
        }
        list_offset = 0;
        de_state_init(&de_header_state);
        state = GET_LIST_LENGTH;
        record_counter = 0;
        log_info("parser: END_OF_RECORD & DONE");
        break;
    default:
        break;
    }
}