forked from rdkcentral/networkmanager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NetworkManagerGnomeWIFI.h
111 lines (101 loc) · 3.71 KB
/
NetworkManagerGnomeWIFI.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
* If not stated otherwise in this file or this component's LICENSE file the
* following copyright and licenses apply:
*
* Copyright 2020 RDK Management
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <NetworkManager.h>
#include <libnm/NetworkManager.h>
#include "NetworkManagerLogger.h"
#include "INetworkManager.h"
#include <iostream>
#include <glib.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <atomic>
#define WPA_SUPPLICANT_CONF "/opt/secure/wifi/wpa_supplicant.conf"
#define WPA_CLI_STATUS "wpa_cli status"
#define MAX_WPS_AP_COUNT 3
#define MAX_WPS_WAIT_DURATION 120
typedef struct _wifi_wps_pbc_ap
{
char bssid[32];
char ssid[32];
} wifi_wps_pbc_ap_t;
namespace WPEFramework
{
namespace Plugin
{
class wifiManager
{
public:
static wifiManager* getInstance()
{
static wifiManager instance;
return &instance;
}
bool isWifiConnected();
bool wifiDisconnect();
bool wifiConnectedSSIDInfo(Exchange::INetworkManager::WiFiSSIDInfo &ssidinfo);
bool wifiConnect(Exchange::INetworkManager::WiFiConnectTo wifiData);
bool wifiScanRequest(std::string ssidReq = "");
bool isWifiScannedRecently(int timelimitInSec = 5); // default 10 sec as shotest scanning interval
bool getKnownSSIDs(std::list<string>& ssids);
bool addToKnownSSIDs(const Exchange::INetworkManager::WiFiConnectTo ssidinfo);
bool removeKnownSSID(const string& ssid);
bool quit(NMDevice *wifiNMDevice);
bool wait(GMainLoop *loop, int timeOutMs = 10000); // default maximium set as 10 sec
bool initiateWPS();
bool cancelWPS();
void wpsAction();
std::string executeWpaCliCommand(const std::string& wpaCliCommand);
bool setInterfaceState(std::string interface, bool enabled);
bool setIpSettings(const string interface, const Exchange::INetworkManager::IPAddress address);
private:
NMDevice *getWifiDevice();
private:
wifiManager();
~wifiManager() {
NMLOG_INFO("~wifiManager");
g_main_context_pop_thread_default(m_nmContext);
if(m_client != NULL) {
g_object_unref(m_client);
m_client = NULL;
}
if(m_loop != NULL) {
g_main_loop_unref(m_loop);
m_loop = NULL;
}
}
wifiManager(wifiManager const&) = delete;
void operator=(wifiManager const&) = delete;
bool createClientNewConnection();
std::atomic<bool> wpsStop = {false};
std::thread wpsThread;
public:
NMClient *m_client;
GMainLoop *m_loop;
gboolean m_createNewConnection;
GMainContext *m_nmContext = nullptr;
GMainContext *m_wpsContext = nullptr;
const char* m_objectPath;
NMDevice *m_wifidevice;
GSource *m_source;
bool m_isSuccess = false;
};
} // Plugin
} // WPEFramework