OpenOCD
device.c File Reference

Device enumeration and handling. More...

Include dependency graph for device.c:

Go to the source code of this file.

Functions

static bool _inet_pton (const char *str, struct in_addr *in)
 
static struct
jaylink_device_handle
allocate_device_handle (struct jaylink_device *dev)
 
static struct jaylink_device ** allocate_device_list (size_t length)
 
static void free_device_handle (struct jaylink_device_handle *devh)
 
JAYLINK_API int jaylink_close (struct jaylink_device_handle *devh)
 Close a device. More...
 
JAYLINK_API int jaylink_device_get_hardware_version (const struct jaylink_device *dev, struct jaylink_hardware_version *version)
 Get the hardware version of a device. More...
 
JAYLINK_API int jaylink_device_get_host_interface (const struct jaylink_device *dev, enum jaylink_host_interface *iface)
 Get the host interface of a device. More...
 
JAYLINK_API int jaylink_device_get_ipv4_address (const struct jaylink_device *dev, char *address)
 Get the IPv4 address string of a device. More...
 
JAYLINK_API int jaylink_device_get_mac_address (const struct jaylink_device *dev, uint8_t *address)
 Get the MAC address of a device. More...
 
JAYLINK_API int jaylink_device_get_nickname (const struct jaylink_device *dev, char *nickname)
 Get the nickname of a device. More...
 
JAYLINK_API int jaylink_device_get_product_name (const struct jaylink_device *dev, char *name)
 Get the product name of a device. More...
 
JAYLINK_API int jaylink_device_get_serial_number (const struct jaylink_device *dev, uint32_t *serial_number)
 Get the serial number of a device. More...
 
JAYLINK_API int jaylink_device_get_usb_address (const struct jaylink_device *dev, enum jaylink_usb_address *address)
 Get the USB address of a device. More...
 
JAYLINK_API void jaylink_free_devices (struct jaylink_device **devs, bool unref)
 Free devices. More...
 
JAYLINK_API int jaylink_get_caps (struct jaylink_device_handle *devh, uint8_t *caps)
 Retrieve the capabilities of a device. More...
 
JAYLINK_API int jaylink_get_counters (struct jaylink_device_handle *devh, uint32_t mask, uint32_t *values)
 Retrieve the counter values of a device. More...
 
JAYLINK_API struct jaylink_devicejaylink_get_device (struct jaylink_device_handle *devh)
 Get the device instance from a device handle. More...
 
JAYLINK_API int jaylink_get_devices (struct jaylink_context *ctx, struct jaylink_device ***devs, size_t *count)
 Get available devices. More...
 
JAYLINK_API int jaylink_get_extended_caps (struct jaylink_device_handle *devh, uint8_t *caps)
 Retrieve the extended capabilities of a device. More...
 
JAYLINK_API int jaylink_get_firmware_version (struct jaylink_device_handle *devh, char **version, size_t *length)
 Retrieve the firmware version of a device. More...
 
JAYLINK_API int jaylink_get_free_memory (struct jaylink_device_handle *devh, uint32_t *size)
 Retrieve the size of free memory of a device. More...
 
JAYLINK_API int jaylink_get_hardware_info (struct jaylink_device_handle *devh, uint32_t mask, uint32_t *info)
 Retrieve the hardware information of a device. More...
 
JAYLINK_API int jaylink_get_hardware_status (struct jaylink_device_handle *devh, struct jaylink_hardware_status *status)
 Retrieve the hardware status of a device. More...
 
JAYLINK_API int jaylink_get_hardware_version (struct jaylink_device_handle *devh, struct jaylink_hardware_version *version)
 Retrieve the hardware version of a device. More...
 
JAYLINK_API int jaylink_open (struct jaylink_device *dev, struct jaylink_device_handle **devh)
 Open a device. More...
 
JAYLINK_API int jaylink_read_raw_config (struct jaylink_device_handle *devh, uint8_t *config)
 Read the raw configuration data of a device. More...
 
JAYLINK_API struct jaylink_devicejaylink_ref_device (struct jaylink_device *dev)
 Increment the reference count of a device. More...
 
JAYLINK_API int jaylink_register (struct jaylink_device_handle *devh, struct jaylink_connection *connection, struct jaylink_connection *connections, size_t *count)
 Register a connection on a device. More...
 
