bluetoothmgmt/btmgr/BTManClient/BTDefCommPort.cpp
changeset 0 29b1cd4cb562
equal deleted inserted replaced
-1:000000000000 0:29b1cd4cb562
       
     1 // Copyright (c) 1999-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 // Implements classes dealing with setting virtual serial ports
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <btdefcommport.h>
       
    19 #include <bttypes.h>
       
    20 #include <e32base.h>
       
    21 #include <s32strm.h>
       
    22 #include "btmanclientserver.h"
       
    23 #include <bluetooth/logger.h>
       
    24 
       
    25 #ifdef __FLOG_ACTIVE
       
    26 _LIT8(KLogComponent, LOG_COMPONENT_BT_MANAGER_CLIENT);
       
    27 #endif
       
    28 
       
    29 
       
    30 /**
       
    31 Constructor
       
    32 @param aName The name of the virtual serial port
       
    33 @param aUUID the UUID to use on the remote device
       
    34 @param aBTCommPort The virtual serial port number
       
    35 @param aSecurityLevel The Bluetooth security desired for the connection
       
    36 @param aBDAddr The Bluetooth device address of the remote device
       
    37 @see Bluetooth Assigned numbers for UUIDs
       
    38 
       
    39 @publishedAll
       
    40 @released
       
    41 */
       
    42 EXPORT_C TBTCommPortSettings::TBTCommPortSettings(const TDesC& aName, TUUID aUUID, 
       
    43 		TUint32 aBTCommPort, TUint8 aSecurityLevel, TBTDevAddr aBDAddr) :
       
    44 	iName(aName),
       
    45 	iUUID(aUUID),
       
    46 	iPort(aBTCommPort),
       
    47 	iSecurityLevel(aSecurityLevel),
       
    48 	iBDAddr(aBDAddr)
       
    49 	{
       
    50 	LOG_FUNC
       
    51 	}
       
    52 
       
    53 /**
       
    54 Default constructor
       
    55 @publishedAll
       
    56 @released
       
    57 */
       
    58 EXPORT_C TBTCommPortSettings::TBTCommPortSettings() :
       
    59 	iUUID(),
       
    60 	iPort(0),
       
    61 	iSecurityLevel(0),
       
    62 	iBDAddr(TInt64(0))
       
    63 	{
       
    64 	LOG_FUNC
       
    65 	iName.Zero();
       
    66 	}
       
    67 
       
    68 /**
       
    69 Getter for the name of the virtual serial port
       
    70 @return name of virtual serial port
       
    71 @publishedAll
       
    72 @released
       
    73 */
       
    74 EXPORT_C const TDesC& TBTCommPortSettings::Name() const
       
    75 	{
       
    76 	LOG_FUNC
       
    77 	return iName;
       
    78 	}
       
    79 
       
    80 /**
       
    81 Getter for the UUID of the virtual serial port
       
    82 @return UUID of virtual serial port
       
    83 @publishedAll
       
    84 @released
       
    85 */
       
    86 EXPORT_C TUUID TBTCommPortSettings::UUID() const
       
    87 	{
       
    88 	LOG_FUNC
       
    89 	return iUUID;
       
    90 	}
       
    91 
       
    92 /**
       
    93 Getter for the port number of the virtual serial port
       
    94 @return port number of virtual serial port
       
    95 @publishedAll
       
    96 @released
       
    97 */
       
    98 EXPORT_C TUint32 TBTCommPortSettings::Port() const
       
    99 	{
       
   100 	LOG_FUNC
       
   101 	return iPort;
       
   102 	}
       
   103 
       
   104 /**
       
   105 Setter for the name of the virtual serial port
       
   106 @param aName name of the virtual serial port
       
   107 @publishedAll
       
   108 @released
       
   109 */
       
   110 EXPORT_C void TBTCommPortSettings::SetName(const TDesC& aName)
       
   111 	{
       
   112 	LOG_FUNC
       
   113 	iName = aName;
       
   114 	}
       
   115 
       
   116 
       
   117 /**
       
   118 Setter for the UUID of the virtual serial port
       
   119 @param aUUID UUID of the virtual serial port
       
   120 @publishedAll
       
   121 @released
       
   122 */
       
   123 EXPORT_C void TBTCommPortSettings::SetUUID(TUUID aUUID)
       
   124 	{
       
   125 	LOG_FUNC
       
   126 	iUUID = aUUID;
       
   127 	}
       
   128 
       
   129 /**
       
   130 Getter for the remote device address of the virtual serial port
       
   131 @return remote device address of the virtual serial port
       
   132 @publishedAll
       
   133 @released
       
   134 */
       
   135 EXPORT_C TBTDevAddr TBTCommPortSettings::BDAddr() const
       
   136 	{
       
   137 	LOG_FUNC
       
   138 	return iBDAddr;
       
   139 	}
       
   140 
       
   141 /**
       
   142 Setter for the remote device address of the virtual serial port
       
   143 @param aBDAddr remote device address of the virtual serial port
       
   144 @publishedAll
       
   145 @released
       
   146 */
       
   147 EXPORT_C void TBTCommPortSettings::SetBTAddr(TBTDevAddr aBDAddr)
       
   148 	{
       
   149 	LOG_FUNC
       
   150 	iBDAddr = aBDAddr;
       
   151 	}
       
   152 
       
   153 /**
       
   154 Setter for the port number of the virtual serial port
       
   155 @param aBTCommPort port number of the virtual serial port
       
   156 @publishedAll
       
   157 @released
       
   158 */
       
   159 EXPORT_C void TBTCommPortSettings::SetPort(TUint32 aBTCommPort)
       
   160 	{
       
   161 	LOG_FUNC
       
   162 	iPort=aBTCommPort;
       
   163 	}
       
   164 
       
   165 /**
       
   166 Setter to request authentication of the virtual serial connection when connection occurs
       
   167 @publishedAll
       
   168 @released
       
   169 */
       
   170 EXPORT_C void TBTCommPortSettings::SetAuthentication()
       
   171 	{
       
   172 	LOG_FUNC
       
   173 	iSecurityLevel=KBTDefaultServiceSecurityAuthenticateOnly;
       
   174 	}
       
   175 
       
   176 /**
       
   177 Setter to request authentication and encryption of the virtual serial connection when connection occurs
       
   178 @publishedAll
       
   179 @released
       
   180 */
       
   181 EXPORT_C void TBTCommPortSettings::SetAuthenticationAndEncryption() 
       
   182 	{
       
   183 	LOG_FUNC
       
   184 	iSecurityLevel=KBTDefaultServiceSecurityAuthenticateAndEncrypt;
       
   185 	}
       
   186 
       
   187 /** 
       
   188 Setter to clear any setting of security settings
       
   189 @publishedAll
       
   190 @released
       
   191 */
       
   192 EXPORT_C void TBTCommPortSettings::SetNoSecurity() 
       
   193 	{
       
   194 	LOG_FUNC
       
   195 	iSecurityLevel=KBTDefaultServiceSecurityNone;
       
   196 	}
       
   197 
       
   198 /**
       
   199 Sets the security level for this default service.
       
   200 @param aLevel the security level:
       
   201 KBTDefaultServiceSecurityNone                   = 0;
       
   202 KBTDefaultServiceSecurityAuthenticateOnly       = 1;
       
   203 KBTDefaultServiceSecurityAuthenticateAndEncrypt = 2;
       
   204 
       
   205 @publishedAll
       
   206 @released
       
   207 */
       
   208 EXPORT_C void TBTCommPortSettings::SetSecurityLevel(TUint8 aLevel)
       
   209 	{
       
   210 	LOG_FUNC
       
   211 	iSecurityLevel=aLevel;
       
   212 	}
       
   213 
       
   214 
       
   215 /**
       
   216 Getter for the security level of the virtual serial port
       
   217 @return the level
       
   218 @see  TBTCommPortSettings::SetSecurityLevel
       
   219 @publishedAll
       
   220 @released
       
   221 */
       
   222 EXPORT_C TUint8 TBTCommPortSettings::SecurityLevel() const
       
   223 	{
       
   224 	LOG_FUNC
       
   225 	return iSecurityLevel;
       
   226 	}
       
   227 
       
   228 /**
       
   229 Getter to return whether any security level is set
       
   230 @return EFalse if no security has been set, otherwise ETrue
       
   231 @publishedAll
       
   232 @released
       
   233 */
       
   234 EXPORT_C TBool TBTCommPortSettings::IsSecuritySet() const
       
   235 	{
       
   236 	LOG_FUNC
       
   237 	return (iSecurityLevel);
       
   238 	}
       
   239 
       
   240 
       
   241 /**
       
   242 Getter to return whether encryption has been set for the virtual serial port connection
       
   243 @return ETrue if encryption has been set, otherwise EFalse
       
   244 @publishedAll
       
   245 @released
       
   246 */
       
   247 EXPORT_C TBool TBTCommPortSettings::IsEncryptionSet() const
       
   248 	{
       
   249 	LOG_FUNC
       
   250 	return (iSecurityLevel==KBTDefaultServiceSecurityAuthenticateAndEncrypt);
       
   251 	}
       
   252 
       
   253 /**
       
   254 Getter to return whether only authentication has been set for the virtual serial port connection
       
   255 @return ETrue if only authentication has been set, otherwise EFalse
       
   256 @publishedAll
       
   257 @released
       
   258 */
       
   259 EXPORT_C TBool TBTCommPortSettings::IsAuthenticationOnlySet() const
       
   260 	{
       
   261 	LOG_FUNC
       
   262 	return (iSecurityLevel==KBTDefaultServiceSecurityAuthenticateOnly);
       
   263 	}
       
   264 
       
   265 /**
       
   266 Default constructor
       
   267 @publishedAll
       
   268 @released
       
   269 */
       
   270 EXPORT_C RBTCommPortSettings::RBTCommPortSettings()
       
   271 : RBTManSubSession()
       
   272 	{
       
   273 	LOG_FUNC
       
   274 	}
       
   275 
       
   276 /**
       
   277 Open the virtual serial port subsession on the registry server
       
   278 @param aSession the session on the Registry server on which to open this subsession
       
   279 @return Systemwide error code
       
   280 @publishedAll
       
   281 @released
       
   282 */
       
   283 EXPORT_C TInt RBTCommPortSettings::Open(RBTRegServ& aSession)
       
   284 	{
       
   285 	LOG_FUNC
       
   286 	return CreateSubSession(aSession.Session(), EBTManCreateCommPortSettingsSubSession, TIpcArgs(NULL));
       
   287 	}
       
   288 
       
   289 /**
       
   290 Get the virtual serial port settings
       
   291 @param aPortSettings reference to a TBTCommPortSettings used for both an 'input' and 'output'.  For the input the aPortSettings MUST have a serial
       
   292 port number.  This is used to retrieve the remaining details for that virtual serial port from the Registry.
       
   293 When the call completes the client's TBTCommPortSettings will have been fully set with all values.
       
   294 Note this is a synchronous call.
       
   295 @return Systemwide error code
       
   296 @publishedAll
       
   297 @released
       
   298 */
       
   299 EXPORT_C TInt RBTCommPortSettings::Get(TBTCommPortSettings& aPortSettings)
       
   300 /**
       
   301 	Get the port settings for a given port
       
   302 	At present the lookup is based on the port number in aPortSettings
       
   303 
       
   304 	Synchronous
       
   305 
       
   306 	@param	aPortSettings Reference to TBTCommPortSettings for result, and uses the port number within it to search
       
   307 	@return	System-wide error
       
   308 **/
       
   309 	{
       
   310 	LOG_FUNC
       
   311 	if (SubSessionHandle())
       
   312 		{
       
   313 		TPckg<TBTCommPortSettings> pckg(aPortSettings);	// TPckg=>Server updates client variable
       
   314 		return SendReceive(EBTRegistryGetCommPortSettings, TIpcArgs(&pckg, NULL, NULL));	// synchronous
       
   315 		}
       
   316 	else
       
   317 		{
       
   318 		//Client has a bad handle therefore complete the call from here
       
   319 		return KErrBadHandle;
       
   320 		}
       
   321 	}
       
   322 
       
   323 /**
       
   324 Modify or add the virtual serial port settings
       
   325 @param aPortSettings reference to a const TBTCommPortSettings.  The aPortSettings MUST have a serial
       
   326 port number.  This is used by the Registry to find the current settings and update with the other settings in aSettings.
       
   327 If the Registry cannot find the port specified it will add the settings in a new record.
       
   328 @param aStatus reference to a TRequestStatus. Note this is an asynchronous call.
       
   329 @publishedAll
       
   330 @released
       
   331 */
       
   332 EXPORT_C void RBTCommPortSettings::Modify(const TBTCommPortSettings& aSettings, TRequestStatus& aStatus)
       
   333 /**
       
   334 	Asynchronously update virtual serial port settings
       
   335 
       
   336 	@param aSettings	The new settings
       
   337 **/
       
   338 	{
       
   339 	LOG_FUNC
       
   340 	if (IsBusy())
       
   341 		{
       
   342 		LocalComplete(aStatus, KErrInUse);
       
   343 		}
       
   344 	else
       
   345 		{
       
   346 		if (SubSessionHandle())
       
   347 			{
       
   348 			iPortPckg = aSettings;
       
   349 			iClientServerMsg().iClientStatusToCancel = &aStatus;
       
   350 			SendReceive(EBTRegistryUpdateCommPortSettings, TIpcArgs(&iPortPckg, NULL, &iClientServerMsg), aStatus);
       
   351 			}
       
   352 		else
       
   353 			{
       
   354 			//Client has a bad handle therefore complete the call from here
       
   355 			LocalComplete(aStatus, KErrBadHandle);
       
   356 			}
       
   357 		}
       
   358 	}
       
   359 
       
   360 
       
   361 
       
   362 /**
       
   363 Delete virtual serial settings
       
   364 @param aSettings reference to a const TBTCommPortSettings.  aSettings MUST have a serial
       
   365 port number.  This is used by the Registry to find the current settings and delete them from the Registry.
       
   366 @param aStatus reference to a TRequestStatus. Note this is an asynchronous call.
       
   367 @publishedAll
       
   368 @released
       
   369 */
       
   370 EXPORT_C void RBTCommPortSettings::Delete(const TBTCommPortSettings& aSettings, TRequestStatus& aStatus)
       
   371 	{
       
   372 	LOG_FUNC
       
   373 	if (IsBusy())
       
   374 		{
       
   375 		LocalComplete(aStatus, KErrInUse);
       
   376 		}
       
   377 	else
       
   378 		{
       
   379 		if (SubSessionHandle())
       
   380 			{
       
   381 			iPortPckg = aSettings;
       
   382 			iClientServerMsg().iClientStatusToCancel = &aStatus;
       
   383 			SendReceive(EBTRegistryDeleteCommPortSettings, TIpcArgs(&iPortPckg, NULL, &iClientServerMsg), aStatus);
       
   384 			}
       
   385 		else
       
   386 			{
       
   387 			//Client has a bad handle therefore complete the call from here
       
   388 			LocalComplete(aStatus, KErrBadHandle);
       
   389 			}
       
   390 		}
       
   391 	}
       
   392 
       
   393 
       
   394 /**
       
   395 Close the virtual serial port subsession on the Registry
       
   396 @publishedAll
       
   397 @released
       
   398 */
       
   399 EXPORT_C void RBTCommPortSettings::Close()
       
   400 	{
       
   401 	LOG_FUNC
       
   402 	RSubSessionBase::CloseSubSession(EBTManCloseSubSession);
       
   403 	}