callc.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792
  1. /* $Id: callc.c,v 2.59.2.4 2004/02/11 13:21:32 keil Exp $
  2. *
  3. * Author Karsten Keil
  4. * Copyright by Karsten Keil <keil@isdn4linux.de>
  5. *
  6. * This software may be used and distributed according to the terms
  7. * of the GNU General Public License, incorporated herein by reference.
  8. *
  9. * For changes and modifications please read
  10. * Documentation/isdn/HiSax.cert
  11. *
  12. * based on the teles driver from Jan den Ouden
  13. *
  14. * Thanks to Jan den Ouden
  15. * Fritz Elfert
  16. *
  17. */
  18. #include <linux/module.h>
  19. #include <linux/slab.h>
  20. #include <linux/init.h>
  21. #include "hisax.h"
  22. #include <linux/isdn/capicmd.h>
  23. const char *lli_revision = "$Revision: 2.59.2.4 $";
  24. extern struct IsdnCard cards[];
  25. static int init_b_st(struct Channel *chanp, int incoming);
  26. static void release_b_st(struct Channel *chanp);
  27. static struct Fsm callcfsm;
  28. static int chancount;
  29. /* experimental REJECT after ALERTING for CALLBACK to beat the 4s delay */
  30. #define ALERT_REJECT 0
  31. /* Value to delay the sending of the first B-channel packet after CONNECT
  32. * here is no value given by ITU, but experience shows that 300 ms will
  33. * work on many networks, if you or your other side is behind local exchanges
  34. * a greater value may be recommented. If the delay is to short the first paket
  35. * will be lost and autodetect on many comercial routers goes wrong !
  36. * You can adjust this value on runtime with
  37. * hisaxctrl <id> 2 <value>
  38. * value is in milliseconds
  39. */
  40. #define DEFAULT_B_DELAY 300
  41. /* Flags for remembering action done in lli */
  42. #define FLG_START_B 0
  43. /*
  44. * Find card with given driverId
  45. */
  46. static inline struct IsdnCardState *
  47. hisax_findcard(int driverid)
  48. {
  49. int i;
  50. for (i = 0; i < nrcards; i++)
  51. if (cards[i].cs)
  52. if (cards[i].cs->myid == driverid)
  53. return (cards[i].cs);
  54. return (struct IsdnCardState *) 0;
  55. }
  56. static __printf(3, 4) void
  57. link_debug(struct Channel *chanp, int direction, char *fmt, ...)
  58. {
  59. va_list args;
  60. char tmp[16];
  61. va_start(args, fmt);
  62. sprintf(tmp, "Ch%d %s ", chanp->chan,
  63. direction ? "LL->HL" : "HL->LL");
  64. VHiSax_putstatus(chanp->cs, tmp, fmt, args);
  65. va_end(args);
  66. }
  67. enum {
  68. ST_NULL, /* 0 inactive */
  69. ST_OUT_DIAL, /* 1 outgoing, SETUP send; awaiting confirm */
  70. ST_IN_WAIT_LL, /* 2 incoming call received; wait for LL confirm */
  71. ST_IN_ALERT_SENT, /* 3 incoming call received; ALERT send */
  72. ST_IN_WAIT_CONN_ACK, /* 4 incoming CONNECT send; awaiting CONN_ACK */
  73. ST_WAIT_BCONN, /* 5 CONNECT/CONN_ACK received, awaiting b-channel prot. estbl. */
  74. ST_ACTIVE, /* 6 active, b channel prot. established */
  75. ST_WAIT_BRELEASE, /* 7 call clear. (initiator), awaiting b channel prot. rel. */
  76. ST_WAIT_BREL_DISC, /* 8 call clear. (receiver), DISCONNECT req. received */
  77. ST_WAIT_DCOMMAND, /* 9 call clear. (receiver), awaiting DCHANNEL message */
  78. ST_WAIT_DRELEASE, /* 10 DISCONNECT sent, awaiting RELEASE */
  79. ST_WAIT_D_REL_CNF, /* 11 RELEASE sent, awaiting RELEASE confirm */
  80. ST_IN_PROCEED_SEND, /* 12 incoming call, proceeding send */
  81. };
  82. #define STATE_COUNT (ST_IN_PROCEED_SEND + 1)
  83. static char *strState[] =
  84. {
  85. "ST_NULL",
  86. "ST_OUT_DIAL",
  87. "ST_IN_WAIT_LL",
  88. "ST_IN_ALERT_SENT",
  89. "ST_IN_WAIT_CONN_ACK",
  90. "ST_WAIT_BCONN",
  91. "ST_ACTIVE",
  92. "ST_WAIT_BRELEASE",
  93. "ST_WAIT_BREL_DISC",
  94. "ST_WAIT_DCOMMAND",
  95. "ST_WAIT_DRELEASE",
  96. "ST_WAIT_D_REL_CNF",
  97. "ST_IN_PROCEED_SEND",
  98. };
  99. enum {
  100. EV_DIAL, /* 0 */
  101. EV_SETUP_CNF, /* 1 */
  102. EV_ACCEPTB, /* 2 */
  103. EV_DISCONNECT_IND, /* 3 */
  104. EV_RELEASE, /* 4 */
  105. EV_LEASED, /* 5 */
  106. EV_LEASED_REL, /* 6 */
  107. EV_SETUP_IND, /* 7 */
  108. EV_ACCEPTD, /* 8 */
  109. EV_SETUP_CMPL_IND, /* 9 */
  110. EV_BC_EST, /* 10 */
  111. EV_WRITEBUF, /* 11 */
  112. EV_HANGUP, /* 12 */
  113. EV_BC_REL, /* 13 */
  114. EV_CINF, /* 14 */
  115. EV_SUSPEND, /* 15 */
  116. EV_RESUME, /* 16 */
  117. EV_NOSETUP_RSP, /* 17 */
  118. EV_SETUP_ERR, /* 18 */
  119. EV_CONNECT_ERR, /* 19 */
  120. EV_PROCEED, /* 20 */
  121. EV_ALERT, /* 21 */
  122. EV_REDIR, /* 22 */
  123. };
  124. #define EVENT_COUNT (EV_REDIR + 1)
  125. static char *strEvent[] =
  126. {
  127. "EV_DIAL",
  128. "EV_SETUP_CNF",
  129. "EV_ACCEPTB",
  130. "EV_DISCONNECT_IND",
  131. "EV_RELEASE",
  132. "EV_LEASED",
  133. "EV_LEASED_REL",
  134. "EV_SETUP_IND",
  135. "EV_ACCEPTD",
  136. "EV_SETUP_CMPL_IND",
  137. "EV_BC_EST",
  138. "EV_WRITEBUF",
  139. "EV_HANGUP",
  140. "EV_BC_REL",
  141. "EV_CINF",
  142. "EV_SUSPEND",
  143. "EV_RESUME",
  144. "EV_NOSETUP_RSP",
  145. "EV_SETUP_ERR",
  146. "EV_CONNECT_ERR",
  147. "EV_PROCEED",
  148. "EV_ALERT",
  149. "EV_REDIR",
  150. };
  151. static inline void
  152. HL_LL(struct Channel *chanp, int command)
  153. {
  154. isdn_ctrl ic;
  155. ic.driver = chanp->cs->myid;
  156. ic.command = command;
  157. ic.arg = chanp->chan;
  158. chanp->cs->iif.statcallb(&ic);
  159. }
  160. static inline void
  161. lli_deliver_cause(struct Channel *chanp)
  162. {
  163. isdn_ctrl ic;
  164. if (!chanp->proc)
  165. return;
  166. if (chanp->proc->para.cause == NO_CAUSE)
  167. return;
  168. ic.driver = chanp->cs->myid;
  169. ic.command = ISDN_STAT_CAUSE;
  170. ic.arg = chanp->chan;
  171. if (chanp->cs->protocol == ISDN_PTYPE_EURO)
  172. sprintf(ic.parm.num, "E%02X%02X", chanp->proc->para.loc & 0x7f,
  173. chanp->proc->para.cause & 0x7f);
  174. else
  175. sprintf(ic.parm.num, "%02X%02X", chanp->proc->para.loc & 0x7f,
  176. chanp->proc->para.cause & 0x7f);
  177. chanp->cs->iif.statcallb(&ic);
  178. }
  179. static inline void
  180. lli_close(struct FsmInst *fi)
  181. {
  182. struct Channel *chanp = fi->userdata;
  183. FsmChangeState(fi, ST_NULL);
  184. chanp->Flags = 0;
  185. chanp->cs->cardmsg(chanp->cs, MDL_INFO_REL, (void *) (long)chanp->chan);
  186. }
  187. static void
  188. lli_leased_in(struct FsmInst *fi, int event, void *arg)
  189. {
  190. struct Channel *chanp = fi->userdata;
  191. isdn_ctrl ic;
  192. int ret;
  193. if (!chanp->leased)
  194. return;
  195. chanp->cs->cardmsg(chanp->cs, MDL_INFO_SETUP, (void *) (long)chanp->chan);
  196. FsmChangeState(fi, ST_IN_WAIT_LL);
  197. if (chanp->debug & 1)
  198. link_debug(chanp, 0, "STAT_ICALL_LEASED");
  199. ic.driver = chanp->cs->myid;
  200. ic.command = ((chanp->chan < 2) ? ISDN_STAT_ICALL : ISDN_STAT_ICALLW);
  201. ic.arg = chanp->chan;
  202. ic.parm.setup.si1 = 7;
  203. ic.parm.setup.si2 = 0;
  204. ic.parm.setup.plan = 0;
  205. ic.parm.setup.screen = 0;
  206. sprintf(ic.parm.setup.eazmsn, "%d", chanp->chan + 1);
  207. sprintf(ic.parm.setup.phone, "LEASED%d", chanp->cs->myid);
  208. ret = chanp->cs->iif.statcallb(&ic);
  209. if (chanp->debug & 1)
  210. link_debug(chanp, 1, "statcallb ret=%d", ret);
  211. if (!ret) {
  212. chanp->cs->cardmsg(chanp->cs, MDL_INFO_REL, (void *) (long)chanp->chan);
  213. FsmChangeState(fi, ST_NULL);
  214. }
  215. }
  216. /*
  217. * Dial out
  218. */
  219. static void
  220. lli_init_bchan_out(struct FsmInst *fi, int event, void *arg)
  221. {
  222. struct Channel *chanp = fi->userdata;
  223. FsmChangeState(fi, ST_WAIT_BCONN);
  224. if (chanp->debug & 1)
  225. link_debug(chanp, 0, "STAT_DCONN");
  226. HL_LL(chanp, ISDN_STAT_DCONN);
  227. init_b_st(chanp, 0);
  228. chanp->b_st->lli.l4l3(chanp->b_st, DL_ESTABLISH | REQUEST, NULL);
  229. }
  230. static void
  231. lli_prep_dialout(struct FsmInst *fi, int event, void *arg)
  232. {
  233. struct Channel *chanp = fi->userdata;
  234. FsmDelTimer(&chanp->drel_timer, 60);
  235. FsmDelTimer(&chanp->dial_timer, 73);
  236. chanp->l2_active_protocol = chanp->l2_protocol;
  237. chanp->incoming = 0;
  238. chanp->cs->cardmsg(chanp->cs, MDL_INFO_SETUP, (void *) (long)chanp->chan);
  239. if (chanp->leased) {
  240. lli_init_bchan_out(fi, event, arg);
  241. } else {
  242. FsmChangeState(fi, ST_OUT_DIAL);
  243. chanp->d_st->lli.l4l3(chanp->d_st, CC_SETUP | REQUEST, chanp);
  244. }
  245. }
  246. static void
  247. lli_resume(struct FsmInst *fi, int event, void *arg)
  248. {
  249. struct Channel *chanp = fi->userdata;
  250. FsmDelTimer(&chanp->drel_timer, 60);
  251. FsmDelTimer(&chanp->dial_timer, 73);
  252. chanp->l2_active_protocol = chanp->l2_protocol;
  253. chanp->incoming = 0;
  254. chanp->cs->cardmsg(chanp->cs, MDL_INFO_SETUP, (void *) (long)chanp->chan);
  255. if (chanp->leased) {
  256. lli_init_bchan_out(fi, event, arg);
  257. } else {
  258. FsmChangeState(fi, ST_OUT_DIAL);
  259. chanp->d_st->lli.l4l3(chanp->d_st, CC_RESUME | REQUEST, chanp);
  260. }
  261. }
  262. static void
  263. lli_go_active(struct FsmInst *fi, int event, void *arg)
  264. {
  265. struct Channel *chanp = fi->userdata;
  266. isdn_ctrl ic;
  267. FsmChangeState(fi, ST_ACTIVE);
  268. chanp->data_open = !0;
  269. if (chanp->bcs->conmsg)
  270. strcpy(ic.parm.num, chanp->bcs->conmsg);
  271. else
  272. ic.parm.num[0] = 0;
  273. if (chanp->debug & 1)
  274. link_debug(chanp, 0, "STAT_BCONN %s", ic.parm.num);
  275. ic.driver = chanp->cs->myid;
  276. ic.command = ISDN_STAT_BCONN;
  277. ic.arg = chanp->chan;
  278. chanp->cs->iif.statcallb(&ic);
  279. chanp->cs->cardmsg(chanp->cs, MDL_INFO_CONN, (void *) (long)chanp->chan);
  280. }
  281. /*
  282. * RESUME
  283. */
  284. /* incoming call */
  285. static void
  286. lli_deliver_call(struct FsmInst *fi, int event, void *arg)
  287. {
  288. struct Channel *chanp = fi->userdata;
  289. isdn_ctrl ic;
  290. int ret;
  291. chanp->cs->cardmsg(chanp->cs, MDL_INFO_SETUP, (void *) (long)chanp->chan);
  292. /*
  293. * Report incoming calls only once to linklevel, use CallFlags
  294. * which is set to 3 with each broadcast message in isdnl1.c
  295. * and resetted if a interface answered the STAT_ICALL.
  296. */
  297. if (1) { /* for only one TEI */
  298. FsmChangeState(fi, ST_IN_WAIT_LL);
  299. if (chanp->debug & 1)
  300. link_debug(chanp, 0, (chanp->chan < 2) ? "STAT_ICALL" : "STAT_ICALLW");
  301. ic.driver = chanp->cs->myid;
  302. ic.command = ((chanp->chan < 2) ? ISDN_STAT_ICALL : ISDN_STAT_ICALLW);
  303. ic.arg = chanp->chan;
  304. /*
  305. * No need to return "unknown" for calls without OAD,
  306. * cause that's handled in linklevel now (replaced by '0')
  307. */
  308. memcpy(&ic.parm.setup, &chanp->proc->para.setup, sizeof(setup_parm));
  309. ret = chanp->cs->iif.statcallb(&ic);
  310. if (chanp->debug & 1)
  311. link_debug(chanp, 1, "statcallb ret=%d", ret);
  312. switch (ret) {
  313. case 1: /* OK, someone likes this call */
  314. FsmDelTimer(&chanp->drel_timer, 61);
  315. FsmChangeState(fi, ST_IN_ALERT_SENT);
  316. chanp->d_st->lli.l4l3(chanp->d_st, CC_ALERTING | REQUEST, chanp->proc);
  317. break;
  318. case 5: /* direct redirect */
  319. case 4: /* Proceeding desired */
  320. FsmDelTimer(&chanp->drel_timer, 61);
  321. FsmChangeState(fi, ST_IN_PROCEED_SEND);
  322. chanp->d_st->lli.l4l3(chanp->d_st, CC_PROCEED_SEND | REQUEST, chanp->proc);
  323. if (ret == 5) {
  324. memcpy(&chanp->setup, &ic.parm.setup, sizeof(setup_parm));
  325. chanp->d_st->lli.l4l3(chanp->d_st, CC_REDIR | REQUEST, chanp->proc);
  326. }
  327. break;
  328. case 2: /* Rejecting Call */
  329. break;
  330. case 3: /* incomplete number */
  331. FsmDelTimer(&chanp->drel_timer, 61);
  332. chanp->d_st->lli.l4l3(chanp->d_st, CC_MORE_INFO | REQUEST, chanp->proc);
  333. break;
  334. case 0: /* OK, nobody likes this call */
  335. default: /* statcallb problems */
  336. chanp->d_st->lli.l4l3(chanp->d_st, CC_IGNORE | REQUEST, chanp->proc);
  337. chanp->cs->cardmsg(chanp->cs, MDL_INFO_REL, (void *) (long)chanp->chan);
  338. FsmChangeState(fi, ST_NULL);
  339. break;
  340. }
  341. } else {
  342. chanp->d_st->lli.l4l3(chanp->d_st, CC_IGNORE | REQUEST, chanp->proc);
  343. chanp->cs->cardmsg(chanp->cs, MDL_INFO_REL, (void *) (long)chanp->chan);
  344. }
  345. }
  346. static void
  347. lli_send_dconnect(struct FsmInst *fi, int event, void *arg)
  348. {
  349. struct Channel *chanp = fi->userdata;
  350. FsmChangeState(fi, ST_IN_WAIT_CONN_ACK);
  351. chanp->d_st->lli.l4l3(chanp->d_st, CC_SETUP | RESPONSE, chanp->proc);
  352. }
  353. static void
  354. lli_send_alert(struct FsmInst *fi, int event, void *arg)
  355. {
  356. struct Channel *chanp = fi->userdata;
  357. FsmChangeState(fi, ST_IN_ALERT_SENT);
  358. chanp->d_st->lli.l4l3(chanp->d_st, CC_ALERTING | REQUEST, chanp->proc);
  359. }
  360. static void
  361. lli_send_redir(struct FsmInst *fi, int event, void *arg)
  362. {
  363. struct Channel *chanp = fi->userdata;
  364. chanp->d_st->lli.l4l3(chanp->d_st, CC_REDIR | REQUEST, chanp->proc);
  365. }
  366. static void
  367. lli_init_bchan_in(struct FsmInst *fi, int event, void *arg)
  368. {
  369. struct Channel *chanp = fi->userdata;
  370. FsmChangeState(fi, ST_WAIT_BCONN);
  371. if (chanp->debug & 1)
  372. link_debug(chanp, 0, "STAT_DCONN");
  373. HL_LL(chanp, ISDN_STAT_DCONN);
  374. chanp->l2_active_protocol = chanp->l2_protocol;
  375. chanp->incoming = !0;
  376. init_b_st(chanp, !0);
  377. chanp->b_st->lli.l4l3(chanp->b_st, DL_ESTABLISH | REQUEST, NULL);
  378. }
  379. static void
  380. lli_setup_rsp(struct FsmInst *fi, int event, void *arg)
  381. {
  382. struct Channel *chanp = fi->userdata;
  383. if (chanp->leased) {
  384. lli_init_bchan_in(fi, event, arg);
  385. } else {
  386. FsmChangeState(fi, ST_IN_WAIT_CONN_ACK);
  387. #ifdef WANT_ALERT
  388. chanp->d_st->lli.l4l3(chanp->d_st, CC_ALERTING | REQUEST, chanp->proc);
  389. #endif
  390. chanp->d_st->lli.l4l3(chanp->d_st, CC_SETUP | RESPONSE, chanp->proc);
  391. }
  392. }
  393. /* Call suspend */
  394. static void
  395. lli_suspend(struct FsmInst *fi, int event, void *arg)
  396. {
  397. struct Channel *chanp = fi->userdata;
  398. chanp->d_st->lli.l4l3(chanp->d_st, CC_SUSPEND | REQUEST, chanp->proc);
  399. }
  400. /* Call clearing */
  401. static void
  402. lli_leased_hup(struct FsmInst *fi, struct Channel *chanp)
  403. {
  404. isdn_ctrl ic;
  405. ic.driver = chanp->cs->myid;
  406. ic.command = ISDN_STAT_CAUSE;
  407. ic.arg = chanp->chan;
  408. sprintf(ic.parm.num, "L0010");
  409. chanp->cs->iif.statcallb(&ic);
  410. if (chanp->debug & 1)
  411. link_debug(chanp, 0, "STAT_DHUP");
  412. HL_LL(chanp, ISDN_STAT_DHUP);
  413. lli_close(fi);
  414. }
  415. static void
  416. lli_disconnect_req(struct FsmInst *fi, int event, void *arg)
  417. {
  418. struct Channel *chanp = fi->userdata;
  419. if (chanp->leased) {
  420. lli_leased_hup(fi, chanp);
  421. } else {
  422. FsmChangeState(fi, ST_WAIT_DRELEASE);
  423. if (chanp->proc)
  424. chanp->proc->para.cause = 0x10; /* Normal Call Clearing */
  425. chanp->d_st->lli.l4l3(chanp->d_st, CC_DISCONNECT | REQUEST,
  426. chanp->proc);
  427. }
  428. }
  429. static void
  430. lli_disconnect_reject(struct FsmInst *fi, int event, void *arg)
  431. {
  432. struct Channel *chanp = fi->userdata;
  433. if (chanp->leased) {
  434. lli_leased_hup(fi, chanp);
  435. } else {
  436. FsmChangeState(fi, ST_WAIT_DRELEASE);
  437. if (chanp->proc)
  438. chanp->proc->para.cause = 0x15; /* Call Rejected */
  439. chanp->d_st->lli.l4l3(chanp->d_st, CC_DISCONNECT | REQUEST,
  440. chanp->proc);
  441. }
  442. }
  443. static void
  444. lli_dhup_close(struct FsmInst *fi, int event, void *arg)
  445. {
  446. struct Channel *chanp = fi->userdata;
  447. if (chanp->leased) {
  448. lli_leased_hup(fi, chanp);
  449. } else {
  450. if (chanp->debug & 1)
  451. link_debug(chanp, 0, "STAT_DHUP");
  452. lli_deliver_cause(chanp);
  453. HL_LL(chanp, ISDN_STAT_DHUP);
  454. lli_close(fi);
  455. }
  456. }
  457. static void
  458. lli_reject_req(struct FsmInst *fi, int event, void *arg)
  459. {
  460. struct Channel *chanp = fi->userdata;
  461. if (chanp->leased) {
  462. lli_leased_hup(fi, chanp);
  463. return;
  464. }
  465. #ifndef ALERT_REJECT
  466. if (chanp->proc)
  467. chanp->proc->para.cause = 0x15; /* Call Rejected */
  468. chanp->d_st->lli.l4l3(chanp->d_st, CC_REJECT | REQUEST, chanp->proc);
  469. lli_dhup_close(fi, event, arg);
  470. #else
  471. FsmRestartTimer(&chanp->drel_timer, 40, EV_HANGUP, NULL, 63);
  472. FsmChangeState(fi, ST_IN_ALERT_SENT);
  473. chanp->d_st->lli.l4l3(chanp->d_st, CC_ALERTING | REQUEST, chanp->proc);
  474. #endif
  475. }
  476. static void
  477. lli_disconn_bchan(struct FsmInst *fi, int event, void *arg)
  478. {
  479. struct Channel *chanp = fi->userdata;
  480. chanp->data_open = 0;
  481. FsmChangeState(fi, ST_WAIT_BRELEASE);
  482. chanp->b_st->lli.l4l3(chanp->b_st, DL_RELEASE | REQUEST, NULL);
  483. }
  484. static void
  485. lli_start_disc(struct FsmInst *fi, int event, void *arg)
  486. {
  487. struct Channel *chanp = fi->userdata;
  488. if (chanp->leased) {
  489. lli_leased_hup(fi, chanp);
  490. } else {
  491. lli_disconnect_req(fi, event, arg);
  492. }
  493. }
  494. static void
  495. lli_rel_b_disc(struct FsmInst *fi, int event, void *arg)
  496. {
  497. struct Channel *chanp = fi->userdata;
  498. release_b_st(chanp);
  499. lli_start_disc(fi, event, arg);
  500. }
  501. static void
  502. lli_bhup_disc(struct FsmInst *fi, int event, void *arg)
  503. {
  504. struct Channel *chanp = fi->userdata;
  505. if (chanp->debug & 1)
  506. link_debug(chanp, 0, "STAT_BHUP");
  507. HL_LL(chanp, ISDN_STAT_BHUP);
  508. lli_rel_b_disc(fi, event, arg);
  509. }
  510. static void
  511. lli_bhup_rel_b(struct FsmInst *fi, int event, void *arg)
  512. {
  513. struct Channel *chanp = fi->userdata;
  514. FsmChangeState(fi, ST_WAIT_DCOMMAND);
  515. chanp->data_open = 0;
  516. if (chanp->debug & 1)
  517. link_debug(chanp, 0, "STAT_BHUP");
  518. HL_LL(chanp, ISDN_STAT_BHUP);
  519. release_b_st(chanp);
  520. }
  521. static void
  522. lli_release_bchan(struct FsmInst *fi, int event, void *arg)
  523. {
  524. struct Channel *chanp = fi->userdata;
  525. chanp->data_open = 0;
  526. FsmChangeState(fi, ST_WAIT_BREL_DISC);
  527. chanp->b_st->lli.l4l3(chanp->b_st, DL_RELEASE | REQUEST, NULL);
  528. }
  529. static void
  530. lli_rel_b_dhup(struct FsmInst *fi, int event, void *arg)
  531. {
  532. struct Channel *chanp = fi->userdata;
  533. release_b_st(chanp);
  534. lli_dhup_close(fi, event, arg);
  535. }
  536. static void
  537. lli_bhup_dhup(struct FsmInst *fi, int event, void *arg)
  538. {
  539. struct Channel *chanp = fi->userdata;
  540. if (chanp->debug & 1)
  541. link_debug(chanp, 0, "STAT_BHUP");
  542. HL_LL(chanp, ISDN_STAT_BHUP);
  543. lli_rel_b_dhup(fi, event, arg);
  544. }
  545. static void
  546. lli_abort(struct FsmInst *fi, int event, void *arg)
  547. {
  548. struct Channel *chanp = fi->userdata;
  549. chanp->data_open = 0;
  550. chanp->b_st->lli.l4l3(chanp->b_st, DL_RELEASE | REQUEST, NULL);
  551. lli_bhup_dhup(fi, event, arg);
  552. }
  553. static void
  554. lli_release_req(struct FsmInst *fi, int event, void *arg)
  555. {
  556. struct Channel *chanp = fi->userdata;
  557. if (chanp->leased) {
  558. lli_leased_hup(fi, chanp);
  559. } else {
  560. FsmChangeState(fi, ST_WAIT_D_REL_CNF);
  561. chanp->d_st->lli.l4l3(chanp->d_st, CC_RELEASE | REQUEST,
  562. chanp->proc);
  563. }
  564. }
  565. static void
  566. lli_rel_b_release_req(struct FsmInst *fi, int event, void *arg)
  567. {
  568. struct Channel *chanp = fi->userdata;
  569. release_b_st(chanp);
  570. lli_release_req(fi, event, arg);
  571. }
  572. static void
  573. lli_bhup_release_req(struct FsmInst *fi, int event, void *arg)
  574. {
  575. struct Channel *chanp = fi->userdata;
  576. if (chanp->debug & 1)
  577. link_debug(chanp, 0, "STAT_BHUP");
  578. HL_LL(chanp, ISDN_STAT_BHUP);
  579. lli_rel_b_release_req(fi, event, arg);
  580. }
  581. /* processing charge info */
  582. static void
  583. lli_charge_info(struct FsmInst *fi, int event, void *arg)
  584. {
  585. struct Channel *chanp = fi->userdata;
  586. isdn_ctrl ic;
  587. ic.driver = chanp->cs->myid;
  588. ic.command = ISDN_STAT_CINF;
  589. ic.arg = chanp->chan;
  590. sprintf(ic.parm.num, "%d", chanp->proc->para.chargeinfo);
  591. chanp->cs->iif.statcallb(&ic);
  592. }
  593. /* error procedures */
  594. static void
  595. lli_dchan_not_ready(struct FsmInst *fi, int event, void *arg)
  596. {
  597. struct Channel *chanp = fi->userdata;
  598. if (chanp->debug & 1)
  599. link_debug(chanp, 0, "STAT_DHUP");
  600. HL_LL(chanp, ISDN_STAT_DHUP);
  601. }
  602. static void
  603. lli_no_setup_rsp(struct FsmInst *fi, int event, void *arg)
  604. {
  605. struct Channel *chanp = fi->userdata;
  606. if (chanp->debug & 1)
  607. link_debug(chanp, 0, "STAT_DHUP");
  608. HL_LL(chanp, ISDN_STAT_DHUP);
  609. lli_close(fi);
  610. }
  611. static void
  612. lli_error(struct FsmInst *fi, int event, void *arg)
  613. {
  614. FsmChangeState(fi, ST_WAIT_DRELEASE);
  615. }
  616. static void
  617. lli_failure_l(struct FsmInst *fi, int event, void *arg)
  618. {
  619. struct Channel *chanp = fi->userdata;
  620. isdn_ctrl ic;
  621. FsmChangeState(fi, ST_NULL);
  622. ic.driver = chanp->cs->myid;
  623. ic.command = ISDN_STAT_CAUSE;
  624. ic.arg = chanp->chan;
  625. sprintf(ic.parm.num, "L%02X%02X", 0, 0x2f);
  626. chanp->cs->iif.statcallb(&ic);
  627. HL_LL(chanp, ISDN_STAT_DHUP);
  628. chanp->Flags = 0;
  629. chanp->cs->cardmsg(chanp->cs, MDL_INFO_REL, (void *) (long)chanp->chan);
  630. }
  631. static void
  632. lli_rel_b_fail(struct FsmInst *fi, int event, void *arg)
  633. {
  634. struct Channel *chanp = fi->userdata;
  635. release_b_st(chanp);
  636. lli_failure_l(fi, event, arg);
  637. }
  638. static void
  639. lli_bhup_fail(struct FsmInst *fi, int event, void *arg)
  640. {
  641. struct Channel *chanp = fi->userdata;
  642. if (chanp->debug & 1)
  643. link_debug(chanp, 0, "STAT_BHUP");
  644. HL_LL(chanp, ISDN_STAT_BHUP);
  645. lli_rel_b_fail(fi, event, arg);
  646. }
  647. static void
  648. lli_failure_a(struct FsmInst *fi, int event, void *arg)
  649. {
  650. struct Channel *chanp = fi->userdata;
  651. chanp->data_open = 0;
  652. chanp->b_st->lli.l4l3(chanp->b_st, DL_RELEASE | REQUEST, NULL);
  653. lli_bhup_fail(fi, event, arg);
  654. }
  655. /* *INDENT-OFF* */
  656. static struct FsmNode fnlist[] __initdata =
  657. {
  658. {ST_NULL, EV_DIAL, lli_prep_dialout},
  659. {ST_NULL, EV_RESUME, lli_resume},
  660. {ST_NULL, EV_SETUP_IND, lli_deliver_call},
  661. {ST_NULL, EV_LEASED, lli_leased_in},
  662. {ST_OUT_DIAL, EV_SETUP_CNF, lli_init_bchan_out},
  663. {ST_OUT_DIAL, EV_HANGUP, lli_disconnect_req},
  664. {ST_OUT_DIAL, EV_DISCONNECT_IND, lli_release_req},
  665. {ST_OUT_DIAL, EV_RELEASE, lli_dhup_close},
  666. {ST_OUT_DIAL, EV_NOSETUP_RSP, lli_no_setup_rsp},
  667. {ST_OUT_DIAL, EV_SETUP_ERR, lli_error},
  668. {ST_IN_WAIT_LL, EV_LEASED_REL, lli_failure_l},
  669. {ST_IN_WAIT_LL, EV_ACCEPTD, lli_setup_rsp},
  670. {ST_IN_WAIT_LL, EV_HANGUP, lli_reject_req},
  671. {ST_IN_WAIT_LL, EV_DISCONNECT_IND, lli_release_req},
  672. {ST_IN_WAIT_LL, EV_RELEASE, lli_dhup_close},
  673. {ST_IN_WAIT_LL, EV_SETUP_IND, lli_deliver_call},
  674. {ST_IN_WAIT_LL, EV_SETUP_ERR, lli_error},
  675. {ST_IN_ALERT_SENT, EV_SETUP_CMPL_IND, lli_init_bchan_in},
  676. {ST_IN_ALERT_SENT, EV_ACCEPTD, lli_send_dconnect},
  677. {ST_IN_ALERT_SENT, EV_HANGUP, lli_disconnect_reject},
  678. {ST_IN_ALERT_SENT, EV_DISCONNECT_IND, lli_release_req},
  679. {ST_IN_ALERT_SENT, EV_RELEASE, lli_dhup_close},
  680. {ST_IN_ALERT_SENT, EV_REDIR, lli_send_redir},
  681. {ST_IN_PROCEED_SEND, EV_REDIR, lli_send_redir},
  682. {ST_IN_PROCEED_SEND, EV_ALERT, lli_send_alert},
  683. {ST_IN_PROCEED_SEND, EV_ACCEPTD, lli_send_dconnect},
  684. {ST_IN_PROCEED_SEND, EV_HANGUP, lli_disconnect_reject},
  685. {ST_IN_PROCEED_SEND, EV_DISCONNECT_IND, lli_dhup_close},
  686. {ST_IN_ALERT_SENT, EV_RELEASE, lli_dhup_close},
  687. {ST_IN_WAIT_CONN_ACK, EV_SETUP_CMPL_IND, lli_init_bchan_in},
  688. {ST_IN_WAIT_CONN_ACK, EV_HANGUP, lli_disconnect_req},
  689. {ST_IN_WAIT_CONN_ACK, EV_DISCONNECT_IND, lli_release_req},
  690. {ST_IN_WAIT_CONN_ACK, EV_RELEASE, lli_dhup_close},
  691. {ST_IN_WAIT_CONN_ACK, EV_CONNECT_ERR, lli_error},
  692. {ST_WAIT_BCONN, EV_BC_EST, lli_go_active},
  693. {ST_WAIT_BCONN, EV_BC_REL, lli_rel_b_disc},
  694. {ST_WAIT_BCONN, EV_HANGUP, lli_rel_b_disc},
  695. {ST_WAIT_BCONN, EV_DISCONNECT_IND, lli_rel_b_release_req},
  696. {ST_WAIT_BCONN, EV_RELEASE, lli_rel_b_dhup},
  697. {ST_WAIT_BCONN, EV_LEASED_REL, lli_rel_b_fail},
  698. {ST_WAIT_BCONN, EV_CINF, lli_charge_info},
  699. {ST_ACTIVE, EV_CINF, lli_charge_info},
  700. {ST_ACTIVE, EV_BC_REL, lli_bhup_rel_b},
  701. {ST_ACTIVE, EV_SUSPEND, lli_suspend},
  702. {ST_ACTIVE, EV_HANGUP, lli_disconn_bchan},
  703. {ST_ACTIVE, EV_DISCONNECT_IND, lli_release_bchan},
  704. {ST_ACTIVE, EV_RELEASE, lli_abort},
  705. {ST_ACTIVE, EV_LEASED_REL, lli_failure_a},
  706. {ST_WAIT_BRELEASE, EV_BC_REL, lli_bhup_disc},
  707. {ST_WAIT_BRELEASE, EV_DISCONNECT_IND, lli_bhup_release_req},
  708. {ST_WAIT_BRELEASE, EV_RELEASE, lli_bhup_dhup},
  709. {ST_WAIT_BRELEASE, EV_LEASED_REL, lli_bhup_fail},
  710. {ST_WAIT_BREL_DISC, EV_BC_REL, lli_bhup_release_req},
  711. {ST_WAIT_BREL_DISC, EV_RELEASE, lli_bhup_dhup},
  712. {ST_WAIT_DCOMMAND, EV_HANGUP, lli_start_disc},
  713. {ST_WAIT_DCOMMAND, EV_DISCONNECT_IND, lli_release_req},
  714. {ST_WAIT_DCOMMAND, EV_RELEASE, lli_dhup_close},
  715. {ST_WAIT_DCOMMAND, EV_LEASED_REL, lli_failure_l},
  716. {ST_WAIT_DRELEASE, EV_RELEASE, lli_dhup_close},
  717. {ST_WAIT_DRELEASE, EV_DIAL, lli_dchan_not_ready},
  718. /* ETS 300-104 16.1 */
  719. {ST_WAIT_D_REL_CNF, EV_RELEASE, lli_dhup_close},
  720. {ST_WAIT_D_REL_CNF, EV_DIAL, lli_dchan_not_ready},
  721. };
  722. /* *INDENT-ON* */
  723. int __init
  724. CallcNew(void)
  725. {
  726. callcfsm.state_count = STATE_COUNT;
  727. callcfsm.event_count = EVENT_COUNT;
  728. callcfsm.strEvent = strEvent;
  729. callcfsm.strState = strState;
  730. return FsmNew(&callcfsm, fnlist, ARRAY_SIZE(fnlist));
  731. }
  732. void
  733. CallcFree(void)
  734. {
  735. FsmFree(&callcfsm);
  736. }
  737. static void
  738. release_b_st(struct Channel *chanp)
  739. {
  740. struct PStack *st = chanp->b_st;
  741. if (test_and_clear_bit(FLG_START_B, &chanp->Flags)) {
  742. chanp->bcs->BC_Close(chanp->bcs);
  743. switch (chanp->l2_active_protocol) {
  744. case (ISDN_PROTO_L2_X75I):
  745. releasestack_isdnl2(st);
  746. break;
  747. case (ISDN_PROTO_L2_HDLC):
  748. case (ISDN_PROTO_L2_HDLC_56K):
  749. case (ISDN_PROTO_L2_TRANS):
  750. case (ISDN_PROTO_L2_MODEM):
  751. case (ISDN_PROTO_L2_FAX):
  752. releasestack_transl2(st);
  753. break;
  754. }
  755. }
  756. }
  757. static struct Channel
  758. *selectfreechannel(struct PStack *st, int bch)
  759. {
  760. struct IsdnCardState *cs = st->l1.hardware;
  761. struct Channel *chanp = st->lli.userdata;
  762. int i;
  763. if (test_bit(FLG_TWO_DCHAN, &cs->HW_Flags))
  764. i = 1;
  765. else
  766. i = 0;
  767. if (!bch) {
  768. i = 2; /* virtual channel */
  769. chanp += 2;
  770. }
  771. while (i < ((bch) ? cs->chanlimit : (2 + MAX_WAITING_CALLS))) {
  772. if (chanp->fi.state == ST_NULL)
  773. return (chanp);
  774. chanp++;
  775. i++;
  776. }
  777. if (bch) /* number of channels is limited */ {
  778. i = 2; /* virtual channel */
  779. chanp = st->lli.userdata;
  780. chanp += i;
  781. while (i < (2 + MAX_WAITING_CALLS)) {
  782. if (chanp->fi.state == ST_NULL)
  783. return (chanp);
  784. chanp++;
  785. i++;
  786. }
  787. }
  788. return (NULL);
  789. }
  790. static void stat_redir_result(struct IsdnCardState *cs, int chan, ulong result)
  791. { isdn_ctrl ic;
  792. ic.driver = cs->myid;
  793. ic.command = ISDN_STAT_REDIR;
  794. ic.arg = chan;
  795. ic.parm.num[0] = result;
  796. cs->iif.statcallb(&ic);
  797. } /* stat_redir_result */
  798. static void
  799. dchan_l3l4(struct PStack *st, int pr, void *arg)
  800. {
  801. struct l3_process *pc = arg;
  802. struct IsdnCardState *cs = st->l1.hardware;
  803. struct Channel *chanp;
  804. if (!pc)
  805. return;
  806. if (pr == (CC_SETUP | INDICATION)) {
  807. if (!(chanp = selectfreechannel(pc->st, pc->para.bchannel))) {
  808. pc->para.cause = 0x11; /* User busy */
  809. pc->st->lli.l4l3(pc->st, CC_REJECT | REQUEST, pc);
  810. } else {
  811. chanp->proc = pc;
  812. pc->chan = chanp;
  813. FsmEvent(&chanp->fi, EV_SETUP_IND, NULL);
  814. }
  815. return;
  816. }
  817. if (!(chanp = pc->chan))
  818. return;
  819. switch (pr) {
  820. case (CC_MORE_INFO | INDICATION):
  821. FsmEvent(&chanp->fi, EV_SETUP_IND, NULL);
  822. break;
  823. case (CC_DISCONNECT | INDICATION):
  824. FsmEvent(&chanp->fi, EV_DISCONNECT_IND, NULL);
  825. break;
  826. case (CC_RELEASE | CONFIRM):
  827. FsmEvent(&chanp->fi, EV_RELEASE, NULL);
  828. break;
  829. case (CC_SUSPEND | CONFIRM):
  830. FsmEvent(&chanp->fi, EV_RELEASE, NULL);
  831. break;
  832. case (CC_RESUME | CONFIRM):
  833. FsmEvent(&chanp->fi, EV_SETUP_CNF, NULL);
  834. break;
  835. case (CC_RESUME_ERR):
  836. FsmEvent(&chanp->fi, EV_RELEASE, NULL);
  837. break;
  838. case (CC_RELEASE | INDICATION):
  839. FsmEvent(&chanp->fi, EV_RELEASE, NULL);
  840. break;
  841. case (CC_SETUP_COMPL | INDICATION):
  842. FsmEvent(&chanp->fi, EV_SETUP_CMPL_IND, NULL);
  843. break;
  844. case (CC_SETUP | CONFIRM):
  845. FsmEvent(&chanp->fi, EV_SETUP_CNF, NULL);
  846. break;
  847. case (CC_CHARGE | INDICATION):
  848. FsmEvent(&chanp->fi, EV_CINF, NULL);
  849. break;
  850. case (CC_NOSETUP_RSP):
  851. FsmEvent(&chanp->fi, EV_NOSETUP_RSP, NULL);
  852. break;
  853. case (CC_SETUP_ERR):
  854. FsmEvent(&chanp->fi, EV_SETUP_ERR, NULL);
  855. break;
  856. case (CC_CONNECT_ERR):
  857. FsmEvent(&chanp->fi, EV_CONNECT_ERR, NULL);
  858. break;
  859. case (CC_RELEASE_ERR):
  860. FsmEvent(&chanp->fi, EV_RELEASE, NULL);
  861. break;
  862. case (CC_PROCEED_SEND | INDICATION):
  863. case (CC_PROCEEDING | INDICATION):
  864. case (CC_ALERTING | INDICATION):
  865. case (CC_PROGRESS | INDICATION):
  866. case (CC_NOTIFY | INDICATION):
  867. break;
  868. case (CC_REDIR | INDICATION):
  869. stat_redir_result(cs, chanp->chan, pc->redir_result);
  870. break;
  871. default:
  872. if (chanp->debug & 0x800) {
  873. HiSax_putstatus(chanp->cs, "Ch",
  874. "%d L3->L4 unknown primitiv %#x",
  875. chanp->chan, pr);
  876. }
  877. }
  878. }
  879. static void
  880. dummy_pstack(struct PStack *st, int pr, void *arg) {
  881. printk(KERN_WARNING"call to dummy_pstack pr=%04x arg %lx\n", pr, (long)arg);
  882. }
  883. static int
  884. init_PStack(struct PStack **stp) {
  885. *stp = kmalloc(sizeof(struct PStack), GFP_ATOMIC);
  886. if (!*stp)
  887. return -ENOMEM;
  888. (*stp)->next = NULL;
  889. (*stp)->l1.l1l2 = dummy_pstack;
  890. (*stp)->l1.l1hw = dummy_pstack;
  891. (*stp)->l1.l1tei = dummy_pstack;
  892. (*stp)->l2.l2tei = dummy_pstack;
  893. (*stp)->l2.l2l1 = dummy_pstack;
  894. (*stp)->l2.l2l3 = dummy_pstack;
  895. (*stp)->l3.l3l2 = dummy_pstack;
  896. (*stp)->l3.l3ml3 = dummy_pstack;
  897. (*stp)->l3.l3l4 = dummy_pstack;
  898. (*stp)->lli.l4l3 = dummy_pstack;
  899. (*stp)->ma.layer = dummy_pstack;
  900. return 0;
  901. }
  902. static int
  903. init_d_st(struct Channel *chanp)
  904. {
  905. struct PStack *st;
  906. struct IsdnCardState *cs = chanp->cs;
  907. char tmp[16];
  908. int err;
  909. err = init_PStack(&chanp->d_st);
  910. if (err)
  911. return err;
  912. st = chanp->d_st;
  913. st->next = NULL;
  914. HiSax_addlist(cs, st);
  915. setstack_HiSax(st, cs);
  916. st->l2.sap = 0;
  917. st->l2.tei = -1;
  918. st->l2.flag = 0;
  919. test_and_set_bit(FLG_MOD128, &st->l2.flag);
  920. test_and_set_bit(FLG_LAPD, &st->l2.flag);
  921. test_and_set_bit(FLG_ORIG, &st->l2.flag);
  922. st->l2.maxlen = MAX_DFRAME_LEN;
  923. st->l2.window = 1;
  924. st->l2.T200 = 1000; /* 1000 milliseconds */
  925. st->l2.N200 = 3; /* try 3 times */
  926. st->l2.T203 = 10000; /* 10000 milliseconds */
  927. if (test_bit(FLG_TWO_DCHAN, &cs->HW_Flags))
  928. sprintf(tmp, "DCh%d Q.921 ", chanp->chan);
  929. else
  930. sprintf(tmp, "DCh Q.921 ");
  931. setstack_isdnl2(st, tmp);
  932. setstack_l3dc(st, chanp);
  933. st->lli.userdata = chanp;
  934. st->l3.l3l4 = dchan_l3l4;
  935. return 0;
  936. }
  937. static __printf(2, 3) void
  938. callc_debug(struct FsmInst *fi, char *fmt, ...)
  939. {
  940. va_list args;
  941. struct Channel *chanp = fi->userdata;
  942. char tmp[16];
  943. va_start(args, fmt);
  944. sprintf(tmp, "Ch%d callc ", chanp->chan);
  945. VHiSax_putstatus(chanp->cs, tmp, fmt, args);
  946. va_end(args);
  947. }
  948. static int
  949. init_chan(int chan, struct IsdnCardState *csta)
  950. {
  951. struct Channel *chanp = csta->channel + chan;
  952. int err;
  953. chanp->cs = csta;
  954. chanp->bcs = csta->bcs + chan;
  955. chanp->chan = chan;
  956. chanp->incoming = 0;
  957. chanp->debug = 0;
  958. chanp->Flags = 0;
  959. chanp->leased = 0;
  960. err = init_PStack(&chanp->b_st);
  961. if (err)
  962. return err;
  963. chanp->b_st->l1.delay = DEFAULT_B_DELAY;
  964. chanp->fi.fsm = &callcfsm;
  965. chanp->fi.state = ST_NULL;
  966. chanp->fi.debug = 0;
  967. chanp->fi.userdata = chanp;
  968. chanp->fi.printdebug = callc_debug;
  969. FsmInitTimer(&chanp->fi, &chanp->dial_timer);
  970. FsmInitTimer(&chanp->fi, &chanp->drel_timer);
  971. if (!chan || (test_bit(FLG_TWO_DCHAN, &csta->HW_Flags) && chan < 2)) {
  972. err = init_d_st(chanp);
  973. if (err)
  974. return err;
  975. } else {
  976. chanp->d_st = csta->channel->d_st;
  977. }
  978. chanp->data_open = 0;
  979. return 0;
  980. }
  981. int
  982. CallcNewChan(struct IsdnCardState *csta) {
  983. int i, err;
  984. chancount += 2;
  985. err = init_chan(0, csta);
  986. if (err)
  987. return err;
  988. err = init_chan(1, csta);
  989. if (err)
  990. return err;
  991. printk(KERN_INFO "HiSax: 2 channels added\n");
  992. for (i = 0; i < MAX_WAITING_CALLS; i++) {
  993. err = init_chan(i + 2, csta);
  994. if (err)
  995. return err;
  996. }
  997. printk(KERN_INFO "HiSax: MAX_WAITING_CALLS added\n");
  998. if (test_bit(FLG_PTP, &csta->channel->d_st->l2.flag)) {
  999. printk(KERN_INFO "LAYER2 WATCHING ESTABLISH\n");
  1000. csta->channel->d_st->lli.l4l3(csta->channel->d_st,
  1001. DL_ESTABLISH | REQUEST, NULL);
  1002. }
  1003. return (0);
  1004. }
  1005. static void
  1006. release_d_st(struct Channel *chanp)
  1007. {
  1008. struct PStack *st = chanp->d_st;
  1009. if (!st)
  1010. return;
  1011. releasestack_isdnl2(st);
  1012. releasestack_isdnl3(st);
  1013. HiSax_rmlist(st->l1.hardware, st);
  1014. kfree(st);
  1015. chanp->d_st = NULL;
  1016. }
  1017. void
  1018. CallcFreeChan(struct IsdnCardState *csta)
  1019. {
  1020. int i;
  1021. for (i = 0; i < 2; i++) {
  1022. FsmDelTimer(&csta->channel[i].drel_timer, 74);
  1023. FsmDelTimer(&csta->channel[i].dial_timer, 75);
  1024. if (i || test_bit(FLG_TWO_DCHAN, &csta->HW_Flags))
  1025. release_d_st(csta->channel + i);
  1026. if (csta->channel[i].b_st) {
  1027. release_b_st(csta->channel + i);
  1028. kfree(csta->channel[i].b_st);
  1029. csta->channel[i].b_st = NULL;
  1030. } else
  1031. printk(KERN_WARNING "CallcFreeChan b_st ch%d already freed\n", i);
  1032. if (i || test_bit(FLG_TWO_DCHAN, &csta->HW_Flags)) {
  1033. release_d_st(csta->channel + i);
  1034. } else
  1035. csta->channel[i].d_st = NULL;
  1036. }
  1037. }
  1038. static void
  1039. lldata_handler(struct PStack *st, int pr, void *arg)
  1040. {
  1041. struct Channel *chanp = (struct Channel *) st->lli.userdata;
  1042. struct sk_buff *skb = arg;
  1043. switch (pr) {
  1044. case (DL_DATA | INDICATION):
  1045. if (chanp->data_open) {
  1046. if (chanp->debug & 0x800)
  1047. link_debug(chanp, 0, "lldata: %d", skb->len);
  1048. chanp->cs->iif.rcvcallb_skb(chanp->cs->myid, chanp->chan, skb);
  1049. } else {
  1050. link_debug(chanp, 0, "lldata: channel not open");
  1051. dev_kfree_skb(skb);
  1052. }
  1053. break;
  1054. case (DL_ESTABLISH | INDICATION):
  1055. case (DL_ESTABLISH | CONFIRM):
  1056. FsmEvent(&chanp->fi, EV_BC_EST, NULL);
  1057. break;
  1058. case (DL_RELEASE | INDICATION):
  1059. case (DL_RELEASE | CONFIRM):
  1060. FsmEvent(&chanp->fi, EV_BC_REL, NULL);
  1061. break;
  1062. default:
  1063. printk(KERN_WARNING "lldata_handler unknown primitive %#x\n",
  1064. pr);
  1065. break;
  1066. }
  1067. }
  1068. static void
  1069. lltrans_handler(struct PStack *st, int pr, void *arg)
  1070. {
  1071. struct Channel *chanp = (struct Channel *) st->lli.userdata;
  1072. struct sk_buff *skb = arg;
  1073. switch (pr) {
  1074. case (PH_DATA | INDICATION):
  1075. if (chanp->data_open) {
  1076. if (chanp->debug & 0x800)
  1077. link_debug(chanp, 0, "lltrans: %d", skb->len);
  1078. chanp->cs->iif.rcvcallb_skb(chanp->cs->myid, chanp->chan, skb);
  1079. } else {
  1080. link_debug(chanp, 0, "lltrans: channel not open");
  1081. dev_kfree_skb(skb);
  1082. }
  1083. break;
  1084. case (PH_ACTIVATE | INDICATION):
  1085. case (PH_ACTIVATE | CONFIRM):
  1086. FsmEvent(&chanp->fi, EV_BC_EST, NULL);
  1087. break;
  1088. case (PH_DEACTIVATE | INDICATION):
  1089. case (PH_DEACTIVATE | CONFIRM):
  1090. FsmEvent(&chanp->fi, EV_BC_REL, NULL);
  1091. break;
  1092. default:
  1093. printk(KERN_WARNING "lltrans_handler unknown primitive %#x\n",
  1094. pr);
  1095. break;
  1096. }
  1097. }
  1098. void
  1099. lli_writewakeup(struct PStack *st, int len)
  1100. {
  1101. struct Channel *chanp = st->lli.userdata;
  1102. isdn_ctrl ic;
  1103. if (chanp->debug & 0x800)
  1104. link_debug(chanp, 0, "llwakeup: %d", len);
  1105. ic.driver = chanp->cs->myid;
  1106. ic.command = ISDN_STAT_BSENT;
  1107. ic.arg = chanp->chan;
  1108. ic.parm.length = len;
  1109. chanp->cs->iif.statcallb(&ic);
  1110. }
  1111. static int
  1112. init_b_st(struct Channel *chanp, int incoming)
  1113. {
  1114. struct PStack *st = chanp->b_st;
  1115. struct IsdnCardState *cs = chanp->cs;
  1116. char tmp[16];
  1117. st->l1.hardware = cs;
  1118. if (chanp->leased)
  1119. st->l1.bc = chanp->chan & 1;
  1120. else
  1121. st->l1.bc = chanp->proc->para.bchannel - 1;
  1122. switch (chanp->l2_active_protocol) {
  1123. case (ISDN_PROTO_L2_X75I):
  1124. case (ISDN_PROTO_L2_HDLC):
  1125. st->l1.mode = L1_MODE_HDLC;
  1126. break;
  1127. case (ISDN_PROTO_L2_HDLC_56K):
  1128. st->l1.mode = L1_MODE_HDLC_56K;
  1129. break;
  1130. case (ISDN_PROTO_L2_TRANS):
  1131. st->l1.mode = L1_MODE_TRANS;
  1132. break;
  1133. case (ISDN_PROTO_L2_MODEM):
  1134. st->l1.mode = L1_MODE_V32;
  1135. break;
  1136. case (ISDN_PROTO_L2_FAX):
  1137. st->l1.mode = L1_MODE_FAX;
  1138. break;
  1139. }
  1140. chanp->bcs->conmsg = NULL;
  1141. if (chanp->bcs->BC_SetStack(st, chanp->bcs))
  1142. return (-1);
  1143. st->l2.flag = 0;
  1144. test_and_set_bit(FLG_LAPB, &st->l2.flag);
  1145. st->l2.maxlen = MAX_DATA_SIZE;
  1146. if (!incoming)
  1147. test_and_set_bit(FLG_ORIG, &st->l2.flag);
  1148. st->l2.T200 = 1000; /* 1000 milliseconds */
  1149. st->l2.window = 7;
  1150. st->l2.N200 = 4; /* try 4 times */
  1151. st->l2.T203 = 5000; /* 5000 milliseconds */
  1152. st->l3.debug = 0;
  1153. switch (chanp->l2_active_protocol) {
  1154. case (ISDN_PROTO_L2_X75I):
  1155. sprintf(tmp, "Ch%d X.75", chanp->chan);
  1156. setstack_isdnl2(st, tmp);
  1157. setstack_l3bc(st, chanp);
  1158. st->l2.l2l3 = lldata_handler;
  1159. st->lli.userdata = chanp;
  1160. test_and_clear_bit(FLG_LLI_L1WAKEUP, &st->lli.flag);
  1161. test_and_set_bit(FLG_LLI_L2WAKEUP, &st->lli.flag);
  1162. st->l2.l2m.debug = chanp->debug & 16;
  1163. st->l2.debug = chanp->debug & 64;
  1164. break;
  1165. case (ISDN_PROTO_L2_HDLC):
  1166. case (ISDN_PROTO_L2_HDLC_56K):
  1167. case (ISDN_PROTO_L2_TRANS):
  1168. case (ISDN_PROTO_L2_MODEM):
  1169. case (ISDN_PROTO_L2_FAX):
  1170. st->l1.l1l2 = lltrans_handler;
  1171. st->lli.userdata = chanp;
  1172. test_and_set_bit(FLG_LLI_L1WAKEUP, &st->lli.flag);
  1173. test_and_clear_bit(FLG_LLI_L2WAKEUP, &st->lli.flag);
  1174. setstack_transl2(st);
  1175. setstack_l3bc(st, chanp);
  1176. break;
  1177. }
  1178. test_and_set_bit(FLG_START_B, &chanp->Flags);
  1179. return (0);
  1180. }
  1181. static void
  1182. leased_l4l3(struct PStack *st, int pr, void *arg)
  1183. {
  1184. struct Channel *chanp = (struct Channel *) st->lli.userdata;
  1185. struct sk_buff *skb = arg;
  1186. switch (pr) {
  1187. case (DL_DATA | REQUEST):
  1188. link_debug(chanp, 0, "leased line d-channel DATA");
  1189. dev_kfree_skb(skb);
  1190. break;
  1191. case (DL_ESTABLISH | REQUEST):
  1192. st->l2.l2l1(st, PH_ACTIVATE | REQUEST, NULL);
  1193. break;
  1194. case (DL_RELEASE | REQUEST):
  1195. break;
  1196. default:
  1197. printk(KERN_WARNING "transd_l4l3 unknown primitive %#x\n",
  1198. pr);
  1199. break;
  1200. }
  1201. }
  1202. static void
  1203. leased_l1l2(struct PStack *st, int pr, void *arg)
  1204. {
  1205. struct Channel *chanp = (struct Channel *) st->lli.userdata;
  1206. struct sk_buff *skb = arg;
  1207. int i, event = EV_LEASED_REL;
  1208. switch (pr) {
  1209. case (PH_DATA | INDICATION):
  1210. link_debug(chanp, 0, "leased line d-channel DATA");
  1211. dev_kfree_skb(skb);
  1212. break;
  1213. case (PH_ACTIVATE | INDICATION):
  1214. case (PH_ACTIVATE | CONFIRM):
  1215. event = EV_LEASED;
  1216. case (PH_DEACTIVATE | INDICATION):
  1217. case (PH_DEACTIVATE | CONFIRM):
  1218. if (test_bit(FLG_TWO_DCHAN, &chanp->cs->HW_Flags))
  1219. i = 1;
  1220. else
  1221. i = 0;
  1222. while (i < 2) {
  1223. FsmEvent(&chanp->fi, event, NULL);
  1224. chanp++;
  1225. i++;
  1226. }
  1227. break;
  1228. default:
  1229. printk(KERN_WARNING
  1230. "transd_l1l2 unknown primitive %#x\n", pr);
  1231. break;
  1232. }
  1233. }
  1234. static void
  1235. distr_debug(struct IsdnCardState *csta, int debugflags)
  1236. {
  1237. int i;
  1238. struct Channel *chanp = csta->channel;
  1239. for (i = 0; i < (2 + MAX_WAITING_CALLS); i++) {
  1240. chanp[i].debug = debugflags;
  1241. chanp[i].fi.debug = debugflags & 2;
  1242. chanp[i].d_st->l2.l2m.debug = debugflags & 8;
  1243. chanp[i].b_st->l2.l2m.debug = debugflags & 0x10;
  1244. chanp[i].d_st->l2.debug = debugflags & 0x20;
  1245. chanp[i].b_st->l2.debug = debugflags & 0x40;
  1246. chanp[i].d_st->l3.l3m.debug = debugflags & 0x80;
  1247. chanp[i].b_st->l3.l3m.debug = debugflags & 0x100;
  1248. chanp[i].b_st->ma.tei_m.debug = debugflags & 0x200;
  1249. chanp[i].b_st->ma.debug = debugflags & 0x200;
  1250. chanp[i].d_st->l1.l1m.debug = debugflags & 0x1000;
  1251. chanp[i].b_st->l1.l1m.debug = debugflags & 0x2000;
  1252. }
  1253. if (debugflags & 4)
  1254. csta->debug |= DEB_DLOG_HEX;
  1255. else
  1256. csta->debug &= ~DEB_DLOG_HEX;
  1257. }
  1258. static char tmpbuf[256];
  1259. static void
  1260. capi_debug(struct Channel *chanp, capi_msg *cm)
  1261. {
  1262. char *t = tmpbuf;
  1263. t += QuickHex(t, (u_char *)cm, (cm->Length > 50) ? 50 : cm->Length);
  1264. t--;
  1265. *t = 0;
  1266. HiSax_putstatus(chanp->cs, "Ch", "%d CAPIMSG %s", chanp->chan, tmpbuf);
  1267. }
  1268. static void
  1269. lli_got_fac_req(struct Channel *chanp, capi_msg *cm) {
  1270. if ((cm->para[0] != 3) || (cm->para[1] != 0))
  1271. return;
  1272. if (cm->para[2] < 3)
  1273. return;
  1274. if (cm->para[4] != 0)
  1275. return;
  1276. switch (cm->para[3]) {
  1277. case 4: /* Suspend */
  1278. strncpy(chanp->setup.phone, &cm->para[5], cm->para[5] + 1);
  1279. FsmEvent(&chanp->fi, EV_SUSPEND, cm);
  1280. break;
  1281. case 5: /* Resume */
  1282. strncpy(chanp->setup.phone, &cm->para[5], cm->para[5] + 1);
  1283. if (chanp->fi.state == ST_NULL) {
  1284. FsmEvent(&chanp->fi, EV_RESUME, cm);
  1285. } else {
  1286. FsmDelTimer(&chanp->dial_timer, 72);
  1287. FsmAddTimer(&chanp->dial_timer, 80, EV_RESUME, cm, 73);
  1288. }
  1289. break;
  1290. }
  1291. }
  1292. static void
  1293. lli_got_manufacturer(struct Channel *chanp, struct IsdnCardState *cs, capi_msg *cm) {
  1294. if ((cs->typ == ISDN_CTYPE_ELSA) || (cs->typ == ISDN_CTYPE_ELSA_PNP) ||
  1295. (cs->typ == ISDN_CTYPE_ELSA_PCI)) {
  1296. if (cs->hw.elsa.MFlag) {
  1297. cs->cardmsg(cs, CARD_AUX_IND, cm->para);
  1298. }
  1299. }
  1300. }
  1301. /***************************************************************/
  1302. /* Limit the available number of channels for the current card */
  1303. /***************************************************************/
  1304. static int
  1305. set_channel_limit(struct IsdnCardState *cs, int chanmax)
  1306. {
  1307. isdn_ctrl ic;
  1308. int i, ii;
  1309. if ((chanmax < 0) || (chanmax > 2))
  1310. return (-EINVAL);
  1311. cs->chanlimit = 0;
  1312. for (ii = 0; ii < 2; ii++) {
  1313. ic.driver = cs->myid;
  1314. ic.command = ISDN_STAT_DISCH;
  1315. ic.arg = ii;
  1316. if (ii >= chanmax)
  1317. ic.parm.num[0] = 0; /* disabled */
  1318. else
  1319. ic.parm.num[0] = 1; /* enabled */
  1320. i = cs->iif.statcallb(&ic);
  1321. if (i) return (-EINVAL);
  1322. if (ii < chanmax)
  1323. cs->chanlimit++;
  1324. }
  1325. return (0);
  1326. } /* set_channel_limit */
  1327. int
  1328. HiSax_command(isdn_ctrl *ic)
  1329. {
  1330. struct IsdnCardState *csta = hisax_findcard(ic->driver);
  1331. struct PStack *st;
  1332. struct Channel *chanp;
  1333. int i;
  1334. u_int num;
  1335. if (!csta) {
  1336. printk(KERN_ERR
  1337. "HiSax: if_command %d called with invalid driverId %d!\n",
  1338. ic->command, ic->driver);
  1339. return -ENODEV;
  1340. }
  1341. switch (ic->command) {
  1342. case (ISDN_CMD_SETEAZ):
  1343. chanp = csta->channel + ic->arg;
  1344. break;
  1345. case (ISDN_CMD_SETL2):
  1346. chanp = csta->channel + (ic->arg & 0xff);
  1347. if (chanp->debug & 1)
  1348. link_debug(chanp, 1, "SETL2 card %d %ld",
  1349. csta->cardnr + 1, ic->arg >> 8);
  1350. chanp->l2_protocol = ic->arg >> 8;
  1351. break;
  1352. case (ISDN_CMD_SETL3):
  1353. chanp = csta->channel + (ic->arg & 0xff);
  1354. if (chanp->debug & 1)
  1355. link_debug(chanp, 1, "SETL3 card %d %ld",
  1356. csta->cardnr + 1, ic->arg >> 8);
  1357. chanp->l3_protocol = ic->arg >> 8;
  1358. break;
  1359. case (ISDN_CMD_DIAL):
  1360. chanp = csta->channel + (ic->arg & 0xff);
  1361. if (chanp->debug & 1)
  1362. link_debug(chanp, 1, "DIAL %s -> %s (%d,%d)",
  1363. ic->parm.setup.eazmsn, ic->parm.setup.phone,
  1364. ic->parm.setup.si1, ic->parm.setup.si2);
  1365. memcpy(&chanp->setup, &ic->parm.setup, sizeof(setup_parm));
  1366. if (!strcmp(chanp->setup.eazmsn, "0"))
  1367. chanp->setup.eazmsn[0] = '\0';
  1368. /* this solution is dirty and may be change, if
  1369. * we make a callreference based callmanager */
  1370. if (chanp->fi.state == ST_NULL) {
  1371. FsmEvent(&chanp->fi, EV_DIAL, NULL);
  1372. } else {
  1373. FsmDelTimer(&chanp->dial_timer, 70);
  1374. FsmAddTimer(&chanp->dial_timer, 50, EV_DIAL, NULL, 71);
  1375. }
  1376. break;
  1377. case (ISDN_CMD_ACCEPTB):
  1378. chanp = csta->channel + ic->arg;
  1379. if (chanp->debug & 1)
  1380. link_debug(chanp, 1, "ACCEPTB");
  1381. FsmEvent(&chanp->fi, EV_ACCEPTB, NULL);
  1382. break;
  1383. case (ISDN_CMD_ACCEPTD):
  1384. chanp = csta->channel + ic->arg;
  1385. memcpy(&chanp->setup, &ic->parm.setup, sizeof(setup_parm));
  1386. if (chanp->debug & 1)
  1387. link_debug(chanp, 1, "ACCEPTD");
  1388. FsmEvent(&chanp->fi, EV_ACCEPTD, NULL);
  1389. break;
  1390. case (ISDN_CMD_HANGUP):
  1391. chanp = csta->channel + ic->arg;
  1392. if (chanp->debug & 1)
  1393. link_debug(chanp, 1, "HANGUP");
  1394. FsmEvent(&chanp->fi, EV_HANGUP, NULL);
  1395. break;
  1396. case (CAPI_PUT_MESSAGE):
  1397. chanp = csta->channel + ic->arg;
  1398. if (chanp->debug & 1)
  1399. capi_debug(chanp, &ic->parm.cmsg);
  1400. if (ic->parm.cmsg.Length < 8)
  1401. break;
  1402. switch (ic->parm.cmsg.Command) {
  1403. case CAPI_FACILITY:
  1404. if (ic->parm.cmsg.Subcommand == CAPI_REQ)
  1405. lli_got_fac_req(chanp, &ic->parm.cmsg);
  1406. break;
  1407. case CAPI_MANUFACTURER:
  1408. if (ic->parm.cmsg.Subcommand == CAPI_REQ)
  1409. lli_got_manufacturer(chanp, csta, &ic->parm.cmsg);
  1410. break;
  1411. default:
  1412. break;
  1413. }
  1414. break;
  1415. case (ISDN_CMD_IOCTL):
  1416. switch (ic->arg) {
  1417. case (0):
  1418. num = *(unsigned int *) ic->parm.num;
  1419. HiSax_reportcard(csta->cardnr, num);
  1420. break;
  1421. case (1):
  1422. num = *(unsigned int *) ic->parm.num;
  1423. distr_debug(csta, num);
  1424. printk(KERN_DEBUG "HiSax: debugging flags card %d set to %x\n",
  1425. csta->cardnr + 1, num);
  1426. HiSax_putstatus(csta, "debugging flags ",
  1427. "card %d set to %x", csta->cardnr + 1, num);
  1428. break;
  1429. case (2):
  1430. num = *(unsigned int *) ic->parm.num;
  1431. csta->channel[0].b_st->l1.delay = num;
  1432. csta->channel[1].b_st->l1.delay = num;
  1433. HiSax_putstatus(csta, "delay ", "card %d set to %d ms",
  1434. csta->cardnr + 1, num);
  1435. printk(KERN_DEBUG "HiSax: delay card %d set to %d ms\n",
  1436. csta->cardnr + 1, num);
  1437. break;
  1438. case (5): /* set card in leased mode */
  1439. num = *(unsigned int *) ic->parm.num;
  1440. if ((num < 1) || (num > 2)) {
  1441. HiSax_putstatus(csta, "Set LEASED ",
  1442. "wrong channel %d", num);
  1443. printk(KERN_WARNING "HiSax: Set LEASED wrong channel %d\n",
  1444. num);
  1445. } else {
  1446. num--;
  1447. chanp = csta->channel + num;
  1448. chanp->leased = 1;
  1449. HiSax_putstatus(csta, "Card",
  1450. "%d channel %d set leased mode\n",
  1451. csta->cardnr + 1, num + 1);
  1452. chanp->d_st->l1.l1l2 = leased_l1l2;
  1453. chanp->d_st->lli.l4l3 = leased_l4l3;
  1454. chanp->d_st->lli.l4l3(chanp->d_st,
  1455. DL_ESTABLISH | REQUEST, NULL);
  1456. }
  1457. break;
  1458. case (6): /* set B-channel test loop */
  1459. num = *(unsigned int *) ic->parm.num;
  1460. if (csta->stlist)
  1461. csta->stlist->l2.l2l1(csta->stlist,
  1462. PH_TESTLOOP | REQUEST, (void *) (long)num);
  1463. break;
  1464. case (7): /* set card in PTP mode */
  1465. num = *(unsigned int *) ic->parm.num;
  1466. if (test_bit(FLG_TWO_DCHAN, &csta->HW_Flags)) {
  1467. printk(KERN_ERR "HiSax PTP mode only with one TEI possible\n");
  1468. } else if (num) {
  1469. test_and_set_bit(FLG_PTP, &csta->channel[0].d_st->l2.flag);
  1470. test_and_set_bit(FLG_FIXED_TEI, &csta->channel[0].d_st->l2.flag);
  1471. csta->channel[0].d_st->l2.tei = 0;
  1472. HiSax_putstatus(csta, "set card ", "in PTP mode");
  1473. printk(KERN_DEBUG "HiSax: set card in PTP mode\n");
  1474. printk(KERN_INFO "LAYER2 WATCHING ESTABLISH\n");
  1475. csta->channel[0].d_st->lli.l4l3(csta->channel[0].d_st,
  1476. DL_ESTABLISH | REQUEST, NULL);
  1477. } else {
  1478. test_and_clear_bit(FLG_PTP, &csta->channel[0].d_st->l2.flag);
  1479. test_and_clear_bit(FLG_FIXED_TEI, &csta->channel[0].d_st->l2.flag);
  1480. HiSax_putstatus(csta, "set card ", "in PTMP mode");
  1481. printk(KERN_DEBUG "HiSax: set card in PTMP mode\n");
  1482. }
  1483. break;
  1484. case (8): /* set card in FIXED TEI mode */
  1485. num = *(unsigned int *)ic->parm.num;
  1486. chanp = csta->channel + (num & 1);
  1487. num = num >> 1;
  1488. if (num == 127) {
  1489. test_and_clear_bit(FLG_FIXED_TEI, &chanp->d_st->l2.flag);
  1490. chanp->d_st->l2.tei = -1;
  1491. HiSax_putstatus(csta, "set card ", "in VAR TEI mode");
  1492. printk(KERN_DEBUG "HiSax: set card in VAR TEI mode\n");
  1493. } else {
  1494. test_and_set_bit(FLG_FIXED_TEI, &chanp->d_st->l2.flag);
  1495. chanp->d_st->l2.tei = num;
  1496. HiSax_putstatus(csta, "set card ", "in FIXED TEI (%d) mode", num);
  1497. printk(KERN_DEBUG "HiSax: set card in FIXED TEI (%d) mode\n",
  1498. num);
  1499. }
  1500. chanp->d_st->lli.l4l3(chanp->d_st,
  1501. DL_ESTABLISH | REQUEST, NULL);
  1502. break;
  1503. case (11):
  1504. num = csta->debug & DEB_DLOG_HEX;
  1505. csta->debug = *(unsigned int *) ic->parm.num;
  1506. csta->debug |= num;
  1507. HiSax_putstatus(cards[0].cs, "l1 debugging ",
  1508. "flags card %d set to %x",
  1509. csta->cardnr + 1, csta->debug);
  1510. printk(KERN_DEBUG "HiSax: l1 debugging flags card %d set to %x\n",
  1511. csta->cardnr + 1, csta->debug);
  1512. break;
  1513. case (13):
  1514. csta->channel[0].d_st->l3.debug = *(unsigned int *) ic->parm.num;
  1515. csta->channel[1].d_st->l3.debug = *(unsigned int *) ic->parm.num;
  1516. HiSax_putstatus(cards[0].cs, "l3 debugging ",
  1517. "flags card %d set to %x\n", csta->cardnr + 1,
  1518. *(unsigned int *) ic->parm.num);
  1519. printk(KERN_DEBUG "HiSax: l3 debugging flags card %d set to %x\n",
  1520. csta->cardnr + 1, *(unsigned int *) ic->parm.num);
  1521. break;
  1522. case (10):
  1523. i = *(unsigned int *) ic->parm.num;
  1524. return (set_channel_limit(csta, i));
  1525. default:
  1526. if (csta->auxcmd)
  1527. return (csta->auxcmd(csta, ic));
  1528. printk(KERN_DEBUG "HiSax: invalid ioctl %d\n",
  1529. (int) ic->arg);
  1530. return (-EINVAL);
  1531. }
  1532. break;
  1533. case (ISDN_CMD_PROCEED):
  1534. chanp = csta->channel + ic->arg;
  1535. if (chanp->debug & 1)
  1536. link_debug(chanp, 1, "PROCEED");
  1537. FsmEvent(&chanp->fi, EV_PROCEED, NULL);
  1538. break;
  1539. case (ISDN_CMD_ALERT):
  1540. chanp = csta->channel + ic->arg;
  1541. if (chanp->debug & 1)
  1542. link_debug(chanp, 1, "ALERT");
  1543. FsmEvent(&chanp->fi, EV_ALERT, NULL);
  1544. break;
  1545. case (ISDN_CMD_REDIR):
  1546. chanp = csta->channel + ic->arg;
  1547. if (chanp->debug & 1)
  1548. link_debug(chanp, 1, "REDIR");
  1549. memcpy(&chanp->setup, &ic->parm.setup, sizeof(setup_parm));
  1550. FsmEvent(&chanp->fi, EV_REDIR, NULL);
  1551. break;
  1552. /* protocol specific io commands */
  1553. case (ISDN_CMD_PROT_IO):
  1554. for (st = csta->stlist; st; st = st->next)
  1555. if (st->protocol == (ic->arg & 0xFF))
  1556. return (st->lli.l4l3_proto(st, ic));
  1557. return (-EINVAL);
  1558. break;
  1559. default:
  1560. if (csta->auxcmd)
  1561. return (csta->auxcmd(csta, ic));
  1562. return (-EINVAL);
  1563. }
  1564. return (0);
  1565. }
  1566. int
  1567. HiSax_writebuf_skb(int id, int chan, int ack, struct sk_buff *skb)
  1568. {
  1569. struct IsdnCardState *csta = hisax_findcard(id);
  1570. struct Channel *chanp;
  1571. struct PStack *st;
  1572. int len = skb->len;
  1573. struct sk_buff *nskb;
  1574. if (!csta) {
  1575. printk(KERN_ERR
  1576. "HiSax: if_sendbuf called with invalid driverId!\n");
  1577. return -ENODEV;
  1578. }
  1579. chanp = csta->channel + chan;
  1580. st = chanp->b_st;
  1581. if (!chanp->data_open) {
  1582. link_debug(chanp, 1, "writebuf: channel not open");
  1583. return -EIO;
  1584. }
  1585. if (len > MAX_DATA_SIZE) {
  1586. link_debug(chanp, 1, "writebuf: packet too large (%d bytes)", len);
  1587. printk(KERN_WARNING "HiSax_writebuf: packet too large (%d bytes) !\n",
  1588. len);
  1589. return -EINVAL;
  1590. }
  1591. if (len) {
  1592. if ((len + chanp->bcs->tx_cnt) > MAX_DATA_MEM) {
  1593. /* Must return 0 here, since this is not an error
  1594. * but a temporary lack of resources.
  1595. */
  1596. if (chanp->debug & 0x800)
  1597. link_debug(chanp, 1, "writebuf: no buffers for %d bytes", len);
  1598. return 0;
  1599. } else if (chanp->debug & 0x800)
  1600. link_debug(chanp, 1, "writebuf %d/%d/%d", len, chanp->bcs->tx_cnt, MAX_DATA_MEM);
  1601. nskb = skb_clone(skb, GFP_ATOMIC);
  1602. if (nskb) {
  1603. nskb->truesize = nskb->len;
  1604. if (!ack)
  1605. nskb->pkt_type = PACKET_NOACK;
  1606. if (chanp->l2_active_protocol == ISDN_PROTO_L2_X75I)
  1607. st->l3.l3l2(st, DL_DATA | REQUEST, nskb);
  1608. else {
  1609. chanp->bcs->tx_cnt += len;
  1610. st->l2.l2l1(st, PH_DATA | REQUEST, nskb);
  1611. }
  1612. dev_kfree_skb(skb);
  1613. } else
  1614. len = 0;
  1615. }
  1616. return (len);
  1617. }