adjust root folder

This commit is contained in:
Steve Karg
2019-10-08 23:47:53 -05:00
parent b6fc50ddea
commit a42e8f507c
1258 changed files with 26 additions and 214 deletions
+65
View File
@@ -0,0 +1,65 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef ABORT_H
#define ABORT_H
#include <stdint.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
BACNET_ABORT_REASON abort_convert_error_code(
BACNET_ERROR_CODE error_code);
int abort_encode_apdu(
uint8_t * apdu,
uint8_t invoke_id,
uint8_t abort_reason,
bool server);
int abort_decode_service_request(
uint8_t * apdu,
unsigned apdu_len,
uint8_t * invoke_id,
uint8_t * abort_reason);
#ifdef TEST
#include "ctest.h"
int abort_decode_apdu(
uint8_t * apdu,
unsigned apdu_len,
uint8_t * invoke_id,
uint8_t * abort_reason,
bool * server);
void testAbort(
Test * pTest);
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+76
View File
@@ -0,0 +1,76 @@
/**************************************************************************
*
* Copyright (C) 2015 Nikola Jelic <nikola.jelic@euroicc.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.
*
*********************************************************************/
#ifndef ACCESS_RULE_H
#define ACCESS_RULE_H
#include <stdbool.h>
#include <stdint.h>
#include "bacdef.h"
#include "bacapp.h"
#include "bacdevobjpropref.h"
typedef enum {
TIME_RANGE_SPECIFIER_SPECIFIED = 0,
TIME_RANGE_SPECIFIER_ALWAYS = 1
} BACNET_ACCESS_RULE_TIME_RANGE_SPECIFIER;
typedef enum {
LOCATION_SPECIFIER_SPECIFIED = 0,
LOCATION_SPECIFIER_ALL = 1
} BACNET_ACCESS_RULE_LOCATION_SPECIFIER;
typedef struct {
BACNET_ACCESS_RULE_TIME_RANGE_SPECIFIER time_range_specifier;
BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE time_range;
BACNET_ACCESS_RULE_LOCATION_SPECIFIER location_specifier;
BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE location;
bool enable;
} BACNET_ACCESS_RULE;
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
int bacapp_encode_access_rule(
uint8_t * apdu,
BACNET_ACCESS_RULE * rule);
int bacapp_encode_context_access_rule(
uint8_t * apdu,
uint8_t tag_number,
BACNET_ACCESS_RULE * rule);
int bacapp_decode_access_rule(
uint8_t * apdu,
BACNET_ACCESS_RULE * rule);
int bacapp_decode_context_access_rule(
uint8_t * apdu,
uint8_t tag_number,
BACNET_ACCESS_RULE * rule);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+127
View File
@@ -0,0 +1,127 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef ADDRESS_H
#define ADDRESS_H
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include "bacdef.h"
#include "readrange.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
void address_init(
void);
void address_init_partial(
void);
void address_add(
uint32_t device_id,
unsigned max_apdu,
BACNET_ADDRESS * src);
void address_remove_device(
uint32_t device_id);
bool address_get_by_device(
uint32_t device_id,
unsigned *max_apdu,
BACNET_ADDRESS * src);
bool address_get_by_index(
unsigned index,
uint32_t * device_id,
unsigned *max_apdu,
BACNET_ADDRESS * src);
bool address_device_get_by_index(
unsigned index,
uint32_t * device_id,
uint32_t * device_ttl,
unsigned *max_apdu,
BACNET_ADDRESS * src);
bool address_get_device_id(
BACNET_ADDRESS * src,
uint32_t * device_id);
unsigned address_count(
void);
bool address_match(
BACNET_ADDRESS * dest,
BACNET_ADDRESS * src);
bool address_bind_request(
uint32_t device_id,
unsigned *max_apdu,
BACNET_ADDRESS * src);
bool address_device_bind_request(
uint32_t device_id,
uint32_t * device_ttl,
unsigned *max_apdu,
BACNET_ADDRESS * src);
void address_add_binding(
uint32_t device_id,
unsigned max_apdu,
BACNET_ADDRESS * src);
int address_list_encode(
uint8_t * apdu,
unsigned apdu_len);
int rr_address_list_encode(
uint8_t * apdu,
BACNET_READ_RANGE_DATA * pRequest);
void address_set_device_TTL(
uint32_t device_id,
uint32_t TimeOut,
bool StaticFlag);
void address_cache_timer(
uint16_t uSeconds);
void address_mac_init(
BACNET_MAC_ADDRESS *mac,
uint8_t *adr,
uint8_t len);
bool address_mac_from_ascii(
BACNET_MAC_ADDRESS *mac,
char *arg);
void address_protected_entry_index_set(uint32_t top_protected_entry_index);
void address_own_device_id_set(uint32_t own_id);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+86
View File
@@ -0,0 +1,86 @@
/**************************************************************************
*
* Copyright (C) 2009 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.
*********************************************************************/
#ifndef ALARM_ACK_H_
#define ALARM_ACK_H_
#include "bacenum.h"
#include <stdint.h>
#include <stdbool.h>
#include "bacapp.h"
#include "timestamp.h"
typedef struct {
uint32_t ackProcessIdentifier;
BACNET_OBJECT_ID eventObjectIdentifier;
BACNET_EVENT_STATE eventStateAcked;
BACNET_TIMESTAMP eventTimeStamp;
BACNET_CHARACTER_STRING ackSource;
BACNET_TIMESTAMP ackTimeStamp;
} BACNET_ALARM_ACK_DATA;
/* return +1 if alarm was acknowledged
return -1 if any error occurred
return -2 abort */
typedef int (
*alarm_ack_function) (
BACNET_ALARM_ACK_DATA * alarmack_data,
BACNET_ERROR_CODE * error_code);
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/***************************************************
**
** Creates a Alarm Acknowledge APDU
**
****************************************************/
int alarm_ack_encode_apdu(
uint8_t * apdu,
uint8_t invoke_id,
BACNET_ALARM_ACK_DATA * data);
/***************************************************
**
** Encodes the service data part of Alarm Acknowledge
**
****************************************************/
int alarm_ack_encode_service_request(
uint8_t * apdu,
BACNET_ALARM_ACK_DATA * data);
/***************************************************
**
** Decodes the service data part of Alarm Acknowledge
**
****************************************************/
int alarm_ack_decode_service_request(
uint8_t * apdu,
unsigned apdu_len,
BACNET_ALARM_ACK_DATA * data);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* ALARM_ACK_H_ */
+195
View File
@@ -0,0 +1,195 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef APDU_H
#define APDU_H
#include <stdbool.h>
#include <stdint.h>
#include "bacdef.h"
#include "bacenum.h"
typedef struct _confirmed_service_data {
bool segmented_message;
bool more_follows;
bool segmented_response_accepted;
int max_segs;
int max_resp;
uint8_t invoke_id;
uint8_t sequence_number;
uint8_t proposed_window_number;
} BACNET_CONFIRMED_SERVICE_DATA;
typedef struct _confirmed_service_ack_data {
bool segmented_message;
bool more_follows;
uint8_t invoke_id;
uint8_t sequence_number;
uint8_t proposed_window_number;
} BACNET_CONFIRMED_SERVICE_ACK_DATA;
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* generic unconfirmed function handler */
/* Suitable to handle the following services: */
/* I_Am, Who_Is, Unconfirmed_COV_Notification, I_Have, */
/* Unconfirmed_Event_Notification, Unconfirmed_Private_Transfer, */
/* Unconfirmed_Text_Message, Time_Synchronization, Who_Has, */
/* UTC_Time_Synchronization */
typedef void (
*unconfirmed_function) (
uint8_t * service_request,
uint16_t len,
BACNET_ADDRESS * src);
/* generic confirmed function handler */
/* Suitable to handle the following services: */
/* Acknowledge_Alarm, Confirmed_COV_Notification, */
/* Confirmed_Event_Notification, Get_Alarm_Summary, */
/* Get_Enrollment_Summary_Handler, Get_Event_Information, */
/* Subscribe_COV_Handler, Subscribe_COV_Property, */
/* Life_Safety_Operation, Atomic_Read_File, */
/* Confirmed_Atomic_Write_File, Add_List_Element, */
/* Remove_List_Element, Create_Object_Handler, */
/* Delete_Object_Handler, Read_Property, */
/* Read_Property_Conditional, Read_Property_Multiple, Read_Range, */
/* Write_Property, Write_Property_Multiple, */
/* Device_Communication_Control, Confirmed_Private_Transfer, */
/* Confirmed_Text_Message, Reinitialize_Device, */
/* VT_Open, VT_Close, VT_Data_Handler, */
/* Authenticate, Request_Key */
typedef void (
*confirmed_function) (
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src,
BACNET_CONFIRMED_SERVICE_DATA * service_data);
/* generic confirmed simple ack function handler */
typedef void (
*confirmed_simple_ack_function) (
BACNET_ADDRESS * src,
uint8_t invoke_id);
/* generic confirmed ack function handler */
typedef void (
*confirmed_ack_function) (
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src,
BACNET_CONFIRMED_SERVICE_ACK_DATA * service_data);
/* generic error reply function */
typedef void (
*error_function) (
BACNET_ADDRESS * src,
uint8_t invoke_id,
BACNET_ERROR_CLASS error_class,
BACNET_ERROR_CODE error_code);
/* generic abort reply function */
typedef void (
*abort_function) (
BACNET_ADDRESS * src,
uint8_t invoke_id,
uint8_t abort_reason,
bool server);
/* generic reject reply function */
typedef void (
*reject_function) (
BACNET_ADDRESS * src,
uint8_t invoke_id,
uint8_t reject_reason);
void apdu_set_confirmed_ack_handler(
BACNET_CONFIRMED_SERVICE service_choice,
confirmed_ack_function pFunction);
void apdu_set_confirmed_simple_ack_handler(
BACNET_CONFIRMED_SERVICE service_choice,
confirmed_simple_ack_function pFunction);
/* configure reject for confirmed services that are not supported */
void apdu_set_unrecognized_service_handler_handler(
confirmed_function pFunction);
void apdu_set_confirmed_handler(
BACNET_CONFIRMED_SERVICE service_choice,
confirmed_function pFunction);
void apdu_set_unconfirmed_handler(
BACNET_UNCONFIRMED_SERVICE service_choice,
unconfirmed_function pFunction);
/* returns true if the service is supported by a handler */
bool apdu_service_supported(
BACNET_SERVICES_SUPPORTED service_supported);
/* Function to translate a SERVICE_SUPPORTED_ enum to its SERVICE_CONFIRMED_
* or SERVICE_UNCONFIRMED_ index.
*/
bool apdu_service_supported_to_index(
BACNET_SERVICES_SUPPORTED service_supported,
size_t * index,
bool * bIsConfirmed);
void apdu_set_error_handler(
BACNET_CONFIRMED_SERVICE service_choice,
error_function pFunction);
void apdu_set_abort_handler(
abort_function pFunction);
void apdu_set_reject_handler(
reject_function pFunction);
uint16_t apdu_decode_confirmed_service_request(
uint8_t * apdu, /* APDU data */
uint16_t apdu_len,
BACNET_CONFIRMED_SERVICE_DATA * service_data,
uint8_t * service_choice,
uint8_t ** service_request,
uint16_t * service_request_len);
uint16_t apdu_timeout(
void);
void apdu_timeout_set(
uint16_t value);
uint8_t apdu_retries(
void);
void apdu_retries_set(
uint8_t value);
void apdu_handler(
BACNET_ADDRESS * src, /* source address */
uint8_t * apdu, /* APDU data */
uint16_t pdu_len); /* for confirmed messages */
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+72
View File
@@ -0,0 +1,72 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef ARCNET_H
#define ARCNET_H
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
#include "bacdef.h"
#include "npdu.h"
/* specific defines for ARCNET */
#define MAX_HEADER (1+1+2+2+1+1+1+1)
#define MAX_MPDU (MAX_HEADER+MAX_PDU)
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
bool arcnet_valid(
void);
void arcnet_cleanup(
void);
bool arcnet_init(
char *interface_name);
/* function to send a packet out the 802.2 socket */
/* returns zero on success, non-zero on failure */
int arcnet_send_pdu(
BACNET_ADDRESS * dest, /* destination address */
BACNET_NPDU_DATA * npdu_data, /* network information */
uint8_t * pdu, /* any data to be sent - may be null */
unsigned pdu_len); /* number of bytes of data */
/* receives an framed packet */
/* returns the number of octets in the PDU, or zero on failure */
uint16_t arcnet_receive(
BACNET_ADDRESS * src, /* source address */
uint8_t * pdu, /* PDU data */
uint16_t max_pdu, /* amount of space available in the PDU */
unsigned timeout); /* milliseconds to wait for a packet */
void arcnet_get_my_address(
BACNET_ADDRESS * my_address);
void arcnet_get_broadcast_address(
BACNET_ADDRESS * dest); /* destination address */
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+110
View File
@@ -0,0 +1,110 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef ATOMIC_READ_FILE_H
#define ATOMIC_READ_FILE_H
#include <stdint.h>
#include <stdbool.h>
#include "bacdcode.h"
#include "bacstr.h"
#ifndef BACNET_READ_FILE_RECORD_COUNT
#define BACNET_READ_FILE_RECORD_COUNT 1
#endif
typedef struct BACnet_Atomic_Read_File_Data {
BACNET_OBJECT_TYPE object_type;
uint32_t object_instance;
BACNET_FILE_ACCESS_METHOD access;
union {
struct {
int32_t fileStartPosition;
uint32_t requestedOctetCount;
} stream;
struct {
int32_t fileStartRecord;
/* requested or returned record count */
uint32_t RecordCount;
} record;
} type;
BACNET_OCTET_STRING fileData[BACNET_READ_FILE_RECORD_COUNT];
bool endOfFile;
} BACNET_ATOMIC_READ_FILE_DATA;
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* Atomic Read File */
/* encode service */
int arf_encode_apdu(
uint8_t * apdu,
uint8_t invoke_id,
BACNET_ATOMIC_READ_FILE_DATA * data);
/* decode the service request only */
int arf_decode_service_request(
uint8_t * apdu,
unsigned apdu_len,
BACNET_ATOMIC_READ_FILE_DATA * data);
int arf_decode_apdu(
uint8_t * apdu,
unsigned apdu_len,
uint8_t * invoke_id,
BACNET_ATOMIC_READ_FILE_DATA * data);
/* Atomic Read File Ack */
/* encode service */
int arf_ack_encode_apdu(
uint8_t * apdu,
uint8_t invoke_id,
BACNET_ATOMIC_READ_FILE_DATA * data);
/* decode the service request only */
int arf_ack_decode_service_request(
uint8_t * apdu,
unsigned apdu_len,
BACNET_ATOMIC_READ_FILE_DATA * data);
int arf_ack_decode_apdu(
uint8_t * apdu,
unsigned apdu_len,
uint8_t * invoke_id,
BACNET_ATOMIC_READ_FILE_DATA * data);
#ifdef TEST
#include "ctest.h"
void test_AtomicReadFile(
Test * pTest);
void test_AtomicReadFileAck(
Test * pTest);
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+62
View File
@@ -0,0 +1,62 @@
/**************************************************************************
*
* Copyright (C) 2015 Nikola Jelic <nikola.jelic@euroicc.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.
*
*********************************************************************/
#ifndef BACNET_ASSIGNED_ACCESS_RIGHTS_H
#define BACNET_ASSIGNED_ACCESS_RIGHTS_H
#include <stdbool.h>
#include <stdint.h>
#include "bacdef.h"
#include "bacapp.h"
#include "bacdevobjpropref.h"
typedef struct {
BACNET_DEVICE_OBJECT_REFERENCE assigned_access_rights;
bool enable;
} BACNET_ASSIGNED_ACCESS_RIGHTS;
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
int bacapp_encode_assigned_access_rights(
uint8_t * apdu,
BACNET_ASSIGNED_ACCESS_RIGHTS * aar);
int bacapp_encode_context_assigned_access_rights(
uint8_t * apdu,
uint8_t tag,
BACNET_ASSIGNED_ACCESS_RIGHTS * aar);
int bacapp_decode_assigned_access_rights(
uint8_t * apdu,
BACNET_ASSIGNED_ACCESS_RIGHTS * aar);
int bacapp_decode_context_assigned_access_rights(
uint8_t * apdu,
uint8_t tag,
BACNET_ASSIGNED_ACCESS_RIGHTS * aar);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+64
View File
@@ -0,0 +1,64 @@
/**************************************************************************
*
* Copyright (C) 2015 Nikola Jelic <nikola.jelic@euroicc.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.
*
*********************************************************************/
#ifndef BACNET_AUTHENTICATION_FACTOR_H
#define BACNET_AUTHENTICATION_FACTOR_H
#include <stdbool.h>
#include <stdint.h>
#include "bacdef.h"
#include "bacapp.h"
typedef struct {
BACNET_AUTHENTICATION_FACTOR_TYPE format_type;
uint32_t format_class;
BACNET_OCTET_STRING value;
} BACNET_AUTHENTICATION_FACTOR;
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
int bacapp_encode_authentication_factor(
uint8_t * apdu,
BACNET_AUTHENTICATION_FACTOR * af);
int bacapp_encode_context_authentication_factor(
uint8_t * apdu,
uint8_t tag,
BACNET_AUTHENTICATION_FACTOR * af);
int bacapp_decode_authentication_factor(
uint8_t * apdu,
BACNET_AUTHENTICATION_FACTOR * af);
int bacapp_decode_context_authentication_factor(
uint8_t * apdu,
uint8_t tag,
BACNET_AUTHENTICATION_FACTOR * af);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+60
View File
@@ -0,0 +1,60 @@
/**************************************************************************
*
* Copyright (C) 2015 Nikola Jelic <nikola.jelic@euroicc.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.
*
*********************************************************************/
#ifndef BACNET_AUTHENTICATION_FACTOR_FORMAT_H
#define BACNET_AUTHENTICATION_FACTOR_FORMAT_H
#include <stdbool.h>
#include <stdint.h>
#include "bacdef.h"
typedef struct {
BACNET_AUTHENTICATION_FACTOR_TYPE format_type;
uint32_t vendor_id, vendor_format;
} BACNET_AUTHENTICATION_FACTOR_FORMAT;
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
int bacapp_encode_authentication_factor_format(
uint8_t * apdu,
BACNET_AUTHENTICATION_FACTOR_FORMAT * aff);
int bacapp_encode_context_authentication_factor_format(
uint8_t * apdu,
uint8_t tag_number,
BACNET_AUTHENTICATION_FACTOR_FORMAT * aff);
int bacapp_decode_authentication_factor_format(
uint8_t * apdu,
BACNET_AUTHENTICATION_FACTOR_FORMAT * aff);
int bacapp_decode_context_authentication_factor_format(
uint8_t * apdu,
uint8_t tag_number,
BACNET_AUTHENTICATION_FACTOR_FORMAT * aff);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+105
View File
@@ -0,0 +1,105 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef ATOMIC_WRITE_FILE_H
#define ATOMIC_WRITE_FILE_H
#include <stdint.h>
#include <stdbool.h>
#include "bacdcode.h"
#ifndef BACNET_WRITE_FILE_RECORD_COUNT
#define BACNET_WRITE_FILE_RECORD_COUNT 1
#endif
typedef struct BACnet_Atomic_Write_File_Data {
BACNET_OBJECT_TYPE object_type;
uint32_t object_instance;
BACNET_FILE_ACCESS_METHOD access;
union {
struct {
int32_t fileStartPosition;
} stream;
struct {
int32_t fileStartRecord;
uint32_t returnedRecordCount;
} record;
} type;
BACNET_OCTET_STRING fileData[BACNET_WRITE_FILE_RECORD_COUNT];
} BACNET_ATOMIC_WRITE_FILE_DATA;
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* Atomic Write File */
/* encode service */
int awf_encode_apdu(
uint8_t * apdu,
uint8_t invoke_id,
BACNET_ATOMIC_WRITE_FILE_DATA * data);
/* decode the service request only */
int awf_decode_service_request(
uint8_t * apdu,
unsigned apdu_len,
BACNET_ATOMIC_WRITE_FILE_DATA * data);
int awf_decode_apdu(
uint8_t * apdu,
unsigned apdu_len,
uint8_t * invoke_id,
BACNET_ATOMIC_WRITE_FILE_DATA * data);
/* Atomic Write File Ack */
/* encode service */
int awf_ack_encode_apdu(
uint8_t * apdu,
uint8_t invoke_id,
BACNET_ATOMIC_WRITE_FILE_DATA * data);
/* decode the service request only */
int awf_ack_decode_service_request(
uint8_t * apdu,
unsigned apdu_len,
BACNET_ATOMIC_WRITE_FILE_DATA * data);
int awf_ack_decode_apdu(
uint8_t * apdu,
unsigned apdu_len,
uint8_t * invoke_id,
BACNET_ATOMIC_WRITE_FILE_DATA * data);
#ifdef TEST
#include "ctest.h"
void test_AtomicWriteFile(
Test * pTest);
void test_AtomicWriteFileAck(
Test * pTest);
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+46
View File
@@ -0,0 +1,46 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef BACADDR_H
#define BACADDR_H
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include "bacdef.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
void bacnet_address_copy(
BACNET_ADDRESS * dest,
BACNET_ADDRESS * src);
bool bacnet_address_same(
BACNET_ADDRESS * dest,
BACNET_ADDRESS * src);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+256
View File
@@ -0,0 +1,256 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef BACAPP_H
#define BACAPP_H
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include "bacdef.h"
#include "bacstr.h"
#include "datetime.h"
#if defined (BACAPP_LIGHTING_COMMAND)
#include "lighting.h"
#endif
#if defined (BACAPP_DEVICE_OBJECT_PROP_REF)
#include "bacdevobjpropref.h"
#endif
struct BACnet_Application_Data_Value;
typedef struct BACnet_Application_Data_Value {
bool context_specific; /* true if context specific data */
uint8_t context_tag; /* only used for context specific data */
uint8_t tag; /* application tag data type */
union {
/* NULL - not needed as it is encoded in the tag alone */
#if defined (BACAPP_BOOLEAN)
bool Boolean;
#endif
#if defined (BACAPP_UNSIGNED)
uint32_t Unsigned_Int;
#endif
#if defined (BACAPP_SIGNED)
int32_t Signed_Int;
#endif
#if defined (BACAPP_REAL)
float Real;
#endif
#if defined (BACAPP_DOUBLE)
double Double;
#endif
#if defined (BACAPP_OCTET_STRING)
BACNET_OCTET_STRING Octet_String;
#endif
#if defined (BACAPP_CHARACTER_STRING)
BACNET_CHARACTER_STRING Character_String;
#endif
#if defined (BACAPP_BIT_STRING)
BACNET_BIT_STRING Bit_String;
#endif
#if defined (BACAPP_ENUMERATED)
uint32_t Enumerated;
#endif
#if defined (BACAPP_DATE)
BACNET_DATE Date;
#endif
#if defined (BACAPP_TIME)
BACNET_TIME Time;
#endif
#if defined (BACAPP_OBJECT_ID)
BACNET_OBJECT_ID Object_Id;
#endif
#if defined (BACAPP_LIGHTING_COMMAND)
BACNET_LIGHTING_COMMAND Lighting_Command;
#endif
#if defined (BACAPP_DEVICE_OBJECT_PROP_REF)
BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE
Device_Object_Property_Reference;
#endif
} type;
/* simple linked list if needed */
struct BACnet_Application_Data_Value *next;
} BACNET_APPLICATION_DATA_VALUE;
struct BACnet_Access_Error;
typedef struct BACnet_Access_Error {
BACNET_ERROR_CLASS error_class;
BACNET_ERROR_CODE error_code;
} BACNET_ACCESS_ERROR;
struct BACnet_Property_Reference;
typedef struct BACnet_Property_Reference {
BACNET_PROPERTY_ID propertyIdentifier;
uint32_t propertyArrayIndex; /* optional */
/* either value or error, but not both.
Use NULL value to indicate error */
BACNET_APPLICATION_DATA_VALUE *value;
BACNET_ACCESS_ERROR error;
/* simple linked list */
struct BACnet_Property_Reference *next;
} BACNET_PROPERTY_REFERENCE;
struct BACnet_Property_Value;
typedef struct BACnet_Property_Value {
BACNET_PROPERTY_ID propertyIdentifier;
uint32_t propertyArrayIndex;
BACNET_APPLICATION_DATA_VALUE value;
uint8_t priority;
/* simple linked list */
struct BACnet_Property_Value *next;
} BACNET_PROPERTY_VALUE;
/* used for printing values */
struct BACnet_Object_Property_Value;
typedef struct BACnet_Object_Property_Value {
BACNET_OBJECT_TYPE object_type;
uint32_t object_instance;
BACNET_PROPERTY_ID object_property;
uint32_t array_index;
BACNET_APPLICATION_DATA_VALUE *value;
} BACNET_OBJECT_PROPERTY_VALUE;
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
void bacapp_value_list_init(
BACNET_APPLICATION_DATA_VALUE *value,
size_t count);
void bacapp_property_value_list_init(
BACNET_PROPERTY_VALUE *value,
size_t count);
int bacapp_encode_data(
uint8_t * apdu,
BACNET_APPLICATION_DATA_VALUE * value);
int bacapp_decode_data(
uint8_t * apdu,
uint8_t tag_data_type,
uint32_t len_value_type,
BACNET_APPLICATION_DATA_VALUE * value);
int bacapp_decode_application_data(
uint8_t * apdu,
unsigned max_apdu_len,
BACNET_APPLICATION_DATA_VALUE * value);
bool bacapp_decode_application_data_safe(
uint8_t * new_apdu,
uint32_t new_apdu_len,
BACNET_APPLICATION_DATA_VALUE * value);
int bacapp_encode_application_data(
uint8_t * apdu,
BACNET_APPLICATION_DATA_VALUE * value);
int bacapp_decode_context_data(
uint8_t * apdu,
unsigned max_apdu_len,
BACNET_APPLICATION_DATA_VALUE * value,
BACNET_PROPERTY_ID property);
int bacapp_encode_context_data(
uint8_t * apdu,
BACNET_APPLICATION_DATA_VALUE * value,
BACNET_PROPERTY_ID property);
int bacapp_encode_context_data_value(
uint8_t * apdu,
uint8_t context_tag_number,
BACNET_APPLICATION_DATA_VALUE * value);
BACNET_APPLICATION_TAG bacapp_context_tag_type(
BACNET_PROPERTY_ID property,
uint8_t tag_number);
bool bacapp_copy(
BACNET_APPLICATION_DATA_VALUE * dest_value,
BACNET_APPLICATION_DATA_VALUE * src_value);
/* returns the length of data between an opening tag and a closing tag.
Expects that the first octet contain the opening tag.
Include a value property identifier for context specific data
such as the value received in a WriteProperty request */
int bacapp_data_len(
uint8_t * apdu,
unsigned max_apdu_len,
BACNET_PROPERTY_ID property);
int bacapp_decode_data_len(
uint8_t * apdu,
uint8_t tag_data_type,
uint32_t len_value_type);
int bacapp_decode_application_data_len(
uint8_t * apdu,
unsigned max_apdu_len);
int bacapp_decode_context_data_len(
uint8_t * apdu,
unsigned max_apdu_len,
BACNET_PROPERTY_ID property);
#ifndef BACAPP_PRINT_ENABLED
#if PRINT_ENABLED || defined TEST
#define BACAPP_PRINT_ENABLED
#define BACAPP_SNPRINTF_ENABLED
#endif
#endif
#ifdef BACAPP_SNPRINTF_ENABLED
int bacapp_snprintf_value(
char *str,
size_t str_len,
BACNET_OBJECT_PROPERTY_VALUE * object_value);
#endif
#ifdef BACAPP_PRINT_ENABLED
bool bacapp_parse_application_data(
BACNET_APPLICATION_TAG tag_number,
const char *argv,
BACNET_APPLICATION_DATA_VALUE * value);
bool bacapp_print_value(
FILE * stream,
BACNET_OBJECT_PROPERTY_VALUE * value);
#else
/* Provide harmless return values */
#define bacapp_parse_application_data(x,y,z) false
#define bacapp_print_value(x,y) false
#endif
#ifdef TEST
#include "ctest.h"
#include "datetime.h"
bool bacapp_same_value(
BACNET_APPLICATION_DATA_VALUE * value,
BACNET_APPLICATION_DATA_VALUE * test_value);
void testBACnetApplicationDataLength(
Test * pTest);
void testBACnetApplicationData(
Test * pTest);
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+444
View File
@@ -0,0 +1,444 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef BACDCODE_H
#define BACDCODE_H
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include "bacdef.h"
#include "datetime.h"
#include "bacstr.h"
#include "bacint.h"
#include "bacreal.h"
#include "bits.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* from clause 20.2.1 General Rules for Encoding BACnet Tags */
/* returns the number of apdu bytes consumed */
int encode_tag(
uint8_t * apdu,
uint8_t tag_number,
bool context_specific,
uint32_t len_value_type);
/* from clause 20.2.1.3.2 Constructed Data */
/* returns the number of apdu bytes consumed */
int encode_opening_tag(
uint8_t * apdu,
uint8_t tag_number);
int encode_closing_tag(
uint8_t * apdu,
uint8_t tag_number);
int decode_tag_number(
uint8_t * apdu,
uint8_t * tag_number);
int decode_tag_number_safe(
uint8_t * apdu,
uint32_t apdu_len_remaining,
uint8_t * tag_number);
int decode_tag_number_and_value(
uint8_t * apdu,
uint8_t * tag_number,
uint32_t * value);
int decode_tag_number_and_value_safe(
uint8_t * apdu,
uint32_t apdu_len_remaining,
uint8_t * tag_number,
uint32_t * value);
/* returns true if the tag is an opening tag and matches */
bool decode_is_opening_tag_number(
uint8_t * apdu,
uint8_t tag_number);
/* returns true if the tag is a closing tag and matches */
bool decode_is_closing_tag_number(
uint8_t * apdu,
uint8_t tag_number);
/* returns true if the tag is context specific and matches */
bool decode_is_context_tag(
uint8_t * apdu,
uint8_t tag_number);
bool decode_is_context_tag_with_length(
uint8_t * apdu,
uint8_t tag_number,
int *tag_length);
/* returns true if the tag is an opening tag */
bool decode_is_opening_tag(
uint8_t * apdu);
/* returns true if the tag is a closing tag */
bool decode_is_closing_tag(
uint8_t * apdu);
/* from clause 20.2.2 Encoding of a Null Value */
int encode_application_null(
uint8_t * apdu);
int encode_context_null(
uint8_t * apdu,
uint8_t tag_number);
/* from clause 20.2.3 Encoding of a Boolean Value */
int encode_application_boolean(
uint8_t * apdu,
bool boolean_value);
bool decode_boolean(
uint32_t len_value);
int encode_context_boolean(
uint8_t * apdu,
uint8_t tag_number,
bool boolean_value);
bool decode_context_boolean(
uint8_t * apdu);
int decode_context_boolean2(
uint8_t * apdu,
uint8_t tag_number,
bool * boolean_value);
/* from clause 20.2.10 Encoding of a Bit String Value */
/* returns the number of apdu bytes consumed */
int decode_bitstring(
uint8_t * apdu,
uint32_t len_value,
BACNET_BIT_STRING * bit_string);
int decode_context_bitstring(
uint8_t * apdu,
uint8_t tag_number,
BACNET_BIT_STRING * bit_string);
/* returns the number of apdu bytes consumed */
int encode_bitstring(
uint8_t * apdu,
BACNET_BIT_STRING * bit_string);
int encode_application_bitstring(
uint8_t * apdu,
BACNET_BIT_STRING * bit_string);
int encode_context_bitstring(
uint8_t * apdu,
uint8_t tag_number,
BACNET_BIT_STRING * bit_string);
/* from clause 20.2.6 Encoding of a Real Number Value */
/* and 20.2.1 General Rules for Encoding BACnet Tags */
/* returns the number of apdu bytes consumed */
int encode_application_real(
uint8_t * apdu,
float value);
int encode_context_real(
uint8_t * apdu,
uint8_t tag_number,
float value);
/* from clause 20.2.7 Encoding of a Double Precision Real Number Value */
/* and 20.2.1 General Rules for Encoding BACnet Tags */
/* returns the number of apdu bytes consumed */
int encode_application_double(
uint8_t * apdu,
double value);
int encode_context_double(
uint8_t * apdu,
uint8_t tag_number,
double value);
/* from clause 20.2.14 Encoding of an Object Identifier Value */
/* and 20.2.1 General Rules for Encoding BACnet Tags */
/* returns the number of apdu bytes consumed */
int decode_object_id(
uint8_t * apdu,
uint16_t * object_type,
uint32_t * instance);
int decode_object_id_safe(
uint8_t * apdu,
uint32_t len_value,
uint16_t * object_type,
uint32_t * instance);
int decode_context_object_id(
uint8_t * apdu,
uint8_t tag_number,
uint16_t * object_type,
uint32_t * instance);
int encode_bacnet_object_id(
uint8_t * apdu,
int object_type,
uint32_t instance);
int encode_context_object_id(
uint8_t * apdu,
uint8_t tag_number,
int object_type,
uint32_t instance);
int encode_application_object_id(
uint8_t * apdu,
int object_type,
uint32_t instance);
/* from clause 20.2.8 Encoding of an Octet String Value */
/* and 20.2.1 General Rules for Encoding BACnet Tags */
/* returns the number of apdu bytes consumed */
int encode_octet_string(
uint8_t * apdu,
BACNET_OCTET_STRING * octet_string);
int encode_application_octet_string(
uint8_t * apdu,
BACNET_OCTET_STRING * octet_string);
int encode_context_octet_string(
uint8_t * apdu,
uint8_t tag_number,
BACNET_OCTET_STRING * octet_string);
int decode_octet_string(
uint8_t * apdu,
uint32_t len_value,
BACNET_OCTET_STRING * octet_string);
int decode_context_octet_string(
uint8_t * apdu,
uint8_t tag_number,
BACNET_OCTET_STRING * octet_string);
/* from clause 20.2.9 Encoding of a Character String Value */
/* and 20.2.1 General Rules for Encoding BACnet Tags */
/* returns the number of apdu bytes consumed */
uint32_t encode_bacnet_character_string_safe(
uint8_t * apdu,
uint32_t max_apdu,
uint8_t encoding,
char *pString,
uint32_t length);
int encode_bacnet_character_string(
uint8_t * apdu,
BACNET_CHARACTER_STRING * char_string);
int encode_application_character_string(
uint8_t * apdu,
BACNET_CHARACTER_STRING * char_string);
int encode_context_character_string(
uint8_t * apdu,
uint8_t tag_number,
BACNET_CHARACTER_STRING * char_string);
int decode_character_string(
uint8_t * apdu,
uint32_t len_value,
BACNET_CHARACTER_STRING * char_string);
int decode_context_character_string(
uint8_t * apdu,
uint8_t tag_number,
BACNET_CHARACTER_STRING * char_string);
/* from clause 20.2.4 Encoding of an Unsigned Integer Value */
/* and 20.2.1 General Rules for Encoding BACnet Tags */
/* returns the number of apdu bytes consumed */
int encode_bacnet_unsigned(
uint8_t * apdu,
uint32_t value);
int encode_context_unsigned(
uint8_t * apdu,
uint8_t tag_number,
uint32_t value);
int encode_application_unsigned(
uint8_t * apdu,
uint32_t value);
int decode_unsigned(
uint8_t * apdu,
uint32_t len_value,
uint32_t * value);
int decode_context_unsigned(
uint8_t * apdu,
uint8_t tag_number,
uint32_t * value);
/* from clause 20.2.5 Encoding of a Signed Integer Value */
/* and 20.2.1 General Rules for Encoding BACnet Tags */
/* returns the number of apdu bytes consumed */
int encode_bacnet_signed(
uint8_t * apdu,
int32_t value);
int encode_application_signed(
uint8_t * apdu,
int32_t value);
int encode_context_signed(
uint8_t * apdu,
uint8_t tag_number,
int32_t value);
int decode_signed(
uint8_t * apdu,
uint32_t len_value,
int32_t * value);
int decode_context_signed(
uint8_t * apdu,
uint8_t tag_number,
int32_t * value);
/* from clause 20.2.11 Encoding of an Enumerated Value */
/* and 20.2.1 General Rules for Encoding BACnet Tags */
/* returns the number of apdu bytes consumed */
int decode_enumerated(
uint8_t * apdu,
uint32_t len_value,
uint32_t * value);
int decode_context_enumerated(
uint8_t * apdu,
uint8_t tag_value,
uint32_t * value);
int encode_bacnet_enumerated(
uint8_t * apdu,
uint32_t value);
int encode_application_enumerated(
uint8_t * apdu,
uint32_t value);
int encode_context_enumerated(
uint8_t * apdu,
uint8_t tag_number,
uint32_t value);
/* from clause 20.2.13 Encoding of a Time Value */
/* and 20.2.1 General Rules for Encoding BACnet Tags */
/* returns the number of apdu bytes consumed */
int encode_bacnet_time(
uint8_t * apdu,
BACNET_TIME * btime);
int encode_application_time(
uint8_t * apdu,
BACNET_TIME * btime);
int decode_bacnet_time(
uint8_t * apdu,
BACNET_TIME * btime);
int decode_bacnet_time_safe(
uint8_t * apdu,
uint32_t len_value,
BACNET_TIME * btime);
int encode_context_time(
uint8_t * apdu,
uint8_t tag_number,
BACNET_TIME * btime);
int decode_application_time(
uint8_t * apdu,
BACNET_TIME * btime);
int decode_context_bacnet_time(
uint8_t * apdu,
uint8_t tag_number,
BACNET_TIME * btime);
/* BACnet Date */
/* year = years since 1900 */
/* month 1=Jan */
/* day = day of month */
/* wday 1=Monday...7=Sunday */
/* from clause 20.2.12 Encoding of a Date Value */
/* and 20.2.1 General Rules for Encoding BACnet Tags */
/* returns the number of apdu bytes consumed */
int encode_bacnet_date(
uint8_t * apdu,
BACNET_DATE * bdate);
int encode_application_date(
uint8_t * apdu,
BACNET_DATE * bdate);
int encode_context_date(
uint8_t * apdu,
uint8_t tag_number,
BACNET_DATE * bdate);
int decode_date(
uint8_t * apdu,
BACNET_DATE * bdate);
int decode_date_safe(
uint8_t * apdu,
uint32_t len_value,
BACNET_DATE * bdate);
int decode_application_date(
uint8_t * apdu,
BACNET_DATE * bdate);
int decode_context_date(
uint8_t * apdu,
uint8_t tag_number,
BACNET_DATE * bdate);
/* from clause 20.1.2.4 max-segments-accepted */
/* and clause 20.1.2.5 max-APDU-length-accepted */
/* returns the encoded octet */
uint8_t encode_max_segs_max_apdu(
int max_segs,
int max_apdu);
int decode_max_segs(
uint8_t octet);
int decode_max_apdu(
uint8_t octet);
/* returns the number of apdu bytes consumed */
int encode_simple_ack(
uint8_t * apdu,
uint8_t invoke_id,
uint8_t service_choice);
int encode_bacnet_address(
uint8_t * apdu,
BACNET_ADDRESS * destination);
int decode_bacnet_address(
uint8_t * apdu,
BACNET_ADDRESS * destination);
int encode_context_bacnet_address(
uint8_t * apdu,
uint8_t tag_number,
BACNET_ADDRESS * destination);
int decode_context_bacnet_address(
uint8_t * apdu,
uint8_t tag_number,
BACNET_ADDRESS * destination);
/* from clause 20.2.1.2 Tag Number */
/* true if extended tag numbering is used */
#define IS_EXTENDED_TAG_NUMBER(x) ((x & 0xF0) == 0xF0)
/* from clause 20.2.1.3.1 Primitive Data */
/* true if the extended value is used */
#define IS_EXTENDED_VALUE(x) ((x & 0x07) == 5)
/* from clause 20.2.1.1 Class */
/* true if the tag is context specific */
#define IS_CONTEXT_SPECIFIC(x) ((x & BIT3) == BIT3)
/* from clause 20.2.1.3.2 Constructed Data */
/* true if the tag is an opening tag */
#define IS_OPENING_TAG(x) ((x & 0x07) == 6)
/* from clause 20.2.1.3.2 Constructed Data */
/* true if the tag is a closing tag */
#define IS_CLOSING_TAG(x) ((x & 0x07) == 7)
#ifdef TEST
#include "ctest.h"
void test_BACDCode(
Test * pTest);
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+180
View File
@@ -0,0 +1,180 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef BACDEF_H
#define BACDEF_H
#include <stddef.h>
#include <stdint.h>
#include "bacenum.h"
#include "config.h"
#if defined(_MSC_VER)
/* Silence the warnings about unsafe versions of library functions */
/* as we need to keep the code portable */
#pragma warning( disable : 4996)
#endif
/* This stack implements this version of BACnet */
#define BACNET_PROTOCOL_VERSION 1
/* Although this stack can implement a later revision,
* sometimes another revision is desired */
#ifndef BACNET_PROTOCOL_REVISION
#define BACNET_PROTOCOL_REVISION 19
#endif
/* there are a few dependencies on the BACnet Protocol-Revision */
#if (BACNET_PROTOCOL_REVISION == 0)
#define MAX_ASHRAE_OBJECT_TYPE 18
#define MAX_BACNET_SERVICES_SUPPORTED 35
#elif (BACNET_PROTOCOL_REVISION == 1)
#define MAX_ASHRAE_OBJECT_TYPE 21
#define MAX_BACNET_SERVICES_SUPPORTED 37
#elif (BACNET_PROTOCOL_REVISION == 2)
/* from 135-2001 version of the BACnet Standard */
#define MAX_ASHRAE_OBJECT_TYPE 23
#define MAX_BACNET_SERVICES_SUPPORTED 40
#elif (BACNET_PROTOCOL_REVISION == 3)
#define MAX_ASHRAE_OBJECT_TYPE 23
#define MAX_BACNET_SERVICES_SUPPORTED 40
#elif (BACNET_PROTOCOL_REVISION == 4)
/* from 135-2004 version of the BACnet Standard */
#define MAX_ASHRAE_OBJECT_TYPE 25
#define MAX_BACNET_SERVICES_SUPPORTED 40
#elif (BACNET_PROTOCOL_REVISION == 5)
#define MAX_ASHRAE_OBJECT_TYPE 30
#define MAX_BACNET_SERVICES_SUPPORTED 40
#elif (BACNET_PROTOCOL_REVISION == 6)
#define MAX_ASHRAE_OBJECT_TYPE 31
#define MAX_BACNET_SERVICES_SUPPORTED 40
#elif (BACNET_PROTOCOL_REVISION == 7)
#define MAX_ASHRAE_OBJECT_TYPE 31
#define MAX_BACNET_SERVICES_SUPPORTED 40
#elif (BACNET_PROTOCOL_REVISION == 8)
#define MAX_ASHRAE_OBJECT_TYPE 31
#define MAX_BACNET_SERVICES_SUPPORTED 40
#elif (BACNET_PROTOCOL_REVISION == 9)
/* from 135-2008 version of the BACnet Standard */
#define MAX_ASHRAE_OBJECT_TYPE 38
#define MAX_BACNET_SERVICES_SUPPORTED 40
#elif (BACNET_PROTOCOL_REVISION == 10)
#define MAX_ASHRAE_OBJECT_TYPE 51
#define MAX_BACNET_SERVICES_SUPPORTED 40
#elif (BACNET_PROTOCOL_REVISION == 11)
#define MAX_ASHRAE_OBJECT_TYPE 51
#define MAX_BACNET_SERVICES_SUPPORTED 40
#elif (BACNET_PROTOCOL_REVISION == 12)
/* from 135-2010 version of the BACnet Standard */
#define MAX_ASHRAE_OBJECT_TYPE 51
#define MAX_BACNET_SERVICES_SUPPORTED 40
#elif (BACNET_PROTOCOL_REVISION == 13)
#define MAX_ASHRAE_OBJECT_TYPE 53
#define MAX_BACNET_SERVICES_SUPPORTED 40
#elif (BACNET_PROTOCOL_REVISION == 14) || (BACNET_PROTOCOL_REVISION == 15)
/* from 135-2012 version of the BACnet Standard */
#define MAX_ASHRAE_OBJECT_TYPE 55
#define MAX_BACNET_SERVICES_SUPPORTED 41
#elif (BACNET_PROTOCOL_REVISION == 16)
/* Addendum 135-2012an, 135-2012at, 135-2012au,
135-2012av, 135-2012aw, 135-2012ax, 135-2012az */
#define MAX_ASHRAE_OBJECT_TYPE 56
#define MAX_BACNET_SERVICES_SUPPORTED 41
#elif (BACNET_PROTOCOL_REVISION == 17)
/* Addendum 135-2012ai */
#define MAX_ASHRAE_OBJECT_TYPE 57
#define MAX_BACNET_SERVICES_SUPPORTED 41
#elif (BACNET_PROTOCOL_REVISION == 18) || (BACNET_PROTOCOL_REVISION == 19)
/* from 135-2016 version of the BACnet Standard */
#define MAX_ASHRAE_OBJECT_TYPE 60
#define MAX_BACNET_SERVICES_SUPPORTED 44
#else
#error MAX_ASHRAE_OBJECT_TYPE and MAX_BACNET_SERVICES_SUPPORTED not defined!
#endif
/* largest BACnet Instance Number */
/* Also used as a device instance number wildcard address */
#define BACNET_MAX_INSTANCE (0x3FFFFF)
#define BACNET_INSTANCE_BITS 22
/* large BACnet Object Type */
#define BACNET_MAX_OBJECT (0x3FF)
/* Array index 0=size of array, n=array element n, MAX=all array elements */
/* 32-bit MAX, to use with uint32_t */
#define BACNET_ARRAY_ALL 0xFFFFFFFFU
/* For device object property references with no device id defined */
#define BACNET_NO_DEV_ID 0xFFFFFFFFu
#define BACNET_NO_DEV_TYPE 0xFFFFu
/* Priority Array for commandable objects */
#define BACNET_NO_PRIORITY 0
#define BACNET_MIN_PRIORITY 1
#define BACNET_MAX_PRIORITY 16
#define BACNET_BROADCAST_NETWORK (0xFFFF)
/* Any size MAC address should be allowed which is less than or
equal to 7 bytes. The IPv6 addresses are planned to be handled
outside this area. */
/* FIXME: mac[] only needs to be as big as our local datalink MAC */
#define MAX_MAC_LEN 7
struct BACnet_Device_Address {
/* mac_len = 0 is a broadcast address */
uint8_t mac_len;
/* note: MAC for IP addresses uses 4 bytes for addr, 2 bytes for port */
/* use de/encode_unsigned32/16 for re/storing the IP address */
uint8_t mac[MAX_MAC_LEN];
/* DNET,DLEN,DADR or SNET,SLEN,SADR */
/* the following are used if the device is behind a router */
/* net = 0 indicates local */
uint16_t net; /* BACnet network number */
/* LEN = 0 denotes broadcast MAC ADR and ADR field is absent */
/* LEN > 0 specifies length of ADR field */
uint8_t len; /* length of MAC address */
uint8_t adr[MAX_MAC_LEN]; /* hwaddr (MAC) address */
};
typedef struct BACnet_Device_Address BACNET_ADDRESS;
/* define a MAC address for manipulation */
struct BACnet_MAC_Address {
uint8_t len; /* length of MAC address */
uint8_t adr[MAX_MAC_LEN];
};
typedef struct BACnet_MAC_Address BACNET_MAC_ADDRESS;
/* note: with microprocessors having lots more code space than memory,
it might be better to have a packed encoding with a library to
easily access the data. */
typedef struct BACnet_Object_Id {
uint16_t type;
uint32_t instance;
} BACNET_OBJECT_ID;
#define MAX_NPDU (1+1+2+1+MAX_MAC_LEN+2+1+MAX_MAC_LEN+1+1+2)
#define MAX_PDU (MAX_APDU + MAX_NPDU)
#define BACNET_ID_VALUE(bacnet_object_instance, bacnet_object_type) ((((bacnet_object_type) & BACNET_MAX_OBJECT) << BACNET_INSTANCE_BITS) | ((bacnet_object_instance) & BACNET_MAX_INSTANCE))
#define BACNET_INSTANCE(bacnet_object_id_num) ((bacnet_object_id_num)&BACNET_MAX_INSTANCE)
#define BACNET_TYPE(bacnet_object_id_num) (((bacnet_object_id_num) >> BACNET_INSTANCE_BITS ) & BACNET_MAX_OBJECT)
#define BACNET_STATUS_OK (0)
#define BACNET_STATUS_ERROR (-1)
#define BACNET_STATUS_ABORT (-2)
#define BACNET_STATUS_REJECT (-3)
#endif
+101
View File
@@ -0,0 +1,101 @@
/**************************************************************************
*
* 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.
*********************************************************************/
#ifndef _BAC_DEV_PROP_REF_H_
#define _BAC_DEV_PROP_REF_H_
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include "bacdef.h"
#include "bacenum.h"
typedef struct BACnetDeviceObjectPropertyReference {
BACNET_OBJECT_ID objectIdentifier;
BACNET_PROPERTY_ID propertyIdentifier;
uint32_t arrayIndex;
BACNET_OBJECT_ID deviceIdentifier;
} BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE;
/** BACnetDeviceObjectReference structure.
* If the optional deviceIdentifier is not provided, then this refers
* to an object inside this Device.
*/
typedef struct BACnetDeviceObjectReference {
BACNET_OBJECT_ID deviceIdentifier; /**< Optional, for external device. */
BACNET_OBJECT_ID objectIdentifier;
} BACNET_DEVICE_OBJECT_REFERENCE;
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
int bacapp_encode_device_obj_property_ref(
uint8_t * apdu,
BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE * value);
int bacapp_encode_context_device_obj_property_ref(
uint8_t * apdu,
uint8_t tag_number,
BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE * value);
int bacapp_decode_device_obj_property_ref(
uint8_t * apdu,
BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE * value);
int bacapp_decode_context_device_obj_property_ref(
uint8_t * apdu,
uint8_t tag_number,
BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE * value);
int bacapp_encode_device_obj_ref(
uint8_t * apdu,
BACNET_DEVICE_OBJECT_REFERENCE * value);
int bacapp_encode_context_device_obj_ref(
uint8_t * apdu,
uint8_t tag_number,
BACNET_DEVICE_OBJECT_REFERENCE * value);
int bacapp_decode_device_obj_ref(
uint8_t * apdu,
BACNET_DEVICE_OBJECT_REFERENCE * value);
int bacapp_decode_context_device_obj_ref(
uint8_t * apdu,
uint8_t tag_number,
BACNET_DEVICE_OBJECT_REFERENCE * value);
#ifdef TEST
#include "ctest.h"
void testBACnetDeviceObjectPropertyReference(
Test * pTest);
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+2352
View File
File diff suppressed because it is too large Load Diff
+73
View File
@@ -0,0 +1,73 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef BACERROR_H
#define BACERROR_H
#include <stdint.h>
#include <stdbool.h>
#include "bacenum.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
int bacerror_encode_apdu(
uint8_t * apdu,
uint8_t invoke_id,
BACNET_CONFIRMED_SERVICE service,
BACNET_ERROR_CLASS error_class,
BACNET_ERROR_CODE error_code);
int bacerror_decode_service_request(
uint8_t * apdu,
unsigned apdu_len,
uint8_t * invoke_id,
BACNET_CONFIRMED_SERVICE * service,
BACNET_ERROR_CLASS * error_class,
BACNET_ERROR_CODE * error_code);
int bacerror_decode_error_class_and_code(
uint8_t * apdu,
unsigned apdu_len,
BACNET_ERROR_CLASS * error_class,
BACNET_ERROR_CODE * error_code);
#ifdef TEST
#include "ctest.h"
int bacerror_decode_apdu(
uint8_t * apdu,
unsigned apdu_len,
uint8_t * invoke_id,
BACNET_CONFIRMED_SERVICE * service,
BACNET_ERROR_CLASS * error_class,
BACNET_ERROR_CODE * error_code);
void testBACError(
Test * pTest);
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+99
View File
@@ -0,0 +1,99 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef BACINT_H
#define BACINT_H
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* unsigned value encoding and decoding */
int encode_unsigned16(
uint8_t * apdu,
uint16_t value);
int decode_unsigned16(
uint8_t * apdu,
uint16_t * value);
int encode_unsigned24(
uint8_t * apdu,
uint32_t value);
int decode_unsigned24(
uint8_t * apdu,
uint32_t * value);
int encode_unsigned32(
uint8_t * apdu,
uint32_t value);
int decode_unsigned32(
uint8_t * apdu,
uint32_t * value);
#ifdef UINT64_MAX
int decode_unsigned64(
uint8_t * buffer,
uint64_t * value);
#endif
/* signed value encoding and decoding */
int encode_signed8(
uint8_t * apdu,
int8_t value);
int decode_signed8(
uint8_t * apdu,
int32_t * value);
int encode_signed16(
uint8_t * apdu,
int16_t value);
int decode_signed16(
uint8_t * apdu,
int32_t * value);
int encode_signed24(
uint8_t * apdu,
int32_t value);
int decode_signed24(
uint8_t * apdu,
int32_t * value);
int encode_signed32(
uint8_t * apdu,
int32_t value);
int decode_signed32(
uint8_t * apdu,
int32_t * value);
#ifdef UINT64_MAX
int encode_unsigned64(
uint8_t * buffer,
uint64_t value);
#endif
#ifdef TEST
#include "ctest.h"
void testBACnetIntegers(
Test * pTest);
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+109
View File
@@ -0,0 +1,109 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef BACNET_H
#define BACNET_H
/** @file bacnet.h This file is designed to reference the entire BACnet stack library */
/* core files */
#include "version.h"
#include "config.h"
#include "address.h"
#include "apdu.h"
#include "bacapp.h"
#include "bacdcode.h"
#include "bacint.h"
#include "bacreal.h"
#include "bacstr.h"
#include "bacdef.h"
#include "bacenum.h"
#include "bacerror.h"
#include "bactext.h"
#include "datalink.h"
#include "indtext.h"
#include "npdu.h"
#include "reject.h"
#include "tsm.h"
/* services */
#include "arf.h"
#include "awf.h"
#include "cov.h"
#include "dcc.h"
#include "iam.h"
#include "ihave.h"
#include "rd.h"
#include "rp.h"
#include "rpm.h"
#include "timesync.h"
#include "whohas.h"
#include "whois.h"
#include "wp.h"
#include "event.h"
#include "lso.h"
#include "alarm_ack.h"
/* required object - note: developer must supply the device.c file
since it is not included in the library. However, the library
references the device.c members via the device.h API. */
#include "device.h"
/* demo objects */
#include "ai.h"
#include "ao.h"
#include "av.h"
#include "bacfile.h"
#include "bi.h"
#include "bo.h"
#include "bv.h"
#include "lc.h"
#include "lsp.h"
#include "mso.h"
/* demo handlers */
#include "txbuf.h"
#include "client.h"
#include "handlers.h"
/* Additions for Doxygen documenting */
/**
* @mainpage BACnet-stack API Documentation
* This documents the BACnet-Stack API, OS ports, and sample applications. <br>
*
* - The high-level handler interface can be found in the Modules tab.
* - Specifics for each file can be found in the Files tab.
* - A full list of all functions is provided in the index of the
* Files->Globals subtab.
*
* While all the central files are included in the file list, not all important
* functions have been given the javadoc treatment, nor have Modules (chapters)
* been created yet for all groupings. If you are doing work in an under-
* documented area, please add the javadoc comments at least to the API calls,
* and consider adding doxygen's module grouping for your area of interest.
*
* See doc/README.doxygen for notes on building and extending this document. <br>
* In particular, if you have graphviz installed, you can enhance this
* documentation by turning on the function call graphs feature.
*/
#endif
+52
View File
@@ -0,0 +1,52 @@
/**************************************************************************
*
* Copyright (C) 2005 John Goulah
*
* 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.
*********************************************************************/
#ifndef BACPROP_H
#define BACPROP_H
#include <stdbool.h>
#include <stdint.h>
#include "bacenum.h"
typedef struct {
signed prop_id; /* index number that matches the text */
signed tag_id; /* text pair - use NULL to end the list */
} PROP_TAG_DATA;
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
signed bacprop_tag_by_index_default(
PROP_TAG_DATA * data_list,
signed index,
signed default_ret);
signed bacprop_property_tag(
BACNET_OBJECT_TYPE type,
signed prop);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+90
View File
@@ -0,0 +1,90 @@
/**************************************************************************
*
* 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.
*********************************************************************/
#ifndef _BAC_PROP_STATES_H_
#define _BAC_PROP_STATES_H_
#include <stdint.h>
#include <stdbool.h>
#include "bacenum.h"
#include "bacapp.h"
#include "timestamp.h"
typedef enum {
BOOLEAN_VALUE,
BINARY_VALUE,
EVENT_TYPE,
POLARITY,
PROGRAM_CHANGE,
PROGRAM_STATE,
REASON_FOR_HALT,
RELIABILITY,
STATE,
SYSTEM_STATUS,
UNITS,
UNSIGNED_VALUE,
LIFE_SAFETY_MODE,
LIFE_SAFETY_STATE
} BACNET_PROPERTY_STATE_TYPE;
typedef struct {
BACNET_PROPERTY_STATE_TYPE tag;
union {
bool booleanValue;
BACNET_BINARY_PV binaryValue;
BACNET_EVENT_TYPE eventType;
BACNET_POLARITY polarity;
BACNET_PROGRAM_REQUEST programChange;
BACNET_PROGRAM_STATE programState;
BACNET_PROGRAM_ERROR programError;
BACNET_RELIABILITY reliability;
BACNET_EVENT_STATE state;
BACNET_DEVICE_STATUS systemStatus;
BACNET_ENGINEERING_UNITS units;
uint32_t unsignedValue;
BACNET_LIFE_SAFETY_MODE lifeSafetyMode;
BACNET_LIFE_SAFETY_STATE lifeSafetyState;
} state;
} BACNET_PROPERTY_STATE;
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
int bacapp_decode_property_state(
uint8_t * apdu,
BACNET_PROPERTY_STATE * value);
int bacapp_decode_context_property_state(
uint8_t * apdu,
uint8_t tag_number,
BACNET_PROPERTY_STATE * value);
int bacapp_encode_property_state(
uint8_t * apdu,
BACNET_PROPERTY_STATE * value);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+79
View File
@@ -0,0 +1,79 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef BACREAL_H
#define BACREAL_H
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
int decode_real_safe(
uint8_t * apdu,
uint32_t len_value,
float *real_value);
int decode_real(
uint8_t * apdu,
float *real_value);
int decode_context_real(
uint8_t * apdu,
uint8_t tag_number,
float *real_value);
int encode_bacnet_real(
float value,
uint8_t * apdu);
int decode_double(
uint8_t * apdu,
double *real_value);
int decode_context_double(
uint8_t * apdu,
uint8_t tag_number,
double *double_value);
int decode_double_safe(
uint8_t * apdu,
uint32_t len_value,
double *double_value);
int encode_bacnet_double(
double value,
uint8_t * apdu);
#ifdef TEST
#include "ctest.h"
void testBACreal(
Test * pTest);
void testBACdouble(
Test * pTest);
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+290
View File
@@ -0,0 +1,290 @@
/**************************************************************************
*
* Copyright (C) 2015 Nikola Jelic <nikola.jelic@euroicc.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.
*
*********************************************************************/
#ifndef BACNET_SECURITY_H
#define BACNET_SECURITY_H
#define MAX_AUTH_DATA_LEN 16
#define MD5_KEY_SIZE 16
#define AES_KEY_SIZE 16
#define SHA256_KEY_SIZE 32
#define MAX_KEY_LEN 48
#define MAX_UPDATE_KEY_COUNT 32
#define MAX_INCORRECT_KEYS 255
#define MAX_SUPPORTED_ALGORITHMS 255
#define MAX_PAD_LEN 16
#define SIGNATURE_LEN 16
#include <stdbool.h>
#include <stdint.h>
#include "bacdef.h"
#include "bacenum.h"
typedef struct BACnet_Security_Wrapper {
bool payload_net_or_bvll_flag; /* true if NPDU or BVLL */
bool encrypted_flag;
bool authentication_flag; /* always false for responses */
bool do_not_unwrap_flag; /* always true if do-not-encrypt is true */
bool do_not_decrypt_flag; /* when encrypted flag is false, it also false */
bool non_trusted_source_flag;
bool secured_by_router_flag;
uint8_t key_revision; /* 0 for Device-Master key */
uint16_t key_identifier;
uint32_t source_device_instance;
uint32_t message_id; /* monotonically increased value */
uint32_t timestamp; /* seconds from UTC 1970-1-1 00:00:00 */
uint32_t destination_device_instance;
uint16_t dnet;
uint8_t dlen;
uint8_t dadr[MAX_MAC_LEN];
uint16_t snet;
uint8_t slen;
uint8_t sadr[MAX_MAC_LEN];
uint8_t authentication_mechanism; /* present when User-Authenticated or
* Application-Specific keys are used with: */
/* APDU: Confrmed-Request, Unconfirmed-Request */
/* NPDU: Initialize-Routing-Table, Establish-Connection-To-Network,
* Disconnect-Connection-To-Network */
/* BVLL: Write-Broadcast-Distribution-Table, Read-Broadcast-Distribution-Table,
* Register-Foreign-Device, Read-Foreign-Device-Table,
* Delete-Foreign-Device-Table-Entry */
/* 0 is only legitimate value for now. 200-255 are vendor-specific */
uint16_t user_id; /* 0 for unknown */
uint8_t user_role; /* 0 and 1 are "system users": 0 for device-to-device non-human,
* 1 for device-to-device by unknown human */
uint16_t authentication_data_length; /* authentication mechanism 1-255 */
uint16_t vendor_id; /* authentication mechanism 200-255 */
uint8_t authentication_data[MAX_AUTH_DATA_LEN]; /* other than id, role, length and
* vendor-id */
uint16_t service_data_len; /* case-to-case */
uint8_t *service_data;
uint8_t service_type; /* first octet of service_data */
uint16_t padding_len; /* included in padding */
uint8_t padding[MAX_PAD_LEN];
uint8_t signature[SIGNATURE_LEN]; /* hmac-md5 or hmac-sha256, first 16 bytes */
} BACNET_SECURITY_WRAPPER;
typedef struct Challenge_Request {
uint8_t message_challenge; /* 1 as a response, everything else for other */
uint32_t orig_message_id;
uint32_t orig_timestamp;
} BACNET_CHALLENGE_REQUEST;
typedef struct Security_Payload {
uint16_t payload_length;
uint8_t *payload;
} BACNET_SECURITY_PAYLOAD;
struct Bad_Timestamp {
uint32_t expected_timestamp;
};
struct Cannot_Use_Key {
uint16_t key;
};
struct Incorrect_Key {
uint8_t number_of_keys;
uint16_t keys[MAX_INCORRECT_KEYS];
};
struct Unknown_Authentication_Type {
uint8_t original_authentication_type;
uint16_t vendor_id;
};
struct Unknown_Key {
uint16_t original_key;
};
struct Unknown_Key_Revision {
uint8_t original_key_revision;
};
struct Too_Many_Keys {
uint8_t max_num_of_keys;
};
struct Invalid_Key_Data {
uint16_t key;
};
typedef struct Security_Response {
uint16_t response_code;
uint32_t orig_message_id;
uint32_t orig_timestamp;
union {
struct Bad_Timestamp bad_timestamp;
struct Cannot_Use_Key cannot_use_key;
struct Incorrect_Key incorrect_key;
struct Unknown_Authentication_Type unknown_authentication_type;
struct Unknown_Key unknown_key;
struct Unknown_Key_Revision unknown_key_revision;
struct Too_Many_Keys too_many_keys;
struct Invalid_Key_Data invalid_key_data;
} response;
} BACNET_SECURITY_RESPONSE;
typedef struct Request_Key_Update {
uint8_t set_1_key_revision;
uint32_t set_1_activation_time;
uint32_t set_1_expiration_time;
uint8_t set_2_key_revision;
uint32_t set_2_activation_time;
uint32_t set_2_expiration_time;
uint8_t distribution_key_revision;
} BACNET_REQUEST_KEY_UPDATE;
typedef struct Key_Entry {
uint16_t key_identifier;
uint8_t key_len;
uint8_t key[MAX_KEY_LEN];
} BACNET_KEY_ENTRY;
typedef struct Update_Key_Set {
bool set_rae[2], set_ck[2], set_clr[2];
bool more;
bool remove; /* false for add, true for remove */
uint8_t set_key_revision[2];
uint32_t set_activation_time[2];
uint32_t set_expiration_time[2];
uint8_t set_key_count[2];
BACNET_KEY_ENTRY set_keys[2][MAX_UPDATE_KEY_COUNT];
} BACNET_UPDATE_KEY_SET;
typedef struct Update_Distribution_Key {
uint8_t key_revision;
BACNET_KEY_ENTRY key;
} BACNET_UPDATE_DISTRIBUTION_KEY;
typedef struct Request_Master_Key {
uint8_t no_supported_algorithms;
uint8_t es_algorithms[MAX_SUPPORTED_ALGORITHMS];
} BACNET_REQUEST_MASTER_KEY;
typedef struct Set_Master_Key {
BACNET_KEY_ENTRY key;
} BACNET_SET_MASTER_KEY;
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* helper functions */
BACNET_KEY_IDENTIFIER_ALGORITHM key_algorithm(uint16_t id);
BACNET_KEY_IDENTIFIER_KEY_NUMBER key_number(uint16_t id);
/* key manipulation functions - port specific! */
BACNET_SECURITY_RESPONSE_CODE bacnet_master_key_set(BACNET_SET_MASTER_KEY *
key);
BACNET_SECURITY_RESPONSE_CODE
bacnet_distribution_key_update(BACNET_UPDATE_DISTRIBUTION_KEY * key);
BACNET_SECURITY_RESPONSE_CODE bacnet_key_set_update(BACNET_UPDATE_KEY_SET *
update_key_sets);
BACNET_SECURITY_RESPONSE_CODE bacnet_find_key(uint8_t revision,
BACNET_KEY_ENTRY * key);
/* signing/verification and encryption/decryption - port specific */
int key_sign_msg(BACNET_KEY_ENTRY * key,
uint8_t * msg,
uint32_t msg_len,
uint8_t * signature);
bool key_verify_sign_msg(BACNET_KEY_ENTRY * key,
uint8_t * msg,
uint32_t msg_len,
uint8_t * signature);
int key_encrypt_msg(BACNET_KEY_ENTRY * key,
uint8_t * msg,
uint32_t msg_len,
uint8_t * signature);
bool key_decrypt_msg(BACNET_KEY_ENTRY * key,
uint8_t * msg,
uint32_t msg_len,
uint8_t * signature);
void key_set_padding(BACNET_KEY_ENTRY * key,
int enc_len,
uint16_t * padding_len,
uint8_t * padding);
/* encoders */
int encode_security_wrapper(int bytes_before,
uint8_t * apdu,
BACNET_SECURITY_WRAPPER * wrapper);
int encode_challenge_request(uint8_t * apdu,
BACNET_CHALLENGE_REQUEST * bc_req);
int encode_security_payload(uint8_t * apdu,
BACNET_SECURITY_PAYLOAD * payload);
int encode_security_response(uint8_t * apdu,
BACNET_SECURITY_RESPONSE * resp);
int encode_request_key_update(uint8_t * apdu,
BACNET_REQUEST_KEY_UPDATE * req);
int encode_key_entry(uint8_t * apdu,
BACNET_KEY_ENTRY * entry);
int encode_update_key_set(uint8_t * apdu,
BACNET_UPDATE_KEY_SET * key_set);
int encode_update_distribution_key(uint8_t * apdu,
BACNET_UPDATE_DISTRIBUTION_KEY * dist_key);
int encode_request_master_key(uint8_t * apdu,
BACNET_REQUEST_MASTER_KEY * req_master_key);
int encode_set_master_key(uint8_t * apdu,
BACNET_SET_MASTER_KEY * set_master_key);
/* safe decoders */
int decode_security_wrapper_safe(int bytes_before,
uint8_t * apdu,
uint32_t apdu_len_remaining,
BACNET_SECURITY_WRAPPER * wrapper);
int decode_challenge_request_safe(uint8_t * apdu,
uint32_t apdu_len_remaining,
BACNET_CHALLENGE_REQUEST * bc_req);
int decode_security_payload_safe(uint8_t * apdu,
uint32_t apdu_len_remaining,
BACNET_SECURITY_PAYLOAD * payload);
int decode_security_response_safe(uint8_t * apdu,
uint32_t apdu_len_remaining,
BACNET_SECURITY_RESPONSE * resp);
int decode_request_key_update_safe(uint8_t * apdu,
uint32_t apdu_len_remaining,
BACNET_REQUEST_KEY_UPDATE * req);
int decode_key_entry_safe(uint8_t * apdu,
uint32_t apdu_len_remaining,
BACNET_KEY_ENTRY * entry);
int decode_update_key_set_safe(uint8_t * apdu,
uint32_t apdu_len_remaining,
BACNET_UPDATE_KEY_SET * key_set);
int decode_update_distribution_key_safe(uint8_t * apdu,
uint32_t apdu_len_remaining,
BACNET_UPDATE_DISTRIBUTION_KEY * dist_key);
int decode_request_master_key_safe(uint8_t * apdu,
uint32_t apdu_len_remaining,
BACNET_REQUEST_MASTER_KEY * req_master_key);
int decode_set_master_key_safe(uint8_t * apdu,
uint32_t apdu_len_remaining,
BACNET_SET_MASTER_KEY * set_master_key);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+207
View File
@@ -0,0 +1,207 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef BACSTR_H
#define BACSTR_H
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include "bacdef.h"
#include "config.h"
/* bit strings
They could be as large as 256/8=32 octets */
typedef struct BACnet_Bit_String {
uint8_t bits_used;
uint8_t value[MAX_BITSTRING_BYTES];
} BACNET_BIT_STRING;
typedef struct BACnet_Character_String {
size_t length;
uint8_t encoding;
/* limit - 6 octets is the most our tag and type could be */
char value[MAX_CHARACTER_STRING_BYTES];
} BACNET_CHARACTER_STRING;
/* FIXME: convert the bacdcode library to use BACNET_OCTET_STRING
for APDU buffer to prevent buffer overflows */
typedef struct BACnet_Octet_String {
size_t length;
/* limit - 6 octets is the most our tag and type could be */
uint8_t value[MAX_OCTET_STRING_BYTES];
} BACNET_OCTET_STRING;
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
void bitstring_init(
BACNET_BIT_STRING * bit_string);
void bitstring_set_bit(
BACNET_BIT_STRING * bit_string,
uint8_t bit_number,
bool value);
bool bitstring_bit(
BACNET_BIT_STRING * bit_string,
uint8_t bit_number);
uint8_t bitstring_bits_used(
BACNET_BIT_STRING * bit_string);
/* returns the number of bytes that a bit string is using */
uint8_t bitstring_bytes_used(
BACNET_BIT_STRING * bit_string);
uint8_t bitstring_bits_capacity(
BACNET_BIT_STRING * bit_string);
/* used for encoding and decoding from the APDU */
uint8_t bitstring_octet(
BACNET_BIT_STRING * bit_string,
uint8_t octet_index);
bool bitstring_set_octet(
BACNET_BIT_STRING * bit_string,
uint8_t index,
uint8_t octet);
bool bitstring_set_bits_used(
BACNET_BIT_STRING * bit_string,
uint8_t bytes_used,
uint8_t unused_bits);
bool bitstring_copy(
BACNET_BIT_STRING * dest,
BACNET_BIT_STRING * src);
bool bitstring_same(
BACNET_BIT_STRING * bitstring1,
BACNET_BIT_STRING * bitstring2);
bool bitstring_init_ascii(
BACNET_BIT_STRING * bit_string,
const char *ascii);
/* returns false if the string exceeds capacity
initialize by using length=0 */
bool characterstring_init(
BACNET_CHARACTER_STRING * char_string,
uint8_t encoding,
const char *value,
size_t length);
/* used for ANSI C-Strings */
bool characterstring_init_ansi(
BACNET_CHARACTER_STRING * char_string,
const char *value);
bool characterstring_copy(
BACNET_CHARACTER_STRING * dest,
BACNET_CHARACTER_STRING * src);
bool characterstring_ansi_copy(
char *dest,
size_t dest_max_len,
BACNET_CHARACTER_STRING * src);
/* returns true if the strings are the same length, encoding, value */
bool characterstring_same(
BACNET_CHARACTER_STRING * dest,
BACNET_CHARACTER_STRING * src);
bool characterstring_ansi_same(
BACNET_CHARACTER_STRING * dest,
const char *src);
/* returns false if the string exceeds capacity */
bool characterstring_append(
BACNET_CHARACTER_STRING * char_string,
const char *value,
size_t length);
/* This function sets a new length without changing the value.
If length exceeds capacity, no modification happens and
function returns false. */
bool characterstring_truncate(
BACNET_CHARACTER_STRING * char_string,
size_t length);
bool characterstring_set_encoding(
BACNET_CHARACTER_STRING * char_string,
uint8_t encoding);
/* Returns the value */
char *characterstring_value(
BACNET_CHARACTER_STRING * char_string);
/* returns the length */
size_t characterstring_length(
BACNET_CHARACTER_STRING * char_string);
uint8_t characterstring_encoding(
BACNET_CHARACTER_STRING * char_string);
size_t characterstring_capacity(
BACNET_CHARACTER_STRING * char_string);
bool characterstring_printable(
BACNET_CHARACTER_STRING * char_string);
bool characterstring_valid(
BACNET_CHARACTER_STRING * char_string);
bool utf8_isvalid(
const char *str,
size_t length);
/* returns false if the string exceeds capacity
initialize by using length=0 */
bool octetstring_init(
BACNET_OCTET_STRING * octet_string,
uint8_t * value,
size_t length);
#ifdef PRINT_ENABLED
/* converts an null terminated ASCII Hex string to an octet string.
returns true if successfully converted and fits; false if too long */
bool octetstring_init_ascii_hex(
BACNET_OCTET_STRING * octet_string,
const char *ascii_hex);
#endif
bool octetstring_copy(
BACNET_OCTET_STRING * dest,
BACNET_OCTET_STRING * src);
size_t octetstring_copy_value(
uint8_t * dest,
size_t length,
BACNET_OCTET_STRING * src);
/* returns false if the string exceeds capacity */
bool octetstring_append(
BACNET_OCTET_STRING * octet_string,
uint8_t * value,
size_t length);
/* This function sets a new length without changing the value.
If length exceeds capacity, no modification happens and
function returns false. */
bool octetstring_truncate(
BACNET_OCTET_STRING * octet_string,
size_t length);
/* Returns the value */
uint8_t *octetstring_value(
BACNET_OCTET_STRING * octet_string);
/* Returns the length.*/
size_t octetstring_length(
BACNET_OCTET_STRING * octet_string);
size_t octetstring_capacity(
BACNET_OCTET_STRING * octet_string);
/* returns true if the same length and contents */
bool octetstring_value_same(
BACNET_OCTET_STRING * octet_string1,
BACNET_OCTET_STRING * octet_string2);
#ifdef TEST
#include "ctest.h"
void testBACnetStrings(
Test * pTest);
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+145
View File
@@ -0,0 +1,145 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef BACTEXT_H
#define BACTEXT_H
/* tiny implementations have no need to print */
#if PRINT_ENABLED
#define BACTEXT_PRINT_ENABLED
#else
#ifdef TEST
#define BACTEXT_PRINT_ENABLED
#endif
#endif
#include <stdbool.h>
#include <stdint.h>
#include "indtext.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
const char *bactext_confirmed_service_name(
unsigned index);
const char *bactext_unconfirmed_service_name(
unsigned index);
const char *bactext_application_tag_name(
unsigned index);
bool bactext_application_tag_index(
const char *search_name,
unsigned *found_index);
const char *bactext_object_type_name(
unsigned index);
bool bactext_object_type_index(
const char *search_name,
unsigned *found_index);
const char *bactext_notify_type_name(
unsigned index);
const char *bactext_event_type_name(
unsigned index);
const char *bactext_property_name(
unsigned index);
const char *bactext_property_name_default(
unsigned index,
const char *default_string);
bool bactext_property_index(
const char *search_name,
unsigned *found_index);
const char *bactext_engineering_unit_name(
unsigned index);
bool bactext_engineering_unit_index(
const char *search_name,
unsigned *found_index);
const char *bactext_reject_reason_name(
unsigned index);
const char *bactext_abort_reason_name(
unsigned index);
const char *bactext_error_class_name(
unsigned index);
const char *bactext_error_code_name(
unsigned index);
unsigned bactext_property_id(
const char *name);
const char *bactext_month_name(
unsigned index);
const char *bactext_week_of_month_name(
unsigned index);
const char *bactext_day_of_week_name(
unsigned index);
const char *bactext_event_state_name(
unsigned index);
const char *bactext_binary_present_value_name(
unsigned index);
const char *bactext_binary_polarity_name(
unsigned index);
bool bactext_binary_present_value_index(
const char *search_name,
unsigned *found_index);
const char *bactext_reliability_name(
unsigned index);
const char *bactext_device_status_name(
unsigned index);
const char *bactext_segmentation_name(
unsigned index);
bool bactext_segmentation_index(
const char *search_name,
unsigned *found_index);
const char *bactext_node_type_name(
unsigned index);
const char *bactext_character_string_encoding_name(
unsigned index);
const char *bactext_event_transition_name(
unsigned index);
bool bactext_event_transition_index(
const char *search_name,
unsigned *found_index);
const char *bactext_days_of_week_name(
unsigned index);
bool bactext_days_of_week_index(
const char *search_name,
unsigned *found_index);
const char *bactext_network_layer_msg_name(
unsigned index);
const char *bactext_life_safety_state_name(
unsigned index);
const char *bactext_device_communications_name(
unsigned index);
const char *bactext_lighting_operation_name(
unsigned index);
const char *bactext_lighting_in_progress(
unsigned index);
const char *bactext_lighting_transition(
unsigned index);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+62
View File
@@ -0,0 +1,62 @@
/**************************************************************************
*
* Copyright (C) 2015 Nikola Jelic
*
* 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.
*********************************************************************/
#ifndef _BAC_TIME_VALUE_H_
#define _BAC_TIME_VALUE_H_
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include "bacdef.h"
#include "bacenum.h"
#include "bacapp.h"
typedef struct {
BACNET_TIME Time;
BACNET_APPLICATION_DATA_VALUE Value;
} BACNET_TIME_VALUE;
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
int bacapp_encode_time_value(uint8_t * apdu,
BACNET_TIME_VALUE * value);
int bacapp_encode_context_time_value(uint8_t * apdu,
uint8_t tag_number,
BACNET_TIME_VALUE * value);
int bacapp_decode_time_value(uint8_t * apdu,
BACNET_TIME_VALUE * value);
int bacapp_decode_context_time_value(uint8_t * apdu,
uint8_t tag_number,
BACNET_TIME_VALUE * value);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+53
View File
@@ -0,0 +1,53 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef BIGEND_H
#define BIGEND_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* Big-Endian systems save the most significant byte first. */
/* Sun and Motorola processors, IBM-370s and PDP-10s are big-endian. */
/* for example, a 4 byte integer 67305985 is 0x04030201 in hexidecimal. */
/* x[0] = 0x04 */
/* x[1] = 0x03 */
/* x[2] = 0x02 */
/* x[3] = 0x01 */
/* Little-Endian systems save the least significant byte first. */
/* The entire Intel x86 family, Vaxes, Alphas and PDP-11s are little-endian. */
/* for example, a 4 byte integer 67305985 is 0x04030201 in hexidecimal. */
/* x[0] = 0x01 */
/* x[1] = 0x02 */
/* x[2] = 0x03 */
/* x[3] = 0x04 */
int big_endian(
void);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+126
View File
@@ -0,0 +1,126 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef BIP_H
#define BIP_H
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
#include "bacdef.h"
#include "npdu.h"
#include "net.h"
/* specific defines for BACnet/IP over Ethernet */
#define MAX_HEADER (1 + 1 + 2)
#define MAX_MPDU (MAX_HEADER+MAX_PDU)
#define BVLL_TYPE_BACNET_IP (0x81)
extern bool BIP_Debug;
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* note: define init, set_interface, and cleanup in your port */
/* on Linux, ifname is eth0, ath0, arc0, and others.
on Windows, ifname is the dotted ip address of the interface */
bool bip_init(
char *ifname);
void bip_set_interface(
char *ifname);
void bip_cleanup(
void);
/* common BACnet/IP functions */
void bip_set_socket(
int sock_fd);
int bip_socket(
void);
bool bip_valid(
void);
void bip_get_broadcast_address(
BACNET_ADDRESS * dest); /* destination address */
void bip_get_my_address(
BACNET_ADDRESS * my_address);
/* function to send a packet out the BACnet/IP socket */
/* returns zero on success, non-zero on failure */
int bip_send_pdu(
BACNET_ADDRESS * dest, /* destination address */
BACNET_NPDU_DATA * npdu_data, /* network information */
uint8_t * pdu, /* any data to be sent - may be null */
unsigned pdu_len); /* number of bytes of data */
/* receives a BACnet/IP packet */
/* returns the number of octets in the PDU, or zero on failure */
uint16_t bip_receive(
BACNET_ADDRESS * src, /* source address */
uint8_t * pdu, /* PDU data */
uint16_t max_pdu, /* amount of space available in the PDU */
unsigned timeout); /* milliseconds to wait for a packet */
/* use network byte order for setting */
void bip_set_port(
uint16_t port);
bool bip_port_changed(void);
/* returns network byte order */
uint16_t bip_get_port(
void);
/* use network byte order for setting */
void bip_set_addr(
uint32_t net_address);
/* returns network byte order */
uint32_t bip_get_addr(
void);
/* use network byte order for setting */
void bip_set_broadcast_addr(
uint32_t net_address);
/* returns network byte order */
uint32_t bip_get_broadcast_addr(
void);
/* gets an IP address by name, where name can be a
string that is an IP address in dotted form, or
a name that is a domain name
returns 0 if not found, or
an IP address in network byte order */
long bip_getaddrbyname(
const char *host_name);
#ifdef __cplusplus
}
#endif /* __cplusplus */
/** @defgroup DLBIP BACnet/IP DataLink Network Layer
* @ingroup DataLink
* Implementation of the Network Layer using BACnet/IP as the transport, as
* described in Annex J.
* The functions described here fulfill the roles defined generically at the
* DataLink level by serving as the implementation of the function templates.
*
*/
#endif
+87
View File
@@ -0,0 +1,87 @@
/**
* @file
* @author Steve Karg
* @date 2015
* @defgroup DLBIP6 BACnet/IPv6 DataLink Network Layer
* @ingroup DataLink
*
* Implementation of the Network Layer using BACnet/IPv6 as the transport, as
* described in Annex J.
* The functions described here fulfill the roles defined generically at the
* DataLink level by serving as the implementation of the function templates.
*/
#ifndef BIP6_H
#define BIP6_H
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
#include "bacdef.h"
#include "npdu.h"
#include "bvlc6.h"
/* specific defines for BACnet/IP over Ethernet */
#define BIP6_HEADER_MAX (1 + 1 + 2)
#define BIP6_MPDU_MAX (BIP6_HEADER_MAX+MAX_PDU)
/* for legacy demo applications */
#define MAX_MPDU BIP6_MPDU_MAX
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* 6 datalink functions used by demo handlers and applications:
init, send, receive, cleanup, unicast/broadcast address.
Note: the addresses used here are VMAC addresses. */
bool bip6_init(
char *ifname);
void bip6_cleanup(
void);
void bip6_get_broadcast_address(
BACNET_ADDRESS * my_address);
void bip6_get_my_address(
BACNET_ADDRESS * my_address);
int bip6_send_pdu(
BACNET_ADDRESS * dest,
BACNET_NPDU_DATA * npdu_data,
uint8_t * pdu,
unsigned pdu_len);
uint16_t bip6_receive(
BACNET_ADDRESS * src,
uint8_t * pdu,
uint16_t max_pdu,
unsigned timeout);
/* functions that are custom per port */
void bip6_set_interface(
char *ifname);
bool bip6_address_match_self(
BACNET_IP6_ADDRESS *addr);
bool bip6_set_addr(
BACNET_IP6_ADDRESS *addr);
bool bip6_get_addr(
BACNET_IP6_ADDRESS *addr);
void bip6_set_port(
uint16_t port);
uint16_t bip6_get_port(
void);
bool bip6_set_broadcast_addr(
BACNET_IP6_ADDRESS *addr);
/* returns network byte order */
bool bip6_get_broadcast_addr(
BACNET_IP6_ADDRESS *addr);
int bip6_send_mpdu(
BACNET_IP6_ADDRESS *addr,
uint8_t * mtu,
uint16_t mtu_len);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+80
View File
@@ -0,0 +1,80 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef BITS_H
#define BITS_H
/********************************************************************
* Bit Masks
*********************************************************************/
#define BIT(x) (1<<(x))
#define BIT0 (0x01)
#define BIT1 (0x02)
#define BIT2 (0x04)
#define BIT3 (0x08)
#define BIT4 (0x10)
#define BIT5 (0x20)
#define BIT6 (0x40)
#define BIT7 (0x80)
#define BIT8 (0x0100)
#define BIT9 (0x0200)
#define BIT10 (0x0400)
#define BIT11 (0x0800)
#define BIT12 (0x1000)
#define BIT13 (0x2000)
#define BIT14 (0x4000)
#define BIT15 (0x8000)
#define BIT16 (0x010000UL)
#define BIT17 (0x020000UL)
#define BIT18 (0x040000UL)
#define BIT19 (0x080000UL)
#define BIT20 (0x100000UL)
#define BIT21 (0x200000UL)
#define BIT22 (0x400000UL)
#define BIT23 (0x800000UL)
#define BIT24 (0x01000000UL)
#define BIT25 (0x02000000UL)
#define BIT26 (0x04000000UL)
#define BIT27 (0x08000000UL)
#define BIT28 (0x10000000UL)
#define BIT29 (0x20000000UL)
#define BIT30 (0x40000000UL)
#define BIT31 (0x80000000UL)
/* a=register, b=bit number to act upon 0-n */
#define BIT_SET(a,b) ((a) |= (1<<(b)))
#define BIT_CLEAR(a,b) ((a) &= ~(1<<(b)))
#define BIT_FLIP(a,b) ((a) ^= (1<<(b)))
#define BIT_CHECK(a,b) ((a) & (1<<(b)))
/* x=target variable, y=mask */
#define BITMASK_SET(x,y) ((x) |= (y))
#define BITMASK_CLEAR(x,y) ((x) &= (~(y)))
#define BITMASK_FLIP(x,y) ((x) ^= (y))
#define BITMASK_CHECK(x,y) (((x) & (y)) == (y))
#ifndef _BV
#define _BV(x) (1<<(x))
#endif
#endif
+182
View File
@@ -0,0 +1,182 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef BVLC_H
#define BVLC_H
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
#include <time.h>
#include "bacdef.h"
#include "npdu.h"
#include "bip.h"
struct sockaddr_in; /* Defined elsewhere, needed here. */
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#if defined(BBMD_ENABLED) && BBMD_ENABLED
void bvlc_maintenance_timer(
time_t seconds);
#else
#define bvlc_maintenance_timer(x)
#endif
typedef struct {
/* true if valid entry - false if not */
bool valid;
/* BACnet/IP address */
struct in_addr dest_address; /* in network format */
/* BACnet/IP port number - not always 47808=BAC0h */
uint16_t dest_port; /* in network format */
/* Broadcast Distribution Mask */
struct in_addr broadcast_mask; /* in tework format */
} BBMD_TABLE_ENTRY;
uint16_t bvlc_receive(
BACNET_ADDRESS * src, /* returns the source address */
uint8_t * npdu, /* returns the NPDU */
uint16_t max_npdu, /* amount of space available in the NPDU */
unsigned timeout); /* number of milliseconds to wait for a packet */
int bvlc_send_pdu(
BACNET_ADDRESS * dest, /* destination address */
BACNET_NPDU_DATA * npdu_data, /* network information */
uint8_t * pdu, /* any data to be sent - may be null */
unsigned pdu_len);
int bvlc_send_mpdu(
struct sockaddr_in *dest,
uint8_t * mtu,
uint16_t mtu_len);
#if defined(BBMD_CLIENT_ENABLED) && BBMD_CLIENT_ENABLED
int bvlc_encode_write_bdt_init(
uint8_t * pdu,
unsigned entries);
int bvlc_encode_read_fdt(
uint8_t * pdu);
int bvlc_encode_delete_fdt_entry(
uint8_t * pdu,
uint32_t address, /* in network byte order */
uint16_t port); /* in network byte order */
int bvlc_encode_original_unicast_npdu(
uint8_t * pdu,
uint8_t * npdu,
unsigned npdu_length);
int bvlc_encode_original_broadcast_npdu(
uint8_t * pdu,
uint8_t * npdu,
unsigned npdu_length);
#endif
int bvlc_encode_read_bdt(
uint8_t * pdu);
int bvlc_bbmd_read_bdt(
uint32_t bbmd_address,
uint16_t bbmd_port);
/* registers with a bbmd as a foreign device */
int bvlc_register_with_bbmd(
uint32_t bbmd_address, /* in network byte order */
uint16_t bbmd_port, /* in network byte order */
uint16_t time_to_live_seconds);
/* Note any BVLC_RESULT code, or NAK the BVLL message in the unsupported cases. */
int bvlc_for_non_bbmd(
struct sockaddr_in *sout,
uint8_t * npdu,
uint16_t received_bytes);
/* Returns the last BVLL Result we received, either as the result of a BBMD
* request we sent, or (if not a BBMD or Client), from trying to register
* as a foreign device. */
BACNET_BVLC_RESULT bvlc_get_last_result(
void);
/* Returns the current BVLL Function Code we are processing.
* We have to store this higher layer code for when the lower layers
* need to know what it is, especially to differentiate between
* BVLC_ORIGINAL_UNICAST_NPDU and BVLC_ORIGINAL_BROADCAST_NPDU. */
BACNET_BVLC_FUNCTION bvlc_get_function_code(
void);
/* Local interface to manage BBMD.
* The interface user needs to handle mutual exclusion if needed i.e.
* BACnet packet is not being handled when the BBMD table is modified.
*/
/* Get handle to broadcast distribution table. Returns the number of
* valid entries in the table. */
int bvlc_get_bdt_local(
const BBMD_TABLE_ENTRY** table);
/* Invalidate all entries in the broadcast distribution table */
void bvlc_clear_bdt_local(void);
/* Add new entry to broadcast distribution table. Returns true if the new
* entry was added successfully */
bool bvlc_add_bdt_entry_local(
BBMD_TABLE_ENTRY* entry);
/* Backup broadcast distribution table to a file.
* Filename is the BBMD_BACKUP_FILE constant
*/
void bvlc_bdt_backup_local(
void);
/* Restore broadcast distribution from a file.
* Filename is the BBMD_BACKUP_FILE constant
*/
void bvlc_bdt_restore_local(
void);
/* NAT handling
* If the communication between BBMDs goes through a NAT enabled internet
* router, special considerations are needed as stated in Annex J.7.8.
*
* In short, the local IP address of the BBMD is different than the global
* address which is visible to the other BBMDs or foreign devices. This is
* why the source address in forwarded messages needs to be changed to the
* global IP address.
*
* For other considerations/limitations see Annex J.7.8.
*/
/* Set global IP address of a NAT enabled router which is used in forwarded
* messages. Enables NAT handling.
*/
void bvlc_set_global_address_for_nat(const struct in_addr* addr);
/* Disable NAT handling of BBMD.
*/
void bvlc_disable_nat(void);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* */
+403
View File
@@ -0,0 +1,403 @@
/**
* @file
* @author Steve Karg
* @date 2015
*
* Implementation of the BACnet Virtual Link Layer using IPv6,
* as described in Annex J.
*/
#ifndef BVLC6_H
#define BVLC6_H
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
#include <time.h>
#include "bacdef.h"
#include "npdu.h"
/**
* BVLL for BACnet/IPv6
* @{
*/
#define BVLL_TYPE_BACNET_IP6 (0x82)
/** @} */
/**
* B/IPv6 BVLL Messages
* @{
*/
#define BVLC6_RESULT 0x00
#define BVLC6_ORIGINAL_UNICAST_NPDU 0x01
#define BVLC6_ORIGINAL_BROADCAST_NPDU 0x02
#define BVLC6_ADDRESS_RESOLUTION 0x03
#define BVLC6_FORWARDED_ADDRESS_RESOLUTION 0x04
#define BVLC6_ADDRESS_RESOLUTION_ACK 0x05
#define BVLC6_VIRTUAL_ADDRESS_RESOLUTION 0x06
#define BVLC6_VIRTUAL_ADDRESS_RESOLUTION_ACK 0x07
#define BVLC6_FORWARDED_NPDU 0x08
#define BVLC6_REGISTER_FOREIGN_DEVICE 0x09
#define BVLC6_DELETE_FOREIGN_DEVICE 0x0A
#define BVLC6_SECURE_BVLL 0x0B
#define BVLC6_DISTRIBUTE_BROADCAST_TO_NETWORK 0x0C
/** @} */
/**
* BVLC Result Code
* @{
*/
#define BVLC6_RESULT_SUCCESSFUL_COMPLETION 0x0000
#define BVLC6_RESULT_ADDRESS_RESOLUTION_NAK 0x0030
#define BVLC6_RESULT_VIRTUAL_ADDRESS_RESOLUTION_NAK 0x0060
#define BVLC6_RESULT_REGISTER_FOREIGN_DEVICE_NAK 0x0090
#define BVLC6_RESULT_DELETE_FOREIGN_DEVICE_NAK 0x00A0
#define BVLC6_RESULT_DISTRIBUTE_BROADCAST_TO_NETWORK_NAK 0x00C0
/** @} */
/**
* BACnet IPv6 Multicast Group ID
* BACnet broadcast messages shall be delivered by IPv6 multicasts
* as opposed to using IP broadcasting. Broadcasting in
* IPv6 is subsumed by multicasting to the all-nodes link
* group FF02::1; however, the use of the all-nodes group is not
* recommended, and BACnet/IPv6 uses an IANA permanently assigned
* multicast group identifier to avoid disturbing
* every interface in the network.
*
* The IANA assigned BACnet/IPv6 variable scope multicast address
* is FF0X:0:0:0:0:0:0:BAC0 (FF0X::BAC0) which indicates the multicast
* group identifier X'BAC0'. The following multicast scopes are
* defined for B/IPv6.
* @{
*/
#define BIP6_MULTICAST_GROUP_ID 0xBAC0
/** @} */
/**
* IANA prefixes
* @{
*/
#define BIP6_MULTICAST_reserved_0 0xFF00
#define BIP6_MULTICAST_NODE_LOCAL 0xFF01
#define BIP6_MULTICAST_LINK_LOCAL 0xFF02
#define BIP6_MULTICAST_reserved_3 0xFF03
#define BIP6_MULTICAST_ADMIN_LOCAL 0xFF04
#define BIP6_MULTICAST_SITE_LOCAL 0xFF05
#define BIP6_MULTICAST_ORG_LOCAL 0xFF08
#define BIP6_MULTICAST_GLOBAL 0xFF0E
/** @} */
/* number of bytes in the IPv6 address */
#define IP6_ADDRESS_MAX 16
/* number of bytes in the B/IPv6 address */
#define BIP6_ADDRESS_MAX 18
/**
* BACnet IPv6 Address
*
* Data link layer addressing between B/IPv6 nodes consists of a 128-bit
* IPv6 address followed by a two-octet UDP port number (both of which
* shall be transmitted with the most significant octet first).
* This address shall be referred to as a B/IPv6 address.
* @{
*/
typedef struct BACnet_IP6_Address {
uint8_t address[IP6_ADDRESS_MAX];
uint16_t port;
} BACNET_IP6_ADDRESS;
/** @} */
/**
* BACnet /IPv6 Broadcast Distribution Table Format
*
* The BDT shall consist of either the eighteen-octet B/IPv6 address
* of the peer BBMD or the combination of the fully qualified
* domain name service (DNS) entry and UDP port that resolves to
* the B/IPv6 address of the peer BBMD. The Broadcast
* Distribution Table shall not contain an entry for the BBMD in
* which the BDT resides.
* @{
*/
struct BACnet_IP6_Broadcast_Distribution_Table_Entry;
typedef struct BACnet_IP6_Broadcast_Distribution_Table_Entry {
/* true if valid entry - false if not */
bool valid;
/* BACnet/IPv6 address */
BACNET_IP6_ADDRESS bip6_address;
struct BACnet_IP6_Broadcast_Distribution_Table_Entry *next;
} BACNET_IP6_BROADCAST_DISTRIBUTION_TABLE_ENTRY;
/** @} */
/**
* Foreign Device Table (FDT)
*
* Each entry shall contain the B/IPv6 address and the TTL of the
* registered foreign device.
*
* Each entry shall consist of the eighteen-octet B/IPv6 address of the
* registrant; the 2-octet Time-to-Live value supplied at the time of
* registration; and a 2-octet value representing the number of seconds
* remaining before the BBMD will purge the registrant's FDT entry if no
* re-registration occurs. The number of seconds remaining shall be
* initialized to the 2-octet Time-to-Live value supplied at the time
* of registration plus 30 seconds (see U.4.5.2), with a maximum of 65535.
* @{
*/
struct BACnet_IP6_Foreign_Device_Table_Entry;
typedef struct BACnet_IP6_Foreign_Device_Table_Entry {
/* true if valid entry - false if not */
bool valid;
/* BACnet/IPv6 address */
BACNET_IP6_ADDRESS bip6_address;
/* requested time-to-live value */
uint16_t ttl_seconds;
/* number of seconds remaining */
uint16_t ttl_seconds_remaining;
struct BACnet_IP6_Foreign_Device_Table_Entry *next;
} BACNET_IP6_FOREIGN_DEVICE_TABLE_ENTRY;
/** @} */
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
int bvlc6_encode_address(
uint8_t * pdu,
uint16_t pdu_size,
BACNET_IP6_ADDRESS * ip6_address);
int bvlc6_decode_address(
uint8_t * pdu,
uint16_t pdu_len,
BACNET_IP6_ADDRESS * ip6_address);
bool bvlc6_address_copy(
BACNET_IP6_ADDRESS * dst,
BACNET_IP6_ADDRESS * src);
bool bvlc6_address_different(
BACNET_IP6_ADDRESS * dst,
BACNET_IP6_ADDRESS * src);
bool bvlc6_address_set(
BACNET_IP6_ADDRESS * addr,
uint16_t addr0,
uint16_t addr1,
uint16_t addr2,
uint16_t addr3,
uint16_t addr4,
uint16_t addr5,
uint16_t addr6,
uint16_t addr7);
bool bvlc6_address_get(
BACNET_IP6_ADDRESS * addr,
uint16_t *addr0,
uint16_t *addr1,
uint16_t *addr2,
uint16_t *addr3,
uint16_t *addr4,
uint16_t *addr5,
uint16_t *addr6,
uint16_t *addr7);
bool bvlc6_vmac_address_set(
BACNET_ADDRESS * addr,
uint32_t device_id);
bool bvlc6_vmac_address_get(
BACNET_ADDRESS * addr,
uint32_t *device_id);
int bvlc6_encode_header(
uint8_t * pdu,
uint16_t pdu_size,
uint8_t message_type,
uint16_t length);
int bvlc6_decode_header(
uint8_t * pdu,
uint16_t pdu_len,
uint8_t * message_type,
uint16_t * length);
int bvlc6_encode_result(
uint8_t * pdu,
uint16_t pdu_size,
uint32_t vmac,
uint16_t result_code);
int bvlc6_decode_result(
uint8_t * pdu,
uint16_t pdu_len,
uint32_t * vmac,
uint16_t * result_code);
int bvlc6_encode_original_unicast(
uint8_t * pdu,
uint16_t pdu_size,
uint32_t vmac_src,
uint32_t vmac_dst,
uint8_t * npdu,
uint16_t npdu_len);
int bvlc6_decode_original_unicast(
uint8_t * pdu,
uint16_t pdu_len,
uint32_t * vmac_src,
uint32_t * vmac_dst,
uint8_t * npdu,
uint16_t npdu_size,
uint16_t * npdu_len);
int bvlc6_encode_original_broadcast(
uint8_t * pdu,
uint16_t pdu_size,
uint32_t vmac,
uint8_t * npdu,
uint16_t npdu_len);
int bvlc6_decode_original_broadcast(
uint8_t * pdu,
uint16_t pdu_len,
uint32_t * vmac,
uint8_t * npdu,
uint16_t npdu_size,
uint16_t * npdu_len);
int bvlc6_encode_address_resolution(
uint8_t * pdu,
uint16_t pdu_size,
uint32_t vmac_src,
uint32_t vmac_target);
int bvlc6_decode_address_resolution(
uint8_t * pdu,
uint16_t pdu_len,
uint32_t * vmac_src,
uint32_t * vmac_target);
int bvlc6_encode_forwarded_address_resolution(
uint8_t * pdu,
uint16_t pdu_size,
uint32_t vmac_src,
uint32_t vmac_target,
BACNET_IP6_ADDRESS * bip6_address);
int bvlc6_decode_forwarded_address_resolution(
uint8_t * pdu,
uint16_t pdu_len,
uint32_t * vmac_src,
uint32_t * vmac_target,
BACNET_IP6_ADDRESS * bip6_address);
int bvlc6_encode_address_resolution_ack(
uint8_t * pdu,
uint16_t pdu_size,
uint32_t vmac_src,
uint32_t vmac_dst);
int bvlc6_decode_address_resolution_ack(
uint8_t * pdu,
uint16_t pdu_len,
uint32_t * vmac_src,
uint32_t * vmac_dst);
int bvlc6_encode_virtual_address_resolution(
uint8_t * pdu,
uint16_t pdu_size,
uint32_t vmac_src);
int bvlc6_decode_virtual_address_resolution(
uint8_t * pdu,
uint16_t pdu_len,
uint32_t * vmac_src);
int bvlc6_encode_virtual_address_resolution_ack(
uint8_t * pdu,
uint16_t pdu_size,
uint32_t vmac_src,
uint32_t vmac_dst);
int bvlc6_decode_virtual_address_resolution_ack(
uint8_t * pdu,
uint16_t pdu_len,
uint32_t * vmac_src,
uint32_t * vmac_dst);
int bvlc6_encode_forwarded_npdu(
uint8_t * pdu,
uint16_t pdu_size,
uint32_t vmac_src,
BACNET_IP6_ADDRESS * address,
uint8_t * npdu,
uint16_t npdu_len);
int bvlc6_decode_forwarded_npdu(
uint8_t * pdu,
uint16_t pdu_len,
uint32_t * vmac_src,
BACNET_IP6_ADDRESS * address,
uint8_t * npdu,
uint16_t npdu_size,
uint16_t * npdu_len);
int bvlc6_encode_register_foreign_device(
uint8_t * pdu,
uint16_t pdu_size,
uint32_t vmac_src,
uint16_t ttl_seconds);
int bvlc6_decode_register_foreign_device(
uint8_t * pdu,
uint16_t pdu_len,
uint32_t * vmac_src,
uint16_t * ttl_seconds);
int bvlc6_encode_delete_foreign_device(
uint8_t * pdu,
uint16_t pdu_size,
uint32_t vmac_src,
BACNET_IP6_FOREIGN_DEVICE_TABLE_ENTRY * fdt_entry);
int bvlc6_decode_delete_foreign_device(
uint8_t * pdu,
uint16_t pdu_len,
uint32_t * vmac_src,
BACNET_IP6_FOREIGN_DEVICE_TABLE_ENTRY * fdt_entry);
int bvlc6_encode_secure_bvll(
uint8_t * pdu,
uint16_t pdu_size,
uint8_t * sbuf,
uint16_t sbuf_len);
int bvlc6_decode_secure_bvll(
uint8_t * pdu,
uint16_t pdu_len,
uint8_t * sbuf,
uint16_t sbuf_size,
uint16_t * sbuf_len);
int bvlc6_encode_distribute_broadcast_to_network(
uint8_t * pdu,
uint16_t pdu_size,
uint32_t vmac,
uint8_t * npdu,
uint16_t npdu_len);
int bvlc6_decode_distribute_broadcast_to_network(
uint8_t * pdu,
uint16_t pdu_len,
uint32_t * vmac,
uint8_t * npdu,
uint16_t npdu_size,
uint16_t * npdu_len);
/* user application function prototypes */
int bvlc6_handler(
BACNET_IP6_ADDRESS *addr,
BACNET_ADDRESS * src,
uint8_t * npdu,
uint16_t npdu_len);
int bvlc6_register_with_bbmd(
BACNET_IP6_ADDRESS *bbmd_addr,
uint32_t vmac_src,
uint16_t time_to_live_seconds);
uint16_t bvlc6_get_last_result(
void);
uint8_t bvlc6_get_function_code(
void);
void bvlc6_init(void);
#ifdef TEST
#include "ctest.h"
void test_BVLC6(
Test * pTest);
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* */
+92
View File
@@ -0,0 +1,92 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef BYTES_H
#define BYTES_H
/* Defines the bit/byte/word/long conversions that are used in code */
#include <stdint.h>
#ifndef LO_NIB
#define LO_NIB(b) ((b) & 0xF)
#endif
#ifndef HI_NIB
#define HI_NIB(b) ((b) >> 4)
#endif
#ifndef LO_BYTE
#define LO_BYTE(w) ((uint8_t)(w))
#endif
#ifndef HI_BYTE
#define HI_BYTE(w) ((uint8_t)((uint16_t)(w) >> 8))
#endif
#ifndef LO_WORD
#define LO_WORD(x) ((uint16_t)(x))
#endif
#ifndef HI_WORD
#define HI_WORD(x) ((uint16_t)((uint32_t)(x) >> 16))
#endif
#ifndef MAKE_WORD
#define MAKE_WORD(lo,hi) \
((uint16_t)(((uint8_t)(lo))|(((uint16_t)((uint8_t)(hi)))<<8)))
#endif
#ifndef MAKE_LONG
#define MAKE_LONG(lo,hi) \
((uint32_t)(((uint16_t)(lo))|(((uint32_t)((uint16_t)(hi)))<<16)))
#endif
#endif /* end of header file */
+307
View File
@@ -0,0 +1,307 @@
/**************************************************************************
*
* 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.
*
*********************************************************************/
#ifndef CLIENT_H
#define CLIENT_H
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include "bacdef.h"
#include "apdu.h"
#include "npdu.h"
#include "bacapp.h"
#include "bacenum.h"
#include "rpm.h"
#include "wpm.h"
#include "cov.h"
#include "event.h"
#include "lso.h"
#include "alarm_ack.h"
#include "ptransfer.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* unconfirmed requests */
void Send_I_Am(
uint8_t * buffer);
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 iam_encode_pdu(
uint8_t * buffer,
BACNET_ADDRESS * dest,
BACNET_NPDU_DATA * npdu_data);
void Send_I_Am_Unicast(
uint8_t * buffer,
BACNET_ADDRESS * src);
int iam_unicast_encode_pdu(
uint8_t * buffer,
BACNET_ADDRESS * src,
BACNET_ADDRESS * dest,
BACNET_NPDU_DATA * npdu_data);
void Send_WhoIs(
int32_t low_limit,
int32_t high_limit);
void Send_WhoIs_Global(
int32_t low_limit,
int32_t high_limit);
void Send_WhoIs_Local(
int32_t low_limit,
int32_t high_limit);
void Send_WhoIs_Remote(
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);
void Send_WhoHas_Object(
int32_t low_limit,
int32_t high_limit,
BACNET_OBJECT_TYPE object_type,
uint32_t object_instance);
void Send_WhoHas_Name(
int32_t low_limit,
int32_t high_limit,
const char *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 Send_UCOV_Notify(
uint8_t * buffer,
unsigned buffer_len,
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);
uint8_t Send_COV_Subscribe(
uint32_t device_id,
BACNET_SUBSCRIBE_COV_DATA * cov_data);
/* returns the invoke ID for confirmed request, or 0 if failed */
uint8_t Send_GetEvent(
BACNET_ADDRESS * target_address,
BACNET_OBJECT_ID *lastReceivedObjectIdentifier);
uint8_t Send_GetEvent_Global(void);
/* returns the invoke ID for confirmed request, or 0 if failed */
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(
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_Multiple_Request(
uint8_t * pdu,
size_t max_pdu,
uint32_t device_id, /* destination device */
BACNET_READ_ACCESS_DATA * read_access_data);
/* returns the invoke ID for confirmed request, or 0 if failed */
uint8_t Send_Write_Property_Request(
uint32_t device_id, /* destination device */
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_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_Multiple_Request(
uint8_t * pdu,
size_t max_pdu,
uint32_t device_id,
BACNET_WRITE_ACCESS_DATA * write_access_data);
/* returns the invoke ID for confirmed request, or 0 if failed */
uint8_t Send_Reinitialize_Device_Request(
uint32_t device_id,
BACNET_REINITIALIZED_STATE state,
char *password);
/* returns the invoke ID for confirmed request, or 0 if failed */
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 */
void Send_TimeSync(
BACNET_DATE * bdate,
BACNET_TIME * btime);
void Send_TimeSync_Remote(
BACNET_ADDRESS * dest,
BACNET_DATE * bdate,
BACNET_TIME * btime);
void Send_TimeSyncUTC(
BACNET_DATE * bdate,
BACNET_TIME * btime);
void Send_TimeSyncUTC_Remote(
BACNET_ADDRESS * dest,
BACNET_DATE * bdate,
BACNET_TIME * btime);
void Send_TimeSyncUTC_Device(void);
void Send_TimeSync_Device(void);
uint8_t Send_Atomic_Read_File_Stream(
uint32_t device_id,
uint32_t file_instance,
int fileStartPosition,
unsigned requestedOctetCount);
uint8_t Send_Atomic_Write_File_Stream(
uint32_t device_id,
uint32_t file_instance,
int fileStartPosition,
BACNET_OCTET_STRING * fileData);
int Send_UEvent_Notify(
uint8_t * buffer,
BACNET_EVENT_NOTIFICATION_DATA * data,
BACNET_ADDRESS * dest);
uint8_t Send_CEvent_Notify(
uint32_t device_id,
BACNET_EVENT_NOTIFICATION_DATA * data);
int Send_Network_Layer_Message(
BACNET_NETWORK_MESSAGE_TYPE network_message_type,
BACNET_ADDRESS * dst,
int *iArgs);
void Send_Who_Is_Router_To_Network(
BACNET_ADDRESS * dst,
int dnet);
void Send_I_Am_Router_To_Network(
const int DNET_list[]);
void Send_Reject_Message_To_Network(
BACNET_ADDRESS * dst,
uint8_t reject_reason,
int dnet);
void Send_Initialize_Routing_Table(
BACNET_ADDRESS * dst,
const int DNET_list[]);
void Send_Initialize_Routing_Table_Ack(
BACNET_ADDRESS * dst,
const int DNET_list[]);
uint8_t Send_Life_Safety_Operation_Data(
uint32_t device_id,
BACNET_LSO_DATA * data);
uint8_t Send_Alarm_Acknowledgement(
uint32_t device_id,
BACNET_ALARM_ACK_DATA * data);
int Send_UnconfirmedPrivateTransfer(
BACNET_ADDRESS * dest,
BACNET_PRIVATE_TRANSFER_DATA * private_data);
uint8_t Send_Get_Alarm_Summary_Address(
BACNET_ADDRESS *dest,
uint16_t max_apdu);
uint8_t Send_Get_Alarm_Summary(
uint32_t device_id);
uint8_t Send_Get_Event_Information_Address(
BACNET_ADDRESS *dest,
uint16_t max_apdu,
BACNET_OBJECT_ID * lastReceivedObjectIdentifier);
uint8_t Send_Get_Event_Information(
uint32_t device_id,
BACNET_OBJECT_ID * lastReceivedObjectIdentifier);
int Send_Abort_To_Network(
uint8_t * buffer,
BACNET_ADDRESS *dest,
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 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 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);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+284
View File
@@ -0,0 +1,284 @@
/**************************************************************************
*
* Copyright (C) 2004 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.
*
*********************************************************************/
#ifndef CONFIG_H
#define CONFIG_H
/* Note: these defines can be defined in your makefile or project
or here or not defined and defaults will be used */
/* declare a single physical layer using your compiler define.
see datalink.h for possible defines. */
#if !(defined(BACDL_ETHERNET) || defined(BACDL_ARCNET) || \
defined(BACDL_MSTP) || defined(BACDL_BIP) || defined(BACDL_BIP6) || \
defined(BACDL_TEST) || defined(BACDL_ALL) || defined(BACDL_NONE))
#define BACDL_BIP
#endif
/* optional configuration for BACnet/IP datalink layer */
#if (defined(BACDL_BIP) || defined(BACDL_ALL))
/* other BIP defines (define as 1 to enable):
USE_INADDR - uses INADDR_BROADCAST for broadcast and binds using INADDR_ANY
USE_CLASSADDR = uses IN_CLASSx_HOST where x=A,B,C or D for broadcast
*/
#if !defined(BBMD_ENABLED)
#define BBMD_ENABLED 1
#endif
#endif
/* optional configuration for BACnet/IPv6 datalink layer */
#if defined(BACDL_BIP6)
#if !defined(BBMD6_ENABLED)
#define BBMD6_ENABLED 0
#endif
#endif
/* Enable the Gateway (Routing) functionality here, if desired. */
#if !defined(MAX_NUM_DEVICES)
#ifdef BAC_ROUTING
#define MAX_NUM_DEVICES 3 /* Eg, Gateway + two remote devices */
#else
#define MAX_NUM_DEVICES 1 /* Just the one normal BACnet Device Object */
#endif
#endif
/* Define your processor architecture as
Big Endian (PowerPC,68K,Sparc) or Little Endian (Intel,AVR)
ARM and MIPS can be either - what is your setup? */
#if !defined(BIG_ENDIAN)
#define BIG_ENDIAN 0
#endif
/* Define your Vendor Identifier assigned by ASHRAE */
#if !defined(BACNET_VENDOR_ID)
#define BACNET_VENDOR_ID 260
#endif
#if !defined(BACNET_VENDOR_NAME)
#define BACNET_VENDOR_NAME "BACnet Stack at SourceForge"
#endif
/* Max number of bytes in an APDU. */
/* Typical sizes are 50, 128, 206, 480, 1024, and 1476 octets */
/* This is used in constructing messages and to tell others our limits */
/* 50 is the minimum; adjust to your memory and physical layer constraints */
/* Lon=206, MS/TP=480, ARCNET=480, Ethernet=1476, BACnet/IP=1476 */
#if !defined(MAX_APDU)
/* #define MAX_APDU 50 */
/* #define MAX_APDU 1476 */
#if defined(BACDL_BIP)
#define MAX_APDU 1476
/* #define MAX_APDU 128 enable this IP for testing
readrange so you get the More Follows flag set */
#elif defined(BACDL_BIP6)
#define MAX_APDU 1476
#elif defined (BACDL_ETHERNET)
#if defined(BACNET_SECURITY)
#define MAX_APDU 1420
#else
#define MAX_APDU 1476
#endif
#else
#if defined(BACNET_SECURITY)
#define MAX_APDU 412
#else
#define MAX_APDU 480
#endif
#endif
#endif
/* for confirmed messages, this is the number of transactions */
/* that we hold in a queue waiting for timeout. */
/* Configure to zero if you don't want any confirmed messages */
/* Configure from 1..255 for number of outstanding confirmed */
/* requests available. */
#if !defined(MAX_TSM_TRANSACTIONS)
#define MAX_TSM_TRANSACTIONS 255
#endif
/* The address cache is used for binding to BACnet devices */
/* The number of entries corresponds to the number of */
/* devices that might respond to an I-Am on the network. */
/* If your device is a simple server and does not need to bind, */
/* then you don't need to use this. */
#if !defined(MAX_ADDRESS_CACHE)
#define MAX_ADDRESS_CACHE 255
#endif
/* some modules have debugging enabled using PRINT_ENABLED */
#if !defined(PRINT_ENABLED)
#define PRINT_ENABLED 0
#endif
/* BACAPP decodes WriteProperty service requests
Choose the datatypes that your application supports */
#if !(defined(BACAPP_ALL) || \
defined(BACAPP_MINIMAL) || \
defined(BACAPP_NULL) || \
defined(BACAPP_BOOLEAN) || \
defined(BACAPP_UNSIGNED) || \
defined(BACAPP_SIGNED) || \
defined(BACAPP_REAL) || \
defined(BACAPP_DOUBLE) || \
defined(BACAPP_OCTET_STRING) || \
defined(BACAPP_CHARACTER_STRING) || \
defined(BACAPP_BIT_STRING) || \
defined(BACAPP_ENUMERATED) || \
defined(BACAPP_DATE) || \
defined(BACAPP_TIME) || \
defined(BACAPP_LIGHTING_COMMAND) || \
defined(BACAPP_DEVICE_OBJECT_PROP_REF) || \
defined(BACAPP_OBJECT_ID))
#define BACAPP_ALL
#endif
#if defined (BACAPP_ALL)
#define BACAPP_NULL
#define BACAPP_BOOLEAN
#define BACAPP_UNSIGNED
#define BACAPP_SIGNED
#define BACAPP_REAL
#define BACAPP_DOUBLE
#define BACAPP_OCTET_STRING
#define BACAPP_CHARACTER_STRING
#define BACAPP_BIT_STRING
#define BACAPP_ENUMERATED
#define BACAPP_DATE
#define BACAPP_TIME
#define BACAPP_OBJECT_ID
#define BACAPP_DEVICE_OBJECT_PROP_REF
#define BACAPP_LIGHTING_COMMAND
#elif defined (BACAPP_MINIMAL)
#define BACAPP_NULL
#define BACAPP_BOOLEAN
#define BACAPP_UNSIGNED
#define BACAPP_SIGNED
#define BACAPP_REAL
#define BACAPP_CHARACTER_STRING
#define BACAPP_ENUMERATED
#define BACAPP_DATE
#define BACAPP_TIME
#define BACAPP_OBJECT_ID
#endif
/*
** Set the maximum vector type sizes
*/
#ifndef MAX_BITSTRING_BYTES
#define MAX_BITSTRING_BYTES (15)
#endif
#ifndef MAX_CHARACTER_STRING_BYTES
#define MAX_CHARACTER_STRING_BYTES (MAX_APDU-6)
#endif
#ifndef MAX_OCTET_STRING_BYTES
#define MAX_OCTET_STRING_BYTES (MAX_APDU-6)
#endif
/*
** Control the selection of services etc to enable code size reduction for those
** compiler suites which do not handle removing of unused functions in modules
** so well.
**
** We will start with the A type services code first as these are least likely
** to be required in embedded systems using the stack.
*/
/*
** First we see if this is a test build and enable all the services as they
** may be required.
**
** Note: I've left everything enabled here in the main config.h. You should
** use a local copy of config.h with settings configured for your needs to
** make use of the code space reductions.
**/
#ifdef TEST
#define BACNET_SVC_I_HAVE_A 1
#define BACNET_SVC_WP_A 1
#define BACNET_SVC_RP_A 1
#define BACNET_SVC_RPM_A 1
#define BACNET_SVC_DCC_A 1
#define BACNET_SVC_RD_A 1
#define BACNET_SVC_TS_A 1
#define BACNET_SVC_SERVER 0
#define BACNET_USE_OCTETSTRING 1
#define BACNET_USE_DOUBLE 1
#define BACNET_USE_SIGNED 1
#else /* Otherwise define our working set - all enabled here to avoid breaking things */
#define BACNET_SVC_I_HAVE_A 1
#define BACNET_SVC_WP_A 1
#define BACNET_SVC_RP_A 1
#define BACNET_SVC_RPM_A 1
#define BACNET_SVC_DCC_A 1
#define BACNET_SVC_RD_A 1
#define BACNET_SVC_TS_A 1
#define BACNET_SVC_SERVER 0
#define BACNET_USE_OCTETSTRING 1
#define BACNET_USE_DOUBLE 1
#define BACNET_USE_SIGNED 1
#endif
/* Do them one by one */
#ifndef BACNET_SVC_I_HAVE_A /* Do we send I_Have requests? */
#define BACNET_SVC_I_HAVE_A 0
#endif
#ifndef BACNET_SVC_WP_A /* Do we send WriteProperty requests? */
#define BACNET_SVC_WP_A 0
#endif
#ifndef BACNET_SVC_RP_A /* Do we send ReadProperty requests? */
#define BACNET_SVC_RP_A 0
#endif
#ifndef BACNET_SVC_RPM_A /* Do we send ReadPropertyMultiple requests? */
#define BACNET_SVC_RPM_A 0
#endif
#ifndef BACNET_SVC_DCC_A /* Do we send DeviceCommunicationControl requests? */
#define BACNET_SVC_DCC_A 0
#endif
#ifndef BACNET_SVC_RD_A /* Do we send ReinitialiseDevice requests? */
#define BACNET_SVC_RD_A 0
#endif
#ifndef BACNET_SVC_SERVER /* Are we a pure server type device? */
#define BACNET_SVC_SERVER 1
#endif
#ifndef BACNET_USE_OCTETSTRING /* Do we need any octet strings? */
#define BACNET_USE_OCTETSTRING 0
#endif
#ifndef BACNET_USE_DOUBLE /* Do we need any doubles? */
#define BACNET_USE_DOUBLE 0
#endif
#ifndef BACNET_USE_SIGNED /* Do we need any signed integers */
#define BACNET_USE_SIGNED 0
#endif
#endif
+145
View File
@@ -0,0 +1,145 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef COV_H
#define COV_H
#include <stdint.h>
#include <stdbool.h>
#include "bacapp.h"
typedef struct BACnet_COV_Data {
uint32_t subscriberProcessIdentifier;
uint32_t initiatingDeviceIdentifier;
BACNET_OBJECT_ID monitoredObjectIdentifier;
uint32_t timeRemaining; /* seconds */
/* simple linked list of values */
BACNET_PROPERTY_VALUE *listOfValues;
} BACNET_COV_DATA;
struct BACnet_Subscribe_COV_Data;
typedef struct BACnet_Subscribe_COV_Data {
uint32_t subscriberProcessIdentifier;
BACNET_OBJECT_ID monitoredObjectIdentifier;
bool cancellationRequest; /* true if this is a cancellation request */
bool issueConfirmedNotifications; /* optional */
uint32_t lifetime; /* seconds, optional */
BACNET_PROPERTY_REFERENCE monitoredProperty;
bool covIncrementPresent; /* true if present */
float covIncrement; /* optional */
BACNET_ERROR_CLASS error_class;
BACNET_ERROR_CODE error_code;
struct BACnet_Subscribe_COV_Data *next;
} BACNET_SUBSCRIBE_COV_DATA;
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
int ucov_notify_encode_apdu(
uint8_t * apdu,
unsigned max_apdu_len,
BACNET_COV_DATA * data);
int ucov_notify_decode_apdu(
uint8_t * apdu,
unsigned apdu_len,
BACNET_COV_DATA * data);
int ucov_notify_send(
uint8_t * apdu,
unsigned max_apdu_len,
BACNET_COV_DATA * data);
int ccov_notify_encode_apdu(
uint8_t * apdu,
unsigned max_apdu_len,
uint8_t invoke_id,
BACNET_COV_DATA * data);
int ccov_notify_decode_apdu(
uint8_t * apdu,
unsigned apdu_len,
uint8_t * invoke_id,
BACNET_COV_DATA * data);
/* common for both confirmed and unconfirmed */
int cov_notify_decode_service_request(
uint8_t * apdu,
unsigned apdu_len,
BACNET_COV_DATA * data);
int cov_subscribe_property_decode_service_request(
uint8_t * apdu,
unsigned apdu_len,
BACNET_SUBSCRIBE_COV_DATA * data);
int cov_subscribe_property_encode_apdu(
uint8_t * apdu,
unsigned max_apdu_len,
uint8_t invoke_id,
BACNET_SUBSCRIBE_COV_DATA * data);
int cov_subscribe_decode_service_request(
uint8_t * apdu,
unsigned apdu_len,
BACNET_SUBSCRIBE_COV_DATA * data);
int cov_subscribe_encode_apdu(
uint8_t * apdu,
unsigned max_apdu_len,
uint8_t invoke_id,
BACNET_SUBSCRIBE_COV_DATA * data);
void cov_data_value_list_link(
BACNET_COV_DATA *data,
BACNET_PROPERTY_VALUE *value_list,
size_t count);
#ifdef TEST
#include "ctest.h"
void testCOVNotify(
Test * pTest);
void testCOVSubscribeProperty(
Test * pTest);
void testCOVSubscribe(
Test * pTest);
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
/** @defgroup DSCOV Data Sharing - Change of Value Service (DS-COV)
* @ingroup DataShare
* 13.1 Change of Value Reporting <br>
* Change of value (COV) reporting allows a COV-client to subscribe with a
* COV-server, on a permanent or temporary basis, to receive reports of some
* changes of value of some referenced property based on fixed criteria.
* If an object provides COV reporting, then changes of value of any
* subscribed-to properties of the object, in some cases based on programmable
* increments, trigger COV notifications to be sent to subscribing clients.
* Typically, COV notifications are sent to supervisory programs in COV-client
* devices or to operators or logging devices. Any object, proprietary or
* standard, may support COV reporting at the implementor's option.
*/
#endif
+44
View File
@@ -0,0 +1,44 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef CRC_H
#define CRC_H
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
uint8_t CRC_Calc_Header(
uint8_t dataValue,
uint8_t crcValue);
uint16_t CRC_Calc_Data(
uint8_t dataValue,
uint16_t crcValue);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
@@ -0,0 +1,63 @@
/**************************************************************************
*
* Copyright (C) 2015 Nikola Jelic <nikola.jelic@euroicc.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.
*
*********************************************************************/
#ifndef BACNET_CREDENTIAL_AUTHENTICATION_FACTOR_H
#define BACNET_CREDENTIAL_AUTHENTICATION_FACTOR_H
#include <stdbool.h>
#include <stdint.h>
#include "bacdef.h"
#include "bacapp.h"
#include "authentication_factor.h"
typedef struct {
BACNET_ACCESS_AUTHENTICATION_FACTOR_DISABLE disable;
BACNET_AUTHENTICATION_FACTOR authentication_factor;
} BACNET_CREDENTIAL_AUTHENTICATION_FACTOR;
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
int bacapp_encode_credential_authentication_factor(
uint8_t * apdu,
BACNET_CREDENTIAL_AUTHENTICATION_FACTOR * caf);
int bacapp_encode_context_credential_authentication_factor(
uint8_t * apdu,
uint8_t tag,
BACNET_CREDENTIAL_AUTHENTICATION_FACTOR * caf);
int bacapp_decode_credential_authentication_factor(
uint8_t * apdu,
BACNET_CREDENTIAL_AUTHENTICATION_FACTOR * caf);
int bacapp_decode_context_credential_authentication_factor(
uint8_t * apdu,
uint8_t tag,
BACNET_CREDENTIAL_AUTHENTICATION_FACTOR * caf);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+154
View File
@@ -0,0 +1,154 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef DATALINK_H
#define DATALINK_H
#include "config.h"
#include "bacdef.h"
#if defined(BACDL_ETHERNET)
#include "ethernet.h"
#define datalink_init ethernet_init
#define datalink_send_pdu ethernet_send_pdu
#define datalink_receive ethernet_receive
#define datalink_cleanup ethernet_cleanup
#define datalink_get_broadcast_address ethernet_get_broadcast_address
#define datalink_get_my_address ethernet_get_my_address
#elif defined(BACDL_ARCNET)
#include "arcnet.h"
#define datalink_init arcnet_init
#define datalink_send_pdu arcnet_send_pdu
#define datalink_receive arcnet_receive
#define datalink_cleanup arcnet_cleanup
#define datalink_get_broadcast_address arcnet_get_broadcast_address
#define datalink_get_my_address arcnet_get_my_address
#elif defined(BACDL_MSTP)
#include "dlmstp.h"
#define datalink_init dlmstp_init
#define datalink_send_pdu dlmstp_send_pdu
#define datalink_receive dlmstp_receive
#define datalink_cleanup dlmstp_cleanup
#define datalink_get_broadcast_address dlmstp_get_broadcast_address
#define datalink_get_my_address dlmstp_get_my_address
#elif defined(BACDL_BIP)
#include "bip.h"
#include "bvlc.h"
#define datalink_init bip_init
#if defined(BBMD_ENABLED) && BBMD_ENABLED
#define datalink_send_pdu bvlc_send_pdu
#define datalink_receive bvlc_receive
#else
#define datalink_send_pdu bip_send_pdu
#define datalink_receive bip_receive
#endif
#define datalink_cleanup bip_cleanup
#define datalink_get_broadcast_address bip_get_broadcast_address
#ifdef BAC_ROUTING
extern void routed_get_my_address(
BACNET_ADDRESS * my_address);
#define datalink_get_my_address routed_get_my_address
#else
#define datalink_get_my_address bip_get_my_address
#endif
#elif defined(BACDL_BIP6)
#include "bip6.h"
#include "bvlc6.h"
#define datalink_init bip6_init
#define datalink_send_pdu bip6_send_pdu
#define datalink_receive bip6_receive
#define datalink_cleanup bip6_cleanup
#define datalink_get_broadcast_address bip6_get_broadcast_address
#define datalink_get_my_address bip6_get_my_address
#elif defined(BACDL_ALL) || defined(BACDL_NONE)
#include "npdu.h"
#define MAX_HEADER (8)
#define MAX_MPDU (MAX_HEADER+MAX_PDU)
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
int datalink_send_pdu(
BACNET_ADDRESS * dest,
BACNET_NPDU_DATA * npdu_data,
uint8_t * pdu,
unsigned pdu_len);
extern uint16_t datalink_receive(
BACNET_ADDRESS * src,
uint8_t * pdu,
uint16_t max_pdu,
unsigned timeout);
extern void datalink_cleanup(
void);
extern void datalink_get_broadcast_address(
BACNET_ADDRESS * dest);
extern void datalink_get_my_address(
BACNET_ADDRESS * my_address);
extern void datalink_set_interface(
char *ifname);
extern void datalink_set(
char *datalink_string);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
/** @defgroup DataLink The BACnet Network (DataLink) Layer
* <b>6 THE NETWORK LAYER </b><br>
* The purpose of the BACnet network layer is to provide the means by which
* messages can be relayed from one BACnet network to another, regardless of
* the BACnet data link technology in use on that network. Whereas the data
* link layer provides the capability to address messages to a single device
* or broadcast them to all devices on the local network, the network layer
* allows messages to be directed to a single remote device, broadcast on a
* remote network, or broadcast globally to all devices on all networks.
* A BACnet Device is uniquely located by a network number and a MAC address.
*
* Each client or server application must define exactly one of these
* DataLink settings, which will control which parts of the code will be built:
* - BACDL_ETHERNET -- for Clause 7 ISO 8802-3 ("Ethernet") LAN
* - BACDL_ARCNET -- for Clause 8 ARCNET LAN
* - BACDL_MSTP -- for Clause 9 MASTER-SLAVE/TOKEN PASSING (MS/TP) LAN
* - BACDL_BIP -- for ANNEX J - BACnet/IP
* - BACDL_ALL -- Unspecified for the build, so the transport can be
* chosen at runtime from among these choices.
* - Clause 10 POINT-TO-POINT (PTP) and Clause 11 EIA/CEA-709.1 ("LonTalk") LAN
* are not currently supported by this project.
*//** @defgroup DLTemplates DataLink Template Functions
* @ingroup DataLink
* Most of the functions in this group are function templates which are assigned
* to a specific DataLink network layer implementation either at compile time or
* at runtime.
*/
#endif
+255
View File
@@ -0,0 +1,255 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef DATE_TIME_H
#define DATE_TIME_H
#include <stdint.h>
#include <stdbool.h>
typedef enum BACnet_Weekday {
BACNET_WEEKDAY_MONDAY = 1,
BACNET_WEEKDAY_TUESDAY = 2,
BACNET_WEEKDAY_WEDNESDAY = 3,
BACNET_WEEKDAY_THURSDAY = 4,
BACNET_WEEKDAY_FRIDAY = 5,
BACNET_WEEKDAY_SATURDAY = 6,
BACNET_WEEKDAY_SUNDAY = 7
} BACNET_WEEKDAY;
/* date */
typedef struct BACnet_Date {
uint16_t year; /* AD */
uint8_t month; /* 1=Jan */
uint8_t day; /* 1..31 */
uint8_t wday; /* 1=Monday-7=Sunday */
} BACNET_DATE;
/* time */
typedef struct BACnet_Time {
uint8_t hour;
uint8_t min;
uint8_t sec;
uint8_t hundredths;
} BACNET_TIME;
typedef struct BACnet_DateTime {
BACNET_DATE date;
BACNET_TIME time;
} BACNET_DATE_TIME;
/* range of dates */
typedef struct BACnet_Date_Range {
BACNET_DATE startdate;
BACNET_DATE enddate;
} BACNET_DATE_RANGE;
/* week and days */
typedef struct BACnet_Weeknday {
uint8_t month; /* 1=Jan 13=odd 14=even FF=any */
uint8_t weekofmonth; /* 1=days 1-7, 2=days 8-14, 3=days 15-21, 4=days 22-28, 5=days 29-31, 6=last 7 days, FF=any week */
uint8_t dayofweek; /* 1=Monday-7=Sunday, FF=any */
} BACNET_WEEKNDAY;
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* utility initialization functions */
void datetime_set_date(
BACNET_DATE * bdate,
uint16_t year,
uint8_t month,
uint8_t day);
void datetime_set_time(
BACNET_TIME * btime,
uint8_t hour,
uint8_t minute,
uint8_t seconds,
uint8_t hundredths);
void datetime_set(
BACNET_DATE_TIME * bdatetime,
BACNET_DATE * bdate,
BACNET_TIME * btime);
void datetime_set_values(
BACNET_DATE_TIME * bdatetime,
uint16_t year,
uint8_t month,
uint8_t day,
uint8_t hour,
uint8_t minute,
uint8_t seconds,
uint8_t hundredths);
/* utility test for validity */
bool datetime_is_valid(
BACNET_DATE * bdate,
BACNET_TIME * btime);
bool datetime_time_is_valid(
BACNET_TIME * btime);
bool datetime_date_is_valid(
BACNET_DATE * bdate);
/* date and time calculations and summaries */
uint32_t datetime_days_since_epoch(
BACNET_DATE * bdate);
void datetime_days_since_epoch_into_date(
uint32_t days,
BACNET_DATE * bdate);
uint32_t datetime_day_of_year(
BACNET_DATE *bdate);
void datetime_day_of_year_into_date(
uint32_t days,
uint16_t year,
BACNET_DATE *bdate);
bool datetime_is_leap_year(
uint16_t year);
uint8_t datetime_month_days(
uint16_t year,
uint8_t month);
uint8_t datetime_day_of_week(
uint16_t year,
uint8_t month,
uint8_t day);
bool datetime_ymd_is_valid(
uint16_t year,
uint8_t month,
uint8_t day);
uint32_t datetime_seconds_since_midnight(
BACNET_TIME * btime);
uint16_t datetime_minutes_since_midnight(
BACNET_TIME * btime);
/* utility comparison functions:
if the date/times are the same, return is 0
if date1 is before date2, returns negative
if date1 is after date2, returns positive */
int datetime_compare_date(
BACNET_DATE * date1,
BACNET_DATE * date2);
int datetime_compare_time(
BACNET_TIME * time1,
BACNET_TIME * time2);
int datetime_compare(
BACNET_DATE_TIME * datetime1,
BACNET_DATE_TIME * datetime2);
/* full comparison functions:
* taking into account FF fields in date and time structures,
* do a full comparison of two values */
int datetime_wildcard_compare_date(
BACNET_DATE * date1,
BACNET_DATE * date2);
int datetime_wildcard_compare_time(
BACNET_TIME * time1,
BACNET_TIME * time2);
int datetime_wildcard_compare(
BACNET_DATE_TIME * datetime1,
BACNET_DATE_TIME * datetime2);
/* utility copy functions */
void datetime_copy_date(
BACNET_DATE * dest,
BACNET_DATE * src);
void datetime_copy_time(
BACNET_TIME * dest,
BACNET_TIME * src);
void datetime_copy(
BACNET_DATE_TIME * dest,
BACNET_DATE_TIME * src);
/* utility add or subtract minutes function */
void datetime_add_minutes(
BACNET_DATE_TIME * bdatetime,
int32_t minutes);
/* date and time wildcards */
bool datetime_wildcard_year(
BACNET_DATE *bdate);
void datetime_wildcard_year_set(
BACNET_DATE *bdate);
bool datetime_wildcard_month(
BACNET_DATE *bdate);
void datetime_wildcard_month_set(
BACNET_DATE *bdate);
bool datetime_wildcard_day(
BACNET_DATE *bdate);
void datetime_wildcard_day_set(
BACNET_DATE *bdate);
bool datetime_wildcard_weekday(
BACNET_DATE *bdate);
void datetime_wildcard_weekday_set(
BACNET_DATE *bdate);
bool datetime_wildcard_hour(
BACNET_TIME *btime);
void datetime_wildcard_hour_set(
BACNET_TIME *btime);
bool datetime_wildcard_minute(
BACNET_TIME *btime);
void datetime_wildcard_minute_set(
BACNET_TIME *btime);
bool datetime_wildcard_second(
BACNET_TIME *btime);
void datetime_wildcard_second_set(
BACNET_TIME *btime);
bool datetime_wildcard_hundredths(
BACNET_TIME *btime);
void datetime_wildcard_hundredths_set(
BACNET_TIME *btime);
bool datetime_wildcard(
BACNET_DATE_TIME * bdatetime);
bool datetime_wildcard_present(
BACNET_DATE_TIME * bdatetime);
void datetime_wildcard_set(
BACNET_DATE_TIME * bdatetime);
void datetime_date_wildcard_set(
BACNET_DATE * bdate);
void datetime_time_wildcard_set(
BACNET_TIME * btime);
int bacapp_encode_datetime(
uint8_t * apdu,
BACNET_DATE_TIME * value);
int bacapp_encode_context_datetime(
uint8_t * apdu,
uint8_t tag_number,
BACNET_DATE_TIME * value);
int bacapp_decode_datetime(
uint8_t * apdu,
BACNET_DATE_TIME * value);
int bacapp_decode_context_datetime(
uint8_t * apdu,
uint8_t tag_number,
BACNET_DATE_TIME * value);
#ifdef TEST
#include "ctest.h"
void testDateTime(
Test * pTest);
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* DATE_TIME_H */
+127
View File
@@ -0,0 +1,127 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef DCC_H
#define DCC_H
#include <stdint.h>
#include <stdbool.h>
#include "bacenum.h"
#include "bacstr.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* return the status */
BACNET_COMMUNICATION_ENABLE_DISABLE dcc_enable_status(
void);
bool dcc_communication_enabled(
void);
bool dcc_communication_disabled(
void);
bool dcc_communication_initiation_disabled(
void);
/* return the time */
uint32_t dcc_duration_seconds(
void);
/* called every second or so. If more than one second,
then seconds should be the number of seconds to tick away */
void dcc_timer_seconds(
uint32_t seconds);
/* setup the communication values */
bool dcc_set_status_duration(
BACNET_COMMUNICATION_ENABLE_DISABLE status,
uint16_t minutes);
/* encode service */
int dcc_encode_apdu(
uint8_t * apdu,
uint8_t invoke_id,
uint16_t timeDuration, /* 0=optional */
BACNET_COMMUNICATION_ENABLE_DISABLE enable_disable,
BACNET_CHARACTER_STRING * password); /* NULL=optional */
/* decode the service request only */
int dcc_decode_service_request(
uint8_t * apdu,
unsigned apdu_len,
uint16_t * timeDuration,
BACNET_COMMUNICATION_ENABLE_DISABLE * enable_disable,
BACNET_CHARACTER_STRING * password);
#ifdef TEST
#include "ctest.h"
int dcc_decode_apdu(
uint8_t * apdu,
unsigned apdu_len,
uint8_t * invoke_id,
uint16_t * timeDuration,
BACNET_COMMUNICATION_ENABLE_DISABLE * enable_disable,
BACNET_CHARACTER_STRING * password);
void test_DeviceCommunicationControl(
Test * pTest);
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
/** @defgroup RDMS Device and Network Management Service BIBBs
* These device management BIBBs prescribe the BACnet capabilities required
* to interoperably perform the device management functions enumerated in
* 22.2.1.5 for the BACnet devices defined therein.
*
* The network management BIBBs prescribe the BACnet capabilities required to
* interoperably perform network management functions.
*/
/** @defgroup DMDCC Device Management-Device Communication Control (DM-DCC)
* @ingroup RDMS
* 16.1 DeviceCommunicationControl Service <br>
* The DeviceCommunicationControl service is used by a client BACnet-user to
* instruct a remote device to stop initiating and optionally stop responding
* to all APDUs (except DeviceCommunicationControl or, if supported,
* ReinitializeDevice) on the communication network or internetwork for a
* specified duration of time. This service is primarily used by a human operator
* for diagnostic purposes. A password may be required from the client
* BACnet-user prior to executing the service. The time duration may be set to
* "indefinite," meaning communication must be re-enabled by a
* DeviceCommunicationControl or, if supported, ReinitializeDevice service,
* not by time.
*/
/** @defgroup NMRC Network Management-Router Configuration (NM-RC)
* @ingroup RDMS
* The A device may query and change the configuration of routers and
* half-routers.
* The B device responds to router management commands and must meet the
* requirements for BACnet Routers as stated in Clause 6.
*
* 6.4 Network Layer Protocol Messages <br>
* This subclause describes the format and purpose of the ten BACnet network
* layer protocol messages. These messages provide the basis for router
* auto-configuration, router table maintenance, and network layer congestion
* control.
*/
#endif
+57
View File
@@ -0,0 +1,57 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef DEBUG_H
#define DEBUG_H
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include "bacdef.h"
#ifndef DEBUG_ENABLED
#define DEBUG_ENABLED 0
#endif
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
void debug_printf(
const char *format,
...);
#if DEBUG_ENABLED
/* Nothing more here */
#else
/* If your compiler supports it, this is more compact:
inline void debug_printf(
const char *format,
...) {
format = format;
}
*/
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+52
View File
@@ -0,0 +1,52 @@
/**************************************************************************
*
* 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.
*
*********************************************************************/
#ifndef DLENV_H
#define DLENV_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
void dlenv_init(
void);
int dlenv_register_as_foreign_device(
void);
void dlenv_maintenance_timer(
uint16_t elapsed_seconds);
/* Simple setters and getter. */
void dlenv_bbmd_address_set(
long address);
void dlenv_bbmd_port_set(
int port);
void dlenv_bbmd_ttl_set(
int ttl_secs);
int dlenv_bbmd_result(
void);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+122
View File
@@ -0,0 +1,122 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef DLMSTP_H
#define DLMSTP_H
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
#include "bacdef.h"
#include "npdu.h"
/* defines specific to MS/TP */
/* preamble+type+dest+src+len+crc8+crc16 */
#define MAX_HEADER (2+1+1+1+2+1+2)
#define MAX_MPDU (MAX_HEADER+MAX_PDU)
typedef struct dlmstp_packet {
bool ready; /* true if ready to be sent or received */
BACNET_ADDRESS address; /* source address */
uint8_t frame_type; /* type of message */
uint16_t pdu_len; /* packet length */
uint8_t pdu[MAX_MPDU]; /* packet */
} DLMSTP_PACKET;
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
bool dlmstp_init(
char *ifname);
void dlmstp_reset(
void);
void dlmstp_cleanup(
void);
/* returns number of bytes sent on success, negative on failure */
int dlmstp_send_pdu(
BACNET_ADDRESS * dest, /* destination address */
BACNET_NPDU_DATA * npdu_data, /* network information */
uint8_t * pdu, /* any data to be sent - may be null */
unsigned pdu_len); /* number of bytes of data */
/* returns the number of octets in the PDU, or zero on failure */
uint16_t dlmstp_receive(
BACNET_ADDRESS * src, /* source address */
uint8_t * pdu, /* PDU data */
uint16_t max_pdu, /* amount of space available in the PDU */
unsigned timeout); /* milliseconds to wait for a packet */
/* This parameter represents the value of the Max_Info_Frames property of */
/* the node's Device object. The value of Max_Info_Frames specifies the */
/* maximum number of information frames the node may send before it must */
/* pass the token. Max_Info_Frames may have different values on different */
/* nodes. This may be used to allocate more or less of the available link */
/* bandwidth to particular nodes. If Max_Info_Frames is not writable in a */
/* node, its value shall be 1. */
void dlmstp_set_max_info_frames(
uint8_t max_info_frames);
uint8_t dlmstp_max_info_frames(
void);
/* This parameter represents the value of the Max_Master property of the */
/* node's Device object. The value of Max_Master specifies the highest */
/* allowable address for master nodes. The value of Max_Master shall be */
/* less than or equal to 127. If Max_Master is not writable in a node, */
/* its value shall be 127. */
void dlmstp_set_max_master(
uint8_t max_master);
uint8_t dlmstp_max_master(
void);
/* MAC address 0-127 */
void dlmstp_set_mac_address(
uint8_t my_address);
uint8_t dlmstp_mac_address(
void);
void dlmstp_get_my_address(
BACNET_ADDRESS * my_address);
void dlmstp_get_broadcast_address(
BACNET_ADDRESS * dest); /* destination address */
/* RS485 Baud Rate 9600, 19200, 38400, 57600, 115200 */
void dlmstp_set_baud_rate(
uint32_t baud);
uint32_t dlmstp_baud_rate(
void);
void dlmstp_fill_bacnet_address(
BACNET_ADDRESS * src,
uint8_t mstp_address);
bool dlmstp_sole_master(
void);
bool dlmstp_send_pdu_queue_empty(void);
bool dlmstp_send_pdu_queue_full(void);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+82
View File
@@ -0,0 +1,82 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef ETHERNET_H
#define ETHERNET_H
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
#include "bacdef.h"
#include "npdu.h"
/* specific defines for Ethernet */
#define MAX_HEADER (6+6+2+1+1+1)
#define MAX_MPDU (MAX_HEADER+MAX_PDU)
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
bool ethernet_valid(
void);
void ethernet_cleanup(
void);
bool ethernet_init(
char *interface_name);
/* function to send a packet out the 802.2 socket */
/* returns number of bytes sent on success, negative on failure */
int ethernet_send_pdu(
BACNET_ADDRESS * dest, /* destination address */
BACNET_NPDU_DATA * npdu_data, /* network information */
uint8_t * pdu, /* any data to be sent - may be null */
unsigned pdu_len); /* number of bytes of data */
/* receives an 802.2 framed packet */
/* returns the number of octets in the PDU, or zero on failure */
uint16_t ethernet_receive(
BACNET_ADDRESS * src, /* source address */
uint8_t * pdu, /* PDU data */
uint16_t max_pdu, /* amount of space available in the PDU */
unsigned timeout); /* milliseconds to wait for a packet */
void ethernet_set_my_address(
BACNET_ADDRESS * my_address);
void ethernet_get_my_address(
BACNET_ADDRESS * my_address);
void ethernet_get_broadcast_address(
BACNET_ADDRESS * dest); /* destination address */
/* some functions from Linux driver */
void ethernet_debug_address(
const char *info,
BACNET_ADDRESS * dest);
int ethernet_send(
uint8_t * mtu,
int mtu_len);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+233
View File
@@ -0,0 +1,233 @@
/**************************************************************************
*
* 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.
*********************************************************************/
#ifndef BACNET_EVENT_H_
#define BACNET_EVENT_H_
#include "bacenum.h"
#include <stdint.h>
#include <stdbool.h>
#include "bacapp.h"
#include "timestamp.h"
#include "bacpropstates.h"
#include "bacdevobjpropref.h"
typedef enum {
CHANGE_OF_VALUE_BITS,
CHANGE_OF_VALUE_REAL
} CHANGE_OF_VALUE_TYPE;
/*
** Based on UnconfirmedEventNotification-Request
*/
typedef struct BACnet_Event_Notification_Data {
uint32_t processIdentifier;
BACNET_OBJECT_ID initiatingObjectIdentifier;
BACNET_OBJECT_ID eventObjectIdentifier;
BACNET_TIMESTAMP timeStamp;
uint32_t notificationClass;
uint8_t priority;
BACNET_EVENT_TYPE eventType;
BACNET_CHARACTER_STRING *messageText; /* OPTIONAL - Set to NULL if not being used */
BACNET_NOTIFY_TYPE notifyType;
bool ackRequired;
BACNET_EVENT_STATE fromState;
BACNET_EVENT_STATE toState;
/*
** Each of these structures in the union maps to a particular eventtype
** Based on BACnetNotificationParameters
*/
union {
/*
** EVENT_CHANGE_OF_BITSTRING
*/
struct {
BACNET_BIT_STRING referencedBitString;
BACNET_BIT_STRING statusFlags;
} changeOfBitstring;
/*
** EVENT_CHANGE_OF_STATE
*/
struct {
BACNET_PROPERTY_STATE newState;
BACNET_BIT_STRING statusFlags;
} changeOfState;
/*
** EVENT_CHANGE_OF_VALUE
*/
struct {
union {
BACNET_BIT_STRING changedBits;
float changeValue;
} newValue;
CHANGE_OF_VALUE_TYPE tag;
BACNET_BIT_STRING statusFlags;
} changeOfValue;
/*
** EVENT_COMMAND_FAILURE
**
** Not Supported!
*/
/*
** EVENT_FLOATING_LIMIT
*/
struct {
float referenceValue;
BACNET_BIT_STRING statusFlags;
float setPointValue;
float errorLimit;
} floatingLimit;
/*
** EVENT_OUT_OF_RANGE
*/
struct {
float exceedingValue;
BACNET_BIT_STRING statusFlags;
float deadband;
float exceededLimit;
} outOfRange;
/*
** EVENT_CHANGE_OF_LIFE_SAFETY
*/
struct {
BACNET_LIFE_SAFETY_STATE newState;
BACNET_LIFE_SAFETY_MODE newMode;
BACNET_BIT_STRING statusFlags;
BACNET_LIFE_SAFETY_OPERATION operationExpected;
} changeOfLifeSafety;
/*
** EVENT_EXTENDED
**
** Not Supported!
*/
/*
** EVENT_BUFFER_READY
*/
struct {
BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE bufferProperty;
uint32_t previousNotification;
uint32_t currentNotification;
} bufferReady;
/*
** EVENT_UNSIGNED_RANGE
*/
struct {
uint32_t exceedingValue;
BACNET_BIT_STRING statusFlags;
uint32_t exceededLimit;
} unsignedRange;
} notificationParams;
} BACNET_EVENT_NOTIFICATION_DATA;
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/***************************************************
**
** Creates a Confirmed Event Notification APDU
**
****************************************************/
int cevent_notify_encode_apdu(
uint8_t * apdu,
uint8_t invoke_id,
BACNET_EVENT_NOTIFICATION_DATA * data);
/***************************************************
**
** Creates an Unconfirmed Event Notification APDU
**
****************************************************/
int uevent_notify_encode_apdu(
uint8_t * apdu,
BACNET_EVENT_NOTIFICATION_DATA * data);
/***************************************************
**
** Encodes the service data part of Event Notification
**
****************************************************/
int event_notify_encode_service_request(
uint8_t * apdu,
BACNET_EVENT_NOTIFICATION_DATA * data);
/***************************************************
**
** Decodes the service data part of Event Notification
**
****************************************************/
int event_notify_decode_service_request(
uint8_t * apdu,
unsigned apdu_len,
BACNET_EVENT_NOTIFICATION_DATA * data);
/***************************************************
**
** Sends an Unconfirmed Event Notifcation to a dest
**
****************************************************/
int uevent_notify_send(
uint8_t * buffer,
BACNET_EVENT_NOTIFICATION_DATA * data,
BACNET_ADDRESS * dest);
#ifdef __cplusplus
}
#endif /* __cplusplus */
/** @defgroup ALMEVNT Alarm and Event Management BIBBs
* These BIBBs prescribe the BACnet capabilities required to interoperably
* perform the alarm and event management functions enumerated in 22.2.1.2
* for the BACnet devices defined therein.
*//** @defgroup EVNOTFCN Alarm and Event-Notification (AE-N)
* @ingroup ALMEVNT
* 13.6 ConfirmedCOVNotification Service <br>
* The ConfirmedCOVNotification service is used to notify subscribers about
* changes that may have occurred to the properties of a particular object.
* Subscriptions for COV notifications are made using the SubscribeCOV service
* or the SubscribeCOVProperty service.
*
* 13.7 UnconfirmedCOVNotification Service <br>
* The UnconfirmedCOVNotification Service is used to notify subscribers about
* changes that may have occurred to the properties of a particular object,
* or to distribute object properties of wide interest (such as outside air
* conditions) to many devices simultaneously without a subscription.
* Subscriptions for COV notifications are made using the SubscribeCOV service.
* For unsubscribed notifications, the algorithm for determining when to issue
* this service is a local matter and may be based on a change of value,
* periodic updating, or some other criteria.
*//** @defgroup ALMACK Alarm and Event-ACK (AE-ACK)
* @ingroup ALMEVNT
* 13.5 AcknowledgeAlarm Service <br>
* In some systems a device may need to know that an operator has seen the alarm
* notification. The AcknowledgeAlarm service is used by a notification-client
* to acknowledge that a human operator has seen and responded to an event
* notification with 'AckRequired' = TRUE. Ensuring that the acknowledgment
* actually comes from a person with appropriate authority is a local matter.
* This service may be used in conjunction with either the
* ConfirmedEventNotification service or the UnconfirmedEventNotification service.
*/
#endif /* BACNET_EVENT_H_ */
Executable
+85
View File
@@ -0,0 +1,85 @@
/**
* @file
* @author Steve Karg
* @date 2004
*/
#ifndef FIFO_H
#define FIFO_H
#include <stdint.h>
#include <stdbool.h>
/**
* FIFO data structure
*
* @{
*/
struct fifo_buffer_t {
/** first byte of data */
volatile unsigned head;
/** last byte of data */
volatile unsigned tail;
/** block of memory or array of data */
volatile uint8_t *buffer;
/** length of the data */
unsigned buffer_len;
};
typedef struct fifo_buffer_t FIFO_BUFFER;
/** @} */
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
unsigned FIFO_Count(
FIFO_BUFFER const *b);
bool FIFO_Full(
FIFO_BUFFER const *b);
bool FIFO_Available(
FIFO_BUFFER const *b,
unsigned count);
bool FIFO_Empty(
FIFO_BUFFER const *b);
uint8_t FIFO_Peek(
FIFO_BUFFER const *b);
uint8_t FIFO_Get(
FIFO_BUFFER * b);
unsigned FIFO_Pull(
FIFO_BUFFER * b,
uint8_t * data_bytes,
unsigned length);
bool FIFO_Put(
FIFO_BUFFER * b,
uint8_t data_byte);
bool FIFO_Add(
FIFO_BUFFER * b,
uint8_t * data_bytes,
unsigned count);
void FIFO_Flush(
FIFO_BUFFER * b);
/* note: buffer_len must be a power of two */
void FIFO_Init(
FIFO_BUFFER * b,
volatile uint8_t * buffer,
unsigned buffer_len);
#ifdef TEST
#include "ctest.h"
void testFIFOBuffer(
Test * pTest);
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+37
View File
@@ -0,0 +1,37 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef FILENAME_H
#define FILENAME_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
char *filename_remove_path(
const char *filename_in);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+93
View File
@@ -0,0 +1,93 @@
/**************************************************************************
*
* 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.
*
*********************************************************************/
#ifndef BACNET_GET_ALARM_SUM_H_
#define BACNET_GET_ALARM_SUM_H_
#include "bacenum.h"
#include <stdint.h>
#include <stdbool.h>
#include "bacapp.h"
#include "timestamp.h"
typedef struct BACnet_Get_Alarm_Summary_Data {
BACNET_OBJECT_ID objectIdentifier;
BACNET_EVENT_STATE alarmState;
BACNET_BIT_STRING acknowledgedTransitions;
} BACNET_GET_ALARM_SUMMARY_DATA;
/* return 0 if no active alarm at this index
return -1 if end of list
return +1 if active alarm */
typedef int (
*get_alarm_summary_function) (
unsigned index,
BACNET_GET_ALARM_SUMMARY_DATA * getalarm_data);
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
int get_alarm_summary_encode_apdu(
uint8_t * apdu,
uint8_t invoke_id);
/* set GetAlarmSummary function */
void handler_get_alarm_summary_set(
BACNET_OBJECT_TYPE object_type,
get_alarm_summary_function pFunction);
/* encode service */
int get_alarm_summary_ack_encode_apdu_init(
uint8_t * apdu,
uint8_t invoke_id);
int get_alarm_summary_ack_encode_apdu_data(
uint8_t * apdu,
size_t max_apdu,
BACNET_GET_ALARM_SUMMARY_DATA * get_alarm_data);
int get_alarm_summary_ack_decode_apdu_data(
uint8_t * apdu,
size_t max_apdu,
BACNET_GET_ALARM_SUMMARY_DATA * get_alarm_data);
#ifdef __cplusplus
}
#endif /* __cplusplus */
/** @defgroup ALMEVNT Alarm and Event Management BIBBs
* @ingroup ALMEVNT
* 13.1 ConfirmedCOVNotification Service <br>
* The GetAlarmSummary service 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.
* The GetEnrollmentSummary service provides a more sophisticated approach
* with various kinds of filters.
*/
#endif /* BACNET_GET_ALARM_SUM_H_ */
+115
View File
@@ -0,0 +1,115 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef GETEVENT_H
#define GETEVENT_H
#include <stdint.h>
#include <stdbool.h>
#include "bacdef.h"
#include "bacenum.h"
#include "timestamp.h"
#include "event.h"
struct BACnet_Get_Event_Information_Data;
typedef struct BACnet_Get_Event_Information_Data {
BACNET_OBJECT_ID objectIdentifier;
BACNET_EVENT_STATE eventState;
BACNET_BIT_STRING acknowledgedTransitions;
BACNET_TIMESTAMP eventTimeStamps[3];
BACNET_NOTIFY_TYPE notifyType;
BACNET_BIT_STRING eventEnable;
uint32_t eventPriorities[3];
struct BACnet_Get_Event_Information_Data *next;
} BACNET_GET_EVENT_INFORMATION_DATA;
/* return 0 if no active event at this index
return -1 if end of list
return +1 if active event */
typedef int (
*get_event_info_function) (
unsigned index,
BACNET_GET_EVENT_INFORMATION_DATA * getevent_data);
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
int getevent_encode_apdu(
uint8_t * apdu,
uint8_t invoke_id,
BACNET_OBJECT_ID * lastReceivedObjectIdentifier);
int getevent_decode_service_request(
uint8_t * apdu,
unsigned apdu_len,
BACNET_OBJECT_ID * object_id);
int getevent_ack_encode_apdu_init(
uint8_t * apdu,
size_t max_apdu,
uint8_t invoke_id);
int getevent_ack_encode_apdu_data(
uint8_t * apdu,
size_t max_apdu,
BACNET_GET_EVENT_INFORMATION_DATA * get_event_data);
int getevent_ack_encode_apdu_end(
uint8_t * apdu,
size_t max_apdu,
bool moreEvents);
int getevent_ack_decode_service_request(
uint8_t * apdu,
int apdu_len, /* total length of the apdu */
BACNET_GET_EVENT_INFORMATION_DATA * get_event_data,
bool * moreEvents);
#ifdef TEST
#include "ctest.h"
int getevent_decode_apdu(
uint8_t * apdu,
unsigned apdu_len,
uint8_t * invoke_id,
BACNET_OBJECT_ID * lastReceivedObjectIdentifier);
int getevent_ack_decode_apdu(
uint8_t * apdu,
int apdu_len, /* total length of the apdu */
uint8_t * invoke_id,
BACNET_GET_EVENT_INFORMATION_DATA * get_event_data,
bool * moreEvents);
void testGetEventInformationAck(
Test * pTest);
void testGetEventInformation(
Test * pTest);
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+368
View File
@@ -0,0 +1,368 @@
/**************************************************************************
*
* Copyright (C) 2005-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.
*
*********************************************************************/
#ifndef HANDLERS_H
#define HANDLERS_H
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include "bacdef.h"
#include "apdu.h"
#include "bacapp.h"
#include "ptransfer.h"
#include "npdu.h"
#include "rd.h"
#include "rp.h"
#include "rpm.h"
#include "wp.h"
#include "readrange.h"
#include "getevent.h"
#include "get_alarm_sum.h"
#include "alarm_ack.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
void handler_unrecognized_service(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * dest,
BACNET_CONFIRMED_SERVICE_DATA * service_data);
void npdu_handler(
BACNET_ADDRESS * src, /* source address */
uint8_t * pdu, /* PDU data */
uint16_t pdu_len); /* length PDU */
void npdu_handler_cleanup(void);
void npdu_handler_init(
uint16_t bip_net,
uint16_t mstp_net);
void npdu_router_handler(
uint16_t snet,
BACNET_ADDRESS * src,
uint8_t * pdu,
uint16_t pdu_len);
int npdu_router_send_pdu(
uint16_t dnet,
BACNET_ADDRESS * dest,
BACNET_NPDU_DATA * npdu_data,
uint8_t * pdu,
unsigned int pdu_len);
void npdu_router_get_my_address(
uint16_t dnet,
BACNET_ADDRESS * my_address);
void routing_npdu_handler(
BACNET_ADDRESS * src,
int *DNET_list,
uint8_t * pdu,
uint16_t pdu_len);
void handler_who_is(
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);
void handler_who_is_bcast_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);
void handler_who_has(
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);
void handler_i_am_add(
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);
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_ack(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src,
BACNET_CONFIRMED_SERVICE_ACK_DATA * service_data);
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_multiple(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src,
BACNET_CONFIRMED_SERVICE_DATA * service_data);
bool WPValidateString(
BACNET_APPLICATION_DATA_VALUE * pValue,
int iMaxLen,
bool bEmptyAllowed,
BACNET_ERROR_CLASS * pErrorClass,
BACNET_ERROR_CODE * pErrorCode);
bool WPValidateArgType(
BACNET_APPLICATION_DATA_VALUE * pValue,
uint8_t ucExpectedType,
BACNET_ERROR_CLASS * pErrorClass,
BACNET_ERROR_CODE * pErrorCode);
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_ack(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src,
BACNET_CONFIRMED_SERVICE_ACK_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);
void handler_reinitialize_device(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src,
BACNET_CONFIRMED_SERVICE_DATA * service_data);
void handler_device_communication_control(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src,
BACNET_CONFIRMED_SERVICE_DATA * service_data);
void handler_dcc_password_set(
char *new_password);
char *handler_dcc_password(void);
void handler_i_have(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src);
/* time synchronization handlers */
void handler_timesync(
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);
/* time sync master features */
int handler_timesync_encode_recipients(
uint8_t * apdu,
int max_apdu);
void handler_timesync_task(BACNET_DATE_TIME *bdatetime);
void handler_timesync_init(void);
bool handler_timesync_recipient_write(
BACNET_WRITE_PROPERTY_DATA * wp_data);
uint32_t handler_timesync_interval(void);
bool handler_timesync_interval_set(uint32_t minutes);
uint32_t handler_timesync_interval_offset(void);
bool handler_timesync_interval_offset_set(uint32_t minutes);
bool handler_timesync_interval_align(void);
bool handler_timesync_interval_align_set(bool flag);
bool handler_timesync_recipient_address_set(
unsigned index,
BACNET_ADDRESS * address);
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_ack(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src,
BACNET_CONFIRMED_SERVICE_ACK_DATA * service_data);
/* Decode the received RPM data and make a linked list of the results. */
int rpm_ack_decode_service_request(
uint8_t * apdu,
int apdu_len,
BACNET_READ_ACCESS_DATA * read_access_data);
/* print the RP Ack data to stdout */
void rp_ack_print_data(
BACNET_READ_PROPERTY_DATA * data);
/* print the GE Ack data to stdout */
void ge_ack_print_data(BACNET_GET_EVENT_INFORMATION_DATA * data, uint32_t device_id);
/* print the RPM Ack data to stdout */
void rpm_ack_print_data(
BACNET_READ_ACCESS_DATA * rpm_data);
void handler_cov_subscribe(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src,
BACNET_CONFIRMED_SERVICE_DATA * service_data);
bool handler_cov_fsm(
void);
void handler_cov_task(
void);
void handler_cov_timer_seconds(
uint32_t elapsed_seconds);
void handler_cov_init(
void);
int handler_cov_encode_subscriptions(
uint8_t * apdu,
int max_apdu);
void handler_ucov_notification(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src);
void handler_ccov_notification(
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);
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_set(
BACNET_OBJECT_TYPE object_type,
alarm_ack_function pFunction);
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_ack(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src,
BACNET_CONFIRMED_SERVICE_ACK_DATA * service_data);
void handler_unconfirmed_private_transfer(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src);
void private_transfer_print_data(
BACNET_PRIVATE_TRANSFER_DATA *private_data);
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_ack(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src,
BACNET_CONFIRMED_SERVICE_ACK_DATA * service_data);
void handler_get_event_information_set(
BACNET_OBJECT_TYPE object_type,
get_event_info_function 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_alarm_summary_set(
BACNET_OBJECT_TYPE object_type,
get_alarm_summary_function pFunction);
void handler_get_alarm_summary(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src,
BACNET_CONFIRMED_SERVICE_DATA * service_data);
void get_alarm_summary_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);
#ifdef __cplusplus
}
#endif /* __cplusplus */
/** @defgroup MISCHNDLR Miscellaneous Handler Utilities
* Various utilities and functions to support the Handlers.
*/
#endif
+67
View File
@@ -0,0 +1,67 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef IAM_H
#define IAM_H
#include <stdint.h>
#include <stdbool.h>
#include "bacdef.h"
#include "bacaddr.h"
#include "npdu.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
int iam_encode_apdu(
uint8_t * apdu,
uint32_t device_id,
unsigned max_apdu,
int segmentation,
uint16_t vendor_id);
int iam_decode_service_request(
uint8_t * apdu,
uint32_t * pDevice_id,
unsigned *pMax_apdu,
int *pSegmentation,
uint16_t * pVendor_id);
#ifdef TEST
#include "ctest.h"
int iam_decode_apdu(
uint8_t * apdu,
uint32_t * pDevice_id,
unsigned *pMax_apdu,
int *pSegmentation,
uint16_t * pVendor_id);
void testIAm(
Test * pTest);
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+64
View File
@@ -0,0 +1,64 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef IHAVE_H
#define IHAVE_H
#include <stdint.h>
#include <stdbool.h>
#include "bacstr.h"
typedef struct BACnet_I_Have_Data {
BACNET_OBJECT_ID device_id;
BACNET_OBJECT_ID object_id;
BACNET_CHARACTER_STRING object_name;
} BACNET_I_HAVE_DATA;
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
int ihave_encode_apdu(
uint8_t * apdu,
BACNET_I_HAVE_DATA * data);
int ihave_decode_service_request(
uint8_t * apdu,
unsigned apdu_len,
BACNET_I_HAVE_DATA * data);
int ihave_decode_apdu(
uint8_t * apdu,
unsigned apdu_len,
BACNET_I_HAVE_DATA * data);
#ifdef TEST
#include "ctest.h"
void testIHave(
Test * pTest);
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+108
View File
@@ -0,0 +1,108 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef INDTEXT_H
#define INDTEXT_H
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
/* index and text pairs */
typedef const struct {
const unsigned index; /* index number that matches the text */
const char *pString; /* text pair - use NULL to end the list */
} INDTEXT_DATA;
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* Searches for a matching string and returns the index to the string
in the parameter found_index.
If the string is not found, false is returned
If the string is found, true is returned and the found_index contains
the first index where the string was found. */
bool indtext_by_string(
INDTEXT_DATA * data_list,
const char *search_name,
unsigned *found_index);
/* case insensitive version */
bool indtext_by_istring(
INDTEXT_DATA * data_list,
const char *search_name,
unsigned *found_index);
/* Searches for a matching string and returns the index to the string
or the default_index if the string is not found. */
unsigned indtext_by_string_default(
INDTEXT_DATA * data_list,
const char *search_name,
unsigned default_index);
/* case insensitive version */
unsigned indtext_by_istring_default(
INDTEXT_DATA * data_list,
const char *search_name,
unsigned default_index);
/* for a given index, return the matching string,
or NULL if not found */
const char *indtext_by_index(
INDTEXT_DATA * data_list,
unsigned index);
/* for a given index, return the matching string,
or default_name if not found */
const char *indtext_by_index_default(
INDTEXT_DATA * data_list,
unsigned index,
const char *default_name);
/* for a given index, return the matching string,
or default_name if not found.
if the index is before the split,
the before_split_default_name is used */
const char *indtext_by_index_split_default(
INDTEXT_DATA * data_list,
unsigned index,
unsigned split_index,
const char *before_split_default_name,
const char *default_name);
/* returns the number of elements in the list */
unsigned indtext_count(
INDTEXT_DATA * data_list);
#if !defined(__BORLANDC__) && !defined(_MSC_VER)
int stricmp(
const char *s1,
const char *s2);
#endif
#ifdef TEST
#include "ctest.h"
void testIndexText(
Test * pTest);
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+50
View File
@@ -0,0 +1,50 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef KEY_H
#define KEY_H
#include <stdint.h>
/* This file has the macros that encode and decode the */
/* keys for the keylist when used with BACnet Object Id's */
typedef uint32_t KEY;
/* assuming a 32 bit KEY */
#define KEY_TYPE_OFFSET 22 /* bits - for BACnet */
#define KEY_TYPE_MASK 0x000003FFL
#define KEY_ID_MASK 0x003FFFFFL
#define KEY_ID_MAX (KEY_ID_MASK + 1L)
#define KEY_TYPE_MAX (KEY_TYPE_MASK + 1L)
#define KEY_LAST(key) ((key & KEY_ID_MASK) == KEY_ID_MAX)
#define KEY_ENCODE(type,id) ( ((unsigned int)\
((unsigned int)(type) & KEY_TYPE_MASK) << KEY_TYPE_OFFSET) |\
((unsigned int)(id) & KEY_ID_MASK) )
#define KEY_DECODE_TYPE(key) ((int)(((unsigned int)(key) >> KEY_TYPE_OFFSET)\
& KEY_TYPE_MASK))
#define KEY_DECODE_ID(key) ((int)((unsigned int)(key) & KEY_ID_MASK))
#endif
+120
View File
@@ -0,0 +1,120 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef KEYLIST_H
#define KEYLIST_H
#include "key.h"
/* This is a key sorted linked list data library that */
/* uses a key or index to access the data. */
/* If the keys are duplicated, they can be added into the list like FIFO */
/* list data and datatype */
struct Keylist_Node {
KEY key; /* unique number that is sorted in the list */
void *data; /* pointer to some data that is stored */
};
typedef struct Keylist {
struct Keylist_Node **array; /* array of nodes */
int count; /* number of nodes in this list - more effecient than loop */
int size; /* number of available nodes on this list - can grow or shrink */
} KEYLIST_TYPE;
typedef KEYLIST_TYPE *OS_Keylist;
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* returns head of the list or NULL on failure. */
OS_Keylist Keylist_Create(
void);
/* delete specified list */
/* note: you should pop all the nodes off the list first. */
void Keylist_Delete(
OS_Keylist list);
/* inserts a node into its sorted position */
/* returns the index where it was added */
int Keylist_Data_Add(
OS_Keylist list,
KEY key,
void *data);
/* deletes a node specified by its key */
/* returns the data from the node */
void *Keylist_Data_Delete(
OS_Keylist list,
KEY key);
/* deletes a node specified by its index */
/* returns the data from the node */
void *Keylist_Data_Delete_By_Index(
OS_Keylist list,
int index);
/* returns the data from last node, and removes it from the list */
void *Keylist_Data_Pop(
OS_Keylist list);
/* returns the data from the node specified by key */
void *Keylist_Data(
OS_Keylist list,
KEY key);
/* returns the index from the node specified by key */
int Keylist_Index(
OS_Keylist list,
KEY key);
/* returns the data specified by key */
void *Keylist_Data_Index(
OS_Keylist list,
int index);
/* return the key at the given index */
KEY Keylist_Key(
OS_Keylist list,
int index);
/* returns the next empty key from the list */
KEY Keylist_Next_Empty_Key(
OS_Keylist list,
KEY key);
/* returns the number of items in the list */
int Keylist_Count(
OS_Keylist list);
#ifdef TEST
#include "ctest.h"
void testKeyList(
Test * pTest);
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+82
View File
@@ -0,0 +1,82 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef LIGHTING_H
#define LIGHTING_H
#include <stdint.h>
#include <stdbool.h>
#include "bacenum.h"
/* BACnetLightingCommand ::= SEQUENCE {
operation [0] BACnetLightingOperation,
target-level [1] REAL (0.0..100.0) OPTIONAL,
ramp-rate [2] REAL (0.1..100.0) OPTIONAL,
step-increment [3] REAL (0.1..100.0) OPTIONAL,
fade-time [4] Unsigned (100.. 86400000) OPTIONAL,
priority [5] Unsigned (1..16) OPTIONAL
}
-- Note that the combination of level, ramp-rate, step-increment, and fade-time fields is
-- dependent on the specific lighting operation. See Table 12-67.
*/
typedef struct BACnetLightingCommand {
BACNET_LIGHTING_OPERATION operation;
/* fields are optional */
bool use_target_level:1;
bool use_ramp_rate:1;
bool use_step_increment:1;
bool use_fade_time:1;
bool use_priority:1;
float target_level;
float ramp_rate;
float step_increment;
uint32_t fade_time;
uint8_t priority;
} BACNET_LIGHTING_COMMAND;
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
int lighting_command_encode(
uint8_t * apdu,
BACNET_LIGHTING_COMMAND * data);
int lighting_command_encode_context(
uint8_t * apdu,
uint8_t tag_number,
BACNET_LIGHTING_COMMAND * value);
int lighting_command_decode(
uint8_t * apdu,
unsigned apdu_max_len,
BACNET_LIGHTING_COMMAND * data);
bool lighting_command_copy(
BACNET_LIGHTING_COMMAND * dst,
BACNET_LIGHTING_COMMAND * src);
bool lighting_command_same(
BACNET_LIGHTING_COMMAND * dst,
BACNET_LIGHTING_COMMAND * src);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+67
View File
@@ -0,0 +1,67 @@
/**************************************************************************
*
* Copyright (C) 2006 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.
*********************************************************************/
#ifndef LSO_H
#define LSO_H
#include <stdint.h>
#include <stdbool.h>
#include "bacenum.h"
#include "bacdef.h"
#include "bacstr.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* Life Safety Operation Service */
typedef struct {
uint32_t processId;
BACNET_CHARACTER_STRING requestingSrc;
BACNET_LIFE_SAFETY_OPERATION operation;
BACNET_OBJECT_ID targetObject;
} BACNET_LSO_DATA;
int lso_encode_apdu(
uint8_t * apdu,
uint8_t invoke_id,
BACNET_LSO_DATA * data);
/* decode the service request only */
int lso_decode_service_request(
uint8_t * apdu,
unsigned apdu_len,
BACNET_LSO_DATA * data);
#ifdef TEST
#include "ctest.h"
void testLSO(
Test * pTest);
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+50
View File
@@ -0,0 +1,50 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef MEMCOPY_H
#define MEMCOPY_H
/* Functional Description: Memory copy function */
#include <stdint.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
bool memcopylen(
size_t offset,
size_t max,
size_t len);
size_t memcopy(
void *dest,
void *src,
size_t offset,
size_t len,
size_t max);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+232
View File
@@ -0,0 +1,232 @@
/**************************************************************************
*
* Copyright (C) 2004 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.
*
*********************************************************************/
#ifndef MSTP_H
#define MSTP_H
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include "mstpdef.h"
struct mstp_port_struct_t {
MSTP_RECEIVE_STATE receive_state;
/* When a master node is powered up or reset, */
/* it shall unconditionally enter the INITIALIZE state. */
MSTP_MASTER_STATE master_state;
/* A Boolean flag set to TRUE by the Receive State Machine */
/* if an error is detected during the reception of a frame. */
/* Set to FALSE by the Master or Slave Node state machine. */
unsigned ReceiveError:1;
/* There is data in the buffer */
unsigned DataAvailable:1;
unsigned ReceivedInvalidFrame:1;
/* A Boolean flag set to TRUE by the Receive State Machine */
/* if a valid frame is received. */
/* Set to FALSE by the Master or Slave Node state machine. */
unsigned ReceivedValidFrame:1;
/* A Boolean flag set to TRUE by the Receive State Machine */
/* if a valid frame is received but it is not addressed to us. */
/* Set to FALSE by the Master or Slave Node state machine. */
unsigned ReceivedValidFrameNotForUs:1;
/* A Boolean flag set to TRUE by the master machine if this node is the */
/* only known master node. */
unsigned SoleMaster:1;
/* stores the latest received data */
uint8_t DataRegister;
/* Used to accumulate the CRC on the data field of a frame. */
uint16_t DataCRC;
/* Used to store the actual CRC from the data field. */
uint8_t DataCRCActualMSB;
uint8_t DataCRCActualLSB;
/* Used to store the data length of a received frame. */
uint16_t DataLength;
/* Used to store the destination address of a received frame. */
uint8_t DestinationAddress;
/* Used to count the number of received octets or errors. */
/* This is used in the detection of link activity. */
/* Compared to Nmin_octets */
uint8_t EventCount;
/* Used to store the frame type of a received frame. */
uint8_t FrameType;
/* The number of frames sent by this node during a single token hold. */
/* When this counter reaches the value Nmax_info_frames, the node must */
/* pass the token. */
uint8_t FrameCount;
/* Used to accumulate the CRC on the header of a frame. */
uint8_t HeaderCRC;
/* Used to store the actual CRC from the header. */
uint8_t HeaderCRCActual;
/* Used as an index by the Receive State Machine, up to a maximum value of */
/* InputBufferSize. */
uint32_t Index;
/* An array of octets, used to store octets as they are received. */
/* InputBuffer is indexed from 0 to InputBufferSize-1. */
/* The maximum size of a frame is 501 octets. */
/* FIXME: assign this to an actual array of bytes! */
/* Note: the buffer is designed as a pointer since some compilers
and microcontroller architectures have limits as to places to
hold contiguous memory. */
uint8_t *InputBuffer;
uint16_t InputBufferSize;
/* "Next Station," the MAC address of the node to which This Station passes */
/* the token. If the Next_Station is unknown, Next_Station shall be equal to */
/* This_Station. */
uint8_t Next_Station;
/* "Poll Station," the MAC address of the node to which This Station last */
/* sent a Poll For Master. This is used during token maintenance. */
uint8_t Poll_Station;
/* A counter of transmission retries used for Token and Poll For Master */
/* transmission. */
unsigned RetryCount;
/* A timer with nominal 5 millisecond resolution used to measure and */
/* generate silence on the medium between octets. It is incremented by a */
/* timer process and is cleared by the Receive State Machine when activity */
/* is detected and by the SendFrame procedure as each octet is transmitted. */
/* Since the timer resolution is limited and the timer is not necessarily */
/* synchronized to other machine events, a timer value of N will actually */
/* denote intervals between N-1 and N */
/* Note: done here as functions - put into timer task or ISR
so that you can be atomic on 8 bit microcontrollers */
uint32_t(
*SilenceTimer) (
void *pArg);
void (
*SilenceTimerReset) (
void *pArg);
/* A timer used to measure and generate Reply Postponed frames. It is */
/* incremented by a timer process and is cleared by the Master Node State */
/* Machine when a Data Expecting Reply Answer activity is completed. */
/* note: we always send a reply postponed since a message other than
the reply may be in the transmit queue */
/* uint16_t ReplyPostponedTimer; */
/* Used to store the Source Address of a received frame. */
uint8_t SourceAddress;
/* The number of tokens received by this node. When this counter reaches the */
/* value Npoll, the node polls the address range between TS and NS for */
/* additional master nodes. TokenCount is set to zero at the end of the */
/* polling process. */
unsigned TokenCount;
/* "This Station," the MAC address of this node. TS is generally read from a */
/* hardware DIP switch, or from nonvolatile memory. Valid values for TS are */
/* 0 to 254. The value 255 is used to denote broadcast when used as a */
/* destination address but is not allowed as a value for TS. */
uint8_t This_Station;
/* This parameter represents the value of the Max_Info_Frames property of */
/* the node's Device object. The value of Max_Info_Frames specifies the */
/* maximum number of information frames the node may send before it must */
/* pass the token. Max_Info_Frames may have different values on different */
/* nodes. This may be used to allocate more or less of the available link */
/* bandwidth to particular nodes. If Max_Info_Frames is not writable in a */
/* node, its value shall be 1. */
uint8_t Nmax_info_frames;
/* This parameter represents the value of the Max_Master property of the */
/* node's Device object. The value of Max_Master specifies the highest */
/* allowable address for master nodes. The value of Max_Master shall be */
/* less than or equal to 127. If Max_Master is not writable in a node, */
/* its value shall be 127. */
uint8_t Nmax_master;
/* An array of octets, used to store octets for transmitting */
/* OutputBuffer is indexed from 0 to OutputBufferSize-1. */
/* The maximum size of a frame is 501 octets. */
/* FIXME: assign this to an actual array of bytes! */
/* Note: the buffer is designed as a pointer since some compilers
and microcontroller architectures have limits as to places to
hold contiguous memory. */
uint8_t *OutputBuffer;
uint16_t OutputBufferSize;
/*Platform-specific port data */
void *UserData;
};
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
void MSTP_Init(
volatile struct mstp_port_struct_t *mstp_port);
void MSTP_Receive_Frame_FSM(
volatile struct mstp_port_struct_t
*mstp_port);
bool MSTP_Master_Node_FSM(
volatile struct mstp_port_struct_t
*mstp_port);
void MSTP_Slave_Node_FSM(
volatile struct mstp_port_struct_t *mstp_port);
/* returns true if line is active */
bool MSTP_Line_Active(
volatile struct mstp_port_struct_t *mstp_port);
uint16_t MSTP_Create_Frame(
uint8_t * buffer, /* where frame is loaded */
uint16_t buffer_len, /* amount of space available */
uint8_t frame_type, /* type of frame to send - see defines */
uint8_t destination, /* destination address */
uint8_t source, /* source address */
uint8_t * data, /* any data to be sent - may be null */
uint16_t data_len); /* number of bytes of data (up to 501) */
void MSTP_Create_And_Send_Frame(
volatile struct mstp_port_struct_t *mstp_port, /* port to send from */
uint8_t frame_type, /* type of frame to send - see defines */
uint8_t destination, /* destination address */
uint8_t source, /* source address */
uint8_t * data, /* any data to be sent - may be null */
uint16_t data_len);
void MSTP_Fill_BACnet_Address(
BACNET_ADDRESS * src,
uint8_t mstp_address);
/* functions used by the MS/TP state machine to put or get data */
/* FIXME: developer must implement these in their DLMSTP module */
uint16_t MSTP_Put_Receive(
volatile struct mstp_port_struct_t *mstp_port);
/* for the MS/TP state machine to use for getting data to send */
/* Return: amount of PDU data */
uint16_t MSTP_Get_Send(
volatile struct mstp_port_struct_t *mstp_port,
unsigned timeout); /* milliseconds to wait for a packet */
/* for the MS/TP state machine to use for getting the reply for
Data-Expecting-Reply Frame */
/* Return: amount of PDU data */
uint16_t MSTP_Get_Reply(
volatile struct mstp_port_struct_t *mstp_port,
unsigned timeout); /* milliseconds to wait for a packet */
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+134
View File
@@ -0,0 +1,134 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef MSTPDEF_H
#define MSTPDEF_H
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include "bacdef.h"
/* The value 255 is used to denote broadcast when used as a */
/* destination address but is not allowed as a value for a station. */
/* Station addresses for master nodes can be 0-127. */
/* Station addresses for slave nodes can be 127-254. */
#define MSTP_BROADCAST_ADDRESS 255
/* MS/TP Frame Type */
/* Frame Types 8 through 127 are reserved by ASHRAE. */
#define FRAME_TYPE_TOKEN 0
#define FRAME_TYPE_POLL_FOR_MASTER 1
#define FRAME_TYPE_REPLY_TO_POLL_FOR_MASTER 2
#define FRAME_TYPE_TEST_REQUEST 3
#define FRAME_TYPE_TEST_RESPONSE 4
#define FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY 5
#define FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY 6
#define FRAME_TYPE_REPLY_POSTPONED 7
/* Frame Types 128 through 255: Proprietary Frames */
/* These frames are available to vendors as proprietary (non-BACnet) frames. */
/* The first two octets of the Data field shall specify the unique vendor */
/* identification code, most significant octet first, for the type of */
/* vendor-proprietary frame to be conveyed. The length of the data portion */
/* of a Proprietary frame shall be in the range of 2 to 501 octets. */
#define FRAME_TYPE_PROPRIETARY_MIN 128
#define FRAME_TYPE_PROPRIETARY_MAX 255
/* The initial CRC16 checksum value */
#define CRC16_INITIAL_VALUE (0xFFFF)
/* receive FSM states */
typedef enum {
MSTP_RECEIVE_STATE_IDLE = 0,
MSTP_RECEIVE_STATE_PREAMBLE = 1,
MSTP_RECEIVE_STATE_HEADER = 2,
MSTP_RECEIVE_STATE_DATA = 3,
MSTP_RECEIVE_STATE_SKIP_DATA = 4
} MSTP_RECEIVE_STATE;
/* master node FSM states */
typedef enum {
MSTP_MASTER_STATE_INITIALIZE = 0,
MSTP_MASTER_STATE_IDLE = 1,
MSTP_MASTER_STATE_USE_TOKEN = 2,
MSTP_MASTER_STATE_WAIT_FOR_REPLY = 3,
MSTP_MASTER_STATE_DONE_WITH_TOKEN = 4,
MSTP_MASTER_STATE_PASS_TOKEN = 5,
MSTP_MASTER_STATE_NO_TOKEN = 6,
MSTP_MASTER_STATE_POLL_FOR_MASTER = 7,
MSTP_MASTER_STATE_ANSWER_DATA_REQUEST = 8
} MSTP_MASTER_STATE;
/* The time without a DataAvailable or ReceiveError event before declaration */
/* of loss of token: 500 milliseconds. */
#define Tno_token 500
/* The minimum time after the end of the stop bit of the final octet of a */
/* received frame before a node may enable its EIA-485 driver: 40 bit times. */
/* At 9600 baud, 40 bit times would be about 4.166 milliseconds */
/* At 19200 baud, 40 bit times would be about 2.083 milliseconds */
/* At 38400 baud, 40 bit times would be about 1.041 milliseconds */
/* At 57600 baud, 40 bit times would be about 0.694 milliseconds */
/* At 76800 baud, 40 bit times would be about 0.520 milliseconds */
/* At 115200 baud, 40 bit times would be about 0.347 milliseconds */
/* 40 bits is 4 octets including a start and stop bit with each octet */
#define Tturnaround (40UL)
/* turnaround_time_milliseconds = (Tturnaround*1000UL)/RS485_Baud; */
/* The number of tokens received or used before a Poll For Master cycle */
/* is executed: 50. */
#define Npoll 50
/* The number of retries on sending Token: 1. */
#define Nretry_token 1
/* The maximum idle time a sending node may allow to elapse between octets */
/* of a frame the node is transmitting: 20 bit times. */
#define Tframe_gap 20
/* The maximum time after the end of the stop bit of the final */
/* octet of a transmitted frame before a node must disable its */
/* EIA-485 driver: 15 bit times. */
#define Tpostdrive 15
/* The width of the time slot within which a node may generate a token: */
/* 10 milliseconds. */
#define Tslot 10
/* The maximum time a node may wait after reception of the token or */
/* a Poll For Master frame before sending the first octet of a frame: */
/* 15 milliseconds. */
#define Tusage_delay 15
#define DEFAULT_MAX_INFO_FRAMES 1
#define DEFAULT_MAX_MASTER 127
#define DEFAULT_MAC_ADDRESS 127
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+41
View File
@@ -0,0 +1,41 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef MSTPTEXT_H
#define MSTPTEXT_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
const char *mstptext_receive_state(
unsigned index);
const char *mstptext_master_state(
unsigned index);
const char *mstptext_frame_type(
unsigned index);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+21
View File
@@ -0,0 +1,21 @@
/* Sample data structure for confirmed private transfer
We have a simple data structure which can be written to
and read from by sending a confirmed private transfer
request with the appropriate parameters.
*/
#define MY_MAX_STR 32
#define MY_MAX_BLOCK 8
#define MY_SVC_READ 0
#define MY_SVC_WRITE 1
#define MY_ERR_OK 0
#define MY_ERR_BAD_INDEX 1
typedef struct MyData {
uint8_t cMyByte1;
uint8_t cMyByte2;
float fMyReal;
int8_t sMyString[MY_MAX_STR + 1]; /* A little extra for the nul */
} DATABLOCK;
+95
View File
@@ -0,0 +1,95 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef NPDU_H
#define NPDU_H
#include <stdbool.h>
#include <stdint.h>
#include "bacdef.h"
#include "bacenum.h"
/** Hop count default is required by BTL to be maximum */
#ifndef HOP_COUNT_DEFAULT
#define HOP_COUNT_DEFAULT 255
#endif
/* an NPDU structure keeps the parameter stack to a minimum */
typedef struct bacnet_npdu_data_t {
uint8_t protocol_version;
/* parts of the control octet: */
bool data_expecting_reply;
bool network_layer_message; /* false if APDU */
BACNET_MESSAGE_PRIORITY priority;
/* optional network message info */
BACNET_NETWORK_MESSAGE_TYPE network_message_type; /* optional */
uint16_t vendor_id; /* optional, if net message type is > 0x80 */
uint8_t hop_count;
} BACNET_NPDU_DATA;
struct router_port_t;
/** The info[] string has no agreed-upon purpose, hence it is useless.
* Keeping it short here. This size could be 0-255. */
#define ROUTER_PORT_INFO_LEN 2
/** Port Info structure used by Routers for their routing table. */
typedef struct router_port_t {
uint16_t dnet; /**< The DNET number that identifies this port. */
uint8_t id; /**< Either 0 or some ill-defined, meaningless value. */
uint8_t info[ROUTER_PORT_INFO_LEN]; /**< Info like 'modem dialing string' */
uint8_t info_len; /**< Length of info[]. */
struct router_port_t *next; /**< Point to next in linked list */
} BACNET_ROUTER_PORT;
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
uint8_t npdu_encode_max_seg_max_apdu(
int max_segs,
int max_apdu);
int npdu_encode_pdu(
uint8_t * npdu,
BACNET_ADDRESS * dest,
BACNET_ADDRESS * src,
BACNET_NPDU_DATA * npdu_data);
void npdu_encode_npdu_data(
BACNET_NPDU_DATA * npdu,
bool data_expecting_reply,
BACNET_MESSAGE_PRIORITY priority);
void npdu_copy_data(
BACNET_NPDU_DATA * dest,
BACNET_NPDU_DATA * src);
int npdu_decode(
uint8_t * npdu,
BACNET_ADDRESS * dest,
BACNET_ADDRESS * src,
BACNET_NPDU_DATA * npdu_data);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+78
View File
@@ -0,0 +1,78 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef OBJECTS_H
#define OBJECTS_H
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include "bacdef.h"
#include "bacstr.h"
#include "bacenum.h"
typedef union BACnetScale_t {
float Float;
int32_t Integer;
} BACNET_SCALE_T;
/* structures to hold the data gotten by ReadProperty from the device */
typedef struct object_accumulator_t {
BACNET_OBJECT_ID Object_Identifier;
BACNET_CHARACTER_STRING Object_Name;
BACNET_OBJECT_TYPE Object_Type;
uint32_t Present_Value;
BACNET_STATUS_FLAGS Status_Flags;
BACNET_EVENT_STATE Event_State;
bool Out_Of_Service;
BACNET_SCALE_T Scale;
BACNET_ENGINEERING_UNITS Units;
uint32_t Max_Pres_Value;
} OBJECT_ACCUMULATOR_T;
typedef struct object_device_t {
BACNET_OBJECT_ID Object_Identifier;
BACNET_CHARACTER_STRING Object_Name;
BACNET_OBJECT_TYPE Object_Type;
BACNET_DEVICE_STATUS System_Status;
BACNET_CHARACTER_STRING Vendor_Name;
uint16_t Vendor_Identifier;
BACNET_CHARACTER_STRING Model_Name;
BACNET_CHARACTER_STRING Firmware_Revision;
BACNET_CHARACTER_STRING Application_Software_Version;
BACNET_CHARACTER_STRING Location;
BACNET_CHARACTER_STRING Description;
uint8_t Protocol_Version;
uint8_t Protocol_Revision;
BACNET_BIT_STRING Protocol_Services_Supported;
BACNET_BIT_STRING Protocol_Object_Types_Supported;
OS_Keylist Object_List;
uint32_t Max_APDU_Length_Accepted;
BACNET_SEGMENTATION Segmentation_Supported;
uint32_t APDU_Timeout;
uint8_t Number_Of_APDU_Retries;
uint32_t Database_Revision;
} OBJECT_DEVICE_T;
#endif
+78
View File
@@ -0,0 +1,78 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef PROPLIST_H
#define PROPLIST_H
#include <stdint.h>
#include <stdbool.h>
#include "bacdef.h"
#include "bacenum.h"
#include "rp.h"
/** @file proplist.h Library of all required and optional object properties */
struct property_list_t {
const int *pList;
unsigned count;
};
struct special_property_list_t {
struct property_list_t Required;
struct property_list_t Optional;
struct property_list_t Proprietary;
};
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
unsigned property_list_count(
const int *pList);
bool property_list_member(
const int *pList,
int object_property);
const int * property_list_optional(
BACNET_OBJECT_TYPE object_type);
const int * property_list_required(
BACNET_OBJECT_TYPE object_type);
void property_list_special(
BACNET_OBJECT_TYPE object_type,
struct special_property_list_t *pPropertyList);
BACNET_PROPERTY_ID property_list_special_property(
BACNET_OBJECT_TYPE object_type,
BACNET_PROPERTY_ID special_property,
unsigned index);
unsigned property_list_special_count(
BACNET_OBJECT_TYPE object_type,
BACNET_PROPERTY_ID special_property);
int property_list_encode(
BACNET_READ_PROPERTY_DATA * rpdata,
const int *pListRequired,
const int *pListOptional,
const int *pListProprietary);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+86
View File
@@ -0,0 +1,86 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef PRIVATE_TRANSFER_H
#define PRIVATE_TRANSFER_H
#include <stdint.h>
#include <stdbool.h>
typedef struct BACnet_Private_Transfer_Data {
uint16_t vendorID;
uint32_t serviceNumber;
uint8_t *serviceParameters;
int serviceParametersLen;
} BACNET_PRIVATE_TRANSFER_DATA;
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
int ptransfer_encode_apdu(
uint8_t * apdu,
uint8_t invoke_id,
BACNET_PRIVATE_TRANSFER_DATA * private_data);
int uptransfer_encode_apdu(
uint8_t * apdu,
BACNET_PRIVATE_TRANSFER_DATA * private_data);
int ptransfer_decode_service_request(
uint8_t * apdu,
unsigned apdu_len,
BACNET_PRIVATE_TRANSFER_DATA * private_data);
int ptransfer_error_encode_apdu(
uint8_t * apdu,
uint8_t invoke_id,
BACNET_ERROR_CLASS error_class,
BACNET_ERROR_CODE error_code,
BACNET_PRIVATE_TRANSFER_DATA * private_data);
int ptransfer_error_decode_service_request(
uint8_t * apdu,
unsigned apdu_len,
BACNET_ERROR_CLASS * error_class,
BACNET_ERROR_CODE * error_code,
BACNET_PRIVATE_TRANSFER_DATA * private_data);
int ptransfer_ack_encode_apdu(
uint8_t * apdu,
uint8_t invoke_id,
BACNET_PRIVATE_TRANSFER_DATA * private_data);
/* ptransfer_ack_decode_service_request() is the same as
ptransfer_decode_service_request */
#ifdef TEST
#include "ctest.h"
void test_Private_Transfer_Request(
Test * pTest);
void test_Private_Transfer_Ack(
Test * pTest);
void test_Private_Transfer_Error(
Test * pTest);
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+90
View File
@@ -0,0 +1,90 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef REINITIALIZE_DEVICE_H
#define REINITIALIZE_DEVICE_H
#include <stdint.h>
#include <stdbool.h>
typedef struct BACnet_Reinitialize_Device_Data {
BACNET_REINITIALIZED_STATE state;
BACNET_CHARACTER_STRING password;
BACNET_ERROR_CLASS error_class;
BACNET_ERROR_CODE error_code;
} BACNET_REINITIALIZE_DEVICE_DATA;
typedef bool(
*reinitialize_device_function) (
BACNET_REINITIALIZE_DEVICE_DATA * rd_data);
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* encode service */
int rd_encode_apdu(
uint8_t * apdu,
uint8_t invoke_id,
BACNET_REINITIALIZED_STATE state,
BACNET_CHARACTER_STRING * password);
/* decode the service request only */
int rd_decode_service_request(
uint8_t * apdu,
unsigned apdu_len,
BACNET_REINITIALIZED_STATE * state,
BACNET_CHARACTER_STRING * password);
#ifdef TEST
#include "ctest.h"
int rd_decode_apdu(
uint8_t * apdu,
unsigned apdu_len,
uint8_t * invoke_id,
BACNET_REINITIALIZED_STATE * state,
BACNET_CHARACTER_STRING * password);
void test_ReinitializeDevice(
Test * pTest);
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
/** @defgroup DMRD Device Management-ReinitializeDevice (DM-RD)
* @ingroup RDMS
* 16.4 ReinitializeDevice Service <br>
* The ReinitializeDevice service is used by a client BACnet-user to instruct
* a remote device to reboot itself (cold start), reset itself to some
* predefined initial state (warm start), or to control the backup or restore
* procedure. Resetting or rebooting a device is primarily initiated by a human
* operator for diagnostic purposes. Use of this service during the backup or
* restore procedure is usually initiated on behalf of the user by the device
* controlling the backup or restore. Due to the sensitive nature of this
* service, a password may be required from the responding BACnet-user prior
* to executing the service.
*
*/
#endif
+175
View File
@@ -0,0 +1,175 @@
/**************************************************************************
*
* Copyright (C) 2009 Peter Mc Shane
*
* 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.
*********************************************************************/
#ifndef READRANGE_H
#define READRANGE_H
#include "bacstr.h"
#include "datetime.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
struct BACnet_Read_Range_Data;
typedef struct BACnet_Read_Range_Data {
BACNET_OBJECT_TYPE object_type;
uint32_t object_instance;
BACNET_PROPERTY_ID object_property;
uint32_t array_index;
uint8_t *application_data;
int application_data_len;
BACNET_BIT_STRING ResultFlags; /**< FIRST_ITEM, LAST_ITEM, MORE_ITEMS. */
int RequestType;/**< Index, sequence or time based request. */
int Overhead; /**< How much space the baggage takes in the response. */
uint32_t ItemCount;
uint32_t FirstSequence;
union { /**< Pick the appropriate data type. */
uint32_t RefIndex;
uint32_t RefSeqNum;
BACNET_DATE_TIME RefTime;
} Range;
int32_t Count; /**< SIGNED value as +ve vs -ve is important. */
BACNET_ERROR_CLASS error_class;
BACNET_ERROR_CODE error_code;
} BACNET_READ_RANGE_DATA;
/** Defines to indicate which type of read range request it is.
Not really a bit map but we do it like this to allow quick
checking of request against capabilities for the property */
#define RR_BY_POSITION 1
#define RR_BY_SEQUENCE 2
#define RR_BY_TIME 4
#define RR_READ_ALL 8 /**< Read all of array - so don't send any range in the request */
#define RR_ARRAY_OF_LISTS 16 /**< For info functionality indicates array of lists if set */
/** Bit String Enumerations */
typedef enum {
RESULT_FLAG_FIRST_ITEM = 0,
RESULT_FLAG_LAST_ITEM = 1,
RESULT_FLAG_MORE_ITEMS = 2
} BACNET_RESULT_FLAGS;
/** Defines for ReadRange packet overheads to allow us to determine how
* much space is left for actual payload:
*
* Overhead is comprised of:
* - 1. PDU Type + invoke ID + service type = 3 bytes
* - 2. Object ID = 5 bytes
* - 3. Object Property = 2 bytes if property is 0-255, 3 if property is
* 256-65535 theoretical max of 5 bytes but how likely is that?
* - 4. Optional array index = 2 bytes if index is 0-255, 3 if index is
* 256-65535 theoretical max of 5 bytes but how likely is that?
* - 5. Flags = 3 bytes
* - 6. Opening and closing tag for data = 2 bytes
* - 7. firstSequenceNumber [6] Unsigned32 OPTIONAL -- used only if 'Item Count' > 0
* and the request was either of type 'By Sequence Number' or 'By Time'
* = minimum of 2 bytes, maximum of 5 bytes.
*
* These figures give an absolute worst-case overhead of 28 bytes. A less
* conservative value (if we assume object property is 3 bytes and array
* index is 3 bytes) is 24. */
/* This is the fixed part of the overhead before we check for array and
* first sequence number requirements. again if you are really paranoid
* use a value of 18 */
#define RR_OVERHEAD 16
#define RR_1ST_SEQ_OVERHEAD 5
#define RR_INDEX_OVERHEAD 3 /* or 5 if paranoid */
/** Define pointer to function type for handling ReadRange request.
This function will take the following parameters:
- 1. A pointer to a buffer of at least MAX_APDU bytes to build the response in.
- 2. A pointer to a BACNET_READ_RANGE_DATA structure with all the request
information in it. The function is responsible for applying the request
to the property in question and returning the response. */
typedef int (
*rr_handler_function) (
uint8_t * apdu,
BACNET_READ_RANGE_DATA * pRequest);
/** Structure to return the type of requests a given object property can
* accept and the address of the function to handle the request */
typedef struct rrpropertyinfo {
int RequestTypes;
rr_handler_function Handler;
} RR_PROP_INFO;
/** Function template for ReadRange information retrieval function.
* A function template; @see device.c for assignment to object types.
* @ingroup ObjHelpers
* @param pRequest [in] Info on the request.
* @param pInfo [out] Where to write the response to.
* @return True on success, False on error or failure.
*/
typedef bool(
*rr_info_function) (
BACNET_READ_RANGE_DATA * pRequest, /* Info on the request */
RR_PROP_INFO * pInfo); /* Where to write the response to */
int rr_encode_apdu(
uint8_t * apdu,
uint8_t invoke_id,
BACNET_READ_RANGE_DATA * rrdata);
int rr_decode_service_request(
uint8_t * apdu,
unsigned apdu_len,
BACNET_READ_RANGE_DATA * rrdata);
int rr_ack_encode_apdu(
uint8_t * apdu,
uint8_t invoke_id,
BACNET_READ_RANGE_DATA * rrdata);
int rr_ack_decode_service_request(
uint8_t * apdu,
int apdu_len, /* total length of the apdu */
BACNET_READ_RANGE_DATA * rrdata);
uint8_t Send_ReadRange_Request(
uint32_t device_id, /* destination device */
BACNET_READ_RANGE_DATA * read_access_data);
#ifdef __cplusplus
}
#endif /* __cplusplus */
/** @defgroup Trend Trending BIBBs
* These BIBBs prescribe the BACnet capabilities required to interoperably
* perform the trending functions enumerated in clause 22.2.1.4 for the
* BACnet devices defined therein.
*/
/** @defgroup TrendReadRange Trending -Read Range Service (eg, in T-VMT)
* @ingroup Trend
* 15.8 ReadRange Service <br>
* The ReadRange service is used by a client BACnet-user to read a specific
* range of data items representing a subset of data available within a
* specified object property.
* The service may be used with any list or array of lists property.
*/
#endif
+62
View File
@@ -0,0 +1,62 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef REJECT_H
#define REJECT_H
#include <stdint.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
BACNET_REJECT_REASON reject_convert_error_code(
BACNET_ERROR_CODE error_code);
int reject_encode_apdu(
uint8_t * apdu,
uint8_t invoke_id,
uint8_t reject_reason);
int reject_decode_service_request(
uint8_t * apdu,
unsigned apdu_len,
uint8_t * invoke_id,
uint8_t * reject_reason);
#ifdef TEST
int reject_decode_apdu(
uint8_t * apdu,
unsigned apdu_len,
uint8_t * invoke_id,
uint8_t * reject_reason);
void testReject(
Test * pTest);
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+96
View File
@@ -0,0 +1,96 @@
/**
* @file
* @author Steve Karg
* @date 2004
*
* Generic ring buffer library for deeply embedded system.
* See the unit tests for usage examples.
*/
#ifndef RINGBUF_H
#define RINGBUF_H
#include <stdint.h>
#include <stdbool.h>
/**
* ring buffer power of two alignment macro
*
* @{
*/
#ifndef NEXT_POWER_OF_2
#define B2(x) ( (x) | ( (x) >> 1) )
#define B4(x) ( B2(x) | ( B2(x) >> 2) )
#define B8(x) ( B4(x) | ( B4(x) >> 4) )
#define B16(x) ( B8(x) | ( B8(x) >> 8) )
#define B32(x) (B16(x) | (B16(x) >>16) )
#define NEXT_POWER_OF_2(x) (B32((x)-1) + 1)
#endif
/** @} */
/**
* ring buffer data structure
*
* @{
*/
struct ring_buffer_t {
/** block of memory or array of data */
volatile uint8_t *buffer;
/** how many bytes for each chunk */
unsigned element_size;
/** number of chunks of data */
unsigned element_count;
/** where the writes go */
volatile unsigned head;
/** where the reads come from */
volatile unsigned tail;
/* maximum depth reached */
volatile unsigned depth;
};
typedef struct ring_buffer_t RING_BUFFER;
/** @} */
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
unsigned Ringbuf_Count(RING_BUFFER const *b);
unsigned Ringbuf_Depth(RING_BUFFER const *b);
unsigned Ringbuf_Depth_Reset(RING_BUFFER *b);
unsigned Ringbuf_Size(RING_BUFFER const *b);
bool Ringbuf_Full(RING_BUFFER const *b);
bool Ringbuf_Empty(RING_BUFFER const *b);
/* tail */
volatile uint8_t *Ringbuf_Peek(RING_BUFFER const *b);
bool Ringbuf_Pop(RING_BUFFER * b,
uint8_t * data_element);
bool Ringbuf_Pop_Element(RING_BUFFER * b,
uint8_t * this_element,
uint8_t * data_element);
bool Ringbuf_Put_Front(RING_BUFFER * b,
uint8_t * data_element);
/* head */
bool Ringbuf_Put(RING_BUFFER * b,
uint8_t * data_element);
/* pair of functions to use head memory directly */
volatile uint8_t *Ringbuf_Data_Peek(RING_BUFFER * b);
volatile uint8_t *Ringbuf_Peek_Next(RING_BUFFER const *b,
uint8_t * data_element);
bool Ringbuf_Data_Put(RING_BUFFER * b, volatile uint8_t *data_element);
/* Note: element_count must be a power of two */
bool Ringbuf_Init(RING_BUFFER * b,
volatile uint8_t * buffer,
unsigned element_size,
unsigned element_count);
#ifdef TEST
#include "ctest.h"
void testRingBufPowerOfTwo(Test * pTest);
void testRingBufSizeSmall(Test * pTest);
void testRingBufSizeLarge(Test * pTest);
void testRingBufSizeInvalid(Test * pTest);
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+137
View File
@@ -0,0 +1,137 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef READPROPERTY_H
#define READPROPERTY_H
#include <stdint.h>
#include <stdbool.h>
#include "bacdef.h"
#include "bacenum.h"
typedef struct BACnet_Read_Property_Data {
BACNET_OBJECT_TYPE object_type;
uint32_t object_instance;
BACNET_PROPERTY_ID object_property;
uint32_t array_index;
uint8_t *application_data;
int application_data_len;
BACNET_ERROR_CLASS error_class;
BACNET_ERROR_CODE error_code;
} BACNET_READ_PROPERTY_DATA;
/* Forward declaration of RPM-style data structure */
struct BACnet_Read_Access_Data;
/** Reads one property for this object type of a given instance.
* A function template; @see device.c for assignment to object types.
* @ingroup ObjHelpers
*
* @param rp_data [in] Pointer to the BACnet_Read_Property_Data structure,
* which is packed with the information from the RP request.
* @return The length of the apdu encoded or -1 for error or
* -2 for abort message.
*/
typedef int (
*read_property_function) (
BACNET_READ_PROPERTY_DATA * rp_data);
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* encode service */
int rp_encode_apdu(
uint8_t * apdu,
uint8_t invoke_id,
BACNET_READ_PROPERTY_DATA * rpdata);
/* decode the service request only */
int rp_decode_service_request(
uint8_t * apdu,
unsigned apdu_len,
BACNET_READ_PROPERTY_DATA * rpdata);
/* method to encode the ack without extra buffer */
int rp_ack_encode_apdu_init(
uint8_t * apdu,
uint8_t invoke_id,
BACNET_READ_PROPERTY_DATA * rpdata);
int rp_ack_encode_apdu_object_property_end(
uint8_t * apdu);
/* method to encode the ack using extra buffer */
int rp_ack_encode_apdu(
uint8_t * apdu,
uint8_t invoke_id,
BACNET_READ_PROPERTY_DATA * rpdata);
int rp_ack_decode_service_request(
uint8_t * apdu,
int apdu_len, /* total length of the apdu */
BACNET_READ_PROPERTY_DATA * rpdata);
/* Decode instead to RPM-style data structure. */
int rp_ack_fully_decode_service_request(
uint8_t * apdu,
int apdu_len,
struct BACnet_Read_Access_Data *read_access_data);
#ifdef TEST
#include "ctest.h"
int rp_decode_apdu(
uint8_t * apdu,
unsigned apdu_len,
uint8_t * invoke_id,
BACNET_READ_PROPERTY_DATA * rpdata);
int rp_ack_decode_apdu(
uint8_t * apdu,
int apdu_len, /* total length of the apdu */
uint8_t * invoke_id,
BACNET_READ_PROPERTY_DATA * rpdata);
void test_ReadProperty(
Test * pTest);
void test_ReadPropertyAck(
Test * pTest);
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
/** @defgroup DataShare Data Sharing BIBBs
* These BIBBs prescribe the BACnet capabilities required to interoperably
* perform the data sharing functions enumerated in 22.2.1.1 for the BACnet
* devices defined therein.
*/
/** @defgroup DSRP Data Sharing -Read Property Service (DS-RP)
* @ingroup DataShare
* 15.5 ReadProperty Service <br>
* The ReadProperty service is used by a client BACnet-user to request the
* value of one property of one BACnet Object. This service allows read access
* to any property of any object, whether a BACnet-defined object or not.
*/
#endif
+206
View File
@@ -0,0 +1,206 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef RPM_H
#define RPM_H
#include <stdint.h>
#include <stdbool.h>
#include "bacenum.h"
#include "bacdef.h"
#include "bacapp.h"
#include "proplist.h"
/*
* Bundle together commonly used data items for convenience when calling
* rpm helper functions.
*/
typedef struct BACnet_RPM_Data {
BACNET_OBJECT_TYPE object_type;
uint32_t object_instance;
BACNET_PROPERTY_ID object_property;
uint32_t array_index;
BACNET_ERROR_CLASS error_class;
BACNET_ERROR_CODE error_code;
} BACNET_RPM_DATA;
struct BACnet_Read_Access_Data;
typedef struct BACnet_Read_Access_Data {
BACNET_OBJECT_TYPE object_type;
uint32_t object_instance;
/* simple linked list of values */
BACNET_PROPERTY_REFERENCE *listOfProperties;
struct BACnet_Read_Access_Data *next;
} BACNET_READ_ACCESS_DATA;
/** Fetches the lists of properties (array of BACNET_PROPERTY_ID's) for this
* object type, grouped by Required, Optional, and Proprietary.
* A function template; @see device.c for assignment to object types.
* @ingroup ObjHelpers
*
* @param pRequired [out] Pointer reference for the list of Required properties.
* @param pOptional [out] Pointer reference for the list of Optional properties.
* @param pProprietary [out] Pointer reference for the list of Proprietary
* properties for this BACNET_OBJECT_TYPE.
*/
typedef void (
*rpm_property_lists_function) (
const int **pRequired,
const int **pOptional,
const int **pProprietary);
typedef void (
*rpm_object_property_lists_function) (
BACNET_OBJECT_TYPE object_type,
struct special_property_list_t * pPropertyList);
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* encode functions */
/* Start with the Init function, and then add an object,
then add its properties, and then end the object.
Continue to add objects and properties as needed
until the APDU is full.*/
/* RPM */
int rpm_encode_apdu_init(
uint8_t * apdu,
uint8_t invoke_id);
int rpm_encode_apdu_object_begin(
uint8_t * apdu,
BACNET_OBJECT_TYPE object_type,
uint32_t object_instance);
int rpm_encode_apdu_object_property(
uint8_t * apdu,
BACNET_PROPERTY_ID object_property,
uint32_t array_index);
int rpm_encode_apdu_object_end(
uint8_t * apdu);
int rpm_encode_apdu(
uint8_t * apdu,
size_t max_apdu,
uint8_t invoke_id,
BACNET_READ_ACCESS_DATA * read_access_data);
/* decode the object portion of the service request only */
int rpm_decode_object_id(
uint8_t * apdu,
unsigned apdu_len,
BACNET_RPM_DATA * rpmdata);
/* is this the end of this object property list? */
int rpm_decode_object_end(
uint8_t * apdu,
unsigned apdu_len);
/* decode the object property portion of the service request only */
int rpm_decode_object_property(
uint8_t * apdu,
unsigned apdu_len,
BACNET_RPM_DATA * rpmdata);
/* RPM Ack - reply from server */
int rpm_ack_encode_apdu_init(
uint8_t * apdu,
uint8_t invoke_id);
int rpm_ack_encode_apdu_object_begin(
uint8_t * apdu,
BACNET_RPM_DATA * rpmdata);
int rpm_ack_encode_apdu_object_property(
uint8_t * apdu,
BACNET_PROPERTY_ID object_property,
uint32_t array_index);
int rpm_ack_encode_apdu_object_property_value(
uint8_t * apdu,
uint8_t * application_data,
unsigned application_data_len);
int rpm_ack_encode_apdu_object_property_error(
uint8_t * apdu,
BACNET_ERROR_CLASS error_class,
BACNET_ERROR_CODE error_code);
int rpm_ack_encode_apdu_object_end(
uint8_t * apdu);
int rpm_ack_decode_object_id(
uint8_t * apdu,
unsigned apdu_len,
BACNET_OBJECT_TYPE * object_type,
uint32_t * object_instance);
/* is this the end of the list of this objects properties values? */
int rpm_ack_decode_object_end(
uint8_t * apdu,
unsigned apdu_len);
int rpm_ack_decode_object_property(
uint8_t * apdu,
unsigned apdu_len,
BACNET_PROPERTY_ID * object_property,
uint32_t * array_index);
#ifdef TEST
#include "ctest.h"
int rpm_decode_apdu(
uint8_t * apdu,
unsigned apdu_len,
uint8_t * invoke_id,
uint8_t ** service_request,
unsigned *service_request_len);
int rpm_ack_decode_apdu(
uint8_t * apdu,
int apdu_len, /* total length of the apdu */
uint8_t * invoke_id,
uint8_t ** service_request,
unsigned *service_request_len);
void testReadPropertyMultiple(
Test * pTest);
void testReadPropertyMultipleAck(
Test * pTest);
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
/** @defgroup DSRPM Data Sharing -Read Property Multiple Service (DS-RPM)
* @ingroup DataShare
* 15.7 ReadPropertyMultiple Service <br>
* The ReadPropertyMultiple service is used by a client BACnet-user to request
* the values of one or more specified properties of one or more BACnet Objects.
* This service allows read access to any property of any object, whether a
* BACnet-defined object or not. The user may read a single property of a single
* object, a list of properties of a single object, or any number of properties
* of any number of objects.
* A 'Read Access Specification' with the property identifier ALL can be used to
* learn the implemented properties of an object along with their values.
*/
#endif
+80
View File
@@ -0,0 +1,80 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef SBUF_H
#define SBUF_H
/* Functional Description: Static buffer library for deeply
embedded system. See the unit tests for usage examples. */
#include <stdint.h>
#include <stdbool.h>
struct static_buffer_t {
char *data; /* block of memory or array of data */
unsigned size; /* actual size, in bytes, of the block of data */
unsigned count; /* number of bytes in use */
};
typedef struct static_buffer_t STATIC_BUFFER;
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
void sbuf_init(
STATIC_BUFFER * b, /* static buffer structure */
char *data, /* data block */
unsigned size); /* actual size, in bytes, of the data block or array of data */
/* returns true if size==0, false if size > 0 */
bool sbuf_empty(
STATIC_BUFFER const *b);
/* returns the data block, or NULL if not initialized */
char *sbuf_data(
STATIC_BUFFER const *b);
/* returns the max size of the data block */
unsigned sbuf_size(
STATIC_BUFFER * b);
/* returns the number of bytes used in the data block */
unsigned sbuf_count(
STATIC_BUFFER * b);
/* returns true if successful, false if not enough room to append data */
bool sbuf_put(
STATIC_BUFFER * b, /* static buffer structure */
unsigned offset, /* where to start */
char *data, /* data to add */
unsigned data_size); /* how many to add */
/* returns true if successful, false if not enough room to append data */
bool sbuf_append(
STATIC_BUFFER * b, /* static buffer structure */
char *data, /* data to append */
unsigned data_size); /* how many to append */
/* returns true if successful, false if count is bigger than size */
bool sbuf_truncate(
STATIC_BUFFER * b, /* static buffer structure */
unsigned count); /* new number of bytes used in buffer */
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+86
View File
@@ -0,0 +1,86 @@
/**************************************************************************
*
* 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.
*********************************************************************/
#ifndef _TIMESTAMP_H_
#define _TIMESTAMP_H_
#include "bacdcode.h"
typedef enum {
TIME_STAMP_TIME = 0,
TIME_STAMP_SEQUENCE = 1,
TIME_STAMP_DATETIME = 2
} BACNET_TIMESTAMP_TAG;
typedef uint8_t TYPE_BACNET_TIMESTAMP_TYPE;
typedef struct BACnet_Timestamp {
TYPE_BACNET_TIMESTAMP_TYPE tag;
union {
BACNET_TIME time;
uint16_t sequenceNum;
BACNET_DATE_TIME dateTime;
} value;
} BACNET_TIMESTAMP;
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
void bacapp_timestamp_sequence_set(
BACNET_TIMESTAMP * dest,
uint16_t sequenceNum);
void bacapp_timestamp_time_set(
BACNET_TIMESTAMP * dest,
BACNET_TIME *btime);
void bacapp_timestamp_datetime_set(
BACNET_TIMESTAMP * dest,
BACNET_DATE_TIME * bdateTime);
void bacapp_timestamp_copy(
BACNET_TIMESTAMP * dest,
BACNET_TIMESTAMP * src);
int bacapp_encode_timestamp(
uint8_t * apdu,
BACNET_TIMESTAMP * value);
int bacapp_decode_timestamp(
uint8_t * apdu,
BACNET_TIMESTAMP * value);
int bacapp_encode_context_timestamp(
uint8_t * apdu,
uint8_t tag_number,
BACNET_TIMESTAMP * value);
int bacapp_decode_context_timestamp(
uint8_t * apdu,
uint8_t tag_number,
BACNET_TIMESTAMP * value);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+101
View File
@@ -0,0 +1,101 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef TIMESYNC_H
#define TIMESYNC_H
#include <stdint.h>
#include <stdbool.h>
#include "bacdef.h"
struct BACnet_Recipient_List;
typedef struct BACnet_Recipient_List {
/*
BACnetRecipient ::= CHOICE {
device [0] BACnetObjectIdentifier,
address [1] BACnetAddress
}
*/
uint8_t tag;
union {
BACNET_OBJECT_ID device;
BACNET_ADDRESS address;
} type;
/* simple linked list */
struct BACnet_Recipient_List *next;
} BACNET_RECIPIENT_LIST;
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* encode service */
int timesync_utc_encode_apdu(
uint8_t * apdu,
BACNET_DATE * my_date,
BACNET_TIME * my_time);
int timesync_encode_apdu(
uint8_t * apdu,
BACNET_DATE * my_date,
BACNET_TIME * my_time);
int timesync_encode_apdu_service(
uint8_t * apdu,
BACNET_UNCONFIRMED_SERVICE service,
BACNET_DATE * my_date,
BACNET_TIME * my_time);
/* decode the service request only */
int timesync_decode_service_request(
uint8_t * apdu,
unsigned apdu_len,
BACNET_DATE * my_date,
BACNET_TIME * my_time);
int timesync_utc_decode_apdu(
uint8_t * apdu,
unsigned apdu_len,
BACNET_DATE * my_date,
BACNET_TIME * my_time);
int timesync_decode_apdu(
uint8_t * apdu,
unsigned apdu_len,
BACNET_DATE * my_date,
BACNET_TIME * my_time);
int timesync_encode_timesync_recipients(
uint8_t * apdu,
unsigned max_apdu,
BACNET_RECIPIENT_LIST * recipient);
int timesync_decode_timesync_recipients(
uint8_t * apdu,
unsigned apdu_len,
BACNET_RECIPIENT_LIST * recipient);
#ifdef TEST
#include "ctest.h"
void testTimeSync(
Test * pTest);
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+134
View File
@@ -0,0 +1,134 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef TSM_H
#define TSM_H
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
#include "bacdef.h"
#include "npdu.h"
/* note: TSM functionality is optional - only needed if we are
doing client requests */
#if (!MAX_TSM_TRANSACTIONS)
#define tsm_free_invoke_id(x) (void)x;
#else
typedef enum {
TSM_STATE_IDLE,
TSM_STATE_AWAIT_CONFIRMATION,
TSM_STATE_AWAIT_RESPONSE,
TSM_STATE_SEGMENTED_REQUEST,
TSM_STATE_SEGMENTED_CONFIRMATION
} BACNET_TSM_STATE;
/* 5.4.1 Variables And Parameters */
/* The following variables are defined for each instance of */
/* Transaction State Machine: */
typedef struct BACnet_TSM_Data {
/* used to count APDU retries */
uint8_t RetryCount;
/* used to count segment retries */
/*uint8_t SegmentRetryCount; */
/* used to control APDU retries and the acceptance of server replies */
/*bool SentAllSegments; */
/* stores the sequence number of the last segment received in order */
/*uint8_t LastSequenceNumber; */
/* stores the sequence number of the first segment of */
/* a sequence of segments that fill a window */
/*uint8_t InitialSequenceNumber; */
/* stores the current window size */
/*uint8_t ActualWindowSize; */
/* stores the window size proposed by the segment sender */
/*uint8_t ProposedWindowSize; */
/* used to perform timeout on PDU segments */
/*uint8_t SegmentTimer; */
/* used to perform timeout on Confirmed Requests */
/* in milliseconds */
uint16_t RequestTimer;
/* unique id */
uint8_t InvokeID;
/* state that the TSM is in */
BACNET_TSM_STATE state;
/* the address we sent it to */
BACNET_ADDRESS dest;
/* the network layer info */
BACNET_NPDU_DATA npdu_data;
/* copy of the APDU, should we need to send it again */
uint8_t apdu[MAX_PDU];
unsigned apdu_len;
} BACNET_TSM_DATA;
typedef void (
*tsm_timeout_function) (
uint8_t invoke_id);
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
void tsm_set_timeout_handler(
tsm_timeout_function pFunction);
bool tsm_transaction_available(
void);
uint8_t tsm_transaction_idle_count(
void);
void tsm_timer_milliseconds(
uint16_t milliseconds);
/* free the invoke ID when the reply comes back */
void tsm_free_invoke_id(
uint8_t invokeID);
/* use these in tandem */
uint8_t tsm_next_free_invokeID(
void);
void tsm_invokeID_set(
uint8_t invokeID);
/* returns the same invoke ID that was given */
void tsm_set_confirmed_unsegmented_transaction(
uint8_t invokeID,
BACNET_ADDRESS * dest,
BACNET_NPDU_DATA * ndpu_data,
uint8_t * apdu,
uint16_t apdu_len);
/* returns true if transaction is found */
bool tsm_get_transaction_pdu(
uint8_t invokeID,
BACNET_ADDRESS * dest,
BACNET_NPDU_DATA * ndpu_data,
uint8_t * apdu,
uint16_t * apdu_len);
bool tsm_invoke_id_free(
uint8_t invokeID);
bool tsm_invoke_id_failed(
uint8_t invokeID);
#ifdef __cplusplus
}
#endif /* __cplusplus */
/* define out any functions necessary for compile */
#endif
#endif
+35
View File
@@ -0,0 +1,35 @@
/**************************************************************************
*
* 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.
*
*********************************************************************/
#ifndef TXBUF_H
#define TXBUF_H
#include <stddef.h>
#include <stdint.h>
#include "config.h"
#include "datalink.h"
extern uint8_t Handler_Transmit_Buffer[MAX_PDU];
#endif
+73
View File
@@ -0,0 +1,73 @@
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* Copyright (C) 2008 John Crispin <blogic@openwrt.org>
*/
#ifndef _UCI_H__
#define _UCI_H__
struct uci_context *ucix_init(
const char *config_file);
struct uci_context *ucix_init_path(
const char *path,
const char *config_file);
void ucix_cleanup(
struct uci_context *ctx);
void ucix_save(
struct uci_context *ctx);
void ucix_save_state(
struct uci_context *ctx);
const char *ucix_get_option(
struct uci_context *ctx,
const char *p,
const char *s,
const char *o);
int ucix_get_option_int(
struct uci_context *ctx,
const char *p,
const char *s,
const char *o,
int def);
void ucix_add_section(
struct uci_context *ctx,
const char *p,
const char *s,
const char *t);
void ucix_add_option(
struct uci_context *ctx,
const char *p,
const char *s,
const char *o,
const char *t);
void ucix_add_option_int(
struct uci_context *ctx,
const char *p,
const char *s,
const char *o,
int t);
int ucix_commit(
struct uci_context *ctx,
const char *p);
void ucix_revert(
struct uci_context *ctx,
const char *p,
const char *s,
const char *o);
void ucix_del(
struct uci_context *ctx,
const char *p,
const char *s,
const char *o);
#endif
+39
View File
@@ -0,0 +1,39 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef VERSION_H
#define VERSION_H
/* This BACnet protocol stack version 0.0.0 - FF.FF.FF */
#ifndef BACNET_VERSION
#define BACNET_VERSION(x,y,z) (((x)<<16)+((y)<<8)+(z))
#endif
#define BACNET_VERSION_TEXT "0.9.1"
#define BACNET_VERSION_CODE BACNET_VERSION(0,9,1)
#define BACNET_VERSION_MAJOR ((BACNET_VERSION_CODE>>16)&0xFF)
#define BACNET_VERSION_MINOR ((BACNET_VERSION_CODE>>8)&0xFF)
#define BACNET_VERSION_MAINTENANCE (BACNET_VERSION_CODE&0xFF)
extern char *BACnet_Version;
#endif
+52
View File
@@ -0,0 +1,52 @@
/**
* @file
* @author Steve Karg
* @date 2016
*/
#ifndef VMAC_H
#define VMAC_H
#include <stdint.h>
#include <stdbool.h>
/* define the max MAC as big as IPv6 + port number */
#define VMAC_MAC_MAX 18
/**
* VMAC data structure
*
* @{
*/
struct vmac_data {
uint8_t mac[18];
uint8_t mac_len;
};
/** @} */
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
unsigned int VMAC_Count(void);
struct vmac_data *VMAC_Find_By_Key(uint32_t device_id);
bool VMAC_Find_By_Data(struct vmac_data *vmac, uint32_t *device_id);
bool VMAC_Add(uint32_t device_id, struct vmac_data *pVMAC);
bool VMAC_Delete(uint32_t device_id);
bool VMAC_Different(
struct vmac_data *vmac1,
struct vmac_data *vmac2);
bool VMAC_Match(
struct vmac_data *vmac1,
struct vmac_data *vmac2);
void VMAC_Cleanup(void);
void VMAC_Init(void);
#ifdef TEST
#include "ctest.h"
void testVMAC(
Test * pTest);
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+82
View File
@@ -0,0 +1,82 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef WHOHAS_H
#define WHOHAS_H
#include <stdint.h>
#include <stdbool.h>
#include "bacstr.h"
typedef struct BACnet_Who_Has_Data {
int32_t low_limit; /* deviceInstanceRange */
int32_t high_limit;
bool is_object_name; /* true if a string */
union {
BACNET_OBJECT_ID identifier;
BACNET_CHARACTER_STRING name;
} object;
} BACNET_WHO_HAS_DATA;
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* encode service - use -1 for limit if you want unlimited */
int whohas_encode_apdu(
uint8_t * apdu,
BACNET_WHO_HAS_DATA * data);
int whohas_decode_service_request(
uint8_t * apdu,
unsigned apdu_len,
BACNET_WHO_HAS_DATA * data);
int whohas_decode_apdu(
uint8_t * apdu,
unsigned apdu_len,
BACNET_WHO_HAS_DATA * data);
#ifdef TEST
#include "ctest.h"
void testWhoHas(
Test * pTest);
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
/** @defgroup DMDOB Device Management-Dynamic Object Binding (DM-DOB)
* @ingroup RDMS
* 16.9 Who-Has and I-Have Services <br>
* The Who-Has service is used by a sending BACnet-user to identify the device
* object identifiers and network addresses of other BACnet devices whose local
* databases contain an object with a given Object_Name or a given Object_Identifier.
* The I-Have service is used to respond to Who-Has service requests or to
* advertise the existence of an object with a given Object_Name or
* Object_Identifier. The I-Have service request may be issued at any time and
* does not need to be preceded by the receipt of a Who-Has service request.
* The Who-Has and I-Have services are unconfirmed services.
*
*/
#endif
+79
View File
@@ -0,0 +1,79 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef WHOIS_H
#define WHOIS_H
#include <stdint.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* encode service - use -1 for limit if you want unlimited */
int whois_encode_apdu(
uint8_t * apdu,
int32_t low_limit,
int32_t high_limit);
int whois_decode_service_request(
uint8_t * apdu,
unsigned apdu_len,
int32_t * pLow_limit,
int32_t * pHigh_limit);
#ifdef TEST
int whois_decode_apdu(
uint8_t * apdu,
unsigned apdu_len,
int32_t * pLow_limit,
int32_t * pHigh_limit);
void testWhoIs(
Test * pTest);
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
/** @defgroup DMDDB Device Management-Dynamic Device Binding (DM-DDB)
* @ingroup RDMS
* 16.10 Who-Is and I-Am Services <br>
* The Who-Is service is used by a sending BACnet-user to determine the device
* object identifier, the network address, or both, of other BACnet devices
* that share the same internetwork.
* The Who-Is service is an unconfirmed service. The Who-Is service may be used
* to determine the device object identifier and network addresses of all devices
* on the network, or to determine the network address of a specific device whose
* device object identifier is known, but whose address is not. <br>
* The I-Am service is also an unconfirmed service. The I-Am service is used to
* respond to Who-Is service requests. However, the I-Am service request may be
* issued at any time. It does not need to be preceded by the receipt of a
* Who-Is service request. In particular, a device may wish to broadcast an I-Am
* service request when it powers up. The network address is derived either
* from the MAC address associated with the I-Am service request, if the device
* issuing the request is on the local network, or from the NPCI if the device
* is on a remote network.
*/
#endif
+107
View File
@@ -0,0 +1,107 @@
/**************************************************************************
*
* Copyright (C) 2012 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.
*********************************************************************/
#ifndef WRITEPROPERTY_H
#define WRITEPROPERTY_H
#include <stdint.h>
#include <stdbool.h>
#include "bacdcode.h"
#include "bacapp.h"
/** @note: write property can have application tagged data, or context tagged data,
or even complex data types (i.e. opening and closing tag around data).
It could also have more than one value or element. */
typedef struct BACnet_Write_Property_Data {
BACNET_OBJECT_TYPE object_type;
uint32_t object_instance;
BACNET_PROPERTY_ID object_property;
uint32_t array_index; /* use BACNET_ARRAY_ALL when not setting */
uint8_t application_data[MAX_APDU];
int application_data_len;
uint8_t priority; /* use BACNET_NO_PRIORITY if no priority */
BACNET_ERROR_CLASS error_class;
BACNET_ERROR_CODE error_code;
} BACNET_WRITE_PROPERTY_DATA;
/** Attempts to write a new value to one property for this object type
* of a given instance.
* A function template; @see device.c for assignment to object types.
* @ingroup ObjHelpers
*
* @param wp_data [in] Pointer to the BACnet_Write_Property_Data structure,
* which is packed with the information from the WP request.
* @return The length of the apdu encoded or -1 for error or
* -2 for abort message.
*/
typedef bool(
*write_property_function) (
BACNET_WRITE_PROPERTY_DATA * wp_data);
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* encode service */
int wp_encode_apdu(
uint8_t * apdu,
uint8_t invoke_id,
BACNET_WRITE_PROPERTY_DATA * wp_data);
/* decode the service request only */
int wp_decode_service_request(
uint8_t * apdu,
unsigned apdu_len,
BACNET_WRITE_PROPERTY_DATA * wp_data);
#ifdef TEST
#include "ctest.h"
int wp_decode_apdu(
uint8_t * apdu,
unsigned apdu_len,
uint8_t * invoke_id,
BACNET_WRITE_PROPERTY_DATA * wp_data);
void testWriteProperty(
Test * pTest);
void testWritePropertyTag(
Test * pTest,
BACNET_APPLICATION_DATA_VALUE * value);
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
/** @defgroup DSWP Data Sharing - Write Property Service (DS-WP)
* @ingroup DataShare
* 15.9 WriteProperty Service <br>
* The WriteProperty service is used by a client BACnet-user to modify the
* value of a single specified property of a BACnet object. This service
* potentially allows write access to any property of any object, whether a
* BACnet-defined object or not. Some implementors may wish to restrict write
* access to certain properties of certain objects. In such cases, an attempt
* to modify a restricted property shall result in the return of an error of
* 'Error Class' PROPERTY and 'Error Code' WRITE_ACCESS_DENIED.
*/
#endif
+111
View File
@@ -0,0 +1,111 @@
/**************************************************************************
*
* 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.
*
*********************************************************************/
#ifndef WRITEPROPERTYMULTIPLE_H
#define WRITEPROPERTYMULTIPLE_H
#include <stdint.h>
#include <stdbool.h>
#include "bacdcode.h"
#include "bacapp.h"
#include "wp.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
struct BACnet_Write_Access_Data;
typedef struct BACnet_Write_Access_Data {
BACNET_OBJECT_TYPE object_type;
uint32_t object_instance;
/* simple linked list of values */
BACNET_PROPERTY_VALUE *listOfProperties;
struct BACnet_Write_Access_Data *next;
} BACNET_WRITE_ACCESS_DATA;
/* decode the service request only */
int wpm_decode_object_id(
uint8_t * apdu,
uint16_t apdu_len,
BACNET_WRITE_PROPERTY_DATA * data);
int wpm_decode_object_property(
uint8_t * apdu,
uint16_t apdu_len,
BACNET_WRITE_PROPERTY_DATA * wpm_data);
/* encode objects */
int wpm_encode_apdu_init(
uint8_t * apdu,
uint8_t invoke_id);
int wpm_encode_apdu_object_begin(
uint8_t * apdu,
BACNET_OBJECT_TYPE object_type,
uint32_t object_instance);
int wpm_encode_apdu_object_end(
uint8_t * apdu);
int wpm_encode_apdu_object_property(
uint8_t * apdu,
BACNET_WRITE_PROPERTY_DATA * wpdata);
int wpm_encode_apdu(
uint8_t * apdu,
size_t max_apdu,
uint8_t invoke_id,
BACNET_WRITE_ACCESS_DATA * write_access_data);
/* encode service */
int wpm_ack_encode_apdu_init(
uint8_t * apdu,
uint8_t invoke_id);
int wpm_error_ack_encode_apdu(
uint8_t * apdu,
uint8_t invoke_id,
BACNET_WRITE_PROPERTY_DATA * wp_data);
#ifdef __cplusplus
}
#endif /* __cplusplus */
/** @defgroup DSWP Data Sharing - Write Property Multiple Service (DS-WPM)
* @ingroup DataShare
* 15.10 WriteProperty Multiple Service <br>
* The WritePropertyMultiple service is used by a client BACnet-user
* to modify the value of one or more specified properties of a BACnet object.
* This service potentially allows write access to any property of any object,
* whether a BACnet-defined object or not.
* Properties shall be modified by the WritePropertyMultiple service
* in the order specified in the 'List of Write Access Specifications' parameter,
* and execution of the service shall continue until all of the specified
* properties have been written to or a property is encountered that
* for some reason cannot be modified as requested.
* Some implementors may wish to restrict write access to certain properties
* of certain objects. In such cases, an attempt to modify a restricted property
* shall result in the return of an error of 'Error Class' PROPERTY and 'Error Code'
* WRITE_ACCESS_DENIED. Note that these restricted properties may be accessible
* through the use of Virtual Terminal services or other means at the discretion
* of the implementor.
*/
#endif