Soletta™ Framework
Framework for making IoT devices

Full online documentation | C API Index
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Typedefs | Enumerations | Functions

Network module provides a way to handle network link interfaces. More...

Data Structures

struct  sol_network_link
 Structure to represent a network link. More...
 
struct  sol_network_link_addr
 Structure to represent a network address, both IPv6 and IPv4 are valid. More...
 

Macros

#define SOL_BLUETOOTH_ADDR_STRLEN   18
 String size of a Bluetooth address. More...
 
#define SOL_NETWORK_INET_ADDR_STR_LEN   48
 String size of an IPv4/v6 address. More...
 
#define SOL_NETWORK_LINK_CHECK_VERSION(link_,...)
 Macro used to check if a struct struct sol_network_link has the expected API version. More...
 

Typedefs

typedef struct
sol_network_hostname_pending 
sol_network_hostname_pending
 A handle returned by sol_network_get_hostname_address_info() More...
 
typedef struct sol_network_link sol_network_link
 Structure to represent a network link. More...
 
typedef struct
sol_network_link_addr 
sol_network_link_addr
 Structure to represent a network address, both IPv6 and IPv4 are valid. More...
 

Enumerations

enum  sol_network_bt_addr_type { SOL_NETWORK_BT_ADDR_BASIC_RATE, SOL_NETWORK_BT_ADDR_LE_PUBLIC, SOL_NETWORK_BT_ADDR_LE_RANDOM }
 Type of a Bluetooth address. More...
 
enum  sol_network_event { SOL_NETWORK_LINK_ADDED, SOL_NETWORK_LINK_REMOVED, SOL_NETWORK_LINK_CHANGED }
 Type of events generated for a network link. More...
 
enum  sol_network_family {
  SOL_NETWORK_FAMILY_UNSPEC, SOL_NETWORK_FAMILY_INET, SOL_NETWORK_FAMILY_INET6, SOL_NETWORK_FAMILY_BLUETOOTH,
  SOL_NETWORK_FAMILY_BLUETOOTH_RFCOMM, SOL_NETWORK_FAMILY_BLUETOOTH_L2CAP
}
 Type of a network address. More...
 
enum  sol_network_link_flags {
  SOL_NETWORK_LINK_UP = (1 << 0), SOL_NETWORK_LINK_BROADCAST = (1 << 1), SOL_NETWORK_LINK_LOOPBACK = (1 << 2), SOL_NETWORK_LINK_MULTICAST = (1 << 3),
  SOL_NETWORK_LINK_RUNNING = (1 << 4)
}
 Bitwise OR-ed flags to represent the status of a sol_network_link. More...
 

Functions

const struct sol_vectorsol_network_get_available_links (void)
 Retrieve the available network links on a system. More...
 
struct
sol_network_hostname_pending
sol_network_get_hostname_address_info (const struct sol_str_slice hostname, enum sol_network_family family, void(*host_info_cb)(void *data, const struct sol_str_slice hostname, const struct sol_vector *addrs_list), const void *data)
 Gets a hostname address info. More...
 
int sol_network_hostname_pending_cancel (struct sol_network_hostname_pending *handle)
 Cancels a request to get the hostname info. More...
 
static bool sol_network_link_addr_eq (const struct sol_network_link_addr *a, const struct sol_network_link_addr *b)
 Checks if two address are equal. More...
 
static bool sol_network_link_addr_eq_full (const struct sol_network_link_addr *a, const struct sol_network_link_addr *b, bool compare_ports)
 Checks if two address are equal - possibly including the port field. More...
 
const struct
sol_network_link_addr
sol_network_link_addr_from_str (struct sol_network_link_addr *addr, const char *buf)
 Converts a string address to sol_network_link_addr. More...
 
const char * sol_network_link_addr_to_str (const struct sol_network_link_addr *addr, struct sol_buffer *buf)
 Converts a sol_network_link_addr to a string. More...
 
int sol_network_link_down (uint16_t link_index)
 Sets a network link down. More...
 
char * sol_network_link_get_name (const struct sol_network_link *link)
 Gets the name of a network link. More...
 
int sol_network_link_up (uint16_t link_index)
 Sets a network link up. More...
 
int sol_network_subscribe_events (void(*cb)(void *data, const struct sol_network_link *link, enum sol_network_event event), const void *data)
 Subscribes to receive network link events. More...
 
int sol_network_unsubscribe_events (void(*cb)(void *data, const struct sol_network_link *link, enum sol_network_event event), const void *data)
 Stops receiving network link events. More...
 

Detailed Description

Network module provides a way to handle network link interfaces.

It makes it possible to observe events, to inquire available links and to set their states.

Macro Definition Documentation

#define SOL_BLUETOOTH_ADDR_STRLEN   18

String size of a Bluetooth address.

