Illustrated C/C++ source sheets, symbol index, API relationship graph, compiler console and debug trace

LIVE AI / FLEXIBLE SENSING / FLIGHT CONTEXT

Sensoraia API

Live AI and sensing, connected to the flight.
See, listen, inspect and return supported results while airborne.

Loading...
Searching...
No Matches
chdkbridge.c File Reference

Standalone USB PTP client for CHDK JPEG capture and normalized zoom. More...

#include <dlfcn.h>
#include <errno.h>
#include <math.h>
#include <fcntl.h>
#include <limits.h>
#include <poll.h>
#include <signal.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
#include "usbfs.h"
#include "version.h"
Include dependency graph for chdkbridge.c:

Go to the source code of this file.

Data Structures

struct  transport
 Single-session USB transport with bounded input staging. More...
struct  response
 Validated successful PTP response and optional data-phase length. More...
struct  direct_download
struct  camera_setting
 Shoot to the camera SD card and stream the resulting JPEG to a local file. More...
struct  focus_policy
struct  exposure_policy
struct  capture_settings
struct  usb_port_selection
struct  desktop_api

Macros

#define _POSIX_C_SOURCE   200809L
#define _DEFAULT_SOURCE
#define SCRIPT_BODY_CAPACITY   (SCRIPT_CAPACITY - sizeof(record_mode_script))
#define CAMERA_SETTING_COUNT   (sizeof(camera_settings) / sizeof(camera_settings[0]))
#define DESKTOP_SYMBOL(FIELD, NAME)

Enumerations

enum  {
  PTP_COMMAND = 1 , PTP_DATA = 2 , PTP_RESPONSE = 3 , PTP_OPEN_SESSION = 0x1002 ,
  PTP_CLOSE_SESSION = 0x1003 , PTP_OK = 0x2001 , PTP_CHDK = 0x9999 , CHDK_VERSION = 0 ,
  CHDK_TEMP_DATA = 4 , CHDK_DOWNLOAD = 6 , CHDK_EXECUTE = 7 , CHDK_STATUS = 8 ,
  CHDK_SUPPORT = 9 , CHDK_MESSAGE = 10 , CHDK_WRITE_MESSAGE = 11 , CHDK_CAPTURE_READY = 13 ,
  CHDK_CAPTURE_DATA = 14 , CHDK_CAPTURE_JPEG = 1 , CHDK_CAPTURE_NOTSET = 0x10000000 , CHDK_MESSAGE_NONE = 0 ,
  CHDK_MESSAGE_ERROR = 1 , CHDK_MESSAGE_RETURN = 2 , CHDK_MESSAGE_USER = 3 , CHDK_UNSUPPORTED = 0 ,
  CHDK_NIL = 1 , CHDK_BOOLEAN = 2 , CHDK_INTEGER = 3 , CHDK_STRING = 4 ,
  CHDK_TABLE = 5 , CHDK_ERROR_NONE = 0 , CHDK_ERROR_COMPILE = 1 , CHDK_ERROR_RUNTIME = 2 ,
  CHDK_ERROR_RUNNING = 0x1000 , CHDK_SCRIPT_FLAGS = 0x700 , TRANSFER_SIZE = 65536 , SCRIPT_CAPACITY = 12288 ,
  SCRIPT_POLL_MIN_MS = 10 , SCRIPT_POLL_MAX_MS = 50 , DESKTOP_VOLUME_LIMIT = 128 , DESKTOP_RELEASE_MS = 5000 ,
  DESKTOP_DISCOVERY_POLLS = 50 , DESKTOP_DISCOVERY_POLL_MS = 10 , DESKTOP_RECLAIM_MS = 2000 , DESKTOP_RECLAIM_POLL_MS = 20 ,
  MAX_DOWNLOAD = 256 * 1024 * 1024
}
 Wire constants and resource limits, not an exhaustive PTP API. More...
enum  {
  PTP_CLASS_OUT = 0x21 , PTP_CLASS_IN = 0xa1 , PTP_REQUEST_DEVICE_RESET = 0x66 , PTP_REQUEST_DEVICE_STATUS = 0x67 ,
  RECOVERY_CONTROL_MS = 3000 , RECOVERY_DRAIN_MS = 100 , RECOVERY_DRAIN_READS = 64
}
enum  focus_mode {
  FOCUS_UNCHANGED , FOCUS_AF , FOCUS_AFLOCK , FOCUS_MANUAL ,
  FOCUS_AUTO
}
enum  exposure_parameter {
  EXPOSURE_TV , EXPOSURE_SV , EXPOSURE_AV , EXPOSURE_ND ,
  EXPOSURE_COUNT
}
enum  exposure_iso_kind { EXPOSURE_ISO_SV96 , EXPOSURE_ISO_REAL , EXPOSURE_ISO_MARKET }

Functions

static bool download_direct_chunk (struct transport *transport, FILE *file, struct direct_download *download)
 Receive one direct JPEG chunk into the private output stream.
static void interrupt_handler (int signal_number)
 Request cancellation without allocation, I/O, or USB calls in a signal handler.
static uint64_t monotonic_ms (void)
 Read a wall-clock-independent time base; return zero if the clock fails.
static unsigned remaining_ms (const struct transport *transport)
 Compute the next USB call's timeout within the operation deadline.
static const char * usb_failure_hint (int error)
 Select a recovery hint for a USB transport failure.
static uint16_t decode16 (const uint8_t *bytes)
 Decode a 16-bit little-endian value without alignment assumptions.
static uint32_t decode32 (const uint8_t *bytes)
 Decode a 32-bit little-endian value without native-endian casts.
static void encode16 (uint8_t *bytes, uint16_t value)
 Encode a wire value into two writable bytes.
static void encode32 (uint8_t *bytes, uint32_t value)
 Encode a wire value into four writable bytes.
static bool send_packet (struct transport *transport, uint8_t *bytes, size_t length)
 Submit one complete, small outbound PTP container.
static bool refill_buffer (struct transport *transport)
 Refill empty bounded USB storage without replaying a command.
static bool receive_bytes (struct transport *transport, uint8_t *destination, size_t length)
 Read an exact bounded payload across arbitrary USB transfer splits.
static const char * ptp_response_name (uint16_t code)
 Describe standard PTP response failures without triggering recovery actions.
static bool transaction (struct transport *transport, uint16_t operation, const uint32_t *parameters, size_t parameter_count, const uint8_t *outgoing, size_t outgoing_size, uint8_t *incoming, size_t capacity, FILE *file, struct response *response)
 Perform command, optional data, and response phases for one PTP operation.
