WE310F5  39.00.000
M2MB PING

This section describes the M2MB APIs for Ping feature. More...

#define M2MB_PING_PACKET_SIZE_MAX_TX   (1576)
 
#define M2MB_PING_PACKET_SIZE_MAX_RX   (1556)
 
#define M2MB_NETWORK_PING_SUCCESS   0
 
#define M2MB_NETWORK_PING_INVALID_IP_ADDRESS   M2MB_NET_ERR_INVALID_IPADDR
 
#define M2MB_NETWORK_PING_REQUEST_TIMED_OUT   2
 
enum  M2MB_PING_CFGID {
  M2MB_PING_CFGID_ADDRESS,
  M2MB_PING_CFGID_DATA_SIZE,
  M2MB_PING_CFGID_COUNT,
  M2MB_PING_CFGID_STAT
}
 M2MB_PING_CFGID_E defines configuration IDs for ping. More...
 
enum  M2MB_PING_EVENT {
  M2MB_PING_REQ_RESULT,
  M2MB_PING_COMPLETE
}
 M2MB_PING_EVENT_E defines events passed in the ping callback. More...
 
typedef enum M2MB_PING_CFGID M2MB_PING_CFGID_E
 M2MB_PING_CFGID_E defines configuration IDs for ping. More...
 
typedef enum M2MB_PING_EVENT M2MB_PING_EVENT_E
 M2MB_PING_EVENT_E defines events passed in the ping callback. More...
 
typedef struct M2MB_PING_REQ_STATUS M2MB_PING_REQ_STATUS_T
 M2MB_PING_REQ_STATUS_T defines the data type of M2MB_PING_REQ_RESULT event. More...
 
typedef struct M2MB_PING_COMPLETE_STATUS M2MB_PING_COMPLETE_STATUS_T
 M2MB_PING_COMPLETE_STATUS_T defines the data type of M2MB_PING_COMPLETE event. More...
 
typedef INT32(* M2MB_PING_CB_T) (void *user_ctx, M2MB_PING_EVENT_E ev, VOID *data)
 M2MB_PING_CB_T defines callback for ping request. More...
 
typedef union M2MB_PING_CONF_PARAMS M2MB_PING_CONF_PARAMS_T
 M2MB_PING_CONF_PARAMS_T defines configuration data structure for ping. More...
 
typedef struct M2MB_PING_INIT_PARAMS M2MB_PING_INIT_PARAMS_T
 PING initialization parameters. More...
 
M2MB_STATUS_T m2mb_ping_init (HANDLE *handle, M2MB_PING_INIT_PARAMS_T init_params)
 m2mb_ping_init is called to initialize the PING user callback and continuous interval. More...
 
M2MB_STATUS_T m2mb_ping_deinit (HANDLE handle)
 m2mb_ping_deinit is called to de-initialize PING module. More...
 
INT32 m2mb_ping_start (HANDLE handle)
 m2mb_ping_start is called to initiate Ping. More...
 
INT32 m2mb_ping_stop (HANDLE handle)
 m2mb_ping_stop is called to stop ping procedure. More...
 
INT32 m2mb_ping_set_cfg (HANDLE handle, M2MB_PING_CFGID_E cfgID, M2MB_PING_CONF_PARAMS_T *conf_params)
 m2mb_ping_set_cfg is called to set the ping configuration. More...
 
INT32 m2mb_ping_get_cfg (HANDLE handle, M2MB_PING_CFGID_E cfgID, M2MB_PING_CONF_PARAMS_T *conf_params)
 m2mb_ping_get_cfg is called to set the ping configuration. More...
 

Detailed Description

This section describes the M2MB APIs for Ping feature.

WE310F5_PING.png
PING

Macro Definition Documentation

◆ M2MB_NETWORK_PING_INVALID_IP_ADDRESS

#define M2MB_NETWORK_PING_INVALID_IP_ADDRESS   M2MB_NET_ERR_INVALID_IPADDR

Macro for invalid IP address

Definition at line 57 of file m2mb_ping.h.

◆ M2MB_NETWORK_PING_REQUEST_TIMED_OUT

#define M2MB_NETWORK_PING_REQUEST_TIMED_OUT   2

Macro for ping request timed out

Definition at line 58 of file m2mb_ping.h.

◆ M2MB_NETWORK_PING_SUCCESS

#define M2MB_NETWORK_PING_SUCCESS   0

MACROs for PING_STATUS Macro for ping success

Definition at line 56 of file m2mb_ping.h.

◆ M2MB_PING_PACKET_SIZE_MAX_RX

