|
22 | 22 | import random |
23 | 23 | import threading |
24 | 24 | from array import array |
25 | | -from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes |
| 25 | +from cryptography.hazmat.primitives.ciphers import (algorithms, Cipher, modes) |
26 | 26 | from queue import Queue |
27 | 27 |
|
28 | 28 | from .. import Target |
29 | 29 | from ..session import Session |
30 | 30 | from ..msgs import (create_message, create_request_by_name, create_response_by_name, |
31 | 31 | encode_message, decode_message, constants) |
32 | 32 | from ..messaging import ChannelAuthenticationCapabilities |
33 | | -from ..errors import DecodingError, NotSupportedError, RetryError |
| 33 | +from ..errors import (DecodingError, NotSupportedError, RetryError) |
34 | 34 | from ..logger import log |
35 | 35 | from ..interfaces.ipmb import (IpmbHeaderReq, encode_ipmb_msg, |
36 | 36 | encode_bridged_message, decode_bridged_message, |
37 | 37 | rx_filter) |
38 | | -from ..utils import (check_rsp_completion_code, py3_array_tobytes) |
| 38 | +from ..utils import check_rsp_completion_code |
39 | 39 |
|
40 | 40 |
|
41 | 41 | CLASS_NORMAL_MSG = 0x00 |
@@ -300,7 +300,7 @@ def pack(self, sdu): |
300 | 300 | else: |
301 | 301 | raise NotSupportedError('authentication type %s' % auth_type) |
302 | 302 |
|
303 | | - pdu += py3_array_tobytes(array('B', [data_len])) |
| 303 | + pdu += array('B', [data_len]).tobytes() |
304 | 304 |
|
305 | 305 | if sdu is not None: |
306 | 306 | pdu += sdu |
@@ -410,11 +410,11 @@ def pack(self, sdu, payload_type): |
410 | 410 | ) |
411 | 411 |
|
412 | 412 | if sdu is None: |
413 | | - pdu += py3_array_tobytes(array('B', list(data_len.to_bytes(2, 'little')))) |
| 413 | + pdu += array('B', list(data_len.to_bytes(2, 'little'))).tobytes() |
414 | 414 | return pdu |
415 | 415 |
|
416 | 416 | if self.session is None or self.session.is_encrypted is False: |
417 | | - pdu += py3_array_tobytes(array('B', list(data_len.to_bytes(2, 'little')))) |
| 417 | + pdu += array('B', list(data_len.to_bytes(2, 'little'))).tobytes() |
418 | 418 | pdu += sdu |
419 | 419 | return pdu |
420 | 420 |
|
@@ -443,7 +443,7 @@ def pack(self, sdu, payload_type): |
443 | 443 | ct = encryptor.update(sdu) + encryptor.finalize() |
444 | 444 |
|
445 | 445 | data_len = len(initialization_vector + ct) |
446 | | - pdu += py3_array_tobytes(array('B', list(data_len.to_bytes(2, 'little')))) |
| 446 | + pdu += array('B', list(data_len.to_bytes(2, 'little'))).tobytes() |
447 | 447 | pdu += initialization_vector + ct |
448 | 448 |
|
449 | 449 | # Now add the Session trailer |
@@ -610,12 +610,12 @@ def _receive_asf_msg(self, cls): |
610 | 610 |
|
611 | 611 | def ping(self): |
612 | 612 | ping = AsfPing() |
613 | | - self._send_asf_msg(ping) |
614 | | - self._receive_asf_msg(AsfPong) |
| 613 | + with self.transaction_lock: |
| 614 | + self._send_asf_msg(ping) |
| 615 | + self._receive_asf_msg(AsfPong) |
615 | 616 |
|
616 | 617 | def _get_channel_auth_cap(self, session): |
617 | 618 | CHANNEL_NUMBER_FOR_THIS = 0xe |
618 | | - # get channel auth cap |
619 | 619 | req = create_request_by_name('GetChannelAuthenticationCapabilities') |
620 | 620 | req.target = self.host_target |
621 | 621 | req.channel.number = CHANNEL_NUMBER_FOR_THIS |
@@ -985,6 +985,10 @@ def establish_session(self, session): |
985 | 985 | self._session = session |
986 | 986 | log().debug("Session Opened") |
987 | 987 |
|
| 988 | + if self.keep_alive_interval: |
| 989 | + self._stop_keep_alive = call_repeatedly( |
| 990 | + self.keep_alive_interval, self._get_device_id) |
| 991 | + |
988 | 992 | def _send_and_receive(self, target, lun, netfn, cmdid, payload): |
989 | 993 | self._inc_sequence_number() |
990 | 994 |
|
|
0 commit comments