JAYLINK_API void jaylink_unref_device (struct jaylink_device *dev)
 Decrement the reference count of a device. More...
 
JAYLINK_API int jaylink_unregister (struct jaylink_device_handle *devh, const struct jaylink_connection *connection, struct jaylink_connection *connections, size_t *count)
 Unregister a connection from a device. More...
 
JAYLINK_API int jaylink_write_raw_config (struct jaylink_device_handle *devh, const uint8_t *config)
 Write the raw configuration data of a device. More...
 
static void parse_conn_table (struct jaylink_connection *conns, const uint8_t *buffer, uint16_t num, uint16_t entry_size)
 

Detailed Description

Device enumeration and handling.

Definition in file device.c.

Function Documentation

static bool _inet_pton ( const char *  str,
struct in_addr *  in 
)
static

Definition at line 1353 of file device.c.

References length, and NULL.

Referenced by jaylink_register(), and jaylink_unregister().

static struct jaylink_device_handle* allocate_device_handle ( struct jaylink_device dev)
static

Definition at line 512 of file device.c.

References jaylink_device_handle::dev, devh, jaylink_ref_device(), and NULL.

Referenced by jaylink_open().

static struct jaylink_device** allocate_device_list ( size_t  length)
static

Definition at line 100 of file device.c.

References length, and NULL.

Referenced by jaylink_get_devices().

static void free_device_handle ( struct jaylink_device_handle devh)
static

Definition at line 527 of file device.c.

References jaylink_device_handle::dev, and jaylink_unref_device().

Referenced by jaylink_close(), and jaylink_open().

JAYLINK_API int jaylink_close ( struct jaylink_device_handle devh)

Close a device.

Parameters
[in,out]devhDevice instance.
Return values
JAYLINK_OKSuccess.
JAYLINK_ERR_ARGInvalid arguments.
JAYLINK_ERROther error conditions.
Since
0.1.0

Definition at line 588 of file device.c.

References free_device_handle(), JAYLINK_ERR_ARG, and transport_close().

Referenced by jlink_init(), and jlink_quit().

JAYLINK_API int jaylink_device_get_hardware_version ( const struct jaylink_device dev,
struct jaylink_hardware_version version 
)

Get the hardware version of a device.

Note
The hardware type can not be obtained by this function, use jaylink_get_hardware_version() instead.
Parameters
[in]devDevice instance.
[out]versionHardware version of the device on success and undefined on failure.
Return values
JAYLINK_OKSuccess.
JAYLINK_ERR_ARGInvalid arguments.
JAYLINK_ERR_NOT_SUPPORTEDSupported for devices with host interface JAYLINK_HIF_TCP only.
JAYLINK_ERR_NOT_AVAILABLEHardware version is not available.
Since
0.2.0

Definition at line 367 of file device.c.

References jaylink_device::has_hw_version, jaylink_device::hw_version, jaylink_device::iface, JAYLINK_ERR_ARG, JAYLINK_ERR_NOT_AVAILABLE, JAYLINK_ERR_NOT_SUPPORTED, JAYLINK_HIF_TCP, and JAYLINK_OK.

JAYLINK_API int jaylink_device_get_host_interface ( const struct jaylink_device dev,
enum jaylink_host_interface iface 
)

Get the host interface of a device.

Parameters
[in]devDevice instance.
[out]ifaceHost interface of the device on success, and undefined on failure.
Return values
JAYLINK_OKSuccess.
JAYLINK_ERR_ARGInvalid arguments.
Since
0.1.0

Definition at line 208 of file device.c.

References jaylink_device::iface, JAYLINK_ERR_ARG, and JAYLINK_OK.

JAYLINK_API int jaylink_device_get_ipv4_address ( const struct jaylink_device dev,
char *  address 
)

Get the IPv4 address string of a device.

Parameters
[in]devDevice instance.
[out]addressIPv4 address string in quad-dotted decimal format of the device on success and undefined on failure.
Return values
JAYLINK_OKSuccess.
JAYLINK_ERR_ARGInvalid arguments.
JAYLINK_ERR_NOT_SUPPORTEDSupported for devices with host interface JAYLINK_HIF_TCP only.
Since
0.2.0

Definition at line 302 of file device.c.

