isdn_common.c 57 KB

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