#define M2MB_PING_PACKET_SIZE_MAX_RX   (1556)

Macro for maximum number of bytes to receive

Definition at line 53 of file m2mb_ping.h.

◆ M2MB_PING_PACKET_SIZE_MAX_TX

#define M2MB_PING_PACKET_SIZE_MAX_TX   (1576)

Macro for maximum number of bytes to transmit

Definition at line 52 of file m2mb_ping.h.

Typedef Documentation

◆ M2MB_PING_CB_T

typedef INT32( * M2MB_PING_CB_T) (void *user_ctx, M2MB_PING_EVENT_E ev, VOID *data)

M2MB_PING_CB_T defines callback for ping request.

This callback is called to indicate the event to the application. The data pointer has to be interpreted based on the event and has to be either M2MB_PING_REQ_STATUS_T or M2MB_PING_COMPLETE_STATUS_T.here data is of type either M2MB_PING_REQ_STATUS_T or M2MB_PING_COMPLETE_STATUS_T, depends on event type.

Parameters
[in]user_ctxPointer to the applicaiton context passed by the user.
[in]evIndicate the event of type M2MB_PING_EVENT_E to the application.
[in]dataThe data pointer has to be interpreted based on the event. If event is M2MB_PING_REQ_RESULT data is M2MB_PING_REQ_STATUS_T else NULL. Example
M2MB_PINGC_APP_CB_T ping_user_cb( void *user_ctx, M2MB_PING_EVENT_E ev, VOID* data )
{
user_ctx(ev);
switch(ev)
{
...
...
}
}

Definition at line 168 of file m2mb_ping.h.

◆ M2MB_PING_CFGID_E

M2MB_PING_CFGID_E defines configuration IDs for ping.

This enum is used to get/set ping configuration using m2mb_ping_get_cfg/m2mb_ping_set_cfg APIs.

◆ M2MB_PING_COMPLETE_STATUS_T

M2MB_PING_COMPLETE_STATUS_T defines the data type of M2MB_PING_COMPLETE event.

M2MB_PING_COMPLETE_STATUS_T defines the data type of the data filled in the ping request callback for M2MB_PING_COMPLETE event.

◆ M2MB_PING_CONF_PARAMS_T

M2MB_PING_CONF_PARAMS_T defines configuration data structure for ping.

This union is used to get/set ping configuration using m2mb_ping_get_cfg/m2mb_ping_set_cfg APIs.

◆ M2MB_PING_EVENT_E

M2MB_PING_EVENT_E defines events passed in the ping callback.

This enum is used while passing the event in the ping callback.

◆ M2MB_PING_INIT_PARAMS_T

PING initialization parameters.

Contains information needed to initialize the PING module, such as user callback and user context.

◆ M2MB_PING_REQ_STATUS_T

M2MB_PING_REQ_STATUS_T defines the data type of M2MB_PING_REQ_RESULT event.

M2MB_PING_REQ_STATUS_T defines the data type of the data filed in the ping request callback for M2MB_PING_REQ_RESULT event.

Enumeration Type Documentation

◆ M2MB_PING_CFGID

M2MB_PING_CFGID_E defines configuration IDs for ping.

This enum is used to get/set ping configuration using m2mb_ping_get_cfg/m2mb_ping_set_cfg APIs.

Enumerator
M2MB_PING_CFGID_ADDRESS 

ping address ping data size

M2MB_PING_CFGID_DATA_SIZE 

ping count

M2MB_PING_CFGID_COUNT 

ping start

M2MB_PING_CFGID_STAT 

Definition at line 70 of file m2mb_ping.h.

◆ M2MB_PING_EVENT

M2MB_PING_EVENT_E defines events passed in the ping callback.

This enum is used while passing the event in the ping callback.

Enumerator
M2MB_PING_REQ_RESULT 

ping request result, call back returns M2MB_PING_REQ_STATUS_T type data last ping result, call back returns M2MB_PING_COMPLETE_STATUS_T type data

M2MB_PING_COMPLETE 

Definition at line 89 of file m2mb_ping.h.

Function Documentation

◆ m2mb_ping_deinit()

M2MB_STATUS_T m2mb_ping_deinit ( HANDLE  handle)

m2mb_ping_deinit is called to de-initialize PING module.

m2mb_ping_deinit de-initializes the PING module. It frees up all memory allocated during initialization process.

