callc.c 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793
  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/init.h>
  20. #include "hisax.h"
  21. #include <linux/isdn/capicmd.h>
  22. const char *lli_revision = "$Revision: 2.59.2.4 $";
  23. extern struct IsdnCard cards[];
  24. extern int nrcards;
  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 paket 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 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. #define FNCOUNT (sizeof(fnlist)/sizeof(struct FsmNode))
  724. int __init
  725. CallcNew(void)
  726. {
  727. callcfsm.state_count = STATE_COUNT;
  728. callcfsm.event_count = EVENT_COUNT;
  729. callcfsm.strEvent = strEvent;
  730. callcfsm.strState = strState;
  731. return FsmNew(&callcfsm, fnlist, FNCOUNT);
  732. }
  733. void
  734. CallcFree(void)
  735. {
  736. FsmFree(&callcfsm);
  737. }
  738. static void
  739. release_b_st(struct Channel *chanp)
  740. {
  741. struct PStack *st = chanp->b_st;
  742. if(test_and_clear_bit(FLG_START_B, &chanp->Flags)) {
  743. chanp->bcs->BC_Close(chanp->bcs);
  744. switch (chanp->l2_active_protocol) {
  745. case (ISDN_PROTO_L2_X75I):
  746. releasestack_isdnl2(st);
  747. break;
  748. case (ISDN_PROTO_L2_HDLC):
  749. case (ISDN_PROTO_L2_HDLC_56K):
  750. case (ISDN_PROTO_L2_TRANS):
  751. case (ISDN_PROTO_L2_MODEM):
  752. case (ISDN_PROTO_L2_FAX):
  753. releasestack_transl2(st);
  754. break;
  755. }
  756. }
  757. }
  758. static struct Channel
  759. *selectfreechannel(struct PStack *st, int bch)
  760. {
  761. struct IsdnCardState *cs = st->l1.hardware;
  762. struct Channel *chanp = st->lli.userdata;
  763. int i;
  764. if (test_bit(FLG_TWO_DCHAN, &cs->HW_Flags))
  765. i=1;
  766. else
  767. i=0;
  768. if (!bch) {
  769. i = 2; /* virtual channel */
  770. chanp += 2;
  771. }
  772. while (i < ((bch) ? cs->chanlimit : (2 + MAX_WAITING_CALLS))) {
  773. if (chanp->fi.state == ST_NULL)
  774. return (chanp);
  775. chanp++;
  776. i++;
  777. }
  778. if (bch) /* number of channels is limited */ {
  779. i = 2; /* virtual channel */
  780. chanp = st->lli.userdata;
  781. chanp += i;
  782. while (i < (2 + MAX_WAITING_CALLS)) {
  783. if (chanp->fi.state == ST_NULL)
  784. return (chanp);
  785. chanp++;
  786. i++;
  787. }
  788. }
  789. return (NULL);
  790. }
  791. static void stat_redir_result(struct IsdnCardState *cs, int chan, ulong result)
  792. { isdn_ctrl ic;
  793. ic.driver = cs->myid;
  794. ic.command = ISDN_STAT_REDIR;
  795. ic.arg = chan;
  796. ic.parm.num[0] = result;
  797. cs->iif.statcallb(&ic);
  798. } /* stat_redir_result */
  799. static void
  800. dchan_l3l4(struct PStack *st, int pr, void *arg)
  801. {
  802. struct l3_process *pc = arg;
  803. struct IsdnCardState *cs = st->l1.hardware;
  804. struct Channel *chanp;
  805. if(!pc)
  806. return;
  807. if (pr == (CC_SETUP | INDICATION)) {
  808. if (!(chanp = selectfreechannel(pc->st, pc->para.bchannel))) {
  809. pc->para.cause = 0x11; /* User busy */
  810. pc->st->lli.l4l3(pc->st, CC_REJECT | REQUEST, pc);
  811. } else {
  812. chanp->proc = pc;
  813. pc->chan = chanp;
  814. FsmEvent(&chanp->fi, EV_SETUP_IND, NULL);
  815. }
  816. return;
  817. }
  818. if (!(chanp = pc->chan))
  819. return;
  820. switch (pr) {
  821. case (CC_MORE_INFO | INDICATION):
  822. FsmEvent(&chanp->fi, EV_SETUP_IND, NULL);
  823. break;
  824. case (CC_DISCONNECT | INDICATION):
  825. FsmEvent(&chanp->fi, EV_DISCONNECT_IND, NULL);
  826. break;
  827. case (CC_RELEASE | CONFIRM):
  828. FsmEvent(&chanp->fi, EV_RELEASE, NULL);
  829. break;
  830. case (CC_SUSPEND | CONFIRM):
  831. FsmEvent(&chanp->fi, EV_RELEASE, NULL);
  832. break;
  833. case (CC_RESUME | CONFIRM):
  834. FsmEvent(&chanp->fi, EV_SETUP_CNF, NULL);
  835. break;
  836. case (CC_RESUME_ERR):
  837. FsmEvent(&chanp->fi, EV_RELEASE, NULL);
  838. break;
  839. case (CC_RELEASE | INDICATION):
  840. FsmEvent(&chanp->fi, EV_RELEASE, NULL);
  841. break;
  842. case (CC_SETUP_COMPL | INDICATION):
  843. FsmEvent(&chanp->fi, EV_SETUP_CMPL_IND, NULL);
  844. break;
  845. case (CC_SETUP | CONFIRM):
  846. FsmEvent(&chanp->fi, EV_SETUP_CNF, NULL);
  847. break;
  848. case (CC_CHARGE | INDICATION):
  849. FsmEvent(&chanp->fi, EV_CINF, NULL);
  850. break;
  851. case (CC_NOSETUP_RSP):
  852. FsmEvent(&chanp->fi, EV_NOSETUP_RSP, NULL);
  853. break;
  854. case (CC_SETUP_ERR):
  855. FsmEvent(&chanp->fi, EV_SETUP_ERR, NULL);
  856. break;
  857. case (CC_CONNECT_ERR):
  858. FsmEvent(&chanp->fi, EV_CONNECT_ERR, NULL);
  859. break;
  860. case (CC_RELEASE_ERR):
  861. FsmEvent(&chanp->fi, EV_RELEASE, NULL);
  862. break;
  863. case (CC_PROCEED_SEND | INDICATION):
  864. case (CC_PROCEEDING | INDICATION):
  865. case (CC_ALERTING | INDICATION):
  866. case (CC_PROGRESS | INDICATION):
  867. case (CC_NOTIFY | INDICATION):
  868. break;
  869. case (CC_REDIR | INDICATION):
  870. stat_redir_result(cs, chanp->chan, pc->redir_result);
  871. break;
  872. default:
  873. if (chanp->debug & 0x800) {
  874. HiSax_putstatus(chanp->cs, "Ch",
  875. "%d L3->L4 unknown primitiv %#x",
  876. chanp->chan, pr);
  877. }
  878. }
  879. }
  880. static void
  881. dummy_pstack(struct PStack *st, int pr, void *arg) {
  882. printk(KERN_WARNING"call to dummy_pstack pr=%04x arg %lx\n", pr, (long)arg);
  883. }
  884. static int
  885. init_PStack(struct PStack **stp) {
  886. *stp = kmalloc(sizeof(struct PStack), GFP_ATOMIC);
  887. if (!*stp)
  888. return -ENOMEM;
  889. (*stp)->next = NULL;
  890. (*stp)->l1.l1l2 = dummy_pstack;
  891. (*stp)->l1.l1hw = dummy_pstack;
  892. (*stp)->l1.l1tei = dummy_pstack;
  893. (*stp)->l2.l2tei = dummy_pstack;
  894. (*stp)->l2.l2l1 = dummy_pstack;
  895. (*stp)->l2.l2l3 = dummy_pstack;
  896. (*stp)->l3.l3l2 = dummy_pstack;
  897. (*stp)->l3.l3ml3 = dummy_pstack;
  898. (*stp)->l3.l3l4 = dummy_pstack;
  899. (*stp)->lli.l4l3 = dummy_pstack;
  900. (*stp)->ma.layer = dummy_pstack;
  901. return 0;
  902. }
  903. static int
  904. init_d_st(struct Channel *chanp)
  905. {
  906. struct PStack *st;
  907. struct IsdnCardState *cs = chanp->cs;
  908. char tmp[16];
  909. int err;
  910. err = init_PStack(&chanp->d_st);
  911. if (err)
  912. return err;
  913. st = chanp->d_st;
  914. st->next = NULL;
  915. HiSax_addlist(cs, st);
  916. setstack_HiSax(st, cs);
  917. st->l2.sap = 0;
  918. st->l2.tei = -1;
  919. st->l2.flag = 0;
  920. test_and_set_bit(FLG_MOD128, &st->l2.flag);
  921. test_and_set_bit(FLG_LAPD, &st->l2.flag);
  922. test_and_set_bit(FLG_ORIG, &st->l2.flag);
  923. st->l2.maxlen = MAX_DFRAME_LEN;
  924. st->l2.window = 1;
  925. st->l2.T200 = 1000; /* 1000 milliseconds */
  926. st->l2.N200 = 3; /* try 3 times */
  927. st->l2.T203 = 10000; /* 10000 milliseconds */
  928. if (test_bit(FLG_TWO_DCHAN, &cs->HW_Flags))
  929. sprintf(tmp, "DCh%d Q.921 ", chanp->chan);
  930. else
  931. sprintf(tmp, "DCh Q.921 ");
  932. setstack_isdnl2(st, tmp);
  933. setstack_l3dc(st, chanp);
  934. st->lli.userdata = chanp;
  935. st->l3.l3l4 = dchan_l3l4;
  936. return 0;
  937. }
  938. static void
  939. callc_debug(struct FsmInst *fi, char *fmt, ...)
  940. {
  941. va_list args;
  942. struct Channel *chanp = fi->userdata;
  943. char tmp[16];
  944. va_start(args, fmt);
  945. sprintf(tmp, "Ch%d callc ", chanp->chan);
  946. VHiSax_putstatus(chanp->cs, tmp, fmt, args);
  947. va_end(args);
  948. }
  949. static int
  950. init_chan(int chan, struct IsdnCardState *csta)
  951. {
  952. struct Channel *chanp = csta->channel + chan;
  953. int err;
  954. chanp->cs = csta;
  955. chanp->bcs = csta->bcs + chan;
  956. chanp->chan = chan;
  957. chanp->incoming = 0;
  958. chanp->debug = 0;
  959. chanp->Flags = 0;
  960. chanp->leased = 0;
  961. err = init_PStack(&chanp->b_st);
  962. if (err)
  963. return err;
  964. chanp->b_st->l1.delay = DEFAULT_B_DELAY;
  965. chanp->fi.fsm = &callcfsm;
  966. chanp->fi.state = ST_NULL;
  967. chanp->fi.debug = 0;
  968. chanp->fi.userdata = chanp;
  969. chanp->fi.printdebug = callc_debug;
  970. FsmInitTimer(&chanp->fi, &chanp->dial_timer);
  971. FsmInitTimer(&chanp->fi, &chanp->drel_timer);
  972. if (!chan || (test_bit(FLG_TWO_DCHAN, &csta->HW_Flags) && chan < 2)) {
  973. err = init_d_st(chanp);
  974. if (err)
  975. return err;
  976. } else {
  977. chanp->d_st = csta->channel->d_st;
  978. }
  979. chanp->data_open = 0;
  980. return 0;
  981. }
  982. int
  983. CallcNewChan(struct IsdnCardState *csta) {
  984. int i, err;
  985. chancount += 2;
  986. err = init_chan(0, csta);
  987. if (err)
  988. return err;
  989. err = init_chan(1, csta);
  990. if (err)
  991. return err;
  992. printk(KERN_INFO "HiSax: 2 channels added\n");
  993. for (i = 0; i < MAX_WAITING_CALLS; i++) {
  994. err = init_chan(i+2,csta);
  995. if (err)
  996. return err;
  997. }
  998. printk(KERN_INFO "HiSax: MAX_WAITING_CALLS added\n");
  999. if (test_bit(FLG_PTP, &csta->channel->d_st->l2.flag)) {
  1000. printk(KERN_INFO "LAYER2 WATCHING ESTABLISH\n");
  1001. csta->channel->d_st->lli.l4l3(csta->channel->d_st,
  1002. DL_ESTABLISH | REQUEST, NULL);
  1003. }
  1004. return (0);
  1005. }
  1006. static void
  1007. release_d_st(struct Channel *chanp)
  1008. {
  1009. struct PStack *st = chanp->d_st;
  1010. if (!st)
  1011. return;
  1012. releasestack_isdnl2(st);
  1013. releasestack_isdnl3(st);
  1014. HiSax_rmlist(st->l1.hardware, st);
  1015. kfree(st);
  1016. chanp->d_st = NULL;
  1017. }
  1018. void
  1019. CallcFreeChan(struct IsdnCardState *csta)
  1020. {
  1021. int i;
  1022. for (i = 0; i < 2; i++) {
  1023. FsmDelTimer(&csta->channel[i].drel_timer, 74);
  1024. FsmDelTimer(&csta->channel[i].dial_timer, 75);
  1025. if (i || test_bit(FLG_TWO_DCHAN, &csta->HW_Flags))
  1026. release_d_st(csta->channel + i);
  1027. if (csta->channel[i].b_st) {
  1028. release_b_st(csta->channel + i);
  1029. kfree(csta->channel[i].b_st);
  1030. csta->channel[i].b_st = NULL;
  1031. } else
  1032. printk(KERN_WARNING "CallcFreeChan b_st ch%d allready freed\n", i);
  1033. if (i || test_bit(FLG_TWO_DCHAN, &csta->HW_Flags)) {
  1034. release_d_st(csta->channel + i);
  1035. } else
  1036. csta->channel[i].d_st = NULL;
  1037. }
  1038. }
  1039. static void
  1040. lldata_handler(struct PStack *st, int pr, void *arg)
  1041. {
  1042. struct Channel *chanp = (struct Channel *) st->lli.userdata;
  1043. struct sk_buff *skb = arg;
  1044. switch (pr) {
  1045. case (DL_DATA | INDICATION):
  1046. if (chanp->data_open) {
  1047. if (chanp->debug & 0x800)
  1048. link_debug(chanp, 0, "lldata: %d", skb->len);
  1049. chanp->cs->iif.rcvcallb_skb(chanp->cs->myid, chanp->chan, skb);
  1050. } else {
  1051. link_debug(chanp, 0, "lldata: channel not open");
  1052. dev_kfree_skb(skb);
  1053. }
  1054. break;
  1055. case (DL_ESTABLISH | INDICATION):
  1056. case (DL_ESTABLISH | CONFIRM):
  1057. FsmEvent(&chanp->fi, EV_BC_EST, NULL);
  1058. break;
  1059. case (DL_RELEASE | INDICATION):
  1060. case (DL_RELEASE | CONFIRM):
  1061. FsmEvent(&chanp->fi, EV_BC_REL, NULL);
  1062. break;
  1063. default:
  1064. printk(KERN_WARNING "lldata_handler unknown primitive %#x\n",
  1065. pr);
  1066. break;
  1067. }
  1068. }
  1069. static void
  1070. lltrans_handler(struct PStack *st, int pr, void *arg)
  1071. {
  1072. struct Channel *chanp = (struct Channel *) st->lli.userdata;
  1073. struct sk_buff *skb = arg;
  1074. switch (pr) {
  1075. case (PH_DATA | INDICATION):
  1076. if (chanp->data_open) {
  1077. if (chanp->debug & 0x800)
  1078. link_debug(chanp, 0, "lltrans: %d", skb->len);
  1079. chanp->cs->iif.rcvcallb_skb(chanp->cs->myid, chanp->chan, skb);
  1080. } else {
  1081. link_debug(chanp, 0, "lltrans: channel not open");
  1082. dev_kfree_skb(skb);
  1083. }
  1084. break;
  1085. case (PH_ACTIVATE | INDICATION):
  1086. case (PH_ACTIVATE | CONFIRM):
  1087. FsmEvent(&chanp->fi, EV_BC_EST, NULL);
  1088. break;
  1089. case (PH_DEACTIVATE | INDICATION):
  1090. case (PH_DEACTIVATE | CONFIRM):
  1091. FsmEvent(&chanp->fi, EV_BC_REL, NULL);
  1092. break;
  1093. default:
  1094. printk(KERN_WARNING "lltrans_handler unknown primitive %#x\n",
  1095. pr);
  1096. break;
  1097. }
  1098. }
  1099. void
  1100. lli_writewakeup(struct PStack *st, int len)
  1101. {
  1102. struct Channel *chanp = st->lli.userdata;
  1103. isdn_ctrl ic;
  1104. if (chanp->debug & 0x800)
  1105. link_debug(chanp, 0, "llwakeup: %d", len);
  1106. ic.driver = chanp->cs->myid;
  1107. ic.command = ISDN_STAT_BSENT;
  1108. ic.arg = chanp->chan;
  1109. ic.parm.length = len;
  1110. chanp->cs->iif.statcallb(&ic);
  1111. }
  1112. static int
  1113. init_b_st(struct Channel *chanp, int incoming)
  1114. {
  1115. struct PStack *st = chanp->b_st;
  1116. struct IsdnCardState *cs = chanp->cs;
  1117. char tmp[16];
  1118. st->l1.hardware = cs;
  1119. if (chanp->leased)
  1120. st->l1.bc = chanp->chan & 1;
  1121. else
  1122. st->l1.bc = chanp->proc->para.bchannel - 1;
  1123. switch (chanp->l2_active_protocol) {
  1124. case (ISDN_PROTO_L2_X75I):
  1125. case (ISDN_PROTO_L2_HDLC):
  1126. st->l1.mode = L1_MODE_HDLC;
  1127. break;
  1128. case (ISDN_PROTO_L2_HDLC_56K):
  1129. st->l1.mode = L1_MODE_HDLC_56K;
  1130. break;
  1131. case (ISDN_PROTO_L2_TRANS):
  1132. st->l1.mode = L1_MODE_TRANS;
  1133. break;
  1134. case (ISDN_PROTO_L2_MODEM):
  1135. st->l1.mode = L1_MODE_V32;
  1136. break;
  1137. case (ISDN_PROTO_L2_FAX):
  1138. st->l1.mode = L1_MODE_FAX;
  1139. break;
  1140. }
  1141. chanp->bcs->conmsg = NULL;
  1142. if (chanp->bcs->BC_SetStack(st, chanp->bcs))
  1143. return (-1);
  1144. st->l2.flag = 0;
  1145. test_and_set_bit(FLG_LAPB, &st->l2.flag);
  1146. st->l2.maxlen = MAX_DATA_SIZE;
  1147. if (!incoming)
  1148. test_and_set_bit(FLG_ORIG, &st->l2.flag);
  1149. st->l2.T200 = 1000; /* 1000 milliseconds */
  1150. st->l2.window = 7;
  1151. st->l2.N200 = 4; /* try 4 times */
  1152. st->l2.T203 = 5000; /* 5000 milliseconds */
  1153. st->l3.debug = 0;
  1154. switch (chanp->l2_active_protocol) {
  1155. case (ISDN_PROTO_L2_X75I):
  1156. sprintf(tmp, "Ch%d X.75", chanp->chan);
  1157. setstack_isdnl2(st, tmp);
  1158. setstack_l3bc(st, chanp);
  1159. st->l2.l2l3 = lldata_handler;
  1160. st->lli.userdata = chanp;
  1161. test_and_clear_bit(FLG_LLI_L1WAKEUP, &st->lli.flag);
  1162. test_and_set_bit(FLG_LLI_L2WAKEUP, &st->lli.flag);
  1163. st->l2.l2m.debug = chanp->debug & 16;
  1164. st->l2.debug = chanp->debug & 64;
  1165. break;
  1166. case (ISDN_PROTO_L2_HDLC):
  1167. case (ISDN_PROTO_L2_HDLC_56K):
  1168. case (ISDN_PROTO_L2_TRANS):
  1169. case (ISDN_PROTO_L2_MODEM):
  1170. case (ISDN_PROTO_L2_FAX):
  1171. st->l1.l1l2 = lltrans_handler;
  1172. st->lli.userdata = chanp;
  1173. test_and_set_bit(FLG_LLI_L1WAKEUP, &st->lli.flag);
  1174. test_and_clear_bit(FLG_LLI_L2WAKEUP, &st->lli.flag);
  1175. setstack_transl2(st);
  1176. setstack_l3bc(st, chanp);
  1177. break;
  1178. }
  1179. test_and_set_bit(FLG_START_B, &chanp->Flags);
  1180. return (0);
  1181. }
  1182. static void
  1183. leased_l4l3(struct PStack *st, int pr, void *arg)
  1184. {
  1185. struct Channel *chanp = (struct Channel *) st->lli.userdata;
  1186. struct sk_buff *skb = arg;
  1187. switch (pr) {
  1188. case (DL_DATA | REQUEST):
  1189. link_debug(chanp, 0, "leased line d-channel DATA");
  1190. dev_kfree_skb(skb);
  1191. break;
  1192. case (DL_ESTABLISH | REQUEST):
  1193. st->l2.l2l1(st, PH_ACTIVATE | REQUEST, NULL);
  1194. break;
  1195. case (DL_RELEASE | REQUEST):
  1196. break;
  1197. default:
  1198. printk(KERN_WARNING "transd_l4l3 unknown primitive %#x\n",
  1199. pr);
  1200. break;
  1201. }
  1202. }
  1203. static void
  1204. leased_l1l2(struct PStack *st, int pr, void *arg)
  1205. {
  1206. struct Channel *chanp = (struct Channel *) st->lli.userdata;
  1207. struct sk_buff *skb = arg;
  1208. int i,event = EV_LEASED_REL;
  1209. switch (pr) {
  1210. case (PH_DATA | INDICATION):
  1211. link_debug(chanp, 0, "leased line d-channel DATA");
  1212. dev_kfree_skb(skb);
  1213. break;
  1214. case (PH_ACTIVATE | INDICATION):
  1215. case (PH_ACTIVATE | CONFIRM):
  1216. event = EV_LEASED;
  1217. case (PH_DEACTIVATE | INDICATION):
  1218. case (PH_DEACTIVATE | CONFIRM):
  1219. if (test_bit(FLG_TWO_DCHAN, &chanp->cs->HW_Flags))
  1220. i = 1;
  1221. else
  1222. i = 0;
  1223. while (i < 2) {
  1224. FsmEvent(&chanp->fi, event, NULL);
  1225. chanp++;
  1226. i++;
  1227. }
  1228. break;
  1229. default:
  1230. printk(KERN_WARNING
  1231. "transd_l1l2 unknown primitive %#x\n", pr);
  1232. break;
  1233. }
  1234. }
  1235. static void
  1236. distr_debug(struct IsdnCardState *csta, int debugflags)
  1237. {
  1238. int i;
  1239. struct Channel *chanp = csta->channel;
  1240. for (i = 0; i < (2 + MAX_WAITING_CALLS) ; i++) {
  1241. chanp[i].debug = debugflags;
  1242. chanp[i].fi.debug = debugflags & 2;
  1243. chanp[i].d_st->l2.l2m.debug = debugflags & 8;
  1244. chanp[i].b_st->l2.l2m.debug = debugflags & 0x10;
  1245. chanp[i].d_st->l2.debug = debugflags & 0x20;
  1246. chanp[i].b_st->l2.debug = debugflags & 0x40;
  1247. chanp[i].d_st->l3.l3m.debug = debugflags & 0x80;
  1248. chanp[i].b_st->l3.l3m.debug = debugflags & 0x100;
  1249. chanp[i].b_st->ma.tei_m.debug = debugflags & 0x200;
  1250. chanp[i].b_st->ma.debug = debugflags & 0x200;
  1251. chanp[i].d_st->l1.l1m.debug = debugflags & 0x1000;
  1252. chanp[i].b_st->l1.l1m.debug = debugflags & 0x2000;
  1253. }
  1254. if (debugflags & 4)
  1255. csta->debug |= DEB_DLOG_HEX;
  1256. else
  1257. csta->debug &= ~DEB_DLOG_HEX;
  1258. }
  1259. static char tmpbuf[256];
  1260. static void
  1261. capi_debug(struct Channel *chanp, capi_msg *cm)
  1262. {
  1263. char *t = tmpbuf;
  1264. t += QuickHex(t, (u_char *)cm, (cm->Length>50)? 50: cm->Length);
  1265. t--;
  1266. *t= 0;
  1267. HiSax_putstatus(chanp->cs, "Ch", "%d CAPIMSG %s", chanp->chan, tmpbuf);
  1268. }
  1269. static void
  1270. lli_got_fac_req(struct Channel *chanp, capi_msg *cm) {
  1271. if ((cm->para[0] != 3) || (cm->para[1] != 0))
  1272. return;
  1273. if (cm->para[2]<3)
  1274. return;
  1275. if (cm->para[4] != 0)
  1276. return;
  1277. switch(cm->para[3]) {
  1278. case 4: /* Suspend */
  1279. strncpy(chanp->setup.phone, &cm->para[5], cm->para[5] +1);
  1280. FsmEvent(&chanp->fi, EV_SUSPEND, cm);
  1281. break;
  1282. case 5: /* Resume */
  1283. strncpy(chanp->setup.phone, &cm->para[5], cm->para[5] +1);
  1284. if (chanp->fi.state == ST_NULL) {
  1285. FsmEvent(&chanp->fi, EV_RESUME, cm);
  1286. } else {
  1287. FsmDelTimer(&chanp->dial_timer, 72);
  1288. FsmAddTimer(&chanp->dial_timer, 80, EV_RESUME, cm, 73);
  1289. }
  1290. break;
  1291. }
  1292. }
  1293. static void
  1294. lli_got_manufacturer(struct Channel *chanp, struct IsdnCardState *cs, capi_msg *cm) {
  1295. if ((cs->typ == ISDN_CTYPE_ELSA) || (cs->typ == ISDN_CTYPE_ELSA_PNP) ||
  1296. (cs->typ == ISDN_CTYPE_ELSA_PCI)) {
  1297. if (cs->hw.elsa.MFlag) {
  1298. cs->cardmsg(cs, CARD_AUX_IND, cm->para);
  1299. }
  1300. }
  1301. }
  1302. /***************************************************************/
  1303. /* Limit the available number of channels for the current card */
  1304. /***************************************************************/
  1305. static int
  1306. set_channel_limit(struct IsdnCardState *cs, int chanmax)
  1307. {
  1308. isdn_ctrl ic;
  1309. int i, ii;
  1310. if ((chanmax < 0) || (chanmax > 2))
  1311. return(-EINVAL);
  1312. cs->chanlimit = 0;
  1313. for (ii = 0; ii < 2; ii++) {
  1314. ic.driver = cs->myid;
  1315. ic.command = ISDN_STAT_DISCH;
  1316. ic.arg = ii;
  1317. if (ii >= chanmax)
  1318. ic.parm.num[0] = 0; /* disabled */
  1319. else
  1320. ic.parm.num[0] = 1; /* enabled */
  1321. i = cs->iif.statcallb(&ic);
  1322. if (i) return(-EINVAL);
  1323. if (ii < chanmax)
  1324. cs->chanlimit++;
  1325. }
  1326. return(0);
  1327. } /* set_channel_limit */
  1328. int
  1329. HiSax_command(isdn_ctrl * ic)
  1330. {
  1331. struct IsdnCardState *csta = hisax_findcard(ic->driver);
  1332. struct PStack *st;
  1333. struct Channel *chanp;
  1334. int i;
  1335. u_int num;
  1336. if (!csta) {
  1337. printk(KERN_ERR
  1338. "HiSax: if_command %d called with invalid driverId %d!\n",
  1339. ic->command, ic->driver);
  1340. return -ENODEV;
  1341. }
  1342. switch (ic->command) {
  1343. case (ISDN_CMD_SETEAZ):
  1344. chanp = csta->channel + ic->arg;
  1345. break;
  1346. case (ISDN_CMD_SETL2):
  1347. chanp = csta->channel + (ic->arg & 0xff);
  1348. if (chanp->debug & 1)
  1349. link_debug(chanp, 1, "SETL2 card %d %ld",
  1350. csta->cardnr + 1, ic->arg >> 8);
  1351. chanp->l2_protocol = ic->arg >> 8;
  1352. break;
  1353. case (ISDN_CMD_SETL3):
  1354. chanp = csta->channel + (ic->arg & 0xff);
  1355. if (chanp->debug & 1)
  1356. link_debug(chanp, 1, "SETL3 card %d %ld",
  1357. csta->cardnr + 1, ic->arg >> 8);
  1358. chanp->l3_protocol = ic->arg >> 8;
  1359. break;
  1360. case (ISDN_CMD_DIAL):
  1361. chanp = csta->channel + (ic->arg & 0xff);
  1362. if (chanp->debug & 1)
  1363. link_debug(chanp, 1, "DIAL %s -> %s (%d,%d)",
  1364. ic->parm.setup.eazmsn, ic->parm.setup.phone,
  1365. ic->parm.setup.si1, ic->parm.setup.si2);
  1366. memcpy(&chanp->setup, &ic->parm.setup, sizeof(setup_parm));
  1367. if (!strcmp(chanp->setup.eazmsn, "0"))
  1368. chanp->setup.eazmsn[0] = '\0';
  1369. /* this solution is dirty and may be change, if
  1370. * we make a callreference based callmanager */
  1371. if (chanp->fi.state == ST_NULL) {
  1372. FsmEvent(&chanp->fi, EV_DIAL, NULL);
  1373. } else {
  1374. FsmDelTimer(&chanp->dial_timer, 70);
  1375. FsmAddTimer(&chanp->dial_timer, 50, EV_DIAL, NULL, 71);
  1376. }
  1377. break;
  1378. case (ISDN_CMD_ACCEPTB):
  1379. chanp = csta->channel + ic->arg;
  1380. if (chanp->debug & 1)
  1381. link_debug(chanp, 1, "ACCEPTB");
  1382. FsmEvent(&chanp->fi, EV_ACCEPTB, NULL);
  1383. break;
  1384. case (ISDN_CMD_ACCEPTD):
  1385. chanp = csta->channel + ic->arg;
  1386. memcpy(&chanp->setup, &ic->parm.setup, sizeof(setup_parm));
  1387. if (chanp->debug & 1)
  1388. link_debug(chanp, 1, "ACCEPTD");
  1389. FsmEvent(&chanp->fi, EV_ACCEPTD, NULL);
  1390. break;
  1391. case (ISDN_CMD_HANGUP):
  1392. chanp = csta->channel + ic->arg;
  1393. if (chanp->debug & 1)
  1394. link_debug(chanp, 1, "HANGUP");
  1395. FsmEvent(&chanp->fi, EV_HANGUP, NULL);
  1396. break;
  1397. case (CAPI_PUT_MESSAGE):
  1398. chanp = csta->channel + ic->arg;
  1399. if (chanp->debug & 1)
  1400. capi_debug(chanp, &ic->parm.cmsg);
  1401. if (ic->parm.cmsg.Length < 8)
  1402. break;
  1403. switch(ic->parm.cmsg.Command) {
  1404. case CAPI_FACILITY:
  1405. if (ic->parm.cmsg.Subcommand == CAPI_REQ)
  1406. lli_got_fac_req(chanp, &ic->parm.cmsg);
  1407. break;
  1408. case CAPI_MANUFACTURER:
  1409. if (ic->parm.cmsg.Subcommand == CAPI_REQ)
  1410. lli_got_manufacturer(chanp, csta, &ic->parm.cmsg);
  1411. break;
  1412. default:
  1413. break;
  1414. }
  1415. break;
  1416. case (ISDN_CMD_IOCTL):
  1417. switch (ic->arg) {
  1418. case (0):
  1419. num = *(unsigned int *) ic->parm.num;
  1420. HiSax_reportcard(csta->cardnr, num);
  1421. break;
  1422. case (1):
  1423. num = *(unsigned int *) ic->parm.num;
  1424. distr_debug(csta, num);
  1425. printk(KERN_DEBUG "HiSax: debugging flags card %d set to %x\n",
  1426. csta->cardnr + 1, num);
  1427. HiSax_putstatus(csta, "debugging flags ",
  1428. "card %d set to %x", csta->cardnr + 1, num);
  1429. break;
  1430. case (2):
  1431. num = *(unsigned int *) ic->parm.num;
  1432. csta->channel[0].b_st->l1.delay = num;
  1433. csta->channel[1].b_st->l1.delay = num;
  1434. HiSax_putstatus(csta, "delay ", "card %d set to %d ms",
  1435. csta->cardnr + 1, num);
  1436. printk(KERN_DEBUG "HiSax: delay card %d set to %d ms\n",
  1437. csta->cardnr + 1, num);
  1438. break;
  1439. case (5): /* set card in leased mode */
  1440. num = *(unsigned int *) ic->parm.num;
  1441. if ((num <1) || (num > 2)) {
  1442. HiSax_putstatus(csta, "Set LEASED ",
  1443. "wrong channel %d", num);
  1444. printk(KERN_WARNING "HiSax: Set LEASED wrong channel %d\n",
  1445. num);
  1446. } else {
  1447. num--;
  1448. chanp = csta->channel +num;
  1449. chanp->leased = 1;
  1450. HiSax_putstatus(csta, "Card",
  1451. "%d channel %d set leased mode\n",
  1452. csta->cardnr + 1, num + 1);
  1453. chanp->d_st->l1.l1l2 = leased_l1l2;
  1454. chanp->d_st->lli.l4l3 = leased_l4l3;
  1455. chanp->d_st->lli.l4l3(chanp->d_st,
  1456. DL_ESTABLISH | REQUEST, NULL);
  1457. }
  1458. break;
  1459. case (6): /* set B-channel test loop */
  1460. num = *(unsigned int *) ic->parm.num;
  1461. if (csta->stlist)
  1462. csta->stlist->l2.l2l1(csta->stlist,
  1463. PH_TESTLOOP | REQUEST, (void *) (long)num);
  1464. break;
  1465. case (7): /* set card in PTP mode */
  1466. num = *(unsigned int *) ic->parm.num;
  1467. if (test_bit(FLG_TWO_DCHAN, &csta->HW_Flags)) {
  1468. printk(KERN_ERR "HiSax PTP mode only with one TEI possible\n");
  1469. } else if (num) {
  1470. test_and_set_bit(FLG_PTP, &csta->channel[0].d_st->l2.flag);
  1471. test_and_set_bit(FLG_FIXED_TEI, &csta->channel[0].d_st->l2.flag);
  1472. csta->channel[0].d_st->l2.tei = 0;
  1473. HiSax_putstatus(csta, "set card ", "in PTP mode");
  1474. printk(KERN_DEBUG "HiSax: set card in PTP mode\n");
  1475. printk(KERN_INFO "LAYER2 WATCHING ESTABLISH\n");
  1476. csta->channel[0].d_st->lli.l4l3(csta->channel[0].d_st,
  1477. DL_ESTABLISH | REQUEST, NULL);
  1478. } else {
  1479. test_and_clear_bit(FLG_PTP, &csta->channel[0].d_st->l2.flag);
  1480. test_and_clear_bit(FLG_FIXED_TEI, &csta->channel[0].d_st->l2.flag);
  1481. HiSax_putstatus(csta, "set card ", "in PTMP mode");
  1482. printk(KERN_DEBUG "HiSax: set card in PTMP mode\n");
  1483. }
  1484. break;
  1485. case (8): /* set card in FIXED TEI mode */
  1486. num = *(unsigned int *) ic->parm.num;
  1487. chanp = csta->channel + (num & 1);
  1488. num = num >>1;
  1489. if (num == 127) {
  1490. test_and_clear_bit(FLG_FIXED_TEI, &chanp->d_st->l2.flag);
  1491. chanp->d_st->l2.tei = -1;
  1492. HiSax_putstatus(csta, "set card ", "in VAR TEI mode");
  1493. printk(KERN_DEBUG "HiSax: set card in VAR TEI mode\n");
  1494. } else {
  1495. test_and_set_bit(FLG_FIXED_TEI, &chanp->d_st->l2.flag);
  1496. chanp->d_st->l2.tei = num;
  1497. HiSax_putstatus(csta, "set card ", "in FIXED TEI (%d) mode", num);
  1498. printk(KERN_DEBUG "HiSax: set card in FIXED TEI (%d) mode\n",
  1499. num);
  1500. }
  1501. chanp->d_st->lli.l4l3(chanp->d_st,
  1502. DL_ESTABLISH | REQUEST, NULL);
  1503. break;
  1504. case (11):
  1505. num = csta->debug & DEB_DLOG_HEX;
  1506. csta->debug = *(unsigned int *) ic->parm.num;
  1507. csta->debug |= num;
  1508. HiSax_putstatus(cards[0].cs, "l1 debugging ",
  1509. "flags card %d set to %x",
  1510. csta->cardnr + 1, csta->debug);
  1511. printk(KERN_DEBUG "HiSax: l1 debugging flags card %d set to %x\n",
  1512. csta->cardnr + 1, csta->debug);
  1513. break;
  1514. case (13):
  1515. csta->channel[0].d_st->l3.debug = *(unsigned int *) ic->parm.num;
  1516. csta->channel[1].d_st->l3.debug = *(unsigned int *) ic->parm.num;
  1517. HiSax_putstatus(cards[0].cs, "l3 debugging ",
  1518. "flags card %d set to %x\n", csta->cardnr + 1,
  1519. *(unsigned int *) ic->parm.num);
  1520. printk(KERN_DEBUG "HiSax: l3 debugging flags card %d set to %x\n",
  1521. csta->cardnr + 1, *(unsigned int *) ic->parm.num);
  1522. break;
  1523. case (10):
  1524. i = *(unsigned int *) ic->parm.num;
  1525. return(set_channel_limit(csta, i));
  1526. default:
  1527. if (csta->auxcmd)
  1528. return(csta->auxcmd(csta, ic));
  1529. printk(KERN_DEBUG "HiSax: invalid ioclt %d\n",
  1530. (int) ic->arg);
  1531. return (-EINVAL);
  1532. }
  1533. break;
  1534. case (ISDN_CMD_PROCEED):
  1535. chanp = csta->channel + ic->arg;
  1536. if (chanp->debug & 1)
  1537. link_debug(chanp, 1, "PROCEED");
  1538. FsmEvent(&chanp->fi, EV_PROCEED, NULL);
  1539. break;
  1540. case (ISDN_CMD_ALERT):
  1541. chanp = csta->channel + ic->arg;
  1542. if (chanp->debug & 1)
  1543. link_debug(chanp, 1, "ALERT");
  1544. FsmEvent(&chanp->fi, EV_ALERT, NULL);
  1545. break;
  1546. case (ISDN_CMD_REDIR):
  1547. chanp = csta->channel + ic->arg;
  1548. if (chanp->debug & 1)
  1549. link_debug(chanp, 1, "REDIR");
  1550. memcpy(&chanp->setup, &ic->parm.setup, sizeof(setup_parm));
  1551. FsmEvent(&chanp->fi, EV_REDIR, NULL);
  1552. break;
  1553. /* protocol specific io commands */
  1554. case (ISDN_CMD_PROT_IO):
  1555. for (st = csta->stlist; st; st = st->next)
  1556. if (st->protocol == (ic->arg & 0xFF))
  1557. return(st->lli.l4l3_proto(st, ic));
  1558. return(-EINVAL);
  1559. break;
  1560. default:
  1561. if (csta->auxcmd)
  1562. return(csta->auxcmd(csta, ic));
  1563. return(-EINVAL);
  1564. }
  1565. return (0);
  1566. }
  1567. int
  1568. HiSax_writebuf_skb(int id, int chan, int ack, struct sk_buff *skb)
  1569. {
  1570. struct IsdnCardState *csta = hisax_findcard(id);
  1571. struct Channel *chanp;
  1572. struct PStack *st;
  1573. int len = skb->len;
  1574. struct sk_buff *nskb;
  1575. if (!csta) {
  1576. printk(KERN_ERR
  1577. "HiSax: if_sendbuf called with invalid driverId!\n");
  1578. return -ENODEV;
  1579. }
  1580. chanp = csta->channel + chan;
  1581. st = chanp->b_st;
  1582. if (!chanp->data_open) {
  1583. link_debug(chanp, 1, "writebuf: channel not open");
  1584. return -EIO;
  1585. }
  1586. if (len > MAX_DATA_SIZE) {
  1587. link_debug(chanp, 1, "writebuf: packet too large (%d bytes)", len);
  1588. printk(KERN_WARNING "HiSax_writebuf: packet too large (%d bytes) !\n",
  1589. len);
  1590. return -EINVAL;
  1591. }
  1592. if (len) {
  1593. if ((len + chanp->bcs->tx_cnt) > MAX_DATA_MEM) {
  1594. /* Must return 0 here, since this is not an error
  1595. * but a temporary lack of resources.
  1596. */
  1597. if (chanp->debug & 0x800)
  1598. link_debug(chanp, 1, "writebuf: no buffers for %d bytes", len);
  1599. return 0;
  1600. } else if (chanp->debug & 0x800)
  1601. link_debug(chanp, 1, "writebuf %d/%d/%d", len, chanp->bcs->tx_cnt,MAX_DATA_MEM);
  1602. nskb = skb_clone(skb, GFP_ATOMIC);
  1603. if (nskb) {
  1604. nskb->truesize = nskb->len;
  1605. if (!ack)
  1606. nskb->pkt_type = PACKET_NOACK;
  1607. if (chanp->l2_active_protocol == ISDN_PROTO_L2_X75I)
  1608. st->l3.l3l2(st, DL_DATA | REQUEST, nskb);
  1609. else {
  1610. chanp->bcs->tx_cnt += len;
  1611. st->l2.l2l1(st, PH_DATA | REQUEST, nskb);
  1612. }
  1613. dev_kfree_skb(skb);
  1614. } else
  1615. len = 0;
  1616. }
  1617. return (len);
  1618. }