-
Notifications
You must be signed in to change notification settings - Fork 2
/
roam.cpp
executable file
·224 lines (185 loc) · 6.37 KB
/
roam.cpp
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#include <stdint.h>
#include <stddef.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <netlink/genl/genl.h>
#include <netlink/genl/family.h>
#include <netlink/genl/ctrl.h>
#include <linux/rtnetlink.h>
#include <netpacket/packet.h>
#include <linux/filter.h>
#include <linux/errqueue.h>
#include <linux/pkt_sched.h>
#include <netlink/object-api.h>
#include <netlink/netlink.h>
#include <netlink/socket.h>
#include <netlink/handlers.h>
#include "sync.h"
#define LOG_TAG "WifiHAL"
#include <utils/Log.h>
#include "wifi_hal.h"
#include "common.h"
#include "cpp_bindings.h"
#define REQUEST_ID_MAX 1000
#define get_requestid() ((arc4random()%REQUEST_ID_MAX) + 1)
enum roam_attributes {
SLSI_ATTR_ROAM_CAPABILITY_BLACKLIST_SIZE,
SLSI_ATTR_ROAM_CAPABILITY_WHITELIST_SIZE,
SLSI_ATTR_ROAM_STATE
};
class BssidBlacklistCommand : public WifiCommand
{
private:
wifi_bssid_params *mParams;
public:
BssidBlacklistCommand(wifi_interface_handle handle, int id,
wifi_bssid_params *params)
: WifiCommand(handle, id), mParams(params)
{ }
int createRequest(WifiRequest& request) {
int result = request.create(GOOGLE_OUI, SLSI_NL80211_VENDOR_SUBCMD_SET_BSSID_BLACKLIST);
if (result < 0) {
return result;
}
nlattr *data = request.attr_start(NL80211_ATTR_VENDOR_DATA);
result = request.put_u32(GSCAN_ATTRIBUTE_NUM_BSSID, mParams->num_bssid);
if (result < 0) {
return result;
}
for (int i = 0; i < mParams->num_bssid; i++) {
result = request.put_addr(GSCAN_ATTRIBUTE_BLACKLIST_BSSID, mParams->bssids[i]);
if (result < 0) {
return result;
}
}
request.attr_end(data);
return result;
}
int start() {
WifiRequest request(familyId(), ifaceId());
int result = createRequest(request);
if (result < 0) {
return result;
}
result = requestResponse(request);
if (result < 0) {
ALOGE("Failed to execute bssid blacklist request, result = %d", result);
return result;
}
return result;
}
virtual int handleResponse(WifiEvent& reply) {
/* Nothing to do on response! */
return NL_SKIP;
}
};
wifi_error wifi_set_bssid_blacklist(wifi_request_id id, wifi_interface_handle iface,
wifi_bssid_params params)
{
BssidBlacklistCommand *cmd = new BssidBlacklistCommand(iface, id, ¶ms);
wifi_error result = (wifi_error)cmd->start();
//release the reference of command as well
cmd->releaseRef();
return result;
}
class RoamingCapabilitiesCommand : public WifiCommand
{
private:
wifi_roaming_capabilities *mCaps;
public:
RoamingCapabilitiesCommand(wifi_interface_handle handle, wifi_roaming_capabilities *caps)
: WifiCommand(handle, 0) {
mCaps = caps;
}
virtual int create() {
int ret;
ret = mMsg.create(GOOGLE_OUI, SLSI_NL80211_VENDOR_SUBCMD_GET_ROAMING_CAPABILITIES);
if (ret < 0) {
ALOGE("Can't create message to send to driver - %d", ret);
return ret;
}
return WIFI_SUCCESS;
}
virtual int handleResponse(WifiEvent& reply) {
if (reply.get_cmd() != NL80211_CMD_VENDOR) {
ALOGD("Ignore reply; cmd = %d", reply.get_cmd());
return NL_SKIP;
}
nlattr *vendor_data = reply.get_attribute(NL80211_ATTR_VENDOR_DATA);
int len = reply.get_vendor_data_len();
if (vendor_data == NULL || len == 0) {
ALOGE("vendor data in GetFeatureSetCommand missing!!");
return NL_SKIP;
}
for (nl_iterator it(vendor_data); it.has_next(); it.next()) {
switch(it.get_type()) {
case SLSI_ATTR_ROAM_CAPABILITY_BLACKLIST_SIZE:
mCaps->max_blacklist_size = it.get_u32();
break;
case SLSI_ATTR_ROAM_CAPABILITY_WHITELIST_SIZE:
mCaps->max_whitelist_size = it.get_u32();
break;
default :
break;
}
}
return NL_OK;
}
};
wifi_error wifi_get_roaming_capabilities(wifi_interface_handle handle,
wifi_roaming_capabilities *caps)
{
RoamingCapabilitiesCommand cmd(handle, caps);
return (wifi_error) cmd.requestResponse();
}
class RoamingStateCommand : public WifiCommand
{
private:
fw_roaming_state_t mRoamingState;
public:
RoamingStateCommand(wifi_interface_handle handle, fw_roaming_state_t roaming_state)
: WifiCommand(handle, 0) {
mRoamingState = roaming_state;
}
virtual int create() {
int ret;
ret = mMsg.create(GOOGLE_OUI, SLSI_NL80211_VENDOR_SUBCMD_SET_ROAMING_STATE);
if (ret < 0) {
ALOGE("Can't create message to send to driver - %d", ret);
return ret;
}
nlattr *data = mMsg.attr_start(NL80211_ATTR_VENDOR_DATA);
ret = mMsg.put_u8(SLSI_ATTR_ROAM_STATE, mRoamingState);
if (ret < 0) {
return ret;
}
mMsg.attr_end(data);
return WIFI_SUCCESS;
}
};
wifi_error wifi_enable_firmware_roaming(wifi_interface_handle handle, fw_roaming_state_t state) {
RoamingStateCommand cmd(handle, state);
wifi_error ret = (wifi_error) cmd.requestResponse();
return ret;
}
wifi_error wifi_configure_roaming(wifi_interface_handle iface, wifi_roaming_config *roaming_config)
{
wifi_error ret;
int requestId;
wifi_bssid_params bssid_params;
if (!roaming_config) {
ALOGE("%s: Invalid Buffer provided. Exit", __FUNCTION__);
return WIFI_ERROR_INVALID_ARGS;
}
/* Generate request id randomly*/
requestId = get_requestid();
bssid_params.num_bssid = roaming_config->num_blacklist_bssid;
memcpy(bssid_params.bssids, roaming_config->blacklist_bssid,
(bssid_params.num_bssid * sizeof(mac_addr)));
ret = wifi_set_bssid_blacklist(requestId, iface, bssid_params);
if (ret != WIFI_SUCCESS) {
ALOGE("%s: Failed to configure blacklist bssids", __FUNCTION__);
return WIFI_ERROR_UNKNOWN;
}
return ret;
}