2
* Copyright (C) 2015 Canonical, Ltd.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License version 3, as published
6
* by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranties of
10
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11
* PURPOSE. See the GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License along
14
* with this program. If not, see <http://www.gnu.org/licenses/>.
18
#ifndef NETWORKP2PMANAGERWPASUPPLICANT_H_
19
#define NETWORKP2PMANAGERWPASUPPLICANT_H_
27
#include <mcs/networkdevice.h>
28
#include <mcs/networkmanager.h>
30
#include "dhcpclient.h"
31
#include "dhcpserver.h"
34
#include "commandqueue.h"
35
#include "networkdevice.h"
36
#include "wififirmwareloader.h"
39
class NetworkManager : public mcs::NetworkManager,
40
public CommandQueue::Delegate,
41
public DhcpClient::Delegate,
42
public w11t::WiFiFirmwareLoader::Delegate {
47
void SetDelegate(mcs::NetworkManager::Delegate *delegate) override;
49
bool Setup() override;
51
void SetWfdSubElements(const std::list<std::string> &elements) override;
53
void Scan(const std::chrono::seconds &timeout) override;
55
bool Connect(const mcs::NetworkDevice::Ptr &device) override;
56
bool Disconnect(const mcs::NetworkDevice::Ptr &device) override;
58
mcs::IpV4Address LocalAddress() const override;
59
bool Running() const override;
60
bool Scanning() const override;
61
std::vector<mcs::NetworkDevice::Ptr> Devices() const override;
63
void OnUnsolicitedResponse(Message message);
64
void OnWriteMessage(Message message);
66
void OnAddressAssigned(const mcs::IpV4Address &address);
68
void OnFirmwareLoaded();
69
void OnFirmwareUnloaded();
72
bool StartSupplicant();
73
void StopSupplicant();
74
bool ConnectSupplicant();
75
void DisconnectSupplicant();
76
void RequestAsync(const Message &message, std::function<void(Message)> callback = nullptr);
77
bool CreateSupplicantConfig(const std::string &conf_path);
78
void HandleSupplicantFailed();
80
void AdvanceDeviceState(const NetworkDevice::Ptr &device, mcs::NetworkDeviceState state);
82
void OnP2pDeviceFound(Message &message);
83
void OnP2pDeviceLost(Message &message);
84
void OnP2pGroupStarted(Message &message);
85
void OnP2pGroupRemoved(Message &message);
86
void OnP2pGoNegFailure(Message &message);
87
void OnP2pFindStopped(Message &message);
88
void OnApStaConnected(Message &message);
89
void OnApStaDisconnected(Message &message);
91
static gboolean OnConnectSupplicant(gpointer user_data);
92
static void OnSupplicantWatch(GPid pid, gint status, gpointer user_data);
93
static gboolean OnGroupClientDhcpTimeout(gpointer user_data);
94
static gboolean OnDeviceFailureTimeout(gpointer user_data);
95
static gboolean OnIncomingMessages(GIOChannel *source, GIOCondition condition,
97
static gboolean OnSupplicantRespawn(gpointer user_data);
98
static void OnSupplicantProcessSetup(gpointer user_data);
101
mcs::NetworkManager::Delegate *delegate_;
102
std::string interface_name_;
103
w11t::WiFiFirmwareLoader firmware_loader_;
104
std::string ctrl_path_;
106
std::map<std::string, NetworkDevice::Ptr> available_devices_;
107
std::unique_ptr<CommandQueue> command_queue_;
108
NetworkDevice::Ptr current_peer_;
109
DhcpClient dhcp_client_;
110
DhcpServer dhcp_server_;
111
GPid supplicant_pid_;
112
GIOChannel *channel_;
113
guint channel_watch_;
115
guint respawn_limit_;
116
guint respawn_source_;
117
bool is_group_owner_;