References jaylink_device::iface, jaylink_device::ipv4_address, JAYLINK_ERR_ARG, JAYLINK_ERR_NOT_SUPPORTED, JAYLINK_HIF_TCP, and JAYLINK_OK.

JAYLINK_API int jaylink_device_get_mac_address ( const struct jaylink_device dev,
uint8_t *  address 
)

Get the MAC address of a device.

Parameters
[in]devDevice instance.
[out]addressMAC address of the device on success and undefined on failure. The length of the MAC address is JAYLINK_MAC_ADDRESS_LENGTH bytes.
Return values
JAYLINK_OKSuccess.
JAYLINK_ERR_ARGInvalid arguments.
JAYLINK_ERR_NOT_SUPPORTEDSupported for devices with host interface JAYLINK_HIF_TCP only.
JAYLINK_ERR_NOT_AVAILABLEMAC address is not available.
Since
0.2.0

Definition at line 332 of file device.c.

References jaylink_device::has_mac_address, jaylink_device::iface, JAYLINK_ERR_ARG, JAYLINK_ERR_NOT_AVAILABLE, JAYLINK_ERR_NOT_SUPPORTED, JAYLINK_HIF_TCP, JAYLINK_OK, and jaylink_device::mac_address.

JAYLINK_API int jaylink_device_get_nickname ( const struct jaylink_device dev,
char *  nickname 
)

Get the nickname of a device.

Parameters
[in]devDevice instance.
[out]nicknameNickname of the device on success and undefined on failure. The maximum length of the nickname is JAYLINK_NICKNAME_MAX_LENGTH bytes.
Return values
JAYLINK_OKSuccess.
JAYLINK_ERR_ARGInvalid arguments.
JAYLINK_ERR_NOT_SUPPORTEDSupported for devices with host interface JAYLINK_HIF_TCP only.
JAYLINK_ERR_NOT_AVAILABLENickname is not available.
Since
0.2.0

Definition at line 434 of file device.c.

References jaylink_device::has_nickname, jaylink_device::iface, JAYLINK_ERR_ARG, JAYLINK_ERR_NOT_AVAILABLE, JAYLINK_ERR_NOT_SUPPORTED, JAYLINK_HIF_TCP, JAYLINK_OK, and jaylink_device::nickname.

JAYLINK_API int jaylink_device_get_product_name ( const struct jaylink_device dev,
char *  name 
)

Get the product name of a device.

Parameters
[in]devDevice instance.
[out]nameProduct name of the device on success and undefined on failure. The maximum length of the product name is JAYLINK_PRODUCT_NAME_MAX_LENGTH bytes.
Return values
JAYLINK_OKSuccess.
JAYLINK_ERR_ARGInvalid arguments.
JAYLINK_ERR_NOT_SUPPORTEDSupported for devices with host interface JAYLINK_HIF_TCP only.
JAYLINK_ERR_NOT_AVAILABLEProduct name is not available.
Since
0.2.0

Definition at line 401 of file device.c.

References jaylink_device::has_product_name, jaylink_device::iface, JAYLINK_ERR_ARG, JAYLINK_ERR_NOT_AVAILABLE, JAYLINK_ERR_NOT_SUPPORTED, JAYLINK_HIF_TCP, JAYLINK_OK, and jaylink_device::product_name.

JAYLINK_API int jaylink_device_get_serial_number ( const struct jaylink_device dev,
uint32_t *  serial_number 
)

Get the serial number of a device.

Note
This serial number is for enumeration purpose only and might differ from the real serial number of the device.
Parameters
[in]devDevice instance.
[out]serial_numberSerial number of the device on success, and undefined on failure.
Return values
JAYLINK_OKSuccess.
JAYLINK_ERR_ARGInvalid arguments.
JAYLINK_ERR_NOT_AVAILABLESerial number is not available.
Since
0.1.0

Definition at line 236 of file device.c.

References JAYLINK_ERR_ARG, JAYLINK_ERR_NOT_AVAILABLE, JAYLINK_OK, jaylink_device::serial_number, and jaylink_device::valid_serial_number.

Referenced by jlink_init().

JAYLINK_API int jaylink_device_get_usb_address ( const struct jaylink_device dev,
enum jaylink_usb_address address 
)

Get the USB address of a device.

