Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dcp tests #435

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions src/common/pf_dcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1440,7 +1440,7 @@ static int pf_dcp_identify_req (
uint16_t ix;
bool first = true; /* First of the blocks */
bool match = false; /* Is it for us? */
bool filter = false; /* Is it IdentifyFilter or IdentifyAll? */
bool filter = true; /* Is it IdentifyFilter or IdentifyAll? */
uint8_t * p_src;
uint16_t src_pos = 0;
pf_ethhdr_t * p_src_ethhdr;
Expand Down Expand Up @@ -1673,18 +1673,18 @@ static int pf_dcp_identify_req (
stationname_position = src_pos;
stationname_len = src_block_len;
#endif
if (
(memcmp (p_value, &p_src[src_pos], src_block_len) == 0) &&
(p_value[src_block_len] == '\0'))
if (filter == true)
{
if (first == true)
if (
(memcmp (p_value, &p_src[src_pos], src_block_len) != 0) ||
(p_value[src_block_len] != '\0'))
{
filter = true;
match = false;
}
}
else
{
match = false;
ret = -1;
}
break;
case PF_DCP_SUB_DEV_PROP_ID:
Expand Down Expand Up @@ -1837,7 +1837,6 @@ static int pf_dcp_identify_req (
if (first == true)
{
p_req_alias_name = alias;
filter = true;
}
}
else
Expand Down
20 changes: 20 additions & 0 deletions test/test_dcp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ static uint8_t ident_req[] = {
0x73, 0x2d, 0x64, 0x65, 0x6d, 0x6f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

static uint8_t ident_by_device_id_req[] = {
0x01, 0x0e, 0xcf, 0x00, 0x00, 0x00, 0x74, 0xda, 0x38, 0xc2, 0x5e, 0xa4,
0x88, 0x92, 0xfe, 0xfe, 0x05, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00,
0x00, 0x08, 0x02, 0x03, 0x00, 0x04, 0xfe, 0xed, 0xbe, 0xef, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

static uint8_t set_name_req[] = {
0x12, 0x34, 0x00, 0x78, 0x90, 0xab, 0xc8, 0x5b, 0x76, 0xe6, 0x89, 0xdf,
0x88, 0x92, 0xfe, 0xfd, 0x04, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00,
Expand Down Expand Up @@ -140,6 +147,19 @@ TEST_F (DcpTest, DcpRunTest)
ret = pf_eth_recv (mock_os_data.eth_if_handle, net, p_buf);
EXPECT_EQ (ret, 1);

TEST_TRACE ("\nGenerating mock set ident by device id request\n");
p_buf = pnal_buf_alloc (PF_FRAME_BUFFER_SIZE);
memcpy (p_buf->payload, ident_by_device_id_req, sizeof (ident_by_device_id_req));
ret = pf_eth_recv (mock_os_data.eth_if_handle, net, p_buf);
EXPECT_EQ (ret, 1);

TEST_TRACE ("\nCheck invalid length set ident by device id request fails\n");
p_buf = pnal_buf_alloc (PF_FRAME_BUFFER_SIZE);
ident_by_device_id_req[32] = 0x01;
memcpy (p_buf->payload, ident_by_device_id_req, sizeof (ident_by_device_id_req));
ret = pf_eth_recv (mock_os_data.eth_if_handle, net, p_buf);
EXPECT_EQ (ret, 0);

atlowl marked this conversation as resolved.
Show resolved Hide resolved
TEST_TRACE ("\nGenerating mock factory reset request\n");
p_buf = pnal_buf_alloc (PF_FRAME_BUFFER_SIZE);
memcpy (p_buf->payload, factory_reset_req, sizeof (factory_reset_req));
Expand Down