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
+3 -3
View File
@@ -52,9 +52,9 @@ void handler_i_am_add(
#endif #endif
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 {
+14 -20
View File
@@ -43,12 +43,12 @@ bool handler_lso(
BACNET_ADDRESS * src, BACNET_ADDRESS * src,
BACNET_CONFIRMED_SERVICE_DATA * service_data) BACNET_CONFIRMED_SERVICE_DATA * service_data)
{ {
BACNET_LSO_DATA data; BACNET_LSO_DATA data;
int len = 0; int len = 0;
int pdu_len = 0; int pdu_len = 0;
BACNET_NPDU_DATA npdu_data; BACNET_NPDU_DATA npdu_data;
int bytes_sent = 0; int bytes_sent = 0;
BACNET_ADDRESS my_address; BACNET_ADDRESS my_address;
/* encode the NPDU portion of the packet */ /* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address); datalink_get_my_address(&my_address);
@@ -84,24 +84,20 @@ bool handler_lso(
goto LSO_ABORT; goto LSO_ABORT;
} }
/* /*
** Process Life Safety Operation Here ** Process Life Safety Operation Here
*/ */
#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 {
+14 -16
View File
@@ -50,10 +50,10 @@ static int rpm_ack_decode_service_request(
BACNET_READ_ACCESS_DATA * read_access_data) BACNET_READ_ACCESS_DATA * read_access_data)
{ {
int decoded_len = 0; /* return value */ int decoded_len = 0; /* return value */
uint32_t error_value = 0; /* decoded error value */ uint32_t error_value = 0; /* decoded error value */
int len = 0; /* number of bytes returned from decoding */ int len = 0; /* number of bytes returned from decoding */
uint8_t tag_number = 0; /* decoded tag number */ uint8_t tag_number = 0; /* decoded tag number */
uint32_t len_value = 0; /* decoded length value */ uint32_t len_value = 0; /* decoded length value */
BACNET_READ_ACCESS_DATA *rpm_object; BACNET_READ_ACCESS_DATA *rpm_object;
BACNET_READ_ACCESS_DATA *old_rpm_object; BACNET_READ_ACCESS_DATA *old_rpm_object;
BACNET_PROPERTY_REFERENCE *rpm_property; BACNET_PROPERTY_REFERENCE *rpm_property;
@@ -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,13 +148,12 @@ 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;
/* FIXME: we could validate that the tag is enumerated... */ /* FIXME: we could validate that the tag is enumerated... */
len = decode_enumerated(apdu, len_value, &error_value); len = decode_enumerated(apdu, len_value, &error_value);
rpm_property->error.error_code = error_value; rpm_property->error.error_code = error_value;
decoded_len += len; decoded_len += len;
apdu_len -= len; apdu_len -= 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 =
+28 -32
View File
@@ -99,11 +99,12 @@ 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;
timeOut.tv_sec = milliseconds/1000; timeOut.tv_sec = milliseconds / 1000;
timeOut.tv_nsec = (milliseconds - (timeOut.tv_sec * 1000)) * 10000000; timeOut.tv_nsec = (milliseconds - (timeOut.tv_sec * 1000)) * 10000000;
nanosleep(&timeOut, &remains); nanosleep(&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;
@@ -173,13 +175,9 @@ static void filename_create(char *filename)
if (filename) { if (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);
} }
} }
@@ -198,13 +196,13 @@ static void write_global_header(
/* create a new file. */ /* create a new file. */
pFile = fopen(filename, "wb"); pFile = fopen(filename, "wb");
if (pFile) { if (pFile) {
(void)fwrite(&magic_number, sizeof(magic_number), 1, pFile); (void) fwrite(&magic_number, sizeof(magic_number), 1, pFile);
(void)fwrite(&version_major, sizeof(version_major), 1, pFile); (void) fwrite(&version_major, sizeof(version_major), 1, pFile);
(void)fwrite(&version_minor, sizeof(version_minor), 1, pFile); (void) fwrite(&version_minor, sizeof(version_minor), 1, pFile);
(void)fwrite(&thiszone, sizeof(thiszone), 1, pFile); (void) fwrite(&thiszone, sizeof(thiszone), 1, pFile);
(void)fwrite(&sigfigs, sizeof(sigfigs), 1, pFile); (void) fwrite(&sigfigs, sizeof(sigfigs), 1, pFile);
(void)fwrite(&snaplen, sizeof(snaplen), 1, pFile); (void) fwrite(&snaplen, sizeof(snaplen), 1, pFile);
(void)fwrite(&network, sizeof(network), 1, pFile); (void) fwrite(&network, sizeof(network), 1, pFile);
fflush(pFile); fflush(pFile);
fprintf(stdout, "mstpcap: saving capture to %s\n", filename); fprintf(stdout, "mstpcap: saving capture to %s\n", filename);
} else { } else {
@@ -228,16 +226,16 @@ static void write_received_packet(
gettimeofday(&tv, NULL); gettimeofday(&tv, NULL);
ts_sec = tv.tv_sec; ts_sec = tv.tv_sec;
ts_usec = tv.tv_usec; ts_usec = tv.tv_usec;
(void)fwrite(&ts_sec, sizeof(ts_sec), 1, pFile); (void) fwrite(&ts_sec, sizeof(ts_sec), 1, pFile);
(void)fwrite(&ts_usec, sizeof(ts_usec), 1, pFile); (void) fwrite(&ts_usec, sizeof(ts_usec), 1, pFile);
if (mstp_port->DataLength) { if (mstp_port->DataLength) {
max_data = min(mstp_port->InputBufferSize, mstp_port->DataLength); max_data = min(mstp_port->InputBufferSize, mstp_port->DataLength);
incl_len = orig_len = 8 + max_data + 2; incl_len = orig_len = 8 + max_data + 2;
} else { } else {
incl_len = orig_len = 8; incl_len = orig_len = 8;
} }
(void)fwrite(&incl_len, sizeof(incl_len), 1, pFile); (void) fwrite(&incl_len, sizeof(incl_len), 1, pFile);
(void)fwrite(&orig_len, sizeof(orig_len), 1, pFile); (void) fwrite(&orig_len, sizeof(orig_len), 1, pFile);
header[0] = 0x55; header[0] = 0x55;
header[1] = 0xFF; header[1] = 0xFF;
header[2] = mstp_port->FrameType; header[2] = mstp_port->FrameType;
@@ -246,11 +244,11 @@ static void write_received_packet(
header[5] = HI_BYTE(mstp_port->DataLength); header[5] = HI_BYTE(mstp_port->DataLength);
header[6] = LO_BYTE(mstp_port->DataLength); header[6] = LO_BYTE(mstp_port->DataLength);
header[7] = mstp_port->HeaderCRCActual; header[7] = mstp_port->HeaderCRCActual;
(void)fwrite(header, sizeof(header), 1, pFile); (void) fwrite(header, sizeof(header), 1, pFile);
if (mstp_port->DataLength) { if (mstp_port->DataLength) {
(void)fwrite(mstp_port->InputBuffer, max_data, 1, pFile); (void) fwrite(mstp_port->InputBuffer, max_data, 1, pFile);
(void)fwrite((char *) &mstp_port->DataCRCActualMSB, 1, 1, pFile); (void) fwrite((char *) &mstp_port->DataCRCActualMSB, 1, 1, pFile);
(void)fwrite((char *) &mstp_port->DataCRCActualLSB, 1, 1, pFile); (void) fwrite((char *) &mstp_port->DataCRCActualLSB, 1, 1, pFile);
} }
} else { } else {
fprintf(stderr, "mstpcap: failed to open %s: %s\n", Capture_Filename, fprintf(stderr, "mstpcap: failed to open %s: %s\n", Capture_Filename,
@@ -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 -2
View File
@@ -174,14 +174,14 @@ static void Init_DataLink(
pEnv = getenv("BACNET_MSTP_BAUD"); pEnv = getenv("BACNET_MSTP_BAUD");
if (pEnv) { if (pEnv) {
RS485_Set_Baud_Rate(strtol(pEnv, NULL, 0)); RS485_Set_Baud_Rate(strtol(pEnv, NULL, 0));
fprintf(stderr, "BACNET_MSTP_BAUD=%s\r\n",pEnv); fprintf(stderr, "BACNET_MSTP_BAUD=%s\r\n", pEnv);
} else { } else {
RS485_Set_Baud_Rate(38400); RS485_Set_Baud_Rate(38400);
} }
pEnv = getenv("BACNET_APDU_TIMEOUT"); pEnv = getenv("BACNET_APDU_TIMEOUT");
if (pEnv) { if (pEnv) {
apdu_timeout_set(strtol(pEnv, NULL, 0)); apdu_timeout_set(strtol(pEnv, NULL, 0));
fprintf(stderr, "BACNET_APDU_TIMEOUT=%s\r\n",pEnv); fprintf(stderr, "BACNET_APDU_TIMEOUT=%s\r\n", pEnv);
} }
pEnv = getenv("BACNET_MSTP_MAC"); pEnv = getenv("BACNET_MSTP_MAC");
if (pEnv) { if (pEnv) {
+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);
+1 -1
View File
@@ -100,7 +100,7 @@ typedef struct BACnet_Property_Reference {
BACNET_PROPERTY_ID propertyIdentifier; BACNET_PROPERTY_ID propertyIdentifier;
int32_t propertyArrayIndex; /* optional */ int32_t propertyArrayIndex; /* optional */
/* either value or error, but not both. /* either value or error, but not both.
Use NULL value to indicate error */ Use NULL value to indicate error */
BACNET_APPLICATION_DATA_VALUE *value; BACNET_APPLICATION_DATA_VALUE *value;
BACNET_ACCESS_ERROR error; BACNET_ACCESS_ERROR error;
/* simple linked list */ /* simple linked list */
+2 -2
View File
@@ -288,11 +288,11 @@ extern "C" {
int decode_enumerated( int decode_enumerated(
uint8_t * apdu, uint8_t * apdu,
uint32_t len_value, uint32_t len_value,
uint32_t *value); uint32_t * value);
int decode_context_enumerated( int decode_context_enumerated(
uint8_t * apdu, uint8_t * apdu,
uint8_t tag_value, uint8_t tag_value,
uint32_t *value); uint32_t * value);
int encode_bacnet_enumerated( int encode_bacnet_enumerated(
uint8_t * apdu, uint8_t * apdu,
uint32_t value); uint32_t value);
+3 -5
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
+20 -21
View File
@@ -92,30 +92,29 @@
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
int datalink_send_pdu( int datalink_send_pdu(
BACNET_ADDRESS * dest, BACNET_ADDRESS * dest,
BACNET_NPDU_DATA * npdu_data, BACNET_NPDU_DATA * npdu_data,
uint8_t * pdu, uint8_t * pdu,
unsigned pdu_len); unsigned pdu_len);
extern uint16_t datalink_receive( extern uint16_t datalink_receive(
BACNET_ADDRESS * src, BACNET_ADDRESS * src,
uint8_t * pdu, uint8_t * pdu,
uint16_t max_pdu, uint16_t max_pdu,
unsigned timeout); unsigned timeout);
extern void datalink_cleanup( extern void datalink_cleanup(
void); void);
extern void datalink_get_broadcast_address( extern void datalink_get_broadcast_address(
BACNET_ADDRESS * dest); BACNET_ADDRESS * dest);
extern void datalink_get_my_address( extern void datalink_get_my_address(
BACNET_ADDRESS * my_address); BACNET_ADDRESS * my_address);
extern void datalink_set_interface( extern void datalink_set_interface(
char *ifname); char *ifname);
extern void datalink_set( extern void datalink_set(
char *datalink_string); char *datalink_string);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */
#endif #endif
#endif #endif
+12 -12
View File
@@ -46,10 +46,10 @@
#include <stdbool.h> #include <stdbool.h>
struct fifo_buffer_t { struct fifo_buffer_t {
volatile unsigned head; /* first byte of data */ volatile unsigned head; /* first byte of data */
volatile unsigned tail; /* last byte of data */ volatile unsigned tail; /* last byte of data */
volatile uint8_t *buffer; /* block of memory or array of data */ volatile uint8_t *buffer; /* block of memory or array of data */
unsigned buffer_len; /* length of the data */ unsigned buffer_len; /* length of the data */
}; };
typedef struct fifo_buffer_t FIFO_BUFFER; typedef struct fifo_buffer_t FIFO_BUFFER;
@@ -57,31 +57,31 @@ typedef struct fifo_buffer_t FIFO_BUFFER;
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
bool FIFO_Empty( bool FIFO_Empty(
FIFO_BUFFER const *b); FIFO_BUFFER const *b);
uint8_t FIFO_Peek( uint8_t FIFO_Peek(
FIFO_BUFFER const *b); FIFO_BUFFER const *b);
uint8_t FIFO_Get( uint8_t FIFO_Get(
FIFO_BUFFER * b); FIFO_BUFFER * b);
bool FIFO_Put( bool FIFO_Put(
FIFO_BUFFER * b, FIFO_BUFFER * b,
uint8_t data_byte); uint8_t data_byte);
bool FIFO_Add( bool FIFO_Add(
FIFO_BUFFER * b, FIFO_BUFFER * b,
uint8_t *data_bytes, uint8_t * data_bytes,
unsigned count); unsigned count);
void FIFO_Flush( void FIFO_Flush(
FIFO_BUFFER * b); FIFO_BUFFER * b);
/* note: buffer_len must be a power of two */ /* note: buffer_len must be a power of two */
void FIFO_Init( void FIFO_Init(
FIFO_BUFFER * b, FIFO_BUFFER * b,
volatile uint8_t *buffer, volatile uint8_t * buffer,
unsigned buffer_len); unsigned buffer_len);
#ifdef __cplusplus #ifdef __cplusplus
+7 -7
View File
@@ -169,13 +169,13 @@ extern "C" {
uint8_t * service_request, uint8_t * service_request,
uint16_t service_len, uint16_t service_len,
BACNET_ADDRESS * src); BACNET_ADDRESS * src);
bool handler_lso( bool handler_lso(
uint8_t * service_request, uint8_t * service_request,
uint16_t service_len, uint16_t service_len,
BACNET_ADDRESS * src, BACNET_ADDRESS * src,
BACNET_CONFIRMED_SERVICE_DATA * service_data); BACNET_CONFIRMED_SERVICE_DATA * service_data);
#ifdef __cplusplus #ifdef __cplusplus
} }
+30 -31
View File
@@ -58,63 +58,62 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
/* returns head of the list or NULL on failure. */ /* returns head of the list or NULL on failure. */
OS_Keylist Keylist_Create( OS_Keylist Keylist_Create(
void); void);
/* delete specified list */ /* delete specified list */
/* note: you should pop all the nodes off the list first. */ /* note: you should pop all the nodes off the list first. */
void Keylist_Delete( void Keylist_Delete(
OS_Keylist list); OS_Keylist list);
/* inserts a node into its sorted position */ /* inserts a node into its sorted position */
/* returns the index where it was added */ /* returns the index where it was added */
int Keylist_Data_Add( int Keylist_Data_Add(
OS_Keylist list, OS_Keylist list,
KEY key, KEY key,
void *data); void *data);
/* deletes a node specified by its key */ /* deletes a node specified by its key */
/* returns the data from the node */ /* returns the data from the node */
void *Keylist_Data_Delete( void *Keylist_Data_Delete(
OS_Keylist list, OS_Keylist list,
KEY key); KEY key);
/* deletes a node specified by its index */ /* deletes a node specified by its index */
/* returns the data from the node */ /* returns the data from the node */
void *Keylist_Data_Delete_By_Index( void *Keylist_Data_Delete_By_Index(
OS_Keylist list, OS_Keylist list,
int index); int index);
/* returns the data from last node, and removes it from the list */ /* returns the data from last node, and removes it from the list */
void *Keylist_Data_Pop( void *Keylist_Data_Pop(
OS_Keylist list); OS_Keylist list);
/* returns the data from the node specified by key */ /* returns the data from the node specified by key */
void *Keylist_Data( void *Keylist_Data(
OS_Keylist list, OS_Keylist list,
KEY key); KEY key);
/* returns the data specified by key */ /* returns the data specified by key */
void *Keylist_Data_Index( void *Keylist_Data_Index(
OS_Keylist list, OS_Keylist list,
int index); int index);
/* return the key at the given index */ /* return the key at the given index */
KEY Keylist_Key( KEY Keylist_Key(
OS_Keylist list, OS_Keylist list,
int index); int index);
/* returns the next empty key from the list */ /* returns the next empty key from the list */
KEY Keylist_Next_Empty_Key( KEY Keylist_Next_Empty_Key(
OS_Keylist list, OS_Keylist list,
KEY key); KEY key);
/* returns the number of items in the list */ /* returns the number of items in the list */
int Keylist_Count( int Keylist_Count(
OS_Keylist list); OS_Keylist list);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */
#endif #endif
+14 -15
View File
@@ -46,24 +46,23 @@ 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; BACNET_OBJECT_ID targetObject;
BACNET_OBJECT_ID targetObject; } BACNET_LSO_DATA;
} BACNET_LSO_DATA;
int lso_encode_adpu( int lso_encode_adpu(
uint8_t *apdu, uint8_t * apdu,
uint8_t invoke_id, uint8_t invoke_id,
BACNET_LSO_DATA *data); BACNET_LSO_DATA * data);
/* decode the service request only */ /* decode the service request only */
int lso_decode_service_request( int lso_decode_service_request(
uint8_t *apdu, uint8_t * apdu,
unsigned apdu_len, unsigned apdu_len,
BACNET_LSO_DATA *data); BACNET_LSO_DATA * data);
#ifdef TEST #ifdef TEST
+5 -5
View File
@@ -62,7 +62,7 @@ extern "C" {
uint8_t invoke_id, uint8_t invoke_id,
BACNET_ERROR_CLASS error_class, BACNET_ERROR_CLASS error_class,
BACNET_ERROR_CODE error_code, BACNET_ERROR_CODE error_code,
BACNET_PRIVATE_TRANSFER_DATA *private_data); BACNET_PRIVATE_TRANSFER_DATA * private_data);
int ptransfer_error_decode_service_request( int ptransfer_error_decode_service_request(
uint8_t * apdu, uint8_t * apdu,
unsigned apdu_len, unsigned apdu_len,
@@ -73,18 +73,18 @@ extern "C" {
int ptransfer_ack_encode_apdu( int ptransfer_ack_encode_apdu(
uint8_t * apdu, uint8_t * apdu,
uint8_t invoke_id, uint8_t invoke_id,
BACNET_PRIVATE_TRANSFER_DATA *private_data); BACNET_PRIVATE_TRANSFER_DATA * private_data);
/* ptransfer_ack_decode_service_request() is the same as /* ptransfer_ack_decode_service_request() is the same as
ptransfer_decode_service_request */ ptransfer_decode_service_request */
#ifdef TEST #ifdef TEST
#include "ctest.h" #include "ctest.h"
void test_Private_Transfer_Request( void test_Private_Transfer_Request(
Test * pTest); Test * pTest);
void test_Private_Transfer_Ack( void test_Private_Transfer_Ack(
Test * pTest); Test * pTest);
void test_Private_Transfer_Error( void test_Private_Transfer_Error(
Test * pTest); Test * pTest);
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
+2 -3
View File
@@ -17,11 +17,10 @@
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
void DLL_EXPORT SomeFunction( void DLL_EXPORT SomeFunction(
const LPCSTR sometext); const LPCSTR sometext);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */
#endif #endif
+5 -9
View File
@@ -267,18 +267,14 @@ 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 */
if (argc > 1) { if (argc > 1) {
RS485_Set_Interface(argv[1]); RS485_Set_Interface(argv[1]);
+1 -1
View File
@@ -246,7 +246,7 @@ void RS485_Initialize(
Open device for reading and writing. Open device for reading and writing.
Blocking mode - more CPU effecient Blocking mode - more CPU effecient
*/ */
RS485_Handle = open(RS485_Port_Name, O_RDWR | O_NOCTTY /*| O_NDELAY*/); RS485_Handle = open(RS485_Port_Name, O_RDWR | O_NOCTTY /*| O_NDELAY */ );
if (RS485_Handle < 0) { if (RS485_Handle < 0) {
perror(RS485_Port_Name); perror(RS485_Port_Name);
exit(-1); exit(-1);
+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 {
+4 -4
View File
@@ -260,10 +260,10 @@ void main(
Hardware_Initialize(); Hardware_Initialize();
Initialize_Variables(); Initialize_Variables();
/* initialize BACnet Data Link Layer */ /* initialize BACnet Data Link Layer */
dlmstp_set_my_address(42); dlmstp_set_my_address(42);
dlmstp_set_max_info_frames(1); dlmstp_set_max_info_frames(1);
dlmstp_set_max_master(127); dlmstp_set_max_master(127);
RS485_Set_Baud_Rate(38400); RS485_Set_Baud_Rate(38400);
dlmstp_init(); dlmstp_init();
/* Handle anything that needs to be done on powerup */ /* Handle anything that needs to be done on powerup */
/* Greet the BACnet world! */ /* Greet the BACnet world! */
+1 -1
View File
@@ -89,7 +89,7 @@ int dlmstp_send_pdu(
return -2; return -2;
} }
/* header len */ /* header len */
mtu_len = MAX_HEADER - 2 /* data crc */; mtu_len = MAX_HEADER - 2 /* data crc */ ;
if ((MAX_HEADER + pdu_len) > MAX_MPDU) { if ((MAX_HEADER + pdu_len) > MAX_MPDU) {
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "mstp: PDU is too big to send!\n"); fprintf(stderr, "mstp: PDU is too big to send!\n");
+34 -33
View File
@@ -54,39 +54,40 @@ 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 * src) BACNET_ADDRESS * dest,
BACNET_ADDRESS * src)
{ {
uint8_t i = 0; uint8_t i = 0;
uint8_t max_len = 0; uint8_t max_len = 0;
if (dest->mac_len != src->mac_len) if (dest->mac_len != src->mac_len)
return false; return false;
max_len = dest->mac_len; max_len = dest->mac_len;
if (max_len > MAX_MAC_LEN) if (max_len > MAX_MAC_LEN)
max_len = MAX_MAC_LEN; max_len = MAX_MAC_LEN;
for (i = 0; i < max_len; i++) { for (i = 0; i < max_len; i++) {
if (dest->mac[i] != src->mac[i]) if (dest->mac[i] != src->mac[i])
return false; return false;
} }
if (dest->net != src->net) if (dest->net != src->net)
return false; return false;
/* if local, ignore remaining fields */ /* if local, ignore remaining fields */
if (dest->net == 0) if (dest->net == 0)
return true; return true;
if (dest->len != src->len) if (dest->len != src->len)
return false; return false;
max_len = dest->len; max_len = dest->len;
if (max_len > MAX_MAC_LEN) if (max_len > MAX_MAC_LEN)
max_len = MAX_MAC_LEN; max_len = MAX_MAC_LEN;
for (i = 0; i < max_len; i++) { for (i = 0; i < max_len; i++) {
if (dest->adr[i] != src->adr[i]) if (dest->adr[i] != src->adr[i])
return false; return false;
} }
return true; return true;
} }
void address_remove_device( void address_remove_device(
@@ -129,7 +130,7 @@ void address_file_init(
pFile = fopen(pFilename, "r"); pFile = fopen(pFilename, "r");
if (pFile) { if (pFile) {
while (fgets(line, (int)sizeof(line), pFile) != NULL) { while (fgets(line, (int) sizeof(line), pFile) != NULL) {
/* ignore comments */ /* ignore comments */
if (line[0] != ';') { if (line[0] != ';') {
if (sscanf(line, "%ld %s %d %s %u", &device_id, &mac_string[0], if (sscanf(line, "%ld %s %d %s %u", &device_id, &mac_string[0],
@@ -137,16 +138,16 @@ void address_file_init(
count = count =
sscanf(mac_string, "%x:%x:%x:%x:%x:%x", &mac[0], sscanf(mac_string, "%x:%x:%x:%x:%x:%x", &mac[0],
&mac[1], &mac[2], &mac[3], &mac[4], &mac[5]); &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]);
src.mac_len = (uint8_t)count; src.mac_len = (uint8_t) count;
for (index = 0; index < MAX_MAC_LEN; index++) { for (index = 0; index < MAX_MAC_LEN; index++) {
src.mac[index] = mac[index]; src.mac[index] = mac[index];
} }
src.net = (uint16_t)snet; src.net = (uint16_t) snet;
if (snet) { if (snet) {
count = count =
sscanf(sadr_string, "%x:%x:%x:%x:%x:%x", &mac[0], sscanf(sadr_string, "%x:%x:%x:%x:%x:%x", &mac[0],
&mac[1], &mac[2], &mac[3], &mac[4], &mac[5]); &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]);
src.len = (uint8_t)count; src.len = (uint8_t) count;
for (index = 0; index < MAX_MAC_LEN; index++) { for (index = 0; index < MAX_MAC_LEN; index++) {
src.adr[index] = mac[index]; src.adr[index] = mac[index];
} }
@@ -156,7 +157,7 @@ void address_file_init(
src.adr[index] = 0; src.adr[index] = 0;
} }
} }
address_add((uint32_t)device_id, max_apdu, &src); address_add((uint32_t) device_id, max_apdu, &src);
} }
} }
} }
+2 -2
View File
@@ -60,8 +60,8 @@ bool bacnet_address_same(
BACNET_ADDRESS * dest, BACNET_ADDRESS * dest,
BACNET_ADDRESS * src) BACNET_ADDRESS * src)
{ {
uint8_t i = 0; /* loop counter */ uint8_t i = 0; /* loop counter */
uint8_t max_len = 0; /* used for dynamic max */ uint8_t max_len = 0; /* used for dynamic max */
bool match = true; /* return value */ bool match = true; /* return value */
if (dest->mac_len != src->mac_len) if (dest->mac_len != src->mac_len)
+3 -3
View File
@@ -135,7 +135,7 @@ int bacapp_encode_application_data(
case BACNET_APPLICATION_TAG_OBJECT_ID: case BACNET_APPLICATION_TAG_OBJECT_ID:
apdu_len = apdu_len =
encode_application_object_id(&apdu[0], encode_application_object_id(&apdu[0],
(int)value->type.Object_Id.type, (int) value->type.Object_Id.type,
value->type.Object_Id.instance); value->type.Object_Id.instance);
break; break;
#endif #endif
@@ -376,7 +376,7 @@ int bacapp_encode_context_data_value(
case BACNET_APPLICATION_TAG_OBJECT_ID: case BACNET_APPLICATION_TAG_OBJECT_ID:
apdu_len = apdu_len =
encode_context_object_id(&apdu[0], context_tag_number, encode_context_object_id(&apdu[0], context_tag_number,
(int)value->type.Object_Id.type, (int) value->type.Object_Id.type,
value->type.Object_Id.instance); value->type.Object_Id.instance);
break; break;
#endif #endif
@@ -686,7 +686,7 @@ int bacapp_data_len(
break; break;
} }
} }
if ((unsigned)apdu_len > max_apdu_len) { if ((unsigned) apdu_len > max_apdu_len) {
/* error: exceeding our buffer limit */ /* error: exceeding our buffer limit */
total_len = -1; total_len = -1;
break; break;
+50 -35
View File
@@ -682,7 +682,7 @@ int encode_application_bitstring(
BACNET_BIT_STRING * bit_string) BACNET_BIT_STRING * bit_string)
{ {
int len = 0; int len = 0;
uint32_t bit_string_encoded_length = 1; /* 1 for the bits remaining octet */ uint32_t bit_string_encoded_length = 1; /* 1 for the bits remaining octet */
/* 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);
@@ -700,13 +700,11 @@ int encode_context_bitstring(
BACNET_BIT_STRING * bit_string) BACNET_BIT_STRING * bit_string)
{ {
int len = 0; int len = 0;
uint32_t bit_string_encoded_length = 1; /* 1 for the bits remaining octet */ uint32_t bit_string_encoded_length = 1; /* 1 for the bits remaining octet */
/* 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;
@@ -757,7 +755,7 @@ int encode_bacnet_object_id(
uint32_t type = 0; uint32_t type = 0;
int len = 0; int len = 0;
type = (uint32_t)object_type; type = (uint32_t) object_type;
value = value =
((type & BACNET_MAX_OBJECT) << BACNET_INSTANCE_BITS) | (instance & ((type & BACNET_MAX_OBJECT) << BACNET_INSTANCE_BITS) | (instance &
BACNET_MAX_INSTANCE); BACNET_MAX_INSTANCE);
@@ -781,7 +779,7 @@ int encode_context_object_id(
len = encode_bacnet_object_id(&apdu[1], object_type, instance); len = encode_bacnet_object_id(&apdu[1], object_type, instance);
/* we only reserved 1 byte for encoding the tag - check the limits */ /* we only reserved 1 byte for encoding the tag - check the limits */
if ((tag_number <= 14) && (len <= 4)) { if ((tag_number <= 14) && (len <= 4)) {
len += encode_tag(&apdu[0], tag_number, true, (uint32_t)len); len += encode_tag(&apdu[0], tag_number, true, (uint32_t) len);
} else { } else {
len = 0; len = 0;
} }
@@ -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;
} }
@@ -819,7 +819,7 @@ int encode_octet_string(
if (octet_string) { if (octet_string) {
/* FIXME: might need to pass in the length of the APDU /* FIXME: might need to pass in the length of the APDU
to bounds check since it might not be the only data chunk */ to bounds check since it might not be the only data chunk */
len = (int)octetstring_length(octet_string); len = (int) octetstring_length(octet_string);
value = octetstring_value(octet_string); value = octetstring_value(octet_string);
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
apdu[i] = value[i]; apdu[i] = value[i];
@@ -891,7 +891,7 @@ int decode_octet_string(
status = octetstring_init(octet_string, &apdu[0], len_value); status = octetstring_init(octet_string, &apdu[0], len_value);
if (status) { if (status) {
len = (int)len_value; len = (int) len_value;
} }
return len; return len;
@@ -931,11 +931,11 @@ int encode_bacnet_character_string(
int len, i; int len, i;
char *pString; char *pString;
len = (int)characterstring_length(char_string); len = (int) characterstring_length(char_string);
apdu[0] = characterstring_encoding(char_string); apdu[0] = characterstring_encoding(char_string);
pString = characterstring_value(char_string); pString = characterstring_value(char_string);
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
apdu[1 + i] = (uint8_t)pString[i]; apdu[1 + i] = (uint8_t) pString[i];
} }
return len + 1 /* for encoding */ ; return len + 1 /* for encoding */ ;
@@ -951,10 +951,11 @@ 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);
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);
} else { } else {
@@ -972,8 +973,9 @@ 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 =
len += encode_tag(&apdu[0], tag_number, true, (uint32_t)string_len); (int) characterstring_length(char_string) + 1 /* for encoding */ ;
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);
} else { } else {
@@ -998,7 +1000,7 @@ int decode_character_string(
characterstring_init(char_string, apdu[0], (char *) &apdu[1], characterstring_init(char_string, apdu[0], (char *) &apdu[1],
len_value - 1); len_value - 1);
if (status) { if (status) {
len = (int)len_value; len = (int) len_value;
} }
return len; return len;
@@ -1061,7 +1063,7 @@ int decode_unsigned(
} }
} }
return (int)len_value; return (int) len_value;
} }
int decode_context_unsigned( int decode_context_unsigned(
@@ -1119,7 +1121,7 @@ int encode_context_unsigned(
len = encode_bacnet_unsigned(&apdu[1], value); len = encode_bacnet_unsigned(&apdu[1], value);
/* we only reserved 1 byte for encoding the tag - check the limits */ /* we only reserved 1 byte for encoding the tag - check the limits */
if ((tag_number <= 14) && (len <= 4)) { if ((tag_number <= 14) && (len <= 4)) {
len += encode_tag(&apdu[0], tag_number, true, (uint32_t)len); len += encode_tag(&apdu[0], tag_number, true, (uint32_t) len);
} else { } else {
len = 0; len = 0;
} }
@@ -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;
} }
@@ -1149,7 +1152,7 @@ int encode_application_unsigned(
int decode_enumerated( int decode_enumerated(
uint8_t * apdu, uint8_t * apdu,
uint32_t len_value, uint32_t len_value,
uint32_t *value) uint32_t * value)
{ {
uint32_t unsigned_value = 0; uint32_t unsigned_value = 0;
int len; int len;
@@ -1165,7 +1168,7 @@ int decode_enumerated(
int decode_context_enumerated( int decode_context_enumerated(
uint8_t * apdu, uint8_t * apdu,
uint8_t tag_value, uint8_t tag_value,
uint32_t *value) uint32_t * value)
{ {
int len = 0; int len = 0;
uint8_t tag_number; uint8_t tag_number;
@@ -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;
} }
@@ -1221,7 +1226,7 @@ int encode_context_enumerated(
len = encode_bacnet_enumerated(&apdu[1], value); len = encode_bacnet_enumerated(&apdu[1], value);
/* we only reserved 1 byte for encoding the tag - check the limits */ /* we only reserved 1 byte for encoding the tag - check the limits */
if ((tag_number <= 14) && (len <= 4)) { if ((tag_number <= 14) && (len <= 4)) {
len += encode_tag(&apdu[0], tag_number, true, (uint32_t)len); len += encode_tag(&apdu[0], tag_number, true, (uint32_t) len);
} else { } else {
len = 0; len = 0;
} }
@@ -1257,7 +1262,7 @@ int decode_signed(
} }
} }
return (int)len_value; return (int) len_value;
} }
int decode_context_signed( int decode_context_signed(
@@ -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;
} }
@@ -1335,7 +1342,7 @@ int encode_context_signed(
len = encode_bacnet_signed(&apdu[1], value); len = encode_bacnet_signed(&apdu[1], value);
/* we only reserved 1 byte for encoding the tag - check the limits */ /* we only reserved 1 byte for encoding the tag - check the limits */
if ((tag_number <= 14) && (len <= 4)) { if ((tag_number <= 14) && (len <= 4)) {
len += encode_tag(&apdu[0], tag_number, true, (uint32_t)len); len += encode_tag(&apdu[0], tag_number, true, (uint32_t) len);
} else { } else {
len = 0; len = 0;
} }
@@ -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;
} }
@@ -1370,7 +1379,7 @@ int encode_context_real(
len = encode_bacnet_real(value, &apdu[1]); len = encode_bacnet_real(value, &apdu[1]);
/* we only reserved 1 byte for encoding the tag - check the limits */ /* we only reserved 1 byte for encoding the tag - check the limits */
if (tag_number <= 14) { if (tag_number <= 14) {
len += encode_tag(&apdu[0], tag_number, true, (uint32_t)len); len += encode_tag(&apdu[0], tag_number, true, (uint32_t) len);
} else { } else {
len = 0; len = 0;
} }
@@ -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;
} }
@@ -1405,7 +1416,7 @@ int encode_context_double(
len = encode_bacnet_double(value, &apdu[1]); len = encode_bacnet_double(value, &apdu[1]);
/* we only reserved 1 byte for encoding the tag - check the limits */ /* we only reserved 1 byte for encoding the tag - check the limits */
if (tag_number <= 14) { if (tag_number <= 14) {
len += encode_tag(&apdu[0], tag_number, true, (uint32_t)len); len += encode_tag(&apdu[0], tag_number, true, (uint32_t) len);
} else { } else {
len = 0; len = 0;
} }
@@ -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;
} }
@@ -1455,7 +1468,7 @@ int encode_context_time(
len = encode_bacnet_time(&apdu[1], btime); len = encode_bacnet_time(&apdu[1], btime);
/* we only reserved 1 byte for encoding the tag - check the limits */ /* we only reserved 1 byte for encoding the tag - check the limits */
if ((tag_number <= 14) && (len <= 4)) { if ((tag_number <= 14) && (len <= 4)) {
len += encode_tag(&apdu[0], tag_number, true, (uint32_t)len); len += encode_tag(&apdu[0], tag_number, true, (uint32_t) len);
} else { } else {
len = 0; len = 0;
} }
@@ -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;
@@ -1575,7 +1590,7 @@ int encode_context_date(
len = encode_bacnet_date(&apdu[1], bdate); len = encode_bacnet_date(&apdu[1], bdate);
/* we only reserved 1 byte for encoding the tag - check the limits */ /* we only reserved 1 byte for encoding the tag - check the limits */
if ((tag_number <= 14) && (len <= 4)) { if ((tag_number <= 14) && (len <= 4)) {
len += encode_tag(&apdu[0], tag_number, true, (uint32_t)len); len += encode_tag(&apdu[0], tag_number, true, (uint32_t) len);
} else { } else {
len = 0; len = 0;
} }
+3 -2
View File
@@ -68,7 +68,7 @@ int bacapp_encode_device_obj_property_ref(
len = len =
encode_context_object_id(&apdu[apdu_len], 0, encode_context_object_id(&apdu[apdu_len], 0,
(int)value->objectIdentifier.type, value->objectIdentifier.instance); (int) value->objectIdentifier.type, value->objectIdentifier.instance);
apdu_len += len; apdu_len += len;
len = len =
@@ -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;
+1 -1
View File
@@ -301,7 +301,7 @@ int bacapp_encode_property_state(
} }
#ifdef TEST #ifdef TEST
#include <string.h> /* for memset */ #include <string.h> /* for memset */
void testPropStates( void testPropStates(
Test * pTest) Test * pTest)
+5 -5
View File
@@ -68,7 +68,7 @@ static int notify_encode_adpu(
/* tag 2 - monitoredObjectIdentifier */ /* tag 2 - monitoredObjectIdentifier */
len = len =
encode_context_object_id(&apdu[apdu_len], 2, encode_context_object_id(&apdu[apdu_len], 2,
(int)data->monitoredObjectIdentifier.type, (int) data->monitoredObjectIdentifier.type,
data->monitoredObjectIdentifier.instance); data->monitoredObjectIdentifier.instance);
apdu_len += len; apdu_len += len;
/* tag 3 - timeRemaining */ /* tag 3 - timeRemaining */
@@ -173,7 +173,7 @@ int cov_notify_decode_service_request(
uint32_t len_value = 0; uint32_t len_value = 0;
uint32_t decoded_value = 0; /* for decoding */ uint32_t decoded_value = 0; /* for decoding */
uint16_t decoded_type = 0; /* for decoding */ uint16_t decoded_type = 0; /* for decoding */
uint32_t property = 0; /* for decoding */ uint32_t property = 0; /* for decoding */
BACNET_PROPERTY_VALUE *value = NULL; /* value in list */ BACNET_PROPERTY_VALUE *value = NULL; /* value in list */
if (apdu_len && data) { if (apdu_len && data) {
@@ -338,7 +338,7 @@ int cov_subscribe_encode_adpu(
/* tag 1 - monitoredObjectIdentifier */ /* tag 1 - monitoredObjectIdentifier */
len = len =
encode_context_object_id(&apdu[apdu_len], 1, encode_context_object_id(&apdu[apdu_len], 1,
(int)data->monitoredObjectIdentifier.type, (int) data->monitoredObjectIdentifier.type,
data->monitoredObjectIdentifier.instance); data->monitoredObjectIdentifier.instance);
apdu_len += len; apdu_len += len;
/* /*
@@ -467,7 +467,7 @@ int cov_subscribe_property_encode_adpu(
/* tag 1 - monitoredObjectIdentifier */ /* tag 1 - monitoredObjectIdentifier */
len = len =
encode_context_object_id(&apdu[apdu_len], 1, encode_context_object_id(&apdu[apdu_len], 1,
(int)data->monitoredObjectIdentifier.type, (int) data->monitoredObjectIdentifier.type,
data->monitoredObjectIdentifier.instance); data->monitoredObjectIdentifier.instance);
apdu_len += len; apdu_len += len;
if (!data->cancellationRequest) { if (!data->cancellationRequest) {
@@ -518,7 +518,7 @@ int cov_subscribe_property_decode_service_request(
uint32_t len_value = 0; uint32_t len_value = 0;
uint32_t decoded_value = 0; /* for decoding */ uint32_t decoded_value = 0; /* for decoding */
uint16_t decoded_type = 0; /* for decoding */ uint16_t decoded_type = 0; /* for decoding */
uint32_t property = 0; /* for decoding */ uint32_t property = 0; /* for decoding */
if (apdu_len && data) { if (apdu_len && data) {
/* tag 0 - subscriberProcessIdentifier */ /* tag 0 - subscriberProcessIdentifier */
+12 -12
View File
@@ -106,14 +106,14 @@ int event_notify_encode_service_request(
/* tag 1 - initiatingObjectIdentifier */ /* tag 1 - initiatingObjectIdentifier */
len = len =
encode_context_object_id(&apdu[apdu_len], 1, encode_context_object_id(&apdu[apdu_len], 1,
(int)data->initiatingObjectIdentifier.type, (int) data->initiatingObjectIdentifier.type,
data->initiatingObjectIdentifier.instance); data->initiatingObjectIdentifier.instance);
apdu_len += len; apdu_len += len;
/* tag 2 - eventObjectIdentifier */ /* tag 2 - eventObjectIdentifier */
len = len =
encode_context_object_id(&apdu[apdu_len], 2, encode_context_object_id(&apdu[apdu_len], 2,
(int)data->eventObjectIdentifier.type, (int) data->eventObjectIdentifier.type,
data->eventObjectIdentifier.instance); data->eventObjectIdentifier.instance);
apdu_len += len; apdu_len += len;
@@ -442,7 +442,7 @@ int event_notify_decode_service_request(
int len = 0; /* return value */ int len = 0; /* return value */
int section_length = 0; int section_length = 0;
uint32_t value = 0; uint32_t value = 0;
if (apdu_len && data) { if (apdu_len && data) {
/* tag 0 - processIdentifier */ /* tag 0 - processIdentifier */
if ((section_length = if ((section_length =
@@ -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;
+15 -15
View File
@@ -47,7 +47,7 @@
* ALGORITHM: none * ALGORITHM: none
* NOTES: none * NOTES: none
*****************************************************************************/ *****************************************************************************/
static unsigned FIFO_Count ( static unsigned FIFO_Count(
FIFO_BUFFER const *b) FIFO_BUFFER const *b)
{ {
return (b ? (b->head - b->tail) : 0); return (b ? (b->head - b->tail) : 0);
@@ -59,7 +59,7 @@ static unsigned FIFO_Count (
* ALGORITHM: none * ALGORITHM: none
* NOTES: none * NOTES: none
*****************************************************************************/ *****************************************************************************/
static bool FIFO_Full ( static bool FIFO_Full(
FIFO_BUFFER const *b) FIFO_BUFFER const *b)
{ {
return (b ? (FIFO_Count(b) == b->buffer_len) : true); return (b ? (FIFO_Count(b) == b->buffer_len) : true);
@@ -71,7 +71,7 @@ static bool FIFO_Full (
* ALGORITHM: none * ALGORITHM: none
* NOTES: none * NOTES: none
*****************************************************************************/ *****************************************************************************/
static bool FIFO_Available ( static bool FIFO_Available(
FIFO_BUFFER const *b, FIFO_BUFFER const *b,
unsigned count) unsigned count)
{ {
@@ -85,7 +85,7 @@ static bool FIFO_Available (
* NOTES: none * NOTES: none
*****************************************************************************/ *****************************************************************************/
bool FIFO_Empty( bool FIFO_Empty(
FIFO_BUFFER const *b) FIFO_BUFFER const *b)
{ {
return (b ? (FIFO_Count(b) == 0) : true); return (b ? (FIFO_Count(b) == 0) : true);
} }
@@ -97,7 +97,7 @@ bool FIFO_Empty(
* NOTES: Use Empty function to see if there is data to retrieve * NOTES: Use Empty function to see if there is data to retrieve
*****************************************************************************/ *****************************************************************************/
uint8_t FIFO_Peek( uint8_t FIFO_Peek(
FIFO_BUFFER const *b) FIFO_BUFFER const *b)
{ {
if (b) { if (b) {
return (b->buffer[b->tail % b->buffer_len]); return (b->buffer[b->tail % b->buffer_len]);
@@ -113,7 +113,7 @@ uint8_t FIFO_Peek(
* NOTES: Use Empty function to see if there is data to retrieve * NOTES: Use Empty function to see if there is data to retrieve
*****************************************************************************/ *****************************************************************************/
uint8_t FIFO_Get( uint8_t FIFO_Get(
FIFO_BUFFER * b) FIFO_BUFFER * b)
{ {
uint8_t data_byte = 0; uint8_t data_byte = 0;
@@ -131,8 +131,8 @@ uint8_t FIFO_Get(
* NOTES: none * NOTES: none
*****************************************************************************/ *****************************************************************************/
bool FIFO_Put( bool FIFO_Put(
FIFO_BUFFER * b, FIFO_BUFFER * b,
uint8_t data_byte) uint8_t data_byte)
{ {
bool status = false; /* return value */ bool status = false; /* return value */
@@ -155,14 +155,14 @@ bool FIFO_Put(
* NOTES: none * NOTES: none
*****************************************************************************/ *****************************************************************************/
bool FIFO_Add( bool FIFO_Add(
FIFO_BUFFER * b, FIFO_BUFFER * b,
uint8_t *data_bytes, uint8_t * data_bytes,
unsigned count) unsigned count)
{ {
bool status = false; /* return value */ bool status = false; /* return value */
/* limit the ring to prevent overwriting */ /* limit the ring to prevent overwriting */
if (FIFO_Available (b, count)) { if (FIFO_Available(b, count)) {
while (count) { while (count) {
b->buffer[b->head % b->buffer_len] = *data_bytes; b->buffer[b->head % b->buffer_len] = *data_bytes;
b->head++; b->head++;
@@ -182,7 +182,7 @@ bool FIFO_Add(
* NOTES: none * NOTES: none
*****************************************************************************/ *****************************************************************************/
void FIFO_Flush( void FIFO_Flush(
FIFO_BUFFER * b) FIFO_BUFFER * b)
{ {
if (b) { if (b) {
b->tail = b->head; b->tail = b->head;
@@ -197,7 +197,7 @@ void FIFO_Flush(
*****************************************************************************/ *****************************************************************************/
void FIFO_Init( void FIFO_Init(
FIFO_BUFFER * b, FIFO_BUFFER * b,
volatile uint8_t *buffer, volatile uint8_t * buffer,
unsigned buffer_len) unsigned buffer_len)
{ {
if (b) { if (b) {
@@ -224,7 +224,7 @@ void testFIFOBuffer(
{ {
FIFO_BUFFER test_buffer; FIFO_BUFFER test_buffer;
volatile uint8_t data_store[FIFO_BUFFER_SIZE]; volatile uint8_t data_store[FIFO_BUFFER_SIZE];
uint8_t test_add_data[40] = {"RoseSteveLouPatRachelJessicaDaniAmyHerb"}; uint8_t test_add_data[40] = { "RoseSteveLouPatRachelJessicaDaniAmyHerb" };
uint8_t test_data; uint8_t test_data;
uint8_t index; uint8_t index;
uint8_t count; uint8_t count;
+5 -4
View File
@@ -61,8 +61,9 @@ 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 =
(uint32_t)segmentation); encode_application_enumerated(&apdu[apdu_len],
(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);
apdu_len += len; apdu_len += len;
@@ -107,7 +108,7 @@ int iam_decode_service_request(
len = decode_unsigned(&apdu[apdu_len], len_value, &decoded_value); len = decode_unsigned(&apdu[apdu_len], len_value, &decoded_value);
apdu_len += len; apdu_len += len;
if (pMax_apdu) if (pMax_apdu)
*pMax_apdu = (unsigned)decoded_value; *pMax_apdu = (unsigned) decoded_value;
/* Segmentation - enumerated */ /* Segmentation - enumerated */
len = len =
decode_tag_number_and_value(&apdu[apdu_len], &tag_number, &len_value); decode_tag_number_and_value(&apdu[apdu_len], &tag_number, &len_value);
@@ -119,7 +120,7 @@ int iam_decode_service_request(
if (decoded_value >= MAX_BACNET_SEGMENTATION) if (decoded_value >= MAX_BACNET_SEGMENTATION)
return -1; return -1;
if (pSegmentation) if (pSegmentation)
*pSegmentation = (int)decoded_value; *pSegmentation = (int) decoded_value;
/* Vendor ID - unsigned16 */ /* Vendor ID - unsigned16 */
len = len =
decode_tag_number_and_value(&apdu[apdu_len], &tag_number, &len_value); decode_tag_number_and_value(&apdu[apdu_len], &tag_number, &len_value);
+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 =
+2 -2
View File
@@ -44,8 +44,8 @@ int stricmp(
unsigned char c1, c2; unsigned char c1, c2;
do { do {
c1 = (unsigned char)*s1; c1 = (unsigned char) *s1;
c2 = (unsigned char)*s2; c2 = (unsigned char) *s2;
c1 = (unsigned char) tolower(c1); c1 = (unsigned char) tolower(c1);
c2 = (unsigned char) tolower(c2); c2 = (unsigned char) tolower(c2);
s1++; s1++;
+63 -65
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 =
@@ -62,17 +60,17 @@ int lso_encode_adpu(
&data->requestingSrc); &data->requestingSrc);
apdu_len += len; apdu_len += len;
/* /*
Operation Operation
*/ */
len = encode_context_enumerated(&apdu[apdu_len], 2, data->operation); len = encode_context_enumerated(&apdu[apdu_len], 2, data->operation);
apdu_len += len; apdu_len += len;
/* /*
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;
} }
@@ -81,60 +79,59 @@ int lso_encode_adpu(
} }
int lso_decode_service_request( int lso_decode_service_request(
uint8_t *apdu, uint8_t * apdu,
unsigned apdu_len, unsigned apdu_len,
BACNET_LSO_DATA *data) BACNET_LSO_DATA * data)
{ {
int len = 0; /* return value */ int len = 0; /* return value */
int section_length = 0; /* length returned from decoding */ int section_length = 0; /* length returned from decoding */
uint32_t operation = 0; /* handles decoded value */ uint32_t operation = 0; /* handles decoded value */
/* check for value pointers */ /* check for value pointers */
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,
return -1; &data->processId)) == -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,
return -1; &data->requestingSrc)) == -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;
len += section_length; len += section_length;
/* /*
** 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 {
} data->targetObject.type = 0;
else data->targetObject.instance = 0;
{ }
data->targetObject.type = 0; return len;
data->targetObject.instance = 0;
}
return len;
} }
return 0; return 0;
} }
#ifdef TEST #ifdef TEST
@@ -146,30 +143,31 @@ int lso_decode_service_request(
void testLSO( void testLSO(
Test * pTest) Test * pTest)
{ {
uint8_t apdu[1000]; uint8_t apdu[1000];
int len; int len;
BACNET_LSO_DATA data; BACNET_LSO_DATA data;
BACNET_LSO_DATA rxdata; BACNET_LSO_DATA rxdata;
memset(&rxdata, 0, sizeof(rxdata)); memset(&rxdata, 0, sizeof(rxdata));
characterstring_init_ansi(&data.requestingSrc, "foobar"); characterstring_init_ansi(&data.requestingSrc, "foobar");
data.operation = LIFE_SAFETY_OP_RESET; data.operation = LIFE_SAFETY_OP_RESET;
data.processId = 0x1234; data.processId = 0x1234;
data.targetObject.instance = 0x1000; data.targetObject.instance = 0x1000;
data.targetObject.type = OBJECT_BINARY_INPUT; data.targetObject.type = OBJECT_BINARY_INPUT;
len = lso_encode_adpu(apdu, 100, &data); len = lso_encode_adpu(apdu, 100, &data);
lso_decode_service_request(&apdu[4], len, &rxdata); lso_decode_service_request(&apdu[4], len, &rxdata);
ct_test(pTest, data.operation == rxdata.operation); ct_test(pTest, data.operation == rxdata.operation);
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
+4 -4
View File
@@ -103,7 +103,7 @@ int npdu_encode_pdu(
BACNET_NPDU_DATA * npdu_data) BACNET_NPDU_DATA * npdu_data)
{ {
int len = 0; /* return value - number of octets loaded in this function */ int len = 0; /* return value - number of octets loaded in this function */
uint8_t i = 0; /* counter */ uint8_t i = 0; /* counter */
if (npdu && npdu_data) { if (npdu && npdu_data) {
@@ -248,7 +248,7 @@ int npdu_decode(
BACNET_NPDU_DATA * npdu_data) BACNET_NPDU_DATA * npdu_data)
{ {
int len = 0; /* return value - number of octets loaded in this function */ int len = 0; /* return value - number of octets loaded in this function */
uint8_t i = 0; /* counter */ uint8_t i = 0; /* counter */
uint16_t src_net = 0; uint16_t src_net = 0;
uint16_t dest_net = 0; uint16_t dest_net = 0;
uint8_t address_len = 0; uint8_t address_len = 0;
@@ -297,7 +297,7 @@ int npdu_decode(
dest->len = address_len; dest->len = address_len;
} }
if (address_len) { if (address_len) {
if ( address_len > MAX_MAC_LEN ) { if (address_len > MAX_MAC_LEN) {
/* address is too large could be a malformed message */ /* address is too large could be a malformed message */
return -1; return -1;
} }
@@ -332,7 +332,7 @@ int npdu_decode(
src->len = address_len; src->len = address_len;
} }
if (address_len) { if (address_len) {
if ( address_len > MAX_MAC_LEN ) { if (address_len > MAX_MAC_LEN) {
/* address is too large could be a malformed message */ /* address is too large could be a malformed message */
return -1; return -1;
} }
+83 -85
View File
@@ -59,11 +59,13 @@ 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 =
private_data->vendorID); encode_context_unsigned(&apdu[apdu_len], 0,
private_data->vendorID);
apdu_len += len; apdu_len += len;
len = encode_context_unsigned(&apdu[apdu_len], 1, len =
private_data->serviceNumber); encode_context_unsigned(&apdu[apdu_len], 1,
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);
apdu_len += len; apdu_len += len;
@@ -84,10 +86,10 @@ int ptransfer_decode_service_request(
unsigned apdu_len, unsigned apdu_len,
BACNET_PRIVATE_TRANSFER_DATA * private_data) BACNET_PRIVATE_TRANSFER_DATA * private_data)
{ {
int len = 0; /* return value */ int len = 0; /* return value */
int decode_len = 0; /* return value */ int decode_len = 0; /* return value */
uint32_t unsigned_value = 0; uint32_t unsigned_value = 0;
/* check for value pointers */ /* check for value pointers */
if (apdu_len && private_data) { if (apdu_len && private_data) {
/* Tag 0: vendorID */ /* Tag 0: vendorID */
@@ -110,10 +112,10 @@ int ptransfer_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 = private_data->serviceParametersLen =
(int)apdu_len - len - 1 /*closing tag */ ; (int) apdu_len - len - 1 /*closing tag */ ;
/* len includes the data and the closing tag */ /* len includes the data and the closing tag */
len = (int)apdu_len; len = (int) apdu_len;
} else { } else {
return -1; return -1;
} }
@@ -127,10 +129,10 @@ int ptransfer_error_encode_apdu(
uint8_t invoke_id, uint8_t invoke_id,
BACNET_ERROR_CLASS error_class, BACNET_ERROR_CLASS error_class,
BACNET_ERROR_CODE error_code, BACNET_ERROR_CODE error_code,
BACNET_PRIVATE_TRANSFER_DATA *private_data) BACNET_PRIVATE_TRANSFER_DATA * private_data)
{ {
int apdu_len = 0; /* total length of the apdu, return value */ int apdu_len = 0; /* total length of the apdu, return value */
int len = 0; /* length of the part of the encoding */ int len = 0; /* length of the part of the encoding */
if (apdu) { if (apdu) {
apdu[0] = PDU_TYPE_ERROR; apdu[0] = PDU_TYPE_ERROR;
@@ -154,11 +156,13 @@ 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 =
private_data->vendorID); encode_context_unsigned(&apdu[apdu_len], 1,
private_data->vendorID);
apdu_len += len; apdu_len += len;
len = encode_context_unsigned(&apdu[apdu_len], 2, len =
private_data->serviceNumber); encode_context_unsigned(&apdu[apdu_len], 2,
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);
apdu_len += len; apdu_len += len;
@@ -181,7 +185,7 @@ int ptransfer_error_decode_service_request(
BACNET_ERROR_CODE * error_code, BACNET_ERROR_CODE * error_code,
BACNET_PRIVATE_TRANSFER_DATA * private_data) BACNET_PRIVATE_TRANSFER_DATA * private_data)
{ {
int len = 0; /* return value */ int len = 0; /* return value */
int decode_len = 0; /* return value */ int decode_len = 0; /* return value */
uint8_t tag_number = 0; uint8_t tag_number = 0;
uint32_t len_value_type = 0; uint32_t len_value_type = 0;
@@ -196,12 +200,12 @@ int ptransfer_error_decode_service_request(
/* error class */ /* error class */
decode_len = decode_len =
decode_tag_number_and_value(&apdu[len], &tag_number, decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type); &len_value_type);
len += decode_len; len += decode_len;
if (tag_number != BACNET_APPLICATION_TAG_ENUMERATED) { if (tag_number != BACNET_APPLICATION_TAG_ENUMERATED) {
return 0; return 0;
} }
decode_len = decode_len =
decode_enumerated(&apdu[len], len_value_type, &unsigned_value); decode_enumerated(&apdu[len], len_value_type, &unsigned_value);
len += decode_len; len += decode_len;
if (error_class) { if (error_class) {
@@ -210,12 +214,12 @@ int ptransfer_error_decode_service_request(
/* error code */ /* error code */
decode_len = decode_len =
decode_tag_number_and_value(&apdu[len], &tag_number, decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type); &len_value_type);
len += decode_len; len += decode_len;
if (tag_number != BACNET_APPLICATION_TAG_ENUMERATED) { if (tag_number != BACNET_APPLICATION_TAG_ENUMERATED) {
return 0; return 0;
} }
decode_len = decode_len =
decode_enumerated(&apdu[len], len_value_type, &unsigned_value); decode_enumerated(&apdu[len], len_value_type, &unsigned_value);
len += decode_len; len += decode_len;
if (error_code) { if (error_code) {
@@ -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;
} }
@@ -261,7 +266,7 @@ int ptransfer_error_decode_service_request(
int ptransfer_ack_encode_apdu( int ptransfer_ack_encode_apdu(
uint8_t * apdu, uint8_t * apdu,
uint8_t invoke_id, uint8_t invoke_id,
BACNET_PRIVATE_TRANSFER_DATA *private_data) BACNET_PRIVATE_TRANSFER_DATA * private_data)
{ {
int len = 0; /* length of each encoding */ int len = 0; /* length of each encoding */
int apdu_len = 0; /* total length of the apdu, return value */ int apdu_len = 0; /* total length of the apdu, return value */
@@ -269,7 +274,7 @@ int ptransfer_ack_encode_apdu(
if (apdu) { if (apdu) {
apdu[0] = PDU_TYPE_COMPLEX_ACK; /* complex ACK service */ apdu[0] = PDU_TYPE_COMPLEX_ACK; /* complex ACK service */
apdu[1] = invoke_id; /* original invoke id from request */ apdu[1] = invoke_id; /* original invoke id from request */
apdu[2] = SERVICE_CONFIRMED_PRIVATE_TRANSFER; /* service choice */ apdu[2] = SERVICE_CONFIRMED_PRIVATE_TRANSFER; /* service choice */
apdu_len = 3; apdu_len = 3;
/* service ack follows */ /* service ack follows */
/* /*
@@ -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);
@@ -311,7 +318,7 @@ int ptransfer_decode_apdu(
uint8_t * apdu, uint8_t * apdu,
unsigned apdu_len, unsigned apdu_len,
uint8_t * invoke_id, uint8_t * invoke_id,
BACNET_PRIVATE_TRANSFER_DATA *private_data) BACNET_PRIVATE_TRANSFER_DATA * private_data)
{ {
int len = 0; int len = 0;
unsigned offset = 0; unsigned offset = 0;
@@ -323,16 +330,17 @@ int ptransfer_decode_apdu(
return -1; return -1;
/* apdu[1] = encode_max_segs_max_apdu(0, MAX_APDU); */ /* apdu[1] = encode_max_segs_max_apdu(0, MAX_APDU); */
/* invoke id - filled in by net layer */ /* invoke id - filled in by net layer */
*invoke_id = apdu[2]; *invoke_id = apdu[2];
if (apdu[3] != SERVICE_CONFIRMED_PRIVATE_TRANSFER) if (apdu[3] != SERVICE_CONFIRMED_PRIVATE_TRANSFER)
return -1; return -1;
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;
} }
@@ -340,7 +348,7 @@ int ptransfer_ack_decode_apdu(
uint8_t * apdu, uint8_t * apdu,
int apdu_len, /* total length of the apdu */ int apdu_len, /* total length of the apdu */
uint8_t * invoke_id, uint8_t * invoke_id,
BACNET_PRIVATE_TRANSFER_DATA *private_data) BACNET_PRIVATE_TRANSFER_DATA * private_data)
{ {
int len = 0; int len = 0;
int offset = 0; int offset = 0;
@@ -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;
@@ -369,7 +377,7 @@ int ptransfer_error_decode_apdu(
uint8_t * invoke_id, uint8_t * invoke_id,
BACNET_ERROR_CLASS * error_class, BACNET_ERROR_CLASS * error_class,
BACNET_ERROR_CODE * error_code, BACNET_ERROR_CODE * error_code,
BACNET_PRIVATE_TRANSFER_DATA *private_data) BACNET_PRIVATE_TRANSFER_DATA * private_data)
{ {
int len = 0; int len = 0;
int offset = 0; int offset = 0;
@@ -385,16 +393,15 @@ 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;
} }
void test_Private_Transfer_Ack( void test_Private_Transfer_Ack(
Test * pTest) Test * pTest)
{ {
uint8_t apdu[480] = { 0 }; uint8_t apdu[480] = { 0 };
int len = 0; int len = 0;
@@ -405,19 +412,17 @@ void test_Private_Transfer_Ack(
BACNET_PRIVATE_TRANSFER_DATA test_data; BACNET_PRIVATE_TRANSFER_DATA test_data;
uint8_t test_value[480] = { 0 }; uint8_t test_value[480] = { 0 };
int private_data_len = 0; int private_data_len = 0;
uint8_t private_data_chunk[32] = {"I Love You, Patricia!"}; uint8_t private_data_chunk[32] = { "I Love You, Patricia!" };
BACNET_APPLICATION_DATA_VALUE data_value; BACNET_APPLICATION_DATA_VALUE data_value;
BACNET_APPLICATION_DATA_VALUE test_data_value; BACNET_APPLICATION_DATA_VALUE test_data_value;
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,24 +432,23 @@ 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);
} }
void test_Private_Transfer_Error( void test_Private_Transfer_Error(
Test * pTest) Test * pTest)
{ {
uint8_t apdu[480] = { 0 }; uint8_t apdu[480] = { 0 };
int len = 0; int len = 0;
@@ -459,49 +463,45 @@ void test_Private_Transfer_Error(
BACNET_PRIVATE_TRANSFER_DATA test_data; BACNET_PRIVATE_TRANSFER_DATA test_data;
uint8_t test_value[480] = { 0 }; uint8_t test_value[480] = { 0 };
int private_data_len = 0; int private_data_len = 0;
uint8_t private_data_chunk[32] = {"I Love You, Patricia!"}; uint8_t private_data_chunk[32] = { "I Love You, Patricia!" };
BACNET_APPLICATION_DATA_VALUE data_value; BACNET_APPLICATION_DATA_VALUE data_value;
BACNET_APPLICATION_DATA_VALUE test_data_value; BACNET_APPLICATION_DATA_VALUE test_data_value;
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);
ct_test(pTest, test_data.serviceNumber == private_data.serviceNumber); ct_test(pTest, test_data.serviceNumber == private_data.serviceNumber);
ct_test(pTest, test_error_class == error_class); ct_test(pTest, test_error_class == error_class);
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);
} }
void test_Private_Transfer_Request( void test_Private_Transfer_Request(
Test * pTest) Test * pTest)
{ {
uint8_t apdu[480] = { 0 }; uint8_t apdu[480] = { 0 };
uint8_t test_value[480] = { 0 }; uint8_t test_value[480] = { 0 };
@@ -510,7 +510,7 @@ void test_Private_Transfer_Request(
uint8_t invoke_id = 128; uint8_t invoke_id = 128;
uint8_t test_invoke_id = 0; uint8_t test_invoke_id = 0;
int private_data_len = 0; int private_data_len = 0;
uint8_t private_data_chunk[32] = {"I Love You, Patricia!"}; uint8_t private_data_chunk[32] = { "I Love You, Patricia!" };
BACNET_APPLICATION_DATA_VALUE data_value; BACNET_APPLICATION_DATA_VALUE data_value;
BACNET_APPLICATION_DATA_VALUE test_data_value; BACNET_APPLICATION_DATA_VALUE test_data_value;
BACNET_PRIVATE_TRANSFER_DATA private_data; BACNET_PRIVATE_TRANSFER_DATA private_data;
@@ -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;
@@ -548,7 +546,7 @@ void test_Private_Transfer_Request(
#ifdef TEST_PRIVATE_TRANSFER #ifdef TEST_PRIVATE_TRANSFER
int main( int main(
void) void)
{ {
Test *pTest; Test *pTest;
bool rc; bool rc;
+3 -3
View File
@@ -82,7 +82,7 @@ int rp_decode_service_request(
uint8_t tag_number = 0; uint8_t tag_number = 0;
uint32_t len_value_type = 0; uint32_t len_value_type = 0;
uint16_t type = 0; /* for decoding */ uint16_t type = 0; /* for decoding */
uint32_t property = 0; /* for decoding */ uint32_t property = 0; /* for decoding */
uint32_t array_value = 0; /* for decoding */ uint32_t array_value = 0; /* for decoding */
/* check for value pointers */ /* check for value pointers */
@@ -215,7 +215,7 @@ int rp_ack_decode_service_request(
int tag_len = 0; /* length of tag decode */ int tag_len = 0; /* length of tag decode */
int len = 0; /* total length of decodes */ int len = 0; /* total length of decodes */
uint16_t object = 0; /* object type */ uint16_t object = 0; /* object type */
uint32_t property = 0; /* for decoding */ uint32_t property = 0; /* for decoding */
uint32_t array_value = 0; /* for decoding */ uint32_t array_value = 0; /* for decoding */
/* FIXME: check apdu_len against the len during decode */ /* FIXME: check apdu_len against the len during decode */
@@ -247,7 +247,7 @@ int rp_ack_decode_service_request(
len++; len++;
/* don't decode the application tag number or its data here */ /* don't decode the application tag number or its data here */
rpdata->application_data = &apdu[len]; rpdata->application_data = &apdu[len];
rpdata->application_data_len = apdu_len - len - 1 /*closing tag */; rpdata->application_data_len = apdu_len - len - 1 /*closing tag */ ;
/* len includes the data and the closing tag */ /* len includes the data and the closing tag */
len = apdu_len; len = apdu_len;
} else { } else {
+26 -18
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;
} }
@@ -242,7 +248,7 @@ int rpm_decode_object_property(
unsigned option_len = 0; unsigned option_len = 0;
uint8_t tag_number = 0; uint8_t tag_number = 0;
uint32_t len_value_type = 0; uint32_t len_value_type = 0;
uint32_t property = 0; /* for decoding */ uint32_t property = 0; /* for decoding */
uint32_t array_value = 0; /* for decoding */ uint32_t array_value = 0; /* for decoding */
/* check for valid pointers */ /* check for valid pointers */
@@ -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 +=
@@ -434,7 +441,7 @@ int rpm_ack_decode_object_property(
unsigned tag_len = 0; unsigned tag_len = 0;
uint8_t tag_number = 0; uint8_t tag_number = 0;
uint32_t len_value_type = 0; uint32_t len_value_type = 0;
uint32_t property = 0; /* for decoding */ uint32_t property = 0; /* for decoding */
uint32_t array_value = 0; /* for decoding */ uint32_t array_value = 0; /* for decoding */
/* check for valid pointers */ /* check for valid pointers */
@@ -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 +=
+1 -1
View File
@@ -69,7 +69,7 @@ int whohas_encode_apdu(
} else { } else {
len = len =
encode_context_object_id(&apdu[apdu_len], 2, encode_context_object_id(&apdu[apdu_len], 2,
(int)data->object.identifier.type, (int) data->object.identifier.type,
data->object.identifier.instance); data->object.identifier.instance);
apdu_len += len; apdu_len += len;
} }
+1 -1
View File
@@ -100,7 +100,7 @@ int wp_decode_service_request(
uint8_t tag_number = 0; uint8_t tag_number = 0;
uint32_t len_value_type = 0; uint32_t len_value_type = 0;
uint16_t type = 0; /* for decoding */ uint16_t type = 0; /* for decoding */
uint32_t property = 0; /* for decoding */ uint32_t property = 0; /* for decoding */
uint32_t unsigned_value = 0; uint32_t unsigned_value = 0;
int i = 0; /* loop counter */ int i = 0; /* loop counter */