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

Commit 02bdf668 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge changes from topic "oob_sl4a_cert_test" am: 844e9816

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/2028187

Change-Id: I6e68c0a0d725bd524c668e803da1a4a98370b7e7
parents d7262a1f 844e9816
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -15,11 +15,12 @@
#   limitations under the License.

from blueberry.tests.gd_sl4a.hci.le_advanced_scanning_test import LeAdvancedScanningTest
from blueberry.tests.gd_sl4a.security.oob_pairing_sl4a_test import OobPairingSl4aTest

from mobly import suite_runner
import argparse

ALL_TESTS = [LeAdvancedScanningTest]
ALL_TESTS = [LeAdvancedScanningTest, OobPairingSl4aTest]


def main():
+83 −0
Original line number Diff line number Diff line
#!/usr/bin/env python3
#
#   Copyright 2022 - 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.

import queue
import logging

from google.protobuf import empty_pb2 as empty_proto

from blueberry.tests.gd_sl4a.lib.gd_sl4a_base_test import GdSl4aBaseTestClass
from blueberry.tests.gd.cert.truth import assertThat


class OobData:

    def __init__(self):
        pass


class OobPairingSl4aTest(GdSl4aBaseTestClass):
    # Events sent from SL4A
    SL4A_EVENT_GENERATED = "GeneratedOobData"
    SL4A_EVENT_ERROR = "ErrorOobData"

    # Matches tBT_TRANSPORT
    # Used Strings because ints were causing gRPC problems
    TRANSPORT_AUTO = "0"
    TRANSPORT_BREDR = "1"
    TRANSPORT_LE = "2"

    def setup_class(self):
        super().setup_class(cert_module='SECURITY')
        self.default_timeout = 5  # seconds

    def setup_test(self):
        super().setup_test()

    def teardown_test(self):
        super().teardown_test()

    def _generate_sl4a_oob_data(self, transport):
        logging.info("Fetching OOB data...")
        self.dut.sl4a.bluetoothGenerateLocalOobData(transport)
        try:
            event_info = self.dut.ed.pop_event(self.SL4A_EVENT_GENERATED, self.default_timeout)
        except queue.Empty as error:
            logging.error("Failed to generate OOB data!")
            return None
        logging.info("Data received!")
        return OobData()

    def _generate_cert_oob_data(self, transport):
        if transport == self.TRANSPORT_LE:
            return self.cert.security.GetLeOutOfBandData(empty_proto.Empty())
        return None

    def test_sl4a_classic_generate_oob_data(self):
        oob_data = self._generate_sl4a_oob_data(self.TRANSPORT_BREDR)
        assertThat(oob_data).isNotNone()

    def test_sl4a_classic_generate_oob_data_twice(self):
        self.test_sl4a_classic_generate_oob_data()
        self.test_sl4a_classic_generate_oob_data()

    def test_sl4a_ble_generate_oob_data(self):
        oob_data = self._generate_sl4a_oob_data(self.TRANSPORT_LE)
        assertThat(oob_data).isNotNone()

    def test_cert_ble_generate_oob_data(self):
        oob_data = self._generate_cert_oob_data(self.TRANSPORT_LE)
        assertThat(oob_data).isNotNone()
+8 −2
Original line number Diff line number Diff line
@@ -2512,8 +2512,14 @@ void btif_dm_proc_loc_oob(tBT_TRANSPORT transport, bool is_valid,
    waiting_on_oob_advertiser_start = false;
    return;
  }
  if (transport == BT_TRANSPORT_LE) {
    // Now that we have the data, lets start advertising and get the address.
    start_oob_advertiser(transport, is_valid, c, r);
  } else {
    invoke_oob_data_request_cb(transport, is_valid, c, r,
                               *controller_get_interface()->get_address(),
                               0x00);
  }
}

/*******************************************************************************
+8 −9
Original line number Diff line number Diff line
@@ -1743,11 +1743,16 @@ void btm_ble_connected_from_address_with_type(
 *****************************************************************************/
tBTM_STATUS btm_proc_smp_cback(tSMP_EVT event, const RawAddress& bd_addr,
                               const tSMP_EVT_DATA* p_data) {
  BTM_TRACE_DEBUG("btm_proc_smp_cback event = %d", event);

  if (event == SMP_SC_LOC_OOB_DATA_UP_EVT) {
    btm_sec_cr_loc_oob_data_cback_event(RawAddress{}, p_data->loc_oob_data);
    return BTM_SUCCESS;
  }

  tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr);
  tBTM_STATUS res = BTM_SUCCESS;

  BTM_TRACE_DEBUG("btm_proc_smp_cback event = %d", event);

  if (p_dev_rec != NULL) {
    switch (event) {
      case SMP_IO_CAP_REQ_EVT:
@@ -1860,13 +1865,7 @@ tBTM_STATUS btm_proc_smp_cback(tSMP_EVT event, const RawAddress& bd_addr,
        break;
    }
  } else {
    // If we are being paired with via OOB we haven't created a dev rec for
    // the device yet
    if (event == SMP_SC_LOC_OOB_DATA_UP_EVT) {
      btm_sec_cr_loc_oob_data_cback_event(bd_addr, p_data->loc_oob_data);
    } else {
      LOG_WARN("Unexpected event '%d' without p_dev_rec", event);
    }
    LOG_WARN("Unexpected event '%d' for unknown device.", event);
  }

  return BTM_SUCCESS;