Morse Micro IoT SDK  2.9.7
Morse Micro IP Stack Abstraction Layer (MMIPAL) API

Detailed Description

This API provides a layer of abstraction from the underlying IP stack for common operations such as configuring the link and getting link status.

Data Structures

struct  mmipal_ip_config
 IPv4 configuration structure. More...
 
struct  mmipal_ip6_config
 IPv6 configuration structure. More...
 
struct  mmipal_init_args
 Initialize arguments structure. More...
 
struct  mmipal_link_status
 Structure representing the current status of the link. More...
 

Macros

#define MMIPAL_IPADDR_STR_MAXLEN   (48)
 Maximum length of an IP address string, including null-terminator. More...
 
#define MMIPAL_MAX_IPV6_ADDRESSES   (3)
 Maximum number of IPv6 addresses supported. More...
 
#define MMIPAL_IP_CONFIG_DEFAULT   { MMIPAL_DHCP, "", "", "", }
 Initializer for mmipal_ip_config. More...
 
#define MMIPAL_IP6_CONFIG_DEFAULT   { MMIPAL_IP6_AUTOCONFIG }
 Initializer for mmipal_ip6_config. More...
 
#define MMIPAL_INIT_ARGS_DEFAULT
 Default values for mmipal_init_args. More...
 

Typedefs

typedef char mmipal_ip_addr_t[MMIPAL_IPADDR_STR_MAXLEN]
 IP address string type. More...
 
typedef void(* mmipal_link_status_cb_fn_t) (const struct mmipal_link_status *link_status)
 Prototype for callback function invoked on link status changes. More...
 
typedef void(* mmipal_ext_link_status_cb_fn_t) (const struct mmipal_link_status *link_status, void *arg)
 Prototype for callback function invoked on link status changes. More...
 

Enumerations

enum  mmipal_status {
  MMIPAL_SUCCESS , MMIPAL_INVALID_ARGUMENT , MMIPAL_NO_LINK , MMIPAL_NO_MEM ,
  MMIPAL_NOT_SUPPORTED
}
 Enumeration of status codes returned by MMIPAL functions. More...
 
enum  mmipal_link_state { MMIPAL_LINK_DOWN , MMIPAL_LINK_UP }
 Enumeration of link states. More...
 
enum  mmipal_addr_mode {
  MMIPAL_DISABLED , MMIPAL_STATIC , MMIPAL_DHCP , MMIPAL_AUTOIP ,
  MMIPAL_DHCP_OFFLOAD
}
 Enumeration of IP address allocation modes. More...
 
enum  mmipal_ip6_addr_mode { MMIPAL_IP6_DISABLED , MMIPAL_IP6_STATIC , MMIPAL_IP6_AUTOCONFIG , MMIPAL_IP6_DHCP6_STATELESS }
 Enumeration of IPv6 address allocation modes. More...
 

Functions

enum mmipal_status mmipal_init (const struct mmipal_init_args *args)
 Initialize the IP stack and enable the MMWLAN interface. More...
 
void mmipal_set_link_status_callback (mmipal_link_status_cb_fn_t fn)
 Sets the callback function to be invoked on link status changes. More...
 
void mmipal_set_ext_link_status_callback (mmipal_ext_link_status_cb_fn_t fn, void *arg)
 Sets the extended link status callback function to be invoked on link status changes. More...
 
void mmipal_get_link_packet_counts (uint32_t *tx_packets, uint32_t *rx_packets)
 Get the total number of transmitted and received packets on the MMWLAN interface. More...
 
void mmipal_set_tx_qos_tid (uint8_t tid)
 Set the QoS Traffic ID to use when transmitting. More...
 
enum mmipal_status mmipal_get_local_addr (mmipal_ip_addr_t local_addr, const mmipal_ip_addr_t dest_addr)
 Gets the local address for the MMWLAN interface that is appropriate for a given destination address. More...
 
enum mmipal_status mmipal_get_ip_config (struct mmipal_ip_config *config)
 Get the IP configurations. More...
 
