WL865E4-P  36.07.001
M2MB MDNS

This section describes the M2MB APIs to perform various multicast Domain Name System(mDNS) operations. More...

#define M2MB_MDNS_MAX_TXT_RECORDS   10
 
enum  M2MB_MDNS_COMMAND {
  M2MB_MDNS_START_E,
  M2MB_MDNS_STOP_E,
  M2MB_MDNS_DISABLE_E,
  M2MB_MDNS_ADDSVC_E,
  M2MB_MDNS_RMSVC_E,
  M2MB_MDNS_SET_HOSTNAME_E,
  M2MB_MDNS_UPDATE_TXT_RECORD_E
}
 Commands supported by the mDNS service. More...
 
typedef enum M2MB_MDNS_COMMAND M2MB_MDNS_COMMAND_T
 Commands supported by the mDNS service. More...
 
typedef struct M2MB_MDNS_TXT_RECORD M2MB_MDNS_TXT_RECORD_T
 Structure for updating or adding a new text record. More...
 
typedef struct M2MB_MDNS_SVC_REG_STATUS M2MB_MDNS_SVC_REG_STATUS_T
 Structure for registration status information. More...
 
typedef struct M2MB_MDNS_SVC_INFO M2MB_MDNS_SVC_INFO_T
 Structure for registering the new service or advertising a service. More...
 
typedef struct M2MB_MDNS_START M2MB_MDNS_START_T
 mDNS start command structure. More...
 
typedef struct M2MB_MDNS_TXT M2MB_MDNS_TXT_T
 
typedef UINT32(* M2MB_MDNS_CB_T) (VOID *arg)
 mDNS application callback. More...
 
M2MB_STATUS_T m2mb_mdns_start (M2MB_MDNS_START_T *start, M2MB_MDNS_CB_T app_cb, UINT8 blocking)
 m2mb_mdns_start is called to Start the mDNS service. More...
 
M2MB_STATUS_T m2mb_mdns_stop (VOID)
 Stops the mDNS service. More...
 
M2MB_STATUS_T m2mb_mdns_set_hostname (const CHAR *host_name)
 Sets the hostname for mDNS. More...
 
M2MB_STATUS_T m2mb_mdns_register_service (M2MB_MDNS_SVC_INFO_T *svc_info, UINT8 blocking)
 Registers a new service with mDNS. More...
 
M2MB_STATUS_T m2mb_mdns_unregister_service (const CHAR *svc_name)
 unregisters a service with mDNS. More...
 
M2MB_STATUS_T m2mb_mdns_update_txt (M2MB_MDNS_TXT_T *txt_update)
 Updates a text record of registered service of mDNS. More...
 

Detailed Description

This section describes the M2MB APIs to perform various multicast Domain Name System(mDNS) operations.

Macro Definition Documentation

◆ M2MB_MDNS_MAX_TXT_RECORDS

#define M2MB_MDNS_MAX_TXT_RECORDS   10

Maximum text records in a service information structure.

Definition at line 54 of file m2mb_mdns.h.

Typedef Documentation

◆ M2MB_MDNS_CB_T

typedef UINT32(* M2MB_MDNS_CB_T) (VOID *arg)

mDNS application callback.

Callback to be registered when the mDNS service is started. The callback will be invoked for all mDNS commands (Nonblocking mode) and for all asynchronous responses from mDNS.

Definition at line 174 of file m2mb_mdns.h.

◆ M2MB_MDNS_COMMAND_T

Commands supported by the mDNS service.

List of commands to start, stop, or disable an mDNS responder, and to register/unregister services with mDNS.

◆ M2MB_MDNS_START_T

mDNS start command structure.

This structure contains the information needed to start the mDNS.

◆ M2MB_MDNS_SVC_INFO_T

Structure for registering the new service or advertising a service.

This structure contains information related to an mdns service.

◆ M2MB_MDNS_SVC_REG_STATUS_T

Structure for registration status information.

This structure contains the name of the service/hostname and status code to denote if the registration is successful or to report if there is a subsequent conflict of hostname/servicename. An application callback will receive this asynchronously in the following cases:

  • Subsequent service/hostname conflict, after a service or hostname was successfully registered
  • If Nonblocking mode is used for an operation.

◆ M2MB_MDNS_TXT_RECORD_T

Structure for updating or adding a new text record.

This structure contains the text record in the format key=value and a service name that is already registered. If the key in the text record already exists for the given service name, the value is updated with the given value, otherwise, the text record is added as a new text record.

