API documentation

BSD Library Management

group bsd

Application interface offered for management of BSD Library.

Functions

int bsd_init(const bsd_init_params_t *p_init_params)

Initialize the library.

Once initialized, the library uses the resources defined in bsd_platform.h.

Parameters
  • [in] p_init_params: Parameters to initialize bsd library. Cannot be NULL.

Return Value
  • Zero: on success.

  • A: positive value from BSD Modem DFU when executing Modem firmware updates.

  • -1: on error.

int bsd_shutdown(void)

Shutdown the library.

Resources reserved by the library in bsd_platform.h are freed when the library is shutdown.

Return Value
  • Zero: on success.

  • -1: on error.

void bsd_recoverable_error_handler(uint32_t error)

Handler for BSD library errors.

Parameters
  • [in] error: The error reason.

struct bsd_init_params_t
#include <bsd.h>

Structure for bsd library initialization parameters.

Public Members

bool trace_on

Indicates the traces are in use.

uint32_t bsd_memory_address

Defines the bsd library memory address.

uint32_t bsd_memory_size

Defines the bsd library memory size.

bsd_init() return values for modem firmware updates

group bsd_modem_dfu

bsd_init() return values when executing Modem firmware updates.

Defines

MODEM_DFU_RESULT_OK

Modem firmware update successful. The modem will run the updated firmware on reboot.

MODEM_DFU_RESULT_INTERNAL_ERROR

Modem firmware update failed. The modem encoutered a fatal internal error during firmware update.

MODEM_DFU_RESULT_HARDWARE_ERROR

Modem firmware update failed. The modem encoutered a fatal hardware error during firmware update.

MODEM_DFU_RESULT_AUTH_ERROR

Modem firmware update failed, due to an authentication error. The modem will automatically run the previous (non-updated) firmware on reboot.

MODEM_DFU_RESULT_UUID_ERROR

Modem firmware update failed, due to UUID mismatch. The modem will automatically run the previous (non-updated) firmware on reboot.

Limits of the BSD library

group bsd_limits

Upper and lower bound limits of BSD library.

Defines

BSD_MAX_SOCKET_COUNT

Maximum number of AT and IP sockets available at the same time.

BSD_AT_MAX_CMD_SIZE

Maximum AT Command Size in bytes.

BSD_IP_MAX_MESSAGE_SIZE

Maximum IP message size in bytes.

BSD_TLS_MAX_MESSAGE_SIZE

Maximum TLS message size in bytes.

BSD_MAX_PDN_COUNT

Maximum number of PDN connections that can be created.

BSD Platform

group bsd_platform_ipc
group bsd_version

BSD Library version number.

Defines

BSD_VERSION_MAJOR_NUMBER

Major version number.

BSD_VERSION_MINOR_NUMBER

Minor version number.

group bsd_reserved_memory

Memory reserved by the BSD library for communication with the application and the network layer.

Defines

BSD_RESERVED_MEMORY_ADDRESS

Memory start address reserved by the BSD library.

BSD_RESERVED_MEMORY_SIZE

Memory size reserved by the BSD library. This value has to match with the application RAM start address defined in the linker script.

BSD_RESERVED_MEMORY_SIZE_TRACE_DISABLED

Memory size reserved by the BSD library when trace will always be disabled.

group BSD_reserved_interrupts

Interrupts and priorities reserved by the BSD library for communication with the application and the network layer.

Defines

BSD_NETWORK_IRQ

Interrupt used for communication with the network layer.

BSD_NETWORK_IRQ_PRIORITY

Interrupt priority used on interrupt for communication with the network layer.

BSD_APPLICATION_IRQ

Interrupt used for communication with the application layer.

BSD_APPLICATION_IRQ_HANDLER

Interrupt handler used for communication with the application layer.

BSD_APPLICATION_IRQ_PRIORITY

Interrupt priority used on interrupt for communication with the application layer.

RPC_MAX_CLIENTS

Maximum number of client that can be registered with RPC.

RPC_TRANSPORT_IPC

Enable IPC based transport.

Socket parameter enumerators

Socket families

group nrf_socket_families

Defines

NRF_AF_LOCAL

Family to identify protocols/operations local to Nordic device.

NRF_AF_INET

IPv4 socket family.

NRF_AF_PACKET

Raw packet family.

NRF_AF_INET6

IPv6 socket family.

NRF_AF_LTE

Nordic proprietary LTE socket family.

Socket types

group nrf_socket_types

Defines

NRF_SOCK_STREAM

TCP socket type.

NRF_SOCK_DGRAM

UDP socket type.

NRF_SOCK_RAW

RAW socket type.

NRF_SOCK_MGMT

Nordic specific management socket. Used for system or link management.

Socket protocols

group nrf_socket_protocols

Defines

NRF_IPPROTO_TCP

TCP protocol.

NRF_IPPROTO_UDP

UDP protocol.

NRF_SPROTO_TLS1v2

TLS1v2 protocol.

NRF_SPROTO_TLS1v3

TLS1v3 protocol.

NRF_SPROTO_DTLS1v2

DTLS1v2 protocol.

NRF_PROTO_AT

AT command protocol.

NRF_PROTO_PDN

PDN management protocol.

NRF_PROTO_DFU

DFU protocol.

NRF_PROTO_GNSS

GNSS protocol.

Socket API

group nrf_socket_api

Functions

int nrf_socket(int family, int type, int protocol)

Function for creating a socket.

API to create a socket that can be used for network communication independently of lower protocol layers.

Return

A non-negative socket descriptor on success, or -1 on error.

Parameters
  • [in] family: The protocol family of the network protocol to use.

  • [in] type: The protocol type to use for this socket.

  • [in] protocol: The transport protocol to use for this socket.

int nrf_close(int sock)

Function for closing a socket and freeing any resources held by it.

If the socket is already closed, this function does nothing.

Return

0 on success, or -1 on error.

Parameters
  • [in] sock: The socket to close.

int nrf_fcntl(int fd, int cmd, int flags)

Function for controlling file descriptor options.

Set or get file descriptor options or flags. For a list of supported commands, refer to Descriptor manipulate API. For a list of supported flags, refer to nrf_fcnt_flags.

