backup
[lcr.git] / mISDN.h
1 /*****************************************************************************\
2 **                                                                           **
3 ** PBX4Linux                                                                 **
4 **                                                                           **
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg                                              **
7 **                                                                           **
8 ** mISDN-port header file                                                    **
9 **                                                                           **
10 \*****************************************************************************/ 
11
12
13 #define B_STATE_IDLE            0
14 #define B_STATE_ACTIVATING      1
15 #define B_STATE_ACTIVE          2
16 #define B_STATE_DEACTIVATING    3
17
18
19 extern int entity;
20 extern int mISDNdevice;
21
22 /* mISDN port structure list */
23 struct mISDNport {
24         net_stack_t nst; /* MUST be the first entry, so &nst equals &mISDNlist */
25         manager_t mgr;
26         struct mISDNport *next;
27         struct interface_port *ifport; /* link to interface_port */
28 //      int iftype; /* IF_* */
29 //      int multilink; /* if set, this port will not support callwaiting */
30         int portnum; /* port number */
31         int ptp; /* if ptp is set, we keep track of l2link */
32         int l1link; /* if l1 is available (only works with nt-mode) */
33         int l2link; /* if l2 is available (at PTP we take this serious) */
34 //      time_t l1timeout; /* timout when establishing link */
35         time_t l2establish; /* time until establishing after link failure */
36         int use; /* counts the number of port that uses this port */
37         int ntmode; /* is TRUE if port is nt mode */
38         int pri; /* is TRUE if port is a primary rate interface */
39         int is_tones; /* TRUE if tones are sent outside connect state */
40         int is_earlyb; /* TRUE if tones are received outside connect state */
41         int upper_id; /* id to transfer data down */
42         int lower_id; /* id to transfer data up */
43         int d_stid;
44         int b_num; /* number of bchannels */
45         int b_reserved; /* number of bchannels reserved or in use */
46         class PmISDN *b_port[128]; /* maximum number of ports shall be 128 due to S0 / E1 / special E1 */
47         int b_stid[128];
48         int b_addr[128];
49         int b_state[128]; /* state 0 = IDLE */
50         int procids[128]; /* keep track of free ids */
51         msg_queue_t downqueue;          /* l4->l3 */
52 };
53 extern mISDNport *mISDNport_first;
54
55 /*
56
57    notes on bchannels:
58
59 if a b-channel is in use, the b_port[channel] is linked to the port using it.
60 also each used b-channel counts b_inuse.
61 to assign a bchannel, that is not jet defined due to remote channel assignment,
62 the b_inuse is also increased to reserve channel
63
64 'use' is the number of port instances using this mISDNport. this counts also
65 calls with no bchannel (call waiting, call on hold).
66
67 */
68
69
70 /* mISDN none-object functions */
71 void mISDN_port_info(void);
72 struct mISDNport *mISDNport_open(int port, int ptp);
73 void mISDNport_close_all(void);
74 void mISDNport_close(struct mISDNport *mISDNport);
75 void mISDN_port_reorder(void);
76 int mISDN_handler(void);
77 void enc_ie_cause_standalone(unsigned char **ntmode, msg_t *msg, int location, int cause);
78 void ph_control(unsigned long b_addr, int c1, int c2);
79 void ph_control_block(unsigned long b_addr, int c1, void *c2, int c2_len);
80 msg_t *create_l2msg(int prim, int dinfo, int size);
81 void setup_queue(struct mISDNport *mISDNport, int link);
82 int stack2manager_nt(void *dat, void *arg);
83 int stack2manager_te(struct mISDNport *mISDNport, msg_t *msg);
84
85
86 /* mISDN port classes */
87 class PmISDN : public Port
88 {
89         public:
90         PmISDN(int type, struct mISDNport *mISDNport, char *portname, struct port_settings *settings, int channel);
91         ~PmISDN();
92         void bchannel_receive(iframe_t *frm);
93         int handler(void);
94         void transmit(unsigned char *buffer, int length);
95         int message_epoint(unsigned long epoint_id, int message, union parameter *param);
96         void message_mISDNsignal(unsigned long epoint_id, int message_id, union parameter *param);
97         void message_crypt(unsigned long epoint_id, int message_id, union parameter *param);
98         struct mISDNport *p_m_mISDNport;        /* pointer to port */
99         int p_m_delay;                          /* use delay instead of dejitter */
100         int p_m_txvol, p_m_rxvol;               /* volume shift (0 = no change) */
101         int p_m_echo, p_m_conf;                 /* remote echo, conference number */
102         int p_m_tone;                           /* current kernel space tone */
103         int p_m_rxoff;                          /* rx from driver is disabled */
104         int p_m_nodata;                         /* all parties within a conf are isdn ports, so pure bridging is possible */
105 //      int p_m_txmix;                          /* mix tx with conference */
106 //      int p_m_txmix_on;                       /* delay for turning back on after sending a binary message, must be signed */
107         int p_m_dtmf;                           /* dtmf decoding is enabled */
108
109         int p_m_crypt;                          /* encryption is enabled */
110         int p_m_crypt_msg_loops;                /* sending a message */
111         int p_m_crypt_msg_len;
112         unsigned char p_m_crypt_msg[1100];
113         int p_m_crypt_msg_current;
114         unsigned char p_m_crypt_key[128];
115         int p_m_crypt_key_len;
116         int p_m_crypt_listen;
117         int p_m_crypt_listen_state;
118         int p_m_crypt_listen_len;
119         unsigned char p_m_crypt_listen_msg[1100];
120         unsigned long p_m_crypt_listen_crc;
121         void cryptman_listen_bch(unsigned char *p, int l);
122
123         void set_tone(char *dir, char *name);
124         void set_echotest(int echotest);
125
126         int p_m_portnum;                        /* used port number (1...n) */
127         int p_m_b_index;                        /* index 0,1 0..29 */
128         int p_m_b_channel;                      /* number 1,2 1..15,17... */
129         int p_m_b_exclusive;                    /* if bchannel is exclusive */
130 //      int p_m_b_reserved;                     /* set if channel is reserved */
131         int p_m_b_stid;                         /* current stack id */
132         int p_m_b_addr;                         /* current layer address */
133         long long p_m_jittercheck;              /* time of audio data */
134         long long p_m_jitterdropped;            /* number of bytes dropped */
135         int p_m_delete;                         /* true if obj. must del. */
136         int p_m_hold;                           /* if port is on hold */
137         unsigned long p_m_timeout;              /* timeout of timers */
138         time_t p_m_timer;                       /* start of timer */
139
140         int alloc_bchannel(int channel, int exclusive);
141         void free_bchannel(void);
142 };
143
144 extern unsigned char mISDN_rand[256]; /* noisy randomizer */
145