Note
Identification of a device with the USB address is deprecated and the serial number should be used instead.
Parameters
[in]devDevice instance.
[out]addressUSB address of the device on success, and undefined on failure.
Return values
JAYLINK_OKSuccess.
JAYLINK_ERR_ARGInvalid arguments.
JAYLINK_ERR_NOT_SUPPORTEDSupported for devices with host interface JAYLINK_HIF_USB only.
See Also
jaylink_device_get_serial_number()
Since
0.1.0

Definition at line 269 of file device.c.

References jaylink_device::iface, JAYLINK_ERR_ARG, JAYLINK_ERR_NOT_SUPPORTED, JAYLINK_HIF_USB, and JAYLINK_OK.

Referenced by jlink_init().

JAYLINK_API void jaylink_free_devices ( struct jaylink_device **  devs,
bool  unref 
)

Free devices.

Parameters
[in,out]devsArray of device instances. Must be NULL-terminated.
[in]unrefDetermines whether the device instances should be unreferenced.
See Also
jaylink_get_devices()
Since
0.1.0

Definition at line 181 of file device.c.

References jaylink_unref_device().

Referenced by jlink_init().

JAYLINK_API int jaylink_get_caps ( struct jaylink_device_handle devh,
uint8_t *  caps 
)

Retrieve the capabilities of a device.

The capabilities are stored in a 32-bit bit array consisting of JAYLINK_DEV_CAPS_SIZE bytes where each individual bit represents a capability. The first bit of this array is the least significant bit of the first byte and the following bits are sequentially numbered in order of increasing bit significance and byte index. A set bit indicates a supported capability. See jaylink_device_capability for a description of the capabilities and their bit positions.

Parameters
[in,out]devhDevice handle.
[out]capsBuffer to store capabilities on success. Its content is undefined on failure. The buffer must be large enough to contain at least JAYLINK_DEV_CAPS_SIZE bytes.
Return values
JAYLINK_OKSuccess.
JAYLINK_ERR_ARGInvalid arguments.
JAYLINK_ERR_TIMEOUTA timeout occurred.
JAYLINK_ERR_IOInput/output error.
JAYLINK_ERROther error conditions.
See Also
jaylink_get_extended_caps()
jaylink_has_cap()
Since
0.1.0

Definition at line 1038 of file device.c.

References jaylink_device::ctx, jaylink_device_handle::dev, JAYLINK_DEV_CAPS_SIZE, JAYLINK_ERR_ARG, JAYLINK_OK, jaylink_strerror(), log_err(), transport_read(), transport_start_write_read(), and transport_write().

Referenced by jlink_init().

JAYLINK_API int jaylink_get_counters ( struct jaylink_device_handle devh,
uint32_t  mask,
uint32_t *  values 
)

Retrieve the counter values of a device.

Note
This function must only be used if the device has the JAYLINK_DEV_CAP_GET_COUNTERS capability.
Parameters
[in,out]devhDevice handle.
[in]maskA bit field where each set bit represents a counter value to request. See jaylink_counter for a description of the counters and their bit positions.
[out]valuesArray to store the counter values on success. Its content is undefined on failure. The array must be large enough to contain at least as many elements as bits set in mask.
Return values
JAYLINK_OKSuccess.
JAYLINK_ERR_ARGInvalid arguments.
JAYLINK_ERR_TIMEOUTA timeout occurred.
JAYLINK_ERR_IOInput/output error.
JAYLINK_ERROther error conditions.
Since
0.2.0

Definition at line 823 of file device.c.

References buffer_get_u32(), buffer_set_u32(), jaylink_device::ctx, jaylink_device_handle::dev, JAYLINK_ERR_ARG, JAYLINK_OK, jaylink_strerror(), length, log_err(), transport_read(), transport_start_write_read(), and transport_write().

JAYLINK_API struct jaylink_device* jaylink_get_device ( struct jaylink_device_handle devh)

Get the device instance from a device handle.

Note
The reference count of the device instance is not increased.
Parameters
[in]devhDevice handle.
Returns
The device instance on success, or NULL on invalid argument.
Since
0.1.0

Definition at line 612 of file device.c.

References jaylink_device_handle::dev, and NULL.

JAYLINK_API int jaylink_get_devices ( struct jaylink_context ctx,
struct jaylink_device ***  devs,
size_t *  count 
)

