Wed Jan 8 2020 09:50:19

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.

Macros

#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: 413586 $")
 
static int dahdi_test_timer (void)
 
static int 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 russe.nosp@m.ll@d.nosp@m.igium.nosp@m..com

Definition in file res_timing_dahdi.c.

Macro Definition 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 139 of file res_timing_dahdi.c.

Referenced by dahdi_test_timer().

Function Documentation

static void __reg_module ( void  )
static

Definition at line 205 of file res_timing_dahdi.c.

static void __unreg_module ( void  )
static

Definition at line 205 of file res_timing_dahdi.c.

ASTERISK_FILE_VERSION ( __FILE__  ,
"$Revision: 413586 $"   
)
static int dahdi_test_timer ( void  )
static

Definition at line 141 of file res_timing_dahdi.c.

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

Referenced by load_module().

142 {
143  int fd;
144  int x = 160;
145 
146  fd = open("/dev/dahdi/timer", O_RDWR);
147 
148  if (fd < 0) {
149  return -1;
150  }
151 
152  if (ioctl(fd, DAHDI_TIMERCONFIG, &x)) {
153  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);
154  close(fd);
155  return -1;
156  }
157 
158  if ((x = ast_wait_for_input(fd, 300)) < 0) {
159  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);
160  close(fd);
161  return -1;
162  }
163 
164  if (!x) {
165  const char dahdi_timer_error[] = {
166  "Asterisk has detected a problem with your DAHDI configuration and will shutdown for your protection. You have options:"
167  "\n\t1. You only have to compile DAHDI support into Asterisk if you need it. One option is to recompile without DAHDI support."
168  "\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."
169  "\n\t3. If you need DAHDI services, you must correctly configure DAHDI."
170  };
171  ast_log(LOG_ERROR, "%s\n" SEE_TIMING, dahdi_timer_error);
172  usleep(100);
173  close(fd);
174  return -1;
175  }
176 
177  close(fd);
178 
179  return 0;
180 }
#define SEE_TIMING
#define LOG_ERROR
Definition: logger.h:155
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
int ast_wait_for_input(int fd, int ms)
Definition: utils.c:1255
static int dahdi_timer_ack ( int  handle,
unsigned int  quantity 
)
static

Definition at line 95 of file res_timing_dahdi.c.

96 {
97  return ioctl(handle, DAHDI_TIMERACK, &quantity) ? -1 : 0;
98 }
static void dahdi_timer_close ( int  handle)
static

Definition at line 75 of file res_timing_dahdi.c.

76 {
77  close(handle);
78 }
static int dahdi_timer_disable_continuous ( int  handle)
static

Definition at line 107 of file res_timing_dahdi.c.

108 {
109  int flags = -1;
110 
111  return ioctl(handle, DAHDI_TIMERPONG, &flags) ? -1 : 0;
112 }
static int dahdi_timer_enable_continuous ( int  handle)
static

Definition at line 100 of file res_timing_dahdi.c.

101 {
102  int flags = 1;
103 
104  return ioctl(handle, DAHDI_TIMERPING, &flags) ? -1 : 0;
105 }
static enum ast_timer_event dahdi_timer_get_event ( int  handle)
static

Definition at line 114 of file res_timing_dahdi.c.

References AST_TIMING_EVENT_CONTINUOUS, and AST_TIMING_EVENT_EXPIRED.

115 {
116  int res;
117  int event;
118 
119  res = ioctl(handle, DAHDI_GETEVENT, &event);
120 
121  if (res) {
122  event = DAHDI_EVENT_TIMER_EXPIRED;
123  }
124 
125  switch (event) {
126  case DAHDI_EVENT_TIMER_PING:
128  case DAHDI_EVENT_TIMER_EXPIRED:
129  default:
130  return AST_TIMING_EVENT_EXPIRED;
131  }
132 }
static unsigned int dahdi_timer_get_max_rate ( int  handle)
static

Definition at line 134 of file res_timing_dahdi.c.

135 {
136  return 1000;
137 }
static int dahdi_timer_open ( void  )
static

Definition at line 70 of file res_timing_dahdi.c.

71 {
72  return open("/dev/dahdi/timer", O_RDWR);
73 }
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(), LOG_ERROR, and roundf().

81 {
82  /* DAHDI timers are configured using a number of samples,
83  * based on an 8 kHz sample rate. */
84  unsigned int samples = roundf((8000.0 / ((float) rate)));
85 
86  if (ioctl(handle, DAHDI_TIMERCONFIG, &samples)) {
87  ast_log(LOG_ERROR, "Failed to configure DAHDI timing fd for %u sample timer ticks\n",
88  samples);
89  return -1;
90  }
91 
92  return 0;
93 }
float roundf(float x)
#define LOG_ERROR
Definition: logger.h:155
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
static int load_module ( void  )
static

Definition at line 182 of file res_timing_dahdi.c.

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

183 {
184  if (dahdi_test_timer()) {
186  }
187 
190 }
static struct ast_timing_interface dahdi_timing
static void * timing_funcs_handle
static int dahdi_test_timer(void)
#define ast_register_timing_interface(i)
Register a set of timing functions.
Definition: timing.h:94
static int unload_module ( void  )
static

Definition at line 192 of file res_timing_dahdi.c.

References ast_unregister_timing_interface(), and timing_funcs_handle.

193 {
194  if (timing_funcs_handle) {
196  }
197 
198  return 0;
199 }
int ast_unregister_timing_interface(void *handle)
Unregister a previously registered timing interface.
Definition: timing.c:105
static void * timing_funcs_handle

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 205 of file res_timing_dahdi.c.

Definition at line 205 of file res_timing_dahdi.c.

struct ast_timing_interface dahdi_timing
static

Definition at line 57 of file res_timing_dahdi.c.

void* timing_funcs_handle
static

Definition at line 46 of file res_timing_dahdi.c.

Referenced by load_module(), and unload_module().