diff --git a/src/tests/kits/net/ppp/headers/KPPPInterface.h b/src/tests/kits/net/ppp/headers/KPPPInterface.h index c9f14e1c8a..7c7b8698b9 100644 --- a/src/tests/kits/net/ppp/headers/KPPPInterface.h +++ b/src/tests/kits/net/ppp/headers/KPPPInterface.h @@ -138,7 +138,10 @@ class PPPInterface { PPPLCP fLCP; PPPReportManager fReportManager; ifnet *fIfnet; + thread_id fUpThread; + uint32 fRetry; + int32 fMaxRetries; ppp_manager_info *fManager; diff --git a/src/tests/kits/net/ppp/headers/KPPPReportDefs.h b/src/tests/kits/net/ppp/headers/KPPPReportDefs.h index 99fc3a944f..50829064ed 100644 --- a/src/tests/kits/net/ppp/headers/KPPPReportDefs.h +++ b/src/tests/kits/net/ppp/headers/KPPPReportDefs.h @@ -24,13 +24,13 @@ enum PPP_REPORT_TYPE { // report codes (type-specific) enum PPP_CONNECTION_REPORT_CODES { - PPP_GOING_UP = 0, - PPP_UP_SUCCESSFUL = 1, - PPP_DOWN_SUCCESSFUL = 2, - PPP_UP_ABORTED = 3, - PPP_UP_FAILED = 4, - PPP_AUTHENTICATION_FAILED = 5, - PPP_CONNECTION_LOST = 6 + PPP_REPORT_GOING_UP = 0, + PPP_REPORT_UP_SUCCESSFUL = 1, + PPP_REPORT_DOWN_SUCCESSFUL = 2, + PPP_REPORT_UP_ABORTED = 3, + PPP_REPORT_DEVICE_UP_FAILED = 4, + PPP_REPORT_AUTHENTICATION_FAILED = 5, + PPP_REPORT_CONNECTION_LOST = 6 }; typedef struct ppp_report_packet { diff --git a/src/tests/kits/net/ppp/src/KPPPInterface.cpp b/src/tests/kits/net/ppp/src/KPPPInterface.cpp index 0b0d739274..e9d22d211d 100644 --- a/src/tests/kits/net/ppp/src/KPPPInterface.cpp +++ b/src/tests/kits/net/ppp/src/KPPPInterface.cpp @@ -26,8 +26,9 @@ PPPInterface::PPPInterface(driver_settings *settings, PPPInterface *parent = NULL) : fSettings(dup_driver_settings(settings)), fStateMachine(*this), fLCP(*this), fReportManager(StateMachine().Locker()), - fIfnet(NULL), fUpThread(-1), fLinkMTU(1500), fAccessing(0), fChildrenCount(0), - fDevice(NULL), fFirstEncapsulator(NULL), fLock(StateMachine().Locker()) + fIfnet(NULL), fUpThread(-1), fRetry(0), fMaxRetries(0), fLinkMTU(1500), + fAccessing(0), fChildrenCount(0), fDevice(NULL), fFirstEncapsulator(NULL), + fLock(StateMachine().Locker()) { if(get_module(PPP_MANAGER_MODULE_NAME, (module_info**) &fManager) != B_OK) fManager = NULL; @@ -46,7 +47,7 @@ PPPInterface::PPPInterface(driver_settings *settings, PPPInterface *parent = NUL const char *value; - value = get_settings_value(PPP_MODE_KEY, fsettings); + value = get_settings_value(PPP_MODE_KEY, fSettings); if(!strcasecmp(value, PPP_SERVER_MODE_VALUE)) fMode = PPP_SERVER_MODE; else @@ -456,29 +457,41 @@ PPPInterface::Up() fReportManager.DisableReports(PPP_CONNECTION_REPORT, me); } - if(report.code == PPP_GOING_UP) { + if(report.code == PPP_REPORT_GOING_UP) { PPP_REPLY(sender, B_OK); continue; - } else if(report.code == PPP_UP_SUCCESSFUL) { + } else if(report.code == PPP_REPORT_UP_SUCCESSFUL) { PPP_REPLY(sender, B_OK); fReportManager.DisableReports(PPP_CONNECTION_REPORT, me); return true; - } else if(report.code == PPP_DOWN_SUCCESSFUL - || report.code == PPP_UP_ABORTED) { + } else if(report.code == PPP_REPORT_DOWN_SUCCESSFUL + || report.code == PPP_REPORT_UP_ABORTED + || report.code == PPP_REPORT_AUTHENTICATION_FAILED) { PPP_REPLY(sender, B_OK); fReportManager.DisableReports(PPP_CONNECTION_REPORT, me); return false; - } else if(report.code == PPP_UP_FAILED) { + } else if(report.code == PPP_REPORT_DEVICE_UP_FAILED) { // TODO: - // if maximum number of retries is reached we return false - // otherwise we wait for the next dial-attempt - } else if(report.code == PPP_AUTHENTICATION_FAILED) { - PPP_REPLY(sender, B_OK); - fReportManager.DisableReports(PPP_CONNECTION_REPORT, me); - return false; - } else if(report.code == PPP_CONNECTION_LOST) { + // !!! check code (after vacation you sometimes forget things ;) !!! + if(fRetry >= fMaxRetries || fUpThread == -1) { + PPP_REPLY(sender, B_OK); + fReportManager.DisableReports(PPP_CONNECTION_REPORT, me); + return false; + } else { + PPP_REPLY(sender, B_OK); + continue; + } + } else if(report.code == PPP_REPORT_CONNECTION_LOST) { // TODO: - // if autoredial is enabled wait for redial attemts (just continue) + // !!! check code (after vacation you sometimes forget things ;) !!! + if(DoesAutoRedial()) { + PPP_REPLY(sender, B_OK); + continue; + } else { + PPP_REPLY(sender, B_OK); + fReportManager.DisableReports(PPP_CONNECTION_REPORT, me); + return false; + } } } } else { diff --git a/src/tests/kits/net/ppp/src/KPPPStateMachine.cpp b/src/tests/kits/net/ppp/src/KPPPStateMachine.cpp index f0319697dd..41128e16ad 100644 --- a/src/tests/kits/net/ppp/src/KPPPStateMachine.cpp +++ b/src/tests/kits/net/ppp/src/KPPPStateMachine.cpp @@ -318,7 +318,8 @@ PPPStateMachine::UpFailedEvent() break; } - Interface()->Report(PPP_CONNECTION_REPORT, PPP_UP_FAILED, NULL, 0); + Interface()->Report(PPP_CONNECTION_REPORT, PPP_REPORT_DEVICE_UP_FAILED, + NULL, 0); if(Interface()->Parent()) Interface()->Parent()->StateMachine().UpFailedEvent(Interface()); @@ -430,10 +431,10 @@ PPPStateMachine::DownEvent() || fAuthenticationStatus == PPP_AUTHENTICATING || fPeerAuthenticationStatus == PPP_AUTHENTICATION_FAILED || fPeerAuthenticationStatus == PPP_AUTHENTICATING) - Interface()->Report(PPP_CONNECTION_REPORT, PPP_AUTHENTICATION_FAILED, + Interface()->Report(PPP_CONNECTION_REPORT, PPP_REPORT_AUTHENTICATION_FAILED, NULL, 0); else - Interface()->Report(PPP_CONNECTION_REPORT, PPP_CONNECTION_LOST, + Interface()->Report(PPP_CONNECTION_REPORT, PPP_REPORT_CONNECTION_LOST, NULL, 0); if(Interface()->Parent()) @@ -443,11 +444,14 @@ PPPStateMachine::DownEvent() if(Interface()->DoesAutoRedial()) { // TODO: - // Redial() + // redial if we have been connected + // problem: if we are reconfiguring we should redial, too +// if(oldState == PPP_OPENED_STATE) +// Interface()->Redial(); } else if(!Interface()->DoesDialOnDemand()) Interface()->Delete(); } else { - Interface()->Report(PPP_CONNECTION_REPORT, PPP_DOWN_SUCCESSFUL, NULL, 0); + Interface()->Report(PPP_CONNECTION_REPORT, PPP_REPORT_DOWN_SUCCESSFUL, NULL, 0); if(!Interface()->DoesDialOnDemand()) Interface()->Delete(); @@ -463,7 +467,7 @@ PPPStateMachine::OpenEvent() switch(State()) { case PPP_INITIAL_STATE: - if(!Interface()->Report(PPP_CONNECTION_REPORT, PPP_GOING_UP, NULL, 0)) + if(!Interface()->Report(PPP_CONNECTION_REPORT, PPP_REPORT_GOING_UP, NULL, 0)) return; if(Interface()->Mode() == PPP_SERVER_MODE) { @@ -1378,7 +1382,7 @@ PPPStateMachine::BringHandlersUp() if(Interface()->Ifnet()) Interface()->Ifnet()->if_flags |= IFF_RUNNING; - Interface()->Report(PPP_CONNECTION_REPORT, PPP_UP_SUCCESSFUL, NULL, 0); + Interface()->Report(PPP_CONNECTION_REPORT, PPP_REPORT_UP_SUCCESSFUL, NULL, 0); } else NewPhase(Phase() + 1); } diff --git a/src/tests/kits/net/ppp/src/KPPPUtils.cpp b/src/tests/kits/net/ppp/src/KPPPUtils.cpp index 2bfef0504a..c295540617 100644 --- a/src/tests/kits/net/ppp/src/KPPPUtils.cpp +++ b/src/tests/kits/net/ppp/src/KPPPUtils.cpp @@ -15,11 +15,12 @@ send_data_with_timeout(thread_id thread, int32 code, void *buffer, for(tries = 0; tries < timeout; tries++) { if(has_data(thread)) snooze(1000); - else - return send_data(thread, code, buffer, buffer_size); } - return B_TIMED_OUT; + if(!has_data(thread)) + return send_data(thread, code, buffer, buffer_size); + else + return B_TIMED_OUT; } @@ -30,14 +31,15 @@ receive_data_with_timeout(thread_id *sender, int32 *code, void *buffer, int32 tries; for(tries = 0; tries < timeout; tries++) { - if(has_data(find_thread(NULL))) { + if(!has_data(find_thread(NULL))) { snooze(1000); continue; } - - *code = receive_data(sender, buffer, buffer_size); - return B_OK; } - return B_TIMED_OUT; + if(has_data(find_thread(NULL))) { + *code = receive_data(sender, buffer, buffer_size); + return B_OK; + } else + return B_TIMED_OUT; }