static bool chdk_call (struct transport *transport, uint32_t command, uint32_t argument, const uint8_t *outgoing, size_t size, uint8_t *incoming, size_t capacity, FILE *file, struct response *response)
 Place a CHDK subcommand and argument in vendor operation 0x9999.
static void close_session (struct transport *transport)
 Best-effort close of an owned session, even after cancellation, within one second.
static bool recover_ptp (struct transport *transport, int interface_number)
 Clear a session or stale data left by an interrupted earlier run.
static bool camera_info (struct transport *transport)
 Report CHDK protocol and script capabilities without executing a script.
static const char * script_error_name (uint32_t error)
 Translate a CHDK script status for diagnostics.
static bool valid_script_message (const struct response *response, const uint8_t *message)
 Validate known message types and payload lengths, including empty-message zero padding.
static bool wait_script_poll (const struct transport *transport, unsigned interval_ms)
 Sleep to a monotonic poll target without extending it on EINTR or exceeding the deadline.
static bool wait_script_idle (struct transport *transport)
 Wait within the deadline until no camera script is running; never interrupts one.
static bool run_script_operation (struct transport *transport, const char *body, char *result, size_t result_capacity, FILE *direct_file, bool enter_record)
 Run camera-side Lua and wait for its correlated string return value.
static bool run_script (struct transport *transport, const char *body, char *result, size_t result_capacity)
 Execute a capture-path script without direct-download output.
static bool retract_lens (struct transport *transport)
 Ask the camera to enter playback and confirm the resulting mode.
static bool power_status (struct transport *transport)
 Print the camera's idle power-off policy and available telemetry.
static bool valid_camera_path (const char *path)
 Validate a bounded printable camera pathname with no traversal components.
static bool download_file (struct transport *transport, const char *remote_path, FILE *file)
 Stream an existing SD-card file without executing a camera script.
static bool download_romlog (struct transport *transport, FILE *file)
 Export and download the camera's bounded ROM crash log.
static bool exposure_requested (const struct exposure_policy *exposure)
 Check whether an explicit exposure override is present.
static bool settings_requested (const struct capture_settings *settings)
 Check whether a capture needs camera configuration before shooting.
static bool focus_script (const struct focus_policy *focus, char *body, size_t capacity, bool exposure_cleanup)
 Build the focus setup and readback portion of a CHDK script.
static bool settings_script (const struct capture_settings *settings, char *body, size_t capacity)
 Assemble bounded Lua for applying the requested camera settings.
static bool configure_script (const struct capture_settings *settings, char *body, size_t capacity)
 Build a configuration-only script with an observed-state report.
static bool configure_camera (struct transport *transport, const struct capture_settings *settings)
 Apply settings without capturing a picture.
static bool capture_script (const struct capture_settings *settings, char *body, size_t capacity)
 Build the ordinary SD-backed still-capture script.
static bool capture (struct transport *transport, FILE *file, const struct capture_settings *settings)
 Capture to the camera's SD card and download the resulting JPEG.
static bool direct_capture_script (const struct capture_settings *settings, unsigned timeout_ms, char *body, size_t capacity)
 Build the direct JPEG handshake and its camera-side cleanup.
static bool capture_direct (struct transport *transport, FILE *file, const struct capture_settings *settings)
 Capture and stream a JPEG via CHDK's direct-download protocol.
static bool parse_range (const char *text, unsigned minimum, unsigned maximum, unsigned *value)
 Parse unsigned decimal CLI input with inclusive bounds.
static bool set_zoom (struct transport *transport, unsigned level, uint8_t *observed)
 Set normalized optical zoom without taking or downloading a photo.
static bool valid_ptp_interface (const struct usbfs_interface *descriptor, uint8_t *input, uint8_t *output)
 Validate one USB still-image interface without opening the device.
static bool find_interface (const struct usbfs_device *device, int *interface_number, int *alternate, uint8_t *input, uint8_t *output, unsigned *output_packet_size)
 Find a still-image PTP interface and its bulk endpoints.
static bool parse_number (const char *text, unsigned maximum, unsigned *value)
 Parse a positive CLI number; zero is reserved for unspecified selection.
static bool parse_signed (const char *text, int minimum, int maximum, int *value)
 Parse a bounded signed decimal command-line value.
static bool parse_scaled (const char *text, unsigned scale, unsigned minimum, unsigned maximum, unsigned *value)
 Parse a decimal setting and convert it to rounded integer units.
static bool parse_shutter (const char *text, struct exposure_policy *exposure)
 Convert a decimal or rational shutter time to an exposure ratio.
static bool parse_usb_port (const char *text, struct usb_port_selection *selection)
 Parse a stable USB bus and port-chain selector.
static bool usb_port_matches (const struct usb_port_selection *selection, unsigned bus, const uint8_t *ports, int depth)
 Compare a discovered device with the optional port selector.
static bool desktop_camera_uri (const struct desktop_api *api, const char *device, char *uri, size_t capacity)
 Find the unique desktop mount attached to the selected USB node.
static int unmount_desktop_camera (unsigned bus, unsigned address)
 Resolve one optional desktop camera mount and invoke its unmount.
static bool release_desktop_camera (struct transport *transport, unsigned bus, unsigned address)
 Supervise a targeted desktop unmount helper.
static int claim_camera_interface (struct transport *transport, int interface_number, unsigned bus, unsigned address, bool(*release_mount)(struct transport *, unsigned, unsigned))
 Claim an interface, optionally releasing its selected desktop mount.
static void print_help (const char *program)
 Print build identity and CLI usage without initializing USB.
static bool publish_control_reply (unsigned descriptor, uint8_t command, uint8_t observed, uint8_t evidence)
 Emit the control operation's fixed-size binary receipt.
int main (int argc, char **argv)
 Select one camera, execute one operation, and release owned resources.

Variables