Get available devices.

Parameters
[in,out]ctxlibjaylink context.
[out]devsNewly allocated array which contains instances of available devices on success, and undefined on failure. The array is NULL-terminated and must be free'd by the caller with jaylink_free_devices().
[out]countNumber of available devices on success, and undefined on failure. Can be NULL.
Return values
JAYLINK_OKSuccess.
JAYLINK_ERR_ARGInvalid arguments.
JAYLINK_ERR_MALLOCMemory allocation error.
JAYLINK_ERROther error conditions.
See Also
jaylink_discovery_scan()
Since
0.1.0

Definition at line 134 of file device.c.

References allocate_device_list(), list::data, jaylink_context::discovered_devs, JAYLINK_ERR_ARG, JAYLINK_ERR_MALLOC, JAYLINK_OK, jaylink_ref_device(), list_length(), log_err(), and list::next.

Referenced by jlink_init().

JAYLINK_API int jaylink_get_extended_caps ( struct jaylink_device_handle devh,
uint8_t *  caps 
)

Retrieve the extended capabilities of a device.

The extended capabilities are stored in a 256-bit bit array consisting of JAYLINK_DEV_EXT_CAPS_SIZE bytes. See jaylink_get_caps() for a further description of how the capabilities are represented in this bit array. For a description of the capabilities and their bit positions, see jaylink_device_capability.

Note
This function must only be used if the device has the JAYLINK_DEV_CAP_GET_EXT_CAPS capability.
Parameters
[in,out]devhDevice handle.
[out]capsBuffer to store capabilities on success. Its content is undefined on failure. The buffer must be large enough to contain at least JAYLINK_DEV_EXT_CAPS_SIZE bytes.
Return values
JAYLINK_OKSuccess.
JAYLINK_ERR_ARGInvalid arguments.
JAYLINK_ERR_TIMEOUTA timeout occurred.
JAYLINK_ERR_IOInput/output error.
JAYLINK_ERROther error conditions.
See Also
jaylink_get_caps()
Since
0.1.0

Definition at line 1105 of file device.c.

References jaylink_device::ctx, jaylink_device_handle::dev, JAYLINK_DEV_EXT_CAPS_SIZE, JAYLINK_ERR_ARG, JAYLINK_OK, jaylink_strerror(), log_err(), transport_read(), transport_start_write_read(), and transport_write().

Referenced by jlink_init().

JAYLINK_API int jaylink_get_firmware_version ( struct jaylink_device_handle devh,
char **  version,
size_t *  length 
)

Retrieve the firmware version of a device.

Parameters
[in,out]devhDevice handle.
[out]versionNewly allocated string which contains the firmware version on success, and undefined if length is zero or on failure. The string is null-terminated and must be free'd by the caller.
[out]lengthLength of the firmware version string including trailing null-terminator on success, and undefined on failure. Zero if no firmware version string is available.
Return values
JAYLINK_OKSuccess.
JAYLINK_ERR_ARGInvalid arguments.
JAYLINK_ERR_TIMEOUTA timeout occurred.
JAYLINK_ERR_MALLOCMemory allocation error.
JAYLINK_ERR_IOInput/output error.
JAYLINK_ERROther error conditions.
Since
0.1.0

Definition at line 642 of file device.c.

References buffer_get_u16(), CMD_GET_VERSION, jaylink_device::ctx, jaylink_device_handle::dev, JAYLINK_ERR_ARG, JAYLINK_ERR_MALLOC, JAYLINK_OK, jaylink_strerror(), log_err(), transport_read(), transport_start_read(), transport_start_write_read(), and transport_write().

Referenced by jlink_init().

JAYLINK_API int jaylink_get_free_memory ( struct jaylink_device_handle devh,
uint32_t *  size 
)

Retrieve the size of free memory of a device.

Note
This function must only be used if the device has the JAYLINK_DEV_CAP_GET_FREE_MEMORY capability.
Parameters
[in,out]devhDevice handle.
[out]sizeSize of free memory in bytes on success, and undefined on failure.
Return values
JAYLINK_OKSuccess.
JAYLINK_ERR_ARGInvalid arguments.
JAYLINK_ERR_TIMEOUTA timeout occurred.
JAYLINK_ERR_IOInput/output error.
JAYLINK_ERROther error conditions.
Since
0.1.0

