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

Commit 3a145f98 authored by bidsharma's avatar bidsharma
Browse files

[PANDORA_TEST] Use new pairing interface in SMP

Tag: #feature
Bug: 239437774
Test: atest pts-bot:SM/CEN -v

Change-Id: Ia19ab7061b123aea214d69481f816052898fa625
parent 27a19cac
Loading
Loading
Loading
Loading
+26 −8
Original line number Original line Diff line number Diff line
@@ -12,9 +12,11 @@
# See the License for the specific language governing permissions and
# See the License for the specific language governing permissions and
# limitations under the License.
# limitations under the License.
"""SMP proxy module."""
"""SMP proxy module."""
import sys


from mmi2grpc._helpers import assert_description
from mmi2grpc._helpers import assert_description
from mmi2grpc._proxy import ProfileProxy
from mmi2grpc._proxy import ProfileProxy
from mmi2grpc._streaming import StreamWrapper


from pandora.security_grpc import Security
from pandora.security_grpc import Security
from pandora.host_grpc import Host
from pandora.host_grpc import Host
@@ -38,6 +40,17 @@ ACCEPTS_REMOTE_PAIRING_CONFIRMATION = {
}
}




def debug(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)


def get_event(pairing_stream: StreamWrapper, addr: str):
    for event in pairing_stream:
        if event.address == addr:
            return event
    return None


class SMProxy(ProfileProxy):
class SMProxy(ProfileProxy):


    def __init__(self, channel):
    def __init__(self, channel):
@@ -45,6 +58,7 @@ class SMProxy(ProfileProxy):
        self.security = Security(channel)
        self.security = Security(channel)
        self.host = Host(channel)
        self.host = Host(channel)
        self.connection = None
        self.connection = None
        self.pairing_stream = None


    @assert_description
    @assert_description
    def MMI_IUT_ENABLE_CONNECTION_SM(self, test, pts_addr: bytes, **kwargs):
    def MMI_IUT_ENABLE_CONNECTION_SM(self, test, pts_addr: bytes, **kwargs):
@@ -52,20 +66,25 @@ class SMProxy(ProfileProxy):
        Initiate an connection from the IUT to the PTS.
        Initiate an connection from the IUT to the PTS.
        """
        """
        self.connection = self.host.ConnectLE(address=pts_addr).connection
        self.connection = self.host.ConnectLE(address=pts_addr).connection
        self.pairing_stream = self.security.OnPairing()

        if self.connection and test in ACCEPTS_REMOTE_PAIRING_CONFIRMATION:
        if self.connection and test in ACCEPTS_REMOTE_PAIRING_CONFIRMATION:
            self.security.ProvidePairingConfirmation(connection=self.connection, pairing_confirmation_value=True)
            event = get_event(pairing_stream=self.pairing_stream, addr=pts_addr)
            self.pairing_stream.send(event=event, confirm=True)
            self.pairing_stream.close()
        return "OK"
        return "OK"


    @assert_description
    @assert_description
    def MMI_ASK_IUT_PERFORM_PAIRING_PROCESS(self, test, **kwargs):
    def MMI_ASK_IUT_PERFORM_PAIRING_PROCESS(self, test, pts_addr: bytes, **kwargs):
        """
        """
        Please start pairing process.
        Please start pairing process.
        """
        """
        if self.connection:
        if self.connection:
            self.security.Pair(connection=self.connection)
            self.security.Pair(connection=self.connection)
            if test in NEEDS_PAIRING_CONFIRMATION:
            if test in NEEDS_PAIRING_CONFIRMATION:
                self.security.ProvidePairingConfirmation(connection=self.connection, pairing_confirmation_value=True)
                event = get_event(pairing_stream=self.pairing_stream, addr=pts_addr)

                self.pairing_stream.send(event=event, confirm=True)
                self.pairing_stream.close()
            return "OK"
            return "OK"


    @assert_description
    @assert_description
@@ -77,7 +96,6 @@ class SMProxy(ProfileProxy):
        the Implementation Under Test(IUT) can initiate a disconnect request to
        the Implementation Under Test(IUT) can initiate a disconnect request to
        PTS.
        PTS.
        """
        """
        if self.connection:
        self.host.DisconnectLE(connection=self.connection)
        self.host.DisconnectLE(connection=self.connection)
        self.connection = None
        self.connection = None
        return "OK"
        return "OK"
