README 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017
  1. DAHDI Telephony Interface Driver
  2. =================================
  3. Asterisk Development Team <asteriskteam@digium.com>
  4. $Revision$, $Date$
  5. DAHDI stands for Digium Asterisk Hardware Device Interface.
  6. This package contains the kernel modules for DAHDI. For the required
  7. userspace tools see the package dahdi-tools.
  8. Supported Hardware
  9. ------------------
  10. Digital Cards
  11. ~~~~~~~~~~~~~
  12. - wct4xxp:
  13. * Digium TE205P/TE207P/TE210P/TE212P: PCI dual-port T1/E1/J1
  14. * Digium TE405P/TE407P/TE410P/TE412P: PCI quad-port T1/E1/J1
  15. * Digium TE220: PCI-Express dual-port T1/E1/J1
  16. * Digium TE420: PCI-Express quad-port T1/E1/J1
  17. - wcte12xp:
  18. * Digium TE120P: PCI single-port T1/E1/J1
  19. * Digium TE121: PCI-Express single-port T1/E1/J1
  20. * Digium TE122: PCI single-port T1/E1/J1
  21. - wcte11xp:
  22. * Digium TE110P: PCI single-port T1/E1/J1
  23. - wct1xxp:
  24. * Digium T100P: PCI single-port T1
  25. * Digium E100P: PCI single-port E1
  26. - wcb4xxp:
  27. * Digium B410: PCI quad-port BRI
  28. - tor2: Tormenta quad-span T1/E1 card from the Zapata Telephony project
  29. Analog Cards
  30. ~~~~~~~~~~~~
  31. - wctdm24xxp:
  32. * Digium TDM2400P/AEX2400: up to 24 analog ports
  33. * Digium TDM800P/AEX800: up to 8 analog ports
  34. * Digium TDM410P/AEX410: up to 4 analog ports
  35. * Digium Hx8 Series: Up to 8 analog or BRI ports
  36. - wctdm:
  37. * Digium TDM400P: up to 4 analog ports
  38. - xpp: Xorcom Astribank: a USB connected unit of up to 32 ports
  39. (including the digital BRI and E1/T1 modules)
  40. - wcfxo: X100P, similar and clones. A simple single-port FXO card
  41. Other Drivers
  42. ~~~~~~~~~~~~~
  43. - pciradio: Zapata Telephony PCI Quad Radio Interface
  44. - wctc4xxp: Digium hardware transcoder cards (also need dahdi_transcode)
  45. - dahdi_dynamic_eth: TDM over Ethernet (TDMoE) driver. Requires dahdi_dynamic
  46. - dahdi_dynamic_loc: Mirror a local span. Requires dahdi_dynamic
  47. Installation
  48. ------------
  49. If all is well, you just need to run the following:
  50. make
  51. make install
  52. You'll need the utilities provided in the package dahdi-tools to
  53. configure DAHDI devices on your system.
  54. If using `sudo` to build/install, you may need to add /sbin to your PATH.
  55. If you still have problems, read further.
  56. Build Requirements
  57. ~~~~~~~~~~~~~~~~~~
  58. gcc and friends. Generally you will need to install the package gcc.
  59. There may be cases where you will need a specific version of gcc to build
  60. kernel modules.
  61. Kernel Source / "Headers"
  62. ^^^^^^^^^^^^^^^^^^^^^^^^^
  63. - Building DAHDI-linux requires a kernel build tree.
  64. - This should basically be at least a partial kernel source tree and
  65. most importantly, the exact kernel .config file used for the build as
  66. well as several files generated at kernel build time.
  67. - KERNEL_VERSION is the output of the command `uname -r`
  68. - If you build your own kernel, you need to point to the exact kernel
  69. build tree. Luckily for you, this will typically be pointed by the
  70. symbolic link /lib/modules/KERNEL_VERSION/build which is the location
  71. zaptel checks by default.
  72. - If you use a kernel from your distribution you will typically have a
  73. package with all the files required to build a kernel modules for your
  74. kernel image.
  75. * On Debian and Ubuntu this is
  76. +++ linux-headers-`uname -r` +++
  77. * On Fedora, RHEL and compatibles (e.g. CentOS) and SUSE this is
  78. the kernel-devel package. Or if you run kernel-smp or kernel-xen,
  79. you need kernel-smp-devel or kernel-xen-devel, respectively.
  80. * In some distributions (e.g.: in RHEL/CentOS, Fedora, Ubuntu) the
  81. installation of the kernel-devel / kernel-headers package will
  82. be of a version that is newer than the one you currently run. In
  83. such a case you may need to upgrade the kernel package itself as
  84. well and reboot.
  85. - To point explicitly to a different build tree: set KSRC to the kernel
  86. source tree or KVERS to the exact kernel version (if "headers" are
  87. available for a different version). This parameter must be run on
  88. every calls to 'make' (e.g.: 'make clean', 'make install').
  89. make KVERS=2.6.18.Custom
  90. make KSRC=/home/tzafrir/kernels/linus
  91. Kernel Configuration
  92. ^^^^^^^^^^^^^^^^^^^^
  93. If you build a custom kernel, note the following configuration items:
  94. - CONFIG_CRC_CCITT must be enabled ('y' or 'm'). On 2.6 kernels this can
  95. be selected These can be selected from the "Library Routines" submenu
  96. during kernel configuration via "make menuconfig".
  97. - DAHDI will work if you disable module unloading. But you may need
  98. extra reboots.
  99. - DAHDI needs the BKL (Big Kernel Lock). This may be annoying in
  100. >=2.6.37 kernels. Make sure you enable CONFIG_BKL on those kernels.
  101. Installing to a Subtree
  102. ~~~~~~~~~~~~~~~~~~~~~~~
  103. The following may be useful when testing the package or when preparing a
  104. package for a binary distribution (such as an rpm package) installing
  105. onto a subtree rather than on the real system.
  106. make install DESTDIR=targetdir
  107. This can be useful for any partial install target of the above (e.g:
  108. install-modules or install-programs).
  109. the targetdir must be an absolute path, at least if you install the
  110. modules. To install to a relative path you can use something like:
  111. make install-modules DESTDIR=$PWD/target
  112. Extra Modules
  113. ~~~~~~~~~~~~~
  114. To build extra modules / modules directory not included in the DAHDI
  115. distribution, use the optional variables MODULES_EXTRA and
  116. SUBDIRS_EXTRA:
  117. make MODULES_EXTRA="mod1 mod2"
  118. make MODULES_EXTRA="mod1 mod2" SUBDIRS_EXTRA="subdir1/ subdir1/"
  119. Static Device Files
  120. ~~~~~~~~~~~~~~~~~~~
  121. Userspace programs communicate with the DAHDI modules through special
  122. device files under /dev/dahdi . Those are normally created by udev, but
  123. if you use an embedded-type system and don't wish to use udev, you can
  124. generate them with the following script, from the source directory:
  125. ./build_tools/make_static_devs
  126. This will generate the device files under /dev/dahdi . If you need to
  127. generate them elsewhere (e.g. `tmp/newroot/dev/dahdi`) use the option -d
  128. to the script:
  129. ./build_tools/make_static_devs -d tmp/newroot/dev/dahdi
  130. Installing the B410P drivers with mISDN
  131. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  132. DAHDI includes the wcb4xxp driver for the B410P, however, support for the
  133. B410P was historically provided by mISDN. If you would like to use the mISDN
  134. driver with the B410P, please comment out the wcb4xxp line in /etc/dahdi/modules.
  135. This will prevent DAHDI from loading wcb4xxp which will conflict with the mISDN
  136. driver.
  137. To install the mISDN driver for the B410P, please see http://www.misdn.org for
  138. more information, but the following sequence of steps is roughly equivalent to
  139. 'make b410p' from previous releases.
  140. wget http://www.misdn.org/downloads/releases/mISDN-1_1_8.tar.gz
  141. wget http://www.misdn.org/downloads/releases/mISDNuser-1_1_8.tar.gz
  142. tar xfz mISDN-1_1_8.tar.gz
  143. tar xfz mISDNuser-1_1_8.tar.gz
  144. pushd mISDN-1_1_8
  145. make install
  146. popd
  147. pushd mISDNuser-1_1_8
  148. make install
  149. popd
  150. /usr/sbin/misdn-init config
  151. You will then also want to make sure /etc/init.d/misdn-init is started
  152. automatically with either 'chkconfig --add misdn-init' or 'update-rc.d
  153. misdn-init defaults 15 30' depending on your distribution.
  154. NOTE: At the time this was written, misdn-1.1.8 is not compatible the
  155. 2.6.25 kernel. Please use a kernel version 2.6.25 or earlier.
  156. OSLEC
  157. ~~~~~
  158. http://www.rowetel.com/ucasterisk/oslec.html[OSLEC] is an
  159. Open Source Line Echo Canceller. It is currently in the staging subtree
  160. of the mainline kernel and will hopefully be fully merged at around
  161. version 2.6.29. The echo canceller module dahdi_echocan_oslec
  162. provides a DAHDI echo canceller module that uses the code from OSLEC. As
  163. OSLEC has not been accepted into mainline yet, its interface is not set
  164. in stone and thus this driver may need to change. Thus it is not
  165. built by default.
  166. Luckily the structure of the dahdi-linux tree matches that of the kernel
  167. tree. Hence you can basically copy drivers/staging/echo and place it
  168. under driver/staging/echo . In fact, dahdi_echocan_oslec assumes that
  169. this is where the oslec code lies. If it is elsewhere you'll need to fix
  170. the #include line.
  171. Thus for the moment, the simplest way to build OSLEC with dahdi is:
  172. 1. Copy the directory `drivers/staging/echo` from a recent kernel tree
  173. (at least 2.6.28-rc1) to the a subdirectory with the same name in the
  174. dahdi-linux tree.
  175. 2. Edit drivers/dahdi/Kbuild and uncomment the two lines related to OSLEC.
  176. After doing that, you'll see the following when building (running
  177. 'make')
  178. ...
  179. CC [M] /home/tzafrir/dahdi-linux/drivers/dahdi/dahdi_echocan_oslec.o
  180. CC [M] /home/tzafrir/dahdi-linux/drivers/dahdi/../staging/echo/echo.o
  181. ...
  182. As this is an experimental driver, problems building and using it should
  183. be reported on the
  184. https://lists.sourceforge.net/lists/listinfo/freetel-oslec[OSLEC mailing
  185. list].
  186. Live Install
  187. ~~~~~~~~~~~~
  188. In many cases you already have DAHDI installed on your system but would
  189. like to try a different version. E.g. in order to check if the latest
  190. version fixes a bug that your current system happens to have.
  191. DAHDI-linux includes a script to automate the task of installing DAHDI
  192. to a subtree and using it instead of the system copy. Module loading
  193. through modprobe cannot be used. Thus the script pre-loads the required
  194. modules with insmod (which requires some quesswork as for which modules
  195. to load). It also sets PATH and other environment variables to make all
  196. the commands do the right thing.
  197. There is an extra mode of operation to copy all the required files to a
  198. remote host and run things there, for those who don't like to test code
  199. on thir build system.
  200. Live Install: The Basics
  201. ^^^^^^^^^^^^^^^^^^^^^^^^
  202. Basic operation is through running
  203. ./build_tools/live_dahdi
  204. from the root directory of the dahdi-linux tree. Using DAHDI requires
  205. dahdi-tools as well, and the script builds and installs dahdi-tools. By
  206. default it assumes the tree of dahdi-tools is in the directory
  207. 'dahdi-tools' alongside the dahdi-linux tree. If you want to checkout
  208. the trunks from SVN, use:
  209. svn checkout http://svn.asterisk.org/svn/dahdi/linux/trunk dahdi-linux
  210. svn checkout http://svn.asterisk.org/svn/dahdi/tools/trunk dahdi-tools
  211. cd dahdi-linux
  212. If the tools directory resides elsewhere, you'll need to edit
  213. live/live.conf (see later on). The usage message of live_dahdi:
  214. Usage: equivalent of:
  215. live_dahdi configure ./configure
  216. live_dahdi install make install
  217. live_dahdi config make config
  218. live_dahdi unload /etc/init.d/dahdi stop
  219. live_dahdi load /etc/init.d/dahdi start
  220. live_dahdi reload /etc/init.d/dahdi restart
  221. live_dahdi xpp-firm (Reset and load xpp firmware)
  222. live_dahdi rsync TARGET (copy filea to /tmp/live in host TARGET)
  223. live_dahdi exec COMMAND (Run COMMAND in 'live' environment)
  224. Normally you should run:
  225. ./build_tools/live_dahdi configure
  226. ./build_tools/live_dahdi install
  227. ./build_tools/live_dahdi config
  228. to build and install everything. Up until now no real change was done.
  229. This could actually be run by a non-root user. All files are installed
  230. under the subdirectory live/ .
  231. Reloading the modules (and restarting Asterisk) is done by:
  232. ./build_tools/live_dahdi reload
  233. Note: this stops Asterisk, unloads the DAHDI modules, loads the DAHDI
  234. modules from the live/ subdirectory, configures the system and re-starts
  235. Asterisk. This *can* do damage to your system. Furthermore, the DAHDI
  236. configuration is generated by dahdi_genconf. It can be influenced by
  237. a genconf_parameters file. But it may or may not be what you want.
  238. If you want to run a command in the environment of the live system, use
  239. the command 'exec':
  240. ./build_tools/live_dahdi lsdahdi
  241. ./build_tools/live_dahdi dahdi_hardware -v
  242. Note however:
  243. ./build_tools/live_dahdi dahdi_cfg -c live/etc/dahdi/system.conf
  244. Live Install Remote
  245. ^^^^^^^^^^^^^^^^^^^
  246. As mentioned above, live_dahdi can also copy all the live system files
  247. to a remote system and run from there. This requires rsync installed on
  248. both system and assumes you can connect to the remove system through
  249. ssh.
  250. tzafrir@hilbert $ ./build_tools/live_dahdi rsync root@david
  251. root@david's password:
  252. <f+++++++++ live_dahdi
  253. cd+++++++++ live/
  254. <f+++++++++ live/live.conf
  255. cd+++++++++ live/dev/
  256. cd+++++++++ live/dev/dahdi/
  257. cd+++++++++ live/etc/
  258. cd+++++++++ live/etc/asterisk/
  259. cd+++++++++ live/etc/dahdi/
  260. <f+++++++++ live/etc/dahdi/genconf_parameters
  261. <f+++++++++ live/etc/dahdi/init.conf
  262. ...
  263. As you can see, it copies the script itselfand the whole live/
  264. subdirectory. The target directory is /tmp/live on the target directory
  265. (changing it should probably be simple, but I never needed that).
  266. Then, on the remove computer:
  267. root@david:/tmp# ./live_dahdi reload
  268. Configuring a Live Install
  269. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  270. The live_dahdi script reads a configuration file in 'live/live.conf' if
  271. it exists. This file has the format of a shell script snippet:
  272. var1=value # a '#' sign begins a comment
  273. var2='value'
  274. # comments and empty lines are ignored
  275. var3="value"
  276. The variables below can also be overriden from the environment:
  277. var1='value' ./build_tools/live_dahdi
  278. ===== LINUX_DIR
  279. The relative path to the dahdi-linux tree. The default is '.' and normally
  280. there's no reason to override it.
  281. ===== TOOLS_DIR
  282. The relative path to the dahdi-tools tree. The default is 'dahdi-tools'.
  283. ===== XPP_SYNC
  284. Set a syncing astribank. See xpp_sync(8). Default is 'auto'.
  285. ===== AST_SCRIPT
  286. The command for an init.d script to start/stop Asterisk. Should accept
  287. 'start' and 'stop' commands. Use 'true' if you want to make that a
  288. no-op. Defaults to '/etc/init.d/asterisk' .
  289. ===== MODULES_LOAD
  290. Manual list of modules. They will be loaded by insmod. If reside in a
  291. subdir, add it explicitly. Modules for the drivers that are detected on
  292. the system will be added by the script. Default: 'dahdi
  293. dahdi_echocan_mg2'
  294. ===== REMOVE_MODULES
  295. A list of modules to remove when unloading. Will be resolved
  296. recursively. The default is 'dahdi'. You may also want to have 'oslec'
  297. or 'hpec' there if you use them.
  298. Module Parameters
  299. -----------------
  300. The kernel modules can be configured through module parameters. Module
  301. parameters can optionally be set at load time. They are normally set (if
  302. needed) by a line in a file under /etc/modprobe.d/ or in the file
  303. /etc/modprobe.conf.
  304. Example line:
  305. options dahdi debug=1
  306. The module parameters can normally be modified at runtime through sysfs:
  307. pungenday:~# cat /sys/module/dahdi/parameters/debug
  308. 0
  309. pungenday:~# echo 1 >/sys/module/dahdi/parameters/debug
  310. pungenday:~# cat /sys/module/dahdi/parameters/debug
  311. 1
  312. Viewing and setting parameters that way is possible as of kernel 2.6 .
  313. In kernels older than 2.6.10, the sysfs "files" for the parameters
  314. reside directly under /sys/module/'module_name' .
  315. Useful module parameters:
  316. debug (most modules)::
  317. Sets debug mode / debug level. With most modules 'debug' can be either
  318. disabled (0, the default value) or enabled (any other value).
  319. +
  320. +
  321. wctdm and wcte1xp print several extra debugging messages if the value
  322. of debug is more than 1.
  323. +
  324. +
  325. Some modules have "debugging flags" bits - the value of debug is a
  326. bitmask and several messages are printed if some bits are set:
  327. - wctdm24xxp:
  328. * 1: DEBUG_CARD
  329. * 2: DEBUG_ECHOCAN
  330. - wct4xxp:
  331. * 1: DEBUG_MAIN
  332. * 2: DEBUG_DTMF
  333. * 4: DEBUG_REGS
  334. * 8: DEBUG_TSI
  335. * 16: DEBUG_ECHOCAN
  336. * 32: DEBUG_RBS
  337. * 64: DEBUG_FRAMER
  338. - xpp: See also README.Astribank:
  339. * 1: GENERAL - General debug comments.
  340. * 2: PCM - PCM-related messages. Tend to flood logs.
  341. * 4: LEDS - Anything related to the LEDs status control. The driver
  342. produces a lot of messages when the option is enabled.
  343. * 8: SYNC - Synchronization related messages.
  344. * 16: SIGNAL - DAHDI signalling related messages.
  345. * 32: PROC - Messages related to the procfs interface.
  346. * 64: REGS - Reading and writing to chip registers. Tends to flood
  347. logs.
  348. * 128: DEVICES - Device instantiation, destruction and such.
  349. * 256 - COMMANDS - Protocol commands. Tends to flood logs.
  350. deftaps (dahdi)::
  351. The default size for the echo canceller. The number is in "taps", that
  352. is "samples", 1/8 ms. The default is 64 - for a tail size of 8 ms.
  353. +
  354. +
  355. Asterisk's chan_dahdi tends to pass its own value anyway, with a
  356. different default size. So normally setting this doesn't change
  357. anything.
  358. To get a list of parameters supported by a module, use
  359. modinfo module_name
  360. Or, for a module you have just built:
  361. modinfo ./module_name.ko
  362. For the xpp modules this will also include the description and default
  363. value of the module. You can find a list of useful xpp module parameters
  364. in README.Astribank .
  365. Internals
  366. ---------
  367. DAHDI Device Files
  368. ~~~~~~~~~~~~~~~~~~
  369. Userspace programs will usually interact with DAHDI through device
  370. files under the /dev/dahdi directory (pedantically: character device files
  371. with major number 196) . Those device files can be generated statically
  372. or dynamically through the udev system.
  373. * /dev/dahdi/ctl (196:0) - a general device file for various information and
  374. control operations on the DAHDI channels.
  375. * /dev/dahdi/NNN (196:NNN) - for NNN in the range 1-249. A device file for
  376. DAHDI channel NNN. It can be used to read data from the channel
  377. and write data to the channel.
  378. * /dev/dahdi/transcode (196:250) - Used to connect to a DAHDI transcoding
  379. device.
  380. * /dev/dahdi/timer (196:253) - Allows setting timers. Used anywhere?
  381. * /dev/dahdi/channel (196:254) - Can be used to open an arbitrary DAHDI
  382. channel. This is an alternative to /dev/dahdi/NNN that is not limited to
  383. 249 channels.
  384. * /dev/dahdi/pseudo (196:255) - A timing-only device. Every time you open
  385. it, a new DAHDI channel is created. That DAHDI channel is "pseudo" -
  386. DAHDI receives no data in it, and only sends garbage data with the
  387. same timing as the DAHDI timing master device.
  388. DAHDI Timing
  389. ~~~~~~~~~~~~
  390. A PBX system should generally have a single clock. If you are connected to a
  391. telephony provider via a digital interface (e.g: E1, T1) you should also
  392. typically use the provider's clock (as you get through the interface). Hence
  393. one important job of Asterisk is to provide timing to the PBX.
  394. DAHDI "ticks" once per millisecond (1000 times per second). On each tick every
  395. active DAHDI channel reads and 8 bytes of data. Asterisk also uses this for
  396. timing, through a DAHDI pseudo channel it opens.
  397. However, not all PBX systems are connected to a telephony provider via a T1 or
  398. similar connection. With an analog connection you are not synced to the other
  399. party. And some systems don't have DAHDI hardware at all. Even a digital card
  400. may be used for other uses or is simply not connected to a provider. DAHDI
  401. cards are also capable of providing timing from a clock on card. Cheap x100P
  402. clone cards are sometimes used for that purpose.
  403. If a hardware timing source either cannot be found or stops providing timing
  404. during runtime, DAHDI will automatically use the host timer in order provide
  405. timing.
  406. You can check the DAHDI timing source with dahdi_test, which is a small
  407. utility that is included with DAHDI. It runs in cycles. In each such cycle it
  408. tries to read 8192 bytes, and sees how long it takes. If DAHDI is not loaded
  409. or you don't have the device files, it will fail immediately. If you lack a
  410. timing device it will hang forever in the first cycle. Otherwise it will just
  411. give you in each cycle the percent of how close it was. Also try running it
  412. with the option -v for a verbose output.
  413. Spans and Channels
  414. ~~~~~~~~~~~~~~~~~~
  415. DAHDI provides telephony *channels* to the userspace applications.
  416. Those channels are channels are incorporated into logical units called
  417. *spans*.
  418. With digital telephony adapters (e.g: E1 or T1), a span normally
  419. represents a single port. With analog telephony a span typically
  420. represents a PCI adapter or a similar logical unit.
  421. Both channels and spans are identified by enumerating numbers (beginning
  422. with 1). The number of the channel is the lowest unused one when it is
  423. generated, and ditto for spans.
  424. There are up to 128 spans and 1024 channels. This is a hard-wired limit
  425. (see dahdi/user.h . Several places throuout the code assume a channel
  426. number fits in a 16 bits number). Channel and span numbers start at 1.
  427. Dynamic Spans
  428. ~~~~~~~~~~~~~
  429. Dynamic spans are spans that are not represented by real hardware.
  430. Currently there are two types of them:
  431. tdmoe::
  432. TDM over Ethernet. A remote span is identified by an ethernet (MAC)
  433. address.
  434. local::
  435. Generates a span that is actually a loopback to a different local
  436. span.
  437. Modules that support the dynamic spans are typically loaded at the time
  438. the ioctl DAHDI_DYNAMIC_CREATE is called. This is typically called by
  439. dahdi_cfg when it has a line such as:
  440. dynamic,somename,params
  441. in /etc/dahdi/system.conf . In that case it will typically try to load
  442. (through modprobe) the modules dahdi_dynamic and
  443. dahdi_dynamic_'somename'. It will then pass 'params' to it.
  444. Dynamic spans are known to be tricky and are some of the least-tested
  445. parts of DAHDI.
  446. Echo Cancellers
  447. ~~~~~~~~~~~~~~~
  448. (To be documented later)
  449. Tone Zones
  450. ~~~~~~~~~~
  451. (To be documented later)
  452. PROCFS Interface: /proc/dahdi
  453. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  454. A simple way to get the current list of spans and channels each span contains
  455. is the files under /proc/dahdi . /proc/dahdi is generated by DAHDI as it
  456. loads. As each span registers to DAHDI, a file under /proc/dahdi is created
  457. for it. The name of that file is the number of that span.
  458. Each file has a 1-line title for the span followed by a few optional
  459. general counter lines, an empty line and then a line for each channel of
  460. the span.
  461. The title line shows the number of the span, its name and title, and
  462. (potentially) the alarms in which it is.
  463. The title shows the span number and name, followed by any alarms the
  464. span may have: For example, here is the first span in my system (with no
  465. alarms):
  466. Span 1: XBUS-00/XPD-00 "Xorcom XPD #0/0: FXS"
  467. There are several extra optional keywords that may be added there:
  468. (Master)::
  469. This span is the master span. See <<_dahdi_timing,DAHDI Timing>>.
  470. ClockSource::
  471. The clock source among several spans that belong to a single E1/J1/T1
  472. card.
  473. RED/YELLOW/RED/NOTOPEN/LOOP/RECOVERING::
  474. The span is in alarm
  475. Following that line there may be some optional lines about IRQ misses,
  476. timing slips and such, if there are any.
  477. The channel line for each channel shows its channel number, name and the
  478. actual signalling assigned to it through dahdi_cfg. Before being configured by
  479. dahdi_cfg: This is DAHDI channel 2, whose name is 'XPP_FXS/0/0/1'.
  480. 2 XPP_FXS/0/0/1
  481. After being configured by dahdi_cfg: the signalling 'FXOLS' was added. FXS
  482. channels have FXO signalling and vice versa:
  483. 2 XPP_FXS/0/0/1 FXOLS
  484. If the channel is in use (typically opened by Asterisk) then you will
  485. see an extra '(In use)':
  486. 2 XPP_FXS/0/0/1 FXOLS (In use)
  487. User-space Interface
  488. ~~~~~~~~~~~~~~~~~~~~
  489. User-space programs can only work with DAHDI channels. The basic
  490. operation is 'read()' to read audio from the device and write() to write
  491. audio to it. Audio can be encoded as either alaw (G.711a) or (m)ulaw
  492. (G.711u). See the ioctl DAHDI_SETLAW.
  493. While it is technically possible to use /dev/dahdi/NUMBER directly, this
  494. will only work for channel numbers up to 249. Generally you should use:
  495. int channo = CHAN_NUMBER_TO_OPEN;
  496. int rc;
  497. int fd = open("/dev/dahdi/channel", O_RDRW, 0600);
  498. // Make sure fd >= 0
  499. rc = ioctl(fd, DAHDI_SPECIFY, &channo) < 0);
  500. // Make sure this rc >= 0
  501. FIXME: there's more to tell about the user-space interface.
  502. Configuration
  503. ~~~~~~~~~~~~~
  504. Most of the configuration is applied from userspace using the tool
  505. 'dahdi_cfg' in the package dahdi_tools. This section will not cover the
  506. specifics of that file. Rather it will cover the way configuration from
  507. this file is applied. Also note that there are other methods to
  508. configure DAHDI drivers: there are <<_module_parameters,Module
  509. Parameters>>. The xpp driver have their own separate initialization
  510. scripts and xpp.conf that arecovered in README.Astribank.
  511. When a span is registered, it is considered "unconfigured". Only after
  512. dahdi_cfg has been run to apply configuration, the span is ready to run.
  513. Some of the configuration is handled by the DAHDI core. Some of it is
  514. handled by callbacks, which are function pointers in the `struct
  515. dahdi_span': 'spanconfig', 'chanconfig' and (in a way) 'startup'.
  516. Dahdi_cfg starts by reading the configuration from the configuration
  517. file ('/etc/dahdi/system.conf', by default), and creating a local
  518. configuration to apply. If you use -v, at this stage it will pront the
  519. configuration that is "about to be configured". Then it will start to
  520. actually apply the configuration.
  521. Before actually applying configuration, it destroys any existing
  522. <<_dynamic_spans,dynamic spans>> and generates new ones (if so
  523. configured. FIXME: what about running DAHDI_SPANCONFIG for new dynamic
  524. spans?).
  525. Next thing it will do is apply the parameters from *span* lines using
  526. the ioctl DAHDI_SPANCONFIG. Some generic processing of parameters passed
  527. in DAHDI_SPANCONFIG is done in the DAHDI core, in the callback function
  528. spanconfig in , but most of it is left to 'spanconfig' callback of the
  529. span (if it exists. This one typically does not exists on analog cards).
  530. Now dahdi_cfg will ask each existing channel for its existing
  531. configuration and apply configuration if configuration changes are
  532. needed. Configuration is applied to the channels using the ioctl call
  533. DAHDI_CHANCONFIG ioctl. As in the case of the span configuration, part
  534. of it is applied by the DAHDI core, and then it is handed over to the
  535. span's chanconfig callback. Typically all spans will have such a
  536. callback.
  537. <<_echo_cancellers,Echo cancellers>> and <<_tone_zones,tone-zones>> are
  538. handled separately later.
  539. Once everything is done, the ioctl DAHDI_STARTUP is called for every
  540. span. This is also translated to a call to the optional span callback
  541. 'startup'.
  542. Finally the ioctl DAHDI_HDLC_RATE is called for every channel (that is:
  543. if '56k' is not set for the channel, it will be explicitly set to the
  544. standard HDLC rate of 64k).
  545. Low-Level Drivers
  546. ~~~~~~~~~~~~~~~~~
  547. Low-level drivers create spans ('struct dahdi_span'). They register the
  548. spans with the DAHDI core using 'dahdi_register()'.
  549. 'struct dahdi_span' has a number of informative members that are updated
  550. solely by the low-level driver:
  551. name::
  552. A concise span name. E.g.: Foo/1
  553. desc::
  554. A slightly longer span name.
  555. spantype::
  556. Span type in text form.
  557. manufacturer::
  558. Span's device manufacturer
  559. devicetype::
  560. Span's device type
  561. location::
  562. span device's location in system
  563. irq::
  564. IRQ for this span's hardware
  565. irqmisses::
  566. Interrupt misses
  567. timingslips::
  568. Clock slips
  569. There are various function pointers in the struct 'dahdi_span' which are
  570. used by the DAHDI core to call the low-level driver. Most of them are
  571. optional.
  572. The following apply to a span:
  573. setchunksize::
  574. FIXME: seems to be unused.
  575. spanconfig::
  576. Basic span configuration (called from dahdi_cfg).
  577. startup::
  578. Last minute initialization after the configuration was applied.
  579. shutdown::
  580. Explicit shutdown (e.g. for dynamic spans). Normally not needed.
  581. maint::
  582. Enable/disable maintinance mode (FIXME: document).
  583. sync_tick::
  584. Get notified that the master span has ticked.
  585. The following apply to a single channel.
  586. chanconfig::
  587. Configure the channel (called from dahdi_cfg).
  588. open::
  589. Channel was opened for read/write from user-space.
  590. close::
  591. Channel was closed by user-space.
  592. ioctl::
  593. Handle extra ioctls. Should return -ENOTTY if ioctl is not known to
  594. the channel
  595. echocan_create::
  596. Create a custom echo canceller. Normally used for providing a hardware
  597. echo canceller. If NULL, the standard DAHDI echo canceller modules
  598. will be used.
  599. rbsbits::
  600. Copy signalling bits to device. See below on signalling.
  601. hooksig::
  602. Implement RBS-like signalling-handling. See below on signalling.
  603. sethook::
  604. Handle signalling yourself. See below on signalling.
  605. hdlc_hard_xmit::
  606. Used to tell an onboard HDLC controller that there is data ready to
  607. transmit.
  608. audio_notify::
  609. (if DAHDI_AUDIO_NOTIFY is set) - be notified when the channel is (or
  610. isn't) in audio mode. Which may mean (for an ISDN B-channel) that its
  611. data need not be sent.
  612. There are several alternative methods for a span to use for
  613. signalling. One of them should be used.
  614. Signalling: rbsbits
  615. ^^^^^^^^^^^^^^^^^^^
  616. If the device is a CAS interface, the driver should copy the signalling
  617. bits to and from the other side, and DAHDI will handle the signalling.
  618. The driver just need to provide a 'rbsbits' and set DAHDI_FLAG_RBS in
  619. the span->flags.
  620. Note that 'rbs' (Robed Bits Signalling) here merely refers to the (up
  621. to) 4 signalling bits of the channel. In T1 they are transmitted by
  622. "robbing" bits from the channels and hence the name. In E1 they are
  623. transmitted in a timeframe of their own.
  624. The driver should then signal a change in the signalling bits in a
  625. channel using dahdi_rbsbits().
  626. Signalling: hooksig
  627. ^^^^^^^^^^^^^^^^^^^
  628. If the device does not know about signalling bits, but has their
  629. equivalents (i.e. can disconnect battery, detect off hook, generate
  630. ring, etc directly) then the driver can specify a 'sethook' function and
  631. set DAHDI_FLAG_RBS in span->flags. In that case DAHDI will call that
  632. function whenever the signalling state changes.
  633. The hooksig function is only used if the rbsbits function is not set.
  634. The span should notify DAHDI of a change of signalling in a channel using
  635. dahdi_hooksig().
  636. Signalling: sethook
  637. ^^^^^^^^^^^^^^^^^^^
  638. Alternatively, if DAHDI_FLAG_RBS is not set in the flags of the span (to
  639. use either rbsbits or hooksig), the DAHDI core will try to call the
  640. 'sethook' function of the span (if it exists) to handle individual hook
  641. states.
  642. The span should then notify DAHDI of a change in the signalling state
  643. using dahdi_sethook().
  644. FIXME: anybody using this one?
  645. ABI Compatibility
  646. ~~~~~~~~~~~~~~~~~
  647. Like any other kernel code, DAHDI strives to maintain a stable interface to
  648. userspace programs. The API of DAHDI to userspace programs, dahdi/user.h, has
  649. remained backward-compatible for a long time and is expected to remain so in
  650. the future. With the ABI (the bits themselves) things are slightly trickier.
  651. DAHDI's interface to userspace is mostly ioctl(3) calls. Ioctl calls
  652. are identified by a number that stems from various things, one of which
  653. is the size of the data structure passed between the kernel and
  654. userspace.
  655. Many of the DAHDI ioctl-s use some specific structs to pass information
  656. between kernel and userspace. In some cases the need arose to pass a few
  657. more data members in each call. Simply adding a new member to the struct
  658. would have meant a new number for the ioctl, as its number depends on
  659. the size of the data passed.
  660. Thus we would add a new ioctl with the same base number and with the
  661. original struct.
  662. So suppose we had the following ioctl:
  663. ----------------------------------
  664. struct dahdi_example {
  665. int sample;
  666. }
  667. #define DAHDI_EXAMPLE _IOWR (DAHDI_CODE, 62, struct dahdi_example)
  668. ----------------------------------
  669. And we want to add the field 'int onemore', we won't just add it to the
  670. struct. We will do something that is more complex:
  671. ------------------------------------
  672. /* The original, unchanged: */
  673. struct dahdi_example_v1 {
  674. int sample;
  675. }
  676. /* The new struct: */
  677. struct dahdi_example {
  678. int sample;
  679. int onemore;
  680. }
  681. #define DAHDI_EXAMPLE_V1 _IOWR(DAHDI_CODE, 62, struct dahdi_example_v1)
  682. #define DAHDI_EXAMPLE _IOWR(DAHDI_CODE, 62, struct dahdi_example)
  683. ------------------------------------
  684. We actually have here two different ioctls: the old DAHDI_EXAMPLE would be
  685. 0xC004DA3E . DAHDI_EXAMPLE_V1 would have the same value. But the new value
  686. of DAHDI_EXAMPLE would be 0xC008DA3E .
  687. Programs built with the original dahdi/user.h (before the change) use the
  688. original ioctl, whether or not the kernel code is actually of the newer
  689. version. Thus in most cases there are no compatibility issues.
  690. When can we have compatibility issues? If we have code built with the new
  691. dahdi/user.h, but the loaded kernel code (modules) are of the older version.
  692. Thus the userspace program will try to use the newer DAHDI_EXAMPLE (0xC008DA3E).
  693. But the kernel code has no handler for that ioctl. The result: the error 25,
  694. ENOTTY, which means "Inappropriate ioctl for device".
  695. As a by-product of that method, for each interface change a new #define is
  696. added. That definition is for the old version and thus it might appear
  697. slightly confusing in the code, but it is useful for writing code that works
  698. with all versions of DAHDI.
  699. Past Incompatibilities
  700. ^^^^^^^^^^^^^^^^^^^^^^
  701. .DAHDI 2.3:
  702. DAHDI_SPANINFO_V1 (extra members added). This will typically only be
  703. used on ISDN (PRI/BRI) spans in Asterisk.
  704. .DAHDI 2.2:
  705. * DAHDI_GET_PARAMS_V1, DAHDI_GETCONF_V1, DAHDI_SETCONF_V1,
  706. DAHDI_GETGAINS_V1 ('direction' changed from 'R' to 'RW' to fix
  707. FreeBSD support).
  708. * DAHDI_CONFDIAG_V1, DAHDI_CHANDIAG_V1 (fixed direction).
  709. Alarm Types
  710. ~~~~~~~~~~~
  711. An alarm indicates that a port is not available for some reason. Thus it
  712. is probably not a good idea to try to call out through it.
  713. Red Alarm
  714. ^^^^^^^^^
  715. Your T1/E1 port will go into red alarm when it cannot maintain
  716. synchronization with the remote switch. A red alarm typically
  717. indicates either a physical wiring problem, loss of connectivity, or a
  718. framing and/or line-coding mismatch with the remote switch. When your
  719. T1/E1 port loses sync, it will transmit a yellow alarm to the remote
  720. switch to indicate that it's having a problem receiving signal from
  721. the remote switch.
  722. The easy way to remember this is that the R in red stands for "right
  723. here" and "receive"... indicating that we're having a problem right
  724. here receiving the signal from the remote switch.
  725. Yellow Alarm
  726. ^^^^^^^^^^^^
  727. (RAI -- Remote Alarm Indication)
  728. Your T1/E1 port will go into yellow alarm when it receives a signal
  729. from the remote switch that the port on that remote switch is in red
  730. alarm. This essentially means that the remote switch is not able to
  731. maintain sync with you, or is not receiving your transmission.
  732. The easy way to remember this is that the Y in yellow stands for
  733. "yonder"... indicating that the remote switch (over yonder) isn't able
  734. to see what you're sending.
  735. Blue Alarm
  736. ^^^^^^^^^^
  737. (AIS -- Alarm Indication Signal)
  738. Your T1/E1 port will go into blue alarm when it receives all unframed
  739. 1s on all timeslots from the remote switch. This is a special signal
  740. to indicate that the remote switch is having problems with its
  741. upstream connection. dahdi_tool and Asterisk don't correctly indicate
  742. a blue alarm at this time. The easy way to remember this is that
  743. streams are blue, so a blue alarm indicates a problem upstream from
  744. the switch you're connected to.
  745. Recovering from Alarm
  746. ^^^^^^^^^^^^^^^^^^^^^
  747. TODO: explain.
  748. Loopback
  749. ^^^^^^^^
  750. Not really an alarm. Indicates that a span is not available, as the port
  751. is in either a local or remote loopback mode.
  752. Not Open
  753. ^^^^^^^^
  754. Something is not connected. Used by e.g. the drivers of the Astribank to
  755. indicate a span that belongs to a device that has been disconnected
  756. but is still being used by userspace programs and thus can't e
  757. destroyed.
  758. License
  759. -------
  760. This package is distributed under the terms of the GNU General Public License
  761. Version 2, except for some components which are distributed under the terms of
  762. the GNU Lesser General Public License Version 2.1. Both licenses are included
  763. in this directory, and each file is clearly marked as to which license applies.
  764. If you wish to use the DAHDI drivers in an application for which the license
  765. terms are not appropriate (e.g. a proprietary embedded system), licenses under
  766. more flexible terms can be readily obtained through Digium, Inc. at reasonable
  767. cost.
  768. Known Issues
  769. ------------
  770. KB1 does not function when echocancel > 128
  771. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  772. KB1 was not designed to function at greater than 128 taps, and if configured
  773. this way, will result in the destruction of audio. Ideally DAHDI would return
  774. an error when a KB1 echocanceller is configured with greater than 128 taps.
  775. Reporting Bugs
  776. --------------
  777. Please report bug and patches to the Asterisk bug tracker at
  778. http://issues.asterisk.org in the "DAHDI-linux" category.
  779. Links
  780. -----
  781. - http://asterisk.org/[] - The Asterisk PBX
  782. - http://voip-info.org/[]
  783. - http://voip-info.org/wiki/view/DAHDI[]
  784. - http://docs.tzafrir.org.il/dahdi-linux/README.html[Up-to-date HTML version
  785. of this file]