SIP: Register, STUN and authentication support
[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 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[]);
37         void *p_s_sip_inst;
38         struct lcr_work p_s_delete;
39         nua_handle_t *p_s_handle;
40         nua_magic_t *p_s_magic;
41         struct lcr_timer p_s_invite_option_timer; /* time to send OPTION to invite transaction */
42         int p_s_invite_direction; /* DIRECTION_* of invite */
43         int p_s_rtp_bridge; /* bridge RTP instead of having a local RTP peer */
44         unsigned short p_s_rtp_port_local;
45         unsigned short p_s_rtp_port_remote;
46         unsigned int p_s_rtp_ip_local;
47         unsigned int p_s_rtp_ip_remote;
48         struct sockaddr_in p_s_rtp_sin_local;
49         struct sockaddr_in p_s_rtp_sin_remote;
50         struct sockaddr_in p_s_rtcp_sin_local;
51         struct sockaddr_in p_s_rtcp_sin_remote;
52         struct lcr_fd p_s_rtp_fd;
53         struct lcr_fd p_s_rtcp_fd;
54         int p_s_rtp_is_connected; /* if RTP session is connected, so we may send frames */
55         int p_s_rtp_tx_action;
56         uint16_t p_s_rtp_tx_sequence;
57         uint32_t p_s_rtp_tx_timestamp;
58         uint32_t p_s_rtp_tx_ssrc;
59         struct timeval p_s_rtp_tx_last_tv;
60         int rtp_open(void);
61         int rtp_connect(void);
62         void rtp_close(void);
63         int rtp_send_frame(unsigned char *data, unsigned int len, uint8_t payload_type);
64         int p_s_b_sock; /* SIP bchannel socket */
65         struct lcr_fd p_s_b_fd; /* event node */
66         int p_s_b_index; /* SIP bchannel socket index to use */
67         int p_s_b_active; /* SIP bchannel socket is activated */
68         unsigned char p_s_rxdata[160]; /* receive audio buffer */
69         int p_s_rxpos; /* position in audio buffer 0..159 */
70         int bridge_rx(unsigned char *data, int len);
71         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);
72         void rtp_shutdown(void);
73
74         /* audio */
75         struct lcr_timer p_s_load_timer;        /* timer for audio transmission */
76         virtual void update_load(void);
77         void load_tx(void);
78         unsigned int p_s_next_tv_sec;           /* time stamp of next expected tx_load call, (to sync audio data) */
79         unsigned int p_s_next_tv_usec;
80         void set_tone(const char *dir, const char *name);
81 };
82
83 int sip_init_inst(struct interface *interface);
84 void sip_exit_inst(struct interface *interface);
85 int sip_init(void);
86 void sip_exit(void);
87 void sip_handle(void);