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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
|
/*
* Copyright (C) 2016 The Android Open Source Project
*
* 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.
*/
#include <android-base/logging.h>
#include "hidl_return_util.h"
#include "wifi_chip.h"
#include "wifi_status_util.h"
namespace {
using android::sp;
using android::hardware::hidl_vec;
using android::hardware::hidl_string;
template <typename Iface>
void invalidateAndClear(sp<Iface>& iface) {
if (iface.get()) {
iface->invalidate();
iface.clear();
}
}
} // namepsace
namespace android {
namespace hardware {
namespace wifi {
namespace V1_0 {
namespace implementation {
using hidl_return_util::validateAndCall;
WifiChip::WifiChip(ChipId chip_id,
const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal)
: chip_id_(chip_id), legacy_hal_(legacy_hal), is_valid_(true) {}
void WifiChip::invalidate() {
invalidateAndRemoveAllIfaces();
legacy_hal_.reset();
event_callbacks_.clear();
is_valid_ = false;
}
bool WifiChip::isValid() {
return is_valid_;
}
Return<void> WifiChip::getId(getId_cb hidl_status_cb) {
return validateAndCall(this,
WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
&WifiChip::getIdInternal,
hidl_status_cb);
}
Return<void> WifiChip::registerEventCallback(
const sp<IWifiChipEventCallback>& event_callback,
registerEventCallback_cb hidl_status_cb) {
return validateAndCall(this,
WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
&WifiChip::registerEventCallbackInternal,
hidl_status_cb,
event_callback);
}
Return<void> WifiChip::getCapabilities(getCapabilities_cb hidl_status_cb) {
return validateAndCall(this,
WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
&WifiChip::getCapabilitiesInternal,
hidl_status_cb);
}
Return<void> WifiChip::getAvailableModes(getAvailableModes_cb hidl_status_cb) {
return validateAndCall(this,
WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
&WifiChip::getAvailableModesInternal,
hidl_status_cb);
}
Return<void> WifiChip::configureChip(uint32_t mode_id,
configureChip_cb hidl_status_cb) {
return validateAndCall(this,
WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
&WifiChip::configureChipInternal,
hidl_status_cb,
mode_id);
}
Return<void> WifiChip::getMode(getMode_cb hidl_status_cb) {
return validateAndCall(this,
WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
&WifiChip::getModeInternal,
hidl_status_cb);
}
Return<void> WifiChip::requestChipDebugInfo(
requestChipDebugInfo_cb hidl_status_cb) {
return validateAndCall(this,
WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
&WifiChip::requestChipDebugInfoInternal,
hidl_status_cb);
}
Return<void> WifiChip::requestDriverDebugDump(
requestDriverDebugDump_cb hidl_status_cb) {
return validateAndCall(this,
WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
&WifiChip::requestDriverDebugDumpInternal,
hidl_status_cb);
}
Return<void> WifiChip::requestFirmwareDebugDump(
requestFirmwareDebugDump_cb hidl_status_cb) {
return validateAndCall(this,
WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
&WifiChip::requestFirmwareDebugDumpInternal,
hidl_status_cb);
}
Return<void> WifiChip::createApIface(createApIface_cb hidl_status_cb) {
return validateAndCall(this,
WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
&WifiChip::createApIfaceInternal,
hidl_status_cb);
}
Return<void> WifiChip::getApIfaceNames(getApIfaceNames_cb hidl_status_cb) {
return validateAndCall(this,
WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
&WifiChip::getApIfaceNamesInternal,
hidl_status_cb);
}
Return<void> WifiChip::getApIface(const hidl_string& ifname,
getApIface_cb hidl_status_cb) {
return validateAndCall(this,
WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
&WifiChip::getApIfaceInternal,
hidl_status_cb,
ifname);
}
Return<void> WifiChip::createNanIface(createNanIface_cb hidl_status_cb) {
return validateAndCall(this,
WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
&WifiChip::createNanIfaceInternal,
hidl_status_cb);
}
Return<void> WifiChip::getNanIfaceNames(getNanIfaceNames_cb hidl_status_cb) {
return validateAndCall(this,
WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
&WifiChip::getNanIfaceNamesInternal,
hidl_status_cb);
}
Return<void> WifiChip::getNanIface(const hidl_string& ifname,
getNanIface_cb hidl_status_cb) {
return validateAndCall(this,
WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
&WifiChip::getNanIfaceInternal,
hidl_status_cb,
ifname);
}
Return<void> WifiChip::createP2pIface(createP2pIface_cb hidl_status_cb) {
return validateAndCall(this,
WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
&WifiChip::createP2pIfaceInternal,
hidl_status_cb);
}
Return<void> WifiChip::getP2pIfaceNames(getP2pIfaceNames_cb hidl_status_cb) {
return validateAndCall(this,
WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
&WifiChip::getP2pIfaceNamesInternal,
hidl_status_cb);
}
Return<void> WifiChip::getP2pIface(const hidl_string& ifname,
getP2pIface_cb hidl_status_cb) {
return validateAndCall(this,
WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
&WifiChip::getP2pIfaceInternal,
hidl_status_cb,
ifname);
}
Return<void> WifiChip::createStaIface(createStaIface_cb hidl_status_cb) {
return validateAndCall(this,
WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
&WifiChip::createStaIfaceInternal,
hidl_status_cb);
}
Return<void> WifiChip::getStaIfaceNames(getStaIfaceNames_cb hidl_status_cb) {
return validateAndCall(this,
WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
&WifiChip::getStaIfaceNamesInternal,
hidl_status_cb);
}
Return<void> WifiChip::getStaIface(const hidl_string& ifname,
getStaIface_cb hidl_status_cb) {
return validateAndCall(this,
WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
&WifiChip::getStaIfaceInternal,
hidl_status_cb,
ifname);
}
Return<void> WifiChip::createRttController(
const sp<IWifiIface>& bound_iface, createRttController_cb hidl_status_cb) {
return validateAndCall(this,
WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
&WifiChip::createRttControllerInternal,
hidl_status_cb,
bound_iface);
}
Return<void> WifiChip::getDebugRingBuffersStatus(
getDebugRingBuffersStatus_cb hidl_status_cb) {
return validateAndCall(this,
WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
&WifiChip::getDebugRingBuffersStatusInternal,
hidl_status_cb);
}
Return<void> WifiChip::startLoggingToDebugRingBuffer(
const hidl_string& ring_name,
WifiDebugRingBufferVerboseLevel verbose_level,
uint32_t max_interval_in_sec,
uint32_t min_data_size_in_bytes,
startLoggingToDebugRingBuffer_cb hidl_status_cb) {
return validateAndCall(this,
WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
&WifiChip::startLoggingToDebugRingBufferInternal,
hidl_status_cb,
ring_name,
verbose_level,
max_interval_in_sec,
min_data_size_in_bytes);
}
Return<void> WifiChip::forceDumpToDebugRingBuffer(
const hidl_string& ring_name,
forceDumpToDebugRingBuffer_cb hidl_status_cb) {
return validateAndCall(this,
WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
&WifiChip::forceDumpToDebugRingBufferInternal,
hidl_status_cb,
ring_name);
}
Return<void> WifiChip::getDebugHostWakeReasonStats(
getDebugHostWakeReasonStats_cb hidl_status_cb) {
return validateAndCall(this,
WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
&WifiChip::getDebugHostWakeReasonStatsInternal,
hidl_status_cb);
}
void WifiChip::invalidateAndRemoveAllIfaces() {
invalidateAndClear(ap_iface_);
invalidateAndClear(nan_iface_);
invalidateAndClear(p2p_iface_);
invalidateAndClear(sta_iface_);
// Since all the ifaces are invalid now, all RTT controller objects
// using those ifaces also need to be invalidated.
for (const auto& rtt : rtt_controllers_) {
rtt->invalidate();
}
rtt_controllers_.clear();
}
std::pair<WifiStatus, ChipId> WifiChip::getIdInternal() {
return {createWifiStatus(WifiStatusCode::SUCCESS), chip_id_};
}
WifiStatus WifiChip::registerEventCallbackInternal(
const sp<IWifiChipEventCallback>& event_callback) {
// TODO(b/31632518): remove the callback when the client is destroyed
event_callbacks_.emplace_back(event_callback);
return createWifiStatus(WifiStatusCode::SUCCESS);
}
std::pair<WifiStatus, uint32_t> WifiChip::getCapabilitiesInternal() {
// TODO add implementation
return {createWifiStatus(WifiStatusCode::SUCCESS), 0};
}
std::pair<WifiStatus, std::vector<IWifiChip::ChipMode>>
WifiChip::getAvailableModesInternal() {
// TODO add implementation
return {createWifiStatus(WifiStatusCode::SUCCESS), {}};
}
WifiStatus WifiChip::configureChipInternal(uint32_t /* mode_id */) {
invalidateAndRemoveAllIfaces();
// TODO add implementation
return createWifiStatus(WifiStatusCode::SUCCESS);
}
std::pair<WifiStatus, uint32_t> WifiChip::getModeInternal() {
// TODO add implementation
return {createWifiStatus(WifiStatusCode::SUCCESS), 0};
}
std::pair<WifiStatus, IWifiChip::ChipDebugInfo>
WifiChip::requestChipDebugInfoInternal() {
IWifiChip::ChipDebugInfo result;
wifi_error legacy_status;
std::string driver_desc;
std::tie(legacy_status, driver_desc) = legacy_hal_.lock()->getDriverVersion();
if (legacy_status != WIFI_SUCCESS) {
LOG(ERROR) << "Failed to get driver version: "
<< legacyErrorToString(legacy_status);
WifiStatus status = createWifiStatusFromLegacyError(
legacy_status, "failed to get driver version");
return {status, result};
}
result.driverDescription = driver_desc.c_str();
std::string firmware_desc;
std::tie(legacy_status, firmware_desc) =
legacy_hal_.lock()->getFirmwareVersion();
if (legacy_status != WIFI_SUCCESS) {
LOG(ERROR) << "Failed to get firmware version: "
<< legacyErrorToString(legacy_status);
WifiStatus status = createWifiStatusFromLegacyError(
legacy_status, "failed to get firmware version");
return {status, result};
}
result.firmwareDescription = firmware_desc.c_str();
return {createWifiStatus(WifiStatusCode::SUCCESS), result};
}
std::pair<WifiStatus, std::vector<uint8_t>>
WifiChip::requestDriverDebugDumpInternal() {
wifi_error legacy_status;
std::vector<uint8_t> driver_dump;
std::tie(legacy_status, driver_dump) =
legacy_hal_.lock()->requestDriverMemoryDump();
if (legacy_status != WIFI_SUCCESS) {
LOG(ERROR) << "Failed to get driver debug dump: "
<< legacyErrorToString(legacy_status);
return {createWifiStatusFromLegacyError(legacy_status),
std::vector<uint8_t>()};
}
return {createWifiStatus(WifiStatusCode::SUCCESS), driver_dump};
}
std::pair<WifiStatus, std::vector<uint8_t>>
WifiChip::requestFirmwareDebugDumpInternal() {
wifi_error legacy_status;
std::vector<uint8_t> firmware_dump;
std::tie(legacy_status, firmware_dump) =
legacy_hal_.lock()->requestFirmwareMemoryDump();
if (legacy_status != WIFI_SUCCESS) {
LOG(ERROR) << "Failed to get firmware debug dump: "
<< legacyErrorToString(legacy_status);
return {createWifiStatusFromLegacyError(legacy_status), {}};
}
return {createWifiStatus(WifiStatusCode::SUCCESS), firmware_dump};
}
std::pair<WifiStatus, sp<IWifiApIface>> WifiChip::createApIfaceInternal() {
// TODO(b/31997422): Disallow this based on the chip combination.
std::string ifname = legacy_hal_.lock()->getApIfaceName();
ap_iface_ = new WifiApIface(ifname, legacy_hal_);
return {createWifiStatus(WifiStatusCode::SUCCESS), ap_iface_};
}
std::pair<WifiStatus, std::vector<hidl_string>>
WifiChip::getApIfaceNamesInternal() {
if (!ap_iface_.get()) {
return {createWifiStatus(WifiStatusCode::SUCCESS), {}};
}
return {createWifiStatus(WifiStatusCode::SUCCESS),
{legacy_hal_.lock()->getApIfaceName()}};
}
std::pair<WifiStatus, sp<IWifiApIface>> WifiChip::getApIfaceInternal(
const hidl_string& ifname) {
if (!ap_iface_.get() ||
(ifname.c_str() != legacy_hal_.lock()->getApIfaceName())) {
return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr};
}
return {createWifiStatus(WifiStatusCode::SUCCESS), ap_iface_};
}
std::pair<WifiStatus, sp<IWifiNanIface>> WifiChip::createNanIfaceInternal() {
// TODO(b/31997422): Disallow this based on the chip combination.
std::string ifname = legacy_hal_.lock()->getNanIfaceName();
nan_iface_ = new WifiNanIface(ifname, legacy_hal_);
return {createWifiStatus(WifiStatusCode::SUCCESS), nan_iface_};
}
std::pair<WifiStatus, std::vector<hidl_string>>
WifiChip::getNanIfaceNamesInternal() {
if (!nan_iface_.get()) {
return {createWifiStatus(WifiStatusCode::SUCCESS), {}};
}
return {createWifiStatus(WifiStatusCode::SUCCESS),
{legacy_hal_.lock()->getNanIfaceName()}};
}
std::pair<WifiStatus, sp<IWifiNanIface>> WifiChip::getNanIfaceInternal(
const hidl_string& ifname) {
if (!nan_iface_.get() ||
(ifname.c_str() != legacy_hal_.lock()->getNanIfaceName())) {
return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr};
}
return {createWifiStatus(WifiStatusCode::SUCCESS), nan_iface_};
}
std::pair<WifiStatus, sp<IWifiP2pIface>> WifiChip::createP2pIfaceInternal() {
// TODO(b/31997422): Disallow this based on the chip combination.
std::string ifname = legacy_hal_.lock()->getP2pIfaceName();
p2p_iface_ = new WifiP2pIface(ifname, legacy_hal_);
return {createWifiStatus(WifiStatusCode::SUCCESS), p2p_iface_};
}
std::pair<WifiStatus, std::vector<hidl_string>>
WifiChip::getP2pIfaceNamesInternal() {
if (!p2p_iface_.get()) {
return {createWifiStatus(WifiStatusCode::SUCCESS), {}};
}
return {createWifiStatus(WifiStatusCode::SUCCESS),
{legacy_hal_.lock()->getP2pIfaceName()}};
}
std::pair<WifiStatus, sp<IWifiP2pIface>> WifiChip::getP2pIfaceInternal(
const hidl_string& ifname) {
if (!p2p_iface_.get() ||
(ifname.c_str() != legacy_hal_.lock()->getP2pIfaceName())) {
return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr};
}
return {createWifiStatus(WifiStatusCode::SUCCESS), p2p_iface_};
}
std::pair<WifiStatus, sp<IWifiStaIface>> WifiChip::createStaIfaceInternal() {
// TODO(b/31997422): Disallow this based on the chip combination.
std::string ifname = legacy_hal_.lock()->getStaIfaceName();
sta_iface_ = new WifiStaIface(ifname, legacy_hal_);
return {createWifiStatus(WifiStatusCode::SUCCESS), sta_iface_};
}
std::pair<WifiStatus, std::vector<hidl_string>>
WifiChip::getStaIfaceNamesInternal() {
if (!sta_iface_.get()) {
return {createWifiStatus(WifiStatusCode::SUCCESS), {}};
}
return {createWifiStatus(WifiStatusCode::SUCCESS),
{legacy_hal_.lock()->getStaIfaceName()}};
}
std::pair<WifiStatus, sp<IWifiStaIface>> WifiChip::getStaIfaceInternal(
const hidl_string& ifname) {
if (!sta_iface_.get() ||
(ifname.c_str() != legacy_hal_.lock()->getStaIfaceName())) {
return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr};
}
return {createWifiStatus(WifiStatusCode::SUCCESS), sta_iface_};
}
std::pair<WifiStatus, sp<IWifiRttController>>
WifiChip::createRttControllerInternal(const sp<IWifiIface>& bound_iface) {
sp<WifiRttController> rtt = new WifiRttController(bound_iface, legacy_hal_);
rtt_controllers_.emplace_back(rtt);
return {createWifiStatus(WifiStatusCode::SUCCESS), rtt};
}
std::pair<WifiStatus, std::vector<WifiDebugRingBufferStatus>>
WifiChip::getDebugRingBuffersStatusInternal() {
// TODO implement
return {createWifiStatus(WifiStatusCode::SUCCESS), {}};
}
WifiStatus WifiChip::startLoggingToDebugRingBufferInternal(
const hidl_string& /* ring_name */,
WifiDebugRingBufferVerboseLevel /* verbose_level */,
uint32_t /* max_interval_in_sec */,
uint32_t /* min_data_size_in_bytes */) {
// TODO implement
return createWifiStatus(WifiStatusCode::SUCCESS);
}
WifiStatus WifiChip::forceDumpToDebugRingBufferInternal(
const hidl_string& /* ring_name */) {
// TODO implement
return createWifiStatus(WifiStatusCode::SUCCESS);
}
std::pair<WifiStatus, WifiDebugHostWakeReasonStats>
WifiChip::getDebugHostWakeReasonStatsInternal() {
// TODO implement
return {createWifiStatus(WifiStatusCode::SUCCESS), {}};
}
} // namespace implementation
} // namespace V1_0
} // namespace wifi
} // namespace hardware
} // namespace android
|