isdn_common.c 58 KB

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