Parameters
[in]handleSpecifies the context handle initialized by m2mb_ping_init API.
Returns
Returns status.
Note
This API has to be called if the PING is already initialized. Example
M2MB_PINGC_APP_CB_T ping_user_cb( void *user_ctx, M2MB_PING_EVENT_E ev, VOID* data )
{
user_ctx(ev);
switch(ev)
{
...
...
}
...
...
}
void *user_appln_cb(int event)
{
...
...
}
int main()
{
INT32 status = 0;
HANDLE handle = NULL;
M2MB_PING_INIT_PARAMS_T ping_init = {0};
ping_init.user_cb = ping_user_cb;
ping_init.user_ctx = user_appln_cb;
status = m2mb_ping_init( &handle, ping_init );
if( status == M2MB_ERROR )
{
return M2MB_ERROR;
}
...
status = m2mb_ping_deinit( handle );
if( status == M2MB_ERROR )
{
return M2MB_ERROR;
}
...
}

◆ m2mb_ping_get_cfg()

INT32 m2mb_ping_get_cfg ( HANDLE  handle,
M2MB_PING_CFGID_E  cfgID,
M2MB_PING_CONF_PARAMS_T conf_params 
)

m2mb_ping_get_cfg is called to set the ping configuration.

m2mb_ping_get_cfg stores the configuration set by user. This configuration is used when ping start API is called.

Parameters
[in]handleSpecifies the pointer to the context handle initialized by m2mb_ping_init API.
[in]cfgIDConfiguration ID, from M2MB_PING_CFG_T.
[out]valueConfigured value.
Returns
Returns M2MB_OK on success, M2MB_ERROR on error.
Note


Example

void m2m_s2w_nw_ping_cb( void *user_ctx, M2MB_PING_EVENT_E ev, VOID* data )
{
user_ctx(ev);
{
if (m2mb_socket_bsd_inet_pton(M2MB_SOCKET_BSD_AF_INET, pPingrslt->pDst, &rsp.dst->Addr4 ) == 1)
{
}
else if(m2mb_socket_bsd_inet_pton(M2MB_SOCKET_BSD_AF_INET6, pPingrslt->pDst, &rsp.dst->Addr6) == 1)
{
}
if (pPingrslt->status == M2M_NETWORK_PING_SUCCESS)
{
//ping is success
}
else if (pPingrslt->status == M2MB_NET_ERR_INVALID_IPADDR)
{
//ping ip is invalid
}
else
{
//ping request is timedout
}
}
else if( ev == M2MB_PING_COMPLETE )
{
//ping completed
}
}
void *user_appln_cb(int event)
{
...
...
}
int main()
{
INT32 status = 0;
HANDLE handle = NULL;
M2MB_PING_INIT_PARAMS_T ping_init = {0};
ping_init.user_cb = m2m_s2w_nw_ping_cb;
ping_init.user_ctx = user_appln_cb;
status = m2mb_ping_init( &handle, ping_init );
if( status == M2MB_ERROR )
{
return M2MB_ERROR;
}
char addrstr[40];
M2MB_IP46_ADDR_T * IPaddr;
UINT32 payload;
UINT32 count;
if(NULL == m2mb_socket_bsd_inet_ntop(IPaddr->type, &IPaddr->a, addrstr, 40))
return M2MB_ERROR;
return M2MB_ERROR;
return M2MB_ERROR;
return M2MB_ERROR;
if(M2MB_OK != m2mb_ping_set_cfg( handle, M2MB_PING_CFGID_CB, (UINT32)m2m_s2w_nw_ping_cb ))
return M2MB_ERROR;
memcpy(&pingstats.ip, IPaddr, sizeof(M2MB_IP46_ADDR_T) );
if(M2MB_OK != m2mb_ping_start(handle))
{
return M2MB_ERROR;
}
UINT32 val;
return M2MB_ERROR;
else
// print val
}

◆ m2mb_ping_init()

M2MB_STATUS_T m2mb_ping_init ( HANDLE handle,
M2MB_PING_INIT_PARAMS_T  init_params 
)

m2mb_ping_init is called to initialize the PING user callback and continuous interval.

m2mb_ping_init is called to initialize the PING user callback and continuous interval.

Parameters
[in]handleSpecifies the pointer to the context handle that can be used by other PING APIs.
[in]init_paramsInitialization parameters required for PING module initialization.
Returns
Returns M2MB_OK on success, a different value on error.
Note
This API has to be called before any other PING API is called. Example
M2MB_PINGC_APP_CB_T ping_user_cb( void *user_ctx, M2MB_PING_EVENT_E ev, VOID* data )
{
user_ctx(ev);
switch(ev)
{
...
...
}
...
...
}
void *user_appln_cb(int event)
{
...
...
}
int main()
{
INT32 status = 0;
HANDLE handle = NULL;
M2MB_PING_INIT_PARAMS_T ping_init = {0};
ping_init.user_cb = ping_user_cb;
ping_init.user_ctx = user_appln_cb;
status = m2mb_ping_init( &handle, ping_init );
if( status == M2MB_OK )
{
return M2MB_OK;
}
else
{
return M2MB_ERROR;
}
}

