WifiNative.java revision 8c11e952305327183db9f7be719e4c94fde15a7c
1/*
2 * Copyright (C) 2008 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
17package android.net.wifi;
18
19import android.net.DhcpInfo;
20
21/**
22 * Native calls for sending requests to the supplicant daemon, and for
23 * receiving asynchronous events. All methods of the form "xxxxCommand()"
24 * must be single-threaded, to avoid requests and responses initiated
25 * from multiple threads from being intermingled.
26 * <p/>
27 * Note that methods whose names are not of the form "xxxCommand()" do
28 * not talk to the supplicant daemon.
29 * Also, note that all WifiNative calls should happen in the
30 * WifiStateTracker class except for waitForEvent() call which is
31 * on a separate monitor channel for WifiMonitor
32 *
33 * {@hide}
34 */
35public class WifiNative {
36
37    static final int BLUETOOTH_COEXISTENCE_MODE_ENABLED = 0;
38    static final int BLUETOOTH_COEXISTENCE_MODE_DISABLED = 1;
39    static final int BLUETOOTH_COEXISTENCE_MODE_SENSE = 2;
40
41    public native static String getErrorString(int errorCode);
42
43    public native static boolean loadDriver();
44
45    public native static boolean unloadDriver();
46
47    public native static boolean startSupplicant();
48
49    public native static boolean stopSupplicant();
50
51    public native static boolean connectToSupplicant();
52
53    public native static void closeSupplicantConnection();
54
55    public native static boolean pingCommand();
56
57    public native static boolean scanCommand(boolean forceActive);
58
59    public native static boolean setScanModeCommand(boolean setActive);
60
61    public native static String listNetworksCommand();
62
63    public native static int addNetworkCommand();
64
65    public native static boolean setNetworkVariableCommand(int netId, String name, String value);
66
67    public native static String getNetworkVariableCommand(int netId, String name);
68
69    public native static boolean removeNetworkCommand(int netId);
70
71    public native static boolean enableNetworkCommand(int netId, boolean disableOthers);
72
73    public native static boolean disableNetworkCommand(int netId);
74
75    public native static boolean reconnectCommand();
76
77    public native static boolean reassociateCommand();
78
79    public native static boolean disconnectCommand();
80
81    public native static String statusCommand();
82
83    public native static int getRssiCommand();
84
85    public native static int getRssiApproxCommand();
86
87    public native static int getLinkSpeedCommand();
88
89    public native static String getMacAddressCommand();
90
91    public native static String scanResultsCommand();
92
93    public native static boolean startDriverCommand();
94
95    public native static boolean stopDriverCommand();
96
97    /**
98     * Start filtering out multicast packets, to reduce battery consumption
99     * that would result from processing them, only to discard them.
100     * @return {@code true} if the operation succeeded, {@code false} otherwise
101     */
102    public native static boolean startPacketFiltering();
103
104    /**
105     * Stop filtering out multicast packets.
106     * @return {@code true} if the operation succeeded, {@code false} otherwise
107     */
108    public native static boolean stopPacketFiltering();
109
110    public native static boolean setPowerModeCommand(int mode);
111
112    public native static int getPowerModeCommand();
113
114    public native static boolean setNumAllowedChannelsCommand(int numChannels);
115
116    public native static int getNumAllowedChannelsCommand();
117
118    /**
119     * Sets the bluetooth coexistence mode.
120     *
121     * @param mode One of {@link #BLUETOOTH_COEXISTENCE_MODE_DISABLED},
122     *            {@link #BLUETOOTH_COEXISTENCE_MODE_ENABLED}, or
123     *            {@link #BLUETOOTH_COEXISTENCE_MODE_SENSE}.
124     * @return Whether the mode was successfully set.
125     */
126    public native static boolean setBluetoothCoexistenceModeCommand(int mode);
127
128    /**
129     * Enable or disable Bluetooth coexistence scan mode. When this mode is on,
130     * some of the low-level scan parameters used by the driver are changed to
131     * reduce interference with A2DP streaming.
132     *
133     * @param isSet whether to enable or disable this mode
134     * @return {@code true} if the command succeeded, {@code false} otherwise.
135     */
136    public native static boolean setBluetoothCoexistenceScanModeCommand(boolean setCoexScanMode);
137
138    public native static boolean saveConfigCommand();
139
140    public native static boolean reloadConfigCommand();
141
142    public native static boolean setScanResultHandlingCommand(int mode);
143
144    public native static boolean addToBlacklistCommand(String bssid);
145
146    public native static boolean clearBlacklistCommand();
147
148    public native static boolean doDhcpRequest(DhcpInfo results);
149
150    public native static String getDhcpError();
151
152    public native static boolean setSuspendOptimizationsCommand(boolean enabled);
153
154    /**
155     * Wait for the supplicant to send an event, returning the event string.
156     * @return the event string sent by the supplicant.
157     */
158    public native static String waitForEvent();
159}
160