lwIP network interface integration library
Loading...
Searching...
No Matches

General Description

Typedefs

typedef void(* cy_network_ip_change_callback_t) (cy_network_interface_context *iface_context, void *user_data)
 IP change callback function prototype Callback function which can be registered to receive IP address changes must be of this prototype.
 
typedef void(* cy_network_activity_event_callback_t) (bool event_type)
 Network activity callback function prototype.
 

Functions

cy_rslt_t cy_network_init ()
 Initializes the network stack, and allocates and initializes the resources needed by this library.
 
cy_rslt_t cy_network_deinit ()
 Deinitializes the network stack, and releases the resources allocated in the cy_network_init function.
 
cy_rslt_t cy_network_add_nw_interface (cy_network_hw_interface_type_t iface_type, uint8_t iface_idx, void *hw_interface, uint8_t *mac_address, cy_network_static_ip_addr_t *ipaddr, cy_network_interface_context **iface_context)
 Adds a network interface.
 
cy_rslt_t cy_network_remove_nw_interface (cy_network_interface_context *iface_context)
 Removes a network interface.
 
void * cy_network_get_nw_interface (cy_network_hw_interface_type_t iface_type, uint8_t iface_idx)
 Returns the network interface for the given network interface type.
 
cy_rslt_t cy_network_ip_up (cy_network_interface_context *iface_context)
 Brings up the network link layer and starts DHCP if required.
 
cy_rslt_t cy_network_ip_down (cy_network_interface_context *iface_context)
 Brings down the network interface and network link layer, and stops DHCP.
 
cy_rslt_t cy_network_dhcp_renew (cy_network_interface_context *iface_context)
 Invalidates all ARP entries and renews DHCP.
 
void cy_network_register_ip_change_cb (cy_network_interface_context *iface_context, cy_network_ip_change_callback_t cb, void *user_data)
 Helps to register/unregister for any IP address changes from the network stack.
 
void cy_network_activity_register_cb (cy_network_activity_event_callback_t cb)
 Helps to register/unregister a callback function that will be invoked on any Tx/Rx activity on any network interface.
 
cy_rslt_t cy_network_activity_notify (cy_network_activity_type_t activity_type)
 Notifies the network activity to the Low Power Assistant (LPA) module.
 
cy_rslt_t cy_network_get_ip_address (cy_network_interface_context *iface_context, cy_nw_ip_address_t *ip_addr)
 Retrieves the IPv4 address of the given interface.
 
cy_rslt_t cy_network_get_ipv6_address (cy_network_interface_context *iface_context, cy_network_ipv6_type_t type, cy_nw_ip_address_t *ip_addr)
 Retrieves the IPv6 address of the given interface.
 
cy_rslt_t cy_network_get_gateway_ip_address (cy_network_interface_context *iface_context, cy_nw_ip_address_t *gateway_addr)
 Retrieves the gateway IP address of the given interface.
 
cy_rslt_t cy_network_get_gateway_mac_address (cy_network_interface_context *iface_context, cy_nw_ip_mac_t *mac_addr)
 Retrieves the MAC address of the gateway for the given interface.
 
cy_rslt_t cy_network_get_netmask_address (cy_network_interface_context *iface_context, cy_nw_ip_address_t *net_mask_addr)
 Retrieves the subnet mask address of the given interface.
 
cy_rslt_t cy_network_ping (void *if_ctx, cy_nw_ip_address_t *address, uint32_t timeout_ms, uint32_t *elapsed_time_ms)
 Sends a ping request to the given IP address.
 
cy_rslt_t cy_network_random_number_generate (unsigned char *output, size_t len, size_t *olen)
 Random number generate using PDL trng APIs.
 

Typedef Documentation

◆ cy_network_ip_change_callback_t

typedef void(* cy_network_ip_change_callback_t) (cy_network_interface_context *iface_context, void *user_data)

IP change callback function prototype Callback function which can be registered to receive IP address changes must be of this prototype.

Parameters
[in]iface_contextInterface context that has been created with the cy_network_add_nw_interface function
[in]user_dataUser data provided at the time of callback registration

◆ cy_network_activity_event_callback_t

typedef void(* cy_network_activity_event_callback_t) (bool event_type)

Network activity callback function prototype.

The callback function which can be registered/unregistered for any network activity must be of this prototype.

Function Documentation

◆ cy_network_init()

cy_rslt_t cy_network_init ( )

Initializes the network stack, and allocates and initializes the resources needed by this library.

Returns
CY_RSLT_SUCCESS if successful; failure code otherwise.