enum mmipal_status mmipal_set_ip_config (const struct mmipal_ip_config *config)
 Set the IP configurations. More...
 
enum mmipal_status mmipal_get_ip_broadcast_addr (mmipal_ip_addr_t broadcast_addr)
 Gets the current IPv4 broadcast address. More...
 
enum mmipal_status mmipal_get_ip6_config (struct mmipal_ip6_config *config)
 Get the IP configurations. More...
 
enum mmipal_status mmipal_set_ip6_config (const struct mmipal_ip6_config *config)
 Set the IPv6 configurations. More...
 
enum mmipal_link_state mmipal_get_link_state (void)
 Get current IPv4 link state. More...
 
enum mmipal_status mmipal_set_dns_server (uint8_t index, const mmipal_ip_addr_t addr)
 Set the DNS server at the given index. More...
 
enum mmipal_status mmipal_get_dns_server (uint8_t index, mmipal_ip_addr_t addr)
 Get the DNS server at the given index. More...
 

Macro Definition Documentation

◆ MMIPAL_INIT_ARGS_DEFAULT

#define MMIPAL_INIT_ARGS_DEFAULT
Value:
{ MMIPAL_DHCP, { 0 }, { 0 }, { 0 }, \
MMIPAL_IP6_DISABLED, { 0 }, false, 0 }
@ MMIPAL_DHCP
IP address allocated via DHCP.
Definition: mmipal.h:67

Default values for mmipal_init_args.

This should be used when initializing the mmipal_init_args structure.

Definition at line 173 of file mmipal.h.

◆ MMIPAL_IP6_CONFIG_DEFAULT

#define MMIPAL_IP6_CONFIG_DEFAULT   { MMIPAL_IP6_AUTOCONFIG }

Initializer for mmipal_ip6_config.

Definition at line 136 of file mmipal.h.

◆ MMIPAL_IP_CONFIG_DEFAULT

#define MMIPAL_IP_CONFIG_DEFAULT   { MMIPAL_DHCP, "", "", "", }

Initializer for mmipal_ip_config.

Definition at line 100 of file mmipal.h.

◆ MMIPAL_IPADDR_STR_MAXLEN

#define MMIPAL_IPADDR_STR_MAXLEN   (48)

Maximum length of an IP address string, including null-terminator.

Definition at line 27 of file mmipal.h.

◆ MMIPAL_MAX_IPV6_ADDRESSES

#define MMIPAL_MAX_IPV6_ADDRESSES   (3)

Maximum number of IPv6 addresses supported.

Definition at line 32 of file mmipal.h.

Typedef Documentation

◆ mmipal_ext_link_status_cb_fn_t

typedef void(* mmipal_ext_link_status_cb_fn_t) (const struct mmipal_link_status *link_status, void *arg)

Prototype for callback function invoked on link status changes.

This is similar to mmipal_link_status_cb_fn_t but with the addition of the arg parameter.

Parameters
link_statusThe current link status.
argOpaque argument that was provided when the callback was registered.

Definition at line 237 of file mmipal.h.

◆ mmipal_ip_addr_t

typedef char mmipal_ip_addr_t[MMIPAL_IPADDR_STR_MAXLEN]

IP address string type.

Definition at line 75 of file mmipal.h.

◆ mmipal_link_status_cb_fn_t

typedef void(* mmipal_link_status_cb_fn_t) (const struct mmipal_link_status *link_status)

Prototype for callback function invoked on link status changes.

Parameters
link_statusThe current link status.

Definition at line 213 of file mmipal.h.

Enumeration Type Documentation

◆ mmipal_addr_mode

Enumeration of IP address allocation modes.

Enumerator
MMIPAL_DISABLED 

Disabled.

MMIPAL_STATIC 

Static IP address.

MMIPAL_DHCP 

IP address allocated via DHCP.

LWIP_DHCP must be set to 1 if using LWIP.

MMIPAL_AUTOIP 

IP address allocated via AutoIP.

