esockapiextensions/internetsockets/inc/in6_opt.h
changeset 0 af10295192d8
equal deleted inserted replaced
-1:000000000000 0:af10295192d8
       
     1 // Copyright (c) 2004-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 // in6_opt.h - new socket options and MEventService data e.g.
       
    15 // for accessing the network interface and route
       
    16 // information.
       
    17 // New socket options and MEventService data e.g. for accessing the network interface
       
    18 // and route information.
       
    19 //
       
    20 
       
    21 
       
    22 
       
    23 /**
       
    24  @file in6_opt.h
       
    25  @publishedAll
       
    26  @released
       
    27 */
       
    28 
       
    29 #ifndef __INSOCK_IN6_ROUTE_H__
       
    30 #define __INSOCK_IN6_ROUTE_H__
       
    31 
       
    32 #include <in_sock.h>
       
    33 
       
    34 
       
    35 // PS: I'm declaring the following rule:
       
    36 // ** Use socket option names above 0x1000 for all options defined in this file **
       
    37 // (don't want to accidentally collide with in_sock.h, even though the probability is
       
    38 // small considering the number of different sockopt levels)
       
    39 
       
    40 
       
    41 // -- Socket option level: KSolInetIp --
       
    42 
       
    43 /**
       
    44 Controls the use of Explicit Congestion Notification. Values:
       
    45 @li 0 = ECN disabled
       
    46 @li 1 = ECN enabled with ECT(1)
       
    47 @li 2 = ECN enabled with ECT(0) (recommended over ECT(1), because some implementations may
       
    48 not implement ECT(1))
       
    49 
       
    50 See RFC 3168 for more information.
       
    51 @publishedAll
       
    52 @released
       
    53 */
       
    54 const TUint KSoIpEcn = 0x1010;
       
    55 
       
    56 /**
       
    57 Next hop route selection.
       
    58 
       
    59 Set forces the next hop route selection on the flow.
       
    60 The option parameter is not used in set.
       
    61 
       
    62 Get returns information about the current next hop
       
    63 selection. The option parameter is TInetRouteInfo.
       
    64 
       
    65 If the link layer is using addresses, the information
       
    66 refers to neighbor cache entry. If the interface is not
       
    67 using link layer addresses, the returned information just
       
    68 describes the currently attached route entry.
       
    69 
       
    70 To be successful, the flow must be assigned to the
       
    71 interface and the source address must be set at the
       
    72 time of the call.
       
    73 
       
    74 This option is provided for hook implementations, for
       
    75 example ISATAP tunneling hook can use this¨to force
       
    76 next hop selection on the virtual interface to find the
       
    77 actual link layer address (= outer IPv4 address).
       
    78 */
       
    79 const TUint KSoNextHop = 0x1011;
       
    80 
       
    81 
       
    82 // -- Socket option level: KSolInetTcp --
       
    83 /**
       
    84 If set, only full-sized TCP segments are sent before closing the connection. This is like
       
    85 Nagle, but stricter.
       
    86 @publishedAll
       
    87 @released
       
    88 */
       
    89 const TUint KSoTcpCork = 0x1020;
       
    90 
       
    91 /**
       
    92 Send only full-sized TCP segments. Separate option in addition to KSoTcpCork is needed for
       
    93 BSD compatibility.
       
    94 @publishedAll
       
    95 @released
       
    96 */
       
    97 const TUint KSoTcpNoPush = 0x1021;
       
    98 
       
    99 /**
       
   100 Do not return from close immediately, but linger for given maximum time to wait that the
       
   101 send buffers are emptied. Socket option parameter is TSoTcpLingerOpt struct.
       
   102 @publishedAll
       
   103 @released
       
   104 */
       
   105 const TUint KSoTcpLinger = 0x1022;
       
   106 
       
   107 
       
   108 /**
       
   109 Parameter struct for KSoTcpLinger socket option. The following combinations are possible:
       
   110 
       
   111 @li <b>iOnOff == 0</b>: Close() call returns immediately, but TCP still
       
   112 		tries to transmit the data remaining in its send buffers.
       
   113 @li <b>iOnOff == 1, iLinger == 0</b>: Close() returns immediately, and the TCP sender discards
       
   114 		all data in its send buffers. TCP RST is sent to the other end. Note: the TCP sender
       
   115 		avoids the TIME_WAIT state.
       
   116 @li <b>iOnOff == 1, iLinger > 0</b>: Close() call blocks until the data in TCP send buffers
       
   117 		is succesfully transmitted and the connection is graciously terminated.
       
   118 		If the sender cannot transmit all data before the linger time expires,
       
   119 		the Close() call wakes up, but the stack continues towards terminating the
       
   120 		connection as usual.
       
   121 		
       
   122 A similar structure is used in BSD Unix sockets, hence porting Unix apps using linger option
       
   123 should be straight forward.
       
   124 @publishedAll
       
   125 @released
       
   126 */
       
   127 class TSoTcpLingerOpt
       
   128 	{
       
   129 public:
       
   130 	TInt	iOnOff;		//< 0=Linger off; nonzero=Linger on.
       
   131 	TInt	iLinger;	//< Linger time in seconds.
       
   132 	};
       
   133 	
       
   134 
       
   135 // -- Socket option level: KSolInetIfQuery --
       
   136 
       
   137 // The options below are on KSolInetIfQuery level, although they use different option format
       
   138 // than the rest of the options.
       
   139 // There are no incoming parameters for these queries
       
   140 
       
   141 /**
       
   142 Return array of TInetInterfaceInfo objects as the response of GetOptions call.
       
   143 @publishedAll
       
   144 @released
       
   145 */
       
   146 const TUint KSoInetInterfaceInfo = 0x1001;
       
   147 
       
   148 /**
       
   149 Return array of TInetAddressInfo objects as the response of GetOptions call.
       
   150 @publishedAll
       
   151 @released
       
   152 */
       
   153 const TUint KSoInetAddressInfo = 0x1002;
       
   154 
       
   155 /**
       
   156 Return array of TInetRouteInfo objects as the response of GetOptions call.
       
   157 @publishedAll
       
   158 @released
       
   159 */
       
   160 const TUint KSoInetRouteInfo = 0x1003;
       
   161 
       
   162 /**
       
   163 Information of an address attached to interface.
       
   164 Used by the event service (EClassAddress events) and KSoInetAddressInfo socket option.
       
   165 @publishedAll
       
   166 @released
       
   167 */
       
   168 class TInetAddressInfo
       
   169 	{
       
   170 public:
       
   171 	TUint32	    iInterface;	    //< Network interface index to which this address is bound.
       
   172 	TIp6Addr    iAddress;	    //< Prefix or Id part of the address described.
       
   173 	TUint8	    iPrefixLen;	    //< Length of the prefix part in bits.
       
   174 	TUint32	    iScopeId;	    //< ScopeId of this address.
       
   175 	TUint32	    iPrefLifetime;  //< Remaining Preferred lifetime of this address.
       
   176 	TUint32	    iValidLifetime; //< Remaining Valid lifetime of this address.
       
   177 	TUint	    iFlags;	    //< Is address entry for prefix or id, etc. See enum TFlags
       
   178 	TUint	    iState;	    //< Address state, copied from TIp6AddressInfo, see enum TAddressState
       
   179 	TUint	    iType;	    //< Address type copied from TIp6AddressInfo, see enum TAddressType
       
   180 	TUint	    iGenerations;   //< Number of times the address Id is generated (or randomly re-generated)
       
   181 	TUint	    iNS;	    //< Number of neighbour solicitations sent for DAD.
       
   182 
       
   183 	// Values used in iFlags field.
       
   184 	enum TFlags
       
   185 		{
       
   186 	    EF_Prefix = 0x1,	//< This address entry specifies prefix
       
   187 	    EF_Id = 0x2,    	//< This address entry specifies id part of the address
       
   188 	    EF_Deprecated = 0x4 //< Address is deprecated
       
   189 		};
       
   190 
       
   191 	// Values used in iState field. The field is directly copied from iface.cpp.
       
   192 	enum TAddressState
       
   193 		{
       
   194 	    ENoAddress	= 0,	//< 0 0 - unassigned initial state (no address present)
       
   195 	    EDuplicate	= 1,	//< 0 1 - address is duplicate
       
   196 	    EAssigned	= 2,	//< 1 0 - address fully available
       
   197 	    ETentative	= 3	//< 1 1 - address is tentative (DAD in progress)
       
   198 		};
       
   199 
       
   200 	// Values used in iType field. The field is directly copied from iface.cpp.
       
   201 	enum TAddressType
       
   202 		{
       
   203 	    EProxy	= 2,	//< Do DAD, is not for me (forward)
       
   204 	    EAnycast	= 1,	//< Don't do DAD, is for me address
       
   205 	    ENormal	= 0	//< Do DAD, is for me
       
   206 		};
       
   207 	};
       
   208 
       
   209 
       
   210 /**
       
   211 Information of a network interface.
       
   212 Used by event service (EClassInterface events) and KSoInetInterfaceInfo socket option.
       
   213 @publishedAll
       
   214 @released
       
   215 */
       
   216 class TInetInterfaceInfo
       
   217 	{
       
   218 public:
       
   219 	TUint32	    iIndex;
       
   220 	TName	    iName;		//< Interface name
       
   221 	TInt	    iState;		//< State
       
   222 	TInt	    iSMtu;		//< Maximum transmit unit size
       
   223 	TInt	    iRMtu;		//< Maximum receive unit size
       
   224 	TInt	    iSpeedMetric;	//< Metric - bigger is better
       
   225 	TUint	    iFeatures;		//< Feature flags
       
   226 	TSockAddr   iHwAddr;		//< Hardware address
       
   227 
       
   228 	// Possible interface states.
       
   229 	// Can also have negative values when on error state.
       
   230 	enum
       
   231 		{
       
   232 	    IfState_READY   = 0,  //< Ready to receive data from protocol
       
   233 	    IfState_PENDING = 1,  //< Not ready for data yet
       
   234 	    IfState_HOLD    = 2
       
   235 		};
       
   236 	};
       
   237 
       
   238 
       
   239 /**
       
   240 Information of a route entry in IP stack.
       
   241 Used by event service (EClassRoute events) and KSoInetRouteInfo socket option.
       
   242 @publishedAll
       
   243 @released
       
   244 */
       
   245 class TInetRouteInfo
       
   246 	{
       
   247 public:
       
   248 	TUint32	    iIndex;	//< Route index
       
   249 	TUint	    iType;	//< Type of route (kernel generated have 0 at the present)
       
   250 	TUint	    iState;	//< State of route (copied from iState in CIp6Route)
       
   251 	TInt	    iMetric;	//< Smaller is better (less hops and/or faster link)
       
   252 	TUint32	    iInterface; //< Network interface index of the route
       
   253 	TIp6Addr    iGateway;	//< IP address of gateway (might be the interface)
       
   254 	TIp6Addr    iDstAddr;	//< Destination network or host
       
   255 	TUint8	    iPrefixLen;	//< Length of the route prefix in bits
       
   256 	TUint32	    iScopeId;	//< Scope Id of this route
       
   257 	TUint32	    iLifetime;  //< Route lifetime in seconds
       
   258 
       
   259 	enum
       
   260 		{ 
       
   261 		EDeprecated = 0x80000000	//< This bit is set in iType if the route is deprecated
       
   262 		};
       
   263 
       
   264 	// Values used in iState field
       
   265 	enum TState
       
   266 	  	{
       
   267 	    EIncomplete = 0,
       
   268 	    ELoopback = 1,
       
   269 	    EOnlink = 2,
       
   270 	    EGateway = 3,
       
   271 	    EAnycast = 5,
       
   272 	    ERedirect = 7,
       
   273 	    EReachable = 8,
       
   274 	    EStale = 16
       
   275 	 	 };
       
   276 	};
       
   277 	
       
   278 
       
   279 /**
       
   280 Information on a neighbour cache entry in the IP stack.
       
   281 Used by event service (EClassNeighbour events).
       
   282 @publishedAll
       
   283 @released
       
   284 */
       
   285 class TInetNeighbourInfo
       
   286 	{
       
   287 public:
       
   288 	TUint32	    iIndex;		//< Route index.
       
   289 	TIp6Addr    iDstAddr;	//< Neighbour's IP address.
       
   290 	TUint	    iState;		//< State of neigbour entry. @see TInetRouteInfo::TState.
       
   291 	TInt	    iMetric;	//< Smaller is better (less hops and/or faster link).
       
   292 	TUint32	    iInterface; //< Network interface index of the route.
       
   293 	TUint32	    iScopeId;	//< Scope Id of this neighbour.
       
   294 	TUint32	    iLifetime;  //< Cache entry lifetime in seconds.
       
   295 
       
   296 	// Hardware address (e.g. Ethernet MAC).
       
   297 	TBuf8<KMaxSockAddrSize>	iHwAddr;
       
   298 	};
       
   299 
       
   300 
       
   301 /**
       
   302 For building an array on top of TDes8. This is like casting a TDes8 data pointer to an array, but
       
   303 it provides protection against array boundary violations, and some small helpful utilities.
       
   304 The motivation of this class is to help in handling the information accessed by MNetworkInfo
       
   305 interface.
       
   306 @publishedAll
       
   307 @released
       
   308 */
       
   309 template<class T> class TOverlayArray
       
   310 	{
       
   311 public:
       
   312 	inline TOverlayArray(TDes8& aDes) : iDes(aDes)
       
   313 	{ }
       
   314 
       
   315 	/**
       
   316 	* Returns pointer to the given element location in the array. If the index exceeds the
       
   317 	* maximum length of the array, NULL is returned.
       
   318 	*/
       
   319 	inline T* IndexPtr(TInt aIndex)
       
   320 	{ if (aIndex >= MaxLength()) return NULL; else return &((T*)iDes.Ptr())[aIndex]; }
       
   321 
       
   322 	/**
       
   323 	* Return the given element of the array. No boundary checking.
       
   324 	*/
       
   325 	inline T& operator[](TInt aIndex)
       
   326 	{ return ((T*)iDes.Ptr())[aIndex]; }
       
   327 
       
   328 	/**
       
   329 	* Returns the maximum length of the array in the number of array elements.
       
   330 	*/
       
   331 	inline TInt MaxLength()
       
   332 	{ return (iDes.MaxLength() / sizeof(T)); }
       
   333 
       
   334 	/**
       
   335 	* Returns the current length of the array in the number of array elements.
       
   336 	* The length information is based
       
   337 	* on the current underlaying descriptor length, which may not always be the desired result.
       
   338 	*/
       
   339 	inline TInt Length()
       
   340 	{ return (iDes.Length() / sizeof(T)); }
       
   341 
       
   342 	/**
       
   343 	* Set the length of the underlaying descriptor. The parameter is given in the number of array
       
   344 	* elements, which is then multiplied by a length of one element to determine the needed
       
   345 	* descriptor length.
       
   346 	*/
       
   347 	inline void SetLength(TInt aLength)
       
   348 	{ iDes.SetLength(aLength * sizeof(T)); }
       
   349 
       
   350 private:
       
   351 	TDes8&	  iDes;
       
   352 	};
       
   353 
       
   354 
       
   355 /**
       
   356 Information of a multicast group joined by the IP stack. This class is not currently
       
   357 used by socket options, only EClassMulticast events.
       
   358 @publishedAll
       
   359 @released
       
   360 */
       
   361 class TInetMulticastInfo
       
   362 	{
       
   363 public:
       
   364 	TIp6Addr	iMulticastGroup;	//< IP address of the multicast group.
       
   365 	TUint32		iInterface;		//< Interface index of the group.
       
   366 	TUint32		iLifetime;		//< Lifetime of the group in seconds.
       
   367 	};
       
   368 
       
   369 
       
   370 // -- Socket option level: KSolInetIfCtrl --
       
   371 
       
   372 /**
       
   373 Control the use of link-local addresses per interface.
       
   374 Argument: TSoInetIpv4LinkLocalInfo  (SetOpt only).
       
   375 @publishedAll
       
   376 @released
       
   377 
       
   378 @capability ECapabilityNetworkControl Configuring IPv4 Link-local addresses is restricted.
       
   379 @ref RSocket::SetOpt()
       
   380 */
       
   381 const TUint KSoIpv4LinkLocal = 0x1001;
       
   382 
       
   383 /**
       
   384 Used as a parameter in KSoIpv4LinkLocal.
       
   385 @publishedAll
       
   386 @released
       
   387 */
       
   388 class TSoInetIpv4LinkLocalInfo
       
   389 	{
       
   390 public:
       
   391 	TUint	iInterface;		//< Interface index to be affected.
       
   392 	TUint	iFlag;			//< Indicates whether IPv4 link locals are used  (0='no'; 1='yes').
       
   393 	};
       
   394 
       
   395 #endif  // __INSOCK_IN6_ROUTE_H__