Exemple #1
0
 def __init__(self, device, cis_handle, iso_data_stream):
     self._device = device
     self._cis_handle = cis_handle
     self._le_iso_data_stream = iso_data_stream
     self._our_le_iso_cis_view = FilteringEventStream(
         self._le_iso_data_stream,
         IsoMatchers.PacketPayloadWithMatchingCisHandle(self._cis_handle))
Exemple #2
0
 def __init__(self, device, psm, l2cap_stream):
     self._device = device
     self._psm = psm
     self._le_l2cap_stream = l2cap_stream
     self._our_le_l2cap_view = FilteringEventStream(
         self._le_l2cap_stream,
         L2capMatchers.PacketPayloadWithMatchingPsm(self._psm))
Exemple #3
0
 def __init__(self, device, cid, l2cap_stream):
     self._device = device
     self._cid = cid
     self._le_l2cap_stream = l2cap_stream
     self._our_le_l2cap_view = FilteringEventStream(
         self._le_l2cap_stream,
         L2capMatchers.PacketPayloadWithMatchingCid(self._cid))
Exemple #4
0
class PyL2capChannel(IEventStream):
    def __init__(self, device, psm, l2cap_stream):
        self._device = device
        self._psm = psm
        self._le_l2cap_stream = l2cap_stream
        self._our_le_l2cap_view = FilteringEventStream(
            self._le_l2cap_stream,
            L2capMatchers.PacketPayloadWithMatchingPsm(self._psm))

    def get_event_queue(self):
        return self._our_le_l2cap_view.get_event_queue()

    def send(self, payload):
        self._device.l2cap.SendDynamicChannelPacket(
            l2cap_facade_pb2.DynamicChannelPacket(psm=self._psm,
                                                  payload=payload))

    def close_channel(self):
        self._device.l2cap.CloseChannel(
            l2cap_facade_pb2.CloseChannelRequest(psm=self._psm))

    def set_traffic_paused(self, paused):
        self._device.l2cap.SetTrafficPaused(
            l2cap_facade_pb2.SetTrafficPausedRequest(psm=self._psm,
                                                     paused=paused))
 def test_filtering_event_stream_none_filter_function(self):
     with EventStream(FetchEvents(events=[1, 2, 3],
                                  delay_ms=50)) as event_stream:
         filtered_event_stream = FilteringEventStream(event_stream, None)
         assertThat(filtered_event_stream)\
             .emits(lambda data: data.value_ == 1)\
             .then(lambda data: data.value_ == 3)
Exemple #6
0
 def __init__(self,
              device,
              scid,
              dcid,
              acl_stream,
              acl,
              control_channel,
              initial_credits=0):
     self._device = device
     self._scid = scid
     self._dcid = dcid
     self._acl_stream = acl_stream
     self._acl = acl
     self._control_channel = control_channel
     self._our_acl_view = FilteringEventStream(
         acl_stream, L2capMatchers.ExtractBasicFrame(scid))
     self._credits_left = initial_credits
Exemple #7
0
class CertLeL2capChannel(IEventStream):
    def __init__(self,
                 device,
                 scid,
                 dcid,
                 acl_stream,
                 acl,
                 control_channel,
                 initial_credits=0):
        self._device = device
        self._scid = scid
        self._dcid = dcid
        self._acl_stream = acl_stream
        self._acl = acl
        self._control_channel = control_channel
        self._our_acl_view = FilteringEventStream(
            acl_stream, L2capMatchers.ExtractBasicFrame(scid))
        self._credits_left = initial_credits

    def get_event_queue(self):
        return self._our_acl_view.get_event_queue()

    def send(self, packet):
        frame = l2cap_packets.BasicFrameBuilder(self._dcid, packet)
        self._acl.send(frame.Serialize())
        self._credits_left -= 1

    def send_first_le_i_frame(self, sdu_size, packet):
        frame = l2cap_packets.FirstLeInformationFrameBuilder(
            self._dcid, sdu_size, packet)
        self._acl.send(frame.Serialize())
        self._credits_left -= 1

    def disconnect_and_verify(self):
        assertThat(self._scid).isNotEqualTo(1)
        self._control_channel.send(
            l2cap_packets.LeDisconnectionRequestBuilder(
                1, self._dcid, self._scid))

        assertThat(self._control_channel).emits(
            L2capMatchers.LeDisconnectionResponse(self._scid, self._dcid))

    def verify_disconnect_request(self):
        assertThat(self._control_channel).emits(
            L2capMatchers.LeDisconnectionRequest(self._dcid, self._scid))

    def send_credits(self, num_credits):
        self._control_channel.send(
            l2cap_packets.LeFlowControlCreditBuilder(2, self._scid,
                                                     num_credits))

    def credits_left(self):
        return self._credits_left
