• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (C) 2015 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 #ifndef SHILL_WIFI_TDLS_MANAGER_H_
18 #define SHILL_WIFI_TDLS_MANAGER_H_
19 
20 #include <map>
21 #include <string>
22 
23 #include <base/cancelable_callback.h>
24 
25 namespace shill {
26 
27 class Error;
28 class EventDispatcher;
29 class SupplicantInterfaceProxyInterface;
30 
31 // Manage TDLS peers for the specified interface |interface_name|.
32 class TDLSManager {
33  public:
34   TDLSManager(EventDispatcher* dispatcher,
35               SupplicantInterfaceProxyInterface* supplicant_interface_proxy,
36               const std::string& interface_name);
37   virtual ~TDLSManager();
38 
39   // Perform TDLS |operation| on |peer|.
40   virtual std::string PerformOperation(const std::string& peer_mac_address,
41                                        const std::string& operation,
42                                        Error* error);
43 
44   // Called when a discover response for |peer_mac_address| is received.
45   virtual void OnDiscoverResponseReceived(const std::string& peer_mac_address);
46 
interface_name()47   const std::string& interface_name() const { return interface_name_; }
48 
49  private:
50   friend class TDLSManagerTest;
51 
52   enum class PeerDiscoveryState {
53     kNone,
54     kRequestSent,
55     kResponseReceived
56   };
57 
58   static const int kPeerDiscoveryCleanupTimeoutSeconds;
59 
60   // Discover TDLS service on a remote |peer_mac_address|.  Returns true if
61   // operation is initiated successfully.
62   bool DiscoverPeer(const std::string& peer_mac_address);
63 
64   // Setup a TDLS pairing with |peer_mac_address|.  Returns true if operation is
65   // initiated successfully.
66   bool SetupPeer(const std::string& peer_mac_address);
67 
68   // Tear down the TDLS pairing with |peer|.  Returns true if operation is
69   // initiated successfully.
70   bool TearDownPeer(const std::string& peer_mac_address);
71 
72   // Return a string indicating the TDLS status with |peer_mac_address|.
73   std::string PeerStatus(const std::string& peer_mac_address);
74 
75   // Start the timer to delete any peer entries stored in our peer discovery
76   // map.
77   void StartPeerDiscoveryCleanupTimer();
78 
79   // Timeout handler to delete any peer entries from our peer discovery map.
80   void PeerDiscoveryCleanup();
81 
82   // Returns the TDLS discover status for this peer
83   PeerDiscoveryState CheckDiscoveryState(const std::string& peer_mac_address);
84 
85   // Executes when the TDLS peer discovery cleanup timer expires.
86   base::CancelableClosure peer_discovery_cleanup_callback_;
87 
88   // Maps peer to its discovery state.
89   std::map<std::string, PeerDiscoveryState> peer_discovery_state_;
90 
91   EventDispatcher* dispatcher_;
92   SupplicantInterfaceProxyInterface* supplicant_interface_proxy_;
93   std::string interface_name_;
94 
95   DISALLOW_COPY_AND_ASSIGN(TDLSManager);
96 };
97 
98 }  // namespace shill
99 
100 #endif  // SHILL_WIFI_TDLS_MANAGER_H_
101