Changed the API to pass the NPDU data down through the datalink layer in order to make the dlmstp work since it needs data-expecting-reply information. Of course, this affected all the demos, all the unit tests, and most of the demo handlers. Corrected some TSM leaks in confirmed messages. Refactored the AtomicReadFile and AtomicWriteFile demos by moving the Send_ functions to the demo/handlers directory and using the s_whois common handler. Added some common defines for the BACnet version and revision since several modules were using the info. Hopefully I didn't break too many things.

This commit is contained in:
skarg
2006-08-13 00:54:05 +00:00
parent 185d02a9ff
commit 5bb205dc03
46 changed files with 793 additions and 638 deletions
+2 -3
View File
@@ -272,8 +272,8 @@ uint16_t apdu_decode_confirmed_service_request(uint8_t * apdu, /* APDU data */
return len; return len;
} }
void apdu_handler(BACNET_ADDRESS * src, /* source address */ void apdu_handler(BACNET_ADDRESS * src,
bool data_expecting_reply, uint8_t * apdu, /* APDU data */ uint8_t * apdu, /* APDU data */
uint16_t apdu_len) uint16_t apdu_len)
{ {
BACNET_CONFIRMED_SERVICE_DATA service_data = { 0 }; BACNET_CONFIRMED_SERVICE_DATA service_data = { 0 };
@@ -289,7 +289,6 @@ void apdu_handler(BACNET_ADDRESS * src, /* source address */
int error_class = 0; int error_class = 0;
uint8_t reason = 0; uint8_t reason = 0;
(void) data_expecting_reply;
if (apdu) { if (apdu) {
/* PDU Type */ /* PDU Type */
switch (apdu[0] & 0xF0) { switch (apdu[0] & 0xF0) {
+1 -1
View File
@@ -149,7 +149,7 @@ extern "C" {
uint8_t ** service_request, uint16_t * service_request_len); uint8_t ** service_request, uint16_t * service_request_len);
void apdu_handler(BACNET_ADDRESS * src, /* source address */ void apdu_handler(BACNET_ADDRESS * src, /* source address */
bool data_expecting_reply, uint8_t * apdu, /* APDU data */ uint8_t * apdu, /* APDU data */
uint16_t pdu_len); /* for confirmed messages */ uint16_t pdu_len); /* for confirmed messages */
#ifdef __cplusplus #ifdef __cplusplus
+1 -1
View File
@@ -240,7 +240,7 @@ bool bacapp_copy(BACNET_APPLICATION_DATA_VALUE * dest_value,
return status; return status;
} }
#if PRINT_ENABLED #ifdef BACAPP_PRINT_ENABLED
bool bacapp_print_value(FILE * stream, bool bacapp_print_value(FILE * stream,
BACNET_APPLICATION_DATA_VALUE * value, BACNET_PROPERTY_ID property) BACNET_APPLICATION_DATA_VALUE * value, BACNET_PROPERTY_ID property)
{ {
+8
View File
@@ -73,6 +73,14 @@ extern "C" {
BACNET_APPLICATION_DATA_VALUE * src_value); BACNET_APPLICATION_DATA_VALUE * src_value);
#if PRINT_ENABLED #if PRINT_ENABLED
#define BACAPP_PRINT_ENABLED
#else
#ifdef TEST
#define BACAPP_PRINT_ENABLED
#endif
#endif
#ifdef BACAPP_PRINT_ENABLED
bool bacapp_parse_application_data(BACNET_APPLICATION_TAG tag_number, bool bacapp_parse_application_data(BACNET_APPLICATION_TAG tag_number,
const char *argv, BACNET_APPLICATION_DATA_VALUE * value); const char *argv, BACNET_APPLICATION_DATA_VALUE * value);
+4
View File
@@ -39,6 +39,10 @@
#include "bacenum.h" #include "bacenum.h"
#include "config.h" #include "config.h"
/* This stack implements this version of BACnet */
#define BACNET_PROTOCOL_VERSION 1
#define BACNET_PROTOCOL_REVISION 5
/* largest BACnet Instance Number */ /* largest BACnet Instance Number */
/* Also used as a device instance number wildcard address */ /* Also used as a device instance number wildcard address */
#define BACNET_MAX_INSTANCE (0x3FFFFF) #define BACNET_MAX_INSTANCE (0x3FFFFF)
+9 -1
View File
@@ -36,6 +36,14 @@
/* tiny implementations have no need to print */ /* tiny implementations have no need to print */
#if PRINT_ENABLED #if PRINT_ENABLED
#define BACTEXT_PRINT_ENABLED
#else
#ifdef TEST
#define BACTEXT_PRINT_ENABLED
#endif
#endif
#ifdef BACTEXT_PRINT_ENABLED
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
@@ -70,6 +78,6 @@ extern "C" {
} }
#endif /* __cplusplus */ #endif /* __cplusplus */
#endif #endif /* BACTEXT_PRINT_ENABLED */
#endif #endif
+20 -33
View File
@@ -138,65 +138,52 @@ uint16_t bip_get_port(void)
/* function to send a packet out the BACnet/IP socket (Annex J) */ /* function to send a packet out the BACnet/IP socket (Annex J) */
/* returns number of bytes sent on success, negative number on failure */ /* returns number of bytes sent on success, negative number on failure */
static int bip_send(struct sockaddr_in *bip_dest, uint8_t * pdu, /* any data to be sent - may be null */ int bip_send_pdu(BACNET_ADDRESS * dest, /* destination address */
BACNET_NPDU_DATA * npdu_data, /* network information */
uint8_t * pdu, /* any data to be sent - may be null */
unsigned pdu_len) unsigned pdu_len)
{ /* number of bytes of data */ { /* number of bytes of data */
struct sockaddr_in bip_dest;
uint8_t mtu[MAX_MPDU] = { 0 }; uint8_t mtu[MAX_MPDU] = { 0 };
int mtu_len = 0; int mtu_len = 0;
int bytes_sent = 0; int bytes_sent = 0;
BACNET_ADDRESS src;
/* assumes that the driver has already been initialized */ /* assumes that the driver has already been initialized */
if (BIP_Socket < 0) if (BIP_Socket < 0)
return BIP_Socket; return BIP_Socket;
mtu[0] = BVLL_TYPE_BACNET_IP; mtu[0] = BVLL_TYPE_BACNET_IP;
if (bip_dest->sin_addr.s_addr == htonl(BIP_Broadcast_Address.s_addr))
mtu[1] = BVLC_ORIGINAL_BROADCAST_NPDU;
else
mtu[1] = BVLC_ORIGINAL_UNICAST_NPDU;
mtu_len = 2;
mtu_len +=
encode_unsigned16(&mtu[mtu_len],
(uint16_t) (pdu_len + 4 /*inclusive */ ));
memcpy(&mtu[mtu_len], pdu, pdu_len);
mtu_len += pdu_len;
/* Send the packet */
bytes_sent = sendto(BIP_Socket, (char *) mtu, mtu_len, 0,
(struct sockaddr *) bip_dest, sizeof(struct sockaddr));
return bytes_sent;
}
/* function to send a packet out the BACnet/IP socket (Annex J) */
/* returns number of bytes sent on success, negative number on failure */
int bip_send_pdu(BACNET_ADDRESS * dest, /* destination address */
uint8_t * pdu, /* any data to be sent - may be null */
unsigned pdu_len)
{ /* number of bytes of data */
struct sockaddr_in bip_dest;
/* load destination IP address */
bip_dest.sin_family = AF_INET; bip_dest.sin_family = AF_INET;
if (dest->mac_len == 6) { if (dest->mac_len == 6) {
(void) decode_unsigned32(&dest->mac[0], (void) decode_unsigned32(&dest->mac[0],
&(bip_dest.sin_addr.s_addr)); &(bip_dest.sin_addr.s_addr));
(void) decode_unsigned16(&dest->mac[4], &(bip_dest.sin_port)); (void) decode_unsigned16(&dest->mac[4], &(bip_dest.sin_port));
memset(&(bip_dest.sin_zero), '\0', 8); memset(&(bip_dest.sin_zero), '\0', 8);
mtu[1] = BVLC_ORIGINAL_UNICAST_NPDU;
} }
/* broadcast */ /* broadcast */
else if (dest->mac_len == 0) { else if (dest->mac_len == 0) {
bip_dest.sin_addr.s_addr = htonl(BIP_Broadcast_Address.s_addr); bip_dest.sin_addr.s_addr = htonl(BIP_Broadcast_Address.s_addr);
bip_dest.sin_port = htons(BIP_Port); bip_dest.sin_port = htons(BIP_Port);
memset(&(bip_dest.sin_zero), '\0', 8); memset(&(bip_dest.sin_zero), '\0', 8);
mtu[1] = BVLC_ORIGINAL_BROADCAST_NPDU;
} else } else
return -1; return -1;
/* function to send a packet out the BACnet/IP socket */ /* len is encoded at mtu[2], but we haven't finished packing yet */
/* returns 1 on success, 0 on failure */ bip_get_my_address(&src);
return bip_send(&bip_dest, /* destination address */ mtu_len = npdu_encode_pdu(&mtu[4], dest, &src, npdu_data);
pdu, /* any data to be sent - may be null */ mtu_len += 4;
pdu_len); /* number of bytes of data */ memcpy(&mtu[mtu_len], pdu, pdu_len);
mtu_len += pdu_len;
encode_unsigned16(&mtu[2],mtu_len);
/* Send the packet */
bytes_sent = sendto(BIP_Socket, (char *) mtu, mtu_len, 0,
(struct sockaddr *) &bip_dest, sizeof(struct sockaddr));
return bytes_sent;
} }
/* receives a BACnet/IP packet */ /* receives a BACnet/IP packet */
+2
View File
@@ -38,6 +38,7 @@
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
#include "bacdef.h" #include "bacdef.h"
#include "npdu.h"
#include "net.h" #include "net.h"
/* specific defines for BACnet/IP over Ethernet */ /* specific defines for BACnet/IP over Ethernet */
@@ -64,6 +65,7 @@ extern "C" {
/* function to send a packet out the BACnet/IP socket */ /* function to send a packet out the BACnet/IP socket */
/* returns zero on success, non-zero on failure */ /* returns zero on success, non-zero on failure */
int bip_send_pdu(BACNET_ADDRESS * dest, /* destination address */ int bip_send_pdu(BACNET_ADDRESS * dest, /* destination address */
BACNET_NPDU_DATA * npdu_data, /* network information */
uint8_t * pdu, /* any data to be sent - may be null */ uint8_t * pdu, /* any data to be sent - may be null */
unsigned pdu_len); /* number of bytes of data */ unsigned pdu_len); /* number of bytes of data */
+4 -4
View File
@@ -11,8 +11,8 @@
/* This is used in constructing messages and to tell others our limits */ /* This is used in constructing messages and to tell others our limits */
/* 50 is the minimum; adjust to your memory and physical layer constraints */ /* 50 is the minimum; adjust to your memory and physical layer constraints */
/* Lon=206, MS/TP=480, ARCNET=480, Ethernet=1476 */ /* Lon=206, MS/TP=480, ARCNET=480, Ethernet=1476 */
#define MAX_APDU 50 /* #define MAX_APDU 50 */
/* #define MAX_APDU 480 */ #define MAX_APDU 480
/* #define MAX_APDU 1476 */ /* #define MAX_APDU 1476 */
/* for confirmed messages, this is the number of transactions */ /* for confirmed messages, this is the number of transactions */
@@ -20,13 +20,13 @@
/* Configure to zero if you don't want any confirmed messages */ /* Configure to zero if you don't want any confirmed messages */
/* Configure from 1..255 for number of outstanding confirmed */ /* Configure from 1..255 for number of outstanding confirmed */
/* requests available. */ /* requests available. */
#define MAX_TSM_TRANSACTIONS 1 #define MAX_TSM_TRANSACTIONS 255
/* The address cache is used for binding to BACnet devices */ /* The address cache is used for binding to BACnet devices */
/* The number of entries corresponds to the number of */ /* The number of entries corresponds to the number of */
/* devices that might respond to an I-Am on the network. */ /* devices that might respond to an I-Am on the network. */
/* If your device is a simple server and does not need to bind, */ /* If your device is a simple server and does not need to bind, */
/* then you don't need to use this. */ /* then you don't need to use this. */
#define MAX_ADDRESS_CACHE 2 #define MAX_ADDRESS_CACHE 255
#endif #endif
+28 -30
View File
@@ -274,6 +274,31 @@ int cov_notify_decode_service_request(uint8_t * apdu,
return len; return len;
} }
int ucov_notify_send(uint8_t * buffer, BACNET_COV_DATA * data)
{
int pdu_len = 0;
BACNET_ADDRESS dest;
int bytes_sent = 0;
BACNET_NPDU_DATA npdu_data;
/* unconfirmed is a broadcast */
datalink_get_broadcast_address(&dest);
/* encode the APDU portion of the packet */
pdu_len = ucov_notify_encode_apdu(&buffer[0], data);
/* encode the NPDU portion of the packet */
npdu_encode_unconfirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL);
/* send the data */
bytes_sent = datalink_send_pdu(&dest, &npdu_data, &buffer[0], pdu_len);
return bytes_sent;
}
#ifdef TEST
#include <assert.h>
#include <string.h>
#include "ctest.h"
#include "bacapp.h"
int ccov_notify_decode_apdu(uint8_t * apdu, int ccov_notify_decode_apdu(uint8_t * apdu,
unsigned apdu_len, uint8_t * invoke_id, BACNET_COV_DATA * data) unsigned apdu_len, uint8_t * invoke_id, BACNET_COV_DATA * data)
{ {
@@ -325,44 +350,17 @@ int ucov_notify_decode_apdu(uint8_t * apdu,
return len; return len;
} }
int ucov_notify_send(uint8_t * buffer, BACNET_COV_DATA * data)
{
int pdu_len = 0;
BACNET_ADDRESS dest;
int bytes_sent = 0;
/* unconfirmed is a broadcast */
datalink_get_broadcast_address(&dest);
/* encode the NPDU portion of the packet */
pdu_len = npdu_encode_apdu(&buffer[0], &dest, NULL,
false /* true for confirmed messages */ ,
MESSAGE_PRIORITY_NORMAL);
/* encode the APDU portion of the packet */
pdu_len += ucov_notify_encode_apdu(&buffer[pdu_len], data);
bytes_sent = datalink_send_pdu(&dest, /* destination address */
&buffer[0], pdu_len); /* number of bytes of data */
return bytes_sent;
}
#ifdef TEST
#include <assert.h>
#include <string.h>
#include "ctest.h"
#include "bacapp.h"
/* dummy function stubs */ /* dummy function stubs */
int npdu_encode_apdu(uint8_t * npdu, BACNET_ADDRESS * dest, BACNET_ADDRESS * src, bool data_expecting_reply, /* true for confirmed messages */ void npdu_encode_unconfirmed_apdu(BACNET_NPDU_DATA * npdu,
BACNET_MESSAGE_PRIORITY priority) BACNET_MESSAGE_PRIORITY priority)
{ {
return 0; return;
} }
/* dummy function stubs */ /* dummy function stubs */
int datalink_send_pdu(BACNET_ADDRESS * dest, /* destination address */ int datalink_send_pdu(BACNET_ADDRESS * dest, /* destination address */
BACNET_NPDU_DATA * npdu_data, /* network information */
uint8_t * pdu, /* any data to be sent - may be null */ uint8_t * pdu, /* any data to be sent - may be null */
unsigned pdu_len) unsigned pdu_len)
{ /* number of bytes of data */ { /* number of bytes of data */
+31 -41
View File
@@ -42,20 +42,20 @@
/* returns number of bytes sent on success, negative on failure */ /* returns number of bytes sent on success, negative on failure */
int datalink_send_pdu(BACNET_ADDRESS * dest, /* destination address */ int datalink_send_pdu(BACNET_ADDRESS * dest, /* destination address */
BACNET_NPDU_DATA * npdu_data, /* network information */
uint8_t * pdu, /* any data to be sent - may be null */ uint8_t * pdu, /* any data to be sent - may be null */
unsigned pdu_len) unsigned pdu_len)
{ /* number of bytes of data */ { /* number of bytes of data */
#ifdef BACDL_ARCNET #if defined(BACDL_ARCNET)
return arcnet_send_pdu(dest, pdu, pdu_len); return arcnet_send_pdu(dest, npdu_data, pdu, pdu_len);
#endif #elif defined(BACDL_MSTP)
#ifdef BACDL_MSTP return dlmstp_send_pdu(dest, npdu_data, pdu, pdu_len);
return dlmstp_send_pdu(dest, pdu, pdu_len); #elif defined(BACDL_ETHERNET)
#endif return ethernet_send_pdu(dest, npdu_data, pdu, pdu_len);
#ifdef BACDL_ETHERNET #elif defined(BACDL_BIP)
return ethernet_send_pdu(dest, pdu, pdu_len); return bip_send_pdu(dest, npdu_data, pdu, pdu_len);
#endif #else
#ifdef BACDL_BIP return 0;
return bip_send_pdu(dest, pdu, pdu_len);
#endif #endif
} }
@@ -65,64 +65,54 @@ uint16_t datalink_receive(BACNET_ADDRESS * src, /* source address */
uint16_t max_pdu, /* amount of space available in the PDU */ uint16_t max_pdu, /* amount of space available in the PDU */
unsigned timeout) unsigned timeout)
{ /* number of milliseconds to wait for a packet */ { /* number of milliseconds to wait for a packet */
#ifdef BACDL_ARCNET #if defined(BACDL_ARCNET)
return arcnet_receive(src, pdu, max_pdu, timeout); return arcnet_receive(src, pdu, max_pdu, timeout);
#endif #elif defined(BACDL_MSTP)
#ifdef BACDL_MSTP
return dlmstp_receive(src, pdu, max_pdu, timeout); return dlmstp_receive(src, pdu, max_pdu, timeout);
#endif #elif defined(BACDL_ETHERNET)
#ifdef BACDL_ETHERNET
return ethernet_receive(src, pdu, max_pdu, timeout); return ethernet_receive(src, pdu, max_pdu, timeout);
#endif #elif defined(BACDL_BIP)
#ifdef BACDL_BIP
return bip_receive(src, pdu, max_pdu, timeout); return bip_receive(src, pdu, max_pdu, timeout);
#else
return 0;
#endif #endif
} }
void datalink_cleanup(void) void datalink_cleanup(void)
{ {
#ifdef BACDL_ETHERNET #if defined(BACDL_ARCNET)
ethernet_cleanup();
#endif
#ifdef BACDL_BIP
bip_cleanup();
#endif
#ifdef BACDL_ARCNET
arcnet_cleanup(); arcnet_cleanup();
#endif #elif defined(BACDL_MSTP)
#ifdef BACDL_MSTP
dlmstp_cleanup(); dlmstp_cleanup();
#elif defined(BACDL_ETHERNET)
ethernet_cleanup();
#elif defined(BACDL_BIP)
bip_cleanup();
#endif #endif
} }
void datalink_get_broadcast_address(BACNET_ADDRESS * dest) void datalink_get_broadcast_address(BACNET_ADDRESS * dest)
{ /* destination address */ { /* destination address */
#ifdef BACDL_ARCNET #if defined(BACDL_ARCNET)
arcnet_get_broadcast_address(dest); arcnet_get_broadcast_address(dest);
#endif #elif defined(BACDL_MSTP)
#ifdef BACDL_MSTP
dlmstp_get_broadcast_address(dest); dlmstp_get_broadcast_address(dest);
#endif #elif defined(BACDL_ETHERNET)
#ifdef BACDL_ETHERNET
ethernet_get_broadcast_address(dest); ethernet_get_broadcast_address(dest);
#endif #elif defined(BACDL_BIP)
#ifdef BACDL_BIP
bip_get_broadcast_address(dest); bip_get_broadcast_address(dest);
#endif #endif
} }
void datalink_get_my_address(BACNET_ADDRESS * my_address) void datalink_get_my_address(BACNET_ADDRESS * my_address)
{ {
#ifdef BACDL_ARCNET #if defined(BACDL_ARCNET)
arcnet_get_my_address(my_address); arcnet_get_my_address(my_address);
#endif #elif defined(BACDL_MSTP)
#ifdef BACDL_MSTP
dlmstp_get_my_address(my_address); dlmstp_get_my_address(my_address);
#endif #elif defined(BACDL_ETHERNET)
#ifdef BACDL_ETHERNET
ethernet_get_my_address(my_address); ethernet_get_my_address(my_address);
#endif #elif defined(BACDL_BIP)
#ifdef BACDL_BIP
bip_get_my_address(my_address); bip_get_my_address(my_address);
#endif #endif
} }
+2
View File
@@ -38,6 +38,7 @@
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
#include "bacdef.h" #include "bacdef.h"
#include "npdu.h"
#ifdef BACDL_ETHERNET #ifdef BACDL_ETHERNET
#include "ethernet.h" #include "ethernet.h"
@@ -61,6 +62,7 @@ extern "C" {
/* returns number of bytes sent on success, negative on failure */ /* returns number of bytes sent on success, negative on failure */
int datalink_send_pdu(BACNET_ADDRESS * dest, /* destination address */ int datalink_send_pdu(BACNET_ADDRESS * dest, /* destination address */
BACNET_NPDU_DATA * npdu_data, /* network information */
uint8_t * pdu, /* any data to be sent - may be null */ uint8_t * pdu, /* any data to be sent - may be null */
unsigned pdu_len); /* number of bytes of data */ unsigned pdu_len); /* number of bytes of data */
+7
View File
@@ -76,6 +76,13 @@ extern "C" {
void Send_TimeSync(BACNET_DATE * bdate, BACNET_TIME * btime); void Send_TimeSync(BACNET_DATE * bdate, BACNET_TIME * btime);
void Send_TimeSyncUTC(BACNET_DATE * bdate, BACNET_TIME * btime); void Send_TimeSyncUTC(BACNET_DATE * bdate, BACNET_TIME * btime);
uint8_t Send_Atomic_Read_File_Stream(uint32_t device_id,
uint32_t file_instance, int fileStartPosition,
unsigned requestedOctetCount);
uint8_t Send_Atomic_Write_File_Stream(uint32_t device_id,
uint32_t file_instance,
int fileStartPosition, BACNET_OCTET_STRING * fileData);
#ifdef __cplusplus #ifdef __cplusplus
} }
+31 -41
View File
@@ -48,75 +48,65 @@ void handler_atomic_read_file(uint8_t * service_request,
BACNET_ATOMIC_READ_FILE_DATA data; BACNET_ATOMIC_READ_FILE_DATA data;
int len = 0; int len = 0;
int pdu_len = 0; int pdu_len = 0;
BACNET_ADDRESS my_address;
bool send = false;
bool error = false; bool error = false;
int bytes_sent = 0; int bytes_sent = 0;
BACNET_ERROR_CLASS error_class = ERROR_CLASS_OBJECT; BACNET_NPDU_DATA npdu_data;
BACNET_ERROR_CODE error_code = ERROR_CODE_UNKNOWN_OBJECT;
#if PRINT_ENABLED
fprintf(stderr, "Received Atomic-Read-File Request!\n"); fprintf(stderr, "Received Atomic-Read-File Request!\n");
#endif
len = arf_decode_service_request(service_request, service_len, &data); len = arf_decode_service_request(service_request, service_len, &data);
if (len < 0)
fprintf(stderr, "Unable to decode Atomic-Read-File Request!\n");
/* prepare a reply */ /* prepare a reply */
datalink_get_my_address(&my_address);
/* encode the NPDU portion of the packet */
pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], src, &my_address, false, /* true for confirmed messages */
MESSAGE_PRIORITY_NORMAL);
/* bad decoding - send an abort */ /* bad decoding - send an abort */
if (len < 0) { if (len < 0) {
pdu_len += abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], pdu_len = abort_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, ABORT_REASON_OTHER); service_data->invoke_id, ABORT_REASON_OTHER);
fprintf(stderr, "Sending Abort!\n"); #if PRINT_ENABLED
send = true; fprintf(stderr, "Bad Encoding. Sending Abort!\n");
#endif
} else if (service_data->segmented_message) { } else if (service_data->segmented_message) {
pdu_len += abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], pdu_len = abort_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED); ABORT_REASON_SEGMENTATION_NOT_SUPPORTED);
fprintf(stderr, "Sending Abort!\n"); #if PRINT_ENABLED
send = true; fprintf(stderr, "Segmented Message. Sending Abort!\n");
#endif
} else { } else {
if (data.access == FILE_STREAM_ACCESS) { if (data.access == FILE_STREAM_ACCESS) {
if (data.type.stream.requestedOctetCount < if (data.type.stream.requestedOctetCount <
octetstring_capacity(&data.fileData)) { octetstring_capacity(&data.fileData)) {
if (bacfile_read_data(&data)) { if (bacfile_read_data(&data)) {
pdu_len += pdu_len = arf_ack_encode_apdu(&Handler_Transmit_Buffer[0],
arf_ack_encode_apdu(&Handler_Transmit_Buffer service_data->invoke_id, &data);
[pdu_len], service_data->invoke_id, &data);
send = true;
} else { } else {
send = true;
error = true; error = true;
} }
} else { } else {
pdu_len += pdu_len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], abort_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED); ABORT_REASON_SEGMENTATION_NOT_SUPPORTED);
fprintf(stderr, "Sending Abort!\n"); #if PRINT_ENABLED
send = true; fprintf(stderr, "Too Big To Send. Sending Abort!\n");
#endif
} }
} else { } else {
error_class = ERROR_CLASS_SERVICES; pdu_len = bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
error_code = ERROR_CODE_INVALID_FILE_ACCESS_METHOD; service_data->invoke_id, SERVICE_CONFIRMED_ATOMIC_READ_FILE,
send = true; ERROR_CLASS_SERVICES, ERROR_CODE_INVALID_FILE_ACCESS_METHOD);
error = true; #if PRINT_ENABLED
fprintf(stderr, "Record Access Requested. Sending Error!\n");
#endif
} }
} }
if (error) { npdu_encode_confirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL);
pdu_len += bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], bytes_sent = datalink_send_pdu(src, &npdu_data,
service_data->invoke_id, &Handler_Transmit_Buffer[0], pdu_len);
SERVICE_CONFIRMED_ATOMIC_READ_FILE, error_class, error_code); #if PRINT_ENABLED
fprintf(stderr, "Sending Error!\n"); if (bytes_sent <= 0) {
send = true; fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno));
}
if (send) {
bytes_sent = datalink_send_pdu(src, /* destination address */
&Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */
if (bytes_sent <= 0)
fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno));
} }
#endif
return; return;
} }
+6
View File
@@ -62,7 +62,9 @@ void handler_atomic_read_file_ack(uint8_t * service_request,
instance = bacfile_instance_from_tsm(service_data->invoke_id); instance = bacfile_instance_from_tsm(service_data->invoke_id);
len = arf_ack_decode_service_request(service_request, len = arf_ack_decode_service_request(service_request,
service_len, &data); service_len, &data);
#if PRINT_ENABLED
fprintf(stderr, "Received Read-File Ack!\n"); fprintf(stderr, "Received Read-File Ack!\n");
#endif
if ((len > 0) && (instance <= BACNET_MAX_INSTANCE)) { if ((len > 0) && (instance <= BACNET_MAX_INSTANCE)) {
/* write the data received to the file specified */ /* write the data received to the file specified */
if (data.access == FILE_STREAM_ACCESS) { if (data.access == FILE_STREAM_ACCESS) {
@@ -75,8 +77,12 @@ void handler_atomic_read_file_ack(uint8_t * service_request,
if (fwrite(octetstring_value(&data.fileData), if (fwrite(octetstring_value(&data.fileData),
octetstring_length(&data.fileData), 1, octetstring_length(&data.fileData), 1,
pFile) != 1) pFile) != 1)
{
#if PRINT_ENABLED
fprintf(stderr, "Failed to write to %s (%u)!\n", fprintf(stderr, "Failed to write to %s (%u)!\n",
pFilename, instance); pFilename, instance);
#endif
}
fclose(pFile); fclose(pFile);
} }
} }
+12 -19
View File
@@ -38,7 +38,7 @@
#include "reject.h" #include "reject.h"
#include "dcc.h" #include "dcc.h"
static char *My_Password = "AnnaRoseKarg"; static char *My_Password = "filister";
void handler_device_communication_control(uint8_t * service_request, void handler_device_communication_control(uint8_t * service_request,
uint16_t service_len, uint16_t service_len,
@@ -49,8 +49,8 @@ void handler_device_communication_control(uint8_t * service_request,
BACNET_CHARACTER_STRING password; BACNET_CHARACTER_STRING password;
int len = 0; int len = 0;
int pdu_len = 0; int pdu_len = 0;
BACNET_ADDRESS my_address;
int bytes_sent = 0; int bytes_sent = 0;
BACNET_NPDU_DATA npdu_data;
/* decode the service request only */ /* decode the service request only */
len = dcc_decode_service_request(service_request, len = dcc_decode_service_request(service_request,
@@ -62,25 +62,17 @@ void handler_device_communication_control(uint8_t * service_request,
"timeout=%u state=%u password=%s\n", "timeout=%u state=%u password=%s\n",
(unsigned) timeDuration, (unsigned) timeDuration,
(unsigned) state, characterstring_value(&password)); (unsigned) state, characterstring_value(&password));
else
fprintf(stderr, "DeviceCommunicationControl: "
"Unable to decode request!\n");
#endif #endif
/* prepare a reply */
datalink_get_my_address(&my_address);
/* encode the NPDU portion of the packet */
pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], src, &my_address, false, /* true for confirmed messages */
MESSAGE_PRIORITY_NORMAL);
/* bad decoding or something we didn't understand - send an abort */ /* bad decoding or something we didn't understand - send an abort */
if (len == -1) { if (len < 0) {
pdu_len += abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], pdu_len = abort_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, ABORT_REASON_OTHER); service_data->invoke_id, ABORT_REASON_OTHER);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "DeviceCommunicationControl: " fprintf(stderr, "DeviceCommunicationControl: "
"Sending Abort - could not decode.\n"); "Sending Abort - could not decode.\n");
#endif #endif
} else if (service_data->segmented_message) { } else if (service_data->segmented_message) {
pdu_len += abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], pdu_len = abort_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED); ABORT_REASON_SEGMENTATION_NOT_SUPPORTED);
#if PRINT_ENABLED #if PRINT_ENABLED
@@ -88,7 +80,7 @@ void handler_device_communication_control(uint8_t * service_request,
"Sending Abort - segmented message.\n"); "Sending Abort - segmented message.\n");
#endif #endif
} else if (state >= MAX_BACNET_COMMUNICATION_ENABLE_DISABLE) { } else if (state >= MAX_BACNET_COMMUNICATION_ENABLE_DISABLE) {
pdu_len += reject_encode_apdu(&Handler_Transmit_Buffer[pdu_len], pdu_len = reject_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, REJECT_REASON_UNDEFINED_ENUMERATION); service_data->invoke_id, REJECT_REASON_UNDEFINED_ENUMERATION);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "DeviceCommunicationControl: " fprintf(stderr, "DeviceCommunicationControl: "
@@ -96,7 +88,7 @@ void handler_device_communication_control(uint8_t * service_request,
#endif #endif
} else { } else {
if (characterstring_ansi_same(&password, My_Password)) { if (characterstring_ansi_same(&password, My_Password)) {
pdu_len += encode_simple_ack(&Handler_Transmit_Buffer[pdu_len], pdu_len = encode_simple_ack(&Handler_Transmit_Buffer[0],
service_data->invoke_id, service_data->invoke_id,
SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL); SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL);
#if PRINT_ENABLED #if PRINT_ENABLED
@@ -105,8 +97,8 @@ void handler_device_communication_control(uint8_t * service_request,
#endif #endif
dcc_set_status_duration(state, timeDuration); dcc_set_status_duration(state, timeDuration);
} else { } else {
pdu_len += pdu_len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], bacerror_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, service_data->invoke_id,
SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL, SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL,
ERROR_CLASS_SERVICES, ERROR_CODE_PASSWORD_FAILURE); ERROR_CLASS_SERVICES, ERROR_CODE_PASSWORD_FAILURE);
@@ -117,8 +109,9 @@ void handler_device_communication_control(uint8_t * service_request,
#endif #endif
} }
} }
bytes_sent = datalink_send_pdu(src, /* destination address */ npdu_encode_confirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL);
&Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */ bytes_sent = datalink_send_pdu(src, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED #if PRINT_ENABLED
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, "DeviceCommunicationControl: " fprintf(stderr, "DeviceCommunicationControl: "
+8 -1
View File
@@ -44,12 +44,19 @@ void handler_i_am_add(uint8_t * service_request,
(void) service_len; (void) service_len;
len = iam_decode_service_request(service_request, len = iam_decode_service_request(service_request,
&device_id, &max_apdu, &segmentation, &vendor_id); &device_id, &max_apdu, &segmentation, &vendor_id);
#if PRINT_ENABLED
fprintf(stderr, "Received I-Am Request"); fprintf(stderr, "Received I-Am Request");
#endif
if (len != -1) { if (len != -1) {
#if PRINT_ENABLED
fprintf(stderr, " from %u!\n", device_id); fprintf(stderr, " from %u!\n", device_id);
#endif
address_add(device_id, max_apdu, src); address_add(device_id, max_apdu, src);
} else } else {
#if PRINT_ENABLED
fprintf(stderr, "!\n"); fprintf(stderr, "!\n");
#endif
}
return; return;
} }
+6 -1
View File
@@ -43,13 +43,18 @@ void handler_i_have(uint8_t * service_request,
len = ihave_decode_service_request(service_request, len = ihave_decode_service_request(service_request,
service_len, &data); service_len, &data);
if (len != -1) { if (len != -1) {
#if PRINT_ENABLED
fprintf(stderr, "I-Have: %s %d from %s %u!\r\n", fprintf(stderr, "I-Have: %s %d from %s %u!\r\n",
bactext_object_type_name(data.object_id.type), bactext_object_type_name(data.object_id.type),
data.object_id.instance, data.object_id.instance,
bactext_object_type_name(data.device_id.type), bactext_object_type_name(data.device_id.type),
data.device_id.instance); data.device_id.instance);
} else #endif
} else {
#if PRINT_ENABLED
fprintf(stderr, "I-Have: received, but unable to decode!\n"); fprintf(stderr, "I-Have: received, but unable to decode!\n");
#endif
}
return; return;
} }
+11 -15
View File
@@ -49,7 +49,7 @@ void handler_reinitialize_device(uint8_t * service_request,
BACNET_CHARACTER_STRING their_password; BACNET_CHARACTER_STRING their_password;
int len = 0; int len = 0;
int pdu_len = 0; int pdu_len = 0;
BACNET_ADDRESS my_address; BACNET_NPDU_DATA npdu_data;
int bytes_sent = 0; int bytes_sent = 0;
/* decode the service request only */ /* decode the service request only */
@@ -63,21 +63,16 @@ void handler_reinitialize_device(uint8_t * service_request,
else else
fprintf(stderr, "ReinitializeDevice: Unable to decode request!\n"); fprintf(stderr, "ReinitializeDevice: Unable to decode request!\n");
#endif #endif
/* prepare a reply */
datalink_get_my_address(&my_address);
/* encode the NPDU portion of the packet */
pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], src, &my_address, false, /* true for confirmed messages */
MESSAGE_PRIORITY_NORMAL);
/* bad decoding or something we didn't understand - send an abort */ /* bad decoding or something we didn't understand - send an abort */
if (len == -1) { if (len < 0) {
pdu_len += abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], pdu_len = abort_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, ABORT_REASON_OTHER); service_data->invoke_id, ABORT_REASON_OTHER);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, fprintf(stderr,
"ReinitializeDevice: Sending Abort - could not decode.\n"); "ReinitializeDevice: Sending Abort - could not decode.\n");
#endif #endif
} else if (service_data->segmented_message) { } else if (service_data->segmented_message) {
pdu_len += abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], pdu_len = abort_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED); ABORT_REASON_SEGMENTATION_NOT_SUPPORTED);
#if PRINT_ENABLED #if PRINT_ENABLED
@@ -85,7 +80,7 @@ void handler_reinitialize_device(uint8_t * service_request,
"ReinitializeDevice: Sending Abort - segmented message.\n"); "ReinitializeDevice: Sending Abort - segmented message.\n");
#endif #endif
} else if (state >= MAX_BACNET_REINITIALIZED_STATE) { } else if (state >= MAX_BACNET_REINITIALIZED_STATE) {
pdu_len += reject_encode_apdu(&Handler_Transmit_Buffer[pdu_len], pdu_len = reject_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, REJECT_REASON_UNDEFINED_ENUMERATION); service_data->invoke_id, REJECT_REASON_UNDEFINED_ENUMERATION);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, fprintf(stderr,
@@ -94,7 +89,7 @@ void handler_reinitialize_device(uint8_t * service_request,
} else { } else {
characterstring_init_ansi(&My_Password, Password); characterstring_init_ansi(&My_Password, Password);
if (characterstring_same(&their_password, &My_Password)) { if (characterstring_same(&their_password, &My_Password)) {
pdu_len += encode_simple_ack(&Handler_Transmit_Buffer[pdu_len], pdu_len = encode_simple_ack(&Handler_Transmit_Buffer[0],
service_data->invoke_id, service_data->invoke_id,
SERVICE_CONFIRMED_REINITIALIZE_DEVICE); SERVICE_CONFIRMED_REINITIALIZE_DEVICE);
#if PRINT_ENABLED #if PRINT_ENABLED
@@ -105,8 +100,8 @@ void handler_reinitialize_device(uint8_t * service_request,
/* Note: if you don't do something clever like actually restart, /* Note: if you don't do something clever like actually restart,
you probably should clear any DCC status and timeouts */ you probably should clear any DCC status and timeouts */
} else { } else {
pdu_len += pdu_len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], bacerror_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, service_data->invoke_id,
SERVICE_CONFIRMED_REINITIALIZE_DEVICE, SERVICE_CONFIRMED_REINITIALIZE_DEVICE,
ERROR_CLASS_SERVICES, ERROR_CODE_PASSWORD_FAILURE); ERROR_CLASS_SERVICES, ERROR_CODE_PASSWORD_FAILURE);
@@ -116,8 +111,9 @@ void handler_reinitialize_device(uint8_t * service_request,
#endif #endif
} }
} }
bytes_sent = datalink_send_pdu(src, /* destination address */ npdu_encode_confirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL);
&Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */ bytes_sent = datalink_send_pdu(src, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED #if PRINT_ENABLED
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, "ReinitializeDevice: Failed to send PDU (%s)!\n", fprintf(stderr, "ReinitializeDevice: Failed to send PDU (%s)!\n",
+35 -41
View File
@@ -58,7 +58,7 @@ void handler_read_property(uint8_t * service_request,
BACNET_READ_PROPERTY_DATA data; BACNET_READ_PROPERTY_DATA data;
int len = 0; int len = 0;
int pdu_len = 0; int pdu_len = 0;
BACNET_ADDRESS my_address; BACNET_NPDU_DATA npdu_data;
bool send = false; bool send = false;
bool error = false; bool error = false;
int bytes_sent = 0; int bytes_sent = 0;
@@ -70,21 +70,16 @@ void handler_read_property(uint8_t * service_request,
if (len <= 0) if (len <= 0)
fprintf(stderr, "Unable to decode Read-Property Request!\n"); fprintf(stderr, "Unable to decode Read-Property Request!\n");
#endif #endif
/* prepare a reply */
datalink_get_my_address(&my_address);
/* encode the NPDU portion of the packet */
pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], src, &my_address, false, /* true for confirmed messages */
MESSAGE_PRIORITY_NORMAL);
/* bad decoding - send an abort */ /* bad decoding - send an abort */
if (len == -1) { if (len < 0) {
pdu_len += abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], pdu_len = abort_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, ABORT_REASON_OTHER); service_data->invoke_id, ABORT_REASON_OTHER);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Sending Abort!\n"); fprintf(stderr, "Sending Abort!\n");
#endif #endif
send = true; send = true;
} else if (service_data->segmented_message) { } else if (service_data->segmented_message) {
pdu_len += abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], pdu_len = abort_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED); ABORT_REASON_SEGMENTATION_NOT_SUPPORTED);
#if PRINT_ENABLED #if PRINT_ENABLED
@@ -104,9 +99,8 @@ void handler_read_property(uint8_t * service_request,
data.application_data = &Temp_Buf[0]; data.application_data = &Temp_Buf[0];
data.application_data_len = len; data.application_data_len = len;
/* FIXME: probably need a length limitation sent with encode */ /* FIXME: probably need a length limitation sent with encode */
pdu_len += pdu_len = rp_ack_encode_apdu(&Handler_Transmit_Buffer[0],
rp_ack_encode_apdu(&Handler_Transmit_Buffer service_data->invoke_id, &data);
[pdu_len], service_data->invoke_id, &data);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, fprintf(stderr,
"Sending Read Property Ack for Device!\n"); "Sending Read Property Ack for Device!\n");
@@ -128,9 +122,9 @@ void handler_read_property(uint8_t * service_request,
data.application_data = &Temp_Buf[0]; data.application_data = &Temp_Buf[0];
data.application_data_len = len; data.application_data_len = len;
/* FIXME: probably need a length limitation sent with encode */ /* FIXME: probably need a length limitation sent with encode */
pdu_len += pdu_len =
rp_ack_encode_apdu(&Handler_Transmit_Buffer rp_ack_encode_apdu(&Handler_Transmit_Buffer[0],
[pdu_len], service_data->invoke_id, &data); service_data->invoke_id, &data);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Sending Read Property Ack for AI!\n"); fprintf(stderr, "Sending Read Property Ack for AI!\n");
#endif #endif
@@ -151,9 +145,9 @@ void handler_read_property(uint8_t * service_request,
data.application_data = &Temp_Buf[0]; data.application_data = &Temp_Buf[0];
data.application_data_len = len; data.application_data_len = len;
/* FIXME: probably need a length limitation sent with encode */ /* FIXME: probably need a length limitation sent with encode */
pdu_len += pdu_len =
rp_ack_encode_apdu(&Handler_Transmit_Buffer rp_ack_encode_apdu(&Handler_Transmit_Buffer[0],
[pdu_len], service_data->invoke_id, &data); service_data->invoke_id, &data);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Sending Read Property Ack for BI!\n"); fprintf(stderr, "Sending Read Property Ack for BI!\n");
#endif #endif
@@ -174,9 +168,8 @@ void handler_read_property(uint8_t * service_request,
data.application_data = &Temp_Buf[0]; data.application_data = &Temp_Buf[0];
data.application_data_len = len; data.application_data_len = len;
/* FIXME: probably need a length limitation sent with encode */ /* FIXME: probably need a length limitation sent with encode */
pdu_len += pdu_len = rp_ack_encode_apdu(&Handler_Transmit_Buffer[0],
rp_ack_encode_apdu(&Handler_Transmit_Buffer service_data->invoke_id, &data);
[pdu_len], service_data->invoke_id, &data);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Sending Read Property Ack for BO!\n"); fprintf(stderr, "Sending Read Property Ack for BO!\n");
#endif #endif
@@ -197,9 +190,9 @@ void handler_read_property(uint8_t * service_request,
data.application_data = &Temp_Buf[0]; data.application_data = &Temp_Buf[0];
data.application_data_len = len; data.application_data_len = len;
/* FIXME: probably need a length limitation sent with encode */ /* FIXME: probably need a length limitation sent with encode */
pdu_len += pdu_len =
rp_ack_encode_apdu(&Handler_Transmit_Buffer rp_ack_encode_apdu(&Handler_Transmit_Buffer[0],
[pdu_len], service_data->invoke_id, &data); service_data->invoke_id, &data);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Sending Read Property Ack for BV!\n"); fprintf(stderr, "Sending Read Property Ack for BV!\n");
#endif #endif
@@ -220,9 +213,9 @@ void handler_read_property(uint8_t * service_request,
data.application_data = &Temp_Buf[0]; data.application_data = &Temp_Buf[0];
data.application_data_len = len; data.application_data_len = len;
/* FIXME: probably need a length limitation sent with encode */ /* FIXME: probably need a length limitation sent with encode */
pdu_len += pdu_len =
rp_ack_encode_apdu(&Handler_Transmit_Buffer rp_ack_encode_apdu(&Handler_Transmit_Buffer[0],
[pdu_len], service_data->invoke_id, &data); service_data->invoke_id, &data);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Sending Read Property Ack for AO!\n"); fprintf(stderr, "Sending Read Property Ack for AO!\n");
#endif #endif
@@ -243,9 +236,9 @@ void handler_read_property(uint8_t * service_request,
data.application_data = &Temp_Buf[0]; data.application_data = &Temp_Buf[0];
data.application_data_len = len; data.application_data_len = len;
/* FIXME: probably need a length limitation sent with encode */ /* FIXME: probably need a length limitation sent with encode */
pdu_len += pdu_len =
rp_ack_encode_apdu(&Handler_Transmit_Buffer rp_ack_encode_apdu(&Handler_Transmit_Buffer[0],
[pdu_len], service_data->invoke_id, &data); service_data->invoke_id, &data);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Sending Read Property Ack for AV!\n"); fprintf(stderr, "Sending Read Property Ack for AV!\n");
#endif #endif
@@ -266,9 +259,9 @@ void handler_read_property(uint8_t * service_request,
data.application_data = &Temp_Buf[0]; data.application_data = &Temp_Buf[0];
data.application_data_len = len; data.application_data_len = len;
/* FIXME: probably need a length limitation sent with encode */ /* FIXME: probably need a length limitation sent with encode */
pdu_len += pdu_len =
rp_ack_encode_apdu(&Handler_Transmit_Buffer rp_ack_encode_apdu(&Handler_Transmit_Buffer[0],
[pdu_len], service_data->invoke_id, &data); service_data->invoke_id, &data);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, fprintf(stderr,
"Sending Read Property Ack for LSP!\n"); "Sending Read Property Ack for LSP!\n");
@@ -290,9 +283,9 @@ void handler_read_property(uint8_t * service_request,
data.application_data = &Temp_Buf[0]; data.application_data = &Temp_Buf[0];
data.application_data_len = len; data.application_data_len = len;
/* FIXME: probably need a length limitation sent with encode */ /* FIXME: probably need a length limitation sent with encode */
pdu_len += pdu_len =
rp_ack_encode_apdu(&Handler_Transmit_Buffer rp_ack_encode_apdu(&Handler_Transmit_Buffer[0],
[pdu_len], service_data->invoke_id, &data); service_data->invoke_id, &data);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, fprintf(stderr,
"Sending Read Property Ack for MSO!\n"); "Sending Read Property Ack for MSO!\n");
@@ -315,9 +308,9 @@ void handler_read_property(uint8_t * service_request,
data.application_data = &Temp_Buf[0]; data.application_data = &Temp_Buf[0];
data.application_data_len = len; data.application_data_len = len;
/* FIXME: probably need a length limitation sent with encode */ /* FIXME: probably need a length limitation sent with encode */
pdu_len += pdu_len =
rp_ack_encode_apdu(&Handler_Transmit_Buffer rp_ack_encode_apdu(&Handler_Transmit_Buffer[0],
[pdu_len], service_data->invoke_id, &data); service_data->invoke_id, &data);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, fprintf(stderr,
"Sending Read Property Ack for File!\n"); "Sending Read Property Ack for File!\n");
@@ -335,7 +328,7 @@ void handler_read_property(uint8_t * service_request,
} }
} }
if (error) { if (error) {
pdu_len += bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], pdu_len = bacerror_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, service_data->invoke_id,
SERVICE_CONFIRMED_READ_PROPERTY, error_class, error_code); SERVICE_CONFIRMED_READ_PROPERTY, error_class, error_code);
#if PRINT_ENABLED #if PRINT_ENABLED
@@ -344,7 +337,8 @@ void handler_read_property(uint8_t * service_request,
send = true; send = true;
} }
if (send) { if (send) {
bytes_sent = datalink_send_pdu(src, /* destination address */ npdu_encode_confirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL);
bytes_sent = datalink_send_pdu(src, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */ &Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */
#if PRINT_ENABLED #if PRINT_ENABLED
if (bytes_sent <= 0) if (bytes_sent <= 0)
+87 -47
View File
@@ -56,7 +56,7 @@ void handler_write_property(uint8_t * service_request,
BACNET_WRITE_PROPERTY_DATA wp_data; BACNET_WRITE_PROPERTY_DATA wp_data;
int len = 0; int len = 0;
int pdu_len = 0; int pdu_len = 0;
BACNET_ADDRESS my_address; BACNET_NPDU_DATA npdu_data;
BACNET_ERROR_CLASS error_class = ERROR_CLASS_OBJECT; BACNET_ERROR_CLASS error_class = ERROR_CLASS_OBJECT;
BACNET_ERROR_CODE error_code = ERROR_CODE_UNKNOWN_OBJECT; BACNET_ERROR_CODE error_code = ERROR_CODE_UNKNOWN_OBJECT;
int bytes_sent = 0; int bytes_sent = 0;
@@ -64,6 +64,7 @@ void handler_write_property(uint8_t * service_request,
/* decode the service request only */ /* decode the service request only */
len = wp_decode_service_request(service_request, len = wp_decode_service_request(service_request,
service_len, &wp_data); service_len, &wp_data);
#if PRINT_ENABLED
fprintf(stderr, "Received Write-Property Request!\n"); fprintf(stderr, "Received Write-Property Request!\n");
if (len > 0) if (len > 0)
fprintf(stderr, "type=%u instance=%u property=%u index=%d\n", fprintf(stderr, "type=%u instance=%u property=%u index=%d\n",
@@ -72,192 +73,231 @@ void handler_write_property(uint8_t * service_request,
wp_data.object_property, wp_data.array_index); wp_data.object_property, wp_data.array_index);
else else
fprintf(stderr, "Unable to decode Write-Property Request!\n"); fprintf(stderr, "Unable to decode Write-Property Request!\n");
/* prepare a reply */ #endif
datalink_get_my_address(&my_address);
/* encode the NPDU portion of the packet */
pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], src, &my_address, false, /* true for confirmed messages */
MESSAGE_PRIORITY_NORMAL);
/* bad decoding or something we didn't understand - send an abort */ /* bad decoding or something we didn't understand - send an abort */
if (len == -1) { if (len <= 0) {
pdu_len += abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], pdu_len = abort_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, ABORT_REASON_OTHER); service_data->invoke_id, ABORT_REASON_OTHER);
#if PRINT_ENABLED
fprintf(stderr, "Sending Abort!\n"); fprintf(stderr, "Sending Abort!\n");
#endif
} else if (service_data->segmented_message) { } else if (service_data->segmented_message) {
pdu_len += abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], pdu_len = abort_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED); ABORT_REASON_SEGMENTATION_NOT_SUPPORTED);
#if PRINT_ENABLED
fprintf(stderr, "Sending Abort!\n"); fprintf(stderr, "Sending Abort!\n");
#endif
} else { } else {
switch (wp_data.object_type) { switch (wp_data.object_type) {
case OBJECT_DEVICE: case OBJECT_DEVICE:
if (Device_Write_Property(&wp_data, &error_class, &error_code)) { if (Device_Write_Property(&wp_data, &error_class, &error_code)) {
pdu_len += pdu_len =
encode_simple_ack(&Handler_Transmit_Buffer[pdu_len], encode_simple_ack(&Handler_Transmit_Buffer[0],
service_data->invoke_id, service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY); SERVICE_CONFIRMED_WRITE_PROPERTY);
#if PRINT_ENABLED
fprintf(stderr, fprintf(stderr,
"Sending Write Property Simple Ack for Device!\n"); "Sending Write Property Simple Ack for Device!\n");
#endif
} else { } else {
pdu_len += pdu_len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], bacerror_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, SERVICE_CONFIRMED_WRITE_PROPERTY, error_class,
error_code); error_code);
#if PRINT_ENABLED
fprintf(stderr, fprintf(stderr,
"Sending Write Property Error for Device!\n"); "Sending Write Property Error for Device!\n");
#endif
} }
break; break;
case OBJECT_ANALOG_INPUT: case OBJECT_ANALOG_INPUT:
case OBJECT_BINARY_INPUT: case OBJECT_BINARY_INPUT:
error_class = ERROR_CLASS_PROPERTY; error_class = ERROR_CLASS_PROPERTY;
error_code = ERROR_CODE_WRITE_ACCESS_DENIED; error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
pdu_len += pdu_len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], bacerror_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY, service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY,
error_class, error_code); error_class, error_code);
#if PRINT_ENABLED
fprintf(stderr, "Sending Write Access Error!\n"); fprintf(stderr, "Sending Write Access Error!\n");
#endif
break; break;
case OBJECT_BINARY_OUTPUT: case OBJECT_BINARY_OUTPUT:
if (Binary_Output_Write_Property(&wp_data, &error_class, if (Binary_Output_Write_Property(&wp_data, &error_class,
&error_code)) { &error_code)) {
pdu_len += pdu_len =
encode_simple_ack(&Handler_Transmit_Buffer[pdu_len], encode_simple_ack(&Handler_Transmit_Buffer[0],
service_data->invoke_id, service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY); SERVICE_CONFIRMED_WRITE_PROPERTY);
#if PRINT_ENABLED
fprintf(stderr, fprintf(stderr,
"Sending Write Property Simple Ack for BO!\n"); "Sending Write Property Simple Ack for BO!\n");
#endif
} else { } else {
pdu_len += pdu_len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], bacerror_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, SERVICE_CONFIRMED_WRITE_PROPERTY, error_class,
error_code); error_code);
#if PRINT_ENABLED
fprintf(stderr, "Sending Write Access Error for BO!\n"); fprintf(stderr, "Sending Write Access Error for BO!\n");
#endif
} }
break; break;
case OBJECT_BINARY_VALUE: case OBJECT_BINARY_VALUE:
if (Binary_Value_Write_Property(&wp_data, &error_class, if (Binary_Value_Write_Property(&wp_data, &error_class,
&error_code)) { &error_code)) {
pdu_len += pdu_len =
encode_simple_ack(&Handler_Transmit_Buffer[pdu_len], encode_simple_ack(&Handler_Transmit_Buffer[0],
service_data->invoke_id, service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY); SERVICE_CONFIRMED_WRITE_PROPERTY);
#if PRINT_ENABLED
fprintf(stderr, fprintf(stderr,
"Sending Write Property Simple Ack for BV!\n"); "Sending Write Property Simple Ack for BV!\n");
#endif
} else { } else {
pdu_len += pdu_len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], bacerror_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, SERVICE_CONFIRMED_WRITE_PROPERTY, error_class,
error_code); error_code);
#if PRINT_ENABLED
fprintf(stderr, "Sending Write Access Error for BV!\n"); fprintf(stderr, "Sending Write Access Error for BV!\n");
#endif
} }
break; break;
case OBJECT_ANALOG_OUTPUT: case OBJECT_ANALOG_OUTPUT:
if (Analog_Output_Write_Property(&wp_data, &error_class, if (Analog_Output_Write_Property(&wp_data, &error_class,
&error_code)) { &error_code)) {
pdu_len += pdu_len =
encode_simple_ack(&Handler_Transmit_Buffer[pdu_len], encode_simple_ack(&Handler_Transmit_Buffer[0],
service_data->invoke_id, service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY); SERVICE_CONFIRMED_WRITE_PROPERTY);
#if PRINT_ENABLED
fprintf(stderr, fprintf(stderr,
"Sending Write Property Simple Ack for AO!\n"); "Sending Write Property Simple Ack for AO!\n");
#endif
} else { } else {
pdu_len += pdu_len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], bacerror_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, SERVICE_CONFIRMED_WRITE_PROPERTY, error_class,
error_code); error_code);
#if PRINT_ENABLED
fprintf(stderr, "Sending Write Access Error for AO!\n"); fprintf(stderr, "Sending Write Access Error for AO!\n");
#endif
} }
break; break;
case OBJECT_ANALOG_VALUE: case OBJECT_ANALOG_VALUE:
if (Analog_Value_Write_Property(&wp_data, &error_class, if (Analog_Value_Write_Property(&wp_data, &error_class,
&error_code)) { &error_code)) {
pdu_len += pdu_len =
encode_simple_ack(&Handler_Transmit_Buffer[pdu_len], encode_simple_ack(&Handler_Transmit_Buffer[0],
service_data->invoke_id, service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY); SERVICE_CONFIRMED_WRITE_PROPERTY);
#if PRINT_ENABLED
fprintf(stderr, fprintf(stderr,
"Sending Write Property Simple Ack for AV!\n"); "Sending Write Property Simple Ack for AV!\n");
#endif
} else { } else {
pdu_len += pdu_len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], bacerror_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, SERVICE_CONFIRMED_WRITE_PROPERTY, error_class,
error_code); error_code);
#if PRINT_ENABLED
fprintf(stderr, "Sending Write Access Error for AV!\n"); fprintf(stderr, "Sending Write Access Error for AV!\n");
#endif
} }
break; break;
case OBJECT_LIFE_SAFETY_POINT: case OBJECT_LIFE_SAFETY_POINT:
if (Life_Safety_Point_Write_Property(&wp_data, &error_class, if (Life_Safety_Point_Write_Property(&wp_data, &error_class,
&error_code)) { &error_code)) {
pdu_len += pdu_len =
encode_simple_ack(&Handler_Transmit_Buffer[pdu_len], encode_simple_ack(&Handler_Transmit_Buffer[0],
service_data->invoke_id, service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY); SERVICE_CONFIRMED_WRITE_PROPERTY);
#if PRINT_ENABLED
fprintf(stderr, fprintf(stderr,
"Sending Write Property Simple Ack for LSP!\n"); "Sending Write Property Simple Ack for LSP!\n");
#endif
} else { } else {
pdu_len += pdu_len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], bacerror_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, SERVICE_CONFIRMED_WRITE_PROPERTY, error_class,
error_code); error_code);
#if PRINT_ENABLED
fprintf(stderr, "Sending Write Access Error for LSP!\n"); fprintf(stderr, "Sending Write Access Error for LSP!\n");
#endif
} }
break; break;
case OBJECT_MULTI_STATE_OUTPUT: case OBJECT_MULTI_STATE_OUTPUT:
if (Multistate_Output_Write_Property(&wp_data, &error_class, if (Multistate_Output_Write_Property(&wp_data, &error_class,
&error_code)) { &error_code)) {
pdu_len += pdu_len =
encode_simple_ack(&Handler_Transmit_Buffer[pdu_len], encode_simple_ack(&Handler_Transmit_Buffer[0],
service_data->invoke_id, service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY); SERVICE_CONFIRMED_WRITE_PROPERTY);
#if PRINT_ENABLED
fprintf(stderr, fprintf(stderr,
"Sending Write Property Simple Ack for MSO!\n"); "Sending Write Property Simple Ack for MSO!\n");
#endif
} else { } else {
pdu_len += pdu_len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], bacerror_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, SERVICE_CONFIRMED_WRITE_PROPERTY, error_class,
error_code); error_code);
#if PRINT_ENABLED
fprintf(stderr, "Sending Write Access Error for MSO!\n"); fprintf(stderr, "Sending Write Access Error for MSO!\n");
#endif
} }
break; break;
#if BACFILE #if BACFILE
case OBJECT_FILE: case OBJECT_FILE:
if (bacfile_write_property(&wp_data, &error_class, if (bacfile_write_property(&wp_data, &error_class,
&error_code)) { &error_code)) {
pdu_len += pdu_len =
encode_simple_ack(&Handler_Transmit_Buffer[pdu_len], encode_simple_ack(&Handler_Transmit_Buffer[0],
service_data->invoke_id, service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY); SERVICE_CONFIRMED_WRITE_PROPERTY);
#if PRINT_ENABLED
fprintf(stderr, fprintf(stderr,
"Sending Write Property Simple Ack for File!\n"); "Sending Write Property Simple Ack for File!\n");
#endif
} else { } else {
pdu_len += pdu_len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], bacerror_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, SERVICE_CONFIRMED_WRITE_PROPERTY, error_class,
error_code); error_code);
#if PRINT_ENABLED
fprintf(stderr, "Sending Write Access Error for File!\n"); fprintf(stderr, "Sending Write Access Error for File!\n");
#endif
} }
break; break;
#endif #endif
default: default:
pdu_len += pdu_len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], bacerror_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY, service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY,
error_class, error_code); error_class, error_code);
#if PRINT_ENABLED
fprintf(stderr, "Sending Unknown Object Error!\n"); fprintf(stderr, "Sending Unknown Object Error!\n");
#endif
break; break;
} }
} }
bytes_sent = datalink_send_pdu(src, /* destination address */ npdu_encode_confirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL);
&Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */ bytes_sent = datalink_send_pdu(src, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno)); fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno));
#endif
return; return;
} }
+9 -10
View File
@@ -38,26 +38,25 @@ void handler_unrecognized_service(uint8_t * service_request,
uint16_t service_len, uint16_t service_len,
BACNET_ADDRESS * dest, BACNET_CONFIRMED_SERVICE_DATA * service_data) BACNET_ADDRESS * dest, BACNET_CONFIRMED_SERVICE_DATA * service_data)
{ {
BACNET_ADDRESS src;
int pdu_len = 0; int pdu_len = 0;
int bytes_sent = 0; int bytes_sent = 0;
BACNET_NPDU_DATA npdu_data;
(void) service_request; (void) service_request;
(void) service_len; (void) service_len;
datalink_get_my_address(&src);
/* encode the NPDU portion of the packet */
pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], dest, &src, false, /* true for confirmed messages */
MESSAGE_PRIORITY_NORMAL);
/* encode the APDU portion of the packet */ /* encode the APDU portion of the packet */
pdu_len += reject_encode_apdu(&Handler_Transmit_Buffer[pdu_len], pdu_len = reject_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, REJECT_REASON_UNRECOGNIZED_SERVICE); service_data->invoke_id, REJECT_REASON_UNRECOGNIZED_SERVICE);
/* encode the NPDU portion of the packet */
bytes_sent = datalink_send_pdu(dest, /* destination address */ npdu_encode_confirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL);
&Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */ /* send the data */
bytes_sent = datalink_send_pdu(dest, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED
if (bytes_sent > 0) if (bytes_sent > 0)
fprintf(stderr, "Sent Reject!\n"); fprintf(stderr, "Sent Reject!\n");
else else
fprintf(stderr, "Failed to Send Reject (%s)!\n", strerror(errno)); fprintf(stderr, "Failed to Send Reject (%s)!\n", strerror(errno));
#endif
} }
+99
View File
@@ -0,0 +1,99 @@
/**************************************************************************
*
* Copyright (C) 2006 Steve Karg <skarg@users.sourceforge.net>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*********************************************************************/
#include <stddef.h>
#include <stdint.h>
#include <errno.h>
#include "config.h"
#include "config.h"
#include "txbuf.h"
#include "bacdef.h"
#include "bacdcode.h"
#include "address.h"
#include "tsm.h"
#include "npdu.h"
#include "apdu.h"
#include "device.h"
#include "datalink.h"
#include "arf.h"
/* some demo stuff needed */
#include "handlers.h"
#include "txbuf.h"
uint8_t Send_Atomic_Read_File_Stream(uint32_t device_id,
uint32_t file_instance,
int fileStartPosition, unsigned requestedOctetCount)
{
BACNET_ADDRESS dest;
BACNET_NPDU_DATA npdu_data;
unsigned max_apdu = 0;
uint8_t invoke_id = 0;
bool status = false;
int pdu_len = 0;
int bytes_sent = 0;
BACNET_ATOMIC_READ_FILE_DATA data;
/* is the device bound? */
status = address_get_by_device(device_id, &max_apdu, &dest);
/* is there a tsm available? */
if (status)
invoke_id = tsm_next_free_invokeID();
if (invoke_id) {
/* load the data for the encoding */
data.object_type = OBJECT_FILE;
data.object_instance = file_instance;
data.access = FILE_STREAM_ACCESS;
data.type.stream.fileStartPosition = fileStartPosition;
data.type.stream.requestedOctetCount = requestedOctetCount;
pdu_len = arf_encode_apdu(&Handler_Transmit_Buffer[0],
invoke_id, &data);
/* will the APDU fit the target device?
note: if there is a bottleneck router in between
us and the destination, we won't know unless
we have a way to check for that and update the
max_apdu in the address binding table. */
if ((unsigned) pdu_len < max_apdu) {
npdu_encode_confirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL);
tsm_set_confirmed_unsegmented_transaction(invoke_id,
&dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
bytes_sent = datalink_send_pdu(&dest, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0)
fprintf(stderr,
"Failed to Send AtomicReadFile Request (%s)!\n",
strerror(errno));
#endif
} else {
tsm_free_invoke_id(invoke_id);
invoke_id = 0;
#if PRINT_ENABLED
fprintf(stderr, "Failed to Send AtomicReadFile Request "
"(payload exceeds destination maximum APDU)!\n");
#endif
}
}
return invoke_id;
}
+111
View File
@@ -0,0 +1,111 @@
/**************************************************************************
*
* Copyright (C) 2006 Steve Karg <skarg@users.sourceforge.net>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*********************************************************************/
#include <stddef.h>
#include <stdint.h>
#include <errno.h>
#include "config.h"
#include "config.h"
#include "txbuf.h"
#include "bacdef.h"
#include "bacdcode.h"
#include "address.h"
#include "tsm.h"
#include "npdu.h"
#include "apdu.h"
#include "device.h"
#include "datalink.h"
#include "awf.h"
/* some demo stuff needed */
#include "handlers.h"
#include "txbuf.h"
uint8_t Send_Atomic_Write_File_Stream(uint32_t device_id,
uint32_t file_instance,
int fileStartPosition, BACNET_OCTET_STRING * fileData)
{
BACNET_ADDRESS dest;
BACNET_NPDU_DATA npdu_data;
unsigned max_apdu = 0;
uint8_t invoke_id = 0;
bool status = false;
int pdu_len = 0;
int bytes_sent = 0;
BACNET_ATOMIC_WRITE_FILE_DATA data;
/* is the device bound? */
status = address_get_by_device(device_id, &max_apdu, &dest);
/* is there a tsm available? */
if (status)
invoke_id = tsm_next_free_invokeID();
if (invoke_id) {
/* load the data for the encoding */
data.object_type = OBJECT_FILE;
data.object_instance = file_instance;
data.access = FILE_STREAM_ACCESS;
data.type.stream.fileStartPosition = fileStartPosition;
status = octetstring_copy(&data.fileData, fileData);
if (status) {
pdu_len = awf_encode_apdu(&Handler_Transmit_Buffer[0],
invoke_id, &data);
/* will the APDU fit the target device?
note: if there is a bottleneck router in between
us and the destination, we won't know unless
we have a way to check for that and update the
max_apdu in the address binding table. */
if ((unsigned) pdu_len <= max_apdu) {
npdu_encode_confirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL);
tsm_set_confirmed_unsegmented_transaction(invoke_id,
&dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
bytes_sent = datalink_send_pdu(&dest, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0)
fprintf(stderr,
"Failed to Send AtomicWriteFile Request (%s)!\n",
strerror(errno));
#endif
} else {
tsm_free_invoke_id(invoke_id);
invoke_id = 0;
#if PRINT_ENABLED
fprintf(stderr, "Failed to Send AtomicWriteFile Request "
"(payload [%d] exceeds destination maximum APDU [%u])!\n",
pdu_len, max_apdu);
#endif
}
} else {
tsm_free_invoke_id(invoke_id);
invoke_id = 0;
#if PRINT_ENABLED
fprintf(stderr, "Failed to Send AtomicWriteFile Request "
"(payload [%d] exceeds octet string capacity)!\n",
pdu_len);
#endif
}
}
return invoke_id;
}
+15 -12
View File
@@ -45,13 +45,13 @@ uint8_t Send_Device_Communication_Control_Request(uint32_t device_id, uint16_t t
BACNET_COMMUNICATION_ENABLE_DISABLE state, char *password) BACNET_COMMUNICATION_ENABLE_DISABLE state, char *password)
{ /* NULL=optional */ { /* NULL=optional */
BACNET_ADDRESS dest; BACNET_ADDRESS dest;
BACNET_ADDRESS my_address;
unsigned max_apdu = 0; unsigned max_apdu = 0;
uint8_t invoke_id = 0; uint8_t invoke_id = 0;
bool status = false; bool status = false;
int pdu_len = 0; int pdu_len = 0;
int bytes_sent = 0; int bytes_sent = 0;
BACNET_CHARACTER_STRING password_string; BACNET_CHARACTER_STRING password_string;
BACNET_NPDU_DATA npdu_data;
if (!dcc_communication_enabled()) if (!dcc_communication_enabled())
return 0; return 0;
@@ -60,16 +60,11 @@ uint8_t Send_Device_Communication_Control_Request(uint32_t device_id, uint16_t t
status = address_get_by_device(device_id, &max_apdu, &dest); status = address_get_by_device(device_id, &max_apdu, &dest);
/* is there a tsm available? */ /* is there a tsm available? */
if (status) if (status)
status = tsm_transaction_available();
if (status) {
datalink_get_my_address(&my_address);
pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], &dest, &my_address, true, /* true for confirmed messages */
MESSAGE_PRIORITY_NORMAL);
invoke_id = tsm_next_free_invokeID(); invoke_id = tsm_next_free_invokeID();
if (invoke_id) {
/* load the data for the encoding */ /* load the data for the encoding */
characterstring_init_ansi(&password_string, password); characterstring_init_ansi(&password_string, password);
pdu_len += dcc_encode_apdu(&Handler_Transmit_Buffer[pdu_len], pdu_len = dcc_encode_apdu(&Handler_Transmit_Buffer[0],
invoke_id, invoke_id,
timeDuration, state, password ? &password_string : NULL); timeDuration, state, password ? &password_string : NULL);
/* will it fit in the sender? /* will it fit in the sender?
@@ -78,18 +73,26 @@ uint8_t Send_Device_Communication_Control_Request(uint32_t device_id, uint16_t t
we have a way to check for that and update the we have a way to check for that and update the
max_apdu in the address binding table. */ max_apdu in the address binding table. */
if ((unsigned) pdu_len < max_apdu) { if ((unsigned) pdu_len < max_apdu) {
npdu_encode_confirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL);
tsm_set_confirmed_unsegmented_transaction(invoke_id, tsm_set_confirmed_unsegmented_transaction(invoke_id,
&dest, &Handler_Transmit_Buffer[0], pdu_len); &dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
bytes_sent = datalink_send_pdu(&dest, /* destination address */ bytes_sent = datalink_send_pdu(&dest, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */ &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, fprintf(stderr,
"Failed to Send DeviceCommunicationControl Request (%s)!\n", "Failed to Send DeviceCommunicationControl Request (%s)!\n",
strerror(errno)); strerror(errno));
} else #endif
} else {
tsm_free_invoke_id(invoke_id);
invoke_id = 0;
#if PRINT_ENABLED
fprintf(stderr, fprintf(stderr,
"Failed to Send DeviceCommunicationControl Request " "Failed to Send DeviceCommunicationControl Request "
"(exceeds destination maximum APDU)!\n"); "(exceeds destination maximum APDU)!\n");
#endif
}
} }
return invoke_id; return invoke_id;
+6 -5
View File
@@ -51,26 +51,27 @@ void Send_I_Have(uint32_t device_id,
BACNET_ADDRESS dest; BACNET_ADDRESS dest;
int bytes_sent = 0; int bytes_sent = 0;
BACNET_I_HAVE_DATA data; BACNET_I_HAVE_DATA data;
BACNET_NPDU_DATA npdu_data;
/* if we are forbidden to send, don't send! */ /* if we are forbidden to send, don't send! */
if (!dcc_communication_enabled()) if (!dcc_communication_enabled())
return; return;
/* Who-Has is a global broadcast */ /* Who-Has is a global broadcast */
datalink_get_broadcast_address(&dest); datalink_get_broadcast_address(&dest);
/* encode the NPDU portion of the packet */
pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], &dest, NULL, false, /* true for confirmed messages */
MESSAGE_PRIORITY_NORMAL);
/* encode the APDU portion of the packet */ /* encode the APDU portion of the packet */
data.device_id.type = OBJECT_DEVICE; data.device_id.type = OBJECT_DEVICE;
data.device_id.instance = device_id; data.device_id.instance = device_id;
data.object_id.type = object_type; data.object_id.type = object_type;
data.object_id.instance = object_instance; data.object_id.instance = object_instance;
characterstring_init_ansi(&data.object_name, object_name); characterstring_init_ansi(&data.object_name, object_name);
pdu_len += ihave_encode_apdu(&Handler_Transmit_Buffer[pdu_len], &data); pdu_len = ihave_encode_apdu(&Handler_Transmit_Buffer[0], &data);
/* send the data */ /* send the data */
bytes_sent = datalink_send_pdu(&dest, /* destination address */ npdu_encode_unconfirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL);
bytes_sent = datalink_send_pdu(&dest, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */ &Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */
#if PRINT_ENABLED
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, "Failed to Send I-Have Reply (%s)!\n", fprintf(stderr, "Failed to Send I-Have Reply (%s)!\n",
strerror(errno)); strerror(errno));
#endif
} }
+15 -12
View File
@@ -46,13 +46,13 @@ uint8_t Send_Reinitialize_Device_Request(uint32_t device_id,
BACNET_REINITIALIZED_STATE state, char *password) BACNET_REINITIALIZED_STATE state, char *password)
{ {
BACNET_ADDRESS dest; BACNET_ADDRESS dest;
BACNET_ADDRESS my_address;
unsigned max_apdu = 0; unsigned max_apdu = 0;
uint8_t invoke_id = 0; uint8_t invoke_id = 0;
bool status = false; bool status = false;
int pdu_len = 0; int pdu_len = 0;
int bytes_sent = 0; int bytes_sent = 0;
BACNET_CHARACTER_STRING password_string; BACNET_CHARACTER_STRING password_string;
BACNET_NPDU_DATA npdu_data;
if (!dcc_communication_enabled()) if (!dcc_communication_enabled())
return 0; return 0;
@@ -61,16 +61,11 @@ uint8_t Send_Reinitialize_Device_Request(uint32_t device_id,
status = address_get_by_device(device_id, &max_apdu, &dest); status = address_get_by_device(device_id, &max_apdu, &dest);
/* is there a tsm available? */ /* is there a tsm available? */
if (status) if (status)
status = tsm_transaction_available();
if (status) {
datalink_get_my_address(&my_address);
pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], &dest, &my_address, true, /* true for confirmed messages */
MESSAGE_PRIORITY_NORMAL);
invoke_id = tsm_next_free_invokeID(); invoke_id = tsm_next_free_invokeID();
if (invoke_id) {
/* load the data for the encoding */ /* load the data for the encoding */
characterstring_init_ansi(&password_string, password); characterstring_init_ansi(&password_string, password);
pdu_len += rd_encode_apdu(&Handler_Transmit_Buffer[pdu_len], pdu_len = rd_encode_apdu(&Handler_Transmit_Buffer[0],
invoke_id, state, password ? &password_string : NULL); invoke_id, state, password ? &password_string : NULL);
/* will it fit in the sender? /* will it fit in the sender?
note: if there is a bottleneck router in between note: if there is a bottleneck router in between
@@ -78,17 +73,25 @@ uint8_t Send_Reinitialize_Device_Request(uint32_t device_id,
we have a way to check for that and update the we have a way to check for that and update the
max_apdu in the address binding table. */ max_apdu in the address binding table. */
if ((unsigned) pdu_len < max_apdu) { if ((unsigned) pdu_len < max_apdu) {
npdu_encode_confirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL);
tsm_set_confirmed_unsegmented_transaction(invoke_id, tsm_set_confirmed_unsegmented_transaction(invoke_id,
&dest, &Handler_Transmit_Buffer[0], pdu_len); &dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
bytes_sent = datalink_send_pdu(&dest, /* destination address */ bytes_sent = datalink_send_pdu(&dest, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */ &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, fprintf(stderr,
"Failed to Send ReinitializeDevice Request (%s)!\n", "Failed to Send ReinitializeDevice Request (%s)!\n",
strerror(errno)); strerror(errno));
} else #endif
} else {
tsm_free_invoke_id(invoke_id);
invoke_id = 0;
#if PRINT_ENABLED
fprintf(stderr, "Failed to Send ReinitializeDevice Request " fprintf(stderr, "Failed to Send ReinitializeDevice Request "
"(exceeds destination maximum APDU)!\n"); "(exceeds destination maximum APDU)!\n");
#endif
}
} }
return invoke_id; return invoke_id;
+15 -12
View File
@@ -49,13 +49,13 @@ uint8_t Send_Read_Property_Request(uint32_t device_id, /* destination device */
BACNET_PROPERTY_ID object_property, int32_t array_index) BACNET_PROPERTY_ID object_property, int32_t array_index)
{ {
BACNET_ADDRESS dest; BACNET_ADDRESS dest;
BACNET_ADDRESS my_address;
unsigned max_apdu = 0; unsigned max_apdu = 0;
uint8_t invoke_id = 0; uint8_t invoke_id = 0;
bool status = false; bool status = false;
int pdu_len = 0; int pdu_len = 0;
int bytes_sent = 0; int bytes_sent = 0;
BACNET_READ_PROPERTY_DATA data; BACNET_READ_PROPERTY_DATA data;
BACNET_NPDU_DATA npdu_data;
if (!dcc_communication_enabled()) if (!dcc_communication_enabled())
return 0; return 0;
@@ -64,19 +64,14 @@ uint8_t Send_Read_Property_Request(uint32_t device_id, /* destination device */
status = address_get_by_device(device_id, &max_apdu, &dest); status = address_get_by_device(device_id, &max_apdu, &dest);
/* is there a tsm available? */ /* is there a tsm available? */
if (status) if (status)
status = tsm_transaction_available();
if (status) {
datalink_get_my_address(&my_address);
pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], &dest, &my_address, true, /* true for confirmed messages */
MESSAGE_PRIORITY_NORMAL);
invoke_id = tsm_next_free_invokeID(); invoke_id = tsm_next_free_invokeID();
if (invoke_id) {
/* load the data for the encoding */ /* load the data for the encoding */
data.object_type = object_type; data.object_type = object_type;
data.object_instance = object_instance; data.object_instance = object_instance;
data.object_property = object_property; data.object_property = object_property;
data.array_index = array_index; data.array_index = array_index;
pdu_len += rp_encode_apdu(&Handler_Transmit_Buffer[pdu_len], pdu_len = rp_encode_apdu(&Handler_Transmit_Buffer[0],
invoke_id, &data); invoke_id, &data);
/* will it fit in the sender? /* will it fit in the sender?
note: if there is a bottleneck router in between note: if there is a bottleneck router in between
@@ -84,17 +79,25 @@ uint8_t Send_Read_Property_Request(uint32_t device_id, /* destination device */
we have a way to check for that and update the we have a way to check for that and update the
max_apdu in the address binding table. */ max_apdu in the address binding table. */
if ((unsigned) pdu_len < max_apdu) { if ((unsigned) pdu_len < max_apdu) {
npdu_encode_confirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL);
tsm_set_confirmed_unsegmented_transaction(invoke_id, tsm_set_confirmed_unsegmented_transaction(invoke_id,
&dest, &Handler_Transmit_Buffer[0], pdu_len); &dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
bytes_sent = datalink_send_pdu(&dest, /* destination address */ bytes_sent = datalink_send_pdu(&dest, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */ &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, fprintf(stderr,
"Failed to Send ReadProperty Request (%s)!\n", "Failed to Send ReadProperty Request (%s)!\n",
strerror(errno)); strerror(errno));
} else #endif
} else {
tsm_free_invoke_id(invoke_id);
invoke_id = 0;
#if PRINT_ENABLED
fprintf(stderr, "Failed to Send ReadProperty Request " fprintf(stderr, "Failed to Send ReadProperty Request "
"(exceeds destination maximum APDU)!\n"); "(exceeds destination maximum APDU)!\n");
#endif
}
} }
return invoke_id; return invoke_id;
+12 -11
View File
@@ -47,25 +47,26 @@ void Send_TimeSync(BACNET_DATE * bdate, BACNET_TIME * btime)
int pdu_len = 0; int pdu_len = 0;
BACNET_ADDRESS dest; BACNET_ADDRESS dest;
int bytes_sent = 0; int bytes_sent = 0;
BACNET_NPDU_DATA npdu_data;
if (!dcc_communication_enabled()) if (!dcc_communication_enabled())
return; return;
/* we could use unicast or broadcast */ /* we could use unicast or broadcast */
datalink_get_broadcast_address(&dest); datalink_get_broadcast_address(&dest);
/* encode the NPDU portion of the packet */
pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], &dest, NULL, false, /* true for confirmed messages */
MESSAGE_PRIORITY_NORMAL);
/* encode the APDU portion of the packet */ /* encode the APDU portion of the packet */
pdu_len += timesync_encode_apdu(&Handler_Transmit_Buffer[pdu_len], pdu_len = timesync_encode_apdu(&Handler_Transmit_Buffer[0],
bdate, btime); bdate, btime);
npdu_encode_unconfirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL);
/* send it out the datalink */ /* send it out the datalink */
bytes_sent = datalink_send_pdu(&dest, bytes_sent = datalink_send_pdu(&dest, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len); &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, fprintf(stderr,
"Failed to Send Time-Synchronization Request (%s)!\n", "Failed to Send Time-Synchronization Request (%s)!\n",
strerror(errno)); strerror(errno));
#endif
} }
void Send_TimeSyncUTC(BACNET_DATE * bdate, BACNET_TIME * btime) void Send_TimeSyncUTC(BACNET_DATE * bdate, BACNET_TIME * btime)
@@ -73,23 +74,23 @@ void Send_TimeSyncUTC(BACNET_DATE * bdate, BACNET_TIME * btime)
int pdu_len = 0; int pdu_len = 0;
BACNET_ADDRESS dest; BACNET_ADDRESS dest;
int bytes_sent = 0; int bytes_sent = 0;
BACNET_NPDU_DATA npdu_data;
if (!dcc_communication_enabled()) if (!dcc_communication_enabled())
return; return;
/* we could use unicast or broadcast */ /* we could use unicast or broadcast */
datalink_get_broadcast_address(&dest); datalink_get_broadcast_address(&dest);
/* encode the NPDU portion of the packet */
pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], &dest, NULL, false, /* true for confirmed messages */
MESSAGE_PRIORITY_NORMAL);
/* encode the APDU portion of the packet */ /* encode the APDU portion of the packet */
pdu_len += timesync_utc_encode_apdu(&Handler_Transmit_Buffer[pdu_len], pdu_len = timesync_utc_encode_apdu(&Handler_Transmit_Buffer[0],
bdate, btime); bdate, btime);
/* send it out the datalink */ npdu_encode_unconfirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL);
bytes_sent = datalink_send_pdu(&dest, bytes_sent = datalink_send_pdu(&dest, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len); &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, fprintf(stderr,
"Failed to Send UTC-Time-Synchronization Request (%s)!\n", "Failed to Send UTC-Time-Synchronization Request (%s)!\n",
strerror(errno)); strerror(errno));
#endif
} }
+14 -14
View File
@@ -50,28 +50,29 @@ void Send_WhoHas_Name(int32_t low_limit,
BACNET_ADDRESS dest; BACNET_ADDRESS dest;
int bytes_sent = 0; int bytes_sent = 0;
BACNET_WHO_HAS_DATA data; BACNET_WHO_HAS_DATA data;
BACNET_NPDU_DATA npdu_data;
/* if we are forbidden to send, don't send! */ /* if we are forbidden to send, don't send! */
if (!dcc_communication_enabled()) if (!dcc_communication_enabled())
return; return;
/* Who-Has is a global broadcast */ /* Who-Has is a global broadcast */
datalink_get_broadcast_address(&dest); datalink_get_broadcast_address(&dest);
/* encode the NPDU portion of the packet */
pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], &dest, NULL, false, /* true for confirmed messages */
MESSAGE_PRIORITY_NORMAL);
/* encode the APDU portion of the packet */ /* encode the APDU portion of the packet */
data.low_limit = low_limit; data.low_limit = low_limit;
data.high_limit = high_limit; data.high_limit = high_limit;
data.object_name = true; data.object_name = true;
characterstring_init_ansi(&data.object.name, object_name); characterstring_init_ansi(&data.object.name, object_name);
pdu_len += whohas_encode_apdu(&Handler_Transmit_Buffer[pdu_len], pdu_len = whohas_encode_apdu(&Handler_Transmit_Buffer[0],
&data); &data);
npdu_encode_unconfirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL);
/* send the data */ /* send the data */
bytes_sent = datalink_send_pdu(&dest, /* destination address */ bytes_sent = datalink_send_pdu(&dest, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */ &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, "Failed to Send Who-Has Request (%s)!\n", fprintf(stderr, "Failed to Send Who-Has Request (%s)!\n",
strerror(errno)); strerror(errno));
#endif
} }
/* find a specific device, or use -1 for limit if you want unlimited */ /* find a specific device, or use -1 for limit if you want unlimited */
@@ -83,27 +84,26 @@ void Send_WhoHas_Object(int32_t low_limit,
BACNET_ADDRESS dest; BACNET_ADDRESS dest;
int bytes_sent = 0; int bytes_sent = 0;
BACNET_WHO_HAS_DATA data; BACNET_WHO_HAS_DATA data;
BACNET_NPDU_DATA npdu_data;
/* if we are forbidden to send, don't send! */ /* if we are forbidden to send, don't send! */
if (!dcc_communication_enabled()) if (!dcc_communication_enabled())
return; return;
/* Who-Has is a global broadcast */ /* Who-Has is a global broadcast */
datalink_get_broadcast_address(&dest); datalink_get_broadcast_address(&dest);
/* encode the NPDU portion of the packet */
pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], &dest, NULL, false, /* true for confirmed messages */
MESSAGE_PRIORITY_NORMAL);
/* encode the APDU portion of the packet */ /* encode the APDU portion of the packet */
data.low_limit = low_limit; data.low_limit = low_limit;
data.high_limit = high_limit; data.high_limit = high_limit;
data.object_name = false; data.object_name = false;
data.object.identifier.type = object_type; data.object.identifier.type = object_type;
data.object.identifier.instance = object_instance; data.object.identifier.instance = object_instance;
pdu_len += whohas_encode_apdu(&Handler_Transmit_Buffer[pdu_len], pdu_len = whohas_encode_apdu(&Handler_Transmit_Buffer[0], &data);
&data); npdu_encode_unconfirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL);
/* send the data */ bytes_sent = datalink_send_pdu(&dest, &npdu_data,
bytes_sent = datalink_send_pdu(&dest, /* destination address */ &Handler_Transmit_Buffer[0], pdu_len);
&Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */ #if PRINT_ENABLED
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, "Failed to Send Who-Has Request (%s)!\n", fprintf(stderr, "Failed to Send Who-Has Request (%s)!\n",
strerror(errno)); strerror(errno));
#endif
} }
+7 -9
View File
@@ -48,24 +48,22 @@ void Send_WhoIs(int32_t low_limit, int32_t high_limit)
int pdu_len = 0; int pdu_len = 0;
BACNET_ADDRESS dest; BACNET_ADDRESS dest;
int bytes_sent = 0; int bytes_sent = 0;
BACNET_NPDU_DATA npdu_data;
if (!dcc_communication_enabled()) if (!dcc_communication_enabled())
return; return;
/* Who-Is is a global broadcast */ /* Who-Is is a global broadcast */
datalink_get_broadcast_address(&dest); datalink_get_broadcast_address(&dest);
/* encode the NPDU portion of the packet */
pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], &dest, NULL, false, /* true for confirmed messages */
MESSAGE_PRIORITY_NORMAL);
/* encode the APDU portion of the packet */ /* encode the APDU portion of the packet */
pdu_len += whois_encode_apdu(&Handler_Transmit_Buffer[pdu_len], pdu_len = whois_encode_apdu(&Handler_Transmit_Buffer[0],
low_limit, high_limit); low_limit, high_limit);
npdu_encode_unconfirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL);
bytes_sent = datalink_send_pdu(&dest, /* destination address */ bytes_sent = datalink_send_pdu(&dest, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */ &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, "Failed to Send Who-Is Request (%s)!\n", fprintf(stderr, "Failed to Send Who-Is Request (%s)!\n",
strerror(errno)); strerror(errno));
#endif
} }
+15 -12
View File
@@ -51,13 +51,13 @@ uint8_t Send_Write_Property_Request(uint32_t device_id, /* destination device */
uint8_t priority, int32_t array_index) uint8_t priority, int32_t array_index)
{ {
BACNET_ADDRESS dest; BACNET_ADDRESS dest;
BACNET_ADDRESS my_address;
unsigned max_apdu = 0; unsigned max_apdu = 0;
uint8_t invoke_id = 0; uint8_t invoke_id = 0;
bool status = false; bool status = false;
int pdu_len = 0; int pdu_len = 0;
int bytes_sent = 0; int bytes_sent = 0;
BACNET_WRITE_PROPERTY_DATA data; BACNET_WRITE_PROPERTY_DATA data;
BACNET_NPDU_DATA npdu_data;
if (!dcc_communication_enabled()) if (!dcc_communication_enabled())
return 0; return 0;
@@ -66,13 +66,8 @@ uint8_t Send_Write_Property_Request(uint32_t device_id, /* destination device */
status = address_get_by_device(device_id, &max_apdu, &dest); status = address_get_by_device(device_id, &max_apdu, &dest);
/* is there a tsm available? */ /* is there a tsm available? */
if (status) if (status)
status = tsm_transaction_available();
if (status) {
datalink_get_my_address(&my_address);
pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], &dest, &my_address, true, /* true for confirmed messages */
MESSAGE_PRIORITY_NORMAL);
invoke_id = tsm_next_free_invokeID(); invoke_id = tsm_next_free_invokeID();
if (invoke_id) {
/* load the data for the encoding */ /* load the data for the encoding */
data.object_type = object_type; data.object_type = object_type;
data.object_instance = object_instance; data.object_instance = object_instance;
@@ -80,7 +75,7 @@ uint8_t Send_Write_Property_Request(uint32_t device_id, /* destination device */
data.array_index = array_index; data.array_index = array_index;
bacapp_copy(&data.value, object_value); bacapp_copy(&data.value, object_value);
data.priority = priority; data.priority = priority;
pdu_len += wp_encode_apdu(&Handler_Transmit_Buffer[pdu_len], pdu_len = wp_encode_apdu(&Handler_Transmit_Buffer[0],
invoke_id, &data); invoke_id, &data);
/* will it fit in the sender? /* will it fit in the sender?
note: if there is a bottleneck router in between note: if there is a bottleneck router in between
@@ -88,17 +83,25 @@ uint8_t Send_Write_Property_Request(uint32_t device_id, /* destination device */
we have a way to check for that and update the we have a way to check for that and update the
max_apdu in the address binding table. */ max_apdu in the address binding table. */
if ((unsigned) pdu_len < max_apdu) { if ((unsigned) pdu_len < max_apdu) {
npdu_encode_confirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL);
tsm_set_confirmed_unsegmented_transaction(invoke_id, tsm_set_confirmed_unsegmented_transaction(invoke_id,
&dest, &Handler_Transmit_Buffer[0], pdu_len); &dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
bytes_sent = datalink_send_pdu(&dest, /* destination address */ bytes_sent = datalink_send_pdu(&dest, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */ &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, fprintf(stderr,
"Failed to Send WriteProperty Request (%s)!\n", "Failed to Send WriteProperty Request (%s)!\n",
strerror(errno)); strerror(errno));
} else #endif
} else {
tsm_free_invoke_id(invoke_id);
invoke_id = 0;
#if PRINT_ENABLED
fprintf(stderr, "Failed to Send WriteProperty Request " fprintf(stderr, "Failed to Send WriteProperty Request "
"(exceeds destination maximum APDU)!\n"); "(exceeds destination maximum APDU)!\n");
#endif
}
} }
return invoke_id; return invoke_id;
+8 -12
View File
@@ -301,25 +301,21 @@ uint32_t bacfile_instance_from_tsm(uint8_t invokeID)
uint8_t *service_request = NULL; uint8_t *service_request = NULL;
uint16_t service_request_len = 0; uint16_t service_request_len = 0;
BACNET_ADDRESS dest; /* where the original packet was destined */ BACNET_ADDRESS dest; /* where the original packet was destined */
uint8_t pdu[MAX_PDU] = { 0 }; /* original sent packet */ uint8_t apdu[MAX_PDU] = { 0 }; /* original APDU packet */
uint16_t pdu_len = 0; /* original packet length */ uint16_t apdu_len = 0; /* original APDU packet length */
uint16_t len = 0; /* apdu header length */ uint16_t len = 0; /* apdu header length */
BACNET_ATOMIC_READ_FILE_DATA data = { 0 }; BACNET_ATOMIC_READ_FILE_DATA data = { 0 };
uint32_t object_instance = BACNET_MAX_INSTANCE + 1; /* return value */ uint32_t object_instance = BACNET_MAX_INSTANCE + 1; /* return value */
bool found = false; bool found = false;
int apdu_offset = 0; int apdu_offset = 0;
found = tsm_get_transaction_pdu(invokeID, &dest, &pdu[0], &pdu_len); found = tsm_get_transaction_pdu(invokeID, &dest, &npdu_data, &apdu[0],
&apdu_len);
if (found) { if (found) {
apdu_offset = npdu_decode(&pdu[0], /* data to decode */ if (!npdu_data.network_layer_message && npdu_data.confirmed_message &&
NULL, /* destination address - get the DNET/DLEN/DADR if in there */ (apdu[0] == PDU_TYPE_CONFIRMED_SERVICE_REQUEST)) {
NULL, /* source address - get the SNET/SLEN/SADR if in there */ len = apdu_decode_confirmed_service_request(&apdu[0],
&npdu_data); /* amount of data to decode */ apdu_len - apdu_offset,
if (!npdu_data.network_layer_message &&
((pdu[apdu_offset] & 0xF0) ==
PDU_TYPE_CONFIRMED_SERVICE_REQUEST)) {
len = apdu_decode_confirmed_service_request(&pdu[apdu_offset], /* APDU data */
pdu_len - apdu_offset,
&service_data, &service_data,
&service_choice, &service_request, &service_request_len); &service_choice, &service_request, &service_request_len);
if (service_choice == SERVICE_CONFIRMED_ATOMIC_READ_FILE) { if (service_choice == SERVICE_CONFIRMED_ATOMIC_READ_FILE) {
+2 -2
View File
@@ -269,12 +269,12 @@ bool Device_Set_Location(const char *name, size_t length)
uint8_t Device_Protocol_Version(void) uint8_t Device_Protocol_Version(void)
{ {
return 1; return BACNET_PROTOCOL_VERSION;
} }
uint8_t Device_Protocol_Revision(void) uint8_t Device_Protocol_Revision(void)
{ {
return 5; return BACNET_PROTOCOL_REVISION;
} }
uint16_t Device_Max_APDU_Length_Accepted(void) uint16_t Device_Max_APDU_Length_Accepted(void)
+2
View File
@@ -26,6 +26,8 @@ SRCS = readfile.c \
$(BACNET_HANDLER)/txbuf.c \ $(BACNET_HANDLER)/txbuf.c \
$(BACNET_HANDLER)/noserv.c \ $(BACNET_HANDLER)/noserv.c \
$(BACNET_HANDLER)/h_whois.c \ $(BACNET_HANDLER)/h_whois.c \
$(BACNET_HANDLER)/s_whois.c \
$(BACNET_HANDLER)/s_arfs.c \
$(BACNET_HANDLER)/h_rp.c \ $(BACNET_HANDLER)/h_rp.c \
$(BACNET_ROOT)/rp.c \ $(BACNET_ROOT)/rp.c \
$(BACNET_ROOT)/bacdcode.c \ $(BACNET_ROOT)/bacdcode.c \
+2
View File
@@ -23,6 +23,8 @@ SRCS = readfile.c \
..\..\demo\handler\txbuf.c \ ..\..\demo\handler\txbuf.c \
..\..\demo\handler\noserv.c \ ..\..\demo\handler\noserv.c \
..\..\demo\handler\h_whois.c \ ..\..\demo\handler\h_whois.c \
..\..\demo\handler\s_whois.c \
..\..\demo\handler\s_arfs.c \
..\..\demo\handler\h_rp.c \ ..\..\demo\handler\h_rp.c \
..\..\bacdcode.c \ ..\..\bacdcode.c \
..\..\bacapp.c \ ..\..\bacapp.c \
+2 -79
View File
@@ -46,6 +46,7 @@
/* some demo stuff needed */ /* some demo stuff needed */
#include "filename.h" #include "filename.h"
#include "handlers.h" #include "handlers.h"
#include "client.h"
#include "txbuf.h" #include "txbuf.h"
/* buffer used for receive */ /* buffer used for receive */
@@ -97,84 +98,6 @@ void MyRejectHandler(BACNET_ADDRESS * src,
Error_Detected = true; Error_Detected = true;
} }
static uint8_t Send_Atomic_Read_File_Stream(uint32_t device_id,
uint32_t file_instance,
int fileStartPosition, unsigned requestedOctetCount)
{
BACNET_ADDRESS dest;
BACNET_ADDRESS my_address;
unsigned max_apdu = 0;
uint8_t invoke_id = 0;
bool status = false;
int pdu_len = 0;
int bytes_sent = 0;
BACNET_ATOMIC_READ_FILE_DATA data;
/* is the device bound? */
status = address_get_by_device(device_id, &max_apdu, &dest);
/* is there a tsm available? */
if (status)
status = tsm_transaction_available();
if (status) {
datalink_get_my_address(&my_address);
pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], &dest, &my_address, true, /* true for confirmed messages */
MESSAGE_PRIORITY_NORMAL);
invoke_id = tsm_next_free_invokeID();
/* load the data for the encoding */
data.object_type = OBJECT_FILE;
data.object_instance = file_instance;
data.access = FILE_STREAM_ACCESS;
data.type.stream.fileStartPosition = fileStartPosition;
data.type.stream.requestedOctetCount = requestedOctetCount;
pdu_len += arf_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
invoke_id, &data);
/* will the APDU fit the target device?
note: if there is a bottleneck router in between
us and the destination, we won't know unless
we have a way to check for that and update the
max_apdu in the address binding table. */
if ((unsigned) pdu_len < max_apdu) {
tsm_set_confirmed_unsegmented_transaction(invoke_id,
&dest, &Handler_Transmit_Buffer[0], pdu_len);
bytes_sent = datalink_send_pdu(&dest, /* destination address */
&Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */
if (bytes_sent <= 0)
fprintf(stderr,
"Failed to Send AtomicReadFile Request (%s)!\n",
strerror(errno));
} else
fprintf(stderr, "Failed to Send AtomicReadFile Request "
"(payload exceeds destination maximum APDU)!\n");
}
return invoke_id;
}
static void Send_WhoIs(uint32_t device_id)
{
int pdu_len = 0;
BACNET_ADDRESS dest;
int bytes_sent = 0;
/* Who-Is is a global broadcast */
datalink_get_broadcast_address(&dest);
/* encode the NPDU portion of the packet */
pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], &dest, NULL, false, /* true for confirmed messages */
MESSAGE_PRIORITY_NORMAL);
/* encode the APDU portion of the packet */
pdu_len += whois_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
device_id, device_id);
bytes_sent = datalink_send_pdu(&dest, /* destination address */
&Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */
if (bytes_sent <= 0)
fprintf(stderr, "Failed to Send Who-Is Request (%s)!\n",
strerror(errno));
}
static void AtomicReadFileAckHandler(uint8_t * service_request, static void AtomicReadFileAckHandler(uint8_t * service_request,
uint16_t service_len, uint16_t service_len,
BACNET_ADDRESS * src, BACNET_CONFIRMED_SERVICE_ACK_DATA * service_data) BACNET_ADDRESS * src, BACNET_CONFIRMED_SERVICE_ACK_DATA * service_data)
@@ -316,7 +239,7 @@ int main(int argc, char *argv[])
timeout_seconds = (Device_APDU_Timeout() / 1000) * timeout_seconds = (Device_APDU_Timeout() / 1000) *
Device_Number_Of_APDU_Retries(); Device_Number_Of_APDU_Retries();
/* try to bind with the device */ /* try to bind with the device */
Send_WhoIs(Target_Device_Object_Instance); Send_WhoIs(Target_Device_Object_Instance,Target_Device_Object_Instance);
/* loop forever */ /* loop forever */
for (;;) { for (;;) {
/* increment timer - exit if timed out */ /* increment timer - exit if timed out */
+3 -1
View File
@@ -49,8 +49,10 @@
static uint8_t Rx_Buf[MAX_MPDU] = { 0 }; static uint8_t Rx_Buf[MAX_MPDU] = { 0 };
/* global variables used in this file */ /* global variables used in this file */
#if 0
static int32_t Target_Object_Instance_Min = 0; static int32_t Target_Object_Instance_Min = 0;
static int32_t Target_Object_Instance_Max = BACNET_MAX_INSTANCE; static int32_t Target_Object_Instance_Max = BACNET_MAX_INSTANCE;
#endif
static bool Error_Detected = false; static bool Error_Detected = false;
@@ -133,7 +135,7 @@ int main(int argc, char *argv[])
BACNET_ADDRESS my_address, broadcast_address; BACNET_ADDRESS my_address, broadcast_address;
#endif #endif
/* FIXME: we could send directed time sync, and how to we send UTC? */ /* FIXME: we could send directed time sync, and how do we send UTC? */
#if 0 #if 0
if (argc < 2) { if (argc < 2) {
printf("Usage: %s date time [device-instance]\r\n" printf("Usage: %s date time [device-instance]\r\n"
+2
View File
@@ -27,6 +27,8 @@ SRCS = writefile.c \
$(BACNET_HANDLER)/noserv.c \ $(BACNET_HANDLER)/noserv.c \
$(BACNET_HANDLER)/h_whois.c \ $(BACNET_HANDLER)/h_whois.c \
$(BACNET_HANDLER)/h_rp.c \ $(BACNET_HANDLER)/h_rp.c \
$(BACNET_HANDLER)/s_whois.c \
$(BACNET_HANDLER)/s_awfs.c \
$(BACNET_ROOT)/rp.c \ $(BACNET_ROOT)/rp.c \
$(BACNET_ROOT)/bacdcode.c \ $(BACNET_ROOT)/bacdcode.c \
$(BACNET_ROOT)/bacapp.c \ $(BACNET_ROOT)/bacapp.c \
+2
View File
@@ -24,6 +24,8 @@ SRCS = writefile.c \
..\..\demo\handler\noserv.c \ ..\..\demo\handler\noserv.c \
..\..\demo\handler\h_whois.c \ ..\..\demo\handler\h_whois.c \
..\..\demo\handler\h_rp.c \ ..\..\demo\handler\h_rp.c \
..\..\demo\handler\s_whois.c \
..\..\demo\handler\s_awr.c \
..\..\bacdcode.c \ ..\..\bacdcode.c \
..\..\bacapp.c \ ..\..\bacapp.c \
..\..\bacstr.c \ ..\..\bacstr.c \
+2 -85
View File
@@ -46,6 +46,7 @@
/* some demo stuff needed */ /* some demo stuff needed */
#include "filename.h" #include "filename.h"
#include "handlers.h" #include "handlers.h"
#include "client.h"
#include "txbuf.h" #include "txbuf.h"
/* buffer used for receive */ /* buffer used for receive */
@@ -97,90 +98,6 @@ void MyRejectHandler(BACNET_ADDRESS * src,
Error_Detected = true; Error_Detected = true;
} }
static uint8_t Send_Atomic_Write_File_Stream(uint32_t device_id,
uint32_t file_instance,
int fileStartPosition, BACNET_OCTET_STRING * fileData)
{
BACNET_ADDRESS dest;
BACNET_ADDRESS my_address;
unsigned max_apdu = 0;
uint8_t invoke_id = 0;
bool status = false;
int pdu_len = 0;
int bytes_sent = 0;
BACNET_ATOMIC_WRITE_FILE_DATA data;
/* is the device bound? */
status = address_get_by_device(device_id, &max_apdu, &dest);
/* is there a tsm available? */
if (status)
status = tsm_transaction_available();
if (status) {
datalink_get_my_address(&my_address);
pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], &dest, &my_address, true, /* true for confirmed messages */
MESSAGE_PRIORITY_NORMAL);
invoke_id = tsm_next_free_invokeID();
/* load the data for the encoding */
data.object_type = OBJECT_FILE;
data.object_instance = file_instance;
data.access = FILE_STREAM_ACCESS;
data.type.stream.fileStartPosition = fileStartPosition;
status = octetstring_copy(&data.fileData, fileData);
if (status) {
pdu_len += awf_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
invoke_id, &data);
/* will the APDU fit the target device?
note: if there is a bottleneck router in between
us and the destination, we won't know unless
we have a way to check for that and update the
max_apdu in the address binding table. */
if ((unsigned) pdu_len <= max_apdu) {
tsm_set_confirmed_unsegmented_transaction(invoke_id,
&dest, &Handler_Transmit_Buffer[0], pdu_len);
bytes_sent = datalink_send_pdu(&dest, /* destination address */
&Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */
if (bytes_sent <= 0)
fprintf(stderr,
"Failed to Send AtomicWriteFile Request (%s)!\n",
strerror(errno));
} else
fprintf(stderr, "Failed to Send AtomicWriteFile Request "
"(payload [%d] exceeds destination maximum APDU [%u])!\n",
pdu_len, max_apdu);
} else
fprintf(stderr, "Failed to Send AtomicWriteFile Request "
"(payload [%d] exceeds octet string capacity)!\n",
pdu_len);
}
return invoke_id;
}
static void Send_WhoIs(uint32_t device_id)
{
int pdu_len = 0;
BACNET_ADDRESS dest;
int bytes_sent = 0;
/* Who-Is is a global broadcast */
datalink_get_broadcast_address(&dest);
/* encode the NPDU portion of the packet */
pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], &dest, NULL, false, /* true for confirmed messages */
MESSAGE_PRIORITY_NORMAL);
/* encode the APDU portion of the packet */
pdu_len += whois_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
device_id, device_id);
bytes_sent = datalink_send_pdu(&dest, /* destination address */
&Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */
if (bytes_sent <= 0)
fprintf(stderr, "Failed to Send Who-Is Request (%s)!\n",
strerror(errno));
}
static void LocalIAmHandler(uint8_t * service_request, static void LocalIAmHandler(uint8_t * service_request,
uint16_t service_len, BACNET_ADDRESS * src) uint16_t service_len, BACNET_ADDRESS * src)
{ {
@@ -278,7 +195,7 @@ int main(int argc, char *argv[])
timeout_seconds = (Device_APDU_Timeout() / 1000) * timeout_seconds = (Device_APDU_Timeout() / 1000) *
Device_Number_Of_APDU_Retries(); Device_Number_Of_APDU_Retries();
/* try to bind with the device */ /* try to bind with the device */
Send_WhoIs(Target_Device_Object_Instance); Send_WhoIs(Target_Device_Object_Instance,Target_Device_Object_Instance);
/* loop forever */ /* loop forever */
for (;;) { for (;;) {
/* increment timer - exit if timed out */ /* increment timer - exit if timed out */
+8 -8
View File
@@ -139,21 +139,20 @@ int iam_send(uint8_t * buffer)
int pdu_len = 0; int pdu_len = 0;
BACNET_ADDRESS dest; BACNET_ADDRESS dest;
int bytes_sent = 0; int bytes_sent = 0;
BACNET_NPDU_DATA npdu_data;
/* I-Am is a global broadcast */ /* I-Am is a global broadcast */
datalink_get_broadcast_address(&dest); datalink_get_broadcast_address(&dest);
/* encode the NPDU portion of the packet */
pdu_len = npdu_encode_apdu(&buffer[0], &dest, NULL, false, /* true for confirmed messages */
MESSAGE_PRIORITY_NORMAL);
/* encode the APDU portion of the packet */ /* encode the APDU portion of the packet */
pdu_len += iam_encode_apdu(&buffer[pdu_len], pdu_len = iam_encode_apdu(&buffer[0],
Device_Object_Instance_Number(), Device_Object_Instance_Number(),
MAX_APDU, SEGMENTATION_NONE, Device_Vendor_Identifier()); MAX_APDU, SEGMENTATION_NONE, Device_Vendor_Identifier());
/* encode the NPDU portion of the packet */
bytes_sent = datalink_send_pdu(&dest, /* destination address */ npdu_encode_unconfirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL);
&buffer[0], pdu_len); /* number of bytes of data */ /* send data */
bytes_sent = datalink_send_pdu(&dest, &npdu_data,
&buffer[0], pdu_len);
return bytes_sent; return bytes_sent;
} }
@@ -219,6 +218,7 @@ void datalink_get_broadcast_address(BACNET_ADDRESS * dest)
} }
int datalink_send_pdu(BACNET_ADDRESS * dest, /* destination address */ int datalink_send_pdu(BACNET_ADDRESS * dest, /* destination address */
BACNET_NPDU_DATA * npdu_data, /* network information */
uint8_t * pdu, /* any data to be sent - may be null */ uint8_t * pdu, /* any data to be sent - may be null */
unsigned pdu_len) unsigned pdu_len)
{ /* number of bytes of data */ { /* number of bytes of data */
+68 -35
View File
@@ -40,17 +40,37 @@
#include "npdu.h" #include "npdu.h"
#include "apdu.h" #include "apdu.h"
int npdu_encode_raw(uint8_t * npdu, void npdu_copy_data(BACNET_NPDU_DATA * dest, BACNET_NPDU_DATA * src)
{
if (dest && src) {
dest->protocol_version = src->protocol_version;
dest->confirmed_message = src->confirmed_message;
dest->network_layer_message = src->network_layer_message;
dest->priority = src->priority;
dest->network_message_type = src->network_message_type;
dest->vendor_id = src->vendor_id;
dest->hop_count = src->hop_count;
}
return;
}
int npdu_encode_pdu(uint8_t * npdu,
BACNET_ADDRESS * dest, BACNET_ADDRESS * dest,
BACNET_ADDRESS * src, BACNET_NPDU_DATA * npdu_data) BACNET_ADDRESS * src,
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 */
int i = 0; /* counter */ int i = 0; /* counter */
if (npdu && npdu_data) { if (npdu && npdu_data) {
/* Protocol Version */ /* only include src address for data expecting reply, or replies */
npdu[0] = 1; if (!(npdu_data->confirmed_message))
/* control octet */ src = NULL;
/* protocol version */
npdu[0] = npdu_data->protocol_version;
/* initialize the control octet */
npdu[1] = 0; npdu[1] = 0;
/* Bit 7: 1 indicates that the NSDU conveys a network layer message. */ /* Bit 7: 1 indicates that the NSDU conveys a network layer message. */
/* Message Type field is present. */ /* Message Type field is present. */
@@ -74,15 +94,15 @@ int npdu_encode_raw(uint8_t * npdu,
/* SLEN > 0 specifies length of SADR field */ /* SLEN > 0 specifies length of SADR field */
if (src && src->net) if (src && src->net)
npdu[1] |= BIT3; npdu[1] |= BIT3;
/* Bit 2: The value of this bit corresponds to the data_expecting_reply */ /* Bit 2: The value of this bit corresponds to the */
/* parameter in the N-UNITDATA primitives. */ /* data_expecting_reply parameter in the N-UNITDATA primitives. */
/* 1 indicates that a BACnet-Confirmed-Request-PDU, */ /* 1 indicates that a BACnet-Confirmed-Request-PDU, */
/* a segment of a BACnet-ComplexACK-PDU, */ /* a segment of a BACnet-ComplexACK-PDU, */
/* or a network layer message expecting a reply is present. */ /* or a network layer message expecting a reply is present. */
/* 0 indicates that other than a BACnet-Confirmed-Request-PDU, */ /* 0 indicates that other than a BACnet-Confirmed-Request-PDU, */
/* a segment of a BACnet-ComplexACK-PDU, */ /* a segment of a BACnet-ComplexACK-PDU, */
/* or a network layer message expecting a reply is present. */ /* or a network layer message expecting a reply is present. */
if (npdu_data->data_expecting_reply) if (npdu_data->confirmed_message)
npdu[1] |= BIT2; npdu[1] |= BIT2;
/* Bits 1,0: Network priority where: */ /* Bits 1,0: Network priority where: */
/* B'11' = Life Safety message */ /* B'11' = Life Safety message */
@@ -133,20 +153,36 @@ int npdu_encode_raw(uint8_t * npdu,
return len; return len;
} }
/* encode the NPDU portion of the packet for an APDU */ /* Configure the NPDU portion of the packet for an APDU */
/* This function does not handle the network messages, just APDUs. */ /* This function does not handle the network messages, just APDUs. */
int npdu_encode_apdu(uint8_t * npdu, BACNET_ADDRESS * dest, BACNET_ADDRESS * src, bool data_expecting_reply, /* true for confirmed messages */ void npdu_encode_confirmed_apdu(BACNET_NPDU_DATA * npdu_data,
BACNET_MESSAGE_PRIORITY priority) BACNET_MESSAGE_PRIORITY priority)
{ {
BACNET_NPDU_DATA npdu_data = { 0 }; if (npdu_data)
{
npdu_data->confirmed_message = true;
npdu_data->protocol_version = BACNET_PROTOCOL_VERSION;
npdu_data->network_layer_message = false; /* false if APDU */
npdu_data->network_message_type = 0; /* optional */
npdu_data->vendor_id = 0; /* optional, if net message type is > 0x80 */
npdu_data->priority = priority;
npdu_data->hop_count = 0;
}
}
npdu_data.data_expecting_reply = data_expecting_reply; void npdu_encode_unconfirmed_apdu(BACNET_NPDU_DATA * npdu_data,
npdu_data.network_layer_message = false; /* false if APDU */ BACNET_MESSAGE_PRIORITY priority)
npdu_data.network_message_type = 0; /* optional */ {
npdu_data.vendor_id = 0; /* optional, if net message type is > 0x80 */ if (npdu_data)
npdu_data.priority = priority; {
/* call the real function... */ npdu_data->confirmed_message = false;
return npdu_encode_raw(npdu, dest, src, &npdu_data); npdu_data->protocol_version = BACNET_PROTOCOL_VERSION;
npdu_data->network_layer_message = false; /* false if APDU */
npdu_data->network_message_type = 0; /* optional */
npdu_data->vendor_id = 0; /* optional, if net message type is > 0x80 */
npdu_data->priority = priority;
npdu_data->hop_count = 0;
}
} }
int npdu_decode(uint8_t * npdu, int npdu_decode(uint8_t * npdu,
@@ -171,7 +207,7 @@ int npdu_decode(uint8_t * npdu,
npdu_data->network_layer_message = (npdu[1] & BIT7) ? true : false; npdu_data->network_layer_message = (npdu[1] & BIT7) ? true : false;
/*Bit 6: Reserved. Shall be zero. */ /*Bit 6: Reserved. Shall be zero. */
/* Bit 4: Reserved. Shall be zero. */ /* Bit 4: Reserved. Shall be zero. */
/* Bit 2: The value of this bit corresponds to the data_expecting_reply */ /* Bit 2: The value of this bit corresponds to data expecting reply */
/* parameter in the N-UNITDATA primitives. */ /* parameter in the N-UNITDATA primitives. */
/* 1 indicates that a BACnet-Confirmed-Request-PDU, */ /* 1 indicates that a BACnet-Confirmed-Request-PDU, */
/* a segment of a BACnet-ComplexACK-PDU, */ /* a segment of a BACnet-ComplexACK-PDU, */
@@ -179,7 +215,7 @@ int npdu_decode(uint8_t * npdu,
/* 0 indicates that other than a BACnet-Confirmed-Request-PDU, */ /* 0 indicates that other than a BACnet-Confirmed-Request-PDU, */
/* a segment of a BACnet-ComplexACK-PDU, */ /* a segment of a BACnet-ComplexACK-PDU, */
/* or a network layer message expecting a reply is present. */ /* or a network layer message expecting a reply is present. */
npdu_data->data_expecting_reply = (npdu[1] & BIT2) ? true : false; npdu_data->confirmed_message = (npdu[1] & BIT2) ? true : false;
/* Bits 1,0: Network priority where: */ /* Bits 1,0: Network priority where: */
/* B'11' = Life Safety message */ /* B'11' = Life Safety message */
/* B'10' = Critical Equipment message */ /* B'10' = Critical Equipment message */
@@ -277,16 +313,13 @@ void npdu_handler(BACNET_ADDRESS * src, /* source address */
BACNET_ADDRESS dest = { 0 }; BACNET_ADDRESS dest = { 0 };
BACNET_NPDU_DATA npdu_data = { 0 }; BACNET_NPDU_DATA npdu_data = { 0 };
apdu_offset = npdu_decode(&pdu[0], /* data to decode */ apdu_offset = npdu_decode(&pdu[0], &dest, src, &npdu_data);
&dest, /* destination address - get the DNET/DLEN/DADR if in there */
src, /* source address - get the SNET/SLEN/SADR if in there */
&npdu_data); /* amount of data to decode */
if (npdu_data.network_layer_message) { if (npdu_data.network_layer_message) {
/*FIXME: network layer message received! Handle it! */ /*FIXME: network layer message received! Handle it! */
} else { } else {
apdu_handler(src, /* only handle the version that we know how to handle */
npdu_data.data_expecting_reply, if (npdu_data.protocol_version == BACNET_PROTOCOL_VERSION)
&pdu[apdu_offset], pdu_len - apdu_offset); apdu_handler(src, &pdu[apdu_offset], pdu_len - apdu_offset);
} }
return; return;
@@ -306,7 +339,7 @@ void testNPDU2(Test * pTest)
BACNET_ADDRESS npdu_dest = { 0 }; BACNET_ADDRESS npdu_dest = { 0 };
BACNET_ADDRESS npdu_src = { 0 }; BACNET_ADDRESS npdu_src = { 0 };
int len = 0; int len = 0;
bool data_expecting_reply = false; /* true for confirmed messages */ bool confirmed_message = true; /* true for confirmed messages */
BACNET_MESSAGE_PRIORITY priority = MESSAGE_PRIORITY_NORMAL; BACNET_MESSAGE_PRIORITY priority = MESSAGE_PRIORITY_NORMAL;
BACNET_NPDU_DATA npdu_data = { 0 }; BACNET_NPDU_DATA npdu_data = { 0 };
int i = 0; /* counter */ int i = 0; /* counter */
@@ -336,13 +369,13 @@ void testNPDU2(Test * pTest)
for (i = 0; i < src.len; i++) { for (i = 0; i < src.len; i++) {
src.adr[i] = 0x40; src.adr[i] = 0x40;
} }
len = npdu_encode_apdu(&pdu[0], npdu_encode_confirmed_apdu(&npdu_data, priority);
&dest, &src, data_expecting_reply, priority); len = npdu_encode_pdu(&pdu[0], &dest, &src, &npdu_data);
ct_test(pTest, len != 0); ct_test(pTest, len != 0);
/* can we get the info back? */ /* can we get the info back? */
npdu_len = npdu_decode(&pdu[0], &npdu_dest, &npdu_src, &npdu_data); npdu_len = npdu_decode(&pdu[0], &npdu_dest, &npdu_src, &npdu_data);
ct_test(pTest, npdu_len != 0); ct_test(pTest, npdu_len != 0);
ct_test(pTest, npdu_data.data_expecting_reply == data_expecting_reply); ct_test(pTest, npdu_data.confirmed_message == confirmed_message);
ct_test(pTest, ct_test(pTest,
npdu_data.network_layer_message == network_layer_message); npdu_data.network_layer_message == network_layer_message);
ct_test(pTest, npdu_data.network_message_type == network_message_type); ct_test(pTest, npdu_data.network_message_type == network_message_type);
@@ -370,7 +403,7 @@ void testNPDU1(Test * pTest)
BACNET_ADDRESS npdu_dest = { 0 }; BACNET_ADDRESS npdu_dest = { 0 };
BACNET_ADDRESS npdu_src = { 0 }; BACNET_ADDRESS npdu_src = { 0 };
int len = 0; int len = 0;
bool data_expecting_reply = false; /* true for confirmed messages */ bool confirmed_message = false; /* true for confirmed messages */
BACNET_MESSAGE_PRIORITY priority = MESSAGE_PRIORITY_NORMAL; BACNET_MESSAGE_PRIORITY priority = MESSAGE_PRIORITY_NORMAL;
BACNET_NPDU_DATA npdu_data = { 0 }; BACNET_NPDU_DATA npdu_data = { 0 };
int i = 0; /* counter */ int i = 0; /* counter */
@@ -400,13 +433,13 @@ void testNPDU1(Test * pTest)
for (i = 0; i < MAX_MAC_LEN; i++) { for (i = 0; i < MAX_MAC_LEN; i++) {
src.adr[i] = 0; src.adr[i] = 0;
} }
len = npdu_encode_apdu(&pdu[0], npdu_encode_unconfirmed_apdu(&npdu_data, priority);
&dest, &src, data_expecting_reply, priority); len = npdu_encode_pdu(&pdu[0], &dest, &src, &npdu_data);
ct_test(pTest, len != 0); ct_test(pTest, len != 0);
/* can we get the info back? */ /* can we get the info back? */
npdu_len = npdu_decode(&pdu[0], &npdu_dest, &npdu_src, &npdu_data); npdu_len = npdu_decode(&pdu[0], &npdu_dest, &npdu_src, &npdu_data);
ct_test(pTest, npdu_len != 0); ct_test(pTest, npdu_len != 0);
ct_test(pTest, npdu_data.data_expecting_reply == data_expecting_reply); ct_test(pTest, npdu_data.confirmed_message == confirmed_message);
ct_test(pTest, ct_test(pTest,
npdu_data.network_layer_message == network_layer_message); npdu_data.network_layer_message == network_layer_message);
ct_test(pTest, npdu_data.network_message_type == network_message_type); ct_test(pTest, npdu_data.network_message_type == network_message_type);
+9 -4
View File
@@ -43,7 +43,7 @@
typedef struct bacnet_npdu_data_t { typedef struct bacnet_npdu_data_t {
uint8_t protocol_version; uint8_t protocol_version;
/* parts of the control octet: */ /* parts of the control octet: */
bool data_expecting_reply; /* true for confirmed messages */ bool confirmed_message; /* true for confirmed messages */
bool network_layer_message; /* false if APDU */ bool network_layer_message; /* false if APDU */
BACNET_MESSAGE_PRIORITY priority; BACNET_MESSAGE_PRIORITY priority;
/* optional network message info */ /* optional network message info */
@@ -57,12 +57,17 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
uint8_t npdu_encode_max_seg_max_apdu(int max_segs, int max_apdu); uint8_t npdu_encode_max_seg_max_apdu(int max_segs, int max_apdu);
int npdu_encode_raw(uint8_t * npdu,
int npdu_encode_pdu(uint8_t * npdu,
BACNET_ADDRESS * dest, BACNET_ADDRESS * dest,
BACNET_ADDRESS * src, BACNET_NPDU_DATA * npdu_data); BACNET_ADDRESS * src, BACNET_NPDU_DATA * npdu_data);
/* encode the NPDU portion of the packet for an APDU */
int npdu_encode_apdu(uint8_t * npdu, BACNET_ADDRESS * dest, BACNET_ADDRESS * src, bool data_expecting_reply, /* true for confirmed messages */ void npdu_encode_confirmed_apdu(BACNET_NPDU_DATA * npdu,
BACNET_MESSAGE_PRIORITY priority); BACNET_MESSAGE_PRIORITY priority);
void npdu_encode_unconfirmed_apdu(BACNET_NPDU_DATA * npdu,
BACNET_MESSAGE_PRIORITY priority);
void npdu_copy_data(BACNET_NPDU_DATA * dest, BACNET_NPDU_DATA * src);
int npdu_decode(uint8_t * npdu, int npdu_decode(uint8_t * npdu,
BACNET_ADDRESS * dest, BACNET_ADDRESS * dest,
+35 -26
View File
@@ -132,22 +132,26 @@ uint8_t tsm_next_free_invokeID(void)
uint8_t invokeID = 0; uint8_t invokeID = 0;
bool found = false; bool found = false;
while (!found) { /* is there even space available? */
index = tsm_find_invokeID_index(current_invokeID); if (tsm_transaction_available())
/* not found - that is good! */ {
if (index == MAX_TSM_TRANSACTIONS) { while (!found) {
found = true; index = tsm_find_invokeID_index(current_invokeID);
/* set this id into the table */ /* not found - that is good! */
index = tsm_find_first_free_index(); if (index == MAX_TSM_TRANSACTIONS) {
if (index != MAX_TSM_TRANSACTIONS) { found = true;
TSM_List[index].InvokeID = invokeID = current_invokeID; /* set this id into the table */
TSM_List[index].state = TSM_STATE_IDLE; index = tsm_find_first_free_index();
TSM_List[index].RequestTimer = Device_APDU_Timeout(); if (index != MAX_TSM_TRANSACTIONS) {
/* update for the next call or check */ TSM_List[index].InvokeID = invokeID = current_invokeID;
current_invokeID++; TSM_List[index].state = TSM_STATE_IDLE;
/* skip zero - we treat that internally as invalid or no free */ TSM_List[index].RequestTimer = Device_APDU_Timeout();
if (current_invokeID == 0) /* update for the next call or check */
current_invokeID = 1; current_invokeID++;
/* skip zero - we treat that internally as invalid or no free */
if (current_invokeID == 0)
current_invokeID = 1;
}
} }
} }
} }
@@ -156,7 +160,8 @@ uint8_t tsm_next_free_invokeID(void)
} }
void tsm_set_confirmed_unsegmented_transaction(uint8_t invokeID, void tsm_set_confirmed_unsegmented_transaction(uint8_t invokeID,
BACNET_ADDRESS * dest, uint8_t * pdu, uint16_t pdu_len) BACNET_ADDRESS * dest, BACNET_NPDU_DATA * ndpu_data,
uint8_t * apdu, uint16_t apdu_len)
{ {
uint16_t j = 0; uint16_t j = 0;
uint8_t index; uint8_t index;
@@ -170,10 +175,11 @@ void tsm_set_confirmed_unsegmented_transaction(uint8_t invokeID,
/* start the timer */ /* start the timer */
TSM_List[index].RequestTimer = Device_APDU_Timeout(); TSM_List[index].RequestTimer = Device_APDU_Timeout();
/* copy the data */ /* copy the data */
for (j = 0; j < pdu_len; j++) { for (j = 0; j < apdu_len; j++) {
TSM_List[index].pdu[j] = pdu[j]; TSM_List[index].apdu[j] = apdu[j];
} }
TSM_List[index].pdu_len = pdu_len; TSM_List[index].apdu_len = apdu_len;
npdu_copy_data(&TSM_List[index].npdu_data, ndpu_data);
address_copy(&TSM_List[index].dest, dest); address_copy(&TSM_List[index].dest, dest);
} }
} }
@@ -184,7 +190,8 @@ void tsm_set_confirmed_unsegmented_transaction(uint8_t invokeID,
/* used to retrieve the transaction payload */ /* used to retrieve the transaction payload */
/* if we wanted to find out what we sent (i.e. when we get an ack) */ /* if we wanted to find out what we sent (i.e. when we get an ack) */
bool tsm_get_transaction_pdu(uint8_t invokeID, bool tsm_get_transaction_pdu(uint8_t invokeID,
BACNET_ADDRESS * dest, uint8_t * pdu, uint16_t * pdu_len) BACNET_ADDRESS * dest, BACNET_NPDU_DATA * ndpu_data,
uint8_t * apdu, uint16_t * apdu_len)
{ {
uint16_t j = 0; uint16_t j = 0;
uint8_t index; uint8_t index;
@@ -197,10 +204,11 @@ bool tsm_get_transaction_pdu(uint8_t invokeID,
/* FIXME: we may want to free the transaction so it doesn't timeout */ /* FIXME: we may want to free the transaction so it doesn't timeout */
/* retrieve the transaction */ /* retrieve the transaction */
/* FIXME: bounds check the pdu_len? */ /* FIXME: bounds check the pdu_len? */
*pdu_len = TSM_List[index].pdu_len; *apdu_len = TSM_List[index].apdu_len;
for (j = 0; j < *pdu_len; j++) { for (j = 0; j < *apdu_len; j++) {
pdu[j] = TSM_List[index].pdu[j]; apdu[j] = TSM_List[index].apdu[j];
} }
npdu_copy_data(ndpu_data,&TSM_List[index].npdu_data);
address_copy(dest, &TSM_List[index].dest); address_copy(dest, &TSM_List[index].dest);
found = true; found = true;
} }
@@ -226,8 +234,9 @@ void tsm_timer_milliseconds(uint16_t milliseconds)
TSM_List[i].RetryCount--; TSM_List[i].RetryCount--;
TSM_List[i].RequestTimer = Device_APDU_Timeout(); TSM_List[i].RequestTimer = Device_APDU_Timeout();
if (TSM_List[i].RetryCount) { if (TSM_List[i].RetryCount) {
bytes_sent = datalink_send_pdu(&TSM_List[i].dest, /* destination address */ bytes_sent = datalink_send_pdu(&TSM_List[i].dest,
&TSM_List[i].pdu[0], TSM_List[i].pdu_len); /* number of bytes of data */ &TSM_List[i].npdu_data,
&TSM_List[i].apdu[0], TSM_List[i].apdu_len);
} else { } else {
TSM_List[i].InvokeID = 0; TSM_List[i].InvokeID = 0;
TSM_List[i].state = TSM_STATE_IDLE; TSM_List[i].state = TSM_STATE_IDLE;
+10 -5
View File
@@ -38,6 +38,7 @@
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
#include "bacdef.h" #include "bacdef.h"
#include "npdu.h"
/* note: TSM functionality is optional - only needed if we are /* note: TSM functionality is optional - only needed if we are
doing client requests */ doing client requests */
@@ -80,9 +81,11 @@ typedef struct BACnet_TSM_Data {
BACNET_TSM_STATE state; BACNET_TSM_STATE state;
/* the address we sent it to */ /* the address we sent it to */
BACNET_ADDRESS dest; BACNET_ADDRESS dest;
/* copy of the PDU, should we need to send it again */ /* the network layer info */
uint8_t pdu[MAX_PDU]; BACNET_NPDU_DATA npdu_data;
unsigned pdu_len; /* copy of the APDU, should we need to send it again */
uint8_t apdu[MAX_PDU];
unsigned apdu_len;
} BACNET_TSM_DATA; } BACNET_TSM_DATA;
#ifdef __cplusplus #ifdef __cplusplus
@@ -98,10 +101,12 @@ extern "C" {
uint8_t tsm_next_free_invokeID(void); uint8_t tsm_next_free_invokeID(void);
/* returns the same invoke ID that was given */ /* returns the same invoke ID that was given */
void tsm_set_confirmed_unsegmented_transaction(uint8_t invokeID, void tsm_set_confirmed_unsegmented_transaction(uint8_t invokeID,
BACNET_ADDRESS * dest, uint8_t * pdu, uint16_t pdu_len); BACNET_ADDRESS * dest, BACNET_NPDU_DATA * ndpu_data,
uint8_t * apdu, uint16_t apdu_len);
/* returns true if transaction is found */ /* returns true if transaction is found */
bool tsm_get_transaction_pdu(uint8_t invokeID, bool tsm_get_transaction_pdu(uint8_t invokeID,
BACNET_ADDRESS * dest, uint8_t * pdu, uint16_t * pdu_len); BACNET_ADDRESS * dest, BACNET_NPDU_DATA * ndpu_data,
uint8_t * apdu, uint16_t * apdu_len);
bool tsm_invoke_id_free(uint8_t invokeID); bool tsm_invoke_id_free(uint8_t invokeID);