WE310F5  39.00.000
M2MB NWIF

This section describes the M2MB APIs for Network Interface. More...

#define M2MB_NWIF_HOSTNAME_SIZE   (32)
 
enum  M2MB_NWIF_EVENT_E {
  M2MB_NWIF_IPV4CFG_GET_IP_E =(1 << 0),
  M2MB_NWIF_IPV4CFG_STATIC_IP_E =(1 << 1),
  M2MB_NWIF_IPV4CFG_DHCPC_IP_E =(1 << 2),
  M2MB_NWIF_IPV4CFG_DHCPS_CLIENT_IP_E =(1 << 3),
  M2MB_NWIF_IPV4CFG_AUTO_IP_E =(1 << 4),
  M2MB_NWIF_IPV6CFG_GET_IP_E =(1 << 5),
  M2MB_NWIF_IPV6CFG_DHCPC_IP_E =(1 << 6),
  M2MB_NWIF_IPV6CFG_AUTO_IP_E =(1 << 7),
  M2MB_NWIF_DNS_SERVER_LIST_E =(1 << 8)
}
 Commands for NWIF API's.
More...
 
enum  M2MB_NWIF_STATUS {
  M2MB_NWIF_STATUS_NOT_INITIALIZED_E,
  M2MB_NWIF_STATUS_INITIALIZED_E,
  M2MB_NWIF_STATUS_OPEN_IN_PROGRESS_E,
  M2MB_NWIF_STATUS_OPEN_DONE_E
}
 NWIF status enumeration. More...
 
typedef enum M2MB_NWIF_STATUS M2MB_NWIF_STATUS_E
 NWIF status enumeration. More...
 
typedef struct M2MB_NWIF_IPV4_CONFIG M2MB_NWIF_IPV4_CONFIG_T
 IPV4 configuration. More...
 
typedef struct M2MB_NWIF_IPV6_CONFIG M2MB_NWIF_IPV6_CONFIG_T
 IPV6 configuration. More...
 
typedef struct M2MB_NWIF_DHCPV4_CLIENT M2MB_NWIF_DHCPV4_CLIENT_T
 DHCP client configuration in case of DHCP server. More...
 
typedef struct M2MB_NWIF_DNS_SERVER_LIST M2MB_NWIF_DNS_SERVER_LIST_T
 For use with m2mb_nwif_cfgget() to get IP addresses of DNS servers. More...
 
typedef VOID(* M2MB_NWIF_IPCONFIG_CB) (UINT8 deviceId, VOID *cbctx, M2MB_NWIF_EVENT_E eventid, M2MB_NWIF_CFG_T *data)
 NWIF call back prototype. More...
 
M2MB_BOOL_T m2mb_nwif_wlan_devname_get (UINT8 deviceId, CHAR **pWifname)
 WLAN device name. More...
 
INT32 m2mb_nwif_init (UINT8 deviceId, M2MB_NWIF_IPCONFIG_CB cb, VOID *cbctx)
 Network interface initialization. More...
 
INT32 m2mb_nwif_open (UINT8 deviceId, M2MB_NWIF_EVENT_E ip_flag)
 Network interface open. More...
 
INT32 m2mb_nwif_cfgget (UINT8 deviceId, M2MB_NWIF_EVENT_E cfgflag, M2MB_NWIF_CFG_T *pCfg)
 Network interface configuration. More...
 
INT32 m2mb_nwif_cfgset (UINT8 deviceId, M2MB_NWIF_EVENT_E cfgflag, M2MB_NWIF_CFG_T *pCfg)
 Network interface configuration. More...
 
INT32 m2mb_nwif_close (UINT8 deviceId)
 Network interface close. More...
 
INT32 m2mb_nwif_Set_Hostname (const char *hostname)
 Set hostname. More...
 
INT32 m2mb_nwif_deinit (UINT8 deviceId)
 Network interface de-initialization. More...
 
INT32 m2mb_nwif_dhcpv4s (UINT8 deviceId, char *start_ip_addr_string, char *end_ip_addr_string, int leasetime)
 Network interface close. More...
 
INT32 m2mb_nwif_check_ip_addr_valid (INT32 ipaddress)
 
VOID m2mb_nwif_lwip_init (VOID)
 

