isdn_common.c 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386
  1. /* $Id: isdn_common.c,v 1.1.2.3 2004/02/10 01:07:13 keil Exp $
  2. *
  3. * Linux ISDN subsystem, common used functions (linklevel).
  4. *
  5. * Copyright 1994-1999 by Fritz Elfert (fritz@isdn4linux.de)
  6. * Copyright 1995,96 Thinking Objects Software GmbH Wuerzburg
  7. * Copyright 1995,96 by Michael Hipp (Michael.Hipp@student.uni-tuebingen.de)
  8. *
  9. * This software may be used and distributed according to the terms
  10. * of the GNU General Public License, incorporated herein by reference.
  11. *
  12. */
  13. #include <linux/module.h>
  14. #include <linux/init.h>
  15. #include <linux/poll.h>
  16. #include <linux/slab.h>
  17. #include <linux/vmalloc.h>
  18. #include <linux/isdn.h>
  19. #include <linux/mutex.h>
  20. #include "isdn_common.h"
  21. #include "isdn_tty.h"
  22. #include "isdn_net.h"
  23. #include "isdn_ppp.h"
  24. #ifdef CONFIG_ISDN_AUDIO
  25. #include "isdn_audio.h"
  26. #endif
  27. #ifdef CONFIG_ISDN_DIVERSION_MODULE
  28. #define CONFIG_ISDN_DIVERSION
  29. #endif
  30. #ifdef CONFIG_ISDN_DIVERSION
  31. #include <linux/isdn_divertif.h>
  32. #endif /* CONFIG_ISDN_DIVERSION */
  33. #include "isdn_v110.h"
  34. /* Debugflags */
  35. #undef ISDN_DEBUG_STATCALLB
  36. MODULE_DESCRIPTION("ISDN4Linux: link layer");
  37. MODULE_AUTHOR("Fritz Elfert");
  38. MODULE_LICENSE("GPL");
  39. isdn_dev *dev;
  40. static DEFINE_MUTEX(isdn_mutex);
  41. static char *isdn_revision = "$Revision: 1.1.2.3 $";
  42. extern char *isdn_net_revision;
  43. #ifdef CONFIG_ISDN_PPP
  44. extern char *isdn_ppp_revision;
  45. #else
  46. static char *isdn_ppp_revision = ": none $";
  47. #endif
  48. #ifdef CONFIG_ISDN_AUDIO
  49. extern char *isdn_audio_revision;
  50. #else
  51. static char *isdn_audio_revision = ": none $";
  52. #endif
  53. extern char *isdn_v110_revision;
  54. #ifdef CONFIG_ISDN_DIVERSION
  55. static isdn_divert_if *divert_if; /* = NULL */
  56. #endif /* CONFIG_ISDN_DIVERSION */
  57. static int isdn_writebuf_stub(int, int, const u_char __user *, int);
  58. static void set_global_features(void);
  59. static int isdn_wildmat(char *s, char *p);
  60. static int isdn_add_channels(isdn_driver_t *d, int drvidx, int n, int adding);
  61. static inline void
  62. isdn_lock_driver(isdn_driver_t *drv)
  63. {
  64. try_module_get(drv->interface->owner);
  65. drv->locks++;
  66. }
  67. void
  68. isdn_lock_drivers(void)
  69. {
  70. int i;
  71. for (i = 0; i < ISDN_MAX_DRIVERS; i++) {
  72. if (!dev->drv[i])
  73. continue;
  74. isdn_lock_driver(dev->drv[i]);
  75. }
  76. }
  77. static inline void
  78. isdn_unlock_driver(isdn_driver_t *drv)
  79. {
  80. if (drv->locks > 0) {
  81. drv->locks--;
  82. module_put(drv->interface->owner);
  83. }
  84. }
  85. void
  86. isdn_unlock_drivers(void)
  87. {
  88. int i;
  89. for (i = 0; i < ISDN_MAX_DRIVERS; i++) {
  90. if (!dev->drv[i])
  91. continue;
  92. isdn_unlock_driver(dev->drv[i]);
  93. }
  94. }
  95. #if defined(ISDN_DEBUG_NET_DUMP) || defined(ISDN_DEBUG_MODEM_DUMP)
  96. void
  97. isdn_dumppkt(char *s, u_char *p, int len, int dumplen)
  98. {
  99. int dumpc;
  100. printk(KERN_DEBUG "%s(%d) ", s, len);
  101. for (dumpc = 0; (dumpc < dumplen) && (len); len--, dumpc++)
  102. printk(" %02x", *p++);
  103. printk("\n");
  104. }
  105. #endif
  106. /*
  107. * I picked the pattern-matching-functions from an old GNU-tar version (1.10)
  108. * It was originally written and put to PD by rs@mirror.TMC.COM (Rich Salz)
  109. */
  110. static int
  111. isdn_star(char *s, char *p)
  112. {
  113. while (isdn_wildmat(s, p)) {
  114. if (*++s == '\0')
  115. return (2);
  116. }
  117. return (0);
  118. }
  119. /*
  120. * Shell-type Pattern-matching for incoming caller-Ids
  121. * This function gets a string in s and checks, if it matches the pattern
  122. * given in p.
  123. *
  124. * Return:
  125. * 0 = match.
  126. * 1 = no match.
  127. * 2 = no match. Would eventually match, if s would be longer.
  128. *
  129. * Possible Patterns:
  130. *
  131. * '?' matches one character
  132. * '*' matches zero or more characters
  133. * [xyz] matches the set of characters in brackets.
  134. * [^xyz] matches any single character not in the set of characters
  135. */
  136. static int
  137. isdn_wildmat(char *s, char *p)
  138. {
  139. register int last;
  140. register int matched;
  141. register int reverse;
  142. register int nostar = 1;
  143. if (!(*s) && !(*p))
  144. return (1);
  145. for (; *p; s++, p++)
  146. switch (*p) {
  147. case '\\':
  148. /*
  149. * Literal match with following character,
  150. * fall through.
  151. */
  152. p++;
  153. default:
  154. if (*s != *p)
  155. return (*s == '\0') ? 2 : 1;
  156. continue;
  157. case '?':
  158. /* Match anything. */
  159. if (*s == '\0')
  160. return (2);
  161. continue;
  162. case '*':
  163. nostar = 0;
  164. /* Trailing star matches everything. */
  165. return (*++p ? isdn_star(s, p) : 0);
  166. case '[':
  167. /* [^....] means inverse character class. */
  168. if ((reverse = (p[1] == '^')))
  169. p++;
  170. for (last = 0, matched = 0; *++p && (*p != ']'); last = *p)
  171. /* This next line requires a good C compiler. */
  172. if (*p == '-' ? *s <= *++p && *s >= last : *s == *p)
  173. matched = 1;
  174. if (matched == reverse)
  175. return (1);
  176. continue;
  177. }
  178. return (*s == '\0') ? 0 : nostar;
  179. }
  180. int isdn_msncmp(const char *msn1, const char *msn2)
  181. {
  182. char TmpMsn1[ISDN_MSNLEN];
  183. char TmpMsn2[ISDN_MSNLEN];
  184. char *p;
  185. for (p = TmpMsn1; *msn1 && *msn1 != ':';) // Strip off a SPID
  186. *p++ = *msn1++;
  187. *p = '\0';
  188. for (p = TmpMsn2; *msn2 && *msn2 != ':';) // Strip off a SPID
  189. *p++ = *msn2++;
  190. *p = '\0';
  191. return isdn_wildmat(TmpMsn1, TmpMsn2);
  192. }
  193. int
  194. isdn_dc2minor(int di, int ch)
  195. {
  196. int i;
  197. for (i = 0; i < ISDN_MAX_CHANNELS; i++)
  198. if (dev->chanmap[i] == ch && dev->drvmap[i] == di)
  199. return i;
  200. return -1;
  201. }
  202. static int isdn_timer_cnt1 = 0;
  203. static int isdn_timer_cnt2 = 0;
  204. static int isdn_timer_cnt3 = 0;
  205. static void
  206. isdn_timer_funct(ulong dummy)
  207. {
  208. int tf = dev->tflags;
  209. if (tf & ISDN_TIMER_FAST) {
  210. if (tf & ISDN_TIMER_MODEMREAD)
  211. isdn_tty_readmodem();
  212. if (tf & ISDN_TIMER_MODEMPLUS)
  213. isdn_tty_modem_escape();
  214. if (tf & ISDN_TIMER_MODEMXMIT)
  215. isdn_tty_modem_xmit();
  216. }
  217. if (tf & ISDN_TIMER_SLOW) {
  218. if (++isdn_timer_cnt1 >= ISDN_TIMER_02SEC) {
  219. isdn_timer_cnt1 = 0;
  220. if (tf & ISDN_TIMER_NETDIAL)
  221. isdn_net_dial();
  222. }
  223. if (++isdn_timer_cnt2 >= ISDN_TIMER_1SEC) {
  224. isdn_timer_cnt2 = 0;
  225. if (tf & ISDN_TIMER_NETHANGUP)
  226. isdn_net_autohup();
  227. if (++isdn_timer_cnt3 >= ISDN_TIMER_RINGING) {
  228. isdn_timer_cnt3 = 0;
  229. if (tf & ISDN_TIMER_MODEMRING)
  230. isdn_tty_modem_ring();
  231. }
  232. if (tf & ISDN_TIMER_CARRIER)
  233. isdn_tty_carrier_timeout();
  234. }
  235. }
  236. if (tf)
  237. mod_timer(&dev->timer, jiffies + ISDN_TIMER_RES);
  238. }
  239. void
  240. isdn_timer_ctrl(int tf, int onoff)
  241. {
  242. unsigned long flags;
  243. int old_tflags;
  244. spin_lock_irqsave(&dev->timerlock, flags);
  245. if ((tf & ISDN_TIMER_SLOW) && (!(dev->tflags & ISDN_TIMER_SLOW))) {
  246. /* If the slow-timer wasn't activated until now */
  247. isdn_timer_cnt1 = 0;
  248. isdn_timer_cnt2 = 0;
  249. }
  250. old_tflags = dev->tflags;
  251. if (onoff)
  252. dev->tflags |= tf;
  253. else
  254. dev->tflags &= ~tf;
  255. if (dev->tflags && !old_tflags)
  256. mod_timer(&dev->timer, jiffies + ISDN_TIMER_RES);
  257. spin_unlock_irqrestore(&dev->timerlock, flags);
  258. }
  259. /*
  260. * Receive a packet from B-Channel. (Called from low-level-module)
  261. */
  262. static void
  263. isdn_receive_skb_callback(int di, int channel, struct sk_buff *skb)
  264. {
  265. int i;
  266. if ((i = isdn_dc2minor(di, channel)) == -1) {
  267. dev_kfree_skb(skb);
  268. return;
  269. }
  270. /* Update statistics */
  271. dev->ibytes[i] += skb->len;
  272. /* First, try to deliver data to network-device */
  273. if (isdn_net_rcv_skb(i, skb))
  274. return;
  275. /* V.110 handling
  276. * makes sense for async streams only, so it is
  277. * called after possible net-device delivery.
  278. */
  279. if (dev->v110[i]) {
  280. atomic_inc(&dev->v110use[i]);
  281. skb = isdn_v110_decode(dev->v110[i], skb);
  282. atomic_dec(&dev->v110use[i]);
  283. if (!skb)
  284. return;
  285. }
  286. /* No network-device found, deliver to tty or raw-channel */
  287. if (skb->len) {
  288. if (isdn_tty_rcv_skb(i, di, channel, skb))
  289. return;
  290. wake_up_interruptible(&dev->drv[di]->rcv_waitq[channel]);
  291. } else
  292. dev_kfree_skb(skb);
  293. }
  294. /*
  295. * Intercept command from Linklevel to Lowlevel.
  296. * If layer 2 protocol is V.110 and this is not supported by current
  297. * lowlevel-driver, use driver's transparent mode and handle V.110 in
  298. * linklevel instead.
  299. */
  300. int
  301. isdn_command(isdn_ctrl *cmd)
  302. {
  303. if (cmd->driver == -1) {
  304. printk(KERN_WARNING "isdn_command command(%x) driver -1\n", cmd->command);
  305. return (1);
  306. }
  307. if (!dev->drv[cmd->driver]) {
  308. printk(KERN_WARNING "isdn_command command(%x) dev->drv[%d] NULL\n",
  309. cmd->command, cmd->driver);
  310. return (1);
  311. }
  312. if (!dev->drv[cmd->driver]->interface) {
  313. printk(KERN_WARNING "isdn_command command(%x) dev->drv[%d]->interface NULL\n",
  314. cmd->command, cmd->driver);
  315. return (1);
  316. }
  317. if (cmd->command == ISDN_CMD_SETL2) {
  318. int idx = isdn_dc2minor(cmd->driver, cmd->arg & 255);
  319. unsigned long l2prot = (cmd->arg >> 8) & 255;
  320. unsigned long features = (dev->drv[cmd->driver]->interface->features
  321. >> ISDN_FEATURE_L2_SHIFT) &
  322. ISDN_FEATURE_L2_MASK;
  323. unsigned long l2_feature = (1 << l2prot);
  324. switch (l2prot) {
  325. case ISDN_PROTO_L2_V11096:
  326. case ISDN_PROTO_L2_V11019:
  327. case ISDN_PROTO_L2_V11038:
  328. /* If V.110 requested, but not supported by
  329. * HL-driver, set emulator-flag and change
  330. * Layer-2 to transparent
  331. */
  332. if (!(features & l2_feature)) {
  333. dev->v110emu[idx] = l2prot;
  334. cmd->arg = (cmd->arg & 255) |
  335. (ISDN_PROTO_L2_TRANS << 8);
  336. } else
  337. dev->v110emu[idx] = 0;
  338. }
  339. }
  340. return dev->drv[cmd->driver]->interface->command(cmd);
  341. }
  342. void
  343. isdn_all_eaz(int di, int ch)
  344. {
  345. isdn_ctrl cmd;
  346. if (di < 0)
  347. return;
  348. cmd.driver = di;
  349. cmd.arg = ch;
  350. cmd.command = ISDN_CMD_SETEAZ;
  351. cmd.parm.num[0] = '\0';
  352. isdn_command(&cmd);
  353. }
  354. /*
  355. * Begin of a CAPI like LL<->HL interface, currently used only for
  356. * supplementary service (CAPI 2.0 part III)
  357. */
  358. #include <linux/isdn/capicmd.h>
  359. static int
  360. isdn_capi_rec_hl_msg(capi_msg *cm)
  361. {
  362. switch (cm->Command) {
  363. case CAPI_FACILITY:
  364. /* in the moment only handled in tty */
  365. return (isdn_tty_capi_facility(cm));
  366. default:
  367. return (-1);
  368. }
  369. }
  370. static int
  371. isdn_status_callback(isdn_ctrl *c)
  372. {
  373. int di;
  374. u_long flags;
  375. int i;
  376. int r;
  377. int retval = 0;
  378. isdn_ctrl cmd;
  379. isdn_net_dev *p;
  380. di = c->driver;
  381. i = isdn_dc2minor(di, c->arg);
  382. switch (c->command) {
  383. case ISDN_STAT_BSENT:
  384. if (i < 0)
  385. return -1;
  386. if (dev->global_flags & ISDN_GLOBAL_STOPPED)
  387. return 0;
  388. if (isdn_net_stat_callback(i, c))
  389. return 0;
  390. if (isdn_v110_stat_callback(i, c))
  391. return 0;
  392. if (isdn_tty_stat_callback(i, c))
  393. return 0;
  394. wake_up_interruptible(&dev->drv[di]->snd_waitq[c->arg]);
  395. break;
  396. case ISDN_STAT_STAVAIL:
  397. dev->drv[di]->stavail += c->arg;
  398. wake_up_interruptible(&dev->drv[di]->st_waitq);
  399. break;
  400. case ISDN_STAT_RUN:
  401. dev->drv[di]->flags |= DRV_FLAG_RUNNING;
  402. for (i = 0; i < ISDN_MAX_CHANNELS; i++)
  403. if (dev->drvmap[i] == di)
  404. isdn_all_eaz(di, dev->chanmap[i]);
  405. set_global_features();
  406. break;
  407. case ISDN_STAT_STOP:
  408. dev->drv[di]->flags &= ~DRV_FLAG_RUNNING;
  409. break;
  410. case ISDN_STAT_ICALL:
  411. if (i < 0)
  412. return -1;
  413. #ifdef ISDN_DEBUG_STATCALLB
  414. printk(KERN_DEBUG "ICALL (net): %d %ld %s\n", di, c->arg, c->parm.num);
  415. #endif
  416. if (dev->global_flags & ISDN_GLOBAL_STOPPED) {
  417. cmd.driver = di;
  418. cmd.arg = c->arg;
  419. cmd.command = ISDN_CMD_HANGUP;
  420. isdn_command(&cmd);
  421. return 0;
  422. }
  423. /* Try to find a network-interface which will accept incoming call */
  424. r = ((c->command == ISDN_STAT_ICALLW) ? 0 : isdn_net_find_icall(di, c->arg, i, &c->parm.setup));
  425. switch (r) {
  426. case 0:
  427. /* No network-device replies.
  428. * Try ttyI's.
  429. * These return 0 on no match, 1 on match and
  430. * 3 on eventually match, if CID is longer.
  431. */
  432. if (c->command == ISDN_STAT_ICALL)
  433. if ((retval = isdn_tty_find_icall(di, c->arg, &c->parm.setup))) return (retval);
  434. #ifdef CONFIG_ISDN_DIVERSION
  435. if (divert_if)
  436. if ((retval = divert_if->stat_callback(c)))
  437. return (retval); /* processed */
  438. #endif /* CONFIG_ISDN_DIVERSION */
  439. if ((!retval) && (dev->drv[di]->flags & DRV_FLAG_REJBUS)) {
  440. /* No tty responding */
  441. cmd.driver = di;
  442. cmd.arg = c->arg;
  443. cmd.command = ISDN_CMD_HANGUP;
  444. isdn_command(&cmd);
  445. retval = 2;
  446. }
  447. break;
  448. case 1:
  449. /* Schedule connection-setup */
  450. isdn_net_dial();
  451. cmd.driver = di;
  452. cmd.arg = c->arg;
  453. cmd.command = ISDN_CMD_ACCEPTD;
  454. for (p = dev->netdev; p; p = p->next)
  455. if (p->local->isdn_channel == cmd.arg)
  456. {
  457. strcpy(cmd.parm.setup.eazmsn, p->local->msn);
  458. isdn_command(&cmd);
  459. retval = 1;
  460. break;
  461. }
  462. break;
  463. case 2: /* For calling back, first reject incoming call ... */
  464. case 3: /* Interface found, but down, reject call actively */
  465. retval = 2;
  466. printk(KERN_INFO "isdn: Rejecting Call\n");
  467. cmd.driver = di;
  468. cmd.arg = c->arg;
  469. cmd.command = ISDN_CMD_HANGUP;
  470. isdn_command(&cmd);
  471. if (r == 3)
  472. break;
  473. /* Fall through */
  474. case 4:
  475. /* ... then start callback. */
  476. isdn_net_dial();
  477. break;
  478. case 5:
  479. /* Number would eventually match, if longer */
  480. retval = 3;
  481. break;
  482. }
  483. #ifdef ISDN_DEBUG_STATCALLB
  484. printk(KERN_DEBUG "ICALL: ret=%d\n", retval);
  485. #endif
  486. return retval;
  487. break;
  488. case ISDN_STAT_CINF:
  489. if (i < 0)
  490. return -1;
  491. #ifdef ISDN_DEBUG_STATCALLB
  492. printk(KERN_DEBUG "CINF: %ld %s\n", c->arg, c->parm.num);
  493. #endif
  494. if (dev->global_flags & ISDN_GLOBAL_STOPPED)
  495. return 0;
  496. if (strcmp(c->parm.num, "0"))
  497. isdn_net_stat_callback(i, c);
  498. isdn_tty_stat_callback(i, c);
  499. break;
  500. case ISDN_STAT_CAUSE:
  501. #ifdef ISDN_DEBUG_STATCALLB
  502. printk(KERN_DEBUG "CAUSE: %ld %s\n", c->arg, c->parm.num);
  503. #endif
  504. printk(KERN_INFO "isdn: %s,ch%ld cause: %s\n",
  505. dev->drvid[di], c->arg, c->parm.num);
  506. isdn_tty_stat_callback(i, c);
  507. #ifdef CONFIG_ISDN_DIVERSION
  508. if (divert_if)
  509. divert_if->stat_callback(c);
  510. #endif /* CONFIG_ISDN_DIVERSION */
  511. break;
  512. case ISDN_STAT_DISPLAY:
  513. #ifdef ISDN_DEBUG_STATCALLB
  514. printk(KERN_DEBUG "DISPLAY: %ld %s\n", c->arg, c->parm.display);
  515. #endif
  516. isdn_tty_stat_callback(i, c);
  517. #ifdef CONFIG_ISDN_DIVERSION
  518. if (divert_if)
  519. divert_if->stat_callback(c);
  520. #endif /* CONFIG_ISDN_DIVERSION */
  521. break;
  522. case ISDN_STAT_DCONN:
  523. if (i < 0)
  524. return -1;
  525. #ifdef ISDN_DEBUG_STATCALLB
  526. printk(KERN_DEBUG "DCONN: %ld\n", c->arg);
  527. #endif
  528. if (dev->global_flags & ISDN_GLOBAL_STOPPED)
  529. return 0;
  530. /* Find any net-device, waiting for D-channel setup */
  531. if (isdn_net_stat_callback(i, c))
  532. break;
  533. isdn_v110_stat_callback(i, c);
  534. /* Find any ttyI, waiting for D-channel setup */
  535. if (isdn_tty_stat_callback(i, c)) {
  536. cmd.driver = di;
  537. cmd.arg = c->arg;
  538. cmd.command = ISDN_CMD_ACCEPTB;
  539. isdn_command(&cmd);
  540. break;
  541. }
  542. break;
  543. case ISDN_STAT_DHUP:
  544. if (i < 0)
  545. return -1;
  546. #ifdef ISDN_DEBUG_STATCALLB
  547. printk(KERN_DEBUG "DHUP: %ld\n", c->arg);
  548. #endif
  549. if (dev->global_flags & ISDN_GLOBAL_STOPPED)
  550. return 0;
  551. dev->drv[di]->online &= ~(1 << (c->arg));
  552. isdn_info_update();
  553. /* Signal hangup to network-devices */
  554. if (isdn_net_stat_callback(i, c))
  555. break;
  556. isdn_v110_stat_callback(i, c);
  557. if (isdn_tty_stat_callback(i, c))
  558. break;
  559. #ifdef CONFIG_ISDN_DIVERSION
  560. if (divert_if)
  561. divert_if->stat_callback(c);
  562. #endif /* CONFIG_ISDN_DIVERSION */
  563. break;
  564. break;
  565. case ISDN_STAT_BCONN:
  566. if (i < 0)
  567. return -1;
  568. #ifdef ISDN_DEBUG_STATCALLB
  569. printk(KERN_DEBUG "BCONN: %ld\n", c->arg);
  570. #endif
  571. /* Signal B-channel-connect to network-devices */
  572. if (dev->global_flags & ISDN_GLOBAL_STOPPED)
  573. return 0;
  574. dev->drv[di]->online |= (1 << (c->arg));
  575. isdn_info_update();
  576. if (isdn_net_stat_callback(i, c))
  577. break;
  578. isdn_v110_stat_callback(i, c);
  579. if (isdn_tty_stat_callback(i, c))
  580. break;
  581. break;
  582. case ISDN_STAT_BHUP:
  583. if (i < 0)
  584. return -1;
  585. #ifdef ISDN_DEBUG_STATCALLB
  586. printk(KERN_DEBUG "BHUP: %ld\n", c->arg);
  587. #endif
  588. if (dev->global_flags & ISDN_GLOBAL_STOPPED)
  589. return 0;
  590. dev->drv[di]->online &= ~(1 << (c->arg));
  591. isdn_info_update();
  592. #ifdef CONFIG_ISDN_X25
  593. /* Signal hangup to network-devices */
  594. if (isdn_net_stat_callback(i, c))
  595. break;
  596. #endif
  597. isdn_v110_stat_callback(i, c);
  598. if (isdn_tty_stat_callback(i, c))
  599. break;
  600. break;
  601. case ISDN_STAT_NODCH:
  602. if (i < 0)
  603. return -1;
  604. #ifdef ISDN_DEBUG_STATCALLB
  605. printk(KERN_DEBUG "NODCH: %ld\n", c->arg);
  606. #endif
  607. if (dev->global_flags & ISDN_GLOBAL_STOPPED)
  608. return 0;
  609. if (isdn_net_stat_callback(i, c))
  610. break;
  611. if (isdn_tty_stat_callback(i, c))
  612. break;
  613. break;
  614. case ISDN_STAT_ADDCH:
  615. spin_lock_irqsave(&dev->lock, flags);
  616. if (isdn_add_channels(dev->drv[di], di, c->arg, 1)) {
  617. spin_unlock_irqrestore(&dev->lock, flags);
  618. return -1;
  619. }
  620. spin_unlock_irqrestore(&dev->lock, flags);
  621. isdn_info_update();
  622. break;
  623. case ISDN_STAT_DISCH:
  624. spin_lock_irqsave(&dev->lock, flags);
  625. for (i = 0; i < ISDN_MAX_CHANNELS; i++)
  626. if ((dev->drvmap[i] == di) &&
  627. (dev->chanmap[i] == c->arg)) {
  628. if (c->parm.num[0])
  629. dev->usage[i] &= ~ISDN_USAGE_DISABLED;
  630. else
  631. if (USG_NONE(dev->usage[i])) {
  632. dev->usage[i] |= ISDN_USAGE_DISABLED;
  633. }
  634. else
  635. retval = -1;
  636. break;
  637. }
  638. spin_unlock_irqrestore(&dev->lock, flags);
  639. isdn_info_update();
  640. break;
  641. case ISDN_STAT_UNLOAD:
  642. while (dev->drv[di]->locks > 0) {
  643. isdn_unlock_driver(dev->drv[di]);
  644. }
  645. spin_lock_irqsave(&dev->lock, flags);
  646. isdn_tty_stat_callback(i, c);
  647. for (i = 0; i < ISDN_MAX_CHANNELS; i++)
  648. if (dev->drvmap[i] == di) {
  649. dev->drvmap[i] = -1;
  650. dev->chanmap[i] = -1;
  651. dev->usage[i] &= ~ISDN_USAGE_DISABLED;
  652. }
  653. dev->drivers--;
  654. dev->channels -= dev->drv[di]->channels;
  655. kfree(dev->drv[di]->rcverr);
  656. kfree(dev->drv[di]->rcvcount);
  657. for (i = 0; i < dev->drv[di]->channels; i++)
  658. skb_queue_purge(&dev->drv[di]->rpqueue[i]);
  659. kfree(dev->drv[di]->rpqueue);
  660. kfree(dev->drv[di]->rcv_waitq);
  661. kfree(dev->drv[di]);
  662. dev->drv[di] = NULL;
  663. dev->drvid[di][0] = '\0';
  664. isdn_info_update();
  665. set_global_features();
  666. spin_unlock_irqrestore(&dev->lock, flags);
  667. return 0;
  668. case ISDN_STAT_L1ERR:
  669. break;
  670. case CAPI_PUT_MESSAGE:
  671. return (isdn_capi_rec_hl_msg(&c->parm.cmsg));
  672. #ifdef CONFIG_ISDN_TTY_FAX
  673. case ISDN_STAT_FAXIND:
  674. isdn_tty_stat_callback(i, c);
  675. break;
  676. #endif
  677. #ifdef CONFIG_ISDN_AUDIO
  678. case ISDN_STAT_AUDIO:
  679. isdn_tty_stat_callback(i, c);
  680. break;
  681. #endif
  682. #ifdef CONFIG_ISDN_DIVERSION
  683. case ISDN_STAT_PROT:
  684. case ISDN_STAT_REDIR:
  685. if (divert_if)
  686. return (divert_if->stat_callback(c));
  687. #endif /* CONFIG_ISDN_DIVERSION */
  688. default:
  689. return -1;
  690. }
  691. return 0;
  692. }
  693. /*
  694. * Get integer from char-pointer, set pointer to end of number
  695. */
  696. int
  697. isdn_getnum(char **p)
  698. {
  699. int v = -1;
  700. while (*p[0] >= '0' && *p[0] <= '9')
  701. v = ((v < 0) ? 0 : (v * 10)) + (int) ((*p[0]++) - '0');
  702. return v;
  703. }
  704. #define DLE 0x10
  705. /*
  706. * isdn_readbchan() tries to get data from the read-queue.
  707. * It MUST be called with interrupts off.
  708. *
  709. * Be aware that this is not an atomic operation when sleep != 0, even though
  710. * interrupts are turned off! Well, like that we are currently only called
  711. * on behalf of a read system call on raw device files (which are documented
  712. * to be dangerous and for debugging purpose only). The inode semaphore
  713. * takes care that this is not called for the same minor device number while
  714. * we are sleeping, but access is not serialized against simultaneous read()
  715. * from the corresponding ttyI device. Can other ugly events, like changes
  716. * of the mapping (di,ch)<->minor, happen during the sleep? --he
  717. */
  718. int
  719. isdn_readbchan(int di, int channel, u_char *buf, u_char *fp, int len, wait_queue_head_t *sleep)
  720. {
  721. int count;
  722. int count_pull;
  723. int count_put;
  724. int dflag;
  725. struct sk_buff *skb;
  726. u_char *cp;
  727. if (!dev->drv[di])
  728. return 0;
  729. if (skb_queue_empty(&dev->drv[di]->rpqueue[channel])) {
  730. if (sleep)
  731. wait_event_interruptible(*sleep,
  732. !skb_queue_empty(&dev->drv[di]->rpqueue[channel]));
  733. else
  734. return 0;
  735. }
  736. if (len > dev->drv[di]->rcvcount[channel])
  737. len = dev->drv[di]->rcvcount[channel];
  738. cp = buf;
  739. count = 0;
  740. while (len) {
  741. if (!(skb = skb_peek(&dev->drv[di]->rpqueue[channel])))
  742. break;
  743. #ifdef CONFIG_ISDN_AUDIO
  744. if (ISDN_AUDIO_SKB_LOCK(skb))
  745. break;
  746. ISDN_AUDIO_SKB_LOCK(skb) = 1;
  747. if ((ISDN_AUDIO_SKB_DLECOUNT(skb)) || (dev->drv[di]->DLEflag & (1 << channel))) {
  748. char *p = skb->data;
  749. unsigned long DLEmask = (1 << channel);
  750. dflag = 0;
  751. count_pull = count_put = 0;
  752. while ((count_pull < skb->len) && (len > 0)) {
  753. len--;
  754. if (dev->drv[di]->DLEflag & DLEmask) {
  755. *cp++ = DLE;
  756. dev->drv[di]->DLEflag &= ~DLEmask;
  757. } else {
  758. *cp++ = *p;
  759. if (*p == DLE) {
  760. dev->drv[di]->DLEflag |= DLEmask;
  761. (ISDN_AUDIO_SKB_DLECOUNT(skb))--;
  762. }
  763. p++;
  764. count_pull++;
  765. }
  766. count_put++;
  767. }
  768. if (count_pull >= skb->len)
  769. dflag = 1;
  770. } else {
  771. #endif
  772. /* No DLE's in buff, so simply copy it */
  773. dflag = 1;
  774. if ((count_pull = skb->len) > len) {
  775. count_pull = len;
  776. dflag = 0;
  777. }
  778. count_put = count_pull;
  779. skb_copy_from_linear_data(skb, cp, count_put);
  780. cp += count_put;
  781. len -= count_put;
  782. #ifdef CONFIG_ISDN_AUDIO
  783. }
  784. #endif
  785. count += count_put;
  786. if (fp) {
  787. memset(fp, 0, count_put);
  788. fp += count_put;
  789. }
  790. if (dflag) {
  791. /* We got all the data in this buff.
  792. * Now we can dequeue it.
  793. */
  794. if (fp)
  795. *(fp - 1) = 0xff;
  796. #ifdef CONFIG_ISDN_AUDIO
  797. ISDN_AUDIO_SKB_LOCK(skb) = 0;
  798. #endif
  799. skb = skb_dequeue(&dev->drv[di]->rpqueue[channel]);
  800. dev_kfree_skb(skb);
  801. } else {
  802. /* Not yet emptied this buff, so it
  803. * must stay in the queue, for further calls
  804. * but we pull off the data we got until now.
  805. */
  806. skb_pull(skb, count_pull);
  807. #ifdef CONFIG_ISDN_AUDIO
  808. ISDN_AUDIO_SKB_LOCK(skb) = 0;
  809. #endif
  810. }
  811. dev->drv[di]->rcvcount[channel] -= count_put;
  812. }
  813. return count;
  814. }
  815. /*
  816. * isdn_readbchan_tty() tries to get data from the read-queue.
  817. * It MUST be called with interrupts off.
  818. *
  819. * Be aware that this is not an atomic operation when sleep != 0, even though
  820. * interrupts are turned off! Well, like that we are currently only called
  821. * on behalf of a read system call on raw device files (which are documented
  822. * to be dangerous and for debugging purpose only). The inode semaphore
  823. * takes care that this is not called for the same minor device number while
  824. * we are sleeping, but access is not serialized against simultaneous read()
  825. * from the corresponding ttyI device. Can other ugly events, like changes
  826. * of the mapping (di,ch)<->minor, happen during the sleep? --he
  827. */
  828. int
  829. isdn_readbchan_tty(int di, int channel, struct tty_port *port, int cisco_hack)
  830. {
  831. int count;
  832. int count_pull;
  833. int count_put;
  834. int dflag;
  835. struct sk_buff *skb;
  836. char last = 0;
  837. int len;
  838. if (!dev->drv[di])
  839. return 0;
  840. if (skb_queue_empty(&dev->drv[di]->rpqueue[channel]))
  841. return 0;
  842. len = tty_buffer_request_room(port, dev->drv[di]->rcvcount[channel]);
  843. if (len == 0)
  844. return len;
  845. count = 0;
  846. while (len) {
  847. if (!(skb = skb_peek(&dev->drv[di]->rpqueue[channel])))
  848. break;
  849. #ifdef CONFIG_ISDN_AUDIO
  850. if (ISDN_AUDIO_SKB_LOCK(skb))
  851. break;
  852. ISDN_AUDIO_SKB_LOCK(skb) = 1;
  853. if ((ISDN_AUDIO_SKB_DLECOUNT(skb)) || (dev->drv[di]->DLEflag & (1 << channel))) {
  854. char *p = skb->data;
  855. unsigned long DLEmask = (1 << channel);
  856. dflag = 0;
  857. count_pull = count_put = 0;
  858. while ((count_pull < skb->len) && (len > 0)) {
  859. /* push every character but the last to the tty buffer directly */
  860. if (count_put)
  861. tty_insert_flip_char(port, last, TTY_NORMAL);
  862. len--;
  863. if (dev->drv[di]->DLEflag & DLEmask) {
  864. last = DLE;
  865. dev->drv[di]->DLEflag &= ~DLEmask;
  866. } else {
  867. last = *p;
  868. if (last == DLE) {
  869. dev->drv[di]->DLEflag |= DLEmask;
  870. (ISDN_AUDIO_SKB_DLECOUNT(skb))--;
  871. }
  872. p++;
  873. count_pull++;
  874. }
  875. count_put++;
  876. }
  877. if (count_pull >= skb->len)
  878. dflag = 1;
  879. } else {
  880. #endif
  881. /* No DLE's in buff, so simply copy it */
  882. dflag = 1;
  883. if ((count_pull = skb->len) > len) {
  884. count_pull = len;
  885. dflag = 0;
  886. }
  887. count_put = count_pull;
  888. if (count_put > 1)
  889. tty_insert_flip_string(port, skb->data, count_put - 1);
  890. last = skb->data[count_put - 1];
  891. len -= count_put;
  892. #ifdef CONFIG_ISDN_AUDIO
  893. }
  894. #endif
  895. count += count_put;
  896. if (dflag) {
  897. /* We got all the data in this buff.
  898. * Now we can dequeue it.
  899. */
  900. if (cisco_hack)
  901. tty_insert_flip_char(port, last, 0xFF);
  902. else
  903. tty_insert_flip_char(port, last, TTY_NORMAL);
  904. #ifdef CONFIG_ISDN_AUDIO
  905. ISDN_AUDIO_SKB_LOCK(skb) = 0;
  906. #endif
  907. skb = skb_dequeue(&dev->drv[di]->rpqueue[channel]);
  908. dev_kfree_skb(skb);
  909. } else {
  910. tty_insert_flip_char(port, last, TTY_NORMAL);
  911. /* Not yet emptied this buff, so it
  912. * must stay in the queue, for further calls
  913. * but we pull off the data we got until now.
  914. */
  915. skb_pull(skb, count_pull);
  916. #ifdef CONFIG_ISDN_AUDIO
  917. ISDN_AUDIO_SKB_LOCK(skb) = 0;
  918. #endif
  919. }
  920. dev->drv[di]->rcvcount[channel] -= count_put;
  921. }
  922. return count;
  923. }
  924. static inline int
  925. isdn_minor2drv(int minor)
  926. {
  927. return (dev->drvmap[minor]);
  928. }
  929. static inline int
  930. isdn_minor2chan(int minor)
  931. {
  932. return (dev->chanmap[minor]);
  933. }
  934. static char *
  935. isdn_statstr(void)
  936. {
  937. static char istatbuf[2048];
  938. char *p;
  939. int i;
  940. sprintf(istatbuf, "idmap:\t");
  941. p = istatbuf + strlen(istatbuf);
  942. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  943. sprintf(p, "%s ", (dev->drvmap[i] < 0) ? "-" : dev->drvid[dev->drvmap[i]]);
  944. p = istatbuf + strlen(istatbuf);
  945. }
  946. sprintf(p, "\nchmap:\t");
  947. p = istatbuf + strlen(istatbuf);
  948. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  949. sprintf(p, "%d ", dev->chanmap[i]);
  950. p = istatbuf + strlen(istatbuf);
  951. }
  952. sprintf(p, "\ndrmap:\t");
  953. p = istatbuf + strlen(istatbuf);
  954. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  955. sprintf(p, "%d ", dev->drvmap[i]);
  956. p = istatbuf + strlen(istatbuf);
  957. }
  958. sprintf(p, "\nusage:\t");
  959. p = istatbuf + strlen(istatbuf);
  960. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  961. sprintf(p, "%d ", dev->usage[i]);
  962. p = istatbuf + strlen(istatbuf);
  963. }
  964. sprintf(p, "\nflags:\t");
  965. p = istatbuf + strlen(istatbuf);
  966. for (i = 0; i < ISDN_MAX_DRIVERS; i++) {
  967. if (dev->drv[i]) {
  968. sprintf(p, "%ld ", dev->drv[i]->online);
  969. p = istatbuf + strlen(istatbuf);
  970. } else {
  971. sprintf(p, "? ");
  972. p = istatbuf + strlen(istatbuf);
  973. }
  974. }
  975. sprintf(p, "\nphone:\t");
  976. p = istatbuf + strlen(istatbuf);
  977. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  978. sprintf(p, "%s ", dev->num[i]);
  979. p = istatbuf + strlen(istatbuf);
  980. }
  981. sprintf(p, "\n");
  982. return istatbuf;
  983. }
  984. /* Module interface-code */
  985. void
  986. isdn_info_update(void)
  987. {
  988. infostruct *p = dev->infochain;
  989. while (p) {
  990. *(p->private) = 1;
  991. p = (infostruct *) p->next;
  992. }
  993. wake_up_interruptible(&(dev->info_waitq));
  994. }
  995. static ssize_t
  996. isdn_read(struct file *file, char __user *buf, size_t count, loff_t *off)
  997. {
  998. uint minor = iminor(file_inode(file));
  999. int len = 0;
  1000. int drvidx;
  1001. int chidx;
  1002. int retval;
  1003. char *p;
  1004. mutex_lock(&isdn_mutex);
  1005. if (minor == ISDN_MINOR_STATUS) {
  1006. if (!file->private_data) {
  1007. if (file->f_flags & O_NONBLOCK) {
  1008. retval = -EAGAIN;
  1009. goto out;
  1010. }
  1011. wait_event_interruptible(dev->info_waitq,
  1012. file->private_data);
  1013. }
  1014. p = isdn_statstr();
  1015. file->private_data = NULL;
  1016. if ((len = strlen(p)) <= count) {
  1017. if (copy_to_user(buf, p, len)) {
  1018. retval = -EFAULT;
  1019. goto out;
  1020. }
  1021. *off += len;
  1022. retval = len;
  1023. goto out;
  1024. }
  1025. retval = 0;
  1026. goto out;
  1027. }
  1028. if (!dev->drivers) {
  1029. retval = -ENODEV;
  1030. goto out;
  1031. }
  1032. if (minor <= ISDN_MINOR_BMAX) {
  1033. printk(KERN_WARNING "isdn_read minor %d obsolete!\n", minor);
  1034. drvidx = isdn_minor2drv(minor);
  1035. if (drvidx < 0) {
  1036. retval = -ENODEV;
  1037. goto out;
  1038. }
  1039. if (!(dev->drv[drvidx]->flags & DRV_FLAG_RUNNING)) {
  1040. retval = -ENODEV;
  1041. goto out;
  1042. }
  1043. chidx = isdn_minor2chan(minor);
  1044. if (!(p = kmalloc(count, GFP_KERNEL))) {
  1045. retval = -ENOMEM;
  1046. goto out;
  1047. }
  1048. len = isdn_readbchan(drvidx, chidx, p, NULL, count,
  1049. &dev->drv[drvidx]->rcv_waitq[chidx]);
  1050. *off += len;
  1051. if (copy_to_user(buf, p, len))
  1052. len = -EFAULT;
  1053. kfree(p);
  1054. retval = len;
  1055. goto out;
  1056. }
  1057. if (minor <= ISDN_MINOR_CTRLMAX) {
  1058. drvidx = isdn_minor2drv(minor - ISDN_MINOR_CTRL);
  1059. if (drvidx < 0) {
  1060. retval = -ENODEV;
  1061. goto out;
  1062. }
  1063. if (!dev->drv[drvidx]->stavail) {
  1064. if (file->f_flags & O_NONBLOCK) {
  1065. retval = -EAGAIN;
  1066. goto out;
  1067. }
  1068. wait_event_interruptible(dev->drv[drvidx]->st_waitq,
  1069. dev->drv[drvidx]->stavail);
  1070. }
  1071. if (dev->drv[drvidx]->interface->readstat) {
  1072. if (count > dev->drv[drvidx]->stavail)
  1073. count = dev->drv[drvidx]->stavail;
  1074. len = dev->drv[drvidx]->interface->readstat(buf, count,
  1075. drvidx, isdn_minor2chan(minor - ISDN_MINOR_CTRL));
  1076. if (len < 0) {
  1077. retval = len;
  1078. goto out;
  1079. }
  1080. } else {
  1081. len = 0;
  1082. }
  1083. if (len)
  1084. dev->drv[drvidx]->stavail -= len;
  1085. else
  1086. dev->drv[drvidx]->stavail = 0;
  1087. *off += len;
  1088. retval = len;
  1089. goto out;
  1090. }
  1091. #ifdef CONFIG_ISDN_PPP
  1092. if (minor <= ISDN_MINOR_PPPMAX) {
  1093. retval = isdn_ppp_read(minor - ISDN_MINOR_PPP, file, buf, count);
  1094. goto out;
  1095. }
  1096. #endif
  1097. retval = -ENODEV;
  1098. out:
  1099. mutex_unlock(&isdn_mutex);
  1100. return retval;
  1101. }
  1102. static ssize_t
  1103. isdn_write(struct file *file, const char __user *buf, size_t count, loff_t *off)
  1104. {
  1105. uint minor = iminor(file_inode(file));
  1106. int drvidx;
  1107. int chidx;
  1108. int retval;
  1109. if (minor == ISDN_MINOR_STATUS)
  1110. return -EPERM;
  1111. if (!dev->drivers)
  1112. return -ENODEV;
  1113. mutex_lock(&isdn_mutex);
  1114. if (minor <= ISDN_MINOR_BMAX) {
  1115. printk(KERN_WARNING "isdn_write minor %d obsolete!\n", minor);
  1116. drvidx = isdn_minor2drv(minor);
  1117. if (drvidx < 0) {
  1118. retval = -ENODEV;
  1119. goto out;
  1120. }
  1121. if (!(dev->drv[drvidx]->flags & DRV_FLAG_RUNNING)) {
  1122. retval = -ENODEV;
  1123. goto out;
  1124. }
  1125. chidx = isdn_minor2chan(minor);
  1126. wait_event_interruptible(dev->drv[drvidx]->snd_waitq[chidx],
  1127. (retval = isdn_writebuf_stub(drvidx, chidx, buf, count)));
  1128. goto out;
  1129. }
  1130. if (minor <= ISDN_MINOR_CTRLMAX) {
  1131. drvidx = isdn_minor2drv(minor - ISDN_MINOR_CTRL);
  1132. if (drvidx < 0) {
  1133. retval = -ENODEV;
  1134. goto out;
  1135. }
  1136. /*
  1137. * We want to use the isdnctrl device to load the firmware
  1138. *
  1139. if (!(dev->drv[drvidx]->flags & DRV_FLAG_RUNNING))
  1140. return -ENODEV;
  1141. */
  1142. if (dev->drv[drvidx]->interface->writecmd)
  1143. retval = dev->drv[drvidx]->interface->
  1144. writecmd(buf, count, drvidx,
  1145. isdn_minor2chan(minor - ISDN_MINOR_CTRL));
  1146. else
  1147. retval = count;
  1148. goto out;
  1149. }
  1150. #ifdef CONFIG_ISDN_PPP
  1151. if (minor <= ISDN_MINOR_PPPMAX) {
  1152. retval = isdn_ppp_write(minor - ISDN_MINOR_PPP, file, buf, count);
  1153. goto out;
  1154. }
  1155. #endif
  1156. retval = -ENODEV;
  1157. out:
  1158. mutex_unlock(&isdn_mutex);
  1159. return retval;
  1160. }
  1161. static unsigned int
  1162. isdn_poll(struct file *file, poll_table *wait)
  1163. {
  1164. unsigned int mask = 0;
  1165. unsigned int minor = iminor(file_inode(file));
  1166. int drvidx = isdn_minor2drv(minor - ISDN_MINOR_CTRL);
  1167. mutex_lock(&isdn_mutex);
  1168. if (minor == ISDN_MINOR_STATUS) {
  1169. poll_wait(file, &(dev->info_waitq), wait);
  1170. /* mask = POLLOUT | POLLWRNORM; */
  1171. if (file->private_data) {
  1172. mask |= POLLIN | POLLRDNORM;
  1173. }
  1174. goto out;
  1175. }
  1176. if (minor >= ISDN_MINOR_CTRL && minor <= ISDN_MINOR_CTRLMAX) {
  1177. if (drvidx < 0) {
  1178. /* driver deregistered while file open */
  1179. mask = POLLHUP;
  1180. goto out;
  1181. }
  1182. poll_wait(file, &(dev->drv[drvidx]->st_waitq), wait);
  1183. mask = POLLOUT | POLLWRNORM;
  1184. if (dev->drv[drvidx]->stavail) {
  1185. mask |= POLLIN | POLLRDNORM;
  1186. }
  1187. goto out;
  1188. }
  1189. #ifdef CONFIG_ISDN_PPP
  1190. if (minor <= ISDN_MINOR_PPPMAX) {
  1191. mask = isdn_ppp_poll(file, wait);
  1192. goto out;
  1193. }
  1194. #endif
  1195. mask = POLLERR;
  1196. out:
  1197. mutex_unlock(&isdn_mutex);
  1198. return mask;
  1199. }
  1200. static int
  1201. isdn_ioctl(struct file *file, uint cmd, ulong arg)
  1202. {
  1203. uint minor = iminor(file_inode(file));
  1204. isdn_ctrl c;
  1205. int drvidx;
  1206. int ret;
  1207. int i;
  1208. char __user *p;
  1209. char *s;
  1210. union iocpar {
  1211. char name[10];
  1212. char bname[22];
  1213. isdn_ioctl_struct iocts;
  1214. isdn_net_ioctl_phone phone;
  1215. isdn_net_ioctl_cfg cfg;
  1216. } iocpar;
  1217. void __user *argp = (void __user *)arg;
  1218. #define name iocpar.name
  1219. #define bname iocpar.bname
  1220. #define iocts iocpar.iocts
  1221. #define phone iocpar.phone
  1222. #define cfg iocpar.cfg
  1223. if (minor == ISDN_MINOR_STATUS) {
  1224. switch (cmd) {
  1225. case IIOCGETDVR:
  1226. return (TTY_DV +
  1227. (NET_DV << 8) +
  1228. (INF_DV << 16));
  1229. case IIOCGETCPS:
  1230. if (arg) {
  1231. ulong __user *p = argp;
  1232. int i;
  1233. if (!access_ok(VERIFY_WRITE, p,
  1234. sizeof(ulong) * ISDN_MAX_CHANNELS * 2))
  1235. return -EFAULT;
  1236. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  1237. put_user(dev->ibytes[i], p++);
  1238. put_user(dev->obytes[i], p++);
  1239. }
  1240. return 0;
  1241. } else
  1242. return -EINVAL;
  1243. break;
  1244. case IIOCNETGPN:
  1245. /* Get peer phone number of a connected
  1246. * isdn network interface */
  1247. if (arg) {
  1248. if (copy_from_user(&phone, argp, sizeof(phone)))
  1249. return -EFAULT;
  1250. return isdn_net_getpeer(&phone, argp);
  1251. } else
  1252. return -EINVAL;
  1253. default:
  1254. return -EINVAL;
  1255. }
  1256. }
  1257. if (!dev->drivers)
  1258. return -ENODEV;
  1259. if (minor <= ISDN_MINOR_BMAX) {
  1260. drvidx = isdn_minor2drv(minor);
  1261. if (drvidx < 0)
  1262. return -ENODEV;
  1263. if (!(dev->drv[drvidx]->flags & DRV_FLAG_RUNNING))
  1264. return -ENODEV;
  1265. return 0;
  1266. }
  1267. if (minor <= ISDN_MINOR_CTRLMAX) {
  1268. /*
  1269. * isdn net devices manage lots of configuration variables as linked lists.
  1270. * Those lists must only be manipulated from user space. Some of the ioctl's
  1271. * service routines access user space and are not atomic. Therefore, ioctl's
  1272. * manipulating the lists and ioctl's sleeping while accessing the lists
  1273. * are serialized by means of a semaphore.
  1274. */
  1275. switch (cmd) {
  1276. case IIOCNETDWRSET:
  1277. printk(KERN_INFO "INFO: ISDN_DW_ABC_EXTENSION not enabled\n");
  1278. return (-EINVAL);
  1279. case IIOCNETLCR:
  1280. printk(KERN_INFO "INFO: ISDN_ABC_LCR_SUPPORT not enabled\n");
  1281. return -ENODEV;
  1282. case IIOCNETAIF:
  1283. /* Add a network-interface */
  1284. if (arg) {
  1285. if (copy_from_user(name, argp, sizeof(name)))
  1286. return -EFAULT;
  1287. s = name;
  1288. } else {
  1289. s = NULL;
  1290. }
  1291. ret = mutex_lock_interruptible(&dev->mtx);
  1292. if (ret) return ret;
  1293. if ((s = isdn_net_new(s, NULL))) {
  1294. if (copy_to_user(argp, s, strlen(s) + 1)) {
  1295. ret = -EFAULT;
  1296. } else {
  1297. ret = 0;
  1298. }
  1299. } else
  1300. ret = -ENODEV;
  1301. mutex_unlock(&dev->mtx);
  1302. return ret;
  1303. case IIOCNETASL:
  1304. /* Add a slave to a network-interface */
  1305. if (arg) {
  1306. if (copy_from_user(bname, argp, sizeof(bname) - 1))
  1307. return -EFAULT;
  1308. bname[sizeof(bname)-1] = 0;
  1309. } else
  1310. return -EINVAL;
  1311. ret = mutex_lock_interruptible(&dev->mtx);
  1312. if (ret) return ret;
  1313. if ((s = isdn_net_newslave(bname))) {
  1314. if (copy_to_user(argp, s, strlen(s) + 1)) {
  1315. ret = -EFAULT;
  1316. } else {
  1317. ret = 0;
  1318. }
  1319. } else
  1320. ret = -ENODEV;
  1321. mutex_unlock(&dev->mtx);
  1322. return ret;
  1323. case IIOCNETDIF:
  1324. /* Delete a network-interface */
  1325. if (arg) {
  1326. if (copy_from_user(name, argp, sizeof(name)))
  1327. return -EFAULT;
  1328. ret = mutex_lock_interruptible(&dev->mtx);
  1329. if (ret) return ret;
  1330. ret = isdn_net_rm(name);
  1331. mutex_unlock(&dev->mtx);
  1332. return ret;
  1333. } else
  1334. return -EINVAL;
  1335. case IIOCNETSCF:
  1336. /* Set configurable parameters of a network-interface */
  1337. if (arg) {
  1338. if (copy_from_user(&cfg, argp, sizeof(cfg)))
  1339. return -EFAULT;
  1340. return isdn_net_setcfg(&cfg);
  1341. } else
  1342. return -EINVAL;
  1343. case IIOCNETGCF:
  1344. /* Get configurable parameters of a network-interface */
  1345. if (arg) {
  1346. if (copy_from_user(&cfg, argp, sizeof(cfg)))
  1347. return -EFAULT;
  1348. if (!(ret = isdn_net_getcfg(&cfg))) {
  1349. if (copy_to_user(argp, &cfg, sizeof(cfg)))
  1350. return -EFAULT;
  1351. }
  1352. return ret;
  1353. } else
  1354. return -EINVAL;
  1355. case IIOCNETANM:
  1356. /* Add a phone-number to a network-interface */
  1357. if (arg) {
  1358. if (copy_from_user(&phone, argp, sizeof(phone)))
  1359. return -EFAULT;
  1360. ret = mutex_lock_interruptible(&dev->mtx);
  1361. if (ret) return ret;
  1362. ret = isdn_net_addphone(&phone);
  1363. mutex_unlock(&dev->mtx);
  1364. return ret;
  1365. } else
  1366. return -EINVAL;
  1367. case IIOCNETGNM:
  1368. /* Get list of phone-numbers of a network-interface */
  1369. if (arg) {
  1370. if (copy_from_user(&phone, argp, sizeof(phone)))
  1371. return -EFAULT;
  1372. ret = mutex_lock_interruptible(&dev->mtx);
  1373. if (ret) return ret;
  1374. ret = isdn_net_getphones(&phone, argp);
  1375. mutex_unlock(&dev->mtx);
  1376. return ret;
  1377. } else
  1378. return -EINVAL;
  1379. case IIOCNETDNM:
  1380. /* Delete a phone-number of a network-interface */
  1381. if (arg) {
  1382. if (copy_from_user(&phone, argp, sizeof(phone)))
  1383. return -EFAULT;
  1384. ret = mutex_lock_interruptible(&dev->mtx);
  1385. if (ret) return ret;
  1386. ret = isdn_net_delphone(&phone);
  1387. mutex_unlock(&dev->mtx);
  1388. return ret;
  1389. } else
  1390. return -EINVAL;
  1391. case IIOCNETDIL:
  1392. /* Force dialing of a network-interface */
  1393. if (arg) {
  1394. if (copy_from_user(name, argp, sizeof(name)))
  1395. return -EFAULT;
  1396. return isdn_net_force_dial(name);
  1397. } else
  1398. return -EINVAL;
  1399. #ifdef CONFIG_ISDN_PPP
  1400. case IIOCNETALN:
  1401. if (!arg)
  1402. return -EINVAL;
  1403. if (copy_from_user(name, argp, sizeof(name)))
  1404. return -EFAULT;
  1405. return isdn_ppp_dial_slave(name);
  1406. case IIOCNETDLN:
  1407. if (!arg)
  1408. return -EINVAL;
  1409. if (copy_from_user(name, argp, sizeof(name)))
  1410. return -EFAULT;
  1411. return isdn_ppp_hangup_slave(name);
  1412. #endif
  1413. case IIOCNETHUP:
  1414. /* Force hangup of a network-interface */
  1415. if (!arg)
  1416. return -EINVAL;
  1417. if (copy_from_user(name, argp, sizeof(name)))
  1418. return -EFAULT;
  1419. return isdn_net_force_hangup(name);
  1420. break;
  1421. case IIOCSETVER:
  1422. dev->net_verbose = arg;
  1423. printk(KERN_INFO "isdn: Verbose-Level is %d\n", dev->net_verbose);
  1424. return 0;
  1425. case IIOCSETGST:
  1426. if (arg)
  1427. dev->global_flags |= ISDN_GLOBAL_STOPPED;
  1428. else
  1429. dev->global_flags &= ~ISDN_GLOBAL_STOPPED;
  1430. printk(KERN_INFO "isdn: Global Mode %s\n",
  1431. (dev->global_flags & ISDN_GLOBAL_STOPPED) ? "stopped" : "running");
  1432. return 0;
  1433. case IIOCSETBRJ:
  1434. drvidx = -1;
  1435. if (arg) {
  1436. int i;
  1437. char *p;
  1438. if (copy_from_user(&iocts, argp,
  1439. sizeof(isdn_ioctl_struct)))
  1440. return -EFAULT;
  1441. iocts.drvid[sizeof(iocts.drvid) - 1] = 0;
  1442. if (strlen(iocts.drvid)) {
  1443. if ((p = strchr(iocts.drvid, ',')))
  1444. *p = 0;
  1445. drvidx = -1;
  1446. for (i = 0; i < ISDN_MAX_DRIVERS; i++)
  1447. if (!(strcmp(dev->drvid[i], iocts.drvid))) {
  1448. drvidx = i;
  1449. break;
  1450. }
  1451. }
  1452. }
  1453. if (drvidx == -1)
  1454. return -ENODEV;
  1455. if (iocts.arg)
  1456. dev->drv[drvidx]->flags |= DRV_FLAG_REJBUS;
  1457. else
  1458. dev->drv[drvidx]->flags &= ~DRV_FLAG_REJBUS;
  1459. return 0;
  1460. case IIOCSIGPRF:
  1461. dev->profd = current;
  1462. return 0;
  1463. break;
  1464. case IIOCGETPRF:
  1465. /* Get all Modem-Profiles */
  1466. if (arg) {
  1467. char __user *p = argp;
  1468. int i;
  1469. if (!access_ok(VERIFY_WRITE, argp,
  1470. (ISDN_MODEM_NUMREG + ISDN_MSNLEN + ISDN_LMSNLEN)
  1471. * ISDN_MAX_CHANNELS))
  1472. return -EFAULT;
  1473. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  1474. if (copy_to_user(p, dev->mdm.info[i].emu.profile,
  1475. ISDN_MODEM_NUMREG))
  1476. return -EFAULT;
  1477. p += ISDN_MODEM_NUMREG;
  1478. if (copy_to_user(p, dev->mdm.info[i].emu.pmsn, ISDN_MSNLEN))
  1479. return -EFAULT;
  1480. p += ISDN_MSNLEN;
  1481. if (copy_to_user(p, dev->mdm.info[i].emu.plmsn, ISDN_LMSNLEN))
  1482. return -EFAULT;
  1483. p += ISDN_LMSNLEN;
  1484. }
  1485. return (ISDN_MODEM_NUMREG + ISDN_MSNLEN + ISDN_LMSNLEN) * ISDN_MAX_CHANNELS;
  1486. } else
  1487. return -EINVAL;
  1488. break;
  1489. case IIOCSETPRF:
  1490. /* Set all Modem-Profiles */
  1491. if (arg) {
  1492. char __user *p = argp;
  1493. int i;
  1494. if (!access_ok(VERIFY_READ, argp,
  1495. (ISDN_MODEM_NUMREG + ISDN_MSNLEN + ISDN_LMSNLEN)
  1496. * ISDN_MAX_CHANNELS))
  1497. return -EFAULT;
  1498. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  1499. if (copy_from_user(dev->mdm.info[i].emu.profile, p,
  1500. ISDN_MODEM_NUMREG))
  1501. return -EFAULT;
  1502. p += ISDN_MODEM_NUMREG;
  1503. if (copy_from_user(dev->mdm.info[i].emu.plmsn, p, ISDN_LMSNLEN))
  1504. return -EFAULT;
  1505. p += ISDN_LMSNLEN;
  1506. if (copy_from_user(dev->mdm.info[i].emu.pmsn, p, ISDN_MSNLEN))
  1507. return -EFAULT;
  1508. p += ISDN_MSNLEN;
  1509. }
  1510. return 0;
  1511. } else
  1512. return -EINVAL;
  1513. break;
  1514. case IIOCSETMAP:
  1515. case IIOCGETMAP:
  1516. /* Set/Get MSN->EAZ-Mapping for a driver */
  1517. if (arg) {
  1518. if (copy_from_user(&iocts, argp,
  1519. sizeof(isdn_ioctl_struct)))
  1520. return -EFAULT;
  1521. iocts.drvid[sizeof(iocts.drvid) - 1] = 0;
  1522. if (strlen(iocts.drvid)) {
  1523. drvidx = -1;
  1524. for (i = 0; i < ISDN_MAX_DRIVERS; i++)
  1525. if (!(strcmp(dev->drvid[i], iocts.drvid))) {
  1526. drvidx = i;
  1527. break;
  1528. }
  1529. } else
  1530. drvidx = 0;
  1531. if (drvidx == -1)
  1532. return -ENODEV;
  1533. if (cmd == IIOCSETMAP) {
  1534. int loop = 1;
  1535. p = (char __user *) iocts.arg;
  1536. i = 0;
  1537. while (loop) {
  1538. int j = 0;
  1539. while (1) {
  1540. if (!access_ok(VERIFY_READ, p, 1))
  1541. return -EFAULT;
  1542. get_user(bname[j], p++);
  1543. switch (bname[j]) {
  1544. case '\0':
  1545. loop = 0;
  1546. /* Fall through */
  1547. case ',':
  1548. bname[j] = '\0';
  1549. strcpy(dev->drv[drvidx]->msn2eaz[i], bname);
  1550. j = ISDN_MSNLEN;
  1551. break;
  1552. default:
  1553. j++;
  1554. }
  1555. if (j >= ISDN_MSNLEN)
  1556. break;
  1557. }
  1558. if (++i > 9)
  1559. break;
  1560. }
  1561. } else {
  1562. p = (char __user *) iocts.arg;
  1563. for (i = 0; i < 10; i++) {
  1564. snprintf(bname, sizeof(bname), "%s%s",
  1565. strlen(dev->drv[drvidx]->msn2eaz[i]) ?
  1566. dev->drv[drvidx]->msn2eaz[i] : "_",
  1567. (i < 9) ? "," : "\0");
  1568. if (copy_to_user(p, bname, strlen(bname) + 1))
  1569. return -EFAULT;
  1570. p += strlen(bname);
  1571. }
  1572. }
  1573. return 0;
  1574. } else
  1575. return -EINVAL;
  1576. case IIOCDBGVAR:
  1577. return -EINVAL;
  1578. default:
  1579. if ((cmd & IIOCDRVCTL) == IIOCDRVCTL)
  1580. cmd = ((cmd >> _IOC_NRSHIFT) & _IOC_NRMASK) & ISDN_DRVIOCTL_MASK;
  1581. else
  1582. return -EINVAL;
  1583. if (arg) {
  1584. int i;
  1585. char *p;
  1586. if (copy_from_user(&iocts, argp, sizeof(isdn_ioctl_struct)))
  1587. return -EFAULT;
  1588. iocts.drvid[sizeof(iocts.drvid) - 1] = 0;
  1589. if (strlen(iocts.drvid)) {
  1590. if ((p = strchr(iocts.drvid, ',')))
  1591. *p = 0;
  1592. drvidx = -1;
  1593. for (i = 0; i < ISDN_MAX_DRIVERS; i++)
  1594. if (!(strcmp(dev->drvid[i], iocts.drvid))) {
  1595. drvidx = i;
  1596. break;
  1597. }
  1598. } else
  1599. drvidx = 0;
  1600. if (drvidx == -1)
  1601. return -ENODEV;
  1602. if (!access_ok(VERIFY_WRITE, argp,
  1603. sizeof(isdn_ioctl_struct)))
  1604. return -EFAULT;
  1605. c.driver = drvidx;
  1606. c.command = ISDN_CMD_IOCTL;
  1607. c.arg = cmd;
  1608. memcpy(c.parm.num, &iocts.arg, sizeof(ulong));
  1609. ret = isdn_command(&c);
  1610. memcpy(&iocts.arg, c.parm.num, sizeof(ulong));
  1611. if (copy_to_user(argp, &iocts, sizeof(isdn_ioctl_struct)))
  1612. return -EFAULT;
  1613. return ret;
  1614. } else
  1615. return -EINVAL;
  1616. }
  1617. }
  1618. #ifdef CONFIG_ISDN_PPP
  1619. if (minor <= ISDN_MINOR_PPPMAX)
  1620. return (isdn_ppp_ioctl(minor - ISDN_MINOR_PPP, file, cmd, arg));
  1621. #endif
  1622. return -ENODEV;
  1623. #undef name
  1624. #undef bname
  1625. #undef iocts
  1626. #undef phone
  1627. #undef cfg
  1628. }
  1629. static long
  1630. isdn_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  1631. {
  1632. int ret;
  1633. mutex_lock(&isdn_mutex);
  1634. ret = isdn_ioctl(file, cmd, arg);
  1635. mutex_unlock(&isdn_mutex);
  1636. return ret;
  1637. }
  1638. /*
  1639. * Open the device code.
  1640. */
  1641. static int
  1642. isdn_open(struct inode *ino, struct file *filep)
  1643. {
  1644. uint minor = iminor(ino);
  1645. int drvidx;
  1646. int chidx;
  1647. int retval = -ENODEV;
  1648. mutex_lock(&isdn_mutex);
  1649. if (minor == ISDN_MINOR_STATUS) {
  1650. infostruct *p;
  1651. if ((p = kmalloc(sizeof(infostruct), GFP_KERNEL))) {
  1652. p->next = (char *) dev->infochain;
  1653. p->private = (char *) &(filep->private_data);
  1654. dev->infochain = p;
  1655. /* At opening we allow a single update */
  1656. filep->private_data = (char *) 1;
  1657. retval = 0;
  1658. goto out;
  1659. } else {
  1660. retval = -ENOMEM;
  1661. goto out;
  1662. }
  1663. }
  1664. if (!dev->channels)
  1665. goto out;
  1666. if (minor <= ISDN_MINOR_BMAX) {
  1667. printk(KERN_WARNING "isdn_open minor %d obsolete!\n", minor);
  1668. drvidx = isdn_minor2drv(minor);
  1669. if (drvidx < 0)
  1670. goto out;
  1671. chidx = isdn_minor2chan(minor);
  1672. if (!(dev->drv[drvidx]->flags & DRV_FLAG_RUNNING))
  1673. goto out;
  1674. if (!(dev->drv[drvidx]->online & (1 << chidx)))
  1675. goto out;
  1676. isdn_lock_drivers();
  1677. retval = 0;
  1678. goto out;
  1679. }
  1680. if (minor <= ISDN_MINOR_CTRLMAX) {
  1681. drvidx = isdn_minor2drv(minor - ISDN_MINOR_CTRL);
  1682. if (drvidx < 0)
  1683. goto out;
  1684. isdn_lock_drivers();
  1685. retval = 0;
  1686. goto out;
  1687. }
  1688. #ifdef CONFIG_ISDN_PPP
  1689. if (minor <= ISDN_MINOR_PPPMAX) {
  1690. retval = isdn_ppp_open(minor - ISDN_MINOR_PPP, filep);
  1691. if (retval == 0)
  1692. isdn_lock_drivers();
  1693. goto out;
  1694. }
  1695. #endif
  1696. out:
  1697. nonseekable_open(ino, filep);
  1698. mutex_unlock(&isdn_mutex);
  1699. return retval;
  1700. }
  1701. static int
  1702. isdn_close(struct inode *ino, struct file *filep)
  1703. {
  1704. uint minor = iminor(ino);
  1705. mutex_lock(&isdn_mutex);
  1706. if (minor == ISDN_MINOR_STATUS) {
  1707. infostruct *p = dev->infochain;
  1708. infostruct *q = NULL;
  1709. while (p) {
  1710. if (p->private == (char *) &(filep->private_data)) {
  1711. if (q)
  1712. q->next = p->next;
  1713. else
  1714. dev->infochain = (infostruct *) (p->next);
  1715. kfree(p);
  1716. goto out;
  1717. }
  1718. q = p;
  1719. p = (infostruct *) (p->next);
  1720. }
  1721. printk(KERN_WARNING "isdn: No private data while closing isdnctrl\n");
  1722. goto out;
  1723. }
  1724. isdn_unlock_drivers();
  1725. if (minor <= ISDN_MINOR_BMAX)
  1726. goto out;
  1727. if (minor <= ISDN_MINOR_CTRLMAX) {
  1728. if (dev->profd == current)
  1729. dev->profd = NULL;
  1730. goto out;
  1731. }
  1732. #ifdef CONFIG_ISDN_PPP
  1733. if (minor <= ISDN_MINOR_PPPMAX)
  1734. isdn_ppp_release(minor - ISDN_MINOR_PPP, filep);
  1735. #endif
  1736. out:
  1737. mutex_unlock(&isdn_mutex);
  1738. return 0;
  1739. }
  1740. static const struct file_operations isdn_fops =
  1741. {
  1742. .owner = THIS_MODULE,
  1743. .llseek = no_llseek,
  1744. .read = isdn_read,
  1745. .write = isdn_write,
  1746. .poll = isdn_poll,
  1747. .unlocked_ioctl = isdn_unlocked_ioctl,
  1748. .open = isdn_open,
  1749. .release = isdn_close,
  1750. };
  1751. char *
  1752. isdn_map_eaz2msn(char *msn, int di)
  1753. {
  1754. isdn_driver_t *this = dev->drv[di];
  1755. int i;
  1756. if (strlen(msn) == 1) {
  1757. i = msn[0] - '0';
  1758. if ((i >= 0) && (i <= 9))
  1759. if (strlen(this->msn2eaz[i]))
  1760. return (this->msn2eaz[i]);
  1761. }
  1762. return (msn);
  1763. }
  1764. /*
  1765. * Find an unused ISDN-channel, whose feature-flags match the
  1766. * given L2- and L3-protocols.
  1767. */
  1768. #define L2V (~(ISDN_FEATURE_L2_V11096 | ISDN_FEATURE_L2_V11019 | ISDN_FEATURE_L2_V11038))
  1769. /*
  1770. * This function must be called with holding the dev->lock.
  1771. */
  1772. int
  1773. isdn_get_free_channel(int usage, int l2_proto, int l3_proto, int pre_dev
  1774. , int pre_chan, char *msn)
  1775. {
  1776. int i;
  1777. ulong features;
  1778. ulong vfeatures;
  1779. features = ((1 << l2_proto) | (0x10000 << l3_proto));
  1780. vfeatures = (((1 << l2_proto) | (0x10000 << l3_proto)) &
  1781. ~(ISDN_FEATURE_L2_V11096 | ISDN_FEATURE_L2_V11019 | ISDN_FEATURE_L2_V11038));
  1782. /* If Layer-2 protocol is V.110, accept drivers with
  1783. * transparent feature even if these don't support V.110
  1784. * because we can emulate this in linklevel.
  1785. */
  1786. for (i = 0; i < ISDN_MAX_CHANNELS; i++)
  1787. if (USG_NONE(dev->usage[i]) &&
  1788. (dev->drvmap[i] != -1)) {
  1789. int d = dev->drvmap[i];
  1790. if ((dev->usage[i] & ISDN_USAGE_EXCLUSIVE) &&
  1791. ((pre_dev != d) || (pre_chan != dev->chanmap[i])))
  1792. continue;
  1793. if (!strcmp(isdn_map_eaz2msn(msn, d), "-"))
  1794. continue;
  1795. if (dev->usage[i] & ISDN_USAGE_DISABLED)
  1796. continue; /* usage not allowed */
  1797. if (dev->drv[d]->flags & DRV_FLAG_RUNNING) {
  1798. if (((dev->drv[d]->interface->features & features) == features) ||
  1799. (((dev->drv[d]->interface->features & vfeatures) == vfeatures) &&
  1800. (dev->drv[d]->interface->features & ISDN_FEATURE_L2_TRANS))) {
  1801. if ((pre_dev < 0) || (pre_chan < 0)) {
  1802. dev->usage[i] &= ISDN_USAGE_EXCLUSIVE;
  1803. dev->usage[i] |= usage;
  1804. isdn_info_update();
  1805. return i;
  1806. } else {
  1807. if ((pre_dev == d) && (pre_chan == dev->chanmap[i])) {
  1808. dev->usage[i] &= ISDN_USAGE_EXCLUSIVE;
  1809. dev->usage[i] |= usage;
  1810. isdn_info_update();
  1811. return i;
  1812. }
  1813. }
  1814. }
  1815. }
  1816. }
  1817. return -1;
  1818. }
  1819. /*
  1820. * Set state of ISDN-channel to 'unused'
  1821. */
  1822. void
  1823. isdn_free_channel(int di, int ch, int usage)
  1824. {
  1825. int i;
  1826. if ((di < 0) || (ch < 0)) {
  1827. printk(KERN_WARNING "%s: called with invalid drv(%d) or channel(%d)\n",
  1828. __func__, di, ch);
  1829. return;
  1830. }
  1831. for (i = 0; i < ISDN_MAX_CHANNELS; i++)
  1832. if (((!usage) || ((dev->usage[i] & ISDN_USAGE_MASK) == usage)) &&
  1833. (dev->drvmap[i] == di) &&
  1834. (dev->chanmap[i] == ch)) {
  1835. dev->usage[i] &= (ISDN_USAGE_NONE | ISDN_USAGE_EXCLUSIVE);
  1836. strcpy(dev->num[i], "???");
  1837. dev->ibytes[i] = 0;
  1838. dev->obytes[i] = 0;
  1839. // 20.10.99 JIM, try to reinitialize v110 !
  1840. dev->v110emu[i] = 0;
  1841. atomic_set(&(dev->v110use[i]), 0);
  1842. isdn_v110_close(dev->v110[i]);
  1843. dev->v110[i] = NULL;
  1844. // 20.10.99 JIM, try to reinitialize v110 !
  1845. isdn_info_update();
  1846. if (dev->drv[di])
  1847. skb_queue_purge(&dev->drv[di]->rpqueue[ch]);
  1848. }
  1849. }
  1850. /*
  1851. * Cancel Exclusive-Flag for ISDN-channel
  1852. */
  1853. void
  1854. isdn_unexclusive_channel(int di, int ch)
  1855. {
  1856. int i;
  1857. for (i = 0; i < ISDN_MAX_CHANNELS; i++)
  1858. if ((dev->drvmap[i] == di) &&
  1859. (dev->chanmap[i] == ch)) {
  1860. dev->usage[i] &= ~ISDN_USAGE_EXCLUSIVE;
  1861. isdn_info_update();
  1862. return;
  1863. }
  1864. }
  1865. /*
  1866. * writebuf replacement for SKB_ABLE drivers
  1867. */
  1868. static int
  1869. isdn_writebuf_stub(int drvidx, int chan, const u_char __user *buf, int len)
  1870. {
  1871. int ret;
  1872. int hl = dev->drv[drvidx]->interface->hl_hdrlen;
  1873. struct sk_buff *skb = alloc_skb(hl + len, GFP_ATOMIC);
  1874. if (!skb)
  1875. return -ENOMEM;
  1876. skb_reserve(skb, hl);
  1877. if (copy_from_user(skb_put(skb, len), buf, len)) {
  1878. dev_kfree_skb(skb);
  1879. return -EFAULT;
  1880. }
  1881. ret = dev->drv[drvidx]->interface->writebuf_skb(drvidx, chan, 1, skb);
  1882. if (ret <= 0)
  1883. dev_kfree_skb(skb);
  1884. if (ret > 0)
  1885. dev->obytes[isdn_dc2minor(drvidx, chan)] += ret;
  1886. return ret;
  1887. }
  1888. /*
  1889. * Return: length of data on success, -ERRcode on failure.
  1890. */
  1891. int
  1892. isdn_writebuf_skb_stub(int drvidx, int chan, int ack, struct sk_buff *skb)
  1893. {
  1894. int ret;
  1895. struct sk_buff *nskb = NULL;
  1896. int v110_ret = skb->len;
  1897. int idx = isdn_dc2minor(drvidx, chan);
  1898. if (dev->v110[idx]) {
  1899. atomic_inc(&dev->v110use[idx]);
  1900. nskb = isdn_v110_encode(dev->v110[idx], skb);
  1901. atomic_dec(&dev->v110use[idx]);
  1902. if (!nskb)
  1903. return 0;
  1904. v110_ret = *((int *)nskb->data);
  1905. skb_pull(nskb, sizeof(int));
  1906. if (!nskb->len) {
  1907. dev_kfree_skb(nskb);
  1908. return v110_ret;
  1909. }
  1910. /* V.110 must always be acknowledged */
  1911. ack = 1;
  1912. ret = dev->drv[drvidx]->interface->writebuf_skb(drvidx, chan, ack, nskb);
  1913. } else {
  1914. int hl = dev->drv[drvidx]->interface->hl_hdrlen;
  1915. if (skb_headroom(skb) < hl) {
  1916. /*
  1917. * This should only occur when new HL driver with
  1918. * increased hl_hdrlen was loaded after netdevice
  1919. * was created and connected to the new driver.
  1920. *
  1921. * The V.110 branch (re-allocates on its own) does
  1922. * not need this
  1923. */
  1924. struct sk_buff *skb_tmp;
  1925. skb_tmp = skb_realloc_headroom(skb, hl);
  1926. printk(KERN_DEBUG "isdn_writebuf_skb_stub: reallocating headroom%s\n", skb_tmp ? "" : " failed");
  1927. if (!skb_tmp) return -ENOMEM; /* 0 better? */
  1928. ret = dev->drv[drvidx]->interface->writebuf_skb(drvidx, chan, ack, skb_tmp);
  1929. if (ret > 0) {
  1930. dev_kfree_skb(skb);
  1931. } else {
  1932. dev_kfree_skb(skb_tmp);
  1933. }
  1934. } else {
  1935. ret = dev->drv[drvidx]->interface->writebuf_skb(drvidx, chan, ack, skb);
  1936. }
  1937. }
  1938. if (ret > 0) {
  1939. dev->obytes[idx] += ret;
  1940. if (dev->v110[idx]) {
  1941. atomic_inc(&dev->v110use[idx]);
  1942. dev->v110[idx]->skbuser++;
  1943. atomic_dec(&dev->v110use[idx]);
  1944. /* For V.110 return unencoded data length */
  1945. ret = v110_ret;
  1946. /* if the complete frame was send we free the skb;
  1947. if not upper function will requeue the skb */
  1948. if (ret == skb->len)
  1949. dev_kfree_skb(skb);
  1950. }
  1951. } else
  1952. if (dev->v110[idx])
  1953. dev_kfree_skb(nskb);
  1954. return ret;
  1955. }
  1956. static int
  1957. isdn_add_channels(isdn_driver_t *d, int drvidx, int n, int adding)
  1958. {
  1959. int j, k, m;
  1960. init_waitqueue_head(&d->st_waitq);
  1961. if (d->flags & DRV_FLAG_RUNNING)
  1962. return -1;
  1963. if (n < 1) return 0;
  1964. m = (adding) ? d->channels + n : n;
  1965. if (dev->channels + n > ISDN_MAX_CHANNELS) {
  1966. printk(KERN_WARNING "register_isdn: Max. %d channels supported\n",
  1967. ISDN_MAX_CHANNELS);
  1968. return -1;
  1969. }
  1970. if ((adding) && (d->rcverr))
  1971. kfree(d->rcverr);
  1972. if (!(d->rcverr = kzalloc(sizeof(int) * m, GFP_ATOMIC))) {
  1973. printk(KERN_WARNING "register_isdn: Could not alloc rcverr\n");
  1974. return -1;
  1975. }
  1976. if ((adding) && (d->rcvcount))
  1977. kfree(d->rcvcount);
  1978. if (!(d->rcvcount = kzalloc(sizeof(int) * m, GFP_ATOMIC))) {
  1979. printk(KERN_WARNING "register_isdn: Could not alloc rcvcount\n");
  1980. if (!adding)
  1981. kfree(d->rcverr);
  1982. return -1;
  1983. }
  1984. if ((adding) && (d->rpqueue)) {
  1985. for (j = 0; j < d->channels; j++)
  1986. skb_queue_purge(&d->rpqueue[j]);
  1987. kfree(d->rpqueue);
  1988. }
  1989. if (!(d->rpqueue = kmalloc(sizeof(struct sk_buff_head) * m, GFP_ATOMIC))) {
  1990. printk(KERN_WARNING "register_isdn: Could not alloc rpqueue\n");
  1991. if (!adding) {
  1992. kfree(d->rcvcount);
  1993. kfree(d->rcverr);
  1994. }
  1995. return -1;
  1996. }
  1997. for (j = 0; j < m; j++) {
  1998. skb_queue_head_init(&d->rpqueue[j]);
  1999. }
  2000. if ((adding) && (d->rcv_waitq))
  2001. kfree(d->rcv_waitq);
  2002. d->rcv_waitq = kmalloc(sizeof(wait_queue_head_t) * 2 * m, GFP_ATOMIC);
  2003. if (!d->rcv_waitq) {
  2004. printk(KERN_WARNING "register_isdn: Could not alloc rcv_waitq\n");
  2005. if (!adding) {
  2006. kfree(d->rpqueue);
  2007. kfree(d->rcvcount);
  2008. kfree(d->rcverr);
  2009. }
  2010. return -1;
  2011. }
  2012. d->snd_waitq = d->rcv_waitq + m;
  2013. for (j = 0; j < m; j++) {
  2014. init_waitqueue_head(&d->rcv_waitq[j]);
  2015. init_waitqueue_head(&d->snd_waitq[j]);
  2016. }
  2017. dev->channels += n;
  2018. for (j = d->channels; j < m; j++)
  2019. for (k = 0; k < ISDN_MAX_CHANNELS; k++)
  2020. if (dev->chanmap[k] < 0) {
  2021. dev->chanmap[k] = j;
  2022. dev->drvmap[k] = drvidx;
  2023. break;
  2024. }
  2025. d->channels = m;
  2026. return 0;
  2027. }
  2028. /*
  2029. * Low-level-driver registration
  2030. */
  2031. static void
  2032. set_global_features(void)
  2033. {
  2034. int drvidx;
  2035. dev->global_features = 0;
  2036. for (drvidx = 0; drvidx < ISDN_MAX_DRIVERS; drvidx++) {
  2037. if (!dev->drv[drvidx])
  2038. continue;
  2039. if (dev->drv[drvidx]->interface)
  2040. dev->global_features |= dev->drv[drvidx]->interface->features;
  2041. }
  2042. }
  2043. #ifdef CONFIG_ISDN_DIVERSION
  2044. static char *map_drvname(int di)
  2045. {
  2046. if ((di < 0) || (di >= ISDN_MAX_DRIVERS))
  2047. return (NULL);
  2048. return (dev->drvid[di]); /* driver name */
  2049. } /* map_drvname */
  2050. static int map_namedrv(char *id)
  2051. { int i;
  2052. for (i = 0; i < ISDN_MAX_DRIVERS; i++)
  2053. { if (!strcmp(dev->drvid[i], id))
  2054. return (i);
  2055. }
  2056. return (-1);
  2057. } /* map_namedrv */
  2058. int DIVERT_REG_NAME(isdn_divert_if *i_div)
  2059. {
  2060. if (i_div->if_magic != DIVERT_IF_MAGIC)
  2061. return (DIVERT_VER_ERR);
  2062. switch (i_div->cmd)
  2063. {
  2064. case DIVERT_CMD_REL:
  2065. if (divert_if != i_div)
  2066. return (DIVERT_REL_ERR);
  2067. divert_if = NULL; /* free interface */
  2068. return (DIVERT_NO_ERR);
  2069. case DIVERT_CMD_REG:
  2070. if (divert_if)
  2071. return (DIVERT_REG_ERR);
  2072. i_div->ll_cmd = isdn_command; /* set command function */
  2073. i_div->drv_to_name = map_drvname;
  2074. i_div->name_to_drv = map_namedrv;
  2075. divert_if = i_div; /* remember interface */
  2076. return (DIVERT_NO_ERR);
  2077. default:
  2078. return (DIVERT_CMD_ERR);
  2079. }
  2080. } /* DIVERT_REG_NAME */
  2081. EXPORT_SYMBOL(DIVERT_REG_NAME);
  2082. #endif /* CONFIG_ISDN_DIVERSION */
  2083. EXPORT_SYMBOL(register_isdn);
  2084. #ifdef CONFIG_ISDN_PPP
  2085. EXPORT_SYMBOL(isdn_ppp_register_compressor);
  2086. EXPORT_SYMBOL(isdn_ppp_unregister_compressor);
  2087. #endif
  2088. int
  2089. register_isdn(isdn_if *i)
  2090. {
  2091. isdn_driver_t *d;
  2092. int j;
  2093. ulong flags;
  2094. int drvidx;
  2095. if (dev->drivers >= ISDN_MAX_DRIVERS) {
  2096. printk(KERN_WARNING "register_isdn: Max. %d drivers supported\n",
  2097. ISDN_MAX_DRIVERS);
  2098. return 0;
  2099. }
  2100. if (!i->writebuf_skb) {
  2101. printk(KERN_WARNING "register_isdn: No write routine given.\n");
  2102. return 0;
  2103. }
  2104. if (!(d = kzalloc(sizeof(isdn_driver_t), GFP_KERNEL))) {
  2105. printk(KERN_WARNING "register_isdn: Could not alloc driver-struct\n");
  2106. return 0;
  2107. }
  2108. d->maxbufsize = i->maxbufsize;
  2109. d->pktcount = 0;
  2110. d->stavail = 0;
  2111. d->flags = DRV_FLAG_LOADED;
  2112. d->online = 0;
  2113. d->interface = i;
  2114. d->channels = 0;
  2115. spin_lock_irqsave(&dev->lock, flags);
  2116. for (drvidx = 0; drvidx < ISDN_MAX_DRIVERS; drvidx++)
  2117. if (!dev->drv[drvidx])
  2118. break;
  2119. if (isdn_add_channels(d, drvidx, i->channels, 0)) {
  2120. spin_unlock_irqrestore(&dev->lock, flags);
  2121. kfree(d);
  2122. return 0;
  2123. }
  2124. i->channels = drvidx;
  2125. i->rcvcallb_skb = isdn_receive_skb_callback;
  2126. i->statcallb = isdn_status_callback;
  2127. if (!strlen(i->id))
  2128. sprintf(i->id, "line%d", drvidx);
  2129. for (j = 0; j < drvidx; j++)
  2130. if (!strcmp(i->id, dev->drvid[j]))
  2131. sprintf(i->id, "line%d", drvidx);
  2132. dev->drv[drvidx] = d;
  2133. strcpy(dev->drvid[drvidx], i->id);
  2134. isdn_info_update();
  2135. dev->drivers++;
  2136. set_global_features();
  2137. spin_unlock_irqrestore(&dev->lock, flags);
  2138. return 1;
  2139. }
  2140. /*
  2141. *****************************************************************************
  2142. * And now the modules code.
  2143. *****************************************************************************
  2144. */
  2145. static char *
  2146. isdn_getrev(const char *revision)
  2147. {
  2148. char *rev;
  2149. char *p;
  2150. if ((p = strchr(revision, ':'))) {
  2151. rev = p + 2;
  2152. p = strchr(rev, '$');
  2153. *--p = 0;
  2154. } else
  2155. rev = "???";
  2156. return rev;
  2157. }
  2158. /*
  2159. * Allocate and initialize all data, register modem-devices
  2160. */
  2161. static int __init isdn_init(void)
  2162. {
  2163. int i;
  2164. char tmprev[50];
  2165. dev = vzalloc(sizeof(isdn_dev));
  2166. if (!dev) {
  2167. printk(KERN_WARNING "isdn: Could not allocate device-struct.\n");
  2168. return -EIO;
  2169. }
  2170. init_timer(&dev->timer);
  2171. dev->timer.function = isdn_timer_funct;
  2172. spin_lock_init(&dev->lock);
  2173. spin_lock_init(&dev->timerlock);
  2174. #ifdef MODULE
  2175. dev->owner = THIS_MODULE;
  2176. #endif
  2177. mutex_init(&dev->mtx);
  2178. init_waitqueue_head(&dev->info_waitq);
  2179. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  2180. dev->drvmap[i] = -1;
  2181. dev->chanmap[i] = -1;
  2182. dev->m_idx[i] = -1;
  2183. strcpy(dev->num[i], "???");
  2184. }
  2185. if (register_chrdev(ISDN_MAJOR, "isdn", &isdn_fops)) {
  2186. printk(KERN_WARNING "isdn: Could not register control devices\n");
  2187. vfree(dev);
  2188. return -EIO;
  2189. }
  2190. if ((isdn_tty_modem_init()) < 0) {
  2191. printk(KERN_WARNING "isdn: Could not register tty devices\n");
  2192. vfree(dev);
  2193. unregister_chrdev(ISDN_MAJOR, "isdn");
  2194. return -EIO;
  2195. }
  2196. #ifdef CONFIG_ISDN_PPP
  2197. if (isdn_ppp_init() < 0) {
  2198. printk(KERN_WARNING "isdn: Could not create PPP-device-structs\n");
  2199. isdn_tty_exit();
  2200. unregister_chrdev(ISDN_MAJOR, "isdn");
  2201. vfree(dev);
  2202. return -EIO;
  2203. }
  2204. #endif /* CONFIG_ISDN_PPP */
  2205. strcpy(tmprev, isdn_revision);
  2206. printk(KERN_NOTICE "ISDN subsystem Rev: %s/", isdn_getrev(tmprev));
  2207. strcpy(tmprev, isdn_net_revision);
  2208. printk("%s/", isdn_getrev(tmprev));
  2209. strcpy(tmprev, isdn_ppp_revision);
  2210. printk("%s/", isdn_getrev(tmprev));
  2211. strcpy(tmprev, isdn_audio_revision);
  2212. printk("%s/", isdn_getrev(tmprev));
  2213. strcpy(tmprev, isdn_v110_revision);
  2214. printk("%s", isdn_getrev(tmprev));
  2215. #ifdef MODULE
  2216. printk(" loaded\n");
  2217. #else
  2218. printk("\n");
  2219. #endif
  2220. isdn_info_update();
  2221. return 0;
  2222. }
  2223. /*
  2224. * Unload module
  2225. */
  2226. static void __exit isdn_exit(void)
  2227. {
  2228. #ifdef CONFIG_ISDN_PPP
  2229. isdn_ppp_cleanup();
  2230. #endif
  2231. if (isdn_net_rmall() < 0) {
  2232. printk(KERN_WARNING "isdn: net-device busy, remove cancelled\n");
  2233. return;
  2234. }
  2235. isdn_tty_exit();
  2236. unregister_chrdev(ISDN_MAJOR, "isdn");
  2237. del_timer_sync(&dev->timer);
  2238. /* call vfree with interrupts enabled, else it will hang */
  2239. vfree(dev);
  2240. printk(KERN_NOTICE "ISDN-subsystem unloaded\n");
  2241. }
  2242. module_init(isdn_init);
  2243. module_exit(isdn_exit);