TI's CC3100 host driver and demo. Experimental and a work in progress.

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers cc3100_netcfg.h Source File

cc3100_netcfg.h

00001 /*
00002  * netcfg.h - CC31xx/CC32xx Host Driver Implementation
00003  *
00004  * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ 
00005  * 
00006  * 
00007  *  Redistribution and use in source and binary forms, with or without 
00008  *  modification, are permitted provided that the following conditions 
00009  *  are met:
00010  *
00011  *    Redistributions of source code must retain the above copyright 
00012  *    notice, this list of conditions and the following disclaimer.
00013  *
00014  *    Redistributions in binary form must reproduce the above copyright
00015  *    notice, this list of conditions and the following disclaimer in the 
00016  *    documentation and/or other materials provided with the   
00017  *    distribution.
00018  *
00019  *    Neither the name of Texas Instruments Incorporated nor the names of
00020  *    its contributors may be used to endorse or promote products derived
00021  *    from this software without specific prior written permission.
00022  *
00023  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
00024  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
00025  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00026  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
00027  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
00028  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
00029  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00030  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00031  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
00032  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
00033  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034  *
00035 */
00036     
00037 #ifndef __NETCFG_H__
00038 #define __NETCFG_H__
00039 
00040 /*****************************************************************************/
00041 /* Include files                                                             */
00042 /*****************************************************************************/
00043 #include "cc3100_simplelink.h"
00044 
00045 #ifdef    __cplusplus
00046 extern "C" {
00047 #endif
00048 
00049 
00050 
00051 /*!
00052 
00053     \addtogroup netcfg
00054     @{
00055 
00056 */
00057 
00058 
00059 /*****************************************************************************/
00060 /* Macro declarations                                                        */
00061 /*****************************************************************************/
00062 
00063 #define SL_MAC_ADDR_LEN                          (6)
00064 #define SL_IPV4_VAL(add_3,add_2,add_1,add_0)     ((((_u32)add_3 << 24) & 0xFF000000) | (((_u32)add_2 << 16) & 0xFF0000) | (((_u32)add_1 << 8) & 0xFF00) | ((_u32)add_0 & 0xFF) )
00065 #define SL_IPV4_BYTE(val,index)                  ( (val >> (index*8)) & 0xFF )
00066 
00067 #define IPCONFIG_MODE_DISABLE_IPV4               (0)
00068 #define IPCONFIG_MODE_ENABLE_IPV4                (1)
00069 
00070 /*****************************************************************************/
00071 /* Structure/Enum declarations                                               */
00072 /*****************************************************************************/
00073 typedef enum
00074 {
00075     SL_MAC_ADDRESS_SET          = 1,
00076     SL_MAC_ADDRESS_GET          = 2,          
00077     SL_IPV4_STA_P2P_CL_GET_INFO           = 3,
00078     SL_IPV4_STA_P2P_CL_DHCP_ENABLE        = 4,
00079     SL_IPV4_STA_P2P_CL_STATIC_ENABLE      = 5,
00080     SL_IPV4_AP_P2P_GO_GET_INFO            = 6,
00081     SL_IPV4_AP_P2P_GO_STATIC_ENABLE       = 7,
00082     SL_SET_HOST_RX_AGGR                   = 8,
00083     MAX_SETTINGS = 0xFF
00084 }Sl_NetCfg_e;
00085 
00086 
00087 typedef struct
00088 {
00089     _u32  ipV4;
00090     _u32  ipV4Mask;
00091     _u32  ipV4Gateway;
00092     _u32  ipV4DnsServer;
00093 }SlNetCfgIpV4Args_t;
00094 
00095 
00096 /*****************************************************************************/
00097 /* Function prototypes                                                       */
00098 /*****************************************************************************/
00099 
00100 /*!
00101     \brief     Internal function for setting network configurations
00102 
00103     \return    On success, zero is returned. On error, -1 is 
00104                returned
00105      
00106     \param[in] ConfigId   configuration id
00107     \param[in] ConfigOpt  configurations option
00108     \param[in] ConfigLen  configurations len
00109     \param[in] pValues    configurations values
00110      
00111     \sa         
00112     \note 
00113     \warning  
00114 
00115     \par   Examples:
00116     \code
00117         SL_MAC_ADDRESS_SET:
00118     
00119         Setting MAC address to the Device.
00120         The new MAC address will override the default MAC address and it be saved in the FileSystem.
00121         Requires restarting the device for updating this setting.
00122     
00123         _u8 MAC_Address[6];
00124         MAC_Address[0] = 0x8;
00125         MAC_Address[1] = 0x0;
00126         MAC_Address[2] = 0x28;
00127         MAC_Address[3] = 0x22;
00128         MAC_Address[4] = 0x69;
00129         MAC_Address[5] = 0x31;
00130         sl_NetCfgSet(SL_MAC_ADDRESS_SET,1,SL_MAC_ADDR_LEN,(_u8 *)newMacAddress);
00131         sl_Stop(0);
00132         sl_Start(NULL,NULL,NULL);
00133     \endcode 
00134 
00135     \code 
00136         SL_IPV4_STA_P2P_CL_STATIC_ENABLE:
00137 
00138         Setting a static IP address to the device working in STA mode or P2P client.
00139         The IP address will be stored in the FileSystem.
00140         In order to disable the static IP and get the address assigned from DHCP one should use SL_STA_P2P_CL_IPV4_DHCP_SET
00141 
00142         SlNetCfgIpV4Args_t ipV4;
00143         ipV4.ipV4          = (_u32)SL_IPV4_VAL(10,1,1,201);            // _u32 IP address 
00144         ipV4.ipV4Mask      = (_u32)SL_IPV4_VAL(255,255,255,0);         // _u32 Subnet mask for this STA/P2P
00145         ipV4.ipV4Gateway   = (_u32)SL_IPV4_VAL(10,1,1,1);              // _u32 Default gateway address
00146         ipV4.ipV4DnsServer = (_u32)SL_IPV4_VAL(8,16,32,64);            // _u32 DNS server address
00147 
00148         sl_NetCfgSet(SL_IPV4_STA_P2P_CL_STATIC_ENABLE,IPCONFIG_MODE_ENABLE_IPV4,sizeof(SlNetCfgIpV4Args_t),(_u8 *)&ipV4); 
00149         sl_Stop(0);
00150         sl_Start(NULL,NULL,NULL);
00151     \endcode
00152 
00153     \code 
00154         SL_IPV4_STA_P2P_CL_DHCP_ENABLE:
00155 
00156         Setting IP address by DHCP to FileSystem using WLAN sta mode or P2P client.
00157                 This should be done once if using Serial Flash.
00158                 This is the system's default mode for acquiring an IP address after WLAN connection.
00159         _u8 val = 1;
00160         sl_NetCfgSet(SL_IPV4_STA_P2P_CL_DHCP_ENABLE,IPCONFIG_MODE_ENABLE_IPV4,1,&val);
00161         sl_Stop(0);
00162         sl_Start(NULL,NULL,NULL);
00163     \endcode
00164 
00165     \code       
00166         SL_IPV4_AP_P2P_GO_STATIC_ENABLE:
00167 
00168         Setting a static IP address to the device working in AP mode or P2P go.
00169         The IP address will be stored in the FileSystem. Requires restart.
00170                                                                      
00171         SlNetCfgIpV4Args_t ipV4;
00172         ipV4.ipV4          = (_u32)SL_IPV4_VAL(10,1,1,201);            // _u32 IP address 
00173         ipV4.ipV4Mask      = (_u32)SL_IPV4_VAL(255,255,255,0);         // _u32 Subnet mask for this AP/P2P
00174         ipV4.ipV4Gateway   = (_u32)SL_IPV4_VAL(10,1,1,1);              // _u32 Default gateway address
00175         ipV4.ipV4DnsServer = (_u32)SL_IPV4_VAL(8,16,32,64);            // _u32 DNS server address
00176 
00177         sl_NetCfgSet(SL_IPV4_AP_P2P_GO_STATIC_ENABLE,IPCONFIG_MODE_ENABLE_IPV4,sizeof(SlNetCfgIpV4Args_t),(_u8 *)&ipV4);
00178         sl_Stop(0);
00179         sl_Start(NULL,NULL,NULL);
00180     \endcode
00181 
00182    
00183 */
00184 #if _SL_INCLUDE_FUNC(sl_NetCfgSet)
00185 _i32 sl_NetCfgSet(_u8 ConfigId ,_u8 ConfigOpt, _u8 ConfigLen, _u8 *pValues);
00186 #endif
00187 
00188 
00189 /*!
00190     \brief     Internal function for getting network configurations
00191 
00192     \return    On success, zero is returned. On error, -1 is 
00193                returned
00194    
00195     \param[in] ConfigId      configuration id
00196 
00197     \param[out] pConfigOpt   Get configurations option 
00198 
00199     \param[out] pConfigLen   The length of the allocated memory as input, when the
00200                                         function complete, the value of this parameter would be
00201                              the len that actually read from the device.\n 
00202                                         If the device return length that is longer from the input 
00203                                         value, the function will cut the end of the returned structure
00204                                         and will return ESMALLBUF
00205 
00206     \param[out] pValues - get configurations values
00207 
00208     \sa         
00209     \note 
00210     \warning     
00211     \par   Examples:
00212     \code
00213        SL_MAC_ADDRESS_GET:
00214         
00215        Get the device MAC address.
00216        The returned MAC address is taken from FileSystem first. If the MAC address was not set by SL_MAC_ADDRESS_SET, the default MAC address
00217        is retrieved from HW.
00218        
00219        _u8 macAddressVal[SL_MAC_ADDR_LEN];
00220        _u8 macAddressLen = SL_MAC_ADDR_LEN;
00221        sl_NetCfgGet(SL_MAC_ADDRESS_GET,NULL,&macAddressLen,(_u8 *)macAddressVal);
00222     
00223     \endcode
00224 
00225     \code
00226         SL_IPV4_STA_P2P_CL_GET_INFO:
00227        
00228         Get IP address from WLAN station or P2P client. A DHCP flag is returned to indicate if the IP address is static or from DHCP. 
00229  
00230         _u8 len = sizeof(SlNetCfgIpV4Args_t);
00231         _u8 dhcpIsOn = 0;
00232         SlNetCfgIpV4Args_t ipV4 = {0};
00233         sl_NetCfgGet(SL_IPV4_STA_P2P_CL_GET_INFO,&dhcpIsOn,&len,(_u8 *)&ipV4);
00234                                           
00235         printf("DHCP is %s IP %d.%d.%d.%d MASK %d.%d.%d.%d GW %d.%d.%d.%d DNS %d.%d.%d.%d\n",        
00236                 (dhcpIsOn > 0) ? "ON" : "OFF",                                                           
00237                 SL_IPV4_BYTE(ipV4.ipV4,3),SL_IPV4_BYTE(ipV4.ipV4,2),SL_IPV4_BYTE(ipV4.ipV4,1),SL_IPV4_BYTE(ipV4.ipV4,0), 
00238                 SL_IPV4_BYTE(ipV4.ipV4Mask,3),SL_IPV4_BYTE(ipV4.ipV4Mask,2),SL_IPV4_BYTE(ipV4.ipV4Mask,1),SL_IPV4_BYTE(ipV4.ipV4Mask,0),         
00239                 SL_IPV4_BYTE(ipV4.ipV4Gateway,3),SL_IPV4_BYTE(ipV4.ipV4Gateway,2),SL_IPV4_BYTE(ipV4.ipV4Gateway,1),SL_IPV4_BYTE(ipV4.ipV4Gateway,0),                 
00240                 SL_IPV4_BYTE(ipV4.ipV4DnsServer,3),SL_IPV4_BYTE(ipV4.ipV4DnsServer,2),SL_IPV4_BYTE(ipV4.ipV4DnsServer,1),SL_IPV4_BYTE(ipV4.ipV4DnsServer,0));
00241 
00242     \endcode
00243 
00244     \code
00245         SL_IPV4_AP_P2P_GO_GET_INFO:
00246        
00247         Get static IP address for AP or P2P go.   
00248  
00249         _u8 len = sizeof(SlNetCfgIpV4Args_t);
00250         _u8 dhcpIsOn = 0; // this flag is meaningless on AP/P2P go.
00251         SlNetCfgIpV4Args_t ipV4 = {0};
00252         sl_NetCfgGet(SL_IPV4_AP_P2P_GO_GET_INFO,&dhcpIsOn,&len,(_u8 *)&ipV4);
00253                                           
00254         printf("IP %d.%d.%d.%d MASK %d.%d.%d.%d GW %d.%d.%d.%d DNS %d.%d.%d.%d\n",                                                             
00255                 SL_IPV4_BYTE(ipV4.ipV4,3),SL_IPV4_BYTE(ipV4.ipV4,2),SL_IPV4_BYTE(ipV4.ipV4,1),SL_IPV4_BYTE(ipV4.ipV4,0), 
00256                 SL_IPV4_BYTE(ipV4.ipV4Mask,3),SL_IPV4_BYTE(ipV4.ipV4Mask,2),SL_IPV4_BYTE(ipV4.ipV4Mask,1),SL_IPV4_BYTE(ipV4.ipV4Mask,0),         
00257                 SL_IPV4_BYTE(ipV4.ipV4Gateway,3),SL_IPV4_BYTE(ipV4.ipV4Gateway,2),SL_IPV4_BYTE(ipV4.ipV4Gateway,1),SL_IPV4_BYTE(ipV4.ipV4Gateway,0),                 
00258                 SL_IPV4_BYTE(ipV4.ipV4DnsServer,3),SL_IPV4_BYTE(ipV4.ipV4DnsServer,2),SL_IPV4_BYTE(ipV4.ipV4DnsServer,1),SL_IPV4_BYTE(ipV4.ipV4DnsServer,0));
00259 
00260     \endcode
00261 
00262    
00263 */
00264 #if _SL_INCLUDE_FUNC(sl_NetCfgGet)
00265 _i32 sl_NetCfgGet(_u8 ConfigId ,_u8 *pConfigOpt, _u8 *pConfigLen, _u8 *pValues);
00266 #endif
00267 
00268 /*!
00269 
00270  Close the Doxygen group.
00271  @}
00272 
00273  */
00274 
00275 
00276 #ifdef  __cplusplus
00277 }
00278 #endif /*  __cplusplus */
00279 
00280 #endif    /*  __NETCFG_H__ */
00281 
00282