1 /* 2 * Copyright (C) 2017 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 #pragma once 17 18 #include <memory> 19 #include <thread> 20 21 #include <netlink/genl/genl.h> 22 #include "common/libs/wifi/nl_client.h" 23 #include "common/libs/wifi/wr_client.h" 24 25 namespace cvd { 26 // Netlink provides access to relevant netlink backends and resources. 27 class Netlink { 28 public: 29 Netlink(const std::string& wifirouter_socket); 30 ~Netlink() = default; 31 32 // Initialize instance of Netlink Factory. 33 bool Init(); 34 35 // Getter for NETLINK_GENERIC NlClient instance. 36 NlClient& GeNL() { return genl_; } 37 38 // Getter for NETLINK_ROUTE NlClient instance. 39 NlClient& RtNL() { return rtnl_; } 40 41 WRClient& WRCL() { return wrcl_; } 42 43 // Access Family ID for MAC80211 (WIFI Simulator). 44 int FamilyMAC80211() const { return mac80211_hwsim_family_; } 45 46 // Access Family ID for NL80211 (WIFI management). 47 int FamilyNL80211() const { return nl80211_family_; } 48 49 private: 50 // Loop and process all incoming netlink messages. 51 // This function will trigger calls to NlClient's OnResponse() which handles 52 // incoming netlink messages. 53 void HandleNetlinkMessages(); 54 55 NlClient genl_; 56 NlClient rtnl_; 57 WRClient wrcl_; 58 59 int mac80211_hwsim_family_ = 0; 60 #if 0 61 int router_family_ = 0; 62 #endif 63 int nl80211_family_ = 0; 64 65 Netlink(const Netlink&) = delete; 66 Netlink& operator=(const Netlink&) = delete; 67 }; 68 69 } // namespace cvd 70