Detailed Description

This section describes the M2MB APIs for Network Interface.

NWIF is used to configure IPv4 and IPv6 on specified WLAN. once the WLAN gets connected, IP can be configured on specified WLAN.

Macro Definition Documentation

◆ M2MB_NWIF_HOSTNAME_SIZE

#define M2MB_NWIF_HOSTNAME_SIZE   (32)

Macro for Host name maximum size in bytes

Definition at line 49 of file m2mb_nwif.h.

Typedef Documentation

◆ M2MB_NWIF_DHCPV4_CLIENT_T

DHCP client configuration in case of DHCP server.

◆ M2MB_NWIF_DNS_SERVER_LIST_T

For use with m2mb_nwif_cfgget() to get IP addresses of DNS servers.

◆ M2MB_NWIF_IPCONFIG_CB

typedef VOID(* M2MB_NWIF_IPCONFIG_CB) (UINT8 deviceId, VOID *cbctx, M2MB_NWIF_EVENT_E eventid, M2MB_NWIF_CFG_T *data)

NWIF call back prototype.

Type definition of the user callback to receive asynchronous events from NWIF. cbctx represents user context registered in 'm2mb_nwif_init', eventid is asynchronous events from NWIF. data is data from NWIF of IP configuration.

Note
this callback gets called only when ip configuration succeeds.

Definition at line 161 of file m2mb_nwif.h.

◆ M2MB_NWIF_IPV4_CONFIG_T

IPV4 configuration.

◆ M2MB_NWIF_IPV6_CONFIG_T

IPV6 configuration.

◆ M2MB_NWIF_STATUS_E

NWIF status enumeration.

This enum defines macros for various Network Interface status. These status signify present state of the Interface.

Enumeration Type Documentation

◆ M2MB_NWIF_EVENT_E

Commands for NWIF API's.

Enumerator
M2MB_NWIF_IPV4CFG_GET_IP_E 

Commands for IPv4 Configuration.

Get command: get IPv4 parameters of an interface, such as IP address, subnet mask and default gateway Set command:Assign static IPv4 address, subnet mask and default gateway

M2MB_NWIF_IPV4CFG_STATIC_IP_E 

Set command:Run DHCPv4 client to obtain IPv4 parameters from DHCPv4 server

M2MB_NWIF_IPV4CFG_DHCPC_IP_E 

Get command:Run DHCPv4 SERVER to provide IPv4 parameters to DHCPv4 client

M2MB_NWIF_IPV4CFG_DHCPS_CLIENT_IP_E 

Set command:Run auto-IP (Automatic Private IP Addressing)

M2MB_NWIF_IPV4CFG_AUTO_IP_E 
M2MB_NWIF_IPV6CFG_GET_IP_E 

Commands for IPv6 Configuration.

Get command:Get IPv6 parameters of an interface, such as IP address, subnet mask and default gateway Set command:Run DHCPv6 client to obtain IPv6 parameters from DHCPv6 server

M2MB_NWIF_IPV6CFG_DHCPC_IP_E 

Set command:Run auto-IP (Automatic Private IP Addressing)

M2MB_NWIF_IPV6CFG_AUTO_IP_E 
M2MB_NWIF_DNS_SERVER_LIST_E 

Commands for DNS Configuration get.

Get command:IPv4 or IPv6 DNS server addresses

Definition at line 56 of file m2mb_nwif.h.

◆ M2MB_NWIF_STATUS

NWIF status enumeration.

This enum defines macros for various Network Interface status. These status signify present state of the Interface.

Enumerator
M2MB_NWIF_STATUS_NOT_INITIALIZED_E 

Network Interface is not initialized.

M2MB_NWIF_STATUS_INITIALIZED_E 

Network Interface is initialized.

M2MB_NWIF_STATUS_OPEN_IN_PROGRESS_E 

Open is initiated, but not completed yet.

M2MB_NWIF_STATUS_OPEN_DONE_E 

IP configuration successfully completed.

Definition at line 103 of file m2mb_nwif.h.

Function Documentation

◆ m2mb_nwif_cfgget()

INT32 m2mb_nwif_cfgget ( UINT8  deviceId,
M2MB_NWIF_EVENT_E  cfgflag,
M2MB_NWIF_CFG_T pCfg 
)

