The latest development version of this page may be more current than this released 2.3-beta.1 version.

Net Manager API Reference

Macro Definitions

WIFI_STATION_NETIF_NAME

Name of station netif.

WIFI_SOFTAP_NETIF_NAME

Name of softAP netif.

WM_NM_INVALID_NETIF

Invalid net manager netif handle.

Enumerations

enum wm_nm_netif_flag_e

Flag of net manager’s netif.

Values:

enumerator NM_NETIF_FLAG_UP
enumerator NM_NETIF_FLAG_BROADCAST

If set, the netif has broadcast capability.

If set, the interface has an active link

enumerator NM_NETIF_FLAG_ETHARP

If set, the netif is an ethernet device using ARP

enumerator NM_NETIF_FLAG_ETHERNET

If set, the netif is an ethernet device using ARP.

enumerator NM_NETIF_FLAG_IGMP

If set, the netif is an ethernet device.

enumerator NM_NETIF_FLAG_MLD6

If set, the netif has IGMP capability.

enum wm_nm_dns_type_t

Type of DNS server.

Values:

enumerator WM_NM_DNS_MAIN

DNS main server address.

enumerator WM_NM_DNS_BACKUP

DNS backup server address.

enum wm_nm_state_e

State of net manager.

Values:

enumerator WM_NM_INIT

net manager state: initializing.

enumerator WM_NM_WIFI_STA_CONNECTING

net manager state: connecting to AP. only for Wi-Fi station.

enumerator WM_NM_WIFI_STA_CONNECTED

net manager state: connected to AP. only for Wi-Fi station.

enumerator WM_NM_WIFI_STA_DISCONNECTED

net manager state: disconnect from AP. only for Wi-Fi station.

enumerator WM_NM_WIFI_STA_GOT_IP

net manager state: got IPv4. only for Wi-Fi station.

enumerator WM_NM_WIFI_STA_GOT_IP6

net manager state: got global IPv6. only for Wi-Fi station.

enumerator WM_NM_WIFI_STA_LOST_IP

net manager state: lost IPv4. only for Wi-Fi station.

enumerator WM_NM_WIFI_STA_LOST_IP6

net manager state: lost global IPv6. only for Wi-Fi station.

enumerator WM_NM_WIFI_AP_READY

net manager state: softAP is ready. only for Wi-Fi softap.

enumerator WM_NM_WIFI_AP_ASSIGNED_IP_ID

net manager state: softAP assigns IP to station. only for Wi-Fi softap.

enumerator WM_NM_EXIT

net manager state: exit, cannot be used.

Structures

struct wm_netif_ip_info_t

struct of ip info

struct wm_nm_dhcps_option_t

struct of dhcp server option

struct wm_nm_wifi_station_cfg_t

struct of Wi-Fi station config

struct wm_nm_wifi_softap_cfg_t

struct of Wi-Fi softap config

API References

Netif API

wm_nm_netif_t wm_nm_get_netif(void)

Query available netif.

Returns:

  • WM_NM_INVALID_NETIF: No available netif found

  • others: Available netif

int wm_nm_get_netif_number(void)

Query number of available netif.

Returns:

  • 0: No available netif

  • others: number of available netif

wm_nm_netif_t wm_nm_get_next_netif(wm_nm_netif_t netif)

Query next available netif.

Parameters:

netif[in] Current netif

Returns:

  • WM_NM_INVALID_NETIF: No next netif found

  • others: Available netif

const char *wm_nm_get_netif_name(wm_nm_netif_t netif)

Query netif name from net manager.

Parameters:

netif[in] Netif

Returns:

  • NULL: Invalid netif

  • others: Netif name

wm_nm_netif_t wm_nm_get_netif_by_name(const char *name)

Query netif by name.

Parameters:

name[in] Netif name

Returns:

  • WM_NM_INVALID_NETIF: No found netif

  • others: Available netif

int wm_nm_get_netif_flag(wm_nm_netif_t netif, uint32_t *flag)

Query the netif flag.

Parameters:
  • netif[in] Netif handle

  • flag[in] flag write back address

Returns:

  • WM_ERR_SUCCESS: succeed

  • WM_ERR_INVALID_PARAM: invalid argument

  • others: failed

int wm_nm_get_netif_mtu(wm_nm_netif_t netif, uint32_t *mtu)

Query the netif mtu.

Parameters:
  • netif[in] Netif handle

  • mtu[in] mtu write back address

