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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
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.
33 // CNifIfBase::Control(aLevel, aName, aOption, ..)
34 // aLevel is KSOLInterface defined in in_iface.h in standard EPOC
36 // IPv6 specific aName constants and aOption structures
39 * Option to get the current network interface driver operation parameters to
40 * the passed TSoIfInfo6 structure.
45 const TUint KSoIfInfo6 = 0x202;
49 * Incoming RMBufPktInfo iFlag value for a loopback packet.
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.
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.
59 const TUint KIpLoopbackPacket = 0x1;
61 * Incoming and outgoing RMBufPktInfo iFlag value for broadcast packet.
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.
69 const TUint KIpBroadcastOnLink = 0x2;
73 * A TSoIfInfo::iFeatures flag to indicate that the interface requires Neighbour
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.
84 const TUint KIfNeedsND = 0x00000100;
86 const TUint KMaxInterfaceName=32;
89 * Holds the name of a network interface.
91 * This is used in TSoIfInfo.
94 typedef TBuf<KMaxInterfaceName> TInterfaceName;
97 // Socket option structure for KSoIfInfo
99 * Current network interface operation parameters.
101 * It is returned by RSocket::GetOpt(), when that function is called with anOptionLevel
102 * set to KSOLInterface and anOptionName set to KSoIfInfo.
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;
118 class TSoIfInfo6 : public TSoIfInfo // aOption when aName == KSoIfInfo
120 * Extends the TSoIfInfo for the receive MTU.
122 * The IPv6 capable interfaces must support this control option. The usage
123 * template in the stack is:
127 TPckgBuf<TSoIfInfo6> ifProp;
128 TInt err = iNif->Control(KSOLInterface, KSoIfInfo6, ifProp);
130 * For the IPv4 interfaces, only the plain TSoIfInfo is used.
134 TPckgBuf<TSoIfInfo> ifProp;
135 TInt err = iNif->Control(KSOLInterface, KSoIfInfo, ifProp);
143 /** Maximum transmission unit for receiving. */
147 class TSoIfConfigBase
149 * Base class for TSoInetIfConfig, which simply identifies the protocol family
150 * using the interface.
156 /** The protocol family, e.g. KAfInet. */
160 class TSoInet6IfConfig : public TSoIfConfigBase
162 * IPv6 interface configuration.
164 * This is the option when stack queries the interface configuration
167 TPckgBuf<TSoInet6IfConfig> cfg;
168 cfg().iFamily = KAfInet6; // Query about IPv6 capability
169 TInt res = iNif->Control(KSOLInterface, KSoIfConfig, cfg);
171 * The KErrNone return signifies that this NIF supports IPv6 on the
172 * link layer. Note, similarly, the IPv4 support is detected by the
175 TPckgBuf<TSoInetIfConfig> cfg;
176 cfg().iFamily = KAfInet; // Query about IPv4 capability.
177 TInt res = iNif->Control(KSOLInterface, KSoIfConfig, cfg);
179 * The same NIF can support both IPv4 and IPv6.
188 * The local interface id.
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).
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.
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).
207 * The remote interface id (or KAFUnspec, if not applicaple).
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.
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.
219 * Unused highest significant bits in interface id (usually 0).
221 * This is reserved for future use, in case there is a need for id length
222 * that is not multiple of 8.
225 /** 1st DNS address (or Unspecified address, if none) */
227 /** 2nd DNS address (or Unspecified address, if none) */
233 @page nif_interface The interface between a NIF and the TCP/IP stack.
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.
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.
243 The following CNifBase functions are used by the stack:
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)
253 The following CProtocolBase functions are available for NIFs:
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)
259 The network interface is removed from the stack either by directly deleting it, or
260 by NIFMAN using MNifIfUser::IfUserInterfaceDown.
262 A pointer to the MNifIfUser object can be obtained from the network
265 MNetworkService *iNetwork;
266 TPckgBuf<MNifIfUser*> ifUser;
267 TInt err = iNetwork->Protocol()->GetOption(KNifOptLevel, KNifOptGetNifIfUser, ifUser);
271 @section nif_binding Binding the NIF and TCP/IP together
273 MNifIfUser::IfUserNewInterfaceL introduces a new network interface (NIF) to the stack.
274 The introduction consists of the following steps:
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.
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
295 @section nif_control_api The Control API
297 The stack requires the NIF to implement a minimal set of #KSOLInterface level
298 options via it's CNifIfBase::Control API.
300 - at least one of the information options
301 - TSoIfInfo6 with #KSoIfInfo6 (for IPv6)
302 - TSoIfInfo with #KSoIfInfo (for IPv4)
304 - at least one of the configuration options
305 - TSoInet6IfConfig (iFamily=#KAfInet6) with #KSoIfConfig
306 - TSoInetIfConfig (iFamily=#KAfInet) with #KSoIfConfig
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
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)
321 -# [4] NET number (site local scope id)
324 -# [7] NET number (organization scope id)
330 -# [13] NET number (IPv6 global scope)
332 -# [15] NET number (highest, NET id, IPv4 global)
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).
341 @section nif_inbound_packets Inbound packets from the NIF to stack.
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:
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
358 - RMBufPktInfo::iLength, the length of the packet in octets
359 - RMBufPktInfo::iFlags, should be set to zero (reserved for future use).
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.
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).
370 @section nif_outbound_packets Outbound packets from the stack to NIF
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:
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.
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
390 - RMBufPktInfo::iProtocol, defines the type of packet
391 - #KProtocolInetIp, IPv4 packet
392 - #KProtocolInet6Ip, IPv6 packet
393 - #KProtocolArp, ARP packet
395 - RMBufPktInfo::iLength, the length of the packet in octets.
396 - RMBufPktInfo::iFlags, undefined (must be igrnored by the NIF).
398 The stack interprets the return value from the CNifIfBase::Send as follows:
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.