Skip to content

Commit

Permalink
tlv add permissions now uses <drivernum, commandnum>
Browse files Browse the repository at this point in the history
  • Loading branch information
bradjc committed Jan 23, 2024
1 parent 852dbb6 commit 2aceb27
Showing 1 changed file with 31 additions and 12 deletions.
43 changes: 31 additions & 12 deletions tockloader/tbfh.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,8 @@ def object(self):

class TBFTLVPermissions(TBFTLV):
TLVID = TBFTLV.HEADER_TYPE_PERMISSIONS
NUMBER_PARAMETERS = 3
NUMBER_PARAMETERS = 2
PARAMETER_HELP = "<driver_numer> <command_number>"

def __init__(self, buffer, parameters=[]):
self.valid = False
Expand All @@ -406,11 +407,16 @@ def __init__(self, buffer, parameters=[]):
self.valid = True
else:
try:
if len(parameters) == 3:
if len(parameters) == 2:
driver_number = int(parameters[0], 0)
command_number = int(parameters[1], 0)
offset = command_number // 64
index = command_number - (offset * 64)

permission = {
"driver_number": int(parameters[0], 0),
"offset": int(parameters[1], 0),
"allowed_commands": int(parameters[2], 0),
"driver_number": driver_number,
"offset": offset,
"allowed_commands": (1 << index),
}
self.permissions.append(permission)
self.valid = True
Expand All @@ -419,13 +425,26 @@ def __init__(self, buffer, parameters=[]):

def add(self, parameters):
try:
if len(parameters) == 3:
permission = {
"driver_number": int(parameters[0], 0),
"offset": int(parameters[1], 0),
"allowed_commands": int(parameters[2], 0),
}
self.permissions.append(permission)
if len(parameters) == 2:
driver_number = int(parameters[0], 0)
command_number = int(parameters[1], 0)
offset = command_number // 64
index = command_number - (offset * 64)

for permission in self.permissions:
if (
permission["driver_number"] == driver_number
and permission["offset"] == offset
):
permission["allowed_commands"] |= 1 << index
break
else:
permission = {
"driver_number": driver_number,
"offset": offset,
"allowed_commands": (1 << index),
}
self.permissions.append(permission)
except:
logging.error("Failed parsing params for TLVID={}".format(self.TLVID))

Expand Down

0 comments on commit 2aceb27

Please sign in to comment.