Parameters
  • [in] fd: The descriptor to set options on.

  • [in] cmd: The command class for options.

  • [in] flags: The flags to set.

int nrf_connect(int sock, const void *p_servaddr, nrf_socklen_t addrlen)

Function for connecting to an endpoint with a given address.

The socket handle must be a valid handle that has not yet been connected. Running connect on a connected handle will return an error.

Return

0 on success, or -1 on error.

Parameters
  • [in] sock: The socket to use for connection.

  • [in] p_servaddr: The address of the server to connect to.

  • [in] addrlen: The size of the p_servaddr argument.

ssize_t nrf_send(int sock, const void *p_buff, size_t nbytes, int flags)

Function for sending data through a socket.

By default, this function will block unless the NRF_O_NONBLOCK socket option has been set, OR NRF_MSG_DONTWAIT is passed as a flag. In that case, the method will return immediately.

Return

The number of bytes that were sent on success, or -1 on error.

Parameters
  • [in] sock: The socket to write data to.

  • [in] p_buff: Buffer containing the data to send.

  • [in] nbytes: Size of data contained on p_buff.

  • [in] flags: Flags to control send behavior.

ssize_t nrf_sendto(int sock, const void *p_buff, size_t nbytes, int flags, const void *p_servaddr, nrf_socklen_t addrlen)

Function for sending datagram through a socket.

By default, this function will block if the lower layers are not able to process the packet, unless the NRF_O_NONBLOCK socket option has been set, OR NRF_MSG_DONTWAIT is passed as a flag. In that case, the method will return immediately.

Return

The number of bytes that were sent on success, or -1 on error.

Parameters
  • [in] sock: The socket to write data to.

  • [in] p_buff: Buffer containing the data to send.

  • [in] nbytes: Size of data contained in p_buff.

  • [in] flags: Flags to control send behavior.

  • [in] p_servaddr: The address of the server to send to.

  • [in] addrlen: The size of the p_servaddr argument.

ssize_t nrf_write(int sock, const void *p_buff, size_t nbytes)

Function for writing data to a socket. See nrf_send() for details.

Return

The number of bytes that were sent on success, or -1 on error.

Parameters
  • [in] sock: The socket to write data to.

  • [in] p_buff: Buffer containing the data to send.

  • [in] nbytes: Size of data contained in p_buff.

ssize_t nrf_recv(int sock, void *p_buff, size_t nbytes, int flags)

Function for receiving data on a socket.

API for receiving data from a socket. By default, this function will block, unless the NRF_O_NONBLOCK socket option has been set, or NRF_MSG_DONTWAIT is passed as a flag.

Return

The number of bytes that were read, or -1 on error.

Parameters
  • [in] sock: The socket to receive data from.

  • [out] p_buff: Buffer to hold the data to be read.

  • [in] nbytes: Number of bytes to read. Should not be larger than the size of p_buff.

  • [in] flags: Flags to control receive behavior.

ssize_t nrf_recvfrom(int sock, void *p_buff, size_t nbytes, int flags, void *p_cliaddr, nrf_socklen_t *p_addrlen)

Function for receiving datagram on a socket.

API for receiving data from a socket. By default, this function will block, unless the NRF_O_NONBLOCK socket option has been set, or NRF_MSG_DONTWAIT is passed as a flag.

Return

The number of bytes that were read, or -1 on error.

Parameters
  • [in] sock: The socket to receive data from.

  • [out] p_buff: Buffer to hold the data to be read.

  • [in] nbytes: Number of bytes to read. Should not be larger than the size of p_buff.

  • [in] flags: Flags to control receive behavior.

  • [out] p_cliaddr: Socket address that will be set to the client’s address.

  • [inout] p_addrlen: The size of the p_cliaddr passed. Might be modified by the function.

ssize_t nrf_read(int sock, void *p_buff, size_t nbytes)

Function for reading data from a socket. See nrf_recv() for details.

Return

The number of bytes that were read, or -1 on error.

Parameters
  • [in] sock: The socket to receive data from.

  • [out] p_buff: Buffer to hold the data to be read.

  • [in] nbytes: Number of bytes to read. Should not be larger than the size of p_buff.

int nrf_select(int nfds, nrf_fd_set *p_readset, nrf_fd_set *p_writeset, nrf_fd_set *p_exceptset, const struct nrf_timeval *p_timeout)

Function for waiting for read, write, or exception events on a socket.

Wait for a set of socket descriptors to be ready for reading, writing, or having exceptions. The set of socket descriptors is configured before calling this function. This function will block until any of the descriptors in the set has any of the required events. This function is mostly useful when using NRF_O_NONBLOCK or NRF_MSG_DONTWAIT options to enable asynchronous operation.

Return

The number of ready descriptors contained in the descriptor sets on success, or -1 on error.

Parameters
  • [in] nfds: The highest socket descriptor value contained in the sets.

  • [inout] p_readset: The set of descriptors for which to wait for read events. Set to NULL if not used.

  • [inout] p_writeset: The set of descriptors for which to wait for write events. Set to NULL if not used.

  • [inout] p_exceptset: The set of descriptors for which to wait for exception events. Set to NULL if not used.

  • [in] p_timeout: The timeout to use for select call. Set to NULL if waiting forever.

int nrf_poll(struct nrf_pollfd *p_fds, uint32_t nfds, int timeout)

Method to poll for events on one or more sockets.

Return

A positive number less than or equal to nfds indicating sockets on which events occurred. 0 indicates the timed out occurred and no file descriptors were ready. -1 on error, and errno indicates the reason for failure.

Parameters
  • [inout] p_fds: An array of sockets, and respective for each socket that the caller polls for. The occurred events per socket is returned in the revents field of nrf_pollfd structure. Shall not be NULL.

  • [in] nfds: Positive number of sockets being polled for events. Shall not be more than BSD_MAX_SOCKET_COUNT.

  • [in] timeout: Timeout in milliseconds. The methods waits for this time period for the events to occur on the sockets.

int nrf_setsockopt(int sock, int level, int optname, const void *p_optval, nrf_socklen_t optlen)

