Skip to content
Merged
Changes from all 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
9 changes: 6 additions & 3 deletions udsoncan/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def request_seed(self, level: int, data=bytes()) -> Optional[services.SecurityAc
:param level: The security level to unlock. If value is even, it will be converted to the corresponding odd value
:type level: int

:param data: The data to send to the server
:param data: The data to send to the server (securityAccessDataRecord)
:type data: bytes

:return: The server response parsed by :meth:`SecurityAccess.interpret_response<udsoncan.services.SecurityAccess.interpret_response>`
Expand Down Expand Up @@ -327,7 +327,7 @@ def send_key(self, level: int, key: bytes) -> Optional[services.SecurityAccess.I
return response

@standard_error_management
def unlock_security_access(self, level) -> Optional[services.SecurityAccess.InterpretedResponse]:
def unlock_security_access(self, level, seed_params=bytes()) -> Optional[services.SecurityAccess.InterpretedResponse]:
"""
Successively calls request_seed and send_key to unlock a security level with the :ref:`SecurityAccess<SecurityAccess>` service.
The key computation is done by calling config['security_algo']
Expand All @@ -337,14 +337,17 @@ def unlock_security_access(self, level) -> Optional[services.SecurityAccess.Inte
:param level: The level to unlock. Can be the odd or even variant of it.
:type level: int

:param seed_params: Optional data to attach to the RequestSeed request (securityAccessDataRecord).
:type seed_params: bytes

:return: The server response parsed by :meth:`SecurityAccess.interpret_response<udsoncan.services.SecurityAccess.interpret_response>`
:rtype: :ref:`Response<Response>`
"""

if 'security_algo' not in self.config or not callable(self.config['security_algo']):
raise NotImplementedError("Client configuration does not provide a security algorithm")

response = self.request_seed._func_no_error_management(self, level)
response = self.request_seed._func_no_error_management(self, level, data=seed_params)
seed = response.service_data.seed
if len(seed) > 0 and seed == b'\x00' * len(seed):
self.logger.info('%s - Security access level 0x%02x is already unlocked, no key will be sent.' %
Expand Down