Asterisk - The Open Source Telephony Project  18.5.0
Data Structures | Macros | Functions | Variables
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"
Include dependency graph for res_timing_dahdi.c:

Go to the source code of this file.

Data Structures

struct  dahdi_timer
 

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)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static int dahdi_test_timer (void)
 
static int dahdi_timer_ack (void *data, unsigned int quantity)
 
static void dahdi_timer_close (void *data)
 
static int dahdi_timer_disable_continuous (void *data)
 
static int dahdi_timer_enable_continuous (void *data)
 
static int dahdi_timer_fd (void *data)
 
static enum ast_timer_event dahdi_timer_get_event (void *data)
 
static unsigned int dahdi_timer_get_max_rate (void *data)
 
static void * dahdi_timer_open (void)
 
static int dahdi_timer_set_rate (void *data, 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 = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_TIMING, }
 
static const 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

◆ SEE_TIMING

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

Referenced by dahdi_test_timer().

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 240 of file res_timing_dahdi.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 240 of file res_timing_dahdi.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 240 of file res_timing_dahdi.c.

◆ dahdi_test_timer()

static int dahdi_test_timer ( void  )
static

Definition at line 175 of file res_timing_dahdi.c.

References ast_log, ast_wait_for_input(), dahdi_timer::fd, LOG_ERROR, and SEE_TIMING.

Referenced by load_module().

176 {
177  int fd;
178  int x = 160;
179 
180  fd = open("/dev/dahdi/timer", O_RDWR);
181 
182  if (fd < 0) {
183  return -1;
184  }
185 
186  if (ioctl(fd, DAHDI_TIMERCONFIG, &x)) {
187  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);
188  close(fd);
189  return -1;
190  }
191 
192  if ((x = ast_wait_for_input(fd, 300)) < 0) {
193  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);
194  close(fd);
195  return -1;
196  }
197 
198  if (!x) {
199  const char dahdi_timer_error[] = {
200  "Asterisk has detected a problem with your DAHDI configuration and will shutdown for your protection. You have options:"
201  "\n\t1. You only have to compile DAHDI support into Asterisk if you need it. One option is to recompile without DAHDI support."
202  "\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."
203  "\n\t3. If you need DAHDI services, you must correctly configure DAHDI."
204  };
205  ast_log(LOG_ERROR, "%s\n" SEE_TIMING, dahdi_timer_error);
206  usleep(100);
207  close(fd);
208  return -1;
209  }
210 
211  close(fd);
212 
213  return 0;
214 }
#define ast_log
Definition: astobj2.c:42
#define SEE_TIMING
#define LOG_ERROR
Definition: logger.h:285
int ast_wait_for_input(int fd, int ms)
Definition: main/utils.c:1519

◆ dahdi_timer_ack()

static int dahdi_timer_ack ( void *  data,
unsigned int  quantity 
)
static

Definition at line 117 of file res_timing_dahdi.c.

References dahdi_timer::fd, and timer.

118 {
119  struct dahdi_timer *timer = data;
120 
121  return ioctl(timer->fd, DAHDI_TIMERACK, &quantity) ? -1 : 0;
122 }
static struct ast_timer * timer
Definition: chan_iax2.c:360

◆ dahdi_timer_close()

static void dahdi_timer_close ( void *  data)
static

Definition at line 91 of file res_timing_dahdi.c.

References ast_free, dahdi_timer::fd, and timer.

92 {
93  struct dahdi_timer *timer = data;
94 
95  close(timer->fd);
96  ast_free(timer);
97 }
#define ast_free(a)
Definition: astmm.h:182
static struct ast_timer * timer
Definition: chan_iax2.c:360

◆ dahdi_timer_disable_continuous()

static int dahdi_timer_disable_continuous ( void *  data)
static

Definition at line 132 of file res_timing_dahdi.c.

References dahdi_timer::fd, and timer.

133 {
134  struct dahdi_timer *timer = data;
135  int flags = -1;
136 
137  return ioctl(timer->fd, DAHDI_TIMERPONG, &flags) ? -1 : 0;
138 }
static struct ast_timer * timer
Definition: chan_iax2.c:360

◆ dahdi_timer_enable_continuous()

static int dahdi_timer_enable_continuous ( void *  data)
static

Definition at line 124 of file res_timing_dahdi.c.

References dahdi_timer::fd, and timer.

125 {
126  struct dahdi_timer *timer = data;
127  int flags = 1;
128 
129  return ioctl(timer->fd, DAHDI_TIMERPING, &flags) ? -1 : 0;
130 }
static struct ast_timer * timer
Definition: chan_iax2.c:360

◆ dahdi_timer_fd()

static int dahdi_timer_fd ( void *  data)
static

Definition at line 166 of file res_timing_dahdi.c.

References dahdi_timer::fd, and timer.

