~morphis/aethercast/enable-arm64-builds

« back to all changes in this revision

Viewing changes to src/w11t/networkmanager.h

  • Committer: Tarmac
  • Author(s): Simon Fels
  • Date: 2016-02-04 06:38:31 UTC
  • mfrom: (119.1.65 trunk)
  • Revision ID: tarmac-20160204063831-b6q9o8ktznevvd8x
Add a network manager implementation to use the DBus interface of wpa-supplicant.

Approved by PS Jenkins bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2015 Canonical, Ltd.
3
 
 *
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.
7
 
 *
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.
12
 
 *
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/>.
15
 
 *
16
 
 */
17
 
 
18
 
#ifndef NETWORKP2PMANAGERWPASUPPLICANT_H_
19
 
#define NETWORKP2PMANAGERWPASUPPLICANT_H_
20
 
 
21
 
#include <functional>
22
 
#include <memory>
23
 
#include <map>
24
 
 
25
 
#include <glib.h>
26
 
 
27
 
#include <mcs/networkdevice.h>
28
 
#include <mcs/networkmanager.h>
29
 
 
30
 
#include "dhcpclient.h"
31
 
#include "dhcpserver.h"
32
 
 
33
 
#include "message.h"
34
 
#include "commandqueue.h"
35
 
#include "networkdevice.h"
36
 
#include "wififirmwareloader.h"
37
 
 
38
 
namespace w11t {
39
 
class NetworkManager : public mcs::NetworkManager,
40
 
                                    public CommandQueue::Delegate,
41
 
                                    public DhcpClient::Delegate,
42
 
                                    public w11t::WiFiFirmwareLoader::Delegate {
43
 
public:
44
 
    NetworkManager();
45
 
    ~NetworkManager();
46
 
 
47
 
    void SetDelegate(mcs::NetworkManager::Delegate *delegate) override;
48
 
 
49
 
    bool Setup() override;
50
 
 
51
 
    void SetWfdSubElements(const std::list<std::string> &elements) override;
52
 
 
53
 
    void Scan(const std::chrono::seconds &timeout) override;
54
 
 
55
 
    bool Connect(const mcs::NetworkDevice::Ptr &device) override;
56
 
    bool Disconnect(const mcs::NetworkDevice::Ptr &device) override;
57
 
 
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;
62
 
 
63
 
    void OnUnsolicitedResponse(Message message);
64
 
    void OnWriteMessage(Message message);
65
 
 
66
 
    void OnAddressAssigned(const mcs::IpV4Address &address);
67
 
 
68
 
    void OnFirmwareLoaded();
69
 
    void OnFirmwareUnloaded();
70
 
 
71
 
private:
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();
79
 
    void Reset();
80
 
    void AdvanceDeviceState(const NetworkDevice::Ptr &device, mcs::NetworkDeviceState state);
81
 
 
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);
90
 
 
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,
96
 
                                         gpointer user_data);
97
 
    static gboolean OnSupplicantRespawn(gpointer user_data);
98
 
    static void OnSupplicantProcessSetup(gpointer user_data);
99
 
 
100
 
private:
101
 
    mcs::NetworkManager::Delegate *delegate_;
102
 
    std::string interface_name_;
103
 
    w11t::WiFiFirmwareLoader firmware_loader_;
104
 
    std::string ctrl_path_;
105
 
    int sock_;
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_;
114
 
    guint dhcp_timeout_;
115
 
    guint respawn_limit_;
116
 
    guint respawn_source_;
117
 
    bool is_group_owner_;
118
 
    bool scanning_;
119
 
};
120
 
}
121
 
#endif