我是靠谱客的博主 懦弱海燕,最近开发中收集的这篇文章主要介绍dahdi_tools 分析(一)dahdi_scandahdi_tools 分析(一)dahdi_scan,觉得挺不错的,现在分享给大家,希望可以做个参考。
概述
dahdi_tools 分析(一)dahdi_scan
dahdi_scan 的使用
示例:
# dahdi_scan
[1]
active=yes
alarms=OK
description= XX WCTDM Board 1
name=WCTDM/0
manufacturer=xx
devicetype=xx
location=PCI Bus 00 Slot 00
basechan=1
totchans=4
irq=0
type=analog
port=1,FXS
port=2,FXS
port=3,FXS
port=4,FXS
dahdi_scan 用于显示板卡的一些信息。无参数时扫描所有板卡信息,加参数时扫描指定板卡,如 dahdi_scan 4 5 6 ;只扫描 4 5 6 号板卡。
源码分析
int main(int argc, char *argv[])
{
int ctl;
int x, y, z;
struct dahdi_params params;
unsigned int basechan = 1;
int direct_basechan;
struct dahdi_spaninfo s;
char buf[100];
char alarms[50];
// 打开 /dev/dahdi/ctl
if ((ctl = open("/dev/dahdi/ctl", O_RDWR)) < 0) {
fprintf(stderr, "Unable to open /dev/dahdi/ctl: %sn", strerror(errno));
exit(1);
}
for (x = 1; x < DAHDI_MAX_SPANS; x++) {
memset(&s, 0, sizeof(s));
s.spanno = x;
if (ioctl(ctl, DAHDI_SPANSTAT, &s))
// 使用 ioctl DAHDI_SPANSTAT 获取板卡信息,struct dahdi_spaninfo
continue;
/* DAHDI-Linux 2.5.x exposes the base channel in sysfs. Let's
* try to look for it there in case there are holes in the span
* numbering. */
direct_basechan = get_basechan(x);
// get_basechan 后面分析
if (-1 != direct_basechan) {
basechan = direct_basechan;
}
fprintf(stdout, "[%d]n", x);
fprintf(stdout, "active=yesn");
fprintf(stdout, "alarms=%sn", alarms);
fprintf(stdout, "description=%sn", s.desc);
fprintf(stdout, "name=%sn", s.name);
fprintf(stdout, "manufacturer=%sn", s.manufacturer);
fprintf(stdout, "devicetype=%sn", s.devicetype);
fprintf(stdout, "location=%sn", s.location);
fprintf(stdout, "basechan=%dn", basechan);
fprintf(stdout, "totchans=%dn", s.totalchans);
fprintf(stdout, "irq=%dn", s.irq);
// 显示一些基本信息
y = basechan;
memset(¶ms, 0, sizeof(params));
params.channo = y;
if (ioctl(ctl, DAHDI_GET_PARAMS, ¶ms)) {
// 看是否能获取其它信息
basechan += s.totalchans;
continue;
}
if (is_digital_span(&s)) {
// 判断是数字板卡还是模拟板卡
/* this is a digital span */
fprintf(stdout, "type=digital-%sn", s.spantype);
fprintf(stdout, "syncsrc=%dn", s.syncsrc);
fprintf(stdout, "lbo=%sn", s.lboname);
fprintf(stdout, "coding_opts=");
buf[0] = '