summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings/ppp/modem.cpp
Unidiff
Diffstat (limited to 'noncore/settings/networksettings/ppp/modem.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/settings/networksettings/ppp/modem.cpp85
1 files changed, 71 insertions, 14 deletions
diff --git a/noncore/settings/networksettings/ppp/modem.cpp b/noncore/settings/networksettings/ppp/modem.cpp
index d23fee4..3dbc8c3 100644
--- a/noncore/settings/networksettings/ppp/modem.cpp
+++ b/noncore/settings/networksettings/ppp/modem.cpp
@@ -52,9 +52,6 @@
52#include "modem.h" 52#include "modem.h"
53#include "pppdata.h" 53#include "pppdata.h"
54//#include <klocale.h>
55#define i18n QObject::tr
56#define qError qDebug 54#define qError qDebug
57//#include <kdebug.h> 55
58//#include <config.h>
59 56
60#define MY_ASSERT(x) if (!(x)) { \ 57#define MY_ASSERT(x) if (!(x)) { \
@@ -100,5 +97,5 @@ Modem::Modem( PPPData* pd )
100 _pppdExitStatus = -1; 97 _pppdExitStatus = -1;
101 pppdPid = -1; 98 pppdPid = -1;
102 sn = 0L; 99 sn = m_modemDebug = 0L;
103 data_mode = false; 100 data_mode = false;
104 modem_is_locked = false; 101 modem_is_locked = false;
@@ -170,5 +167,5 @@ bool Modem::opentty() {
170 if ((modemfd = open(device, O_RDWR|O_NDELAY|O_NOCTTY)) == -1) { 167 if ((modemfd = open(device, O_RDWR|O_NDELAY|O_NOCTTY)) == -1) {
171 qDebug("error opening modem device !"); 168 qDebug("error opening modem device !");
172 errmsg = i18n("Unable to open modem."); 169 errmsg = QObject::tr("Unable to open modem.");
173 return false; 170 return false;
174 } 171 }
@@ -179,5 +176,5 @@ bool Modem::opentty() {
179 if(_pppdata->UseCDLine()) { 176 if(_pppdata->UseCDLine()) {
180 if(ioctl(modemfd, TIOCMGET, &flags) == -1) { 177 if(ioctl(modemfd, TIOCMGET, &flags) == -1) {
181 errmsg = i18n("Unable to detect state of CD line."); 178 errmsg = QObject::tr("Unable to detect state of CD line.");
182 ::close(modemfd); 179 ::close(modemfd);
183 modemfd = -1; 180 modemfd = -1;
@@ -185,5 +182,5 @@ bool Modem::opentty() {
185 } 182 }
186 if ((flags&TIOCM_CD) == 0) { 183 if ((flags&TIOCM_CD) == 0) {
187 errmsg = i18n("The modem is not ready."); 184 errmsg = QObject::tr("The modem is not ready.");
188 ::close(modemfd); 185 ::close(modemfd);
189 modemfd = -1; 186 modemfd = -1;
@@ -201,5 +198,5 @@ bool Modem::opentty() {
201 sleep(1); 198 sleep(1);
202 if(tcgetattr(modemfd, &tty) < 0){ 199 if(tcgetattr(modemfd, &tty) < 0){
203 errmsg = i18n("The modem is busy."); 200 errmsg = QObject::tr("The modem is busy.");
204 ::close(modemfd); 201 ::close(modemfd);
205 modemfd = -1; 202 modemfd = -1;
@@ -246,5 +243,5 @@ bool Modem::opentty() {
246 243
247 if(tcsetattr(modemfd, TCSANOW, &tty) < 0){ 244 if(tcsetattr(modemfd, TCSANOW, &tty) < 0){
248 errmsg = i18n("The modem is busy."); 245 errmsg = QObject::tr("The modem is busy.");
249 ::close(modemfd); 246 ::close(modemfd);
250 modemfd=-1; 247 modemfd=-1;
@@ -252,5 +249,5 @@ bool Modem::opentty() {
252 } 249 }
253 250
254 errmsg = i18n("Modem Ready."); 251 errmsg = QObject::tr("Modem Ready.");
255 return true; 252 return true;
256} 253}
@@ -264,5 +261,5 @@ bool Modem::closetty() {
264 261
265 if(tcsetattr(modemfd, TCSANOW, &initial_tty) < 0){ 262 if(tcsetattr(modemfd, TCSANOW, &initial_tty) < 0){
266 errmsg = i18n("Can't restore tty settings: tcsetattr()\n"); 263 errmsg = QObject::tr("Can't restore tty settings: tcsetattr()\n");
267 ::close(modemfd); 264 ::close(modemfd);
268 modemfd = -1; 265 modemfd = -1;
@@ -414,5 +411,5 @@ bool Modem::hangup() {
414 close(modemfd); 411 close(modemfd);
415 modemfd = -1; 412 modemfd = -1;
416 errmsg = i18n("The modem does not respond."); 413 errmsg = QObject::tr("The modem does not respond.");
417 return false; 414 return false;
418 } 415 }
@@ -556,5 +553,5 @@ QString Modem::parseModemSpeed(const QString &s) {
556 553
557 if(rx == -1 && tx == -1) 554 if(rx == -1 && tx == -1)
558 result = i18n("Unknown speed"); 555 result = QObject::tr("Unknown speed");
559 else if(tx == -1) 556 else if(tx == -1)
560 result.setNum(rx); 557 result.setNum(rx);
@@ -878,8 +875,12 @@ bool Modem::execpppd(const char *arguments) {
878 _pppdExitStatus = -1; 875 _pppdExitStatus = -1;
879 876
877 (void)::pipe( m_pppdLOG );
878
880 switch(pppdPid = fork()) 879 switch(pppdPid = fork())
881 { 880 {
882 case -1: 881 case -1:
883 fprintf(stderr,"In parent: fork() failed\n"); 882 fprintf(stderr,"In parent: fork() failed\n");
883 ::close( m_pppdLOG[0] );
884 ::close( m_pppdLOG[1] );
884 return false; 885 return false;
885 break; 886 break;
@@ -903,7 +904,11 @@ bool Modem::execpppd(const char *arguments) {
903 fprintf(stderr, "tcsetpgrp() failed.\n"); 904 fprintf(stderr, "tcsetpgrp() failed.\n");
904 905
906 ::close( m_pppdLOG[0] );
907 ::setenv( "LANG", "C", 1 ); // overwrite
908 dup2(m_pppdLOG[1], 11 ); // for logfd 11
905 dup2(modemfd, 0); 909 dup2(modemfd, 0);
906 dup2(modemfd, 1); 910 dup2(modemfd, 1);
907 911
912
908 switch (checkForInterface()) { 913 switch (checkForInterface()) {
909 case 1: 914 case 1:
@@ -925,5 +930,22 @@ bool Modem::execpppd(const char *arguments) {
925 qDebug("In parent: pppd pid %d\n",pppdPid); 930 qDebug("In parent: pppd pid %d\n",pppdPid);
926 close(modemfd); 931 close(modemfd);
932
933 ::close( m_pppdLOG[1] );
934 // set it to nonblocking io
935 int flag = ::fcntl( m_pppdLOG[0], F_GETFL );
936
937 if ( !(flag & O_NONBLOCK) ) {
938 qDebug("Setting nonblocking io");
939 flag |= O_NONBLOCK;
940 ::fcntl(m_pppdLOG[0], F_SETFL, flag );
941 }
942
943 delete m_modemDebug;
944 m_modemDebug = new QSocketNotifier(m_pppdLOG[0], QSocketNotifier::Read, this );
945 connect(m_modemDebug, SIGNAL(activated(int) ),
946 this, SLOT(slotModemDebug(int) ) );
947
927 modemfd = -1; 948 modemfd = -1;
949 m_pppdDev = QString::fromLatin1("ppp0");
928 return true; 950 return true;
929 break; 951 break;
@@ -933,5 +955,8 @@ bool Modem::execpppd(const char *arguments) {
933 955
934bool Modem::killpppd() { 956bool Modem::killpppd() {
957 qDebug("In killpppd and pid is %d", pppdPid );
935 if(pppdPid > 0) { 958 if(pppdPid > 0) {
959 delete m_modemDebug;
960 m_modemDebug = 0;
936 qDebug("In killpppd(): Sending SIGTERM to %d\n", pppdPid); 961 qDebug("In killpppd(): Sending SIGTERM to %d\n", pppdPid);
937 if(kill(pppdPid, SIGTERM) < 0) { 962 if(kill(pppdPid, SIGTERM) < 0) {
@@ -1022,2 +1047,34 @@ bool Modem::setHostname(const QString & name)
1022} 1047}
1023 1048
1049QString Modem::pppDevice()const {
1050 return m_pppdDev;
1051}
1052void Modem::setPPPDevice( const QString& dev ) {
1053 m_pppdDev = dev;
1054}
1055pid_t Modem::pppPID()const {
1056 return pppdPid;
1057}
1058void Modem::setPPPDPid( pid_t pid ) {
1059 qDebug("Modem setting pid");
1060 _pppdExitStatus = -1;
1061 pppdPid = pid;
1062 modemfd = -1;
1063}
1064void Modem::slotModemDebug(int fd) {
1065 char buf[2049];
1066 int len;
1067
1068 // read in pppd data look for Using interface
1069 // then read the interface
1070 // we limit to 10 device now 0-9
1071 if((len = ::read(fd, buf, 2048)) > 0) {
1072 buf[len+1] = '\0';
1073 char *found;
1074 if ( (found = ::strstr(buf, "Using interface ") ) ) {
1075 found += 16;
1076 m_pppdDev = QString::fromLatin1(found, 5 );
1077 m_pppdDev = m_pppdDev.simplifyWhiteSpace();
1078 }
1079 }
1080}