epoc32/include/in6_if.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
parent 2 2fe1408b6811
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
     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_if.h - control API between the stack and IPv6 interfaces
    15 // Specifies the IPv6 extensions for CNifIfBase::Control() API
    16 // defined in the standard EPOC header file in_iface.h.
    17 //
    18 
    19 
    20 
    21 /**
    22  @file in6_if.h
    23  @publishedAll
    24  @released
    25 */
    26 
    27 #ifndef __IN6_IF_H__
    28 #define __IN6_IF_H__
    29 
    30 #include <e32std.h>
    31 #include <in_sock.h>
    32 
    33 //	CNifIfBase::Control(aLevel, aName, aOption, ..)
    34 //  aLevel is KSOLInterface defined in in_iface.h in standard EPOC
    35 
    36 //	IPv6 specific aName constants and aOption structures
    37 
    38 /**
    39 * Option to get the current network interface driver operation parameters to 
    40 * the passed TSoIfInfo6 structure. 
    41 * @since v7.0
    42 * @publishedAll
    43 * @released
    44 */
    45 const TUint KSoIfInfo6	= 0x202;
    46 
    47 
    48 /**
    49 * Incoming RMBufPktInfo iFlag value for a loopback packet.
    50 *
    51 * The stack sets this flag for a packet, which is looped
    52 * back by a call to IP layer Process function. A NIF should
    53 * never set this flag.
    54 *
    55 * This flag is effective only when capabilities are enabled.
    56 * A packet with this flag set can be delivered to sockets
    57 * that do not posses NetworkServices cabability.
    58 */
    59 const TUint KIpLoopbackPacket = 0x1;
    60 /**
    61 * Incoming and outgoing RMBufPktInfo iFlag value for broadcast packet.
    62 *
    63 * The packet uses link layer broadcast. The stack sets this bit for
    64 * outgoing packets that are not unicast (e.g. multicast and broadcast
    65 * destinations). A NIF can set this flag for incoming packet, if it
    66 * was sent to a link layer broadcast address. The presence of this
    67 * flag suppresses some error replies from the stack.
    68 */
    69 const TUint KIpBroadcastOnLink = 0x2;
    70 
    71 
    72 /**
    73 * A TSoIfInfo::iFeatures flag to indicate that the interface requires Neighbour 
    74 * Discovery.
    75 *
    76 * @note
    77 *	For IPv4 this enables ARP for the interface. The NIF must
    78 *	pass received ARP packets to the stack, and accept ARP
    79 *	packets for sending from the stack.
    80 * @since v7.0
    81 * @publishedAll
    82 * @released
    83 */
    84 const TUint KIfNeedsND	= 0x00000100;
    85 
    86 const TUint KMaxInterfaceName=32;
    87 
    88 /** 
    89  * Holds the name of a network interface. 
    90  * 
    91  * This is used in TSoIfInfo. 
    92  * 
    93  */
    94 typedef TBuf<KMaxInterfaceName> TInterfaceName;
    95 
    96 class TSoIfInfo
    97 // Socket option structure for KSoIfInfo
    98 /** 
    99  * Current network interface operation parameters.
   100  * 
   101  * It is returned by RSocket::GetOpt(), when that function is called with anOptionLevel 
   102  * set to KSOLInterface and anOptionName set to KSoIfInfo. 
   103  *
   104  */
   105 	{
   106 public:
   107 	/** Feature flags. Possible values are defined in in_iface.h. */
   108 	TUint iFeatures;		// Feature flags
   109 	/** Maximum transmission unit. */
   110 	TInt iMtu;				// Max frame size
   111 	/** An approximation of the interface speed in Kbps. */
   112 	TInt iSpeedMetric;		// Indication of performance, approx to Kbps
   113 	/** Interface protocol name, ipcp::\<port\>. */
   114 	TInterfaceName iName;
   115 	};
   116 
   117 
   118 class TSoIfInfo6 : public TSoIfInfo		// aOption when aName == KSoIfInfo
   119 	/**
   120 	* Extends the TSoIfInfo for the receive MTU.
   121 	*
   122 	* The IPv6 capable interfaces must support this control option. The usage
   123 	* template in the stack is:
   124 @code
   125 	CNifIfBase *iNif;
   126 	...
   127 	TPckgBuf<TSoIfInfo6> ifProp;
   128 	TInt err = iNif->Control(KSOLInterface, KSoIfInfo6, ifProp);
   129 @endcode
   130 	* For the IPv4 interfaces, only the plain TSoIfInfo is used.
   131 @code
   132 	CNifIfBase *iNif;
   133 	...
   134 	TPckgBuf<TSoIfInfo> ifProp;
   135 	TInt err = iNif->Control(KSOLInterface, KSoIfInfo, ifProp);
   136 @endcode
   137 	* @since v7.0
   138 	* @publishedAll
   139 	* @released
   140 	*/
   141 	{
   142 public:
   143 	/** Maximum transmission unit for receiving. */
   144 	TInt iRMtu;
   145 	};
   146 
   147 class TSoIfConfigBase
   148 /** 
   149  * Base class for TSoInetIfConfig, which simply identifies the protocol family 
   150  * using the interface. 
   151  *
   152  * @internalComponent
   153  */
   154 	{
   155 public:
   156 	/** The protocol family, e.g. KAfInet. */
   157 	TUint iFamily;
   158 	};
   159 
   160 class TSoInet6IfConfig : public TSoIfConfigBase
   161 	/**
   162 	* IPv6 interface configuration.
   163 	*
   164 	* This is the option when stack queries the interface configuration
   165 	* information using
   166 @code
   167 	TPckgBuf<TSoInet6IfConfig> cfg;
   168 	cfg().iFamily = KAfInet6;	// Query about IPv6 capability
   169 	TInt res = iNif->Control(KSOLInterface, KSoIfConfig, cfg);
   170 @endcode
   171 	* The KErrNone return signifies that this NIF supports IPv6 on the
   172 	* link layer. Note, similarly, the IPv4 support is detected by the
   173 	* stack using:
   174 @code
   175 	TPckgBuf<TSoInetIfConfig> cfg;
   176 	cfg().iFamily = KAfInet;	// Query about IPv4 capability.
   177 	TInt res = iNif->Control(KSOLInterface, KSoIfConfig, cfg);
   178 @endcode
   179 	* The same NIF can support both IPv4 and IPv6.
   180 	*
   181 	* @since v7.0
   182 	* @publishedAll
   183 	* @released
   184 	*/
   185 	{
   186 public:	
   187 	/**
   188 	* The local interface id.
   189 	*
   190 	* If the address family is not KAFUnspec, then this defines the id portion of
   191 	* the IPv6 addresses for this host. The id portion is used in constructing the
   192 	* link-local address (fe80::id) and combined with any other prefixes, which
   193 	* are configured for this interface (prefix::id). Prefixes are configured via
   194 	* Router Advertisement prefix option (TInet6OptionICMP_Prefix) with the A flag
   195 	* set, or using interface control socket options (see TSoInet6InterfaceInfo).
   196 	*
   197 	* The length of the id is determined by the TSockAddr::GetUserLen. The normal
   198 	* value is 8 (e.g. the standard id is always 64 bits). Other id lengths are
   199 	* possibly activated by future RFC's for some special address formats.
   200 	*
   201 	* If the address family is KAFUnspec, then id is not configured (and for the
   202 	* IPv6 interface to be functional, address(es), including the link-local address,
   203 	* must be configured by some other means).
   204 	*/
   205 	TSockAddr iLocalId;
   206 	/**
   207 	* The remote interface id (or KAFUnspec, if not applicaple).
   208 	*
   209 	* If the address family is not KAFUnspec, then this defines the id portion of
   210 	* another host on the link. The stack constructs a link-local address
   211 	* (fe80::remote-id) and installs a host route for it.
   212 	*
   213 	* This might be useful for PPP links, if other end is not acting as a router.
   214 	* If the other end is a router, it's address will become automaticly known,
   215 	* when it sends the Router Advertisement.
   216 	*/
   217 	TSockAddr iRemoteId;
   218 	/**
   219 	* Unused highest significant bits in interface id (usually 0).
   220 	*
   221 	* This is reserved for future use, in case there is a need for id length
   222 	* that is not multiple of 8.
   223 	*/
   224 	TUint idPaddingBits;
   225 	/** 1st DNS address (or Unspecified address, if none) */
   226 	TInetAddr iNameSer1;
   227 	/** 2nd DNS address (or Unspecified address, if none) */
   228 	TInetAddr iNameSer2;
   229 	};
   230 
   231 /**
   232 
   233 @page nif_interface	The interface between a NIF and the TCP/IP stack.
   234 
   235   The network interfaces (NIF's) are registered with the stack using the
   236   MNifIfUser::IfUserNewInterfaceL function. Stack has an internal object that
   237   represents the interface and the given CNifIfBase object is attached to this.
   238 
   239   The stack communicates with the NIF using the public API defined by the CNifIfBase.
   240   The NIF sees the stack as an instance of CProtocolBase and can use a subset of
   241   public functions to communcite with the stack.
   242 
   243   The following CNifBase functions are used by the stack:
   244 
   245 	- CNifIfBase::Open, (binding stack and NIF)
   246 	- CNifIfBase::Close, (binding stack and NIF)
   247 	- CNifIfBase::BindL, (binding stack and NIF)
   248 	- CNifIfBase::Control, (for the configuration information)
   249 	- CNifIfBase::Info, (retrieve the interface name)
   250 	- CNifIfBase::Send, (send outbound packets to NIF)
   251 	- CNifIfBase::Notify, (NIFMAN about packet activity)
   252 
   253   The following CProtocolBase functions are available for NIFs:
   254 
   255 	- CProtocolBase::StartSending, (notify stack that NIF is ready)
   256 	- CProtocolBase::Error, (notify stack about NIF error)
   257 	- CProtocolBase::Process, (feed inbound packets to stack)
   258 
   259   The network interface is removed from the stack either by directly deleting it, or
   260   by NIFMAN using MNifIfUser::IfUserInterfaceDown.
   261 
   262   A pointer to the MNifIfUser object can be obtained from the network
   263   layer protocol.
   264 @code
   265 	MNetworkService *iNetwork;
   266 	TPckgBuf<MNifIfUser*> ifUser;
   267 	TInt err = iNetwork->Protocol()->GetOption(KNifOptLevel, KNifOptGetNifIfUser, ifUser);
   268 @endcode
   269 
   270 
   271 @section nif_binding			Binding the NIF and TCP/IP together
   272 
   273   MNifIfUser::IfUserNewInterfaceL introduces a new network interface (NIF) to the stack.
   274   The introduction consists of the following steps:
   275 
   276   -# retrieve interface info into TNifIfInfo by CNifIfBase::Info function. Stack uses
   277   only the interface name (iName) from this. The name cannot be an empty string.
   278   -# using the name, the stack searches for a matching internal interface object. If
   279   it does not exist, it is created. If there was an existing interface with the same
   280   name, the stack will disconnect that first.
   281   -# the stack gives itself to the new NIF by calling CNifIfBase::BindL.
   282   -# stack does not send any packets to the interface until the NIF has called
   283   CProtocolBase::StartSending at least once.
   284   -# stack executes the interface configuration when the first CProtocolBase::StartSending arrives
   285   after MNifIfUser::IfUserNewInterfaceL. The configuration uses the CNifIfBase::Control function
   286   with different options to retrieve additional information from the NIF.
   287 
   288   MNifIfUser::IfUserInterfaceDown disconnects the NIF from the stack. There is one
   289   exception: if the MNifIfUser::IfUserInterfaceDown aResult parameter has a special
   290   value #KErrLinkConfigChanged, then the internal interface state is only reset to the
   291   exact same state as if interface was just introduced by the
   292   MNifIfUser::IfUserNewInterfaceL, and a reconfiguration occurs when the NIF calls
   293   StartSending.
   294 
   295 @section nif_control_api		The Control API
   296 
   297   The stack requires the NIF to implement a minimal set of #KSOLInterface level
   298   options via it's CNifIfBase::Control API.
   299 
   300 	- at least one of the information options
   301 		- TSoIfInfo6 with #KSoIfInfo6 (for IPv6)
   302 		- TSoIfInfo with #KSoIfInfo (for IPv4)
   303 		.
   304 	- at least one of the configuration options
   305 		- TSoInet6IfConfig (iFamily=#KAfInet6) with #KSoIfConfig
   306 		- TSoInetIfConfig (iFamily=#KAfInet) with #KSoIfConfig
   307 		.
   308 	- TSoIfHardwareAddr with #KSoIfHardwareAddr if the link
   309 	uses hardware addresses (only used #KIfNeedsND is also set.). The returned
   310 	address is used in the neighbor discovery (ICMPv6 ND or ARP for IPv4), and
   311 	in sending packets to NIF, the address family is used to indicate that the
   312 	stack has chosen the destination link layer address (based on the neighbor
   313 	cache).
   314 	- TSoIfConnectionInfo with #KSoIfGetConnectionInfo (for IAP and NET numbers).
   315 	If this is not supported, the stack will assign unique numbers for the
   316 	IAP and NET. The scope vector (zone identifiers) is contructed as follows:
   317 		-# [0] The unique interface index (node local scope id)
   318 		-# [1] IAP number (link scope id)
   319 		-# [2] IAP number (subnet scope id)
   320 		-# [3] NET number
   321 		-# [4] NET number (site local scope id)
   322 		-# [5] NET number
   323 		-# [6] NET number
   324 		-# [7] NET number (organization scope id)
   325 		-# [8] NET number
   326 		-# [9] NET number
   327 		-# [10] NET number
   328 		-# [11] NET number
   329 		-# [12] NET number
   330 		-# [13] NET number (IPv6 global scope)
   331 		-# [14] NET number
   332 		-# [15] NET number (highest, NET id, IPv4 global)
   333 
   334   @note
   335 	To build complete ARP packets in the stack, stack needs to know the hardware
   336 	type value to be used in the packet (see TInet6HeaderArp). This 16 bit value
   337 	is assumed to be in the Port() field of the returned hardware address
   338 	(#KSoIfHardwareAddr). An IPv4 NIF that leaves the ARP to the stack,
   339 	must provide this value (or sniff and fix the outgoing ARP packets).
   340 
   341 @section nif_inbound_packets	Inbound packets from the NIF to stack.
   342 
   343   The NIF feeds the inbound packets to the stack through the CProtocolBase::Process
   344   function (see also MNetworkService::Process). The information block associated
   345   with the packet is RMBufPktInfo and the fields must have been set as follows:
   346 
   347 	- RMBufPktInfo::iSrcAddr, the link layer source address (using the same
   348 	address family as returned with the hardware address control option). If
   349 	the link does not use addresses, then #KAFUnspec should be used.
   350 	- RMBufPktInfo::iDstAddr, the link layer destination address (using the same
   351 	address family as returned with the hardware address control option). If
   352 	the link does not use addresses, then #KAFUnspec should be used.
   353 	- RMBufPktInfo::iProtocol, the type of the packet:
   354 		- #KProtocolInetIp, IPv4 packet
   355 		- #KProtocolInet6Ip, IPv6 packet
   356 		- #KProtocolArp, ARP packet
   357 		.
   358 	- RMBufPktInfo::iLength, the length of the packet in octets
   359 	- RMBufPktInfo::iFlags, should be set to zero (reserved for future use).
   360 
   361 @note
   362 	The stack is relaxed about the checking of iProtocol field, and anything
   363 	else except #KProtocolArp is assumed to be an IP packet. This is potentially
   364 	to changed in future, and NIFs should set the protocol field correctly.
   365 @note
   366 	The link layer addresses in iSrcAddr and iDstAddr are informative. The
   367 	values do not affect the processing of the packet within stack. They are
   368 	made available for the inbound post hooks (CProtocolPosthook).
   369 
   370 @section nif_outbound_packets	Outbound packets from the stack to NIF
   371 
   372   The stack feeds the outbound packets to the NIF through the CNifIfBase::Send
   373   function. The information block associated with the packet follows RMBufPktInfo
   374   and the fields need to be interpreted as follows:
   375 
   376 	- RMBufPktInfo::iSrcAddr, undefined (must be ignored by the NIF).
   377 	The NIF must choose the link layer source address.
   378 	- RMBufPktInfo::iDstAddr, three variants, if link layer addresses are used
   379 		- hardware address, using the same address family as NIF returned
   380 		in harware address control option (TSoIfHardwareAddr ).
   381 		The packet must be sent to this link layer destination.
   382 		- #KAfInet, the address is IPv4 multicast address. and the NIF must
   383 		select a suitable link layer broadcast address as a destination.
   384 		- #KAfInet6, the address is IPv6 multicast address, and the NIF msut
   385 		select a suitable link layer broadcast address as a destination.
   386 		.
   387 	If the NIF does not use link layer addresses, then iDstAddr is also
   388 	undefined (must be ingnored byt the NIF). The link is a point-to-point
   389 	interface.
   390 	- RMBufPktInfo::iProtocol, defines the type of packet
   391 		- #KProtocolInetIp, IPv4 packet
   392 		- #KProtocolInet6Ip, IPv6 packet
   393 		- #KProtocolArp, ARP packet
   394 		.
   395 	- RMBufPktInfo::iLength, the length of the packet in octets.
   396 	- RMBufPktInfo::iFlags, undefined (must be igrnored by the NIF).
   397 
   398   The stack interprets the return value from the CNifIfBase::Send as follows:
   399 
   400   - return 1; the NIF is ready to receive more packets.
   401   - return 0; the NIF is blocked and cannot receive any more packets. The stack
   402   <b>does not send anything</b> to the NIF until it calls CProtocolBase::StartSending.
   403   - return < 0; unspecified, but currently, the error is passed on to
   404   all flows attached to this interface. The stack will continue sending
   405   packets to the interface (no StartSending is required).
   406   - return > 1; unspecified, but currently treated same as return 1.
   407 
   408 */
   409 
   410 #endif