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 PppController::PppController() {
38 mTtys = new TtyCollection();
42 PppController::~PppController() {
43 TtyCollection::iterator it;
45 for (it = mTtys->begin(); it != mTtys->end(); ++it) {
51 int PppController::attachPppd(const char *tty, struct in_addr local,
52 struct in_addr remote, struct in_addr dns1,
53 struct in_addr dns2) {
57 ALOGE("Multiple PPPD instances not currently supported");
62 TtyCollection::iterator it;
63 for (it = mTtys->begin(); it != mTtys->end(); ++it) {
64 if (!strcmp(tty, *it)) {
68 if (it == mTtys->end()) {
69 ALOGE("Invalid tty '%s' specified", tty);
74 if ((pid = fork()) < 0) {
75 ALOGE("fork failed (%s)", strerror(errno));
80 char *l = strdup(inet_ntoa(local));
81 char *r = strdup(inet_ntoa(remote));
82 char *d1 = strdup(inet_ntoa(dns1));
83 char *d2 = strdup(inet_ntoa(dns2));
87 asprintf(&lr, "%s:%s", l, r);
89 snprintf(dev, sizeof(dev), "/dev/%s", tty);
91 // TODO: Deal with pppd bailing out after 99999 seconds of being started
92 // but not getting a connection
93 if (execl("/system/bin/pppd", "/system/bin/pppd", "-detach", dev, "115200",
94 lr, "ms-dns", d1, "ms-dns", d2, "lcp-max-configure", "99999", (char *) NULL)) {
95 ALOGE("execl failed (%s)", strerror(errno));
97 ALOGE("Should never get here!");
105 int PppController::detachPppd(const char *tty) {
108 ALOGE("PPPD already stopped");
112 ALOGD("Stopping PPPD services on port %s", tty);
114 waitpid(mPid, NULL, 0);
116 ALOGD("PPPD services on port %s stopped", tty);
120 TtyCollection *PppController::getTtyList() {
125 int PppController::updateTtyList() {
126 TtyCollection::iterator it;
128 for (it = mTtys->begin(); it != mTtys->end(); ++it) {
133 DIR *d = opendir("/sys/class/tty");
135 ALOGE("Error opening /sys/class/tty (%s)", strerror(errno));
140 while ((de = readdir(d))) {
141 if (de->d_name[0] == '.')
143 if ((!strncmp(de->d_name, "tty", 3)) && (strlen(de->d_name) > 3)) {
144 mTtys->push_back(strdup(de->d_name));