LWIP_DHCP must be set to 1 if using LWIP.

MMIPAL_DHCP_OFFLOAD 

DHCP offloaded to chip.

Definition at line 60 of file mmipal.h.

◆ mmipal_ip6_addr_mode

Enumeration of IPv6 address allocation modes.

Enumerator
MMIPAL_IP6_DISABLED 

Disabled.

MMIPAL_IP6_STATIC 

Static IPv6 addresses.

MMIPAL_IP6_AUTOCONFIG 

IPv6 address allocated via autoconfiguration.

LWIP_IPV6_AUTOCONFIG must be set to 1 if using LWIP.

MMIPAL_IP6_DHCP6_STATELESS 

IPv6 address allocated via stateless DHCPv6.

LWIP_IPV6_DHCP6_STATELESS must be set to 1 if using LWIP.

Definition at line 103 of file mmipal.h.

◆ mmipal_link_state

Enumeration of link states.

Enumerator
MMIPAL_LINK_DOWN 

Link is down.

MMIPAL_LINK_UP 

Link is up.

Definition at line 51 of file mmipal.h.

◆ mmipal_status

Enumeration of status codes returned by MMIPAL functions.

Enumerator
MMIPAL_SUCCESS 

Completed successfully.

MMIPAL_INVALID_ARGUMENT 

One or more arguments were invalid.

MMIPAL_NO_LINK 

The operation could not complete because the link is not up.

MMIPAL_NO_MEM 

Failed due to memory allocation failure.

MMIPAL_NOT_SUPPORTED 

This functionality is not supported (e.g., due to build configuration).

Definition at line 36 of file mmipal.h.

Function Documentation

◆ mmipal_get_dns_server()

enum mmipal_status mmipal_get_dns_server ( uint8_t  index,
mmipal_ip_addr_t  addr 
)

Get the DNS server at the given index.

Parameters
[in]indexIndex of the DNS server to set.
[out]addrIP address buffer to receive the IP address of the DNS server at the given index. Will be set to empty string if no server at the given index.
Returns
MMIPAL_SUCCESS on success.

◆ mmipal_get_ip6_config()

enum mmipal_status mmipal_get_ip6_config ( struct mmipal_ip6_config config)

Get the IP configurations.

This can be used to get the local IP configurations.

Parameters
configPointer to the IP configurations.
Returns
MMIPAL_SUCCESS on success, MMIPAL_NOT_SUPPORTED if IPv6 is not supported..

◆ mmipal_get_ip_broadcast_addr()

enum mmipal_status mmipal_get_ip_broadcast_addr ( mmipal_ip_addr_t  broadcast_addr)

Gets the current IPv4 broadcast address.

Parameters
[out]broadcast_addrBuffer to receive the broadcast address as a string.
Returns
MMIPAL_SUCCESS on success, MMIPAL_NOT_SUPPORTED if IPv4 is not supported.

◆ mmipal_get_ip_config()

enum mmipal_status mmipal_get_ip_config ( struct mmipal_ip_config config)

Get the IP configurations.

This can be used to get the local IP configurations.

Parameters
configPointer to the IP configurations.
Returns
MMIPAL_SUCCESS on success, MMIPAL_NOT_SUPPORTED if IPv4 is not supported.

◆ mmipal_get_link_packet_counts()

void mmipal_get_link_packet_counts ( uint32_t *  tx_packets,
uint32_t *  rx_packets 
)

Get the total number of transmitted and received packets on the MMWLAN interface.

Note
If using LWIP, this function requires LWIP_STATS to be defined in your application, otherwise packet counters will always return as 0.
Parameters
tx_packetsPointer to location to store total tx packets
rx_packetsPointer to location to store total rx packets

◆ mmipal_get_link_state()

enum mmipal_link_state mmipal_get_link_state ( void  )

Get current IPv4 link state.

Returns
the current IPv4 link state (up or down).

◆ mmipal_get_local_addr()