Network interface configuration.

Network Interface configuration for static IP.

Parameters
[in]deviceIdWLAN deviceId, it should be greater than or equal to 0"
[in]cfgflagConfiguration flag, this is anyone of the NWIF_EVENT_T events to get.
[in]pCfgUser buffer to get the configuration values.
Returns

M2MB_OK in case of success M2MB_ERROR in case of error
Example
void wlan_cb(UINT8 deviceid, UINT8 event_id, INT8 status, VOID *data)
{
//this call back will be called when WLAN connection get success.
}
int32_t nwif_cb(VOID *cbctx, NWIF_EVENT_T eventid, UINT8 *data)
{
//this call back will be called when IP or DNS configuration succeeds.
}
VOID *cbctx;
void main(void)
{
int ret;
UINT8 deviceid;
UINT8 device_id = 2;
UINT8 *ssid = "scan_ap";
INT8 result;
result = m2m_wlan_init();
if (result != 0)
{
return -1;
}
if (result == -1)
{
return -1;
}
if(device_id != 0 || device_id != 1)
return -1;
result = m2m_wlan_connect ( device_id, ssid);
ret = m2mb_nwif_init( deviceId, nwif_cb, cbctx);
ret = m2mb_nwif_open( deviceId, cfgflag);
ret = m2mb_nwif_cfgget(deviceId, cfgflag, &ipcfg);
//can print ip configuration values here, if m2mb_nwif_cfgget get success.
ret = m2mb_nwif_close( deviceId );
ret = m2mb_nwif_deinit( deviceId );
}

◆ m2mb_nwif_cfgset()

INT32 m2mb_nwif_cfgset ( UINT8  deviceId,
M2MB_NWIF_EVENT_E  cfgflag,
M2MB_NWIF_CFG_T pCfg 
)

Network interface configuration.

Network Interface configuration for static IP.

Parameters
[in]deviceIdWLAN deviceId, it should be greater than or equal to 0"
[in]cfgflagConfiguration flag, this is anyone of the NWIF_EVENT_T events to set.
[in]pCfgUser buffer to get the configuration values.
Returns

M2MB_OK in case of success M2MB_ERROR in case of error
Example
void wlan_cb(UINT8 deviceid, UINT8 event_id, INT8 status, VOID *data)
{
//this call back will be called when WLAN connection get success.
}
int32_t nwif_cb(VOID *cbctx, NWIF_EVENT_T eventid, UINT8 *data)
{
//this call back will be called when IP or DNS configuration succeeds.
switch(Eventid)
{
case M2MB_NWIF_IPV4CFG_GET_IP:
{
char ip_str[20];
char mask_str[20];
char gw_str[20];
m2mb_dbg_printf("DHCPv4c: IP=%s Subnet Mask=%s Gateway=%s\r\n",
m2mb_socket_bsd_inet_ntop(M2MB_SOCKET_BSD_AF_INET, &pCfg->ipv4cfg.addr, ip_str, sizeof(ip_str)),
m2mb_socket_bsd_inet_ntop(M2MB_SOCKET_BSD_AF_INET, &pCfg->ipv4cfg.mask, mask_str, sizeof(mask_str)),
m2mb_socket_bsd_inet_ntop(M2MB_SOCKET_BSD_AF_INET, &pCfg->ipv4cfg.gw, gw_str, sizeof(gw_str)));
}
break;
case M2MB_NWIF_IPV4CFG_DHCPS_CLIENT_IP:
{
char ip_str[20];
m2mb_dbg_printf("DHCPv4s: Client IP=%s Client MAC=%02x:%02x:%02x:%02x:%02x:%02x\n",
m2mb_socket_bsd_inet_ntop(M2MB_SOCKET_BSD_AF_INET, &ipaddr, ip_str, sizeof(ip_str)),
macaddr[0], macaddr[1], macaddr[2], macaddr[3], macaddr[4], macaddr[5]);
}
break;
}
}
VOID *cbctx;
void main(void)
{
int ret;
UINT8 deviceid;
UINT8 device_id = 2;
UINT8 *ssid = "scan_ap";
INT8 result;
result = m2m_wlan_init();
if (result != 0)
{
return -1;
}
if (result == -1)
{
return -1;
}
if(device_id != 0 || device_id != 1)
return -1;
result = m2m_wlan_connect ( device_id, ssid);
ret = m2mb_nwif_init( deviceId, nwif_cb, cbctx);
ipcfg.ipv4cfg.addr = Ipaddr;
ipcfg.ipv4cfg.mask = mask;
ipcfg.ipv4cfg.gw = gw;
ret = m2mb_nwif_cfgset(deviceId, cfgflag, &ipcfg);
ret = m2mb_nwif_open( deviceId, cfgflag);
ret = m2mb_nwif_close( deviceId );
ret = m2mb_nwif_deinit( deviceId );
}