Definition at line 1164 of file device.c.

References buffer_get_u32(), jaylink_device::ctx, jaylink_device_handle::dev, JAYLINK_ERR_ARG, JAYLINK_OK, jaylink_strerror(), log_err(), transport_read(), transport_start_write_read(), and transport_write().

Referenced by adjust_swd_buffer_size(), calculate_trace_buffer_size(), and COMMAND_HANDLER().

JAYLINK_API int jaylink_get_hardware_info ( struct jaylink_device_handle devh,
uint32_t  mask,
uint32_t *  info 
)

Retrieve the hardware information of a device.

Note
This function must only be used if the device has the JAYLINK_DEV_CAP_GET_HW_INFO capability.
Parameters
[in,out]devhDevice handle.
[in]maskA bit field where each set bit represents hardware information to request. See jaylink_hardware_info for a description of the hardware information and their bit positions.
[out]infoArray to store the hardware information on success. Its content is undefined on failure. The array must be large enough to contain at least as many elements as bits set in mask.
Return values
JAYLINK_OKSuccess.
JAYLINK_ERR_ARGInvalid arguments.
JAYLINK_ERR_TIMEOUTA timeout occurred.
JAYLINK_ERR_IOInput/output error.
JAYLINK_ERROther error conditions.
Since
0.1.0

Definition at line 743 of file device.c.

References buffer_get_u32(), buffer_set_u32(), jaylink_device::ctx, jaylink_device_handle::dev, JAYLINK_ERR_ARG, JAYLINK_OK, jaylink_strerror(), length, log_err(), transport_read(), transport_start_write_read(), and transport_write().

JAYLINK_API int jaylink_get_hardware_status ( struct jaylink_device_handle devh,
struct jaylink_hardware_status status 
)

Retrieve the hardware status of a device.

Parameters
[in,out]devhDevice handle.
[out]statusHardware status on success, and undefined on failure.
Return values
JAYLINK_OKSuccess.
JAYLINK_ERR_ARGInvalid arguments.
JAYLINK_ERR_TIMEOUTA timeout occurred.
JAYLINK_ERR_IOInput/output error.
JAYLINK_ERROther error conditions.
Since
0.1.0

Definition at line 963 of file device.c.

References buffer_get_u16(), jaylink_device::ctx, jaylink_device_handle::dev, JAYLINK_ERR_ARG, JAYLINK_OK, jaylink_strerror(), log_err(), jaylink_hardware_status::target_voltage, jaylink_hardware_status::tck, jaylink_hardware_status::tdi, jaylink_hardware_status::tdo, jaylink_hardware_status::tms, transport_read(), transport_start_write_read(), transport_write(), jaylink_hardware_status::tres, and jaylink_hardware_status::trst.

Referenced by COMMAND_HANDLER(), and jlink_init().

JAYLINK_API int jaylink_get_hardware_version ( struct jaylink_device_handle devh,
struct jaylink_hardware_version version 
)

Retrieve the hardware version of a device.

Note
This function must only be used if the device has the JAYLINK_DEV_CAP_GET_HW_VERSION capability.
Warning
This function may return a value for version where jaylink_hardware_version::type is not covered by jaylink_hardware_type.
Parameters
[in,out]devhDevice handle.
[out]versionHardware version on success, and undefined on failure.
Return values
JAYLINK_OKSuccess.
JAYLINK_ERR_ARGInvalid arguments.
JAYLINK_ERR_TIMEOUTA timeout occurred.
JAYLINK_ERR_IOInput/output error.
JAYLINK_ERROther error conditions.
Since
0.1.0

Definition at line 900 of file device.c.

References buffer_get_u32(), jaylink_device::ctx, jaylink_device_handle::dev, JAYLINK_ERR_ARG, JAYLINK_OK, jaylink_strerror(), log_err(), jaylink_hardware_version::major, jaylink_hardware_version::minor, jaylink_hardware_version::revision, transport_read(), transport_start_write_read(), transport_write(), and jaylink_hardware_version::type.

Referenced by jlink_init().

JAYLINK_API int jaylink_open ( struct jaylink_device dev,
struct jaylink_device_handle **  devh 
)

Open a device.

