Update revision to use TI's mqtt and Freertos.

Dependencies:   mbed client server

Fork of cc3100_Test_mqtt_CM3 by David Fletcher

Committer:
dflet
Date:
Thu Sep 03 14:02:37 2015 +0000
Revision:
3:a8c249046181
SPI Mode change 1 to 0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dflet 3:a8c249046181 1 /*
dflet 3:a8c249046181 2 * netcfg.h - CC31xx/CC32xx Host Driver Implementation
dflet 3:a8c249046181 3 *
dflet 3:a8c249046181 4 * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
dflet 3:a8c249046181 5 *
dflet 3:a8c249046181 6 *
dflet 3:a8c249046181 7 * Redistribution and use in source and binary forms, with or without
dflet 3:a8c249046181 8 * modification, are permitted provided that the following conditions
dflet 3:a8c249046181 9 * are met:
dflet 3:a8c249046181 10 *
dflet 3:a8c249046181 11 * Redistributions of source code must retain the above copyright
dflet 3:a8c249046181 12 * notice, this list of conditions and the following disclaimer.
dflet 3:a8c249046181 13 *
dflet 3:a8c249046181 14 * Redistributions in binary form must reproduce the above copyright
dflet 3:a8c249046181 15 * notice, this list of conditions and the following disclaimer in the
dflet 3:a8c249046181 16 * documentation and/or other materials provided with the
dflet 3:a8c249046181 17 * distribution.
dflet 3:a8c249046181 18 *
dflet 3:a8c249046181 19 * Neither the name of Texas Instruments Incorporated nor the names of
dflet 3:a8c249046181 20 * its contributors may be used to endorse or promote products derived
dflet 3:a8c249046181 21 * from this software without specific prior written permission.
dflet 3:a8c249046181 22 *
dflet 3:a8c249046181 23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
dflet 3:a8c249046181 24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
dflet 3:a8c249046181 25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
dflet 3:a8c249046181 26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
dflet 3:a8c249046181 27 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
dflet 3:a8c249046181 28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
dflet 3:a8c249046181 29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
dflet 3:a8c249046181 30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
dflet 3:a8c249046181 31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
dflet 3:a8c249046181 32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
dflet 3:a8c249046181 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
dflet 3:a8c249046181 34 *
dflet 3:a8c249046181 35 */
dflet 3:a8c249046181 36
dflet 3:a8c249046181 37 /*****************************************************************************/
dflet 3:a8c249046181 38 /* Include files */
dflet 3:a8c249046181 39 /*****************************************************************************/
dflet 3:a8c249046181 40 #include "cc3100_simplelink.h"
dflet 3:a8c249046181 41
dflet 3:a8c249046181 42 #ifndef NETCFG_H_
dflet 3:a8c249046181 43 #define NETCFG_H_
dflet 3:a8c249046181 44
dflet 3:a8c249046181 45 namespace mbed_cc3100 {
dflet 3:a8c249046181 46
dflet 3:a8c249046181 47 /*!
dflet 3:a8c249046181 48
dflet 3:a8c249046181 49 \addtogroup netcfg
dflet 3:a8c249046181 50 @{
dflet 3:a8c249046181 51
dflet 3:a8c249046181 52 */
dflet 3:a8c249046181 53
dflet 3:a8c249046181 54
dflet 3:a8c249046181 55 /*****************************************************************************/
dflet 3:a8c249046181 56 /* Macro declarations */
dflet 3:a8c249046181 57 /*****************************************************************************/
dflet 3:a8c249046181 58 const uint8_t SL_MAC_ADDR_LEN = (6);
dflet 3:a8c249046181 59 const uint8_t IPCONFIG_MODE_DISABLE_IPV4 = (0);
dflet 3:a8c249046181 60 const uint8_t IPCONFIG_MODE_ENABLE_IPV4 = (1);
dflet 3:a8c249046181 61
dflet 3:a8c249046181 62 /*****************************************************************************/
dflet 3:a8c249046181 63 /* Structure/Enum declarations */
dflet 3:a8c249046181 64 /*****************************************************************************/
dflet 3:a8c249046181 65 typedef enum {
dflet 3:a8c249046181 66 SL_MAC_ADDRESS_SET = 1,
dflet 3:a8c249046181 67 SL_MAC_ADDRESS_GET = 2,
dflet 3:a8c249046181 68 SL_IPV4_STA_P2P_CL_GET_INFO = 3,
dflet 3:a8c249046181 69 SL_IPV4_STA_P2P_CL_DHCP_ENABLE = 4,
dflet 3:a8c249046181 70 SL_IPV4_STA_P2P_CL_STATIC_ENABLE = 5,
dflet 3:a8c249046181 71 SL_IPV4_AP_P2P_GO_GET_INFO = 6,
dflet 3:a8c249046181 72 SL_IPV4_AP_P2P_GO_STATIC_ENABLE = 7,
dflet 3:a8c249046181 73 SL_SET_HOST_RX_AGGR = 8,
dflet 3:a8c249046181 74 MAX_SETTINGS = 0xFF
dflet 3:a8c249046181 75 } Sl_NetCfg_e;
dflet 3:a8c249046181 76
dflet 3:a8c249046181 77
dflet 3:a8c249046181 78 typedef struct {
dflet 3:a8c249046181 79 uint32_t ipV4;
dflet 3:a8c249046181 80 uint32_t ipV4Mask;
dflet 3:a8c249046181 81 uint32_t ipV4Gateway;
dflet 3:a8c249046181 82 uint32_t ipV4DnsServer;
dflet 3:a8c249046181 83 } SlNetCfgIpV4Args_t;
dflet 3:a8c249046181 84
dflet 3:a8c249046181 85 class cc3100_netcfg
dflet 3:a8c249046181 86 {
dflet 3:a8c249046181 87
dflet 3:a8c249046181 88 public:
dflet 3:a8c249046181 89
dflet 3:a8c249046181 90 cc3100_netcfg(cc3100_driver &driver);
dflet 3:a8c249046181 91
dflet 3:a8c249046181 92 ~cc3100_netcfg();
dflet 3:a8c249046181 93
dflet 3:a8c249046181 94
dflet 3:a8c249046181 95 /*****************************************************************************/
dflet 3:a8c249046181 96 /* Function prototypes */
dflet 3:a8c249046181 97 /*****************************************************************************/
dflet 3:a8c249046181 98
dflet 3:a8c249046181 99 /*!
dflet 3:a8c249046181 100 \brief Internal function for setting network configurations
dflet 3:a8c249046181 101
dflet 3:a8c249046181 102 \return On success, zero is returned. On error, -1 is
dflet 3:a8c249046181 103 returned
dflet 3:a8c249046181 104
dflet 3:a8c249046181 105 \param[in] ConfigId configuration id
dflet 3:a8c249046181 106 \param[in] ConfigOpt configurations option
dflet 3:a8c249046181 107 \param[in] ConfigLen configurations len
dflet 3:a8c249046181 108 \param[in] pValues configurations values
dflet 3:a8c249046181 109
dflet 3:a8c249046181 110 \sa
dflet 3:a8c249046181 111 \note
dflet 3:a8c249046181 112 \warning
dflet 3:a8c249046181 113
dflet 3:a8c249046181 114 \par Examples:
dflet 3:a8c249046181 115 \code
dflet 3:a8c249046181 116 SL_MAC_ADDRESS_SET:
dflet 3:a8c249046181 117
dflet 3:a8c249046181 118 Setting MAC address to the Device.
dflet 3:a8c249046181 119 The new MAC address will override the default MAC address and it be saved in the FileSystem.
dflet 3:a8c249046181 120 Requires restarting the device for updating this setting.
dflet 3:a8c249046181 121
dflet 3:a8c249046181 122 uint8_t MAC_Address[6];
dflet 3:a8c249046181 123 MAC_Address[0] = 0x8;
dflet 3:a8c249046181 124 MAC_Address[1] = 0x0;
dflet 3:a8c249046181 125 MAC_Address[2] = 0x28;
dflet 3:a8c249046181 126 MAC_Address[3] = 0x22;
dflet 3:a8c249046181 127 MAC_Address[4] = 0x69;
dflet 3:a8c249046181 128 MAC_Address[5] = 0x31;
dflet 3:a8c249046181 129 sl_NetCfgSet(SL_MAC_ADDRESS_SET,1,SL_MAC_ADDR_LEN,(uint8_t *)newMacAddress);
dflet 3:a8c249046181 130 sl_Stop(0);
dflet 3:a8c249046181 131 sl_Start(NULL,NULL,NULL);
dflet 3:a8c249046181 132 \endcode
dflet 3:a8c249046181 133
dflet 3:a8c249046181 134 \code
dflet 3:a8c249046181 135 SL_IPV4_STA_P2P_CL_STATIC_ENABLE:
dflet 3:a8c249046181 136
dflet 3:a8c249046181 137 Setting a static IP address to the device working in STA mode or P2P client.
dflet 3:a8c249046181 138 The IP address will be stored in the FileSystem.
dflet 3:a8c249046181 139 In order to disable the static IP and get the address assigned from DHCP one should use SL_STA_P2P_CL_IPV4_DHCP_SET
dflet 3:a8c249046181 140
dflet 3:a8c249046181 141 SlNetCfgIpV4Args_t ipV4;
dflet 3:a8c249046181 142 ipV4.ipV4 = (uint32_t)SL_IPV4_VAL(10,1,1,201); // uint32_t IP address
dflet 3:a8c249046181 143 ipV4.ipV4Mask = (uint32_t)SL_IPV4_VAL(255,255,255,0); // uint32_t Subnet mask for this STA/P2P
dflet 3:a8c249046181 144 ipV4.ipV4Gateway = (uint32_t)SL_IPV4_VAL(10,1,1,1); // uint32_t Default gateway address
dflet 3:a8c249046181 145 ipV4.ipV4DnsServer = (uint32_t)SL_IPV4_VAL(8,16,32,64); // uint32_t DNS server address
dflet 3:a8c249046181 146
dflet 3:a8c249046181 147 sl_NetCfgSet(SL_IPV4_STA_P2P_CL_STATIC_ENABLE,IPCONFIG_MODE_ENABLE_IPV4,sizeof(SlNetCfgIpV4Args_t),(uint8_t *)&ipV4);
dflet 3:a8c249046181 148 sl_Stop(0);
dflet 3:a8c249046181 149 sl_Start(NULL,NULL,NULL);
dflet 3:a8c249046181 150 \endcode
dflet 3:a8c249046181 151
dflet 3:a8c249046181 152 \code
dflet 3:a8c249046181 153 SL_IPV4_STA_P2P_CL_DHCP_ENABLE:
dflet 3:a8c249046181 154
dflet 3:a8c249046181 155 Setting IP address by DHCP to FileSystem using WLAN sta mode or P2P client.
dflet 3:a8c249046181 156 This should be done once if using Serial Flash.
dflet 3:a8c249046181 157 This is the system's default mode for acquiring an IP address after WLAN connection.
dflet 3:a8c249046181 158 uint8_t val = 1;
dflet 3:a8c249046181 159 sl_NetCfgSet(SL_IPV4_STA_P2P_CL_DHCP_ENABLE,IPCONFIG_MODE_ENABLE_IPV4,1,&val);
dflet 3:a8c249046181 160 sl_Stop(0);
dflet 3:a8c249046181 161 sl_Start(NULL,NULL,NULL);
dflet 3:a8c249046181 162 \endcode
dflet 3:a8c249046181 163
dflet 3:a8c249046181 164 \code
dflet 3:a8c249046181 165 SL_IPV4_AP_P2P_GO_STATIC_ENABLE:
dflet 3:a8c249046181 166
dflet 3:a8c249046181 167 Setting a static IP address to the device working in AP mode or P2P go.
dflet 3:a8c249046181 168 The IP address will be stored in the FileSystem. Requires restart.
dflet 3:a8c249046181 169
dflet 3:a8c249046181 170 SlNetCfgIpV4Args_t ipV4;
dflet 3:a8c249046181 171 ipV4.ipV4 = (uint32_t)SL_IPV4_VAL(10,1,1,201); // uint32_t IP address
dflet 3:a8c249046181 172 ipV4.ipV4Mask = (uint32_t)SL_IPV4_VAL(255,255,255,0); // uint32_t Subnet mask for this AP/P2P
dflet 3:a8c249046181 173 ipV4.ipV4Gateway = (uint32_t)SL_IPV4_VAL(10,1,1,1); // uint32_t Default gateway address
dflet 3:a8c249046181 174 ipV4.ipV4DnsServer = (uint32_t)SL_IPV4_VAL(8,16,32,64); // uint32_t DNS server address
dflet 3:a8c249046181 175
dflet 3:a8c249046181 176 sl_NetCfgSet(SL_IPV4_AP_P2P_GO_STATIC_ENABLE,IPCONFIG_MODE_ENABLE_IPV4,sizeof(SlNetCfgIpV4Args_t),(uint8_t *)&ipV4);
dflet 3:a8c249046181 177 sl_Stop(0);
dflet 3:a8c249046181 178 sl_Start(NULL,NULL,NULL);
dflet 3:a8c249046181 179 \endcode
dflet 3:a8c249046181 180
dflet 3:a8c249046181 181
dflet 3:a8c249046181 182 */
dflet 3:a8c249046181 183 #if _SL_INCLUDE_FUNC(sl_NetCfgSet)
dflet 3:a8c249046181 184 int32_t sl_NetCfgSet(const uint8_t ConfigId, const uint8_t ConfigOpt, const uint8_t ConfigLen, const uint8_t *pValues);
dflet 3:a8c249046181 185 #endif
dflet 3:a8c249046181 186
dflet 3:a8c249046181 187
dflet 3:a8c249046181 188 /*!
dflet 3:a8c249046181 189 \brief Internal function for getting network configurations
dflet 3:a8c249046181 190
dflet 3:a8c249046181 191 \return On success, zero is returned. On error, -1 is
dflet 3:a8c249046181 192 returned
dflet 3:a8c249046181 193
dflet 3:a8c249046181 194 \param[in] ConfigId configuration id
dflet 3:a8c249046181 195
dflet 3:a8c249046181 196 \param[out] pConfigOpt Get configurations option
dflet 3:a8c249046181 197
dflet 3:a8c249046181 198 \param[out] pConfigLen The length of the allocated memory as input, when the
dflet 3:a8c249046181 199 function complete, the value of this parameter would be
dflet 3:a8c249046181 200 the len that actually read from the device.\n
dflet 3:a8c249046181 201 If the device return length that is longer from the input
dflet 3:a8c249046181 202 value, the function will cut the end of the returned structure
dflet 3:a8c249046181 203 and will return ESMALLBUF
dflet 3:a8c249046181 204
dflet 3:a8c249046181 205 \param[out] pValues - get configurations values
dflet 3:a8c249046181 206
dflet 3:a8c249046181 207 \sa
dflet 3:a8c249046181 208 \note
dflet 3:a8c249046181 209 \warning
dflet 3:a8c249046181 210 \par Examples:
dflet 3:a8c249046181 211 \code
dflet 3:a8c249046181 212 SL_MAC_ADDRESS_GET:
dflet 3:a8c249046181 213
dflet 3:a8c249046181 214 Get the device MAC address.
dflet 3:a8c249046181 215 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
dflet 3:a8c249046181 216 is retrieved from HW.
dflet 3:a8c249046181 217
dflet 3:a8c249046181 218 uint8_t macAddressVal[SL_MAC_ADDR_LEN];
dflet 3:a8c249046181 219 uint8_t macAddressLen = SL_MAC_ADDR_LEN;
dflet 3:a8c249046181 220 sl_NetCfgGet(SL_MAC_ADDRESS_GET,NULL,&macAddressLen,(uint8_t *)macAddressVal);
dflet 3:a8c249046181 221
dflet 3:a8c249046181 222 \endcode
dflet 3:a8c249046181 223
dflet 3:a8c249046181 224 \code
dflet 3:a8c249046181 225 SL_IPV4_STA_P2P_CL_GET_INFO:
dflet 3:a8c249046181 226
dflet 3:a8c249046181 227 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.
dflet 3:a8c249046181 228
dflet 3:a8c249046181 229 uint8_t len = sizeof(SlNetCfgIpV4Args_t);
dflet 3:a8c249046181 230 uint8_t dhcpIsOn = 0;
dflet 3:a8c249046181 231 SlNetCfgIpV4Args_t ipV4 = {0};
dflet 3:a8c249046181 232 sl_NetCfgGet(SL_IPV4_STA_P2P_CL_GET_INFO,&dhcpIsOn,&len,(uint8_t *)&ipV4);
dflet 3:a8c249046181 233
dflet 3:a8c249046181 234 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",
dflet 3:a8c249046181 235 (dhcpIsOn > 0) ? "ON" : "OFF",
dflet 3:a8c249046181 236 SL_IPV4_BYTE(ipV4.ipV4,3),SL_IPV4_BYTE(ipV4.ipV4,2),SL_IPV4_BYTE(ipV4.ipV4,1),SL_IPV4_BYTE(ipV4.ipV4,0),
dflet 3:a8c249046181 237 SL_IPV4_BYTE(ipV4.ipV4Mask,3),SL_IPV4_BYTE(ipV4.ipV4Mask,2),SL_IPV4_BYTE(ipV4.ipV4Mask,1),SL_IPV4_BYTE(ipV4.ipV4Mask,0),
dflet 3:a8c249046181 238 SL_IPV4_BYTE(ipV4.ipV4Gateway,3),SL_IPV4_BYTE(ipV4.ipV4Gateway,2),SL_IPV4_BYTE(ipV4.ipV4Gateway,1),SL_IPV4_BYTE(ipV4.ipV4Gateway,0),
dflet 3:a8c249046181 239 SL_IPV4_BYTE(ipV4.ipV4DnsServer,3),SL_IPV4_BYTE(ipV4.ipV4DnsServer,2),SL_IPV4_BYTE(ipV4.ipV4DnsServer,1),SL_IPV4_BYTE(ipV4.ipV4DnsServer,0));
dflet 3:a8c249046181 240
dflet 3:a8c249046181 241 \endcode
dflet 3:a8c249046181 242
dflet 3:a8c249046181 243 \code
dflet 3:a8c249046181 244 SL_IPV4_AP_P2P_GO_GET_INFO:
dflet 3:a8c249046181 245
dflet 3:a8c249046181 246 Get static IP address for AP or P2P go.
dflet 3:a8c249046181 247
dflet 3:a8c249046181 248 uint8_t len = sizeof(SlNetCfgIpV4Args_t);
dflet 3:a8c249046181 249 uint8_t dhcpIsOn = 0; // this flag is meaningless on AP/P2P go.
dflet 3:a8c249046181 250 SlNetCfgIpV4Args_t ipV4 = {0};
dflet 3:a8c249046181 251 sl_NetCfgGet(SL_IPV4_AP_P2P_GO_GET_INFO,&dhcpIsOn,&len,(uint8_t *)&ipV4);
dflet 3:a8c249046181 252
dflet 3:a8c249046181 253 printf("IP %d.%d.%d.%d MASK %d.%d.%d.%d GW %d.%d.%d.%d DNS %d.%d.%d.%d\n",
dflet 3:a8c249046181 254 SL_IPV4_BYTE(ipV4.ipV4,3),SL_IPV4_BYTE(ipV4.ipV4,2),SL_IPV4_BYTE(ipV4.ipV4,1),SL_IPV4_BYTE(ipV4.ipV4,0),
dflet 3:a8c249046181 255 SL_IPV4_BYTE(ipV4.ipV4Mask,3),SL_IPV4_BYTE(ipV4.ipV4Mask,2),SL_IPV4_BYTE(ipV4.ipV4Mask,1),SL_IPV4_BYTE(ipV4.ipV4Mask,0),
dflet 3:a8c249046181 256 SL_IPV4_BYTE(ipV4.ipV4Gateway,3),SL_IPV4_BYTE(ipV4.ipV4Gateway,2),SL_IPV4_BYTE(ipV4.ipV4Gateway,1),SL_IPV4_BYTE(ipV4.ipV4Gateway,0),
dflet 3:a8c249046181 257 SL_IPV4_BYTE(ipV4.ipV4DnsServer,3),SL_IPV4_BYTE(ipV4.ipV4DnsServer,2),SL_IPV4_BYTE(ipV4.ipV4DnsServer,1),SL_IPV4_BYTE(ipV4.ipV4DnsServer,0));
dflet 3:a8c249046181 258
dflet 3:a8c249046181 259 \endcode
dflet 3:a8c249046181 260
dflet 3:a8c249046181 261
dflet 3:a8c249046181 262 */
dflet 3:a8c249046181 263 #if _SL_INCLUDE_FUNC(sl_NetCfgGet)
dflet 3:a8c249046181 264 int32_t sl_NetCfgGet(const uint8_t ConfigId ,uint8_t *pConfigOpt, uint8_t *pConfigLen, uint8_t *pValues);
dflet 3:a8c249046181 265 #endif
dflet 3:a8c249046181 266
dflet 3:a8c249046181 267 uint32_t SL_IPV4_VAL(uint8_t add_3,uint8_t add_2,uint8_t add_1,uint8_t add_0);
dflet 3:a8c249046181 268 uint8_t SL_IPV4_BYTE(uint32_t val,uint8_t index);
dflet 3:a8c249046181 269
dflet 3:a8c249046181 270 private:
dflet 3:a8c249046181 271
dflet 3:a8c249046181 272 cc3100_driver &_driver;
dflet 3:a8c249046181 273
dflet 3:a8c249046181 274 };//class
dflet 3:a8c249046181 275
dflet 3:a8c249046181 276 }//namespace mbed_cc3100
dflet 3:a8c249046181 277
dflet 3:a8c249046181 278 /*!
dflet 3:a8c249046181 279
dflet 3:a8c249046181 280 Close the Doxygen group.
dflet 3:a8c249046181 281 @}
dflet 3:a8c249046181 282
dflet 3:a8c249046181 283 */
dflet 3:a8c249046181 284
dflet 3:a8c249046181 285
dflet 3:a8c249046181 286 #endif /* __NETCFG_H__ */
dflet 3:a8c249046181 287
dflet 3:a8c249046181 288