struct { 
   int(*   devices_open )(struct usbfs_devices *) 
   int(*   devices_next )(struct usbfs_devices *,
       struct usbfs_device *) 
   void(*   devices_close )(struct usbfs_devices *) 
   int(*   active_config )(const struct usbfs_device *,
       uint8_t *, size_t, const
      uint8_t **, size_t *) 
   int(*   open )(const struct usbfs_device *,
       struct usbfs_handle *) 
   void(*   close )(struct usbfs_handle *) 
   int(*   claim_interface )(struct usbfs_handle *, int) 
   int(*   release_interface )(struct usbfs_handle *, int) 
   int(*   set_alternate )(struct usbfs_handle *, int, int) 
   int(*   bulk_transfer )(struct usbfs_handle *,
       unsigned char, unsigned char *,
       int, int *, unsigned) 
   int(*   control_transfer )(struct usbfs_handle *,
       uint8_t, uint8_t, uint16_t,
       uint16_t, unsigned char *,
       uint16_t, unsigned) 
   int(*   clear_halt )(struct usbfs_handle *,
       unsigned char) 
} usb
 USB operations used by the application; tests substitute fakes.
static volatile sig_atomic_t interrupted
 Signal-safe cancellation flag checked before blocking USB calls.
static const char record_mode_script []
static const char retract_lens_script []
static const char power_status_script []
static const char romlog_script []
static const struct camera_setting camera_settings []

Detailed Description

Standalone USB PTP client for CHDK JPEG capture and normalized zoom.

One invocation owns one USB interface and PTP session. Standard PTP framing carries CHDK vendor commands; small Lua scripts execute on the camera, not on the host. USB access uses Linux usbfs directly (usbfs.h); no USB library is loaded. This standalone C client implements camera control directly over USB PTP.

Warning
A failed transaction is not retried: capture or lens movement may already have occurred. Fake-USB tests are not physical-camera validation.

Definition in file chdkbridge.c.

Macro Definition Documentation

◆ _DEFAULT_SOURCE

#define _DEFAULT_SOURCE

Definition at line 30 of file chdkbridge.c.

◆ _POSIX_C_SOURCE

#define _POSIX_C_SOURCE   200809L

Definition at line 29 of file chdkbridge.c.

◆ CAMERA_SETTING_COUNT

#define CAMERA_SETTING_COUNT   (sizeof(camera_settings) / sizeof(camera_settings[0]))

Definition at line 1033 of file chdkbridge.c.

◆ DESKTOP_SYMBOL

#define DESKTOP_SYMBOL ( FIELD,
NAME )
Value:
api.FIELD = (__typeof__(api.FIELD))dlsym(library, NAME); \
if (!api.FIELD) { fprintf(stderr, "chdkbridge: missing desktop API %s\n", NAME); return 1; }

◆ SCRIPT_BODY_CAPACITY

#define SCRIPT_BODY_CAPACITY   (SCRIPT_CAPACITY - sizeof(record_mode_script))

Definition at line 605 of file chdkbridge.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Wire constants and resource limits, not an exhaustive PTP API.

Enumerator
PTP_COMMAND 
PTP_DATA 
PTP_RESPONSE 
PTP_OPEN_SESSION 
PTP_CLOSE_SESSION 
PTP_OK 
PTP_CHDK 
CHDK_VERSION 
CHDK_TEMP_DATA 
CHDK_DOWNLOAD 
CHDK_EXECUTE 
CHDK_STATUS 
CHDK_SUPPORT 
CHDK_MESSAGE 
CHDK_WRITE_MESSAGE 
CHDK_CAPTURE_READY 
CHDK_CAPTURE_DATA 
CHDK_CAPTURE_JPEG 
CHDK_CAPTURE_NOTSET 
CHDK_MESSAGE_NONE 
CHDK_MESSAGE_ERROR 
CHDK_MESSAGE_RETURN 
CHDK_MESSAGE_USER 
CHDK_UNSUPPORTED 
CHDK_NIL 
CHDK_BOOLEAN 
CHDK_INTEGER 
CHDK_STRING 
CHDK_TABLE 
CHDK_ERROR_NONE 
CHDK_ERROR_COMPILE 
CHDK_ERROR_RUNTIME 
CHDK_ERROR_RUNNING 
CHDK_SCRIPT_FLAGS 
TRANSFER_SIZE 
SCRIPT_CAPACITY 
SCRIPT_POLL_MIN_MS 
SCRIPT_POLL_MAX_MS 
DESKTOP_VOLUME_LIMIT 
DESKTOP_RELEASE_MS 
DESKTOP_DISCOVERY_POLLS 
DESKTOP_DISCOVERY_POLL_MS 
DESKTOP_RECLAIM_MS 
DESKTOP_RECLAIM_POLL_MS 
MAX_DOWNLOAD 

Definition at line 72 of file chdkbridge.c.

◆ anonymous enum

anonymous enum
Enumerator
PTP_CLASS_OUT 
PTP_CLASS_IN 
PTP_REQUEST_DEVICE_RESET 
PTP_REQUEST_DEVICE_STATUS 
RECOVERY_CONTROL_MS 
RECOVERY_DRAIN_MS 
RECOVERY_DRAIN_READS 

Definition at line 440 of file chdkbridge.c.

◆ exposure_iso_kind

Enumerator
EXPOSURE_ISO_SV96 
EXPOSURE_ISO_REAL 
EXPOSURE_ISO_MARKET 

Definition at line 1045 of file chdkbridge.c.

◆ exposure_parameter

Enumerator
EXPOSURE_TV 
EXPOSURE_SV 
EXPOSURE_AV 
EXPOSURE_ND 
EXPOSURE_COUNT 

Definition at line 1044 of file chdkbridge.c.

◆ focus_mode

enum focus_mode
Enumerator
FOCUS_UNCHANGED 
FOCUS_AF 
FOCUS_AFLOCK 
FOCUS_MANUAL 
FOCUS_AUTO 

Definition at line 1035 of file chdkbridge.c.

Function Documentation

◆ camera_info()

bool camera_info ( struct transport * transport)
static

Report CHDK protocol and script capabilities without executing a script.

Parameters
transportOpen session on one selected camera.
Returns
True when version, scripting support, and status queries succeed.
Note
Does not enter record mode, drain messages, move the lens, or touch files.

Definition at line 502 of file chdkbridge.c.

◆ capture()

bool capture ( struct transport * transport,
FILE * file,
const struct capture_settings * settings )
static

Capture to the camera's SD card and download the resulting JPEG.

Parameters
transportActive PTP session and deadline.
fileCaller-owned temporary destination stream.
settingsOptional settings for this shot.
Returns
True if the script and file download succeeded.
Warning
A failed download does not imply the exposure failed.

Definition at line 1463 of file chdkbridge.c.

◆ capture_direct()

bool capture_direct ( struct transport * transport,
FILE * file,
const struct capture_settings * settings )
static

Capture and stream a JPEG via CHDK's direct-download protocol.

