Mon Oct 8 12:39:28 2012

Asterisk developer's documentation


res_timing_dahdi.c File Reference

DAHDI timing interface. More...

#include "asterisk.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <math.h>
#include <dahdi/user.h>
#include "asterisk/module.h"
#include "asterisk/timing.h"
#include "asterisk/utils.h"

Go to the source code of this file.

Defines

#define SEE_TIMING   "For more information on Asterisk timing modules, including ways to potentially fix this problem, please see https://wiki.asterisk.org/wiki/display/AST/Timing+Interfaces\n"

Functions

static void __reg_module (void)
static void __unreg_module (void)
 ASTERISK_FILE_VERSION (__FILE__,"$Revision: 349194 $")
static int dahdi_test_timer (void)
static void dahdi_timer_ack (int handle, unsigned int quantity)
static void dahdi_timer_close (int handle)
static int dahdi_timer_disable_continuous (int handle)
static int dahdi_timer_enable_continuous (int handle)
static enum ast_timer_event dahdi_timer_get_event (int handle)
static unsigned int dahdi_timer_get_max_rate (int handle)
static int dahdi_timer_open (void)
static int dahdi_timer_set_rate (int handle, unsigned int rate)
static int load_module (void)
static int unload_module (void)

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "DAHDI Timing Interface" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_TIMING, }
static struct ast_module_infoast_module_info = &__mod_info
static struct ast_timing_interface dahdi_timing
static void * timing_funcs_handle


Detailed Description

DAHDI timing interface.

Author:
Russell Bryant <russell@digium.com>

Definition in file res_timing_dahdi.c.


Define Documentation

#define SEE_TIMING   "For more information on Asterisk timing modules, including ways to potentially fix this problem, please see https://wiki.asterisk.org/wiki/display/AST/Timing+Interfaces\n"

Definition at line 141 of file res_timing_dahdi.c.

Referenced by dahdi_test_timer().


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 207 of file res_timing_dahdi.c.

static void __unreg_module ( void   )  [static]

Definition at line 207 of file res_timing_dahdi.c.

ASTERISK_FILE_VERSION ( __FILE__  ,
"$Revision: 349194 $"   
)

static int dahdi_test_timer ( void   )  [static]

Definition at line 143 of file res_timing_dahdi.c.

References ast_log(), ast_wait_for_input(), LOG_ERROR, and SEE_TIMING.

Referenced by load_module().

00144 {
00145    int fd;
00146    int x = 160;
00147    
00148    fd = open("/dev/dahdi/timer", O_RDWR);
00149 
00150    if (fd < 0) {
00151       return -1;
00152    }
00153 
00154    if (ioctl(fd, DAHDI_TIMERCONFIG, &x)) {
00155       ast_log(LOG_ERROR, "You have DAHDI built and drivers loaded, but the DAHDI timer test failed to set DAHDI_TIMERCONFIG to %d.\n" SEE_TIMING, x);
00156       close(fd);
00157       return -1;
00158    }
00159 
00160    if ((x = ast_wait_for_input(fd, 300)) < 0) {
00161       ast_log(LOG_ERROR, "You have DAHDI built and drivers loaded, but the DAHDI timer could not be polled during the DAHDI timer test.\n" SEE_TIMING);
00162       close(fd);
00163       return -1;
00164    }
00165 
00166    if (!x) {
00167       const char dahdi_timer_error[] = {
00168          "Asterisk has detected a problem with your DAHDI configuration and will shutdown for your protection.  You have options:"
00169          "\n\t1. You only have to compile DAHDI support into Asterisk if you need it.  One option is to recompile without DAHDI support."
00170          "\n\t2. You only have to load DAHDI drivers if you want to take advantage of DAHDI services.  One option is to unload DAHDI modules if you don't need them."
00171          "\n\t3. If you need DAHDI services, you must correctly configure DAHDI."
00172       };
00173       ast_log(LOG_ERROR, "%s\n" SEE_TIMING, dahdi_timer_error);
00174       usleep(100);
00175       close(fd);
00176       return -1;
00177    }
00178 
00179    close(fd);
00180 
00181    return 0;
00182 }