Function for setting socket options for a given socket.

The options are grouped by level, and the option value should be the expected for the given option, and the lifetime must be longer than that of the socket.

Return

0 on success, or -1 on error.

Parameters
  • [in] sock: The socket for which to set the option.

  • [in] level: The level or group to which the option belongs.

  • [in] optname: The name of the socket option.

  • [in] p_optval: The value to be stored for this option.

  • [in] optlen: The size of p_optval.

int nrf_getsockopt(int sock, int level, int optname, void *p_optval, nrf_socklen_t *p_optlen)

Function for getting socket options for a given socket.

The options are grouped by level, and the option value is the value described by the option name.

Return

0 on success, or -1 on error.

Parameters
  • [in] sock: The socket for which to set the option.

  • [in] level: The level or group to which the option belongs.

  • [in] optname: The name of the socket option.

  • [out] p_optval: Pointer to the storage for the option value.

  • [inout] p_optlen: The size of p_optval. Can be modified to the actual size of p_optval.

int nrf_bind(int sock, const void *p_myaddr, nrf_socklen_t addrlen)

Function for binding a socket to an address and port.

The provided address must be supported by the socket protocol family.

Return

0 on success, or -1 on error.

Parameters
  • [in] sock: The socket descriptor to bind.

  • [in] p_myaddr: The address to bind this socket to.

  • [in] addrlen: The size of p_myaddr.

int nrf_listen(int sock, int backlog)

Function to put the socket in listening mode for incoming connections.

Once a socket is marked to be in the listening state, it remains a listening socket until closed. It is important to consider the backlog parameter, as it will affect how much memory your application will use in the worst case.

Return

0 on success, or -1 on error.

Parameters
  • [in] sock: The socket descriptor on which to set the listening options.

  • [in] backlog: The max length of the queue of pending connections. A value of 0 means infinite.

int nrf_accept(int sock, void *p_cliaddr, nrf_socklen_t *p_addrlen)

Function for waiting for the next client to connect.

This function will block if there are no clients attempting to connect.

Return

A non-negative client descriptor on success, or -1 on error.

Parameters
  • [in] sock: The socket descriptor to use for waiting on client connections.

  • [out] p_cliaddr: Socket address that will be set to the client’s address.

  • [out] p_addrlen: The size of the p_cliaddr passed. Might be modified by the function.

TLS socket

group nrf_socket_tls

TLS socket API.

Defines

NRF_SO_SEC_ROLE

Socket option to set role for the connection. Accepts an nrf_sec_role_t with values:

  • 0 - Client role.

  • 1 - Server role.

NRF_SO_SEC_TAG_LIST

Socket option to select the security tags to be used.

See

nrf_sec_tag_t.

NRF_SO_SEC_SESSION_CACHE

Socket option to control TLS session caching. Accepts an nrf_sec_session_cache_t with values:

  • 0 - Disabled.

  • 1 - Enabled.

    See

    nrf_sec_session_cache_t.

NRF_SO_SEC_PEER_VERIFY

Socket option to set peer verification level. This option accepts an nrf_sec_peer_verify_t with values:

  • 0 - None

  • 1 - Optional

  • 2 - Required

    See

    nrf_sec_peer_verify_t.

NRF_SO_HOSTNAME

Socket option to set the hostname used for peer verification. This option accepts a string containing the hostname, and its length. The length may be set to zero to disable hostname verification.

NRF_SO_CIPHERSUITE_LIST

Socket option to select which ciphersuites to use.

See

nrf_sec_cipher_t.

NRF_SO_CIPHER_IN_USE

Socket option to retrieve the ciphersuites used during the handshake.

See

nrf_sec_cipher_t.

NRF_IFNAMSIZ

Typedefs

typedef uint32_t nrf_sec_role_t

TLS role for the connection.

  • 0 - TLS client role.

  • 1 - TLS server role.

typedef uint32_t nrf_sec_tag_t

Security tags used on the TLS socket.

More than one security tags may be used on a socket. If more than one tag is used on the socket, pass an array of security tags.

A maximum of 8 tags can be set per socket.

typedef uint8_t nrf_sec_session_cache_t

Session cache configuration for the TLS connection.

  • 0 - Disabled.

  • 1 - Enabled.

By default, the session cache is enabled.

Note

Session cache, may not be used if the peer does not support it.

typedef uint32_t nrf_sec_peer_verify_t

Peer verification level for the TLS connection.

  • 0 - None.

  • 1 - Optional.

  • 2 - Required.

By default, peer verification is optional.

typedef uint32_t nrf_sec_cipher_t

A IANA cipher suite identifier.

struct nrf_sec_config_t
#include <nrf_socket.h>

Data type to combine all security configuration parameters.

Public Members

nrf_sec_role_t role

Local role to be played. See nrf_sec_role_t for details.

nrf_sec_peer_verify_t peer_verify

Indicates the preference for peer verification. See nrf_sec_peer_verify_t for details.

nrf_sec_session_cache_t session_cache

Indicates the preference for session caching. See nrf_sec_session_cache_t for details.

uint32_t cipher_count

Indicates the number of entries in the cipher list.

nrf_sec_cipher_t *p_cipher_list

Indicates the list of ciphers to be used for the session. See nrf_sec_cipher_t for details.

uint32_t sec_tag_count

Indicates the number of entries in the sec tag list.

nrf_sec_tag_t *p_sec_tag_list

Indicates the list of security tags to be used for the session. See nrf_sec_tag_t for details.

struct nrf_ifreq
#include <nrf_socket.h>

Data type for network interface.

GNSS socket

GNSS socket options

group nrf_socket_gnss_options

Sockets options to configure behaviour of the socket.

Defines

NRF_SO_GNSS_FIX_INTERVAL

Identifies the option used to set the GNSS fix interval in seconds.

Single-fix navigation mode is engaged by setting the fix interval to 0.

Continuous navigation mode is engaged by setting fix interval to 1.

Periodic navigation mode is engaged by setting the fix interval to value 10…1800. The unit is seconds.

NRF_SO_GNSS_FIX_RETRY

