我是靠谱客的博主 花痴斑马,这篇文章主要介绍dahdi_tools 分析(四) dahdi_cfgdahdi_tools 分析(四) dahdi_cfg,现在分享给大家,希望可以做个参考。

dahdi_tools 分析(四) dahdi_cfg

dahdi_cfg 的使用

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
dahdi_cfg -h DAHDI Tools Version - 2.11.1 Usage: dahdi_cfg [options] Valid options are: -c <filename> -- Use <filename> instead of /etc/dahdi/system.conf -d [level] -- Generate debugging output. (Default level is 1.) -f -- Always reconfigure every channel -h -- Generate this help statement -s -- Shutdown spans only -t -- Test mode only, do not apply -C <chan_list> -- Only configure specified channels -S <spanno> -- Only configure specified span -v -- Verbose (more -v's means more verbose)

作用

用于对dahdi 驱动进行相关参数配置。默认从 /etc/dahdi/system.conf 中读取配置。

/etc/dahdi/system.conf 示例

复制代码
1
2
3
4
5
loadzone=cn defaultzone=cn fxsks=1 echocanceller=OSLEC,1

代码分析

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#define CONFIG_FILENAME "/etc/dahdi/system.conf" #define MASTER_DEVICE "/dev/dahdi/ctl" static FILE *cf; static char *filename=CONFIG_FILENAME; int main(int argc, char *argv[]) { if (fd == -1) fd = open(MASTER_DEVICE, O_RDWR); // 打开 /dev/dahdi/ctl if (strcmp(filename, "-") == 0) cf = fdopen(STDIN_FILENO, "r"); else cf = fopen(filename, "r"); // 打开 /etc/dahdi/system.conf if (cf) { while((buf = readline())) { // 按行读取 if (*buf == 10) /* skip new line */ continue; if ((value = strchr(buf, '='))) { *value++ = ''; value = trim(value); key = trim(buf); } if (!value || !*value || !*key) { error("Syntax error. Should be <keyword>=<value>n"); continue; } found = 0; for (x = 0; x < sizeof(handlers) / sizeof(handlers[0]); x++) { // 遍历 handlers 数组 if (!strcasecmp(key, handlers[x].keyword)) { // 匹配 key found++; handlers[x].func(key, value); // 执行相应 func break; } } } }

来看 handlers 的定义

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
static struct handler { char *keyword; int (*func)(char *keyword, char *args); } handlers[] = { { "span", spanconfig }, { "dynamic", dspanconfig }, { "loadzone", registerzone }, { "defaultzone", defaultzone }, { "e&m", chanconfig }, { "e&me1", chanconfig }, { "fxsls", chanconfig }, { "fxsgs", chanconfig }, { "fxsks", chanconfig }, { "fxols", chanconfig }, { "fxogs", chanconfig }, { "fxoks", chanconfig }, { "rawhdlc", chanconfig }, { "nethdlc", chanconfig }, { "fcshdlc", chanconfig }, { "hardhdlc", chanconfig }, { "mtp2", chanconfig }, { "dchan", chanconfig }, { "bchan", chanconfig }, { "indclear", chanconfig }, { "clear", chanconfig }, { "unused", chanconfig }, { "cas", chanconfig }, { "dacs", chanconfig }, { "dacsrbs", chanconfig }, { "user", chanconfig }, { "alaw", setlaw }, { "mulaw", setlaw }, { "deflaw", setlaw }, { "ctcss", ctcss }, { "dcsrx", dcsrx }, { "rxdcs", dcsrx }, { "tx", tx }, { "debouncetime", debounce_time }, { "bursttime", burst_time }, { "exttone", ext_tone }, { "invertcor", invert_cor }, { "corthresh", cor_thresh }, { "rxgain", rx_gain }, { "txgain", tx_gain }, { "deemp", de_emp }, { "preemp", pre_emp }, { "channel", rad_chanconfig }, { "channels", rad_chanconfig }, { "echocanceller", setechocan }, { "56k", setfiftysixkhdlc }, };

就是一个 keyword :func 一一对应的一张表。

以 loadzone=cn 为例跟踪一下代码

{ “loadzone”, registerzone },

复制代码
1
2
3
4
5
6
7
8
9
10
static int registerzone(char *keyword, char *args) { if (numzones >= DAHDI_TONE_ZONE_MAX) { error("Too many tone zones specifiedn"); return 0; } dahdi_copy_string(zonestoload[numzones++], args, sizeof(zonestoload[0])); return 0; }
复制代码
1
2
3
4
5
6
7
for (x=0;x<numzones;x++) { if (tone_zone_register(fd, zonestoload[x])) { if (errno != EBUSY) error("Unable to register tone zone '%s'n", zonestoload[x]); } }
复制代码
1
2
3
4
5
6
7
8
9
10
11
int tone_zone_register(int fd, char *country) { struct tone_zone *z; z = tone_zone_find(country); if (z) { return tone_zone_register_zone(-1, z); } else { return -1; } }
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
int tone_zone_register_zone(int fd, struct tone_zone *z) { ... if ((res = ioctl(fd, DAHDI_FREEZONE, &x))) { if (errno != EBUSY) fprintf(stderr, "ioctl(DAHDI_FREEZONE) failed: %sn", strerror(errno)); return res; } if ((res = ioctl(fd, DAHDI_LOADZONE, h))) { } }

可以看出其最终是使用 ioctl 向驱动里面设置一些参数,其它的也都类似。不逐一分析。

最后

以上就是花痴斑马最近收集整理的关于dahdi_tools 分析(四) dahdi_cfgdahdi_tools 分析(四) dahdi_cfg的全部内容,更多相关dahdi_tools内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(75)

评论列表共有 0 条评论

立即
投稿
返回
顶部