voipplugins/dhcppositionprovider/src/dhcpdataresponsepacket.cpp
changeset 0 a4daefaec16c
equal deleted inserted replaced
-1:000000000000 0:a4daefaec16c
       
     1 /*
       
     2 * Copyright (c) 2007 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:  Handle and parse dhcp server response message.
       
    15 *
       
    16 */
       
    17 
       
    18 #include "dhcppsylogging.h"          // For logging
       
    19 #include "dhcpconstants.h"
       
    20 #include "dhcpdataresponsepacket.h"
       
    21 
       
    22 const TInt KLengthOverMCookie = 236;
       
    23 const TInt KDhcpMessageEndOption = 255;
       
    24 
       
    25 // ======== MEMBER FUNCTIONS ========
       
    26 
       
    27 // ---------------------------------------------------------------------------
       
    28 // TDhcpDataResponsePacket
       
    29 // ---------------------------------------------------------------------------
       
    30 //
       
    31 TDhcpDataResponsePacket::TDhcpDataResponsePacket()
       
    32     {
       
    33     iXid = 0;
       
    34     }
       
    35 
       
    36 // ---------------------------------------------------------------------------
       
    37 // Parses the location information part from the DHCPv4 Inform message,
       
    38 // Currently supported Options 123 and 99.
       
    39 // ---------------------------------------------------------------------------
       
    40 //
       
    41 TInt TDhcpDataResponsePacket::ParseDHCPAck ()
       
    42     {
       
    43     TRACESTRING( "TDhcpDataResponsePacket::ParseDHCPAck" );
       
    44     TInt dataFound = KErrNotFound;
       
    45     if (Length() > KLengthOverMCookie)
       
    46         {
       
    47         TPtrC8 magicCookie (KDhcpMagicCookie, sizeof(KDhcpMagicCookie));
       
    48         //Locate the 'magic cookie' after which the option field begins
       
    49         TInt offset = Find( magicCookie );
       
    50         if (offset!=KErrNotFound)
       
    51             {
       
    52             offset += 4; // Skip the cookie
       
    53             while (iBuffer[offset] != KDhcpMessageEndOption )
       
    54                 {
       
    55                 TInt messageOption = iBuffer[offset];
       
    56                 switch (messageOption)
       
    57                     {
       
    58                     case KDhcpMessageGeoSpatialCoordinates:
       
    59                         {
       
    60                         // Parse Option 123
       
    61                         TUint8 dataLength = iBuffer[offset+1];
       
    62                         iGeoConf = Mid( ( offset + 2 ), dataLength );
       
    63                         offset++;
       
    64                         offset += dataLength + 1;
       
    65                         dataFound = KErrNone;
       
    66                         }
       
    67                         break;
       
    68                     case KDhcpMessageCivicAddress:
       
    69                         {
       
    70                         // Parse Option 99
       
    71                         // GeoConfCivic can be of variable length
       
    72                         TUint8 dataLength = iBuffer[offset+1];
       
    73                         iCivicAddress = Mid( ( offset + 2 ), dataLength );
       
    74                         offset++;
       
    75                         offset += dataLength + 1;
       
    76                         dataFound = KErrNone;
       
    77                         }
       
    78                         break;
       
    79                     default:
       
    80                         {
       
    81                         offset++;
       
    82                         offset = offset + (iBuffer[offset]+1) ;
       
    83                         }
       
    84                         break;
       
    85                     }
       
    86                 }
       
    87             }
       
    88         }
       
    89     return dataFound;
       
    90     }
       
    91