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