added clang format C and H files.

This commit is contained in:
Steve Karg
2019-10-24 16:23:10 -05:00
parent da91a11454
commit 710173d6e0
205 changed files with 19377 additions and 25754 deletions
+55 -65
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* Copyright (C) 2009 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.
*
*********************************************************************/
*
* Copyright (C) 2009 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.
*
*********************************************************************/
/* environment variables used for the command line tools */
#include <stddef.h>
@@ -52,7 +52,6 @@ static long bbmd_mask = 0xFFFFFFFF;
static int bbmd_result = 0;
static BBMD_TABLE_ENTRY BBMD_Table_Entry;
/* Simple setters for BBMD registration variables. */
/** Sets the IPv4 address for BBMD registration.
@@ -61,8 +60,7 @@ static BBMD_TABLE_ENTRY BBMD_Table_Entry;
* @param address - IPv4 address (long) of BBMD to register with,
* in network byte order.
*/
void dlenv_bbmd_address_set(
long address)
void dlenv_bbmd_address_set(long address)
{
bbmd_address = address;
}
@@ -71,8 +69,7 @@ void dlenv_bbmd_address_set(
* Default if not set is 0xBAC0.
* @param port - The port number (provided in network byte order).
*/
void dlenv_bbmd_port_set(
int port)
void dlenv_bbmd_port_set(int port)
{
bbmd_port = port;
}
@@ -81,8 +78,7 @@ void dlenv_bbmd_port_set(
* Default if not set is 60000 (1000 minutes).
* @param ttl_secs - The Lease Time, in seconds.
*/
void dlenv_bbmd_ttl_set(
int ttl_secs)
void dlenv_bbmd_ttl_set(int ttl_secs)
{
bbmd_timetolive_seconds = ttl_secs;
}
@@ -95,8 +91,7 @@ void dlenv_bbmd_ttl_set(
* 0 if no registration request was made, or
* -1 if registration attempt failed.
*/
int dlenv_bbmd_result(
void)
int dlenv_bbmd_result(void)
{
if ((bbmd_result > 0) &&
(bvlc_get_last_result() == BVLC_RESULT_REGISTER_FOREIGN_DEVICE_NAK))
@@ -120,8 +115,7 @@ int dlenv_bbmd_result(
* 0 if no registration request is sent, or
* -1 if registration fails.
*/
int dlenv_register_as_foreign_device(
void)
int dlenv_register_as_foreign_device(void)
{
int retval = 0;
#if defined(BACDL_BIP)
@@ -153,17 +147,17 @@ int dlenv_register_as_foreign_device(
struct in_addr addr;
addr.s_addr = bbmd_address;
fprintf(stderr, "Registering with BBMD at %s:%ld for %ld seconds\n",
inet_ntoa(addr), bbmd_port, bbmd_timetolive_seconds);
inet_ntoa(addr), bbmd_port, bbmd_timetolive_seconds);
retval =
bvlc_register_with_bbmd(bbmd_address, htons((uint16_t) bbmd_port),
(uint16_t) bbmd_timetolive_seconds);
bvlc_register_with_bbmd(bbmd_address, htons((uint16_t)bbmd_port),
(uint16_t)bbmd_timetolive_seconds);
if (retval < 0)
fprintf(stderr, "FAILED to Register with BBMD at %s \n",
inet_ntoa(addr));
BBMD_Timer_Seconds = (uint16_t) bbmd_timetolive_seconds;
inet_ntoa(addr));
BBMD_Timer_Seconds = (uint16_t)bbmd_timetolive_seconds;
} else {
for (entry_number = 1; entry_number <= 128; entry_number++) {
sprintf(bbmd_env,"BACNET_BDT_ADDR_%u", entry_number);
sprintf(bbmd_env, "BACNET_BDT_ADDR_%u", entry_number);
pEnv = getenv(bbmd_env);
if (pEnv) {
bbmd_address = bip_getaddrbyname(pEnv);
@@ -173,7 +167,7 @@ int dlenv_register_as_foreign_device(
}
if (bbmd_address) {
bbmd_port = 0xBAC0;
sprintf(bbmd_env,"BACNET_BDT_PORT_%u", entry_number);
sprintf(bbmd_env, "BACNET_BDT_PORT_%u", entry_number);
pEnv = getenv(bbmd_env);
if (pEnv) {
bbmd_port = strtol(pEnv, NULL, 0);
@@ -185,15 +179,15 @@ int dlenv_register_as_foreign_device(
bbmd_port = bip_get_port();
}
bbmd_mask = 0xFFFFFFFF;
sprintf(bbmd_env,"BACNET_BDT_MASK_%u", entry_number);
sprintf(bbmd_env, "BACNET_BDT_MASK_%u", entry_number);
pEnv = getenv(bbmd_env);
if (pEnv) {
c = sscanf(pEnv, "%3u.%3u.%3u.%3u",
&a[0],&a[1],&a[2],&a[3]);
c = sscanf(pEnv, "%3u.%3u.%3u.%3u", &a[0], &a[1], &a[2],
&a[3]);
if (c == 4) {
bbmd_mask =
((a[0]&0xFF)<<24)|((a[1]&0xFF)<<16)|
((a[2]&0xFF)<<8)|(a[3]&0xFF);
bbmd_mask = ((a[0] & 0xFF) << 24) |
((a[1] & 0xFF) << 16) |
((a[2] & 0xFF) << 8) | (a[3] & 0xFF);
}
}
BBMD_Table_Entry.valid = true;
@@ -222,7 +216,7 @@ static void dlenv_network_port_init(void)
uint32_t test_broadcast = 0;
uint32_t mask = 0;
uint16_t port = 0;
uint8_t mac[4+2] = {0};
uint8_t mac[4 + 2] = {0};
uint8_t prefix = 0;
Network_Port_Object_Instance_Number_Set(0, instance);
@@ -331,8 +325,7 @@ static void dlenv_network_port_init(void)
* Call this function to renew our Foreign Device Registration
* @param elapsed_seconds Number of seconds that have elapsed since last called.
*/
void dlenv_maintenance_timer(
uint16_t elapsed_seconds)
void dlenv_maintenance_timer(uint16_t elapsed_seconds)
{
#if defined(BACDL_BIP)
if (BBMD_Timer_Seconds) {
@@ -342,11 +335,11 @@ void dlenv_maintenance_timer(
BBMD_Timer_Seconds -= elapsed_seconds;
}
if (BBMD_Timer_Seconds == 0) {
(void) dlenv_register_as_foreign_device();
(void)dlenv_register_as_foreign_device();
/* If that failed (negative), maybe just a network issue.
* If nothing happened (0), may be un/misconfigured.
* Set up to try again later in all cases. */
BBMD_Timer_Seconds = (uint16_t) bbmd_timetolive_seconds;
BBMD_Timer_Seconds = (uint16_t)bbmd_timetolive_seconds;
}
}
#endif
@@ -402,8 +395,7 @@ void dlenv_maintenance_timer(
* communications. Default is 47808 (0xBAC0).
* - BACNET_BIP6_BROADCAST - FF05::BAC0 or FF02::BAC0 or ...
*/
void dlenv_init(
void)
void dlenv_init(void)
{
char *pEnv = NULL;
@@ -419,19 +411,17 @@ void dlenv_init(
BACNET_IP6_ADDRESS addr;
pEnv = getenv("BACNET_BIP6_BROADCAST");
if (pEnv) {
bvlc6_address_set(&addr,
(uint16_t) strtol(pEnv, NULL, 0), 0, 0, 0, 0, 0, 0,
BIP6_MULTICAST_GROUP_ID);
bvlc6_address_set(&addr, (uint16_t)strtol(pEnv, NULL, 0), 0, 0, 0, 0, 0,
0, BIP6_MULTICAST_GROUP_ID);
bip6_set_broadcast_addr(&addr);
} else {
bvlc6_address_set(&addr,
BIP6_MULTICAST_SITE_LOCAL, 0, 0, 0, 0, 0, 0,
BIP6_MULTICAST_GROUP_ID);
bvlc6_address_set(&addr, BIP6_MULTICAST_SITE_LOCAL, 0, 0, 0, 0, 0, 0,
BIP6_MULTICAST_GROUP_ID);
bip6_set_broadcast_addr(&addr);
}
pEnv = getenv("BACNET_BIP6_PORT");
if (pEnv) {
bip6_set_port((uint16_t) strtol(pEnv, NULL, 0));
bip6_set_port((uint16_t)strtol(pEnv, NULL, 0));
} else {
bip6_set_port(0xBAC0);
}
@@ -442,7 +432,7 @@ void dlenv_init(
#endif
pEnv = getenv("BACNET_IP_PORT");
if (pEnv) {
bip_set_port(htons((uint16_t) strtol(pEnv, NULL, 0)));
bip_set_port(htons((uint16_t)strtol(pEnv, NULL, 0)));
} else {
/* BIP_Port is statically initialized to 0xBAC0,
* so if it is different, then it was programmatically altered,
@@ -489,7 +479,7 @@ void dlenv_init(
#endif
pEnv = getenv("BACNET_APDU_TIMEOUT");
if (pEnv) {
apdu_timeout_set((uint16_t) strtol(pEnv, NULL, 0));
apdu_timeout_set((uint16_t)strtol(pEnv, NULL, 0));
} else {
#if defined(BACDL_MSTP)
apdu_timeout_set(60000);
@@ -497,7 +487,7 @@ void dlenv_init(
}
pEnv = getenv("BACNET_APDU_RETRIES");
if (pEnv) {
apdu_retries_set((uint8_t) strtol(pEnv, NULL, 0));
apdu_retries_set((uint8_t)strtol(pEnv, NULL, 0));
}
/* === Initialize the Datalink Here === */
if (!datalink_init(getenv("BACNET_IFACE"))) {
@@ -506,7 +496,7 @@ void dlenv_init(
#if (MAX_TSM_TRANSACTIONS)
pEnv = getenv("BACNET_INVOKE_ID");
if (pEnv) {
tsm_invokeID_set((uint8_t) strtol(pEnv, NULL, 0));
tsm_invokeID_set((uint8_t)strtol(pEnv, NULL, 0));
}
#endif
dlenv_network_port_init();
+82 -90
View File
@@ -1,28 +1,28 @@
/**************************************************************************
*
* Copyright (C) 2005 Steve Karg <skarg@users.sourceforge.net>
* Copyright (C) 2011 Krzysztof Malorny <malornykrzysztof@gmail.com>
*
* 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.
*
*********************************************************************/
*
* Copyright (C) 2005 Steve Karg <skarg@users.sourceforge.net>
* Copyright (C) 2011 Krzysztof Malorny <malornykrzysztof@gmail.com>
*
* 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 <stdio.h>
@@ -42,14 +42,12 @@
#include "handlers.h"
#include "device.h"
/** @file h_alarm_ack.c Handles Alarm Acknowledgment. */
static alarm_ack_function Alarm_Ack[MAX_BACNET_OBJECT_TYPE];
void handler_alarm_ack_set(
BACNET_OBJECT_TYPE object_type,
alarm_ack_function pFunction)
void handler_alarm_ack_set(BACNET_OBJECT_TYPE object_type,
alarm_ack_function pFunction)
{
if (object_type < MAX_BACNET_OBJECT_TYPE) {
Alarm_Ack[object_type] = pFunction;
@@ -72,11 +70,9 @@ void handler_alarm_ack_set(
* @param service_data [in] The BACNET_CONFIRMED_SERVICE_DATA information
* decoded from the APDU header of this message.
*/
void handler_alarm_ack(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src,
BACNET_CONFIRMED_SERVICE_DATA * service_data)
void handler_alarm_ack(uint8_t* service_request, uint16_t service_len,
BACNET_ADDRESS* src,
BACNET_CONFIRMED_SERVICE_DATA* service_data)
{
int len = 0;
int pdu_len = 0;
@@ -90,32 +86,29 @@ void handler_alarm_ack(
/* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
if (service_data->segmented_message) {
/* we don't support segmentation - send an abort */
len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
true);
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
#if PRINT_ENABLED
fprintf(stderr, "Alarm Ack: Segmented message. Sending Abort!\n");
#endif
goto AA_ABORT;
}
len =
alarm_ack_decode_service_request(service_request, service_len, &data);
len = alarm_ack_decode_service_request(service_request, service_len, &data);
#if PRINT_ENABLED
if (len <= 0)
fprintf(stderr, "Alarm Ack: Unable to decode Request!\n");
#endif
if (len < 0) {
/* bad decoding - send an abort */
len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_OTHER, true);
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_OTHER,
true);
#if PRINT_ENABLED
fprintf(stderr, "Alarm Ack: Bad Encoding. Sending Abort!\n");
#endif
@@ -123,82 +116,81 @@ void handler_alarm_ack(
}
#if PRINT_ENABLED
fprintf(stderr,
"Alarm Ack Operation: Received acknowledge for object id (%d, %lu) from %s for process id %lu \n",
data.eventObjectIdentifier.type,
(unsigned long) data.eventObjectIdentifier.instance,
data.ackSource.value, (unsigned long) data.ackProcessIdentifier);
"Alarm Ack Operation: Received acknowledge for object id (%d, %lu) "
"from %s for process id %lu \n",
data.eventObjectIdentifier.type,
(unsigned long)data.eventObjectIdentifier.instance,
data.ackSource.value, (unsigned long)data.ackProcessIdentifier);
#endif
/* BACnet Testing Observed Incident oi00105
ACK of a non-existent object returned the incorrect error code
Revealed by BACnet Test Client v1.8.16 ( www.bac-test.com/bacnet-test-client-download )
BC 135.1: 9.1.3.3-A
Any discussions can be directed to edward@bac-test.com */
if (!Device_Valid_Object_Id(data.eventObjectIdentifier.type, data.eventObjectIdentifier.instance))
{
len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM, ERROR_CLASS_OBJECT, ERROR_CODE_UNKNOWN_OBJECT);
}
else if (Alarm_Ack[data.eventObjectIdentifier.type]) {
/* BACnet Testing Observed Incident oi00105
ACK of a non-existent object returned the incorrect error code
Revealed by BACnet Test Client v1.8.16 (
www.bac-test.com/bacnet-test-client-download ) BC 135.1: 9.1.3.3-A Any
discussions can be directed to edward@bac-test.com */
if (!Device_Valid_Object_Id(data.eventObjectIdentifier.type,
data.eventObjectIdentifier.instance)) {
len = bacerror_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM, ERROR_CLASS_OBJECT,
ERROR_CODE_UNKNOWN_OBJECT);
} else if (Alarm_Ack[data.eventObjectIdentifier.type]) {
ack_result =
Alarm_Ack[data.eventObjectIdentifier.type] (&data, &error_code);
Alarm_Ack[data.eventObjectIdentifier.type](&data, &error_code);
switch (ack_result) {
case 1:
len =
encode_simple_ack(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM);
len = encode_simple_ack(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM);
#if PRINT_ENABLED
fprintf(stderr, "Alarm Acknowledge: " "Sending Simple Ack!\n");
fprintf(stderr,
"Alarm Acknowledge: "
"Sending Simple Ack!\n");
#endif
break;
case -1:
len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM, ERROR_CLASS_OBJECT,
error_code);
len = bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM,
ERROR_CLASS_OBJECT, error_code);
#if PRINT_ENABLED
fprintf(stderr, "Alarm Acknowledge: error %s!\n",
bactext_error_code_name(error_code));
bactext_error_code_name(error_code));
#endif
break;
default:
len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_OTHER, true);
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
ABORT_REASON_OTHER, true);
#if PRINT_ENABLED
fprintf(stderr, "Alarm Acknowledge: abort other!\n");
#endif
break;
}
} else {
len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM,
ERROR_CLASS_OBJECT, ERROR_CODE_NO_ALARM_CONFIGURED);
len = bacerror_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM, ERROR_CLASS_OBJECT,
ERROR_CODE_NO_ALARM_CONFIGURED);
#if PRINT_ENABLED
fprintf(stderr, "Alarm Acknowledge: error %s!\n",
bactext_error_code_name(ERROR_CODE_NO_ALARM_CONFIGURED));
bactext_error_code_name(ERROR_CODE_NO_ALARM_CONFIGURED));
#endif
}
AA_ABORT:
AA_ABORT:
pdu_len += len;
bytes_sent =
datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
bytes_sent = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0)
fprintf(stderr, "Alarm Acknowledge: " "Failed to send PDU (%s)!\n",
strerror(errno));
fprintf(stderr,
"Alarm Acknowledge: "
"Failed to send PDU (%s)!\n",
strerror(errno));
#endif
return;
+53 -62
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* Copyright (C) 2005 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.
*
*********************************************************************/
*
* Copyright (C) 2005 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 <stdio.h>
@@ -96,11 +96,9 @@ shall be TRUE, otherwise FALSE.
*/
#if defined(BACFILE)
void handler_atomic_read_file(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src,
BACNET_CONFIRMED_SERVICE_DATA * service_data)
void handler_atomic_read_file(uint8_t* service_request, uint16_t service_len,
BACNET_ADDRESS* src,
BACNET_CONFIRMED_SERVICE_DATA* service_data)
{
BACNET_ATOMIC_READ_FILE_DATA data;
int len = 0;
@@ -118,14 +116,12 @@ void handler_atomic_read_file(
/* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
if (service_data->segmented_message) {
len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
true);
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
#if PRINT_ENABLED
fprintf(stderr, "ARF: Segmented Message. Sending Abort!\n");
#endif
@@ -134,9 +130,9 @@ void handler_atomic_read_file(
len = arf_decode_service_request(service_request, service_len, &data);
/* bad decoding - send an abort */
if (len < 0) {
len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_OTHER, true);
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_OTHER,
true);
#if PRINT_ENABLED
fprintf(stderr, "Bad Encoding. Sending Abort!\n");
#endif
@@ -150,22 +146,20 @@ void handler_atomic_read_file(
octetstring_capacity(&data.fileData[0])) {
bacfile_read_stream_data(&data);
#if PRINT_ENABLED
fprintf(stderr, "ARF: Stream offset %d, %d octets.\n",
data.type.stream.fileStartPosition,
data.type.stream.requestedOctetCount);
fprintf(stderr, "ARF: Stream offset %d, %d octets.\n",
data.type.stream.fileStartPosition,
data.type.stream.requestedOctetCount);
#endif
len =
arf_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, &data);
len = arf_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, &data);
} else {
len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
#if PRINT_ENABLED
fprintf(stderr, "Too Big To Send (%d >= %d). Sending Abort!\n",
data.type.stream.requestedOctetCount,
(int)octetstring_capacity(&data.fileData[0]));
data.type.stream.requestedOctetCount,
(int)octetstring_capacity(&data.fileData[0]));
#endif
}
} else if (data.access == FILE_RECORD_ACCESS) {
@@ -177,12 +171,11 @@ void handler_atomic_read_file(
} else if (bacfile_read_stream_data(&data)) {
#if PRINT_ENABLED
fprintf(stderr, "ARF: fileStartRecord %d, %u RecordCount.\n",
data.type.record.fileStartRecord,
data.type.record.RecordCount);
data.type.record.fileStartRecord,
data.type.record.RecordCount);
#endif
len =
arf_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, &data);
len = arf_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, &data);
} else {
error = true;
error_class = ERROR_CLASS_OBJECT;
@@ -202,16 +195,14 @@ void handler_atomic_read_file(
error_code = ERROR_CODE_INCONSISTENT_OBJECT_TYPE;
}
if (error) {
len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, SERVICE_CONFIRMED_ATOMIC_READ_FILE,
error_class, error_code);
len = bacerror_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_ATOMIC_READ_FILE, error_class, error_code);
}
ARF_ABORT:
ARF_ABORT:
pdu_len += len;
bytes_sent =
datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
bytes_sent = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0) {
fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno));
+26 -28
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* Copyright (C) 2005 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.
*
*********************************************************************/
*
* Copyright (C) 2005 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 "config.h"
@@ -51,16 +51,14 @@
/* use the description as the file name. */
#if defined(BACFILE)
void handler_atomic_read_file_ack(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src,
BACNET_CONFIRMED_SERVICE_ACK_DATA * service_data)
uint8_t* service_request, uint16_t service_len, BACNET_ADDRESS* src,
BACNET_CONFIRMED_SERVICE_ACK_DATA* service_data)
{
int len = 0;
BACNET_ATOMIC_READ_FILE_DATA data;
uint32_t instance = 0;
(void) src;
(void)src;
/* get the file instance from the tsm data before freeing it */
instance = bacfile_instance_from_tsm(service_data->invoke_id);
len = arf_ack_decode_service_request(service_request, service_len, &data);
+48 -56
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* Copyright (C) 2007 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.
*
*********************************************************************/
*
* Copyright (C) 2007 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 <stdio.h>
@@ -76,11 +76,9 @@ standard.
*/
#if defined(BACFILE)
void handler_atomic_write_file(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src,
BACNET_CONFIRMED_SERVICE_DATA * service_data)
void handler_atomic_write_file(uint8_t* service_request, uint16_t service_len,
BACNET_ADDRESS* src,
BACNET_CONFIRMED_SERVICE_DATA* service_data)
{
BACNET_ATOMIC_WRITE_FILE_DATA data;
int len = 0;
@@ -98,14 +96,12 @@ void handler_atomic_write_file(
/* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
if (service_data->segmented_message) {
len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
true);
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
#if PRINT_ENABLED
fprintf(stderr, "Segmented Message. Sending Abort!\n");
#endif
@@ -114,9 +110,9 @@ void handler_atomic_write_file(
len = awf_decode_service_request(service_request, service_len, &data);
/* bad decoding - send an abort */
if (len < 0) {
len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_OTHER, true);
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_OTHER,
true);
#if PRINT_ENABLED
fprintf(stderr, "Bad Encoding. Sending Abort!\n");
#endif
@@ -129,12 +125,11 @@ void handler_atomic_write_file(
if (bacfile_write_stream_data(&data)) {
#if PRINT_ENABLED
fprintf(stderr, "AWF: Stream offset %d, %d bytes\n",
data.type.stream.fileStartPosition,
(int)octetstring_length(&data.fileData[0]));
data.type.stream.fileStartPosition,
(int)octetstring_length(&data.fileData[0]));
#endif
len =
awf_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, &data);
len = awf_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, &data);
} else {
error = true;
error_class = ERROR_CLASS_OBJECT;
@@ -144,12 +139,11 @@ void handler_atomic_write_file(
if (bacfile_write_record_data(&data)) {
#if PRINT_ENABLED
fprintf(stderr, "AWF: StartRecord %d, RecordCount %u\n",
data.type.record.fileStartRecord,
data.type.record.returnedRecordCount);
data.type.record.fileStartRecord,
data.type.record.returnedRecordCount);
#endif
len =
awf_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, &data);
len = awf_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, &data);
} else {
error = true;
error_class = ERROR_CLASS_OBJECT;
@@ -169,16 +163,14 @@ void handler_atomic_write_file(
error_code = ERROR_CODE_INCONSISTENT_OBJECT_TYPE;
}
if (error) {
len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, SERVICE_CONFIRMED_ATOMIC_WRITE_FILE,
error_class, error_code);
len = bacerror_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_ATOMIC_WRITE_FILE, error_class, error_code);
}
AWF_ABORT:
AWF_ABORT:
pdu_len += len;
bytes_sent =
datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
bytes_sent = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0) {
fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno));
+125 -199
View File
@@ -32,10 +32,10 @@
-------------------------------------------
####COPYRIGHTEND####*/
#include <stdio.h> /* for standard i/o, like printing */
#include <stdint.h> /* for standard integer types uint8_t etc. */
#include <stdbool.h> /* for the standard bool type. */
#include <string.h> /* for memcpy */
#include <stdio.h> /* for standard i/o, like printing */
#include <stdint.h> /* for standard integer types uint8_t etc. */
#include <stdbool.h> /* for the standard bool type. */
#include <string.h> /* for memcpy */
#include "bacdcode.h"
#include "bip6.h"
#include "bvlc6.h"
@@ -61,7 +61,8 @@ static uint16_t BVLC6_Buffer_Len;
#ifndef MAX_BBMD6_ENTRIES
#define MAX_BBMD6_ENTRIES 128
#endif
static BACNET_IP6_BROADCAST_DISTRIBUTION_TABLE_ENTRY BBMD_Table[MAX_BBMD6_ENTRIES];
static BACNET_IP6_BROADCAST_DISTRIBUTION_TABLE_ENTRY
BBMD_Table[MAX_BBMD6_ENTRIES];
/* Foreign Device Table */
#ifndef MAX_FD6_ENTRIES
#define MAX_FD6_ENTRIES 128
@@ -74,8 +75,7 @@ static BACNET_IP6_FOREIGN_DEVICE_TABLE_ENTRY FD_Table[MAX_FD6_ENTRIES];
*
* @param seconds - number of elapsed seconds since the last call
*/
void bbmd6_maintenance_timer(
time_t seconds)
void bbmd6_maintenance_timer(time_t seconds)
{
unsigned i = 0;
@@ -104,9 +104,8 @@ void bbmd6_maintenance_timer(
*
* @return true if the address was set
*/
static bool bbmd6_address_from_vmac(
BACNET_IP6_ADDRESS *addr,
struct vmac_data *vmac)
static bool bbmd6_address_from_vmac(BACNET_IP6_ADDRESS *addr,
struct vmac_data *vmac)
{
bool status = false;
unsigned int i = 0;
@@ -130,9 +129,8 @@ static bool bbmd6_address_from_vmac(
*
* @return true if the address was set
*/
static bool bbmd6_address_to_vmac(
struct vmac_data *vmac,
BACNET_IP6_ADDRESS *addr)
static bool bbmd6_address_to_vmac(struct vmac_data *vmac,
BACNET_IP6_ADDRESS *addr)
{
bool status = false;
unsigned int i = 0;
@@ -157,9 +155,7 @@ static bool bbmd6_address_to_vmac(
*
* @return true if the VMAC address was added
*/
static bool bbmd6_add_vmac(
uint32_t device_id,
BACNET_IP6_ADDRESS *addr)
static bool bbmd6_add_vmac(uint32_t device_id, BACNET_IP6_ADDRESS *addr)
{
bool status = false;
struct vmac_data *vmac;
@@ -186,8 +182,7 @@ static bool bbmd6_add_vmac(
*
* @return true if the IPv6 from sin match me
*/
static bool bbmd6_address_match_self(
BACNET_IP6_ADDRESS *addr)
static bool bbmd6_address_match_self(BACNET_IP6_ADDRESS *addr)
{
BACNET_IP6_ADDRESS my_addr = {{0}};
bool status = false;
@@ -211,10 +206,9 @@ static bool bbmd6_address_match_self(
*
* @return true if the address was in the VMAC table
*/
static bool bbmd6_address_from_bacnet_address(
BACNET_IP6_ADDRESS * addr,
uint32_t * vmac_src,
BACNET_ADDRESS * baddr)
static bool bbmd6_address_from_bacnet_address(BACNET_IP6_ADDRESS *addr,
uint32_t *vmac_src,
BACNET_ADDRESS *baddr)
{
struct vmac_data *vmac;
bool status = false;
@@ -226,8 +220,7 @@ static bool bbmd6_address_from_bacnet_address(
vmac = VMAC_Find_By_Key(device_id);
if (vmac) {
debug_printf("BVLC6: Found VMAC %lu (len=%u).\n",
(unsigned long)device_id,
(unsigned)vmac->mac_len);
(unsigned long)device_id, (unsigned)vmac->mac_len);
status = bbmd6_address_from_vmac(addr, vmac);
if (vmac_src) {
*vmac_src = device_id;
@@ -239,8 +232,6 @@ static bool bbmd6_address_from_bacnet_address(
return status;
}
/**
* The common send function for BACnet/IPv6 application layer
*
@@ -253,20 +244,17 @@ static bool bbmd6_address_from_bacnet_address(
* @return Upon successful completion, returns the number of bytes sent.
* Otherwise, -1 shall be returned and errno set to indicate the error.
*/
int bip6_send_pdu(
BACNET_ADDRESS * dest,
BACNET_NPDU_DATA * npdu_data,
uint8_t * pdu,
unsigned pdu_len)
int bip6_send_pdu(BACNET_ADDRESS *dest, BACNET_NPDU_DATA *npdu_data,
uint8_t *pdu, unsigned pdu_len)
{
BACNET_IP6_ADDRESS bvlc_dest = {{0}};
uint8_t mtu[MAX_MPDU] = { 0 };
uint8_t mtu[MAX_MPDU] = {0};
uint16_t mtu_len = 0;
uint32_t vmac_src = 0;
uint32_t vmac_dst = 0;
/* this datalink doesn't need to know the npdu data */
(void) npdu_data;
(void)npdu_data;
/* handle various broadcasts: */
if ((dest->net == BACNET_BROADCAST_NETWORK) || (dest->mac_len == 0)) {
/* mac_len = 0 is a broadcast address */
@@ -281,8 +269,8 @@ int bip6_send_pdu(
} else {
bip6_get_broadcast_addr(&bvlc_dest);
vmac_src = Device_Object_Instance_Number();
mtu_len = bvlc6_encode_original_broadcast(
mtu, sizeof(mtu), vmac_src, pdu, pdu_len);
mtu_len = bvlc6_encode_original_broadcast(mtu, sizeof(mtu),
vmac_src, pdu, pdu_len);
debug_printf("BVLC6: Sent Original-Broadcast-NPDU.\n");
}
} else if ((dest->net > 0) && (dest->len == 0)) {
@@ -294,16 +282,16 @@ int bip6_send_pdu(
bip6_get_broadcast_addr(&bvlc_dest);
}
vmac_src = Device_Object_Instance_Number();
mtu_len = bvlc6_encode_original_broadcast(
mtu, sizeof(mtu), vmac_src, pdu, pdu_len);
mtu_len = bvlc6_encode_original_broadcast(mtu, sizeof(mtu), vmac_src,
pdu, pdu_len);
debug_printf("BVLC6: Sent Original-Broadcast-NPDU.\n");
} else if (dest->mac_len == 3) {
/* valid unicast */
bbmd6_address_from_bacnet_address(&bvlc_dest, &vmac_dst, dest);
debug_printf("BVLC6: Sending to VMAC %lu.\n", (unsigned long)vmac_dst);
vmac_src = Device_Object_Instance_Number();
mtu_len = bvlc6_encode_original_unicast(
mtu, sizeof(mtu), vmac_src, vmac_dst, pdu, pdu_len);
mtu_len = bvlc6_encode_original_unicast(mtu, sizeof(mtu), vmac_src,
vmac_dst, pdu, pdu_len);
debug_printf("BVLC6: Sent Original-Unicast-NPDU.\n");
} else {
debug_printf("BVLC6: Send failure. Invalid Address.\n");
@@ -323,19 +311,17 @@ int bip6_send_pdu(
* @param npdu - the bytes of NPDU+APDU data to send
* @param npdu_len - the number of bytes of NPDU+APDU data to send
*/
static void bbmd6_send_pdu_bdt(
uint8_t * mtu,
unsigned int mtu_len)
static void bbmd6_send_pdu_bdt(uint8_t *mtu, unsigned int mtu_len)
{
BACNET_IP6_ADDRESS my_addr = {{0}};
unsigned i = 0; /* loop counter */
unsigned i = 0; /* loop counter */
if (mtu) {
bip6_get_addr(&my_addr);
for (i = 0; i < MAX_BBMD_ENTRIES; i++) {
if (BBMD_Table[i].valid) {
if (bvlc6_address_different(&my_addr,
&BBMD_Table[i].bip6_address)) {
&BBMD_Table[i].bip6_address)) {
bip6_send_mpdu(&BBMD_Table[i].bip6_address, mtu, mtu_len);
}
}
@@ -352,19 +338,17 @@ static void bbmd6_send_pdu_bdt(
* @param npdu - the bytes of NPDU+APDU data to send
* @param npdu_len - the number of bytes of NPDU+APDU data to send
*/
static void bbmd6_send_pdu_fdt(
uint8_t * mtu,
unsigned int mtu_len)
static void bbmd6_send_pdu_fdt(uint8_t *mtu, unsigned int mtu_len)
{
BACNET_IP6_ADDRESS my_addr = {{0}};
unsigned i = 0; /* loop counter */
unsigned i = 0; /* loop counter */
if (mtu) {
bip6_get_addr(&my_addr);
for (i = 0; i < MAX_FD_ENTRIES; i++) {
if (FD_Table[i].valid) {
if (bvlc6_address_different(&my_addr,
&FD_Table[i].bip6_address)) {
&FD_Table[i].bip6_address)) {
bip6_send_mpdu(&FD_Table[i].bip6_address, mtu, mtu_len);
}
}
@@ -381,15 +365,13 @@ static void bbmd6_send_pdu_fdt(
* @param npdu - the bytes of NPDU+APDU data to send
* @param npdu_len - the number of bytes of NPDU+APDU data to send
*/
static void bbmd6_send_forward_npdu(
BACNET_IP6_ADDRESS *address,
uint32_t vmac_src,
uint8_t * npdu,
unsigned int npdu_len)
static void bbmd6_send_forward_npdu(BACNET_IP6_ADDRESS *address,
uint32_t vmac_src, uint8_t *npdu,
unsigned int npdu_len)
{
uint8_t mtu[MAX_MPDU] = { 0 };
uint8_t mtu[MAX_MPDU] = {0};
uint16_t mtu_len = 0;
unsigned i = 0; /* loop counter */
unsigned i = 0; /* loop counter */
for (i = 0; i < MAX_BBMD_ENTRIES; i++) {
if (BBMD_Table[i].valid) {
@@ -424,12 +406,10 @@ static void bbmd6_send_forward_npdu(
* @return Upon successful completion, returns the number of bytes sent.
* Otherwise, -1 shall be returned and errno set to indicate the error.
*/
static int bvlc6_send_result(
BACNET_IP6_ADDRESS *dest_addr,
uint32_t vmac_src,
uint16_t result_code)
static int bvlc6_send_result(BACNET_IP6_ADDRESS *dest_addr, uint32_t vmac_src,
uint16_t result_code)
{
uint8_t mtu[MAX_MPDU] = { 0 };
uint8_t mtu[MAX_MPDU] = {0};
uint16_t mtu_len = 0;
mtu_len = bvlc6_encode_result(&mtu[0], sizeof(mtu), vmac_src, result_code);
@@ -448,17 +428,15 @@ static int bvlc6_send_result(
* @return Upon successful completion, returns the number of bytes sent.
* Otherwise, -1 shall be returned and errno set to indicate the error.
*/
static int bvlc6_send_address_resolution_ack(
BACNET_IP6_ADDRESS *dest_addr,
uint32_t vmac_src,
uint32_t vmac_dst)
static int bvlc6_send_address_resolution_ack(BACNET_IP6_ADDRESS *dest_addr,
uint32_t vmac_src,
uint32_t vmac_dst)
{
uint8_t mtu[MAX_MPDU] = { 0 };
uint8_t mtu[MAX_MPDU] = {0};
uint16_t mtu_len = 0;
mtu_len = bvlc6_encode_address_resolution_ack(
&mtu[0], sizeof(mtu),
vmac_src, vmac_dst);
mtu_len = bvlc6_encode_address_resolution_ack(&mtu[0], sizeof(mtu),
vmac_src, vmac_dst);
return bip6_send_mpdu(dest_addr, mtu, mtu_len);
}
@@ -476,16 +454,13 @@ static int bvlc6_send_address_resolution_ack(
* Otherwise, -1 shall be returned and errno set to indicate the error.
*/
static int bvlc6_send_virtual_address_resolution_ack(
BACNET_IP6_ADDRESS *dest_addr,
uint32_t vmac_src,
uint32_t vmac_dst)
BACNET_IP6_ADDRESS *dest_addr, uint32_t vmac_src, uint32_t vmac_dst)
{
uint8_t mtu[MAX_MPDU] = { 0 };
uint8_t mtu[MAX_MPDU] = {0};
uint16_t mtu_len = 0;
mtu_len = bvlc6_encode_virtual_address_resolution_ack(
&mtu[0], sizeof(mtu),
vmac_src, vmac_dst);
mtu_len = bvlc6_encode_virtual_address_resolution_ack(&mtu[0], sizeof(mtu),
vmac_src, vmac_dst);
return bip6_send_mpdu(dest_addr, mtu, mtu_len);
}
@@ -497,10 +472,9 @@ static int bvlc6_send_virtual_address_resolution_ack(
* @param pdu - The received NPDU+APDU buffer.
* @param pdu_len - How many bytes in NPDU+APDU buffer.
*/
static void bbmd6_virtual_address_resolution_handler(
BACNET_IP6_ADDRESS *addr,
uint8_t * pdu,
uint16_t pdu_len)
static void bbmd6_virtual_address_resolution_handler(BACNET_IP6_ADDRESS *addr,
uint8_t *pdu,
uint16_t pdu_len)
{
int function_len = 0;
uint32_t vmac_src = 0;
@@ -511,17 +485,16 @@ static void bbmd6_virtual_address_resolution_handler(
if (bbmd6_address_match_self(addr)) {
/* ignore messages from my IPv6 address */
} else {
function_len = bvlc6_decode_virtual_address_resolution(
pdu, pdu_len,
&vmac_src);
function_len = bvlc6_decode_virtual_address_resolution(pdu, pdu_len,
&vmac_src);
if (function_len) {
bbmd6_add_vmac(vmac_src, addr);
/* The Address-Resolution-ACK message is unicast
to the B/IPv6 node that originally initiated
the Address-Resolution message. */
vmac_me = Device_Object_Instance_Number();
bvlc6_send_virtual_address_resolution_ack(
addr, vmac_me, vmac_src);
bvlc6_send_virtual_address_resolution_ack(addr, vmac_me,
vmac_src);
}
}
}
@@ -535,9 +508,7 @@ static void bbmd6_virtual_address_resolution_handler(
* @param pdu_len - How many bytes in NPDU+APDU buffer.
*/
static void bbmd6_virtual_address_resolution_ack_handler(
BACNET_IP6_ADDRESS *addr,
uint8_t * pdu,
uint16_t pdu_len)
BACNET_IP6_ADDRESS *addr, uint8_t *pdu, uint16_t pdu_len)
{
int function_len = 0;
uint32_t vmac_src = 0;
@@ -549,8 +520,7 @@ static void bbmd6_virtual_address_resolution_ack_handler(
/* ignore messages from my IPv6 address */
} else {
function_len = bvlc6_decode_virtual_address_resolution_ack(
pdu, pdu_len,
&vmac_src, &vmac_dst);
pdu, pdu_len, &vmac_src, &vmac_dst);
if (function_len) {
bbmd6_add_vmac(vmac_src, addr);
}
@@ -565,10 +535,8 @@ static void bbmd6_virtual_address_resolution_ack_handler(
* @param pdu - The received NPDU+APDU buffer.
* @param pdu_len - How many bytes in NPDU+APDU buffer.
*/
static void bbmd6_address_resolution_handler(
BACNET_IP6_ADDRESS *addr,
uint8_t * pdu,
uint16_t pdu_len)
static void bbmd6_address_resolution_handler(BACNET_IP6_ADDRESS *addr,
uint8_t *pdu, uint16_t pdu_len)
{
int function_len = 0;
uint32_t vmac_src = 0;
@@ -581,8 +549,7 @@ static void bbmd6_address_resolution_handler(
/* ignore messages from my IPv6 address */
} else {
function_len = bvlc6_decode_address_resolution(
pdu, pdu_len,
&vmac_src, &vmac_target);
pdu, pdu_len, &vmac_src, &vmac_target);
if (function_len) {
bbmd6_add_vmac(vmac_src, addr);
vmac_me = Device_Object_Instance_Number();
@@ -590,8 +557,7 @@ static void bbmd6_address_resolution_handler(
/* The Address-Resolution-ACK message is unicast
to the B/IPv6 node that originally initiated
the Address-Resolution message. */
bvlc6_send_address_resolution_ack(
addr, vmac_me, vmac_src);
bvlc6_send_address_resolution_ack(addr, vmac_me, vmac_src);
}
}
}
@@ -605,10 +571,8 @@ static void bbmd6_address_resolution_handler(
* @param pdu - The received NPDU+APDU buffer.
* @param pdu_len - How many bytes in NPDU+APDU buffer.
*/
static void bbmd6_address_resolution_ack_handler(
BACNET_IP6_ADDRESS *addr,
uint8_t * pdu,
uint16_t pdu_len)
static void bbmd6_address_resolution_ack_handler(BACNET_IP6_ADDRESS *addr,
uint8_t *pdu, uint16_t pdu_len)
{
int function_len = 0;
uint32_t vmac_src = 0;
@@ -620,8 +584,7 @@ static void bbmd6_address_resolution_ack_handler(
/* ignore messages from my IPv6 address */
} else {
function_len = bvlc6_decode_address_resolution_ack(
pdu, pdu_len,
&vmac_src, &vmac_dst);
pdu, pdu_len, &vmac_src, &vmac_dst);
if (function_len) {
bbmd6_add_vmac(vmac_src, addr);
}
@@ -640,11 +603,9 @@ static void bbmd6_address_resolution_ack_handler(
*
* @return number of bytes offset into the NPDU for APDU, or 0 if handled
*/
static int handler_bbmd6_for_non_bbmd(
BACNET_IP6_ADDRESS *addr,
BACNET_ADDRESS * src,
uint8_t * mtu,
uint16_t mtu_len)
static int handler_bbmd6_for_non_bbmd(BACNET_IP6_ADDRESS *addr,
BACNET_ADDRESS *src, uint8_t *mtu,
uint16_t mtu_len)
{
uint16_t result_code = BVLC6_RESULT_SUCCESSFUL_COMPLETION;
uint32_t vmac_src = 0;
@@ -653,23 +614,23 @@ static int handler_bbmd6_for_non_bbmd(
uint16_t message_length = 0;
int header_len = 0;
int function_len = 0;
uint8_t * pdu = NULL;
uint8_t *pdu = NULL;
uint16_t pdu_len = 0;
uint16_t npdu_len = 0;
bool send_result = false;
uint16_t offset = 0;
BACNET_IP6_ADDRESS fwd_address = {{0}};
header_len = bvlc6_decode_header(mtu, mtu_len, &message_type,
&message_length);
header_len =
bvlc6_decode_header(mtu, mtu_len, &message_type, &message_length);
if (header_len == 4) {
BVLC6_Function_Code = message_type;
pdu = &mtu[header_len];
pdu_len = mtu_len - header_len;
switch (BVLC6_Function_Code) {
case BVLC6_RESULT:
function_len = bvlc6_decode_result(pdu, pdu_len, &vmac_src,
&result_code);
function_len =
bvlc6_decode_result(pdu, pdu_len, &vmac_src, &result_code);
if (function_len) {
BVLC6_Result_Code = result_code;
/* The Virtual MAC address table shall be updated
@@ -678,7 +639,7 @@ static int handler_bbmd6_for_non_bbmd(
bbmd6_add_vmac(vmac_src, addr);
bvlc6_vmac_address_set(src, vmac_src);
debug_printf("BIP6: Received Result Code=%d\n",
BVLC6_Result_Code);
BVLC6_Result_Code);
}
break;
case BVLC6_REGISTER_FOREIGN_DEVICE:
@@ -702,9 +663,7 @@ static int handler_bbmd6_for_non_bbmd(
debug_printf("BIP6: Original-Unicast-NPDU is me!.\n");
} else {
function_len = bvlc6_decode_original_unicast(
pdu, pdu_len,
&vmac_src, &vmac_dst,
NULL, 0, &npdu_len);
pdu, pdu_len, &vmac_src, &vmac_dst, NULL, 0, &npdu_len);
if (function_len) {
if (vmac_dst == Device_Object_Instance_Number()) {
/* The Virtual MAC address table shall be updated
@@ -731,9 +690,7 @@ static int handler_bbmd6_for_non_bbmd(
debug_printf("BIP6: Original-Broadcast-NPDU is me!\n");
} else {
function_len = bvlc6_decode_original_broadcast(
pdu, pdu_len,
&vmac_src,
NULL, 0, &npdu_len);
pdu, pdu_len, &vmac_src, NULL, 0, &npdu_len);
if (function_len) {
/* The Virtual MAC address table shall be updated
using the respective parameter values of the
@@ -743,7 +700,8 @@ static int handler_bbmd6_for_non_bbmd(
offset = header_len + (function_len - npdu_len);
} else {
debug_printf(
"BIP6: Original-Broadcast-NPDU: Unable to decode!\n");
"BIP6: Original-Broadcast-NPDU: Unable to "
"decode!\n");
}
}
break;
@@ -754,9 +712,8 @@ static int handler_bbmd6_for_non_bbmd(
debug_printf("BIP6: Forwarded-NPDU is me!\n");
} else {
function_len = bvlc6_decode_forwarded_npdu(
pdu, pdu_len,
&vmac_src, &fwd_address,
NULL, 0, &npdu_len);
pdu, pdu_len, &vmac_src, &fwd_address, NULL, 0,
&npdu_len);
if (function_len) {
/* The Virtual MAC address table shall be updated
using the respective parameter values of the
@@ -784,7 +741,8 @@ static int handler_bbmd6_for_non_bbmd(
bbmd6_virtual_address_resolution_handler(addr, pdu, pdu_len);
break;
case BVLC6_VIRTUAL_ADDRESS_RESOLUTION_ACK:
bbmd6_virtual_address_resolution_ack_handler(addr, pdu, pdu_len);
bbmd6_virtual_address_resolution_ack_handler(addr, pdu,
pdu_len);
break;
case BVLC6_SECURE_BVLL:
break;
@@ -814,11 +772,8 @@ static int handler_bbmd6_for_non_bbmd(
*
* @return number of bytes offset into the NPDU for APDU, or 0 if handled
*/
static int handler_bbmd6_for_bbmd(
BACNET_IP6_ADDRESS *addr,
BACNET_ADDRESS * src,
uint8_t * mtu,
uint16_t mtu_len)
static int handler_bbmd6_for_bbmd(BACNET_IP6_ADDRESS *addr, BACNET_ADDRESS *src,
uint8_t *mtu, uint16_t mtu_len)
{
uint16_t result_code = BVLC6_RESULT_SUCCESSFUL_COMPLETION;
uint32_t vmac_me = 0;
@@ -829,24 +784,24 @@ static int handler_bbmd6_for_bbmd(
uint16_t message_length = 0;
int header_len = 0;
int function_len = 0;
uint8_t * pdu = NULL;
uint8_t *pdu = NULL;
uint16_t pdu_len = 0;
uint8_t * npdu = NULL;
uint8_t *npdu = NULL;
uint16_t npdu_len = 0;
bool send_result = false;
uint16_t offset = 0;
BACNET_IP6_ADDRESS fwd_address = {{0}};
header_len = bvlc6_decode_header(mtu, mtu_len, &message_type,
&message_length);
header_len =
bvlc6_decode_header(mtu, mtu_len, &message_type, &message_length);
if (header_len == 4) {
BVLC6_Function_Code = message_type;
pdu = &mtu[header_len];
pdu_len = mtu_len - header_len;
switch (BVLC6_Function_Code) {
case BVLC6_RESULT:
function_len = bvlc6_decode_result(pdu, pdu_len, &vmac_src,
&result_code);
function_len =
bvlc6_decode_result(pdu, pdu_len, &vmac_src, &result_code);
if (function_len) {
BVLC6_Result_Code = result_code;
/* The Virtual MAC address table shall be updated
@@ -855,7 +810,7 @@ static int handler_bbmd6_for_bbmd(
bbmd6_add_vmac(vmac_src, addr);
bvlc6_vmac_address_set(src, vmac_src);
debug_printf("BIP6: Received Result Code=%d\n",
BVLC6_Result_Code);
BVLC6_Result_Code);
}
break;
case BVLC6_REGISTER_FOREIGN_DEVICE:
@@ -880,9 +835,7 @@ static int handler_bbmd6_for_bbmd(
offset = 0;
} else {
function_len = bvlc6_decode_original_unicast(
pdu, pdu_len,
&vmac_src, &vmac_dst,
NULL, 0, &npdu_len);
pdu, pdu_len, &vmac_src, &vmac_dst, NULL, 0, &npdu_len);
if (function_len) {
if (vmac_dst == Device_Object_Instance_Number()) {
/* The Virtual MAC address table shall be updated
@@ -898,9 +851,7 @@ static int handler_bbmd6_for_bbmd(
case BVLC6_ORIGINAL_BROADCAST_NPDU:
debug_printf("BIP6: Received Original-Broadcast-NPDU.\n");
function_len = bvlc6_decode_original_broadcast(
pdu, pdu_len,
&vmac_src,
NULL, 0, &npdu_len);
pdu, pdu_len, &vmac_src, NULL, 0, &npdu_len);
if (function_len) {
offset = header_len + (function_len - npdu_len);
npdu = &mtu[offset];
@@ -912,8 +863,7 @@ static int handler_bbmd6_for_bbmd(
be unicast to each foreign device currently in
the BBMD's FDT */
BVLC6_Buffer_Len = bvlc6_encode_forwarded_npdu(
&BVLC6_Buffer[0], sizeof(BVLC6_Buffer),
vmac_src, addr,
&BVLC6_Buffer[0], sizeof(BVLC6_Buffer), vmac_src, addr,
npdu, npdu_len);
bbmd6_send_pdu_bdt(&BVLC6_Buffer[0], BVLC6_Buffer_Len);
bbmd6_send_pdu_fdt(&BVLC6_Buffer[0], BVLC6_Buffer_Len);
@@ -929,9 +879,7 @@ static int handler_bbmd6_for_bbmd(
case BVLC6_FORWARDED_NPDU:
debug_printf("BIP6: Received Forwarded-NPDU.\n");
function_len = bvlc6_decode_forwarded_npdu(
pdu, pdu_len,
&vmac_src, &fwd_address,
NULL, 0, &npdu_len);
pdu, pdu_len, &vmac_src, &fwd_address, NULL, 0, &npdu_len);
if (function_len) {
offset = header_len + (function_len - npdu_len);
npdu = &mtu[offset];
@@ -941,11 +889,11 @@ static int handler_bbmd6_for_bbmd(
transmit it via multicast to B/IPv6 devices in the
local multicast domain. */
BVLC6_Buffer_Len = bvlc6_encode_forwarded_npdu(
&BVLC6_Buffer[0], sizeof(BVLC6_Buffer),
vmac_src, addr,
&BVLC6_Buffer[0], sizeof(BVLC6_Buffer), vmac_src, addr,
npdu, npdu_len);
bip6_get_broadcast_addr(&bvlc_dest);
bip6_send_mpdu(&bvlc_dest, &BVLC6_Buffer[0], BVLC6_Buffer_Len);
bip6_send_mpdu(&bvlc_dest, &BVLC6_Buffer[0],
BVLC6_Buffer_Len);
/* In addition, the constructed BVLL Forwarded-NPDU
message shall be unicast to each foreign device in
the BBMD's FDT. If the BBMD is unable to transmit
@@ -977,7 +925,8 @@ static int handler_bbmd6_for_bbmd(
bbmd6_virtual_address_resolution_handler(addr, pdu, pdu_len);
break;
case BVLC6_VIRTUAL_ADDRESS_RESOLUTION_ACK:
bbmd6_virtual_address_resolution_ack_handler(addr, pdu, pdu_len);
bbmd6_virtual_address_resolution_ack_handler(addr, pdu,
pdu_len);
break;
case BVLC6_SECURE_BVLL:
break;
@@ -1005,11 +954,8 @@ static int handler_bbmd6_for_bbmd(
*
* @return number of bytes offset into the NPDU for APDU, or 0 if handled
*/
int bvlc6_handler(
BACNET_IP6_ADDRESS *addr,
BACNET_ADDRESS * src,
uint8_t * npdu,
uint16_t npdu_len)
int bvlc6_handler(BACNET_IP6_ADDRESS *addr, BACNET_ADDRESS *src, uint8_t *npdu,
uint16_t npdu_len)
{
#if defined(BACDL_BIP6) && BBMD6_ENABLED
return handler_bbmd6_for_bbmd(addr, src, npdu, npdu_len);
@@ -1027,12 +973,10 @@ int bvlc6_handler(
* 0 if no registration request is sent, or
* -1 if registration fails.
*/
int bvlc6_register_with_bbmd(
BACNET_IP6_ADDRESS *bbmd_addr,
uint32_t vmac_src,
uint16_t time_to_live_seconds)
int bvlc6_register_with_bbmd(BACNET_IP6_ADDRESS *bbmd_addr, uint32_t vmac_src,
uint16_t time_to_live_seconds)
{
uint8_t mtu[MAX_MPDU] = { 0 };
uint8_t mtu[MAX_MPDU] = {0};
uint16_t mtu_len = 0;
mtu_len = bvlc6_encode_register_foreign_device(
@@ -1049,8 +993,7 @@ int bvlc6_register_with_bbmd(
* BVLC6_RESULT_REGISTER_FOREIGN_DEVICE_NAK if registration failed,
* or one of the other codes (if we are a BBMD).
*/
uint16_t bvlc6_get_last_result(
void)
uint16_t bvlc6_get_last_result(void)
{
return BVLC6_Result_Code;
}
@@ -1062,8 +1005,7 @@ uint16_t bvlc6_get_last_result(
*
* @return A BVLC6_ code, such as BVLC6_ORIGINAL_UNICAST_NPDU.
*/
uint8_t bvlc6_get_function_code(
void)
uint8_t bvlc6_get_function_code(void)
{
return BVLC6_Function_Code;
}
@@ -1095,11 +1037,8 @@ static uint8_t BIP6_MTU_Buffer[MAX_MPDU];
*
* @return Number of bytes received, or 0 if none or timeout.
*/
uint16_t bip6_receive(
BACNET_ADDRESS * src,
uint8_t * npdu,
uint16_t max_npdu,
unsigned timeout)
uint16_t bip6_receive(BACNET_ADDRESS *src, uint8_t *npdu, uint16_t max_npdu,
unsigned timeout)
{
return 0;
}
@@ -1115,10 +1054,7 @@ uint16_t bip6_receive(
* @return Upon successful completion, returns the number of bytes sent.
* Otherwise, -1 shall be returned and errno set to indicate the error.
*/
int bip6_send_mpdu(
BACNET_IP6_ADDRESS *dest,
uint8_t * mtu,
uint16_t mtu_len)
int bip6_send_mpdu(BACNET_IP6_ADDRESS *dest, uint8_t *mtu, uint16_t mtu_len)
{
return 0;
}
@@ -1129,8 +1065,7 @@ int bip6_send_mpdu(
*
* @return The Instance number used in the BACNET_OBJECT_ID for the Device.
*/
uint32_t Device_Object_Instance_Number(
void)
uint32_t Device_Object_Instance_Number(void)
{
return Device_ID;
}
@@ -1140,8 +1075,7 @@ uint32_t Device_Object_Instance_Number(
*
* @return BACnet/IP address
*/
bool bip6_get_addr(
BACNET_IP6_ADDRESS *addr)
bool bip6_get_addr(BACNET_IP6_ADDRESS *addr)
{
return bvlc6_address_copy(addr, &BIP6_Addr);
}
@@ -1151,14 +1085,12 @@ bool bip6_get_addr(
*
* @return BACnet/IP address
*/
bool bip6_get_broadcast_addr(
BACNET_IP6_ADDRESS *addr)
bool bip6_get_broadcast_addr(BACNET_IP6_ADDRESS *addr)
{
return bvlc6_address_copy(addr, &BIP6_Broadcast_Addr);
}
static void test_BBMD_Result(
Test * pTest)
static void test_BBMD_Result(Test *pTest)
{
int result = 0;
uint32_t vmac_src = 0x1234;
@@ -1168,24 +1100,22 @@ static void test_BBMD_Result(
BVLC6_RESULT_VIRTUAL_ADDRESS_RESOLUTION_NAK,
BVLC6_RESULT_REGISTER_FOREIGN_DEVICE_NAK,
BVLC6_RESULT_DELETE_FOREIGN_DEVICE_NAK,
BVLC6_RESULT_DISTRIBUTE_BROADCAST_TO_NETWORK_NAK
};
BVLC6_RESULT_DISTRIBUTE_BROADCAST_TO_NETWORK_NAK};
uint16_t test_result_code = 0;
uint8_t test_function_code = 0;
BACNET_IP6_ADDRESS addr;
BACNET_ADDRESS src;
unsigned int i = 0;
uint8_t mtu[MAX_MPDU] = { 0 };
uint8_t mtu[MAX_MPDU] = {0};
uint16_t mtu_len = 0;
bvlc6_address_set(&addr,
BIP6_MULTICAST_LINK_LOCAL, 0, 0, 0, 0, 0, 0,
BIP6_MULTICAST_GROUP_ID);
bvlc6_address_set(&addr, BIP6_MULTICAST_LINK_LOCAL, 0, 0, 0, 0, 0, 0,
BIP6_MULTICAST_GROUP_ID);
addr.port = 0xBAC0;
bvlc6_vmac_address_set(&src, vmac_src);
for (i = 0; i < 6; i++) {
mtu_len = bvlc6_encode_result(&mtu[0], sizeof(mtu),
vmac_src, result_code[i]);
mtu_len =
bvlc6_encode_result(&mtu[0], sizeof(mtu), vmac_src, result_code[i]);
result = handler_bbmd6_for_non_bbmd(&addr, &src, &mtu[0], mtu_len);
/* validate that the result is handled (0) */
ct_test(pTest, result == 0);
@@ -1196,8 +1126,7 @@ static void test_BBMD_Result(
}
}
static void test_BBMD6(
Test * pTest)
static void test_BBMD6(Test *pTest)
{
bool rc;
@@ -1207,8 +1136,7 @@ static void test_BBMD6(
}
#ifdef TEST_BBMD6
int main(
void)
int main(void)
{
Test *pTest;
@@ -1217,12 +1145,10 @@ int main(
/* configure output */
ct_setStream(pTest, stdout);
ct_run(pTest);
(void) ct_report(pTest);
(void)ct_report(pTest);
ct_destroy(pTest);
return 0;
}
#endif
#endif
+48 -53
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* Copyright (C) 2011 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.
*
*********************************************************************/
*
* Copyright (C) 2011 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 <stdio.h>
@@ -59,11 +59,9 @@
* @param service_data [in] The BACNET_CONFIRMED_SERVICE_DATA information
* decoded from the APDU header of this message.
*/
void handler_ccov_notification(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src,
BACNET_CONFIRMED_SERVICE_DATA * service_data)
void handler_ccov_notification(uint8_t *service_request, uint16_t service_len,
BACNET_ADDRESS *src,
BACNET_CONFIRMED_SERVICE_DATA *service_data)
{
BACNET_NPDU_DATA npdu_data;
BACNET_COV_DATA cov_data;
@@ -81,31 +79,29 @@ void handler_ccov_notification(
/* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
#if PRINT_ENABLED
fprintf(stderr, "CCOV: Received Notification!\n");
#endif
if (service_data->segmented_message) {
len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
true);
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
#if PRINT_ENABLED
fprintf(stderr, "CCOV: Segmented message. Sending Abort!\n");
#endif
goto CCOV_ABORT;
}
/* decode the service request only */
len =
cov_notify_decode_service_request(service_request, service_len,
&cov_data);
len = cov_notify_decode_service_request(service_request, service_len,
&cov_data);
#if PRINT_ENABLED
if (len > 0) {
fprintf(stderr, "CCOV: PID=%u ", cov_data.subscriberProcessIdentifier);
fprintf(stderr, "instance=%u ", cov_data.initiatingDeviceIdentifier);
fprintf(stderr, "%s %u ",
fprintf(
stderr, "%s %u ",
bactext_object_type_name(cov_data.monitoredObjectIdentifier.type),
cov_data.monitoredObjectIdentifier.instance);
fprintf(stderr, "time remaining=%u seconds ", cov_data.timeRemaining);
@@ -114,12 +110,12 @@ void handler_ccov_notification(
while (pProperty_value) {
fprintf(stderr, "CCOV: ");
if (pProperty_value->propertyIdentifier < 512) {
fprintf(stderr, "%s ",
bactext_property_name
(pProperty_value->propertyIdentifier));
fprintf(
stderr, "%s ",
bactext_property_name(pProperty_value->propertyIdentifier));
} else {
fprintf(stderr, "proprietary %u ",
pProperty_value->propertyIdentifier);
pProperty_value->propertyIdentifier);
}
if (pProperty_value->propertyArrayIndex != BACNET_ARRAY_ALL) {
fprintf(stderr, "%u ", pProperty_value->propertyArrayIndex);
@@ -131,26 +127,25 @@ void handler_ccov_notification(
#endif
/* bad decoding or something we didn't understand - send an abort */
if (len <= 0) {
len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_OTHER, true);
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_OTHER,
true);
#if PRINT_ENABLED
fprintf(stderr, "CCOV: Bad Encoding. Sending Abort!\n");
#endif
goto CCOV_ABORT;
} else {
len =
encode_simple_ack(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, SERVICE_CONFIRMED_COV_NOTIFICATION);
len = encode_simple_ack(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
SERVICE_CONFIRMED_COV_NOTIFICATION);
#if PRINT_ENABLED
fprintf(stderr, "CCOV: Sending Simple Ack!\n");
#endif
}
CCOV_ABORT:
CCOV_ABORT:
pdu_len += len;
bytes_sent =
datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
bytes_sent = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0) {
fprintf(stderr, "CCOV: Failed to send PDU (%s)!\n", strerror(errno));
+148 -183
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* Copyright (C) 2007-2008 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.
*
*********************************************************************/
*
* Copyright (C) 2007-2008 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 <stdio.h>
@@ -54,24 +54,24 @@
/** @file h_cov.c Handles Change of Value (COV) services. */
typedef struct BACnet_COV_Address {
bool valid:1;
bool valid : 1;
BACNET_ADDRESS dest;
} BACNET_COV_ADDRESS;
/* note: This COV service only monitors the properties
of an object that have been specified in the standard. */
typedef struct BACnet_COV_Subscription_Flags {
bool valid:1;
bool issueConfirmedNotifications:1; /* optional */
bool send_requested:1;
bool valid : 1;
bool issueConfirmedNotifications : 1; /* optional */
bool send_requested : 1;
} BACNET_COV_SUBSCRIPTION_FLAGS;
typedef struct BACnet_COV_Subscription {
BACNET_COV_SUBSCRIPTION_FLAGS flag;
uint8_t dest_index;
uint8_t invokeID; /* for confirmed COV */
uint8_t invokeID; /* for confirmed COV */
uint32_t subscriberProcessIdentifier;
uint32_t lifetime; /* optional */
uint32_t lifetime; /* optional */
BACNET_OBJECT_ID monitoredObjectIdentifier;
} BACNET_COV_SUBSCRIPTION;
@@ -85,15 +85,14 @@ static BACNET_COV_SUBSCRIPTION COV_Subscriptions[MAX_COV_SUBCRIPTIONS];
static BACNET_COV_ADDRESS COV_Addresses[MAX_COV_ADDRESSES];
/**
* Gets the address from the list of COV addresses
*
* @param index - offset into COV address list where address is stored
* @param dest - address to be filled when found
*
* @return true if valid address, false if not valid or not found
*/
static BACNET_ADDRESS *cov_address_get(
int index)
* Gets the address from the list of COV addresses
*
* @param index - offset into COV address list where address is stored
* @param dest - address to be filled when found
*
* @return true if valid address, false if not valid or not found
*/
static BACNET_ADDRESS *cov_address_get(int index)
{
BACNET_ADDRESS *cov_dest = NULL;
@@ -110,8 +109,7 @@ static BACNET_ADDRESS *cov_address_get(
* Removes the address from the list of COV addresses, if it is not
* used by other COV subscriptions
*/
static void cov_address_remove_unused(
void)
static void cov_address_remove_unused(void)
{
unsigned index = 0;
unsigned cov_index = 0;
@@ -135,14 +133,13 @@ static void cov_address_remove_unused(
}
/**
* Adds the address to the list of COV addresses
*
* @param dest - address to be added if there is room in the list
*
* @return index number 0..N, or -1 if unable to add
*/
static int cov_address_add(
BACNET_ADDRESS * dest)
* Adds the address to the list of COV addresses
*
* @param dest - address to be added if there is room in the list
*
* @return index number 0..N, or -1 if unable to add
*/
static int cov_address_add(BACNET_ADDRESS *dest)
{
int index = -1;
unsigned i = 0;
@@ -207,17 +204,14 @@ TimeRemaining [3] Unsigned,
COVIncrement [4] REAL OPTIONAL
*/
static int cov_encode_subscription(
uint8_t * apdu,
int max_apdu,
BACNET_COV_SUBSCRIPTION * cov_subscription)
static int cov_encode_subscription(uint8_t *apdu, int max_apdu,
BACNET_COV_SUBSCRIPTION *cov_subscription)
{
int len = 0;
int apdu_len = 0;
BACNET_OCTET_STRING octet_string;
BACNET_ADDRESS *dest = NULL;
/* FIXME: unused parameter */
max_apdu = max_apdu;
if (!cov_subscription) {
@@ -256,9 +250,8 @@ static int cov_encode_subscription(
len = encode_closing_tag(&apdu[apdu_len], 0);
apdu_len += len;
/* processIdentifier [1] Unsigned32 */
len =
encode_context_unsigned(&apdu[apdu_len], 1,
cov_subscription->subscriberProcessIdentifier);
len = encode_context_unsigned(
&apdu[apdu_len], 1, cov_subscription->subscriberProcessIdentifier);
apdu_len += len;
/* Recipient [0] BACnetRecipientProcess - closing */
len = encode_closing_tag(&apdu[apdu_len], 0);
@@ -267,9 +260,8 @@ static int cov_encode_subscription(
len = encode_opening_tag(&apdu[apdu_len], 1);
apdu_len += len;
/* objectIdentifier [0] */
len =
encode_context_object_id(&apdu[apdu_len], 0,
cov_subscription->monitoredObjectIdentifier.type,
len = encode_context_object_id(
&apdu[apdu_len], 0, cov_subscription->monitoredObjectIdentifier.type,
cov_subscription->monitoredObjectIdentifier.instance);
apdu_len += len;
/* propertyIdentifier [1] */
@@ -280,14 +272,12 @@ static int cov_encode_subscription(
len = encode_closing_tag(&apdu[apdu_len], 1);
apdu_len += len;
/* IssueConfirmedNotifications [2] BOOLEAN, */
len =
encode_context_boolean(&apdu[apdu_len], 2,
cov_subscription->flag.issueConfirmedNotifications);
len = encode_context_boolean(
&apdu[apdu_len], 2, cov_subscription->flag.issueConfirmedNotifications);
apdu_len += len;
/* TimeRemaining [3] Unsigned, */
len =
encode_context_unsigned(&apdu[apdu_len], 3,
cov_subscription->lifetime);
encode_context_unsigned(&apdu[apdu_len], 3, cov_subscription->lifetime);
apdu_len += len;
return apdu_len;
@@ -295,18 +285,16 @@ static int cov_encode_subscription(
/** Handle a request to list all the COV subscriptions.
* @ingroup DSCOV
* Invoked by a request to read the Device object's PROP_ACTIVE_COV_SUBSCRIPTIONS.
* Loops through the list of COV Subscriptions, and, for each valid one,
* adds its description to the APDU.
* Invoked by a request to read the Device object's
* PROP_ACTIVE_COV_SUBSCRIPTIONS. Loops through the list of COV Subscriptions,
* and, for each valid one, adds its description to the APDU.
* @note This function needs some work to better handle buffer overruns.
* @param apdu [out] Buffer in which the APDU contents are built.
* @param max_apdu [in] Max length of the APDU buffer.
* @return How many bytes were encoded in the buffer, or -2 if the response
* would not fit within the buffer.
*/
int handler_cov_encode_subscriptions(
uint8_t * apdu,
int max_apdu)
int handler_cov_encode_subscriptions(uint8_t *apdu, int max_apdu)
{
int len = 0;
int apdu_len = 0;
@@ -315,9 +303,9 @@ int handler_cov_encode_subscriptions(
if (apdu) {
for (index = 0; index < MAX_COV_SUBCRIPTIONS; index++) {
if (COV_Subscriptions[index].flag.valid) {
len =
cov_encode_subscription(&apdu[apdu_len],
max_apdu - apdu_len, &COV_Subscriptions[index]);
len = cov_encode_subscription(&apdu[apdu_len],
max_apdu - apdu_len,
&COV_Subscriptions[index]);
apdu_len += len;
/* TODO: too late here to notice that we overran the buffer */
if (apdu_len > max_apdu) {
@@ -333,8 +321,7 @@ int handler_cov_encode_subscriptions(
/** Handler to initialize the COV list, clearing and disabling each entry.
* @ingroup DSCOV
*/
void handler_cov_init(
void)
void handler_cov_init(void)
{
unsigned index = 0;
@@ -355,11 +342,10 @@ void handler_cov_init(
}
}
static bool cov_list_subscribe(
BACNET_ADDRESS * src,
BACNET_SUBSCRIBE_COV_DATA * cov_data,
BACNET_ERROR_CLASS * error_class,
BACNET_ERROR_CODE * error_code)
static bool cov_list_subscribe(BACNET_ADDRESS *src,
BACNET_SUBSCRIBE_COV_DATA *cov_data,
BACNET_ERROR_CLASS *error_class,
BACNET_ERROR_CODE *error_code)
{
bool existing_entry = false;
int index;
@@ -382,11 +368,12 @@ static bool cov_list_subscribe(
address_match = true;
}
if ((COV_Subscriptions[index].monitoredObjectIdentifier.type ==
cov_data->monitoredObjectIdentifier.type) &&
cov_data->monitoredObjectIdentifier.type) &&
(COV_Subscriptions[index].monitoredObjectIdentifier.instance ==
cov_data->monitoredObjectIdentifier.instance) &&
cov_data->monitoredObjectIdentifier.instance) &&
(COV_Subscriptions[index].subscriberProcessIdentifier ==
cov_data->subscriberProcessIdentifier) && address_match) {
cov_data->subscriberProcessIdentifier) &&
address_match) {
existing_entry = true;
if (cov_data->cancellationRequest) {
COV_Subscriptions[index].flag.valid = false;
@@ -447,9 +434,8 @@ static bool cov_list_subscribe(
return found;
}
static bool cov_send_request(
BACNET_COV_SUBSCRIPTION * cov_subscription,
BACNET_PROPERTY_VALUE * value_list)
static bool cov_send_request(BACNET_COV_SUBSCRIPTION *cov_subscription,
BACNET_PROPERTY_VALUE *value_list)
{
int len = 0;
int pdu_len = 0;
@@ -457,7 +443,7 @@ static bool cov_send_request(
BACNET_ADDRESS my_address;
int bytes_sent = 0;
uint8_t invoke_id = 0;
bool status = false; /* return value */
bool status = false; /* return value */
BACNET_COV_DATA cov_data;
BACNET_ADDRESS *dest = NULL;
@@ -479,9 +465,8 @@ static bool cov_send_request(
}
datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], dest, &my_address,
&npdu_data);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], dest, &my_address,
&npdu_data);
/* load the COV data structure for outgoing message */
cov_data.subscriberProcessIdentifier =
cov_subscription->subscriberProcessIdentifier;
@@ -497,25 +482,26 @@ static bool cov_send_request(
invoke_id = tsm_next_free_invokeID();
if (invoke_id) {
cov_subscription->invokeID = invoke_id;
len =
ccov_notify_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
sizeof(Handler_Transmit_Buffer) - pdu_len, invoke_id, &cov_data);
len = ccov_notify_encode_apdu(
&Handler_Transmit_Buffer[pdu_len],
sizeof(Handler_Transmit_Buffer) - pdu_len, invoke_id,
&cov_data);
} else {
goto COV_FAILED;
}
} else {
len =
ucov_notify_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
sizeof(Handler_Transmit_Buffer) - pdu_len, &cov_data);
len = ucov_notify_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
sizeof(Handler_Transmit_Buffer) - pdu_len,
&cov_data);
}
pdu_len += len;
if (cov_subscription->flag.issueConfirmedNotifications) {
tsm_set_confirmed_unsegmented_transaction(invoke_id, dest, &npdu_data,
&Handler_Transmit_Buffer[0], (uint16_t) pdu_len);
&Handler_Transmit_Buffer[0],
(uint16_t)pdu_len);
}
bytes_sent =
datalink_send_pdu(dest, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
bytes_sent = datalink_send_pdu(dest, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len);
if (bytes_sent > 0) {
status = true;
#if PRINT_ENABLED
@@ -523,15 +509,14 @@ static bool cov_send_request(
#endif
}
COV_FAILED:
COV_FAILED:
return status;
}
static void cov_lifetime_expiration_handler(
unsigned index,
uint32_t elapsed_seconds,
uint32_t lifetime_seconds)
static void cov_lifetime_expiration_handler(unsigned index,
uint32_t elapsed_seconds,
uint32_t lifetime_seconds)
{
if (index < MAX_COV_SUBCRIPTIONS) {
/* handle lifetime expiration */
@@ -548,13 +533,14 @@ static void cov_lifetime_expiration_handler(
/* expire the subscription */
#if PRINT_ENABLED
fprintf(stderr, "COVtimer: PID=%u ",
COV_Subscriptions[index].subscriberProcessIdentifier);
fprintf(stderr, "%s %u ",
bactext_object_type_name(COV_Subscriptions[index].
monitoredObjectIdentifier.type),
COV_Subscriptions[index].subscriberProcessIdentifier);
fprintf(
stderr, "%s %u ",
bactext_object_type_name(
COV_Subscriptions[index].monitoredObjectIdentifier.type),
COV_Subscriptions[index].monitoredObjectIdentifier.instance);
fprintf(stderr, "time remaining=%u seconds ",
COV_Subscriptions[index].lifetime);
COV_Subscriptions[index].lifetime);
fprintf(stderr, "\n");
#endif
COV_Subscriptions[index].flag.valid = false;
@@ -591,8 +577,7 @@ static void cov_lifetime_expiration_handler(
*
* @param elapsed_seconds [in] How many seconds have elapsed since last called.
*/
void handler_cov_timer_seconds(
uint32_t elapsed_seconds)
void handler_cov_timer_seconds(uint32_t elapsed_seconds)
{
unsigned index = 0;
uint32_t lifetime_seconds = 0;
@@ -605,15 +590,14 @@ void handler_cov_timer_seconds(
if (lifetime_seconds) {
/* only expire COV with definite lifetimes */
cov_lifetime_expiration_handler(index, elapsed_seconds,
lifetime_seconds);
lifetime_seconds);
}
}
}
}
}
bool handler_cov_fsm(
void)
bool handler_cov_fsm(void)
{
static int index = 0;
BACNET_OBJECT_TYPE object_type = MAX_BACNET_OBJECT_TYPE;
@@ -638,11 +622,10 @@ bool handler_cov_fsm(
case COV_STATE_MARK:
/* mark any subscriptions where the value has changed */
if (COV_Subscriptions[index].flag.valid) {
object_type = (BACNET_OBJECT_TYPE)
COV_Subscriptions[index].monitoredObjectIdentifier.type;
object_type = (BACNET_OBJECT_TYPE)COV_Subscriptions[index]
.monitoredObjectIdentifier.type;
object_instance =
COV_Subscriptions[index].
monitoredObjectIdentifier.instance;
COV_Subscriptions[index].monitoredObjectIdentifier.instance;
status = Device_COV(object_type, object_instance);
if (status) {
COV_Subscriptions[index].flag.send_requested = true;
@@ -661,11 +644,10 @@ bool handler_cov_fsm(
/* clear the COV flag after checking all subscriptions */
if ((COV_Subscriptions[index].flag.valid) &&
(COV_Subscriptions[index].flag.send_requested)) {
object_type = (BACNET_OBJECT_TYPE)
COV_Subscriptions[index].monitoredObjectIdentifier.type;
object_type = (BACNET_OBJECT_TYPE)COV_Subscriptions[index]
.monitoredObjectIdentifier.type;
object_instance =
COV_Subscriptions[index].
monitoredObjectIdentifier.instance;
COV_Subscriptions[index].monitoredObjectIdentifier.instance;
Device_COV_Clear(object_type, object_instance);
}
index++;
@@ -681,9 +663,8 @@ bool handler_cov_fsm(
(COV_Subscriptions[index].invokeID)) {
if (tsm_invoke_id_free(COV_Subscriptions[index].invokeID)) {
COV_Subscriptions[index].invokeID = 0;
} else
if (tsm_invoke_id_failed(COV_Subscriptions
[index].invokeID)) {
} else if (tsm_invoke_id_failed(
COV_Subscriptions[index].invokeID)) {
tsm_free_invoke_id(COV_Subscriptions[index].invokeID);
COV_Subscriptions[index].invokeID = 0;
}
@@ -710,24 +691,21 @@ bool handler_cov_fsm(
}
}
if (send) {
object_type = (BACNET_OBJECT_TYPE)
COV_Subscriptions[index].
monitoredObjectIdentifier.type;
object_instance =
COV_Subscriptions[index].
monitoredObjectIdentifier.instance;
object_type = (BACNET_OBJECT_TYPE)COV_Subscriptions[index]
.monitoredObjectIdentifier.type;
object_instance = COV_Subscriptions[index]
.monitoredObjectIdentifier.instance;
#if PRINT_ENABLED
fprintf(stderr, "COVtask: Sending...\n");
#endif
/* configure the linked list for the two properties */
bacapp_property_value_list_init(&value_list[0],
MAX_COV_PROPERTIES);
status = Device_Encode_Value_List(object_type,
object_instance, &value_list[0]);
MAX_COV_PROPERTIES);
status = Device_Encode_Value_List(
object_type, object_instance, &value_list[0]);
if (status) {
status =
cov_send_request(&COV_Subscriptions[index],
&value_list[0]);
status = cov_send_request(&COV_Subscriptions[index],
&value_list[0]);
}
if (status) {
COV_Subscriptions[index].flag.send_requested = false;
@@ -748,31 +726,27 @@ bool handler_cov_fsm(
return (cov_task_state == COV_STATE_IDLE);
}
void handler_cov_task(
void)
void handler_cov_task(void)
{
handler_cov_fsm();
}
static bool cov_subscribe(
BACNET_ADDRESS * src,
BACNET_SUBSCRIBE_COV_DATA * cov_data,
BACNET_ERROR_CLASS * error_class,
BACNET_ERROR_CODE * error_code)
static bool cov_subscribe(BACNET_ADDRESS *src,
BACNET_SUBSCRIBE_COV_DATA *cov_data,
BACNET_ERROR_CLASS *error_class,
BACNET_ERROR_CODE *error_code)
{
bool status = false; /* return value */
bool status = false; /* return value */
BACNET_OBJECT_TYPE object_type = MAX_BACNET_OBJECT_TYPE;
uint32_t object_instance = 0;
object_type =
(BACNET_OBJECT_TYPE) cov_data->monitoredObjectIdentifier.type;
object_type = (BACNET_OBJECT_TYPE)cov_data->monitoredObjectIdentifier.type;
object_instance = cov_data->monitoredObjectIdentifier.instance;
status = Device_Valid_Object_Id(object_type, object_instance);
if (status) {
status = Device_Value_List_Supported(object_type);
if (status) {
status =
cov_list_subscribe(src, cov_data, error_class, error_code);
status = cov_list_subscribe(src, cov_data, error_class, error_code);
} else {
*error_class = ERROR_CLASS_OBJECT;
*error_code = ERROR_CODE_OPTIONAL_FUNCTIONALITY_NOT_SUPPORTED;
@@ -802,11 +776,9 @@ static bool cov_subscribe(
* @param service_data [in] The BACNET_CONFIRMED_SERVICE_DATA information
* decoded from the APDU header of this message.
*/
void handler_cov_subscribe(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src,
BACNET_CONFIRMED_SERVICE_DATA * service_data)
void handler_cov_subscribe(uint8_t *service_request, uint16_t service_len,
BACNET_ADDRESS *src,
BACNET_CONFIRMED_SERVICE_DATA *service_data)
{
BACNET_SUBSCRIBE_COV_DATA cov_data;
int len = 0;
@@ -824,9 +796,8 @@ void handler_cov_subscribe(
/* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
npdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
npdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
if (service_data->segmented_message) {
/* we don't support segmentation - send an abort */
len = BACNET_STATUS_ABORT;
@@ -836,9 +807,8 @@ void handler_cov_subscribe(
error = true;
goto COV_ABORT;
}
len =
cov_subscribe_decode_service_request(service_request, service_len,
&cov_data);
len = cov_subscribe_decode_service_request(service_request, service_len,
&cov_data);
#if PRINT_ENABLED
if (len <= 0)
fprintf(stderr, "SubscribeCOV: Unable to decode Request!\n");
@@ -849,13 +819,12 @@ void handler_cov_subscribe(
}
cov_data.error_class = ERROR_CLASS_OBJECT;
cov_data.error_code = ERROR_CODE_UNKNOWN_OBJECT;
success =
cov_subscribe(src, &cov_data, &cov_data.error_class,
&cov_data.error_code);
success = cov_subscribe(src, &cov_data, &cov_data.error_class,
&cov_data.error_code);
if (success) {
apdu_len =
encode_simple_ack(&Handler_Transmit_Buffer[npdu_len],
service_data->invoke_id, SERVICE_CONFIRMED_SUBSCRIBE_COV);
apdu_len = encode_simple_ack(&Handler_Transmit_Buffer[npdu_len],
service_data->invoke_id,
SERVICE_CONFIRMED_SUBSCRIBE_COV);
#if PRINT_ENABLED
fprintf(stderr, "SubscribeCOV: Sending Simple Ack!\n");
#endif
@@ -866,28 +835,26 @@ void handler_cov_subscribe(
fprintf(stderr, "SubscribeCOV: Sending Error!\n");
#endif
}
COV_ABORT:
COV_ABORT:
if (error) {
if (len == BACNET_STATUS_ABORT) {
apdu_len =
abort_encode_apdu(&Handler_Transmit_Buffer[npdu_len],
service_data->invoke_id,
apdu_len = abort_encode_apdu(
&Handler_Transmit_Buffer[npdu_len], service_data->invoke_id,
abort_convert_error_code(cov_data.error_code), true);
#if PRINT_ENABLED
fprintf(stderr, "SubscribeCOV: Sending Abort!\n");
#endif
} else if (len == BACNET_STATUS_ERROR) {
apdu_len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[npdu_len],
service_data->invoke_id, SERVICE_CONFIRMED_SUBSCRIBE_COV,
cov_data.error_class, cov_data.error_code);
apdu_len = bacerror_encode_apdu(
&Handler_Transmit_Buffer[npdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_SUBSCRIBE_COV, cov_data.error_class,
cov_data.error_code);
#if PRINT_ENABLED
fprintf(stderr, "SubscribeCOV: Sending Error!\n");
#endif
} else if (len == BACNET_STATUS_REJECT) {
apdu_len =
reject_encode_apdu(&Handler_Transmit_Buffer[npdu_len],
service_data->invoke_id,
apdu_len = reject_encode_apdu(
&Handler_Transmit_Buffer[npdu_len], service_data->invoke_id,
reject_convert_error_code(cov_data.error_code));
#if PRINT_ENABLED
fprintf(stderr, "SubscribeCOV: Sending Reject!\n");
@@ -895,16 +862,14 @@ void handler_cov_subscribe(
}
}
pdu_len = npdu_len + apdu_len;
bytes_sent =
datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
bytes_sent = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
if (bytes_sent <= 0) {
#if PRINT_ENABLED
fprintf(stderr, "SubscribeCOV: Failed to send PDU (%s)!\n",
strerror(errno));
strerror(errno));
#endif
}
return;
}
+66 -73
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* 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.
*
*********************************************************************/
*
* 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 <stdio.h>
@@ -47,10 +47,9 @@ static char My_Password[32] = "filister";
/** Sets (non-volatile hold) the password to be used for DCC requests.
* @param new_password [in] The new DCC password, of up to 31 characters.
*/
void handler_dcc_password_set(
char *new_password)
void handler_dcc_password_set(char *new_password)
{
size_t i = 0; /* loop counter */
size_t i = 0; /* loop counter */
if (new_password) {
for (i = 0; i < (sizeof(My_Password) - 1); i++) {
@@ -95,10 +94,8 @@ char *handler_dcc_password(void)
* decoded from the APDU header of this message.
*/
void handler_device_communication_control(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src,
BACNET_CONFIRMED_SERVICE_DATA * service_data)
uint8_t *service_request, uint16_t service_len, BACNET_ADDRESS *src,
BACNET_CONFIRMED_SERVICE_DATA *service_data)
{
uint16_t timeDuration = 0;
BACNET_COMMUNICATION_ENABLE_DISABLE state = COMMUNICATION_ENABLE;
@@ -111,100 +108,96 @@ void handler_device_communication_control(
/* encode the NPDU portion of the reply packet */
datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
#if PRINT_ENABLED
fprintf(stderr, "DeviceCommunicationControl!\n");
#endif
if (service_data->segmented_message) {
len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
true);
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
#if PRINT_ENABLED
fprintf(stderr,
"DeviceCommunicationControl: "
"Sending Abort - segmented message.\n");
"DeviceCommunicationControl: "
"Sending Abort - segmented message.\n");
#endif
goto DCC_ABORT;
}
/* decode the service request only */
len =
dcc_decode_service_request(service_request, service_len, &timeDuration,
&state, &password);
len = dcc_decode_service_request(service_request, service_len,
&timeDuration, &state, &password);
#if PRINT_ENABLED
if (len > 0)
fprintf(stderr,
"DeviceCommunicationControl: " "timeout=%u state=%u password=%s\n",
(unsigned) timeDuration, (unsigned) state,
characterstring_value(&password));
"DeviceCommunicationControl: "
"timeout=%u state=%u password=%s\n",
(unsigned)timeDuration, (unsigned)state,
characterstring_value(&password));
#endif
/* bad decoding or something we didn't understand - send an abort */
if (len < 0) {
len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_OTHER, true);
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_OTHER,
true);
#if PRINT_ENABLED
fprintf(stderr,
"DeviceCommunicationControl: "
"Sending Abort - could not decode.\n");
"DeviceCommunicationControl: "
"Sending Abort - could not decode.\n");
#endif
goto DCC_ABORT;
}
if (state >= MAX_BACNET_COMMUNICATION_ENABLE_DISABLE) {
len =
reject_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, REJECT_REASON_UNDEFINED_ENUMERATION);
len = reject_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
REJECT_REASON_UNDEFINED_ENUMERATION);
#if PRINT_ENABLED
fprintf(stderr,
"DeviceCommunicationControl: "
"Sending Reject - undefined enumeration\n");
"DeviceCommunicationControl: "
"Sending Reject - undefined enumeration\n");
#endif
} else {
#if BAC_ROUTING
/* Check to see if the current Device supports this service. */
len =
Routed_Device_Service_Approval
(SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL, (int) state,
len = Routed_Device_Service_Approval(
SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL, (int)state,
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id);
if (len > 0)
goto DCC_ABORT;
#endif
if (characterstring_ansi_same(&password, My_Password)) {
len =
encode_simple_ack(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
len = encode_simple_ack(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL);
#if PRINT_ENABLED
fprintf(stderr,
"DeviceCommunicationControl: " "Sending Simple Ack!\n");
"DeviceCommunicationControl: "
"Sending Simple Ack!\n");
#endif
dcc_set_status_duration(state, timeDuration);
} else {
len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
len = bacerror_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL,
ERROR_CLASS_SECURITY, ERROR_CODE_PASSWORD_FAILURE);
#if PRINT_ENABLED
fprintf(stderr,
"DeviceCommunicationControl: "
"Sending Error - password failure.\n");
"DeviceCommunicationControl: "
"Sending Error - password failure.\n");
#endif
}
}
DCC_ABORT:
DCC_ABORT:
pdu_len += len;
len =
datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
len = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
if (len <= 0) {
#if PRINT_ENABLED
fprintf(stderr,
"DeviceCommunicationControl: " "Failed to send PDU (%s)!\n",
strerror(errno));
"DeviceCommunicationControl: "
"Failed to send PDU (%s)!\n",
strerror(errno));
#endif
}
+39 -43
View File
@@ -1,39 +1,39 @@
/**
* @file
* @author Daniel Blazevic <daniel.blazevic@gmail.com>
* @date 2013
* @brief GetAlarmSummary ACK service handling
*
* @section LICENSE
*
* Copyright (C) 2013 Daniel Blazevic <daniel.blazevic@gmail.com>
*
* 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.
*
* @section DESCRIPTION
*
* The GetAlarmSummary ACK service handler is used by a client BACnet-user to
* obtain a summary of "active alarms." The term "active alarm" refers to
* BACnet standard objects that have an Event_State property whose value is
* not equal to NORMAL and a Notify_Type property whose value is ALARM.
*/
* @file
* @author Daniel Blazevic <daniel.blazevic@gmail.com>
* @date 2013
* @brief GetAlarmSummary ACK service handling
*
* @section LICENSE
*
* Copyright (C) 2013 Daniel Blazevic <daniel.blazevic@gmail.com>
*
* 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.
*
* @section DESCRIPTION
*
* The GetAlarmSummary ACK service handler is used by a client BACnet-user to
* obtain a summary of "active alarms." The term "active alarm" refers to
* BACnet standard objects that have an Event_State property whose value is
* not equal to NORMAL and a Notify_Type property whose value is ALARM.
*/
#include <assert.h>
#include "config.h"
#include "txbuf.h"
@@ -46,7 +46,6 @@
#include "handlers.h"
#include "get_alarm_sum.h"
/** Example function to handle a GetAlarmSummary ACK.
*
* @param service_request [in] The contents of the service request.
@@ -56,19 +55,16 @@
* decoded from the APDU header of this message.
*/
void get_alarm_summary_ack_handler(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src,
BACNET_CONFIRMED_SERVICE_ACK_DATA * service_data)
uint8_t* service_request, uint16_t service_len, BACNET_ADDRESS* src,
BACNET_CONFIRMED_SERVICE_ACK_DATA* service_data)
{
uint16_t apdu_len = 0;
uint16_t len = 0;
BACNET_GET_ALARM_SUMMARY_DATA data;
while (service_len - len) {
apdu_len =
get_alarm_summary_ack_decode_apdu_data(&service_request[len],
service_len - len, &data);
apdu_len = get_alarm_summary_ack_decode_apdu_data(
&service_request[len], service_len - len, &data);
len += apdu_len;
+50 -65
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* Copyright (C) 2011 Krzysztof Malorny <malornykrzysztof@gmail.com>
*
* 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.
*
*********************************************************************/
*
* Copyright (C) 2011 Krzysztof Malorny <malornykrzysztof@gmail.com>
*
* 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 <stdio.h>
@@ -41,20 +41,17 @@
static get_alarm_summary_function Get_Alarm_Summary[MAX_BACNET_OBJECT_TYPE];
void handler_get_alarm_summary_set(
BACNET_OBJECT_TYPE object_type,
get_alarm_summary_function pFunction)
void handler_get_alarm_summary_set(BACNET_OBJECT_TYPE object_type,
get_alarm_summary_function pFunction)
{
if (object_type < MAX_BACNET_OBJECT_TYPE) {
Get_Alarm_Summary[object_type] = pFunction;
}
}
void handler_get_alarm_summary(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src,
BACNET_CONFIRMED_SERVICE_DATA * service_data)
void handler_get_alarm_summary(uint8_t* service_request, uint16_t service_len,
BACNET_ADDRESS* src,
BACNET_CONFIRMED_SERVICE_DATA* service_data)
{
int len = 0;
int pdu_len = 0;
@@ -68,41 +65,33 @@ void handler_get_alarm_summary(
BACNET_NPDU_DATA npdu_data;
BACNET_GET_ALARM_SUMMARY_DATA getalarm_data;
/* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
if (service_data->segmented_message) {
/* we don't support segmentation - send an abort */
apdu_len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
true);
apdu_len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
#if PRINT_ENABLED
fprintf(stderr,
"GetAlarmSummary: Segmented message. Sending Abort!\n");
fprintf(stderr, "GetAlarmSummary: Segmented message. Sending Abort!\n");
#endif
goto GET_ALARM_SUMMARY_ABORT;
}
/* init header */
apdu_len =
get_alarm_summary_ack_encode_apdu_init(&Handler_Transmit_Buffer
[pdu_len], service_data->invoke_id);
apdu_len = get_alarm_summary_ack_encode_apdu_init(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id);
for (i = 0; i < MAX_BACNET_OBJECT_TYPE; i++) {
if (Get_Alarm_Summary[i]) {
for (j = 0; j < 0xffff; j++) {
alarm_value = Get_Alarm_Summary[i] (j, &getalarm_data);
alarm_value = Get_Alarm_Summary[i](j, &getalarm_data);
if (alarm_value > 0) {
len =
get_alarm_summary_ack_encode_apdu_data
(&Handler_Transmit_Buffer[pdu_len + apdu_len],
len = get_alarm_summary_ack_encode_apdu_data(
&Handler_Transmit_Buffer[pdu_len + apdu_len],
service_data->max_resp - apdu_len, &getalarm_data);
if (len <= 0) {
error = true;
@@ -116,40 +105,36 @@ void handler_get_alarm_summary(
}
}
#if PRINT_ENABLED
fprintf(stderr, "GetAlarmSummary: Sending response!\n");
#endif
GET_ALARM_SUMMARY_ERROR:
GET_ALARM_SUMMARY_ERROR:
if (error) {
if (len == BACNET_STATUS_ABORT) {
/* BACnet APDU too small to fit data, so proper response is Abort */
apdu_len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
apdu_len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
#if PRINT_ENABLED
fprintf(stderr,
"GetAlarmSummary: Reply too big to fit into APDU!\n");
"GetAlarmSummary: Reply too big to fit into APDU!\n");
#endif
} else {
apdu_len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, SERVICE_CONFIRMED_GET_ALARM_SUMMARY,
ERROR_CLASS_PROPERTY, ERROR_CODE_OTHER);
apdu_len = bacerror_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_GET_ALARM_SUMMARY, ERROR_CLASS_PROPERTY,
ERROR_CODE_OTHER);
#if PRINT_ENABLED
fprintf(stderr, "GetAlarmSummary: Sending Error!\n");
#endif
}
}
GET_ALARM_SUMMARY_ABORT:
GET_ALARM_SUMMARY_ABORT:
pdu_len += apdu_len;
bytes_sent =
datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
bytes_sent = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0) {
/*fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno)); */
+82 -95
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* Copyright (C) 2009 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.
*
*********************************************************************/
*
* Copyright (C) 2009 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 <stdio.h>
@@ -43,45 +43,37 @@
static get_event_info_function Get_Event_Info[MAX_BACNET_OBJECT_TYPE];
/** print eventState
*/
void ge_ack_print_data(
BACNET_GET_EVENT_INFORMATION_DATA * data,
uint32_t device_id)
void ge_ack_print_data(BACNET_GET_EVENT_INFORMATION_DATA* data,
uint32_t device_id)
{
BACNET_GET_EVENT_INFORMATION_DATA *act_data = data;
BACNET_GET_EVENT_INFORMATION_DATA* act_data = data;
const char* state_strs[] = {"NO", "FA", "ON", "HL", "LL"};
printf("DeviceID\tType\tInstance\teventState\n");
printf("--------------- ------- --------------- ---------------\n");
int count = 0;
while (act_data) {
printf("%u\t\t%u\t%u\t\t%s\n",
device_id,
act_data->objectIdentifier.type,
act_data->objectIdentifier.instance,
state_strs[data->eventState]
);
act_data = act_data->next;
count++;
}
printf("\n%u\t Total\n",count);
printf("DeviceID\tType\tInstance\teventState\n");
printf("--------------- ------- --------------- ---------------\n");
int count = 0;
while (act_data) {
printf(
"%u\t\t%u\t%u\t\t%s\n", device_id, act_data->objectIdentifier.type,
act_data->objectIdentifier.instance, state_strs[data->eventState]);
act_data = act_data->next;
count++;
}
printf("\n%u\t Total\n", count);
}
void handler_get_event_information_set(
BACNET_OBJECT_TYPE object_type,
get_event_info_function pFunction)
void handler_get_event_information_set(BACNET_OBJECT_TYPE object_type,
get_event_info_function pFunction)
{
if (object_type < MAX_BACNET_OBJECT_TYPE) {
Get_Event_Info[object_type] = pFunction;
}
}
void handler_get_event_information(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src,
BACNET_CONFIRMED_SERVICE_DATA * service_data)
void handler_get_event_information(uint8_t* service_request,
uint16_t service_len, BACNET_ADDRESS* src,
BACNET_CONFIRMED_SERVICE_DATA* service_data)
{
int len = 0;
int pdu_len = 0;
@@ -94,7 +86,7 @@ void handler_get_event_information(
BACNET_ERROR_CODE error_code = ERROR_CODE_UNKNOWN_OBJECT;
BACNET_ADDRESS my_address;
BACNET_OBJECT_ID object_id;
unsigned i = 0, j = 0; /* counter */
unsigned i = 0, j = 0; /* counter */
BACNET_GET_EVENT_INFORMATION_DATA getevent_data;
int valid_event = 0;
@@ -104,38 +96,35 @@ void handler_get_event_information(
/* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
if (service_data->segmented_message) {
/* we don't support segmentation - send an abort */
len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
true);
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
#if PRINT_ENABLED
fprintf(stderr,
"GetEventInformation: " "Segmented message. Sending Abort!\n");
"GetEventInformation: "
"Segmented message. Sending Abort!\n");
#endif
goto GET_EVENT_ABORT;
}
len =
getevent_decode_service_request(service_request, service_len,
&object_id);
len = getevent_decode_service_request(service_request, service_len,
&object_id);
if (len < 0) {
/* bad decoding - send an abort */
len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_OTHER, true);
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_OTHER,
true);
#if PRINT_ENABLED
fprintf(stderr,
"GetEventInformation: Bad Encoding. Sending Abort!\n");
fprintf(stderr, "GetEventInformation: Bad Encoding. Sending Abort!\n");
#endif
goto GET_EVENT_ABORT;
}
len =
getevent_ack_encode_apdu_init(&Handler_Transmit_Buffer[pdu_len],
len = getevent_ack_encode_apdu_init(
&Handler_Transmit_Buffer[pdu_len],
sizeof(Handler_Transmit_Buffer) - pdu_len, service_data->invoke_id);
if (len <= 0) {
error = true;
@@ -146,14 +135,15 @@ void handler_get_event_information(
for (i = 0; i < MAX_BACNET_OBJECT_TYPE; i++) {
if (Get_Event_Info[i]) {
for (j = 0; j < 0xffff; j++) {
valid_event = Get_Event_Info[i] (j, &getevent_data);
valid_event = Get_Event_Info[i](j, &getevent_data);
if (valid_event > 0) {
/* encode GetEvent_data only when type of object_id has max value */
/* encode GetEvent_data only when type of object_id has max
* value */
if (object_id.type != MAX_BACNET_OBJECT_TYPE) {
if ((object_id.type ==
getevent_data.objectIdentifier.type) &&
getevent_data.objectIdentifier.type) &&
(object_id.instance ==
getevent_data.objectIdentifier.instance)) {
getevent_data.objectIdentifier.instance)) {
/* found 'Last Received Object Identifier'
so should set type of object_id to max value */
object_id.type = MAX_BACNET_OBJECT_TYPE;
@@ -162,16 +152,16 @@ void handler_get_event_information(
}
getevent_data.next = NULL;
len =
getevent_ack_encode_apdu_data(&Handler_Transmit_Buffer
[pdu_len], sizeof(Handler_Transmit_Buffer) - pdu_len,
len = getevent_ack_encode_apdu_data(
&Handler_Transmit_Buffer[pdu_len],
sizeof(Handler_Transmit_Buffer) - pdu_len,
&getevent_data);
if (len <= 0) {
error = true;
goto GET_EVENT_ERROR;
}
apdu_len += len;
if ((apdu_len >= service_data->max_resp - 2) ||
if ((apdu_len >= service_data->max_resp - 2) ||
(apdu_len >= MAX_APDU - 2)) {
/* Device must be able to fit minimum
one event information.
@@ -195,8 +185,8 @@ void handler_get_event_information(
}
}
}
len =
getevent_ack_encode_apdu_end(&Handler_Transmit_Buffer[pdu_len],
len = getevent_ack_encode_apdu_end(
&Handler_Transmit_Buffer[pdu_len],
sizeof(Handler_Transmit_Buffer) - pdu_len, more_events);
if (len <= 0) {
error = true;
@@ -205,37 +195,34 @@ void handler_get_event_information(
#if PRINT_ENABLED
fprintf(stderr, "Got a GetEventInformation request: Sending Ack!\n");
#endif
GET_EVENT_ERROR:
GET_EVENT_ERROR:
if (error) {
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
if (len == -2) {
/* BACnet APDU too small to fit data, so proper response is Abort */
len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
#if PRINT_ENABLED
fprintf(stderr,
"GetEventInformation: " "Reply too big to fit into APDU!\n");
"GetEventInformation: "
"Reply too big to fit into APDU!\n");
#endif
} else {
len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, SERVICE_CONFIRMED_READ_PROPERTY,
error_class, error_code);
len = bacerror_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_READ_PROPERTY, error_class, error_code);
#if PRINT_ENABLED
fprintf(stderr, "GetEventInformation: Sending Error!\n");
#endif
}
}
GET_EVENT_ABORT:
GET_EVENT_ABORT:
pdu_len += len;
bytes_sent =
datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
bytes_sent = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0)
fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno));
+5 -8
View File
@@ -59,11 +59,9 @@
* @param service_data [in] The BACNET_CONFIRMED_SERVICE_ACK_DATA information
* decoded from the APDU header of this message.
*/
void get_event_ack_handler(
uint8_t *service_request,
uint16_t service_len,
BACNET_ADDRESS *src,
BACNET_CONFIRMED_SERVICE_ACK_DATA *service_data)
void get_event_ack_handler(uint8_t *service_request, uint16_t service_len,
BACNET_ADDRESS *src,
BACNET_CONFIRMED_SERVICE_ACK_DATA *service_data)
{
uint8_t i = 0;
uint16_t apdu_len = 0;
@@ -77,9 +75,8 @@ void get_event_ack_handler(
get_event_data[i - 1].next = &get_event_data[i];
}
apdu_len =
getevent_ack_decode_service_request(&service_request[0],
service_len, &get_event_data[0], &more_events);
apdu_len = getevent_ack_decode_service_request(
&service_request[0], service_len, &get_event_data[0], &more_events);
if (apdu_len > 0) {
/* FIXME: Add code to process get_event_data */
+35 -41
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* Copyright (C) 2005 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.
*
*********************************************************************/
*
* Copyright (C) 2005 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 <stdio.h>
@@ -42,10 +42,8 @@
* @param service_len [in] Length of the service_request message.
* @param src [in] The BACNET_ADDRESS of the message's source.
*/
void handler_i_am_add(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src)
void handler_i_am_add(uint8_t* service_request, uint16_t service_len,
BACNET_ADDRESS* src)
{
int len = 0;
uint32_t device_id = 0;
@@ -53,18 +51,17 @@ void handler_i_am_add(
int segmentation = 0;
uint16_t vendor_id = 0;
(void) service_len;
len =
iam_decode_service_request(service_request, &device_id, &max_apdu,
&segmentation, &vendor_id);
(void)service_len;
len = iam_decode_service_request(service_request, &device_id, &max_apdu,
&segmentation, &vendor_id);
#if PRINT_ENABLED
fprintf(stderr, "Received I-Am Request");
#endif
if (len != -1) {
#if PRINT_ENABLED
fprintf(stderr, " from %lu, MAC = %d.%d.%d.%d.%d.%d\n",
(unsigned long) device_id, src->mac[0], src->mac[1], src->mac[2],
src->mac[3], src->mac[4], src->mac[5]);
(unsigned long)device_id, src->mac[0], src->mac[1], src->mac[2],
src->mac[3], src->mac[4], src->mac[5]);
#endif
address_add(device_id, max_apdu, src);
} else {
@@ -84,10 +81,8 @@ void handler_i_am_add(
* @param service_len [in] Length of the service_request message.
* @param src [in] The BACNET_ADDRESS of the message's source.
*/
void handler_i_am_bind(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src)
void handler_i_am_bind(uint8_t* service_request, uint16_t service_len,
BACNET_ADDRESS* src)
{
int len = 0;
uint32_t device_id = 0;
@@ -95,10 +90,9 @@ void handler_i_am_bind(
int segmentation = 0;
uint16_t vendor_id = 0;
(void) service_len;
len =
iam_decode_service_request(service_request, &device_id, &max_apdu,
&segmentation, &vendor_id);
(void)service_len;
len = iam_decode_service_request(service_request, &device_id, &max_apdu,
&segmentation, &vendor_id);
if (len > 0) {
/* only add address if requested to bind */
address_add_binding(device_id, max_apdu, src);
+31 -33
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* 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.
*
*********************************************************************/
*
* 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 <stdio.h>
@@ -41,24 +41,22 @@
* @param service_len [in] Length of the service_request message.
* @param src [in] The BACNET_ADDRESS of the message's source.
*/
void handler_i_have(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src)
void handler_i_have(uint8_t* service_request, uint16_t service_len,
BACNET_ADDRESS* src)
{
int len = 0;
BACNET_I_HAVE_DATA data;
(void) service_len;
(void) src;
(void)service_len;
(void)src;
len = ihave_decode_service_request(service_request, service_len, &data);
if (len != -1) {
#if PRINT_ENABLED
fprintf(stderr, "I-Have: %s %lu from %s %lu!\r\n",
bactext_object_type_name(data.object_id.type),
(unsigned long) data.object_id.instance,
bactext_object_type_name(data.device_id.type),
(unsigned long) data.device_id.instance);
bactext_object_type_name(data.object_id.type),
(unsigned long)data.object_id.instance,
bactext_object_type_name(data.device_id.type),
(unsigned long)data.device_id.instance);
#endif
} else {
#if PRINT_ENABLED
+51 -51
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* Copyright (C) 2005 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.
*
*********************************************************************/
*
* Copyright (C) 2005 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 <stdio.h>
@@ -40,11 +40,9 @@
/** @file h_lso.c Handles BACnet Life Safey Operation messages. */
void handler_lso(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src,
BACNET_CONFIRMED_SERVICE_DATA * service_data)
void handler_lso(uint8_t* service_request, uint16_t service_len,
BACNET_ADDRESS* src,
BACNET_CONFIRMED_SERVICE_DATA* service_data)
{
BACNET_LSO_DATA data;
int len = 0;
@@ -56,15 +54,13 @@ void handler_lso(
/* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
if (service_data->segmented_message) {
/* we don't support segmentation - send an abort */
len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
true);
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
#if PRINT_ENABLED
fprintf(stderr, "LSO: Segmented message. Sending Abort!\n");
#endif
@@ -78,9 +74,9 @@ void handler_lso(
#endif
if (len < 0) {
/* bad decoding - send an abort */
len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_OTHER, true);
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_OTHER,
true);
#if PRINT_ENABLED
fprintf(stderr, "LSO: Bad Encoding. Sending Abort!\n");
#endif
@@ -92,27 +88,31 @@ void handler_lso(
*/
#if PRINT_ENABLED
fprintf(stderr,
"Life Safety Operation: Received operation %d from process id %lu for object %lu\n",
data.operation, (unsigned long) data.processId,
(unsigned long) data.targetObject.instance);
"Life Safety Operation: Received operation %d from process id %lu "
"for object %lu\n",
data.operation, (unsigned long)data.processId,
(unsigned long)data.targetObject.instance);
#endif
len =
encode_simple_ack(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, SERVICE_CONFIRMED_LIFE_SAFETY_OPERATION);
len = encode_simple_ack(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
SERVICE_CONFIRMED_LIFE_SAFETY_OPERATION);
#if PRINT_ENABLED
fprintf(stderr, "Life Safety Operation: " "Sending Simple Ack!\n");
fprintf(stderr,
"Life Safety Operation: "
"Sending Simple Ack!\n");
#endif
LSO_ABORT:
LSO_ABORT:
pdu_len += len;
bytes_sent =
datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
bytes_sent = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0)
fprintf(stderr, "Life Safety Operation: " "Failed to send PDU (%s)!\n",
strerror(errno));
fprintf(stderr,
"Life Safety Operation: "
"Failed to send PDU (%s)!\n",
strerror(errno));
#endif
return;
+33 -34
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* Copyright (C) 2008 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.
*
*********************************************************************/
*
* Copyright (C) 2008 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 <stdbool.h>
#include <stdint.h>
#include "bacdef.h"
@@ -63,14 +63,13 @@
* @param pdu [in] Buffer containing the NPDU and APDU of the received packet.
* @param pdu_len [in] The size of the received message in the pdu[] buffer.
*/
void npdu_handler(
BACNET_ADDRESS * src, /* source address */
uint8_t * pdu, /* PDU data */
uint16_t pdu_len)
{ /* length PDU */
void npdu_handler(BACNET_ADDRESS* src, /* source address */
uint8_t* pdu, /* PDU data */
uint16_t pdu_len)
{ /* length PDU */
int apdu_offset = 0;
BACNET_ADDRESS dest = { 0 };
BACNET_NPDU_DATA npdu_data = { 0 };
BACNET_ADDRESS dest = {0};
BACNET_NPDU_DATA npdu_data = {0};
/* only handle the version that we know how to handle */
if (pdu[0] == BACNET_PROTOCOL_VERSION) {
@@ -87,24 +86,24 @@ void npdu_handler(
routing information cause they are not for us */
if ((dest.net == BACNET_BROADCAST_NETWORK) &&
((pdu[apdu_offset] & 0xF0) ==
PDU_TYPE_CONFIRMED_SERVICE_REQUEST)) {
PDU_TYPE_CONFIRMED_SERVICE_REQUEST)) {
/* hack for 5.4.5.1 - IDLE */
/* ConfirmedBroadcastReceived */
/* then enter IDLE - ignore the PDU */
} else {
apdu_handler(src, &pdu[apdu_offset],
(uint16_t) (pdu_len - apdu_offset));
(uint16_t)(pdu_len - apdu_offset));
}
} else {
#if PRINT_ENABLED
printf("NPDU: DNET=%u. Discarded!\n", (unsigned) dest.net);
printf("NPDU: DNET=%u. Discarded!\n", (unsigned)dest.net);
#endif
}
}
} else {
#if PRINT_ENABLED
printf("NPDU: BACnet Protocol Version=%u. Discarded!\n",
(unsigned) pdu[0]);
(unsigned)pdu[0]);
#endif
}
+81 -103
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* Copyright (C) 2005 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.
*
*********************************************************************/
*
* Copyright (C) 2005 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 <stdio.h>
@@ -50,12 +50,11 @@
DATABLOCK MyData[MYMAXBLOCK];
uint8_t IOBufferPT[MAX_APDU]; /* Buffer for building response in */
uint8_t IOBufferPT[MAX_APDU]; /* Buffer for building response in */
static void ProcessPT(
BACNET_PRIVATE_TRANSFER_DATA * data)
static void ProcessPT(BACNET_PRIVATE_TRANSFER_DATA *data)
{
int iLen; /* Index to current location in data */
int iLen; /* Index to current location in data */
char cBlockNumber;
uint32_t ulTemp;
int tag_len;
@@ -66,9 +65,8 @@ static void ProcessPT(
iLen = 0;
/* Decode the block number */
tag_len =
decode_tag_number_and_value(&data->serviceParameters[iLen],
&tag_number, &len_value_type);
tag_len = decode_tag_number_and_value(&data->serviceParameters[iLen],
&tag_number, &len_value_type);
iLen += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT) {
/* Bail out early if wrong type */
@@ -77,10 +75,9 @@ static void ProcessPT(
return;
}
iLen +=
decode_unsigned(&data->serviceParameters[iLen], len_value_type,
&ulTemp);
cBlockNumber = (char) ulTemp;
iLen += decode_unsigned(&data->serviceParameters[iLen], len_value_type,
&ulTemp);
cBlockNumber = (char)ulTemp;
if (cBlockNumber < MY_MAX_BLOCK) {
if (data->serviceNumber == MY_SVC_READ) {
/* Read Response is an unsigned int with
@@ -101,20 +98,16 @@ static void ProcessPT(
iLen +=
encode_application_unsigned(&IOBufferPT[iLen], cBlockNumber);
/* And Then the block contents */
iLen += encode_application_unsigned(
&IOBufferPT[iLen], MyData[(int8_t)cBlockNumber].cMyByte1);
iLen += encode_application_unsigned(
&IOBufferPT[iLen], MyData[(int8_t)cBlockNumber].cMyByte2);
iLen += encode_application_real(
&IOBufferPT[iLen], MyData[(int8_t)cBlockNumber].fMyReal);
characterstring_init_ansi(
&bsTemp, (char *)MyData[(int8_t)cBlockNumber].sMyString);
iLen +=
encode_application_unsigned(&IOBufferPT[iLen],
MyData[(int8_t) cBlockNumber].cMyByte1);
iLen +=
encode_application_unsigned(&IOBufferPT[iLen],
MyData[(int8_t) cBlockNumber].cMyByte2);
iLen +=
encode_application_real(&IOBufferPT[iLen],
MyData[(int8_t) cBlockNumber].fMyReal);
characterstring_init_ansi(&bsTemp,
(char *) MyData[(int8_t) cBlockNumber].sMyString);
iLen +=
encode_application_character_string(&IOBufferPT[iLen],
&bsTemp);
encode_application_character_string(&IOBufferPT[iLen], &bsTemp);
} else {
/* Write operation */
/* Write block consists of the block number
@@ -124,59 +117,52 @@ static void ProcessPT(
response which is 0 for success and
a non 0 error code otherwise. */
tag_len =
decode_tag_number_and_value(&data->serviceParameters[iLen],
&tag_number, &len_value_type);
tag_len = decode_tag_number_and_value(
&data->serviceParameters[iLen], &tag_number, &len_value_type);
iLen += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT) {
data->serviceParametersLen = 0;
return;
}
iLen +=
decode_unsigned(&data->serviceParameters[iLen], len_value_type,
&ulTemp);
MyData[(int8_t) cBlockNumber].cMyByte1 = (char) ulTemp;
iLen += decode_unsigned(&data->serviceParameters[iLen],
len_value_type, &ulTemp);
MyData[(int8_t)cBlockNumber].cMyByte1 = (char)ulTemp;
tag_len =
decode_tag_number_and_value(&data->serviceParameters[iLen],
&tag_number, &len_value_type);
tag_len = decode_tag_number_and_value(
&data->serviceParameters[iLen], &tag_number, &len_value_type);
iLen += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT) {
data->serviceParametersLen = 0;
return;
}
iLen +=
decode_unsigned(&data->serviceParameters[iLen], len_value_type,
&ulTemp);
MyData[(int8_t) cBlockNumber].cMyByte2 = (char) ulTemp;
iLen += decode_unsigned(&data->serviceParameters[iLen],
len_value_type, &ulTemp);
MyData[(int8_t)cBlockNumber].cMyByte2 = (char)ulTemp;
tag_len =
decode_tag_number_and_value(&data->serviceParameters[iLen],
&tag_number, &len_value_type);
tag_len = decode_tag_number_and_value(
&data->serviceParameters[iLen], &tag_number, &len_value_type);
iLen += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_REAL) {
data->serviceParametersLen = 0;
return;
}
iLen +=
decode_real(&data->serviceParameters[iLen],
&MyData[(int8_t) cBlockNumber].fMyReal);
iLen += decode_real(&data->serviceParameters[iLen],
&MyData[(int8_t)cBlockNumber].fMyReal);
tag_len =
decode_tag_number_and_value(&data->serviceParameters[iLen],
&tag_number, &len_value_type);
tag_len = decode_tag_number_and_value(
&data->serviceParameters[iLen], &tag_number, &len_value_type);
iLen += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_CHARACTER_STRING) {
data->serviceParametersLen = 0;
return;
}
decode_character_string(&data->serviceParameters[iLen],
len_value_type, &bsTemp);
len_value_type, &bsTemp);
/* Only copy as much as we can accept */
strncpy((char *) MyData[(int8_t) cBlockNumber].sMyString,
characterstring_value(&bsTemp), MY_MAX_STR);
strncpy((char *)MyData[(int8_t)cBlockNumber].sMyString,
characterstring_value(&bsTemp), MY_MAX_STR);
/* Make sure it is nul terminated */
MyData[(int8_t) cBlockNumber].sMyString[MY_MAX_STR] = '\0';
MyData[(int8_t)cBlockNumber].sMyString[MY_MAX_STR] = '\0';
/* Signal success */
iLen = encode_application_unsigned(&IOBufferPT[0], MY_ERR_OK);
}
@@ -198,12 +184,9 @@ static void ProcessPT(
*
*/
void handler_conf_private_trans(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src,
BACNET_CONFIRMED_SERVICE_DATA * service_data)
void handler_conf_private_trans(uint8_t *service_request, uint16_t service_len,
BACNET_ADDRESS *src,
BACNET_CONFIRMED_SERVICE_DATA *service_data)
{
BACNET_PRIVATE_TRANSFER_DATA data;
int len;
@@ -230,28 +213,25 @@ void handler_conf_private_trans(
datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
if (service_data->segmented_message) {
len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
true);
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
#if PRINT_ENABLED
fprintf(stderr, "CPT: Segmented Message. Sending Abort!\n");
#endif
goto CPT_ABORT;
}
len =
ptransfer_decode_service_request(service_request, service_len, &data);
len = ptransfer_decode_service_request(service_request, service_len, &data);
/* bad decoding - send an abort */
if (len < 0) {
len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_OTHER, true);
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_OTHER,
true);
#if PRINT_ENABLED
fprintf(stderr, "CPT: Bad Encoding. Sending Abort!\n");
#endif
@@ -278,10 +258,9 @@ void handler_conf_private_trans(
fprintf(stderr, "CPT: Error servicing request!\n");
#endif
}
len =
ptransfer_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, &data);
} else { /* Not our vendor ID or bad service parameter */
len = ptransfer_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, &data);
} else { /* Not our vendor ID or bad service parameter */
error = true;
error_class = ERROR_CLASS_SERVICES;
@@ -292,15 +271,14 @@ void handler_conf_private_trans(
}
if (error) {
len =
ptransfer_error_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, error_class, error_code, &data);
len = ptransfer_error_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, error_class,
error_code, &data);
}
CPT_ABORT:
CPT_ABORT:
pdu_len += len;
bytes_sent =
datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
bytes_sent = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0) {
+71 -84
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* Copyright (C) 2005 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.
*
*********************************************************************/
*
* Copyright (C) 2005 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 <stdio.h>
@@ -45,11 +45,10 @@
/** @file h_pt_a.c Handles Confirmed Private Transfer Acknowledgment. */
extern uint8_t IOBufferPT[300]; /* Somewhere to build the encoded result block for Private Transfers */
extern uint8_t IOBufferPT[300]; /* Somewhere to build the encoded result block
for Private Transfers */
static void DecodeBlock(
char cBlockNum,
uint8_t * pData)
static void DecodeBlock(char cBlockNum, uint8_t *pData)
{
int iLen;
uint32_t ulTemp;
@@ -65,28 +64,25 @@ static void DecodeBlock(
return;
tag_len =
decode_tag_number_and_value(&pData[iLen], &tag_number,
&len_value_type);
decode_tag_number_and_value(&pData[iLen], &tag_number, &len_value_type);
iLen += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT)
return;
iLen += decode_unsigned(&pData[iLen], len_value_type, &ulTemp);
Response.cMyByte1 = (char) ulTemp;
Response.cMyByte1 = (char)ulTemp;
tag_len =
decode_tag_number_and_value(&pData[iLen], &tag_number,
&len_value_type);
decode_tag_number_and_value(&pData[iLen], &tag_number, &len_value_type);
iLen += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT)
return;
iLen += decode_unsigned(&pData[iLen], len_value_type, &ulTemp);
Response.cMyByte2 = (char) ulTemp;
Response.cMyByte2 = (char)ulTemp;
tag_len =
decode_tag_number_and_value(&pData[iLen], &tag_number,
&len_value_type);
decode_tag_number_and_value(&pData[iLen], &tag_number, &len_value_type);
iLen += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_REAL)
return;
@@ -94,29 +90,27 @@ static void DecodeBlock(
iLen += decode_real(&pData[iLen], &Response.fMyReal);
tag_len =
decode_tag_number_and_value(&pData[iLen], &tag_number,
&len_value_type);
decode_tag_number_and_value(&pData[iLen], &tag_number, &len_value_type);
iLen += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_CHARACTER_STRING)
return;
iLen += decode_character_string(&pData[iLen], len_value_type, &bsName);
strncpy((char *) Response.sMyString, characterstring_value(&bsName),
MY_MAX_STR);
Response.sMyString[MY_MAX_STR] = '\0'; /* Make sure it is nul terminated */
strncpy((char *)Response.sMyString, characterstring_value(&bsName),
MY_MAX_STR);
Response.sMyString[MY_MAX_STR] = '\0'; /* Make sure it is nul terminated */
printf("Private Transfer Read Block Response\n");
printf("Data Block: %d\n", (int) cBlockNum);
printf(" First Byte : %d\n", (int) Response.cMyByte1);
printf(" Second Byte : %d\n", (int) Response.cMyByte2);
printf("Data Block: %d\n", (int)cBlockNum);
printf(" First Byte : %d\n", (int)Response.cMyByte1);
printf(" Second Byte : %d\n", (int)Response.cMyByte2);
printf(" Real : %f\n", Response.fMyReal);
printf(" String : %s\n\n", Response.sMyString);
}
static void ProcessPTA(
BACNET_PRIVATE_TRANSFER_DATA * data)
static void ProcessPTA(BACNET_PRIVATE_TRANSFER_DATA *data)
{
int iLen; /* Index to current location in data */
int iLen; /* Index to current location in data */
uint32_t uiErrorCode;
char cBlockNumber;
uint32_t ulTemp;
@@ -128,9 +122,8 @@ static void ProcessPTA(
/* Error code is returned for read and write operations */
tag_len =
decode_tag_number_and_value(&data->serviceParameters[iLen],
&tag_number, &len_value_type);
tag_len = decode_tag_number_and_value(&data->serviceParameters[iLen],
&tag_number, &len_value_type);
iLen += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT) {
#if PRINT_ENABLED
@@ -138,18 +131,18 @@ static void ProcessPTA(
#endif
return;
}
iLen +=
decode_unsigned(&data->serviceParameters[iLen], len_value_type,
&uiErrorCode);
iLen += decode_unsigned(&data->serviceParameters[iLen], len_value_type,
&uiErrorCode);
if (data->serviceNumber == MY_SVC_READ) { /* Read I/O block so should be full block of data or error */
/* Decode the error type and if necessary block number and then fetch the info */
if (data->serviceNumber == MY_SVC_READ) { /* Read I/O block so should be
full block of data or error */
/* Decode the error type and if necessary block number and then fetch
* the info */
if (uiErrorCode == MY_ERR_OK) {
/* Block Number */
tag_len =
decode_tag_number_and_value(&data->serviceParameters[iLen],
&tag_number, &len_value_type);
tag_len = decode_tag_number_and_value(
&data->serviceParameters[iLen], &tag_number, &len_value_type);
iLen += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT) {
#if PRINT_ENABLED
@@ -158,25 +151,21 @@ static void ProcessPTA(
return;
}
iLen +=
decode_unsigned(&data->serviceParameters[iLen], len_value_type,
&ulTemp);
cBlockNumber = (char) ulTemp;
iLen += decode_unsigned(&data->serviceParameters[iLen],
len_value_type, &ulTemp);
cBlockNumber = (char)ulTemp;
DecodeBlock(cBlockNumber, &data->serviceParameters[iLen]);
} else { /* Read error */
printf
("Private Transfer read operation returned error code: %lu\n",
(unsigned long) uiErrorCode);
} else { /* Read error */
printf("Private Transfer read operation returned error code: %lu\n",
(unsigned long)uiErrorCode);
return;
}
} else { /* Write I/O block - should just be an OK type message */
} else { /* Write I/O block - should just be an OK type message */
printf("Private Transfer write operation returned error code: %lu\n",
(unsigned long) uiErrorCode);
(unsigned long)uiErrorCode);
}
}
/*
* This is called when we receive a private transfer packet ack.
* We parse the response which the remote application generated
@@ -184,40 +173,38 @@ static void ProcessPTA(
*/
void handler_conf_private_trans_ack(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src,
BACNET_CONFIRMED_SERVICE_ACK_DATA * service_data)
uint8_t *service_request, uint16_t service_len, BACNET_ADDRESS *src,
BACNET_CONFIRMED_SERVICE_ACK_DATA *service_data)
{
BACNET_PRIVATE_TRANSFER_DATA data;
int len;
/*
* Note:
* We currently don't look at the source address and service data
* but we probably should to verify that the ack is oneit is what
* we were expecting. But this is just to silence some compiler
* warnings from Borland.
*/
/*
* Note:
* We currently don't look at the source address and service data
* but we probably should to verify that the ack is oneit is what
* we were expecting. But this is just to silence some compiler
* warnings from Borland.
*/
src = src;
service_data = service_data;
len = 0;
#if PRINT_ENABLED
printf("Received Confirmed Private Transfer Ack!\n");
#endif
len = ptransfer_decode_service_request(service_request, service_len, &data); /* Same decode for ack as for service request! */
len = ptransfer_decode_service_request(
service_request, service_len,
&data); /* Same decode for ack as for service request! */
if (len < 0) {
#if PRINT_ENABLED
printf("cpta: Bad Encoding!\n");
#endif
}
ProcessPTA(&data); /* See what to do with the response */
ProcessPTA(&data); /* See what to do with the response */
return;
}
+57 -65
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* 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.
*
*********************************************************************/
*
* 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 <stdio.h>
@@ -63,11 +63,9 @@
* @param service_data [in] The BACNET_CONFIRMED_SERVICE_DATA information
* decoded from the APDU header of this message.
*/
void handler_reinitialize_device(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src,
BACNET_CONFIRMED_SERVICE_DATA * service_data)
void handler_reinitialize_device(uint8_t* service_request, uint16_t service_len,
BACNET_ADDRESS* src,
BACNET_CONFIRMED_SERVICE_DATA* service_data)
{
BACNET_REINITIALIZE_DEVICE_DATA rd_data;
int len = 0;
@@ -78,94 +76,88 @@ void handler_reinitialize_device(
/* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
#if PRINT_ENABLED
fprintf(stderr, "ReinitializeDevice!\n");
#endif
if (service_data->segmented_message) {
len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
true);
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
#if PRINT_ENABLED
fprintf(stderr,
"ReinitializeDevice: Sending Abort - segmented message.\n");
"ReinitializeDevice: Sending Abort - segmented message.\n");
#endif
goto RD_ABORT;
}
/* decode the service request only */
len =
rd_decode_service_request(service_request, service_len, &rd_data.state,
&rd_data.password);
len = rd_decode_service_request(service_request, service_len,
&rd_data.state, &rd_data.password);
#if PRINT_ENABLED
if (len > 0) {
fprintf(stderr, "ReinitializeDevice: state=%u password=%s\n",
(unsigned) rd_data.state,
characterstring_value(&rd_data.password));
(unsigned)rd_data.state,
characterstring_value(&rd_data.password));
} else {
fprintf(stderr, "ReinitializeDevice: Unable to decode request!\n");
}
#endif
/* bad decoding or something we didn't understand - send an abort */
if (len < 0) {
len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_OTHER, true);
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_OTHER,
true);
#if PRINT_ENABLED
fprintf(stderr,
"ReinitializeDevice: Sending Abort - could not decode.\n");
"ReinitializeDevice: Sending Abort - could not decode.\n");
#endif
goto RD_ABORT;
}
/* check the data from the request */
if (rd_data.state >= BACNET_REINIT_MAX) {
len =
reject_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, REJECT_REASON_UNDEFINED_ENUMERATION);
len = reject_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
REJECT_REASON_UNDEFINED_ENUMERATION);
#if PRINT_ENABLED
fprintf(stderr,
"ReinitializeDevice: Sending Reject - undefined enumeration\n");
"ReinitializeDevice: Sending Reject - undefined enumeration\n");
#endif
} else {
#if BAC_ROUTING
/* Check to see if the current Device supports this service. */
len =
Routed_Device_Service_Approval
(SERVICE_CONFIRMED_REINITIALIZE_DEVICE, (int) rd_data.state,
len = Routed_Device_Service_Approval(
SERVICE_CONFIRMED_REINITIALIZE_DEVICE, (int)rd_data.state,
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id);
if (len > 0)
goto RD_ABORT;
#endif
if (Device_Reinitialize(&rd_data)) {
len =
encode_simple_ack(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
SERVICE_CONFIRMED_REINITIALIZE_DEVICE);
len = encode_simple_ack(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
SERVICE_CONFIRMED_REINITIALIZE_DEVICE);
#if PRINT_ENABLED
fprintf(stderr, "ReinitializeDevice: Sending Simple Ack!\n");
#endif
} else {
len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, SERVICE_CONFIRMED_REINITIALIZE_DEVICE,
rd_data.error_class, rd_data.error_code);
len = bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
SERVICE_CONFIRMED_REINITIALIZE_DEVICE,
rd_data.error_class, rd_data.error_code);
#if PRINT_ENABLED
fprintf(stderr, "ReinitializeDevice: Sending Error.\n");
#endif
}
}
RD_ABORT:
RD_ABORT:
pdu_len += len;
len =
datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
len = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
if (len <= 0) {
#if PRINT_ENABLED
fprintf(stderr, "ReinitializeDevice: Failed to send PDU (%s)!\n",
strerror(errno));
strerror(errno));
#endif
}
+58 -67
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* Copyright (C) 2010 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.
*
*********************************************************************/
*
* Copyright (C) 2010 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.
*
*********************************************************************/
/* Acknowledging the contribution of code and ideas used here that
* came from Paul Chapman's vmac demo project. */
@@ -47,10 +47,8 @@
#include "bvlc.h"
#endif
/** @file h_routed_npdu.c Handles messages at the NPDU level of the BACnet stack,
* including routing and network control messages. */
/** @file h_routed_npdu.c Handles messages at the NPDU level of the BACnet
* stack, including routing and network control messages. */
/** Handler to manage the Network Layer Control Messages received in a packet.
* This handler is called if the NCPI bit 7 indicates that this packet is a
@@ -61,20 +59,18 @@
* @param src [in] The routing source information, if any.
* If src->net and src->len are 0, there is no
* routing source information.
* @param DNET_list [in] List of our reachable downstream BACnet Network numbers.
* Normally just one valid entry; terminated with a -1 value.
* @param DNET_list [in] List of our reachable downstream BACnet Network
* numbers. Normally just one valid entry; terminated with a -1 value.
* @param npdu_data [in] Contains a filled-out structure with information
* decoded from the NCPI and other NPDU bytes.
* decoded from the NCPI and other NPDU
* bytes.
* @param npdu [in] Buffer containing the rest of the NPDU, following the
* bytes that have already been decoded.
* @param npdu_len [in] The length of the remaining NPDU message in npdu[].
*/
static void network_control_handler(
BACNET_ADDRESS * src,
int *DNET_list,
BACNET_NPDU_DATA * npdu_data,
uint8_t * npdu,
uint16_t npdu_len)
static void network_control_handler(BACNET_ADDRESS *src, int *DNET_list,
BACNET_NPDU_DATA *npdu_data, uint8_t *npdu,
uint16_t npdu_len)
{
uint16_t npdu_offset = 0;
uint16_t dnet = 0;
@@ -109,8 +105,8 @@ static void network_control_handler(
* later for congestion control - then it could matter.
*/
debug_printf("%s for Networks: ",
bactext_network_layer_msg_name
(NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK));
bactext_network_layer_msg_name(
NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK));
while (npdu_len >= 2) {
len = decode_unsigned16(&npdu[npdu_offset], &dnet);
debug_printf("%hu", dnet);
@@ -129,8 +125,8 @@ static void network_control_handler(
if (npdu_len >= 3) {
decode_unsigned16(&npdu[1], &dnet);
debug_printf("Received %s for Network: ",
bactext_network_layer_msg_name
(NETWORK_MESSAGE_I_COULD_BE_ROUTER_TO_NETWORK));
bactext_network_layer_msg_name(
NETWORK_MESSAGE_I_COULD_BE_ROUTER_TO_NETWORK));
debug_printf("%hu, Reason code: %d \n", dnet, npdu[0]);
}
break;
@@ -168,8 +164,8 @@ static void network_control_handler(
break;
default:
/* An unrecognized message is bad; send an error response. */
Send_Reject_Message_To_Network(src,
NETWORK_REJECT_UNKNOWN_MESSAGE_TYPE, DNET_list[0]);
Send_Reject_Message_To_Network(
src, NETWORK_REJECT_UNKNOWN_MESSAGE_TYPE, DNET_list[0]);
/* Sending our DNET doesn't make a lot of sense, does it? */
break;
}
@@ -186,19 +182,16 @@ static void network_control_handler(
*
* @param src [in] The BACNET_ADDRESS of the message's source.
* @param dest [in] The BACNET_ADDRESS of the message's destination.
* @param DNET_list [in] List of our reachable downstream BACnet Network numbers.
* Normally just one valid entry; terminated with a -1 value.
* @param DNET_list [in] List of our reachable downstream BACnet Network
* numbers. Normally just one valid entry; terminated with a -1 value.
* @param apdu [in] The apdu portion of the request, to be processed.
* @param apdu_len [in] The total (remaining) length of the apdu.
*/
static void routed_apdu_handler(
BACNET_ADDRESS * src,
BACNET_ADDRESS * dest,
int *DNET_list,
uint8_t * apdu,
uint16_t apdu_len)
static void routed_apdu_handler(BACNET_ADDRESS *src, BACNET_ADDRESS *dest,
int *DNET_list, uint8_t *apdu,
uint16_t apdu_len)
{
int cursor = 0; /* Starting hint */
int cursor = 0; /* Starting hint */
bool bGotOne = false;
if (!Routed_Device_Is_Valid_Network(dest->net, DNET_list)) {
@@ -220,8 +213,8 @@ static void routed_apdu_handler(
*/
if (dest->len > 0) {
Send_Reject_Message_To_Network(src, NETWORK_REJECT_NO_ROUTE,
dest->net);
} /* else, silently drop it */
dest->net);
} /* else, silently drop it */
return;
}
@@ -260,20 +253,17 @@ static void routed_apdu_handler(
* think this project's code has any use for the src info
* on return from this handler, since the response has
* already been sent via the apdu_handler.
* @param DNET_list [in] List of our reachable downstream BACnet Network numbers.
* Normally just one valid entry; terminated with a -1 value.
* @param DNET_list [in] List of our reachable downstream BACnet Network
* numbers. Normally just one valid entry; terminated with a -1 value.
* @param pdu [in] Buffer containing the NPDU and APDU of the received packet.
* @param pdu_len [in] The size of the received message in the pdu[] buffer.
*/
void routing_npdu_handler(
BACNET_ADDRESS * src,
int *DNET_list,
uint8_t * pdu,
uint16_t pdu_len)
void routing_npdu_handler(BACNET_ADDRESS *src, int *DNET_list, uint8_t *pdu,
uint16_t pdu_len)
{
int apdu_offset = 0;
BACNET_ADDRESS dest = { 0 };
BACNET_NPDU_DATA npdu_data = { 0 };
BACNET_ADDRESS dest = {0};
BACNET_NPDU_DATA npdu_data = {0};
/* only handle the version that we know how to handle */
if (pdu[0] == BACNET_PROTOCOL_VERSION) {
@@ -283,7 +273,8 @@ void routing_npdu_handler(
} else if (npdu_data.network_layer_message) {
if ((dest.net == 0) || (dest.net == BACNET_BROADCAST_NETWORK)) {
network_control_handler(src, DNET_list, &npdu_data,
&pdu[apdu_offset], (uint16_t) (pdu_len - apdu_offset));
&pdu[apdu_offset],
(uint16_t)(pdu_len - apdu_offset));
} else {
/* The DNET is set, but we don't support downstream routers,
* so we just silently drop this network layer message,
@@ -292,14 +283,14 @@ void routing_npdu_handler(
} else if (apdu_offset <= pdu_len) {
if ((dest.net == 0) || (npdu_data.hop_count > 1))
routed_apdu_handler(src, &dest, DNET_list, &pdu[apdu_offset],
(uint16_t) (pdu_len - apdu_offset));
(uint16_t)(pdu_len - apdu_offset));
/* Else, hop_count bottomed out and we discard this one. */
}
} else {
/* Should we send NETWORK_MESSAGE_REJECT_MESSAGE_TO_NETWORK? */
debug_printf
("NPDU: Unsupported BACnet Protocol Version=%u. Discarded!\n",
(unsigned) pdu[0]);
debug_printf(
"NPDU: Unsupported BACnet Protocol Version=%u. Discarded!\n",
(unsigned)pdu[0]);
}
return;
+44 -53
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* Copyright (C) 2005 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.
*
*********************************************************************/
*
* Copyright (C) 2005 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 <stdio.h>
@@ -44,7 +44,6 @@
/** @file h_rp.c Handles Read Property requests. */
/** Handler for a ReadProperty Service request.
* @ingroup DSRP
* This handler will be invoked by apdu_handler() if it has been enabled
@@ -64,11 +63,9 @@
* @param service_data [in] The BACNET_CONFIRMED_SERVICE_DATA information
* decoded from the APDU header of this message.
*/
void handler_read_property(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src,
BACNET_CONFIRMED_SERVICE_DATA * service_data)
void handler_read_property(uint8_t* service_request, uint16_t service_len,
BACNET_ADDRESS* src,
BACNET_CONFIRMED_SERVICE_DATA* service_data)
{
BACNET_READ_PROPERTY_DATA rpdata;
int len = 0;
@@ -76,7 +73,7 @@ void handler_read_property(
int apdu_len = -1;
int npdu_len = -1;
BACNET_NPDU_DATA npdu_data;
bool error = true; /* assume that there is an error */
bool error = true; /* assume that there is an error */
int bytes_sent = 0;
BACNET_ADDRESS my_address;
@@ -85,9 +82,8 @@ void handler_read_property(
/* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
npdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
npdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
if (service_data->segmented_message) {
/* we don't support segmentation - send an abort */
len = BACNET_STATUS_ABORT;
@@ -116,9 +112,8 @@ void handler_read_property(
rpdata.object_instance = Device_Object_Instance_Number();
}
apdu_len =
rp_ack_encode_apdu_init(&Handler_Transmit_Buffer[npdu_len],
service_data->invoke_id, &rpdata);
apdu_len = rp_ack_encode_apdu_init(&Handler_Transmit_Buffer[npdu_len],
service_data->invoke_id, &rpdata);
/* configure our storage */
rpdata.application_data = &Handler_Transmit_Buffer[npdu_len + apdu_len];
rpdata.application_data_len =
@@ -126,9 +121,8 @@ void handler_read_property(
len = Device_Read_Property(&rpdata);
if (len >= 0) {
apdu_len += len;
len =
rp_ack_encode_apdu_object_property_end(&Handler_Transmit_Buffer
[npdu_len + apdu_len]);
len = rp_ack_encode_apdu_object_property_end(
&Handler_Transmit_Buffer[npdu_len + apdu_len]);
apdu_len += len;
if (apdu_len > service_data->max_resp) {
/* too big for the sender - send an abort
@@ -160,28 +154,26 @@ void handler_read_property(
#endif
}
RP_FAILURE:
RP_FAILURE:
if (error) {
if (len == BACNET_STATUS_ABORT) {
apdu_len =
abort_encode_apdu(&Handler_Transmit_Buffer[npdu_len],
service_data->invoke_id,
apdu_len = abort_encode_apdu(
&Handler_Transmit_Buffer[npdu_len], service_data->invoke_id,
abort_convert_error_code(rpdata.error_code), true);
#if PRINT_ENABLED
fprintf(stderr, "RP: Sending Abort!\n");
#endif
} else if (len == BACNET_STATUS_ERROR) {
apdu_len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[npdu_len],
service_data->invoke_id, SERVICE_CONFIRMED_READ_PROPERTY,
rpdata.error_class, rpdata.error_code);
apdu_len = bacerror_encode_apdu(
&Handler_Transmit_Buffer[npdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_READ_PROPERTY, rpdata.error_class,
rpdata.error_code);
#if PRINT_ENABLED
fprintf(stderr, "RP: Sending Error!\n");
#endif
} else if (len == BACNET_STATUS_REJECT) {
apdu_len =
reject_encode_apdu(&Handler_Transmit_Buffer[npdu_len],
service_data->invoke_id,
apdu_len = reject_encode_apdu(
&Handler_Transmit_Buffer[npdu_len], service_data->invoke_id,
reject_convert_error_code(rpdata.error_code));
#if PRINT_ENABLED
fprintf(stderr, "RP: Sending Reject!\n");
@@ -190,9 +182,8 @@ void handler_read_property(
}
pdu_len = npdu_len + apdu_len;
bytes_sent =
datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
bytes_sent = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
if (bytes_sent <= 0) {
#if PRINT_ENABLED
fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno));
+40 -47
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* Copyright (C) 2005 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.
*
*********************************************************************/
*
* Copyright (C) 2005 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 <stdlib.h>
@@ -46,11 +46,10 @@
/** For debugging...
* @param [in] data portion of the ACK
*/
void rp_ack_print_data(
BACNET_READ_PROPERTY_DATA * data)
void rp_ack_print_data(BACNET_READ_PROPERTY_DATA *data)
{
BACNET_OBJECT_PROPERTY_VALUE object_value; /* for bacapp printing */
BACNET_APPLICATION_DATA_VALUE value; /* for decode value data */
BACNET_OBJECT_PROPERTY_VALUE object_value; /* for bacapp printing */
BACNET_APPLICATION_DATA_VALUE value; /* for decode value data */
int len = 0;
uint8_t *application_data;
int application_data_len;
@@ -63,9 +62,8 @@ void rp_ack_print_data(
/* FIXME: what if application_data_len is bigger than 255? */
/* value? need to loop until all of the len is gone... */
for (;;) {
len =
bacapp_decode_application_data(application_data,
(uint8_t) application_data_len, &value);
len = bacapp_decode_application_data(
application_data, (uint8_t)application_data_len, &value);
if (first_value && (len < application_data_len)) {
first_value = false;
#if PRINT_ENABLED
@@ -102,7 +100,6 @@ void rp_ack_print_data(
}
}
/** Handler for a ReadProperty ACK.
* @ingroup DSRP
* Doesn't actually do anything, except, for debugging, to
@@ -114,17 +111,15 @@ void rp_ack_print_data(
* @param service_data [in] The BACNET_CONFIRMED_SERVICE_DATA information
* decoded from the APDU header of this message.
*/
void handler_read_property_ack(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src,
BACNET_CONFIRMED_SERVICE_ACK_DATA * service_data)
void handler_read_property_ack(uint8_t *service_request, uint16_t service_len,
BACNET_ADDRESS *src,
BACNET_CONFIRMED_SERVICE_ACK_DATA *service_data)
{
int len = 0;
BACNET_READ_PROPERTY_DATA data;
(void) src;
(void) service_data; /* we could use these... */
(void)src;
(void)service_data; /* we could use these... */
len = rp_ack_decode_service_request(service_request, service_len, &data);
#if 0
fprintf(stderr, "Received Read-Property Ack!\n");
@@ -148,13 +143,11 @@ void handler_read_property_ack(
* or -1 on decoding error.
*/
int rp_ack_fully_decode_service_request(
uint8_t * apdu,
int apdu_len,
BACNET_READ_ACCESS_DATA * read_access_data)
uint8_t *apdu, int apdu_len, BACNET_READ_ACCESS_DATA *read_access_data)
{
int decoded_len = 0; /* return value */
int decoded_len = 0; /* return value */
BACNET_READ_PROPERTY_DATA rp1data;
BACNET_PROPERTY_REFERENCE *rp1_property; /* single property */
BACNET_PROPERTY_REFERENCE *rp1_property; /* single property */
BACNET_APPLICATION_DATA_VALUE *value, *old_value;
uint8_t *vdata;
int vlen, len;
@@ -174,7 +167,8 @@ int rp_ack_fully_decode_service_request(
}
rp1_property->propertyIdentifier = rp1data.object_property;
rp1_property->propertyArrayIndex = rp1data.array_index;
/* Is there no Error case possible here, as there is when decoding RPM? */
/* Is there no Error case possible here, as there is when decoding RPM?
*/
/* rp1_property->error.error_class = ?? */
/* rp_ack_decode_service_request() processing already removed the
* Opening and Closing '3' Tags.
@@ -187,9 +181,8 @@ int rp_ack_fully_decode_service_request(
old_value = value;
while (value && vdata && (vlen > 0)) {
if (IS_CONTEXT_SPECIFIC(*vdata)) {
len =
bacapp_decode_context_data(vdata, vlen, value,
rp1_property->propertyIdentifier);
len = bacapp_decode_context_data(
vdata, vlen, value, rp1_property->propertyIdentifier);
} else {
len = bacapp_decode_application_data(vdata, vlen, value);
}
+90 -112
View File
@@ -1,28 +1,28 @@
/**************************************************************************
*
* Copyright (C) 2007 Steve Karg <skarg@users.sourceforge.net>
* Inspired by John Stachler <John.Stachler@lennoxind.com>
*
* 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.
*
*********************************************************************/
*
* Copyright (C) 2007 Steve Karg <skarg@users.sourceforge.net>
* Inspired by John Stachler <John.Stachler@lennoxind.com>
*
* 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>
@@ -46,14 +46,13 @@
/** @file h_rpm.c Handles Read Property Multiple requests. */
static uint8_t Temp_Buf[MAX_APDU] = { 0 };
static uint8_t Temp_Buf[MAX_APDU] = {0};
static BACNET_PROPERTY_ID RPM_Object_Property(
struct special_property_list_t *pPropertyList,
BACNET_PROPERTY_ID special_property,
unsigned index)
BACNET_PROPERTY_ID special_property, unsigned index)
{
int property = -1; /* return value */
int property = -1; /* return value */
unsigned required, optional, proprietary;
required = pPropertyList->Required.count;
@@ -79,7 +78,7 @@ static BACNET_PROPERTY_ID RPM_Object_Property(
}
}
return (BACNET_PROPERTY_ID) property;
return (BACNET_PROPERTY_ID)property;
}
static unsigned RPM_Object_Property_Count(
@@ -89,9 +88,8 @@ static unsigned RPM_Object_Property_Count(
unsigned count = 0; /* return value */
if (special_property == PROP_ALL) {
count =
pPropertyList->Required.count + pPropertyList->Optional.count +
pPropertyList->Proprietary.count;
count = pPropertyList->Required.count + pPropertyList->Optional.count +
pPropertyList->Proprietary.count;
} else if (special_property == PROP_REQUIRED) {
count = pPropertyList->Required.count;
} else if (special_property == PROP_OPTIONAL) {
@@ -103,20 +101,16 @@ static unsigned RPM_Object_Property_Count(
/** Encode the RPM property returning the length of the encoding,
or 0 if there is no room to fit the encoding. */
static int RPM_Encode_Property(
uint8_t * apdu,
uint16_t offset,
uint16_t max_apdu,
BACNET_RPM_DATA * rpmdata)
static int RPM_Encode_Property(uint8_t *apdu, uint16_t offset,
uint16_t max_apdu, BACNET_RPM_DATA *rpmdata)
{
int len = 0;
size_t copy_len = 0;
int apdu_len = 0;
BACNET_READ_PROPERTY_DATA rpdata;
len =
rpm_ack_encode_apdu_object_property(&Temp_Buf[0],
rpmdata->object_property, rpmdata->array_index);
len = rpm_ack_encode_apdu_object_property(
&Temp_Buf[0], rpmdata->object_property, rpmdata->array_index);
copy_len = memcopy(&apdu[0], &Temp_Buf[0], offset, len, max_apdu);
if (copy_len == 0) {
rpmdata->error_code = ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED;
@@ -140,9 +134,8 @@ static int RPM_Encode_Property(
return len; /* Ie, Abort */
}
/* error was returned - encode that for the response */
len =
rpm_ack_encode_apdu_object_property_error(&Temp_Buf[0],
rpdata.error_class, rpdata.error_code);
len = rpm_ack_encode_apdu_object_property_error(
&Temp_Buf[0], rpdata.error_class, rpdata.error_code);
copy_len =
memcopy(&apdu[0], &Temp_Buf[0], offset + apdu_len, len, max_apdu);
@@ -152,9 +145,8 @@ static int RPM_Encode_Property(
}
} else if ((offset + apdu_len + 1 + len + 1) < max_apdu) {
/* enough room to fit the property value and tags */
len =
rpm_ack_encode_apdu_object_property_value(&apdu[offset + apdu_len],
&Temp_Buf[0], len);
len = rpm_ack_encode_apdu_object_property_value(
&apdu[offset + apdu_len], &Temp_Buf[0], len);
} else {
/* not enough room - abort! */
rpmdata->error_code = ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED;
@@ -175,8 +167,8 @@ static int RPM_Encode_Property(
* - if decoding fails
* - if the response would be too large
* - the result from each included read request, if it succeeds
* - an Error if processing fails for all, or individual errors if only some fail,
* or there isn't enough room in the APDU to fit the data.
* - an Error if processing fails for all, or individual errors if only some
* fail, or there isn't enough room in the APDU to fit the data.
*
* @param service_request [in] The contents of the service request.
* @param service_len [in] The length of the service_request.
@@ -184,11 +176,9 @@ static int RPM_Encode_Property(
* @param service_data [in] The BACNET_CONFIRMED_SERVICE_DATA information
* decoded from the APDU header of this message.
*/
void handler_read_property_multiple(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src,
BACNET_CONFIRMED_SERVICE_DATA * service_data)
void handler_read_property_multiple(uint8_t *service_request,
uint16_t service_len, BACNET_ADDRESS *src,
BACNET_CONFIRMED_SERVICE_DATA *service_data)
{
int len = 0;
uint16_t copy_len = 0;
@@ -203,13 +193,13 @@ void handler_read_property_multiple(
int error = 0;
/* jps_debug - see if we are utilizing all the buffer */
/* memset(&Handler_Transmit_Buffer[0], 0xff, sizeof(Handler_Transmit_Buffer)); */
/* memset(&Handler_Transmit_Buffer[0], 0xff,
* sizeof(Handler_Transmit_Buffer)); */
/* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
npdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
npdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
if (service_data->segmented_message) {
rpmdata.error_code = ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED;
error = BACNET_STATUS_ABORT;
@@ -220,14 +210,12 @@ void handler_read_property_multiple(
}
/* decode apdu request & encode apdu reply
encode complex ack, invoke id, service choice */
apdu_len =
rpm_ack_encode_apdu_init(&Handler_Transmit_Buffer[npdu_len],
service_data->invoke_id);
apdu_len = rpm_ack_encode_apdu_init(&Handler_Transmit_Buffer[npdu_len],
service_data->invoke_id);
for (;;) {
/* Start by looking for an object ID */
len =
rpm_decode_object_id(&service_request[decode_len],
service_len - decode_len, &rpmdata);
len = rpm_decode_object_id(&service_request[decode_len],
service_len - decode_len, &rpmdata);
if (len >= 0) {
/* Got one so skip to next stage */
decode_len += len;
@@ -248,9 +236,8 @@ void handler_read_property_multiple(
/* Stick this object id into the reply - if it will fit */
len = rpm_ack_encode_apdu_object_begin(&Temp_Buf[0], &rpmdata);
copy_len =
memcopy(&Handler_Transmit_Buffer[npdu_len], &Temp_Buf[0], apdu_len,
len, MAX_APDU);
copy_len = memcopy(&Handler_Transmit_Buffer[npdu_len], &Temp_Buf[0],
apdu_len, len, MAX_APDU);
if (copy_len == 0) {
#if PRINT_ENABLED
fprintf(stderr, "RPM: Response too big!\r\n");
@@ -266,7 +253,7 @@ void handler_read_property_multiple(
/* Fetch a property */
len =
rpm_decode_object_property(&service_request[decode_len],
service_len - decode_len, &rpmdata);
service_len - decode_len, &rpmdata);
if (len < 0) {
/* bad encoding - skip to error/reject/abort handling */
#if PRINT_ENABLED
@@ -288,16 +275,15 @@ void handler_read_property_multiple(
if (rpmdata.array_index != BACNET_ARRAY_ALL) {
/* No array index options for this special property.
Encode error for this object property response */
len =
rpm_ack_encode_apdu_object_property(&Temp_Buf[0],
rpmdata.object_property, rpmdata.array_index);
copy_len =
memcopy(&Handler_Transmit_Buffer[npdu_len],
&Temp_Buf[0], apdu_len, len, MAX_APDU);
len = rpm_ack_encode_apdu_object_property(
&Temp_Buf[0], rpmdata.object_property,
rpmdata.array_index);
copy_len = memcopy(&Handler_Transmit_Buffer[npdu_len],
&Temp_Buf[0], apdu_len, len, MAX_APDU);
if (copy_len == 0) {
#if PRINT_ENABLED
fprintf(stderr,
"RPM: Too full to encode property!\r\n");
"RPM: Too full to encode property!\r\n");
#endif
rpmdata.error_code =
ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED;
@@ -305,13 +291,11 @@ void handler_read_property_multiple(
goto RPM_FAILURE;
}
apdu_len += len;
len =
rpm_ack_encode_apdu_object_property_error(&Temp_Buf[0],
ERROR_CLASS_PROPERTY,
len = rpm_ack_encode_apdu_object_property_error(
&Temp_Buf[0], ERROR_CLASS_PROPERTY,
ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY);
copy_len =
memcopy(&Handler_Transmit_Buffer[npdu_len],
&Temp_Buf[0], apdu_len, len, MAX_APDU);
copy_len = memcopy(&Handler_Transmit_Buffer[npdu_len],
&Temp_Buf[0], apdu_len, len, MAX_APDU);
if (copy_len == 0) {
#if PRINT_ENABLED
fprintf(stderr, "RPM: Too full to encode error!\r\n");
@@ -325,10 +309,10 @@ void handler_read_property_multiple(
} else {
special_object_property = rpmdata.object_property;
Device_Objects_Property_List(rpmdata.object_type,
rpmdata.object_instance, &property_list);
property_count =
RPM_Object_Property_Count(&property_list,
special_object_property);
rpmdata.object_instance,
&property_list);
property_count = RPM_Object_Property_Count(
&property_list, special_object_property);
if (property_count == 0) {
/* this only happens with the OPTIONAL property */
/* 135-2016bl-2. Clarify ReadPropertyMultiple
@@ -338,19 +322,17 @@ void handler_read_property_multiple(
for the specified property.*/
} else {
for (index = 0; index < property_count; index++) {
rpmdata.object_property =
RPM_Object_Property(&property_list,
special_object_property, index);
len =
RPM_Encode_Property(&Handler_Transmit_Buffer
[npdu_len], (uint16_t) apdu_len, MAX_APDU,
&rpmdata);
rpmdata.object_property = RPM_Object_Property(
&property_list, special_object_property, index);
len = RPM_Encode_Property(
&Handler_Transmit_Buffer[npdu_len],
(uint16_t)apdu_len, MAX_APDU, &rpmdata);
if (len > 0) {
apdu_len += len;
} else {
#if PRINT_ENABLED
fprintf(stderr,
"RPM: Too full for property!\r\n");
"RPM: Too full for property!\r\n");
#endif
error = len;
goto RPM_FAILURE;
@@ -362,13 +344,13 @@ void handler_read_property_multiple(
/* handle an individual property */
len =
RPM_Encode_Property(&Handler_Transmit_Buffer[npdu_len],
(uint16_t) apdu_len, MAX_APDU, &rpmdata);
(uint16_t)apdu_len, MAX_APDU, &rpmdata);
if (len > 0) {
apdu_len += len;
} else {
#if PRINT_ENABLED
fprintf(stderr,
"RPM: Too full for individual property!\r\n");
"RPM: Too full for individual property!\r\n");
#endif
error = len;
goto RPM_FAILURE;
@@ -378,9 +360,8 @@ void handler_read_property_multiple(
/* Reached end of property list so cap the result list */
decode_len++;
len = rpm_ack_encode_apdu_object_end(&Temp_Buf[0]);
copy_len =
memcopy(&Handler_Transmit_Buffer[npdu_len], &Temp_Buf[0],
apdu_len, len, MAX_APDU);
copy_len = memcopy(&Handler_Transmit_Buffer[npdu_len],
&Temp_Buf[0], apdu_len, len, MAX_APDU);
if (copy_len == 0) {
#if PRINT_ENABLED
fprintf(stderr, "RPM: Too full to encode object end!\r\n");
@@ -392,7 +373,7 @@ void handler_read_property_multiple(
} else {
apdu_len += copy_len;
}
break; /* finished with this property list */
break; /* finished with this property list */
}
}
if (decode_len >= service_len) {
@@ -411,28 +392,26 @@ void handler_read_property_multiple(
goto RPM_FAILURE;
}
RPM_FAILURE:
RPM_FAILURE:
if (error) {
if (error == BACNET_STATUS_ABORT) {
apdu_len =
abort_encode_apdu(&Handler_Transmit_Buffer[npdu_len],
service_data->invoke_id,
apdu_len = abort_encode_apdu(
&Handler_Transmit_Buffer[npdu_len], service_data->invoke_id,
abort_convert_error_code(rpmdata.error_code), true);
#if PRINT_ENABLED
fprintf(stderr, "RPM: Sending Abort!\n");
#endif
} else if (error == BACNET_STATUS_ERROR) {
apdu_len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[npdu_len],
service_data->invoke_id, SERVICE_CONFIRMED_READ_PROP_MULTIPLE,
rpmdata.error_class, rpmdata.error_code);
apdu_len = bacerror_encode_apdu(
&Handler_Transmit_Buffer[npdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_READ_PROP_MULTIPLE, rpmdata.error_class,
rpmdata.error_code);
#if PRINT_ENABLED
fprintf(stderr, "RPM: Sending Error!\n");
#endif
} else if (error == BACNET_STATUS_REJECT) {
apdu_len =
reject_encode_apdu(&Handler_Transmit_Buffer[npdu_len],
service_data->invoke_id,
apdu_len = reject_encode_apdu(
&Handler_Transmit_Buffer[npdu_len], service_data->invoke_id,
reject_convert_error_code(rpmdata.error_code));
#if PRINT_ENABLED
fprintf(stderr, "RPM: Sending Reject!\n");
@@ -441,9 +420,8 @@ void handler_read_property_multiple(
}
pdu_len = apdu_len + npdu_len;
bytes_sent =
datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
bytes_sent = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
if (bytes_sent <= 0) {
#if PRINT_ENABLED
fprintf(stderr, "RPM: Failed to send PDU (%s)!\n", strerror(errno));
+55 -64
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* Copyright (C) 2008 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.
*
*********************************************************************/
*
* Copyright (C) 2008 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 <stdlib.h>
@@ -53,16 +53,14 @@
* where the RPM data is to be stored.
* @return The number of bytes decoded, or -1 on error
*/
int rpm_ack_decode_service_request(
uint8_t * apdu,
int apdu_len,
BACNET_READ_ACCESS_DATA * read_access_data)
int rpm_ack_decode_service_request(uint8_t *apdu, int apdu_len,
BACNET_READ_ACCESS_DATA *read_access_data)
{
int decoded_len = 0; /* return value */
uint32_t error_value = 0; /* decoded error value */
int len = 0; /* number of bytes returned from decoding */
uint8_t tag_number = 0; /* decoded tag number */
uint32_t len_value = 0; /* decoded length value */
int decoded_len = 0; /* return value */
uint32_t error_value = 0; /* decoded error value */
int len = 0; /* number of bytes returned from decoding */
uint8_t tag_number = 0; /* decoded tag number */
uint32_t len_value = 0; /* decoded length value */
BACNET_READ_ACCESS_DATA *rpm_object;
BACNET_READ_ACCESS_DATA *old_rpm_object;
BACNET_PROPERTY_REFERENCE *rpm_property;
@@ -74,9 +72,8 @@ int rpm_ack_decode_service_request(
rpm_object = read_access_data;
old_rpm_object = rpm_object;
while (rpm_object && apdu_len) {
len =
rpm_ack_decode_object_id(apdu, apdu_len, &rpm_object->object_type,
&rpm_object->object_instance);
len = rpm_ack_decode_object_id(apdu, apdu_len, &rpm_object->object_type,
&rpm_object->object_instance);
if (len <= 0) {
old_rpm_object->next = NULL;
free(rpm_object);
@@ -89,9 +86,8 @@ int rpm_ack_decode_service_request(
rpm_object->listOfProperties = rpm_property;
old_rpm_property = rpm_property;
while (rpm_property && apdu_len) {
len =
rpm_ack_decode_object_property(apdu, apdu_len,
&rpm_property->propertyIdentifier,
len = rpm_ack_decode_object_property(
apdu, apdu_len, &rpm_property->propertyIdentifier,
&rpm_property->propertyArrayIndex);
if (len <= 0) {
old_rpm_property->next = NULL;
@@ -117,13 +113,12 @@ int rpm_ack_decode_service_request(
old_value = value;
while (value && (apdu_len > 0)) {
if (IS_CONTEXT_SPECIFIC(*apdu)) {
len =
bacapp_decode_context_data(apdu, apdu_len, value,
len = bacapp_decode_context_data(
apdu, apdu_len, value,
rpm_property->propertyIdentifier);
} else {
len =
bacapp_decode_application_data(apdu, apdu_len,
value);
len = bacapp_decode_application_data(apdu, apdu_len,
value);
}
/* If len == 0 then it's an empty structure, which is OK. */
if (len < 0) {
@@ -201,10 +196,9 @@ int rpm_ack_decode_service_request(
}
/* for debugging... */
void rpm_ack_print_data(
BACNET_READ_ACCESS_DATA * rpm_data)
void rpm_ack_print_data(BACNET_READ_ACCESS_DATA *rpm_data)
{
BACNET_OBJECT_PROPERTY_VALUE object_value; /* for bacapp printing */
BACNET_OBJECT_PROPERTY_VALUE object_value; /* for bacapp printing */
BACNET_PROPERTY_REFERENCE *listOfProperties;
BACNET_APPLICATION_DATA_VALUE *value;
bool array_value = false;
@@ -212,8 +206,8 @@ void rpm_ack_print_data(
if (rpm_data) {
#if PRINT_ENABLED
fprintf(stdout, "%s #%lu\r\n",
bactext_object_type_name(rpm_data->object_type),
(unsigned long) rpm_data->object_instance);
bactext_object_type_name(rpm_data->object_type),
(unsigned long)rpm_data->object_instance);
fprintf(stdout, "{\r\n");
#endif
listOfProperties = rpm_data->listOfProperties;
@@ -221,11 +215,11 @@ void rpm_ack_print_data(
#if PRINT_ENABLED
if (listOfProperties->propertyIdentifier < 512) {
fprintf(stdout, " %s: ",
bactext_property_name(listOfProperties->
propertyIdentifier));
bactext_property_name(
listOfProperties->propertyIdentifier));
} else {
fprintf(stdout, " proprietary %u: ",
(unsigned) listOfProperties->propertyIdentifier);
(unsigned)listOfProperties->propertyIdentifier);
}
#endif
if (listOfProperties->propertyArrayIndex != BACNET_ARRAY_ALL) {
@@ -269,10 +263,10 @@ void rpm_ack_print_data(
#if PRINT_ENABLED
/* AccessError */
fprintf(stdout, "BACnet Error: %s: %s\r\n",
bactext_error_class_name((int) listOfProperties->
error.error_class),
bactext_error_code_name((int) listOfProperties->
error.error_code));
bactext_error_class_name(
(int)listOfProperties->error.error_class),
bactext_error_code_name(
(int)listOfProperties->error.error_code));
#endif
}
listOfProperties = listOfProperties->next;
@@ -295,10 +289,8 @@ void rpm_ack_print_data(
* decoded from the APDU header of this message.
*/
void handler_read_property_multiple_ack(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src,
BACNET_CONFIRMED_SERVICE_ACK_DATA * service_data)
uint8_t *service_request, uint16_t service_len, BACNET_ADDRESS *src,
BACNET_CONFIRMED_SERVICE_ACK_DATA *service_data)
{
int len = 0;
BACNET_READ_ACCESS_DATA *rpm_data;
@@ -308,14 +300,13 @@ void handler_read_property_multiple_ack(
BACNET_APPLICATION_DATA_VALUE *value;
BACNET_APPLICATION_DATA_VALUE *old_value;
(void) src;
(void) service_data; /* we could use these... */
(void)src;
(void)service_data; /* we could use these... */
rpm_data = calloc(1, sizeof(BACNET_READ_ACCESS_DATA));
if (rpm_data) {
len =
rpm_ack_decode_service_request(service_request, service_len,
rpm_data);
len = rpm_ack_decode_service_request(service_request, service_len,
rpm_data);
}
#if 1
fprintf(stderr, "Received Read-Property-Multiple Ack!\n");
+72 -68
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* Copyright (C) 2009 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.
*
*********************************************************************/
*
* Copyright (C) 2009 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 <stdio.h>
@@ -41,13 +41,11 @@
/** @file h_rr.c Handles Read Range requests. */
static uint8_t Temp_Buf[MAX_APDU] = { 0 };
static uint8_t Temp_Buf[MAX_APDU] = {0};
/* Encodes the property APDU and returns the length,
or sets the error, and returns -1 */
static int Encode_RR_payload(
uint8_t * apdu,
BACNET_READ_RANGE_DATA * pRequest)
static int Encode_RR_payload(uint8_t* apdu, BACNET_READ_RANGE_DATA* pRequest)
{
int apdu_len = -1;
rr_info_function info_fn_ptr = NULL;
@@ -61,37 +59,48 @@ static int Encode_RR_payload(
info_fn_ptr = Device_Objects_RR_Info(pRequest->object_type);
if ((info_fn_ptr != NULL) && (info_fn_ptr(pRequest, &PropInfo) != false)) {
/* We try and do some of the more generic error checking here to cut down on duplication of effort */
/* We try and do some of the more generic error checking here to cut
* down on duplication of effort */
if ((pRequest->RequestType == RR_BY_POSITION) && (pRequest->Range.RefIndex == 0)) { /* First index is 1 so can't accept 0 */
pRequest->error_code = ERROR_CODE_OTHER; /* I couldn't see anything more appropriate so... */
if ((pRequest->RequestType == RR_BY_POSITION) &&
(pRequest->Range.RefIndex ==
0)) { /* First index is 1 so can't accept 0 */
pRequest->error_code =
ERROR_CODE_OTHER; /* I couldn't see anything more appropriate
so... */
} else if (((PropInfo.RequestTypes & RR_ARRAY_OF_LISTS) == 0) &&
(pRequest->array_index != 0) &&
(pRequest->array_index != BACNET_ARRAY_ALL)) {
(pRequest->array_index != 0) &&
(pRequest->array_index != BACNET_ARRAY_ALL)) {
/* Array access attempted on a non array property */
pRequest->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY;
} else if ((pRequest->RequestType != RR_READ_ALL) &&
((PropInfo.RequestTypes & pRequest->RequestType) == 0)) {
/* By Time or By Sequence not supported - By Position is always required */
pRequest->error_code = ERROR_CODE_OTHER; /* I couldn't see anything more appropriate so... */
} else if ((pRequest->Count == 0) && (pRequest->RequestType != RR_READ_ALL)) { /* Count cannot be zero */
pRequest->error_code = ERROR_CODE_OTHER; /* I couldn't see anything more appropriate so... */
((PropInfo.RequestTypes & pRequest->RequestType) == 0)) {
/* By Time or By Sequence not supported - By Position is always
* required */
pRequest->error_code =
ERROR_CODE_OTHER; /* I couldn't see anything more appropriate
so... */
} else if ((pRequest->Count == 0) &&
(pRequest->RequestType !=
RR_READ_ALL)) { /* Count cannot be zero */
pRequest->error_code =
ERROR_CODE_OTHER; /* I couldn't see anything more appropriate
so... */
} else if (PropInfo.Handler != NULL) {
apdu_len = PropInfo.Handler(apdu, pRequest);
}
} else {
/* Either we don't support RR for this property yet or it is not a list or array of lists */
/* Either we don't support RR for this property yet or it is not a list
* or array of lists */
pRequest->error_code = ERROR_CODE_PROPERTY_IS_NOT_A_LIST;
}
return apdu_len;
}
void handler_read_range(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src,
BACNET_CONFIRMED_SERVICE_DATA * service_data)
void handler_read_range(uint8_t* service_request, uint16_t service_len,
BACNET_ADDRESS* src,
BACNET_CONFIRMED_SERVICE_DATA* service_data)
{
BACNET_READ_RANGE_DATA data;
int len = 0;
@@ -106,21 +115,19 @@ void handler_read_range(
/* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
if (service_data->segmented_message) {
/* we don't support segmentation - send an abort */
len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
true);
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
#if PRINT_ENABLED
fprintf(stderr, "RR: Segmented message. Sending Abort!\n");
#endif
goto RR_ABORT;
}
memset(&data, 0, sizeof(data)); /* start with blank canvas */
memset(&data, 0, sizeof(data)); /* start with blank canvas */
len = rr_decode_service_request(service_request, service_len, &data);
#if PRINT_ENABLED
if (len <= 0)
@@ -128,9 +135,9 @@ void handler_read_range(
#endif
if (len < 0) {
/* bad decoding - send an abort */
len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_OTHER, true);
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_OTHER,
true);
#if PRINT_ENABLED
fprintf(stderr, "RR: Bad Encoding. Sending Abort!\n");
#endif
@@ -145,9 +152,8 @@ void handler_read_range(
data.application_data = &Temp_Buf[0];
data.application_data_len = len;
/* FIXME: probably need a length limitation sent with encode */
len =
rr_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, &data);
len = rr_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, &data);
#if PRINT_ENABLED
fprintf(stderr, "RR: Sending Ack!\n");
#endif
@@ -156,28 +162,26 @@ void handler_read_range(
if (error) {
if (len == -2) {
/* BACnet APDU too small to fit data, so proper response is Abort */
len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
#if PRINT_ENABLED
fprintf(stderr, "RR: Reply too big to fit into APDU!\n");
#endif
} else {
len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, SERVICE_CONFIRMED_READ_RANGE,
data.error_class, data.error_code);
len = bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
SERVICE_CONFIRMED_READ_RANGE,
data.error_class, data.error_code);
#if PRINT_ENABLED
fprintf(stderr, "RR: Sending Error!\n");
#endif
}
}
RR_ABORT:
RR_ABORT:
pdu_len += len;
bytes_sent =
datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
bytes_sent = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0)
fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno));
+33 -37
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* Copyright (C) 2009 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.
*
*********************************************************************/
*
* Copyright (C) 2009 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 "config.h"
@@ -43,11 +43,10 @@
/** @file h_rr_a.c Handles Read Range Acknowledgments. */
/* for debugging... */
static void PrintReadRangeData(
BACNET_READ_RANGE_DATA * data)
static void PrintReadRangeData(BACNET_READ_RANGE_DATA *data)
{
BACNET_OBJECT_PROPERTY_VALUE object_value; /* for bacapp printing */
BACNET_APPLICATION_DATA_VALUE value; /* for decode value data */
BACNET_OBJECT_PROPERTY_VALUE object_value; /* for bacapp printing */
BACNET_APPLICATION_DATA_VALUE value; /* for decode value data */
int len = 0;
uint8_t *application_data;
int application_data_len;
@@ -60,9 +59,8 @@ static void PrintReadRangeData(
/* FIXME: what if application_data_len is bigger than 255? */
/* value? need to loop until all of the len is gone... */
for (;;) {
len =
bacapp_decode_application_data(application_data,
(uint8_t) application_data_len, &value);
len = bacapp_decode_application_data(
application_data, (uint8_t)application_data_len, &value);
if (first_value && (len < application_data_len)) {
first_value = false;
#if PRINT_ENABLED
@@ -99,17 +97,15 @@ static void PrintReadRangeData(
}
}
void handler_read_range_ack(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src,
BACNET_CONFIRMED_SERVICE_ACK_DATA * service_data)
void handler_read_range_ack(uint8_t *service_request, uint16_t service_len,
BACNET_ADDRESS *src,
BACNET_CONFIRMED_SERVICE_ACK_DATA *service_data)
{
int len = 0;
BACNET_READ_RANGE_DATA data;
(void) src;
(void) service_data; /* we could use these... */
(void)src;
(void)service_data; /* we could use these... */
len = rr_ack_decode_service_request(service_request, service_len, &data);
#if PRINT_ENABLED
+64 -82
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* 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.
*
*********************************************************************/
*
* 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 <stdio.h>
@@ -49,37 +49,32 @@ static BACNET_DATE_TIME Next_Sync_Time;
#endif
#if PRINT_ENABLED
static void show_bacnet_date_time(
BACNET_DATE * bdate,
BACNET_TIME * btime)
static void show_bacnet_date_time(BACNET_DATE *bdate, BACNET_TIME *btime)
{
/* show the date received */
fprintf(stderr, "%u", (unsigned) bdate->year);
fprintf(stderr, "/%u", (unsigned) bdate->month);
fprintf(stderr, "/%u", (unsigned) bdate->day);
fprintf(stderr, "%u", (unsigned)bdate->year);
fprintf(stderr, "/%u", (unsigned)bdate->month);
fprintf(stderr, "/%u", (unsigned)bdate->day);
/* show the time received */
fprintf(stderr, " %02u", (unsigned) btime->hour);
fprintf(stderr, ":%02u", (unsigned) btime->min);
fprintf(stderr, ":%02u", (unsigned) btime->sec);
fprintf(stderr, ".%02u", (unsigned) btime->hundredths);
fprintf(stderr, " %02u", (unsigned)btime->hour);
fprintf(stderr, ":%02u", (unsigned)btime->min);
fprintf(stderr, ":%02u", (unsigned)btime->sec);
fprintf(stderr, ".%02u", (unsigned)btime->hundredths);
fprintf(stderr, "\r\n");
}
#endif
void handler_timesync(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src)
void handler_timesync(uint8_t *service_request, uint16_t service_len,
BACNET_ADDRESS *src)
{
int len = 0;
BACNET_DATE bdate = {0};
BACNET_TIME btime = {0};
(void) src;
(void) service_len;
len =
timesync_decode_service_request(service_request, service_len, &bdate,
&btime);
(void)src;
(void)service_len;
len = timesync_decode_service_request(service_request, service_len, &bdate,
&btime);
if (len > 0) {
if (datetime_is_valid(&bdate, &btime)) {
/* fixme: only set the time if off by some amount */
@@ -96,20 +91,17 @@ void handler_timesync(
return;
}
void handler_timesync_utc(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src)
void handler_timesync_utc(uint8_t *service_request, uint16_t service_len,
BACNET_ADDRESS *src)
{
int len = 0;
BACNET_DATE bdate;
BACNET_TIME btime;
(void) src;
(void) service_len;
len =
timesync_decode_service_request(service_request, service_len, &bdate,
&btime);
(void)src;
(void)service_len;
len = timesync_decode_service_request(service_request, service_len, &bdate,
&btime);
if (len > 0) {
if (datetime_is_valid(&bdate, &btime)) {
#if PRINT_ENABLED
@@ -138,18 +130,15 @@ void handler_timesync_utc(
* @return How many bytes were encoded in the buffer, or
* BACNET_STATUS_ABORT if the response would not fit within the buffer.
*/
int handler_timesync_encode_recipients(
uint8_t * apdu,
int max_apdu)
int handler_timesync_encode_recipients(uint8_t *apdu, int max_apdu)
{
return timesync_encode_timesync_recipients(apdu, max_apdu,
&Time_Sync_Recipients[0]);
&Time_Sync_Recipients[0]);
}
#endif
#if defined(BACNET_TIME_MASTER)
bool handler_timesync_recipient_write(
BACNET_WRITE_PROPERTY_DATA * wp_data)
bool handler_timesync_recipient_write(BACNET_WRITE_PROPERTY_DATA *wp_data)
{
bool status = false;
@@ -162,8 +151,7 @@ bool handler_timesync_recipient_write(
#endif
#if defined(BACNET_TIME_MASTER)
static void handler_timesync_send(
BACNET_DATE_TIME * current_date_time)
static void handler_timesync_send(BACNET_DATE_TIME *current_date_time)
{
unsigned index = 0;
bool status = false;
@@ -171,10 +159,9 @@ static void handler_timesync_send(
for (index = 0; index < MAX_TIME_SYNC_RECIPIENTS; index++) {
if (Time_Sync_Recipients[index].tag == 1) {
if (status) {
Send_TimeSync_Remote(
&Time_Sync_Recipients[index].type.address,
&current_date_time->date,
&current_date_time->time);
Send_TimeSync_Remote(&Time_Sync_Recipients[index].type.address,
&current_date_time->date,
&current_date_time->time);
}
}
}
@@ -182,9 +169,8 @@ static void handler_timesync_send(
#endif
#if defined(BACNET_TIME_MASTER)
static void handler_timesync_update(
uint32_t device_interval,
BACNET_DATE_TIME * current_date_time)
static void handler_timesync_update(uint32_t device_interval,
BACNET_DATE_TIME *current_date_time)
{
uint32_t current_minutes = 0;
uint32_t next_minutes = 0;
@@ -207,7 +193,7 @@ static void handler_timesync_update(
/* Interval_Minutes = 1 2 3 4 5 6 10 12 15 20 30 60 */
/* determine next interval */
current_minutes = Next_Sync_Time.time.min;
interval = current_minutes/device_interval;
interval = current_minutes / device_interval;
interval++;
next_minutes = interval * device_interval;
offset_minutes = interval_offset % device_interval;
@@ -223,7 +209,7 @@ static void handler_timesync_update(
144 160 180 240 288 360 480 720 1440 */
current_minutes =
datetime_minutes_since_midnight(&Next_Sync_Time.time);
interval = current_minutes/device_interval;
interval = current_minutes / device_interval;
interval++;
next_minutes = interval * device_interval;
offset_minutes = interval_offset % device_interval;
@@ -242,17 +228,14 @@ static void handler_timesync_update(
#endif
#if defined(BACNET_TIME_MASTER)
bool handler_timesync_recipient_address_set(
unsigned index,
BACNET_ADDRESS *address)
bool handler_timesync_recipient_address_set(unsigned index,
BACNET_ADDRESS *address)
{
bool status = false;
if (address && (index < MAX_TIME_SYNC_RECIPIENTS)) {
Time_Sync_Recipients[index].tag = 1;
bacnet_address_copy(
&Time_Sync_Recipients[index].type.address,
address);
bacnet_address_copy(&Time_Sync_Recipients[index].type.address, address);
status = true;
}
@@ -261,8 +244,7 @@ bool handler_timesync_recipient_address_set(
#endif
#if defined(BACNET_TIME_MASTER)
void handler_timesync_task(
BACNET_DATE_TIME * current_date_time)
void handler_timesync_task(BACNET_DATE_TIME *current_date_time)
{
int compare = 0;
uint32_t device_interval = 0;
@@ -270,9 +252,9 @@ void handler_timesync_task(
device_interval = Device_Time_Sync_Interval();
if (device_interval) {
compare = datetime_compare(current_date_time, &Next_Sync_Time);
/* if the date/times are the same, return is 0
if date1 is before date2, returns negative
if date1 is after date2, returns positive */
/* if the date/times are the same, return is 0
if date1 is before date2, returns negative
if date1 is after date2, returns positive */
if (compare >= 0) {
handler_timesync_update(device_interval, current_date_time);
handler_timesync_send(current_date_time);
@@ -287,9 +269,9 @@ void handler_timesync_init(void)
unsigned i = 0;
/* connect linked list */
for (; i < (MAX_TIME_SYNC_RECIPIENTS-1); i++) {
Time_Sync_Recipients[i].next = &Time_Sync_Recipients[i+1];
Time_Sync_Recipients[i+1].next = NULL;
for (; i < (MAX_TIME_SYNC_RECIPIENTS - 1); i++) {
Time_Sync_Recipients[i].next = &Time_Sync_Recipients[i + 1];
Time_Sync_Recipients[i + 1].next = NULL;
}
for (i = 0; i < MAX_TIME_SYNC_RECIPIENTS; i++) {
Time_Sync_Recipients[i].tag = 0xFF;
+33 -35
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* Copyright (C) 2008 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.
*
*********************************************************************/
*
* Copyright (C) 2008 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 <stdio.h>
@@ -57,10 +57,8 @@
* @param service_len [in] The length of the service_request.
* @param src [in] BACNET_ADDRESS of the source of the message (unused)
*/
void handler_ucov_notification(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src)
void handler_ucov_notification(uint8_t *service_request, uint16_t service_len,
BACNET_ADDRESS *src)
{
BACNET_COV_DATA cov_data;
BACNET_PROPERTY_VALUE property_value[MAX_COV_PROPERTIES];
@@ -77,14 +75,14 @@ void handler_ucov_notification(
fprintf(stderr, "UCOV: Received Notification!\n");
#endif
/* decode the service request only */
len =
cov_notify_decode_service_request(service_request, service_len,
&cov_data);
len = cov_notify_decode_service_request(service_request, service_len,
&cov_data);
#if PRINT_ENABLED
if (len > 0) {
fprintf(stderr, "UCOV: PID=%u ", cov_data.subscriberProcessIdentifier);
fprintf(stderr, "instance=%u ", cov_data.initiatingDeviceIdentifier);
fprintf(stderr, "%s %u ",
fprintf(
stderr, "%s %u ",
bactext_object_type_name(cov_data.monitoredObjectIdentifier.type),
cov_data.monitoredObjectIdentifier.instance);
fprintf(stderr, "time remaining=%u seconds ", cov_data.timeRemaining);
@@ -93,12 +91,12 @@ void handler_ucov_notification(
while (pProperty_value) {
fprintf(stderr, "UCOV: ");
if (pProperty_value->propertyIdentifier < 512) {
fprintf(stderr, "%s ",
bactext_property_name
(pProperty_value->propertyIdentifier));
fprintf(
stderr, "%s ",
bactext_property_name(pProperty_value->propertyIdentifier));
} else {
fprintf(stderr, "proprietary %u ",
pProperty_value->propertyIdentifier);
pProperty_value->propertyIdentifier);
}
if (pProperty_value->propertyArrayIndex != BACNET_ARRAY_ALL) {
fprintf(stderr, "%u ", pProperty_value->propertyArrayIndex);
+35 -39
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* Copyright (C) 2009 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.
*
*********************************************************************/
*
* Copyright (C) 2009 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 <stdio.h>
@@ -39,11 +39,10 @@
/** @file h_upt.c Handles Unconfirmed Private Transfer requests. */
void private_transfer_print_data(
BACNET_PRIVATE_TRANSFER_DATA *private_data)
void private_transfer_print_data(BACNET_PRIVATE_TRANSFER_DATA *private_data)
{
BACNET_OBJECT_PROPERTY_VALUE object_value; /* for bacapp printing */
BACNET_APPLICATION_DATA_VALUE value; /* for decode value data */
BACNET_OBJECT_PROPERTY_VALUE object_value; /* for bacapp printing */
BACNET_APPLICATION_DATA_VALUE value; /* for decode value data */
int len = 0;
uint8_t *application_data;
int application_data_len;
@@ -53,16 +52,15 @@ void private_transfer_print_data(
if (private_data) {
#if PRINT_ENABLED
printf("PrivateTransfer:vendorID=%u\r\n",
(unsigned) private_data->vendorID);
(unsigned)private_data->vendorID);
printf("PrivateTransfer:serviceNumber=%lu\r\n",
(unsigned long) private_data->serviceNumber);
(unsigned long)private_data->serviceNumber);
#endif
application_data = private_data->serviceParameters;
application_data_len = private_data->serviceParametersLen;
for (;;) {
len =
bacapp_decode_application_data(application_data,
(uint8_t) application_data_len, &value);
len = bacapp_decode_application_data(
application_data, (uint8_t)application_data_len, &value);
if (first_value && (len < application_data_len)) {
first_value = false;
#if PRINT_ENABLED
@@ -101,10 +99,9 @@ void private_transfer_print_data(
}
}
void handler_unconfirmed_private_transfer(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src)
void handler_unconfirmed_private_transfer(uint8_t *service_request,
uint16_t service_len,
BACNET_ADDRESS *src)
{
BACNET_PRIVATE_TRANSFER_DATA private_data;
int len = 0;
@@ -112,9 +109,8 @@ void handler_unconfirmed_private_transfer(
#if PRINT_ENABLED
fprintf(stderr, "Received Unconfirmed Private Transfer Request!\n");
#endif
len =
ptransfer_decode_service_request(service_request, service_len,
&private_data);
len = ptransfer_decode_service_request(service_request, service_len,
&private_data);
if (len >= 0) {
private_transfer_print_data(&private_data);
}
+53 -57
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* 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.
*
*********************************************************************/
*
* 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 <stdio.h>
@@ -42,8 +42,7 @@
* or object ID, if the Device has a match.
* @param data [in] The decoded who-has payload from the request.
*/
static void match_name_or_object(
BACNET_WHO_HAS_DATA * data)
static void match_name_or_object(BACNET_WHO_HAS_DATA* data)
{
int object_type = 0;
uint32_t object_instance = 0;
@@ -54,29 +53,26 @@ static void match_name_or_object(
note: we should have only 1 of such an object */
if (data->is_object_name) {
/* valid name in my device? */
found =
Device_Valid_Object_Name(&data->object.name, &object_type,
&object_instance);
found = Device_Valid_Object_Name(&data->object.name, &object_type,
&object_instance);
if (found) {
Send_I_Have(Device_Object_Instance_Number(),
(BACNET_OBJECT_TYPE) object_type, object_instance,
&data->object.name);
(BACNET_OBJECT_TYPE)object_type, object_instance,
&data->object.name);
}
} else {
/* valid object_name copy in my device? */
found =
Device_Object_Name_Copy((BACNET_OBJECT_TYPE) data->
object.identifier.type, data->object.identifier.instance,
&object_name);
found = Device_Object_Name_Copy(
(BACNET_OBJECT_TYPE)data->object.identifier.type,
data->object.identifier.instance, &object_name);
if (found) {
Send_I_Have(Device_Object_Instance_Number(),
(BACNET_OBJECT_TYPE) data->object.identifier.type,
data->object.identifier.instance, &object_name);
(BACNET_OBJECT_TYPE)data->object.identifier.type,
data->object.identifier.instance, &object_name);
}
}
}
/** Handler for Who-Has requests, with broadcast I-Have response.
* Will respond if the device Object ID matches, and we have
* the Object or Object Name requested.
@@ -86,22 +82,21 @@ static void match_name_or_object(
* @param service_len [in] Length of the service_request message.
* @param src [in] The BACNET_ADDRESS of the message's source.
*/
void handler_who_has(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src)
void handler_who_has(uint8_t* service_request, uint16_t service_len,
BACNET_ADDRESS* src)
{
int len = 0;
BACNET_WHO_HAS_DATA data;
bool directed_to_me = false;
(void) src;
(void)src;
len = whohas_decode_service_request(service_request, service_len, &data);
if (len > 0) {
if ((data.low_limit == -1) || (data.high_limit == -1))
directed_to_me = true;
else if ((Device_Object_Instance_Number() >= (uint32_t) data.low_limit)
&& (Device_Object_Instance_Number() <= (uint32_t) data.high_limit))
else if ((Device_Object_Instance_Number() >=
(uint32_t)data.low_limit) &&
(Device_Object_Instance_Number() <= (uint32_t)data.high_limit))
directed_to_me = true;
if (directed_to_me) {
match_name_or_object(&data);
@@ -109,10 +104,12 @@ void handler_who_has(
}
}
#ifdef BAC_ROUTING /* was for BAC_ROUTING - delete in 2/2012 if still unused */
/* EKH: I restored this to BAC_ROUTING (from DEPRECATED) because I found that the server demo with the built-in
virtual Router did not insert the SADRs of the virtual devices on the virtual network without it */
#ifdef BAC_ROUTING /* was for BAC_ROUTING - delete in 2/2012 if still unused \
*/
/* EKH: I restored this to BAC_ROUTING (from DEPRECATED) because I found that
the server demo with the built-in
virtual Router did not insert the SADRs of the virtual devices on the virtual
network without it */
/** Handler for Who-Has requests in the virtual routing setup,
* with broadcast I-Have response.
@@ -124,29 +121,28 @@ void handler_who_has(
* @param service_len [in] Length of the service_request message.
* @param src [in] The BACNET_ADDRESS of the message's source (ignored).
*/
void handler_who_has_for_routing(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src)
void handler_who_has_for_routing(uint8_t* service_request, uint16_t service_len,
BACNET_ADDRESS* src)
{
int len = 0;
BACNET_WHO_HAS_DATA data;
int32_t dev_instance;
int cursor = 0; /* Starting hint */
int my_list[2] = { 0, -1 }; /* Not really used, so dummy values */
int cursor = 0; /* Starting hint */
int my_list[2] = {0, -1}; /* Not really used, so dummy values */
BACNET_ADDRESS bcast_net;
(void) src;
(void)src;
len = whohas_decode_service_request(service_request, service_len, &data);
if (len > 0) {
/* Go through all devices, starting with the root gateway Device */
memset(&bcast_net, 0, sizeof(BACNET_ADDRESS));
bcast_net.net = BACNET_BROADCAST_NETWORK; /* That's all we have to set */
bcast_net.net =
BACNET_BROADCAST_NETWORK; /* That's all we have to set */
while (Routed_Device_GetNext(&bcast_net, my_list, &cursor)) {
dev_instance = Device_Object_Instance_Number();
if ((data.low_limit == -1) || (data.high_limit == -1) ||
((dev_instance >= data.low_limit) &&
(dev_instance <= data.high_limit)))
(dev_instance <= data.high_limit)))
match_name_or_object(&data);
}
}
+61 -73
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* Copyright (C) 2005 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.
*
*********************************************************************/
*
* Copyright (C) 2005 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 <stdio.h>
@@ -47,25 +47,22 @@
* @param service_len [in] Length of the service_request message.
* @param src [in] The BACNET_ADDRESS of the message's source (ignored).
*/
void handler_who_is(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src)
void handler_who_is(uint8_t* service_request, uint16_t service_len,
BACNET_ADDRESS* src)
{
int len = 0;
int32_t low_limit = 0;
int32_t high_limit = 0;
(void) src;
len =
whois_decode_service_request(service_request, service_len, &low_limit,
&high_limit);
(void)src;
len = whois_decode_service_request(service_request, service_len, &low_limit,
&high_limit);
if (len == 0) {
Send_I_Am(&Handler_Transmit_Buffer[0]);
} else if (len != BACNET_STATUS_ERROR) {
/* is my device id within the limits? */
if ((Device_Object_Instance_Number() >= (uint32_t) low_limit) &&
(Device_Object_Instance_Number() <= (uint32_t) high_limit)) {
if ((Device_Object_Instance_Number() >= (uint32_t)low_limit) &&
(Device_Object_Instance_Number() <= (uint32_t)high_limit)) {
Send_I_Am(&Handler_Transmit_Buffer[0]);
}
}
@@ -73,32 +70,30 @@ void handler_who_is(
return;
}
/** Handler for Who-Is requests, with Unicast I-Am response (per Addendum 135-2004q).
/** Handler for Who-Is requests, with Unicast I-Am response (per Addendum
* 135-2004q).
* @ingroup DMDDB
* @param service_request [in] The received message to be handled.
* @param service_len [in] Length of the service_request message.
* @param src [in] The BACNET_ADDRESS of the message's source that the
* response will be sent back to.
*/
void handler_who_is_unicast(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src)
void handler_who_is_unicast(uint8_t* service_request, uint16_t service_len,
BACNET_ADDRESS* src)
{
int len = 0;
int32_t low_limit = 0;
int32_t high_limit = 0;
len =
whois_decode_service_request(service_request, service_len, &low_limit,
&high_limit);
len = whois_decode_service_request(service_request, service_len, &low_limit,
&high_limit);
/* If no limits, then always respond */
if (len == 0) {
Send_I_Am_Unicast(&Handler_Transmit_Buffer[0], src);
} else if (len != BACNET_STATUS_ERROR) {
/* is my device id within the limits? */
if ((Device_Object_Instance_Number() >= (uint32_t) low_limit) &&
(Device_Object_Instance_Number() <= (uint32_t) high_limit)) {
if ((Device_Object_Instance_Number() >= (uint32_t)low_limit) &&
(Device_Object_Instance_Number() <= (uint32_t)high_limit)) {
Send_I_Am_Unicast(&Handler_Transmit_Buffer[0], src);
}
}
@@ -106,11 +101,12 @@ void handler_who_is_unicast(
return;
}
#ifdef BAC_ROUTING /* was for BAC_ROUTING - delete in 2/2012 if still unused */
/* EKH: I restored this to BAC_ROUTING (from DEPRECATED) because I found that the server demo with the built-in
virtual Router did not insert the SADRs of the virtual devices on the virtual network without it */
#ifdef BAC_ROUTING /* was for BAC_ROUTING - delete in 2/2012 if still unused \
*/
/* EKH: I restored this to BAC_ROUTING (from DEPRECATED) because I found that
the server demo with the built-in
virtual Router did not insert the SADRs of the virtual devices on the virtual
network without it */
/** Local function to check Who-Is requests against our Device IDs.
* Will check the gateway (root Device) and all virtual routed
@@ -120,48 +116,44 @@ void handler_who_is_unicast(
* @param service_len [in] Length of the service_request message.
* @param src [in] The BACNET_ADDRESS of the message's source.
* @param is_unicast [in] True if should send unicast response(s)
* back to the src, else False if should broadcast response(s).
* back to the src, else False if should broadcast
* response(s).
*/
static void check_who_is_for_routing(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src,
bool is_unicast)
static void check_who_is_for_routing(uint8_t* service_request,
uint16_t service_len, BACNET_ADDRESS* src,
bool is_unicast)
{
int len = 0;
int32_t low_limit = 0;
int32_t high_limit = 0;
int32_t dev_instance;
int cursor = 0; /* Starting hint */
int my_list[2] = { 0, -1 }; /* Not really used, so dummy values */
int cursor = 0; /* Starting hint */
int my_list[2] = {0, -1}; /* Not really used, so dummy values */
BACNET_ADDRESS bcast_net;
len =
whois_decode_service_request(service_request, service_len, &low_limit,
&high_limit);
len = whois_decode_service_request(service_request, service_len, &low_limit,
&high_limit);
if (len == BACNET_STATUS_ERROR) {
/* Invalid; just leave */
return;
}
/* Go through all devices, starting with the root gateway Device */
memset(&bcast_net, 0, sizeof(BACNET_ADDRESS));
bcast_net.net = BACNET_BROADCAST_NETWORK; /* That's all we have to set */
bcast_net.net = BACNET_BROADCAST_NETWORK; /* That's all we have to set */
while (Routed_Device_GetNext(&bcast_net, my_list, &cursor)) {
dev_instance = Device_Object_Instance_Number();
/* If len == 0, no limits and always respond */
if ((len == 0) || ((dev_instance >= low_limit) &&
(dev_instance <= high_limit))) {
if ((len == 0) ||
((dev_instance >= low_limit) && (dev_instance <= high_limit))) {
if (is_unicast)
Send_I_Am_Unicast(&Handler_Transmit_Buffer[0], src);
else
Send_I_Am(&Handler_Transmit_Buffer[0]);
}
}
}
/** Handler for Who-Is requests in the virtual routing setup,
* with broadcast I-Am response(s).
* @ingroup DMDDB
@@ -173,15 +165,12 @@ static void check_who_is_for_routing(
* @param service_len [in] Length of the service_request message.
* @param src [in] The BACNET_ADDRESS of the message's source (ignored).
*/
void handler_who_is_bcast_for_routing(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src)
void handler_who_is_bcast_for_routing(uint8_t* service_request,
uint16_t service_len, BACNET_ADDRESS* src)
{
check_who_is_for_routing(service_request, service_len, src, false);
}
/** Handler for Who-Is requests in the virtual routing setup,
* with unicast I-Am response(s) returned to the src.
* Will check the gateway (root Device) and all virtual routed
@@ -193,10 +182,9 @@ void handler_who_is_bcast_for_routing(
* @param src [in] The BACNET_ADDRESS of the message's source that the
* response will be sent back to.
*/
void handler_who_is_unicast_for_routing(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src)
void handler_who_is_unicast_for_routing(uint8_t* service_request,
uint16_t service_len,
BACNET_ADDRESS* src)
{
check_who_is_for_routing(service_request, service_len, src, true);
}
+61 -72
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* Copyright (C) 2005 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.
*
*********************************************************************/
*
* Copyright (C) 2005 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 <stdio.h>
@@ -42,7 +42,6 @@
/** @file h_wp.c Handles Write Property requests. */
/** Handler for a WriteProperty Service request.
* @ingroup DSWP
* This handler will be invoked by apdu_handler() if it has been enabled
@@ -61,11 +60,9 @@
* @param service_data [in] The BACNET_CONFIRMED_SERVICE_DATA information
* decoded from the APDU header of this message.
*/
void handler_write_property(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src,
BACNET_CONFIRMED_SERVICE_DATA * service_data)
void handler_write_property(uint8_t* service_request, uint16_t service_len,
BACNET_ADDRESS* src,
BACNET_CONFIRMED_SERVICE_DATA* service_data)
{
BACNET_WRITE_PROPERTY_DATA wp_data;
int len = 0;
@@ -77,65 +74,63 @@ void handler_write_property(
/* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
#if PRINT_ENABLED
fprintf(stderr, "WP: Received Request!\n");
#endif
if (service_data->segmented_message) {
len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
true);
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
#if PRINT_ENABLED
fprintf(stderr, "WP: Segmented message. Sending Abort!\n");
#endif
goto WP_ABORT;
} /* decode the service request only */
} /* decode the service request only */
len = wp_decode_service_request(service_request, service_len, &wp_data);
#if PRINT_ENABLED
if (len > 0)
fprintf(stderr,
fprintf(
stderr,
"WP: type=%lu instance=%lu property=%lu priority=%lu index=%ld\n",
(unsigned long) wp_data.object_type,
(unsigned long) wp_data.object_instance,
(unsigned long) wp_data.object_property,
(unsigned long) wp_data.priority, (long) wp_data.array_index);
(unsigned long)wp_data.object_type,
(unsigned long)wp_data.object_instance,
(unsigned long)wp_data.object_property,
(unsigned long)wp_data.priority, (long)wp_data.array_index);
else
fprintf(stderr, "WP: Unable to decode Request!\n");
#endif
/* bad decoding or something we didn't understand - send an abort */
if (len <= 0) {
len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_OTHER, true);
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_OTHER,
true);
#if PRINT_ENABLED
fprintf(stderr, "WP: Bad Encoding. Sending Abort!\n");
#endif
goto WP_ABORT;
}
if (Device_Write_Property(&wp_data)) {
len =
encode_simple_ack(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY);
len = encode_simple_ack(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY);
#if PRINT_ENABLED
fprintf(stderr, "WP: Sending Simple Ack!\n");
#endif
} else {
len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY,
wp_data.error_class, wp_data.error_code);
len = bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY,
wp_data.error_class, wp_data.error_code);
#if PRINT_ENABLED
fprintf(stderr, "WP: Sending Error!\n");
#endif
}
WP_ABORT:
WP_ABORT:
pdu_len += len;
bytes_sent =
datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
bytes_sent = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
if (bytes_sent <= 0) {
#if PRINT_ENABLED
fprintf(stderr, "WP: Failed to send PDU (%s)!\n", strerror(errno));
@@ -145,19 +140,15 @@ void handler_write_property(
return;
}
/** Perform basic validation of Write Property argument based on
* the assumption that it is a string. Check for correct data type,
* correct encoding (fixed here as ANSI X34),correct length, and
* finally if it is allowed to be empty.
*/
bool WPValidateString(
BACNET_APPLICATION_DATA_VALUE * pValue,
int iMaxLen,
bool bEmptyAllowed,
BACNET_ERROR_CLASS * pErrorClass,
BACNET_ERROR_CODE * pErrorCode)
bool WPValidateString(BACNET_APPLICATION_DATA_VALUE* pValue, int iMaxLen,
bool bEmptyAllowed, BACNET_ERROR_CLASS* pErrorClass,
BACNET_ERROR_CODE* pErrorCode)
{
bool bResult;
@@ -172,15 +163,15 @@ bool WPValidateString(
if (characterstring_encoding(&pValue->type.Character_String) ==
CHARACTER_ANSI_X34) {
if ((bEmptyAllowed == false) &&
(characterstring_length(&pValue->type.Character_String) ==
0)) {
(characterstring_length(&pValue->type.Character_String) == 0)) {
*pErrorCode = ERROR_CODE_VALUE_OUT_OF_RANGE;
} else if ((bEmptyAllowed == false) &&
(!characterstring_printable(&pValue->type.Character_String))) {
(!characterstring_printable(
&pValue->type.Character_String))) {
/* assumption: non-empty also means must be "printable" */
*pErrorCode = ERROR_CODE_VALUE_OUT_OF_RANGE;
} else if (characterstring_length(&pValue->type.Character_String) >
(uint16_t) iMaxLen) {
(uint16_t)iMaxLen) {
*pErrorClass = ERROR_CLASS_RESOURCES;
*pErrorCode = ERROR_CODE_NO_SPACE_TO_WRITE_PROPERTY;
} else
@@ -198,11 +189,9 @@ bool WPValidateString(
* validation fails. Cuts out reams of repeated code in the object code.
*/
bool WPValidateArgType(
BACNET_APPLICATION_DATA_VALUE * pValue,
uint8_t ucExpectedTag,
BACNET_ERROR_CLASS * pErrorClass,
BACNET_ERROR_CODE * pErrorCode)
bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE* pValue,
uint8_t ucExpectedTag, BACNET_ERROR_CLASS* pErrorClass,
BACNET_ERROR_CODE* pErrorCode)
{
bool bResult;
+61 -65
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* Copyright (C) 2011 Krzysztof Malorny <malornykrzysztof@gmail.com>
*
* 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.
*
*********************************************************************/
*
* Copyright (C) 2011 Krzysztof Malorny <malornykrzysztof@gmail.com>
*
* 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 <stdio.h>
@@ -44,7 +44,6 @@
/** @file h_wpm.c Handles Write Property Multiple requests. */
/** Handler for a WriteProperty Service request.
* @ingroup DSWP
* This handler will be invoked by apdu_handler() if it has been enabled
@@ -63,10 +62,8 @@
* decoded from the APDU header of this message.
*/
void handler_write_property_multiple(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src,
BACNET_CONFIRMED_SERVICE_DATA * service_data)
uint8_t* service_request, uint16_t service_len, BACNET_ADDRESS* src,
BACNET_CONFIRMED_SERVICE_DATA* service_data)
{
int len = 0;
int apdu_len = 0;
@@ -92,32 +89,34 @@ void handler_write_property_multiple(
decode_len = 0;
do {
/* decode Object Identifier */
len =
wpm_decode_object_id(&service_request[decode_len],
service_len - decode_len, &wp_data);
len = wpm_decode_object_id(&service_request[decode_len],
service_len - decode_len, &wp_data);
if (len > 0) {
uint8_t tag_number = 0;
decode_len += len;
/* Opening tag 1 - List of Properties */
if (decode_is_opening_tag_number(&service_request[decode_len++],
1)) {
1)) {
do {
/* decode a 'Property Identifier'; (3) an optional 'Property Array Index' */
/* (4) a 'Property Value'; and (5) an optional 'Priority'. */
len =
wpm_decode_object_property(&service_request
[decode_len], service_len - decode_len, &wp_data);
/* decode a 'Property Identifier'; (3) an optional 'Property
* Array Index' */
/* (4) a 'Property Value'; and (5) an optional 'Priority'.
*/
len = wpm_decode_object_property(
&service_request[decode_len], service_len - decode_len,
&wp_data);
if (len > 0) {
decode_len += len;
#if PRINT_ENABLED
fprintf(stderr,
"WPM: type=%lu instance=%lu property=%lu priority=%lu index=%ld\n",
(unsigned long) wp_data.object_type,
(unsigned long) wp_data.object_instance,
(unsigned long) wp_data.object_property,
(unsigned long) wp_data.priority,
(long) wp_data.array_index);
"WPM: type=%lu instance=%lu property=%lu "
"priority=%lu index=%ld\n",
(unsigned long)wp_data.object_type,
(unsigned long)wp_data.object_instance,
(unsigned long)wp_data.object_property,
(unsigned long)wp_data.priority,
(long)wp_data.array_index);
#endif
if (Device_Write_Property(&wp_data) == false) {
error = true;
@@ -133,15 +132,17 @@ void handler_write_property_multiple(
}
/* Closing tag 1 - List of Properties */
if (decode_is_closing_tag_number(&service_request
[decode_len], 1)) {
if (decode_is_closing_tag_number(
&service_request[decode_len], 1)) {
tag_number = 1;
decode_len++;
} else
tag_number = 0; /* it was not tag 1, decode next Property Identifier ... */
tag_number = 0; /* it was not tag 1, decode next
Property Identifier ... */
}
while (tag_number != 1); /* end decoding List of Properties for "that" object */
} while (
tag_number !=
1); /* end decoding List of Properties for "that" object */
if (error) {
goto WPM_ABORT;
@@ -156,20 +157,18 @@ void handler_write_property_multiple(
}
} while (decode_len < service_len);
WPM_ABORT:
WPM_ABORT:
/* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
npdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
npdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
apdu_len = 0;
/* handle any errors */
if (error) {
if (len == BACNET_STATUS_ABORT) {
apdu_len =
abort_encode_apdu(&Handler_Transmit_Buffer[npdu_len],
service_data->invoke_id,
apdu_len = abort_encode_apdu(
&Handler_Transmit_Buffer[npdu_len], service_data->invoke_id,
abort_convert_error_code(wp_data.error_code), true);
#if PRINT_ENABLED
fprintf(stderr, "WPM: Sending Abort!\n");
@@ -177,32 +176,29 @@ void handler_write_property_multiple(
} else if (len == BACNET_STATUS_ERROR) {
apdu_len =
wpm_error_ack_encode_apdu(&Handler_Transmit_Buffer[npdu_len],
service_data->invoke_id, &wp_data);
service_data->invoke_id, &wp_data);
#if PRINT_ENABLED
fprintf(stderr, "WPM: Sending Error!\n");
#endif
} else if (len == BACNET_STATUS_REJECT) {
apdu_len =
reject_encode_apdu(&Handler_Transmit_Buffer[npdu_len],
service_data->invoke_id,
apdu_len = reject_encode_apdu(
&Handler_Transmit_Buffer[npdu_len], service_data->invoke_id,
reject_convert_error_code(wp_data.error_code));
#if PRINT_ENABLED
fprintf(stderr, "WPM: Sending Reject!\n");
#endif
}
} else {
apdu_len =
wpm_ack_encode_apdu_init(&Handler_Transmit_Buffer[npdu_len],
service_data->invoke_id);
apdu_len = wpm_ack_encode_apdu_init(&Handler_Transmit_Buffer[npdu_len],
service_data->invoke_id);
#if PRINT_ENABLED
fprintf(stderr, "WPM: Sending Ack!\n");
#endif
}
pdu_len = npdu_len + apdu_len;
bytes_sent =
datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
bytes_sent = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0) {
fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno));
+35 -39
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* Copyright (C) 2005 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.
*
*********************************************************************/
*
* Copyright (C) 2005 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 <stdio.h>
@@ -49,11 +49,9 @@
* @param service_data [in] The BACNET_CONFIRMED_SERVICE_DATA information
* decoded from the APDU header of this message.
*/
void handler_unrecognized_service(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src,
BACNET_CONFIRMED_SERVICE_DATA * service_data)
void handler_unrecognized_service(uint8_t* service_request,
uint16_t service_len, BACNET_ADDRESS* src,
BACNET_CONFIRMED_SERVICE_DATA* service_data)
{
int len = 0;
int pdu_len = 0;
@@ -61,24 +59,22 @@ void handler_unrecognized_service(
BACNET_NPDU_DATA npdu_data;
BACNET_ADDRESS my_address;
(void) service_request;
(void) service_len;
(void)service_request;
(void)service_len;
/* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
/* encode the APDU portion of the packet */
len =
reject_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, REJECT_REASON_UNRECOGNIZED_SERVICE);
len = reject_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
REJECT_REASON_UNRECOGNIZED_SERVICE);
pdu_len += len;
/* send the data */
bytes_sent =
datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
bytes_sent = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
if (bytes_sent > 0) {
#if PRINT_ENABLED
fprintf(stderr, "Sent Reject!\n");
+16 -26
View File
@@ -44,36 +44,31 @@
/* list of devices */
static OS_Keylist Device_List = NULL;
void objects_init(
void)
void objects_init(void)
{
if (!Device_List)
Device_List = Keylist_Create();
}
int objects_device_count(
void)
int objects_device_count(void)
{
objects_init();
return Keylist_Count(Device_List);
}
OBJECT_DEVICE_T *objects_device_data(
int index)
OBJECT_DEVICE_T *objects_device_data(int index)
{
objects_init();
return Keylist_Data_Index(Device_List, index);
}
OBJECT_DEVICE_T *objects_device_by_instance(
uint32_t device_instance)
OBJECT_DEVICE_T *objects_device_by_instance(uint32_t device_instance)
{
objects_init();
return Keylist_Data(Device_List, device_instance);
}
OBJECT_DEVICE_T *objects_device_new(
uint32_t device_instance)
OBJECT_DEVICE_T *objects_device_new(uint32_t device_instance)
{
OBJECT_DEVICE_T *pDevice = NULL;
KEY key = device_instance;
@@ -93,8 +88,8 @@ OBJECT_DEVICE_T *objects_device_new(
Keylist_Data_Add(Device_List, key, pDevice);
} else {
fprintf(stderr,
"Objects: Unable to allocate device %lu buffer\n",
(unsigned long) device_instance);
"Objects: Unable to allocate device %lu buffer\n",
(unsigned long)device_instance);
}
}
}
@@ -102,8 +97,7 @@ OBJECT_DEVICE_T *objects_device_new(
return pDevice;
}
OBJECT_DEVICE_T *objects_device_delete(
int index)
OBJECT_DEVICE_T *objects_device_delete(int index)
{
OBJECT_DEVICE_T *pDevice = NULL;
BACNET_OBJECT_ID *pObject;
@@ -112,7 +106,7 @@ OBJECT_DEVICE_T *objects_device_delete(
pDevice = Keylist_Data_Delete_By_Index(Device_List, index);
if (pDevice) {
fprintf(stderr, "Objects: removing device %lu",
(unsigned long) pDevice->Object_Identifier.instance);
(unsigned long)pDevice->Object_Identifier.instance);
if (pDevice->Object_List) {
do {
pObject =
@@ -137,10 +131,8 @@ OBJECT_DEVICE_T *objects_device_delete(
#include "ctest.h"
/* test the object creation and deletion */
void testBACnetObjectsCompare(
Test * pTest,
OBJECT_DEVICE_T * pDevice,
uint32_t device_id)
void testBACnetObjectsCompare(Test *pTest, OBJECT_DEVICE_T *pDevice,
uint32_t device_id)
{
ct_test(pTest, pDevice != NULL);
if (pDevice) {
@@ -151,8 +143,7 @@ void testBACnetObjectsCompare(
}
}
void testBACnetObjects(
Test * pTest)
void testBACnetObjects(Test *pTest)
{
uint32_t device_id = 0;
unsigned test_point = 0;
@@ -175,8 +166,8 @@ void testBACnetObjects(
for (test_point = 0; test_point < max_test_points; test_point++) {
device_id = test_point * (BACNET_MAX_INSTANCE / max_test_points);
pDevice = objects_device_data(test_point);
testBACnetObjectsCompare(pTest, pDevice, Keylist_Key(Device_List,
test_point));
testBACnetObjectsCompare(pTest, pDevice,
Keylist_Key(Device_List, test_point));
}
for (test_point = 0; test_point < max_test_points; test_point++) {
pDevice = objects_device_delete(0);
@@ -184,8 +175,7 @@ void testBACnetObjects(
}
#ifdef TEST_OBJECT_LIST
int main(
void)
int main(void)
{
Test *pTest;
bool rc;
@@ -198,7 +188,7 @@ int main(
ct_setStream(pTest, stdout);
ct_run(pTest);
(void) ct_report(pTest);
(void)ct_report(pTest);
ct_destroy(pTest);
+31 -40
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* Copyright (C) 2016 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.
*
*********************************************************************/
*
* Copyright (C) 2016 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>
@@ -43,7 +43,6 @@
#include "handlers.h"
#include "client.h"
/** Encodes an Abort message
* @param buffer The buffer to build the message for sending.
* @param dest - Destination address to send the message
@@ -55,14 +54,9 @@
*
* @return Size of the message sent (bytes), or a negative value on error.
*/
int abort_encode_pdu(
uint8_t * buffer,
BACNET_ADDRESS * dest,
BACNET_ADDRESS * src,
BACNET_NPDU_DATA * npdu_data,
uint8_t invoke_id,
BACNET_ABORT_REASON reason,
bool server)
int abort_encode_pdu(uint8_t *buffer, BACNET_ADDRESS *dest, BACNET_ADDRESS *src,
BACNET_NPDU_DATA *npdu_data, uint8_t invoke_id,
BACNET_ABORT_REASON reason, bool server)
{
int len = 0;
int pdu_len = 0;
@@ -87,12 +81,9 @@ int abort_encode_pdu(
*
* @return Size of the message sent (bytes), or a negative value on error.
*/
int Send_Abort_To_Network(
uint8_t * buffer,
BACNET_ADDRESS *dest,
uint8_t invoke_id,
BACNET_ABORT_REASON reason,
bool server)
int Send_Abort_To_Network(uint8_t *buffer, BACNET_ADDRESS *dest,
uint8_t invoke_id, BACNET_ABORT_REASON reason,
bool server)
{
int pdu_len = 0;
BACNET_ADDRESS src;
@@ -100,8 +91,8 @@ int Send_Abort_To_Network(
BACNET_NPDU_DATA npdu_data;
datalink_get_my_address(&src);
pdu_len = abort_encode_pdu(buffer, dest, &src, &npdu_data,
invoke_id, reason, server);
pdu_len = abort_encode_pdu(buffer, dest, &src, &npdu_data, invoke_id,
reason, server);
bytes_sent = datalink_send_pdu(dest, &npdu_data, &buffer[0], pdu_len);
return bytes_sent;
+38 -42
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* Copyright (C) 2009 John Minack <minack@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.
*
*********************************************************************/
*
* Copyright (C) 2009 John Minack <minack@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>
@@ -48,10 +48,8 @@
/* returns the invoke ID for confirmed request, or zero on failure */
uint8_t Send_Alarm_Acknowledgement(
uint32_t device_id,
BACNET_ALARM_ACK_DATA * data)
uint8_t Send_Alarm_Acknowledgement(uint32_t device_id,
BACNET_ALARM_ACK_DATA* data)
{
BACNET_ADDRESS dest;
BACNET_ADDRESS my_address;
@@ -75,36 +73,34 @@ uint8_t Send_Alarm_Acknowledgement(
/* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address,
&npdu_data);
len =
alarm_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id,
data);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest,
&my_address, &npdu_data);
len = alarm_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
invoke_id, data);
pdu_len += len;
/* will it fit in the sender?
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,
&npdu_data, &Handler_Transmit_Buffer[0], (uint16_t) pdu_len);
bytes_sent =
datalink_send_pdu(&dest, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len);
if ((unsigned)pdu_len < max_apdu) {
tsm_set_confirmed_unsegmented_transaction(
invoke_id, &dest, &npdu_data, &Handler_Transmit_Buffer[0],
(uint16_t)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 Alarm Ack Request (%s)!\n",
strerror(errno));
strerror(errno));
#endif
} else {
tsm_free_invoke_id(invoke_id);
invoke_id = 0;
#if PRINT_ENABLED
fprintf(stderr,
"Failed to Send Alarm Ack Request "
"(exceeds destination maximum APDU)!\n");
"Failed to Send Alarm Ack Request "
"(exceeds destination maximum APDU)!\n");
#endif
}
}
+40 -45
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* 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.
*
*********************************************************************/
*
* 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>
@@ -45,11 +45,9 @@
/** @file s_arfs.c Send part of an Atomic Read File Stream. */
uint8_t Send_Atomic_Read_File_Stream(
uint32_t device_id,
uint32_t file_instance,
int fileStartPosition,
unsigned requestedOctetCount)
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;
@@ -81,37 +79,34 @@ uint8_t Send_Atomic_Read_File_Stream(
/* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address,
&npdu_data);
len =
arf_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id,
&data);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest,
&my_address, &npdu_data);
len = arf_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id,
&data);
pdu_len += len;
/* 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,
&npdu_data, &Handler_Transmit_Buffer[0], (uint16_t) pdu_len);
bytes_sent =
datalink_send_pdu(&dest, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len);
if ((unsigned)pdu_len < max_apdu) {
tsm_set_confirmed_unsegmented_transaction(
invoke_id, &dest, &npdu_data, &Handler_Transmit_Buffer[0],
(uint16_t)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));
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");
"Failed to Send AtomicReadFile Request "
"(payload exceeds destination maximum APDU)!\n");
#endif
}
}
+44 -46
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* 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.
*
*********************************************************************/
*
* 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>
@@ -45,11 +45,10 @@
/** @file s_awfs.c Send part of an Atomic Write File Stream request. */
uint8_t Send_Atomic_Write_File_Stream(
uint32_t device_id,
uint32_t file_instance,
int fileStartPosition,
BACNET_OCTET_STRING * fileData)
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;
@@ -82,37 +81,35 @@ uint8_t Send_Atomic_Write_File_Stream(
/* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest,
&my_address, &npdu_data);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest,
&my_address, &npdu_data);
/* encode the APDU portion of the packet */
len =
awf_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id,
&data);
len = awf_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id,
&data);
pdu_len += len;
/* 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,
&npdu_data, &Handler_Transmit_Buffer[0],
(uint16_t) pdu_len);
bytes_sent =
datalink_send_pdu(&dest, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len);
if ((unsigned)pdu_len <= max_apdu) {
tsm_set_confirmed_unsegmented_transaction(
invoke_id, &dest, &npdu_data, &Handler_Transmit_Buffer[0],
(uint16_t)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));
"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,
fprintf(
stderr,
"Failed to Send AtomicWriteFile Request "
"(payload [%d] exceeds destination maximum APDU [%u])!\n",
pdu_len, max_apdu);
@@ -123,8 +120,9 @@ uint8_t Send_Atomic_Write_File_Stream(
invoke_id = 0;
#if PRINT_ENABLED
fprintf(stderr,
"Failed to Send AtomicWriteFile Request "
"(payload [%d] exceeds octet string capacity)!\n", pdu_len);
"Failed to Send AtomicWriteFile Request "
"(payload [%d] exceeds octet string capacity)!\n",
pdu_len);
#endif
}
}
+39 -41
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* Copyright (C) 2005 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.
*
*********************************************************************/
*
* Copyright (C) 2005 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>
@@ -47,9 +47,8 @@
* @return invoke id of outgoing message, or 0 if communication is disabled,
* or no tsm slot is available.
*/
uint8_t Send_CEvent_Notify(
uint32_t device_id,
BACNET_EVENT_NOTIFICATION_DATA * data)
uint8_t Send_CEvent_Notify(uint32_t device_id,
BACNET_EVENT_NOTIFICATION_DATA* data)
{
int len = 0;
int pdu_len = 0;
@@ -73,28 +72,27 @@ uint8_t Send_CEvent_Notify(
/* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address,
&npdu_data);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest,
&my_address, &npdu_data);
/* encode the APDU portion of the packet */
len =
cevent_notify_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
invoke_id, data);
len = cevent_notify_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
invoke_id, data);
pdu_len += len;
/* will it fit in the sender?
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,
&npdu_data, &Handler_Transmit_Buffer[0], (uint16_t) pdu_len);
bytes_sent =
datalink_send_pdu(&dest, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len);
if ((unsigned)pdu_len < max_apdu) {
tsm_set_confirmed_unsegmented_transaction(
invoke_id, &dest, &npdu_data, &Handler_Transmit_Buffer[0],
(uint16_t)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,
fprintf(
stderr,
"Failed to Send ConfirmedEventNotification Request (%s)!\n",
strerror(errno));
}
@@ -104,8 +102,8 @@ uint8_t Send_CEvent_Notify(
invoke_id = 0;
#if PRINT_ENABLED
fprintf(stderr,
"Failed to Send ConfirmedEventNotification Request "
"(exceeds destination maximum APDU)!\n");
"Failed to Send ConfirmedEventNotification Request "
"(exceeds destination maximum APDU)!\n");
#endif
}
}
+50 -56
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* Copyright (C) 2008 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.
*
*********************************************************************/
*
* Copyright (C) 2008 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>
@@ -42,7 +42,8 @@
#include "txbuf.h"
#include "client.h"
/** @file s_cov.c Send a Change of Value (COV) update or a Subscribe COV request. */
/** @file s_cov.c Send a Change of Value (COV) update or a Subscribe COV
* request. */
/** Encodes an Unconfirmed COV Notification.
* @ingroup DSCOV
@@ -54,12 +55,9 @@
* @param cov_data [in] The COV update information to be encoded.
* @return Size of the message sent (bytes), or a negative value on error.
*/
int ucov_notify_encode_pdu(
uint8_t * buffer,
unsigned buffer_len,
BACNET_ADDRESS * dest,
BACNET_NPDU_DATA * npdu_data,
BACNET_COV_DATA * cov_data)
int ucov_notify_encode_pdu(uint8_t* buffer, unsigned buffer_len,
BACNET_ADDRESS* dest, BACNET_NPDU_DATA* npdu_data,
BACNET_COV_DATA* cov_data)
{
int len = 0;
int pdu_len = 0;
@@ -73,8 +71,8 @@ int ucov_notify_encode_pdu(
pdu_len = npdu_encode_pdu(&buffer[0], dest, &my_address, npdu_data);
/* encode the APDU portion of the packet */
len = ucov_notify_encode_apdu(&buffer[pdu_len],
buffer_len - pdu_len, cov_data);
len = ucov_notify_encode_apdu(&buffer[pdu_len], buffer_len - pdu_len,
cov_data);
if (len) {
pdu_len += len;
} else {
@@ -92,18 +90,16 @@ int ucov_notify_encode_pdu(
* @param cov_data [in] The COV update information to be encoded.
* @return Size of the message sent (bytes), or a negative value on error.
*/
int Send_UCOV_Notify(
uint8_t * buffer,
unsigned buffer_len,
BACNET_COV_DATA * cov_data)
int Send_UCOV_Notify(uint8_t* buffer, unsigned buffer_len,
BACNET_COV_DATA* cov_data)
{
int pdu_len = 0;
BACNET_ADDRESS dest;
int bytes_sent = 0;
BACNET_NPDU_DATA npdu_data;
pdu_len = ucov_notify_encode_pdu(buffer, buffer_len, &dest, &npdu_data,
cov_data);
pdu_len =
ucov_notify_encode_pdu(buffer, buffer_len, &dest, &npdu_data, cov_data);
bytes_sent = datalink_send_pdu(&dest, &npdu_data, &buffer[0], pdu_len);
return bytes_sent;
@@ -117,9 +113,8 @@ int Send_UCOV_Notify(
* @return invoke id of outgoing message, or 0 if communication is disabled or
* no slot is available from the tsm for sending.
*/
uint8_t Send_COV_Subscribe(
uint32_t device_id,
BACNET_SUBSCRIBE_COV_DATA * cov_data)
uint8_t Send_COV_Subscribe(uint32_t device_id,
BACNET_SUBSCRIBE_COV_DATA* cov_data)
{
BACNET_ADDRESS dest;
BACNET_ADDRESS my_address;
@@ -143,29 +138,28 @@ uint8_t Send_COV_Subscribe(
/* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address,
&npdu_data);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest,
&my_address, &npdu_data);
/* encode the APDU portion of the packet */
len =
cov_subscribe_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
sizeof(Handler_Transmit_Buffer)-pdu_len, invoke_id, cov_data);
len = cov_subscribe_encode_apdu(
&Handler_Transmit_Buffer[pdu_len],
sizeof(Handler_Transmit_Buffer) - pdu_len, invoke_id, cov_data);
pdu_len += len;
/* will it fit in the sender?
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,
&npdu_data, &Handler_Transmit_Buffer[0], (uint16_t) pdu_len);
bytes_sent =
datalink_send_pdu(&dest, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len);
if ((unsigned)pdu_len < max_apdu) {
tsm_set_confirmed_unsegmented_transaction(
invoke_id, &dest, &npdu_data, &Handler_Transmit_Buffer[0],
(uint16_t)pdu_len);
bytes_sent = datalink_send_pdu(
&dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
if (bytes_sent <= 0) {
#if PRINT_ENABLED
fprintf(stderr, "Failed to Send SubscribeCOV Request (%s)!\n",
strerror(errno));
strerror(errno));
#endif
}
} else {
@@ -173,8 +167,8 @@ uint8_t Send_COV_Subscribe(
invoke_id = 0;
#if PRINT_ENABLED
fprintf(stderr,
"Failed to Send SubscribeCOV Request "
"(exceeds destination maximum APDU)!\n");
"Failed to Send SubscribeCOV Request "
"(exceeds destination maximum APDU)!\n");
#endif
}
}
+41 -43
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* 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.
*
*********************************************************************/
*
* 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>
@@ -56,11 +56,9 @@
*/
uint8_t Send_Device_Communication_Control_Request(
uint32_t device_id,
uint16_t timeDuration, /* 0=optional */
BACNET_COMMUNICATION_ENABLE_DISABLE state,
char *password)
{ /* NULL=optional */
uint32_t device_id, uint16_t timeDuration, /* 0=optional */
BACNET_COMMUNICATION_ENABLE_DISABLE state, char *password)
{ /* NULL=optional */
BACNET_ADDRESS dest;
BACNET_ADDRESS my_address;
unsigned max_apdu = 0;
@@ -85,29 +83,29 @@ uint8_t Send_Device_Communication_Control_Request(
/* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address,
&npdu_data);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest,
&my_address, &npdu_data);
/* encode the APDU portion of the packet */
characterstring_init_ansi(&password_string, password);
len =
dcc_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id,
timeDuration, state, password ? &password_string : NULL);
len = dcc_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id,
timeDuration, state,
password ? &password_string : NULL);
pdu_len += len;
/* will it fit in the sender?
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,
&npdu_data, &Handler_Transmit_Buffer[0], (uint16_t) pdu_len);
bytes_sent =
datalink_send_pdu(&dest, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len);
if ((unsigned)pdu_len < max_apdu) {
tsm_set_confirmed_unsegmented_transaction(
invoke_id, &dest, &npdu_data, &Handler_Transmit_Buffer[0],
(uint16_t)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,
fprintf(
stderr,
"Failed to Send DeviceCommunicationControl Request (%s)!\n",
strerror(errno));
#endif
@@ -116,8 +114,8 @@ uint8_t Send_Device_Communication_Control_Request(
invoke_id = 0;
#if PRINT_ENABLED
fprintf(stderr,
"Failed to Send DeviceCommunicationControl Request "
"(exceeds destination maximum APDU)!\n");
"Failed to Send DeviceCommunicationControl Request "
"(exceeds destination maximum APDU)!\n");
#endif
}
}
+36 -44
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* Copyright (C) 2016 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.
*
*********************************************************************/
*
* Copyright (C) 2016 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>
@@ -42,7 +42,6 @@
#include "handlers.h"
#include "client.h"
/** Encodes an Error message
* @param buffer The buffer to build the message for sending.
* @param dest - Destination address to send the message
@@ -54,15 +53,11 @@
*
* @return Size of the message sent (bytes), or a negative value on error.
*/
int error_encode_pdu(
uint8_t * buffer,
BACNET_ADDRESS * dest,
BACNET_ADDRESS * src,
BACNET_NPDU_DATA * npdu_data,
uint8_t invoke_id,
BACNET_CONFIRMED_SERVICE service,
BACNET_ERROR_CLASS error_class,
BACNET_ERROR_CODE error_code)
int error_encode_pdu(uint8_t *buffer, BACNET_ADDRESS *dest, BACNET_ADDRESS *src,
BACNET_NPDU_DATA *npdu_data, uint8_t invoke_id,
BACNET_CONFIRMED_SERVICE service,
BACNET_ERROR_CLASS error_class,
BACNET_ERROR_CODE error_code)
{
int len = 0;
int pdu_len = 0;
@@ -72,8 +67,8 @@ int error_encode_pdu(
pdu_len = npdu_encode_pdu(&buffer[0], dest, src, npdu_data);
/* encode the APDU portion of the packet */
len = bacerror_encode_apdu(&buffer[pdu_len], invoke_id,
service, error_class, error_code);
len = bacerror_encode_apdu(&buffer[pdu_len], invoke_id, service,
error_class, error_code);
pdu_len += len;
return pdu_len;
@@ -88,13 +83,10 @@ int error_encode_pdu(
*
* @return Size of the message sent (bytes), or a negative value on error.
*/
int Send_Error_To_Network(
uint8_t * buffer,
BACNET_ADDRESS *dest,
uint8_t invoke_id,
BACNET_CONFIRMED_SERVICE service,
BACNET_ERROR_CLASS error_class,
BACNET_ERROR_CODE error_code)
int Send_Error_To_Network(uint8_t *buffer, BACNET_ADDRESS *dest,
uint8_t invoke_id, BACNET_CONFIRMED_SERVICE service,
BACNET_ERROR_CLASS error_class,
BACNET_ERROR_CODE error_code)
{
int pdu_len = 0;
BACNET_ADDRESS src;
@@ -102,8 +94,8 @@ int Send_Error_To_Network(
BACNET_NPDU_DATA npdu_data;
datalink_get_my_address(&src);
pdu_len = error_encode_pdu(buffer, dest, &src, &npdu_data,
invoke_id, service, error_class, error_code);
pdu_len = error_encode_pdu(buffer, dest, &src, &npdu_data, invoke_id,
service, error_class, error_code);
bytes_sent = datalink_send_pdu(dest, &npdu_data, &buffer[0], pdu_len);
return bytes_sent;
+16 -21
View File
@@ -52,9 +52,7 @@
#include "client.h"
#include "get_alarm_sum.h"
uint8_t Send_Get_Alarm_Summary_Address(
BACNET_ADDRESS *dest,
uint16_t max_apdu)
uint8_t Send_Get_Alarm_Summary_Address(BACNET_ADDRESS *dest, uint16_t max_apdu)
{
int len = 0;
int pdu_len = 0;
@@ -72,36 +70,35 @@ uint8_t Send_Get_Alarm_Summary_Address(
/* encode the NPDU portion of the packet */
npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], dest,
&my_address, &npdu_data);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], dest,
&my_address, &npdu_data);
/* encode the APDU portion of the packet */
len = get_alarm_summary_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
invoke_id);
invoke_id);
pdu_len += len;
if ((uint16_t) pdu_len < max_apdu) {
tsm_set_confirmed_unsegmented_transaction(invoke_id, dest,
&npdu_data, &Handler_Transmit_Buffer[0],
(uint16_t) pdu_len);
if ((uint16_t)pdu_len < max_apdu) {
tsm_set_confirmed_unsegmented_transaction(
invoke_id, dest, &npdu_data, &Handler_Transmit_Buffer[0],
(uint16_t)pdu_len);
#if PRINT_ENABLED
bytes_sent =
#endif
datalink_send_pdu(dest, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len);
datalink_send_pdu(dest, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0)
fprintf(stderr,
"Failed to Send Get Alarm Summary Request (%s)!\n",
strerror(errno));
"Failed to Send Get Alarm Summary Request (%s)!\n",
strerror(errno));
#endif
} else {
tsm_free_invoke_id(invoke_id);
invoke_id = 0;
#if PRINT_ENABLED
fprintf(stderr,
"Failed to Send Get Alarm Summary Request "
"(exceeds destination maximum APDU)!\n");
"Failed to Send Get Alarm Summary Request "
"(exceeds destination maximum APDU)!\n");
#endif
}
}
@@ -109,8 +106,7 @@ uint8_t Send_Get_Alarm_Summary_Address(
return invoke_id;
}
uint8_t Send_Get_Alarm_Summary(
uint32_t device_id)
uint8_t Send_Get_Alarm_Summary(uint32_t device_id)
{
BACNET_ADDRESS dest;
unsigned max_apdu = 0;
@@ -120,8 +116,7 @@ uint8_t Send_Get_Alarm_Summary(
/* is the device bound? */
status = address_get_by_device(device_id, &max_apdu, &dest);
if (status) {
invoke_id = Send_Get_Alarm_Summary_Address(
&dest, max_apdu);
invoke_id = Send_Get_Alarm_Summary_Address(&dest, max_apdu);
}
return invoke_id;
+18 -19
View File
@@ -55,9 +55,8 @@
#include "getevent.h"
uint8_t Send_Get_Event_Information_Address(
BACNET_ADDRESS *dest,
uint16_t max_apdu,
BACNET_OBJECT_ID * lastReceivedObjectIdentifier)
BACNET_ADDRESS *dest, uint16_t max_apdu,
BACNET_OBJECT_ID *lastReceivedObjectIdentifier)
{
int len = 0;
int pdu_len = 0;
@@ -74,34 +73,35 @@ uint8_t Send_Get_Event_Information_Address(
datalink_get_my_address(&my_address);
/* encode the NPDU portion of the packet */
npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], dest,
&my_address, &npdu_data);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], dest,
&my_address, &npdu_data);
/* encode the APDU portion of the packet */
len = getevent_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
invoke_id, lastReceivedObjectIdentifier);
len = getevent_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id,
lastReceivedObjectIdentifier);
pdu_len += len;
if ((uint16_t) pdu_len < max_apdu) {
tsm_set_confirmed_unsegmented_transaction(invoke_id, dest,
&npdu_data, &Handler_Transmit_Buffer[0], (uint16_t) pdu_len);
if ((uint16_t)pdu_len < max_apdu) {
tsm_set_confirmed_unsegmented_transaction(
invoke_id, dest, &npdu_data, &Handler_Transmit_Buffer[0],
(uint16_t)pdu_len);
#if PRINT_ENABLED
bytes_sent =
#endif
datalink_send_pdu(dest, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len);
datalink_send_pdu(dest, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0)
fprintf(stderr, "Failed to Send Get Event Information Request (%s)!\n",
strerror(errno));
fprintf(stderr,
"Failed to Send Get Event Information Request (%s)!\n",
strerror(errno));
#endif
} else {
tsm_free_invoke_id(invoke_id);
invoke_id = 0;
#if PRINT_ENABLED
fprintf(stderr,
"Failed to Send Get Event Information Request "
"(exceeds destination maximum APDU)!\n");
"Failed to Send Get Event Information Request "
"(exceeds destination maximum APDU)!\n");
#endif
}
}
@@ -110,8 +110,7 @@ uint8_t Send_Get_Event_Information_Address(
}
uint8_t Send_Get_Event_Information(
uint32_t device_id,
BACNET_OBJECT_ID * lastReceivedObjectIdentifier)
uint32_t device_id, BACNET_OBJECT_ID *lastReceivedObjectIdentifier)
{
BACNET_ADDRESS dest = {0};
unsigned max_apdu = 0;
+43 -46
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* Copyright (C) 2015 bowe
*
* 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.
*
*********************************************************************/
*
* Copyright (C) 2015 bowe
*
* 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>
@@ -46,13 +46,12 @@
/** @file s_getevent.c Send a GetEventInformation request. */
/** Send a GetEventInformation request to a remote network for a specific device, a range,
* or any device.
/** Send a GetEventInformation request to a remote network for a specific
* device, a range, or any device.
* @param target_address [in] BACnet address of target or broadcast
*/
uint8_t Send_GetEvent(
BACNET_ADDRESS * target_address,
BACNET_OBJECT_ID * lastReceivedObjectIdentifier)
uint8_t Send_GetEvent(BACNET_ADDRESS* target_address,
BACNET_OBJECT_ID* lastReceivedObjectIdentifier)
{
int len = 0;
int pdu_len = 0;
@@ -65,29 +64,28 @@ uint8_t Send_GetEvent(
/* encode the NPDU portion of the packet */
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], target_address,
&my_address, &npdu_data);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], target_address,
&my_address, &npdu_data);
invoke_id = tsm_next_free_invokeID();
if (invoke_id) {
/* encode the APDU portion of the packet */
len =
getevent_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id, lastReceivedObjectIdentifier);
len = getevent_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id,
lastReceivedObjectIdentifier);
pdu_len += len;
bytes_sent =
datalink_send_pdu(target_address, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0)
fprintf(stderr, "Failed to Send GetEventInformation Request (%s)!\n",
strerror(errno));
#endif
} else {
tsm_free_invoke_id(invoke_id);
invoke_id = 0;
bytes_sent = datalink_send_pdu(target_address, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0)
fprintf(stderr,
"Failed to Send GetEventInformation Request (%s)!\n",
strerror(errno));
#endif
} else {
tsm_free_invoke_id(invoke_id);
invoke_id = 0;
#if PRINT_ENABLED
fprintf(stderr,
"Failed to Send GetEventInformation Request "
"(exceeds destination maximum APDU)!\n");
#endif
@@ -97,7 +95,7 @@ uint8_t Send_GetEvent(
/** Send a global GetEventInformation request.
*/
uint8_t Send_GetEvent_Global( void )
uint8_t Send_GetEvent_Global(void)
{
BACNET_ADDRESS dest;
@@ -108,4 +106,3 @@ uint8_t Send_GetEvent_Global( void )
return Send_GetEvent(&dest, NULL);
}
+45 -61
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* Copyright (C) 2008 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.
*
*********************************************************************/
*
* Copyright (C) 2008 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>
@@ -51,12 +51,9 @@
* @param segmentation [in] #BACNET_SEGMENTATION enumeration
* @param vendor_id [in] BACnet vendor ID 0-65535
*/
void Send_I_Am_To_Network(
BACNET_ADDRESS * target_address,
uint32_t device_id,
unsigned int max_apdu,
int segmentation,
uint16_t vendor_id)
void Send_I_Am_To_Network(BACNET_ADDRESS* target_address, uint32_t device_id,
unsigned int max_apdu, int segmentation,
uint16_t vendor_id)
{
int len = 0;
int pdu_len = 0;
@@ -68,25 +65,20 @@ void Send_I_Am_To_Network(
/* encode the NPDU portion of the packet */
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], target_address,
&my_address, &npdu_data);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], target_address,
&my_address, &npdu_data);
/* encode the APDU portion of the packet */
/* encode the APDU portion of the packet */
len =
iam_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
device_id, max_apdu, segmentation, vendor_id);
len = iam_encode_apdu(&Handler_Transmit_Buffer[pdu_len], device_id,
max_apdu, segmentation, vendor_id);
pdu_len += len;
bytes_sent =
datalink_send_pdu(target_address, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len);
bytes_sent = datalink_send_pdu(target_address, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len);
if (bytes_sent <= 0) {
#if PRINT_ENABLED
fprintf(stderr, "Failed to Send I-Am Request (%s)!\n",
strerror(errno));
fprintf(stderr, "Failed to Send I-Am Request (%s)!\n", strerror(errno));
#endif
}
}
/** Encode an I Am message to be broadcast.
@@ -95,10 +87,8 @@ void Send_I_Am_To_Network(
* @param npdu_data [out] The NPDU structure describing the message.
* @return The length of the message in buffer[].
*/
int iam_encode_pdu(
uint8_t * buffer,
BACNET_ADDRESS * dest,
BACNET_NPDU_DATA * npdu_data)
int iam_encode_pdu(uint8_t* buffer, BACNET_ADDRESS* dest,
BACNET_NPDU_DATA* npdu_data)
{
int len = 0;
int pdu_len = 0;
@@ -111,9 +101,9 @@ int iam_encode_pdu(
pdu_len = npdu_encode_pdu(&buffer[0], dest, &my_address, npdu_data);
/* encode the APDU portion of the packet */
len =
iam_encode_apdu(&buffer[pdu_len], Device_Object_Instance_Number(),
MAX_APDU, SEGMENTATION_NONE, Device_Vendor_Identifier());
len = iam_encode_apdu(&buffer[pdu_len], Device_Object_Instance_Number(),
MAX_APDU, SEGMENTATION_NONE,
Device_Vendor_Identifier());
pdu_len += len;
return pdu_len;
@@ -124,8 +114,7 @@ int iam_encode_pdu(
*
* @param buffer [in] The buffer to use for building and sending the message.
*/
void Send_I_Am(
uint8_t * buffer)
void Send_I_Am(uint8_t* buffer)
{
int pdu_len = 0;
BACNET_ADDRESS dest;
@@ -165,11 +154,8 @@ void Send_I_Am(
* @param npdu_data [out] The NPDU structure describing the message.
* @return The length of the message in buffer[].
*/
int iam_unicast_encode_pdu(
uint8_t * buffer,
BACNET_ADDRESS * src,
BACNET_ADDRESS * dest,
BACNET_NPDU_DATA * npdu_data)
int iam_unicast_encode_pdu(uint8_t* buffer, BACNET_ADDRESS* src,
BACNET_ADDRESS* dest, BACNET_NPDU_DATA* npdu_data)
{
int npdu_len = 0;
int apdu_len = 0;
@@ -184,9 +170,9 @@ int iam_unicast_encode_pdu(
npdu_encode_npdu_data(npdu_data, false, MESSAGE_PRIORITY_NORMAL);
npdu_len = npdu_encode_pdu(&buffer[0], dest, &my_address, npdu_data);
/* encode the APDU portion of the packet */
apdu_len =
iam_encode_apdu(&buffer[npdu_len], Device_Object_Instance_Number(),
MAX_APDU, SEGMENTATION_NONE, Device_Vendor_Identifier());
apdu_len = iam_encode_apdu(&buffer[npdu_len],
Device_Object_Instance_Number(), MAX_APDU,
SEGMENTATION_NONE, Device_Vendor_Identifier());
pdu_len = npdu_len + apdu_len;
return pdu_len;
@@ -203,9 +189,7 @@ int iam_unicast_encode_pdu(
* @param buffer [in] The buffer to use for building and sending the message.
* @param src [in] The source address information from service handler.
*/
void Send_I_Am_Unicast(
uint8_t * buffer,
BACNET_ADDRESS * src)
void Send_I_Am_Unicast(uint8_t* buffer, BACNET_ADDRESS* src)
{
int pdu_len = 0;
BACNET_ADDRESS dest;
+30 -36
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* 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.
*
*********************************************************************/
*
* 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>
@@ -53,11 +53,8 @@
* @param object_instance [in] The Object ID that I Have.
* @param object_name [in] The Name of the Object I Have.
*/
void Send_I_Have(
uint32_t device_id,
BACNET_OBJECT_TYPE object_type,
uint32_t object_instance,
BACNET_CHARACTER_STRING * object_name)
void Send_I_Have(uint32_t device_id, BACNET_OBJECT_TYPE object_type,
uint32_t object_instance, BACNET_CHARACTER_STRING* object_name)
{
int len = 0;
int pdu_len = 0;
@@ -75,9 +72,8 @@ void Send_I_Have(
datalink_get_broadcast_address(&dest);
/* encode the NPDU portion of the packet */
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address,
&npdu_data);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address,
&npdu_data);
/* encode the APDU portion of the packet */
data.device_id.type = OBJECT_DEVICE;
@@ -88,13 +84,11 @@ void Send_I_Have(
len = ihave_encode_apdu(&Handler_Transmit_Buffer[pdu_len], &data);
pdu_len += len;
/* send the data */
bytes_sent =
datalink_send_pdu(&dest, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
bytes_sent = datalink_send_pdu(&dest, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len);
if (bytes_sent <= 0) {
#if PRINT_ENABLED
fprintf(stderr, "Failed to Send I-Have Reply (%s)!\n",
strerror(errno));
fprintf(stderr, "Failed to Send I-Have Reply (%s)!\n", strerror(errno));
#endif
}
}
+37 -41
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* Copyright (C) 2009 John Minack <minack@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.
*
*********************************************************************/
*
* Copyright (C) 2009 John Minack <minack@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>
@@ -48,10 +48,8 @@
/* returns the invoke ID for confirmed request, or zero on failure */
uint8_t Send_Life_Safety_Operation_Data(
uint32_t device_id,
BACNET_LSO_DATA * data)
uint8_t Send_Life_Safety_Operation_Data(uint32_t device_id,
BACNET_LSO_DATA* data)
{
BACNET_ADDRESS dest;
BACNET_ADDRESS my_address;
@@ -75,36 +73,34 @@ uint8_t Send_Life_Safety_Operation_Data(
/* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address,
&npdu_data);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest,
&my_address, &npdu_data);
len =
lso_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id,
data);
lso_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id, data);
pdu_len += len;
/* will it fit in the sender?
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,
&npdu_data, &Handler_Transmit_Buffer[0], (uint16_t) pdu_len);
bytes_sent =
datalink_send_pdu(&dest, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len);
if ((unsigned)pdu_len < max_apdu) {
tsm_set_confirmed_unsegmented_transaction(
invoke_id, &dest, &npdu_data, &Handler_Transmit_Buffer[0],
(uint16_t)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 Life Safe Op Request (%s)!\n",
strerror(errno));
strerror(errno));
#endif
} else {
tsm_free_invoke_id(invoke_id);
invoke_id = 0;
#if PRINT_ENABLED
fprintf(stderr,
"Failed to Send Life Safe Op Request "
"(exceeds destination maximum APDU)!\n");
"Failed to Send Life Safe Op Request "
"(exceeds destination maximum APDU)!\n");
#endif
}
}
+60 -65
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* 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.
*
*********************************************************************/
*
* 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 <stdlib.h>
#include <stddef.h>
#include <stdint.h>
@@ -48,20 +48,14 @@
/** @file s_ptransfer.c Send a Private Transfer request. */
/* This function is exported. Hence this unnecessary prototype. */
uint8_t Send_Private_Transfer_Request(
uint32_t device_id,
uint16_t vendor_id,
uint32_t service_number,
char block_number,
DATABLOCK * block);
uint8_t Send_Private_Transfer_Request(uint32_t device_id, uint16_t vendor_id,
uint32_t service_number,
char block_number, DATABLOCK *block);
uint8_t Send_Private_Transfer_Request(
uint32_t device_id,
uint16_t vendor_id,
uint32_t service_number,
char block_number,
DATABLOCK * block)
{ /* NULL=optional */
uint8_t Send_Private_Transfer_Request(uint32_t device_id, uint16_t vendor_id,
uint32_t service_number,
char block_number, DATABLOCK *block)
{ /* NULL=optional */
BACNET_ADDRESS dest;
BACNET_ADDRESS my_address;
unsigned max_apdu = 0;
@@ -71,7 +65,8 @@ uint8_t Send_Private_Transfer_Request(
int pdu_len = 0;
int bytes_sent = 0;
BACNET_NPDU_DATA npdu_data;
static uint8_t pt_req_buffer[300]; /* Somewhere to build the request packet */
static uint8_t
pt_req_buffer[300]; /* Somewhere to build the request packet */
BACNET_PRIVATE_TRANSFER_DATA pt_block;
BACNET_CHARACTER_STRING bsTemp;
@@ -88,34 +83,34 @@ uint8_t Send_Private_Transfer_Request(
/* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address,
&npdu_data);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest,
&my_address, &npdu_data);
/* encode the APDU portion of the packet */
pt_block.vendorID = vendor_id;
pt_block.serviceNumber = service_number;
if (service_number == MY_SVC_READ) {
len += encode_application_unsigned(&pt_req_buffer[len], block_number); /* The block number we want to retrieve */
len += encode_application_unsigned(
&pt_req_buffer[len],
block_number); /* The block number we want to retrieve */
} else {
len += encode_application_unsigned(&pt_req_buffer[len], block_number); /* The block number */
len += encode_application_unsigned(&pt_req_buffer[len], block->cMyByte1); /* And Then the block contents */
len +=
encode_application_unsigned(&pt_req_buffer[len],
block->cMyByte2);
len +=
encode_application_real(&pt_req_buffer[len], block->fMyReal);
characterstring_init_ansi(&bsTemp, (char *) block->sMyString);
len +=
encode_application_character_string(&pt_req_buffer[len],
&bsTemp);
len += encode_application_unsigned(
&pt_req_buffer[len], block_number); /* The block number */
len += encode_application_unsigned(
&pt_req_buffer[len],
block->cMyByte1); /* And Then the block contents */
len += encode_application_unsigned(&pt_req_buffer[len],
block->cMyByte2);
len += encode_application_real(&pt_req_buffer[len], block->fMyReal);
characterstring_init_ansi(&bsTemp, (char *)block->sMyString);
len += encode_application_character_string(&pt_req_buffer[len],
&bsTemp);
}
pt_block.serviceParameters = &pt_req_buffer[0];
pt_block.serviceParametersLen = len;
len =
ptransfer_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id,
&pt_block);
len = ptransfer_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
invoke_id, &pt_block);
pdu_len += len;
/* will it fit in the sender?
@@ -124,25 +119,25 @@ uint8_t Send_Private_Transfer_Request(
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,
&npdu_data, &Handler_Transmit_Buffer[0], (uint16_t) pdu_len);
bytes_sent =
datalink_send_pdu(&dest, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len);
if ((unsigned)pdu_len < max_apdu) {
tsm_set_confirmed_unsegmented_transaction(
invoke_id, &dest, &npdu_data, &Handler_Transmit_Buffer[0],
(uint16_t)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 Private Transfer Request (%s)!\n",
strerror(errno));
"Failed to Send Private Transfer Request (%s)!\n",
strerror(errno));
#endif
} else {
tsm_free_invoke_id(invoke_id);
invoke_id = 0;
#if PRINT_ENABLED
fprintf(stderr,
"Failed to Send Private Transfer Request "
"(exceeds destination maximum APDU)!\n");
"Failed to Send Private Transfer Request "
"(exceeds destination maximum APDU)!\n");
#endif
}
}
+42 -44
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* Copyright (C) 2005 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.
*
*********************************************************************/
*
* Copyright (C) 2005 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>
@@ -49,14 +49,14 @@
* @ingroup DMRD
*
* @param device_id [in] The index to the device address in our address cache.
* @param state [in] Specifies the desired state of the device after reinitialization.
* @param state [in] Specifies the desired state of the device after
* reinitialization.
* @param password [in] Optional password, up to 20 chars.
* @return The invokeID of the transmitted message, or 0 on failure.
*/
uint8_t Send_Reinitialize_Device_Request(
uint32_t device_id,
BACNET_REINITIALIZED_STATE state,
char *password)
uint8_t Send_Reinitialize_Device_Request(uint32_t device_id,
BACNET_REINITIALIZED_STATE state,
char *password)
{
BACNET_ADDRESS dest;
BACNET_ADDRESS my_address;
@@ -82,39 +82,37 @@ uint8_t Send_Reinitialize_Device_Request(
/* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address,
&npdu_data);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest,
&my_address, &npdu_data);
/* encode the APDU portion of the packet */
characterstring_init_ansi(&password_string, password);
len =
rd_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id, state,
password ? &password_string : NULL);
len = rd_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id,
state, password ? &password_string : NULL);
pdu_len += len;
/* will it fit in the sender?
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,
&npdu_data, &Handler_Transmit_Buffer[0], (uint16_t) pdu_len);
bytes_sent =
datalink_send_pdu(&dest, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len);
if ((unsigned)pdu_len < max_apdu) {
tsm_set_confirmed_unsegmented_transaction(
invoke_id, &dest, &npdu_data, &Handler_Transmit_Buffer[0],
(uint16_t)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 ReinitializeDevice Request (%s)!\n",
strerror(errno));
"Failed to Send ReinitializeDevice Request (%s)!\n",
strerror(errno));
#endif
} else {
tsm_free_invoke_id(invoke_id);
invoke_id = 0;
#if PRINT_ENABLED
fprintf(stderr,
"Failed to Send ReinitializeDevice Request "
"(exceeds destination maximum APDU)!\n");
"Failed to Send ReinitializeDevice Request "
"(exceeds destination maximum APDU)!\n");
#endif
}
}
+38 -40
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* Copyright (C) 2008 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.
*
*********************************************************************/
*
* Copyright (C) 2008 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>
@@ -47,9 +47,8 @@
/** @file s_readrange.c Send a ReadRange request. */
/* returns invoke id of 0 if device is not bound or no tsm available */
uint8_t Send_ReadRange_Request(
uint32_t device_id, /* destination device */
BACNET_READ_RANGE_DATA * read_access_data)
uint8_t Send_ReadRange_Request(uint32_t device_id, /* destination device */
BACNET_READ_RANGE_DATA* read_access_data)
{
BACNET_ADDRESS dest;
BACNET_ADDRESS my_address;
@@ -74,14 +73,12 @@ uint8_t Send_ReadRange_Request(
/* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address,
&npdu_data);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest,
&my_address, &npdu_data);
/* encode the APDU portion of the packet */
len =
rr_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id,
read_access_data);
len = rr_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id,
read_access_data);
if (len <= 0) {
return 0;
}
@@ -92,23 +89,24 @@ uint8_t Send_ReadRange_Request(
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,
&npdu_data, &Handler_Transmit_Buffer[0], (uint16_t) pdu_len);
bytes_sent =
datalink_send_pdu(&dest, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len);
if ((unsigned)pdu_len < max_apdu) {
tsm_set_confirmed_unsegmented_transaction(
invoke_id, &dest, &npdu_data, &Handler_Transmit_Buffer[0],
(uint16_t)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 ReadRange Request (%s)!\n",
strerror(errno));
strerror(errno));
#endif
} else {
tsm_free_invoke_id(invoke_id);
invoke_id = 0;
#if PRINT_ENABLED
fprintf(stderr,
"Failed to Send ReadRange Request (exceeds destination maximum APDU)!\n");
"Failed to Send ReadRange Request (exceeds destination "
"maximum APDU)!\n");
#endif
}
}
+72 -89
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* Copyright (C) 2005 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.
*
*********************************************************************/
*
* Copyright (C) 2005 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>
@@ -43,7 +43,8 @@
#include "client.h"
#include "debug.h"
/** @file s_router.c Methods to send various BACnet Router Network Layer Messages. */
/** @file s_router.c Methods to send various BACnet Router Network Layer
* Messages. */
/** Initialize an npdu_data structure with given parameters and good defaults,
* and add the Network Layer Message fields.
@@ -52,30 +53,29 @@
* APDU instead of a Network Layer Message.
*
* @param npdu_data [out] Returns a filled-out structure with information
* provided by the other arguments and good defaults.
* provided by the other arguments and
* good defaults.
* @param network_message_type [in] The type of Network Layer Message.
* @param data_expecting_reply [in] True if message should have a reply.
* @param priority [in] One of the 4 priorities defined in section 6.2.2,
* like B'11' = Life Safety message
*/
static void npdu_encode_npdu_network(
BACNET_NPDU_DATA * npdu_data,
BACNET_NETWORK_MESSAGE_TYPE network_message_type,
bool data_expecting_reply,
BACNET_NPDU_DATA *npdu_data,
BACNET_NETWORK_MESSAGE_TYPE network_message_type, bool data_expecting_reply,
BACNET_MESSAGE_PRIORITY priority)
{
if (npdu_data) {
npdu_data->data_expecting_reply = data_expecting_reply;
npdu_data->protocol_version = BACNET_PROTOCOL_VERSION;
npdu_data->network_layer_message = true; /* false if APDU */
npdu_data->network_layer_message = true; /* false if APDU */
npdu_data->network_message_type = network_message_type; /* optional */
npdu_data->vendor_id = 0; /* optional, if net message type is > 0x80 */
npdu_data->vendor_id = 0; /* optional, if net message type is > 0x80 */
npdu_data->priority = priority;
npdu_data->hop_count = HOP_COUNT_DEFAULT;
}
}
/** Function to encode and send any supported Network Layer Message.
* The payload for the message is encoded from information in the iArgs[] array.
* The contents of iArgs are are, per message type:
@@ -97,21 +97,19 @@ static void npdu_encode_npdu_network(
* the type of message.
* @return Number of bytes sent, or <=0 if no message was sent.
*/
int Send_Network_Layer_Message(
BACNET_NETWORK_MESSAGE_TYPE network_message_type,
BACNET_ADDRESS * dst,
int *iArgs)
int Send_Network_Layer_Message(BACNET_NETWORK_MESSAGE_TYPE network_message_type,
BACNET_ADDRESS *dst, int *iArgs)
{
int len = 0;
int pdu_len = 0;
int bytes_sent = 0;
int *pVal = iArgs; /* Start with first value */
int *pVal = iArgs; /* Start with first value */
bool data_expecting_reply = false;
BACNET_NPDU_DATA npdu_data;
BACNET_ADDRESS bcastDest;
if (iArgs == NULL)
return 0; /* Can't do anything here */
return 0; /* Can't do anything here */
/* If dst was NULL, get our (local net) broadcast MAC address. */
if (dst == NULL) {
@@ -120,9 +118,9 @@ int Send_Network_Layer_Message(
}
if (network_message_type == NETWORK_MESSAGE_INIT_RT_TABLE)
data_expecting_reply = true; /* DER in this one case */
data_expecting_reply = true; /* DER in this one case */
npdu_encode_npdu_network(&npdu_data, network_message_type,
data_expecting_reply, MESSAGE_PRIORITY_NORMAL);
data_expecting_reply, MESSAGE_PRIORITY_NORMAL);
/* We don't need src information, since a message can't originate from
* our downstream BACnet network.
@@ -134,9 +132,8 @@ int Send_Network_Layer_Message(
switch (network_message_type) {
case NETWORK_MESSAGE_WHO_IS_ROUTER_TO_NETWORK:
if (*pVal >= 0) {
len =
encode_unsigned16(&Handler_Transmit_Buffer[pdu_len],
(uint16_t) * pVal);
len = encode_unsigned16(&Handler_Transmit_Buffer[pdu_len],
(uint16_t)*pVal);
pdu_len += len;
}
/* else, don't encode a DNET */
@@ -146,9 +143,8 @@ int Send_Network_Layer_Message(
case NETWORK_MESSAGE_ROUTER_BUSY_TO_NETWORK:
case NETWORK_MESSAGE_ROUTER_AVAILABLE_TO_NETWORK:
while (*pVal >= 0) {
len =
encode_unsigned16(&Handler_Transmit_Buffer[pdu_len],
(uint16_t) * pVal);
len = encode_unsigned16(&Handler_Transmit_Buffer[pdu_len],
(uint16_t)*pVal);
pdu_len += len;
pVal++;
}
@@ -156,40 +152,38 @@ int Send_Network_Layer_Message(
case NETWORK_MESSAGE_REJECT_MESSAGE_TO_NETWORK:
/* Encode the Reason byte, then the DNET */
Handler_Transmit_Buffer[pdu_len++] = (uint8_t) * pVal;
Handler_Transmit_Buffer[pdu_len++] = (uint8_t)*pVal;
pVal++;
len =
encode_unsigned16(&Handler_Transmit_Buffer[pdu_len],
(uint16_t) * pVal);
len = encode_unsigned16(&Handler_Transmit_Buffer[pdu_len],
(uint16_t)*pVal);
pdu_len += len;
break;
case NETWORK_MESSAGE_INIT_RT_TABLE:
case NETWORK_MESSAGE_INIT_RT_TABLE_ACK:
/* First, count the number of Ports we will encode */
len = 0; /* Re-purpose len as our counter here */
len = 0; /* Re-purpose len as our counter here */
while (*pVal >= 0) {
len++;
pVal++;
}
Handler_Transmit_Buffer[pdu_len++] = (uint8_t) len;
Handler_Transmit_Buffer[pdu_len++] = (uint8_t)len;
if (len > 0) {
uint8_t portID = 1;
pVal = iArgs; /* Reset to beginning */
pVal = iArgs; /* Reset to beginning */
/* Now encode each (virtual) BACNET_ROUTER_PORT.
* We will simply use a positive index for PortID,
* and have no PortInfo.
*/
while (*pVal >= 0) {
len =
encode_unsigned16(&Handler_Transmit_Buffer[pdu_len],
(uint16_t) * pVal);
len = encode_unsigned16(&Handler_Transmit_Buffer[pdu_len],
(uint16_t)*pVal);
pdu_len += len;
Handler_Transmit_Buffer[pdu_len++] = portID++;
Handler_Transmit_Buffer[pdu_len++] = 0;
debug_printf(" Sending Routing Table entry for %u \n",
*pVal);
*pVal);
pVal++;
}
}
@@ -197,34 +191,33 @@ int Send_Network_Layer_Message(
default:
debug_printf("Not sent: %s message unsupported \n",
bactext_network_layer_msg_name(network_message_type));
bactext_network_layer_msg_name(network_message_type));
return 0;
break; /* Will never reach this line */
break; /* Will never reach this line */
}
if (dst != NULL)
debug_printf("Sending %s message to BACnet network %u \n",
bactext_network_layer_msg_name(network_message_type), dst->net);
bactext_network_layer_msg_name(network_message_type),
dst->net);
else
debug_printf("Sending %s message to local BACnet network \n",
bactext_network_layer_msg_name(network_message_type));
bactext_network_layer_msg_name(network_message_type));
/* Now send the message */
bytes_sent =
datalink_send_pdu(dst, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
bytes_sent = datalink_send_pdu(dst, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0) {
int wasErrno = errno; /* preserve the errno */
int wasErrno = errno; /* preserve the errno */
debug_printf("Failed to send %s message (%s)!\n",
bactext_network_layer_msg_name(network_message_type),
strerror(wasErrno));
bactext_network_layer_msg_name(network_message_type),
strerror(wasErrno));
}
#endif
return bytes_sent;
}
/** Finds a specific router, or all reachable BACnet networks.
* The response(s) will come in I-am-router-to-network message(s).
* @ingroup NMRC
@@ -236,12 +229,10 @@ int Send_Network_Layer_Message(
* will be sent and the receiving router(s) will send
* their full list of reachable BACnet networks.
*/
void Send_Who_Is_Router_To_Network(
BACNET_ADDRESS * dst,
int dnet)
void Send_Who_Is_Router_To_Network(BACNET_ADDRESS *dst, int dnet)
{
Send_Network_Layer_Message(NETWORK_MESSAGE_WHO_IS_ROUTER_TO_NETWORK, dst,
&dnet);
&dnet);
}
/** Broadcast an I-am-router-to-network message, giving the list of networks
@@ -253,12 +244,11 @@ void Send_Who_Is_Router_To_Network(
* @param DNET_list [in] List of BACnet network numbers for which I am a router,
* terminated with -1
*/
void Send_I_Am_Router_To_Network(
const int DNET_list[])
void Send_I_Am_Router_To_Network(const int DNET_list[])
{
/* Use a NULL dst here since we want a broadcast MAC address. */
Send_Network_Layer_Message(NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK, NULL,
(int *) DNET_list);
(int *)DNET_list);
}
/** Finds a specific router, or all reachable BACnet networks.
@@ -271,20 +261,17 @@ void Send_I_Am_Router_To_Network(
* @param reject_reason [in] One of the BACNET_NETWORK_REJECT_REASONS codes.
* @param dnet [in] Which BACnet network orginated the message.
*/
void Send_Reject_Message_To_Network(
BACNET_ADDRESS * dst,
uint8_t reject_reason,
int dnet)
void Send_Reject_Message_To_Network(BACNET_ADDRESS *dst, uint8_t reject_reason,
int dnet)
{
int iArgs[2];
iArgs[0] = reject_reason;
iArgs[1] = dnet;
Send_Network_Layer_Message(NETWORK_MESSAGE_REJECT_MESSAGE_TO_NETWORK, dst,
iArgs);
iArgs);
debug_printf(" Reject Reason=%d, DNET=%u\n", reject_reason, dnet);
}
/** Send an Initialize Routing Table message, built from an optional DNET[]
* array.
* There are two cases here:
@@ -301,16 +288,13 @@ void Send_Reject_Message_To_Network(
* terminated with -1. Will be just -1 when we are
* requesting a routing table.
*/
void Send_Initialize_Routing_Table(
BACNET_ADDRESS * dst,
const int DNET_list[])
void Send_Initialize_Routing_Table(BACNET_ADDRESS *dst, const int DNET_list[])
{
/* Use a NULL dst here since we want a broadcast MAC address. */
Send_Network_Layer_Message(NETWORK_MESSAGE_INIT_RT_TABLE, dst,
(int *) DNET_list);
(int *)DNET_list);
}
/** Sends our Routing Table, built from our DNET[] array, as an ACK.
* There are two cases here:
* 1) We are responding to a NETWORK_MESSAGE_INIT_RT_TABLE requesting our table.
@@ -328,10 +312,9 @@ void Send_Initialize_Routing_Table(
* terminated with -1. May be just -1 when no table
* should be sent.
*/
void Send_Initialize_Routing_Table_Ack(
BACNET_ADDRESS * dst,
const int DNET_list[])
void Send_Initialize_Routing_Table_Ack(BACNET_ADDRESS *dst,
const int DNET_list[])
{
Send_Network_Layer_Message(NETWORK_MESSAGE_INIT_RT_TABLE_ACK, dst,
(int *) DNET_list);
(int *)DNET_list);
}
+58 -58
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* Copyright (C) 2005 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.
*
*********************************************************************/
*
* Copyright (C) 2005 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>
@@ -52,20 +52,21 @@
* @param max_apdu [in]
* @param object_type [in] Type of the object whose property is to be read.
* @param object_instance [in] Instance # of the object to be read.
* @param object_property [in] Property to be read, but not ALL, REQUIRED, or OPTIONAL.
* @param object_property [in] Property to be read, but not ALL, REQUIRED, or
* OPTIONAL.
* @param array_index [in] Optional: if the Property is an array,
* - 0 for the array size
* - 1 to n for individual array members
* - BACNET_ARRAY_ALL (~0) for the full array to be read.
* @return invoke id of outgoing message, or 0 if device is not bound or no tsm available
* @return invoke id of outgoing message, or 0 if device is not bound or no tsm
* available
*/
uint8_t Send_Read_Property_Request_Address(
BACNET_ADDRESS * dest,
uint16_t max_apdu,
BACNET_OBJECT_TYPE object_type,
uint32_t object_instance,
BACNET_PROPERTY_ID object_property,
uint32_t array_index)
uint8_t Send_Read_Property_Request_Address(BACNET_ADDRESS* dest,
uint16_t max_apdu,
BACNET_OBJECT_TYPE object_type,
uint32_t object_instance,
BACNET_PROPERTY_ID object_property,
uint32_t array_index)
{
BACNET_ADDRESS my_address;
uint8_t invoke_id = 0;
@@ -87,33 +88,31 @@ uint8_t Send_Read_Property_Request_Address(
/* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], dest, &my_address,
&npdu_data);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], dest,
&my_address, &npdu_data);
/* encode the APDU portion of the packet */
data.object_type = object_type;
data.object_instance = object_instance;
data.object_property = object_property;
data.array_index = array_index;
len =
rp_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id,
&data);
rp_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id, &data);
pdu_len += len;
/* will it fit in the sender?
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 ((uint16_t) pdu_len < max_apdu) {
tsm_set_confirmed_unsegmented_transaction(invoke_id, dest,
&npdu_data, &Handler_Transmit_Buffer[0], (uint16_t) pdu_len);
bytes_sent =
datalink_send_pdu(dest, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len);
if ((uint16_t)pdu_len < max_apdu) {
tsm_set_confirmed_unsegmented_transaction(
invoke_id, dest, &npdu_data, &Handler_Transmit_Buffer[0],
(uint16_t)pdu_len);
bytes_sent = datalink_send_pdu(
dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
if (bytes_sent <= 0) {
#if PRINT_ENABLED
fprintf(stderr, "Failed to Send ReadProperty Request (%s)!\n",
strerror(errno));
strerror(errno));
#endif
}
} else {
@@ -121,8 +120,8 @@ uint8_t Send_Read_Property_Request_Address(
invoke_id = 0;
#if PRINT_ENABLED
fprintf(stderr,
"Failed to Send ReadProperty Request "
"(exceeds destination maximum APDU)!\n");
"Failed to Send ReadProperty Request "
"(exceeds destination maximum APDU)!\n");
#endif
}
}
@@ -136,21 +135,22 @@ uint8_t Send_Read_Property_Request_Address(
* @param device_id [in] ID of the destination device
* @param object_type [in] Type of the object whose property is to be read.
* @param object_instance [in] Instance # of the object to be read.
* @param object_property [in] Property to be read, but not ALL, REQUIRED, or OPTIONAL.
* @param object_property [in] Property to be read, but not ALL, REQUIRED, or
* OPTIONAL.
* @param array_index [in] Optional: if the Property is an array,
* - 0 for the array size
* - 1 to n for individual array members
* - BACNET_ARRAY_ALL (~0) for the full array to be read.
* @return invoke id of outgoing message, or 0 if device is not bound or no tsm available
* @return invoke id of outgoing message, or 0 if device is not bound or no tsm
* available
*/
uint8_t Send_Read_Property_Request(
uint32_t device_id, /* destination device */
BACNET_OBJECT_TYPE object_type,
uint32_t object_instance,
BACNET_PROPERTY_ID object_property,
uint32_t array_index)
uint8_t Send_Read_Property_Request(uint32_t device_id, /* destination device */
BACNET_OBJECT_TYPE object_type,
uint32_t object_instance,
BACNET_PROPERTY_ID object_property,
uint32_t array_index)
{
BACNET_ADDRESS dest = { 0 };
BACNET_ADDRESS dest = {0};
unsigned max_apdu = 0;
uint8_t invoke_id = 0;
bool status = false;
@@ -158,9 +158,9 @@ uint8_t Send_Read_Property_Request(
/* is the device bound? */
status = address_get_by_device(device_id, &max_apdu, &dest);
if (status) {
invoke_id =
Send_Read_Property_Request_Address(&dest, max_apdu, object_type,
object_instance, object_property, array_index);
invoke_id = Send_Read_Property_Request_Address(
&dest, max_apdu, object_type, object_instance, object_property,
array_index);
}
return invoke_id;
+37 -40
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* Copyright (C) 2008 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.
*
*********************************************************************/
*
* Copyright (C) 2008 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>
@@ -53,13 +53,12 @@
* @param device_id [in] ID of the destination device
* @param read_access_data [in] Ptr to structure with the linked list of
* properties to be read.
* @return invoke id of outgoing message, or 0 if device is not bound or no tsm available
* @return invoke id of outgoing message, or 0 if device is not bound or no tsm
* available
*/
uint8_t Send_Read_Property_Multiple_Request(
uint8_t * pdu,
size_t max_pdu,
uint32_t device_id, /* destination device */
BACNET_READ_ACCESS_DATA * read_access_data)
uint8_t* pdu, size_t max_pdu, uint32_t device_id, /* destination device */
BACNET_READ_ACCESS_DATA* read_access_data)
{
BACNET_ADDRESS dest;
BACNET_ADDRESS my_address;
@@ -85,9 +84,8 @@ uint8_t Send_Read_Property_Multiple_Request(
npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL);
pdu_len = npdu_encode_pdu(&pdu[0], &dest, &my_address, &npdu_data);
/* encode the APDU portion of the packet */
len =
rpm_encode_apdu(&pdu[pdu_len], max_pdu - pdu_len, invoke_id,
read_access_data);
len = rpm_encode_apdu(&pdu[pdu_len], max_pdu - pdu_len, invoke_id,
read_access_data);
if (len <= 0) {
return 0;
}
@@ -97,24 +95,23 @@ uint8_t Send_Read_Property_Multiple_Request(
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,
&npdu_data, &pdu[0], (uint16_t) pdu_len);
bytes_sent =
datalink_send_pdu(&dest, &npdu_data, &pdu[0], pdu_len);
if ((unsigned)pdu_len < max_apdu) {
tsm_set_confirmed_unsegmented_transaction(
invoke_id, &dest, &npdu_data, &pdu[0], (uint16_t)pdu_len);
bytes_sent = datalink_send_pdu(&dest, &npdu_data, &pdu[0], pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0)
fprintf(stderr,
"Failed to Send ReadPropertyMultiple Request (%s)!\n",
strerror(errno));
"Failed to Send ReadPropertyMultiple Request (%s)!\n",
strerror(errno));
#endif
} else {
tsm_free_invoke_id(invoke_id);
invoke_id = 0;
#if PRINT_ENABLED
fprintf(stderr,
"Failed to Send ReadPropertyMultiple Request "
"(exceeds destination maximum APDU)!\n");
"Failed to Send ReadPropertyMultiple Request "
"(exceeds destination maximum APDU)!\n");
#endif
}
}
+43 -57
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* Copyright (C) 2005 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.
*
*********************************************************************/
*
* Copyright (C) 2005 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>
@@ -52,10 +52,8 @@
* @param bdate - #BACNET_DATE
* @param btime - #BACNET_TIME
*/
void Send_TimeSync_Remote(
BACNET_ADDRESS * dest,
BACNET_DATE * bdate,
BACNET_TIME * btime)
void Send_TimeSync_Remote(BACNET_ADDRESS* dest, BACNET_DATE* bdate,
BACNET_TIME* btime)
{
int len = 0;
int pdu_len = 0;
@@ -69,21 +67,18 @@ void Send_TimeSync_Remote(
datalink_get_my_address(&my_address);
/* encode the NPDU portion of the packet */
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], dest, &my_address,
&npdu_data);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], dest, &my_address,
&npdu_data);
/* encode the APDU portion of the packet */
len =
timesync_encode_apdu(&Handler_Transmit_Buffer[pdu_len], bdate, btime);
len = timesync_encode_apdu(&Handler_Transmit_Buffer[pdu_len], bdate, btime);
pdu_len += len;
/* send it out the datalink */
bytes_sent =
datalink_send_pdu(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 Time-Synchronization Request (%s)!\n",
strerror(errno));
strerror(errno));
#endif
}
@@ -93,9 +88,7 @@ void Send_TimeSync_Remote(
* @param bdate - #BACNET_DATE
* @param btime - #BACNET_TIME
*/
void Send_TimeSync(
BACNET_DATE * bdate,
BACNET_TIME * btime)
void Send_TimeSync(BACNET_DATE* bdate, BACNET_TIME* btime)
{
BACNET_ADDRESS dest;
@@ -110,10 +103,8 @@ void Send_TimeSync(
* @param bdate - #BACNET_DATE
* @param btime - #BACNET_TIME
*/
void Send_TimeSyncUTC_Remote(
BACNET_ADDRESS * dest,
BACNET_DATE * bdate,
BACNET_TIME * btime)
void Send_TimeSyncUTC_Remote(BACNET_ADDRESS* dest, BACNET_DATE* bdate,
BACNET_TIME* btime)
{
int len = 0;
int pdu_len = 0;
@@ -127,22 +118,19 @@ void Send_TimeSyncUTC_Remote(
datalink_get_my_address(&my_address);
/* encode the NPDU portion of the packet */
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], dest, &my_address,
&npdu_data);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], dest, &my_address,
&npdu_data);
/* encode the APDU portion of the packet */
len =
timesync_utc_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
bdate, btime);
len = timesync_utc_encode_apdu(&Handler_Transmit_Buffer[pdu_len], bdate,
btime);
pdu_len += len;
bytes_sent =
datalink_send_pdu(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 UTC-Time-Synchronization Request (%s)!\n",
strerror(errno));
"Failed to Send UTC-Time-Synchronization Request (%s)!\n",
strerror(errno));
#endif
}
@@ -152,9 +140,7 @@ void Send_TimeSyncUTC_Remote(
* @param bdate - #BACNET_DATE
* @param btime - #BACNET_TIME
*/
void Send_TimeSyncUTC(
BACNET_DATE * bdate,
BACNET_TIME * btime)
void Send_TimeSyncUTC(BACNET_DATE* bdate, BACNET_TIME* btime)
{
BACNET_ADDRESS dest;
+25 -27
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* Copyright (C) 2008 John Minack
*
* 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.
*
*********************************************************************/
*
* Copyright (C) 2008 John Minack
*
* 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>
@@ -40,10 +40,8 @@
* @param dest [in] The destination address information (may be a broadcast).
* @return Size of the message sent (bytes), or a negative value on error.
*/
int Send_UEvent_Notify(
uint8_t * buffer,
BACNET_EVENT_NOTIFICATION_DATA * data,
BACNET_ADDRESS * dest)
int Send_UEvent_Notify(uint8_t* buffer, BACNET_EVENT_NOTIFICATION_DATA* data,
BACNET_ADDRESS* dest)
{
int len = 0;
int pdu_len = 0;
+32 -36
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* Copyright (C) 2009 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.
*
*********************************************************************/
*
* Copyright (C) 2009 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>
@@ -45,9 +45,8 @@
/** @file s_upt.c Send an Unconfirmed Private Transfer request. */
int Send_UnconfirmedPrivateTransfer(
BACNET_ADDRESS * dest,
BACNET_PRIVATE_TRANSFER_DATA * private_data)
int Send_UnconfirmedPrivateTransfer(BACNET_ADDRESS* dest,
BACNET_PRIVATE_TRANSFER_DATA* private_data)
{
int len = 0;
int pdu_len = 0;
@@ -61,23 +60,20 @@ int Send_UnconfirmedPrivateTransfer(
datalink_get_my_address(&my_address);
/* encode the NPDU portion of the packet */
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], dest, &my_address,
&npdu_data);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], dest, &my_address,
&npdu_data);
/* encode the APDU portion of the packet */
len =
uptransfer_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
private_data);
uptransfer_encode_apdu(&Handler_Transmit_Buffer[pdu_len], private_data);
pdu_len += len;
bytes_sent =
datalink_send_pdu(dest, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
bytes_sent = datalink_send_pdu(dest, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len);
if (bytes_sent <= 0) {
#if PRINT_ENABLED
fprintf(stderr,
"Failed to Send UnconfirmedPrivateTransfer Request (%s)!\n",
strerror(errno));
"Failed to Send UnconfirmedPrivateTransfer Request (%s)!\n",
strerror(errno));
#endif
}
+46 -54
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* 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.
*
*********************************************************************/
*
* 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>
@@ -47,18 +47,16 @@
/** Send a Who-Has request for a device which has a named Object.
* @ingroup DMDOB
* If low_limit and high_limit both are -1, then the device ID range is unlimited.
* If low_limit and high_limit have the same non-negative value, then only
* that device will respond.
* Otherwise, low_limit must be less than high_limit for a range.
* If low_limit and high_limit both are -1, then the device ID range is
* unlimited. If low_limit and high_limit have the same non-negative value, then
* only that device will respond. Otherwise, low_limit must be less than
* high_limit for a range.
* @param low_limit [in] Device Instance Low Range, 0 - 4,194,303 or -1
* @param high_limit [in] Device Instance High Range, 0 - 4,194,303 or -1
* @param object_name [in] The Name of the desired Object.
*/
void Send_WhoHas_Name(
int32_t low_limit,
int32_t high_limit,
const char *object_name)
void Send_WhoHas_Name(int32_t low_limit, int32_t high_limit,
const char *object_name)
{
int len = 0;
int pdu_len = 0;
@@ -76,9 +74,8 @@ void Send_WhoHas_Name(
datalink_get_my_address(&my_address);
/* encode the NPDU portion of the packet */
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address,
&npdu_data);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address,
&npdu_data);
/* encode the APDU portion of the packet */
data.low_limit = low_limit;
@@ -88,32 +85,29 @@ void Send_WhoHas_Name(
len = whohas_encode_apdu(&Handler_Transmit_Buffer[pdu_len], &data);
pdu_len += len;
/* send the data */
bytes_sent =
datalink_send_pdu(&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 Who-Has Request (%s)!\n",
strerror(errno));
strerror(errno));
#endif
}
/** Send a Who-Has request for a device which has a specific Object type and ID.
* @ingroup DMDOB
* If low_limit and high_limit both are -1, then the device ID range is unlimited.
* If low_limit and high_limit have the same non-negative value, then only
* that device will respond.
* Otherwise, low_limit must be less than high_limit for a range.
* If low_limit and high_limit both are -1, then the device ID range is
* unlimited. If low_limit and high_limit have the same non-negative value, then
* only that device will respond. Otherwise, low_limit must be less than
* high_limit for a range.
* @param low_limit [in] Device Instance Low Range, 0 - 4,194,303 or -1
* @param high_limit [in] Device Instance High Range, 0 - 4,194,303 or -1
* @param object_type [in] The BACNET_OBJECT_TYPE of the desired Object.
* @param object_instance [in] The ID of the desired Object.
*/
void Send_WhoHas_Object(
int32_t low_limit,
int32_t high_limit,
BACNET_OBJECT_TYPE object_type,
uint32_t object_instance)
void Send_WhoHas_Object(int32_t low_limit, int32_t high_limit,
BACNET_OBJECT_TYPE object_type,
uint32_t object_instance)
{
int len = 0;
int pdu_len = 0;
@@ -131,9 +125,8 @@ void Send_WhoHas_Object(
datalink_get_my_address(&my_address);
/* encode the NPDU portion of the packet */
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address,
&npdu_data);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address,
&npdu_data);
/* encode the APDU portion of the packet */
data.low_limit = low_limit;
@@ -143,12 +136,11 @@ void Send_WhoHas_Object(
data.object.identifier.instance = object_instance;
len = whohas_encode_apdu(&Handler_Transmit_Buffer[pdu_len], &data);
pdu_len += len;
bytes_sent =
datalink_send_pdu(&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 Who-Has Request (%s)!\n",
strerror(errno));
strerror(errno));
#endif
}
+39 -52
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* Copyright (C) 2005 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.
*
*********************************************************************/
*
* Copyright (C) 2005 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>
@@ -56,10 +56,8 @@
* @param low_limit [in] Device Instance Low Range, 0 - 4,194,303 or -1
* @param high_limit [in] Device Instance High Range, 0 - 4,194,303 or -1
*/
void Send_WhoIs_To_Network(
BACNET_ADDRESS * target_address,
int32_t low_limit,
int32_t high_limit)
void Send_WhoIs_To_Network(BACNET_ADDRESS* target_address, int32_t low_limit,
int32_t high_limit)
{
int len = 0;
int pdu_len = 0;
@@ -71,21 +69,18 @@ void Send_WhoIs_To_Network(
/* encode the NPDU portion of the packet */
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], target_address,
&my_address, &npdu_data);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], target_address,
&my_address, &npdu_data);
/* encode the APDU portion of the packet */
len =
whois_encode_apdu(&Handler_Transmit_Buffer[pdu_len], low_limit,
high_limit);
len = whois_encode_apdu(&Handler_Transmit_Buffer[pdu_len], low_limit,
high_limit);
pdu_len += len;
bytes_sent =
datalink_send_pdu(target_address, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len);
bytes_sent = datalink_send_pdu(target_address, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0)
fprintf(stderr, "Failed to Send Who-Is Request (%s)!\n",
strerror(errno));
strerror(errno));
#endif
}
@@ -97,9 +92,7 @@ void Send_WhoIs_To_Network(
* @param low_limit [in] Device Instance Low Range, 0 - 4,194,303 or -1
* @param high_limit [in] Device Instance High Range, 0 - 4,194,303 or -1
*/
void Send_WhoIs_Global(
int32_t low_limit,
int32_t high_limit)
void Send_WhoIs_Global(int32_t low_limit, int32_t high_limit)
{
BACNET_ADDRESS dest;
@@ -120,9 +113,7 @@ void Send_WhoIs_Global(
* @param low_limit [in] Device Instance Low Range, 0 - 4,194,303 or -1
* @param high_limit [in] Device Instance High Range, 0 - 4,194,303 or -1
*/
void Send_WhoIs_Local(
int32_t low_limit,
int32_t high_limit)
void Send_WhoIs_Local(int32_t low_limit, int32_t high_limit)
{
BACNET_ADDRESS dest;
char temp[6];
@@ -138,7 +129,8 @@ void Send_WhoIs_Local(
/* I added this to make it a local broadcast */
dest.net = 0;
/* Not sure why this happens but values are backwards so they need to be reversed */
/* Not sure why this happens but values are backwards so they need to be
* reversed */
temp[0] = dest.mac[3];
temp[1] = dest.mac[2];
@@ -147,7 +139,6 @@ void Send_WhoIs_Local(
temp[4] = dest.mac[5];
temp[5] = dest.mac[4];
for (loop = 0; loop < 6; loop++) {
dest.mac[loop] = temp[loop];
}
@@ -166,10 +157,8 @@ void Send_WhoIs_Local(
* @param low_limit [in] Device Instance Low Range, 0 - 4,194,303 or -1
* @param high_limit [in] Device Instance High Range, 0 - 4,194,303 or -1
*/
void Send_WhoIs_Remote(
BACNET_ADDRESS * target_address,
int32_t low_limit,
int32_t high_limit)
void Send_WhoIs_Remote(BACNET_ADDRESS* target_address, int32_t low_limit,
int32_t high_limit)
{
if (!dcc_communication_enabled())
return;
@@ -189,9 +178,7 @@ void Send_WhoIs_Remote(
* @param low_limit [in] Device Instance Low Range, 0 - 4,194,303 or -1
* @param high_limit [in] Device Instance High Range, 0 - 4,194,303 or -1
*/
void Send_WhoIs(
int32_t low_limit,
int32_t high_limit)
void Send_WhoIs(int32_t low_limit, int32_t high_limit)
{
Send_WhoIs_Global(low_limit, high_limit);
}
+59 -65
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* Copyright (C) 2005 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.
*
*********************************************************************/
*
* Copyright (C) 2005 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>
@@ -46,15 +46,13 @@
/** @file s_wp.c Send a Write Property request. */
/** returns the invoke ID for confirmed request, or zero on failure */
uint8_t Send_Write_Property_Request_Data(
uint32_t device_id,
BACNET_OBJECT_TYPE object_type,
uint32_t object_instance,
BACNET_PROPERTY_ID object_property,
uint8_t * application_data,
int application_data_len,
uint8_t priority,
uint32_t array_index)
uint8_t Send_Write_Property_Request_Data(uint32_t device_id,
BACNET_OBJECT_TYPE object_type,
uint32_t object_instance,
BACNET_PROPERTY_ID object_property,
uint8_t* application_data,
int application_data_len,
uint8_t priority, uint32_t array_index)
{
BACNET_ADDRESS dest;
BACNET_ADDRESS my_address;
@@ -79,9 +77,8 @@ uint8_t Send_Write_Property_Request_Data(
/* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address,
&npdu_data);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest,
&my_address, &npdu_data);
/* encode the APDU portion of the packet */
data.object_type = object_type;
data.object_instance = object_instance;
@@ -89,35 +86,34 @@ uint8_t Send_Write_Property_Request_Data(
data.array_index = array_index;
data.application_data_len = application_data_len;
memcpy(&data.application_data[0], &application_data[0],
application_data_len);
application_data_len);
data.priority = priority;
len =
wp_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id,
&data);
wp_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id, &data);
pdu_len += len;
/* will it fit in the sender?
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,
&npdu_data, &Handler_Transmit_Buffer[0], (uint16_t) pdu_len);
bytes_sent =
datalink_send_pdu(&dest, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len);
if ((unsigned)pdu_len < max_apdu) {
tsm_set_confirmed_unsegmented_transaction(
invoke_id, &dest, &npdu_data, &Handler_Transmit_Buffer[0],
(uint16_t)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 WriteProperty Request (%s)!\n",
strerror(errno));
strerror(errno));
#endif
} else {
tsm_free_invoke_id(invoke_id);
invoke_id = 0;
#if PRINT_ENABLED
fprintf(stderr,
"Failed to Send WriteProperty Request "
"(exceeds destination maximum APDU)!\n");
"Failed to Send WriteProperty Request "
"(exceeds destination maximum APDU)!\n");
#endif
}
}
@@ -125,7 +121,6 @@ uint8_t Send_Write_Property_Request_Data(
return invoke_id;
}
/** Sends a Write Property request.
* @ingroup DSWP
*
@@ -141,25 +136,24 @@ uint8_t Send_Write_Property_Request_Data(
* - BACNET_ARRAY_ALL (~0) for the array value to be ignored (not sent)
* @return invoke id of outgoing message, or 0 on failure.
*/
uint8_t Send_Write_Property_Request(
uint32_t device_id,
BACNET_OBJECT_TYPE object_type,
uint32_t object_instance,
BACNET_PROPERTY_ID object_property,
BACNET_APPLICATION_DATA_VALUE * object_value,
uint8_t priority,
uint32_t array_index)
uint8_t Send_Write_Property_Request(uint32_t device_id,
BACNET_OBJECT_TYPE object_type,
uint32_t object_instance,
BACNET_PROPERTY_ID object_property,
BACNET_APPLICATION_DATA_VALUE* object_value,
uint8_t priority, uint32_t array_index)
{
uint8_t application_data[MAX_APDU] = { 0 };
uint8_t application_data[MAX_APDU] = {0};
int apdu_len = 0, len = 0;
while (object_value) {
#if PRINT_ENABLED_DEBUG
fprintf(stderr, "WriteProperty service: " "%s tag=%d\n",
(object_value->context_specific ? "context" : "application"),
(int) (object_value->
context_specific ? object_value->context_tag : object_value->
tag));
fprintf(stderr,
"WriteProperty service: "
"%s tag=%d\n",
(object_value->context_specific ? "context" : "application"),
(int)(object_value->context_specific ? object_value->context_tag
: object_value->tag));
#endif
len = bacapp_encode_data(&application_data[apdu_len], object_value);
if ((len + apdu_len) < MAX_APDU) {
@@ -170,7 +164,7 @@ uint8_t Send_Write_Property_Request(
object_value = object_value->next;
}
return Send_Write_Property_Request_Data(device_id, object_type,
object_instance, object_property, &application_data[0], apdu_len,
priority, array_index);
return Send_Write_Property_Request_Data(
device_id, object_type, object_instance, object_property,
&application_data[0], apdu_len, priority, array_index);
}
+43 -47
View File
@@ -1,32 +1,32 @@
/**
* @file
* @author Daniel Blazevic <daniel.blazevic@gmail.com>
* @date 2013
* @brief Send Write Property Multiple request
*
* @section LICENSE
*
* Copyright (C) 2013 Daniel Blazevic <daniel.blazevic@gmail.com>
*
* 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.
*/
* @file
* @author Daniel Blazevic <daniel.blazevic@gmail.com>
* @date 2013
* @brief Send Write Property Multiple request
*
* @section LICENSE
*
* Copyright (C) 2013 Daniel Blazevic <daniel.blazevic@gmail.com>
*
* 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>
@@ -55,13 +55,12 @@
* @param device_id [in] ID of the destination device
* @param write_access_data [in] Ptr to structure with the linked list of
* objects and properties to be written.
* @return invoke id of outgoing message, or 0 if device is not bound or no tsm available
* @return invoke id of outgoing message, or 0 if device is not bound or no tsm
* available
*/
uint8_t Send_Write_Property_Multiple_Request(
uint8_t * pdu,
size_t max_pdu,
uint32_t device_id,
BACNET_WRITE_ACCESS_DATA * write_access_data)
uint8_t* pdu, size_t max_pdu, uint32_t device_id,
BACNET_WRITE_ACCESS_DATA* write_access_data)
{
BACNET_ADDRESS dest;
BACNET_ADDRESS my_address;
@@ -87,11 +86,10 @@ uint8_t Send_Write_Property_Multiple_Request(
/* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL);
pdu_len = npdu_encode_pdu(&pdu[0], &dest, &my_address,&npdu_data);
pdu_len = npdu_encode_pdu(&pdu[0], &dest, &my_address, &npdu_data);
/* encode the APDU portion of the packet */
len =
wpm_encode_apdu(&pdu[pdu_len], max_pdu - pdu_len,
invoke_id, write_access_data);
len = wpm_encode_apdu(&pdu[pdu_len], max_pdu - pdu_len, invoke_id,
write_access_data);
pdu_len += len;
/* will it fit in the sender?
@@ -99,17 +97,15 @@ uint8_t Send_Write_Property_Multiple_Request(
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,
&npdu_data, &pdu[0], (uint16_t) pdu_len);
bytes_sent =
datalink_send_pdu(&dest, &npdu_data,
&pdu[0], pdu_len);
if ((unsigned)pdu_len < max_apdu) {
tsm_set_confirmed_unsegmented_transaction(
invoke_id, &dest, &npdu_data, &pdu[0], (uint16_t)pdu_len);
bytes_sent = datalink_send_pdu(&dest, &npdu_data, &pdu[0], pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0) {
fprintf(stderr,
"Failed to Send WritePropertyMultiple Request (%s)!\n",
strerror(errno));
"Failed to Send WritePropertyMultiple Request (%s)!\n",
strerror(errno));
}
#endif
} else {
@@ -117,8 +113,8 @@ uint8_t Send_Write_Property_Multiple_Request(
invoke_id = 0;
#if PRINT_ENABLED
fprintf(stderr,
"Failed to Send WritePropertyMultiple Request "
"(exceeds destination maximum APDU)!\n");
"Failed to Send WritePropertyMultiple Request "
"(exceeds destination maximum APDU)!\n");
#endif
}
}
+24 -24
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* Copyright (C) 2005 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.
*
*********************************************************************/
*
* Copyright (C) 2005 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 "config.h"
@@ -29,4 +29,4 @@
/** @file txbuf.c Declare the global Transmit Buffer for handler functions. */
uint8_t Handler_Transmit_Buffer[MAX_PDU] = { 0 };
uint8_t Handler_Transmit_Buffer[MAX_PDU] = {0};