summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings/ppp/modem.cpp
Unidiff
Diffstat (limited to 'noncore/settings/networksettings/ppp/modem.cpp') (more/less context) (ignore 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
@@ -51,11 +51,8 @@
51#include "auth.h" 51#include "auth.h"
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)) { \
61 qFatal( "ASSERT: \"%s\" in %s (%d)\n",#x,__FILE__,__LINE__); \ 58 qFatal( "ASSERT: \"%s\" in %s (%d)\n",#x,__FILE__,__LINE__); \
@@ -99,7 +96,7 @@ Modem::Modem( PPPData* pd )
99 modemfd = -1; 96 modemfd = -1;
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;
105 lockfile[0] = '\0'; 102 lockfile[0] = '\0';
@@ -169,7 +166,7 @@ bool Modem::opentty() {
169 device = _pppdata->modemDevice(); 166 device = _pppdata->modemDevice();
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 }
175//bend if((modemfd = Requester::rq->openModem(gpppdata.modemDevice()))<0) { 172//bend if((modemfd = Requester::rq->openModem(gpppdata.modemDevice()))<0) {
@@ -178,13 +175,13 @@ bool Modem::opentty() {
178#if 0 175#if 0
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;
184 return false; 181 return false;
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;
190 return false; 187 return false;
@@ -200,7 +197,7 @@ bool Modem::opentty() {
200 tcsendbreak(modemfd, 0); 197 tcsendbreak(modemfd, 0);
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;
206 return false; 203 return false;
@@ -245,13 +242,13 @@ bool Modem::opentty() {
245 tcdrain(modemfd); 242 tcdrain(modemfd);
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;
251 return false; 248 return false;
252 } 249 }
253 250
254 errmsg = i18n("Modem Ready."); 251 errmsg = QObject::tr("Modem Ready.");
255 return true; 252 return true;
256} 253}
257 254
@@ -263,7 +260,7 @@ bool Modem::closetty() {
263 tcflush(modemfd, TCIOFLUSH); 260 tcflush(modemfd, TCIOFLUSH);
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;
269 return false; 266 return false;
@@ -413,7 +410,7 @@ bool Modem::hangup() {
413 closetty(); 410 closetty();
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 }
419 416
@@ -555,7 +552,7 @@ QString Modem::parseModemSpeed(const QString &s) {
555 } 552 }
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);
561 else if(rx == -1) // should not happen 558 else if(rx == -1) // should not happen
@@ -877,10 +874,14 @@ bool Modem::execpppd(const char *arguments) {
877 874
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;
886 887
@@ -902,9 +903,13 @@ bool Modem::execpppd(const char *arguments) {
902 if(tcsetpgrp(modemfd, pgrpid)<0) 903 if(tcsetpgrp(modemfd, pgrpid)<0)
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:
910 fprintf(stderr, "Cannot determine if kernel supports ppp.\n"); 915 fprintf(stderr, "Cannot determine if kernel supports ppp.\n");
@@ -924,7 +929,24 @@ bool Modem::execpppd(const char *arguments) {
924 default: 929 default:
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;
930 } 952 }
@@ -932,7 +954,10 @@ bool Modem::execpppd(const char *arguments) {
932 954
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) {
938 qDebug("Error terminating %d. Sending SIGKILL\n", pppdPid); 963 qDebug("Error terminating %d. Sending SIGKILL\n", pppdPid);
@@ -1021,3 +1046,35 @@ bool Modem::setHostname(const QString & name)
1021 return sethostname(name, name.length()) == 0; 1046 return sethostname(name, name.length()) == 0;
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}