1 /*
2  * netcfg.h - CC31xx/CC32xx Host Driver Implementation
3  *
4  * Copyright (C) 2017 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 
38 
39 /*****************************************************************************/
40 /* Include files                                                             */
41 /*****************************************************************************/
42 #include <ti/drivers/net/wifi/simplelink.h>
43 
44 
45 #ifndef __NETCFG_H__
46 #define __NETCFG_H__
47 
48 
49 #ifdef    __cplusplus
50 extern "C" {
51 #endif
52 
53 /*!
54     \defgroup NetCfg
55     \short Controls the configuration of the device addresses (i.e. IP and MAC addresses)
56 
57 */
58 
59 /*!
60 
61     \addtogroup NetCfg
62     @{
63 
64 */
65 
66 
67 /*****************************************************************************/
68 /* Macro declarations                                                        */
69 /*****************************************************************************/
70 
71 #define SL_MAC_ADDR_LEN                              (6)
72 #define SL_IPV6_ADDR_LEN                             (16)
73 #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) )
74 #define SL_IPV6_VAL(add_1,add_2)                     ((((_u32)add_1 << 16) & 0xFFFF0000) | (((_u32)add_2 ) & 0x0000FFFF) )
75 #define SL_IPV4_BYTE(val,index)                      ( (val >> (index*8)) & 0xFF )
76 
77 
78 #define SL_NETCFG_IF_IPV6_STA_LOCAL                  (0x4)    /* disable ipv6 local */
79 #define SL_NETCFG_IF_IPV6_STA_GLOBAL                 (0x8)    /* disable ipv6 global */
80 #define SL_NETCFG_IF_DISABLE_IPV4_DHCP               (0x40)   /* disable ipv4 dhcp */
81 #define SL_NETCFG_IF_IPV6_LOCAL_STATIC               (0x80)   /* enable ipv6 local static */
82 #define SL_NETCFG_IF_IPV6_LOCAL_STATELESS            (0x100)  /* enable ipv6 local stateless */
83 #define SL_NETCFG_IF_IPV6_LOCAL_STATEFUL             (0x200)  /* enable ipv6 local statefull */
84 #define SL_NETCFG_IF_IPV6_GLOBAL_STATIC              (0x400)  /* enable ipv6 global static */
85 #define SL_NETCFG_IF_IPV6_GLOBAL_STATEFUL            (0x800)  /* enable ipv6 global statefull */
86 #define SL_NETCFG_IF_DISABLE_IPV4_LLA                (0x1000) /* disable LLA feature. Relevant only in IPV4 */
87 #define SL_NETCFG_IF_ENABLE_DHCP_RELEASE             (0x2000) /* Enables DHCP release when WLAN disconnect command is issued */
88 #define SL_NETCFG_IF_IPV6_GLOBAL_STATELESS           (0x4000) /* enable ipv6 global stateless */
89 #define SL_NETCFG_IF_DISABLE_FAST_RENEW              (0x8000) /* fast renew disabled */
90 
91 
92 #define    SL_NETCFG_IF_STATE                        (0)
93 #define SL_NETCFG_ADDR_DHCP                          (1)
94 #define SL_NETCFG_ADDR_DHCP_LLA                      (2)
95 #define SL_NETCFG_ADDR_STATIC                        (4)
96 #define SL_NETCFG_ADDR_STATELESS                     (5)
97 #define SL_NETCFG_ADDR_STATEFUL                      (6)
98 #define SL_NETCFG_ADDR_RELEASE_IP_SET                (7)
99 #define SL_NETCFG_ADDR_RELEASE_IP_OFF                (8)
100 #define SL_NETCFG_ADDR_ENABLE_FAST_RENEW             (9)
101 #define SL_NETCFG_ADDR_DISABLE_FAST_RENEW            (10)
102 #define SL_NETCFG_ADDR_FAST_RENEW_MODE_NO_WAIT_ACK   (11)
103 #define SL_NETCFG_ADDR_FAST_RENEW_MODE_WAIT_ACK      (12)
104 
105 
106 /*****************************************************************************/
107 /* Structure/Enum declarations                                               */
108 /*****************************************************************************/
109 typedef enum
110 {
111     SL_NETCFG_MAC_ADDRESS_SET                   = 1,
112     SL_NETCFG_MAC_ADDRESS_GET                   = 2,
113     SL_NETCFG_AP_STATIONS_NUM_CONNECTED         = 3,
114     SL_NETCFG_AP_STATIONS_INFO_LIST             = 4,
115     SL_NETCFG_AP_STATION_DISCONNECT             = 5,
116     SL_NETCFG_IF                                = 6,
117     SL_NETCFG_IPV4_STA_ADDR_MODE                = 7,
118     SL_NETCFG_IPV4_AP_ADDR_MODE                 = 8,
119     SL_NETCFG_IPV6_ADDR_LOCAL                   = 9,
120     SL_NETCFG_IPV6_ADDR_GLOBAL                  = 10,
121     SL_NETCFG_IPV4_DHCP_CLIENT                  = 11,
122     SL_NETCFG_IPV4_DNS_CLIENT                   = 12,
123     SL_NETCFG_IPV6_DNS_CLIENT                   = 13,
124     MAX_SETTINGS = 0xFF
125 }SlNetCfg_e;
126 
127 typedef struct
128 {
129     _u32 DnsSecondServerAddr;
130 }SlNetCfgIpV4DnsClientArgs_t;
131 
132 typedef struct
133 {
134     _u32 DnsSecondServerAddr[4];
135 }SlNetCfgIpV6DnsClientArgs_t;
136 
137 
138 typedef struct
139 {
140     _u32  Ip;
141     _u32  Gateway;
142     _u32  Mask;
143     _u32  Dns[2];
144     _u32  DhcpServer;
145     _u32  LeaseTime;
146     _u32  TimeToRenew;
147     _u8   DhcpState;
148     _u8   Reserved[3];
149 } SlNetCfgIpv4DhcpClient_t;
150 
151 typedef enum
152 {
153     SL_NETCFG_DHCP_CLIENT_UNKNOWN = 0,
154     SL_NETCFG_DHCP_CLIENT_DISABLED,
155     SL_NETCFG_DHCP_CLIENT_ENABLED,
156     SL_NETCFG_DHCP_CLIENT_BOUND,
157     SL_NETCFG_DHCP_CLIENT_RENEW,
158     SL_NETCFG_DHCP_CLIENT_REBIND
159 }SlNetCfgIpv4DhcpClientState_e;
160 
161 
162 typedef enum
163 {
164     SL_NETCFG_DHCP_OPT_DISABLE_LLA = 0x2,                   /* 1=LLA disabled, 0=LLA enabled. */
165     SL_NETCFG_DHCP_OPT_RELEASE_IP_BEFORE_DISCONNECT = 0x4,  /* 1=DHCP release enabled, 0=DHCP release disabled */
166     MAX_SL_NETCFG_DHCP_OPT = 0xFF
167 } SlNetCfgDhcpOption_e;
168 
169 typedef struct
170 {
171     _u32  Ip;
172     _u32  IpMask;
173     _u32  IpGateway;
174     _u32  IpDnsServer;
175 }SlNetCfgIpV4Args_t;
176 
177 typedef struct
178 {
179     _u32  Ip[4];
180     _u32  IpDnsServer[4];
181     _u32  IpV6Flags; /* bit 0: Indicate if the address is valid for use in the network (IPv6 DAD completed) . If not, try again later or set a different address. 1=Valid. Relevant for sl_NetCfgGet only. */
182 }SlNetCfgIpV6Args_t;
183 
184 #define _SL_NETCFG_IPV6_ADDR_BIT_STATUS     0x01
185 #define SL_IS_IPV6_ADDR_VALID(IpV6Flags)    (IpV6Flags & _SL_NETCFG_IPV6_ADDR_BIT_STATUS)
186 
187 #define NET_CFG_STA_INFO_STATUS_DHCP_ADDR   1
188 
189 typedef struct
190 {
191     _u32 Ip;
192     _u8  MacAddr[6];
193     _u16 Status;
194     _u8  Name[32];
195 } SlNetCfgStaInfo_t;
196 
197 /*****************************************************************************/
198 /* Function prototypes                                                       */
199 /*****************************************************************************/
200 
201 /*!
202     \brief     Setting network configurations
203 
204     \param[in] ConfigId   Configuration id:
205                                             - SL_NETCFG_IF
206                                             - SL_NETCFG_IPV4_STA_ADDR_MODE
207                                             - SL_NETCFG_IPV6_ADDR_LOCAL
208                                             - SL_NETCFG_IPV6_ADDR_GLOBAL
209                                             - SL_NETCFG_IPV4_AP_ADDR_MODE
210                                             - SL_NETCFG_MAC_ADDRESS_SET
211                                             - SL_NETCFG_AP_STATION_DISCONNECT
212     \param[in] ConfigOpt  Configurations option:
213                                             - SL_NETCFG_IF_STATE
214                                             - SL_NETCFG_ADDR_DHCP
215                                             - SL_NETCFG_ADDR_DHCP_LLA
216                                             - SL_NETCFG_ADDR_STATIC
217                                             - SL_NETCFG_ADDR_STATELESS
218                                             - SL_NETCFG_ADDR_STATEFUL
219                                             - SL_NETCFG_ADDR_RELEASE_IP_SET
220                                             - SL_NETCFG_ADDR_RELEASE_IP_OFF
221     \param[in] ConfigLen  Configurations len
222     \param[in] pValues    Configurations values
223     \par                  Persistent
224     \par
225                           <b>Reset</b>:
226                                             - SL_NETCFG_MAC_ADDRESS_SET
227                                             - SL_NETCFG_IPV4_AP_ADDR_MODE
228     \par
229                           <b>Non- Persistent</b>:
230                                             - SL_NETCFG_AP_STATION_DISCONNECT
231     \par
232                           <b>System Persistent</b>:
233                                             - SL_NETCFG_IPV4_STA_ADDR_MODE
234                                             - SL_NETCFG_IF
235                                             - SL_NETCFG_IPV6_ADDR_LOCAL
236                                             - SL_NETCFG_IPV6_ADDR_GLOBAL
237                                             - SL_NETCFG_IPV6_DNS_CLIENT
238 
239     \return    Non-negative value on success, or -1 for failure
240     \sa        sl_NetCfgGet
241     \note
242     \warning
243 
244     \par      Examples
245 
246     - SL_NETCFG_MAC_ADDRESS_SET: <br>
247       Setting MAC address to the Device.
248       The new MAC address will override the default MAC address and it be saved in the FileSystem.
249       Requires restarting the device for updating this setting.
250     \code
251         _u8 MAC_Address[6];
252         MAC_Address[0] = 0x8;
253         MAC_Address[1] = 0x0;
254         MAC_Address[2] = 0x28;
255         MAC_Address[3] = 0x22;
256         MAC_Address[4] = 0x69;
257         MAC_Address[5] = 0x31;
258         sl_NetCfgSet(SL_NETCFG_MAC_ADDRESS_SET,1,SL_MAC_ADDR_LEN,(_u8 *)MAC_Address);
259         sl_Stop(0);
260         sl_Start(NULL,NULL,NULL);
261     \endcode
262     <br>
263 
264     - <b>SL_NETCFG_IPV4_STA_ADDR_MODE</b><br>:
265         Setting/Releasing a DHCP/DHCP LLA /STATIC STA IP address
266 
267     - SL_NETCFG_ADDR_STATIC: <br>
268     Setting a static IP address to the device working in STA mode or P2P client.
269     The IP address will be stored in the FileSystem.
270     \code
271         SlNetCfgIpV4Args_t ipV4;
272         ipV4.Ip          = (_u32)SL_IPV4_VAL(10,1,1,201);            // _u32 IP address
273         ipV4.IpMask      = (_u32)SL_IPV4_VAL(255,255,255,0);         // _u32 Subnet mask for this STA/P2P
274         ipV4.IpGateway   = (_u32)SL_IPV4_VAL(10,1,1,1);              // _u32 Default gateway address
275         ipV4.IpDnsServer = (_u32)SL_IPV4_VAL(8,16,32,64);            // _u32 DNS server address
276 
277         sl_NetCfgSet(SL_NETCFG_IPV4_STA_ADDR_MODE,SL_NETCFG_ADDR_STATIC,sizeof(SlNetCfgIpV4Args_t),(_u8 *)&ipV4);
278         sl_Stop(0);
279         sl_Start(NULL,NULL,NULL);
280     \endcode
281     <br>
282 
283     - SL_NETCFG_ADDR_DHCP:<br>
284     Setting IP address by DHCP to FileSystem using WLAN sta mode or P2P client.
285     This should be done once if using Serial Flash.
286     This is the system's default mode for acquiring an IP address after WLAN connection.
287     \code
288         sl_NetCfgSet(SL_NETCFG_IPV4_STA_ADDR_MODE,SL_NETCFG_ADDR_DHCP,0,0);
289         sl_Stop(0);
290         sl_Start(NULL,NULL,NULL);
291     \endcode
292     <br>
293 
294     - SL_NETCFG_ADDR_DHCP_LLA: <br>
295     Setting DHCP LLA will runs LLA mechanism in case DHCP fails to acquire an address. It is optional to set the LLA timeout, default is 25 seconds.
296     SL_NETCFG_DHCP_OPT_RELEASE_IP_BEFORE_DISCONNECT - If set, enables sending a DHCP release frame to the server if user issues a WLAN disconnect command.
297     \code
298         _u32 LLATimeout;
299         LLATimeout = 60;
300         sl_NetCfgSet(SL_NETCFG_IPV4_STA_ADDR_MODE,SL_NETCFG_ADDR_DHCP_LLA,sizeof(_u32),&LLATimeout);
301         sl_Stop(0);
302         sl_Start(NULL,NULL,NULL);
303     \endcode
304     <br>
305     \code
306         sl_NetCfgSet(SL_NETCFG_IPV4_STA_ADDR_MODE,SL_NETCFG_ADDR_DHCP_LLA,0,0);
307         sl_Stop(0);
308         sl_Start(NULL,NULL,NULL);
309     \endcode
310     <br>
311 
312     - SL_NETCFG_ADDR_RELEASE_IP_SET: <br>
313     Setting release ip before disconnect enables sending a DHCP release frame to the server if user issues a WLAN disconnect command.
314     \code
315         sl_NetCfgSet(SL_NETCFG_IPV4_STA_ADDR_MODE,SL_NETCFG_ADDR_RELEASE_IP_SET,0,0);
316         sl_Stop(0);
317         sl_Start(NULL,NULL,NULL);
318     \endcode
319     <br>
320 
321     - SL_NETCFG_ADDR_RELEASE_IP_OFF:<br>
322     Setting release ip before disconnect disables sending a DHCP release frame to the server if user issues a WLAN disconnect command.
323     \code
324         sl_NetCfgSet(SL_NETCFG_IPV4_STA_ADDR_MODE,SL_NETCFG_ADDR_RELEASE_IP_OFF,0,0);
325         sl_Stop(0);
326         sl_Start(NULL,NULL,NULL);
327     \endcode
328     <br>
329 
330     - SL_NETCFG_IPV4_AP_ADDR_MODE:<br>
331     Setting a static IP address to the device working in AP mode or P2P go.
332     The IP address will be stored in the FileSystem. Requires restart.
333     \code
334         SlNetCfgIpV4Args_t ipV4;
335         ipV4.Ip          = (_u32)SL_IPV4_VAL(10,1,1,201);            // _u32 IP address
336         ipV4.IpMask      = (_u32)SL_IPV4_VAL(255,255,255,0);         // _u32 Subnet mask for this AP/P2P
337         ipV4.IpGateway   = (_u32)SL_IPV4_VAL(10,1,1,1);              // _u32 Default gateway address
338         ipV4.IpDnsServer = (_u32)SL_IPV4_VAL(8,16,32,64);            // _u32 DNS server address
339 
340         sl_NetCfgSet(SL_NETCFG_IPV4_AP_ADDR_MODE,SL_NETCFG_ADDR_STATIC,sizeof(SlNetCfgIpV4Args_t),(_u8 *)&ipV4);
341         sl_Stop(0);
342         sl_Start(NULL,NULL,NULL);
343     \endcode
344     <br>
345 
346     - SL_NETCFG_IF:<br>
347     Enable\Disable IPV6 interface - Local or/and Global address (Global could not be enabled without Local)
348     \code
349         _u32 IfBitmap = 0;
350 
351         IfBitmap = SL_NETCFG_IF_IPV6_STA_LOCAL | SL_NETCFG_IF_IPV6_STA_GLOBAL;
352         sl_NetCfgSet(SL_NETCFG_IF,SL_NETCFG_IF_STATE,sizeof(IfBitmap),&IfBitmap);
353         sl_Stop(0);
354         sl_Start(NULL,NULL,NULL);
355     \endcode
356     <br>
357 
358     - SL_NETCFG_IPV6_ADDR_LOCAL: <br>
359     Setting a IPv6 Local static address to the device working in STA mode.
360     The IP address will be stored in the FileSystem. Requires restart.
361     \code
362           SlNetCfgIpV6Args_t ipV6;
363         _u32 IfBitmap = 0;
364 
365         IfBitmap = SL_NETCFG_IF_IPV6_STA_LOCAL;
366         sl_NetCfgSet(SL_NETCFG_IF,SL_NETCFG_IF_STATE,sizeof(IfBitmap),&IfBitmap);
367 
368         ipV6.Ip[0] = 0xfe800000;
369         ipV6.Ip[1] = 0x00000000;
370         ipV6.Ip[2] = 0x00004040;
371         ipV6.Ip[3] = 0x0000ce65;
372 
373         sl_NetCfgSet(SL_NETCFG_IPV6_ADDR_LOCAL,SL_NETCFG_ADDR_STATIC,sizeof(SlNetCfgIpV6Args_t),(_u8 *)&ipV6);
374         sl_Stop(0);
375         sl_Start(NULL,NULL,NULL);
376     \endcode
377     <br>
378 
379     - SL_NETCFG_IPV6_ADDR_LOCAL: <br>
380     Setting a IPv6 Local stateless address to the device working in STA mode.
381     The IP address will be stored in the FileSystem. Requires restart.
382     \code
383         _u32 IfBitmap = 0;
384         IfBitmap = SL_NETCFG_IF_IPV6_STA_LOCAL;
385         sl_NetCfgSet(SL_NETCFG_IF,SL_NETCFG_IF_STATE,sizeof(IfBitmap),&IfBitmap);
386         sl_NetCfgSet(SL_NETCFG_IPV6_ADDR_LOCAL,SL_NETCFG_ADDR_STATELESS,0,0);
387         sl_Stop(0);
388         sl_Start(NULL,NULL,NULL);
389     \endcode
390     <br>
391 
392     - SL_NETCFG_IPV6_ADDR_LOCAL: <br>
393     Setting a IPv6 Local statefull address to the device working in STA mode.
394     The IP address will be stored in the FileSystem. Requires restart.
395     \code
396         _u32 IfBitmap = 0;
397 
398         IfBitmap = SL_NETCFG_IF_IPV6_STA_LOCAL;
399         sl_NetCfgSet(SL_NETCFG_IF,SL_NETCFG_IF_STATE,sizeof(IfBitmap),&IfBitmap);
400         sl_NetCfgSet(SL_NETCFG_IPV6_ADDR_LOCAL,SL_NETCFG_ADDR_STATEFUL,0,0);
401         sl_Stop(0);
402         sl_Start(NULL,NULL,NULL);
403     \endcode
404     <br>
405 
406     - SL_NETCFG_IPV6_ADDR_GLOBAL:<br>
407     Setting a IPv6 Global static address to the device working in STA mode.
408     The IP address will be stored in the FileSystem. Requires restart.
409     \code
410         SlNetCfgIpV6Args_t ipV6;
411         _u32 IfBitmap = 0;
412 
413         ipV6.Ip[0] = 0xfe80;
414         ipV6.Ip[1] = 0x03a;
415         ipV6.Ip[2] = 0x4040;
416         ipV6.Ip[3] = 0xce65;
417 
418         ipV6.IpDnsServer[0] = 0xa780;
419         ipV6.IpDnsServer[1] = 0x65e;
420         ipV6.IpDnsServer[2] = 0x8;
421         ipV6.IpDnsServer[3] = 0xce00;
422 
423         IfBitmap = SL_NETCFG_IF_IPV6_STA_GLOBAL;
424         sl_NetCfgSet(SL_NETCFG_IF,SL_NETCFG_IF_STATE,sizeof(IfBitmap),&IfBitmap);
425         sl_NetCfgSet(SL_NETCFG_IPV6_ADDR_GLOBAL,SL_NETCFG_ADDR_STATIC,sizeof(SlNetCfgIpV6Args_t),(_u8 *)&ipV6);
426         sl_Stop(0);
427         sl_Start(NULL,NULL,NULL);
428     \endcode
429     <br>
430 
431     - SL_NETCFG_IPV6_ADDR_GLOBAL:<br>
432     Setting a IPv6 Global statefull address to the device working in STA mode.
433     The IP address will be stored in the FileSystem. Requires restart.
434     \code
435         _u32 IfBitmap = 0;
436         IfBitmap = SL_NETCFG_IF_IPV6_STA_GLOBAL;
437         sl_NetCfgSet(SL_NETCFG_IF,SL_NETCFG_IF_STATE,sizeof(IfBitmap),&IfBitmap);
438         sl_NetCfgSet(SL_NETCFG_IPV6_ADDR_GLOBAL,SL_NETCFG_ADDR_STATEFUL,0,0);
439         sl_Stop(0);
440         sl_Start(NULL,NULL,NULL);
441     \endcode
442     <br>
443 
444     - SL_NETCFG_AP_STATION_DISCONNECT:<br>
445     Disconnect AP station by mac address.
446     The AP connected stations list can be read by sl_NetCfgGet with options: SL_AP_STATIONS_NUM_CONNECTED, SL_AP_STATIONS_INFO_LIST
447     \code
448         _u8  ap_sta_mac[6] = { 0x00, 0x22, 0x33, 0x44, 0x55, 0x66 };
449         sl_NetCfgSet(SL_NETCFG_AP_STATION_DISCONNECT,1,SL_MAC_ADDR_LEN,(_u8 *)ap_sta_mac);
450     \endcode
451     <br>
452 
453     - SL_NETCFG_IPV4_DNS_CLIENT:<br>
454     Set additional IPv4 DNS address
455     \code
456         _i32 Status;
457         SlNetCfgIpV4DnsClientArgs_t DnsOpt;
458         DnsOpt.DnsSecondServerAddr  =  SL_IPV4_VAL(8,8,8,8); ;
459         Status = sl_NetCfgSet(SL_NETCFG_IPV4_DNS_CLIENT,0,sizeof(SlNetCfgIpV4DnsClientArgs_t),(unsigned char *)&DnsOpt);
460         if( Status )
461         {
462             // error
463         }
464     \endcode
465     <br>
466 
467     - SL_NETCFG_IPV6_DNS_CLIENT:<br>
468     Set additional IPv6 DNS address
469     \code
470         _i32 Status;
471         SlNetCfgIpV6DnsClientArgs_t DnsOpt;
472         DnsOpt.DnsSecondServerAddr[0] = SL_IPV6_VAL(0x2001, 0x4860);
473         DnsOpt.DnsSecondServerAddr[1] = SL_IPV6_VAL(0x4860, 0x0);
474         DnsOpt.DnsSecondServerAddr[2] = SL_IPV6_VAL(0x0, 0x0);
475         DnsOpt.DnsSecondServerAddr[3] = SL_IPV6_VAL(0x0, 0x8844);
476         Status = sl_NetCfgSet(SL_NETCFG_IPV6_DNS_CLIENT,0,sizeof(SlNetCfgIpV6DnsClientArgs_t),(unsigned char *)&DnsOpt);
477         if( Status )
478         {
479             // error
480         }
481     \endcode
482 
483 */
484 #if _SL_INCLUDE_FUNC(sl_NetCfgSet)
485 _i16 sl_NetCfgSet(const _u16 ConfigId,const _u16 ConfigOpt,const _u16 ConfigLen,const _u8 *pValues);
486 #endif
487 
488 
489 /*!
490     \brief      Getting network configurations
491 
492     \param[in]  ConfigId      Configuration id
493 
494     \param[out] pConfigOpt    Get configurations option
495 
496     \param[out] pConfigLen    The length of the allocated memory as input, when the
497                               function complete, the value of this parameter would be
498                               the len that actually read from the device.\n
499                               If the device return length that is longer from the input
500                               value, the function will cut the end of the returned structure
501                               and will return ESMALLBUF
502 
503     \param[out] pValues - get configurations values
504     \return     Zero on success, or -1 on failure
505     \sa         sl_NetCfgSet
506     \note
507     \warning
508     \par        Examples
509 
510     - SL_NETCFG_MAC_ADDRESS_GET: <br>
511      Get the device MAC address.
512      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
513      is retrieved from HW.
514     \code
515         _u8 macAddressVal[SL_MAC_ADDR_LEN];
516         _u16 macAddressLen = SL_MAC_ADDR_LEN;
517         _u16 ConfigOpt = 0;
518         sl_NetCfgGet(SL_NETCFG_MAC_ADDRESS_GET,&ConfigOpt,&macAddressLen,(_u8 *)macAddressVal);
519     \endcode
520     <br>
521 
522     - SL_NETCFG_IPV4_STA_ADDR_MODE: <br>
523       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.
524     \code
525         _u16 len = sizeof(SlNetCfgIpV4Args_t);
526         _u16 ConfigOpt = 0;   //return value could be one of the following: SL_NETCFG_ADDR_DHCP / SL_NETCFG_ADDR_DHCP_LLA / SL_NETCFG_ADDR_STATIC
527         SlNetCfgIpV4Args_t ipV4 = {0};
528         sl_NetCfgGet(SL_NETCFG_IPV4_STA_ADDR_MODE,&ConfigOpt,&len,(_u8 *)&ipV4);
529 
530         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",
531             (ConfigOpt == SL_NETCFG_ADDR_DHCP) ? "ON" : "OFF",
532             SL_IPV4_BYTE(ipV4.Ip,3),SL_IPV4_BYTE(ipV4.Ip,2),SL_IPV4_BYTE(ipV4.Ip,1),SL_IPV4_BYTE(ipV4.Ip,0),
533             SL_IPV4_BYTE(ipV4.IpMask,3),SL_IPV4_BYTE(ipV4.IpMask,2),SL_IPV4_BYTE(ipV4.IpMask,1),SL_IPV4_BYTE(ipV4.IpMask,0),
534             SL_IPV4_BYTE(ipV4.IpGateway,3),SL_IPV4_BYTE(ipV4.IpGateway,2),SL_IPV4_BYTE(ipV4.IpGateway,1),SL_IPV4_BYTE(ipV4.IpGateway,0),
535             SL_IPV4_BYTE(ipV4.IpDnsServer,3),SL_IPV4_BYTE(ipV4.IpDnsServer,2),SL_IPV4_BYTE(ipV4.IpDnsServer,1),SL_IPV4_BYTE(ipV4.IpDnsServer,0));
536     \endcode
537     <br>
538 
539     - SL_NETCFG_IPV4_AP_ADDR_MODE: <br>
540       Get static IP address for AP or P2P go.
541     \code
542         _u16 len = sizeof(SlNetCfgIpV4Args_t);
543         _u16 ConfigOpt = 0;  //return value could be one of the following: SL_NETCFG_ADDR_DHCP / SL_NETCFG_ADDR_DHCP_LLA / SL_NETCFG_ADDR_STATIC
544         SlNetCfgIpV4Args_t ipV4 = {0};
545         sl_NetCfgGet(SL_NETCFG_IPV4_AP_ADDR_MODE,&ConfigOpt,&len,(_u8 *)&ipV4);
546 
547         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",
548             (ConfigOpt == SL_NETCFG_ADDR_DHCP) ? "ON" : "OFF",
549             SL_IPV4_BYTE(ipV4.Ip,3),SL_IPV4_BYTE(ipV4.Ip,2),SL_IPV4_BYTE(ipV4.Ip,1),SL_IPV4_BYTE(ipV4.Ip,0),
550             SL_IPV4_BYTE(ipV4.IpMask,3),SL_IPV4_BYTE(ipV4.IpMask,2),SL_IPV4_BYTE(ipV4.IpMask,1),SL_IPV4_BYTE(ipV4.IpMask,0),
551             SL_IPV4_BYTE(ipV4.IpGateway,3),SL_IPV4_BYTE(ipV4.IpGateway,2),SL_IPV4_BYTE(ipV4.IpGateway,1),SL_IPV4_BYTE(ipV4.IpGateway,0),
552             SL_IPV4_BYTE(ipV4.IpDnsServer,3),SL_IPV4_BYTE(ipV4.IpDnsServer,2),SL_IPV4_BYTE(ipV4.IpDnsServer,1),SL_IPV4_BYTE(ipV4.IpDnsServer,0));
553     \endcode
554     <br>
555 
556     - SL_NETCFG_IF: <br>
557     Get interface bitmap
558     \code
559         _u16 len;
560         _u32 IfBitmap;
561         len = sizeof(IfBitmap);
562         sl_NetCfgGet(SL_NETCFG_IF,NULL,&len,(_u8 *)&IfBitmap);
563     \endcode
564     <br>
565 
566     - SL_NETCFG_IPV6_ADDR_LOCAL: <br>
567     Get IPV6 Local address (ipV6.ipV6IsValid holds the address status. 1=Valid, ipv6 DAD completed and address is valid for use)
568     \code
569         SlNetCfgIpV6Args_t ipV6;
570         _u16 len = sizeof(SlNetCfgIpV6Args_t);
571         _u16 ConfigOpt = 0;  //return value could be one of the following: SL_NETCFG_ADDR_STATIC / SL_NETCFG_ADDR_STATELESS / SL_NETCFG_ADDR_STATEFUL
572 
573         sl_NetCfgGet(SL_NETCFG_IPV6_ADDR_LOCAL,&ConfigOpt,&len,(_u8 *)&ipV6);
574         if (SL_IS_IPV6_ADDR_VALID(ipV6.IpV6Flags))
575         {
576             printf("Ipv6 Local Address is valid: %8x:%8x:%8x:%8x\n", ipV6.Ip[0],ipV6.Ip[0],ipV6.Ip[0],ipV6.Ip[0]);
577         }
578         else
579         {
580             printf("Ipv6 Local Address is not valid, wait for DAD to complete or configure a different address");
581         }
582 
583     \endcode
584     <br>
585 
586     - SL_NETCFG_IPV6_ADDR_GLOBAL:<br>
587     Get IPV6 Global address (ipV6.ipV6IsValid holds the address status. 1=Valid, ipv6 DAD completed and address is valid for use)
588     \code
589         SlNetCfgIpV6Args_t ipV6;
590         _u16 len = sizeof(SlNetCfgIpV6Args_t);
591         _u16 ConfigOpt = 0;  //return value could be one of the following: SL_NETCFG_ADDR_STATIC  / SL_NETCFG_ADDR_STATEFUL
592 
593         if (SL_IS_IPV6_ADDR_VALID(ipV6.IpV6Flags))
594         {
595             printf("Ipv6 Global Address is valid: %8x:%8x:%8x:%8x\n", ipV6.Ip[0],ipV6.Ip[0],ipV6.Ip[0],ipV6.Ip[0]);
596         }
597         else
598         {
599             printf("Ipv6 Global Address is not valid, wait for DAD to complete or configure a different address");
600         }
601 
602     \endcode
603     <br>
604 
605     - SL_NETCFG_AP_STATIONS_NUM_CONNECTED: <br>
606       Get AP number of connected stations.
607     \code
608         _u8 num_ap_connected_sta;
609         _u16 len = sizeof(num_ap_connected_sta);
610         sl_NetCfgGet(SL_NETCFG_AP_STATIONS_NUM_CONNECTED, NULL, &len, &num_ap_connected_sta);
611         printf("AP number of connected stations = %d\n", num_ap_connected_sta);
612 
613     \endcode
614     <br>
615 
616     - SL_NETCFG_AP_STATIONS_INFO_LIST: <br>
617        Get AP full list of connected stationss.
618     \code
619         SlNetCfgStaInfo_t ApStaList[4];
620         _u16 sta_info_len;
621         _u16 start_sta_index = 0;
622         int actual_num_sta;
623         int i;
624 
625         start_sta_index = 0;
626         sta_info_len = sizeof(ApStaList);
627         sl_NetCfgGet(SL_NETCFG_AP_STATIONS_INFO_LIST, &start_sta_index, &sta_info_len, (_u8 *)ApStaList);
628 
629         actual_num_sta = sta_info_len / sizeof(SlNetCfgStaInfo_t);
630         printf("-Print SL_NETCFG_AP_STATIONS_INFO_LIST actual num_stations = %d (upon sta_info_len = %d)\n", actual_num_sta, sta_info_len);
631 
632         for (i=0; i<actual_num_sta; i++)
633         {
634             SlNetCfgStaInfo_t *staInfo = &ApStaList[i];
635             printf("  Ap Station %d is connected\n", i);
636             printf("    NAME: %s\n", staInfo->Name);
637             printf("    MAC:  %02x:%02x:%02x:%02x:%02x:%02x\n", staInfo->MacAddr[0], staInfo->MacAddr[1], staInfo->MacAddr[2], staInfo->MacAddr[3], staInfo->MacAddr[4], staInfo->MacAddr[5]);
638             printf("    IP:   %d.%d.%d.%d\n", SL_IPV4_BYTE(staInfo->Ip,3), SL_IPV4_BYTE(staInfo->Ip,2), SL_IPV4_BYTE(staInfo->Ip,1), SL_IPV4_BYTE(staInfo->Ip,0));
639         }
640 
641     \endcode
642     <br>
643 
644     - SL_NETCFG_IPV4_DNS_CLIENT: <br>
645     Get secondary DNS address (DHCP and static configuration)
646     \code
647         _u16 ConfigOpt = 0;
648         _i32 Status;
649         _u16 pConfigLen = sizeof(SlNetCfgIpV4DnsClientArgs_t);
650         SlNetCfgIpV4DnsClientArgs_t DnsOpt;
651         Status = sl_NetCfgGet(SL_NETCFG_IPV4_DNS_CLIENT,&ConfigOpt,&pConfigLen,&DnsOpt);
652         if( Status )
653         {
654             // error
655         }
656     \endcode
657     <br>
658 
659     - SL_NETCFG_IPV6_DNS_CLIENT: <br>
660     Get secondary DNS address (DHCP and static configuration)
661     \code
662         _u16 ConfigOpt = 0;
663         _i32 Status;
664         _u16 pConfigLen = sizeof(SlNetCfgIpV6DnsClientArgs_t);
665         SlNetCfgIpV6DnsClientArgs_t DnsOpt;
666         Status = sl_NetCfgGet(SL_NETCFG_IPV6_DNS_CLIENT,&ConfigOpt,&pConfigLen,&DnsOpt);
667         if( Status )
668         {
669             // error
670         }
671     \endcode
672 
673     - SL_NETCFG_IPV4_DHCP_CLIENT: <br>
674       Get DHCP Client info
675     \code
676         _u16 ConfigOpt = 0;
677         _u16 pConfigLen = sizeof(SlNetCfgIpv4DhcpClient_t);
678         SlNetCfgIpv4DhcpClient_t dhcpCl;
679         SlNetCfgIpV4Args_t ipV4 = {0};
680 
681         ret = sl_NetCfgGet(SL_NETCFG_IPV4_DHCP_CLIENT, &ConfigOpt, &pConfigLen, (_u8 *)&dhcpCl);
682         if(ret < 0)
683         {
684             printf("Error = %d\n", ret);
685         }
686     \endcode
687 
688 */
689 #if _SL_INCLUDE_FUNC(sl_NetCfgGet)
690 _i16 sl_NetCfgGet(const _u16 ConfigId ,_u16 *pConfigOpt, _u16 *pConfigLen, _u8 *pValues);
691 #endif
692 
693 /*!
694 
695  Close the Doxygen group.
696  @}
697 
698  */
699 
700 
701 #ifdef  __cplusplus
702 }
703 #endif /*  __cplusplus */
704 
705 #endif    /*  __NETCFG_H__ */
706 
707