167 {
168  struct dahdi_timer *timer = data;
169 
170  return timer->fd;
171 }
static struct ast_timer * timer
Definition: chan_iax2.c:360

◆ dahdi_timer_get_event()

static enum ast_timer_event dahdi_timer_get_event ( void *  data)
static

Definition at line 140 of file res_timing_dahdi.c.

References AST_TIMING_EVENT_CONTINUOUS, AST_TIMING_EVENT_EXPIRED, dahdi_timer::fd, and timer.

141 {
142  struct dahdi_timer *timer = data;
143  int res;
144  int event;
145 
146  res = ioctl(timer->fd, DAHDI_GETEVENT, &event);
147 
148  if (res) {
149  event = DAHDI_EVENT_TIMER_EXPIRED;
150  }
151 
152  switch (event) {
153  case DAHDI_EVENT_TIMER_PING:
155  case DAHDI_EVENT_TIMER_EXPIRED:
156  default:
158  }
159 }
Definition: astman.c:222
static struct ast_timer * timer
Definition: chan_iax2.c:360

◆ dahdi_timer_get_max_rate()

static unsigned int dahdi_timer_get_max_rate ( void *  data)
static

Definition at line 161 of file res_timing_dahdi.c.

162 {
163  return 1000;
164 }

◆ dahdi_timer_open()

static void * dahdi_timer_open ( void  )
static

Definition at line 74 of file res_timing_dahdi.c.

References ast_calloc, ast_free, ast_log, errno, dahdi_timer::fd, LOG_ERROR, NULL, and timer.

75 {
76  struct dahdi_timer *timer;
77 
78  if (!(timer = ast_calloc(1, sizeof(*timer)))) {
79  return NULL;
80  }
81 
82  if ((timer->fd = open("/dev/dahdi/timer", O_RDWR)) < 0) {
83  ast_log(LOG_ERROR, "Failed to create dahdi timer: %s\n", strerror(errno));
84  ast_free(timer);
85  return NULL;
86  }
87 
88  return timer;
89 }
#define NULL
Definition: resample.c:96
#define ast_log
Definition: astobj2.c:42
#define LOG_ERROR
Definition: logger.h:285
int errno
#define ast_free(a)
Definition: astmm.h:182
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
static struct ast_timer * timer
Definition: chan_iax2.c:360

◆ dahdi_timer_set_rate()

static int dahdi_timer_set_rate ( void *  data,
unsigned int  rate 
)
static

Definition at line 99 of file res_timing_dahdi.c.

References ast_log, dahdi_timer::fd, LOG_ERROR, roundf(), and timer.

100 {
101  struct dahdi_timer *timer = data;
102  int samples;
103 
104  /* DAHDI timers are configured using a number of samples,
105  * based on an 8 kHz sample rate. */
106  samples = (unsigned int) roundf((8000.0 / ((float) rate)));
107 
108  if (ioctl(timer->fd, DAHDI_TIMERCONFIG, &samples)) {
109  ast_log(LOG_ERROR, "Failed to configure DAHDI timing fd for %d sample timer ticks\n",
110  samples);
111  return -1;
112  }
113 
114  return 0;
115 }
#define ast_log
Definition: astobj2.c:42
#define LOG_ERROR
Definition: logger.h:285
float roundf(float x)
static struct ast_timer * timer
Definition: chan_iax2.c:360

◆ load_module()

static int load_module ( void  )
static

Definition at line 216 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.

Referenced by unload_module().

217 {
218  if (dahdi_test_timer()) {
220  }
221 
224 }
static struct ast_timing_interface dahdi_timing
static void * timing_funcs_handle
static int dahdi_test_timer(void)
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
#define ast_register_timing_interface(i)
Register a set of timing functions.
Definition: timing.h:95

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 226 of file res_timing_dahdi.c.

References AST_MODFLAG_LOAD_ORDER, AST_MODPRI_TIMING, AST_MODULE_INFO(), AST_MODULE_SUPPORT_CORE, ast_unregister_timing_interface(), ASTERISK_GPL_KEY, load_module(), and timing_funcs_handle.

227 {
228  if (timing_funcs_handle) {
230  }
231 
232  return 0;
233 }
int ast_unregister_timing_interface(void *handle)
Unregister a previously registered timing interface.
Definition: timing.c:104
static void * timing_funcs_handle

Variable Documentation

◆ __mod_info

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 = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_TIMING, }
static

Definition at line 240 of file res_timing_dahdi.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 240 of file res_timing_dahdi.c.

◆ dahdi_timing

struct ast_timing_interface dahdi_timing
static

Definition at line 56 of file res_timing_dahdi.c.

◆ timing_funcs_handle

void* timing_funcs_handle
static

Definition at line 44 of file res_timing_dahdi.c.

Referenced by load_module(), and unload_module().