static void dahdi_timer_ack ( int  handle,
unsigned int  quantity 
) [static]

Definition at line 97 of file res_timing_dahdi.c.

00098 {
00099    ioctl(handle, DAHDI_TIMERACK, &quantity);
00100 }

static void dahdi_timer_close ( int  handle  )  [static]

Definition at line 75 of file res_timing_dahdi.c.

00076 {
00077    close(handle);
00078 }

static int dahdi_timer_disable_continuous ( int  handle  )  [static]

Definition at line 109 of file res_timing_dahdi.c.

00110 {
00111    int flags = -1;
00112 
00113    return ioctl(handle, DAHDI_TIMERPONG, &flags) ? -1 : 0;
00114 }

static int dahdi_timer_enable_continuous ( int  handle  )  [static]

Definition at line 102 of file res_timing_dahdi.c.

00103 {
00104    int flags = 1;
00105 
00106    return ioctl(handle, DAHDI_TIMERPING, &flags) ? -1 : 0;
00107 }

static enum ast_timer_event dahdi_timer_get_event ( int  handle  )  [static]

Definition at line 116 of file res_timing_dahdi.c.

References AST_TIMING_EVENT_CONTINUOUS, and AST_TIMING_EVENT_EXPIRED.

00117 {
00118    int res;
00119    int event;
00120 
00121    res = ioctl(handle, DAHDI_GETEVENT, &event);
00122 
00123    if (res) {
00124       event = DAHDI_EVENT_TIMER_EXPIRED;
00125    }
00126 
00127    switch (event) {
00128    case DAHDI_EVENT_TIMER_PING:
00129       return AST_TIMING_EVENT_CONTINUOUS;
00130    case DAHDI_EVENT_TIMER_EXPIRED:
00131    default:
00132       return AST_TIMING_EVENT_EXPIRED; 
00133    }
00134 }

static unsigned int dahdi_timer_get_max_rate ( int  handle  )  [static]

Definition at line 136 of file res_timing_dahdi.c.

00137 {
00138    return 1000;
00139 }

static int dahdi_timer_open ( void   )  [static]

Definition at line 70 of file res_timing_dahdi.c.

00071 {
00072    return open("/dev/dahdi/timer", O_RDWR);
00073 }

static int dahdi_timer_set_rate ( int  handle,
unsigned int  rate 
) [static]

Definition at line 80 of file res_timing_dahdi.c.

References ast_log(), and LOG_ERROR.

00081 {
00082    int samples;
00083 
00084    /* DAHDI timers are configured using a number of samples,
00085     * based on an 8 kHz sample rate. */
00086    samples = (unsigned int) roundf((8000.0 / ((float) rate)));
00087 
00088    if (ioctl(handle, DAHDI_TIMERCONFIG, &samples)) {
00089       ast_log(LOG_ERROR, "Failed to configure DAHDI timing fd for %u sample timer ticks\n",
00090          samples);
00091       return -1;
00092    }
00093 
00094    return 0;
00095 }

static int load_module ( void   )  [static]

Definition at line 184 of file res_timing_dahdi.c.

References AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, ast_register_timing_interface, dahdi_test_timer(), dahdi_timing, and timing_funcs_handle.

static int unload_module ( void   )  [static]

Definition at line 194 of file res_timing_dahdi.c.

References ast_unregister_timing_interface(), and timing_funcs_handle.

00195 {
00196    if (timing_funcs_handle) {
00197       return ast_unregister_timing_interface(timing_funcs_handle);
00198    }
00199 
00200    return 0;
00201 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "DAHDI Timing Interface" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_TIMING, } [static]

Definition at line 207 of file res_timing_dahdi.c.

struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 207 of file res_timing_dahdi.c.

struct ast_timing_interface dahdi_timing [static]

Definition at line 57 of file res_timing_dahdi.c.

Referenced by load_module().

void* timing_funcs_handle [static]

Definition at line 46 of file res_timing_dahdi.c.

Referenced by load_module(), and unload_module().


Generated on Mon Oct 8 12:39:28 2012 for Asterisk - The Open Source Telephony Project by  doxygen 1.4.7