◆ m2mb_ping_set_cfg()

INT32 m2mb_ping_set_cfg ( HANDLE  handle,
M2MB_PING_CFGID_E  cfgID,
M2MB_PING_CONF_PARAMS_T conf_params 
)

m2mb_ping_set_cfg is called to set the ping configuration.

m2mb_ping_set_cfg stores the configuration set by user. This configuration is used when ping start API is called.

Parameters
[in]handleSpecifies the pointer to the context handle initialized by m2mb_ping_init API.
[in]cfgIDConfiguration ID, from M2MB_PING_CFG_T.
[in]conf_paramsConfiguration value according to the cfgID, type M2MB_PING_CONF_PARAMS_T
Returns
Returns M2MB_OK on success, M2MB_ERROR value on error.
Note

Example

void m2m_s2w_nw_ping_cb( void *user_ctx, M2MB_PING_EVENT_E ev, VOID* data )
{
user_ctx(ev);
{
if (m2mb_socket_bsd_inet_pton(M2MB_SOCKET_BSD_AF_INET, pPingrslt->pDst, &rsp.dst->Addr4 ) == 1)
{
}
else if(m2mb_socket_bsd_inet_pton(M2MB_SOCKET_BSD_AF_INET6, pPingrslt->pDst, &rsp.dst->Addr6) == 1)
{
}
if (pPingrslt->status == M2M_NETWORK_PING_SUCCESS)
{
//ping is success
}
else if (pPingrslt->status == M2MB_NET_ERR_INVALID_IPADDR)
{
//ping ip is invalid
}
else
{
//ping request is timedout
}
}
else if( ev == M2MB_PING_COMPLETE )
{
//ping completed
}
}
void *user_appln_cb(int event)
{
...
...
}
int main()
{
INT32 status = 0;
HANDLE handle = NULL;
M2MB_PING_INIT_PARAMS_T ping_init = {0};
M2MB_PING_CONF_PARAMS_T conf_params = {0};
ping_init.user_cb = m2m_s2w_nw_ping_cb;
ping_init.user_ctx = user_appln_cb;
status = m2mb_ping_init( &handle, ping_init );
if( status == M2MB_ERROR )
{
return M2MB_ERROR;
}
char addrstr[40];
M2MB_IP46_ADDR_T * IPaddr;
UINT32 payload;
UINT32 count;
if(NULL == m2mb_socket_bsd_inet_ntop(IPaddr->type, &IPaddr->a, addrstr, 40))
return M2MB_ERROR;
conf_params.ipaddr_string = addrstr;
if(M2MB_OK != m2mb_ping_set_cfg( handle, M2MB_PING_CFGID_ADDRESS, &conf_params ))
return M2MB_ERROR;
conf_params.datasize = payload;
if(M2MB_OK != m2mb_ping_set_cfg( handle, M2MB_PING_CFGID_DATA_SIZE, &conf_params))
return M2MB_ERROR;
conf_params.pingcnt = count;
if(M2MB_OK != m2mb_ping_set_cfg( handle, M2MB_PING_CFGID_COUNT, &conf_params ))
return M2MB_ERROR;
if(M2MB_OK != m2mb_ping_set_cfg( handle, M2MB_PING_CFGID_CB, (UINT32)m2m_s2w_nw_ping_cb ))
return M2MB_ERROR;
memcpy(&pingstats.ip, IPaddr, sizeof(M2MB_IP46_ADDR_T) );
if(M2MB_OK != m2mb_ping_start(handle))
{
return M2MB_ERROR;
}
}

◆ m2mb_ping_start()

INT32 m2mb_ping_start ( HANDLE  handle)

m2mb_ping_start is called to initiate Ping.

m2mb_ping_start initiates Ping procedure.