enum mmipal_status mmipal_get_local_addr ( mmipal_ip_addr_t  local_addr,
const mmipal_ip_addr_t  dest_addr 
)

Gets the local address for the MMWLAN interface that is appropriate for a given destination address.

The following table shows how the returned local_addr is selected:

dest_addr local_addr returned
type is IPv4 IPv4 address
type is IPv6 An IPv6 source address selected from interface's IPv6 addresses or ERR_CONN

(X = don't care)

If the given parameters would result in a local_addr type of IPv4 and IPv4 is not enabled, or IPv6 and IPv6 is not enabled, then MMIPAL_INVALID_ARGUMENT will be returned.

Parameters
[out]local_addrOutput local address for the MMWLAN interface, as noted above.
[in]dest_addrDestination address.
Returns
MMIPAL_SUCESS if local_addr successfully set. otherwise an appropriate error code.

◆ mmipal_init()

enum mmipal_status mmipal_init ( const struct mmipal_init_args args)

Initialize the IP stack and enable the MMWLAN interface.

This will implicitly initialize and boot MMWLAN, and will block until this has completed.

Note
This function will boot the Morse Micro transceiver using mmwlan_boot() in order to read the MAC address. It is the responsibility of the caller to shut down the transceiver using mmwlan_shutdown() as required.
Warning
mmwlan_init() must be called before invoking this function.
Parameters
argsInitialization arguments.
Returns
MMIPAL_SUCCESS on success. otherwise a vendor specific error code.

◆ mmipal_set_dns_server()

enum mmipal_status mmipal_set_dns_server ( uint8_t  index,
const mmipal_ip_addr_t  addr 
)

Set the DNS server at the given index.

Warning
Depending on IP stack implementation, this setting may be overridden by DHCP.
Parameters
[in]indexIndex of the DNS server to set.
[out]addrAddress of the DNS server to set.
Returns
MMIPAL_SUCCESS on success, MMIPAL_INVALID_ARGUMENT if an invalid index or IP address was given.

◆ mmipal_set_ext_link_status_callback()

void mmipal_set_ext_link_status_callback ( mmipal_ext_link_status_cb_fn_t  fn,
void *  arg 
)

Sets the extended link status callback function to be invoked on link status changes.

This is similar to mmipal_set_link_status_callback() with the exception that an opaque argument may also be specified.

This will be used when DHCP is enabled.

Note
This is for IPv4 only. To get IPv6 status use mmipal_get_ip6_config.
Parameters
fnFunction pointer to the callback function.
argOpaque argument to be passed to the callback.

◆ mmipal_set_ip6_config()

enum mmipal_status mmipal_set_ip6_config ( const struct mmipal_ip6_config config)

Set the IPv6 configurations.

This can be used to set the local IPv6 configurations.

Parameters
configPointer to the IPv6 configurations.
Returns
MMIPAL_SUCCESS on success, MMIPAL_NOT_SUPPORTED if IPv6 is not supported.

◆ mmipal_set_ip_config()

enum mmipal_status mmipal_set_ip_config ( const struct mmipal_ip_config config)

Set the IP configurations.

This can be used to set the local IP configurations.

Parameters
configPointer to the IP configurations.
Returns
MMIPAL_SUCCESS on success, MMIPAL_NOT_SUPPORTED if IPv4 is not supported.

◆ mmipal_set_link_status_callback()

void mmipal_set_link_status_callback ( mmipal_link_status_cb_fn_t  fn)

Sets the callback function to be invoked on link status changes.

This will be used when DHCP is enabled.

Note
This is for IPv4 only. To get IPv6 status use mmipal_get_ip6_config.
If an opaque argument is required then use mmipal_set_ext_link_status_callback() instead.
Parameters
fnFunction pointer to the callback function.

◆ mmipal_set_tx_qos_tid()

void mmipal_set_tx_qos_tid ( uint8_t  tid)

Set the QoS Traffic ID to use when transmitting.

Parameters
tidThe QoS TID to use (0 - MMWLAN_MAX_QOS_TID).