blob: 23cc92a358e4b732c0ff8d58b30bb4ff76cd35be [file] [log] [blame]
The Android Open Source Projectd6054a32008-10-21 07:00:00 -07001/*
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
17#ifndef _WIFI_H
18#define _WIFI_H
19
20#if __cplusplus
21extern "C" {
22#endif
23
24/**
The Android Open Source Project51704be2008-12-17 18:05:50 -080025 * Load the Wi-Fi driver.
The Android Open Source Projectd6054a32008-10-21 07:00:00 -070026 *
27 * @return 0 on success, < 0 on failure.
28 */
29int wifi_load_driver();
30
31/**
The Android Open Source Project51704be2008-12-17 18:05:50 -080032 * Unload the Wi-Fi driver.
The Android Open Source Projectd6054a32008-10-21 07:00:00 -070033 *
34 * @return 0 on success, < 0 on failure.
35 */
36int wifi_unload_driver();
37
38/**
39 * Start supplicant.
40 *
41 * @return 0 on success, < 0 on failure.
42 */
43int wifi_start_supplicant();
44
45/**
46 * Stop supplicant.
47 *
48 * @return 0 on success, < 0 on failure.
49 */
50int wifi_stop_supplicant();
51
52/**
53 * Open a connection to supplicant.
54 *
55 * @return 0 on success, < 0 on failure.
56 */
57int wifi_connect_to_supplicant();
58
59/**
60 * Close connection supplicant.
61 *
62 * @return 0 on success, < 0 on failure.
63 */
64void wifi_close_supplicant_connection();
65
66/**
The Android Open Source Project51704be2008-12-17 18:05:50 -080067 * wifi_wait_for_event() performs a blocking call to
68 * get a Wi-Fi event and returns a string representing
69 * a Wi-Fi event when it occurs.
The Android Open Source Projectd6054a32008-10-21 07:00:00 -070070 *
71 * @param buf is the buffer that receives the event
72 * @param len is the maximum length of the buffer
73 *
74 * @returns number of bytes in buffer, 0 if no
The Android Open Source Project51704be2008-12-17 18:05:50 -080075 * event (for instance, no connection), and less than 0
76 * if there is an error.
The Android Open Source Projectd6054a32008-10-21 07:00:00 -070077 */
78int wifi_wait_for_event(char *buf, size_t len);
79
80/**
The Android Open Source Project51704be2008-12-17 18:05:50 -080081 * wifi_command() issues a command to the Wi-Fi driver.
The Android Open Source Projectd6054a32008-10-21 07:00:00 -070082 *
The Android Open Source Project51704be2008-12-17 18:05:50 -080083 * Android extends the standard commands listed at
84 * /link http://hostap.epitest.fi/wpa_supplicant/devel/ctrl_iface_page.html
85 * to include support for sending commands to the driver:
The Android Open Source Projectd6054a32008-10-21 07:00:00 -070086 *
The Android Open Source Project51704be2008-12-17 18:05:50 -080087 * <table border="2" cellspacing="2" cellpadding="2">
88 * <tr>
89 * <td><strong>Command / Command summary</strong></td>
90 * <td><strong>Form of Response</strong></td>
91 * <td><strong>Processing</strong></td>
92 * </tr>
93 * <tr>
94 * <td>DRIVER START<BR>&nbsp;&nbsp;Turn on Wi-Fi Hardware</td>
95 * <td>OK if successful</td>
96 * <td>OK ? true : false</td>
97 * </tr>
98 * <tr>
99 * <td>DRIVER STOP<BR>&nbsp;&nbsp;Turn off Wi-Fi hardware</td>
100 * <td>OK if successful</td>
101 * <td>OK ? true : false</td>
102 * </tr>
103 * <tr>
104 * <td>DRIVER RSSI<BR>&nbsp;&nbsp;Return received signal strength indicator in -db for current AP</td>
105 * <td>&lt;ssid&gt; Rssi xx</td>
106 * <td>%*s %*s %d", &rssi</td>
107 * </tr>
108 * <tr>
109 * <td>DRIVER LINKSPEED<BR>&nbsp;&nbsp;Return link speed in MBPS</td>
110 * <td>LinkSpeed xx</td>
111 * <td>%*s %d", &linkspd</td>
112 * </tr>
113 * <tr>
114 * <td>DRIVER MACADDR<BR>&nbsp;&nbsp;Return mac address of the station</td>
115 * <td>Macaddr = xx.xx.xx.xx.xx.xx</td>
116 * <td>"%*s = %s", &macadr</td>
117 * </tr>
118 * <tr>
119 * <td>DRIVER SCAN-ACTIVE<BR>&nbsp;&nbsp;Set scan type to active</td>
120 * <td>"OK" if successful</td>
121 * <td>"OK" ? true : false</td>
122 * </tr>
123 * <tr>
124 * <td>DRIVER SCAN-PASSIVE<BR>&nbsp;&nbsp;Set scan type to passive</td>
125 * <td>"OK" if successful</td>
126 * <td>"OK" ? true : false</td>
127 * </tr>
128 * </table>
The Android Open Source Projectd6054a32008-10-21 07:00:00 -0700129 *
130 * See libs/android_runtime/android_net_wifi_Wifi.cpp for more information
The Android Open Source Project51704be2008-12-17 18:05:50 -0800131 * describing how these and other commands are invoked.
The Android Open Source Projectd6054a32008-10-21 07:00:00 -0700132 *
133 * @param command is the string command
134 * @param reply is a buffer to receive a reply string
The Android Open Source Project51704be2008-12-17 18:05:50 -0800135 * @param reply_len on entry, this is the maximum length of
136 * the reply buffer. On exit, the number of
The Android Open Source Projectd6054a32008-10-21 07:00:00 -0700137 * bytes in the reply buffer.
138 *
139 * @return 0 if successful, < 0 if an error.
140 */
141int wifi_command(const char *command, char *reply, size_t *reply_len);
142
143/**
The Android Open Source Project51704be2008-12-17 18:05:50 -0800144 * do_dhcp_request() issues a dhcp request and returns the acquired
145 * information.
146 *
147 * All IPV4 addresses/mask are in network byte order.
The Android Open Source Projectd6054a32008-10-21 07:00:00 -0700148 *
149 * @param ipaddr return the assigned IPV4 address
150 * @param gateway return the gateway being used
151 * @param mask return the IPV4 mask
The Android Open Source Project51704be2008-12-17 18:05:50 -0800152 * @param dns1 return the IPV4 address of a DNS server
153 * @param dns2 return the IPV4 address of a DNS server
154 * @param server return the IPV4 address of DHCP server
The Android Open Source Projectd6054a32008-10-21 07:00:00 -0700155 * @param lease return the length of lease in seconds.
156 *
157 * @return 0 if successful, < 0 if error.
158 */
159int do_dhcp_request(int *ipaddr, int *gateway, int *mask,
160 int *dns1, int *dns2, int *server, int *lease);
161
162/**
The Android Open Source Project51704be2008-12-17 18:05:50 -0800163 * Return the error string of the last do_dhcp_request().
The Android Open Source Projectd6054a32008-10-21 07:00:00 -0700164 */
165const char *get_dhcp_error_string();
166
167#if __cplusplus
168}; // extern "C"
169#endif
170
171#endif // _WIFI_H