2 * Copyright (C) 2008 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <sys/socket.h>
24 #include <sys/types.h>
29 #include <netinet/in.h>
30 #include <arpa/inet.h>
32 #define LOG_TAG "PppController"
33 #include <cutils/log.h>
35 #include "PppController.h"
37 extern "C" int logwrap(int argc, const char **argv, int background);
39 PppController::PppController() {
40 mTtys = new TtyCollection();
44 PppController::~PppController() {
45 TtyCollection::iterator it;
47 for (it = mTtys->begin(); it != mTtys->end(); ++it) {
53 int PppController::attachPppd(const char *tty, struct in_addr local,
54 struct in_addr remote, struct in_addr dns1,
55 struct in_addr dns2) {
59 LOGE("Multiple PPPD instances not currently supported");
64 TtyCollection::iterator it;
65 for (it = mTtys->begin(); it != mTtys->end(); ++it) {
66 if (!strcmp(tty, *it)) {
70 if (it == mTtys->end()) {
71 LOGE("Invalid tty '%s' specified", tty);
76 if ((pid = fork()) < 0) {
77 LOGE("fork failed (%s)", strerror(errno));
82 char *l = strdup(inet_ntoa(local));
83 char *r = strdup(inet_ntoa(remote));
84 char *d1 = strdup(inet_ntoa(dns1));
85 char *d2 = strdup(inet_ntoa(dns2));
89 asprintf(&lr, "%s:%s", l, r);
91 snprintf(dev, sizeof(dev), "/dev/%s", tty);
93 // TODO: Deal with pppd bailing out after 99999 seconds of being started
94 // but not getting a connection
95 if (execl("/system/bin/pppd", "/system/bin/pppd", "-detach", dev, "115200",
96 lr, "ms-dns", d1, "ms-dns", d2, "lcp-max-configure", "99999", (char *) NULL)) {
97 LOGE("execl failed (%s)", strerror(errno));
99 LOGE("Should never get here!");
107 int PppController::detachPppd(const char *tty) {
110 LOGE("PPPD already stopped");
114 LOGD("Stopping PPPD services on port %s", tty);
116 waitpid(mPid, NULL, 0);
118 LOGD("PPPD services on port %s stopped", tty);
122 TtyCollection *PppController::getTtyList() {
127 int PppController::updateTtyList() {
128 TtyCollection::iterator it;
130 for (it = mTtys->begin(); it != mTtys->end(); ++it) {
135 DIR *d = opendir("/sys/class/tty");
137 LOGE("Error opening /sys/class/tty (%s)", strerror(errno));
142 while ((de = readdir(d))) {
143 if (de->d_name[0] == '.')
145 if ((!strncmp(de->d_name, "tty", 3)) && (strlen(de->d_name) > 3)) {
146 mTtys->push_back(strdup(de->d_name));