688faa6229904820a9ef83426881d2e8461a3ae9
[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        0x0100
18 #define PORT_CLASS_MASK         0xff00
19 #define PORT_CLASS_mISDN_DSS1   0x0110
20 #define PORT_CLASS_mISDN_MASK   0xfff0
21         /* nt-mode */
22 #define PORT_TYPE_DSS1_NT_IN    0x0111
23 #define PORT_TYPE_DSS1_NT_OUT   0x0112
24         /* te-mode */
25 #define PORT_TYPE_DSS1_TE_IN    0x0113
26 #define PORT_TYPE_DSS1_TE_OUT   0x0114
27         /* sip */
28 #define PORT_TYPE_SIP_IN        0x0121
29 #define PORT_TYPE_SIP_OUT       0x0122
30         /* h323 */
31 #define PORT_TYPE_H323_IN       0x0211
32 #define PORT_TYPE_H323_OUT      0x0212
33         /* answering machine */
34 #define PORT_TYPE_VBOX_OUT      0x0311
35
36
37 enum { /* states of call */
38         PORT_STATE_IDLE,        /* no call */
39         PORT_STATE_IN_SETUP,    /* incoming connection */
40         PORT_STATE_OUT_SETUP,   /* outgoing connection */
41         PORT_STATE_IN_OVERLAP,  /* more informatiopn needed */
42         PORT_STATE_OUT_OVERLAP, /* more informatiopn needed */
43         PORT_STATE_IN_PROCEEDING,/* call is proceeding */
44         PORT_STATE_OUT_PROCEEDING,/* call is proceeding */
45         PORT_STATE_IN_ALERTING, /* call is ringing */
46         PORT_STATE_OUT_ALERTING,/* call is ringing */
47         PORT_STATE_CONNECT_WAITING,/* connect is sent to the network, waiting for acknowledge */
48         PORT_STATE_CONNECT,     /* call is connected and transmission is enabled */
49         PORT_STATE_IN_DISCONNECT,/* incoming disconnected */
50         PORT_STATE_OUT_DISCONNECT,/* outgoing disconnected */
51         PORT_STATE_RELEASE,     /* call released */
52 };
53
54 #define PORT_STATE_NAMES \
55 static char *state_name[] = { \
56         "PORT_STATE_IDLE", \
57         "PORT_STATE_IN_SETUP", \
58         "PORT_STATE_OUT_SETUP", \
59         "PORT_STATE_IN_OVERLAP", \
60         "PORT_STATE_OUT_OVERLAP", \
61         "PORT_STATE_IN_PROCEEDING", \
62         "PORT_STATE_OUT_PROCEEDING", \
63         "PORT_STATE_IN_ALERTING", \
64         "PORT_STATE_OUT_ALERTING", \
65         "PORT_STATE_CONNECT_WAITING", \
66         "PORT_STATE_CONNECT", \
67         "PORT_STATE_IN_DISCONNECT", \
68         "PORT_STATE_OUT_DISCONNECT", \
69         "PORT_STATE_RELEASE", \
70 };
71
72
73 enum { /* event list from listening to tty */
74         TTYI_EVENT_nodata,      /* no data was received nor processed */
75         TTYI_EVENT_NONE,        /* nothing happens */
76         TTYI_EVENT_CONNECT,     /* a connection is made */
77         TTYI_EVENT_RING,        /* incoming call */
78         TTYI_EVENT_CALLER,      /* caller id information */
79         TTYI_EVENT_INFO,        /* dialing information */
80         TTYI_EVENT_OVERLAP,     /* setup complete, awaiting more dialing info */
81         TTYI_EVENT_PROC,        /* proceeding */
82         TTYI_EVENT_ALRT,        /* alerting */
83         TTYI_EVENT_CONN,        /* connect */
84         TTYI_EVENT_DISC,        /* disconnect */
85         TTYI_EVENT_RELE,        /* release signal */
86         TTYI_EVENT_BUSY,        /* channel unavailable */
87 };
88
89 /* structure of epoint_list */
90 struct epoint_list {
91         struct epoint_list      *next;
92         unsigned long           epoint_id;
93         int                     active;
94 };
95
96 inline unsigned long ACTIVE_EPOINT(struct epoint_list *epointlist)
97 {
98         while(epointlist)
99         {
100                 if (epointlist->active)
101                         return(epointlist->epoint_id);
102                 epointlist = epointlist->next;
103         }
104         return(0);
105 }
106
107 inline unsigned long INACTIVE_EPOINT(struct epoint_list *epointlist)
108 {
109         while(epointlist)
110         {
111                 if (!epointlist->active)
112                         return(epointlist->epoint_id);
113                 epointlist = epointlist->next;
114         }
115         return(0);
116 }
117
118
119 /* a linked list of soft-mixer relations */
120 struct mixer_relation {
121         struct mixer_relation *next;            /* next in list */
122         unsigned long port_id;                  /* port related to */
123         int mixer_writep;                       /* write pointer in buffer */
124         };
125
126 /* structure of port settings */
127 struct port_settings {
128         char tones_dir[256];                    /* directory of current tone */
129         int tout_setup;
130         int tout_dialing;
131         int tout_proceeding;
132         int tout_alerting;
133         int tout_disconnect;
134 //      int tout_hold;
135 //      int tout_park;
136         int no_seconds;                         /* don't send seconds with time information element */
137 };
138
139 /* generic port class */
140 class Port
141 {
142         public:
143         /* methods */
144         Port(int type, char *portname, struct port_settings *settings);
145         virtual ~Port();
146         class Port *next;                       /* next port in list */
147         int p_type;                             /* type of port */
148         virtual int handler(void);
149         virtual int message_epoint(unsigned long epoint_id, int message, union parameter *param);
150         virtual void set_echotest(int echotest);
151         virtual void set_tone(char *dir, char *name);
152         virtual int read_audio(unsigned char *buffer, int length, int compressed);
153
154         struct port_settings p_settings;
155         
156         /* tone */
157         int p_debug_nothingtosend;              /* used for debugging the, if we have currently nothing to send (used for ISDN) */
158         char p_tone_dir[256];                   /* name of current directory */
159         char p_tone_name[256];                  /* name of current tone */
160         char p_tone_fh;                         /* file descriptor of current tone or -1 if not open */
161         void *p_tone_fetched;                   /* pointer to fetched data */
162         int p_tone_codec;                       /* codec that the tone is made of */
163         long p_tone_size, p_tone_left;          /* size of tone in bytes (not samples), bytes left */
164         long p_tone_eof;                        /* flag that makes the use of eof message */
165         long p_tone_counter;                    /* flag that makes the use of counter message */
166         long p_tone_speed;                      /* speed of current tone, 1=normal, may also be negative */
167 //      char p_knock_fh;                        /* file descriptor of knocking tone or -1 if not open */
168 //      void *p_knock_fetched;                  /* pointer to fetched data */
169 //      int p_knock_codec;
170 //      long p_knock_size, p_knock_left;
171         void set_vbox_tone(char *dir, char *name);/* tone of answering machine */
172         void set_vbox_play(char *name, int offset); /* sample of answ. */
173         void set_vbox_speed(int speed); /* speed of answ. */
174
175         /* user space mixer buffer */
176         signed long p_mixer_buffer[PORT_BUFFER];        /* mixer buffer */
177         signed long p_record_buffer[PORT_BUFFER];       /* record buffer */
178         signed long p_stereo_buffer[PORT_BUFFER];       /* record buffer for stereo (user only) */
179         struct mixer_relation *p_mixer_rel;     /* list of mixer relations */
180         int p_mixer_readp;                      /* read pointer in buffer */
181
182         /* methods */
183         void mixer(union parameter *param);
184         
185         /* identification */
186         unsigned long p_serial;                 /* serial unique id of port */
187         char p_name[128];                       /* name of port or token (h323) */
188
189         /* endpoint relation */
190         struct epoint_list *p_epointlist;       /* endpoint relation */
191
192         /* state */
193         int p_state;                            /* state of port */
194         void new_state(int state);              /* set new state */
195         struct caller_info p_callerinfo;        /* information about the caller */
196         struct dialing_info p_dialinginfo;      /* information about dialing */
197         struct connect_info p_connectinfo;      /* information about connected line */
198         struct redir_info p_redirinfo;          /* info on redirection (to the calling user) */
199         struct capa_info p_capainfo;    /* info on l2,l3 capacity */
200         int p_echotest;                         /* set to echo audio data FROM port back to port's mixer */
201
202         /* recording */
203         int open_record(int type, int mode, int skip, char *terminal, int anon_ignore, char *vbox_email, int vbox_email_file);
204         void close_record(int beep);
205         FILE *p_record;                         /* recording fp: if not NULL, recording is enabled */
206         int p_record_type;                      /* codec to use: RECORD_MONO, RECORD_STEREO, ... */
207         int p_record_skip;                      /* skip bytes before writing the sample */
208         unsigned long p_record_length;          /* size of what's written so far */
209         char p_record_filename[256];            /* record filename */
210         int p_record_vbox;                      /* 0= normal recording, 1= announcement, 2= record to vbox dir */
211         int p_record_vbox_year;                 /* time when vbox recording started */
212         int p_record_vbox_mon;
213         int p_record_vbox_mday;
214         int p_record_vbox_hour;
215         int p_record_vbox_min;
216         char p_record_extension[32];            /* current name (digits) of extension */
217         int p_record_anon_ignore;
218         char p_record_vbox_email[128];
219         int p_record_vbox_email_file;
220
221         virtual void printisdn(char *fmt, ...);
222
223         void free_epointlist(struct epoint_list *epointlist);
224         void free_epointid(unsigned long epoint_id);
225         struct epoint_list *epointlist_new(unsigned long epoint_id);
226 };
227
228
229 extern Port *port_first;
230 extern unsigned long port_serial;
231
232 class Port *find_port_with_token(char *name);
233 class Port *find_port_id(unsigned long port_id);
234
235
236 #endif // PORT_HEADER
237
238