Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
socketInit

The function performs the necessary initializations for the socket library through the following steps:

Functions

NMI_API void socketInit (void)
 

NMI_API void socketInit ( void  )
The function performs the necessary initialization for the socket library through the following steps:
- A check made by the global variable gbSocketInit, ensuring that initialization for sockets is performed only once,
 in-order to prevent resetting the socket instances already created in the global socket array (gastrSockets).
- Zero initializations to the global socket array (gastrSockets), which holds the list of TCP sockets.
- Registers the socket (Host Interface)hif callback function through the call to the hif_register_cb function.
   This facilitates handling all of the socket related functions received through interrupts from the firmware.
Returns
void
Remarks
This initialization function must be invoked before any socket operation is performed. No error codes from this initialization function since the socket array is statically allocated based on the maximum number of sockets MAX_SOCKET which is tuned to the systems capability.

Example

This example demonstrates the use of the socketInit for socket initialization for an mqtt chat application.

tstrNetworkId strNetworkId;
tstrAuthPsk strAuthPsk;
int8_t ret;
char topic[strlen(MAIN_CHAT_TOPIC) + MAIN_CHAT_USER_NAME_SIZE + 1];
//Initialize the board.
system_init();
//Initialize the UART console.
// Initialize the BSP.
----------
// Initialize socket interface.
registerSocketCallback(socket_event_handler, socket_resolve_handler);
// Connect to router.
strNetworkId.pu8Bssid = NULL;
strNetworkId.pu8Ssid = MAIN_WLAN_SSID;
strNetworkId.u8SsidLen = sizeof(MAIN_WLAN_SSID);
strNetworkId.u8Channel = M2M_WIFI_CH_ALL;
strAuthPsk.pu8Psk = NULL;
strAuthPsk.u8PassphraseLen = (uint8)strlen((char*)MAIN_WLAN_PSK);
m2m_wifi_connect_psk(WIFI_CRED_SAVE_ENCRYPTED, &strNetworkId, &strAuthPsk);
Returns
void
Remarks
This initialization function must be invoked before any socket operation is performed. No error codes from this initialization function since the socket array is statically allocated based in the maximum number of sockets MAX_SOCKET based on the systems capability.

Example

This example demonstrates the use of the socketinit for socket initialization for an mqtt chat application.

tstrNetworkId strNetworkId;
tstrAuthPsk strAuthPsk;
int8_t ret;
char topic[strlen(MAIN_CHAT_TOPIC) + MAIN_CHAT_USER_NAME_SIZE + 1];
//Initialize the board.
system_init();
//Initialize the UART console.
// Initialize the BSP.
----------
// Initialize socket interface.
registerSocketCallback(socket_event_handler, socket_resolve_handler);
// Connect to router.
strNetworkId.pu8Bssid = NULL;
strNetworkId.pu8Ssid = MAIN_WLAN_SSID;
strNetworkId.u8SsidLen = sizeof(MAIN_WLAN_SSID);
strNetworkId.u8Channel = M2M_WIFI_CH_ALL;
strAuthPsk.pu8Psk = NULL;
strAuthPsk.u8PassphraseLen = (uint8)strlen((char*)MAIN_WLAN_PSK);
m2m_wifi_connect_psk(WIFI_CRED_SAVE_ENCRYPTED, &strNetworkId, &strAuthPsk);

References gbSocketInit, gu16SessionID, hif_register_cb(), m2m_ip_cb(), m2m_memset(), M2M_REQ_GROUP_IP, and MAX_SOCKET.

Referenced by main(), wifi_ap_provision(), and wifi_init().