Identifies the option used to set the GNSS fix retry interval in seconds.

Fix retry parameter controls the maximum time the GNSS receiver is allowed to run while trying to produce a valid PVT estimate. If the fix retry time is non-zero, the GNSS receiver is turned off after the fix retry time is up regardless of whether a valid PVT estimate was produced or not. If fix retry parameter is set to zero, the GNSS receiver is allowed to run indefinitely until a valid PVT estimate is produced.

NRF_SO_GNSS_SYSTEM

Identifies the option used to set and/or get the GNSS system used. See nrf_gnss_system_t for details.

NRF_SO_GNSS_NMEA_MASK

Identifies the option used to select the data format of the received data.

NRF_SO_GNSS_ELEVATION_MASK

Indicates at which elevation the GPS should stop tracking a satellite.

NRF_SO_GNSS_USE_CASE

Indicates the targeted start performance: 0 = single cold start performance targeted, 1 = multiple hot start performance targeted.

NRF_SO_GNSS_START

Identifies the option to start the GPS. nrf_gnss_delete_mask_t given as payload.

NRF_SO_GNSS_STOP

Identifies the option to stop the GPS. nrf_gnss_delete_mask_t given as payload.

NRF_SO_GNSS_POWER_SAVE_MODE

Identifies the option to set power save mode.

NRF_SO_GNSS_ENABLE_PRIORITY

Identifies the option to enable priority time window (with no payload).

NRF_SO_GNSS_DISABLE_PRIORITY

Identifies the option to disable priority time window (with no payload).

GNSS socket option data types

group nrf_socketopt_gnss_types

Data types defined to set and get socket options on GNSS sockets.

Typedefs

typedef uint16_t nrf_gnss_fix_interval_t

Defines the interval between each fix in seconds.

Allowed values are 0, 1, 10..1800, value 0 denotes single fix. Default interval is 1 second (continous mode), 0 denotes a single fix.

typedef uint16_t nrf_gnss_fix_retry_t

Defines how long (in seconds) the receiver should try to get a fix.

The default retry wait time is 60 seconds before it gives up. 0 denotes an infinite limit.

typedef uint8_t nrf_gnss_system_t

Defines which GNSS system to use.

0 denotes GPS. Currently, only GPS is supported and any other value returns an error.

typedef uint8_t nrf_gnss_elevation_mask_t

Defines at which elevation the GPS should track a satellite.

This option is used to make the GPS stop tracking GPSes on a certain elevation, because the information sent from the GPS gets more inaccurate as it gets closer to the horizon. Acceptable values are between 0 and 30 degrees.

typedef uint8_t nrf_gnss_use_case_t

Defines the targeted start performance.

0 denotes single cold start performance. 1 denotes multiple hot start performance.

typedef uint16_t nrf_gnss_nmea_mask_t

Defines if NMEA frames should be added.

typedef uint8_t nrf_gnss_power_save_mode_t

Defines which power mode policy to use for the GNSS module.

  • NRF_GNSS_PSM_DISABLED for no power mode policy.

  • NRF_GNSS_PSM_DUTY_CYCLING_PERFORMANCE for low power mode with better performance.

  • NRF_GNSS_PSM_DUTY_CYCLING_POWER for low power mode with lower power consumption.

The available power modes determine whether duty-cycled tracking is allowed, and, if allowed what is the target performance.

Performance duty-cycled power mode: Duty-cycled tracking is engaged and run when conditions allow it without significant performance degradation.

Power duty-cycled power mode:: Duty-cycled tracking is engaged and run whenever it is possible with acceptable performance degradation.

The GNSS receiver keeps producing PVT estimates at the configured rate regardless of whether it is tracking continuously or in duty cycles. However, a failure to produce a valid PVT estimate during duty-cycled tracking may cause the GNSS receiver to resume continuous tracking.

typedef uint32_t nrf_gnss_delete_mask_t

Defines a mask of non-volatile data types to delete.

  • Bit 0 denotes ephemerides data.

  • Bit 1 denotes almanac data (excluding leap second and ionospheric correction parameters).

  • Bit 2 denotes ionospheric correction parameters data.

  • Bit 3 denotes last good fix (the last position) data.

  • Bit 4 denotes GPS time-of-week (TOW) data.

  • Bit 5 denotes GPS week number data.

  • Bit 6 denotes leap second (UTC parameters) data.

  • Bit 7 denotes local clock (TCXO) frequency offset data.

NMEA mask enumerator

group nrf_socket_gnss_nmea_str_mask

Use these bitmask values to enable different type of NMEA output strings, the values can be OR’ed together to enable multiple string types at the same time. Writing 0 to the bit position will disable the corresponding NMEA string type.

Defines

NRF_GNSS_NMEA_GGA_MASK

Enables Global Positioning System Fix Data.

NRF_GNSS_NMEA_GLL_MASK

Enables Geographic Position Latitude/Longitude and time.

NRF_GNSS_NMEA_GSA_MASK

Enables DOP and active satellites.

NRF_GNSS_NMEA_GSV_MASK

Enables Satellites in view.

NRF_GNSS_NMEA_RMC_MASK

Enables Recommended minimum specific GPS/Transit data.

Power save mode enumerator

group nrf_socket_gnss_psm_modes

Use these values to select which power save mode the GNSS module should use.

Defines

NRF_GNSS_PSM_DISABLED
NRF_GNSS_PSM_DUTY_CYCLING_PERFORMANCE
NRF_GNSS_PSM_DUTY_CYCLING_POWER

GNSS socket data frames

group nrf_socket_gnss_data_frame

GNSS Data frame formats. All data frames will be wrapped with the nrf_gnss_data_frame_t which will identify the frame type in the data_id struct element.

Defines

NRF_GNSS_MAX_SATELLITES
NRF_GNSS_NMEA_MAX_LEN
NRF_GNSS_AGPS_GPS_UTC_REQUEST
NRF_GNSS_AGPS_KLOBUCHAR_REQUEST
NRF_GNSS_AGPS_NEQUICK_REQUEST
NRF_GNSS_AGPS_SYS_TIME_AND_SV_TOW_REQUEST
NRF_GNSS_AGPS_POSITION_REQUEST
NRF_GNSS_AGPS_INTEGRITY_REQUEST
NRF_GNSS_PVT_DATA_ID
NRF_GNSS_NMEA_DATA_ID
NRF_GNSS_AGPS_DATA_ID

