isdn_common.c 58 KB

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