const CBBSensorEvent& CLogBatteryImpl::get_value() { CALLSTACKITEM_N(_CL("CLogBatteryImpl"), _CL("get_value")); #ifndef __WINS__ # ifndef __S60V2__ RPhoneType::TBatteryInfo info; TInt err=Phone().GetBatteryInfo(info); # else TRequestStatus s; RMobilePhone::TMobilePhoneBatteryInfoV1 info; iPhone.GetBatteryInfo(s, info); User::WaitForRequest(s); TInt err=s.Int(); # endif if (err==KErrNone) { iValue.iLevel=info.iChargeLevel; iValue.iState=info.iStatus; } else { TBuf<100> msg=_L("failed to get battery status: "); msg.AppendNum(err); post_error(msg, err); } #else iValue.iLevel=100; iValue.iState=1; #endif return iEvent; }
TInt Clog_cellidImpl::CheckedRunError(TInt aError) { CALLSTACKITEM_N(_CL("Clog_cellidImpl"), _CL("CheckedRunError")); if (iErrorCount >= 10) return aError; TBuf<40> msg; msg.Format(_L("Clog_cellidImpl::CheckedRunError %d"), aError); post_error(msg, aError, GetTime()); #ifndef __WINS__ Cancel(); # ifdef BASICGSM # ifndef __S60V2__ Phone().NotifyChangeOfCurrentNetwork(iStatus, async_info); # else Phone().NotifyChangeOfCurrentNetworkNS(iStatus, async_info); # endif # endif # ifdef ETEL3RDPARTY Telephony().NotifyChange(iStatus, CTelephony::ECurrentNetworkInfoChange, async_infop); i3rdpartyState=NOTIFYONCHANGE; # endif # ifdef MOBINFO if (iInfoState==GETTING_FIRST_MCC || iInfoState==GETTING_NEW_MCC) { iMobInfo->GetCurrentNetwork(iNetworkInfo, iStatus); } else { iMobInfo->NotifyCellIdChange(async_infop, iStatus); } # endif SetActive(); return KErrNone; #else // __WINS__ return aError; #endif }
void CLogBatteryImpl::DoCancel() { CALLSTACKITEM_N(_CL("CLogBatteryImpl"), _CL("DoCancel")); #ifndef __S60V2__ Phone().BatteryInfoNotificationCancel(); #else iPhone.Close(); if (iStatus.Int()==KRequestPending) { TRequestStatus *s=&iStatus; User::RequestComplete(s, KErrCancel); } #endif }
void Clog_cellidImpl::ConstructL() { CALLSTACKITEM_N(_CL("Clog_cellidImpl"), _CL("ConstructL")); Mlog_base_impl::ConstructL(); CActiveScheduler::Add(this); // add to scheduler iTimeOut=CTimeOut::NewL(*this); #ifndef __WINS__ #ifdef BASICGSM TInt err=Phone().GetCurrentNetworkInfo(async_info); TRequestStatus *s=&iStatus; User::RequestComplete(s, err); #endif #ifdef ETEL3RDPARTY Telephony().GetCurrentNetworkInfo(iStatus, async_infop); i3rdpartyState=GETTING_INFO; #endif #ifdef MOBINFO iMobInfo=CMobileNetworkInfo::NewL(); iInfoState=GETTING_FIRST_MCC; iMobInfo->GetCurrentNetwork(iNetworkInfo, iStatus); //iMobInfo->GetCellId(async_infop, iStatus); #endif SetActive(); #else iOpMap->AddRef(); timer.CreateLocal(); //TTimeIntervalMicroSeconds32 w(5*1000*1000); TTimeIntervalMicroSeconds32 w(1*1000*1000); timer.After(iStatus, w); SetActive(); #endif #ifdef BASICGSM //post_new_value(get_value()); #endif }
void Clog_cellidImpl::DoCancel() { CALLSTACKITEM_N(_CL("Clog_cellidImpl"), _CL("DoCancel")); #ifndef __WINS__ # ifdef BASICGSM # ifndef __S60V2__ Phone().NotifyChangeOfCurrentNetworkCancel(); # else // The Cancel hangs on v2 :-( //Phone().NotifyChangeOfCurrentNetworkCancelNS(); TRequestStatus* s=&iStatus; User::RequestComplete(s, KErrCancel); # endif # endif #ifdef ETEL3RDPARTY if (i3rdpartyState==NOTIFYONCHANGE) Telephony().CancelAsync(CTelephony::ECurrentNetworkInfoChangeCancel); else Telephony().CancelAsync(CTelephony::EGetCurrentNetworkInfoCancel); #endif #ifdef MOBINFO switch(iInfoState) { case GETTING_CELL: iMobInfo->CancelCellIdChangeNotification(); break; case GETTING_FIRST_CELL: iMobInfo->CancelGetCellId(); break; case GETTING_FIRST_MCC: case GETTING_NEW_MCC: iMobInfo->CancelGetCurrentNetwork(); break; }; #endif #else timer.Cancel(); #endif }
void CLogBatteryImpl::ConstructL() { CALLSTACKITEM_N(_CL("CLogBatteryImpl"), _CL("ConstructL")); Mlog_base_impl::ConstructL(); iEvent.iData()=&iValue; iEvent.iData.SetOwnsValue(EFalse); #ifndef __WINS__ CActiveScheduler::Add(this); #ifndef __S60V2__ Phone().BatteryInfoNotification(iStatus, iBatteryInfo); #else RTelServer::TPhoneInfo info; User::LeaveIfError( TelServer().GetPhoneInfo( 0, info ) ); User::LeaveIfError( iPhone.Open( TelServer(), info.iName ) ); iPhone.NotifyBatteryInfoChange(iStatus, iBatteryInfo); #endif #endif SetActive(); }
void CLogBatteryImpl::CheckedRunL() { CALLSTACKITEM_N(_CL("CLogBatteryImpl"), _CL("CheckedRunL")); if (iStatus.Int()==KErrNone) { iValue.iLevel=iBatteryInfo.iChargeLevel; iValue.iState=iBatteryInfo.iStatus; } else { iErrorCount++; if (iErrorCount>5) User::Leave(iStatus.Int()); get_value(); } iEvent.iStamp()=GetTime(); post_new_value(iEvent); #ifndef __S60V2__ Phone().BatteryInfoNotification(iStatus, iBatteryInfo); #else iPhone.NotifyBatteryInfoChange(iStatus, iBatteryInfo); #endif SetActive(); }
void Clog_cellidImpl::CheckedRunL() { CALLSTACKITEM_N(_CL("Clog_cellidImpl"), _CL("CheckedRunL")); #ifdef __WINS__ TTimeIntervalMicroSeconds32 wait_time; #endif if (iStatus!=KErrNone) { TBuf<40> msg; msg.Format(_L("NotifyChangeOfCurrentNetwork %d"), iStatus.Int()); post_error(msg, iStatus.Int(), GetTime()); if (iErrorCount++ >= 10) { User::Leave(-1005); } } else { iErrorCount=0; #ifndef __WINS__ # ifdef BASICGSM if (async_info.iNetworkInfo.iShortName.CompareF(_L("elisa"))==0) { async_info.iNetworkInfo.iShortName=_L("RADIOLINJA"); } iCell.iMCC()=async_info.iNetworkInfo.iId.iMCC; iCell.iMNC()=async_info.iNetworkInfo.iId.iMNC; iCell.iShortName=async_info.iNetworkInfo.iShortName; iCell.iLocationAreaCode()=async_info.iLocationAreaCode; iCell.iCellId()=async_info.iCellId; iCell.iMappedId()=iCellMap->GetId(iCell); # endif # ifdef ETEL3RDPARTY iCell.iMCC.FromStringL(async_info.iCountryCode); iCell.iMNC.FromStringL(async_info.iNetworkId); iCell.iShortName=async_info.iShortName; iCell.iLocationAreaCode()=async_info.iLocationAreaCode; iCell.iCellId()=async_info.iCellId; iCell.iMappedId()=iCellMap->GetId(iCell); # endif # ifdef MOBINFO //TBuf<100> msg=_L("cell mcc "); if (iInfoState==GETTING_FIRST_MCC || iInfoState==GETTING_NEW_MCC) { iCell.iMCC.FromStringL(iNetworkInfo.iNetworkCountryCode); } if (iInfoState==GETTING_FIRST_MCC) { //post_error(msg, KErrGeneral); iInfoState=GETTING_FIRST_CELL; iMobInfo->GetCellId(async_infop, iStatus); SetActive(); return; } /* msg.Append(iNetworkInfo.iNetworkCountryCode); if (iInfoState==GETTING_CELL) { msg.Append(async_infop().iCountryCode); msg.Append(_L(" mnc ")); msg.Append(async_infop().iNetworkIdentity); msg.Append(_L(" lac ")); msg.AppendNum(async_infop().iLocationAreaCode); msg.Append(_L(" cellid ")); msg.AppendNum(async_infop().iCellId); } post_error(msg, KErrGeneral); return; */ iCell.iMNC.FromStringL(async_infop().iNetworkIdentity); iCell.iShortName()=iNetworkInfo.iNetworkShortName; iCell.iLocationAreaCode()=async_infop().iLocationAreaCode; iCell.iCellId()=async_infop().iCellId; iCell.iMappedId()=iCellMap->GetId(iCell); if ( (iInfoState==GETTING_CELL) && (iCell.iMNC() != prev_info.iLocationAreaCode)) { iInfoState=GETTING_NEW_MCC; iMobInfo->GetCellId(async_infop, iStatus); SetActive(); return; } async_infop().iCountryCode=iNetworkInfo.iNetworkCountryCode; iInfoState=GETTING_CELL; # endif if ( iCell.iLocationAreaCode()==0 && iCell.iCellId()==0) { if (!iPostedMissing ) { iTimeOut->WaitMax(MISSING_TIMEOUT); } } else { ResetMissing(); post_new_value(&iCell); } # ifndef MOBINFO prev_info=async_info; # else prev_info=async_infop(); # endif } #ifdef BASICGSM # ifndef __S60V2__ Phone().NotifyChangeOfCurrentNetwork(iStatus, async_info); # else Phone().NotifyChangeOfCurrentNetworkNS(iStatus, async_info); # endif #endif //BASICGSM #ifdef ETEL3RDPARTY Telephony().NotifyChange(iStatus, CTelephony::ECurrentNetworkInfoChange, async_infop); i3rdpartyState=NOTIFYONCHANGE; #endif #ifdef MOBINFO post_error(_L("NotifyCellIdChange"), KErrGeneral); iMobInfo->NotifyCellIdChange(async_infop, iStatus); #endif SetActive(); #else //WINS TTime this_time; TBuf<40> val=bases::test_data[test_data_i][1]; while (! val.Compare(_L("SWITCH"))) { val=bases::test_data[++test_data_i][1]; } TPtrC dtd(bases::test_data[test_data_i][0]); _LIT(KTime, "t"); TBBTime t(KTime); t.FromStringL(dtd); CCellMap::Parse(val, iCell.iCellId(), iCell.iLocationAreaCode(), iCell.iShortName()); iOpMap->NameToMccMnc(iCell.iShortName(), iCell.iMCC(), iCell.iMNC()); ++test_data_i; if (test_data_i == 322) { TInt x=0; } iCell.iMappedId()=iCellMap->GetId(iCell); post_new_value(&iCell, t()); this_time=t(); TTime next_time; { val=bases::test_data[test_data_i][1]; while (! val.Compare(_L("SWITCH"))) { val=bases::test_data[++test_data_i][1]; } TPtrC dtd(bases::test_data[test_data_i][0]); t.FromStringL(dtd); next_time=t(); } TTimeIntervalMicroSeconds w=next_time.MicroSecondsFrom(this_time); TInt64 ms=w.Int64(); //ms/=(60*5); wait_time=I64LOW(ms); }
int main(int argc, char **argv) { Connection con; Message msg1, msg2, msg3; char *OurNetName, *OthersNetName, *ServerNetName; /* Konstruktion eindeutiger Namen für das Netzwerksystem: * OurName, OthersName und ServerName wird der Gruppenname vorangestellt. * So gibt es KEINE Kollisionen zwischen den einzelnen Gruppen! * Dieser Netzname wird nur für den Verbindungsaufbau über das * E.I.S.S.-Network-Playfield benutzt. Die im Rahmen des Protokolls * ausgetauschten Namen sind OutName, OthersName und ServerName! */ OurNetName = MakeNetName2(OurName); OthersNetName = MakeNetName2(OthersName); ServerNetName = MakeNetName2(ServerName); /*************** Verbindungsaufbau zum Server ********************/ /* Die Verbindung zum Server muß einen anderen "Quell"-Namen haben, als * die zu Bob. Daher hängen wir einfach ein _S an! */ if (!(con = ConnectTo(concatstrings(OurNetName, "_S", NULL), ServerNetName))) { fprintf(stderr, "ALICE: Kann keine Verbindung zum Server aufbauen: %s\n", NET_ErrorText()); exit(20); } /****** Paket mit den beiden Namen erzeugen und Abschicken *******/ msg1.typ = Alice_Server; strcpy(msg1.body.Alice_Server.A, OurName); strcpy(msg1.body.Alice_Server.B, OthersName); PutMessage("Server", con, &msg1); /*********** Antwort des Servers lesen ***********/ GetMessage("Server", con, &msg1, Server_Alice); /**************** Verbindung zum Server abbauen *************/ DisConnect(con); /*>>>> <<<<* *>>>> AUFGABE: - Entschlüsseln der Nachricht <<<<* *>>>> - Nachrichtenaustauch mit Bob <<<<* *>>>> - Überprüfen der Bob-Nachricht <<<<* *>>>> - Schlüssel für Telefonieren <<<<* *>>>> <<<<*/ // Entschlüsseln der Nachricht DES_ikey ikey_sa; DES_GenKeys(Key_AS, 0, ikey_sa); DES_data iv; memset(&iv, 0, sizeof(DES_data)); ServerData toDecServerData; memcpy(&toDecServerData, &msg1.body.Server_Alice.Serv_A1, sizeof(ServerData)); DES_OFB(ikey_sa, iv, &toDecServerData, sizeof(ServerData), &msg1.body.Server_Alice.Serv_A1); // Analysierung der Nachricht DES_GenKeys(msg1.body.Server_Alice.Serv_A1.Key_AB, 0, iKey_AB); int TimeStamp = msg1.body.Server_Alice.Serv_A1.TimeStamp; int cur_time = GetCurrentTime(); printf("%d\n",cur_time-TimeStamp); if (cur_time - TimeStamp < 0 || cur_time - TimeStamp > 30000) { //set Time-out 30s fprintf(stderr, "TimeStamp check Error!\n"); exit(20); } // Generierung neuer Nachricht zu Bob mit ServerData_B und AuthData_A msg2.typ = Alice_Bob; memcpy(&msg2.body.Alice_Bob.Serv_B2, &msg1.body.Server_Alice.Serv_B1, sizeof(ServerData)); strcpy(&msg2.body.Alice_Bob.Auth_A2.Name, &msg1.body.Server_Alice.Serv_A1.Receiver); msg2.body.Alice_Bob.Auth_A2.Rand = RandomNumber(); AuthData toEncAuthData; memset(&iv, 0, sizeof(DES_data)); memcpy(&toEncAuthData, &msg2.body.Alice_Bob.Auth_A2, sizeof(AuthData)); DES_OFB(iKey_AB, iv, &toEncAuthData, sizeof(AuthData), &msg2.body.Alice_Bob.Auth_A2); // Schick Bob die Nachricht if (!(con = ConnectTo(OurNetName, OthersNetName))) { fprintf(stderr, "ALICE: Kann keine Verbindung zum %s aufbauen: %s\n", OthersNetName, NET_ErrorText()); exit(20); } PutMessage(OthersName, con, &msg2); // bekommen der Nachricht von Bob, enschlüsseln und überprüfen GetMessage(OthersName, con, &msg3, Bob_Alice); AuthData toDecAuthData; memset(&iv, 0, sizeof(DES_data)); memcpy(&toDecAuthData, &msg3.body.Bob_Alice.Auth_B3, sizeof(AuthData)); DES_OFB(iKey_AB, iv, &toDecAuthData, sizeof(AuthData), &msg3.body.Bob_Alice.Auth_B3); if (strcmp(msg3.body.Bob_Alice.Auth_B3.Name, OthersName) != 0) { fprintf(stderr, "Sender check Error!\n"); exit(20); } if (msg3.body.Bob_Alice.Auth_B3.Rand != SwitchRandNum(toEncAuthData.Rand)) { fprintf(stderr, "Rand check Error!\n"); exit(20); } printf("Keberos-Handshake successful!\n"); /*********************** Phone starten *****************************/ Phone(con, OurName, OthersName, EnCrypt, DeCrypt); DisConnect(con); return 0; }