isdn_common.c 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391
  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/smp_lock.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 char *isdn_revision = "$Revision: 1.1.2.3 $";
  41. extern char *isdn_net_revision;
  42. extern char *isdn_tty_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. int di;
  362. int ch;
  363. di = (cm->adr.Controller & 0x7f) -1;
  364. ch = isdn_dc2minor(di, (cm->adr.Controller>>8)& 0x7f);
  365. switch(cm->Command) {
  366. case CAPI_FACILITY:
  367. /* in the moment only handled in tty */
  368. return(isdn_tty_capi_facility(cm));
  369. default:
  370. return(-1);
  371. }
  372. }
  373. static int
  374. isdn_status_callback(isdn_ctrl * c)
  375. {
  376. int di;
  377. u_long flags;
  378. int i;
  379. int r;
  380. int retval = 0;
  381. isdn_ctrl cmd;
  382. isdn_net_dev *p;
  383. di = c->driver;
  384. i = isdn_dc2minor(di, c->arg);
  385. switch (c->command) {
  386. case ISDN_STAT_BSENT:
  387. if (i < 0)
  388. return -1;
  389. if (dev->global_flags & ISDN_GLOBAL_STOPPED)
  390. return 0;
  391. if (isdn_net_stat_callback(i, c))
  392. return 0;
  393. if (isdn_v110_stat_callback(i, c))
  394. return 0;
  395. if (isdn_tty_stat_callback(i, c))
  396. return 0;
  397. wake_up_interruptible(&dev->drv[di]->snd_waitq[c->arg]);
  398. break;
  399. case ISDN_STAT_STAVAIL:
  400. dev->drv[di]->stavail += c->arg;
  401. wake_up_interruptible(&dev->drv[di]->st_waitq);
  402. break;
  403. case ISDN_STAT_RUN:
  404. dev->drv[di]->flags |= DRV_FLAG_RUNNING;
  405. for (i = 0; i < ISDN_MAX_CHANNELS; i++)
  406. if (dev->drvmap[i] == di)
  407. isdn_all_eaz(di, dev->chanmap[i]);
  408. set_global_features();
  409. break;
  410. case ISDN_STAT_STOP:
  411. dev->drv[di]->flags &= ~DRV_FLAG_RUNNING;
  412. break;
  413. case ISDN_STAT_ICALL:
  414. if (i < 0)
  415. return -1;
  416. #ifdef ISDN_DEBUG_STATCALLB
  417. printk(KERN_DEBUG "ICALL (net): %d %ld %s\n", di, c->arg, c->parm.num);
  418. #endif
  419. if (dev->global_flags & ISDN_GLOBAL_STOPPED) {
  420. cmd.driver = di;
  421. cmd.arg = c->arg;
  422. cmd.command = ISDN_CMD_HANGUP;
  423. isdn_command(&cmd);
  424. return 0;
  425. }
  426. /* Try to find a network-interface which will accept incoming call */
  427. r = ((c->command == ISDN_STAT_ICALLW) ? 0 : isdn_net_find_icall(di, c->arg, i, &c->parm.setup));
  428. switch (r) {
  429. case 0:
  430. /* No network-device replies.
  431. * Try ttyI's.
  432. * These return 0 on no match, 1 on match and
  433. * 3 on eventually match, if CID is longer.
  434. */
  435. if (c->command == ISDN_STAT_ICALL)
  436. if ((retval = isdn_tty_find_icall(di, c->arg, &c->parm.setup))) return(retval);
  437. #ifdef CONFIG_ISDN_DIVERSION
  438. if (divert_if)
  439. if ((retval = divert_if->stat_callback(c)))
  440. return(retval); /* processed */
  441. #endif /* CONFIG_ISDN_DIVERSION */
  442. if ((!retval) && (dev->drv[di]->flags & DRV_FLAG_REJBUS)) {
  443. /* No tty responding */
  444. cmd.driver = di;
  445. cmd.arg = c->arg;
  446. cmd.command = ISDN_CMD_HANGUP;
  447. isdn_command(&cmd);
  448. retval = 2;
  449. }
  450. break;
  451. case 1:
  452. /* Schedule connection-setup */
  453. isdn_net_dial();
  454. cmd.driver = di;
  455. cmd.arg = c->arg;
  456. cmd.command = ISDN_CMD_ACCEPTD;
  457. for ( p = dev->netdev; p; p = p->next )
  458. if ( p->local->isdn_channel == cmd.arg )
  459. {
  460. strcpy( cmd.parm.setup.eazmsn, p->local->msn );
  461. isdn_command(&cmd);
  462. retval = 1;
  463. break;
  464. }
  465. break;
  466. case 2: /* For calling back, first reject incoming call ... */
  467. case 3: /* Interface found, but down, reject call actively */
  468. retval = 2;
  469. printk(KERN_INFO "isdn: Rejecting Call\n");
  470. cmd.driver = di;
  471. cmd.arg = c->arg;
  472. cmd.command = ISDN_CMD_HANGUP;
  473. isdn_command(&cmd);
  474. if (r == 3)
  475. break;
  476. /* Fall through */
  477. case 4:
  478. /* ... then start callback. */
  479. isdn_net_dial();
  480. break;
  481. case 5:
  482. /* Number would eventually match, if longer */
  483. retval = 3;
  484. break;
  485. }
  486. #ifdef ISDN_DEBUG_STATCALLB
  487. printk(KERN_DEBUG "ICALL: ret=%d\n", retval);
  488. #endif
  489. return retval;
  490. break;
  491. case ISDN_STAT_CINF:
  492. if (i < 0)
  493. return -1;
  494. #ifdef ISDN_DEBUG_STATCALLB
  495. printk(KERN_DEBUG "CINF: %ld %s\n", c->arg, c->parm.num);
  496. #endif
  497. if (dev->global_flags & ISDN_GLOBAL_STOPPED)
  498. return 0;
  499. if (strcmp(c->parm.num, "0"))
  500. isdn_net_stat_callback(i, c);
  501. isdn_tty_stat_callback(i, c);
  502. break;
  503. case ISDN_STAT_CAUSE:
  504. #ifdef ISDN_DEBUG_STATCALLB
  505. printk(KERN_DEBUG "CAUSE: %ld %s\n", c->arg, c->parm.num);
  506. #endif
  507. printk(KERN_INFO "isdn: %s,ch%ld cause: %s\n",
  508. dev->drvid[di], c->arg, c->parm.num);
  509. isdn_tty_stat_callback(i, c);
  510. #ifdef CONFIG_ISDN_DIVERSION
  511. if (divert_if)
  512. divert_if->stat_callback(c);
  513. #endif /* CONFIG_ISDN_DIVERSION */
  514. break;
  515. case ISDN_STAT_DISPLAY:
  516. #ifdef ISDN_DEBUG_STATCALLB
  517. printk(KERN_DEBUG "DISPLAY: %ld %s\n", c->arg, c->parm.display);
  518. #endif
  519. isdn_tty_stat_callback(i, c);
  520. #ifdef CONFIG_ISDN_DIVERSION
  521. if (divert_if)
  522. divert_if->stat_callback(c);
  523. #endif /* CONFIG_ISDN_DIVERSION */
  524. break;
  525. case ISDN_STAT_DCONN:
  526. if (i < 0)
  527. return -1;
  528. #ifdef ISDN_DEBUG_STATCALLB
  529. printk(KERN_DEBUG "DCONN: %ld\n", c->arg);
  530. #endif
  531. if (dev->global_flags & ISDN_GLOBAL_STOPPED)
  532. return 0;
  533. /* Find any net-device, waiting for D-channel setup */
  534. if (isdn_net_stat_callback(i, c))
  535. break;
  536. isdn_v110_stat_callback(i, c);
  537. /* Find any ttyI, waiting for D-channel setup */
  538. if (isdn_tty_stat_callback(i, c)) {
  539. cmd.driver = di;
  540. cmd.arg = c->arg;
  541. cmd.command = ISDN_CMD_ACCEPTB;
  542. isdn_command(&cmd);
  543. break;
  544. }
  545. break;
  546. case ISDN_STAT_DHUP:
  547. if (i < 0)
  548. return -1;
  549. #ifdef ISDN_DEBUG_STATCALLB
  550. printk(KERN_DEBUG "DHUP: %ld\n", c->arg);
  551. #endif
  552. if (dev->global_flags & ISDN_GLOBAL_STOPPED)
  553. return 0;
  554. dev->drv[di]->online &= ~(1 << (c->arg));
  555. isdn_info_update();
  556. /* Signal hangup to network-devices */
  557. if (isdn_net_stat_callback(i, c))
  558. break;
  559. isdn_v110_stat_callback(i, c);
  560. if (isdn_tty_stat_callback(i, c))
  561. break;
  562. #ifdef CONFIG_ISDN_DIVERSION
  563. if (divert_if)
  564. divert_if->stat_callback(c);
  565. #endif /* CONFIG_ISDN_DIVERSION */
  566. break;
  567. break;
  568. case ISDN_STAT_BCONN:
  569. if (i < 0)
  570. return -1;
  571. #ifdef ISDN_DEBUG_STATCALLB
  572. printk(KERN_DEBUG "BCONN: %ld\n", c->arg);
  573. #endif
  574. /* Signal B-channel-connect to network-devices */
  575. if (dev->global_flags & ISDN_GLOBAL_STOPPED)
  576. return 0;
  577. dev->drv[di]->online |= (1 << (c->arg));
  578. isdn_info_update();
  579. if (isdn_net_stat_callback(i, c))
  580. break;
  581. isdn_v110_stat_callback(i, c);
  582. if (isdn_tty_stat_callback(i, c))
  583. break;
  584. break;
  585. case ISDN_STAT_BHUP:
  586. if (i < 0)
  587. return -1;
  588. #ifdef ISDN_DEBUG_STATCALLB
  589. printk(KERN_DEBUG "BHUP: %ld\n", c->arg);
  590. #endif
  591. if (dev->global_flags & ISDN_GLOBAL_STOPPED)
  592. return 0;
  593. dev->drv[di]->online &= ~(1 << (c->arg));
  594. isdn_info_update();
  595. #ifdef CONFIG_ISDN_X25
  596. /* Signal hangup to network-devices */
  597. if (isdn_net_stat_callback(i, c))
  598. break;
  599. #endif
  600. isdn_v110_stat_callback(i, c);
  601. if (isdn_tty_stat_callback(i, c))
  602. break;
  603. break;
  604. case ISDN_STAT_NODCH:
  605. if (i < 0)
  606. return -1;
  607. #ifdef ISDN_DEBUG_STATCALLB
  608. printk(KERN_DEBUG "NODCH: %ld\n", c->arg);
  609. #endif
  610. if (dev->global_flags & ISDN_GLOBAL_STOPPED)
  611. return 0;
  612. if (isdn_net_stat_callback(i, c))
  613. break;
  614. if (isdn_tty_stat_callback(i, c))
  615. break;
  616. break;
  617. case ISDN_STAT_ADDCH:
  618. spin_lock_irqsave(&dev->lock, flags);
  619. if (isdn_add_channels(dev->drv[di], di, c->arg, 1)) {
  620. spin_unlock_irqrestore(&dev->lock, flags);
  621. return -1;
  622. }
  623. spin_unlock_irqrestore(&dev->lock, flags);
  624. isdn_info_update();
  625. break;
  626. case ISDN_STAT_DISCH:
  627. spin_lock_irqsave(&dev->lock, flags);
  628. for (i = 0; i < ISDN_MAX_CHANNELS; i++)
  629. if ((dev->drvmap[i] == di) &&
  630. (dev->chanmap[i] == c->arg)) {
  631. if (c->parm.num[0])
  632. dev->usage[i] &= ~ISDN_USAGE_DISABLED;
  633. else
  634. if (USG_NONE(dev->usage[i])) {
  635. dev->usage[i] |= ISDN_USAGE_DISABLED;
  636. }
  637. else
  638. retval = -1;
  639. break;
  640. }
  641. spin_unlock_irqrestore(&dev->lock, flags);
  642. isdn_info_update();
  643. break;
  644. case ISDN_STAT_UNLOAD:
  645. while (dev->drv[di]->locks > 0) {
  646. isdn_unlock_driver(dev->drv[di]);
  647. }
  648. spin_lock_irqsave(&dev->lock, flags);
  649. isdn_tty_stat_callback(i, c);
  650. for (i = 0; i < ISDN_MAX_CHANNELS; i++)
  651. if (dev->drvmap[i] == di) {
  652. dev->drvmap[i] = -1;
  653. dev->chanmap[i] = -1;
  654. dev->usage[i] &= ~ISDN_USAGE_DISABLED;
  655. }
  656. dev->drivers--;
  657. dev->channels -= dev->drv[di]->channels;
  658. kfree(dev->drv[di]->rcverr);
  659. kfree(dev->drv[di]->rcvcount);
  660. for (i = 0; i < dev->drv[di]->channels; i++)
  661. skb_queue_purge(&dev->drv[di]->rpqueue[i]);
  662. kfree(dev->drv[di]->rpqueue);
  663. kfree(dev->drv[di]->rcv_waitq);
  664. kfree(dev->drv[di]);
  665. dev->drv[di] = NULL;
  666. dev->drvid[di][0] = '\0';
  667. isdn_info_update();
  668. set_global_features();
  669. spin_unlock_irqrestore(&dev->lock, flags);
  670. return 0;
  671. case ISDN_STAT_L1ERR:
  672. break;
  673. case CAPI_PUT_MESSAGE:
  674. return(isdn_capi_rec_hl_msg(&c->parm.cmsg));
  675. #ifdef CONFIG_ISDN_TTY_FAX
  676. case ISDN_STAT_FAXIND:
  677. isdn_tty_stat_callback(i, c);
  678. break;
  679. #endif
  680. #ifdef CONFIG_ISDN_AUDIO
  681. case ISDN_STAT_AUDIO:
  682. isdn_tty_stat_callback(i, c);
  683. break;
  684. #endif
  685. #ifdef CONFIG_ISDN_DIVERSION
  686. case ISDN_STAT_PROT:
  687. case ISDN_STAT_REDIR:
  688. if (divert_if)
  689. return(divert_if->stat_callback(c));
  690. #endif /* CONFIG_ISDN_DIVERSION */
  691. default:
  692. return -1;
  693. }
  694. return 0;
  695. }
  696. /*
  697. * Get integer from char-pointer, set pointer to end of number
  698. */
  699. int
  700. isdn_getnum(char **p)
  701. {
  702. int v = -1;
  703. while (*p[0] >= '0' && *p[0] <= '9')
  704. v = ((v < 0) ? 0 : (v * 10)) + (int) ((*p[0]++) - '0');
  705. return v;
  706. }
  707. #define DLE 0x10
  708. /*
  709. * isdn_readbchan() tries to get data from the read-queue.
  710. * It MUST be called with interrupts off.
  711. *
  712. * Be aware that this is not an atomic operation when sleep != 0, even though
  713. * interrupts are turned off! Well, like that we are currently only called
  714. * on behalf of a read system call on raw device files (which are documented
  715. * to be dangerous and for debugging purpose only). The inode semaphore
  716. * takes care that this is not called for the same minor device number while
  717. * we are sleeping, but access is not serialized against simultaneous read()
  718. * from the corresponding ttyI device. Can other ugly events, like changes
  719. * of the mapping (di,ch)<->minor, happen during the sleep? --he
  720. */
  721. int
  722. isdn_readbchan(int di, int channel, u_char * buf, u_char * fp, int len, wait_queue_head_t *sleep)
  723. {
  724. int count;
  725. int count_pull;
  726. int count_put;
  727. int dflag;
  728. struct sk_buff *skb;
  729. u_char *cp;
  730. if (!dev->drv[di])
  731. return 0;
  732. if (skb_queue_empty(&dev->drv[di]->rpqueue[channel])) {
  733. if (sleep)
  734. interruptible_sleep_on(sleep);
  735. else
  736. return 0;
  737. }
  738. if (len > dev->drv[di]->rcvcount[channel])
  739. len = dev->drv[di]->rcvcount[channel];
  740. cp = buf;
  741. count = 0;
  742. while (len) {
  743. if (!(skb = skb_peek(&dev->drv[di]->rpqueue[channel])))
  744. break;
  745. #ifdef CONFIG_ISDN_AUDIO
  746. if (ISDN_AUDIO_SKB_LOCK(skb))
  747. break;
  748. ISDN_AUDIO_SKB_LOCK(skb) = 1;
  749. if ((ISDN_AUDIO_SKB_DLECOUNT(skb)) || (dev->drv[di]->DLEflag & (1 << channel))) {
  750. char *p = skb->data;
  751. unsigned long DLEmask = (1 << channel);
  752. dflag = 0;
  753. count_pull = count_put = 0;
  754. while ((count_pull < skb->len) && (len > 0)) {
  755. len--;
  756. if (dev->drv[di]->DLEflag & DLEmask) {
  757. *cp++ = DLE;
  758. dev->drv[di]->DLEflag &= ~DLEmask;
  759. } else {
  760. *cp++ = *p;
  761. if (*p == DLE) {
  762. dev->drv[di]->DLEflag |= DLEmask;
  763. (ISDN_AUDIO_SKB_DLECOUNT(skb))--;
  764. }
  765. p++;
  766. count_pull++;
  767. }
  768. count_put++;
  769. }
  770. if (count_pull >= skb->len)
  771. dflag = 1;
  772. } else {
  773. #endif
  774. /* No DLE's in buff, so simply copy it */
  775. dflag = 1;
  776. if ((count_pull = skb->len) > len) {
  777. count_pull = len;
  778. dflag = 0;
  779. }
  780. count_put = count_pull;
  781. skb_copy_from_linear_data(skb, cp, count_put);
  782. cp += count_put;
  783. len -= count_put;
  784. #ifdef CONFIG_ISDN_AUDIO
  785. }
  786. #endif
  787. count += count_put;
  788. if (fp) {
  789. memset(fp, 0, count_put);
  790. fp += count_put;
  791. }
  792. if (dflag) {
  793. /* We got all the data in this buff.
  794. * Now we can dequeue it.
  795. */
  796. if (fp)
  797. *(fp - 1) = 0xff;
  798. #ifdef CONFIG_ISDN_AUDIO
  799. ISDN_AUDIO_SKB_LOCK(skb) = 0;
  800. #endif
  801. skb = skb_dequeue(&dev->drv[di]->rpqueue[channel]);
  802. dev_kfree_skb(skb);
  803. } else {
  804. /* Not yet emptied this buff, so it
  805. * must stay in the queue, for further calls
  806. * but we pull off the data we got until now.
  807. */
  808. skb_pull(skb, count_pull);
  809. #ifdef CONFIG_ISDN_AUDIO
  810. ISDN_AUDIO_SKB_LOCK(skb) = 0;
  811. #endif
  812. }
  813. dev->drv[di]->rcvcount[channel] -= count_put;
  814. }
  815. return count;
  816. }
  817. /*
  818. * isdn_readbchan_tty() tries to get data from the read-queue.
  819. * It MUST be called with interrupts off.
  820. *
  821. * Be aware that this is not an atomic operation when sleep != 0, even though
  822. * interrupts are turned off! Well, like that we are currently only called
  823. * on behalf of a read system call on raw device files (which are documented
  824. * to be dangerous and for debugging purpose only). The inode semaphore
  825. * takes care that this is not called for the same minor device number while
  826. * we are sleeping, but access is not serialized against simultaneous read()
  827. * from the corresponding ttyI device. Can other ugly events, like changes
  828. * of the mapping (di,ch)<->minor, happen during the sleep? --he
  829. */
  830. int
  831. isdn_readbchan_tty(int di, int channel, struct tty_struct *tty, int cisco_hack)
  832. {
  833. int count;
  834. int count_pull;
  835. int count_put;
  836. int dflag;
  837. struct sk_buff *skb;
  838. char last = 0;
  839. int len;
  840. if (!dev->drv[di])
  841. return 0;
  842. if (skb_queue_empty(&dev->drv[di]->rpqueue[channel]))
  843. return 0;
  844. len = tty_buffer_request_room(tty, dev->drv[di]->rcvcount[channel]);
  845. if(len == 0)
  846. return len;
  847. count = 0;
  848. while (len) {
  849. if (!(skb = skb_peek(&dev->drv[di]->rpqueue[channel])))
  850. break;
  851. #ifdef CONFIG_ISDN_AUDIO
  852. if (ISDN_AUDIO_SKB_LOCK(skb))
  853. break;
  854. ISDN_AUDIO_SKB_LOCK(skb) = 1;
  855. if ((ISDN_AUDIO_SKB_DLECOUNT(skb)) || (dev->drv[di]->DLEflag & (1 << channel))) {
  856. char *p = skb->data;
  857. unsigned long DLEmask = (1 << channel);
  858. dflag = 0;
  859. count_pull = count_put = 0;
  860. while ((count_pull < skb->len) && (len > 0)) {
  861. /* push every character but the last to the tty buffer directly */
  862. if ( count_put )
  863. tty_insert_flip_char(tty, last, TTY_NORMAL);
  864. len--;
  865. if (dev->drv[di]->DLEflag & DLEmask) {
  866. last = DLE;
  867. dev->drv[di]->DLEflag &= ~DLEmask;
  868. } else {
  869. last = *p;
  870. if (last == DLE) {
  871. dev->drv[di]->DLEflag |= DLEmask;
  872. (ISDN_AUDIO_SKB_DLECOUNT(skb))--;
  873. }
  874. p++;
  875. count_pull++;
  876. }
  877. count_put++;
  878. }
  879. if (count_pull >= skb->len)
  880. dflag = 1;
  881. } else {
  882. #endif
  883. /* No DLE's in buff, so simply copy it */
  884. dflag = 1;
  885. if ((count_pull = skb->len) > len) {
  886. count_pull = len;
  887. dflag = 0;
  888. }
  889. count_put = count_pull;
  890. if(count_put > 1)
  891. tty_insert_flip_string(tty, skb->data, count_put - 1);
  892. last = skb->data[count_put - 1];
  893. len -= count_put;
  894. #ifdef CONFIG_ISDN_AUDIO
  895. }
  896. #endif
  897. count += count_put;
  898. if (dflag) {
  899. /* We got all the data in this buff.
  900. * Now we can dequeue it.
  901. */
  902. if(cisco_hack)
  903. tty_insert_flip_char(tty, last, 0xFF);
  904. else
  905. tty_insert_flip_char(tty, last, TTY_NORMAL);
  906. #ifdef CONFIG_ISDN_AUDIO
  907. ISDN_AUDIO_SKB_LOCK(skb) = 0;
  908. #endif
  909. skb = skb_dequeue(&dev->drv[di]->rpqueue[channel]);
  910. dev_kfree_skb(skb);
  911. } else {
  912. tty_insert_flip_char(tty, last, TTY_NORMAL);
  913. /* Not yet emptied this buff, so it
  914. * must stay in the queue, for further calls
  915. * but we pull off the data we got until now.
  916. */
  917. skb_pull(skb, count_pull);
  918. #ifdef CONFIG_ISDN_AUDIO
  919. ISDN_AUDIO_SKB_LOCK(skb) = 0;
  920. #endif
  921. }
  922. dev->drv[di]->rcvcount[channel] -= count_put;
  923. }
  924. return count;
  925. }
  926. static inline int
  927. isdn_minor2drv(int minor)
  928. {
  929. return (dev->drvmap[minor]);
  930. }
  931. static inline int
  932. isdn_minor2chan(int minor)
  933. {
  934. return (dev->chanmap[minor]);
  935. }
  936. static char *
  937. isdn_statstr(void)
  938. {
  939. static char istatbuf[2048];
  940. char *p;
  941. int i;
  942. sprintf(istatbuf, "idmap:\t");
  943. p = istatbuf + strlen(istatbuf);
  944. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  945. sprintf(p, "%s ", (dev->drvmap[i] < 0) ? "-" : dev->drvid[dev->drvmap[i]]);
  946. p = istatbuf + strlen(istatbuf);
  947. }
  948. sprintf(p, "\nchmap:\t");
  949. p = istatbuf + strlen(istatbuf);
  950. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  951. sprintf(p, "%d ", dev->chanmap[i]);
  952. p = istatbuf + strlen(istatbuf);
  953. }
  954. sprintf(p, "\ndrmap:\t");
  955. p = istatbuf + strlen(istatbuf);
  956. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  957. sprintf(p, "%d ", dev->drvmap[i]);
  958. p = istatbuf + strlen(istatbuf);
  959. }
  960. sprintf(p, "\nusage:\t");
  961. p = istatbuf + strlen(istatbuf);
  962. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  963. sprintf(p, "%d ", dev->usage[i]);
  964. p = istatbuf + strlen(istatbuf);
  965. }
  966. sprintf(p, "\nflags:\t");
  967. p = istatbuf + strlen(istatbuf);
  968. for (i = 0; i < ISDN_MAX_DRIVERS; i++) {
  969. if (dev->drv[i]) {
  970. sprintf(p, "%ld ", dev->drv[i]->online);
  971. p = istatbuf + strlen(istatbuf);
  972. } else {
  973. sprintf(p, "? ");
  974. p = istatbuf + strlen(istatbuf);
  975. }
  976. }
  977. sprintf(p, "\nphone:\t");
  978. p = istatbuf + strlen(istatbuf);
  979. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  980. sprintf(p, "%s ", dev->num[i]);
  981. p = istatbuf + strlen(istatbuf);
  982. }
  983. sprintf(p, "\n");
  984. return istatbuf;
  985. }
  986. /* Module interface-code */
  987. void
  988. isdn_info_update(void)
  989. {
  990. infostruct *p = dev->infochain;
  991. while (p) {
  992. *(p->private) = 1;
  993. p = (infostruct *) p->next;
  994. }
  995. wake_up_interruptible(&(dev->info_waitq));
  996. }
  997. static ssize_t
  998. isdn_read(struct file *file, char __user *buf, size_t count, loff_t * off)
  999. {
  1000. uint minor = iminor(file->f_path.dentry->d_inode);
  1001. int len = 0;
  1002. int drvidx;
  1003. int chidx;
  1004. int retval;
  1005. char *p;
  1006. lock_kernel();
  1007. if (minor == ISDN_MINOR_STATUS) {
  1008. if (!file->private_data) {
  1009. if (file->f_flags & O_NONBLOCK) {
  1010. retval = -EAGAIN;
  1011. goto out;
  1012. }
  1013. interruptible_sleep_on(&(dev->info_waitq));
  1014. }
  1015. p = isdn_statstr();
  1016. file->private_data = NULL;
  1017. if ((len = strlen(p)) <= count) {
  1018. if (copy_to_user(buf, p, len)) {
  1019. retval = -EFAULT;
  1020. goto out;
  1021. }
  1022. *off += len;
  1023. retval = len;
  1024. goto out;
  1025. }
  1026. retval = 0;
  1027. goto out;
  1028. }
  1029. if (!dev->drivers) {
  1030. retval = -ENODEV;
  1031. goto out;
  1032. }
  1033. if (minor <= ISDN_MINOR_BMAX) {
  1034. printk(KERN_WARNING "isdn_read minor %d obsolete!\n", minor);
  1035. drvidx = isdn_minor2drv(minor);
  1036. if (drvidx < 0) {
  1037. retval = -ENODEV;
  1038. goto out;
  1039. }
  1040. if (!(dev->drv[drvidx]->flags & DRV_FLAG_RUNNING)) {
  1041. retval = -ENODEV;
  1042. goto out;
  1043. }
  1044. chidx = isdn_minor2chan(minor);
  1045. if (!(p = kmalloc(count, GFP_KERNEL))) {
  1046. retval = -ENOMEM;
  1047. goto out;
  1048. }
  1049. len = isdn_readbchan(drvidx, chidx, p, NULL, count,
  1050. &dev->drv[drvidx]->rcv_waitq[chidx]);
  1051. *off += len;
  1052. if (copy_to_user(buf,p,len))
  1053. len = -EFAULT;
  1054. kfree(p);
  1055. retval = len;
  1056. goto out;
  1057. }
  1058. if (minor <= ISDN_MINOR_CTRLMAX) {
  1059. drvidx = isdn_minor2drv(minor - ISDN_MINOR_CTRL);
  1060. if (drvidx < 0) {
  1061. retval = -ENODEV;
  1062. goto out;
  1063. }
  1064. if (!dev->drv[drvidx]->stavail) {
  1065. if (file->f_flags & O_NONBLOCK) {
  1066. retval = -EAGAIN;
  1067. goto out;
  1068. }
  1069. interruptible_sleep_on(&(dev->drv[drvidx]->st_waitq));
  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. unlock_kernel();
  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->f_path.dentry->d_inode);
  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. lock_kernel();
  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. while ((retval = isdn_writebuf_stub(drvidx, chidx, buf, count)) == 0)
  1127. interruptible_sleep_on(&dev->drv[drvidx]->snd_waitq[chidx]);
  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. unlock_kernel();
  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->f_path.dentry->d_inode);
  1166. int drvidx = isdn_minor2drv(minor - ISDN_MINOR_CTRL);
  1167. lock_kernel();
  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. unlock_kernel();
  1198. return mask;
  1199. }
  1200. static int
  1201. isdn_ioctl(struct inode *inode, struct file *file, uint cmd, ulong arg)
  1202. {
  1203. uint minor = iminor(inode);
  1204. isdn_ctrl c;
  1205. int drvidx;
  1206. int chidx;
  1207. int ret;
  1208. int i;
  1209. char __user *p;
  1210. char *s;
  1211. union iocpar {
  1212. char name[10];
  1213. char bname[22];
  1214. isdn_ioctl_struct iocts;
  1215. isdn_net_ioctl_phone phone;
  1216. isdn_net_ioctl_cfg cfg;
  1217. } iocpar;
  1218. void __user *argp = (void __user *)arg;
  1219. #define name iocpar.name
  1220. #define bname iocpar.bname
  1221. #define iocts iocpar.iocts
  1222. #define phone iocpar.phone
  1223. #define cfg iocpar.cfg
  1224. if (minor == ISDN_MINOR_STATUS) {
  1225. switch (cmd) {
  1226. case IIOCGETDVR:
  1227. return (TTY_DV +
  1228. (NET_DV << 8) +
  1229. (INF_DV << 16));
  1230. case IIOCGETCPS:
  1231. if (arg) {
  1232. ulong __user *p = argp;
  1233. int i;
  1234. if (!access_ok(VERIFY_WRITE, p,
  1235. sizeof(ulong) * ISDN_MAX_CHANNELS * 2))
  1236. return -EFAULT;
  1237. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  1238. put_user(dev->ibytes[i], p++);
  1239. put_user(dev->obytes[i], p++);
  1240. }
  1241. return 0;
  1242. } else
  1243. return -EINVAL;
  1244. break;
  1245. #ifdef CONFIG_NETDEVICES
  1246. case IIOCNETGPN:
  1247. /* Get peer phone number of a connected
  1248. * isdn network interface */
  1249. if (arg) {
  1250. if (copy_from_user(&phone, argp, sizeof(phone)))
  1251. return -EFAULT;
  1252. return isdn_net_getpeer(&phone, argp);
  1253. } else
  1254. return -EINVAL;
  1255. #endif
  1256. default:
  1257. return -EINVAL;
  1258. }
  1259. }
  1260. if (!dev->drivers)
  1261. return -ENODEV;
  1262. if (minor <= ISDN_MINOR_BMAX) {
  1263. drvidx = isdn_minor2drv(minor);
  1264. if (drvidx < 0)
  1265. return -ENODEV;
  1266. chidx = isdn_minor2chan(minor);
  1267. if (!(dev->drv[drvidx]->flags & DRV_FLAG_RUNNING))
  1268. return -ENODEV;
  1269. return 0;
  1270. }
  1271. if (minor <= ISDN_MINOR_CTRLMAX) {
  1272. /*
  1273. * isdn net devices manage lots of configuration variables as linked lists.
  1274. * Those lists must only be manipulated from user space. Some of the ioctl's
  1275. * service routines access user space and are not atomic. Therefore, ioctl's
  1276. * manipulating the lists and ioctl's sleeping while accessing the lists
  1277. * are serialized by means of a semaphore.
  1278. */
  1279. switch (cmd) {
  1280. case IIOCNETDWRSET:
  1281. printk(KERN_INFO "INFO: ISDN_DW_ABC_EXTENSION not enabled\n");
  1282. return(-EINVAL);
  1283. case IIOCNETLCR:
  1284. printk(KERN_INFO "INFO: ISDN_ABC_LCR_SUPPORT not enabled\n");
  1285. return -ENODEV;
  1286. #ifdef CONFIG_NETDEVICES
  1287. case IIOCNETAIF:
  1288. /* Add a network-interface */
  1289. if (arg) {
  1290. if (copy_from_user(name, argp, sizeof(name)))
  1291. return -EFAULT;
  1292. s = name;
  1293. } else {
  1294. s = NULL;
  1295. }
  1296. ret = mutex_lock_interruptible(&dev->mtx);
  1297. if( ret ) return ret;
  1298. if ((s = isdn_net_new(s, NULL))) {
  1299. if (copy_to_user(argp, s, strlen(s) + 1)){
  1300. ret = -EFAULT;
  1301. } else {
  1302. ret = 0;
  1303. }
  1304. } else
  1305. ret = -ENODEV;
  1306. mutex_unlock(&dev->mtx);
  1307. return ret;
  1308. case IIOCNETASL:
  1309. /* Add a slave to a network-interface */
  1310. if (arg) {
  1311. if (copy_from_user(bname, argp, sizeof(bname) - 1))
  1312. return -EFAULT;
  1313. } else
  1314. return -EINVAL;
  1315. ret = mutex_lock_interruptible(&dev->mtx);
  1316. if( ret ) return ret;
  1317. if ((s = isdn_net_newslave(bname))) {
  1318. if (copy_to_user(argp, s, strlen(s) + 1)){
  1319. ret = -EFAULT;
  1320. } else {
  1321. ret = 0;
  1322. }
  1323. } else
  1324. ret = -ENODEV;
  1325. mutex_unlock(&dev->mtx);
  1326. return ret;
  1327. case IIOCNETDIF:
  1328. /* Delete a network-interface */
  1329. if (arg) {
  1330. if (copy_from_user(name, argp, sizeof(name)))
  1331. return -EFAULT;
  1332. ret = mutex_lock_interruptible(&dev->mtx);
  1333. if( ret ) return ret;
  1334. ret = isdn_net_rm(name);
  1335. mutex_unlock(&dev->mtx);
  1336. return ret;
  1337. } else
  1338. return -EINVAL;
  1339. case IIOCNETSCF:
  1340. /* Set configurable parameters of a network-interface */
  1341. if (arg) {
  1342. if (copy_from_user(&cfg, argp, sizeof(cfg)))
  1343. return -EFAULT;
  1344. return isdn_net_setcfg(&cfg);
  1345. } else
  1346. return -EINVAL;
  1347. case IIOCNETGCF:
  1348. /* Get configurable parameters of a network-interface */
  1349. if (arg) {
  1350. if (copy_from_user(&cfg, argp, sizeof(cfg)))
  1351. return -EFAULT;
  1352. if (!(ret = isdn_net_getcfg(&cfg))) {
  1353. if (copy_to_user(argp, &cfg, sizeof(cfg)))
  1354. return -EFAULT;
  1355. }
  1356. return ret;
  1357. } else
  1358. return -EINVAL;
  1359. case IIOCNETANM:
  1360. /* Add a phone-number to a network-interface */
  1361. if (arg) {
  1362. if (copy_from_user(&phone, argp, sizeof(phone)))
  1363. return -EFAULT;
  1364. ret = mutex_lock_interruptible(&dev->mtx);
  1365. if( ret ) return ret;
  1366. ret = isdn_net_addphone(&phone);
  1367. mutex_unlock(&dev->mtx);
  1368. return ret;
  1369. } else
  1370. return -EINVAL;
  1371. case IIOCNETGNM:
  1372. /* Get list of phone-numbers of a network-interface */
  1373. if (arg) {
  1374. if (copy_from_user(&phone, argp, sizeof(phone)))
  1375. return -EFAULT;
  1376. ret = mutex_lock_interruptible(&dev->mtx);
  1377. if( ret ) return ret;
  1378. ret = isdn_net_getphones(&phone, argp);
  1379. mutex_unlock(&dev->mtx);
  1380. return ret;
  1381. } else
  1382. return -EINVAL;
  1383. case IIOCNETDNM:
  1384. /* Delete a phone-number of a network-interface */
  1385. if (arg) {
  1386. if (copy_from_user(&phone, argp, sizeof(phone)))
  1387. return -EFAULT;
  1388. ret = mutex_lock_interruptible(&dev->mtx);
  1389. if( ret ) return ret;
  1390. ret = isdn_net_delphone(&phone);
  1391. mutex_unlock(&dev->mtx);
  1392. return ret;
  1393. } else
  1394. return -EINVAL;
  1395. case IIOCNETDIL:
  1396. /* Force dialing of a network-interface */
  1397. if (arg) {
  1398. if (copy_from_user(name, argp, sizeof(name)))
  1399. return -EFAULT;
  1400. return isdn_net_force_dial(name);
  1401. } else
  1402. return -EINVAL;
  1403. #ifdef CONFIG_ISDN_PPP
  1404. case IIOCNETALN:
  1405. if (!arg)
  1406. return -EINVAL;
  1407. if (copy_from_user(name, argp, sizeof(name)))
  1408. return -EFAULT;
  1409. return isdn_ppp_dial_slave(name);
  1410. case IIOCNETDLN:
  1411. if (!arg)
  1412. return -EINVAL;
  1413. if (copy_from_user(name, argp, sizeof(name)))
  1414. return -EFAULT;
  1415. return isdn_ppp_hangup_slave(name);
  1416. #endif
  1417. case IIOCNETHUP:
  1418. /* Force hangup of a network-interface */
  1419. if (!arg)
  1420. return -EINVAL;
  1421. if (copy_from_user(name, argp, sizeof(name)))
  1422. return -EFAULT;
  1423. return isdn_net_force_hangup(name);
  1424. break;
  1425. #endif /* CONFIG_NETDEVICES */
  1426. case IIOCSETVER:
  1427. dev->net_verbose = arg;
  1428. printk(KERN_INFO "isdn: Verbose-Level is %d\n", dev->net_verbose);
  1429. return 0;
  1430. case IIOCSETGST:
  1431. if (arg)
  1432. dev->global_flags |= ISDN_GLOBAL_STOPPED;
  1433. else
  1434. dev->global_flags &= ~ISDN_GLOBAL_STOPPED;
  1435. printk(KERN_INFO "isdn: Global Mode %s\n",
  1436. (dev->global_flags & ISDN_GLOBAL_STOPPED) ? "stopped" : "running");
  1437. return 0;
  1438. case IIOCSETBRJ:
  1439. drvidx = -1;
  1440. if (arg) {
  1441. int i;
  1442. char *p;
  1443. if (copy_from_user(&iocts, argp,
  1444. sizeof(isdn_ioctl_struct)))
  1445. return -EFAULT;
  1446. iocts.drvid[sizeof(iocts.drvid)-1] = 0;
  1447. if (strlen(iocts.drvid)) {
  1448. if ((p = strchr(iocts.drvid, ',')))
  1449. *p = 0;
  1450. drvidx = -1;
  1451. for (i = 0; i < ISDN_MAX_DRIVERS; i++)
  1452. if (!(strcmp(dev->drvid[i], iocts.drvid))) {
  1453. drvidx = i;
  1454. break;
  1455. }
  1456. }
  1457. }
  1458. if (drvidx == -1)
  1459. return -ENODEV;
  1460. if (iocts.arg)
  1461. dev->drv[drvidx]->flags |= DRV_FLAG_REJBUS;
  1462. else
  1463. dev->drv[drvidx]->flags &= ~DRV_FLAG_REJBUS;
  1464. return 0;
  1465. case IIOCSIGPRF:
  1466. dev->profd = current;
  1467. return 0;
  1468. break;
  1469. case IIOCGETPRF:
  1470. /* Get all Modem-Profiles */
  1471. if (arg) {
  1472. char __user *p = argp;
  1473. int i;
  1474. if (!access_ok(VERIFY_WRITE, argp,
  1475. (ISDN_MODEM_NUMREG + ISDN_MSNLEN + ISDN_LMSNLEN)
  1476. * ISDN_MAX_CHANNELS))
  1477. return -EFAULT;
  1478. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  1479. if (copy_to_user(p, dev->mdm.info[i].emu.profile,
  1480. ISDN_MODEM_NUMREG))
  1481. return -EFAULT;
  1482. p += ISDN_MODEM_NUMREG;
  1483. if (copy_to_user(p, dev->mdm.info[i].emu.pmsn, ISDN_MSNLEN))
  1484. return -EFAULT;
  1485. p += ISDN_MSNLEN;
  1486. if (copy_to_user(p, dev->mdm.info[i].emu.plmsn, ISDN_LMSNLEN))
  1487. return -EFAULT;
  1488. p += ISDN_LMSNLEN;
  1489. }
  1490. return (ISDN_MODEM_NUMREG + ISDN_MSNLEN + ISDN_LMSNLEN) * ISDN_MAX_CHANNELS;
  1491. } else
  1492. return -EINVAL;
  1493. break;
  1494. case IIOCSETPRF:
  1495. /* Set all Modem-Profiles */
  1496. if (arg) {
  1497. char __user *p = argp;
  1498. int i;
  1499. if (!access_ok(VERIFY_READ, argp,
  1500. (ISDN_MODEM_NUMREG + ISDN_MSNLEN + ISDN_LMSNLEN)
  1501. * ISDN_MAX_CHANNELS))
  1502. return -EFAULT;
  1503. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  1504. if (copy_from_user(dev->mdm.info[i].emu.profile, p,
  1505. ISDN_MODEM_NUMREG))
  1506. return -EFAULT;
  1507. p += ISDN_MODEM_NUMREG;
  1508. if (copy_from_user(dev->mdm.info[i].emu.plmsn, p, ISDN_LMSNLEN))
  1509. return -EFAULT;
  1510. p += ISDN_LMSNLEN;
  1511. if (copy_from_user(dev->mdm.info[i].emu.pmsn, p, ISDN_MSNLEN))
  1512. return -EFAULT;
  1513. p += ISDN_MSNLEN;
  1514. }
  1515. return 0;
  1516. } else
  1517. return -EINVAL;
  1518. break;
  1519. case IIOCSETMAP:
  1520. case IIOCGETMAP:
  1521. /* Set/Get MSN->EAZ-Mapping for a driver */
  1522. if (arg) {
  1523. if (copy_from_user(&iocts, argp,
  1524. sizeof(isdn_ioctl_struct)))
  1525. return -EFAULT;
  1526. iocts.drvid[sizeof(iocts.drvid)-1] = 0;
  1527. if (strlen(iocts.drvid)) {
  1528. drvidx = -1;
  1529. for (i = 0; i < ISDN_MAX_DRIVERS; i++)
  1530. if (!(strcmp(dev->drvid[i], iocts.drvid))) {
  1531. drvidx = i;
  1532. break;
  1533. }
  1534. } else
  1535. drvidx = 0;
  1536. if (drvidx == -1)
  1537. return -ENODEV;
  1538. if (cmd == IIOCSETMAP) {
  1539. int loop = 1;
  1540. p = (char __user *) iocts.arg;
  1541. i = 0;
  1542. while (loop) {
  1543. int j = 0;
  1544. while (1) {
  1545. if (!access_ok(VERIFY_READ, p, 1))
  1546. return -EFAULT;
  1547. get_user(bname[j], p++);
  1548. switch (bname[j]) {
  1549. case '\0':
  1550. loop = 0;
  1551. /* Fall through */
  1552. case ',':
  1553. bname[j] = '\0';
  1554. strcpy(dev->drv[drvidx]->msn2eaz[i], bname);
  1555. j = ISDN_MSNLEN;
  1556. break;
  1557. default:
  1558. j++;
  1559. }
  1560. if (j >= ISDN_MSNLEN)
  1561. break;
  1562. }
  1563. if (++i > 9)
  1564. break;
  1565. }
  1566. } else {
  1567. p = (char __user *) iocts.arg;
  1568. for (i = 0; i < 10; i++) {
  1569. snprintf(bname, sizeof(bname), "%s%s",
  1570. strlen(dev->drv[drvidx]->msn2eaz[i]) ?
  1571. dev->drv[drvidx]->msn2eaz[i] : "_",
  1572. (i < 9) ? "," : "\0");
  1573. if (copy_to_user(p, bname, strlen(bname) + 1))
  1574. return -EFAULT;
  1575. p += strlen(bname);
  1576. }
  1577. }
  1578. return 0;
  1579. } else
  1580. return -EINVAL;
  1581. case IIOCDBGVAR:
  1582. if (arg) {
  1583. if (copy_to_user(argp, &dev, sizeof(ulong)))
  1584. return -EFAULT;
  1585. return 0;
  1586. } else
  1587. return -EINVAL;
  1588. break;
  1589. default:
  1590. if ((cmd & IIOCDRVCTL) == IIOCDRVCTL)
  1591. cmd = ((cmd >> _IOC_NRSHIFT) & _IOC_NRMASK) & ISDN_DRVIOCTL_MASK;
  1592. else
  1593. return -EINVAL;
  1594. if (arg) {
  1595. int i;
  1596. char *p;
  1597. if (copy_from_user(&iocts, argp, sizeof(isdn_ioctl_struct)))
  1598. return -EFAULT;
  1599. iocts.drvid[sizeof(iocts.drvid)-1] = 0;
  1600. if (strlen(iocts.drvid)) {
  1601. if ((p = strchr(iocts.drvid, ',')))
  1602. *p = 0;
  1603. drvidx = -1;
  1604. for (i = 0; i < ISDN_MAX_DRIVERS; i++)
  1605. if (!(strcmp(dev->drvid[i], iocts.drvid))) {
  1606. drvidx = i;
  1607. break;
  1608. }
  1609. } else
  1610. drvidx = 0;
  1611. if (drvidx == -1)
  1612. return -ENODEV;
  1613. if (!access_ok(VERIFY_WRITE, argp,
  1614. sizeof(isdn_ioctl_struct)))
  1615. return -EFAULT;
  1616. c.driver = drvidx;
  1617. c.command = ISDN_CMD_IOCTL;
  1618. c.arg = cmd;
  1619. memcpy(c.parm.num, &iocts.arg, sizeof(ulong));
  1620. ret = isdn_command(&c);
  1621. memcpy(&iocts.arg, c.parm.num, sizeof(ulong));
  1622. if (copy_to_user(argp, &iocts, sizeof(isdn_ioctl_struct)))
  1623. return -EFAULT;
  1624. return ret;
  1625. } else
  1626. return -EINVAL;
  1627. }
  1628. }
  1629. #ifdef CONFIG_ISDN_PPP
  1630. if (minor <= ISDN_MINOR_PPPMAX)
  1631. return (isdn_ppp_ioctl(minor - ISDN_MINOR_PPP, file, cmd, arg));
  1632. #endif
  1633. return -ENODEV;
  1634. #undef name
  1635. #undef bname
  1636. #undef iocts
  1637. #undef phone
  1638. #undef cfg
  1639. }
  1640. /*
  1641. * Open the device code.
  1642. */
  1643. static int
  1644. isdn_open(struct inode *ino, struct file *filep)
  1645. {
  1646. uint minor = iminor(ino);
  1647. int drvidx;
  1648. int chidx;
  1649. int retval = -ENODEV;
  1650. lock_kernel();
  1651. if (minor == ISDN_MINOR_STATUS) {
  1652. infostruct *p;
  1653. if ((p = kmalloc(sizeof(infostruct), GFP_KERNEL))) {
  1654. p->next = (char *) dev->infochain;
  1655. p->private = (char *) &(filep->private_data);
  1656. dev->infochain = p;
  1657. /* At opening we allow a single update */
  1658. filep->private_data = (char *) 1;
  1659. retval = 0;
  1660. goto out;
  1661. } else {
  1662. retval = -ENOMEM;
  1663. goto out;
  1664. }
  1665. }
  1666. if (!dev->channels)
  1667. goto out;
  1668. if (minor <= ISDN_MINOR_BMAX) {
  1669. printk(KERN_WARNING "isdn_open minor %d obsolete!\n", minor);
  1670. drvidx = isdn_minor2drv(minor);
  1671. if (drvidx < 0)
  1672. goto out;
  1673. chidx = isdn_minor2chan(minor);
  1674. if (!(dev->drv[drvidx]->flags & DRV_FLAG_RUNNING))
  1675. goto out;
  1676. if (!(dev->drv[drvidx]->online & (1 << chidx)))
  1677. goto out;
  1678. isdn_lock_drivers();
  1679. retval = 0;
  1680. goto out;
  1681. }
  1682. if (minor <= ISDN_MINOR_CTRLMAX) {
  1683. drvidx = isdn_minor2drv(minor - ISDN_MINOR_CTRL);
  1684. if (drvidx < 0)
  1685. goto out;
  1686. isdn_lock_drivers();
  1687. retval = 0;
  1688. goto out;
  1689. }
  1690. #ifdef CONFIG_ISDN_PPP
  1691. if (minor <= ISDN_MINOR_PPPMAX) {
  1692. retval = isdn_ppp_open(minor - ISDN_MINOR_PPP, filep);
  1693. if (retval == 0)
  1694. isdn_lock_drivers();
  1695. goto out;
  1696. }
  1697. #endif
  1698. out:
  1699. nonseekable_open(ino, filep);
  1700. unlock_kernel();
  1701. return retval;
  1702. }
  1703. static int
  1704. isdn_close(struct inode *ino, struct file *filep)
  1705. {
  1706. uint minor = iminor(ino);
  1707. lock_kernel();
  1708. if (minor == ISDN_MINOR_STATUS) {
  1709. infostruct *p = dev->infochain;
  1710. infostruct *q = NULL;
  1711. while (p) {
  1712. if (p->private == (char *) &(filep->private_data)) {
  1713. if (q)
  1714. q->next = p->next;
  1715. else
  1716. dev->infochain = (infostruct *) (p->next);
  1717. kfree(p);
  1718. goto out;
  1719. }
  1720. q = p;
  1721. p = (infostruct *) (p->next);
  1722. }
  1723. printk(KERN_WARNING "isdn: No private data while closing isdnctrl\n");
  1724. goto out;
  1725. }
  1726. isdn_unlock_drivers();
  1727. if (minor <= ISDN_MINOR_BMAX)
  1728. goto out;
  1729. if (minor <= ISDN_MINOR_CTRLMAX) {
  1730. if (dev->profd == current)
  1731. dev->profd = NULL;
  1732. goto out;
  1733. }
  1734. #ifdef CONFIG_ISDN_PPP
  1735. if (minor <= ISDN_MINOR_PPPMAX)
  1736. isdn_ppp_release(minor - ISDN_MINOR_PPP, filep);
  1737. #endif
  1738. out:
  1739. unlock_kernel();
  1740. return 0;
  1741. }
  1742. static const struct file_operations isdn_fops =
  1743. {
  1744. .owner = THIS_MODULE,
  1745. .llseek = no_llseek,
  1746. .read = isdn_read,
  1747. .write = isdn_write,
  1748. .poll = isdn_poll,
  1749. .ioctl = isdn_ioctl,
  1750. .open = isdn_open,
  1751. .release = isdn_close,
  1752. };
  1753. char *
  1754. isdn_map_eaz2msn(char *msn, int di)
  1755. {
  1756. isdn_driver_t *this = dev->drv[di];
  1757. int i;
  1758. if (strlen(msn) == 1) {
  1759. i = msn[0] - '0';
  1760. if ((i >= 0) && (i <= 9))
  1761. if (strlen(this->msn2eaz[i]))
  1762. return (this->msn2eaz[i]);
  1763. }
  1764. return (msn);
  1765. }
  1766. /*
  1767. * Find an unused ISDN-channel, whose feature-flags match the
  1768. * given L2- and L3-protocols.
  1769. */
  1770. #define L2V (~(ISDN_FEATURE_L2_V11096|ISDN_FEATURE_L2_V11019|ISDN_FEATURE_L2_V11038))
  1771. /*
  1772. * This function must be called with holding the dev->lock.
  1773. */
  1774. int
  1775. isdn_get_free_channel(int usage, int l2_proto, int l3_proto, int pre_dev
  1776. ,int pre_chan, char *msn)
  1777. {
  1778. int i;
  1779. ulong features;
  1780. ulong vfeatures;
  1781. features = ((1 << l2_proto) | (0x10000 << l3_proto));
  1782. vfeatures = (((1 << l2_proto) | (0x10000 << l3_proto)) &
  1783. ~(ISDN_FEATURE_L2_V11096|ISDN_FEATURE_L2_V11019|ISDN_FEATURE_L2_V11038));
  1784. /* If Layer-2 protocol is V.110, accept drivers with
  1785. * transparent feature even if these don't support V.110
  1786. * because we can emulate this in linklevel.
  1787. */
  1788. for (i = 0; i < ISDN_MAX_CHANNELS; i++)
  1789. if (USG_NONE(dev->usage[i]) &&
  1790. (dev->drvmap[i] != -1)) {
  1791. int d = dev->drvmap[i];
  1792. if ((dev->usage[i] & ISDN_USAGE_EXCLUSIVE) &&
  1793. ((pre_dev != d) || (pre_chan != dev->chanmap[i])))
  1794. continue;
  1795. if (!strcmp(isdn_map_eaz2msn(msn, d), "-"))
  1796. continue;
  1797. if (dev->usage[i] & ISDN_USAGE_DISABLED)
  1798. continue; /* usage not allowed */
  1799. if (dev->drv[d]->flags & DRV_FLAG_RUNNING) {
  1800. if (((dev->drv[d]->interface->features & features) == features) ||
  1801. (((dev->drv[d]->interface->features & vfeatures) == vfeatures) &&
  1802. (dev->drv[d]->interface->features & ISDN_FEATURE_L2_TRANS))) {
  1803. if ((pre_dev < 0) || (pre_chan < 0)) {
  1804. dev->usage[i] &= ISDN_USAGE_EXCLUSIVE;
  1805. dev->usage[i] |= usage;
  1806. isdn_info_update();
  1807. return i;
  1808. } else {
  1809. if ((pre_dev == d) && (pre_chan == dev->chanmap[i])) {
  1810. dev->usage[i] &= ISDN_USAGE_EXCLUSIVE;
  1811. dev->usage[i] |= usage;
  1812. isdn_info_update();
  1813. return i;
  1814. }
  1815. }
  1816. }
  1817. }
  1818. }
  1819. return -1;
  1820. }
  1821. /*
  1822. * Set state of ISDN-channel to 'unused'
  1823. */
  1824. void
  1825. isdn_free_channel(int di, int ch, int usage)
  1826. {
  1827. int i;
  1828. if ((di < 0) || (ch < 0)) {
  1829. printk(KERN_WARNING "%s: called with invalid drv(%d) or channel(%d)\n",
  1830. __func__, di, ch);
  1831. return;
  1832. }
  1833. for (i = 0; i < ISDN_MAX_CHANNELS; i++)
  1834. if (((!usage) || ((dev->usage[i] & ISDN_USAGE_MASK) == usage)) &&
  1835. (dev->drvmap[i] == di) &&
  1836. (dev->chanmap[i] == ch)) {
  1837. dev->usage[i] &= (ISDN_USAGE_NONE | ISDN_USAGE_EXCLUSIVE);
  1838. strcpy(dev->num[i], "???");
  1839. dev->ibytes[i] = 0;
  1840. dev->obytes[i] = 0;
  1841. // 20.10.99 JIM, try to reinitialize v110 !
  1842. dev->v110emu[i] = 0;
  1843. atomic_set(&(dev->v110use[i]), 0);
  1844. isdn_v110_close(dev->v110[i]);
  1845. dev->v110[i] = NULL;
  1846. // 20.10.99 JIM, try to reinitialize v110 !
  1847. isdn_info_update();
  1848. if (dev->drv[di])
  1849. skb_queue_purge(&dev->drv[di]->rpqueue[ch]);
  1850. }
  1851. }
  1852. /*
  1853. * Cancel Exclusive-Flag for ISDN-channel
  1854. */
  1855. void
  1856. isdn_unexclusive_channel(int di, int ch)
  1857. {
  1858. int i;
  1859. for (i = 0; i < ISDN_MAX_CHANNELS; i++)
  1860. if ((dev->drvmap[i] == di) &&
  1861. (dev->chanmap[i] == ch)) {
  1862. dev->usage[i] &= ~ISDN_USAGE_EXCLUSIVE;
  1863. isdn_info_update();
  1864. return;
  1865. }
  1866. }
  1867. /*
  1868. * writebuf replacement for SKB_ABLE drivers
  1869. */
  1870. static int
  1871. isdn_writebuf_stub(int drvidx, int chan, const u_char __user * buf, int len)
  1872. {
  1873. int ret;
  1874. int hl = dev->drv[drvidx]->interface->hl_hdrlen;
  1875. struct sk_buff *skb = alloc_skb(hl + len, GFP_ATOMIC);
  1876. if (!skb)
  1877. return -ENOMEM;
  1878. skb_reserve(skb, hl);
  1879. if (copy_from_user(skb_put(skb, len), buf, len)) {
  1880. dev_kfree_skb(skb);
  1881. return -EFAULT;
  1882. }
  1883. ret = dev->drv[drvidx]->interface->writebuf_skb(drvidx, chan, 1, skb);
  1884. if (ret <= 0)
  1885. dev_kfree_skb(skb);
  1886. if (ret > 0)
  1887. dev->obytes[isdn_dc2minor(drvidx, chan)] += ret;
  1888. return ret;
  1889. }
  1890. /*
  1891. * Return: length of data on success, -ERRcode on failure.
  1892. */
  1893. int
  1894. isdn_writebuf_skb_stub(int drvidx, int chan, int ack, struct sk_buff *skb)
  1895. {
  1896. int ret;
  1897. struct sk_buff *nskb = NULL;
  1898. int v110_ret = skb->len;
  1899. int idx = isdn_dc2minor(drvidx, chan);
  1900. if (dev->v110[idx]) {
  1901. atomic_inc(&dev->v110use[idx]);
  1902. nskb = isdn_v110_encode(dev->v110[idx], skb);
  1903. atomic_dec(&dev->v110use[idx]);
  1904. if (!nskb)
  1905. return 0;
  1906. v110_ret = *((int *)nskb->data);
  1907. skb_pull(nskb, sizeof(int));
  1908. if (!nskb->len) {
  1909. dev_kfree_skb(nskb);
  1910. return v110_ret;
  1911. }
  1912. /* V.110 must always be acknowledged */
  1913. ack = 1;
  1914. ret = dev->drv[drvidx]->interface->writebuf_skb(drvidx, chan, ack, nskb);
  1915. } else {
  1916. int hl = dev->drv[drvidx]->interface->hl_hdrlen;
  1917. if( skb_headroom(skb) < hl ){
  1918. /*
  1919. * This should only occur when new HL driver with
  1920. * increased hl_hdrlen was loaded after netdevice
  1921. * was created and connected to the new driver.
  1922. *
  1923. * The V.110 branch (re-allocates on its own) does
  1924. * not need this
  1925. */
  1926. struct sk_buff * skb_tmp;
  1927. skb_tmp = skb_realloc_headroom(skb, hl);
  1928. printk(KERN_DEBUG "isdn_writebuf_skb_stub: reallocating headroom%s\n", skb_tmp ? "" : " failed");
  1929. if (!skb_tmp) return -ENOMEM; /* 0 better? */
  1930. ret = dev->drv[drvidx]->interface->writebuf_skb(drvidx, chan, ack, skb_tmp);
  1931. if( ret > 0 ){
  1932. dev_kfree_skb(skb);
  1933. } else {
  1934. dev_kfree_skb(skb_tmp);
  1935. }
  1936. } else {
  1937. ret = dev->drv[drvidx]->interface->writebuf_skb(drvidx, chan, ack, skb);
  1938. }
  1939. }
  1940. if (ret > 0) {
  1941. dev->obytes[idx] += ret;
  1942. if (dev->v110[idx]) {
  1943. atomic_inc(&dev->v110use[idx]);
  1944. dev->v110[idx]->skbuser++;
  1945. atomic_dec(&dev->v110use[idx]);
  1946. /* For V.110 return unencoded data length */
  1947. ret = v110_ret;
  1948. /* if the complete frame was send we free the skb;
  1949. if not upper function will requeue the skb */
  1950. if (ret == skb->len)
  1951. dev_kfree_skb(skb);
  1952. }
  1953. } else
  1954. if (dev->v110[idx])
  1955. dev_kfree_skb(nskb);
  1956. return ret;
  1957. }
  1958. static int
  1959. isdn_add_channels(isdn_driver_t *d, int drvidx, int n, int adding)
  1960. {
  1961. int j, k, m;
  1962. init_waitqueue_head(&d->st_waitq);
  1963. if (d->flags & DRV_FLAG_RUNNING)
  1964. return -1;
  1965. if (n < 1) return 0;
  1966. m = (adding) ? d->channels + n : n;
  1967. if (dev->channels + n > ISDN_MAX_CHANNELS) {
  1968. printk(KERN_WARNING "register_isdn: Max. %d channels supported\n",
  1969. ISDN_MAX_CHANNELS);
  1970. return -1;
  1971. }
  1972. if ((adding) && (d->rcverr))
  1973. kfree(d->rcverr);
  1974. if (!(d->rcverr = kzalloc(sizeof(int) * m, GFP_ATOMIC))) {
  1975. printk(KERN_WARNING "register_isdn: Could not alloc rcverr\n");
  1976. return -1;
  1977. }
  1978. if ((adding) && (d->rcvcount))
  1979. kfree(d->rcvcount);
  1980. if (!(d->rcvcount = kzalloc(sizeof(int) * m, GFP_ATOMIC))) {
  1981. printk(KERN_WARNING "register_isdn: Could not alloc rcvcount\n");
  1982. if (!adding)
  1983. kfree(d->rcverr);
  1984. return -1;
  1985. }
  1986. if ((adding) && (d->rpqueue)) {
  1987. for (j = 0; j < d->channels; j++)
  1988. skb_queue_purge(&d->rpqueue[j]);
  1989. kfree(d->rpqueue);
  1990. }
  1991. if (!(d->rpqueue = kmalloc(sizeof(struct sk_buff_head) * m, GFP_ATOMIC))) {
  1992. printk(KERN_WARNING "register_isdn: Could not alloc rpqueue\n");
  1993. if (!adding) {
  1994. kfree(d->rcvcount);
  1995. kfree(d->rcverr);
  1996. }
  1997. return -1;
  1998. }
  1999. for (j = 0; j < m; j++) {
  2000. skb_queue_head_init(&d->rpqueue[j]);
  2001. }
  2002. if ((adding) && (d->rcv_waitq))
  2003. kfree(d->rcv_waitq);
  2004. d->rcv_waitq = kmalloc(sizeof(wait_queue_head_t) * 2 * m, GFP_ATOMIC);
  2005. if (!d->rcv_waitq) {
  2006. printk(KERN_WARNING "register_isdn: Could not alloc rcv_waitq\n");
  2007. if (!adding) {
  2008. kfree(d->rpqueue);
  2009. kfree(d->rcvcount);
  2010. kfree(d->rcverr);
  2011. }
  2012. return -1;
  2013. }
  2014. d->snd_waitq = d->rcv_waitq + m;
  2015. for (j = 0; j < m; j++) {
  2016. init_waitqueue_head(&d->rcv_waitq[j]);
  2017. init_waitqueue_head(&d->snd_waitq[j]);
  2018. }
  2019. dev->channels += n;
  2020. for (j = d->channels; j < m; j++)
  2021. for (k = 0; k < ISDN_MAX_CHANNELS; k++)
  2022. if (dev->chanmap[k] < 0) {
  2023. dev->chanmap[k] = j;
  2024. dev->drvmap[k] = drvidx;
  2025. break;
  2026. }
  2027. d->channels = m;
  2028. return 0;
  2029. }
  2030. /*
  2031. * Low-level-driver registration
  2032. */
  2033. static void
  2034. set_global_features(void)
  2035. {
  2036. int drvidx;
  2037. dev->global_features = 0;
  2038. for (drvidx = 0; drvidx < ISDN_MAX_DRIVERS; drvidx++) {
  2039. if (!dev->drv[drvidx])
  2040. continue;
  2041. if (dev->drv[drvidx]->interface)
  2042. dev->global_features |= dev->drv[drvidx]->interface->features;
  2043. }
  2044. }
  2045. #ifdef CONFIG_ISDN_DIVERSION
  2046. static char *map_drvname(int di)
  2047. {
  2048. if ((di < 0) || (di >= ISDN_MAX_DRIVERS))
  2049. return(NULL);
  2050. return(dev->drvid[di]); /* driver name */
  2051. } /* map_drvname */
  2052. static int map_namedrv(char *id)
  2053. { int i;
  2054. for (i = 0; i < ISDN_MAX_DRIVERS; i++)
  2055. { if (!strcmp(dev->drvid[i],id))
  2056. return(i);
  2057. }
  2058. return(-1);
  2059. } /* map_namedrv */
  2060. int DIVERT_REG_NAME(isdn_divert_if *i_div)
  2061. {
  2062. if (i_div->if_magic != DIVERT_IF_MAGIC)
  2063. return(DIVERT_VER_ERR);
  2064. switch (i_div->cmd)
  2065. {
  2066. case DIVERT_CMD_REL:
  2067. if (divert_if != i_div)
  2068. return(DIVERT_REL_ERR);
  2069. divert_if = NULL; /* free interface */
  2070. return(DIVERT_NO_ERR);
  2071. case DIVERT_CMD_REG:
  2072. if (divert_if)
  2073. return(DIVERT_REG_ERR);
  2074. i_div->ll_cmd = isdn_command; /* set command function */
  2075. i_div->drv_to_name = map_drvname;
  2076. i_div->name_to_drv = map_namedrv;
  2077. divert_if = i_div; /* remember interface */
  2078. return(DIVERT_NO_ERR);
  2079. default:
  2080. return(DIVERT_CMD_ERR);
  2081. }
  2082. } /* DIVERT_REG_NAME */
  2083. EXPORT_SYMBOL(DIVERT_REG_NAME);
  2084. #endif /* CONFIG_ISDN_DIVERSION */
  2085. EXPORT_SYMBOL(register_isdn);
  2086. #ifdef CONFIG_ISDN_PPP
  2087. EXPORT_SYMBOL(isdn_ppp_register_compressor);
  2088. EXPORT_SYMBOL(isdn_ppp_unregister_compressor);
  2089. #endif
  2090. int
  2091. register_isdn(isdn_if * i)
  2092. {
  2093. isdn_driver_t *d;
  2094. int j;
  2095. ulong flags;
  2096. int drvidx;
  2097. if (dev->drivers >= ISDN_MAX_DRIVERS) {
  2098. printk(KERN_WARNING "register_isdn: Max. %d drivers supported\n",
  2099. ISDN_MAX_DRIVERS);
  2100. return 0;
  2101. }
  2102. if (!i->writebuf_skb) {
  2103. printk(KERN_WARNING "register_isdn: No write routine given.\n");
  2104. return 0;
  2105. }
  2106. if (!(d = kzalloc(sizeof(isdn_driver_t), GFP_KERNEL))) {
  2107. printk(KERN_WARNING "register_isdn: Could not alloc driver-struct\n");
  2108. return 0;
  2109. }
  2110. d->maxbufsize = i->maxbufsize;
  2111. d->pktcount = 0;
  2112. d->stavail = 0;
  2113. d->flags = DRV_FLAG_LOADED;
  2114. d->online = 0;
  2115. d->interface = i;
  2116. d->channels = 0;
  2117. spin_lock_irqsave(&dev->lock, flags);
  2118. for (drvidx = 0; drvidx < ISDN_MAX_DRIVERS; drvidx++)
  2119. if (!dev->drv[drvidx])
  2120. break;
  2121. if (isdn_add_channels(d, drvidx, i->channels, 0)) {
  2122. spin_unlock_irqrestore(&dev->lock, flags);
  2123. kfree(d);
  2124. return 0;
  2125. }
  2126. i->channels = drvidx;
  2127. i->rcvcallb_skb = isdn_receive_skb_callback;
  2128. i->statcallb = isdn_status_callback;
  2129. if (!strlen(i->id))
  2130. sprintf(i->id, "line%d", drvidx);
  2131. for (j = 0; j < drvidx; j++)
  2132. if (!strcmp(i->id, dev->drvid[j]))
  2133. sprintf(i->id, "line%d", drvidx);
  2134. dev->drv[drvidx] = d;
  2135. strcpy(dev->drvid[drvidx], i->id);
  2136. isdn_info_update();
  2137. dev->drivers++;
  2138. set_global_features();
  2139. spin_unlock_irqrestore(&dev->lock, flags);
  2140. return 1;
  2141. }
  2142. /*
  2143. *****************************************************************************
  2144. * And now the modules code.
  2145. *****************************************************************************
  2146. */
  2147. static char *
  2148. isdn_getrev(const char *revision)
  2149. {
  2150. char *rev;
  2151. char *p;
  2152. if ((p = strchr(revision, ':'))) {
  2153. rev = p + 2;
  2154. p = strchr(rev, '$');
  2155. *--p = 0;
  2156. } else
  2157. rev = "???";
  2158. return rev;
  2159. }
  2160. /*
  2161. * Allocate and initialize all data, register modem-devices
  2162. */
  2163. static int __init isdn_init(void)
  2164. {
  2165. int i;
  2166. char tmprev[50];
  2167. if (!(dev = vmalloc(sizeof(isdn_dev)))) {
  2168. printk(KERN_WARNING "isdn: Could not allocate device-struct.\n");
  2169. return -EIO;
  2170. }
  2171. memset((char *) dev, 0, sizeof(isdn_dev));
  2172. init_timer(&dev->timer);
  2173. dev->timer.function = isdn_timer_funct;
  2174. spin_lock_init(&dev->lock);
  2175. spin_lock_init(&dev->timerlock);
  2176. #ifdef MODULE
  2177. dev->owner = THIS_MODULE;
  2178. #endif
  2179. mutex_init(&dev->mtx);
  2180. init_waitqueue_head(&dev->info_waitq);
  2181. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  2182. dev->drvmap[i] = -1;
  2183. dev->chanmap[i] = -1;
  2184. dev->m_idx[i] = -1;
  2185. strcpy(dev->num[i], "???");
  2186. init_waitqueue_head(&dev->mdm.info[i].open_wait);
  2187. init_waitqueue_head(&dev->mdm.info[i].close_wait);
  2188. }
  2189. if (register_chrdev(ISDN_MAJOR, "isdn", &isdn_fops)) {
  2190. printk(KERN_WARNING "isdn: Could not register control devices\n");
  2191. vfree(dev);
  2192. return -EIO;
  2193. }
  2194. if ((isdn_tty_modem_init()) < 0) {
  2195. printk(KERN_WARNING "isdn: Could not register tty devices\n");
  2196. vfree(dev);
  2197. unregister_chrdev(ISDN_MAJOR, "isdn");
  2198. return -EIO;
  2199. }
  2200. #ifdef CONFIG_ISDN_PPP
  2201. if (isdn_ppp_init() < 0) {
  2202. printk(KERN_WARNING "isdn: Could not create PPP-device-structs\n");
  2203. isdn_tty_exit();
  2204. unregister_chrdev(ISDN_MAJOR, "isdn");
  2205. vfree(dev);
  2206. return -EIO;
  2207. }
  2208. #endif /* CONFIG_ISDN_PPP */
  2209. strcpy(tmprev, isdn_revision);
  2210. printk(KERN_NOTICE "ISDN subsystem Rev: %s/", isdn_getrev(tmprev));
  2211. strcpy(tmprev, isdn_tty_revision);
  2212. printk("%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);