Parameters
transportActive session with an absolute operation deadline.
fileSeekable temporary stream for JPEG chunks.
settingsOptional capture settings.
Returns
True when script completion and transfer agree on the image.

Pass the remaining budget to the camera rather than extending the original host deadline with a new per-shot timeout.

Definition at line 1525 of file chdkbridge.c.

◆ capture_script()

bool capture_script ( const struct capture_settings * settings,
char * body,
size_t capacity )
static

Build the ordinary SD-backed still-capture script.

Parameters
settingsOptional settings to apply before exposing.
[out]bodyScript buffer.
capacityAvailable bytes including the terminator.
Returns
True when the capture program fits.

Require the exposure counter to advance, then allow the new JPEG to settle before the host attempts to download its path.

Definition at line 1431 of file chdkbridge.c.

◆ chdk_call()

bool chdk_call ( struct transport * transport,
uint32_t command,
uint32_t argument,
const uint8_t * outgoing,
size_t size,
uint8_t * incoming,
size_t capacity,
FILE * file,
struct response * response )
static

Place a CHDK subcommand and argument in vendor operation 0x9999.

Payloads and response validation are delegated to transaction().

Definition at line 419 of file chdkbridge.c.

◆ claim_camera_interface()

int claim_camera_interface ( struct transport * transport,
int interface_number,
unsigned bus,
unsigned address,
bool(* release_mount )(struct transport *, unsigned, unsigned) )
static

Claim an interface, optionally releasing its selected desktop mount.

Parameters
transportActive device transport and deadline.
interface_numberUSB interface number to claim.
busSelected USB bus.
addressSelected device address.
release_mountTargeted desktop release callback.
Returns
USBFS_SUCCESS or a negative USBFS status.

Only a busy claim triggers desktop release. Use bounded polling to allow that owner to close the descriptor; do not reset the USB device.

Definition at line 1968 of file chdkbridge.c.

◆ close_session()

void close_session ( struct transport * transport)
static

Best-effort close of an owned session, even after cancellation, within one second.

Definition at line 429 of file chdkbridge.c.

◆ configure_camera()

bool configure_camera ( struct transport * transport,
const struct capture_settings * settings )
static

Apply settings without capturing a picture.

Parameters
transportActive PTP session.
settingsRequested settings and optional readback checks.
Returns
True when a configuration report was accepted.

Require the expected report shape before displaying an apparent success.

Definition at line 1413 of file chdkbridge.c.

◆ configure_script()

bool configure_script ( const struct capture_settings * settings,
char * body,
size_t capacity )
static

Build a configuration-only script with an observed-state report.

Parameters
settingsRequested settings.
[out]bodyDestination script buffer.
capacityAvailable bytes including the terminator.
Returns
True if setup and the report fit.

Append readback and release temporary focus/exposure state without taking a picture.

Definition at line 1394 of file chdkbridge.c.

◆ decode16()

uint16_t decode16 ( const uint8_t * bytes)
static

Decode a 16-bit little-endian value without alignment assumptions.

Parameters
bytesAt least two readable bytes.

Definition at line 184 of file chdkbridge.c.

◆ decode32()

uint32_t decode32 ( const uint8_t * bytes)
static

Decode a 32-bit little-endian value without native-endian casts.

Parameters
bytesAt least four readable bytes.

Definition at line 191 of file chdkbridge.c.

◆ desktop_camera_uri()

bool desktop_camera_uri ( const struct desktop_api * api,
const char * device,
char * uri,
size_t capacity )
static

Find the unique desktop mount attached to the selected USB node.

Parameters
apiLoaded desktop volume-monitor functions.
deviceExact USB device path to match.
[out]uriBuffer for a matching gphoto2 URI.
capacityAvailable bytes including the terminator.
Returns
True only for a unique matching mount within the scan bound.

Match the desktop volume by device identity before considering its URI; never choose an unrelated camera by mount order.

Definition at line 1821 of file chdkbridge.c.

◆ direct_capture_script()

bool direct_capture_script ( const struct capture_settings * settings,
unsigned timeout_ms,
char * body,
size_t capacity )
static

Build the direct JPEG handshake and its camera-side cleanup.

Parameters
settingsOptional settings for this shot.
timeout_msRemaining operation budget supplied to the camera.
[out]bodyScript buffer.
capacityAvailable bytes including the terminator.
Returns
True when the complete script fits.

Require single-still support and an unused direct-capture slot. Own cleanup only after enabling the slot; require the host's completion reply before reporting the final image identity.

Definition at line 1481 of file chdkbridge.c.

◆ download_direct_chunk()

bool download_direct_chunk ( struct transport * transport,
FILE * file,
struct direct_download * download )
static

Receive one direct JPEG chunk into the private output stream.

Parameters
transportActive PTP session with the global download limit.
[in,out]fileSeekable temporary stream open for reading and writing.
[in,out]downloadTransfer cursor, file extent and completion state.
Returns
True for an accepted chunk; discard the temporary image after failure.

Stage at the end until the reply supplies the actual offset. Permit backpatching existing bytes but reject gaps, and bound total transferred bytes separately from the resulting extent.

Definition at line 961 of file chdkbridge.c.

◆ download_file()

bool download_file ( struct transport * transport,
const char * remote_path,
FILE * file )
static

Stream an existing SD-card file without executing a camera script.

Parameters
transportOpen session on a selected camera.
remote_pathValid A/ pathname; original is never deleted.
fileWritable caller-owned temporary file.
Returns
True after bounded file transfer and a successful PTP response.
Note
main() still requires JPEG markers before publishing a download.

Definition at line 913 of file chdkbridge.c.

◆ download_romlog()

bool download_romlog ( struct transport * transport,
FILE * file )
static

Export and download the camera's bounded ROM crash log.

Parameters
transportActive PTP session.
fileCaller-owned writable output stream.
Returns
True after a successful export and download.

Require the expected fixed camera pathname before reading it instead of treating arbitrary script output as a destination selector.

Definition at line 946 of file chdkbridge.c.

◆ encode16()

void encode16 ( uint8_t * bytes,
uint16_t value )
static

Encode a wire value into two writable bytes.

Parameters
bytesDestination of at least two bytes.
valueHost-order value to encode little-endian.

Definition at line 200 of file chdkbridge.c.

◆ encode32()

void encode32 ( uint8_t * bytes,
uint32_t value )
static

Encode a wire value into four writable bytes.

Parameters
bytesDestination of at least four bytes.
valueHost-order value to encode little-endian.

