1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #include <stddef.h> 20 #include <stdint.h> 21 22 #include <functional> 23 #include <memory> 24 #include <string_view> 25 #include <vector> 26 27 #include <adbwifi/pairing/pairing_connection.h> 28 29 namespace adbwifi { 30 namespace pairing { 31 32 // PairingServer is the server side of the PairingConnection protocol. It will 33 // listen for incoming PairingClient connections, and allocate a new 34 // PairingConnection per client for processing. PairingServer can handle multiple 35 // connections, but the first one to establish the pairing will be the only one 36 // to succeed. All others will be disconnected. 37 // 38 // See pairing_connection_test.cpp for example usage. 39 // 40 class PairingServer { 41 public: 42 using Data = std::vector<uint8_t>; 43 44 virtual ~PairingServer() = default; 45 46 // Starts the pairing server. This call is non-blocking. Upon completion, 47 // if the pairing was successful, then |cb| will be called with the PeerInfo 48 // containing the info of the trusted peer. Otherwise, |cb| will be 49 // called with an empty value. Start can only be called once in the lifetime 50 // of this object. 51 // 52 // Returns true if PairingServer was successfully started. Otherwise, 53 // returns false. 54 virtual bool start(PairingConnection::ResultCallback cb, void* opaque) = 0; 55 56 // Creates a new PairingServer instance. May return null if unable 57 // to create an instance. |pswd|, |certificate| and |priv_key| cannot 58 // be empty. |port| is the port PairingServer will listen to PairingClient 59 // connections on. |peer_info| must contain non-empty strings for the guid 60 // and name fields. 61 static std::unique_ptr<PairingServer> create(const Data& pswd, const PeerInfo& peer_info, 62 const Data& certificate, const Data& priv_key, 63 int port); 64 65 protected: 66 PairingServer() = default; 67 }; // class PairingServer 68 69 } // namespace pairing 70 } // namespace adbwifi 71