kernel.h 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349
  1. /*
  2. * DAHDI Telephony Interface
  3. *
  4. * Written by Mark Spencer <markster@digium.com>
  5. * Based on previous works, designs, and architectures conceived and
  6. * written by Jim Dixon <jim@lambdatel.com>.
  7. *
  8. * Copyright (C) 2001 Jim Dixon / Zapata Telephony.
  9. * Copyright (C) 2001 - 2010 Digium, Inc.
  10. *
  11. * All rights reserved.
  12. *
  13. */
  14. /*
  15. * See http://www.asterisk.org for more information about
  16. * the Asterisk project. Please do not directly contact
  17. * any of the maintainers of this project for assistance;
  18. * the project provides a web site, mailing lists and IRC
  19. * channels for your use.
  20. *
  21. * This program is free software, distributed under the terms of
  22. * the GNU General Public License Version 2 as published by the
  23. * Free Software Foundation. See the LICENSE file included with
  24. * this program for more details.
  25. */
  26. /*!
  27. * \file
  28. * \brief DAHDI kernel interface definitions
  29. */
  30. #ifndef _DAHDI_KERNEL_H
  31. #define _DAHDI_KERNEL_H
  32. #include <dahdi/user.h>
  33. #include <dahdi/fasthdlc.h>
  34. #include <dahdi/dahdi_config.h>
  35. #include <linux/version.h>
  36. #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
  37. #include <linux/config.h>
  38. #endif
  39. #include <linux/fs.h>
  40. #include <linux/kobject.h>
  41. #include <linux/module.h>
  42. #include <linux/ioctl.h>
  43. #ifdef CONFIG_DAHDI_NET
  44. #include <linux/hdlc.h>
  45. #endif
  46. #ifdef CONFIG_DAHDI_PPP
  47. #include <linux/ppp_channel.h>
  48. #include <linux/skbuff.h>
  49. #include <linux/interrupt.h>
  50. #endif
  51. #include <linux/poll.h>
  52. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,10)
  53. #define dahdi_pci_module pci_register_driver
  54. #else
  55. #define dahdi_pci_module pci_module_init
  56. #endif
  57. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19)
  58. #define DAHDI_IRQ_HANDLER(a) static irqreturn_t a(int irq, void *dev_id)
  59. #else
  60. #define DAHDI_IRQ_HANDLER(a) static irqreturn_t a(int irq, void *dev_id, struct pt_regs *regs)
  61. #endif
  62. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29)
  63. #define HAVE_NET_DEVICE_OPS
  64. #endif
  65. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
  66. #define DAHDI_IRQ_SHARED IRQF_SHARED
  67. #define DAHDI_IRQ_DISABLED IRQF_DISABLED
  68. #define DAHDI_IRQ_SHARED_DISABLED IRQF_SHARED | IRQF_DISABLED
  69. #else
  70. #define DAHDI_IRQ_SHARED SA_SHIRQ
  71. #define DAHDI_IRQ_DISABLED SA_INTERRUPT
  72. #define DAHDI_IRQ_SHARED_DISABLED SA_SHIRQ | SA_INTERRUPT
  73. #endif
  74. #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,16)
  75. #ifndef dev_notice
  76. #define dev_notice(dev, format, arg...) \
  77. dev_printk(KERN_NOTICE , dev , format , ## arg)
  78. #endif
  79. #endif
  80. #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26)
  81. # ifdef RHEL_RELEASE_VERSION
  82. # if RHEL_RELEASE_CODE < RHEL_RELEASE_VERSION(5, 6)
  83. #define dev_name(dev) ((dev)->bus_id)
  84. # endif
  85. # else
  86. #define dev_name(dev) ((dev)->bus_id)
  87. # endif
  88. #define dev_set_name(dev, format, ...) \
  89. snprintf((dev)->bus_id, BUS_ID_SIZE, format, ## __VA_ARGS__);
  90. #endif
  91. /*! Default chunk size for conferences and such -- static right now, might make
  92. variable sometime. 8 samples = 1 ms = most frequent service interval possible
  93. for a USB device */
  94. #define DAHDI_CHUNKSIZE 8
  95. #define DAHDI_MIN_CHUNKSIZE DAHDI_CHUNKSIZE
  96. #define DAHDI_DEFAULT_CHUNKSIZE DAHDI_CHUNKSIZE
  97. #define DAHDI_MAX_CHUNKSIZE DAHDI_CHUNKSIZE
  98. #define DAHDI_CB_SIZE 2
  99. #define RING_DEBOUNCE_TIME 2000 /*!< 2000 ms ring debounce time */
  100. typedef struct
  101. {
  102. int32_t gain;
  103. int32_t a1;
  104. int32_t a2;
  105. int32_t b1;
  106. int32_t b2;
  107. int32_t z1;
  108. int32_t z2;
  109. } biquad2_state_t;
  110. typedef struct
  111. {
  112. biquad2_state_t notch;
  113. int notch_level;
  114. int channel_level;
  115. int tone_present;
  116. int tone_cycle_duration;
  117. int good_cycles;
  118. int hit;
  119. } echo_can_disable_detector_state_t;
  120. struct sf_detect_state {
  121. long x1;
  122. long x2;
  123. long y1;
  124. long y2;
  125. long e1;
  126. long e2;
  127. int samps;
  128. int lastdetect;
  129. };
  130. struct dahdi_tone_state {
  131. int v1_1;
  132. int v2_1;
  133. int v3_1;
  134. int v1_2;
  135. int v2_2;
  136. int v3_2;
  137. int modulate;
  138. };
  139. /*! \brief Conference queue structure */
  140. struct confq {
  141. u_char buffer[DAHDI_CHUNKSIZE * DAHDI_CB_SIZE];
  142. u_char *buf[DAHDI_CB_SIZE];
  143. int inbuf;
  144. int outbuf;
  145. };
  146. struct dahdi_chan;
  147. struct dahdi_echocan_state;
  148. /*! Features a DAHDI echo canceler (software or hardware) can provide to the DAHDI core. */
  149. struct dahdi_echocan_features {
  150. /*! Able to detect CED tone (2100 Hz with phase reversals) in the transmit direction.
  151. * If the echocan can detect this tone, it may report it it as an event (see
  152. * the events.CED_tx_detected field of dahdi_echocan_state), and if it will automatically
  153. * disable itself or its non-linear processor, then the NLP_automatic feature flag should also
  154. * be set so that the DAHDI core doesn't bother trying to do so.
  155. */
  156. u32 CED_tx_detect:1;
  157. /*! Able to detect CED tone (2100 Hz with phase reversals) in the receive direction.
  158. * If the echocan can detect this tone, it may report it it as an event (see
  159. * the events.CED_rx_detected field of dahdi_echocan_state), and if it will automatically
  160. * disable itself or its non-linear processor, then the NLP_automatic flag feature should also
  161. * be set so that the DAHDI core doesn't bother trying to do so.
  162. */
  163. u32 CED_rx_detect:1;
  164. /*! Able to detect CNG tone (1100 Hz) in the transmit direction. */
  165. u32 CNG_tx_detect:1;
  166. /*! Able to detect CNG tone (1100 Hz) in the receive direction. */
  167. u32 CNG_rx_detect:1;
  168. /*! If the echocan's NLP can be enabled and disabled without requiring destruction
  169. * and recreation of the state structure, this feature flag should be set and the
  170. * echocan_NLP_toggle field of the dahdi_echocan_ops structure should be filled with a
  171. * pointer to the function to perform that operation.
  172. */
  173. u32 NLP_toggle:1;
  174. /*! If the echocan will automatically disable itself (or even just its NLP) based on
  175. * detection of a CED tone in either direction, this feature flag should be set (along
  176. * with the tone detection feature flags).
  177. */
  178. u32 NLP_automatic:1;
  179. };
  180. /*! Operations (methods) that can be performed on a DAHDI echo canceler instance (state
  181. * structure) after it has been created, by either a software or hardware echo canceller.
  182. * The echo canceler must populate the owner field of the dahdi_echocan_state structure
  183. * with a pointer to the relevant operations structure for that instance.
  184. */
  185. struct dahdi_echocan_ops {
  186. /*! The name of the echocan that created this structure. */
  187. const char *name;
  188. /*! \brief Free an echocan state structure.
  189. * \param[in,out] ec Pointer to the state structure to free.
  190. *
  191. * \return Nothing.
  192. */
  193. void (*echocan_free)(struct dahdi_chan *chan, struct dahdi_echocan_state *ec);
  194. /*! \brief Process an array of audio samples through the echocan.
  195. * \param[in,out] ec Pointer to the state structure.
  196. * \param[in,out] isig The receive direction data (will be modified).
  197. * \param[in] iref The transmit direction data.
  198. * \param[in] size The number of elements in the isig and iref arrays.
  199. *
  200. * Note: This function can also return events in the events field of the
  201. * dahdi_echocan_state structure. If it can do so, then the echocan does
  202. * not need to provide the echocan_events function.
  203. *
  204. * \return Nothing.
  205. */
  206. void (*echocan_process)(struct dahdi_echocan_state *ec, short *isig, const short *iref, u32 size);
  207. /*! \brief Retrieve events from the echocan.
  208. * \param[in,out] ec Pointer to the state structure.
  209. *
  210. *
  211. * If any events have occurred, the events field of the dahdi_echocan_state
  212. * structure should be updated to include them.
  213. *
  214. * \return Nothing.
  215. */
  216. void (*echocan_events)(struct dahdi_echocan_state *ec);
  217. /*! \brief Feed a sample (and its position) for echocan training.
  218. * \param[in,out] ec Pointer to the state structure.
  219. * \param[in] pos The tap position to be 'trained'.
  220. * \param[in] val The receive direction sample for the specified tap position.
  221. *
  222. * \retval Zero if training should continue.
  223. * \retval Non-zero if training is complete.
  224. */
  225. int (*echocan_traintap)(struct dahdi_echocan_state *ec, int pos, short val);
  226. /*! \brief Enable or disable non-linear processing (NLP) in the echocan.
  227. * \param[in,out] ec Pointer to the state structure.
  228. * \param[in] enable Zero to disable, non-zero to enable.
  229. *
  230. * \return Nothing.
  231. */
  232. void (*echocan_NLP_toggle)(struct dahdi_echocan_state *ec, unsigned int enable);
  233. };
  234. /*! A factory for creating instances of software echo cancelers to be used on DAHDI channels. */
  235. struct dahdi_echocan_factory {
  236. /*! The name of the factory. */
  237. const char *name;
  238. /*! Pointer to the module that owns this factory; the module's reference count will be
  239. * incremented/decremented by the DAHDI core as needed.
  240. */
  241. struct module *owner;
  242. /*! \brief Function to create an instance of the echocan.
  243. * \param[in] ecp Structure defining parameters to be used for the instance creation.
  244. * \param[in] p Pointer to the beginning of an (optional) array of user-defined parameters.
  245. * \param[out] ec Pointer to the state structure that is created, if any.
  246. *
  247. * \retval Zero on success.
  248. * \retval Non-zero on failure (return value will be returned to userspace so it should be a
  249. * standard error number).
  250. */
  251. int (*echocan_create)(struct dahdi_chan *chan, struct dahdi_echocanparams *ecp,
  252. struct dahdi_echocanparam *p, struct dahdi_echocan_state **ec);
  253. };
  254. /*! \brief Register an echo canceler factory with the DAHDI core.
  255. * \param[in] ec Pointer to the dahdi_echocan_factory structure to be registered.
  256. *
  257. * \retval Zero on success.
  258. * \retval Non-zero on failure (return value will be a standard error number).
  259. */
  260. int dahdi_register_echocan_factory(const struct dahdi_echocan_factory *ec);
  261. /*! \brief Unregister a previously-registered echo canceler factory from the DAHDI core.
  262. * \param[in] ec Pointer to the dahdi_echocan_factory structure to be unregistered.
  263. *
  264. * \return Nothing.
  265. */
  266. void dahdi_unregister_echocan_factory(const struct dahdi_echocan_factory *ec);
  267. enum dahdi_echocan_mode {
  268. __ECHO_MODE_MUTE = 1 << 8,
  269. ECHO_MODE_IDLE = 0,
  270. ECHO_MODE_PRETRAINING = 1 | __ECHO_MODE_MUTE,
  271. ECHO_MODE_STARTTRAINING = 2 | __ECHO_MODE_MUTE,
  272. ECHO_MODE_AWAITINGECHO = 3 | __ECHO_MODE_MUTE,
  273. ECHO_MODE_TRAINING = 4 | __ECHO_MODE_MUTE,
  274. ECHO_MODE_ACTIVE = 5,
  275. ECHO_MODE_FAX = 6,
  276. };
  277. /*! An instance of a DAHDI echo canceler (software or hardware). */
  278. struct dahdi_echocan_state {
  279. /*! Pointer to a dahdi_echocan_ops structure of operations that can be
  280. * performed on this instance.
  281. */
  282. const struct dahdi_echocan_ops *ops;
  283. /*! State data used by the DAHDI core's CED detector for the transmit
  284. * direction, if needed.
  285. */
  286. echo_can_disable_detector_state_t txecdis;
  287. /*! State data used by the DAHDI core's CED detector for the receive
  288. * direction, if needed.
  289. */
  290. echo_can_disable_detector_state_t rxecdis;
  291. /*! Features offered by the echo canceler that provided this instance. */
  292. struct dahdi_echocan_features features;
  293. struct {
  294. /*! The mode the echocan is currently in. */
  295. enum dahdi_echocan_mode mode;
  296. /*! The last tap position that was fed to the echocan's training function. */
  297. u32 last_train_tap;
  298. /*! How many samples to wait before beginning the training operation. */
  299. u32 pretrain_timer;
  300. } status;
  301. /*! This structure contains event flags, allowing the echocan to report
  302. * events that occurred as it processed the transmit and receive streams
  303. * of samples. Each call to the echocan_process operation for this
  304. * instance may report events, so the structure should be cleared before
  305. * calling that operation.
  306. */
  307. union dahdi_echocan_events {
  308. u32 all;
  309. struct {
  310. /*! CED tone was detected in the transmit direction. If the
  311. * echocan automatically disables its NLP when this occurs,
  312. * it must also signal the NLP_auto_disabled event during the *same*
  313. * call to echocan_process that reports the CED detection.
  314. */
  315. u32 CED_tx_detected:1;
  316. /*! CED tone was detected in the receive direction. If the
  317. * echocan automatically disables its NLP when this occurs,
  318. * it must also signal the NLP_auto_disabled event during the *same*
  319. * call to echocan_process that reports the CED detection.
  320. */
  321. u32 CED_rx_detected:1;
  322. /*! CNG tone was detected in the transmit direction. */
  323. u32 CNG_tx_detected:1;
  324. /*! CNG tone was detected in the receive direction. */
  325. u32 CNG_rx_detected:1;
  326. /*! The echocan disabled its NLP automatically.
  327. */
  328. u32 NLP_auto_disabled:1;
  329. /*! The echocan enabled its NLP automatically.
  330. */
  331. u32 NLP_auto_enabled:1;
  332. } bit;
  333. } events;
  334. };
  335. struct dahdi_chan {
  336. #ifdef CONFIG_DAHDI_NET
  337. /*! \note Must be first */
  338. struct dahdi_hdlc *hdlcnetdev;
  339. #endif
  340. #ifdef CONFIG_DAHDI_PPP
  341. struct ppp_channel *ppp;
  342. struct tasklet_struct ppp_calls;
  343. int do_ppp_wakeup;
  344. int do_ppp_error;
  345. struct sk_buff_head ppp_rq;
  346. #endif
  347. #ifdef BUFFER_DEBUG
  348. int statcount;
  349. int lastnumbufs;
  350. #endif
  351. spinlock_t lock;
  352. char name[40];
  353. /* Specified by DAHDI */
  354. /*! \brief DAHDI channel number */
  355. int channo;
  356. int chanpos;
  357. unsigned long flags;
  358. long rxp1;
  359. long rxp2;
  360. long rxp3;
  361. int txtone;
  362. int tx_v2;
  363. int tx_v3;
  364. int v1_1;
  365. int v2_1;
  366. int v3_1;
  367. int toneflags;
  368. struct sf_detect_state rd;
  369. struct dahdi_chan *master; /*!< Our Master channel (could be us) */
  370. /*! \brief Next slave (if appropriate) */
  371. int nextslave;
  372. u_char *writechunk; /*!< Actual place to write to */
  373. u_char swritechunk[DAHDI_MAX_CHUNKSIZE]; /*!< Buffer to be written */
  374. u_char *readchunk; /*!< Actual place to read from */
  375. u_char sreadchunk[DAHDI_MAX_CHUNKSIZE]; /*!< Preallocated static area */
  376. short *readchunkpreec;
  377. /*! Pointer to tx and rx gain tables */
  378. u_char *rxgain;
  379. u_char *txgain;
  380. /*! Whether or not we have allocated gains or are using the default */
  381. int gainalloc;
  382. /* Specified by driver, readable by DAHDI */
  383. void *pvt; /*!< Private channel data */
  384. struct file *file; /*!< File structure */
  385. struct dahdi_span *span; /*!< Span we're a member of */
  386. int sig; /*!< Signalling */
  387. int sigcap; /*!< Capability for signalling */
  388. __u32 chan_alarms; /*!< alarms status */
  389. /* Used only by DAHDI -- NO DRIVER SERVICEABLE PARTS BELOW */
  390. /* Buffer declarations */
  391. u_char *readbuf[DAHDI_MAX_NUM_BUFS]; /*!< read buffer */
  392. int inreadbuf;
  393. int outreadbuf;
  394. wait_queue_head_t readbufq; /*!< read wait queue */
  395. u_char *writebuf[DAHDI_MAX_NUM_BUFS]; /*!< write buffers */
  396. int inwritebuf;
  397. int outwritebuf;
  398. wait_queue_head_t writebufq; /*!< write wait queue */
  399. int blocksize; /*!< Block size */
  400. int eventinidx; /*!< out index in event buf (circular) */
  401. int eventoutidx; /*!< in index in event buf (circular) */
  402. unsigned int eventbuf[DAHDI_MAX_EVENTSIZE]; /*!< event circ. buffer */
  403. wait_queue_head_t eventbufq; /*!< event wait queue */
  404. wait_queue_head_t txstateq; /*!< waiting on the tx state to change */
  405. int readn[DAHDI_MAX_NUM_BUFS]; /*!< # of bytes ready in read buf */
  406. int readidx[DAHDI_MAX_NUM_BUFS]; /*!< current read pointer */
  407. int writen[DAHDI_MAX_NUM_BUFS]; /*!< # of bytes ready in write buf */
  408. int writeidx[DAHDI_MAX_NUM_BUFS]; /*!< current write pointer */
  409. int numbufs; /*!< How many buffers in channel */
  410. int txbufpolicy; /*!< Buffer policy */
  411. int rxbufpolicy; /*!< Buffer policy */
  412. int txdisable; /*!< Disable transmitter */
  413. int rxdisable; /*!< Disable receiver */
  414. /* Tone zone stuff */
  415. struct dahdi_zone *curzone; /*!< Zone for selecting tones */
  416. int tonezone; /*!< Tone zone for this channel */
  417. struct dahdi_tone *curtone; /*!< Current tone we're playing (if any) */
  418. int tonep; /*!< Current position in tone */
  419. struct dahdi_tone_state ts; /*!< Tone state */
  420. /* Pulse dial stuff */
  421. int pdialcount; /*!< pulse dial count */
  422. /*! Ring cadence */
  423. int ringcadence[DAHDI_MAX_CADENCE];
  424. int firstcadencepos; /*!< Where to restart ring cadence */
  425. /* Digit string dialing stuff */
  426. int digitmode; /*!< What kind of tones are we sending? */
  427. char txdialbuf[DAHDI_MAX_DTMF_BUF];
  428. int dialing;
  429. int afterdialingtimer;
  430. int cadencepos; /*!< Where in the cadence we are */
  431. /* I/O Mask */
  432. int iomask; /*! I/O Mux signal mask */
  433. wait_queue_head_t sel; /*! thingy for select stuff */
  434. /* HDLC state machines */
  435. struct fasthdlc_state txhdlc;
  436. struct fasthdlc_state rxhdlc;
  437. int infcs;
  438. /* Conferencing stuff */
  439. int confna; /*! conference number (alias) */
  440. int _confn; /*! Actual conference number */
  441. int confmode; /*! conference mode */
  442. int confmute; /*! conference mute mode */
  443. /* Incoming and outgoing conference chunk queues for
  444. communicating between DAHDI master time and
  445. other boards */
  446. struct confq confin;
  447. struct confq confout;
  448. short getlin[DAHDI_MAX_CHUNKSIZE]; /*!< Last transmitted samples */
  449. unsigned char getraw[DAHDI_MAX_CHUNKSIZE]; /*!< Last received raw data */
  450. short getlin_lastchunk[DAHDI_MAX_CHUNKSIZE]; /*!< Last transmitted samples from last chunk */
  451. short putlin[DAHDI_MAX_CHUNKSIZE]; /*!< Last received samples */
  452. unsigned char putraw[DAHDI_MAX_CHUNKSIZE]; /*!< Last received raw data */
  453. short conflast[DAHDI_MAX_CHUNKSIZE]; /*!< Last conference sample -- base part of channel */
  454. short conflast1[DAHDI_MAX_CHUNKSIZE]; /*!< Last conference sample -- pseudo part of channel */
  455. short conflast2[DAHDI_MAX_CHUNKSIZE]; /*!< Previous last conference sample -- pseudo part of channel */
  456. /*! The echo canceler module that should be used to create an
  457. instance when this channel needs one */
  458. const struct dahdi_echocan_factory *ec_factory;
  459. /*! The echo canceler module that owns the instance currently
  460. on this channel, if one is present */
  461. const struct dahdi_echocan_factory *ec_current;
  462. /*! The state data of the echo canceler instance in use */
  463. struct dahdi_echocan_state *ec_state;
  464. /* RBS timings */
  465. int prewinktime; /*!< pre-wink time (ms) */
  466. int preflashtime; /*!< pre-flash time (ms) */
  467. int winktime; /*!< wink time (ms) */
  468. int flashtime; /*!< flash time (ms) */
  469. int starttime; /*!< start time (ms) */
  470. int rxwinktime; /*!< rx wink time (ms) */
  471. int rxflashtime; /*!< rx flash time (ms) */
  472. int debouncetime; /*!< FXS GS sig debounce time (ms) */
  473. int pulsebreaktime; /*!< pulse line open time (ms) */
  474. int pulsemaketime; /*!< pulse line closed time (ms) */
  475. int pulseaftertime; /*!< pulse time between digits (ms) */
  476. /*! RING debounce timer */
  477. int ringdebtimer;
  478. /*! RING trailing detector to make sure a RING is really over */
  479. int ringtrailer;
  480. /* PULSE digit receiver stuff */
  481. int pulsecount;
  482. int pulsetimer;
  483. /* RBS timers */
  484. int itimerset; /*!< what the itimer was set to last */
  485. int itimer;
  486. int otimer;
  487. /* RBS state */
  488. int gotgs;
  489. int txstate;
  490. int rxsig;
  491. int txsig;
  492. int rxsigstate;
  493. /* non-RBS rx state */
  494. int rxhooksig;
  495. int txhooksig;
  496. int kewlonhook;
  497. /*! Idle signalling if CAS signalling */
  498. int idlebits;
  499. int deflaw; /*! 1 = mulaw, 2=alaw, 0=undefined */
  500. short *xlaw;
  501. #ifdef OPTIMIZE_CHANMUTE
  502. int chanmute; /*!< no need for PCM data */
  503. #endif
  504. #ifdef CONFIG_CALC_XLAW
  505. unsigned char (*lineartoxlaw)(short a);
  506. #else
  507. unsigned char *lin2x;
  508. #endif
  509. };
  510. #ifdef CONFIG_DAHDI_NET
  511. struct dahdi_hdlc {
  512. struct net_device *netdev;
  513. struct dahdi_chan *chan;
  514. };
  515. #endif
  516. /*! Define the maximum block size */
  517. #define DAHDI_MAX_BLOCKSIZE 8192
  518. #define DAHDI_DEFAULT_WINKTIME 150 /*!< 150 ms default wink time */
  519. #define DAHDI_DEFAULT_FLASHTIME 750 /*!< 750 ms default flash time */
  520. #define DAHDI_DEFAULT_PREWINKTIME 50 /*!< 50 ms before wink */
  521. #define DAHDI_DEFAULT_PREFLASHTIME 50 /*!< 50 ms before flash */
  522. #define DAHDI_DEFAULT_STARTTIME 1500 /*!< 1500 ms of start */
  523. #define DAHDI_DEFAULT_RINGTIME 2000 /*!< 2000 ms of ring on (start, FXO) */
  524. #if 0
  525. #define DAHDI_DEFAULT_RXWINKTIME 250 /*!< 250ms longest rx wink */
  526. #endif
  527. #define DAHDI_DEFAULT_RXWINKTIME 300 /*!< 300ms longest rx wink (to work with the Atlas) */
  528. #define DAHDI_DEFAULT_RXFLASHTIME 1250 /*!< 1250ms longest rx flash */
  529. #define DAHDI_DEFAULT_DEBOUNCETIME 600 /*!< 600ms of FXS GS signalling debounce */
  530. #define DAHDI_DEFAULT_PULSEMAKETIME 50 /*!< 50 ms of line closed when dial pulsing */
  531. #define DAHDI_DEFAULT_PULSEBREAKTIME 50 /*!< 50 ms of line open when dial pulsing */
  532. #define DAHDI_DEFAULT_PULSEAFTERTIME 750 /*!< 750ms between dial pulse digits */
  533. #define DAHDI_MINPULSETIME (15 * 8) /*!< 15 ms minimum */
  534. #ifdef SHORT_FLASH_TIME
  535. #define DAHDI_MAXPULSETIME (80 * 8) /*!< we need 80 ms, not 200ms, as we have a short flash */
  536. #else
  537. #define DAHDI_MAXPULSETIME (200 * 8) /*!< 200 ms maximum */
  538. #endif
  539. #define DAHDI_PULSETIMEOUT ((DAHDI_MAXPULSETIME / 8) + 50)
  540. #define DAHDI_RINGTRAILER (50 * 8) /*!< Don't consider a ring "over" until it's been gone at least this
  541. much time */
  542. #define DAHDI_LOOPCODE_TIME 10000 /*!< send loop codes for 10 secs */
  543. #define DAHDI_ALARMSETTLE_TIME 5000 /*!< allow alarms to settle for 5 secs */
  544. #define DAHDI_AFTERSTART_TIME 500 /*!< 500ms after start */
  545. #define DAHDI_RINGOFFTIME 4000 /*!< Turn off ringer for 4000 ms */
  546. #define DAHDI_KEWLTIME 500 /*!< 500ms for kewl pulse */
  547. #define DAHDI_AFTERKEWLTIME 300 /*!< 300ms after kewl pulse */
  548. #define DAHDI_MAX_PRETRAINING 1000 /*!< 1000ms max pretraining time */
  549. #ifdef FXSFLASH
  550. #define DAHDI_FXSFLASHMINTIME 450 /*!< min 450ms */
  551. #define DAHDI_FXSFLASHMAXTIME 550 /*!< max 550ms */
  552. #endif
  553. struct dahdi_chardev {
  554. const char *name;
  555. __u8 minor;
  556. };
  557. int dahdi_register_chardev(struct dahdi_chardev *dev);
  558. int dahdi_unregister_chardev(struct dahdi_chardev *dev);
  559. /*! \brief defines for transmit signalling */
  560. enum dahdi_txsig {
  561. DAHDI_TXSIG_ONHOOK, /*!< On hook */
  562. DAHDI_TXSIG_OFFHOOK, /*!< Off hook */
  563. DAHDI_TXSIG_START, /*!< Start / Ring */
  564. DAHDI_TXSIG_KEWL, /*!< Drop battery if possible */
  565. /*! Leave this as the last entry */
  566. DAHDI_TXSIG_TOTAL,
  567. };
  568. enum dahdi_rxsig {
  569. DAHDI_RXSIG_ONHOOK,
  570. DAHDI_RXSIG_OFFHOOK,
  571. DAHDI_RXSIG_START,
  572. DAHDI_RXSIG_RING,
  573. DAHDI_RXSIG_INITIAL
  574. };
  575. enum {
  576. /* Span flags */
  577. DAHDI_FLAGBIT_REGISTERED= 0,
  578. DAHDI_FLAGBIT_RUNNING = 1,
  579. DAHDI_FLAGBIT_RBS = 12, /*!< Span uses RBS signalling */
  580. /* Channel flags */
  581. DAHDI_FLAGBIT_DTMFDECODE= 2, /*!< Channel supports native DTMF decode */
  582. DAHDI_FLAGBIT_MFDECODE = 3, /*!< Channel supports native MFr2 decode */
  583. DAHDI_FLAGBIT_ECHOCANCEL= 4, /*!< Channel supports native echo cancellation */
  584. DAHDI_FLAGBIT_HDLC = 5, /*!< Perform HDLC */
  585. DAHDI_FLAGBIT_NETDEV = 6, /*!< Send to network */
  586. DAHDI_FLAGBIT_PSEUDO = 7, /*!< Pseudo channel */
  587. DAHDI_FLAGBIT_CLEAR = 8, /*!< Clear channel */
  588. DAHDI_FLAGBIT_AUDIO = 9, /*!< Audio mode channel */
  589. DAHDI_FLAGBIT_OPEN = 10, /*!< Channel is open */
  590. DAHDI_FLAGBIT_FCS = 11, /*!< Calculate FCS */
  591. /* Reserve 12 for uniqueness with span flags */
  592. DAHDI_FLAGBIT_LINEAR = 13, /*!< Talk to user space in linear */
  593. DAHDI_FLAGBIT_PPP = 14, /*!< PPP is available */
  594. DAHDI_FLAGBIT_T1PPP = 15,
  595. DAHDI_FLAGBIT_SIGFREEZE = 16, /*!< Freeze signalling */
  596. DAHDI_FLAGBIT_NOSTDTXRX = 17, /*!< Do NOT do standard transmit and receive on every interrupt */
  597. DAHDI_FLAGBIT_LOOPED = 18, /*!< Loopback the receive data from the channel to the transmit */
  598. DAHDI_FLAGBIT_MTP2 = 19, /*!< Repeats last message in buffer and also discards repeating messages sent to us */
  599. DAHDI_FLAGBIT_HDLC56 = 20, /*!< Sets the given channel (if in HDLC mode) to use 56K HDLC instead of 64K */
  600. };
  601. struct dahdi_count {
  602. __u32 fe; /*!< Framing error counter */
  603. __u32 cv; /*!< Coding violations counter */
  604. __u32 bpv; /*!< Bipolar Violation counter */
  605. __u32 crc4; /*!< CRC4 error counter */
  606. __u32 ebit; /*!< current E-bit error count */
  607. __u32 fas; /*!< current FAS error count */
  608. __u32 be; /*!< current bit error count */
  609. __u32 prbs; /*!< current PRBS detected pattern */
  610. __u32 errsec; /*!< errored seconds */
  611. };
  612. /* map flagbits to flag masks */
  613. #define DAHDI_FLAG(x) (1 << (DAHDI_FLAGBIT_ ## x))
  614. /*! This is a redefinition of the flags from above to allow use of the
  615. * legacy drivers that do not use the kernel atomic bit testing and
  616. * changing routines.
  617. *
  618. * See the above descriptions for DAHDI_FLAGBIT_.... for documentation
  619. * about function. */
  620. /* Span flags */
  621. #define DAHDI_FLAG_REGISTERED DAHDI_FLAG(REGISTERED)
  622. #define DAHDI_FLAG_RUNNING DAHDI_FLAG(RUNNING)
  623. #define DAHDI_FLAG_RBS DAHDI_FLAG(RBS)
  624. /* Channel flags */
  625. #define DAHDI_FLAG_DTMFDECODE DAHDI_FLAG(DTMFDECODE)
  626. #define DAHDI_FLAG_MFDECODE DAHDI_FLAG(MFDECODE)
  627. #define DAHDI_FLAG_ECHOCANCEL DAHDI_FLAG(ECHOCANCEL)
  628. #define DAHDI_FLAG_HDLC DAHDI_FLAG(HDLC)
  629. #define DAHDI_FLAG_NETDEV DAHDI_FLAG(NETDEV)
  630. #define DAHDI_FLAG_PSEUDO DAHDI_FLAG(PSEUDO)
  631. #define DAHDI_FLAG_CLEAR DAHDI_FLAG(CLEAR)
  632. #define DAHDI_FLAG_AUDIO DAHDI_FLAG(AUDIO)
  633. #define DAHDI_FLAG_OPEN DAHDI_FLAG(OPEN)
  634. #define DAHDI_FLAG_FCS DAHDI_FLAG(FCS)
  635. /* Reserve 12 for uniqueness with span flags */
  636. #define DAHDI_FLAG_LINEAR DAHDI_FLAG(LINEAR)
  637. #define DAHDI_FLAG_PPP DAHDI_FLAG(PPP)
  638. #define DAHDI_FLAG_T1PPP DAHDI_FLAG(T1PPP)
  639. #define DAHDI_FLAG_SIGFREEZE DAHDI_FLAG(SIGFREEZE)
  640. #define DAHDI_FLAG_NOSTDTXRX DAHDI_FLAG(NOSTDTXRX)
  641. #define DAHDI_FLAG_LOOPED DAHDI_FLAG(LOOPED)
  642. #define DAHDI_FLAG_MTP2 DAHDI_FLAG(MTP2)
  643. #define DAHDI_FLAG_HDLC56 DAHDI_FLAG(HDLC56)
  644. struct dahdi_span_ops {
  645. struct module *owner; /*!< Which module is exporting this span. */
  646. /* ==== Span Callback Operations ==== */
  647. /*! Req: Set the requested chunk size. This is the unit in which you must
  648. report results for conferencing, etc */
  649. int (*setchunksize)(struct dahdi_span *span, int chunksize);
  650. /*! Opt: Configure the span (if appropriate) */
  651. int (*spanconfig)(struct dahdi_span *span, struct dahdi_lineconfig *lc);
  652. /*! Opt: Start the span */
  653. int (*startup)(struct dahdi_span *span);
  654. /*! Opt: Shutdown the span */
  655. int (*shutdown)(struct dahdi_span *span);
  656. /*! Opt: Enable maintenance modes */
  657. int (*maint)(struct dahdi_span *span, int mode);
  658. #ifdef DAHDI_SYNC_TICK
  659. /*! Opt: send sync to spans */
  660. int (*sync_tick)(struct dahdi_span *span, int is_master);
  661. #endif
  662. /* ==== Channel Callback Operations ==== */
  663. /*! Opt: Set signalling type (if appropriate) */
  664. int (*chanconfig)(struct dahdi_chan *chan, int sigtype);
  665. /*! Opt: Prepare a channel for I/O */
  666. int (*open)(struct dahdi_chan *chan);
  667. /*! Opt: Close channel for I/O */
  668. int (*close)(struct dahdi_chan *chan);
  669. /*! Opt: IOCTL */
  670. int (*ioctl)(struct dahdi_chan *chan, unsigned int cmd, unsigned long data);
  671. /* Okay, now we get to the signalling. You have several options: */
  672. /* Option 1: If you're a T1 like interface, you can just provide a
  673. rbsbits function and we'll assert robbed bits for you. Be sure to
  674. set the DAHDI_FLAG_RBS in this case. */
  675. /*! Opt: If the span uses A/B bits, set them here */
  676. int (*rbsbits)(struct dahdi_chan *chan, int bits);
  677. /*! Option 2: If you don't know about sig bits, but do have their
  678. equivalents (i.e. you can disconnect battery, detect off hook,
  679. generate ring, etc directly) then you can just specify a
  680. sethook function, and we'll call you with appropriate hook states
  681. to set. Still set the DAHDI_FLAG_RBS in this case as well */
  682. int (*hooksig)(struct dahdi_chan *chan, enum dahdi_txsig hookstate);
  683. /*! Option 3: If you can't use sig bits, you can write a function
  684. which handles the individual hook states */
  685. int (*sethook)(struct dahdi_chan *chan, int hookstate);
  686. /*! Opt: Used to tell an onboard HDLC controller that there is data ready to transmit */
  687. void (*hdlc_hard_xmit)(struct dahdi_chan *chan);
  688. /*! If the watchdog detects no received data, it will call the
  689. watchdog routine */
  690. int (*watchdog)(struct dahdi_span *span, int cause);
  691. #ifdef DAHDI_AUDIO_NOTIFY
  692. /*! Opt: audio is used, don't optimize out */
  693. int (*audio_notify)(struct dahdi_chan *chan, int yes);
  694. #endif
  695. /*! Opt: Dacs the contents of chan2 into chan1 if possible */
  696. int (*dacs)(struct dahdi_chan *chan1, struct dahdi_chan *chan2);
  697. /*! Opt: Provide echo cancellation on a channel */
  698. int (*echocan_create)(struct dahdi_chan *chan,
  699. struct dahdi_echocanparams *ecp,
  700. struct dahdi_echocanparam *p,
  701. struct dahdi_echocan_state **ec);
  702. };
  703. struct dahdi_span {
  704. spinlock_t lock;
  705. char name[40]; /*!< Span name */
  706. char desc[80]; /*!< Span description */
  707. const char *spantype; /*!< span type in text form */
  708. const char *manufacturer; /*!< span's device manufacturer */
  709. char devicetype[80]; /*!< span's device type */
  710. char location[40]; /*!< span device's location in system */
  711. int deflaw; /*!< Default law (DAHDI_MULAW or DAHDI_ALAW) */
  712. int alarms; /*!< Pending alarms on span */
  713. unsigned long flags;
  714. int irq; /*!< IRQ for this span's hardware */
  715. int lbo; /*!< Span Line-Buildout */
  716. int lineconfig; /*!< Span line configuration */
  717. int linecompat; /*!< Span line compatibility (0 for
  718. analog spans)*/
  719. int channels; /*!< Number of channels in span */
  720. int txlevel; /*!< Tx level */
  721. int rxlevel; /*!< Rx level */
  722. int syncsrc; /*!< current sync src (gets copied here) */
  723. struct dahdi_count count; /*!< Performance and Error counters */
  724. int maintstat; /*!< Maintenance state */
  725. wait_queue_head_t maintq; /*!< Maintenance queue */
  726. int mainttimer; /*!< Maintenance timer */
  727. int irqmisses; /*!< Interrupt misses */
  728. int timingslips; /*!< Clock slips */
  729. struct dahdi_chan **chans; /*!< Member channel structures */
  730. const struct dahdi_span_ops *ops; /*!< span callbacks. */
  731. /* Used by DAHDI only -- no user servicable parts inside */
  732. int spanno; /*!< Span number for DAHDI */
  733. int offset; /*!< Offset within a given card */
  734. int lastalarms; /*!< Previous alarms */
  735. #ifdef CONFIG_DAHDI_WATCHDOG
  736. int watchcounter;
  737. int watchstate;
  738. #endif
  739. };
  740. struct dahdi_transcoder_channel {
  741. void *pvt;
  742. struct dahdi_transcoder *parent;
  743. wait_queue_head_t ready;
  744. __u32 built_fmts;
  745. #define DAHDI_TC_FLAG_BUSY 1
  746. #define DAHDI_TC_FLAG_CHAN_BUILT 2
  747. #define DAHDI_TC_FLAG_NONBLOCK 3
  748. #define DAHDI_TC_FLAG_DATA_WAITING 4
  749. unsigned long flags;
  750. u32 dstfmt;
  751. u32 srcfmt;
  752. };
  753. static inline int
  754. dahdi_tc_is_built(struct dahdi_transcoder_channel *dtc) {
  755. return test_bit(DAHDI_TC_FLAG_CHAN_BUILT, &dtc->flags);
  756. }
  757. static inline void
  758. dahdi_tc_set_built(struct dahdi_transcoder_channel *dtc) {
  759. set_bit(DAHDI_TC_FLAG_CHAN_BUILT, &dtc->flags);
  760. }
  761. static inline void
  762. dahdi_tc_clear_built(struct dahdi_transcoder_channel *dtc) {
  763. clear_bit(DAHDI_TC_FLAG_CHAN_BUILT, &dtc->flags);
  764. }
  765. static inline int
  766. dahdi_tc_is_nonblock(struct dahdi_transcoder_channel *dtc) {
  767. return test_bit(DAHDI_TC_FLAG_NONBLOCK, &dtc->flags);
  768. }
  769. static inline void
  770. dahdi_tc_set_nonblock(struct dahdi_transcoder_channel *dtc) {
  771. set_bit(DAHDI_TC_FLAG_NONBLOCK, &dtc->flags);
  772. }
  773. static inline void
  774. dahdi_tc_clear_nonblock(struct dahdi_transcoder_channel *dtc) {
  775. clear_bit(DAHDI_TC_FLAG_NONBLOCK, &dtc->flags);
  776. }
  777. static inline int
  778. dahdi_tc_is_data_waiting(struct dahdi_transcoder_channel *dtc) {
  779. return test_bit(DAHDI_TC_FLAG_DATA_WAITING, &dtc->flags);
  780. }
  781. static inline int
  782. dahdi_tc_is_busy(struct dahdi_transcoder_channel *dtc) {
  783. return test_bit(DAHDI_TC_FLAG_BUSY, &dtc->flags);
  784. }
  785. static inline void
  786. dahdi_tc_set_busy(struct dahdi_transcoder_channel *dtc) {
  787. set_bit(DAHDI_TC_FLAG_BUSY, &dtc->flags);
  788. }
  789. static inline void
  790. dahdi_tc_clear_busy(struct dahdi_transcoder_channel *dtc) {
  791. clear_bit(DAHDI_TC_FLAG_BUSY, &dtc->flags);
  792. }
  793. static inline void
  794. dahdi_tc_set_data_waiting(struct dahdi_transcoder_channel *dtc) {
  795. set_bit(DAHDI_TC_FLAG_DATA_WAITING, &dtc->flags);
  796. }
  797. static inline void
  798. dahdi_tc_clear_data_waiting(struct dahdi_transcoder_channel *dtc) {
  799. clear_bit(DAHDI_TC_FLAG_DATA_WAITING, &dtc->flags);
  800. }
  801. struct dahdi_transcoder {
  802. struct list_head active_list_node;
  803. struct list_head registration_list_node;
  804. char name[80];
  805. int numchannels;
  806. unsigned int srcfmts;
  807. unsigned int dstfmts;
  808. struct file_operations fops;
  809. int (*allocate)(struct dahdi_transcoder_channel *channel);
  810. int (*release)(struct dahdi_transcoder_channel *channel);
  811. /* Transcoder channels */
  812. struct dahdi_transcoder_channel channels[0];
  813. };
  814. #define DAHDI_WATCHDOG_NOINTS (1 << 0)
  815. #define DAHDI_WATCHDOG_INIT 1000
  816. #define DAHDI_WATCHSTATE_UNKNOWN 0
  817. #define DAHDI_WATCHSTATE_OK 1
  818. #define DAHDI_WATCHSTATE_RECOVERING 2
  819. #define DAHDI_WATCHSTATE_FAILED 3
  820. struct dahdi_dynamic_driver {
  821. /*! Driver name (e.g. Eth) */
  822. char name[20];
  823. /*! Driver description */
  824. char desc[80];
  825. /*! Create a new transmission pipe */
  826. void *(*create)(struct dahdi_span *span, char *address);
  827. /*! Destroy a created transmission pipe */
  828. void (*destroy)(void *tpipe);
  829. /*! Transmit a given message */
  830. int (*transmit)(void *tpipe, unsigned char *msg, int msglen);
  831. /*! Flush any pending messages */
  832. int (*flush)(void);
  833. struct list_head list;
  834. };
  835. /*! \brief Receive a dynamic span message */
  836. void dahdi_dynamic_receive(struct dahdi_span *span, unsigned char *msg, int msglen);
  837. /*! \brief Register a dynamic driver */
  838. int dahdi_dynamic_register(struct dahdi_dynamic_driver *driver);
  839. /*! \brief Unregister a dynamic driver */
  840. void dahdi_dynamic_unregister(struct dahdi_dynamic_driver *driver);
  841. /*! Receive on a span. The DAHDI interface will handle all the calculations for
  842. all member channels of the span, pulling the data from the readchunk buffer */
  843. int dahdi_receive(struct dahdi_span *span);
  844. /*! Prepare writechunk buffers on all channels for this span */
  845. int dahdi_transmit(struct dahdi_span *span);
  846. /*! Abort the buffer currently being receive with event "event" */
  847. void dahdi_hdlc_abort(struct dahdi_chan *ss, int event);
  848. /*! Indicate to DAHDI that the end of frame was received and rotate buffers */
  849. void dahdi_hdlc_finish(struct dahdi_chan *ss);
  850. /*! Put a chunk of data into the current receive buffer */
  851. void dahdi_hdlc_putbuf(struct dahdi_chan *ss, unsigned char *rxb, int bytes);
  852. /*! Get a chunk of data from the current transmit buffer. Returns -1 if no data
  853. * is left to send, 0 if there is data remaining in the current message to be sent
  854. * and 1 if the currently transmitted message is now done */
  855. int dahdi_hdlc_getbuf(struct dahdi_chan *ss, unsigned char *bufptr, unsigned int *size);
  856. /*! Register a span. Returns 0 on success, -1 on failure. Pref-master is non-zero if
  857. we should have preference in being the master device */
  858. int dahdi_register(struct dahdi_span *span, int prefmaster);
  859. /*! Allocate / free memory for a transcoder */
  860. struct dahdi_transcoder *dahdi_transcoder_alloc(int numchans);
  861. void dahdi_transcoder_free(struct dahdi_transcoder *ztc);
  862. /*! \brief Register a transcoder */
  863. int dahdi_transcoder_register(struct dahdi_transcoder *tc);
  864. /*! \brief Unregister a transcoder */
  865. int dahdi_transcoder_unregister(struct dahdi_transcoder *tc);
  866. /*! \brief Alert a transcoder */
  867. int dahdi_transcoder_alert(struct dahdi_transcoder_channel *ztc);
  868. /*! \brief Unregister a span */
  869. int dahdi_unregister(struct dahdi_span *span);
  870. /*! \brief Gives a name to an LBO */
  871. char *dahdi_lboname(int lbo);
  872. /*! \brief Tell DAHDI about changes in received rbs bits */
  873. void dahdi_rbsbits(struct dahdi_chan *chan, int bits);
  874. /*! \brief Tell DAHDI abou changes in received signalling */
  875. void dahdi_hooksig(struct dahdi_chan *chan, enum dahdi_rxsig rxsig);
  876. /*! \brief Queue an event on a channel */
  877. void dahdi_qevent_nolock(struct dahdi_chan *chan, int event);
  878. /*! \brief Queue an event on a channel, locking it first */
  879. void dahdi_qevent_lock(struct dahdi_chan *chan, int event);
  880. /*! \brief Notify a change possible change in alarm status on a channel */
  881. void dahdi_alarm_channel(struct dahdi_chan *chan, int alarms);
  882. /*! \brief Notify a change possible change in alarm status on a span */
  883. void dahdi_alarm_notify(struct dahdi_span *span);
  884. /*! \brief Initialize a tone state */
  885. void dahdi_init_tone_state(struct dahdi_tone_state *ts, struct dahdi_tone *zt);
  886. /*! \brief Get a given MF tone struct, suitable for dahdi_tone_nextsample. */
  887. struct dahdi_tone *dahdi_mf_tone(const struct dahdi_chan *chan, char digit, int digitmode);
  888. /* Echo cancel a receive and transmit chunk for a given channel. This
  889. should be called by the low-level driver as close to the interface
  890. as possible. ECHO CANCELLATION IS NO LONGER AUTOMATICALLY DONE
  891. AT THE DAHDI LEVEL. dahdi_ec_chunk will not echo cancel if it should
  892. not be doing so. rxchunk is modified in-place */
  893. void dahdi_ec_chunk(struct dahdi_chan *chan, unsigned char *rxchunk, const unsigned char *txchunk);
  894. void dahdi_ec_span(struct dahdi_span *span);
  895. extern struct file_operations *dahdi_transcode_fops;
  896. /* Don't use these directly -- they're not guaranteed to
  897. be there. */
  898. extern short __dahdi_mulaw[256];
  899. extern short __dahdi_alaw[256];
  900. #ifdef CONFIG_CALC_XLAW
  901. u_char __dahdi_lineartoulaw(short a);
  902. u_char __dahdi_lineartoalaw(short a);
  903. #else
  904. extern u_char __dahdi_lin2mu[16384];
  905. extern u_char __dahdi_lin2a[16384];
  906. #endif
  907. /*! \brief Used by dynamic DAHDI -- don't use directly */
  908. void dahdi_set_dynamic_ioctl(int (*func)(unsigned int cmd, unsigned long data));
  909. /*! \brief Used by DAHDI HPEC module -- don't use directly */
  910. void dahdi_set_hpec_ioctl(int (*func)(unsigned int cmd, unsigned long data));
  911. /*! \brief Used privately by DAHDI. Avoid touching directly */
  912. struct dahdi_tone {
  913. int fac1;
  914. int init_v2_1;
  915. int init_v3_1;
  916. int fac2;
  917. int init_v2_2;
  918. int init_v3_2;
  919. int tonesamples; /*!< How long to play this tone before
  920. going to the next (in samples) */
  921. struct dahdi_tone *next; /* Next tone in this sequence */
  922. int modulate;
  923. };
  924. static inline short dahdi_tone_nextsample(struct dahdi_tone_state *ts, struct dahdi_tone *zt)
  925. {
  926. /* follow the curves, return the sum */
  927. int p;
  928. ts->v1_1 = ts->v2_1;
  929. ts->v2_1 = ts->v3_1;
  930. ts->v3_1 = (zt->fac1 * ts->v2_1 >> 15) - ts->v1_1;
  931. ts->v1_2 = ts->v2_2;
  932. ts->v2_2 = ts->v3_2;
  933. ts->v3_2 = (zt->fac2 * ts->v2_2 >> 15) - ts->v1_2;
  934. /* Return top 16 bits */
  935. if (!ts->modulate) return ts->v3_1 + ts->v3_2;
  936. /* we are modulating */
  937. p = ts->v3_2 - 32768;
  938. if (p < 0) p = -p;
  939. p = ((p * 9) / 10) + 1;
  940. return (ts->v3_1 * p) >> 15;
  941. }
  942. static inline short dahdi_txtone_nextsample(struct dahdi_chan *ss)
  943. {
  944. /* follow the curves, return the sum */
  945. ss->v1_1 = ss->v2_1;
  946. ss->v2_1 = ss->v3_1;
  947. ss->v3_1 = (ss->txtone * ss->v2_1 >> 15) - ss->v1_1;
  948. return ss->v3_1;
  949. }
  950. /* These are the right functions to use. */
  951. #define DAHDI_MULAW(a) (__dahdi_mulaw[(a)])
  952. #define DAHDI_ALAW(a) (__dahdi_alaw[(a)])
  953. #define DAHDI_XLAW(a,c) (c->xlaw[(a)])
  954. #ifdef CONFIG_CALC_XLAW
  955. #define DAHDI_LIN2MU(a) (__dahdi_lineartoulaw((a)))
  956. #define DAHDI_LIN2A(a) (__dahdi_lineartoalaw((a)))
  957. #define DAHDI_LIN2X(a,c) ((c)->lineartoxlaw((a)))
  958. #else
  959. /* Use tables */
  960. #define DAHDI_LIN2MU(a) (__dahdi_lin2mu[((unsigned short)(a)) >> 2])
  961. #define DAHDI_LIN2A(a) (__dahdi_lin2a[((unsigned short)(a)) >> 2])
  962. /* Manipulate as appropriate for x-law */
  963. #define DAHDI_LIN2X(a,c) ((c)->lin2x[((unsigned short)(a)) >> 2])
  964. #endif /* CONFIG_CALC_XLAW */
  965. /* Data formats for capabilities and frames alike (from Asterisk) */
  966. /*! G.723.1 compression */
  967. #define DAHDI_FORMAT_G723_1 (1 << 0)
  968. /*! GSM compression */
  969. #define DAHDI_FORMAT_GSM (1 << 1)
  970. /*! Raw mu-law data (G.711) */
  971. #define DAHDI_FORMAT_ULAW (1 << 2)
  972. /*! Raw A-law data (G.711) */
  973. #define DAHDI_FORMAT_ALAW (1 << 3)
  974. /*! ADPCM (G.726, 32kbps) */
  975. #define DAHDI_FORMAT_G726 (1 << 4)
  976. /*! ADPCM (IMA) */
  977. #define DAHDI_FORMAT_ADPCM (1 << 5)
  978. /*! Raw 16-bit Signed Linear (8000 Hz) PCM */
  979. #define DAHDI_FORMAT_SLINEAR (1 << 6)
  980. /*! LPC10, 180 samples/frame */
  981. #define DAHDI_FORMAT_LPC10 (1 << 7)
  982. /*! G.729A audio */
  983. #define DAHDI_FORMAT_G729A (1 << 8)
  984. /*! SpeeX Free Compression */
  985. #define DAHDI_FORMAT_SPEEX (1 << 9)
  986. /*! iLBC Free Compression */
  987. #define DAHDI_FORMAT_ILBC (1 << 10)
  988. /*! Maximum audio format */
  989. #define DAHDI_FORMAT_MAX_AUDIO (1 << 15)
  990. /*! Maximum audio mask */
  991. #define DAHDI_FORMAT_AUDIO_MASK ((1 << 16) - 1)
  992. #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31)
  993. #define KERN_CONT ""
  994. #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 26)
  995. #ifndef clamp
  996. #define clamp(x, low, high) min(max(low, x), high)
  997. #endif
  998. #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 25)
  999. /* Some distributions backported fatal_signal_pending so we'll use a macro to
  1000. * override the inline function definition. */
  1001. #define fatal_signal_pending(p) \
  1002. (signal_pending((p)) && sigismember(&(p)->pending.signal, SIGKILL))
  1003. #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 22)
  1004. #include <linux/ctype.h>
  1005. /* A define of 'clamp_val' happened to be added in the patch
  1006. * linux-2.6-sata-prep-work-for-rhel5-3.patch kernel-2.6.spec that also
  1007. * backported support for strcasecmp to some later RHEL/Centos kernels.
  1008. * If you have an older kernel that breaks because strcasecmp is already
  1009. * defined, somebody out-smarted us. In that case, replace the line below
  1010. * with '#if 0' to get the code building, and file a bug report at
  1011. * https://issues.asterisk.org/ .
  1012. */
  1013. #ifndef clamp_val
  1014. static inline int strcasecmp(const char *s1, const char *s2)
  1015. {
  1016. int c1, c2;
  1017. do {
  1018. c1 = tolower(*s1++);
  1019. c2 = tolower(*s2++);
  1020. } while (c1 == c2 && c1 != 0);
  1021. return c1 - c2;
  1022. }
  1023. #endif /* clamp_val */
  1024. #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18)
  1025. static inline void list_replace(struct list_head *old, struct list_head *new)
  1026. {
  1027. new->next = old->next;
  1028. new->next->prev = new;
  1029. new->prev = old->prev;
  1030. new->prev->next = new;
  1031. }
  1032. #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 14)
  1033. #define kzalloc(a, b) kcalloc(1, a, b)
  1034. #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 12)
  1035. #define synchronize_rcu() synchronize_kernel()
  1036. #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 11)
  1037. #if !defined(HAVE_WAIT_FOR_COMPLETION_TIMEOUT)
  1038. static inline unsigned long
  1039. wait_for_completion_interruptible_timeout(struct completion *x,
  1040. unsigned long timeout)
  1041. {
  1042. /* There is a race condition here. If x->done is reset to 0
  1043. * before the call to wait_for_completion after this thread wakes.
  1044. */
  1045. timeout = wait_event_interruptible_timeout(x->wait, x->done, timeout);
  1046. if (timeout)
  1047. wait_for_completion(x);
  1048. return timeout;
  1049. }
  1050. #endif
  1051. #endif /* 2.6.11 */
  1052. #endif /* 2.6.12 */
  1053. #endif /* 2.6.14 */
  1054. #endif /* 2.6.18 */
  1055. #endif /* 2.6.22 */
  1056. #endif /* 2.6.25 */
  1057. #endif /* 2.6.26 */
  1058. #endif /* 2.6.31 */
  1059. #ifndef DEFINE_SEMAPHORE
  1060. #define DEFINE_SEMAPHORE(name) \
  1061. struct semaphore name = __SEMAPHORE_INITIALIZER(name, 1)
  1062. #endif
  1063. #ifndef DEFINE_MUTEX
  1064. #define DEFINE_MUTEX DEFINE_SEMAPHORE
  1065. #define mutex_lock(_x) down(_x)
  1066. #define mutex_unlock(_x) up(_x)
  1067. #endif
  1068. #ifndef DEFINE_PCI_DEVICE_TABLE
  1069. #define DEFINE_PCI_DEVICE_TABLE(_x) \
  1070. const struct pci_device_id _x[] __devinitdata
  1071. #endif
  1072. #ifndef DEFINE_SPINLOCK
  1073. #define DEFINE_SPINLOCK(x) spinlock_t x = SPIN_LOCK_UNLOCKED
  1074. #endif
  1075. #ifndef DMA_BIT_MASK
  1076. #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
  1077. #endif
  1078. /* prink-wrapper macros */
  1079. #define DAHDI_PRINTK(level, category, fmt, ...) \
  1080. printk(KERN_ ## level "%s%s-%s: " fmt, #level, category, \
  1081. THIS_MODULE->name, ## __VA_ARGS__)
  1082. #define span_printk(level, category, span, fmt, ...) \
  1083. printk(KERN_ ## level "%s%s-%s: span-%d: " fmt, #level, \
  1084. category, THIS_MODULE->name, (span)->spanno, ## __VA_ARGS__)
  1085. #define chan_printk(level, category, chan, fmt, ...) \
  1086. printk(KERN_ ## level "%s%s-%s: %d: " fmt, #level, \
  1087. category, THIS_MODULE->name, (chan)->channo, ## __VA_ARGS__)
  1088. #define dahdi_err(fmt, ...) DAHDI_PRINTK(ERR, "", fmt, ## __VA_ARGS__)
  1089. #define span_info(span, fmt, ...) span_printk(INFO, "", span, fmt, \
  1090. ## __VA_ARGS__)
  1091. #define span_notice(span, fmt, ...) span_printk(NOTICE, "", span, fmt, \
  1092. ## __VA_ARGS__)
  1093. #define span_err(span, fmt, ...) span_printk(ERR, "", span, fmt, \
  1094. ## __VA_ARGS__)
  1095. #define chan_notice(chan, fmt, ...) chan_printk(NOTICE, "", chan, fmt, \
  1096. ## __VA_ARGS__)
  1097. #define chan_err(chan, fmt, ...) chan_printk(ERR, "", chan, fmt, \
  1098. ## __VA_ARGS__)
  1099. /* The dbg_* ones use a magical variable 'debug' and the user should be
  1100. * aware of that.
  1101. */
  1102. #ifdef DAHDI_PRINK_MACROS_USE_debug
  1103. #ifndef BIT /* added in 2.6.24 */
  1104. #define BIT(i) (1UL << (i))
  1105. #endif
  1106. /* Standard debug bit values. Any module may define others. They must
  1107. * be of the form DAHDI_DBG_*
  1108. */
  1109. #define DAHDI_DBG_GENERAL BIT(0)
  1110. #define DAHDI_DBG_DEVICES BIT(7) /* instantiation/destruction etc. */
  1111. #define dahdi_dbg(bits, fmt, ...) \
  1112. ((void)((debug & (DAHDI_DBG_ ## bits)) && DAHDI_PRINTK(DEBUG, \
  1113. "-" #bits, "%s: " fmt, __func__, ## __VA_ARGS__)))
  1114. #define span_dbg(bits, span, fmt, ...) \
  1115. ((void)((debug & (DAHDI_DBG_ ## bits)) && \
  1116. span_printk(DEBUG, "-" #bits, span, "%s: " \
  1117. fmt, __func__, ## __VA_ARGS__)))
  1118. #define chan_dbg(bits, chan, fmt, ...) \
  1119. ((void)((debug & (DAHDI_DBG_ ## bits)) && \
  1120. chan_printk(DEBUG, "-" #bits, chan, \
  1121. "%s: " fmt, __func__, ## __VA_ARGS__)))
  1122. #endif /* DAHDI_PRINK_MACROS_USE_debug */
  1123. #endif /* _DAHDI_KERNEL_H */