wlan_bearer/wlanengine/wlan_common/wlanengine_common_3.1/inc/core_frame_ethernet.h
changeset 0 c40eb8fe8501
equal deleted inserted replaced
-1:000000000000 0:c40eb8fe8501
       
     1 /*
       
     2 * Copyright (c) 2006-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 the License "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:  Class for parsing Ethernet frames
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef CORE_FRAME_ETHERNET_H
       
    20 #define CORE_FRAME_ETHERNET_H
       
    21 
       
    22 #include "core_types.h"
       
    23 
       
    24 /**
       
    25  * Class for parsing Ethernet frames.
       
    26  *
       
    27  * @since S60 v3.2
       
    28  */
       
    29 NONSHARABLE_CLASS( core_frame_ethernet_c )
       
    30     {
       
    31 
       
    32 public:
       
    33 
       
    34     /**
       
    35      * Possible values for Ethernet Type field.
       
    36      */
       
    37     enum core_ethernet_type_e
       
    38         {
       
    39         core_ethernet_type_none = 0x0000,
       
    40         core_ethernet_type_ip   = 0x0800,
       
    41         core_ethernet_type_arp  = 0x0806,
       
    42         core_ethernet_type_test = 0x8013
       
    43         };
       
    44 
       
    45     /**
       
    46      * Factory for creating a parser for the given frame.
       
    47      *
       
    48      * @since S60 v3.2
       
    49      * @param data_length Length of the frame.
       
    50      * @param data Pointer to the frame data.
       
    51      * @param is_copied Whether the object should take a copy of the frame data.
       
    52      * @return Pointer to the created parser instance.
       
    53      */
       
    54     static core_frame_ethernet_c* instance(
       
    55         u16_t data_length,
       
    56         const u8_t* data,
       
    57         bool_t is_copied );
       
    58 
       
    59     /**
       
    60      * Factory for creating an Ethernet frame.
       
    61      *
       
    62      * @since S60 v3.2
       
    63      * @param max_data_length The maximum size of the frame.
       
    64      * @param destination The destination MAC field of the frame.
       
    65      * @param source The source MAC field of the frame.
       
    66      * @param type The Ethernet Type field of the frame.
       
    67      * @return Pointer to the created frame instance.
       
    68      */    
       
    69     static core_frame_ethernet_c* instance(
       
    70         u16_t max_data_length,
       
    71         const core_mac_address_s& destination,
       
    72         const core_mac_address_s& source,
       
    73         u16_t type );
       
    74 
       
    75     /**
       
    76      * Destructor.
       
    77      */
       
    78     virtual ~core_frame_ethernet_c();
       
    79 
       
    80     /**
       
    81      * Return the destination MAC field of the frame.
       
    82      *
       
    83      * @since S60 v3.2
       
    84      * @return The destination MAC field of the frame.
       
    85      */
       
    86     core_mac_address_s destination() const;
       
    87 
       
    88     /** 
       
    89      * Return the source MAC field of the frame.
       
    90      *
       
    91      * @since S60 v3.2
       
    92      * @return The source MAC field of the frame.
       
    93      */
       
    94     core_mac_address_s source() const;
       
    95 
       
    96     /**
       
    97      * Return the Ethernet Type field of the frame.
       
    98      *
       
    99      * @since S60 v3.2
       
   100      * @return The Ethernet Type field of the frame.
       
   101      */
       
   102     u16_t type() const;
       
   103 
       
   104     /**
       
   105      * Return the current length of the frame.
       
   106      *
       
   107      * @since S60 v3.1
       
   108      * @return The current length of the frame.
       
   109      */
       
   110     u16_t data_length() const;
       
   111 
       
   112     /**
       
   113      * Return a pointer to the frame data.
       
   114      *
       
   115      * @since S60 v3.1
       
   116      * @return A pointer to the frame data.
       
   117      */    
       
   118     const u8_t* data() const;
       
   119 
       
   120     /**
       
   121      * Return the length of the payload data.
       
   122      *
       
   123      * @since S60 v3.1
       
   124      * @return The length of the payload data.
       
   125      */
       
   126     u16_t payload_data_length() const;
       
   127 
       
   128     /**
       
   129      * Return a pointer to the payload data.
       
   130      *
       
   131      * @since S60 v3.1
       
   132      * @return A pointer to the payload data.
       
   133      */
       
   134     const u8_t* payload_data() const;
       
   135 
       
   136 protected:
       
   137 
       
   138     /**
       
   139      * Return the MAC address field from the given index.
       
   140      *
       
   141      * @param index Index of the MAC address field.
       
   142      * @return The MAC address field from the given index.
       
   143      */
       
   144     core_mac_address_s mac_address(
       
   145         u16_t index ) const;    
       
   146 
       
   147     /**
       
   148      * Generate an Ethernet header.
       
   149      *
       
   150      * @param destination The destination MAC field of the frame.
       
   151      * @param source The source MAC field of the frame.
       
   152      * @param type The Ethernet Type field of the frame.
       
   153      */
       
   154     void generate(
       
   155         const core_mac_address_s& destination,
       
   156         const core_mac_address_s& source,
       
   157         u16_t type );
       
   158 
       
   159     /**
       
   160      * Constructor.
       
   161      *
       
   162      * @param data_length Length of the frame.
       
   163      * @param data Pointer to the frame data.
       
   164      * @param max_data_length The maximum size of the frame buffer.
       
   165      */
       
   166     core_frame_ethernet_c(
       
   167         u16_t data_length,
       
   168         const u8_t* data,
       
   169         u16_t max_data_length );
       
   170 
       
   171 protected: // data
       
   172 
       
   173     /** The length of the frame. */
       
   174     u16_t data_length_m;     
       
   175 
       
   176     /** Pointer to the frame data. */
       
   177     u8_t* data_m;
       
   178 
       
   179     /** The maximum frame length when generating a frame or copying it. */
       
   180     const u16_t max_data_length_m;
       
   181 
       
   182     };
       
   183 
       
   184 #endif // CORE_FRAME_ETHERNET_H