◆ M2MB_MDNS_TXT_T

Enumeration Type Documentation

◆ M2MB_MDNS_COMMAND

Commands supported by the mDNS service.

List of commands to start, stop, or disable an mDNS responder, and to register/unregister services with mDNS.

Enumerator
M2MB_MDNS_START_E 

Start mDNS server.

M2MB_MDNS_STOP_E 

Stop mDNS server.

M2MB_MDNS_DISABLE_E 

Disable mDNS server.

M2MB_MDNS_ADDSVC_E 

Add/register a service with mDNS.

M2MB_MDNS_RMSVC_E 

Remove a service already registered with mDNS.

M2MB_MDNS_SET_HOSTNAME_E 

Set the hostname for the mDNS server. The hostname should be set after starting mDNS and before registering a new service. If sethostname returns a hostname conflict error, retry sethostname until it succeeds.

M2MB_MDNS_UPDATE_TXT_RECORD_E 

Update an existing text record or add a new text record for an already registered service.

Definition at line 67 of file m2mb_mdns.h.

Function Documentation

◆ m2mb_mdns_register_service()

M2MB_STATUS_T m2mb_mdns_register_service ( M2MB_MDNS_SVC_INFO_T svc_info,
UINT8  blocking 
)

Registers a new service with mDNS.

m2mb_mdns_register_service registers a service with the mDNS module

Parameters
[in]svc_infoService information, such as name, type, port, txt records, etc.
[in]blockingFlag to indicate if the service registration is blocking or nonblocking.
  • If the flag = 1, service registration will block until complete (success or failure).
  • If the flag = 0, service registration will be nonblocking and will invoke the app callback to return the result of the operation.
Returns
M2MB_OK on success, or an code on error.
Note

m2mb_mdns_register_service( &svc_info, 0 );

UINT32 m2mb_profile_mdns_cb( VOID *pCtx )
{
...
}
int main()
{
M2MB_MDNS_START_T mdns = { 0 };
M2MB_MDNS_SVC_INFO_T svc_info = { 0 };
{
mdns.device_id = 1;
break;
mdns.device_id = 0;
break;
return M2MB_ERROR;
}
if( m2mb_mdns_start( &mdns, m2mb_profile_mdns_cb, TRUE ) != M2MB_OK )
return M2MB_ERROR;
if( m2mb_mdns_set_hostname("Telit Host Name") != M2MB_OK )
return M2MB_ERROR;
svc_info.instance = "_MyDevice";
svc_info.type = "_http._tcp.local";
svc_info.port = 80;
svc_info.txt[0] = "Testing Text";
return m2mb_mdns_register_service( &svc_info, 0 );
}

◆ m2mb_mdns_set_hostname()

M2MB_STATUS_T m2mb_mdns_set_hostname ( const CHAR host_name)

Sets the hostname for mDNS.

m2mb_mdns_set_hostname sets the mDNS hostname

Parameters
[in]host_nameHostname to be set for mDNS. This is the hostname that will be used by queriers to query for an IP address or a record.
Returns
M2MB_OK on success, or an code on error.
Note

m2mb_mdns_set_hostname("Telit Host Name");

UINT32 m2mb_profile_mdns_cb( VOID *pCtx )
{
...
}
int main()
{
M2MB_MDNS_START_T mdns = { 0 };
{
mdns.device_id = 1;
break;
mdns.device_id = 0;
break;
return M2MB_ERROR;
}
if( m2mb_mdns_start( &mdns, m2mb_profile_mdns_cb, TRUE ) != M2MB_OK )
return M2MB_ERROR;
return m2mb_mdns_set_hostname("Telit Host Name");
}

◆ m2mb_mdns_start()

M2MB_STATUS_T m2mb_mdns_start ( M2MB_MDNS_START_T start,
M2MB_MDNS_CB_T  app_cb,
UINT8  blocking 
)

m2mb_mdns_start is called to Start the mDNS service.

m2mb_mdns_start starts the mDNS service

Parameters
[in]startParameters required to start mDNS, such as ip_Version, if_Name, etc.
[in]app_cbApplication callback. The callback is invoked for nonblocking operations and to return asynchronous responses, e.g., hostname conflicts in the local network.
[in]blockingFlag to indicate if the mDNS function is in Blocking or Nonblocking mode.
  • If the flag = 1, all mDNS commands will block until complete (success or failure).
  • If the flag = 0, all mDNS commands will be nonblocking and will invoke the app callback to return the result of the operation.
