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 17 #pragma once 18 19 #include "macaddress.h" 20 #include "pollable.h" 21 #include "result.h" 22 23 #include <string> 24 #include <unordered_set> 25 26 struct Ieee80211Header; 27 struct pcap; 28 typedef struct pcap pcap_t; 29 30 class WifiForwarder : public Pollable { 31 public: 32 explicit WifiForwarder(const char* monitorInterfaceName); 33 ~WifiForwarder(); 34 35 Result init(); 36 37 // Pollable interface 38 void getPollData(std::vector<pollfd>* fds) const override; 39 Timestamp getTimeout() const override; 40 bool onReadAvailable(int fd, int* status) override; 41 bool onClose(int fd, int* status) override; 42 bool onTimeout(int* status) override; 43 private: 44 void forwardFromPcap(); 45 void injectFromPipe(); 46 void cleanup(); 47 48 std::string mInterfaceName; 49 Pollable::Timestamp mDeadline; 50 std::vector<unsigned char> mMonitorBuffer; 51 pcap_t* mMonitorPcap; 52 int mPipeFd; 53 }; 54