Exemple #8
0
 def __init__(self,
              device,
              scid,
              dcid,
              acl_stream,
              acl,
              control_channel,
              fcs=None):
     self._device = device
     self._scid = scid
     self._dcid = dcid
     self._acl_stream = acl_stream
     self._acl = acl
     self._control_channel = control_channel
     self._config_rsp_received = False
     self._config_rsp_sent = False
     if fcs == l2cap_packets.FcsType.DEFAULT:
         self._our_acl_view = FilteringEventStream(
             acl_stream, L2capMatchers.ExtractBasicFrameWithFcs(scid))
     else:
         self._our_acl_view = FilteringEventStream(
             acl_stream, L2capMatchers.ExtractBasicFrame(scid))
Exemple #9
0
class PyLeIsoStream(IEventStream):
    def __init__(self, device, cis_handle, iso_data_stream):
        self._device = device
        self._cis_handle = cis_handle
        self._le_iso_data_stream = iso_data_stream
        self._our_le_iso_cis_view = FilteringEventStream(
            self._le_iso_data_stream,
            IsoMatchers.PacketPayloadWithMatchingCisHandle(self._cis_handle))

    def get_event_queue(self):
        return self._our_le_iso_cis_view.get_event_queue()

    def send(self, payload):
        self._device.iso.SendIsoPacket(
            iso_facade_pb2.IsoPacket(handle=self._cis_handle, payload=payload))
Exemple #10
0
class PyHalAclConnection(IEventStream):
    def __init__(self, handle, acl_stream, device):
        self.handle = int(handle)
        self.device = device
        self.our_acl_stream = FilteringEventStream(acl_stream, None)

    def send(self, pb_flag, b_flag, data):
        acl = AclBuilder(self.handle, pb_flag, b_flag, RawBuilder(data))
        self.device.hal.SendAcl(common.Data(payload=bytes(acl.Serialize())))

    def send_first(self, data):
        self.send(PacketBoundaryFlag.FIRST_NON_AUTOMATICALLY_FLUSHABLE,
                  BroadcastFlag.POINT_TO_POINT, bytes(data))

    def get_event_queue(self):
        return self.our_acl_stream.get_event_queue()
Exemple #11
0
class PyLeL2capFixedChannel(IEventStream):

    def __init__(self, device, cid, l2cap_stream):
        self._device = device
        self._cid = cid
        self._le_l2cap_stream = l2cap_stream
        self._our_le_l2cap_view = FilteringEventStream(self._le_l2cap_stream,
                                                       L2capMatchers.PacketPayloadWithMatchingCid(self._cid))

    def get_event_queue(self):
        return self._our_le_l2cap_view.get_event_queue()

    def send(self, payload):
        self._device.l2cap_le.SendFixedChannelPacket(
            l2cap_le_facade_pb2.FixedChannelPacket(cid=self._cid, payload=payload))

    def close_channel(self):
        self._device.l2cap_le.SetFixedChannel(
            l2cap_le_facade_pb2.SetEnableFixedChannelRequest(cid=self._cid, enable=False))
