140cb5e5dSvi /*
240cb5e5dSvi  * CDDL HEADER START
340cb5e5dSvi  *
440cb5e5dSvi  * The contents of this file are subject to the terms of the
540cb5e5dSvi  * Common Development and Distribution License (the "License").
640cb5e5dSvi  * You may not use this file except in compliance with the License.
740cb5e5dSvi  *
840cb5e5dSvi  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
940cb5e5dSvi  * or http://www.opensolaris.org/os/licensing.
1040cb5e5dSvi  * See the License for the specific language governing permissions
1140cb5e5dSvi  * and limitations under the License.
1240cb5e5dSvi  *
1340cb5e5dSvi  * When distributing Covered Code, include this CDDL HEADER in each
1440cb5e5dSvi  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1540cb5e5dSvi  * If applicable, add the following below this CDDL HEADER, with the
1640cb5e5dSvi  * fields enclosed by brackets "[]" replaced with your own identifying
1740cb5e5dSvi  * information: Portions Copyright [yyyy] [name of copyright owner]
1840cb5e5dSvi  *
1940cb5e5dSvi  * CDDL HEADER END
2040cb5e5dSvi  */
2140cb5e5dSvi 
2240cb5e5dSvi /*
23*2c2c4183Svi  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
2440cb5e5dSvi  * Use is subject to license terms.
2540cb5e5dSvi  */
2640cb5e5dSvi 
2740cb5e5dSvi #ifndef	_SIP_MISCDEFS_H
2840cb5e5dSvi #define	_SIP_MISCDEFS_H
2940cb5e5dSvi 
3040cb5e5dSvi #pragma ident	"%Z%%M%	%I%	%E% SMI"
3140cb5e5dSvi 
3240cb5e5dSvi #ifdef	__cplusplus
3340cb5e5dSvi extern "C" {
3440cb5e5dSvi #endif
3540cb5e5dSvi 
36*2c2c4183Svi #include <pthread.h>
3740cb5e5dSvi #include <sys/types.h>
38*2c2c4183Svi #include <sys/time.h>
3940cb5e5dSvi 
4040cb5e5dSvi #define	SIP_CR			'\r'
4140cb5e5dSvi #define	SIP_SP			' '
4240cb5e5dSvi #define	SIP_HCOLON		':'
4340cb5e5dSvi #define	SIP_SEMI		';'
4440cb5e5dSvi #define	SIP_COMMA		','
4540cb5e5dSvi #define	SIP_LAQUOT		'<'
4640cb5e5dSvi #define	SIP_RAQUOT		'>'
4740cb5e5dSvi #define	SIP_QUOTE		'"'
4840cb5e5dSvi #define	SIP_EQUAL		'='
4940cb5e5dSvi #define	SIP_SLASH		'/'
5040cb5e5dSvi #define	SIP_PERIOD		'.'
5140cb5e5dSvi #define	SIP_LPAR		'('
5240cb5e5dSvi #define	SIP_RPAR		')'
5340cb5e5dSvi 
5440cb5e5dSvi #define	SIP_BRANCHID_LEN	28	/* incl. the magic cookie */
5540cb5e5dSvi #define	SIP_TAG_LEN		20
5640cb5e5dSvi #define	SIP_URI_LEN		25
5740cb5e5dSvi #define	SIP_DISPLAY_LEN		25
5840cb5e5dSvi #define	SIP_DOMAIN_LEN		25
5940cb5e5dSvi #define	SIP_MAX_FWDLEN		5
6040cb5e5dSvi #define	SIP_TRANSPORT_LEN	5
6140cb5e5dSvi #define	SIP_SIZE_OF_STATUS_CODE	3
6240cb5e5dSvi #define	SIP_SPACE_LEN		sizeof (char)
6340cb5e5dSvi 
6440cb5e5dSvi #define	SIP_MS			1L
6540cb5e5dSvi #define	SIP_SECONDS		(1000 * SIP_MS)
6640cb5e5dSvi #define	SIP_MINUTES		(60 * SIP_SECONDS)
6740cb5e5dSvi #define	SIP_HOURS   		(60 * SIP_MINUTES)
6840cb5e5dSvi 
6940cb5e5dSvi /* timer granularity is in msecs */
7040cb5e5dSvi #define	SIP_TIMER_T1		(1 * SIP_SECONDS)
7140cb5e5dSvi #define	SIP_TIMER_T2		(4 * SIP_SECONDS)
7240cb5e5dSvi #define	SIP_TIMER_T4		(5 * SIP_SECONDS)
7340cb5e5dSvi 
7440cb5e5dSvi #ifdef		__linux__
7540cb5e5dSvi #define		SEC		1
7640cb5e5dSvi #define		MILLISEC	1000
7740cb5e5dSvi #define		MICROSEC	1000000
7840cb5e5dSvi #define		NANOSEC		1000000000
7940cb5e5dSvi 
8040cb5e5dSvi typedef struct timespec	timestruc_t;
8140cb5e5dSvi typedef	long long	hrtime_t;
8240cb5e5dSvi #endif
8340cb5e5dSvi 
8440cb5e5dSvi extern int	sip_timer_T1;
8540cb5e5dSvi extern int	sip_timer_T2;
8640cb5e5dSvi extern int	sip_timer_T4;
8740cb5e5dSvi extern int	sip_timer_TD;
8840cb5e5dSvi 
8940cb5e5dSvi /* Structure for SIP timers */
9040cb5e5dSvi typedef struct sip_timer_s {
9140cb5e5dSvi 	uint_t		sip_timerid;
9240cb5e5dSvi 	struct timeval	sip_timeout_val;
9340cb5e5dSvi }sip_timer_t;
9440cb5e5dSvi 
9540cb5e5dSvi /* time is in msec */
9640cb5e5dSvi #define	SIP_SET_TIMEOUT(timer, time) {					\
9740cb5e5dSvi 	int	mtime = (time);						\
9840cb5e5dSvi 									\
9940cb5e5dSvi 	(timer).sip_timeout_val.tv_sec = mtime / MILLISEC;	\
10040cb5e5dSvi 	mtime -= (timer).sip_timeout_val.tv_sec * MILLISEC;	\
10140cb5e5dSvi 	(timer).sip_timeout_val.tv_usec = mtime * MILLISEC;		\
10240cb5e5dSvi }
10340cb5e5dSvi 
10440cb5e5dSvi /* time is in msec */
10540cb5e5dSvi #define	SIP_INIT_TIMER(timer, time) {				\
10640cb5e5dSvi 	SIP_SET_TIMEOUT(timer, time);				\
10740cb5e5dSvi 	(timer).sip_timerid = 0;				\
10840cb5e5dSvi }
10940cb5e5dSvi 
11040cb5e5dSvi #define	SIP_SCHED_TIMER(timer, obj, func) {			\
11140cb5e5dSvi 	(timer).sip_timerid = sip_stack_timeout((void *)(obj),	\
11240cb5e5dSvi 	    (func), &((timer).sip_timeout_val));			\
11340cb5e5dSvi }
11440cb5e5dSvi 
11540cb5e5dSvi #define	SIP_CANCEL_TIMER(timer) {				\
11640cb5e5dSvi 	if ((timer).sip_timerid != 0) {				\
11740cb5e5dSvi 		sip_stack_untimeout((timer).sip_timerid);	\
11840cb5e5dSvi 		(timer).sip_timerid = 0;			\
11940cb5e5dSvi 	}							\
12040cb5e5dSvi }
12140cb5e5dSvi 
12240cb5e5dSvi /* returned time is in msec */
12340cb5e5dSvi #define	SIP_GET_TIMEOUT(timer)					\
12440cb5e5dSvi 	((timer).sip_timeout_val.tv_sec * MILLISEC +		\
12540cb5e5dSvi 	(timer).sip_timeout_val.tv_usec / MILLISEC)
12640cb5e5dSvi 
12740cb5e5dSvi #define	SIP_IS_TIMER_RUNNING(timer)	((timer).sip_timerid != 0)
12840cb5e5dSvi 
12940cb5e5dSvi /* This is the transaction list */
13040cb5e5dSvi typedef struct sip_conn_cache_s {
13140cb5e5dSvi 	void			*obj;
13240cb5e5dSvi 	struct sip_conn_cache_s	*next;
13340cb5e5dSvi 	struct sip_conn_cache_s	*prev;
13440cb5e5dSvi } sip_conn_cache_t;
13540cb5e5dSvi 
13640cb5e5dSvi /* TCP fragment entry */
13740cb5e5dSvi typedef struct sip_reass_entry_s {
13840cb5e5dSvi 	char		*sip_reass_msg;
13940cb5e5dSvi 	int		sip_reass_msglen;
14040cb5e5dSvi }sip_reass_entry_t;
14140cb5e5dSvi 
14240cb5e5dSvi /* Library data in stored in connection object */
14340cb5e5dSvi typedef struct sip_conn_obj_pvt_s {
14440cb5e5dSvi 	sip_reass_entry_t	*sip_conn_obj_reass;
14540cb5e5dSvi 	pthread_mutex_t		sip_conn_obj_reass_lock;
14640cb5e5dSvi 	sip_conn_cache_t	*sip_conn_obj_cache;
14740cb5e5dSvi 	pthread_mutex_t		sip_conn_obj_cache_lock;
14840cb5e5dSvi } sip_conn_obj_pvt_t;
14940cb5e5dSvi 
15040cb5e5dSvi extern boolean_t sip_manage_dialog;
15140cb5e5dSvi 
15240cb5e5dSvi /* To salt the hash function */
15340cb5e5dSvi extern uint64_t	sip_hash_salt;
15440cb5e5dSvi 
15540cb5e5dSvi extern void		sip_timeout_init();
15640cb5e5dSvi extern uint_t		sip_timeout(void *, void (*)(void *), struct timeval *);
15740cb5e5dSvi extern boolean_t	sip_untimeout(uint_t);
15840cb5e5dSvi extern void		sip_md5_hash(char *, int, char *, int, char *, int,
15940cb5e5dSvi 			    char *, int, char *, int, char *, int, uchar_t *);
16040cb5e5dSvi 
16140cb5e5dSvi #ifdef	__cplusplus
16240cb5e5dSvi }
16340cb5e5dSvi #endif
16440cb5e5dSvi 
16540cb5e5dSvi #endif	/* _SIP_MISCDEFS_H */
166