int rp_ack_decode_apdu( uint8_t * apdu, int apdu_len, /* total length of the apdu */ uint8_t * invoke_id, BACNET_READ_PROPERTY_DATA * rpdata) { int len = 0; int offset = 0; if (!apdu) return -1; /* optional checking - most likely was already done prior to this call */ if (apdu[0] != PDU_TYPE_COMPLEX_ACK) return -1; *invoke_id = apdu[1]; if (apdu[2] != SERVICE_CONFIRMED_READ_PROPERTY) return -1; offset = 3; if (apdu_len > offset) { len = rp_ack_decode_service_request(&apdu[offset], apdu_len - offset, rpdata); } return len; }
/** Handler for a ReadProperty ACK. * @ingroup DSRP * Doesn't actually do anything, except, for debugging, to * print out the ACK data of a matching request. * * @param service_request [in] The contents of the service request. * @param service_len [in] The length of the service_request. * @param src [in] BACNET_ADDRESS of the source of the message * @param service_data [in] The BACNET_CONFIRMED_SERVICE_DATA information * decoded from the APDU header of this message. */ static void My_Read_Property_Ack_Handler( uint8_t * service_request, uint16_t service_len, BACNET_ADDRESS * src, BACNET_CONFIRMED_SERVICE_ACK_DATA * service_data) { int len = 0; BACNET_READ_PROPERTY_DATA data; if (address_match(&Target_Address, src) && (service_data->invoke_id == Request_Invoke_ID)) { len = rp_ack_decode_service_request(service_request, service_len, &data); if (len > 0) { rp_ack_extract_data(&data); } } }
/** Handler for a ReadProperty ACK. * @ingroup DSRP * Doesn't actually do anything, except, for debugging, to * print out the ACK message. * * @param service_request [in] The contents of the service request. * @param service_len [in] The length of the service_request. * @param src [in] BACNET_ADDRESS of the source of the message * @param service_data [in] The BACNET_CONFIRMED_SERVICE_DATA information * decoded from the APDU header of this message. */ void handler_read_property_ack( uint8_t * service_request, uint16_t service_len, BACNET_ADDRESS * src, BACNET_CONFIRMED_SERVICE_ACK_DATA * service_data) { int len = 0; BACNET_READ_PROPERTY_DATA data; (void) src; (void) service_data; /* we could use these... */ len = rp_ack_decode_service_request(service_request, service_len, &data); #if 0 fprintf(stderr, "Received Read-Property Ack!\n"); #endif if (len > 0) rp_ack_print_data(&data); }
/** Handler for a ReadProperty ACK. * @ingroup DSRP * Doesn't actually do anything, except, for debugging, to * print out the ACK message. * * @param service_request [in] The contents of the service request. * @param service_len [in] The length of the service_request. * @param src [in] BACNET_ADDRESS of the source of the message * @param service_data [in] The BACNET_CONFIRMED_SERVICE_DATA information * decoded from the APDU header of this message. */ void handler_read_property_ack( uint8_t * service_request, uint16_t service_len, BACNET_ADDRESS * src, BACNET_CONFIRMED_SERVICE_ACK_DATA * service_data) { int len = 0; BACNET_READ_PROPERTY_DATA data; (void) src; (void) service_data; /* we could use these... */ len = rp_ack_decode_service_request(service_request, service_len, &data); #if TRACE_ENABLED fprintf(stderr, "Received Read-Property Ack! %d with length %d\n", service_data->invoke_id, len); #endif if (len > 0) { emit_read_property_ack(service_data->invoke_id, &data); // rp_ack_print_data(&data); } }
void My_Read_Property_Ack_Handler( uint8_t * service_request, uint16_t service_len, BACNET_ADDRESS * src, BACNET_CONFIRMED_SERVICE_ACK_DATA * service_data) { int len = 0; BACNET_READ_PROPERTY_DATA data; if (address_match(&target_address, src) && (service_data->invoke_id == request_invoke_id)) { len = rp_ack_decode_service_request(service_request, service_len, &data); if (len < 0) { printf("<decode failed!>\r\n"); } else { rp_ack_sprintf_data(value, (size_t) value_length,&data); } } }
/** Decode the received RP data into a linked list of the results, with the * same data structure used by RPM ACK replies. * This function is provided to provide common handling for RP and RPM data, * and fully decodes the value(s) portion of the data for one property. * @ingroup DSRP * @see rp_ack_decode_service_request(), rpm_ack_decode_service_request() * * @param apdu [in] The received apdu data. * @param apdu_len [in] Total length of the apdu. * @param read_access_data [out] Pointer to the head of the linked list * where the RP data is to be stored. * @return Number of decoded bytes (could be less than apdu_len), * or -1 on decoding error. */ int rp_ack_fully_decode_service_request( uint8_t * apdu, int apdu_len, BACNET_READ_ACCESS_DATA * read_access_data) { int decoded_len = 0; /* return value */ BACNET_READ_PROPERTY_DATA rp1data; BACNET_PROPERTY_REFERENCE *rp1_property; /* single property */ BACNET_APPLICATION_DATA_VALUE *value, *old_value; uint8_t *vdata; int vlen, len; decoded_len = rp_ack_decode_service_request(apdu, apdu_len, &rp1data); if (decoded_len > 0) { /* Then we have to transfer to the BACNET_READ_ACCESS_DATA structure * and decode the value(s) portion */ read_access_data->object_type = rp1data.object_type; read_access_data->object_instance = rp1data.object_instance; rp1_property = calloc(1, sizeof(BACNET_PROPERTY_REFERENCE)); read_access_data->listOfProperties = rp1_property; if (rp1_property == NULL) { /* can't proceed if calloc failed. */ return BACNET_STATUS_ERROR; } rp1_property->propertyIdentifier = rp1data.object_property; rp1_property->propertyArrayIndex = rp1data.array_index; /* Is there no Error case possible here, as there is when decoding RPM? */ /* rp1_property->error.error_class = ?? */ /* rp_ack_decode_service_request() processing already removed the * Opening and Closing '3' Tags. * note: if this is an array, there will be more than one element to decode */ vdata = rp1data.application_data; vlen = rp1data.application_data_len; value = calloc(1, sizeof(BACNET_APPLICATION_DATA_VALUE)); rp1_property->value = value; old_value = value; while (value && vdata && (vlen > 0)) { if (IS_CONTEXT_SPECIFIC(*vdata)) { len = bacapp_decode_context_data(vdata, vlen, value, rp1_property->propertyIdentifier); } else { len = bacapp_decode_application_data(vdata, vlen, value); } if (len < 0) { /* unable to decode the data */ while (value) { /* free the linked list of values */ old_value = value; value = value->next; free(old_value); } free(rp1_property); read_access_data->listOfProperties = NULL; return len; } decoded_len += len; vlen -= len; vdata += len; /* If unexpected closing tag here: */ if (vlen && decode_is_closing_tag_number(vdata, 3)) { decoded_len++; vlen--; vdata++; break; } else { if (len == 0) { /* nothing decoded and no closing tag, so malformed */ while (value) { /* free the linked list of values */ old_value = value; value = value->next; free(old_value); } free(rp1_property); read_access_data->listOfProperties = NULL; return BACNET_STATUS_ERROR; } if (vlen > 0) { /* If more values */ old_value = value; value = calloc(1, sizeof(BACNET_APPLICATION_DATA_VALUE)); old_value->next = value; } } } } return decoded_len; }