Performed standard indent script indent.sh on project files.

This commit is contained in:
skarg
2010-12-15 19:02:40 +00:00
parent f820697464
commit 2a0bf4926a
107 changed files with 974 additions and 1033 deletions
+4 -5
View File
@@ -346,9 +346,8 @@ static bool cov_send_request(
value_list[1].next = NULL;
switch (cov_subscription->monitoredObjectIdentifier.type) {
case OBJECT_BINARY_INPUT:
Binary_Input_Encode_Value_List
(cov_subscription->monitoredObjectIdentifier.instance,
&value_list[0]);
Binary_Input_Encode_Value_List(cov_subscription->
monitoredObjectIdentifier.instance, &value_list[0]);
break;
default:
goto COV_FAILED;
@@ -465,8 +464,8 @@ static bool cov_subscribe(
switch (cov_data->monitoredObjectIdentifier.type) {
case OBJECT_BINARY_INPUT:
if (Binary_Input_Valid_Instance
(cov_data->monitoredObjectIdentifier.instance)) {
if (Binary_Input_Valid_Instance(cov_data->
monitoredObjectIdentifier.instance)) {
status =
cov_list_subscribe(src, cov_data, error_class, error_code);
} else {
+67 -71
View File
@@ -67,9 +67,9 @@
*/
static void network_control_handler(
BACNET_ADDRESS * src,
int * DNET_list,
int *DNET_list,
BACNET_NPDU_DATA * npdu_data,
uint8_t * npdu,
uint8_t * npdu,
uint16_t npdu_len)
{
uint16_t npdu_offset = 0;
@@ -78,23 +78,19 @@ static void network_control_handler(
switch (npdu_data->network_message_type) {
case NETWORK_MESSAGE_WHO_IS_ROUTER_TO_NETWORK:
/* Send I-am-router-to-network with our one-network list if
* our specific network is requested, or no specific
* network is requested. Silently drop other DNET requests.
*/
if (npdu_len >= 2)
{
uint16_t network;
len += decode_unsigned16(&npdu[len], &network);
if (network == DNET_list[0] )
{
Send_I_Am_Router_To_Network( DNET_list );
}
}
else
{
Send_I_Am_Router_To_Network( DNET_list );
}
/* Send I-am-router-to-network with our one-network list if
* our specific network is requested, or no specific
* network is requested. Silently drop other DNET requests.
*/
if (npdu_len >= 2) {
uint16_t network;
len += decode_unsigned16(&npdu[len], &network);
if (network == DNET_list[0]) {
Send_I_Am_Router_To_Network(DNET_list);
}
} else {
Send_I_Am_Router_To_Network(DNET_list);
}
break;
case NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK:
/* Per the standard, we are supposed to process this message and
@@ -108,9 +104,9 @@ static void network_control_handler(
* -- Unless we act upon NETWORK_MESSAGE_ROUTER_BUSY_TO_NETWORK
* later for congestion control - then it could matter.
*/
debug_printf("%s for Networks: ",
bactext_network_layer_msg_name(
NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK ) );
debug_printf("%s for Networks: ",
bactext_network_layer_msg_name
(NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK));
while (npdu_len) {
len = decode_unsigned16(&npdu[npdu_offset], &dnet);
debug_printf("%hu", dnet);
@@ -126,12 +122,12 @@ static void network_control_handler(
/* Do nothing, same as previous case. */
break;
case NETWORK_MESSAGE_REJECT_MESSAGE_TO_NETWORK:
if ( npdu_len >= 3 ) {
if (npdu_len >= 3) {
decode_unsigned16(&npdu[1], &dnet);
debug_printf("Received %s for Network: ",
bactext_network_layer_msg_name(
NETWORK_MESSAGE_I_COULD_BE_ROUTER_TO_NETWORK ) );
debug_printf("%hu, Reason code: %d \n", dnet, npdu[0] );
bactext_network_layer_msg_name
(NETWORK_MESSAGE_I_COULD_BE_ROUTER_TO_NETWORK));
debug_printf("%hu, Reason code: %d \n", dnet, npdu[0]);
}
break;
case NETWORK_MESSAGE_ROUTER_BUSY_TO_NETWORK:
@@ -143,18 +139,18 @@ static void network_control_handler(
* NETWORK_MESSAGE_INIT_RT_TABLE_ACK and a list of all our
* reachable networks.
*/
if ( npdu_len > 0) {
/* If Number of Ports is 0, broadcast our "full" table */
if (npdu[0] == 0)
Send_Initialize_Routing_Table_Ack( NULL, DNET_list );
else {
/* If they sent us a list, just politely ACK it
* with no routing list of our own. But we don't DO
* anything with the info, either.
*/
int listTerminator = -1;
Send_Initialize_Routing_Table_Ack( src, &listTerminator );
}
if (npdu_len > 0) {
/* If Number of Ports is 0, broadcast our "full" table */
if (npdu[0] == 0)
Send_Initialize_Routing_Table_Ack(NULL, DNET_list);
else {
/* If they sent us a list, just politely ACK it
* with no routing list of our own. But we don't DO
* anything with the info, either.
*/
int listTerminator = -1;
Send_Initialize_Routing_Table_Ack(src, &listTerminator);
}
break;
}
/* Else, fall through to do nothing. */
@@ -168,9 +164,9 @@ static void network_control_handler(
break;
default:
/* An unrecognized message is bad; send an error response. */
Send_Reject_Message_To_Network( src,
NETWORK_REJECT_UNKNOWN_MESSAGE_TYPE, DNET_list[0] );
/* Sending our DNET doesn't make a lot of sense, does it? */
Send_Reject_Message_To_Network(src,
NETWORK_REJECT_UNKNOWN_MESSAGE_TYPE, DNET_list[0]);
/* Sending our DNET doesn't make a lot of sense, does it? */
break;
}
}
@@ -190,31 +186,32 @@ static void network_control_handler(
* Normally just one valid entry; terminated with a -1 value.
* @param apdu [in] The apdu portion of the request, to be processed.
* @param apdu_len [in] The total (remaining) length of the apdu.
*/
*/
static void routed_apdu_handler(
BACNET_ADDRESS * src,
BACNET_ADDRESS * src,
BACNET_ADDRESS * dest,
int * DNET_list,
uint8_t * apdu,
int *DNET_list,
uint8_t * apdu,
uint16_t apdu_len)
{
int cursor = 0; /* Starting hint */
{
int cursor = 0; /* Starting hint */
bool bGotOne = false;
if (!Routed_Device_Is_Valid_Network( dest->net, DNET_list ) ) {
if (!Routed_Device_Is_Valid_Network(dest->net, DNET_list)) {
/* We don't know how to reach this one */
Send_Reject_Message_To_Network( src, NETWORK_REJECT_NO_ROUTE, dest->net );
Send_Reject_Message_To_Network(src, NETWORK_REJECT_NO_ROUTE,
dest->net);
return;
}
while ( Routed_Device_GetNext( dest, DNET_list, &cursor ) ) {
apdu_handler(src, apdu, apdu_len);
bGotOne = true;
if ( cursor < 0 ) /* If no more matches, */
break; /* We don't need to keep looking */
while (Routed_Device_GetNext(dest, DNET_list, &cursor)) {
apdu_handler(src, apdu, apdu_len);
bGotOne = true;
if (cursor < 0) /* If no more matches, */
break; /* We don't need to keep looking */
}
if ( !bGotOne ) {
/* Just silently drop this packet. */
if (!bGotOne) {
/* Just silently drop this packet. */
}
}
@@ -249,10 +246,10 @@ static void routed_apdu_handler(
*/
void routing_npdu_handler(
BACNET_ADDRESS * src,
int * DNET_list,
uint8_t * pdu,
int *DNET_list,
uint8_t * pdu,
uint16_t pdu_len)
{
{
int apdu_offset = 0;
BACNET_ADDRESS dest = { 0 };
BACNET_NPDU_DATA npdu_data = { 0 };
@@ -260,29 +257,28 @@ void routing_npdu_handler(
/* only handle the version that we know how to handle */
if (pdu[0] == BACNET_PROTOCOL_VERSION) {
apdu_offset = npdu_decode(&pdu[0], &dest, src, &npdu_data);
if ( apdu_offset <= 0 ) {
if (apdu_offset <= 0) {
debug_printf("NPDU: Decoding failed; Discarded!\n");
} else if (npdu_data.network_layer_message) {
if ((dest.net == 0) || (dest.net == BACNET_BROADCAST_NETWORK)) {
network_control_handler( src, DNET_list, &npdu_data,
&pdu[apdu_offset],
(uint16_t) (pdu_len - apdu_offset));
network_control_handler(src, DNET_list, &npdu_data,
&pdu[apdu_offset], (uint16_t) (pdu_len - apdu_offset));
} else {
/* The DNET is set, but we don't support downstream routers,
* so we just silently drop this network layer message,
* since only routers can handle it (even if for our DNET) */
}
} else if (apdu_offset <= pdu_len) {
if ( (dest.net == 0) || (npdu_data.hop_count > 1) )
routed_apdu_handler(src, &dest, DNET_list, &pdu[apdu_offset],
(uint16_t) (pdu_len - apdu_offset));
/* Else, hop_count bottomed out and we discard this one. */
if ((dest.net == 0) || (npdu_data.hop_count > 1))
routed_apdu_handler(src, &dest, DNET_list, &pdu[apdu_offset],
(uint16_t) (pdu_len - apdu_offset));
/* Else, hop_count bottomed out and we discard this one. */
}
} else {
/* Should we send NETWORK_MESSAGE_REJECT_MESSAGE_TO_NETWORK? */
debug_printf(
"NPDU: Unsupported BACnet Protocol Version=%u. Discarded!\n",
(unsigned) pdu[0]);
debug_printf
("NPDU: Unsupported BACnet Protocol Version=%u. Discarded!\n",
(unsigned) pdu[0]);
}
return;
+2 -2
View File
@@ -170,7 +170,7 @@ int rp_ack_fully_decode_service_request(
read_access_data->listOfProperties = rp1_property;
if (rp1_property == NULL) {
/* can't proceed if calloc failed. */
return BACNET_STATUS_ERROR;
return BACNET_STATUS_ERROR;
}
rp1_property->propertyIdentifier = rp1data.object_property;
rp1_property->propertyArrayIndex = rp1data.array_index;
@@ -227,7 +227,7 @@ int rp_ack_fully_decode_service_request(
read_access_data->listOfProperties = NULL;
return BACNET_STATUS_ERROR;
}
if (vlen > 0) {
if (vlen > 0) {
/* If more values */
old_value = value;
value = calloc(1, sizeof(BACNET_APPLICATION_DATA_VALUE));
+6 -6
View File
@@ -220,8 +220,8 @@ void rpm_ack_print_data(
#if PRINT_ENABLED
if (listOfProperties->propertyIdentifier < 512) {
fprintf(stdout, " %s: ",
bactext_property_name(listOfProperties->
propertyIdentifier));
bactext_property_name
(listOfProperties->propertyIdentifier));
} else {
fprintf(stdout, " proprietary %u: ",
(unsigned) listOfProperties->propertyIdentifier);
@@ -268,10 +268,10 @@ void rpm_ack_print_data(
#if PRINT_ENABLED
/* AccessError */
fprintf(stdout, "BACnet Error: %s: %s\r\n",
bactext_error_class_name((int) listOfProperties->
error.error_class),
bactext_error_code_name((int) listOfProperties->
error.error_code));
bactext_error_class_name((int) listOfProperties->error.
error_class),
bactext_error_code_name((int) listOfProperties->error.
error_code));
#endif
}
listOfProperties = listOfProperties->next;
+2 -2
View File
@@ -104,8 +104,8 @@ void handler_ucov_notification(
fprintf(stderr, "UCOV: ");
if (pProperty_value->propertyIdentifier < 512) {
fprintf(stderr, "%s ",
bactext_property_name
(pProperty_value->propertyIdentifier));
bactext_property_name(pProperty_value->
propertyIdentifier));
} else {
fprintf(stderr, "proprietary %u ",
pProperty_value->propertyIdentifier);
+15 -15
View File
@@ -42,8 +42,8 @@
* or object ID, if the Device has a match.
* @param data [in] The decoded who-has payload from the request.
*/
static void match_name_or_object(
BACNET_WHO_HAS_DATA * data)
static void match_name_or_object(
BACNET_WHO_HAS_DATA * data)
{
char *object_name = NULL;
int object_type = 0;
@@ -98,10 +98,10 @@ void handler_who_has(
if ((data.low_limit == -1) || (data.high_limit == -1))
directed_to_me = true;
else if ((Device_Object_Instance_Number() >= (uint32_t) data.low_limit)
&& (Device_Object_Instance_Number() <= (uint32_t) data.high_limit))
&& (Device_Object_Instance_Number() <= (uint32_t) data.high_limit))
directed_to_me = true;
if (directed_to_me) {
match_name_or_object(&data);
match_name_or_object(&data);
}
}
}
@@ -126,23 +126,23 @@ void handler_who_has_for_routing(
int len = 0;
BACNET_WHO_HAS_DATA data;
int32_t dev_instance;
int cursor = 0; /* Starting hint */
int my_list[2] = {0, -1}; /* Not really used, so dummy values */
int cursor = 0; /* Starting hint */
int my_list[2] = { 0, -1 }; /* Not really used, so dummy values */
BACNET_ADDRESS bcast_net;
(void) src;
len = whohas_decode_service_request(service_request, service_len, &data);
if (len > 0) {
/* Go through all devices, starting with the root gateway Device */
memset( &bcast_net, 0, sizeof(BACNET_ADDRESS));
bcast_net.net = BACNET_BROADCAST_NETWORK; /* That's all we have to set */
while ( Routed_Device_GetNext( &bcast_net, my_list, &cursor ) ) {
dev_instance = Device_Object_Instance_Number();
if ( (data.low_limit == -1) || (data.high_limit == -1) ||
((dev_instance >= data.low_limit) &&
(dev_instance <= data.high_limit)))
match_name_or_object(&data);
memset(&bcast_net, 0, sizeof(BACNET_ADDRESS));
bcast_net.net = BACNET_BROADCAST_NETWORK; /* That's all we have to set */
while (Routed_Device_GetNext(&bcast_net, my_list, &cursor)) {
dev_instance = Device_Object_Instance_Number();
if ((data.low_limit == -1) || (data.high_limit == -1) ||
((dev_instance >= data.low_limit) &&
(dev_instance <= data.high_limit)))
match_name_or_object(&data);
}
}
}
#endif /* BAC_ROUTING */
#endif /* BAC_ROUTING */
+24 -24
View File
@@ -127,44 +127,44 @@ static void check_who_is_for_routing(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src,
bool is_unicast )
bool is_unicast)
{
int len = 0;
int32_t low_limit = 0;
int32_t high_limit = 0;
int32_t dev_instance;
int cursor = 0; /* Starting hint */
int my_list[2] = {0, -1}; /* Not really used, so dummy values */
int cursor = 0; /* Starting hint */
int my_list[2] = { 0, -1 }; /* Not really used, so dummy values */
BACNET_ADDRESS bcast_net;
len =
whois_decode_service_request(service_request, service_len, &low_limit,
&high_limit);
if (len == -1) {
/* Invalid; just leave */
return;
/* Invalid; just leave */
return;
}
/* If len == 0, then high_limit is untouched and still == 0 */
/* BACnet wildcard is the max instance number - everyone responds */
if ((BACNET_MAX_INSTANCE >= (uint32_t) low_limit) &&
(BACNET_MAX_INSTANCE <= (uint32_t) high_limit))
high_limit = 0;
/* This is the "always accept" case we will test for below */
high_limit = 0;
/* This is the "always accept" case we will test for below */
/* Go through all devices, starting with the root gateway Device */
memset( &bcast_net, 0, sizeof(BACNET_ADDRESS));
bcast_net.net = BACNET_BROADCAST_NETWORK; /* That's all we have to set */
while ( Routed_Device_GetNext( &bcast_net, my_list, &cursor ) ) {
dev_instance = Device_Object_Instance_Number();
if ( (high_limit == 0) ||
((dev_instance >= low_limit) && (dev_instance <= high_limit))) {
if ( is_unicast )
Send_I_Am_Unicast(&Handler_Transmit_Buffer[0], src);
else
Send_I_Am(&Handler_Transmit_Buffer[0]);
}
}
memset(&bcast_net, 0, sizeof(BACNET_ADDRESS));
bcast_net.net = BACNET_BROADCAST_NETWORK; /* That's all we have to set */
while (Routed_Device_GetNext(&bcast_net, my_list, &cursor)) {
dev_instance = Device_Object_Instance_Number();
if ((high_limit == 0) || ((dev_instance >= low_limit) &&
(dev_instance <= high_limit))) {
if (is_unicast)
Send_I_Am_Unicast(&Handler_Transmit_Buffer[0], src);
else
Send_I_Am(&Handler_Transmit_Buffer[0]);
}
}
}
@@ -185,7 +185,7 @@ void handler_who_is_bcast_for_routing(
uint16_t service_len,
BACNET_ADDRESS * src)
{
check_who_is_for_routing(service_request, service_len, src, false );
check_who_is_for_routing(service_request, service_len, src, false);
}
@@ -205,6 +205,6 @@ void handler_who_is_unicast_for_routing(
uint16_t service_len,
BACNET_ADDRESS * src)
{
check_who_is_for_routing(service_request, service_len, src, true );
check_who_is_for_routing(service_request, service_len, src, true);
}
#endif /* BAC_ROUTING */
#endif /* BAC_ROUTING */
+3 -4
View File
@@ -178,12 +178,11 @@ bool WPValidateString(
0)) {
*pErrorCode = ERROR_CODE_VALUE_OUT_OF_RANGE;
} else if ((bEmptyAllowed == false) &&
(!characterstring_printable(
&pValue->type.Character_String))) {
(!characterstring_printable(&pValue->type.Character_String))) {
/* assumption: non-empty also means must be "printable" */
*pErrorCode = ERROR_CODE_VALUE_OUT_OF_RANGE;
} else if (characterstring_length(&pValue->
type.Character_String) >= iMaxLen) {
} else if (characterstring_length(&pValue->type.
Character_String) >= iMaxLen) {
*pErrorClass = ERROR_CLASS_RESOURCES;
*pErrorCode = ERROR_CODE_NO_SPACE_TO_WRITE_PROPERTY;
} else
+1 -1
View File
@@ -70,7 +70,7 @@ uint8_t Send_CEvent_Notify(
invoke_id = tsm_next_free_invokeID();
if (invoke_id) {
/* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address);
datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address,
+5 -3
View File
@@ -65,7 +65,8 @@ int iam_encode_pdu(
pdu_len = npdu_encode_pdu(&buffer[0], dest, &my_address, npdu_data);
/* encode the APDU portion of the packet */
len = iam_encode_apdu(&buffer[pdu_len], Device_Object_Instance_Number(),
len =
iam_encode_apdu(&buffer[pdu_len], Device_Object_Instance_Number(),
MAX_APDU, SEGMENTATION_NONE, Device_Vendor_Identifier());
pdu_len += len;
@@ -139,8 +140,9 @@ int iam_unicast_encode_pdu(
npdu_encode_npdu_data(npdu_data, false, MESSAGE_PRIORITY_NORMAL);
npdu_len = npdu_encode_pdu(&buffer[0], dest, &my_address, npdu_data);
/* encode the APDU portion of the packet */
apdu_len = iam_encode_apdu(&buffer[npdu_len], Device_Object_Instance_Number(),
MAX_APDU, SEGMENTATION_NONE, Device_Vendor_Identifier());
apdu_len =
iam_encode_apdu(&buffer[npdu_len], Device_Object_Instance_Number(),
MAX_APDU, SEGMENTATION_NONE, Device_Vendor_Identifier());
pdu_len = npdu_len + apdu_len;
return pdu_len;
+3 -1
View File
@@ -75,7 +75,9 @@ void Send_I_Have(
datalink_get_broadcast_address(&dest);
/* encode the NPDU portion of the packet */
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address, &npdu_data);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address,
&npdu_data);
/* encode the APDU portion of the packet */
data.device_id.type = OBJECT_DEVICE;
+103 -105
View File
@@ -71,7 +71,7 @@ static void npdu_encode_npdu_network(
npdu_data->network_message_type = network_message_type; /* optional */
npdu_data->vendor_id = 0; /* optional, if net message type is > 0x80 */
npdu_data->priority = priority;
npdu_data->hop_count = DFLT_HOP_COUNT;
npdu_data->hop_count = DFLT_HOP_COUNT;
}
}
@@ -97,119 +97,117 @@ static void npdu_encode_npdu_network(
* the type of message.
* @return Number of bytes sent, or <=0 if no message was sent.
*/
int Send_Network_Layer_Message(
BACNET_NETWORK_MESSAGE_TYPE network_message_type,
BACNET_ADDRESS * dst,
int * iArgs )
int Send_Network_Layer_Message(
BACNET_NETWORK_MESSAGE_TYPE network_message_type,
BACNET_ADDRESS * dst,
int *iArgs)
{
int len = 0;
int pdu_len = 0;
int bytes_sent = 0;
int *pVal = iArgs; /* Start with first value */
int *pVal = iArgs; /* Start with first value */
bool data_expecting_reply = false;
BACNET_NPDU_DATA npdu_data;
BACNET_ADDRESS bcastDest;
if ( iArgs == NULL )
return 0; /* Can't do anything here */
if (iArgs == NULL)
return 0; /* Can't do anything here */
/* If dst was NULL, get our (local net) broadcast MAC address. */
if ( dst == NULL ) {
datalink_get_broadcast_address(&bcastDest);
dst = &bcastDest;
if (dst == NULL) {
datalink_get_broadcast_address(&bcastDest);
dst = &bcastDest;
}
if ( network_message_type == NETWORK_MESSAGE_INIT_RT_TABLE )
if (network_message_type == NETWORK_MESSAGE_INIT_RT_TABLE)
data_expecting_reply = true; /* DER in this one case */
npdu_encode_npdu_network(&npdu_data,
network_message_type, data_expecting_reply,
MESSAGE_PRIORITY_NORMAL);
npdu_encode_npdu_network(&npdu_data, network_message_type,
data_expecting_reply, MESSAGE_PRIORITY_NORMAL);
/* We don't need src information, since a message can't originate from
* our downstream BACnet network.
*/
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], dst, NULL, &npdu_data);
/* Now encode the optional payload bytes, per message type */
switch ( network_message_type )
{
case NETWORK_MESSAGE_WHO_IS_ROUTER_TO_NETWORK:
if (*pVal >= 0) {
len =
encode_unsigned16(&Handler_Transmit_Buffer[pdu_len],
(uint16_t) *pVal);
pdu_len += len;
}
/* else, don't encode a DNET */
break;
case NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK:
case NETWORK_MESSAGE_ROUTER_BUSY_TO_NETWORK:
case NETWORK_MESSAGE_ROUTER_AVAILABLE_TO_NETWORK:
while ( *pVal >= 0 ) {
len =
encode_unsigned16(&Handler_Transmit_Buffer[pdu_len],
(uint16_t) *pVal);
pdu_len += len;
pVal++;
}
break;
case NETWORK_MESSAGE_REJECT_MESSAGE_TO_NETWORK:
/* Encode the Reason byte, then the DNET */
Handler_Transmit_Buffer[pdu_len++] = (uint8_t) *pVal;
pVal++;
len =
encode_unsigned16(&Handler_Transmit_Buffer[pdu_len],
(uint16_t) *pVal);
pdu_len += len;
break;
case NETWORK_MESSAGE_INIT_RT_TABLE:
case NETWORK_MESSAGE_INIT_RT_TABLE_ACK:
/* First, count the number of Ports we will encode */
len = 0; /* Re-purpose len as our counter here */
while ( *pVal >= 0 ) {
len++;
pVal++;
}
Handler_Transmit_Buffer[pdu_len++] = (uint8_t) len;
if ( len > 0 ) {
uint8_t portID = 1;
pVal = iArgs; /* Reset to beginning */
/* Now encode each (virtual) BACNET_ROUTER_PORT.
* We will simply use a positive index for PortID,
* and have no PortInfo.
*/
while ( *pVal >= 0 ) {
/* Now encode the optional payload bytes, per message type */
switch (network_message_type) {
case NETWORK_MESSAGE_WHO_IS_ROUTER_TO_NETWORK:
if (*pVal >= 0) {
len =
encode_unsigned16(&Handler_Transmit_Buffer[pdu_len],
(uint16_t) *pVal);
(uint16_t) * pVal);
pdu_len += len;
}
/* else, don't encode a DNET */
break;
case NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK:
case NETWORK_MESSAGE_ROUTER_BUSY_TO_NETWORK:
case NETWORK_MESSAGE_ROUTER_AVAILABLE_TO_NETWORK:
while (*pVal >= 0) {
len =
encode_unsigned16(&Handler_Transmit_Buffer[pdu_len],
(uint16_t) * pVal);
pdu_len += len;
Handler_Transmit_Buffer[pdu_len++] = portID++;
Handler_Transmit_Buffer[pdu_len++] = 0;
debug_printf( " Sending Routing Table entry for %u \n", *pVal );
pVal++;
}
}
break;
default:
debug_printf("Not sent: %s message unsupported \n",
bactext_network_layer_msg_name( network_message_type ) );
return 0;
break; /* Will never reach this line */
break;
case NETWORK_MESSAGE_REJECT_MESSAGE_TO_NETWORK:
/* Encode the Reason byte, then the DNET */
Handler_Transmit_Buffer[pdu_len++] = (uint8_t) * pVal;
pVal++;
len =
encode_unsigned16(&Handler_Transmit_Buffer[pdu_len],
(uint16_t) * pVal);
pdu_len += len;
break;
case NETWORK_MESSAGE_INIT_RT_TABLE:
case NETWORK_MESSAGE_INIT_RT_TABLE_ACK:
/* First, count the number of Ports we will encode */
len = 0; /* Re-purpose len as our counter here */
while (*pVal >= 0) {
len++;
pVal++;
}
Handler_Transmit_Buffer[pdu_len++] = (uint8_t) len;
if (len > 0) {
uint8_t portID = 1;
pVal = iArgs; /* Reset to beginning */
/* Now encode each (virtual) BACNET_ROUTER_PORT.
* We will simply use a positive index for PortID,
* and have no PortInfo.
*/
while (*pVal >= 0) {
len =
encode_unsigned16(&Handler_Transmit_Buffer[pdu_len],
(uint16_t) * pVal);
pdu_len += len;
Handler_Transmit_Buffer[pdu_len++] = portID++;
Handler_Transmit_Buffer[pdu_len++] = 0;
debug_printf(" Sending Routing Table entry for %u \n",
*pVal);
pVal++;
}
}
break;
default:
debug_printf("Not sent: %s message unsupported \n",
bactext_network_layer_msg_name(network_message_type));
return 0;
break; /* Will never reach this line */
}
if ( dst != NULL )
debug_printf("Sending %s message to BACnet network %u \n",
bactext_network_layer_msg_name( network_message_type ),
dst->net );
if (dst != NULL)
debug_printf("Sending %s message to BACnet network %u \n",
bactext_network_layer_msg_name(network_message_type), dst->net);
else
debug_printf("Sending %s message to local BACnet network \n",
bactext_network_layer_msg_name( network_message_type ) );
debug_printf("Sending %s message to local BACnet network \n",
bactext_network_layer_msg_name(network_message_type));
/* Now send the message */
bytes_sent =
@@ -217,13 +215,13 @@ int Send_Network_Layer_Message(
pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0) {
int wasErrno = errno; /* preserve the errno */
debug_printf("Failed to send %s message (%s)!\n",
bactext_network_layer_msg_name( network_message_type ),
int wasErrno = errno; /* preserve the errno */
debug_printf("Failed to send %s message (%s)!\n",
bactext_network_layer_msg_name(network_message_type),
strerror(wasErrno));
}
#endif
return bytes_sent;
return bytes_sent;
}
@@ -242,8 +240,8 @@ void Send_Who_Is_Router_To_Network(
BACNET_ADDRESS * dst,
int dnet)
{
Send_Network_Layer_Message( NETWORK_MESSAGE_WHO_IS_ROUTER_TO_NETWORK,
dst, &dnet );
Send_Network_Layer_Message(NETWORK_MESSAGE_WHO_IS_ROUTER_TO_NETWORK, dst,
&dnet);
}
/** Broadcast an I-am-router-to-network message, giving the list of networks
@@ -259,8 +257,8 @@ void Send_I_Am_Router_To_Network(
const int DNET_list[])
{
/* Use a NULL dst here since we want a broadcast MAC address. */
Send_Network_Layer_Message( NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK,
NULL, (int *) DNET_list );
Send_Network_Layer_Message(NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK, NULL,
(int *) DNET_list);
}
/** Finds a specific router, or all reachable BACnet networks.
@@ -281,9 +279,9 @@ void Send_Reject_Message_To_Network(
int iArgs[2];
iArgs[0] = reject_reason;
iArgs[1] = dnet;
Send_Network_Layer_Message( NETWORK_MESSAGE_REJECT_MESSAGE_TO_NETWORK,
dst, iArgs );
debug_printf(" Reject Reason=%d, DNET=%u\n", reject_reason, dnet );
Send_Network_Layer_Message(NETWORK_MESSAGE_REJECT_MESSAGE_TO_NETWORK, dst,
iArgs);
debug_printf(" Reject Reason=%d, DNET=%u\n", reject_reason, dnet);
}
@@ -308,8 +306,8 @@ void Send_Initialize_Routing_Table(
const int DNET_list[])
{
/* Use a NULL dst here since we want a broadcast MAC address. */
Send_Network_Layer_Message( NETWORK_MESSAGE_INIT_RT_TABLE,
dst, (int *) DNET_list );
Send_Network_Layer_Message(NETWORK_MESSAGE_INIT_RT_TABLE, dst,
(int *) DNET_list);
}
@@ -334,6 +332,6 @@ void Send_Initialize_Routing_Table_Ack(
BACNET_ADDRESS * dst,
const int DNET_list[])
{
Send_Network_Layer_Message( NETWORK_MESSAGE_INIT_RT_TABLE_ACK,
dst, (int *) DNET_list );
Send_Network_Layer_Message(NETWORK_MESSAGE_INIT_RT_TABLE_ACK, dst,
(int *) DNET_list);
}
+4 -2
View File
@@ -65,7 +65,8 @@ void Send_TimeSync(
/* encode the NPDU portion of the packet */
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address, &npdu_data);
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address,
&npdu_data);
/* encode the APDU portion of the packet */
len =
@@ -101,7 +102,8 @@ void Send_TimeSyncUTC(
/* encode the NPDU portion of the packet */
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address, &npdu_data);
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address,
&npdu_data);
/* encode the APDU portion of the packet */
pdu_len =
+3 -1
View File
@@ -61,7 +61,9 @@ void Send_UnconfirmedPrivateTransfer(
datalink_get_my_address(&my_address);
/* encode the NPDU portion of the packet */
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], dest, &my_address, &npdu_data);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], dest, &my_address,
&npdu_data);
/* encode the APDU portion of the packet */
len =
+4 -2
View File
@@ -77,7 +77,8 @@ void Send_WhoHas_Name(
/* encode the NPDU portion of the packet */
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address, &npdu_data);
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address,
&npdu_data);
/* encode the APDU portion of the packet */
data.low_limit = low_limit;
@@ -131,7 +132,8 @@ void Send_WhoHas_Object(
/* encode the NPDU portion of the packet */
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address, &npdu_data);
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address,
&npdu_data);
/* encode the APDU portion of the packet */
data.low_limit = low_limit;
+2 -1
View File
@@ -72,7 +72,8 @@ void Send_WhoIs_To_Network(
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], target_address, &my_address, &npdu_data);
npdu_encode_pdu(&Handler_Transmit_Buffer[0], target_address,
&my_address, &npdu_data);
/* encode the APDU portion of the packet */
len =
whois_encode_apdu(&Handler_Transmit_Buffer[pdu_len], low_limit,
+2 -3
View File
@@ -155,9 +155,8 @@ uint8_t Send_Write_Property_Request(
#if PRINT_ENABLED_DEBUG
fprintf(stderr, "WriteProperty service: " "%s tag=%d\n",
(object_value->context_specific ? "context" : "application"),
(int) (object_value->
context_specific ? object_value->context_tag : object_value->
tag));
(int) (object_value->context_specific ? object_value->
context_tag : object_value->tag));
#endif
len = bacapp_encode_data(&application_data[apdu_len], object_value);
if ((len + apdu_len) < MAX_APDU) {