/** * The device init.rc file needs a corresponding entry. * * Example: * service iprenew_<interface> /system/bin/dhcpcd -n * */ int dhcp_start_renew(const char *interface) { char result_prop_name[PROPERTY_KEY_MAX]; char prop_value[PROPERTY_VALUE_MAX] = {'\0'}; char daemon_cmd[PROPERTY_VALUE_MAX * 2]; const char *ctrl_prop = "ctl.start"; char p2p_interface[MAX_INTERFACE_LENGTH]; get_p2p_interface_replacement(interface, p2p_interface); snprintf(result_prop_name, sizeof(result_prop_name), "%s.%s.result", DHCP_PROP_NAME_PREFIX, p2p_interface); /* Erase any previous setting of the dhcp result property */ property_set(result_prop_name, ""); /* Start the renew daemon and wait until it's ready */ snprintf(daemon_cmd, sizeof(daemon_cmd), "%s_%s:%s", DAEMON_NAME_RENEW, p2p_interface, interface); memset(prop_value, '\0', PROPERTY_VALUE_MAX); property_set(ctrl_prop, daemon_cmd); /* Wait for the daemon to return a result */ if (wait_for_property(result_prop_name, NULL, 30) < 0) { snprintf(errmsg, sizeof(errmsg), "%s", "Timed out waiting for DHCP Renew to finish"); return -1; } return 0; }
/** * Stop the DHCP client daemon. */ int dhcp_stop(const char *interface) { char result_prop_name[PROPERTY_KEY_MAX]; char daemon_prop_name[PROPERTY_KEY_MAX]; char daemon_cmd[PROPERTY_VALUE_MAX * 2]; const char *ctrl_prop = "ctl.stop"; const char *desired_status = "stopped"; char p2p_interface[MAX_INTERFACE_LENGTH]; get_p2p_interface_replacement(interface, p2p_interface); snprintf(result_prop_name, sizeof(result_prop_name), "%s.%s.result", DHCP_PROP_NAME_PREFIX, p2p_interface); snprintf(daemon_prop_name, sizeof(daemon_prop_name), "%s_%s", DAEMON_PROP_NAME, p2p_interface); snprintf(daemon_cmd, sizeof(daemon_cmd), "%s_%s", DAEMON_NAME, p2p_interface); /* Stop the daemon and wait until it's reported to be stopped */ property_set(ctrl_prop, daemon_cmd); if (wait_for_property(daemon_prop_name, desired_status, 5) < 0) { return -1; } property_set(result_prop_name, "failed"); return 0; }
/** * Release the current DHCP client lease. */ int dhcp_release_lease(const char *interface) { char daemon_prop_name[PROPERTY_KEY_MAX]; char daemon_cmd[PROPERTY_VALUE_MAX * 2]; const char *ctrl_prop = "ctl.stop"; const char *desired_status = "stopped"; char p2p_interface[MAX_INTERFACE_LENGTH]; get_p2p_interface_replacement(interface, p2p_interface); snprintf(daemon_prop_name, sizeof(daemon_prop_name), "%s_%s", DAEMON_PROP_NAME, p2p_interface); snprintf(daemon_cmd, sizeof(daemon_cmd), "%s_%s", DAEMON_NAME, p2p_interface); pid_t pid; char pid_property_name[PROPERTY_KEY_MAX]; char pid_property_value[PROPERTY_VALUE_MAX]; snprintf(pid_property_name, sizeof(pid_property_name), "dhcp.%s.pid", interface); property_get(pid_property_name, pid_property_value, NULL); pid = atoi(pid_property_value); kill(pid, SIGHUP); if (wait_for_property(daemon_prop_name, desired_status, 5) < 0) { return -1; } return 0; }
int service_stop(const char *service_name) { int result = 0; D(INFO, "Stopping MDNSD"); property_set("ctl.stop", service_name); if (wait_for_property(service_name, "stopped", 5)) result = -1; return result; }
/** * The device init.rc file needs a corresponding entry. * * Example: * service iprenew_<interface> /system/bin/dhcpcd -n * */ int dhcp_do_request_renew(const char *interface, char *ipaddr, char *gateway, uint32_t *prefixLength, char *dns[], char *server, uint32_t *lease, char *vendorInfo, char *domain, char *mtu) { char result_prop_name[PROPERTY_KEY_MAX]; char prop_value[PROPERTY_VALUE_MAX] = {'\0'}; char daemon_cmd[PROPERTY_VALUE_MAX * 2]; const char *ctrl_prop = "ctl.start"; char p2p_interface[MAX_INTERFACE_LENGTH]; get_p2p_interface_replacement(interface, p2p_interface); snprintf(result_prop_name, sizeof(result_prop_name), "%s.%s.result", DHCP_PROP_NAME_PREFIX, p2p_interface); /* Erase any previous setting of the dhcp result property */ property_set(result_prop_name, ""); /* Start the renew daemon and wait until it's ready */ snprintf(daemon_cmd, sizeof(daemon_cmd), "%s_%s:%s", DAEMON_NAME_RENEW, p2p_interface, interface); memset(prop_value, '\0', PROPERTY_VALUE_MAX); property_set(ctrl_prop, daemon_cmd); /* Wait for the daemon to return a result */ if (wait_for_property(result_prop_name, NULL, 30) < 0) { snprintf(errmsg, sizeof(errmsg), "%s", "Timed out waiting for DHCP Renew to finish"); return -1; } if (!property_get(result_prop_name, prop_value, NULL)) { /* shouldn't ever happen, given the success of wait_for_property() */ snprintf(errmsg, sizeof(errmsg), "%s", "DHCP Renew result property was not set"); return -1; } if (strcmp(prop_value, "ok") == 0) { return fill_ip_info(interface, ipaddr, gateway, prefixLength, dns, server, lease, vendorInfo, domain, mtu); } else { snprintf(errmsg, sizeof(errmsg), "DHCP Renew result was %s", prop_value); return -1; } }
int MDnsSdListener::Monitor::stopService() { int result = 0; pthread_mutex_lock(&mHeadMutex); if (mHead == NULL) { ALOGD("Stopping MDNSD"); property_set("ctl.stop", MDNS_SERVICE_NAME); wait_for_property(MDNS_SERVICE_STATUS, "stopped", 5); result = -1; } else { result = 0; } pthread_mutex_unlock(&mHeadMutex); return result; }
int service_start(const char *service_name) { int result = 0; char property_value[PROPERTY_VALUE_MAX]; property_get(service_name, property_value, ""); if (strcmp("running", property_value) != 0) { D(INFO, "Starting %s", service_name); property_set("ctl.start", service_name); if (wait_for_property(service_name, "running", 5)) result = -1; } return result; }
int MDnsSdListener::Monitor::startService() { int result = 0; char property_value[PROPERTY_VALUE_MAX]; pthread_mutex_lock(&mHeadMutex); property_get(MDNS_SERVICE_STATUS, property_value, ""); if (strcmp("running", property_value) != 0) { ALOGD("Starting MDNSD"); property_set("ctl.start", MDNS_SERVICE_NAME); wait_for_property(MDNS_SERVICE_STATUS, "running", 5); result = -1; } else { result = 0; } pthread_mutex_unlock(&mHeadMutex); return result; }
/** * Release the current DHCP client lease. */ int dhcp_release_lease(const char *interface) { char daemon_prop_name[PROPERTY_KEY_MAX]; char daemon_cmd[PROPERTY_VALUE_MAX * 2]; const char *ctrl_prop = "ctl.stop"; const char *desired_status = "stopped"; char daemon_suffix[MAX_DAEMON_SUFFIX]; get_daemon_suffix(interface, daemon_suffix); snprintf(daemon_prop_name, sizeof(daemon_prop_name), "%s_%s", DAEMON_PROP_NAME, daemon_suffix); snprintf(daemon_cmd, sizeof(daemon_cmd), "%s_%s", DAEMON_NAME, daemon_suffix); /* Stop the daemon and wait until it's reported to be stopped */ property_set(ctrl_prop, daemon_cmd); if (wait_for_property(daemon_prop_name, desired_status, 5) < 0) { return -1; } return 0; }
/* * Start the dhcp client daemon, and wait for it to finish * configuring the interface. * * The device init.rc file needs a corresponding entry for this work. * * Example: * service dhcpcd_<interface> /system/bin/dhcpcd -ABKL -f dhcpcd.conf */ int dhcp_start(const char *interface) { char result_prop_name[PROPERTY_KEY_MAX]; char daemon_prop_name[PROPERTY_KEY_MAX]; char prop_value[PROPERTY_VALUE_MAX] = {'\0'}; char daemon_cmd[PROPERTY_VALUE_MAX * 2 + sizeof(DHCP_CONFIG_PATH)]; const char *ctrl_prop = "ctl.start"; const char *desired_status = "running"; /* Interface name after converting p2p0-p2p0-X to p2p to reuse system properties */ char p2p_interface[MAX_INTERFACE_LENGTH]; #ifdef SAMSUNG_OXYGEN_NETWORK int isIbss = 0; #endif get_p2p_interface_replacement(interface, p2p_interface); #ifdef SAMSUNG_OXYGEN_NETWORK isIbss = get_ibss_interface_replacement(interface, p2p_interface); #endif snprintf(result_prop_name, sizeof(result_prop_name), "%s.%s.result", DHCP_PROP_NAME_PREFIX, p2p_interface); #ifdef SAMSUNG_OXYGEN_NETWORK if (isIbss > 0) { snprintf(daemon_prop_name, sizeof(daemon_prop_name), "%s_ibss", DAEMON_PROP_NAME); } else { snprintf(daemon_prop_name, sizeof(daemon_prop_name), "%s_%s", DAEMON_PROP_NAME, p2p_interface); } #else snprintf(daemon_prop_name, sizeof(daemon_prop_name), "%s_%s", DAEMON_PROP_NAME, p2p_interface); #endif /* Erase any previous setting of the dhcp result property */ property_set(result_prop_name, ""); /* Start the daemon and wait until it's ready */ if (property_get(HOSTNAME_PROP_NAME, prop_value, NULL) && (prop_value[0] != '\0')) #ifdef SAMSUNG_OXYGEN_NETWORK { if (isIbss > 0) { snprintf(daemon_cmd, sizeof(daemon_cmd), "%s_ibss:-f %s -h %s wlan0", DAEMON_NAME, DHCP_CONFIG_PATH, prop_value); } else #endif snprintf(daemon_cmd, sizeof(daemon_cmd), "%s_%s:-f %s -h %s %s", DAEMON_NAME, p2p_interface, DHCP_CONFIG_PATH, prop_value, interface); #ifdef SAMSUNG_OXYGEN_NETWORK } #endif else snprintf(daemon_cmd, sizeof(daemon_cmd), "%s_%s:-f %s %s", DAEMON_NAME, p2p_interface, DHCP_CONFIG_PATH, interface); memset(prop_value, '\0', PROPERTY_VALUE_MAX); property_set(ctrl_prop, daemon_cmd); if (wait_for_property(daemon_prop_name, desired_status, 10) < 0) { snprintf(errmsg, sizeof(errmsg), "%s", "Timed out waiting for dhcpcd to start"); return -1; } /* Wait for the daemon to return a result */ if (wait_for_property(result_prop_name, NULL, 30) < 0) { snprintf(errmsg, sizeof(errmsg), "%s", "Timed out waiting for DHCP to finish"); return -1; } return 0; }
/* * Start the dhcp client daemon, and wait for it to finish * configuring the interface. */ int dhcp_do_request(const char *interface, char *ipaddr, char *gateway, uint32_t *prefixLength, char *dns1, char *dns2, char *server, uint32_t *lease) { char result_prop_name[PROPERTY_KEY_MAX]; char daemon_prop_name[PROPERTY_KEY_MAX]; char prop_value[PROPERTY_VALUE_MAX] = {'\0'}; char daemon_cmd[PROPERTY_VALUE_MAX * 2]; const char *ctrl_prop = "ctl.start"; const char *desired_status = "running"; char daemon_suffix[MAX_DAEMON_SUFFIX]; get_daemon_suffix(interface, daemon_suffix); snprintf(result_prop_name, sizeof(result_prop_name), "%s.%s.result", DHCP_PROP_NAME_PREFIX, interface); snprintf(daemon_prop_name, sizeof(daemon_prop_name), "%s_%s", DAEMON_PROP_NAME, daemon_suffix); /* Erase any previous setting of the dhcp result property */ property_set(result_prop_name, ""); /* Start the daemon and wait until it's ready */ if (property_get(HOSTNAME_PROP_NAME, prop_value, NULL) && (prop_value[0] != '\0')) snprintf(daemon_cmd, sizeof(daemon_cmd), "%s_%s:-h %s %s", DAEMON_NAME, daemon_suffix, prop_value, interface); else snprintf(daemon_cmd, sizeof(daemon_cmd), "%s_%s:%s", DAEMON_NAME, daemon_suffix, interface); memset(prop_value, '\0', PROPERTY_VALUE_MAX); property_set(ctrl_prop, daemon_cmd); if (wait_for_property(daemon_prop_name, desired_status, 10) < 0) { snprintf(errmsg, sizeof(errmsg), "%s", "Timed out waiting for dhcpcd to start"); return -1; } /* Wait for the daemon to return a result */ if (wait_for_property(result_prop_name, NULL, 30) < 0) { snprintf(errmsg, sizeof(errmsg), "%s", "Timed out waiting for DHCP to finish"); return -1; } if (!property_get(result_prop_name, prop_value, NULL)) { /* shouldn't ever happen, given the success of wait_for_property() */ snprintf(errmsg, sizeof(errmsg), "%s", "DHCP result property was not set"); return -1; } if (strcmp(prop_value, "ok") == 0) { char dns_prop_name[PROPERTY_KEY_MAX]; if (fill_ip_info(interface, ipaddr, gateway, prefixLength, dns1, dns2, server, lease) == -1) { return -1; } /* copy dns data to system properties - TODO - remove this after we have async * notification of renewal's */ snprintf(dns_prop_name, sizeof(dns_prop_name), "net.%s.dns1", interface); property_set(dns_prop_name, *dns1 ? ipaddr_to_string(*dns1) : ""); snprintf(dns_prop_name, sizeof(dns_prop_name), "net.%s.dns2", interface); property_set(dns_prop_name, *dns2 ? ipaddr_to_string(*dns2) : ""); return 0; } else { snprintf(errmsg, sizeof(errmsg), "DHCP result was %s", prop_value); return -1; } }
/* * Start the dhcp client daemon, and wait for it to finish * configuring the interface. * * The device init.rc file needs a corresponding entry for this work. * * Example: * service dhcpcd_<interface> /system/bin/dhcpcd -ABKL -f dhcpcd.conf */ int dhcp_do_request(const char *interface, char *ipaddr, char *gateway, uint32_t *prefixLength, char *dns[], char *server, uint32_t *lease, char *vendorInfo, char *domain, char *mtu) { char result_prop_name[PROPERTY_KEY_MAX]; char daemon_prop_name[PROPERTY_KEY_MAX]; char prop_value[PROPERTY_VALUE_MAX] = {'\0'}; char daemon_cmd[PROPERTY_VALUE_MAX * 2 + sizeof(DHCP_CONFIG_PATH)]; const char *ctrl_prop = "ctl.start"; const char *desired_status = "running"; /* Interface name after converting p2p0-p2p0-X to p2p to reuse system properties */ char p2p_interface[MAX_INTERFACE_LENGTH]; get_p2p_interface_replacement(interface, p2p_interface); snprintf(result_prop_name, sizeof(result_prop_name), "%s.%s.result", DHCP_PROP_NAME_PREFIX, p2p_interface); snprintf(daemon_prop_name, sizeof(daemon_prop_name), "%s_%s", DAEMON_PROP_NAME, p2p_interface); /* Erase any previous setting of the dhcp result property */ property_set(result_prop_name, ""); /* HACK: Sometimes the lease file appears to be corrupted, which can cause * unknown errors while obtaining an address. We just remove the corresponding * lease file prior to starting the daemon... */ { char lease_file_path[PROPERTY_VALUE_MAX]; snprintf(lease_file_path, sizeof(lease_file_path), "/data/misc/dhcp/dhcpcd-%s.lease", p2p_interface); unlink(lease_file_path); } /* Start the daemon and wait until it's ready */ if (property_get(HOSTNAME_PROP_NAME, prop_value, NULL) && (prop_value[0] != '\0')) snprintf(daemon_cmd, sizeof(daemon_cmd), "%s_%s:-f %s -h %s %s", DAEMON_NAME, p2p_interface, DHCP_CONFIG_PATH, prop_value, interface); else snprintf(daemon_cmd, sizeof(daemon_cmd), "%s_%s:-f %s %s", DAEMON_NAME, p2p_interface, DHCP_CONFIG_PATH, interface); memset(prop_value, '\0', PROPERTY_VALUE_MAX); property_set(ctrl_prop, daemon_cmd); if (wait_for_property(daemon_prop_name, desired_status, 10) < 0) { snprintf(errmsg, sizeof(errmsg), "%s", "Timed out waiting for dhcpcd to start"); return -1; } /* Wait for the daemon to return a result */ if (wait_for_property(result_prop_name, NULL, 30) < 0) { snprintf(errmsg, sizeof(errmsg), "%s", "Timed out waiting for DHCP to finish"); return -1; } if (!property_get(result_prop_name, prop_value, NULL)) { /* shouldn't ever happen, given the success of wait_for_property() */ snprintf(errmsg, sizeof(errmsg), "%s", "DHCP result property was not set"); return -1; } if (strcmp(prop_value, "ok") == 0) { char dns_prop_name[PROPERTY_KEY_MAX]; if (fill_ip_info(interface, ipaddr, gateway, prefixLength, dns, server, lease, vendorInfo, domain, mtu) == -1) { return -1; } return 0; } else { snprintf(errmsg, sizeof(errmsg), "DHCP result was %s", prop_value); return -1; } }