TI's CC3100. A test demo with very little testing done!

Dependencies:   mbed

Fork of cc3100_Test_Demo2 by 高 杨

Committer:
gaoyang
Date:
Sun Jul 30 06:32:08 2017 +0000
Revision:
9:b8da46b97970
Parent:
6:778b081f6a13
DAS

Who changed what in which revision?

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