bluetooth/btsdp/test/TSDPSAS.h
changeset 0 29b1cd4cb562
equal deleted inserted replaced
-1:000000000000 0:29b1cd4cb562
       
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Verification Test SDP
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <btsdp.h>
       
    19 #include "sdpkey.h"
       
    20 #include "SDPDatabase.h"
       
    21 #include <btmanclient.h>
       
    22 
       
    23 #ifndef __SDPSAS_H__
       
    24 #define __SDPSAS_H__
       
    25 
       
    26 #ifndef __ES_SOCK_H__
       
    27 #include <es_sock.h>
       
    28 #endif
       
    29 
       
    30 #ifndef __BT_SOCK_H__
       
    31 #include <bt_sock.h>
       
    32 #endif
       
    33 
       
    34 
       
    35 // Constants
       
    36 const TInt KMaxRequestableUUIDs	= 12;
       
    37 const TInt KMaxNumRecordHandles	= 50;
       
    38 const TInt KMaxNumBrowseUUIDs	= 50;
       
    39 const TInt KNumSDPServiceTests = 6;
       
    40 const TInt KNumSDPAttributeTests = 23;
       
    41 const TInt KNumSDPServiceAttributeTests = 24;
       
    42 const TInt KMaxAttributeListByteCount = 200;
       
    43 
       
    44 // SDP test base class. Provides untilities for running raw SDP tests over
       
    45 // L2CAP. 
       
    46 class CSdpTestBase : public CBase
       
    47 	{
       
    48 public:
       
    49 	enum TUuidType {EUuid16,
       
    50 					EUuid32,
       
    51 					EUuid128,
       
    52 					EUuidInvalid} ;
       
    53 	CSdpTestBase(CConsoleBase& aConsole);
       
    54 	~CSdpTestBase();
       
    55 
       
    56 	// Utility functions
       
    57 	//
       
    58 	void StartSDPServerL();
       
    59 	void SendCloseL();
       
    60 	void WaitForCloseL();
       
    61 	void RegisterDatabaseInServerL(CSdpDatabase& aDb);
       
    62 	void SdpConnectL();
       
    63 	virtual	CSdpDatabase* BuildDbL() = 0;	// To be implemented according to test types.
       
    64 
       
    65 protected:
       
    66 	// SDP database stuff
       
    67 	//
       
    68 	RSdp iSdp;
       
    69 	RSdpDatabase iSdpDatabase;
       
    70 	CSdpDatabase* iTheDb;
       
    71 	CConsoleBase& iConsole;
       
    72 	RSocket iRawSock;	// Socket for sending raw bytes over L2CAP PSM 1 (SDP).
       
    73 
       
    74 	TUint16 iRawTransactionId;	// Incremented to provide a unique ID for every query.
       
    75 
       
    76 	};
       
    77 
       
    78 // Class to represent the SDP header bytes
       
    79 class TSDPHeader
       
    80 {
       
    81 public:
       
    82 	TSDPHeader();
       
    83 	TSDPHeader(TUint8 aPduId, TUint16 aTranId, TUint16 aLen);
       
    84 	void AppendHeader(TDes8& aBuf);
       
    85 
       
    86 	inline TUint8 GetPduUd(){return iPduId;}
       
    87 	inline TUint16 GetTransactionId(){return iTransactionId;}
       
    88 	inline TUint16 GetParamsLen(){return iParamLen;}
       
    89 private:
       
    90 	TUint8  iPduId;
       
    91 	TUint16  iTransactionId;
       
    92 	TUint16  iParamLen;
       
    93 };
       
    94 
       
    95 // Class to represent the SDP service request bytes
       
    96 class TServiceRequest	// Note this doesn't contain continuation
       
    97 	{
       
    98 public:
       
    99 	TServiceRequest();
       
   100 	//TServiceRequest(TUint8* aDes, const TUint8* aUuid128, TUint16 aMaxRecordCount);
       
   101 	TServiceRequest(TUint8* aDes, TUUID aUuid, CSdpTestBase::TUuidType aUuidType, TUint16 aMaxRecordCount);
       
   102 	TServiceRequest(TUint8* aDes, CSdpSearchPattern& aSP, CSdpTestBase::TUuidType aUuidType, TUint16 aMaxRecordCount);
       
   103 	TServiceRequest(TUUID aUuid, CSdpTestBase::TUuidType aUuidType, TUint16 aMaxRecordCount);
       
   104 	TServiceRequest(CSdpSearchPattern& aSP, CSdpTestBase::TUuidType aUuidType, TUint16 aMaxRecordCount);
       
   105 	void SetupDES();
       
   106 	void SetUuidType(CSdpTestBase::TUuidType aUuidType);
       
   107 	void AppendRequest(TDes8& aBuf);
       
   108 
       
   109 	inline TUUID Uuid(){return iUuid;}
       
   110 	inline CSdpSearchPattern* SP(){return iSP;}
       
   111 	inline CSdpTestBase::TUuidType UuidType(){return iUuidType;}
       
   112 	inline TUint16 MaxRecordCount(){return iMaxRecordCount;}
       
   113 	inline TUint8* Des(){return iDes;}
       
   114 private:
       
   115 	TUint8  iDes[3];
       
   116 	//TUint32	iUuid32;
       
   117 	TUUID iUuid;
       
   118 	CSdpSearchPattern* iSP;//for multiple uuid requests
       
   119 	TUint16 iMaxRecordCount;
       
   120 	CSdpTestBase::TUuidType iUuidType; //inticates which length of Uuid used
       
   121 	TBool iAutoDes;
       
   122 	};
       
   123 	
       
   124 // Class to represent the SDP attribute request bytes
       
   125 class TAttributeRequest	
       
   126 	{
       
   127 public:
       
   128 	TAttributeRequest();
       
   129 	TAttributeRequest(TUint32 aRecordHandle, TUint16 aMaxByteCount, TUint8* aDes, TUint16 aAttributeId);
       
   130 	TAttributeRequest(TUint32 aRecordHandle, TUint16 aMaxByteCount, TUint8* aDes, TUint32 aAttributeIdRange);
       
   131 	TAttributeRequest(TUint32 aRecordHandle, TUint16 aMaxByteCount, TUint16 aAttributeId);
       
   132 	TAttributeRequest(TUint32 aRecordHandle, TUint16 aMaxByteCount, TUint32 aAttributeIdRange);
       
   133 	void SetupDES();
       
   134 	void AppendRequest(TDes8& aBuf);
       
   135 
       
   136 	inline TUint32 RecordHandle(){return iRecordHandle;}
       
   137 	inline void SetRecordHandle(TUint16 aRecordHandle){iRecordHandle=aRecordHandle;}
       
   138 	inline TUint16 MaxByteCount(){return iMaxByteCount;}
       
   139 	inline TUint16 AttributeId(){return iAttributeId;}
       
   140 	inline TUint32 AttributeIdRange(){return iAttributeIdRange;}
       
   141 	inline TUint8* Des(){return iDes;}
       
   142 
       
   143 private:
       
   144 	TUint32 iRecordHandle;
       
   145 	TUint16 iMaxByteCount;
       
   146 	TUint8  iDes[3];
       
   147 	TUint16	iAttributeId;
       
   148 	TUint32	iAttributeIdRange;
       
   149 	TBool iAutoDes;
       
   150 	}; 
       
   151 
       
   152 //
       
   153 // TServiceAttributeRequest
       
   154 //
       
   155 class TServiceAttributeRequest
       
   156 	{
       
   157 public:
       
   158 	TServiceAttributeRequest();
       
   159 
       
   160 	//TServiceAttributeRequest(TUint8* aServiceDes, TUint16 aServiceUuid, TUint16 aMaxByteCount, TUint8* aAttribDes, TUint16 aAttributeId);
       
   161 	//TServiceAttributeRequest(TUint8* aServiceDes, TUint32 aServiceUuid, TUint16 aMaxByteCount, TUint8* aAttribDes, TUint16 aAttributeId);
       
   162 	TServiceAttributeRequest(TUint8* aServiceDes, TUUID aServiceUuid, CSdpTestBase::TUuidType aUuidType, TUint16 aMaxByteCount, TUint8* aAttribDes, TUint16 aAttributeId);
       
   163 	TServiceAttributeRequest(TUUID aServiceUuid, CSdpTestBase::TUuidType aUuidType, TUint16 aMaxByteCount, TUint16 aAttributeId);
       
   164 
       
   165 	//TServiceAttributeRequest(TUint8* aServiceDes, TUint16 aServiceUuid, TUint16 aMaxByteCount, TUint8* aAttribDes, TUint32 aAttributeIdRange);
       
   166 	//TServiceAttributeRequest(TUint8* aServiceDes, TUint32 aServiceUuid, TUint16 aMaxByteCount, TUint8* aAttribDes, TUint32 aAttributeIdRange);
       
   167 	TServiceAttributeRequest(TUint8* aServiceDes, TUUID aServiceUuid, CSdpTestBase::TUuidType aUuidType, TUint16 aMaxByteCount, TUint8* aAttribDes, TUint32 aAttributeIdRange);
       
   168 	TServiceAttributeRequest(TUUID aServiceUuid, CSdpTestBase::TUuidType aUuidType, TUint16 aMaxByteCount, TUint32 aAttributeIdRange);
       
   169 
       
   170 	void SetUuidType(CSdpTestBase::TUuidType aUuidType);
       
   171 	void AppendRequest(TDes8& aBuf);
       
   172 
       
   173 	inline TUint16 MaxByteCount(){return iAttributeRequest.MaxByteCount();}
       
   174 
       
   175 	inline TServiceRequest& ServiceParams(){return iServiceRequest;}
       
   176 	inline TAttributeRequest& AttributeParams(){return iAttributeRequest;}
       
   177 private:
       
   178 	//Have this as a combination of service and attribute requests
       
   179 	//
       
   180 	TServiceRequest iServiceRequest;
       
   181 	TAttributeRequest iAttributeRequest;
       
   182 
       
   183 	};
       
   184 
       
   185 
       
   186 
       
   187 // Class for the SDP verification test group.
       
   188 class CSdpVerificationTests : public CSdpTestBase , public MSdpElementBuilder
       
   189 	{
       
   190 public:
       
   191 	static void RunTestL(CConsoleBase& aConsole);
       
   192 	CSdpVerificationTests(CConsoleBase& aConsole);
       
   193 	~CSdpVerificationTests();
       
   194 
       
   195 	// Master 
       
   196 	void RunMasterTestL();
       
   197 	CSdpDatabase* BuildDbL();
       
   198 	void PrintDb(CSdpDatabase& aDb, CConsoleBase& aConsole);
       
   199 private:
       
   200 
       
   201 	// Test functions
       
   202 	void DoTestsL();
       
   203 	void SDPQueryL();
       
   204 	void RunSDPSearchL();
       
   205 	void SDPServiceSearchL();
       
   206 	void SDPAttributeSearchL();
       
   207 	void SDPServiceAttributeSearch();
       
   208 	void SDPBrowseTestL(TUuidType aUuidType);
       
   209 	TBool AnotherQuery();
       
   210 	TBool Continue();
       
   211 	TInt GetUuidSize();
       
   212 	void UpdateTestString();
       
   213 	void FlogTestId();
       
   214 	TInt MaxCountFoundAfterServiceSearchPatternOrWhatYouWill(TDesC8& aString);
       
   215 	void FlogParsedPDUHeader(TDesC8& aString);
       
   216 	void FlogString(const TText* aLineStart, TDesC8& aString);
       
   217 	void FlogReadString(TDesC8& aString);
       
   218 	void FlogContinuationString(TDesC8&aString);
       
   219 	void FlogWriteString(TDesC8& aString);
       
   220 	void WaitForStartSignalL();
       
   221 	void SendStartSignalL();
       
   222 	void PromptedGetch();
       
   223 
       
   224 	// Browse tests
       
   225 	//
       
   226 	void BuildBrowseDbL(CConsoleBase&  aConsole);
       
   227 
       
   228 	// Initialisation
       
   229 	void SetUpServiceTestParams();
       
   230 	void SetUpAttributeTestParams();
       
   231 	void SetUpServiceAttributeTestParams();
       
   232 
       
   233 	// Process results
       
   234 	TInt ProcessSearchResults(TDesC8& aResult1, TDesC8& aResult2);
       
   235 	TInt ProcessServiceSearchResults(TDesC8& aResult1, TDesC8& aResult2);
       
   236 	TInt ProcessAttributeSearchResults(TDesC8& aResult1, TDesC8& aResult2);
       
   237 	TInt ProcessServiceAttributeSearchResults(TDesC8& aResult1, TDesC8& aResult2);
       
   238 
       
   239 	// MSdpElementBuilder implementations
       
   240 	MSdpElementBuilder* BuildUintL(const TDesC8& aUint);
       
   241 	MSdpElementBuilder* BuildUUIDL(const TUUID& aUUID);
       
   242 	MSdpElementBuilder* BuildStringL(const TDesC8& aString);
       
   243 	MSdpElementBuilder* BuildDESL();  // Must not return NULL
       
   244 	MSdpElementBuilder* BuildURLL(const TDesC8& aURL);
       
   245 	MSdpElementBuilder* StartListL();
       
   246 	MSdpElementBuilder* EndListL();
       
   247 	MSdpElementBuilder* BuildNilL();
       
   248 
       
   249 
       
   250 	// Private data
       
   251 	//
       
   252 	TServiceRequest iServiceTests[KNumSDPServiceTests + KNumSDPAttributeTests];	// Holds the service test params.
       
   253 																				// Attribute tests involve a service query as well.
       
   254 	TAttributeRequest iAttributeTests[KNumSDPAttributeTests];	//Holds the attribute test params
       
   255 	TServiceAttributeRequest iServiceAttributeTests[KNumSDPServiceAttributeTests];
       
   256 	
       
   257 	CSdpSearchPattern* iSP;
       
   258 
       
   259 	
       
   260 	TUint8 iContinuationBuffer[KSdpContinuationStateMaxLength];	// Buffer for continuation state
       
   261 	TUint8 iContLength;	// Continuation state length
       
   262 	TBuf8<14000>	iContinuationStore;	// Holds the growing buffer while the requests 
       
   263 									// are returning one by one
       
   264 	TUint32 iAttributeTestServiceRecordHandle;
       
   265 	TUint32 iBrowseTestServiceRecordHandle[KMaxNumRecordHandles];
       
   266 	TUint32 iBrowseTestNumRecordHandlesStored;
       
   267 	TUUID iBrowseUUID[KMaxNumBrowseUUIDs];
       
   268 	TInt iNumBrowseUUIDs;
       
   269 
       
   270 	enum TTestType {EServiceRequest,
       
   271 					EServiceAttributeRequest,
       
   272 					EServiceSearchAttributeRequest} ;
       
   273 
       
   274 	TTestType iType;	// The type of test currently being run
       
   275 	TInt8 iQueryIndex;	// For the tests that have 2 queries.
       
   276 	TTestType	iQueryState;
       
   277 	TUint iTestNum;		// THe number of test running.
       
   278 	TBool iNeedAttributeId;
       
   279 	TInt iBuildingList;
       
   280 	TInt iBrowseIter;
       
   281 	TInt iIndent;
       
   282 	TInt iRequestMaxCount;
       
   283 	TInt iRequestMaxCount1;
       
   284 	TInt iRequestMaxCount2;
       
   285 	TInt iRequestTransId;
       
   286 	TInt iRequestTransId1;
       
   287 	TInt iRequestTransId2;
       
   288 	TBool iNeedMoreRecordHandles;
       
   289 	CSdpTestBase::TUuidType iUuidType; //indicates which length of Uuid to be used
       
   290 	TBuf<77> iTestName;
       
   291 	};
       
   292 
       
   293 class CBrowseResponseBuilder : public CBase, public MSdpElementBuilder
       
   294 	{
       
   295 public:
       
   296 		CBrowseResponseBuilder(TDes& aTestName, TInt aBrowseIter, CSdpSearchPattern& aBrowseSP);
       
   297 		~CBrowseResponseBuilder();
       
   298 		MSdpElementBuilder* BuildUintL(const TDesC8& aUint);
       
   299 		MSdpElementBuilder* BuildUUIDL(const TUUID& aUUID);
       
   300  		MSdpElementBuilder* BuildDESL();  // Must not return NULL
       
   301 		MSdpElementBuilder* StartListL();
       
   302 		MSdpElementBuilder* EndListL();
       
   303 private:
       
   304 	TDes& iTestName;
       
   305 	TInt iBrowseIter;
       
   306 	TBool iNeedAttributeId;
       
   307 	TInt iBuildingList;
       
   308 	CSdpSearchPattern& iBrowseSP;
       
   309 	};
       
   310 
       
   311 
       
   312 class CPrintBuilder : public CBase, public MSdpElementBuilder
       
   313 	{
       
   314 public:
       
   315 	CPrintBuilder(CConsoleBase& aConsole);
       
   316 	~CPrintBuilder();
       
   317 
       
   318 	void HexDumpVT(const TDesC8& aDes);
       
   319 	MSdpElementBuilder* BuildUnknown(TUint8 aType, TUint8 aSizeDesc, const TDesC8& aData);
       
   320 	MSdpElementBuilder* BuildUintL(const TDesC8& aUint);
       
   321 	MSdpElementBuilder* BuildIntL(const TDesC8& aUint);
       
   322 	MSdpElementBuilder* BuildUUIDL(const TUUID& aUUID);
       
   323 	MSdpElementBuilder* BuildBooleanL(TBool aBool);
       
   324 	MSdpElementBuilder* BuildStringL(const TDesC8& aString);
       
   325 	MSdpElementBuilder* BuildDESL();  // Must not return NULL
       
   326 	MSdpElementBuilder* BuildDEAL();  // Must not return NULL
       
   327 	MSdpElementBuilder* BuildURLL(const TDesC8& aURL);
       
   328 	MSdpElementBuilder* StartListL();
       
   329 	MSdpElementBuilder* EndListL();
       
   330 	MSdpElementBuilder* BuildNilL();
       
   331 
       
   332 private:
       
   333 	TInt iIndent;
       
   334 	CConsoleBase& iConsole;
       
   335 	};
       
   336 #endif