AllJoyn/Samples/BACnetAdapter/bacnet-stack-0.8.2/src/bacapp.c
int bacapp_data_len(
    uint8_t * apdu,
    unsigned max_apdu_len,
    BACNET_PROPERTY_ID property)
{
    int len = 0;
    int total_len = 0;
    int apdu_len = 0;
    uint8_t tag_number = 0;
    uint8_t opening_tag_number = 0;
    uint8_t opening_tag_number_counter = 0;
    uint32_t value = 0;

    if (IS_OPENING_TAG(apdu[0])) {
        len =
            decode_tag_number_and_value(&apdu[apdu_len], &tag_number, &value);
        apdu_len += len;
        opening_tag_number = tag_number;
        opening_tag_number_counter = 1;
        while (opening_tag_number_counter) {
            if (IS_OPENING_TAG(apdu[apdu_len])) {
                len =
                    decode_tag_number_and_value(&apdu[apdu_len], &tag_number,
                    &value);
                if (tag_number == opening_tag_number)
                    opening_tag_number_counter++;
            } else if (IS_CLOSING_TAG(apdu[apdu_len])) {
                len =
                    decode_tag_number_and_value(&apdu[apdu_len], &tag_number,
                    &value);
                if (tag_number == opening_tag_number)
                    opening_tag_number_counter--;
            } else if (IS_CONTEXT_SPECIFIC(apdu[apdu_len])) {
                /* context-specific tagged data */
                len =
                    bacapp_decode_context_data_len(&apdu[apdu_len],
                    max_apdu_len - apdu_len, property);
            } else {
                /* application tagged data */
                len =
                    bacapp_decode_application_data_len(&apdu[apdu_len],
                    max_apdu_len - apdu_len);
            }
            apdu_len += len;
            if (opening_tag_number_counter) {
                if (len > 0) {
                    total_len += len;
                } else {
                    /* error: len is not incrementing */
                    total_len = BACNET_STATUS_ERROR;
                    break;
                }
            }
            if ((unsigned) apdu_len > max_apdu_len) {
                /* error: exceeding our buffer limit */
                total_len = BACNET_STATUS_ERROR;
                break;
            }
        }
    }

    return total_len;
}
/* returns the length of data between an opening tag and a closing tag.
   Expects that the first octet contain the opening tag.
   Include a value property identifier for context specific data
   such as the value received in a WriteProperty request */
returns the length of data between an opening tag and a closing tag.
Expects that the first octet contain the opening tag.
Include a value property identifier for context specific data
such as the value received in a WriteProperty request
returns the length of data between an opening tag and a closing tag . Expects that the first octet contain the opening tag . Include a value property identifier for context specific data such as the value received in a WriteProperty request
int bacapp_data_len(
    uint8_t * apdu,
    unsigned max_apdu_len,
    BACNET_PROPERTY_ID property)
{
    int len = 0;
    int total_len = 0;
    int apdu_len = 0;
    uint8_t tag_number = 0;
    uint8_t opening_tag_number = 0;
    uint8_t opening_tag_number_counter = 0;
    uint32_t value = 0;
    if (IS_OPENING_TAG(apdu[0])) {
        len =
            decode_tag_number_and_value(&apdu[apdu_len], &tag_number, &value);
        apdu_len += len;
        opening_tag_number = tag_number;
        opening_tag_number_counter = 1;
        while (opening_tag_number_counter) {
            if (IS_OPENING_TAG(apdu[apdu_len])) {
                len =
                    decode_tag_number_and_value(&apdu[apdu_len], &tag_number,
                    &value);
                if (tag_number == opening_tag_number)
                    opening_tag_number_counter++;
            } else if (IS_CLOSING_TAG(apdu[apdu_len])) {
                len =
                    decode_tag_number_and_value(&apdu[apdu_len], &tag_number,
                    &value);
                if (tag_number == opening_tag_number)
                    opening_tag_number_counter--;
            } else if (IS_CONTEXT_SPECIFIC(apdu[apdu_len])) {
                len =
                    bacapp_decode_context_data_len(&apdu[apdu_len],
                    max_apdu_len - apdu_len, property);
            } else {
                len =
                    bacapp_decode_application_data_len(&apdu[apdu_len],
                    max_apdu_len - apdu_len);
            }
            apdu_len += len;
            if (opening_tag_number_counter) {
                if (len > 0) {
                    total_len += len;
                } else {
                    total_len = BACNET_STATUS_ERROR;
                    break;
                }
            }
            if ((unsigned) apdu_len > max_apdu_len) {
                total_len = BACNET_STATUS_ERROR;
                break;
            }
        }
    }
    return total_len;
}
int bacapp_data_len ( uint8_t * apdu , unsigned max_apdu_len , BACNET_PROPERTY_ID property ) { int len = 0 ; int total_len = 0 ; int apdu_len = 0 ; uint8_t tag_number = 0 ; uint8_t opening_tag_number = 0 ; uint8_t opening_tag_number_counter = 0 ; uint32_t value = 0 ; if ( IS_OPENING_TAG ( apdu [ 0 ] ) ) { len = decode_tag_number_and_value ( & apdu [ apdu_len ] , & tag_number , & value ) ; apdu_len += len ; opening_tag_number = tag_number ; opening_tag_number_counter = 1 ; while ( opening_tag_number_counter ) { if ( IS_OPENING_TAG ( apdu [ apdu_len ] ) ) { len = decode_tag_number_and_value ( & apdu [ apdu_len ] , & tag_number , & value ) ; if ( tag_number == opening_tag_number ) opening_tag_number_counter ++ ; } else if ( IS_CLOSING_TAG ( apdu [ apdu_len ] ) ) { len = decode_tag_number_and_value ( & apdu [ apdu_len ] , & tag_number , & value ) ; if ( tag_number == opening_tag_number ) opening_tag_number_counter -- ; } else if ( IS_CONTEXT_SPECIFIC ( apdu [ apdu_len ] ) ) { len = bacapp_decode_context_data_len ( & apdu [ apdu_len ] , max_apdu_len - apdu_len , property ) ; } else { len = bacapp_decode_application_data_len ( & apdu [ apdu_len ] , max_apdu_len - apdu_len ) ; } apdu_len += len ; if ( opening_tag_number_counter ) { if ( len > 0 ) { total_len += len ; } else { total_len = BACNET_STATUS_ERROR ; break ; } } if ( ( unsigned ) apdu_len > max_apdu_len ) { total_len = BACNET_STATUS_ERROR ; break ; } } } return total_len ; }
returns the length of data between an opening tag and a closing tag.
returns the length of data between an opening tag and a closing tag .
/* context-specific tagged data */ /* application tagged data */ /* error: len is not incrementing */ /* error: exceeding our buffer limit */