1 #ifndef MODEM_CORE_H
2 #define MODEM_CORE_H 1
3 
4 #define MDM_RESP_OK 0
5 #define MDM_RESP_CONNECT 1
6 #define MDM_RESP_RING 2
7 #define MDM_RESP_NO_CARRIER 3
8 #define MDM_RESP_ERROR 4
9 #define MDM_RESP_CONNECT_1200 5
10 #define MDM_RESP_NO_DIALTONE 6
11 #define MDM_RESP_BUSY 7
12 #define MDM_RESP_NO_ANSWER 8
13 #define MDM_RESP_CONNECT_0600 9
14 #define MDM_RESP_CONNECT_2400 10
15 #define MDM_RESP_CONNECT_4800 11
16 #define MDM_RESP_CONNECT_9600 12
17 #define MDM_RESP_CONNECT_7200 13
18 #define MDM_RESP_CONNECT_12000 14
19 #define MDM_RESP_CONNECT_14400 15
20 #define MDM_RESP_CONNECT_19200 16
21 #define MDM_RESP_CONNECT_38400 17
22 #define MDM_RESP_CONNECT_57600 18
23 #define MDM_RESP_CONNECT_115200 19
24 #define MDM_RESP_CONNECT_234000 20
25 
26 #define MDM_CL_DSR_LOW 0
27 #define MDM_CL_DSR_HIGH 1
28 #define MDM_CL_DCD_LOW 0
29 #define MDM_CL_DCD_HIGH 2
30 #define MDM_CL_CTS_LOW 0
31 #define MDM_CL_CTS_HIGH 4
32 #define MDM_CL_DTR_LOW 0
33 #define MDM_CL_DTR_HIGH 8
34 #define MDM_FC_RTS 1
35 #define MDM_FC_XON 2
36 
37 #define MDM_CONN_NONE 0
38 #define MDM_CONN_OUTGOING 1
39 #define MDM_CONN_INCOMING 2
40 
41 #ifndef TRUE
42 #define TRUE 1
43 #define FALSE 0
44 #endif
45 
46 #include "nvt.h"
47 
48 #ifndef MAX
49 #define MAX(a, b) ((a) > (b) ? (a) : (b))
50 #endif
51 
52 
53 typedef struct line_config {
54   int valid_conn;
55   int fd;
56   int sfd;
57   int is_telnet;
58   int first_char;
59   nvt_vars nvt_data;
60 } line_config;
61 
62 typedef struct x_config {
63   int mp[2][2];
64   int cp[2][2];
65   int wp[2][2];
66   unsigned char no_answer[256];
67   unsigned char local_connect[256];
68   unsigned char remote_connect[256];
69   unsigned char local_answer[256];
70   unsigned char remote_answer[256];
71   unsigned char inactive[256];
72   unsigned int direct_conn;
73   unsigned char direct_conn_num[256];
74 } x_config;
75 
76 typedef struct dce_config {
77   int is_ip232;
78   unsigned char tty[256];
79   int first_char;
80   int fd;
81   int dp[2][2];
82   int sSocket;
83   int ip232_is_connected;
84   int ip232_dtr;
85   int ip232_dcd;
86   int ip232_iac;
87 } dce_config;
88 
89 typedef struct modem_config {
90   // master configuration information
91 
92   // need to eventually change these
93   dce_config dce_data;
94   line_config line_data;
95   x_config data;
96   unsigned char config0[1024];
97   unsigned char config1[1024];
98   int dce_speed;
99   int dte_speed;
100   int conn_type;
101   int line_ringing;
102   int off_hook;
103   int dsr_active;
104   int dsr_on;
105   int dcd_on;
106   int invert_dsr;
107   int invert_dcd;
108   int allow_transmit;
109   int rings;
110   // command information
111   int pre_break_delay;
112   int found_a;
113   int cmd_started;
114   int cmd_mode;
115   unsigned char last_cmd[1024];
116   unsigned char cur_line[1024];
117   int cur_line_idx;
118   // dailing information
119   unsigned char dialno[256];
120   unsigned char last_dialno[256];
121   unsigned char dial_type;
122   unsigned char last_dial_type;
123   int memory_dial;
124   // modem config
125   int connect_response;
126   int response_code_level;
127   int send_responses;
128   int text_responses;
129   int echo;
130   int s[100];
131   int break_len;
132   int disconnect_delay;
133   unsigned char crlf[3];
134 } modem_config;
135 
136 int mdm_init(void);
137 void mdm_init_config(modem_config* cfg);
138 int get_new_cts_state(modem_config *cfg, int up);
139 int get_new_dsr_state(modem_config *cfg, int up);
140 int get_new_dcd_state(modem_config *cfg, int up);
141 int mdm_set_control_lines(modem_config *cfg);
142 void mdm_write_char(modem_config *cfg,unsigned char data);
143 void mdm_write(modem_config *cfg,unsigned char data[], int len);
144 void mdm_send_response(int msg,modem_config *cfg);
145 int mdm_off_hook(modem_config *cfg);
146 int mdm_answer(modem_config *cfg);
147 int mdm_print_speed(modem_config *cfg);
148 int mdm_connect(modem_config* cfg);
149 int mdm_listen(modem_config *cfg);
150 int mdm_disconnect(modem_config* cfg);
151 int mdm_parse_cmd(modem_config* cfg);
152 int mdm_handle_char(modem_config* cfg, unsigned char ch);
153 int mdm_clear_break(modem_config* cfg);
154 int mdm_parse_data(modem_config* cfg,unsigned char* data, int len);
155 int mdm_handle_timeout(modem_config* cfg);
156 int mdm_send_ring(modem_config *cfg);
157 
158 #include "line.h"
159 #include "shared.h"
160 #include "dce.h"
161 
162 #endif
163