-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReport.cpp
More file actions
165 lines (137 loc) · 3.86 KB
/
Copy pathReport.cpp
File metadata and controls
165 lines (137 loc) · 3.86 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
* Report.cpp
*
*/
#include "Report.h"
#include "hostap.h"
#include <iostream>
#include <iomanip>
#include <sstream>
#include <time.h>
using namespace std;
string Report::PrintTime(){
m_ptm = localtime(&m_time);
string strTime = asctime(m_ptm);
strTime.erase(strTime.length()-5);
return strTime;
}
Report::Report() {
// TODO Auto-generated constructor stub
Initialize();
}
Report::Report(hostap* ap) {
// TODO Auto-generated constructor stub
m_ap = ap;
Initialize();
}
Report::~Report() {
// TODO Auto-generated destructor stub
}
/***********************************************
*void Report::Initialize()
* Make connection with OpenWinNet Manager
* Send Wake-Up Message to OpenWinNet Manager
* Receive Wake-Up-Response Message.
********************************************/
void Report::Initialize() {
// Make connection with OpenWinNetManager
cout << "sock create" << endl;
m_sock.create();
m_sock.connect("127.0.0.1", PORT_NUMBER);
cout << "sock connetcted" << endl;
string msg;
Packet pkt;
// Get AP Information from hardware.
m_APInfo.UpdateAPInformation();
m_APInfo.SetAPInformation(AP_PASSWORD, m_ap->get_pwd());
if(m_ap->get_hide() == "1" )
m_APInfo.SetAPInformation(AP_HIDE, "on");
else
m_APInfo.SetAPInformation(AP_HIDE, "off");
m_APInfo.SetAPInformation(AP_CHANNEL, m_ap->get_channel());
// Send AP-Registration-Request Message to OpenWinNetManager
SendAPRegistrationRequest();
// Receive Response about Request message.
while(true){
m_sock.recv(msg);
if(msg != ""){
pkt.Parse(msg);
if(pkt.m_MsgType == AP_REGISTRATION_RESPONSE){
cout << PrintTime() << "[R] AP_REGISTRATION_RESPONSE" << endl;
break;
}
}
}
// Send AP_STATE_UPDATE_REQUEST Message.
while(true){
sleep(UPDATE_TIME); // check report.h to find update_time
m_APInfo.UpdateAPInformation();
m_APInfo.SetAPInformation(AP_PASSWORD, m_ap->get_pwd());
m_APInfo.SetAPInformation(AP_CHANNEL, m_ap->get_channel());
if(m_ap->get_hide() == "1" )
m_APInfo.SetAPInformation(AP_HIDE, "on");
else
m_APInfo.SetAPInformation(AP_HIDE, "off");
SendAPStateUpdateRequest();
// Receive Response about Request message.
while(true){
m_sock.recv(msg);
cout << msg << endl;
if(msg != ""){
pkt.Parse(msg);
if(pkt.m_MsgType == AP_STATE_UPDATE_RESPONSE){
cout << PrintTime() << "[R] AP_STATE_UPDATE_RESPONSE" << endl;
break;
}
}
}
}
}
/***********************************************
*void Report::SendAPRegistrationRequest()
* Make AP Registration Request
* Send Message to Manager
* Receive ACK from Manager
********************************************/
void Report::SendAPRegistrationRequest(){
//Make Message
Packet pkt;
pkt.DecideMessageType(AP_REGISTRATION_REQUEST);
for(int type=AP_ID; type<=AP_CHANNEL; type++){
pkt.AddValue(type, m_APInfo.GetAPInformation(type));
}
/*
for(int type=AP_ID; type<=AP_DESCRIPTION; type++){
pkt.AddValue(type, m_APInfo.GetAPInformation(type));
}
*/
string msg = pkt.CreateMessage();
//Send Message to OpenWinNet Manager
cout << PrintTime() << "[S] AP_REGISTRATION_REQUEST" << endl;
m_sock.send(msg);
cout << "Send.." << endl;
msg.clear();
}
/***********************************************
*void Report::SendAPUpdateRequest()
* Make AP Update Request
* Send Message to Manager
* Receive ACK from Manager
********************************************/
void Report::SendAPStateUpdateRequest(){
//Make Message
Packet pkt;
pkt.DecideMessageType(AP_STATE_UPDATE_REQUEST);
for(int type=AP_ID; type<=AP_CHANNEL; type++){
pkt.AddValue(type, m_APInfo.GetAPInformation(type));
}
/*
for(int type=AP_ID; type<=AP_DESCRIPTION; type++){
pkt.AddValue(type, m_APInfo.GetAPInformation(type));
}*/
string msg = pkt.CreateMessage();
//Send Message to OpenWinNet Manager
cout << PrintTime() << "[S] AP_STATE_UPDATE REQUEST" << endl;
m_sock.send(msg);
msg.clear();
}