Examples:
/src/samples/bluetooth/browse.c, and /src/samples/bluetooth/connect-paired.c.

Referenced by found_device(), on_connect(), and on_disconnect().

#define SOL_NETWORK_INET_ADDR_STR_LEN   48
#define SOL_NETWORK_LINK_CHECK_VERSION (   link_,
  ... 
)
Value:
if (SOL_UNLIKELY((link_)->api_version != \
SOL_WRN("Unexpected API version (message is %u, expected %u)", \
return __VA_ARGS__; \
}
uint16_t api_version
Definition: sol-http.h:181
#define SOL_WRN(fmt,...)
Logs a message with warning level.
Definition: sol-log.h:645
#define SOL_NETWORK_LINK_API_VERSION
Definition: sol-network.h:168
#define SOL_UNLIKELY(x)
Convenience macro for unlikely branch annotation.
Definition: sol-macros.h:201

Macro used to check if a struct struct sol_network_link has the expected API version.

In case it has wrong version, it'll return extra arguments passed to the macro.

Typedef Documentation

Structure to represent a network link.

This struct contains the necessary information do deal with a network link. It has the state sol_network_link_flags, the index (the value used by the SO to identify the link) and its address sol_network_link_addr.

Structure to represent a network address, both IPv6 and IPv4 are valid.

Enumeration Type Documentation

Type of a Bluetooth address.

With the increased privacy allowed by Bluetooth Low Energy, a Bluetooth device may be identified by different types of addresses.

Enumerator
SOL_NETWORK_BT_ADDR_BASIC_RATE 
SOL_NETWORK_BT_ADDR_LE_PUBLIC 
SOL_NETWORK_BT_ADDR_LE_RANDOM 

Type of events generated for a network link.

See Also
sol_network_subscribe_events()
Enumerator
SOL_NETWORK_LINK_ADDED 
SOL_NETWORK_LINK_REMOVED 
SOL_NETWORK_LINK_CHANGED 

Type of a network address.

Tells how an address should be interpreted.

Enumerator
SOL_NETWORK_FAMILY_UNSPEC 

Unspecified address type.

SOL_NETWORK_FAMILY_INET 

IPv4 family.

SOL_NETWORK_FAMILY_INET6 

IPv6 family.

SOL_NETWORK_FAMILY_BLUETOOTH 

Bluetooth "raw" family.

SOL_NETWORK_FAMILY_BLUETOOTH_RFCOMM 

Bluetooth RFCOMM family.

SOL_NETWORK_FAMILY_BLUETOOTH_L2CAP 

Bluetooth L2CAP family.

Bitwise OR-ed flags to represent the status of a sol_network_link.

See Also
sol_network_link
Enumerator
SOL_NETWORK_LINK_UP 
SOL_NETWORK_LINK_BROADCAST 
SOL_NETWORK_LINK_LOOPBACK 
SOL_NETWORK_LINK_MULTICAST 
SOL_NETWORK_LINK_RUNNING 

Function Documentation

const struct sol_vector* sol_network_get_available_links ( void  )

Retrieve the available network links on a system.

Returns
A vector containing the available links
See Also
sol_network_link
Note
This vector is updated as soon as the SO notifies about a network link. This information is cached, so it's possible that at the moment it is called the data is still not available. It's recommended to first subscribe to receive network events (
See Also
sol_network_subscribe_events()) and then call it.
struct sol_network_hostname_pending* sol_network_get_hostname_address_info ( const struct sol_str_slice  hostname,
enum sol_network_family  family,
void(*)(void *data, const struct sol_str_slice hostname, const struct sol_vector *addrs_list)  host_info_cb,
const void *  data 
)

Gets a hostname address info.

This function will fetch the address of a given hostname. Since this may take some time to complete, this will be an asynchronous operation. When the address information is ready, host_info_cb will be called with it. If an error happens or it was not possible to fetch the host address information, addrs_list will be set to NULL. The list addrs_list will contain a set of sol_network_link_addr.

Note
This operation may be cancelled by user with sol_network_hostname_pending_cancel() while host_info_cb has not been called yet.
Parameters
hostnameThe hostname to get the address info.
familyThe family the returned addresses should be, pass SOL_NETWORK_FAMILY_UNSPEC to match them all.
host_info_cbA callback to be called with the address list.
dataData to host_info_cb.
Returns
A handle to a hostname or NULL on error.
See Also
sol_network_hostname_pending_cancel()
sol_network_family
int sol_network_hostname_pending_cancel ( struct sol_network_hostname_pending handle)

Cancels a request to get the hostname info.

Parameters
handleThe handle returned by sol_network_get_hostname_address_info
Returns
0 on success, -errno on error.
See Also
sol_network_get_hostname_address_info()
static bool sol_network_link_addr_eq ( const struct sol_network_link_addr a,
const struct sol_network_link_addr b 
)
inlinestatic

Checks if two address are equal.

This function compares two addresses to see if they are the same.

Parameters
aThe first address to be compared.
bThe second address to be compared.
Returns
true if they are equal, otherwise false.
Examples:
/src/samples/bluetooth/browse.c.

References sol_network_link_addr_eq_full().

Referenced by found_device().

static bool sol_network_link_addr_eq_full ( const struct sol_network_link_addr a,
const struct sol_network_link_addr b,
bool  compare_ports 
)
inlinestatic

Checks if two address are equal - possibly including the port field.

This function compares two addresses to see if they are the same.

Parameters
aThe first address to be compared.
bThe second address to be compared.
compare_portsIndicates if the port should be included in the comparison as well.
Returns
true if they are equal, otherwise false.

An IPv6 is Mapped into v4 when: First 80 bits are zero The next 16 bits are 0xffff

References sol_network_link_addr::addr, sol_network_link_addr::bt_addr, sol_network_link_addr::bt_type, sol_network_link_addr::family, sol_network_link_addr::in, sol_network_link_addr::in6, sol_network_link_addr::port, SOL_NETWORK_FAMILY_BLUETOOTH, SOL_NETWORK_FAMILY_INET, SOL_NETWORK_FAMILY_INET6, and sol_util_be16_to_cpu().

Referenced by sol_network_link_addr_eq().

const struct sol_network_link_addr* sol_network_link_addr_from_str ( struct sol_network_link_addr addr,
const char *  buf 
)

Converts a string address to sol_network_link_addr.

Parameters
addrA valid address with the same family of the address given in buf.
bufThe string with the address.
Returns
the network link address on success, NULL on error.
See Also
sol_network_link_addr_to_str()
Examples:
/src/samples/bluetooth/browse.c, /src/samples/coap/iotivity-test-client.c, /src/samples/coap/oic-client.c, /src/samples/coap/simple-client.c, and /src/samples/network/echo-client.c.

Referenced by main(), startup(), and startup_client().

const char* sol_network_link_addr_to_str ( const struct sol_network_link_addr addr,
struct sol_buffer buf 
)

Converts a sol_network_link_addr to a string.

Parameters
addrThe address to be converted.
bufThe buffer where the converted string will be appended - It must be already initialized.
Returns
a string with the network link address on success, NULL on error.
See Also
sol_network_link_addr_from_str()
Examples:
/src/samples/bluetooth/browse.c, /src/samples/bluetooth/connect-paired.c, /src/samples/coap/iotivity-test-client.c, /src/samples/coap/oic-client.c, /src/samples/coap/simple-client.c, /src/samples/http/server-sse.c, and /src/samples/network/network-status.c.

Referenced by _on_network_event(), found_device(), found_resource(), found_resource_print(), got_get_response(), on_connect(), on_disconnect(), print_response(), reply_cb(), request_cb(), and resource_notify().

int sol_network_link_down ( uint16_t  link_index)

Sets a network link down.

This function sets a network link down, after this a link will not be able to get a network address.

Parameters
link_indexThe index of a sol_network_link structure.
Returns
0 on success, -ENOSYS on error.
See Also
sol_network_linke_up()
char* sol_network_link_get_name ( const struct sol_network_link link)

Gets the name of a network link.

Parameters
linkThe sol_network_link structure which the name is desired.
Returns
The name of the interface on success, NULL on error.
Note
It must be freed by the user after usage.
Examples:
/src/samples/network/network-status.c.

Referenced by _match_link(), and _on_network_event().

int sol_network_link_up ( uint16_t  link_index)

Sets a network link up.

This function sets a network link up, after this a link will be able to get a network address.

Parameters
link_indexThe index of a sol_network_link structure.
Returns
true on success, -errno on error.
See Also
sol_network_linke_down()
int sol_network_subscribe_events ( void(*)(void *data, const struct sol_network_link *link, enum sol_network_event event)  cb,
const void *  data 
)

Subscribes to receive network link events.

This function register a callback given by the user that will be called when a network event (sol_network_event) occurrs in one link (sol_network_link).

Parameters
cbThe callback used to notify the user.
dataThe user data given in the callback.
Returns
true on success, -errno on error
See Also
sol_network_unsubscribe_events()
Examples:
/src/samples/network/network-status.c.

Referenced by startup_network().

int sol_network_unsubscribe_events ( void(*)(void *data, const struct sol_network_link *link, enum sol_network_event event)  cb,
const void *  data 
)

Stops receiving network link events.

This function removes previous callbacks set (sol_network_subscribe_events()) to receive network events.

Parameters
cbThe callback given on sol_network_subscribe_events.
dataThe data given on sol_network_subscribe_events.
Returns
O on success, -errno on error
Note
It should be the same pair (callback/userdata) given on sol_network_subscribe_events()
Examples:
/src/samples/network/network-status.c.

Referenced by shutdown_network().