Fix ReinitializeDevice service handling of optional password (#487)

* Fix ReinitializeDevice service handling of optional password

* Improve ReinitializeDevice service unit testing

---------

Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
This commit is contained in:
Steve Karg
2023-09-08 14:58:04 -05:00
committed by GitHub
parent f641aacddb
commit bd597082d2
5 changed files with 188 additions and 84 deletions
+12 -2
View File
@@ -544,8 +544,18 @@ bool Device_Reinitialize(BACNET_REINITIALIZE_DEVICE_DATA *rd_data)
{
bool status = false;
/* Note: you could use a mix of state and password to multiple things */
if (characterstring_ansi_same(&rd_data->password, Reinit_Password)) {
/* From 16.4.1.1.2 Password
This optional parameter shall be a CharacterString of up to
20 characters. For those devices that require the password as a
protection, the service request shall be denied if the parameter
is absent or if the password is incorrect. For those devices that
do not require a password, this parameter shall be ignored.*/
if (characterstring_length(&rd_data->password) > 20) {
rd_data->error_class = ERROR_CLASS_SERVICES;
rd_data->error_code = ERROR_CODE_PARAMETER_OUT_OF_RANGE;
} else if (characterstring_ansi_same(&rd_data->password, Reinit_Password)) {
/* Note: you could use a mix of state and password to
accomplish multiple things before restarting */
switch (rd_data->state) {
case BACNET_REINIT_COLDSTART:
case BACNET_REINIT_WARMSTART:
+7 -5
View File
@@ -69,11 +69,11 @@ void handler_reinitialize_device(uint8_t *service_request,
BACNET_ADDRESS *src,
BACNET_CONFIRMED_SERVICE_DATA *service_data)
{
BACNET_REINITIALIZE_DEVICE_DATA rd_data;
BACNET_REINITIALIZE_DEVICE_DATA rd_data = { 0 };
int len = 0;
int pdu_len = 0;
BACNET_NPDU_DATA npdu_data;
BACNET_ADDRESS my_address;
BACNET_NPDU_DATA npdu_data = { 0 };
BACNET_ADDRESS my_address = { 0 };
/* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address);
@@ -98,8 +98,10 @@ void handler_reinitialize_device(uint8_t *service_request,
service_request, service_len, &rd_data.state, &rd_data.password);
#if PRINT_ENABLED
if (len > 0) {
fprintf(stderr, "ReinitializeDevice: state=%u password=%s\n",
(unsigned)rd_data.state, characterstring_value(&rd_data.password));
fprintf(stderr, "ReinitializeDevice: state=%u password=%*s\n",
(unsigned)rd_data.state,
(int)characterstring_length(&rd_data.password),
characterstring_value(&rd_data.password));
} else {
fprintf(stderr, "ReinitializeDevice: Unable to decode request!\n");
}