Typedefs

typedef char nrf_gnss_nmea_data_frame_t[83]

Single null-terminated NMEA sentence.

struct nrf_gnss_datetime_t
#include <nrf_socket.h>

Public Members

uint16_t year

4-digit representation (Gregorian calendar).

uint8_t month

1…12

uint8_t day

1…31

uint8_t hour

0…23

uint8_t minute

0…59

uint8_t seconds

0…59

uint16_t ms

0…999

struct nrf_gnss_sv_t
#include <nrf_socket.h>

Public Members

uint16_t sv

SV number 1…32 for GPS.

uint8_t signal

Signal type. 0: invalid, 1: GPS L1C/A, other values are reserved for other GNSSes or signals.

uint16_t cn0

0.1 dB/Hz.

int16_t elevation

SV elevation angle in degrees.

int16_t azimuth

SV azimuth angle in degrees.

uint8_t flags

Bit mask of measurement and position computation flags.

struct nrf_gnss_pvt_data_frame_t
#include <nrf_socket.h>

Public Members

double latitude

Latitude in degrees.

double longitude

Longitude in degrees.

float altitude

Altitude above WGS-84 ellipsoid in meters.

float accuracy

Accuracy (2D 1-sigma) in meters.

float speed

Horizontal speed in meters.

float heading

Heading of user movement in degrees.

float pdop

Position dilution of precision.

float hdop

Horizontal dilution of precision.

float vdop

Vertical dilution of precision.

float tdop

Time dilution of precision.

uint8_t flags

Bit 0 (LSB): fix validity. Bit 1: Leap second validity. Bit 2: If set, the GNSS operation is blocked, for example, by LTE.

nrf_gnss_sv_t sv[12]

Describes up to 12 of the space vehicles used for the measurement.

struct nrf_gnss_agps_data_frame_t
#include <nrf_socket.h>

AGPS notification data frame used by the GPS module to let the application know it needs new APGS data.

Public Members

uint32_t sv_mask_ephe

Bit mask indicating the satellite PRNs for which the assistance GPS ephemeris data is needed.

uint32_t sv_mask_alm

Bit mask indicating the satellite PRNs for which the assistance GPS almanac data is needed.

uint32_t data_flags

Indicating other AGPS data models is needed by the GNSS module

struct nrf_gnss_data_frame_t
#include <nrf_socket.h>

Wrapper struct that used for all data frames read from the GNSS module.

Public Members

nrf_gnss_pvt_data_frame_t pvt

PVT (Position, Velocity, and Time) data notification frame

nrf_gnss_nmea_data_frame_t nmea

NMEA data notification frame

nrf_gnss_agps_data_frame_t agps

AGPS data request notification

GNSS socket AGPS data frames

group nrf_socket_gnss_data_agps

AGPS Data types.

Use these values in the address field when using sendto to write AGPS models to the GNSS module.

Defines

NRF_GNSS_AGPS_UTC_PARAMETERS

GPS UTC assistance AGPS parameters.

NRF_GNSS_AGPS_EPHEMERIDES

GPS ephemeris assistance AGPS parameters.

NRF_GNSS_AGPS_ALMANAC

GPS almanac assistance AGPS parameters.

NRF_GNSS_AGPS_KLOBUCHAR_IONOSPHERIC_CORRECTION

GPS ionospheric assistance AGPS parameters, Klobuchar model.

NRF_GNSS_AGPS_NEQUICK_IONOSPHERIC_CORRECTION

GPS ionospheric assistance AGPS parameters, NeQuick model.

NRF_GNSS_AGPS_GPS_SYSTEM_CLOCK_AND_TOWS

GPS system time and SV TOW assistance AGPS parameter.

NRF_GNSS_AGPS_LOCATION

GPS location assistance AGPS parameters

NRF_GNSS_AGPS_INTEGRITY

GPS integrity assistance AGPS parameters

NRF_GNSS_AGPS_MAX_SV_TOW

Typedefs

typedef uint16_t nrf_gnss_agps_data_type_t

Type used to select which AGPS data is written to the GPS module.

Goes into the p_servaddr parameter in the nrf_sendto function prototype. Possible values:

  • NRF_GNSS_AGPS_UTC_PARAMETERS

  • NRF_GNSS_AGPS_EPHEMERIDE

  • NRF_GNSS_AGPS_ALMANAC

  • NRF_GNSS_AGPS_KLOBUCHAR_IONOSPHERIC_CORRECTION

  • NRF_GNSS_AGPS_NEQUICK_IONOSPHERIC_CORRECTION

  • NRF_GNSS_AGPS_GPS_SYSTEM_CLOCK_AND_TOWS

  • NRF_GNSS_AGPS_LOCATION

  • NRF_GNSS_AGPS_INTEGRITY

struct nrf_gnss_agps_data_utc_t
#include <nrf_socket.h>

Public Members

int32_t a1

First order term of polynomial (sec/sec). Scale factor 2^-50. Range -8388608…8388607 (25 bits).

int32_t a0

Constant term of polynomial (sec). Scale factor 2^-30.

uint8_t tot

UTC reference GPS time-of-week (sec). Scale factor 2^12. Range 0..147.

uint8_t wn_t

UTC reference GPS week number modulo 256.

int8_t delta_tls

Current or past leap second count (sec).

uint8_t wn_lsf

Leap second reference GPS week number modulo 256.

int8_t dn

Leap second reference GPS day-of-week (day). Range 1…7.

int8_t delta_tlsf

Current or future leap second count (sec) (total size of the type-specific assistance data).

struct nrf_gnss_agps_data_ephemeris_t
#include <nrf_socket.h>

Public Members

uint8_t sv_id

Satellite ID (dimensionless). Range 1…32.

uint8_t health

Satellite health (dimensionless).

uint16_t iodc

