Diffstat (limited to 'noncore/settings/networksettings/ppp/modem.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/settings/networksettings/ppp/modem.cpp | 45 |
1 files changed, 22 insertions, 23 deletions
diff --git a/noncore/settings/networksettings/ppp/modem.cpp b/noncore/settings/networksettings/ppp/modem.cpp index 5139482..002c8e7 100644 --- a/noncore/settings/networksettings/ppp/modem.cpp +++ b/noncore/settings/networksettings/ppp/modem.cpp | |||
@@ -59,13 +59,13 @@ | |||
59 | qFatal( "ASSERT: \"%s\" in %s (%d)\n",#x,__FILE__,__LINE__); \ | 59 | qFatal( "ASSERT: \"%s\" in %s (%d)\n",#x,__FILE__,__LINE__); \ |
60 | exit(1); } | 60 | exit(1); } |
61 | 61 | ||
62 | 62 | ||
63 | static sigjmp_buf jmp_buffer; | 63 | static sigjmp_buf jmp_buffer; |
64 | 64 | ||
65 | Modem *Modem::modem = 0; | 65 | //Modem *Modem::modem = 0; |
66 | 66 | ||
67 | 67 | ||
68 | const char* pppdPath() { | 68 | const char* pppdPath() { |
69 | // wasting a few bytes | 69 | // wasting a few bytes |
70 | static char buffer[sizeof(PPPDSEARCHPATH)+sizeof(PPPDNAME)]; | 70 | static char buffer[sizeof(PPPDSEARCHPATH)+sizeof(PPPDNAME)]; |
71 | static char *pppdPath = 0L; | 71 | static char *pppdPath = 0L; |
@@ -88,37 +88,36 @@ const char* pppdPath() { | |||
88 | } | 88 | } |
89 | 89 | ||
90 | return pppdPath; | 90 | return pppdPath; |
91 | } | 91 | } |
92 | 92 | ||
93 | 93 | ||
94 | Modem::Modem() | 94 | Modem::Modem( PPPData* pd ) |
95 | { | 95 | { |
96 | if (Modem::modem != 0) return; //CORRECT? | 96 | _pppdata = pd; |
97 | modemfd = -1; | 97 | modemfd = -1; |
98 | _pppdExitStatus = -1; | 98 | _pppdExitStatus = -1; |
99 | pppdPid = -1; | 99 | pppdPid = -1; |
100 | sn = 0L; | 100 | sn = 0L; |
101 | data_mode = false; | 101 | data_mode = false; |
102 | modem_is_locked = false; | 102 | modem_is_locked = false; |
103 | lockfile[0] = '\0'; | 103 | lockfile[0] = '\0'; |
104 | device = "/dev/modem"; | 104 | device = "/dev/modem"; |
105 | modem = this; | ||
106 | } | 105 | } |
107 | 106 | ||
108 | 107 | ||
109 | Modem::~Modem() { | 108 | Modem::~Modem() |
110 | modem = 0; | 109 | { |
111 | } | 110 | } |
112 | 111 | ||
113 | 112 | ||
114 | speed_t Modem::modemspeed() { | 113 | speed_t Modem::modemspeed() { |
115 | // convert the string modem speed int the gpppdata object to a t_speed type | 114 | // convert the string modem speed int the gpppdata object to a t_speed type |
116 | // to set the modem. The constants here should all be ifdef'd because | 115 | // to set the modem. The constants here should all be ifdef'd because |
117 | // other systems may not have them | 116 | // other systems may not have them |
118 | int i = PPPData::data()->speed().toInt()/100; | 117 | int i = _pppdata->speed().toInt()/100; |
119 | 118 | ||
120 | switch(i) { | 119 | switch(i) { |
121 | case 24: | 120 | case 24: |
122 | return B2400; | 121 | return B2400; |
123 | break; | 122 | break; |
124 | case 96: | 123 | case 96: |
@@ -162,23 +161,23 @@ speed_t Modem::modemspeed() { | |||
162 | 161 | ||
163 | bool Modem::opentty() { | 162 | bool Modem::opentty() { |
164 | // int flags; | 163 | // int flags; |
165 | 164 | ||
166 | //begin if((modemfd = Requester::rq->openModem(gpppdata.modemDevice()))<0) { | 165 | //begin if((modemfd = Requester::rq->openModem(gpppdata.modemDevice()))<0) { |
167 | close(modemfd); | 166 | close(modemfd); |
168 | device = PPPData::data()->modemDevice(); | 167 | device = _pppdata->modemDevice(); |
169 | if ((modemfd = open(device, O_RDWR|O_NDELAY|O_NOCTTY)) == -1) { | 168 | if ((modemfd = open(device, O_RDWR|O_NDELAY|O_NOCTTY)) == -1) { |
170 | qDebug("error opening modem device !"); | 169 | qDebug("error opening modem device !"); |
171 | errmsg = i18n("Unable to open modem."); | 170 | errmsg = i18n("Unable to open modem."); |
172 | return false; | 171 | return false; |
173 | } | 172 | } |
174 | //bend if((modemfd = Requester::rq->openModem(gpppdata.modemDevice()))<0) { | 173 | //bend if((modemfd = Requester::rq->openModem(gpppdata.modemDevice()))<0) { |
175 | //} | 174 | //} |
176 | 175 | ||
177 | #if 0 | 176 | #if 0 |
178 | if(PPPData::data()->UseCDLine()) { | 177 | if(_pppdata->UseCDLine()) { |
179 | if(ioctl(modemfd, TIOCMGET, &flags) == -1) { | 178 | if(ioctl(modemfd, TIOCMGET, &flags) == -1) { |
180 | errmsg = i18n("Unable to detect state of CD line."); | 179 | errmsg = i18n("Unable to detect state of CD line."); |
181 | ::close(modemfd); | 180 | ::close(modemfd); |
182 | modemfd = -1; | 181 | modemfd = -1; |
183 | return false; | 182 | return false; |
184 | } | 183 | } |
@@ -220,14 +219,14 @@ bool Modem::opentty() { | |||
220 | tty.c_cflag |= CLOCAL; // ignore modem status lines | 219 | tty.c_cflag |= CLOCAL; // ignore modem status lines |
221 | tty.c_iflag = IGNBRK | IGNPAR /* | ISTRIP */ ; | 220 | tty.c_iflag = IGNBRK | IGNPAR /* | ISTRIP */ ; |
222 | tty.c_lflag &= ~ICANON; // non-canonical mode | 221 | tty.c_lflag &= ~ICANON; // non-canonical mode |
223 | tty.c_lflag &= ~(ECHO|ECHOE|ECHOK|ECHOKE); | 222 | tty.c_lflag &= ~(ECHO|ECHOE|ECHOK|ECHOKE); |
224 | 223 | ||
225 | 224 | ||
226 | if(PPPData::data()->flowcontrol() != "None") { | 225 | if(_pppdata->flowcontrol() != "None") { |
227 | if(PPPData::data()->flowcontrol() == "CRTSCTS") { | 226 | if(_pppdata->flowcontrol() == "CRTSCTS") { |
228 | tty.c_cflag |= CRTSCTS; | 227 | tty.c_cflag |= CRTSCTS; |
229 | } | 228 | } |
230 | else { | 229 | else { |
231 | tty.c_iflag |= IXON | IXOFF; | 230 | tty.c_iflag |= IXON | IXOFF; |
232 | tty.c_cc[VSTOP] = 0x13; /* DC3 = XOFF = ^S */ | 231 | tty.c_cc[VSTOP] = 0x13; /* DC3 = XOFF = ^S */ |
233 | tty.c_cc[VSTART] = 0x11; /* DC1 = XON = ^Q */ | 232 | tty.c_cc[VSTART] = 0x11; /* DC1 = XON = ^Q */ |
@@ -350,13 +349,13 @@ bool Modem::writeChar(unsigned char c) { | |||
350 | 349 | ||
351 | bool Modem::writeLine(const char *buf) { | 350 | bool Modem::writeLine(const char *buf) { |
352 | int len = strlen(buf); | 351 | int len = strlen(buf); |
353 | char *b = new char[len+2]; | 352 | char *b = new char[len+2]; |
354 | memcpy(b, buf, len); | 353 | memcpy(b, buf, len); |
355 | // different modems seem to need different line terminations | 354 | // different modems seem to need different line terminations |
356 | QString term = PPPData::data()->enter(); | 355 | QString term = _pppdata->enter(); |
357 | if(term == "LF") | 356 | if(term == "LF") |
358 | b[len++]='\n'; | 357 | b[len++]='\n'; |
359 | else if(term == "CR") | 358 | else if(term == "CR") |
360 | b[len++]='\r'; | 359 | b[len++]='\r'; |
361 | else if(term == "CR/LF") { | 360 | else if(term == "CR/LF") { |
362 | b[len++]='\r'; | 361 | b[len++]='\r'; |
@@ -390,15 +389,15 @@ bool Modem::hangup() { | |||
390 | 389 | ||
391 | // is this Escape & HangupStr stuff really necessary ? (Harri) | 390 | // is this Escape & HangupStr stuff really necessary ? (Harri) |
392 | 391 | ||
393 | if (data_mode) escape_to_command_mode(); | 392 | if (data_mode) escape_to_command_mode(); |
394 | 393 | ||
395 | // Then hangup command | 394 | // Then hangup command |
396 | writeLine(PPPData::data()->modemHangupStr().local8Bit()); | 395 | writeLine(_pppdata->modemHangupStr().local8Bit()); |
397 | 396 | ||
398 | usleep(PPPData::data()->modemInitDelay() * 10000); // 0.01 - 3.0 sec | 397 | usleep(_pppdata->modemInitDelay() * 10000); // 0.01 - 3.0 sec |
399 | 398 | ||
400 | #ifndef DEBUG_WO_DIALING | 399 | #ifndef DEBUG_WO_DIALING |
401 | if (sigsetjmp(jmp_buffer, 1) == 0) { | 400 | if (sigsetjmp(jmp_buffer, 1) == 0) { |
402 | // set alarm in case tcsendbreak() hangs | 401 | // set alarm in case tcsendbreak() hangs |
403 | signal(SIGALRM, alarm_handler); | 402 | signal(SIGALRM, alarm_handler); |
404 | alarm(2); | 403 | alarm(2); |
@@ -428,13 +427,13 @@ bool Modem::hangup() { | |||
428 | ioctl(modemfd, TIOCMSET, &modemstat); | 427 | ioctl(modemfd, TIOCMSET, &modemstat); |
429 | ioctl(modemfd, TIOCMGET, &modemstat); | 428 | ioctl(modemfd, TIOCMGET, &modemstat); |
430 | modemstat |= TIOCM_DTR; | 429 | modemstat |= TIOCM_DTR; |
431 | ioctl(modemfd, TIOCMSET, &modemstat); | 430 | ioctl(modemfd, TIOCMSET, &modemstat); |
432 | #endif | 431 | #endif |
433 | 432 | ||
434 | usleep(PPPData::data()->modemInitDelay() * 10000); // 0.01 - 3.0 secs | 433 | usleep(_pppdata->modemInitDelay() * 10000); // 0.01 - 3.0 secs |
435 | 434 | ||
436 | cfsetospeed(&temptty, modemspeed()); | 435 | cfsetospeed(&temptty, modemspeed()); |
437 | cfsetispeed(&temptty, modemspeed()); | 436 | cfsetispeed(&temptty, modemspeed()); |
438 | tcsetattr(modemfd, TCSAFLUSH, &temptty); | 437 | tcsetattr(modemfd, TCSAFLUSH, &temptty); |
439 | #endif | 438 | #endif |
440 | return true; | 439 | return true; |
@@ -451,17 +450,17 @@ void Modem::escape_to_command_mode() { | |||
451 | // Need to send properly timed escape sequence to put modem in command state. | 450 | // Need to send properly timed escape sequence to put modem in command state. |
452 | // Escape codes and guard times are controlled by S2 and S12 values. | 451 | // Escape codes and guard times are controlled by S2 and S12 values. |
453 | // | 452 | // |
454 | tcflush(modemfd, TCIOFLUSH); | 453 | tcflush(modemfd, TCIOFLUSH); |
455 | 454 | ||
456 | // +3 because quiet time must be greater than guard time. | 455 | // +3 because quiet time must be greater than guard time. |
457 | usleep((PPPData::data()->modemEscapeGuardTime()+3)*20000); | 456 | usleep((_pppdata->modemEscapeGuardTime()+3)*20000); |
458 | QCString tmp = PPPData::data()->modemEscapeStr().local8Bit(); | 457 | QCString tmp = _pppdata->modemEscapeStr().local8Bit(); |
459 | write(modemfd, tmp.data(), tmp.length()); | 458 | write(modemfd, tmp.data(), tmp.length()); |
460 | tcflush(modemfd, TCIOFLUSH); | 459 | tcflush(modemfd, TCIOFLUSH); |
461 | usleep((PPPData::data()->modemEscapeGuardTime()+3)*20000); | 460 | usleep((_pppdata->modemEscapeGuardTime()+3)*20000); |
462 | 461 | ||
463 | data_mode = false; | 462 | data_mode = false; |
464 | } | 463 | } |
465 | 464 | ||
466 | 465 | ||
467 | const QString Modem::modemMessage() { | 466 | const QString Modem::modemMessage() { |
@@ -571,22 +570,22 @@ QString Modem::parseModemSpeed(const QString &s) { | |||
571 | // Lock modem device. Returns 0 on success 1 if the modem is locked and -1 if | 570 | // Lock modem device. Returns 0 on success 1 if the modem is locked and -1 if |
572 | // a lock file can't be created ( permission problem ) | 571 | // a lock file can't be created ( permission problem ) |
573 | int Modem::lockdevice() { | 572 | int Modem::lockdevice() { |
574 | int fd; | 573 | int fd; |
575 | char newlock[80]=""; // safe | 574 | char newlock[80]=""; // safe |
576 | 575 | ||
577 | if(!PPPData::data()->modemLockFile()) { | 576 | if(!_pppdata->modemLockFile()) { |
578 | qDebug("The user doesn't want a lockfile."); | 577 | qDebug("The user doesn't want a lockfile."); |
579 | return 0; | 578 | return 0; |
580 | } | 579 | } |
581 | 580 | ||
582 | if (modem_is_locked) | 581 | if (modem_is_locked) |
583 | return 1; | 582 | return 1; |
584 | 583 | ||
585 | QString lockfile = LOCK_DIR"/LCK.."; | 584 | QString lockfile = LOCK_DIR"/LCK.."; |
586 | lockfile += PPPData::data()->modemDevice().mid(5); // append everything after /dev/ | 585 | lockfile += _pppdata->modemDevice().mid(5); // append everything after /dev/ |
587 | 586 | ||
588 | if(access(QFile::encodeName(lockfile), F_OK) == 0) { | 587 | if(access(QFile::encodeName(lockfile), F_OK) == 0) { |
589 | // if ((fd = Requester::rq-> | 588 | // if ((fd = Requester::rq-> |
590 | if ((fd = openLockfile(QFile::encodeName(lockfile), O_RDONLY)) >= 0) { | 589 | if ((fd = openLockfile(QFile::encodeName(lockfile), O_RDONLY)) >= 0) { |
591 | // Mario: it's not necessary to read more than lets say 32 bytes. If | 590 | // Mario: it's not necessary to read more than lets say 32 bytes. If |
592 | // file has more than 32 bytes, skip the rest | 591 | // file has more than 32 bytes, skip the rest |
@@ -611,13 +610,13 @@ if ((fd = openLockfile(QFile::encodeName(lockfile), O_RDONLY)) >= 0) { | |||
611 | return 1; | 610 | return 1; |
612 | 611 | ||
613 | qDebug( "lockfile is stale" ); | 612 | qDebug( "lockfile is stale" ); |
614 | } | 613 | } |
615 | } | 614 | } |
616 | 615 | ||
617 | fd = openLockfile(PPPData::data()->modemDevice(),O_WRONLY|O_TRUNC|O_CREAT); | 616 | fd = openLockfile(_pppdata->modemDevice(),O_WRONLY|O_TRUNC|O_CREAT); |
618 | if(fd >= 0) { | 617 | if(fd >= 0) { |
619 | sprintf(newlock,"%010d\n", getpid()); | 618 | sprintf(newlock,"%010d\n", getpid()); |
620 | qDebug("Locking Device: %s", newlock); | 619 | qDebug("Locking Device: %s", newlock); |
621 | 620 | ||
622 | write(fd, newlock, strlen(newlock)); | 621 | write(fd, newlock, strlen(newlock)); |
623 | close(fd); | 622 | close(fd); |
@@ -985,21 +984,21 @@ void Modem::parseargs(char* buf, char** args) { | |||
985 | *args = 0L; | 984 | *args = 0L; |
986 | } | 985 | } |
987 | 986 | ||
988 | bool Modem::execPPPDaemon(const QString & arguments) | 987 | bool Modem::execPPPDaemon(const QString & arguments) |
989 | { | 988 | { |
990 | if(execpppd(arguments)==0) { | 989 | if(execpppd(arguments)==0) { |
991 | PPPData::data()->setpppdRunning(true); | 990 | _pppdata->setpppdRunning(true); |
992 | return true; | 991 | return true; |
993 | } else | 992 | } else |
994 | return false; | 993 | return false; |
995 | } | 994 | } |
996 | 995 | ||
997 | void Modem::killPPPDaemon() | 996 | void Modem::killPPPDaemon() |
998 | { | 997 | { |
999 | PPPData::data()->setpppdRunning(false); | 998 | _pppdata->setpppdRunning(false); |
1000 | killpppd(); | 999 | killpppd(); |
1001 | } | 1000 | } |
1002 | 1001 | ||
1003 | int Modem::pppdExitStatus() | 1002 | int Modem::pppdExitStatus() |
1004 | { | 1003 | { |
1005 | return _pppdExitStatus; | 1004 | return _pppdExitStatus; |