Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit be4671b2 authored by Zach Johnson's avatar Zach Johnson
Browse files

Begin PyL2cap, to make interfacing with l2cap facade easier

Test: cert/run --host --test_filter=L2capTest
Change-Id: Ib614e1fa3cbca96607b6a1715243479b37a31b89
parent ba65d9aa
Loading
Loading
Loading
Loading
+33 −0
Original line number Diff line number Diff line
#!/usr/bin/env python3
#
#   Copyright 2020 - The Android Open Source Project
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.

from l2cap.classic import facade_pb2 as l2cap_facade_pb2
from bluetooth_packets_python3 import l2cap_packets


class PyL2cap(object):

    def __init__(self, device):
        self.device = device

    def open_channel(self,
                     psm=0x33,
                     mode=l2cap_facade_pb2.RetransmissionFlowControlMode.BASIC):

        # todo, I don't understand what SetDynamicChannel means?
        self.device.l2cap.SetDynamicChannel(
            l2cap_facade_pb2.SetEnableDynamicChannelRequest(
                psm=psm, retransmission_mode=mode))
+8 −7
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ from mobly import asserts

from cert.gd_base_test_facade_only import GdFacadeOnlyBaseTestClass
from cert.event_stream import EventStream
from cert.py_l2cap import PyL2cap
from facade import common_pb2
from facade import rootservice_pb2 as facade_rootservice
from google.protobuf import empty_pb2 as empty_proto
@@ -67,6 +68,8 @@ class L2capTest(GdFacadeOnlyBaseTestClass):
        self.ertm_tx_window_size = 10
        self.ertm_max_transmit = 20

        self.dut_l2cap = PyL2cap(self.dut)

    def _on_connection_request_default(self, l2cap_control_view):
        connection_request_view = l2cap_packets.ConnectionRequestView(
            l2cap_control_view)
@@ -491,13 +494,11 @@ class L2capTest(GdFacadeOnlyBaseTestClass):
            psm=0x33,
            mode=l2cap_facade_pb2.RetransmissionFlowControlMode.BASIC):

        self.dut.l2cap.SetDynamicChannel(
            l2cap_facade_pb2.SetEnableDynamicChannelRequest(
                psm=psm, retransmission_mode=mode))
        open_channel = l2cap_packets.ConnectionRequestBuilder(
            signal_id, psm, scid)
        open_channel_l2cap = l2cap_packets.BasicFrameBuilder(1, open_channel)
        self.cert_send_b_frame(open_channel_l2cap)
        self.dut_l2cap.open_channel(psm, mode)

        open_channel = l2cap_packets.BasicFrameBuilder(
            1, l2cap_packets.ConnectionRequestBuilder(signal_id, psm, scid))
        self.cert_send_b_frame(open_channel)

        def verify_connection_response(packet):
            packet_bytes = packet.payload