Returns:

  • WM_ERR_SUCCESS: succeed

  • WM_ERR_INVALID_PARAM: invalid argument

  • others: failed

int wm_nm_set_netif_mac(wm_nm_netif_t netif, uint8_t *mac, size_t len)

Set the MAC address.

Parameters:
  • netif[in] Netif handle

  • mac[in] MAC address buffer

  • len[in] MAC address length

Returns:

  • WM_ERR_SUCCESS: succeed

  • WM_ERR_INVALID_PARAM: invalid argument

  • others: failed

int wm_nm_get_netif_mac(wm_nm_netif_t netif, uint8_t *mac, size_t *max_len)

Query the MAC address.

Parameters:
  • netif[in] Netif handle

  • mac[in] MAC address write back buffer

  • max_len[in] write back buffer maximum length

Returns:

  • WM_ERR_SUCCESS: succeed

  • WM_ERR_INVALID_PARAM: invalid argument

  • others: failed

int wm_nm_set_netif_ip_info(wm_nm_netif_t netif, wm_netif_ip_info_t *ip_info)

Set the IPv4 address.

Note

Set the IPv4 address, it will be stop DHCP client

Parameters:
  • netif[in] Netif handle

  • ip_info[in] include IPv4 address, net mask, gateway

Returns:

  • WM_ERR_SUCCESS: succeed

  • WM_ERR_INVALID_PARAM: invalid argument

  • others: failed

int wm_nm_get_netif_ip_info(wm_nm_netif_t netif, wm_netif_ip_info_t *ip_info)

Query the IPv4 address.

Note

After setting the IP, DHCP server/client will be stopped

Parameters:
  • netif[in] Netif handle

  • ip_info[in] Net info write back address

Returns:

  • WM_ERR_SUCCESS: succeed

  • WM_ERR_INVALID_PARAM: invalid argument

  • others: failed

int wm_nm_enable_netif_ip6(wm_nm_netif_t netif)

Enable IPv6 function.

Parameters:

netif[in] Netif handle

Returns:

  • WM_ERR_SUCCESS: succeed

  • WM_ERR_INVALID_PARAM: invalid argument

  • others: failed

int wm_nm_disable_netif_ip6(wm_nm_netif_t netif)

disable IPv6 function

Parameters:

netif[in] Netif handle

Returns:

  • WM_ERR_SUCCESS: succeed

  • WM_ERR_INVALID_PARAM: invalid argument

  • others: failed

bool wm_nm_get_netif_ip6_state(wm_nm_netif_t netif)

Query the IPv6 enable or disable.

Parameters:

netif[in] Netif handle

Returns:

  • FALSE: invalid argument or IPv6 is not enabled

  • TRUE: IPv6 is enabled

int wm_nm_get_netif_ip6_linklocal(wm_nm_netif_t netif, wm_ip6_addr_t *ip6)

Query the IPv6 address.

Parameters:
  • netif[in] Netif handle

  • ip6[in] IPv6 linklocal address write back address

Returns:

  • WM_ERR_SUCCESS: succeed

  • WM_ERR_INVALID_PARAM: invalid argument

  • others: failed

int wm_nm_get_netif_ip6_global(wm_nm_netif_t netif, wm_ip6_addr_t *ip6)

Query the IPv6 address.

Parameters:
  • netif[in] Netif handle

  • ip6[in] IPv6 global address write back address

Returns:

  • WM_ERR_SUCCESS: succeed

  • WM_ERR_INVALID_PARAM: invalid argument

  • others: failed

int wm_nm_set_netif_dhcps_option(wm_nm_netif_t netif, wm_nm_dhcps_option_t *dhcps_option)

Set DHCP server options.

Note

After DHCP server start, The original IP info will be overwritten

Parameters:
Returns:

  • WM_ERR_SUCCESS: succeed

  • WM_ERR_INVALID_PARAM: invalid argument

  • others: failed

int wm_nm_get_netif_dhcps_option(wm_nm_netif_t netif, wm_nm_dhcps_option_t *dhcps_option)

Query DHCP server options.

Parameters:
  • netif[in] Netif handle

  • dhcps_option[in] DHCP server options write back address

Returns:

  • WM_ERR_SUCCESS: succeed

  • WM_ERR_INVALID_PARAM: invalid argument

  • others: failed

int wm_nm_start_netif_dhcps(wm_nm_netif_t netif)

