1/* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#include "wificond/scanning/scan_result.h" 18 19#include <android-base/logging.h> 20 21#include "wificond/logging_utils.h" 22#include "wificond/parcelable_utils.h" 23 24using android::status_t; 25using android::OK; 26using std::string; 27 28namespace com { 29namespace android { 30namespace server { 31namespace wifi { 32namespace wificond { 33 34NativeScanResult::NativeScanResult(std::vector<uint8_t>& ssid_, 35 std::vector<uint8_t>& bssid_, 36 std::vector<uint8_t>& info_element_, 37 uint32_t frequency_, 38 int32_t signal_mbm_, 39 uint64_t tsf_, 40 uint16_t capability_, 41 bool associated_) 42 : ssid(ssid_), 43 bssid(bssid_), 44 info_element(info_element_), 45 frequency(frequency_), 46 signal_mbm(signal_mbm_), 47 tsf(tsf_), 48 capability(capability_), 49 associated(associated_) { 50} 51 52status_t NativeScanResult::writeToParcel(::android::Parcel* parcel) const { 53 RETURN_IF_FAILED(parcel->writeByteVector(ssid)); 54 RETURN_IF_FAILED(parcel->writeByteVector(bssid)); 55 RETURN_IF_FAILED(parcel->writeByteVector(info_element)); 56 RETURN_IF_FAILED(parcel->writeUint32(frequency)); 57 RETURN_IF_FAILED(parcel->writeInt32(signal_mbm)); 58 RETURN_IF_FAILED(parcel->writeUint64(tsf)); 59 // There is no writeUint16() available. 60 // Use writeUint32() instead. 61 RETURN_IF_FAILED(parcel->writeUint32(capability)); 62 RETURN_IF_FAILED(parcel->writeInt32(associated ? 1 : 0)); 63 return ::android::OK; 64} 65 66status_t NativeScanResult::readFromParcel(const ::android::Parcel* parcel) { 67 RETURN_IF_FAILED(parcel->readByteVector(&ssid)); 68 RETURN_IF_FAILED(parcel->readByteVector(&bssid)); 69 RETURN_IF_FAILED(parcel->readByteVector(&info_element)); 70 RETURN_IF_FAILED(parcel->readUint32(&frequency)); 71 RETURN_IF_FAILED(parcel->readInt32(&signal_mbm)); 72 RETURN_IF_FAILED(parcel->readUint64(&tsf)); 73 // There is no readUint16() available. 74 // Use readUint32() instead. 75 capability = static_cast<uint16_t>(parcel->readUint32()); 76 associated = (parcel->readInt32() != 0); 77 return ::android::OK; 78} 79 80void NativeScanResult::DebugLog() { 81 LOG(INFO) << "Scan result:"; 82 // |ssid| might be an encoded array but we just print it as ASCII here. 83 string ssid_str(ssid.data(), ssid.data() + ssid.size()); 84 LOG(INFO) << "SSID: " << ssid_str; 85 86 LOG(INFO) << "BSSID: " 87 << ::android::wificond::LoggingUtils::GetMacString(bssid); 88 LOG(INFO) << "FREQUENCY: " << frequency; 89 LOG(INFO) << "SIGNAL: " << signal_mbm/100 << "dBm"; 90 LOG(INFO) << "TSF: " << tsf; 91 LOG(INFO) << "CAPABILITY: " << capability; 92 LOG(INFO) << "ASSOCIATED: " << associated; 93 94} 95 96} // namespace wificond 97} // namespace wifi 98} // namespace server 99} // namespace android 100} // namespace com 101