Returns
M2MB_OK on success, or an code on error.
Note
This API has to be called before any other DNS server API is called.

m2mb_mdns_start( &mdns, m2mb_profile_mdns_cb, TRUE );

UINT32 m2mb_profile_mdns_cb( VOID *pCtx )
{
...
}
int main()
{
M2MB_MDNS_START_T mdns = { 0 };
{
mdns.device_id = 1;
break;
mdns.device_id = 0;
break;
return M2MB_ERROR;
}
return m2mb_mdns_start( &mdns, m2mb_profile_mdns_cb, TRUE );
}

◆ m2mb_mdns_stop()

M2MB_STATUS_T m2mb_mdns_stop ( VOID  )

Stops the mDNS service.

m2mb_mdns_stop stops the mDNS module

Returns
M2MB_OK on success, or an code on error.
Note

m2mb_mdns_stop();

UINT32 m2mb_profile_mdns_cb( VOID *pCtx )
{
...
}
int main()
{
M2MB_MDNS_START_T mdns = { 0 };
{
mdns.device_id = 1;
break;
mdns.device_id = 0;
break;
return M2MB_ERROR;
}
if( m2mb_mdns_start( &mdns, m2mb_profile_mdns_cb, TRUE ) != M2MB_OK )
return M2MB_ERROR;
...
return m2mb_mdns_stop();
}

◆ m2mb_mdns_unregister_service()

M2MB_STATUS_T m2mb_mdns_unregister_service ( const CHAR svc_name)

unregisters a service with mDNS.

m2mb_mdns_unregister_service unregisters a service with the mDNS module

Parameters
[in]svc_nameName of the service to be unregistered.
Returns
M2MB_OK on success, or an code on error.
Note

m2mb_mdns_unregister_service( "_MyDevice._http._tcp.local" );

UINT32 m2mb_profile_mdns_cb( VOID *pCtx )
{
...
}
int main()
{
M2MB_MDNS_START_T mdns = { 0 };
M2MB_MDNS_SVC_INFO_T svc_info = { 0 };
{
mdns.device_id = 1;
break;
mdns.device_id = 0;
break;
return M2MB_ERROR;
}
if( m2mb_mdns_start( &mdns, m2mb_profile_mdns_cb, TRUE ) != M2MB_OK )
return M2MB_ERROR;
if( m2mb_mdns_set_hostname("Telit Host Name") != M2MB_OK )
return M2MB_ERROR;
svc_info.instance = "_MyDevice";
svc_info.type = "_http._tcp.local";
svc_info.port = 80;
svc_info.txt[0] = "Testing Text";
if( m2mb_mdns_register_service( &svc_info, 0 ) != M2MB_OK )
return M2MB_ERROR;
...
return m2mb_mdns_unregister_service( "_MyDevice._http._tcp.local" );
}

◆ m2mb_mdns_update_txt()

M2MB_STATUS_T m2mb_mdns_update_txt ( M2MB_MDNS_TXT_T txt_update)

Updates a text record of registered service of mDNS.

m2mb_mdns_update_txt updates the text record of a registered service with the mDNS module

Parameters
[in]txt_updateContains the service name and the text record to be updated. If the text record does not exist, a new text record will be created. The text record should be of the form key=value.
Returns
M2MB_OK on success, or an code on error.
Note

m2mb_mdns_update_txt( &txt_update );

UINT32 m2mb_profile_mdns_cb( VOID *pCtx )
{
...
}
int main()
{
M2MB_MDNS_START_T mdns = { 0 };
M2MB_MDNS_SVC_INFO_T svc_info = { 0 };
M2MB_MDNS_TXT_T txt_update = { 0 };
{
mdns.device_id = 1;
break;
mdns.device_id = 0;
break;
return M2MB_ERROR;
}
if( m2mb_mdns_start( &mdns, m2mb_profile_mdns_cb, TRUE ) != M2MB_OK )
return M2MB_ERROR;
if( m2mb_mdns_set_hostname("Telit Host Name") != M2MB_OK )
return M2MB_ERROR;
svc_info.instance = "_MyDevice";
svc_info.type = "_http._tcp.local";
svc_info.port = 80;
svc_info.txt[0] = "Testing Text";
if( m2mb_mdns_register_service( &svc_info, 0 ) != M2MB_OK )
return M2MB_ERROR;
...
txt_update.svc_Name = "_MyDevice._http._tcp.local";
txt_update.txt = "Updated text";
return m2mb_mdns_update_txt( &txt_update );
}