Updated to use external spawn.

Fork of simplelink_V2 by David Fletcher

Committer:
dflet
Date:
Sat Jun 06 13:48:29 2015 +0000
Revision:
1:9b68e650b3f6
Parent:
0:1a07906111ec
Oppps

Who changed what in which revision?

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