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

Commit 3e4963b6 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "LeL2capTest: Add COC PTS test"

parents e44a9981 faf9ccca
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -48,7 +48,7 @@ def ConnectionCompleteCapture():


def LeConnectionCompleteCapture():
    return Capture(lambda packet: print(packet.event[0:3]) or packet.event[0] == 0x3e
    return Capture(lambda packet: packet.event[0] == 0x3e
                   and (packet.event[2] == 0x01 or packet.event[2] == 0x0a),
        lambda packet: hci_packets.LeConnectionCompleteView(
            hci_packets.LeMetaEventView(
+21 −6
Original line number Diff line number Diff line
@@ -58,8 +58,13 @@ class L2capMatchers(object):
        return lambda packet: L2capMatchers._is_le_control_frame_with_code(packet, LeCommandCode.LE_CREDIT_BASED_CONNECTION_REQUEST)

    @staticmethod
    def CreditBasedConnectionResponse(scid):
        return lambda packet: L2capMatchers._is_matching_credit_based_connection_response(packet, scid)
    def CreditBasedConnectionResponse(
            scid, result=LeCreditBasedConnectionResponseResult.SUCCESS):
        return lambda packet: L2capMatchers._is_matching_credit_based_connection_response(packet, scid, result)

    @staticmethod
    def LeDisconnectionRequest(scid, dcid):
        return lambda packet: L2capMatchers._is_matching_le_disconnection_request(packet, scid, dcid)

    @staticmethod
    def SFrame(req_seq=None, f=None, s=None, p=None):
@@ -199,6 +204,16 @@ class L2capMatchers(object):
        return response.GetSourceCid() == scid and response.GetDestinationCid(
        ) == dcid

    @staticmethod
    def _is_matching_le_disconnection_request(packet, scid, dcid):
        frame = L2capMatchers.le_control_frame_with_code(
            packet, LeCommandCode.DISCONNECTION_REQUEST)
        if frame is None:
            return False
        request = l2cap_packets.LeDisconnectionRequestView(frame)
        return request.GetSourceCid() == scid and request.GetDestinationCid(
        ) == dcid

    @staticmethod
    def _information_response_with_type(packet, info_type):
        frame = L2capMatchers.control_frame_with_code(
@@ -232,12 +247,12 @@ class L2capMatchers(object):
        return True

    @staticmethod
    def _is_matching_credit_based_connection_response(packet, scid):
    def _is_matching_credit_based_connection_response(packet, scid, result):
        frame = L2capMatchers.le_control_frame_with_code(
            packet, LeCommandCode.LE_CREDIT_BASED_CONNECTION_RESPONSE)
        if frame is None:
            return False
        response = l2cap_packets.LeCreditBasedConnectionResponseView(frame)
        return response.GetResult(
        ) == LeCreditBasedConnectionResponseResult.SUCCESS and response.GetDestinationCid(
        ) != 0
        return response.GetResult() == result and (
            result != LeCreditBasedConnectionResponseResult.SUCCESS or
            response.GetDestinationCid() != 0)
+4 −0
Original line number Diff line number Diff line
@@ -29,6 +29,10 @@ class PyL2capChannel(object):
        self._device.l2cap.SendDynamicChannelPacket(
            l2cap_facade_pb2.DynamicChannelPacket(psm=0x33, payload=payload))

    def send_le(self, payload):
        self._device.l2cap_le.SendDynamicChannelPacket(
            l2cap_le_facade_pb2.DynamicChannelPacket(psm=0x33, payload=payload))


class PyL2cap(object):

+2 −0
Original line number Diff line number Diff line
@@ -102,6 +102,7 @@ void LeCreditBasedDataController::OnPdu(packet::PacketView<true> pdu) {
}

std::unique_ptr<packet::BasePacketBuilder> LeCreditBasedDataController::GetNextPacket() {
  ASSERT(!pdu_queue_.empty());
  auto next = std::move(pdu_queue_.front());
  pdu_queue_.pop();
  return next;
@@ -123,6 +124,7 @@ void LeCreditBasedDataController::OnCredit(uint16_t credits) {
  credits_ = total_credits;
  if (pending_frames_count_ > 0 && credits_ >= pending_frames_count_) {
    scheduler_->OnPacketsReady(cid_, pending_frames_count_);
    pending_frames_count_ = 0;
    credits_ -= pending_frames_count_;
  } else if (pending_frames_count_ > 0) {
    scheduler_->OnPacketsReady(cid_, credits_);
+8 −3
Original line number Diff line number Diff line
@@ -55,6 +55,12 @@ class CertLeL2capChannel(IEventStream):
        assertThat(self._control_channel).emits(
            L2capMatchers.DisconnectionResponse(self._scid, self._dcid))

    def get_scid(self):
        return self._scid

    def get_dcid(self):
        return self._dcid


class CertLeL2cap(Closable):

@@ -88,11 +94,10 @@ class CertLeL2cap(Closable):
            control_channel=None)
        self._get_acl_stream().register_callback(self._handle_control_packet)

    def open_channel(self, signal_id, psm, scid):
        # TODO(hsz): use credit based
    def open_channel(self, signal_id, psm, scid, initial_credit=6):
        self.control_channel.send(
            l2cap_packets.LeCreditBasedConnectionRequestBuilder(
                signal_id, psm, scid, 2000, 1000, 1000))
                signal_id, psm, scid, 2000, 1000, initial_credit))

        response = L2capCaptures.CreditBasedConnectionResponse(scid)
        assertThat(self.control_channel).emits(response)
Loading