Definition at line 209 of file chdkbridge.c.

◆ exposure_requested()

bool exposure_requested ( const struct exposure_policy * exposure)
static

Check whether an explicit exposure override is present.

Parameters
exposureRequested exposure policy.
Returns
True if at least one override was supplied.

Presence, not the numeric value, determines whether a control was requested.

Definition at line 1068 of file chdkbridge.c.

◆ find_interface()

bool find_interface ( const struct usbfs_device * device,
int * interface_number,
int * alternate,
uint8_t * input,
uint8_t * output,
unsigned * output_packet_size )
static

Find a still-image PTP interface and its bulk endpoints.

Parameters
deviceEnumerated USB device; ownership stays with the device list.
interface_numberOutput interface number, not its array index.
alternateOutput alternate-setting number, not its array index.
inputOutput bulk-IN endpoint address on success.
outputOutput bulk-OUT endpoint address on success.
output_packet_sizeOutput bulk-OUT maximum packet size in bytes.
Returns
True for a class/subclass/protocol 6/1/1 interface with both endpoints.
Note
This examines descriptors, not CHDK support. CHDK is checked after opening the selected device; listing never claims an interface or triggers capture.

Definition at line 1640 of file chdkbridge.c.

◆ focus_script()

bool focus_script ( const struct focus_policy * focus,
char * body,
size_t capacity,
bool exposure_cleanup )
static

Build the focus setup and readback portion of a CHDK script.

Parameters
focusRequested mode, distance and verification bounds.
[out]bodyScript buffer; discard on failure.
capacityAvailable bytes including the terminator.
exposure_cleanupInclude the exposure-abort hook in focus failure handling.
Returns
True if the policy is supported locally and the script fits.

Validate mode combinations before formatting. The camera script checks model capabilities and bounds waits for mode and distance readback.

Definition at line 1096 of file chdkbridge.c.

◆ interrupt_handler()

void interrupt_handler ( int signal_number)
static

Request cancellation without allocation, I/O, or USB calls in a signal handler.

Definition at line 134 of file chdkbridge.c.

◆ main()

int main ( int argc,
char ** argv )

Select one camera, execute one operation, and release owned resources.

Parameters
argcArgument count.
argvProgram name and CLI arguments.
Returns
0 for success, 1 for dependency/device/operation failure, 2 for invalid CLI.

Capture publishes a complete temporary file with link(), which fails if the destination exists, including a file created after the initial check. Zoom and info bypass local-file creation. Cleanup closes only a session opened here and removes only a temporary file successfully created by this invocation.

Definition at line 2078 of file chdkbridge.c.

◆ monotonic_ms()

uint64_t monotonic_ms ( void )
static

Read a wall-clock-independent time base; return zero if the clock fails.

Definition at line 141 of file chdkbridge.c.

◆ parse_number()

bool parse_number ( const char * text,
unsigned maximum,
unsigned * value )
static

Parse a positive CLI number; zero is reserved for unspecified selection.

Definition at line 1680 of file chdkbridge.c.

◆ parse_range()

bool parse_range ( const char * text,
unsigned minimum,
unsigned maximum,
unsigned * value )
static

Parse unsigned decimal CLI input with inclusive bounds.

Parameters
textNonempty digits; signs, whitespace, and trailing text are rejected.
minimumLowest accepted number, inclusive.
maximumHighest accepted number, inclusive.
valueOutput destination, modified only on success.
Returns
True for a representable value in the specified range.

Definition at line 1668 of file chdkbridge.c.

◆ parse_scaled()

bool parse_scaled ( const char * text,
unsigned scale,
unsigned minimum,
unsigned maximum,
unsigned * value )
static

Parse a decimal setting and convert it to rounded integer units.

Parameters
textNull-terminated numeric token beginning with a decimal digit.
scaleMultiplier applied before checking bounds.
minimumInclusive minimum in scaled units.
maximumInclusive maximum in scaled units.
[out]valueRounded result written on success.
Returns
True when syntax and scaled range are accepted.

Reject hexadecimal and non-finite inputs rather than passing unusual spellings through to camera-side option handling.

Definition at line 1712 of file chdkbridge.c.

◆ parse_shutter()

bool parse_shutter ( const char * text,
struct exposure_policy * exposure )
static

Convert a decimal or rational shutter time to an exposure ratio.

Parameters
textExposure in seconds, as a decimal or numerator/denominator.
[in,out]exposurePolicy receiving the checked ratio.
Returns
True for an exposure from one microsecond through 64 seconds.

Keep fractions exact and convert decimal seconds to microseconds; validate rational bounds with widened integers before updating the policy.

Definition at line 1729 of file chdkbridge.c.

◆ parse_signed()

bool parse_signed ( const char * text,
int minimum,
int maximum,
int * value )
static

Parse a bounded signed decimal command-line value.

Parameters
textNull-terminated token, optionally prefixed by minus.
minimumInclusive lower bound.
maximumInclusive upper bound.
[out]valueResult written on success.
Returns
True for a complete in-range token.

Check both syntax and range before narrowing the conversion.

Definition at line 1692 of file chdkbridge.c.

◆ parse_usb_port()

bool parse_usb_port ( const char * text,
struct usb_port_selection * selection )
static

Parse a stable USB bus and port-chain selector.

Parameters
textUSB path in BUS-PORT[.PORT...] form.
[out]selectionParsed selector; discard on failure.
Returns
True when the complete nonempty chain fits.

Select the physical port independently of changing device addresses.

Definition at line 1761 of file chdkbridge.c.

◆ power_status()

bool power_status ( struct transport * transport)
static

Print the camera's idle power-off policy and available telemetry.

Parameters
transportActive PTP session.
Returns
True only for a valid reply indicating the Always keep-awake policy.

The query is read-only. Report the observed setting even if it does not satisfy the operational policy.

Definition at line 867 of file chdkbridge.c.

◆ print_help()

void print_help ( const char * program)
static

Print build identity and CLI usage without initializing USB.

Parameters
programProgram name from argv[0].

Definition at line 1993 of file chdkbridge.c.

◆ ptp_response_name()

const char * ptp_response_name ( uint16_t code)
static

Describe standard PTP response failures without triggering recovery actions.

Definition at line 298 of file chdkbridge.c.

◆ publish_control_reply()

bool publish_control_reply ( unsigned descriptor,
uint8_t command,
uint8_t observed,
uint8_t evidence )
static

Emit the control operation's fixed-size binary receipt.