◆ m2mb_nwif_check_ip_addr_valid()

INT32 m2mb_nwif_check_ip_addr_valid ( INT32  ipaddress)

◆ m2mb_nwif_close()

INT32 m2mb_nwif_close ( UINT8  deviceId)

Network interface close.

it closes the network interface of corresponding WLAN interface.

Parameters
[in]deviceIdWLAN deviceId, it should be greater than or equal to 0"
Returns

M2MB_OK in case of success M2MB_ERROR in case of error Example
void wlan_cb(UINT8 deviceid, UINT8 event_id, INT8 status, VOID *data)
{
//this call back will be called when WLAN connection get success.
}
int32_t nwif_cb(VOID *cbctx, NWIF_EVENT_T eventid, UINT8 *data)
{
//this call back will be called when IP or DNS configuration succeeds.
switch(Eventid)
{
case M2MB_NWIF_IPV4CFG_GET_IP:
{
char ip_str[20];
char mask_str[20];
char gw_str[20];
m2mb_dbg_printf("DHCPv4c: IP=%s Subnet Mask=%s Gateway=%s\r\n",
m2mb_socket_bsd_inet_ntop(M2MB_SOCKET_BSD_AF_INET, &pCfg->ipv4cfg.addr, ip_str, sizeof(ip_str)),
m2mb_socket_bsd_inet_ntop(M2MB_SOCKET_BSD_AF_INET, &pCfg->ipv4cfg.mask, mask_str, sizeof(mask_str)),
m2mb_socket_bsd_inet_ntop(M2MB_SOCKET_BSD_AF_INET, &pCfg->ipv4cfg.gw, gw_str, sizeof(gw_str)));
}
break;
case M2MB_NWIF_IPV4CFG_DHCPS_CLIENT_IP:
{
char ip_str[20];
m2mb_dbg_printf("DHCPv4s: Client IP=%s Client MAC=%02x:%02x:%02x:%02x:%02x:%02x\n",
m2mb_socket_bsd_inet_ntop(M2MB_SOCKET_BSD_AF_INET, &ipaddr, ip_str, sizeof(ip_str)),
macaddr[0], macaddr[1], macaddr[2], macaddr[3], macaddr[4], macaddr[5]);
}
break;
}
}
VOID *cbctx;
void main(void)
{
int ret;
UINT8 deviceid;
M2MB_NWIF_EVENT_E ip_flag = M2MB_NWIF_IPV4CFG_DHCPC_IP;
UINT8 device_id = 2;
UINT8 *ssid = "scan_ap";
INT8 result;
result = m2m_wlan_init();
if (result != 0)
{
return -1;
}
if (result == -1)
{
return -1;
}
if(device_id != 0 || device_id != 1)
return -1;
result = m2m_wlan_connect ( device_id, ssid);
//m2mb_nwif_init function should be called after WLAN connection done.
//wlan_cb callback will be called once WLAN connection success.
ret = m2mb_nwif_init( deviceId, nwif_cb, cbctx);
ret = m2mb_nwif_open( deviceId, ip_flag);
ret = m2mb_nwif_close( deviceId );
ret = m2mb_nwif_deinit( deviceId );
}

◆ m2mb_nwif_deinit()

INT32 m2mb_nwif_deinit ( UINT8  deviceId)

Network interface de-initialization.

De-initializing user callback and de-initializing network interface.

Parameters
[in]deviceIdWLAN deviceId, it should be greater than or equal to 0"
Returns

