some sip fixes
[lcr.git] / sip.h
1 /*****************************************************************************\
2 **                                                                           **
3 ** Linux Call Router                                                         **
4 **                                                                           **
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg                                              **
7 **                                                                           **
8 ** SIP-port header file                                                      **
9 **                                                                           **
10 \*****************************************************************************/ 
11
12 #include <sofia-sip/nua.h>
13
14 extern int any_sip_interface;
15
16 /* SIP port class */
17 class Psip : public Port
18 {
19         public:
20         Psip(int type, char *portname, struct port_settings *settings, struct interface *interface);
21         ~Psip();
22         unsigned int get_local_ip(unsigned int ip);
23         int message_epoint(unsigned int epoint_id, int message, union parameter *param);
24         int message_connect(unsigned int epoint_id, int message, union parameter *param);
25         int message_release(unsigned int epoint_id, int message, union parameter *param);
26         int message_setup(unsigned int epoint_id, int message, union parameter *param);
27         int message_notify(unsigned int epoint_id, int message, union parameter *param);
28         int message_information(unsigned int epoint_id, int message, union parameter *param);
29         int message_dtmf(unsigned int epoint_id, int message, union parameter *param);
30         void i_invite(int status, char const *phrase, nua_t *nua, nua_magic_t *magic, nua_handle_t *nh, nua_hmagic_t *hmagic, sip_t const *sip, tagi_t tags[]);
31         void i_bye(int status, char const *phrase, nua_t *nua, nua_magic_t *magic, nua_handle_t *nh, nua_hmagic_t *hmagic, sip_t const *sip, tagi_t tags[]);
32         void i_cancel(int status, char const *phrase, nua_t *nua, nua_magic_t *magic, nua_handle_t *nh, nua_hmagic_t *hmagic, sip_t const *sip, tagi_t tags[]);
33         void r_bye(int status, char const *phrase, nua_t *nua, nua_magic_t *magic, nua_handle_t *nh, nua_hmagic_t *hmagic, sip_t const *sip, tagi_t tags[]);
34         void r_cancel(int status, char const *phrase, nua_t *nua, nua_magic_t *magic, nua_handle_t *nh, nua_hmagic_t *hmagic, sip_t const *sip, tagi_t tags[]);
35         void r_invite(int status, char const *phrase, nua_t *nua, nua_magic_t *magic, nua_handle_t *nh, nua_hmagic_t *hmagic, sip_t const *sip, tagi_t tags[]);
36         void i_options(int status, char const *phrase, nua_t *nua, nua_magic_t *magic, nua_handle_t *nh, nua_hmagic_t *hmagic, sip_t const *sip, tagi_t tags[]);
37         void r_options(int status, char const *phrase, nua_t *nua, nua_magic_t *magic, nua_handle_t *nh, nua_hmagic_t *hmagic, sip_t const *sip, tagi_t tags[]);
38         void i_state(int status, char const *phrase, nua_t *nua, nua_magic_t *magic, nua_handle_t *nh, nua_hmagic_t *hmagic, sip_t const *sip, tagi_t tags[]);
39         void *p_s_sip_inst;
40         struct lcr_work p_s_delete;
41         nua_handle_t *p_s_handle;
42         nua_magic_t *p_s_magic;
43         struct lcr_timer p_s_invite_option_timer; /* time to send OPTION to invite transaction */
44         int p_s_invite_direction; /* DIRECTION_* of invite */
45         int p_s_rtp_bridge; /* bridge RTP instead of having a local RTP peer */
46         unsigned short p_s_rtp_port_local;
47         unsigned short p_s_rtp_port_remote;
48         unsigned int p_s_rtp_ip_local;
49         unsigned int p_s_rtp_ip_remote;
50         struct sockaddr_in p_s_rtp_sin_local;
51         struct sockaddr_in p_s_rtp_sin_remote;
52         struct sockaddr_in p_s_rtcp_sin_local;
53         struct sockaddr_in p_s_rtcp_sin_remote;
54         struct lcr_fd p_s_rtp_fd;
55         struct lcr_fd p_s_rtcp_fd;
56         int p_s_rtp_is_connected; /* if RTP session is connected, so we may send frames */
57         int p_s_rtp_tx_action;
58         uint16_t p_s_rtp_tx_sequence;
59         uint32_t p_s_rtp_tx_timestamp;
60         uint32_t p_s_rtp_tx_ssrc;
61         struct timeval p_s_rtp_tx_last_tv;
62         int rtp_open(void);
63         int rtp_connect(void);
64         void rtp_close(void);
65         int rtp_send_frame(unsigned char *data, unsigned int len, uint8_t payload_type);
66         int p_s_b_sock; /* SIP bchannel socket */
67         struct lcr_fd p_s_b_fd; /* event node */
68         int p_s_b_index; /* SIP bchannel socket index to use */
69         int p_s_b_active; /* SIP bchannel socket is activated */
70         unsigned char p_s_rxdata[160]; /* receive audio buffer */
71         int p_s_rxpos; /* position in audio buffer 0..159 */
72         int bridge_rx(unsigned char *data, int len);
73         const char *generate_sdp(unsigned int rtp_ip_local, unsigned short rtp_port_local, int payloads, unsigned char *payload_types, int *media_types);
74         int parse_sdp(sip_t const *sip, unsigned int *ip, unsigned short *port, uint8_t *payload_types, int *media_types, int *payloads, int max_payloads);
75         void rtp_shutdown(void);
76
77         /* audio */
78         struct lcr_timer p_s_load_timer;        /* timer for audio transmission */
79         virtual void update_load(void);
80         void load_tx(void);
81         unsigned int p_s_next_tv_sec;           /* time stamp of next expected tx_load call, (to sync audio data) */
82         unsigned int p_s_next_tv_usec;
83         void set_tone(const char *dir, const char *name);
84 };
85
86 int sip_init_inst(struct interface *interface);
87 void sip_exit_inst(struct interface *interface);
88 int sip_init(void);
89 void sip_exit(void);
90 void sip_handle(void);