◆ cy_network_deinit()

cy_rslt_t cy_network_deinit ( )

Deinitializes the network stack, and releases the resources allocated in the cy_network_init function.

Returns
CY_RSLT_SUCCESS if successful; failure code otherwise.

◆ cy_network_add_nw_interface()

cy_rslt_t cy_network_add_nw_interface ( cy_network_hw_interface_type_t  iface_type,
uint8_t  iface_idx,
void *  hw_interface,
uint8_t *  mac_address,
cy_network_static_ip_addr_t *  ipaddr,
cy_network_interface_context **  iface_context 
)

Adds a network interface.

Binds the hardware interface to the IP layer of the network stack.

Parameters
[in]iface_typeNetwork interface type cy_network_hw_interface_type_t
[in]iface_idxNetwork interface index. If the cy_network_add_nw_interface function is called multiple times for same interface type, the index passed should be the hardware port available on the device. This is used to handle multiple Ethernet interfaces. For example, ethernet port0 will have index as 0 and ethernet port1 will have index as 1.
[in]hw_interfaceHandle to the already initialized HW interface. For example, the whd_interface_t pointer that is initialized using the cybsp_wifi_init_primary() function. Similarly for Ethernet, it can be the Ethernet interface pointer.
[in]mac_addressMAC address to be configured to the network interface
[in]ipaddrStatic IP address provided by the user
[out]iface_contextInterface context. Network core library allocates memory for this structure and initializes it. Caller should not modify the contents of this structure, and should not free the memory. To free the memory allocated by this function, the caller should invoke the cy_network_remove_nw_interface function.
Returns
CY_RSLT_SUCCESS if successful; failure code otherwise.

◆ cy_network_remove_nw_interface()

cy_rslt_t cy_network_remove_nw_interface ( cy_network_interface_context *  iface_context)

Removes a network interface.

Unbinds the network interface from the IP layer of the network stack.

Parameters
[in]iface_contextInterface context that has been created with the cy_network_add_nw_interface function.
Returns
CY_RSLT_SUCCESS if successful; failure code otherwise.

◆ cy_network_get_nw_interface()

void * cy_network_get_nw_interface ( cy_network_hw_interface_type_t  iface_type,
uint8_t  iface_idx 
)

Returns the network interface for the given network interface type.

Parameters
[in]iface_typeNetwork interface type
[in]iface_idxNetwork interface index
Returns
Associated network stack's net interface structure for the HW interface

◆ cy_network_ip_up()

cy_rslt_t cy_network_ip_up ( cy_network_interface_context *  iface_context)

Brings up the network link layer and starts DHCP if required.

Parameters
[in]iface_contextInterface context that has been created with the cy_network_add_nw_interface function
Returns
CY_RSLT_SUCCESS on successful network bring up; failure code otherwise.

◆ cy_network_ip_down()

cy_rslt_t cy_network_ip_down ( cy_network_interface_context *  iface_context)

Brings down the network interface and network link layer, and stops DHCP.

Parameters
[in]iface_contextInterface context that has been created with the cy_network_add_nw_interface function
Returns
CY_RSLT_SUCCESS on successful teardown of the network; failure code otherwise.

◆ cy_network_dhcp_renew()

cy_rslt_t cy_network_dhcp_renew ( cy_network_interface_context *  iface_context)

Invalidates all ARP entries and renews DHCP.

Parameters
[in]iface_contextInterface context that has been created with the cy_network_add_nw_interface function
Returns
CY_RSLT_SUCCESS on successful network bring up; failure code otherwise.

◆ cy_network_register_ip_change_cb()

void cy_network_register_ip_change_cb ( cy_network_interface_context *  iface_context,
cy_network_ip_change_callback_t  cb,
void *  user_data 
)

Helps to register/unregister for any IP address changes from the network stack.

Passing "NULL" as callback will deregister the IP changes callback.

Parameters
[in]iface_contextInterface context that has been created with the cy_network_add_nw_interface function
[in]cbIP address change callback function
[in]user_dataUser data that is passed to the callback function

◆ cy_network_activity_register_cb()

void cy_network_activity_register_cb ( cy_network_activity_event_callback_t  cb)

Helps to register/unregister a callback function that will be invoked on any Tx/Rx activity on any network interface.

Passing "NULL" as cb will deregister the activity callback.

Parameters
[in]cbNetwork activity callback function

◆ cy_network_activity_notify()

cy_rslt_t cy_network_activity_notify ( cy_network_activity_type_t  activity_type)

Notifies the network activity to the Low Power Assistant (LPA) module.

