isdn_common.c 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398
  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. } else
  1310. return -EINVAL;
  1311. ret = mutex_lock_interruptible(&dev->mtx);
  1312. if( ret ) return ret;
  1313. if ((s = isdn_net_newslave(bname))) {
  1314. if (copy_to_user(argp, s, strlen(s) + 1)){
  1315. ret = -EFAULT;
  1316. } else {
  1317. ret = 0;
  1318. }
  1319. } else
  1320. ret = -ENODEV;
  1321. mutex_unlock(&dev->mtx);
  1322. return ret;
  1323. case IIOCNETDIF:
  1324. /* Delete a network-interface */
  1325. if (arg) {
  1326. if (copy_from_user(name, argp, sizeof(name)))
  1327. return -EFAULT;
  1328. ret = mutex_lock_interruptible(&dev->mtx);
  1329. if( ret ) return ret;
  1330. ret = isdn_net_rm(name);
  1331. mutex_unlock(&dev->mtx);
  1332. return ret;
  1333. } else
  1334. return -EINVAL;
  1335. case IIOCNETSCF:
  1336. /* Set configurable parameters of a network-interface */
  1337. if (arg) {
  1338. if (copy_from_user(&cfg, argp, sizeof(cfg)))
  1339. return -EFAULT;
  1340. return isdn_net_setcfg(&cfg);
  1341. } else
  1342. return -EINVAL;
  1343. case IIOCNETGCF:
  1344. /* Get configurable parameters of a network-interface */
  1345. if (arg) {
  1346. if (copy_from_user(&cfg, argp, sizeof(cfg)))
  1347. return -EFAULT;
  1348. if (!(ret = isdn_net_getcfg(&cfg))) {
  1349. if (copy_to_user(argp, &cfg, sizeof(cfg)))
  1350. return -EFAULT;
  1351. }
  1352. return ret;
  1353. } else
  1354. return -EINVAL;
  1355. case IIOCNETANM:
  1356. /* Add a phone-number to a network-interface */
  1357. if (arg) {
  1358. if (copy_from_user(&phone, argp, sizeof(phone)))
  1359. return -EFAULT;
  1360. ret = mutex_lock_interruptible(&dev->mtx);
  1361. if( ret ) return ret;
  1362. ret = isdn_net_addphone(&phone);
  1363. mutex_unlock(&dev->mtx);
  1364. return ret;
  1365. } else
  1366. return -EINVAL;
  1367. case IIOCNETGNM:
  1368. /* Get list of phone-numbers of a network-interface */
  1369. if (arg) {
  1370. if (copy_from_user(&phone, argp, sizeof(phone)))
  1371. return -EFAULT;
  1372. ret = mutex_lock_interruptible(&dev->mtx);
  1373. if( ret ) return ret;
  1374. ret = isdn_net_getphones(&phone, argp);
  1375. mutex_unlock(&dev->mtx);
  1376. return ret;
  1377. } else
  1378. return -EINVAL;
  1379. case IIOCNETDNM:
  1380. /* Delete a phone-number of a network-interface */
  1381. if (arg) {
  1382. if (copy_from_user(&phone, argp, sizeof(phone)))
  1383. return -EFAULT;
  1384. ret = mutex_lock_interruptible(&dev->mtx);
  1385. if( ret ) return ret;
  1386. ret = isdn_net_delphone(&phone);
  1387. mutex_unlock(&dev->mtx);
  1388. return ret;
  1389. } else
  1390. return -EINVAL;
  1391. case IIOCNETDIL:
  1392. /* Force dialing of a network-interface */
  1393. if (arg) {
  1394. if (copy_from_user(name, argp, sizeof(name)))
  1395. return -EFAULT;
  1396. return isdn_net_force_dial(name);
  1397. } else
  1398. return -EINVAL;
  1399. #ifdef CONFIG_ISDN_PPP
  1400. case IIOCNETALN:
  1401. if (!arg)
  1402. return -EINVAL;
  1403. if (copy_from_user(name, argp, sizeof(name)))
  1404. return -EFAULT;
  1405. return isdn_ppp_dial_slave(name);
  1406. case IIOCNETDLN:
  1407. if (!arg)
  1408. return -EINVAL;
  1409. if (copy_from_user(name, argp, sizeof(name)))
  1410. return -EFAULT;
  1411. return isdn_ppp_hangup_slave(name);
  1412. #endif
  1413. case IIOCNETHUP:
  1414. /* Force hangup of a network-interface */
  1415. if (!arg)
  1416. return -EINVAL;
  1417. if (copy_from_user(name, argp, sizeof(name)))
  1418. return -EFAULT;
  1419. return isdn_net_force_hangup(name);
  1420. break;
  1421. #endif /* CONFIG_NETDEVICES */
  1422. case IIOCSETVER:
  1423. dev->net_verbose = arg;
  1424. printk(KERN_INFO "isdn: Verbose-Level is %d\n", dev->net_verbose);
  1425. return 0;
  1426. case IIOCSETGST:
  1427. if (arg)
  1428. dev->global_flags |= ISDN_GLOBAL_STOPPED;
  1429. else
  1430. dev->global_flags &= ~ISDN_GLOBAL_STOPPED;
  1431. printk(KERN_INFO "isdn: Global Mode %s\n",
  1432. (dev->global_flags & ISDN_GLOBAL_STOPPED) ? "stopped" : "running");
  1433. return 0;
  1434. case IIOCSETBRJ:
  1435. drvidx = -1;
  1436. if (arg) {
  1437. int i;
  1438. char *p;
  1439. if (copy_from_user(&iocts, argp,
  1440. sizeof(isdn_ioctl_struct)))
  1441. return -EFAULT;
  1442. iocts.drvid[sizeof(iocts.drvid)-1] = 0;
  1443. if (strlen(iocts.drvid)) {
  1444. if ((p = strchr(iocts.drvid, ',')))
  1445. *p = 0;
  1446. drvidx = -1;
  1447. for (i = 0; i < ISDN_MAX_DRIVERS; i++)
  1448. if (!(strcmp(dev->drvid[i], iocts.drvid))) {
  1449. drvidx = i;
  1450. break;
  1451. }
  1452. }
  1453. }
  1454. if (drvidx == -1)
  1455. return -ENODEV;
  1456. if (iocts.arg)
  1457. dev->drv[drvidx]->flags |= DRV_FLAG_REJBUS;
  1458. else
  1459. dev->drv[drvidx]->flags &= ~DRV_FLAG_REJBUS;
  1460. return 0;
  1461. case IIOCSIGPRF:
  1462. dev->profd = current;
  1463. return 0;
  1464. break;
  1465. case IIOCGETPRF:
  1466. /* Get all Modem-Profiles */
  1467. if (arg) {
  1468. char __user *p = argp;
  1469. int i;
  1470. if (!access_ok(VERIFY_WRITE, argp,
  1471. (ISDN_MODEM_NUMREG + ISDN_MSNLEN + ISDN_LMSNLEN)
  1472. * ISDN_MAX_CHANNELS))
  1473. return -EFAULT;
  1474. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  1475. if (copy_to_user(p, dev->mdm.info[i].emu.profile,
  1476. ISDN_MODEM_NUMREG))
  1477. return -EFAULT;
  1478. p += ISDN_MODEM_NUMREG;
  1479. if (copy_to_user(p, dev->mdm.info[i].emu.pmsn, ISDN_MSNLEN))
  1480. return -EFAULT;
  1481. p += ISDN_MSNLEN;
  1482. if (copy_to_user(p, dev->mdm.info[i].emu.plmsn, ISDN_LMSNLEN))
  1483. return -EFAULT;
  1484. p += ISDN_LMSNLEN;
  1485. }
  1486. return (ISDN_MODEM_NUMREG + ISDN_MSNLEN + ISDN_LMSNLEN) * ISDN_MAX_CHANNELS;
  1487. } else
  1488. return -EINVAL;
  1489. break;
  1490. case IIOCSETPRF:
  1491. /* Set all Modem-Profiles */
  1492. if (arg) {
  1493. char __user *p = argp;
  1494. int i;
  1495. if (!access_ok(VERIFY_READ, argp,
  1496. (ISDN_MODEM_NUMREG + ISDN_MSNLEN + ISDN_LMSNLEN)
  1497. * ISDN_MAX_CHANNELS))
  1498. return -EFAULT;
  1499. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  1500. if (copy_from_user(dev->mdm.info[i].emu.profile, p,
  1501. ISDN_MODEM_NUMREG))
  1502. return -EFAULT;
  1503. p += ISDN_MODEM_NUMREG;
  1504. if (copy_from_user(dev->mdm.info[i].emu.plmsn, p, ISDN_LMSNLEN))
  1505. return -EFAULT;
  1506. p += ISDN_LMSNLEN;
  1507. if (copy_from_user(dev->mdm.info[i].emu.pmsn, p, ISDN_MSNLEN))
  1508. return -EFAULT;
  1509. p += ISDN_MSNLEN;
  1510. }
  1511. return 0;
  1512. } else
  1513. return -EINVAL;
  1514. break;
  1515. case IIOCSETMAP:
  1516. case IIOCGETMAP:
  1517. /* Set/Get MSN->EAZ-Mapping for a driver */
  1518. if (arg) {
  1519. if (copy_from_user(&iocts, argp,
  1520. sizeof(isdn_ioctl_struct)))
  1521. return -EFAULT;
  1522. iocts.drvid[sizeof(iocts.drvid)-1] = 0;
  1523. if (strlen(iocts.drvid)) {
  1524. drvidx = -1;
  1525. for (i = 0; i < ISDN_MAX_DRIVERS; i++)
  1526. if (!(strcmp(dev->drvid[i], iocts.drvid))) {
  1527. drvidx = i;
  1528. break;
  1529. }
  1530. } else
  1531. drvidx = 0;
  1532. if (drvidx == -1)
  1533. return -ENODEV;
  1534. if (cmd == IIOCSETMAP) {
  1535. int loop = 1;
  1536. p = (char __user *) iocts.arg;
  1537. i = 0;
  1538. while (loop) {
  1539. int j = 0;
  1540. while (1) {
  1541. if (!access_ok(VERIFY_READ, p, 1))
  1542. return -EFAULT;
  1543. get_user(bname[j], p++);
  1544. switch (bname[j]) {
  1545. case '\0':
  1546. loop = 0;
  1547. /* Fall through */
  1548. case ',':
  1549. bname[j] = '\0';
  1550. strcpy(dev->drv[drvidx]->msn2eaz[i], bname);
  1551. j = ISDN_MSNLEN;
  1552. break;
  1553. default:
  1554. j++;
  1555. }
  1556. if (j >= ISDN_MSNLEN)
  1557. break;
  1558. }
  1559. if (++i > 9)
  1560. break;
  1561. }
  1562. } else {
  1563. p = (char __user *) iocts.arg;
  1564. for (i = 0; i < 10; i++) {
  1565. snprintf(bname, sizeof(bname), "%s%s",
  1566. strlen(dev->drv[drvidx]->msn2eaz[i]) ?
  1567. dev->drv[drvidx]->msn2eaz[i] : "_",
  1568. (i < 9) ? "," : "\0");
  1569. if (copy_to_user(p, bname, strlen(bname) + 1))
  1570. return -EFAULT;
  1571. p += strlen(bname);
  1572. }
  1573. }
  1574. return 0;
  1575. } else
  1576. return -EINVAL;
  1577. case IIOCDBGVAR:
  1578. if (arg) {
  1579. if (copy_to_user(argp, &dev, sizeof(ulong)))
  1580. return -EFAULT;
  1581. return 0;
  1582. } else
  1583. return -EINVAL;
  1584. break;
  1585. default:
  1586. if ((cmd & IIOCDRVCTL) == IIOCDRVCTL)
  1587. cmd = ((cmd >> _IOC_NRSHIFT) & _IOC_NRMASK) & ISDN_DRVIOCTL_MASK;
  1588. else
  1589. return -EINVAL;
  1590. if (arg) {
  1591. int i;
  1592. char *p;
  1593. if (copy_from_user(&iocts, argp, sizeof(isdn_ioctl_struct)))
  1594. return -EFAULT;
  1595. iocts.drvid[sizeof(iocts.drvid)-1] = 0;
  1596. if (strlen(iocts.drvid)) {
  1597. if ((p = strchr(iocts.drvid, ',')))
  1598. *p = 0;
  1599. drvidx = -1;
  1600. for (i = 0; i < ISDN_MAX_DRIVERS; i++)
  1601. if (!(strcmp(dev->drvid[i], iocts.drvid))) {
  1602. drvidx = i;
  1603. break;
  1604. }
  1605. } else
  1606. drvidx = 0;
  1607. if (drvidx == -1)
  1608. return -ENODEV;
  1609. if (!access_ok(VERIFY_WRITE, argp,
  1610. sizeof(isdn_ioctl_struct)))
  1611. return -EFAULT;
  1612. c.driver = drvidx;
  1613. c.command = ISDN_CMD_IOCTL;
  1614. c.arg = cmd;
  1615. memcpy(c.parm.num, &iocts.arg, sizeof(ulong));
  1616. ret = isdn_command(&c);
  1617. memcpy(&iocts.arg, c.parm.num, sizeof(ulong));
  1618. if (copy_to_user(argp, &iocts, sizeof(isdn_ioctl_struct)))
  1619. return -EFAULT;
  1620. return ret;
  1621. } else
  1622. return -EINVAL;
  1623. }
  1624. }
  1625. #ifdef CONFIG_ISDN_PPP
  1626. if (minor <= ISDN_MINOR_PPPMAX)
  1627. return (isdn_ppp_ioctl(minor - ISDN_MINOR_PPP, file, cmd, arg));
  1628. #endif
  1629. return -ENODEV;
  1630. #undef name
  1631. #undef bname
  1632. #undef iocts
  1633. #undef phone
  1634. #undef cfg
  1635. }
  1636. static long
  1637. isdn_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  1638. {
  1639. int ret;
  1640. mutex_lock(&isdn_mutex);
  1641. ret = isdn_ioctl(file, cmd, arg);
  1642. mutex_unlock(&isdn_mutex);
  1643. return ret;
  1644. }
  1645. /*
  1646. * Open the device code.
  1647. */
  1648. static int
  1649. isdn_open(struct inode *ino, struct file *filep)
  1650. {
  1651. uint minor = iminor(ino);
  1652. int drvidx;
  1653. int chidx;
  1654. int retval = -ENODEV;
  1655. mutex_lock(&isdn_mutex);
  1656. if (minor == ISDN_MINOR_STATUS) {
  1657. infostruct *p;
  1658. if ((p = kmalloc(sizeof(infostruct), GFP_KERNEL))) {
  1659. p->next = (char *) dev->infochain;
  1660. p->private = (char *) &(filep->private_data);
  1661. dev->infochain = p;
  1662. /* At opening we allow a single update */
  1663. filep->private_data = (char *) 1;
  1664. retval = 0;
  1665. goto out;
  1666. } else {
  1667. retval = -ENOMEM;
  1668. goto out;
  1669. }
  1670. }
  1671. if (!dev->channels)
  1672. goto out;
  1673. if (minor <= ISDN_MINOR_BMAX) {
  1674. printk(KERN_WARNING "isdn_open minor %d obsolete!\n", minor);
  1675. drvidx = isdn_minor2drv(minor);
  1676. if (drvidx < 0)
  1677. goto out;
  1678. chidx = isdn_minor2chan(minor);
  1679. if (!(dev->drv[drvidx]->flags & DRV_FLAG_RUNNING))
  1680. goto out;
  1681. if (!(dev->drv[drvidx]->online & (1 << chidx)))
  1682. goto out;
  1683. isdn_lock_drivers();
  1684. retval = 0;
  1685. goto out;
  1686. }
  1687. if (minor <= ISDN_MINOR_CTRLMAX) {
  1688. drvidx = isdn_minor2drv(minor - ISDN_MINOR_CTRL);
  1689. if (drvidx < 0)
  1690. goto out;
  1691. isdn_lock_drivers();
  1692. retval = 0;
  1693. goto out;
  1694. }
  1695. #ifdef CONFIG_ISDN_PPP
  1696. if (minor <= ISDN_MINOR_PPPMAX) {
  1697. retval = isdn_ppp_open(minor - ISDN_MINOR_PPP, filep);
  1698. if (retval == 0)
  1699. isdn_lock_drivers();
  1700. goto out;
  1701. }
  1702. #endif
  1703. out:
  1704. nonseekable_open(ino, filep);
  1705. mutex_unlock(&isdn_mutex);
  1706. return retval;
  1707. }
  1708. static int
  1709. isdn_close(struct inode *ino, struct file *filep)
  1710. {
  1711. uint minor = iminor(ino);
  1712. mutex_lock(&isdn_mutex);
  1713. if (minor == ISDN_MINOR_STATUS) {
  1714. infostruct *p = dev->infochain;
  1715. infostruct *q = NULL;
  1716. while (p) {
  1717. if (p->private == (char *) &(filep->private_data)) {
  1718. if (q)
  1719. q->next = p->next;
  1720. else
  1721. dev->infochain = (infostruct *) (p->next);
  1722. kfree(p);
  1723. goto out;
  1724. }
  1725. q = p;
  1726. p = (infostruct *) (p->next);
  1727. }
  1728. printk(KERN_WARNING "isdn: No private data while closing isdnctrl\n");
  1729. goto out;
  1730. }
  1731. isdn_unlock_drivers();
  1732. if (minor <= ISDN_MINOR_BMAX)
  1733. goto out;
  1734. if (minor <= ISDN_MINOR_CTRLMAX) {
  1735. if (dev->profd == current)
  1736. dev->profd = NULL;
  1737. goto out;
  1738. }
  1739. #ifdef CONFIG_ISDN_PPP
  1740. if (minor <= ISDN_MINOR_PPPMAX)
  1741. isdn_ppp_release(minor - ISDN_MINOR_PPP, filep);
  1742. #endif
  1743. out:
  1744. mutex_unlock(&isdn_mutex);
  1745. return 0;
  1746. }
  1747. static const struct file_operations isdn_fops =
  1748. {
  1749. .owner = THIS_MODULE,
  1750. .llseek = no_llseek,
  1751. .read = isdn_read,
  1752. .write = isdn_write,
  1753. .poll = isdn_poll,
  1754. .unlocked_ioctl = isdn_unlocked_ioctl,
  1755. .open = isdn_open,
  1756. .release = isdn_close,
  1757. };
  1758. char *
  1759. isdn_map_eaz2msn(char *msn, int di)
  1760. {
  1761. isdn_driver_t *this = dev->drv[di];
  1762. int i;
  1763. if (strlen(msn) == 1) {
  1764. i = msn[0] - '0';
  1765. if ((i >= 0) && (i <= 9))
  1766. if (strlen(this->msn2eaz[i]))
  1767. return (this->msn2eaz[i]);
  1768. }
  1769. return (msn);
  1770. }
  1771. /*
  1772. * Find an unused ISDN-channel, whose feature-flags match the
  1773. * given L2- and L3-protocols.
  1774. */
  1775. #define L2V (~(ISDN_FEATURE_L2_V11096|ISDN_FEATURE_L2_V11019|ISDN_FEATURE_L2_V11038))
  1776. /*
  1777. * This function must be called with holding the dev->lock.
  1778. */
  1779. int
  1780. isdn_get_free_channel(int usage, int l2_proto, int l3_proto, int pre_dev
  1781. ,int pre_chan, char *msn)
  1782. {
  1783. int i;
  1784. ulong features;
  1785. ulong vfeatures;
  1786. features = ((1 << l2_proto) | (0x10000 << l3_proto));
  1787. vfeatures = (((1 << l2_proto) | (0x10000 << l3_proto)) &
  1788. ~(ISDN_FEATURE_L2_V11096|ISDN_FEATURE_L2_V11019|ISDN_FEATURE_L2_V11038));
  1789. /* If Layer-2 protocol is V.110, accept drivers with
  1790. * transparent feature even if these don't support V.110
  1791. * because we can emulate this in linklevel.
  1792. */
  1793. for (i = 0; i < ISDN_MAX_CHANNELS; i++)
  1794. if (USG_NONE(dev->usage[i]) &&
  1795. (dev->drvmap[i] != -1)) {
  1796. int d = dev->drvmap[i];
  1797. if ((dev->usage[i] & ISDN_USAGE_EXCLUSIVE) &&
  1798. ((pre_dev != d) || (pre_chan != dev->chanmap[i])))
  1799. continue;
  1800. if (!strcmp(isdn_map_eaz2msn(msn, d), "-"))
  1801. continue;
  1802. if (dev->usage[i] & ISDN_USAGE_DISABLED)
  1803. continue; /* usage not allowed */
  1804. if (dev->drv[d]->flags & DRV_FLAG_RUNNING) {
  1805. if (((dev->drv[d]->interface->features & features) == features) ||
  1806. (((dev->drv[d]->interface->features & vfeatures) == vfeatures) &&
  1807. (dev->drv[d]->interface->features & ISDN_FEATURE_L2_TRANS))) {
  1808. if ((pre_dev < 0) || (pre_chan < 0)) {
  1809. dev->usage[i] &= ISDN_USAGE_EXCLUSIVE;
  1810. dev->usage[i] |= usage;
  1811. isdn_info_update();
  1812. return i;
  1813. } else {
  1814. if ((pre_dev == d) && (pre_chan == dev->chanmap[i])) {
  1815. dev->usage[i] &= ISDN_USAGE_EXCLUSIVE;
  1816. dev->usage[i] |= usage;
  1817. isdn_info_update();
  1818. return i;
  1819. }
  1820. }
  1821. }
  1822. }
  1823. }
  1824. return -1;
  1825. }
  1826. /*
  1827. * Set state of ISDN-channel to 'unused'
  1828. */
  1829. void
  1830. isdn_free_channel(int di, int ch, int usage)
  1831. {
  1832. int i;
  1833. if ((di < 0) || (ch < 0)) {
  1834. printk(KERN_WARNING "%s: called with invalid drv(%d) or channel(%d)\n",
  1835. __func__, di, ch);
  1836. return;
  1837. }
  1838. for (i = 0; i < ISDN_MAX_CHANNELS; i++)
  1839. if (((!usage) || ((dev->usage[i] & ISDN_USAGE_MASK) == usage)) &&
  1840. (dev->drvmap[i] == di) &&
  1841. (dev->chanmap[i] == ch)) {
  1842. dev->usage[i] &= (ISDN_USAGE_NONE | ISDN_USAGE_EXCLUSIVE);
  1843. strcpy(dev->num[i], "???");
  1844. dev->ibytes[i] = 0;
  1845. dev->obytes[i] = 0;
  1846. // 20.10.99 JIM, try to reinitialize v110 !
  1847. dev->v110emu[i] = 0;
  1848. atomic_set(&(dev->v110use[i]), 0);
  1849. isdn_v110_close(dev->v110[i]);
  1850. dev->v110[i] = NULL;
  1851. // 20.10.99 JIM, try to reinitialize v110 !
  1852. isdn_info_update();
  1853. if (dev->drv[di])
  1854. skb_queue_purge(&dev->drv[di]->rpqueue[ch]);
  1855. }
  1856. }
  1857. /*
  1858. * Cancel Exclusive-Flag for ISDN-channel
  1859. */
  1860. void
  1861. isdn_unexclusive_channel(int di, int ch)
  1862. {
  1863. int i;
  1864. for (i = 0; i < ISDN_MAX_CHANNELS; i++)
  1865. if ((dev->drvmap[i] == di) &&
  1866. (dev->chanmap[i] == ch)) {
  1867. dev->usage[i] &= ~ISDN_USAGE_EXCLUSIVE;
  1868. isdn_info_update();
  1869. return;
  1870. }
  1871. }
  1872. /*
  1873. * writebuf replacement for SKB_ABLE drivers
  1874. */
  1875. static int
  1876. isdn_writebuf_stub(int drvidx, int chan, const u_char __user * buf, int len)
  1877. {
  1878. int ret;
  1879. int hl = dev->drv[drvidx]->interface->hl_hdrlen;
  1880. struct sk_buff *skb = alloc_skb(hl + len, GFP_ATOMIC);
  1881. if (!skb)
  1882. return -ENOMEM;
  1883. skb_reserve(skb, hl);
  1884. if (copy_from_user(skb_put(skb, len), buf, len)) {
  1885. dev_kfree_skb(skb);
  1886. return -EFAULT;
  1887. }
  1888. ret = dev->drv[drvidx]->interface->writebuf_skb(drvidx, chan, 1, skb);
  1889. if (ret <= 0)
  1890. dev_kfree_skb(skb);
  1891. if (ret > 0)
  1892. dev->obytes[isdn_dc2minor(drvidx, chan)] += ret;
  1893. return ret;
  1894. }
  1895. /*
  1896. * Return: length of data on success, -ERRcode on failure.
  1897. */
  1898. int
  1899. isdn_writebuf_skb_stub(int drvidx, int chan, int ack, struct sk_buff *skb)
  1900. {
  1901. int ret;
  1902. struct sk_buff *nskb = NULL;
  1903. int v110_ret = skb->len;
  1904. int idx = isdn_dc2minor(drvidx, chan);
  1905. if (dev->v110[idx]) {
  1906. atomic_inc(&dev->v110use[idx]);
  1907. nskb = isdn_v110_encode(dev->v110[idx], skb);
  1908. atomic_dec(&dev->v110use[idx]);
  1909. if (!nskb)
  1910. return 0;
  1911. v110_ret = *((int *)nskb->data);
  1912. skb_pull(nskb, sizeof(int));
  1913. if (!nskb->len) {
  1914. dev_kfree_skb(nskb);
  1915. return v110_ret;
  1916. }
  1917. /* V.110 must always be acknowledged */
  1918. ack = 1;
  1919. ret = dev->drv[drvidx]->interface->writebuf_skb(drvidx, chan, ack, nskb);
  1920. } else {
  1921. int hl = dev->drv[drvidx]->interface->hl_hdrlen;
  1922. if( skb_headroom(skb) < hl ){
  1923. /*
  1924. * This should only occur when new HL driver with
  1925. * increased hl_hdrlen was loaded after netdevice
  1926. * was created and connected to the new driver.
  1927. *
  1928. * The V.110 branch (re-allocates on its own) does
  1929. * not need this
  1930. */
  1931. struct sk_buff * skb_tmp;
  1932. skb_tmp = skb_realloc_headroom(skb, hl);
  1933. printk(KERN_DEBUG "isdn_writebuf_skb_stub: reallocating headroom%s\n", skb_tmp ? "" : " failed");
  1934. if (!skb_tmp) return -ENOMEM; /* 0 better? */
  1935. ret = dev->drv[drvidx]->interface->writebuf_skb(drvidx, chan, ack, skb_tmp);
  1936. if( ret > 0 ){
  1937. dev_kfree_skb(skb);
  1938. } else {
  1939. dev_kfree_skb(skb_tmp);
  1940. }
  1941. } else {
  1942. ret = dev->drv[drvidx]->interface->writebuf_skb(drvidx, chan, ack, skb);
  1943. }
  1944. }
  1945. if (ret > 0) {
  1946. dev->obytes[idx] += ret;
  1947. if (dev->v110[idx]) {
  1948. atomic_inc(&dev->v110use[idx]);
  1949. dev->v110[idx]->skbuser++;
  1950. atomic_dec(&dev->v110use[idx]);
  1951. /* For V.110 return unencoded data length */
  1952. ret = v110_ret;
  1953. /* if the complete frame was send we free the skb;
  1954. if not upper function will requeue the skb */
  1955. if (ret == skb->len)
  1956. dev_kfree_skb(skb);
  1957. }
  1958. } else
  1959. if (dev->v110[idx])
  1960. dev_kfree_skb(nskb);
  1961. return ret;
  1962. }
  1963. static int
  1964. isdn_add_channels(isdn_driver_t *d, int drvidx, int n, int adding)
  1965. {
  1966. int j, k, m;
  1967. init_waitqueue_head(&d->st_waitq);
  1968. if (d->flags & DRV_FLAG_RUNNING)
  1969. return -1;
  1970. if (n < 1) return 0;
  1971. m = (adding) ? d->channels + n : n;
  1972. if (dev->channels + n > ISDN_MAX_CHANNELS) {
  1973. printk(KERN_WARNING "register_isdn: Max. %d channels supported\n",
  1974. ISDN_MAX_CHANNELS);
  1975. return -1;
  1976. }
  1977. if ((adding) && (d->rcverr))
  1978. kfree(d->rcverr);
  1979. if (!(d->rcverr = kzalloc(sizeof(int) * m, GFP_ATOMIC))) {
  1980. printk(KERN_WARNING "register_isdn: Could not alloc rcverr\n");
  1981. return -1;
  1982. }
  1983. if ((adding) && (d->rcvcount))
  1984. kfree(d->rcvcount);
  1985. if (!(d->rcvcount = kzalloc(sizeof(int) * m, GFP_ATOMIC))) {
  1986. printk(KERN_WARNING "register_isdn: Could not alloc rcvcount\n");
  1987. if (!adding)
  1988. kfree(d->rcverr);
  1989. return -1;
  1990. }
  1991. if ((adding) && (d->rpqueue)) {
  1992. for (j = 0; j < d->channels; j++)
  1993. skb_queue_purge(&d->rpqueue[j]);
  1994. kfree(d->rpqueue);
  1995. }
  1996. if (!(d->rpqueue = kmalloc(sizeof(struct sk_buff_head) * m, GFP_ATOMIC))) {
  1997. printk(KERN_WARNING "register_isdn: Could not alloc rpqueue\n");
  1998. if (!adding) {
  1999. kfree(d->rcvcount);
  2000. kfree(d->rcverr);
  2001. }
  2002. return -1;
  2003. }
  2004. for (j = 0; j < m; j++) {
  2005. skb_queue_head_init(&d->rpqueue[j]);
  2006. }
  2007. if ((adding) && (d->rcv_waitq))
  2008. kfree(d->rcv_waitq);
  2009. d->rcv_waitq = kmalloc(sizeof(wait_queue_head_t) * 2 * m, GFP_ATOMIC);
  2010. if (!d->rcv_waitq) {
  2011. printk(KERN_WARNING "register_isdn: Could not alloc rcv_waitq\n");
  2012. if (!adding) {
  2013. kfree(d->rpqueue);
  2014. kfree(d->rcvcount);
  2015. kfree(d->rcverr);
  2016. }
  2017. return -1;
  2018. }
  2019. d->snd_waitq = d->rcv_waitq + m;
  2020. for (j = 0; j < m; j++) {
  2021. init_waitqueue_head(&d->rcv_waitq[j]);
  2022. init_waitqueue_head(&d->snd_waitq[j]);
  2023. }
  2024. dev->channels += n;
  2025. for (j = d->channels; j < m; j++)
  2026. for (k = 0; k < ISDN_MAX_CHANNELS; k++)
  2027. if (dev->chanmap[k] < 0) {
  2028. dev->chanmap[k] = j;
  2029. dev->drvmap[k] = drvidx;
  2030. break;
  2031. }
  2032. d->channels = m;
  2033. return 0;
  2034. }
  2035. /*
  2036. * Low-level-driver registration
  2037. */
  2038. static void
  2039. set_global_features(void)
  2040. {
  2041. int drvidx;
  2042. dev->global_features = 0;
  2043. for (drvidx = 0; drvidx < ISDN_MAX_DRIVERS; drvidx++) {
  2044. if (!dev->drv[drvidx])
  2045. continue;
  2046. if (dev->drv[drvidx]->interface)
  2047. dev->global_features |= dev->drv[drvidx]->interface->features;
  2048. }
  2049. }
  2050. #ifdef CONFIG_ISDN_DIVERSION
  2051. static char *map_drvname(int di)
  2052. {
  2053. if ((di < 0) || (di >= ISDN_MAX_DRIVERS))
  2054. return(NULL);
  2055. return(dev->drvid[di]); /* driver name */
  2056. } /* map_drvname */
  2057. static int map_namedrv(char *id)
  2058. { int i;
  2059. for (i = 0; i < ISDN_MAX_DRIVERS; i++)
  2060. { if (!strcmp(dev->drvid[i],id))
  2061. return(i);
  2062. }
  2063. return(-1);
  2064. } /* map_namedrv */
  2065. int DIVERT_REG_NAME(isdn_divert_if *i_div)
  2066. {
  2067. if (i_div->if_magic != DIVERT_IF_MAGIC)
  2068. return(DIVERT_VER_ERR);
  2069. switch (i_div->cmd)
  2070. {
  2071. case DIVERT_CMD_REL:
  2072. if (divert_if != i_div)
  2073. return(DIVERT_REL_ERR);
  2074. divert_if = NULL; /* free interface */
  2075. return(DIVERT_NO_ERR);
  2076. case DIVERT_CMD_REG:
  2077. if (divert_if)
  2078. return(DIVERT_REG_ERR);
  2079. i_div->ll_cmd = isdn_command; /* set command function */
  2080. i_div->drv_to_name = map_drvname;
  2081. i_div->name_to_drv = map_namedrv;
  2082. divert_if = i_div; /* remember interface */
  2083. return(DIVERT_NO_ERR);
  2084. default:
  2085. return(DIVERT_CMD_ERR);
  2086. }
  2087. } /* DIVERT_REG_NAME */
  2088. EXPORT_SYMBOL(DIVERT_REG_NAME);
  2089. #endif /* CONFIG_ISDN_DIVERSION */
  2090. EXPORT_SYMBOL(register_isdn);
  2091. #ifdef CONFIG_ISDN_PPP
  2092. EXPORT_SYMBOL(isdn_ppp_register_compressor);
  2093. EXPORT_SYMBOL(isdn_ppp_unregister_compressor);
  2094. #endif
  2095. int
  2096. register_isdn(isdn_if * i)
  2097. {
  2098. isdn_driver_t *d;
  2099. int j;
  2100. ulong flags;
  2101. int drvidx;
  2102. if (dev->drivers >= ISDN_MAX_DRIVERS) {
  2103. printk(KERN_WARNING "register_isdn: Max. %d drivers supported\n",
  2104. ISDN_MAX_DRIVERS);
  2105. return 0;
  2106. }
  2107. if (!i->writebuf_skb) {
  2108. printk(KERN_WARNING "register_isdn: No write routine given.\n");
  2109. return 0;
  2110. }
  2111. if (!(d = kzalloc(sizeof(isdn_driver_t), GFP_KERNEL))) {
  2112. printk(KERN_WARNING "register_isdn: Could not alloc driver-struct\n");
  2113. return 0;
  2114. }
  2115. d->maxbufsize = i->maxbufsize;
  2116. d->pktcount = 0;
  2117. d->stavail = 0;
  2118. d->flags = DRV_FLAG_LOADED;
  2119. d->online = 0;
  2120. d->interface = i;
  2121. d->channels = 0;
  2122. spin_lock_irqsave(&dev->lock, flags);
  2123. for (drvidx = 0; drvidx < ISDN_MAX_DRIVERS; drvidx++)
  2124. if (!dev->drv[drvidx])
  2125. break;
  2126. if (isdn_add_channels(d, drvidx, i->channels, 0)) {
  2127. spin_unlock_irqrestore(&dev->lock, flags);
  2128. kfree(d);
  2129. return 0;
  2130. }
  2131. i->channels = drvidx;
  2132. i->rcvcallb_skb = isdn_receive_skb_callback;
  2133. i->statcallb = isdn_status_callback;
  2134. if (!strlen(i->id))
  2135. sprintf(i->id, "line%d", drvidx);
  2136. for (j = 0; j < drvidx; j++)
  2137. if (!strcmp(i->id, dev->drvid[j]))
  2138. sprintf(i->id, "line%d", drvidx);
  2139. dev->drv[drvidx] = d;
  2140. strcpy(dev->drvid[drvidx], i->id);
  2141. isdn_info_update();
  2142. dev->drivers++;
  2143. set_global_features();
  2144. spin_unlock_irqrestore(&dev->lock, flags);
  2145. return 1;
  2146. }
  2147. /*
  2148. *****************************************************************************
  2149. * And now the modules code.
  2150. *****************************************************************************
  2151. */
  2152. static char *
  2153. isdn_getrev(const char *revision)
  2154. {
  2155. char *rev;
  2156. char *p;
  2157. if ((p = strchr(revision, ':'))) {
  2158. rev = p + 2;
  2159. p = strchr(rev, '$');
  2160. *--p = 0;
  2161. } else
  2162. rev = "???";
  2163. return rev;
  2164. }
  2165. /*
  2166. * Allocate and initialize all data, register modem-devices
  2167. */
  2168. static int __init isdn_init(void)
  2169. {
  2170. int i;
  2171. char tmprev[50];
  2172. if (!(dev = vmalloc(sizeof(isdn_dev)))) {
  2173. printk(KERN_WARNING "isdn: Could not allocate device-struct.\n");
  2174. return -EIO;
  2175. }
  2176. memset((char *) dev, 0, sizeof(isdn_dev));
  2177. init_timer(&dev->timer);
  2178. dev->timer.function = isdn_timer_funct;
  2179. spin_lock_init(&dev->lock);
  2180. spin_lock_init(&dev->timerlock);
  2181. #ifdef MODULE
  2182. dev->owner = THIS_MODULE;
  2183. #endif
  2184. mutex_init(&dev->mtx);
  2185. init_waitqueue_head(&dev->info_waitq);
  2186. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  2187. dev->drvmap[i] = -1;
  2188. dev->chanmap[i] = -1;
  2189. dev->m_idx[i] = -1;
  2190. strcpy(dev->num[i], "???");
  2191. init_waitqueue_head(&dev->mdm.info[i].open_wait);
  2192. init_waitqueue_head(&dev->mdm.info[i].close_wait);
  2193. }
  2194. if (register_chrdev(ISDN_MAJOR, "isdn", &isdn_fops)) {
  2195. printk(KERN_WARNING "isdn: Could not register control devices\n");
  2196. vfree(dev);
  2197. return -EIO;
  2198. }
  2199. if ((isdn_tty_modem_init()) < 0) {
  2200. printk(KERN_WARNING "isdn: Could not register tty devices\n");
  2201. vfree(dev);
  2202. unregister_chrdev(ISDN_MAJOR, "isdn");
  2203. return -EIO;
  2204. }
  2205. #ifdef CONFIG_ISDN_PPP
  2206. if (isdn_ppp_init() < 0) {
  2207. printk(KERN_WARNING "isdn: Could not create PPP-device-structs\n");
  2208. isdn_tty_exit();
  2209. unregister_chrdev(ISDN_MAJOR, "isdn");
  2210. vfree(dev);
  2211. return -EIO;
  2212. }
  2213. #endif /* CONFIG_ISDN_PPP */
  2214. strcpy(tmprev, isdn_revision);
  2215. printk(KERN_NOTICE "ISDN subsystem Rev: %s/", isdn_getrev(tmprev));
  2216. strcpy(tmprev, isdn_tty_revision);
  2217. printk("%s/", isdn_getrev(tmprev));
  2218. strcpy(tmprev, isdn_net_revision);
  2219. printk("%s/", isdn_getrev(tmprev));
  2220. strcpy(tmprev, isdn_ppp_revision);
  2221. printk("%s/", isdn_getrev(tmprev));
  2222. strcpy(tmprev, isdn_audio_revision);
  2223. printk("%s/", isdn_getrev(tmprev));
  2224. strcpy(tmprev, isdn_v110_revision);
  2225. printk("%s", isdn_getrev(tmprev));
  2226. #ifdef MODULE
  2227. printk(" loaded\n");
  2228. #else
  2229. printk("\n");
  2230. #endif
  2231. isdn_info_update();
  2232. return 0;
  2233. }
  2234. /*
  2235. * Unload module
  2236. */
  2237. static void __exit isdn_exit(void)
  2238. {
  2239. #ifdef CONFIG_ISDN_PPP
  2240. isdn_ppp_cleanup();
  2241. #endif
  2242. if (isdn_net_rmall() < 0) {
  2243. printk(KERN_WARNING "isdn: net-device busy, remove cancelled\n");
  2244. return;
  2245. }
  2246. isdn_tty_exit();
  2247. unregister_chrdev(ISDN_MAJOR, "isdn");
  2248. del_timer(&dev->timer);
  2249. /* call vfree with interrupts enabled, else it will hang */
  2250. vfree(dev);
  2251. printk(KERN_NOTICE "ISDN-subsystem unloaded\n");
  2252. }
  2253. module_init(isdn_init);
  2254. module_exit(isdn_exit);