aboutsummaryrefslogtreecommitdiff
path: root/src/modem.h
blob: 196a551b432c505e5d1c6dd22ff4bbe078101e2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
 * modem.h
 * (c) 2019, Jonas Gunz, jonasgunz.de
 * <Description>
 * <License>
*/

#include <unistd.h>
#include <poll.h>
#include <string.h>
#include <signal.h>
#include <errno.h>

#include "misc.h"
#include "log.h"
#include "serial.h"

#define _AT "AT\r\n"
#define _AT_ANSWER "ATA\r\n"
#define _AT_ECHO_OFF "ATE0\r\n"
#define _AT_ECHO_ON "ATE1\r\n"
#define _AT_HANGUP "ATH\r\n"
#define _AT_CMD_MODE "+++\r\n"
#define _AT_MUTE "ATM0\r\n"
#define _AT_RESET_ON_DTR "AT&D3\r\n"

//Uncomment to ignore wait for modem ring
#define _MODEM_WAIT_RING

/*
 * Waits for RING (ifdef _MODEM_WAIT_RING), accepts incoming calls. Return is non-zero when cennection fails.
 * */
int modem_accept_wait(int fd);

/*
 * Execute an AT command. return is non-zero if answer is not OK
 * */
int modem_command(int fd, char* cmd, int timeout_ms);

/*
 * Run a program with modem as STDIO. checks if connection is still alive & process is still active.
 * will close fd on successful return
 * */
int modem_run(int fd, int argc, char* argv[]);

/*
 * Spawn a telnet server
 * */
void dialup_server(struct prog_params params);