Indented according to standard indent rules for this project.

This commit is contained in:
skarg
2009-04-18 20:50:04 +00:00
parent b3fab21603
commit b85c4355d0
43 changed files with 501 additions and 502 deletions
+2 -2
View File
@@ -53,8 +53,8 @@ void handler_i_am_add(
if (len != -1) { if (len != -1) {
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, " from %u, MAC = %d.%d.%d.%d.%d.%d\n", device_id, fprintf(stderr, " from %u, MAC = %d.%d.%d.%d.%d.%d\n", device_id,
src->mac[0],src->mac[1],src->mac[2], src->mac[0], src->mac[1], src->mac[2], src->mac[3], src->mac[4],
src->mac[3],src->mac[4],src->mac[5]); src->mac[5]);
#endif #endif
address_add(device_id, max_apdu, src); address_add(device_id, max_apdu, src);
} else { } else {
+4 -10
View File
@@ -90,18 +90,14 @@ bool handler_lso(
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, fprintf(stderr,
"Life Safety Operation: Received operation %d from process id %d for object %id\n", "Life Safety Operation: Received operation %d from process id %d for object %id\n",
data.operation, data.operation, data.processId, data.targetObject.instance);
data.processId,
data.targetObject.instance);
#endif #endif
len = len =
encode_simple_ack(&Handler_Transmit_Buffer[pdu_len], encode_simple_ack(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, service_data->invoke_id, SERVICE_CONFIRMED_LIFE_SAFETY_OPERATION);
SERVICE_CONFIRMED_LIFE_SAFETY_OPERATION);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, fprintf(stderr, "Life Safety Operation: " "Sending Simple Ack!\n");
"Life Safety Operation: " "Sending Simple Ack!\n");
#endif #endif
LSO_ABORT: LSO_ABORT:
@@ -111,11 +107,9 @@ bool handler_lso(
pdu_len); pdu_len);
#if PRINT_ENABLED #if PRINT_ENABLED
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, fprintf(stderr, "Life Safety Operation: " "Failed to send PDU (%s)!\n",
"Life Safety Operation: " "Failed to send PDU (%s)!\n",
strerror(errno)); strerror(errno));
#endif #endif
return; return;
} }
+6 -8
View File
@@ -421,15 +421,14 @@ void handler_read_property_multiple(
/* handle the error code - but use the special property */ /* handle the error code - but use the special property */
len = len =
RPM_Encode_Property(&Handler_Transmit_Buffer[0], RPM_Encode_Property(&Handler_Transmit_Buffer[0],
npdu_len + apdu_len, MAX_APDU, npdu_len + apdu_len, MAX_APDU, object_type,
object_type, object_instance, object_property, object_instance, object_property, array_index);
array_index);
if (len > 0) { if (len > 0) {
apdu_len += len; apdu_len += len;
} else { } else {
apdu_len = apdu_len =
abort_encode_apdu(&Handler_Transmit_Buffer[npdu_len], abort_encode_apdu(&Handler_Transmit_Buffer
service_data->invoke_id, [npdu_len], service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
goto RPM_ABORT; goto RPM_ABORT;
} }
@@ -440,9 +439,8 @@ void handler_read_property_multiple(
special_object_property, index); special_object_property, index);
len = len =
RPM_Encode_Property(&Handler_Transmit_Buffer[0], RPM_Encode_Property(&Handler_Transmit_Buffer[0],
npdu_len + apdu_len, MAX_APDU, npdu_len + apdu_len, MAX_APDU, object_type,
object_type, object_instance, object_property, object_instance, object_property, array_index);
array_index);
if (len > 0) { if (len > 0) {
apdu_len += len; apdu_len += len;
} else { } else {
+9 -11
View File
@@ -108,12 +108,12 @@ static int rpm_ack_decode_service_request(
while (value && (apdu_len > 0)) { while (value && (apdu_len > 0)) {
if (decode_is_context_specific(apdu)) { if (decode_is_context_specific(apdu)) {
len = len =
bacapp_decode_context_data( bacapp_decode_context_data(apdu, apdu_len, value,
apdu, apdu_len, value,
rpm_property->propertyIdentifier); rpm_property->propertyIdentifier);
} else { } else {
len = len =
bacapp_decode_application_data(apdu, apdu_len, value); bacapp_decode_application_data(apdu, apdu_len,
value);
} }
decoded_len += len; decoded_len += len;
apdu_len -= len; apdu_len -= len;
@@ -137,8 +137,7 @@ static int rpm_ack_decode_service_request(
apdu++; apdu++;
/* decode the class and code sequence */ /* decode the class and code sequence */
len = len =
decode_tag_number_and_value(apdu, &tag_number, decode_tag_number_and_value(apdu, &tag_number, &len_value);
&len_value);
decoded_len += len; decoded_len += len;
apdu_len -= len; apdu_len -= len;
apdu += len; apdu += len;
@@ -149,8 +148,7 @@ static int rpm_ack_decode_service_request(
apdu_len -= len; apdu_len -= len;
apdu += len; apdu += len;
len = len =
decode_tag_number_and_value(apdu, &tag_number, decode_tag_number_and_value(apdu, &tag_number, &len_value);
&len_value);
decoded_len += len; decoded_len += len;
apdu_len -= len; apdu_len -= len;
apdu += len; apdu += len;
@@ -242,10 +240,10 @@ static void PrintReadPropertyMultipleData(
#if PRINT_ENABLED #if PRINT_ENABLED
/* AccessError */ /* AccessError */
fprintf(stdout, "BACnet Error: %s: %s\r\n", fprintf(stdout, "BACnet Error: %s: %s\r\n",
bactext_error_class_name( bactext_error_class_name((int) listOfProperties->error.
(int)listOfProperties->error.error_class), error_class),
bactext_error_code_name( bactext_error_code_name((int) listOfProperties->error.
(int)listOfProperties->error.error_code)); error_code));
#endif #endif
} }
listOfProperties = listOfProperties->next; listOfProperties = listOfProperties->next;
+1 -2
View File
@@ -325,8 +325,7 @@ static void address_parse(BACNET_ADDRESS * dst,
dst->mac_len = 6; dst->mac_len = 6;
for (index = 0; index < 4; index++) { for (index = 0; index < 4; index++) {
dst->mac[index] = mac[index]; dst->mac[index] = mac[index];
} } encode_unsigned16(&dst->mac[4],
encode_unsigned16(&dst->mac[4],
port); port);
} else { } else {
count = count =
+11 -15
View File
@@ -99,7 +99,8 @@ static void dlmstp_millisecond_timer(
} }
#if !defined (_WIN32) #if !defined (_WIN32)
void Sleep(unsigned long milliseconds) void Sleep(
unsigned long milliseconds)
{ {
struct timespec timeOut, remains; struct timespec timeOut, remains;
@@ -165,7 +166,8 @@ uint16_t MSTP_Get_Reply(
static char Capture_Filename[32] = "mstp_20090123091200.cap"; static char Capture_Filename[32] = "mstp_20090123091200.cap";
static FILE *pFile = NULL; /* stream pointer */ static FILE *pFile = NULL; /* stream pointer */
static void filename_create(char *filename) static void filename_create(
char *filename)
{ {
time_t my_time; time_t my_time;
struct tm *today; struct tm *today;
@@ -174,12 +176,8 @@ static void filename_create(char *filename)
my_time = time(NULL); my_time = time(NULL);
today = localtime(&my_time); today = localtime(&my_time);
sprintf(filename, "mstp_%04d%02d%02d%02d%02d%02d.cap", sprintf(filename, "mstp_%04d%02d%02d%02d%02d%02d.cap",
1900+today->tm_year, 1900 + today->tm_year, 1 + today->tm_mon, today->tm_mday,
1+today->tm_mon, today->tm_hour, today->tm_min, today->tm_sec);
today->tm_mday,
today->tm_hour,
today->tm_min,
today->tm_sec);
} }
} }
@@ -287,7 +285,8 @@ void signal_init(
} }
#endif #endif
void filename_create_new(void) void filename_create_new(
void)
{ {
if (pFile) { if (pFile) {
fclose(pFile); fclose(pFile);
@@ -320,14 +319,11 @@ int main(
"Captures MS/TP packets from a serial interface\r\n" "Captures MS/TP packets from a serial interface\r\n"
"and save them to a file. Saves packets in a\r\n" "and save them to a file. Saves packets in a\r\n"
"filename mstp_20090123091200.cap that has data and time.\r\n" "filename mstp_20090123091200.cap that has data and time.\r\n"
"After receiving 65535 packets, a new file is created.\r\n" "After receiving 65535 packets, a new file is created.\r\n" "\r\n"
"\r\n" "Command line options:\r\n" "[interface] - serial interface.\r\n"
"Command line options:\r\n"
"[interface] - serial interface.\r\n"
" defaults to COM4 on Windows, and /dev/ttyUSB0 on linux.\r\n" " defaults to COM4 on Windows, and /dev/ttyUSB0 on linux.\r\n"
"[baud] - baud rate. 9600, 19200, 38400, 57600, 115200\r\n" "[baud] - baud rate. 9600, 19200, 38400, 57600, 115200\r\n"
" defaults to 38400.\r\n" " defaults to 38400.\r\n" "");
"");
return 0; return 0;
} }
if (argc > 1) { if (argc > 1) {
+2 -1
View File
@@ -230,7 +230,8 @@ void cleanup(void) {
old_rpm_property = rpm_property; old_rpm_property = rpm_property;
rpm_property = rpm_property->next; rpm_property = rpm_property->next;
free(old_rpm_property); free(old_rpm_property);
} old_rpm_object = rpm_object; }
old_rpm_object = rpm_object;
rpm_object = rpm_object->next; rpm_object = rpm_object->next;
free(old_rpm_object); free(old_rpm_object);
} }
+2 -2
View File
@@ -212,8 +212,8 @@ int main(int argc, char *argv[]) {
filename_remove_path(argv[0]), filename_remove_path(argv[0])); filename_remove_path(argv[0]), filename_remove_path(argv[0]));
return 0; return 0;
} }
/* decode the command line parameters */ cov_data. /* decode the command line parameters */
subscriberProcessIdentifier = strtol(argv[1], NULL, 0); cov_data.subscriberProcessIdentifier = strtol(argv[1], NULL, 0);
cov_data.initiatingDeviceIdentifier = strtol(argv[2], NULL, 0); cov_data.initiatingDeviceIdentifier = strtol(argv[2], NULL, 0);
cov_data.monitoredObjectIdentifier.type = strtol(argv[3], NULL, 0); cov_data.monitoredObjectIdentifier.type = strtol(argv[3], NULL, 0);
cov_data.monitoredObjectIdentifier.instance = strtol(argv[4], NULL, 0); cov_data.monitoredObjectIdentifier.instance = strtol(argv[4], NULL, 0);
-2
View File
@@ -898,11 +898,9 @@ typedef enum {
OBJECT_ACCESS_ZONE = 36, OBJECT_ACCESS_ZONE = 36,
OBJECT_AUTHENTICATION_FACTOR_INPUT = 37, OBJECT_AUTHENTICATION_FACTOR_INPUT = 37,
MAX_ASHRAE_OBJECT_TYPE = 38 MAX_ASHRAE_OBJECT_TYPE = 38
/* Enumerated values 0-127 are reserved for definition by ASHRAE. */ /* Enumerated values 0-127 are reserved for definition by ASHRAE. */
/* Enumerated values 128-1023 may be used by others subject to */ /* Enumerated values 128-1023 may be used by others subject to */
/* the procedures and constraints described in Clause 23. */ /* the procedures and constraints described in Clause 23. */
} BACNET_OBJECT_TYPE; } BACNET_OBJECT_TYPE;
/* used for bit string loop */ /* used for bit string loop */
#define MAX_BACNET_OBJECT_TYPE 1023 #define MAX_BACNET_OBJECT_TYPE 1023
-1
View File
@@ -117,5 +117,4 @@ extern void datalink_set(
} }
#endif /* __cplusplus */ #endif /* __cplusplus */
#endif #endif
#endif #endif
-1
View File
@@ -116,5 +116,4 @@ int Keylist_Count(
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */
#endif #endif
+1 -2
View File
@@ -46,8 +46,7 @@ extern "C" {
/* Life Safety Operation Service */ /* Life Safety Operation Service */
typedef struct typedef struct {
{
uint32_t processId; uint32_t processId;
BACNET_CHARACTER_STRING requestingSrc; BACNET_CHARACTER_STRING requestingSrc;
BACNET_LIFE_SAFETY_OPERATION operation; BACNET_LIFE_SAFETY_OPERATION operation;
-1
View File
@@ -23,5 +23,4 @@ void DLL_EXPORT SomeFunction(
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */
#endif #endif
+4 -8
View File
@@ -267,16 +267,12 @@ int main(
printf("mstsnap [serial] [baud] [network]\r\n" printf("mstsnap [serial] [baud] [network]\r\n"
"Captures MS/TP packets from a serial interface\r\n" "Captures MS/TP packets from a serial interface\r\n"
"and sends them to a network interface using SNAP \r\n" "and sends them to a network interface using SNAP \r\n"
"protocol packets (mimics Cimetrics U+4 packet).\r\n" "protocol packets (mimics Cimetrics U+4 packet).\r\n" "\r\n"
"\r\n" "Command line options:\r\n" "[serial] - serial interface.\r\n"
"Command line options:\r\n"
"[serial] - serial interface.\r\n"
" defaults to /dev/ttyUSB0.\r\n" " defaults to /dev/ttyUSB0.\r\n"
"[baud] - baud rate. 9600, 19200, 38400, 57600, 115200\r\n" "[baud] - baud rate. 9600, 19200, 38400, 57600, 115200\r\n"
" defaults to 38400.\r\n" " defaults to 38400.\r\n" "[network] - network interface.\r\n"
"[network] - network interface.\r\n" " defaults to eth0.\r\n" "");
" defaults to eth0.\r\n"
"");
return 0; return 0;
} }
/* initialize our interface */ /* initialize our interface */
+5 -4
View File
@@ -123,14 +123,15 @@ void apdu_handler(
if (service_choice == SERVICE_CONFIRMED_READ_PROPERTY) { if (service_choice == SERVICE_CONFIRMED_READ_PROPERTY) {
handler_read_property(service_request, service_request_len, handler_read_property(service_request, service_request_len,
src, &service_data); src, &service_data);
} } else if (service_choice == SERVICE_CONFIRMED_WRITE_PROPERTY) {
else if (service_choice == SERVICE_CONFIRMED_WRITE_PROPERTY) {
handler_write_property(service_request, handler_write_property(service_request,
service_request_len, src, &service_data); service_request_len, src, &service_data);
} else if (service_choice == SERVICE_CONFIRMED_REINITIALIZE_DEVICE) { } else if (service_choice ==
SERVICE_CONFIRMED_REINITIALIZE_DEVICE) {
handler_reinitialize_device(service_request, handler_reinitialize_device(service_request,
service_request_len, src, &service_data); service_request_len, src, &service_data);
} else if (service_choice == SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL) { } else if (service_choice ==
SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL) {
handler_device_communication_control(service_request, handler_device_communication_control(service_request,
service_request_len, src, &service_data); service_request_len, src, &service_data);
} else { } else {
+2 -1
View File
@@ -54,7 +54,8 @@ static struct Address_Cache_Entry {
BACNET_ADDRESS address; BACNET_ADDRESS address;
} Address_Cache[MAX_ADDRESS_CACHE]; } Address_Cache[MAX_ADDRESS_CACHE];
bool address_match(BACNET_ADDRESS * dest, bool address_match(
BACNET_ADDRESS * dest,
BACNET_ADDRESS * src) BACNET_ADDRESS * src)
{ {
uint8_t i = 0; uint8_t i = 0;
+28 -13
View File
@@ -704,9 +704,7 @@ int encode_context_bitstring(
/* bit string may use more than 1 octet for the tag, so find out how many */ /* bit string may use more than 1 octet for the tag, so find out how many */
bit_string_encoded_length += bitstring_bytes_used(bit_string); bit_string_encoded_length += bitstring_bytes_used(bit_string);
len = len = encode_tag(&apdu[0], tag_number, true, bit_string_encoded_length);
encode_tag(&apdu[0], tag_number, true,
bit_string_encoded_length);
len += encode_bitstring(&apdu[len], bit_string); len += encode_bitstring(&apdu[len], bit_string);
return len; return len;
@@ -801,7 +799,9 @@ int encode_application_object_id(
/* assumes that the tag only consumes 1 octet */ /* assumes that the tag only consumes 1 octet */
len = encode_bacnet_object_id(&apdu[1], object_type, instance); len = encode_bacnet_object_id(&apdu[1], object_type, instance);
len += encode_tag(&apdu[0], BACNET_APPLICATION_TAG_OBJECT_ID, false, (uint32_t)len); len +=
encode_tag(&apdu[0], BACNET_APPLICATION_TAG_OBJECT_ID, false,
(uint32_t) len);
return len; return len;
} }
@@ -951,7 +951,8 @@ int encode_application_character_string(
int len = 0; int len = 0;
int string_len = 0; int string_len = 0;
string_len = (int)characterstring_length(char_string) + 1 /* for encoding */ ; string_len =
(int) characterstring_length(char_string) + 1 /* for encoding */ ;
len = len =
encode_tag(&apdu[0], BACNET_APPLICATION_TAG_CHARACTER_STRING, false, encode_tag(&apdu[0], BACNET_APPLICATION_TAG_CHARACTER_STRING, false,
(uint32_t) string_len); (uint32_t) string_len);
@@ -972,7 +973,8 @@ int encode_context_character_string(
int len = 0; int len = 0;
int string_len = 0; int string_len = 0;
string_len = (int)characterstring_length(char_string) + 1 /* for encoding */ ; string_len =
(int) characterstring_length(char_string) + 1 /* for encoding */ ;
len += encode_tag(&apdu[0], tag_number, true, (uint32_t) string_len); len += encode_tag(&apdu[0], tag_number, true, (uint32_t) string_len);
if ((len + string_len) < MAX_APDU) { if ((len + string_len) < MAX_APDU) {
len += encode_bacnet_character_string(&apdu[len], char_string); len += encode_bacnet_character_string(&apdu[len], char_string);
@@ -1138,7 +1140,8 @@ int encode_application_unsigned(
len = encode_bacnet_unsigned(&apdu[1], value); len = encode_bacnet_unsigned(&apdu[1], value);
len += len +=
encode_tag(&apdu[0], BACNET_APPLICATION_TAG_UNSIGNED_INT, false, (uint32_t)len); encode_tag(&apdu[0], BACNET_APPLICATION_TAG_UNSIGNED_INT, false,
(uint32_t) len);
return len; return len;
} }
@@ -1202,7 +1205,9 @@ int encode_application_enumerated(
/* assumes that the tag only consumes 1 octet */ /* assumes that the tag only consumes 1 octet */
len = encode_bacnet_enumerated(&apdu[1], value); len = encode_bacnet_enumerated(&apdu[1], value);
len += encode_tag(&apdu[0], BACNET_APPLICATION_TAG_ENUMERATED, false, (uint32_t)len); len +=
encode_tag(&apdu[0], BACNET_APPLICATION_TAG_ENUMERATED, false,
(uint32_t) len);
return len; return len;
} }
@@ -1316,7 +1321,9 @@ int encode_application_signed(
/* assumes that the tag only consumes 1 octet */ /* assumes that the tag only consumes 1 octet */
len = encode_bacnet_signed(&apdu[1], value); len = encode_bacnet_signed(&apdu[1], value);
len += encode_tag(&apdu[0], BACNET_APPLICATION_TAG_SIGNED_INT, false, (uint32_t)len); len +=
encode_tag(&apdu[0], BACNET_APPLICATION_TAG_SIGNED_INT, false,
(uint32_t) len);
return len; return len;
} }
@@ -1354,7 +1361,9 @@ int encode_application_real(
/* assumes that the tag only consumes 1 octet */ /* assumes that the tag only consumes 1 octet */
len = encode_bacnet_real(value, &apdu[1]); len = encode_bacnet_real(value, &apdu[1]);
len += encode_tag(&apdu[0], BACNET_APPLICATION_TAG_REAL, false, (uint32_t)len); len +=
encode_tag(&apdu[0], BACNET_APPLICATION_TAG_REAL, false,
(uint32_t) len);
return len; return len;
} }
@@ -1389,7 +1398,9 @@ int encode_application_double(
/* assumes that the tag only consumes 1 octet */ /* assumes that the tag only consumes 1 octet */
len = encode_bacnet_double(value, &apdu[1]); len = encode_bacnet_double(value, &apdu[1]);
len += encode_tag(&apdu[0], BACNET_APPLICATION_TAG_DOUBLE, false, (uint32_t)len); len +=
encode_tag(&apdu[0], BACNET_APPLICATION_TAG_DOUBLE, false,
(uint32_t) len);
return len; return len;
} }
@@ -1439,7 +1450,9 @@ int encode_application_time(
/* assumes that the tag only consumes 1 octet */ /* assumes that the tag only consumes 1 octet */
len = encode_bacnet_time(&apdu[1], btime); len = encode_bacnet_time(&apdu[1], btime);
len += encode_tag(&apdu[0], BACNET_APPLICATION_TAG_TIME, false, (uint32_t)len); len +=
encode_tag(&apdu[0], BACNET_APPLICATION_TAG_TIME, false,
(uint32_t) len);
return len; return len;
} }
@@ -1558,7 +1571,9 @@ int encode_application_date(
/* assumes that the tag only consumes 1 octet */ /* assumes that the tag only consumes 1 octet */
len = encode_bacnet_date(&apdu[1], bdate); len = encode_bacnet_date(&apdu[1], bdate);
len += encode_tag(&apdu[0], BACNET_APPLICATION_TAG_DATE, false, (uint32_t)len); len +=
encode_tag(&apdu[0], BACNET_APPLICATION_TAG_DATE, false,
(uint32_t) len);
return len; return len;
+2 -1
View File
@@ -82,7 +82,8 @@ int bacapp_encode_device_obj_property_ref(
} }
len = len =
encode_context_object_id(&apdu[apdu_len], 3, encode_context_object_id(&apdu[apdu_len], 3,
(int)value->deviceIndentifier.type, value->deviceIndentifier.instance); (int) value->deviceIndentifier.type,
value->deviceIndentifier.instance);
apdu_len += len; apdu_len += len;
return apdu_len; return apdu_len;
+9 -9
View File
@@ -501,8 +501,7 @@ int event_notify_decode_service_request(
} }
/* tag 6 - eventType */ /* tag 6 - eventType */
if ((section_length = if ((section_length =
decode_context_enumerated(&apdu[len], 6, decode_context_enumerated(&apdu[len], 6, &value)) == -1) {
&value)) == -1) {
return -1; return -1;
} else { } else {
data->eventType = value; data->eventType = value;
@@ -531,8 +530,7 @@ int event_notify_decode_service_request(
/* tag 8 - notifyType */ /* tag 8 - notifyType */
if ((section_length = if ((section_length =
decode_context_enumerated(&apdu[len], 8, decode_context_enumerated(&apdu[len], 8, &value)) == -1) {
&value)) == -1) {
return -1; return -1;
} else { } else {
data->notifyType = value; data->notifyType = value;
@@ -568,8 +566,7 @@ int event_notify_decode_service_request(
} }
/* tag 11 - toState */ /* tag 11 - toState */
if ((section_length = if ((section_length =
decode_context_enumerated(&apdu[len], 11, decode_context_enumerated(&apdu[len], 11, &value)) == -1) {
&value)) == -1) {
return -1; return -1;
} else { } else {
data->toState = value; data->toState = value;
@@ -753,7 +750,8 @@ int event_notify_decode_service_request(
&value))) { &value))) {
return -1; return -1;
} }
data->notificationParams.changeOfLifeSafety.newState = value; data->notificationParams.changeOfLifeSafety.newState =
value;
len += section_length; len += section_length;
if (-1 == (section_length = if (-1 == (section_length =
@@ -761,7 +759,8 @@ int event_notify_decode_service_request(
&value))) { &value))) {
return -1; return -1;
} }
data->notificationParams.changeOfLifeSafety.newMode = value; data->notificationParams.changeOfLifeSafety.newMode =
value;
len += section_length; len += section_length;
if (-1 == (section_length = if (-1 == (section_length =
@@ -777,7 +776,8 @@ int event_notify_decode_service_request(
&value))) { &value))) {
return -1; return -1;
} }
data->notificationParams.changeOfLifeSafety.operationExpected = value; data->notificationParams.changeOfLifeSafety.
operationExpected = value;
len += section_length; len += section_length;
break; break;
+2 -1
View File
@@ -61,7 +61,8 @@ int iam_encode_apdu(
apdu_len += len; apdu_len += len;
len = encode_application_unsigned(&apdu[apdu_len], max_apdu); len = encode_application_unsigned(&apdu[apdu_len], max_apdu);
apdu_len += len; apdu_len += len;
len = encode_application_enumerated(&apdu[apdu_len], len =
encode_application_enumerated(&apdu[apdu_len],
(uint32_t) segmentation); (uint32_t) segmentation);
apdu_len += len; apdu_len += len;
len = encode_application_unsigned(&apdu[apdu_len], vendor_id); len = encode_application_unsigned(&apdu[apdu_len], vendor_id);
+4 -4
View File
@@ -50,13 +50,13 @@ int ihave_encode_apdu(
apdu_len = 2; apdu_len = 2;
/* deviceIdentifier */ /* deviceIdentifier */
len = len =
encode_application_object_id(&apdu[apdu_len], (int)data->device_id.type, encode_application_object_id(&apdu[apdu_len],
data->device_id.instance); (int) data->device_id.type, data->device_id.instance);
apdu_len += len; apdu_len += len;
/* objectIdentifier */ /* objectIdentifier */
len = len =
encode_application_object_id(&apdu[apdu_len], (int)data->object_id.type, encode_application_object_id(&apdu[apdu_len],
data->object_id.instance); (int) data->object_id.type, data->object_id.instance);
apdu_len += len; apdu_len += len;
/* objectName */ /* objectName */
len = len =
+19 -21
View File
@@ -52,9 +52,7 @@ int lso_encode_adpu(
apdu[3] = SERVICE_CONFIRMED_LIFE_SAFETY_OPERATION; apdu[3] = SERVICE_CONFIRMED_LIFE_SAFETY_OPERATION;
apdu_len = 4; apdu_len = 4;
/* tag 0 - requestingProcessId */ /* tag 0 - requestingProcessId */
len = len = encode_context_unsigned(&apdu[apdu_len], 0, data->processId);
encode_context_unsigned(&apdu[apdu_len], 0,
data->processId);
apdu_len += len; apdu_len += len;
/* tag 1 - requestingSource */ /* tag 1 - requestingSource */
len = len =
@@ -70,9 +68,9 @@ int lso_encode_adpu(
Object ID Object ID
*/ */
len = encode_context_object_id(&apdu[apdu_len], 3, len =
(int)data->targetObject.type, encode_context_object_id(&apdu[apdu_len], 3,
data->targetObject.instance); (int) data->targetObject.type, data->targetObject.instance);
apdu_len += len; apdu_len += len;
} }
@@ -93,20 +91,22 @@ int lso_decode_service_request(
if (apdu_len && data) { if (apdu_len && data) {
/* Tag 0: Object ID */ /* Tag 0: Object ID */
if ( (section_length = decode_context_unsigned(&apdu[len], 0, &data->processId)) == -1) if ((section_length =
{ decode_context_unsigned(&apdu[len], 0,
&data->processId)) == -1) {
return -1; return -1;
} }
len += section_length; len += section_length;
if ( (section_length = decode_context_character_string(&apdu[len], 1, &data->requestingSrc)) == -1) if ((section_length =
{ decode_context_character_string(&apdu[len], 1,
&data->requestingSrc)) == -1) {
return -1; return -1;
} }
len += section_length; len += section_length;
if ( (section_length = decode_context_enumerated(&apdu[len], 2, &operation)) == -1) if ((section_length =
{ decode_context_enumerated(&apdu[len], 2, &operation)) == -1) {
return -1; return -1;
} }
data->operation = operation; data->operation = operation;
@@ -115,18 +115,15 @@ int lso_decode_service_request(
/* /*
** This is an optional parameter, so dont fail if it doesnt exist ** This is an optional parameter, so dont fail if it doesnt exist
*/ */
if ( decode_is_context_tag(&apdu[len], 3) ) if (decode_is_context_tag(&apdu[len], 3)) {
{ if ((section_length =
if ( (section_length = decode_context_object_id(&apdu[len], 3, decode_context_object_id(&apdu[len], 3,
&data->targetObject.type, &data->targetObject.type,
&data->targetObject.instance)) == -1 ) &data->targetObject.instance)) == -1) {
{
return -1; return -1;
} }
len += section_length; len += section_length;
} } else {
else
{
data->targetObject.type = 0; data->targetObject.type = 0;
data->targetObject.instance = 0; data->targetObject.instance = 0;
} }
@@ -169,7 +166,8 @@ void testLSO(
ct_test(pTest, data.processId == rxdata.processId); ct_test(pTest, data.processId == rxdata.processId);
ct_test(pTest, data.targetObject.instance == rxdata.targetObject.instance); ct_test(pTest, data.targetObject.instance == rxdata.targetObject.instance);
ct_test(pTest, data.targetObject.type == rxdata.targetObject.type); ct_test(pTest, data.targetObject.type == rxdata.targetObject.type);
ct_test(pTest, memcmp(data.requestingSrc.value, rxdata.requestingSrc.value, rxdata.requestingSrc.length) == 0); ct_test(pTest, memcmp(data.requestingSrc.value, rxdata.requestingSrc.value,
rxdata.requestingSrc.length) == 0);
} }
#ifdef TEST_LSO #ifdef TEST_LSO
+50 -52
View File
@@ -59,10 +59,12 @@ int ptransfer_encode_apdu(
serviceParameters [2] ABSTRACT-SYNTAX.&Type OPTIONAL serviceParameters [2] ABSTRACT-SYNTAX.&Type OPTIONAL
} }
*/ */
len = encode_context_unsigned(&apdu[apdu_len], 0, len =
encode_context_unsigned(&apdu[apdu_len], 0,
private_data->vendorID); private_data->vendorID);
apdu_len += len; apdu_len += len;
len = encode_context_unsigned(&apdu[apdu_len], 1, len =
encode_context_unsigned(&apdu[apdu_len], 1,
private_data->serviceNumber); private_data->serviceNumber);
apdu_len += len; apdu_len += len;
len = encode_opening_tag(&apdu[apdu_len], 2); len = encode_opening_tag(&apdu[apdu_len], 2);
@@ -154,10 +156,12 @@ int ptransfer_error_encode_apdu(
apdu_len += len; apdu_len += len;
len = encode_closing_tag(&apdu[apdu_len], 0); len = encode_closing_tag(&apdu[apdu_len], 0);
apdu_len += len; apdu_len += len;
len = encode_context_unsigned(&apdu[apdu_len], 1, len =
encode_context_unsigned(&apdu[apdu_len], 1,
private_data->vendorID); private_data->vendorID);
apdu_len += len; apdu_len += len;
len = encode_context_unsigned(&apdu[apdu_len], 2, len =
encode_context_unsigned(&apdu[apdu_len], 2,
private_data->serviceNumber); private_data->serviceNumber);
apdu_len += len; apdu_len += len;
len = encode_opening_tag(&apdu[apdu_len], 3); len = encode_opening_tag(&apdu[apdu_len], 3);
@@ -248,7 +252,8 @@ int ptransfer_error_decode_service_request(
len++; len++;
/* don't decode the serviceParameters here */ /* don't decode the serviceParameters here */
private_data->serviceParameters = &apdu[len]; private_data->serviceParameters = &apdu[len];
private_data->serviceParametersLen = (int)apdu_len - len - 1 /*closing tag */ ; private_data->serviceParametersLen =
(int) apdu_len - len - 1 /*closing tag */ ;
} else { } else {
return -1; return -1;
} }
@@ -279,10 +284,12 @@ int ptransfer_ack_encode_apdu(
resultBlock [2] ABSTRACT-SYNTAX.&Type OPTIONAL resultBlock [2] ABSTRACT-SYNTAX.&Type OPTIONAL
} }
*/ */
len = encode_context_unsigned(&apdu[apdu_len], 0, len =
encode_context_unsigned(&apdu[apdu_len], 0,
private_data->vendorID); private_data->vendorID);
apdu_len += len; apdu_len += len;
len = encode_context_unsigned(&apdu[apdu_len], 1, len =
encode_context_unsigned(&apdu[apdu_len], 1,
private_data->serviceNumber); private_data->serviceNumber);
apdu_len += len; apdu_len += len;
len = encode_opening_tag(&apdu[apdu_len], 2); len = encode_opening_tag(&apdu[apdu_len], 2);
@@ -329,8 +336,9 @@ int ptransfer_decode_apdu(
offset = 4; offset = 4;
if (apdu_len > offset) { if (apdu_len > offset) {
len = ptransfer_decode_service_request( len =
&apdu[offset], apdu_len - offset, private_data); ptransfer_decode_service_request(&apdu[offset], apdu_len - offset,
private_data);
} }
return len; return len;
@@ -356,8 +364,8 @@ int ptransfer_ack_decode_apdu(
offset = 3; offset = 3;
if (apdu_len > offset) { if (apdu_len > offset) {
len = len =
ptransfer_decode_service_request( ptransfer_decode_service_request(&apdu[offset], apdu_len - offset,
&apdu[offset], apdu_len - offset, private_data); private_data);
} }
return len; return len;
@@ -385,9 +393,8 @@ int ptransfer_error_decode_apdu(
offset = 3; offset = 3;
if (apdu_len > offset) { if (apdu_len > offset) {
len = len =
ptransfer_error_decode_service_request( ptransfer_error_decode_service_request(&apdu[offset],
&apdu[offset], apdu_len - offset, apdu_len - offset, error_class, error_code, private_data);
error_class, error_code, private_data);
} }
return len; return len;
@@ -412,12 +419,10 @@ void test_Private_Transfer_Ack(
private_data.vendorID = BACNET_VENDOR_ID; private_data.vendorID = BACNET_VENDOR_ID;
private_data.serviceNumber = 1; private_data.serviceNumber = 1;
bacapp_parse_application_data( bacapp_parse_application_data(BACNET_APPLICATION_TAG_OCTET_STRING,
BACNET_APPLICATION_TAG_OCTET_STRING,
&private_data_chunk[0], &data_value); &private_data_chunk[0], &data_value);
private_data_len = bacapp_encode_application_data( private_data_len =
&test_value[0], bacapp_encode_application_data(&test_value[0], &data_value);
&data_value);
private_data.serviceParameters = &test_value[0]; private_data.serviceParameters = &test_value[0];
private_data.serviceParametersLen = private_data_len; private_data.serviceParametersLen = private_data_len;
@@ -427,19 +432,18 @@ void test_Private_Transfer_Ack(
ct_test(pTest, len != 0); ct_test(pTest, len != 0);
ct_test(pTest, len != -1); ct_test(pTest, len != -1);
apdu_len = len; apdu_len = len;
len = ptransfer_ack_decode_apdu( len =
&apdu[0], apdu_len, ptransfer_ack_decode_apdu(&apdu[0], apdu_len, &test_invoke_id,
&test_invoke_id, &test_data); &test_data);
ct_test(pTest, len != -1); ct_test(pTest, len != -1);
ct_test(pTest, test_invoke_id == invoke_id); ct_test(pTest, test_invoke_id == invoke_id);
ct_test(pTest, test_data.vendorID == private_data.vendorID); ct_test(pTest, test_data.vendorID == private_data.vendorID);
ct_test(pTest, test_data.serviceNumber == private_data.serviceNumber); ct_test(pTest, test_data.serviceNumber == private_data.serviceNumber);
ct_test(pTest, ct_test(pTest,
test_data.serviceParametersLen == private_data.serviceParametersLen); test_data.serviceParametersLen == private_data.serviceParametersLen);
len = bacapp_decode_application_data( len =
test_data.serviceParameters, bacapp_decode_application_data(test_data.serviceParameters,
test_data.serviceParametersLen, test_data.serviceParametersLen, &test_data_value);
&test_data_value);
ct_test(pTest, bacapp_same_value(&data_value, &test_data_value) == true); ct_test(pTest, bacapp_same_value(&data_value, &test_data_value) == true);
} }
@@ -466,25 +470,22 @@ void test_Private_Transfer_Error(
private_data.vendorID = BACNET_VENDOR_ID; private_data.vendorID = BACNET_VENDOR_ID;
private_data.serviceNumber = 1; private_data.serviceNumber = 1;
bacapp_parse_application_data( bacapp_parse_application_data(BACNET_APPLICATION_TAG_OCTET_STRING,
BACNET_APPLICATION_TAG_OCTET_STRING,
&private_data_chunk[0], &data_value); &private_data_chunk[0], &data_value);
private_data_len = bacapp_encode_application_data( private_data_len =
&test_value[0], bacapp_encode_application_data(&test_value[0], &data_value);
&data_value);
private_data.serviceParameters = &test_value[0]; private_data.serviceParameters = &test_value[0];
private_data.serviceParametersLen = private_data_len; private_data.serviceParametersLen = private_data_len;
len = ptransfer_error_encode_apdu(&apdu[0], invoke_id, len =
error_class, error_code, &private_data); ptransfer_error_encode_apdu(&apdu[0], invoke_id, error_class,
error_code, &private_data);
ct_test(pTest, len != 0); ct_test(pTest, len != 0);
ct_test(pTest, len != -1); ct_test(pTest, len != -1);
apdu_len = len; apdu_len = len;
len = ptransfer_error_decode_apdu( len =
&apdu[0], apdu_len, ptransfer_error_decode_apdu(&apdu[0], apdu_len, &test_invoke_id,
&test_invoke_id, &test_error_class, &test_error_code, &test_data);
&test_error_class, &test_error_code,
&test_data);
ct_test(pTest, len != -1); ct_test(pTest, len != -1);
ct_test(pTest, test_invoke_id == invoke_id); ct_test(pTest, test_invoke_id == invoke_id);
ct_test(pTest, test_data.vendorID == private_data.vendorID); ct_test(pTest, test_data.vendorID == private_data.vendorID);
@@ -493,10 +494,9 @@ void test_Private_Transfer_Error(
ct_test(pTest, test_error_code == error_code); ct_test(pTest, test_error_code == error_code);
ct_test(pTest, ct_test(pTest,
test_data.serviceParametersLen == private_data.serviceParametersLen); test_data.serviceParametersLen == private_data.serviceParametersLen);
len = bacapp_decode_application_data( len =
test_data.serviceParameters, bacapp_decode_application_data(test_data.serviceParameters,
test_data.serviceParametersLen, test_data.serviceParametersLen, &test_data_value);
&test_data_value);
ct_test(pTest, bacapp_same_value(&data_value, &test_data_value) == true); ct_test(pTest, bacapp_same_value(&data_value, &test_data_value) == true);
} }
@@ -519,28 +519,26 @@ void test_Private_Transfer_Request(
private_data.vendorID = BACNET_VENDOR_ID; private_data.vendorID = BACNET_VENDOR_ID;
private_data.serviceNumber = 1; private_data.serviceNumber = 1;
bacapp_parse_application_data( bacapp_parse_application_data(BACNET_APPLICATION_TAG_OCTET_STRING,
BACNET_APPLICATION_TAG_OCTET_STRING,
&private_data_chunk[0], &data_value); &private_data_chunk[0], &data_value);
private_data_len = bacapp_encode_application_data( private_data_len =
&test_value[0], bacapp_encode_application_data(&test_value[0], &data_value);
&data_value);
private_data.serviceParameters = &test_value[0]; private_data.serviceParameters = &test_value[0];
private_data.serviceParametersLen = private_data_len; private_data.serviceParametersLen = private_data_len;
len = ptransfer_encode_apdu(&apdu[0], invoke_id, &private_data); len = ptransfer_encode_apdu(&apdu[0], invoke_id, &private_data);
ct_test(pTest, len != 0); ct_test(pTest, len != 0);
apdu_len = len; apdu_len = len;
len = ptransfer_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, &test_data); len =
ptransfer_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, &test_data);
ct_test(pTest, len != -1); ct_test(pTest, len != -1);
ct_test(pTest, test_data.vendorID == private_data.vendorID); ct_test(pTest, test_data.vendorID == private_data.vendorID);
ct_test(pTest, test_data.serviceNumber == private_data.serviceNumber); ct_test(pTest, test_data.serviceNumber == private_data.serviceNumber);
ct_test(pTest, ct_test(pTest,
test_data.serviceParametersLen == private_data.serviceParametersLen); test_data.serviceParametersLen == private_data.serviceParametersLen);
len = bacapp_decode_application_data( len =
test_data.serviceParameters, bacapp_decode_application_data(test_data.serviceParameters,
test_data.serviceParametersLen, test_data.serviceParametersLen, &test_data_value);
&test_data_value);
ct_test(pTest, bacapp_same_value(&data_value, &test_data_value) == true); ct_test(pTest, bacapp_same_value(&data_value, &test_data_value) == true);
return; return;
+24 -16
View File
@@ -119,8 +119,9 @@ int rpm_encode_apdu(
BACNET_PROPERTY_REFERENCE *rpm_property; /* current property */ BACNET_PROPERTY_REFERENCE *rpm_property; /* current property */
len = rpm_encode_apdu_init(&apdu_temp[0], invoke_id); len = rpm_encode_apdu_init(&apdu_temp[0], invoke_id);
len = (int)memcopy(&apdu[0], &apdu_temp[0], len =
(size_t)apdu_len, (size_t)len, (size_t)max_apdu); (int) memcopy(&apdu[0], &apdu_temp[0], (size_t) apdu_len, (size_t) len,
(size_t) max_apdu);
if (len == 0) { if (len == 0) {
return 0; return 0;
} }
@@ -130,16 +131,18 @@ int rpm_encode_apdu(
len = len =
encode_context_object_id(&apdu_temp[0], 0, rpm_object->object_type, encode_context_object_id(&apdu_temp[0], 0, rpm_object->object_type,
rpm_object->object_instance); rpm_object->object_instance);
len = (int)memcopy(&apdu[0], &apdu_temp[0], len =
(size_t)apdu_len, (size_t)len, (size_t)max_apdu); (int) memcopy(&apdu[0], &apdu_temp[0], (size_t) apdu_len,
(size_t) len, (size_t) max_apdu);
if (len == 0) { if (len == 0) {
return 0; return 0;
} }
apdu_len += len; apdu_len += len;
/* Tag 1: sequence of ReadAccessSpecification */ /* Tag 1: sequence of ReadAccessSpecification */
len = encode_opening_tag(&apdu_temp[0], 1); len = encode_opening_tag(&apdu_temp[0], 1);
len = (int)memcopy(&apdu[0], &apdu_temp[0], len =
(size_t)apdu_len, (size_t)len, (size_t)max_apdu); (int) memcopy(&apdu[0], &apdu_temp[0], (size_t) apdu_len,
(size_t) len, (size_t) max_apdu);
if (len == 0) { if (len == 0) {
return 0; return 0;
} }
@@ -150,8 +153,9 @@ int rpm_encode_apdu(
len = len =
encode_context_enumerated(&apdu_temp[0], 0, encode_context_enumerated(&apdu_temp[0], 0,
rpm_property->propertyIdentifier); rpm_property->propertyIdentifier);
len = (int)memcopy(&apdu[0], &apdu_temp[0], len =
(size_t)apdu_len, (size_t)len, (size_t)max_apdu); (int) memcopy(&apdu[0], &apdu_temp[0], (size_t) apdu_len,
(size_t) len, (size_t) max_apdu);
if (len == 0) { if (len == 0) {
return 0; return 0;
} }
@@ -161,8 +165,9 @@ int rpm_encode_apdu(
len = len =
encode_context_unsigned(&apdu_temp[0], 1, encode_context_unsigned(&apdu_temp[0], 1,
rpm_property->propertyArrayIndex); rpm_property->propertyArrayIndex);
len = (int)memcopy(&apdu[0], &apdu_temp[0], len =
(size_t)apdu_len, (size_t)len, (size_t)max_apdu); (int) memcopy(&apdu[0], &apdu_temp[0], (size_t) apdu_len,
(size_t) len, (size_t) max_apdu);
if (len == 0) { if (len == 0) {
return 0; return 0;
} }
@@ -171,8 +176,9 @@ int rpm_encode_apdu(
rpm_property = rpm_property->next; rpm_property = rpm_property->next;
} }
len = encode_closing_tag(&apdu_temp[0], 1); len = encode_closing_tag(&apdu_temp[0], 1);
len = (int)memcopy(&apdu[0], &apdu_temp[0], len =
(size_t)apdu_len, (size_t)len, (size_t)max_apdu); (int) memcopy(&apdu[0], &apdu_temp[0], (size_t) apdu_len,
(size_t) len, (size_t) max_apdu);
if (len == 0) { if (len == 0) {
return 0; return 0;
} }
@@ -261,8 +267,9 @@ int rpm_decode_object_property(
/* Tag 1: Optional propertyArrayIndex */ /* Tag 1: Optional propertyArrayIndex */
if ((len < apdu_len) && decode_is_context_specific(&apdu[len]) && if ((len < apdu_len) && decode_is_context_specific(&apdu[len]) &&
(!decode_is_closing_tag(&apdu[len]))) { (!decode_is_closing_tag(&apdu[len]))) {
option_len = (unsigned)decode_tag_number_and_value( option_len =
&apdu[len], &tag_number, &len_value_type); (unsigned) decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
if (tag_number == 1) { if (tag_number == 1) {
len += option_len; len += option_len;
len += len +=
@@ -453,8 +460,9 @@ int rpm_ack_decode_object_property(
/* Tag 3: Optional propertyArrayIndex */ /* Tag 3: Optional propertyArrayIndex */
if ((len < apdu_len) && decode_is_context_specific(&apdu[len]) && if ((len < apdu_len) && decode_is_context_specific(&apdu[len]) &&
(!decode_is_closing_tag(&apdu[len]))) { (!decode_is_closing_tag(&apdu[len]))) {
tag_len = (unsigned)decode_tag_number_and_value( tag_len =
&apdu[len], &tag_number, &len_value_type); (unsigned) decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
if (tag_number == 3) { if (tag_number == 3) {
len += tag_len; len += tag_len;
len += len +=