TVerdict CSmsCapsWapSetLocalName::doTestStepL() { RSocket wapsock; TInt ret=wapsock.Open(iSocketServer,KWAPSMSAddrFamily,KSockDatagram,KWAPSMSDatagramProtocol); User::LeaveIfError(ret); CleanupClosePushL(wapsock); TWapAddr wapAddr; wapAddr.SetWapPort(TWapPortNumber(9204)); ret=wapsock.Bind(wapAddr); if(RProcess().HasCapability(ECapabilityNetworkServices)) { TEST(ret != KErrPermissionDenied); } else { TEST(ret == KErrPermissionDenied); } CleanupStack::PopAndDestroy(&wapsock); return TestStepResult() ; }
/** Create a UDP Socket and bind it to an arbitrary address @param aSocket The socket @param aAddress On return, contains the local socket name @return ETrue on success, EFalse otherwise */ TBool CEsockTest9_6::CreateUdpSocket( RSocket& aSocket, TSockAddr& aAddress ) { // Open the socket TInt nRet = aSocket.Open( iEsockSuite->iSocketServer, KAfInet, KSockDatagram, KProtocolInetUdp ); if( KErrNone != nRet ) { Logger().WriteFormat(_L("Failed to open socket: return value = <%d>"), nRet ); return EFalse; } // Bind to any address. //TInetAddr myAddress( KInetAddrAny, KInetPortAny ); TInetAddr myAddress( KInetAddrLoop, KInetPortAny ); nRet = aSocket.Bind( myAddress ); if( KErrNone != nRet ) { Logger().WriteFormat(_L("Failed to bind socket: return value = <%d>"), nRet ); return EFalse; } // Retrieve the bound address aSocket.LocalName( aAddress ); // Happy shiny return ETrue; }
TVerdict CSmsCapsSmsSetLocalName::doTestStepL() { RSocket socket; TInt ret=socket.Open(iSocketServer,KSMSAddrFamily,KSockDatagram,KSMSDatagramProtocol); if(ret!=KErrNone) User::Leave(ret); CleanupClosePushL(socket); TSmsAddr smsaddr; smsaddr.SetSmsAddrFamily(ESmsAddrRecvAny); ret=socket.Bind(smsaddr); if(RProcess().HasCapability(ECapabilityNetworkServices)) { TEST(ret != KErrPermissionDenied); } else { TEST(ret == KErrPermissionDenied); } CleanupStack::PopAndDestroy(&socket); return TestStepResult() ; }
void CGetPortCommand::DoExecuteL() { TInt errorCode = KErrNone; RSocketServ socketServer; errorCode = socketServer.Connect(); if(errorCode == KErrNone) { RSocket listeningSocket; TSockAddr localAddress; //TODO: add retrying to find ports for(int i = 0; errorCode == KErrNone && i < iFreePortsNum; i++) { TInt port = iDriver->NextRandomPort(); listeningSocket.Open(socketServer, KAfInet, KSockStream, KProtocolInetTcp); localAddress.SetPort(port); errorCode = listeningSocket.Bind(localAddress); if(errorCode == KErrNone) { iFreePorts.Append(port); } listeningSocket.Close(); } } socketServer.Close(); User::LeaveIfError(errorCode); }
TVerdict CRtpNegTests_02::doTestStepL() /** * @return - TVerdict code */ { SetTestStepResult(EFail); TInt err; TRequestStatus stat; if(KErrNone == InitSubConL()) { RSocket sock; err = sock.Open(iSocketServ, KAfInet, KSockStream, KProtocolInetTcp, iSubCon); if(KErrNone == err) { iIpAddrLocal.SetPort(iLocalPort1); sock.Bind(iIpAddrLocal); iIpAddrDest1.SetPort(iDestPort1); sock.Connect(iIpAddrDest1,stat); User::WaitForRequest(stat); if(KErrNone != stat.Int()) { SetTestStepResult(EPass); } sock.Close(); } } return TestStepResult(); }
TBool CSmsReplyToStep::WatchersAlreadyRunningL() { RSocketServ server; RSocket socket; User::LeaveIfError(server.Connect()); CleanupClosePushL(server); // test if it's there... TProtocolDesc protoInfo; TProtocolName protocolname; protocolname.Copy(KSmsDatagram); User::LeaveIfError(server.FindProtocol(protocolname,protoInfo)); User::LeaveIfError(socket.Open(server, protoInfo.iAddrFamily, protoInfo.iSockType, protoInfo.iProtocol)); CleanupClosePushL(socket); TSmsAddr addr; addr.SetSmsAddrFamily(ESmsAddrRecvAny); TInt err = socket.Bind(addr); CleanupStack::Pop(2, &server); socket.CancelAll(); socket.Close(); server.Close(); return (err == KErrAlreadyExists); }
int CTcpSock::Bind(TInetAddr &ia) { TInt ret; ret = iSocket.Open(ts->cts->iSockServer->iSocketServer, ia.Family(), KSockStream, KProtocolInetTcp); if (KErrNone != ret) { DEBUG_WARNING("bind: Open (ret=%d)\n", ret); goto error; } ret = iSocket.SetOpt(KSoReuseAddr, KSolInetIp, 1); if (KErrNone != ret) { DEBUG_WARNING("SetOpt ReuseAddr: ret=%d\n", ret); } ret = iSocket.Bind(ia); if (KErrNone != ret) { DEBUG_WARNING("bind: Bind (ret=%d)\n", ret); goto error; } error: return kerr2errno(ret); }
TBool TestFrameworkActionsUtils::CheckIfSmsWatcherAlreadyRunningL() { RSocketServ socketServer; RSocket socket; User::LeaveIfError(socketServer.Connect()); CleanupClosePushL(socketServer); TProtocolDesc protoInfo; TProtocolName protocolname; protocolname.Copy(KSmsDatagram); User::LeaveIfError(socketServer.FindProtocol(protocolname,protoInfo)); User::LeaveIfError(socket.Open(socketServer, protoInfo.iAddrFamily, protoInfo.iSockType, protoInfo.iProtocol)); CleanupClosePushL(socket); TSmsAddr addr; addr.SetSmsAddrFamily(ESmsAddrRecvAny); TInt err = socket.Bind(addr); socket.CancelAll(); CleanupStack::PopAndDestroy(2); //socketServer, socket return (err == KErrAlreadyExists); }
/** * Get the local IP address of the device * * @note Requires at least one IP packet sent in advance! */ int net_if_getaddr4(const char *ifname, int af, struct sa *ip) { (void)ifname; if (AF_INET != af) return EAFNOSUPPORT; /* Already cached? */ if (sa_isset(&local_ip, SA_ADDR)) { sa_cpy(ip, &local_ip); return 0; } RSocketServ ss; RSocket s; TInt ret; ret = ss.Connect(); if (KErrNone != ret) { DEBUG_WARNING("connecting to socket server fail (ret=%d)\n", ret); return ECONNREFUSED; } ret = s.Open(ss, KAfInet, KSockDatagram, KProtocolInetUdp); if (KErrNone != ret) { DEBUG_WARNING("open socket failed (ret=%d)\n", ret); return ECONNREFUSED; } TInetAddr bind; bind.SetPort(0); bind.SetAddress(KInetAddrAny); ret = s.Bind(bind); if (KErrNone != ret) { DEBUG_WARNING("bind socket failed (ret=%d)\n", ret); return ECONNREFUSED; } TInetAddr local; s.LocalName(local); s.Close(); ss.Close(); sa_set_in(&local_ip, local.Address(), local.Port()); DEBUG_NOTICE("local IP addr: %j\n", &local_ip); if (!sa_isset(&local_ip, SA_ADDR)) return EINVAL; sa_cpy(ip, &local_ip); return 0; }
int CTcpConn::Bind(TInetAddr &ia) { TInt ret; ret = iSocket.SetOpt(KSoReuseAddr, KSolInetIp, 1); if (KErrNone != ret) { DEBUG_WARNING("SetOpt ReuseAddr: ret=%d\n", ret); } return kerr2errno(iSocket.Bind(ia)); }
TVerdict CSmsCapsSmsIoctlDeleteSms::doTestStepL() { RSocket socket; TRequestStatus status; TInt ret=socket.Open(iSocketServer,KSMSAddrFamily,KSockDatagram,KSMSDatagramProtocol); if(ret!=KErrNone) User::Leave(ret); CleanupClosePushL(socket); TSmsAddr smsaddr; smsaddr.SetSmsAddrFamily(ESmsAddrRecvAny); ret=socket.Bind(smsaddr); if(RProcess().HasCapability(ECapabilityWriteUserData, ECapabilityNetworkServices) && RProcess().HasCapability(ECapabilityReadUserData)) { TESTL(ret != KErrPermissionDenied); } else { // skip this one CleanupStack::PopAndDestroy(&socket); return TestStepResult() ; } // Create message with SRR _LIT(KText,"This is a simple SMS!"); CSmsMessage* msg=CreateSmsMessageL(KText,TSmsDataCodingScheme::ESmsAlphabet7Bit); CleanupStack::PushL(msg); RSmsSocketWriteStream writestream(socket); writestream << *msg; writestream.CommitL(); CleanupStack::PopAndDestroy(msg); socket.Ioctl(KIoctlDeleteSmsMessage, status, NULL, KSolSmsProv); User::WaitForRequest(status); if(RProcess().HasCapability(ECapabilityWriteUserData)) { TEST(status.Int() != KErrPermissionDenied); } else { TEST(status.Int() == KErrPermissionDenied); } CleanupStack::PopAndDestroy(&socket); return TestStepResult(); }
TVerdict CSmsCapsSmsIoctlReadParamsSms::doTestStepL() { TInt testNo=13; RProperty testNumberProperty; User::LeaveIfError(testNumberProperty.Attach(KUidPSSimTsyCategory, KPSSimTsyTestNumber)); CleanupClosePushL(testNumberProperty); TRequestStatus status; testNumberProperty.Subscribe(status); User::LeaveIfError(testNumberProperty.Set(KUidPSSimTsyCategory,KPSSimTsyTestNumber,testNo)); User::WaitForRequest(status); TEST(status.Int() == KErrNone); TInt testNumberCheck; User::LeaveIfError(testNumberProperty.Get(testNumberCheck)); if (testNo != testNumberCheck) User::Leave(KErrNotFound); CleanupStack::PopAndDestroy(&testNumberProperty); RSocket socket; TInt ret=socket.Open(iSocketServer,KSMSAddrFamily,KSockDatagram,KSMSDatagramProtocol); if(ret!=KErrNone) User::Leave(ret); CleanupClosePushL(socket); TSmsAddr smsaddr; smsaddr.SetSmsAddrFamily(ESmsAddrLocalOperation); ret=socket.Bind(smsaddr); if(RProcess().HasCapability(ECapabilityNetworkServices)) { TESTL(ret != KErrPermissionDenied); } else { // skip this one CleanupStack::PopAndDestroy(&socket); return TestStepResult() ; } socket.Ioctl(KIoctlReadSmsParams,status,NULL,KSolSmsProv); User::WaitForRequest(status); TEST(status.Int() != KErrPermissionDenied); CleanupStack::PopAndDestroy(&socket); return TestStepResult() ; }
int ILibSocketWrapper_bind(int socketObject, struct sockaddr *local) { TInetAddr addr = TInetAddr(htonl(((struct in_addr*)local->sa_data)->s_addr),ntohs(local->sa_port)); RSocket *s = (RSocket*)SocketArray[socketObject]; if(s->Bind(addr)==KErrNone) { return(0); } else { return(-1); } }
TVerdict CSmsCapsSmsIoctlEnumerateSms::doTestStepL() { RSocket socket; TRequestStatus status; TInt ret=socket.Open(iSocketServer,KSMSAddrFamily,KSockDatagram,KSMSDatagramProtocol); CleanupClosePushL(socket); if(ret!=KErrNone) User::Leave(ret); TSmsAddr smsaddr; smsaddr.SetSmsAddrFamily(ESmsAddrRecvAny); ret=socket.Bind(smsaddr); if(RProcess().HasCapability(ECapabilityWriteUserData, ECapabilityNetworkServices) && RProcess().HasCapability(ECapabilityReadUserData)) { TESTL(ret != KErrPermissionDenied); } else { // skip this one CleanupStack::PopAndDestroy(&socket); return TestStepResult() ; } TPckgBuf<TUint> sbuf; sbuf()=0; // test cancel first - due to Lubbock problems canceled out socket.Ioctl(KIoctlEnumerateSmsMessages,status,&sbuf, KSolSmsProv); User::WaitForRequest(status); if(RProcess().HasCapability(ECapabilityReadUserData)) { TEST(status.Int() != KErrPermissionDenied); } else { TEST(status.Int() == KErrPermissionDenied); } CleanupStack::PopAndDestroy(&socket); return TestStepResult() ; }
SYSCALL(int, maConnGetAddr(MAHandle conn, MAConnAddr* addr)) { LOGST("maConnGetAddr(%i, 0x%08X)", conn, addr); if(conn == HANDLE_LOCAL) { if(addr->family == CONN_FAMILY_BT) { TBTDevAddr btaddr; //TPckgBuf<TBTDevAddr> pckg(btaddr); //old style, might work on Symbian 7.0 and earlier //update: doesn't work on 6630. #if 0//!defined(__SERIES60_3X__) RSocket socket; socket.Open(gSocketServ, KBTAddrFamily, KSockSeqPacket, KL2CAP); TRequestStatus status; socket.Ioctl(KHCILocalAddressIoctl, status, &pckg, KSolBtHCI); User::WaitForRequest(status); LOG("KHCILocalAddressIoctl result: %i\n", status.Int()); socket.Close(); if(status != KErrNone) { return CONNERR_GENERIC; } #else #if 0 //doesn't work; bug in Symbian. int result = RProperty::Get(KUidSystemCategory, KPropertyKeyBluetoothGetLocalDeviceAddress, pckg); LOG("KPropertyKeyBluetoothGetLocalDeviceAddress result: %i\n", result); if(result != KErrNone) { return CONNERR_GENERIC; } #else //open a server socket and read its address. RSocket socket; socket.Open(gSocketServ, KBTAddrFamily, KSockStream, KRFCOMM); int channel; LHEL_BASE(socket.GetOpt(KRFCOMMGetAvailableServerChannel, KSolBtRFCOMM, channel), return CONNERR_GENERIC); TBTSockAddr btsockaddr; btsockaddr.SetPort(channel); LHEL_BASE(socket.Bind(btsockaddr), return CONNERR_GENERIC); socket.LocalName(btsockaddr); socket.Close(); btaddr = btsockaddr.BTAddr(); #endif //0 #endif //0//__SERIES60_3X__ storeBtAddr(btaddr, addr); return 1; } else { //TCP server return CONNERR_INTERNAL;
LOCAL_C void doMainL() { RSocketServ serv; RSocket socket; User::LeaveIfError(serv.Connect()); CleanupClosePushL(serv); TProtocolDesc protoinfo; TProtocolName protocolname(KSmsDatagram); User::LeaveIfError(serv.FindProtocol(protocolname,protoinfo)); User::LeaveIfError(socket.Open(serv,protoinfo.iAddrFamily,protoinfo.iSockType,protoinfo.iProtocol)); TSmsAddr smsaddr; smsaddr.SetSmsAddrFamily(ESmsAddrSendOnly); User::LeaveIfError(socket.Bind(smsaddr)); CleanupClosePushL(socket); CActiveScheduler* iScheduler = new (ELeave) CActiveScheduler; CleanupStack::PushL(iScheduler); CActiveScheduler::Install( iScheduler ); CSmsTestUtils* smsTest = CSmsTestUtils::NewL(test); CleanupStack::PushL(smsTest); TInt nextTest = 0; smsTest->NotifySaPhoneOnL(); smsTest->WaitForInitializeL(); CSmsSendNbsTest* nbsTest = CSmsSendNbsTest::NewL(*smsTest, KNbsScript, nextTest); CleanupStack::PushL(nbsTest); nbsTest->StartL(); CleanupStack::PopAndDestroy(3); //SmsTest, iScheduler CleanupStack::PopAndDestroy(&socket); CleanupStack::PopAndDestroy(&serv); }
TVerdict CSmsCapsWapWrite::doTestStepL() { RSocket wapsock; TRequestStatus status; TInt ret=wapsock.Open(iSocketServer,KWAPSMSAddrFamily,KSockDatagram,KWAPSMSDatagramProtocol); User::LeaveIfError(ret); CleanupClosePushL(wapsock); TWapAddr wapAddr; wapAddr.SetWapPort(TWapPortNumber(9204)); ret=wapsock.Bind(wapAddr); if(RProcess().HasCapability(ECapabilityNetworkServices)) { TESTL(ret != KErrPermissionDenied); } else { // skip this one CleanupStack::PopAndDestroy(&wapsock); return TestStepResult() ; } _LIT(KText,"This is a simple SMS!"); TBuf8<200> data; data.Copy(KText); wapsock.SendTo(data, wapAddr, 0, status); User::WaitForRequest(status); TEST(status.Int() != KErrPermissionDenied); CleanupStack::PopAndDestroy(&wapsock); return TestStepResult() ; }
TVerdict CSmsCapsWapIoctl::doTestStepL() { RSocket wapsock; TRequestStatus status; TInt ret=wapsock.Open(iSocketServer,KWAPSMSAddrFamily,KSockDatagram,KWAPSMSDatagramProtocol); User::LeaveIfError(ret); CleanupClosePushL(wapsock); TWapAddr wapAddr; wapAddr.SetWapPort(TWapPortNumber(9204)); ret=wapsock.Bind(wapAddr); if(RProcess().HasCapability(ECapabilityNetworkServices)) { TESTL(ret != KErrPermissionDenied); } else { // skip this one CleanupStack::PopAndDestroy(&wapsock); return TestStepResult() ; } TPckgBuf<TInt> length; // // Issue Ioctl for getting the length of the message (should fail) // wapsock.Ioctl(KSOGetLength, status, &length, KSolWapProv); User::WaitForRequest(status); TEST(status.Int() != KErrPermissionDenied); CleanupStack::PopAndDestroy(&wapsock); return TestStepResult() ; }
TVerdict CSmsCapsSmsIoctlReadFailedSms::doTestStepL() { TInt ret; // // Set TSY to the test case that has read message // #TestSimpleRxL in tsmsprt-config.txt // TInt testNo=6; RProperty testNumberProperty; User::LeaveIfError(testNumberProperty.Attach(KUidPSSimTsyCategory, KPSSimTsyTestNumber)); CleanupClosePushL(testNumberProperty); TRequestStatus status; testNumberProperty.Subscribe(status); User::LeaveIfError(testNumberProperty.Set(KUidPSSimTsyCategory,KPSSimTsyTestNumber,testNo)); User::WaitForRequest(status); TEST(status.Int() == KErrNone); TInt testNumberCheck; User::LeaveIfError(testNumberProperty.Get(testNumberCheck)); if (testNo != testNumberCheck) User::Leave(KErrNotFound); CleanupStack::PopAndDestroy(&testNumberProperty); // RSocket socket; ret=socket.Open(iSocketServer,KSMSAddrFamily,KSockDatagram,KSMSDatagramProtocol); if(ret!=KErrNone) User::Leave(ret); CleanupClosePushL(socket); TSmsAddr smsaddr; smsaddr.SetSmsAddrFamily(ESmsAddrRecvAny); ret=socket.Bind(smsaddr); if(RProcess().HasCapability(ECapabilityWriteUserData, ECapabilityNetworkServices) && RProcess().HasCapability(ECapabilityReadUserData)) { TESTL(ret != KErrPermissionDenied); } else { // skip this one CleanupStack::PopAndDestroy(&socket); return TestStepResult() ; } // CSmsBuffer* buffer=CSmsBuffer::NewL(); CSmsMessage* smsMessage=CSmsMessage::NewL(iFs, CSmsPDU::ESmsSubmit,buffer); CleanupStack::PushL(smsMessage); RSmsSocketReadStream readstream(socket); TRequestStatus timerStatus; RTimer timer; timer.CreateLocal(); timer.After(timerStatus, TTimeIntervalMicroSeconds32(20000000)); TPckgBuf<TUint> sbuf; sbuf()=KSockSelectRead; socket.Ioctl(KIOctlSelect, status, &sbuf, KSOLSocket); User::WaitForRequest(timerStatus, status); if(status.Int() != KErrNone) { socket.CancelIoctl(); User::WaitForRequest(status); ret = EFalse; } else { timer.Cancel(); User::WaitForRequest(timerStatus); ret = ETrue; } timer.Close(); if(ret) { TRAP(ret,readstream >> *smsMessage); User::LeaveIfError(ret); socket.Ioctl(KIoctlReadMessageFailed, status, NULL, KSolSmsProv); User::WaitForRequest(status); if(RProcess().HasCapability(ECapabilityReadUserData)) { TEST(status.Int() != KErrPermissionDenied); } else { TEST(status.Int() == KErrPermissionDenied); } } CleanupStack::PopAndDestroy(smsMessage); CleanupStack::PopAndDestroy(&socket); return TestStepResult() ; }
TInt Finger() // // // { RTest test(_L("eSock Emulation test - Simple Finger Server")); test.Title(); User::AfterInMicroSeconds(400000); // Connect to the actual socket server TRequestStatus stat; RSocketServ ss; TInt ret = ss.Connect(); test(ret==KErrNone); test.Start(_L("Create Server Socket")); // { RSocket server; ret = server.Open(ss, KAFInet, KSockStream, KProtocolInetTCP); test(ret==KErrNone); test.Next(_L("Starting server")); TInetAddr svraddr(NULL_ADDR, TCP_PORT_FINGER); server.Bind(svraddr, stat); User::WaitForRequest(stat); test(stat==KErrNone); // Set client to non-blocking server.SetOpt(KSOBlockingIO,NULL,KSOLSocket); server.Listen(5, stat); User::WaitForRequest(stat); test(stat==KErrNone); FOREVER { const TInt KBufLen=256; RSocket client; TSockAddr cliaddr; test.Next(_L("Opening null socket to accept with")); ret=client.Open(ss); test(ret==KErrNone); test.Next(_L("Awaiting connection")); // Wait for connection request server.SetOpt(KSOBlockingIO,NULL,KSOLSocket); client.Accept(server, cliaddr, stat); User::WaitForRequest(stat); test(stat==KErrNone); test.Next(_L("Get request string")); // Set client to non-blocking server.SetOpt(KSONonBlockingIO,NULL,KSOLSocket); // Read request string from remote client TBuf<KBufLen> reqbuf; reqbuf.SetLength(KBufLen); test(RecvLine(test, reqbuf, client)>0); test.Printf(_L("Request: %s\n"), reqbuf.PtrZ()); test.Next(_L("Send answer text")); TBuf<100> tmpbuf; tmpbuf.SetLength(0); tmpbuf.Format(_L("No information available on user \"%s\".\r\n"), reqbuf.PtrZ()); client.Write(tmpbuf,stat); User::WaitForRequest(stat); test(stat==KErrNone); tmpbuf.Format(_L("\r\n"), reqbuf.PtrZ()); client.Write(tmpbuf,stat); User::WaitForRequest(stat); test(stat==KErrNone); test.Next(_L("Close")); test(client.Close()==KErrNone); // break; } test.Next(_L("Closing")); test(server.Close()==KErrNone); test.End(); // } return 0; }
TVerdict CSmsCapsSmsIoctlWriteSms::doTestStepL() { TInt ret; // // Set TSY to the test case // // TInt testNo=13; RProperty testNumberProperty; User::LeaveIfError(testNumberProperty.Attach(KUidPSSimTsyCategory, KPSSimTsyTestNumber)); CleanupClosePushL(testNumberProperty); TRequestStatus status; testNumberProperty.Subscribe(status); User::LeaveIfError(testNumberProperty.Set(KUidPSSimTsyCategory,KPSSimTsyTestNumber,testNo)); User::WaitForRequest(status); TEST(status.Int() == KErrNone); TInt testNumberCheck; User::LeaveIfError(testNumberProperty.Get(testNumberCheck)); if (testNo != testNumberCheck) User::Leave(KErrNotFound); CleanupStack::PopAndDestroy(&testNumberProperty); // RSocket socket; ret=socket.Open(iSocketServer,KSMSAddrFamily,KSockDatagram,KSMSDatagramProtocol); if(ret!=KErrNone) User::Leave(ret); CleanupClosePushL(socket); TSmsAddr smsaddr; smsaddr.SetSmsAddrFamily(ESmsAddrRecvAny); ret=socket.Bind(smsaddr); if(RProcess().HasCapability(ECapabilityWriteUserData, ECapabilityNetworkServices) && RProcess().HasCapability(ECapabilityReadUserData)) { TESTL(ret != KErrPermissionDenied); } else { // skip this one CleanupStack::PopAndDestroy(&socket); return TestStepResult() ; } // Create message with SRR _LIT(KText,"This is a simple SMS!"); CSmsMessage* msg=CreateSmsMessageL(KText,TSmsDataCodingScheme::ESmsAlphabet7Bit); CleanupStack::PushL(msg); // Send message RSmsSocketWriteStream writestream(socket); TRAP(ret,writestream << *msg); User::LeaveIfError(ret); TRAP(ret,writestream.CommitL()); User::LeaveIfError(ret); socket.Ioctl(KIoctlWriteSmsMessage,status,NULL, KSolSmsProv); User::WaitForRequest(status); if(RProcess().HasCapability(ECapabilityWriteUserData)) { TEST(status.Int() != KErrPermissionDenied); } else { TEST(status.Int() == KErrPermissionDenied); } CleanupStack::PopAndDestroy(msg); CleanupStack::PopAndDestroy(&socket); return TestStepResult() ; }
SilcStream silc_net_udp_connect(const char *local_ip_addr, int local_port, const char *remote_ip_addr, int remote_port, SilcSchedule schedule) { SilcSymbianSocket *s; SilcStream stream; TInetAddr local, remote; TRequestStatus status; RSocket *sock = NULL; RSocketServ *ss = NULL; TInt ret; SILC_LOG_DEBUG(("Creating UDP stream")); if (!schedule) { schedule = silc_schedule_get_global(); if (!schedule) { silc_set_errno(SILC_ERR_INVALID_ARGUMENT); goto err; } } SILC_LOG_DEBUG(("Binding to local address %s", local_ip_addr ? local_ip_addr : "0.0.0.0")); sock = new RSocket; if (!sock) goto err; ss = new RSocketServ; if (!ss) goto err; /* Open socket server */ ret = ss->Connect(); if (ret != KErrNone) goto err; #ifdef SILC_THREADS /* Make our socket shareable between threads */ ss->ShareAuto(); #endif /* SILC_THREADS */ /* Get local bind address */ if (!silc_net_set_sockaddr(&local, local_ip_addr, local_port)) goto err; /* Create the socket */ ret = sock->Open(*ss, KAfInet, KSockDatagram, KProtocolInetUdp); if (ret != KErrNone) { SILC_LOG_ERROR(("Cannot create socket")); goto err; } /* Set the socket options */ sock->SetOpt(KSoReuseAddr, KSolInetIp, 1); /* Bind the listener socket */ ret = sock->Bind(local); if (ret != KErrNone) { SILC_LOG_DEBUG(("Cannot bind socket")); goto err; } /* Set to connected state if remote address is provided. */ if (remote_ip_addr && remote_port) { if (silc_net_set_sockaddr(&remote, remote_ip_addr, remote_port)) { sock->Connect(remote, status); if (status != KErrNone) { SILC_LOG_DEBUG(("Cannot connect UDP stream")); goto err; } } } /* Encapsulate into socket stream */ s = silc_create_symbian_socket(sock, ss); if (!s) goto err; stream = silc_socket_udp_stream_create((SilcSocket)s, local_ip_addr ? silc_net_is_ip6(local_ip_addr) : FALSE, remote_ip_addr ? TRUE : FALSE, schedule); if (!stream) goto err; SILC_LOG_DEBUG(("UDP stream created, fd=%d", sock)); return stream; err: if (sock) delete sock; if (ss) { ss->Close(); delete ss; } return NULL; }
TVerdict CSmsCapsSmsIoctlCompleteReadParamsSms::doTestStepL() { TInt ret; // // Set TSY to the test case that has read message // #TestSimpleRxL in tsmsprt-config.txt // TInt testNo=13; RProperty testNumberProperty; User::LeaveIfError(testNumberProperty.Attach(KUidPSSimTsyCategory, KPSSimTsyTestNumber)); CleanupClosePushL(testNumberProperty); TRequestStatus status; testNumberProperty.Subscribe(status); User::LeaveIfError(testNumberProperty.Set(KUidPSSimTsyCategory,KPSSimTsyTestNumber,testNo)); User::WaitForRequest(status); TEST(status.Int() == KErrNone); TInt testNumberCheck; User::LeaveIfError(testNumberProperty.Get(testNumberCheck)); if (testNo != testNumberCheck) User::Leave(KErrNotFound); CleanupStack::PopAndDestroy(&testNumberProperty); RSocket socket; ret=socket.Open(iSocketServer,KSMSAddrFamily,KSockDatagram,KSMSDatagramProtocol); User::LeaveIfError(ret); CleanupClosePushL(socket); TSmsAddr smsaddr; smsaddr.SetSmsAddrFamily(ESmsAddrLocalOperation); ret=socket.Bind(smsaddr); if(RProcess().HasCapability(ECapabilityNetworkServices)) { TESTL(ret != KErrPermissionDenied); } else { // skip this one CleanupStack::PopAndDestroy(&socket); return TestStepResult(); } // Small delay to allow the SMS Stack PRT to initialise... User::After(1*1000000); RSmsSocketReadStream readstream(socket); //Create the smspList CMobilePhoneSmspList* smspList = CMobilePhoneSmspList::NewL(); CleanupStack::PushL(smspList); // Make read SMS params request to the SMS Stack. socket.Ioctl(KIoctlReadSmsParams,status,NULL, KSolSmsProv); User::WaitForRequest(status); // Read list from stream and make acknowledgement to the SMS Stack readstream >> *smspList; socket.Ioctl(KIoctlCompleteReadSmsParams, status, NULL,KSolSmsProv); User::WaitForRequest(status); TEST(status.Int() != KErrPermissionDenied); CleanupStack::PopAndDestroy(smspList); CleanupStack::PopAndDestroy(&socket); return TestStepResult() ; }
TVerdict CSmsCapsSmsIoctlWriteParamsSms::doTestStepL() { RSocket socket; TRequestStatus status; TInt ret=socket.Open(iSocketServer,KSMSAddrFamily,KSockDatagram,KSMSDatagramProtocol); if(ret!=KErrNone) User::Leave(ret); CleanupClosePushL(socket); TSmsAddr smsaddr; smsaddr.SetSmsAddrFamily(ESmsAddrLocalOperation); ret=socket.Bind(smsaddr); if(RProcess().HasCapability(ECapabilityWriteUserData, ECapabilityNetworkServices) && RProcess().HasCapability(ECapabilityReadUserData)) { TESTL(ret != KErrPermissionDenied); } else { // skip this one CleanupStack::PopAndDestroy(&socket); return TestStepResult(); } CMobilePhoneSmspList* smspList=CMobilePhoneSmspList::NewL(); CleanupStack::PushL(smspList); RMobileSmsMessaging::TMobileSmspEntryV1 entryToTsy; entryToTsy.iText = SMSCAPS_STORE_TEXT1; entryToTsy.iValidParams = SMSCAPS_STORE_VALID_PARAMS1; entryToTsy.iDestination.iTypeOfNumber = SMSCAPS_MESSAGE_DESTINATION_TON_0; entryToTsy.iDestination.iNumberPlan = SMSCAPS_MESSAGE_DESTINATION_NP_0; entryToTsy.iDestination.iTelNumber = SMSCAPS_MESSAGE_DESTINATION_TEL_NUMBER_0; entryToTsy.iValidityPeriod = SMSCAPS_STORE_VALIDITY1; entryToTsy.iServiceCentre.iTypeOfNumber = SMSCAPS_MESSAGE_GSMSERVICECENTRE_TON_1; entryToTsy.iServiceCentre.iNumberPlan = SMSCAPS_MESSAGE_GSMSERVICECENTRE_NP_1; entryToTsy.iServiceCentre.iTelNumber = SMSCAPS_MESSAGE_GSMSERVICECENTRE_TEL_NUMBER_1; entryToTsy.iProtocolId = SMSCAPS_STORE_PID1; entryToTsy.iDcs = SMSCAPS_STORE_DCS1; entryToTsy.iIndex = 0; smspList->AddEntryL(entryToTsy); RSmsSocketWriteStream writestream(socket); TRAP(ret,writestream << *smspList); User::LeaveIfError(ret); TRAP(ret,writestream.CommitL()); User::LeaveIfError(ret); socket.Ioctl(KIoctlWriteSmsParams,status,NULL, KSolSmsProv); User::WaitForRequest(status); if(RProcess().HasCapability(ECapabilityWriteDeviceData)) { TEST(status.Int() != KErrPermissionDenied); } else { TEST(status.Int() == KErrPermissionDenied); } CleanupStack::PopAndDestroy(smspList); CleanupStack::PopAndDestroy(&socket); return TestStepResult() ; }
enum TVerdict CTestStepLoopback::doTestStepL() { SetTestStepResult(EFail); // const TUid KPktTxKey = {0x104045dd}; // const TUid KPktRxKey = {0x104045de}; // const TUid KMeUid = {0x101F529F}; // TSecurityPolicy readPolicy(ECapability_None); // TSecurityPolicy writePolicy(ECapability_None); // TInt result = RProperty::Define(KMeUid, KPktTxKey .iUid, RProperty::EInt, readPolicy, writePolicy); // result = RProperty::Define(KMeUid, KPktRxKey .iUid, RProperty::EInt, readPolicy, writePolicy); RSocketServ ss; CleanupClosePushL(ss); Logger().WriteFormat(_L("Start: creating + starting connection")); User::LeaveIfError(ss.Connect()); RConnection conn; CleanupClosePushL(conn); User::LeaveIfError(conn.Open(ss)); User::LeaveIfError(conn.Start()); TInt srvPort; if(!GetIntFromConfig(_L("TcpLoop"), _L("Port"), srvPort)) { srvPort = 5002; } Logger().WriteFormat(_L("Start: creating server socket listening on %d"), srvPort); RSocket srv; CleanupClosePushL(srv); User::LeaveIfError(srv.Open(ss, KAfInet, KSockStream, KProtocolInetTcp, conn)); TInetAddr srvAddr(KAfInet); srvAddr.SetPort(srvPort); User::LeaveIfError(srv.Bind(srvAddr)); User::LeaveIfError(srv.Listen(5)); RSocket acc; CleanupClosePushL(acc); User::LeaveIfError(acc.Open(ss)); TRequestStatus accStat; srv.Accept(acc, accStat); Logger().WriteFormat(_L("Start: connecting client socket")); RSocket cli; CleanupClosePushL(cli); User::LeaveIfError(cli.Open(ss, KAfInet, KSockStream, KProtocolInetTcp, conn)); srvAddr.SetAddress(0xC0A80707); TRequestStatus cliStat; cli.Connect(srvAddr, cliStat); User::WaitForRequest(cliStat, accStat); User::WaitForRequest(cliStat, accStat); User::LeaveIfError(cliStat.Int()); User::LeaveIfError(accStat.Int()); //_LIT8(KTest, "jackdaws love my big sphinx of quartz"); TInt xferSize = 0; if(!GetIntFromConfig(_L("TcpLoop"), _L("xferSize"), xferSize)) { xferSize = 1 * 1000 * 1000; } TInt fc = User::FastCounter(); TInt txSize = 0; TInt txCnt = 0; TRequestStatus txStat(KErrNone); TBuf8<4096> txBuf; txBuf.SetMax(); TInt rxSize = 0; TInt rxCnt = -1; TRequestStatus rxStat(KErrNone); TBuf8<4096> rxBuf; Logger().WriteFormat(_L("Transferring %d bytes"), xferSize); while(rxSize < xferSize) { fc = User::FastCounter(); if(txStat.Int() != KRequestPending) { RDebug::Printf("tx status:%d, ", txStat.Int()); cli.Send(txBuf, 0, txStat); ++txCnt; txSize += txBuf.Length(); RDebug::Printf("tx #%d, %d, +%d\n", txCnt, fc, txBuf.Length()); } if(rxStat.Int() != KRequestPending) { RDebug::Printf("rx status:%d, ", rxStat.Int()); ++rxCnt; rxSize += rxBuf.Length(); RDebug::Printf("rx #%d, %d, +%d\n", rxCnt, fc, rxBuf.Length()); TSockXfrLength dummy; acc.RecvOneOrMore(rxBuf, 0, rxStat, dummy); } User::WaitForRequest(rxStat, txStat); } Logger().WriteFormat(_L("Transferred; %d writes, %d reads"), txCnt, rxCnt); // RProperty::Get(KUidSystemCategory, KPktTxKey .iUid, txCnt); // RProperty::Define(KUidSystemCategory, KPktRxKey .iUid, rxCnt); // Logger().WriteFormat(_L("Packet counts; %d sends, %d processes"), txCnt, rxCnt); CleanupStack::PopAndDestroy(5, &ss); SetTestStepResult(EPass); return TestStepResult(); };