callc.c 48 KB

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