Exemple #12
0
class PyLeL2capDynamicChannel(IEventStream):

    def __init__(self, device, cert_address, psm, l2cap_stream):
        self._device = device
        self._cert_address = cert_address
        self._psm = psm
        self._le_l2cap_stream = l2cap_stream
        self._our_le_l2cap_view = FilteringEventStream(self._le_l2cap_stream,
                                                       L2capMatchers.PacketPayloadWithMatchingPsm(self._psm))

    def get_event_queue(self):
        return self._our_le_l2cap_view.get_event_queue()

    def send(self, payload):
        self._device.l2cap_le.SendDynamicChannelPacket(
            l2cap_le_facade_pb2.DynamicChannelPacket(psm=self._psm, payload=payload))

    def close_channel(self):
        self._device.l2cap_le.CloseDynamicChannel(
            l2cap_le_facade_pb2.CloseDynamicChannelRequest(remote=self._cert_address, psm=self._psm))
Exemple #13
0
class PyHciAclConnection(IEventStream):

    def __init__(self, handle, acl_stream, device):
        self.handle = int(handle)
        self.device = device
        # todo, handle we got is 0, so doesn't match - fix before enabling filtering
        self.our_acl_stream = FilteringEventStream(acl_stream, None)

    def send(self, pb_flag, b_flag, data):
        acl = AclBuilder(self.handle, pb_flag, b_flag, RawBuilder(data))
        self.device.hci.SendAcl(common.Data(payload=bytes(acl.Serialize())))

    def send_first(self, data):
        self.send(hci_packets.PacketBoundaryFlag.FIRST_AUTOMATICALLY_FLUSHABLE,
                  hci_packets.BroadcastFlag.POINT_TO_POINT, bytes(data))

    def send_continuing(self, data):
        self.send(hci_packets.PacketBoundaryFlag.CONTINUING_FRAGMENT, hci_packets.BroadcastFlag.POINT_TO_POINT,
                  bytes(data))

    def get_event_queue(self):
        return self.our_acl_stream.get_event_queue()
Exemple #14
0
class PyHciAclConnection(IEventStream):
    def __init__(self, handle, acl_stream, device):
        self.handle = int(handle)
        self.device = device
        # todo, handle we got is 0, so doesn't match - fix before enabling filtering
        self.our_acl_stream = FilteringEventStream(acl_stream, None)

    def send(self, pb_flag, b_flag, data):
        acl_msg = hci_facade.AclMsg(handle=self.handle,
                                    packet_boundary_flag=int(pb_flag),
                                    broadcast_flag=int(b_flag),
                                    data=data)
        self.device.hci.SendAclData(acl_msg)

    def send_first(self, data):
        self.send(hci_packets.PacketBoundaryFlag.FIRST_AUTOMATICALLY_FLUSHABLE,
                  hci_packets.BroadcastFlag.POINT_TO_POINT, bytes(data))

    def send_continuing(self, data):
        self.send(hci_packets.PacketBoundaryFlag.CONTINUING_FRAGMENT,
                  hci_packets.BroadcastFlag.POINT_TO_POINT, bytes(data))

    def get_event_queue(self):
        return self.our_acl_stream.get_event_queue()
