isdn_common.c 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392
  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. interruptible_sleep_on(sleep);
  732. else
  733. return 0;
  734. }
  735. if (len > dev->drv[di]->rcvcount[channel])
  736. len = dev->drv[di]->rcvcount[channel];
  737. cp = buf;
  738. count = 0;
  739. while (len) {
  740. if (!(skb = skb_peek(&dev->drv[di]->rpqueue[channel])))
  741. break;
  742. #ifdef CONFIG_ISDN_AUDIO
  743. if (ISDN_AUDIO_SKB_LOCK(skb))
  744. break;
  745. ISDN_AUDIO_SKB_LOCK(skb) = 1;
  746. if ((ISDN_AUDIO_SKB_DLECOUNT(skb)) || (dev->drv[di]->DLEflag & (1 << channel))) {
  747. char *p = skb->data;
  748. unsigned long DLEmask = (1 << channel);
  749. dflag = 0;
  750. count_pull = count_put = 0;
  751. while ((count_pull < skb->len) && (len > 0)) {
  752. len--;
  753. if (dev->drv[di]->DLEflag & DLEmask) {
  754. *cp++ = DLE;
  755. dev->drv[di]->DLEflag &= ~DLEmask;
  756. } else {
  757. *cp++ = *p;
  758. if (*p == DLE) {
  759. dev->drv[di]->DLEflag |= DLEmask;
  760. (ISDN_AUDIO_SKB_DLECOUNT(skb))--;
  761. }
  762. p++;
  763. count_pull++;
  764. }
  765. count_put++;
  766. }
  767. if (count_pull >= skb->len)
  768. dflag = 1;
  769. } else {
  770. #endif
  771. /* No DLE's in buff, so simply copy it */
  772. dflag = 1;
  773. if ((count_pull = skb->len) > len) {
  774. count_pull = len;
  775. dflag = 0;
  776. }
  777. count_put = count_pull;
  778. skb_copy_from_linear_data(skb, cp, count_put);
  779. cp += count_put;
  780. len -= count_put;
  781. #ifdef CONFIG_ISDN_AUDIO
  782. }
  783. #endif
  784. count += count_put;
  785. if (fp) {
  786. memset(fp, 0, count_put);
  787. fp += count_put;
  788. }
  789. if (dflag) {
  790. /* We got all the data in this buff.
  791. * Now we can dequeue it.
  792. */
  793. if (fp)
  794. *(fp - 1) = 0xff;
  795. #ifdef CONFIG_ISDN_AUDIO
  796. ISDN_AUDIO_SKB_LOCK(skb) = 0;
  797. #endif
  798. skb = skb_dequeue(&dev->drv[di]->rpqueue[channel]);
  799. dev_kfree_skb(skb);
  800. } else {
  801. /* Not yet emptied this buff, so it
  802. * must stay in the queue, for further calls
  803. * but we pull off the data we got until now.
  804. */
  805. skb_pull(skb, count_pull);
  806. #ifdef CONFIG_ISDN_AUDIO
  807. ISDN_AUDIO_SKB_LOCK(skb) = 0;
  808. #endif
  809. }
  810. dev->drv[di]->rcvcount[channel] -= count_put;
  811. }
  812. return count;
  813. }
  814. /*
  815. * isdn_readbchan_tty() tries to get data from the read-queue.
  816. * It MUST be called with interrupts off.
  817. *
  818. * Be aware that this is not an atomic operation when sleep != 0, even though
  819. * interrupts are turned off! Well, like that we are currently only called
  820. * on behalf of a read system call on raw device files (which are documented
  821. * to be dangerous and for debugging purpose only). The inode semaphore
  822. * takes care that this is not called for the same minor device number while
  823. * we are sleeping, but access is not serialized against simultaneous read()
  824. * from the corresponding ttyI device. Can other ugly events, like changes
  825. * of the mapping (di,ch)<->minor, happen during the sleep? --he
  826. */
  827. int
  828. isdn_readbchan_tty(int di, int channel, struct tty_struct *tty, int cisco_hack)
  829. {
  830. int count;
  831. int count_pull;
  832. int count_put;
  833. int dflag;
  834. struct sk_buff *skb;
  835. char last = 0;
  836. int len;
  837. if (!dev->drv[di])
  838. return 0;
  839. if (skb_queue_empty(&dev->drv[di]->rpqueue[channel]))
  840. return 0;
  841. len = tty_buffer_request_room(tty, dev->drv[di]->rcvcount[channel]);
  842. if (len == 0)
  843. return len;
  844. count = 0;
  845. while (len) {
  846. if (!(skb = skb_peek(&dev->drv[di]->rpqueue[channel])))
  847. break;
  848. #ifdef CONFIG_ISDN_AUDIO
  849. if (ISDN_AUDIO_SKB_LOCK(skb))
  850. break;
  851. ISDN_AUDIO_SKB_LOCK(skb) = 1;
  852. if ((ISDN_AUDIO_SKB_DLECOUNT(skb)) || (dev->drv[di]->DLEflag & (1 << channel))) {
  853. char *p = skb->data;
  854. unsigned long DLEmask = (1 << channel);
  855. dflag = 0;
  856. count_pull = count_put = 0;
  857. while ((count_pull < skb->len) && (len > 0)) {
  858. /* push every character but the last to the tty buffer directly */
  859. if (count_put)
  860. tty_insert_flip_char(tty, last, TTY_NORMAL);
  861. len--;
  862. if (dev->drv[di]->DLEflag & DLEmask) {
  863. last = DLE;
  864. dev->drv[di]->DLEflag &= ~DLEmask;
  865. } else {
  866. last = *p;
  867. if (last == DLE) {
  868. dev->drv[di]->DLEflag |= DLEmask;
  869. (ISDN_AUDIO_SKB_DLECOUNT(skb))--;
  870. }
  871. p++;
  872. count_pull++;
  873. }
  874. count_put++;
  875. }
  876. if (count_pull >= skb->len)
  877. dflag = 1;
  878. } else {
  879. #endif
  880. /* No DLE's in buff, so simply copy it */
  881. dflag = 1;
  882. if ((count_pull = skb->len) > len) {
  883. count_pull = len;
  884. dflag = 0;
  885. }
  886. count_put = count_pull;
  887. if (count_put > 1)
  888. tty_insert_flip_string(tty, skb->data, count_put - 1);
  889. last = skb->data[count_put - 1];
  890. len -= count_put;
  891. #ifdef CONFIG_ISDN_AUDIO
  892. }
  893. #endif
  894. count += count_put;
  895. if (dflag) {
  896. /* We got all the data in this buff.
  897. * Now we can dequeue it.
  898. */
  899. if (cisco_hack)
  900. tty_insert_flip_char(tty, last, 0xFF);
  901. else
  902. tty_insert_flip_char(tty, last, TTY_NORMAL);
  903. #ifdef CONFIG_ISDN_AUDIO
  904. ISDN_AUDIO_SKB_LOCK(skb) = 0;
  905. #endif
  906. skb = skb_dequeue(&dev->drv[di]->rpqueue[channel]);
  907. dev_kfree_skb(skb);
  908. } else {
  909. tty_insert_flip_char(tty, last, TTY_NORMAL);
  910. /* Not yet emptied this buff, so it
  911. * must stay in the queue, for further calls
  912. * but we pull off the data we got until now.
  913. */
  914. skb_pull(skb, count_pull);
  915. #ifdef CONFIG_ISDN_AUDIO
  916. ISDN_AUDIO_SKB_LOCK(skb) = 0;
  917. #endif
  918. }
  919. dev->drv[di]->rcvcount[channel] -= count_put;
  920. }
  921. return count;
  922. }
  923. static inline int
  924. isdn_minor2drv(int minor)
  925. {
  926. return (dev->drvmap[minor]);
  927. }
  928. static inline int
  929. isdn_minor2chan(int minor)
  930. {
  931. return (dev->chanmap[minor]);
  932. }
  933. static char *
  934. isdn_statstr(void)
  935. {
  936. static char istatbuf[2048];
  937. char *p;
  938. int i;
  939. sprintf(istatbuf, "idmap:\t");
  940. p = istatbuf + strlen(istatbuf);
  941. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  942. sprintf(p, "%s ", (dev->drvmap[i] < 0) ? "-" : dev->drvid[dev->drvmap[i]]);
  943. p = istatbuf + strlen(istatbuf);
  944. }
  945. sprintf(p, "\nchmap:\t");
  946. p = istatbuf + strlen(istatbuf);
  947. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  948. sprintf(p, "%d ", dev->chanmap[i]);
  949. p = istatbuf + strlen(istatbuf);
  950. }
  951. sprintf(p, "\ndrmap:\t");
  952. p = istatbuf + strlen(istatbuf);
  953. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  954. sprintf(p, "%d ", dev->drvmap[i]);
  955. p = istatbuf + strlen(istatbuf);
  956. }
  957. sprintf(p, "\nusage:\t");
  958. p = istatbuf + strlen(istatbuf);
  959. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  960. sprintf(p, "%d ", dev->usage[i]);
  961. p = istatbuf + strlen(istatbuf);
  962. }
  963. sprintf(p, "\nflags:\t");
  964. p = istatbuf + strlen(istatbuf);
  965. for (i = 0; i < ISDN_MAX_DRIVERS; i++) {
  966. if (dev->drv[i]) {
  967. sprintf(p, "%ld ", dev->drv[i]->online);
  968. p = istatbuf + strlen(istatbuf);
  969. } else {
  970. sprintf(p, "? ");
  971. p = istatbuf + strlen(istatbuf);
  972. }
  973. }
  974. sprintf(p, "\nphone:\t");
  975. p = istatbuf + strlen(istatbuf);
  976. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  977. sprintf(p, "%s ", dev->num[i]);
  978. p = istatbuf + strlen(istatbuf);
  979. }
  980. sprintf(p, "\n");
  981. return istatbuf;
  982. }
  983. /* Module interface-code */
  984. void
  985. isdn_info_update(void)
  986. {
  987. infostruct *p = dev->infochain;
  988. while (p) {
  989. *(p->private) = 1;
  990. p = (infostruct *) p->next;
  991. }
  992. wake_up_interruptible(&(dev->info_waitq));
  993. }
  994. static ssize_t
  995. isdn_read(struct file *file, char __user *buf, size_t count, loff_t *off)
  996. {
  997. uint minor = iminor(file->f_path.dentry->d_inode);
  998. int len = 0;
  999. int drvidx;
  1000. int chidx;
  1001. int retval;
  1002. char *p;
  1003. mutex_lock(&isdn_mutex);
  1004. if (minor == ISDN_MINOR_STATUS) {
  1005. if (!file->private_data) {
  1006. if (file->f_flags & O_NONBLOCK) {
  1007. retval = -EAGAIN;
  1008. goto out;
  1009. }
  1010. interruptible_sleep_on(&(dev->info_waitq));
  1011. }
  1012. p = isdn_statstr();
  1013. file->private_data = NULL;
  1014. if ((len = strlen(p)) <= count) {
  1015. if (copy_to_user(buf, p, len)) {
  1016. retval = -EFAULT;
  1017. goto out;
  1018. }
  1019. *off += len;
  1020. retval = len;
  1021. goto out;
  1022. }
  1023. retval = 0;
  1024. goto out;
  1025. }
  1026. if (!dev->drivers) {
  1027. retval = -ENODEV;
  1028. goto out;
  1029. }
  1030. if (minor <= ISDN_MINOR_BMAX) {
  1031. printk(KERN_WARNING "isdn_read minor %d obsolete!\n", minor);
  1032. drvidx = isdn_minor2drv(minor);
  1033. if (drvidx < 0) {
  1034. retval = -ENODEV;
  1035. goto out;
  1036. }
  1037. if (!(dev->drv[drvidx]->flags & DRV_FLAG_RUNNING)) {
  1038. retval = -ENODEV;
  1039. goto out;
  1040. }
  1041. chidx = isdn_minor2chan(minor);
  1042. if (!(p = kmalloc(count, GFP_KERNEL))) {
  1043. retval = -ENOMEM;
  1044. goto out;
  1045. }
  1046. len = isdn_readbchan(drvidx, chidx, p, NULL, count,
  1047. &dev->drv[drvidx]->rcv_waitq[chidx]);
  1048. *off += len;
  1049. if (copy_to_user(buf, p, len))
  1050. len = -EFAULT;
  1051. kfree(p);
  1052. retval = len;
  1053. goto out;
  1054. }
  1055. if (minor <= ISDN_MINOR_CTRLMAX) {
  1056. drvidx = isdn_minor2drv(minor - ISDN_MINOR_CTRL);
  1057. if (drvidx < 0) {
  1058. retval = -ENODEV;
  1059. goto out;
  1060. }
  1061. if (!dev->drv[drvidx]->stavail) {
  1062. if (file->f_flags & O_NONBLOCK) {
  1063. retval = -EAGAIN;
  1064. goto out;
  1065. }
  1066. interruptible_sleep_on(&(dev->drv[drvidx]->st_waitq));
  1067. }
  1068. if (dev->drv[drvidx]->interface->readstat) {
  1069. if (count > dev->drv[drvidx]->stavail)
  1070. count = dev->drv[drvidx]->stavail;
  1071. len = dev->drv[drvidx]->interface->readstat(buf, count,
  1072. drvidx, isdn_minor2chan(minor - ISDN_MINOR_CTRL));
  1073. if (len < 0) {
  1074. retval = len;
  1075. goto out;
  1076. }
  1077. } else {
  1078. len = 0;
  1079. }
  1080. if (len)
  1081. dev->drv[drvidx]->stavail -= len;
  1082. else
  1083. dev->drv[drvidx]->stavail = 0;
  1084. *off += len;
  1085. retval = len;
  1086. goto out;
  1087. }
  1088. #ifdef CONFIG_ISDN_PPP
  1089. if (minor <= ISDN_MINOR_PPPMAX) {
  1090. retval = isdn_ppp_read(minor - ISDN_MINOR_PPP, file, buf, count);
  1091. goto out;
  1092. }
  1093. #endif
  1094. retval = -ENODEV;
  1095. out:
  1096. mutex_unlock(&isdn_mutex);
  1097. return retval;
  1098. }
  1099. static ssize_t
  1100. isdn_write(struct file *file, const char __user *buf, size_t count, loff_t *off)
  1101. {
  1102. uint minor = iminor(file->f_path.dentry->d_inode);
  1103. int drvidx;
  1104. int chidx;
  1105. int retval;
  1106. if (minor == ISDN_MINOR_STATUS)
  1107. return -EPERM;
  1108. if (!dev->drivers)
  1109. return -ENODEV;
  1110. mutex_lock(&isdn_mutex);
  1111. if (minor <= ISDN_MINOR_BMAX) {
  1112. printk(KERN_WARNING "isdn_write minor %d obsolete!\n", minor);
  1113. drvidx = isdn_minor2drv(minor);
  1114. if (drvidx < 0) {
  1115. retval = -ENODEV;
  1116. goto out;
  1117. }
  1118. if (!(dev->drv[drvidx]->flags & DRV_FLAG_RUNNING)) {
  1119. retval = -ENODEV;
  1120. goto out;
  1121. }
  1122. chidx = isdn_minor2chan(minor);
  1123. while ((retval = isdn_writebuf_stub(drvidx, chidx, buf, count)) == 0)
  1124. interruptible_sleep_on(&dev->drv[drvidx]->snd_waitq[chidx]);
  1125. goto out;
  1126. }
  1127. if (minor <= ISDN_MINOR_CTRLMAX) {
  1128. drvidx = isdn_minor2drv(minor - ISDN_MINOR_CTRL);
  1129. if (drvidx < 0) {
  1130. retval = -ENODEV;
  1131. goto out;
  1132. }
  1133. /*
  1134. * We want to use the isdnctrl device to load the firmware
  1135. *
  1136. if (!(dev->drv[drvidx]->flags & DRV_FLAG_RUNNING))
  1137. return -ENODEV;
  1138. */
  1139. if (dev->drv[drvidx]->interface->writecmd)
  1140. retval = dev->drv[drvidx]->interface->
  1141. writecmd(buf, count, drvidx,
  1142. isdn_minor2chan(minor - ISDN_MINOR_CTRL));
  1143. else
  1144. retval = count;
  1145. goto out;
  1146. }
  1147. #ifdef CONFIG_ISDN_PPP
  1148. if (minor <= ISDN_MINOR_PPPMAX) {
  1149. retval = isdn_ppp_write(minor - ISDN_MINOR_PPP, file, buf, count);
  1150. goto out;
  1151. }
  1152. #endif
  1153. retval = -ENODEV;
  1154. out:
  1155. mutex_unlock(&isdn_mutex);
  1156. return retval;
  1157. }
  1158. static unsigned int
  1159. isdn_poll(struct file *file, poll_table *wait)
  1160. {
  1161. unsigned int mask = 0;
  1162. unsigned int minor = iminor(file->f_path.dentry->d_inode);
  1163. int drvidx = isdn_minor2drv(minor - ISDN_MINOR_CTRL);
  1164. mutex_lock(&isdn_mutex);
  1165. if (minor == ISDN_MINOR_STATUS) {
  1166. poll_wait(file, &(dev->info_waitq), wait);
  1167. /* mask = POLLOUT | POLLWRNORM; */
  1168. if (file->private_data) {
  1169. mask |= POLLIN | POLLRDNORM;
  1170. }
  1171. goto out;
  1172. }
  1173. if (minor >= ISDN_MINOR_CTRL && minor <= ISDN_MINOR_CTRLMAX) {
  1174. if (drvidx < 0) {
  1175. /* driver deregistered while file open */
  1176. mask = POLLHUP;
  1177. goto out;
  1178. }
  1179. poll_wait(file, &(dev->drv[drvidx]->st_waitq), wait);
  1180. mask = POLLOUT | POLLWRNORM;
  1181. if (dev->drv[drvidx]->stavail) {
  1182. mask |= POLLIN | POLLRDNORM;
  1183. }
  1184. goto out;
  1185. }
  1186. #ifdef CONFIG_ISDN_PPP
  1187. if (minor <= ISDN_MINOR_PPPMAX) {
  1188. mask = isdn_ppp_poll(file, wait);
  1189. goto out;
  1190. }
  1191. #endif
  1192. mask = POLLERR;
  1193. out:
  1194. mutex_unlock(&isdn_mutex);
  1195. return mask;
  1196. }
  1197. static int
  1198. isdn_ioctl(struct file *file, uint cmd, ulong arg)
  1199. {
  1200. uint minor = iminor(file->f_path.dentry->d_inode);
  1201. isdn_ctrl c;
  1202. int drvidx;
  1203. int ret;
  1204. int i;
  1205. char __user *p;
  1206. char *s;
  1207. union iocpar {
  1208. char name[10];
  1209. char bname[22];
  1210. isdn_ioctl_struct iocts;
  1211. isdn_net_ioctl_phone phone;
  1212. isdn_net_ioctl_cfg cfg;
  1213. } iocpar;
  1214. void __user *argp = (void __user *)arg;
  1215. #define name iocpar.name
  1216. #define bname iocpar.bname
  1217. #define iocts iocpar.iocts
  1218. #define phone iocpar.phone
  1219. #define cfg iocpar.cfg
  1220. if (minor == ISDN_MINOR_STATUS) {
  1221. switch (cmd) {
  1222. case IIOCGETDVR:
  1223. return (TTY_DV +
  1224. (NET_DV << 8) +
  1225. (INF_DV << 16));
  1226. case IIOCGETCPS:
  1227. if (arg) {
  1228. ulong __user *p = argp;
  1229. int i;
  1230. if (!access_ok(VERIFY_WRITE, p,
  1231. sizeof(ulong) * ISDN_MAX_CHANNELS * 2))
  1232. return -EFAULT;
  1233. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  1234. put_user(dev->ibytes[i], p++);
  1235. put_user(dev->obytes[i], p++);
  1236. }
  1237. return 0;
  1238. } else
  1239. return -EINVAL;
  1240. break;
  1241. #ifdef CONFIG_NETDEVICES
  1242. case IIOCNETGPN:
  1243. /* Get peer phone number of a connected
  1244. * isdn network interface */
  1245. if (arg) {
  1246. if (copy_from_user(&phone, argp, sizeof(phone)))
  1247. return -EFAULT;
  1248. return isdn_net_getpeer(&phone, argp);
  1249. } else
  1250. return -EINVAL;
  1251. #endif
  1252. default:
  1253. return -EINVAL;
  1254. }
  1255. }
  1256. if (!dev->drivers)
  1257. return -ENODEV;
  1258. if (minor <= ISDN_MINOR_BMAX) {
  1259. drvidx = isdn_minor2drv(minor);
  1260. if (drvidx < 0)
  1261. return -ENODEV;
  1262. if (!(dev->drv[drvidx]->flags & DRV_FLAG_RUNNING))
  1263. return -ENODEV;
  1264. return 0;
  1265. }
  1266. if (minor <= ISDN_MINOR_CTRLMAX) {
  1267. /*
  1268. * isdn net devices manage lots of configuration variables as linked lists.
  1269. * Those lists must only be manipulated from user space. Some of the ioctl's
  1270. * service routines access user space and are not atomic. Therefore, ioctl's
  1271. * manipulating the lists and ioctl's sleeping while accessing the lists
  1272. * are serialized by means of a semaphore.
  1273. */
  1274. switch (cmd) {
  1275. case IIOCNETDWRSET:
  1276. printk(KERN_INFO "INFO: ISDN_DW_ABC_EXTENSION not enabled\n");
  1277. return (-EINVAL);
  1278. case IIOCNETLCR:
  1279. printk(KERN_INFO "INFO: ISDN_ABC_LCR_SUPPORT not enabled\n");
  1280. return -ENODEV;
  1281. #ifdef CONFIG_NETDEVICES
  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. } else
  1309. return -EINVAL;
  1310. ret = mutex_lock_interruptible(&dev->mtx);
  1311. if (ret) return ret;
  1312. if ((s = isdn_net_newslave(bname))) {
  1313. if (copy_to_user(argp, s, strlen(s) + 1)) {
  1314. ret = -EFAULT;
  1315. } else {
  1316. ret = 0;
  1317. }
  1318. } else
  1319. ret = -ENODEV;
  1320. mutex_unlock(&dev->mtx);
  1321. return ret;
  1322. case IIOCNETDIF:
  1323. /* Delete a network-interface */
  1324. if (arg) {
  1325. if (copy_from_user(name, argp, sizeof(name)))
  1326. return -EFAULT;
  1327. ret = mutex_lock_interruptible(&dev->mtx);
  1328. if (ret) return ret;
  1329. ret = isdn_net_rm(name);
  1330. mutex_unlock(&dev->mtx);
  1331. return ret;
  1332. } else
  1333. return -EINVAL;
  1334. case IIOCNETSCF:
  1335. /* Set configurable parameters of a network-interface */
  1336. if (arg) {
  1337. if (copy_from_user(&cfg, argp, sizeof(cfg)))
  1338. return -EFAULT;
  1339. return isdn_net_setcfg(&cfg);
  1340. } else
  1341. return -EINVAL;
  1342. case IIOCNETGCF:
  1343. /* Get configurable parameters of a network-interface */
  1344. if (arg) {
  1345. if (copy_from_user(&cfg, argp, sizeof(cfg)))
  1346. return -EFAULT;
  1347. if (!(ret = isdn_net_getcfg(&cfg))) {
  1348. if (copy_to_user(argp, &cfg, sizeof(cfg)))
  1349. return -EFAULT;
  1350. }
  1351. return ret;
  1352. } else
  1353. return -EINVAL;
  1354. case IIOCNETANM:
  1355. /* Add a phone-number to a network-interface */
  1356. if (arg) {
  1357. if (copy_from_user(&phone, argp, sizeof(phone)))
  1358. return -EFAULT;
  1359. ret = mutex_lock_interruptible(&dev->mtx);
  1360. if (ret) return ret;
  1361. ret = isdn_net_addphone(&phone);
  1362. mutex_unlock(&dev->mtx);
  1363. return ret;
  1364. } else
  1365. return -EINVAL;
  1366. case IIOCNETGNM:
  1367. /* Get list of phone-numbers of a network-interface */
  1368. if (arg) {
  1369. if (copy_from_user(&phone, argp, sizeof(phone)))
  1370. return -EFAULT;
  1371. ret = mutex_lock_interruptible(&dev->mtx);
  1372. if (ret) return ret;
  1373. ret = isdn_net_getphones(&phone, argp);
  1374. mutex_unlock(&dev->mtx);
  1375. return ret;
  1376. } else
  1377. return -EINVAL;
  1378. case IIOCNETDNM:
  1379. /* Delete a phone-number of a network-interface */
  1380. if (arg) {
  1381. if (copy_from_user(&phone, argp, sizeof(phone)))
  1382. return -EFAULT;
  1383. ret = mutex_lock_interruptible(&dev->mtx);
  1384. if (ret) return ret;
  1385. ret = isdn_net_delphone(&phone);
  1386. mutex_unlock(&dev->mtx);
  1387. return ret;
  1388. } else
  1389. return -EINVAL;
  1390. case IIOCNETDIL:
  1391. /* Force dialing of a network-interface */
  1392. if (arg) {
  1393. if (copy_from_user(name, argp, sizeof(name)))
  1394. return -EFAULT;
  1395. return isdn_net_force_dial(name);
  1396. } else
  1397. return -EINVAL;
  1398. #ifdef CONFIG_ISDN_PPP
  1399. case IIOCNETALN:
  1400. if (!arg)
  1401. return -EINVAL;
  1402. if (copy_from_user(name, argp, sizeof(name)))
  1403. return -EFAULT;
  1404. return isdn_ppp_dial_slave(name);
  1405. case IIOCNETDLN:
  1406. if (!arg)
  1407. return -EINVAL;
  1408. if (copy_from_user(name, argp, sizeof(name)))
  1409. return -EFAULT;
  1410. return isdn_ppp_hangup_slave(name);
  1411. #endif
  1412. case IIOCNETHUP:
  1413. /* Force hangup of a network-interface */
  1414. if (!arg)
  1415. return -EINVAL;
  1416. if (copy_from_user(name, argp, sizeof(name)))
  1417. return -EFAULT;
  1418. return isdn_net_force_hangup(name);
  1419. break;
  1420. #endif /* CONFIG_NETDEVICES */
  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. if (arg) {
  1578. if (copy_to_user(argp, &dev, sizeof(ulong)))
  1579. return -EFAULT;
  1580. return 0;
  1581. } else
  1582. return -EINVAL;
  1583. break;
  1584. default:
  1585. if ((cmd & IIOCDRVCTL) == IIOCDRVCTL)
  1586. cmd = ((cmd >> _IOC_NRSHIFT) & _IOC_NRMASK) & ISDN_DRVIOCTL_MASK;
  1587. else
  1588. return -EINVAL;
  1589. if (arg) {
  1590. int i;
  1591. char *p;
  1592. if (copy_from_user(&iocts, argp, sizeof(isdn_ioctl_struct)))
  1593. return -EFAULT;
  1594. iocts.drvid[sizeof(iocts.drvid) - 1] = 0;
  1595. if (strlen(iocts.drvid)) {
  1596. if ((p = strchr(iocts.drvid, ',')))
  1597. *p = 0;
  1598. drvidx = -1;
  1599. for (i = 0; i < ISDN_MAX_DRIVERS; i++)
  1600. if (!(strcmp(dev->drvid[i], iocts.drvid))) {
  1601. drvidx = i;
  1602. break;
  1603. }
  1604. } else
  1605. drvidx = 0;
  1606. if (drvidx == -1)
  1607. return -ENODEV;
  1608. if (!access_ok(VERIFY_WRITE, argp,
  1609. sizeof(isdn_ioctl_struct)))
  1610. return -EFAULT;
  1611. c.driver = drvidx;
  1612. c.command = ISDN_CMD_IOCTL;
  1613. c.arg = cmd;
  1614. memcpy(c.parm.num, &iocts.arg, sizeof(ulong));
  1615. ret = isdn_command(&c);
  1616. memcpy(&iocts.arg, c.parm.num, sizeof(ulong));
  1617. if (copy_to_user(argp, &iocts, sizeof(isdn_ioctl_struct)))
  1618. return -EFAULT;
  1619. return ret;
  1620. } else
  1621. return -EINVAL;
  1622. }
  1623. }
  1624. #ifdef CONFIG_ISDN_PPP
  1625. if (minor <= ISDN_MINOR_PPPMAX)
  1626. return (isdn_ppp_ioctl(minor - ISDN_MINOR_PPP, file, cmd, arg));
  1627. #endif
  1628. return -ENODEV;
  1629. #undef name
  1630. #undef bname
  1631. #undef iocts
  1632. #undef phone
  1633. #undef cfg
  1634. }
  1635. static long
  1636. isdn_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  1637. {
  1638. int ret;
  1639. mutex_lock(&isdn_mutex);
  1640. ret = isdn_ioctl(file, cmd, arg);
  1641. mutex_unlock(&isdn_mutex);
  1642. return ret;
  1643. }
  1644. /*
  1645. * Open the device code.
  1646. */
  1647. static int
  1648. isdn_open(struct inode *ino, struct file *filep)
  1649. {
  1650. uint minor = iminor(ino);
  1651. int drvidx;
  1652. int chidx;
  1653. int retval = -ENODEV;
  1654. mutex_lock(&isdn_mutex);
  1655. if (minor == ISDN_MINOR_STATUS) {
  1656. infostruct *p;
  1657. if ((p = kmalloc(sizeof(infostruct), GFP_KERNEL))) {
  1658. p->next = (char *) dev->infochain;
  1659. p->private = (char *) &(filep->private_data);
  1660. dev->infochain = p;
  1661. /* At opening we allow a single update */
  1662. filep->private_data = (char *) 1;
  1663. retval = 0;
  1664. goto out;
  1665. } else {
  1666. retval = -ENOMEM;
  1667. goto out;
  1668. }
  1669. }
  1670. if (!dev->channels)
  1671. goto out;
  1672. if (minor <= ISDN_MINOR_BMAX) {
  1673. printk(KERN_WARNING "isdn_open minor %d obsolete!\n", minor);
  1674. drvidx = isdn_minor2drv(minor);
  1675. if (drvidx < 0)
  1676. goto out;
  1677. chidx = isdn_minor2chan(minor);
  1678. if (!(dev->drv[drvidx]->flags & DRV_FLAG_RUNNING))
  1679. goto out;
  1680. if (!(dev->drv[drvidx]->online & (1 << chidx)))
  1681. goto out;
  1682. isdn_lock_drivers();
  1683. retval = 0;
  1684. goto out;
  1685. }
  1686. if (minor <= ISDN_MINOR_CTRLMAX) {
  1687. drvidx = isdn_minor2drv(minor - ISDN_MINOR_CTRL);
  1688. if (drvidx < 0)
  1689. goto out;
  1690. isdn_lock_drivers();
  1691. retval = 0;
  1692. goto out;
  1693. }
  1694. #ifdef CONFIG_ISDN_PPP
  1695. if (minor <= ISDN_MINOR_PPPMAX) {
  1696. retval = isdn_ppp_open(minor - ISDN_MINOR_PPP, filep);
  1697. if (retval == 0)
  1698. isdn_lock_drivers();
  1699. goto out;
  1700. }
  1701. #endif
  1702. out:
  1703. nonseekable_open(ino, filep);
  1704. mutex_unlock(&isdn_mutex);
  1705. return retval;
  1706. }
  1707. static int
  1708. isdn_close(struct inode *ino, struct file *filep)
  1709. {
  1710. uint minor = iminor(ino);
  1711. mutex_lock(&isdn_mutex);
  1712. if (minor == ISDN_MINOR_STATUS) {
  1713. infostruct *p = dev->infochain;
  1714. infostruct *q = NULL;
  1715. while (p) {
  1716. if (p->private == (char *) &(filep->private_data)) {
  1717. if (q)
  1718. q->next = p->next;
  1719. else
  1720. dev->infochain = (infostruct *) (p->next);
  1721. kfree(p);
  1722. goto out;
  1723. }
  1724. q = p;
  1725. p = (infostruct *) (p->next);
  1726. }
  1727. printk(KERN_WARNING "isdn: No private data while closing isdnctrl\n");
  1728. goto out;
  1729. }
  1730. isdn_unlock_drivers();
  1731. if (minor <= ISDN_MINOR_BMAX)
  1732. goto out;
  1733. if (minor <= ISDN_MINOR_CTRLMAX) {
  1734. if (dev->profd == current)
  1735. dev->profd = NULL;
  1736. goto out;
  1737. }
  1738. #ifdef CONFIG_ISDN_PPP
  1739. if (minor <= ISDN_MINOR_PPPMAX)
  1740. isdn_ppp_release(minor - ISDN_MINOR_PPP, filep);
  1741. #endif
  1742. out:
  1743. mutex_unlock(&isdn_mutex);
  1744. return 0;
  1745. }
  1746. static const struct file_operations isdn_fops =
  1747. {
  1748. .owner = THIS_MODULE,
  1749. .llseek = no_llseek,
  1750. .read = isdn_read,
  1751. .write = isdn_write,
  1752. .poll = isdn_poll,
  1753. .unlocked_ioctl = isdn_unlocked_ioctl,
  1754. .open = isdn_open,
  1755. .release = isdn_close,
  1756. };
  1757. char *
  1758. isdn_map_eaz2msn(char *msn, int di)
  1759. {
  1760. isdn_driver_t *this = dev->drv[di];
  1761. int i;
  1762. if (strlen(msn) == 1) {
  1763. i = msn[0] - '0';
  1764. if ((i >= 0) && (i <= 9))
  1765. if (strlen(this->msn2eaz[i]))
  1766. return (this->msn2eaz[i]);
  1767. }
  1768. return (msn);
  1769. }
  1770. /*
  1771. * Find an unused ISDN-channel, whose feature-flags match the
  1772. * given L2- and L3-protocols.
  1773. */
  1774. #define L2V (~(ISDN_FEATURE_L2_V11096 | ISDN_FEATURE_L2_V11019 | ISDN_FEATURE_L2_V11038))
  1775. /*
  1776. * This function must be called with holding the dev->lock.
  1777. */
  1778. int
  1779. isdn_get_free_channel(int usage, int l2_proto, int l3_proto, int pre_dev
  1780. , int pre_chan, char *msn)
  1781. {
  1782. int i;
  1783. ulong features;
  1784. ulong vfeatures;
  1785. features = ((1 << l2_proto) | (0x10000 << l3_proto));
  1786. vfeatures = (((1 << l2_proto) | (0x10000 << l3_proto)) &
  1787. ~(ISDN_FEATURE_L2_V11096 | ISDN_FEATURE_L2_V11019 | ISDN_FEATURE_L2_V11038));
  1788. /* If Layer-2 protocol is V.110, accept drivers with
  1789. * transparent feature even if these don't support V.110
  1790. * because we can emulate this in linklevel.
  1791. */
  1792. for (i = 0; i < ISDN_MAX_CHANNELS; i++)
  1793. if (USG_NONE(dev->usage[i]) &&
  1794. (dev->drvmap[i] != -1)) {
  1795. int d = dev->drvmap[i];
  1796. if ((dev->usage[i] & ISDN_USAGE_EXCLUSIVE) &&
  1797. ((pre_dev != d) || (pre_chan != dev->chanmap[i])))
  1798. continue;
  1799. if (!strcmp(isdn_map_eaz2msn(msn, d), "-"))
  1800. continue;
  1801. if (dev->usage[i] & ISDN_USAGE_DISABLED)
  1802. continue; /* usage not allowed */
  1803. if (dev->drv[d]->flags & DRV_FLAG_RUNNING) {
  1804. if (((dev->drv[d]->interface->features & features) == features) ||
  1805. (((dev->drv[d]->interface->features & vfeatures) == vfeatures) &&
  1806. (dev->drv[d]->interface->features & ISDN_FEATURE_L2_TRANS))) {
  1807. if ((pre_dev < 0) || (pre_chan < 0)) {
  1808. dev->usage[i] &= ISDN_USAGE_EXCLUSIVE;
  1809. dev->usage[i] |= usage;
  1810. isdn_info_update();
  1811. return i;
  1812. } else {
  1813. if ((pre_dev == d) && (pre_chan == dev->chanmap[i])) {
  1814. dev->usage[i] &= ISDN_USAGE_EXCLUSIVE;
  1815. dev->usage[i] |= usage;
  1816. isdn_info_update();
  1817. return i;
  1818. }
  1819. }
  1820. }
  1821. }
  1822. }
  1823. return -1;
  1824. }
  1825. /*
  1826. * Set state of ISDN-channel to 'unused'
  1827. */
  1828. void
  1829. isdn_free_channel(int di, int ch, int usage)
  1830. {
  1831. int i;
  1832. if ((di < 0) || (ch < 0)) {
  1833. printk(KERN_WARNING "%s: called with invalid drv(%d) or channel(%d)\n",
  1834. __func__, di, ch);
  1835. return;
  1836. }
  1837. for (i = 0; i < ISDN_MAX_CHANNELS; i++)
  1838. if (((!usage) || ((dev->usage[i] & ISDN_USAGE_MASK) == usage)) &&
  1839. (dev->drvmap[i] == di) &&
  1840. (dev->chanmap[i] == ch)) {
  1841. dev->usage[i] &= (ISDN_USAGE_NONE | ISDN_USAGE_EXCLUSIVE);
  1842. strcpy(dev->num[i], "???");
  1843. dev->ibytes[i] = 0;
  1844. dev->obytes[i] = 0;
  1845. // 20.10.99 JIM, try to reinitialize v110 !
  1846. dev->v110emu[i] = 0;
  1847. atomic_set(&(dev->v110use[i]), 0);
  1848. isdn_v110_close(dev->v110[i]);
  1849. dev->v110[i] = NULL;
  1850. // 20.10.99 JIM, try to reinitialize v110 !
  1851. isdn_info_update();
  1852. if (dev->drv[di])
  1853. skb_queue_purge(&dev->drv[di]->rpqueue[ch]);
  1854. }
  1855. }
  1856. /*
  1857. * Cancel Exclusive-Flag for ISDN-channel
  1858. */
  1859. void
  1860. isdn_unexclusive_channel(int di, int ch)
  1861. {
  1862. int i;
  1863. for (i = 0; i < ISDN_MAX_CHANNELS; i++)
  1864. if ((dev->drvmap[i] == di) &&
  1865. (dev->chanmap[i] == ch)) {
  1866. dev->usage[i] &= ~ISDN_USAGE_EXCLUSIVE;
  1867. isdn_info_update();
  1868. return;
  1869. }
  1870. }
  1871. /*
  1872. * writebuf replacement for SKB_ABLE drivers
  1873. */
  1874. static int
  1875. isdn_writebuf_stub(int drvidx, int chan, const u_char __user *buf, int len)
  1876. {
  1877. int ret;
  1878. int hl = dev->drv[drvidx]->interface->hl_hdrlen;
  1879. struct sk_buff *skb = alloc_skb(hl + len, GFP_ATOMIC);
  1880. if (!skb)
  1881. return -ENOMEM;
  1882. skb_reserve(skb, hl);
  1883. if (copy_from_user(skb_put(skb, len), buf, len)) {
  1884. dev_kfree_skb(skb);
  1885. return -EFAULT;
  1886. }
  1887. ret = dev->drv[drvidx]->interface->writebuf_skb(drvidx, chan, 1, skb);
  1888. if (ret <= 0)
  1889. dev_kfree_skb(skb);
  1890. if (ret > 0)
  1891. dev->obytes[isdn_dc2minor(drvidx, chan)] += ret;
  1892. return ret;
  1893. }
  1894. /*
  1895. * Return: length of data on success, -ERRcode on failure.
  1896. */
  1897. int
  1898. isdn_writebuf_skb_stub(int drvidx, int chan, int ack, struct sk_buff *skb)
  1899. {
  1900. int ret;
  1901. struct sk_buff *nskb = NULL;
  1902. int v110_ret = skb->len;
  1903. int idx = isdn_dc2minor(drvidx, chan);
  1904. if (dev->v110[idx]) {
  1905. atomic_inc(&dev->v110use[idx]);
  1906. nskb = isdn_v110_encode(dev->v110[idx], skb);
  1907. atomic_dec(&dev->v110use[idx]);
  1908. if (!nskb)
  1909. return 0;
  1910. v110_ret = *((int *)nskb->data);
  1911. skb_pull(nskb, sizeof(int));
  1912. if (!nskb->len) {
  1913. dev_kfree_skb(nskb);
  1914. return v110_ret;
  1915. }
  1916. /* V.110 must always be acknowledged */
  1917. ack = 1;
  1918. ret = dev->drv[drvidx]->interface->writebuf_skb(drvidx, chan, ack, nskb);
  1919. } else {
  1920. int hl = dev->drv[drvidx]->interface->hl_hdrlen;
  1921. if (skb_headroom(skb) < hl) {
  1922. /*
  1923. * This should only occur when new HL driver with
  1924. * increased hl_hdrlen was loaded after netdevice
  1925. * was created and connected to the new driver.
  1926. *
  1927. * The V.110 branch (re-allocates on its own) does
  1928. * not need this
  1929. */
  1930. struct sk_buff *skb_tmp;
  1931. skb_tmp = skb_realloc_headroom(skb, hl);
  1932. printk(KERN_DEBUG "isdn_writebuf_skb_stub: reallocating headroom%s\n", skb_tmp ? "" : " failed");
  1933. if (!skb_tmp) return -ENOMEM; /* 0 better? */
  1934. ret = dev->drv[drvidx]->interface->writebuf_skb(drvidx, chan, ack, skb_tmp);
  1935. if (ret > 0) {
  1936. dev_kfree_skb(skb);
  1937. } else {
  1938. dev_kfree_skb(skb_tmp);
  1939. }
  1940. } else {
  1941. ret = dev->drv[drvidx]->interface->writebuf_skb(drvidx, chan, ack, skb);
  1942. }
  1943. }
  1944. if (ret > 0) {
  1945. dev->obytes[idx] += ret;
  1946. if (dev->v110[idx]) {
  1947. atomic_inc(&dev->v110use[idx]);
  1948. dev->v110[idx]->skbuser++;
  1949. atomic_dec(&dev->v110use[idx]);
  1950. /* For V.110 return unencoded data length */
  1951. ret = v110_ret;
  1952. /* if the complete frame was send we free the skb;
  1953. if not upper function will requeue the skb */
  1954. if (ret == skb->len)
  1955. dev_kfree_skb(skb);
  1956. }
  1957. } else
  1958. if (dev->v110[idx])
  1959. dev_kfree_skb(nskb);
  1960. return ret;
  1961. }
  1962. static int
  1963. isdn_add_channels(isdn_driver_t *d, int drvidx, int n, int adding)
  1964. {
  1965. int j, k, m;
  1966. init_waitqueue_head(&d->st_waitq);
  1967. if (d->flags & DRV_FLAG_RUNNING)
  1968. return -1;
  1969. if (n < 1) return 0;
  1970. m = (adding) ? d->channels + n : n;
  1971. if (dev->channels + n > ISDN_MAX_CHANNELS) {
  1972. printk(KERN_WARNING "register_isdn: Max. %d channels supported\n",
  1973. ISDN_MAX_CHANNELS);
  1974. return -1;
  1975. }
  1976. if ((adding) && (d->rcverr))
  1977. kfree(d->rcverr);
  1978. if (!(d->rcverr = kzalloc(sizeof(int) * m, GFP_ATOMIC))) {
  1979. printk(KERN_WARNING "register_isdn: Could not alloc rcverr\n");
  1980. return -1;
  1981. }
  1982. if ((adding) && (d->rcvcount))
  1983. kfree(d->rcvcount);
  1984. if (!(d->rcvcount = kzalloc(sizeof(int) * m, GFP_ATOMIC))) {
  1985. printk(KERN_WARNING "register_isdn: Could not alloc rcvcount\n");
  1986. if (!adding)
  1987. kfree(d->rcverr);
  1988. return -1;
  1989. }
  1990. if ((adding) && (d->rpqueue)) {
  1991. for (j = 0; j < d->channels; j++)
  1992. skb_queue_purge(&d->rpqueue[j]);
  1993. kfree(d->rpqueue);
  1994. }
  1995. if (!(d->rpqueue = kmalloc(sizeof(struct sk_buff_head) * m, GFP_ATOMIC))) {
  1996. printk(KERN_WARNING "register_isdn: Could not alloc rpqueue\n");
  1997. if (!adding) {
  1998. kfree(d->rcvcount);
  1999. kfree(d->rcverr);
  2000. }
  2001. return -1;
  2002. }
  2003. for (j = 0; j < m; j++) {
  2004. skb_queue_head_init(&d->rpqueue[j]);
  2005. }
  2006. if ((adding) && (d->rcv_waitq))
  2007. kfree(d->rcv_waitq);
  2008. d->rcv_waitq = kmalloc(sizeof(wait_queue_head_t) * 2 * m, GFP_ATOMIC);
  2009. if (!d->rcv_waitq) {
  2010. printk(KERN_WARNING "register_isdn: Could not alloc rcv_waitq\n");
  2011. if (!adding) {
  2012. kfree(d->rpqueue);
  2013. kfree(d->rcvcount);
  2014. kfree(d->rcverr);
  2015. }
  2016. return -1;
  2017. }
  2018. d->snd_waitq = d->rcv_waitq + m;
  2019. for (j = 0; j < m; j++) {
  2020. init_waitqueue_head(&d->rcv_waitq[j]);
  2021. init_waitqueue_head(&d->snd_waitq[j]);
  2022. }
  2023. dev->channels += n;
  2024. for (j = d->channels; j < m; j++)
  2025. for (k = 0; k < ISDN_MAX_CHANNELS; k++)
  2026. if (dev->chanmap[k] < 0) {
  2027. dev->chanmap[k] = j;
  2028. dev->drvmap[k] = drvidx;
  2029. break;
  2030. }
  2031. d->channels = m;
  2032. return 0;
  2033. }
  2034. /*
  2035. * Low-level-driver registration
  2036. */
  2037. static void
  2038. set_global_features(void)
  2039. {
  2040. int drvidx;
  2041. dev->global_features = 0;
  2042. for (drvidx = 0; drvidx < ISDN_MAX_DRIVERS; drvidx++) {
  2043. if (!dev->drv[drvidx])
  2044. continue;
  2045. if (dev->drv[drvidx]->interface)
  2046. dev->global_features |= dev->drv[drvidx]->interface->features;
  2047. }
  2048. }
  2049. #ifdef CONFIG_ISDN_DIVERSION
  2050. static char *map_drvname(int di)
  2051. {
  2052. if ((di < 0) || (di >= ISDN_MAX_DRIVERS))
  2053. return (NULL);
  2054. return (dev->drvid[di]); /* driver name */
  2055. } /* map_drvname */
  2056. static int map_namedrv(char *id)
  2057. { int i;
  2058. for (i = 0; i < ISDN_MAX_DRIVERS; i++)
  2059. { if (!strcmp(dev->drvid[i], id))
  2060. return (i);
  2061. }
  2062. return (-1);
  2063. } /* map_namedrv */
  2064. int DIVERT_REG_NAME(isdn_divert_if *i_div)
  2065. {
  2066. if (i_div->if_magic != DIVERT_IF_MAGIC)
  2067. return (DIVERT_VER_ERR);
  2068. switch (i_div->cmd)
  2069. {
  2070. case DIVERT_CMD_REL:
  2071. if (divert_if != i_div)
  2072. return (DIVERT_REL_ERR);
  2073. divert_if = NULL; /* free interface */
  2074. return (DIVERT_NO_ERR);
  2075. case DIVERT_CMD_REG:
  2076. if (divert_if)
  2077. return (DIVERT_REG_ERR);
  2078. i_div->ll_cmd = isdn_command; /* set command function */
  2079. i_div->drv_to_name = map_drvname;
  2080. i_div->name_to_drv = map_namedrv;
  2081. divert_if = i_div; /* remember interface */
  2082. return (DIVERT_NO_ERR);
  2083. default:
  2084. return (DIVERT_CMD_ERR);
  2085. }
  2086. } /* DIVERT_REG_NAME */
  2087. EXPORT_SYMBOL(DIVERT_REG_NAME);
  2088. #endif /* CONFIG_ISDN_DIVERSION */
  2089. EXPORT_SYMBOL(register_isdn);
  2090. #ifdef CONFIG_ISDN_PPP
  2091. EXPORT_SYMBOL(isdn_ppp_register_compressor);
  2092. EXPORT_SYMBOL(isdn_ppp_unregister_compressor);
  2093. #endif
  2094. int
  2095. register_isdn(isdn_if *i)
  2096. {
  2097. isdn_driver_t *d;
  2098. int j;
  2099. ulong flags;
  2100. int drvidx;
  2101. if (dev->drivers >= ISDN_MAX_DRIVERS) {
  2102. printk(KERN_WARNING "register_isdn: Max. %d drivers supported\n",
  2103. ISDN_MAX_DRIVERS);
  2104. return 0;
  2105. }
  2106. if (!i->writebuf_skb) {
  2107. printk(KERN_WARNING "register_isdn: No write routine given.\n");
  2108. return 0;
  2109. }
  2110. if (!(d = kzalloc(sizeof(isdn_driver_t), GFP_KERNEL))) {
  2111. printk(KERN_WARNING "register_isdn: Could not alloc driver-struct\n");
  2112. return 0;
  2113. }
  2114. d->maxbufsize = i->maxbufsize;
  2115. d->pktcount = 0;
  2116. d->stavail = 0;
  2117. d->flags = DRV_FLAG_LOADED;
  2118. d->online = 0;
  2119. d->interface = i;
  2120. d->channels = 0;
  2121. spin_lock_irqsave(&dev->lock, flags);
  2122. for (drvidx = 0; drvidx < ISDN_MAX_DRIVERS; drvidx++)
  2123. if (!dev->drv[drvidx])
  2124. break;
  2125. if (isdn_add_channels(d, drvidx, i->channels, 0)) {
  2126. spin_unlock_irqrestore(&dev->lock, flags);
  2127. kfree(d);
  2128. return 0;
  2129. }
  2130. i->channels = drvidx;
  2131. i->rcvcallb_skb = isdn_receive_skb_callback;
  2132. i->statcallb = isdn_status_callback;
  2133. if (!strlen(i->id))
  2134. sprintf(i->id, "line%d", drvidx);
  2135. for (j = 0; j < drvidx; j++)
  2136. if (!strcmp(i->id, dev->drvid[j]))
  2137. sprintf(i->id, "line%d", drvidx);
  2138. dev->drv[drvidx] = d;
  2139. strcpy(dev->drvid[drvidx], i->id);
  2140. isdn_info_update();
  2141. dev->drivers++;
  2142. set_global_features();
  2143. spin_unlock_irqrestore(&dev->lock, flags);
  2144. return 1;
  2145. }
  2146. /*
  2147. *****************************************************************************
  2148. * And now the modules code.
  2149. *****************************************************************************
  2150. */
  2151. static char *
  2152. isdn_getrev(const char *revision)
  2153. {
  2154. char *rev;
  2155. char *p;
  2156. if ((p = strchr(revision, ':'))) {
  2157. rev = p + 2;
  2158. p = strchr(rev, '$');
  2159. *--p = 0;
  2160. } else
  2161. rev = "???";
  2162. return rev;
  2163. }
  2164. /*
  2165. * Allocate and initialize all data, register modem-devices
  2166. */
  2167. static int __init isdn_init(void)
  2168. {
  2169. int i;
  2170. char tmprev[50];
  2171. dev = vzalloc(sizeof(isdn_dev));
  2172. if (!dev) {
  2173. printk(KERN_WARNING "isdn: Could not allocate device-struct.\n");
  2174. return -EIO;
  2175. }
  2176. init_timer(&dev->timer);
  2177. dev->timer.function = isdn_timer_funct;
  2178. spin_lock_init(&dev->lock);
  2179. spin_lock_init(&dev->timerlock);
  2180. #ifdef MODULE
  2181. dev->owner = THIS_MODULE;
  2182. #endif
  2183. mutex_init(&dev->mtx);
  2184. init_waitqueue_head(&dev->info_waitq);
  2185. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  2186. dev->drvmap[i] = -1;
  2187. dev->chanmap[i] = -1;
  2188. dev->m_idx[i] = -1;
  2189. strcpy(dev->num[i], "???");
  2190. }
  2191. if (register_chrdev(ISDN_MAJOR, "isdn", &isdn_fops)) {
  2192. printk(KERN_WARNING "isdn: Could not register control devices\n");
  2193. vfree(dev);
  2194. return -EIO;
  2195. }
  2196. if ((isdn_tty_modem_init()) < 0) {
  2197. printk(KERN_WARNING "isdn: Could not register tty devices\n");
  2198. vfree(dev);
  2199. unregister_chrdev(ISDN_MAJOR, "isdn");
  2200. return -EIO;
  2201. }
  2202. #ifdef CONFIG_ISDN_PPP
  2203. if (isdn_ppp_init() < 0) {
  2204. printk(KERN_WARNING "isdn: Could not create PPP-device-structs\n");
  2205. isdn_tty_exit();
  2206. unregister_chrdev(ISDN_MAJOR, "isdn");
  2207. vfree(dev);
  2208. return -EIO;
  2209. }
  2210. #endif /* CONFIG_ISDN_PPP */
  2211. strcpy(tmprev, isdn_revision);
  2212. printk(KERN_NOTICE "ISDN subsystem Rev: %s/", isdn_getrev(tmprev));
  2213. strcpy(tmprev, isdn_net_revision);
  2214. printk("%s/", isdn_getrev(tmprev));
  2215. strcpy(tmprev, isdn_ppp_revision);
  2216. printk("%s/", isdn_getrev(tmprev));
  2217. strcpy(tmprev, isdn_audio_revision);
  2218. printk("%s/", isdn_getrev(tmprev));
  2219. strcpy(tmprev, isdn_v110_revision);
  2220. printk("%s", isdn_getrev(tmprev));
  2221. #ifdef MODULE
  2222. printk(" loaded\n");
  2223. #else
  2224. printk("\n");
  2225. #endif
  2226. isdn_info_update();
  2227. return 0;
  2228. }
  2229. /*
  2230. * Unload module
  2231. */
  2232. static void __exit isdn_exit(void)
  2233. {
  2234. #ifdef CONFIG_ISDN_PPP
  2235. isdn_ppp_cleanup();
  2236. #endif
  2237. if (isdn_net_rmall() < 0) {
  2238. printk(KERN_WARNING "isdn: net-device busy, remove cancelled\n");
  2239. return;
  2240. }
  2241. isdn_tty_exit();
  2242. unregister_chrdev(ISDN_MAJOR, "isdn");
  2243. del_timer(&dev->timer);
  2244. /* call vfree with interrupts enabled, else it will hang */
  2245. vfree(dev);
  2246. printk(KERN_NOTICE "ISDN-subsystem unloaded\n");
  2247. }
  2248. module_init(isdn_init);
  2249. module_exit(isdn_exit);