summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVinit Deshpande2015-03-16 03:30:49 -0500
committerVinit Deshpande2015-03-16 03:30:49 -0500
commitac56e6ba1d5ab6b33ef1453c327c66a7409f3433 (patch)
tree96e6775f93a6b22031df53f675b5a3503db5b31e /libnetutils
parent186367f3b36e0d6894cf305338175e037052e6eb (diff)
parent314d82c3c514f7f216e99e9b2ad760ed0f7354c8 (diff)
downloadplatform-system-core-ac56e6ba1d5ab6b33ef1453c327c66a7409f3433.tar.gz
platform-system-core-ac56e6ba1d5ab6b33ef1453c327c66a7409f3433.tar.xz
platform-system-core-ac56e6ba1d5ab6b33ef1453c327c66a7409f3433.zip
Merge remote-tracking branch 'goog/mirror-m-wireless-internal-release'
Change-Id: I4d3d55dac794db8fa81d3048e41ac589920f43b8
Diffstat (limited to 'libnetutils')
-rw-r--r--libnetutils/dhcp_utils.c112
1 files changed, 55 insertions, 57 deletions
diff --git a/libnetutils/dhcp_utils.c b/libnetutils/dhcp_utils.c
index 0f7c384c5..851d56597 100644
--- a/libnetutils/dhcp_utils.c
+++ b/libnetutils/dhcp_utils.c
@@ -1,16 +1,16 @@
1/* 1/*
2 * Copyright 2008, The Android Open Source Project 2 * Copyright 2008, The Android Open Source Project
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with 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 6 * You may obtain a copy of the License at
7 * 7 *
8 * http://www.apache.org/licenses/LICENSE-2.0 8 * http://www.apache.org/licenses/LICENSE-2.0
9 * 9 *
10 * Unless required by applicable law or agreed to in writing, software 10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, 11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 16
@@ -33,7 +33,7 @@ static const char DHCP_CONFIG_PATH[] = "/system/etc/dhcpcd/dhcpcd.conf";
33static const int NAP_TIME = 200; /* wait for 200ms at a time */ 33static const int NAP_TIME = 200; /* wait for 200ms at a time */
34 /* when polling for property values */ 34 /* when polling for property values */
35static const char DAEMON_NAME_RENEW[] = "iprenew"; 35static const char DAEMON_NAME_RENEW[] = "iprenew";
36static char errmsg[100]; 36static char errmsg[100] = "\0";
37/* interface length for dhcpcd daemon start (dhcpcd_<interface> as defined in init.rc file) 37/* interface length for dhcpcd daemon start (dhcpcd_<interface> as defined in init.rc file)
38 * or for filling up system properties dhcpcd.<interface>.ipaddress, dhcpcd.<interface>.dns1 38 * or for filling up system properties dhcpcd.<interface>.ipaddress, dhcpcd.<interface>.dns1
39 * and other properties on a successful bind 39 * and other properties on a successful bind
@@ -75,7 +75,7 @@ static int wait_for_property(const char *name, const char *desired_value, int ma
75 while (maxnaps-- > 0) { 75 while (maxnaps-- > 0) {
76 usleep(NAP_TIME * 1000); 76 usleep(NAP_TIME * 1000);
77 if (property_get(name, value, NULL)) { 77 if (property_get(name, value, NULL)) {
78 if (desired_value == NULL || 78 if (desired_value == NULL ||
79 strcmp(value, desired_value) == 0) { 79 strcmp(value, desired_value) == 0) {
80 return 0; 80 return 0;
81 } 81 }
@@ -167,6 +167,47 @@ static int fill_ip_info(const char *interface,
167} 167}
168 168
169/* 169/*
170 * Get any available DHCP results.
171 */
172int dhcp_get_results(const char *interface,
173 char *ipaddr,
174 char *gateway,
175 uint32_t *prefixLength,
176 char *dns[],
177 char *server,
178 uint32_t *lease,
179 char *vendorInfo,
180 char *domain,
181 char *mtu)
182{
183 char result_prop_name[PROPERTY_KEY_MAX];
184 char prop_value[PROPERTY_VALUE_MAX];
185
186 /* Interface name after converting p2p0-p2p0-X to p2p to reuse system properties */
187 char p2p_interface[MAX_INTERFACE_LENGTH];
188 get_p2p_interface_replacement(interface, p2p_interface);
189 snprintf(result_prop_name, sizeof(result_prop_name), "%s.%s.result",
190 DHCP_PROP_NAME_PREFIX,
191 p2p_interface);
192
193 memset(prop_value, '\0', PROPERTY_VALUE_MAX);
194 if (!property_get(result_prop_name, prop_value, NULL)) {
195 snprintf(errmsg, sizeof(errmsg), "%s", "DHCP result property was not set");
196 return -1;
197 }
198 if (strcmp(prop_value, "ok") == 0) {
199 if (fill_ip_info(interface, ipaddr, gateway, prefixLength, dns,
200 server, lease, vendorInfo, domain, mtu) == -1) {
201 return -1;
202 }
203 return 0;
204 } else {
205 snprintf(errmsg, sizeof(errmsg), "DHCP result was %s", prop_value);
206 return -1;
207 }
208}
209
210/*
170 * Start the dhcp client daemon, and wait for it to finish 211 * Start the dhcp client daemon, and wait for it to finish
171 * configuring the interface. 212 * configuring the interface.
172 * 213 *
@@ -175,16 +216,7 @@ static int fill_ip_info(const char *interface,
175 * Example: 216 * Example:
176 * service dhcpcd_<interface> /system/bin/dhcpcd -ABKL -f dhcpcd.conf 217 * service dhcpcd_<interface> /system/bin/dhcpcd -ABKL -f dhcpcd.conf
177 */ 218 */
178int dhcp_do_request(const char *interface, 219int dhcp_start(const char *interface)
179 char *ipaddr,
180 char *gateway,
181 uint32_t *prefixLength,
182 char *dns[],
183 char *server,
184 uint32_t *lease,
185 char *vendorInfo,
186 char *domain,
187 char *mtu)
188{ 220{
189 char result_prop_name[PROPERTY_KEY_MAX]; 221 char result_prop_name[PROPERTY_KEY_MAX];
190 char daemon_prop_name[PROPERTY_KEY_MAX]; 222 char daemon_prop_name[PROPERTY_KEY_MAX];
@@ -228,21 +260,7 @@ int dhcp_do_request(const char *interface,
228 return -1; 260 return -1;
229 } 261 }
230 262
231 if (!property_get(result_prop_name, prop_value, NULL)) { 263 return 0;
232 /* shouldn't ever happen, given the success of wait_for_property() */
233 snprintf(errmsg, sizeof(errmsg), "%s", "DHCP result property was not set");
234 return -1;
235 }
236 if (strcmp(prop_value, "ok") == 0) {
237 if (fill_ip_info(interface, ipaddr, gateway, prefixLength, dns,
238 server, lease, vendorInfo, domain, mtu) == -1) {
239 return -1;
240 }
241 return 0;
242 } else {
243 snprintf(errmsg, sizeof(errmsg), "DHCP result was %s", prop_value);
244 return -1;
245 }
246} 264}
247 265
248/** 266/**
@@ -318,16 +336,7 @@ char *dhcp_get_errmsg() {
318 * service iprenew_<interface> /system/bin/dhcpcd -n 336 * service iprenew_<interface> /system/bin/dhcpcd -n
319 * 337 *
320 */ 338 */
321int dhcp_do_request_renew(const char *interface, 339int dhcp_start_renew(const char *interface)
322 char *ipaddr,
323 char *gateway,
324 uint32_t *prefixLength,
325 char *dns[],
326 char *server,
327 uint32_t *lease,
328 char *vendorInfo,
329 char *domain,
330 char *mtu)
331{ 340{
332 char result_prop_name[PROPERTY_KEY_MAX]; 341 char result_prop_name[PROPERTY_KEY_MAX];
333 char prop_value[PROPERTY_VALUE_MAX] = {'\0'}; 342 char prop_value[PROPERTY_VALUE_MAX] = {'\0'};
@@ -357,16 +366,5 @@ int dhcp_do_request_renew(const char *interface,
357 return -1; 366 return -1;
358 } 367 }
359 368
360 if (!property_get(result_prop_name, prop_value, NULL)) { 369 return 0;
361 /* shouldn't ever happen, given the success of wait_for_property() */
362 snprintf(errmsg, sizeof(errmsg), "%s", "DHCP Renew result property was not set");
363 return -1;
364 }
365 if (strcmp(prop_value, "ok") == 0) {
366 return fill_ip_info(interface, ipaddr, gateway, prefixLength, dns,
367 server, lease, vendorInfo, domain, mtu);
368 } else {
369 snprintf(errmsg, sizeof(errmsg), "DHCP Renew result was %s", prop_value);
370 return -1;
371 }
372} 370}