linklayerprotocols/ethernetnif/IRLAN/IRLANBUF.CPP
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 // Started by Mal, August 1997
       
    15 // IrLAN mbuf functions
       
    16 // 
       
    17 //
       
    18 
       
    19 /**
       
    20  @file
       
    21  @internalComponent 
       
    22 */
       
    23 
       
    24 #include <nifman.h>
       
    25 #include <nifvar.h>
       
    26 #include <nifutl.h>
       
    27 #include <es_mbuf.h>
       
    28 #include "IRLANUTL.H"
       
    29 #include "IRLANBUF.H"
       
    30 
       
    31 //#define __TRACEWIN__
       
    32 #ifdef __TRACEWIN__
       
    33   #include <log.h>
       
    34 #else
       
    35   #define LOG(a)
       
    36 #endif
       
    37 
       
    38 /**
       
    39 Sets the command code.
       
    40 @param aCode The Command Code.
       
    41 */
       
    42 void RIrlanControlMBufChain::SetCommandCode(TUint8 aCode)
       
    43 {
       
    44 	*(this->First()->Ptr()+KCommandCodeFieldOffset)=aCode;
       
    45 }
       
    46 
       
    47 /**
       
    48 Get the command code.
       
    49 @return The command code.
       
    50 */
       
    51 TUint8 RIrlanControlMBufChain::GetCommandCode()
       
    52 {
       
    53 	return *(this->First()->Ptr()+KCommandCodeFieldOffset);
       
    54 }
       
    55 
       
    56 /**
       
    57 Sets the command code result.
       
    58 @param aCode The Command Code.
       
    59 */
       
    60 void RIrlanControlMBufChain::SetResultCode(TUint8 aCode)
       
    61 {
       
    62 	*(this->First()->Ptr()+KCommandCodeFieldOffset)=aCode;
       
    63 }
       
    64 
       
    65 /**
       
    66 Gets the Command code result.
       
    67 @param aCode The Command Code.
       
    68 */
       
    69 TUint8 RIrlanControlMBufChain::GetResultCode()
       
    70 {
       
    71 	return *(this->First()->Ptr()+KCommandCodeFieldOffset);
       
    72 }
       
    73 
       
    74 /**
       
    75 Sets the parameter count.
       
    76 @param aCount A parameter count.
       
    77 */
       
    78 void RIrlanControlMBufChain::SetParameterCount(TUint8 aCount)
       
    79 {
       
    80 	*(this->First()->Ptr()+KParameterCountFieldOffset)=aCount;
       
    81 }
       
    82 
       
    83 /**
       
    84 Gets the parameter count.
       
    85 @return The parameter count.
       
    86 */
       
    87 TUint8 RIrlanControlMBufChain::GetParameterCount()
       
    88 {
       
    89 	return *(this->First()->Ptr()+KParameterCountFieldOffset);
       
    90 }
       
    91 
       
    92 /**
       
    93 OK to use TUint8 for name length - it can only be up to 255 in size.
       
    94 Sets the length of the Parameter name.
       
    95 @param aOffset offset.
       
    96 @param aLength Length of the parameter name.
       
    97 */
       
    98 void RIrlanControlMBufChain::SetParameterNameLength(TInt aOffset,TUint8 aLength)
       
    99 {
       
   100 	*(this->First()->Ptr()+KParameterListFieldOffset+aOffset)=aLength;
       
   101 }
       
   102 
       
   103 /**
       
   104 OK to use TUint8 for name length - it can only be up to 255 in size.
       
   105 Gets the length of the parameter name.
       
   106 @param aOffset offset.
       
   107 @return The name length.
       
   108 */
       
   109 TUint8 RIrlanControlMBufChain::GetParameterNameLength(TInt aOffset)
       
   110 {
       
   111 	return *(this->First()->Ptr()+KParameterListFieldOffset+aOffset);
       
   112 }
       
   113 
       
   114 /**
       
   115 Sets the Parameter name.
       
   116 @param aOffset offset.
       
   117 @param aName The parameter name.
       
   118 */
       
   119 void RIrlanControlMBufChain::SetParameterName(TInt aOffset,const TDesC8& aName)
       
   120 {
       
   121 	__ASSERT_DEBUG((TUint)aName.Length()<=KParameterNameMaxSize,IrlanUtil::Panic(EIrlanParameterNameTooBig));
       
   122 	TUint offset=aOffset;
       
   123 	TPtr8 temp((this->First()->Ptr()+KParameterListFieldOffset),
       
   124 		offset,KParameterFrameMaxSize-offset);
       
   125 	temp.Append(aName);
       
   126 }
       
   127 
       
   128 /**
       
   129 Gets the Parameter name.
       
   130 @param aOffset offset.
       
   131 @param aLength The length of the parameter name.
       
   132 @param aName The parameter name.
       
   133 */
       
   134 void RIrlanControlMBufChain::GetParameterName(TInt aOffset,TInt aLength,TDes8& aName)
       
   135 {
       
   136 	__ASSERT_DEBUG((TUint)aLength<=KParameterNameMaxSize,IrlanUtil::Panic(EIrlanParameterNameTooBig));
       
   137 	TUint offset=aOffset;
       
   138 	TPtr8 name((this->First()->Ptr()+offset),aLength,KParameterNameMaxSize);
       
   139 	aName=name;
       
   140 }
       
   141 
       
   142 /**
       
   143 Gets the length of the Parameter value.
       
   144 @param aOffset offset.
       
   145 @return The lenght of the value.
       
   146 */
       
   147 TUint16 RIrlanControlMBufChain::GetParameterValueLength(TInt aOffset)
       
   148 {
       
   149 //	TUint16 val;
       
   150 //	TPtr8 p((TUint8 *)&val,2,4);
       
   151 //	CopyOut(p,aOffset);
       
   152 //	return val;
       
   153 	return LittleEndian::Get16(this->First()->Ptr()+KParameterListFieldOffset+aOffset);
       
   154 }
       
   155 
       
   156 /**
       
   157 Sets the length of the Parameter value.
       
   158 @param aOffset offset.
       
   159 @param aValue  The value of the parameter.
       
   160 */
       
   161 void RIrlanControlMBufChain::SetParameterValueLength(TInt aOffset,TUint16 aValue)
       
   162 {
       
   163 //	TPtr8 val((TUint8 *)&aValue,2,4);
       
   164 //	CopyIn(val,aOffset);
       
   165 	LittleEndian::Put16(this->First()->Ptr()+aOffset+KParameterListFieldOffset,aValue);
       
   166 }
       
   167 
       
   168 /**
       
   169 Sets the Parameter value.
       
   170 @param aOffset offset.
       
   171 @param aValue  The value of the parameter.
       
   172 */
       
   173 void RIrlanControlMBufChain::SetParameterValue(TInt aOffset,const TDesC8& aValue)
       
   174 {
       
   175 	__ASSERT_DEBUG((TUint)aValue.Length()<=KParameterValueMaxSize,IrlanUtil::Panic(EIrlanParameterValueTooBig));
       
   176 	TUint offset=aOffset;
       
   177 	TPtr8 temp((this->First()->Ptr()+KParameterListFieldOffset),
       
   178 		offset,KParameterFrameMaxSize-offset);
       
   179 	temp.Append(aValue);
       
   180 }
       
   181 
       
   182 /**
       
   183 Gets the Parameter value.
       
   184 @param aOffset offset.
       
   185 @param aValue  The value of the parameter.
       
   186 */
       
   187 void RIrlanControlMBufChain::GetParameterValue(TInt aOffset,TInt aLength,TDes8& aValue)
       
   188 {
       
   189 	__ASSERT_DEBUG((TUint)aLength<=KParameterValueMaxSize,IrlanUtil::Panic(EIrlanParameterValueTooBig));
       
   190 	TUint offset=aOffset;
       
   191 	TPtr8 value((this->First()->Ptr()+offset),aLength,KParameterValueMaxSize);
       
   192 	aValue=value;
       
   193 }