Loading system/gd/cert/matchers.py +16 −0 Original line number Diff line number Diff line Loading @@ -17,10 +17,15 @@ import bluetooth_packets_python3 as bt_packets from bluetooth_packets_python3 import l2cap_packets from bluetooth_packets_python3.l2cap_packets import CommandCode from bluetooth_packets_python3.l2cap_packets import ConnectionResponseResult class L2capMatchers(object): @staticmethod def ConnectionResponse(scid): return lambda packet: L2capMatchers._is_matching_connection_response(packet, scid) @staticmethod def ConnectionRequest(): return lambda packet: L2capMatchers._is_control_frame_with_code(packet, CommandCode.CONNECTION_REQUEST) Loading Loading @@ -61,3 +66,14 @@ class L2capMatchers(object): @staticmethod def _is_control_frame_with_code(packet, code): return L2capMatchers._control_frame_with_code(packet, code) is not None @staticmethod def _is_matching_connection_response(packet, scid): frame = L2capMatchers._control_frame_with_code( packet, CommandCode.CONNECTION_RESPONSE) if frame is None: return False response = l2cap_packets.ConnectionResponseView(frame) return response.GetSourceCid() == scid and response.GetResult( ) == ConnectionResponseResult.SUCCESS and response.GetDestinationCid( ) != 0 system/gd/l2cap/classic/cert/l2cap_test.py +1 −17 Original line number Diff line number Diff line Loading @@ -364,24 +364,8 @@ class L2capTest(GdFacadeOnlyBaseTestClass): 1, l2cap_packets.ConnectionRequestBuilder(signal_id, psm, scid)) self.cert_send_b_frame(open_channel) def verify_connection_response(packet): packet_bytes = packet.payload l2cap_view = l2cap_packets.BasicFrameView( bt_packets.PacketViewLittleEndian(list(packet_bytes))) l2cap_control_view = l2cap_packets.ControlView( l2cap_view.GetPayload()) if l2cap_control_view.GetCode( ) != l2cap_packets.CommandCode.CONNECTION_RESPONSE: return False connection_response_view = l2cap_packets.ConnectionResponseView( l2cap_control_view) return connection_response_view.GetSourceCid( ) == scid and connection_response_view.GetResult( ) == l2cap_packets.ConnectionResponseResult.SUCCESS and connection_response_view.GetDestinationCid( ) != 0 assertThat(self.cert_acl_manager.get_acl_stream()).emits( verify_connection_response) L2capMatchers.ConnectionResponse(scid)) def test_connect_dynamic_channel_and_send_data(self): self._setup_link_from_cert() Loading Loading
system/gd/cert/matchers.py +16 −0 Original line number Diff line number Diff line Loading @@ -17,10 +17,15 @@ import bluetooth_packets_python3 as bt_packets from bluetooth_packets_python3 import l2cap_packets from bluetooth_packets_python3.l2cap_packets import CommandCode from bluetooth_packets_python3.l2cap_packets import ConnectionResponseResult class L2capMatchers(object): @staticmethod def ConnectionResponse(scid): return lambda packet: L2capMatchers._is_matching_connection_response(packet, scid) @staticmethod def ConnectionRequest(): return lambda packet: L2capMatchers._is_control_frame_with_code(packet, CommandCode.CONNECTION_REQUEST) Loading Loading @@ -61,3 +66,14 @@ class L2capMatchers(object): @staticmethod def _is_control_frame_with_code(packet, code): return L2capMatchers._control_frame_with_code(packet, code) is not None @staticmethod def _is_matching_connection_response(packet, scid): frame = L2capMatchers._control_frame_with_code( packet, CommandCode.CONNECTION_RESPONSE) if frame is None: return False response = l2cap_packets.ConnectionResponseView(frame) return response.GetSourceCid() == scid and response.GetResult( ) == ConnectionResponseResult.SUCCESS and response.GetDestinationCid( ) != 0
system/gd/l2cap/classic/cert/l2cap_test.py +1 −17 Original line number Diff line number Diff line Loading @@ -364,24 +364,8 @@ class L2capTest(GdFacadeOnlyBaseTestClass): 1, l2cap_packets.ConnectionRequestBuilder(signal_id, psm, scid)) self.cert_send_b_frame(open_channel) def verify_connection_response(packet): packet_bytes = packet.payload l2cap_view = l2cap_packets.BasicFrameView( bt_packets.PacketViewLittleEndian(list(packet_bytes))) l2cap_control_view = l2cap_packets.ControlView( l2cap_view.GetPayload()) if l2cap_control_view.GetCode( ) != l2cap_packets.CommandCode.CONNECTION_RESPONSE: return False connection_response_view = l2cap_packets.ConnectionResponseView( l2cap_control_view) return connection_response_view.GetSourceCid( ) == scid and connection_response_view.GetResult( ) == l2cap_packets.ConnectionResponseResult.SUCCESS and connection_response_view.GetDestinationCid( ) != 0 assertThat(self.cert_acl_manager.get_acl_stream()).emits( verify_connection_response) L2capMatchers.ConnectionResponse(scid)) def test_connect_dynamic_channel_and_send_data(self): self._setup_link_from_cert() Loading