Adding shutdown option to interface.conf
[lcr.git] / port.h
1 /*****************************************************************************\
2 **                                                                           **
3 ** PBX4Linux                                                                 **
4 **                                                                           **
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg                                              **
7 **                                                                           **
8 ** port header file                                                          **
9 **                                                                           **
10 \*****************************************************************************/ 
11
12 #ifndef PORT_HEADER
13 #define PORT_HEADER
14
15 /* type of port */
16 #define PORT_TYPE_NULL          0x0000
17 #define PORT_CLASS_mISDN        0x1000
18 #define PORT_CLASS_DSS1         0x1100
19 #define PORT_CLASS_DSS1_NT      0x1110
20 #define PORT_CLASS_DSS1_TE      0x1120
21 #define PORT_CLASS_GSM          0x1200
22 #define PORT_CLASS_GSM_BS       0x1210
23 #define PORT_CLASS_GSM_MS       0x1220
24 #define PORT_CLASS_SS5          0x1300
25 #define PORT_CLASS_REMOTE       0x1400
26 #define PORT_CLASS_MASK         0xf000
27 #define PORT_CLASS_mISDN_MASK   0xff00
28 #define PORT_CLASS_DSS1_MASK    0xfff0
29 #define PORT_CLASS_GSM_MASK     0xfff0
30 #define PORT_CLASS_DIR_MASK     0x000f
31 #define PORT_CLASS_DIR_IN       0x0001
32 #define PORT_CLASS_DIR_OUT      0x0002
33         /* nt-mode */
34 #define PORT_TYPE_DSS1_NT_IN    0x1111
35 #define PORT_TYPE_DSS1_NT_OUT   0x1112
36         /* te-mode */
37 #define PORT_TYPE_DSS1_TE_IN    0x1121
38 #define PORT_TYPE_DSS1_TE_OUT   0x1122
39         /* gsm */
40 #define PORT_TYPE_GSM_BS_IN     0x1211
41 #define PORT_TYPE_GSM_BS_OUT    0x1212
42 #define PORT_TYPE_GSM_MS_IN     0x1221
43 #define PORT_TYPE_GSM_MS_OUT    0x1222
44         /* ss5 */
45 #define PORT_TYPE_SS5_IN        0x1311
46 #define PORT_TYPE_SS5_OUT       0x1312
47 #define PORT_TYPE_SS5_IDLE      0x1313
48         /* remote */
49 #define PORT_TYPE_REMOTE_IN     0x1411
50 #define PORT_TYPE_REMOTE_OUT    0x1412
51         /* answering machine */
52 #define PORT_TYPE_VBOX_OUT      0x3111
53
54
55 enum { /* states of call */
56         PORT_STATE_IDLE,        /* no call */
57         PORT_STATE_IN_SETUP,    /* incoming connection */
58         PORT_STATE_OUT_SETUP,   /* outgoing connection */
59         PORT_STATE_IN_OVERLAP,  /* more informatiopn needed */
60         PORT_STATE_OUT_OVERLAP, /* more informatiopn needed */
61         PORT_STATE_IN_PROCEEDING,/* call is proceeding */
62         PORT_STATE_OUT_PROCEEDING,/* call is proceeding */
63         PORT_STATE_IN_ALERTING, /* call is ringing */
64         PORT_STATE_OUT_ALERTING,/* call is ringing */
65         PORT_STATE_CONNECT_WAITING,/* connect is sent to the network, waiting for acknowledge */
66         PORT_STATE_CONNECT,     /* call is connected and transmission is enabled */
67         PORT_STATE_IN_DISCONNECT,/* incoming disconnected */
68         PORT_STATE_OUT_DISCONNECT,/* outgoing disconnected */
69         PORT_STATE_RELEASE,     /* call released */
70 };
71
72 #define PORT_STATE_NAMES \
73 static const char *state_name[] = { \
74         "PORT_STATE_IDLE", \
75         "PORT_STATE_IN_SETUP", \
76         "PORT_STATE_OUT_SETUP", \
77         "PORT_STATE_IN_OVERLAP", \
78         "PORT_STATE_OUT_OVERLAP", \
79         "PORT_STATE_IN_PROCEEDING", \
80         "PORT_STATE_OUT_PROCEEDING", \
81         "PORT_STATE_IN_ALERTING", \
82         "PORT_STATE_OUT_ALERTING", \
83         "PORT_STATE_CONNECT_WAITING", \
84         "PORT_STATE_CONNECT", \
85         "PORT_STATE_IN_DISCONNECT", \
86         "PORT_STATE_OUT_DISCONNECT", \
87         "PORT_STATE_RELEASE", \
88 };
89
90
91 enum { /* event list from listening to tty */
92         TTYI_EVENT_nodata,      /* no data was received nor processed */
93         TTYI_EVENT_NONE,        /* nothing happens */
94         TTYI_EVENT_CONNECT,     /* a connection is made */
95         TTYI_EVENT_RING,        /* incoming call */
96         TTYI_EVENT_CALLER,      /* caller id information */
97         TTYI_EVENT_INFO,        /* dialing information */
98         TTYI_EVENT_OVERLAP,     /* setup complete, awaiting more dialing info */
99         TTYI_EVENT_PROC,        /* proceeding */
100         TTYI_EVENT_ALRT,        /* alerting */
101         TTYI_EVENT_CONN,        /* connect */
102         TTYI_EVENT_DISC,        /* disconnect */
103         TTYI_EVENT_RELE,        /* release signal */
104         TTYI_EVENT_BUSY,        /* channel unavailable */
105 };
106
107 #define RECORD_BUFFER_LENGTH    1024 // must be a binary border & must be greater 256, because 256 will be written if buffer overflows
108 #define RECORD_BUFFER_MASK      1023
109
110 /* structure of epoint_list */
111 struct epoint_list {
112         struct epoint_list      *next;
113         unsigned int            epoint_id;
114         int                     active;
115 };
116
117 inline unsigned int ACTIVE_EPOINT(struct epoint_list *epointlist)
118 {
119         while(epointlist)
120         {
121                 if (epointlist->active)
122                         return(epointlist->epoint_id);
123                 epointlist = epointlist->next;
124         }
125         return(0);
126 }
127
128 inline unsigned int INACTIVE_EPOINT(struct epoint_list *epointlist)
129 {
130         while(epointlist)
131         {
132                 if (!epointlist->active)
133                         return(epointlist->epoint_id);
134                 epointlist = epointlist->next;
135         }
136         return(0);
137 }
138
139
140 /* structure of port settings */
141 struct port_settings {
142         char tones_dir[256];                    /* directory of current tone */
143         int no_seconds;
144 };
145
146 /* generic port class */
147 class Port
148 {
149         public:
150         /* methods */
151         Port(int type, const char *portname, struct port_settings *settings);
152         virtual ~Port();
153         class Port *next;                       /* next port in list */
154         int p_type;                             /* type of port */
155         virtual int message_epoint(unsigned int epoint_id, int message, union parameter *param);
156         virtual void set_echotest(int echotest);
157         virtual void set_tone(const char *dir, const char *name);
158         virtual int read_audio(unsigned char *buffer, int length);
159         virtual void update_load(void);
160
161         struct port_settings p_settings;
162         
163         /* tone */
164         char p_tone_dir[256];                   /* name of current directory */
165         char p_tone_name[256];                  /* name of current tone */
166         char p_tone_fh;                         /* file descriptor of current tone or -1 if not open */
167         void *p_tone_fetched;                   /* pointer to fetched data */
168         int p_tone_codec;                       /* codec that the tone is made of */
169         signed int p_tone_size, p_tone_left;    /* size of tone in bytes (not samples), bytes left */
170         signed int p_tone_eof;                  /* flag that makes the use of eof message */
171         signed int p_tone_counter;              /* flag that makes the use of counter message */
172         signed int p_tone_speed;                /* speed of current tone, 1=normal, may also be negative */
173 //      char p_knock_fh;                        /* file descriptor of knocking tone or -1 if not open */
174 //      void *p_knock_fetched;                  /* pointer to fetched data */
175 //      int p_knock_codec;
176 //      signed int p_knock_size, p_knock_left;
177         void set_vbox_tone(const char *dir, const char *name);/* tone of answering machine */
178         void set_vbox_play(const char *name, int offset); /* sample of answ. */
179         void set_vbox_speed(int speed); /* speed of answ. */
180
181         /* identification */
182         unsigned int p_serial;                  /* serial unique id of port */
183         char p_name[128];                       /* name of port or token (h323) */
184
185         /* endpoint relation */
186         struct epoint_list *p_epointlist;       /* endpoint relation */
187
188         /* state */
189         int p_state;                            /* state of port */
190         void new_state(int state);              /* set new state */
191         struct caller_info p_callerinfo;        /* information about the caller */
192         struct dialing_info p_dialinginfo;      /* information about dialing */
193         struct connect_info p_connectinfo;      /* information about connected line */
194         struct redir_info p_redirinfo;          /* info on redirection (to the calling user) */
195         struct capa_info p_capainfo;    /* info on l2,l3 capacity */
196         int p_echotest;                         /* set to echo audio data FROM port back to port's mixer */
197
198         /* recording */
199         int open_record(int type, int mode, int skip, char *terminal, int anon_ignore, const char *vbox_email, int vbox_email_file);
200         void close_record(int beep, int mute);
201         void record(unsigned char *data, int length, int dir_fromup);
202         FILE *p_record;                         /* recording fp: if not NULL, recording is enabled */
203         int p_record_type;                      /* codec to use: RECORD_MONO, RECORD_STEREO, ... */
204         int p_record_skip;                      /* skip bytes before writing the sample */
205         unsigned int p_record_length;           /* size of what's written so far */
206
207         signed short p_record_buffer[RECORD_BUFFER_LENGTH];
208         unsigned int p_record_buffer_readp;
209         unsigned int p_record_buffer_writep;
210         int p_record_buffer_dir;                /* current direction in buffer */
211
212         char p_record_filename[256];            /* record filename */
213         int p_record_vbox;                      /* 0= normal recording, 1= announcement, 2= record to vbox dir */
214         int p_record_vbox_year;                 /* time when vbox recording started */
215         int p_record_vbox_mon;
216         int p_record_vbox_mday;
217         int p_record_vbox_hour;
218         int p_record_vbox_min;
219         char p_record_extension[32];            /* current name (digits) of extension */
220         int p_record_anon_ignore;
221         char p_record_vbox_email[128];
222         int p_record_vbox_email_file;
223         virtual void update_rxoff(void);        /* inherited by mISDNport, to control rxoff */
224
225         void free_epointlist(struct epoint_list *epointlist);
226         void free_epointid(unsigned int epoint_id);
227         struct epoint_list *epointlist_new(unsigned int epoint_id);
228 };
229
230
231 extern Port *port_first;
232 extern unsigned int port_serial;
233
234 class Port *find_port_with_token(char *name);
235 class Port *find_port_id(unsigned int port_id);
236
237
238 #endif // PORT_HEADER
239
240