1 /* 2 * Copyright (C) 2017 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 "chre/apps/wifi_offload/preferred_network.h" 18 19 namespace wifi_offload { 20 PreferredNetwork()21PreferredNetwork::PreferredNetwork() : security_modes_(SecurityMode::UNKNOWN) {} 22 operator ==(const PreferredNetwork & other) const23bool PreferredNetwork::operator==(const PreferredNetwork &other) const { 24 if (this == &other) { 25 return true; 26 } 27 return ssid_ == other.ssid_ && security_modes_ == other.security_modes_; 28 } 29 Serialize(flatbuffers::FlatBufferBuilder * builder) const30flatbuffers::Offset<PreferredNetwork::FbsType> PreferredNetwork::Serialize( 31 flatbuffers::FlatBufferBuilder *builder) const { 32 return fbs::CreatePreferredNetwork(*builder, ssid_.Serialize(builder), 33 security_modes_); 34 } 35 Deserialize(const PreferredNetwork::FbsType & fbs_network)36bool PreferredNetwork::Deserialize( 37 const PreferredNetwork::FbsType &fbs_network) { 38 const auto &fbs_ssid = fbs_network.ssid(); 39 if (fbs_ssid == nullptr || !ssid_.Deserialize(*fbs_ssid)) { 40 LOGE("Failed to deserialize PreferredNetwork. Null or incomplete members."); 41 return false; 42 } 43 44 security_modes_ = fbs_network.security_modes(); 45 if (security_modes_ & ~SecurityMode::ALL_SECURITY_MODES_MASK) { 46 LOGE("Failed to deserialize PreferredNetwork. Invalid security mode."); 47 return false; 48 } 49 50 return true; 51 } 52 Log() const53void PreferredNetwork::Log() const { 54 ssid_.Log(); 55 LOGI(" security modes: 0x%" PRIx8, security_modes_); 56 } 57 58 } // namespace wifi_offload 59