M2MB_OK in case of success M2MB_ERROR in case of error
Example
void wlan_cb(UINT8 deviceid, UINT8 event_id, INT8 status, VOID *data)
{
//this call back will be called when WLAN connection get success.
}
int32_t nwif_cb(VOID *cbctx, NWIF_EVENT_T eventid, UINT8 *data)
{
//this call back will be called when IP or DNS configuration succeeds.
switch(Eventid)
{
case M2MB_NWIF_IPV4CFG_GET_IP:
{
char ip_str[20];
char mask_str[20];
char gw_str[20];
m2mb_dbg_printf("DHCPv4c: IP=%s Subnet Mask=%s Gateway=%s\r\n",
m2mb_socket_bsd_inet_ntop(M2MB_SOCKET_BSD_AF_INET, &pCfg->ipv4cfg.addr, ip_str, sizeof(ip_str)),
m2mb_socket_bsd_inet_ntop(M2MB_SOCKET_BSD_AF_INET, &pCfg->ipv4cfg.mask, mask_str, sizeof(mask_str)),
m2mb_socket_bsd_inet_ntop(M2MB_SOCKET_BSD_AF_INET, &pCfg->ipv4cfg.gw, gw_str, sizeof(gw_str)));
}
break;
case M2MB_NWIF_IPV4CFG_DHCPS_CLIENT_IP:
{
char ip_str[20];
m2mb_dbg_printf("DHCPv4s: Client IP=%s Client MAC=%02x:%02x:%02x:%02x:%02x:%02x\n",
m2mb_socket_bsd_inet_ntop(M2MB_SOCKET_BSD_AF_INET, &ipaddr, ip_str, sizeof(ip_str)),
macaddr[0], macaddr[1], macaddr[2], macaddr[3], macaddr[4], macaddr[5]);
}
break;
}
}
VOID *cbctx;
void main(void)
{
int ret;
UINT8 deviceid;
UINT8 device_id = 2;
UINT8 *ssid = "scan_ap";
INT8 result;
result = m2m_wlan_init();
if (result != 0)
{
return -1;
}
if (result == -1)
{
return -1;
}
if(device_id != 0 || device_id != 1)
return -1;
result = m2m_wlan_connect ( device_id, ssid);
ret = m2mb_nwif_init( deviceId, nwif_cb, cbctx);
ret = m2mb_nwif_open( deviceId, ip_flag);
ret = m2mb_nwif_close( deviceId );
ret = m2mb_nwif_deinit( deviceId );
}

◆ m2mb_nwif_dhcpv4s()

INT32 m2mb_nwif_dhcpv4s ( UINT8  deviceId,
char *  start_ip_addr_string,
char *  end_ip_addr_string,
int  leasetime 
)

Network interface close.

It closes the network interface of the corresponding WLAN interface.

Parameters
[in]deviceIdWLAN deviceID, it should be greater than or equal to 0"
[in]start_ip_addr_stringStart IP address of DHCP range.
[in]end_ip_addr_stringEnd IP address of DHCP range.
[in]leasetimeReservation time for an IP address on the network.
Returns

