This article describes the system-related API operations that need to be defined when you port Link SDK for C.
Architecture

Link SDK for C supports different operating systems or hardware platforms. Link SDK for C encapsulates system-related API operations to interact with operating systems or hardware platforms. When you develop a product, you must call the API operations in the SDK to implement business logic. You must also write code to define system-related API operations.
Description of system-related API operations
System-related API operations decouple Link SDK for C from operating systems. You can call the operations to interact with different operating systems.
The aiot_sysdep_portfile_t g_aiot_sysdep_portfile global variable is defined to include all system-related API operations.
The common operations and mutex-related operations are easy to use. This article does not describe how to call these operations. When you port the SDK, you must define all system-related API operations. You cannot specify NULL when you define the operations. Otherwise, errors occur.
List of system-related API operations
Type | Parameter | Description |
Common operations | core_sysdep_malloc | Applies for memory. |
core_sysdep_free | Releases memory. | |
core_sysdep_time | Obtains the current timestamp. Link SDK is used to calculate the deviation. | |
core_sysdep_sleep | Specifies a sleep time, in milliseconds. | |
core_sysdep_rand | Generates a random number. | |
Network-related operations | core_sysdep_network_init | Creates a session. |
core_sysdep_network_setopt | Sets parameters for a session. | |
core_sysdep_network_establish | Establishes a session. MQTT or HTTP connections are based on sessions. | |
core_sysdep_network_recv | Reads data from a specified session. | |
core_sysdep_network_send | Sends data by using a specified session. | |
core_sysdep_network_deinit | Destroys a session. | |
Mutex-related operations | core_sysdep_mutex_init | Creates a mutex. |
core_sysdep_mutex_lock | Applies for a mutex. | |
core_sysdep_mutex_unlock | Releases a mutex. | |
core_sysdep_mutex_deinit | Destroys a mutex. |
Set the network parameters
When you port Link SDK for C, you must set the following parameters of the core_sysdep_network_setopt operation.
Set the network connection type. You can create a TCP or UDP socket for connection.
Parameter
Description
CORE_SYSDEP_SOCKET_TCP_CLIENT
The TCP client. To establish MQTT, HTTP, HTTP2, or WebSocket connections, you must specify this parameter.
CORE_SYSDEP_SOCKET_UDP_CLIENT
The UDP client. To establish CoAP connections, you must specify this parameter.
Save the following parameters for subsequent use.
Parameter
Description
CORE_SYSDEP_NETWORK_SOCKET_TYPE
The type of the socket to be created.
Data type:
(core_sysdep_socket_type_t *)
.CORE_SYSDEP_NETWORK_HOST
The domain name or IP address that is used to establish the connection. The memory is shared by the upper-layer modules.
Data type:
(char *)
CORE_SYSDEP_NETWORK_BACKUP_IP
The backup IP address that is used if the DNS resolution fails. You do not need to specify this parameter.
CORE_SYSDEP_NETWORK_PORT
The port number that is used to establish the connection.
Data type:
(uint16_t *)
CORE_SYSDEP_NETWORK_CONNECT_TIMEOUT_MS
The timeout period to establish a connection, in milliseconds.
Data type:
(uint32_t *)
CORE_SYSDEP_NETWORK_MAX
This parameter is not used. You do not need to specify this parameter.
Sample code
Link SDK for C provides sample code in the portfile/aiot_port/posix_port.c
file. Code are ported based on the POSIX standard.