netlink_manager.h revision 59ab0a4ec0c5f3124bb63a683a1c46dba21faf3f
17397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang/*
27397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang * Copyright (C) 2016 The Android Open Source Project
37397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang *
47397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang * Licensed under the Apache License, Version 2.0 (the "License");
57397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang * you may not use this file except in compliance with the License.
67397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang * You may obtain a copy of the License at
77397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang *
87397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang *      http://www.apache.org/licenses/LICENSE-2.0
97397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang *
107397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang * Unless required by applicable law or agreed to in writing, software
117397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang * distributed under the License is distributed on an "AS IS" BASIS,
127397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
137397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang * See the License for the specific language governing permissions and
147397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang * limitations under the License.
157397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang */
167397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang
177397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang#ifndef WIFICOND_NET_NETLINK_MANAGER_H_
187397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang#define WIFICOND_NET_NETLINK_MANAGER_H_
197397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang
207397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang#include <functional>
217397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang#include <map>
2221ff4c7ad0b0ec8da8392c00eedbae022d6e21e5Ningyuan Wang#include <memory>
237397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang
240bb07ecdb74d6e9af6271cec1bdc6232d546a878Ningyuan Wang#include <android-base/macros.h>
257397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang#include <android-base/unique_fd.h>
267397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang
277397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang#include "event_loop.h"
287397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang
297397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wangnamespace android {
307397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wangnamespace wificond {
317397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang
32042736e71ac9b9e18c38c00a3d588a5239a1da0fNingyuan Wangclass MlmeEventHandler;
337397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wangclass NL80211Packet;
347397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang
357397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang// Encapsulates all the different things we know about a specific message
367397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang// type like its name, and its id.
377397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wangstruct MessageType {
387397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang   // This constructor is needed by map[key] operation.
397397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang   MessageType() {};
407397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang   explicit MessageType(uint16_t id) {
417397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang     family_id = id;
427397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang   };
437397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang   uint16_t family_id;
447397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang   // Multicast groups supported by the family.  The string and mapping to
457397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang   // a group id are extracted from the CTRL_CMD_NEWFAMILY message.
467397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang   std::map<std::string, uint32_t> groups;
477397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang};
487397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang
49c67d730fd1da7d8290312cd7429221602df76e70Ningyuan Wang// This describes a type of function handling scan results ready notification.
50c67d730fd1da7d8290312cd7429221602df76e70Ningyuan Wang// |interface_index| is the index of interface which the scan results
51c67d730fd1da7d8290312cd7429221602df76e70Ningyuan Wang// are from.
5259ab0a4ec0c5f3124bb63a683a1c46dba21faf3fNingyuan Wang// |aborted| is a boolean indicating if this scan was aborted or not.
5359ab0a4ec0c5f3124bb63a683a1c46dba21faf3fNingyuan Wang// According to nl80211.h document, part of the scan result might still be
5459ab0a4ec0c5f3124bb63a683a1c46dba21faf3fNingyuan Wang// available even when the scan was aborted.
55c67d730fd1da7d8290312cd7429221602df76e70Ningyuan Wang// |ssids| is a vector of scan ssids associated with the corresponding
56c67d730fd1da7d8290312cd7429221602df76e70Ningyuan Wang// scan request.
57c67d730fd1da7d8290312cd7429221602df76e70Ningyuan Wang// |frequencies| is a vector of scan frequencies associated with the
58c67d730fd1da7d8290312cd7429221602df76e70Ningyuan Wang// corresponding scan request.
59c67d730fd1da7d8290312cd7429221602df76e70Ningyuan Wangtypedef std::function<void(
60c67d730fd1da7d8290312cd7429221602df76e70Ningyuan Wang    uint32_t interface_index,
61c9566b1dc5f3bd92e03ed8806e59af9cba2b672fNingyuan Wang    bool aborted,
62c67d730fd1da7d8290312cd7429221602df76e70Ningyuan Wang    std::vector<std::vector<uint8_t>>& ssids,
63c67d730fd1da7d8290312cd7429221602df76e70Ningyuan Wang    std::vector<uint32_t>& frequencies)> OnScanResultsReadyHandler;
64c67d730fd1da7d8290312cd7429221602df76e70Ningyuan Wang
6559ab0a4ec0c5f3124bb63a683a1c46dba21faf3fNingyuan Wang// This describes a type of function handling scheduled scan results ready
6659ab0a4ec0c5f3124bb63a683a1c46dba21faf3fNingyuan Wang// notification. This can also be used for notificating the stopping of a
6759ab0a4ec0c5f3124bb63a683a1c46dba21faf3fNingyuan Wang// scheduled scan.
6859ab0a4ec0c5f3124bb63a683a1c46dba21faf3fNingyuan Wang// |interface_index| is the index of interface which the scan results
6959ab0a4ec0c5f3124bb63a683a1c46dba21faf3fNingyuan Wang// are from.
7059ab0a4ec0c5f3124bb63a683a1c46dba21faf3fNingyuan Wang// |scan_stopped| is a boolean indicating if this scheduled scan was stopped
7159ab0a4ec0c5f3124bb63a683a1c46dba21faf3fNingyuan Wang// or not.
728044a946f4b350291ddd44c52db7ca34e21bad8fNingyuan Wangtypedef std::function<void(
7359ab0a4ec0c5f3124bb63a683a1c46dba21faf3fNingyuan Wang    uint32_t interface_index,
7459ab0a4ec0c5f3124bb63a683a1c46dba21faf3fNingyuan Wang    bool scan_stopped)> OnSchedScanResultsReadyHandler;
758044a946f4b350291ddd44c52db7ca34e21bad8fNingyuan Wang
767397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wangclass NetlinkManager {
777397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang public:
787397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang  explicit NetlinkManager(EventLoop* event_loop);
79e6dce59eaa5f1fcbdfb4b3fc6a60d5cd3b522b06Ningyuan Wang  virtual ~NetlinkManager();
807397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang  // Initialize netlink manager.
817397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang  // This includes setting up socket and requesting nl80211 family id from kernel.
825ea9c07f01b5a7a617dbc99011a5d0952a7a87dbNingyuan Wang  // Returns true on success.
834911e28b6555e42d12027d1b6999654a25feb758Ningyuan Wang  virtual bool Start();
845ea9c07f01b5a7a617dbc99011a5d0952a7a87dbNingyuan Wang  // Returns true if this netlink manager object is started.
854911e28b6555e42d12027d1b6999654a25feb758Ningyuan Wang  virtual bool IsStarted() const;
867397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang  // Returns a sequence number available for use.
874911e28b6555e42d12027d1b6999654a25feb758Ningyuan Wang  virtual uint32_t GetSequenceNumber();
88e6dce59eaa5f1fcbdfb4b3fc6a60d5cd3b522b06Ningyuan Wang  // Get NL80211 netlink family id,
894911e28b6555e42d12027d1b6999654a25feb758Ningyuan Wang  virtual uint16_t GetFamilyId();
9084b17dff63534af6957003f89fd4110c06d100e6Ningyuan Wang
917397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang  // Send |packet| to kernel.
927397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang  // This works in an asynchronous way.
937397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang  // |handler| will be run when we receive a valid reply from kernel.
940c2afe0b1381efea4a2821a51b65fb2a255364d3Ningyuan Wang  // Do not use this asynchronous interface to send a dump request.
957397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang  // Returns true on success.
964911e28b6555e42d12027d1b6999654a25feb758Ningyuan Wang  virtual bool RegisterHandlerAndSendMessage(const NL80211Packet& packet,
9721ff4c7ad0b0ec8da8392c00eedbae022d6e21e5Ningyuan Wang      std::function<void(std::unique_ptr<const NL80211Packet>)> handler);
980c2afe0b1381efea4a2821a51b65fb2a255364d3Ningyuan Wang  // Synchronous version of |RegisterHandlerAndSendMessage|.
990c2afe0b1381efea4a2821a51b65fb2a255364d3Ningyuan Wang  // Returns true on successfully receiving an valid reply.
10084b17dff63534af6957003f89fd4110c06d100e6Ningyuan Wang  // Reply packets will be stored in |*response|.
10121ff4c7ad0b0ec8da8392c00eedbae022d6e21e5Ningyuan Wang  virtual bool SendMessageAndGetResponses(
10221ff4c7ad0b0ec8da8392c00eedbae022d6e21e5Ningyuan Wang      const NL80211Packet& packet,
10321ff4c7ad0b0ec8da8392c00eedbae022d6e21e5Ningyuan Wang      std::vector<std::unique_ptr<const NL80211Packet>>* response);
10484b17dff63534af6957003f89fd4110c06d100e6Ningyuan Wang  // Wrapper of |SendMessageAndGetResponses| for messages with a single
10584b17dff63534af6957003f89fd4110c06d100e6Ningyuan Wang  // response.
10684b17dff63534af6957003f89fd4110c06d100e6Ningyuan Wang  // Returns true on successfully receiving an valid reply.
107f4bed1cc3958c78754997d17cd6fb3839468331dNingyuan Wang  // This will returns false if a NLMSG_ERROR is received.
10884b17dff63534af6957003f89fd4110c06d100e6Ningyuan Wang  // Reply packet will be stored in |*response|.
10984b17dff63534af6957003f89fd4110c06d100e6Ningyuan Wang  virtual bool SendMessageAndGetSingleResponse(
11084b17dff63534af6957003f89fd4110c06d100e6Ningyuan Wang      const NL80211Packet& packet,
11184b17dff63534af6957003f89fd4110c06d100e6Ningyuan Wang      std::unique_ptr<const NL80211Packet>* response);
112f4bed1cc3958c78754997d17cd6fb3839468331dNingyuan Wang
113f4bed1cc3958c78754997d17cd6fb3839468331dNingyuan Wang  // Wrapper of |SendMessageAndGetResponses| for messages with a single
114f4bed1cc3958c78754997d17cd6fb3839468331dNingyuan Wang  // response.
115f4bed1cc3958c78754997d17cd6fb3839468331dNingyuan Wang  // Returns true on successfully receiving an valid reply.
116f4bed1cc3958c78754997d17cd6fb3839468331dNingyuan Wang  // This will returns true if a NLMSG_ERROR is received.
117f4bed1cc3958c78754997d17cd6fb3839468331dNingyuan Wang  // This is useful when the caller needs the error code from kernel.
118f4bed1cc3958c78754997d17cd6fb3839468331dNingyuan Wang  // Reply packet will be stored in |*response|.
119f4bed1cc3958c78754997d17cd6fb3839468331dNingyuan Wang  virtual bool SendMessageAndGetSingleResponseOrError(
120f4bed1cc3958c78754997d17cd6fb3839468331dNingyuan Wang      const NL80211Packet& packet,
121f4bed1cc3958c78754997d17cd6fb3839468331dNingyuan Wang      std::unique_ptr<const NL80211Packet>* response);
122f4bed1cc3958c78754997d17cd6fb3839468331dNingyuan Wang
12384b17dff63534af6957003f89fd4110c06d100e6Ningyuan Wang  // Wrapper of |SendMessageAndGetResponses| for messages that trigger
12484b17dff63534af6957003f89fd4110c06d100e6Ningyuan Wang  // only a NLMSG_ERROR response
12584b17dff63534af6957003f89fd4110c06d100e6Ningyuan Wang  // Returns true if the message is successfully sent and a NLMSG_ERROR response
12684b17dff63534af6957003f89fd4110c06d100e6Ningyuan Wang  // comes back, regardless of the error code.
12784b17dff63534af6957003f89fd4110c06d100e6Ningyuan Wang  // Error code will be stored in |*error_code|
12884b17dff63534af6957003f89fd4110c06d100e6Ningyuan Wang  virtual bool SendMessageAndGetAckOrError(const NL80211Packet& packet,
12984b17dff63534af6957003f89fd4110c06d100e6Ningyuan Wang                                           int* error_code);
13084b17dff63534af6957003f89fd4110c06d100e6Ningyuan Wang  // Wrapper of |SendMessageAndGetResponses| that returns true iff the response
13184b17dff63534af6957003f89fd4110c06d100e6Ningyuan Wang  // is an ACK.
13284b17dff63534af6957003f89fd4110c06d100e6Ningyuan Wang  virtual bool SendMessageAndGetAck(const NL80211Packet& packet);
1337397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang
134c67d730fd1da7d8290312cd7429221602df76e70Ningyuan Wang  // Sign up to receive and log multicast events of a specific type.
1351cd71d54940f028c1881c0962ff18ace2c94d9f3Ningyuan Wang  // |group| is one of the string NL80211_MULTICAST_GROUP_* in nl80211.h.
1361cd71d54940f028c1881c0962ff18ace2c94d9f3Ningyuan Wang  virtual bool SubscribeToEvents(const std::string& group);
1371cd71d54940f028c1881c0962ff18ace2c94d9f3Ningyuan Wang
138c67d730fd1da7d8290312cd7429221602df76e70Ningyuan Wang  // Sign up to be notified when new scan results are available.
139c67d730fd1da7d8290312cd7429221602df76e70Ningyuan Wang  // |handler| will be called when the kernel signals to wificond that a scan
140c67d730fd1da7d8290312cd7429221602df76e70Ningyuan Wang  // has been completed on the given |interface_index|.  See the declaration of
141c67d730fd1da7d8290312cd7429221602df76e70Ningyuan Wang  // OnScanResultsReadyHandler for documentation on the semantics of this
142c67d730fd1da7d8290312cd7429221602df76e70Ningyuan Wang  // callback.
1438044a946f4b350291ddd44c52db7ca34e21bad8fNingyuan Wang  // Only one handler can be registered per interface index.
1448044a946f4b350291ddd44c52db7ca34e21bad8fNingyuan Wang  // New handler will replace the registered handler if they are for the
1458044a946f4b350291ddd44c52db7ca34e21bad8fNingyuan Wang  // same interface index.
146c67d730fd1da7d8290312cd7429221602df76e70Ningyuan Wang  virtual void SubscribeScanResultNotification(
147c67d730fd1da7d8290312cd7429221602df76e70Ningyuan Wang      uint32_t interface_index,
148c67d730fd1da7d8290312cd7429221602df76e70Ningyuan Wang      OnScanResultsReadyHandler handler);
149c67d730fd1da7d8290312cd7429221602df76e70Ningyuan Wang
150c67d730fd1da7d8290312cd7429221602df76e70Ningyuan Wang  // Cancel the sign-up of receiving new scan result notification from
151c67d730fd1da7d8290312cd7429221602df76e70Ningyuan Wang  // interface with index |interface_index|.
152c67d730fd1da7d8290312cd7429221602df76e70Ningyuan Wang  virtual void UnsubscribeScanResultNotification(uint32_t interface_index);
153c67d730fd1da7d8290312cd7429221602df76e70Ningyuan Wang
154042736e71ac9b9e18c38c00a3d588a5239a1da0fNingyuan Wang  // Sign up to be notified when there is MLME event.
155042736e71ac9b9e18c38c00a3d588a5239a1da0fNingyuan Wang  // Only one handler can be registered per interface index.
156042736e71ac9b9e18c38c00a3d588a5239a1da0fNingyuan Wang  // New handler will replace the registered handler if they are for the
157042736e71ac9b9e18c38c00a3d588a5239a1da0fNingyuan Wang  // same interface index.
158042736e71ac9b9e18c38c00a3d588a5239a1da0fNingyuan Wang  // NetlinkManager is not going to take ownership of this pointer, and that it
159042736e71ac9b9e18c38c00a3d588a5239a1da0fNingyuan Wang  // is the caller's responsibility to make sure that the object exists for the
160042736e71ac9b9e18c38c00a3d588a5239a1da0fNingyuan Wang  // duration of the subscription.
161042736e71ac9b9e18c38c00a3d588a5239a1da0fNingyuan Wang  virtual void SubscribeMlmeEvent(uint32_t interface_index,
162042736e71ac9b9e18c38c00a3d588a5239a1da0fNingyuan Wang                                  MlmeEventHandler* handler);
163042736e71ac9b9e18c38c00a3d588a5239a1da0fNingyuan Wang
164042736e71ac9b9e18c38c00a3d588a5239a1da0fNingyuan Wang  // Cancel the sign-up of receiving MLME event notification
165042736e71ac9b9e18c38c00a3d588a5239a1da0fNingyuan Wang  // from interface with index |interface_index|.
166042736e71ac9b9e18c38c00a3d588a5239a1da0fNingyuan Wang  virtual void UnsubscribeMlmeEvent(uint32_t interface_index);
167042736e71ac9b9e18c38c00a3d588a5239a1da0fNingyuan Wang
1688044a946f4b350291ddd44c52db7ca34e21bad8fNingyuan Wang  // Sign up to be notified when new scan results are available.
1698044a946f4b350291ddd44c52db7ca34e21bad8fNingyuan Wang  // |handler| will be called when the kernel signals to wificond that a
1708044a946f4b350291ddd44c52db7ca34e21bad8fNingyuan Wang  // scheduled scan has been completed on the given |interface_index|.
1718044a946f4b350291ddd44c52db7ca34e21bad8fNingyuan Wang  // See the declaration of OnSchedScanResultsReadyHandler for documentation
1728044a946f4b350291ddd44c52db7ca34e21bad8fNingyuan Wang  // on the semantics of this callback.
1738044a946f4b350291ddd44c52db7ca34e21bad8fNingyuan Wang  // Only one handler can be registered per interface index.
1748044a946f4b350291ddd44c52db7ca34e21bad8fNingyuan Wang  // New handler will replace the registered handler if they are for the
1758044a946f4b350291ddd44c52db7ca34e21bad8fNingyuan Wang  // same interface index.
1768044a946f4b350291ddd44c52db7ca34e21bad8fNingyuan Wang  virtual void SubscribeSchedScanResultNotification(
1778044a946f4b350291ddd44c52db7ca34e21bad8fNingyuan Wang      uint32_t interface_index,
1788044a946f4b350291ddd44c52db7ca34e21bad8fNingyuan Wang      OnSchedScanResultsReadyHandler handler);
1798044a946f4b350291ddd44c52db7ca34e21bad8fNingyuan Wang
1808044a946f4b350291ddd44c52db7ca34e21bad8fNingyuan Wang  // Cancel the sign-up of receiving new scheduled scan result notification from
1818044a946f4b350291ddd44c52db7ca34e21bad8fNingyuan Wang  // interface with index |interface_index|.
1828044a946f4b350291ddd44c52db7ca34e21bad8fNingyuan Wang  virtual void UnsubscribeSchedScanResultNotification(uint32_t interface_index);
1838044a946f4b350291ddd44c52db7ca34e21bad8fNingyuan Wang
1847397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang private:
1850c2afe0b1381efea4a2821a51b65fb2a255364d3Ningyuan Wang  bool SetupSocket(android::base::unique_fd* netlink_fd);
1860c2afe0b1381efea4a2821a51b65fb2a255364d3Ningyuan Wang  bool WatchSocket(android::base::unique_fd* netlink_fd);
1870c2afe0b1381efea4a2821a51b65fb2a255364d3Ningyuan Wang  void ReceivePacketAndRunHandler(int fd);
1887397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang  bool DiscoverFamilyId();
1890c2afe0b1381efea4a2821a51b65fb2a255364d3Ningyuan Wang  bool SendMessageInternal(const NL80211Packet& packet, int fd);
19021ff4c7ad0b0ec8da8392c00eedbae022d6e21e5Ningyuan Wang  void BroadcastHandler(std::unique_ptr<const NL80211Packet> packet);
191042736e71ac9b9e18c38c00a3d588a5239a1da0fNingyuan Wang  void OnMlmeEvent(std::unique_ptr<const NL80211Packet> packet);
19221ff4c7ad0b0ec8da8392c00eedbae022d6e21e5Ningyuan Wang  void OnScanResultsReady(std::unique_ptr<const NL80211Packet> packet);
1938044a946f4b350291ddd44c52db7ca34e21bad8fNingyuan Wang  void OnSchedScanResultsReady(std::unique_ptr<const NL80211Packet> packet);
1947397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang
1957397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang  // This handler revceives mapping from NL80211 family name to family id,
1967397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang  // as well as mapping from group name to group id.
1977397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang  // These mappings are allocated by kernel.
19821ff4c7ad0b0ec8da8392c00eedbae022d6e21e5Ningyuan Wang  void OnNewFamily(std::unique_ptr<const NL80211Packet> packet);
1997397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang
2005ea9c07f01b5a7a617dbc99011a5d0952a7a87dbNingyuan Wang  bool started_;
2010c2afe0b1381efea4a2821a51b65fb2a255364d3Ningyuan Wang  // We use different sockets for synchronous and asynchronous interfaces.
2020c2afe0b1381efea4a2821a51b65fb2a255364d3Ningyuan Wang  // Kernel will reply error message when we start a new request in the
2030c2afe0b1381efea4a2821a51b65fb2a255364d3Ningyuan Wang  // middle of a dump request.
2040c2afe0b1381efea4a2821a51b65fb2a255364d3Ningyuan Wang  // Using different sockets help us avoid the complexity of message
2050c2afe0b1381efea4a2821a51b65fb2a255364d3Ningyuan Wang  // rescheduling.
2060c2afe0b1381efea4a2821a51b65fb2a255364d3Ningyuan Wang  android::base::unique_fd sync_netlink_fd_;
2070c2afe0b1381efea4a2821a51b65fb2a255364d3Ningyuan Wang  android::base::unique_fd async_netlink_fd_;
2087397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang  EventLoop* event_loop_;
2097397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang
2107397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang  // This is a collection of message handlers, for each sequence number.
21121ff4c7ad0b0ec8da8392c00eedbae022d6e21e5Ningyuan Wang  std::map<uint32_t,
21221ff4c7ad0b0ec8da8392c00eedbae022d6e21e5Ningyuan Wang      std::function<void(std::unique_ptr<const NL80211Packet>)>> message_handlers_;
2137397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang
214c67d730fd1da7d8290312cd7429221602df76e70Ningyuan Wang  // A mapping from interface index to the handler registered to receive
215c67d730fd1da7d8290312cd7429221602df76e70Ningyuan Wang  // scan results notifications.
216c67d730fd1da7d8290312cd7429221602df76e70Ningyuan Wang  std::map<uint32_t, OnScanResultsReadyHandler> on_scan_result_ready_handler_;
2178044a946f4b350291ddd44c52db7ca34e21bad8fNingyuan Wang  // A mapping from interface index to the handler registered to receive
2188044a946f4b350291ddd44c52db7ca34e21bad8fNingyuan Wang  // scheduled scan results notifications.
2198044a946f4b350291ddd44c52db7ca34e21bad8fNingyuan Wang  std::map<uint32_t, OnSchedScanResultsReadyHandler>
2208044a946f4b350291ddd44c52db7ca34e21bad8fNingyuan Wang      on_sched_scan_result_ready_handler_;
221c67d730fd1da7d8290312cd7429221602df76e70Ningyuan Wang
222042736e71ac9b9e18c38c00a3d588a5239a1da0fNingyuan Wang  std::map<uint32_t, MlmeEventHandler*> on_mlme_event_handler_;
223042736e71ac9b9e18c38c00a3d588a5239a1da0fNingyuan Wang
2247397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang  // Mapping from family name to family id, and group name to group id.
2257397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang  std::map<std::string, MessageType> message_types_;
2267397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang
2277397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang  uint32_t sequence_number_;
2280bb07ecdb74d6e9af6271cec1bdc6232d546a878Ningyuan Wang
2290bb07ecdb74d6e9af6271cec1bdc6232d546a878Ningyuan Wang  DISALLOW_COPY_AND_ASSIGN(NetlinkManager);
2307397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang};
2317397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang
2327397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang}  // namespace wificond
2337397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang}  // namespace android
2347397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang
2357397e6b7c3635e2121f6d2229557e684bc4756cfNingyuan Wang#endif  // WIFICOND_NET_NETLINK_MANAGER_H_
236