wlan_bearer/wlannwif/inc/WlanProto.h
changeset 0 c40eb8fe8501
equal deleted inserted replaced
-1:000000000000 0:c40eb8fe8501
       
     1 /*
       
     2 * Copyright (c) 2002-2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Protocol definitions
       
    15 *
       
    16 */
       
    17 
       
    18 /*
       
    19 * %version: 8 %
       
    20 */
       
    21 
       
    22 #ifndef __WLANPROTO_H__
       
    23 #define __WLANPROTO_H__
       
    24 
       
    25 
       
    26 #include "wlmclientserver.h"
       
    27 #include "wlancontrolinterface.h"
       
    28 
       
    29 #include <comms-infras/nifif.h>
       
    30 #include <in_sock.h>
       
    31 
       
    32 #include <comms-infras/ss_subconnflow.h>
       
    33 #include <comms-infras/ss_flowbinders.h>
       
    34 
       
    35 class TLanIp4Provision;
       
    36 class TLanIp6Provision;
       
    37 
       
    38 const TUint KWlannifMajorVersionNumber = 0;
       
    39 const TUint KWlannifMinorVersionNumber = 0;
       
    40 const TUint KWlannifBuildVersionNumber = 0;
       
    41 
       
    42 const TInt KEtherMaxDataLen = 1500;
       
    43 // This should actually be 1492,
       
    44 // but we allow 8 bytes more because at least in WINS we may receive such packets...
       
    45 const TInt KEtherLLCMaxDataLen = 1500; 
       
    46 // Allow 8 bytes more. Some sources say we should allow even more
       
    47 // => change this if needed. (e.g. http://www.cisco.com/warp/public/105/encheat.html:
       
    48 // max length field value 0x5EE (1518))
       
    49 const TInt KEtherLLCMaxLengthFieldValue = 1508; 
       
    50 // I guess this value is ok also for WLAN. 
       
    51 // (Ideally we should ask this from the drivers but there isn't any API for that at the moment.)
       
    52 const TInt KEtherSpeedInKbps = 10000; 
       
    53 const TInt KMinEtherType = 0x0600; // 1536
       
    54 
       
    55 /*******************************************************************************
       
    56 * A quick intro to the Ethernet packet format:
       
    57 *
       
    58 * A plain frame looks like this:
       
    59 * 
       
    60 * struct EtherFrame {
       
    61 *   TUint64 iDestAddr, iSrcAddr;
       
    62 *   TUint16 iType; // ether type, should be >= 1536 (0x0600) (must not conflict with IEEE 802.3 length field)
       
    63 *   TUint8  iData[1500]; // Payload.
       
    64 * };
       
    65 *
       
    66 * iType denotes the type of the payload, 0x0800 denotes IP.
       
    67 *                                        0x0806 denotes ARP.
       
    68 *                                        <= 1500 denotes IEEE 802.3 encapsulation and is interpreted as length
       
    69 * A frame may also contain an extra 'LLC' field which encapsulates the original
       
    70 * payload in a 5 byte header. The LLC field is somewhat complex, but here we
       
    71 * confine ourselves to the LLC-SNAP variant.
       
    72 *
       
    73 * struct EtherLLCFrame {
       
    74 *   TUint64 iDestAddr, iSrcAddr;
       
    75 *   TUint16 iLen; // length, must be <=1500
       
    76 *   TUint8 iDSAP=0xAA; // Which denotes an LLC-SNAP frame.
       
    77 *   TUint8 iSSAP=0xAA; // Which denotes an LLC-SNAP frame.
       
    78 *   TUint8 iCTRL=3;    // Which denotes an LLC-SNAP frame encapsulated by
       
    79 *                      // Ethernet.
       
    80 *   TUint24 OUI=iDstAddr&0xffffff; // 0 is also a valid value.
       
    81 *   TUint16 iType; // The actual iType as described earlier.
       
    82 *   TUint8  iData[1492]; // Payload.
       
    83 * };
       
    84 *
       
    85 *******************************************************************************/
       
    86 
       
    87 _LIT8(KWlanLog, "Wlannwif");
       
    88 
       
    89 const TUint32 KMACByteLength = 6;
       
    90 // Ethernet types (ref. e.g. http://www.iana.org/assignments/ethernet-numbers)
       
    91 const TUint16 KIPFrameType  = 0x0800; // IPv4 ether type
       
    92 const TUint16 KIP6FrameType = 0x86DD; // IPv6 ether type
       
    93 const TUint16 KArpFrameType = 0x0806; // ARP ether type
       
    94 // 802.2 LLC constants
       
    95 const TUint8 KLLC_SNAP_DSAP = 0xAA;
       
    96 const TUint8 KLLC_SNAP_SSAP = 0xAA;
       
    97 const TUint8 KLLC_SNAP_CTRL = 3;
       
    98 
       
    99 // Ethernet header types
       
   100 enum TEtherHeaderType
       
   101     {
       
   102     EStandardEthernet, 
       
   103     ELLCEthernet
       
   104     };
       
   105 
       
   106 const TUint KEtherHeaderSize = 14;
       
   107 const TUint KEtherLLCHeaderSize = KEtherHeaderSize + 8;
       
   108 
       
   109 struct TEtherFrame
       
   110     {
       
   111    TUint16 GetType() { return BigEndian::Get16((TUint8*)&iType); }
       
   112    TUint16 iDestAddr[3];
       
   113    TUint16 iSrcAddr[3];
       
   114    TUint16 iType;
       
   115    TUint8  iData[KEtherMaxDataLen];
       
   116     };
       
   117 
       
   118 struct TEtherLLCFrame
       
   119     {
       
   120     TUint16 GetType() {return(TUint16)((iTypeHi<<8)|iTypeLo);}
       
   121     void SetType(TUint16 aType)
       
   122         {
       
   123         iTypeHi=(TUint8)(aType>>8);
       
   124         iTypeLo=(TUint8)(aType&0xff);
       
   125         }
       
   126     void SetDestAddr( TDesC8& aDest);
       
   127     void SetSrcAddr( TDesC8& aSrc);
       
   128     void SetOUI( TUint32 aOUI);
       
   129     TUint16 iDestAddr[3];
       
   130     TUint16 iSrcAddr[3];
       
   131     union
       
   132         {
       
   133         TUint16 iLen;
       
   134         TUint16 iType;
       
   135         };
       
   136     TUint8 iDSAP;
       
   137     TUint8 iSSAP;
       
   138     TUint8 iCtrl;
       
   139     TUint8 OUI[3];
       
   140     TUint8 iTypeHi;
       
   141     TUint8 iTypeLo;
       
   142     TUint8 iData[KEtherLLCMaxDataLen];
       
   143     };
       
   144 
       
   145 /**
       
   146  * User priority values as defined 802.1D specification.
       
   147  */
       
   148 enum T8021DPriority
       
   149     {
       
   150     E8021DUserPriorityBE    = 0,    // Best Effort
       
   151     E8021DUserPriorityBK1   = 1,    // Background
       
   152     E8021DUserPriorityBK2   = 2,    // Background
       
   153     E8021DUserPriorityEE    = 3,    // Excellent Effort
       
   154     E8021DUserPriorityCL    = 4,    // Controlled Load
       
   155     E8021DUserPriorityVI    = 5,    // Video
       
   156     E8021DUserPriorityVO    = 6,    // Voice
       
   157     E8021DUserPriorityNC    = 7,    // Network Control
       
   158     E8021DUserPriorityMax   = 8     // Defined as the upper bound
       
   159     };
       
   160 
       
   161 /**
       
   162  * Mapping of access classes to the corresponding user priority values.
       
   163  */
       
   164 const T8021DPriority KACtoUP[EWlmAccessClassMax] =
       
   165     {
       
   166     E8021DUserPriorityBE,   // EWlmAccessClassBackground
       
   167     E8021DUserPriorityBK2,  // EWlmAccessClassBestEffort
       
   168     E8021DUserPriorityCL,   // EWlmAccessClassVideo
       
   169     E8021DUserPriorityVO,   // EWlmAccessClassVoice
       
   170     };
       
   171 
       
   172 //forward declaration
       
   173 class CLANNifWLMServerCommon;
       
   174 class CLANNifWLMServerPerAC;
       
   175 class CPcCardPktDrv;
       
   176 class CLanxBearer;
       
   177 
       
   178 typedef CArrayPtrFlat<CLanxBearer> CLanxBearerPtrArray;
       
   179 
       
   180 /**
       
   181 *  CLANLinkCommon
       
   182 */
       
   183 class CLANLinkCommon : public ESock::CSubConnectionFlowBase, public ESock::MFlowBinderControl
       
   184     {   
       
   185     friend class CPktDrvBase;
       
   186 
       
   187 public:
       
   188     enum TAction 
       
   189         {
       
   190         EReconnect,
       
   191         EDisconnect
       
   192         };
       
   193 
       
   194     IMPORT_C static CLANLinkCommon* NewL(ESock::CSubConnectionFlowFactoryBase& aFactory, const Messages::TNodeId& aSubConnId, ESock::CProtocolIntfBase* aProtocolIntf);
       
   195     IMPORT_C CLANLinkCommon(ESock::CSubConnectionFlowFactoryBase& aFactory, const Messages::TNodeId& aSubConnId, ESock::CProtocolIntfBase* aProtocolIntf);
       
   196     IMPORT_C virtual ~CLANLinkCommon();
       
   197     IMPORT_C void ConstructL();
       
   198     
       
   199     // from MFlowBinderControl
       
   200     IMPORT_C virtual ESock::MLowerControl* GetControlL(const TDesC8& aProtocol);
       
   201     IMPORT_C virtual ESock::MLowerDataSender* BindL(const TDesC8& aProtocol, ESock::MUpperDataReceiver* aReceiver, ESock::MUpperControl* aControl);
       
   202     IMPORT_C virtual void Unbind(ESock::MUpperDataReceiver* aReceiver, ESock::MUpperControl* aControl);
       
   203     virtual ESock::CSubConnectionFlowBase* Flow()
       
   204         {
       
   205         return this;
       
   206         }
       
   207     
       
   208     // from MCFNode
       
   209     IMPORT_C virtual void ReceivedL(const Messages::TRuntimeCtxId& aSender, const Messages::TNodeId& aRecipient, Messages::TSignatureBase& aMessage);
       
   210     
       
   211     // Dispatch functions for messages received from SCPR.
       
   212     
       
   213     void StartFlowL();
       
   214     void CancelStartFlow(); 
       
   215     void StopFlow(TInt aError);
       
   216     void SubConnectionGoingDown();
       
   217     void SubConnectionError(TInt aError);
       
   218     void BindToL(Messages::TNodeId& aCommsBinder);
       
   219 
       
   220     void Destroy();
       
   221 
       
   222     // Utility functions for sending messages to SCPR.
       
   223     void PostProgressMessage(TInt aStage, TInt aError);
       
   224     void PostDataClientStartedMessage();
       
   225     void PostFlowDownMessage(TInt aError);
       
   226     void PostFlowGoingDownMessage(TInt aError, MNifIfNotify::TAction aAction);
       
   227     void MaybePostDataClientIdle();
       
   228 
       
   229     // CSubConnectionFlowBase
       
   230     MFlowBinderControl* DoGetBinderControlL()
       
   231         {
       
   232         return this;
       
   233         }
       
   234 
       
   235     void Process( RMBufChain& aPdu, TUint8* aEtherHeader, TUint8 aUPValue );
       
   236     IMPORT_C void ResumeSending(); // Flow Control unblocked
       
   237     IMPORT_C void LinkLayerUp(); // Notify the Protocol that the line is up
       
   238     IMPORT_C void LinkLayerDown(TInt aError, TAction aAction); // Notify the Protocol that the line is down
       
   239     
       
   240     IMPORT_C TInt ReadInt(const TDesC& aField, TUint32& aValue);
       
   241     IMPORT_C TInt WriteInt(const TDesC& aField, TUint32 aValue);
       
   242     IMPORT_C TInt ReadDes(const TDesC& aField, TDes8& aValue);
       
   243     IMPORT_C TInt ReadDes(const TDesC& aField, TDes16& aValue);
       
   244     IMPORT_C TInt WriteDes(const TDesC& aField, const TDesC8& aValue);
       
   245     IMPORT_C TInt WriteDes(const TDesC& aField, const TDesC16& aValue);
       
   246     IMPORT_C TInt ReadBool(const TDesC& aField, TBool& aValue);
       
   247     IMPORT_C TInt WriteBool(const TDesC& aField, TBool aValue);    
       
   248     IMPORT_C void IfProgress(TInt aStage, TInt aError);
       
   249     IMPORT_C void IfProgress(TSubConnectionUniqueId aSubConnectionUniqueId, TInt aStage, TInt aError);
       
   250     IMPORT_C void NifEvent(TNetworkAdaptorEventType aEventType, TUint aEvent, const TDesC8& aEventData, TAny* aSource=0);
       
   251     
       
   252     
       
   253     TUint Mtu() const;
       
   254     TUint SpeedMetric() const {return KEtherSpeedInKbps;}
       
   255 
       
   256     const TBuf8<KMACByteLength>& MacAddress() const;
       
   257 
       
   258     TInt FrameSend(RMBufChain& aPdu, TDesC8& aDestAddr, TUint16 aType );
       
   259     void SetAllowedBearer(CLanxBearer* aBearer);
       
   260     TBool BearerIsActive(CLanxBearer* aBearer);
       
   261 
       
   262 public: // Admission control related functions
       
   263 
       
   264     /**
       
   265      * The traffic mode of an access class has changed.
       
   266      *
       
   267      * @param aAccessClass Access class.
       
   268      * @param aMode Traffic mode of the access class.
       
   269      */
       
   270     void AcTrafficModeChanged(
       
   271         TWlmAccessClass aAccessClass,
       
   272         TWlmAcTrafficMode aMode );
       
   273 
       
   274     /**
       
   275      * The traffic status of an access class has changed.
       
   276      *
       
   277      * @param aAccessClass Access class.
       
   278      * @param aStatus Traffic status of the access class.
       
   279      */
       
   280     void AcTrafficStatusChanged(
       
   281         TWlmAccessClass aAccessClass,
       
   282         TWlmAcTrafficStatus aStatus );
       
   283 
       
   284 private:
       
   285     
       
   286     // Configuration methods
       
   287     TBool ReadMACSettings();
       
   288     void ReadEthintSettingsL();
       
   289 
       
   290     TInt EtherFrame(
       
   291         RMBufChain &aChain,
       
   292         TDesC8& aDestAddr,
       
   293         TUint16 aType,
       
   294         TUint8& aDscp );
       
   295 
       
   296     // checks that the packet driver has returned a valid MAC address,
       
   297     TBool CheckMac( TDes8& aMacAddr ); 
       
   298 
       
   299    
       
   300     TInt GetProtocolType( 
       
   301         TUint8* aEtherHeader, 
       
   302         TUint16& aEtherType );
       
   303 
       
   304     static TInt StopCb(TAny* aThisPtr);
       
   305     void StopInterface();
       
   306 
       
   307     /**
       
   308      * DownGradePacket
       
   309      * @param aUP: downgraded UP value
       
   310      * @param aDrop: sets to ETrue if packet to be dropped 
       
   311      * Downgrades the UP value of the packet if stream is not created. Also decides if packet to be
       
   312      * dropped. This can happen if ACM is set for all traffic streams and TS is not yet created
       
   313      */
       
   314     void DownGradePacket(T8021DPriority& aUP, TBool& aDrop);
       
   315     
       
   316     
       
   317     // Driver management
       
   318     void LoadPacketDriverL();
       
   319 
       
   320     
       
   321     // Search CLanxBearer array by various keys (used in bind/unbind/provisioning)
       
   322     CLanxBearer* FindBearerByProtocolName(const TDesC8& aProtocol, TInt& aIndex) const;
       
   323     CLanxBearer* FindBearerByUpperControl(const ESock::MUpperControl* aUpperControl, TInt& aIndex) const;
       
   324     
       
   325     // Provisioning
       
   326 	void ProvisionConfig(const ESock::RMetaExtensionContainerC& aConfigData);
       
   327     void ProvisionConfigL();
       
   328     void ProvisionBearerConfigL(const TDesC8& aName);
       
   329  
       
   330 protected:
       
   331  
       
   332     CPcCardPktDrv* iPktDrv;
       
   333 
       
   334     /** */
       
   335     TBuf8<KMACByteLength> iMacAddr;
       
   336 
       
   337     /** Handle to the NIF-WLAN engine interface class. */
       
   338 	CLANNifWLMServerCommon* iWLMServerCommon;
       
   339 
       
   340     /** Array containing handles to per-AC instances. */
       
   341 	CLANNifWLMServerPerAC* iAcArray[EWlmAccessClassMax];
       
   342 
       
   343     /** indicates if iMacAddr contains a valid Mac address */
       
   344     TBool iValidMacAddr;
       
   345 
       
   346     enum TlanIfStatus {EIfPending, EIfUp, EIfBusy, EIfDown};
       
   347     /** */
       
   348     TlanIfStatus iState;
       
   349     
       
   350     /** */
       
   351     TEtherHeaderType iEtherType;
       
   352 
       
   353     /** Bearer List */
       
   354     CLanxBearerPtrArray  *iBearers;
       
   355     CLanxBearer          *iOnlyThisBearer;
       
   356     
       
   357     /** iPeriodic and iError needed for sending DHCPRELEASE when the 
       
   358      * interface is being closed
       
   359      */
       
   360     CPeriodic* iPeriodic;
       
   361     
       
   362     // Provisioning related
       
   363     const TLanIp4Provision* iLanIp4Provision;       // ip4 provisioning information from SCPR
       
   364     const TLanIp6Provision* iLanIp6Provision;       // ip6 provisioning information from SCPR
       
   365     TBool iStopRequested;
       
   366 
       
   367     TInt iError;                                    // Saved from StopFlow() argument
       
   368     TInt iSavedError;                               // saved errors from processing TProvisionConfig message
       
   369 
       
   370     enum TMeshMashineFlowState
       
   371         {
       
   372         EStopped,
       
   373         EStarting,
       
   374         EStarted,
       
   375         EStopping,
       
   376         };
       
   377     TMeshMashineFlowState iMMState; 
       
   378 };
       
   379     
       
   380 inline const TBuf8<KMACByteLength>& CLANLinkCommon::MacAddress() const
       
   381 {
       
   382     return iMacAddr;
       
   383 }
       
   384 
       
   385 #endif // __WLANPROTO_H__