M2MB_OK in case of success M2MB_ERROR in case of error Example
void wlan_cb(UINT8 deviceid, UINT8 event_id, INT8 status, VOID *data)
{
//this call back will be called when WLAN connection get success.
}
int32_t nwif_cb(VOID *cbctx, NWIF_EVENT_T eventid, UINT8 *data)
{
//this call back will be called when IP or DNS configuration succeeds.
switch(Eventid)
{
case M2MB_NWIF_IPV4CFG_GET_IP:
{
char ip_str[20];
char mask_str[20];
char gw_str[20];
m2mb_dbg_printf("DHCPv4c: IP=%s Subnet Mask=%s Gateway=%s\r\n",
m2mb_socket_bsd_inet_ntop(M2MB_SOCKET_BSD_AF_INET, &pCfg->ipv4cfg.addr, ip_str, sizeof(ip_str)),
m2mb_socket_bsd_inet_ntop(M2MB_SOCKET_BSD_AF_INET, &pCfg->ipv4cfg.mask, mask_str, sizeof(mask_str)),
m2mb_socket_bsd_inet_ntop(M2MB_SOCKET_BSD_AF_INET, &pCfg->ipv4cfg.gw, gw_str, sizeof(gw_str)));
}
break;
case M2MB_NWIF_IPV4CFG_DHCPS_CLIENT_IP:
{
char ip_str[20];
m2mb_dbg_printf("DHCPv4s: Client IP=%s Client MAC=%02x:%02x:%02x:%02x:%02x:%02x\n",
m2mb_socket_bsd_inet_ntop(AF_INET, &ipaddr, ip_str, sizeof(ip_str)),
macaddr[0], macaddr[1], macaddr[2], macaddr[3], macaddr[4], macaddr[5]);
}
break;
}
}
VOID *cbctx;
void main(void)
{
int ret;
UINT8 deviceid;
UINT8 device_id = 2;
UINT8 *ssid = "scan_ap";
INT8 result;
result = m2m_wlan_init();
if (result != 0)
{
return -1;
}
if (result == -1)
{
return -1;
}
if(device_id != 0 || device_id != 1)
return -1;
result = m2m_wlan_connect ( device_id, ssid);
ret = m2mb_nwif_init( deviceId, nwif_cb, cbctx);
ipcfg.ipv4cfg.addr = Ipaddr;
ipcfg.ipv4cfg.mask = mask;
ipcfg.ipv4cfg.gw = gw;
ret = m2mb_nwif_cfgset(deviceId, cfgflag, &ipcfg);
{
if(M2MB_ERROR == m2mb_nwif_dhcpv4s(device_id, "192.168.120.3","192.168.120.40", 1000 ))
{
m2mb_dbg_printf("m2mb_nwif_dhcpv4s:failed\r\n");
}
else
{
m2mb_dbg_printf("m2mb_nwif_dhcpv4s:success\r\n");
}
}
}

◆ m2mb_nwif_init()

INT32 m2mb_nwif_init ( UINT8  deviceId,
M2MB_NWIF_IPCONFIG_CB  cb,
VOID cbctx 
)

Network interface initialization.

Initializing user callback and initializing network interface.

Parameters
[in]deviceIdWLAN deviceId, it should be greater than or equal to 0"
[in]cbuser call back of type M2MB_NWIF_IPCONFIG_CB.
[in]cbctxuser call back context.
Returns

M2MB_OK in case of success M2MB_ERROR in case of error
Example
void wlan_cb(UINT8 deviceid, UINT8 event_id, INT8 status, VOID *data)
{
//this call back will be called when WLAN connection get success.
}
int32_t nwif_cb(VOID *cbctx, NWIF_EVENT_T eventid, UINT8 *data)
{
//this call back will be called when IP or DNS configuration succeeds.
switch(Eventid)
{
case M2MB_NWIF_IPV4CFG_GET_IP:
{
char ip_str[20];
char mask_str[20];
char gw_str[20];
m2mb_dbg_printf("DHCPv4c: IP=%s Subnet Mask=%s Gateway=%s\r\n",
m2mb_socket_bsd_inet_ntop(M2MB_SOCKET_BSD_AF_INET, &pCfg->ipv4cfg.addr, ip_str, sizeof(ip_str)),
m2mb_socket_bsd_inet_ntop(M2MB_SOCKET_BSD_AF_INET, &pCfg->ipv4cfg.mask, mask_str, sizeof(mask_str)),
m2mb_socket_bsd_inet_ntop(M2MB_SOCKET_BSD_AF_INET, &pCfg->ipv4cfg.gw, gw_str, sizeof(gw_str)));
}
break;
case M2MB_NWIF_IPV4CFG_DHCPS_CLIENT_IP:
{
char ip_str[20];
m2mb_dbg_printf("DHCPv4s: Client IP=%s Client MAC=%02x:%02x:%02x:%02x:%02x:%02x\n",
m2mb_socket_bsd_inet_ntop(M2MB_SOCKET_BSD_AF_INET, &ipaddr, ip_str, sizeof(ip_str)),
macaddr[0], macaddr[1], macaddr[2], macaddr[3], macaddr[4], macaddr[5]);
}
break;
}
}
VOID *cbctx;
void main(void)
{
int ret;
UINT8 deviceid;
UINT8 device_id = 2;
UINT8 *ssid = "scan_ap";
INT8 result;
result = m2m_wlan_init();
if (result != 0)
{
return -1;
}
if (result == -1)
{
return -1;
}
if(device_id != 0 || device_id != 1)
return -1;
result = m2m_wlan_connect ( device_id, ssid);
ret = m2mb_nwif_init( deviceId, nwif_cb, cbctx);
}