Issue of data, clock parameters (dimensionless). Range 0…2047 (11 bits).

uint16_t toc

Clock parameters reference GPS time-of-week (sec). Scale factor 2^4. Range 0…37799.

int8_t af2

Clock drift rate (sec/sec2). Scale factor 2^-55.

int16_t af1

Clock drift (sec/sec). Scale factor 2^-43.

int32_t af0

Clock bias (sec). Scale factor 2^-31. Range -2097152…2097151 (22 bit)

int8_t tgd

Group delay (sec). Scale factor 2^-31.

uint8_t ura

URA index (dimensionless). Range 0…15.

uint8_t fit_int

Curve fit interval indication. Range 0…1.

uint16_t toe

Ephemeris parameters reference GPS time-of-week (sec). Scale factor 2^4. Range 0…37799.

int32_t w

Argument of perigee (semi-circle). Scale factor 2^-31.

int16_t delta_n

Mean motion difference (semi-circle/sec). Scale factor 2^-43.

int32_t m0

Mean anomaly at reference time (semi-circle). Scale factor 2^-31.

int32_t omega_dot

Rate of right ascension (semi-circle/sec). Scale factor 2^-43. Range -8388608…8388607 (24 bits).

uint32_t e

Eccentricity (dimensionless). Scale factor 2^-33.

int16_t idot

Rate of inclination angle (semi-circle/sec). Scale factor 2-43. Range -8192…8191 (14 bits).

uint32_t sqrt_a

Square root of semi-major axis (m). Scale factor 2^-19.

int32_t i0

Inclination angle at reference time (semi-circle). Scale factor 2^-31.

int32_t omega0

Longitude of ascending node at weekly epoch (semi-circle). Scale factor 2^-31.

int16_t crs

Orbit radius, sine harmonic amplitude (m). Scale factor 2^-5.

int16_t cis

Inclination angle, sine harmonic amplitude (rad). Scale factor 2^-29.

int16_t cus

Argument of latitude, sine harmonic amplitude (rad). Scale factor 2^-29.

int16_t crc

Orbit radius, cosine harmonic amplitude (m). Scale factor 2^-5.

int16_t cic

Inclination angle, cosine harmonic amplitude (rad). Scale factor 2^-29.

int16_t cuc

Argument of latitude, cosine harmonic amplitude (rad). Scale factor 2^-29.

struct nrf_gnss_agps_data_almanac_t
#include <nrf_socket.h>

Public Members

uint8_t sv_id

Satellite ID (dimensionless). Range 1…32.

uint8_t wn

Almanac reference GPS week number modulo 256.

uint8_t toa

Almanac reference GPS time-of-week (sec). Scale factor 2^12. Range 0…147.

uint8_t ioda

Issue of data, almanac (dimensionless). Range 0…3 (2 bits).

uint16_t e

Eccentricity (dimensionless). Scale factor 2^-21.

int16_t delta_i

Correction to inclination (semi-circle). Scale factor 2^-19.

int16_t omega_dot

Rate of right ascension (semi-circle/sec). Scale factor 2^-38.

uint8_t sv_health

Satellite health (dimensionless)

uint32_t sqrt_a

Square root of semi-major axis (m^(1/2)). Scale factor 2^-11. Range 0…16777215 (24 bit).

int32_t omega0

Longitude of ascending node at weekly epoch (semi-circle). Scale factor 2^-23. Range -8388608…8388607 (24 bits).

int32_t w

Argument of perigee (semi-circle). Scale factor 2^-23.

int32_t m0

Mean anomaly at reference time (semi-circle). Scale factor 2^-23. Range -8388608…8388608 (24 bits).

int16_t af0

Clock bias (sec). Scale factor 2^-20. Range -1024…1023 (11 bits).

int16_t af1

Clock drift (sec/sec). Scale factor 2^-38. Range -1024…1023 (11 bits).

struct nrf_gnss_agps_data_klobuchar_t
#include <nrf_socket.h>

Public Members

int8_t alpha0

Constant term (sec). Scale factor 2^-30.

int8_t alpha1

First-order coefficient (sec/semi-circle). Scale factor 2^-27.

int8_t alpha2

Second-order coefficient (sec/semi-circle^2). Scale factor 2^-24.

int8_t alpha3

Third-order coefficient (sec/semi-circle^3). Scale factor 2^-24.

int8_t beta0

Constant term (sec). Scale factor 2^11.

int8_t beta1

First-order coefficient (sec/semi-circle). Scale factor 2^14.

int8_t beta2

Second-order coefficient (sec/semi-circle^2). Scale factor 2^16.

int8_t beta3

Third-order coefficient (sec/semi-circle^3). Scale factor 2^16.

struct nrf_gnss_agps_data_nequick_t
#include <nrf_socket.h>

Public Members

int16_t ai0

Effective ionisation level 1st order parameter (SFU). Scale factor 2^-2. Range 0…2047 (11 bits).

int16_t ai1

Effective ionisation level 2nd order parameter (SFU/deg). Scale factor 2^-8. Range -1024…1023 (11 bits).

int16_t ai2

Effective ionisation level 3rd order parameter (SFU/deg^2). Scale factor 2^-15. Range -8192…8191 (14 bits).

uint8_t storm_cond

Storm condition bit mask indicating the ionospheric storm condition for different regions.

uint8_t storm_valid

Storm validity bit mask indicating for which regions the ionospheric storm condition bit is valid.

struct nrf_gnss_agps_data_tow_element_t
#include <nrf_socket.h>

Public Members

uint16_t tlm

First two bits (MSB) represent the reserved bit and integrity status flag in the telemetry message (TLM) word. The following 14 bits represent the TLM being broadcast by the satellite.

uint8_t flags

Bit 0 (LSB): anti-spoof flag. Bit 1: alert flag.

struct nrf_gnss_agps_data_system_time_and_sv_tow_t
#include <nrf_socket.h>

Public Members

uint16_t date_day

Day number since Jan 6th, 1980 00:00:00 UTC (USNO)

uint32_t time_full_s

Full seconds part of time-of-day (s). Range 0…86399.

uint16_t time_frac_ms