Parameters
descriptorCaller-provided descriptor, or zero to omit the receipt.
commandEchoed command ID.
observedObserved camera value when applicable.
evidenceKind of confirmation supplied with the value.
Returns
True for a complete write or when no receipt was requested.

Keep this receipt separate from human-readable stdout so the parent can distinguish camera evidence from process success.

Definition at line 2059 of file chdkbridge.c.

◆ receive_bytes()

bool receive_bytes ( struct transport * transport,
uint8_t * destination,
size_t length )
static

Read an exact bounded payload across arbitrary USB transfer splits.

Parameters
transportInput stream, including retained read-ahead.
destinationWritable region of at least length bytes.
lengthExact number of bytes required by the parser.
Returns
True only when the requested bytes have been copied.

Definition at line 281 of file chdkbridge.c.

◆ recover_ptp()

bool recover_ptp ( struct transport * transport,
int interface_number )
static

Clear a session or stale data left by an interrupted earlier run.

Parameters
transportClaimed interface whose OpenSession just failed.
interface_numberClaimed still-image interface.
Returns
True when the device is present and OpenSession may be retried once.

Uses the still-image class requests and endpoint halt clearing, as chdkptp does; never resets the USB port. Stale input is drained with a bound.

Definition at line 454 of file chdkbridge.c.

◆ refill_buffer()

bool refill_buffer ( struct transport * transport)
static

Refill empty bounded USB storage without replaying a command.

Parameters
transportInput stream whose previous bytes have been consumed.
Returns
False on cancellation, exhausted deadline, repeated empty reads, or a USB error.

Read-ahead is retained for subsequent headers or payloads. Failed calls may already have consumed part of the stream; do not retry parsing.

Definition at line 245 of file chdkbridge.c.

◆ release_desktop_camera()

bool release_desktop_camera ( struct transport * transport,
unsigned bus,
unsigned address )
static

Supervise a targeted desktop unmount helper.

Parameters
transportOperation whose deadline bounds the helper.
busSelected USB bus.
addressSelected device address.
Returns
True if the helper exited successfully.

Run the helper in its own process group and terminate it on expiry or cancellation. Success permits a claim attempt, not assumed ownership.

Definition at line 1919 of file chdkbridge.c.

◆ remaining_ms()

unsigned remaining_ms ( const struct transport * transport)
static

Compute the next USB call's timeout within the operation deadline.

Parameters
transportActive session and its absolute deadline.
Returns
1..10000 ms, or zero for cancellation, expiry, or clock failure.
Note
A zero result means "do not call"; USB calls always receive a nonzero timeout. Calls default to a 1 s cap; –usb-timeout permits 50..10000 ms without extending the overall operation deadline.

Definition at line 156 of file chdkbridge.c.

◆ retract_lens()

bool retract_lens ( struct transport * transport)
static

Ask the camera to enter playback and confirm the resulting mode.

Parameters
transportActive PTP session.
Returns
True if playback was confirmed.
Warning
Success does not establish physical lens position.

Definition at line 807 of file chdkbridge.c.

◆ run_script()

bool run_script ( struct transport * transport,
const char * body,
char * result,
size_t result_capacity )
static

Execute a capture-path script without direct-download output.

Parameters
transportActive PTP session and deadline.
bodyCamera-side Lua source.
[out]resultCaller buffer for the validated script result.
result_capacityBuffer size including the terminator.
Returns
True after the script operation succeeds.

Reuse the common script runner with the capture-path policy so ordinary SD capture and direct transfer share result validation.

Definition at line 781 of file chdkbridge.c.

◆ run_script_operation()

bool run_script_operation ( struct transport * transport,
const char * body,
char * result,
size_t result_capacity,
FILE * direct_file,
bool enter_record )
static

Run camera-side Lua and wait for its correlated string return value.

Parameters
transportOpen CHDK PTP session and overall operation deadline.
bodyIndependently authored script body.
resultDestination for one nonempty, NUL-terminated return string.
result_capacityTotal writable capacity, including the terminator.
direct_fileOptional JPEG stream serviced while the script runs.
enter_recordPrepend record-mode setup for existing capture/configuration operations.
Returns
True when this script has returned a string and is no longer running.

Requires CHDK protocol 2.6+ within major version 2. Existing scripts are not killed. Messages belonging to another script ID are ignored, camera errors fail the operation, and an oversized or embedded-NUL result is rejected.

Warning
Host cancellation/timeout does not stop a script already on the camera.

Definition at line 621 of file chdkbridge.c.

◆ script_error_name()

const char * script_error_name ( uint32_t error)
static

Translate a CHDK script status for diagnostics.

Parameters
errorCamera-reported script error code.
Returns
Borrowed static description, including an unknown-code fallback.

Definition at line 521 of file chdkbridge.c.

◆ send_packet()

bool send_packet ( struct transport * transport,
uint8_t * bytes,
size_t length )
static

Submit one complete, small outbound PTP container.

Parameters
transportClaimed USB transport.
bytesEncoded container; the URB API requires a non-const buffer.
lengthNumber of bytes to transmit, representable by an int.
Returns
True only when the complete container was transferred.
Warning
Partial writes abort rather than resend a possibly executed command.

Definition at line 223 of file chdkbridge.c.

◆ set_zoom()

bool set_zoom ( struct transport * transport,
unsigned level,
uint8_t * observed )
static

Set normalized optical zoom without taking or downloading a photo.

Parameters
transportOpen camera session.
level0 selects the first zoom step; 255 selects the last.
observedOptional confirmed normalized lens-step position.
Returns
True after camera-side get_zoom() confirms the requested step.

The camera computes floor((level * (steps - 1) + 127) / 255), using get_zoom_steps() as a count. This rounds to a lens step, not a focal length. A lens with one step maps every valid level to zero. Digital zoom is not set.

Definition at line 1550 of file chdkbridge.c.

◆ settings_requested()

bool settings_requested ( const struct capture_settings * settings)
static

Check whether a capture needs camera configuration before shooting.

Parameters
settingsParsed optional settings.
Returns
True if a focus, exposure, power or camera setting was requested.

Skip the configuration script when the user requested no changes.

Definition at line 1079 of file chdkbridge.c.

◆ settings_script()

bool settings_script ( const struct capture_settings * settings,
char * body,
size_t capacity )
static

Assemble bounded Lua for applying the requested camera settings.

Parameters
settingsParsed settings and focus/exposure policies.
[out]bodyScript buffer; discard on failure.
capacityAvailable bytes including the terminator.
Returns
True when the script fits and local policy checks pass.