◆ m2mb_nwif_lwip_init()

VOID m2mb_nwif_lwip_init ( VOID  )

◆ m2mb_nwif_open()

INT32 m2mb_nwif_open ( UINT8  deviceId,
M2MB_NWIF_EVENT_E  ip_flag 
)

Network interface open.

It configures the IP address for an active WLAN interface.

Parameters
[in]deviceIdWLAN deviceId, it should be greater than or equal to 0"
[in]ip_flagIt is an IP address type required to configure IP address on a given device. M2MB_NWIF_IPV4CFG_STATIC_IP_E M2MB_NWIF_IPV4CFG_DHCPC_IP M2MB_NWIF_IPV4CFG_AUTO_IP_E M2MB_NWIF_IPV6CFG_DHCP_IP_E M2MB_NWIF_IPV6CFG_AUTO_IP_E
Returns

M2MB_OK in case of success M2MB_ERROR in case of error
Note
Before calling this function static IP should be set by using m2mb_nwif_cfgset API if the ip_flag is M2MB_NWIF_IPV4CFG_STATIC_IP_E in m2mb_nwif_open function call. Example
void wlan_cb(UINT8 deviceid, UINT8 event_id, INT8 status, VOID *data)
{
//this call back will be called when WLAN connection get success.
}
int32_t nwif_cb(VOID *cbctx, NWIF_EVENT_T eventid, UINT8 *data)
{
//this call back will be called when IP or DNS configuration succeeds.
switch(Eventid)
{
case M2MB_NWIF_IPV4CFG_GET_IP:
{
char ip_str[20];
char mask_str[20];
char gw_str[20];
m2mb_dbg_printf("DHCPv4c: IP=%s Subnet Mask=%s Gateway=%s\r\n",
m2mb_socket_bsd_inet_ntop(M2MB_SOCKET_BSD_AF_INET, &pCfg->ipv4cfg.addr, ip_str, sizeof(ip_str)),
m2mb_socket_bsd_inet_ntop(M2MB_SOCKET_BSD_AF_INET, &pCfg->ipv4cfg.mask, mask_str, sizeof(mask_str)),
m2mb_socket_bsd_inet_ntop(M2MB_SOCKET_BSD_AF_INET, &pCfg->ipv4cfg.gw, gw_str, sizeof(gw_str)));
}
break;
case M2MB_NWIF_IPV4CFG_DHCPS_CLIENT_IP:
{
char ip_str[20];
m2mb_dbg_printf("DHCPv4s: Client IP=%s Client MAC=%02x:%02x:%02x:%02x:%02x:%02x\n",
m2mb_socket_bsd_inet_ntop(M2MB_SOCKET_BSD_AF_INET, &ipaddr, ip_str, sizeof(ip_str)),
macaddr[0], macaddr[1], macaddr[2], macaddr[3], macaddr[4], macaddr[5]);
}
break;
}
}
VOID *cbctx;
void main(void)
{
int ret;
UINT8 deviceid;
M2MB_NWIF_EVENT_E ip_flag = M2MB_NWIF_IPV4CFG_DHCPC_IP;
UINT8 device_id = 2;
UINT8 *ssid = "scan_ap";
INT8 result;
result = m2m_wlan_init();
if (result != 0)
{
return -1;
}
if (result == -1)
{
return -1;
}
if(device_id != 0 || device_id != 1)
return -1;
result = m2m_wlan_connect ( device_id, ssid);
//m2mb_nwif_init function should be called after WLAN connection done.
//wlan_cb callback will be called once WLAN connection success.
ret = m2mb_nwif_init( deviceId, nwif_cb, cbctx);
ret = m2mb_nwif_open( deviceId, ip_flag);
ret = m2mb_nwif_close( deviceId );
ret = m2mb_nwif_deinit( deviceId );
}

◆ m2mb_nwif_Set_Hostname()

