DeepCover Embedded Security in IoT: Public-key Secured Data Paths
Dependencies: MaximInterface
netcfg.h
00001 /* 00002 * netcfg.h - CC31xx/CC32xx Host Driver Implementation 00003 * 00004 * Copyright (C) 2015 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 "simplelink.h" 00041 00042 00043 #ifndef __NETCFG_H__ 00044 #define __NETCFG_H__ 00045 00046 00047 #ifdef __cplusplus 00048 extern "C" { 00049 #endif 00050 00051 00052 00053 /*! 00054 00055 \addtogroup netcfg 00056 @{ 00057 00058 */ 00059 00060 00061 /*****************************************************************************/ 00062 /* Macro declarations */ 00063 /*****************************************************************************/ 00064 00065 #define SL_MAC_ADDR_LEN (6) 00066 #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) ) 00067 #define SL_IPV4_BYTE(val,index) ( (val >> (index*8)) & 0xFF ) 00068 00069 #define IPCONFIG_MODE_DISABLE_IPV4 (0) 00070 #define IPCONFIG_MODE_ENABLE_IPV4 (1) 00071 00072 /*****************************************************************************/ 00073 /* Structure/Enum declarations */ 00074 /*****************************************************************************/ 00075 typedef enum 00076 { 00077 SL_MAC_ADDRESS_SET = 1, 00078 SL_MAC_ADDRESS_GET = 2, 00079 SL_IPV4_STA_P2P_CL_GET_INFO = 3, 00080 SL_IPV4_STA_P2P_CL_DHCP_ENABLE = 4, 00081 SL_IPV4_STA_P2P_CL_STATIC_ENABLE = 5, 00082 SL_IPV4_AP_P2P_GO_GET_INFO = 6, 00083 SL_IPV4_AP_P2P_GO_STATIC_ENABLE = 7, 00084 SL_SET_HOST_RX_AGGR = 8, 00085 SL_IPV4_DHCP_CLIENT = 9, 00086 SL_IPV4_DNS_CLIENT = 10, 00087 SL_IPV4_ARP_FLUSH = 11, 00088 MAX_SETTINGS = 0xFF 00089 }Sl_NetCfg_e; 00090 00091 00092 typedef struct 00093 { 00094 _u32 ipV4; 00095 _u32 ipV4Mask; 00096 _u32 ipV4Gateway; 00097 _u32 ipV4DnsServer; 00098 }SlNetCfgIpV4Args_t; 00099 00100 typedef struct 00101 { 00102 _u32 Ip; 00103 _u32 Gateway; 00104 _u32 Mask; 00105 _u32 Dns[2]; 00106 _u32 DhcpServer; 00107 _u32 LeaseTime; 00108 _u8 DhcpState; 00109 _u8 Reserved[3]; 00110 }SlNetCfgIpV4DhcpClientArgs_t; 00111 00112 typedef enum 00113 { 00114 SL_NETCFG_DHCP_CLIENT_UNKNOWN = 0, 00115 SL_NETCFG_DHCP_CLIENT_DISABLED, 00116 SL_NETCFG_DHCP_CLIENT_ENABLED, 00117 SL_NETCFG_DHCP_CLIENT_BOUND, 00118 SL_NETCFG_DHCP_CLIENT_RENEW, 00119 SL_NETCFG_DHCP_CLIENT_REBIND 00120 }SlNetCfgIpv4DhcpClientState_e; 00121 00122 typedef struct 00123 { 00124 _u32 DnsSecondServerAddr; 00125 _u32 DnsMaxRetries; 00126 }SlNetCfgIpV4DnsClientArgs_t; 00127 00128 /*****************************************************************************/ 00129 /* Function prototypes */ 00130 /*****************************************************************************/ 00131 00132 /*! 00133 \brief Internal function for setting network configurations 00134 00135 \return On success, zero is returned. On error, -1 is 00136 returned 00137 00138 \param[in] ConfigId configuration id 00139 \param[in] ConfigOpt configurations option 00140 \param[in] ConfigLen configurations len 00141 \param[in] pValues configurations values 00142 00143 \sa 00144 \note 00145 \warning 00146 00147 \par Examples: 00148 \code 00149 SL_MAC_ADDRESS_SET: 00150 00151 Setting MAC address to the Device. 00152 The new MAC address will override the default MAC address and it be saved in the FileSystem. 00153 Requires restarting the device for updating this setting. 00154 00155 _u8 MAC_Address[6]; 00156 MAC_Address[0] = 0x8; 00157 MAC_Address[1] = 0x0; 00158 MAC_Address[2] = 0x28; 00159 MAC_Address[3] = 0x22; 00160 MAC_Address[4] = 0x69; 00161 MAC_Address[5] = 0x31; 00162 sl_NetCfgSet(SL_MAC_ADDRESS_SET,1,SL_MAC_ADDR_LEN,(_u8 *)newMacAddress); 00163 sl_Stop(0); 00164 sl_Start(NULL,NULL,NULL); 00165 \endcode 00166 00167 \code 00168 SL_IPV4_STA_P2P_CL_STATIC_ENABLE: 00169 00170 Setting a static IP address to the device working in STA mode or P2P client. 00171 The IP address will be stored in the FileSystem. 00172 In order to disable the static IP and get the address assigned from DHCP one should use SL_STA_P2P_CL_IPV4_DHCP_SET 00173 00174 SlNetCfgIpV4Args_t ipV4; 00175 ipV4.ipV4 = (_u32)SL_IPV4_VAL(10,1,1,201); // _u32 IP address 00176 ipV4.ipV4Mask = (_u32)SL_IPV4_VAL(255,255,255,0); // _u32 Subnet mask for this STA/P2P 00177 ipV4.ipV4Gateway = (_u32)SL_IPV4_VAL(10,1,1,1); // _u32 Default gateway address 00178 ipV4.ipV4DnsServer = (_u32)SL_IPV4_VAL(8,16,32,64); // _u32 DNS server address 00179 00180 sl_NetCfgSet(SL_IPV4_STA_P2P_CL_STATIC_ENABLE,IPCONFIG_MODE_ENABLE_IPV4,sizeof(SlNetCfgIpV4Args_t),(_u8 *)&ipV4); 00181 sl_Stop(0); 00182 sl_Start(NULL,NULL,NULL); 00183 \endcode 00184 00185 \code 00186 SL_IPV4_STA_P2P_CL_DHCP_ENABLE: 00187 00188 Setting IP address by DHCP to FileSystem using WLAN sta mode or P2P client. 00189 This should be done once if using Serial Flash. 00190 This is the system's default mode for acquiring an IP address after WLAN connection. 00191 _u8 val = 1; 00192 sl_NetCfgSet(SL_IPV4_STA_P2P_CL_DHCP_ENABLE,IPCONFIG_MODE_ENABLE_IPV4,1,&val); 00193 sl_Stop(0); 00194 sl_Start(NULL,NULL,NULL); 00195 \endcode 00196 00197 \code 00198 SL_IPV4_AP_P2P_GO_STATIC_ENABLE: 00199 00200 Setting a static IP address to the device working in AP mode or P2P go. 00201 The IP address will be stored in the FileSystem. Requires restart. 00202 00203 SlNetCfgIpV4Args_t ipV4; 00204 ipV4.ipV4 = (_u32)SL_IPV4_VAL(10,1,1,201); // _u32 IP address 00205 ipV4.ipV4Mask = (_u32)SL_IPV4_VAL(255,255,255,0); // _u32 Subnet mask for this AP/P2P 00206 ipV4.ipV4Gateway = (_u32)SL_IPV4_VAL(10,1,1,1); // _u32 Default gateway address 00207 ipV4.ipV4DnsServer = (_u32)SL_IPV4_VAL(8,16,32,64); // _u32 DNS server address 00208 00209 sl_NetCfgSet(SL_IPV4_AP_P2P_GO_STATIC_ENABLE,IPCONFIG_MODE_ENABLE_IPV4,sizeof(SlNetCfgIpV4Args_t),(_u8 *)&ipV4); 00210 sl_Stop(0); 00211 sl_Start(NULL,NULL,NULL); 00212 \endcode 00213 00214 \code 00215 SL_IPV4_DNS_CLIENT: 00216 00217 Set DNS max retries (range 5-32, default 32 retries) and secondary DNS address (DHCP and static configuration) 00218 changes not saved on the internal flash. 00219 00220 _i32 Status; 00221 SlNetCfgIpV4DnsClientArgs_t DnsOpt; 00222 DnsOpt.DnsSecondServerAddr = SL_IPV4_VAL(8,8,8,8); ; 00223 DnsOpt.DnsMaxRetries = 12; 00224 Status = sl_NetCfgSet(SL_IPV4_DNS_CLIENT,0,sizeof(SlNetCfgIpV4DnsClientArgs_t),(unsigned char *)&DnsOpt); 00225 if( Status ) 00226 { 00227 // error 00228 } 00229 \endcode 00230 \code 00231 SL_IPV4_ARP_FLUSH: 00232 00233 Flush ARP table 00234 00235 _i32 Status; 00236 Status = sl_NetCfgSet(SL_IPV4_ARP_FLUSH,0,0,NULL); 00237 if( Status ) 00238 { 00239 // 00240 } 00241 \endcode 00242 00243 */ 00244 #if _SL_INCLUDE_FUNC(sl_NetCfgSet) 00245 _i32 sl_NetCfgSet(const _u8 ConfigId,const _u8 ConfigOpt,const _u8 ConfigLen,const _u8 *pValues); 00246 #endif 00247 00248 00249 /*! 00250 \brief Internal function for getting network configurations 00251 00252 \return On success, zero is returned. On error, -1 is 00253 returned 00254 00255 \param[in] ConfigId configuration id 00256 00257 \param[out] pConfigOpt Get configurations option 00258 00259 \param[out] pConfigLen The length of the allocated memory as input, when the 00260 function complete, the value of this parameter would be 00261 the len that actually read from the device.\n 00262 If the device return length that is longer from the input 00263 value, the function will cut the end of the returned structure 00264 and will return ESMALLBUF 00265 00266 \param[out] pValues - get configurations values 00267 00268 \sa 00269 \note 00270 \warning 00271 \par Examples: 00272 \code 00273 SL_MAC_ADDRESS_GET: 00274 00275 Get the device MAC address. 00276 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 00277 is retrieved from HW. 00278 00279 _u8 macAddressVal[SL_MAC_ADDR_LEN]; 00280 _u8 macAddressLen = SL_MAC_ADDR_LEN; 00281 sl_NetCfgGet(SL_MAC_ADDRESS_GET,NULL,&macAddressLen,(_u8 *)macAddressVal); 00282 00283 \endcode 00284 00285 \code 00286 SL_IPV4_STA_P2P_CL_GET_INFO: 00287 00288 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. 00289 00290 _u8 len = sizeof(SlNetCfgIpV4Args_t); 00291 _u8 dhcpIsOn = 0; 00292 SlNetCfgIpV4Args_t ipV4 = {0}; 00293 sl_NetCfgGet(SL_IPV4_STA_P2P_CL_GET_INFO,&dhcpIsOn,&len,(_u8 *)&ipV4); 00294 00295 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", 00296 (dhcpIsOn > 0) ? "ON" : "OFF", 00297 SL_IPV4_BYTE(ipV4.ipV4,3),SL_IPV4_BYTE(ipV4.ipV4,2),SL_IPV4_BYTE(ipV4.ipV4,1),SL_IPV4_BYTE(ipV4.ipV4,0), 00298 SL_IPV4_BYTE(ipV4.ipV4Mask,3),SL_IPV4_BYTE(ipV4.ipV4Mask,2),SL_IPV4_BYTE(ipV4.ipV4Mask,1),SL_IPV4_BYTE(ipV4.ipV4Mask,0), 00299 SL_IPV4_BYTE(ipV4.ipV4Gateway,3),SL_IPV4_BYTE(ipV4.ipV4Gateway,2),SL_IPV4_BYTE(ipV4.ipV4Gateway,1),SL_IPV4_BYTE(ipV4.ipV4Gateway,0), 00300 SL_IPV4_BYTE(ipV4.ipV4DnsServer,3),SL_IPV4_BYTE(ipV4.ipV4DnsServer,2),SL_IPV4_BYTE(ipV4.ipV4DnsServer,1),SL_IPV4_BYTE(ipV4.ipV4DnsServer,0)); 00301 00302 \endcode 00303 00304 \code 00305 SL_IPV4_AP_P2P_GO_GET_INFO: 00306 00307 Get static IP address for AP or P2P go. 00308 00309 _u8 len = sizeof(SlNetCfgIpV4Args_t); 00310 _u8 dhcpIsOn = 0; // this flag is meaningless on AP/P2P go. 00311 SlNetCfgIpV4Args_t ipV4 = {0}; 00312 sl_NetCfgGet(SL_IPV4_AP_P2P_GO_GET_INFO,&dhcpIsOn,&len,(_u8 *)&ipV4); 00313 00314 printf("IP %d.%d.%d.%d MASK %d.%d.%d.%d GW %d.%d.%d.%d DNS %d.%d.%d.%d\n", 00315 SL_IPV4_BYTE(ipV4.ipV4,3),SL_IPV4_BYTE(ipV4.ipV4,2),SL_IPV4_BYTE(ipV4.ipV4,1),SL_IPV4_BYTE(ipV4.ipV4,0), 00316 SL_IPV4_BYTE(ipV4.ipV4Mask,3),SL_IPV4_BYTE(ipV4.ipV4Mask,2),SL_IPV4_BYTE(ipV4.ipV4Mask,1),SL_IPV4_BYTE(ipV4.ipV4Mask,0), 00317 SL_IPV4_BYTE(ipV4.ipV4Gateway,3),SL_IPV4_BYTE(ipV4.ipV4Gateway,2),SL_IPV4_BYTE(ipV4.ipV4Gateway,1),SL_IPV4_BYTE(ipV4.ipV4Gateway,0), 00318 SL_IPV4_BYTE(ipV4.ipV4DnsServer,3),SL_IPV4_BYTE(ipV4.ipV4DnsServer,2),SL_IPV4_BYTE(ipV4.ipV4DnsServer,1),SL_IPV4_BYTE(ipV4.ipV4DnsServer,0)); 00319 00320 \endcode 00321 00322 \code 00323 00324 SL_IPV4_DHCP_CLIENT: 00325 00326 Get DHCP client inforamtion, when DhcpState is SL_NETCFG_DHCP_CLIENT_BOUND, SL_NETCFG_DHCP_CLIENT_RENEW or SL_NETCFG_DHCP_CLIENT_REBIND, dhcp inforamtion is not zeroed 00327 00328 _u8 ConfigOpt = 0, ConfigLen = sizeof(SlNetCfgIpV4DhcpClientArgs_t); 00329 _i32 Status; 00330 SlNetCfgIpV4DhcpClientArgs_t Dhcp; 00331 Status = sl_NetCfgGet(SL_IPV4_DHCP_CLIENT,&ConfigOpt,&ConfigLen,(_u8 *)&Dhcp); 00332 if( Status ) 00333 { 00334 // error 00335 } 00336 \endcode 00337 00338 \code 00339 SL_IPV4_DNS_CLIENT: 00340 00341 Get DNS max retries and secondary DNS address (DHCP and static configuration) 00342 00343 _u8 ConfigOpt; 00344 _i32 Status; 00345 _u8 pConfigLen = sizeof(SlNetCfgIpV4DnsClientArgs_t); 00346 SlNetCfgIpV4DnsClientArgs_t DnsOpt; 00347 Status = sl_NetCfgGet(SL_IPV4_DNS_CLIENT,&ConfigOpt,&pConfigLen,&DnsOpt); 00348 if( Status ) 00349 { 00350 // error 00351 } 00352 \endcode 00353 00354 00355 */ 00356 #if _SL_INCLUDE_FUNC(sl_NetCfgGet) 00357 _i32 sl_NetCfgGet(const _u8 ConfigId ,_u8 *pConfigOpt, _u8 *pConfigLen, _u8 *pValues); 00358 #endif 00359 00360 /*! 00361 00362 Close the Doxygen group. 00363 @} 00364 00365 */ 00366 00367 00368 #ifdef __cplusplus 00369 } 00370 #endif /* __cplusplus */ 00371 00372 #endif /* __NETCFG_H__ */ 00373
Generated on Tue Jul 12 2022 12:06:48 by 1.7.2