Parameters
[in,out]devDevice instance.
[out]devhNewly allocated handle for the opened device on success, and undefined on failure.
Return values
JAYLINK_OKSuccess.
JAYLINK_ERR_ARGInvalid arguments.
JAYLINK_ERR_TIMEOUTA timeout occurred.
JAYLINK_ERR_MALLOCMemory allocation error.
JAYLINK_ERR_IOInput/output error.
JAYLINK_ERROther error conditions.
Since
0.1.0

Definition at line 549 of file device.c.

References allocate_device_handle(), jaylink_device::ctx, free_device_handle(), JAYLINK_ERR_ARG, JAYLINK_ERR_MALLOC, JAYLINK_OK, log_err(), and transport_open().

Referenced by jlink_init().

JAYLINK_API int jaylink_read_raw_config ( struct jaylink_device_handle devh,
uint8_t *  config 
)

Read the raw configuration data of a device.

Note
This function must only be used if the device has the JAYLINK_DEV_CAP_READ_CONFIG capability.
Parameters
[in,out]devhDevice handle.
[out]configBuffer to store configuration data on success. Its content is undefined on failure. The buffer must be large enough to contain at least JAYLINK_DEV_CONFIG_SIZE bytes.
Return values
JAYLINK_OKSuccess.
JAYLINK_ERR_ARGInvalid arguments.
JAYLINK_ERR_TIMEOUTA timeout occurred.
JAYLINK_ERR_IOInput/output error.
JAYLINK_ERROther error conditions.
Since
0.1.0

Definition at line 1226 of file device.c.

References jaylink_device::ctx, jaylink_device_handle::dev, JAYLINK_DEV_CONFIG_SIZE, JAYLINK_ERR_ARG, JAYLINK_OK, jaylink_strerror(), log_err(), transport_read(), transport_start_write_read(), and transport_write().

Referenced by read_device_config().

JAYLINK_API struct jaylink_device* jaylink_ref_device ( struct jaylink_device dev)

Increment the reference count of a device.

Parameters
[in,out]devDevice instance.
Returns
The given device instance on success, or NULL on invalid argument.
Since
0.1.0

Definition at line 460 of file device.c.

References NULL, and jaylink_device::ref_count.

Referenced by allocate_device_handle(), jaylink_get_devices(), and probe_device().

JAYLINK_API int jaylink_register ( struct jaylink_device_handle devh,
struct jaylink_connection connection,
struct jaylink_connection connections,
size_t *  count 
)

Register a connection on a device.

A connection can be registered by using 0 as handle. Additional information about the connection can be attached whereby the timestamp is a read-only value and therefore ignored for registration. On success, a new handle greater than 0 is obtained from the device.

However, if an obtained handle does not appear in the list of device connections, the connection was not registered because the maximum number of connections on the device is reached.

Note
This function must only be used if the device has the JAYLINK_DEV_CAP_REGISTER capability.

Example code:

