}
/*
- * Receive an HDLC frame. The timeout is against
- * the receipt of the HDLC flags; the frame itself must
+ * Receive an HDLC frame. The frame itself must
* be received within 3 seconds (per the spec).
* If a carrier is received, but the complete frame
* is not received before the timeout, the receive
{
int c;
/*
- * Search for HDLC frame flags. The
- * timeout is to reception of the flags.
+ * The spec says that a frame that takes between
+ * 2.55 and 3.45 seconds to be received may be
+ * discarded; we also add some time for DCE
+ * to detect and strip flags.
+ */
+ startTimeout(5000);
+ /*
+ * Strip HDLC frame flags. This is not needed,
+ * (according to the standard DCE does the job),
+ * be we leave this legacy code unchanged
+ * for sure - D.B.
*/
do {
c = getModemChar(0);
} while (c != EOF && c != 0xff);
- stopTimeout("waiting for HDLC flags");
- if (c == 0xff) { // flags received
- /*
- * The spec says that a frame that takes between
- * 2.55 and 3.45 seconds to be received may be
- * discarded; we use 3.1 seconds as a compromise.
- */
- startTimeout(3100);
+ if (c == 0xff) { // address field received
do {
if (c == DLE) {
c = getModemChar(0);
}
frame.put(frameRev[c]);
} while ((c = getModemChar(0)) != EOF);
- stopTimeout("receiving HDLC frame data");
}
+ stopTimeout("receiving HDLC frame data");
if (wasTimeout()) {
abortReceive();
return (false);
frame.reset();
startTimeout(ms);
bool readPending = atCmd(rhCmd, AT_NOTHING);
- if (readPending && waitFor(AT_CONNECT,0))
- return recvRawFrame(frame); // NB: stops inherited timeout
+ if (readPending && waitFor(AT_CONNECT,0)){
+ stopTimeout("waiting for HDLC flags");
+ if (wasTimeout()){
+ abortReceive();
+ return (false);
+ }
+ return recvRawFrame(frame);
+ }
stopTimeout("waiting for v.21 carrier");
if (readPending && wasTimeout())
abortReceive();
time_t start = Sys::now();
HDLCFrame frame(conf.class1FrameOverhead);
- startTimeout(conf.t2Timer);
bool framerecvd = recvRawFrame(frame);
- stopTimeout("receiving id frame");
for (;;) {
if (framerecvd) {
/*
*/
params.br = curcap->br;
dcs = (dcs &~ DCS_SIGRATE) | curcap->sr;
- int t = 2;
+ /*
+ * Set the number of train attemps on the same
+ * modulation; having set it to 1 we immediately drop
+ * the speed if the training has been failed.
+ * This parameter is not specified by T.30
+ * (the algorith left implementation defined),
+ * so we choose the exact value according to our
+ * common sense.
+ */
+ int t = 1;
do {
protoTrace("SEND training at %s %s",
modulationNames[curcap->mod],
pause(conf.class1TrainingRecovery);
} while (--t > 0);
/*
- * Two attempts at the current speed failed, drop
+ * (t) attempts at the current speed failed, drop
* the signalling rate to the next lower rate supported
* by the local & remote sides and try again.
*/
return (false);
}
emsg = "No response to MPS or EOP repeated 3 tries";
+ protoTrace(emsg);
return (false);
}
// XXX: workaround yet another GCC bug (sigh)
const fxStr& flow = conf.getFlowCmd(conf.flowControl);
resetCmds = "AT"
- | stripAT(conf.softResetCmd)
- | "\nAT"
| stripAT(conf.resetCmds) // prepend to insure our needs
| stripAT(conf.echoOffCmd)
| stripAT(conf.verboseResultsCmd)
*/
server.reopenDevice();
#endif
- if (!setBaudRate(rate, iFlow, oFlow))
- return (false);
+ if (!setBaudRate(rate, iFlow, oFlow)) {
+ return (false);
+ }
flushModemInput();
- return atCmd(resetCmds, AT_OK, ms);
+ /*
+ * Perform a soft reset as well to ensure the modem
+ * is in a stable state before sending the additional
+ * reset commands.
+ */
+ return atCmd(conf.softResetCmd, AT_OK, conf.resetDelay)
+ && atCmd(resetCmds, AT_OK, ms);
}
bool
HDLCFrame::getDataWord() const
{
u_int n = getFrameDataLength();
- u_int w = (n > 1) ? (*this)[3] : 0;
- if (n > 2) w = (w<<8)|(*this)[4];
- if (n > 3) w = (w<<8)|(*this)[5];
- if (n > 4) w = (w<<8)|(*this)[6];
+ u_int w = (n >= 1) ? (*this)[3] : 0;
+ if (n >= 2) w = (w<<8)|(*this)[4];
+ if (n >= 3) w = (w<<8)|(*this)[5];
+ if (n >= 4) w = (w<<8)|(*this)[6];
return w;
}
HDLCFrame::getDIS() const
{
u_int n = getFrameDataLength();
- u_int dis = (n > 1) ? (*this)[3] : 0;
- dis <<= 8; if (n > 2) dis |= (*this)[4];
- dis <<= 8; if (n > 3) dis |= (*this)[5];
+ u_int dis = (n >= 1) ? (*this)[3] : 0;
+ dis <<= 8; if (n >= 2) dis |= (*this)[4];
+ dis <<= 8; if (n >= 3) dis |= (*this)[5];
return dis;
}
HDLCFrame::getXINFO() const
{
u_int n = getFrameDataLength();
- u_int xinfo = (n > 4 && ((*this)[5] & 0x1)) ? (*this)[6] : 0;
- xinfo <<= 8; if (n > 5 && (xinfo & 0x100)) xinfo |= (*this)[7];
- xinfo <<= 8; if (n > 6 && (xinfo & 0x100)) xinfo |= (*this)[8];
- xinfo <<= 8; if (n > 7 && (xinfo & 0x100)) xinfo |= (*this)[9];
+ u_int xinfo = (n >= 4 && ((*this)[5] & 0x1)) ? (*this)[6] : 0;
+ xinfo <<= 8; if (n >= 5 && (xinfo & 0x100)) xinfo |= (*this)[7];
+ xinfo <<= 8; if (n >= 6 && (xinfo & 0x100)) xinfo |= (*this)[8];
+ xinfo <<= 8; if (n >= 7 && (xinfo & 0x100)) xinfo |= (*this)[9];
return xinfo;
}