wlan_bearer/wlanengine/wlan_common/wlanengine_common_3.1/inc/core_tools.h
changeset 0 c40eb8fe8501
equal deleted inserted replaced
-1:000000000000 0:c40eb8fe8501
       
     1 /*
       
     2 * Copyright (c) 2002-2009 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:  Simple utility functions for core
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef CORE_TOOLS_H
       
    20 #define CORE_TOOLS_H
       
    21 
       
    22 #include "am_platform_libraries.h"
       
    23 #include "core_types.h"
       
    24 #include "core_iap_data.h"
       
    25 #include "core_ap_data.h"
       
    26 #include "genscanlist.h"
       
    27 
       
    28 /**
       
    29 * core_tools_c offers generic utilities
       
    30 *
       
    31 * @lib wlmserversrv.lib
       
    32 * @since Series 60 3.0
       
    33 */
       
    34 NONSHARABLE_CLASS(core_tools_c)
       
    35     {
       
    36     public: // New functions
       
    37 
       
    38         /**
       
    39         * compares two arrays of data
       
    40         * @param pl Pointer to parameter1 data.
       
    41         * @param ll Length of parameter1 data.
       
    42         * @param pr Pointer to parameter2 data.
       
    43         * @param rl Length of parameter2 data.
       
    44         * @return 0 if data is same or similar
       
    45         *         !0 if data is not similar
       
    46         */        
       
    47         static int_t compare(
       
    48             const u8_t* pl,
       
    49             int_t ll, 
       
    50             const u8_t* pr, 
       
    51             int_t rl );
       
    52 
       
    53         /**
       
    54         * copies data from source buffer to target buffer
       
    55         * @param trg Pointer to target buffer.
       
    56         * @param src Pointer to source buffer.
       
    57         * @param len Length of data to copy in bytes.
       
    58         * @return pointer to end of target
       
    59         */
       
    60         static u8_t* copy(
       
    61             void* trg,
       
    62             const void* src,
       
    63             int_t len );
       
    64 
       
    65         /**
       
    66         * fills buffer with zeroes
       
    67         * @param trg Pointer to buffer.
       
    68         * @param len Length of buffer in bytes.
       
    69         */
       
    70         static void fillz(
       
    71             void* trg, 
       
    72             int_t len );
       
    73 
       
    74         /**
       
    75          * Convert the given parameter to big-endian order.
       
    76          * @param source integer
       
    77          * @return converted integer
       
    78          */
       
    79         static u16_t convert_host_to_big_endian(
       
    80             u16_t src );
       
    81 
       
    82         /**
       
    83          * Convert the given parameter to big-endian order.
       
    84          * @param source integer
       
    85          * @return converted integer
       
    86          */           
       
    87         static u32_t convert_host_to_big_endian(
       
    88             u32_t src );
       
    89 
       
    90         /**
       
    91          * Convert the given parameter to big-endian order.
       
    92          * @param source integer
       
    93          * @return converted integer
       
    94          */
       
    95         static u16_t convert_big_endian_to_host(
       
    96             u16_t src );
       
    97             
       
    98         /**
       
    99          * Convert the given parameter to big-endian order.
       
   100          * @param source integer
       
   101          * @return converted integer
       
   102          */
       
   103         static u32_t convert_big_endian_to_host(
       
   104             u32_t src );
       
   105             
       
   106         /**
       
   107          * Return a big endian word from the given buffer index in host order.
       
   108          *
       
   109          * @since S60 v3.1
       
   110          * @param pointer to data
       
   111          * @param index in the buffer
       
   112          * @return A word from the given buffer index in host order.
       
   113          */    
       
   114         static u16_t get_u16_big_endian(
       
   115             const u8_t* data,
       
   116             u16_t index );                    
       
   117 
       
   118         /**
       
   119          * Return a host order word from the given buffer index.
       
   120          *
       
   121          * @since S60 v3.1
       
   122          * @param pointer to data
       
   123          * @param index in the buffer
       
   124          * @return A word from the given buffer index in host order.
       
   125          */    
       
   126         static u16_t get_u16(
       
   127             const u8_t* data,
       
   128             u16_t index );
       
   129 
       
   130         /**
       
   131          * Return a big endian long word from the given buffer index in host order.
       
   132          *
       
   133          * @since S60 v3.1
       
   134          * @param pointer to data
       
   135          * @param index in the buffer
       
   136          * @return A long word from the given buffer index in host order.
       
   137          */
       
   138         static u32_t get_u32_big_endian(
       
   139             const u8_t* data,
       
   140             u16_t index );          
       
   141 
       
   142         /**
       
   143          * Return a host order from the given buffer index.
       
   144          *
       
   145          * @since S60 v3.1
       
   146          * @param pointer to data
       
   147          * @param index in the buffer
       
   148          * @return A long word from the given buffer index in host order.
       
   149          */
       
   150         static u32_t get_u32(
       
   151             const u8_t* data,
       
   152             u16_t index ); 
       
   153 
       
   154         /**
       
   155          * Return a host order from the given buffer index.
       
   156          *
       
   157          * @since S60 v5.2
       
   158          * @param pointer to data
       
   159          * @param index in the buffer
       
   160          * @return A quadruple word from the given buffer index in host order.
       
   161          */
       
   162         static u64_t get_u64(
       
   163             const u8_t* data,
       
   164             u16_t index ); 
       
   165 
       
   166         /**
       
   167          * Insert a big endian u16_t to the given buffer index.
       
   168          *
       
   169          * @since S60 v3.2
       
   170          * @param data Pointer to the buffer.
       
   171          * @param index Index in the buffer.
       
   172          * @param value Data be to appended.
       
   173          */
       
   174         static void insert_u16_big_endian(
       
   175             u8_t* data,
       
   176             u16_t index,
       
   177             u16_t value );
       
   178 
       
   179         /**
       
   180          * Insert a host order u16_t to the given buffer index.
       
   181          *
       
   182          * @since S60 v3.2
       
   183          * @param data Pointer to the buffer.
       
   184          * @param index Index in the buffer.
       
   185          * @param value Data be to appended.
       
   186          */
       
   187         static void insert_u16(
       
   188             u8_t* data,
       
   189             u16_t index,
       
   190             u16_t value );
       
   191 
       
   192         /**
       
   193          * Insert a big endian u32_t to the given buffer index.
       
   194          *
       
   195          * @since S60 v3.2
       
   196          * @param data Pointer to the buffer.
       
   197          * @param index Index in the buffer.
       
   198          * @param value Data be to appended.
       
   199          */
       
   200         static void insert_u32_big_endian(
       
   201             u8_t* data,
       
   202             u16_t index,
       
   203             u32_t value );
       
   204 
       
   205         /**
       
   206          * Insert a host order u32_t to the given buffer index.
       
   207          *
       
   208          * @since S60 v3.2
       
   209          * @param data Pointer to the buffer.
       
   210          * @param index Index in the buffer.
       
   211          * @param value Data be to appended.
       
   212          */
       
   213         static void insert_u32(
       
   214             u8_t* data,
       
   215             u16_t index,
       
   216             u32_t value );
       
   217 
       
   218         /**
       
   219          * Append a big endian u16_t to the given buffer.
       
   220          *
       
   221          * @since S60 v3.2
       
   222          * @param data Pointer to the buffer.
       
   223          * @param data_length Current buffer length.
       
   224          * @param value Data be to appended.
       
   225          */
       
   226         static void append_u16_big_endian(
       
   227             u8_t* data,
       
   228             u16_t& data_length,
       
   229             u16_t value );            
       
   230 
       
   231         /**
       
   232          * Append a host order u16_t to the given buffer.
       
   233          *
       
   234          * @since S60 v3.2
       
   235          * @param data Pointer to the buffer.
       
   236          * @param data_length Current buffer length.
       
   237          * @param value Data be to appended.
       
   238          */
       
   239         static void append_u16(
       
   240             u8_t* data,
       
   241             u16_t& data_length,
       
   242             u16_t value );
       
   243 
       
   244         /**
       
   245          * Append a big endian u32_t to the given buffer.
       
   246          *
       
   247          * @since S60 v3.2
       
   248          * @param data Pointer to the buffer.
       
   249          * @param data_length Current buffer length.
       
   250          * @param value Data be to appended.
       
   251          */
       
   252         static void append_u32_big_endian(
       
   253             u8_t* data,
       
   254             u16_t& data_length,
       
   255             u32_t value );            
       
   256 
       
   257         /**
       
   258          * Append a host order u32_t to the given buffer.
       
   259          *
       
   260          * @since S60 v3.2
       
   261          * @param data Pointer to the buffer.
       
   262          * @param data_length Current buffer length.
       
   263          * @param value Data be to appended.
       
   264          */
       
   265         static void append_u32(
       
   266             u8_t* data,
       
   267             u16_t& data_length,
       
   268             u32_t value );
       
   269 
       
   270         /**
       
   271          * Convert the given cipher suite to matching cipher key type.
       
   272          * 
       
   273          * @since S60 v3.1
       
   274          * @param cipher Cipher suite to convert.
       
   275          * @return The type of the cipher key. 
       
   276          */        
       
   277         static core_cipher_key_type_e cipher_key_type(
       
   278             core_cipher_suite_e cipher );
       
   279 
       
   280         /**
       
   281          * Determine the type of the cipher key from the given parameters.
       
   282          *
       
   283          * @since S60 v3.1
       
   284          * @param type Type of the key reported by EAPOL.
       
   285          * @param pairwise_cipher The currently used pairwise cipher.
       
   286          * @param group_cipher The currently used group cipher.
       
   287          * @return The type of the cipher key.
       
   288          */
       
   289         static core_cipher_key_type_e cipher_key_type(
       
   290             wlan_eapol_if_eapol_key_type_e type,
       
   291             core_cipher_suite_e pairwise_cipher,
       
   292             core_cipher_suite_e group_cipher );            
       
   293 
       
   294         /**
       
   295          * Determine the EAPOL authentication type from the given parameters.
       
   296          *
       
   297          * @since S60 v3.1
       
   298          * @param iap_data Information about the used IAP.         
       
   299          * @param ap_data Information about the used AP.
       
   300          * @retun The authentication type.
       
   301          */        
       
   302         static wlan_eapol_if_eapol_key_authentication_type_e eap_authentication_type(
       
   303             const core_iap_data_c& iap_data,
       
   304             const core_ap_data_c& ap_data );
       
   305 
       
   306         /**
       
   307          * Convert the given cipher suite to the EAPOL equivalent.
       
   308          *
       
   309          * @since S60 v3.1
       
   310          * @param cipher Cipher suite to convert.
       
   311          * @return The converted cipher suite.
       
   312          */
       
   313         static wlan_eapol_if_rsna_cipher_e eapol_cipher(
       
   314             core_cipher_suite_e cipher );
       
   315 
       
   316         /**
       
   317          * Add the given beacon to the scan list.
       
   318          *
       
   319          * @since S60 v3.1
       
   320          * @param scan_list Scan list where the beacon is added.
       
   321          * @param ap_data Beacon to be added.
       
   322          * @param rcpi RCPI value of the beacon.
       
   323          */
       
   324         static void add_beacon_to_scan_list(
       
   325             ScanList& scan_list,
       
   326             const core_ap_data_c& ap_data,
       
   327             u32_t rcpi );            
       
   328 
       
   329         /**
       
   330          * Convert the given user priority value to an access class.
       
   331          *
       
   332          * @since S60 v3.1
       
   333          * @param user_priority User priority value to be converted.
       
   334          * @return The corresponding access class.
       
   335          */
       
   336         static core_access_class_e convert_user_priority_to_ac(
       
   337             u8_t user_priority );
       
   338 
       
   339         /**
       
   340          * Convert the given access class to an user priority value.
       
   341          *
       
   342          * @since S60 v3.2
       
   343          * @param access_class Access class to be converted
       
   344          * @return The corresponding user priority value.
       
   345          */
       
   346         static u8_t convert_ac_to_user_priority(
       
   347             core_access_class_e access_class );
       
   348 
       
   349         /**
       
   350          * Convert the given tx rate value (500kbit/s per unit) to a corresponding enum.
       
   351          *
       
   352          * @since S60 v3.2
       
   353          * @param tx_rate Tx rate value to be converted.
       
   354          * @return Corresponding tx rate enum.
       
   355          */
       
   356         static core_tx_rate_e convert_tx_rate_to_tx_rate_enum(
       
   357             u8_t tx_rate );
       
   358 
       
   359         /**
       
   360          * Convert the given tx rate enum to a corresponding tx rate value (500kbit/s per unit).
       
   361          *
       
   362          * @since S60 v3.2
       
   363          * @param tx_rate Tx rate enum to be converted.
       
   364          * @return Corresponding rx rate value.
       
   365          */
       
   366         static u8_t convert_tx_rate_enum_to_tx_rate(
       
   367             core_tx_rate_e tx_rate );
       
   368 
       
   369         /**
       
   370          * Return the highest tx rate defined.
       
   371          *
       
   372          * @since S60 v3.2
       
   373          * @param tx_rates Bitmask of tx rates.
       
   374          * @return The highest tx rate defined.
       
   375          */
       
   376         static core_tx_rate_e highest_tx_rate(
       
   377             u32_t tx_rates );
       
   378 
       
   379         /**
       
   380          * Convert the tx rates to a tx policy.
       
   381          *
       
   382          * @since S60 v3.2
       
   383          * @param tx_rates Bitmask of tx rates.
       
   384          * @return Corresponding tx rate policy.
       
   385          */
       
   386         static core_tx_rate_policy_s convert_tx_rates_to_tx_policy(
       
   387             u32_t tx_rates );
       
   388 
       
   389         /**
       
   390          * Determine the security mode from the given parameters.
       
   391          *
       
   392          * @since S60 v3.2
       
   393          * @param iap_data Information about the used IAP.
       
   394          * @param ap_data Information about the used AP.
       
   395          * @retun The security mode.
       
   396          */        
       
   397         static core_connection_security_mode_e security_mode(
       
   398             const core_iap_data_c& iap_data,
       
   399             const core_ap_data_c& ap_data );
       
   400 
       
   401         /**
       
   402          * Convert an EAPOL error code to the the corresponding
       
   403          * protected setup error code.
       
   404          *
       
   405          * @since S60 v3.2
       
   406          * @param error EAPOL error code.
       
   407          * @return The corresponding protected setup status code.
       
   408          */
       
   409          static core_protected_setup_status_e convert_eapol_error_to_protected_setup_status(
       
   410              const wlan_eapol_if_eap_status_e error );
       
   411 
       
   412          /**
       
   413           * Check which WLAN region the country information received from AP matches.
       
   414           * @since S60 5.0
       
   415           * @param found_country Country information received from AP.
       
   416           * @return WLAN region converted from the country information.
       
   417           */  
       
   418          static core_wlan_region_e convert_country_to_region(
       
   419          	    const core_country_string_s& found_country );
       
   420          
       
   421     
       
   422     };
       
   423 
       
   424 #include "core_tools.inl"
       
   425 
       
   426 #endif // CORE_TOOLS_H