netcfg.h 11 KB

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