Fraction of a second part of time-of-day (ms). Range 0…999.

uint32_t sv_mask

Bit mask indicating the satellite PRNs for which the satellite-specific TOW assistance data is valid.

nrf_gnss_agps_data_tow_element_t sv_tow[32]

TOW assistance data for PRN n

struct nrf_gnss_agps_data_location_t
#include <nrf_socket.h>

Public Members

int32_t latitude

Geodetic latitude in WGS-84. Range -8388607…8388607. The relation between the coded number N and the latitude range X (in degrees) is as follows: N <= (2^23/90) * X < N + 1. For N = 2^23 - 1, the range is extended to include N+1. Range of X (in degrees) -90…90.

int32_t longitude

Geodetic longitude in WGS-84. Range -8388607..8388607. The relation between the coded number N and the longitude range X (in degrees) is as follows: N <= (2^24/360) * X < N + 1. Range of X (in degrees) -180…180.

int16_t altitude

Altitude. Above (positive value) or below (negative value) WGS-84 ellipsoid surface. Range -32767…32767. The relation between the coded number N and the altitude range a (in meters) is as follows: N <= a < N + 1. For N = 2^15 - 1 the range is extended to include all greater values of a.

uint8_t unc_semimajor

Uncertainty, semi-major. Range 0…127. The uncertainty (in meters) is mapped from the coded number K with following formula: r = C * ((1 + x)^K - 1), where C = 10 and x = 0,1. Range of r (in kilometers) 0…1800.

uint8_t unc_semiminor

Uncertainty, semi-minor. Range 0…127. The uncertainty (in meters) is mapped from the coded number K with following formula: r = C * ((1 + x)^K - 1), where C = 10 and x = 0,1. Range of r (in kilometers) 0…1800)

uint8_t orientation_major

Orientation angle between the major axis and north. Range in degrees 0…179.

uint8_t unc_altitude

Uncertainty, altitude. Range 0…127. The uncertainty in altitude h (in meters) is mapped from the coded number K with following formula: h = C * ((1 + x)^K - 1). where C = 45 and x = 0,025. Range of h (in meters) 0…990,5.

uint8_t confidence

The confidence level (expressed as a percentage) with which the position of a target entity is included within the uncertainty ellipsoid. Range 0…128. ‘0’ indicates ‘no information’. Values 101..128 should be treated as ‘0’.

struct nrf_gnss_agps_data_integrity_t
#include <nrf_socket.h>

Public Members

uint32_t integrity_mask

Bit mask indicating the unhealthy GPS satellite PRNs. When a mask bit is set, the corresponding GPS satellite PRN is unhealthy.

DFU socket

group nrf_socket_dfu

DFU socket API.

Defines

NRF_SO_DFU_FW_VERSION

Socket option to read the modem firmware version (UUID).

See

nrf_dfu_fw_version_t.

NRF_SO_DFU_RESOURCES

Socket option to retrieve the size of the largest firmware image that can be transferred to the modem for firmware updates.

See

nrf_dfu_resources_t.

NRF_SO_DFU_TIMEO

Socket option to control the timeout to send a firmware fragment.

Note

Not implemented.

NRF_SO_DFU_APPLY

Socket option to schedule a modem firmware update at next boot. The result of the update is returned by bsd_init, at next boot. The modem needs to be reset once more to run the updated firmware.

NRF_SO_DFU_REVERT

Socket option to schedule a rollback of a firmware update at next boot.

NRF_SO_DFU_BACKUP_DELETE

Socket option to delete a modem firmware image from the modem’s scratch area. This option removes the possibility to rollback to a previous version, and is necessary to receive new firmware images.

NRF_SO_DFU_OFFSET

Socket option read and write the offset of the downloaded firmware image in the modem’s scratch area. This option is used to determine whether a firmware image exists in the modem’s scratch area and its size. A value of 2.5 megabytes (2621440 bytes) is returned if the scratch area is dirty, and needs erasing (via NRF_SO_DFU_BACKUP_DELETE). If non-zero and different from 2.5 megabytes, the value indicates the size of the firmware image received so far.

NRF_SO_DFU_ERROR

Socket option to retrieve the latest DFU error, see DFU errors. Read-only.

Typedefs

typedef uint8_t nrf_dfu_fw_version_t[36]

Universally unique identifier of the modem firmware version. The UUID format is defined by RFC 4122.

typedef uint32_t nrf_dfu_resources_t

Maximum size for a firmware image, in bytes.

typedef uint32_t nrf_dfu_fw_offset_t

Size of the firmware image stored in flash, in bytes.

PDN socket

group nrf_socket_pdn

PDN socket API.

Data types defined to set and get socket options on a PDN socket.

Defines

NRF_SO_PDN_AF

Socket option control the supported address families on the PDN.

See

nrf_pdn_af_list_t.

NRF_SO_PDN_CONTEXT_ID

Socket option to retrieve the context ID on the PDN.

See

nrf_pdn_context_id_t.

NRF_SO_PDN_STATE

Socket option to retrieve the PDN state, read-only.

See

nrf_pdn_state_t.

Typedefs

typedef nrf_sa_family_t *nrf_pdn_af_list_t

List of address family(ies) for the PDN.

typedef uint8_t nrf_pdn_context_id_t

Context ID for the PDN.

typedef uint8_t nrf_pdn_state_t

PDN state. 1 - PDN is active. 0 - PDN is inactive.

Socket address resolution API

group nrf_socket_api_utils

Address resolution utility functions.

Utility functions and macros for resolving host name and converting address information between human readable and a format the BSDLib stack expect.

Defines

NRF_HTONS(val)

Host to network byte-orders on half word.

NRF_HTONL(val)

Host to network byte-orders on full word.

NRF_NTOHS(val)

Network to host byte-orders on half word.

NRF_NTOHL(val)

Network to host byte-orders on full word.

nrf_htons(x)

Convert byte order from host to network (short).

nrf_htonl(x)

Convert byte order from host to network (long).

nrf_ntohs(x)

Convert byte order from network to host (short).

nrf_ntohl(x)

Convert byte order from network to host (long).

NRF_INET_ADDRSTRLEN

