corrected defects

This commit is contained in:
skarg
2005-04-08 21:28:34 +00:00
parent 47c2286a34
commit da44de60b3
5 changed files with 40 additions and 30 deletions
+4 -8
View File
@@ -98,32 +98,28 @@ int npdu_encode_raw(
if (dest && dest->net)
{
len += encode_unsigned16(&npdu[len], dest->net);
npdu[len++] = dest->len;
// DLEN = 0 denotes broadcast MAC DADR and DADR field is absent
// DLEN > 0 specifies length of DADR field
if (dest->len)
{
npdu[len] = dest->len;
len++;
for (i = 0; i < dest->len; i++)
{
npdu[len] = dest->adr[i];
len++;
npdu[len++] = dest->adr[i];
}
}
}
if (src && src->net)
{
len += encode_unsigned16(&npdu[len], src->net);
npdu[len++] = src->len;
// SLEN = 0 denotes broadcast MAC SADR and SADR field is absent
// SLEN > 0 specifies length of SADR field
if (src->len)
{
npdu[len] = src->len;
len++;
for (i = 0; i < src->len; i++)
{
npdu[len] = src->adr[i];
len++;
npdu[len++] = src->adr[i];
}
}
}
+2 -2
View File
@@ -118,7 +118,7 @@ static int ethernet_bind(struct sockaddr *eth_addr, char *interface_name)
strerror(errno));
fprintf(stderr,
"You might need to add the following to modules.conf\n"
"(or in modutils/alias on Debian with update-modules):\n"
"(or in /etc/modutils/alias on Debian with update-modules):\n"
"alias net-pf-17 af_packet\n"
"Also, add af_packet to /etc/modules.\n"
"Then follow it by:\n"
@@ -141,7 +141,7 @@ static int ethernet_bind(struct sockaddr *eth_addr, char *interface_name)
strerror(errno));
fprintf(stderr,
"You might need to add the following to modules.conf\n"
"(or in modutils/alias on Debian with update-modules):\n"
"(or in /etc/modutils/alias on Debian with update-modules):\n"
"alias net-pf-17 af_packet\n"
"Also, add af_packet to /etc/modules.\n"
"Then follow it by:\n"
+23 -14
View File
@@ -23,7 +23,7 @@
// buffers used for transmit and receive
static uint8_t Tx_Buf[MAX_MPDU] = {0};
static uint8_t Rx_Buf[MAX_MPDU] = {0};
static uint8_t Temp_Buf[MAX_MPDU] = {0};
static uint8_t Temp_Buf[MAX_APDU] = {0};
// flag to send an I-Am
bool I_Am_Request = true;
@@ -66,17 +66,15 @@ void Send_IAm(void)
{
int pdu_len = 0;
BACNET_ADDRESS dest;
BACNET_ADDRESS src;
// I-Am is a global broadcast
ethernet_set_broadcast_address(&dest);
ethernet_get_my_address(&src);
// encode the NPDU portion of the packet
pdu_len = npdu_encode_apdu(
&Tx_Buf[0],
&dest,
&src,
NULL,
false, // true for confirmed messages
MESSAGE_PRIORITY_NORMAL);
@@ -135,6 +133,7 @@ void ReadPropertyHandler(
uint32_t object_instance;
BACNET_PROPERTY_ID object_property;
int32_t array_index;
BACNET_ADDRESS my_address;
fprintf(stderr,"Received Read-Property Request!\n");
len = rp_decode_service_request(
@@ -144,11 +143,20 @@ void ReadPropertyHandler(
&object_instance,
&object_property,
&array_index);
// prepare a reply
ethernet_get_my_address(&my_address);
// encode the NPDU portion of the packet
pdu_len = npdu_encode_apdu(
&Tx_Buf[0],
src,
&my_address,
false, // true for confirmed messages
MESSAGE_PRIORITY_NORMAL);
// bad encoding - send an abort
if (len == -1)
{
pdu_len = abort_encode_apdu(
&Tx_Buf[0],
pdu_len += abort_encode_apdu(
&Tx_Buf[pdu_len],
service_data->invoke_id,
ABORT_REASON_OTHER);
(void)ethernet_send_pdu(
@@ -159,8 +167,8 @@ void ReadPropertyHandler(
}
else if (service_data->segmented_message)
{
pdu_len = abort_encode_apdu(
&Tx_Buf[0],
pdu_len += abort_encode_apdu(
&Tx_Buf[pdu_len],
service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED);
(void)ethernet_send_pdu(
@@ -181,6 +189,7 @@ void ReadPropertyHandler(
array_index);
if (len > 0)
{
// encode the APDU portion of the packet
rp_data.object_type = object_type;
rp_data.object_instance = object_instance;
rp_data.object_property = object_property;
@@ -188,8 +197,8 @@ void ReadPropertyHandler(
rp_data.application_data = &Temp_Buf[0];
rp_data.application_data_len = len;
// FIXME: probably need a length limitation sent with encode
pdu_len = rp_ack_encode_apdu(
&Tx_Buf[0],
pdu_len += rp_ack_encode_apdu(
&Tx_Buf[pdu_len],
service_data->invoke_id,
&rp_data);
(void)ethernet_send_pdu(
@@ -200,8 +209,8 @@ void ReadPropertyHandler(
}
else
{
pdu_len = bacerror_encode_apdu(
&Tx_Buf[0],
pdu_len += bacerror_encode_apdu(
&Tx_Buf[pdu_len],
service_data->invoke_id,
SERVICE_CONFIRMED_READ_PROPERTY,
ERROR_CLASS_PROPERTY,
@@ -214,8 +223,8 @@ void ReadPropertyHandler(
}
break;
default:
pdu_len = bacerror_encode_apdu(
&Tx_Buf[0],
pdu_len += bacerror_encode_apdu(
&Tx_Buf[pdu_len],
service_data->invoke_id,
SERVICE_CONFIRMED_READ_PROPERTY,
ERROR_CLASS_OBJECT,
+3
View File
@@ -117,6 +117,8 @@ int rp_decode_service_request(
else
*array_index = BACNET_ARRAY_ALL;
}
else
*array_index = BACNET_ARRAY_ALL;
}
return len;
@@ -190,6 +192,7 @@ int rp_ack_encode_apdu(
{
apdu[apdu_len++] = data->application_data[len];
}
apdu_len += encode_closing_tag(&apdu[apdu_len], 3);
}
return apdu_len;
+8 -6
View File
@@ -53,12 +53,14 @@ int whois_encode_apdu(
if ((low_limit >= 0) && (low_limit <= BACNET_MAX_INSTANCE) &&
(high_limit >= 0) && (high_limit <= BACNET_MAX_INSTANCE))
{
len = encode_tagged_unsigned(
&apdu[apdu_len],
len = encode_context_unsigned(
&apdu[apdu_len],
0,
low_limit);
apdu_len += len;
len = encode_tagged_unsigned(
&apdu[apdu_len],
len = encode_context_unsigned(
&apdu[apdu_len],
1,
high_limit);
apdu_len += len;
}
@@ -83,7 +85,7 @@ int whois_decode_service_request(
if (apdu_len)
{
len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value);
if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT)
if (tag_number != 0)
return -1;
len += decode_unsigned(&apdu[len], len_value, &decoded_value);
if ((decoded_value >= 0) && (decoded_value <= BACNET_MAX_INSTANCE))
@@ -92,7 +94,7 @@ int whois_decode_service_request(
*pLow_limit = decoded_value;
}
len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value);
if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT)
if (tag_number != 1)
return -1;
len += decode_unsigned(&apdu[len],
len_value, &decoded_value);