Parameters
[in]activity_typeNetwork activity type cy_network_activity_type_t to be notified to the LPA module
Returns
CY_RSLT_SUCCESS if successful; failure code otherwise.

◆ cy_network_get_ip_address()

cy_rslt_t cy_network_get_ip_address ( cy_network_interface_context *  iface_context,
cy_nw_ip_address_t *  ip_addr 
)

Retrieves the IPv4 address of the given interface.

See cy_network_get_ipv6_address API to get IPv6 addresses.

Parameters
[in]iface_context: Interface context that has been created with the cy_network_add_nw_interface function
[out]ip_addr: Pointer to an IP address structure of type cy_nw_ip_address_t
Returns
CY_RSLT_SUCCESS if IP-address get is successful; failure code otherwise.

◆ cy_network_get_ipv6_address()

cy_rslt_t cy_network_get_ipv6_address ( cy_network_interface_context *  iface_context,
cy_network_ipv6_type_t  type,
cy_nw_ip_address_t *  ip_addr 
)

Retrieves the IPv6 address of the given interface.

Parameters
[in]iface_context: Interface context that has been created with the cy_network_add_nw_interface function
[in]type: IPv6 address type. Only IPv6 link-local address type is supported.
[out]ip_addr: Pointer to an IP address structure of type cy_nw_ip_address_t
Returns
CY_RSLT_SUCCESS if IP-address get is successful; failure code otherwise.

◆ cy_network_get_gateway_ip_address()

cy_rslt_t cy_network_get_gateway_ip_address ( cy_network_interface_context *  iface_context,
cy_nw_ip_address_t *  gateway_addr 
)

Retrieves the gateway IP address of the given interface.

Parameters
[in]iface_context: Interface context that has been created with the cy_network_add_nw_interface function
[out]gateway_addr: Pointer to an IP address structure of type cy_nw_ip_address_t to be filled with the gateway IP address
Returns
CY_RSLT_SUCCESS if retrieval of the gateway IP address was successful; failure code otherwise.

◆ cy_network_get_gateway_mac_address()

cy_rslt_t cy_network_get_gateway_mac_address ( cy_network_interface_context *  iface_context,
cy_nw_ip_mac_t *  mac_addr 
)

Retrieves the MAC address of the gateway for the given interface.

Uses Address Resolution Protocol (ARP) to retrieve the gateway MAC address.

This function is a blocking call and uses an internal timeout while running ARP.

Parameters
[in]iface_context: Interface context that has been created with the cy_network_add_nw_interface function
[out]mac_addr: Pointer to a MAC address structure which is filled with the gateway's MAC address on successful return
Returns
CY_RSLT_SUCCESS if retrieval of the gateway MAC address was successful; failure code otherwise.

◆ cy_network_get_netmask_address()

cy_rslt_t cy_network_get_netmask_address ( cy_network_interface_context *  iface_context,
cy_nw_ip_address_t *  net_mask_addr 
)

Retrieves the subnet mask address of the given interface.

Parameters
[in]iface_context: Interface context that has been created with the cy_network_add_nw_interface function
[out]net_mask_addr: Pointer to an IP address structure of type cy_nw_ip_address_t to be filled with the subnet mask address of the interface.
Returns
CY_RSLT_SUCCESS if retrieval of the subnet mask address was successful; failure code otherwise.

◆ cy_network_ping()

cy_rslt_t cy_network_ping ( void *  if_ctx,
cy_nw_ip_address_t *  address,
uint32_t  timeout_ms,
uint32_t *  elapsed_time_ms 
)

Sends a ping request to the given IP address.

Parameters
[in]if_ctx: Pointer to the network interface context (typecast to void *)
[in]address: Pointer to the destination IP address structure to which the ping request will be sent
[in]timeout_ms: Ping request timeout in milliseconds
[in]elapsed_time_ms: Pointer to store the roundtrip time (in milliseconds), i.e., the time taken to receive the ping response from the destination
Returns
CY_RSLT_SUCCESS if successful; CY_RSLT_NETWORK_ERROR_PING if failure.

◆ cy_network_random_number_generate()

cy_rslt_t cy_network_random_number_generate ( unsigned char *  output,
size_t  len,
size_t *  olen 
)

Random number generate using PDL trng APIs.

Parameters
[out]output: Data to fill
[in]len: Maximum size to provide
[out]olen: The actual amount of bytes put into the buffer (Can be 0)
Returns
CY_RSLT_SUCCESS if successful; CY_RSLT_NETWORK_ERROR_TRNG if failure.