1 /* 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 package com.android.networkstack.tethering; 18 19 import android.annotation.NonNull; 20 import android.os.NativeHandle; 21 22 import com.android.networkstack.tethering.OffloadHardwareInterface.ForwardedStats; 23 import com.android.networkstack.tethering.OffloadHardwareInterface.OffloadHalCallback; 24 25 import java.util.ArrayList; 26 27 /** Abstraction of Tetheroffload HAL interface */ 28 interface IOffloadHal { 29 /* 30 * Initialize the Tetheroffload HAL. Offload management process need to know conntrack rules to 31 * support NAT, but it may not have permission to create netlink netfilter sockets. Create two 32 * netlink netfilter sockets and share them with offload management process. 33 */ initOffload(@onNull NativeHandle handle1, @NonNull NativeHandle handle2, @NonNull OffloadHalCallback callback)34 boolean initOffload(@NonNull NativeHandle handle1, @NonNull NativeHandle handle2, 35 @NonNull OffloadHalCallback callback); 36 37 /** Stop the Tetheroffload HAL. */ stopOffload()38 boolean stopOffload(); 39 40 /** Get HAL interface version number. */ getVersion()41 int getVersion(); 42 43 /** Get Tx/Rx usage from last query. */ getForwardedStats(@onNull String upstream)44 ForwardedStats getForwardedStats(@NonNull String upstream); 45 46 /** Set local prefixes to offload management process. */ setLocalPrefixes(@onNull ArrayList<String> localPrefixes)47 boolean setLocalPrefixes(@NonNull ArrayList<String> localPrefixes); 48 49 /** Set data limit value to offload management process. */ setDataLimit(@onNull String iface, long limit)50 boolean setDataLimit(@NonNull String iface, long limit); 51 52 /** Set data warning and limit value to offload management process. */ setDataWarningAndLimit(@onNull String iface, long warning, long limit)53 boolean setDataWarningAndLimit(@NonNull String iface, long warning, long limit); 54 55 /** Set upstream parameters to offload management process. */ setUpstreamParameters(@onNull String iface, @NonNull String v4addr, @NonNull String v4gateway, @NonNull ArrayList<String> v6gws)56 boolean setUpstreamParameters(@NonNull String iface, @NonNull String v4addr, 57 @NonNull String v4gateway, @NonNull ArrayList<String> v6gws); 58 59 /** Add downstream prefix to offload management process. */ addDownstream(@onNull String ifname, @NonNull String prefix)60 boolean addDownstream(@NonNull String ifname, @NonNull String prefix); 61 62 /** Remove downstream prefix from offload management process. */ removeDownstream(@onNull String ifname, @NonNull String prefix)63 boolean removeDownstream(@NonNull String ifname, @NonNull String prefix); 64 } 65