Parameters
[in]handleSpecifies the pointer to the context handle initialized by m2mb_ping_init API.
Returns
returns status.
Note
This API has to be called after ping configuration. Example
void m2m_s2w_nw_ping_cb( void *user_ctx, M2MB_PING_EVENT_E ev, VOID* data )
{
user_ctx(ev);
{
if (m2mb_socket_bsd_inet_pton(M2MB_SOCKET_BSD_AF_INET, pPingrslt->pDst, &rsp.dst->Addr4 ) == 1)
{
}
else if(m2mb_socket_bsd_inet_pton(M2MB_SOCKET_BSD_AF_INET6, pPingrslt->pDst, &rsp.dst->Addr6) == 1)
{
}
if (pPingrslt->status == M2M_NETWORK_PING_SUCCESS)
{
//ping is success
}
else if (pPingrslt->status == M2MB_NET_ERR_INVALID_IPADDR)
{
//ping ip is invalid
}
else
{
//ping request is timedout
}
}
else if( ev == M2MB_PING_COMPLETE )
{
//ping completed
}
}
void *user_appln_cb(int event)
{
...
...
}
int main()
{
INT32 status = 0;
HANDLE handle = NULL;
M2MB_PING_INIT_PARAMS_T ping_init = {0};
ping_init.user_cb = m2m_s2w_nw_ping_cb;
ping_init.user_ctx = user_appln_cb;
status = m2mb_ping_init( &handle, ping_init );
if( status == M2MB_ERROR )
{
return M2MB_ERROR;
}
char addrstr[40];
M2MB_IP46_ADDR_T * IPaddr;
UINT32 payload;
UINT32 count;
if(NULL == m2mb_socket_bsd_inet_ntop(IPaddr->type, &IPaddr->a, addrstr, 40))
return M2MB_ERROR;
return M2MB_ERROR;
return M2MB_ERROR;
return M2MB_ERROR;
if(M2MB_OK != m2mb_ping_set_cfg( handle, M2MB_PING_CFGID_CB, (UINT32)m2m_s2w_nw_ping_cb ))
return M2MB_ERROR;
memcpy(&pingstats.ip, IPaddr, sizeof(M2MB_IP46_ADDR_T) );
if(M2MB_OK != m2mb_ping_start(handle))
{
return M2MB_ERROR;
}
}

◆ m2mb_ping_stop()

INT32 m2mb_ping_stop ( HANDLE  handle)

m2mb_ping_stop is called to stop ping procedure.

m2mb_ping_stop stops the ping procedure. It is called when ping is started in continuous mode in background.

Parameters
[in]handleSpecifies the pointer to the context handle initialized by m2mb_ping_init API.
Returns
returns status.
Note
This API has to be called when ping is started in continuous mode in background. Example
void m2m_s2w_nw_ping_cb( void *user_ctx, M2MB_PING_EVENT_E ev, VOID* data )
{
user_ctx(ev);
{
if (m2mb_socket_bsd_inet_pton(M2MB_SOCKET_BSD_AF_INET, pPingrslt->pDst, &rsp.dst->Addr4 ) == 1)
{
}
else if(m2mb_socket_bsd_inet_pton(M2MB_SOCKET_BSD_AF_INET6, pPingrslt->pDst, &rsp.dst->Addr6) == 1)
{
}
if (pPingrslt->status == M2M_NETWORK_PING_SUCCESS)
{
//ping is success
}
else if (pPingrslt->status == M2MB_NET_ERR_INVALID_IPADDR)
{
//ping ip is invalid
}
else
{
//ping request is timedout
}
}
else if( ev == M2MB_PING_COMPLETE )
{
//ping completed
}
}
void *user_appln_cb(int event)
{
...
...
}
int main()
{
INT32 status = 0;
HANDLE handle = NULL;
M2MB_PING_INIT_PARAMS_T ping_init = {0};
ping_init.user_cb = m2m_s2w_nw_ping_cb;
ping_init.user_ctx = user_appln_cb;
status = m2mb_ping_init( &handle, ping_init );
if( status == M2MB_ERROR )
{
return M2MB_ERROR;
}
char addrstr[40];
M2MB_IP46_ADDR_T * IPaddr;
UINT32 payload;
UINT32 count;
if(NULL == m2mb_socket_bsd_inet_ntop(IPaddr->type, &IPaddr->a, addrstr, 40))
return M2MB_ERROR;
return M2MB_ERROR;
return M2MB_ERROR;
return M2MB_ERROR;
if(M2MB_OK != m2mb_ping_set_cfg( handle, M2MB_PING_CFGID_CB, (UINT32)m2m_s2w_nw_ping_cb ))
return M2MB_ERROR;
memcpy(&pingstats.ip, IPaddr, sizeof(M2MB_IP46_ADDR_T) );
if(M2MB_OK != m2mb_ping_start( handle ))
{
return M2MB_ERROR;
}
if(M2MB_OK != m2mb_ping_stop( handle ))
{
return M2MB_ERROR;
}
status = m2mb_ping_deinit( handle );
if( status == M2MB_ERROR )
{
return M2MB_ERROR;
}
}