+1 −0
Original line number Original line Diff line number Diff line
@@ -30,6 +30,7 @@
        <option name="profile" value="SDP/SR" />
        <option name="profile" value="SDP/SR" />
        <option name="profile" value="SM/CEN/EKS" />
        <option name="profile" value="SM/CEN/EKS" />
        <option name="profile" value="SM/CEN/JW" />
        <option name="profile" value="SM/CEN/JW" />
        <option name="profile" value="SM/CEN/KDU" />
    </test>
    </test>


    <object type="module_controller"
    <object type="module_controller"
+4 −4
Original line number Original line Diff line number Diff line
@@ -113,6 +113,9 @@
    "SM/CEN/EKS/BI-01-C",
    "SM/CEN/EKS/BI-01-C",
    "SM/CEN/EKS/BV-01-C",
    "SM/CEN/EKS/BV-01-C",
    "SM/CEN/JW/BV-05-C",
    "SM/CEN/JW/BV-05-C",
    "SM/CEN/JW/BI-04-C",
    "SM/CEN/JW/BI-01-C",
    "SM/CEN/KDU/BV-01-C",
    "SM/CEN/KDU/BV-04-C",
    "SM/CEN/KDU/BV-04-C",
    "SM/CEN/KDU/BV-05-C",
    "SM/CEN/KDU/BV-05-C",
    "SM/CEN/KDU/BI-02-C",
    "SM/CEN/KDU/BI-02-C",
@@ -227,10 +230,7 @@
    "HFP/AG/TCA/BV-02-I",
    "HFP/AG/TCA/BV-02-I",
    "HFP/AG/TCA/BV-03-I",
    "HFP/AG/TCA/BV-03-I",
    "HFP/AG/TCA/BV-04-I",
    "HFP/AG/TCA/BV-04-I",
    "HFP/AG/TCA/BV-05-I",
    "HFP/AG/TCA/BV-05-I"
    "SM/CEN/JW/BI-01-C",
    "SM/CEN/JW/BI-04-C",
    "SM/CEN/KDU/BI-01-C"
  ],
  ],
  "ics": {
  "ics": {
    "TSPC_4.0HCI_1a_2": true,
    "TSPC_4.0HCI_1a_2": true,
+0 −9
Original line number Original line Diff line number Diff line
@@ -11,10 +11,6 @@ service Security {
  // Begin pairing asynchronously with a device. Responses will be streamed
  // Begin pairing asynchronously with a device. Responses will be streamed
  // using the OnPairing rpc.
  // using the OnPairing rpc.
  rpc Pair(PairRequest) returns (google.protobuf.Empty);
  rpc Pair(PairRequest) returns (google.protobuf.Empty);
  // Acknowledge a pairing request and continue pairing
  // TODO(240276298) remove, since PairingEventAnswers supersede these
  rpc ProvidePairingConfirmation(PairingConfirmationRequest)
      returns (google.protobuf.Empty);
  // Listen to pairing events.
  // Listen to pairing events.
  // This is handled independently from connections for several reasons:
  // This is handled independently from connections for several reasons:
  // - Pairing can be triggered at any time and multiple times during the
  // - Pairing can be triggered at any time and multiple times during the
@@ -30,11 +26,6 @@ message PairRequest {
    Connection connection = 1;
    Connection connection = 1;
}
}


message PairingConfirmationRequest {
    Connection connection = 1;
    bool pairing_confirmation_value = 2;
}

message PairingEvent {
message PairingEvent {
    // Peer Bluetooth Device Address as array of 6 bytes.
    // Peer Bluetooth Device Address as array of 6 bytes.
    bytes address = 1;
    bytes address = 1;
+0 −16
Original line number Original line Diff line number Diff line
@@ -72,22 +72,6 @@ class Security(private val context: Context) : SecurityImplBase() {
    }
    }
  }
  }


  override fun providePairingConfirmation(
    request: PairingConfirmationRequest,
    responseObserver: StreamObserver<Empty>
  ) {
    grpcUnary(globalScope, responseObserver) {
      val bluetoothDevice = request.connection.toBluetoothDevice(bluetoothAdapter)
      Log.i(TAG, "Confirm pairing for: address=${bluetoothDevice.address}")
      flow
        .filter { it.action == BluetoothDevice.ACTION_PAIRING_REQUEST }
        .filter { it.getBluetoothDeviceExtra() == bluetoothDevice }
        .first()
      bluetoothDevice.setPairingConfirmation(request.pairingConfirmationValue)
      Empty.getDefaultInstance()
    }
  }

  override fun deletePairing(
  override fun deletePairing(
    request: DeletePairingRequest,
    request: DeletePairingRequest,
    responseObserver: StreamObserver<DeletePairingResponse>
    responseObserver: StreamObserver<DeletePairingResponse>