isdn_common.c 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388
  1. /* $Id: isdn_common.c,v 1.1.2.3 2004/02/10 01:07:13 keil Exp $
  2. *
  3. * Linux ISDN subsystem, common used functions (linklevel).
  4. *
  5. * Copyright 1994-1999 by Fritz Elfert (fritz@isdn4linux.de)
  6. * Copyright 1995,96 Thinking Objects Software GmbH Wuerzburg
  7. * Copyright 1995,96 by Michael Hipp (Michael.Hipp@student.uni-tuebingen.de)
  8. *
  9. * This software may be used and distributed according to the terms
  10. * of the GNU General Public License, incorporated herein by reference.
  11. *
  12. */
  13. #include <linux/module.h>
  14. #include <linux/init.h>
  15. #include <linux/poll.h>
  16. #include <linux/slab.h>
  17. #include <linux/vmalloc.h>
  18. #include <linux/isdn.h>
  19. #include <linux/mutex.h>
  20. #include "isdn_common.h"
  21. #include "isdn_tty.h"
  22. #include "isdn_net.h"
  23. #include "isdn_ppp.h"
  24. #ifdef CONFIG_ISDN_AUDIO
  25. #include "isdn_audio.h"
  26. #endif
  27. #ifdef CONFIG_ISDN_DIVERSION_MODULE
  28. #define CONFIG_ISDN_DIVERSION
  29. #endif
  30. #ifdef CONFIG_ISDN_DIVERSION
  31. #include <linux/isdn_divertif.h>
  32. #endif /* CONFIG_ISDN_DIVERSION */
  33. #include "isdn_v110.h"
  34. /* Debugflags */
  35. #undef ISDN_DEBUG_STATCALLB
  36. MODULE_DESCRIPTION("ISDN4Linux: link layer");
  37. MODULE_AUTHOR("Fritz Elfert");
  38. MODULE_LICENSE("GPL");
  39. isdn_dev *dev;
  40. static DEFINE_MUTEX(isdn_mutex);
  41. static char *isdn_revision = "$Revision: 1.1.2.3 $";
  42. extern char *isdn_net_revision;
  43. #ifdef CONFIG_ISDN_PPP
  44. extern char *isdn_ppp_revision;
  45. #else
  46. static char *isdn_ppp_revision = ": none $";
  47. #endif
  48. #ifdef CONFIG_ISDN_AUDIO
  49. extern char *isdn_audio_revision;
  50. #else
  51. static char *isdn_audio_revision = ": none $";
  52. #endif
  53. extern char *isdn_v110_revision;
  54. #ifdef CONFIG_ISDN_DIVERSION
  55. static isdn_divert_if *divert_if; /* = NULL */
  56. #endif /* CONFIG_ISDN_DIVERSION */
  57. static int isdn_writebuf_stub(int, int, const u_char __user *, int);
  58. static void set_global_features(void);
  59. static int isdn_wildmat(char *s, char *p);
  60. static int isdn_add_channels(isdn_driver_t *d, int drvidx, int n, int adding);
  61. static inline void
  62. isdn_lock_driver(isdn_driver_t *drv)
  63. {
  64. try_module_get(drv->interface->owner);
  65. drv->locks++;
  66. }
  67. void
  68. isdn_lock_drivers(void)
  69. {
  70. int i;
  71. for (i = 0; i < ISDN_MAX_DRIVERS; i++) {
  72. if (!dev->drv[i])
  73. continue;
  74. isdn_lock_driver(dev->drv[i]);
  75. }
  76. }
  77. static inline void
  78. isdn_unlock_driver(isdn_driver_t *drv)
  79. {
  80. if (drv->locks > 0) {
  81. drv->locks--;
  82. module_put(drv->interface->owner);
  83. }
  84. }
  85. void
  86. isdn_unlock_drivers(void)
  87. {
  88. int i;
  89. for (i = 0; i < ISDN_MAX_DRIVERS; i++) {
  90. if (!dev->drv[i])
  91. continue;
  92. isdn_unlock_driver(dev->drv[i]);
  93. }
  94. }
  95. #if defined(ISDN_DEBUG_NET_DUMP) || defined(ISDN_DEBUG_MODEM_DUMP)
  96. void
  97. isdn_dumppkt(char *s, u_char *p, int len, int dumplen)
  98. {
  99. int dumpc;
  100. printk(KERN_DEBUG "%s(%d) ", s, len);
  101. for (dumpc = 0; (dumpc < dumplen) && (len); len--, dumpc++)
  102. printk(" %02x", *p++);
  103. printk("\n");
  104. }
  105. #endif
  106. /*
  107. * I picked the pattern-matching-functions from an old GNU-tar version (1.10)
  108. * It was originally written and put to PD by rs@mirror.TMC.COM (Rich Salz)
  109. */
  110. static int
  111. isdn_star(char *s, char *p)
  112. {
  113. while (isdn_wildmat(s, p)) {
  114. if (*++s == '\0')
  115. return (2);
  116. }
  117. return (0);
  118. }
  119. /*
  120. * Shell-type Pattern-matching for incoming caller-Ids
  121. * This function gets a string in s and checks, if it matches the pattern
  122. * given in p.
  123. *
  124. * Return:
  125. * 0 = match.
  126. * 1 = no match.
  127. * 2 = no match. Would eventually match, if s would be longer.
  128. *
  129. * Possible Patterns:
  130. *
  131. * '?' matches one character
  132. * '*' matches zero or more characters
  133. * [xyz] matches the set of characters in brackets.
  134. * [^xyz] matches any single character not in the set of characters
  135. */
  136. static int
  137. isdn_wildmat(char *s, char *p)
  138. {
  139. register int last;
  140. register int matched;
  141. register int reverse;
  142. register int nostar = 1;
  143. if (!(*s) && !(*p))
  144. return (1);
  145. for (; *p; s++, p++)
  146. switch (*p) {
  147. case '\\':
  148. /*
  149. * Literal match with following character,
  150. * fall through.
  151. */
  152. p++;
  153. default:
  154. if (*s != *p)
  155. return (*s == '\0') ? 2 : 1;
  156. continue;
  157. case '?':
  158. /* Match anything. */
  159. if (*s == '\0')
  160. return (2);
  161. continue;
  162. case '*':
  163. nostar = 0;
  164. /* Trailing star matches everything. */
  165. return (*++p ? isdn_star(s, p) : 0);
  166. case '[':
  167. /* [^....] means inverse character class. */
  168. if ((reverse = (p[1] == '^')))
  169. p++;
  170. for (last = 0, matched = 0; *++p && (*p != ']'); last = *p)
  171. /* This next line requires a good C compiler. */
  172. if (*p == '-' ? *s <= *++p && *s >= last : *s == *p)
  173. matched = 1;
  174. if (matched == reverse)
  175. return (1);
  176. continue;
  177. }
  178. return (*s == '\0') ? 0 : nostar;
  179. }
  180. int isdn_msncmp(const char *msn1, const char *msn2)
  181. {
  182. char TmpMsn1[ISDN_MSNLEN];
  183. char TmpMsn2[ISDN_MSNLEN];
  184. char *p;
  185. for (p = TmpMsn1; *msn1 && *msn1 != ':';) // Strip off a SPID
  186. *p++ = *msn1++;
  187. *p = '\0';
  188. for (p = TmpMsn2; *msn2 && *msn2 != ':';) // Strip off a SPID
  189. *p++ = *msn2++;
  190. *p = '\0';
  191. return isdn_wildmat(TmpMsn1, TmpMsn2);
  192. }
  193. int
  194. isdn_dc2minor(int di, int ch)
  195. {
  196. int i;
  197. for (i = 0; i < ISDN_MAX_CHANNELS; i++)
  198. if (dev->chanmap[i] == ch && dev->drvmap[i] == di)
  199. return i;
  200. return -1;
  201. }
  202. static int isdn_timer_cnt1 = 0;
  203. static int isdn_timer_cnt2 = 0;
  204. static int isdn_timer_cnt3 = 0;
  205. static void
  206. isdn_timer_funct(ulong dummy)
  207. {
  208. int tf = dev->tflags;
  209. if (tf & ISDN_TIMER_FAST) {
  210. if (tf & ISDN_TIMER_MODEMREAD)
  211. isdn_tty_readmodem();
  212. if (tf & ISDN_TIMER_MODEMPLUS)
  213. isdn_tty_modem_escape();
  214. if (tf & ISDN_TIMER_MODEMXMIT)
  215. isdn_tty_modem_xmit();
  216. }
  217. if (tf & ISDN_TIMER_SLOW) {
  218. if (++isdn_timer_cnt1 >= ISDN_TIMER_02SEC) {
  219. isdn_timer_cnt1 = 0;
  220. if (tf & ISDN_TIMER_NETDIAL)
  221. isdn_net_dial();
  222. }
  223. if (++isdn_timer_cnt2 >= ISDN_TIMER_1SEC) {
  224. isdn_timer_cnt2 = 0;
  225. if (tf & ISDN_TIMER_NETHANGUP)
  226. isdn_net_autohup();
  227. if (++isdn_timer_cnt3 >= ISDN_TIMER_RINGING) {
  228. isdn_timer_cnt3 = 0;
  229. if (tf & ISDN_TIMER_MODEMRING)
  230. isdn_tty_modem_ring();
  231. }
  232. if (tf & ISDN_TIMER_CARRIER)
  233. isdn_tty_carrier_timeout();
  234. }
  235. }
  236. if (tf)
  237. mod_timer(&dev->timer, jiffies + ISDN_TIMER_RES);
  238. }
  239. void
  240. isdn_timer_ctrl(int tf, int onoff)
  241. {
  242. unsigned long flags;
  243. int old_tflags;
  244. spin_lock_irqsave(&dev->timerlock, flags);
  245. if ((tf & ISDN_TIMER_SLOW) && (!(dev->tflags & ISDN_TIMER_SLOW))) {
  246. /* If the slow-timer wasn't activated until now */
  247. isdn_timer_cnt1 = 0;
  248. isdn_timer_cnt2 = 0;
  249. }
  250. old_tflags = dev->tflags;
  251. if (onoff)
  252. dev->tflags |= tf;
  253. else
  254. dev->tflags &= ~tf;
  255. if (dev->tflags && !old_tflags)
  256. mod_timer(&dev->timer, jiffies + ISDN_TIMER_RES);
  257. spin_unlock_irqrestore(&dev->timerlock, flags);
  258. }
  259. /*
  260. * Receive a packet from B-Channel. (Called from low-level-module)
  261. */
  262. static void
  263. isdn_receive_skb_callback(int di, int channel, struct sk_buff *skb)
  264. {
  265. int i;
  266. if ((i = isdn_dc2minor(di, channel)) == -1) {
  267. dev_kfree_skb(skb);
  268. return;
  269. }
  270. /* Update statistics */
  271. dev->ibytes[i] += skb->len;
  272. /* First, try to deliver data to network-device */
  273. if (isdn_net_rcv_skb(i, skb))
  274. return;
  275. /* V.110 handling
  276. * makes sense for async streams only, so it is
  277. * called after possible net-device delivery.
  278. */
  279. if (dev->v110[i]) {
  280. atomic_inc(&dev->v110use[i]);
  281. skb = isdn_v110_decode(dev->v110[i], skb);
  282. atomic_dec(&dev->v110use[i]);
  283. if (!skb)
  284. return;
  285. }
  286. /* No network-device found, deliver to tty or raw-channel */
  287. if (skb->len) {
  288. if (isdn_tty_rcv_skb(i, di, channel, skb))
  289. return;
  290. wake_up_interruptible(&dev->drv[di]->rcv_waitq[channel]);
  291. } else
  292. dev_kfree_skb(skb);
  293. }
  294. /*
  295. * Intercept command from Linklevel to Lowlevel.
  296. * If layer 2 protocol is V.110 and this is not supported by current
  297. * lowlevel-driver, use driver's transparent mode and handle V.110 in
  298. * linklevel instead.
  299. */
  300. int
  301. isdn_command(isdn_ctrl *cmd)
  302. {
  303. if (cmd->driver == -1) {
  304. printk(KERN_WARNING "isdn_command command(%x) driver -1\n", cmd->command);
  305. return (1);
  306. }
  307. if (!dev->drv[cmd->driver]) {
  308. printk(KERN_WARNING "isdn_command command(%x) dev->drv[%d] NULL\n",
  309. cmd->command, cmd->driver);
  310. return (1);
  311. }
  312. if (!dev->drv[cmd->driver]->interface) {
  313. printk(KERN_WARNING "isdn_command command(%x) dev->drv[%d]->interface NULL\n",
  314. cmd->command, cmd->driver);
  315. return (1);
  316. }
  317. if (cmd->command == ISDN_CMD_SETL2) {
  318. int idx = isdn_dc2minor(cmd->driver, cmd->arg & 255);
  319. unsigned long l2prot = (cmd->arg >> 8) & 255;
  320. unsigned long features = (dev->drv[cmd->driver]->interface->features
  321. >> ISDN_FEATURE_L2_SHIFT) &
  322. ISDN_FEATURE_L2_MASK;
  323. unsigned long l2_feature = (1 << l2prot);
  324. switch (l2prot) {
  325. case ISDN_PROTO_L2_V11096:
  326. case ISDN_PROTO_L2_V11019:
  327. case ISDN_PROTO_L2_V11038:
  328. /* If V.110 requested, but not supported by
  329. * HL-driver, set emulator-flag and change
  330. * Layer-2 to transparent
  331. */
  332. if (!(features & l2_feature)) {
  333. dev->v110emu[idx] = l2prot;
  334. cmd->arg = (cmd->arg & 255) |
  335. (ISDN_PROTO_L2_TRANS << 8);
  336. } else
  337. dev->v110emu[idx] = 0;
  338. }
  339. }
  340. return dev->drv[cmd->driver]->interface->command(cmd);
  341. }
  342. void
  343. isdn_all_eaz(int di, int ch)
  344. {
  345. isdn_ctrl cmd;
  346. if (di < 0)
  347. return;
  348. cmd.driver = di;
  349. cmd.arg = ch;
  350. cmd.command = ISDN_CMD_SETEAZ;
  351. cmd.parm.num[0] = '\0';
  352. isdn_command(&cmd);
  353. }
  354. /*
  355. * Begin of a CAPI like LL<->HL interface, currently used only for
  356. * supplementary service (CAPI 2.0 part III)
  357. */
  358. #include <linux/isdn/capicmd.h>
  359. static int
  360. isdn_capi_rec_hl_msg(capi_msg *cm)
  361. {
  362. switch (cm->Command) {
  363. case CAPI_FACILITY:
  364. /* in the moment only handled in tty */
  365. return (isdn_tty_capi_facility(cm));
  366. default:
  367. return (-1);
  368. }
  369. }
  370. static int
  371. isdn_status_callback(isdn_ctrl *c)
  372. {
  373. int di;
  374. u_long flags;
  375. int i;
  376. int r;
  377. int retval = 0;
  378. isdn_ctrl cmd;
  379. isdn_net_dev *p;
  380. di = c->driver;
  381. i = isdn_dc2minor(di, c->arg);
  382. switch (c->command) {
  383. case ISDN_STAT_BSENT:
  384. if (i < 0)
  385. return -1;
  386. if (dev->global_flags & ISDN_GLOBAL_STOPPED)
  387. return 0;
  388. if (isdn_net_stat_callback(i, c))
  389. return 0;
  390. if (isdn_v110_stat_callback(i, c))
  391. return 0;
  392. if (isdn_tty_stat_callback(i, c))
  393. return 0;
  394. wake_up_interruptible(&dev->drv[di]->snd_waitq[c->arg]);
  395. break;
  396. case ISDN_STAT_STAVAIL:
  397. dev->drv[di]->stavail += c->arg;
  398. wake_up_interruptible(&dev->drv[di]->st_waitq);
  399. break;
  400. case ISDN_STAT_RUN:
  401. dev->drv[di]->flags |= DRV_FLAG_RUNNING;
  402. for (i = 0; i < ISDN_MAX_CHANNELS; i++)
  403. if (dev->drvmap[i] == di)
  404. isdn_all_eaz(di, dev->chanmap[i]);
  405. set_global_features();
  406. break;
  407. case ISDN_STAT_STOP:
  408. dev->drv[di]->flags &= ~DRV_FLAG_RUNNING;
  409. break;
  410. case ISDN_STAT_ICALL:
  411. if (i < 0)
  412. return -1;
  413. #ifdef ISDN_DEBUG_STATCALLB
  414. printk(KERN_DEBUG "ICALL (net): %d %ld %s\n", di, c->arg, c->parm.num);
  415. #endif
  416. if (dev->global_flags & ISDN_GLOBAL_STOPPED) {
  417. cmd.driver = di;
  418. cmd.arg = c->arg;
  419. cmd.command = ISDN_CMD_HANGUP;
  420. isdn_command(&cmd);
  421. return 0;
  422. }
  423. /* Try to find a network-interface which will accept incoming call */
  424. r = ((c->command == ISDN_STAT_ICALLW) ? 0 : isdn_net_find_icall(di, c->arg, i, &c->parm.setup));
  425. switch (r) {
  426. case 0:
  427. /* No network-device replies.
  428. * Try ttyI's.
  429. * These return 0 on no match, 1 on match and
  430. * 3 on eventually match, if CID is longer.
  431. */
  432. if (c->command == ISDN_STAT_ICALL)
  433. if ((retval = isdn_tty_find_icall(di, c->arg, &c->parm.setup))) return (retval);
  434. #ifdef CONFIG_ISDN_DIVERSION
  435. if (divert_if)
  436. if ((retval = divert_if->stat_callback(c)))
  437. return (retval); /* processed */
  438. #endif /* CONFIG_ISDN_DIVERSION */
  439. if ((!retval) && (dev->drv[di]->flags & DRV_FLAG_REJBUS)) {
  440. /* No tty responding */
  441. cmd.driver = di;
  442. cmd.arg = c->arg;
  443. cmd.command = ISDN_CMD_HANGUP;
  444. isdn_command(&cmd);
  445. retval = 2;
  446. }
  447. break;
  448. case 1:
  449. /* Schedule connection-setup */
  450. isdn_net_dial();
  451. cmd.driver = di;
  452. cmd.arg = c->arg;
  453. cmd.command = ISDN_CMD_ACCEPTD;
  454. for (p = dev->netdev; p; p = p->next)
  455. if (p->local->isdn_channel == cmd.arg)
  456. {
  457. strcpy(cmd.parm.setup.eazmsn, p->local->msn);
  458. isdn_command(&cmd);
  459. retval = 1;
  460. break;
  461. }
  462. break;
  463. case 2: /* For calling back, first reject incoming call ... */
  464. case 3: /* Interface found, but down, reject call actively */
  465. retval = 2;
  466. printk(KERN_INFO "isdn: Rejecting Call\n");
  467. cmd.driver = di;
  468. cmd.arg = c->arg;
  469. cmd.command = ISDN_CMD_HANGUP;
  470. isdn_command(&cmd);
  471. if (r == 3)
  472. break;
  473. /* Fall through */
  474. case 4:
  475. /* ... then start callback. */
  476. isdn_net_dial();
  477. break;
  478. case 5:
  479. /* Number would eventually match, if longer */
  480. retval = 3;
  481. break;
  482. }
  483. #ifdef ISDN_DEBUG_STATCALLB
  484. printk(KERN_DEBUG "ICALL: ret=%d\n", retval);
  485. #endif
  486. return retval;
  487. break;
  488. case ISDN_STAT_CINF:
  489. if (i < 0)
  490. return -1;
  491. #ifdef ISDN_DEBUG_STATCALLB
  492. printk(KERN_DEBUG "CINF: %ld %s\n", c->arg, c->parm.num);
  493. #endif
  494. if (dev->global_flags & ISDN_GLOBAL_STOPPED)
  495. return 0;
  496. if (strcmp(c->parm.num, "0"))
  497. isdn_net_stat_callback(i, c);
  498. isdn_tty_stat_callback(i, c);
  499. break;
  500. case ISDN_STAT_CAUSE:
  501. #ifdef ISDN_DEBUG_STATCALLB
  502. printk(KERN_DEBUG "CAUSE: %ld %s\n", c->arg, c->parm.num);
  503. #endif
  504. printk(KERN_INFO "isdn: %s,ch%ld cause: %s\n",
  505. dev->drvid[di], c->arg, c->parm.num);
  506. isdn_tty_stat_callback(i, c);
  507. #ifdef CONFIG_ISDN_DIVERSION
  508. if (divert_if)
  509. divert_if->stat_callback(c);
  510. #endif /* CONFIG_ISDN_DIVERSION */
  511. break;
  512. case ISDN_STAT_DISPLAY:
  513. #ifdef ISDN_DEBUG_STATCALLB
  514. printk(KERN_DEBUG "DISPLAY: %ld %s\n", c->arg, c->parm.display);
  515. #endif
  516. isdn_tty_stat_callback(i, c);
  517. #ifdef CONFIG_ISDN_DIVERSION
  518. if (divert_if)
  519. divert_if->stat_callback(c);
  520. #endif /* CONFIG_ISDN_DIVERSION */
  521. break;
  522. case ISDN_STAT_DCONN:
  523. if (i < 0)
  524. return -1;
  525. #ifdef ISDN_DEBUG_STATCALLB
  526. printk(KERN_DEBUG "DCONN: %ld\n", c->arg);
  527. #endif
  528. if (dev->global_flags & ISDN_GLOBAL_STOPPED)
  529. return 0;
  530. /* Find any net-device, waiting for D-channel setup */
  531. if (isdn_net_stat_callback(i, c))
  532. break;
  533. isdn_v110_stat_callback(i, c);
  534. /* Find any ttyI, waiting for D-channel setup */
  535. if (isdn_tty_stat_callback(i, c)) {
  536. cmd.driver = di;
  537. cmd.arg = c->arg;
  538. cmd.command = ISDN_CMD_ACCEPTB;
  539. isdn_command(&cmd);
  540. break;
  541. }
  542. break;
  543. case ISDN_STAT_DHUP:
  544. if (i < 0)
  545. return -1;
  546. #ifdef ISDN_DEBUG_STATCALLB
  547. printk(KERN_DEBUG "DHUP: %ld\n", c->arg);
  548. #endif
  549. if (dev->global_flags & ISDN_GLOBAL_STOPPED)
  550. return 0;
  551. dev->drv[di]->online &= ~(1 << (c->arg));
  552. isdn_info_update();
  553. /* Signal hangup to network-devices */
  554. if (isdn_net_stat_callback(i, c))
  555. break;
  556. isdn_v110_stat_callback(i, c);
  557. if (isdn_tty_stat_callback(i, c))
  558. break;
  559. #ifdef CONFIG_ISDN_DIVERSION
  560. if (divert_if)
  561. divert_if->stat_callback(c);
  562. #endif /* CONFIG_ISDN_DIVERSION */
  563. break;
  564. break;
  565. case ISDN_STAT_BCONN:
  566. if (i < 0)
  567. return -1;
  568. #ifdef ISDN_DEBUG_STATCALLB
  569. printk(KERN_DEBUG "BCONN: %ld\n", c->arg);
  570. #endif
  571. /* Signal B-channel-connect to network-devices */
  572. if (dev->global_flags & ISDN_GLOBAL_STOPPED)
  573. return 0;
  574. dev->drv[di]->online |= (1 << (c->arg));
  575. isdn_info_update();
  576. if (isdn_net_stat_callback(i, c))
  577. break;
  578. isdn_v110_stat_callback(i, c);
  579. if (isdn_tty_stat_callback(i, c))
  580. break;
  581. break;
  582. case ISDN_STAT_BHUP:
  583. if (i < 0)
  584. return -1;
  585. #ifdef ISDN_DEBUG_STATCALLB
  586. printk(KERN_DEBUG "BHUP: %ld\n", c->arg);
  587. #endif
  588. if (dev->global_flags & ISDN_GLOBAL_STOPPED)
  589. return 0;
  590. dev->drv[di]->online &= ~(1 << (c->arg));
  591. isdn_info_update();
  592. #ifdef CONFIG_ISDN_X25
  593. /* Signal hangup to network-devices */
  594. if (isdn_net_stat_callback(i, c))
  595. break;
  596. #endif
  597. isdn_v110_stat_callback(i, c);
  598. if (isdn_tty_stat_callback(i, c))
  599. break;
  600. break;
  601. case ISDN_STAT_NODCH:
  602. if (i < 0)
  603. return -1;
  604. #ifdef ISDN_DEBUG_STATCALLB
  605. printk(KERN_DEBUG "NODCH: %ld\n", c->arg);
  606. #endif
  607. if (dev->global_flags & ISDN_GLOBAL_STOPPED)
  608. return 0;
  609. if (isdn_net_stat_callback(i, c))
  610. break;
  611. if (isdn_tty_stat_callback(i, c))
  612. break;
  613. break;
  614. case ISDN_STAT_ADDCH:
  615. spin_lock_irqsave(&dev->lock, flags);
  616. if (isdn_add_channels(dev->drv[di], di, c->arg, 1)) {
  617. spin_unlock_irqrestore(&dev->lock, flags);
  618. return -1;
  619. }
  620. spin_unlock_irqrestore(&dev->lock, flags);
  621. isdn_info_update();
  622. break;
  623. case ISDN_STAT_DISCH:
  624. spin_lock_irqsave(&dev->lock, flags);
  625. for (i = 0; i < ISDN_MAX_CHANNELS; i++)
  626. if ((dev->drvmap[i] == di) &&
  627. (dev->chanmap[i] == c->arg)) {
  628. if (c->parm.num[0])
  629. dev->usage[i] &= ~ISDN_USAGE_DISABLED;
  630. else
  631. if (USG_NONE(dev->usage[i])) {
  632. dev->usage[i] |= ISDN_USAGE_DISABLED;
  633. }
  634. else
  635. retval = -1;
  636. break;
  637. }
  638. spin_unlock_irqrestore(&dev->lock, flags);
  639. isdn_info_update();
  640. break;
  641. case ISDN_STAT_UNLOAD:
  642. while (dev->drv[di]->locks > 0) {
  643. isdn_unlock_driver(dev->drv[di]);
  644. }
  645. spin_lock_irqsave(&dev->lock, flags);
  646. isdn_tty_stat_callback(i, c);
  647. for (i = 0; i < ISDN_MAX_CHANNELS; i++)
  648. if (dev->drvmap[i] == di) {
  649. dev->drvmap[i] = -1;
  650. dev->chanmap[i] = -1;
  651. dev->usage[i] &= ~ISDN_USAGE_DISABLED;
  652. }
  653. dev->drivers--;
  654. dev->channels -= dev->drv[di]->channels;
  655. kfree(dev->drv[di]->rcverr);
  656. kfree(dev->drv[di]->rcvcount);
  657. for (i = 0; i < dev->drv[di]->channels; i++)
  658. skb_queue_purge(&dev->drv[di]->rpqueue[i]);
  659. kfree(dev->drv[di]->rpqueue);
  660. kfree(dev->drv[di]->rcv_waitq);
  661. kfree(dev->drv[di]);
  662. dev->drv[di] = NULL;
  663. dev->drvid[di][0] = '\0';
  664. isdn_info_update();
  665. set_global_features();
  666. spin_unlock_irqrestore(&dev->lock, flags);
  667. return 0;
  668. case ISDN_STAT_L1ERR:
  669. break;
  670. case CAPI_PUT_MESSAGE:
  671. return (isdn_capi_rec_hl_msg(&c->parm.cmsg));
  672. #ifdef CONFIG_ISDN_TTY_FAX
  673. case ISDN_STAT_FAXIND:
  674. isdn_tty_stat_callback(i, c);
  675. break;
  676. #endif
  677. #ifdef CONFIG_ISDN_AUDIO
  678. case ISDN_STAT_AUDIO:
  679. isdn_tty_stat_callback(i, c);
  680. break;
  681. #endif
  682. #ifdef CONFIG_ISDN_DIVERSION
  683. case ISDN_STAT_PROT:
  684. case ISDN_STAT_REDIR:
  685. if (divert_if)
  686. return (divert_if->stat_callback(c));
  687. #endif /* CONFIG_ISDN_DIVERSION */
  688. default:
  689. return -1;
  690. }
  691. return 0;
  692. }
  693. /*
  694. * Get integer from char-pointer, set pointer to end of number
  695. */
  696. int
  697. isdn_getnum(char **p)
  698. {
  699. int v = -1;
  700. while (*p[0] >= '0' && *p[0] <= '9')
  701. v = ((v < 0) ? 0 : (v * 10)) + (int) ((*p[0]++) - '0');
  702. return v;
  703. }
  704. #define DLE 0x10
  705. /*
  706. * isdn_readbchan() tries to get data from the read-queue.
  707. * It MUST be called with interrupts off.
  708. *
  709. * Be aware that this is not an atomic operation when sleep != 0, even though
  710. * interrupts are turned off! Well, like that we are currently only called
  711. * on behalf of a read system call on raw device files (which are documented
  712. * to be dangerous and for debugging purpose only). The inode semaphore
  713. * takes care that this is not called for the same minor device number while
  714. * we are sleeping, but access is not serialized against simultaneous read()
  715. * from the corresponding ttyI device. Can other ugly events, like changes
  716. * of the mapping (di,ch)<->minor, happen during the sleep? --he
  717. */
  718. int
  719. isdn_readbchan(int di, int channel, u_char *buf, u_char *fp, int len, wait_queue_head_t *sleep)
  720. {
  721. int count;
  722. int count_pull;
  723. int count_put;
  724. int dflag;
  725. struct sk_buff *skb;
  726. u_char *cp;
  727. if (!dev->drv[di])
  728. return 0;
  729. if (skb_queue_empty(&dev->drv[di]->rpqueue[channel])) {
  730. if (sleep)
  731. interruptible_sleep_on(sleep);
  732. else
  733. return 0;
  734. }
  735. if (len > dev->drv[di]->rcvcount[channel])
  736. len = dev->drv[di]->rcvcount[channel];
  737. cp = buf;
  738. count = 0;
  739. while (len) {
  740. if (!(skb = skb_peek(&dev->drv[di]->rpqueue[channel])))
  741. break;
  742. #ifdef CONFIG_ISDN_AUDIO
  743. if (ISDN_AUDIO_SKB_LOCK(skb))
  744. break;
  745. ISDN_AUDIO_SKB_LOCK(skb) = 1;
  746. if ((ISDN_AUDIO_SKB_DLECOUNT(skb)) || (dev->drv[di]->DLEflag & (1 << channel))) {
  747. char *p = skb->data;
  748. unsigned long DLEmask = (1 << channel);
  749. dflag = 0;
  750. count_pull = count_put = 0;
  751. while ((count_pull < skb->len) && (len > 0)) {
  752. len--;
  753. if (dev->drv[di]->DLEflag & DLEmask) {
  754. *cp++ = DLE;
  755. dev->drv[di]->DLEflag &= ~DLEmask;
  756. } else {
  757. *cp++ = *p;
  758. if (*p == DLE) {
  759. dev->drv[di]->DLEflag |= DLEmask;
  760. (ISDN_AUDIO_SKB_DLECOUNT(skb))--;
  761. }
  762. p++;
  763. count_pull++;
  764. }
  765. count_put++;
  766. }
  767. if (count_pull >= skb->len)
  768. dflag = 1;
  769. } else {
  770. #endif
  771. /* No DLE's in buff, so simply copy it */
  772. dflag = 1;
  773. if ((count_pull = skb->len) > len) {
  774. count_pull = len;
  775. dflag = 0;
  776. }
  777. count_put = count_pull;
  778. skb_copy_from_linear_data(skb, cp, count_put);
  779. cp += count_put;
  780. len -= count_put;
  781. #ifdef CONFIG_ISDN_AUDIO
  782. }
  783. #endif
  784. count += count_put;
  785. if (fp) {
  786. memset(fp, 0, count_put);
  787. fp += count_put;
  788. }
  789. if (dflag) {
  790. /* We got all the data in this buff.
  791. * Now we can dequeue it.
  792. */
  793. if (fp)
  794. *(fp - 1) = 0xff;
  795. #ifdef CONFIG_ISDN_AUDIO
  796. ISDN_AUDIO_SKB_LOCK(skb) = 0;
  797. #endif
  798. skb = skb_dequeue(&dev->drv[di]->rpqueue[channel]);
  799. dev_kfree_skb(skb);
  800. } else {
  801. /* Not yet emptied this buff, so it
  802. * must stay in the queue, for further calls
  803. * but we pull off the data we got until now.
  804. */
  805. skb_pull(skb, count_pull);
  806. #ifdef CONFIG_ISDN_AUDIO
  807. ISDN_AUDIO_SKB_LOCK(skb) = 0;
  808. #endif
  809. }
  810. dev->drv[di]->rcvcount[channel] -= count_put;
  811. }
  812. return count;
  813. }
  814. /*
  815. * isdn_readbchan_tty() tries to get data from the read-queue.
  816. * It MUST be called with interrupts off.
  817. *
  818. * Be aware that this is not an atomic operation when sleep != 0, even though
  819. * interrupts are turned off! Well, like that we are currently only called
  820. * on behalf of a read system call on raw device files (which are documented
  821. * to be dangerous and for debugging purpose only). The inode semaphore
  822. * takes care that this is not called for the same minor device number while
  823. * we are sleeping, but access is not serialized against simultaneous read()
  824. * from the corresponding ttyI device. Can other ugly events, like changes
  825. * of the mapping (di,ch)<->minor, happen during the sleep? --he
  826. */
  827. int
  828. isdn_readbchan_tty(int di, int channel, struct tty_port *port, int cisco_hack)
  829. {
  830. int count;
  831. int count_pull;
  832. int count_put;
  833. int dflag;
  834. struct sk_buff *skb;
  835. char last = 0;
  836. int len;
  837. if (!dev->drv[di])
  838. return 0;
  839. if (skb_queue_empty(&dev->drv[di]->rpqueue[channel]))
  840. return 0;
  841. len = tty_buffer_request_room(port, dev->drv[di]->rcvcount[channel]);
  842. if (len == 0)
  843. return len;
  844. count = 0;
  845. while (len) {
  846. if (!(skb = skb_peek(&dev->drv[di]->rpqueue[channel])))
  847. break;
  848. #ifdef CONFIG_ISDN_AUDIO
  849. if (ISDN_AUDIO_SKB_LOCK(skb))
  850. break;
  851. ISDN_AUDIO_SKB_LOCK(skb) = 1;
  852. if ((ISDN_AUDIO_SKB_DLECOUNT(skb)) || (dev->drv[di]->DLEflag & (1 << channel))) {
  853. char *p = skb->data;
  854. unsigned long DLEmask = (1 << channel);
  855. dflag = 0;
  856. count_pull = count_put = 0;
  857. while ((count_pull < skb->len) && (len > 0)) {
  858. /* push every character but the last to the tty buffer directly */
  859. if (count_put)
  860. tty_insert_flip_char(port, last, TTY_NORMAL);
  861. len--;
  862. if (dev->drv[di]->DLEflag & DLEmask) {
  863. last = DLE;
  864. dev->drv[di]->DLEflag &= ~DLEmask;
  865. } else {
  866. last = *p;
  867. if (last == DLE) {
  868. dev->drv[di]->DLEflag |= DLEmask;
  869. (ISDN_AUDIO_SKB_DLECOUNT(skb))--;
  870. }
  871. p++;
  872. count_pull++;
  873. }
  874. count_put++;
  875. }
  876. if (count_pull >= skb->len)
  877. dflag = 1;
  878. } else {
  879. #endif
  880. /* No DLE's in buff, so simply copy it */
  881. dflag = 1;
  882. if ((count_pull = skb->len) > len) {
  883. count_pull = len;
  884. dflag = 0;
  885. }
  886. count_put = count_pull;
  887. if (count_put > 1)
  888. tty_insert_flip_string(port, skb->data, count_put - 1);
  889. last = skb->data[count_put - 1];
  890. len -= count_put;
  891. #ifdef CONFIG_ISDN_AUDIO
  892. }
  893. #endif
  894. count += count_put;
  895. if (dflag) {
  896. /* We got all the data in this buff.
  897. * Now we can dequeue it.
  898. */
  899. if (cisco_hack)
  900. tty_insert_flip_char(port, last, 0xFF);
  901. else
  902. tty_insert_flip_char(port, last, TTY_NORMAL);
  903. #ifdef CONFIG_ISDN_AUDIO
  904. ISDN_AUDIO_SKB_LOCK(skb) = 0;
  905. #endif
  906. skb = skb_dequeue(&dev->drv[di]->rpqueue[channel]);
  907. dev_kfree_skb(skb);
  908. } else {
  909. tty_insert_flip_char(port, last, TTY_NORMAL);
  910. /* Not yet emptied this buff, so it
  911. * must stay in the queue, for further calls
  912. * but we pull off the data we got until now.
  913. */
  914. skb_pull(skb, count_pull);
  915. #ifdef CONFIG_ISDN_AUDIO
  916. ISDN_AUDIO_SKB_LOCK(skb) = 0;
  917. #endif
  918. }
  919. dev->drv[di]->rcvcount[channel] -= count_put;
  920. }
  921. return count;
  922. }
  923. static inline int
  924. isdn_minor2drv(int minor)
  925. {
  926. return (dev->drvmap[minor]);
  927. }
  928. static inline int
  929. isdn_minor2chan(int minor)
  930. {
  931. return (dev->chanmap[minor]);
  932. }
  933. static char *
  934. isdn_statstr(void)
  935. {
  936. static char istatbuf[2048];
  937. char *p;
  938. int i;
  939. sprintf(istatbuf, "idmap:\t");
  940. p = istatbuf + strlen(istatbuf);
  941. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  942. sprintf(p, "%s ", (dev->drvmap[i] < 0) ? "-" : dev->drvid[dev->drvmap[i]]);
  943. p = istatbuf + strlen(istatbuf);
  944. }
  945. sprintf(p, "\nchmap:\t");
  946. p = istatbuf + strlen(istatbuf);
  947. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  948. sprintf(p, "%d ", dev->chanmap[i]);
  949. p = istatbuf + strlen(istatbuf);
  950. }
  951. sprintf(p, "\ndrmap:\t");
  952. p = istatbuf + strlen(istatbuf);
  953. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  954. sprintf(p, "%d ", dev->drvmap[i]);
  955. p = istatbuf + strlen(istatbuf);
  956. }
  957. sprintf(p, "\nusage:\t");
  958. p = istatbuf + strlen(istatbuf);
  959. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  960. sprintf(p, "%d ", dev->usage[i]);
  961. p = istatbuf + strlen(istatbuf);
  962. }
  963. sprintf(p, "\nflags:\t");
  964. p = istatbuf + strlen(istatbuf);
  965. for (i = 0; i < ISDN_MAX_DRIVERS; i++) {
  966. if (dev->drv[i]) {
  967. sprintf(p, "%ld ", dev->drv[i]->online);
  968. p = istatbuf + strlen(istatbuf);
  969. } else {
  970. sprintf(p, "? ");
  971. p = istatbuf + strlen(istatbuf);
  972. }
  973. }
  974. sprintf(p, "\nphone:\t");
  975. p = istatbuf + strlen(istatbuf);
  976. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  977. sprintf(p, "%s ", dev->num[i]);
  978. p = istatbuf + strlen(istatbuf);
  979. }
  980. sprintf(p, "\n");
  981. return istatbuf;
  982. }
  983. /* Module interface-code */
  984. void
  985. isdn_info_update(void)
  986. {
  987. infostruct *p = dev->infochain;
  988. while (p) {
  989. *(p->private) = 1;
  990. p = (infostruct *) p->next;
  991. }
  992. wake_up_interruptible(&(dev->info_waitq));
  993. }
  994. static ssize_t
  995. isdn_read(struct file *file, char __user *buf, size_t count, loff_t *off)
  996. {
  997. uint minor = iminor(file_inode(file));
  998. int len = 0;
  999. int drvidx;
  1000. int chidx;
  1001. int retval;
  1002. char *p;
  1003. mutex_lock(&isdn_mutex);
  1004. if (minor == ISDN_MINOR_STATUS) {
  1005. if (!file->private_data) {
  1006. if (file->f_flags & O_NONBLOCK) {
  1007. retval = -EAGAIN;
  1008. goto out;
  1009. }
  1010. interruptible_sleep_on(&(dev->info_waitq));
  1011. }
  1012. p = isdn_statstr();
  1013. file->private_data = NULL;
  1014. if ((len = strlen(p)) <= count) {
  1015. if (copy_to_user(buf, p, len)) {
  1016. retval = -EFAULT;
  1017. goto out;
  1018. }
  1019. *off += len;
  1020. retval = len;
  1021. goto out;
  1022. }
  1023. retval = 0;
  1024. goto out;
  1025. }
  1026. if (!dev->drivers) {
  1027. retval = -ENODEV;
  1028. goto out;
  1029. }
  1030. if (minor <= ISDN_MINOR_BMAX) {
  1031. printk(KERN_WARNING "isdn_read minor %d obsolete!\n", minor);
  1032. drvidx = isdn_minor2drv(minor);
  1033. if (drvidx < 0) {
  1034. retval = -ENODEV;
  1035. goto out;
  1036. }
  1037. if (!(dev->drv[drvidx]->flags & DRV_FLAG_RUNNING)) {
  1038. retval = -ENODEV;
  1039. goto out;
  1040. }
  1041. chidx = isdn_minor2chan(minor);
  1042. if (!(p = kmalloc(count, GFP_KERNEL))) {
  1043. retval = -ENOMEM;
  1044. goto out;
  1045. }
  1046. len = isdn_readbchan(drvidx, chidx, p, NULL, count,
  1047. &dev->drv[drvidx]->rcv_waitq[chidx]);
  1048. *off += len;
  1049. if (copy_to_user(buf, p, len))
  1050. len = -EFAULT;
  1051. kfree(p);
  1052. retval = len;
  1053. goto out;
  1054. }
  1055. if (minor <= ISDN_MINOR_CTRLMAX) {
  1056. drvidx = isdn_minor2drv(minor - ISDN_MINOR_CTRL);
  1057. if (drvidx < 0) {
  1058. retval = -ENODEV;
  1059. goto out;
  1060. }
  1061. if (!dev->drv[drvidx]->stavail) {
  1062. if (file->f_flags & O_NONBLOCK) {
  1063. retval = -EAGAIN;
  1064. goto out;
  1065. }
  1066. interruptible_sleep_on(&(dev->drv[drvidx]->st_waitq));
  1067. }
  1068. if (dev->drv[drvidx]->interface->readstat) {
  1069. if (count > dev->drv[drvidx]->stavail)
  1070. count = dev->drv[drvidx]->stavail;
  1071. len = dev->drv[drvidx]->interface->readstat(buf, count,
  1072. drvidx, isdn_minor2chan(minor - ISDN_MINOR_CTRL));
  1073. if (len < 0) {
  1074. retval = len;
  1075. goto out;
  1076. }
  1077. } else {
  1078. len = 0;
  1079. }
  1080. if (len)
  1081. dev->drv[drvidx]->stavail -= len;
  1082. else
  1083. dev->drv[drvidx]->stavail = 0;
  1084. *off += len;
  1085. retval = len;
  1086. goto out;
  1087. }
  1088. #ifdef CONFIG_ISDN_PPP
  1089. if (minor <= ISDN_MINOR_PPPMAX) {
  1090. retval = isdn_ppp_read(minor - ISDN_MINOR_PPP, file, buf, count);
  1091. goto out;
  1092. }
  1093. #endif
  1094. retval = -ENODEV;
  1095. out:
  1096. mutex_unlock(&isdn_mutex);
  1097. return retval;
  1098. }
  1099. static ssize_t
  1100. isdn_write(struct file *file, const char __user *buf, size_t count, loff_t *off)
  1101. {
  1102. uint minor = iminor(file_inode(file));
  1103. int drvidx;
  1104. int chidx;
  1105. int retval;
  1106. if (minor == ISDN_MINOR_STATUS)
  1107. return -EPERM;
  1108. if (!dev->drivers)
  1109. return -ENODEV;
  1110. mutex_lock(&isdn_mutex);
  1111. if (minor <= ISDN_MINOR_BMAX) {
  1112. printk(KERN_WARNING "isdn_write minor %d obsolete!\n", minor);
  1113. drvidx = isdn_minor2drv(minor);
  1114. if (drvidx < 0) {
  1115. retval = -ENODEV;
  1116. goto out;
  1117. }
  1118. if (!(dev->drv[drvidx]->flags & DRV_FLAG_RUNNING)) {
  1119. retval = -ENODEV;
  1120. goto out;
  1121. }
  1122. chidx = isdn_minor2chan(minor);
  1123. while ((retval = isdn_writebuf_stub(drvidx, chidx, buf, count)) == 0)
  1124. interruptible_sleep_on(&dev->drv[drvidx]->snd_waitq[chidx]);
  1125. goto out;
  1126. }
  1127. if (minor <= ISDN_MINOR_CTRLMAX) {
  1128. drvidx = isdn_minor2drv(minor - ISDN_MINOR_CTRL);
  1129. if (drvidx < 0) {
  1130. retval = -ENODEV;
  1131. goto out;
  1132. }
  1133. /*
  1134. * We want to use the isdnctrl device to load the firmware
  1135. *
  1136. if (!(dev->drv[drvidx]->flags & DRV_FLAG_RUNNING))
  1137. return -ENODEV;
  1138. */
  1139. if (dev->drv[drvidx]->interface->writecmd)
  1140. retval = dev->drv[drvidx]->interface->
  1141. writecmd(buf, count, drvidx,
  1142. isdn_minor2chan(minor - ISDN_MINOR_CTRL));
  1143. else
  1144. retval = count;
  1145. goto out;
  1146. }
  1147. #ifdef CONFIG_ISDN_PPP
  1148. if (minor <= ISDN_MINOR_PPPMAX) {
  1149. retval = isdn_ppp_write(minor - ISDN_MINOR_PPP, file, buf, count);
  1150. goto out;
  1151. }
  1152. #endif
  1153. retval = -ENODEV;
  1154. out:
  1155. mutex_unlock(&isdn_mutex);
  1156. return retval;
  1157. }
  1158. static unsigned int
  1159. isdn_poll(struct file *file, poll_table *wait)
  1160. {
  1161. unsigned int mask = 0;
  1162. unsigned int minor = iminor(file_inode(file));
  1163. int drvidx = isdn_minor2drv(minor - ISDN_MINOR_CTRL);
  1164. mutex_lock(&isdn_mutex);
  1165. if (minor == ISDN_MINOR_STATUS) {
  1166. poll_wait(file, &(dev->info_waitq), wait);
  1167. /* mask = POLLOUT | POLLWRNORM; */
  1168. if (file->private_data) {
  1169. mask |= POLLIN | POLLRDNORM;
  1170. }
  1171. goto out;
  1172. }
  1173. if (minor >= ISDN_MINOR_CTRL && minor <= ISDN_MINOR_CTRLMAX) {
  1174. if (drvidx < 0) {
  1175. /* driver deregistered while file open */
  1176. mask = POLLHUP;
  1177. goto out;
  1178. }
  1179. poll_wait(file, &(dev->drv[drvidx]->st_waitq), wait);
  1180. mask = POLLOUT | POLLWRNORM;
  1181. if (dev->drv[drvidx]->stavail) {
  1182. mask |= POLLIN | POLLRDNORM;
  1183. }
  1184. goto out;
  1185. }
  1186. #ifdef CONFIG_ISDN_PPP
  1187. if (minor <= ISDN_MINOR_PPPMAX) {
  1188. mask = isdn_ppp_poll(file, wait);
  1189. goto out;
  1190. }
  1191. #endif
  1192. mask = POLLERR;
  1193. out:
  1194. mutex_unlock(&isdn_mutex);
  1195. return mask;
  1196. }
  1197. static int
  1198. isdn_ioctl(struct file *file, uint cmd, ulong arg)
  1199. {
  1200. uint minor = iminor(file_inode(file));
  1201. isdn_ctrl c;
  1202. int drvidx;
  1203. int ret;
  1204. int i;
  1205. char __user *p;
  1206. char *s;
  1207. union iocpar {
  1208. char name[10];
  1209. char bname[22];
  1210. isdn_ioctl_struct iocts;
  1211. isdn_net_ioctl_phone phone;
  1212. isdn_net_ioctl_cfg cfg;
  1213. } iocpar;
  1214. void __user *argp = (void __user *)arg;
  1215. #define name iocpar.name
  1216. #define bname iocpar.bname
  1217. #define iocts iocpar.iocts
  1218. #define phone iocpar.phone
  1219. #define cfg iocpar.cfg
  1220. if (minor == ISDN_MINOR_STATUS) {
  1221. switch (cmd) {
  1222. case IIOCGETDVR:
  1223. return (TTY_DV +
  1224. (NET_DV << 8) +
  1225. (INF_DV << 16));
  1226. case IIOCGETCPS:
  1227. if (arg) {
  1228. ulong __user *p = argp;
  1229. int i;
  1230. if (!access_ok(VERIFY_WRITE, p,
  1231. sizeof(ulong) * ISDN_MAX_CHANNELS * 2))
  1232. return -EFAULT;
  1233. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  1234. put_user(dev->ibytes[i], p++);
  1235. put_user(dev->obytes[i], p++);
  1236. }
  1237. return 0;
  1238. } else
  1239. return -EINVAL;
  1240. break;
  1241. case IIOCNETGPN:
  1242. /* Get peer phone number of a connected
  1243. * isdn network interface */
  1244. if (arg) {
  1245. if (copy_from_user(&phone, argp, sizeof(phone)))
  1246. return -EFAULT;
  1247. return isdn_net_getpeer(&phone, argp);
  1248. } else
  1249. return -EINVAL;
  1250. default:
  1251. return -EINVAL;
  1252. }
  1253. }
  1254. if (!dev->drivers)
  1255. return -ENODEV;
  1256. if (minor <= ISDN_MINOR_BMAX) {
  1257. drvidx = isdn_minor2drv(minor);
  1258. if (drvidx < 0)
  1259. return -ENODEV;
  1260. if (!(dev->drv[drvidx]->flags & DRV_FLAG_RUNNING))
  1261. return -ENODEV;
  1262. return 0;
  1263. }
  1264. if (minor <= ISDN_MINOR_CTRLMAX) {
  1265. /*
  1266. * isdn net devices manage lots of configuration variables as linked lists.
  1267. * Those lists must only be manipulated from user space. Some of the ioctl's
  1268. * service routines access user space and are not atomic. Therefore, ioctl's
  1269. * manipulating the lists and ioctl's sleeping while accessing the lists
  1270. * are serialized by means of a semaphore.
  1271. */
  1272. switch (cmd) {
  1273. case IIOCNETDWRSET:
  1274. printk(KERN_INFO "INFO: ISDN_DW_ABC_EXTENSION not enabled\n");
  1275. return (-EINVAL);
  1276. case IIOCNETLCR:
  1277. printk(KERN_INFO "INFO: ISDN_ABC_LCR_SUPPORT not enabled\n");
  1278. return -ENODEV;
  1279. case IIOCNETAIF:
  1280. /* Add a network-interface */
  1281. if (arg) {
  1282. if (copy_from_user(name, argp, sizeof(name)))
  1283. return -EFAULT;
  1284. s = name;
  1285. } else {
  1286. s = NULL;
  1287. }
  1288. ret = mutex_lock_interruptible(&dev->mtx);
  1289. if (ret) return ret;
  1290. if ((s = isdn_net_new(s, NULL))) {
  1291. if (copy_to_user(argp, s, strlen(s) + 1)) {
  1292. ret = -EFAULT;
  1293. } else {
  1294. ret = 0;
  1295. }
  1296. } else
  1297. ret = -ENODEV;
  1298. mutex_unlock(&dev->mtx);
  1299. return ret;
  1300. case IIOCNETASL:
  1301. /* Add a slave to a network-interface */
  1302. if (arg) {
  1303. if (copy_from_user(bname, argp, sizeof(bname) - 1))
  1304. return -EFAULT;
  1305. } else
  1306. return -EINVAL;
  1307. ret = mutex_lock_interruptible(&dev->mtx);
  1308. if (ret) return ret;
  1309. if ((s = isdn_net_newslave(bname))) {
  1310. if (copy_to_user(argp, s, strlen(s) + 1)) {
  1311. ret = -EFAULT;
  1312. } else {
  1313. ret = 0;
  1314. }
  1315. } else
  1316. ret = -ENODEV;
  1317. mutex_unlock(&dev->mtx);
  1318. return ret;
  1319. case IIOCNETDIF:
  1320. /* Delete a network-interface */
  1321. if (arg) {
  1322. if (copy_from_user(name, argp, sizeof(name)))
  1323. return -EFAULT;
  1324. ret = mutex_lock_interruptible(&dev->mtx);
  1325. if (ret) return ret;
  1326. ret = isdn_net_rm(name);
  1327. mutex_unlock(&dev->mtx);
  1328. return ret;
  1329. } else
  1330. return -EINVAL;
  1331. case IIOCNETSCF:
  1332. /* Set configurable parameters of a network-interface */
  1333. if (arg) {
  1334. if (copy_from_user(&cfg, argp, sizeof(cfg)))
  1335. return -EFAULT;
  1336. return isdn_net_setcfg(&cfg);
  1337. } else
  1338. return -EINVAL;
  1339. case IIOCNETGCF:
  1340. /* Get configurable parameters of a network-interface */
  1341. if (arg) {
  1342. if (copy_from_user(&cfg, argp, sizeof(cfg)))
  1343. return -EFAULT;
  1344. if (!(ret = isdn_net_getcfg(&cfg))) {
  1345. if (copy_to_user(argp, &cfg, sizeof(cfg)))
  1346. return -EFAULT;
  1347. }
  1348. return ret;
  1349. } else
  1350. return -EINVAL;
  1351. case IIOCNETANM:
  1352. /* Add a phone-number to a network-interface */
  1353. if (arg) {
  1354. if (copy_from_user(&phone, argp, sizeof(phone)))
  1355. return -EFAULT;
  1356. ret = mutex_lock_interruptible(&dev->mtx);
  1357. if (ret) return ret;
  1358. ret = isdn_net_addphone(&phone);
  1359. mutex_unlock(&dev->mtx);
  1360. return ret;
  1361. } else
  1362. return -EINVAL;
  1363. case IIOCNETGNM:
  1364. /* Get list of phone-numbers of a network-interface */
  1365. if (arg) {
  1366. if (copy_from_user(&phone, argp, sizeof(phone)))
  1367. return -EFAULT;
  1368. ret = mutex_lock_interruptible(&dev->mtx);
  1369. if (ret) return ret;
  1370. ret = isdn_net_getphones(&phone, argp);
  1371. mutex_unlock(&dev->mtx);
  1372. return ret;
  1373. } else
  1374. return -EINVAL;
  1375. case IIOCNETDNM:
  1376. /* Delete a phone-number of a network-interface */
  1377. if (arg) {
  1378. if (copy_from_user(&phone, argp, sizeof(phone)))
  1379. return -EFAULT;
  1380. ret = mutex_lock_interruptible(&dev->mtx);
  1381. if (ret) return ret;
  1382. ret = isdn_net_delphone(&phone);
  1383. mutex_unlock(&dev->mtx);
  1384. return ret;
  1385. } else
  1386. return -EINVAL;
  1387. case IIOCNETDIL:
  1388. /* Force dialing of a network-interface */
  1389. if (arg) {
  1390. if (copy_from_user(name, argp, sizeof(name)))
  1391. return -EFAULT;
  1392. return isdn_net_force_dial(name);
  1393. } else
  1394. return -EINVAL;
  1395. #ifdef CONFIG_ISDN_PPP
  1396. case IIOCNETALN:
  1397. if (!arg)
  1398. return -EINVAL;
  1399. if (copy_from_user(name, argp, sizeof(name)))
  1400. return -EFAULT;
  1401. return isdn_ppp_dial_slave(name);
  1402. case IIOCNETDLN:
  1403. if (!arg)
  1404. return -EINVAL;
  1405. if (copy_from_user(name, argp, sizeof(name)))
  1406. return -EFAULT;
  1407. return isdn_ppp_hangup_slave(name);
  1408. #endif
  1409. case IIOCNETHUP:
  1410. /* Force hangup of a network-interface */
  1411. if (!arg)
  1412. return -EINVAL;
  1413. if (copy_from_user(name, argp, sizeof(name)))
  1414. return -EFAULT;
  1415. return isdn_net_force_hangup(name);
  1416. break;
  1417. case IIOCSETVER:
  1418. dev->net_verbose = arg;
  1419. printk(KERN_INFO "isdn: Verbose-Level is %d\n", dev->net_verbose);
  1420. return 0;
  1421. case IIOCSETGST:
  1422. if (arg)
  1423. dev->global_flags |= ISDN_GLOBAL_STOPPED;
  1424. else
  1425. dev->global_flags &= ~ISDN_GLOBAL_STOPPED;
  1426. printk(KERN_INFO "isdn: Global Mode %s\n",
  1427. (dev->global_flags & ISDN_GLOBAL_STOPPED) ? "stopped" : "running");
  1428. return 0;
  1429. case IIOCSETBRJ:
  1430. drvidx = -1;
  1431. if (arg) {
  1432. int i;
  1433. char *p;
  1434. if (copy_from_user(&iocts, argp,
  1435. sizeof(isdn_ioctl_struct)))
  1436. return -EFAULT;
  1437. iocts.drvid[sizeof(iocts.drvid) - 1] = 0;
  1438. if (strlen(iocts.drvid)) {
  1439. if ((p = strchr(iocts.drvid, ',')))
  1440. *p = 0;
  1441. drvidx = -1;
  1442. for (i = 0; i < ISDN_MAX_DRIVERS; i++)
  1443. if (!(strcmp(dev->drvid[i], iocts.drvid))) {
  1444. drvidx = i;
  1445. break;
  1446. }
  1447. }
  1448. }
  1449. if (drvidx == -1)
  1450. return -ENODEV;
  1451. if (iocts.arg)
  1452. dev->drv[drvidx]->flags |= DRV_FLAG_REJBUS;
  1453. else
  1454. dev->drv[drvidx]->flags &= ~DRV_FLAG_REJBUS;
  1455. return 0;
  1456. case IIOCSIGPRF:
  1457. dev->profd = current;
  1458. return 0;
  1459. break;
  1460. case IIOCGETPRF:
  1461. /* Get all Modem-Profiles */
  1462. if (arg) {
  1463. char __user *p = argp;
  1464. int i;
  1465. if (!access_ok(VERIFY_WRITE, argp,
  1466. (ISDN_MODEM_NUMREG + ISDN_MSNLEN + ISDN_LMSNLEN)
  1467. * ISDN_MAX_CHANNELS))
  1468. return -EFAULT;
  1469. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  1470. if (copy_to_user(p, dev->mdm.info[i].emu.profile,
  1471. ISDN_MODEM_NUMREG))
  1472. return -EFAULT;
  1473. p += ISDN_MODEM_NUMREG;
  1474. if (copy_to_user(p, dev->mdm.info[i].emu.pmsn, ISDN_MSNLEN))
  1475. return -EFAULT;
  1476. p += ISDN_MSNLEN;
  1477. if (copy_to_user(p, dev->mdm.info[i].emu.plmsn, ISDN_LMSNLEN))
  1478. return -EFAULT;
  1479. p += ISDN_LMSNLEN;
  1480. }
  1481. return (ISDN_MODEM_NUMREG + ISDN_MSNLEN + ISDN_LMSNLEN) * ISDN_MAX_CHANNELS;
  1482. } else
  1483. return -EINVAL;
  1484. break;
  1485. case IIOCSETPRF:
  1486. /* Set all Modem-Profiles */
  1487. if (arg) {
  1488. char __user *p = argp;
  1489. int i;
  1490. if (!access_ok(VERIFY_READ, argp,
  1491. (ISDN_MODEM_NUMREG + ISDN_MSNLEN + ISDN_LMSNLEN)
  1492. * ISDN_MAX_CHANNELS))
  1493. return -EFAULT;
  1494. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  1495. if (copy_from_user(dev->mdm.info[i].emu.profile, p,
  1496. ISDN_MODEM_NUMREG))
  1497. return -EFAULT;
  1498. p += ISDN_MODEM_NUMREG;
  1499. if (copy_from_user(dev->mdm.info[i].emu.plmsn, p, ISDN_LMSNLEN))
  1500. return -EFAULT;
  1501. p += ISDN_LMSNLEN;
  1502. if (copy_from_user(dev->mdm.info[i].emu.pmsn, p, ISDN_MSNLEN))
  1503. return -EFAULT;
  1504. p += ISDN_MSNLEN;
  1505. }
  1506. return 0;
  1507. } else
  1508. return -EINVAL;
  1509. break;
  1510. case IIOCSETMAP:
  1511. case IIOCGETMAP:
  1512. /* Set/Get MSN->EAZ-Mapping for a driver */
  1513. if (arg) {
  1514. if (copy_from_user(&iocts, argp,
  1515. sizeof(isdn_ioctl_struct)))
  1516. return -EFAULT;
  1517. iocts.drvid[sizeof(iocts.drvid) - 1] = 0;
  1518. if (strlen(iocts.drvid)) {
  1519. drvidx = -1;
  1520. for (i = 0; i < ISDN_MAX_DRIVERS; i++)
  1521. if (!(strcmp(dev->drvid[i], iocts.drvid))) {
  1522. drvidx = i;
  1523. break;
  1524. }
  1525. } else
  1526. drvidx = 0;
  1527. if (drvidx == -1)
  1528. return -ENODEV;
  1529. if (cmd == IIOCSETMAP) {
  1530. int loop = 1;
  1531. p = (char __user *) iocts.arg;
  1532. i = 0;
  1533. while (loop) {
  1534. int j = 0;
  1535. while (1) {
  1536. if (!access_ok(VERIFY_READ, p, 1))
  1537. return -EFAULT;
  1538. get_user(bname[j], p++);
  1539. switch (bname[j]) {
  1540. case '\0':
  1541. loop = 0;
  1542. /* Fall through */
  1543. case ',':
  1544. bname[j] = '\0';
  1545. strcpy(dev->drv[drvidx]->msn2eaz[i], bname);
  1546. j = ISDN_MSNLEN;
  1547. break;
  1548. default:
  1549. j++;
  1550. }
  1551. if (j >= ISDN_MSNLEN)
  1552. break;
  1553. }
  1554. if (++i > 9)
  1555. break;
  1556. }
  1557. } else {
  1558. p = (char __user *) iocts.arg;
  1559. for (i = 0; i < 10; i++) {
  1560. snprintf(bname, sizeof(bname), "%s%s",
  1561. strlen(dev->drv[drvidx]->msn2eaz[i]) ?
  1562. dev->drv[drvidx]->msn2eaz[i] : "_",
  1563. (i < 9) ? "," : "\0");
  1564. if (copy_to_user(p, bname, strlen(bname) + 1))
  1565. return -EFAULT;
  1566. p += strlen(bname);
  1567. }
  1568. }
  1569. return 0;
  1570. } else
  1571. return -EINVAL;
  1572. case IIOCDBGVAR:
  1573. if (arg) {
  1574. if (copy_to_user(argp, &dev, sizeof(ulong)))
  1575. return -EFAULT;
  1576. return 0;
  1577. } else
  1578. return -EINVAL;
  1579. break;
  1580. default:
  1581. if ((cmd & IIOCDRVCTL) == IIOCDRVCTL)
  1582. cmd = ((cmd >> _IOC_NRSHIFT) & _IOC_NRMASK) & ISDN_DRVIOCTL_MASK;
  1583. else
  1584. return -EINVAL;
  1585. if (arg) {
  1586. int i;
  1587. char *p;
  1588. if (copy_from_user(&iocts, argp, sizeof(isdn_ioctl_struct)))
  1589. return -EFAULT;
  1590. iocts.drvid[sizeof(iocts.drvid) - 1] = 0;
  1591. if (strlen(iocts.drvid)) {
  1592. if ((p = strchr(iocts.drvid, ',')))
  1593. *p = 0;
  1594. drvidx = -1;
  1595. for (i = 0; i < ISDN_MAX_DRIVERS; i++)
  1596. if (!(strcmp(dev->drvid[i], iocts.drvid))) {
  1597. drvidx = i;
  1598. break;
  1599. }
  1600. } else
  1601. drvidx = 0;
  1602. if (drvidx == -1)
  1603. return -ENODEV;
  1604. if (!access_ok(VERIFY_WRITE, argp,
  1605. sizeof(isdn_ioctl_struct)))
  1606. return -EFAULT;
  1607. c.driver = drvidx;
  1608. c.command = ISDN_CMD_IOCTL;
  1609. c.arg = cmd;
  1610. memcpy(c.parm.num, &iocts.arg, sizeof(ulong));
  1611. ret = isdn_command(&c);
  1612. memcpy(&iocts.arg, c.parm.num, sizeof(ulong));
  1613. if (copy_to_user(argp, &iocts, sizeof(isdn_ioctl_struct)))
  1614. return -EFAULT;
  1615. return ret;
  1616. } else
  1617. return -EINVAL;
  1618. }
  1619. }
  1620. #ifdef CONFIG_ISDN_PPP
  1621. if (minor <= ISDN_MINOR_PPPMAX)
  1622. return (isdn_ppp_ioctl(minor - ISDN_MINOR_PPP, file, cmd, arg));
  1623. #endif
  1624. return -ENODEV;
  1625. #undef name
  1626. #undef bname
  1627. #undef iocts
  1628. #undef phone
  1629. #undef cfg
  1630. }
  1631. static long
  1632. isdn_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  1633. {
  1634. int ret;
  1635. mutex_lock(&isdn_mutex);
  1636. ret = isdn_ioctl(file, cmd, arg);
  1637. mutex_unlock(&isdn_mutex);
  1638. return ret;
  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. mutex_lock(&isdn_mutex);
  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. mutex_unlock(&isdn_mutex);
  1701. return retval;
  1702. }
  1703. static int
  1704. isdn_close(struct inode *ino, struct file *filep)
  1705. {
  1706. uint minor = iminor(ino);
  1707. mutex_lock(&isdn_mutex);
  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. mutex_unlock(&isdn_mutex);
  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. .unlocked_ioctl = isdn_unlocked_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. dev = vzalloc(sizeof(isdn_dev));
  2168. if (!dev) {
  2169. printk(KERN_WARNING "isdn: Could not allocate device-struct.\n");
  2170. return -EIO;
  2171. }
  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. }
  2187. if (register_chrdev(ISDN_MAJOR, "isdn", &isdn_fops)) {
  2188. printk(KERN_WARNING "isdn: Could not register control devices\n");
  2189. vfree(dev);
  2190. return -EIO;
  2191. }
  2192. if ((isdn_tty_modem_init()) < 0) {
  2193. printk(KERN_WARNING "isdn: Could not register tty devices\n");
  2194. vfree(dev);
  2195. unregister_chrdev(ISDN_MAJOR, "isdn");
  2196. return -EIO;
  2197. }
  2198. #ifdef CONFIG_ISDN_PPP
  2199. if (isdn_ppp_init() < 0) {
  2200. printk(KERN_WARNING "isdn: Could not create PPP-device-structs\n");
  2201. isdn_tty_exit();
  2202. unregister_chrdev(ISDN_MAJOR, "isdn");
  2203. vfree(dev);
  2204. return -EIO;
  2205. }
  2206. #endif /* CONFIG_ISDN_PPP */
  2207. strcpy(tmprev, isdn_revision);
  2208. printk(KERN_NOTICE "ISDN subsystem Rev: %s/", isdn_getrev(tmprev));
  2209. strcpy(tmprev, isdn_net_revision);
  2210. printk("%s/", isdn_getrev(tmprev));
  2211. strcpy(tmprev, isdn_ppp_revision);
  2212. printk("%s/", isdn_getrev(tmprev));
  2213. strcpy(tmprev, isdn_audio_revision);
  2214. printk("%s/", isdn_getrev(tmprev));
  2215. strcpy(tmprev, isdn_v110_revision);
  2216. printk("%s", isdn_getrev(tmprev));
  2217. #ifdef MODULE
  2218. printk(" loaded\n");
  2219. #else
  2220. printk("\n");
  2221. #endif
  2222. isdn_info_update();
  2223. return 0;
  2224. }
  2225. /*
  2226. * Unload module
  2227. */
  2228. static void __exit isdn_exit(void)
  2229. {
  2230. #ifdef CONFIG_ISDN_PPP
  2231. isdn_ppp_cleanup();
  2232. #endif
  2233. if (isdn_net_rmall() < 0) {
  2234. printk(KERN_WARNING "isdn: net-device busy, remove cancelled\n");
  2235. return;
  2236. }
  2237. isdn_tty_exit();
  2238. unregister_chrdev(ISDN_MAJOR, "isdn");
  2239. del_timer(&dev->timer);
  2240. /* call vfree with interrupts enabled, else it will hang */
  2241. vfree(dev);
  2242. printk(KERN_NOTICE "ISDN-subsystem unloaded\n");
  2243. }
  2244. module_init(isdn_init);
  2245. module_exit(isdn_exit);