callc.c 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791
  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. }