l3_1tr6.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946
  1. /* $Id: l3_1tr6.c,v 2.15.2.3 2004/01/13 14:31:25 keil Exp $
  2. *
  3. * German 1TR6 D-channel protocol
  4. *
  5. * Author Karsten Keil
  6. * Copyright by Karsten Keil <keil@isdn4linux.de>
  7. *
  8. * This software may be used and distributed according to the terms
  9. * of the GNU General Public License, incorporated herein by reference.
  10. *
  11. * For changes and modifications please read
  12. * Documentation/isdn/HiSax.cert
  13. *
  14. */
  15. #include "hisax.h"
  16. #include "l3_1tr6.h"
  17. #include "isdnl3.h"
  18. #include <linux/ctype.h>
  19. extern char *HiSax_getrev(const char *revision);
  20. static const char *l3_1tr6_revision = "$Revision: 2.15.2.3 $";
  21. #define MsgHead(ptr, cref, mty, dis) \
  22. *ptr++ = dis; \
  23. *ptr++ = 0x1; \
  24. *ptr++ = cref ^ 0x80; \
  25. *ptr++ = mty
  26. static void
  27. l3_1TR6_message(struct l3_process *pc, u_char mt, u_char pd)
  28. {
  29. struct sk_buff *skb;
  30. u_char *p;
  31. if (!(skb = l3_alloc_skb(4)))
  32. return;
  33. p = skb_put(skb, 4);
  34. MsgHead(p, pc->callref, mt, pd);
  35. l3_msg(pc->st, DL_DATA | REQUEST, skb);
  36. }
  37. static void
  38. l3_1tr6_release_req(struct l3_process *pc, u_char pr, void *arg)
  39. {
  40. StopAllL3Timer(pc);
  41. newl3state(pc, 19);
  42. l3_1TR6_message(pc, MT_N1_REL, PROTO_DIS_N1);
  43. L3AddTimer(&pc->timer, T308, CC_T308_1);
  44. }
  45. static void
  46. l3_1tr6_invalid(struct l3_process *pc, u_char pr, void *arg)
  47. {
  48. struct sk_buff *skb = arg;
  49. dev_kfree_skb(skb);
  50. l3_1tr6_release_req(pc, 0, NULL);
  51. }
  52. static void
  53. l3_1tr6_error(struct l3_process *pc, u_char *msg, struct sk_buff *skb)
  54. {
  55. dev_kfree_skb(skb);
  56. if (pc->st->l3.debug & L3_DEB_WARN)
  57. l3_debug(pc->st, msg);
  58. l3_1tr6_release_req(pc, 0, NULL);
  59. }
  60. static void
  61. l3_1tr6_setup_req(struct l3_process *pc, u_char pr, void *arg)
  62. {
  63. struct sk_buff *skb;
  64. u_char tmp[128];
  65. u_char *p = tmp;
  66. u_char *teln;
  67. u_char *eaz;
  68. u_char channel = 0;
  69. int l;
  70. MsgHead(p, pc->callref, MT_N1_SETUP, PROTO_DIS_N1);
  71. teln = pc->para.setup.phone;
  72. pc->para.spv = 0;
  73. if (!isdigit(*teln)) {
  74. switch (0x5f & *teln) {
  75. case 'S':
  76. pc->para.spv = 1;
  77. break;
  78. case 'C':
  79. channel = 0x08;
  80. case 'P':
  81. channel |= 0x80;
  82. teln++;
  83. if (*teln == '1')
  84. channel |= 0x01;
  85. else
  86. channel |= 0x02;
  87. break;
  88. default:
  89. if (pc->st->l3.debug & L3_DEB_WARN)
  90. l3_debug(pc->st, "Wrong MSN Code");
  91. break;
  92. }
  93. teln++;
  94. }
  95. if (channel) {
  96. *p++ = 0x18; /* channel indicator */
  97. *p++ = 1;
  98. *p++ = channel;
  99. }
  100. if (pc->para.spv) { /* SPV ? */
  101. /* NSF SPV */
  102. *p++ = WE0_netSpecFac;
  103. *p++ = 4; /* Laenge */
  104. *p++ = 0;
  105. *p++ = FAC_SPV; /* SPV */
  106. *p++ = pc->para.setup.si1; /* 0 for all Services */
  107. *p++ = pc->para.setup.si2; /* 0 for all Services */
  108. *p++ = WE0_netSpecFac;
  109. *p++ = 4; /* Laenge */
  110. *p++ = 0;
  111. *p++ = FAC_Activate; /* aktiviere SPV (default) */
  112. *p++ = pc->para.setup.si1; /* 0 for all Services */
  113. *p++ = pc->para.setup.si2; /* 0 for all Services */
  114. }
  115. eaz = pc->para.setup.eazmsn;
  116. if (*eaz) {
  117. *p++ = WE0_origAddr;
  118. *p++ = strlen(eaz) + 1;
  119. /* Classify as AnyPref. */
  120. *p++ = 0x81; /* Ext = '1'B, Type = '000'B, Plan = '0001'B. */
  121. while (*eaz)
  122. *p++ = *eaz++ & 0x7f;
  123. }
  124. *p++ = WE0_destAddr;
  125. *p++ = strlen(teln) + 1;
  126. /* Classify as AnyPref. */
  127. *p++ = 0x81; /* Ext = '1'B, Type = '000'B, Plan = '0001'B. */
  128. while (*teln)
  129. *p++ = *teln++ & 0x7f;
  130. *p++ = WE_Shift_F6;
  131. /* Codesatz 6 fuer Service */
  132. *p++ = WE6_serviceInd;
  133. *p++ = 2; /* len=2 info,info2 */
  134. *p++ = pc->para.setup.si1;
  135. *p++ = pc->para.setup.si2;
  136. l = p - tmp;
  137. if (!(skb = l3_alloc_skb(l)))
  138. return;
  139. memcpy(skb_put(skb, l), tmp, l);
  140. L3DelTimer(&pc->timer);
  141. L3AddTimer(&pc->timer, T303, CC_T303);
  142. newl3state(pc, 1);
  143. l3_msg(pc->st, DL_DATA | REQUEST, skb);
  144. }
  145. static void
  146. l3_1tr6_setup(struct l3_process *pc, u_char pr, void *arg)
  147. {
  148. u_char *p;
  149. int bcfound = 0;
  150. char tmp[80];
  151. struct sk_buff *skb = arg;
  152. /* Channel Identification */
  153. p = findie(skb->data, skb->len, WE0_chanID, 0);
  154. if (p) {
  155. if (p[1] != 1) {
  156. l3_1tr6_error(pc, "setup wrong chanID len", skb);
  157. return;
  158. }
  159. if ((p[2] & 0xf4) != 0x80) {
  160. l3_1tr6_error(pc, "setup wrong WE0_chanID", skb);
  161. return;
  162. }
  163. if ((pc->para.bchannel = p[2] & 0x3))
  164. bcfound++;
  165. } else {
  166. l3_1tr6_error(pc, "missing setup chanID", skb);
  167. return;
  168. }
  169. p = skb->data;
  170. if ((p = findie(p, skb->len, WE6_serviceInd, 6))) {
  171. pc->para.setup.si1 = p[2];
  172. pc->para.setup.si2 = p[3];
  173. } else {
  174. l3_1tr6_error(pc, "missing setup SI", skb);
  175. return;
  176. }
  177. p = skb->data;
  178. if ((p = findie(p, skb->len, WE0_destAddr, 0)))
  179. iecpy(pc->para.setup.eazmsn, p, 1);
  180. else
  181. pc->para.setup.eazmsn[0] = 0;
  182. p = skb->data;
  183. if ((p = findie(p, skb->len, WE0_origAddr, 0))) {
  184. iecpy(pc->para.setup.phone, p, 1);
  185. } else
  186. pc->para.setup.phone[0] = 0;
  187. p = skb->data;
  188. pc->para.spv = 0;
  189. if ((p = findie(p, skb->len, WE0_netSpecFac, 0))) {
  190. if ((FAC_SPV == p[3]) || (FAC_Activate == p[3]))
  191. pc->para.spv = 1;
  192. }
  193. dev_kfree_skb(skb);
  194. /* Signal all services, linklevel takes care of Service-Indicator */
  195. if (bcfound) {
  196. if ((pc->para.setup.si1 != 7) && (pc->st->l3.debug & L3_DEB_WARN)) {
  197. sprintf(tmp, "non-digital call: %s -> %s",
  198. pc->para.setup.phone,
  199. pc->para.setup.eazmsn);
  200. l3_debug(pc->st, tmp);
  201. }
  202. newl3state(pc, 6);
  203. pc->st->l3.l3l4(pc->st, CC_SETUP | INDICATION, pc);
  204. } else
  205. release_l3_process(pc);
  206. }
  207. static void
  208. l3_1tr6_setup_ack(struct l3_process *pc, u_char pr, void *arg)
  209. {
  210. u_char *p;
  211. struct sk_buff *skb = arg;
  212. L3DelTimer(&pc->timer);
  213. p = skb->data;
  214. newl3state(pc, 2);
  215. if ((p = findie(p, skb->len, WE0_chanID, 0))) {
  216. if (p[1] != 1) {
  217. l3_1tr6_error(pc, "setup_ack wrong chanID len", skb);
  218. return;
  219. }
  220. if ((p[2] & 0xf4) != 0x80) {
  221. l3_1tr6_error(pc, "setup_ack wrong WE0_chanID", skb);
  222. return;
  223. }
  224. pc->para.bchannel = p[2] & 0x3;
  225. } else {
  226. l3_1tr6_error(pc, "missing setup_ack WE0_chanID", skb);
  227. return;
  228. }
  229. dev_kfree_skb(skb);
  230. L3AddTimer(&pc->timer, T304, CC_T304);
  231. pc->st->l3.l3l4(pc->st, CC_MORE_INFO | INDICATION, pc);
  232. }
  233. static void
  234. l3_1tr6_call_sent(struct l3_process *pc, u_char pr, void *arg)
  235. {
  236. u_char *p;
  237. struct sk_buff *skb = arg;
  238. L3DelTimer(&pc->timer);
  239. p = skb->data;
  240. if ((p = findie(p, skb->len, WE0_chanID, 0))) {
  241. if (p[1] != 1) {
  242. l3_1tr6_error(pc, "call sent wrong chanID len", skb);
  243. return;
  244. }
  245. if ((p[2] & 0xf4) != 0x80) {
  246. l3_1tr6_error(pc, "call sent wrong WE0_chanID", skb);
  247. return;
  248. }
  249. if ((pc->state == 2) && (pc->para.bchannel != (p[2] & 0x3))) {
  250. l3_1tr6_error(pc, "call sent wrong chanID value", skb);
  251. return;
  252. }
  253. pc->para.bchannel = p[2] & 0x3;
  254. } else {
  255. l3_1tr6_error(pc, "missing call sent WE0_chanID", skb);
  256. return;
  257. }
  258. dev_kfree_skb(skb);
  259. L3AddTimer(&pc->timer, T310, CC_T310);
  260. newl3state(pc, 3);
  261. pc->st->l3.l3l4(pc->st, CC_PROCEEDING | INDICATION, pc);
  262. }
  263. static void
  264. l3_1tr6_alert(struct l3_process *pc, u_char pr, void *arg)
  265. {
  266. struct sk_buff *skb = arg;
  267. dev_kfree_skb(skb);
  268. L3DelTimer(&pc->timer); /* T304 */
  269. newl3state(pc, 4);
  270. pc->st->l3.l3l4(pc->st, CC_ALERTING | INDICATION, pc);
  271. }
  272. static void
  273. l3_1tr6_info(struct l3_process *pc, u_char pr, void *arg)
  274. {
  275. u_char *p;
  276. int i, tmpcharge = 0;
  277. char a_charge[8], tmp[32];
  278. struct sk_buff *skb = arg;
  279. p = skb->data;
  280. if ((p = findie(p, skb->len, WE6_chargingInfo, 6))) {
  281. iecpy(a_charge, p, 1);
  282. for (i = 0; i < strlen(a_charge); i++) {
  283. tmpcharge *= 10;
  284. tmpcharge += a_charge[i] & 0xf;
  285. }
  286. if (tmpcharge > pc->para.chargeinfo) {
  287. pc->para.chargeinfo = tmpcharge;
  288. pc->st->l3.l3l4(pc->st, CC_CHARGE | INDICATION, pc);
  289. }
  290. if (pc->st->l3.debug & L3_DEB_CHARGE) {
  291. sprintf(tmp, "charging info %d", pc->para.chargeinfo);
  292. l3_debug(pc->st, tmp);
  293. }
  294. } else if (pc->st->l3.debug & L3_DEB_CHARGE)
  295. l3_debug(pc->st, "charging info not found");
  296. dev_kfree_skb(skb);
  297. }
  298. static void
  299. l3_1tr6_info_s2(struct l3_process *pc, u_char pr, void *arg)
  300. {
  301. struct sk_buff *skb = arg;
  302. dev_kfree_skb(skb);
  303. }
  304. static void
  305. l3_1tr6_connect(struct l3_process *pc, u_char pr, void *arg)
  306. {
  307. struct sk_buff *skb = arg;
  308. L3DelTimer(&pc->timer); /* T310 */
  309. if (!findie(skb->data, skb->len, WE6_date, 6)) {
  310. l3_1tr6_error(pc, "missing connect date", skb);
  311. return;
  312. }
  313. newl3state(pc, 10);
  314. dev_kfree_skb(skb);
  315. pc->para.chargeinfo = 0;
  316. pc->st->l3.l3l4(pc->st, CC_SETUP | CONFIRM, pc);
  317. }
  318. static void
  319. l3_1tr6_rel(struct l3_process *pc, u_char pr, void *arg)
  320. {
  321. struct sk_buff *skb = arg;
  322. u_char *p;
  323. p = skb->data;
  324. if ((p = findie(p, skb->len, WE0_cause, 0))) {
  325. if (p[1] > 0) {
  326. pc->para.cause = p[2];
  327. if (p[1] > 1)
  328. pc->para.loc = p[3];
  329. else
  330. pc->para.loc = 0;
  331. } else {
  332. pc->para.cause = 0;
  333. pc->para.loc = 0;
  334. }
  335. } else {
  336. pc->para.cause = NO_CAUSE;
  337. l3_1tr6_error(pc, "missing REL cause", skb);
  338. return;
  339. }
  340. dev_kfree_skb(skb);
  341. StopAllL3Timer(pc);
  342. newl3state(pc, 0);
  343. l3_1TR6_message(pc, MT_N1_REL_ACK, PROTO_DIS_N1);
  344. pc->st->l3.l3l4(pc->st, CC_RELEASE | INDICATION, pc);
  345. release_l3_process(pc);
  346. }
  347. static void
  348. l3_1tr6_rel_ack(struct l3_process *pc, u_char pr, void *arg)
  349. {
  350. struct sk_buff *skb = arg;
  351. dev_kfree_skb(skb);
  352. StopAllL3Timer(pc);
  353. newl3state(pc, 0);
  354. pc->para.cause = NO_CAUSE;
  355. pc->st->l3.l3l4(pc->st, CC_RELEASE | CONFIRM, pc);
  356. release_l3_process(pc);
  357. }
  358. static void
  359. l3_1tr6_disc(struct l3_process *pc, u_char pr, void *arg)
  360. {
  361. struct sk_buff *skb = arg;
  362. u_char *p;
  363. int i, tmpcharge = 0;
  364. char a_charge[8], tmp[32];
  365. StopAllL3Timer(pc);
  366. p = skb->data;
  367. if ((p = findie(p, skb->len, WE6_chargingInfo, 6))) {
  368. iecpy(a_charge, p, 1);
  369. for (i = 0; i < strlen(a_charge); i++) {
  370. tmpcharge *= 10;
  371. tmpcharge += a_charge[i] & 0xf;
  372. }
  373. if (tmpcharge > pc->para.chargeinfo) {
  374. pc->para.chargeinfo = tmpcharge;
  375. pc->st->l3.l3l4(pc->st, CC_CHARGE | INDICATION, pc);
  376. }
  377. if (pc->st->l3.debug & L3_DEB_CHARGE) {
  378. sprintf(tmp, "charging info %d", pc->para.chargeinfo);
  379. l3_debug(pc->st, tmp);
  380. }
  381. } else if (pc->st->l3.debug & L3_DEB_CHARGE)
  382. l3_debug(pc->st, "charging info not found");
  383. p = skb->data;
  384. if ((p = findie(p, skb->len, WE0_cause, 0))) {
  385. if (p[1] > 0) {
  386. pc->para.cause = p[2];
  387. if (p[1] > 1)
  388. pc->para.loc = p[3];
  389. else
  390. pc->para.loc = 0;
  391. } else {
  392. pc->para.cause = 0;
  393. pc->para.loc = 0;
  394. }
  395. } else {
  396. if (pc->st->l3.debug & L3_DEB_WARN)
  397. l3_debug(pc->st, "cause not found");
  398. pc->para.cause = NO_CAUSE;
  399. }
  400. if (!findie(skb->data, skb->len, WE6_date, 6)) {
  401. l3_1tr6_error(pc, "missing connack date", skb);
  402. return;
  403. }
  404. dev_kfree_skb(skb);
  405. newl3state(pc, 12);
  406. pc->st->l3.l3l4(pc->st, CC_DISCONNECT | INDICATION, pc);
  407. }
  408. static void
  409. l3_1tr6_connect_ack(struct l3_process *pc, u_char pr, void *arg)
  410. {
  411. struct sk_buff *skb = arg;
  412. if (!findie(skb->data, skb->len, WE6_date, 6)) {
  413. l3_1tr6_error(pc, "missing connack date", skb);
  414. return;
  415. }
  416. dev_kfree_skb(skb);
  417. newl3state(pc, 10);
  418. pc->para.chargeinfo = 0;
  419. L3DelTimer(&pc->timer);
  420. pc->st->l3.l3l4(pc->st, CC_SETUP_COMPL | INDICATION, pc);
  421. }
  422. static void
  423. l3_1tr6_alert_req(struct l3_process *pc, u_char pr, void *arg)
  424. {
  425. newl3state(pc, 7);
  426. l3_1TR6_message(pc, MT_N1_ALERT, PROTO_DIS_N1);
  427. }
  428. static void
  429. l3_1tr6_setup_rsp(struct l3_process *pc, u_char pr, void *arg)
  430. {
  431. struct sk_buff *skb;
  432. u_char tmp[24];
  433. u_char *p = tmp;
  434. int l;
  435. MsgHead(p, pc->callref, MT_N1_CONN, PROTO_DIS_N1);
  436. if (pc->para.spv) { /* SPV ? */
  437. /* NSF SPV */
  438. *p++ = WE0_netSpecFac;
  439. *p++ = 4; /* Laenge */
  440. *p++ = 0;
  441. *p++ = FAC_SPV; /* SPV */
  442. *p++ = pc->para.setup.si1;
  443. *p++ = pc->para.setup.si2;
  444. *p++ = WE0_netSpecFac;
  445. *p++ = 4; /* Laenge */
  446. *p++ = 0;
  447. *p++ = FAC_Activate; /* aktiviere SPV */
  448. *p++ = pc->para.setup.si1;
  449. *p++ = pc->para.setup.si2;
  450. }
  451. newl3state(pc, 8);
  452. l = p - tmp;
  453. if (!(skb = l3_alloc_skb(l)))
  454. return;
  455. memcpy(skb_put(skb, l), tmp, l);
  456. l3_msg(pc->st, DL_DATA | REQUEST, skb);
  457. L3DelTimer(&pc->timer);
  458. L3AddTimer(&pc->timer, T313, CC_T313);
  459. }
  460. static void
  461. l3_1tr6_reset(struct l3_process *pc, u_char pr, void *arg)
  462. {
  463. release_l3_process(pc);
  464. }
  465. static void
  466. l3_1tr6_disconnect_req(struct l3_process *pc, u_char pr, void *arg)
  467. {
  468. struct sk_buff *skb;
  469. u_char tmp[16];
  470. u_char *p = tmp;
  471. int l;
  472. u_char cause = 0x10;
  473. u_char clen = 1;
  474. if (pc->para.cause > 0)
  475. cause = pc->para.cause;
  476. /* Map DSS1 causes */
  477. switch (cause & 0x7f) {
  478. case 0x10:
  479. clen = 0;
  480. break;
  481. case 0x11:
  482. cause = CAUSE_UserBusy;
  483. break;
  484. case 0x15:
  485. cause = CAUSE_CallRejected;
  486. break;
  487. }
  488. StopAllL3Timer(pc);
  489. MsgHead(p, pc->callref, MT_N1_DISC, PROTO_DIS_N1);
  490. *p++ = WE0_cause;
  491. *p++ = clen; /* Laenge */
  492. if (clen)
  493. *p++ = cause | 0x80;
  494. newl3state(pc, 11);
  495. l = p - tmp;
  496. if (!(skb = l3_alloc_skb(l)))
  497. return;
  498. memcpy(skb_put(skb, l), tmp, l);
  499. l3_msg(pc->st, DL_DATA | REQUEST, skb);
  500. L3AddTimer(&pc->timer, T305, CC_T305);
  501. }
  502. static void
  503. l3_1tr6_t303(struct l3_process *pc, u_char pr, void *arg)
  504. {
  505. if (pc->N303 > 0) {
  506. pc->N303--;
  507. L3DelTimer(&pc->timer);
  508. l3_1tr6_setup_req(pc, pr, arg);
  509. } else {
  510. L3DelTimer(&pc->timer);
  511. pc->para.cause = 0;
  512. l3_1tr6_disconnect_req(pc, 0, NULL);
  513. }
  514. }
  515. static void
  516. l3_1tr6_t304(struct l3_process *pc, u_char pr, void *arg)
  517. {
  518. L3DelTimer(&pc->timer);
  519. pc->para.cause = 0xE6;
  520. l3_1tr6_disconnect_req(pc, pr, NULL);
  521. pc->st->l3.l3l4(pc->st, CC_SETUP_ERR, pc);
  522. }
  523. static void
  524. l3_1tr6_t305(struct l3_process *pc, u_char pr, void *arg)
  525. {
  526. struct sk_buff *skb;
  527. u_char tmp[16];
  528. u_char *p = tmp;
  529. int l;
  530. u_char cause = 0x90;
  531. u_char clen = 1;
  532. L3DelTimer(&pc->timer);
  533. if (pc->para.cause != NO_CAUSE)
  534. cause = pc->para.cause;
  535. /* Map DSS1 causes */
  536. switch (cause & 0x7f) {
  537. case 0x10:
  538. clen = 0;
  539. break;
  540. case 0x15:
  541. cause = CAUSE_CallRejected;
  542. break;
  543. }
  544. MsgHead(p, pc->callref, MT_N1_REL, PROTO_DIS_N1);
  545. *p++ = WE0_cause;
  546. *p++ = clen; /* Laenge */
  547. if (clen)
  548. *p++ = cause;
  549. newl3state(pc, 19);
  550. l = p - tmp;
  551. if (!(skb = l3_alloc_skb(l)))
  552. return;
  553. memcpy(skb_put(skb, l), tmp, l);
  554. l3_msg(pc->st, DL_DATA | REQUEST, skb);
  555. L3AddTimer(&pc->timer, T308, CC_T308_1);
  556. }
  557. static void
  558. l3_1tr6_t310(struct l3_process *pc, u_char pr, void *arg)
  559. {
  560. L3DelTimer(&pc->timer);
  561. pc->para.cause = 0xE6;
  562. l3_1tr6_disconnect_req(pc, pr, NULL);
  563. pc->st->l3.l3l4(pc->st, CC_SETUP_ERR, pc);
  564. }
  565. static void
  566. l3_1tr6_t313(struct l3_process *pc, u_char pr, void *arg)
  567. {
  568. L3DelTimer(&pc->timer);
  569. pc->para.cause = 0xE6;
  570. l3_1tr6_disconnect_req(pc, pr, NULL);
  571. pc->st->l3.l3l4(pc->st, CC_CONNECT_ERR, pc);
  572. }
  573. static void
  574. l3_1tr6_t308_1(struct l3_process *pc, u_char pr, void *arg)
  575. {
  576. L3DelTimer(&pc->timer);
  577. l3_1TR6_message(pc, MT_N1_REL, PROTO_DIS_N1);
  578. L3AddTimer(&pc->timer, T308, CC_T308_2);
  579. newl3state(pc, 19);
  580. }
  581. static void
  582. l3_1tr6_t308_2(struct l3_process *pc, u_char pr, void *arg)
  583. {
  584. L3DelTimer(&pc->timer);
  585. pc->st->l3.l3l4(pc->st, CC_RELEASE_ERR, pc);
  586. release_l3_process(pc);
  587. }
  588. static void
  589. l3_1tr6_dl_reset(struct l3_process *pc, u_char pr, void *arg)
  590. {
  591. pc->para.cause = CAUSE_LocalProcErr;
  592. l3_1tr6_disconnect_req(pc, pr, NULL);
  593. pc->st->l3.l3l4(pc->st, CC_SETUP_ERR, pc);
  594. }
  595. static void
  596. l3_1tr6_dl_release(struct l3_process *pc, u_char pr, void *arg)
  597. {
  598. newl3state(pc, 0);
  599. pc->para.cause = 0x1b; /* Destination out of order */
  600. pc->para.loc = 0;
  601. pc->st->l3.l3l4(pc->st, CC_RELEASE | INDICATION, pc);
  602. release_l3_process(pc);
  603. }
  604. /* *INDENT-OFF* */
  605. static struct stateentry downstl[] =
  606. {
  607. {SBIT(0),
  608. CC_SETUP | REQUEST, l3_1tr6_setup_req},
  609. {SBIT(1) | SBIT(2) | SBIT(3) | SBIT(4) | SBIT(6) | SBIT(7) | SBIT(8) |
  610. SBIT(10),
  611. CC_DISCONNECT | REQUEST, l3_1tr6_disconnect_req},
  612. {SBIT(12),
  613. CC_RELEASE | REQUEST, l3_1tr6_release_req},
  614. {SBIT(6),
  615. CC_IGNORE | REQUEST, l3_1tr6_reset},
  616. {SBIT(6),
  617. CC_REJECT | REQUEST, l3_1tr6_disconnect_req},
  618. {SBIT(6),
  619. CC_ALERTING | REQUEST, l3_1tr6_alert_req},
  620. {SBIT(6) | SBIT(7),
  621. CC_SETUP | RESPONSE, l3_1tr6_setup_rsp},
  622. {SBIT(1),
  623. CC_T303, l3_1tr6_t303},
  624. {SBIT(2),
  625. CC_T304, l3_1tr6_t304},
  626. {SBIT(3),
  627. CC_T310, l3_1tr6_t310},
  628. {SBIT(8),
  629. CC_T313, l3_1tr6_t313},
  630. {SBIT(11),
  631. CC_T305, l3_1tr6_t305},
  632. {SBIT(19),
  633. CC_T308_1, l3_1tr6_t308_1},
  634. {SBIT(19),
  635. CC_T308_2, l3_1tr6_t308_2},
  636. };
  637. static struct stateentry datastln1[] =
  638. {
  639. {SBIT(0),
  640. MT_N1_INVALID, l3_1tr6_invalid},
  641. {SBIT(0),
  642. MT_N1_SETUP, l3_1tr6_setup},
  643. {SBIT(1),
  644. MT_N1_SETUP_ACK, l3_1tr6_setup_ack},
  645. {SBIT(1) | SBIT(2),
  646. MT_N1_CALL_SENT, l3_1tr6_call_sent},
  647. {SBIT(1) | SBIT(2) | SBIT(3) | SBIT(4) | SBIT(7) | SBIT(8) | SBIT(10),
  648. MT_N1_DISC, l3_1tr6_disc},
  649. {SBIT(2) | SBIT(3) | SBIT(4),
  650. MT_N1_ALERT, l3_1tr6_alert},
  651. {SBIT(2) | SBIT(3) | SBIT(4),
  652. MT_N1_CONN, l3_1tr6_connect},
  653. {SBIT(2),
  654. MT_N1_INFO, l3_1tr6_info_s2},
  655. {SBIT(8),
  656. MT_N1_CONN_ACK, l3_1tr6_connect_ack},
  657. {SBIT(10),
  658. MT_N1_INFO, l3_1tr6_info},
  659. {SBIT(0) | SBIT(1) | SBIT(2) | SBIT(3) | SBIT(4) | SBIT(7) | SBIT(8) |
  660. SBIT(10) | SBIT(11) | SBIT(12) | SBIT(15) | SBIT(17),
  661. MT_N1_REL, l3_1tr6_rel},
  662. {SBIT(19),
  663. MT_N1_REL, l3_1tr6_rel_ack},
  664. {SBIT(0) | SBIT(1) | SBIT(2) | SBIT(3) | SBIT(4) | SBIT(7) | SBIT(8) |
  665. SBIT(10) | SBIT(11) | SBIT(12) | SBIT(15) | SBIT(17),
  666. MT_N1_REL_ACK, l3_1tr6_invalid},
  667. {SBIT(19),
  668. MT_N1_REL_ACK, l3_1tr6_rel_ack}
  669. };
  670. static struct stateentry manstatelist[] =
  671. {
  672. {SBIT(2),
  673. DL_ESTABLISH | INDICATION, l3_1tr6_dl_reset},
  674. {ALL_STATES,
  675. DL_RELEASE | INDICATION, l3_1tr6_dl_release},
  676. };
  677. /* *INDENT-ON* */
  678. static void
  679. up1tr6(struct PStack *st, int pr, void *arg)
  680. {
  681. int i, mt, cr;
  682. struct l3_process *proc;
  683. struct sk_buff *skb = arg;
  684. char tmp[80];
  685. switch (pr) {
  686. case (DL_DATA | INDICATION):
  687. case (DL_UNIT_DATA | INDICATION):
  688. break;
  689. case (DL_ESTABLISH | CONFIRM):
  690. case (DL_ESTABLISH | INDICATION):
  691. case (DL_RELEASE | INDICATION):
  692. case (DL_RELEASE | CONFIRM):
  693. l3_msg(st, pr, arg);
  694. return;
  695. break;
  696. }
  697. if (skb->len < 4) {
  698. if (st->l3.debug & L3_DEB_PROTERR) {
  699. sprintf(tmp, "up1tr6 len only %d", skb->len);
  700. l3_debug(st, tmp);
  701. }
  702. dev_kfree_skb(skb);
  703. return;
  704. }
  705. if ((skb->data[0] & 0xfe) != PROTO_DIS_N0) {
  706. if (st->l3.debug & L3_DEB_PROTERR) {
  707. sprintf(tmp, "up1tr6%sunexpected discriminator %x message len %d",
  708. (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
  709. skb->data[0], skb->len);
  710. l3_debug(st, tmp);
  711. }
  712. dev_kfree_skb(skb);
  713. return;
  714. }
  715. if (skb->data[1] != 1) {
  716. if (st->l3.debug & L3_DEB_PROTERR) {
  717. sprintf(tmp, "up1tr6 CR len not 1");
  718. l3_debug(st, tmp);
  719. }
  720. dev_kfree_skb(skb);
  721. return;
  722. }
  723. cr = skb->data[2];
  724. mt = skb->data[3];
  725. if (skb->data[0] == PROTO_DIS_N0) {
  726. dev_kfree_skb(skb);
  727. if (st->l3.debug & L3_DEB_STATE) {
  728. sprintf(tmp, "up1tr6%s N0 mt %x unhandled",
  729. (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ", mt);
  730. l3_debug(st, tmp);
  731. }
  732. } else if (skb->data[0] == PROTO_DIS_N1) {
  733. if (!(proc = getl3proc(st, cr))) {
  734. if (mt == MT_N1_SETUP) {
  735. if (cr < 128) {
  736. if (!(proc = new_l3_process(st, cr))) {
  737. if (st->l3.debug & L3_DEB_PROTERR) {
  738. sprintf(tmp, "up1tr6 no roc mem");
  739. l3_debug(st, tmp);
  740. }
  741. dev_kfree_skb(skb);
  742. return;
  743. }
  744. } else {
  745. dev_kfree_skb(skb);
  746. return;
  747. }
  748. } else if ((mt == MT_N1_REL) || (mt == MT_N1_REL_ACK) ||
  749. (mt == MT_N1_CANC_ACK) || (mt == MT_N1_CANC_REJ) ||
  750. (mt == MT_N1_REG_ACK) || (mt == MT_N1_REG_REJ) ||
  751. (mt == MT_N1_SUSP_ACK) || (mt == MT_N1_RES_REJ) ||
  752. (mt == MT_N1_INFO)) {
  753. dev_kfree_skb(skb);
  754. return;
  755. } else {
  756. if (!(proc = new_l3_process(st, cr))) {
  757. if (st->l3.debug & L3_DEB_PROTERR) {
  758. sprintf(tmp, "up1tr6 no roc mem");
  759. l3_debug(st, tmp);
  760. }
  761. dev_kfree_skb(skb);
  762. return;
  763. }
  764. mt = MT_N1_INVALID;
  765. }
  766. }
  767. for (i = 0; i < ARRAY_SIZE(datastln1); i++)
  768. if ((mt == datastln1[i].primitive) &&
  769. ((1 << proc->state) & datastln1[i].state))
  770. break;
  771. if (i == ARRAY_SIZE(datastln1)) {
  772. dev_kfree_skb(skb);
  773. if (st->l3.debug & L3_DEB_STATE) {
  774. sprintf(tmp, "up1tr6%sstate %d mt %x unhandled",
  775. (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
  776. proc->state, mt);
  777. l3_debug(st, tmp);
  778. }
  779. return;
  780. } else {
  781. if (st->l3.debug & L3_DEB_STATE) {
  782. sprintf(tmp, "up1tr6%sstate %d mt %x",
  783. (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
  784. proc->state, mt);
  785. l3_debug(st, tmp);
  786. }
  787. datastln1[i].rout(proc, pr, skb);
  788. }
  789. }
  790. }
  791. static void
  792. down1tr6(struct PStack *st, int pr, void *arg)
  793. {
  794. int i, cr;
  795. struct l3_process *proc;
  796. struct Channel *chan;
  797. char tmp[80];
  798. if ((DL_ESTABLISH | REQUEST)== pr) {
  799. l3_msg(st, pr, NULL);
  800. return;
  801. } else if ((CC_SETUP | REQUEST) == pr) {
  802. chan = arg;
  803. cr = newcallref();
  804. cr |= 0x80;
  805. if (!(proc = new_l3_process(st, cr))) {
  806. return;
  807. } else {
  808. proc->chan = chan;
  809. chan->proc = proc;
  810. memcpy(&proc->para.setup, &chan->setup, sizeof(setup_parm));
  811. proc->callref = cr;
  812. }
  813. } else {
  814. proc = arg;
  815. }
  816. for (i = 0; i < ARRAY_SIZE(downstl); i++)
  817. if ((pr == downstl[i].primitive) &&
  818. ((1 << proc->state) & downstl[i].state))
  819. break;
  820. if (i == ARRAY_SIZE(downstl)) {
  821. if (st->l3.debug & L3_DEB_STATE) {
  822. sprintf(tmp, "down1tr6 state %d prim %d unhandled",
  823. proc->state, pr);
  824. l3_debug(st, tmp);
  825. }
  826. } else {
  827. if (st->l3.debug & L3_DEB_STATE) {
  828. sprintf(tmp, "down1tr6 state %d prim %d",
  829. proc->state, pr);
  830. l3_debug(st, tmp);
  831. }
  832. downstl[i].rout(proc, pr, arg);
  833. }
  834. }
  835. static void
  836. man1tr6(struct PStack *st, int pr, void *arg)
  837. {
  838. int i;
  839. struct l3_process *proc = arg;
  840. if (!proc) {
  841. printk(KERN_ERR "HiSax man1tr6 without proc pr=%04x\n", pr);
  842. return;
  843. }
  844. for (i = 0; i < ARRAY_SIZE(manstatelist); i++)
  845. if ((pr == manstatelist[i].primitive) &&
  846. ((1 << proc->state) & manstatelist[i].state))
  847. break;
  848. if (i == ARRAY_SIZE(manstatelist)) {
  849. if (st->l3.debug & L3_DEB_STATE) {
  850. l3_debug(st, "cr %d man1tr6 state %d prim %d unhandled",
  851. proc->callref & 0x7f, proc->state, pr);
  852. }
  853. } else {
  854. if (st->l3.debug & L3_DEB_STATE) {
  855. l3_debug(st, "cr %d man1tr6 state %d prim %d",
  856. proc->callref & 0x7f, proc->state, pr);
  857. }
  858. manstatelist[i].rout(proc, pr, arg);
  859. }
  860. }
  861. void
  862. setstack_1tr6(struct PStack *st)
  863. {
  864. char tmp[64];
  865. st->lli.l4l3 = down1tr6;
  866. st->l2.l2l3 = up1tr6;
  867. st->l3.l3ml3 = man1tr6;
  868. st->l3.N303 = 0;
  869. strcpy(tmp, l3_1tr6_revision);
  870. printk(KERN_INFO "HiSax: 1TR6 Rev. %s\n", HiSax_getrev(tmp));
  871. }