blob: a1f6bce51f5317d3894c37e3acf490d4131bee42 [file] [log] [blame]
KH Shid97a3082022-12-06 19:46:31 +08001/*
2 * Copyright (C) 2022 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#pragma once
18
19#include <aidl/android/hardware/tetheroffload/BnOffload.h>
20
21namespace aidl {
22namespace android {
23namespace hardware {
24namespace tetheroffload {
25namespace impl {
26namespace example {
27
28using aidl::android::hardware::tetheroffload::ForwardedStats;
29using aidl::android::hardware::tetheroffload::ITetheringOffloadCallback;
30
31class Offload : public BnOffload {
32 public:
33 ndk::ScopedAStatus addDownstream(const std::string& in_iface,
34 const std::string& in_prefix) override;
35 ndk::ScopedAStatus getForwardedStats(const std::string& in_upstream,
36 ForwardedStats* _aidl_return) override;
37 ndk::ScopedAStatus initOffload(
38 const ndk::ScopedFileDescriptor& in_fd1, const ndk::ScopedFileDescriptor& in_fd2,
39 const std::shared_ptr<ITetheringOffloadCallback>& in_cb) override;
40 ndk::ScopedAStatus removeDownstream(const std::string& in_iface,
41 const std::string& in_prefix) override;
42 ndk::ScopedAStatus setDataWarningAndLimit(const std::string& in_upstream,
43 int64_t in_warningBytes,
44 int64_t in_limitBytes) override;
45 ndk::ScopedAStatus setLocalPrefixes(const std::vector<std::string>& in_prefixes) override;
46 ndk::ScopedAStatus setUpstreamParameters(const std::string& in_iface,
47 const std::string& in_v4Addr,
48 const std::string& in_v4Gw,
49 const std::vector<std::string>& in_v6Gws) override;
50 ndk::ScopedAStatus stopOffload() override;
51
52 private:
53 bool isInitialized();
54 bool isValidInterface(const std::string& iface);
55 bool isValidIpv4Address(const std::string& repr);
56 bool isValidIpv4Prefix(const std::string& repr);
57 bool isValidIpv6Address(const std::string& repr);
58 bool isValidIpv6Prefix(const std::string& repr);
59 bool isValidIpAddress(const std::string& repr);
60 bool isValidIpPrefix(const std::string& repr);
61 bool validateIpAddressOrPrefix(const std::string& repr, const int expectedFamily,
62 const bool isPrefix);
63
64 bool mInitialized = false;
65 ndk::ScopedFileDescriptor mFd1;
66 ndk::ScopedFileDescriptor mFd2;
67};
68
69} // namespace example
70} // namespace impl
71} // namespace tetheroffload
72} // namespace hardware
73} // namespace android
74} // namespace aidl