Skip to content

Commit

Permalink
mesh: Add virtual address before using it
Browse files Browse the repository at this point in the history
Virtual address behavior has been changed in this PR:
zephyrproject-rtos/zephyr#57878

Now it requires label uuid to be added before any message can be sent
and desired uuid should be passed to message context structure before
sending a message to a virtual address.

This change should fix MESH/NODE/NET/BV-02-C and MESH/NODE/TNPT/BV-05-C
failing tests.

For MESH/NODE/NET/BV-02-C the virtual address is added on hdl_wid_21 as
PTS asks the stack to provide known virtual address.

For MESH/NODE/TNPT/BV-05-C PTS gives the label uuid in the message,
therefore we need to add this address first before sending a message to
it.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
  • Loading branch information
PavelVPV committed Jun 21, 2023
1 parent 5cc20ed commit 298b2ff
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
39 changes: 39 additions & 0 deletions autopts/pybtp/btp/mesh.py
Expand Up @@ -250,6 +250,12 @@
"provision_adv": (defs.BTP_SERVICE_ID_MESH,
defs.MESH_PROVISION_ADV,
CONTROLLER_INDEX),
"va_add": (defs.BTP_SERVICE_ID_MESH,
defs.MESH_VA_ADD,
CONTROLLER_INDEX),
"va_del": (defs.BTP_SERVICE_ID_MESH,
defs.MESH_VA_DEL,
CONTROLLER_INDEX),
}


Expand Down Expand Up @@ -426,6 +432,39 @@ def mesh_net_send(ttl, src, dst, payload):
iutctl.btp_socket.send_wait_rsp(*MESH['net_send'], data=data)


def mesh_va_add(label):
logging.debug("%s %r", mesh_va_add.__name__, label)

label = binascii.unhexlify(label)

if len(label) != 16:
raise BTPError("Label UUID length is invalid")

data = bytearray(struct.pack("<"))
data.extend(label)

iutctl = get_iut()
(rsp,) = iutctl.btp_socket.send_wait_rsp(*MESH['va_add'], data=data)

(virtual_addr,) = struct.unpack_from('<H', rsp)
return int(virtual_addr)


def mesh_va_del(label):
logging.debug("%s %r", mesh_va_del.__name__, label)

label = binascii.unhexlify(label)

if len(label) != 16:
raise BTPError("Label UUID length is invalid")

data = bytearray(struct.pack("<"))
data.extend(label)

iutctl = get_iut()
iutctl.btp_socket.send_wait_rsp(*MESH['va_del'], data=data)


def mesh_health_generate_faults():
logging.debug("%s", mesh_health_generate_faults.__name__)

Expand Down
2 changes: 2 additions & 0 deletions autopts/pybtp/defs.py
Expand Up @@ -308,6 +308,8 @@
MESH_PROVISION_ADV = 0x4A
MESH_CFG_KRP_GET = 0x4B
MESH_CFG_KRP_SET = 0x4C
MESH_VA_ADD = 0x4D
MESH_VA_DEL = 0x4E
MESH_EV_OUT_NUMBER_ACTION = 0x80
MESH_EV_OUT_STRING_ACTION = 0x81
MESH_EV_IN_ACTION = 0x82
Expand Down
19 changes: 18 additions & 1 deletion autopts/wid/mesh.py
Expand Up @@ -248,7 +248,12 @@ def hdl_wid_21(_: WIDParams):
Implements: ENTER_VIRTUAL_ADDRESS
description: Please enter a valid virtual address the IUT knows
"""
return '8000'

# Should generate virtual address 0x8000
addr = btp.mesh_va_add('f5f4ca5e1d710dc6f9fa1bd4c32ca61e')

logging.debug("Virtual address = %r", addr)
return f'{addr:x}'


def hdl_wid_22(params: WIDParams):
Expand Down Expand Up @@ -573,9 +578,21 @@ def hdl_wid_44(params: WIDParams):

params = dict(params)

# Add virtual address before sending a message. If it was added before, reference will be
# incremented.
addr = btp.mesh_va_add(value)
if (addr != int(params.get('(address'), 16)):
logging.error("%s Generated virtual address (%s) doesn't match the provided one (%s)",
hdl_wid_44.__name__, addr, int(params.get('(address'), 16))
return False

btp.mesh_model_send(int(params.get('source address'), 16),
int(params.get('(address'), 16),
value)

# Remove virtual address after sending a message. If it was added before, reference will be
# decremented.
btp.mesh_va_del(value)
return True


Expand Down

0 comments on commit 298b2ff

Please sign in to comment.