Share the setup and cleanup fragments between configuration and capture so both paths apply the same camera-side checks.

Definition at line 1178 of file chdkbridge.c.

◆ transaction()

bool transaction ( struct transport * transport,
uint16_t operation,
const uint32_t * parameters,
size_t parameter_count,
const uint8_t * outgoing,
size_t outgoing_size,
uint8_t * incoming,
size_t capacity,
FILE * file,
struct response * response )
static

Perform command, optional data, and response phases for one PTP operation.

Parameters
transportSingle-session transport; transaction_id advances once.
operationStandard PTP or vendor operation code.
parametersHost-order command parameters, or NULL for zero parameters.
parameter_countNumber of command parameters, at most five.
outgoingOptional host-to-camera data; NULL means no outgoing data phase.
outgoing_sizePayload size, limited to SCRIPT_CAPACITY bytes.
incomingOptional destination for a small camera-to-host payload.
capacityWritable size of incoming; ignored when file is supplied.
fileOptional stream for image data; takes precedence over incoming.
responseSuccessful response parameters and data size; reset on entry.
Returns
True only after a matching PTP_OK response and any required data phase.

A data phase is bounded before it is consumed. Response bodies contain at most five 32-bit parameters. This minimal client does not recover the USB stream after malformed input or retry non-idempotent operations.

Definition at line 329 of file chdkbridge.c.

◆ unmount_desktop_camera()

int unmount_desktop_camera ( unsigned bus,
unsigned address )
static

Resolve one optional desktop camera mount and invoke its unmount.

Parameters
busSelected USB bus.
addressSelected device address.
Returns
One on failure; successful exec replaces this helper process.

Load desktop dependencies only in the helper so headless operation does not require the GIO runtime.

Definition at line 1865 of file chdkbridge.c.

◆ usb_failure_hint()

const char * usb_failure_hint ( int error)
static

Select a recovery hint for a USB transport failure.

Parameters
errorusbfs wrapper status.
Returns
Borrowed static diagnostic.

Distinguish device loss, access and ownership from timeouts that may leave a completed shot on the camera. Do not prescribe blind replay.

Definition at line 170 of file chdkbridge.c.

◆ usb_port_matches()

bool usb_port_matches ( const struct usb_port_selection * selection,
unsigned bus,
const uint8_t * ports,
int depth )
static

Compare a discovered device with the optional port selector.

Parameters
selectionParsed selector; empty depth disables the filter.
busDiscovered bus number.
portsDiscovered port chain with depth entries when valid.
depthDiscovered chain length, or a negative unavailable value.
Returns
True for an exact match or an unconfigured selector.

Do not accept a prefix match: another device may be farther downstream on the same hub.

Definition at line 1789 of file chdkbridge.c.

◆ valid_camera_path()

bool valid_camera_path ( const char * path)
static

Validate a bounded printable camera pathname with no traversal components.

Parameters
pathAbsolute camera path beginning with A/; no script interpolation occurs.
Returns
True for a nonempty file path shorter than 512 bytes.

Definition at line 886 of file chdkbridge.c.

◆ valid_ptp_interface()

bool valid_ptp_interface ( const struct usbfs_interface * descriptor,
uint8_t * input,
uint8_t * output )
static

Validate one USB still-image interface without opening the device.

Parameters
descriptorCandidate alternate-setting descriptor.
inputBulk-IN address, modified only on successful validation.
outputBulk-OUT address, modified only on successful validation.
Returns
True for PTP 6/1/1 with one valid bulk endpoint in each direction.

Zero/reserved endpoint addresses, missing packet sizes, duplicate bulk directions, and unsupported endpoint types are rejected. One optional interrupt-IN endpoint is allowed for events, although this client does not consume events. Packet-size checks cover full/high/super-speed bulk limits.

Definition at line 1589 of file chdkbridge.c.

◆ valid_script_message()

bool valid_script_message ( const struct response * response,
const uint8_t * message )
static

Validate known message types and payload lengths, including empty-message zero padding.

Definition at line 533 of file chdkbridge.c.

◆ wait_script_idle()

bool wait_script_idle ( struct transport * transport)
static

Wait within the deadline until no camera script is running; never interrupts one.

Definition at line 586 of file chdkbridge.c.

◆ wait_script_poll()

bool wait_script_poll ( const struct transport * transport,
unsigned interval_ms )
static

Sleep to a monotonic poll target without extending it on EINTR or exceeding the deadline.

Definition at line 566 of file chdkbridge.c.

Variable Documentation

◆ active_config

int(* active_config) (const struct usbfs_device *, uint8_t *, size_t, const uint8_t **, size_t *) ( const struct usbfs_device * ,
uint8_t * ,
size_t ,
const uint8_t ** ,
size_t *  )

Definition at line 55 of file chdkbridge.c.

◆ bulk_transfer

int(* bulk_transfer) (struct usbfs_handle *, unsigned char, unsigned char *, int, int *, unsigned) ( struct usbfs_handle * ,
unsigned char ,
unsigned char * ,
int ,
int * ,
unsigned  )

Definition at line 61 of file chdkbridge.c.

◆ camera_settings

const struct camera_setting camera_settings[]
static
Initial value:
= {
{"--iso-mode", "ISO_MODE", 32767},
{"--flash", "FLASH_MODE", 2},
{"--resolution", "RESOLUTION", 8},
{"--quality", "QUALITY", 2},
{"--date-stamp", "DATE_STAMP", 3},
{"--af-assist", "AF_ASSIST_BEAM", 1},
{"--raw", NULL, 1}
}

Definition at line 1024 of file chdkbridge.c.

◆ claim_interface

int(* claim_interface) (struct usbfs_handle *, int) ( struct usbfs_handle * ,
int  )

Definition at line 58 of file chdkbridge.c.

◆ clear_halt

int(* clear_halt) (struct usbfs_handle *, unsigned char) ( struct usbfs_handle * ,
unsigned char  )

Definition at line 64 of file chdkbridge.c.

◆ close

void(* close) (struct usbfs_handle *) ( struct usbfs_handle * )

Definition at line 57 of file chdkbridge.c.

◆ control_transfer

int(* control_transfer) (struct usbfs_handle *, uint8_t, uint8_t, uint16_t, uint16_t, unsigned char *, uint16_t, unsigned) ( struct usbfs_handle * ,
uint8_t ,
uint8_t ,
uint16_t ,
uint16_t ,
unsigned char * ,
uint16_t ,
unsigned  )

