WifiNative.java revision 25c9bf2396ceb48fc5cfd5c1dd58aa4d4750d056
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 isDriverLoaded();
46
47    public native static boolean unloadDriver();
48
49    public native static boolean startSupplicant();
50
51    public native static boolean stopSupplicant();
52
53    public native static boolean connectToSupplicant();
54
55    public native static void closeSupplicantConnection();
56
57    public native static boolean pingCommand();
58
59    public native static boolean scanCommand(boolean forceActive);
60
61    public native static boolean setScanModeCommand(boolean setActive);
62
63    public native static String listNetworksCommand();
64
65    public native static int addNetworkCommand();
66
67    public native static boolean setNetworkVariableCommand(int netId, String name, String value);
68
69    public native static String getNetworkVariableCommand(int netId, String name);
70
71    public native static boolean removeNetworkCommand(int netId);
72
73    public native static boolean enableNetworkCommand(int netId, boolean disableOthers);
74
75    public native static boolean disableNetworkCommand(int netId);
76
77    public native static boolean reconnectCommand();
78
79    public native static boolean reassociateCommand();
80
81    public native static boolean disconnectCommand();
82
83    public native static String statusCommand();
84
85    public native static int getRssiCommand();
86
87    public native static int getRssiApproxCommand();
88
89    public native static int getLinkSpeedCommand();
90
91    public native static String getMacAddressCommand();
92
93    public native static String scanResultsCommand();
94
95    public native static boolean startDriverCommand();
96
97    public native static boolean stopDriverCommand();
98
99    /**
100     * Start filtering out multicast packets, to reduce battery consumption
101     * that would result from processing them, only to discard them.
102     * @return {@code true} if the operation succeeded, {@code false} otherwise
103     */
104    public native static boolean startPacketFiltering();
105
106    /**
107     * Stop filtering out multicast packets.
108     * @return {@code true} if the operation succeeded, {@code false} otherwise
109     */
110    public native static boolean stopPacketFiltering();
111
112    public native static boolean setPowerModeCommand(int mode);
113
114    public native static int getBandCommand();
115
116    public native static boolean setBandCommand(int band);
117
118    public native static int getPowerModeCommand();
119
120    public native static boolean setNumAllowedChannelsCommand(int numChannels);
121
122    public native static int getNumAllowedChannelsCommand();
123
124    /**
125     * Sets the bluetooth coexistence mode.
126     *
127     * @param mode One of {@link #BLUETOOTH_COEXISTENCE_MODE_DISABLED},
128     *            {@link #BLUETOOTH_COEXISTENCE_MODE_ENABLED}, or
129     *            {@link #BLUETOOTH_COEXISTENCE_MODE_SENSE}.
130     * @return Whether the mode was successfully set.
131     */
132    public native static boolean setBluetoothCoexistenceModeCommand(int mode);
133
134    /**
135     * Enable or disable Bluetooth coexistence scan mode. When this mode is on,
136     * some of the low-level scan parameters used by the driver are changed to
137     * reduce interference with A2DP streaming.
138     *
139     * @param isSet whether to enable or disable this mode
140     * @return {@code true} if the command succeeded, {@code false} otherwise.
141     */
142    public native static boolean setBluetoothCoexistenceScanModeCommand(boolean setCoexScanMode);
143
144    public native static boolean saveConfigCommand();
145
146    public native static boolean reloadConfigCommand();
147
148    public native static boolean setScanResultHandlingCommand(int mode);
149
150    public native static boolean addToBlacklistCommand(String bssid);
151
152    public native static boolean clearBlacklistCommand();
153
154    public native static boolean doDhcpRequest(DhcpInfo results);
155
156    public native static String getDhcpError();
157
158    /**
159     * Wait for the supplicant to send an event, returning the event string.
160     * @return the event string sent by the supplicant.
161     */
162    public native static String waitForEvent();
163}
164