Exemple #15
0
class CertL2capChannel(IEventStream):
    def __init__(self,
                 device,
                 scid,
                 dcid,
                 acl_stream,
                 acl,
                 control_channel,
                 fcs=None):
        self._device = device
        self._scid = scid
        self._dcid = dcid
        self._acl_stream = acl_stream
        self._acl = acl
        self._control_channel = control_channel
        self._config_rsp_received = False
        self._config_rsp_sent = False
        if fcs == l2cap_packets.FcsType.DEFAULT:
            self._our_acl_view = FilteringEventStream(
                acl_stream, L2capMatchers.ExtractBasicFrameWithFcs(scid))
        else:
            self._our_acl_view = FilteringEventStream(
                acl_stream, L2capMatchers.ExtractBasicFrame(scid))

    def get_event_queue(self):
        return self._our_acl_view.get_event_queue()

    def is_configured(self):
        return self._config_rsp_received and self._config_rsp_sent

    def send(self, packet):
        frame = l2cap_packets.BasicFrameBuilder(self._dcid, packet)
        self._acl.send(frame.Serialize())

    def send_i_frame(self,
                     tx_seq,
                     req_seq,
                     f=Final.NOT_SET,
                     sar=SegmentationAndReassembly.UNSEGMENTED,
                     payload=None,
                     fcs=False):
        if fcs == l2cap_packets.FcsType.DEFAULT:
            frame = l2cap_packets.EnhancedInformationFrameWithFcsBuilder(
                self._dcid, tx_seq, f, req_seq, sar, payload)
        else:
            frame = l2cap_packets.EnhancedInformationFrameBuilder(
                self._dcid, tx_seq, f, req_seq, sar, payload)
        self._acl.send(frame.Serialize())

    def send_s_frame(self,
                     req_seq,
                     s=SupervisoryFunction.RECEIVER_READY,
                     p=Poll.NOT_SET,
                     f=Final.NOT_SET):
        frame = l2cap_packets.EnhancedSupervisoryFrameBuilder(
            self._dcid, s, p, f, req_seq)
        self._acl.send(frame.Serialize())

    def config_request_for_me(self):
        return L2capMatchers.ConfigurationRequest(self._scid)

    def send_configure_request(self,
                               options,
                               sid=2,
                               continuation=l2cap_packets.Continuation.END):
        assertThat(self._scid).isNotEqualTo(1)
        request = l2cap_packets.ConfigurationRequestBuilder(
            sid, self._dcid, continuation, options)
        self._control_channel.send(request)

    def _send_information_request(self, type):
        assertThat(self._scid).isEqualTo(1)
        signal_id = 3
        information_request = l2cap_packets.InformationRequestBuilder(
            signal_id, type)
        self.send(information_request)

    def send_extended_features_request(self):
        self._send_information_request(
            InformationRequestInfoType.EXTENDED_FEATURES_SUPPORTED)

    def verify_configuration_request_and_respond(
            self, result=ConfigurationResponseResult.SUCCESS, options=None):
        request_capture = L2capCaptures.ConfigurationRequest(self._scid)
        assertThat(self._control_channel).emits(request_capture)
        request = request_capture.get()
        sid = request.GetIdentifier()
        if options is None:
            options = []
        config_response = l2cap_packets.ConfigurationResponseBuilder(
            sid, self._dcid, l2cap_packets.Continuation.END, result, options)
        self._control_channel.send(config_response)

    def send_configuration_response(self,
                                    request,
                                    result=ConfigurationResponseResult.SUCCESS,
                                    options=None):
        sid = request.GetIdentifier()
        if options is None:
            options = []
        config_response = l2cap_packets.ConfigurationResponseBuilder(
            sid, self._dcid, l2cap_packets.Continuation.END, result, options)
        self._control_channel.send(config_response)
        self._config_rsp_sent = True

    def verify_configuration_response(
            self, result=ConfigurationResponseResult.SUCCESS):
        assertThat(self._control_channel).emits(
            L2capMatchers.ConfigurationResponse(result))

    def disconnect_and_verify(self):
        assertThat(self._scid).isNotEqualTo(1)
        self._control_channel.send(
            l2cap_packets.DisconnectionRequestBuilder(1, self._dcid,
                                                      self._scid))

        assertThat(self._control_channel).emits(
            L2capMatchers.DisconnectionResponse(self._scid, self._dcid))

    def verify_disconnect_request(self):
        assertThat(self._control_channel).emits(
            L2capMatchers.DisconnectionRequest(self._dcid, self._scid))
Exemple #16
0
 def __init__(self, handle, acl_stream, device):
     self.handle = int(handle)
     self.device = device
     # todo, handle we got is 0, so doesn't match - fix before enabling filtering
     self.our_acl_stream = FilteringEventStream(acl_stream, None)
Exemple #17
0
 def __init__(self, handle, acl_stream, device):
     self.handle = int(handle)
     self.device = device
     self.our_acl_stream = FilteringEventStream(acl_stream, None)