47#include "modemu2k_version.h"
64# if defined(M2K_BUILDING_DLL)
65# define M2K_API __declspec(dllexport)
67# define M2K_API __declspec(dllimport)
69# elif defined(__GNUC__) && __GNUC__ >= 4
70# define M2K_API __attribute__((visibility("default")))
80#if defined(M2K_SUPPRESS_DEPRECATED)
81# define M2K_DEPRECATED(msg)
82#elif defined(__GNUC__) || defined(__clang__)
83# define M2K_DEPRECATED(msg) __attribute__((deprecated(msg)))
84#elif defined(_MSC_VER)
85# define M2K_DEPRECATED(msg) __declspec(deprecated(msg))
87# define M2K_DEPRECATED(msg)
165#define M2K_ERROR_BUFFER_SIZE 256
238M2K_API M2K_DEPRECATED(
"use m2k_run() or the step API instead")
239m2k_err_t m2k_dial(
m2k_t *ctx, const
char *host, const
char *port);
254M2K_API M2K_DEPRECATED(
"use m2k_run() or the step API instead")
535#define M2K_MAX_POLLFDS 3
555 size_t *nfds_inout,
int *timeout_ms);
M2K_API void m2k_set_force_verbose(m2k_t *ctx, int on)
Bypass the ATV verbose mask in verboseOut() / verbosePerror().
M2K_API m2k_err_t m2k_setup_app_io(m2k_t *ctx)
Embed mode: no real TTY fd; the host application supplies the bytes a TTY would normally produce,...
void(* m2k_log_fn)(const char *msg, void *userdata)
Log callback type.
Definition modemu2k.h:115
M2K_API int m2k_is_online(const m2k_t *ctx)
Test whether the modem is currently in online mode.
M2K_API int m2k_get_dtr(const m2k_t *ctx)
M2K_API m2k_err_t m2k_listen_accept(m2k_t *ctx)
Accept a single incoming connection on the listening socket opened by m2k_setup_listen() and adopt it...
M2K_API m2k_err_t m2k_run(m2k_t *ctx)
Run the modem command/online loop until the PTY closes.
M2K_API void m2k_set_error_buffer(m2k_t *ctx, char *buf, size_t size)
Install a buffer that receives a detailed message for the most recent error.
M2K_API void m2k_free(m2k_t *ctx)
Release all resources held by ctx.
M2K_API m2k_err_t m2k_setup_comm_program(m2k_t *ctx, const char *cmd)
Allocate a PTY and fork/exec a comm program on the slave.
M2K_API int m2k_run_done(const m2k_t *ctx)
Test whether the session has ended.
M2K_API m2k_err_t m2k_setup_stdin(m2k_t *ctx)
Use stdin/stdout as the TTY (standalone mode).
M2K_API void m2k_set_log_fn(m2k_t *ctx, m2k_log_fn fn, void *userdata)
Install a log callback.
M2K_API m2k_err_t m2k_setup_dev(m2k_t *ctx, const char *dev)
Open an existing PTY device as the TTY.
M2K_API m2k_err_t m2k_escape(m2k_t *ctx)
Request an immediate return to command mode from online mode.
M2K_API const char * m2k_version(void)
Runtime version string of the linked libmodemu2k.
struct m2k_s m2k_t
Opaque modem emulator context. Create with m2k_new(), destroy with m2k_free().
Definition modemu2k.h:95
M2K_API m2k_err_t m2k_atcmd(m2k_t *ctx, const char *cmd)
Feed a Hayes AT command string to the modem.
M2K_API m2k_err_t m2k_hangup(m2k_t *ctx)
Tear down the active TCP connection.
M2K_API m2k_t * m2k_new(void)
Allocate and initialise a new modem context.
M2K_API m2k_err_t m2k_step(m2k_t *ctx, struct pollfd *fds, size_t nfds)
Run one non-blocking iteration of the state machine.
M2K_API int m2k_has_pending_output(const m2k_t *ctx)
Test whether the modem has TTY-bound bytes still buffered.
M2K_API int m2k_get_rts(const m2k_t *ctx)
m2k_err_t
Return codes used by all m2k_* functions.
Definition modemu2k.h:122
@ M2K_ERR_PTY
Definition modemu2k.h:125
@ M2K_ERR_NOMEM
Definition modemu2k.h:124
@ M2K_ERR_WOULDBLOCK
Definition modemu2k.h:130
@ M2K_ERR_TIMEOUT
Definition modemu2k.h:127
@ M2K_OK
Definition modemu2k.h:123
@ M2K_ERR_CANCELED
Definition modemu2k.h:128
@ M2K_ERR_BUG
Definition modemu2k.h:129
@ M2K_ERR_SOCKET
Definition modemu2k.h:126
@ M2K_ERR_AT
Definition modemu2k.h:133
M2K_API m2k_err_t m2k_write_from_app(m2k_t *ctx, const void *buf, size_t len, size_t *consumed)
Push bytes into the modem as if they had been read from the TTY.
M2K_API m2k_err_t m2k_setup_pty(m2k_t *ctx, const char **slave_out)
Allocate a PTY master and return the slave device path.
M2K_API m2k_err_t m2k_read_to_app(m2k_t *ctx, void *buf, size_t max, size_t *len_out)
Drain bytes from the modem that would normally have been written to the TTY.
M2K_API int m2k_has_carrier(const m2k_t *ctx)
Test whether the modem has an active carrier (live TCP socket).
M2K_API m2k_err_t m2k_get_pollfds(m2k_t *ctx, struct pollfd *fds, size_t *nfds_inout, int *timeout_ms)
Describe the fds and timeout the caller's event loop should watch.
M2K_API const char * m2k_strerror(m2k_err_t err)
Return a human-readable string for err.
M2K_API void m2k_set_rts(m2k_t *ctx, int on)
Set the host's RTS (Request to Send) signal state.
M2K_API int m2k_get_force_verbose(const m2k_t *ctx)
M2K_API m2k_err_t m2k_setup_listen(m2k_t *ctx, const char *port)
Bind a TCP listening socket on port.
M2K_API void m2k_set_dtr(m2k_t *ctx, int on)
Set the host's DTR (Data Terminal Ready) signal state.
#define M2K_API
Public-symbol visibility/export marker.
Definition modemu2k.h:72
M2K_API int m2k_get_listen_fd(const m2k_t *ctx)
Expose the listening socket's fd (after m2k_setup_listen, before m2k_listen_accept).