Update revision to use TI's mqtt and Freertos.

Dependencies:   mbed client server

Fork of cc3100_Test_mqtt_CM3 by David Fletcher

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 /*****************************************************************************/
00038 /* Include files                                                             */
00039 /*****************************************************************************/
00040 #include "cc3100_simplelink.h"
00041 
00042 #ifndef NETCFG_H_
00043 #define NETCFG_H_
00044 
00045 namespace mbed_cc3100 {
00046 
00047 /*!
00048 
00049     \addtogroup netcfg
00050     @{
00051 
00052 */
00053 
00054 
00055 /*****************************************************************************/
00056 /* Macro declarations                                                        */
00057 /*****************************************************************************/
00058 const uint8_t SL_MAC_ADDR_LEN                       =   (6);
00059 const uint8_t IPCONFIG_MODE_DISABLE_IPV4            =   (0);
00060 const uint8_t IPCONFIG_MODE_ENABLE_IPV4             =   (1);
00061 
00062 /*****************************************************************************/
00063 /* Structure/Enum declarations                                               */
00064 /*****************************************************************************/
00065 typedef enum {
00066     SL_MAC_ADDRESS_SET          = 1,
00067     SL_MAC_ADDRESS_GET          = 2,
00068     SL_IPV4_STA_P2P_CL_GET_INFO           = 3,
00069     SL_IPV4_STA_P2P_CL_DHCP_ENABLE        = 4,
00070     SL_IPV4_STA_P2P_CL_STATIC_ENABLE      = 5,
00071     SL_IPV4_AP_P2P_GO_GET_INFO            = 6,
00072     SL_IPV4_AP_P2P_GO_STATIC_ENABLE       = 7,
00073     SL_SET_HOST_RX_AGGR                   = 8,
00074     MAX_SETTINGS = 0xFF
00075 } Sl_NetCfg_e;
00076 
00077 
00078 typedef struct {
00079     uint32_t  ipV4;
00080     uint32_t  ipV4Mask;
00081     uint32_t  ipV4Gateway;
00082     uint32_t  ipV4DnsServer;
00083 } SlNetCfgIpV4Args_t;
00084 
00085 class cc3100_netcfg
00086 {
00087 
00088 public:
00089 
00090     cc3100_netcfg(cc3100_driver  &driver);
00091 
00092     ~cc3100_netcfg();
00093 
00094 
00095     /*****************************************************************************/
00096     /* Function prototypes                                                       */
00097     /*****************************************************************************/
00098 
00099     /*!
00100         \brief     Internal function for setting network configurations
00101 
00102         \return    On success, zero is returned. On error, -1 is
00103                    returned
00104 
00105         \param[in] ConfigId   configuration id
00106         \param[in] ConfigOpt  configurations option
00107         \param[in] ConfigLen  configurations len
00108         \param[in] pValues    configurations values
00109 
00110         \sa
00111         \note
00112         \warning
00113 
00114         \par   Examples:
00115         \code
00116             SL_MAC_ADDRESS_SET:
00117 
00118             Setting MAC address to the Device.
00119             The new MAC address will override the default MAC address and it be saved in the FileSystem.
00120             Requires restarting the device for updating this setting.
00121 
00122             uint8_t MAC_Address[6];
00123             MAC_Address[0] = 0x8;
00124             MAC_Address[1] = 0x0;
00125             MAC_Address[2] = 0x28;
00126             MAC_Address[3] = 0x22;
00127             MAC_Address[4] = 0x69;
00128             MAC_Address[5] = 0x31;
00129             sl_NetCfgSet(SL_MAC_ADDRESS_SET,1,SL_MAC_ADDR_LEN,(uint8_t *)newMacAddress);
00130             sl_Stop(0);
00131             sl_Start(NULL,NULL,NULL);
00132         \endcode
00133 
00134         \code
00135             SL_IPV4_STA_P2P_CL_STATIC_ENABLE:
00136 
00137             Setting a static IP address to the device working in STA mode or P2P client.
00138             The IP address will be stored in the FileSystem.
00139             In order to disable the static IP and get the address assigned from DHCP one should use SL_STA_P2P_CL_IPV4_DHCP_SET
00140 
00141             SlNetCfgIpV4Args_t ipV4;
00142             ipV4.ipV4          = (uint32_t)SL_IPV4_VAL(10,1,1,201);            // uint32_t IP address
00143             ipV4.ipV4Mask      = (uint32_t)SL_IPV4_VAL(255,255,255,0);         // uint32_t Subnet mask for this STA/P2P
00144             ipV4.ipV4Gateway   = (uint32_t)SL_IPV4_VAL(10,1,1,1);              // uint32_t Default gateway address
00145             ipV4.ipV4DnsServer = (uint32_t)SL_IPV4_VAL(8,16,32,64);            // uint32_t DNS server address
00146 
00147             sl_NetCfgSet(SL_IPV4_STA_P2P_CL_STATIC_ENABLE,IPCONFIG_MODE_ENABLE_IPV4,sizeof(SlNetCfgIpV4Args_t),(uint8_t *)&ipV4);
00148             sl_Stop(0);
00149             sl_Start(NULL,NULL,NULL);
00150         \endcode
00151 
00152         \code
00153             SL_IPV4_STA_P2P_CL_DHCP_ENABLE:
00154 
00155             Setting IP address by DHCP to FileSystem using WLAN sta mode or P2P client.
00156                     This should be done once if using Serial Flash.
00157                     This is the system's default mode for acquiring an IP address after WLAN connection.
00158             uint8_t val = 1;
00159             sl_NetCfgSet(SL_IPV4_STA_P2P_CL_DHCP_ENABLE,IPCONFIG_MODE_ENABLE_IPV4,1,&val);
00160             sl_Stop(0);
00161             sl_Start(NULL,NULL,NULL);
00162         \endcode
00163 
00164         \code
00165             SL_IPV4_AP_P2P_GO_STATIC_ENABLE:
00166 
00167             Setting a static IP address to the device working in AP mode or P2P go.
00168             The IP address will be stored in the FileSystem. Requires restart.
00169 
00170             SlNetCfgIpV4Args_t ipV4;
00171             ipV4.ipV4          = (uint32_t)SL_IPV4_VAL(10,1,1,201);            // uint32_t IP address
00172             ipV4.ipV4Mask      = (uint32_t)SL_IPV4_VAL(255,255,255,0);         // uint32_t Subnet mask for this AP/P2P
00173             ipV4.ipV4Gateway   = (uint32_t)SL_IPV4_VAL(10,1,1,1);              // uint32_t Default gateway address
00174             ipV4.ipV4DnsServer = (uint32_t)SL_IPV4_VAL(8,16,32,64);            // uint32_t DNS server address
00175 
00176             sl_NetCfgSet(SL_IPV4_AP_P2P_GO_STATIC_ENABLE,IPCONFIG_MODE_ENABLE_IPV4,sizeof(SlNetCfgIpV4Args_t),(uint8_t *)&ipV4);
00177             sl_Stop(0);
00178             sl_Start(NULL,NULL,NULL);
00179         \endcode
00180 
00181 
00182     */
00183 #if _SL_INCLUDE_FUNC(sl_NetCfgSet)
00184     int32_t sl_NetCfgSet(const uint8_t ConfigId, const uint8_t ConfigOpt, const uint8_t ConfigLen, const uint8_t *pValues);
00185 #endif
00186 
00187 
00188     /*!
00189         \brief     Internal function for getting network configurations
00190 
00191         \return    On success, zero is returned. On error, -1 is
00192                    returned
00193 
00194         \param[in] ConfigId      configuration id
00195 
00196         \param[out] pConfigOpt   Get configurations option
00197 
00198         \param[out] pConfigLen   The length of the allocated memory as input, when the
00199                                             function complete, the value of this parameter would be
00200                                  the len that actually read from the device.\n
00201                                             If the device return length that is longer from the input
00202                                             value, the function will cut the end of the returned structure
00203                                             and will return ESMALLBUF
00204 
00205         \param[out] pValues - get configurations values
00206 
00207         \sa
00208         \note
00209         \warning
00210         \par   Examples:
00211         \code
00212            SL_MAC_ADDRESS_GET:
00213 
00214            Get the device MAC address.
00215            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
00216            is retrieved from HW.
00217 
00218            uint8_t macAddressVal[SL_MAC_ADDR_LEN];
00219            uint8_t macAddressLen = SL_MAC_ADDR_LEN;
00220            sl_NetCfgGet(SL_MAC_ADDRESS_GET,NULL,&macAddressLen,(uint8_t *)macAddressVal);
00221 
00222         \endcode
00223 
00224         \code
00225             SL_IPV4_STA_P2P_CL_GET_INFO:
00226 
00227             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.
00228 
00229             uint8_t len = sizeof(SlNetCfgIpV4Args_t);
00230             uint8_t dhcpIsOn = 0;
00231             SlNetCfgIpV4Args_t ipV4 = {0};
00232             sl_NetCfgGet(SL_IPV4_STA_P2P_CL_GET_INFO,&dhcpIsOn,&len,(uint8_t *)&ipV4);
00233 
00234             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",
00235                     (dhcpIsOn > 0) ? "ON" : "OFF",
00236                     SL_IPV4_BYTE(ipV4.ipV4,3),SL_IPV4_BYTE(ipV4.ipV4,2),SL_IPV4_BYTE(ipV4.ipV4,1),SL_IPV4_BYTE(ipV4.ipV4,0),
00237                     SL_IPV4_BYTE(ipV4.ipV4Mask,3),SL_IPV4_BYTE(ipV4.ipV4Mask,2),SL_IPV4_BYTE(ipV4.ipV4Mask,1),SL_IPV4_BYTE(ipV4.ipV4Mask,0),
00238                     SL_IPV4_BYTE(ipV4.ipV4Gateway,3),SL_IPV4_BYTE(ipV4.ipV4Gateway,2),SL_IPV4_BYTE(ipV4.ipV4Gateway,1),SL_IPV4_BYTE(ipV4.ipV4Gateway,0),
00239                     SL_IPV4_BYTE(ipV4.ipV4DnsServer,3),SL_IPV4_BYTE(ipV4.ipV4DnsServer,2),SL_IPV4_BYTE(ipV4.ipV4DnsServer,1),SL_IPV4_BYTE(ipV4.ipV4DnsServer,0));
00240 
00241         \endcode
00242 
00243         \code
00244             SL_IPV4_AP_P2P_GO_GET_INFO:
00245 
00246             Get static IP address for AP or P2P go.
00247 
00248             uint8_t len = sizeof(SlNetCfgIpV4Args_t);
00249             uint8_t dhcpIsOn = 0; // this flag is meaningless on AP/P2P go.
00250             SlNetCfgIpV4Args_t ipV4 = {0};
00251             sl_NetCfgGet(SL_IPV4_AP_P2P_GO_GET_INFO,&dhcpIsOn,&len,(uint8_t *)&ipV4);
00252 
00253             printf("IP %d.%d.%d.%d MASK %d.%d.%d.%d GW %d.%d.%d.%d DNS %d.%d.%d.%d\n",
00254                     SL_IPV4_BYTE(ipV4.ipV4,3),SL_IPV4_BYTE(ipV4.ipV4,2),SL_IPV4_BYTE(ipV4.ipV4,1),SL_IPV4_BYTE(ipV4.ipV4,0),
00255                     SL_IPV4_BYTE(ipV4.ipV4Mask,3),SL_IPV4_BYTE(ipV4.ipV4Mask,2),SL_IPV4_BYTE(ipV4.ipV4Mask,1),SL_IPV4_BYTE(ipV4.ipV4Mask,0),
00256                     SL_IPV4_BYTE(ipV4.ipV4Gateway,3),SL_IPV4_BYTE(ipV4.ipV4Gateway,2),SL_IPV4_BYTE(ipV4.ipV4Gateway,1),SL_IPV4_BYTE(ipV4.ipV4Gateway,0),
00257                     SL_IPV4_BYTE(ipV4.ipV4DnsServer,3),SL_IPV4_BYTE(ipV4.ipV4DnsServer,2),SL_IPV4_BYTE(ipV4.ipV4DnsServer,1),SL_IPV4_BYTE(ipV4.ipV4DnsServer,0));
00258 
00259         \endcode
00260 
00261 
00262     */
00263 #if _SL_INCLUDE_FUNC(sl_NetCfgGet)
00264     int32_t sl_NetCfgGet(const uint8_t ConfigId ,uint8_t *pConfigOpt, uint8_t *pConfigLen, uint8_t *pValues);
00265 #endif
00266 
00267 uint32_t SL_IPV4_VAL(uint8_t add_3,uint8_t add_2,uint8_t add_1,uint8_t add_0);
00268 uint8_t SL_IPV4_BYTE(uint32_t val,uint8_t index);
00269 
00270 private:
00271 
00272     cc3100_driver  &_driver;
00273     
00274 };//class
00275 
00276 }//namespace mbed_cc3100    
00277 
00278     /*!
00279 
00280      Close the Doxygen group.
00281      @}
00282 
00283      */
00284 
00285 
00286 #endif    /*  __NETCFG_H__ */
00287 
00288