Maximum length of IPv4 in string form, including null-termination character.

NRF_INET6_ADDRSTRLEN

Maximum length of IPv6 in string form, including null-termination character.

Typedefs

typedef uint32_t nrf_socklen_t

Socket module size type.

Functions

int nrf_inet_pton(int family, const char *p_src, void *p_dst)

Function for converting a human-readable IP address to a form usable by the socket API.

This function will convert a string form of addresses and encode it into a byte array in network byte order.

Note

Currently not supporting mixed IPv4 and IPv6 format strings.

Return

1 on success, 0 if p_src does not contain a valid address, -1 and errno set in case of error.

Parameters
  • [in] family: Address family. NRF_AF_INET or NRF_AF_INET6.

  • [in] p_src: Null-terminated string containing the address to convert.

  • [out] p_dst: Pointer to a struct nrf_in_addr or nrf_in6_addr where the address will be stored.

const char *nrf_inet_ntop(int family, const void *p_src, char *p_dst, nrf_socklen_t size)

Function for converting an IP address to a human-readable string form.

This function will decode the IP bytes from network byte order and convert it to a string form of the address.

Note

Currently not supporting mixed IPv4 and IPv6 format strings.

Return

Pointer to p_dst on success, NULL and errno set in case of error.

Parameters
  • [in] family: Address family. NRF_AF_INET or NRF_AF_INET6.

  • [in] p_src: Pointer to a struct nrf_in_addr or nrf_in6_addr containing the address to convert.

  • [out] p_dst: Pointer to a buffer where the string representation of the address will be stored.

  • [in] size: Size of the provided buffer in p_dst.

int nrf_getaddrinfo(const char *p_node, const char *p_service, const struct nrf_addrinfo *p_hints, struct nrf_addrinfo **pp_res)

Function to resolve the host name into IPv4 and/or IPv6 addresses.

Note

The memory pointed to by pp_res must be freed using nrf_freeaddrinfo when the address is no longer needed or before calling nrf_getaddrinfo again.

Return

0 if the procedure succeeds, else, an errno indicating the reason for failure.

Parameters
  • [in] p_node: Host name to resolve.

  • [in] p_service: Service to resolve.

  • [in] p_hints: Any hints to be used for the resolution.

  • [out] pp_res: Pointer to the linked list of resolved addresses if the procedure was successful.

void nrf_freeaddrinfo(struct nrf_addrinfo *p_res)

Function for freeing the memory allocated for the result of nrf_getaddrinfo.

When the linked list of resolved addresses created by nrf_getaddrinfo is no longer needed, call this function to free the allocated memory.

Parameters
  • [in] p_res: Pointer to the memory to be freed.

int nrf_setdnsaddr(int family, const void *in_addr)
struct nrf_sockaddr
#include <nrf_socket.h>

Generic socket address.

Only provided for API compatibility.

Public Members

uint8_t sa_len

Socket address length

int sa_family

Socket address family

char sa_data[]

Socket address

struct nrf_addrinfo
#include <nrf_socket.h>

Address information.

Public Members

int ai_flags

Input flags.

int ai_family

Address family of the socket.

int ai_socktype

Socket type.

int ai_protocol

Protocol of the socket.

nrf_socklen_t ai_addrlen

Length of the socket address.

struct nrf_sockaddr *ai_addr

Address of the socket.

char *ai_canonname

Canonical name of service location.

struct nrf_addrinfo *ai_next

Pointer to next in list.

File descriptor sets API

File descriptor sets are used as input to the nrf_select() function for doing I/O multiplexing. The maximum number of descriptors contained in a set is defined by NRF_FD_SETSIZE.

group nrf_fd_set_api

Types and macros used to manipulate the input data argument to the nrf_select() function.

File descriptor sets are used as input to the nrf_select() function for doing I/O multiplexing. The maximum number of descriptors contained in a set is defined by NRF_FD_SETSIZE.

Defines

NRF_FD_ZERO(set)

Clear the entire set.

NRF_FD_SET(fd, set)

Set a bit in the set.

NRF_FD_CLR(fd, set)

Clear a bit in the set.

NRF_FD_ISSET(fd, set)

Check if a bit in the set is set.

NRF_FD_SETSIZE

The max size of a set.

Typedefs

typedef uint32_t nrf_fd_set

Socket polling API

Necessary data types and defines to poll for events on one or more sockets using nrf_poll().

group nrf_socket_api_poll

Data types and defines for use with nrf_poll().

Necessary data types and defines to poll for events on one or more sockets using nrf_poll().

Defines

NRF_POLLIN

Event for data receive. Can be requested and returned.

NRF_POLLOUT

Event for data send. Can be requested and returned.

NRF_POLLERR

Event for error on the polled socket. Is set in returned events to indicate error on a polled socket. Ignored in requested events.

NRF_POLLHUP

Event to indicate that the polled socket has been closed by the peer. Ignored in requested events. Subsequent calls to read the socket will be possible until all outstanding data has been read, and return zero-length packets (EOF).

NRF_POLLNVAL

Event to indicate the polled socket is not open. Is set in returned events to indicate error on a polled socket. Ignored in requested events.

struct nrf_pollfd
#include <nrf_socket.h>

This structure is used to describe which events to poll for a given socket. Which is then given as argument to nrf_poll().

Public Members

int fd

Socket handle.

short events

Requested events, is a mask of events.

short revents

Returned events, is a mask of events.

OS specific definitions

group bsd_os

Defines

BSD_OS_NO_WAIT

Zero time-out.

BSD_OS_FOREVER

Infinite time-out.

Functions

void bsd_os_init(void)
int32_t bsd_os_timedwait(uint32_t context, int32_t *p_timeout)
void bsd_os_errno_set(int errno_val)
void bsd_os_application_irq_clear(void)
void bsd_os_application_irq_set(void)
void bsd_os_trace_irq_set(void)
void bsd_os_trace_irq_clear(void)
int32_t bsd_os_trace_put(const uint8_t *const p_buffer, uint32_t buf_len)
void bsd_os_application_irq_handler(void)
void bsd_os_trace_irq_handler(void)