start DHCP server

Parameters:

netif[in] Netif handle

Returns:

  • WM_ERR_SUCCESS: succeed

  • WM_ERR_INVALID_PARAM: invalid argument

  • others: failed

int wm_nm_stop_netif_dhcps(wm_nm_netif_t netif)

stop DHCP server

Parameters:

netif[in] Netif handle

Returns:

  • WM_ERR_SUCCESS: succeed

  • WM_ERR_INVALID_PARAM: invalid argument

  • others: failed

int wm_nm_start_netif_dhcpc(wm_nm_netif_t netif)

start DHCP client

Note

if set static IP, start DHCP will fail,

Note

if you want restart DHCP, must set ip to “0.0.0.0” first.

Parameters:

netif[in] Netif handle

Returns:

  • WM_ERR_SUCCESS: succeed

  • WM_ERR_INVALID_PARAM: invalid argument

  • others: failed

int wm_nm_stop_netif_dhcpc(wm_nm_netif_t netif)

stop DHCP client

Parameters:

netif[in] Netif handle

Returns:

  • WM_ERR_SUCCESS: succeed

  • WM_ERR_INVALID_PARAM: invalid argument

  • others: failed

int wm_nm_set_dns(wm_nm_dns_type_t type, wm_ip_addr_t *dns)

Set DHCP server start.

Note

After setting DNS, DHCP server allocated DNS server will be ignored

Parameters:
  • type[in] DNS main server or backup server

  • dns[in] DNS server address

Returns:

  • WM_ERR_SUCCESS: succeed

  • WM_ERR_INVALID_PARAM: invalid argument

  • others: failed

int wm_nm_get_dns(wm_nm_dns_type_t type, wm_ip_addr_t *dns)

Query DHCP server start.

Parameters:
  • type[in] DNS main server or backup server

  • dns[in] DNS server address write back address

Returns:

  • WM_ERR_SUCCESS: succeed

  • WM_ERR_INVALID_PARAM: invalid argument

  • others: failed

int wm_nm_start_netif_dnss(wm_nm_netif_t netif)

start DNS server

Note

It only works on the softap mode.

Parameters:

netif[in] Netif handle

Returns:

  • WM_ERR_SUCCESS: succeed

  • WM_ERR_INVALID_PARAM: invalid argument

  • others: failed

int wm_nm_stop_netif_dnss(wm_nm_netif_t netif)

stop DNS server

Note

It only works on the softap mode.

Parameters:

netif[in] Netif handle

Returns:

  • WM_ERR_SUCCESS: succeed

  • WM_ERR_INVALID_PARAM: invalid argument

  • others: failed

WiFi API

int wm_nm_start_wifi_station(wm_nm_wifi_station_cfg_t *cfg)

Start Wi-Fi station mode, It will be init Wi-Fi and connected to the specified AP, as well as start the DHCP client.

Attention

This is asynchronous API. Please subscribe to the NM event, or call wm_nm_get_wifi_station_state to query the connection results

Parameters:

cfg[in] reference wm_nm_wifi_station_cfg_t

Returns:

  • WM_ERR_SUCCESS: succeed

  • WM_ERR_INVALID_PARAM: invalid argument

  • others: failed

wm_nm_state_e wm_nm_get_wifi_station_state(void)

Query NM Wi-Fi station state.

Returns:

  • reference wm_nm_state_e

int wm_nm_stop_wifi_station(void)

Stop Wi-Fi station mode, It will be disconnect from AP.

Returns:

  • WM_ERR_SUCCESS: succeed

  • others: failed

int wm_nm_start_wifi_softap(wm_nm_wifi_softap_cfg_t *cfg)

Start Wi-Fi softAP, It will be started soft AP and DHCP server.

Note

This is asynchronous API. Please subscribe to the NM event, or call wm_nm_get_wifi_softap_state to query the softAP state

Parameters:

cfg[in] reference wm_nm_wifi_softap_cfg_t

Returns:

  • WM_ERR_SUCCESS: succeed

  • WM_ERR_INVALID_PARAM: invalid argument

  • others: failed

wm_nm_state_e wm_nm_get_wifi_softap_state(void)

Query NM Wi-Fi softAP state.

Returns:

  • reference wm_nm_state_e

int wm_nm_stop_wifi_softap(void)

Stop Wi-Fi softAP.

Returns:

  • WM_ERR_SUCCESS: succeed

  • others: failed