static bool register_connection(struct jaylink_device_handle *devh,
{
int ret;
bool found_handle;
size_t count;
size_t i;
conn->handle = 0;
conn->pid = 0;
strcpy(conn->hid, "0.0.0.0");
conn->iid = 0;
conn->cid = 0;
ret = jaylink_register(devh, conn, conns, &count);
if (ret != JAYLINK_OK) {
printf("jaylink_register() failed: %s.\n",
return false;
}
found_handle = false;
for (i = 0; i < count; i++) {
if (conns[i].handle == conn->handle) {
found_handle = true;
break;
}
}
if (!found_handle) {
printf("Maximum number of connections reached.\n");
return false;
}
printf("Connection successfully registered.\n");
return true;
}
Parameters
[in,out]devhDevice handle.
[in,out]connectionConnection to register on the device.
[out]connectionsArray to store device connections on success. Its content is undefined on failure. The array must be large enough to contain at least JAYLINK_MAX_CONNECTIONS elements.
[out]countNumber of device connections on success, and undefined on failure.
Return values
JAYLINK_OKSuccess.
JAYLINK_ERR_ARGInvalid arguments.
JAYLINK_ERR_TIMEOUTA timeout occurred.
JAYLINK_ERR_PROTOProtocol violation.
JAYLINK_ERR_IOInput/output error.
JAYLINK_ERROther error conditions.
See Also
jaylink_unregister()
Since
0.1.0

Definition at line 1461 of file device.c.

References _inet_pton(), buffer_get_u16(), buffer_set_u16(), buffer_set_u32(), jaylink_connection::cid, jaylink_device::ctx, jaylink_device_handle::dev, jaylink_connection::handle, jaylink_connection::hid, jaylink_connection::iid, JAYLINK_ERR, JAYLINK_ERR_ARG, JAYLINK_ERR_PROTO, JAYLINK_MAX_CONNECTIONS, JAYLINK_OK, jaylink_strerror(), log_err(), parse_conn_table(), jaylink_connection::pid, transport_read(), transport_start_read(), transport_start_write_read(), and transport_write().

Referenced by jlink_register().

JAYLINK_API void jaylink_unref_device ( struct jaylink_device dev)

Decrement the reference count of a device.

Parameters
[in,out]devDevice instance.
Since
0.1.0

Definition at line 478 of file device.c.

References jaylink_device::ctx, jaylink_context::devs, jaylink_device::iface, jaylink_device::ipv4_address, JAYLINK_HIF_TCP, JAYLINK_HIF_USB, list_remove(), log_dbg(), log_err(), and jaylink_device::ref_count.

Referenced by clear_discovery_list(), free_device_handle(), jaylink_exit(), and jaylink_free_devices().

JAYLINK_API int jaylink_unregister ( struct jaylink_device_handle devh,
const struct jaylink_connection connection,
struct jaylink_connection connections,
size_t *  count 
)

Unregister a connection from a device.

Note
This function must only be used if the device has the JAYLINK_DEV_CAP_REGISTER capability.
Parameters
[in,out]devhDevice handle.
[in,out]connectionConnection to unregister from the device.
[out]connectionsArray to store device connections on success. Its content is undefined on failure. The array must be large enough to contain at least JAYLINK_MAX_CONNECTIONS elements.
[out]countNumber of device connections on success, and undefined on failure.
Return values
JAYLINK_OKSuccess.
JAYLINK_ERR_ARGInvalid arguments.
JAYLINK_ERR_TIMEOUTA timeout occurred.
JAYLINK_ERR_PROTOProtocol violation.
JAYLINK_ERR_IOInput/output error.
JAYLINK_ERROther error conditions.
See Also
jaylink_register()
Since
0.1.0

Definition at line 1602 of file device.c.

References _inet_pton(), buffer_get_u16(), buffer_set_u16(), buffer_set_u32(), jaylink_connection::cid, jaylink_device::ctx, jaylink_device_handle::dev, jaylink_connection::handle, jaylink_connection::hid, jaylink_connection::iid, JAYLINK_ERR, JAYLINK_ERR_ARG, JAYLINK_ERR_PROTO, JAYLINK_MAX_CONNECTIONS, JAYLINK_OK, jaylink_strerror(), log_err(), parse_conn_table(), jaylink_connection::pid, transport_read(), transport_start_read(), transport_start_write_read(), and transport_write().

Referenced by jlink_quit().

JAYLINK_API int jaylink_write_raw_config ( struct jaylink_device_handle devh,
const uint8_t *  config 
)

Write the raw configuration data of a device.

Note
This function must only be used if the device has the JAYLINK_DEV_CAP_WRITE_CONFIG capability.
Parameters
[in,out]devhDevice handle.
[in]configBuffer to write configuration data from. The size of the configuration data is expected to be JAYLINK_DEV_CONFIG_SIZE bytes.
Return values
JAYLINK_OKSuccess.
JAYLINK_ERR_ARGInvalid arguments.
JAYLINK_ERR_TIMEOUTA timeout occurred.
JAYLINK_ERR_IOInput/output error.
JAYLINK_ERROther error conditions.
Since
0.1.0

Definition at line 1286 of file device.c.

References jaylink_device::ctx, jaylink_device_handle::dev, JAYLINK_DEV_CONFIG_SIZE, JAYLINK_ERR_ARG, JAYLINK_OK, jaylink_strerror(), log_err(), transport_start_write(), and transport_write().

Referenced by COMMAND_HANDLER().

static void parse_conn_table ( struct jaylink_connection conns,
const uint8_t *  buffer,
uint16_t  num,
uint16_t  entry_size 
)
static