| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  * Asterisk -- An open source telephony toolkit. | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  * Copyright (C) 1999 - 2005, Digium, Inc. | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2004-10-02 01:56:08 +00:00
										 |  |  |  * Mark Spencer <markster@digium.com> | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  * See http://www.asterisk.org for more information about
 | 
					
						
							|  |  |  |  * the Asterisk project. Please do not directly contact | 
					
						
							|  |  |  |  * any of the maintainers of this project for assistance; | 
					
						
							|  |  |  |  * the project provides a web site, mailing lists and IRC | 
					
						
							|  |  |  |  * channels for your use. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  |  * This program is free software, distributed under the terms of | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  * the GNU General Public License Version 2. See the LICENSE file | 
					
						
							|  |  |  |  * at the top of the source tree. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-26 13:03:17 +00:00
										 |  |  | /*! \file
 | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-10-26 13:03:17 +00:00
										 |  |  |  * \brief Implementation of Inter-Asterisk eXchange Protocol, v 2 | 
					
						
							| 
									
										
										
										
											2005-12-30 21:18:06 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * \author Mark Spencer <markster@digium.com>  | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-07 18:54:56 +00:00
										 |  |  | #include "asterisk.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ASTERISK_FILE_VERSION(__FILE__, "$Revision$") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | #include <sys/socket.h>
 | 
					
						
							|  |  |  | #include <netinet/in.h>
 | 
					
						
							| 
									
										
										
										
											2005-11-10 23:42:45 +00:00
										 |  |  | #include <arpa/inet.h>
 | 
					
						
							| 
									
										
										
										
											2005-06-06 21:09:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-21 06:02:45 +00:00
										 |  |  | #include "asterisk/frame.h"
 | 
					
						
							|  |  |  | #include "asterisk/utils.h"
 | 
					
						
							|  |  |  | #include "asterisk/unaligned.h"
 | 
					
						
							| 
									
										
										
										
											2007-01-16 08:38:59 +00:00
										 |  |  | #include "asterisk/config.h"
 | 
					
						
							| 
									
										
										
										
											2006-07-31 17:27:42 +00:00
										 |  |  | #include "asterisk/lock.h"
 | 
					
						
							| 
									
										
										
										
											2006-08-29 20:50:36 +00:00
										 |  |  | #include "asterisk/threadstorage.h"
 | 
					
						
							| 
									
										
										
										
											2006-07-31 17:27:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | #include "iax2.h"
 | 
					
						
							|  |  |  | #include "iax2-parser.h"
 | 
					
						
							| 
									
										
										
										
											2004-07-07 09:34:01 +00:00
										 |  |  | #include "iax2-provision.h"
 | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-19 18:12:41 +00:00
										 |  |  | static int frames = 0; | 
					
						
							|  |  |  | static int iframes = 0; | 
					
						
							|  |  |  | static int oframes = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-01-04 18:17:24 +00:00
										 |  |  | #if !defined(LOW_MEMORY)
 | 
					
						
							| 
									
										
										
										
											2006-08-29 20:50:36 +00:00
										 |  |  | static void frame_cache_cleanup(void *data); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*! \brief A per-thread cache of iax_frame structures */ | 
					
						
							| 
									
										
										
										
											2006-10-19 01:00:57 +00:00
										 |  |  | AST_THREADSTORAGE_CUSTOM(frame_cache, NULL, frame_cache_cleanup); | 
					
						
							| 
									
										
										
										
											2006-08-29 20:50:36 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /*! \brief This is just so iax_frames, a list head struct for holding a list of
 | 
					
						
							|  |  |  |  *  iax_frame structures, is defined. */ | 
					
						
							| 
									
										
										
										
											2008-07-31 16:50:10 +00:00
										 |  |  | AST_LIST_HEAD_NOLOCK(iax_frame_list, iax_frame); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct iax_frames { | 
					
						
							|  |  |  | 	struct iax_frame_list list; | 
					
						
							|  |  |  | 	size_t size; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define FRAME_CACHE_MAX_SIZE	20
 | 
					
						
							| 
									
										
										
										
											2007-01-04 18:19:55 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2006-08-29 20:50:36 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | static void internaloutput(const char *str) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2004-10-24 06:44:37 +00:00
										 |  |  | 	fputs(str, stdout); | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void internalerror(const char *str) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	fprintf(stderr, "WARNING: %s", str); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void (*outputf)(const char *str) = internaloutput; | 
					
						
							|  |  |  | static void (*errorf)(const char *str) = internalerror; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void dump_addr(char *output, int maxlen, void *value, int len) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct sockaddr_in sin; | 
					
						
							| 
									
										
										
										
											2004-06-13 21:25:10 +00:00
										 |  |  | 	if (len == (int)sizeof(sin)) { | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | 		memcpy(&sin, value, len); | 
					
						
							| 
									
										
										
										
											2006-07-21 17:31:28 +00:00
										 |  |  | 		snprintf(output, maxlen, "IPV4 %s:%d", ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port)); | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2007-10-01 15:23:19 +00:00
										 |  |  | 		ast_copy_string(output, "Invalid Address", maxlen); | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-01 18:16:24 +00:00
										 |  |  | static void dump_string_hex(char *output, int maxlen, void *value, int len) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int i = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	while (len-- && (i + 1) * 4 < maxlen) { | 
					
						
							|  |  |  | 		sprintf(output + (4 * i), "\\x%2.2x", *((unsigned char *)value + i)); | 
					
						
							|  |  |  | 		i++; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | static void dump_string(char *output, int maxlen, void *value, int len) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	maxlen--; | 
					
						
							|  |  |  | 	if (maxlen > len) | 
					
						
							|  |  |  | 		maxlen = len; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:28:30 +00:00
										 |  |  | 	strncpy(output, value, maxlen); | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | 	output[maxlen] = '\0'; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-01-09 10:32:53 +00:00
										 |  |  | static void dump_prefs(char *output, int maxlen, void *value, int len) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ast_codec_pref pref; | 
					
						
							|  |  |  | 	int total_len = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	maxlen--; | 
					
						
							|  |  |  | 	total_len = maxlen; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (maxlen > len) | 
					
						
							|  |  |  | 		maxlen = len; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:28:30 +00:00
										 |  |  | 	strncpy(output, value, maxlen); | 
					
						
							| 
									
										
										
										
											2005-01-09 10:32:53 +00:00
										 |  |  | 	output[maxlen] = '\0'; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	ast_codec_pref_convert(&pref, output, total_len, 0); | 
					
						
							|  |  |  | 	memset(output,0,total_len); | 
					
						
							|  |  |  | 	ast_codec_pref_string(&pref, output, total_len); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | static void dump_int(char *output, int maxlen, void *value, int len) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2004-06-13 21:25:10 +00:00
										 |  |  | 	if (len == (int)sizeof(unsigned int)) | 
					
						
							| 
									
										
										
										
											2005-03-29 04:49:24 +00:00
										 |  |  | 		snprintf(output, maxlen, "%lu", (unsigned long)ntohl(get_unaligned_uint32(value))); | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2005-05-17 19:41:09 +00:00
										 |  |  | 		ast_copy_string(output, "Invalid INT", maxlen);	 | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void dump_short(char *output, int maxlen, void *value, int len) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2004-06-13 21:25:10 +00:00
										 |  |  | 	if (len == (int)sizeof(unsigned short)) | 
					
						
							| 
									
										
										
										
											2005-03-29 04:49:24 +00:00
										 |  |  | 		snprintf(output, maxlen, "%d", ntohs(get_unaligned_uint16(value))); | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2005-05-17 19:41:09 +00:00
										 |  |  | 		ast_copy_string(output, "Invalid SHORT", maxlen); | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void dump_byte(char *output, int maxlen, void *value, int len) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2004-06-13 21:25:10 +00:00
										 |  |  | 	if (len == (int)sizeof(unsigned char)) | 
					
						
							| 
									
										
										
										
											2004-07-07 09:34:01 +00:00
										 |  |  | 		snprintf(output, maxlen, "%d", *((unsigned char *)value)); | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2005-05-17 19:41:09 +00:00
										 |  |  | 		ast_copy_string(output, "Invalid BYTE", maxlen); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void dump_datetime(char *output, int maxlen, void *value, int len) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2007-07-18 19:47:20 +00:00
										 |  |  | 	struct ast_tm tm; | 
					
						
							| 
									
										
										
										
											2005-05-17 19:41:09 +00:00
										 |  |  | 	unsigned long val = (unsigned long) ntohl(get_unaligned_uint32(value)); | 
					
						
							|  |  |  | 	if (len == (int)sizeof(unsigned int)) { | 
					
						
							|  |  |  | 		tm.tm_sec  = (val & 0x1f) << 1; | 
					
						
							|  |  |  | 		tm.tm_min  = (val >> 5) & 0x3f; | 
					
						
							|  |  |  | 		tm.tm_hour = (val >> 11) & 0x1f; | 
					
						
							|  |  |  | 		tm.tm_mday = (val >> 16) & 0x1f; | 
					
						
							|  |  |  | 		tm.tm_mon  = ((val >> 21) & 0x0f) - 1; | 
					
						
							|  |  |  | 		tm.tm_year = ((val >> 25) & 0x7f) + 100; | 
					
						
							| 
									
										
										
										
											2007-07-18 19:47:20 +00:00
										 |  |  | 		ast_strftime(output, maxlen, "%Y-%m-%d  %T", &tm);  | 
					
						
							| 
									
										
										
										
											2005-05-17 19:41:09 +00:00
										 |  |  | 	} else | 
					
						
							|  |  |  | 		ast_copy_string(output, "Invalid DATETIME format!", maxlen); | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-07 09:34:01 +00:00
										 |  |  | static void dump_ipaddr(char *output, int maxlen, void *value, int len) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct sockaddr_in sin; | 
					
						
							|  |  |  | 	if (len == (int)sizeof(unsigned int)) { | 
					
						
							|  |  |  | 		memcpy(&sin.sin_addr, value, len); | 
					
						
							| 
									
										
										
										
											2006-07-21 17:31:28 +00:00
										 |  |  | 		snprintf(output, maxlen, "%s", ast_inet_ntoa(sin.sin_addr)); | 
					
						
							| 
									
										
										
										
											2004-07-07 09:34:01 +00:00
										 |  |  | 	} else | 
					
						
							| 
									
										
										
										
											2005-05-17 19:41:09 +00:00
										 |  |  | 		ast_copy_string(output, "Invalid IPADDR", maxlen); | 
					
						
							| 
									
										
										
										
											2004-07-07 09:34:01 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void dump_prov_flags(char *output, int maxlen, void *value, int len) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	char buf[256] = ""; | 
					
						
							|  |  |  | 	if (len == (int)sizeof(unsigned int)) | 
					
						
							| 
									
										
										
										
											2005-03-29 04:49:24 +00:00
										 |  |  | 		snprintf(output, maxlen, "%lu (%s)", (unsigned long)ntohl(get_unaligned_uint32(value)), | 
					
						
							|  |  |  | 			iax_provflags2str(buf, sizeof(buf), ntohl(get_unaligned_uint32(value)))); | 
					
						
							| 
									
										
										
										
											2004-07-07 09:34:01 +00:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2005-05-17 19:41:09 +00:00
										 |  |  | 		ast_copy_string(output, "Invalid INT", maxlen); | 
					
						
							| 
									
										
										
										
											2004-07-07 09:34:01 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-11-19 21:52:25 +00:00
										 |  |  | static void dump_samprate(char *output, int maxlen, void *value, int len) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	char tmp[256]=""; | 
					
						
							|  |  |  | 	int sr; | 
					
						
							|  |  |  | 	if (len == (int)sizeof(unsigned short)) { | 
					
						
							|  |  |  | 		sr = ntohs(*((unsigned short *)value)); | 
					
						
							|  |  |  | 		if (sr & IAX_RATE_8KHZ) | 
					
						
							|  |  |  | 			strcat(tmp, ",8khz"); | 
					
						
							|  |  |  | 		if (sr & IAX_RATE_11KHZ) | 
					
						
							|  |  |  | 			strcat(tmp, ",11.025khz"); | 
					
						
							|  |  |  | 		if (sr & IAX_RATE_16KHZ) | 
					
						
							|  |  |  | 			strcat(tmp, ",16khz"); | 
					
						
							|  |  |  | 		if (sr & IAX_RATE_22KHZ) | 
					
						
							|  |  |  | 			strcat(tmp, ",22.05khz"); | 
					
						
							|  |  |  | 		if (sr & IAX_RATE_44KHZ) | 
					
						
							|  |  |  | 			strcat(tmp, ",44.1khz"); | 
					
						
							|  |  |  | 		if (sr & IAX_RATE_48KHZ) | 
					
						
							|  |  |  | 			strcat(tmp, ",48khz"); | 
					
						
							|  |  |  | 		if (strlen(tmp)) | 
					
						
							| 
									
										
										
										
											2005-05-17 19:41:09 +00:00
										 |  |  | 			ast_copy_string(output, &tmp[1], maxlen); | 
					
						
							| 
									
										
										
										
											2004-11-19 21:52:25 +00:00
										 |  |  | 		else | 
					
						
							| 
									
										
										
										
											2005-05-17 19:41:09 +00:00
										 |  |  | 			ast_copy_string(output, "None Specified!\n", maxlen); | 
					
						
							| 
									
										
										
										
											2004-11-19 21:52:25 +00:00
										 |  |  | 	} else | 
					
						
							| 
									
										
										
										
											2005-05-17 19:41:09 +00:00
										 |  |  | 		ast_copy_string(output, "Invalid SHORT", maxlen); | 
					
						
							| 
									
										
										
										
											2004-11-19 21:52:25 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-04 14:05:12 +00:00
										 |  |  | static void dump_versioned_codec(char *output, int maxlen, void *value, int len) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	char *version = (char *) value; | 
					
						
							|  |  |  | 	if (version[0] == 0) { | 
					
						
							|  |  |  | 		if (len == (int) (sizeof(format_t) + sizeof(char))) { | 
					
						
							|  |  |  | 			format_t codec = ntohll(get_unaligned_uint64(value + 1)); | 
					
						
							|  |  |  | 			ast_copy_string(output, ast_getformatname(codec), maxlen); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			ast_copy_string(output, "Invalid length!", maxlen); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		ast_copy_string(output, "Unknown version!", maxlen); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-07 09:34:01 +00:00
										 |  |  | static void dump_prov_ies(char *output, int maxlen, unsigned char *iedata, int len); | 
					
						
							|  |  |  | static void dump_prov(char *output, int maxlen, void *value, int len) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	dump_prov_ies(output, maxlen, value, len); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | static struct iax2_ie { | 
					
						
							|  |  |  | 	int ie; | 
					
						
							|  |  |  | 	char *name; | 
					
						
							|  |  |  | 	void (*dump)(char *output, int maxlen, void *value, int len); | 
					
						
							| 
									
										
										
										
											2008-08-09 14:12:34 +00:00
										 |  |  | } infoelts[] = { | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | 	{ IAX_IE_CALLED_NUMBER, "CALLED NUMBER", dump_string }, | 
					
						
							|  |  |  | 	{ IAX_IE_CALLING_NUMBER, "CALLING NUMBER", dump_string }, | 
					
						
							| 
									
										
										
										
											2003-08-31 02:04:42 +00:00
										 |  |  | 	{ IAX_IE_CALLING_ANI, "ANI", dump_string }, | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | 	{ IAX_IE_CALLING_NAME, "CALLING NAME", dump_string }, | 
					
						
							|  |  |  | 	{ IAX_IE_CALLED_CONTEXT, "CALLED CONTEXT", dump_string }, | 
					
						
							|  |  |  | 	{ IAX_IE_USERNAME, "USERNAME", dump_string }, | 
					
						
							|  |  |  | 	{ IAX_IE_PASSWORD, "PASSWORD", dump_string }, | 
					
						
							|  |  |  | 	{ IAX_IE_CAPABILITY, "CAPABILITY", dump_int }, | 
					
						
							| 
									
										
										
										
											2009-11-04 14:05:12 +00:00
										 |  |  | 	{ IAX_IE_CAPABILITY2, "CAPABILITY2", dump_versioned_codec }, | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | 	{ IAX_IE_FORMAT, "FORMAT", dump_int }, | 
					
						
							| 
									
										
										
										
											2009-11-04 14:05:12 +00:00
										 |  |  | 	{ IAX_IE_FORMAT2, "FORMAT2", dump_versioned_codec }, | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | 	{ IAX_IE_LANGUAGE, "LANGUAGE", dump_string }, | 
					
						
							|  |  |  | 	{ IAX_IE_VERSION, "VERSION", dump_short }, | 
					
						
							|  |  |  | 	{ IAX_IE_ADSICPE, "ADSICPE", dump_short }, | 
					
						
							|  |  |  | 	{ IAX_IE_DNID, "DNID", dump_string }, | 
					
						
							|  |  |  | 	{ IAX_IE_AUTHMETHODS, "AUTHMETHODS", dump_short }, | 
					
						
							| 
									
										
										
										
											2008-08-01 18:16:24 +00:00
										 |  |  | 	{ IAX_IE_CHALLENGE, "CHALLENGE", dump_string_hex }, | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | 	{ IAX_IE_MD5_RESULT, "MD5 RESULT", dump_string }, | 
					
						
							|  |  |  | 	{ IAX_IE_RSA_RESULT, "RSA RESULT", dump_string }, | 
					
						
							|  |  |  | 	{ IAX_IE_APPARENT_ADDR, "APPARENT ADDRESS", dump_addr }, | 
					
						
							|  |  |  | 	{ IAX_IE_REFRESH, "REFRESH", dump_short }, | 
					
						
							|  |  |  | 	{ IAX_IE_DPSTATUS, "DIALPLAN STATUS", dump_short }, | 
					
						
							|  |  |  | 	{ IAX_IE_CALLNO, "CALL NUMBER", dump_short }, | 
					
						
							|  |  |  | 	{ IAX_IE_CAUSE, "CAUSE", dump_string }, | 
					
						
							|  |  |  | 	{ IAX_IE_IAX_UNKNOWN, "UNKNOWN IAX CMD", dump_byte }, | 
					
						
							|  |  |  | 	{ IAX_IE_MSGCOUNT, "MESSAGE COUNT", dump_short }, | 
					
						
							|  |  |  | 	{ IAX_IE_AUTOANSWER, "AUTO ANSWER REQ" }, | 
					
						
							| 
									
										
										
										
											2003-03-20 05:56:00 +00:00
										 |  |  | 	{ IAX_IE_TRANSFERID, "TRANSFER ID", dump_int }, | 
					
						
							| 
									
										
										
										
											2003-05-14 05:33:06 +00:00
										 |  |  | 	{ IAX_IE_RDNIS, "REFERRING DNIS", dump_string }, | 
					
						
							| 
									
										
										
										
											2004-07-07 09:34:01 +00:00
										 |  |  | 	{ IAX_IE_PROVISIONING, "PROVISIONING", dump_prov }, | 
					
						
							| 
									
										
										
										
											2004-05-25 04:34:43 +00:00
										 |  |  | 	{ IAX_IE_AESPROVISIONING, "AES PROVISIONG" }, | 
					
						
							| 
									
										
										
										
											2005-05-17 19:41:09 +00:00
										 |  |  | 	{ IAX_IE_DATETIME, "DATE TIME", dump_datetime }, | 
					
						
							| 
									
										
										
										
											2004-02-24 21:27:16 +00:00
										 |  |  | 	{ IAX_IE_DEVICETYPE, "DEVICE TYPE", dump_string }, | 
					
						
							|  |  |  | 	{ IAX_IE_SERVICEIDENT, "SERVICE IDENT", dump_string }, | 
					
						
							|  |  |  | 	{ IAX_IE_FIRMWAREVER, "FIRMWARE VER", dump_short }, | 
					
						
							|  |  |  | 	{ IAX_IE_FWBLOCKDESC, "FW BLOCK DESC", dump_int }, | 
					
						
							|  |  |  | 	{ IAX_IE_FWBLOCKDATA, "FW BLOCK DATA" }, | 
					
						
							| 
									
										
										
										
											2004-05-25 04:34:43 +00:00
										 |  |  | 	{ IAX_IE_PROVVER, "PROVISIONG VER", dump_int }, | 
					
						
							| 
									
										
										
										
											2004-10-02 01:56:08 +00:00
										 |  |  | 	{ IAX_IE_CALLINGPRES, "CALLING PRESNTN", dump_byte }, | 
					
						
							|  |  |  | 	{ IAX_IE_CALLINGTON, "CALLING TYPEOFNUM", dump_byte }, | 
					
						
							|  |  |  | 	{ IAX_IE_CALLINGTNS, "CALLING TRANSITNET", dump_short }, | 
					
						
							| 
									
										
										
										
											2004-11-19 21:52:25 +00:00
										 |  |  | 	{ IAX_IE_SAMPLINGRATE, "SAMPLINGRATE", dump_samprate }, | 
					
						
							| 
									
										
										
										
											2004-12-29 23:02:21 +00:00
										 |  |  | 	{ IAX_IE_CAUSECODE, "CAUSE CODE", dump_byte }, | 
					
						
							|  |  |  | 	{ IAX_IE_ENCRYPTION, "ENCRYPTION", dump_short }, | 
					
						
							|  |  |  | 	{ IAX_IE_ENCKEY, "ENCRYPTION KEY" }, | 
					
						
							| 
									
										
										
										
											2005-01-09 10:32:53 +00:00
										 |  |  | 	{ IAX_IE_CODEC_PREFS, "CODEC_PREFS", dump_prefs }, | 
					
						
							| 
									
										
										
										
											2005-02-12 18:52:14 +00:00
										 |  |  | 	{ IAX_IE_RR_JITTER, "RR_JITTER", dump_int }, | 
					
						
							|  |  |  | 	{ IAX_IE_RR_LOSS, "RR_LOSS", dump_int }, | 
					
						
							|  |  |  | 	{ IAX_IE_RR_PKTS, "RR_PKTS", dump_int }, | 
					
						
							|  |  |  | 	{ IAX_IE_RR_DELAY, "RR_DELAY", dump_short }, | 
					
						
							|  |  |  | 	{ IAX_IE_RR_DROPPED, "RR_DROPPED", dump_int }, | 
					
						
							|  |  |  | 	{ IAX_IE_RR_OOO, "RR_OUTOFORDER", dump_int }, | 
					
						
							| 
									
										
										
										
											2007-01-16 08:38:59 +00:00
										 |  |  | 	{ IAX_IE_VARIABLE, "VARIABLE", dump_string }, | 
					
						
							| 
									
										
										
										
											2007-04-20 21:12:53 +00:00
										 |  |  | 	{ IAX_IE_OSPTOKEN, "OSPTOKEN" }, | 
					
						
							| 
									
										
										
										
											2009-09-03 16:31:54 +00:00
										 |  |  | 	{ IAX_IE_CALLTOKEN, "CALLTOKEN" }, | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-21 21:13:09 +00:00
										 |  |  | static const struct iax2_ie prov_ies[] = { | 
					
						
							| 
									
										
										
										
											2004-07-07 09:34:01 +00:00
										 |  |  | 	{ PROV_IE_USEDHCP, "USEDHCP" }, | 
					
						
							|  |  |  | 	{ PROV_IE_IPADDR, "IPADDR", dump_ipaddr }, | 
					
						
							|  |  |  | 	{ PROV_IE_SUBNET, "SUBNET", dump_ipaddr }, | 
					
						
							|  |  |  | 	{ PROV_IE_GATEWAY, "GATEWAY", dump_ipaddr }, | 
					
						
							|  |  |  | 	{ PROV_IE_PORTNO, "BINDPORT", dump_short }, | 
					
						
							| 
									
										
										
										
											2004-07-31 02:51:40 +00:00
										 |  |  | 	{ PROV_IE_USER, "USERNAME", dump_string }, | 
					
						
							|  |  |  | 	{ PROV_IE_PASS, "PASSWORD", dump_string }, | 
					
						
							| 
									
										
										
										
											2004-07-07 09:34:01 +00:00
										 |  |  | 	{ PROV_IE_LANG, "LANGUAGE", dump_string }, | 
					
						
							|  |  |  | 	{ PROV_IE_TOS, "TYPEOFSERVICE", dump_byte }, | 
					
						
							|  |  |  | 	{ PROV_IE_FLAGS, "FLAGS", dump_prov_flags }, | 
					
						
							|  |  |  | 	{ PROV_IE_FORMAT, "FORMAT", dump_int }, | 
					
						
							|  |  |  | 	{ PROV_IE_AESKEY, "AESKEY" }, | 
					
						
							|  |  |  | 	{ PROV_IE_SERVERIP, "SERVERIP", dump_ipaddr }, | 
					
						
							|  |  |  | 	{ PROV_IE_SERVERPORT, "SERVERPORT", dump_short }, | 
					
						
							|  |  |  | 	{ PROV_IE_NEWAESKEY, "NEWAESKEY" }, | 
					
						
							|  |  |  | 	{ PROV_IE_PROVVER, "PROV VERSION", dump_int }, | 
					
						
							|  |  |  | 	{ PROV_IE_ALTSERVER, "ALTSERVERIP", dump_ipaddr }, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | const char *iax_ie2str(int ie) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int x; | 
					
						
							| 
									
										
										
										
											2008-08-09 14:12:34 +00:00
										 |  |  | 	for (x = 0; x < ARRAY_LEN(infoelts); x++) { | 
					
						
							|  |  |  | 		if (infoelts[x].ie == ie) | 
					
						
							|  |  |  | 			return infoelts[x].name; | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return "Unknown IE"; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-07 09:34:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static void dump_prov_ies(char *output, int maxlen, unsigned char *iedata, int len) | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int ielen; | 
					
						
							|  |  |  | 	int ie; | 
					
						
							|  |  |  | 	int x; | 
					
						
							|  |  |  | 	int found; | 
					
						
							|  |  |  | 	char interp[80]; | 
					
						
							|  |  |  | 	char tmp[256]; | 
					
						
							| 
									
										
										
										
											2004-07-07 09:34:01 +00:00
										 |  |  | 	if (len < 2) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	strcpy(output, "\n");  | 
					
						
							|  |  |  | 	maxlen -= strlen(output); output += strlen(output); | 
					
						
							|  |  |  | 	while(len > 2) { | 
					
						
							|  |  |  | 		ie = iedata[0]; | 
					
						
							|  |  |  | 		ielen = iedata[1]; | 
					
						
							|  |  |  | 		if (ielen + 2> len) { | 
					
						
							|  |  |  | 			snprintf(tmp, (int)sizeof(tmp), "Total Prov IE length of %d bytes exceeds remaining prov frame length of %d bytes\n", ielen + 2, len); | 
					
						
							| 
									
										
										
										
											2005-05-17 19:41:09 +00:00
										 |  |  | 			ast_copy_string(output, tmp, maxlen); | 
					
						
							|  |  |  | 			maxlen -= strlen(output); | 
					
						
							|  |  |  | 			output += strlen(output); | 
					
						
							| 
									
										
										
										
											2004-07-07 09:34:01 +00:00
										 |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		found = 0; | 
					
						
							|  |  |  | 		for (x=0;x<(int)sizeof(prov_ies) / (int)sizeof(prov_ies[0]); x++) { | 
					
						
							|  |  |  | 			if (prov_ies[x].ie == ie) { | 
					
						
							|  |  |  | 				if (prov_ies[x].dump) { | 
					
						
							|  |  |  | 					prov_ies[x].dump(interp, (int)sizeof(interp), iedata + 2, ielen); | 
					
						
							|  |  |  | 					snprintf(tmp, (int)sizeof(tmp), "       %-15.15s : %s\n", prov_ies[x].name, interp); | 
					
						
							| 
									
										
										
										
											2005-10-27 02:42:05 +00:00
										 |  |  | 					ast_copy_string(output, tmp, maxlen); | 
					
						
							| 
									
										
										
										
											2004-07-07 09:34:01 +00:00
										 |  |  | 					maxlen -= strlen(output); output += strlen(output); | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					if (ielen) | 
					
						
							|  |  |  | 						snprintf(interp, (int)sizeof(interp), "%d bytes", ielen); | 
					
						
							|  |  |  | 					else | 
					
						
							|  |  |  | 						strcpy(interp, "Present"); | 
					
						
							|  |  |  | 					snprintf(tmp, (int)sizeof(tmp), "       %-15.15s : %s\n", prov_ies[x].name, interp); | 
					
						
							| 
									
										
										
										
											2005-10-27 02:42:05 +00:00
										 |  |  | 					ast_copy_string(output, tmp, maxlen); | 
					
						
							| 
									
										
										
										
											2004-07-07 09:34:01 +00:00
										 |  |  | 					maxlen -= strlen(output); output += strlen(output); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				found++; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (!found) { | 
					
						
							|  |  |  | 			snprintf(tmp, (int)sizeof(tmp), "       Unknown Prov IE %03d  : Present\n", ie); | 
					
						
							| 
									
										
										
										
											2005-10-27 02:42:05 +00:00
										 |  |  | 			ast_copy_string(output, tmp, maxlen); | 
					
						
							| 
									
										
										
										
											2004-07-07 09:34:01 +00:00
										 |  |  | 			maxlen -= strlen(output); output += strlen(output); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		iedata += (2 + ielen); | 
					
						
							|  |  |  | 		len -= (2 + ielen); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void dump_ies(unsigned char *iedata, int len) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int ielen; | 
					
						
							|  |  |  | 	int ie; | 
					
						
							|  |  |  | 	int x; | 
					
						
							|  |  |  | 	int found; | 
					
						
							|  |  |  | 	char interp[1024]; | 
					
						
							|  |  |  | 	char tmp[1024]; | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | 	if (len < 2) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	while(len > 2) { | 
					
						
							|  |  |  | 		ie = iedata[0]; | 
					
						
							|  |  |  | 		ielen = iedata[1]; | 
					
						
							|  |  |  | 		if (ielen + 2> len) { | 
					
						
							| 
									
										
										
										
											2004-06-13 21:25:10 +00:00
										 |  |  | 			snprintf(tmp, (int)sizeof(tmp), "Total IE length of %d bytes exceeds remaining frame length of %d bytes\n", ielen + 2, len); | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | 			outputf(tmp); | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		found = 0; | 
					
						
							| 
									
										
										
										
											2008-08-09 14:12:34 +00:00
										 |  |  | 		for (x = 0; x < ARRAY_LEN(infoelts); x++) { | 
					
						
							|  |  |  | 			if (infoelts[x].ie == ie) { | 
					
						
							|  |  |  | 				if (infoelts[x].dump) { | 
					
						
							|  |  |  | 					infoelts[x].dump(interp, (int)sizeof(interp), iedata + 2, ielen); | 
					
						
							|  |  |  | 					snprintf(tmp, (int)sizeof(tmp), "   %-15.15s : %s\n", infoelts[x].name, interp); | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | 					outputf(tmp); | 
					
						
							|  |  |  | 				} else { | 
					
						
							| 
									
										
										
										
											2004-02-24 21:27:16 +00:00
										 |  |  | 					if (ielen) | 
					
						
							| 
									
										
										
										
											2004-06-13 21:25:10 +00:00
										 |  |  | 						snprintf(interp, (int)sizeof(interp), "%d bytes", ielen); | 
					
						
							| 
									
										
										
										
											2004-02-24 21:27:16 +00:00
										 |  |  | 					else | 
					
						
							|  |  |  | 						strcpy(interp, "Present"); | 
					
						
							| 
									
										
										
										
											2008-08-09 14:12:34 +00:00
										 |  |  | 					snprintf(tmp, (int)sizeof(tmp), "   %-15.15s : %s\n", infoelts[x].name, interp); | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | 					outputf(tmp); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				found++; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (!found) { | 
					
						
							| 
									
										
										
										
											2004-06-13 21:25:10 +00:00
										 |  |  | 			snprintf(tmp, (int)sizeof(tmp), "   Unknown IE %03d  : Present\n", ie); | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | 			outputf(tmp); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		iedata += (2 + ielen); | 
					
						
							|  |  |  | 		len -= (2 + ielen); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	outputf("\n"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-15 20:52:12 +00:00
										 |  |  | void iax_frame_subclass2str(enum iax_frame_subclass subclass, char *str, size_t len) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	const char *cmd = "Unknown"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* if an error occurs here during compile, that means a new iax frame subclass
 | 
					
						
							|  |  |  | 	 * has been added to the iax_frame_subclass enum.  Add the new subclass to the | 
					
						
							|  |  |  | 	 * switch case and make sure to update it with a new string representation. */ | 
					
						
							|  |  |  | 	switch (subclass) { | 
					
						
							|  |  |  | 	case IAX_COMMAND_NEW: | 
					
						
							|  |  |  | 		cmd = "NEW    "; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case IAX_COMMAND_PING: | 
					
						
							|  |  |  | 		cmd = "PING   "; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case IAX_COMMAND_PONG: | 
					
						
							|  |  |  | 		cmd = "PONG   "; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case IAX_COMMAND_ACK: | 
					
						
							|  |  |  | 		cmd = "ACK    "; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case IAX_COMMAND_HANGUP: | 
					
						
							|  |  |  | 		cmd = "HANGUP "; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case IAX_COMMAND_REJECT: | 
					
						
							|  |  |  | 		cmd = "REJECT "; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case IAX_COMMAND_ACCEPT: | 
					
						
							|  |  |  | 		cmd = "ACCEPT "; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case IAX_COMMAND_AUTHREQ: | 
					
						
							|  |  |  | 		cmd = "AUTHREQ"; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case IAX_COMMAND_AUTHREP: | 
					
						
							|  |  |  | 		cmd = "AUTHREP"; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case IAX_COMMAND_INVAL: | 
					
						
							|  |  |  | 		cmd = "INVAL  "; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case IAX_COMMAND_LAGRQ: | 
					
						
							|  |  |  | 		cmd = "LAGRQ  "; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case IAX_COMMAND_LAGRP: | 
					
						
							|  |  |  | 		cmd = "LAGRP  "; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case IAX_COMMAND_REGREQ: | 
					
						
							|  |  |  | 		cmd = "REGREQ "; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case IAX_COMMAND_REGAUTH: | 
					
						
							|  |  |  | 		cmd = "REGAUTH"; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case IAX_COMMAND_REGACK: | 
					
						
							|  |  |  | 		cmd = "REGACK "; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case IAX_COMMAND_REGREJ: | 
					
						
							|  |  |  | 		cmd = "REGREJ "; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case IAX_COMMAND_REGREL: | 
					
						
							|  |  |  | 		cmd = "REGREL "; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case IAX_COMMAND_VNAK: | 
					
						
							|  |  |  | 		cmd = "VNAK   "; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case IAX_COMMAND_DPREQ: | 
					
						
							|  |  |  | 		cmd = "DPREQ  "; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case IAX_COMMAND_DPREP: | 
					
						
							|  |  |  | 		cmd = "DPREP  "; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case IAX_COMMAND_DIAL: | 
					
						
							|  |  |  | 		cmd = "DIAL   "; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case IAX_COMMAND_TXREQ: | 
					
						
							|  |  |  | 		cmd = "TXREQ  "; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case IAX_COMMAND_TXCNT: | 
					
						
							|  |  |  | 		cmd = "TXCNT  "; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case IAX_COMMAND_TXACC: | 
					
						
							|  |  |  | 		cmd = "TXACC  "; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case IAX_COMMAND_TXREADY: | 
					
						
							|  |  |  | 		cmd = "TXREADY"; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case IAX_COMMAND_TXREL: | 
					
						
							|  |  |  | 		cmd = "TXREL  "; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case IAX_COMMAND_TXREJ: | 
					
						
							|  |  |  | 		cmd = "TXREJ  "; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case IAX_COMMAND_QUELCH: | 
					
						
							|  |  |  | 		cmd = "QUELCH "; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case IAX_COMMAND_UNQUELCH: | 
					
						
							|  |  |  | 		cmd = "UNQULCH"; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case IAX_COMMAND_POKE: | 
					
						
							|  |  |  | 		cmd = "POKE   "; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case IAX_COMMAND_PAGE: | 
					
						
							|  |  |  | 		cmd = "PAGE   "; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case IAX_COMMAND_MWI: | 
					
						
							|  |  |  | 		cmd = "MWI    "; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case IAX_COMMAND_UNSUPPORT: | 
					
						
							|  |  |  | 		cmd = "UNSPRTD"; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case IAX_COMMAND_TRANSFER: | 
					
						
							|  |  |  | 		cmd = "TRANSFR"; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case IAX_COMMAND_PROVISION: | 
					
						
							|  |  |  | 		cmd = "PROVISN"; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case IAX_COMMAND_FWDOWNL: | 
					
						
							|  |  |  | 		cmd = "FWDWNLD"; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case IAX_COMMAND_FWDATA: | 
					
						
							|  |  |  | 		cmd = "FWDATA "; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case IAX_COMMAND_TXMEDIA: | 
					
						
							|  |  |  | 		cmd = "TXMEDIA"; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case IAX_COMMAND_RTKEY: | 
					
						
							|  |  |  | 		cmd = "RTKEY  "; | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2009-09-03 16:31:54 +00:00
										 |  |  | 	case IAX_COMMAND_CALLTOKEN: | 
					
						
							|  |  |  | 		cmd = "CTOKEN "; | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2009-05-15 20:52:12 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	ast_copy_string(str, cmd, len); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-19 18:12:41 +00:00
										 |  |  | void iax_showframe(struct iax_frame *f, struct ast_iax2_full_hdr *fhi, int rx, struct sockaddr_in *sin, int datalen) | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2008-08-09 14:12:34 +00:00
										 |  |  | 	const char *framelist[] = { | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | 		"(0?)", | 
					
						
							| 
									
										
										
										
											2006-08-31 01:59:02 +00:00
										 |  |  | 		"DTMF_E ", | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | 		"VOICE  ", | 
					
						
							|  |  |  | 		"VIDEO  ", | 
					
						
							|  |  |  | 		"CONTROL", | 
					
						
							|  |  |  | 		"NULL   ", | 
					
						
							|  |  |  | 		"IAX    ", | 
					
						
							|  |  |  | 		"TEXT   ", | 
					
						
							| 
									
										
										
										
											2005-02-28 06:06:42 +00:00
										 |  |  | 		"IMAGE  ", | 
					
						
							|  |  |  | 		"HTML   ", | 
					
						
							| 
									
										
										
										
											2006-08-31 01:59:02 +00:00
										 |  |  | 		"CNG    ", | 
					
						
							|  |  |  | 		"MODEM  ", | 
					
						
							|  |  |  | 		"DTMF_B ", | 
					
						
							|  |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2005-08-23 17:38:58 +00:00
										 |  |  | 	const char *cmds[] = { | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | 		"(0?)", | 
					
						
							|  |  |  | 		"HANGUP ", | 
					
						
							|  |  |  | 		"RING   ", | 
					
						
							|  |  |  | 		"RINGING", | 
					
						
							|  |  |  | 		"ANSWER ", | 
					
						
							|  |  |  | 		"BUSY   ", | 
					
						
							| 
									
										
										
										
											2005-09-21 12:47:03 +00:00
										 |  |  | 		"TKOFFHK", | 
					
						
							| 
									
										
										
										
											2006-07-08 02:24:07 +00:00
										 |  |  | 		"OFFHOOK", | 
					
						
							|  |  |  | 		"CONGSTN", | 
					
						
							|  |  |  | 		"FLASH  ", | 
					
						
							|  |  |  | 		"WINK   ", | 
					
						
							|  |  |  | 		"OPTION ", | 
					
						
							|  |  |  | 		"RDKEY  ", | 
					
						
							|  |  |  | 		"RDUNKEY", | 
					
						
							|  |  |  | 		"PROGRES", | 
					
						
							|  |  |  | 		"PROCDNG", | 
					
						
							|  |  |  | 		"HOLD   ", | 
					
						
							|  |  |  | 		"UNHOLD ", | 
					
						
							| 
									
										
										
										
											2009-06-01 21:03:18 +00:00
										 |  |  | 		"VIDUPDT", | 
					
						
							|  |  |  | 		"T38    ", | 
					
						
							|  |  |  | 		"SRCUPDT", | 
					
						
							|  |  |  | 		"TXFER  ", | 
					
						
							|  |  |  | 		"CNLINE ", | 
					
						
							|  |  |  | 		"REDIR  ", | 
					
						
							|  |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | 	struct ast_iax2_full_hdr *fh; | 
					
						
							|  |  |  | 	char retries[20]; | 
					
						
							|  |  |  | 	char class2[20]; | 
					
						
							|  |  |  | 	char subclass2[20]; | 
					
						
							| 
									
										
										
										
											2005-08-23 17:38:58 +00:00
										 |  |  | 	const char *class; | 
					
						
							|  |  |  | 	const char *subclass; | 
					
						
							| 
									
										
										
										
											2005-07-12 14:46:20 +00:00
										 |  |  | 	char *dir; | 
					
						
							| 
									
										
										
										
											2005-08-23 17:38:58 +00:00
										 |  |  | 	char tmp[512]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-07-12 14:46:20 +00:00
										 |  |  | 	switch(rx) { | 
					
						
							|  |  |  | 	case 0: | 
					
						
							|  |  |  | 		dir = "Tx"; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case 2: | 
					
						
							|  |  |  | 		dir = "TE"; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case 3: | 
					
						
							|  |  |  | 		dir = "RD"; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		dir = "Rx"; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | 	if (f) { | 
					
						
							|  |  |  | 		fh = f->data; | 
					
						
							| 
									
										
										
										
											2005-08-23 17:38:58 +00:00
										 |  |  | 		snprintf(retries, sizeof(retries), "%03d", f->retries); | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		fh = fhi; | 
					
						
							|  |  |  | 		if (ntohs(fh->dcallno) & IAX_FLAG_RETRANS) | 
					
						
							|  |  |  | 			strcpy(retries, "Yes"); | 
					
						
							|  |  |  | 		else | 
					
						
							| 
									
										
										
										
											2004-09-09 01:36:01 +00:00
										 |  |  | 			strcpy(retries, " No"); | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	if (!(ntohs(fh->scallno) & IAX_FLAG_FULL)) { | 
					
						
							|  |  |  | 		/* Don't mess with mini-frames */ | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-08-09 14:12:34 +00:00
										 |  |  | 	if (fh->type >= ARRAY_LEN(framelist)) { | 
					
						
							| 
									
										
										
										
											2005-08-23 17:38:58 +00:00
										 |  |  | 		snprintf(class2, sizeof(class2), "(%d?)", fh->type); | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | 		class = class2; | 
					
						
							|  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2008-08-09 14:12:34 +00:00
										 |  |  | 		class = framelist[(int)fh->type]; | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2006-08-31 01:59:02 +00:00
										 |  |  | 	if (fh->type == AST_FRAME_DTMF_BEGIN || fh->type == AST_FRAME_DTMF_END) { | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | 		sprintf(subclass2, "%c", fh->csub); | 
					
						
							|  |  |  | 		subclass = subclass2; | 
					
						
							|  |  |  | 	} else if (fh->type == AST_FRAME_IAX) { | 
					
						
							| 
									
										
										
										
											2009-05-15 20:52:12 +00:00
										 |  |  | 			iax_frame_subclass2str((int)fh->csub, subclass2, sizeof(subclass2)); | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | 			subclass = subclass2; | 
					
						
							|  |  |  | 	} else if (fh->type == AST_FRAME_CONTROL) { | 
					
						
							| 
									
										
										
										
											2008-12-10 01:09:06 +00:00
										 |  |  | 		if (fh->csub >= ARRAY_LEN(cmds)) { | 
					
						
							| 
									
										
										
										
											2005-08-23 17:38:58 +00:00
										 |  |  | 			snprintf(subclass2, sizeof(subclass2), "(%d?)", fh->csub); | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | 			subclass = subclass2; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			subclass = cmds[(int)fh->csub]; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2005-08-23 17:38:58 +00:00
										 |  |  | 		snprintf(subclass2, sizeof(subclass2), "%d", fh->csub); | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | 		subclass = subclass2; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-08-23 17:38:58 +00:00
										 |  |  | 	snprintf(tmp, sizeof(tmp),  | 
					
						
							|  |  |  | 		 "%s-Frame Retry[%s] -- OSeqno: %3.3d ISeqno: %3.3d Type: %s Subclass: %s\n", | 
					
						
							|  |  |  | 		 dir, | 
					
						
							|  |  |  | 		 retries, fh->oseqno, fh->iseqno, class, subclass); | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | 	outputf(tmp); | 
					
						
							| 
									
										
										
										
											2005-08-23 17:38:58 +00:00
										 |  |  | 	snprintf(tmp, sizeof(tmp),  | 
					
						
							|  |  |  | 		 "   Timestamp: %05lums  SCall: %5.5d  DCall: %5.5d [%s:%d]\n", | 
					
						
							|  |  |  | 		 (unsigned long)ntohl(fh->ts), | 
					
						
							|  |  |  | 		 ntohs(fh->scallno) & ~IAX_FLAG_FULL, ntohs(fh->dcallno) & ~IAX_FLAG_RETRANS, | 
					
						
							| 
									
										
										
										
											2006-07-21 17:31:28 +00:00
										 |  |  | 		 ast_inet_ntoa(sin->sin_addr), ntohs(sin->sin_port)); | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | 	outputf(tmp); | 
					
						
							|  |  |  | 	if (fh->type == AST_FRAME_IAX) | 
					
						
							|  |  |  | 		dump_ies(fh->iedata, datalen); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-01 23:05:28 +00:00
										 |  |  | int iax_ie_append_raw(struct iax_ie_data *ied, unsigned char ie, const void *data, int datalen) | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	char tmp[256]; | 
					
						
							| 
									
										
										
										
											2004-06-13 21:25:10 +00:00
										 |  |  | 	if (datalen > ((int)sizeof(ied->buf) - ied->pos)) { | 
					
						
							|  |  |  | 		snprintf(tmp, (int)sizeof(tmp), "Out of space for ie '%s' (%d), need %d have %d\n", iax_ie2str(ie), ie, datalen, (int)sizeof(ied->buf) - ied->pos); | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | 		errorf(tmp); | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	ied->buf[ied->pos++] = ie; | 
					
						
							|  |  |  | 	ied->buf[ied->pos++] = datalen; | 
					
						
							|  |  |  | 	memcpy(ied->buf + ied->pos, data, datalen); | 
					
						
							|  |  |  | 	ied->pos += datalen; | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-01 23:05:28 +00:00
										 |  |  | int iax_ie_append_addr(struct iax_ie_data *ied, unsigned char ie, const struct sockaddr_in *sin) | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-06-13 21:25:10 +00:00
										 |  |  | 	return iax_ie_append_raw(ied, ie, sin, (int)sizeof(struct sockaddr_in)); | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-04 14:05:12 +00:00
										 |  |  | int iax_ie_append_versioned_uint64(struct iax_ie_data *ied, unsigned char ie, unsigned char version, uint64_t value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct _local { | 
					
						
							|  |  |  | 		unsigned char version; | 
					
						
							|  |  |  | 		uint64_t value; | 
					
						
							|  |  |  | 	} __attribute__((packed)) newval = { version, }; | 
					
						
							|  |  |  | 	put_unaligned_uint64(&newval.value, htonll(value)); | 
					
						
							|  |  |  | 	return iax_ie_append_raw(ied, ie, &newval, (int) sizeof(newval)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | int iax_ie_append_int(struct iax_ie_data *ied, unsigned char ie, unsigned int value)  | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	unsigned int newval; | 
					
						
							|  |  |  | 	newval = htonl(value); | 
					
						
							| 
									
										
										
										
											2004-06-13 21:25:10 +00:00
										 |  |  | 	return iax_ie_append_raw(ied, ie, &newval, (int)sizeof(newval)); | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int iax_ie_append_short(struct iax_ie_data *ied, unsigned char ie, unsigned short value)  | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	unsigned short newval; | 
					
						
							|  |  |  | 	newval = htons(value); | 
					
						
							| 
									
										
										
										
											2004-06-13 21:25:10 +00:00
										 |  |  | 	return iax_ie_append_raw(ied, ie, &newval, (int)sizeof(newval)); | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-01 23:05:28 +00:00
										 |  |  | int iax_ie_append_str(struct iax_ie_data *ied, unsigned char ie, const char *str) | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	return iax_ie_append_raw(ied, ie, str, strlen(str)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int iax_ie_append_byte(struct iax_ie_data *ied, unsigned char ie, unsigned char dat) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return iax_ie_append_raw(ied, ie, &dat, 1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int iax_ie_append(struct iax_ie_data *ied, unsigned char ie)  | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return iax_ie_append_raw(ied, ie, NULL, 0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void iax_set_output(void (*func)(const char *)) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	outputf = func; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void iax_set_error(void (*func)(const char *)) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	errorf = func; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2003-03-18 06:00:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-09 01:07:25 +00:00
										 |  |  | int iax_parse_ies(struct iax_ies *ies, unsigned char *data, int datalen) | 
					
						
							| 
									
										
										
										
											2003-03-18 06:00:18 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	/* Parse data into information elements */ | 
					
						
							|  |  |  | 	int len; | 
					
						
							|  |  |  | 	int ie; | 
					
						
							| 
									
										
										
										
											2007-01-16 08:38:59 +00:00
										 |  |  | 	char tmp[256], *tmp2; | 
					
						
							|  |  |  | 	struct ast_variable *var, *var2, *prev; | 
					
						
							| 
									
										
										
										
											2007-04-20 21:12:53 +00:00
										 |  |  | 	unsigned int count; | 
					
						
							| 
									
										
										
										
											2004-06-13 21:25:10 +00:00
										 |  |  | 	memset(ies, 0, (int)sizeof(struct iax_ies)); | 
					
						
							| 
									
										
										
										
											2003-03-18 06:00:18 +00:00
										 |  |  | 	ies->msgcount = -1; | 
					
						
							| 
									
										
										
										
											2004-02-24 21:27:16 +00:00
										 |  |  | 	ies->firmwarever = -1; | 
					
						
							| 
									
										
										
										
											2004-10-02 01:56:08 +00:00
										 |  |  | 	ies->calling_ton = -1; | 
					
						
							|  |  |  | 	ies->calling_tns = -1; | 
					
						
							|  |  |  | 	ies->calling_pres = -1; | 
					
						
							| 
									
										
										
										
											2004-11-19 21:52:25 +00:00
										 |  |  | 	ies->samprate = IAX_RATE_8KHZ; | 
					
						
							| 
									
										
										
										
											2003-03-18 06:00:18 +00:00
										 |  |  | 	while(datalen >= 2) { | 
					
						
							|  |  |  | 		ie = data[0]; | 
					
						
							|  |  |  | 		len = data[1]; | 
					
						
							|  |  |  | 		if (len > datalen - 2) { | 
					
						
							|  |  |  | 			errorf("Information element length exceeds message size\n"); | 
					
						
							|  |  |  | 			return -1; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		switch(ie) { | 
					
						
							|  |  |  | 		case IAX_IE_CALLED_NUMBER: | 
					
						
							| 
									
										
										
										
											2005-09-09 01:07:25 +00:00
										 |  |  | 			ies->called_number = (char *)data + 2; | 
					
						
							| 
									
										
										
										
											2003-03-18 06:00:18 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		case IAX_IE_CALLING_NUMBER: | 
					
						
							| 
									
										
										
										
											2005-09-09 01:07:25 +00:00
										 |  |  | 			ies->calling_number = (char *)data + 2; | 
					
						
							| 
									
										
										
										
											2003-03-18 06:00:18 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		case IAX_IE_CALLING_ANI: | 
					
						
							| 
									
										
										
										
											2005-09-09 01:07:25 +00:00
										 |  |  | 			ies->calling_ani = (char *)data + 2; | 
					
						
							| 
									
										
										
										
											2003-03-18 06:00:18 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		case IAX_IE_CALLING_NAME: | 
					
						
							| 
									
										
										
										
											2005-09-09 01:07:25 +00:00
										 |  |  | 			ies->calling_name = (char *)data + 2; | 
					
						
							| 
									
										
										
										
											2003-03-18 06:00:18 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		case IAX_IE_CALLED_CONTEXT: | 
					
						
							| 
									
										
										
										
											2005-09-09 01:07:25 +00:00
										 |  |  | 			ies->called_context = (char *)data + 2; | 
					
						
							| 
									
										
										
										
											2003-03-18 06:00:18 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		case IAX_IE_USERNAME: | 
					
						
							| 
									
										
										
										
											2005-09-09 01:07:25 +00:00
										 |  |  | 			ies->username = (char *)data + 2; | 
					
						
							| 
									
										
										
										
											2003-03-18 06:00:18 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		case IAX_IE_PASSWORD: | 
					
						
							| 
									
										
										
										
											2005-09-09 01:07:25 +00:00
										 |  |  | 			ies->password = (char *)data + 2; | 
					
						
							| 
									
										
										
										
											2003-03-18 06:00:18 +00:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2005-01-09 10:32:53 +00:00
										 |  |  | 		case IAX_IE_CODEC_PREFS: | 
					
						
							| 
									
										
										
										
											2005-09-09 01:07:25 +00:00
										 |  |  | 			ies->codec_prefs = (char *)data + 2; | 
					
						
							| 
									
										
										
										
											2005-01-09 10:32:53 +00:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2003-03-18 06:00:18 +00:00
										 |  |  | 		case IAX_IE_CAPABILITY: | 
					
						
							| 
									
										
										
										
											2004-06-13 21:25:10 +00:00
										 |  |  | 			if (len != (int)sizeof(unsigned int)) { | 
					
						
							|  |  |  | 				snprintf(tmp, (int)sizeof(tmp), "Expecting capability to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len); | 
					
						
							| 
									
										
										
										
											2003-03-18 06:00:18 +00:00
										 |  |  | 				errorf(tmp); | 
					
						
							| 
									
										
										
										
											2009-11-04 14:05:12 +00:00
										 |  |  | 			} else if (ies->capability == 0) { /* Don't overwrite capability2, if specified */ | 
					
						
							| 
									
										
										
										
											2009-11-09 17:17:29 +00:00
										 |  |  | 				ies->capability = ntohl(get_unaligned_uint32(data + 2)); | 
					
						
							| 
									
										
										
										
											2009-11-04 14:05:12 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case IAX_IE_CAPABILITY2: | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				int version = data[2]; | 
					
						
							|  |  |  | 				if (version == 0) { | 
					
						
							|  |  |  | 					if (len != (int)sizeof(char) + sizeof(format_t)) { | 
					
						
							|  |  |  | 						snprintf(tmp, (int)sizeof(tmp), "Expecting capability to be %d bytes long but was %d\n", (int) (sizeof(format_t) + sizeof(char)), len); | 
					
						
							|  |  |  | 						errorf(tmp); | 
					
						
							|  |  |  | 					} else { | 
					
						
							|  |  |  | 						ies->capability = (format_t) ntohll(get_unaligned_uint64(data + 3)); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} /* else unknown version */ | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2003-03-18 06:00:18 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		case IAX_IE_FORMAT: | 
					
						
							| 
									
										
										
										
											2004-06-13 21:25:10 +00:00
										 |  |  | 			if (len != (int)sizeof(unsigned int)) { | 
					
						
							|  |  |  | 				snprintf(tmp, (int)sizeof(tmp), "Expecting format to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len); | 
					
						
							| 
									
										
										
										
											2003-03-18 06:00:18 +00:00
										 |  |  | 				errorf(tmp); | 
					
						
							| 
									
										
										
										
											2009-11-04 14:05:12 +00:00
										 |  |  | 			} else if (ies->format == 0) { /* Don't overwrite format2, if specified */ | 
					
						
							| 
									
										
										
										
											2005-03-29 04:49:24 +00:00
										 |  |  | 				ies->format = ntohl(get_unaligned_uint32(data + 2)); | 
					
						
							| 
									
										
										
										
											2009-11-04 14:05:12 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case IAX_IE_FORMAT2: | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				int version = data[2]; | 
					
						
							|  |  |  | 				if (version == 0) { | 
					
						
							|  |  |  | 					if (len != (int)sizeof(char) + sizeof(format_t)) { | 
					
						
							|  |  |  | 						snprintf(tmp, (int)sizeof(tmp), "Expecting format to be %d bytes long but was %d\n", (int) (sizeof(format_t) + sizeof(char)), len); | 
					
						
							|  |  |  | 						errorf(tmp); | 
					
						
							|  |  |  | 					} else { | 
					
						
							|  |  |  | 						ies->format = (format_t) ntohll(get_unaligned_uint64(data + 3)); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} /* else unknown version */ | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2003-03-18 06:00:18 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		case IAX_IE_LANGUAGE: | 
					
						
							| 
									
										
										
										
											2005-09-09 01:07:25 +00:00
										 |  |  | 			ies->language = (char *)data + 2; | 
					
						
							| 
									
										
										
										
											2003-03-18 06:00:18 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		case IAX_IE_VERSION: | 
					
						
							| 
									
										
										
										
											2004-06-13 21:25:10 +00:00
										 |  |  | 			if (len != (int)sizeof(unsigned short)) { | 
					
						
							|  |  |  | 				snprintf(tmp, (int)sizeof(tmp),  "Expecting version to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len); | 
					
						
							| 
									
										
										
										
											2003-03-18 06:00:18 +00:00
										 |  |  | 				errorf(tmp); | 
					
						
							|  |  |  | 			} else | 
					
						
							| 
									
										
										
										
											2005-03-29 04:49:24 +00:00
										 |  |  | 				ies->version = ntohs(get_unaligned_uint16(data + 2)); | 
					
						
							| 
									
										
										
										
											2003-03-18 06:00:18 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		case IAX_IE_ADSICPE: | 
					
						
							| 
									
										
										
										
											2004-06-13 21:25:10 +00:00
										 |  |  | 			if (len != (int)sizeof(unsigned short)) { | 
					
						
							|  |  |  | 				snprintf(tmp, (int)sizeof(tmp), "Expecting adsicpe to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len); | 
					
						
							| 
									
										
										
										
											2003-03-18 06:00:18 +00:00
										 |  |  | 				errorf(tmp); | 
					
						
							|  |  |  | 			} else | 
					
						
							| 
									
										
										
										
											2005-03-29 04:49:24 +00:00
										 |  |  | 				ies->adsicpe = ntohs(get_unaligned_uint16(data + 2)); | 
					
						
							| 
									
										
										
										
											2003-03-18 06:00:18 +00:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2004-11-19 21:52:25 +00:00
										 |  |  | 		case IAX_IE_SAMPLINGRATE: | 
					
						
							|  |  |  | 			if (len != (int)sizeof(unsigned short)) { | 
					
						
							|  |  |  | 				snprintf(tmp, (int)sizeof(tmp), "Expecting samplingrate to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len); | 
					
						
							|  |  |  | 				errorf(tmp); | 
					
						
							|  |  |  | 			} else | 
					
						
							| 
									
										
										
										
											2005-03-29 04:49:24 +00:00
										 |  |  | 				ies->samprate = ntohs(get_unaligned_uint16(data + 2)); | 
					
						
							| 
									
										
										
										
											2004-11-19 21:52:25 +00:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2003-03-18 06:00:18 +00:00
										 |  |  | 		case IAX_IE_DNID: | 
					
						
							| 
									
										
										
										
											2005-09-09 01:07:25 +00:00
										 |  |  | 			ies->dnid = (char *)data + 2; | 
					
						
							| 
									
										
										
										
											2003-03-18 06:00:18 +00:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2003-05-14 05:33:06 +00:00
										 |  |  | 		case IAX_IE_RDNIS: | 
					
						
							| 
									
										
										
										
											2005-09-09 01:07:25 +00:00
										 |  |  | 			ies->rdnis = (char *)data + 2; | 
					
						
							| 
									
										
										
										
											2003-05-14 05:33:06 +00:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2003-03-18 06:00:18 +00:00
										 |  |  | 		case IAX_IE_AUTHMETHODS: | 
					
						
							| 
									
										
										
										
											2004-06-13 21:25:10 +00:00
										 |  |  | 			if (len != (int)sizeof(unsigned short))  { | 
					
						
							|  |  |  | 				snprintf(tmp, (int)sizeof(tmp), "Expecting authmethods to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len); | 
					
						
							| 
									
										
										
										
											2003-03-18 06:00:18 +00:00
										 |  |  | 				errorf(tmp); | 
					
						
							|  |  |  | 			} else | 
					
						
							| 
									
										
										
										
											2005-03-29 04:49:24 +00:00
										 |  |  | 				ies->authmethods = ntohs(get_unaligned_uint16(data + 2)); | 
					
						
							| 
									
										
										
										
											2003-03-18 06:00:18 +00:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2004-12-29 23:02:21 +00:00
										 |  |  | 		case IAX_IE_ENCRYPTION: | 
					
						
							|  |  |  | 			if (len != (int)sizeof(unsigned short))  { | 
					
						
							|  |  |  | 				snprintf(tmp, (int)sizeof(tmp), "Expecting encryption to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len); | 
					
						
							|  |  |  | 				errorf(tmp); | 
					
						
							|  |  |  | 			} else | 
					
						
							| 
									
										
										
										
											2005-03-29 04:49:24 +00:00
										 |  |  | 				ies->encmethods = ntohs(get_unaligned_uint16(data + 2)); | 
					
						
							| 
									
										
										
										
											2004-12-29 23:02:21 +00:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2003-03-18 06:00:18 +00:00
										 |  |  | 		case IAX_IE_CHALLENGE: | 
					
						
							| 
									
										
										
										
											2005-09-09 01:07:25 +00:00
										 |  |  | 			ies->challenge = (char *)data + 2; | 
					
						
							| 
									
										
										
										
											2003-03-18 06:00:18 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		case IAX_IE_MD5_RESULT: | 
					
						
							| 
									
										
										
										
											2005-09-09 01:07:25 +00:00
										 |  |  | 			ies->md5_result = (char *)data + 2; | 
					
						
							| 
									
										
										
										
											2003-03-18 06:00:18 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		case IAX_IE_RSA_RESULT: | 
					
						
							| 
									
										
										
										
											2005-09-09 01:07:25 +00:00
										 |  |  | 			ies->rsa_result = (char *)data + 2; | 
					
						
							| 
									
										
										
										
											2003-03-18 06:00:18 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		case IAX_IE_APPARENT_ADDR: | 
					
						
							|  |  |  | 			ies->apparent_addr = ((struct sockaddr_in *)(data + 2)); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case IAX_IE_REFRESH: | 
					
						
							| 
									
										
										
										
											2004-06-13 21:25:10 +00:00
										 |  |  | 			if (len != (int)sizeof(unsigned short)) { | 
					
						
							|  |  |  | 				snprintf(tmp, (int)sizeof(tmp),  "Expecting refresh to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len); | 
					
						
							| 
									
										
										
										
											2003-03-18 06:00:18 +00:00
										 |  |  | 				errorf(tmp); | 
					
						
							|  |  |  | 			} else | 
					
						
							| 
									
										
										
										
											2005-03-29 04:49:24 +00:00
										 |  |  | 				ies->refresh = ntohs(get_unaligned_uint16(data + 2)); | 
					
						
							| 
									
										
										
										
											2003-03-18 06:00:18 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		case IAX_IE_DPSTATUS: | 
					
						
							| 
									
										
										
										
											2004-06-13 21:25:10 +00:00
										 |  |  | 			if (len != (int)sizeof(unsigned short)) { | 
					
						
							|  |  |  | 				snprintf(tmp, (int)sizeof(tmp),  "Expecting dpstatus to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len); | 
					
						
							| 
									
										
										
										
											2003-03-18 06:00:18 +00:00
										 |  |  | 				errorf(tmp); | 
					
						
							|  |  |  | 			} else | 
					
						
							| 
									
										
										
										
											2005-03-29 04:49:24 +00:00
										 |  |  | 				ies->dpstatus = ntohs(get_unaligned_uint16(data + 2)); | 
					
						
							| 
									
										
										
										
											2003-03-18 06:00:18 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		case IAX_IE_CALLNO: | 
					
						
							| 
									
										
										
										
											2004-06-13 21:25:10 +00:00
										 |  |  | 			if (len != (int)sizeof(unsigned short)) { | 
					
						
							|  |  |  | 				snprintf(tmp, (int)sizeof(tmp),  "Expecting callno to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len); | 
					
						
							| 
									
										
										
										
											2003-03-18 06:00:18 +00:00
										 |  |  | 				errorf(tmp); | 
					
						
							|  |  |  | 			} else | 
					
						
							| 
									
										
										
										
											2005-03-29 04:49:24 +00:00
										 |  |  | 				ies->callno = ntohs(get_unaligned_uint16(data + 2)); | 
					
						
							| 
									
										
										
										
											2003-03-18 06:00:18 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		case IAX_IE_CAUSE: | 
					
						
							| 
									
										
										
										
											2005-09-09 01:07:25 +00:00
										 |  |  | 			ies->cause = (char *)data + 2; | 
					
						
							| 
									
										
										
										
											2003-03-18 06:00:18 +00:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2004-12-26 22:33:25 +00:00
										 |  |  | 		case IAX_IE_CAUSECODE: | 
					
						
							|  |  |  | 			if (len != 1) { | 
					
						
							|  |  |  | 				snprintf(tmp, (int)sizeof(tmp), "Expecting causecode to be single byte but was %d\n", len); | 
					
						
							|  |  |  | 				errorf(tmp); | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				ies->causecode = data[2]; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2003-03-18 06:00:18 +00:00
										 |  |  | 		case IAX_IE_IAX_UNKNOWN: | 
					
						
							|  |  |  | 			if (len == 1) | 
					
						
							|  |  |  | 				ies->iax_unknown = data[2]; | 
					
						
							|  |  |  | 			else { | 
					
						
							| 
									
										
										
										
											2004-06-13 21:25:10 +00:00
										 |  |  | 				snprintf(tmp, (int)sizeof(tmp), "Expected single byte Unknown command, but was %d long\n", len); | 
					
						
							| 
									
										
										
										
											2003-03-18 06:00:18 +00:00
										 |  |  | 				errorf(tmp); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case IAX_IE_MSGCOUNT: | 
					
						
							| 
									
										
										
										
											2004-06-13 21:25:10 +00:00
										 |  |  | 			if (len != (int)sizeof(unsigned short)) { | 
					
						
							|  |  |  | 				snprintf(tmp, (int)sizeof(tmp), "Expecting msgcount to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len); | 
					
						
							| 
									
										
										
										
											2003-03-18 06:00:18 +00:00
										 |  |  | 				errorf(tmp); | 
					
						
							|  |  |  | 			} else | 
					
						
							| 
									
										
										
										
											2005-03-29 04:49:24 +00:00
										 |  |  | 				ies->msgcount = ntohs(get_unaligned_uint16(data + 2));	 | 
					
						
							| 
									
										
										
										
											2003-03-18 06:00:18 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		case IAX_IE_AUTOANSWER: | 
					
						
							|  |  |  | 			ies->autoanswer = 1; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case IAX_IE_MUSICONHOLD: | 
					
						
							|  |  |  | 			ies->musiconhold = 1; | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2003-03-20 05:56:00 +00:00
										 |  |  | 		case IAX_IE_TRANSFERID: | 
					
						
							| 
									
										
										
										
											2004-06-13 21:25:10 +00:00
										 |  |  | 			if (len != (int)sizeof(unsigned int)) { | 
					
						
							|  |  |  | 				snprintf(tmp, (int)sizeof(tmp), "Expecting transferid to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len); | 
					
						
							| 
									
										
										
										
											2003-03-20 05:56:00 +00:00
										 |  |  | 				errorf(tmp); | 
					
						
							|  |  |  | 			} else | 
					
						
							| 
									
										
										
										
											2005-03-29 04:49:24 +00:00
										 |  |  | 				ies->transferid = ntohl(get_unaligned_uint32(data + 2)); | 
					
						
							| 
									
										
										
										
											2003-03-20 05:56:00 +00:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2003-10-01 22:59:06 +00:00
										 |  |  | 		case IAX_IE_DATETIME: | 
					
						
							| 
									
										
										
										
											2004-06-13 21:25:10 +00:00
										 |  |  | 			if (len != (int)sizeof(unsigned int)) { | 
					
						
							|  |  |  | 				snprintf(tmp, (int)sizeof(tmp), "Expecting date/time to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len); | 
					
						
							| 
									
										
										
										
											2003-10-01 22:59:06 +00:00
										 |  |  | 				errorf(tmp); | 
					
						
							|  |  |  | 			} else | 
					
						
							| 
									
										
										
										
											2005-03-29 04:49:24 +00:00
										 |  |  | 				ies->datetime = ntohl(get_unaligned_uint32(data + 2)); | 
					
						
							| 
									
										
										
										
											2003-10-01 22:59:06 +00:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2004-02-24 21:27:16 +00:00
										 |  |  | 		case IAX_IE_FIRMWAREVER: | 
					
						
							| 
									
										
										
										
											2004-06-13 21:25:10 +00:00
										 |  |  | 			if (len != (int)sizeof(unsigned short)) { | 
					
						
							|  |  |  | 				snprintf(tmp, (int)sizeof(tmp), "Expecting firmwarever to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len); | 
					
						
							| 
									
										
										
										
											2004-02-24 21:27:16 +00:00
										 |  |  | 				errorf(tmp); | 
					
						
							|  |  |  | 			} else | 
					
						
							| 
									
										
										
										
											2005-03-29 04:49:24 +00:00
										 |  |  | 				ies->firmwarever = ntohs(get_unaligned_uint16(data + 2));	 | 
					
						
							| 
									
										
										
										
											2004-02-24 21:27:16 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		case IAX_IE_DEVICETYPE: | 
					
						
							| 
									
										
										
										
											2005-09-09 01:07:25 +00:00
										 |  |  | 			ies->devicetype = (char *)data + 2; | 
					
						
							| 
									
										
										
										
											2004-02-24 21:27:16 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		case IAX_IE_SERVICEIDENT: | 
					
						
							| 
									
										
										
										
											2005-09-09 01:07:25 +00:00
										 |  |  | 			ies->serviceident = (char *)data + 2; | 
					
						
							| 
									
										
										
										
											2004-02-24 21:27:16 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		case IAX_IE_FWBLOCKDESC: | 
					
						
							| 
									
										
										
										
											2004-06-13 21:25:10 +00:00
										 |  |  | 			if (len != (int)sizeof(unsigned int)) { | 
					
						
							|  |  |  | 				snprintf(tmp, (int)sizeof(tmp), "Expected block desc to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len); | 
					
						
							| 
									
										
										
										
											2004-02-24 21:27:16 +00:00
										 |  |  | 				errorf(tmp); | 
					
						
							|  |  |  | 			} else | 
					
						
							| 
									
										
										
										
											2005-03-29 04:49:24 +00:00
										 |  |  | 				ies->fwdesc = ntohl(get_unaligned_uint32(data + 2)); | 
					
						
							| 
									
										
										
										
											2004-02-24 21:27:16 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		case IAX_IE_FWBLOCKDATA: | 
					
						
							| 
									
										
										
										
											2005-09-09 01:07:25 +00:00
										 |  |  | 			ies->fwdata = data + 2; | 
					
						
							| 
									
										
										
										
											2004-02-24 21:27:16 +00:00
										 |  |  | 			ies->fwdatalen = len; | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2004-12-29 23:02:21 +00:00
										 |  |  | 		case IAX_IE_ENCKEY: | 
					
						
							| 
									
										
										
										
											2005-09-09 01:07:25 +00:00
										 |  |  | 			ies->enckey = data + 2; | 
					
						
							| 
									
										
										
										
											2004-12-29 23:02:21 +00:00
										 |  |  | 			ies->enckeylen = len; | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2004-05-25 04:34:43 +00:00
										 |  |  | 		case IAX_IE_PROVVER: | 
					
						
							| 
									
										
										
										
											2004-06-13 21:25:10 +00:00
										 |  |  | 			if (len != (int)sizeof(unsigned int)) { | 
					
						
							|  |  |  | 				snprintf(tmp, (int)sizeof(tmp), "Expected provisioning version to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len); | 
					
						
							| 
									
										
										
										
											2004-05-25 04:34:43 +00:00
										 |  |  | 				errorf(tmp); | 
					
						
							| 
									
										
										
										
											2004-07-07 09:34:01 +00:00
										 |  |  | 			} else { | 
					
						
							|  |  |  | 				ies->provverpres = 1; | 
					
						
							| 
									
										
										
										
											2005-03-29 04:49:24 +00:00
										 |  |  | 				ies->provver = ntohl(get_unaligned_uint32(data + 2)); | 
					
						
							| 
									
										
										
										
											2004-07-07 09:34:01 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2004-05-25 04:34:43 +00:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2004-10-02 01:56:08 +00:00
										 |  |  | 		case IAX_IE_CALLINGPRES: | 
					
						
							|  |  |  | 			if (len == 1) | 
					
						
							|  |  |  | 				ies->calling_pres = data[2]; | 
					
						
							|  |  |  | 			else { | 
					
						
							|  |  |  | 				snprintf(tmp, (int)sizeof(tmp), "Expected single byte callingpres, but was %d long\n", len); | 
					
						
							|  |  |  | 				errorf(tmp); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case IAX_IE_CALLINGTON: | 
					
						
							|  |  |  | 			if (len == 1) | 
					
						
							|  |  |  | 				ies->calling_ton = data[2]; | 
					
						
							|  |  |  | 			else { | 
					
						
							|  |  |  | 				snprintf(tmp, (int)sizeof(tmp), "Expected single byte callington, but was %d long\n", len); | 
					
						
							|  |  |  | 				errorf(tmp); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case IAX_IE_CALLINGTNS: | 
					
						
							|  |  |  | 			if (len != (int)sizeof(unsigned short)) { | 
					
						
							|  |  |  | 				snprintf(tmp, (int)sizeof(tmp), "Expecting callingtns to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len); | 
					
						
							|  |  |  | 				errorf(tmp); | 
					
						
							|  |  |  | 			} else | 
					
						
							| 
									
										
										
										
											2005-03-29 04:49:24 +00:00
										 |  |  | 				ies->calling_tns = ntohs(get_unaligned_uint16(data + 2));	 | 
					
						
							| 
									
										
										
										
											2004-10-02 01:56:08 +00:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2005-02-12 18:52:14 +00:00
										 |  |  |                case IAX_IE_RR_JITTER: | 
					
						
							|  |  |  |                        if (len != (int)sizeof(unsigned int)) { | 
					
						
							|  |  |  |                                snprintf(tmp, (int)sizeof(tmp), "Expected jitter rr to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len); | 
					
						
							|  |  |  |                                errorf(tmp); | 
					
						
							|  |  |  |                        } else { | 
					
						
							| 
									
										
										
										
											2005-03-29 04:49:24 +00:00
										 |  |  |                                ies->rr_jitter = ntohl(get_unaligned_uint32(data + 2)); | 
					
						
							| 
									
										
										
										
											2005-02-12 18:52:14 +00:00
										 |  |  |                        } | 
					
						
							|  |  |  |                        break; | 
					
						
							|  |  |  |                case IAX_IE_RR_LOSS: | 
					
						
							|  |  |  |                        if (len != (int)sizeof(unsigned int)) { | 
					
						
							|  |  |  |                                snprintf(tmp, (int)sizeof(tmp), "Expected loss rr to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len); | 
					
						
							|  |  |  |                                errorf(tmp); | 
					
						
							|  |  |  |                        } else { | 
					
						
							| 
									
										
										
										
											2005-03-29 04:49:24 +00:00
										 |  |  |                                ies->rr_loss = ntohl(get_unaligned_uint32(data + 2)); | 
					
						
							| 
									
										
										
										
											2005-02-12 18:52:14 +00:00
										 |  |  |                        } | 
					
						
							|  |  |  |                        break; | 
					
						
							|  |  |  |                case IAX_IE_RR_PKTS: | 
					
						
							|  |  |  |                        if (len != (int)sizeof(unsigned int)) { | 
					
						
							|  |  |  |                                snprintf(tmp, (int)sizeof(tmp), "Expected packets rr to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len); | 
					
						
							|  |  |  |                                errorf(tmp); | 
					
						
							|  |  |  |                        } else { | 
					
						
							| 
									
										
										
										
											2005-03-29 04:49:24 +00:00
										 |  |  |                                ies->rr_pkts = ntohl(get_unaligned_uint32(data + 2)); | 
					
						
							| 
									
										
										
										
											2005-02-12 18:52:14 +00:00
										 |  |  |                        } | 
					
						
							|  |  |  |                        break; | 
					
						
							|  |  |  |                case IAX_IE_RR_DELAY: | 
					
						
							|  |  |  |                        if (len != (int)sizeof(unsigned short)) { | 
					
						
							|  |  |  |                                snprintf(tmp, (int)sizeof(tmp), "Expected loss rr to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len); | 
					
						
							|  |  |  |                         errorf(tmp); | 
					
						
							|  |  |  |                        } else { | 
					
						
							| 
									
										
										
										
											2005-03-29 04:49:24 +00:00
										 |  |  |                                ies->rr_delay = ntohs(get_unaligned_uint16(data + 2)); | 
					
						
							| 
									
										
										
										
											2005-02-12 18:52:14 +00:00
										 |  |  |                        } | 
					
						
							|  |  |  |                        break; | 
					
						
							|  |  |  | 		case IAX_IE_RR_DROPPED: | 
					
						
							|  |  |  | 			if (len != (int)sizeof(unsigned int)) { | 
					
						
							|  |  |  | 				snprintf(tmp, (int)sizeof(tmp), "Expected packets rr to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len); | 
					
						
							|  |  |  | 				errorf(tmp); | 
					
						
							|  |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2005-03-29 04:49:24 +00:00
										 |  |  | 				ies->rr_dropped = ntohl(get_unaligned_uint32(data + 2)); | 
					
						
							| 
									
										
										
										
											2005-02-12 18:52:14 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case IAX_IE_RR_OOO: | 
					
						
							|  |  |  | 			if (len != (int)sizeof(unsigned int)) { | 
					
						
							|  |  |  | 				snprintf(tmp, (int)sizeof(tmp), "Expected packets rr to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len); | 
					
						
							|  |  |  | 				errorf(tmp); | 
					
						
							|  |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2005-03-29 04:49:24 +00:00
										 |  |  | 				ies->rr_ooo = ntohl(get_unaligned_uint32(data + 2)); | 
					
						
							| 
									
										
										
										
											2005-02-12 18:52:14 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2007-01-16 08:38:59 +00:00
										 |  |  | 		case IAX_IE_VARIABLE: | 
					
						
							|  |  |  | 			ast_copy_string(tmp, (char *)data + 2, len + 1); | 
					
						
							|  |  |  | 			tmp2 = strchr(tmp, '='); | 
					
						
							|  |  |  | 			if (tmp2) | 
					
						
							|  |  |  | 				*tmp2++ = '\0'; | 
					
						
							|  |  |  | 			else | 
					
						
							|  |  |  | 				tmp2 = ""; | 
					
						
							| 
									
										
										
										
											2008-09-13 13:54:15 +00:00
										 |  |  | 			{ | 
					
						
							|  |  |  | 				struct ast_str *str = ast_str_create(16); | 
					
						
							|  |  |  | 				/* Existing variable or new variable? */ | 
					
						
							|  |  |  | 				for (var2 = ies->vars, prev = NULL; var2; prev = var2, var2 = var2->next) { | 
					
						
							|  |  |  | 					if (strcmp(tmp, var2->name) == 0) { | 
					
						
							|  |  |  | 						ast_str_set(&str, 0, "%s%s", var2->value, tmp2); | 
					
						
							| 
									
										
										
										
											2008-12-13 08:36:35 +00:00
										 |  |  | 						var = ast_variable_new(tmp, ast_str_buffer(str), var2->file); | 
					
						
							| 
									
										
										
										
											2008-09-13 13:54:15 +00:00
										 |  |  | 						var->next = var2->next; | 
					
						
							|  |  |  | 						if (prev) { | 
					
						
							|  |  |  | 							prev->next = var; | 
					
						
							|  |  |  | 						} else { | 
					
						
							|  |  |  | 							ies->vars = var; | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 						snprintf(tmp, sizeof(tmp), "Assigned (%p)%s to (%p)%s\n", var->name, var->name, var->value, var->value); | 
					
						
							| 
									
										
										
										
											2010-01-28 20:00:09 +00:00
										 |  |  | 						outputf(tmp); | 
					
						
							| 
									
										
										
										
											2008-09-13 13:54:15 +00:00
										 |  |  | 						ast_free(var2); | 
					
						
							|  |  |  | 						break; | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2007-01-16 08:38:59 +00:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2008-09-13 13:54:15 +00:00
										 |  |  | 				ast_free(str); | 
					
						
							| 
									
										
										
										
											2007-01-16 08:38:59 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2008-09-13 13:54:15 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-01-16 08:38:59 +00:00
										 |  |  | 			if (!var2) { | 
					
						
							| 
									
										
										
										
											2007-08-29 20:55:40 +00:00
										 |  |  | 				var = ast_variable_new(tmp, tmp2, ""); | 
					
						
							| 
									
										
										
										
											2008-09-13 13:54:15 +00:00
										 |  |  | 				snprintf(tmp, sizeof(tmp), "Assigned (%p)%s to (%p)%s\n", var->name, var->name, var->value, var->value); | 
					
						
							| 
									
										
										
										
											2010-01-28 20:00:09 +00:00
										 |  |  | 				outputf(tmp); | 
					
						
							| 
									
										
										
										
											2007-01-16 08:38:59 +00:00
										 |  |  | 				var->next = ies->vars; | 
					
						
							|  |  |  | 				ies->vars = var; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2007-04-20 21:12:53 +00:00
										 |  |  | 		case IAX_IE_OSPTOKEN: | 
					
						
							|  |  |  | 			if ((count = data[2]) < IAX_MAX_OSPBLOCK_NUM) { | 
					
						
							|  |  |  | 				ies->osptokenblock[count] = (char *)data + 2 + 1; | 
					
						
							|  |  |  | 				ies->ospblocklength[count] = len - 1; | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				snprintf(tmp, (int)sizeof(tmp), "Expected OSP token block index to be 0~%d but was %d\n", IAX_MAX_OSPBLOCK_NUM - 1, count); | 
					
						
							|  |  |  | 				errorf(tmp); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2009-09-03 16:31:54 +00:00
										 |  |  | 		case IAX_IE_CALLTOKEN: | 
					
						
							|  |  |  | 			if (len) { | 
					
						
							|  |  |  | 				ies->calltokendata = (unsigned char *) data + 2; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			ies->calltoken = 1; | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2003-03-18 06:00:18 +00:00
										 |  |  | 		default: | 
					
						
							| 
									
										
										
										
											2004-06-13 21:25:10 +00:00
										 |  |  | 			snprintf(tmp, (int)sizeof(tmp), "Ignoring unknown information element '%s' (%d) of length %d\n", iax_ie2str(ie), ie, len); | 
					
						
							| 
									
										
										
										
											2004-05-25 15:16:45 +00:00
										 |  |  | 			outputf(tmp); | 
					
						
							| 
									
										
										
										
											2003-03-18 06:00:18 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		/* Overwrite information element with 0, to null terminate previous portion */ | 
					
						
							|  |  |  | 		data[0] = 0; | 
					
						
							|  |  |  | 		datalen -= (len + 2); | 
					
						
							|  |  |  | 		data += (len + 2); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	/* Null-terminate last field */ | 
					
						
							|  |  |  | 	*data = '\0'; | 
					
						
							|  |  |  | 	if (datalen) { | 
					
						
							|  |  |  | 		errorf("Invalid information element contents, strange boundary\n"); | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-19 18:12:41 +00:00
										 |  |  | void iax_frame_wrap(struct iax_frame *fr, struct ast_frame *f) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	fr->af.frametype = f->frametype; | 
					
						
							| 
									
										
										
										
											2009-11-04 14:05:12 +00:00
										 |  |  | 	fr->af.subclass.codec = f->subclass.codec; | 
					
						
							| 
									
										
										
										
											2003-04-19 18:12:41 +00:00
										 |  |  | 	fr->af.mallocd = 0;				/* Our frame is static relative to the container */ | 
					
						
							|  |  |  | 	fr->af.datalen = f->datalen; | 
					
						
							|  |  |  | 	fr->af.samples = f->samples; | 
					
						
							|  |  |  | 	fr->af.offset = AST_FRIENDLY_OFFSET; | 
					
						
							|  |  |  | 	fr->af.src = f->src; | 
					
						
							| 
									
										
										
										
											2004-04-22 19:16:52 +00:00
										 |  |  | 	fr->af.delivery.tv_sec = 0; | 
					
						
							|  |  |  | 	fr->af.delivery.tv_usec = 0; | 
					
						
							| 
									
										
										
										
											2008-05-22 16:29:54 +00:00
										 |  |  | 	fr->af.data.ptr = fr->afdata; | 
					
						
							| 
									
										
										
										
											2007-03-20 20:44:58 +00:00
										 |  |  | 	fr->af.len = f->len; | 
					
						
							| 
									
										
										
										
											2005-04-03 22:57:18 +00:00
										 |  |  | 	if (fr->af.datalen) { | 
					
						
							| 
									
										
										
										
											2007-07-17 20:49:09 +00:00
										 |  |  | 		size_t copy_len = fr->af.datalen; | 
					
						
							|  |  |  | 		if (copy_len > fr->afdatalen) { | 
					
						
							|  |  |  | 			ast_log(LOG_ERROR, "Losing frame data because destination buffer size '%d' bytes not big enough for '%d' bytes in the frame\n", | 
					
						
							|  |  |  | 				(int) fr->afdatalen, (int) fr->af.datalen); | 
					
						
							|  |  |  | 			copy_len = fr->afdatalen; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2005-04-03 22:57:18 +00:00
										 |  |  | #if __BYTE_ORDER == __LITTLE_ENDIAN
 | 
					
						
							|  |  |  | 		/* We need to byte-swap slinear samples from network byte order */ | 
					
						
							| 
									
										
										
										
											2009-11-04 14:05:12 +00:00
										 |  |  | 		if ((fr->af.frametype == AST_FRAME_VOICE) && (fr->af.subclass.codec == AST_FORMAT_SLINEAR)) { | 
					
						
							| 
									
										
										
										
											2007-07-17 20:49:09 +00:00
										 |  |  | 			/* 2 bytes / sample for SLINEAR */ | 
					
						
							| 
									
										
										
										
											2008-05-22 16:29:54 +00:00
										 |  |  | 			ast_swapcopy_samples(fr->af.data.ptr, f->data.ptr, copy_len / 2); | 
					
						
							| 
									
										
										
										
											2005-04-03 22:57:18 +00:00
										 |  |  | 		} else | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2008-05-22 16:29:54 +00:00
										 |  |  | 			memcpy(fr->af.data.ptr, f->data.ptr, copy_len); | 
					
						
							| 
									
										
										
										
											2005-04-03 22:57:18 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-04-19 18:12:41 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-01-04 18:32:23 +00:00
										 |  |  | struct iax_frame *iax_frame_new(int direction, int datalen, unsigned int cacheable) | 
					
						
							| 
									
										
										
										
											2003-04-19 18:12:41 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2006-08-29 20:50:36 +00:00
										 |  |  | 	struct iax_frame *fr = NULL; | 
					
						
							| 
									
										
										
										
											2007-01-04 18:17:24 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #if !defined(LOW_MEMORY)
 | 
					
						
							| 
									
										
										
										
											2007-09-06 21:01:10 +00:00
										 |  |  | 	struct iax_frames *iax_frames = NULL; | 
					
						
							| 
									
										
										
										
											2008-07-31 19:39:25 +00:00
										 |  |  | 	struct iax_frame *smallest = NULL; | 
					
						
							| 
									
										
										
										
											2006-08-29 20:50:36 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Attempt to get a frame from this thread's cache */ | 
					
						
							|  |  |  | 	if ((iax_frames = ast_threadstorage_get(&frame_cache, sizeof(*iax_frames)))) { | 
					
						
							| 
									
										
										
										
											2008-07-31 19:03:41 +00:00
										 |  |  | 		smallest = AST_LIST_FIRST(&iax_frames->list); | 
					
						
							| 
									
										
										
										
											2008-07-31 16:50:10 +00:00
										 |  |  | 		AST_LIST_TRAVERSE_SAFE_BEGIN(&iax_frames->list, fr, list) { | 
					
						
							| 
									
										
										
										
											2007-07-17 20:49:09 +00:00
										 |  |  | 			if (fr->afdatalen >= datalen) { | 
					
						
							|  |  |  | 				size_t afdatalen = fr->afdatalen; | 
					
						
							| 
									
										
										
										
											2007-11-08 05:28:47 +00:00
										 |  |  | 				AST_LIST_REMOVE_CURRENT(list); | 
					
						
							| 
									
										
										
										
											2008-07-31 16:50:10 +00:00
										 |  |  | 				iax_frames->size--; | 
					
						
							| 
									
										
										
										
											2006-08-29 20:50:36 +00:00
										 |  |  | 				memset(fr, 0, sizeof(*fr)); | 
					
						
							| 
									
										
										
										
											2007-07-17 20:49:09 +00:00
										 |  |  | 				fr->afdatalen = afdatalen; | 
					
						
							| 
									
										
										
										
											2006-08-29 20:50:36 +00:00
										 |  |  | 				break; | 
					
						
							| 
									
										
										
										
											2008-07-31 19:03:41 +00:00
										 |  |  | 			} else if (smallest->afdatalen > fr->afdatalen) { | 
					
						
							|  |  |  | 				smallest = fr; | 
					
						
							| 
									
										
										
										
											2006-08-29 20:50:36 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2007-11-08 05:28:47 +00:00
										 |  |  | 		AST_LIST_TRAVERSE_SAFE_END; | 
					
						
							| 
									
										
										
										
											2006-08-29 20:50:36 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	if (!fr) { | 
					
						
							| 
									
										
										
										
											2008-07-31 19:03:41 +00:00
										 |  |  | 		if (iax_frames->size >= FRAME_CACHE_MAX_SIZE && smallest) { | 
					
						
							|  |  |  | 			/* Make useless cache into something more useful */ | 
					
						
							|  |  |  | 			AST_LIST_REMOVE(&iax_frames->list, smallest, list); | 
					
						
							|  |  |  | 			if (!(fr = ast_realloc(smallest, sizeof(*fr) + datalen))) { | 
					
						
							|  |  |  | 				AST_LIST_INSERT_TAIL(&iax_frames->list, smallest, list); | 
					
						
							|  |  |  | 				return NULL; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} else if (!(fr = ast_calloc_cache(1, sizeof(*fr) + datalen))) | 
					
						
							| 
									
										
										
										
											2006-08-29 20:50:36 +00:00
										 |  |  | 			return NULL; | 
					
						
							| 
									
										
										
										
											2007-07-17 20:49:09 +00:00
										 |  |  | 		fr->afdatalen = datalen; | 
					
						
							| 
									
										
										
										
											2003-04-19 18:12:41 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-01-04 21:59:06 +00:00
										 |  |  | #else
 | 
					
						
							|  |  |  | 	if (!(fr = ast_calloc(1, sizeof(*fr) + datalen))) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2007-07-17 20:49:09 +00:00
										 |  |  | 	fr->afdatalen = datalen; | 
					
						
							| 
									
										
										
										
											2007-01-04 21:59:06 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-29 20:50:36 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	fr->direction = direction; | 
					
						
							|  |  |  | 	fr->retrans = -1; | 
					
						
							| 
									
										
										
										
											2007-01-04 18:32:23 +00:00
										 |  |  | 	fr->cacheable = cacheable; | 
					
						
							| 
									
										
										
										
											2006-08-29 20:50:36 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	if (fr->direction == DIRECTION_INGRESS) | 
					
						
							|  |  |  | 		ast_atomic_fetchadd_int(&iframes, 1); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		ast_atomic_fetchadd_int(&oframes, 1); | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2007-01-04 21:06:35 +00:00
										 |  |  | 	ast_atomic_fetchadd_int(&frames, 1); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-19 18:12:41 +00:00
										 |  |  | 	return fr; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-31 21:50:07 +00:00
										 |  |  | void iax_frame_free(struct iax_frame *fr) | 
					
						
							| 
									
										
										
										
											2003-04-19 18:12:41 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2007-01-04 18:17:24 +00:00
										 |  |  | #if !defined(LOW_MEMORY)
 | 
					
						
							| 
									
										
										
										
											2007-09-06 21:01:10 +00:00
										 |  |  | 	struct iax_frames *iax_frames = NULL; | 
					
						
							| 
									
										
										
										
											2007-01-04 18:17:24 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2006-08-29 20:50:36 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-19 18:12:41 +00:00
										 |  |  | 	/* Note: does not remove from scheduler! */ | 
					
						
							|  |  |  | 	if (fr->direction == DIRECTION_INGRESS) | 
					
						
							| 
									
										
										
										
											2006-07-31 17:27:42 +00:00
										 |  |  | 		ast_atomic_fetchadd_int(&iframes, -1); | 
					
						
							| 
									
										
										
										
											2003-04-19 18:12:41 +00:00
										 |  |  | 	else if (fr->direction == DIRECTION_OUTGRESS) | 
					
						
							| 
									
										
										
										
											2006-07-31 17:27:42 +00:00
										 |  |  | 		ast_atomic_fetchadd_int(&oframes, -1); | 
					
						
							| 
									
										
										
										
											2003-04-19 18:12:41 +00:00
										 |  |  | 	else { | 
					
						
							|  |  |  | 		errorf("Attempt to double free frame detected\n"); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2006-07-31 17:27:42 +00:00
										 |  |  | 	ast_atomic_fetchadd_int(&frames, -1); | 
					
						
							| 
									
										
										
										
											2006-08-29 20:50:36 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-01-04 18:17:24 +00:00
										 |  |  | #if !defined(LOW_MEMORY)
 | 
					
						
							| 
									
										
										
										
											2007-01-04 18:32:23 +00:00
										 |  |  | 	if (!fr->cacheable || !(iax_frames = ast_threadstorage_get(&frame_cache, sizeof(*iax_frames)))) { | 
					
						
							| 
									
										
										
										
											2007-06-06 21:20:11 +00:00
										 |  |  | 		ast_free(fr); | 
					
						
							| 
									
										
										
										
											2006-08-29 20:50:36 +00:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-31 16:50:10 +00:00
										 |  |  | 	if (iax_frames->size < FRAME_CACHE_MAX_SIZE) { | 
					
						
							|  |  |  | 		fr->direction = 0; | 
					
						
							| 
									
										
										
										
											2008-07-31 19:03:41 +00:00
										 |  |  | 		/* Pseudo-sort: keep smaller frames at the top of the list. This should
 | 
					
						
							|  |  |  | 		 * increase the chance that we pick the smallest applicable frame for use. */ | 
					
						
							|  |  |  | 		if (AST_LIST_FIRST(&iax_frames->list) && AST_LIST_FIRST(&iax_frames->list)->afdatalen < fr->afdatalen) { | 
					
						
							|  |  |  | 			AST_LIST_INSERT_TAIL(&iax_frames->list, fr, list); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			AST_LIST_INSERT_HEAD(&iax_frames->list, fr, list); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2008-07-31 16:50:10 +00:00
										 |  |  | 		iax_frames->size++; | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-01-04 18:17:24 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2008-07-31 16:50:10 +00:00
										 |  |  | 	ast_free(fr); | 
					
						
							| 
									
										
										
										
											2006-08-29 20:50:36 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-01-04 18:17:24 +00:00
										 |  |  | #if !defined(LOW_MEMORY)
 | 
					
						
							| 
									
										
										
										
											2006-08-29 20:50:36 +00:00
										 |  |  | static void frame_cache_cleanup(void *data) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2008-08-09 14:12:34 +00:00
										 |  |  | 	struct iax_frames *framelist = data; | 
					
						
							|  |  |  | 	struct iax_frame *current; | 
					
						
							| 
									
										
										
										
											2006-08-29 20:50:36 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-09 14:12:34 +00:00
										 |  |  | 	while ((current = AST_LIST_REMOVE_HEAD(&framelist->list, list))) | 
					
						
							|  |  |  | 		ast_free(current); | 
					
						
							| 
									
										
										
										
											2006-08-29 20:50:36 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-09 14:12:34 +00:00
										 |  |  | 	ast_free(framelist); | 
					
						
							| 
									
										
										
										
											2006-08-29 20:50:36 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2007-01-04 18:17:24 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2006-08-29 20:50:36 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-19 18:12:41 +00:00
										 |  |  | int iax_get_frames(void) { return frames; } | 
					
						
							|  |  |  | int iax_get_iframes(void) { return iframes; } | 
					
						
							|  |  |  | int iax_get_oframes(void) { return oframes; } |