// Wraps DiscoverDevices() to provide a Python method interface. // Arguments: // - boolean value of whether to perform name lookup // // Returns list of (address, name, (service,major,minor)) tuples detailing the // found devices. static PyObject* LightBlue_DiscoverDevices(PyObject* self, PyObject* args) { bool lookupNames; if (!PyArg_ParseTuple(args, "b", &lookupNames)) return NULL; // run the discovery TDeviceDataList devDataList; TInt err = DiscoverDevices(&devDataList, lookupNames); if (err) return SPyErr_SetFromSymbianOSErr(err); // put the results into a python list TInt i; TDeviceData *devData; TBuf8<6*2+5> addrString; PyObject *addrList = PyList_New(0); // python list to hold results for( i=0; i<devDataList.Count(); i++ ) { devData = devDataList[i]; // convert address to string DevAddressToString(devData->iDeviceAddr, addrString); PyObject *devValues; if (lookupNames) { THostName name = devData->iDeviceName; devValues = Py_BuildValue("(s#u#(iii))", addrString.Ptr(), addrString.Length(), // s# - address name.Ptr(), name.Length(), // u# - name devData->iServiceClass, // i - service class devData->iMajorClass, // i - major class devData->iMinorClass // i - minor class ); } else { devValues = Py_BuildValue("(s#O(iii))", addrString.Ptr(), addrString.Length(), // s# - address Py_None, devData->iServiceClass, // i - service class devData->iMajorClass, // i - major class devData->iMinorClass // i - minor class ); } // add tuple to list PyList_Append(addrList, devValues); } devDataList.ResetAndDestroy(); return addrList; }
TInt CTestIfioctls::TestSiocGIfIndex( ) { TInt ret = KErrNone; struct ifreq ifr; int sockfd; TPtrC String; _LIT( KString, "String" ); TBool res = GetStringFromConfig(ConfigSection(), KString, String ); if(!res) { _LIT(Kerr , "Failed to read interface name from ini file.") ; INFO_PRINTF1(Kerr) ; return KErrGeneral ; } TBuf8<256> asciiBuffer; asciiBuffer.Copy(String); TInt len = asciiBuffer.Length(); Mem::Copy(ifr.ifr_name, asciiBuffer.Ptr(), len); ifr.ifr_name[len] = 0; StripStar(ifr.ifr_name); sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); *(ifr.ifr_name + sizeof(ifr.ifr_name) - 1 ) = '\0'; if (ioctl(sockfd, SIOCGIFINDEX, &ifr) != -1) { ret = KErrIoctl; } close(sockfd); return ret; }
TBool SubConnActivities::CEventNotification::FillInEvent(const CSubConNotificationEvent& aEvent) { TBool sendEvent(iEventUidFilterListLength == 0); for (TUint i = 0; i < iEventUidFilterListLength; ++i) { if (iEventUidFilterList[i].iEventGroupUid == aEvent.GroupId() && iEventUidFilterList[i].iEventMask & aEvent.Id()) { sendEvent = ETrue; break; } } if (sendEvent) { TBuf8<KMaxSubConnectionEventSize> eventBuffer; TPtr8 ptr((TUint8*)eventBuffer.Ptr(),eventBuffer.MaxLength()); if (aEvent.Store(ptr) == KErrNone) { LOG(ESockLog::Printf(_L("ESock: CSubConnection[%x]: Notification Sent. Event Type %d"), this, aEvent.Id())); eventBuffer.SetLength(ptr.Length()); TInt err = iMessage.Write(0, eventBuffer); } } return sendEvent; }
int main() { __UHEAP_MARK; int retval =ESuccess; wchar_t* mywcharstring = L"Hello Widechar String"; int wchar_length= wcslen(mywcharstring); TBuf8 <45> myBuffer; retval = WcharToTbuf8 (mywcharstring, myBuffer); int buf_len = myBuffer.Length(); if (retval ==ESuccess &&\ wchar_length == buf_len/2 &&\ strncmp("Hello Widechar String",(char*)myBuffer.Ptr() , 21) ==0 ) { printf("wchartotbuf8 content check Passed\n"); } else { assert_failed = true; printf("wchartotbuf8 content check Failed\n"); } __UHEAP_MARKEND; testResultXml("test_wchartotbuf8_content_check"); return 0; }
GLDEF_C TInt E32Main() { test.Title(); test.Start(_L("Waiting...")); RUndertaker u; TInt r=u.Create(); test(r==KErrNone); //to avoid RVCT4 warning of unreachable statement. volatile TInt forever = 0; while(forever) { TInt h; TRequestStatus s; r=u.Logon(s,h); test(r==KErrNone); User::WaitForRequest(s); RThread t; t.SetHandle(h); TBuf8<128> b; t.Context(b); TInt *pR=(TInt*)b.Ptr(); TFullName tFullName = t.FullName(); TExitCategoryName tExitCategory = t.ExitCategory(); test.Printf(_L("Thread %S Exit %d %S %d\n"),&tFullName,t.ExitType(),&tExitCategory,t.ExitReason()); test.Printf(_L("r0 =%08x r1 =%08x r2 =%08x r3 =%08x\n"),pR[0],pR[1],pR[2],pR[3]); test.Printf(_L("r4 =%08x r5 =%08x r6 =%08x r7 =%08x\n"),pR[4],pR[5],pR[6],pR[7]); test.Printf(_L("r8 =%08x r9 =%08x r10=%08x r11=%08x\n"),pR[8],pR[9],pR[10],pR[11]); test.Printf(_L("r12=%08x r13=%08x r14=%08x r15=%08x\n"),pR[12],pR[13],pR[14],pR[15]); test.Printf(_L("cps=%08x dac=%08x\n"),pR[16],pR[17]); t.Close(); } return 0; }
OMX_ERRORTYPE CBellagioOpenMaxSymbianLoader::ComponentNameEnum(OMX_STRING cComponentName, OMX_U32 nNameLength, OMX_U32 nIndex) { TInt count = 0; count = componentInfos.Count(); if (count < 1) { return OMX_ErrorComponentNotFound; } if (nIndex > (count - 1)) { return OMX_ErrorNoMore; } TBuf8<257> name; name.FillZ(); name.Zero(); CnvUtfConverter::ConvertFromUnicodeToUtf8(name, (componentInfos[nIndex])->DisplayName()); name.ZeroTerminate(); if (nNameLength < name.Length() - 1) { return OMX_ErrorUndefined; } strcpy((char*)cComponentName, (char*)name.Ptr()); return OMX_ErrorNone; }
void MainWindow::Order() { HBufC8* order = GetOrderInfo(_L8("uninstall king"), _L8("1.00")); if (order == NULL) return; TBuf8<2048> info; HBufC8* sign = NULL; sign = DoMD5(order->Des()); HBufC8* signEncoded = EscapeUtils::EscapeEncodeL(sign->Des(), EscapeUtils::EEscapeUrlEncoded); info.Append(order->Des()); info.Append(_L8("&sign=\"")); info.Append(signEncoded->Des()); info.Append(_L8("\"")); info.Append(_L8("&sign_type=\"MD5\"")); delete sign; delete signEncoded; delete order; QByteArray array(reinterpret_cast<const char*>(info.Ptr()),info.Length()); iAlipayService->AliXPay(array,0); }
bool UPPayHttpConnection::openConnection() { RStringF method = iSession.StringPool().StringF(HTTP::EGET, RHTTPSession::GetTable()); if (!iIsGetMethod) { method = iSession.StringPool().StringF(HTTP::EPOST, RHTTPSession::GetTable()); } #ifdef F_ENCODE_URI iTransaction = iSession.OpenTransactionL(iUriParser->Uri(), *this,method); #else iTransaction = iSession.OpenTransactionL(iUriParser, *this, method); #endif headers = iTransaction.Request().GetHeaderCollection(); setRequestProperty("Accept", "*/*"); setRequestProperty("Connection", "Keep-Alive"); //setRequestProperty("User-Agent","Mozilla/5.0 (SymbianOS/9.1;U;[en];NokiaN73-1/3.0638.0.0.1 Series60/3.0) AppleWebKit/413 (KHTML, like Gecko) Safari/413"); //#endif if (iContentStartPos != 0) { TBuf8<100> range; range.Append(_L8("bytes=")); range.AppendNum(iContentStartPos); range.Append(_L8("-\0\0")); char* temp = new char[range.Length() + 1]; memset(temp, 0, range.Length() + 1); memcpy(temp, range.Ptr(), range.Length()); setRequestProperty("RANGE", (const char *) temp); //CommonUtils::WriteLogL(_L8("RANGE:"), range); delete temp; } return true; }
void Logging::Printf(const TDesC8& /*aSubTag*/, TLogEntryType aType, TRefByValue<const TDesC8> aFmt, VA_LIST& aList) { TBuf8<250> buf; TLogIgnoreOverflow8 overflowHandler; buf.AppendFormatList(aFmt, aList, &overflowHandler); UTracePfAny(KPrimaryFilter, KText, ETrue, EFalse, aType, buf.Ptr(), buf.Size()); }
void CFileLogger::ReadStream(TDes &aDes) { TBuf8<50> buf; TInt pos = 0; User::LeaveIfError(iFile.Seek(ESeekStart, pos)); iFile.Read(buf); aDes.Copy((TUint16* )buf.Ptr(), buf.Size()/2); }
HBufC8* CIkev1Dialog::GetUserNameFromFile() { /*-------------------------------------------------------------------- * * Get user name default value from encrypted cache file * *---------------------------------------------------------------------*/ // // Allocate buffer for file header and encrypted key // HBufC8* UserNameBfr = NULL; RFile UserNameFile; if ( UserNameFile.Open(iFs, USER_NAME_CACHE_FILE, EFileRead) == KErrNone ) { TInt FileSize = 0; UserNameFile.Size(FileSize); if ( (FileSize > 0) && (FileSize < 256) ) { HBufC8* FileData = HBufC8::New(FileSize); if ( FileData ) { // // Read encrypted file data into the allocated buffer. // TPtr8 FileDataPtr(FileData->Des()); if ( UserNameFile.Read(FileDataPtr) == KErrNone ) { // // Build decryption key and decrypt user name data. // Both salt data needed in key generation and IV // value required in decryption are found from // encrypted file header // TUserNameFileHdr* FileHeader = (TUserNameFileHdr*)FileData->Ptr(); if ( FileHeader->iFileId == USER_NAME_FILE_ID ) { TBuf8<16> DecryptionKey; TPtr8 SaltPtr((TUint8*)FileHeader->iSalt, 8, 8); if ( CIkev1Dialog::BuildEncryptionKey(SaltPtr, DecryptionKey) ) { TInt EncrLth = FileSize - sizeof(TUserNameFileHdr); TUint8* UserNameRawPtr = (TUint8*)FileHeader + sizeof(TUserNameFileHdr); TInt err; TRAP(err, EncrLth = SymmetricCipherL(UserNameRawPtr, UserNameRawPtr, EncrLth, FileHeader->iIV, (TUint8*)DecryptionKey.Ptr(), EFalse)); if ( (err == KErrNone) && EncrLth ) { // // Allocate a HBufC8 for decrypted user name // UserNameBfr = HBufC8::New(EncrLth); if ( UserNameBfr ) UserNameBfr->Des().Copy(UserNameRawPtr, EncrLth); } } } } delete FileData; } } } UserNameFile.Close(); return UserNameBfr; }
/* ------------------------------------------------------------------------------- Class: CStifParser Method: ConstructL Description: Symbian OS second phase constructor Symbian OS default constructor can leave. Connecting and opening configuration file if path and file information is given. If path and file information is not given and information is given in buffer then create parser according to the buffer. Parameters: const TDesC& aPath: in: Source path definition const TDesC& aConfig: in: Configuration filename const TDesC& aBuffer: in: Buffer of the parsed information Return Values: None Errors/Exceptions: Leaves if called Connect method fails Leaves if called SetSessionPath method fails Leaves if called Open method fails Leaves if HBufC::NewL operation leaves Status: Proposal ------------------------------------------------------------------------------- */ void CStifParser::ConstructL( const TDesC& aPath, const TDesC& aConfig, const TDesC& aBuffer) { if( aPath == KNullDesC && aConfig == KNullDesC && aBuffer != KNullDesC ) { // Set mode iParsingMode = EBufferParsing; // Construct modifiable heap-based descriptor. iBufferTmp = HBufC::NewL( aBuffer.Length() ); //iBuffer = iBufferTmp->Des(); iBuffer.Set( iBufferTmp->Des() ); // Copy content iBuffer.Copy( aBuffer ); } else { User::LeaveIfError( iFileServer.Connect() ); __TRACE( KInfo, ( _L( "STIFPARSER: Open configfile '%S%S'" ), &aPath, &aConfig ) ); User::LeaveIfError( iFileServer.SetSessionPath( aPath ) ); User::LeaveIfError( iFile.Open( iFileServer, aConfig, EFileRead | EFileShareAny ) ); //Check whether the file is unicoded __TRACE(KInfo, (_L("STIFPARSER: Check if the file is unicode"))); _LIT(KUnicode, "#UNICODE"); const TInt KUnicodeLength(8 * 2 + 2); //times two, because we want to read unicode string using 8bit descriptor //two characters more because on some systems FEFF is always added on the beginning of unicode file TInt size(0); User::LeaveIfError(iFile.Size(size)); if(size >= KUnicodeLength) { TBuf8<KUnicodeLength> buf; User::LeaveIfError(iFile.Read(0, buf)); TPtrC16 bufuni((TUint16 *)(buf.Ptr()), buf.Length() / 2); if(bufuni.Find(KUnicode) != KErrNotFound) { iIsUnicode = ETrue; __TRACE(KInfo, (_L("STIFPARSER: File is unicode"))); } } //Create file parser object iFileParser = CStifFileParser::NewL(iFileServer, iFile, iIsUnicode, iCommentType); } iOffset = 0; }
OMX_ERRORTYPE CBellagioOpenMaxSymbianLoader::GetComponentsOfRole(OMX_STRING role, OMX_U32 *pNumComps, OMX_U8 **compNames) { TInt index = 0; TInt count = 0; TInt length = 0; TInt roles = 0; TInt nameIndex = 0; count = componentInfos.Count(); if (count < 1) { return OMX_ErrorComponentNotFound; } /* Turn the role into Symbian descriptor */ length = strlen(role); TPtrC8 role8(reinterpret_cast<const TUint8 *>(role), length); /* Search all the components for the roles count */ for (index = 0; index < count; index++) { if (role8.Compare((componentInfos[index])->DataType()) == 0) { roles++; } } *pNumComps = roles; // check if client is asking only for the number of components if (compNames == NULL) { return OMX_ErrorNone; } TBuf8<257> component; TBufC8<1> endOfString((TText8*)"\0"); /* Search all the components for the component names */ for (index = 0; index < count; index++) { if (role8.Compare((componentInfos[index])->DataType()) == 0) { CnvUtfConverter::ConvertFromUnicodeToUtf8(component, (componentInfos[index])->DisplayName()); component.Append(endOfString); strcpy((char*)compNames[nameIndex], (char*)component.Ptr()); nameIndex++; } } return OMX_ErrorNone; }
/*********************************************************** * Name: os_assert_failure * * Arguments: const char *msg - message for log (normally condition text) * const char *file - filename of translation unit * const char *func - name of function (NULL if not available) * int line - line number */ void os_assert_failure(const char *msg, const char *file, const char *func, int line) { TBuf8<256> printBuf; if (func) my_sprintf(printBuf, "VC: Assertion failed: %s, function %s, file %s, line %d", msg, func, file, line); else my_sprintf(printBuf, "VC: Assertion failed: %s, file %s, line %d", msg, file, line); Kern::Fault(reinterpret_cast<const char *>(printBuf.Ptr()), KErrGeneral); }
int Syscall::maIapSave() { if(gNetworkingState != EStarted) return 0; WriteFileStream writeFile(CCP gIapPath8.PtrZ()); DEBUG_ASSERT(writeFile.isOpen()); TBuf8<32> buf; buf.Format(_L8("%i\n"), gIapId); DEBUG_ASSERT(writeFile.write(buf.Ptr(), buf.Size())); return 1; }
// Util function TInt GetIfrName(char* ifrname, int size) { char* tInfr = 0; TBuf8<KMaxName> ifbuf; GetIpFromDHCPServer(); TAutoClose<RSocketServ> ss; ss.iObj.Connect(); TAutoClose<RSocket> sock; sock.iObj.Open(ss.iObj, _L("udp")); sock.iObj.SetOpt(KSoInetEnumInterfaces, KSolInetIfCtrl); TProtocolDesc in; sock.iObj.Info(in); TPckgBuf<TSoInetInterfaceInfo> info, next; TInt res=sock.iObj.GetOpt(KSoInetNextInterface, KSolInetIfCtrl, info); if(res!=KErrNone) return KErrGeneral; while(res==KErrNone) { res=sock.iObj.GetOpt(KSoInetNextInterface, KSolInetIfCtrl, next); if(info().iState != EIfUp || info().iFeatures&KIfIsLoopback || info().iName.Left(4) == _L("eth6")) { info = next; continue; } ifbuf.Copy(info().iName); tInfr = (char*) ifbuf.Ptr(); if( tInfr && (size > info().iName.Length()) ) { tInfr[info().iName.Length()] = '\0'; strcpy(ifrname, tInfr); } TName address; info().iAddress.Output(address); info().iNetMask.Output(address); if(res==KErrNone) { info = next; } } return KErrNone; }
// todo: improve efficiency by using native file api instead of FileStream. bool Syscall::getSavedIap(TUint& iap) { FileStream readFile(CCP gIapPath8.PtrZ()); if(!readFile.isOpen()) return false; TBuf8<32> buf; int len; DEBUG_ASSERT(readFile.length(len)); buf.SetLength(len); DEBUG_ASSERT(readFile.read((void*)buf.Ptr(), len)); TLex8 lex(buf); DEBUG_ASSERT(!lex.Val(iap)); return true; }
void TestProtection() { test.Next(_L("Test protection")); TBool jit=User::JustInTime(); User::SetJustInTime(EFalse); TUint x=0xffffffff; TBuf8<64> ubuf; TPtrC8 uptrc(ubuf.Ptr(),11); TPtr8 uptr((TUint8*)ubuf.Ptr(),1,20); TPtrC8 kptrc(Kern,1); TPtr8 kptr(Kern,10,256); TPtrC8 gptrc(Garbage,1); TPtr8 gptr(Garbage,10,256); RunTestInThread(GlobalReadThread,&x,&KLitKernExec,EKUDesInfoInvalidType); RunTestInThread(GlobalReadThread,&ubuf,NULL,KErrNone); RunTestInThread(GlobalReadThread,&uptr,NULL,KErrNone); RunTestInThread(GlobalReadThread,&uptrc,&KLitKernExec,EKUDesInfoInvalidType); RunTestInThread(GlobalReadThread,&kptrc,&KLitKernExec,EKUDesInfoInvalidType); RunTestInThread(GlobalReadThread,&gptrc,&KLitKernExec,EKUDesInfoInvalidType); RunTestInThread(GlobalReadThread,&gptr,&KLitKernExec,ECausedException); if (KernProt) { RunTestInThread(GlobalReadThread,Kern,&KLitKernExec,ECausedException); RunTestInThread(GlobalReadThread,&kptr,&KLitKernExec,ECausedException); } RunTestInThread(GlobalWriteThread,&x,&KLitKernExec,EKUDesInfoInvalidType); RunTestInThread(GlobalWriteThread,&ubuf,NULL,KErrNone); RunTestInThread(GlobalWriteThread,&uptr,NULL,KErrNone); RunTestInThread(GlobalWriteThread,&uptrc,NULL,KErrNone); RunTestInThread(GlobalWriteThread,&gptrc,&KLitKernExec,ECausedException); RunTestInThread(GlobalWriteThread,&gptr,&KLitKernExec,ECausedException); if (KernProt) { RunTestInThread(GlobalWriteThread,Kern,&KLitKernExec,ECausedException); RunTestInThread(GlobalWriteThread,&kptrc,&KLitKernExec,ECausedException); RunTestInThread(GlobalWriteThread,&kptr,&KLitKernExec,ECausedException); } User::SetJustInTime(jit); }
bool QMessageContentContainerPrivate::createAttachment(const QString& attachmentPath) { //set the attachment data if (!QFile::exists(attachmentPath)) { return false; } QFile attachmentFile(attachmentPath); if (!attachmentFile.open(QIODevice::ReadOnly)) { return false; } _content = attachmentFile.readAll(); _available = true; _size = attachmentFile.size(); attachmentFile.close(); QFileInfo fi(attachmentPath); _name = fi.fileName().toLatin1(); //set the mime-type QByteArray mimeType; QString type; TBuf8<255> fileBuffer; RApaLsSession session; QString fileString = fi.fileName(); TPtrC16 filePtr(reinterpret_cast<const TUint16*>(fileString.utf16())); TBuf8<20> fileType; TPtrC8 ptr8((TUint8 *)(_content.constData()), _content.length()); if(session.Connect() == KErrNone){ TDataRecognitionResult fileDataType; session.RecognizeData(filePtr, ptr8, fileDataType); fileType.Copy(fileDataType.iDataType.Des8()); mimeType = QByteArray((const char*)fileType.Ptr(), fileType.Length()); session.Close(); } QString extension(fi.suffix()); int index = mimeType.indexOf("/"); if (index != -1) { _type = mimeType.left(index).trimmed(); _subType = mimeType.mid(index + 1).trimmed(); } // set the whole filepath to _filename _filename = fi.filePath().toLatin1(); return true; }
TInt CTestWideApi::wfreopen_valinv() { TPtrC nameRead; _LIT( KString, "Parameter1" ); TBool res = GetStringFromConfig(ConfigSection(), KString, nameRead); if(!res) { _LIT(Kerr , "Failed to read string") ; INFO_PRINTF1(Kerr) ; return KErrGeneral ; } int ret_wmkdir = wmkdir(L"C:\\ggg" , S_IWUSR); if((errno == EEXIST) || (!ret_wmkdir)) { TBuf8<100> buf; buf.Copy(nameRead); char* filename = (char*) buf.Ptr(); filename[buf.Length()]='\0'; wchar_t *pathName = (wchar_t *)malloc(30*sizeof(wchar_t)); if(pathName==NULL) { wrmdir(L"C:\\ggg"); return KErrNoMemory; } size_t siz = mbstowcs(pathName, filename, 30); wunlink(pathName) ; FILE *fp = wfreopen(pathName ,L"w",stdout); if(fp == NULL) { _LIT(Kropen , " Failed to reopen file " ) ; INFO_PRINTF1(Kropen) ; wrmdir(L"C:\\ggg"); free(pathName); return KErrNone; } else { wrmdir(L"C:\\ggg"); free(pathName); return KErrGeneral; } } else { _LIT(Kerr , "Failed to make dir") ; INFO_PRINTF1(Kerr) ; return KErrGeneral ; } }
void CConsoleBase::Printf(const TDesC &str, ...) { va_list args; va_start(args, str); TBuf8<200> nstr; nstr.Copy(str); char *p = (char *)nstr.Ptr(); p[nstr.Length()] = '\0'; vprintf(p, args); va_end(args); }
// Wraps GetLocalAddress() to provide a Python method interface. // Takes no arguments. // // Returns local device address as Python string. static PyObject* LightBlue_GetLocalAddress(PyObject* self, PyObject* args) { TBTDevAddr addr; TBuf8<6*2+5> addrString; if (!PyArg_ParseTuple(args, "")) return NULL; TInt err = GetLocalAddress(addr); if (err) return SPyErr_SetFromSymbianOSErr(err); DevAddressToString(addr, addrString); return Py_BuildValue("s#", addrString.Ptr(), addrString.Length()); }
void DPropertyAccess::DoPropertyChanged(TNotifyRequest& aRequest, TInt aReason) { // First, rerequest if (aReason == KErrNone) { aRequest.iProperty.Subscribe(aRequest.iRequest); } // Then try and notify if (iNotifyClientStatus && !aRequest.iBtrace) { TPropNotifyResult result; result.iCategory = aRequest.iCat.iUid; result.iKey = aRequest.iKey; result.iMissedChanges = iMissedChanges; result.iError = aReason; iMissedChanges = 0; // No need to lock/safeswap because we run in the context of the pubsub DFC TInt err = Kern::ThreadRawWrite(iClient, iClientNotifyPtr, &result, sizeof(TPropNotifyResult)); Kern::RequestComplete(iClient, iNotifyClientStatus, err); } else if (aRequest.iBtrace) { #ifdef FSHELL_TRACE_SUPPORT TUint cat = aRequest.iCat.iUid; TUint key = aRequest.iKey; TInt intVal; TInt err = aRequest.iProperty.Get(intVal); if (err == KErrNone) { BTrace12(ExtraBTrace::EPubSub, ExtraBTrace::EPubSubIntPropertyChanged, cat, key, intVal); } else if (err == KErrArgument) { TBuf8<KMaxBTraceDataArray> buf; // No point using larger buffer, as this is the max we can output over btrace (80 bytes) err = aRequest.iProperty.Get(buf); if (err == KErrNone || err == KErrOverflow) { BTraceN(ExtraBTrace::EPubSub, ExtraBTrace::EPubSubDataPropertyChanged, cat, key, buf.Ptr(), buf.Length()); } } #endif } else { iMissedChanges++; } }
TInt CTestIfioctls::ChooseInterface() { ifreq ifr; TInt sockfd; TInt ret = KErrNone; // Name of the interface TPtrC String; _LIT( KString, "String" ); TBool res = GetStringFromConfig(ConfigSection(), KString, String ); if(!res) { _LIT(Kerr , "Failed to read interface name") ; INFO_PRINTF1(Kerr) ; return KErrGeneral ; } TBuf8<256> asciiBuffer; asciiBuffer.Copy(String); TInt len = asciiBuffer.Length(); Mem::Copy(ifr.ifr_name, asciiBuffer.Ptr(), len); ifr.ifr_name[len] = 0; StripStar(ifr.ifr_name); sockfd = socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP); if (sockfd < 0) { ret = KErrSocket; close(sockfd); return ret; } ret = ioctl(sockfd,SIOCSIFNAME, &ifr); if (ret != KErrNone) { ret = KErrIoctl; close(sockfd); return ret; } ret = ioctl(sockfd, SIOCIFSTART , &ifr); if (ret != KErrNone) { close(sockfd); return ret; } ret = ioctl(sockfd, SIOCIFSTOP, &ifr); return ret; }
/** * Wrapper method around the flash erase block fundtion to determine if the erase was succesful. * If the erase was not succesful we can't continue as we cannot write. * @param aBlockOffset Block to erase * @return One of the OS wide codes */ TInt SCMonitor::EraseFlashBlock(const SCMCrashBlockEntry& aBlock) { iFlash->StartTransaction(); TInt numAttempts = 0; while(numAttempts < KFlashEraseAttempts) { iFlash->SetWritePos(aBlock.iBlockOffset); iFlash->EraseFlashBlock(aBlock.iBlockOffset); //we will read the flash to make sure that it set the block to all 1's (well not all, just the start) TBuf8<sizeof(TUint32)> buf; buf.SetLength(sizeof(TUint32)); iFlash->SetReadPos(aBlock.iBlockOffset); iFlash->Read(buf); volatile TUint32* result = (TUint32*)buf.Ptr(); if(*result == 0xFFFFFFFF) { __KTRACE_OPT(KALWAYS, Kern::Printf("Erase of block [0x%X] succesful after [%d] attempts", aBlock.iBlockOffset, numAttempts+1)) iFlash->EndTransaction(); return KErrNone; } numAttempts++; //Sometimes a write to the block helps the next erase TUint32 bytesWritten = 0; while(bytesWritten < aBlock.iBlockSize) { TBuf8<sizeof(TUint8)> num; num.Append(0x0); iFlash->Write(num); bytesWritten++; } } __KTRACE_OPT(KALWAYS, Kern::Printf("After %d attempts, we were unable to erase the flash block at [0x%X]. This could be because " "the driver is defective or because the flash has gone past its lifetime. Whatever it is though, " "we cannot continue.", KFlashEraseAttempts, aBlock.iBlockOffset)); iFlash->EndTransaction(); return KErrAbort; }
void CTe_rtpSuite::ConfigureReflectorModeL(TBool aMode, TInetAddr& aAddr) { /* Configures the reflector to change the SSRC or not */ RSocketServ sockServer; //Open a connection RConnection conn; User::LeaveIfError(sockServer.Connect()); CleanupClosePushL(sockServer); User::LeaveIfError(conn.Open(sockServer)); CleanupClosePushL(conn); //Start the connection User::LeaveIfError(conn.Start()); RSocket ctrlSock; User::LeaveIfError(ctrlSock.Open(sockServer,KAfInet, KSockDatagram, KProtocolInetUdp, conn)); CleanupClosePushL(ctrlSock); TBuf8<64> lCmdBuff; TUint8* lPtr = const_cast<TUint8*>(lCmdBuff.Ptr()); TUint32* lIntData = (TUint32*)lPtr; *lIntData = ByteOrder::Swap32(0xFF00BABE); if (aMode) { *(lIntData + 1) = ByteOrder::Swap32(0xCD000100); } else { *(lIntData + 1) = ByteOrder::Swap32(0xCD000101); } lCmdBuff.SetLength(64); TRequestStatus lMyReqStat; ctrlSock.SendTo(lCmdBuff,aAddr,0,lMyReqStat); User::WaitForRequest(lMyReqStat); ctrlSock.Close(); conn.Close(); sockServer.Close(); CleanupStack::Pop(3); }
TInt TMetaVarLenBase::CheckBuf( TPtrC8& aBuffer ) { // Check if the descriptor is long enough if (aBuffer.Length() < (TInt)sizeof(TUint32)) { return KErrArgument; } // Check if the descriptor is long enough TBuf8<sizeof(TUint32)> lenSubBuf; lenSubBuf.Copy(aBuffer.Ptr(), sizeof(TUint32)); TUint length = *((TUint32*)lenSubBuf.Ptr()); if (aBuffer.Length() < (TInt)length) { return KErrArgument; } aBuffer.Set(aBuffer.Ptr() + sizeof(TUint32), aBuffer.Length() - sizeof(TUint32)); //update pointer return length; }
//Util function void CTestIfioctls::ReadStringParam(char* aString) { _LIT( KSl, "Param%d" ); TBuf<8> pNameBuf; TPtrC string; pNameBuf.Format(KSl,++iParamCount); TBool res = GetStringFromConfig(ConfigSection(), pNameBuf, string); if(!res) { _LIT(Kerr , "Unable to retrieve string parameter") ; INFO_PRINTF1(Kerr); } TBuf8<256> bufstring; bufstring.Copy(string); TInt paramLength=string.Length(); char* text=(char *)(bufstring.Ptr()); *(text+paramLength)='\0'; strcpy(aString,text); return; }
// Wraps SelectDeviceUI() to provide a Python method interface. // Takes no arguments. // // Returns None if user cancelled, otherwise returns a // (name, address, (service,major,minor)) Python tuple. static PyObject* LightBlue_SelectDevice(PyObject* self, PyObject* args) { if (!PyArg_ParseTuple(args, "")) return NULL; TBTDeviceResponseParamsPckg response; TInt err = SelectDeviceUI(response); if (err) { if (err == KErrCancel) { // user cancelled Py_INCREF(Py_None); return Py_None; } else { // some other error occured return SPyErr_SetFromSymbianOSErr(err); } } if (!(response().IsValidDeviceName())) { PyErr_SetString(PyExc_SymbianError, "discovery returned invalid data"); return NULL; } // get device address TBuf8<6*2+5> addrString; TBTDevAddr addr = response().BDAddr(); DevAddressToString(addr, addrString); // get device class details TBTDeviceClass deviceClass = response().DeviceClass(); TUint16 service = deviceClass.MajorServiceClass(); TUint8 major = deviceClass.MajorDeviceClass(); TUint8 minor = deviceClass.MinorDeviceClass(); return Py_BuildValue("s#u#(iii)", addrString.Ptr(), addrString.Length(), response().DeviceName().Ptr(), response().DeviceName().Length(), service, major, minor); }
TBool CSuspendTest::ValidateBlock( TInt aBlockNumber, TUint32 aFillWord ) // // Checks that every word in block aBlockNumber has the value aFillWord // { TUint offset = aBlockNumber * iBlockSize; test.Printf( _L("Validating block %d (offs=0x%x)\n"), aBlockNumber, offset ); TBool failed = EFalse; const TInt readBufLen = iReadBuffer.MaxLength(); for( TInt len = iBlockSize; len > 0 && !failed ;) { TInt r = iDrive.Read( offset, readBufLen, iReadBuffer ); if( r != KErrNone ) { test.Printf( _L("... FAIL: read failed (%d) at offset 0x%x\n"), r, offset ); test( KErrNone == r ); } test( iReadBuffer.Length() == readBufLen ); TUint32* p = (TUint32*)iReadBuffer.Ptr(); for( TInt i = 0; i < readBufLen; i += 4 ) { if( aFillWord != *p ) { failed = ETrue; test.Printf( _L("... FAILED: word @ offs=0x%x, read=0x%x, expected=0x%x\n"), offset+i, p[0], aFillWord ); break; } ++p; } offset += readBufLen; len -= readBufLen; } return !failed; }