Definition at line 62 of file chdkbridge.c.

◆ devices_close

void(* devices_close) (struct usbfs_devices *) ( struct usbfs_devices * )

Definition at line 54 of file chdkbridge.c.

◆ devices_next

int(* devices_next) (struct usbfs_devices *, struct usbfs_device *) ( struct usbfs_devices * ,
struct usbfs_device *  )

Definition at line 53 of file chdkbridge.c.

◆ devices_open

int(* devices_open) (struct usbfs_devices *) ( struct usbfs_devices * )

Definition at line 52 of file chdkbridge.c.

◆ interrupted

volatile sig_atomic_t interrupted
static

Signal-safe cancellation flag checked before blocking USB calls.

Definition at line 131 of file chdkbridge.c.

◆ open

int(* open) (const struct usbfs_device *, struct usbfs_handle *) ( const struct usbfs_device * ,
struct usbfs_handle *  )

Definition at line 56 of file chdkbridge.c.

◆ power_status_script

const char power_status_script[]
static

Definition at line 819 of file chdkbridge.c.

◆ record_mode_script

const char record_mode_script[]
static
Initial value:
=
"if not get_mode() then set_record(true) end\n"
"local started=get_tick_count()\n"
"while not get_mode() and bitand(get_tick_count()-started,2147483647)<5000 do sleep(100) end\n"
"if not get_mode() then error('cannot enter record mode') end\n"

Definition at line 600 of file chdkbridge.c.

◆ release_interface

int(* release_interface) (struct usbfs_handle *, int) ( struct usbfs_handle * ,
int  )

Definition at line 59 of file chdkbridge.c.

◆ retract_lens_script

const char retract_lens_script[]
static
Initial value:
=
"if type(get_mode)~='function' or type(get_shooting)~='function' or "
"type(get_tick_count)~='function' or type(sleep)~='function' then error('missing playback API') end\n"
"if get_shooting() then error('camera is shooting; lens retract rejected') end\n"
"local record=get_mode()\n"
"if type(record)~='boolean' then error('invalid camera mode') end\n"
"if record then\n"
" if type(switch_mode_usb)=='function' then switch_mode_usb(0)\n"
" elseif type(set_record)=='function' then set_record(false)\n"
" else error('missing playback transition API') end\n"
" local started=get_tick_count()\n"
" while get_mode() and bitand(get_tick_count()-started,2147483647)<5000 do sleep(50) end\n"
" if get_mode()~=false then error('cannot enter playback mode') end\n"
"end\n"
"return 'Playback confirmed; physical lens retraction not verified'\n"

Definition at line 787 of file chdkbridge.c.

◆ romlog_script

const char romlog_script[]
static
Initial value:
=
"if type(call_event_proc)~='function' then error('native event procedures unavailable') end\n"
"if type(os)~='table' or type(os.stat)~='function' or type(os.remove)~='function' then error('log filesystem API unavailable') end\n"
"if type(get_config_value)~='function' or get_config_value(1999)~=1 then error('Enable Lua native calls in CHDK menu, or use Save ROM crash log') end\n"
"if call_event_proc('SystemEventInit')==-1 and call_event_proc('System.Create')==-1 then error('log export initialization failed') end\n"
"for _,path in ipairs{'A/ROMLOG.LOG','A/RomLogErr.txt'} do\n"
" if os.stat(path) and not os.remove(path) then error('cannot replace old log '..path) end\n"
"end\n"
"if call_event_proc('GetLogToFile','A/ROMLOG.LOG',1)~=0 then error('GetLogToFile failed') end\n"
"if os.stat('A/RomLogErr.txt') then error('camera reported RomLogErr.txt') end\n"
"local info=os.stat('A/ROMLOG.LOG')\n"
"if type(info)~='table' or type(info.size)~='number' or info.size<1 or info.size>65536 then error('missing or oversized ROM log') end\n"
"return 'A/ROMLOG.LOG'\n"

Definition at line 926 of file chdkbridge.c.

◆ set_alternate

int(* set_alternate) (struct usbfs_handle *, int, int) ( struct usbfs_handle * ,
int ,
int  )

Definition at line 60 of file chdkbridge.c.

◆ [struct]

struct { ... } usb
Initial value:
= {
}
static int usbfs_clear_halt(struct usbfs_handle *handle, unsigned char endpoint)
Clear a halted endpoint of a claimed interface; data toggles are reset by the kernel.
Definition usbfs.h:465
static int usbfs_release_interface(struct usbfs_handle *handle, int interface)
Release the numbered interface on an open device.
Definition usbfs.h:411
static int usbfs_bulk_transfer(struct usbfs_handle *handle, unsigned char endpoint, unsigned char *data, int length, int *transferred, unsigned timeout)
Synchronous bulk transfer with libusb_bulk_transfer() semantics.
Definition usbfs.h:563
static int usbfs_active_config(const struct usbfs_device *device, uint8_t *buffer, size_t capacity, const uint8_t **config, size_t *config_length)
Read the active configuration into buffer; config points inside it.
Definition usbfs.h:256
static void usbfs_devices_close(struct usbfs_devices *devices)
Release the sysfs enumeration stream.
Definition usbfs.h:225
static int usbfs_devices_open(struct usbfs_devices *devices)
Start a streaming sysfs enumeration.
Definition usbfs.h:192
static int usbfs_control_transfer(struct usbfs_handle *handle, uint8_t request_type, uint8_t request, uint16_t value, uint16_t index, unsigned char *data, uint16_t length, unsigned timeout)
Synchronous control transfer on endpoint zero.
Definition usbfs.h:444
static int usbfs_open(const struct usbfs_device *device, struct usbfs_handle *handle)
Open the device node, rejecting a node now owned by a different device.
Definition usbfs.h:343
static int usbfs_set_alternate(struct usbfs_handle *handle, int interface, int alternate)
Select an alternate setting for an interface.
Definition usbfs.h:423
static int usbfs_devices_next(struct usbfs_devices *devices, struct usbfs_device *device)
Definition usbfs.h:200
static int usbfs_claim_interface(struct usbfs_handle *handle, int interface)
Claim without detaching another owner; EBUSY is reported to the caller.
Definition usbfs.h:400
static void usbfs_close(struct usbfs_handle *handle)
Close the node; the kernel releases claimed interfaces and kills pending URBs.
Definition usbfs.h:371

USB operations used by the application; tests substitute fakes.