int bacapp_decode_device_obj_ref(
    uint8_t * apdu,
    BACNET_DEVICE_OBJECT_REFERENCE * value)
{
    int len;
    int apdu_len = 0;

    /* Device ID is optional */
    if (decode_is_context_tag(&apdu[apdu_len], 0)) {
        if (-1 == (len =
                decode_context_object_id(&apdu[apdu_len], 0,
                    &value->deviceIndentifier.type,
                    &value->deviceIndentifier.instance))) {
            return -1;
        }
        apdu_len += len;
    } else {
    	value->deviceIndentifier.type = BACNET_NO_DEV_TYPE;
    	value->deviceIndentifier.instance = BACNET_NO_DEV_ID;
    }

    if (-1 == (len =
            decode_context_object_id(&apdu[apdu_len], 1,
                &value->objectIdentifier.type,
                &value->objectIdentifier.instance))) {
        return -1;
    }
    apdu_len += len;

    return apdu_len;
}
Beispiel #2
0
/* BACnetDeviceObjectReference ::= SEQUENCE {
    device-identifier [0] BACnetObjectIdentifier OPTIONAL,
    object-identifier [1] BACnetObjectIdentifier
}*/
int bacapp_decode_device_obj_ref(
    uint8_t * apdu,
    BACNET_DEVICE_OBJECT_REFERENCE * value)
{
    int len;
    int apdu_len = 0;

    /* device-identifier [0] BACnetObjectIdentifier OPTIONAL */
    if (decode_is_context_tag(&apdu[apdu_len], 0) &&
        !decode_is_closing_tag(&apdu[apdu_len])) {
        if (-1 == (len =
                decode_context_object_id(&apdu[apdu_len], 0,
                    &value->deviceIndentifier.type,
                    &value->deviceIndentifier.instance))) {
            return -1;
        }
        apdu_len += len;
    } else {
    	value->deviceIndentifier.type = BACNET_NO_DEV_TYPE;
    	value->deviceIndentifier.instance = BACNET_NO_DEV_ID;
    }
    /* object-identifier [1] BACnetObjectIdentifier */
    if (-1 == (len =
            decode_context_object_id(&apdu[apdu_len], 1,
                &value->objectIdentifier.type,
                &value->objectIdentifier.instance))) {
        return -1;
    }
    apdu_len += len;

    return apdu_len;
}
Beispiel #3
0
/* BACnetDeviceObjectPropertyReference ::= SEQUENCE {
    object-identifier       [0] BACnetObjectIdentifier,
    property-identifier     [1] BACnetPropertyIdentifier,
    property-array-index    [2] Unsigned OPTIONAL,
        -- used only with array datatype
        -- if omitted with an array then
        -- the entire array is referenced
    device-identifier       [3] BACnetObjectIdentifier OPTIONAL
}
*/
int bacapp_decode_device_obj_property_ref(
    uint8_t * apdu,
    BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE * value)
{
    int len;
    int apdu_len = 0;
    uint32_t enumValue;

    /* object-identifier       [0] BACnetObjectIdentifier */
    if (-1 == (len =
            decode_context_object_id(&apdu[apdu_len], 0,
                &value->objectIdentifier.type,
                &value->objectIdentifier.instance))) {
        return -1;
    }
    apdu_len += len;
    /* property-identifier     [1] BACnetPropertyIdentifier */
    if (-1 == (len =
            decode_context_enumerated(&apdu[apdu_len], 1, &enumValue))) {
        return -1;
    }
    value->propertyIdentifier = (BACNET_PROPERTY_ID) enumValue;
    apdu_len += len;
    /* property-array-index    [2] Unsigned OPTIONAL */
    if (decode_is_context_tag(&apdu[apdu_len], 2) &&
        !decode_is_closing_tag(&apdu[apdu_len])) {
        if (-1 == (len =
                decode_context_unsigned(&apdu[apdu_len], 2,
                    &value->arrayIndex))) {
            return -1;
        }
        apdu_len += len;
    } else {
        value->arrayIndex = BACNET_ARRAY_ALL;
    }
    /* device-identifier       [3] BACnetObjectIdentifier OPTIONAL */
    if (decode_is_context_tag(&apdu[apdu_len], 3) &&
        !decode_is_closing_tag(&apdu[apdu_len])) {
        if (-1 == (len =
                decode_context_object_id(&apdu[apdu_len], 3,
                    &value->deviceIndentifier.type,
                    &value->deviceIndentifier.instance))) {
            return -1;
        }
        apdu_len += len;
    } else {
    	value->deviceIndentifier.type = BACNET_NO_DEV_TYPE;
    	value->deviceIndentifier.instance = BACNET_NO_DEV_ID;
    }

    return apdu_len;
}
int bacapp_decode_device_obj_property_ref(
    uint8_t * apdu,
    BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE * value)
{
    int len;
    int apdu_len = 0;
    uint32_t enumValue;
    if (-1 == (len =
            decode_context_object_id(&apdu[apdu_len], 0,
                &value->objectIdentifier.type,
                &value->objectIdentifier.instance))) {
        return -1;
    }
    apdu_len += len;

    if (-1 == (len =
            decode_context_enumerated(&apdu[apdu_len], 1, &enumValue))) {
        return -1;
    }
    value->propertyIdentifier = (BACNET_PROPERTY_ID) enumValue;
    apdu_len += len;

    if (decode_is_context_tag(&apdu[apdu_len], 2)) {
        if (-1 == (len =
                decode_context_unsigned(&apdu[apdu_len], 2,
                    &value->arrayIndex))) {
            return -1;
        }
        apdu_len += len;
    } else {
        value->arrayIndex = BACNET_ARRAY_ALL;
    }

    if (decode_is_context_tag(&apdu[apdu_len], 3)) {
        if (-1 == (len =
                decode_context_object_id(&apdu[apdu_len], 3,
                    &value->deviceIndentifier.type,
                    &value->deviceIndentifier.instance))) {
            return -1;
        }
        apdu_len += len;
    } else {
    	value->deviceIndentifier.type = BACNET_NO_DEV_TYPE;
    	value->deviceIndentifier.instance = BACNET_NO_DEV_ID;
    }

    return apdu_len;
}
Beispiel #5
0
/***************************************************
**
** Decodes the service data part of Event Notification
**
****************************************************/
int alarm_ack_decode_service_request(
    uint8_t * apdu,
    unsigned apdu_len,
    BACNET_ALARM_ACK_DATA * data)
{
    int len = 0;
    int section_len;
    uint32_t enumValue;

    /* unused parameter */
    unused_var(apdu_len);

    if (-1 == (section_len =
                   decode_context_unsigned(&apdu[len], 0,
                                           &data->ackProcessIdentifier))) {
        return -1;
    }
    len += section_len;

    if (-1 == (section_len =
                   decode_context_object_id(&apdu[len], 1,
                                            &data->eventObjectIdentifier.type,
                                            &data->eventObjectIdentifier.instance))) {
        return -1;
    }
    len += section_len;

    if (-1 == (section_len =
                   decode_context_enumerated(&apdu[len], 2, &enumValue))) {
        return -1;
    }
    data->eventStateAcked = (BACNET_EVENT_STATE) enumValue;
    len += section_len;

    if (-1 == (section_len =
                   bacapp_decode_context_timestamp(&apdu[len], 3,
                           &data->eventTimeStamp))) {
        return -1;
    }
    len += section_len;

    if (-1 == (section_len =
                   decode_context_character_string(&apdu[len], 4,
                           &data->ackSource))) {
        return -1;
    }
    len += section_len;

    if (-1 == (section_len =
                   bacapp_decode_context_timestamp(&apdu[len], 5,
                           &data->ackTimeStamp))) {
        return -1;
    }
    len += section_len;

    return len;
}
int lso_decode_service_request(
    uint8_t * apdu,
    unsigned apdu_len,
    BACNET_LSO_DATA * data)
{
    int len = 0;        /* return value */
    int section_length = 0;     /* length returned from decoding */
    uint32_t operation = 0;     /* handles decoded value */

    /* check for value pointers */
    if (apdu_len && data) {
        /* Tag 0: Object ID          */

        if ((section_length =
                decode_context_unsigned(&apdu[len], 0,
                    &data->processId)) == -1) {
            return -1;
        }
        len += section_length;

        if ((section_length =
                decode_context_character_string(&apdu[len], 1,
                    &data->requestingSrc)) == -1) {
            return -1;
        }
        len += section_length;

        if ((section_length =
                decode_context_enumerated(&apdu[len], 2, &operation)) == -1) {
            return -1;
        }
        data->operation = (BACNET_LIFE_SAFETY_OPERATION) operation;
        len += section_length;

        /*
         ** This is an optional parameter, so dont fail if it doesnt exist
         */
        if (decode_is_context_tag(&apdu[len], 3)) {
            if ((section_length =
                    decode_context_object_id(&apdu[len], 3,
                        &data->targetObject.type,
                        &data->targetObject.instance)) == -1) {
                return -1;
            }
            len += section_length;
        } else {
            data->targetObject.type = 0;
            data->targetObject.instance = 0;
        }
        return len;

    }

    return 0;
}