INT32 m2mb_nwif_Set_Hostname ( const char *  hostname)

Set hostname.

it sets the host name.

Parameters
[in]hostnameHost name, it should be a maximum length of M2MB_NWIF_HOSTNAME_SIZE.
Returns

M2MB_OK in case of success M2MB_ERROR in case of error Example
void wlan_cb(UINT8 deviceid, UINT8 event_id, INT8 status, VOID *data)
{
//this call back will be called when WLAN connection get success.
}
int32_t nwif_cb(VOID *cbctx, NWIF_EVENT_T eventid, UINT8 *data)
{
//this call back will be called when IP or DNS configuration succeeds.
switch(Eventid)
{
case M2MB_NWIF_IPV4CFG_GET_IP:
{
char ip_str[20];
char mask_str[20];
char gw_str[20];
m2mb_dbg_printf("DHCPv4c: IP=%s Subnet Mask=%s Gateway=%s\r\n",
m2mb_socket_bsd_inet_ntop(M2MB_SOCKET_BSD_AF_INET, &pCfg->ipv4cfg.addr, ip_str, sizeof(ip_str)),
m2mb_socket_bsd_inet_ntop(M2MB_SOCKET_BSD_AF_INET, &pCfg->ipv4cfg.mask, mask_str, sizeof(mask_str)),
m2mb_socket_bsd_inet_ntop(M2MB_SOCKET_BSD_AF_INET, &pCfg->ipv4cfg.gw, gw_str, sizeof(gw_str)));
}
break;
case M2MB_NWIF_IPV4CFG_DHCPS_CLIENT_IP:
{
char ip_str[20];
m2mb_dbg_printf("DHCPv4s: Client IP=%s Client MAC=%02x:%02x:%02x:%02x:%02x:%02x\n",
m2mb_socket_bsd_inet_ntop(M2MB_SOCKET_BSD_AF_INET, &ipaddr, ip_str, sizeof(ip_str)),
macaddr[0], macaddr[1], macaddr[2], macaddr[3], macaddr[4], macaddr[5]);
}
break;
}
}
VOID *cbctx;
void main(void)
{
int ret;
UINT8 deviceid;
M2MB_NWIF_EVENT_E ip_flag = M2MB_NWIF_IPV4CFG_DHCPC_IP;
UINT8 device_id = 2;
UINT8 *ssid = "scan_ap";
INT8 result;
result = m2m_wlan_init();
if (result != 0)
{
return -1;
}
if (result == -1)
{
return -1;
}
if(device_id != 0 || device_id != 1)
return -1;
result = m2m_wlan_connect ( device_id, ssid);
//m2mb_nwif_init function should be called after WLAN connection done.
//wlan_cb callback will be called once WLAN connection success.
ret = m2mb_nwif_init( deviceId, nwif_cb, cbctx);
ret = m2mb_nwif_Set_Hostname( "Telit_Device" );
ret = m2mb_nwif_open( deviceId, ip_flag);
ret = m2mb_nwif_close( deviceId );
ret = m2mb_nwif_deinit( deviceId );
}

◆ m2mb_nwif_wlan_devname_get()

M2MB_BOOL_T m2mb_nwif_wlan_devname_get ( UINT8  deviceId,
CHAR **  pWifname 
)

WLAN device name.

This API provides the WLAN device name for the corresponding device ID.

Parameters
[in]deviceIdWLAN deviceId, it should be either 0 or 1.
[out]pWifnamePointer to the device name.
Returns

TRUE in case interface is UP. FALSE in case interface is DOWN. Example
void wlan_cb(UINT8 deviceid, UINT8 event_id, INT8 status, VOID *data)
{
//this call back will be called when WLAN connection get success.
}
void main(void)
{
char *pWifname;
UINT8 deviceid;
UINT8 device_id = 2;
UINT8 *ssid = "scan_ap";
INT8 result;
result = m2m_wlan_init();
if (result != 0)
{
return -1;
}
if (result == -1)
{
return -1;
}
if(device_id != 0 || device_id != 1)
return -1;
result = m2m_wlan_connect ( device_id, ssid);
if( FALSE == m2mb_nwif_wlan_devname_get(deviceId, &pWifname))
return M2MB_ERROR;
}